{"text": "\\chapter{Training, validation and test data}\nIn a classification problem, we divide the (usually manually) labeled dataset $D=\\{(x_i,y_i)\\}$ into three disjoint sets, including a training dataset $X$, a validation dataset $V$ and a test dataset $T$.\n% to give an expectation of the real generalization of NN.\n\n\t\\begin{enumerate}\n\t\t\\item The labeled dataset $D=\\{(x_i,y_i)\\}_{i=1}^N$: $x_i$ are samples and $y_i$ are corresponding labels. For example, Figure \\ref{xd:lbd} shows the labeled dataset of five class points, i.e. $x_i\\in\\mathbb{R}^2,y_i=1:5$.\n\t\t\n\t\t\t\\begin{figure}[!ht] \n\t\t\t\t\\center{\\includegraphics[width=10cm] {Homework1_5classes.png}}        \n\t\t\t\t\\caption{labeled dataset} \n\t\t\t\t\\label{xd:lbd}\n\t\t\t\\end{figure}\n\t\t\t \n\t\t\\begin{enumerate}\n\t\t\t\\item Training Data $X$: we use it to train the neural network $f_\\theta(x)$, aiming at minimizing the loss function $\\mathcal{L}(X;\\theta)$ by adjusting $\\theta$.\n\t\t\t\n\t\t\t\\item Validation Data $V$: \n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Detecting whether the neural network is over-fitting, i.e. if $\\mathcal{L}(X)$ decreases while $\\mathcal{L}(V)$ increases.\n\t\t\t\t\\item If it is the case, one may consider stopping training on $X$, because the prediction ability of $f_\\theta$ on other samples (which are what we really want) may decrease.\n\t\t\t\t\\item To make full use of the labeled data, one may continue to train $f_\\theta$ with $V$, and make $X$ the validation data.\n\t\t\t\\end{enumerate}\n\t\t\t\\item Test Data $T$\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Testing the real performance of $f_\\theta$.\n\t\t\t\t\\item We expect a similar accuracy on other unlabeled data as on the test data.\n\t\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Data augmentation: how to generate more data (to avoid over-fitting and make the training easier)\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Shift: shift an image\n\t\t\t\t\\item Rotation: rotate an image\n\t\t\t\t\\item Crop: separate an image to small (intersected) images\n\t\t\t\t\\item ...\n\t\t\t\\end{enumerate}\n\t\\end{enumerate}\n\t\n\n", "meta": {"hexsha": "44fea4da48b8660924252374adce667048b6e941", "size": 1965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/TrainValidateTest.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/TrainValidateTest.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/TrainValidateTest.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": 49.125, "max_line_length": 224, "alphanum_fraction": 0.7002544529, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.649987270016695}}
{"text": "\\subsubsection{Combinations of Fungal Species}\nThe distribution of fungi in the nature is diverse and wide, and there are often hundreds of microorganisms in one square meter of natural land~\\cite{land}. In order to simplify the study on the topic that \\textbf{combinations of fungal species likely to persist in different environment conditions}, we only analyze and predict the growth and decomposition ability of two fungi in combination.\n\\par\nSince the known information is not sufficient and the internal relationship of fungal species combinations in different environments has a degree of uncertainty, we use \\textbf{Gray Prediction Model}~\\cite{gray} and time series data based on the \\textbf{Decomposition Models} in \\textit{Model~4.1} and \\textit{Model~4.2} to analyze and predict the living situation of the fungal species combination and the change trend of decomposition ability.\n\\par\nMark the known group of time series data as follows.\n$$X^0 = (x^0(1),\\ x^0(2),\\ x^0(3),\\ \\ldots,\\ x^0(n))$$\n\\par\nTo ensure the stability of the data, we perform \\textbf{Accumulated Generating Operation} (AGO)~\\cite{gray} on the data. The AGO process would be executed multiple times until the time series data is stable enough, and we get the following time series data.\n$$X^1 = (\\sum^1_{i=1}x^0(i),\\ \\sum^2_{i=1}x^0(i),\\ \\ldots,\\ \\sum^n_{i=1}x^0(i))$$\n\\par\nThe time series $X^1$ is then fitted by a first-order differential equation given by \\textit{Eq.~(\\ref{15eq})}\n\\begin{equation}\n  \\label{15eq}\n  \\frac{dx^1}{dt} = ax^1 = b\n\\end{equation}\nwhere the parameters $a$ and $b$ are the development coefficient and control variable.\n\\par\nAccording to the \\textbf{whitening gray derivatives} of discrete data points, the following equation is obtained.\n\\begin{equation}\n  \\frac{dX^1(t)}{dt} = x^1(k) - x^1(k-1) = x^0(k)\n\\end{equation}\n\\par\nA new variable $z^1(k)$, which is known as the whitening value of $x^1(k)$, is defined by the following equation.\n\\begin{equation}\n  z^1(k) = 0.5x^1(k) + 0.5x^1(k-1)\n\\end{equation}\n\\par\nThen we use \\textbf{the least square method} to calculate the parameters.\n\\begin{equation}\n  \\hat{\\delta} = (B^\\top B)^{-1}B^\\top Y\n\\end{equation}\nwhere\n$$\\hat{\\delta} = [\\hat{a},\\ \\hat{b}]^\\top,\\ B=\\left[ \\begin{array}{cc}\n      -z^1(2) & 1      \\\\\n      -z^1(3) & 1      \\\\\n      \\vdots  & \\vdots \\\\\n      -z^1(n) & 1\n    \\end{array}\n    \\right],\\ Y=\\left[ \\begin{array}{c}\n      x^0(2) \\\\\n      x^0(3) \\\\\n      \\vdots \\\\\n      x^0(n)\n    \\end{array}\n    \\right]$$\n\\par\nFinally, use \\textbf{inverse AGO} and get the predicted value $x^2(k+1)$ as follows.\n$$\\hat{x}^2(k+1) = \\hat{x}^1(k+1) - \\hat{x}^1(k) = (1-e^a)(x^1(1) - \\frac{b}{a})e^{-at},\\ k = 1,\\ 2,\\ \\ldots,\\ n$$\n\\par\nWhen new data are added, the parameters $a$ and $b$ in the Gray Prediction Model would be \\textbf{updated} to ensure the accuracy of prediction.\n\\par\nDue to the large differences in the suitable environment among the five fungi, we divide the five fungi into four combinations, including $F_A\\ \\&\\ F_B$, $F_B\\ \\&\\ F_C$, $F_C\\ \\&\\ F_D$, and $F_D\\ \\&\\ F_E$, based on the conclusion of \\textit{Table~\\ref{correspondingoptimalenvironment}} for analysis and prediction.\n\\par\nTake combination $F_A\\ \\&\\ F_B$ as an example. Calculate the time series data of the decomposition rate for the previous $122$ days using the data in \\textit{Eq.~(\\ref{sixtheq})}, \\textit{Eq.~(\\ref{ninetheq})}, and \\textit{Table~\\ref{decompositionrates}}, and mark it as follows.\n$$X^0_{A\\&B} = (x^0_{A\\&B}(1),\\ x^0_{A\\&B}(2),\\ \\ldots,\\ x^0_{a\\&B}(122))$$\n\\par\nThen the time series data is substituted into Gray Prediction Model, and the prediction data is calculated as follows.\n$$X^2_{A\\&B}=(x^2_{A\\&B}(123),\\ x^2_{A\\&B}(124),\\ \\ldots,\\ x^2_{A\\&B}(200))$$\n\\par\nDraw the decomposition rate of fungal species combination $F_A\\ \\&\\ F_B$ in five climates, including arid, semi-arid, temperate, arboreal, and tropical rain forests, as shown in the figure below.\n\\begin{figure}[H]\n  \\centering\n  \\label{decompositioninfiveclimates}\n  \\includegraphics[width=\\textwidth]{figures/A&B.png}\n  \\caption{Decomposition rate of fungal species combination $F_A\\ \\&\\ F_B$ in five climates.}\n\\end{figure}\nCombination $F_A\\ \\&\\ F_B$ is most suitable for the decomposition of lignin or cellulose in semi-arid climate. From the prediction result, the cumulative decomposition rate after $200$ days can reach $34.7\\%$.\n\\par\nIn the same way, the time series data of the other three fungal species combinations, $F_B\\ \\&\\ F_C$, $F_C \\&\\ F_D$ and $F_D \\&\\ F_E$, are calculated as follows.\n\\begin{equation*}\n  \\begin{cases}\n    X^0_{B\\&C} = (x^0_{B\\&C}(1),\\ x^0_{B\\&C}(2),\\ \\ldots,\\ x^0_{B\\&C}(122)) \\\\ \\\\\n    X^0_{C\\&D} = (x^0_{C\\&D}(1),\\ x^0_{C\\&D}(2),\\ \\ldots,\\ x^0_{C\\&D}(122)) \\\\ \\\\\n    X^0_{D\\&E} = (x^0_{D\\&E}(1),\\ x^0_{D\\&E}(2),\\ \\ldots,\\ x^0_{D\\&E}(122))\n  \\end{cases}\n\\end{equation*}\n\\par\nSubstituting Gray Prediction Model to obtain the following decomposition rate prediction curves in different climates in turn.\n\\par\n\\begin{figure}[H]\n  \\centering\n  \\subfigure[$F_B\\ \\&\\ F_C$]{\n    \\includegraphics[width=0.95\\textwidth]{figures/B&C.png}\n  }\n\\end{figure}\n\\begin{figure}[H]\n  \\centering\n  \\subfigure[$F_C\\ \\&\\ F_D$]{\n    \\includegraphics[width=0.95\\textwidth]{figures/C&D.png}\n  }\n\\end{figure}\n\\begin{figure}[H]\n  \\centering\n  \\subfigure[$F_D\\ \\&\\ F_E$]{\n    \\includegraphics[width=0.95\\textwidth]{figures/D&E.png}\n  }\n  \\caption{Decomposition rate of fungal species combinations in five climates.}\n\\end{figure}\n\\par\nThe optimal environment and the predicted decomposition rate after $200$ days under different combinations of fungal species are summarized in the following table.\n\\begin{table}[H]\n  \\centering\n  \\caption{Summary of optimal environment and predicted decomposition rate.}\n  \\label{summaryofenvironmentandprediction}\n  \\begin{tabular*}{\\hsize}{@{\\extracolsep{\\fill}}ccc}\n    \\toprule\n    Combinations & Optimal Environment & Decomposition Rate Predicted Value \\\\\n    \\midrule\n    $F_A\\&F_B$ & Semi-arid & $34.7\\%$ \\\\\n    $F_B\\&F_C$ & Temperate & $32.8\\%$ \\\\\n    $F_C\\&F_D$ & Temperate / Arboreal & $32.7\\%$ \\\\\n    $F_D\\&F_E$ & Tropical rain forests & $34.3\\%$ \\\\\n    \\bottomrule\n  \\end{tabular*}\n\\end{table}\nAccording to the above table, we find that the combination of $F_A\\ \\&\\ F_B$ has the highest decomposition rate in semi-arid region, which is $34.7\\%$, and the decomposition rates of other species combinations in their optimal environment are also relatively high, which are all above $32\\%$.", "meta": {"hexsha": "bf2d597b4eb8fac0d4228b7d7eeea0be957a271c", "size": 6473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/5/2.tex", "max_stars_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_stars_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-07T14:38:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T10:37:34.000Z", "max_issues_repo_path": "4/5/2.tex", "max_issues_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_issues_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_issues_repo_licenses": ["MIT"], "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/5/2.tex", "max_forks_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_forks_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_forks_repo_licenses": ["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.3247863248, "max_line_length": 445, "alphanum_fraction": 0.6888614244, "num_tokens": 2146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6499872625262179}}
{"text": "\n\n\\section{Preliminaries and exploratory data analysis}\n\nWe're going to revisit data we considered in the cluster analysis lab., so you need to load the \\texttt{cluster} and the \\texttt{flexclust} libraries to make the data available.\n\nWe'll start by considering the \\texttt{milk} data; you should have done some interesting eda in the cluster lab.   We follow this up by carrying out multidimensional scaling using \\texttt{cmdscale} from the \\texttt{MASS} library (look at the helpfile):\n\n\\begin{verbatim}\nlibrary(cluster)\nlibrary(flexclust)\nlibrary(MASS)\ndata(milk)\nmilk.dist <- dist(milk)\nmilk.pco <- cmdscale(milk.dist)\npar(xpd = NA, bty = \"n\") ## let the labels run past the \n## plotting region, and remove the box\nplot(milk.pco, type = \"n\", main = \"PCO representation\")\ntext(milk.pco, row.names(milk.pco), cex = 0.5)\n\\end{verbatim}\n\nNote that we've produced a blank plot but then drawn text on in the positions of the data with the row names.   Can you make sense of the resulting plot?\n\nIf you're very interested, you could even plot the cluster solutions you find when doing cluster analysis against the 2-dimensional representation of the distance matrix:\n\n\\begin{verbatim}\nmilk.hclust <- hclust(milk.dist)\nmilk.cut <- cutree(milk.hclust, 3)\nplot(milk.pco, type = \"n\", main = \"PCO representation\")\ntext(milk.pco, row.names(milk.pco), cex = 0.5, col = milk.cut, pch = milk.cut)\n\\end{verbatim}\n\n\nMore importantly this week is to consider some diagnostics.\n\n\nLets look at the $n-1$ solution, using the delightfully titled \\texttt{zapsmall} function to round our eigenvalues to 8 digits (computer arithmetic means we have a lot of negative eigenvalues in the 15th decimal place which we get rid of).   \n\n\\begin{verbatim}\nmilk.pco.24 <- cmdscale(milk.dist, eig = TRUE, k = 24)\nevals <- zapsmall(milk.pco.24$eig, digits = 8)\nevals\n\\end{verabtim}\n\nNow, if we want to examine the fit of a $q$ dimensional approximation we use $2 \\times n \\times \\sum_{j=q+1}^{n-1} \\lambda_{j}$ (note we are summing all the discarded eigenvalues) to give us: \n\n\\begin{verbatim}\n2 * dim(milk)[1] * sum(milk.pco.24$eig[3:24])\n\\end{verbatim}\n\nYou can adjust this last line to see the SS for a 3 dimensional approximation (use \\texttt{4:24} in the square brackets) and so on.\n\nAnd now try to calculate the same thing directly from the projection and from the data.   We already know $\\boldsymbol{Delta}$ (although we have to tell \\textbf{R} we want a matrix and not a distance matrix.   We can get an estimate of $d$ by taking the distance matrix of the points in the $q$ dimensional approximation that interests us.   Finally, we just want the sum of the differences in the squared distances:\n\n\\begin{verbatim}\nmilk.pco.2 <- cmdscale(milk.dist, eig = TRUE, k = 2)\ndelta <- as.matrix(milk.dist)\nd <- as.matrix(dist(milk.pco.2$points))\nsum(as.vector(delta)^2 - as.vector(d)^2)\n\\end{verbatim}\n\n\nThe other obvious method is just to use the percentage of variance explained / discarded.   Consider dividing the cumulative sum of the eigenvalues by the sum of the eigenvalues:\n\n\\begin{verbatim}\ncumsum(evals) / sum(evals)\n\\end{verbatim}\n\n\nCareful examination should convince you that a 2-dimensional approximation might well be adequate.\n\n\n\\section{Sammon Mapping}\n\nYou could try ``Sammon'' mapping on the mvmclass data.   Assuming you've used \\texttt{daisy} to generate a distance matrix from the class data (we did this in an earlier lab.)\n\n\\begin{verbatim}\nmvmclass <- read.csv(\"class06.csv\", row.names = 1)\nmvmclass.dist <- daisy(mvmclass)\nmvmclass.sammon <- sammon(mvmclass.dist)\n\\end{verbatim}\n\nIf you want to plot the representation, the material you need is under \\verb+mvmclass.sammon$points+.\n\n\\begin{itemize}\n\\item How do you determine whether your sammon fit is a good one or not?\n\\end{itemize}\n\n\\section{Further analyses}\n\nIn case you wish to follow this from Johnson and Wichern's perspective, two datasets have been placed in the portal are very interesting: \\texttt{utilities.csv} and \\texttt{USUni.csv}.   The former we saw last time when we were considering clustering.   The latter considers a number of measures on 25 US Universities.   \n\nAnother interesting analysis involves the Painters data (see \\texttt{?painters} in \\texttt{MASS}) - in particular you may like to see whether there any evidence that the first dimension corresponds with a time axis?\n\n\\section{Summary}\n\n\\fbox{\\parbox[c]{0.9\\textwidth}{\\color{blue}\nIn some ways, it might have been better for this topic to follow cluster analysis.   It is really a different way of examining the relationships between individuals in a dataset.   By the end of this week, we should be able to:\n\n\\begin{itemize}\n\\item Computer and plot a p.c.o projection of a distance matrix\n\\item Understand and justify methods for determining whether our low dimension projection is adequate\n\\item Explain and interpret results, especially if those results are placed relative to a cluster analysis\n\\item Be able to relate p.c.o. to p.c.a.\n\\end{itemize}\n}}\n", "meta": {"hexsha": "3d04fbff91321c6bd51894ba3d69f74c81c9ac23", "size": 4990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "newworksheet/week9pco.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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": "newworksheet/week9pco.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "newworksheet/week9pco.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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.6355140187, "max_line_length": 416, "alphanum_fraction": 0.7563126253, "num_tokens": 1309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6499654445822111}}
{"text": "\\section{Proof Details}\n\\label{sec:ibhc-proof}\n\n\\treerefinement*\n\\begin{proof}\n\nSuppose, first, that $\\tree$ is a refinement of $\\tree'$. Pick any triplet $(\\{a,b\\},c) \\in \\Delta(\\tree')$. Then there is a node in $\\tree'$ whose descendants include $a,b$ but not $c$. By the definition of refinement, $\\tree$ contains a node with the same descendants. Hence the constraint $(\\{a,b\\},c)$ holds for $\\tree$ as well.\n\nConversely, say $\\Delta(\\tree') \\subseteq \\Delta(\\tree)$. Pick any cluster $S'$ of $\\tree'$; it consists of the descendants of some node in $\\tree'$. Consider the set of all triplet constraints consisting of two nodes of $S'$ and one node outside $S'$. Since these constraints also hold for $\\tree$, it follows that the lowest common ancestor of $S'$ in $\\tree$ must have exactly $S'$ as its set of descendants. Thus $S'$ is also a cluster of $\\tree$.\n\\end{proof}\n\n\\irreducible*\n\\begin{proof}\nTo prove irreducibility, we show that there is a non-zero probability\nof moving from state $\\tree$ to $\\tree'$, both of which satisfy $C$. We\naccomplish this by first defining a \\emph{canonical tree} $\\tree_C$ given a triplet \nset $C$ and showing that we can reach $\\tree_C$ from $\\tree$ using  \nconstrained-SPR moves. We then show that for every constrained-SPR move,\nthere exists an equivalent reverse move that undoes it with non-zero\nprobability.\nThis proves that that from $\\tree_C$ we can reach $\\tree'$, \ncreating a path from $\\tree$ to $\\tree_C$ to $\\tree'$.\n\nA binary tree $\\tree$ can be entirely defined by the bipartitions\nmade over the data at each node. \nLet $G_n$ be the Aho graph for node $n$.\nFor a binary tree that satisfies a set of triplets, \nthe split over the data at each node $n$ must \nbe a bipartition of the connected components of $G_n$.\nWe define a particular node to be in \\emph{canonical form}\nif either a) it is a leaf, or b) the bipartition over $G_n$\nat that node can be written as\n$(l, r)$, where $l$ exactly matches a single, particular connected component of\n$G_n$, and $r$ is the rest of the connected components. \nThe particular component\n$l$ is the connected component in $G_n$ with the minimum data index\ninside it.\nNote that we treat the children of nodes as unordered.\nA canonical tree $\\tree_C$ is one such that every node in the tree is\nin canonical form.\nTo convert an arbitrary tree $\\tree$ that satisfies $C$ into $\\tree_C$, we first\nconvert the root node of $\\tree$ into canonical form\nusing constrained-SPR moves.\n\nLet $s$ be the root of $\\tree$ and let $l$\nbe the set of points that ought to be in their own partition according\nto $G_s$. In order for\n$s$ not to be in canonical form, $l$ must be in a partition with \ndata from other connected components in $G_s$, which we will call $o$.\nThe bipartition if $s$ were in canonical form would be $(l, r)$ and\nthe current non-canonical bipartition can thus be written as $(l + o, r - o)$.\n\nWe first examine $t$, the child of the root that contains $l + o$.\nIn general, the data from $l$ and the data from $o$ could\nbe split over the children of $t$, so the partition at $t$\ncan be written as $(l_1 + o_1, l_2 + o_2)$ where $l = l_1 + l_2$ \nand $o = o_1 + o_2$. This is visualized in the first\ntree of \\autoref{fig:canonical}.\nWe first group the data from $l$ into their own ``pure'' subtree\nof $t$ as follows.\nLet $u$ be the root of the\nlowest non-pure subtree of $t$ that has\ndata from $l$ in both of its children.\nThere exist two subtrees that are descendants of $u$ \nthat contain data from $l$ (one on the left and one on the right).\nThose two subtrees\nmust be pure, and furthermore, they are both free to\nmove within $u$ via constrained-SPR moves because\nthey are in different connected components in $G_u$.\nThus, we can perform a constrained-SPR move to merge these\ntwo pure subtrees together into a larger pure subtree.\nWe can repeat this process for $t$ until all nodes\nfrom $l$ are in their own pure subtree of $t$.\nThe partition of $t$ can thus be written as\n$(l + o_1, o_2)$, since the pure subtree may be several\nlevels down from $t$. This grouping process is visualized in\n\\autoref{fig:canonicalgrouping} and the results can be\nseen in the second\ntree in \\autoref{fig:canonical}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{img/ibhc/CanonicalTreeGrouping}\n    \\caption{The process of grouping the data in $u$\n    that belong to $l$ into their own pure subtree. $u$ is the\n    lowest node of $t$ (see \\autoref{fig:canonical}) that has data from $l$\n    in both of its children.}\n    \\label{fig:canonicalgrouping}\n\\end{figure}\n\n\nWe now perform a constrained-SPR move to detach\nthe pure subtree of $l$ and regraft it to\nthe edge between $s$ and $t$. This is a permissible\nmove since $l$ is its own connected component in \n$G_s$. We now have the third tree in \\autoref{fig:supcanonical}.\nWe now perform a final constrained-SPR\nmove, moving the subtree of $o$ to the opposite\nside of $s$, creating the proper canonical partition\nof $(l, r)$.\nTo entirely convert $\\tree$ into $\\tree_C$, we need to recurse\nand convert every node in $\\tree$ into canonical form.\n\n\\begin{figure*}\n    \\centering\n    \\includegraphics[width=\\textwidth]{img/ibhc/CanonicalTree}\n    \\caption{The process of converting $s$ into canonical form.\n    We first group nodes from $l$ into their own pure subtree, then perform\n    two constrained-SPR moves to put $s$ into canonical form.}\n    \\label{fig:supcanonical}\n\\end{figure*}\n\nEvery constrained-SPR move has an associated reverse constrained-SPR move that\nperforms the opposite transition.\nThe reverse constrained-SPR move selects the same subtree as the forward one\nand prunes it, and just regrafts the subtree to its original location\nbefore the forward move.\nWe know that this regraft has non-zero probability because the original tree\ndid not violate constraints.\nThus, since any arbitrary $\\tree$ can be converted into $\\tree_C$ and since each move\nhas a non-zero probability reverse move,\n$\\tree_C$ can be converted into an arbitrary tree $\\tree'$ and we have a non-zero probability\npath to convert $\\tree$ into $\\tree'$.\n\n\\end{proof}\n\n\\section{Additional Results}\n\n\\begin{figure*}[h]\n    \\begin{subfigure}[b]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/ibhc/Zoo-result.png}\n        \\caption{Zoo}\n        \\label{fig:zoo-result}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/ibhc/20-Newsgroups-result.png}\n        \\caption{20 Newsgroups}\n        \\label{fig:20news-result}\n    \\end{subfigure}\n    \\caption{The average of four runs of constrained-SPR samplers\n        for the Zoo dataset and the 20 Newsgroups dataset, using 5 different querying schemes.\n        A query was made every 100 iterations.}\n    \\label{fig:main-results2}\n\\end{figure*}\n", "meta": {"hexsha": "28612772ece5b996d3ecd1327f3f4d1f84fdb9ed", "size": 6830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/content/appendix/ibhc-appendix.tex", "max_stars_repo_name": "sharadmv/thesis", "max_stars_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-30T01:28:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-30T01:28:54.000Z", "max_issues_repo_path": "writeup/content/appendix/ibhc-appendix.tex", "max_issues_repo_name": "sharadmv/thesis", "max_issues_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "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": "writeup/content/appendix/ibhc-appendix.tex", "max_forks_repo_name": "sharadmv/thesis", "max_forks_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "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.462585034, "max_line_length": 451, "alphanum_fraction": 0.7295754026, "num_tokens": 1871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.7905303285397348, "lm_q1q2_score": 0.6499654434733163}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath} % for \\over version of fractions\n\\usepackage{amsfonts} %for number system sets\n\\usepackage{xfrac} %for slanted fractions with sfrac\n\\usepackage[ampersand]{easylist}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\title{Introductory Programming Exercises}\n\\author{Hamik Mukelyan}\n\\maketitle\n\n\\section*{Variables and basic control}\n\\subsection*{Exercise 1: Fibonacci numbers the easy way}\nThe \\textbf{fibonacci numbers} are $1, 1, 2, 3, 5, 8, 13, 21, 34, \\cdots, F_{n}$, where $F_{0} = F_{1} = 1$. There is a \\textbf{closed form} solution for $F_{n}$, which means we can find $F_{n}$ by just plugging $n$ into a formula that we only have to evaluate once. Find this formula online and write a program to compute $F_{5}, F_{10},$ and $F_{20}$. The fibonacci numbers are integers, so make sure that your program rounds or \\textbf{truncates} your numbers correctly. After you've gotten your program to work correctly, \\textbf{refactor} it - i.e., improve it - so that you store $\\sqrt{5}$ in a variable. That way you don't have to perform the slow square root operation three times - you only have to perform it once at the beginning of the program then reuse that result over and over.\n\n\\subsection*{Exercise 2: Fibonacci numbers with a loop}\nWrite a program that displays the fibonacci numbers from $F_{0}$ to $F_{n}$. One way to do this is with a loop that keeps a \\textbf{counter variable}, $i$, that is \\textbf{initialized} to $0$ and is incremented by 1 at the end of each \\textbf{iteration} of the loop until it reaches $n$. The variable names $i, j,$ and $k$ are traditionally used as loop counter variables, with $i$ being used in outermost loops and $j$ being used in loops nested within those outermost loops. For each iteration of the loop you plug $i$ into the formula from exercise 1 and display the result with a print statement. Try it for $n = 10$ and see if the correct numbers show up!\n\nNow let's refactor. The closed form solution for $F_{n}$ uses divisions and exponentiations in addition to square roots. We mitigated the slowness of square root operations by storing $\\sqrt{5}$ in a variable, but we still do divisions and exponentiations, which are super slow compared to simple additions. The \\textbf{recursive formula} for $F_{n}$ elegantly (and simply) describes the sequence in terms of the numbers that came before it: $F_{n} = F_{n - 1} + F_{n - 2}$. Along with the \\textbf{base cases} $F_{0} = F_{1} = 0$, this formula fully defines the sequence. Switch your program over from using the closed form solution to the recursive one. Recursive solutions - that is, solutions that are stated in terms of \\textit{smaller or easier versions of the same problem}, show up often in computer science because closed form solutions are often difficult or impossible to find.\n\n\\subsection*{Exercise 3: The radix}\nWhen we write a number like 987, we actually mean $9 \\cdot 10^{2} + 8 \\cdot 10^{1} + 7 \\cdot 10^{0}$. The number 10 is called the \\textbf{base} or \\textbf{radix} of the number. Most civilizations have used the radix 10 for counting, but some have used weird ones like 60 - we'll see in a moment how to think about numbers in a non-standard base. \\textbf{Binary} (base 2), \\textbf{octal} (base 8), and \\textbf{hexadecimal} (base 16) are the most commonly used bases in programming other than decimal (base 10). If a base $B$ is less than 10, we use only the digits 0 to $B - 1$. For example, in octal we never use the digits 8 or 9. The number $123_{10} = 1 \\cdot 8^{2} + 7 \\cdot 8^{1} + 3 \\cdot 8^{0} = 173_{8}$, where the subscripts are reminders about the bases of the numbers. When the base is 10 we usually omit the subscript by writing e.g. $123$ instead of $123_{10}$.\n\nIn bases greater than 10 we use letters starting from A for digits greater than 9. For example, in hexadecimal the digit A is one greater than 9, B is two greater than 9, and F is the biggest digit, which represents $15_{10}$. So counting from 1 to 32 in base 16, or hexadecimal, looks like 1, 2, 3, $\\cdots,$ 9, A, B, C, D, E, F, 10, 11, 12, 13, $\\cdots,$ 1E, 1F, 20. In binary we have only the digits 0 and 1 at our disposal. Any number that can be represented in decimal can be represented in any other base. Computers store numbers and operate on numbers in binary for the simple reason that it's easy to represent them with hardware: it's much easier for a switch to be simply on or off - representing 1 or 0 - than it is for it to be in one of ten states.\n\nBinary has a special relationship with octal and hexadecimal, which is why they're used frequently in programming. Binary numbers are annoyingly long, so we can represent them more compactly by using their relationship with hex. Write out the first 16 numbers in binary. E.g., 0, 1, 10, 11, 100, 101, $\\cdots$. These numbers match up, respectively, with the hex numbers 0, 1, 2, 3, $\\cdots$, E, F. If you want to write a long binary number like 111100101010$_{2}$ compactly, you break it up into 4-digit chunks and use the equivalent hex number for each chunk. E.g., 1111 0010 1010$_{2}$ = F2A$_{16} = 15 \\cdot 16^{2} + 2 \\cdot 16^{1} + 10 \\cdot 16^{0} = 3882$.\n\nIn many programming languages, you can represent a binary, octal, or hexadecimal number by prefixing any numerical literal with 0b, 0, or 0x. For instance, if you want to double-check that F2A$_{16}$ is actually 3882, just type 0xF2A into a REPL and see the resulting decimal value. Similarly, you can double-check that 173$_{8} = 123$ by typing 0123. These prefixed numerical literals can used anywhere you'd use a typical decimal literal in a program.\n\nHere's the exercise: prompt the user for $n_{10}$ then display it in base 3. Then prompt the user for $m_{3}$ and display it in base 10. Before you try this problem, make sure you can convert a base 10 number into base 3 by hand and vice versa. Next make sure you can clearly articulate the steps you took to do so: in other words, devise an \\textbf{algorithm}, which is a step-by-step problem solving procedure.\n\\end{document}\n\n\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": "ff657efebcd3adf2e23f843fd2e8513b444ca34a", "size": 6076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises.tex", "max_stars_repo_name": "hamikm/CodeExercises", "max_stars_repo_head_hexsha": "1601d08cbad119c0037ad3dc8a6dc78100cb74b7", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "hamikm/CodeExercises", "max_issues_repo_head_hexsha": "1601d08cbad119c0037ad3dc8a6dc78100cb74b7", "max_issues_repo_licenses": ["MIT"], "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", "max_forks_repo_name": "hamikm/CodeExercises", "max_forks_repo_head_hexsha": "1601d08cbad119c0037ad3dc8a6dc78100cb74b7", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 887, "alphanum_fraction": 0.7432521396, "num_tokens": 1700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6499654272432038}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 1}\n\nA reactor contains 5\\% (by atom) enriched uranium dioxide, which is 15\\% of the entire core by volume.\n\\begin{enumerate}[a)]\n\\item Calculate the macroscopic cross section for this core if we were to treat it as a homogeneous volume. \n\\item If the reactor were a cube with a side length of 4 m and a beam of $10^{15}$ thermal neutrons were incident on one face of the cube, how many neutrons would we expect to make it through to the other side?\n\\end{enumerate}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\t\\hline\n\t\t\tNucleus\t\t& Thermal $\\sigma_{\\text{t}}$ (b) & Mass (g/mol) \\\\\n\t\t\t\\hline\n\t\t\t$^{1}$H\t\t&  20.8\t\t\t\t\t\t& 1.008\t\t\t\\\\\n\t\t\t$^{16}$O\t&  3.5 \t\t\t\t\t\t& 15.995\t\t\\\\\n\t\t\t$^{235}$U\t&  607.5 \t\t\t\t\t& 235.044\t\t\\\\\n\t\t\t$^{238}$U\t&  11.8\t\t\t\t\t\t& 238.050\t\t\\\\\n\t\t\t\\hline\n\t\t\tCompound\t& \\multicolumn{2}{|c|}{$\\rho \\left(\\text{g/cm}^3\\right)$}          \\\\\n\t\t\t\\hline\n\t\t\tH$_2$O\t\t& \\multicolumn{2}{|c|}{1.0}      \\\\\n\t\t\tUO$_2$\t\t& \\multicolumn{2}{|c|}{10.4}\t\\\\\n\t\t\t\\hline\n\t\\end{tabular}\n\t\\label{tab:design-specs}\n\\end{table}\n\n", "meta": {"hexsha": "04a4bb82207e768cd3aabce762477555d8cec232", "size": 1119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc04/disc04_exercise01.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_exercise01.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_exercise01.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": 37.3, "max_line_length": 210, "alphanum_fraction": 0.5665773012, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6499512440291368}}
{"text": "\\subsection{Relational Databases}\\label{relational_databases}\nThe group last year chose to implement the WordCount and Fuseki databases using PostgreSQL.\nPostgreSQL is a relational database system\\cite{knox2020}.\n\nIn the coming sections, we will describe how one can model and describe a relational database design, both mathematically and with a more graphic design.\nAfter doing this, we will examine how operations on these models can be described using SQL and relational algebra.\n\n\\subsubsection*{Relational Model}\nRelational database systems can be mathematically described using relations and sets, mapping a unique key to a tuple of information\\cite{DBSBook}.\nThe values of the tuples contained within the relation can be described by the attributes of the relation and their corresponding domains\\cite{KatjaFirstPP}. \nThe relations are often described using a \\textit{relational schema}, denoting the name and domains of the attributes.\n\n\nEquation \\ref{eq:relational_schema} shows an example of a relation describing books as tuples of three text fields ($ISBN$, $author\\_name$, and $title$ ) and a positive integer ($number\\_of\\_pages$).\nThe relation also denotes a super key for the relation. A super key is one or more attributes that can uniquely identify a tuple in a given relation.\nA super key is called a \\textit{candidate key} if removal of a single attribute from the key results in it longer uniquely identifying tuples.\nAttributes describing the primary key are underlined.\n\n\\begin{equation} \\label{eq:relational_schema}\n    book(\\underline{ISBN: text}, author\\_name:text, title: text, number\\_of\\_pages:\\mathbb{Z}^+)\n\\end{equation}\nSuper keys can be explained by $t_1 \\in r\\neq t_2 \\in r \\implies t_1.K \\neq t_2.K$ \\cite{DBSBook}, where $t_1, t_2$ are tuples contained within the relation $r$.\nThat is, no two tuples $t_1, t_2$ from relation $r$ have the same values if they do not have the same superkey $K$. \nIf the super key does not contain extraneous attributes, it is said to be \\textit{minimal} \\cite{DBSBook}.\nWe will use the term \\textit{primary key} to denote a chosen super key of a relation. \nWhen describing a database, it is often necessary to specify how various data are connected. \nTo do this, one can use \\textit{foreign keys} to denote that tuples in $r_1$ are related to the tuples in $r_2$.\n\n\nOne could model the relationship between a book owner and a book using the relational schemas seen in equation \\ref{eq:relational_schema} and \\ref{eq:bookOwnerExample}.\nThere, primary keys from other relations are used to reference unique tuples. The $owns$ relation describes how relations $book$ and $book\\_owner$ are connected. \n\\begin{equation}\\label{eq:bookOwnerExample}\n    \\begin{split}\n        owns(\\underline{owner\\_id \\rightarrow book\\_owner}, \\underline{ISBN \\rightarrow book}), \\\\\n        book\\_owner(\\underline{owner\\_id:\\mathbb{Z}^+}, name:text,)\n    \\end{split}\n\\end{equation}\n\n\\subsubsection*{Evaluating a Database Design}\nWhen evaluating the design of relational database schemas, we want to avoid redundant data duplication, loss by decomposition and change of dependencies\\cite{DBSBook}.\nOne approach to ensure this is to use normalization theory\\cite{DBSBook}. \nThis approach examines the \\textit{functional dependencies} of the relations and evaluates them based on their \\textit{normal form}.\nWhen a relation is in a normal form, it adheres to certain design criteria. \nThese criteria are defined using functional dependencies.\n\nA functional dependency describes the relationship between two sets of attributes. \nFunctional dependency between $\\alpha$ and $\\beta$, written as $\\alpha \\rightarrow \\beta$, defines that a value for $\\alpha$ is sufficient to identify unique values for $\\beta$ \\cite{DBSBook}.\nIn this case, we say that $\\alpha$ is the determinant and $\\beta$ is the dependant. \nWe say that $\\beta$ is functionally determined by $\\alpha$ if $\\alpha \\rightarrow \\beta$.\nIt is logically implied that if $\\alpha \\rightarrow \\beta$ and $\\beta \\rightarrow \\gamma$, then $\\gamma$ is functionally determined by $\\alpha$.\nIf all attributes are functionally determined by $\\alpha$, it is a super key\\cite{DBSBook}.\nThe closure of functional dependency $\\alpha$, denoted $\\alpha^+$, describes all attributes that can be logically implied by functional dependencies having $\\alpha$ as determinant\\cite{DBSBook}. \n\nBoyce-Codd Normal Form (BCNF) eliminates all redundancy that can be discovered using functional dependencies\\cite{DBSBook}. \nA relation is BCNF with respect to functional dependencies $F$ if, for all functional dependencies in $F^+$ of the form $\\alpha \\rightarrow \\beta$ if one of the following holds:\n$\\alpha \\rightarrow \\beta$ is trivial ($\\alpha \\rightarrow \\alpha$) or $\\alpha$ is a super key for the relation.\n\nThus, if a relation $R$ is not in BCNF, there must be a functional dependency $\\alpha \\rightarrow \\beta$ where $\\alpha$ is not a super key. \nWe can split such relation $R$ into two relations $R1(\\alpha \\cup \\beta)$ and $R2(R-(\\beta-\\alpha))$ that are both in BCNF.\n\nThird Normal Form (TNF) prevents partial and transitive dependencies\\cite{MontayaNormalForms}.\nThat is, third normal form prevents functional dependencies of the form seen in equation \\ref{eq:trans} \nand functional dependencies where non-prime attributes are functionally dependent on only a part of the candidate key. \n\\begin{equation}\\label{eq:trans}\n    {\\alpha} \\rightarrow{\\beta}, {\\beta \\rightarrow \\gamma} \\implies \\alpha \\rightarrow \\gamma\n\\end{equation}\n\nA relation is in TNF with respect to functional dependencies $F$ if, for all dependencies in $F^+$ of the form $\\alpha \\rightarrow \\beta$, one of the following holds: \n\n$\\alpha \\rightarrow \\beta$ is trivial, $\\alpha$ is a super key, or each attribute $A \\in \\beta-\\alpha$ is contained in a candidate key for $R$ \\cite{DBSBook}.\n\nHaving established how one can evaluate a relational database design schema, we can proceed to discuss how a different model that can be used to represent the logic of a relational schema can make it easier to ensure that relations are of at least TNF.\n", "meta": {"hexsha": "80468524a979f3bed1786a89f4dbe118acf5e6f1", "size": 6101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Chapter 3 Sprint 1/Relational_databases.tex", "max_stars_repo_name": "chhoumann/p5", "max_stars_repo_head_hexsha": "ea51a218806e552691538e33c16f9cf067be52d4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-14T05:43:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T12:25:11.000Z", "max_issues_repo_path": "sections/Chapter 3 Sprint 1/Relational_databases.tex", "max_issues_repo_name": "chhoumann/p5", "max_issues_repo_head_hexsha": "ea51a218806e552691538e33c16f9cf067be52d4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-11-10T09:54:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-09T07:47:18.000Z", "max_forks_repo_path": "sections/Chapter 3 Sprint 1/Relational_databases.tex", "max_forks_repo_name": "chhoumann/p5", "max_forks_repo_head_hexsha": "ea51a218806e552691538e33c16f9cf067be52d4", "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": 83.5753424658, "max_line_length": 252, "alphanum_fraction": 0.7742992952, "num_tokens": 1461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6497923073125772}}
{"text": "\\subsection{Equations of motion}\\label{sec-1}\nThe formulation of SELFE is based on classic expressions of mass and momentum conservation within a shallow fluid,\nas well as the transport equations for salt and heat. The three dimensional expressions of these laws of motion\ninvolve much less reduction and averaging than one or two-dimensional models. However, 3D estuary-scale models\ndo invoke a standard set of assumptions that will be discussed in section \\ref{sec-assump}.\n\nThe SELFE variant used in this equation is defined in a Cartesian (ie map projection) frame with\nbathymetric depth $h$ and free surface $\\eta$ defined relative to a fixed datum (NAVD 88 in our case) as shown \nin Figure \\ref{fig:depths}. The total depth $H$ is the sum of bathymetric depth and free surface elevation.\n\n\n\nThe 3D continuity, depth-integrated mass conservation, and horizontal momentum conservation equations are given by:\n\\begin{align}\n  %& \\text{3D Continuity}& \\nonumber \\\\\n  \\nabla \\cdot \\bs{u} &= 0 \\label{3Dcon}&\\\\\n  %& \\text{Depth-integrated Continuity}& \\nonumber \\\\\n  \\eta_t+\\nabla \\cdot \\int_{-h}^\\eta \\bs{u} & = 0 \\label{cont1} &\\\\\n  %& \\text{Momentum}& \\nonumber \\\\\n  \\frac{D\\bs{u}}{Dt} &= \\explain{ -f\\bs{k} \\times \\bs{u} }{\\text{Coriolis}} \n\t                      \\; \\explain{-\\frac{1}{\\rho_0} \\nabla p_A}{\\text{Atmos. pressure}}\n\t\t\t\t\t\t\t\t\t\t\t\t\\; \\explain{- \\frac{g}{\\rho_0} \\int_z^\\eta \\nabla \\rho d \\xi}{\\text{Baroclinic}}\n\t                      \\; \\; \\; \\explain{-g\\nabla \\eta}{\\text{Gravity wave}} & \\nonumber \\\\\n\t                      \\; \\; \\; &\\explain{+ \\nabla \\cdot (\\mu \\nabla \\bs{u})}{\\text{Horizontal diffusion}}\n\t\t\t\t\t\t\t\t\t\t\t\t\\; \\; \\; \\; \\explain{+\\frac{\\pd}{\\pd z}(\\nu \\frac{\\pd \\bs{u}}{\\pd z})}{\\text{Vertical diffusion}} \\label{mom1}\n\t\\end{align}\n\twith wind and bed stress boundary conditions at the surface and bottom of the water column:\n\t\\begin{align}\n\t\\nu \\frac{\\pd \\bs{u}}{\\pd z} &= \\bs{\\tau}_w \\mbox{ at } z=\\eta &\\\\\n  \\nu \\frac{\\pd \\bs{u}}{\\pd z} &= \\chi \\bs{u}_b \\mbox{ at } z=-h &\n\\end{align}\nwhere the variables and parameters are:\n\\begin{align*}\n&\\eta(x,y,t)  &\\text{free surface elevation (m)} &\\\\\n&\\bs{u}(x,y,z,t)  &\\text{horizontal velocity(m/s)}  &\\\\\n&h(x,y)  &\\text{bathymetric depth(m)} &\\\\\n&w  & \\text{vertical velocity (m/s)}  &\\\\\n&f     & \\text{Coriolis factor (s\\textsuperscript{-1} )} & \\\\\n&g     & \\text{gravity (m/s\\textsuperscript{2})} & \\\\\n&\\rho  & \\text{water density (kg/m\\textsuperscript{3})} & \\\\\n&p_A(x,y, t) & \\text{atmospheric pressure at the free surface (N m\\textsuperscript{2})} & \\\\\n&\\nu    & \\text{vertical eddy viscosity (m\\textsuperscript{2}/s)} & \\\\\n&\\mu    & \\text{horizontal eddy viscosity (m\\textsuperscript{2}/s) }\\\\\n&\\kappa & \\text{vertical eddy diffusivity, for salt and heat (m\\textsuperscript{2}/s)} & \\\\\n\\end{align*}\n\nand the labeled processes in the momentum equations include:\n\\begin{description}\n    \\item{Coriolis} an apparent force that results from writing equations on a rotating system (the earth) in a projected (x,y) coordinate system. The Coriolis force is most important in the ocean and near coast, less so in estuary or riverine systems. \n\t  \\item{Atmospheric pressure} This is the horizontal variation of pressure above the water.\n\t\t\\item{Gravity wave} Pressure differences due to slope in the water surface are the main force that causes tide and flood propagation. \n\t  \\item{Baroclinic forcing} This is the driving mechanism for density-driven (exchange) flow, as\ncommonly found in estuaries, of which salinity intrusion is an example. Another example is gravity (dense) underflow. Due to this force, the horizontal gradient of the density field will initiate 3D flow that moves denser water under the lighter water and will lead to a two-layer flow structure commonly found in stratified estuaries. \n\\end{description}\n\n\\subsubsection{Assumptions}\\label{sec-assump}\nThe Reynolds averaged shallow water equations include some simplifications of the raw (Navier-Stokes) equations in order\nto eliminate small scale terms and make the equations more tractable.\n\\begin{itemize}\n\\item {\\em Free surface} The free surface is incorporated into the equations and results from the \ndivergence of the horizontal flows. This simplification avoids a complex moving boundary problem at the water-atmosphere interface.\n\\item {\\em Reynolds averaging} SELFE solves for velocity in a time-mean sense, averaged over small scale turbulence. Mixing induced by turbulent fluctuations \nis accounted for by relating the fluctuations to mean flow properties using a set of relations called the {\\em turbulence closure}. \n\\item {\\em Boussinesq approximation} The Boussinesq approximation simplifies terms in the governing equations by considering the the effect of density differences due to soluble tracers (salt, temperature and sediment) only\nin a single buoyancy term.\n\\item {\\em Hydrostaticity} Most models in SELFE's class have both a hydrostatic and non-hydrostatic option. In hydrostatic mode, the model only considers pressure forces on a parcel of water arising only from the weight of the water and atmospheric pressure above, neglecting vertical momentum. \nThe assumption can be relaxed by enabling non-hydrostatic pressure; however, due to the required resolution and computation time, \nthis feature is not used at system scales in any model in the Bay-Delta.\n\\item In hydrostatic mode, volume conservation is first enforced over the water column using horizontal velocities into and out of the water column. Vertical velocity is implied in the equations and later inferred in a separate step that invokes the 3D continuity equation. \n\\end{itemize}\n\n\\subsubsection{Roughness and friction}\nIn SELFE, resistance is introduced into the water column through the combination of the bottom stress (drag)\nboundary condition and vertical turbulent momentum diffusion. The mechanism is less direct than the direct \nbody force used in 1-D and 2-D models. [how does SELFE2D fit here?]\n\nThere are two options in the stipulation of the drag coefficient for each spatial location:\n\\begin{itemize}\n\t\\item $C_d$ may be given directly\n\t\\item $C_d$ may be inferred using an analytical description (logarithmic decay) of velocity in a viscous boundary layer. The parametrized form leads to a formula for $C_d$: \n\t$C_d=[\\frac{1}{\\kappa_0}log(\\frac{\\delta}{z_0})]^{-2}$, where $\\kappa_0$ is von Karman's constant, and $\\delta$ is the thickness\nof the bottom layer. In this case the calibration parameter is roughness ($z_0$) rather than drag.\n\\end{itemize}\n\nOnce drag is characterized at the bed, it is mixed vertically up the water column through a turbulent eddy diffusion, which is\nlabeled \"vertical viscosity\" in equation (\\ref{mom1}) and shown visually in figure ****. The mixing of slower water into \nfaster water has the effect of slowing the faster water down. Near the bed, this viscous process is the analog of\nfriction in a lower dimension model. Higher in the water column, the effect of eddy diffusion and location of the velocity\nmaximum are harder to predict.\n\nIn terms of calibration the above formulation leads to two sets of parameters that need to be estimated. The first is the\ndrag coefficient, which may take the form of $C_d$ or roughness $z_0$. In addition, an eddy diffusion coefficient \nhas to be supplied -- this is not stipulated directly but rather emerges from the choice of turbulence closure, described in Section \\ref{sec-tur}.\n\n\\subsection{Turbulence closure}\\label{sec-tur}\nThe final component of vertical mixing is the turbulence closure, which is used to obtain an eddy viscosity coefficient\nfor the momentum equations and a vertical eddy diffusivity for the transport equations. \n\nWe use the vertical component of Umlauf and Burchard's \\cite{Umlauf2003}  generic length-scale model, a separate differential \nequation which is integrated \"off-line\" of the other equations based on values from the previous time step. \nThe model is as follows:\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 turbulent kinetic energy, $l$ is the mixing length, $c_{\\Psi *}$ are some constants and $\\Psi=(c_\\mu^0)^pk^m l^n$ is a generic\nlength-scale variable, and $\\D$ is the distance from 'walls' (i.e. surface and bottom). \n\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\n\nIn the code, the natural b.c. is applied first (see the FEM formulation below), and the essential b.c. is then used to overwrite the\nboundary values of the unknown, as in the GOTM code. SELFE has been directly coupled to the GOTM model to take advantage of the latter.\n\nOnce the equations for turbulent kinetic energy mixing length have been updated, the \nvalues of eddy viscosity and eddy diffusivity used in the momentum and transport equations are obtained from the relations: \n\\beqa\n  \\nu &=& \\sqrt{2k}s_m l \\\\\n  \\kappa &=& \\sqrt{2k}s_h l\n\\eeqa\nwhere $s_m$ and $s_h$ are stability functions, such as those given by \\citet{Kantha94}\n\nWith this step, the specification of turbulent mixing (and indirectly the mechanism of friction) is complete.\n\n\n\n", "meta": {"hexsha": "cd72904c897777eb8c16ae5b7d7d2c96725a60d2", "size": 10129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/form_hydro.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_hydro.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_hydro.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": 67.0794701987, "max_line_length": 336, "alphanum_fraction": 0.7200118472, "num_tokens": 2897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6497922982609806}}
{"text": "% CReviewofCalculus.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 Calculus}\n\n\\subsection*{Total and Partial Derivatives}\n\n\\begin{proposition}[C.3] (The Chain Rule for Total Derivatives)\n\nSuppose $V,W,X$ finite-dim. vector spaces\n\nopen $\\begin{aligned}\n  & \\quad \\\\ \n  & U \\subseteq V \\\\\n  & \\widetilde{U} \\subseteq W \\end{aligned}$\n\nmaps $\\begin{aligned}\n  & \\quad \\\\\n  & F : U \\to \\widetilde{U} \\\\\n  & G: \\widetilde{U} \\to X \\end{aligned}$\n\nif $F$ diff. at $a\\in U$, $G$ diff. at $F(a) \\in \\widetilde{U}$, \\\\\n\\phantom{ \\quad } then $GF$ diff. at $a$\n\\[\nD(GF)(a) = DG(F(a)) \\circ DF(a)\n\\]\n\\end{proposition}\n\n\\begin{proposition}[C.4] Suppose $\\begin{aligned}\n    & \\quad \\\\ \n    & U \\subseteq \\mathbb{R}^n \\\\\n    & V\\subseteq \\mathbb{R}^m \\end{aligned}$, \\quad \\, $F: U \\to V$ diffeomorphism \\\\\nThen $m=n$ and \\\\\n\\phantom{ \\quad } $\\forall \\, a \\in U$, $DF(a)$ invertible, with \n\\[\nDF(a)^{-1} = D(F^{-1})(F(a))\n\\]\n\\end{proposition}\n\n\\begin{proof}\n$F^{-1}F = 1_U$  \\\\\nChain rule implies $\\forall \\, a \\in U$, \n\n\\begin{equation}\n  1_{\\mathbb{R}^n} = D(1_U)(a) = D(F^{-1}F)(a) = DF^{-1}(F(a))DF(a) \\quad \\quad \\, (C.5)\n\\end{equation}\n\nSimilarly $FF^{-1}=1_V$ implies\n\\[\nDF(a)DF^{-1}(F(a)) = 1_{\\mathbb{R}^m}\n\\]\nso thus\n\\[\nDF(a)^{-1}=D(F^{-1})(F(a))\n\\]\n\\end{proof}\n\n\n", "meta": {"hexsha": "775374dc508000da7eeb4de3ff8fbe3807ba0a04", "size": 2642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LeeJM/CReviewofCalculus.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/CReviewofCalculus.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/CReviewofCalculus.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": 36.1917808219, "max_line_length": 217, "alphanum_fraction": 0.4375473126, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.649757655208227}}
{"text": "\\section{Introduction}\nFluid viscosity is one of the most important properties of fluids, determining\nthe fluid’s flow. \nMotion of an object in a fluid is hindered by a drag force acting in the\ndirection opposite to the direction of motion, i.e. opposite to the object’s\nvelocity. \n\nThe magnitude of the drag force is related to the shape and speed of the object\nas well as to the internal friction in the fluid.\nThe method used in this lab is known as Stokes’ method and it a common and\nsimple method for characterizing transparent or translucent fluids with high\nviscosity.\n\n\n% theoretical\nMotion of an object in a fluid is hindered by a drag force acting in the\ndirection opposite to the direction of motion, i.e. opposite to the object’s\nvelocity. \nThe magnitude of the drag force is related to the shape and speed of the object\nas well as to the internal friction in the fluid.\n\nThis internal friction can be quantified by a number known as the viscosity\ncoefficient $\\mu$.\nFor a spherical object with radius R moving at speed v in an infinite volume of\na liquid, the magnitude of the drag force is usually modeled as linear in the\nspeed\n$$  F_1 = 6 \\pi \\mu v R  $$\n\nWhen a spherical object falls vertically downwards in a fluid, it is being acted\nupon by the following three forces:\nThe viscous force \\emph{$F_1$} and the buoyancy force \\emph{$F_2$} both act\nupwards, and the weight of the object \\emph{$F_3$} is directed downwards.\nThe magnitude of the buoyancy force is\n$$  F_2 = \\frac{4}{3} \\pi R^3 \\rho_1 g $$\nwhere $\\rho_1$ is the density of the fluid and $g$ is the acceleration due to\ngravity. The weight of the object\n$$  F_3 = \\frac{4}{3} \\pi R^3 \\rho_2 g $$\nwith $\\rho_2$ being the density of the object. After some time, the three forces\nwill balance each other\n$$  F_1 + F_2 = F_3  $$\nso that the net force on the object will be zero and from that instant on, the\nobject will be moving with constant speed $v_t$, known as the terminal speed.\nApplying the condition, we can find\n$$  \\mu = \\frac{2}{9} g R^2 \\frac{\\rho_2 - \\rho_1 }{v_t}  $$\nTherefore, the fluid viscosity can be found by measuring the terminal speed.\nTaking into account that the motion with terminal speed is a motion with\nconstant velocity, the equation can be rewritten as\n$$  \\mu = \\frac{2}{9} g R^2 \\frac{( \\rho_2 - \\rho_1 ) t  }{s}  $$\nwhere $s$ is the distance traveled in time $t$ after reaching the terminal\nspeed.\n\nSince the volume of the fluid used in the measurement is not infinite, the\nresults are affected by some boundary effects due to the presence of the\ncontainer.\n\nTherefore, the equation should be modified, and the formula for the\ncorrected magnitude of the viscous force for a infinitely long cylindrical\ncontainer with radius $R_c$ is \n$$  F_1 = 6 \\pi \\mu v R (1 + 2.4 \\frac{R}{R_c})  $$\nConsequently,\n$$ \\mu = \\frac{2}{9} g R^2 \\frac{( \\rho_2 - \\rho_1 ) t  }{s} (1 + 2.4\n\\frac{R}{R_c})  $$\nSince the length $L$ of the container is limited, there may be further\ncorrections introduced, depending on the ratio on $\\frac{R_c}{L}$. \n\n\n\n\n\n", "meta": {"hexsha": "a530abc8ab3405277a8ec5d11038051caa1036e7", "size": 3042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E2/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": "E2/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": "E2/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.4571428571, "max_line_length": 80, "alphanum_fraction": 0.7406311637, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6497576506138266}}
{"text": "% !TeX root = constructions.tex\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\chapter{Lill's Method for Finding Roots}\\label{c.lill}\n\n\\section{Magic}\\label{s.magic}\n\nConstruct a path consisting of four line segments $\\{a_3,a_2,a_1,a_0\\}$ of lengths:\n\\[\n\\{a_3=1,a_2=6,a_1=11,a_0=6\\}\\,,\n\\]\nstarting from the origin, first along the positive direciton of the $x$-axis and turning $90^\\circ$ counterclockwise between segments. Construct a second path as follows: draw a line from the origin at an angle of $63.4^\\circ$ and mark its intersection with $a_2$ by $P$. Turn left $90^\\circ$, draw a line and and mark its intersection with $a_1$ by $Q$. Turn left $90^\\circ$ once again, draw a line and note that it intersects the end of the first path at $(-10,0)$. %See Figure~\\ref{fig.magic}.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=1.15]\n% Draw help lines and axes\n\\draw[step=10mm,white!50!black] (-11,-1) grid (2,7);\n\\draw[thick] (-11,0) -- (2,0);\n\\draw[thick] (0,-1) -- (0,7);\n\\foreach \\x in {-10,...,2}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {1,...,7}\n  \\node at (-.2,\\y-.3) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,6);\n\\coordinate (D) at (-10,6);\n\\coordinate (E) at (-10,0);\n\\foreach \\x in {A,B,C,D,E}\n  \\fill (\\x) circle(1.5pt);\n\\draw[very thick] (A) --\n  node[below,xshift=1pt,yshift=-10pt] {$a_3=1$} (B);\n\\draw[very thick,name path=bc] (B) -- \n  node[right,yshift=6pt] {$a_2=6$} (C);\n\\draw[very thick,name path=cd] (C) --\n  node[above,xshift=4pt] {$a_1=11$}(D);\n\\draw[very thick,name path=de] (D) --\n  node[left,xshift=3pt,yshift=6pt] {$a_0=6$}(E);\n\n% Draw first segment of second path\n\\path[name path=a2] (A) -- +(63.4:4);\n\\path [name intersections = {of = a2 and bc, by = {A2}}];\n\\fill (A2) circle(1.5pt) node[above right] {$P$};\n\\draw[very thick,dashed] (A) -- (A2);\n\\draw ($(A) + (14pt,0)$)\n  arc [start angle=0, end angle = 63.4, radius=14pt];\n\\node[above right,xshift=35pt,yshift=2pt] at (A) {$63.4^\\circ$};\n\\draw[->] ($(A)+(32pt,8pt)$) -- +(-18pt,0);\n\\draw[rotate=153.4] (A2) rectangle +(10pt,10pt);\n\n% Draw second segment of second path\n\\path[name path=b2] (A2) -- +(153.4:10);\n\\path [name intersections = {of = b2 and cd, by = {B2}}];\n\\fill (B2) circle(1.5pt) node[above left] {$Q$};\n\\draw[very thick,dashed] (A2) -- (B2);\n\\draw[rotate=243.4] (B2) rectangle +(10pt,10pt);\n\n% Draw third segment of second path%\n\\draw[very thick,dashed] (B2) -- (E);\n\\end{tikzpicture}\n\\end{center}\nLet $p(x)=a_3x^3+a_2x^2+a_1x+a_0=x^3+6x^2+11x+6$. Compute $\\tan 63.4^\\circ=2$, the tangent of the angle at the start of the second path. Then:\n\\[\np(-\\tan 63.4^\\circ)=(-2)^3+6(-2)^2+11(-2)+6=0\\,.\n\\]\nCongratulations! You have found a root of the cubic polynomial $x^3+6x^2+11x+6$.\n\n\\newpage\n\n\\section{Introduction}\nThis example demonstrates a method discovered by Eduard Lill in 1867 for graphically finding (or more accurately, verifying) the real roots of any polynomial \\cite{bradford, hull-beloch, riaz}. We limit the presentation to cubic polynomials. Lill's method has seen renewed interest because it can be implemented using origami, as we shall see in Chapter~\\ref{c.beloch}.\n\nIn Sections~\\ref{s.multiple}--\\ref{s.noroots} we continue the initial example to find additional roots and to show that if an angle $\\alpha$ is such that $(-\\tan\\alpha)$ is \\emph{not} a root, then the construction doesn't work. Section~\\ref{s.method} presents the full specification of Lill's method. Special cases of the method are demonstrated by the examples in Sections~\\ref{s.negative}--\\ref{s.noninteger}. Since Lill's method can find a real root of any cubic polynomial, it can be used to trisect an angle. By computing $\\sqrt[3]{2}$ as a root of $x^3-2$, it can double a cube (Section~\\ref{s.cube}). Section~\\ref{s.proof} gives a proof that Lill's method can find the real roots of any cubic polynomial. The proof for arbitrary polynomials is similar.\n\n%\\newpage\n\n\\section{Multiple roots}\\label{s.multiple}\n\nLet us continue the example above. The polynomial $p(x)=x^3+6x^2+11x+6$ has three roots $-1,-2,-3$. Computing the arc tangent of the negation of the roots gives:\n\\[\n\\alpha=-\\tan^{-1} (-1) = 45^\\circ,\\quad \\beta=-\\tan^{-1}(-2) = 63.4^\\circ,\\quad \\gamma=-\\tan^{-1} (-3)= 71.6^\\circ\\,.\n\\]\nIn the diagram below we see that for each of the three angles, the second path intersects the end of the first path.\n\\begin{center}\n\\begin{tikzpicture}[scale=1.15]\n% Draw help lines and axes\n\\draw[step=10mm,white!50!black] (-11,-1) grid (2,7);\n\\draw[thick] (-11,0) -- (2,0);\n\\draw[thick] (0,-1) -- (0,7);\n\\foreach \\x in {-10,...,2}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {1,...,7}\n  \\node at (-.2,\\y-.3) {\\sm{\\y}};\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,6);\n\\coordinate (D) at (-10,6);\n\\coordinate (E) at (-10,0);\n\\foreach \\x in {A,B,C,D,E}\n  \\fill (\\x) circle(1.5pt);\n\\draw[very thick] (A) --\n  node[below,yshift=-5pt] {$1$} (B);\n\\draw[very thick,name path=bc] (B) -- \n  node[right,yshift=24pt] {$6$} (C);\n\\draw[very thick,name path=cd] (C) --\n  node[above] {$11$}(D);\n\\path[name path=de] (D) -- ($(E)+(0,-.8)$);\n\\draw[very thick] (D) --\n  node[left,yshift=6pt] {$6$} (E);\n\n\n% Draw first segment of first second path\n\\path[name path=a1] (A) -- +(45:3);\n\\path [name intersections = {of = a1 and bc, by = {A1}}];\n\\fill (A1) circle(1.5pt) node[above right] {$P_1$};\n\\draw[very thick,dashed] (A) -- (A1);\n\\draw[thick] ($(A) + (16pt,0)$)\n  arc [start angle=0, end angle = 45, radius=16pt];\n\\node[above right,xshift=44pt,yshift=0pt] at (A) {$\\alpha$};\n\\draw[rotate=135] (A1) rectangle +(10pt,10pt);\n\\draw[Stealth-,thick] ($(A) + (16pt,6pt)$) -- +(24pt,0);\n\n% Draw second segment of first second path\n\\path[name path=b1] (A1) -- +(135:8);\n\\path [name intersections = {of = b1 and cd, by = {B1}}];\n\\fill (B1) circle(1.5pt) node[above right] {$Q_1$};\n\\draw[very thick,dashed] (A1) -- (B1);\n\\draw[rotate=225] (B1) rectangle +(10pt,10pt);\n\n% Draw third segment of first second path\n\\draw[very thick,dashed] (B1) -- (E);\n\n% Draw first segment of second second path\n\\path[name path=a2] (A) -- +(63.4:4);\n\\path [name intersections = {of = a2 and bc, by = {A2}}];\n\\fill (A2) circle(1.5pt) node[above right] {$P_2$};\n\\draw[very thick,dashed] (A) -- (A2);\n\\draw[thick] ($(A) + (24pt,0)$)\n  arc [start angle=0, end angle = 63.4, radius=24pt];\n\\node[above right,xshift=44pt,yshift=8pt] at (A) {$\\beta$};\n\\draw[rotate=153.4] (A2) rectangle +(10pt,10pt);\n\\draw[<-,thick] ($(A) + (22pt,14pt)$) -- +(18pt,0);\n\n% Draw second segment of second second path%\n\\path[name path=b2] (A2) -- +(153.4:10);\n\\path [name intersections = {of = b2 and cd, by = {B2}}];\n\\fill (B2) circle(1.5pt) node[above right] {$Q_2$};\n\\draw[very thick,dashed] (A2) -- (B2);\n\\draw[rotate=243.4] (B2) rectangle +(10pt,10pt);\n\n% Draw third segment of second second path%\n\\draw[very thick,dashed] (B2) -- (E);\n\n% Draw first segment of second second path%\n\\path[name path=a3] (A) -- +(71.6:4);\n\\path [name intersections = {of = a3 and bc, by = {A3}}];\n\\fill (A3) circle(1.5pt) node[above right] {$P_3$};\n\\draw[very thick,dashed] (A) -- (A3);\n\\draw[thick] ($(A) + (38pt,0)$)\n  arc [start angle=0, end angle = 71.6, radius=40pt];\n\\node[above right,xshift=44pt,yshift=22pt] at (A) {$\\gamma$};\n\\draw[rotate=161.6] (A3) rectangle +(10pt,10pt);\n\\draw[<-,thick] ($(A) + (32pt,25pt)$) -- +(10pt,0);\n\n% Draw second segment of second second path%\n\\path[name path=b3] (A3) -- +(161.6:10);\n\\path [name intersections = {of = b3 and cd, by = {B3}}];\n\\fill (B3) circle(1.5pt) node[above right] {$Q_3$};\n\\draw[very thick,dashed] (A3) -- (B3);\n\\draw[rotate=251.6] (B3) rectangle +(10pt,10pt);\n\n% Draw third segment of second second path%\n\\draw[very thick,dashed] (B3) -- (E);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\section{Paths that do not lead to roots}\\label{s.noroots}\n\nPerhaps the second path intersects the end of the first path for \\emph{any} initial angle, for example, $56.3^\\circ$. In the following diagram, the second path intersects the extension of the line segment for the coefficient $a_0$, but not at $(-10,0)$, the end of the first path. We conclude that $-\\tan 56.3^\\circ =-1.5$ is \\emph{not} a root of the equation.\n\\begin{center}\n\\begin{tikzpicture}[scale=1.15]\n% Draw help lines and axes\n\\draw[step=10mm,white!50!black] (-11,-1) grid (2,7);\n\\draw[thick] (-11,0) -- (2,0);\n\\draw[thick] (0,-1) -- (0,7);\n\\foreach \\x in {-10,...,2}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {1,...,7}\n  \\node at (-.2,\\y-.3) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,6);\n\\coordinate (D) at (-10,6);\n\\coordinate (E) at (-10,0);\n\\foreach \\x in {A,B,C,D,E}\n  \\fill (\\x) circle(1.5pt);\n\\draw[very thick] (A) --\n  node[below,yshift=-5pt] {$1$} (B);\n\\draw[very thick,name path=bc] (B) -- \n  node[right,yshift=6pt] {$6$} (C);\n\\draw[very thick,name path=cd] (C) --\n  node[above] {$11$}(D);\n\\draw[very thick] (D) --\n  node[left,yshift=6pt] {$6$}(E);\n\\path[name path=de] (-10,-1) -- (-10,7);\n\n% Draw first segment of second path\n\\path[name path=a2] (A) -- +(56.3:3);\n\\path [name intersections = {of = a2 and bc, by = {A2}}];\n\\fill (A2) circle(1.5pt) node[above right] {$P$};\n\\draw[very thick,dashed] (A) -- (A2);\n\\draw ($(A) + (14pt,0)$)\n  arc [start angle=0, end angle = 56.3, radius=14pt];\n\\node[above right,xshift=10pt,yshift=6pt] at (A) {$56.3^\\circ$};\n\\draw[rotate=146.3] (A2) rectangle +(10pt,10pt);\n\n% Draw second segment of second path\n\\path[name path=b2] (A2) -- +(146.3:10);\n\\path [name intersections = {of = b2 and cd, by = {B2}}];\n\\fill (B2) circle(1.5pt) node[above right] {$Q$};\n\\draw[very thick,dashed] (A2) -- (B2);\n\\draw[rotate=236.3] (B2) rectangle +(10pt,10pt);\n\n% Draw third segment of second path\n\\path[name path=c2] (B2) -- +(236.3:8.5);\n\\path [name intersections = {of = c2 and de, by = {C2}}];\n\\fill (C2) circle(1.5pt);\n\\draw[very thick,dashed] (B2) -- (C2);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\section{Specification of Lill's method}\\label{s.method}\n\nExamining the examples below will help understand the details.\n\\begin{itemize}\n\\item Start with an arbitrary cubic polynomial: $p(x)=a_3x^3+a_2x^2+a_1x+a_0$.\n\\item Construct the first path as follows:\n\\begin{itemize}\n\\item For each coefficient $a_3,a_2,a_1,a_0$ (in that order) draw a line segment starting at the origin $O=(0,0)$ in the positive direction of the $x$-axis. Turn $90^\\circ$ counterclockwise between each segment.\n\\end{itemize}\n\\item Construct the second path as follows:\n\\begin{itemize}\n\\item We use the symbol for a coefficient $a_i$ to also denote the corresponding side of the first path.\n\\item Construct a line from $O$ at an angle of $\\theta$ with the positive $x$-axis that intersects $a_2$ at point $P$.\n\\item Turn $\\pm 90^\\circ$ and construct a line from $P$ that intersects $a_1$ at $Q$.\n\\item Turn $\\pm 90^\\circ$ and construct a line from $Q$ that intersects $a_0$ at $R$.\n\\item If $R$ is the end point of the first path, then $-\\tan\\theta$ is a root of $p(x)$.\n\\end{itemize}\n\\item Special cases:\n\\begin{itemize}\n\\item When drawing the line segments of the first path, if a coefficient is negative, draw the line segment \\emph{backwards}.\n\\item When drawing the line segments of the first path, if a coefficient is zero, do not draw a line segment but continue with the next $\\pm 90^\\circ$ turn.\n\\end{itemize}\n\\item Notes:\n\\begin{itemize}\n\\item ``Intersects $a_i$'' means ``intersects the line that contains the line segment $a_i$''.\n\\item When building the second path, choose to turn left or right by $90^\\circ$ so that there is an intersection with the next segment of the first path.\n\\end{itemize}\n\\end{itemize}\n\n\\newpage\n\n\\section{Negative coefficients}\\label{s.negative}\n\nSection~\\ref{s.ax6} gave an example of the use of Axiom~6 that resulted in the polynomial $p(x)=x^3-3x^2-3x+1$ with negative coefficients.\n\nWe start by drawing a segment of length $1$ to the right. Next we turn $90^\\circ$ to face up, but the coefficient is negative, so we draw a segment of length $3$ \\emph{down}. After turning $90^\\circ$ to the left, the coefficient is again negative, so we draw a segment of length $3$ to the right. Finally, we turn down and draw a segment of length $1$.\n\nWe start the second path with a line angled $45^\\circ$ with the $x$-axis. It intersects the \\emph{extension} of the line segment for $a_2$ at $(1,1)$. Turning $-90^\\circ$ (to the right), the line intersects the \\emph{extension} of the line segment for $a_1$ at $(5,-3)$. Turning $-90^\\circ$ again, the line intersects the end of the first path at $(4,-4)$.\n\nSince $-\\tan 45^\\circ=-1$, a real root of the polynomial is $-1$:\n\\[\np(-1)=(-1)^3-3(-1)^2-3(-1)+6=0\\,.\n\\]\nThe loosely dashed lines in the diagram will be discussed  in Section~\\ref{s.noninteger}.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=1.1]\n% Draw help lines and axes\n\\draw[step=10mm,white!50!black] (-1,-6) grid (6,2);\n\\draw (0,-6) -- (0,2);\n\\foreach \\x in {0,...,6}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {-5,...,-1}\n  \\node at (-.3,\\y-.3) {\\sm{\\y}};\n\\foreach \\y in {1,...,2}\n  \\node at (-.3,\\y-.3) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,-3);\n\\coordinate (D) at (4,-3);\n\\coordinate (E) at (4,-4);\n\\foreach \\x in {A,B,C,D,E}\n  \\fill (\\x) circle(1pt);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt,reversed]}-] (A) --\n  node[below,yshift=-5pt] {$1$} (B);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt]}-,name path=bc] (B) -- \n  node[right,xshift=3pt] {$a_2=-3$} (C);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt]}-,name path=cd] (C) --\n  node[above,xshift=11pt] {$a_1=-3$}(D);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt,reversed]}-,name path=de] (D) --\n  node[right] {$1$}(E);\n\n% Draw extensions of first path\n\\draw[very thick,loosely dotted,name path=a] (-1,0) -- (6,0);\n\\draw[very thick,loosely dotted,name path=b] (1,-6) -- (1,2);\n\\draw[very thick,loosely dotted,name path=c] (-1,-3) -- (6,-3);\n\n% Draw first second path\n\\path[name path=a1] (A) -- +(-75:5);\n\\path [name intersections = {of = a1 and b, by = {B1}}];\n\\path[name path=b1] (B1) -- +(15:5);\n\\path [name intersections = {of = b1 and c, by = {C1}}];\n\\draw[thick,loosely dashed] (A) -- (B1) -- (C1) -- (E);\n\n% Draw second second path\n\\draw[very thick,dashed] (4,-4) -- (5,-3) coordinate (A2);\n\\fill (5,-3) circle (1.5pt) node[above right] {$P$};\n\\draw[very thick,dashed] (5,-3) -- (1,1) coordinate (B2);\n\\fill (1,1) circle (1.5pt) node[above right] {$Q$};\n\\draw[very thick,dashed] (1,1) -- (0,0);\n\n% Draw third second path\n\\path[name path=a3] (A) -- +(-15:5);\n\\path [name intersections = {of = a3 and b, by = {B3}}];\n\\path[name path=b3] (B3) -- +(-105:5);\n\\path [name intersections = {of = b3 and c, by = {C3}}];\n\\draw[thick,loosely dashed] (A) -- (B3) -- (C3) -- (E);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\section{Zero coefficients}\\label{s.zero}\n\n$a_2$, the coefficient of the $x^2$ term in the polynomial $x^3-7x-6=0$, is zero. For a zero coefficient, we ``draw'' a line segment of length $0$, that is, we do not draw a line, but we still make the $\\pm 90^\\circ$ turn before ``drawing'' it, as indicated by the arrow pointed up at point $(1,0)$ in the diagram. Next make an additional turn and draw a line of length $-7$, that is, of length $7$ backwards, to point $(8,0)$. Finally, turn again and draw a line of length $-6$ to point $(8,6)$.\n\nThere are three second paths that intersect the end of the first path. They start with angles of:\n\\[\n\\alpha=45^\\circ,\\quad \\beta=63.4^\\circ,\\quad \\gamma=-71.6^\\circ\\,.\n\\]\nWe conclude that there are three real roots:\n\\[\n-\\tan 45^\\circ=-1,\\quad -\\tan 63.4^\\circ =-2,\\quad -\\tan (-71.6^\\circ)=3\\,.\n\\]\nCheck:\n\\[\n(x+1)(x+2)(x-3)=x^3-7x-6\\,.\n\\]\n\n\\begin{center}\n\\begin{tikzpicture}[scale=1.1]\n% Draw help lines and axes\n\\draw[step=10mm,white!50!black] (-1,-4) grid (11,7);\n\\foreach \\x in {0,...,11}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {-3,...,-1}\n  \\node at (-.3,\\y-.3) {\\sm{\\y}};\n\\foreach \\y in {1,...,7}\n  \\node at (-.3,\\y-.3) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0) node[above left] {$O$};\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (8,0);\n\\coordinate (D) at (8,6);\n\\node[below right] at (D) {$A$};\n\\foreach \\x in {A,B,C,D}\n  \\fill (\\x) circle(1.5pt); \n\\draw[very thick,{Stealth[scale=1.4,inset=2pt,reversed]}-] (A) --\n  node[below,yshift=-5pt] {$1$} (B);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] (B) --\n  ($(B)+(0,.1)$);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt]}-,name path=bc] (B) -- \n  node[below,xshift=-6pt,yshift=-5pt] {$-7$} (C);\n\\draw[very thick,{Stealth[scale=1.4,inset=2pt]}-,name path=cd] (C) --\n  node[right,yshift=4pt] {$-6$}(D);\n\n% Draw extensions of first path\n\\draw[very thick,loosely dotted] (1,-3) -- (1,7);\n\\draw[very thick,loosely dotted] (-1,0) -- (11,0);\n\n% Draw first second path\n\\draw[very thick,dashed,->] (0,0) -- (1,-3);\n\\fill (1,-3) circle (1.5pt) node[below left] {$P_1$};\n\\draw[very thick,dashed,->] (1,-3) coordinate (A1) -- (10,0);\n\\fill (10,0) circle (1.5pt) node[below right] {$Q_1$};\n\\draw[very thick,dashed,->] (10,0) coordinate (B1) -- (D);\n\n% Draw second second path\n\\draw[very thick,dashed,->] (0,0) -- (1,1) coordinate (A2);\n\\fill (A2) circle (1.5pt) node[above right] at (A2) {$P_2$};\n\\draw[very thick,dashed,->] (A2) -- (2,0) coordinate (B2);\n\\fill (B2) circle (1.5pt) node[below right] at (B2) {$Q_2$};\n\\draw[very thick,dashed,->] (B2) -- (D);\n\n% Draw third second path\n\\draw[very thick,dashed,->] (0,0) -- (1,2) coordinate (A3);\n\\fill (A3) circle (1.5pt) node[above left] {$P_3$};\n\\draw[very thick,dashed,->] (A3) -- (5,0) coordinate (B3);\n\\fill (B3) circle (1.5pt) node[below right] at (B3) {$Q_3$};\n\\draw[very thick,dashed,->] (B3) -- (D);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\section{Non-integer roots}\\label{s.noninteger}\n\nConsider the polynomial $p(x)=x^3-2x+1$. The first segment is from $(0,0)$ to $(1,0)$ and turns up. The coefficient of $x^2$ is zero so no segment is drawn and turns left. The next coefficient is negative so the segment it goes backwards from $(1,0)$ to $(3,0)$ and turns right. Finally, a segment is drawn from $(3,0)$ to $(3,-1)$. Clearly, $1$ is a root of $p(x)$ and since $-\\tan^{-1} (-45^\\circ)=1$, there is a path $\\overline{OP_1Q_1A}$.\n\n If we divide $p(x)$ by $x-1$, we obtain the quadratic polynomial $x^2+x-1$ whose roots are $\\frac{-1\\pm\\sqrt{5}}{2} \\approx 0.62,\\; -1.62$.\n%\\[\n%\\disfrac{-1\\pm\\sqrt{5}}{2} \\approx 0.62,\\; -1.62\\,.\n%\\]\nThere are two additional second paths: one starting at $-31.8^\\circ$ since $-\\tan^{-1} 0.62=-31.8^\\circ$, and one starting at $58.3^\\circ$ since $-\\tan^{-1}1.62=58.3^\\circ$.\n\nSimilarly, the polynomial in Section~\\ref{s.negative} has roots $ 2\\pm\\sqrt{3}\\approx 3.73, 0.27$. The corresponding angles are $-75^\\circ$ and $-15^\\circ$, because $-\\tan (-75^\\circ)\\approx 3.73$ and $-\\tan (-15^\\circ)\\approx 0.27$.\n\\begin{center}\n\\begin{tikzpicture}[scale=1.6]\n% Draw help lines and axes\n\\draw[step=10mm,white!70!black,] (-1,-2) grid (4,2);\n\\foreach \\x in {0,...,4}\n  \\node at (\\x-.2,-.1) {\\sm{\\x}};\n\\foreach \\y in {-1}\n  \\node at (-.1,\\y-.2) {\\sm{\\y}};\n\\foreach \\y in {1,2}\n  \\node at (-.1,\\y-.2) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0);\n\\node[above left] at (A) {$O$};\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (3,0);\n\\coordinate (D) at (3,-1);\n\\node[below right] at (D) {$A$};\n\\foreach \\x in {A,B,C,D}\n  \\fill (\\x) circle(1pt); \n\\draw[very thick] (A) -- node[above,yshift=2pt] {$1$} (B);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(A)+(.1,0)$) --\n  ($(A)+(.15,0)$);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(B)+(0,.05)$) --\n  ($(B)+(0,.1)$);\n\\draw[very thick,name path=bc] (B) -- \n  node[above,xshift=-4pt,yshift=2pt] {$-2$} (C);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(B)+(.22,0)$) --\n  ($(B)+(.17,0)$);\n\\draw[very thick,name path=cd] (C) --\n  node[right] {$1$}(D);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(C)+(0,-.05)$) --\n ($(C)+(0,-.1)$);\n\n% Draw extensions of first path\n\\draw[very thick,loosely dotted,name path=b] (1,-2) -- (1,2);\n\\draw[very thick,loosely dotted,name path=c] (-1,0) -- (4,0);\n\\draw[very thick,loosely dotted,name path=d] (3,-2) -- (3,2);\n\n% Draw first second path\n\\coordinate (A1) at (1,-1);\n\\draw[very thick,dashed,->] (0,0) -- (A1);\n\\fill (A1) circle (1pt) node[below right] {$P_1$};\n\\coordinate (B1) at (2,0);\n\\draw[very thick,dashed,->] (A1) -- (B1);\n\\fill (B1) circle (1pt) node[above right,xshift=4pt] {$Q_1$};\n\\draw[very thick,dashed,->] (B1) -- (D);\n\\draw[rotate=45] (A1) rectangle +(6pt,6pt);\n\\draw[rotate=-135] (B1) rectangle +(6pt,6pt);\n\n% Draw second second path\n\\path[name path=a2] (0,0) -- +(-31.7:4);\n\\path [name intersections = {of = a2 and b, by = {A2}}];\n\\draw[very thick,dashed,->] (0,0) -- (A2);\n\\fill (A2) circle (1pt) node[below right,yshift=2pt] {$P_2$};\n\\path[name path=b2] (A2) -- +(58.3:2.5);\n\\path [name intersections = {of = b2 and c, by = {B2}}];\n\\draw[very thick,dashed,->] (A2) -- (B2);\n\\fill (B2) circle (1pt) node[above] {$Q_2$};\n\\draw[very thick,dashed,->] (B2) -- (D);\n\\draw[rotate=58.3]   (A2) rectangle +(6pt,6pt);\n\\draw[rotate=-121.7] (B2) rectangle +(6pt,6pt);\n\n% Draw third second path\n\\path[name path=a3] (0,0) -- +(58.3:2.5);\n\\path [name intersections = {of = a3 and b, by = {A3}}];\n\\draw[very thick,dashed,->] (0,0) -- (A3);\n\\fill (A3) circle (1pt) node[above left] {$P_3$};\n\\path[name path=b3] (A3) -- +(-31.7:4);\n\\path [name intersections = {of = b3 and c, by = {B3}}];\n\\draw[very thick,dashed,->] (A3) -- (B3);\n\\fill (B3) circle (1pt) node[above right] {$Q_3$};\n\\path[name path=c3] (B3) -- +(-121.7:4);\n\\draw[very thick,dashed,->] (B3) -- (D);\n\\draw[rotate=-121.7]   (A3) rectangle +(6pt,6pt);\n\\draw[rotate=-211.7]   (B3) rectangle +(6pt,6pt);\n\\end{tikzpicture}\n\\end{center}\n\n%\\newpage\n\n\\vspace{-13ex}\n\n\\section{The cube root of two}\\label{s.cube}\n\n$\\sqrt[3]{2}$ is a root of the cubic polynomial $x^3-2$. In the first path, we turn left twice without drawing any line segments, because $a_2$ and $a_1$ are both zero. Then we turn left again (to face down) and draw backwards because $a_0=-2$ is negative. The first segment of the second path is drawn at an angle of $-51.6^\\circ$ and $-\\tan (-51.6^\\circ)\\approx 1.26\\approx \\sqrt[3]{2}$.\n\\begin{center}\n\\begin{tikzpicture}[scale=1.2]\n% Draw help lines and axes\n\\draw[step=10mm,white!70!black,] (-1,-2) grid (3,2);\n\\foreach \\x in {0,...,3}\n  \\node at (\\x-.2,-.1) {\\sm{\\x}};\n\\foreach \\y in {-1}\n  \\node at (-.2,\\y-.2) {\\sm{\\y}};\n\\foreach \\y in {1,2}\n  \\node at (-.2,\\y-.2) {\\sm{\\y}};\n\n% Draw first path\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,2);\n\\foreach \\x in {A,B,C}\n  \\fill (\\x) circle(1pt); \n\\draw[very thick] (A) -- node[above,yshift=2pt] {$1$} (B);\n\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(A)+(.05,0)$) --\n  ($(A)+(.1,0)$);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(B)+(0,.05)$) --\n  ($(B)+(0,.1)$);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(B)+(.1,.3)$) --\n  ($(B)+(.08,.3)$);\n\\draw[{Stealth[scale=1.4,inset=2pt,reversed]}-,very thick] ($(B)+(0,.55)$) --\n  ($(B)+(0,.5)$);\n\n\\draw[very thick] (B) -- \n  node[left,yshift=6pt] {$-2$} (C);\n\n% Draw extensions of first path\n\\draw[very thick,loosely dotted,name path=a] (-1,0) -- (3,0);\n\\draw[very thick,loosely dotted,name path=b] (1,-2) -- (1,2);\n\n% Draw first segment of second path\n\\path[name path=a1] (0,0) -- +(-51.6:2);\n\\path [name intersections = {of = a1 and b, by = {A1}}];\n\\draw[very thick,dashed,->] (A) -- (A1);\n\\fill (A1) circle (1pt) node[below left] {$P_1$};\n\\draw[rotate=38.4]   (A1) rectangle +(6pt,6pt);\n\n% Draw second segment of second path\n\\path[name path=b1] (A1) -- +(38.4:2.5);\n\\path [name intersections = {of = b1 and a, by = {B1}}];\n\\draw[very thick,dashed,->] (A1) -- (B1);\n\\fill (B1) circle (1pt) node[above right] {$Q_1$};\n\\draw[rotate=128.4] (B1) rectangle +(7pt,7pt);\n\n% Draw third segement of second path\n\\draw[very thick,dashed,->] (B1) -- (C);\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\section{Proof of Lill's method}\\label{s.proof}\n\nWe limit ourselves to monic cubic polynomials $p(x)=x^3+a_2x^2+a_1x+a_0$.\\footnote{If the polynomial is not monic, divide it by $a_3$ and the resulting monic polynomial has the same roots.} In the diagram below, segments of the first path are labeled with coefficients and with $b_2,b_1,a_2-b_2,a_1-b_1$.\n\nSince the sum of the angles of a triangle is $180^\\circ$, in a right triangle if one acute angle is $\\theta$, the other is $90^\\circ-\\theta$. Therefore, the angle above $P$ and the angle to the left of $Q$ are equal to $\\theta$. We now derive a sequence of formulas for $\\tan \\theta$:\n\\vspace{-2ex}\n\\begin{form}{1.1}\n\\tan \\theta &=& \\disfrac{b_2}{1}=b_2\\\\\n%a_2-b_2&=&a_2-\\tan\\theta\\\\\n\\tan \\theta &=& \\disfrac{b_1}{a_2-b_2}=\\disfrac{b_1}{a_2-\\tan\\theta}\\\\\nb_1&=&\\tan\\theta (a_2-\\tan\\theta)\\\\\n\\tan \\theta &=& \\disfrac{a_0}{a_1-b_1}=\\disfrac{a_0}{a_1-\\tan\\theta(a_2-\\tan\\theta)}\\,.\n\\end{form}\nSimplifying the last equation gives:\n\\vspace{-2ex}\n\\begin{form}{1}\n(\\tan\\theta)^3-a_2(\\tan\\theta)^2+a_1(\\tan\\theta)-a_0&=&0\\\\\n-(\\tan\\theta)^3+a_2(\\tan\\theta)^2-a_1(\\tan\\theta)+a_0&=&0\\\\\n(-\\tan\\theta)^3+a_2(-\\tan\\theta)^2+a_1(-\\tan\\theta)+a_0&=&0\\,.\n\\end{form}\nWe conclude that $-\\tan\\theta$ is a real root of $p(x)=x^3+a_2x^2+a_1x+a_0$.\n\n\n\\begin{center}\n\\begin{tikzpicture}[scale=1.15]\n% Draw grid and axes\n\\draw[step=10mm,white!50!black] (-11,-1) grid (2,7);\n\\draw[thick] (-11,0) -- (2,0);\n\\draw[thick] (0,-1) -- (0,7);\n\\foreach \\x in {-10,...,2}\n  \\node at (\\x-.3,-.2) {\\sm{\\x}};\n\\foreach \\y in {1,...,7}\n  \\node at (-.2,\\y-.3) {\\sm{\\y}};\n  \n% Draw the points of the first path\n\\coordinate (A) at (0,0);\n\\coordinate (B) at (1,0);\n\\coordinate (C) at (1,6);\n\\coordinate (D) at (-10,6);\n\\coordinate (E) at (-10,0);\n\\foreach \\x in {A,B,C,D,E}\n  \\fill (\\x) circle(2pt);\n\\draw[rotate=90] (B) rectangle +(10pt,10pt);\n  \n% Draw A -- B and arrow\n\\draw[very thick] (A) --(B);\n\\draw[thick,<->] ($(A)+(0,-16pt)$) --\n  node[fill=white] {$1$} ($(B)+(0,-16pt)$);\n\n% Draw B -- C and arrow\n\\draw[very thick,name path=bc] (B) -- (C);\n\\draw[thick,<->] ($(B)+(36pt,0)$) --\n  node[fill=white] {$a_2$} ($(C)+(36pt,0)$);\n\n% Draw C -- D and arrow\n\\draw[very thick,name path=cd] (C) --(D);\n\\draw[thick,<->] ($(C)+(0,24pt)$) -- \n  node[fill=white] {$a_1$} ($(D)+(0,24pt)$);\n\n% Draw D -- E and arrow\n\\draw[very thick,name path=de] (D) -- (E);\n\\draw[thick,<->] ($(D)+(-16pt,0)$) --\n  node[fill=white] {$a_0$} ($(E)+(-16pt,0)$);\n\n% Draw first angled segment of the second path and intersection A2 with BC\n\\path[name path=a2] (A) -- +(63.4:4);\n\\path [name intersections = {of = a2 and bc, by = {A2}}];\n\\fill (A2) circle(2pt) node[above right] {$P$};\n\\draw[very thick,dashed] (A) -- (A2);\n\\path (B) -- node[right] {$b_2$} (A2);\n\\path (A2) -- node[right,yshift=8pt] {$a_2-b_2$} (C);\n\\draw[rotate=153.4] (A2) rectangle +(10pt,10pt);\n\n% Draw second segment of the second path and intersection B2 with CD\n\\path[name path=b2] (A2) -- +(153.4:10);\n\\path [name intersections = {of = b2 and cd, by = {B2}}];\n\\fill (B2) circle(2pt) node[above right] {$Q$};\n\\draw[very thick,dashed] (A2) -- (B2);\n\\draw[rotate=243.4] (B2) rectangle +(10pt,10pt);\n\\path (D) -- node[above] {$a_1-b_1$} (B2); \n\\path (B2) -- node[above] {$b_1$} (C);\n\n% Draw third segment of the second path to E\n\\draw[very thick,dashed] (B2)-- (E);\n\n% Label A, A2, B2 with theta\n\\draw ($(A) + (14pt,0)$)\n  arc [start angle=0, end angle = 63.4, radius=14pt];\n\\node[above right,xshift=10pt,yshift=8pt] at (A) {$\\theta$};\n\\draw ($(A2) + (0,14pt)$)\n  arc [start angle=90, end angle = 153.4, radius=14pt];\n\\node[above left,xshift=-4pt,yshift=14pt] at (A2) {$\\theta$};\n\\draw ($(B2) + (-14pt,0)$)\n  arc [start angle=180, end angle = 243.4, radius=14pt];\n\\node[below left,xshift=-14pt,yshift=-4pt] at (B2) {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n", "meta": {"hexsha": "d0802e9bdd032bee0c39271ef3cc7aa77b7968e0", "size": 27805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lill.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": "lill.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": "lill.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": 41.5620328849, "max_line_length": 759, "alphanum_fraction": 0.6275130372, "num_tokens": 10685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.8962513807543223, "lm_q1q2_score": 0.6496659858912462}}
{"text": "\\section{Model and strategy} % (fold)\n\\label{sec:model_and_strategy}\n\n%\\subsection{Board description} % (fold)\n%\\label{sub:board_description}\n\n% \n% \\paragraph{Change of square values and traps definition} % (fold)\n% \\label{par:change_of_square_values_and_traps_definition}\n% \n% % paragraph change_of_square_values_and_traps_definition (end)\n% \n% \\paragraph{No consecutive traps} % (fold)\n% \\label{par:no_consecutive_traps}\n% A first assumption in the way we defined our board concerns the non-existence\n% of domino effect of traps. This means that the only way to activate a trap\n% is to fall on its box immediately after one dice throw.\n% For example, if one lands on box 8, which is a type 3 [??? type 2 if we can not\n% modify the project rules] trap, it brings us back to box 5. In this case,\n% even if box 5 is a trap, it won't affect us until the following dice throw\n% (i.e. if a 0 is made at the following dice throw).\n% % paragraph no_consecutive_traps (end)\n% \n% % subsection board_description (end)\n\n\\subsection{Markov model} % (fold)\n\\label{sub:markov_model}\nLet us first recall the general idea behind Markov decision processes.\nThe objective is to determine the best set of actions $\\{u(1), u(2), \\dots\nu(n)\\}$ that minimizes $V_{\\pi}(s_0)$, the total expected cost of the process.\nThe algorithm we use in order to determine this set is the one based on Bellman equation\n\\[\n  V(k) \\leftarrow \\min_{a\\in U(k)} \\{c(a|k) \n  + \\sum_{k'=1}^n p(k'|k,a)V(k') \\} \\qquad k \\neq d\n\\]\nwhere $V(d)$ is set to 0 at each iteration, $d$ being the destination state.\nIn this \\emph{value-iteration} algorithm, $c(a|k)$ and $p(k'|k,a)$\nrespectively represent the \\emph{cost} of making action $a$\nwhen being in state $k$ and the \\emph{probability} of going\nfrom state $k$ to $k'$ when action $a$ is triggered.\n\nIt is proven that if we find a set of values $\\{V(1), \\dots, V(n)\\}$\nthat satisfies this set of equations, then it is \\emph{optimal}\nand it can be solved by \\emph{recursion}.\n\nLinking this process to our \\textit{Snakes and Ladders} game,\na state $k$ corresponds to \\emph{being on} the kth square,\nthus taking values in the range 1 to 15.\nWe then define the action $a$ as the \\emph{throw of a dice}\nand since every one of the three dices can be thrown at each\niteration we have $U(1) = \\dots = U(15) = \\{a_{\\text{secu}},\na_{\\text{norm}}, a_{\\text{risk}}\\}$.\nFinally, recalling that the goal of the game is to get to\nthe 15th square by \\emph{minimizing the number of dice throws},\nthe cost $c(a|k)$ equals 1 as each turn will lead in one dice\nthrow, whatever the action $a$ or the state $k$. \n\nAt this point only one last ingredient is missing to start implementing\nthe above described algorithm~: the transition probabilities $p(k'|k,a)$.\nHere lies the first main difficulty of the project as those depends\nboth on the type of square or trap from which one leaves $k$ and\non which one will arrive $k'$, as well as on the dice one\ndecides to use (i.e. $a$).\nIt is now important to \\emph{find an efficient way of constructing\nthe 3 transition probability matrices} $P_{\\text{secu}}$, $P_{\\text{norm}}$\nand $P_{\\text{risk}}$ by minimizing the number of particular cases,\nas one can not even imagine to compute the $3\\times 15^2$ individual probabilities.\n\nThe precise implementation of the probability matrices won't be\ndiscussed in this section but it appeared important to us\nto still make a point on the mathematical idea of our method.\n\\begin{enumerate}\n  \\item First we fill the matrix by assuming that\n  all squares are normal squares and thus filling the matrices\n  with probabilities $\\frac{1}{2}$, $\\frac{1}{3}$ and $\\frac{1}{4}$,\n  making particular cases for the slow/fast \\emph{lanes}\n  and the \\emph{circularity} of the board.\n  \\item Then we re-modify each matrix line by taking \\emph{traps} into account\n  and thus re-distributing the traps transition probabilities.\n  For example, if there a \\emph{type 2 trap} at square 8 \n  and the \\emph{normal} dice is thrown, we make the following adjustments\n  for each line $i$.\n  \\begin{align*}\n    p(i,5) &\\leftarrow p(i,5) + p(i,8)/2 \\\\\n     p(i,8) &\\leftarrow p(i,8)/2\n  \\end{align*}\n\\end{enumerate}\n\n% subsection markov_model (end)\n\n\\subsection{Finding the optimal dice} % (fold)\n\\label{sub:choosing_the_optimal_dice}\nOnce the algorithm converged and we obtained the optimal \ncost values $\\{V(1), \\dots, V(n)\\}$, the optimal dices that\nlead to these expected cost can be retrieved by applying\nthe following formula\n\\[\n  u(k) \\leftarrow \\arg\\min_{a\\in U(k)} \\{c(a|k) \n  + \\sum_{k'=1}^n p(k'|k,a)V(k') \\} \\qquad k \\neq d\n\\]\nThis formula returns at each iteration the action\n(i.e. the \\emph{type of dice}) that enables to reach the minimum\nexpected cost contained in the values $\\{V(1), \\dots, V(n)\\}$.\n\n% subsection choosing_the_optimal_dice (end)\n\n% section model_and_strategy (end)", "meta": {"hexsha": "7834ef5e1135b20c7f2c15e5dab109a95b08f2b8", "size": 4843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/src/model.tex", "max_stars_repo_name": "qlete/markov-decision", "max_stars_repo_head_hexsha": "9043e8e014b165dff2ebe9be77f8630d7b8d2237", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-03-21T13:48:00.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-21T13:48:00.000Z", "max_issues_repo_path": "report/src/model.tex", "max_issues_repo_name": "qlete/markov-decision", "max_issues_repo_head_hexsha": "9043e8e014b165dff2ebe9be77f8630d7b8d2237", "max_issues_repo_licenses": ["MIT"], "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/src/model.tex", "max_forks_repo_name": "qlete/markov-decision", "max_forks_repo_head_hexsha": "9043e8e014b165dff2ebe9be77f8630d7b8d2237", "max_forks_repo_licenses": ["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.261682243, "max_line_length": 88, "alphanum_fraction": 0.7257897997, "num_tokens": 1417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6496659783584912}}
{"text": "% Created 2020-01-22 Wed 15:54\n% Intended LaTeX compiler: pdflatex\n\\documentclass[11pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\author{Vaibhav Pujari}\n\\date{\\today}\n\\title{Foundations of Haskell}\n\\hypersetup{\n pdfauthor={Vaibhav Pujari},\n pdftitle={Foundations of Haskell},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.3)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\n\n\\section{Lambda calculus and Category theory}\n\\label{sec:org3dd5759}\n\\begin{itemize}\n\\item Everything is a function\n\\item There is no error reporting - not that practical because there is no help from compiler\n\\item If we introduce error checking and types, we deviate from lambda calculus because not every expression is correct. But we also gain a lot of practical value\n\\item This then becomes a category - because in category composition is not arbitrary, it is constrained by morphisms\n\\end{itemize}\n\\section{The language}\n\\label{sec:org5892609}\n\\subsection{Data types}\n\\label{sec:org305db3e}\n\\begin{verbatim}\nx :: Int\nx = 5\n\\end{verbatim}\n\\subsection{Function types}\n\\label{sec:org3b97478}\nTypes are sets and in category of sets, a function is a member of Hom-set between two objects, so its a member of some other object in the same category (every set is an object)\n\\subsection{Partial functions}\n\\label{sec:org816f474}\n\\begin{itemize}\n\\item Recursion can create programs that never terminate\n\\item Well-founded recursion - compiler can prove that it terminates. But its a theoretical concept because for every algorithm that claims to find out if a recursion is well-founded or not, there always exists a particual recursion that breaks the algorithm\n\\item Therefore, in practice we need partial functions. A partial function gives result when it terminates, but there is no guarantee that it will terminate\n\\end{itemize}\n\\subsection{Composition}\n\\label{sec:org97e878e}\n\\begin{verbatim}\n(.) :: (b->c) -> (a->b) -> a -> c\n(g . f) x = g ( f x )\n\\end{verbatim}\nPolymorphic types and higher order functions are foundational in haskell as opposed to a later added feature in most common languages\n\\subsection{Functors}\n\\label{sec:org7e9a78e}\n\\begin{itemize}\n\\item A structure-preserving mapping between two categories\n\\begin{itemize}\n\\item To preserve objects, we just need a type constructor\n\\end{itemize}\n\nF: Ob(Hask) \\(\\to\\) Ob(Hask)\n\n\\begin{itemize}\n\\item To preserve morphism structure, we need \\texttt{fmap}. \\texttt{fmap} maps morphism in first category to a morphism in second category such that it is still composable in the same way as original morphism was composable\n\\end{itemize}\n\nfmap: Hom\\textsubscript{Hask} \\(\\to\\) Hom\\textsubscript{Hask}\n\n\\item Shrinking the structure is a special case of preserving. When objects collapse, the morphisms must follow\n\\item There is a category \\texttt{Cat}, in which objects are smaller categories and morphisms are functors\n\\end{itemize}\n\\end{document}\n", "meta": {"hexsha": "80b5c5c4e6d6a9f979687e5fadd2362ca3ce41c3", "size": 3193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03-haskell-foundations.tex", "max_stars_repo_name": "vaibhav276/category-theory-notes", "max_stars_repo_head_hexsha": "164285a8ace6bcf86f19a083255c029a2c39cdbe", "max_stars_repo_licenses": ["MIT"], "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-haskell-foundations.tex", "max_issues_repo_name": "vaibhav276/category-theory-notes", "max_issues_repo_head_hexsha": "164285a8ace6bcf86f19a083255c029a2c39cdbe", "max_issues_repo_licenses": ["MIT"], "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-haskell-foundations.tex", "max_forks_repo_name": "vaibhav276/category-theory-notes", "max_forks_repo_head_hexsha": "164285a8ace6bcf86f19a083255c029a2c39cdbe", "max_forks_repo_licenses": ["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.1279069767, "max_line_length": 258, "alphanum_fraction": 0.7785781397, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6496192680134897}}
{"text": "\n\\subsection{Convergence}\n\nIf \\(x=c\\) then the power series will be equal to \\(a_0\\).\n\nFor other values the power series may not converge.\n\n\\subsubsection{Cauchy-Hadamard theorem}\n\nRadius of convergence:\n\n\\(\\dfrac{1}{R}={\\lim \\sup}_{n_\\rightarrow \\infty} (|a_n|^{\\dfrac{1}{n}})\\)\n\n", "meta": {"hexsha": "691493ca9b8bb3da3595e470a505847e4aea5c12", "size": 281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/02-02-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/transformations/02-02-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/transformations/02-02-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": 20.0714285714, "max_line_length": 74, "alphanum_fraction": 0.6939501779, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6495862384240451}}
{"text": "\\chapter{Unit 3}\n\\section{Related Rates}\nRelated rates are a technique of differentiation that allows us to examine the\nrate of change of one quantity, with respect to the rate of change of several\nother quantitities.\n\nThe process for using related rates in calculus is as follows:\n\\begin{enumerate}\n  \\item Identify all of the given quantities, and the quantities to be\n    determined.\n  \\item Write an equation involving the variables whos rates of change are\n    given, or to be determined.\n  \\item Use the Chain Rule to differentiate both sides of the equation with\n    respect to time.\n  \\item Substitute all known values for rates of change into the original\n    equation.\n\\end{enumerate}\n\nAn example follows below:\n\\textit{Air is being pumped into a spherical balloon at a rate of\n\\SI{4.5}{\\meter\\cubed\\per\\minute}. Find the rate of change of the radius when the\nradius is \\SI{2}{\\meter}.}\n\n\\begin{align*}\n  \\frac{dV}{dt} &= \\frac{9}{2} \\\\\n  \\frac{dr}{dt} \\text{when} r=2 \\\\\n  V &= \\frac{4}{3}\\pi{r^3} \\\\\n  \\frac{dV}{dt} &= 4\\pi{r^2}\\frac{dr}{dt} \\\\\n  \\frac{dr}{dt} &= \\frac{1}{4\\pi(2^2)}\\frac{9}{2}\n\\end{align*}\n\n\\section{Application of Derivatives}\n\\subsection{Extrema on an Interval}\nDefinition of extrema:\n\\begin{enumerate}\n  \\item $f(c)$ is the minimum of $f$ on $I$ when $f(c) \\leq f(x) \\forall x \\in\n    I$\n  \\item $f(c)$ is the maximum of $f$ on $I$ when $f(c) \\geq f(x) \\forall x \\in\n    I$\n\\end{enumerate}\n\n\\subsubsection{The Extreme Value Theorem}\nIf $f$ is continuous on a closed interval $[a,b]$ then $f$ has both a minimum\nand a maximum on the closed interval.\n\n\\subsubsection{Relative Extrema}\n\\begin{enumerate}\n  \\item If there is an open interval containing $c$ on which $f(c)$ is a\n    minimum then $f(c)$ is a relative minimum of $f$.\n  \\item If there is an open interval containing $c$ on which $f(c)$ is a\n    maximum then $f(c)$ is a relative maximum of $f$.\n\\end{enumerate}\n\n\\subsubsection{Critical Number}\nIf $f$ is defined at $c$ and $f'(c)=0$ or is undefined, then $c$ is a critical\nnumber of $f$.\n\nIf $f$ has a relative minimum or relative maximum at $x=c$, then $c$ is a\ncritical number of $f$.\n\nTo find critical numbers of $f$ on $[a,b]$, use the following process:\n\\begin{enumerate}\n  \\item Find the critical numbers of $f$ on $(a,b)$.\n  \\item Evaluate $f$ at each of those critical numbers.\n  \\item Evaluate $f$ at each of the endpoints of $[a,b]$.\n  \\item The least of these values is the minimum. The greatest is the maximum.\n\\end{enumerate}\n\n\\subsection{Rolle's Theorem \\& Mean Value Theorem}\n\\subsubsection{Rolle's Theorem}\nLet $f$ be a continuous function defined on a closed interval $[a,b]$. If\n$f(a)=f(b)$ then there is at least one $c\\in(a,b)$ such that $f'(c)=0$.\n\n\\subsubsection{Mean Value Theorem}\nLet $f$ be a continuous function defined $\\forall{x}\\in [a,b]$, and\ndifferentiable over $x\\in(a,b)$. $c\\in(a,b)\\to f'(c)=\\frac{f(b)-f(a)}{b-a}$.\n\n\\subsection{Increasing and Decreasing Functions}\nLet $f$ be a function defined over some open interval. For all critical numbers,\nthe following can be said about the function:\n\\begin{description}\n  \\item[$f'(x)>0$] $f(x)$ increasing\n  \\item[$f'(x)<0$] $f(x)$ decreasing\n  \\item[$f'(x)=0$] $f(x)$ constant\n\\end{description}\n\n\\subsubsection{First Derivative Test}\n\\begin{enumerate}\n  \\item If $f'(x)$ changes from negative to positive at $x=c$, then there is a\n    relative minumum on $f$ at $x=c$.\n  \\item If $f'(x)$ changes from positive to negative at $x=c$, then there is a\n    relative maximum on $f$ at $x=c$.\n\\end{enumerate}\n\n\\subsection{Concavity}\nLet $f$ be differentiable on an open interval $I$. The graph of $f$ is concave\nupward on $I$ when $f'(x)$ is increasing on the interval and concave downward\nwhen $f'(x)$ is decreasing on the interval.\n\n\\subsubsection{Test for Concavity}\nLet $f$ be a function whose second derivative exists $\\forall{x}\\in(a,b)$.\n\\begin{description}\n  \\item[$f''(x)>0\\forall{x}\\in{I}$] $f$ is concave upward on $I$.\n  \\item[$f''(x)<0\\forall{x}\\in{I}$] $f$ is concave downward on $I$.\n\\end{description}\n\n\\subsection{Limits at Infinity}\nHorizontal asymptotes of a function can be determined when the limit of that\nfunction at a positive or negative $\\infty$ is a value $L$.\n\nLet $L$ be a horizontal asymptote of a function $f$.\n\\begin{equation}\n  L = \\lim_{x\\to\\pm\\infty} f(x)\n\\end{equation}\n\n\\subsection{Curve Sketching}\nTo sketch a curve, implement the following process:\n\n\\begin{enumerate}\n  \\item determine the $x$-intercepts\n  \\item determine the $y$-intercepts\n  \\item Determine any vertical asymptotes by seeing where $f(x)$ becomes\n    undefined.\n  \\item Determine any horizontal asymptotes by evaluating the limits at\n    $\\pm\\infty$.\n  \\item Determine the critical numbers of the first derivative to sketch a\n    general curve of the graph.\n  \\item Determine the critical numbers of the second derivative to determine\n    points of inflection.\n\\end{enumerate}\n\n\\section{Optimization}\nTo optimize a problem, follow steps very similar to those described in the\nsection on Related Rates.\n\\begin{enumerate}\n  \\item Set up a related rates problem.\n  \\item Determine the feasiable domain of the problem.\n  \\item Evaluate the function.\n  \\item Determine critical numbers to find the relative maximum or minimum.\n\\end{enumerate}\n\n\\section{Newton's Method}\nNewton's method is a convenient way to determine the zeros of a function. To\nsolve for a zero using Newton's method, use the following process:\n\\begin{enumerate}\n  \\item Make an initial estimate $x_1$ that is close to $c$.\n  \\item Determine $x_{n+1}=x_n-\\frac{f(x_n)}{f'(x_n)}$.\n  \\item See step 2.\n\\end{enumerate}\n\n\\section{Differentials}\n", "meta": {"hexsha": "efdef64a57dbae062c8b7681e4d341b96a7f0b26", "size": 5626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016/bc_calculus/units/unit_3.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_3.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_3.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.0131578947, "max_line_length": 81, "alphanum_fraction": 0.7099182368, "num_tokens": 1660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6495292971039955}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 1.11 Cycling free indices -- preferred solution}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,u,v,w}::Indices.\n\n   expr := A_{a b c}.                                             # cdb (ex-0111.101,expr)\n\n   rule := T_{a b c} -> @(expr).\n   expr := T_{b c a}.                                             # cdb (ex-0111.102,expr)\n\n   substitute (expr, rule)                                        # cdb (ex-0111.103,expr)\n\\end{cadabra}\n\n\\begin{align*}\n   &\\Cdb{ex-0111.101}\\\\\n   &\\Cdb{ex-0111.102}\\\\\n   &\\Cdb{ex-0111.103}\n\\end{align*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 1.11 Cycling free indices -- alternative solution}\n\nThis alternative solution uses two rounds of Kroncker deltas. It does the job but is not as\nsimple as the previous solution.\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,u,v,w}::Indices.\n\n   \\delta{#}::KroneckerDelta.\n\n   expr := A_{a b c}.                                             # cdb (ex-0111.201,expr)\n\n   expr := \\delta^{a}_{u} \\delta^{b}_{v} \\delta^{c}_{w} @(expr).  # cdb (ex-0111.202,expr)\n\n   eliminate_kronecker (expr)                                     # cdb (ex-0111.203,expr)\n\n   expr := \\delta^{u}_{b} \\delta^{v}_{c} \\delta^{w}_{a} @(expr).  # cdb (ex-0111.204,expr)\n\n   eliminate_kronecker (expr)                                     # cdb (ex-0111.205,expr)\n\n\\end{cadabra}\n\n\\begin{align*}\n   &\\Cdb{ex-0111.201}\\\\\n   &\\Cdb{ex-0111.202}\\\\\n   &\\Cdb{ex-0111.203}\\\\\n   &\\Cdb{ex-0111.204}\\\\\n   &\\Cdb{ex-0111.205}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "859d2b61c6fc103c861c25783e80254098da2d13", "size": 1773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0111.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-0111.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-0111.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": 28.5967741935, "max_line_length": 94, "alphanum_fraction": 0.475465313, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.853912754810561, "lm_q1q2_score": 0.6495292942761144}}
{"text": "\\documentclass[a4paper, 12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{color}\n\\usepackage{dsfont}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage[left=2cm, right=2cm, bottom=3cm, top=2cm]{geometry}\n\\usepackage{natbib}\n\\usepackage{microtype}\n\n\\definecolor{orange}{rgb}{1, 0.5, 0}\n\\definecolor{darkgreen}{rgb}{0, 0.5, 0}\n\\definecolor{darkred}{rgb}{0.7, 0, 0}\n\\newcommand{\\btheta}{\\boldsymbol{\\theta}}\n\\newcommand{\\tn}{\\textnormal}\n\n\\title{Notes}\n\\author{Brendon J. Brewer}\n\\date{}\n\\begin{document}\n\\maketitle\n\n% Need this after the abstract\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{8pt}\n\n\\section{A property of Nested Sampling}\nConsider the implied prior for $L$, denoted $\\pi(L)$. This is\na probability distribution over the real line.\nAs usual, define $X(\\ell)$ as the amount of prior mass\nwith likelihood above $\\ell$:\n\\begin{align}\nX(\\ell) &= \\int_\\ell^\\infty \\pi(L) \\, dL.\n\\end{align}\nThis is the complementary CDF of $L$.\n\nThe NS sequence rectifies $\\pi$ to give you the distribution\n\\begin{align}\np_{\\rm NS}(L) &= \\frac{1}{C} \\frac{\\pi(L)}{X(L)}\n\\end{align}\nwhere\n\\begin{align}\nC &= \\int_{-\\infty}^{L_{\\rm max}} \\frac{\\pi(L)}{X(L)} \\, dL\n\\end{align}\nis a normalising constant,\nand $L_{\\rm max}$ is the maximum likelihood from the\ndiscarded points of the run\n(not necessarily the overall maximum likelihood).\n\nConsider a `constrained prior' distribution, which is just the\nprior $\\pi$ but truncated so it only includes values above\na threshold $\\ell$:\n\\begin{align}\np(L \\,|\\, \\ell) &\\propto\n               \\left\\{\n                 \\begin{array}{lr}\n                   \\pi(L),&  L > \\ell, \\\\\n                   0,     &  \\tn{otherwise}.\n                 \\end{array}\n               \\right.\n\\end{align}\nThe normalisation constant of a constrained prior is\njust $X(\\ell)$.\n\nNS gives us the opportunity to measure this for any given\nvalue of $\\ell$. Consider the KL divergence from $p_{\\rm NS}$ to\nthe constrained prior:\n\\begin{align}\nD_{\\rm KL}(p_\\ell \\,||\\, p_{\\rm NS})\n  &= \\int_{\\ell}^{\\infty} \\frac{\\pi(L)}{X(\\ell)}\n           \\log\\left[\\frac{\\pi(L)/X(\\ell)}{\\pi(L)/C/X(L)}\\right] \\, dL \\\\\n  &= \\int_{\\ell}^{\\infty} \\frac{\\pi(L)}{X(\\ell)}\n           \\log\\left[\\frac{CX(L)}{X(\\ell)}\\right] \\, dL\n\\end{align}\nWe can take the expectation (integral) in terms of $X$ instead of\n$L$, and use the fact that the prior corresponds to a\nUniform$(0,1)$ distribution for $X$:\n\\begin{align}\nD_{\\rm KL}(p_\\ell \\,||\\, p_{\\rm NS})\n    &= \\int_0^{X(\\ell)} \\frac{1}{X(\\ell)}\n           \\log(X) \\, dX - \\log X(\\ell) + \\log C \\\\\n    &= \\frac{1}{X(\\ell)} \\int_0^{X(\\ell)} \\log(X) \\, dX\n           - \\log X(\\ell) + \\log C \\\\\n    &= \\frac{1}{X(\\ell)}\\left[X\\log(X) - X\\right]_0^{X(\\ell)}\n           - \\log X(\\ell) + \\log C \\\\\n    &= \\log X(\\ell) - 1 - \\log X(\\ell) + \\log C \\\\\n    &= \\log C - 1.\n\\end{align}\nCrucially, {\\em this does not depend on} $\\ell$.\n\n\\section{Uniqueness}\nIs $p_{\\rm NS}$ the only distribution with the above property?\nConsider the KL divergence from some distribution $q$\nto the constrained prior.\nWe will then see what choices of $q$ have the above property.\nThe KL divergence is\n\\begin{align}\nD_{\\rm KL}(p_\\ell \\,||\\, q)\n  &= \\int_{\\ell}^{\\infty} \\frac{\\pi(L)}{X(\\ell)}\n           \\log\\left[\\frac{\\pi(L)/X(\\ell)}{q(L)}\\right] \\, dL \\\\\n  &= -\\log X(\\ell) + \\frac{1}{X(\\ell)}\n    \\int_{\\ell}^{\\infty} \\pi(L)\n               \\log\\left[\\frac{\\pi(L)}{q(L)}\\right] \\, dL\n\\end{align}\n\nThe derivative of the KL divergence, with respect to $\\ell$, is\n\\begin{align}\n\\frac{d}{d\\ell} D_{\\rm KL}(p_\\ell \\,||\\, q)\n  &= -\\frac{X'(\\ell)}{X(\\ell)}\n     + \\frac{X(\\ell)\\pi(\\ell)\\log\\left[\\pi(\\ell)/q(\\ell)\\right]\n             -X'(\\ell)\\int_{\\ell}^{\\infty} \\pi(L)\n               \\log\\left[\\pi(L)/q(L)\\right] \\, dL}\n            {X(\\ell)^2} \\\\\n  &= -\\frac{X'(\\ell)}{X(\\ell)}\n     + \\frac{\\pi(\\ell)\\log\\left[\\pi(\\ell)/q(\\ell)\\right]}\n            {X(\\ell)}\n     - \\frac{X'(\\ell)/X(\\ell)\\int_{\\ell}^{\\infty} \\pi(L)\n               \\log\\left[\\pi(L)/q(L)\\right] \\, dL}\n            {X(\\ell)}\\\\\n  &= -\\frac{X'(\\ell)}{X(\\ell)}\n     + \\frac{\\pi(\\ell)\\log\\left[\\pi(\\ell)/q(\\ell)\\right]}\n            {X(\\ell)}\n     - \\frac{X'(\\ell)\\left(D_{\\rm KL} + \\log X(\\ell)\\right)}\n            {X(\\ell)} \\\\\n  &= \\frac{\\pi(\\ell)}{X(\\ell)}\n        \\Big(1\n             + \\log\\left[\\pi(\\ell)/q(\\ell)\\right]\n             + D_{\\rm KL} + \\log X(\\ell)\n        \\Big)\n\\end{align}\nTo satisfy the nice property of the previous section, the derivative\nmust be zero. This is achieved if\n\\begin{align}\n1 + \\log\\left[\\pi(\\ell)/q(\\ell)\\right]\n+ D_{\\rm KL} + \\log X(\\ell) &= 0 \\\\\n1 + \\log\\pi(\\ell) - \\log q(\\ell)\n+ D_{\\rm KL} + \\log X(\\ell) &= 0\n\\end{align}\n\n\n%\\section*{TwinPeaks}\n%Denote the two scalars by $L_1(\\btheta)$ and $L_2(\\btheta)$.\n%The implied prior for $L_1$ and $L_2$ is $\\pi(L_1, L_2)$.\n%Consider a constrained distribution\n%\\begin{align}\n%p(L_1, L_2 \\,|\\, \\ell_1, \\ell_2) &\\propto\n%    \\left\\{\n%        \\begin{array}{lr}\n%            \\pi(L_1, L_2),  &   L_1 > \\ell_1 \\tn{ and } L_2 > \\ell_2 \\\\\n%            0,              &   \\tn{otherwise}.\n%        \\end{array}\n%    \\right.\n%\\end{align}\n%The normalising constant of this distribution is\n%\\begin{align}\n%X(\\ell_1, \\ell_2) &=\n%    \\int_{\\ell_1}^{\\infty}\n%    \\int_{\\ell_2}^{\\infty}\n%        \\pi(L_1, L_2)\n%    \\, dL_1\n%    \\, dL_2.\n%\\end{align}\n\n%My proposed TwinPeaks distribution is\n%\\begin{align}\n%p_{\\rm TP}(L_1, L_2) &=\n%  \\frac{1}{C}\n%  \\frac{\\pi(L_1, L_2)}{X(L_1, L_2)}.\n%\\end{align}\n%As in the previous section, we can compute the KL divergence from\n%this to a constrained prior:\n%\\begin{align}\n%D_{\\rm KL}(p_{\\ell_1, \\ell_2} \\,||\\, p_{\\rm TP})\n%  &= \\int_{\\ell_1}^{\\infty}\n%     \\int_{\\ell_2}^{\\infty}\n%         \\frac{\\pi(L_1, L_2)}{X(\\ell_1, \\ell_2)}\n%         \\log\\left[C \\frac{X(L_1, L_2)}{X(\\ell_1, \\ell_2)} \\right]\n%     \\, dL_1\n%     \\, dL_2 \\\\\n%  &=\n%     \\int_{\\ell_1}^{\\infty}\n%     \\int_{\\ell_2}^{\\infty}\n%         \\frac{\\pi(L_1, L_2)}{X(\\ell_1, \\ell_2)}\n%         \\log\\left[C \\frac{X(L_1, L_2)}{X(\\ell_1, \\ell_2)} \\right]\n%     \\, dL_1\n%     \\, dL_2 \\\\\n%  &=\n%     \\log C \\,-\\, \\log X(\\ell_1, \\ell_2) \\\\ &\\quad\\quad\\quad\n%     \\,+\\,\n%     \\frac{1}{X(\\ell_1, \\ell_2)}\n%     \\int_{\\ell_1}^{\\infty}\n%     \\int_{\\ell_2}^{\\infty}\n%         \\pi(L_1, L_2)\n%         \\log X(L_1, L_2)\n%     \\, dL_1\n%     \\, dL_2 \\\\\n%\\end{align}\n%Doing the integral in terms of $X$\n\n\\section{Commutativity}\nDoes the operation of constraining by $f(\\theta)$ by a factor of $t_1$\ncommute with the operation of constraining by $g(\\theta)$ by a factor\nof $t_2$? I think so...that's the product rule, right?\n\nThe first route yields the following sequence of distributions:\n\\begin{align}\n\\pi(\\theta)\n    \\implies\n\\frac{\\pi(\\theta)\\mathds{1}\\big(f(\\theta) \\geq f^*\\big)}{t_1}\n    \\implies\n\\frac{\\pi(\\theta)\\mathds{1}\\big(f(\\theta) \\geq f^*\\big)\\mathds{1}\\big(g(\\theta) \\geq g^*\\big)}{t_1t_2}\n\\end{align}\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "0ae967dfc29c246ae0e8e31e867f546fc4897dd1", "size": 6845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes.tex", "max_stars_repo_name": "eggplantbren/TwinPeaks-hs", "max_stars_repo_head_hexsha": "a4da4fe17d586fe75cc09d6cddfaa6b3052aeea8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-10T03:16:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-10T03:16:50.000Z", "max_issues_repo_path": "doc/notes.tex", "max_issues_repo_name": "eggplantbren/TwinPeaks-hs", "max_issues_repo_head_hexsha": "a4da4fe17d586fe75cc09d6cddfaa6b3052aeea8", "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/notes.tex", "max_forks_repo_name": "eggplantbren/TwinPeaks-hs", "max_forks_repo_head_hexsha": "a4da4fe17d586fe75cc09d6cddfaa6b3052aeea8", "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.3990825688, "max_line_length": 102, "alphanum_fraction": 0.5701972243, "num_tokens": 2613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6495292910568545}}
{"text": "\\section{Experiment 1: Simulated Data from Multivariate Normal Distribution}\n\n\tIn the first simulation experiment, we focused on an ideal setting where data come from a known multivariate normal \n\tdistribution and imputation is required to estimate the means, variances, and covariances of six items with \n\tmissing values.\n\tWe investigated the relative performance of the methods described above across a set of conditions defined by two \n\texperimental factors: the number of columns in the dataset $p$, taking values 50 or 500; \n\tand the proportion of \\emph{per} variable missing cases $pm$, taking values 0.1 or 0.3.\n\tTable \\ref{tab:condExp1} summarizes the four crossed conditions.\n\tData with sample size $n=200$ were independently generated $S = 1,000$ times for each condition.\n\tFor each $s$-th replicate, missing values were imposed and then all the missing data treatment methods described above\n\twere used to obtain estimates of the item means, variances, and covariances.\n\n\\begin{table}\n\t\\centering\n\t\\begin{tabular}{l | r | r | r | r }\n\t\tcondition & label & n & p & pm \\\\\n\t\t\\hline\n\t\t1 & low-dim-low-pm   & 200 & 50  & .1 \\\\\n\t\t2 & high-dim-low-pm  & 200 & 500 & .1 \\\\\n\t\t3 & low-dim-high-pm  & 200 & 50  & .3 \\\\\n\t\t4 & high-dim-high-pm & 200 & 500 & .3 \\\\\n\t\\end{tabular}\n\t\\caption{\\label{tab:condExp1}Summary of conditions for Experiment 1.}\n\\end{table}\n\n%\\FloatBarrier\n\n\\subsection{Simulation Study Procedure}\n\n\\subsubsection{Data Generation}\n\tAt every replication, a data matrix $\\bm{Z}_{n \\times p}$ was generated according to a multivariate normal model \n\tcentered around a mean of 0 with a covariance matrix $\\bm{\\Sigma}_0$, with diagonal elements (variances) equal to 1.\n\tThe off-diagonal elements of $\\bm{\\Sigma}_0$ were used to define three blocks of variables: \n\tthe first five variables were highly correlated among themselves ($\\rho = .6$);\n\tvariables 6 to 10 were weakly correlated with variables in block 1 and among themselves ($\\rho = .3$), \n\tand all the remaining $p-10$ variables were uncorrelated.\n\tItems were rescaled to have mean of 5.\n\n\\subsubsection{Missing Data Imposition} \\label{sub_missing}\n\n\tMissing values were imposed on six items in $\\bm{Z}$: three variables in the block of\n\thighly correlated variables ($z_j$ with $j = 1,2,3$), and three in the block of lowly correlated variables ($z_j$ \n\twith $j = 6,7,8$).\n\tItem non-response was imposed by sampling from a Bernoulli distribution with individual missing probabilities \n\tdefined by \n%\n\t\\begin{equation} \\label{eqn:rm}\n\t\tp_{miss} = p(z_{i,j} = miss | \\tilde{Z}) = \\frac{ exp(\\gamma_0 + \\tilde{Z}_{i}\\bm{\\gamma}) }\n\t\t\t\t\t\t\t\t{ 1 + exp(\\gamma_0 + \\tilde{Z}_{i}\\bm{\\gamma}) }\n\t\\end{equation}\n%\n\twhere $z_{i,j}$ is the $i$-th subject's response on the $j$-th variable target of missing data imposition, \n\t$\\tilde{Z}_{i}$ is a vector of responses to the set of predictors involved in the missing data mechanism \n\tfor the $i$-th individual, $\\gamma_0$ is an intercept parameter, and $\\bm{\\gamma}$ is a vector of slope \n\tparameters for the linear term.\n\t$\\tilde{Z}$ was specified to include two fully observed variables from the highly correlated set, and two \n\tfrom the lowly correlated set ($z_r$ with $r = 4,5,9,10$).\n\tThe probability of observing a response on a target variable did not depend on the variable itself, \n\tto avoid imputation under MNAR.\n\tFurthermore, when all the features in the data are provided to the MI procedures, the predictors in $\\tilde{Z}$ \n\tare allowed to be part of the imputation models and the MAR assumption can be met.\n\tAll slopes in $\\bm{\\gamma}$ were fixed to 1, while the value of $\\gamma_0$ was chosen with an optimization \n\talgorithm that minimized the difference between the actual and desired proportion of missing values.\n\n\\subsubsection{Imputation}\n\t\n\tMissing values were treated with all the methods described in Section 2.\n\tConvergence of the imputation models was assessed in a preprocessing step by observing trace plots.\n\tThe imputation algorithms were considered to have converged after 50 iterations, after which 10 imputed data \n\tsets were stored and used for the subsequent standard complete-data analysis and pooling.\n\tThe only exception was blasso, which required approximately 2,000 iterations for convergence.\n\n\tThe ridge penalty used in the bridge algorithm was fixed across iterations.\n\tThe value used in the simulation was determined by means of cross-validation in a preprocessing phase.\n\tThe ridge penalty values $10^{-1}, 10^{-2}, ..., 10^{-8}$ were used to impute data with bridge\n\tand we selected the value that resulted in the smallest average Fraction of Missing Information (FMI)\n\t\\citep[eq. 3.1.10]{rubin:1987} across the analysis model parameters.\n\t\t\n\tBoth IURR and DURR could have been specified with a variety of penalty parameters.\n\tFor example, one could use any of the following: ridge penalty \\citep{hoerlKennard:1970}, lasso penalty \n\t\\citep{tibshirani:1996}, elastic net penalty \\citep{zouHastie:2005}, adaptive lasso \\citep{zou:2006}.\n\tIn this study, we specified the lasso penalty for regularization as it is computationally efficient, \n\tand it performed well for imputation in \\cite{zhaoLong:2016} and \\cite{dengEtAl:2016}.\n\tA 10-fold cross-validation procedure was used at every iteration of DURR and IURR to choose the penalty parameter.\n\n\tFor blasso, in order to maintain consistency with previous research, the hyper-parameters in equations \n\t\\eqref{eqn:sigprior}, \\eqref{eqn:tauprior}, and \\eqref{eqn:rhoprior} were specified as in \\cite{zhaoLong:2016}: \n\t$(a,b)=(0.1, 0.1)$, $(r,s)=(0.01, 0.01)$, and $(g,h)=(1,1)$.\n\tIn the MI-PCA algorithm, enough components were extracted to explain 50\\% of the total variance in the data.\n\tTo impute data with the single imputation random forest approach we used the missForest R package \n\t\\citep{missForest} implementing algorithm 1 proposed by \\cite{stekhovenBuhlmann:2011}.\n\tThe stopping criterion for the missForest algorithm was usually met within the first 10 iterations, \n\tbut to make a conservative choice we fixed the maximum number of iterations to 20.\n\t\\cite{stekhovenBuhlmann:2011} showed that increasing the number of trees grown in each forest has \n\tstagnating effects on the imputation error while linearly increasing the computation time.\n\tIn their paper, the authors recommend growing 100 trees per forest, which offers a good compromise \n\tbetween imputation precision and computation time.\n\tTherefore, we used this value in our study.\n\n\\subsubsection{Analysis}\n\tThe substantive model of interest in Experiment 1 was a saturated model that estimated means,\n\tvariances, and covariances of the six variables with missing values.\n\tThis resulted in estimating six means, six variances, and 15 covariances.\n\n\\subsection{Comparison Criteria} \\label{criteria}\n\n\tWe compared methods in terms of bias and confidence interval coverage.\n\n\t\\paragraph{Bias}\n\n\tFor a given parameter of interest $\\theta$ (e.g., mean of item 1, variance of item 2), we used the \n\tPercent Relative Bias (PRB) to quantify the estimation bias introduced by the imputation procedures:\n%\n\t\\begin{equation} \\label{eqn:prb}\n\t\tPRB = \\frac{\\bar{\\hat{\\theta}} - \\dot{\\theta}}{\\dot{\\theta}} \\times 100\n\t\\end{equation}\n%\n\twhere $\\dot{\\theta}$ is the true value of the focal parameter defined as \n\t$\\sum_{s=1}^{S} \\hat{\\theta}_{s}^{GS}/S$\n\t, with\n\t$\\hat{\\theta}_{s}^{GS}$ \n\tbeing the Gold Standard parameter estimate for the $s$-th repetition. \n\tThe averaged focal parameter estimate under a given missing data treatment is computed as \n\t$\\bar{\\hat{\\theta}} = \\sum_{s=1}^{S} \\hat{\\theta}_{s}/S$,\n\twith\n\t$\\hat{\\theta}_{s}$ being the estimate obtained after having treated the missing values in the \n\t$s$-th repetition.\n\tFollowing \\cite{muthenEtAl:1987}, $|\\text{PRB}| > 10\\%$ was considered indicative of problematic \n\testimation bias.\n\n\t\\paragraph{Confidence Intervals Coverage}\n\tTo assess the correctness of hypothesis testing, the Confidence Interval Coverage (CIC) of the true parameter\n\tvalue was defined as:\n%\n\t\\begin{equation} \\label{eqn:cic}\n\t\tCIC =  \\frac{ \\sum_{s=1}^{S} I(\\dot{\\theta} \\in \\widehat{CI}_s ) }{S}\n\t\\end{equation}\n%\n\twhere $\\widehat{CI}_s$ is the confidence interval of the parameter estimate $\\hat{\\theta}_{s}$ in a given repetition, \n\tand $I(.)$ is the indicator function that returns 1 if the argument is true and 0 otherwise.\n\t\n\tCICs below 0.9 are usually considered problematic for 95\\% confidence intervals \\cite[p. 52]{vanBuuren:2018} \n\tas they imply inflated Type I error rates.\n\tA high coverage (e.g., 0.99) may indicate confidence intervals that are too wide, implying inflated Type II error rates.\n\tTherefore, Confidence Intervals were considered to show severe under-coverage (over-coverage) if they were \n\tbelow 0.9 (above 0.99).\n\n\tFollowing \\cite{burtonEtAl:2006}, in simulation studies, a CIC can be considered as significantly different from the \n\tnominal coverage rate if it falls outside two Standard Errors of the nominal coverage probability ($SE(p)$) from the \n\tnominal coverage rate.\n\tThe standard error of nominal coverage probability is defined as $SE(p) = \\sqrt{p (1-p)/S}$, with $p$ indicating the\n\tchosen nominal coverage probability.\n\tTherefore, for $S = 1000$, 95\\% CI coverages ($p = 0.95$) outside the range (0.94, 0.96) were considered as significantly \n\tdifferent from the nominal coverage rate.\n\n\\subsection{Results}\n\t\n\tBoth PRB and CIC were computed for all the 27 parameters in the analysis model (six means, six item variances,\n\tand 15 covariances).\n\tTo summarize the results, we focus on the typical and extreme values of these measures.\n\tIn Figures \\ref{fig:exp1bias} and \\ref{fig:exp1cir}, we report the average, minimum, and maximum absolute PRB \n\tand CIC achieved by the missing data treatment methods for each parameter parameter type.\n\tIn the supplementary material, we included figures reporting the raw PRB and CIC for every parameter estimate.\n%\n\t\\paragraph{Means} \n\tFocusing first on the item means (top rows), the largest $|\\text{PRB}|$ is below 10 percentage points for all \n\timputation methods.\n\tHowever, looking at relative performances, IURR and MI-PCA resulted in smaller bias than all other methods, \n\texcept MI-OP.\n\tIn the conditions with high proportion of missing values (columns 3 and 4 in the figures), all methods showed \n\tsignificant deviations from nominal coverage rates, with all CICs outside of the interval $(0.94, 0.96)$.\n\tThe only exceptions was MI-PCA which showed non-significant deviations from nominal coverage for \n\talmost all estimates, with both the lowest and highest CIC falling within (0.94, 0.96) in all conditions.\n\tThe tree-based MI methods, missForest, and CC lead to CICs significantly different from nominal coverage rates\n\tin all conditions.\n%\n\t\\paragraph{Variances} \n\tMoving to the item variances (central rows), IURR, blasso, and the MI tree-based methods resulted in the lowest\n\tbiases across all conditions, even in the high-dim-high-pm condition.\n\tThese low biases were mostly paired with low deviations from nominal coverage, except for the high-dim-high-pm\n\tcondition where they resulted in significant under-coverage of the true item \n\tvariances (highest $CIC < 0.94$).\n\tNevertheless, apart from MI-OP, blasso was the method with best coverage in this final condition.\n\t\n\tDURR showed poor performance with regard to the item variances: in all conditions but the first, it led to \n\tlarge bias accompanied by significant CI under-coverage.\n\tBridge was the only MI method showing larger bias than DURR in all the high-dimensional conditions (columns 2 and 4),\n\twith even the minimum $|\\text{PRB}|$ exceeding the 20\\% threshold.\n\tMI-PCA also showed poor performance with noticeable item variance bias in all conditions that became extreme in the\n\thigh-dim-high-pm condition (column 4), where even the smallest $|\\text{PRB}|$ exceeded 20\\%.\n\tThis poor performance was reflected in extreme confidence interval under-coverage of the true item variances in\n\tthe final experimental condition.\n\tFinally, missForest and CC led to substantial bias and CI under-coverage for all \n\titem variances, even in condition 1.\n%\n\t\\paragraph{Covariances}\n\tIURR performed noticeably better than most other methods, with negligible covariance bias \n\t(maximum $|\\text{PRB}| < 10\\%$) and acceptable coverage (average $CIC \\sim 0.94$) in the high-dim-low-pm \n\tcondition.\n\tHowever, it struggled with a large covariance bias and extreme under-coverage in the high-dim-high-pm \n\tcondition (average $|\\text{PRB}| > 10\\%$ and average $CIC < 0.90$).\n\tMI-PCA showed negligible bias for all the covariance estimates (with the maximum $|\\text{PRB}| < 10\\%$), \n\tand performed as well as MI-OP in all but the high-dim-high-pm condition.\n\tFurthermore, MI-PCA resulted in virtually no deviation from nominal coverage, except in the last condition.\n\tIn the high-dim-high-pm condition, MI-PCA led to negligible bias, and mild significant \\emph{over}-coverage \n\tof the items covariances: the average CIC was greater than 0.96, but smaller than 0.99.\n\n\tBridge displayed low bias and acceptable coverage in the low dimensional conditions (columns 1 and 3), but \n\textreme bias and low CI coverage in all the high dimensional conditions (columns 2 and 4).\n\tMissForest and CC showed extreme bias and under-coverage for all the covariances (minimum $|\\text{PRB}|>10\\%$),\n\teven in condition 1.\n\tAll other methods, including DURR, showed absolute covariance PRBs larger than the 10\\% threshold in all but the \n\tfirst condition, with persistently significant CI under-coverage of the true values.\n\n\\begin{figure}\n\\centering\n\\includegraphics{\\pathFIG/exp1_bias_summy.pdf}\n\\caption{\\label{fig:exp1bias}\n\tMaximum, average, and minimum absolute Percent Relative Bias ($|\\text{PRB}|$) for item means, variances, \n\tand covariances in Experiment 1.\n\tFor each method, the maximum, average, and minimum $|\\text{PRB}|$ are reported in this order.\n\t}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics{\\pathFIG/exp1_CI_summy.pdf}\n\\caption{\\label{fig:exp1cir}\n\tMaximum, average, and minimum CIC for item means, variances, and covariances in Experiment 1.\n\tFor each method, the maximum, average, and minimum are reported in this order.\n\t}\n\\end{figure}\n\t\n%\\FloatBarrier % stops fig:exp1cir to leave its section\n\n", "meta": {"hexsha": "ba35e193a96f75173a0dd5272d2ecd723913802d", "size": 14243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/old/03_section.tex", "max_stars_repo_name": "EdoardoCostantini/imputeHD-comp", "max_stars_repo_head_hexsha": "c6fad9ee406ad85dd9874f336220177ae08ae477", "max_stars_repo_licenses": ["MIT"], "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/old/03_section.tex", "max_issues_repo_name": "EdoardoCostantini/imputeHD-comp", "max_issues_repo_head_hexsha": "c6fad9ee406ad85dd9874f336220177ae08ae477", "max_issues_repo_licenses": ["MIT"], "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/old/03_section.tex", "max_forks_repo_name": "EdoardoCostantini/imputeHD-comp", "max_forks_repo_head_hexsha": "c6fad9ee406ad85dd9874f336220177ae08ae477", "max_forks_repo_licenses": ["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.0970464135, "max_line_length": 123, "alphanum_fraction": 0.759250158, "num_tokens": 3727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7772998714925404, "lm_q1q2_score": 0.6494212460246347}}
{"text": "\\lab{Application}{Cracking Blackjack}{Cracking Blackjack}\n\\label{Ch:BJ}\n\n\\objective{This section teaches about how toexploite the weaknesses of a pseudorandom number generator that uses Linear Congruience}\n\n\\section*{Blackjack}\n\n%Lab \\ref{BJ}\n\nBlack Jack is a card game that involes the use of randomness. The game is simple, the dealer deals the player and himself each two cards. He flips over his first card so the player can see it. The player has to chose to take another card (\"hit\") or not (\"stand\"). If the player hits he gets another card and again has the choice to hit or stand.\n\nThe goal is to get your hand to be at or as close to 21 without going over. Face cards are worth 10 points. Aces can count either as 11 or 1. The of value other cards are equal to number on the card.\n\nOnce the player has decided to stand the dealer flips over his second card and deals himself cards until his hand value is 17 or greater. \n\nIf the player value goes above 21 he automaticly loses. If his value is 21 and below and dealer has above 21 then the player wins. If they both have 21 or under than whose hand has the highest value, wins. If both hands have the same value, the game is a tie.\n\n\\section*{Shuffling Algorithms}\n\nOne use of Psuedorandom Number Generators (PRNGs) is to shuffle cards. The main goal of these algorithms is that the card order are random - so that no one player has advatage based on order. Often online gambling sites will post their algorithms online. The only thing they do not post is their seed values. Often the time in miliseconds is used as the seed value.\n\n\\section*{Cracking Blackjack}\nFor these next problems you will need three files that are provided:Black.py, BlackEasy.py, and bjHelp.py.  Black.py and BlackEasy.py are are programs that run games of Blackjack that use a Linear Congruentail Generator (LCG) to shuffle the cards. They print out 52 numbers and the argsort of those numbers is the order of the cards.The parameters for BlackEasy.py are a$=2521$, c$=13$, mod$=2^{16}$; For Black.py they are a$=25214903917$, c$=11$, mod$=2^{48}$. In order to play them python name (Black.py or BlackEasy.py) numberofgames. They are both seeded initially by the time.\n\nbjHelp.py contains two functions that will help you \"predict\" the cards:\nSuffleHack(n,a,c,mod,seed) gives the first n card shuffles given the parameters for a LCG. The shuffles are represented by numbers \nHacker(Stats,['card','card','card']) Stats is the output of SuffleHack and takes a list of 3 cards (see below.) It prints all shuffles as a list of cards in Stats that have the same first three cards as the inputed list.\n\nThe trick to being able to \"predict\" the cards is to find the initial seed value.\n\nCards- A, 2-10, J, Q, or K combined with heart, diamond, club, or spade in single quotes. Examples: '6diamond', 'Kclub'\n\n\n\n\\begin{problem}\nPlay 10 games of BlackEasy.py and by the 5th game be able to predict the cards. You can write your own functions or use the ones in bjHelp.py. You will want to open two comand promts, one to play the game and one to use to predict the cards. \n\\end{problem}\n\nNot too hard. That is because there is only $2^{16}$ seed values. This next one you will have to look at more hands until you can find out the initial seed value.\n\n\\begin{problem}\nPlay 20 games of Black.py and by the 15th game be able to predict the cards.\n\\end{problem}\n\n\n\n", "meta": {"hexsha": "8c1f65b46b1b7c4ddeeb2200038d1a5ff815b0eb", "size": 3387, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Blackjack/Blackjack.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/Blackjack/Blackjack.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/Blackjack/Blackjack.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": 72.0638297872, "max_line_length": 581, "alphanum_fraction": 0.7664599941, "num_tokens": 848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6494212428405399}}
{"text": "% !TEX root=../main.tex\n\nWe now present our one-class Neural Network (OC-NN) model for unsupervised anomaly detection.\nThe method can be seen as designing a neural architecture using an  OC-SVM equivalent loss function.\nUsing OC-NN we will be able to exploit and refine features obtained from unsupervised tranfer learning specifically for anomaly\ndetection. This in turn will it make it possible to discern anomalies in complex data sets where the decision boundary between normal and anomalous\nis highly nonlinear.\n\\vspace{-0.1cm}\n\\subsection{One-Class Neural Networks (OC-NN)}\n\\label{sec:oc-nn}\nWe design a simple feed forward network with one hiden layer having linear or sigmoid activation $g(\\cdot )$ and one output node. Generalizations to deeper\narchitectures is straightforward. The OC-NN objective can be formulated as:\n\\begin{equation}\n\t\\label{eqn:oc-nn}\n\t\\min_{w, V, \\bias} \\frac{1}{2} \\| w \\|_{2}^2 + \\frac{1}{2} \\| V \\|_F^2 + \\frac{1}{\\nu} \\cdot \\frac{1}{N} \\sum_{n= 1}^N \\max( 0, \\bias - \\langle w, g( V  \\X_{n :} ) \\rangle ) - \\bias\n\\end{equation}\n\nwhere $w$ is the scalar output obtained from the hidden to output layer,\n$V$ is the weight matrix from input to hidden units.\nThus the \\underline{key insight} of the paper is to replace the dot product $\\mathbf{\\langle w,\\Phi(\\X_{n :}) \\rangle}$ in OC-SVM with the dot product $\\mathbf{\\langle w,g(V\\X_{n :})\\rangle}$. This change will make it possible to leverage transfer learning features obtained using an autoencoder and create an additional layer to refine\nthe features for anomaly detection. However, the price for the change is that the objective becomes non-convex and thus the resulting algorithm\nfor inferring the parameters of the model will not lead to a global optima.\n\n%which is randomly initialized from the uniform distribution within the range $[-1, 1]$.  $\\nu \\in (0,1)$, is the parameter that\n%equates to the percentage of anomalies within data, found via grid search in the experiments. $\\bias$ is the equivalent maximum margin separating plane from the origin.\n\n\n%%%%\n\\begin{comment}\n\\subsection{Connection to OC-SVM}\n\\label{sec:connection_to_OC-SVM}\n\nClearly, Equation~\\ref{eqn:oc-nn} is the special case of the Equation~\\ref{eqn:ocsvm-objective} presented in the Section~\\ref{sec:ocsvm}, where the weights $V$  in Equation~\\ref{eqn:oc-nn} are randomly initialised, and not optimised, and $g$ is the either a $linear$ and $sigmoid$ activations.\nMore generally, for a deep network with parameters $w$, we have\n\n\\begin{equation}\n\\label{eqn:gen-oc-nn}\n \\min_{w,\\bias} \\frac{1}{2} \\| w \\|_{2}^2 +\\frac{1}{\\nu} \\cdot \\frac{1}{N} \\sum_{i = 1}^N \\max( 0, \\bias - \\langle w, \\Phi( \\X_{n :} w ) \\rangle ) - \\bias\n\\end{equation}\n\\end{comment}\n\n%%%%\n\\vspace{-0.1cm}\n\\subsection{Training the model}\n\\label{sec:training}\nWe can optimize Equation~\\ref{eqn:oc-nn} using an alternate minimization approach: We first fix $r$ and optimize for $w$ and $V$. We then use\nthe new values of $w$ and $V$ to optimize $r$. However, as we  will show, the optimal value of $r$ is just the $\\upsilon$-quantile of\nthe array $\\langle w,g(Vx_{n})\\rangle$. We first define the objective to solve for $w$ and $V$ as\n% \\vspace{-0.1cm}\n\\begin{equation}\n                \\label{eqn:minimize_w_V}\n                 \\underset{w, V}{\\argmin} \\frac{1}{2} \\| w \\|_{2}^2 + \\frac{1}{2} \\| V \\|_F^2 + \\frac{1}{\\upsilon} \\cdot \\frac{1}{N} \\sum_{n = 1}^N \\ell( y_n, \\hat{y}_n( w, V ) )\n                 \\end{equation}\n                where\n                \\begin{align*}\n                        \\ell( y, \\hat{y} ) &= \\max( 0, y - \\hat{y} ) \\\\\n                        y_n       &= \\bias \\\\\n                        \\hat{y}_n( w, V ) &= \\langle w, g( V x_n ) \\rangle\n                \\end{align*}\n\nSimilarly the optimization problem for $\\bias$ is\n\\begin{equation}\n\\label{eqn:minimize_r}\n\\underset{\\bias}{\\argmin} \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - r\n\\end{equation}\n\\begin{comment}\n%%%\n\\begin{enumerate}[(1)]\n\t\\item Initialise $w^{(0)}, V^{(0)}, r^{(0)}$ randomly\n\t\\item for $t = 1, 2, \\ldots$\n\t\\begin{enumerate}[(a)]\n\t\t\\item find $(w^{(t+1)}, V^{(t+1)})$ that minimise the objective through Backpropagation (BP) algorithm.\n\t\t\\begin{equation}\n\t\t\\label{eqn:minimize_w_V}\n\t\t \\underset{w, V}{\\argmin} \\frac{1}{2} \\| w \\|_{2}^2 + \\frac{1}{2} \\| V \\|_F^2 + \\frac{1}{\\upsilon} \\cdot \\frac{1}{N} \\sum_{n = 1}^N \\ell( y_n, \\hat{y}_n( w, V ) )\n\t\t \\end{equation}\n\t\twhere\n\t\t\\begin{align*}\n\t\t\t\\ell( y, \\hat{y} ) &= \\max( 0, y - \\hat{y} ) \\\\\n\t\t\ty_n       &= \\bias^{(t)} \\\\\n\t\t\t\\hat{y}_n( w, V ) &= \\langle w, g( V x_n ) \\rangle\n\t\t\\end{align*}\n\n\t\t\\item pick $\\bias^{(t)}$ to be the $\\upsilon^{\\text{th}}$ quantile of $\\{ \\hat{y}_n \\}_{n = 1}^N$, where\n\t\t$$ \\hat{y}_n^{(t+1)} = \\langle w^{(t+1)}, g( V^{(t+1)} x_n ) \\rangle. $$\n\t\\end{enumerate}\n\n\\end{enumerate}\n\nTo justify step 2(b), let us observe that the optimisation with respect to $\\bias$ is\\\\\n%\n\\begin{equation}\n\\label{eqn:minimize_r}\n\\underset{\\bias}{\\argmin} \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - r\n\\end{equation}\n\\end{comment}\n\\begin{theorem}\nGiven $w$ and $V$ obtained from solving Equation~\\ref{eqn:minimize_w_V}, the solution to Equation~\\ref{eqn:minimize_r} is given\nby the $\\upsilon^{\\text{th}}$ quantile of $\\{ \\hat{y}_n \\}_{n = 1}^N$, where\n                $$ \\hat{y}_n = \\langle w, g(V x_n ) \\rangle. $$\n\\end{theorem}\n\\begin{proof}\n We can rewrite Equation~\\ref{eqn:minimize_r} as:\n\\begin{align*}\n%\\underset{\\bias}{\\argmin} \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - r \\\\\n\\underset{\\bias}{\\argmin} \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - \\left( \\bias - \\frac{1}{N} \\sum_{n = 1}^{N} \\hat{y}_n \\right) \\\\\n= \\underset{\\bias}{\\argmin} \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - \\left( \\frac{1}{N} \\sum_{n = 1}^{N} \\left[ \\bias - \\hat{y}_n \\right] \\right) \\\\\n= \\underset{\\bias}{\\argmin} \\left( \\sum_{n = 1}^N \\max( 0, \\bias - \\hat{y}_n ) \\right) - \\upsilon \\cdot \\left( \\sum_{n = 1}^{N} \\left[ \\bias - \\hat{y}_n \\right] \\right) \\\\\n= \\underset{\\bias}{\\argmin} \\sum_{n = 1}^N \\left[ \\max( 0, \\bias - \\hat{y}_n ) - \\upsilon \\cdot \\left( \\bias - \\hat{y}_n \\right) \\right] \\\\\n= \\underset{\\bias}{\\argmin} \\sum_{n = 1}^N\n\\begin{cases} (1 - \\upsilon) \\cdot \\left( \\bias - \\hat{y}_n \\right) & \\text{ if } \\bias - \\hat{y}_n > 0 \\\\ - \\upsilon \\cdot \\left( \\bias - \\hat{y}_n \\right) & \\text{ otherwise}\n\\end{cases}\n\\end{align*}\n% \\vspace{0.4cm}\n\\vspace{-0.1cm}\nWe can observe that the derivative with respect to $r$ is\n$$ F'( r ) = \\sum_{n = 1}^N \\begin{cases} (1 - \\upsilon) & \\text{ if } \\bias - \\hat{y}_n > 0 \\\\ -\\upsilon & \\text{ otherwise. } \\end{cases} $$\nThus, by F'( r ) = 0 we obtain\n%\n\\begin{align*}\n\t(1 - \\upsilon) \\cdot \\sum_{n = 1}^N \\indicator{ \\bias - \\hat{y}_n > 0 } &= \\upsilon \\cdot \\sum_{n = 1}^N \\indicator{ \\bias - \\hat{y}_n \\leq 0 } \\\\\n\t&= \\upsilon \\cdot \\sum_{n = 1}^N (1 - \\indicator{ \\bias - \\hat{y}_n > 0 }) \\\\\n\t&= \\upsilon \\cdot N - \\upsilon \\cdot \\sum_{n = 1}^N \\indicator{ \\bias - \\hat{y}_n > 0 },\n\\end{align*}\nor\n\\begin{equation}\n \\frac{1}{N} \\sum_{n = 1}^N \\indicator{ \\bias -\\hat{y}_n > 0 }= \\frac{1}{N} \\sum_{n = 1}^N \\indicator{ \\hat{y}_n < r } = \\upsilon\n\\end{equation}\\\\\nThis means we would require the $\\nu^{\\text{th}}$ quantile of $\\{ \\hat{y}_n \\}_{n = 1}^N$.\n\\end{proof}\n% \\vspace{0.3cm}\n%Algorithm\n\\vspace{-0.3cm}\n\\subsection{OC-NN Algorithm}\n\\label{sec:algorithm}\nWe summarize the solution in Algorithm~\\ref{alg1}. We initialize $\\bias^{(0)}$ in Line 2. We learn the parameters($w,V$) of the neural network\nusing the standard Backpropogation(BP) algorithm (Line 7). In the experiment section, we will train the model using features extracted from\nan autoencoder instead of raw data points. However this has no impact on the OC-NN algorithm. As show  in Theorem 3.1, we solve for $\\bias$\nusing the $\\upsilon$-quantile of the scores $\\langle y_{n} \\rangle$. Once the convergence criterion is satisfied, the data points are\nlabeled normal or anomalous using the decision function $S_{n} = sgn(\\hat{y}_{n} - r)$.\n\n\\begin{algorithm}\n\\caption{one-class neural network (OC-NN) algorithm}\\label{alg:oc-nn}\n\\label{alg1}\n\\begin{algorithmic}[1]\n\\State{\n\\textbf{Input:} Set of points $\\X_{n :},\\hspace{0.2cm} n: 1,...,N$\n}\n\\State{\n\\textbf{Output:} A Set of decision scores $S_{n :}=\\hat{y}_{n :}$, n: 1,...,N for X\n}\n\n\\State Initialise $\\bias^{(0)}$\n\\State $t \\gets 0$\n\\While{(no convergence achieved)}\n\\State Find $(w^{(t+1)}, V^{(t+1)})$ \\Comment Optimize Equation~\\ref{eqn:minimize_w_V} using BP.\n\\State $r^{t+1} \\gets \\nu^{\\text{th}}$ quantile of $\\{ \\hat{y}_n^{t+1} \\}_{n = 1}^N$\n\\State $t \\gets t + 1$\n\\EndWhile \\label{endwhile}\n\\State \\textbf{end}\n\\State Compute decision score $S_{n :}=  \\hat{y}_n -r  \\mbox{ for each }  \\X_{n :}$\n\\If{($S_{n :}$ $\\geq$ 0)}\n    \\State $\\X_{n :}$ is normal point\n   \\Else\n    \\State $\\X_{n :}$ is anomalous\n\\EndIf\n\n\\State \\textbf{return} $\\{S_n\\}$\n\n\\end{algorithmic}\n\\end{algorithm}\n% \\vspace{-0.05cm}\n%\n\\noindent\n{\\bf Example:} We give a small example to illustrate that the minimum of the function\n\\[f(r) =  \\left( \\frac{1}{N\\upsilon} \\cdot \\sum_{n = 1}^N \\max( 0, \\bias - y_n ) \\right) - r\\] occurs at the\nthe $\\upsilon$-quantile of the set $\\{y_{n}\\}$. \\\\\n\nLet $y =\\{1,2,3,4,5,6,7,8,9\\}$ and  $\\upsilon = 0.33$. Then the minimum will occur at $f(3)$ as detailed in\nthe table below.\n\\[\n\\begin{array}{|r|l|r|}  \\hline \\hline\nr & f(r) (\\mbox{expr}) & f(r) (\\mbox{value}) \\\\ \\hline \\hline\n1 & \\frac{1}{9*.33}[0 + 0 +\\ldots 0] - 1 & -1.00 \\\\ \\hline\n2 & \\frac{1}{9*.33}[1 + 0 +\\ldots 0] - 2 & -1.67 \\\\ \\hline\n\\rowcolor{green!20}\n3 & \\frac{1}{9*.33}[2 + 1 +\\ldots 0] - 3 & -1.99  \\\\ \\hline\n4 & \\frac{1}{9*.33}[3 + 2 + 1 +\\ldots 0] - 4 & -1.98  \\\\ \\hline\n5 & \\frac{1}{9*.33}[4 + 3 + 2 + 1\\ldots 0] - 5 & -1.63  \\\\ \\hline\n6 & \\frac{1}{9*.33}[5 + 4  + 3 + 2 + 1\\ldots 0] - 6 & -0.94  \\\\ \\hline\n7 & \\frac{1}{9*.33}[6 + 5  + 4 + 3 + 2 + 1\\ldots 0] - 7 & 0.07  \\\\ \\hline\n8 & \\frac{1}{9*.33}[7 + 6  + 5 + 4 + 3 + 2 + 1\\ldots 0] - 8 & 1.43  \\\\ \\hline\n9 & \\frac{1}{9*.33}[8 + 7  + 6 + 4 + \\ldots 0] - 9 & 3.12  \\\\ \\hline\n\\end{array}\n\\]\n\n\n\\begin{comment}\n\\subsection{Predicting with the model}\n\nOne convenient property of our model is that the anomaly detector will be inductive, i.e.\\ it can generalise to unseen data points.\nOne can interpret the model as learning a non linear projection  of the input;\nsuch a representation should thus be able to accurately model any unseen points that lie on the same manifold as the data used to train the model. Formally, $f( x ) = \\langle w, \\Phi( \\X_{n :} w ) \\rangle$  computes decision score of the given data point.\nThe \"negative\" or \"closer\" $\\langle w, \\Phi( \\X_{n :} w ) \\rangle$ is, to origin and the more likely the point is deemed to be anomalous.\n\n%\n\\subsection{Relation to existing models}\nOur contribution is breaking-new grounds, to integrate the OC-SVM equivalent objective into the neural\nnetwork architecture, utilizing the features extracted through unsupervised tranfer representation learning for anomaly detection.\nSome previous works have employed deep networks for anomaly detection~\\cite{chalapathy2017robust,zhou2017anomaly}. For example, the recent work of \\cite{zhou2017anomaly} employed an autoencoder-inspired objective to train a robust deep autoencoder network, with extensions to capture structured noise within the data; Our method is distinct to robust deep autoencoders (RDA),  wherein we introduce a novel one-class neural network objective function illustrating the analytic derivation of $\\nu^{th}$ quantile of the sorted output scores represents, the maximum margin distance,  separating normal data from anomalies. Although, nonlinear projections~\\cite{bingham2001random,rathore2017ensemble} have been explored  for anomaly detection. We are unaware of prior usage of transfer learnt autoencoder networks integrated with one-class neural network objective to detect anomalies in unsupervised fashion.\n\\end{comment}\n", "meta": {"hexsha": "a82fec1cb1266e6b5de36b0bbe539461d6890b96", "size": 12060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ARXIV_DAD_Survey/src/method.tex", "max_stars_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey", "max_stars_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 107, "max_stars_repo_stars_event_min_datetime": "2019-01-11T12:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T12:03:57.000Z", "max_issues_repo_path": "ARXIV_DAD_Survey/src/method.tex", "max_issues_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey_Arxiv_WorkingDocument", "max_issues_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ARXIV_DAD_Survey/src/method.tex", "max_forks_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey_Arxiv_WorkingDocument", "max_forks_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-01-15T02:42:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-06T07:59:29.000Z", "avg_line_length": 56.8867924528, "max_line_length": 904, "alphanum_fraction": 0.6501658375, "num_tokens": 4330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6494212289780591}}
{"text": "\\appendix\n\\section{Cantilever beam dynamics}\n\nConsider an eVTOL wing with multiple electric motors and rotors mounted along the spar, shown in Fig.~\\ref{fig:wing_diagram}. The wing structure is idealized as a cantilever beam with non-structural lumped masses placed along the span, shown in Fig.~\\ref{fig:cantilever}. \n\n\\begin{figure}[H]\n     \\centering\n         \\includegraphics[width=0.7\\textwidth]{images/wing_diagram.png}\n        \\caption{Rotor layout for an example eVTOL wing}\n         \\label{fig:wing_diagram}\n\\end{figure}\n\n\\begin{figure}[H]\n         \\centering\n         \\includegraphics[width=0.7\\textwidth]{images/cantilever.png}\n        \\caption{Idealization of eVTOL wing structure}\n         \\label{fig:cantilever}\n\\end{figure}\n\nTo expand the generality of the analysis, consider a tapered circular spar running along the length of the wing. The cross-section of the spar is shown in Fig.~\\ref{fig:taper_beam}. The tube thickness is equal to $t$, and is uniform along the spar length. The radius of the circular cross-section varies from $r_1$ at the root of the beam to $r_2$ at the tip. The mass per unit span and bending stiffness of the spar is given by \n\\begin{align*}\nm(x) \\quad &= \\quad 2 \\pi \\rho r(x) t \\\\\nEI_{yy}(x) \\quad &= \\quad E \\pi r(x)^3 t\n\\end{align*}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.45\\textwidth]{images/taper_beam.png}\n\\vspace{-0.1cm}\n\\caption{Linearly tapered circular spar}\n\\label{fig:taper_beam}\n\\end{center}\n\\end{figure}\n\nThe first bending natural frequency is estimated using a Rayleigh-Ritz approximation, with a mode shape set by the static deflection of the cantilever due to a tip-load, i.e.,\n\\begin{equation}\nw''(x) \\quad = \\quad P (L - x)\n\\end{equation}\nIntegrate twice along the span and apply the cantilever boundary condition to obtain the deflected bending slope as \n\\begin{equation}\nw'(x) \\quad = \\quad \\frac{P}{E\\pi t}\\left[\\frac{a_2}{r(x)^2} \\spc+\\spc \\frac{a_1}{r(x)} \\spc+\\spc a_0\\right]\n\\end{equation}\nThe constants are \n\\begin{align*}\na_2 \\quad =& \\quad -\\frac{L}{2r'} \\spc-\\spc \\frac{r_1}{2{r'}^2} \\\\\na_1 \\quad =& \\quad -\\frac{1}{{r'}^2} \\\\\na_0 \\quad =& \\quad \\frac{L}{2r'r_1^2} \\spc-\\spc \\frac{1}{2{r'}^2 r_1}\n\\end{align*}\nIntegrate the bending slope along the span to obtain the deflected mode shape as \n\\begin{equation}\nw(x) \\quad = \\quad \\frac{P}{E\\pi t}\\left[b_0 \\spc + \\spc b_1 x \\spc+\\spc \\frac{b_m}{r(x)} \\spc+\\spc b_l \\log_e r(x)\\right]\n\\end{equation}\nThe constants are \n\\begin{align*}\nb_0 \\quad =& \\quad -\\frac{a_2}{r_1 r'} \\spc-\\spc \\frac{a_1}{r'} \\log_e(r_1)\\\\\nb_1 \\quad =& \\quad a_0 \\\\\nb_m \\quad =& \\quad -\\frac{a_2}{r'}  \\\\\nb_l \\quad =& \\quad \\frac{a_1}{r'} \n\\end{align*}\n\\subsection{Potential energy}\nThe maximum potential energy is given by \n\\begin{equation*}\nU \\quad = \\quad \\frac{1}{2} \\int_0^L \\frac{P^2(L-x)^2}{EI_{yy}(x)} dx\n\\end{equation*}\nSubstitute for the bending stiffness to obtain \n\\begin{equation*}\nU \\quad = \\quad \\frac{1}{2} \\frac{P^2}{E\\pi t} [A + B + C](\\lambda) \n\\end{equation*}\nThe term $\\lambda$ is the spar taper ratio, given by \n\\begin{equation}\n\\lambda \\quad = \\quad \\frac{r_2}{r_1}\n\\end{equation}\nThe sum $A+B+C$ is well-represented by a cubic polynomial in $\\lambda$ as \n\\begin{equation*}\nA+B+C\\quad \\approx \\quad (1.6261 \\spc - \\spc 0.4826 \\lambda \\spc + \\spc 2.1197 \\lambda^2 \\spc - \\spc 0.5957 \\lambda^3) \\frac{1}{K^3}\n\\end{equation*}\nThe constant $K$ is the inverse of the spar aspect ratio, given by \n\\begin{equation}\nK \\quad = \\quad \\frac{2 (\\frac{t}{c})}{AR_{\\rm wing}}\n\\end{equation}\nHere, $\\frac{t}{c}$ is the wing thickness to chord ratio, and $AR_{\\rm wing}$ is the wing aspect ratio.\n\n\\subsection{Kinetic energy}\nThe maximum kinetic energy of the beam has contributions from three types of masses:\n\\begin{enumerate}\n\\item \\textbf{Structural masses}: This term deals with the kinetic energy of the spar structure. This contribution to kinetic energy is \n\\begin{equation*}\nKE_{s} \\quad = \\quad \\int_0^L \\frac{1}{2} \\spc 2 \\pi r(x) t \\rho \\spc w(x)^2 \\spc \\omega_n^2 \\spc dx \\quad = \\quad \\frac{P^2}{E^2 \\pi t} \\rho \\omega_n^2 (RHS)\n\\end{equation*}\nThe term $RHS$ is a function of the taper ratio $\\lambda$, length $L$ and spar taper ratio inverse $K$ only. Further, the dependence on wing taper $\\lambda$ can be approximated using a cubic polynomial in $\\lambda$. Thus, the kinetic energy coefficient $RHS$ is approximated as \n\\begin{equation*}\nRHS \\quad \\approx \\quad \\frac{L^2}{K^5} (0.04823 \\spc + \\spc 0.269 \\lambda \\spc + \\spc 0.15178 \\lambda^2 \\spc + \\spc 0.36917 \\lambda^3) \n\\end{equation*}\n\\item \\textbf{Non-structural distributed masses}: This term deals with the kinetic energy due to the skin and other components (e.g., wires) that do not contribute significantly to bending stiffness. The kinetic energy term is \n\\begin{equation*}\nKE_{\\rm NS} \\quad = \\quad \\int_0^L \\frac{1}{2} \\spc m_{\\rm NS}(x)  \\spc w(x)^2 \\spc \\omega_n^2 \\spc dx \n\\end{equation*}\nThe non-structural mass due to wing skin is given by \n\\begin{equation*}\nm_{\\rm NS}(x) \\quad = \\quad \\frac{2 M_{\\rm NS}}{A (\\frac{t}{c})} r(x) \n\\end{equation*}\nThe term $\\frac{M_{\\rm NS}}{A}$ is the non-structural mass per unit plan-form area of the skin. Define an intermediate quantity $\\beta$ given by \n\\begin{equation*}\n\\beta \\quad = \\quad \\frac{M_{\\rm NS}}{A (\\frac{t}{c})}\n\\end{equation*}\nThe expression for kinetic energy of non-structural masses simplifies to \n\\begin{equation*}\nKE_{\\rm NS} \\quad = \\quad \\beta \\spc \\frac{P^2 \\omega_n^2}{E^2 \\pi^2 t^2} \\spc RHS\n\\end{equation*}\n\\item \\textbf{Non-structural lumped mass}: This term refers to the kinetic energy of the electric motor/speed controller unit, rotor hubs and rotor blades. These discrete lumped masses are mounted along the wing spar, and the kinetic energy of these masses is given by \n\\begin{equation*}\nKE_{\\rm lump} \\quad = \\quad \\mathlarger{\\mathlarger{\\Sigma}}_i^{N_{\\rm M}}\\spc \\frac{1}{2} \\spc M_i \\spc w(x_i)^2 \\quad = \\quad \\frac{P^2 \\omega_n^2}{E^2 \\pi^2 t^2} \\Delta RHS\n\\end{equation*}\nThe coefficient $\\Delta RHS$ is \n\\begin{equation*}\n\\Delta RHS \\quad = \\quad \\mathlarger{\\mathlarger{\\Sigma}}_i^{N_{\\rm M}} \\frac{M_i}{2} \\left[b_0 \\spc + \\spc b_1 x_i \\spc + \\spc b_l \\log_e r(x_i) \\spc + \\spc \\frac{b_m}{r(x_i)} \\right]^2 \n\\end{equation*}\n\\end{enumerate}\n\\subsection{Frequency tuning}\nThe goal is to determine the spar mass by setting a target first natural frequency $\\omega_n$ for the cantilever beam with distributed and lumped non-structural masses. Equating the maximum total kinetic energy and maximum potential energy for the first bending mode, we obtain\n\\begin{equation}\n\\frac{1}{2} \\frac{P^2}{E^2 \\pi t} \\spc LHS \\quad = \\quad \\omega_n^2 \\left[\\frac{P^2}{E^2 t} (RHS) \\spc + \\spc \\frac{P^2}{E^2 \\pi^2 t^2} \\beta (RHS) \\spc + \\spc \\frac{P^2}{E^2 \\pi^2 t^2} \\Delta RHS \\right]\n\\end{equation}\nSolve for spar thickness as \n\\begin{equation*}\nt \\quad = \\quad \\left(\\frac{E \\pi}{2 \\omega_n^2} LHS \\spc - \\spc \\rho \\pi RHS \\right)^{-1} \\left[\\beta (RHS) \\spc + \\spc \\Delta RHS \\right]\n\\end{equation*}\nThe total spar mass is therefore \n\\begin{equation}\nM_{\\rm spar} \\quad = \\quad \\pi \\rho \\spc t (1 + \\lambda) r_1 \n\\end{equation}\n\nFor validation of the Rayleigh-Ritz solution, several cases were evaluated with and without lumped non-structural masses. \n\n\\subsection{Validation}\n\\subsubsection{Case 1: cantilever beam}\nConsider a cantilever beam with a hollow circular cross-section of constant wall thickness, and the cross-section radius is linearly tapered from root to tip, with a taper ratio of $\\lambda$ varying from 0.5 to 1.2. The beam length is 2.9 m, mean tube radius is 0.1411 m. The first bending natural frequency predictions from the Rayleigh-Ritz approximation are compared against a beam Finite Element Method analysis. These two frequencies are plotted in Fig.~\\ref{fig:beam_freq1}. The Rayleigh-Ritz approximation exhibits about 2\\% over-prediction, but otherwise captures the trends accurately. In this example, no non-structural masses were considered.\n\n\\begin{figure}\n     \\centering\n\t\\subfigure[Natural frequency vs. taper ratio]{\\includegraphics[width=0.45\\textwidth]{images/beam_freq1b.png}}\n\t\\subfigure[Rayleigh-Ritz vs. FEM]{\\includegraphics[width=0.45\\textwidth]{images/beam_freq1.png}}\n     \\caption{Natural frequency: Rayleigh-Ritz vs. FEM predicted natural frequencies for a tapered cantilever beam}\n     \\label{fig:beam_freq1}\n\\end{figure}\n\n\\begin{figure}\n     \\centering\n\t\\subfigure[Natural frequency vs. taper ratio]{\\includegraphics[width=0.45\\textwidth]{images/beam_freq2b.png}}\n\t\\subfigure[Rayleigh-Ritz vs. FEM]{\\includegraphics[width=0.45\\textwidth]{images/beam_freq2.png}}\n     \\caption{Natural frequency: Rayleigh-Ritz vs. FEM for a tapered cantilever beam with distributed non-structural masses}\n     \\label{fig:beam_freq2}\n\\end{figure}\n\n\\subsubsection{Case 2: distributed non-structural mass}\nThis case is representative of an aircraft half-wing with skin, and no lumped masses. The non-structural masses are represented as a mass per unit area, i.e., $\\large\\frac{M}{A}$ kg/$m^2$. Three different values of the non-structural mass per unit wing area were evaluated: 0, 2.0 and 4.9 kg/m$^2$. The resulting natural frequencies were calculated from both Rayleigh-Ritz and FEM, and are plotted in Fig.~\\ref{fig:beam_freq2}. Excellent agreement is obtained.\n\n\\subsubsection{Case 3: half-wing with lumped masses}\nThis case is representative of an eVTOL wing. The dimensions of the beam are the same as in the previous examples, and the distributed skin mass per unit area is 4.9 kg/m$^2$. Two lumped masses (21.3 kg, 27 kg) are placed along the beam at 0.5$L$ and $L$, respectively. The wing layout and natural frequencies are shown in Fig.~\\ref{fig:beam_freq3}.\n\n\\begin{figure}\n     \\centering\n\t\\subfigure[Layout of eVTOL wing]{\\includegraphics[width=0.3\\textwidth]{images/wing_layout.png}}\n\t\\subfigure[Rayleigh-Ritz vs. FEM]{\\includegraphics[width=0.45\\textwidth]{images/beam_freq3b.png}}\n     \\caption{Natural frequency: Rayleigh-Ritz vs. FEM for an example eVTOL wing}\n     \\label{fig:beam_freq3}\n\\end{figure}", "meta": {"hexsha": "393bd2c42ed33d43f77ac09cfee351fa64720bc6", "size": 10024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Autodoc/theory_prog_manual/Appendices.tex", "max_stars_repo_name": "ananthsridharan/vtol_sizing", "max_stars_repo_head_hexsha": "3f754e1bd3cebdb5b5c68c8a2d84c47be1df2f02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-03-24T10:20:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T18:49:25.000Z", "max_issues_repo_path": "Autodoc/theory_prog_manual/Appendices.tex", "max_issues_repo_name": "ananthsridharan/vtol_sizing", "max_issues_repo_head_hexsha": "3f754e1bd3cebdb5b5c68c8a2d84c47be1df2f02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-08T10:26:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-04T18:19:59.000Z", "max_forks_repo_path": "Autodoc/theory_prog_manual/Appendices.tex", "max_forks_repo_name": "ananthsridharan/vtol_sizing", "max_forks_repo_head_hexsha": "3f754e1bd3cebdb5b5c68c8a2d84c47be1df2f02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-11-27T21:21:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-20T15:44:18.000Z", "avg_line_length": 60.0239520958, "max_line_length": 653, "alphanum_fraction": 0.7193735036, "num_tokens": 3294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.649421219231564}}
{"text": "% Copyright 2021 Google LLC\n%\n% Use of this source code is governed by an MIT-style\n% license that can be found in the LICENSE file or at\n% https://opensource.org/licenses/MIT.\n\n%!BIB program = biber\n%!TeX program = lualatex\n%!TeX spellcheck = en-US\n\n\\documentclass[hctr2.tex]{subfiles}\n\\begin{document}\n\\section{Specification}\\label{specification}\n\\subfile{algorithm.tex}\n\\subsection{Notation}\n\\begin{itemize}\n    \\item $\\abs{X}$: length of $X \\in \\bin^{*}$ in bits\n    \\item $\\lambda$: the empty string $\\abs{\\lambda} = 0$\n    \\item $X[a;l]$: the substring of $X$ of length $l$ starting at the 0-based index $a$\n    \\item $\\Concat$: bitstring concatenation\n    \\item \\(\\xor\\): bitwise XOR\n    \\item \\(n\\): block size in bits\n    \\item $\\fromint_l: \\{0 \\ldots 2^l-1\\} \\rightarrow \\bin^l$:\n    little-endian conversion of integers to binary; \n    \\(\\fromint(x)\\) means \\(\\fromint_n(x)\\)\n    \\item $\\pad(X) = X \\Concat 0^v$\n    where $v$ is the least integer $\\geq 0$ such that $n$ divides $\\abs{X} + v$\n    \\item \\(x, x^2, \\ldots\\): elements of the finite field \\(\\GF(2^n)\\)\n    \\item \\(E: \\mathcal{K} \\times \\bin^n \\rightarrow \\bin^n\\): \n    \\(n\\)-bit block cipher with keyspace \\(\\mathcal{K}\\);\n    our concrete proposal uses AES\\cite{aes},\n    so \\(n=128\\) and \\(\\mathcal{K}\\) is\n    \\(\\bin^{128}\\), \\(\\bin^{192}\\), or \\(\\bin^{256}\\)\n    \\item \\(\\mathcal{T}\\): the set of permissible tweaks\n    \\(\\mathcal{T} = \\bigcup_{i \\in \\{0\\ldots2^{n-1}-2\\}}\\bin^i\\)\n    \\item \\(\\mathcal{M}\\): the set of permissible messages\n    \\(\\mathcal{M} = \\bigcup_{i \\in \\{n\\ldots n + 2^{n-1}-2\\}}\\bin^i\\)\n\\end{itemize}\nWe map bytes to bitstrings with \\(\\fromint_8\\). Subscripts may denote partial application; if we define $f: A \\times B \\rightarrow C$ and\n$a \\in A$ then $f_a: B \\rightarrow C$, and if $f_a^{-1}$ exists then $f_a^{-1}(f_a(b)) = b$.\n\n\\subsection{Polynomial hash function}\\label{hashspec}\nWe interpret \\(n\\)-bit blocks as little-endian field elements of \\(\\GF(2^n)\\),\nso \\(001 \\Concat 0^{n-3}\\) is interpreted as the element \\(x^2\\).\nPer \\cite{aes_gcm_siv,aes_gcm_siv_rfc} we define\n\\begin{align*}\n    \\POLYVAL(\\hgen, \\lambda) & = 0^n\\\\\n    \\POLYVAL(\\hgen, A \\Concat B) & = (\\POLYVAL(\\hgen, A) \\xor B) \\otimes \\hgen \\otimes x^{-n}\n\\end{align*}\nwhere \\(\\abs{\\hgen} = \\abs{B} = n\\) and\n\\(\\otimes\\) is multiplication in the finite field.\nIn our concrete proposal, \\(n=128\\), we reduce by\n\\(x^{128} + x^{127} + x^{126} + x^{121} + 1\\),\nand the value of the field element \\(x^{-n}\\)\nis equal to \\(x^{127} + x^{124} + x^{121} + x^{114} + 1\\).\n\nFor hash key \\(\\hgen \\in \\bin^n\\), tweak \\(T\\) and message \\(M\\), we define:\n\\begin{align*}\n    & H_{\\hgen}(T, M) \\\\\n    \\defeq & \n    \\begin{cases}\n        \\POLYVAL(\\hgen, \\fromint(2\\abs{T} + 2) \\Concat \\pad(T) \\Concat M) &\n        \\text{if } n \\text{ divides } \\abs{M} \\\\\n        \\POLYVAL(\\hgen, \\fromint(2\\abs{T} + 3) \\Concat \\pad(T) \\Concat \\pad(M \\Concat 1)) &\n        \\text{otherwise}\n    \\end{cases}\n\\end{align*}\n\n\\subsection{XCTR mode}\nHCTR and HCTR2 use an unusual mode of stream encryption,\nwhich we name \\emph{XCTR mode}:\n\\begin{displaymath}\n    \\XCTR_k(S) = E_k(S \\xor \\fromint(1)) \\Concat E_k(S \\xor \\fromint(2)) \\Concat E_k(S \\xor \\fromint(3)) \\Concat \\cdots\n\\end{displaymath}\nGenerating the first \\(m\\) bits \\(\\XCTR_k(S)[0; m]\\) takes \\(\\ceil{m/n}\\) block cipher calls. \n\n\\subsection{HCTR2}\nHCTR2 encryption, defined in \\autoref{pseudocode},\ntakes a tweak and a plaintext,\nand returns a ciphertext of the same length as the plaintext.\nHCTR2 decryption (\\autoref{decryptionpseudocode})\nrecovers the plaintext given the same tweak and the ciphertext, ie\nfor \\(k \\in \\mathcal{K}\\), \\(T \\in \\mathcal{T}\\)\nand \\(P \\in \\mathcal{M}\\),\n\\(\\textsc{Decrypt}(k, T, \\textsc{Encrypt}(k, T, P)) = P\\).\n\\end{document}\n", "meta": {"hexsha": "2f0362ffcc978752aeab5fa7db2264235c552d5a", "size": 3754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/specification.tex", "max_stars_repo_name": "google/hctr2", "max_stars_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-11-05T14:23:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:24:43.000Z", "max_issues_repo_path": "paper/specification.tex", "max_issues_repo_name": "google/hctr2", "max_issues_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2021-11-01T21:35:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T23:41:06.000Z", "max_forks_repo_path": "paper/specification.tex", "max_forks_repo_name": "google/hctr2", "max_forks_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-04T17:58:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T13:29:03.000Z", "avg_line_length": 43.1494252874, "max_line_length": 137, "alphanum_fraction": 0.631326585, "num_tokens": 1334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6492813563761566}}
{"text": "\\chapter{Maximum Likelihood Estimation for Multiparameter Models}\\label{S:MultiParamEst}\n\n\\section{Introduction}\\label{S:MultiParamEstIntro}\nWhen two or more parameters index a statistical experiment we want to estimate the vector-valued parameter $\\theta^* := (\\theta^*_1,\\ldots,\\theta^*_k)$.\nHere we will find the maximum likelihood estimates of vector-valued parameters.  \n\nThe maximum likelihood estimator (MLE) of a possibly unknown but fixed parameter  $\\theta^* := (\\theta^*_1,\\ldots,\\theta^*_k)$  in a multi-parametric experiment, i.e.~$\\theta^* \\in \\BB{\\Theta} \\subset \\Rz^k$ with $1 < k < \\infty$ is defined analogously to \\hyperref[D:LklFn]{Definition~\\ref*{D:MLE}} with the exception that we allow the parameter to be a vector.  We take an excursion in multi-dimensional optimisation before finding the MLE of a parametric experiment involving two parameters.\n\n \\section{Practical Excursion in Multi-dimensional Optimisation}\\label{S:PracticalMultiDimOptimization}\nThe basic idea involves multi-dimensional iterations that attempt to converge on a local maximum close to the starting vector $\\theta^{(0)} \\in \\BB{\\Theta}$ (our initial guess).  We can employ {\\sc Matlab}'s built-in function {\\tt fminsearch} to find the MLE of vector-valued parameters such as in the $\\lognormal$ model with two parameters, i.e.~$\\theta=(\\lambda,\\zeta) \\in \\BB{\\Theta} \\subset \\Rz^2$.  The  function {\\tt fminsearch} is similar to {\\tt fminbnd} except that it handles a given function of many variables, and the user specifies a starting vector $\\theta^{(0)}$ rather than a starting interval.  Thus, {\\tt fminsearch} tries to return a vector $\\theta^{(*)}$ that is a local minimiser of, $-\\log(L(x_1,x_2,\\ldots,x_n; \\theta)$, the negative log-likelihood function of the vector-valued parameter $\\theta$, near this starting vector $\\theta^{(0)}$.  \nWe illustrate the use of {\\tt fminsearch} on a more challenging target called the Levy density:\n\n{\\scriptsize\n\\begin{equation}\\label{E:LevyDensity}\nf(x,y)   =  \\exp \\left(-\\frac{1}{50} \\left( \\left( \\sum_{i=1}^5 {i \\cos{((i-1)x+i)} } \\right) \\left( \\sum_{j=1}^5 {j \\cos{((j+1)y+j)} } \\right)+ (x + 1.42513 )^2 + (y + 0.80032)^2\\right) \\right)\n\\end{equation}\n}\n\n\\begin{figure}[htpb]\n\\caption{Plot of Levy density as a function of the parameter $(x,y) \\in [-10,10]^2$ scripted in \\hyperref[Mf:LevyDensityPlot]{Labwork \\ref*{Mf:LevyDensityPlot}}.\\label {F:LevyDensityPlot}}\n\\begin{center}\n\\makebox{\\includegraphics[width=6.750in]{figures/LevyDensityT50}}\n\\end{center}\n\\end{figure}\n\n{\\tt fminsearch} uses the simplex search method [Nelder, J.A., and Mead, R.~1965, Computer Journal, vol.~7, p.~308-313].  For an animation of the method and more details, please visit \\href{http://en.wikipedia.org/wiki/Nelder-Mead_method}{\\url{http://en.wikipedia.org/wiki/Nelder-Mead_method}}.  \n%For a more recent treatment see Lagarias, J.C., J. A. Reeds, M. H. Wright, and P. E. Wright, {\\em Convergence Properties of the Nelder-Mead Simplex Method in Low Dimensions}, SIAM Journal of Optimisation, Vol. 9 Number 1, pp. 112-147, 1998.  \nAn advantage of the method is that it does not use numerical (finite differencing) or analytical (closed-form expressions) gradients but relies on a direct search method.  Briefly, the simplex algorithm tries to ``tumble and shrink'' a simplex towards the local valley of the function to be minimised.  If $k$ is the dimension of the parameter space or domain of the function to be optimised, a $k$-dimensional simplex is specified by its $k+1$ distinct vertices each of dimension $k$.  Thus, a simplex is a triangle in a two-dimensional space and a pyramid in a three-dimensional space. At each iteration of the algorithm: \n\\begin{enumerate}\n\\item A new point inside or nearby the current simplex is proposed.\n\\item The function's value at the newly proposed point is compared with its values at the vertices of the simplex. \n\\item One of the vertices is typically replaced by the proposed point, giving rise to a new simplex. \n\\item The first three steps are repeated until the diameter of the simplex is less than the specified tolerance.  \n\\end{enumerate}\n\nA major limitation of {\\tt fminsearch}, as demonstrated with the Levy target (encoded in \\hyperref[Mf:NegLevyDensity]{Labwork~\\ref*{Mf:NegLevyDensity}}) is that it  can only give local solutions.  The {\\bf global maximiser} of the Levy function $f(x,y)$ is $(-1.3069, -1.4249)$ and the {\\bf global maximum} is $f (-1.3069, -1.4249)=33.8775$ For instance, if we start the search close to, say $(x^{(0)},y^{(0)})=(-1.3,-1.4)$, as shown below, then the simplex algorithm converges as desired to the solution $(-1.3068, -1.4249)$.\n\\begin{VrbM}\n>> [params, fvalue, exitflag, output] = fminsearch('NegLevyDensity',[-1.3 -1.4],options)\nparams =   -1.3068   -1.4249\nfvalue =  -33.8775\nexitflag =     1\noutput = \n    iterations: 24\n     funcCount: 46\n     algorithm: 'Nelder-Mead simplex direct search'\n       message: [1x194 char]\n\\end{VrbM}\nHowever, if we start the search further away, say $(x^{(0)},y^{(0)})=(1.3,1.4)$, as shown below, then the algorithm converges to the {\\bf local maximiser} $(1.1627,1.3093)$ with a {\\bf local maximum} value of $f(1.1627,1.3093)=0.9632$, which is clearly smaller than the global maximum of $33.8775$.  \n\\begin{VrbM}\n>> [params, fvalue, exitflag, output] = fminsearch('NegLevyDensity',[1.3 1.4],options)\nparams = 1.1627    1.3093\nfvalue = -0.9632\nexitflag = 1\noutput = \n   iterations: 29\n     funcCount: 57\n     algorithm: 'Nelder-Mead simplex direct search'\n       message: [1x194 char]\n\\end{VrbM}\nTherefore, we have to be extremely careful when using point-valued, iterative,  local optimisation algorithms, implemented in floating-point arithmetic to find the global maximum.  Other examples of such algorithms include:\n\\begin{itemize}\n\\item {\\bf Conjugate Gradient Method}:\\\\ \\href{http://en.wikipedia.org/wiki/Conjugate_gradient_method}{\\url{http://en.wikipedia.org/wiki/Conjugate_gradient_method}}\n\\item {\\bf Broyden-Fletcher-Goldfarb-Shanno (BFGS) method}:\\\\ \\href{http://en.wikipedia.org/wiki/BFGS_method}{\\url{http://en.wikipedia.org/wiki/BFGS_method}}\n\\item {\\bf Simulated Annealing}:\\\\ \\href{http://en.wikipedia.org/wiki/Simulated_annealing}{\\url{http://en.wikipedia.org/wiki/Simulated_annealing}}\n\\end{itemize}\nIn general, we have no guarantee that the output of such local optimisation routines will indeed be the global optimum.  In practice, you can start the search at several distinct starting points and choose the best local maximum from the lot.\n\n\\begin{figure}[hbpt]\n\\caption{Plot of the ``well-behaved'' (uni-modal and non-spiky) $\\log(L((x_1,x_2,\\ldots,x_{100});\\lambda,\\zeta))$, based on $100$ samples $(x_1,x_2,\\ldots,x_{100})$ drawn from the $\\lognormal(\\lambda^*=10.36,\\zeta^*=0.26)$ as per \\hyperref[Mf:LogNormalLogLklPlot]{Labwork \\ref*{Mf:LogNormalLogLklPlot}}.\\label {F:LogNormalLogLklPlot}}\n\\begin{center}\n\\makebox{\\includegraphics[width=4.0in]{figures/LogNormalLogLklPlot}}\n\\end{center}\n\\end{figure}\n\nWhen the target function is ``well-behaved,'' i.e.~uni-modal or single-peaked and not too spiky, the optimisation routine can be expected to perform well.  Log-likelihood functions are often well-behaved.  Let us generate $100$ samples from an RV $C\\sim \\lognormal(\\lambda^*=10.36, \\zeta^*=0.26)$ by exponentiating the samples from the $\\normal(10.36,0.26^2)$ RV, and then compute the corresponding MMEs and MLEs for parameters $(\\lambda,\\zeta)$ using the formulae in \\hyperref[T:MMEMLE]{Table~\\ref*{T:MMEMLE}}.\n\\begin{VrbM}\n>> rand('twister',001); % set the fundamental sampler\n>> % draw 100 samples from the Lognormal(10.36,0.26) RV\n>> Cs = exp(arrayfun(@(u)(Sample1NormalByNewRap(u,10.36,0.26^2)),rand(1,100))); \n>> MLElambdahat = mean(log(Cs)) % maximum likelihood estimate of lambda \nMLElambdahat =   10.3397\n>> MLEzetahat = sqrt(mean( (log(Cs)-MLElambdahat) .^ 2)) % max. lkl. estimate of zeta\nMLEzetahat =    0.2744\n>> MMEzetaahat = sqrt(log(var(Cs)/(mean(Cs)^2) + 1)) % moment estimate of zeta\nMMEzetaahat =    0.2624\n>> MMElambdahat = log(mean(Cs))-(0.5*MMEzetaahat^2) % moment estimate of lambda\nMMElambdahat =   10.3417\n\\end{VrbM}\nLet us try to apply the simplex algorithm to find the MLE numerically.  We first encode the negative log-likelihood function of the parameters $(\\lambda,\\zeta) \\in (0,\\infty)^2$ for the given data $x$, as follows: \n{\\VrbMf[label=NegLogNormalLogLkl.m]{scripts/NegLogNormalLogLkl.m}}\nHere is how we can call {\\tt fminsearch} and find the MLE after the re-transformation. \n\\begin{VrbM}\n>> [params, fvalue, exitflag, output] = ...\nfminsearch(@(params)(NegLogNormalLogLkl(Cs,params)),[log(5), log(1)])\nparams =    2.3360   -1.2931\nfvalue =  -1.0214e+03\nexitflag =     1\noutput = \n    iterations: 74\n     funcCount: 131\n     algorithm: 'Nelder-Mead simplex direct search'\n       message: [1x194 char]\n>> % But we want exp(params) since we defined lambda and zeta as exp(params)\nexp(params)\nans =   10.3397    0.2744\n\\end{VrbM}\nNote that the MLEs $(\\widehat{\\lambda}_{100},\\widehat{\\zeta}_{100}) = (10.3397,0.2744)$ from $74$ iterations or ``tumbles'' of the `Nelder-Mead simplex (triangle)' and the MLEs agree well with the direct evaluations {\\tt MLElambdahat} and {\\tt MLEzetahat} based on the formulae in \\hyperref[T:MMEMLE]{Table~\\ref*{T:MMEMLE}}.\n\n%%\\newpage\n%\\begin{labwork}\n%Recall \\hyperref[LW:lognormal]{labwork~\\ref*{LW:lognormal}} where you simulated $1000$ samples directly from the RV $C$ (in part 3.).  Pretend that you do not know the true parameters used in this particular simulation from RV $C$ and do the following:\n%\\begin{enumerate}\n%\\item Store the first 10, the first 100 and all 1000 samples in data arrays named {\\tt x10}, {\\tt x100} and {\\tt x1000} [Please don't do this manually!].\n%\\item Report the MLE of the two parameters for each of the three sub-arrays of data, namely {\\tt x10}, {\\tt x100} and {\\tt x1000}, i.e.~report the six point estimates: $\\widehat{\\lambda}_{10},\\widehat{\\zeta}_{10},\\widehat{\\lambda}_{100},\\widehat{\\zeta}_{100},\\widehat{\\lambda}_{1000},\\widehat{\\zeta}_{1000}$.\n%\\item Report the MME of the two parameters for each of the three sub-arrays of data, namely {\\tt x10}, {\\tt x100} and {\\tt x1000}, i.e.~report the six point estimates: $\\widehat{\\lambda}_{10},\\widehat{\\zeta}_{10},\\widehat{\\lambda}_{100},\\widehat{\\zeta}_{100},\\widehat{\\lambda}_{1000},\\widehat{\\zeta}_{1000}$.\n%\\item Discuss in a short paragraph what you can deduce from the two sets of point estimates.  Explain how the maximum likelihood (ML) and method of moments (MM) estimates of the parameters are related to the true parameters used in the simulation as the sample size increases in powers of $10$. \n%\\item {\\bf There is no credit for this part}: Try to use {\\tt fminsearch} to numerically find the MLE for your data and make a 2D-plot of the log-likelihood function being maximised.\n%\\end{enumerate} \n%\\end{labwork}\n\n\\subsubsection*{Summarizing Table of Point Estimators}\nUsing the sample mean $\\overline{X}_n$ and sample standard deviation $S_n$ defined in \\eqref{E:SampleMeanRV} and \\eqref{E:SampleStdDevRV}, respectively, we summarise the two point estimators of the parameters of some common distributions below.  For some cases, the MLE is the same as the MME (method of moments) and can be solved analytically.\n\\begin{center}\n\\begin{table}[htbp]\n\\caption{Summary of the Method of Moment Estimator (MME) and the Maximum Likelihood Estimator (MLE) for some IID Experiments. \\label{T:MMEMLE}}\n\\begin{tabular}{l | r | r}\n\\hline\nStatistical Experiment & MLE & MME \\\\ \\hline\n$X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta)$ & $\\widehat{\\theta}=\\overline{X}_n$ & same as MLE \\\\ \\hline\n$X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\exponential(\\lambda)$ & $\\widehat{\\lambda}={1}/{\\overline{X}_n} $ & same as MLE \\\\ \\hline\n$X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\normal(\\mu,\\sigma^2)$ & $\\widehat{\\mu}=\\overline{X}_n, \\widehat{\\sigma} = \\sqrt{\\frac{n-1}{n}S^2_n} $ & $\\widehat{\\mu}=\\overline{X}_n, \\widehat{\\sigma} = S_n $ \\\\ \\hline\n$X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\lognormal(\\lambda,\\zeta)$ & $\\widehat{\\lambda}=\\frac{1}{n}{\\sum_{i=1}^n \\log(X_i)} $ & $\\widehat{\\lambda} = \\log(\\overline{X}_n) - \\frac{1}{2} {\\widehat{\\zeta}} \\ ^2$ \\\\ %\\\\\n & $\\widehat{\\zeta} = \\sqrt{\\frac{1}{n} \\sum_{i=1}^n{(\\log(X_i)-\\widehat{\\lambda})^2}} $ & $\\widehat{\\zeta} = \\sqrt{\\log \\left({S_n^2}/{\\overline{X}_n^2} +1 \\right)}$ \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\\end{center}\n\n\\section{Confidence Sets for Multiparameter Models}\\label{S:ConfSetsMultiParamModels}\nWe will extend the Fisher Information and Delta method to models with more than one parameter:\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} f(x;\\theta^*), \\qquad \\theta^* := (\\theta_1^*, \\theta_2^*, \\ldots, \\theta_k^*) \\in \\BB{\\Theta} \\subset \\Rz^k  \\ .\n\\]\nLet, the ML estimator of the fixed and possibly unknown vector-valued parameter $\\theta^*$ be:\n\\[\n\\widehat{\\Theta}_n := \\left( \\widehat{\\Theta}_{1,n}, \\widehat{\\Theta}_{2,n}, \\ldots, \\widehat{\\Theta}_{k,n} \\right), \\qquad  \\widehat{\\Theta}_n := \\widehat{\\Theta}_n(X_1,X_2,\\ldots,X_n) : \\Xz_n \\to \\BB{\\Theta}\n\\]\nand the ML estimate based on $n$ observations $x_1,x_2,\\ldots,x_n$ be:\n\\[\n\\widehat{\\theta}_n := \\left( \\widehat{\\theta}_{1,n}, \\widehat{\\theta}_{2,n}, \\ldots, \\widehat{\\theta}_{k,n} \\right), \\qquad  \\widehat{\\theta}_n := \\widehat{\\theta}_n(x_1,x_2,\\ldots,x_n) \\in \\BB{\\Theta} \\ .\n\\]\nLet the log-likelihood function and its Hessian matrix $H = (H_{i,j})_{i,j=1,2,\\ldots,k}$ of partial derivatives be:\n\\[\n\\ell_n(\\theta) := \\ell_n(\\theta_1,\\theta_2,\\ldots,\\theta_k) := \\sum_{i=1}^n \\log(f(x_i; (\\theta_1,\\theta_2,\\ldots,\\theta_k))), \\qquad\nH_{i,j} := \\frac{\\partial}{\\partial \\theta_i} \\frac{\\partial}{\\partial \\theta_j} \\ell_n(\\theta_1,\\theta_2,\\ldots,\\theta_k) \\ ,\n\\]\nrespectively, provided the log-likelihood function is sufficiently smooth.\n\\begin{definition}[Fisher Information Matrix]  The Fisher Information matrix is:\n\\begin{equation}\\label{E:FisherInfoMat}\nI_n(\\theta) := I_n(\\theta_1,\\theta_2,\\ldots,\\theta_k) =\n-\n\\begin{bmatrix}\n\\E_{\\theta}(H_{1,1}) & \\E_{\\theta}(H_{1,2}) & \\cdots & \\E_{\\theta}(H_{1,k}) \\\\\n\\E_{\\theta}(H_{2,1}) & \\E_{\\theta}(H_{2,2}) & \\cdots & \\E_{\\theta}(H_{2,k}) \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\E_{\\theta}(H_{k,1}) & \\E_{\\theta}(H_{k,2}) & \\cdots & \\E_{\\theta}(H_{k,k})\n\\end{bmatrix}\n\\end{equation}\nand its matrix inverse is denoted by $I_n^{-1}(\\theta)$.\n\\end{definition}\n\\begin{prop}[Asymptotic Normality of MLE in Multiparameter Models]\nLet \n$$X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} f(x_1;\\theta_1^*,\\theta_2^*,\\ldots,\\theta_k^*), \\qquad \\theta^*=(\\theta_1^*,\\theta_2^*,\\ldots,\\theta_k^*)\\in \\BB{\\Theta}\\subset \\Rz^k \\ ,$$\nfor some fixed and possibly unknown $\\theta^* \\in \\BB{\\Theta}\\subset \\Rz^k$.  Then, under appropriate regularity conditions:\n\\[\n{\\widehat{\\Theta}_n} := \\left( \\widehat{\\Theta}_{1,n}, \\widehat{\\Theta}_{2,n}, \\ldots, \\widehat{\\Theta}_{k,n} \\right) \\rightsquigarrow \\normal(\\theta^*,I_n^{-1})\n\\]\nIn other words, the vector-valued estimator $\\widehat{\\Theta}_n$ converges in distribution to the multivariate $\\normal$ distribution centred at the unknown parameter $\\theta^*$ with the variance-covariance matrix given by inverse Fisher Information matrix $I_n^{-1}$.  Furthermore, let $I_n^{-1}(j,j)$ denote the $j^{\\text{th}}$ diagonal entry of $I_n^{-1}$.  In this case:\n% and let $$\\widehat{\\mathsf{se}}_n ( \\widehat{\\Theta}_{j,n}) = \\sqrt{ I_n^{-1}(j,j)}$$  be the standard error of the estimator of $\\theta_j^*$\n\\[\n\\frac{\\widehat{\\Theta}_{j,n} - \\theta^*_j}{\\sqrt{I_n^{-1}(j,j)}} \\rightsquigarrow \\normal(0,1)\n\\]\nand the approximate covariance of $\\widehat{\\Theta}_{i,n}$ and $\\widehat{\\Theta}_{j,n}$ is:\n\\[\n{\\sf Cov}({\\Theta}_{i,n},{\\Theta}_{j,n}) \\approxeq I_n^{-1}(i,j) \\ .\n\\]\n\\end{prop}\nNow, let us look at a way of obtaining ML estimates and confidence sets for functions of $\\theta$.  Suppose the real-valued function $g(\\theta)=\\psi:\\BB{\\Theta} \\to \\BB{\\Psi}$ maps points in the $k$-dimensional parameter space $\\BB{\\Theta} \\subset \\Rz^k$ to points in $\\BB{\\Psi} \\subset \\Rz$.  Let the gradient of $g$ be\n\\[\n\\bigtriangledown g(\\theta)\n:=\n\\bigtriangledown g (\\theta_1,\\theta_2,\\ldots,\\theta_k)\n=\n\\begin{pmatrix}\n\\frac{\\partial} {\\partial \\theta_1}{g(\\theta_1,\\theta_2,\\ldots,\\theta_k)} \\\\\n\\frac{\\partial} {\\partial \\theta_2}{g(\\theta_1,\\theta_2,\\ldots,\\theta_k)} \\\\\n\\vdots \\\\\n\\frac{\\partial} {\\partial \\theta_k}{g(\\theta_1,\\theta_2,\\ldots,\\theta_k)} \\\\\n\\end{pmatrix} \\ .\n\\]\n\\begin{prop}[Multiparameter Delta Method]\nSuppose:\n\\begin{enumerate}\n\\item $X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} f(x_1;\\theta_1^*,\\theta_2^*,\\ldots,\\theta_k^*), \\qquad \\theta^*=(\\theta_1^*,\\theta_2^*,\\ldots,\\theta_k^*)\\in \\BB{\\Theta}\\subset \\Rz^k$,\n\\item Let  $\\widehat{\\Theta}_n$ be a ML estimator of $\\theta^* \\in \\BB{\\Theta}$ and let $\\widehat{\\theta}_n$ be its ML estimate, and\n\\item Let $g(\\theta)=\\psi:\\BB{\\Theta} \\to \\BB{\\Psi} \\subset \\Rz$ be a smooth function such that $\\bigtriangledown g(\\widehat{\\theta}_n) \\neq 0$.\n\\end{enumerate}\nThen: \n\\begin{enumerate}\n\\item $\\widehat{\\Psi}_n = g(\\widehat{\\Theta}_n)$ is the ML estimator and  $\\widehat{\\psi}_n = g(\\widehat{\\theta}_n)$ is the ML estimate of of $\\psi^*=g(\\theta^*) \\in \\BB{\\Psi}$,\n\\item The standard error of the ML estimator of $\\psi^*$ is:\n$$\\widehat{\\sf{se}}_n(\\widehat{\\Psi}_n) = \\sqrt{ \\left( \\bigtriangledown g(\\widehat{\\theta}_n) \\right)^T I_n^{-1}(\\widehat{\\theta}_n) \\left( \\bigtriangledown g(\\widehat{\\theta}_n) \\right)}, $$\n\\item The ML estimator of $\\psi^*$ is asymptotically normal, i.e.:\n$$\\frac{\\widehat{\\Psi}_n - \\psi^*}{\\widehat{\\sf{se}}_n(\\widehat{\\Psi}_n)} \\rightsquigarrow \\normal(0,1) \\  ,$$\n\\item And a $1-\\alpha$ confidence interval for $\\psi^*$ is:\n\\[\n\\widehat{\\psi}_n \\pm z_{\\alpha/2} {\\widehat{\\sf{se}}_n(\\widehat{\\Psi}_n)} \n\\]\n\\end{enumerate}\n\\end{prop}\nLet us put the theory to practice in the problem of estimating the coefficient of variation from samples of size $n$ from an RV.\n\\begin{example}[Estimating the Coefficient of Variation of a $\\normal(\\mu^*,{\\sigma^*}^2)$ RV]\\label{EX:CoeffOfVarForBivNormal}\nLet \n$$\n\\psi^* = g(\\mu^*,\\sigma^*)=\\sigma^*/\\mu^*, \\qquad X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\normal(\\mu^*,{\\sigma^*}^2) \\ .\n$$ \nWe do not know the fixed parameters $(\\mu^*,\\sigma^*)$ and are interested in estimating the coefficient of variation $\\psi^*$ based on $n$ IID samples $x_1,x_2,\\ldots,x_n$.  We have already seen that the ML estimates of $\\mu^*$ and $\\sigma^*$ are:\n\\[\n\\widehat{\\mu}_n =  \\overline{x}_n := \\frac{1}{n}\\sum_{i=1}^n x_i,  \\qquad \n\\widehat{\\sigma}_n = s_n := \\sqrt{\\frac{1}{n} \\sum_{i=1}^n (x_i-\\widehat{\\mu}_n)^2} \\ .\n\\]\nThus, the ML estimate of $\\psi^*=\\sigma^*/ \\mu^*$ is:\n\\[\n\\widehat{\\psi}_n =  \\frac {\\widehat{\\sigma}_n}{\\widehat{\\mu}_n} = \\frac {s_n}{\\overline{x}_n}\n\\] \nWe can now derive the standard error of the ML estimator $\\widehat{\\Psi}_n$ by first computing $I_n(\\mu,\\sigma)$, $I_n^{-1}(\\mu,\\sigma)$, and $\\bigtriangledown g(\\mu,\\sigma)$.  A careful computation shows that:\n\\[\nI_n(\\mu,\\sigma) = \n\\begin{bmatrix}\n\\frac{n}{\\sigma^2} & 0\\\\\n0 & \\frac{2n}{\\sigma^2}\n\\end{bmatrix},\n\\qquad \\qquad\nI_n^{-1}(\\mu,\\sigma) = \n\\frac{1}{n}\n\\begin{bmatrix}\n{\\sigma^2} & 0\\\\\n0 & \\frac{\\sigma^2}{2}\n\\end{bmatrix},\n\\qquad \\qquad\n\\bigtriangledown g(\\mu,\\sigma) =\n\\begin{pmatrix}\n-\\frac{\\sigma}{\\mu^2} \\\\\n\\frac{1}{\\mu}\n\\end{pmatrix} \\ .\n\\]\nTherefore, the standard error of interest is:\n\\[\n\\widehat{\\sf{se}}_n(\\widehat{\\Psi}_n) = \\sqrt{ \\left( \\bigtriangledown g(\\widehat{\\theta}_n) \\right)^T I_n^{-1}(\\widehat{\\theta}_n) \\left( \\bigtriangledown g(\\widehat{\\theta}_n) \\right)} = \n\\frac{1}{\\sqrt{n}} \\sqrt{\\frac{1}{\\widehat{\\mu}_n^4} + \\frac{\\widehat{\\sigma}_n^2}{2 \\widehat{\\mu}_n^2}}\n\\]\nand the $95\\%$ confidence interval for the unknown coefficient of variation $\\psi^*$ is:\n\\[\n\\widehat{\\psi}_n \\pm z_{\\alpha/2} {\\widehat{\\sf{se}}_n(\\widehat{\\Psi}_n)}  = \n\\frac{s_n}{\\overline{x}_n} \\pm z_{\\alpha/2} \\left( \\frac{1}{\\sqrt{n}} \\sqrt{\\frac{1}{\\widehat{\\mu}_n^4} + \\frac{\\widehat{\\sigma}_n^2}{2 \\widehat{\\mu}_n^2}} \\right)\n\\]\n\\end{example}\n\nLet us get our hands dirty in the machine with Labwork~\\ref{LW:CoeffOfVarForBivNormal} next.\n\\begin{labwork} [Computing the coefficient of variation of a $\\normal(\\mu^*,{\\sigma^*}^2)$ RV]\\label{LW:CoeffOfVarForBivNormal}\nLet us apply these results to $n=100$ simulated samples from $\\normal(100,10^2)$ as follows.\n{\\VrbMf[label=CoeffOfVarNormal.m]{scripts/CoeffOfVarNormal.m}}\n\\begin{VrbM}\n>> CoeffOfVarNormal\nMuhat =  100.3117\nSigmahat =   10.9800\nPsihat =    0.1095\nSehat =    0.0077\nConfInt95 =    0.0943    0.1246\n\\end{VrbM}\n\\end{labwork}\n", "meta": {"hexsha": "718bfbd5c216b460c42dba44068aa35174c8e9f0", "size": 20525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/MultiParamEstim.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/MultiParamEstim.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/MultiParamEstim.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": 72.7836879433, "max_line_length": 865, "alphanum_fraction": 0.6994884287, "num_tokens": 6959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6492238658048131}}
{"text": "\\section{M/M/m Queues}\n\\label{sec:M-M-m-Queues}\n\nA $M/M/m$ is a queue where \n(i) the arrival process is Poissonian with rate $\\lambda$,\n(ii) the service process is Exponential with rate $\\mu$,\n(iii) there are $m$ servers,\n(iv) the buffer has infinite capacity,\n(v) the scheduling policy is FCFS.\n\n%\\begin{figure}[tp]\n%\\label{fig:M-M-m-Queue}\t\n%\t\\centering\n%\t\\includegraphics{fig/M-M-m-Queue}\n%\t\\caption{An M/M/m queue and its corresponding CTMC.}\n%\\end{figure}\n\nThe key question in these types of systems is determining the \\textit{Queue Probability} $P_{Q}$, that is the probability that an arriving job is enqueued.\n\n\\begin{definition}[Utilization]\n\\label{def:M-M-m-Utilization}\n\tFor any $M/M/m$, the system utilization is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Utilization}\n\t\\varrho = \\frac{\\lambda}{m \\mu}\n\t\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Resource Requirement]\n\\label{def:M-M-m-Resource-Requirement}\n\tFor any $M/M/m$, the resource requirement is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Resource-Requirement}\t\n\tR = \\frac{\\lambda}{\\mu}\n\t\\end{equation}\n\\end{definition}\n\nThe resource requirement $R$ is \n(i) the minimum number of servers needed to keep the system stable,\n(ii) the expected number of busy servers, and \n(iii) the expected number of jobs in service.\n\t\n\\begin{theorem}[State Probability]\n\\label{thm:M-M-m-Probability-State}\t\n\tFor any $M/M/m$, the state probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Probability-State}\n\t\\pi_{i} = \\frac{m^{q} \\varrho^{i}}{q!} \\cdot \\pi_{0}\n\t\\end{equation}\n\t\n\twith\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Probability-State-Zero}\t\n\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\\end{equation}\n\t\n\twhere\n\t\n\t$q=\\min\\{i,m\\}$ is the number of busy servers.\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 258-259.\n\t\\end{proof}\n\\end{theorem}\n\n\\begin{theorem}[Queue Probability]\n\t\\label{thm:M-M-m-Probability-Queue}\t\n\tFor any $M/M/m$, the queue probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Probability-Queue}\n\tP_{Q} = \\frac{(m \\varrho)^{m}}{m!(1-\\varrho)} \\cdot \\pi_{0}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 260.\n\t\\end{proof}\n\\end{theorem}\n\n\\Cref{thm:M-M-m-Probability-Queue} is called \\textit{Erlang-C Formula}.\n\n\\begin{theorem}[Mean Queue Jobs]\n\t\\label{thm:M-M-m-Mean-Queue-Jobs}\t\n\tFor any $M/M/m$, the expected number of jobs in queue is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-Mean-Queue-Jobs}\n\t\\expected{N_{Q}} = \\frac{\\varrho}{(1-\\varrho)} \\cdot P_{Q}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 262.\n\t\\end{proof}\n\\end{theorem}\n\nThe remaining metrics ($\\expected{N},\\expected{T},\\expected{T_{Q}}$) could be determined by applying the Little's Law, the basic definitions \n$\\expected{N}=\\expected{N_{Q}}+\\expected{N_{S}}$, \n$\\expected{N_{S}}=R$, \n$\\expected{T}=\\expected{T_{Q}}+\\expected{T_{S}}$, and\n$\\expected{T_{S}}=\\frac{1}{\\mu}$.\n\nIn particular we obtain:\n\n\\begin{equation}\n\\label{eqn:M-M-m-Delay}\n\\expected{T_{Q}} = \\frac{1}{\\lambda} P_{Q} \\frac{\\varrho}{(1-\\varrho)}\n\\end{equation}\n\n\\begin{equation}\n\\label{eqn:M-M-m-Reponse-Time}\n\\expected{T} = \\frac{1}{\\lambda} P_{Q} \\frac{\\varrho}{(1-\\varrho)} + \\frac{1}{\\mu}\n\\end{equation}\n\n\\begin{equation}\n\\label{eqn:M-M-m-System-Jobs}\n\\expected{N} = P_{Q} \\frac{\\varrho}{(1-\\varrho)} + m\\varrho\n\\end{equation}\n\n\n\n\n\\subsection{Comparison between M/M/m and M/M/1}\n\\label{sec:Comparison-M-M-m-And-M-M-1}\n\nLet us consider \n(i) a $M/M/m$ with average arrival rate $\\lambda$ and average service rate $\\mu$, and\n(ii) a $M/M/1$ with average arrival rate $\\lambda$ and average service rate $m \\mu$.\n\nUnder light load, in (i) jobs are served by few servers with rate $\\mu$; whereas in (ii) jobs are served with rate $m \\mu$.\nUnder high load, in (i) the state is always greater than $m$ and it behaves just like (ii).\n\nHence, if $\\lambda^{M/M/1} = \\lambda^{M/M/m}$ and $\\mu^{M/M/1} = m \\mu^{M/M/m}$, then $M/M/1$ is always at least $m$ time faster than $M/M/m$.\n\n\n\n\n\\subsection{Comparison between M/M/m/m and M/M/m}\n\\label{sec:Comparison-M-M-m-m-And-M-M-m}\n\nIt is interesting to compare the block probability of a $M/M/m/m$ with the queue probability of an equivalent $M/M/m$.\nThe following theorem compares $P_{block}^{M/M/m/m}$ with $P_{Q}^{M/M/m}$.\n\n\\begin{theorem}[Relation $P_{block}^{M/M/m/m}$ with $P_{Q}^{M/M/m}$]\n\\label{thm:Relation-Probability-Block-Probability-Queue}\t\n\tFor any $M/M/m/m$ with block probability $P_{block}$ and any $M/M/m$ with queue probability $P_{Q}$, we have that\n\t \n\t\\begin{equation}\n\t\\label{eqn:Relation-Probability-Block-Probability-Queue}\n\tP_{block} = \\frac{(1-\\varrho)P_{Q}}{1-\\varrho P_{Q}}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 261.\n\t\\end{proof}\n\\end{theorem}", "meta": {"hexsha": "1272a3467b392d5bc68b024b381720f41167a6a9", "size": 4909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-m-m-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-m-m-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-m-m-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": 30.8742138365, "max_line_length": 155, "alphanum_fraction": 0.6858830719, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.6492238625262197}}
{"text": "\\section{Calculations and Results}\nFrom the following equaitions,\n\n$$ \\tau_z = I\\beta_z $$\n$$ I_{ab} = I_A + I_B $$\n$$ M_\\mu = -I_1\\beta_1 $$\n$$ T = m(g-a)$$\n\nWe can derive\n$$ m(g-R\\beta_2)R-M_\\mu=I_1\\beta_2 $$\nThen we find\n$$ I_1=\\frac{mR(g-R\\beta_2)}{\\beta_2-\\beta_1} $$\nSimilarly, if a rigid body with an unknown moment of inertia is placed on the\nturntable, we may find \n$$ I_2=\\frac{mR(g-R\\beta_4)}{\\beta_4-\\beta_3} $$\nUsing the fact that the moment of inertia is an additive quantity, the moment of\ninertia of the rigid object placed on the turntable, with respect to the axis of\nrotation, may be found as the difference \n$$ I_3 = I_2 - I_1 $$\n\n\\subsection{Measurement of Angular Acceleration}\nAngular acceleration can be derive by investigating the measurement data (k,t),\nthe corresponding angular position is\n$$ \\theta = k\\pi = \\omega_0 t + \\frac{1}{2}\\beta t^2 $$\n\n\n\\subsection{In Lab Data}\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabularx}{\\textwidth}{|p{6cm}|X|X|X|X|}\n    \\hline\n    Object & 1 & 2 & 3 & 4 \\\\\n    \\hline\n    Disk $[cm] \\pm 0.002[cm]$& 24.098 & 24.094 & 24.094 & 24.094 \\\\\n    Hoop 1 $[cm] \\pm 0.002[cm]$& 20.982 & 20.918 & 20.966 & 20.976 \\\\\n    Hoop 2 $[cm] \\pm 0.002[cm]$& 23.998 & 24.000 & 24.000 & 24.002 \\\\\n    Cylinder A $[cm] \\pm 0.002[cm]$& 2.994 & 2.994 & 2.994 & 2.994 \\\\\n    Cylinder B $[cm] \\pm 0.002[cm]$& 2.994 & 2.994 & 2.994 & 2.994 \\\\\n    Cone pulley $[cm] \\pm 0.002[cm]$& 5.022 & 5.020 & 5.008 & 5.008 \\\\\n    Hole 1 d $[cm] \\pm 0.002[cm]$& 3.978 & 5.534 & & \\\\\n    Hole 2 d $[cm] \\pm 0.002[cm]$& 3.982 & 5.540 & & \\\\\n    Hole 3 d $[cm] \\pm 0.002[cm]$& 5.524 & 6.500 & & \\\\\n    Hole 4 d $[cm] \\pm 0.002[cm]$& 5.520 & 6.520 & & \\\\\n    \\hline\n  \\end{tabularx}\n  \\caption{Calliper measurements}\n  \\end{table}\n\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabularx}{\\textwidth}{|X|X|}\n    \\hline\n    Object & Mass\\\\\n\t\\hline\n    Disk $[g] \\pm 0.1 [g] $ & 493.1\\\\\n    Hoop $[g] \\pm 0.1 [g] $ & 422.5\\\\\n    Cylinder A $[g] \\pm 0.1 [g] $ & 165.8\\\\\n    Cylinder B $[g] \\pm 0.1 [g] $ & 165.8\\\\\n    Weight $[g] \\pm 0.1 [g] $ & 59.1 \\\\\n    \\hline\n  \\end{tabularx}\n  \\caption{Mass measurements}\n  \\end{table}\n% begin real data\n\\begin{table}[H]\n  \\centering\n\\begin{tabular}{|p{2cm}|p{1.5cm}|l|l|l|l|l|l|l|l|l|}\n\\hline\nSituation & A or D & k & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\\n\\hline\nEmpty & Dec & $t[s]$ & 0.2958 & 0.5924 & 0.8899 & 1.1881 & 1.4873 & 1.7871 & 2.0879 & 2.3895 \\\\\nEmpty & Acc & $t[s]$ & 0.9005 & 1.5186 & 2.0204 & 2.4557 & 2.8448 & 3.1996 & 3.5280 & 3.7038 \\\\\nWith disk & Dec &  $t[s]$ & 0.3178 & 0.6362 & 0.9554 & 1.2752 & 1.5958 & 1.9170 & 2.2390 & 2.5616 \\\\\nWith disk & Acc &  $t[s]$ & 0.8957 & 1.5808 & 2.1582 & 2.6666 & 3.1264 & 3.5491 & 3.9428 & 4.3322 \\\\\nWith hoop & Dec &  $t[s]$ & 0.2450 & 0.4903 & 0.7359 & 0.9818 & 1.2281 & 1.4746 & 1.7216 & 1.9688 \\\\\nWith hoop & Acc &  $t[s]$ & 1.0035 & 1.7614 & 2.3967 & 2.9547 & 3.4589 & 3.9216 & 4.3521 & 4.7560 \\\\\nA 1 B 2 & Dec &  $t[s]$ & 0.4491 & 0.9003 & 1.3536 & 1.8089 & 2.2666 & 2.7263 & 3.1883 & 3.6524 \\\\\nA 1 B 2 & Acc &  $t[s]$ & 1.3586 & 2.0905 & 2.6595 & 3.1424 & 3.5692 & 3.9562 & 4.3125 & 4.6448 \\\\\nA 3 B 4 & Dec &  $t[s]$ & 0.4539 & 0.9099 & 1.3678 & 1.8279 & 2.2899 & 2.7541 & 3.2204 & 3.6888 \\\\\nA 3 B 4 & Acc &  $t[s]$ & 1.3748 & 2.1298 & 2.7179 & 3.2171 & 3.6585 & 4.0587 & 4.4273 & 4.7711 \\\\\n\\hline\n\\end{tabular}\n\\caption{ Time measurements}\n\\end{table}\n\nAccording to  United States Department of Commerce, the standard gravitational\nacceleration is \n$$ g =  9.80665 m/s^2 $$\n\n% ==================================================================\n% ==================================================================\nFor the Empty turntable,\n\\newcommand{\\EFWwr}{17cm}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/etd}\n\\end{figure}\n\n$$ \\beta_1 = -0.0970 radius/s^2$$ (with 95\\% confidence bounds) \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/eta}\n\\end{figure}\n\n$$ \\beta_2 = 2.6580 radius/s^2$$ (with 95\\% confidence bounds) \n\nThus,\n$$ I_1 = \\frac{59.1 g \\times 5.0145 cm \\times (9.80665 m/s^2 - 5.0145 cm \\times (-0.0970) radius/s^2 )}{2.6580 radius/s^2 -(-0.0970 radius/s^2) } = 0.0105 kg\\times m^2 $$\n\n% ==================================================================\n% ==================================================================\nFor turntable with disk,\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/wdd}\n\\end{figure}\n\n$$ \\beta_1 = -0.0668 radius/s^2$$ (with 95\\% confidence bounds) \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/wda}\n\\end{figure}\n\n$$ \\beta_2 = 1.2970 radius/s^2$$ (with 95\\% confidence bounds) \n\n$$ I_2 = \\frac{59.1 g \\times 5.0145 cm \\times (9.80665 m/s^2 - 5.0145 cm \\times (-0.0668) radius/s^2 )}{1.2970 radius/s^2 -(-0.0668 radius/s^2) } = 0.0213 kg\\times m^2 $$\n\n\n% ==================================================================\n% ==================================================================\nFor turntable with hoop,\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/whd}\n\\end{figure}\n\n$$ \\beta_1 = -0.0689 radius/s^2$$ (with 95\\% confidence bounds) \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/wha}\n\\end{figure}\n\n$$ \\beta_2 = 1.1444 radius/s^2$$ (with 95\\% confidence bounds) \n\n\n$$ I_3 = \\frac{59.1 g \\times 5.0145 cm \\times (9.80665 m/s^2 - 5.0145 cm \\times (-0.0689) radius/s^2 )}{1.1444 radius/s^2 -(-0.0689 radius/s^2) } =  0.0240 kg\\times m^2 $$\n\n\n% ==================================================================\n% ==================================================================\nFor Cylinder A in hole 1, B in hole 2\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/cabd}\n\\end{figure}\n\n$$ \\beta_1 = -0.0710 radius/s^2$$ (with 95\\% confidence bounds) \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/caba}\n\\end{figure}\n\n$$ \\beta_2 = 1.8752 radius/s^2$$ (with 95\\% confidence bounds) \n\n\n$$ I_4 = \\frac{59.1 g \\times 5.0145 cm \\times (9.80665 m/s^2 - 5.0145 cm \\times (-0.0710) radius/s^2 )}{1.8752 radius/s^2 -(-0.0710 radius/s^2) } =  0.0149 kg\\times m^2 $$\n\n\n% ==================================================================\n% ==================================================================\nFor Cylinder A in hole 3, B in hole 4\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/ccdd}\n\\end{figure}\n\n$$ \\beta_1 = -0.0661 radius/s^2$$ (with 95\\% confidence bounds) \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\EFWwr]{matlab/ccda}\n\\end{figure}\n\n$$ \\beta_2 = 1.7496 radius/s^2$$ (with 95\\% confidence bounds) \n\n\n$$ I_5 = \\frac{59.1 g \\times 5.0145 cm \\times (9.80665 m/s^2 - 5.0145 cm \\times (-0.0661) radius/s^2 )}{ 1.7496 radius/s^2 -(-0.0661 radius/s^2) } = 0.0160 kg\\times m^2 $$\n\nThus, the moment of inertia for disk is \n$$ I_{disk} = I_2 - I_1 = 0.0213  kg\\times m^2 - 0.0105 kg\\times m^2 =  0.0108  kg\\times m^2 $$\n\nThe moment of inertia for hoop is \n$$ I_{hoop} = I_3 - I_1 = 0.0240  kg\\times m^2 - 0.0105 kg\\times m^2 =  0.0135  kg\\times m^2 $$\n\nThe moment of inertia for Cylinder A in hole 1 and Cylinder B in hole 2 is \n$$ I_{A1B2} = I_4 - I_1 = 0.0149  kg\\times m^2 - 0.0105 kg\\times m^2 =  0.0044  kg\\times m^2 $$\n\nThe moment of inertia for Cylinder A in hole 3 and Cylinder B in hole 4 is \n$$ I_{A3B4} = I_5 - I_1 = 0.0160  kg\\times m^2 - 0.0105 kg\\times m^2 =  0.0055  kg\\times m^2 $$\n\n$$ I_{A3B4} -I_{A1B2} =0.0055  kg\\times m^2 -   0.0044  kg\\times m^2 = 0.0011 kg\\times m^2  $$\n$$ md^2 =  165.8 g \\times  (4.7560 cm - 6.0120cm )^2 + 165.8 g \\times  (4.7610 cm - 6.0200cm )^2  = 0.0052436 kg\\times m^2 $$\n\nThus, the relative uncertainty is $$ \\frac{ 0.0055  kg\\times m^2 - 0.0052436 kg \\times m^2}{0.0055  kg\\times m^2} = 4.66 \\% $$\n\n", "meta": {"hexsha": "42884dd390cc03042c19b7ec2804f1178d02b1a6", "size": 7717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E1/part/calculation.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": "E1/part/calculation.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": "E1/part/calculation.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": 35.8930232558, "max_line_length": 171, "alphanum_fraction": 0.5557859272, "num_tokens": 3232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706733, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.649223857496951}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage{fancyhdr}\n\\usepackage[margin=.7in]{geometry}\n\\usepackage{exsheets}\n\\usepackage{enumerate}\n\n\\usepackage{./Style/linearProgramsStyle} % This is a set of commands for maths content.\n\n\\pagestyle{fancy}\n\n\\renewcommand{\\headrulewidth}{2pt}\n\\fancyhead[L]{EPITA\\_ING1\\_BING\\_2020\\_S5\\_PROL}\n\\fancyhead[R]{March 2018}\n\n\\fancyfoot[C]{\\textbf{\\thepage}}\n\\fancyfoot[L]{}\n\n\\pretitle{\\vspace{-.5\\baselineskip} \\begin{center}}\n\\title{%\n  { \\huge Linear Programming}\\\\ %\n  \\vspace{.5\\baselineskip}\n  {\\Large \\textit{Complemetary Exam} }\n}\n\\posttitle{\n\\end{center}\n  \\begin{flushleft}\n    \\vspace{2\\baselineskip} \\textit{\n      \\!\\!\\emph{Duration: 1h30.}\\\\\n      \\! \\emph{No documents are allowed.}  \\\\\n      Only \\emph{non-programmable} pocket calculators are allowed.\n    }\n  \\end{flushleft}\n  \\rule{\\textwidth}{1.5pt}\n  \\vspace{-5\\baselineskip}\n}\n\\author{}\n\\date{}\n\n\\pdfinfo{\n   /Author (Bashar Dudin)\n   /Title  (PROL Exam -- 2018)\n   /Subject (Linear Programming)\n}\n\n\\begin{document}\n\n\\maketitle\\thispagestyle{fancy}\n\nWe're considering the following list of linear programs respectively\ngiven the names $(A)$, $(B)$, $(C)$, $(D)$, $(E)$ and $(F)$.\n\\[\n(A) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $3x_1 + 2x_2 + 3x_3$\n    }{\n      \\systeme{\n        -x_1 - 2x_2 - 3x_3 \\leq 5,\n        2x_1 + x_2 + x_3 \\leq 3,\n        -x_1 - x_2 + x_3 \\leq 1\n      }\n    }{\n      $x_1$, $x_2$, $x_3 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\qquad (B)\\;\n\\left\\{\n  \\begin{linearProg}{\n      minimize\n    }{\n      $ x_1 + x_2 - x_3$\n    }{\n      \\systeme{\n        -x_1 - 2x_2 + 3x_3 \\leq 1,\n        - x_1 - x_2 + 2x_3 \\geq 2\n      }\n    }{\n      $x_1$, $x_2$, $x_3 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\\[\n(C) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $3x_1 + 2x_2 + 3x_3$\n    }{\n      \\systeme{\n        -x_1 - 2x_2 - 3x_3 \\leq 5,\n        2x_1 + x_2 + x_3 \\leq 3,\n        -x_1 - x_2 + x_3 \\leq 1\n      }\n    }{\n      $x_1$, $x_2 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\qquad (D) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $-x_1 - x_2 + x_3$\n    }{\n      \\systeme{\n        -x_1 + 2x_2 - 3x_3 + x_4 = 1,\n         x_1 + x_2 - 2x_3 \\leq -2\n      }\n    }{\n      $x_1$, $x_2$, $x_3$, $x_4 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\\[\n\\qquad (E)\\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $ -x_1 - x_2 + x_3$\n    }{\n      \\systeme{\n        -x_1 - 2x_2 + 3x_3 \\leq 1,\n        - x_1 - x_2 + 2x_3 \\geq 2\n      }\n    }{\n      $x_1$, $x_2$, $x_3 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\qquad (F)\\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $6x_1 + 4x_2 + 6x_3$\n    }{\n      \\systeme{\n        -x_1 - 2x_2 - 3x_3 \\leq 5,\n        2x_1 + x_2 + x_3 \\leq 3,\n        x_1 + x_2 - x_3 \\geq -1\n      }\n    }{\n      $x_1$, $x_2 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\n\\section{Equivalence and Duality}\n\n\\begin{question}{3}\n  Which previous programs are equivalent to each others? Sort them\n  into groups of equivalent classes.\n\\end{question}\n\n\\begin{question}{2}\n  Give standard form of $(F)$. What is the slack form of $(B)$?\n\\end{question}\n\n\\begin{question}{2}\n  What are the dual programs of $(A)$ and $(E)$?\n\\end{question}\n\n\\begin{question}{2}\n  Guess feasible solutions of $(A)$ and $(D)$.\n\\end{question}\n\n\\section{Simplex Algorithm}\n\n\\begin{question}{4}\n  Solve linear program $(A)$ using the simplex algorithm.\n\\end{question}\n\n\\begin{question}{2}\n  Out of previous solution of $(A)$ give an optimal point of its\n  dual. What is its optimal objective value?\n\\end{question}\n\n\\begin{question}{5}\n  Solve dual of linear program $(E)$.\n\\end{question}\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "7715770a133db655bd5afca2975528e0a4629d87", "size": 3821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/TeX/Ecrit_PROL_2018_03_BING.tex", "max_stars_repo_name": "bashardudin/LinearPrograms", "max_stars_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2016-10-20T14:04:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-31T08:45:14.000Z", "max_issues_repo_path": "Exams/TeX/Ecrit_PROL_2018_03_BING.tex", "max_issues_repo_name": "bashardudin/LinearPrograms", "max_issues_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-04T01:30:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-09T08:18:10.000Z", "max_forks_repo_path": "Exams/TeX/Ecrit_PROL_2018_03_BING.tex", "max_forks_repo_name": "bashardudin/LinearPrograms", "max_forks_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-10-26T21:19:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-17T19:28:15.000Z", "avg_line_length": 19.105, "max_line_length": 87, "alphanum_fraction": 0.5681758702, "num_tokens": 1516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6492238565473597}}
{"text": "\\chapter{Newton and quasi-Newton methods}\n\\label{chapter:Newton}\n\n\\section{Basics of nonlinear iterations}\n\\begin{intro}\n  The efficient solution of nonlinear problems is an important\n  ingredient to implicit timestepping schemes as well as shooting\n  methods. Without attempting completeness, we present some important\n  facts about iterative methods for this problem. We introduce the two\n  generic schemes, Newton and gradient methods, discuss their\n  respective pros and cons and combine their features in order to\n  obtain better methods.\n\\end{intro}\n\n\\input{definitions/nonlinear}\n\\input{definitions/iteration-order}\n\\input{definitions/newton}\n\\input{theorems/newton-kantorovich}\n\n\\begin{remark}\n  Instead of proving the Newton-Kantorovich theorem, we discuss its\n  main assumptions and features. First, we note that it does not\n  require that the initial value be close to a root, or even assumes\n  the existence of a root. The theorem is actually an existence proof.\n  \n  The Lipschitz condition on $\\nabla f$ can be seen as the deviation\n  of $f$ from being linear. Indeed, if $f$ were linear, then $L=0$ and\n  provided $M\\neq 0$ the method converges in a single step for any\n  initial value.\n\n  The larger the constant $M$, the smaller wone of the eigenvalues of % wone?\n  the Jacobian. Therefore, the function becomes flat in that\n  direction and the root finding problem becomes unstable.\n  \n  If we have convergence due to $\\beta_0 \\le 1/2$ (the proof shows\n  contraction) there holds $\\beta_1 := LM \\left\\| f\\left(x^{(1)}\\right)\n  \\right\\| < 1/2$ and we have quadratic convergence from the second step on.\n\\end{remark}\n\n\\input{definitions/gradient-method}\n\\input{theorems/gradient-method}\n\n% \\begin{proof}\n%   First, we observe that in any point $x$ with $\\nabla F(x) \\neq 0$,\n%   there exists $\\epsilon > 0$ such that\n%   \\begin{gather*}\n%     F(x) - F(x-\\epsilon\\nabla F(x))\n%     = \\epsilon \\abs{\\nabla F(x)}^2 > 0.\n%   \\end{gather*}\n%   Thus, $F(x-\\epsilon\\nabla F(x)) < F(x)$. We conclude, that for such\n%   $x$, the line search obtains a positive value of $\\alpha$. Thus, the\n%   sequence of the gradient iteration is monotonically decreasing and\n%   stays within the set $K$.\n% \\end{proof}\n\n\\section{Globalization}\n\n\\begin{intro}\n  The convergence of the Newton method is only local, and it is the\n  faster, the closer to the solution we start. Thus, finding good\n  initial guesses is an important task. A reasonable initial guess in\n  a one-step method seems to be $y_0$, but on closer inspection, this\n  is true only if the time step is small. Therefore, the convergence\n  requirements of Newton's method would insert a new time step\n  restriction, which we want to avoid in the context of implicit\n  methods. Therefore, and for other cases like the shooting\n  methods of chapter~\\ref{chapter:rwa}, we present\n  methods which extend the domain of convergence.\n\n  As a rule, Newton'a method should never be implemented without some\n  globalization strategy!\n\\end{intro}\n\n\\input{definitions/newton-line-search}\n\\input{definitions/newton-step-size}\n\n\\begin{remark}\n  The step size control algorithm can be implemented with very low\n  overhead. In fact, in each Newton step we only have to compute the\n  norm of the residual, which is typically needed for the stopping\n  criterion anyway. Additional work is only needed if the residual\n  grows. But this is the case, when the original method was likely to\n  fail.\n\n  The convergence proof does not guarantee that the values of $j$\n  remain bounded. Practically, this is irrelevant, since typically the\n  step size control only triggers within the first few steps, then the\n  quadratic convergence of the Newton method starts.\n\\end{remark}\n\n\\input{definitions/descent-methods}\n\n\\begin{remark}\n  Obviously, the gradient method is a descent method, where the direction $s$\n  is chosen parallel to $\\nabla F(x^{(k)})$ and $\\mu$ is chosen in an\n  optimal way. It is also called the method of \\define{steepest\n    descent}.\n\\end{remark}\n\n\\begin{Lemma}{newton-descent}\n  The Newton method applied to the function $f(x)$ is a descent method\n  applied to the functional $F(x) = \\abs{f(x)}^2$. The same holds for\n  the Newton method with line search or step size control.\n\\end{Lemma}\n\n\\begin{proof}\n  By the product rule, there holds\n  \\begin{gather*}\n    \\nabla F(x) = 2 f^T(x) \\nabla f(x).\n  \\end{gather*}\n  The search direction of the Newton method is\n  \\begin{gather*}\n    s = -\\frac{d^{(k)}}{\\abs{d^{(k)}}}\n    = \\frac{\\bigl(\\nabla f(x^{(k)})\\bigr)^{-1}f(x^{(k)})}{\\abs{\\dots}}\n  \\end{gather*}\n  Thus, omitting the arguments $x^{(k)}$, we obtain\n  \\begin{gather*}\n    \\frac{\\nabla F\\, s}{\\norm{\\nabla F}}\n    = \\frac{f^T \\nabla f(x)\\bigl(\\nabla f\\bigr)^{-1} f}%\n    {\\norm{\\bigl(\\nabla f\\bigr)^{-1} f}\\,\\norm{f^T \\nabla f(x)}}\n    \\ge \\frac{\\abs{f}^2}{\\norm{\\bigl(\\nabla f\\bigr)^{-1}}\\;\n      \\norm{f}^2 \\norm{\\nabla f(x)} }\n    = \\frac1{\\operatorname{cond}_2 (\\nabla f(x))},\n  \\end{gather*}\n  where we used the operator norm $\\norm{.}$ of matrices with respect\n  tot the Euclidean norm of $\\R^d$. $\\operatorname{cond}_2(A)$ is the\n  spectral condition of $A$, namely\n  \\begin{gather*}\n    \\operatorname{cond}_2(A) = \\norm{A} \\, \\norm{A^{-1}}.\n  \\end{gather*}\n  With ~\\ref{eq:descent-methods:1} we conclude that $s\\in \\mathcal S_\\gamma(\\nabla F)$ for any\n  $\\gamma$ with\n  \\begin{gather*}\n    \\gamma \\le \\frac1{\\operatorname{cond}_2 (\\nabla f(x))}.\n  \\end{gather*}\n  The different variants of the Newton method are only distinguished by\n  a different choice of the scaling parameter $\\mu$.\n\\end{proof}\n\n\\begin{Lemma}{downhill}\n  Let $F: \\R^d \\to \\R$ be continuously differentiable. For a given\n  point $x$, assume $\\nabla F = \\nabla F(x) \\neq 0$.  Then, there is a\n  constant $\\lambda > 0$ such that for any\n  $s\\in \\mathcal S_\\gamma(\\nabla F(x))$ and any\n  $0 \\le \\mu \\le \\lambda$ there holds\n  \\begin{gather}\n    \\label{eq:downhill:1}\n    F(x-\\mu s) \\le F(x) - \\frac{\\gamma\\mu}2 \\abs{\\nabla F(x)}.\n  \\end{gather}\n  In particular, a positive scaling factor $\\mu$ for the descent method can\n  always be found.\n\\end{Lemma}\n\n% Stoer/Bulirsch I, 4. Auflage, p. 238\n\\begin{proof}\n  First, define\n  \\begin{gather*}\n    U_1(x) = \\bigl\\{ y\\in \\R^d \\big\\vert \\abs{\\nabla F(y)-\\nabla F(x)}\n    \\le \\tfrac{\\gamma}{2} \\abs{\\nabla F(x)}\\bigr\\}.\n  \\end{gather*}\n  Since $\\nabla F$ is continuous and $\\nabla F(x) \\neq 0$, this set is\n  a nonempty neighborhood of $x$.\n% Similarly, the set\n%  \\begin{gather*}\n%    U_2(x) =\n%    \\bigl\\{ y\\in \\R^d \\big\\vert \\mathcal S_\\gamma(\\nabla F(y)) \\subseteq\n%    \\mathcal S_{\\nicefrac{\\gamma}{2}}(\\nabla F(x))\\bigr\\}\n%  \\end{gather*}\n%  is a nonempty neighborhood of $x$.\nChoose now $\\lambda$ such that\n  \\begin{gather*}\n    B_{\\lambda}(x) \\subseteq U_1(x),% \\cap U_2(x).\n  \\end{gather*}\n  Hence, for any $\\mu\\in(0,\\lambda)$ and\n  $s\\in \\mathcal S_\\gamma(\\nabla F(x))$, there holds by the mean value\n  theorem with $0<\\theta<1$\n  \\begin{multline*}\n    F(x)-F(x-\\mu s) = \\mu \\nabla F(x-\\theta\\mu s)s \\\\\n    = \\mu \\Bigl(\\bigl(\\nabla F(x-\\theta\\mu s) - \\nabla F(x)\\bigr)\n    +\\nabla F(x)\\Bigr).\n  \\end{multline*}\n  Using the definitions of $U_1(x)$ and $U_2(x)$, we obtain\n  \\begin{align*}\n    F(x)-F(x-\\mu s)\n    &\\ge -\\tfrac{\\gamma\\mu}{2}\\abs{\\nabla F(x)}\n      + \\mu DF(x)s\\\\\n    &\\ge -\\tfrac{\\gamma\\mu}{2}\\abs{\\nabla F(x)}\n      + \\mu\\gamma\\abs{\\nabla F(x)}\\\\\n    &= \\tfrac{\\gamma\\mu}{2}\\abs{\\nabla F(x)}.\n  \\end{align*}\n\\end{proof}\n\n\\section{Practical considerations}\n\n\\begin{intro}\n  Quadratic convergence is an asymptotic statement, which for any\n  practical purpose can be replaced by ``fast'' convergence. Most of\n  the effort spent in a single Newton step consists of setting up the\n  Jacobian $J$ and solving the linear system in the second line\n  of~\\eqref{eq:newton-def:1}. Therefore, we will consider techniques\n  here, which avoid some of this work. We will have to consider two\n  cases\n  \\begin{enumerate}\n  \\item Small systems with $d\\lesssim 1000$. For such systems, a\n    direct method like $LU$- or $QR$-decomposition is advisable in\n    order to solve the linear system. To this end, we compute the\n    whole Jacobian and compute its decomposition, an effort of order\n    $d^3$ operations. Comparing to $d^2$ operations for applying the\n    inverse and order $d$ for all other tasks, this must be avoided as\n    much as possible.\n  \\item Large systems, where the Jacobian is typically sparse (most of\n    its entries are zero). For such a system, the effort of order\n    $d^2$ for a full matrix vector multiplication is already not\n    affordable. Therefore, the linear problem is solved by an\n    iterative method and we will not have to compute the Jacobian at\n    all.\n  \\end{enumerate}\n\\end{intro}\n\n\\begin{remark}\n  In order to save numerical effort constructing and inverting\n  Jacobians, the following strategies have been successful.\n  \\begin{itemize}\n  \\item Fix a threshold $0<\\eta<1$ which will be used as a bound for\n    error reduction. In each Newton step, first compute the update\n    vector $\\widehat d$ using the Jacobian $\\widehat J$ of the\n    previous step. This yields the modified method\n    \\begin{gather}\n      \\label{eq:newton:1}\n      \\begin{alignedat}2\n        &&J_k &= J_{k-1} \\\\\n        &&\\widehat x &= x^{(k)} - J_{k}^{-1}f(x^{(k)})\\\\\n        \\text{If }\\abs{f(\\widehat x)} &\\le \\eta\n          \\abs{f(x^{(k)})} \\quad& x^{(k+1)} &= \\widehat x\\\\\n          \\text{Else } J_k &= \\bigl(\\nabla f(x^{(k)}\\bigr)^{-1}\n          \\quad & x^{(k+1)} &=x^{(k)}- J_{k}^{-1}f(x^{(k)}). \n      \\end{alignedat}\n    \\end{gather}\n    Thus, an old Jacobian and its inverse are used until convergence\n    rates deteriorate. This method is again a quasi-Newton method\n    which will not converge quadratically. However, we can obtain linear\n    convergence at any rate $\\eta$.\n  \\item If Newton's method is used within a time stepping scheme, the\n    Jacobian of the last Newton step in the previous time step is\n    often a good approximation for the Jacobian of the first Newton\n    step in the new time step. This holds in particular for small time\n    steps and constant extrapolation. Therefore, the previous method\n    should also be extended over the bounds of time steps.\n  \\item An improvement of the method above can be achieved by so\n    called rank-1 updates. Given $x^{(k)}$ and $x^{(k-1)}$, compute\n    \\begin{gather}\n      \\label{eq:newton:2}\n      \\begin{split}\n        p &= x^{(k)} - x^{(k-1)}\\\\\n        q &= f(x^{(k)}) - f(x^{(k-1)})\\\\\n        J_k &= J_{k-1} + \\frac1{\\abs{p}^2}\n        \\left(q - J_{k-1} p\\right)p^T\n      \\end{split}\n    \\end{gather}\n    The fact that the rank of $J_k - J_{k-1}$ is at most one can be\n    used to obtain a decomposition of $J_k$ in a cheap way from one\n    for $J_{k-1}$.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{remark}\n  For problems leading to large, sparse Jacobians, typically space\n  discretizations of partial differential equations, computing\n  inverses of $LU$-decompositions is infeasible. These matrices\n  typically only feature a few nonzero elements per row, while the\n  inverse and the $LU$-decomposition is fully populated, thus\n  increasing the amount of memory from $d$ to $d^2$.\n\n  Linear systems like this are often solved by iterative methods,\n  leading for instance to so called Newton-Krylov methods. Iterative\n  methods approximate the solution of a linear system\n  \\begin{gather*}\n    J d = f\n  \\end{gather*}\n  only using multiplications of a vector with the matrix $J$. On\n  the other hand, for any vector $v\\in \\R^d$, the term $Jv$ denotes\n  the directional derivative of $f$ in direction $J$. Thus, it can be\n  approximated easily by\n  \\begin{gather*}\n    J v \\approx \\frac{f\\left(x^{(k)}+\\epsilon v\\right) -\n      f\\left(x^{(k)}\\right)}{\\epsilon}.\n  \\end{gather*}\n  The term $f\\left(x^{(k)}\\right)$ must be calculated anyway as it is\n  the current Newton residual. Thus, each step of the iterative linear\n  solver requires one evaluation of the nonlinear function, and no\n  derivatives are computed.\n\n  The efficiency of such a method depends on the number of linear\n  iteration steps which is determined by two factors: the gain in\n  accuracy and the contraction speed. It turns out that typically\n  gaining two digits in accuracy is sufficient to ensure fast\n  convergence of the Newton iteration. The contraction number is a\n  more difficult issue and typically requires preconditioning, which\n  is problem-dependent and as such must be discussed when needed.\n\\end{remark}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End:\n", "meta": {"hexsha": "88c84b4a08aafbb2d9043621627b73f2a87f1055", "size": 12534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/newton.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/newton.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/newton.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": 40.9607843137, "max_line_length": 94, "alphanum_fraction": 0.6876495931, "num_tokens": 3799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8918110389681662, "lm_q1q2_score": 0.649216541432157}}
{"text": "%This is my super simple Real Analysis Homework template\n\n\\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage[]{amsthm} %lets us use \\begin{proof}\n\\usepackage[]{amssymb} %gives us the character \\varnothing\n\\usepackage{amsmath}\n\n\\title{Debye length}\n\\author{John ``Jack'' Brooks}\n\\date\\today\n%This information doesn't actually show up on your document unless you use the maketitle command below\n\n\\begin{document}\n\t\n\t\n\\maketitle %This command prints the title based on information entered above\n\t\n\n\n\\section{Debye length derivation}\nThe Debye length is the scale length associated with plasma screening out external electric fields, $\\mathbf{E}$.  To show this, we start with Gauss's law and convert $\\mathbf{E}$ to potential, $\\phi$ with $\\mathbf{E} = - \\nabla \\phi$.  \n\n\\begin{equation}\n\\begin{split}\n\t%\\label{eq:asdf}\n\t\\nabla^2 \\phi &= \\frac{1}{\\epsilon_0}\\left( \\rho_{plasma} \\right) \\\\\n\t&= \\frac{1}{\\epsilon_0}\\left[ q n_0 \\, \\textrm{exp} \\left( \\frac{-q \\phi (r)}{k_b T} \\right)\\right] \n\\end{split}\n\\end{equation}\nwhere and the plasma charge is assuming a Boltzmann distribution.  \n\nIf we assume that $k_bT \\gg q\\phi$, then we can Taylor expand the exponential term to get\n\\begin{equation}\n\\begin{split}\n%\\label{eq:asdf}\n\\nabla^2 \\phi = \\frac{1}{\\epsilon_0}\\left[ q n_0 \\,  \\left(1- \\frac{q \\phi (r)}{k_b T} \\right)\\right]\n\\end{split}\n\\end{equation}\nAssuming that we have equal ion and electron charge density, $q_e n_{oe}$ cancels with $q_i n_{oi}$ leaving\n\\begin{equation}\n\\begin{split}\n%\\label{eq:asdf}\n\\nabla^2 \\phi = \\frac{1}{\\epsilon_0}\\left[ -   \\frac{q^2 n_0 \\phi (r)}{k_b T}  \\right].\n\\end{split}\n\\end{equation}\nThe solution to this is \n\\begin{equation}\n\\begin{split}\n\\phi &= \\phi_0 \\, \\textrm{exp} \\left( -r / \\left( \\frac{q^2n_0}{\\epsilon_0 k_b T} \\right)^{1/2} \\right) \\\\\n &= \\phi_0 \\, \\textrm{exp} \\left( -r /\\lambda_D^{1/2} \\right)\n\\end{split}\n\\end{equation}\nwhere the scale length, \n\\begin{equation}\n\\begin{split}\n \\lambda_D =  \\left( \\frac{q^2n_0}{\\epsilon_0 k_b T} \\right)^{1/2},\n\\end{split}\n\\end{equation}\nis called the Debye length.\n\n\\section{Debye length screening}\n\nIf we now include a test charge, $Q_{tc}$, to our Gauss's law equation,\n\\begin{equation}\n\\begin{split}\n%\\label{eq:asdf}\n\\nabla^2 \\phi &= \\frac{1}{\\epsilon_0}\\left( \\rho_{plasma} - \\rho_{tc}\\right) \\\\\n&= \\frac{1}{\\lambda_D^2}\\phi - \\frac{Q_{tc}}{\\epsilon_0}\\delta (r-r_0)\n\\end{split}\n\\end{equation}\nwe can now investigate how the plasma screens out this charge.\n\nTODO\n\n\\end{document}\n\n\n", "meta": {"hexsha": "41bf3135c19161cfaebdd836373abcceda5d08e5", "size": 2550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Plasma_physics/Debye_length/debye_length.tex", "max_stars_repo_name": "jwbrooks0/misc_derivations", "max_stars_repo_head_hexsha": "3f5b1bbf0dc07821de89619dd794166f5cc217f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Plasma_physics/Debye_length/debye_length.tex", "max_issues_repo_name": "jwbrooks0/misc_derivations", "max_issues_repo_head_hexsha": "3f5b1bbf0dc07821de89619dd794166f5cc217f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Plasma_physics/Debye_length/debye_length.tex", "max_forks_repo_name": "jwbrooks0/misc_derivations", "max_forks_repo_head_hexsha": "3f5b1bbf0dc07821de89619dd794166f5cc217f2", "max_forks_repo_licenses": ["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.4814814815, "max_line_length": 237, "alphanum_fraction": 0.6984313725, "num_tokens": 892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6490432314420403}}
{"text": "\\documentclass{article}\n\n\\begin{document}\n\nAuthor: Carl Cortright\n\n\\section{Problem 10.1}\n\nTraining Data:\\\\\n\n\\begin{tabular}{c|cccc}\n\n  Class & CornFlakes & Frosties & Sugar Puffs & Branflakes \\\\\n  \\hline\n  Greater than 60 & 1 & 0 & 0 & 0\\\\\n  Greater than 60 & 1 & 0 & 0 & 1\\\\\n  Greater than 60 & 1 & 1 & 1 & 1\\\\\n  Greater than 60 & 0 & 0 & 0 & 1\\\\\n  Less than 60 & 0 & 1 & 1 & 0\\\\\n  Less than 60 & 1 & 1 & 1 & 0\\\\\n  \n\n\\end{tabular}\n\n\\subsection{(a)}\n\n$P(Less than 60 | <0,1,1,0>) = \\frac{P(Less than 60) * P(<0,1,1,0>|Less than 60)}{P(<0,1,1,0>)} = \\frac{\\frac{1}{3} * \\frac{1}{2}}{\\frac{1}{6}} = 1$\n\n\\subsection{(b)}\n\n$P(age) = \\frac{ P(age) * P(<a,b,c,d> | age) }{ P(<a,b,c,d>) }$\n\n\\section{Problem 10.5}\n\n\\subsection{}\n\n$P(C=1) = \\sum_{i=0}^N P(X_i | C=1)$ \\\\\n\n\n$P(X_i = 1 | C = 1) = \\frac{P(C=1) * P(C=1 | X_i=1) }{P(X_i = 1}$ \\\\\n\n\n$P(X_i=1 | C = 0) =  \\frac{P(C=0) * P(C=0 | X_i=1) }{P(X_i = 1}$ \\\\\n\n\n\\subsection{}\n\nTo form the classifier, we must take the probability of an input vector $\\vec{x}$ and class $C$ and divide it by the probability of the input vector:\\\\\n\n$P(C|\\vec{x}) = \\frac{P(\\vec{x},C)}{P(\\vec{x})}$\n\n\\subsection{}\n\nIf the word viagra doesn't appear in the training set, then $P(Viagra | C) = 0$ meaning via Bayes rule $P(C | Viagra) = 0$ . Via intuition, we know this must not be true. To fix this, we need to use a technique called smoothing, which basically means adding some arbitrary value $z$ to all of our probabilities to insure that they are always non-zero.\n\n\\section{Dirichlet Distributions}\n\n\\subsection{(a)}\n\nOne situation might be where we want to model classes of classes. An example would be if we were to classify spam or not spam, and then classify the sender of that particular email.\n\n\\subsection{(b)}\n\nFrom Lowest to highest entopy:\\\\\n$Dir(2,2,2)$\\\\\n$Dir(1,1,1)$\\\\\n$Dir(0.1,0.1,0.1)$\\\\\n\n\\end{document}\n", "meta": {"hexsha": "10c33f5a3891aa8c19b445e257008a6ff22b07f1", "size": 1847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homeworks/week2/homework2.tex", "max_stars_repo_name": "ckcortright/CSCI4830MachineLearning", "max_stars_repo_head_hexsha": "5d1c6c7bfb05b54f7c000c940b1f6410054f10f0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homeworks/week2/homework2.tex", "max_issues_repo_name": "ckcortright/CSCI4830MachineLearning", "max_issues_repo_head_hexsha": "5d1c6c7bfb05b54f7c000c940b1f6410054f10f0", "max_issues_repo_licenses": ["MIT"], "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/week2/homework2.tex", "max_forks_repo_name": "ckcortright/CSCI4830MachineLearning", "max_forks_repo_head_hexsha": "5d1c6c7bfb05b54f7c000c940b1f6410054f10f0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-11-30T07:28:47.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-28T05:52:45.000Z", "avg_line_length": 26.3857142857, "max_line_length": 351, "alphanum_fraction": 0.6161342718, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146849, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6490432258025568}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{The Gauss relation for the curvature of a hypersurface}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,g,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices.\n\n   \\nabla_{#}::Derivative.\n\n   K_{a b}::Symmetric.\n   g^{a}_{b}::KroneckerDelta.\n\n   # Define the projection operator\n\n   hab:=h^{a}_{b} -> g^{a}_{b} - n^{a} n_{b}.\n\n   # 3-covariant derivative obtained by projection on 4-covariant derivative\n\n   vpq:=v_{p q} -> h^{a}_{p} h^{b}_{q} \\nabla_{b}{v_{a}}.\n\n   # Compute 3-curvature by commutation of covariant derivatives\n\n   vpqr:= h^{a}_{p} h^{b}_{q} h^{c}_{r} ( \\nabla_{c}{v_{a b}} - \\nabla_{b}{v_{a c}} ).\n\n   substitute (vpq,hab)\n   substitute (vpqr,vpq)\n\n   distribute   (vpqr)\n   product_rule (vpqr)\n   distribute   (vpqr)\n   eliminate_kronecker(vpqr)\n\n   # Standard substitutions\n\n   substitute (vpqr,$h^{a}_{b} n^{b} -> 0$)\n   substitute (vpqr,$h^{a}_{b} n_{a} -> 0$)\n   substitute (vpqr,$\\nabla_{a}{g^{b}_{c}} -> 0$)\n   substitute (vpqr,$n^{a} \\nabla_{b}{v_{a}} -> -v_{a} \\nabla_{b}{n^{a}}$)\n   substitute (vpqr,$v_{a} \\nabla_{b}{n^{a}} -> v_{p} h^{p}_{a}\\nabla_{b}{n^{a}}$)\n   substitute (vpqr,$h^{p}_{a} h^{q}_{b} \\nabla_{p}{n_{q}} -> K_{a b}$)\n   substitute (vpqr,$h^{p}_{a} h^{q}_{b} \\nabla_{p}{n^{b}} -> K_{a}^{q}$)\n\n   # Tidy up and display the results\n\n   {h^{a}_{b},\\nabla_{a}{v_{b}}}::SortOrder.\n\n   sort_product   (vpqr)\n   rename_dummies (vpqr)\n   canonicalise   (vpqr)\n   factor_out     (vpqr,$h^{a?}_{b?}$)\n   factor_out     (vpqr,$v_{a?}$)       # cdb(gauss,vpqr)\n\\end{cadabra}\n\n\\subsection*{The Gauss relation for the curvature of a hypersurface}\n\n\\begin{align*}\n   D_{r}(D_{q}v_p) - D_{q}(D_{r}v_p) = \\cdb{gauss}\n\\end{align*}\n\n\\vspace{15pt}\n\n\\begin{latex}\n   \\begin{align*}\n      D_{r}(D_{q}v_p) - D_{q}(D_{r}v_p) = \\cdb{gauss}\n   \\end{align*}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "4e60e88ff393e328417195f1cc152050f1666924", "size": 1856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/examples/example-06.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-06.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-06.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": 25.7777777778, "max_line_length": 86, "alphanum_fraction": 0.5899784483, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6490230515743588}}
{"text": "\n\n\n\\subsection{Analysis of the wave energy cascade}\n\n\\subsubsection{Formulation of the spectral energy budget for\nnon-quadratic energy}\n\nIn order to analyze the flux of energy, we derive the spectral energy\nbudget, i.e.\\ the governing equations for spectral KE and APE\nfunctions.\n%\nThis is not as straightforward as in incompressible turbulence since\nthe expression of the kinetic energy $E_K = \\JJ\\cdot\\uu/2$ is not\nquadratic.\n%\nIn order to define the spectral KE function, we use the relation\n\\begin{equation}\n\\meanx{ E_K } = \\sum_\\kk \\scalarprod{\\uu}{\\JJ}/2,\n\\end{equation}\nwhere\n\\begin{equation}\n\\scalarprod{\\baa}{\\bb} \\equiv \\Re\\{ \\hat \\baa(\\kk)^* \\cdot \\hat \\bb(\\kk) \\},\n\\end{equation}\nwhere $\\Re$ denotes the real part, $\\kk$ is the wave number and the\nhat denotes the Fourier transform.\n%\nThe spectral KE function can therefore be defined as\n\\begin{equation}\nE_K(\\kk) \\equiv \\scalarprod{\\uu}{\\JJ}/2, \n\\end{equation}\nsuch as $\\meanx{ E_K } = \\sum_\\kk E_K(\\kk)$.\n%\nSimilarly, the PE can be written as the sum over all wave numbers of\nthe spectral PE function $E_P(\\kk) = c^2 |\\hat h|^2/2 = c^2\n\\scalarprod{h}{h}/2$, where, by definition,\n\\begin{equation}\n\\scalarprod{a}{b} \\equiv \\Re\\{ \\hat a(\\kk)^* \\hat b(\\kk) \\}.\n\\end{equation}\n\n\nThe equation for the spectral KE and PE functions can be written as\n\\begin{eqnarray}\n\\p_t E_K(\\kk) &=& T_K(\\kk) + C_K(\\kk),\\\\\n\\p_t E_P(\\kk) &=& T_P(\\kk) - C_P(\\kk),\n\\end{eqnarray}\nwhere\n\\begin{equation}\nC_K(\\kk) \n= -\\scalarprod{\\uu}{\\bnabla E_P}/2 - c^2 \\scalarprod{\\JJ}{\\bnabla h}/2,\n\\end{equation}\n\\begin{equation}\nC_P(\\kk) = c^2 \\scalarprod{h}{hd} /2,\n\\end{equation}\n\\begin{equation}\nT_P(\\kk) = -c^2 \\scalarprod{h}{\\uu \\cdot \\bnabla h + hd/2}\n\\end{equation}\nand\n\\begin{equation}\nT_K(\\kk) \n= -\\scalarprod{\\uu}{\\uu \\cdot \\bnabla \\JJ}/2\n-\\scalarprod{\\JJ}{\\uu \\cdot \\bnabla \\uu}/2\n-\\scalarprod{\\uu}{d\\JJ}/2.\n\\end{equation}\nThe mean conversion from potential energy to kinetic energy can be\ncomputed from the two conversion spectral functions as $C = \\sum_\\kk\nC_K(\\kk) = \\sum_\\kk C_P(\\kk)$.\n\n\n\n\n\n\n\\subsubsection{Exact Kolmogorov law for irrotational flows}\n\n\n\nAs in incompressible homogeneous isotropic turbulence, an exact\nKolmogorov law for irrotational flows can be derived.\n%\nIt is convenient to start from the following form of the governing\nequations\n\\begin{eqnarray}\n\\p_t \\uu &=& -\\bnabla \\cdot (|\\uu|^2/2) - c^2 \\bnabla h  \n- \\zeta_a \\eez \\wedge \\uu, \\\\\n\\p_t \\JJ &=& -\\p_j (u_j \\JJ) - \\bnabla E_p,\\\\\n\\p_t h   &=& -\\bnabla \\cdot \\JJ.\n\\end{eqnarray}\nAssuming that the flow is irrotational and that there is no global\nrotation ($\\zeta_a=0$), it can be shown that\n\\begin{equation}\n\\p_t ( J_i' u_i ) = - \\p_i( J_i'|\\uu|^2/2) - \\p_i'(u_j J_j' u_i')\n-\\p_i (J_i' c^2 h)  - \\p_i' (u_i E_p')\n\\end{equation}\nand\n\\begin{equation}\n\\p_t ( h' h ) = - \\p_i( h'J_i ) - \\p_i'( hJ_i' ),\n\\end{equation}\nwhich gives\n\\begin{eqnarray}\n\\p_t ( \\JJ'\\cdot\\uu + \\JJ\\cdot\\uu' + 2c^2 h'h )\n&=& - \\p_i( J_i'|\\uu|^2/2) - \\p_i'( J_i|\\uu'|^2/2) %\\nonumber \\\\&& \n- \\p_i'(u_j J_j' u_i') - \\p_i(u_j' J_j u_i) \\nonumber\\\\\n&& -c^2\\p_i (J_i'h) - c^2\\p_i' (J_ih') %\\nonumber\\\\&& \n- \\p_i' (u_i E_p') - \\p_i (u_i' E_p) \\nonumber\\\\\n&& -2c^2\\p_i' (J_i'h) - 2c^2\\p_i (J_ih').\n\\end{eqnarray}\nWe then assume homogeneity and take the ensemble average denoted by\n$\\meane{}$.  The separation vector is noted $\\rr = \\xx' - \\xx$.  For\nevery function $g(\\xx, \\xx')$, we have $\\p_i' \\meane{g} =\n-\\p_i\\meane{g} = \\bnabla_{\\rr} \\meane{g}|_i$. We obtain\n\\begin{eqnarray}\n\\p_t \\meane{ \\JJ'\\cdot\\uu + \\JJ\\cdot\\uu' + 2c^2 h'h }\n&=& + \\bnabla_{\\rr}\\cdot\\meane{ \\JJ'|\\uu|^2/2 - \\JJ|\\uu'|^2/2 } \\nonumber\\\\\n&& - \\bnabla_{\\rr}\\cdot\\meane{ u_j J_j' \\uu' - u_j' J_j \\uu } \\nonumber\\\\\n&& - \\bnabla_{\\rr}\\cdot\\meane{ \\uu E_p'- \\uu' E_p } \\nonumber\\\\\n&& -c^2\\bnabla_{\\rr}\\cdot\\meane{ \\JJ'h - \\JJ h' }\n\\end{eqnarray}\n%\nWe then introduce the structure functions and the operator $\\delta$\nreturning the increment of a variable between two points separated by $\\rr$, \nfor example $\\delta h (\\xx, \\rr) = h(\\xx+\\rr)- h(\\xx)$.\n%\nUsing again homogeneity, we get\n\\begin{equation}\n\\meane{ (\\delta h)^2 \\delta\\uu } = \n-\\meane{ h'^2 \\uu } + \\meane{ h^2 \\uu' }\n+2\\meane{ hh' \\uu } - 2\\meane{ hh' \\uu' }\n\\end{equation}\nand \n\\begin{equation}\n\\meane{ |\\delta \\uu|^2 \\delta\\JJ } = \n\\meane{  |\\uu|^2 \\JJ' } - \\meane{ |\\uu'|^2\\JJ }\n+\\meane{ u_ju_j' \\JJ' } - \\meane{  u_ju_j' \\JJ },\n\\end{equation}\nwhich gives\n\\begin{equation}\n2\\p_t \\meane{ \\JJ'\\cdot\\uu + \\JJ\\cdot\\uu' + 2c^2 h'h }\n= \\bnabla_{\\rr} \\cdot ( \\meane{ |\\delta \\uu|^2 \\delta\\JJ } \n+ c^2\\meane{ (\\delta h)^2 \\delta\\uu } ).\n\\end{equation}\nUsing isotropy and integrating yield an exact Kolmogorov law for\none-layer shallow water irrotational turbulence\n\\begin{equation}\n\\meane{ |\\delta \\uu|^2 \\delta J_L } \n+ c^2\\meane{ (\\delta h)^2 \\delta u_L } = -4 \\varepsilon r, \\label{eq_Kolmo}\n\\end{equation}\nwhere $\\eps$ is the energy dissipation rate and $J_L \\equiv\n\\JJ\\cdot\\rr / |\\rr|$ and $u_L \\equiv \\uu\\cdot\\rr / |\\rr|$ are\nlongitudinal increments.\n\n\n\n\n\n\n\n\\subsection{Simple model for structure functions determined by a\nrandom set of shocks}\n\\label{subsection_shock_model}\n\n\n\\cite{BouchaudMezardParisi1995} and \\cite{Kuznetsov2004} showed that\nthe presence of discontinuities can strongly influence the statistics\nand in particular lead to very strong intermittency.\n%\nWe now present an extremely simple model based on the assumption that\nshocks totally dominate the flow.  The structure functions are\ncalculated by averaging increments over the total surface of the\ndomain $\\mA$.  Considering that the increments are produced only by\ndiscontinuity lines, we get\n\\begin{eqnarray}\n\\meane{|\\delta h|^p} \n&=& \\frac{1}{\\mA} \\int_{\\mA}  d^2\\xx |\\delta h(\\xx)|^p \\nonumber\\\\\n&\\simeq& \\frac{r}{\\mA} \\int_\\shocks ds |\\sin\\theta| |\\Delta h (s)|^p,\n\\end{eqnarray}\nwhere $\\theta$ is the angle between the shock line and the separation\nvector $\\rr$ %\nand $\\Delta h (s)$ is the step in $h$ at a shock.\n%\nAssuming isotropy, the integral can be split and we get\n\\begin{equation}\n\\meane{|\\delta h|^p} \n\\simeq \nr \\frac{L_s}{\\mA} \\meant{|\\sin\\theta|} \\means{|\\Delta h (s)|^p}\n=\nr \\frac{L_s}{\\mA} \\frac{2}{\\pi} \\means{|\\Delta h (s)|^p},\n\\end{equation}\nwhere $\\meant{}$ denotes the mean over $\\theta$, %\n$L_s$ is the total length of the shocks in the domain %\nand $\\means{}$ denotes the mean over all shocks.\n\nFor velocity increments, we can also use a characteristic of the\nvelocity singularities.  The step in velocity is only in the component\nperpendicular to the shocks, which implies that the longitudinal and\ntransverse increments are related by $\\delta u_L = \\delta u\n\\sin\\theta$, $\\delta u_T = \\delta u \\cos\\theta$.\n%\nApplying the same averaging method, we obtain\n\\begin{equation}\n\\meane{|\\delta u_L|^p} \n\\simeq \nr \\frac{L_s}{\\mA} \n\\meant{|\\sin\\theta|^{1+p}}\n\\means{|\\Delta u (s)|^p}\n\\end{equation}\nand\n\\begin{equation}\n\\meane{|\\delta u_T|^p} \n\\simeq \nr \\frac{L_s}{\\mA} \n\\meant{|\\sin\\theta||\\cos\\theta|^{p}}\n\\means{|\\Delta u (s)|^p},\n\\end{equation}\nwhere $\\Delta u (s)$ is the velocity step at a shock.\n%\nThese assumptions completely determine the ratio between the\nlongitudinal and transverse structure functions, which can be\nanalytically computed as\n\\begin{eqnarray}\nR_p(r) \\equiv \\frac{\\meane{|\\delta u_L|^p}}{\\meane{|\\delta u_T|^p}} = \n\\frac{\\meant{|\\sin\\theta|^{1+p}}}{\\meant{|\\sin\\theta||\\cos\\theta|^p}},\n\\end{eqnarray}\ngiving the numerical values $R_2 = 2$, $R_3 = 6\\pi/8$ and $R_4 = 8/3$.\n\n\nInterestingly, for an isotropic and purely divergent flow ($\\zeta =\n0$), the longitudinal and transverse second order structure functions\nare exactly related by $\\meane{(\\delta u_L)^2} = \\p_r( r\\meane{(\\delta\nu_T)^2} )$ \\cite[]{Lindborg2007jas}.\n%\nIf we further assume than both second order structure functions follow\nthe same scaling law $\\meane{ (\\delta u_L)^2} \\propto \\meane{ (\\delta\nu_T)^2} \\propto r^\\alpha$, then we have $\\meane{ (\\delta u_L)^2} =\n(1+\\alpha) \\meane{ (\\delta u_T)^2} $, which gives $ R_2 = 2\n\\Leftrightarrow \\alpha = 1$.\n\n\nThe shock model also provides predictions of the flatness factors of\nthe velocity increments\n\\begin{eqnarray}\nF_L &=&  \\frac{\\meane{|\\delta u_L|^4}}{\\meane{|\\delta u_L|^2}^2} \n= r^{-1} \\frac{\\means{|\\Delta u|^4}}{\\means{|\\Delta u|^2}^2} \n\\frac{\\meant{|\\sin\\theta|^5}}{\\meant{|\\sin\\theta|^3}^2},\\\\\nF_T &=&  \\frac{\\meane{|\\delta u_T|^4}}{\\meane{|\\delta u_T|^2}^2} \n= r^{-1} \\frac{\\means{|\\Delta u|^4}}{\\means{|\\Delta u|^2}^2} \n\\frac{\\meant{|\\sin\\theta||\\cos\\theta|^4}}{\\meant{|\\sin\\theta||\\cos\\theta|^2}^2},\n\\end{eqnarray}\nand on the ratio of the two flatness factors, which is simply equal to\n$F_T/F_L = 1.5$ according to the model.\n\n\n\n\n\n\n", "meta": {"hexsha": "bfbf5577527c0c3ca94ab5c3ea9d87f44d12b0e2", "size": 8583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Old/section_advanced_theory.tex", "max_stars_repo_name": "ashwinvis/augieretal_jfm_2019_shallow_water", "max_stars_repo_head_hexsha": "88d97c2bd5df0795ca636306c1d795ef1d3a8949", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-23T11:06:53.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-23T11:06:53.000Z", "max_issues_repo_path": "Old/section_advanced_theory.tex", "max_issues_repo_name": "ashwinvis/augieretal_jfm_2019_shallow_water", "max_issues_repo_head_hexsha": "88d97c2bd5df0795ca636306c1d795ef1d3a8949", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-08-23T13:00:31.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-23T13:00:31.000Z", "max_forks_repo_path": "Old/section_advanced_theory.tex", "max_forks_repo_name": "ashwinvis/augieretal_jfm_2019_shallow_water", "max_forks_repo_head_hexsha": "88d97c2bd5df0795ca636306c1d795ef1d3a8949", "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": 33.3968871595, "max_line_length": 80, "alphanum_fraction": 0.6705114762, "num_tokens": 3170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6490230471078178}}
{"text": "\\section{Hermitian Forms and Real Skew-Symmetric Forms}\r\n\\begin{definition}\r\n    A sesquilinear form $\\phi:V\\times V\\to\\mathbb C$  is called Hermitian if $\\phi(u,v)=\\overline{\\phi(v,u)}$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    In particular, $\\phi(u,u)=\\overline{\\phi(u,u)}$, so $\\phi(u,u)$ is real.\r\n    Moreover, for any $\\lambda\\in\\mathbb C$ we have $\\phi(\\lambda u,\\lambda u)=|\\lambda|^2\\phi(u,u)$.\r\n    Therefore it makes sense to talk about positive/definite (semi)definite Hermitian forms.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    A sesquilinear form $\\phi:V\\times V\\to\\mathbb C$ is Hermitian iff for any basis $B$ of $V$, $[\\phi]_B=\\overline{[\\phi]}_B^\\top$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $\\phi$ is Hermitian, then write $A=[\\phi]_B=(a_{ij})_{i,j}=(\\phi(e_i,e_j))_{i,j}$ where we have $a_{ji}=\\phi(e_j,e_i)=\\overline{\\phi(e_i,e_j)}=\\bar{a}_{ij}$.\r\n    Conversely if $[\\phi]_B=A$ with $A=(a_{ij})_{ij}=\\bar{A}^\\top$ and $u=\\sum_i\\lambda_ie_i,v=\\sum_i\\mu_ie_i$, then\r\n    \\begin{align*}\r\n        \\phi(u,v)&=\\phi\\left( \\sum_{i=1}^n\\lambda_ie_i,\\sum_{j=1}^n\\mu_je_j \\right)=\\sum_{i=1}^n\\sum_{j=1}^n\\lambda_i\\bar\\mu_ja_{ij}\\\\\r\n        &=\\overline{\\sum_{i=1}^n\\sum_{j=1}^n\\bar\\lambda_i\\mu_ja_{ji}}\\\\\r\n        &=\\overline{\\phi\\left( \\sum_{j=1}^n\\mu_je_j,\\sum_{i=1}^n\\lambda_ie_i \\right)}\\\\\r\n        &=\\overline{\\phi(v,u)}\r\n    \\end{align*}\r\n    So $\\phi$ is Hermitian.\r\n\\end{proof}\r\nThe polarisation identity becomes\r\n$$\\phi(u,v)=\\frac{1}{4}(Q(u+v)-Q(u-v)+iQ(u+iv)-iQ(u-iv))$$\r\nfor a Hermitian $\\phi$ and $Q(w)=\\phi(w,w)$.\r\n\\begin{theorem}[Hermitian Formulation of Sylvester's Law]\r\n    Let $V$ be an $n$-dimensional vector space over $\\mathbb C$ and $\\phi:V\\times V\\to\\mathbb C$ a Hermitian form on $V$, then $V$ has a basis $\\{v_1,\\ldots,v_n\\}$ such that\r\n    $$[\\phi]_B=\\begin{pmatrix}\r\n        I_p&&\\\\\r\n        &-I_q&\\\\\r\n        &&0\r\n    \\end{pmatrix}$$\r\n    where $p,q$ depends only on $\\phi$.\r\n\\end{theorem}\r\nThe proof is nearly identical to the real symmetric case.\r\n\\begin{proof}\r\n    If $\\phi=0$ then we are done.\r\n    Otherwise, by the polarisation identity, there exists $e_1\\neq 0$ such that $\\phi(e_1,e_1)\\neq 0$.\r\n    Set $v_1=e_1/\\sqrt{|\\phi(e_1,e_1)|}$, then we get $\\phi(v_1,v_1)=\\pm 1$.\r\n    Consider $W=\\{w\\in V:\\phi(v,w)=0\\}$, then easily $V=\\langle\\{v_1\\}\\rangle\\oplus W$.\r\n    Then we can do induction on the dimension to show that $\\phi$ is diagonal in some basis, which implies the existence of $p,q$.\r\n    The uniqueness follows from the observation that $p$ (resp. $q$) is the minimal dimension of a subspace on which $\\phi$ is positive (resp. negative) definite.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $V$ be a vector space over $\\mathbb R$.\r\n    A bilinear form on a real vector space is skew-symmetric if $\\phi(u,v)=-\\phi(v,u)$ for all $u,v\\in V$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. For any $u\\in V$, $\\phi(u,u)=-\\phi(u,u)$ therefore $\\phi(u,u)=0$.\\\\\r\n    2. The definition is equivalent to say that for any basis $B$ of $V$ we have $[\\phi]_B=-[\\phi]_B^\\top$.\\\\\r\n    3. For any $A\\in M_n(\\mathbb R)$, we can decompose it\r\n    $$A=\\frac{A+A^\\top}{2}+\\frac{A-A^\\top}{2}$$\r\n    into symmetric and skew-symmetric parts.\r\n\\end{remark}\r\n\\begin{theorem}[Sylvester Form]\r\n    Let $\\phi$ be a skew-symmetric bilinear form over a real vector space $V$ with $\\dim V=n<\\infty$, then there is a basis $B=\\{v_1,w_1,\\ldots,v_m,w_m,v_{2m+1},\\ldots,v_n\\}$ of $V$ such that\r\n    $$[\\phi]_B=\\begin{pmatrix}\r\n        A&&&\\\\\r\n        &\\ddots&&\\\\\r\n        &&A&\\\\\r\n        &&&0\r\n    \\end{pmatrix},A=\\begin{pmatrix}\r\n        0&1\\\\\r\n        -1&0 \r\n    \\end{pmatrix}$$\r\n    where there are $m$ copies of $A$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Induction on $n$.\r\n    If $\\phi=0$, then we are done.\r\n    Otherwise $\\phi\\neq 0$, so there is some $v_1,w_1$ such that $\\phi(v_1,w_1)\\neq 0$.\r\n    After rescaling we might as well assume that $\\phi(v_1,w_1)=1$, so correspondingly $\\phi(w_1,v_1)=-1$.\r\n    We know that $v_1,w_1$ has to be linearly independent as $\\phi$ is skew-symmetric.\r\n    Let $U=\\langle\\{v_1,v_2\\}\\rangle$ and $W=\\{v\\in V:\\phi(v_1,v)=\\phi(w_1,v)=0\\}$, then $V=U\\oplus W$.\r\n    We are then done since we can use induction hypothesis on $W$ and $[\\phi|_U]=A$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Skew-symmetric bilinear forms have even rank.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $V$ be a vector space over $\\mathbb R$ (resp. $\\mathbb C$).\r\n    An inner product on $V$ is a positive definite symmetric (resp. Hermitian) form $\\phi$ on $V$.\r\n    The pair $(V,\\phi)$ is then called a real (resp. complex) inner product space.\r\n\\end{definition}\r\nSometimes we write $\\langle u,v\\rangle=\\phi(u,v)$ if it is understood.\r\n\\begin{example}\r\n    In $\\mathbb R^n$, the usual real scalar product is an inner product.\\\\\r\n    In $\\mathbb C^n$, the usual complex scalar product is an inner product.\\\\\r\n    In $C([0,1],\\mathbb C)$ (over $\\mathbb C$), the form\r\n    $$\\langle f,g\\rangle=\\int_0^1f(t)\\overline{g(t)}w(t)\\,\\mathrm dt$$\r\n    is an inner product for any $w\\in C([0,1],\\mathbb R_+)$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $\\langle\\cdot,\\cdot\\rangle$ be an inner product, its induced norm is $\\|v\\|=\\sqrt{\\langle v,v\\rangle}$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    $\\|v\\|\\ge 0$ and the equality holds iff $v=0$.\r\n\\end{remark}", "meta": {"hexsha": "d262bcbc05675920a534428b018f043e0f8c9bdc", "size": 5305, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "20/hermi.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": "20/hermi.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": "20/hermi.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": 52.0098039216, "max_line_length": 192, "alphanum_fraction": 0.6231856739, "num_tokens": 1912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.6490230394965891}}
{"text": "\\input{../header.tex}\n\\title{\\vspace{-2cm}INF3490/INF4490 Exercise Solutions - Neural Networks}\n\\author{Eivind Samuelsen\\input{../author_footnote.tex}}\n\\date{}\n\n% Removing paragraph indents is sometimes useful:\n\\setlength\\parindent{0pt}\n% ==============================================================================\n\n% ================================= DOCUMENT ===================================\n\\begin{document}\n    \\renewcommand\\marginsymbol[1][0pt]{%\n  \\tabto*{0cm}\\makebox[-1cm][c]{$\\mathbb{P}$}\\tabto*{\\TabPrevPos}}\n\n\\maketitle\n\\input{../intro.tex}\n\n\\section{Single Layer Perceptron}\n\\subsection{}\nIn the perceptron below, what will the output be when the input is (0, 0)?\nWhat about inputs (0, 1), (1, 1) and (1, 0)?\nWhat if we change the bias weight to -0.5?\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.3\\textwidth]{fig1.png}\n\\caption{Single Layer Perceptron. b = 1 }\n\\label{fig:slp}\n\\end{center}\n\\end{figure}\n\n\\noindent\\textit{Answer:}\n\n\\noindent\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|}\n\\hline\n\\multicolumn{3}{|c|}{Bias $=-1.5$} & \\multicolumn{3}{c|}{Bias $=-0.5$}\\tabularnewline\n\\hline\nInput & Weighted sum & Output & Input & Weighted sum & Output\\tabularnewline\n\\hline\n\\hline\n$\\left(0,0\\right)$ & $-1.5$ & $0$ & $\\left(0,0\\right)$ & $-0.5$ & $0$\\tabularnewline\n\\hline\n$\\left(0,1\\right)$ & $-0.5$ & $0$ & $\\left(0,1\\right)$ & $0.5$ & $1$\\tabularnewline\n\\hline\n$\\left(1,0\\right)$ & $-0.5$ & $0$ & $\\left(1,0\\right)$ & $0.5$ & $1$\\tabularnewline\n\\hline\n$\\left(1,1\\right)$ & $0.5$ & $1$ & $\\left(1,1\\right)$ & $1.5$ & $1$\\tabularnewline\n\\hline\n\\end{tabular}\n\\par\\end{center}\n\n\\subsection{}\nStarting with random weights, how do you proceed in order to train the perceptron above to perform any given binary operation?\\\\\n\n\\noindent\\textit{Answer:}\n\n\\noindent\nSee the source code for the next task.\n\n\\subsection{Implement a perceptron \\marginsymbol}\nImplement the perceptron, and train it to perform the logical functions NOT (use only one of the inputs), NAND, and NOR.\nWhat happens when you try to train it do the XOR function?\\\\\n\n\\textit{Source code:}\n\\inputminted{Python}{bool_perceptron.py}\nThe source code is available online on GitHub:\\\\\n\\href{https://github.com/olehermanse/INF3490-AI_Machine_Learning/tree/master/material/week5}{\\textbf{github.com/olehermanse/INF3490-AI\\_Machine\\_Learning/tree/master/material/week5}}\n\n\\section{Multi Layer Perceptron (MLP)}\nThe figure below shows a multilayer perceptron that constructs the XOR function.\nHow would you rewrite it to construct the binary equivalence function\n(i.e. the output is above threshold when both inputs are either 0 or 1)?\nCan you construct it so that it will detect equivalence for any combination of integer inputs?\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{fig2.png}\n\\caption{An illustrated example of a multi layer perceptron}\n\\label{fig:mlp}\n\\end{center}\n\\end{figure}\n\n\\noindent\\textit{Answer:}\n\n\\noindent\nIf we just want it to work in the binary case, we can simply switch\nsigns on all the output weights to create the opposite function:\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{opposite.png}\n\\end{center}\n\\end{figure}\n\nIf we want it to work for all integers, we have to change the weights\nin the first layer. First, note that the output layer encodes the\nfunction $h_{2}-h_{1}-0.5>0$ which is equivalent to $h_{2}\\land\\lnot h_{1}$\nsince $h_{1}$ and $h_{2}$ are either 0 or 1. If we equate true with\n1 and false with 0 we can write $\\mbox{\\ensuremath{h_{1}}:\\,\\ \\ensuremath{i_{1}}+\\ensuremath{i_{2}}-1.5>0}$\nand $\\mbox{\\ensuremath{h_{2}}:\\,\\ \\ensuremath{i_{1}}+\\ensuremath{i_{2}}-0.5>0}$,\nso the output is\n\n\\[\no:\\, i_{1}+i_{2}>0.5\\ \\land\\ i_{1}+i_{2}\\leq1.5\\quad\\Leftrightarrow\\quad o:\\,0.5<i_{1}+i_{2}\\leq1.5\n\\]\n Limiting $i_{1}$ and $i_{2}$ to integers gives us $o:\\, i_{1}+i_{2}=1$.\nSo the output is 1 if and only if the sum of the inputs are 1. We\ncan get the equivalence function by changing this to $o:\\, i_{1}-i_{2}=0$.\nGoing back a step or two we see that we can achieve this by making\nthe output\n\\[\no:\\, i_{1}-i_{2}>-0.5\\ \\land\\ i_{1}-i_{2}\\leq0.5\n\\]\n or something similar. This has the same logical form that we already\nhave, so we don't need to change the weights of the output layer,\nbut only those of the hidden layer.\n\nTracing back, we see that we would need $h_{1}:\\, i_{1}-i_{2}-0.5>0$\nand $h_{2}:\\, i_{1}-i_{2}+0.5>0$ as the hidden layer outputs. This\nimplies the following weights:\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{all_integers.png}\n\\end{center}\n\\end{figure}\n\n\\input{../contact.tex}\n\\end{document}\n% ==============================================================================\n", "meta": {"hexsha": "baaf1ebd11884b529d2a3cebb64914d7c1f887db", "size": 4699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "material/week5/inf3490-sol5.tex", "max_stars_repo_name": "mpambasange/MachineLearning", "max_stars_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-09-01T08:50:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T20:56:07.000Z", "max_issues_repo_path": "material/week5/inf3490-sol5.tex", "max_issues_repo_name": "olehermanse/INF3490-PythonAI", "max_issues_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-10-20T09:36:19.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-29T00:28:54.000Z", "max_forks_repo_path": "material/week5/inf3490-sol5.tex", "max_forks_repo_name": "olehermanse/INF3490-PythonAI", "max_forks_repo_head_hexsha": "8b813345264513a57934317b01e1311628dc5b01", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2016-10-31T12:30:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-15T12:12:50.000Z", "avg_line_length": 35.5984848485, "max_line_length": 182, "alphanum_fraction": 0.6763141094, "num_tokens": 1547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6490184247561361}}
{"text": "\\section{Stationarity}\nBroadly speaking, a time series is said to be {\\sl stationary} if\nthere is no systematic trend, no systematic change in variance,\nand if strictly\nperiodic variations or seasonality do not exist. Most processes in\nnature appear to be non-stationary. Yet much of the theory in\ntime-series literature is only applicable to stationary processes.\n\nOne way of describing a stochastic process is to specify the joint\ndistribution of the observations $Y(t_1), \\dots, Y(t_n)$ for any\nset of times $t_1, \\dots, t_n$ and any value of $n$. A time series\nis said to be strictly stationary if the joint distribution of\n$Y(t_1), \\dots, Y(t_n)$ is the same as that of $Y(t_1 + h), \\dots\nY(t_n + h)$ for all $t_1, \\dots, t_n$ and $h$. To see how this is\na useful assumption, notice that the above condition implies that\nthe expected value and covariance structure of any two components,\n$Y_a(t)$ and $Y_b(t)$, of a time series are\nconstant in time\n\\begin{equation}\n\\label{sos}\n\\E \\{Y_a(t)\\} = \\mu_a \\, , \\, \\var \\{Y_a(t)\\} = \\sigma_a^2 \\mbox{ and }\n\\mbox{corr}\\{ Y_a(t), Y_b(t+h) \\} = \\gamma_{ab}(h).\n\\end{equation}\nThe function\n$\\gamma_{ab}(h)$ is called the cross-correlation function if $a\\neq b$\nand the auto-correlation function if $a=b$. \n\nIn practice it is often useful to define stationarity in a less\nrestricted way than that described above. In many cases,\nthe statistical structure of the processes can be\ncompletely described with the second-order properties of equation\n(\\ref{sos}). We can estimate the\nquantities in (\\ref{sos}) using\nstandard statistical procedures,\nfor example we may estimate the cross-correlation at {\\it lag}\n$h$, $\\gamma_{a,b}(h)$ with the sample correlation of\n$Y_a(1),\\dots,Y_a(T-h)$ and $Y_b(h+1),\\dots,Y_b(T)$. \n\n\n\n\\subsection{An example: Fetal Monitoring}\n\nMeasurements of fetal heart rate (FHR) and fetal movement (FM) are\ngenerated by maternal-fetal monitoring.    \nApproximately 5 measurements per second are taken during 50 minutes on\n120 subjects that are monitored at 20,24,28,32,36,\nand 38-39 weeks of \ngestation. Both FHR and FM are recorded giving us a multiple time \nseries $Y(t), t=1,\\dots,50\\times 60\\times 5$, where $Y(t)$ is a vector\nwith 2 entries. \n\nThe association between accelerations of FHR and    \nFM has been documented since the 1930s. For\nexample, it has been observed \nthat in the third trimester most large fetal heart\naccelerations are \nassociated with fetal activity.\nIn Section 4.2 we will describe how relatively straight-forward time\nseries techniques provide a visual descriptions of how these\nassociations vary with weeks gestation. These description have\nmotivated a methodology that will provide us is with a more rigorous\nassessment of this relationship.\n\nIf we consider the FM and FHR  measurements, seen in Figure 5, as\noutcomes from a two component time series, we may consider the\ncross-correlation function of these two components as a description of\nthe association between these two processes. Notice that the\nmeasurements taken for each \nfetus at each gestation week has a cross-correlation function associated\nwith them. In Figure 6, as a descriptive plot, we show the average,\nover individuals,\nof these functions for each gestation\nweek. Notice that a peak at around the $-6$ second lag starts to\nappear in the plot for the 24 week gestation. As the fetus gets older,\nthis peak grows and becomes more defined. This result\ncan be \nconsidered a first step in the characterization of the relationship\nbetween FM and FHR. \n\n\\centerline{\\epsfig{figure=Plots/plot-10-02.ps,width=\\textwidth}}\n\\centerline{\\epsfig{figure=Plots/plot-10-03.ps,width=\\textwidth}}\n", "meta": {"hexsha": "16f2d0edd98b8e6082edb3e0352e299218394b6a", "size": 3646, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-10-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-10-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-10-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": 44.4634146341, "max_line_length": 72, "alphanum_fraction": 0.7660449808, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6490184154277786}}
{"text": "\\section{Notation}\n\nIn addition to the notation in the Shelley spec, we use the following notations:\n\n\\begin{description}\n\\item[Functions with finite support] For a monoid $M$, $A \\to_0 M$\n  are the functions $f : A \\to M$ with finite support, i.e. such that\n  there exist only finitely many $a \\in A$ such that $f a \\neq 0$. We\n  denote the support of $f$ by $\\supp f$, which is defined as\n  $\\supp f := \\{ a \\in A : f a \\neq 0 \\}$.\n\\end{description}\n", "meta": {"hexsha": "6eea42e40dd3ae4ff79f0794364cd5ec542cfa50", "size": 452, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shelley-ma/formal-spec/notation.tex", "max_stars_repo_name": "ilap/cardano-ledger-specs", "max_stars_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-30T14:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-30T14:19:54.000Z", "max_issues_repo_path": "shelley-ma/formal-spec/notation.tex", "max_issues_repo_name": "ilap/cardano-ledger-specs", "max_issues_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "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": "shelley-ma/formal-spec/notation.tex", "max_forks_repo_name": "ilap/cardano-ledger-specs", "max_forks_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "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.6666666667, "max_line_length": 80, "alphanum_fraction": 0.6792035398, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.648990513390464}}
{"text": "\n\\begin{figure*}[!ht]\n\\includegraphics[width=\\textwidth]{figs/waterfall} \n\\caption{A waterfall plot of the \\texttt{cartoon-spring.wav} from 0-200 ms between frequencies of 20-8000 Hz, where the height indicates the amplitude of each frequency. This plot was created with the REW tool~\\cite{REWTool}.}\n\\label{fig:waterfall}\n\\end{figure*}\n\n\\section{Aural Distance}\n\\label{sec:distance}\n\nAs a distance metric, we used as a starting point the literature on acoustic fingerprinting~\\cite{fingerprinting}.\nAcoustic fingerprinting is the concept of creating a condensed, distinct summary of an audio file that can be used later to identify that audio file or to look it up in a database.\nAcoustic fingerprints turn an audio file into a represent of how the file will sound to the human ear regardless of how it is represented in a digital format~\\cite{fingerprinting}.\nThere are numerous ways to develop acoustic fingerprints and companies like Shazam and Sound-Hound have developed complex algorithms to create accurate fingerprints even from low quality files recorded on a cellphone mic.\nFor this work, we used the work of Shazam~\\cite{wang2003industrial} as an inspiration for our distance metric calculation.\n\n\nAs an intuition, the psycho-acoustic identity of a sound file (how humans distinguish between one sound and the next) can be captured by taking every ``moment'' of audio, and listing the predominate frequencies for that slice of time.\nThis intuition can be represented with a waterfall plot, as shown in Figure~\\ref{fig:waterfall}, which plots how the frequencies change over time.\nA waterfall plot uses the Fast Fourier Transform (FFT) to calculate many discrete Fourier transforms over small times slices.\nIn this way, a waterfall plot is a representation of an audio file as a list of spectrograms plotted over time.\nIn the Shazam method, the peaks are selected from each time slice of audio and used to create a ``constellation'' of peaks over time. \nThis constellation is then used to build a hash that acts as a fingerprint to uniquely identify the audio sample.\nWe use a similar strategy by first performing a real Fast Fourier Transform on the audio file and then picking out the frequency peaks in each time frame.\nHowever, the key difference in DSP-PBE is that we do not use the constellation as a hash for lookup in a database (as Shazam and SoundHound do), but instead, we need a distance metric between two constellations to provide a measure of how close we are to synthesizing the correct DSP filter.\nDistance metrics are common in music synthesis tasks, for example, in the generation of jazz improvisations, where the improvisation should stay close by some measure to the original melody~\\cite{donze2014machine}.\n\nFast Fourier Transforms (FFT) are the key to a good acoustic fingerprint.\nThe FFT, however, cannot be taken as a blackbox in our application.\nThe two factors we need to consider are 1) the window-size for how many samples will be used to calculate the FFT, and 2) the bin size which roughly speaking, defines the resolution of the FFT.\n\nEach return element is a frequency \\textit{bin}, and depending on the scale of your return array the size of these bins varies.\nIn order for each bin to correspond to 1 Hz the size of the return vector must be equal to the sampling frequency (44,100 Hz).\nIf each bin is not 1 Hz, the effects of spectral leakage will be seen.\nThis occurs when the bins do not correspond to the exact frequency peaks of the sound.\nThe amplitude from the peaks that fall in between bins will \\textit{leak} over into the closest bin and create a distorted spectrogram.\nFor this reason we had to adjust the size of the FFT return arrays to be 44,100, as 44,100 Hz is a common format for audio.\nAlthough this slows down the process of FFT, it provides the most accurate representation of the sound and for our purposes frequency accuracy is paramount.\n\nWith our constellations created from the waterfall plot, we constructed a \\texttt{dist} function that measures the aural distance and is faithful to the psycho-acoustics of the human ear.\nOur implementation takes the Euclidean distance of the peaks in a time slice on the frequency-amplitude axis.\nIn order to define this distance more formally, we introduce the notation $c@t$ to indicate selecting time slice $t$ from constellation $c$.\nWe also use the function $peak:: Int \\to Constellation \\to Peak$ to select a peak from a constellation, where the peaks are in sorted order based on frequency.\nThen, for an audio clip $x$ and an audio clip $y$, and a function $toC :: Audio \\to Constellation$ to transform the audio clip into a constellation with $ts$ time slices and $p$ peaks in each time slice:\n%\n\\begin{align*}\n\\sum_{t=0}^{ts}\\ \\sum_{i=0}^{p} euclid\\Big(\\ &peak(i,toC(x)@t), \\\\ &peak(i,toC(y)@t)\\ \\Big)\n\\end{align*}\n%\nNote that this definition requires the audio clips to be temporally aligned, which is not always a fair assumption in the real world. We leave the exploration of a temporal offset between two example audio samples to future work.\n\nAs a sanity check that this distance metric matches the psycho-acoustic definition of distance, we used the test cases listed in Table~\\ref{table:dist}.\n\n\\begin{table*}[!h]\n\\centering\n\\caption{Test cases to evaluate distance metric. The exact values are only important in relationship to the others.}\n\\begin{tabular}{|l | c | c|} \n \\hline\n Test Name \\& Expected Result & Value 1 & Value 2 \\\\\n \\hline\n \\hline\n Identity & \\multirow{2}{*}{(PianoC, PianoC) = 0} & \\multirow{2}{*}{NA}\\\\ \n   \\quad Value 1 = 0 &  & \\\\\n \\hline\n Commutativity & \\multirow{2}{*}{(PianoC, PianoCSharp) = 5.635} & \\multirow{2}{*}{(PianoCSharp, PianoC) = 5.635} \\\\\n   \\quad Value 1 = Value 2  & & \\\\\n \\hline\n Commutativity & \\multirow{2}{*}{(PianoC, HornCSharp) = 20.500} & \\multirow{2}{*}{(HornCSharp, PianoC) = 20.500} \\\\\n   \\quad  Value 1 = Value 2 & & \\\\\n \\hline\n Filter less than pitch & \\multirow{2}{*}{(PianoC, PianoFilterC) = 3.749} & \\multirow{2}{*}{(PianoC, PianoCSharp) = 5.635} \\\\ \n   \\quad Value 1 $<$ Value 2 & & \\\\\n \\hline\n Filter less than pitch+instrument & \\multirow{2}{*}{(PianoC, PianoFilterC) = 3.749} & \\multirow{2}{*}{(PianoC, HornCSharp) = 20.500} \\\\\n   \\quad Value 1 $<$ Value 2 & & \\\\\n \\hline\n Pitch less than pitch+instrument & \\multirow{2}{*}{(PianoC, PianoCSharp) = 5.635} & \\multirow{2}{*}{(PianoC, HornCSharp) = 20.500} \\\\\n   \\quad Value 1 $<$ Value 2 & & \\\\\n \\hline\n\\end{tabular}\n\\label{table:dist}\n\\end{table*}\n\n\nThe goal in the synthesis procedure is to find a DSP filter program, $F$, such that \\texttt{dist$(O, F(I))$ = 0}.\nHowever, in practice the DSP-PBE Synthesizer can only get us so close to this metric and we instead just minimize this distance.\nTo do this, the user specifies a default threshold distance for the aural distance.\nThe threshold distance defines how close is acceptably close, and can be changed by the user depending on their needs or requirements.\n\n", "meta": {"hexsha": "9407f978d041792095b648da1e930e3fc924e9bb", "size": 6947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/FARM-18/secs/distance.tex", "max_stars_repo_name": "Yale-OMI/DSP-PBE", "max_stars_repo_head_hexsha": "073f366e8096004adeec5d2cde1cf3546c4690f5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-03T02:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-03T02:36:39.000Z", "max_issues_repo_path": "papers/FARM-18/secs/distance.tex", "max_issues_repo_name": "Yale-OMI/DSP-PBE", "max_issues_repo_head_hexsha": "073f366e8096004adeec5d2cde1cf3546c4690f5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-11-16T21:50:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-16T18:57:19.000Z", "max_forks_repo_path": "papers/FARM-18/secs/distance.tex", "max_forks_repo_name": "Yale-OMI/DSP-PBE", "max_forks_repo_head_hexsha": "073f366e8096004adeec5d2cde1cf3546c4690f5", "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": 77.1888888889, "max_line_length": 291, "alphanum_fraction": 0.7581689938, "num_tokens": 1797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6489905044190826}}
{"text": "\n\\documentclass[a4paper,11pt]{article}\n\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm, mathtools}\n%\\usepackage{hyperref}\n\\usepackage{color}\n\\usepackage{jheppub}\n\\usepackage[T1]{fontenc} % if needed\n\n% My Documents\n\\newcommand{\\be}{\\begin{equation}}\n\\newcommand{\\ee}{\\end{equation}}\n\\newcommand{\\bes}{\\begin{equation*}}\n\\newcommand{\\ees}{\\end{equation*}}\n\\newcommand{\\bea}{\\begin{flalign*}}\n\\newcommand{\\eea}{\\end{flalign*}}\n\n\n%\\linespread{1.0}\n%\\setlength{\\parindent}{0em}\n%\\setlength{\\parskip}{0.8em}\n\n\\title{\\textbf{Binaries and Tides}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\\abstract{}\n\\begin{document}\n\\maketitle\n\n\\section{Tanja's Lectures at Gravitational Wave School 2017}\n\nNon-black hole objects differ from black holes in that  :-\n\\begin{itemize}\n\t\\item They can deform due to their rotational motion\n\t\\item They can have effects due to no presence of horizon\n\t\\item They can get tidally deformed\n\\end{itemize}\nTanja's lectures focus on tidal effects, which are the most promising candidates (as of 2017) to detect parameters of neutron stars.\n\nWe start off with tides in Newtonian physics.\n\n\\subsection{Newtonian Physics}\nNotation - $ \\vb{a} $ is 3-vector and $ \\va{a} $ is 4-vector.\n\nThe force between two bodies of masses $ m  $ and $ M $ is,\n\\begin{equation}\\label{key}\n\\vb{F} = - \\dfrac{GmM}{r^2} \\vu{n} \\qq{,} U = -\\dfrac{GM}{r} \\qq{,} \\vb{a} = \\grad{U}\n\\end{equation}\nwhere $ U $ and $ \\vb{a} $ are the gravitational potential due to mass $ M $ and the acceleration respectively.\n\nTo make things more specific, consider a body of mass $ m_A $ with position vector $ \\vb{z}_A $. The potential at $\\vb{x} $ due to $ m_A$ is,\n\\begin{equation}\\label{key}\nU_A(\\vb{x}) = \\dfrac{Gm_A}{\\abs{\\vb{x} - \\vb{z}_A}}\n\\end{equation}\nAlternatively, if we consider extended bodies with density $ \\rho(x) $, the potential can be written as,\n\\begin{align}\\label{key}\nU_A(\\vb{x}) &= G \\int \\dd^3{\\vb{x}'}\\dfrac{\\rho(\\vb{x}' )}{\\abs{\\vb{x} - \\vb{x}'}}\\\\\n\\implies \\laplacian{U_A} &= G \\int \\dd^3{\\vb{x}'} \\rho(\\vb{x}' ) \\laplacian{\\dfrac{1}{\\abs{\\vb{x} - \\vb{x}'}}} \\\\\n&=  G \\int \\dd^3{\\vb{x}'} \\rho(\\vb{x}' ) \\qty(-4 \\pi \\delta(\\vb{x} - \\vb{x}'))  \\\\\n\\laplacian{U_A} &= -4 \\pi G \\rho(\\vb{x} )\n\\end{align}\n\\end{document}", "meta": {"hexsha": "32213f5fe933fb6f10e44eae42ab0789a1cc1db2", "size": 2379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "selfstudy/tides/tides.tex", "max_stars_repo_name": "adivijaykumar/courses", "max_stars_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "selfstudy/tides/tides.tex", "max_issues_repo_name": "adivijaykumar/courses", "max_issues_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "selfstudy/tides/tides.tex", "max_forks_repo_name": "adivijaykumar/courses", "max_forks_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_forks_repo_licenses": ["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.5074626866, "max_line_length": 141, "alphanum_fraction": 0.6885245902, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6489904947908847}}
{"text": "\\section{CIFAR10 example} % Jonathan / b-j8501 / Jul 11 & % b-j8505 / Jul 12\nIn this section, we will give more details about training a neural network with PyTorch. We will start with the simple CIFAR10 example introduced before, and explain how to modify each component of it. \n\nThe first of all, the first six lines here just consist the \\emph{import} statements. Basically all this does is bringing code from this imported libraries from PyTorch in your program allows to use the classes, the functions that for implement each of these libraries.\n\\begin{python}\nimport torch \nimport torchvision\nimport torchvision.transforms as transforms\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\n\\end{python}\n\n\\subsection{The \\emph{`Net'} class}\nThen each neural network we should to implement should exactly contain the class in the following. Which you does is that you define a new class called Net, which is a subclass of nn.Module. The nn.Module is a class implemented in the package torch.nn. Bascially you don't have to know exactly what the Module class does, but the point here is Network is going to be a subclass of it. Let go to it step by step.\n\nAny class defined in Python has to have the \\emph{\\_\\_init\\_\\_} function. It will run when the class be created. Late on, in the code when you implement like \\emph{`conv\\_net = Net()'}, it will create an instance of the Net class. And when the instance is created, the \\emph{\\_\\_init\\_\\_} function is run. And we can see that the \\emph{\\_\\_init\\_\\_} function create each of the pieces of the neural network, which are the operators we need for our neural network. This linear (\\emph{nn.Linear}), convolution (\\emph{nn.Conv2d}) and max pool (\\emph{nn.MaxPool2d}) is implement in somewhere else. Roughly speaking, they simply contain how much parameters and a forward function. For example the \\emph{`nn.Linear'} class: \n\\begin{itemize}\n\\item contains parameters which consists from a matrix and a vector $(W,b)$,\n\\item and the `forward' function is\n$${\\rm forward}(x) = Wx+b.$$\n\\end{itemize}\nLater on, we will talk about what \\emph{nn.Conv2d} and \\emph{nn.MaxPool2d} do.\n\nAnd then to make is useful, we need to define this forward function. Basically, it tells you, given this neural network and some inputs, what the output is. In this particular case, what the network does is to apply the first convolution, and a ReLU function. The ReLU function is\n$${\\rm ReLU}(x) = \\max\\{0,x\\}.$$\nAnd then to apply a max pooling. Then applies the next convolution, a ReLU function and pooling layer.\nThen, what the \\emph{`x.view'} does is take $x$, which is still an image (2 dimensional) and flat it out into a vector. Then applies the first linear layer, a ReLu function, and the second linear layer, a ReLU function, and finally the third linear layer. And it returns $x$. What is contained in the class is all the parameters for each of these layers and the forward function which tells you the order and how to apply them. So that is what network consist.\n\\begin{python}\nclass Net(nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n        self.conv1 = nn.Conv2d(3, 6, 5)\n        self.pool = nn.MaxPool2d(2, 2)\n        self.conv2 = nn.Conv2d(6, 16, 5)\n        self.fc1 = nn.Linear(16 * 5 * 5, 120)\n        self.fc2 = nn.Linear(120, 84)\n        self.fc3 = nn.Linear(84, 10)\n\n    def forward(self, x):\n        x = self.pool(F.relu(self.conv1(x)))\n        x = self.pool(F.relu(self.conv2(x)))\n        x = x.view(-1, 16 * 5 * 5)\n        x = F.relu(self.fc1(x))\n        x = F.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n\\end{python}\n\n\\subsection{The `main' function}\nWhat we want to do is to load a bunch of data, and train this network (all the parameters) on these data. So the \\emph{main} function is going to do that. The two lines \\emph{trainset} and \\emph{trainloader} load the train set, and the two lines \\emph{testset} and \\emph{testloader} load the test set. The \\emph{trainloader} is a class which specifies some way of giving you the data. In our particular case, we construct the \\emph{trainloader}, we pass the \\emph{trainset}, the images, to it and also a bunch of the parameters, like the batch size, shuffle, number of workers. When you calculate the gradient, you don't use the whole dataset at once, and we only use some of them. The number of data we use to calculate the gradient is the batch size. Here we pass the \\emph{`batch\\_size'} to the \\emph{DataLoader} what happen is the later on when we loop over everything in the \\emph{trainloader} (see the for loop in the main function), it will return the images four at a time because we set `batch\\_size=4'. The shuffle is true means that you return the data without replacement. It the same thing to the test set.\n\nThe \\emph{criterion} is a class containing the loss function. Given the output of the neural network and the true label applies the loss function. The optimize class, we will talk about it later on. When you construct the \\emph{`optim'} class,  the parameters you have to pass are \\emph{`net.parameters'} that tell the optimizer which parameters need to be optimized, and other hyperparameters. It has a function called \\emph{`step'}. Whenever the \\emph{`step'} function is called it going to modify the parameters in some way based on whatever the gradients are. The optimizer assume you already calculated the gradients and then it does some sort of step based on the gradients. That explains why when you actually run the training we have to call \\emph{`optimizer.zero\\_grad'} and \\emph{` loss.backward'} independently of \\emph{`optimizer.step'}. \\emph{`optimizer.step'} doesn't handle taking the gradient, it assumes that all the gradients already been taking properly.\n \n\\begin{python}\ndef main():\n\ttransform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])\n\ttrainset = torchvision.datasets.CIFAR10(root='./data', train=True,download=True, transform=transform)\n\ttrainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)\n\ttestset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform)\n\ttestloader = torch.utils.data.DataLoader(testset, batch_size=4, shufflex=False, num_workers=2)\n\nclasses = ('plane', 'car', 'bird', 'cat',\n           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')\n           \nconv_net = Net()\n\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n \nfor epoch in range(2):  # loop over the dataset multiple times\n\n    running_loss = 0.0\n    for i, data in enumerate(trainloader, 0):\n        # get the inputs; data is a list of [inputs, labels]\n        inputs, labels = data\n\n        # zero the parameter gradients\n        optimizer.zero_grad()\n\n        # forward + backward + optimize\n        outputs = net(inputs)\n        loss = criterion(outputs, labels)\n        loss.backward()\n        optimizer.step()\n\n        # print statistics\n        running_loss += loss.item()\n        if i % 2000 == 1999:    # print every 2000 mini-batches\n            print('[%d, %5d] loss: %.3f' %\n                  (epoch + 1, i + 1, running_loss / 2000))\n            running_loss = 0.0\n\nprint('Finished Training')\n\ncorrect = 0\ntotal = 0\nwith torch.no_grad():\n    for data in testloader:\n        images, labels = data\n        outputs = net(images)\n        _, predicted = torch.max(outputs.data, 1)\n        total += labels.size(0)\n        correct += (predicted == labels).sum().item()\n\nprint('Accuracy of the network on the 10000 test images: %d %%' % (\n    100 * correct / total))\n\n\\end{python}\n\n\\subsection{\\emph{`DataLoader'}}\nNext, we want to talk about how can we change the Dataloader and how can we make it provide the data samples in a different way. In particular, we already talk about the difference between sampling with and without replacement. Let us recall that a little bit.\n\nThe loss function:\n$$L(\\theta) = \\sum_{i=1}^n l(x_i,\\theta)$$\nwe want to calculate the gradient of the loss function. \n$$\\nabla L(\\theta) = \\sum_{i=1}^n \\nabla_\\theta l(x_i,\\theta)$$\nand $n$ generally could be very large, $n \\sim 10^4 - 10^7$. In this situation, to compute the gradients over all the data point is computationally not feasible. So just approximate the gradients by sampling some of the data points. \nInitially, consider the computation complexity. Stochastic gradient descent\n\\begin{itemize}\n\\item approximate the gradient by considering a sample of data points \n$$\\{x_{i_1}, \\ldots, x_{i_k}\\}$$\nwhere $\\{i_1, \\ldots, i_k\\}$ is randomly chosen in each iteration, then\n$$\\nabla L(\\theta) \\approx \\sum_{l=1}^k \\nabla_\\theta l(x_{i_l},\\theta)$$\n\\item $k$ is called the mini-batch size (controls the accuracy of \"noise\" in the sample).\nThis is a sampled gradient, containing some noise. If I have larger mini-batch size, we will get a more accuracy gradients, so the mini-batch size $k$ is an important hyper-parameter.\n\\item $i_1, \\ldots, i_k$ sampled with/without replacement.\n\\begin{itemize}\n\\item with replacement: there can be repetitions\n\\item without replacement: there can't be repetitions\n\\end{itemize}\n\\end{itemize}\nWhat we implement is sampling without replacement cross the whole epoch. When we randomly choose these data points, we can't choose the same data points again until we around the whole data set. \n\nNow, let's see how we can change it. First, go to the PyTorch documents page\\footnote{\\url{https://pytorch.org/docs/stable/data.html}}. Here is an explanation what exactly is this class does, and the important thing for us is what the possible inputs. So when I construct a DataLoader, I need to pass some variables. Whenever we construct a DataLoader, we have to pass it a dataset because there is no default value. In our program, we passed the train set, CIFAR10. You also can pass something else you want to it. And all the other variables here have some default values. There are options here to keep the defaults or to change it to what you want We can see that some of the defaults actually already changed in our program. Instead of the default value 1, we set the batch size as 4, and shuffle as true instead of false. Now, we know how to change the sampling strategies. We probably want to change some of these other inputs. Look here, we can see the description are. In particular, you will see sampler, the default value be none, which defined the strategy. Most likely, if we construct the samlper and pass it to the DataLoader, we can change the with and without replacement strategy.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{./figures/497Proj_DataLoader}\n%\\caption{DataLoader}\n\\end{figure}\n\nNow, we need to look at the sampler class. If we want to change the sampler, we need to define a class that is a subclass of the sampler, and contain the sampler strategy.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.4]{./figures/497Proj_Sampler}\n%\\caption{}\n\\end{figure}\nIn our case, if you want change that with or without replacement, somebody has already written it. \nIt turns out the RandomSampler.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.4]{./figures/497Proj_RandomSampler}\n%\\caption{}\n\\end{figure}\nLet's use our program as an example to show how to use a sampler class. First, we need to create an instance of the RandomSampler class and pass it to the DataLoader as the sampler variable.\n\\begin{python}\n\ttransform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])\n\ttrainset = torchvision.datasets.CIFAR10(root='./data', train=True,download=True, transform=transform)\n\twith_replacement_sampler = torch.utils.data.RandomSampler(trainset, replacement=True)\n\ttrainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, sampler=with_replacement_sampler, num_workers=2)\n\\end{python}\nNow if we run this code, the data will be sampled with replacement. This is just to illustrate how you go about changing something about the model and the training process. You just look up the classes, look up in the documentation, see what they do. And often the most of thing that you may want to do, someone already program them in a simple way to do them. You can just turn on like we just doing it. Just notice that you don't have to implement it yourself in this case. You just need to look out these classes do and figure out which tools for use. So we recommend just for fun just try to the CIFAR10 example with and without replacement to see difference. \n\n\\subsubsection{Codes for the CIFAR10 example}\n\\begin{python}\n# cifar10_example.py\n\nimport torch \nimport torchvision\nimport torchvision.transforms as transforms\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\n\n\nclass Net(nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n        self.conv1 = nn.Conv2d(3, 6, 5)\n        self.pool = nn.MaxPool2d(2, 2)\n        self.conv2 = nn.Conv2d(6, 16, 5)\n        self.fc1 = nn.Linear(16 * 5 * 5, 120)\n        self.fc2 = nn.Linear(120, 84)\n        self.fc3 = nn.Linear(84, 10)\n\n    def forward(self, x):\n        x = self.pool(F.relu(self.conv1(x)))\n        x = self.pool(F.relu(self.conv2(x)))\n        x = x.view(-1, 16 * 5 * 5)\n        x = F.relu(self.fc1(x))\n        x = F.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n\ndef main():\n\ttransform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])\n\ttrainset = torchvision.datasets.CIFAR10(root='./data', train=True,download=True, transform=transform)\n\ttrainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)\n\ttestset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform)\n\ttestloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False, num_workers=2)\n\nclasses = ('plane', 'car', 'bird', 'cat',\n           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')\n\nconv_net = Net()\n\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n\nfor epoch in range(2):  # loop over the dataset multiple times\n\n    running_loss = 0.0\n    for i, data in enumerate(trainloader, 0):\n        # get the inputs; data is a list of [inputs, labels]\n        inputs, labels = data\n\n        # zero the parameter gradients\n        optimizer.zero_grad()\n\n        # forward + backward + optimize\n        outputs = net(inputs)\n        loss = criterion(outputs, labels)\n        loss.backward()\n        optimizer.step()\n\n        # print statistics\n        running_loss += loss.item()\n        if i % 2000 == 1999:    # print every 2000 mini-batches\n            print('[%d, %5d] loss: %.3f' %\n                  (epoch + 1, i + 1, running_loss / 2000))\n            running_loss = 0.0\n\nprint('Finished Training')\n\ncorrect = 0\ntotal = 0\nwith torch.no_grad():\n    for data in testloader:\n        images, labels = data\n        outputs = net(images)\n        _, predicted = torch.max(outputs.data, 1)\n        total += labels.size(0)\n        correct += (predicted == labels).sum().item()\n\nprint('Accuracy of the network on the 10000 test images: %d %%' % (\n    100 * correct / total))\n\n\\end{python}\n\n\n\\subsection{The training part of CIFAR10 example}\nIn this section, we will analysis the training part code in the CIFAR10 example. \n\\begin{python}\nfor epoch in range(2):  # loop over the dataset multiple times\n\n    running_loss = 0.0\n    for i, data in enumerate(trainloader, 0):\n        # get the inputs; data is a list of [inputs, labels]\n        inputs, labels = data\n\n        # zero the parameter gradients\n        optimizer.zero_grad()\n\n        # forward + backward + optimize\n        outputs = net(inputs)\n        loss = criterion(outputs, labels)\n        loss.backward()\n        optimizer.step()\n\n        # print statistics\n        running_loss += loss.item()\n        if i % 2000 == 1999:    # print every 2000 mini-batches\n            print('[%d, %5d] loss: %.3f' %\n                  (epoch + 1, i + 1, running_loss / 2000))\n            running_loss = 0.0\n\nprint('Finished Training')\n\\end{python}\nIn particular, we will see what the \\emph{loss.backward} and \\emph{optimizer.step} do\n\\subsubsection{\\emph{loss.backward}}\nLet's start with the automatically differentiation of PyTorch. This function \\emph{loss.backward} hides some pretty complicated code that automatically figure out how to calculate the gradient w.r.t. the output.\nLet's start with some simple example.\n\\begin{python}\nimport torch\nfrom torch.autograd import Variable\nx = Variable(torch.randn(3,3), requires_grad = True)\n\\end{python}\n\\emph{Variable} is a fundamental data type in PyTorch, which contains a tensor and some other things, like a flag in our example called \\emph{requires\\_grad}. So if I set \\emph{requires\\_grad} is true, it just indicating to PyTorch that in the future whatever \\emph{x} is involved in (computational graph), it going to calculate the gradient of x. Also, one of the other things the Variable contains is the gradient value. Which right now should be empty. You can check it by running \\emph{x.grad}. \nNow let's see what happen when we use this Variable x in some calculations.\n\\begin{python}\ny = torch.sum(x)\n\\end{python}\nHere, \\emph{torch.sum} means all the values of x. Here, we create a new variable y which consists of the sum of the entries of x. And PyTorch allows us to automatically calculate the gradient of the output w.r.t. any inputs. This is an extremely simple example.\n\\begin{equation}\n\\begin{split}\nx &= \\left(\\begin{array}{ccc} \n\t* &\\cdots &* \\\\\n\t\\vdots &\\ddots &\\vdots \\\\\n\t* &\\cdots &*\n\t\\end{array}\\right) \\\\\ny &=  \\left(\\begin{array}{c} \n\t1 \\\\ \\vdots \\\\ 1\n\t\\end{array}\\right)^\\top\n\tx\\ \n\t\\left(\\begin{array}{c} \n\t1 \\\\ \\vdots \\\\ 1\n\t\\end{array}\\right)\n\t=\\sum_{i=1}^3 \\sum_{j=1}^3 x_{ij} \\\\\n\\frac{{\\rm d} y}{{\\rm d} x} &= \\left(\\begin{array}{ccc} \n\t1 &1 &1 \\\\\n\t1 &1 &1 \\\\\n\t1 &1 &1\n\t\\end{array}\\right) \n\\end{split}\n\\end{equation}\nHow to let PyTorch compute this. Simply call \n\\begin{python}\ntorch.autograd.grad(y,x)\n\\end{python}\nThis function automatically calculate the derivative of the second augment w.r.t the first. And other way, which is more commonly used, is to call \n\\begin{python}\ny.backward()\n\\end{python}\nThis function will calculate the derivative of y w.r.t everything that depends on the requirements of gradients (see the flag \\emph{requires\\_grad}). In our case, it will calculate the gradient of y w.r.t. x and store the gradient value in \\emph{x,grad}.\nThese are two common ways that let PyTorch to calculate the gradients. We just give a simple example with one input and one output, but this whole thing works even for much more complicated examples with multiple input variables. And PyTorch can automatically calculate the gradients of these variables.\n\nAnd there is one important thing to note is now if I call the \\emph{y.backwark} again, what happen to the \\emph{x.grad}? It will keep the same? or it will be changed? The answer is, unfortunately, it adds the gradient to whatever is already stored in the \\emph{x.grad}. So, this explains why we have to zero the gradients of all of the parameters (see \\emph{optimizer.zero\\_grad}) before we call \n\\emph{loss.backward} in our codes.\n\n\\subsubsection{\\emph{optimizer.step}}\nThe \\emph{loss.backward} step calculates the gradients of all of our parameters and stores in \\emph{.grad} fields. Now, let's look at our \\emph{optimizer}. This \\emph{optimizer} may be a class you want to write yourself if you want to try some new algorithm. It will help to know how it works. \nNotice that the function we are calling here is \\emph{optimizer.step}. For example, we set optimizer as SGD. After we calculate the gradients of all of the parameters, then we call this step function, it will add the values of the multiplication of learning rate and negative gradients to current values of the parameters. The \\emph{optimizer} class assume that gradients already been calculated and stored in \\emph{.grad} fields, and the class just decide what to do with the gradients.\n\nNow, let use Logistic regression as an example.\n\\begin{python}\n# lr_example.py\n\nimport torch \nimport torchvision\nimport torchvision.transforms as transforms\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\n\n\nclass LogisticRegression(nn.Module):\n    def __init__(self):\n        super(LogisticRegression, self).__init__()\n        self.linear = nn.Linear(10, 5)\n\n    def forward(self, x):\n        return self.linear(x)\n\\end{python}\nWe just write a logistic regression class with 10 input features and 5 output features. Then we will use this example to see what a the network class exactly contains.\nRun the following codes in python terminal\n\\begin{python}\nimport torch\nfrom lr_example import LogisticRegression\n\nnet = LogisticRegression()\nx = torch.randn(10)\ny = net(x)\n\\end{python}\nHere we create an instance of LogisticRegression class, and set x as input and y as output. The variables this class contains is the parameters which is a 10-by-5 matrix and a vector as the bias. And take a vector x as input, and apply the forward step (see \\emph{net(x)}, `forward' can be dropped), it will run the forward function to calculate $W x+b$.\n\nThere is one thing have to know is that when you call \\emph{backward} on something has to be a scalar. It can't be for example a tensor. For example, if I try to call \\emph{y.backward}, it will be given an error, because you can only call this for scalar outputs. It won't to calculate a Jacobian matrix of a vector output w.r.t. a vector input. However, if you pass it the derivatives of each of this components, then it can continuous do the \\emph{.backward} function. So, for example, if we we want to calculate the derivative of the sum of $y$, we can do it as follows:\n\\begin{python}\ny.backward(torch.ones(5))\n\\end{python}\nIf you have a vector that you want to call \\emph{.backward} on, you have to pass it a vector with the same size, it gives the gradients of each of the components of that vector w.r.t. the output. Actually, it calculate the Jacobian times the vector. In general, it can't calculate the Jacobian of a non-scalar output, but if you know what you want to multiply the Jacobian with, then you can pass it to \\emph{.backward} as well. \n\nThen we can see the parameter of a network \n\\begin{python}\nparams = list(net.parameters())\n\\end{python}\nNow \\emph{params} contains matrix $W$ and vector $b$. Also, we can see the gradient values of them. \n\\begin{python}\nparams[0].grad\nparams[1].grad\n\\end{python}\n\nHere we give an explanation about it. For $x\\in\\mathbb{R}^n$ and $y\\in\\mathbb{R}^d$, $y$ is some function of $x$.\n\\begin{equation}\n\\begin{split}\ny &= f(x) \\\\\n\\frac{{\\rm d} y}{{\\rm d} x} &= \\left(\\begin{array}{ccc} \n\t\\frac{{\\rm d} y_1}{{\\rm d} x_1} &\\cdots &\\frac{{\\rm d} y_d}{{\\rm d} x_1} \\\\\n\t\\vdots &\\ddots &\\vdots \\\\\n\t\\frac{{\\rm d} y_1}{{\\rm d} x_n} &\\cdots &\\frac{{\\rm d} y_d}{{\\rm d} x_n}\n\t\\end{array}\\right)  \n\\end{split}\n\\end{equation}\nIn this case, \\emph{y.backward()} will return an error, but we can call \\emph{y.backward(v)} for some vector $v\\in\\mathbb{d}$. Then it will calculate \n\\begin{equation}\n\\frac{{\\rm d} y}{{\\rm d} x}\\cdot v = \\left(\\begin{array}{ccc} \n\t\\frac{{\\rm d} y_1}{{\\rm d} x_1} &\\cdots &\\frac{{\\rm d} y_d}{{\\rm d} x_1} \\\\\n\t\\vdots &\\ddots &\\vdots \\\\\n\t\\frac{{\\rm d} y_1}{{\\rm d} x_n} &\\cdots &\\frac{{\\rm d} y_d}{{\\rm d} x_n}\n\t\\end{array}\\right)  \n\t\\left(\\begin{array}{c} \n\tv_1 \\\\ \\vdots \\\\v_d\t\n\t\\end{array}\\right)  \n= \\nabla(y\\cdot v)\n\\end{equation}\n\n\nThis is basically because if you want to compute the whole Jacobian matrix, it requires a lot of time and space and it always not necessary. \n\nMaybe this will make more sense if I set another variable $z$ as the sum of $y$, \n\\begin{python}\nnet.zero.grad()\ny = net(x)\nz =torch.sum(y)\n\\end{python}\n\nIn our example, we can see $z$ is a function of $y$ and $z = g(y) = y \\cdot v$.\nIf I take \\emph{z.backward}, this is the same computation with the previous did. Because the derivatives of $z$ w.r.t. $y$ is $\\frac{{\\rm d} z}{{\\rm d}y} = (1,1,1,1,1)^\\top$. This is what the \\emph{.backward} does. It calculate the gradients multiplied by the Jacobian of previous layer to get the previous gradients, and so on.\nYou can call \n\\begin{python}\nz.backward()\nparams[0].grad\nparams[1].grad\n\\end{python}\nand compare the output with the previous one. \n\nIn practice, we would construct some loss function, and call \\emph{backward} on it. Particular, in our cifar10 example, it consists of a bunch of parameters, particular, each of these layers has its parameters, and when you call forward, it performs some complicated calculations. It will build some graph that contains all the dependencies of these calculations. And then, after you apply the network\nand apply a loss function to it, you call \\emph{loss.backward}, this step gives you all the gradients of the parameters, and then this is a special optimizer class, which takes those stored gradients and use them to perform like a forward step. \nThe most important thing to remember are don't forget the \\emph{optimizer.zero\\_grad} because the \\emph{backward} step adds the new calculated gradients to that already stored in the \\emph{grad} field. Of course, if you have two loss functions, called \\emph{loss1} and \\emph{loss2}, you can call \n\\begin{python}\nloss1.backward()\nloss2.backward()\n\\end{python}\nand gradients now is the sum of those two gradients.\n", "meta": {"hexsha": "53398296f71d7897479edf812c17bc91d79d3b7c", "size": 25491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/497Proj_cifar.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/497Proj_cifar.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/497Proj_cifar.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": 58.7350230415, "max_line_length": 1198, "alphanum_fraction": 0.7189988623, "num_tokens": 6802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6489904896483776}}
{"text": "\\selectlanguage{english}\n\\begin{abstract}\n    \\noindent For the first project of the Computer Simulations (ELTE Physics MSc) course I propose a concept of an N-body simulation, which aims to reproduce the satellite formation inside asteroid belts around a larger stellar object (eg. a gas giant or a star). Due to the N-body simulations' high computational difficulty, my spare objective is to observe at least some form of clustering process inside these type of systems. To achieve these goals, I will use Newton's law of universal gravitation, solving the particles' equation of motion by a simple 4th order Runge-Kutta function. Other numerical methods - described in Sec. III. will be optionally tested.\n\\end{abstract}\n\n\\begin{multicols}{2}\n\\section{Introduction}\nThe problem of gravitational- or electromagnetic attraction of more, than 2 bodies are impossible to solve analitically, except for some finite special cases. To study the motion of the particles in such systems we're ought to rely on numerical simulations and approximations. The computational difficulty of the problem grows non-linearly as we try to simulate more and more particles, and thus these simulations are required to be reinforced by some clever numerical tricks to overcome the barrier of immense computational times.\n\n\\section{Motivation}\nAs I've already worked with numerical simulations of many-body systems, using two- and three-body approximations, I've choosen the topic of N-body simulations unhesitantly to work on as the first project of the Computer Simulations course. Also being fascinated by astronomical questions and problems, the choosing of the topic was an overally trivial decision for me. My goals are to improve my knowledge about simple N-body simulations and to learn to use some generally useful numerical tricks while working on the assignment.\n\n\\section{Description of the proposed assignment}\nInside a dense asteroid or planetary debris belt it is inevitable for larger objects to form. This belt could be either orbiting around a central star, or a planet. In both cases, moons or dwarf planets will be created by the constant collisions of the individual smaller bodies. My proposed assignment is to simulate the N-body problem of such system of maximally $10^5$ bodies and monitor its density changes and observe the formation of clusters or even greater satellites with DBSCAN or mean-shift methods. Furthermore to achieve somewhat more realistic results, I propose to implement a simple collision system between the colliding bodies. In a star - planet - asteroids system it is also possible to observe the formation of asteroid clusters around Lagrange points, which could be an extra task for the project. \\newline\nTo evade all possible infinities or huge numerical errors, I will work with spherical rigid bodies, instead of point-like particles. To speed up the processing, I propose to experimentally use a neighbour list method with some reasonable cut-off distance, similar to used in molecular dynamics simulation. Reason for this, that at great distances the gravitational pull between smaller ojects can be bravely neglected, and thus the efficiency of the simulation could be greatly enhanched. However I have no idea how does this approximation affects or deteriorates the accuracy of the simulation. I think at least it deserves a chance.\n\n\\section{Theoretical background}\nDue to my very limited free time and the short deadline for the final submission, I decided to work using the Newtonian gravitational theory only. In this case it becomes pretty straightforward to write down the necessary equations of motion. The force, acting on the $i$th body could be described by the following sum:\n\n\\begin{equation}\nm_{i} \\boldsymbol{\\ddot{r}}_{i}\n=\n- G \\sum_{i \\neq j} \\frac{m_{i} m_{j}}{\\left| r_{i} - r_{j} \\right|^{2}} \\frac{\\boldsymbol{r}_{i} - \\boldsymbol{r}_{j}}{\\left| r_{i} - r_{j} \\right|}\n\\end{equation}\nUsing this, one can simply describe the acceleration acting on the $i$th body:\n\n\\begin{equation}\n\\boldsymbol{\\ddot{r}}_{i}\n=\n- G \\sum_{i \\neq j} \\frac{m_{j}}{\\left| r_{i} - r_{j} \\right|^{2}} \\frac{\\boldsymbol{r}_{i} - \\boldsymbol{r}_{j}}{\\left| r_{i} - r_{j} \\right|}\n\\end{equation}\nWhich differential equation essentially should be solved numerically for the $x$, $y$ and $z$ components of the $\\boldsymbol{r}$ vector to acquire the coordinates and velocities of the individual particles.\n\n\\section{Problems and spare objective}\nN-body simulations are $\\mathcal{O} \\left( N ^{2} \\right)$ hard problems, which in the absence of powerful computational systems, makes these simulations pretty useless for the observation of longterm processes, when too much particle is present. If my initial idea - to observe formation of compact satellites and moons - fails, I aim to try to at least monitor the formation of denser clusters and groups inside my asteroid system. \\newline\nIt could be also provide unsatisfactory results if the initial system is not stable, and all particles simply ejected from the solar system after a while. I really do hope this won't happen...\n\n\\section{Technical deteails}\nI'm the most confident working in Python 3.X enviroments, and prefering mostly Jupyter Notebooks. The used tools and libraries will be only Python-related. I also use FFmpeg to generate animations of the simulated systems. If it is possible, I will upload some animations of my project on my YouTube channel.\n\n\\end{multicols}", "meta": {"hexsha": "9978cc7f5ea46edb5efda998513db3cba118b9b6", "size": 5460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project 1/Documentation/Concept/src/text_src/body.tex", "max_stars_repo_name": "masterdesky/ELTE_Comp_Simulations_2020", "max_stars_repo_head_hexsha": "b7689e0ecf9b5deaf1c713b647c1c106b8af7457", "max_stars_repo_licenses": ["MIT"], "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 1/Documentation/Concept/src/text_src/body.tex", "max_issues_repo_name": "masterdesky/ELTE_Comp_Simulations_2020", "max_issues_repo_head_hexsha": "b7689e0ecf9b5deaf1c713b647c1c106b8af7457", "max_issues_repo_licenses": ["MIT"], "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 1/Documentation/Concept/src/text_src/body.tex", "max_forks_repo_name": "masterdesky/ELTE_Comp_Simulations_2020", "max_forks_repo_head_hexsha": "b7689e0ecf9b5deaf1c713b647c1c106b8af7457", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 133.1707317073, "max_line_length": 828, "alphanum_fraction": 0.7928571429, "num_tokens": 1207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6489730590953954}}
{"text": "\\section{Laurent Series, Isolated Singularities and the Residue Theorem}\r\n\\begin{theorem}\r\n    Consider an open annulus $A=\\{z\\in\\mathbb C:r<|z-a|<R\\}$ and let $f$ be holomorphic on $A$.\r\n    Then $f$ has a Laurent series expansion\r\n    $$f(z)=\\sum_{n\\in\\mathbb Z}c_n(z-a)^n=\\left( \\sum_{n=0}^\\infty c_n(z-a)^n \\right)+\\left( \\sum_{n=1}^\\infty c_{-n}(z-a)^{-n} \\right)$$\r\n    for every $z\\in A$.\r\n    In addition, for any $r<\\rho<R$, we have\r\n    $$c_n=\\frac{1}{2\\pi i}\\oint_{\\partial D_\\rho(a)}\\frac{f(z)}{(z-a)^{n+1}}\\,\\mathrm dz$$\r\n    Also for any $r<\\rho_1<\\rho_2<R$ the series converges uniformly on $\\{z\\in\\mathbb C:\\rho_1<|z-a|<\\rho_2\\}$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $w\\in A$, and choose $r<\\rho_2<|w-a|<\\rho_1<R$ and let $\\gamma_1$ be the anticlockwise curve as the boundary of the a polar slice of the annulus $\\{z\\in\\mathbb C:\\rho_2<|z-a|<\\rho_1\\}$ that contains $w$, and $\\gamma_2$ be the boundary of the rest such that $\\gamma_{1,2}$ agrees on the slices.\r\n    Now\r\n    $$\\oint_{\\gamma_2}\\frac{f(z)}{z-w}\\,\\mathrm dz=0,\\frac{1}{2\\pi i}\\oint_{\\gamma_1}\\frac{f(z)}{z-w}\\,\\mathrm dz=I(\\gamma,w)f(w)$$\r\n    But since $\\gamma_1$ is homotopic to a circle around $w$, $I(\\gamma,w)=1$.\r\n    Hence\r\n    \\begin{align*}\r\n        f(w)&=\\frac{1}{2\\pi i}\\left( \\oint_{\\gamma_1}\\frac{f(z)}{z-w}+\\oint_{\\gamma_2}\\frac{f(z)}{z-w} \\right)\\\\\r\n        &=\\frac{1}{2\\pi i}\\left( \\oint_{\\partial D_{\\rho_1}(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz-\\oint_{\\partial D_{\\rho_2}(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz \\right)\\\\\r\n        &=f_1(w)+f_2(w)\\\\\r\n        f_1(w)&=\\frac{1}{2\\pi i}\\oint_{\\partial D_{\\rho_1}(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz\\\\\r\n        f_2(w)&=-\\frac{1}{2\\pi i}\\oint_{\\partial D_{\\rho_2}(a)}\\frac{f(z)}{z-w}\\,\\mathrm dz\r\n    \\end{align*}\r\n    Expanding $f_1$ as Taylor series about $a$ would give the nonnegative terms of the Laurent series.\r\n    We shall produce the negative terms from $f_2$ by a trick we used before.\r\n    Observe\r\n    $$-\\frac{1}{z-w}=\\frac{1}{w-a}\\frac{1}{1-(z-a)/(w-a)}=\\sum_{m=1}^\\infty\\frac{(z-a)^{m-1}}{(w-a)^m}$$\r\n    which converges uniformly as a geometric series.\r\n    So we can change the order of integration and get\r\n    $$f_2(w)=\\sum_{m=1}^\\infty\\left(\\frac{1}{2\\pi i}\\oint_{\\partial D_{\\rho_2}(a)}f(z)(z-a)^{m-1}\\,\\mathrm dz\\right)(w-a)^{-m}$$\r\n    writing $m=-n$ gives the existence of the Laurent series.\r\n    The rest is trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A complex valued function $f$ has an isolated singularity at a point $a\\in\\mathbb C$ if $f$ is defined and holomorphic in a punctured disk $D_r(a)\\setminus\\{a\\}$ for some $r>0$ but not in $D_r(a)$ (i.e. either not defined at $a$ or not holomorphic there).\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $f(z)=1/z$ has an isolated singularity at $z=0$.\\\\\r\n    2. $f(z)=(e^z-1)/z$ also has one at $0$.\\\\\r\n    3. $f(z)=e^{1/z}$ has one at $0$.\r\n\\end{example}\r\n\\begin{definition}\r\n    An isolated singularity $a$ of $f$ is removable if there is a holomorphic $g$ defined on $D_r(a)$ for some $r>0$ and $f=g$ on $D_r(a)\\setminus\\{a\\}$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $f$ has a removable singularity at $a$ iff $\\lim_{z\\to a}(z-a)f(z)=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The ``only if'' part is immediate.\r\n    For the other direction, Suppose $f$ is holomorphic on $D_r(a)\\setminus\\{a\\}$ and $\\lim_{z\\to a}(z-a)f(z)=0$, then let\r\n    $$h(z)=\\begin{cases}\r\n        (z-a)^2f(z)\\text{, if $z\\neq 0$}\\\\\r\n        0\\text{, if $z=0$}\r\n    \\end{cases}$$\r\n    So $h$ is holomorphic in some disk $D_r(a)\\setminus\\{a\\}$.\r\n    Also\r\n    $$\\frac{h(z)-h(a)}{z-a}=(z-a)f(z)\\to 0$$\r\n    as $z\\to a$, so $h$ is actually holomorphic on $D_r(a)$ with $h^\\prime(a)=0$.\r\n    But $h$ has a zero of order at least $2$, hence there is a holomorphic $g$ on $D_r(a)$ such that $h(z)=(z-a)^2g(z)$, but then $g$ equals $f$ on $D_r(a)\\setminus\\{a\\}$.\r\n\\end{proof}\r\nSo the isolated singularities of bounded functions are removable.\r\n\\begin{definition}\r\n    Let $a$ be an isolated singularity of $f:D_r(a)\\to\\mathbb C$, then $a$ is a pole if the limit $\\lim_{z\\to a}|f(z)|=\\infty$.\\\\\r\n    If $a$ is neither a pole nor a removable singularity, we say $a$ is an essential singularity.\r\n\\end{definition}\r\n\\begin{proposition}\\label{pole_equiv}\r\n    Let $U$ be a domain and $f:U\\setminus\\{a\\}\\to\\mathbb C$ is holomorphic for $a\\neq U$.\r\n    Then the followings are equivalent:\\\\\r\n    1. $a$ is a pole of $f$.\\\\\r\n    2. There is $\\epsilon>0$ such that there is a holomophic $h:D_\\epsilon(a)\\to\\mathbb C$ with $h(z)=0\\iff z=a$ and $\\forall z\\in D_\\epsilon(a)\\setminus\\{a\\},f(z)=1/h(z)$.\\\\\r\n    3. There is a holomorphic $g:U\\to\\mathbb C$ such that $g(a)\\neq 0$ and\r\n    $$f(z)=(z-a)^{-k}g(z)$$\r\n    for some integer $k\\ge 1$.\r\n    Also such $g,k$ are uniquely determined by $f$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $1\\implies 2$: Choose $\\epsilon$ such that $|f(z)|\\ge 1$ whenever $0<|z-a|<\\epsilon$, so $1/f$ is holomorphic on $D_\\epsilon(a)\\setminus\\{a\\}$.\r\n    But $a$ becomes a removable singularity of $1/f$ by the preceding proposition, so the extension of $1/f$ to the entire disk $D_\\epsilon(a)$ would be the desired $h$.\\\\\r\n    $2\\implies 3$: Suppose $h$ has a zero of order $k$, then $h(z)=(z-a)^kq(z)$ where $q$ is holomorphic and $q(a)\\neq 0$, so $q$ is nonzero in a disk $D\\subset D_\\epsilon(a)$ around $a$, hence\r\n    $$g(z)=\\begin{cases}\r\n        1/q(z)\\text{, if $z\\in D$}\\\\\r\n        (z-a)^kf(z)\\text{, if $z\\in U\\setminus\\{a\\}$}\r\n    \\end{cases}$$\r\n    which is well-defined by the definition of $h$ and is holomorphic.\r\n    Uniqueness follows.\\\\\r\n    $3\\implies 1$ is trivial.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $z\\in\\mathbb C$ is an essential singularity of $f$, then the limit of $|f(z)|$ as $z\\to a$ does not exist, either as a real number or infinity.\r\n\\end{corollary}\r\n\\begin{example}\r\n    If we compute $e^{1/z}$ as $z\\to 0$, we will find that it does not exist, so $0$ is an essential singularity of it.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $f$ has a pole at $a$, then the integer $k$ as stated in Proposition \\ref{pole_equiv} is called the order of the pole $a$.\r\n    If $k=1$, then we call $a$ a simple pole.\\\\\r\n    Let $U$ be a domain and $S\\subset U$ is a set of isolated points in $U$.\r\n    If $f$ is holomorphic on $U\\setminus S$ and each $s\\in S$ is either a removable singularity or a pole of $f$, we say $f$ is meromorphic on $U$.\r\n\\end{definition}\r\nMeromorphic functions can be taken (maybe) as holomorphic functions from $U$ to $\\mathbb C_\\infty$.\r\n\\begin{remark}\r\n    By the preceding corollary, at an isolated essential singularity $a$ of $f$, then $f$ oscillates around $a$.\r\n    More precisely we have the Cosorati-Weierstrass Theorem (proven in example sheet), where we find that the image of any punctured neighbourhood around $a$ has dense image in $\\mathbb C$.\r\n    A much much harder theorem will show that this image is the entire complex plane $\\mathbb C$ except possibly one point.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Let $f$ be holomorphic in $D_R(a)\\setminus\\{a\\}$, then we have the series\r\n    $$f(z)=\\sum_{n\\in\\mathbb Z}c_n(z-a)^n,\\forall z\\in D_R(a)\\setminus\\{a\\}$$\r\n    Also, $\\forall n<0,c_n=0$ implies that $a$ is removable.\\\\\r\n    If now $c_{-k}\\neq 0$ for some $k>0$ and $c_n=0$ for $n<-k$, then there is a holomorphic $g:D_R(a)\\to\\mathbb C$ such that\r\n    $$f(z)=\\sum_{n=-k}^\\infty c_n(z-a)^n=\\frac{g(z)}{(z-a)^k}$$\r\n    So $f$ has a pole of order $k$ at $a$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nLet rhe series expansion be as above, then by uniform convergence, the integral\r\n$$\\int_{\\partial D_\\rho(a)}f(z)\\,\\mathrm dz=2\\pi ic_{-1}$$\r\nSo we define\r\n\\begin{definition}\r\n    $c_{-1}$ is defined as the residue $\\operatorname{Res}_f(a)$ of $f$ at $a$.\r\n    And the series\r\n    $$\\sum_{n=-\\infty}^{-1}c_n(z-a)^n$$\r\n    is called the principal part of $f$.\r\n\\end{definition}\r\n\\begin{theorem}[Residue Theorem]\r\n    Let $U$ be a domain and $S=\\{a_1,\\ldots,a_k\\}\\subset U$.\r\n    Suppose $f$ is holomorphic on $U\\setminus S$, then for any closed piecewise $C^1$ curve $\\gamma:[0,1]\\to U\\setminus S$ homologous to $0$ in $U$, we have\r\n    $$\\int_\\gamma f(z)\\,\\mathrm dz=2\\pi i\\sum_{j=1}^kI(\\gamma;a_j)\\operatorname{Res}_f(a_j)$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $g$ be the principal part of $f$ at $a_i$.\r\n    Then $g$ is holomorphic on $\\mathbb C\\setminus\\{a_i\\}$, so $f-(g_1+\\cdots+g_k)$ is holomorphic in $U$ except at removable singularities, so by Cauchy's Theorem,\r\n    $$\\int_\\gamma f(z)\\,\\mathrm dz=\\sum_{j=1}^k\\int_\\gamma g_j(z)\\,\\mathrm dz=2\\pi i\\sum_{j=1}I(\\gamma,a_j)\\operatorname{Res}_f(a)$$\r\n    as desired.\r\n\\end{proof}\r\nThere are some useful facts about residues.\r\n\\begin{proposition}\r\n    If $f$ has a simple pole at $a$, then $\\operatorname{Res}_f(a)=\\lim_{z\\to a}(z-a)f(a)$.\r\n    More generally, if $f$ has a pole of order $k$, then if we write $f(z)=(z-a)^{-k}g(z)$ for a holomorphic $g$, then $\\operatorname{Res}_f(a)=g^{(k-1)}(a)/(k-1)!$.\r\n    If $f=g/h$ with $g,h$ holomorphic and at $a$, $g(a)\\neq 0$ and $h$ has a simple zero at $a$, then $f(a)=g(a)/h^\\prime(a)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Easy.\r\n\\end{proof}\r\n\\begin{proposition}[Jordan's Lemma]\r\n    If $f$ is holomorphic in $\\{z\\in\\mathbb C:|z|>r\\}$ for some $r>0$ and if $zf(z)$ is bounded for large $|z|$, then\r\n    $$\\int_{\\gamma_R}f(z)e^{i\\alpha z}\\,\\mathrm dz\\to 0,\\gamma_R:[0,\\pi]\\ni t\\mapsto Re^{it}$$\r\n    as $R\\to\\infty$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Example sheet.\r\n    Use the fact that $\\sin t/t\\ge 2/\\pi$ for $t\\in (0,\\pi/2]$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $f$ be holomorphic on $D_R(a)\\setminus\\{a\\}$ with a simple pole at $z=a$ and $\\gamma_\\epsilon:[\\alpha,\\beta]\\ni t\\mapsto a+\\epsilon e^{it}$, then\r\n    $$\\lim_{\\epsilon\\to 0^+}\\int_{\\gamma_\\epsilon}f(z)\\,\\mathrm dz=(\\beta-\\alpha)i\\operatorname{Res}_f(a)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just write $f(z)=\\operatorname{Res}_f(a)/(z-a)+g(z)$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $R>\\epsilon>0$.\r\n    Consider $f(z)=e^{iz}/z$ along the contour $\\gamma=\\gamma_1-\\gamma_\\epsilon+\\gamma_2+\\gamma_R$ where $\\gamma_1$ is the segment $[-R,-\\epsilon]$, $\\gamma_2$ is $[\\epsilon,R]$, and $\\gamma_R(t)=Re^{it},\\gamma_\\epsilon(t)=\\epsilon e^{it},t\\in [0,\\pi]$.\r\n    Now by Jordan's Lemma and the preceding proposition respectively, we have\r\n    $$\\lim_{R\\to\\infty}\\int_{\\gamma_R}f(z)\\,\\mathrm dz=0,\\lim_{\\epsilon\\to 0}\\int_{\\gamma_\\epsilon}f(z)\\,\\mathrm dz=\\pi i\\operatorname{Res}_f(a)=\\pi i$$\r\n    Now for $\\epsilon,R$ as before we have\r\n    $$0=\\int_\\gamma f(z)\\,\\mathrm dz=\\int_{-R}^{-\\epsilon}\\frac{e^{ix}}{x}\\,\\mathrm dx+\\int_{-\\gamma_\\epsilon}f(z)\\,\\mathrm dz+\\int_\\epsilon^R\\frac{e^{ix}}{x}\\,\\mathrm dx+\\int_{\\gamma_R}f(z)\\,\\mathrm dz$$\r\n    Now let $R\\to\\infty,\\epsilon\\to 0$, we get\r\n    $$2i\\int_0^\\infty\\frac{\\sin x}{x}\\,\\mathrm dx=\\pi i\\implies\\int_0^\\infty\\frac{\\sin x}{x}\\,\\mathrm dx=\\frac{\\pi}{2}$$\r\n\\end{example}", "meta": {"hexsha": "60b6a79e2ed27ed932e68c8e61f960b7ae664d85", "size": 10890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/res.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": "4/res.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": "4/res.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": 63.6842105263, "max_line_length": 302, "alphanum_fraction": 0.6252525253, "num_tokens": 4026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.6489730367322085}}
{"text": "\\problemname{Elementary Math}\n\n\\illustration{.35}{elementarymath.jpg}{Example exam by Ellen}%\nEllen is teaching elementary math to her students and the time for the final exam has\ncome. The exam consists of $n$ questions. In each question the students have to\nadd ($+$), subtract ($-$) or multiply ($*$) a pair of numbers.\n\nEllen has already chosen the $n$ pairs of numbers. All that remains is to decide\nfor each pair which of the three possible operations the students should perform.\nTo avoid students getting bored, Ellen wants to make sure that the $n$ correct answers\nto her exam are all different.\n\nPlease help Ellen finish constructing the exam by automating this task.\n\n\\section*{Input}\n\nThe input consists of:\n\\begin{itemize}\n   \\item one line with one integer $n$ ($1\\leq n \\leq 2\\,500$), the number of pairs of numbers;\n   \\item $n$ lines each with two integers $a$ and $b$ ($-10^6 \\leq a, b \\leq 10^6$), a pair of numbers used.\n\\end{itemize}\n\n\\section*{Output}\n\nFor each pair of numbers $(a,b)$ in the same order as in the input,\noutput a line containing a valid equation.\nEach equation should consist of five parts: $a$, one of the three operators, $b$,\nan equals sign ($=$), and the result of the expression.\nAll the $n$ expression results must be different.\n\nIf there are multiple valid answers you may output any of them.\nIf there is no valid answer, output a single line with the string ``\\texttt{impossible}'' instead.\n\n", "meta": {"hexsha": "f0d9536f0182d41164eb9f29231840d203606555", "size": 1439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/elementarymath/problem_statement/problem.en.tex", "max_stars_repo_name": "stoman/CompetitiveProgramming", "max_stars_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-22T13:21:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-12T22:26:26.000Z", "max_issues_repo_path": "problems/elementarymath/problem_statement/problem.en.tex", "max_issues_repo_name": "stoman/CompetitiveProgramming", "max_issues_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_issues_repo_licenses": ["MIT"], "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/elementarymath/problem_statement/problem.en.tex", "max_forks_repo_name": "stoman/CompetitiveProgramming", "max_forks_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_forks_repo_licenses": ["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.3235294118, "max_line_length": 108, "alphanum_fraction": 0.7407922168, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.6489439742578481}}
{"text": "\\section{Eigenvalues and eigenvectors of a matrix}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Describe eigenvalues geometrically and algebraically.\n  \\item Find eigenvalues and eigenvectors for a square matrix.\n  \\end{enumerate}\n\\end{outcome}\n\n", "meta": {"hexsha": "bcc687e37d93309c1e23d8f2b47cebead7018574", "size": 246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryEigenvaluesEigenvectors.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/spectraltheoryEigenvaluesEigenvectors.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/spectraltheoryEigenvaluesEigenvectors.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.6, "max_line_length": 62, "alphanum_fraction": 0.7804878049, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.648943972330536}}
{"text": "\\title{Teaching the Geometry of Schemes}\n\\titlerunning{Teaching the Geometry of Schemes}\n\\toctitle{Teaching the Geometry of Schemes}\n\n\\author{Gregory G.~Smith \\and Bernd Sturmfels}\n\\authorrunning{G. G. Smith and B. Sturmfels}\n% \\institute{Department of Mathematics, University of California,\n% Berkeley, California 94720, USA}\n\n\\maketitle\n\n\n%%----------------------------------------------------------\n\\newtheorem*{problem*}{Problem}{\\bfseries\\upshape}{\\itshape}\n\\newtheorem*{solution*}{Solution}{\\itshape}{\\rmfamily}\n\n\\newcommand{\\Spec}{\\operatorname{Spec}}\n\\newcommand{\\Proj}{\\operatorname{Proj}}\n\\newcommand{\\codim}{\\operatorname{codim}}\n%%----------------------------------------------------------\n\n\n\\begin{abstract}\nThis chapter presents a collection of graduate level problems in\nalgebraic geometry illustrating the power of \\Mtwo as an educational\ntool.\n\\end{abstract}\n\nWhen teaching an advanced subject, like the language of schemes, we\nthink it is important to provide plenty of concrete instances of the\ntheory.  Computer algebra systems, such as \\Mtwo, provide students\nwith an invaluable tool for studying complicated examples.\nFurthermore, we believe that the explicit nature of a computational\napproach leads to a better understanding of the objects being\nexamined.  This chapter presents some problems which we feel\nillustrate this point of view.\n\nOur examples are selected from the homework of an algebraic geometry\nclass given at the University of California at Berkeley in the fall of 1999.\nThis graduate course was taught by the second author with assistance from the\nfirst author.  Our choice of problems, as the title suggests, follows the\nmaterial in David Eisenbud and Joe Harris' textbook {\\em The Geometry of\n  Schemes} \\cite{SC:EH}.\n\n%%----------------------------------------------------------\n\\section{Distinguished Open Sets}\n\nWe begin with a simple example involving the Zariski topology of an affine\nscheme\\index{scheme!affine}. This example also indicates some of the\nsubtleties involved in working with arithmetic\nschemes\\index{scheme!arithmetic}.\n\n\\begin{problem*}\nLet $S = \\bbbz[x,y,z]$ and $X = \\Spec(S)$.  If $f = x$ and $X_{f}$ is\nthe corresponding basic open subset in $X$, then establish the\nfollowing:\n\\begin{enumerate}\n\\item[$(1)$] If $e_{1} = x+y+z$, $e_{2} = xy+xz+yz$ and $e_{3} = xyz$\nare the elementary symmetric functions then the set $\\{X_{e_{i}}\\}_{1\n\\leq i \\leq 3}$ is an open cover of $X_{f}$.\n\\item[$(2)$] If $p_{1} = x+y+z$, $p_{2} = x^{2}+y^{2}+z^{2}$ and $p_{3}\n= x^{3}+y^{3}+z^{3}$ are the power sum symmetric functions then\n$\\{X_{p_{i}}\\}_{1 \\leq i \\leq 3}$ is {\\em not} an open cover of\n$X_{f}$.\n\\end{enumerate}\n\\end{problem*}\n\n\\begin{solution*}\n$(1)$ To prove that $\\{X_{e_{i}}\\}_{1 \\leq i \\leq 3}$ is an open cover\nof $X_{f}$, it suffices to show that $e_{1}$, $e_{2}$ and $e_{3}$\ngenerate the unit ideal in $S_{f}$; see Lemma I-16 in Eisenbud and\nHarris~\\cite{SC:EH}.  This is equivalent to showing that $x^{m}$\nbelongs to the $S$-ideal $\\langle e_{1}, e_{2}, e_{3} \\rangle$ for\nsome $m \\in \\bbbn$.  In other words, the saturation\\index{saturation}\n$\\big( \\langle e_{1}, e_{2}, e_{3} \\rangle : x^{\\infty} \\big)$ is the\nunit ideal if and only if $\\{X_{e_{i}}\\}_{1 \\leq i \\leq 3}$ is an open\ncover of $X_{f}$.  We verify this in \\Mtwo as follows:\n<<<S = ZZ[x, y, z];>>>\n<<<elementaryBasis = ideal(x+y+z, x*y+x*z+y*z, x*y*z);>>>\n<<<saturate(elementaryBasis, x)>>>\n$(2)$ Similarly, to show that $\\{X_{p_{i}}\\}_{1 \\leq i \\leq 3}$ is not\nan open cover of $X_{f}$, we prove that $\\big( \\langle p_{1}, p_{2},\np_{3} \\rangle : x^{\\infty} \\big)$ is not the unit ideal.  Calculating\nthis saturation, we find\n<<<powerSumBasis = ideal(x+y+z, x^2+y^2+z^2, x^3+y^3+z^3);>>>\n<<<saturate(powerSumBasis, x)>>>\n<<<clearAll>>>\nwhich is not the unit ideal.\\qed\n\\end{solution*}\n\nThe fact that $6$ is a generator of the ideal $\\big( \\langle p_{1},\np_{2}, p_{3} \\rangle : x^{\\infty} \\big)$ indicates that\n$\\{X_{p_{i}}\\}_{1 \\leq i \\leq 3}$ does not contain the points in $X$\nlying over the points $\\langle 2 \\rangle$ and $\\langle 3 \\rangle$ in\n$\\Spec(\\bbbz)$.  If we work over a base ring in which $6$ is a unit,\nthen $\\{X_{p_{i}}\\}_{1 \\leq i \\leq 3}$ would, in fact, be an open\ncover of $X_{f}$.\n\n\n%%----------------------------------------------------------\n\\section{Irreducibility}\n\nThe study of complex semisimple Lie algebras gives rise to an\nimportant family of algebraic varieties called nilpotent\norbits\\index{nilpotent orbits}.  The next problem examines the\nirreducibility\\index{scheme!irreducible} of a particular nilpotent\norbit.\n\n\\begin{problem*} \nLet $X$ be the set of nilpotent complex $3 \\times 3$ matrices.  Show\nthat $X$ is an irreducible algebraic variety.\n\\end{problem*}\n\n\\begin{solution*}\nA $3 \\times 3$ matrix $M$ is nilpotent if and only if its minimal\npolynomial $p(\\sf T)$ equals ${\\sf T}^{k}$, for some $k \\in \\bbbn$.\nSince each irreducible factor of the characteristic polynomial of $M$\nis also a factor of $p(\\sf T)$, it follows that the characteristic\npolynomial of $M$ is ${\\sf T}^{3}$.  We conclude that the coefficients\nof the characteristic polynomial of a generic $3 \\times 3$ matrix\ndefine the algebraic variety $X$.\n\nTo prove that $X$ is irreducible over $\\bbbc$, we construct a rational\nparameterization\\index{rational parameterization}.  First, observe\nthat ${\\rm GL}_{3}(\\bbbc)$ acts on $X$ by conjugation.  Jordan's\ncanonical form theorem implies that there are exactly three orbits;\none for each of the following matrices:\n\\[\nN_{(1,1,1)} =\\left[ \\begin{smallmatrix} 0 & 0 & 0 \\\\ 0 & 0 & 0 \\\\ 0 &\n0 & 0 \\end{smallmatrix} \\right], \\quad\nN_{(2,1)} = \\left[ \\begin{smallmatrix} 0 & 1 & 0 \\\\ 0 & 0 & 0 \\\\ 0 & 0\n& 0 \\end{smallmatrix} \\right] \\text{ and }\nN_{(3)} = \\left[ \\begin{smallmatrix} 0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 &\n0 \\end{smallmatrix} \\right] \\enspace .\n\\]\nEach orbit is defined by a rational parameterization, so it suffices\nto show that the closure of the orbit containing $N_{(3)}$ is the\nentire variety $X$.  We demonstrate this as follows:\n<<<S = QQ[t, y_0 .. y_8, a..i, MonomialOrder => Eliminate 10];>>>\n<<<N3 = (matrix {{0,1,0},{0,0,1},{0,0,0}}) ** S>>>\n<<<G = genericMatrix(S, y_0, 3, 3)>>>\nTo determine the entries in $G \\cdot N_{(3)} \\cdot G^{-1}$, we use the\nclassical adjoint\\index{classical adjoint} to construct the matrix\n$\\det(G) \\cdot G^{-1}$.\n<<<classicalAdjoint = (G) -> (\n     n := degree target G;\n     m := degree source G;\n     matrix table(n, n, (i, j) -> (-1)^(i+j) * det(\n               submatrix(G, {0..j-1, j+1..n-1}, \n                    {0..i-1, i+1..m-1}))));>>>\n<<<num = G * N3 * classicalAdjoint(G);>>>\n<<<D = det(G);>>>\n<<<M = genericMatrix(S, a, 3, 3);>>>\nThe entries in $G \\cdot N_{(3)} \\cdot G^{-1}$ give a rational\nparameterization of the orbit generated by $N_{(3)}$.  Using\nelimination theory\\index{elimination theory} --- see section~3.3 in\nCox, Little and O`Shea~\\cite{SC:CLO} --- we give an ``implicit\nrepresentation'' of this variety.\n<<<elimIdeal = minors(1, (D*id_(S^3))*M - num) + ideal(1-D*t);>>>\n<<<closureOfOrbit = ideal selectInSubring(1, gens gb elimIdeal);>>>\n\nFinally, we verify that this orbit closure equals $X$\nscheme-theoretically.  Recall that $X$ is defined by the coefficients\nof the characteristic polynomial of a generic $3 \\times 3$ matrix {\\tt\nM}.\n%% was X = ideal submatrix( (coeff-icients({0}, det(M - t*id_(S^3))))_1,\n%% {1,2,3} ), but 'coeff-icients' is to be redesigned, and 'contract' is\n%% more self-explanatory, anyway.\n<<<X = ideal substitute(\n        contract(matrix{{t^2,t,1}}, det(t-M)),\n        {t => 0_S})>>>\n<<<closureOfOrbit == X>>>\n<<<clearAll>>>\nThis completes our solution.\\qed\n\\end{solution*}\n\nMore generally, Kostant shows that the set of all nilpotent elements\nin a complex semisimple Lie algebra\\index{Lie algebra} form an\nirreducible variety.  We refer the reader to Chriss and\nGinzburg~\\cite{SC:CV} for a proof of this result (Corollary~3.2.8) and\na discussion of its applications in representation theory.\n\n\n%%----------------------------------------------------------\n\\section{Singular Points}\n\nIn our third question, we study the singular locus\\index{singular\nlocus} of a family of elliptic curves\\index{elliptic curve}.\n\n\\begin{problem*} \nConsider a general form of degree $3$ in $\\bbbq[x,y,z]$:\n\\[\nF = ax^{3} + bx^{2}y + cx^{2}z + dxy^{2} + exyz + fxz^{2} + gy^{3} +\nhy^{2}z + iyz^{2} + jz^{3} \\enspace .\n\\]\nGive necessary and sufficient conditions in terms of $a, \\ldots, j$\nfor the cubic curve $\\Proj\\big( \\bbbq[x,y,z] / \\langle F \\rangle\n\\big)$ to have a singular point.\n\\end{problem*}\n\n\\begin{solution*}\nThe singular locus of $F$ is defined by a polynomial of degree $12$ in\nthe $10$ variables $a, \\dotsc, j$.  We calculate this polynomial in two\ndifferent ways.\n\nOur first method is an elementary but time consuming elimination.\nCarrying it out in \\Mtwo, we have\n<<<S = QQ[x, y, z, a..j, MonomialOrder => Eliminate 2];>>>\n<<<F = a*x^3+b*x^2*y+c*x^2*z+d*x*y^2+e*x*y*z+f*x*z^2+g*y^3+h*y^2*z+\n             i*y*z^2+j*z^3;>>>\n<<<partials = submatrix(jacobian matrix{{F}}, {0..2}, {0})>>>\n<<<singularities = ideal(partials) + ideal(F);>>>\n<<<elimDiscr = time ideal selectInSubring(1,gens gb singularities);>>>\n<<<elimDiscr = substitute(elimDiscr, {z => 1});>>>\nOn the other hand, there is also an elegant and more useful\ndeterminantal formula for this discriminant\\index{discriminant}; it is\na specialization of the formula (2.8) in section~3.2 of Cox, Little\nand O`Shea~\\cite{SC:CLO2}.  To apply this determinantal formula, we\nfirst create the coefficient matrix {\\tt A} of the partial derivatives\nof $F$.\n%% was A = (coeff-icients({0,1,2}, submatrix(jacobian matrix{{F}}, {0..2}, {0})))_1;\n%% but 'coeff-icients' is deprecated.\n<<<A = contract(matrix{{x^2,x*y,y^2,x*z,y*z,z^2}},\n        diff(transpose matrix{{x,y,z}},F))>>>\nWe also construct the coefficient matrix {\\tt B} of the partial\nderivatives of the Hessian\\index{hessian} of $F$.\n<<<hess = det submatrix(jacobian ideal partials, {0..2}, {0..2});>>>\n%% was B = (coeff-icients({0,1,2}, submatrix(jacobian matrix{{hess}}, {0..2}, {0})))_1;\n%% but 'coeff-icients' is deprecated.\n<<<B = contract(matrix{{x^2,x*y,y^2,x*z,y*z,z^2}},\n        diff(transpose matrix{{x,y,z}},hess))>>>\nTo obtain the discriminant, we combine these two matrices and take the\ndeterminant.\n<<<detDiscr = ideal det (A || B);>>>\nFinally, we check that our two discriminants are equal\n<<<detDiscr == elimDiscr>>>\nand examine the generator.\n<<<detDiscr_0>>>\n<<<numgens detDiscr>>>\n<<<# terms detDiscr_0>>>\n<<<clearAll>>>\nHence, the singular locus is given by a single polynomial of degree\n$12$ with $2040$ terms.\\qed\n\\end{solution*}\n\nFor a further discussion of singularities and discriminants see\nSection~V.3 in Eisenbud and Harris~\\cite{SC:EH}.  For information on\nresultants and discriminants see Chapter~2 in Cox, Little and\nO`Shea~\\cite{SC:CLO2}.\n\n\n%%----------------------------------------------------------\n\\section{Fields of Definition}\n\nSchemes\\index{scheme!over a number field} over non-algebraically\nclosed fields arise in number theory.  Our fourth problem looks at one\ntechnique for working with number fields in \\Mtwo.\n\n\\begin{problem*}[Exercise~II-6 in  \\cite{SC:EH}]\nAn inclusion of fields $K \\hookrightarrow L$ induces a map\n$\\mathbb{A}_{L}^{n} \\to \\mathbb{A}_{K}^{n}$.  Find the images in\n$\\mathbb{A}_{\\bbbq}^{2}$ of the following points of\n$\\mathbb{A}_{\\overline{\\bbbq}}^{2}$ under this map.\n\\begin{enumerate}\n\\item[$(1)$] $\\langle x - \\sqrt{2}, y - \\sqrt{2} \\rangle ;$\n\\item[$(2)$] $\\langle x - \\sqrt{2}, y - \\sqrt{3} \\rangle ;$\n\\item[$(3)$] $\\langle x - \\zeta, y - \\zeta^{-1} \\rangle$ where $\\zeta$\nis a $5$-th root of unity $;$\n\\item[$(4)$] $\\langle \\sqrt{2}x- \\sqrt{3}y \\rangle ;$\n\\item[$(5)$] $\\langle \\sqrt{2}x- \\sqrt{3}y-1 \\rangle$.\n\\end{enumerate}\n\\end{problem*}\n\n\\begin{solution*}\nThe images can be determined by using the following three step\nalgorithm: (1) replace the coefficients not contained in $K$ with\nindeterminates, (2) add the minimal polynomials of these coefficients\nto the given ideal in $\\mathbb{A}_{L}^{2}$, and (3) eliminate the new\nindeterminates.  Here are the five examples:\n<<<S = QQ[a,b,x,y, MonomialOrder => Eliminate 2];>>>\n<<<I1 = ideal(x-a, y-a, a^2-2);>>>\n<<<ideal selectInSubring(1, gens gb I1)>>>\n<<<I2 = ideal(x-a, y-b, a^2-2, b^2-3);>>>\n<<<ideal selectInSubring(1, gens gb I2)>>>\n<<<I3 = ideal(x-a, y-a^4, a^4+a^3+a^2+a+1);>>>\n<<<ideal selectInSubring(1, gens gb I3)>>>\n<<<I4 = ideal(a*x+b*y, a^2-2, b^2-3);>>>\n<<<ideal selectInSubring(1, gens gb I4)>>>\n<<<I5 = ideal(a*x+b*y-1, a^2-2, b^2-3);>>>\n<<<ideal selectInSubring(1, gens gb I5)>>>\n<<<clearAll>>>\n\\qed\n\\end{solution*}\n\nIt is worth noting that the points in $\\mathbb{A}_{\\bbbq}^{n}$ correspond\nto orbits of the action of ${\\rm Gal}(\\overline{\\bbbq}/\\bbbq)$ on the\npoints of $\\mathbb{A}_{\\overline{\\bbbq}}^{n}$.  For more examples and\ninformation, see section~II.2 in Eisenbud and Harris~\\cite{SC:EH}.\n\n\n%%----------------------------------------------------------\n\\section{Multiplicity}\n\nThe multiplicity\\index{multiplicity} of a zero-dimensional scheme $X$\nat a point $p \\in X$ is defined to be the length of the local ring\n$\\mathcal{O}_{X,p}$.  Unfortunately, we cannot work directly in the\nlocal ring in \\Mtwo.  What we can do, however, is to compute the\nmultiplicity by computing the degree of the component of $X$ supported\nat $p$; see page 66 in Eisenbud and Harris~\\cite{SC:EH}.\n\n\\begin{problem*}\nWhat is the multiplicity of the origin as a zero of the polynomial\nequations $x^{5}+y^{3}+z^{3} = x^{3}+y^{5}+z^{3} = x^{3}+y^{3}+z^{5} =\n0$?\n\\end{problem*}\n\n\\begin{solution*}\nIf $I$ is the ideal generated by $x^{5}+y^{3}+z^{3}$,\n$x^{3}+y^{5}+z^{3}$ and $x^{3}+y^{3}+z^{5}$ in $\\bbbq[x,y,z]$, then\nthe multiplicity of the origin is\n\\[\n\\dim_{\\bbbq} \\frac{\\bbbq[x,y,z]_{\\langle x,y,z \\rangle}}\n{I \\bbbq[x,y,z]_{\\langle x,y,z \\rangle}} \\, .\n\\]\nIt follows that the multiplicity is the vector space dimension of the\nring $\\bbbq[x,y,z] / \\varphi^{-1}(I \\bbbq[x,y,z]_{\\langle x,y,z\n\\rangle})$ where $\\varphi \\colon \\bbbq[x,y,z] \\to\n\\bbbq[x,y,z]_{\\langle x,y,z \\rangle}$ is the natural map.  Moreover,\nwe can express this using ideal quotients:\n\\[\n\\varphi^{-1}(I \\bbbq[x,y,z]_{\\langle x,y,z \\rangle}) \\,\\,= \\,\\,\n\\big(I : (I : \\langle x,y,z \\rangle^{\\infty})\\big) \\, .\n\\]\nCarrying out this calculation in \\Mtwo, we obtain:\n<<<S = QQ[x, y, z];>>>\n<<<I = ideal(x^5+y^3+z^3, x^3+y^5+z^3, x^3+y^3+z^5);>>>\n<<<multiplicity = degree(I : saturate(I))>>>\n<<<clearAll>>>\nThus, we conclude that the multiplicity is $27$.\\qed\n\\end{solution*}\n\nThere are algorithms (not yet implemented in \\Mtwo) for working\ndirectly in the local ring $\\bbbq[x,y,z]_{\\langle x,y,z \\rangle}$.  We\nrefer the interested reader to Chapter~4 in Cox, Little and\nO`Shea~\\cite{SC:CLO2}.\n\n\n%%----------------------------------------------------------\n\\section{Flat Families}\n\nNon-reduced schemes\\index{scheme!non-reduced} arise naturally as flat\nlimits\\index{flat limit} of a family of reduced\nschemes\\index{scheme!reduced}. Our next problem illustrates how a\nfamily of skew lines in $\\bbbp^{3}$ gives rise to a double line with\nan embedded point\\index{embedded point}.\n\n\\begin{problem*}[Exercise~III-68 in \\cite{SC:EH}]\nLet $L$ and $M $ be the lines in $\\bbbp^{3}_{k[t]}$ given by $x=y=0$\nand $x-tz = y+t^{2}w =0$ respectively.  Show that the flat limit as $t\n\\to 0$ of the union $L \\cup M$ is the double line $x^{2} = y = 0$ with\nan embedded point of degree $1$ located at the point $(0:0:0:1)$.\n\\end{problem*}\n\n\\begin{solution*}\nWe first find the flat limit by saturating\\index{saturation} the\nintersection ideal and setting $t = 0$.\n<<<PP3 = QQ[t, x, y, z, w];>>>\n<<<L = ideal(x, y);>>>\n<<<M = ideal(x-t*z, y+t^2*w);>>>\n<<<X = intersect(L, M);>>>\n<<<Xzero = trim substitute(saturate(X, t), {t => 0})>>>\nSecondly, we verify that this is the union of a double line and an\nembedded point of degree $1$.\n<<<Xzero == intersect(ideal(x^2, y), ideal(x, y^2, z))>>>\n<<<degree(ideal(x^2, y ) / ideal(x, y^2, z))>>>\n<<<clearAll>>>\n\\qed\n\\end{solution*}\n\nSection~III.3.4 in Eisenbud and Harris~\\cite{SC:EH} contains several\nother interesting limits of various flat families.\n\n\n%%----------------------------------------------------------\n\\section{B\\'{e}zout's Theorem}\n\nB\\'{e}zout's Theorem\\index{Bezout's Theorem@B\\'ezout's Theorem} --- Theorem~III-78 in\nEisenbud and Harris~\\cite{SC:EH} --- may fail without the\nCohen-Macaulay\\index{Cohen-Macaulay} hypothesis.  Our seventh problem\nis to demonstrate this.\n\n\\begin{problem*}[Exercise~III-81 in \\cite{SC:EH}]\nFind irreducible closed subvarieties $X$ and $Y$ in $\\bbbp^{4}$ such\nthat \n\\begin{align*}\n\\codim(X \\cap Y) &= \\codim(X) + \\codim(Y) \\\\\n\\deg(X \\cap Y) &> \\deg(X) \\cdot \\deg(Y) \\, .\n\\end{align*}\n\\end{problem*}\n\n\\begin{solution*}\nWe show that the assertion holds when $X$ is the cone over the\nnonsingular rational quartic curve\\index{rational quartic curve} in\n$\\bbbp^{3}$ and $Y$ is a two-plane passing through the vertex of the\ncone.  First, recall that the rational quartic curve is given by the\n$2 \\times 2$ minors of the matrix $\\left[ \\begin{smallmatrix} a &\nb^{2} & bd & c \\\\ b & ac & c^2 & d \\end{smallmatrix} \\right]$; see\nExercise~18.8 in Eisenbud~\\cite{SC:E}.  Thus, we have\n<<<S = QQ[a, b, c, d, e];>>>\n<<<IX = trim minors(2, matrix{{a, b^2, b*d, c},{b, a*c, c^2, d}})>>>\n<<<IY = ideal(a, d);>>>\n<<<codim IX + codim IY == codim (IX + IY)>>>\n<<<(degree IX) * (degree IY)>>>\n<<<degree (IX + IY)>>>\nwhich establishes the assertion.\\qed\n\\end{solution*}\n\nTo understand how this example works, it is enlightening to express\n$Y$ as the intersection of two hyperplanes; one given by $a = 0$ and\nthe other given by $d = 0$.  Intersecting $X$ with the first\nhyperplane yields\n<<<J = ideal mingens (IX + ideal(a))>>>\nHowever, this first intersection has an embedded point;\n<<<J == intersect(ideal(a, b*c, b^2, c^3-b*d^2), \n     ideal(a, d, b*c, c^3, b^3)) -- embedded point>>>\n<<<clearAll>>>\nThe second hyperplane passes through this embedded\npoint\\index{embedded point} which explains the extra intersection.\n\n\n%%----------------------------------------------------------\n\\section{Constructing Blow-ups}\n\nThe blow-up\\index{blow-up} of a scheme $X$ along a subscheme $Y$ can\nbe constructed from the Rees algebra\\index{Rees algebra} associated to\nthe ideal sheaf of $Y$ in $X$; see Theorem~IV-22 in Eisenbud and\nHarris~\\cite{SC:EH}.  Gr\\\"{o}bner basis techniques allow one to\nexpress the Rees algebra in terms of generators and relations.  We\nillustrate this method in the next solution.\n\n\\begin{problem*}[Exercises~IV-43 \\& IV-44 in \\cite{SC:EH}]\nFind the blow-up $X$ of the affine plane\\index{scheme!affine}\n$\\mathbb{A}^{2} = \\Spec\\big( \\bbbq[x, y] \\big)$ along the subscheme\ndefined by $\\langle x^{3}, xy, y^{2} \\rangle$.  Show that $X$ is\nnonsingular and its fiber over the origin is the union of two copies\nof $\\bbbp^{1}$ meeting at a point.\n\\end{problem*}\n\n\\begin{solution*}\nWe first provide a general function which returns the ideal of\nrelations for the Rees algebra.\n<<<blowUpIdeal = (I) -> (\n     r := numgens I;\n     S := ring I;\n     n := numgens S;\n     K := coefficientRing S;\n     tR := K[t, gens S, vars(0..r-1), \n               MonomialOrder => Eliminate 1];\n     f := map(tR, S, submatrix(vars tR, {1..n}));\n     F := f(gens I);\n     J := ideal apply(1..r, j -> (gens tR)_(n+j)-t*F_(0,(j-1)));\n     L := ideal selectInSubring(1, gens gb J);\n     R := K[gens S, vars(0..r-1)];\n     g := map(R, tR, 0 | vars R);\n     trim g(L));>>>\nNow, applying the function to our specific case yields: \n<<<S = QQ[x, y];>>>\n<<<I = ideal(x^3, x*y, y^2);>>>\n<<<J = blowUpIdeal(I)>>>\nTherefore, the blow-up of the affine plane along the given subscheme\nis\n\\[\nX = \\Proj\\left( \\frac{(\\bbbq[x,y])[a,b,c]}{\\langle yb-xc, xb^{2}-ac,\nx^{2}b-ya, x^{3}c-y^{2}a \\rangle} \\right) \\, .\n\\]\nUsing \\Mtwo, we can also verify that the scheme $X$ is\nnonsingular\\index{singular locus};\n<<<J + ideal jacobian J == ideal gens ring J>>>\n<<<clearAll>>>\nSince we have\n\\[\n\\frac{(\\bbbq[x,y])[a,b,c]}{\\langle yb-xc, xb^{2}-ac, x^{2}b-ya,\nx^{3}c-y^{2}a \\rangle} \\otimes \\frac{\\bbbq[x,y]}{\\langle x, y \\rangle}\n\\cong \\frac{\\bbbq[a,b,c]}{\\langle ac \\rangle} \\, ,\n\\]\nthe fiber over the origin $\\langle x,y \\rangle$ in $\\mathbb{A}^{2}$ is\nclearly a union of two copies of $\\bbbp^{1}$ meeting at one point.  In\nparticular, the exceptional fiber is not a projective space.\\qed\n\\end{solution*}\n\nMany other interesting blow-ups can be found in section~II.2 in\nEisenbud and Harris~\\cite{SC:EH}.\n\n\n%%----------------------------------------------------------\n\\section{A Classic Blow-up}\n\nWe consider the blow-up\\index{blow-up} of the projective plane\n$\\bbbp^{2}$ at a point.\n\n\\vbox{\n\\begin{problem*}\nShow that the following varieties are isomorphic.\n\\begin{enumerate}\n\\item[$(a)$] the image of the rational map from $\\bbbp^{2}$ to\n$\\bbbp^{4}$ given by\n\\[\n(r:s:t) \\mapsto (r^{2}:s^{2}:rs:rt:st) \\, ;\n\\]\n\\item[$(b)$] the blow-up of the plane $\\bbbp^{2}$ at the point\n$(0:0:1)$;\n\\item[$(c)$] the determinantal variety\\index{determinantal variety}\ndefined by the $2 \\times 2$ minors of the matrix $\\left[\n\\begin{smallmatrix} a & c & d \\\\ b & d & e \\end{smallmatrix} \\right]$\nwhere $\\bbbp^{4} = \\Proj\\big( k[a,b,c,d,e] \\big)$.\n\\end{enumerate}\nThis surface is called the {\\em cubic scroll}\\index{cubic scroll} in\n$\\bbbp^{4}$.\n\\end{problem*}\n}\n\n\\begin{solution*}\nWe find the ideal in part~$(a)$ by elimination\ntheory\\index{elimination theory}.\n<<<PP4 = QQ[a..e];>>>\n<<<S = QQ[r..t, A..E, MonomialOrder => Eliminate 3];>>>\n<<<I = ideal(A - r^2, B - s^2, C - r*s, D - r*t, E - s*t);>>>\n<<<phi = map(PP4, S, matrix{{0_PP4, 0_PP4, 0_PP4}} | vars PP4)>>>\n<<<surfaceA = phi ideal selectInSubring(1, gens gb I)>>>\nNext, we determine the surface in part~$(b)$.  We construct the ideal\ndefining the blow-up of $\\bbbp^{2}$ \n<<<R = QQ[t, x, y, z, u, v, MonomialOrder => Eliminate 1];>>>\n<<<blowUpIdeal = ideal selectInSubring(1, gens gb ideal(u-t*x, \n     v-t*y))>>>\nand embed it in $\\bbbp^{2} \\times \\bbbp^{1}$.\n<<<PP2xPP1 = QQ[x, y, z, u, v];>>>\n<<<embed = map(PP2xPP1, R, 0 | vars PP2xPP1);>>>\n<<<blowUp = PP2xPP1 / embed(blowUpIdeal);>>>\nWe then map this surface into $\\bbbp^{5}$ using the Segre\nembedding\\index{Segre embedding}.\n<<<PP5 = QQ[A .. F];>>>\n<<<segre = map(blowUp, PP5, matrix{{x*u,y*u,z*u,x*v,y*v,z*v}});>>>\n<<<ker segre>>>\nNote that the image under the Segre map lies on a hyperplane in\n$\\bbbp^{5}$.  To get the desired surface in $\\bbbp^{4}$, we project\n<<<projection = map(PP4, PP5, matrix{{a, c, d, c, b, e}})>>>\n<<<surfaceB = trim projection ker segre>>>\nFinally, we compute the surface in part~$(c)$.\n<<<determinantal = minors(2, matrix{{a, c, d}, {b, d, e}})>>>\n<<<sigma = map( PP4, PP4, matrix{{d, e, a, c, b}});>>>\n<<<surfaceC = sigma determinantal>>>\nBy incorporating a permutation of the variables into definition of\n{\\tt surfaceC}, we obtain the desired isomorphisms\n<<<surfaceA == surfaceB>>>\n<<<surfaceB == surfaceC>>>\n<<<clearAll>>>\nwhich completes the solution.\\qed\n\\end{solution*}\n\nFor more information of the geometry of rational normal scrolls, see\nLecture~8 in Harris~\\cite{SC:H}.\n\n\n%%----------------------------------------------------------\n\\section{Fano Schemes}\n\nOur final example concerns the family of Fano schemes\\index{Fano\nscheme} associated to a flat family of quadrics.\nRecall that the $k$-th Fano scheme $F_{k}(X)$ of a\nscheme $X \\subseteq \\bbbp^{n}$ is the subscheme of\nthe Grassmannian parametrizing $k$-planes\ncontained in $X$.\n\n\\begin{problem*}[Exercise~IV-69 in \\cite{SC:EH}]\nConsider the one-parameter family\\index{one-parameter family} of\nquadrics tending to a double plane with equation\n\\[ \nQ = V(tx^{2}+ty^{2}+tz^{2}+w^{2}) \\subseteq \\bbbp^{3}_{\\bbbq[t]} =\n\\Proj\\big(\\bbbq[t][x,y,z,w]\\big) \\enspace .\n\\]\nWhat is the flat limit\\index{flat limit} of the Fano schemes\n$F_{1}(Q_{t})$?\n\\end{problem*}\n\n\\begin{solution*}\nWe first compute the ideal defining $F_{1}(Q_{t})$, the scheme\nparametrizing lines in $Q$.\n<<<PP3 = QQ[t, x, y, z, w];>>>\n<<<Q = ideal( t*x^2+t*y^2+t*z^2+w^2 );>>>\nTo parametrize a line in our projective space, we introduce\nindeterminates $u, v$ and $A, \\dotsc, H$.\n<<<R = QQ[t, u, v, A .. H];>>>\nWe then make a map {\\tt phi} from {\\tt PP3} to {\\tt R} sending the\nvariables to the coordinates of the general point on a line.\n<<<phi = map(R, PP3, matrix{{t}} | \n        u*matrix{{A, B, C, D}} + v*matrix{{E, F, G, H}});>>>\n<<<imageFamily = phi Q;>>>\nFor a line to belong to $Q$, the {\\tt imageFamily} must vanish\nidentically.  In other words, $F_{1}(Q)$ is defined by the\ncoefficients of the generators of {\\tt imageFamily}.\n%% removing a final use of 'coefficients'\n%% coeffOfFamily = (coefficients ({1,2}, gens imageFamily))_1;\n<<<coeffOfFamily = contract(matrix{{u^2,u*v,v^2}}, gens imageFamily)>>>\nSince we don't need the variables $u$ and $v$, we get rid of them.\n<<<S = QQ[t, A..H];>>>\n<<<coeffOfFamily = substitute(coeffOfFamily, S);>>>\n<<<Sbar = S / (ideal coeffOfFamily);>>>\nNext, we move to the Grassmannian\\index{Grassmannian} $\\mathbb{G}(1,3)\n\\subset \\bbbp^{5}$.  Recall the homogeneous coordinates on\n$\\bbbp^{5}$ correspond to the $2 \\times 2$ minors of a $2 \\times 4$\nmatrix.  We obtain these minors using the {\\tt exteriorPower} function\nin \\Mtwo.\n<<<psi = matrix{{t}} | exteriorPower(2, \n            matrix{{A, B, C, D}, {E, F, G, H}})>>>\n<<<PP5 = QQ[t, a..f];>>>\n<<<fanoOfFamily = trim ker map(Sbar, PP5, psi);>>>\nNow, to answer the question, we determine the limit as $t$ tends to $0$.\n<<<zeroFibre = trim substitute(saturate(fanoOfFamily, t), {t=>0})>>>\nLet's transpose the matrix of generators so all of its elements are visible\non the printed page.\n<<<transpose gens zeroFibre>>>\nWe see that $F_{1}(Q_{0})$ is supported on the plane conic $\\langle d,\ne, f, a^{2}+b^{2}+c^{2} \\rangle$.  However, $F_{1}(Q_{0})$ is not\nreduced\\index{scheme!non-reduced}; it has\nmultiplicity\\index{multiplicity} two.  On the other hand, the generic\nfiber is\n<<<oneFibre = trim substitute(saturate(fanoOfFamily, t), {t => 1})>>>\n<<<oneFibre == intersect(ideal(c-d, b+e, a-f, d^2+e^2+f^2), \n     ideal(c+d, b-e, a+f, d^2+e^2+f^2))>>>\nHence, for $t \\neq 0$, $F_{1}(Q_{t})$ is the union of two conics lying\nin complementary planes and $F_{1}(Q_{0})$ is the double conic\nobtained when the two conics move together.\\qed\n\\end{solution*}\n\n% Local Variables:\n% mode: latex\n% mode: reftex\n% tex-main-file: \"chapter-wrapper.tex\"\n% reftex-keep-temporary-buffers: t\n% reftex-use-external-file-finders: t\n% reftex-external-file-finders: ((\"tex\" . \"make FILE=%f find-tex\") (\"bib\" . \"make FILE=%f find-bib\"))\n% End:\n", "meta": {"hexsha": "fb590013cbdb2d834a3a89d7b5775d40072e164a", "size": 26542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/ComputationsBook/chapters/schemes/chapter.tex", "max_stars_repo_name": "d-torrance/Macaulay2-web-site", "max_stars_repo_head_hexsha": "edb1d0b607c5aa00ffbcf403f2403961c6d6083a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-27T08:01:17.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-27T08:01:17.000Z", "max_issues_repo_path": "Book/ComputationsBook/chapters/schemes/chapter.tex", "max_issues_repo_name": "d-torrance/Macaulay2-web-site", "max_issues_repo_head_hexsha": "edb1d0b607c5aa00ffbcf403f2403961c6d6083a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-17T19:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-07T01:08:10.000Z", "max_forks_repo_path": "Book/ComputationsBook/chapters/schemes/chapter.tex", "max_forks_repo_name": "d-torrance/Macaulay2-web-site", "max_forks_repo_head_hexsha": "edb1d0b607c5aa00ffbcf403f2403961c6d6083a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-01-08T16:48:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T21:19:02.000Z", "avg_line_length": 41.2783825816, "max_line_length": 101, "alphanum_fraction": 0.6474267199, "num_tokens": 8844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926008, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.6489439705925032}}
{"text": "\\section{Linear transformations defined on a basis}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Check whether two linear transformations are equal by\n    considering their action on a spanning set.\n  \\item Specify a linear transformation by considering its action on a\n    basis.\n  \\end{enumerate}\n\\end{outcome}\n\nRecall that, by definition, two linear transformations $S,T:V\\to W$\nare equal if and only if for all $\\vect{v}\\in V$, we have\n$S(\\vect{v}) = T(\\vect{v})$.  However, this is not a very practical\nway of checking whether $S=T$, as it theoretically requires checking\n$S(\\vect{v}) = T(\\vect{v})$ for each one of infinitely many vectors\n$\\vect{v}$. The following proposition states that it is sufficient to\ncheck the actions of $S$ and $T$ on a spanning set of vectors.\n\n\\begin{proposition}{Equality of linear transformations}{transformation-spanning-set}\n  Let $V$ and $W$ be vector spaces over a field $K$, and let\n  $S,T:V\\to W$ be linear transformations. Moreover, let $X\\subseteq V$\n  be a spanning set of $V$, i.e., such that $V=\\sspan X$.\n  If $S(\\vect{v}) = T(\\vect{v})$ for all $\\vect{v}\\in X$, then $S=T$.%\n  \\index{linear transformation!equality of}%\n  \\index{equality!of linear transformations}\n\\end{proposition}\n\n\\begin{proof}\n  Assume that $S(\\vect{v}) = T(\\vect{v})$ holds for all $\\vect{v}\\in X$. To\n  show that $S=T$, let $\\vect{u}\\in V$ be an arbitrary vector. Since\n  $X$ is a spanning set, we can write\n  $\\vect{u}=a_1\\vect{v}_1+\\ldots+a_n\\vect{v}_n$, for some\n  $\\vect{v}_1,\\ldots,\\vect{v}_n\\in X$ and $a_1,\\ldots,a_n\\in K$.\n  By assumption, $S(\\vect{v}_i) = T(\\vect{v}_i)$ for all $i$, because\n  $\\vect{v}_i\\in X$. Then we have\n  \\begin{eqnarray*}\n    S(\\vect{u})\n    &=& S(a_1\\vect{v}_1+\\ldots+a_n\\vect{v}_n) \\\\\n    &=& a_1S(\\vect{v}_1)+\\ldots+a_nS(\\vect{v}_n) \\\\\n    &=& a_1T(\\vect{v}_1)+\\ldots+a_nT(\\vect{v}_n) \\\\\n    &=& T(a_1\\vect{v}_1+\\ldots+a_n\\vect{v}_n) \\\\\n    &=& T(\\vect{u}).\n  \\end{eqnarray*}\n  Since $\\vect{u}\\in V$ was arbitrary, it follows that $S=T$.\n\\end{proof}\n\nTherefore, if we know how a linear transformation acts on a spanning\nset (and in particular, on a basis), then we know how it acts on the\nentire space. There is also a kind of converse to this: given a basis\nof $V$, we can map the basis vectors to any elements of $W$ we like,\nand this will always determine a unique linear transformations. This\nis the content of the following theorem.\n\n\\begin{theorem}{Linear transformation defined on a basis}{transformation-basis}\n  Suppose $V$ and $W$ are vector spaces over a field $K$. Suppose\n  $\\vect{v}_1,\\vect{v}_2,\\ldots,\\vect{v}_n$ is a basis of $V$, and\n  $\\vect{w}_1,\\vect{w}_2,\\ldots,\\vect{w}_n$ are any vectors in $W$\n  (which may or may not be distinct). Then there exists a unique\n  linear transformation%\n  \\index{linear transformation!defined on a basis}\n  $T:V\\to W$ such that\n  \\begin{equation*}\n    T(\\vect{v}_1) = \\vect{w}_1,\n    \\quad\n    T(\\vect{v}_2) = \\vect{w}_2,\n    \\quad\\ldots\\quad\n    T(\\vect{v}_n) = \\vect{w}_n.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  To show that such a linear transformation $T$ exists, we first\n  define a function $T:V\\to W$ as follows. Given any $\\vect{v}\\in V$,\n  there exists a unique set of coordinates $a_1,\\ldots,a_n\\in K$ such\n  that\n  \\begin{equation*}\n    \\vect{v} = a_1\\vect{v}_1 + \\ldots + a_n\\vect{v}_n.\n  \\end{equation*}\n  Then define\n  \\begin{equation*}\n    T(\\vect{v}) = a_1\\vect{w}_1 + \\ldots + a_n\\vect{w}_n.\n  \\end{equation*}\n  This defines a function $T:V\\to W$.  Next, we must check that $T$ is\n  linear. To show that $T$ preserves addition, consider\n  $\\vect{v},\\vect{v}'\\in V$, with\n  $\\vect{v} = a_1\\vect{v}_1 + \\ldots + a_n\\vect{v}_n$ and\n  $\\vect{v}' = b_1\\vect{v}_1 + \\ldots + b_n\\vect{v}_n$.  Then\n  \\begin{eqnarray*}\n    T(\\vect{v}+\\vect{v}')\n    &=& T((a_1+b_1)\\vect{v}_1 + \\ldots + (a_n+b_n)\\vect{v}_n) \\\\\n    &=& (a_1+b_1)\\vect{w}_1 + \\ldots + (a_n+b_n)\\vect{w}_n \\\\\n    &=& (a_1\\vect{w}_1 + \\ldots + a_n\\vect{w}_n)\n        + (b_1\\vect{w}_1 + \\ldots + b_n\\vect{w}_n) \\\\\n    &=& T(\\vect{v}) + T(\\vect{v}').\n  \\end{eqnarray*}\n  Therefore, $T$ preserves addition. To show that $T$ preserves scalar\n  multiplication, consider $\\vect{v} = a_1\\vect{v}_1 + \\ldots +\n  a_n\\vect{v}_n$ and $k\\in K$. Then\n  \\begin{eqnarray*}\n    T(k\\vect{v})\n    &=& T(ka_1\\vect{v}_1 + \\ldots + ka_n\\vect{v}_n) \\\\\n    &=& ka_1\\vect{w}_1 + \\ldots + ka_n\\vect{w}_n \\\\\n    &=& k(a_1\\vect{w}_1 + \\ldots + a_n\\vect{w}_n) \\\\\n    &=& kT(\\vect{v}).\n  \\end{eqnarray*}\n  Therefore, $T$ preserves scalar multiplication. It follows that $T$\n  is linear. Next, we must show that $T$ satisfies the condition of\n  the theorem, i.e., that $T(\\vect{v}_i) = \\vect{w}_i$ for each $i$.\n  But this is clearly the case, because in this case, $a_i=1$ and\n  $a_j=0$ for all $j\\neq i$. We have shown that there exists a linear\n  function $T$ satisfying all of the conditions required by the\n  theorem.\n\n  Finally, the only thing left to show is uniqueness. But this follows\n  from Proposition~\\ref{prop:transformation-spanning-set}. Namely, if\n  $T'$ is another linear transformation such that\n  $T'(\\vect{v}_i) = \\vect{w}_i$ for all $i$, then $T$ and $T'$ agree\n  on $\\vect{v}_1,\\ldots,\\vect{v}_n$, which is a basis and hence a\n  spanning set. By Proposition~\\ref{prop:transformation-spanning-set},\n  $T=T'$.\n\\end{proof}\n\n\\begin{example}{Linear transformation defined on a basis}{transformation-basis}\n  Recall that $\\set{x^2, (x+1)^2, (x+2)^2}$ is a basis of $\\Poly_2$.\n  Consider the linear function $T:\\Poly_2\\to\\Mat_{22}$ defined by\n  \\begin{equation*}\n    T(x^2) = \\begin{mymatrix}{rr} 1 & 1 \\\\ 0 & 0 \\end{mymatrix},\\quad\n    T((x+1)^2) = \\begin{mymatrix}{rr} 0 & 1 \\\\ 0 & 1 \\end{mymatrix},\\quad\n    T((x+2)^2) = \\begin{mymatrix}{rr} 0 & 0 \\\\ 1 & 1 \\end{mymatrix}.\n  \\end{equation*}\n  Find $T(4x)$.\n\\end{example}\n\n\\begin{solution}\n  Let $\\vect{v}_1=x^2$, $\\vect{v}_2=(x+1)^2$, $\\vect{v}_3=(x+2)^2$,\n  $\\vect{w}_1 = \\begin{mysmallmatrix}{rr} 1 & 1 \\\\ 0 & 0 \\end{mysmallmatrix}$,\n  $\\vect{w}_2 = \\begin{mysmallmatrix}{rr} 0 & 1 \\\\ 0 & 1 \\end{mysmallmatrix}$,\n  and\n  $\\vect{w}_3 = \\begin{mysmallmatrix}{rr} 0 & 0 \\\\ 1 & 1 \\end{mysmallmatrix}$.\n  We must first find $a,b,c$ such that\n  $4x=a\\vect{v}_1+b\\vect{v}_2+c\\vect{v}_3$. We do this by solving a\n  system of equations, using the same method as in\n  Example~\\ref{exa:linear-combination-polynomials}. We find that\n  $a=-3$, $b=4$, and $c=-1$.  Therefore\n  \\begin{equation*}\n    T(4x)\n    ~=~ T(-3\\vect{v}_1 + 4\\vect{v}_2 - \\vect{v}_3)\n    ~=~ -3\\vect{w}_1 + 4\\vect{w}_2 - \\vect{w}_3\n    ~=~ \\begin{mymatrix}{rr}\n      -3 & 1 \\\\\n      -1 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "3ae55fc0453dd40b2e63fd057cb2979e8db6b821", "size": 6641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/LinearTransformationsGeneral-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/LinearTransformationsGeneral-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/LinearTransformationsGeneral-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": 42.2993630573, "max_line_length": 84, "alphanum_fraction": 0.6419213974, "num_tokens": 2507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6489391921037119}}
{"text": "\\section{The Structure Theorem}\r\nUntil further notice, we take our ring to be a ED and we denote its Euclidean function by $\\phi:R^\\times\\to\\mathbb Z_{\\ge 0}$.\r\nlet $A$ be an $m\\times n$ matrix with entries in $R$.\r\n\\begin{definition}\r\n    The elementary row operations are as follows:\\\\\r\n    1. Add $\\lambda\\in R$ times the $j^{th}$ row to the $i^{th}$ row for $i\\neq j$.\\\\\r\n    2. Swap the $i^{th}$ and $j^{th}$ row.\\\\\r\n    3. Multiply the $i^{th}$ row by a unit $u$.\r\n\\end{definition}\r\nNote that all these operations are reversible.\r\nAlso, each of the operations may be realized by multiplying in the left by an $m\\times m$ invertible matrix.\r\nTo wit, the first operation is the left multiplication of the matrix $I+\\lambda E_{ij}$ where $E_{ij}$ is the matrix with $1$ on the $(i,j)$ entry and $0$ otherwise.\r\nThe second is $I+E_{ij}+E_{ji}-E_{ii}-E_{jj}$ and the third is $I+(u-1)E_{ii}$.\r\nWe can similarly define the column operations, and the realization becomes the matrix multiplication on the right by an $n\\times n$ invertible matrix analogous to before.\r\n\\begin{definition}\r\n    Two $m\\times n$ matrices $A,B$ are equivalent if there is a sequence of elementary row and column operations taking $A$ to $B$.\r\n\\end{definition}\r\nIt is obvious that this is an equivalence relation due to reversibility.\r\nSo if $A,B$ are equivalent, there exists invertible square matrices $P,Q$ with $B=QAP$.\r\n\\begin{theorem}[Smith Normal Form]\r\n    An $m\\times n$ matrix $A=(a_{ij})$ with entries in $R$ is equivalent to a diagonal matrix of the form\r\n    $$\\begin{pmatrix}\r\n        d_1&&&&&&\\\\\r\n        &d_2&&&&&\\\\\r\n        &&\\ddots&&&&\\\\\r\n        &&&d_t&&&\\\\\r\n        &&&&0&&\\\\\r\n        &&&&&\\ddots&\\\\\r\n        &&&&&&0\r\n    \\end{pmatrix}$$\r\n    where $d_i\\neq 0$ for all $i$ and $d_1|d_2|\\cdots |d_t$.\r\n\\end{theorem}\r\nThe $d_i$'s are called covariant factors and are unique up to associates (show later).\r\n\\begin{proof}\r\n    If $A=0$ then we are done.\r\n    So assume that $a_{11}\\neq 0$.\r\n    Suppose $a_{11}\\nmid a_{1j}$ for some $j\\ge 2$, then we use the Euclidean algorithm to get $a_{1j}=qa_{11}+r$ with $q,r\\in R$ and $\\phi(r)<\\phi(a_{11})$.\r\n    So we substract $q$ times the first column from the $j^{th}$ column and swap them.\r\n    This makes the top left entry $r$.\r\n    Likewise, we can do the same thing if $a_{11}\\nmid a_{i1}$ for some $i\\ge 2$ by row operations.\r\n    The cases above each decrease the top left entry (in terms of its value in the Euclidean function), thus it must eventually stops, at which time $a_{11}$ divides everything in the first row or the first column.\r\n    Then substracting multiples of the first row or first column can clear up every other entry in the first column or first row except $a_{11}$.\r\n    Now if $a_{11}$ does not divide $a_{ij}$ for $i,j\\ge 2$, then add the $i^{th}$ row to the first row, and so we can do the same column operations to decrease $\\phi(a_{11})$ further till it terminates.\r\n    Do this over and over again (but finitely many times) we can get $a_{11}|a_{ij}$ for any $i,j\\ge 2$ and $a_{ij}=0$ whenever $i\\neg j$ and one of $i,j$ is $1$.\r\n    We rename $a_{11}$ as $d_1$ and repeat the process on the smaller matrix by removing the first row and first column to give the existence.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A $k\\times k$ minor of a matrix $A$ is the determinant of a $k\\times k$ submatrix of $A$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    For a matrix $A$ over a ring $R$, we define the $k^{th}$ Fitting ideal $\\operatorname{Fit}_k(A)$ be the ideal generated by all the $k\\times k$ minors of $A$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    If $A,B$ are equivalent matrices, then $\\operatorname{Fit}_k(A)=\\operatorname{Fit}_k(B)$ for any $k$ (such that the Fitting ideal makes sense).\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suffices to show that the elementary operations do not change the Fitting ideal.\r\n    The second and third row operations are trivial.\r\n    For the first kind of row operation, suppose we add $\\lambda$ times the second row to the first row so that $A=(a_{ij})$ becomes\r\n    $$A'=\\begin{pmatrix}\r\n        a_11+\\lambda a_{21}&a_{12}+\\lambda a_{22}&\\dots&a_{1n}+\\lambda a_{2n}\\\\\r\n        a_{21}&a_{22}&\\dots&a_{2n}\\\\\r\n        \\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n    \\end{pmatrix}$$\r\n    Let $C$ be a $k\\times k$ submatrix of $A$ and $C'$ be its correspondent submatrix in $A'$.\r\n    If $C$ does not intersect the first row, then $\\det C=\\det C'$.\r\n    If $C$ intersect both the first and second row, we also have $\\det C=\\det C'$ since its simply a row operation on the $k\\times k$ submatrix.\r\n    If $C$ intersects the first but not the second row, then by expanding along the first row, the determinant of $\\det C'$ would be $\\det C+\\lambda\\det D$ for some other $k\\times k$ submatrix of $A$.\r\n    So $\\det C'\\in \\operatorname{Fit}_k(A)$, so $\\operatorname{Fit}_k(A')\\subset \\operatorname{Fit}_k(A)$.\r\n    Since row operations are reversible, we also have the reverse inclusion.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    The covarient factors are unique up to associates.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Look at the Fitting ideals.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the following matrix (here $\\to$ represents row/column operations)\r\n    $$A=\\begin{pmatrix}\r\n        2&-1\\\\\r\n        1&2\r\n    \\end{pmatrix}\\to\\begin{pmatrix}\r\n        1&-1\\\\\r\n        3&2\r\n    \\end{pmatrix}\\to\\begin{pmatrix}\r\n        1&0\\\\\r\n        3&5\r\n    \\end{pmatrix}\\to\\begin{pmatrix}\r\n        1&0\\\\\r\n        0&5\r\n    \\end{pmatrix}$$\r\n    One can also get its Smith normal form by considering the minors.\r\n    Indeed, $\\operatorname{Fit}_1(A)=(1)$, so $d_1=\\pm 1$.\r\n    Also $\\operatorname{Fit}_2(A)=(5)$, hence $d_2=\\pm 5$.\r\n    So we obtain the Smith normal form.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Let $R$ be an Euclidean domain and $N$ is an $R$-submodule of $R^n$, then there is a free basis $x_1,\\ldots,x_m$ of $R^m$ such that $N$ is generated as an $R$-module by $d_1x_1,\\ldots,d_tx_t$ for some $t\\le m$ and $d_1|d_2|\\cdots|d_t$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $R$ is a ED hence a PID, hence $N$ is generated by some $y_1,\\ldots,y_n$ for some $n\\le m$.\r\n    Now each $y_i$ is in $R^n$, so we can form an $n\\times n$ matrix $A$ whose columns are the $y_i$'s.\r\n    By the preceding theorem, $A$ is equivalent to $A'=\\operatorname{diag}(d_1,\\ldots,d_t,0,\\ldots,0)$ with $t\\le n$ and $d_1|d_2|\\ldots|d_t$.\r\n    Now $A'$ is obtained from $A$ by elementary row and column operations.\r\n    Each row operation corresponds to changing of our choice of free basis for $R^n$, and every column operation changes the generating set for $R^n$.\r\n    So after changing the free basis for $R^n$ to, say, $x_1,\\ldots, x_n$, then $N$ is generated by $d_1x_1,\\ldots,d_tx_t$.\r\n\\end{proof}\r\n\\begin{theorem}[Structure Theorem]\r\n    Let $R$ be a Euclidean Domain and $M$ a finitely-generated $R$-module, then $M\\cong R/(d_1)\\oplus\\cdots\\oplus R/(d_t)\\oplus R\\oplus\\cdots\\oplus R$ for some $d_i\\in R$ and $d_1|d_2|\\cdots|d_t$.\r\n\\end{theorem}\r\nThese $d_i$'s are called invariant factors.\r\n\\begin{proof}\r\n    Since $M$ is finitely generated, then we can find a surjective $R$-module map $\\phi:R^m\\to M$ for some $m$.\r\n    Then $M\\cong R^m/\\ker\\phi$, but by the preceding theorem, there exists a free basis $x_1,\\ldots,x_n$ for $R^m$ such that $N=\\ker\\phi=Rd_1x_1+\\cdots Rd_tx_t$ for $d_1|d_2|\\cdots|d_t$, hence\r\n    $$M\\cong\\frac{R\\oplus R\\oplus\\cdots\\oplus R\\oplus R\\oplus\\cdots\\oplus R}{Rd_1\\oplus Rd_2\\oplus\\cdots\\oplus Rd_t\\oplus 0\\oplus\\cdots\\oplus 0}\\cong R/(d_1)\\oplus\\cdots\\oplus R/(d_t)\\oplus R\\oplus\\cdots\\oplus R$$\r\n    which is what we wanted.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $M$ be an $R$-module.\r\n    An element $m\\in M$ is called torsion if $\\exists r\\in R\\setminus\\{0\\},rm=0$.\\\\\r\n    $M$ is called a torsion module if every $m\\in M$ is torsion.\r\n    $M$ is called torsion-free if the only torsion is $0$.\r\n\\end{definition}\r\n\\begin{corollary}\r\n    Let $R$ be an Euclidean domain, then any finitely generated torsion-free $R$-module is free.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    By the preceding theorem $M\\cong R/(d_1)\\oplus\\cdots\\oplus R/(d_t)\\oplus R\\oplus\\cdots\\oplus R$, but as $M$ is torsion-free, it cannot contain any of $R/(d_i)$ as $R$-submodule as they would contain torsions.\r\n    Hence $M\\cong R\\oplus\\cdots\\oplus R$, therefore $M$ is free.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The structure theorem in fact holds whenever $R$ is a PID.\r\n    Also, there is also a uniqueness statement in the structure theorem: Suppose no $d_i$'s is a unit (otherwise they only contribute $0$ factors to the product), then the module $M$ uniquely determines $d_1,\\ldots,d_t$.\r\n\\end{remark}\r\n\\begin{example}\r\n    Consider an abelian groupn $G$ generated by $a,b$ subject to relations $2a+b=-a+2b=0$.\r\n    So $G\\cong\\mathbb Z^2/N$ where $N$ is generated by $(2,1),(-1,2)$, so we take (as in the proof of the structure theorem)\r\n    $$A=\\begin{pmatrix}\r\n        2&-1\\\\\r\n        1&2\r\n    \\end{pmatrix}\\to\\begin{pmatrix}\r\n        1&0\\\\\r\n        0&5\r\n    \\end{pmatrix}$$\r\n    as seen before.\r\n    So we can change basis for $\\mathbb Z^2$ to generate $N$ by $(1,0),(0,5)$, hence $G\\cong\\mathbb Z\\oplus\\mathbb Z/(\\mathbb Z\\oplus 5\\mathbb Z)\\cong\\mathbb Z/5\\mathbb Z$.\r\n\\end{example}\r\nMore generally, for finitely generated abelian groups, we have the following:\r\n\\begin{theorem}\r\n    Any finitely generated abelian group $G$ is isomorphic to\r\n    $$\\mathbb Z/d_1\\mathbb Z\\oplus\\cdots\\oplus\\mathbb Z/d_t\\mathbb Z\\oplus\\mathbb Z^r$$\r\n    where $r\\ge 0$ and $d_1|d_2|\\cdots|d_t$.\r\n\\end{theorem}\r\nThe $r$ here stands for the rank of the group.\r\n\\begin{proof}\r\n    Take $R=\\mathbb Z$ in the structure theorem.\r\n\\end{proof}\r\nIn the special case that $G$ is finite, we immediately obtain Theorem \\ref{fin_abe_struct}.\r\n\\begin{remark}\r\n    Let $A,B$ be square matrices over $R$, then $\\det (AB)=\\det A\\det B$, also $\\operatorname{adj}(A)A=A\\operatorname{adj}(A)=\\det(A)I$.\r\n    In particular, $A$ is invertible iff $\\det A$ is a unit.\r\n\\end{remark}\r\n\\begin{theorem}[Cayley-Hamilton]\r\n    Let $A=(a_{ij})$ be a $n\\times n$ matrix over a field $F$.\r\n    Let $\\chi_A(X)=\\det (XI-A)\\in F[X]$, then $\\chi_A(A)=0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider $V=F^n$ as a $F[X]$-module. with $X$ acting as $A$, i.e. $f(X)\\cdot v=f(A)v$.\r\n    Let $e_1,\\ldots,e_n$ be the standard basis for $F^n$, so for any $j$, $X\\cdot e_j=\\sum_{i=1}^na_{ij}e_i$, hence\r\n    $$(XI-A)\\begin{pmatrix}\r\n        e_1\\\\\r\n        \\vdots\\\\\r\n        e_n\r\n    \\end{pmatrix}=0$$\r\n    By multiplying both sides by the adjugate of $XI-A$, we know that for any $i$,\r\n    $$\\chi_A(X)\\cdot e_i=\\det(XI-A)\\cdot e_i=0\\implies\\chi_A(A)e_i=0$$\r\n    But this can only happen when $\\chi_A(A)=0$.\r\n\\end{proof}\r\nRecall that we have mentioned Theorem \\ref{classify_fin_abe}, which is yet another way of classifying the finite abelian groups by writing it as a product of cyclic $p$-groups.\r\nIndeed, we can achieve this by generalising our structure theorem one step further.\r\n\\begin{lemma}\r\n    Let $R$ be a PID and $a,b\\in R$ has $\\gcd(a,b)=1$ (up to associates), then there is an isomorphism of $R$-modules\r\n    $$R/(ab)\\cong R/(a)\\oplus R/(b)$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Since $R$ is a PID, $(a,b)=(d)$ for some $d\\in R$, so $d=\\gcd(a,b)$ by certain questions in example sheet.\r\n    Hence $(a,b)=R$ since $d$ must be a unit by hypothesis, so there is $r,s\\in R$ with $ra+sb=1$.\r\n    Define an $R$-module homomorphism $\\phi:R\\to R/(a)\\oplus R/(b)$ by $x\\mapsto (x+(a),x+(b))$.\r\n    To see it is surjective, $\\phi(sb)=(1+(a),0+(b)),\\phi(ra)=(0+(a),1+(b))$, hence $\\phi(sbx+ray)=(x+(a),y+(b))$.\r\n    Now if $\\phi(x)=(0+(a),0+(b))$, then $x\\in (a)\\cap(b)$, so $x=x(ra+sb)=rax+sxb\\in (ab)$.\r\n    It is obvious that anything in $(ab)$ is mapped to zero, hence $\\ker\\phi=(ab)$, so we deduce the theorem from isomorphism theorem.\r\n\\end{proof}\r\nThis reduced to Chinese Remainder Theorem when we set $R=\\mathbb Z$.\r\n\\begin{theorem}[Prime Decomposition Theorem]\\label{prime_decomp}\r\n    Let $R$ be a ED and let $M$ be a finitely generated $R$-module.\r\n    Then\r\n    $$M\\cong R/(p_1^{n_1})\\oplus\\cdots\\oplus R/(p_k^{n_k})\\oplus R^m$$\r\n    where $p_1,\\ldots,p_k$ are prime in $R$.\r\n\\end{theorem}\r\nNote that $p_1,\\ldots,p_k$ need not to be distinct.\r\n\\begin{proof}\r\n    By the structure theorem, we have\r\n    $$M\\cong R/(d_1)\\oplus\\cdots\\oplus R/(d_t)\\oplus R^m$$\r\n    So it suffices to write each $R/(d_i)$ in the desired form.\r\n    Choose $i$ and write $d_i=up_1^{\\alpha_1}\\cdots p_r^{\\alpha_r}$ where $p_i$ are pairwise non-associates and $u$ is a unit.\r\n    So by the preceding lemma, we have\r\n    $$R/(d_i)\\cong R/(p_1^{\\alpha_1})\\oplus\\cdots\\oplus R/(p_r^{\\alpha_r})$$\r\n    which establishes the theorem.\r\n\\end{proof}\r\nNote that Theorem \\ref{classify_fin_abe} is a direct consequence of this.\\\\\r\nLet $V$ be a vector space over a field $F$ and let $\\alpha:V\\to V$ be an endomorphism, then we can make $V$ an $F[X]$-module (written as $V_\\alpha$) by $f(X)\\cdot v=f(\\alpha)v$.\r\n\\begin{lemma}\r\n    If $V$ is finite-dimensional, then $V_\\alpha$ is finitely generated as an $F[X]$-module.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $v_1,\\ldots,v_n$ generates $V$ as a vector space, then they also generate $V_\\alpha$ as an $F[X]$-module since $F\\le F[X]$.\r\n\\end{proof}\r\nThe lemma itself is trivial, but the thing to take from here is that $V_\\alpha$, being also an $F$-vector space, is isomorphic to $V$.\r\nThis is very useful if we want to analyze the behaviour of $\\alpha$ in $V$:\r\nIf we know that $V_\\alpha$ is isomorphic to some $F[X]$-modules (via e.g. Theorem \\ref{prime_decomp}) that are easier to study, then they are also automatically isomorphic as $F$-vector spaces.\r\nSo by choosing a nice basis for this $F[X]$-module (as a vector space), we can obtain a nice matrix of $\\alpha$.\r\n\\begin{example}\r\n    1. Suppose $V_\\alpha\\cong F[X]/(X^n)$ as $F[X]$-module, then we can choose the basis $1,X,\\ldots,X^{n-1}$ for it to be an $F$-vector space, so $\\alpha$ would have matrix\r\n    $$(\\star)=\\begin{pmatrix}\r\n        0&&&\\\\\r\n        1&0&&\\\\\r\n        &\\ddots&\\ddots&\\\\\r\n        &&1&0\r\n    \\end{pmatrix}$$\r\n    Since $\\alpha$ acts as multiplication by $X$.\\\\\r\n    2. Suppose $V_\\alpha\\cong F[X]/(X-\\lambda)^n$ as an $F[X]$-module, then wrt the basis $1,X-\\lambda,\\ldots,(X-\\lambda)^{n-1}$, $\\alpha-\\lambda\\operatorname{id}$ has matrix $(\\star)$, so $\\alpha$ exists as a Jordan block.\\\\\r\n    3. Suppose $V_\\alpha\\cong F[X]/(f)$ where $f\\in F[X]$ is in the form $f(X)=a_0+a_1X+\\cdots +a_{n-1}X^{n-1}+X^n$, then with respect to $1,X,\\ldots,X^{n-1}$, $\\alpha$ has the matrix\r\n    $$C(f)=\\begin{pmatrix}\r\n        0&&&-a_0\\\\\r\n        1&\\ddots&&-a_1\\\\\r\n        &\\ddots&0&\\vdots\\\\\r\n        &&1&-a_{n-1}\r\n    \\end{pmatrix}$$\r\n    which is called the companion matrix of $f$.\r\n\\end{example}\r\n\\begin{theorem}[Rational Canonical Form]\r\n    Let $\\alpha:V\\to V$ be an endomorphism of a finite dimensional vector space $V$ over a field $F$, then\r\n    $$V_\\alpha\\cong F[X]/(f_1)\\oplus\\cdots\\oplus F[X]/(f_t)$$\r\n    where $f_i\\in F[X]$ are monic and $f_1|f_2|\\cdots|f_t$.\r\n    Moreover, with respect to a suitably chosen basis for $V$, $\\alpha$ has matrix of the form\r\n    $$\\begin{pmatrix}\r\n        C(f_1)&&&\\\\\r\n        &C(f_2)&&\\\\\r\n        &&\\ddots&\\\\\r\n        &&&C(f_t)\r\n    \\end{pmatrix}$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $V_\\alpha$ is finitely generated as an $F[X]$-module and since $F[X]$ is a ED, we can apply the structure theorem to get\r\n    $$V_\\alpha\\cong F[X]/(f_1)\\oplus\\cdots\\oplus F[X]/(f_t)\\oplus F[X]^m$$\r\n    where $f_i\\in F[X]$ are monic and $f_1|f_2|\\cdots|f_t$.\r\n    $m=0$ since $V$ is finite dimensional over $F$.\r\n    The result is immediate.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. If we start by an $n\\times n$ matrix of $\\alpha$, then this matrix must be similar to the above form.\\\\\r\n    2. The minimal polynomial of $\\alpha$ is $f_t$.\\\\\r\n    3. The characteristic polynomial of $\\alpha$ is $f_1\\cdots f_t$ (up to associates).\r\n    Hence the minimal polynomial divides the characteristic polynomial, so we immediately have Cayley-Hamilton.\r\n\\end{remark}\r\n\\begin{example}\r\n    When $V$ is $2$-dimensional vector space over $F$, then one of the following cases happen\r\n    $$V_\\alpha\\cong F[X]/(X-\\lambda_1)\\oplus F[X]/(X-\\lambda_2),V_\\alpha\\cong F[X]/(f)$$\r\n    where $(X-\\lambda_1)(X-\\lambda_2)$ or $f$ is the characteristic polynomial of $\\alpha$.\r\n\\end{example}\r\n\\begin{corollary}\r\n    Let $A,B\\in\\operatorname{GL}_2(F)$ that are not scalar matrices, then $A,B$ are conjugate iff they have the same characteristic polynomial.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Primes in $\\mathbb C[X]$ are polynomials $X-\\lambda$ where $\\lambda$ is any complex number (up to associates).\r\n\\end{lemma}\r\n\\begin{proof}\r\n    FTA.\r\n\\end{proof}\r\n\\begin{theorem}[Jordan Normal Form]\r\n    Let $\\alpha:V\\to V$ be an endomorphism of a finite dimensional vector space over $\\mathbb C$.\r\n    Let $V_\\alpha$ be $V$ as the $\\mathbb C[X]$-module with $X$ acting as $\\alpha$.\r\n    Then there is an isomorphism of $\\mathbb C[X]$-modules\r\n    $$V_\\alpha\\cong\\mathbb C[X]/(X-\\lambda_1)^{n_1}\\oplus\\cdots\\oplus\\mathbb C[X]/(X-\\lambda_t)^{n_t}$$\r\n    where $\\lambda_i\\in\\mathbb C$ are not necessarily distinct and $n_i\\in\\mathbb N$.\r\n    In particular, there is a basis for $V$ such that $\\alpha$ has the matrix\r\n    $$\\begin{pmatrix}\r\n        J_{n_1}(\\lambda_1)&&\\\\\r\n        &\\ddots&\\\\\r\n        &&J_{n_t}(\\lambda_t)\r\n    \\end{pmatrix},J_n(\\lambda)=\\begin{pmatrix}\r\n        \\lambda&&&\\\\\r\n        1&\\lambda&&\\\\\r\n        &\\ddots&\\ddots&\\\\\r\n        &&1&\\lambda\r\n    \\end{pmatrix}$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We know that $\\mathbb C[X]$ is a ED and $V_\\alpha$ is finitely generated as $V$ is finite dimensional.\r\n    By Prime Decomposition Theorem, noting that primes in $\\mathbb C[X]$ are linear factors, and we cannot have any copy of $\\mathbb C[X]$ as the dimension is finite.\r\n    Then we already have the isomorphism.\r\n    Now $J_n(\\lambda)$ represents the multiplication by $X$ on $\\mathbb C[X]/(X-\\lambda)^n$ wrt the basis $1,X-\\lambda,\\ldots,(X-\\lambda)^{n-1}$.\r\n    This shows the theorem.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. The theorem implies that any matrix with entries in $\\mathbb C$ is similar to a matrix in the said form.\\\\\r\n    2. The Jordan blocks are unique up to reordering.\\\\\r\n    3. The minimal polynomial of $\\alpha$ is $\\prod_i(X-\\lambda_i)^{c_i}$ where $c_i$ is the size of the largest block with eigenvalue $\\lambda_i$.\\\\\r\n    4. The characteristic polynomial of $\\alpha$ is $\\prod_i(X-\\lambda_i)^{a_i}$ where $a_i$ is the sum of the sizes of the blocks with eigenvalue $\\lambda_i$.\\\\\r\n    5. The eigenspace of $\\lambda_i$ has dimension equal to the number of blocks with eigenvalue $\\lambda$.\\\\\r\n    6. The uniqueness statement may be proved by considering the dimension of the generalized eigenspaces $\\ker((\\alpha-\\lambda_iI)^n)$, $n=1,2,\\ldots$.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    The structure theorem is true for any PIDs.\r\n\\end{theorem}\r\nWe will not prove this in the course, but we will illustrate the trick that is used for this extension.\r\n\\begin{theorem}\\label{pid_tf_free}\r\n    Let $R$ be a PID, then any finitely generated torsion-free $R$-module is free.\r\n\\end{theorem}\r\nNote that for $R$ a ED, this is a corollary of the structure theorem.\r\n\\begin{lemma}\r\n    Let $R$ be a PID and $M$ an $R$-module.\r\n    Let $r_1,r_2\\in R$ that are not both $0$.\r\n    Let $d=\\gcd(r_1,r_2)$.\\\\\r\n    1. There is a matrix $A\\in\\operatorname{SL}_2(R)$ such that\r\n    $$A\\begin{pmatrix}\r\n        r_1\\\\\r\n        r_2\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        d\\\\\r\n        0\r\n    \\end{pmatrix}$$\r\n    2. If $x_1,x_2\\in M$, then there is $x_1',x_2'\\in M$ such that $Rx_1+Rx_2=Rx_1'+Rx_2'$ and $r_1x_1+r_2x_2=dx_1'+0x_2'$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We know that $(r_1,r_2)=(d)$, so there is $\\alpha,\\beta\\in R$ such that $\\alpha r_1+\\beta r_2=d$.\r\n    Write $r_1=s_1d,r_2=s_2d$ with $s_1,s_2\\in R$.\r\n    We simply take the matrix\r\n    $$A=\\begin{pmatrix}\r\n        \\alpha&\\beta\\\\\r\n        -s_2&s_1\r\n    \\end{pmatrix}\\in\\operatorname{SL}_2(R)$$\r\n    and it works for the first part.\r\n    For the second part, we can take $x_1'=s_1x_1+s_2x_2,x_2'=-\\beta x_1+\\alpha x_2$.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{pid_tf_free}]\r\n    Say $M=Rx_1+\\cdots+Rx_n$ with $n$ minimal.\r\n    If $x_1,\\ldots,x_n$ are independent, then the module is free.\r\n    Otherwise, there is $r_1,\\ldots,r_n\\in R$ such that $r_1x_1+\\cdots+r_nx_n=0$ where WLOG $r_1\\neq 0$.\r\n    By the preceding lemma, we can choose $x_1',x_2'$ such that $Rx_1+Rx_2=Rx_1'+Rx_2'$, so $M=Rx_1'+Rx_2'+Rx_3+\\cdots+Rx_n$ and $dx_1'+r_3x_3+\\cdots+r_nx_n=0$ for $d=\\gcd(r_1,r_2)\\neq 0$.\r\n    Continue the process to $3,\\ldots,n$ to reduce the case to $rx_1=0$ for some $r\\neq 0$, but $R$ is torsion-free, so $x_1=0$, contradicting the minimality of $n$.\r\n\\end{proof}\r\n\r\n", "meta": {"hexsha": "e3b94931a7e15084c72616f2e72e3bc9f227b14b", "size": 20882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16/struct.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": "16/struct.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": "16/struct.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": 58.3296089385, "max_line_length": 240, "alphanum_fraction": 0.6505602912, "num_tokens": 7144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6489391892021701}}
{"text": "\\subsubsection{Time Series Normalization} \\label{time_series_normalization}\nWhen using DTW to determine the similarity of two time series, it is a common approach to z-normalize or Z-score the\ntime series in front of the calculation \\cite{ding2008querying}. In \\cite{das1998rule} two different time series\nnormalizations are presented. Both time series normalizations $\\eta$ and $\\eta '$ are explained in the following\nsection.\n\nGiven is a time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l$ over the domain set $\\mathbb{U}$ and a\ndistance measure function $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$. The first time series normalization\n$\\eta$ transforms every data\npoint of the given time series $Q$ as follows.\n\\begin{equation}\n    \\eta (q) = q -\\bar{q}\n\\end{equation}\nwhere $\\bar{q}$ is the mean of the time series $Q$\n\\begin{equation}\n    \\bar{q} = \\frac{1}{l} \\sum \\limits_{i=1}^{l} q_i\n\\end{equation}\nFigure \\ref{fig:norm1} shows the impact of the $\\eta$ normalization on DTW compared to plain DTW in figure\n\\ref{fig:dynamictimewarping}.\n\n\\begin{figure}\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    \\caption{The same two time series $Q$ and $C$ from figure \\ref{fig:dynamictimewarping} normalized by $\\eta$. On the\n    left plot are both time series graphs, the gray lines are representing the warping path of plain DTW. The right plot\n    shows the associated matrix containing the distances between the time series data points. Starting in the lower left\n    corner and ending in the upper right corner, the warping path is illustrated as a white graph.}\n    \\label{fig:norm1}\n\\end{figure}\n\nThe second time series normalization $\\eta '$ transforms every data point of the given time series $Q$ as follows.\n\\begin{equation}\n    \\eta '(q) = \\frac{\\eta (q)}{\\sigma}\n\\end{equation}\nwhere $\\sigma$ is the standard deviation of the time series $Q$\n\\begin{equation}\n    \\sigma = \\frac{1}{l-1} \\sum \\limits_{i=1}^{l} d(q_i, \\bar{q})^2\n\\end{equation}\nFigure \\ref{fig:norm2} shows the impact of the $\\eta '$ normalization on DTW compared to plain DTW in\nfigure \\ref{fig:dynamictimewarping}.\n\n\\begin{figure}\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    \\caption{The same two time series $Q$ and $C$ from figure \\ref{fig:dynamictimewarping} normalized by $\\eta '$. On the\n    left are plot both time series graphs, the gray lines are representing the warping path of plain DTW. The right plot\n    shows the associated matrix containing the distances between the time series data points. Starting in the lower left\n    corner and ending in the upper right corner, the warping path is illustrated as a white graph.}\n    \\label{fig:norm2}\n\\end{figure}\n", "meta": {"hexsha": "e193e1265cbf30f38008a9b500d9baa9ccfc9afe", "size": 10075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/background_and_notation/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": "bachelor-thesis/background_and_notation/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": "bachelor-thesis/background_and_notation/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": 50.1243781095, "max_line_length": 124, "alphanum_fraction": 0.4220347395, "num_tokens": 2110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.6488199582450379}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[english]{babel}\n\\usepackage{fancyhdr}\n\\usepackage[margin=.7in]{geometry}\n\\usepackage{exsheets}\n\\usepackage{enumerate}\n\n\\usepackage{./Style/linearProgramsStyle} % This is a set of commands for maths content.\n\n\\pagestyle{fancy}\n\n\\renewcommand{\\headrulewidth}{2pt}\n\\fancyhead[L]{EPITA\\_ING1\\_BING\\_2020\\_S5\\_PROL}\n\\fancyhead[R]{January 2018}\n\n\\fancyfoot[C]{\\textbf{\\thepage}}\n\\fancyfoot[L]{}\n\n\\pretitle{\\vspace{-.5\\baselineskip} \\begin{center}}\n\\title{%\n  { \\huge Linear Programming (PROL)}%\n}\n\\posttitle{\n\\end{center}\n  \\begin{flushleft}\n    \\vspace{3\\baselineskip} \\textit{\n      \\!\\!\\emph{Duration: 1h30.}\\\\\n      \\! \\emph{No documents are allowed.}  \\\\\n      Only \\emph{non-programmable} pocket calculators are allowed.\n    }\n  \\end{flushleft}\n  \\rule{\\textwidth}{1.5pt}\n  \\vspace{-5\\baselineskip}\n}\n\\author{}\n\\date{}\n\n\\pdfinfo{\n   /Author (Bashar Dudin)\n   /Title  (PROL Exam -- 2018)\n   /Subject (Linear Programming)\n}\n\n\\begin{document}\n\n\\maketitle\\thispagestyle{fancy}\n\nWe're considering the following list of linear programs respectively\ngiven the names $(A)$, $(B)$, $(C)$, $(D)$ and $(E)$, $(F)$.\n\\[\n(A) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $x_1 + x_2 + x_3$\n    }{\n      \\systeme{\n        2x_1 + 3x_2 + x_3 \\leq 1,\n        x_1 - 4x_2 + 3x_3 \\geq 2\n      }\n    }{\n      $x_1$, $x_2 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\qquad (B)\\;\n\\left\\{\n  \\begin{linearProg}{\n      minimize\n    }{\n      $- x_1 - x_2 - x_3 + x_4$\n    }{\n      \\systeme{\n        2x_1 + 3x_2 + x_3 - x_4 + \\leq 1,\n        -x_1 + 4x_2 - 3x_3 + 3x_4 \\leq -2\n      }\n    }{\n      $x_1$, $x_2$, $x_3$, $x_4 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\\[\n(C) \\;\n\\left\\{\n  \\begin{linearProg}{\n      minimize\n    }{\n      $-5x_1 - 6x_2 - 9x_3 - 8x_4$\n    }{\n      \\systeme{\n        x_1 + 2x_2 + 3x_3 + x_4 \\leq 5,\n        -x_1 - x_2 - 2x_3 - 3x_4 \\geq -3\n      }\n    }{\n      $x_1$, $x_2$, $x_3$, $x_4 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\qquad (D) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $5x_1 + 6x_2 + 9x_3 + 8x_4$\n    }{\n      \\systeme{\n        x_1 + 2x_2 + 3x_3 + x_4 \\leq 5,\n        x_1 + x_2 + 2x_3 + 3x_4 \\leq 3\n      }\n    }{\n      $x_1$, $x_2$, $x_3$, $x_4 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\\[\n(E) \\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $x_1 - 2x_2 - x_3$\n    }{\n      \\systeme{\n        2x_1 + x_2 - x_3 \\leq -1,\n        x_1 - 2x_2 + x_3 \\leq -2\n      }\n    }{\n      $x_1$, $x_2$, $x_3 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\\qquad (F)\\;\n\\left\\{\n  \\begin{linearProg}{\n      maximize\n    }{\n      $5x_1 + 6x_2 + 9x_3 + 8x_4$\n    }{\n      \\systeme{\n        x_1 + 2x_2 + 3x_3 + x_4 \\leq 5,\n        x_1 + x_2 + 2x_3 + 3x_4 + x_5 = 3\n      }\n    }{\n      $x_1$, $x_2$, $x_3$, $x_4$, $x_5 \\geq 0.$\n    }\n  \\end{linearProg}\n\\right.\n\\]\n\n\\section{Equivalence and Duality}\n\n\\begin{question}\n  Which previous programs are equivalent to each others? Sort them\n  into groups of equivalent classes.\n\\end{question}\n\n\\begin{question}\n  Give standard form of $(F)$. What is the slack form of $(E)$?\n\\end{question}\n\n\\begin{question}\n  What are the dual programs $(C)$ and $(D)$?\n\\end{question}\n\n\\begin{question}\n  Which programs $(D)$, $(E)$ and $(F)$ have basic feasible\n  solution?  Give a feasible solution of $(A)$.\n\\end{question}\n\n\\newpage\n\\section{Simplex Algorithm}\n\n\\begin{question}\n  Solve linear program $(D)$.\n\\end{question}\n\n\\begin{question}\n  Out of previous solution of $(D)$ give a solution of its dual.\n\\end{question}\n\n\\begin{question}\n  Transform program $(E)$ into an equivalent linear program having\n  feasible basic solution.\n\\end{question}\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "ed9b07e8ea032dc0bf0449d288007e976a5a7e64", "size": 3795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/TeX/Ecrit_PROL_2018_012_BING.tex", "max_stars_repo_name": "bashardudin/LinearPrograms", "max_stars_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2016-10-20T14:04:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-31T08:45:14.000Z", "max_issues_repo_path": "Exams/TeX/Ecrit_PROL_2018_012_BING.tex", "max_issues_repo_name": "bashardudin/LinearPrograms", "max_issues_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-04T01:30:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-09T08:18:10.000Z", "max_forks_repo_path": "Exams/TeX/Ecrit_PROL_2018_012_BING.tex", "max_forks_repo_name": "bashardudin/LinearPrograms", "max_forks_repo_head_hexsha": "24b67171cd5bbf407db47f2adb5150ab71d88143", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-10-26T21:19:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-17T19:28:15.000Z", "avg_line_length": 19.362244898, "max_line_length": 87, "alphanum_fraction": 0.5725955204, "num_tokens": 1521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6488199565777412}}
{"text": "\\chapter{Predefined Variables}\\label{ch:predefined}\n\nA few commonly used variables are predefined in\n\\aprepro{}\\footnote{The units system described in\nChapter~\\ref{ch:units} also predefines several variables when it is\nactivated}. These are listed below. The default output format\n\\cmd{\\_FORMAT} is specified as a C language format string, see your C\nlanguage documentation for more information. The default output format\n(\\cmd{\\_FORMAT}) and comment (\\cmd{\\_C\\_}) variables are defined with\na leading underscore in their name so they can be redefined without\ngenerating an error message.\n\n\\begin{longtable}{lll}\n\\caption{Predefined Variables}\\\\\nName & Value & Description \\\\\n\\hline\n PI      & 3.14159265358979323846 & $\\pi$ \\\\\n PI\\_2   & 1.57079632679489661923 & $\\pi/2$ \\\\\n TAU     & 6.28318530717958623200 & $2\\pi$ \\\\\n SQRT2   & 1.41421356237309504880 & $\\sqrt{2}$ \\\\\n DEG     & 57.2957795130823208768 & $180/\\pi$ degrees per radian \\\\\n RAD     & 0.01745329251994329576 & $\\pi/180$ radians per degree \\\\\n E       & 2.71828182845904523536 & base of natural logarithm \\\\\n GAMMA   & 0.57721566490153286060 & $\\gamma$, euler-mascheroni constant \\\\\n PHI     & 1.61803398874989484820 & golden ratio $(\\sqrt{5}+1)/2$ \\\\\n VERSION & Varies, string value   & current version of \\aprepro \\\\\n \\_FORMAT& \\texttt{\"}\\%.10g\\texttt{\"} & default output format \\\\\n  \\_C\\_  &  \\texttt{\"}\\$\\texttt{\"} &  default comment character \\\\\n\\end{longtable}\n\nNote that the output format is used to output both integers and floating point \nnumbers. Therefore, it should use the \\%g format descriptor which will use either \nthe decimal (\\%d), exponential (\\%e), or float (\\%f) format, whichever is shorter, \nwith insignificant zeros suppressed. The table below illustrates the effect of \ndifferent format specifications on the output of the variable \\textbf{PI} and the \nvalue 1.0 . See the documentation of your C compiler for more information. For \nmost cases, the default value is sufficient.\n\n\\begin{longtable}{lll}\n\\caption{Effect of various output format specifications}\\\\\nFormat & PI Output & 1.0 Output \\\\\n\\hline\n\\%.10g &  3.141592654      & 1  \\\\\n\\%.10e &  3.1415926536e+00 & 1.0000000000e+00  \\\\\n\\%.10f &  3.1415926536     & 1.0000000000  \\\\\n\\%.10d &  1413754136       & 0000000000  \\\\\n\\end{longtable}\n\nThe comment character should be set to the character that the program\nwhich will read the processed file uses as a comment character. The\ndefault value of \\texttt{\"}\\$\\texttt{\"} is the comment character used\nby the SEACAS codes at Sandia National Laboratories.  The \\textbf{-c}\ncommand line option (described in Chapter~\\ref{ch:execution}) changes\nthe value of the comment variable to match the character specified on\nthe command line.\n", "meta": {"hexsha": "6577786d2a4d217e94ae29fc58e5dd88462ef8a0", "size": 2720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packages/seacas/doc-source/aprepro/predefined_variables.tex", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/doc-source/aprepro/predefined_variables.tex", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/doc-source/aprepro/predefined_variables.tex", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 48.5714285714, "max_line_length": 83, "alphanum_fraction": 0.7272058824, "num_tokens": 785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6488199451546213}}
{"text": "\\lab{Complex Integration}{Integration in the Complex Plane Part 2}{Integration in the Complex Plane Part II}\n\n\\objective{Apply Residues to Integration in the Complex Plane}\n\nAs we noted in the last lab, there are some important links between the residues of a rational function and its partial fraction decomposition.\nHere we will discuss the connection between residues and integrals along the real line and we will also discuss some important applications of residues.\n\n\\section*{Evaluating Residues Using Limits and Derivatives}\nOften it is faster to evaluate a residue using limits instead of its direct integral definition.\nTo see how this might be done, consider some function $f$ with a pole of order $1$ at $z_0$.\nWe say $f$ has a pole of order $n$ at $z_0$ if the first nonzero term in the Laurent Series expansion of is the term corresponding to $(z-z_0)^{-n}$.\nWe then have\n$$f(z)=c_{-1}(z-z_0)^{-1}+c_0 (z-z_0) +c_1 (z-z_0) + \\dots$$\nSo,\n$$f(z)(z-z_0)=c_{-1}+c_0 (z-z_0) + c_1 (z-z_0)^2 + \\dots$$\nSince the right hand side of the Laurent series converges within some nonzero distance of $z_0$, this series will also converge on that domain.\nIt is an ordinary power series, so it will also be continuous on that domain (it will actually be analytic, but continuity is sufficient here).\nThis means that we may take the limit of this expression as $z$ approaches $z_0$.\nTaking this limit, the only nonzero term of the series remaining is $c_{-1}$, so we have\n\\begin{equation*}\n\\lim_{z\\to z_0} f(z)(z-z_0) = c_{-1} = \\Res_{z=z_0} f(z)\n\\end{equation*}\nNow for some $f(z)$ with a pole of order $n$ at $z_0$ we have that within some nonzero distance of $z_0$, the Laurent series of $f$ converges and is of the form\n$$f(z)=c_{-n}(z-z_0)^{-n}+\\dots+c_0+c_1(z-z_0)+\\dots$$\nMultiplying by $(z-z_0)^{n}$ and differentiating $n-1$ times, we have\n$$\\frac{d^{n-1}}{dz^{n-1}}(f(z)(z-z_0)^{n})=(n-1)! c_{-1} + \\frac{n!}{1!} c_0 (z-z_0) + \\frac{(n+1)!}{2} c_1 (z-z_0)^2!+\\dots$$\nTaking the limit, we have\n\\begin{equation*}\n\\lim_{z\\to z_0}\\frac{d^{n-1}}{dz^{n-1}}((z-z_0)^n f(z)) = (n-1)! c_{-1}\n\\end{equation*}\nWhich implies\n\\begin{equation*}\n\\Res_{z=z_0}f(z)=\\frac{1}{(n-1)!}\\lim_{z\\to z_0}\\frac{d^{n-1}}{dz^{n-1}}((z-z_0)^n f(z))\n\\end{equation*}\t\nAnother useful trick involving poles and residues involves the logarithmic residue, i.e. the residue of the logarithmic derivative $\\frac{d}{dz}(\\ln(f(z))) = \\frac{f'(z)}{f(z)}$.\nA natural consequence of the Laurent series expansion of $f(z)$ and $f'(z)$ at a pole $z_0$ is that, where $d$ is the degree of the pole at $z_0$ is that\n\\begin{equation*}\n\\Res_{z=z_0} \\frac{f'(z)}{f(z)} = d\n\\end{equation*}\nThis is a useful bit of information that may be used to simplify computation of residues or of the Laurent series expansion of a function. \nAnother way we can evaluate residues is by the following theorem.\n\\begin{theorem}\nLet $f(z)=\\frac{p(z)}{q(z)}$ and let $p$ and $q$ be holomorphic at $z_0$. Let $p(z_0) \\neq 0$ and $q(z_0)=0$. Suppose that $z_0$ is a pole of order $1$ of $f$. Then \n\\begin{equation*}\n\\Res_{z=z_0} f(z) = \\frac{p(z_0)}{q'(z)}\n\\end{equation*}\n\\end{theorem}\n\n\\begin{problem}\nWrite a python function, which, using symbolic integration in SymPy, returns the Laurent series expansion of a function about a given pole.\nUse the trick involving logarithmic residues to figure out what the degree of the pole is, then use symbolic limits and derivatives to compute the coefficients of the corresponding Laurent series expansion.\nYou may assume that the pole is not an essential singular point.\n(Recall that, as we defined it, a pole is not an essential singular point, so it will always have a finite degree).\n\\end{problem}\n\n\\begin{problem}\nWrite a function which uses SymPy to evaluate the residue of a function $f$ at a pole of $f$ $z_0$ in the case that: $f$ may be written as the quotient of two functions analytic everywhere within some nonzero distance of $z_0$ and the pole of $f$ at $z_0$ is of order $1$.\n\\end{problem}\n\n\\section*{Evaluating Indefinite Integrals Using Residues}\n\nOne convenient use of residues is the evaluation of integrals that are difficult to evaluate symbolically in other ways.\nOften, when we cannot directly assign a value to one of these integrals, residues can still help us evaluate the Cauchy principal value of the integral.\nRecall that for an integral $\\int_{-\\infty}^{\\infty} f(x)dx$ the Cauchy principal value is $\\lim_{r\\to \\infty} \\int_{r}^{r} f(x) dx$. This limit may exist, even though the limit itself may not.\n\nConsider the integral $\\int_{-\\infty}^{\\infty}\\frac{z^2}{z^4+1}$. Let $f(z)=\\frac{z^2}{z^4+1}$.\nNotice that this function has poles at $e^{\\frac{\\pi i}{4}}$, $e^{\\frac{3\\pi i}{4}}$, $e^{\\frac{5\\pi i}{4}}$, and $e^{\\frac{7\\pi i}{4}}$.\nFor notation, let these be $p_1$, $p_2$, $p_3$, and $p_4$.\nFor some real $R>1$, consider the contour $C$ from $-R$ to $R$ and then continuing continuing counterclockwise along the circle centered at $0$ of radius $R$.\nLet $A$ be this second portion of $C$.\nNote that, since $R>1$ we have\n\\begin{equation*}\n\\int_C f(z)dz = 2\\pi i (\\Res_{z=p_0} f(z) +\\Res_{z=p_1} f(z))\n\\end{equation*}\nSo, rewriting, we have\n\\begin{equation*}\n\\int_{-R}^R f(z) dz = 2\\pi i (\\Res_{z=p_0} f(z) +\\Res_{z=p_1} f(z)) - \\int_A f(z) dz\n\\end{equation*}\nso\n\\begin{equation*}\n\\int_{-\\infty}^{\\infty} f(z) dz = \\lim_{R\\to \\infty} \\int_{-R}^R f(z) dz = 2\\pi i (\\Res_{z=p_0} f(z) +\\Res_{z=p_1} f(z)) - \\lim_{R\\to \\infty} \\int_A f(z) dz\n\\end{equation*}\nWe would like to show that that $\\lim_{R\\to\\infty} \\int_A f(z) dz = 0$, so note that on $A$, $\\abs{z}=R$.\nIt follows from the triangle inequality that $\\abs{z^4+1}\\geq \\abs{\\abs{z}^4-1} = R^4 -1$, so we have that \n$$\\abs{\\int_A f(z) dz}\\leq \\int_A \\abs{f(z)} dz \\leq \\int_A \\frac{R^2}{R^4 -1}dz = \\pi R \\frac{R^2}{R^4-1}$$\nso $\\lim_{R\\to\\infty} \\int_A f(z) dz = 0$ as desired.\nThis then implies that \n\\begin{equation*}\n \\int_{-\\infty}^{\\infty} f(z) dz = 2\\pi i (\\Res_{z=p_0} f(z) +\\Res_{z=p_1} f(z))\n\\end{equation*}\nEvaluating the residues at $p_0$ and $p_1$ we have\n$$\\int_{-\\infty}^{\\infty} f(z) dz = \\frac{\\pi}{\\sqrt{2}}$$\n\n\\begin{problem}\nWrite a python function which, given the coefficients for the polynomials in the numerator and denominator of a rational function $f$, evaluates the sum\n\\begin{equation*}\n\\sum 2\\pi i (\\Res_{z=p} f(z)\n\\end{equation*}\nover all poles $p$ of $f$ such that $Im(p)>0$.\nUse that function to numerically evaluate the following integrals.\n$$\\int_{-\\infty}^{\\infty} \\frac{z^2}{z^6+1}dz$$\n$$\\int_{-\\infty}^{\\infty} \\frac{z^{12}-5z^{10}+3z^8-16z^6+4z^4-z^2-4}{4z^{14}+6z^6+12}dz$$\n\\end{problem}\n\n\\begin{problem}\nSimilar arguments can be used to evaluate integrals of functions that can be compared to the rational functions in question.\nWrite a modified version of the function you just wrote and use it to evaluate the following integrals.\n$$\\int_{-\\infty}^{\\infty}\\frac{cos(z)}{z^4+1}dz$$\n$$\\int_{-\\infty}^{\\infty}\\frac{sin^2(z)}{z^{20}+1}dz$$\n\\end{problem}\n\nThe general conditions in which we may apply this particular way of evaluating integrals come from Jordan's Lemma, which states\n\\begin{lemma}[Jordan's Lemma]\nIf for some $f(z)$ on $\\mathbb{C}$, $f$ is analytic for all points $z$ in the upper half plane such that $\\abs{z}>R_0$ for some $R_0 \\in \\mathbb{R}$ where $R_0 >0$ and that, where $C_R$ denotes the semicircle $z=Re^{i\\theta}$ for $0\\leq \\theta \\leq \\pi$, there exists some positive constant $M_R$ such that for all $z$ on $C_R$, $\\abs{f(z)} \\leq M_R$ and $\\lim_{R \\to \\infty} M_R = 0$, then for every positive constant $a$, we have\n$$\\lim_{R \\to \\infty} \\int_{C_R} f(z) e^{iaz} dz = 0$$\n\\end{lemma}\n\\begin{problem}\nUse the function you just wrote to evaluate the Cauchy Principal Value of the integral\n$$\\int_{\\infty}^{-\\infty} \\frac{z sin(z)}{z^2+1}$$\n\\end{problem}\n\nIf a function has a singularity on the real line, we can often still evaluate the value of $\\int_{-\\infty}^{\\infty} f(z) dz$ using a similar argument as before, but by indenting the path along the real axis around a small path around the singularity, then, as we take the limit as our outer contour moves out toward infinity, we can let the small contour around the singularity approach the singularity.\n\nThe following is a useful theorem involving these ``indented path\" methods.\n\\begin{theorem}\nConsider a function $f$ with a pole of order $1$ at $z=x_0$ with a Laurent series representation in a punctured disk of radius $R$ about $x_0$ and residue $B_0$ at $x_0$.\nLet $C_r$ be the upper half of a circle $\\abs{z-x_0}=r$ where $r<R$ oriented in the clockwise direction, then\n$$\\lim_{r\\to 0} \\int_{C_r} f(z) dz = - B_0 \\pi i$$\n\\end{theorem}\nAs a consequence of this, for a function $f$ on $\\mathbb{C}$ with only zeros of at most order $1$ on $\\mathbb{R}$, where $A$ is the sum of the residues of $f$ on the upper half plane and $B$ is the sum of the residues of $f$ on $\\mathbb{R}$, \n$$CPV = \\int_{-\\infty}^{\\infty} f(z) dz = \\pi i (B+2A)$$ \nWhen that Cauchy Principal Value exists.\n\n\\begin{problem}\nUsing the function you just wrote, evaluate\n$$\\int_{0}^{\\infty} \\frac{sin(z)}{z} dz$$\n\nHint: Since $z$ and $sin(z)$ are odd, $\\frac{sin(z)}{z}$ will be even, so \n$\\int_{-\\infty}^{\\infty} \\frac{sin(z)}{z} dz = 2 \\int_{0}^{\\infty} \\frac{sin(z)}{z} dz$.\n\\end{problem}\n\n%% Add example here?\n\n\\begin{problem}\nModify the function you wrote earlier to evaluate the CPV of $\\int_{-\\infty}^{\\infty} f(z) dz$ for a meromorphic function $f$ where $f$ has only poles of order $1$ along the real axis.\n\\end{problem}\n\nIntegration techniques using residues can also be extended to integration around branch points, some types of integrals involving sines and cosines, inverse Laplace transforms, and many other difficult integration problems.", "meta": {"hexsha": "e711b15b68da855c32aaaf63e0a8885b2050a3bc", "size": 9716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/ComplexIntegration/ComplexIntegration2.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/ComplexIntegration2.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/ComplexIntegration2.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": 65.6486486486, "max_line_length": 431, "alphanum_fraction": 0.6986414162, "num_tokens": 3300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721305, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.6488065129901973}}
{"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{Multivariable calculus \\#1}}\n\\author{@all.about.mathematics}\n\n\\begin{document}\n\n\\maketitle\n\\pagecolor{black}\n\\Large{\\section{Introduction}\nIn this post, we talk about local linearization, which is the analog to finding the tangent line to a single-variable function. Basically, we try to find the equation of the tangent \\textbf{plane} to a multivariable function and use some vector notation to extend it to more dimensions.}\n\\newpage\n\\section{Finding tangent planes}\n\\Large{Before we try to figure out the tangent plane to a specific function, let's figure out the equation of a plane in 3D. The easiest way to represent a plane is $$P(x,y)=ax+by+c$$From this, we have $$\\color{myred}\\frac{\\partial P}{\\partial x}=a\\:,\\: \\frac{\\partial P}{\\partial y}=b$$To guarantee that the plane passes through a specific point $(x_0,y_0,z_0)$, let's change our equation a little bit $$\\color{mygreen}L(x,y)=a(x-x_0)+b(y-y_0)+c$$So, if we wanted to find the tangent plane to $f(x,y)$ at the point $(x_0,y_0,f(x_0,y_0))$, we could easily express it as $$\\color{mygreen}L_f(x,y)=a(x-x_0)+b(y-y_0)+f(x_0,y_0)$$We can also see check that $\\color{myred}\\frac{\\partial L_f}{\\partial x}=a$ and $\\color{myred} \\frac{\\partial L_f}{\\partial y}=b$.Finally, we obtain the formula for a tangent plane:$$\\color{myblue}L_f(x,y)=f(x_0,y_0)+f_x(x_0,y_0)(x-x_0)+f_y(x_0,y_0)(y-y_0)$$ }\n\n\\newpage\n\\section{Generalization with vectors}\n\\Large{The formula $$L_f(x,y)=\\textcolor{myyellow}{f(x_0,y_0)}+\\textcolor {mygreen}{f_x(x_0,y_0)}\\textcolor{myred}{(x-x_0)}+\\textcolor {mygreen}{f_y(x_0,y_0)}\\textcolor{myred}{(y-y_0)}$$is also called the local linearization of $f$ near $(x_0,y_0)$. It satisfies 2 important properties. It has the same value and the same partial derivatives at $(x_0,y_0)$ as $f$. We can see that it contains a \\textcolor{myyellow}{constant term}, the \\textcolor{mygreen}{partial derivatives of $f$ at $(x_0,y_0)$} multiplied with a \\textcolor{myred}{variable term minus the constant term respectively.}\n\n\\noindent{Now let $\\bold{x_0}=(x_0,y_0)^{T}$ and $\\bold{x}=(x,y)^{T}$. Then we can rewrite it as $$L_f(x,y)=\\textcolor{myyellow}{f(\\bold{x_0})}+\\textcolor{mygreen}{\\nabla f(\\bold{x_0})}\\cdot\\textcolor{myred}{ (\\bold{x}-\\bold{x_0})}$$}Where $\\textcolor{mygreen}{\\nabla f(\\bold{x_0})=(f_x(x_0,y_0),f_y(x_0,y_0))^T}$ is the gradient of $f$ at $(x_0,y_0)$. }\n\\newpage\n\\section{Example}\n\\large{Let's say we wanted to approximate $$a=\\sqrt{6.99+\\sqrt{2.01+\\sqrt{3.99}}}$$We can let $f(x,y,z)=\\sqrt{x+\\sqrt{y+\\sqrt{z}}}$ and find the local linearization of $f$ near $\\bold(x_0)=(7,2,4)$. First, we evaluate the constant term $$\\textcolor{myyellow}{f(\\bold{x_0})=f(7,2,4)=\\sqrt{7+\\sqrt{2+\\sqrt{4}}}=3}$$Then we evaluate the partial derivatives and plug in the values\n$$\\textcolor{mygreen}{\\nabla f(\\bold{x})=\\left(\\frac{\\partial f}{\\partial x},\\frac{\\partial f}{\\partial y},\\frac{\\partial f}{\\partial z}\\right)^T}$$$$\\frac{\\partial f}{\\partial x}=\\frac{1}{2\\sqrt{x+\\sqrt{y+\\sqrt{z}}}}\\:,\\:\\frac{\\partial f}{\\partial y}=\\frac{1}{2\\sqrt{x+\\sqrt{y+\\sqrt{z}}}}\\cdot\\frac{1}{2\\sqrt{y+\\sqrt{z}}}$$$$\\frac{\\partial f}{\\partial z}=\\frac{1}{2\\sqrt{x+\\sqrt{y+\\sqrt{z}}}}\\cdot\\frac{1}{2\\sqrt{y+\\sqrt{z}}}\\cdot\\frac{1}{2\\sqrt{z}}$$$$\\textcolor{mygreen}{\\nabla f(\\bold{x_0})=\\left(\\frac{1}{6},\\frac{1}{24},\\frac{1}{96}\\right)^T}$$Plugging everything in the formula,$$L_f(x,y,z)=\\textcolor{myyellow}{f(\\bold{x_0})}+\\textcolor{mygreen}{\\nabla f(\\bold{x_0})}\\cdot\\textcolor{myred}{ (\\bold{x}-\\bold{x_0})}$$$$=\\textcolor{myyellow}{f(\\bold{x_0})}+\\textcolor{mygreen}{f_x(\\bold{x_0})}\\textcolor{myred}{(x-x_0)}+\\textcolor{mygreen}{f_y(\\bold{x_0})}\\textcolor{myred}{(y-y_0)}+\\textcolor{mygreen}{f_z(\\bold{x_0})}\\textcolor{myred}{(z-z_0)}$$$$=3+\\frac{1}{6}(x-7)+\\frac{1}{24}(y-2)+\\frac{1}{96}(z-4)$$To approximate $a$, substitute $(x,y,z)=(6.99,2.01,3.99)$ $$L_f(x,y,z))=3+\\frac{1}{6}(6.99-7)+\\frac{1}{24}(2.01-2)+\\frac{1}{96}(3.99-4)\\approx2.9986458$$Using a calculator, $a\\approx2.9986453$, and our approximation is very accurate.}\n\n\\end{document} \n", "meta": {"hexsha": "3af3de2a521ed6cd548fb18fa6c7e8f5048edee3", "size": 4494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/all.about.mathematics' questions/Local linearization.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/Local linearization.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/Local linearization.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": 107.0, "max_line_length": 1245, "alphanum_fraction": 0.6982643525, "num_tokens": 1667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.6488065027030273}}
{"text": "\n\\section{Conclusions}\nThis paper introduces the Elo-MMR rating system, which is in part a generalization of the two-player Glicko system, allowing any number of players. By developing a Bayesian model and taking the limit as the number of participants goes to infinity, we obtained simple, human-interpretable rating update formulas. Furthermore, we saw that the algorithm is incentive-compatible, robust to extreme performances, asymptotically fast, and embarrassingly parallel. To our knowledge, our system is the first to rigorously prove all these properties in a setting with more than two individually ranked players. In terms of practical performance, we saw that it outperforms existing industry systems in both prediction accuracy and computation speed.\n%In particular, we compare against the popular CodeForces, Topcoder, and TrueSkill rating systems, which are deployed on platforms with hundreds of thousands to millions of users.\n\nThis work can be extended in several directions. First, the choices we made in modeling ties, pseudodiffusions, and opponent subsampling are by no means the only possibilities consistent with our Bayesian model of skills and performances. Second, it may be possible to further improve accuracy by fitting more flexible performance and skill evolution models to application-specific data.\n\nAnother useful extension would be to team competitions. Given a performance model for teams, Elo-MMR infers each team's performance. To make this useful in settings where teams are frequently reassigned, we must model teams in terms of their individual members; unfortunately, it's not possible to precisely infer an individual's performance from team rankings alone. Therefore, it becomes necessary to condition an individual's skill on their team's performance. In the case where a team's performance is modeled as the sum of its members' independent Gaussian contributions, elementary facts about multivariate Gaussian distributions enable posterior skill inferences at the individual level. Generalizing this approach to other models remains an open challenge.\n\n% Probably redundant: The algorithm itself is trivially parallelizable, and further speedup can be attained through a simple sub-sampling strategy. We believe there is potential to improve the performance even more, either through a more sophisticated sub-sampling strategy, interpolation, or by combining our two-phase approach with a factor graph framework similar to that of TrueSkill~\\cite{HMG06, KFL01}. \n\nOver the past decade, online competition communities such as Codeforces have grown exponentially. As such, considerable work has gone into engineering scalable and reliable rating systems. Unfortunately, many of these systems have not been rigorously analyzed in the academic community. We hope that our paper and open-source release will open new explorations in this area.\n\n%In addition, we invite non-technical sporting communities, such as the Spartan Race and DanceSport, to find uses of our skill estimation package.", "meta": {"hexsha": "320e6fcbe9854c16b1268de94c831a8de1d26a89", "size": 3033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/source/sections/s7_conclusions.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/s7_conclusions.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/s7_conclusions.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": 216.6428571429, "max_line_length": 764, "alphanum_fraction": 0.8265743488, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6488065007821279}}
{"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 3 Seminar \\& HW}\\\\\n\n\\textbf{Problem 1:} Let $\\mathrm{P}$ be a distribution on $\\mathbb{R}$ and $F$ be its distribution function. Are the following equalities true?\n\\begin{enumerate}\n    \\item $P([a,b])=F(b)-F(a-)$\n    \\item $P((a,b))=F(b-)-F(a)$\n    \\item $P([a,b))=F(b-)-F(a-)$\n    \\item $P(\\{x\\})=F(x)-F(x-)$\n\\end{enumerate}\n\\\\\n\n\\textbf{Problem 2:} Let $\\mathrm{P}$ have density $p$. Find its distribution, $F,$ if\n\\begin{enumerate}\n    \\item $p(t)=\\frac{I_{[a,b]}(t)}{b-a}$\n    \\item $p(t)=\\lambda e^{-\\lambda t} I_{(0,\\infty)}(t)$\n    \\item $p(t)=\\frac{\\theta}{\\pi(t^2+\\theta^2)}$\n\\end{enumerate}\nFind the product of $F_1(2b)F_2(\\ln 2/\\lambda)F_3(0)$.\n\\\\\n\n\\textbf{Problem 3:} Let $\\mathrm{P}$ be a discrete distribution on $\\mathbb{R}$, $p(x)=\\mathrm{P}(\\{x\\})$\n\\begin{enumerate}\n    \\item $p(x)=\\frac{\\lambda^x e^{-\\lambda}}{x!},~x\\in\\mathbb{Z}_+$ (Poisson distribution). Find $\\mathrm{P}(2\\mathbb{Z}_+).$\n    \\item $p(x)=p(1-p)^{x-1},~x\\in\\mathbb{N}$ (geometric distribution). Find the distribution function and $\\mathrm{P}(2\\mathbb{Z}_+).$\n\\end{enumerate}\nFind numerical values for both distributions if $\\lambda=\\ln 2/2, ~p=1/3$\n\\\\\n\n\\textbf{Problem 4:} Let $\\matbrm{P}$ be the uniform distribution on the quarter disk $D=\\{(x,y):~x^2+y^2<1,~x>0,~y>0\\}.$ Let $P_1(x)$ be its \\textit{marginal distribution} (marginalized $y$). Find the density function $p_1(x)$ of it, as well as the distribution function $F_1$. Find the numerical value of $p_1(\\sqrt{1-(\\pi/4)^2}).$\n\\end{document}\n", "meta": {"hexsha": "701883d2e4d283a36fcdde4e160f260916f67afb", "size": 2004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week03_distributions/Week03_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": "week03_distributions/Week03_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": "week03_distributions/Week03_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": 37.8113207547, "max_line_length": 332, "alphanum_fraction": 0.6616766467, "num_tokens": 766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.6487793092361138}}
{"text": "\\section{Radius of Convergence}\r\nWe've established some tests to determine if an infinite series is or isn't convergent, but like we saw with geometric and Taylor series, it's possible that a series only converges over some interval.\r\nWe'd like to be able to find this interval so we know if we can rightly use Taylor series to approximate a function.\r\n\r\n\\subsection{Convergence Theorem for Power Series}\r\n\\begin{theorem}[Convergence Theorem for Power Series]\r\n\tThere are three possibilities for any power series of the form\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{c_k(x-a)^k}\r\n\t\\end{equation*}\r\n\twith respect to convergence.\r\n\t\\begin{enumerate}\r\n\t\t\\item The power series converges, but only on some finite interval centered at $x=a$.\r\n\t\t\tThat is, there is a positive real number $r$ such that the series converges for $\\abs{x-a}<r$ and diverges otherwise.\r\n\t\t\tThe series may or may not converge at the endpoints.\r\n\t\t\\item The power series converges for all real numbers.\r\n\t\t\\item The power series converge only at $x=a$ and diverges elsewhere (i.e $r=0$).\r\n\t\\end{enumerate}\r\n\tWe call this value $r$ the radius of convergence.\r\n\\end{theorem}\r\n\r\nGenerally, we start by applying the ratio test to determine where the series converges absolutely.\r\nIf we find the series converges for all real numbers of just at $x=a$, we are done.\r\nOtherwise the series converges for some finite interval and we need to apply a different test to determine convergence at endpoints.\r\n\r\n\\begin{example}\r\n\tDetermine the radius of convergence for the following series:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{kx^k}{10^k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince this series isn't quite geometric enough for an nth root test but does have all poitive terms, it seems most suited for a ratio test.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{(n+1)x^{n+1}}{10^{n+1}}}{\\frac{nx^n}{10^n}}} = \\lim_{n\\to\\infty}{\\frac{(n+1)x^{n+1}}{10nx^n}} = \\lim_{n\\to\\infty}{\\frac{(n+1)x}{10n}} = \\frac{x}{10}.\r\n\t\\end{equation*}\r\n\t\r\n\t$x$ can be positive or negative.\r\n\tRecall that with a ratio test, the series converges if the limit is less than 1.\r\n\t\\begin{align*}\r\n\t\t\\abs{\\frac{x}{10}} &< 1 \\\\\r\n\t\t\\abs{x} &< 10.\r\n\t\\end{align*}\r\n\t\r\n\tSo, the radius of convergence is 10.\r\n\tNote that this analysis doesn't tell us for sure of the series converges for $x=\\pm 10$ (it happens to not converge in this case).\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tDetermine the radius of convergence for the following series:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{k!x^k}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe can again use a ratio test.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{(n+1)!x^{n+1}}{n!x^n}} = \\lim_{n\\to\\infty}{(n+1)x} = \\begin{cases} \\infty & x\\neq 0 \\\\ 0 & x = 0 \\end{cases}.\r\n\t\\end{equation*}\r\n\t\r\n\tWe see that the only time the limit is less than 1 is when $x=0$.\r\n\tSo, the radius of convergence is 0.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tDetermine the radius of convergence for the following series\\footnote{You might recognize this as the Maclaurin series for $e^x$.}:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{x^k}{k!}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the ratio test,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{x^{n+1}}{(n+1)!}}{\\frac{x^n}{n!}}} = \\lim_{n\\to\\infty}{\\frac{x}{n+1}} = 0.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit is less than 1 everywhere, the series converges for all real $x$.\r\n\\end{answer}\r\n\r\n\\subsection{Convergence at Endpoints}\r\nIf a series only converges over some finite interval, our method of applying the ratio test is inconclusive.\r\nInstead, we plug in the endpoint value for $x$ into our series and apply a different test, which usually depends on the specific series we're working with.\r\nThe most common tests to use are the direct comparison test, the limit comparison test, the integral test, and the alternating series test.\r\n\r\n\\begin{example}\r\n\tGiven that the following series converges by the ratio test for $\\abs{x}<10$, determine convergence at the endpoints.\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{kx^k}{10^k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tPlugging in $x=\\pm10$,\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{k(\\pm10)^k}{10^k}} = \\sum_{k=0}^{\\infty}{(\\pm 1)^k k}.\r\n\t\\end{equation*}\r\n\t\r\n\tThis series diverges by the nth term test for both $x=10$ and $x=-10$.\r\n\tSo the radius of convergence is $\\abs{x} < 10$.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tFor what values of $x$ does the following series converge:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{(-1)^{k+1}\\frac{x^{2k}}{2k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the ratio test to the absolute series,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{x^{2n+2}}{2n+2}}{\\frac{x^{2n}}{2n}}} = \\lim_{n\\to\\infty}{\\frac{2nx^2}{2n+2}} = x^2.\r\n\t\\end{equation*}\r\n\r\n\tSo, by the ratio test, the series converges absolutely when $\\abs{x}<1$.\r\n\tThe series is the same at $x=1$ and $x=-1$.\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{(-1)^{k+1}}{2k}}.\r\n\t\\end{equation*}\r\n\r\n\tSince the series, disregarding the $(-1)^{k+1}$ has all terms positive and decreasing and passes the nth term test, it converges by the alternating series test.\r\n\tTherefore the interval of convergence is $[-1,1]$.\r\n\\end{answer}\r\n\r\nIt's important to remember that although a series might converge over some interval it might do so very slowly, especially at endpoints.\r\nThat is why when estimating a function value using a Taylor series we still need to estimate the error.", "meta": {"hexsha": "ecf75b9618561da63f3bf1f393b2d02ce77b984a", "size": 5542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/infinite_series/radius_of_convergence.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/radius_of_convergence.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/radius_of_convergence.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.6935483871, "max_line_length": 201, "alphanum_fraction": 0.6923493324, "num_tokens": 1748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.9149009474519223, "lm_q1q2_score": 0.6486822885121458}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath,amssymb,amsthm}\n\\usepackage{fullpage}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{listings}\n\n\\theoremstyle{definition}\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{lem}[thm]{Lemma}\n\\newtheorem{defn}{Definition}[section]\n\\newtheorem{conj}{Conjecture}[section]\n\\newcommand{\\floor}[1]{\\left\\lfloor #1 \\right\\rfloor}\n\\newcommand{\\ceil}[1]{\\left\\lceil #1 \\right\\rceil}\n\\newcommand{\\bigC}[0]{\\mathcal{C}}\n\\begin{document}\n\\emergencystretch 3em\n\\title{How hard is it to detect {\\em some} cliques?}\n\n\\author{Josh Burdick}\n\n\\maketitle\n\n\\begin{abstract}\nShannon's function-counting argument\n\\cite{shannon_synthesis_1949} showed that most Boolean functions have\nexponential circuit complexity, but doesn't provide a specific example\nof such a hard-to-compute function. A simple modification of that argument\nshows that detecting a randomly-chosen subset of the $k$-vertex cliques in an\n$n$-vertex graph requires, on average, $\\Omega(n^{k/2})$ NAND gates.\nUnfortunately,\nthis doesn't directly bound the complexity of detecting {\\em all} of the cliques;\nhowever, it seems like a related problem.\nHere, we attempt to combine a counting argument with\nrandom restrictions, to estimate the number\nof NAND gates needed to detect some cliques (as a function\nof the number of cliques).\n\\end{abstract}\n\n\\newpage\n\n\\tableofcontents\n\nThis is an attempt to obtain a lower bound on the the number of NAND gates\nneeded to detect {\\em some} of the cliques in a graph (as opposed to\nall of them).\nAlthough it seems unlikely to work, hopefully\nit will add to the long list of strange things which would happen\nif P = NP \\cite{fenner1996complexity}.\n\n\\section{A counting bound}\n\\label{countingBound}\n\nThe first component we use is a slight modification\nof Shannon's function-counting argument\n\\cite{shannon_synthesis_1949}.\n\n\\subsection{Background: lower bounds from function counting}\n\nIt has long been known that computing {\\em some} function of a bit-string\nrequires exponentially large circuits \\cite{shannon_synthesis_1949}.\nLet $f: \\{0,1\\}^m \\rightarrow \\{0,1\\}$ be a function from bitvectors to bits.\nIf there are $m$ inputs to a circuit,\nthen there are $2^{2^m}$ possible functions from the $m$-input bitstring to\na one-bit output. Each of these functions, being different, must have a\ndifferent circuit.\n\nGiven a count of functions, we can then see, for instance,\nhow many unbounded fan-in NAND gates are needed to compute\nthose functions (see Theorem \\ref{boundFromCounting}\nin Appendix \\ref{gateMath}).\n\n\\subsection{Counting CLIQUE-like functions}\n\nSuppose we are given an $n$-vertex graph.\nLet $k$-CLIQUE($n$) be the boolean function which\ndetects $k$-cliques: it outputs 1 if any $k$-clique\nis present, and 0 otherwise. This is a classic\nNP-complete problem.\n\nWe now consider a ``buggy'' variant of the $k$-CLIQUE function,\nwhich only detects a subset of cliques. (Nomenclature note:\ntechnically, since\nwe're only trying to output a 1 iff there's a clique, I should say\n``detects''; ``finding'' a clique would mean outputting its\nvertices as well. I'll probably write ``finds'' here for now,\neven though it isn't exactly the right nomenclature.)\n\nAs a concrete example,\nconsider the set of ``buggy'' 6-clique detectors.\nMaybe the circuit correctly\nfinds all the cliques. Or maybe it finds all of the cliques except $K_{1..6}$,\nor it misses half the cliques, or finds none (and always outputs 0), or maybe\nit only successfully finds $K_{1,3,4,5,7,8}$, et cetera.\n\nWe define a variant of $k$-CLIQUE which only\nfinds a subset of cliques.\nLet $K$ denote the set of all possible\n$k$-vertex cliques.\n\n\\begin{defn}\n\\label{BUGGYCLIQUE}\nLet $A \\subseteq K$.\nLet $m = {n \\choose 2}$ be the number of edges in the input graph.\n$BUGGYCLIQUE(A): \\{0,1\\}^m \\rightarrow \\{0,1\\}$ is the function which\nis 1 iff any of the $K_k$s in $A$ is present.\nThat is, for each set $A$ of $K_k$s, $BUGGYCLIQUE(A)$\ncontains a function which is 1 if the input contains any $K_k \\in A$,\nand 0 otherwise. (Using this nomenclature,\n$k$-CLIQUE(n) = $BUGGYCLIQUE(K)$).\n\\end{defn}\n\nOf course, many of these functions are quite similar (e.g. all but one of them\noutput a 1 when you feed in all 1's). However, they're all slightly different.\n\n\\begin{thm}\n\\label{buggyDistinct}\nThere are  $2^{|K|}$ distinct $BUGGYCLIQUE$ functions.\n\\end{thm}\n\\begin{proof}\n\nLet $A,B \\subseteq K$, with $A \\neq B$, and w.l.o.g.\nlet $x \\in A-B$. Then $BUGGYCLIQUE(A)$ outputs 1 on the input\nwith just the edges in $x$ set to 1 (and 0 everywhere else),\nwhile $BUGGYCLIQUE(B)$ outputs a 0.\n\nThere are $2^{|K|}$ many subsets of $K$,\nand by the above, each corresponds to a diffferent function.\n\\end{proof}\n\nFor a given $A$, many of the functions in $BUGGYCLIQUE(A)$\nare similar (for instance, most\nof them output a 1 when all the edges are present);\nbut they are all distinct.\nAlthough $2^{n \\choose k}$ is a fairly large number,\nit's still comfortably less than $2^{2^{n \\choose 2}}$, the number of boolean\nfunctions on the ${n \\choose 2}$ input wires (one per edge).\n\n\\subsubsection{But {\\em which} function requires many gates?}\n\nThus, there are $2^{n \\choose k}$ different functions. \nHow many NAND gates do these take?\n(We consider NAND gate circuits (with any fan-in) which find $k$-cliques in $n$-vertex\ngraphs, as a circuit with $n \\choose 2$ inputs.)\n\nApplying Theorem\n\\ref{boundFromCounting}, we know that at least one of the circuits requires\n${\\sqrt {2 {n \\choose {k/2}} + b^2}} - b = \\Omega(n^{k/2})$ \nNAND gates (where $b = {k \\choose 2} - 0.5$).\n\nWhy doesn't this bound $k$-CLIQUE?\nBecause we don't know that the circuit which finds {\\em all} of the\n$K_k$s is one of these larger circuits. As far as what I've\nshown thus far goes, it could be harder to find some weird subset of the $K_k$s.\n\nIndeed, as far as what we've formally shown goes, the problem which needs\nthe most NAND gates could be finding a single clique! That's easily ruled out\n(because that only needs one NAND gate, plus the output gate).\n\n\\subsection{Which sets of cliques are hard to find?}\n\\label{sec:whichCliques}\n\nThe hardness of these functions depends\non how the cliques they find are laid out.\n\nCliques are arguably difficult to draw in a two-dimensional space.\nAs an approximate diagram reflecting what we know,\nwe sketch a Hasse diagram of possible subsets of cliques. Although\nwe only draw a few subsets of three-vertex cliques\non six vertices, hopefully this provides some\nintuition.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=1\\textwidth]{R/Hasse.pdf}\n\\caption{Hasse diagram of BUGGYCLIQUE functions.\n(a-d) \nDetecting all the possible cliques in larger graphs will be\nincreasingly difficult (although {\\em how much} harder isn't clear).\n(e) \nDetecting this set of cliques is definitely harder than (b),\nsince we can convert from (e) to (b) by feeding in 0's to\nsome set of edges.\n(f) Detecting a set of cliques which doesn't overlap much will be\nharder than detecting the same number of cliques, when they overlap\nmaximally (as in (b)).}\n\\label{fig:Hasse}\n\\end{figure}\n\n\n\\begin{thm}\n\\label{edgeZonking}\nLet $A \\subsetneq B \\subseteq K$, such that $A$ is what remains\nof $B$ after removing all cliques overlapping some edge $e$.\nThen $|\\bigC(BUGGYCLIQUE(B))| > |\\bigC(BUGGYCLIQUE(A))|$.\n\\end{thm}\n\\begin{proof}\nFeed in a 0 to $e$, which is in $B$; the remaining cliques are $A$.\nThe resulting\ncircuit computes $BUGGYCLIQUE(A)$, and so has size\nat least $|\\bigC(BUGGYCLIQUE(A))|$. But at least one\nNAND gate has been removed by feeding in the 0.\n\\end{proof}\n\nThis shows that sometimes, finding a larger set of cliques is\nharder. However, the above theorem doesn't help if the two\nsets of cliques cover the same set of edges.\n\n\\begin{figure}\n\\label{overlappingTris}\n\\centering\n\\includegraphics[width=1\\textwidth]{R/tri1.pdf}\n\\caption{A given number of cliques can overlap maximally (left),\nor not overlap much (right).}\n\\label{fig:overlappingTriangles}\n\\end{figure}\n\nTriangles can be detected using matrix multiplication \\cite{itai_finding_1977},\nand there are fast algorithms known for matrix multiplication\n\\cite{strassen_gaussian_1969}\n\\cite{williams_multiplying_2012}, so the set of all possible\ncliques on some set of vertices (Figure \\ref{overlappingTris}, left)\n can be detected\nusing fewer than one NAND gate per triangle (for large enough input graphs).\n\nOn the other hand, if the triangles overlap less (as in\nFigure \\ref{overlappingTris}, right),\nthen to detect all of the triangles, we will definitely need at least one\ngate per triangle. We can see this by feeding in a 0 to some input\nunique to a triangle, applying \\ref{edgeZonking}, and repeating.\n\n\\subsection{Defining levels of CLIQUE}\n\nTo me, it seems a reasonably intuitive guess that the hardness of\ncomputing $BUGGYCLIQUE(A)$ should be somehow related to\n$|A|$, which is simply the number of cliques it ``sees''.\n\n\\begin{defn}\n\\label{CLIQUE-level}\nAssume $n, k$ are fixed. For any $l$ such that\n$0 \\le l \\le |K|$, let $K_l$ be the set of all sets\nwith exactly $l$ cliques. \n\\end{defn}\n\nWe abuse notation slightly, and write\n\n\\[\nBUGGYCLIQUE(K_l) = \\{ BUGGYCLIQUE(k) : k \\in K_l \\}\n\\]\n\nWhat can we say about $E[|\\bigC(BUGGYCLIQUE(K_l))|]$, for\nsome fixed $l$? Let $N = {n \\choose k}$.\nAt the ``bottom'', there's only one $BUGGYCLIQUE(\\emptyset)$\nfunction, so the counting argument is useless.\nIn the ``middle'',\nthere are ${N \\choose {N/2}}$ functions, and so the counting\nargument gives a nontrivial lower bound for\n$E[|\\bigC(BUGGYCLIQUE(K_{N \\choose {N/2}}))|]$ (although\nwithout actually constructing even {\\em one} difficult function!).\nAt the ``top'', again, there's only one $BUGGYCLIQUE(K) = k-CLIQUE$\nfunction, so the counting argument is, once again, useless.\n\nIt would be nice if we could show that, as $l$ increases,\n$E[|\\bigC(BUGGYCLIQUE(K_l))|]$ also increases.\nIf we could prove something in general, for all levels $l$, then at\nthe top of the diagram, we'd be bounding just the function\n$BUGGYCLIQUE(K_l) = k-CLIQUE$. (This suggests that doing so would\nbe difficult...)\n\n\n\\section{Using random restrictions}\n\nRandom restrictions have been used in lower bounds of formula\n\\cite{subbotovskaya1963comparison} and circuit \\cite{hastad1987lower}\ncomplexity (see also the slides at \\cite{rossmanRestrictions}).\nHere, we apply random restrictions to a set of functions (and circuits),\nrather than just one function and circuit.\n\n??? Is this just a ``gate-elimination argument''?\n\n\\subsection{Counting functions by their ``rank'' in a list}\n\nThis argument relies on measuring the size of a circuit,\nfor a given basis. (Here, we assume unbounded fan-in\nNAND gates, but this doesn't seem crucial.)\n\n\\begin{defn}\n\\label{Rank}\nFor all $C \\subseteq K$,\narrange all of the sets of cliques in nondecreasing order\nof $|\\bigC(BUGGYCLIQUE(C))|$ (using unbounded fan-in NAND gates,\nbreaking ties by some lexicographic order of circuits).\n\nLet $A \\subset K$. The {\\em rank} of $A$, $rank(A)$, is the zero-based\nindex of $A$ in this list.\n\\end{defn}\n\nIf we can lower-bound $rank(A)$, then we should be able to translate\nthat into a\nlower bound on $|\\bigC(BUGGYCLIQUE(A))|$. (Possibly, if we\ncan only lower-bound $E[rank(A)]$, we may be able to get\na bound in terms of number of gates using Jensen's inequality?\nNot clear.)\n\nWe can imagine a miles-long linear warehouse of chips with the minimal\ncircuit for each problem, sorted in terms of number of gates.\nNote that the above list only includes functions in $BUGGYCLIQUE$.\nThere are a {\\em ton} of other functions (parity, primality, etc.), but ignoring\nthose should still leave a valid lower bound for the functions in $BUGGYCLIQUE$.\n\n\\subsection{How much smaller are ``restricted'' circuits, on average?}\n\n\\begin{thm}\n\\label{vaguelyUpward}\nLet $C \\subseteq K$ be a set of cliques chosen uniformly at random\nfrom $K$.\n\nLet $a = {n-2 \\choose k-2}$ (this is the number of $k$-cliques\nintersecting a given edge).\n\nThen there is a function $f: 2^K \\rightarrow 2^K$ such that\n\\begin{itemize}\n\n\\item $E[|C| - |f(C)|] = a/2$\n\n\\item $E[rank(C) - rank(f(C))] = a/2$\n\n\\end{itemize}\n\n\\end{thm}\n\\begin{proof}\n\nPick a distinguished input edge $e$, and let $A \\subseteq C$ be\nthe set of cliques in $C$ which include $e$, and $B \\subseteq C$ be\nthe set of cliques in $C$ which don't include $e$.\n\nWe define $f(C) = B$.\n\nNow, take the circuit computing $BUGGYCLIQUE(C)$, and\nfeed in a 0 to $e$. The resulting circuit computes\n$BUGGYCLIQUE(B)$. Note that $A$ could contain anywhere\nfrom 0 to $a$\ncliques, so since $C$ is chosen uniformly at random,\n$E[|A|] = a/2$.\n\nFurthermore, $|\\bigC(B)| \\le |\\bigC(C)|$, because feeding in\na zero to the circuit for $BUGGYCLIQUE(C)$ constructed a\n(possibly non-optimal) circuit for $BUGGYCLIQUE(B)$.\nThus, $rank(B) \\le rank(C)$.\nThis means that\n$C$ is one of $a$ functions chosen uniformly at random,\nand so, on average, there are $a/2$ circuits between $C$\nand $B$, implying at least that large a difference in rank.\n\n(Note that if $e$ ``misses'' all of the cliques in $C$, then $B = C$\nand $rank(B) = rank(C)$. However, provided $e$ is in some clique in $C$,\nthen since we're feeding in a 0 to a NAND-gate circuit,\nthe inequality $rank(B) < rank(C)$ is strict.)\n\n\\end{proof}\n\nIn terms of the previous warehouse analogy, we can imagine that,\nwhen an edge is disabled, the chip now has strictly fewer gates.\nPerhaps the chip-maker spent their entire budget on designing the\noptimal circuits, but then skimped on the wires connecting the chips?\nIn that case, assuming the missing wire is treated as a 0, the chip still\nfinds some cliques, and so might be sellable.\nBy construction of the warehouse, that means the faulty chip could be shifted,\non a giant conveyor belt,\ntoward the ``smaller'' (in number of gates) end of the warehouse.\nThat means that the corresponding set of cliques is also\nin the ``smaller'' end of the warehouse.\n\nAlthough both these numbers (the reduction in number of cliques, and\nthe reduction in rank) have an expected value of $a/2$,\nthey aren't necessarily the same, or even correlated.\n(Indeed, when $n$ is large, the number of cliques is sharply peaked around $a/2$,\nbut the lower bound in reduction in rank is uniformly distributed across $0..a$.)\n\n\\subsubsection{Why this doesn't bound $k-CLIQUE$?}\n\n\\ref{vaguelyUpward} seems to show that ``finding more cliques is\nat least a tiny bit harder on average.'' However, it only applies\non average.\n\nWhat happens if we try to use restrictions to bound $k-CLIQUE$?\nIf we start ``at the top'',\nfeeding in a 0 to $k-CLIQUE$, which is one function,\nwe get only one other function.\n\nHowever, it seems vaguely plausible to proceed ``bottom-up'',\nestimating the difficulty of finding increasingly large\nsets of cliques.\n\n\\subsection{Estimating the rank of functions, at each level}\n\nIt seems intuitive that finding a larger fraction of the cliques\nshould be harder.\nSo, another idea is to try to show this using induction on $l$.\nAs usual, the base case ($l=0$) is easy: finding zero cliques is easiest,\nso its rank is 0.\n\nThe step case is not so straightforward. Suppose we've computed bounds for\nlevels 0 through $l-1$ (thus, we're using some sort of strong induction.)\nIn other words, we've lower-bounded $E[rank(K_i)]$, for $i \\in [0,l-1]$.\nCan we lower-bound $E[rank(K_l)]$?\n\nSuppose we pick a set of cliques at level $l$, uniformly at random.\nIf we then pick an edge $e$ uniformly at random, and remove the cliques\nwhich contain $e$, then the number of cliques removed will vary\ndepending on the level. When $l=1$, we'll remove 0 or 1 cliques; when $l=N$,\nwe'll remove all ${n-2 \\choose k-2}$ cliques which contain $e$.\n\nWe can {\\em estimate} the number of cliques removed, by supposing that each\nclique is ``hit'' by $e$, with probability $p = {k \\choose 2} / {n \\choose 2}$.\nIf we assume that $e$ hitting each clique is an independent event, then\nrestricting a random set of $l$ cliques will hit $pl$ cliques, and\nleave $(1-p)l$ cliques.\nIn general, when $n>>k$, $p$ will be pretty small. Thus, the step case at\nlevel $l$ will depend on estimates for levels fairly ``high up'' near $l$.\nAlso, when $n$ is large, $N$ is way larger; so the distribution of\nthe fraction of cliques removed will be sharply peaked near $p$.\n\nHowever, this induction isn't quite correct.\nWe may have a bound on $E[rank(K_i)]$, for $i$ in $[0,l-1]$.\nBut when we pick a random set of cliques $K_l$, and feed in a 0, we definitely\naren't sampling uniformly from levels 0 through $l-1$, because the graphs we're\nsampling definitely lack one edge.\n\nThus, this is {\\em only an estimate} of the rank of functions at level $l$.\nTo me, this raises (at least) the following questions:\n\n\\begin{itemize}\n\n\\item If we compute the estimate, what do we get?\n\n\\item Is there a way to modify this, to get an actual bound?\n\n\\end{itemize}\n\nI only address the first question, and punt on the second.\n\n\\subsection{An estimated bound}\n\nThus, even though this is an estimate, we ``simulate'' this process, starting\nat level 0, and going up to level $N = {n \\choose k}$. \nFirst, define $p$, the estimated probability that a 0 ``hits'' a clique:\n\n\\[ p = \\frac{{k \\choose 2}}{{n \\choose 2}} \\]\n\nAssume that the number of cliques after feeding in a 0 follows a binomial\ndistribution, with $l$ ``trials'' and ``probability of success'' $1-p$.\n$B(l)$ will then be a weighted average of $B(0)$ through $B(l-1)$. However,\nif the 0 ``misses'' all the cliques, then we can't say anything about the\nrank, and just use 0.\nFurthermore, we know that at level $l$, we're adding ${N \\choose l}$ new\nfunctions.\n\n\nLet $R(l)$ be the lower bound on the expected rank of functions in $K_l$.\n\n\\[\nR(0) = 0\n\\]\n\nFor $0 < l \\le N$, define\n\\[\n\tR(l) = [ \\sum_{1\\le i < N} binom(i; l, 1-p) R(i) ] + {N \\choose l}/2\n\\]\n\nThe file {\\tt py/approxRank.py} computes this bound. Here are the bounds\nfor two small cases.\n\n\\includegraphics[width=0.45\\textwidth]{py/rank_n=6_k=3.pdf}\n\\includegraphics[width=0.45\\textwidth]{py/rank_n=11_k=4.pdf}\n\n\\section{Related work}\n\nThis strategy relies heavily on a modification of Shannon's original\nfunction-counting argument \\cite{shannon_synthesis_1949},\ncombined with random restrictions\n\\cite{subbotovskaya1963comparison} \\cite{hastad1987lower}.\n\nA related question is whether problems\n(such as $k$-SAT) are\nhard on average \\cite{bogdanov2006average}.\nThese efforts seem to focus more on whether\nrandom\ninstances of a given problem are hard, rather\nthan using random problems to show that\na specific problem is hard.\n\n??? What about:\n- co-NP?\n- formula size?\n\n\nThis lower-bound strategy also seems potentially\nrelevant to quantum computing,\nas the argument makes few restrictions on the sort of gates used.\nHowever, we did use the property of NAND gates that ``feeding in\na 0 disables a gate''; it's not clear whether that's needed,\nor holds for quantum gates.\n\n\\section{Conclusion}\n\nWe give a lower bound on finding {\\em some} set of cliques.\nIt is a modified form of Shannon's counting argument\n\\cite{shannon_synthesis_1949}, combined with random restrictions\n\\cite{subbotovskaya1963comparison} \\cite{hastad1987lower}.\nThis suggests {\\em approximate} bounds on functions {\\em similar} to $k$-CLIQUE.\nUnfortunately, however, this is an approximate bound,\nand so doesn't bound the complexity of $k$-CLIQUE.\n\nIf this were true, then by the contrapositive,\n\\cite{fenner1996complexity} would give a concise list of some of the consequences...\n\n\\section{Acknowledgements}\n\nThe author would like to thank William Gasarch for introducing him\nto lower bound strategies, and probabilistic proofs.\nHe would also like to thank the maintainers of\nseveral entertaining and relevant blogs, including but\nnot limited to: the Computational Complexity blog\n(Lance Fortnow and William Gasarch), \nG\\\"odel's Lost Letter (Richard Lipton and Ken Regan),\nand Shtetl-Optimized (Scott Aaronson). \n\n\n\\appendix\n\\section{Calculations for unbounded fan-in NAND gates}\n\\label{gateMath}\n\nWe used unbounded fan-in NAND gates largely because they are\nconvenient to convert from ``number of functions'' to\n``number of gates''.\n\nLet $\\bigC(f)$ be the circuit\nwith the fewest unbounded fan-in NAND\ngates computing $f$, and let $|\\bigC(f)| = g$ be the number of gates in\nthat circuit. The\ncircuit could have at most $gm$ wires from inputs to gates, and ${g \\choose 2}$\nwires from gates to gates. We can view the possible circuits as a bitmask,\ncontaining a 1 everywhere a gate is connected to an input (or another gate),\nand 0 everywhere else.\n\n\\begin{thm}\n\\label{boundFromCounting}\nConsider functions from $m$ bits to one bit of output.\nThis means that, with $g$ gates, we can represent at most\n$2^{gm + {g \\choose 2}}$ different boolean functions (with $m$ bits of input,\nand one bit of output).\n\\end{thm}\n\\begin{proof}\n\nThe number of possible wires which are there, or not, is $gm + {g \\choose 2}$,\nwhich bounds how many possible circuits there are.\nSome of these circuits compute the same function.\nHowever, there can't be any more than this many circuits with this many wires.\n\\end{proof}\n\nThis means that if we have a large set of functions, and we know the size of\nthe set of functions, then we know that at least {\\em one} of them requires\na large number of gates. (Knowing {\\em which} function requires a lot, or many,\ngates is still an issue).\n\nWe used unbounded-fan-in NAND gates because, given a number of circuits,\nit's easier (I think!) to solve for the number of wires than if we had\nused two-input gates.\nConsider functions from $m$ bits to one bit of output.\nLet $g$ be the number of gates, and $w$ be the number of wires.\nSolving for the number of gates:\n\n\\begin{eqnarray*}\nw & = & mg + {g \\choose 2} \\\\\n  & = & mg + g(g-1)/2 \\\\\n  & = & mg + (g^2 - g) / 2 \\\\\n  & = & 0.5g^2 + (m-0.5)g \\\\\n0 & = & 0.5g^2 + (m-0.5)g - w \\\\\n\\end{eqnarray*}\n\nWe solve the quadratic formula (writing $b = m-0.5$ for simplicity), keeping\nonly the non-imaginary root.\n\n\\begin{eqnarray*}\ng & = & -b \\pm \\sqrt{ b^2 + 2w} \\\\\n  & = & {\\sqrt {2w + b^2}} - b \\\\\n\\end{eqnarray*}\n\nThus, given a set of functions, we know that at least one of them requires\nthis many gates.\n\nThis expression is a bit inconvenient, and as $n$ increases, we\nexpect the number of gates to be much larger than the number of\ninputs $b$. To avoid such issues, we can count the number of gates\nbeyond the number of inputs. This gives the bound\n\n\\begin{eqnarray*}\ng & \\ge & {\\sqrt 2w} - m \\\\\n\\end{eqnarray*}\n\n\n\\bibliography{references}\n\\bibliographystyle{unsrt}\n\n\\end{document}\n\n", "meta": {"hexsha": "b2cf995e36a738068a37c0058a518ffaab66f738", "size": 22459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "countingBound/countingBound.tex", "max_stars_repo_name": "joshtburdick/misc", "max_stars_repo_head_hexsha": "7bb103b4f9d850e3279eb675c6df420aa7b8da22", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "countingBound/countingBound.tex", "max_issues_repo_name": "joshtburdick/misc", "max_issues_repo_head_hexsha": "7bb103b4f9d850e3279eb675c6df420aa7b8da22", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "countingBound/countingBound.tex", "max_forks_repo_name": "joshtburdick/misc", "max_forks_repo_head_hexsha": "7bb103b4f9d850e3279eb675c6df420aa7b8da22", "max_forks_repo_licenses": ["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.9391447368, "max_line_length": 86, "alphanum_fraction": 0.7382341155, "num_tokens": 6413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6486463339659636}}
{"text": "\n%*******************************************************************************\n%*********************************** Second Chapter ***************************\n%*******************************************************************************\n%!TEX root = 0.main.tex\n\n\\section{Non uniform sampling schemes and the FEM Laplacian}\n\nIn Chapter 3, we used the fact that when the sampling scheme of the sphere is regular enough, the graph $G$ is such that the corresponding graph Laplacian $\\mathbf {L=V\\Lambda V}^\\intercal$ has eigenvectors that are close enough to the ones of $\\Delta_{\\mathbb S^2}$ to design a graph with a low mean equivariance error. We showed a way to construct a graph $G'$ such that its graph Laplacian well approximates $\\Delta_{\\mathbb S^2}$ in the case of an equiarea sampling scheme of the sphere and we tested it on the HEALPix sampling scheme. In this Chapter we focus on sampling schemes that are less uniform than HEALPix. The sampling scheme $V=\\{v_i\\in \\mathbb S^2\\}$ that we will use for our study, very used in applications, is the so called \\textit{equiangular sampling scheme} \\cite{Driscoll:1994:CFT:184069.184073}. \nThis chapter is organized as follows: In section \\ref{sec:Chapter3: Heat Kernel Graph Laplacian on the Equiangular Sampling} we first introduce the equiangular sampling, and then we present the results that we obtained with two different Graph Laplacians: the HKGL, and a graph proposed by Khasanova et al. \\cite{Frossard2017GraphBasedCO}, specifically designed for this sampling scheme. In section \\ref{sec:Chapter3: Using the Finite Element Method to approximate the Laplace-Beltrami operator on a manifold} we deepen how to use the Finite Element Method (FEM) to construct a discrete approximation of $\\Delta _{\\mathbb S^2}$ and how to derive a graph-like Laplacian from it, that shows a low equivariance error.\n\\subsection{Graph Laplacian on the Equiangular Sampling}\n\\label{sec:Chapter3: Heat Kernel Graph Laplacian on the Equiangular Sampling}\n\n\\subsubsection{The Equiangular Sampling}\n\nGiven the usual parametrization $x = x(\\theta, \\phi)$ of the sphere\n\\begin{align*}\n\t\\mathbb{S}^{2}&=\\left\\{x=\\left(x_{1}, x_{2}, x_{3}\\right) \\in \\mathbb{R}^{3} :\\|x\\|_{\\mathbb{R}^{3}}=\\left(x_{1}^{2}+x_{2}^{2}+x_{3}^{2}\\right)^{1 / 2}=1\\right\\}\\\\\n\tx_{1}&=\\cos (\\phi) \\sin (\\theta), \\quad x_{2}=\\sin (\\phi) \\sin (\\theta), \\quad x_{3}=\\cos (\\theta)\n\\end{align*}\n\nLet $m\\in\\mathbb N$, the \\textit{equiangular sampling} of bandwidth $b=2^m$ is given by \n$\nx_{j k}^{(b)}=x\\left(\\theta_{j}^{(b)}, \\phi_{k}^{(b)}\\right)\n$\nwhere\n\\begin{align*}\n\t\\theta_{j}^{(b)} &:=\\pi \\frac{j}{2 b}, \\quad \\phi_{k}^{(b)} :=2 \\pi \\frac{k}{2 b}\\\\\n\tj&=0, ..., 2b-1 \\text{ and }k=0, ..., 2b-1 \n\\end{align*}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{figs/Chapter3/equiangular.png}\n\t\\caption{\\label{fig:equiangular sampling}Equiangular sampling with bandwidth $b=8$}\n\\end{figure}\nOne has thus $n=4b^2$ points on the sphere, where all the points $x_{0 k}^{(b)}$ correspond to the north pole for every $k=0, ..., 2b-1$. Notice also that the south pole is never sampled. In figure \\ref{fig:equiangular sampling} it can also be appreciated how the area close to the poles is much more sampled that the equator. One reason for which this sampling scheme is very used in application is the existence of the following result from \\cite{Driscoll:1994:CFT:184069.184073}, that states that any band limited function can be exactly recovered from its sampled values $f\\left(x_{j k}^{(b)}\\right)$:\n\\vspace{0.5cm}\n\\begin{theorem}\\label{theo:equiangular sampling theorem}\n\tLet \\(l_{0} \\in \\mathbb{N}\\) and \\(m_{0} \\in \\mathbb{Z},\\left|m_{0}\\right| \\leq l_{0} .\\) If \\(f=\\sum_{l=0}^{b-1} \\sum_{m=-l}^{l} \\widehat{f}(l, m) Y_{l}^{m}\\)\n\tthen\n\t\n\t$$\n\t\\begin{aligned} \\widehat{f}\\left(l_{0}, m_{0}\\right)=& \\frac{1}{4 b^{2}} \\sum_{j=0}^{2 b-1} \\sum_{k=0}^{2 b-1} f\\left(x_{j k}^{(b)}\\right) \\overline{Y_{l_{0}}^{m_{0}}\\left(x_{j k}^{(b)}\\right)} \\sin \\left(\\theta_{j}^{(b)}\\right) \\times \\\\ & \\times \\frac{4}{\\pi} \\sum_{l=0}^{b-1} \\frac{1}{2 l+1} \\sin \\left((2 l+1) \\theta_{j}^{(b)}\\right) \\end{aligned}\n\t$$\n\\end{theorem}\n\\vspace{0.5cm}\nTheorem \\ref{theo:equiangular sampling theorem} is the equivalent on the sphere of the well known Shannon's sampling theorem, that states the minimum sampling frequency at which a band limited signal $f:\\mathbb R \\to \\mathbb R$ can be perfectly reconstructed, and is a precious tool when doing signal processing on the sphere.\n\n\\subsubsection{Heat Kernel Graph Laplacian on the equiangular sampling scheme}\nThanks to theorem \\ref{theo:equiangular sampling theorem} not only we have a characterization of the space \\\\$F=\\{f=\\sum_{l=0}^{b-1} \\sum_{m=-l}^{l} \\widehat{f}(l, m) Y_{l}^{m}\\}\\subset L^2(\\mathbb  S^2)$ of band limited functions on which the sampling operator $T: F\\to \\mathbb R^n$ is invertible, but we also an analytic expression for $T^{-1}$. Thanks to this we can calculate up to machine precision the equivariance error for any function $f\\in F$ and any rotation $g\\in SO(3)$. In figure \\ref{fig:Equivariance error of the full HKGL} we calculated the mean equivariance error of the full HKGL averaging on mono-frequency signals for different bandwidths. We can observe a much cleaner behavior of the mean equivariance error than the one we observed for he HEALPix sampling, most probably due to the fact that this time we can exactly calculate $T^{-1}$. The error increases linearly with the frequency of the signal for all bandwidths, and it seems to converge to zero as $b$ increases. However, the spectrum of the graph Laplacian does not show the eigenvalues grouped in the expected pattern.\n\\begin{table}[h!]\n\t\\centering\n\t\\begin{tabular}{ c|c } \n$b$ & $t$ \\\\ \n\t\\hline\n4 & 0.5 \\\\ \n8 & 0.3 \\\\ \n16 & 0.1 \\\\ \n\t\\end{tabular}\n\t\\caption{\\label{table:equiangular kernel width}Kernel width $t$ used to construct the HKGL for each bandwidth $b$}\n\\end{table}\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/FullHKGLonequiangularsampling.png}\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/equiangular/equi_full_eigenvalues_16.png}\n\t\\caption{\\label{fig:Equivariance error of the full HKGL}Equivariance error of the full HKGL on the equiangular sampling by spherical harmonic degree $\\ell$, and its spectrum for the bandwidth $b=8$ .}\n\\end{figure}\n\n\\subsubsection{A graph alternative to the HKGL for the equiangular sampling}\\label{sec:Chapter3:Frossard}\n\nKhasanova et al. \\cite{Frossard2017GraphBasedCO} designed a discrete Laplacian that is explicitly intended to work on the sphere with the equiangular sampling. They studied a way to build a graph to analyze images produced by omnidirectional cameras. In their work they assume that the image is sampled on the sphere on the equiangular sampling. They consider the set $\\mathcal G$ of all the possible graphs where each node is connected only to four of its nearest neighbours (North, Sud, West, East) and propose a weighting scheme $w_{ij}$ that minimizes the difference in the response to the polynomial spectral filter $\\mathcal F = \\mathbf L$ evaluated on images of the same object seen at different latitudes. In other words, they solve the minimization problem\n\n\\begin{equation}\\label{eq:minimization frossard}\n\t\\min_{W\\in\\mathcal G} \\left|\\mathcal{F}\\left(\\mathbf{y}\\left(v_{ e}\\right)\\right)-\\mathcal{F}\\left(\\mathbf{y}\\left(v_{ i}\\right)\\right)\\right|\n\\end{equation}\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.5\\textwidth]{figs/Chapter3/frossard2.png}\n\t\\end{center}\n\t\\caption{\\label{fig:frossard2}Khasanova et al. setting.}\n\\end{figure}\nfor the adjacency matrix $W$, where $\\mathbf y(v_i)$ is the image of the object on the sphere centered on the vertex $v_i$, and $\\mathcal F (\\mathbf y(v_e))$ is the response of the filter at the vertex $v_e$ that lies at the same longitude of the vertex $v_i$ but on the equator (figure \\ref{fig:frossard2}). In their work they prove that the optimal weights solving the minimization problem (\\ref{eq:minimization frossard}) are given by weights $w_{ij}$ inversely proportional to the Euclidean distance between vertices:\n\\begin{equation}\\label{eq:frossard weights}\n\tw_{ij} = \\frac{1}{\\norm{x_i-x_j}}\n\\end{equation}\nThis construction is interesting since it is adapted to the equiangular sampling, and leads to a very sparse graph with only 4 neighbors per vertex. Furthermore, to obtain the weights (\\ref{eq:frossard weights}) every calculation was done in the \\textit{spatial domain}, without any consideration about the spectral interpretation of the filter. In order to compare it to the HKGL we show the equivariance error by spherical harmonic degree in figure \\ref{fig:Equivariance error of the Frossard-Khasanove graph}. It can be appreciated how this construction performs a little worse that the full HKGL for low bandwidth samplings, but converges faster than the \\textit{full} HKGL, and its spectrum looks much more similar to the one of $\\Delta_{\\mathbb S^2}$.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/KhasanovaFrossardgraphonequiangularsampling.png}\n\t\\includegraphics[width=\\textwidth]{../codes/02.HeatKernelGraphLaplacian/equiangular/equi_full_Khasanova_Frossard_eigenvalues_16.png}\n\t\\caption{\\label{fig:Equivariance error of the Frossard-Khasanove graph}Equivariance error of the Khasanova-Frossard graph on the equiangular sampling with bandwidth $b=8$ by spherical harmonic degree $\\ell$, and its spectrum.}\n\\end{figure}\n\nThe Khasanova-Frossard graph showed us that it is possible to do better than the HKGL on the equiangular sampling. We asked ourself if there's a general way of building a more equivariant graph than the HKGL that is straightforward to implement on any sampling scheme of the sphere. To answer this question in the next section we study a more complex way to approximate the Laplace-Beltrami operator $\\Delta_{\\mathbb S^2}$: the linear FEM Laplacian. We will see that the comparison between the FEM Laplacian and the graph Laplacian will give us precious insights to better understand the limitations of graph Laplacians when it comes to deal with non uniform samplings of the sphere.\n\\subsection{The Finite Element Method approximation of the Laplace-Beltrami operator on the sphere}\\label{sec:Chapter3: Using the Finite Element Method to approximate the Laplace-Beltrami operator on a manifold}\n\nThe Finite Element Method (FEM) is a numerical algorithm that allows to calculate a discrete approximation of the solution of the Laplace-Beltrami eigenvalue problem through a functional discretization of the differential operator $\\Delta_{\\mathbb S^2}$.  We put the necessary definitions and mathematical concepts necessary to properly introduce the weak formulation of a differential problem, the Galerkin method and finally the Finite Element Method in Appendix. For a detailed introduction to the FEM, we refer the reader to \\cite{Quarteroni:1639539}\\\\\nLet's transform the strong form of the eigenvalue problem on the Sphere on its \\textit{weak} formulation. Let's multiply equation (\\ref{eq:continous eigenvalue problem}) by a sufficiently regular function $v$ and integrate on $\\mathbb S^2$. Since the sphere is a closed manifold and has no border, integrating by parts yields\n\\begin{equation}\\label{eq:weak eigenvalue problem}\n\\begin{split}\n&\\text{Find } f\\in H^1(\\mathbb S^2), \\lambda\\in\\mathbb R\\text{ such that }\\\\ \n&\\int_{\\mathbb S^2} \\nabla f(\\mathbf x)\\cdot\\nabla v(\\mathbf x) d\\mathbf x = \\lambda \\int_{\\mathbb S^2} f(\\mathbf x)\\cdot v(\\mathbf x)d\\mathbf x\\quad \\forall v\\in H^1(\\mathbb S^2)\n\\end{split}\n\\end{equation}\nwhere $v$ has been chosen to belong to $H^1\\subset L^2(\\mathbb S^2)$, the Sobolev space of all the functions with derivative $\\nabla f\\in L^2(\\mathbb S^2)$. The Finite Element Method first approximates the domain $\\Omega$ with a triangulation $\\mathcal T_h=\\{ \\tau_i \\}$, and then \\textit{projects} the weak problem (\\ref{eq:weak eigenvalue problem}) into a finite dimensional subspace $V_h\\subset H^1(\\mathcal T_h)$ made by all the piecewise linear polynomials on the triangulation $\\mathcal T_h$. Being the sphere convex, the triangulation $\\mathcal T_h$ has been obtained by calculating the triangulation of the convex hull of the vertices of the chosen sampling scheme through the Qhull algorithm \\cite{Barber96thequickhull}. Now, define $X_h^1$ to be the space of all the continuous, piecewise linear functions on $\\Omega$\n$$X_h^{1}=\\{v_h: v_h\\in C(\\Omega): \\left.v_h\\right|_{\\tau}\\in\\mathbb P^1\\  \\forall \\tau\\in \\mathcal T_h\\}$$ \nand set $V_h=X_h^1$. Since for the functions in $X_h^1$ the number of degrees of freedom is the same of the number of vertices of the mesh $n$, we need  $n$ basis functions $\\phi_i, i=0,...,n-1$ to fully describe $X_h^{1}$. $\\phi_i$ is defined as the continuous piecewise linear function such that \n$$\n\\phi_i(x_j) = \\delta_{ij}\\quad i=0,...,n-1\n$$\nwhere $x_i$ are the points of the sampling scheme that have been used as vertices of the triangles $\\tau$ of the triangulation $\\mathcal T_h$. The support of $\\phi_i$ i.e., the subset of $\\mathcal T_h$ where $\\phi_i$ is not zero, is made by all the triangles sharing the $i$th vertex. An example is shown in figure \\ref{fig:basis function}.\n\n\\vspace{0.5cm}\n\\begin{remark}\n\tFor a function $v_h \\in X^1_h,\\ v_h = v_0 \\phi_0 +...  v_n \\phi_n$ the coefficient $v_i$ is equal to the function $v_h$ evaluated in the $i$th vertex \n\t\\begin{equation}\\label{eq:dof and values}\n\tv_i = v_h( x_i)\n\t\\end{equation}\n\\end{remark}\\vspace{0.5cm}\n\\begin{figure}[h]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.6\\textwidth]{figs/Chapter3/sphere_mesh.png}\n\t\\end{center}\n\t\\caption{\\label{fig:sphere mesh}A triangulation $\\mathcal T_h$ of the sphere made with the vertices of the HEALPix sampling scheme with $N_{side}=8$.}\n\\end{figure}\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.4\\textwidth]{figs/Chapter3/basisfunction.png}\n\t\\end{center}\n\t\\caption{\\label{fig:basis function}Basis function of the space $X^{1}_h$}\n\\end{figure}\n\nBy writing $n$ times the equation (\\ref{eq:weak eigenvalue problem}), setting each time the test function $v_h$ equal to the $i$th basis function $\\phi_i$ of the space $X_h^1$, we obtain the generalized algebraic eigenvalue problem\n\\begin{equation}\\label{eq:algebraic generalized eigenvalue problem}\n\\begin{aligned}\n&\\text{Find }(f,\\lambda)\\text{ such that }\\mathbf A\\mathbf f = \\lambda\\mathbf  B \\mathbf f\\\\\n&\\begin{cases}\n(\\mathbf A)_{ij} &= \\int_{\\mathbb S^2}\\nabla \\phi_i(\\mathbf{x})\\cdot \\nabla \\phi_j(\\mathbf{x})d\\mathbf{x}\\\\\n(\\mathbf B)_{ij} &= \\int_{\\mathbb S^2} \\phi_i(\\mathbf{x}) \\phi_j(\\mathbf{x})d\\mathbf{x}\\\\\n(\\mathbf f)_i &= f_i:\\quad f(\\mathbf x) = f_0\\phi_0(\\mathbf x)+ ... + f_{n-1}\\phi_{n-1}(\\mathbf x) \n\\end{cases}\n\\end{aligned}\n\\end{equation}\n$\\mathbf A$ is called the \\textit{stiffness} matrix, and $\\mathbf B$ is called the \\textit{mass} matrix. Observe that being the Laplace-Beltrami operator self-adjoint, we have that $\\mathbf A=\\mathbf A^\\intercal,$ $\\mathbf B=\\mathbf B^\\intercal$. Being $\\mathbf B$ non singular, the system (\\ref{eq:algebraic generalized eigenvalue problem}) is equivalent to the eigenvalue problem\n\\begin{equation}\\label{eq:algebraic  eigenvalue problem}\n\\mathbf B^{-1}\\mathbf A\\mathbf f = \\lambda \\mathbf f\n\\end{equation}\n\nIt can be shown \\cite{Strang} that even though the matrix $\\mathbf B^{-1}\\mathbf A$ is not symmetric, its eigenvalues are still real and its eigenvectors are such that $\\mathbf V\\mathbf B\\mathbf V^\\intercal=\\mathbf I$, where $\\mathbf I$ is the identity matrix. The solution $\\mathbf f$ that is the vector of the coefficients of the function $f_h$ in the basis $\\phi_i$ corresponds exactly to the values of the function $f_h$ in the vertices. \n\n\\subsection{How to filter a signal with the linear FEM}\nCalculating the discrete Fourier transform with the linear FEM means projecting the Fourier transform into the subspace $V_h$:\n\n\\begin{equation}\\label{eq:FEM fourier}\n\t\\hat f_{FEM} (\\ell, m) = \\int_{\\eta \\in \\mathcal T_h} f_h(\\eta) v_{i(\\ell, m)}(\\eta) d\\eta = \\mathbf v_{i(\\ell, m)}^\\intercal \\mathbf B \\mathbf f\n\\end{equation}\n\nwhere $ v_{i(\\ell, m)}$ is the solution to the eigenvalue problem (\\ref{eq:algebraic generalized eigenvalue problem}), $f_h$ is the projection of $f$ on $V_h$, and $\\mathbf B$ is the mass matrix. It follows that the filtering of a discretized signal $\\mathbf f$ in the spectral domain is done by the following matrix  $\\mathbf \\Omega_K^{FEM}$:\n\n\\begin{equation}\\label{eq:FEM filtering}\n\t \\mathbf \\Omega_K^{FEM} := (\\mathbf B\\mathbf V^\\intercal)^{-1}\\mathbf K\\mathbf V^\\intercal\\mathbf B\n\\end{equation}\n\nwhere $\\mathbf V^\\intercal\\mathbf B$ is the FEM Fourier transform matrix, $\\mathbf K$ is the diagonal matrix that represent the chosen kernel for this filter, and $(\\mathbf V^\\intercal\\mathbf B)^{-1}$ is the matrix representing the inverse FEM Fourier transform. We can already notice a fundamental difference between this way of filtering a signal and the way of filtering a signal with a graph. The FEM filtering uses not only the eigenvectors of the FEM Laplacian, but also the mass matrix $\\mathbf B$. We computed the usual mean equivariance error per spherical harmonic degree for the diffusion filter $\\mathbf K=\\exp(-\\mathbf \\Lambda)$ on the equiangular sampling, and we show it in figure \\ref{fig:FEM diffusion}.\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/FEMdiffusiononequiangularsampling.png}\n\t\\caption{\\label{fig:FEM diffusion}Equivariance error of the linear FEM diffusion on the equiangular sampling by spherical harmonic degree.}\n\\end{figure}\nWe can see that the FEM filtering works better than the state-of-the-art graph of Khasanova-Frossard, but the matrix $\\mathbf \\Omega_K^{FEM}$ is full, and its computation requires the expensive inversion of the Fourier matrix $\\mathbf V^\\intercal\\mathbf B$, making it not efficient if used in a CNN. \n\\subsubsection{A confront between FEM filtering and graph filtering}\\label{sec:FEM filtering as a graph filtering}\nDue to the fact that \n$\n\\mathbf V^\\intercal\\mathbf B\\mathbf V = \\mathbf I\n$,\nwe have that \n$$\n\\begin{aligned}\n\t(\\mathbf V^\\intercal\\mathbf B)^{-1} &= \\mathbf V,\\\\\n\t\\mathbf V^\\intercal\\mathbf B &= \\mathbf V^{-1}.\n\\end{aligned}\n$$\nSo, the FEM filter matrix $\\mathbf \\Omega_K^{FEM}$ can be rewritten as \n\\begin{equation}\\label{eq:FEM filter simple}\n\t \\mathbf \\Omega_K^{FEM}  = \\mathbf V \\mathbf K \\mathbf V^{-1}\n\\end{equation}\nThus a polynomial filter\n$$\nk(\\lambda)=P_\\kappa(\\lambda) = \\sum_{k=0}^{\\kappa-1} \\theta_k \\lambda^k\n$$\nwould be implemented with a matrix\n$$\n\\mathbf\\Omega_K^{FEM} = \\mathbf V \\left(\\sum_{k=0}^{\\kappa-1} \\theta_k \\mathbf \\Lambda^k \\right)\\mathbf V^{-1} = \\sum_{k=0}^{\\kappa-1} \\theta_k (\\mathbf B^{-1}\\mathbf A)^k = P_\\kappa(\\mathbf B^{-1}\\mathbf A).\n$$\n\nIt is interesting to notice that FEM filtering (\\ref{eq:FEM filter simple}) looks very much like graph filtering (\\ref{eq:graph convolution}) but, given that $V$ is not orthogonal anymore, it has to replace the $\\mathbf V^\\intercal$ with $\\mathbf V^{-1}$. Equation \\ref{eq:FEM filter simple} implies that the FEM filtering could be implemented exactly as the graph filtering already implemented in DeepSphere, using the FEM matrix $\\mathbf B^{-1}\\mathbf A$ instead of the usual symmetric HKGL $\\mathbf L_n^t$. Unfortunately, in order to make the evaluation of the polynomial $P_\\kappa(\\mathbf B^{-1}\\mathbf A)$ efficient, we need the matrix $\\mathbf B^{-1}\\mathbf A$ to be sparse. The only way to do so is to have a \\textit{sparse stiffness matrix} $\\mathbf A$ and a \\textit{diagonal mass matrix} $\\mathbf B$. Unfortunately there is no likely way to have both these conditions satisfied at the same time, since this is one of the most well known trade offs of the FEM \\cite{Strang}. To make $\\mathbf B$ diagonal we need to choose $\\phi_i$ to be an orthogonal basis of the finite dimensional functional space $V_h$. To do so, we will need to choose more complicated basis functions than the usual ones in figure \\ref{fig:basis function}, \\textit{most likely with a support that extends to the whole sphere}, making the stiffness matrix $\\mathbf A$ not sparse anymore. A common workaround \\cite{Strang} is the so called \\textit{lumping} of the mass matrix, that consists in replacing the matrix $\\mathbf B$ with the \\textit{lumped} diagonal matrix $\\mathbf D$ obtained by placing in each diagonal entry $(\\mathbf D)_{ii}$ the sum of the elements of the $i$th row of the mass matrix $\\mathbf B$:\n\n\\begin{equation}\\label{eq:lumping}\n\\mathbf D = \\text{diag}\\{d_i\\},\\quad d_i = \\sum_j (\\mathbf B)_{ij}\n\\end{equation}\nThis approximation is well studied in the literature and it is proved to work well in many practical cases \\cite{Quarteroni:1639539}. In this way the FEM matrix $\\mathbf B^{-1}\\mathbf A$ would be approximated by the matrix\n$$\n\\mathbf D^{-1}\\mathbf A.\n$$\nThis matrix has the big advantage of having the same sparsity pattern of the stiffness matrix $\\mathbf A$, making it very efficient for polynomial filtering. We can take one step further by using the symmetric matrix\n$$\n\\mathbf D^{-1/2}\\mathbf A\\mathbf D^{-1/2}.\n$$\nTo confront FEM and HKGL filtering we filter a unit mass signal \\\\$\\mathbf{f}=(0,0,...0,1,0,...,0)^\\intercal$ with the \\textit{diffusion} filter $\\exp{(-\\tau \\mathbf L)}$. It was chosen a very irregular sampling scheme, shown in figure \\ref{fig:FEM lumped symmetric diffusion on irregular sampling}. It can be seen how the full HKGL compresses the signal around the equator where the sampling scheme is more sparse; on the other hand the FEM filtering manages to keep the diffusion homogeneous no matter the asymmetry in the sampling scheme. \nThe mean equivariance error using by spherical harmonic degree can be found in figure \\ref{fig:Equivariance error of the lumped FEM Laplacian}. It can be seen how $\\mathbf D^{-1}\\mathbf A$ ha almost the same equivariance error of the full FEM Laplacian $\\mathbf B^{-1}\\mathbf A$, while using the symmetric matrix $\\mathbf D^{-1/2}\\mathbf A \\mathbf D^{-1/2}$ makes the equivariance error much worse, especially at lower frequencies.\n\\clearpage\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{figs/Chapter3/diffusion.png}\n\t\\caption{\\label{fig:FEM lumped symmetric diffusion on irregular sampling}Symmetric lumped linear FEM diffusion and HKGL diffusion on an irregular sampling scheme of the sphere. The position of the filtered source signal is indicated with a black star.}\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/LumpedFEMLaplacianonequiangularsampling.png}\n\t\\includegraphics[width=\\textwidth]{../codes/06.Equivariance_error/SymmetriclumpedFEMLaplacianonequiangularsampling.png}\n\t\\caption{\\label{fig:Equivariance error of the lumped FEM Laplacian}Equivariance error of the lumped FEM Laplacian and of the symmetric lumped FEM Laplacian on the equiangular sampling by spherical harmonic degree $\\ell$.}\n\\end{figure}\n\\clearpage\n\\paragraph{Accuracy of the linear FEM spherical harmonics.} Thanks to the sampling theorem \\ref{theo:equiangular sampling theorem}, we are able to compute the exact SHT (under the hypothesis of band limited signals) of the solutions to the eigenvalue problem (\\ref{eq:algebraic generalized eigenvalue problem}) and we show in figures \\ref{fig:FEMHealpix}, \\ref{fig:FEMequiangular} the power spectrum of the eigenmodes for both HEALPix sampling and the equiangular sampling, as a measure of the goodness of the linear FEM approach to approximate the spherical harmonics.\n\n\\begin{figure}[h!]\t\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/HEALPix/img/linearFEM.png}\\\\\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/HEALPix/img/linearFEM_diagonal.png}\t\\\\\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/HEALPix/img/FEM_eigenvalues_16.png}\t\\\\\n\t\\caption{\t\\label{fig:FEMHealpix}Alignment of eigenspaces of the linear FEM Laplacian on HEALPix, and its spectrum for $N_{side}=16$}\n\\end{figure}\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/equiangular/normal/img/linearFEM.png}\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/equiangular/normal/img/linearFEM_diagonal.png}\t\n\t\\includegraphics[width=\\linewidth]{../codes/03.FEM_laplacian/equiangular/normal/img/FEM_eigenvalues_16.png}\t\n\t\\caption{\\label{fig:FEMequiangular}Alignment of eigenspaces of the linear FEM Laplacian on the equiangular sampling, and its spectrum for $bw=32$}\n\\end{figure}\n\n\\clearpage\n\n\n\n\n\n\n", "meta": {"hexsha": "2e357dc633541e384cf98af6500f120f14de7273", "size": 24663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/3.Chapter2.tex", "max_stars_repo_name": "MartMilani/PDM", "max_stars_repo_head_hexsha": "cca07a8485c6933361536286279ae6c7e14d7fa1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PDF/3.Chapter2.tex", "max_issues_repo_name": "MartMilani/PDM", "max_issues_repo_head_hexsha": "cca07a8485c6933361536286279ae6c7e14d7fa1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PDF/3.Chapter2.tex", "max_forks_repo_name": "MartMilani/PDM", "max_forks_repo_head_hexsha": "cca07a8485c6933361536286279ae6c7e14d7fa1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.2589641434, "max_line_length": 1692, "alphanum_fraction": 0.7469894173, "num_tokens": 7167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658104908603, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.6486463303941917}}
{"text": "\\subsubsection{Short Range Cusp Form}\n\\label{sec:onebodyjastrowsrcusp}\n\nThe idea behind this functor is to encode nuclear cusps and other details at very\nshort range around a nucleus in the region that the Gaussian orbitals of quantum\nchemistry are not capable of describing correctly.\nThe functor is kept short ranged, because outside this small region, quantum chemistry\norbital expansions are already capable of taking on the correct shapes.\nUnlike a pre-computed cusp correction, this optimizable functor can respond to\nchanges in the wave function during VMC optimization.\nThe functor's form is\n\\begin{equation}\n\\label{srcuspform}\nu(r) = -\\exp{\\left(-r/R_0\\right)} \\left( A R_0 + \\sum_{k=0}^{N-1} B_k \\frac{ (r/R_0)^{k+2} }{ 1 + (r/R_0)^{k+2} } \\right)\n\\end{equation}\nin which $R_0$ acts as a soft cutoff radius ($u(r)$ decays to zero quickly beyond roughly this distance)\nand $A$ determines the cusp condition.\n\\begin{equation}\n\\label{srcusplimit}\n\\lim_{r \\to 0} \\frac{\\partial u}{\\partial r} = A\n\\end{equation}\nThe simple exponential decay is modified by the $N$ coefficients $B_k$ that define\nan expansion in sigmoidal functions, thus adding detailed structure in a short-ranged\nregion around a nucleus while maintaining the correct cusp condition at the nucleus.\nNote that sigmoidal functions are used instead of, say, a bare polynomial expansion, as they\ntrend to unity past the soft cutoff radius and so interfere less with the exponential decay\nthat keeps the functor short ranged.\nAlthough $A$, $R_0$, and the $B_k$ coefficients can all be optimized as variational\nparameters, $A$ will typically be fixed as the desired cusp condition is known.\n\nTo specify this one-body Jastrow factor, use an input section like the following.\n\n\\begin{lstlisting}[style=QMCPXML]\n<jastrow name=\"J1Cusps\" type=\"One-Body\" function=\"shortrangecusp\" source=\"ion0\" print=\"yes\">\n  <correlation rcut=\"6\" cusp=\"3\" elementType=\"Li\">\n    <var id=\"LiCuspR0\" name=\"R0\" optimize=\"yes\"> 0.06 </var>\n    <coefficients id=\"LiCuspB\" type=\"Array\" optimize=\"yes\">\n      0 0 0 0 0 0 0 0 0 0\n    </coefficients>\n  </correlation>\n  <correlation rcut=\"6\" cusp=\"1\" elementType=\"H\">\n    <var id=\"HCuspR0\" name=\"R0\" optimize=\"yes\"> 0.2 </var>\n    <coefficients id=\"HCuspB\" type=\"Array\" optimize=\"yes\">\n      0 0 0 0 0 0 0 0 0 0\n    </coefficients>\n  </correlation>\n</jastrow>\n\\end{lstlisting}\n\nHere ``rcut'' is specified as the range beyond which the functor is assumed to be zero.\nThe value of $A$ can either be specified via the ``cusp'' option as shown above, in\nwhich case its optimization is disabled, or through its own ``var'' line as\nfor $R_0$, in which case it can be specified as either optimizable (``yes'')\nor not (``no'').\nThe coefficients $B_k$ are specified via the ``coefficients'' section,\nwith the length $N$ of the expansion determined automatically based on the length\nof the array.\n\nNote that this one-body Jastrow form can (and probably should) be used in conjunction\nwith a longer ranged one-body Jastrow, such as a spline form.\nBe sure to set the longer-ranged Jastrow to be cusp-free!\n", "meta": {"hexsha": "fc4b39aa666346cc06f36365dc80dd74889c03c4", "size": 3080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "legacy_manual/jastrow_one_body_srcusp.tex", "max_stars_repo_name": "djstaros/qmcpack", "max_stars_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "legacy_manual/jastrow_one_body_srcusp.tex", "max_issues_repo_name": "djstaros/qmcpack", "max_issues_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "legacy_manual/jastrow_one_body_srcusp.tex", "max_forks_repo_name": "djstaros/qmcpack", "max_forks_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.6774193548, "max_line_length": 121, "alphanum_fraction": 0.7454545455, "num_tokens": 877, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.64855918828401}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Random points in the plane}\\label{sec:joint}\n\nLet $X$ and $Y$ be random variables on the same probability space.\n\n% defn: joint distributions\n\\begin{definition}\n\\ben\n\\it The \\emph{joint distribution} of $X$ and $Y$ is the function $\\prob_{X,Y}$ defined on pairs of subsets of $\\R$ by\n\\[\n\\prob_{X,Y}(C,D) = \\prob(X\\in C, Y\\in D).\n\\]\n\\it The distributions $\\prob_X(C)=\\prob(X\\in C)$ and $\\prob_Y(D)=\\prob(Y\\in D)$ are called the \\emph{marginal distributions} of $X$ and $Y$ respectively.\n\\een\n\\end{definition}\n\n%The joint distribution of $X$ and $Y$ is completely determined by their joint CDF.\n% defn: joint distributions\n\\begin{definition}\n\\ben\n\\it The \\emph{joint CDF} of $X$ and $Y$ is the function $F_{X,Y}:\\R^2\\to[0,1]$ given by\n\\[\nF_{X,Y}(x,y) = \\prob(X\\leq x,Y\\leq y).\n\\]\n\\it The CDFs $F_X(x)=\\prob(X\\leq x)$ and $F_Y(y)=\\prob(Y\\leq y)$ are called the \\emph{marginal CDFs} of $X$ and $Y$ respectively.\n\\een\n\\end{definition}\n\n% defn: jointly discrete\n\\begin{definition}\n\\ben\n\\it $X$ and $Y$ are called \\emph{jointly discrete} if the random vector $(X,Y)$ takes only countably many values in $\\R^2$, in which case they are described by their \\emph{joint PMF},\n\\[\n\\begin{array}{cccl}\nf_{X,Y}:\t& \\R^2\t& \\to\t\t& [0,1] \\\\\n\t\t\t& (x,y)\t& \\mapsto\t& \\prob(X=x,Y=y).\n\\end{array}\n\\]\n\\it The PMFs $f_X(x)=\\prob(X=x)$ and $f_Y(y)=\\prob(Y=y)$ are called the \\emph{marginal PMFs} of $X$ and $Y$ respectively.\n\\een\n\\end{definition}\n\n% defn: jointly continuous\n\\begin{definition}\n\\ben\n\\it $X$ and $Y$ are called \\emph{jointly continuous} if their joint CDF can be written as\n\\[\nF_{X,Y}(x,y) = \\int_{-\\infty}^x\\int_{-\\infty}^y f_{X,Y}(u,v)\\,du\\,dv \\text{\\qquad for all $x,y\\in\\R$,}\n\\]\nfor some integrable function $f_{X,Y}:\\R^2\\to[0,\\infty)$ called the \\emph{joint PDF} of $X$ and $Y$. \n\\it The PDFs $f_X(x)=F'_X(x)$ and $f_Y(y)=F'_Y(y)$ are called the \\emph{marginal PDFs} of $X$ and $Y$ respectively, where $F_X(x)$ and $F_Y(y)$ are their marginal CDFs. Note that\n\\[\nf_X(x) = \\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)\\,dy\n\\text{\\qquad and\\qquad}\nf_Y(y) = \\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)\\,dx.\n\\]\n\\een\n\n\\end{definition}\n\n%-----------------------------\n\\subsection{Independence}\n\nRecall that two events $A$ and $B$ are \\emph{independent} if $\\prob(A\\cap B)=\\prob(A)\\prob(B)$.\n\n% defn: independence\n\\begin{definition}\nTwo random variables $X$ and $Y$ are said to be \\emph{independent} if the events $\\{X\\leq x\\}$ and $\\{Y\\leq y\\}$ are independent for all $x,y\\in\\R$.\n\\end{definition}\n\n\\begin{lemma}\\label{lem:product_marginal_cdfs}\n\\ben\n\\it $X$ and $Y$ are independent if and only if $F_{X,Y}(x,y) = F_X(x)F_Y(y)$ for all $x,y\\in\\R$.\n\\it If $X$ and $Y$ are jointly discrete, they are independent if and only if $f_{X,Y}(x,y) =f_X(x) f_Y(y)$ for all $x,y\\in\\R$.\n\\it If $X$ and $Y$ are jointly continuous, they are independent if and only if $f_{X,Y}(x,y) = f_X(x)f_Y(y)$ for all $x,y\\in\\R$ and $\\supp(f_{X,Y})$ is a rectangular region in $\\R^2$.\n\\een\n%\\ben\n%\\it $X$ and $Y$ are independent if and only if \n%    \\bit\n%    \\it $F_{X,Y}(x,y) = F_X(x)F_Y(y)$ for all $x,y\\in\\R$.\n%    \\eit\n%\\it If $X$ and $Y$ are jointly discrete, they are independent if and only if \n%    \\bit\n%    \\it $f_{X,Y}(x,y) =f_X(x) f_Y(y)\\quad\\text{for all}\\quad x,y\\in\\R$.\n%    \\eit\n%\\it If $X$ and $Y$ are jointly continuous, they are independent if and only if\n%    \\bit\n%    \\it $f_{X,Y}(x,y) = f_X(x)f_Y(y)$ for all $x,y\\in\\R$, and\n%    \\it the support of $f_{X,Y}$ is a rectangular region in $\\R^2$.\n%    \\eit\n%\\een\n\\end{lemma}\n\\begin{proof}\nThe first two parts follow directly from the definitions. For the jointly continuous case,\n\\bit\n\\it because $X$ and $Y$ are independent, $F_{X,Y}(x,y)=F_X(x)F_Y(y)$, and differentiating both sides with respect to $x$ and $y$ we get $f_{X,Y}(x,y)=f_X(x)f_Y(y)$. \n\\it If the value taken by $X$ affects the range of values taken by $Y$, then $Y$ clearly dependes on $X$. Thus for $X$ and $Y$ to be independent we need that\n\\[\n\\supp(f_{X,Y}) = \\supp(f_X)\\times \\supp(f_Y),\n\\]\nwhich is a rectangular region in $\\R^2$.\n\\eit\n\\end{proof}\n\n% example: discrete\n\\begin{exercise}\\label{exc:joint_disc}\nA fair die is rolled once. Let $\\omega$ denote the outcome, and consider the random variables\n\\[\nX(\\omega) = \\left\\{\\begin{array}{cl}\n\t1 & \\text{ if $\\omega$ is odd}, \\\\\n\t2 & \\text{ if $\\omega$ is even},\n\\end{array}\\right. \n\\text{\\quad and\\quad}\nY(\\omega) = \\left\\{\\begin{array}{cl}\n\t1 & \\text{ if $\\omega\\leq 3$}, \\\\\n\t2 & \\text{ if $\\omega\\geq 4$}.\n\\end{array}\\right.\n\\]\nFind the joint PMF of $X$ and $Y$. Are $X$ and $Y$ independent?\n\\begin{solution}\n\\[\n\\begin{array}{c|cc|c}\n\t\t& Y=1 \t& Y=2\t& f_X\t\\\\ \\hline\nX=1\t\t& 1/3\t& 1/6\t& 1/2\t\\\\ \nX=2\t\t& 1/6 \t& 1/3\t& 1/2 \t\\\\ \\hline\t\nf_Y\t\t& 1/2\t& 1/2\t& \t\t\\\\ \n\\end{array}\n\\]\n$X$ and $Y$ are \\emph{not} independent, because (for example) \n\\[\n\\prob(X=1,Y=1)\\neq\\prob(X=1)\\prob(Y=1).\n\\]\n\\end{solution}\n\\end{exercise}\n\n% example: continuous\n\\begin{example}\nLet $X$ and $Y$ be jointly continuous random variables with the following joint PDF:\n\\[\nf_{X,Y}(x,y) = \n\\left\\{\\begin{array}{ll}\n\tc(1-x)y\t& \\text{for } 0\\leq y \\leq x \\leq 1, \\\\\n\t0\t\t& \\text{otherwise.}\n\\end{array}\\right.\n\\]\n\\ben\n\\it Sketch the support of $f_{X,Y}$.\n\\it Are $X$ and $Y$ independent?\n\\it Find the marginal PDFs of $X$ and $Y$, and show that $c=24$.\n%\\it Show that $c=24$.\n\\een\n\\end{example}\n\n\\begin{solution}\n\\ben\n\\it % << (a)\n$\\supp(f_{X,Y})$ is the triangular region bounded by the lines $y=x$, $y=0$ and $x=1$.\n\\it % << (d)\nThe support of $f_{X,Y}$ is not a rectangular region in $\\R^2$, so $X$ and $Y$ cannot be independent.\n\\it % << (c)\nThe marginal PDFs are:\n\\[\\begin{array}{lll}\nf_X(x) \t\n\t& = 24\\int_0^x (1-x)y\\,dy \n\t= 24(1-x)\\left[\\frac{y^2}{2}\\right]_0^x \n\t& = \\begin{cases}\n\t\t12x^2(1-x) & 0\\leq x\\leq 1, \\\\\n\t\t0\t\t\t& \\text{otherwise.}\n\t\t\\end{cases} \\\\[3ex]\nf_Y(y) \t\n\t& = 24\\int_y^1 (1-x)y\\,dx \n\t= 24y\\left[x - \\frac{x^2}{2}\\right]_y^1 \n\t& = \\begin{cases}\n\t\t12y(1-y)^2 & 0\\leq y\\leq 1, \\\\\n\t\t0\t\t\t& \\text{otherwise.}\n\t\t\\end{cases}\n\\end{array}\\]\n\\it % << (b)\n\\bit\n\\it For fixed $x\\in[0,1]$, we must have $0\\leq y\\leq x$.\n\\it For fixed $y\\in[0,1]$, we must have $y\\leq x\\leq 1$.\n\\eit\n\\[\n\\int_{-\\infty}^{\\infty}\\left(\\int_{-\\infty}^{\\infty}f_{X,Y}(x,y)\\,dy\\right)\\,dx\n\t= \\int_0^1\\int_0^x c(1-x)y\\,dy\\,dx \n\t= \\frac{c}{2}\\int_0^1 x^2-x^3\\,dx\n%\t= \\frac{c}{2}\\left(\\frac{1}{3}-\\frac{1}{4}\\right)\n\t= \\frac{c}{24}.\n\\]\nBy the law of total probability this must equal $1$, so $c=24$.\n\\een\n\\end{solution}\n\n", "meta": {"hexsha": "ffce862f1b7dc8cc45041c4475a9aa80b8341556", "size": 6479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/05A_joint_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/05A_joint_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/05A_joint_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": 33.056122449, "max_line_length": 183, "alphanum_fraction": 0.6156814323, "num_tokens": 2618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8558511396138366, "lm_q1q2_score": 0.6485591762483519}}
{"text": "\\documentclass[paper.tex]{subfiles}\n\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{tabularx}\n\\usepackage{multicol}\n\\usepackage{algpseudocode}\n\\usepackage{algorithm}\n\n% Add vertical spacing to tables\n\\renewcommand{\\arraystretch}{1.4}\n\n% Begin Document\n\\begin{document}\n\n\\section{$LU$ Factorization}\n\nThe first method to solve this system of equations will be $LU$ Factorization.\nThis involves decomposing the coefficient matrix $A$ into two factors, $L$ and $U$, resulting in an equation of the form $A = LU$.\nDoing so gives:\n\\begin{equation*}\n    \\begin{bmatrix}\n        1 & 0 & 0 & 0 & 0 \\\\\n        \\frac{1}{2} & 1 & 0 & 0 & 0 \\\\\n        \\frac{1}{2} & -1 & 1 & 0 & 0 \\\\\n        0 & -2 & 1 & 1 & 0 \\\\\n        0 & 2 & -\\frac{3}{2} & -1 & 1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        2 & 1 & 0 & 0 & 0 \\\\\n        0 & \\frac{1}{2} & -1 & 0 & -1 \\\\\n        0 & 0 & -2 & 0 & -2 \\\\\n        0 & 0 & 0 & 1 & 1 \\\\\n        0 & 0 & 0 & 0 & 1 \n    \\end{bmatrix}\n\\end{equation*}\n\nUsing the $LU$ decomposition it's possible to decompose the original matrix equation into two separate equations:\n\\begin{equation}\n    Ux = y\n\\end{equation}\n\\begin{equation}\n    Ly = b\n\\end{equation}\n\nWe must first solve for $y$ in equation (3). \n\\begin{equation}\n    y = L^{-1}b\n\\end{equation}\n\nThis requires the inverse of $L$, which is:\n\\begin{equation*}\n    L^{-1}=\\begin{bmatrix}\n        1 & 0 & 0 & 0 & 0 \\\\\n        -\\frac{1}{2} & 1 & 0 & 0 & 0 \\\\\n        -1 & 1 & 1 & 0 & 0 \\\\\n        0 & 1 & -1 & 1 & 0 \\\\\n        -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & 1 & 1 \n    \\end{bmatrix}\n\\end{equation*}\n\nPlugging in values for equation (4) gives:\n\\begin{equation*}\n    y = \\begin{bmatrix}\n        1 & 0 & 0 & 0 & 0 \\\\\n        -\\frac{1}{2} & 1 & 0 & 0 & 0 \\\\\n        -1 & 1 & 1 & 0 & 0 \\\\\n        0 & 1 & -1 & 1 & 0 \\\\\n        -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & 1 & 1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        100 \\\\\n        0 \\\\\n        -50 \\\\\n        120 \\\\\n        0\n    \\end{bmatrix}\n    =\\begin{bmatrix}\n        100 \\\\\n        -50 \\\\\n        -150 \\\\\n        170 \\\\\n        45 \n    \\end{bmatrix}\n\\end{equation*}\n\nIn order to compute for $x$, we rearrange equation (2) into:\n\\begin{equation}\n    x = U^{-1}y\n\\end{equation}\n\nCalculating the inverse of $U$ gives:\n\\begin{equation*}\n    U^{-1}=\\begin{bmatrix}\n        \\frac{1}{2} & -1 & \\frac{1}{2} & 0 & 0 \\\\\n        0 & 2 & -1 & 0 & 0 \\\\\n        0 & 0 & -\\frac{1}{2} & 0 & -1 \\\\\n        0 & 0 & 0 & 1 & -1 \\\\\n        0 & 0 & 0 & 0 & 1 \n    \\end{bmatrix}\n\\end{equation*}\n\nAs given in equation (5), the product of the values of $U^{-1}$ and $y$ gives the solution $x$:\n\\begin{equation*}\n    x = \\begin{bmatrix}\n        25 \\\\\n        50 \\\\ \n        30 \\\\ \n        125 \\\\\n        45\n    \\end{bmatrix}\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "eb1a5e5aede3733d343fc56900c30159807d8c73", "size": 2814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Projects/matrix_theory/docs/tex/lu_factorization.tex", "max_stars_repo_name": "Bkrenz/calu-mat341", "max_stars_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Projects/matrix_theory/docs/tex/lu_factorization.tex", "max_issues_repo_name": "Bkrenz/calu-mat341", "max_issues_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Projects/matrix_theory/docs/tex/lu_factorization.tex", "max_forks_repo_name": "Bkrenz/calu-mat341", "max_forks_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_forks_repo_licenses": ["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.0512820513, "max_line_length": 130, "alphanum_fraction": 0.5074626866, "num_tokens": 1097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6484231843680545}}
{"text": "% A simple template for LaTeX documents\n% \n% To produce pdf run:\n%   $ pdflatex paper.tex \n%\n\n\\documentclass[10pt, twocolumn]{article}\n%\\documentclass[12pt]{article}\n\n% Begin paragraphs with new line\n\\usepackage{parskip}  \n\n% Change margin size\n\\usepackage[margin=0.5in]{geometry}   \n\n% Graphics Example:  (PDF's make for good plots)\n\\usepackage{graphicx}               \n% \\centerline{\\includegraphics{figure.pdf}}\n\n% Allows hyperlinks\n\\usepackage{hyperref}\n\n% Blocks of code\n\\usepackage{listings}\n\\lstset{basicstyle=\\ttfamily, title=\\lstname}\n% Insert code like this. replace `plot.R` with file name.\n% \\lstinputlisting{plot.R}\n\n% Monospaced fonts\n%\\usepackage{inconsolata}\n% GNU \\texttt{make} is a nice tool.\n\n% Supports proof environment\n\\usepackage{amsthm}\n\n% Allows writing \\implies and align*\n\\usepackage{amsmath}\n\n% Allows mathbb{R}\n\\usepackage{amsfonts}\n\n% Numbers in scientific notation\n\\usepackage{siunitx}\n\n% Use tables generated by pandas\n\\usepackage{booktabs}\n\n% norm and infinity norm\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\\newcommand{\\inorm}[1]{\\left\\lVert#1\\right\\rVert_\\infty}\n\n% Statistics essentials\n\\newcommand{\\iid}{\\text{ iid }}\n\\newcommand{\\Expect}{\\operatorname{E}}\n\\newcommand{\\Var}{\\operatorname{Var}}\n\\newcommand{\\Cov}{\\operatorname{Cov}}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n\\textbf{Binomial}\n$X \\sim B(n, p)$\n\\[\n    p(k) = \\binom{n}{k} p^k (1-p)^{n-k}\n    \\qquad k = 0, 1, \\dots, n\n\\]\n$\\Expect X = np, \\quad \\Var X = np(1-p)$\n\nmgf: $M_X (t) = (pe^t + 1 - p)^n$\n\nBeta is conjugate prior, Fisher info $I(p) = \\frac{1}{p(1 - p)}$\n\n\\textbf{Poisson}\n$X \\sim P(\\lambda)$\n\\[\n    p(k) = \\frac{e^{-\\lambda} \\lambda^k}{k!}\n    \\qquad k = 0, 1, \\dots\n\\]\n$\\Expect X = \\lambda, \\quad \\Var X = \\lambda$\n\nmgf: $M_X (t) = e^{\\lambda (e^t -1)}$\n\nGamma is conjugate prior, Fisher info $I(\\lambda) = \\frac{1}{\\lambda}$\n\n\\textbf{Normal}\n$X \\sim N(\\mu, \\Sigma)$, $\\Sigma$ positive definite\n\\[\n    f(x) = \\frac{\\exp\\{ - \\frac{1}{2}(x - \\mu)^T \\Sigma^{-1} (x - \\mu) \\}}\n        {(2\\pi)^{\\frac{k}{2}} \\sqrt{\\det(\\Sigma)}}\n        = \\frac{1}{\\sqrt{2 \\pi} \\sigma} e^{-\\frac{(x - \\mu)^2}{2\n        \\sigma^2}}\n\\]\nmgf: $M_X (t) = \\exp (\\mu' t + \\frac{1}{2} t' \\Sigma t)$\n\nNormal is conj. prior, Fisher info $I(\\mu, \\sigma^2) = \n[\\begin{smallmatrix}\n        1 / \\sigma^2 & 0 \\\\\n        0 & 1 / 2\\sigma^4 \\\\\n\\end{smallmatrix}]$\n\n\\textbf{Beta}\n$ X \\sim \\text{Beta}(\\alpha, \\beta)$\n\\[\n    f(x) = \\frac{x^{\\alpha-1}(1 - x)^{\\beta-1}}{B(\\alpha, \\beta)} \n    \\qquad 0 \\leq x \\leq 1\n\\]\n$\\Expect X = \\frac{\\alpha}{\\alpha + \\beta},\n\\quad \\Var X = \\frac{\\alpha \\beta}{(\\alpha + \\beta)^2 (\\alpha + \\beta + 1)}$\n\nusing the beta function:\n\\[\n    B(\\alpha, \\beta) =\n    \\frac{\\Gamma(\\alpha) \\Gamma(\\beta)}{\\Gamma(\\alpha+ \\beta)} =\n    \\int_0^1 t^{\\alpha -1} (1-t)^{\\beta - 1}dt\n\\]\n\n\\textbf{Gamma}\n$X \\sim \\text{Gamma}(\\alpha, \\beta)$\n\\[\n    f(x) = \\frac{\\beta^\\alpha x^{\\alpha-1} e^{-\\beta x}}{\\Gamma(\\alpha)}\n    \\qquad x > 0\n\\]\n$\\Expect X = \\frac{\\alpha}{\\beta},\n\\quad \\Var X = \\frac{\\alpha}{\\beta^2}$\n\nmgf: $M_X (t) = (1 - \\frac{t}{\\beta})^{-\\alpha}, t < \\beta$\n\n$X \\sim \\text{Gamma}(\\alpha, \\beta) \\iff \\beta X \\sim \\text{Gamma}(\\alpha, 1)$\n\n$X_i \\iid \\text{Gamma}(\\alpha_i, \\beta)$, then\n\\[\n    \\sum X_i \\sim \\text{Gamma}(\\sum \\alpha_i, \\beta)\n\\]\nGamma function: $\\Gamma(\\alpha) = \\int_0^\\infty t^{\\alpha-1} e^{-t} dt$.\n\n$\\Gamma(\\frac{1}{2}) = \\sqrt{\\pi}$.\n\n$\\Gamma(\\alpha + 1) = \\alpha \\Gamma(\\alpha)$\n\n$\\Gamma(k) = (k-1)!$ for $k$ positive integer.\n\n\\textbf{Exponential}\nSpecial case: $\\text{Exp}(\\lambda) \\equiv \\text{Gamma}(1, \\lambda)$\n\n\\textbf{Chi square}\nSpecial case: $\\chi^2_n \\equiv \\text{Gamma}(\\frac{n}{2}, \\frac{1}{2})$\n\nLet $Z_i$ be iid $N(0, 1)$.\n\n$\\sum_{i=1}^n Z_i^2 \\sim \\chi^2_n$\n\nNoncentral $\\chi^2$. Let $Y \\sim N(\\mu, I)$ be an $n$ vector. Then \n\\[\n    \\norm{Y}^2 \\sim \\chi^2_n(\\norm{\\mu}^2)\n\\]\n\n\\textbf{F}\n\\[\n    F(m, n) \\equiv \\frac{\\frac{\\chi^2_m}{m}}\n        {\\frac{\\chi^2_n}{n}}\n\\]\nWhere numerator and denominator are independent $\\chi^2$.\n\n\\textbf{T}\n\\[\n    t(n) = \\frac{N(0, 1)}\n    {\\sqrt{\\frac{\\chi^2_n}{n}}}\n\\]\nWhere numerator and denominator are independent.\n\n\\vspace{0.2in}\n\\hrule\n\nMoment generating functions determine distribution\n\\[\n    M_X(t) \\equiv \\Expect (e^{tX}),\n    \\quad M_X'(0) = \\Expect(X)\n\\]\n$X_i$ independently distributed $\\iff$\n\\[\n    M_{\\sum X_i} (t) = \\prod M_{X_i} (t)\n\\]\n\\textbf{Characteristic function}\n\\[\n    \\phi(t) = \\Expect (e^{i t^T X)}\n    = \\Expect (\\cos (t^T X)) + i \\Expect(\\sin(t^T X))\n\\]\nOrder statistics for sorted sample $X_{(1)}, \\dots, X_{(n)}$ has pdf:\n\\[\n    n! \\prod_{i=1}^n f(X_{(i)}) \\quad I(X_{(1)} < \\dots < X_{(n)})\n\\]\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\textbf{Jensen's Inequality} if $S \\subset R^k$ convex and closed, $g$ convex on $S$, $P[X\n\\in S] = 1$, and $\\Expect X$ is finite, then $\\Expect X \\in S$, $\\Expect\ng(X)$ exists, and\n\\[\n    \\Expect g(X) \\geq g(\\Expect X)\n\\]\n\\textbf{Holder's Inequality} if $r, s > 1$ and $\\frac{1}{r} + \\frac{1}{s} =\n1$ then\n\\[\n    \\Expect |XY| \\leq (\\Expect |X|^r)^{\\frac{1}{r}}(\\Expect |X|^s)^{\\frac{1}{s}}\n\\]\n\n$T(X)$ Sufficient means the distribution of $X | T(X)$ does not depend on\n$\\theta$.\n\nFactorization theorem: $T(x)$ is sufficient $\\iff$\n\\[\n    f_{\\theta}(x) = h(x) g(\\theta, T(x))\n\\]\n$L_x (\\theta) = p_\\theta (x) = p(x, \\theta)$ likelihood is function of\n$\\theta$, density is function of $x$.\n\nThe likelihood ratio\n\\[\n    \\lambda_x (\\theta) = \\frac{L_x (\\theta)}{L_x (\\theta_0)}\n\\]\nis minimal sufficient. To show $T(x)$ is minimal sufficient show that it is\nsufficient and a function of the likelihood $\\lambda_x (\\theta)$.\n\n\\textbf{Fisher information}\n\\[\n    I(\\theta) = \\Expect_\\theta \\left[ \\frac{\\partial}{\\partial \\theta} \n    \\log L_X (\\theta) \\right]^2\n    = \\Expect_\\theta \\left[ - \\frac{\\partial^2}{\\partial \\theta^2}\n    \\log L_X (\\theta) \\right]\n\\]\n$\\text{bias } \\hat{v} \\equiv \\Expect (\\hat{v}) - v$\n\\[\n    MSE(\\hat{v}) \\equiv \\Expect (\\hat{v} - v)^2 \n    = \\Var (\\hat{v}) + (\\text{bias } \\hat{v})^2\n\\]\n\\textbf{Rao-Blackwell} Let $S(X)$ be an unbiased point estimator for\n$g(\\theta)$. Conditioning on a sufficient statistic $T(X)$ reduces\nvariance.\n\\[\n    \\Var_{\\theta} (S(X)) \\geq \\Var_{\\theta} (\\Expect (S(X) | T(X)))\n\\]\nAlso holds for more general convex loss function $L$:\n\\[\n    R(\\theta, S) \\equiv \\Expect_{\\theta} L(\\theta, S(X)) \\geq\n    \\Expect_{\\theta} L(\\theta, \\Expect( S(X) | T(X)))\n\\]\n\\textbf{Completeness} $T(X)$ is complete if $\\Expect g(T(X)) = 0$ \nimplies $g = 0$ almost surely for all $\\theta$.\n\n\\textbf{Cramer Rao Inequality} Let $g: \\Theta \\rightarrow R$. Suppose there\nexists an unbiased estimator $U(X)$, $\\Expect U(X) = g(\\theta)$. Then\n\\[\n    \\Var_\\theta U(X) \\geq \n    \\left( \\frac{\\partial g(\\theta)}{\\partial \\theta} \\right)^T\n    I(\\theta)^{-1}\n    \\left( \\frac{\\partial g(\\theta)}{\\partial \\theta} \\right)\n\\]\nBasu's Theorem - If $T(X)$ complete sufficient statistic and $A(X)$ is \nancillary then $A(X)$ and $T(X)$ are independent.\n\n\\textbf{Lehmann - Scheffe} Suppose $T(X)$ is complete sufficient. Then\nthere exists unique unbiased estimator $\\Expect h(T(x))$ of $g(\\theta) \\in\nR$ with smallest variance (MVUE). \n\n\\textbf{Exponential Families} $T(x)$ is natural sufficient statistic and is\ncomplete sufficient if the $k$ parameter exponential family is full rank.\n\\[\n    p(x, \\theta) = h(x) \\exp \\{ \\eta(\\theta)^T T(x) - B(\\theta) \\}\n\\]\nCanonical form model indexed by $\\eta$.\n\\[\n    q(x, \\eta) = h(x) \\exp \\{ \\eta^T T(x) - A(\\eta) \\}\n\\]\n\\[\n    \\dot{A} (\\eta) = \\Expect_\\eta (T(X)) \\quad\n    \\ddot{A} (\\eta) = I(\\eta) = \\Var_\\eta (T(X))\n\\]\nThen moment generating function for $T(X)$ is\n\\[\n    M_{T(X)}(t) = \\exp \\{A(t + \\eta) - A(\\eta) \\}\n\\]\nEquivalent statements useful for GLM's such as $Y \\sim N(X \\beta,\n\\sigma_0^2 I)$, where $Z$ is $n \\times p$:\n\n1. $I(\\beta) = \\frac{1}{\\sigma_0^2} X^T X$ positive definite\n2. rank$(X) = p$\n3. model is identifiable. More generally another equivalent statement is\n$\\Var (T(X)) = \\ddot{A} (\\eta)$ is positive definite.\n\n\\subsection*{Decision Theory}\n\n\\textbf{Decision rule} $\\delta: \\mathcal{X} \\rightarrow \\mathcal{A}$, where \n$\\delta \\in \\mathcal{D}$, the space of possible decision rules and\n$\\mathcal{A}$ is the action space.\n\n\\textbf{Loss function} $l: \\Theta \\times \\mathcal{A} \\rightarrow \\mathbb{R}^+$\nPosterior mean minimizes square error loss; median minimizes absolute loss.\n\n\\textbf{Risk function} $R: \\Theta \\times \\mathcal{D} \\rightarrow\n\\mathbb{R}^+$ expected loss for a particular value of $\\theta$\n\\[\n    R(\\theta, \\delta) = \\Expect_\\theta l(\\theta, \\delta(X)) = \\int\n    l(\\theta, \\delta(x)) \\cdot p_\\theta (x) dx\n\\]\nBayes setup:\n\\[\n    \\pi(\\theta | x) = \\frac{p_\\theta (x) \\pi(\\theta)}{m(x)}\n\\]\n\\textbf{Bayes decision rule} If there exists $\\delta_\\pi \\in \\mathcal{D}$\nw.r.t prior $\\pi$ such that\n\\[\n    r(\\pi, \\delta_\\pi) = \\inf_{\\delta \\in \\mathcal{D}} r(\\pi, \\delta)\n\\]\nTo find Bayes rule minimize the posterior risk:\n\\[\n    \\delta_\\pi (x) = \\min_{a \\in \\mathcal{A}} r_\\pi (a | x)\n\\]\n\n\\textbf{Bayes risk} $r_\\pi : \\mathcal{D} \\rightarrow\n\\mathbb{R}^+$ expected loss for fixed prior $\\pi$\n\\[\n    r_\\pi (\\delta) = \\Expect_\\pi R(\\theta, \\delta) \n    = \\int_\\Theta R(\\theta, \\delta) \\pi (d \\theta)\n    = \\int_\\mathcal{X} r_\\pi(\\delta(x) | x) m(x) dx\n\\]\nTo find Bayes risk: 1) find the Bayes rule 2) compute the risk function 3)\ntake the expectation of the risk wrt prior $\\pi$.\n\n\n\\textbf{Minimax} decision rule $\\delta^*$ minimizes the worst case\nscenario, satisfies\n\\[\n    \\sup_{\\theta} R(\\theta, \\delta^*) = \\inf_{\\delta} \\sup_{\\theta}\n    R(\\theta, \\delta)\n\\]\nTo show $\\delta^*$ is minimax, first check for constant risk $R(\\theta,\n\\delta^* = c$ for all $\\theta$, then find a\nprior $\\pi$ such that $\\delta^*$ is the Bayes rule. This $\\pi$ is least\nfavorable. More generally can find\na sequence of priors $(\\pi_k)$ such that the Bayes risk $r_{\\pi_k}\n(\\delta_{\\pi_k}) \\rightarrow c$.\n\n\\newpage\n\n\\subsection*{Multivariate Normal}\n\nStein's formula: $X \\sim N(\\mu, \\sigma)$\n\\[\n    \\Expect (g(X) (X - \\mu)) = \\sigma^2 \\Expect(g'(X))\n\\]\nassuming these expectations are finite.\n\n$X \\sim N(\\mu, \\Sigma)$, $A$ an $m \\times n$ matrix,\nthen \n\\[\n    AX \\sim N(A \\mu, A \\Sigma A^t)\n\\]\nFor $\\Sigma$ full rank it's possible to transform between $Z \\sim\nN(0, I)$ and $X$:\n\\[\n    X = \\Sigma^{1/2} Z + \\mu \\qquad Z = \\Sigma^{-1/2} (X - \\mu)\n\\]\nIn block matrix form:\n\\[\n    X =\n    \\begin{bmatrix}\n        X_1 \\\\\n        X_2 \\\\\n    \\end{bmatrix}\n    \\sim N \\left(\n    \\begin{bmatrix}\n        \\mu_1 \\\\\n        \\mu_2 \\\\\n    \\end{bmatrix}\n    ,\n    \\begin{bmatrix}\n        \\Sigma_{11} & \\Sigma_{12} \\\\\n        \\Sigma_{21} & \\Sigma_{22} \\\\\n    \\end{bmatrix}\n\\right)\n\\]\nAssuming $\\Sigma_{11}$ is positive definite then the conditional\ndistribution\n\\[\n    X_2 | X_1 \\sim N(\\mu_2 + \\Sigma_{21} \\Sigma_{11}^{-1} (X_1 - \\mu_1),\n    \\Sigma_{22} - \\Sigma_{21} \\Sigma_{11}^{-1} \\Sigma_{12})\n\\]\n\n\\subsection*{Conditional Distributions}\n\nConditional pdf:\n\\[\n    f_{X|Y}(x, y) \\equiv \\frac{f_{X, Y}(x, y)}{f_Y(y)}\n\\]\nIterated expectation:\n\\[\n    E(Y) = E(E(Y | X))\n\\]\nConditional variance formula:\n\\[\n    \\Var(Y) = \\Var(E(Y | X)) + E(\\Var(Y | X))\n\\]\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{General Techniques}\n\nSingular Value Decompostion (SVD) Any matrix $X$ can be written\n\\[\n    X = UDV^T\n\\]\nwith $U, V$ orthogonal, and $D$ diagonal.\n\nMoore Penrose Psuedoinverse $A^+$ exists uniquely for every matrix $A$.\n\nProjection matrix $P$ are symmetric and idempotent. They have eigenvalues\neither 0 or 1.\n\\[\n    P = P^T \\qquad P^2 = P\n\\]\n\nCovariance of linear transformations\n\\[\n    Cov(Ay, Bx) = A Cov(y, x) B^T\n\\]\n$\n    A = \n    [\\begin{smallmatrix}\n        a & b \\\\\n        c & d \\\\\n    \\end{smallmatrix}]\n$\n\\[\n    A^{-1} = \n    \\frac{1}{\\det (A)}\n    \\begin{bmatrix}\n        d & -b \\\\\n        -c & a \\\\\n    \\end{bmatrix}\n\\]\n\nIntegration by parts:\n\\[\n    \\int uv' = uv - \\int u'v\n\\]\n\nTransformation theorem: Given some regularity conditions, $Y = g(X)$ has\npdf\n\\[\n    p_Y(y) = p_X(g^{-1}(y)) |J_{g^{-1}(y)}|\n\\]\n\nMatrix / Vector differentiation\n\n$\\frac{\\partial A^T \\beta}{\\partial \\beta} = A$, \n$\\frac{\\partial \\beta^T A \\beta}{\\partial \\beta} = (A + A^t) \\beta =\n2A\\beta$ for $A$ symmetric.\n\n\n\\end{document}\n", "meta": {"hexsha": "79d0f1fe56c70287b47da8ed8551d58c27cb3ff0", "size": 12228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "231a/stat_notes.tex", "max_stars_repo_name": "clarkfitzg/phd_stats", "max_stars_repo_head_hexsha": "c74b21a7fd55a713927650ce1827d1b853809395", "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": "231a/stat_notes.tex", "max_issues_repo_name": "clarkfitzg/phd_stats", "max_issues_repo_head_hexsha": "c74b21a7fd55a713927650ce1827d1b853809395", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-11-10T07:47:09.000Z", "max_issues_repo_issues_event_max_datetime": "2015-11-10T22:55:08.000Z", "max_forks_repo_path": "231a/stat_notes.tex", "max_forks_repo_name": "clarkfitzg/phd_stats", "max_forks_repo_head_hexsha": "c74b21a7fd55a713927650ce1827d1b853809395", "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.2967741935, "max_line_length": 90, "alphanum_fraction": 0.592983317, "num_tokens": 4442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936438, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6484231806063482}}
{"text": "\\title{Latent Space Models for Neural Data}\n\n\\subsection{Latent Space Models for Neural Data}\n\nMany scientific fields involve the study of network data, including\nsocial networks, networks in statistical physics, biological\nnetworks, and information networks\n\\citep{newman2010networks,goldenberg2010survey}.\n\nWhat we can learn about nodes in a network from their connectivity patterns?\nWe can begin to study this using a latent space model \\citep{hoff2002latent}.\nLatent space models embed nodes in the network in a latent space,\nwhere the likelihood of forming an edge between two nodes depends on\ntheir distance in the latent space.\n\nWe will analyze network data from neuroscience.\nAn interactive version with Jupyter notebook is available\n\\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/latent_space_models.ipynb}{here}.\n\n\\subsubsection{Data}\n\nThe data comes from \\href{http://www-personal.umich.edu/~mejn/netdata/}{Mark Newman's repository}.\nIt is a weighted, directed network representing the neural network of\nthe nematode\n\\href{https://en.wikipedia.org/wiki/Caenorhabditis_elegans}{C.~Elegans}\ncompiled by \\citet{watts1998collective} using experimental data\nby \\citet{white1986structure}.\n\nThe neural network consists of around $300$ neurons. Each connection\nbetween neurons\nis associated with a weight (positive integer) capturing the strength\nof the connection.\n\nFirst, we load the data.\n\\begin{lstlisting}[language=Python]\nfrom observations import celegans\n\nx_train = celegans(\"~/data\")\n\\end{lstlisting}\n\n\\subsubsection{Model}\n\nWhat can we learn about the neurons from their connectivity patterns? Using\na latent space model \\citep{hoff2002latent}, we will learn a latent\nembedding for each neuron to capture the similarities between them.\n\nEach neuron $n$ is a node in the network and is associated with a latent\nposition $z_n\\in\\mathbb{R}^K$.\nWe place a Gaussian prior on each of the latent positions.\n\nThe log-odds of an edge between node $i$ and\n$j$ is proportional to the Euclidean distance between the latent\nrepresentations of the nodes $|z_i- z_j|$. Here, we\nmodel the weights ($Y_{ij}$) of the edges with a Poisson likelihood.\nThe rate is the reciprocal of the distance in latent space. The\ngenerative process is as follows:\n\n\\begin{enumerate}\n\\item\nFor each node $n=1,\\ldots,N$,\n\\begin{align}\nz_n \\sim N(0,I).\n\\end{align}\n\\item\nFor each edge $(i,j)\\in\\{1,\\ldots,N\\}\\times\\{1,\\ldots,N\\}$,\n\\begin{align}\nY_{ij} \\sim \\text{Poisson}\\Bigg(\\frac{1}{|z_i - z_j|}\\Bigg).\n\\end{align}\n\\end{enumerate}\n\nIn Edward, we write the model as follows.\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Normal, Poisson\n\nN = x_train.shape[0]  # number of data points\nK = 3  # latent dimensionality\n\nz = Normal(loc=tf.zeros([N, K]), scale=tf.ones([N, K]))\n\n# Calculate N x N distance matrix.\n# 1. Create a vector, [||z_1||^2, ||z_2||^2, ..., ||z_N||^2], and tile\n# it to create N identical rows.\nxp = tf.tile(tf.reduce_sum(tf.pow(z, 2), 1, keep_dims=True), [1, N])\n# 2. Create a N x N matrix where entry (i, j) is ||z_i||^2 + ||z_j||^2\n# - 2 z_i^T z_j.\nxp = xp + tf.transpose(xp) - 2 * tf.matmul(z, z, transpose_b=True)\n# 3. Invert the pairwise distances and make rate along diagonals to\n# be close to zero.\nxp = 1.0 / tf.sqrt(xp + tf.diag(tf.zeros(N) + 1e3))\n\nx = Poisson(rate=xp)\n\\end{lstlisting}\n\n\\subsubsection{Inference}\n\nMaximum a posteriori (MAP) estimation is simple in Edward. Two lines are\nrequired: Instantiating inference and running it.\n\\begin{lstlisting}[language=Python]\ninference = ed.MAP([z], data={x: x_train})\n\\end{lstlisting}\n\nSee this extended tutorial about\n\\href{/tutorials/map}{MAP estimation in Edward}.\n\nOne could instead run variational inference. This requires specifying\na variational model and instantiating \\texttt{KLqp}.\n\\begin{lstlisting}[language=Python]\nqz = Normal(loc=tf.Variable(tf.random_normal([N * K])),\n            scale=tf.nn.softplus(tf.Variable(tf.random_normal([N * K]))))\ninference = ed.KLqp({z: qz}, data={x: x_train})\n\\end{lstlisting}\nSee this extended tutorial about\n\\href{/tutorials/variational-inference}{variational inference in Edward}.\n\nFinally, the following line runs the inference procedure for 2500\niterations.\n\\begin{lstlisting}[language=Python]\ninference.run(n_iter=2500)\n\\end{lstlisting}\n\n\\subsubsection{Acknowledgments}\n\nWe thank Maja Rudolph for writing the initial version of this\ntutorial.\n\n\\subsubsection{References}\n", "meta": {"hexsha": "30cbd35163e8c4a5c506aee885452b7d6f1194ea", "size": 4426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/latent-space-models.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-04-06T15:08:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T15:08:53.000Z", "max_issues_repo_path": "docs/tex/tutorials/latent-space-models.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/latent-space-models.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.8503937008, "max_line_length": 112, "alphanum_fraction": 0.757568911, "num_tokens": 1217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6483006538588529}}
{"text": "\\chapter{The Two- and Three-Dimensional Navier-Stokes Equations}\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Background}\nThe Navier-Stokes equations describe the motion of a fluid. In order to derive the Navier-Stokes equations we assume that a fluid is a continuum (not made of individual particles, but rather a continuous substance) and that mass and momentum are conserved. After making some assumptions and using Newton's second law on an incompressible fluid particle, the Navier-Stokes equations can be derived in their entirety. All details are omitted since there are many sources of this information, two sources that are particularly clear are Tritton~\\cite{Tri88} and Doering and Gibbon~\\cite{DoeGib95}; Gallavotti~\\cite{Gal02} should also be noted for introducing both mathematical and physical aspects of these equations, and Uecker~\\cite{Uec09} includes a quick derivation and some example Fourier Spectral Matlab codes. For a more detailed introduction to spectral methods for the Navier-Stokes equations see Canuto et al.~\\cite{CHQZ07}. The incompressible Navier-Stokes equations  are\n\\begin{eqnarray}\n\\rho \\left (\\frac{\\partial \\mathbf{u}}{\\partial t} + \\mathbf{u} \\cdot \\nabla \\mathbf{u} \\right)&=&-\\nabla p + \\mu \\Delta \\mathbf{u} + \\mathbf{f} \\label{eq:NseConMom}\\\\\n\\nabla \\cdot \\mathbf{u} &=& 0. \\label{eq:NseConMas}\n\\end{eqnarray}\nIn these equations, $\\rho$ is density, $\\mathbf{u}(x,y,z)=(u,v,w)$ is the velocity with components in the $x$, $y$ and $z$ directions, $p$ is pressure field, $\\mu$ is dynamic viscosity (constant in incompressible case) and $\\mathbf{f}$ is a body force (force that acts through out the volume). Equation \\eqref{eq:NseConMom} represents conservation of momentum and eq.\\ \\eqref{eq:NseConMas} is the continuity equation which represents conservation of mass for an incompressible fluid.  \n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{The Two-Dimensional Case}\n\nWe will first consider the two-dimensional case. A difficulty in simulating the incompressible Navier-Stokes equations is the numerical satisfaction of the incompressibility constraint in eq.\\ \\eqref{eq:NseConMas}, this is sometimes referred to as a divergence free condition or a solenoidal constraint. To automatically satisfy this incompressibility constraint in two dimensions, where\n$$\\mathbf u(x,y)=\\left(u(x,y),v(x,y)\\right)$$\nit is possible to re-write the equations using a different formulation, the stream-function vorticity formulation. In this case, we let \n$$u=\\frac{\\partial \\psi}{\\partial y}  \\quad v=-\\frac{\\partial \\psi}{\\partial x},$$ \nwhere $\\psi(x,y)$ is the streamfunction.  Level curves of the streamfunction represent streamlines\\footnote{A streamline is a continuous curve along which the instantaneous velocity is tangent, see Tritton~\\cite{Tri88} for more on this.} of the fluid field. Note that \n$$\\nabla\\cdot\\mathbf u =\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}= \\frac{\\partial^2\\psi}{\\partial x \\partial y} - \\frac{\\partial^2\\psi}{\\partial y \\partial x}=0,$$\nso eq.\\ \\eqref{eq:NseConMas} is automatically satisfied. Making this change of variables, we obtain a single scalar partial differential equation by taking the curl of the momentum equation, eq.\\ \\eqref{eq:NseConMom}. We define the vorticity $\\omega$, so that\n$$\\omega=\\nabla\\times\\mathbf u= \\frac{\\partial v}{\\partial x}-\\frac{\\partial u}{\\partial y}=-\\Delta \\psi$$\nand eq.\\ \\eqref{eq:NseConMom} becomes\n\\begin{align*}\n&{}\\hspace{2em}\n\\frac{\\partial }{\\partial x} \\left[\\rho\\left(\\frac{\\partial v}{\\partial t} +u \\frac{\\partial v}{\\partial x} +v\\frac{\\partial v}{\\partial y}\\right) \\right]\n- \\frac{\\partial }{\\partial y} \\left[\\rho\\left(\\frac{\\partial u}{\\partial t} +u \\frac{\\partial u}{\\partial x} +v\\frac{\\partial u}{\\partial y}\\right) \\right]\n\\\\&{}=\\frac{\\partial }{\\partial x} \\left[\\mu\\left(\\frac{\\partial^2 v}{\\partial x^2} + \\frac{\\partial^2 v}{\\partial y^2}\\right) + fy \\right]\n-\\frac{\\partial }{\\partial y} \\left[\\mu\\left(\\frac{\\partial^2 u}{\\partial x^2} + \\frac{\\partial^2 u}{\\partial y^2}\\right) + fx \\right]\n\\end{align*}\nwhere $fx$ and $fy$ represent the $x$ and $y$ components of the force $\\mathbf f$. Since the flow is divergence free, \n$$\\frac{\\partial u}{\\partial x}=-\\frac{\\partial v}{\\partial x}$$\nand so can simplify the nonlinear term to get\n\\begin{align*}\n&{}\\hspace{2em}\\frac{\\partial }{\\partial x} \\left[\\left( u\\frac{\\partial v}{\\partial x} +v\\frac{\\partial v}{\\partial y}\\right) \\right]\n- \\frac{\\partial }{\\partial y} \\left[\\left(u \\frac{\\partial u}{\\partial x} +v\\frac{\\partial u}{\\partial y}\\right) \\right]\n\\\\&{}=\\frac{\\partial u}{\\partial x}\\frac{\\partial v}{\\partial x}+u\\frac{\\partial^2 v}{\\partial x^2 } +\\frac{\\partial v}{\\partial x}\\frac{\\partial v}{\\partial y} + v\\frac{\\partial^2v }{\\partial x \\partial y}\n-\\frac{\\partial u}{\\partial y}\\frac{\\partial u}{\\partial x} - u\\frac{\\partial^2u }{\\partial x\\partial y} -\\frac{\\partial v}{\\partial y}\\frac{\\partial u}{\\partial y} -v \\frac{\\partial^2u }{\\partial y^2 }\n\\\\&{}= u\\left( \\frac{\\partial^2 v}{\\partial x^2 } - \\frac{\\partial^2u }{\\partial x\\partial y} \\right) + v\\left( \\frac{\\partial^2 v}{\\partial x \\partial y } - \\frac{\\partial^2u }{\\partial^2 y} \\right). \n\\end{align*}\nWe finally obtain\n\\begin{align} \\label{eq:Ns2dStrVorA}\n&{}\\hspace{1em}\\rho\\left(\\frac{\\partial \\omega}{\\partial t} + u\\frac{\\partial \\omega}{\\partial x} + v\\frac{\\partial \\omega }{\\partial y}\\right)\n =\\mu\\Delta\\omega+\\frac{\\partial fy}{\\partial x}- \\frac{\\partial fx}{\\partial y} \n \\end{align}\nand\n\\begin{align} \\label{eq:Ns2dStrVorB}\n&{}\\Delta \\psi = -\\omega.\n\\end{align}\nNote that in this formulation, the Navier-Stokes equation is like a forced heat equation for the vorticity with a nonlocal and nonlinear term. We can take advantage of this structure in finding numerical solutions by modifying our numerical programs which give approximate solutions to the heat equation.\n\nA simple time discretization for this equation is the Crank-Nicolson method, where the nonlinear terms are solved for using fixed point iteration. A tutorial on convergence of time discretization schemes for the Navier-Stokes equations can be found in Temam~\\cite{Tem01}. The time discretized equations become\n\\begin{align} \\label{eq:Ns2dStrVorACn}\n&{}\\hspace{2em}\\rho\\left[\\frac{\\omega^{n+1,k+1}-\\omega^n}{\\delta t} \\right.\n\\\\&{}\\left.+\\frac{1}{2} \\left( u^{n+1,k}\\frac{\\partial \\omega^{n+1,k}}{\\partial x} + v^{n+1,k}\\frac{\\partial \\omega^{n+1,k} }{\\partial y} \n+ u^{n}\\frac{\\partial \\omega^{n}}{\\partial x} + v^{n}\\frac{\\partial \\omega^{n} }{\\partial y} \\right)\\right] \\notag\n\\\\&{}=\\frac{\\mu}{2}\\Delta\\left(\\omega^{n+1,k+1}+\\omega^n\\right) + \\left.\\left(\\frac{\\partial fx}{\\partial y}-\\frac{\\partial fy}{\\partial x} \\right)\\right\\rvert_{t=(n+0.5)\\delta t},\\notag\n\\end{align}\nand\n\\begin{align} \\label{eq:Ns2dStrVorBCn}\n&{}\\Delta \\psi^{n+1,k+1} = -\\omega^{n+1,k+1}, \\quad u^{n+1,k+1}=\\frac{\\partial \\psi^{n+1,k+1}}{\\partial y}, \\quad v^{n+1,k+1}=-\\frac{\\partial \\psi^{n+1,k+1}}{\\partial x}.\n\\end{align}\nIn these equations, the superscript $n$ denotes the timestep and the superscript $k$ denotes the iterate. Another choice of time discretization is the implicit midpoint rule which gives,\n\\begin{align} \\label{eq:Ns2dStrVorAimr}\n&{}\\hspace{2em}\\rho\\left[\\frac{\\omega^{n+1,k+1}-\\omega^n}{\\delta t} \\right.\n\\\\&{}\\left.+ \\left(\\frac{u^{n+1,k}+u^n}{2}\\right)\\frac{\\partial}{\\partial x}\\left(\\frac{\\omega^{n+1,k}+\\omega^n}{2}\\right) + \\left(\\frac{v^{n+1,k}+v^n}{2}\\right)\\frac{\\partial}{\\partial y}\\left(\\frac{ \\omega^{n+1,k} +\\omega^n}{2}\\right)\\right] \\notag\n\\\\&{}=\\frac{\\mu}{2}\\Delta\\left(\\omega^{n+1,k+1}+\\omega^n\\right) + \\left.\\left(\\frac{\\partial fx}{\\partial y}-\\frac{\\partial fy}{\\partial x} \\right)\\right\\rvert_{t=(n+0.5)\\delta t},\\notag\n\\end{align}\nand\n\\begin{align} \\label{eq:Ns2dStrVorBimr}\n&{}\\Delta \\psi^{n+1,k+1} = -\\omega^{n+1,k+1}, \\quad u^{n+1,k+1}=\\frac{\\partial \\psi^{n+1,k+1}}{\\partial y}, \\quad v^{n+1,k+1}=-\\frac{\\partial \\psi^{n+1,k+1}}{\\partial x}.\n\\end{align}\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{The Three-Dimensional Case}\n\nHere $\\mathbf u = (u(x,y,z,t),v(x,y,z,t),w(x,y,z,t))$ -- unfortunately, it is not clear if this equation has a unique solution for reasonable boundary conditions and initial data. Numerical methods so far seem to indicate that the solution is unique, but in the absence of a proof, we caution the reader that we are {\\it fearless engineers writing gigantic codes that are supposed to produce solutions to the Navier-Stokes equations when what we are really studying is the output of the algorithm} which we hope will tell us something about these equations\\footnote{This is paraphrased from Gallavoti\\cite[p.~VIII]{Gal02}} -- in practice, although the mathematical foundations for this are uncertain, these codes do seem to give information about the motion of nearly incompressible fluids in many, although not all situations of practical interest. Further information on this aspect of these equations can be found in Doering and Gibbon~\\cite{DoeGib95}.\n\nWe will again consider simulations with periodic boundary conditions to make it easy to apply the Fourier transform. This also makes it easier to enforce the incompressibility constraint by using an idea due to Orszag and Patterson~\\cite{OrsPat72} and also explained in Canuto et al.~\\cite[p.~99]{CHQZ07}. If we take the divergence of the Navier-Stokes equations, we get\n\\begin{align}\n\\nabla\\cdot \\left(\\mathbf u\\cdot\\nabla\\mathbf u\\right)=-\\Delta p\n\\end{align}\nbecause $\\nabla\\cdot\\mathbf u=0$. Hence\n\\begin{align}\n&{}p=-\\Delta^{-1}\\left[\\nabla\\cdot \\left(\\mathbf u\\cdot\\nabla\\mathbf u\\right)\\right] \n\\end{align}\nwhere $\\Delta^{-1}$ is defined using the Fourier transform, thus if $f(x,y,z)$ is a mean zero, periodic scalar field and $\\hat{f}$ is its Fourier transform, then\n$$\\widehat{\\Delta^{-1}f}=\\frac{\\hat{f}}{k_x^2+k_y^2+k_z^2}$$\nwhere $k_x$, $k_y$ and $k_z$ are the wavenumbers. The Navier-Stokes equations then become\n\\begin{align}\n&{}\\frac{\\partial \\mathbf u}{\\partial t}=\\frac{1}{\\textup{Re}}\\Delta \\mathbf u - \\mathbf u\\cdot\\nabla\\mathbf u +\\nabla \\Delta^{-1}\\left[\\nabla\\cdot \\left(\\mathbf u\\cdot\\nabla\\mathbf u\\right)\\right], \\label{eq:NS3dOrsPat}\n\\end{align}\nfor which the incompressibility constraint is satisfied, provided the initial data satisfy the incompressibility constraint. \n\nTo discretize \\eqref{eq:NS3dOrsPat} in time, we will use the implicit midpoint rule. This gives,\n\\begin{align}\n\\hspace{1em}\\frac{\\mathbf u^{n+1}-\\mathbf u^{n}}{\\delta t} =&{}\\frac{0.5}{\\textup{Re}}\\Delta\\left( \\frac{\\mathbf u^{n+1}+\\mathbf u^{n}}{2}\\right)  - 0.25\\left(\\mathbf u^{n+1} + \\mathbf u^{n}\\right)\\cdot\\nabla\\left(\\mathbf u^{n+1} + \\mathbf u^{n} \\right)  \\notag\n\\\\&{}\\hspace{1em} + 0.25\\nabla\\left[ \\Delta^{-1}\\left(\\nabla\\cdot \\left[\\left(\\mathbf u^{n+1} + \\mathbf u^{n}\\right) \\cdot\\nabla\\left(\\mathbf u^{n+1} + \\mathbf u^{n} \\right)\\right]\\right)\\right]. \\label{eq:NS3dOrsPatIMR}\n\\end{align}\n\nIt is helpful to test the correctness of the programs by comparing them to an exact solution. Shapiro~\\cite{Sha93} has found the following exact solution which is a good test for meteorological hurricane simulation programs, as well as for Navier-Stokes solvers with periodic boundary conditions\n\\begin{align*}\n&{} u= -\\frac{A}{k^2+l^2}\\left[\\lambda l\\cos(kx)\\sin(ly)\\sin(mz)+mk\\sin(kx)\\cos(ly)\\cos(mz) \\right]\\exp\\left(-\\frac{\\lambda^2t}{\\textup{Re}}\\right)\n\\\\&{} v= \\frac{A}{k^2+l^2}\\left[\\lambda k\\sin(kx)\\cos(ly)\\sin(mz)-ml\\cos(kx)\\sin(ly)\\cos(mz) \\right]\\exp\\left(-\\frac{\\lambda^2t}{\\textup{Re}}\\right)\n\\\\&{} w= A\\cos(kx)\\cos(ly)\\sin(mz)\\exp\\left(-\\frac{\\lambda^2t}{\\textup{Re}}\\right)\n\\end{align*}\nwhere the constant $\\lambda=\\sqrt{k^2+l^2+m^2}$ and $l$, $k$ and $m$ are constants choosen with the restriction that the solutions are periodic in space. Further examples of such solutions can be found in Majda and Bertozzi~\\cite[sec.~2.3]{MajBer02}.\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Serial Programs}\nWe first write Matlab programs to demonstrate how to solve these equations on a single processor. The first program uses Crank-Nicolson timestepping to solve the two-dimensional Navier-Stokes equations and is in listing \\ref{lst:Ns2DMatlab}. To test the program, following Laizet and Lamballais\\cite{LaiLam09} we use the exact Taylor-Green vortex solution on $(x,y)\\in[0,1]\\times[0,1]$ with periodic boundary conditions given by\n\\begin{align}\n&{}u(x,y,t)=\\sin(2\\pi x)\\cos(2\\pi y)\\exp(-8\\pi^2\\mu t)\n\\\\&{}v(x,y,t)=-\\cos(2\\pi x)\\sin(2\\pi y)\\exp(-8\\pi^2\\mu t).\n\\end{align}\n\n\\lstinputlisting[style=matlab_style,label=lst:Ns2DMatlab,caption={A Matlab program which finds a numerical solution to the 2D Navier Stokes equation.}]{./NavierStokes/Programs/NsMatlabCn/NavierStokes2DFFTCn.m}\n\nThe second program uses the implicit midpoint rule to do timestepping for the three-dimensional Navier-Stokes equations and it is in listing \\ref{lst:Ns3DMatlab}. It also takes the Taylor-Green vortex as its initial condition since this has been extensively studied, and so provides a baseline case to compare results against.\n\n\\lstinputlisting[style=matlab_style,label=lst:Ns3DMatlab,caption={A Matlab program which finds a numerical solution to the 3D Navier Stokes equation.}]{./NavierStokes/Programs/NsMatlab3Dimr/NavierStokes3DfftIMR.m}\n\n% subsection\n\\subsection{Exercises}\n\\begin{enumerate}\n\\item[1)] Show that for the Taylor-Green vortex solution, the nonlinear terms in the two-dimensional Navier-Stokes equations cancel out exactly.\n\\item[2)] Write a Matlab program that uses the implicit midpoint rule instead of the Crank-Nicolson method to obtain a solution to the 2D Navier-Stokes equations. Compare your numerical solution with the Taylor-Green vortex solution.\n\\item[3)] Write a Fortran program that uses the implicit midpoint rule instead of the Crank-Nicolson method to obtain a solution to the 2D Navier-Stokes equations. Compare your numerical solution with the Taylor-Green vortex solution.\n\\item[4)] Write a Matlab program that uses the Crank-Nicolson method instead of the implicit midpoint rule  to obtain a solution to the 3D Navier-Stokes equations. \n\\item[5)] Write a Fortran  program that uses the Crank-Nicolson method instead of the implicit midpoint rule  to obtain a solution to the 3D Navier-Stokes equations.\n\\item[6)] The Navier-Stokes equations as written in eqs.\\ \\eqref{eq:Ns2dStrVorA} and \\eqref{eq:Ns2dStrVorB} also satisfy further integral properties. In particular show that\n\\begin{enumerate}\n\\item[a)] $$\\frac{\\rho}{2}\\frac{\\mathrm{d}}{\\mathrm{d}t}\\lVert \\omega \\rVert_{l^2}^2= -\\mu\\lVert \\nabla \\omega \\rVert_{l^2}^2,$$\nwhere \n$$\\lVert \\omega \\rVert_{l^2}^2=\\int\\int(\\omega)^2\\mathrm{d}x\\mathrm{d}y$$\nand\n$$\\lVert \\nabla \\omega \\rVert_{l^2}^2=\\int\\int(\\nabla\\omega)\\cdot(\\nabla\\omega)\\mathrm{d}x\\mathrm{d}y.$$\nHINT: multiply the Eq.\\ \\eqref{eq:Ns2dStrVorA} by $\\omega$ then integrate by parts. \n\\item[b)] Show that part (a) implies that \n$$\\lVert \\omega(t=T) \\rVert_{l^2}^2-\\lVert \\omega(t=0) \\rVert_{l^2}^2=-\\mu\\int_0^T\\lVert \\nabla \\omega \\rVert_{l^2}^2\\mathrm{d}t$$\n\\item[c)] Part (b) gives a property one can check when integrating the 2D Navier-Stokes equations. We now show that the implicit midpoint rule satisfies an analogous property. Multiply eq.\\ \\eqref{eq:Ns2dStrVorAimr} by $0.5(\\omega^{n+1}+\\omega^n)$, integrate by parts in space, then sum over time to deduce that\n$$\\lVert \\omega^N \\rVert_{l^2}^2-\\lVert \\omega^0 \\rVert_{l^2}^2=-\\frac{\\mu}{4}\\sum_{n=0}^{N-1}\\left\\lVert \\nabla\\left( \\omega^n+\\omega^{n+1}\\right) \\right\\rVert_{l^2}^2\\delta t.$$\n\\item[d)] Deduce that this implies that the implicit midpoint rule time stepping method is unconditionally stable, provided the nonlinear terms can be solved for\\footnote{We have not demonstrated convergence of the spatial discretization, so this result assumes that the spatial discretization has not been done.}.\n\\end{enumerate}\n\\end{enumerate}\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Parallel Programs: OpenMP}\n\nRather than give fully parallelized example programs, we instead give a simple implementation in Fortran of the Crank-Nicolson  and implicit midpoint rule algorithms for the two-dimensional and three dimensional Navier-Stokes equations that were presented in Matlab. The program for the two-dimensional equations is presented in listing \\ref{lst:For2dNs} and an example Matlab script to plot the resulting vorticity fields is in listing \\ref{lst:MatlabPlot2dNS}. This program is presented in listing \\ref{lst:For3dNs} and an example Matlab script to plot the resulting vorticity fields is in listing \\ref{lst:MatlabPlot3dNS}.\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For2dNs,caption={A Fortran program to solve the 2D Navier-Stokes equations.}]{./NavierStokes/Programs/NavierStokes2dFortran/navierstokes.f90}\n\n\\lstinputlisting[style=matlab_style,label=lst:MatlabPlot2dNS,caption={A Matlab program to plot the vorticity fields and error produced by listing \\ref{lst:For2dNs}.}]{./NavierStokes/Programs/NavierStokes2dFortran/plotdata.m}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For3dNs,caption={A Fortran program to solve the 3D Navier-Stokes equations.}]{./NavierStokes/Programs/NavierStokes3dFortran/NavierStokes3DfftIMR.f90}\n\n\\lstinputlisting[style=matlab_style,label=lst:MatlabPlot3dNS,caption={A Matlab program to plot the vorticity fields produced by listing \\ref{lst:For3dNs}.}]{./NavierStokes/Programs/NavierStokes3dFortran/plotdata.m}\n\n\\subsection{Exercises}\n\\begin{enumerate}\n\\item[1)] Verify that the program in listing \\ref{lst:For2dNs} is second order accurate in time.\n\\item[2)] Use OpenMP directives to parallelize the example Fortran code for the two-dimensional Navier Stokes equations. Try and make it as efficient as possible.\n\\item[3)] Write another code which uses threaded FFTW to do the Fast Fourier transforms. This code should have a similar structure to the program in listing \\ref{lst:For2dNlsOmp2}. \n\\item[4)] Use OpenMP directives to parallelize the example Fortran code for the three-dimensional Navier-Stokes equations in listing \\ref{lst:For3dNs}. Try and make it as efficient as possible.\n\\item[5)] Write another code which uses threaded FFTW to do the Fast Fourier transforms for the three-dimensional Navier-Stokes equations. This code should have a similar structure to the program in listing \\ref{lst:For2dNlsOmp2}. \n\\end{enumerate}\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Parallel Programs: MPI}\n\nThe code for this is very similar to the serial code in listing \\ref{lst:For2dNs}. For completeness and to allow one to see how to parallelize other programs, we include it. The program uses the library 2DECOMP\\&FFT. One difference between this program and the serial program is that a subroutine is included to write out data. Since this portion of the calculation is repeated several times, the program becomes more readable when the repeated code is placed in a subroutine. The subroutine is also generic enough that it can be reused in other programs, saving program developers time.\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For3dNsMPI,caption={A parallel MPI Fortran program to solve the 3D Navier-Stokes equations.}]{./NavierStokes/Programs/NavierStokes3dFortranMPI/NavierStokes3DfftIMR.f90}\n\n\\lstinputlisting[style=fortran_style,language=Fortran,label=lst:For3dNsMPIdata,caption={A subroutine to save real array data for the parallel MPI Fortran program to solve the 3D Navier-Stokes equations in listing \\ref{lst:For3dNsMPI}.}]{./NavierStokes/Programs/NavierStokes3dFortranMPI/savedata.f90}\n\n\\lstinputlisting[style=make_style,language=make,label=lst:For3dNsMPImake,caption={A makefile to compile the parallel MPI Fortran program to solve the 3D Navier-Stokes equations.}]{./NavierStokes/Programs/NavierStokes3dFortranMPI/makefile}\n\n\n\\subsection{Exercises}\n\\begin{enumerate}\n\\item[1)] Use 2DECOMP{\\&}FFT to write a two dimensional Navier-Stokes solver. The library is built to do three dimensional FFTs, however by choosing one of the arrays to have only one entry, the library can then do two dimensional FFTs on a distributed memory machine.\n\\item[2)] Uecker~\\cite{Uec09} describes the expected power law scaling for the power spectrum of the enstrophy\\footnote{The enstrophy is the square of the vorticity.} in two dimensional isotropic turbulence. Look up Uecker~\\cite{Uec09} and then try to produce numerical data which verifies the power scaling law over as many decades of wavenumber space as are feasible on the computational resources you have access to. A recent overview of research work in this area can be found in Boffetta and Ecke~\\cite{BofEck12}. Fornberg~\\cite{For77} discusses how to calculate power spectra.\n\\item[3)] If we set $\\mu=0$ the Navier Stokes equations become the Euler equations. Try to use the implicit midpoint rule and/or the Crank-Nicolson methods to simulate the Euler equations in either two or three dimensions. See if you can find good iterative schemes to do this, you may need to use Newton iteration. An introduction to the Euler equations is in Majda and Bertozzi~\\cite{MajBer02}.\n\\item[4)] The Taylor-Green vortex flow initial conditions have been studied as a possible flow that could have a blow up in the maximum value of the absolute value of the gradient of the velocity at a point for the Euler and Navier-Stokes equations. In many of these simulations, symmetries have been used to get higher effective resolutions, see for example Cichowlas and Brachet~\\cite{CicBra05}. Consider using the Kida-Pelz and Taylor-Green vortex as initial conditions for the Euler equations and adding non-symmetric perturbations. If you are unable to get an implicit time-stepping scheme to work, consider using an explicit scheme such as a Runge-Kutta method. How does the flow evolve in comparison to previous studies in the literature? An introduction to the blow up for the Euler equations is in Majda and Bertozzi~\\cite{MajBer02}.\n\\item[5)] The three dimensional program we have written is not the most efficient since one can use a real to complex transform to halve the work done. Implement a real to complex transform in one of the Navier-Stokes programs.\n\\item[6)] The programs we have written can also introduce some aliasing errors.  By reading a book on spectral methods, such as Canuto et al.~\\cite{CHQZ07}, find out what aliasing errors are. Explain why the strategy explained in Johnstone~\\cite{Joh12} can reduce aliasing errors. \n\\end{enumerate}\n", "meta": {"hexsha": "75462ea338611711191fbe22ae705671d6034bf0", "size": 22355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NavierStokes/NavierStokes.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "NavierStokes/NavierStokes.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "NavierStokes/NavierStokes.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 111.2189054726, "max_line_length": 980, "alphanum_fraction": 0.750123015, "num_tokens": 6729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105599, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6482856751391434}}
{"text": "\\title{Enumeration of the Building Game}\n\\author{\n        Daniel Johnson \\& Govind Menon\\\\\n                Division of Applied Mathematics\\\\\n        Brown University\n}\n\\date{\\today}\n\n\\documentclass[12pt]{article}\n\n\\usepackage{graphicx,amsmath,mathtools,bbm,amsthm,enumerate}\n\\usepackage{mathrsfs}\n%\\usepackage[subnum]{cases}\n\n%\\usepackage[titletoc,toc,title]{appendix}\n\n\n\\newtheorem{mythm}{Theorem}\n\\newtheorem{mylem}{Lemma}\n\\newtheorem{mycor}{Corollary}\n\\newtheorem{mydef}{Definition}\n\n\\newcommand{\\colorA}{white}\n\\newcommand{\\colorB}{black}\n\\newcommand{\\colorAsm}{w}\n\\newcommand{\\colorBsm}{b}\n\\newcommand{\\poly}{$\\mathscr{P}$}\n\\newcommand{\\faceset}{F\\left(\\mathscr{P}\\right)}\n\\newcommand{\\spc}{ }\n\\newcommand{\\xj}{$x^j$}\n\\newcommand{\\xk}{$x^k$}\n\\newcommand{\\Sjk}{$S_{jk}$}\n\\newcommand{\\Skj}{$S_{kj}$}\n\n\\DeclareMathOperator{\\diag}{diag}\n\n\n\\begin{document}\n\\maketitle\n\n\\begin{abstract}\nThe Building Game is a sequential coloring process on polyhedra. We enumerate the Building Game state space for all polyhedra in the Platonic, Archimedean, and Catalan solids classes of up to 30 faces. By putting a probability distribution on each step of the Building Game process, a distribution is induced on the entire state space. With the help of a finite group theoretic identity, we find the explicit form of these distributions. Finally, we examine the properties of the resulting distributions.\n\\end{abstract}\n\n\\section{Introduction}\nThe Building Game (BG) was first considered by Zlotnick~\\cite{Zlotnick1994} as a model for the assembly of polyhedral viral capsids. We formalize the idea as a sequential coloring process that progresses from a polyhedron \\poly\\spc with each face colored \\colorA, through a number of intermediate states each having a mix of \\colorA\\spc and \\colorB\\spc faces, and ending with all of the faces colored \\colorB. \n\\begin{mydef}\nA Building Game \\textbf{intermediate} $x$ is a function from the faces of \\poly\\spc, $F\\left(\\mathscr{P}\\right)$, to a color in $\\left\\{\\colorA,\\colorB\\right\\}$ such that the set $\\left\\{f_m \\in F\\left(\\mathscr{P}\\right) : x\\left(f_m\\right) = \\colorB\\right\\}$ is edge connected along with the equivalence relation $x \\sim x'$ if there is an element $g$ of \\poly's rotation group $G$ that satisfies $x(f_m) = x'(g.f_m)$ for every $f_m \\in F(\\mathscr{P})$. \n\\end{mydef}\nFor ease of exposition, we use the notational shorthand $\\left(x\\right)_m$ for $x\\left(f_m\\right)$ and $x = g.x'$ when $x(f_m) = x'(g.f_m)$ for every $f_m \\in F(\\mathscr{P})$. Additionally, we denote the intermediate satisfying $\\left(x\\right)_m = \\colorA$ for all $f_m \\in \\faceset$ as $x^\\colorAsm$ and similarly $x^\\colorBsm$ is the intermediate with $\\left(x\\right)_m = \\colorB$ for all $f_m \\in \\faceset$. The function counting the number of \\colorB\\spc faces an intermediate has is denoted $h\\left(x\\right) \\doteq |\\left\\{f_m \\in \\faceset : \\left(x\\right)_m = \\colorB\\right\\}|$.\n\n\\begin{mydef}\nTwo intermediates $x^j$ and $x^k$ are \\textbf{connected} ($x^j \\leftrightarrow x^k$) if $\\left(x^j\\right)_m = \\left(x^k\\right)_m$ for all $f_m \\in \\faceset$ except for exactly one face $f_n$ that has  $\\left(x^j\\right)_n \\neq \\left(x^k\\right)_n$.\n\\end{mydef}\n\\begin{mydef}\nA Building Game \\textbf{pathway} is a sequence of intermediates $x^{p_0}, x^{p_1}, x^{p_2}, \\dots, x^{p_N}$ such that $x^{p_0} = x^\\colorAsm$, $x^{p_N} = x^\\colorBsm$, $x^{p_i}$ is connected to $x^{p_{i+1}}$ and $h\\left(x^{p_i}\\right) = i$.\n\\end{mydef}\n\nIn this way it is useful to think of intermediates as connected if it is possible to color one face of the first intermediate to get the second and a pathway as a sequence of these connections between $x^\\colorAsm$ and $x^\\colorBsm$. Figure~\\ref{fig:DodecBG} shows a Building Game pathway for the dodecahedron using Schlegel diagrams. The pathways has 13 intermediates since there must be exactly one intermediate $x^{p_i}$ satisfying $h\\left(x^{p_i}\\right) = i$ for each $i = 0,1,2,\\dots,12$.\n\n\\begin{figure}[ht]\n\\caption{One Building Game pathway on the dodecahedron.}\n\\label{fig:DodecBG}\n\\end{figure}\n\nWith many pairs of connected intermediates, we organize these relations in a graph.\n\n\\begin{mydef}\nThe Building Game \\textbf{state space} for a polyhedron \\poly\\spc is a graph in which the nodes are \\poly's intermediates and a graph edge exists between two intermediates if and only if they are connected. \n\\end{mydef}\n\nWhen the intermediates are partitioned by their value of $h$, it is natural to arrange the state space as a tiered graph according to this partition. Figure~\\ref{fig:CubeSS} shows the Building Game state space for the cube. As seen, each tier has intermediates with the same number of \\colorB faces and connections thus exist with intermediates that are either in the tier directly above or below them. We can also see that there are three distinct pathways contained in the state space. \n\n\\begin{figure}[ht]\n\\caption{The Building Game state space of the cube.}\n\\label{fig:CubeSS}\n\\end{figure}\n\nInterestingly, it is not the case that the recoloring of each face of \\xj\\spc results in a distinct intermediate. \n\\begin{mydef}\nThe number of different faces $\\left|\\left\\{f_m \\in \\faceset : x^j + e^m \\in \\left[x^k\\right]\\right\\}\\right|$ of \\xj\\spc that can be colored to form \\xk\\spc is called the \\textbf{degeneracy number} \\Sjk.\n\\end{mydef}\nIt is important to note that in general the degeneracy number is not symmetric, i.e. \\Sjk$\\neq$\\Skj\\spc for some connections \\xj\\spc$\\leftrightarrow$\\spc\\xk\\spc in the state space. Both figures~\\ref{fig:DodecBG} and ~\\ref{fig:DodecBG} show the forward and backward degeneracy numbers for each connection.\n\n\\subsection{Related Work}\n--Like polyominos on polyhedra\n\n\\subsection{Applications}\n--Viral capsid assembly\n\n--Self-assembly of molecular cages\n\n--Self assembly for manufacturing purposes\n%~\\cite{Endres2005}\n\\subsection{Paper Overview}\n-- Summary of subsequent sections\n\n\\section{Enumerative Results}\n\nAs we consider polyhedra with more and more faces, there is a combinatorial explosion in the number intermediates in state space. While the 6-faced cube state space has only 8 nodes and 9 nodes, the 20-faced icosahedron state space has 2,649 nodes and 17,241 nodes and the 26-faced truncated cuboctahedron state space has 1,525,605 nodes and 17,672,377. Figure \\ref{fig:bgtable} details state space sizes of all polyhedra in the Platonic, Archimedean, and Catalan solid classes of up to 26 faces. \n\n\nAlso something about pathway statistics. \n\n\n\\begin{figure}[ht]\n\\scalebox{0.6}{\n%{\\footnotesize\n\\begin{tabular}{ l | c | c | c | c || r | r | r}\nPolyhedra Name & Class & F$\\left(\\mathscr{P}\\right)$ & E$\\left(\\mathscr{P}\\right)$ & V$\\left(\\mathscr{P}\\right)$ & Intermediates & Connections & Pathways \\\\\n  \\hline    \nTetrahedron                     & P & 4 & 6 & 4         & 5     \t& 4             & 1\\\\\nCube                            & P & 6 & 12 & 8        & 9     \t& 10    \t& 3\\\\\nOctahedron                      & P & 8 & 12 & 6        & 15    \t& 22    \t& 14\\\\\nDodecahedron                    & P & 12 & 30 & 20      & 74    \t& 264   \t& 17,696 \\\\\nIcosahedron                     & P & 20 & 30 & 12      & 2,650 \t& 17,242        & 57,396,146,640\\\\\nTruncated Tetrahedron           & A & 8 & 18 & 12       & 29    \t& 65            & 402\\\\\nCuboctahedron                   & A & 14 & 24 & 12 \t& 341   \t& 1,636         & 10,170,968\\\\\nTruncated Cube                  & A & 14 & 36 & 24 \t& 500   \t& 2,731         & 101,443,338 \\\\\nTruncated Octahedron            & A & 14 & 36 & 24 \t& 556           & 3,071         & 68,106,377\\\\\nRhombicuboctahedron             & A & 26 & 48 & 24 \t& 638,851       & 6,459,804     & 16,494,392,631,838,879,380\\\\\nTruncated Cuboctahedron         & A & 26 & 72 & 48 \t& 1,525,605     & 17,672,377    & ? \\\\\nIcosidodecahedron               & A & 32 & 60 & 30 \t& ?             & ?             & ?\\\\\nTruncated Dodecahedron          & A & 32 & 90 & 60 \t& ?             & ? \t        & ? \\\\\nTruncated Icosahedron           & A & 32 & 90 & 60 \t& ?             & ? \t        & ?\\\\\nTriakis Tetrahedron             & C & 12 & 18 & 8       & 99            & 319           & 38,938\\\\\nRhombic Dodecahedron            & C & 12 & 24 & 14 \t& 128           & 494           & 76,936\\\\\nTriakis Octahedron              & C & 24 & 36 & 14 \t& 12,749        & 81,297        & 169,402,670,046,670\\\\\nTetrakis Hexahedron             & C & 24 & 36 & 14 \t& 50,768        & 394,278       & 4,253,948,297,210,346\\\\\nDeltoidal Icositetrahedron      & C & 24 & 48 & 26 \t& 209,676       & 1,989,549     & ? \\\\\nPentagonal Icositetrahedron     & C & 24 & 60 & 38 \t& 345,939       & 3,544,988     & 2,828,128,000,716,774,492\\\\\nRhombic Triacontahedron         & C & 30 & 60 & 32 \t& ?             & ?             & 5,266,831,101,345,821,968\\\\\n  \\hline  \n\\end{tabular}\n}\n\\caption{Table of polyhedra in the Platonic (P), Archimedean (A), and Catalan (C) solid classes of up to 32 faces and their Building Game state space statistics.}\n\\label{fig:bgtable}\n\\end{figure}\n\n\n\\begin{figure}[ht]\n\\scalebox{0.6}{\n%{\\footnotesize\n\\begin{tabular}{ l | c | c | c | c || r | r | r}\nPolyhedra Name & Class & F$\\left(\\mathscr{P}\\right)$ & E$\\left(\\mathscr{P}\\right)$ & V$\\left(\\mathscr{P}\\right)$ & Intermediates & Connections & Pathways \\\\\n  \\hline    \nTetrahedron                     & P & 4 & 6 & 4         & 5     & 4 & 1\\\\\nCube                            & P & 6 & 12 & 8        & 8     & 8 & 2\\\\\nOctahedron                      & P & 8 & 12 & 6        & 12    & 12 & 14 \\\\\nDodecahedron                    & P & 12 & 30 & 20      & 53    & 156 & 2166\\\\\nIcosahedron                     & P & 20 & 30 & 12      & 468   & 1984 & 105999738\\\\\nTruncated Tetrahedron           & A & 8 & 18 & 12       & 22\t& 42 & 174\\\\\nCuboctahedron                   & A & 14 & 24 & 12 \t& 137\t& 470 & 477776\\\\\nTruncated Cube                  & A & 14 & 36 & 24 \t& 248\t& 1002 & 5232294\\\\\nTruncated Octahedron            & A & 14 & 36 & 24 \t& 343\t& 1466 & 5704138\\\\\nRhombicuboctahedron             & A & 26 & 48 & 24 \t& 70836\t& 462149 &  48399693494788840\\\\\nTruncated Cuboctahedron         & A & 26 & 72 & 48 \t& ?\t& ? & ?\\\\\nIcosidodecahedron               & A & 32 & 60 & 30 \t& ?\t& ? & ?\\\\\nTruncated Dodecahedron          & A & 32 & 90 & 60 \t& ?\t& ? & ?\\\\\nTruncated Icosahedron           & A & 32 & 90 & 60 \t& ?\t& ? & ?\\\\\nTriakis Tetrahedron             & C & 12 & 18 & 8       & 49\t& 116 & 5012\\\\\nRhombic Dodecahedron            & C & 12 & 24 & 14 \t& 68\t& 196 & 6258\\\\\nTriakis Octahedron              & C & 24 & 36 & 14 \t& 667\t& 2383 & 15255459\\\\\nTetrakis Hexahedron             & C & 24 & 36 & 14 \t& 4220\t& 21079 & 5854799360107\\\\\nDeltoidal Icositetrahedron      & C & 24 & 48 & 26 \t& ?\t& ? & ?\\\\\nPentagonal Icositetrahedron     & C & 24 & 60 & 38 \t& 95127\t& 654537 & 5607231936129109\\\\\nRhombic Triacontahedron         & C & 30 & 60 & 32 \t& 97368\t& 697623 & 6889989896241902854\\\\\n  \\hline  \n\\end{tabular}\n}\n\\caption{Table of polyhedra in the Platonic (P), Archimedean (A), and Catalan (C) solid classes of up to 32 faces and their Building Game state space shellability statistics.}\n\\label{fig:bgtable_shell}\n\\end{figure}\n\n\n\\subsection{Bounds and Asymptotics}\nHave upper, but what about lower? \n\\subsection{Methods}\n\\section{The Building Game as a Stochastic Process}\n\\label{sec:Prob}\nSince the Building Game is a sequential process with several choices at each step, it is natural to consider it as a stochastic process. By putting a distribution on all possible faces that can be colored \\colorB\\spc at each step of the Building game, a distribution on the space of pathways is implicitly defined. Thus, for a choice of this transition rule, we can ask questions about the likelihood of the different pathways. \n\n--Math and graphical results about putting a distribution on pathways\n\n\\subsection{Forward and Backward Transitions}\n\nIf we allow faces be changed both from \\colorA\\spc to \\colorB\\spc and from \\colorB\\spc to \\colorA, the process consists of transitions from intermediate to intermediate along state space connections. By specifying a distribution on these transitions, it will induce a stationary measure on the state space.  \n\nWe define the Markov process $X_t$ by the transition rate matrix $Q$, with the heuristic that the rate of transition to an intermediate \\xk from an intermediate \\xk should be proportional to the number of faces of \\xj that can be colored to reach the intermediate \\xk. For this reason, we include the degeneracy number \\Sjk\\spc as a factor in the transition rate matrix. Furthermore, we model the process after and energetic model in which each intermediate has an energy and to transtion between intermediates, an energy barrier $E_{jk} = E_{kj}$ must be overcome. \n%\\begin{align}\n%\\label{eq:TransitionProbability}\n% P_{jk} = \\frac{1}{z_j}S_{jk}\\rh \n%\\end{align}\n\\begin{align}\n\\label{eq:TransitionRate}\nQ_{jk} &= S_{jk}e^{-\\beta\\left(E_{jk} - E_j\\right)} \\\\\nQ_{jj} &= -z_j \\\\\n\\end{align}\nHere, $z_j \\doteq \\sum_{\\ell: \\ell \\neq j} S_{j\\ell}e^{-\\beta\\left(E_{j\\ell} - E_j\\right)}$ is the rate at which the process leaves \\xj. \n\n\\begin{mythm}\n\\label{thm:StatDist}\nIf the transition rate matrix $Q$ can be decomposed as $Q = DC$ where $D$ is diagonal with each entry of the diagonal positive and $C$ is a non-negative symmetric matrix with $C_{jk} > 0$ if and only if $x^j$ and $x^k$ are connected, then $X_t$ has the unique stationary distribution $\\pi = \\diag\\left(D^{-1}\\right)$.         \n\\end{mythm}\n\\begin{proof}\nFirst, we show $Q$ and $\\pi$ satisfy detailed balance.\n\\begin{align}\n\\pi_jQ_{jk} &= \\left(\\frac{1}{D_{jj}}\\right)\\left(D_{jj}C_{jk}\\right) \\\\\n&= C_{jk} \\\\\n&= C_{kj} \\\\\n&= \\left(\\frac{1}{D_{kk}}\\right)\\left(D_{kk}C_{kj}\\right) \\\\\n                    &= \\pi_kQ_{kj}\n\\end{align}\n\n-- Prove aperiodicity \n-- Prove positive reccurence\n\n\\end{proof}\n\nIn order to use theorem~\\ref{thm:StatDist} to find the stationary distribution for the transition rule~\\ref{eq:TransitionProbability}, we must be able to decompose the degeneracy number \\Sjk\\spc to fit the template of $\\mathbf{C}$ and $\\mathbf{D}$. In the following section we derive group theoretic identities to show that this is possible.\n\n\\subsection{Hitting Times}\n\n\\begin{align}\n\t\\tau^{A}_{j} &\\doteq \\inf\\left\\{t \\geq 0 : X_t \\in A, X_0 = x^j\\right\\}\n\\end{align}\n\n\\begin{align}\n\t\\nu^{A}_{j} &\\doteq \\inf\\left\\{n \\geq 0 : Y_n \\in A, Y_0 = x^j\\right\\}\n\\end{align}\n\nFor $j \\not\\in A$.\n\\begin{align}\n\tE\\left[\\tau^{A}_{j}\\right] &= E\\left[E\\left[\\tau^{A}_{j} | Y_1 \\right]\\right] \\\\\n        &= E\\left[ Exp\\left(z_j\\right) + \\tau^{A}_{Y_1} \\right] \\\\\n        &=  \\frac{1}{z_j} + E\\left[\\sum_{k}\\tau^{A}_{Y_1}\\mathbbm{1}_{Y_1 = k}\\right] \\\\\n        &=  \\frac{1}{z_j} + \\sum_{k: k\\neq j}E\\left[\\tau^{A}_{k}\\right] P\\left(Y_1 = k\\right) \\\\\n        &=  \\frac{1}{z_j}\\left(1 + \\sum_{k: k\\neq j}q_{jk}E\\left[\\tau^{A}_{k}\\right]\\right)     \\\\\n  \\sum_{k}q_{jk}E\\left[\\tau^{A}_{k}\\right] &= 1 \\\\\n\\end{align}\n\nFor $j \\in A$.\n\\begin{align}\n\tE\\left[\\tau^{A}_{j}\\right] &= 0 \\\\\n\\end{align}\n\nAs a linear system:\n\\begin{align}\n\t\\left(\\diag\\left(\\mathbbm{1}_A\\right) - \\diag\\left(\\mathbbm{1}_{A^c}\\right)Q\\right)E\\left[\\tau^{A}\\right] =\\mathbbm{1}_{A^c}\\\\\n\\end{align}\n\n\n\\begin{align}\n\\psi_j^A\\left(t\\right) &\\doteq P\\left(\\tau^A_j \\leq t\\right) \\\\\n\\psi_j^A\\left(0\\right) &= \\mathbbm{1}_{j\\in A} \\\\\n\\psi_j^A\\left(t\\right) &= 0 \\forall j \\in A \\\\                       \n\\end{align}\n\nFor $j \\not\\in A$.\n\n\\begin{align}\n\\psi_j^A\\left(t\\right) &\\doteq P\\left(\\tau^A_j \\leq t\\right) \\\\\n                       &= \\sum_k P\\left(\\tau^A_j \\leq t | Y_1 = x^k\\right) P\\left(Y_1 = x^k\\right) \\\\ \n                       &= \\frac{1}{z_j}\\sum_{k: k \\neq j} q_{jk} P\\left(Exp\\left(z_j\\right)\\tau^A_j \\leq t\\right)  \\\\\n                       &= \\frac{1}{z_j}\\sum_{k: k \\neq j} q_{jk} \\int^t_0 P\\left(\\tau^A_j \\leq t - s\\right) z_j e^{-z_j s} ds  \\\\\n                       &= \\sum_{k: k \\neq j} q_{jk} \\int^t_0\\psi^A_k\\left(t-s\\right)e^{-z_j s} ds  \\\\\n                       &= \\sum_{k: k \\neq j} q_{jk} \\int^t_0\\psi^A_k\\left(r\\right)e^{-z_j\\left(t-r\\right)} dr  \\\\\ne^{z_jt}\\psi^A_j\\left(t\\right) &= \\sum_{k: k \\neq j} q_{jk} \\int^t_0 e^{z_jr}\\psi^A_k\\left(r\\right) dr  \\\\\ne^{z_jt}\\frac{d\\psi^A_j}{dt} + z_j e^{z_j t} \\psi^A_j\\left(t\\right) &= \\sum_{k: k \\neq j} q_{jk} e^{z_jt}\\psi^A_k\\left(t\\right)  \\\\\n\\frac{d\\psi^A_j}{dt} &= \\sum_{k} q_{jk} \\psi^A_k\\left(t\\right) \n\\end{align}\n\nCombining both cases, we get the linear system and solution.\n\n\\begin{align}\n        \\frac{d\\psi^A}{dt} &= \\diag\\left(\\mathbbm{1}_{A^c}\\right)Q\\psi^A \\\\\n        \\psi^A\\left(0\\right) &= \\mathbbm{1}_{A} \\\\\n        \\psi^A\\left(t\\right) &= e^{\\diag\\left(\\mathbbm{1}_{A^c}\\right)Qt} \\mathbbm{1}_{A} \\\\ \n\\end{align}\n\nThis is the solution for the CDF of the stopping time $\\tau^A$, but we can also compute the PDF explicitly for $t > 0$.\n\n\\begin{align}\n        p\\left(\\tau^A = t\\right) &= \\frac{d\\psi^A}{dt} \\\\\n        &= \\diag\\left(\\mathbbm{1}_{A^c}\\right)Q\\psi^A\n\\end{align} \n\n\n\\section{A Finite Geometric Result}\n\nSince we define Building Game intermediates as rotationally unique from each other, it is useful to think about the problem in the context of $\\mathscr{P}$'s rotational symmetry group $G \\doteq G\\left(\\mathscr{P}\\right)$ and group actions. For an intermediate $x^j$, the number of symmetries $r_j$ is the order of the stabilizer subgroup $G_{x^j} \\doteq \\left\\{g \\in G : g.x^j = x^j\\right\\}$ of $G$ that fixes $x^j$. Suppose $x^j$ and $x^k$ are connected in the state space and $\\varphi$ is one of the $S_{jk}$ faces that, when added to $x^j$, forms $x^k$. We say $x^j + \\varphi = x^k$. The degeneracy number $S_{jk}$ can then be expressed as the order of the orbit $\\left(G_{x^j}\\right).\\varphi$ of $\\varphi$ with respect to $x^j$'s stabilizer subgroup. Analogously, we define the reverse degeneracy number as $S_{kj} \\doteq \\left|\\left(G_{x^k}\\right).\\varphi\\right|$\n\n\\begin{mylem}\n\\label{lem:I}\nFor Building Game intermediates $x^j$ and $x^k$ connected in the state space and a face $f_m \\in \\faceset$ satisfying $x^j + e^m = x^k$, the stabilizer subgroup $G_{x^j,e^m}$ that fixes both $x^j$ and $e^m$ is the same stabilizer subgroup $G_{x^k,e^m}$ that fixes $x^k$ and $e^m$.\n\\end{mylem}\n\\begin{proof}\n\\begin{align}\nG_{x^j,e^m} &\\doteq \\left\\{g \\in G | g.x^j = x^j, g.e^m = e^m \\right\\} \\\\\n                &= \\left\\{g \\in G | g.\\left(x^k - e^m\\right) = x^k - e^m, g.e^m = e^m \\right\\} \\\\\n                &= \\left\\{g \\in G | g.x^k = x^k, g.e^m = e^m \\right\\} \\\\\n                &\\doteq G_{x^k,e^m}\n\\end{align}\n\\end{proof}\n\n\n\\begin{mythm}\n\\label{thm:J}\nFor two Building Game intermediates $x^j$ and $x^k$ are connected in the BG state space, $r_kS_{jk} = r_jS_{kj}$.\n\\end{mythm}\n\\begin{proof}\nLet $e^m$ be a face such that $x^k = x^j + e^m$. Then, by the orbit-stabilizer theorem, Lagrange's Theorem and lemma~\\ref{lem:I} we have the following~\\cite{Rotman1995}.\n\\begin{align}\n\\frac{r_j}{S_{jk}} &\\doteq \\frac{\\left|G_{x^j}\\right|}{\\left|\\left(G_{x^j}\\right).e^m\\right|} \\\\\n                   &= \\left[G_{x^j} : \\left(G_{x^j}\\right).e^m \\right] \\\\\n                   &= \\left|G_{x^j,e^m}\\right| \\\\\n                   &= \\left|G_{x^k,e^m}\\right| \\\\\n                   &= \\left[G_{x^k} : \\left(G_{x^k}\\right).e^m \\right] \\\\\n                   &= \\frac{\\left|G_{x^k}\\right|}{\\left|\\left(G_{x^k}\\right).e^m\\right|} \\\\\n                   &\\doteq \\frac{r_k}{S_{kj}} \n\\end{align}\nThe result $r_kS_{jk} = r_jS_{kj}$ follows.\n\\end{proof}\n\n\\section{Stationarity}\n\n\\begin{mythm}\n\\label{thm:E}\nThe Markov process $X_t$ defined by the transition rate matrix $Q$ in equation~\\ref{eq:TransitionRate} admits the unique stationary distribution $\\frac{1}{zr_j}e^{-\\beta E_j}$ where $z \\doteq \\sum_\\ell \\frac{1}{r_\\ell}e^{-\\beta E_\\ell}$ is the partition function. \n\\end{mythm}\n\\begin{proof}\nWe take $C_{jk} \\doteq \\frac{S_{jk}}{zr_j}e^{-\\beta E_{jk}}$ and notice that it is symmetric by theorem~\\ref{thm:J}. With $D_{jj} \\doteq zr_je^{\\beta E_j}$ we have our partition.  \n\\begin{align}\nQ_{jk} &= S_{jk}e^{-\\beta\\left(E_{jk} - E_j\\right)} \\\\\n       &= \\left(zr_je^{\\beta E_j}\\right) \\left(\\frac{S_{jk}}{zr_j}e^{-\\beta E_{jk}}\\right) \\\\\n       &= D_{jj}C_{jk}   \n\\end{align}\nThus, by theorem~\\ref{thm:StatDist},  $\\pi_j = \\frac{1}{D_{jj}} = \\frac{1}{zr_j}e^{-\\beta E_j}$.\n\\end{proof}\n\n\n\\section{Discussion}\n\\subsection{Nonenumerative Approaches}\n\n\\section*{Acknowledgments}\\label{ackowledgements}\n        Supported by NSF grants DMS 07-48482 and EFRI 10-22638\n\n\\section{Potential Citations (temp)}\n~\\cite{Coxeter1963}\n~\\cite{Grunbaum2003}\n~\\cite{Cromwell1997}\n~\\cite{Ziegler1995}\n~\\cite{Gidas1995}\n~\\cite{Eden1961}\n~\\cite{Grayson2012}\n\n\n\\bibliographystyle{plain}\n%\\nocite{*} \n\\bibliography{Master}\n\n\n%\\appendix\n%\\section{Proof of Theorem ???}\n%\\section{Proof of Theorem ???}\n\n\\end{document}\n\n\n%%%%%%%%%%%%%%%%%%%% CCCCUUUUTTTT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{A Curious Observation}\n\nAs part of the exploration of the nature of the degeneracy numbers $S_{jk}$ to find a stationary distribution, an interesting phenomena was noticed. Given a closed path $x^{k_0} \\to x^{k_1} \\to \\cdots \\to x^{k_n}$ through the state space, starting at $x^{k_0}$ and ending back at $x^{k_n} \\doteq x^{k_0}$, the the identity given in equation~\\ref{eq:DegenIdent} was observed to hold independent of the particular closed path. \n\\begin{align}\n\\prod_{i=1}^n \\frac{S_{k_i,k_{i-1}}}{S_{k_{i-1},k_i}} = 1\n\\label{eq:DegenIdent}\n\\end{align}\nAt first this relation between ratios of degeneracy numbers along the path was noticed in the cube's state space and it can easily be seen by examining figure~\\ref{fig:CubeSS}. To test this conjecture more fully, it was subsequently verified on our library of state spaces for other polyhedra. This exploration lead to the discovery of a more general relation between intermediates that it described below.\n\nIn an attempt to get the the heart of the relation in equation~\\ref{eq:DegenIdent}, we compiled a list of different geometric and combinatorial statistics for each state space connection $x_j \\leftrightarrow x_k$. These statistics included number of faces in $x_j$ and $x_k$, the order of $x_j$ and $x_k$'s rotation groups $r_j$ and $r_k$, and a few others. With the ansatz that there may be a multiplicative relation between the degeneracy number $S_{jk}$ and some of these $d$ statistics $Z_{jk}^{\\left(i\\right)} \\in \\mathbbm{Z}^d$ for each connection, the following linear regression model was used.\n\\begin{align}\n\\log\\left(S_{jk}\\right) = \\sum_{i=1}^d \\beta^{\\left(i\\right)}\\log\\left(Z_{jk}^{\\left(i\\right)}\\right)\n\\label{eq:LinReg}\n\\end{align}\nThe regression coefficients $\\boldsymbol{\\beta} \\in \\mathbbm{R}^d$ that minimize the least-squares residual were solved for and it was found that a perfect relation was found in the sense that equation~\\ref{eq:LinReg} held exactly for all connections tested. The three non-zero entries in $\\boldsymbol{\\beta}$ corresponded to $r_j$, $r_k$ and $S_{kj}$. This result meant that $\\log\\left(S_{jk}\\right) = \\log\\left(S_{kj}\\right) + \\log\\left(r_{j}\\right) - \\log\\left(r_{k}\\right)$, or \n\\begin{align}\nS_{jk} = \\frac{r_jS_{kj}}{r_k}\n\\label{eq:RSConjecture}\n\\end{align} \nfor all connections we tested. This leads to the obvious conjecture that equation~\\ref{eq:RSConjecture} holds for any connection in any Building Game state space. \n\nIn fact, if this is the case, it would explain why equation~\\ref{eq:DegenIdent} holds. \n\\begin{align}\n        \\prod_{i=1}^n \\frac{S_{k_i,k_{i-1}}}{S_{k_{i-1},k_i}} &= \\prod_{i=1}^n \\frac{r_{k_i}}{r_{k_{i-1}}} \\\\ \n        &= \\frac{r_{k_n}}{r_{k_{0}}} \\\\ \n        &= \\frac{r_{k_0}}{r_{k_{0}}} \\\\\n        &= 1 \n\\end{align}\n\n\n\n\\begin{figure}[ht]\n\\scalebox{0.6}{\n%{\\footnotesize\n\\begin{tabular}{ l | c | c | c | c || r | r | r}\nPolyhedra Name & Class & F$\\left(\\mathscr{P}\\right)$ & E$\\left(\\mathscr{P}\\right)$ & V$\\left(\\mathscr{P}\\right)$ & Intermediates & Connections & Pathways \\\\\n  \\hline    \nTetrahedron & P & 4 & 6 & 4 & 5 & 4 & 1\\\\\nCube & P & 6 & 12 & 8 & 9 & 10 & 3\\\\\nOctahedron & P & 8 & 12 & 6 & 15 & 22 & 14\\\\\nDodecahedron & P & 12 & 30 & 20 & 74 & 264 & 17,696 \\\\\nIcosahedron & P & 20 & 30 & 12 & 2,650 & 17,242 & 57,396,146,640\\\\\nTruncated Tetrahedron & A & 8 & 18 & 12 & 29 & 65 & 402\\\\\nCuboctahedron & A & 14 & 24 & 12 & 341 & 1,636 & 10,170,968\\\\\nTruncated Cube & A & 14 & 36 & 24 & 500 & 2,731 & 101,443,338 \\\\\nTruncated Octahedron & A & 14 & 36 & 24 & 556 & 3,071 & 68,106,377\\\\\nRhombicuboctahedron & A & 26 & 48 & 24 & 638,851 & 6,459,804 & 16,494,392,631,838,879,380\\\\\nTruncated Cuboctahedron & A & 26 & 72 & 48 & 1,525,605 & 17,672,377 & ? \\\\\nIcosidodecahedron & A & 32 & 60 & 30 & ? & ? & ?\\\\\nTruncated Dodecahedron & A & 32 & 90 & 60 & ? & ? & ? \\\\\nTruncated Icosahedron & A & 32 & 90 & 60 & ? & ? & ?\\\\\nTriakis Tetrahedron & C & 12 & 18 & 8 & 99 & 319 & 38,938\\\\\nRhombic Dodecahedron & C & 12 & 24 & 14 & 128 & 494 & 76,936\\\\\nTriakis Octahedron & C & 24 & 36 & 14 & 12,749 & 81,297 & 169,402,670,046,670\\\\\nTetrakis Hexahedron & C & 24 & 36 & 14 & 50,768 & 394,278 & 4,253,948,297,210,346\\\\\nDeltoidal Icositetrahedron & C & 24 & 48 & 26 & 209,676 & 1,989,549 & ? \\\\\nPentagonal Icositetrahedron & C & 24 & 60 & 38 & 345,939 & 3,544,988 & 2,828,128,000,716,774,492\\\\\nRhombic Triacontahedron & C & 30 & 60 & 32 & ? & ? & 5,266,831,101,345,821,968\\\\\n  \\hline  \n\\end{tabular}\n}\n\\caption{Table of polyhedra in the Platonic (P), Archimedean (A), and Catalan (C) solid classes of up to 32 faces and their Building Game state space statistics.}\n\\label{fig:bgtable}\n\\end{figure}\n\n\n\n\n\n\n%%%%%%%\n\n\nThe process begins with each face of a polyhedron \\poly\\spc all colored the same color, say \\colorA. A face is then chosen and its color is changed to a second color, \\colorB. From there, at each step a \\colorA\\spc face that is edge-adjacent to a \\colorB\\spc face is chosen and recolored \\colorB. The process continues until all of \\poly's faces are \\colorB. We show one instance of the Building Game process for the dodecahedron in figure~\\ref{fig:DodecBG}. \n\nEach possible coloring of the polyhedron from the Building Game is referred to as an \\textbf{intermediate}. Since we assume each face of the same color is otherwise indistinguishable, there is a rotational equivalence class on intermediate such that two intermediates are equivalent if the first is a rotation of the second. \n\n\\begin{figure}[ht]\n\\caption{One instance of the Building Game on the dodecahedron.}\n\\label{fig:DodecBG}\n\\end{figure}\n\nWe define the \\textbf{state space} of the Building Game to be a graph in which the nodes are all of the possible intermediates allowed by the BG. Connections exist between two intermediates \\xj\\spc and \\xk\\spc if it is possible to color a single face of \\xj\\spc to form \\xk. Interestingly, it is not the case that the recoloring of each face of \\xj\\spc maps to a distinct intermediate. Thus, the number of different faces of \\xj\\spc that can be colored to form \\xk\\spc is called the \\textbf{degeneracy number} \\Sjk. It is important to note that in general the degeneracy number is not symmetric, i.e. \\Sjk$\\neq$\\Skj\\spc for some connections \\xj\\spc$\\leftrightarrow$\\spc\\xk\\spc in the state space. \n\n\nSince the state space can be partitioned by the number of \\colorB\\spc faces each intermediate has, it is natural to view the state space as a tiered graph in which intermediates in each tier have the same number of \\colorB\\spc faces. Organized this way, intermediates can only connect to those in the tier above or below them. A \\textbf{pathway} in the state space is a sequence of intermediates $x^{k_0} \\to x^{k_1}\\to \\cdots \\to x^{k_F}$ connected in the state space such that $x^{k_0}$ is the intermediate with all \\colorA\\spc faces, $x^{k_F}$ is the intermediate with all \\colorB\\spc faces, and $x^{k_m}$ has $m$ \\colorB\\spc faces.  \n\n\n\n%%%%%%%%\n\n\nTo find the stationary measure of this process, we check if it is possible for our transition measure to satisfy the detailed balance equation $\\pi_jP_{jk} = \\pi_kP_{kj}$. As seen in equation~\\ref{eq:DBTry}, for detailed balance to be satisfied, we must find a way to separate the ratio $\\frac{S_{jk}}{S_{kj}}$ into a part depending only on $j$ terms and a part depending only on $k$ terms. \n\\begin{align}\n        \\frac{\\pi_k}{\\pi_j} &= \\frac{P_{jk}}{P_{kj}} \\\\\n        &= \\frac{S_{jk}\\rho_{jk}z_k}{S_{kj}\\rho_{kj}z_j} \\\\\n        &= \\frac{z_k}{z_j}\\frac{S_{jk}}{S_{kj}} \\label{eq:DBTry}\n\\end{align}\nWhile detailed balance is not a necessary condition for the existence of a stationary distribution, along with positive recurrence of the process, it is sufficient and would provide the exact form of the necessarily unique stationary distribution.\n\n\n%%%%%%%%%%\n\n\nAs stated in section~\\ref{sec:Prob}, if we can find a distribution $\\pi$ such that the detailed balance equation $\\pi_jP_{j,k} = \\pi_kP_{k,j}$ is satisfied, we know that $\\pi$ is the unique stationary distribution under $P_{jk}$. With theorem~\\ref{thm:J} we find that $\\frac{S_{jk}}{S_{kj}} = \\frac{r_j}{r_k}$ is indeed separable as conjectured in equation~\\ref{eq:DBTry}. This allows us to find the stationary distribution. \n\n\\begin{mythm}\n\\label{thm:E}\nThe Markov chain $X_t$ defined by the transition rule $P_{jk}$ in equation~\\ref{eq:TransitionProbability} admits the unique stationary distribution $\\pi_j = \\frac{1}{z}\\left(\\frac{z_j}{r_j}\\right)$ where $z \\doteq \\sum_i \\frac{z_i}{r_i}$ is the partition function. \n\\end{mythm}\n\\begin{proof}\nIt suffices to show detailed balance and that each state is positively recurrent. By our definitions of $\\pi$ and $P$ along with Theorem~\\ref{thm:J}, we find detailed balance. \n\\begin{align}\n        \\pi_jP_{jk} &= \\frac{z_j}{z r_j}\\frac{1}{z_j}S_{jk}\\rho_{jk} \\\\ \n                  &= \\frac{1}{z}\\left(\\frac{S_{jk}}{r_{j}}\\right)\\rho_{jk} \\\\\n                  &= \\frac{1}{z}\\left(\\frac{S_{kj}}{r_k}\\right)\\rho_{kj} \\\\\n                   &= \\frac{z_k}{z r_k}\\frac{1}{z_k}S_{kj}\\rho_{kj} \\\\\n                    &= \\pi_kP_{kj}\n\\end{align}\nClearly $X_t$ is positive recurrent since it is a finite irreducible Markov chain on a connected state space in which there exist forward and backward transitions between each connected node with positive probabilities.\n\\end{proof}\n\n", "meta": {"hexsha": "f58f98010d029c2c5805bbebdf1eb8916f1fd14f", "size": 30069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Existing Writing Dump/Keep/em_paper.tex", "max_stars_repo_name": "Danie1Johnson/thesis", "max_stars_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Existing Writing Dump/Keep/em_paper.tex", "max_issues_repo_name": "Danie1Johnson/thesis", "max_issues_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Existing Writing Dump/Keep/em_paper.tex", "max_forks_repo_name": "Danie1Johnson/thesis", "max_forks_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_forks_repo_licenses": ["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.8684210526, "max_line_length": 868, "alphanum_fraction": 0.6547274602, "num_tokens": 10340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.6482856747938529}}
{"text": "\\documentclass{memoir}\n\\usepackage{notestemplate}\n\n%\\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}\n%\\institute{Rice University}\n%\\faculty{Faculty of Whatever Sciences}\n%\\department{Department of Mathematics}\n%\\title{Class Notes}\n%\\subtitle{Based on MATH xxx}\n%\\author{\\textit{Author}\\\\Gabriel \\textsc{Gress}}\n%\\supervisor{Linus \\textsc{Torvalds}}\n%\\context{Well, I was bored...}\n%\\date{\\today}\n\n%\\makeindex\n\n\\begin{document}\n\n% \\maketitle\n\n% Notes taken on 06/09/21\n\nLet \\(V\\) be a finite dimensional vector space over \\(F\\) with dimension \\(n\\), and \\(T\\) a fixed linear transformation of \\(V\\). Recall that we can view \\(V\\) as an \\(F[x]\\)-module where \\(x\\) acts on \\(V\\) as the linear transformation \\(T\\).\\\\\n\nBecause \\(V\\) has finite dimension over \\(F\\), it must be a torsion \\(F[x]\\)-module. Hence \\(V\\) is isomorphic as an \\(F[x]\\)-module to the direct sum of cyclic, torsion \\(F[x]\\)-modules.\\\\\n\nWhen we decompose \\(V\\) into the invariant factor decomposition basis, we obtain the rational canonical form for the matrix for \\(T\\). When we use the elementary divisor decomposition, we obtain the Jordan canonical form.\n\n\\begin{defn}[Minimal Polynomial]\n The \\textbf{minimal polynomial of \\(T\\)} is the unique monic polynomial \\(m_T(x) \\in F[x]\\) that generates the ideal \\(\\textrm{Ann}(V)\\) in \\(F[x]\\).\\\\\n\n Let \\(A\\) be a matrix. The \\textbf{minimal polynomial of \\(T\\)} is the unique monic polynomial of smallest degree \\(m_A(x)\\) that yields the zero matrix when evaluated at \\(A\\).\n\\end{defn}\n\nThe \\textbf{rational canonical form} of the linear transformation \\(T\\) is the isomorphism\n\\begin{align*}\n\tV \\cong F[x] / (a_1(x)) \\oplus F[x] / (a_2(x)) \\oplus \\ldots \\oplus F[x] / (a_m(x))\n\\end{align*}\nwhere \\(a_1(x),a_2(x),\\ldots,a_m(x)\\) are polynomials in \\(F[x]\\) of positive degree such that\n \\begin{align*}\n\t a_1(x) \\mid a_2(x) \\mid \\ldots\\mid a_m(x)\n\\end{align*}\nOf course, the annihilator of \\(V\\) is the ideal \\((a_m(x))\\), and so we obtain:\n\\begin{prop}\n\tThe minimal polynomial \\(m_T(x)\\) is the largest invariant factor of \\(V\\).\n\\end{prop}\n\nObserve that we can get a basis for the vector space \\(F[x] / (a(x))\\) for a fixed\n\\begin{align*}\n\ta(x) = x^{k}+ b_{k-1}x^{k-1} + \\ldots + b_1 x + b_0\n\\end{align*}\nby defining \\(\\overline{x}^{k}= (x \\pmod{a(x)})^{k}\\). The basis is then \\(\\left\\{ 1,\\overline{x},\\overline{x}^2,\\ldots,\\overline{x}^{k-1} \\right\\} \\) which has an action under multiplication by \\(x\\) given by:\n\\begin{align*}\n\t1 \\mapsto \\overline{x}\\\\\n\t\\overline{x} \\mapsto \\overline{x}^2\\\\\n\t\\vdots\\\\\n\t\\overline{x}^{k-2}\\mapsto \\overline{x}^{k-1}\\\\\n\t\\overline{x}^{k-1}\\mapsto \\overline{x}^{k} = -b_0 - b_1\\overline{x} - \\ldots - b_{k-1}\\overline{x}^{k-1}\n\\end{align*}\nwhich follows because\n\\begin{align*}\n\t\\overline{x}^{k} + b_{k-1}\\overline{x}^{k-1} + \\ldots + b_1\\overline{x}+b_0 = 0\n\\end{align*}\nThis gives us a matrix for multiplication by \\(x\\):\n\\begin{defn}[Companion Matrix]\n\tLet \\(a(x) = x^{k}+ b_{k-1}x^{k-1}+ \\ldots + b_1x + b_0\\) be a monic polynomial in \\(F[x]\\). The \\textbf{companion matrix} of \\(a(x)\\) is the \\(k\\times k\\) matrix representing the matrix for multiplication by \\(x\\), and is of the form\n\t\\begin{align*}\n\t\t\\begin{pmatrix} \n\t\t\t0 & 0 & \\ldots & \\ldots & -b_0\\\\\n\t\t\t1 & 0 & \\ldots & \\ldots & -b_1 \\\\\n\t\t\t0 & 1 & \\ldots & \\ldots & -b_2\\\\\n\t\t\t\\vdots & \\vdots &   & \\ddots & \\vdots\\\\\n\t\t\t0 & 0 & \\ldots & 1 & -b_{k-1}\n\t\\end{pmatrix}\n\t\\end{align*}\n\tWe denote the companion matrix of \\(a(x)\\) by \\(\\mathcal{C}_{a(x)}\\).\n\\end{defn}\n\nNow we will apply this to each of the cyclic modules in the rational canonical form of \\(V\\). Let \\(\\mathcal{B}_i\\) be the set of basis elements for each cyclic factor \\(F[x] / (a_i(x))\\). The linear transformation \\(T\\) acts on \\(\\mathcal{B}_i\\) by the companion matrix for \\(a_i(x)\\), and hence the union \\(\\mathcal{B} = \\cup_{i} \\mathcal{B}_i\\) and the matrix of the transformation on \\(V\\) is the direct sum of the companion matrices.\n\n\\begin{defn}[Rational Canonical Form]\n\tA matrix is said to be in \\textbf{rational canonical form} if it is the direct sum of companion matrices for monic polynomials \\(a_1(x),\\ldots,a_m(x)\\) with\n\t\\begin{align*}\n\t\ta_1(x) \\mid a_2(x) \\mid \\ldots \\mid a_m(x).\n\t\\end{align*}\n\tThe matrix is then of the form\n\t\\begin{align*}\n\t\t\\begin{pmatrix} \n\t\t\t\\mathcal{C}_{a_1(x)} & & & \\\\\n\t\t\t& \\mathcal{C}_{a_2(x)} & & \\\\\n\t\t\t& & \\ddots & \\\\\n\t\t\t& & & \\mathcal{C}_{a_m(x)}\n\t\t\\end{pmatrix}.\n\t\\end{align*}\n\tThe polynomials are called the \\textbf{invariant factors} of the matrix, and the matrix is said to be a \\textbf{block diagonal matrix} with the blocks being the companion matrices for \\(a_i(x)\\).\\\\\n\n\tA \\textbf{rational canonical form} for a linear transformation \\(T\\) is a matrix representing \\(T\\) in rational canonical form.\n\\end{defn}\nOne can check that every linear transformation \\(T\\) has a rational canonical form that is unique.\n\n\\begin{thm}[Rational Canonical Form for Linear Transformation]\n\tLet \\(V\\) be a finite dimensional vector space over the field \\(F\\) and let \\(T\\) be a linear transformation of \\(V\\). Thne there is a basis for \\(V\\) and the matrix of \\(T\\) is in rational canonical form with respect to this basis. Furthermore, the rational canonical form for \\(T\\) is unique.\n\\end{thm}\nWe will see that this exists for every \\(T\\), but Jordan canonical form may not.\\\\\n\nFor linear transformations \\(S\\) and \\(T\\), the following are equivalent:\n\\begin{itemize}\n\t\\item \\(S\\) and \\(T\\) are similar linear transformations\n\t\\item The \\(F[x]\\)-modules obtained from \\(V\\) via \\(S,T\\) are isomorphic\n\t\\item \\(S\\) and \\(T\\) have the same rational canonical form\n\\end{itemize}\nOf course, any matrix can be translated into a rational canonical form, as each matrix corresponds to a linear transformation. The \\textbf{invariant factors} of an \\(n\\times n\\) matrix over a field \\(F\\) are the invariant factors of its rational canonical form.\n\n\\begin{lemma}\n\tLet \\(a(x) \\in F[x]\\) be any monic polynomial. The characteristic polynomial of the companion matrix of \\(a(x)\\) is \\(a(x)\\), and if  \\(M\\) is given by\n\t\\begin{align*}\n\t\tM = \n\t\t\\begin{pmatrix}\n\t\t\tA_1 & 0 & \\ldots & 0 \\\\\n\t\t\t0 & A_2 & \\ldots & 0\\\\\n\t\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t\t0 & 0 & \\ldots & A_k\n\t\t\\end{pmatrix} \n\t\\end{align*}\n\tthen the characteristic polynomial of \\(M\\) is the product of the characteristic polynomials of \\(A_1,A_2,\\ldots,A_k\\).\n\\end{lemma}\n\n\\begin{thm}[Cayley-Hamilton Theorem]\n\tLet \\(A\\) be an \\(n\\times n\\) matrix over the field \\(F\\). The minimal polynomial of \\(A\\) divides the characteristic polynomial of \\(A\\).\n\\end{thm}\nIn fact, the characteristic polynomial of \\(A\\) divides some power of the minimal polynomial of \\(A\\).\n\n\\begin{thm}\n\tLet \\(A\\) be an \\(n\\times n\\) matrix over the field \\(F\\). The \\(n\\times n\\) matrix \\(xI - A\\) can be put into the diagonal form\n\t\\begin{align*}\n\t\t\\begin{pmatrix} \n\t\t\t1 & & & & &\\\\\n\t\t\t  & \\ddots & & & &\\\\\n\t\t\t  & & 1 & & &\\\\\n\t\t\t  & & & a_1(x) & &\\\\\n\t\t\t  & & & & \\ddots & \\\\\n\t\t\t  & & & & & a_m(x)\n\t\t\\end{pmatrix}\n\t\\end{align*}\n\twith monic nonzero elements\n\t\\begin{align*}\n\t\ta_1(x) \\mid a_2(x) \\mid \\ldots \\mid a_m(x).\n\t\\end{align*}\n\tvia the operations\n\t\\begin{itemize}\n\t\t\\item interchanging two rows or columns\n\t\t\\item adding a multiple of one row or column to another\n\t\t\\item multiplying any column or row by a unit in \\(F[x]\\)\n\t\\end{itemize}\n\tThe elements \\(a_1(x),\\ldots,a_m(x)\\) are the invariant factors of \\(A\\).\n\\end{thm}\n\n\\subsection{Invariant Factor Decomposition Algorithm}\n\\label{sub:invariant_factor_decomposition_algorithm}\n\n%% Fill in\n\n\\subsection{Converting an \\(n\\times n\\) Matrix to Rational Canonical Form}\n\\label{sub:converting_an_n_by_n_matrix_to_rational_canonical_form}\n\n\n% \\printindex\n\\end{document}\n", "meta": {"hexsha": "fb4b1f2cac25cc460b57144511b36c0e864cb896", "size": 7682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Module Theory/Notes/source/CanonicalForms.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": "Module Theory/Notes/source/CanonicalForms.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": "Module Theory/Notes/source/CanonicalForms.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": 45.4556213018, "max_line_length": 438, "alphanum_fraction": 0.6683155428, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6482856731626594}}
{"text": "\\chapter{Appendix Probability}\r\n\r\n\\section*{Probability Basics}\r\nLet $\\mu$ be a non-negative countably additive set function over a sigma algebra $\\Omega$ of sets from a sample space $S$. In probability theory, $\\Omega$ is the set of possible events $E$. Sets of measure zero denote impossible outcomes. An important feature of measures $\\nu$ and $\\mu$ that agree on sets of measure zero is the ability to define a derivative $\\frac{d \\nu}{d \\mu}$, the Radon-Nikodym derivative.  When $\\nu (E)=0 \\fall E \\in \\Omega \\;| \\; \\mu(e)=0$  Alternatively, given a measure $\\mu$ and a nonnegative measurable function $f$, a new measure can be defined by $ \\nu(E) = \\int\\limits{E \\in \\Omega}{} f d \\mu$. A random variable is a real valued function on a sample space into a metric space, $X : S \\rightarrow \\dblr^{1} $. Associated with a random variable is it's probability density function $f_{X}(x)=P(\\{s \\in S | X(s) = x\\})$ operating on an algebra of sets generated by the sample space $S$. By definition, $f_{X}(x)$ is the sum of probabilities of the events in $S$ that get mapped to $x \\in \\dblr$ by $X$.  Let $\\script{B}(S)$ be the Borel sets on $S$, then $X$ has density $f$ if $P(X \\in A) = \\int_{A \\in \\script{B}(S)} f(x) dx $ and distribution function $F(x) = P(X<x)=\\int\\limits_{-\\infty}^x f(y) dy$ so $F'(x)=f(x) \\;\\; a.e.$.  $E(X)=\\int x f(x) dx$ is the expectation of $X$.  The characteristic function $\\phi(x) = E(e^{itX} )$ determines the distribution and is used in the proof of the CLT theorem, testing for symmetry, and conditional independence.  We denote samples with lower case in this section.  $x_1 \\ldots x_n$ is a random sample of size $n$  In $\\dblr^n$ the random variate $X$ has distribution function $F(x_i, \\ldots , x_n) = P(X_1<x_1, \\ldots , X_n<x_n )$ and density $f(x_1, \\ldots , x_n )$.\r\n\r\nFor parametric distributions, one is interested in the question of what value of a parameter best describes the data at hand.  This obviously requires the assumption that the data derives from a family of distributions parameterized by one or more variables $\\theta_k$.  If $x_1 \\ldots x_n$ is a random sample from $X$ with a distribution given by $p(x;\\theta_1 \\ldots \\theta_k)$, we can think of the joint pdf of of the sample $L(x_i, \\ldots,x_n) = \\prod\\limits_{i=1}^{n} p(x_i;\\theta_1 \\ldots \\theta_k)$ as being explained by the parameters.  $L$ is the likelihood of the data given the parameters.  The maximum likelihood estimate is obtained by solving the set of equations;\r\n\\begin{eqnarray} \\nonumber\r\n  \\frac{\\partial L(\\theta_1 \\ldots \\theta_k)}{\\partial\r\n  \\theta_1}=0 \\\\ \\nonumber\r\n  \\vdots \\\\ \\nonumber\r\n   \\frac{\\partial L(\\theta_1 \\ldots \\theta_k)}{\\partial\r\n   \\theta_k}=0 \\\\ \\nonumber\r\n\\end{eqnarray}\r\n\r\n%$ P(X), P(X|Y), P(X,Y) p(x) p_i x_i \\mathbf{X} \\mathbf{\\beta}$\r\n\r\nThe statistical moments of a random variable $X$ are defined $\\mu_n = E [ X^n] = \\int_\\Omega X^n P(X)dX$.  The characteristic function is the fourier transform of $P(X)$ \\[\\Phi(\\omega)=\\digamma \\mathcal{F} [P(X)] (\\omega) = \\int\\limits_{\\infty}^{\\infty} e^{i \\omega X} P(X) dX.\\]  Taking the logarithm and expanding in a MacLauren series, we can relate the statistical moments to the coefficients. Statistical moments are central or raw.\r\n\r\nCommon sample descriptive statistics relating to location, scale, tail size,  and peakedness;\r\n\\[ mean = \\hat{\\mu_1} = \\frac{1}{n}\\sum x_i  \\]\r\n\\[ variance = sdd^2 =  \\hat{\\mu_2} = \\frac{1}{n-1} \\sum (x_i- \\hat{\\mu_1}\\]\r\n\\[ skewness = \\frac{ \\hat{\\mu_3}}{\\hat{\\mu_2}^{3/2}} \\]\r\n\\[ kurtosis = \\frac{\\hat{\\mu_4}}{\\hat{\\mu_2}^2} \\]\r\nThe linear association between $X_i$ and $X_j$ is measured by the covariance \\[ Cov_{ij} = \\sigma_{ij} = \\frac{1}{n-1} \\sum_k (x_ki - \\hat{\\mu_1}_i)(x_{kj} - \\hat{\\mu_1}_j). \\]  For a measure without dependence on units the scaled covariance is the correlation \\[C_{ij} =\\frac{\\sigma_{ij}}{\\sqrt{\\sigma_{ii}}\\sqrt{\\sigma_{jj}}}\\]\r\n\r\n\\section*{Univariate Probability Distributions}\r\nThis section covers the properties of common univariate\r\nprobability distributions.\r\n\r\n\\subsection{Uniform,  $U(\\alpha,\\beta)$}\r\n$X=_d U(\\alpha,\\beta)$ if $p(x; \\alpha, \\beta)=\r\n\\frac{\\chi_{[\\alpha,\\beta]}}{\\beta-\\alpha}.$\r\n\r\n\\subsection{Exponential Class of Distributions}\r\nThe exponential class of distributions are characterized by the\r\nfunctional for of the pdf; \\[ p(x;\\theta) =\r\nexp(\\alpha(x)\\beta(\\theta)+\\gamma(\\theta)+\\delta(x) ) \\].  This\r\nclass of distributions form the basis of Generalized Linear\r\nModel Theory that is discussed below.\r\n\r\nThere is an alternate parametrization of the exponential family\r\nthat explicitly includes a dispersion parameter $\\phi$.  This\r\nis useful for count data where $E[X]=E[X^2]=\\theta$  In general\r\nif $E[X^2]>E[X]$ we say the process  or data is over dispersed.\r\nThe parameter $\\phi$ is usually fixed in practice.  If we write\r\n\\[ p(x; \\theta, \\phi)=exp(\\frac{x \\theta-\r\n\\beta(\\theta)}{\\alpha(\\phi)}+\\gamma(x,\\phi))\\], the dispersion\r\nparameter $\\phi$ for some common distributions;\r\n\\[\r\n\\begin{array}{cc}\r\np(x;\\theta, \\phi) & \\phi \\\\ \\hline\r\nN(\\mu,\\sigma) & \\sigma^2 \\\\\r\nIG(\\mu,\\sigma) & \\sigma^2 \\\\\r\nGamma(\\theta,\\phi) & \\frac{1}{\\phi} \\\\\r\nPoisson(\\theta) & 1 \\\\\r\nBinomial(\\theta) & 1 \\\\\r\nNegative Binomial(\\theta,r) & r \\\\\r\n\\end{array}\r\n\\]\r\n\r\n\\subsubsection{Normal/Gaussian, $N(\\mu,\\sigma)$}\r\n$X=_d N(\\mu,\\sigma)$ if \\[p(x; \\mu, \\sigma) = \\frac{1}{\\sqrt{2\r\n\\pi \\sigma^2}} exp ( \\frac{(x-\\mu)^2}{2 \\sigma^2}\\].  This can\r\nbe re-written in exponential form \\[ p(x;\\theta) = exp( \\frac{x\r\n\\theta}{2 \\sigma^2} - \\frac{\\theta^2}{2 \\sigma^2 }-\r\n\\frac{1}{2}log(2 \\pi \\sigma^2) - \\frac{x^2}{2 \\sigma^2 } ) \\]\r\n\r\n\\subsubsection{Binomial}\r\nSetting \\[\\alpha(x)=x \\;\\;,\r\n\\beta(\\theta)=log(\\frac{\\theta}{1-\\theta}) \\;\\;,\r\n\\gamma(\\theta)=n log(1-\\theta) \\;\\;, \\delta(x)=log ( \\biggl(\r\n\\begin{array}{c}  n \\\\  y \\\\ \\end{array}  \\biggr) )\r\n\\] gives us the binomial distribution $p(x;\\theta) = \\binomial{n}{x} \\theta^x\r\n(1-\\theta)^{(n-x)}$\r\n\r\n\\subsubsection{Negative Binomial}\r\n\\[p(x;\\theta,r)=\\binomial{x+r-1}{r-1} \\theta^r (1-\\theta)^x\\]\r\n\r\n\\subsubsection{Poisson}\r\n$X$ is Poisson distributed if $p(x;\\theta)=\\frac{\\theta^x\r\ne^{-\\theta}}{x!}$  Setting $\\beta(\\theta)=log(\\theta) \\;\\;,\r\n\\gamma(\\theta)=-\\theta \\;\\;, \\delta(x)=-log(x!)$ we get the\r\nexponential form of the Poisson distribution,\r\n\\[p(x;\\theta)= exp(x log(\\theta) - \\theta- log(x!))\\]\r\n\r\nThe expected value and the variance of a Poisson distributed random variable is equal to $\\theta$. The higher moments of the Poisson distribution are the Touchard polynomials in $\\theta$.  There is a combinatorial interpretation.  When $E[X]=1$ for a Poisson random variate then the i-th moment of $X$ is equal to the number of partitions of a set of size n $\\frac{1}{e} \\sum\\limits_{n=0}^{\\infty} \\frac{n^i}{n!}$ via Dobinski.  The normal distribution with mean $\\theta$ and variance $\\theta$ is a good approximation to the Poisson distribution for large $\\theta$.\r\n\r\n\r\n\\subsubsection{Pareto}\r\n$X$ is Pareto distributed if \\[p(x;\\theta)=\\theta\r\nx^{-\\theta}.\\]\r\n\r\n\\subsubsection{Gamma}\r\n$X$ is Gamma distributed if \\[p(x;\\theta,\r\n\\phi)=\\frac{x^{\\phi^{-1}}\\theta^\\phi e^{-x \\theta}} {\r\n\\Gamma(\\phi)}.\\]\r\n\r\n\\subsubsection{Weibull}\r\n$X$ follows the Weibull distribution if \\[p(x; \\theta , \\lambda\r\n) = \\frac{\\lambda x^{\\lambda-1}}{\\theta^\\lambda}\r\ne^{(\\frac{x}{\\theta} )^\\lambda}.\\]\r\n\r\n\\subsubsection{Inverse Gaussian/ Wald Distribution}\r\n$X$ follows the Inverse Gaussian distribution if\r\n\\[p(x;\\theta)= \\sqrt{\\frac{\\theta}{2 \\pi x^3 \\sigma}}exp(-\r\n\\frac{\\lambda(x-\\theta)^2}{2 x \\theta^2 \\sigma}) \\]\r\n\r\n\\subsection{Generalized Extreme Value Distribution $GEV(\\theta,\\phi,\\xi)$}\r\nThis class of distributions includes the three limiting extreme\r\nvalue distributions of \\cite{Fisher Tippet (1928)} and\r\n\\cite{Gnedenko (1943)}.  $X =_d GEV(\\theta,\\phi,\\xi)$ if\r\n\\[p(x;\\theta,\\phi,\\xi)= exp( -  max\\biggl(\\bigl(1 + \\xi\r\n\\frac{x-\\theta}{\\phi} \\bigr)^{- \\frac{1}{\\xi} }, \\;\\; 0 \\biggr)\r\n\\]. Where\r\n\r\n\r\n\\subsection{Multinomial}%bbcrevisit explanation\r\nLet \\[\\Omega=\\mathcal{B}(\\prod\\limits_{i=0}^{i=\\infty}\r\n\\dblz(K))\\] be the Borel Algebra generated by $\\prod {1, 2,\r\n\\hdots , K}$. This is the sample space of all realizations of\r\nexperiments with $K$ categorical outcomes. Equip $\\dblz(K)= {i\r\n\\in {1, \\hdots, K}}$ with a measure $P(i)=\\theta_i$. Let\r\n${X_i}$ be n iid copies of $X =_d p(i ; \\pi_1, \\hdots ,\r\n\\pi_K)$.  Now map $\\mbf{X}=(X_1, \\hdots, X_n) \\in \\Omega\r\n\\rightarrow \\mbf{Y} \\in \\dbln^K$  Then $Y_i$ are counts of the\r\nnumber of elements of category $i$ in the experiment with n\r\nobservations.  The multinomial distribution is given by\r\n\\[p(\\mbf{Y};n)=\\frac{n!}{y_1! \\hdots y_K!} (\\theta_1)^{y_1} \\hdots\r\n(\\theta_K)^{y_K} \\].  This in not a member of the exponential\r\nfamily, but we can show that the multinomial distribution is\r\nthe joint distribution of ${Y_i =_d Poission(\\theta'_i)}_{i=1,\r\n\\hdots K}$ random variables conditional to their sum.\r\n\\[p(\\mbf{Y}; \\theta'_1, \\hdots , \\theta'_K) =\r\n\\prod\\limits_{i=1}^{K} \\frac{ (\\theta'_i)^{y_i} \\;\r\ne^{-\\theta'_i}}{y_i!}\\], set $n=Y_1 + \\hdots + Y_K$. Writing\r\n$p(\\mbf{Y} | n) =p(\\mbf{Y}; \\theta'_1, \\hdots ,\r\n\\theta'_K) / p(n)$ and noting that $n=_d Poisson(\\sum\\limits_{i=1}^{K} \\theta'_i)$, %bbcrevisit this is an exercise\r\nwe recover the multinomial distribution by simplifying and\r\nsetting $\\theta_i=\\frac{\\theta'_i}{\\sum\\limits_{i=1}^{K}\r\n\\theta'_i}$\r\n\r\n\\subsection{$\\chi^2(n)$}\r\nIf ${X_i}$ iid $N(0,1)$ and $Y_i=X_i^2$ then\r\n$Y=\\sum\\limits_{i=1}^{n} Y_i =_d \\chi^2(n).$  $E[Y]=n$ and\r\n$Var(Y)=E[(Y-\\mu_Y)^2]=E[(Y-E[Y])^2]=2n$. More generally, if\r\n$Y_i=X_i+\\mu_i$ then \\[Y=\\sum\\limits_{i=1}^{n} (Y_i)^2 =\r\n\\sum\\limits_{i=1}^{n} X_i^2 + 2 \\sum\\limits_{i=1}^{n} X_i \\mu_i\r\n+ \\sum\\limits_{i=1}^{n} \\mu_i^2 =_d \\chi^2(n,\\lambda)\\].  Where\r\n$\\lambda=\\sum\\limits_{i=1}^{n} \\mu_i$ is non-centrality\r\nparameter.\r\n\r\nSee the section on multivariate probability distributions for\r\nfurther information, but it is worth noting that if $X =_d\r\nN(\\mu,\\sigma)$ is multivariate and the variance covariance\r\nmatrix $s\\sigma$ is non-singular, then $(y-\\mu)^T  \\sigma^{-1}\r\n(y-\\mu) =_d \\chi^2(n)$ and setting $\\lambda= \\mu^T \\sigma^{-1}\r\n\\mu$ we have $ y^T \\sigma^{-1} y =_d \\chi^s(n,\\lambda)$\r\n\r\n\\subsection{Student-t $t(\\nu)$}\r\n$X =_d \\frac{\\Gamma(\\frac{\\nu+1}{2})}{\\sqrt{\\pi} \\Gamma(\\nu\r\n/2)}(1+x^2)^{- \\frac{\\nu+1}{2}}$\r\n\r\n%\\cite{C. C. Heyde and N. N. Leonenko 2005}\r\n\r\n\\subsection{Generalized Inverse Gaussian $GIG(\\lambda,\\alpha,\\beta )$}\r\nThe GIG distributions are characterized by\\[p(x; \\lambda,\r\n\\theta,\\sigma)=\\bigl(\\frac{\\theta}{\\sigma}\\bigr)^{\\frac{\\lambda}{2}}\r\nx^{\\lambda-1}\\: \\frac{1}{2 K_\\lambda (\\sqrt{\\theta \\sigma})} \\:\r\nexp(-\\frac{1}{2} ( \\theta x^{-1} + \\sigma x) \\].\r\n\r\nNote,  $GIG(-1/2,\\theta,\\sigma)=IG(\\theta,\\sigma)$\r\n\r\nThe GIG family members arise as first passage time\r\ndistributions of ordinary Brownian diffusions to a constant\r\nboundary.\r\n\r\n\\subsection{ Normalized Inverse Gaussian $NIG(\\mu,\\alpha,\\beta,\\delta)$}\r\n$X =_d NIG(\\mu,\\alpha,\\beta,\\delta)$ if \\[p(x;\\mu,\r\n\\beta,\\alpha,\\delta)= \\frac{\\delta \\alpha}{\\pi} exp \\bigl(\r\n\\delta \\sqrt{\\alpha^2 - \\beta^2}+\\beta(x-\\mu) \\bigr)\r\n\\frac{K_1(\\alpha \\; s_\\delta(x-\\mu))}{s_\\delta(x-\\mu)}\\]\r\n\r\nwhere $x \\in \\dblr \\;\\; \\mu \\in \\dblr \\;\\; \\delta>0 \\;\\; 0 \\leq\r\n|\\beta| \\leq \\alpha$ and $s_\\delta(x)=\\sqrt{\\delta^2+x^2}$ and\r\n$K_1(x)=\\frac{x}{4} \\int\\limits_{0}^{\\infty} exp - \\bigl (\r\ny+\\frac{x^2}{4 y} \\bigr ) y^{-2} \\;dy$ is the modified Bessel\r\nfunction of the third kind.  This family of distributions is\r\ninfinitely divisible, $\\exts \\;\\; X_t$, a Levy process, $ X_{t+\r\n\\Delta t} - X_t =_d X_{\\Delta t} =_d\r\nNIG(\\mu,\\alpha,\\beta,\\delta)$. $X_t$ is a pure jump process,\r\nand\r\n\\[p(t; \\alpha,\\beta,\\delta)= \\biggl( \\frac{\\delta \\alpha}{\\pi |t|}\r\n\\biggr) e^{\\beta t} K_1(\\alpha  |t|)\\]. See Eberlein and Keller\r\n(1995) and  Barndorff-Nielsen (1998)\r\n\r\n\r\n\\subsection{Generalized Hyperbolic $GH(\\lambda,\\alpha,\\beta,\\delta,\\mu)$}\r\nThe parameters $\\lambda,\\alpha,\\beta,\\delta,\\mu$ have the\r\nrespective interpretation of tail heaviness, kurtosis,\r\nskewness, and scale, and location.  The distribution includes\r\nthe important classes GIG, NIG, IG, and can be characterized as\r\na Normal variance-mean mixture NVMM parameterized by a GIG\r\ndistribution. Formally set $U=_d GIG()$, then $X=_d NVMM( )$ if\r\n$P(X|U=u) =_d N(\\mu+ \\beta, u \\Delta)$.  This gives a\r\nstochastic representation $X= \\mu+\\beta Z + \\sqrt{Z} Y$ where\r\n$Y =_d N(0,1)$ and $Z =_d GIG( )$.\r\n\r\n\\section*{Limit Theorems}\r\nLimit Theorems use the notion of a basin of attraction for pdf's in some functional space $\\mathcal{H}$. In $L^2(\\Omega)$, we have $N(\\mu,\\sigma) \\subset L^2(\\Omega, \\nu)$ is the basin of attraction for all pdf's satisfying the conditions of the CLT.\r\n\r\nThe CLT says that the series $\\frac{\\sum\\limits_{i=1}^{n} X_i}{n}$ converges in in probability to the mean of $x_i$. Cramer's theorem gives a bound on the probability of large deviation away from the mean in the series $\\frac{\\sum\\limits_{i=1}^{n} X_i}{n}$.  The probability decays exponentially with a rate given by the Legendre transform of the cumulant generating function for $X_i$\r\n\\begin{thm}[Cramer's Theorem]\r\nLet $X_1, X_2, \\hdots $ be iid $E(X_i)=0$, $E(X_i^2)= \\sigma^2$, and $F_n(x) = P(\\frac{1}{\\sigma n^{\\frac{1}{2}}}  \\sum\\limits_{i=1}^{n} X_i < x)$, then if $x>1$ and $x=O(\\sqrt{n})$ as  $n \\rightarrow \\infty$\r\nwe have\r\n\\begin{eqnarray*}\r\n  \\frac{1-F_n(x)}{1-\\Phi(x)} = exp ( \\frac{x^3}{\\sqrt{n}} \\lambda( \\frac{x}{\\sqrt{n}} )  ) [ 1 + O(\\frac{x}{\\sqrt{n}}) ]\r\n\\end{eqnarray*}\r\n\r\n$\\lambda(x) = \\sum\\limits_{i=0}^{\\infty} c_i x_i$   where the $c_i$ depend on the moments of $X_i$.\r\n$\\Phi(x)$ is the distribution\\ function of $N(0,1)$.\r\n\\end{thm}\r\n\r\n\\begin{thm}[Law of Large Numbers]\r\n\\end{thm}\r\n\r\nThe CLT tells us that the pdf of the scaled mean of a sample approaches the normal distribution and the Berry–Esseen theorem specifies the rate at which that happens.  The CLT requires $X_i$ to be iid, and with finite second moment and the Berry-Esseen theorem additionally requires a finite third moment.\r\n\\begin{thm}[Berry–Esseen]\r\nLet ${X_i}$ be iid, $E(X_i^2)=\\sigma$, $E(X_i^3)=\\rho$, $Y_n = \\frac{X_1 + \\ldots + X_n}{n}$, and $F_n = \\int \\frac{Y_n \\sqrt{n} }{\\sigma}$ and $\\Phi$ the CDF of $N(0,1)$, then\r\n\\begin{equation}\r\n\\abs{F_n(x) - \\Phi(x)} \\leq \\frac{C \\rho}{ \\sigma^3 \\sqrt{n} }\r\n\\end{equation}\r\n\r\n\\end{thm}\r\n\r\n\\section*{Multivariate Probability Distributions}\r\n\r\nLet $S_n$ be the unit sphere in $\\dblr^n$ A random variate $X$\r\nis uniformly distributed on $S_n$ when $X$ is radially\r\nsymmetric and $||X||_{L^2} = 1 a.s.$  The pdf of a radially\r\nsymmetric random variable is necessarily of the form\r\n$f(x_1,...,x_n)=g(||x||)$ for some $g \\in [0,\\infty) \\ni\r\n\\int\\limits_{0}^{\\infty} n V_n r^{n-1} g(r) dr =1$ where\r\n$V_n=\\frac{\\pi^{\\frac{d}{2}}}{\\Gamma(\\frac{d}{2}+1) }$ is the\r\nvolume of $S_n$. If $X$ is radially symmetric , then\r\n$\\frac{X}{|||X||}$ is uniformly distributed on $S_n$.  If $X$\r\nis uniformly distributed on $S_n$ then $(X_1^2, \\ldots ,\r\nX_{n}^{2}) =_{dist} (\\frac{Y_1}{\\kappa} , \\ldots ,\r\n\\frac{Y_n}{\\kappa} )$ where $Y_i$ iid $\\Gamma(\\frac{1}{2})$\r\nwith sum $\\kappa$.  If $N_1, \\ldots , N_n$ iid normal, then\r\n$(N_1, \\ldots , N_n)$ is radially symmetric with density $g(r)\r\n= \\frac{1}{(2 \\pi)^{\\frac{n}{2} } } e^{\\frac{ - r^2}{2}}$  This\r\nleads us to an algorithm for generating pseudo random variants\r\non uniformly distributed on $S_n$ ;\r\n\\begin{itemize}\r\n    \\item Generate $n$ iid $N(0,1)$\r\n    \\item Compute $ \\kappa = ( \\sum\\limits_i=1^n N_i^2\r\n        )^\\frac{1}{2}$\r\n    \\item Return $(\\frac{N_1}{\\kappa} , \\ldots ,\r\n        \\frac{N_n}{\\kappa} )$\r\n\\end{itemize}\r\n\\cite{Devorye}\r\n\r\nWith a little linear algebra, the above can be generalized to a\r\ngenerator for $N(\\mu, \\Sigma ) \\in \\dblr^n$.  Consider $f(x)\r\n=\\frac{1}{(2 \\pi)^{\\frac{n}{2} } } e^{ - \\frac{1}{2} x^T \\dot x\r\n} x \\in \\dblr_n$, $f$ has density of $n$ iid $N(0,1)$ rv if\r\n\r\n\\subsection{Multivariate Normal $N(\\mbf{\\mu},\\mbf{\\Sigma})$ }\r\n$N(\\mbf{\\mu},\\mbf{\\Sigma})$ is arguably the most important and tractable multivariate probability distribution. The Gaussian distribution is separable via rotation.  Precisely the rotation induced by PCA.\r\n\r\n\\subsection{Wishart Distribution}\r\nThe Wishart distribution $W(n)$ is the multivariate generalization of the $\\chi^2(n)$ distribution.  If $X_{(i)} \\sim N(\\mbf{\\mu},\\mbf{\\Sigma})$, then\r\n$X X^t =S \\sim W(N)$.\r\n\r\n\\subsection{Elliptic $E(\\mbf{\\mu},\\mbf{\\Sigma})$}\r\nElliptical distributions $E(\\mbf{\\mu},\\mbf{\\Sigma})$ extend the multivariate normal $N(\\mbf{\\mu},\\mbf{\\Sigma})$.  They can be characterized as affine maps of spherical distributions. The density functions\r\nare defined by $p(x) = c g(  (x-\\mu)' \\Sigma^{-1} (x-\\mu) )$  Where $g : \\dblr^{+} \\longrightarrow \\dblr^{+}$ and $ \\Sigma \\succ 0$ is positive definite.\r\nMany of the properties of the multivariate normal distribution\r\nare shared by the elliptical distributions. Linear combinations, marginal distributions and conditional distributions of elliptical random variables can largely be determined by linear algebra using knowledge of covariance\r\nmatrix, mean and generator.\r\n\r\n\\section*{Statistical Dependence}\r\nLinear correlation is a natural dependence measure for\r\nmultivariate normally and elliptically distributed random variables.  Other dependence concepts include rank correlation, comonotonicity, and Brownian covariance.\r\n\r\n\r\n\\section*{Distance measures for probability distribution functions.}\r\nA number of distance measures for probability distance\r\nfunctions exist.  Kullbak Lieber divergence:\\[ J_D  =\r\n\\int\\limits_{\\text{x}} {[p({\\text{x}}\\mid\\omega_1 ) -\r\np({\\text{x}}\\mid\\omega_2 )]}\r\n     \\log \\frac{{p(x\\mid\\omega_1 )}} {{p(x\\mid\\omega_2 )}}{\\text{dx}}\\]\r\nwhich simplifies to:\\[ J_D  = \\tfrac{1} {2}\\left( {\\mu _2  -\r\n\\mu _1 } \\right)^T  \\left( {\\Sigma _1^{^{ - 1} }  + \\Sigma\r\n_2^{^{ - 1} } } \\right)\\left( {\\mu _2  - \\mu _1 } \\right) +\r\n\\tfrac{1} {2}{\\text{tr}}\\left\\{ {\\Sigma _1^{^{ - 1} } \\Sigma _2\r\n+ \\Sigma _2^{^{ - 1} } \\Sigma _1  - 2I} \\right\\}\\] when \\[X_1\r\n=_d N(\\mu_1,\\Sigma_1) \\;\\; , \\;\\; X_2 =_d N(\\mu_2,\\Sigma_2).\\]\r\n\r\nThe Bhattacharyya distance :\r\n\\[J_B  =  - \\log \\int {\\left[ {p(\\xi \\left| {\\omega _1 }\r\n\\right.)p(\\xi \\left| {\\omega _2 } \\right.)} \\right]} ^{{1/2}}\r\n{\\text{d}}\\xi\r\n\\] which simplifies to: \\[\r\nJ_B  = \\tfrac{1} {8}\\left( {\\mu _2  - \\mu _1 } \\right)^T \\left(\r\n{\\frac{{\\Sigma _1  + \\Sigma _2 }} {2}} \\right)^{ - 1} \\left(\r\n{\\mu _2  - \\mu _1 } \\right) + \\tfrac{1}\r\n{2}{\\text{log}}\\frac{{\\left| {\\tfrac{1} {2}(\\Sigma _1  + \\Sigma\r\n_2 )} \\right|}} {{( {\\left| {\\Sigma _1 } \\right|\\left| {\\Sigma\r\n_2 } \\right|} )^{1/2} }}\r\n\\] when \\[X_1 =_d  N(\\mu_1,\\Sigma_1) \\;\\; , \\;\\; X_2 =_d\r\nN(\\mu_2,\\Sigma_2).\\]\r\n\r\nThe Matusita distance:\r\n\\[J_T  = \\left\\{ {\\int {\\left[ {\\sqrt {p(\\xi \\left| {\\omega _1 }\r\n\\right.)}  - \\sqrt {p(\\xi \\left| {\\omega _2 } \\right.)} } \\right]}\r\n^2 {\\text{d}}\\xi } \\right\\}^{{1 / 2}} \\] which simplifies to: \\[\r\nJ_T = \\left\\{ {2\\left[ {1 - \\exp ( - J_B )} \\right]}\r\n\\right\\}^{{1/2 }} \\] where $J_B$ is the Bhattacharyya distance,\r\nwhen \\[X_1 =_d  N(\\mu_1,\\Sigma_1) \\;\\; , \\;\\; X_2 =_d\r\nN(\\mu_2,\\Sigma_2).\\]\r\n\r\nThe Patrick-Fisher distance:\r\n\\[J_P  = \\left\\{ {\\int {\\left[ {p(\\xi \\left| {\\omega _1 }\r\n\\right.)P_1  - p(\\xi \\left| {\\omega _2 } \\right.)P_2 } \\right]} ^2\r\n{\\text{d}}\\xi } \\right\\}^{{1/2}}\\] which simplifies to:\\[J_P =\r\n\\begin{array}{cc} {(2\\pi )^d \\left| {2\\Sigma _1 } \\right|} )^{ -\r\n{1/2}} + ( {(2\\pi )^d \\left| {2\\Sigma _2 } \\right|} )^{ - {1/2}} -\r\n\\\\ 2( {(2\\pi )^d \\left| {\\Sigma _1  + \\Sigma _2 } \\right|}\r\n)^{-{1/2}} \\exp \\left\\{ { - \\tfrac{1} {2}(\\mu _2  - \\mu _1\r\n)^T(\\Sigma _1  + \\Sigma _2 )^{ - 1} (\\mu _2  - \\mu _1 )}\r\n\\right\\}\\end{array}\\] when \\[X_1 =_d N(\\mu_1,\\Sigma_1) \\;\\;  ,\r\n\\;\\; X_2 =_d N(\\mu_2,\\Sigma_2).\\]\r\n Reference: pp257, et sqq., Devijver, P.A.\r\n\\& Kittler, J (1982) \"Pattern Recognition: A Statistical\r\nApproach\", Prentice Hall International, Englewood Cliffs, NJ.\r\n\r\n\\section*{$S_\\alpha(\\sigma,\\beta,\\mu)$ Stable Random Variates}\r\n\r\nA Levy process is a stochastic process with a drift, a diffusion, and a jump component.\r\nThe Lévy–Khinchine representation of a Levy process $X_t$ with parameters $(a,\\sigma^2,W)$\r\nis given by\r\n\r\nThe Levy-Ito decompositon of a Levy process $X_t$ is a decomposition of $X_t$ into\r\nsingular, absolutely continuous, and discrete processes\r\n\\begin{eqnarray*}\r\n X_{ac} : X_{ac} \\ll X \\\\\r\n X_s : X_s \\perp X \\\\\r\n X_d : card (supp X_d) = \\aleph_0\r\n\\end{eqnarray*}\r\nvia Lebesgue's decomposition theorem.\r\n\r\n\r\n\\subsection{4 definitions of stable}\r\n\\begin{itemize}\r\n    \\item If \\[\\exts C, D \\fall A,B s.t. A X_1+BX_2=_dCX+D\r\n        \\fall X_1,X_2\\] independent copies of $X$, then $X\r\n        \\in S_\\alpha(\\sigma,\\beta,\\mu)$. Furthermore $\\exts\r\n        \\alpha \\in (0,2] s.t. C$ satisfies\r\n        $C^\\alpha=A^\\alpha+B^\\alpha$, for any stable RV and\r\n        $\\fall A,B$\r\n    \\item Stable RV's satisfy a general CLT. If \\[\\fall n\r\n        \\geq 2 \\exts C_n>0 D_n \\in \\dblr s.s. X_i+X_@\r\n        \\hdots X_n=_D C_n X+D_n\\] where ${X_i}$ iid, then\r\n        $X \\in S_\\alpha(\\sigma,\\beta,\\mu)$\r\n    \\item If $\\exts \\; iid \\; RV \\;{Y_i}$ and \\[{d_n},\r\n        {a_n} \\in BBCREVISIT^n \\dblr^n s.t\r\n        \\frac{\\sum\\limits_{1}^{n} Y_i}{d_n}+a_n=_d X\\] then\r\n        $X \\in S_\\alpha(\\sigma,\\beta,\\mu)$.\r\n    \\item If $\\exts \\alpha \\in (0,2], \\; \\sigma \\geq0 \\;\r\n        \\beta \\in [-1,1], \\; \\mu \\in \\dblr$ such that\r\n    \\[ E[e^{i \\theta X}]=\\int_\\Omega e^{i \\theta X} dX = exp\\bigr(\r\n    -\\sigma^\\alpha |\\theta|^\\alpha (1-i \\beta \\;sgn(\\theta)\\; tan\r\n    \\bigl(\\frac{\\pi \\alpha}{2} \\bigr) + i \\mu \\theta)\\bigl) \\] when $\\alpha \\neq 1$\r\n    and when $\\alpha =1$ we have \\[E[e^{i \\theta X}]=exp (\r\n    -\\sigma |\\theta|(1+i \\frac{2}{\\pi} \\beta \\; sgn(\\theta)\r\n    \\; ln|\\theta| + i \\mu \\theta) )\\]\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\subsection{Variance Gamma Process}\r\n$X_{VG}(t;\\sigma,\\nu,\\theta)\\theta  \\gamma(t;\\nu)+\\sigma\r\nW_{Y(t;\\nu)}$ where $\\gamma(t;\\nu)$is a $\\Gamma$ process.\r\n\\[P_{\\gamma(t;\\nu)}(x)=\\frac{  x^{\\frac{t}{\\nu-1}} e^-\\frac{x}{\\nu}\r\n} {\\nu^{t/ \\nu} \\Gamma( t/ \\nu)}\\]  \\[\\Phi_{VG}(\\omega)=E(e^{i\r\n\\omega X_{VG}}) = \\frac{1}{(1-i \\omega \\nu \\theta + \\sigma^2\r\n\\nu \\mu^2 / 2)^{t / \\nu}}\\]  We can show that the Variance\r\nGamma process is the difference of two independent Gamma\r\nprocesses $ X_{VG}=\\gamma_p - \\gamma_n$ to obtain a new pdf\r\n\\[P_{\\gamma(t;\\nu)} =\\biggl\\{\\begin{array}{cc} \\frac{1}{\\nu |x|} e^{-|x| / \\eta_p} \\;\\;\\;  x<0 \\\\\r\n\\frac{1}{\\nu |x|} e^{-|x| / \\eta_n} \\;\\;\\;  x>0\r\n\\end{array} \\].\r\n%\r\n%\\section*{Martingales}\r\n%Martingales are sequences of random variables $\\{X_i\\}$where\r\n%the conditional expectation of $X_i$ given all the previous\r\n%values is $X_{i-1}$.  \\[ E( X_i | X_{i-1} \\ldots X_0) = X_{i-1}\r\n%\\]  An ergodic stochastic process $X_t$is one where the sample\r\n%moments $m_r = \\frac{1}{N} \\sum\\limits_{i=1}^{N}(x_i- m)^r$\r\n%converge to the population moments $E[X_t^r] = \\int X_t^r dP$\r\n\r\n\\section*{Maximum Entropy}\r\nEntropy in the context of information theory is expressed in units of bits, the amount of uncertainty in a yes or no question. Formally, for a sequence $ \\{X_i\\} \\ni p_i  $ is a priori/posteriori probability of observing $X_i$ we define $H=- \\sum\\limits_{i} p_i log_2( p_i) $.  We can define the entropy of a probability distribution by $H=\\int\\limits_{\\-infty}^{\\infty} p(x) log( p(x) ) dx $.  We see the uniform distribution maximizes the entropy; if $p_i=\\alpha \\fall i$ then $\\frac{\\partial H}{\\partial } = log p +1/p=0 $\r\n\r\n\\section*{Gaussian Processes}\r\n$X_t$ is a Gaussian process (GP) if $\\forall (t_1,...t_n)$ we have that $(X_{t_1}, ... ,X_{t_n}) \\approx N(\\mu, \\Sigma)$. $\\Sigma \\sim K(x,x')$ the covariance functions.  Gaussian processes are defined by second order statistics (BBCREVISIT). $K(x,x')$ specifies a distribution on functions (in the distribution sense of functional analysis). Every covariance function is a scalar product of vectors.  Orenstein-Uhlenbeck (OU) and Brownian Motion (BM) are Gaussian processes. If a GP depends on $|x-x'|$ it is stationary.  The OU process is a stationary GP and BM is not. The covariance function of the OU process is not differentiable.  If a Gaussian process depends only on $|x-x'|$ it's called isotropic, these form an important class of\r\nHere we list the common covariance functions (kernels) constant, linear, Gaussian noise, square exponential, and OU.\r\n\\begin{center}\\begin{eqnarray*}\r\nK_c(x,x')= const \\\\\r\nK_\\script{l}(x,x') = <x,x'> \\\\\r\nK_{GN}(x,x') = \\sigma^2 \\delta_{x,x'} \\\\\r\nK_{SE}(x,x') = e^{ \\frac{-|d|^2}{2 \\script{l}} }\\\\\r\nK_{OU}(x,x') = e^{ \\frac{-|d|}{\\script{l}} }\r\n\\end{eqnarray*}\\end{center}\r\nHere $\\script{l}$ is the length scale and $d = |x-x'|$ \r\n\r\n\\section*{Discretizing Continuous Variables}\r\n\r\nR discretization library implements Fayyad and Irani\r\n\r\nPython https://github.com/navicto/Discretization-MDLPC\r\n\r\nMost methods used for discretizing a continuous variable use its relationship\r\nto another variable to determine the partitions. This is often found in\r\nclassification procedures, such as decision trees6 ] 10 and in naive Bayesian\r\nclassifiers.11,12\r\nAn entropy based method, proposed by Fayyad and Irani,6 chooses the\r\npartitioning point s in a sorted set of continuous values to minimize the joint Ž .\r\nentropy Ž Ž .. H X, Y of the continuous variable and the classification variable.\r\nThis is applied to the creation of decision tree structures for classification by\r\n66 CLARKE AND BARTON\r\nrecursively finding more partitioning points top-down discretization . The Ž .\r\nmethod is expanded to minimize a MDL metric to choose the partitioning\r\npoints.\r\nAnother MDL based method for discretization is described by Pfahringer.7\r\nA set of the best partitioning points is determined by recursively partitioning the\r\nŽ D sorted variable values to a depth D 2 y 1 partitions in a binary tree. Then .\r\nthe MDL metric is used in a best first search in this set to determine the best\r\npartitions for decision tree classification.\r\nA method that merges adjacent partitions of sorted variable values, according\r\nto the x2 statistical test, is described by Liu and Setiono.8 The variable\r\nvalues are sorted and initially partitioned into, at most, N intervals. The\r\nintervals are first recursively merged according to the lowest x2 value until a\r\nsignificance level of 0.05 is reached for each partition. The intervals are further\r\nmerged until a preset error rate with the classification variable is reached. If\r\nthere is only one resulting interval, the variable is not relevant to the classification\r\nproblem and is dropped. This method combines the discretization of\r\ncontinuous variables with feature selection for classification.\r\nDougherty, Kohavi, and Sahami9 compared several discretization techniques\r\nwith decision trees and with naive Bayesian classifiers. They found that a\r\nMDL metric, similar to that used by Fayyad and Irani,6 provided slightly better\r\nclassifications in both methods.\r\nA metric for discretization, based upon a variable’s classification in relation\r\nto other variables, is described by Hong.10 This metric is based upon a K\r\nnearest neighbor clustering technique and is used to generate decision trees. An\r\ninteresting feature of this method is that it returns an optimal number of\r\npartitions according to the metric. This is done by finding the ‘‘knee’’ of the\r\nplotted curve of the score as a function of the number of partitions. The plot is a\r\nconcave function of the metric; the knee is the point on the plot where the\r\nchanges in the number of variable values Ž . X axis become greater than\r\nthe changes in the metric value Ž . Y axis . The concavity of a plot is exploited in\r\nthe information theoretic discretization methods developed in Section IV.\r\nSubramonian, Venkata, and Chen,13 describe a visual framework for interactive\r\ndiscretization for decision tree classification. A user can choose between\r\nseveral algorithms and metrics for a classification problem, instead of being\r\nlimited to one method and metric. The choice of metrics includes cross-entropy\r\nand the L y 1 norm between two distributions.\r\nPazzani11 describes a technique for iterative discretization of continuous\r\nvariables for naive Bayesian classifiers. Each continuous variable is initially\r\ndivided into five partitions. For each variable, two partitions are then merged or\r\na partition is divided into two partitions to find a lower classification error. This\r\nprocedure is repeated for each continuous variable until the error rate can no\r\nlonger be reduced.\r\nAnother method for constructing naive Bayesian classifiers using a MDL\r\nmetric is presented by Friedman and Goldszmidt.12 This method begins by\r\nfinding the best initial partition of a continuous variable by dividing the range\r\nBAYESIAN BELIEF NETWORKS 67\r\ninto two partitions and then iterating the partitioning until there is no further\r\nimprovement in the MDL score top-down partitioning . The MDL metric Ž .\r\nincludes all of the variables used for classification and is repeated for each\r\ncontinuous variable. Given a BBN structure, this method discretizes each\r\ncontinuous variable in the Markov blanket of each classification variable. This\r\nprocedure is iterated until there is no improvement in each local MDL score.\r\nFriedman and Goldszmidt propose that this method can be adopted to\r\nlearning BBN structure by starting with some initial discretization of each\r\ncontinuous variable, learning an initial structure, and then rediscretizing as\r\ndescribed above. While this technique optimizes the conditional probabilities, it\r\ndepends upon the initial approximate discretization of continuous variables to\r\nlearn the correct network structure.\r\nExtensions to current discretization techniques for classification methods\r\nhave been proposed for BBNs, but none have currently been published. Methods\r\nfor both static done in data preprocessing and dynamic done during BBN Ž .Ž\r\nconstruction discretization of continuous variables are presented in Sections IV .\r\nand V.\r\nOften, a continuous variable has a normal, or Gaussian, frequency distribution.\r\nThe characteristics of the normal distribution are well understood and a\r\nunified heuristic method for finding a BBN structure with both discrete variables\r\nand continuous variables with a Gaussian distribution is described by Heckerman\r\nand Geiger.14 This method requires the mean and variance of each\r\ncontinuous variable’s values to parameterize the distribution", "meta": {"hexsha": "e9664a7d1b3b71115c25e14122e5e5022841f3ca", "size": 30372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix_Probability.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": "Appendix_Probability.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": "Appendix_Probability.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": 60.622754491, "max_line_length": 1746, "alphanum_fraction": 0.6757210589, "num_tokens": 9861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583169, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6482856721744172}}
{"text": "\\documentclass[10pt,a4paper,final]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[fixlanguage]{babelbib}\n\\usepackage[english]{babel}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}\n\\usepackage[round,sort,nonamebreak]{natbib} % citação \n\n\\usepackage[usenames,svgnames,dvipsnames]{xcolor}\n\\usepackage[pdftex]{graphicx}           % usamos arquivos pdf/png como figuras\n\\usepackage{float}%To make tables and figures stay where we want\n\\graphicspath{{./figures/}}\n\n\n\n\\title{Numerical Inverse Laplace Transform Integration on Ellipses}\n\\author{Pedro S. Peixoto}\n\n\\begin{document}\n\\maketitle\n\n\\section{Numerical Inverse Laplace Transform Integration on a Circle}\n\n\nInverse Laplace Transform (via Bromwich integral),\n\\begin{equation}\n{ \\mathfrak{ L } }^{ -1 }\\left\\{ \\widehat { f }  \\right\\} =\\frac { 1 }{ 2\\pi i } \\int _{ \\gamma -i\\infty  }^{ \\gamma +i\\infty  }{ { e }^{ st }\\widehat { f } \\left( s \\right) ds } .\n\\end{equation}\nFrom the Residual Theorem we can replace it with \n\\begin{equation}\n{ \\mathfrak{ L } }^{ -1 }\\left\\{ \\widehat { f }  \\right\\}=\\frac{1}{2\\pi i}\\int _{ { C }^{  } }{ { e }^{ st }\\widehat { f } \\left( s \\right) ds },\n\\end{equation}\nas long as all the poles of $\\widehat{f}$ lay inside a closed contour ($C$). Following \\citet{cclancy11} and \\citet{clancy:PhD} one can choose a circle centered at the origin and of radius $\\gamma$.\n\\begin{figure}[!h]\n  \\centering\n  \\hspace{1cm}\n  \\includegraphics[width=.5\\textwidth]{Cstar} \n  \\caption[Closed contour $C $]{Closed contour $C$}\n  \\label{fig:Cstar} \n\\end{figure}\n\nThe integral over the contour $C $ can be solved using the parametrized circle $s(\\theta)=\\gamma e^{i\\theta}$, $\\theta \\in [0,2\\pi]$.\n\\begin{equation}\n{ \\mathfrak{ L } }^{ -1 }\\left\\{ \\widehat { f }  \\right\\}=\\frac{1}{2\\pi i}\\int _{ { C }^{  } }{ { e }^{ st }\\widehat { f } \\left( s \\right) ds }=\\frac{1}{2\\pi i}\\int _{0}^{2\\pi}{ { e }^{ s(\\theta)t }\\widehat { f } \\left( s(\\theta) \\right)s'(\\theta) ds },\n\\end{equation}\nwhere $s'(\\theta)=is(\\theta)$. This integral can be approximated via numerical quadrature, using Trapezoidal Rule, on the $N$  points $\\theta_n=2\\pi n/N$, that results in \n\\begin{equation}\n{ \\mathfrak{ L } }^{ * }_C\\left\\{ \\widehat { f }  \\right\\}=\\frac { 1 }{ Ni} \\sum _{ n=1 }^{ N }{ { e }^{ { s }_{ n }t }\\widehat { f } \\left( { s }_{ n } \\right) { s }'_{ n } }\n\\end{equation}\nwhere,\n\\begin{equation}\ns_{n}=\\gamma e^{{i\\theta_n}}, \\quad s'_{n}=\\gamma i e^{{i\\theta_n}}=is_n.\n\\end{equation}\n\n\\section{Numerical Inverse Laplace Transform Integration on an Ellipse}\n\nNow we wish to use an ellipse $E $ instead of a circle $C $ as closed contour. This ellipse will be chosen to satisfy the following properties:\\\\\n(i) On the imaginary axis, it will be bounded by the interval $[-\\gamma, \\gamma]$, for $\\gamma >0$.\\\\\n(ii) On the real axis it will be bounded by the interval $[-\\delta, \\delta]$, where $\\delta < 1$.\n\nThe first requirement ensures we can solve hyperbolic with purely imaginary eigenvalues up to the frequency defined by $\\gamma$. The second requirement ensures that having larger timestep sizes in the numerical time integration will not lead to evaluations of complex functions with large real parts, avoiding floating point instabilities.\n\n\\subsection{Parameterized ellipse}\n\nTo attend the above requirements, the ellipse may be defined via specialized Joukowsky transforms. Let $\\theta \\in [0,2\\pi]$ and $z=re^{i\\theta}$ define a circle of radius $r$ on the complex plane. An ellipse, following the above requirements, maybe built as function of $\\theta$ with the Joukowsky transform\n\\begin{equation}\nw(\\theta)=\\frac{\\gamma i}{d}\\left(re^{i\\theta}+\\frac{e^{-i\\theta}}{r}\\right),\n\\end{equation}\nwhere $d>0$ is yet to be determined. The $i\\gamma/d$ term in the Joukowsky is responsible for a few things: $i$ shifts rotates the ellipse, so that its larger axis is placed in the imaginary axis; $\\gamma/d$ is a normalization to allow that request (i) is satisfied. \n\nThe first condition (i) imposes that\n\\begin{equation}\n|\\text{Im}(w(\\theta))|= \\frac{\\gamma }{d}\\left(r+\\frac{1}{r}\\right)|\\cos(\\theta)| \\leq \\gamma, \\quad \\forall \\theta \\in [0, 2\\pi].\n\\end{equation}\nIn the Joukowsky transform, when $r=1$, the ellipse degenerates to a line segment, in this case the interval $[-2\\gamma i/d, 2\\gamma i/d]$. Choosing \n\\begin{equation}\nd=\\left(r+\\frac{1}{r}\\right),\n\\end{equation}\nis enough to fulfill condition (i).\n\nTo fulfill condition (ii), $r$ needs to be chosen such that \n\\begin{equation}\n|\\text{Re}(w(\\theta))|=\\frac{\\gamma}{d}|(r^{-1}-r)\\sin(\\theta)|\\leq\\delta <1 , \\quad \\forall \\theta \\in [0, 2\\pi].\n\\end{equation}\nA condition for this to happen, already using that $d=r^{-1}+r$, is that\n\\begin{equation}\n\\frac{|r^{-1}-r|}{r^{-1}+r}<\\delta /\\gamma\n\\end{equation}\nwhich, for $r>0$, is illustrated in the figure below.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.7]{rlimits1}\n\\caption{$\\frac{|r^{-1}-r|}{r^{-1}+r}$}\n\\end{figure}\n\nTherefore, condition (ii) is satisfied if \n\\begin{equation}\n\\sqrt{\\frac{1-\\delta/\\gamma}{1+\\delta/\\gamma}} <r<\\sqrt{\\frac{1+\\delta/\\gamma}{1-\\delta/\\gamma}}. \n\\end{equation}\n\nTo avoid degenerate ellipses, we need $r\\neq 1$. The symmetry around $r=1$ of the Joukowsky transform allows us to freely chose either $r>1$ or $r<1$. Here, we choose\n\\begin{equation}\nr=\\sqrt{\\frac{1-\\delta/\\gamma}{1+\\delta/\\gamma}},\n\\end{equation}\nwhich is adequate to ensure the imposed conditions.\n\n\nWith $\\gamma=2$, $\\delta=1$ (in practice $\\delta$ should be strictly smaller than $1$, but this is just an illustration) the ellipse generated would look like the figure bellow. \n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{ellipse.png}\n\\label{fig:ellip2_1}\n\\end{figure}\n\n\n\n\n\\subsection{Inverse Laplace Transform}\nLets now go back to the Inverse Laplace Transform, but now with the contour defined via the ellipse contour. \n\nUsing the properties of contour integration, the Inverse Laplace transform on the ellipse maybe written as\n\\begin{equation}\\label{MILT_ellipse}\n{ \\mathfrak{ L } }^{ -1 }\\left\\{ \\widehat { f }  \\right\\}=\\frac{1}{2\\pi i}\\int _{ { E }^{  } }{ { e }^{ st }\\widehat { f } \\left( s \\right) ds }=\\frac{-1}{2\\pi i}\\int_{0}^{2\\pi} e^{s(\\theta)t}\\widehat { f } \\left( s(\\theta) \\right) s'(\\theta)\\,d\\theta,\n\\end{equation}\nwhere \n\\begin{equation}\ns(\\theta)=\\frac{\\gamma i}{d}\\left(re^{i\\theta}+\\frac{e^{-i\\theta}}{r}\\right),\n\\end{equation}\nand\n\\begin{equation}\ns'(\\theta)=-\\frac{\\gamma}{d}\\left(re^{i\\theta}-\\frac{e^{-i\\theta}}{r}\\right),\n\\end{equation}\nand the minus sign in the integration ensures the contour is swept in a counter-clockwise way.\n\nUniformly partitioning the $[0,2\\pi]$ interval on $N$ points with $\\theta_n=2\\pi n/N$, we may define the complex quadrature points as\n\\begin{equation}\ns_n=\\frac{\\gamma i}{d}\\left(re^{i\\theta_n}+\\frac{e^{-i\\theta_n}}{r}\\right), \\quad n=1,2,..,N,\n\\end{equation}\nand respectively the metric terms as\n\\begin{equation}\ns'_n=-\\frac{\\gamma}{d}\\left(re^{i\\theta_n}-\\frac{e^{-i\\theta_n}}{r}\\right),  \\quad n=1,2,..,N.\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.4]{ellipse-quadpoints64}\n\\caption{64 quadrature points on an ellipse with $\\gamma=2$ and $\\delta=1$.}\n\\end{figure}\n\nThe quadrature points are not uniformly (equidistantly) distributed on the ellipse contour. However, the $\\theta_n$ points are equidistantly distributed on the $[0,\\pi]$ interval, ensuring exponential convergence of the Trapezoidal Rule, for instance, of the following estimate for the inverse Laplace transform\n\n\\begin{equation}\\label{milt_ellipse}\n{ \\mathfrak{ L } }^{ * }_E\\left\\{ \\widehat { f }  \\right\\}=-\\frac { 1 }{  N i} \\sum _{ n=1 }^{ N }{ { e }^{ { s }_{ n }t }\\widehat { f } \\left( { s }_{ n } \\right) { s }'_{ n } }\n\\end{equation}\n\n\\section{Constant reconstruction}\n\nLet $\\widehat{f}(s)=1/s$, such that $f(t)=1$. Then the following equalities should hold (approximately):\n\n\\begin{equation}\n{ \\mathfrak{ L } }^{ * }_C\\left\\{ 1/s \\right\\}=\\frac { 1 }{ Ni} \\sum _{ n=1 }^{ N }{ { e }^{ { s }_{ n }t }{ s }'_{ n } /s_n} \\approx 1,\n\\end{equation}\n\n\\begin{equation}\\label{milt_ellipse}\n{ \\mathfrak{ L } }^{ * }_E\\left\\{ 1/s  \\right\\}=-\\frac { 1 }{  Ni} \\sum _{ n=1 }^{ N }{ { e }^{ { s }_{ n }t }{ s }'_{ n }/s_n }\\approx 1.\n\\end{equation}\nwhere $s_n$ and $s'_n$ are defined differently on the circle and ellipse, as defined in the previous sections.\n\nThis reconstruction should be independent on $t$ (which will be our $dt$ in the ODE integration scheme).\n\nWe have set the a circle with radius $10$ and an ellipse with $\\gamma=10$ and $\\delta=0.5$, as the figure bellow.\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.5]{ellip_circ}\n\\label{fig:quad_elip_circ}\n\\caption{Quadrature points for circle ($\\gamma=10$) and ellipse ($\\gamma=10$, $\\delta=0.5$) with $N=32$}\n\\end{figure}\n\n\nThe results bellow indicate how the circle provides an accurate reconstruction for small $dt$, but how it breaks down due to floating point errors when large $dt$ are used. The ellipse has larger errors, but allows larger $dt$.\n\n\\begin{figure}\n\\centering\n\n\\includegraphics[scale=0.5]{const_recon}\n\\label{fig:const}\n\\caption{Absolute error in the numerical inversion of the function $\\widehat{f}=1/s$, which should result in $f(t)=1$ for any $t$ ($dt$). }\n\\end{figure}\n\n\n\\clearpage \n\\section{Exponential truncation}\n\n\n\\citet{cclancy11} and \\citet{clancy:PhD} use a truncated Taylor series in the calculation of the exponential term,\n\\begin{equation}\n{e }^{ { s }_{ n }t }=\\sum_{j=0}^{N}\\frac{(s_nt)^j}{j!},\n\\end{equation}\nwith $N$ matching the number of quadrature points. For the contour integration  on a circle, \\citet{clancy:PhD} showed that the truncated series, with $N$ even, leads to exact reconstructions of polynomials, that is, \n\\begin{equation}\n\\mathfrak{ L }^{ * }_C\\left(\\frac{1}{s^{k+1}}\\right)=\\frac{t^k}{k!}, \\quad 0\\leq k \\leq N.\n\\end{equation}\n\nWe explored numerically the effects of having the truncated exponential and the results are shown in  Figures \\ref{fig:const_truncN} and \\ref{fig:const_trunc16}, that show the errors when the exponential series is truncated with $N$ and $16$ terms respectively. The exponential series is highly sensitive to numerical floating point precision, therefore, for large $dt$, it creates numerical instabilities in both the Circle and Ellipse contours. Reducing the number of terms in the exponential series expansion (to 16) alleviates the problem of numerical stability on the circle, but deteriorates the results for the ellipse.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.5]{const_recon_truncN}\n\\label{fig:const_truncN}\n\\caption{Absolute error in the numerical inversion of the function $\\widehat{f}=1/s$ using truncated exponential with $N$ terms, which should result in $f(t)=1$ for any $t$ ($dt$). }\n\\end{figure}\n\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.5]{const_recon_trunc16}\n\\label{fig:const_trunc16}\n\\caption{Absolute error in the numerical inversion of the function $\\widehat{f}=1/s$ using truncated exponential with 16 terms, which should result in $f(t)=1$ for any $t$ ($dt$). }\n\\end{figure}\n\n\\clearpage\n\\section{Purely imaginary poles}\n\nLet $f(t)=e^{i\\alpha t}$, $\\alpha \\in \\mathbb{R}$,  so that $\\widehat{f}(s)=\\frac{1}{s-i\\alpha}$. We now apply the numerical inverse Laplace transform (NILT), on both circle and ellipse, with $\\alpha$ values approaching the limit of the contour ($\\gamma=10$). See results bellow. The same contours were used as before, with an ellipse with $\\delta=0.5$ (see Fig \\ref{fig:quad_elip_circ}).\n\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.7]{nilt_expix_error}\n\\label{fig:const_trunc16}\n\\caption{Absolute error in the numerical inversion of the function $\\widehat{f}(s)=1/(s-i\\alpha)$, which should result in $f(t)=e^{i\\alpha t}$ for varying $t$ ($dt$) and number of quadrature points. }\n\\end{figure}\n\n\\section{Relation to REXI }\n\nThe discussion above relies on the knowledge of the Laplace transform of the function one desires to invert. However, an analogous construction maybe done directly from the Cauchy Integration theorem:\n\\begin{equation}\nf(x)=\\frac{1}{2\\pi i}\\ointop_{C}\\frac{f(z)}{z-x}dz,\n\\end{equation}\nfor $f$ holomorphic on $\\mathbb{C}$, and the contour curve $C$ assumed to be closed and should be integrated in a counter-clockwise way, as before.\n\nWe can again chose $C$ to be the ellipse contour\n\\begin{equation}\ns_n=\\frac{\\gamma i}{d}\\left(re^{i\\theta_n}+\\frac{e^{-i\\theta_n}}{r}\\right), \\quad n=1,2,..,N,\n\\end{equation}\nand respectively the metric terms as\n\\begin{equation}\ns'_n=-\\frac{\\gamma}{d}\\left(re^{i\\theta_n}-\\frac{e^{-i\\theta_n}}{r}\\right),  \\quad n=1,2,..,N,\n\\end{equation}\nwhere $\\theta_n=2\\pi n/N$.\n\nTherefore, the function $f$ can be approximated via,\n\\begin{equation}\nf(x)=\\frac{-1}{2\\pi i} \\int_{0}^{2\\pi}\\frac{f(s(\\theta))}{s-x} s'(\\theta) d\\theta \\approx \n\\frac{-1}{2\\pi i} \\sum_{n=1}^{N}\\frac{f(s_n)}{s_n-x} s'_ n \\frac{2\\pi}{ N},\n\\end{equation}\nSimplifying,\n\\begin{equation}\nf(x)\\approx \n\\frac{1}{ iN} \\sum_{n=1}^{N}\\frac{f(s_n)}{x-s_n} s'_ n =\\frac{1}{N}\\sum_{n=1}^{N}\\frac{\\beta_n}{x+\\alpha_n},\n\\end{equation}\nwhere\n\\begin{equation}\n\\beta_n=-if(s_n)s'_ n\n\\end{equation}\nand \n\\begin{equation}\n\\alpha_n=-s_n\n\\end{equation}\nand also,\n\\begin{equation}\nr=\\sqrt{\\frac{1-\\delta/\\gamma}{1+\\delta/\\gamma}},\n\\end{equation}\n\\begin{equation}\nd=r^{-1}+r,\n\\end{equation}\nand $\\gamma$ is the largest attainable imaginary value and $\\delta$ is the largest attainable real value of the ellipse, as discussed before.\n\n\\clearpage\n\n\\bibliographystyle{unsrtnat}\n%\\selectbiblanguage{english}\n\n\\bibliography{bibliography} \n\n\\end{document}\n", "meta": {"hexsha": "85495b9b12b28f7120aa159b6256a68e5c78360b", "size": 13639, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/rexi/rexi_with_laplace/Laplace-ellipse.tex", "max_stars_repo_name": "valentinaschueller/sweet", "max_stars_repo_head_hexsha": "27e99c7a110c99deeadee70688c186d82b39ac90", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-11-20T08:12:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-11T15:32:36.000Z", "max_issues_repo_path": "doc/rexi/rexi_with_laplace/Laplace-ellipse.tex", "max_issues_repo_name": "valentinaschueller/sweet", "max_issues_repo_head_hexsha": "27e99c7a110c99deeadee70688c186d82b39ac90", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-02-02T21:46:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-11T11:10:27.000Z", "max_forks_repo_path": "doc/rexi/rexi_with_laplace/Laplace-ellipse.tex", "max_forks_repo_name": "valentinaschueller/sweet", "max_forks_repo_head_hexsha": "27e99c7a110c99deeadee70688c186d82b39ac90", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-03-01T18:33:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T22:20:31.000Z", "avg_line_length": 47.0310344828, "max_line_length": 626, "alphanum_fraction": 0.6988048977, "num_tokens": 4490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.6482856662925942}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\author{Daniel Frederico Lins Leite}\n\\title{Fibonnaci}\n\\newcommand{\\qed}{\\hfill\\blacksquare}\n\\begin{document}\n\t\\maketitle\t\n\\begin{align*}\n\tF_n >= 2^{n/2} &&\\text{for $n >= 6$}\n\\end{align*}\n\\paragraph{Base}\n\\paragraph{TODO. CALCULATE 6 AND 7 MANUALLY}\n\\paragraph{Induction Step}\n\\begin{align*}\n\tF_n &>= 2^{n/2}\\\\\n\tF_n &= F_{n-1}+F_{n-2}\\\\\n\t&>= 2^{(n-1)/2} + 2^{(n-2)/2}\\\\\n\t& &= (X+2^{(n-2)/2}) + 2^{(n-2)/2} &&\\text{$X>0$}\\\\\n\t& &= 2*2^{(n-2)/2}\\\\\n\t&>= 2*2^{(n-2)/2}\\\\\n\t& &=2^{\\frac{n-2}{2}+1}\\\\\n\t& &=2^{\\frac{n-2}{2}+\\frac{2}{2}}\\\\\n\t& &=2^{\\frac{n}{2}}\\\\\n\t&>= 2^{n/2}\\\\\n\t\\qed\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "eff9b2c17b4970cee2e31abfc999798767b0da45", "size": 756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/math/Handout.Fibonnaci.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.Fibonnaci.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.Fibonnaci.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.3870967742, "max_line_length": 52, "alphanum_fraction": 0.5793650794, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6482655459135469}}
{"text": "\\chapter{\\textsc{Abstract Data Types}}\n\\section{Elements and tuples}\nIn Computer Science, \\emph{datum} (data in plural) is a reference with a representation (syntax)  which is stored in a memory. Datum $a$ may be considered (semantically) as an element or object in some universe of discourse, i.e., universal set $U$, we write $a \\in U$. When $A \\subseteq U$ and $a \\in U$, then $a$ carries some \\emph{information} determined by $A$. The set $A$ is understood as a \\emph{concept}.\n\n\\begin{example}\nConsider a datum $a$ which semantically is an element in a set of digital cars (which is a universal set). One might say that $a$ is an \\emph{instance of an object class ``digital car''}. However, the digital car $a$ might be considered as an object whose properties are stored in computer memory in very many memory blocks. Naturally, each memory block should be referred somehow (by variables!) and in this sense there are datum semantically forming this digital car $a$.\n\\end{example}\n\n\\begin{example}\nAn element 5 may be interpreted in many different ways: $5 \\in r$ or $5 \\in \\mathbb{N}$.\n\\end{example}\n\n\\begin{example}\nWhen data is processed, it is usually obligatory to know in which universal set each datum belongs. For example, the term (expression) $5+4$ is not reasonable if $4,5 \\in \\mathbf{S}$ ($\\mathbf{S}$ is the set of arabic digits) and ``$+$'' is an operator on natural numbers. The operator ``$+$'' and $4,5$ are not compatible.\n\\end{example}\n\nSometimes a datum may be a \\emph{tuple}. A tuple (or n-tuple) is an element of a product set, thus, $\\left(a_1, \\dots ,a_n \\right) \\in U_1 \\times\\cdots\\times U_n$.\n\n\\begin{example}\nIf $V$ is a set of color names, and $M$ is a set of men's names, then $a=\\left(75,\\text{gray},\\text{Jari} \\right) \\in \\mathbb{N} \\times V \\times W$. One might say that tuple is a multidimensional datum.\n\\end{example}\n\n\\section{Memory and variables}\nIn program languages, data is stored in computer memory and data is processed using symbols called \\emph{variables}. From a programmer point of view, a variable is a container, label, or frame. A variable (only a symbol) refers to a datum.\\par \nProgram language compiler should transmit variable (symbol) to the operation system which then reserves on or more memory blocks to this symbol. Variable then refers to contents in computer memory block(s) having certain address(s), in which a datum is stored.\\par \nThe use of variables in some context then serves as \\emph{access} to corresponding data. As we have seen, datum is always of some type in the sense that the applicable processing methods variate.\n\n\\begin{example}\nWe have two variables $x$ and $y$, which refers to computer memory and there are datum. Remember that in computer memory blocks ONLY BITS ARE STORED. How the compiler of the current language ``knows'' that a program clause $z:=x+y$ (or cannot) be processed in a reasonable (in the sense of current program) way?\n\\end{example}\n\nIn program languages, the variables must be \\emph{typed}. There are weakly and strongly typed program languages. \\note Operators demand data types and they know themselves the type.\n\n\\section{Variables and data types}\nThe first clauses in a program are often declaring of variables and their types, like \\verb|x::integer| or \\verb|y::float|. After that, variable assignment can be processed; in this presentation, values of variables (variable assignment) are given by \\verb|:=| symbol, for example \\verb|x:=0|.\\par \nA \\emph{data type s} is a symbolic name, which has a set $A$ with operations $O$ on that set as its semantics. The operations usually satisfy some laws, so, semantics of $s$ is some specified algebra $\\mathcal{A}=\\left(A,O \\right)$. A variable $x$ of type $s$, written \\verb|x::s|, will be assigned to an element $a \\in A$ interpreted as \\emph{a point in the algebra $\\mathcal{A}$}, so we write \\verb|x:=| $x$.\n\n\\begin{example}\nclauses \\verb|y::float| and \\verb|y:=5| together stores 5 in some specified memory block, but 5 is understood now as a real number. So, the bits in this memory block are handled as a floating point number.\n\\end{example}\n\n\\begin{example}\nThe clauses \\verb|z::char| and \\verb|z:='c'| together could store the ASCII-code of the letter c.\n\\end{example}\n\n\\begin{example}\nIf an operation $\\omega$ takes values of data types $s_1, \\ldots ,s_n$ and produces values of data type $t$ then this is often written as $\\omega : s_1 \\times\\ldots\\times s_2 rightarrow t$. In this case, data types may have a many-sorted algebra as their semantics.\n\\end{example}\n\n\\note Some program languages (e.g. Python/Sage) process data as OBJECTS (object-oriented languages). Then, variables are often allowed to have \\emph{aliases} by default.\n\n\\begin{example}\nIn a clause \\verb|x:=5| the symbol \\verb|x| refers to a memory block containing object 5 (must be created); this object has a ``nametag'' \\verb|x|, i.e. this object is allowed to be referred by other variables also without copying the datum. This referencing method differs from symbol \\verb|x| being a ``label of box'' which contains 5.\n\\end{example}\n\n%\\section{Advantages of typing}\n%Programmers can focus on program language syntax and create the program syntactically using variables of reasonable data types and their operations. Unnecessary restrictions will be removed.\\par \n%Program languages have primitive data types (built-in data types) which define a kind of user interface to memory blocks. Which restrictions the hardware determines?\\par When data types are used effectively then \\emph{type erros} are avoided. For example,  leet \\verb|x::interger| and \\verb|y,z::char|. Then the clause \\verb|z:=x+y| is reasonable if the operation ``+'' is of the form $+ \\, : \\text{integer} \\times \\text{char} \\rightarrow \\text{char}$.\n\n\\section{Data structures}\n\\subsection{What is data structure?}\nUsually programs handle a large collection of different kinds of data from data type point of view. Some data may form an entity of its own, a datum, which may be called as \\emph{data aggregate}. Data aggregate is referred by one variable.\\par \nThe data itself is naturally stored in different memory blocks, but it is now reasonable to assume that there must be some relation between elements, because the data aggregate is a datum itself.\\par \n\\emph{Data structure} is a way of organizing data such that data aggregate may be stored in and accessed from the memory efficiently and in a reasonable way from application point of view. The structure may be expressed as a relation between elements.\n\\subsection{Tuple} \nOne of the simplest data structure is \\emph{tuple}. Tuples are elements of a product set and in this sense it is a data aggregate. The elements in the tuple are not changeable (tuples are immutable) and the relation between elements is the identity relation.\\par \n\\note In a tuple each element may be of different data types. It might be possible to declare $x:: s_1, \\dots ,s_n$ if $x$ would create a new type from the existing ones (type constructor).\n\\subsection{Array}\n\\emph{Array} is a data structure, where the elements have position numbers. The size of an array is fixed, but elements are changeable (arrays are mutable). There are no other specific methods to manipulate arrays.\\par \nIn a more detail, an array $f$ with the size of $n$ position is a function, such that $f(i)$ is an element at the position number $i$, thus, $f:\\lbrace 0,1,\\ldots ,n-1 rbrace rightarrow S$, when the stored elements are members in $S$.\\par \nThe structure is now given as a function producing a linear order between the elements. Quite often arrays are declared like \\verb|x::array[0..n]| of \\verb|s|, where \\verb|s| is some data type. For example, \\verb|x:=[3,4,5]| would assign a 3-placed array to \\verb|x| declared by \\verb|x::array[0..2]| of \\verb|s|, where \\verb|s| represents integer data type.\\par \nFor \\emph{many-dimensional arrays}, one uses many different indices to position the elements. Notice that some modern program language do not demand array declarations, but the form of writing declares the array themselves.\\par \nIf the array is declared, however, to be the size of $n$ positions then the operating system reserves $n$ memory blocks from the memory, even if the program would not need them all.\n\n\\section{Abstract data type}\nPrimitive data types, like integer or float, are sets with operations such that they are defined by hardware, operating system or compilers. These kinds of data types are called ``built-in'' such that the corresponding algebras are implemented in hardware, operating system, or compiler.\\par \nAn \\emph{abstract data type} $s$ is a symbolic name, which has a collection of \\emph{mathematically isomorphic algebras} as its semantics, i.e. the operations defined for these algebras behave in a similar manner and the underlying sets are bijective.\n\n\\begin{example}\nAn abstract data type \\emph{bool} has a collection of all 2-element Boolean algebras (mathematically isomorphic algebras) as its semantics. For example, \\emph{bookl} might have algebras like $B_1=\\lbrace 0,1 rbrace$ and $B_2=\\lbrace \\text{True},\\text{False} rbrace$ with the operations on these sets behaving in the same way (like connectives in Propositional Logic).\n\\end{example}\n\n\\begin{example}\nConsider a program language with an abstract data type \\emph{bool}. The  collection of all 2-element Boolean algebras is isomorphic to $\\mathcal{B}=\\left( B_2,\\ast , +, ',F,T \\right)$ as its semantics. In this program language, the syntactic operations for bool-type are $\\ast , +, ',F,T$ where $F$ is the zero element and $T$ is the unit element. We have:\n\\begin{verbatim}\nx,y,z::bool\nz = x * y\nWHILE z == T\n...\nENDWHILE\n\\end{verbatim}\nThese program clauses are independent from the actual implementation: it does not matter which 2-element Boolean algebra there is implemented.\n\\end{example}", "meta": {"hexsha": "07c1b3336c520f7bdff0e8f4353af7d3db977c0e", "size": 9833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DataType.tex", "max_stars_repo_name": "buiquanghuy23103/Math", "max_stars_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DataType.tex", "max_issues_repo_name": "buiquanghuy23103/Math", "max_issues_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DataType.tex", "max_forks_repo_name": "buiquanghuy23103/Math", "max_forks_repo_head_hexsha": "230b6363ed938bb9913836f28915ebe3feecf1c5", "max_forks_repo_licenses": ["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.7311827957, "max_line_length": 473, "alphanum_fraction": 0.7589748805, "num_tokens": 2489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6482655359405126}}
{"text": "%---------------------------Warpage-----------------------------\n\\section{Warpage}\n\nWarpage is defined as\n\\[\nq =\n  1 - \\min \\left\\{\n    \\left( \\hat n_0 \\cdot \\hat n_2  \\right)^3,\n    \\left( \\hat n_1 \\cdot \\hat n_3  \\right)^3\n  \\right\\}\n\\]\nwhich is the cosine of the minimum dihedral angle formed by\nplanes intersecting in diagonals (to the fourth power).\n\nNote that if $\\normvec{N_k} < DBL\\_MIN$ for any $k$, we set $q = DBL\\_MAX$.\n\n\\quadmetrictable{warpage}%\n{$1$}%                                      Dimension\n{$[0,0.7]$}%                                Acceptable range\n{$[0,2]$}%                                  Normal range\n{$[0,DBL\\_MAX]$}%                           Full range\n{$0$}%                                      Unit square\n{--}%                                       Citation\n{v\\_quad\\_warpage}%                         Verdict function name\n\n\n", "meta": {"hexsha": "6663d6d60d82a439bc570ab4ef09355a9fd237ba", "size": 864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadWarpage.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/QuadWarpage.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/QuadWarpage.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.0, "max_line_length": 75, "alphanum_fraction": 0.4375, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625126757596, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6482590784053295}}
{"text": "% Chapter 2\n\n\\chapter{Convolutional Neural Networks} % Main chapter title\n\n\\label{Chapter2}\n\n%-------------------------------------------------------------------------------\n%-------------------------------------------------------------------------------\n\n\\section{CNNs: Layer by Layer}\n\nConvolutional neural networks have been very successful in computer vision as their key ingredient convolution filters preserve 2D structure and are able to pull features from images. Back propogation and stochastic gradient descent are used to optimize these filters in order to produce. Here I will cover some of the most common layers used in CNNs.\n\n\\subsection{Convolution Layer}\n\nThe first and foremost layer is the convolution layer. A convolution layer contains a set of filters which are \\textit{convolved} across feature maps in order to get the feature map. Let's take a concrete look at what this means. Imagine we are working with images that are of the shape 28x28x3 pixels. We then decide we want to use a convolution filter of size 2x2x5 which will result in a 28x28x5 feature map. Each kernel in this filter will be of size 2x2x3 since the depth in our original image is 3 and there will be five kernels. We then take the dot product of each slice in our 2x2x3 matrix against the original image at pixel 0x0 giving us 3 scalar values which are summed to get the first value in the first feature map of the output. We then slide these filters across the entire feature map in x and y thereby creating a new feature map.  See ~\\ref{fig:Convolution} for an example of convolving two 3x3x3 kernels on a 7x7 image.  A few things to consider when sliding the feature maps are image padding. For pixel 0,0 in our example part of the filter would be off the image. To keep the convolution consistent people will often times pad the edges of the image with 0 or 0.5. Additionally a stride length can be set which determines how far we move the filter at each step. A stride length of 2 would skip every other pixel when sliding.\n\n\\begin{figure}[ht]\n\\includegraphics[width=0.9\\textwidth]{Figures/Convolution.png}\n\\caption{An example of performing a 3x3 convolution with a depth of two on an 7x7x3 image with 1 pixel of padding from Andrej Karpathy's Stanford CNN Course \\cite{StanfordConv}}\n\\label{fig:Convolution}\n\\end{figure}\n\n\\subsection{Activation Layer}\n\nIts common after each of the convolutional layers to apply a non-linear activation function. A few examples of activation include: \\\\\n\n\\[ \\sigma(x) = \\frac{1}{1+e^{-x}} \\]\n\\[ \\tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}} \\]\n\n\\[ ReLu(x) = \\begin{cases}\n      0 & x < 0 \\\\\n      x & x \\geq 0\n   \\end{cases}\n\\]\n\nReLu or rectified linear unit has been a popular choice for cnns as it is computation efficient without sacrificing accuracy.\n\n\\subsection{Pooling Layer}\n\nPooling layers are used to downsample feature maps from layer to layer. Two common flavors of pooling layers are max pooling and average pooling. Max pooling simply looks at a window and returns only the maximum value. Average pooling as it names suggests averages all the values in the window and returns that value. Lets take for example a 2x2 max pooling layer with an feature map of size of 128x128x32. After applying the pooling layer we would have 64x64x32 as an output. A common intuition behind max pooling is that it provides spatial invariance, i.e. if an object shifts by a few pixels we will still have a high response. An alternative to max pooling is using strided convolutions. The argument for this is that a good amount of information is lost in pooling layers.\n\n\\subsection{Fully Connected Layer}\n\nFully connected layers are what we traditional think of as the multi-layer perceptron model. They are commonly used in the final layer of CNNs to distill feature maps from a multi-dimensional matrix into a vector that can be then used for classification or regression. As a simple example are classification networks that will use two fully connected layers where the output is a vector of the same length as number of classes they want to predict from. SoftMax is applied to the vector to normalize the sum of the vector to one and then each scalar in the vector is interpreted as a likelihood of that image being of that particular class.\n\n\\subsection{Transfer Learning}\n\nTransfer learning is the process of taking a neural network trained for a certain task and refining it for another. A common example of this is retraining a classification network to predict a different set of classes than what it was originally trained for or changed from a classifier to a regression network. The common intuition for this is that the early layers in the network have learned basic features like, curves, corners, or other simple patterns that are universal in all types of objects. The top layers which carry the strong semantic information are closer to the end and therefore receive more gradient during back propagation. Some methods even freeze the weights for lower levels as fixed feature extractors and only allow the the final layers to change during training. As a bonus, transfer learning reduces the total time to train a network as the lower levels of a network take longer to train that the deeper layers.\n\nWhen exploring new architectures it is common procedure to simply download a set of weights for a popular network backbone and just apply transfer learning from there. In these next sections I will cover some of the popular network backbones.\n\n\\subsection{VGG16}\n\nVGG16 was one of the first major networks after AlexNet which went for simplicity and depth \\cite{VGG16}. The first contribution was its simplicity. CNNs before VGG used very large filter sizes, for example AlexNet used 11x11, which led to large parameter sizes. The authors of VGG16 instead used series of two back to back convolution/ReLu layers with 3x3 filters before doing max pooling. VGG16 at the time was considered a very deep network with 13 convolution layers and 3 fully connected layers. It showed that very deep networks were extremely important in learning the hierarchical features necessary for good classification. VGG16 scored $7.3\\%$ error rate on ImageNet dataset.\n\n\\subsection{ResNet}\n\nIn 2015 Microsoft Research came out with \\textit{Deep Residual Learning for Image Recognition} \\cite{ResNet} which had 152 layers and new type of of block called the residual block. It scored $3.6\\%$ on the ImageNet challenge in 2015. A residual block is a normal feed forward neural network that adds in \\textit{shortcut} connections where the input to a layer is both fed through a layer but also routed around the layer and added to the output of the next layer. See ~\\ref{fig:ResBlock} for a visual description. They hypothesized that a residual mapping induced by this block would be easier to learn than the original feed-forward network. ResNets come in several popular forms now such as ResNet18, ResNet32, ResNet50, ResNet101, and ResNet152, where the choice of depth is based on computational resources and dataset. Most popular deep learning frameworks have pretrained ResNet models available for download.\n\nAnother intuition behind ResNets success is that the \\textit{shortcut} connections allow gradients to move more easily through the network which helps alleviate a problem known as the vanishing gradient. Vanishing gradients is the problem where the loss at the end of the network has very little impact on changing the weights on the earlier layers and was one of the main reasons preventing networks from going as deep as ResNet. In the next network the use of skip connection is taken even further.\n\n\\begin{figure}[ht]\n\\includegraphics[width=0.9\\textwidth]{Figures/ResBlock.png}\n\\caption{Diagram of Residual Block from \\cite{ResNet}}\n\\label{fig:ResBlock}\n\\end{figure}\n\n\\subsection{DenseNet}\n\nIn 2016 Densely Connected Convolutional Networks (DenseNets) were proposed and shown to match and beat the residual network architecture on many datasets while using much fewer parameters and therefore computation. With DenseNets the authors connect all feature maps of same size together through concatenation so that the lth layer will have (l-1) feature maps. This is different then the ResNet model which uses summation in its shortcut connections. In order to concatenate feature maps across max pooling layers DenseNet introduce transition layers. These transition layers pass the prior feature maps through batch normalization, convolution, and finally average pooling before concatenating them to layers further down.\n\n\\begin{figure}[ht]\n\\includegraphics[width=0.9\\textwidth]{Figures/DenseNet.png}\n\\caption{Diagram of Residual Block from \\cite{DenseNet}}\n\\label{fig:DenseNet}\n\\end{figure}\n\n%-------------------------------------------------------------------------------\n%-------------------------------------------------------------------------------\n\\section{Object Detection Networks}\n\nObject detection networks deal with the problem of first localizing an object with an image frame as well as classifying that object and is generally considered a harder problem then pure classification tasks. The two popular datasets for benchmarking results are \\textit{Common Objects in Context} (COCO) \\cite{COCO} and \\textit{The PASCAL Visual Object Classes} (PASCAL VOC) \\cite{VOC}. At the time this work began the two most popular object detection networks were Faster-RCNN and YOLOv2 which I will cover in depth in the next two sections. Since then the state of the art has progressed considerably. Future work might include exploring this architectures.\n\n\\subsection{Faster-RCNN}\n\nFaster-RCNN \\cite{FASTER-RCNN}, where the R stands for region, is one of the most popular object detection networks at the moment and is an advancement on the authors previous two networks RCNN and Fast RCNN. The authors show results for both VGG16 and ZF network backbones, but many open source implementations of Faster-RCNN have replaced these backbones with various ResNet and DenseNets backbones.\n\nThe main contribution of Faster-RCNN is the Region Proposal Network (RPN) which replaces Fast-RCNNs slower, more complicated region proposal mechanism. It works by sliding a window across the final convolution feature map in a network and simultaneously predicting class probability and objectness. Objectness in this context is the probability that there is an object present in the bounding box. The RPN is implemented as a single NxN conv layer that maps into a lower dimension followed by two 1x1 conv layers for class probability and objectness. Furthermore they make use anchor boxes or priors on bounding boxes to make the task of the box regressor easier. At each position in the sliding window there are 9 anchor boxes which the regressor predicts bounding boxes with respect to.\n\nThe training scheme for this network is a multi-step process which involves training the RPN and Fast-RCNN networks separately and then later fixing the conv layers of Fast-RCNN and just fine-tuning the RPN.\n\n\\subsubsection{Loss}\nThe loss for Faster-RCNN is split into two parts as shown below.\n\n\\begin{align}\n    \\Loss = \\Loss_{cls} +\\Loss_{reg}\n\\end{align}\n\nGiven $p_i$ is the predicted confidence that the ith anchor box is an object and $p_i^*$ is a binary indicator that the anchor box has an IoU greater than 0.7 with a ground truth we can define the loss as:\n\n\\begin{align}\n    \\Loss_{cls}(p_i,p_i^*) = \\frac{1}{N_{cls}} \\sum_{i=1}^{A} [p_i\\log(p_i) + (p_i^*-p_i)\\log(1-p_i)]\n\\end{align}\n\nWe then parameterize the anchor box and bounding box truth as the following where $_a$ indicates a parameter from the anchor box and $*$ from the ground truth.\n\n\\begin{align}\n    t_x = \\frac{(x - x_a)}{w_a} \\\\\n    t_y = \\frac{(y - y_a)}{h_a} \\\\\n    t_w = \\log(\\frac{w}{w_a}) \\\\\n    t_h = \\log(\\frac{h}{h_a}) \\\\\n    t_x^* = \\frac{(x^* - x_a)}{w_a} \\\\\n    t_y^* = \\frac{(y^* - y_a)}{h_a} \\\\\n    t_w^* = \\log(\\frac{w^*}{w_a}) \\\\\n    t_h^* = \\log(\\frac{h^*}{h_a}) \\\\\n\\end{align}\n\nNext we define the regression loss where again we use $p_i^*$ as an indicator whether this anchor box has an IoU above 0.7 with the ground truth.\n\n\\begin{multline}\n    \\Loss_{reg}(p_i^*, t, t^*) = p_i^*(Smooth_{L1}(t_x-t_x^*) + Smooth_{L1}(t_y-t_y*) \\\\ + Smooth_{L1}(t_w-t_w*) + SL1(t_h-t_h*)) \\\\\n\\end{multline}\n\n\\begin{align}\n    Smooth_{L1}(d) = \\begin{cases}\n      0.5d^2 & if |d| \\leq 0 \\\\\n      |d| - 0.5 & otherwise\n   \\end{cases}\n\\end{align}\n\n\\subsection{YOLOv2}\n\nYOLOv2, You Only Look Once, is another successful object detector released in 2016 \\cite{YOLOv2}. It's key contribution is a unified network that simultaneously predicts object class and location with out the use of a secondary Region Proposal Network. While maintaining comparable accuracy to Faster-RCNN it runs at a much higher frame rate.\n\nThe backbone is of the authors design that uses only 3x3 and 1x1 convolutions, max pooling layers, and batch normalization. The network contains 23 convolution layers, 5 max pooling layers, and one short cut layer that concatenates features from lower levels to the final layer. Since the model contains no fully connected layers the network input size is unconstrained. The 5 max pooling layers of stride 2 mean that the final feature map will have a width and height that is the original width and height divided by $2^5$. As such the the original network input is usually selected to be a multiple of 32 i.e. 320, 416, 608, etc... An example of the network architecture is shown in table~\\ref{table:YOLOV2}\n\n\\begin{center}\n\\begin{table}[h]\\footnotesize\n    \\caption{YOLOv2 Network Architecture layer by layer for an input resolution of 608 x 608}\\label{table:YOLOV2}\n    \\begin{tabular}{| l | l | l | l | l |}\n    \\hline\n    layer  & filters & size & input & output \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n    0 conv & 32 & 3 x 3 / 1 & 608 x 608 x 3 & 608 x 608 x 32 \\\\ \\hline\n\n    \\rowcolor{Salmon}\n    1 max  & N/A & 2 x 2 / 2 & 608 x 608 x  32   &  304 x 304 x  32 \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n    2 conv &       64  & 3 x 3 / 1   & 304 x 304 x  32   & 304 x 304 x  64 \\\\ \\hline\n\n    \\rowcolor{Salmon}\n    3 max &     N/A     & 2 x 2 / 2   & 304 x 304 x  64   &   152 x 152 x  64 \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n    4 conv &    128  & 3 x 3 / 1   & 152 x 152 x  64   &   152 x 152 x 128 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n    5 conv &     64  & 1 x 1 / 1   & 152 x 152 x 128   &   152 x 152 x  64 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n    6 conv &    128  & 3 x 3 / 1   & 152 x 152 x  64   &   152 x 152 x 128 \\\\ \\hline\n\n    \\rowcolor{Salmon}\n    7 max &     N/A     & 2 x 2 / 2   & 152 x 152 x 128   &    76 x  76 x 128 \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n    8 conv &    256  & 3 x 3 / 1   &  76 x  76 x 128   &    76 x  76 x 256 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n    9 conv &    128  & 1 x 1 / 1   &  76 x  76 x 256   &    76 x  76 x 128 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   10 conv &    256  & 3 x 3 / 1   &  76 x  76 x 128   &    76 x  76 x 256 \\\\ \\hline\n\n    \\rowcolor{Salmon}\n   11 max &     N/A     & 2 x 2 / 2   &  76 x  76 x 256   &    38 x  38 x 256 \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n   12 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   13 conv &    256  & 1 x 1 / 1   &  38 x  38 x 512   &    38 x  38 x 256 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   14 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   15 conv &    256  & 1 x 1 / 1   &  38 x  38 x 512   &    38 x  38 x 256 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   16 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\\\ \\hline\n\n   \\rowcolor{Salmon}\n   17 max &     N/A     & 2 x 2 / 2   &  38 x  38 x 512   &    19 x  19 x 512 \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n   18 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   19 conv &    512  & 1 x 1 / 1   &  19 x  19 x1024   &    19 x  19 x 512 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   20 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   21 conv &    512  & 1 x 1 / 1   &  19 x  19 x1024   &    19 x  19 x 512 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   22 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   23 conv &   1024  & 3 x 3 / 1   &  19 x  19 x1024   &    19 x  19 x1024 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   24 conv &   1024  & 3 x 3 / 1   &  19 x  19 x1024   &    19 x  19 x1024 \\\\ \\hline \\hline\n\n   \\rowcolor{LightGreen}\n   25 route  & 16 & N/A & N/A & N/A \\\\ \\hline\n\n   \\rowcolor{Tan}\n   26 reorg & N/A &            / 2      & 38 x  38 x 512    &    19 x  19 x2048 \\\\ \\hline\n\n   \\rowcolor{LightGreen}\n   27 route & 26 & 24 & N/A & N/A \\\\ \\hline \\hline\n\n    \\rowcolor{LightCyan}\n   28 conv &   1024  & 3 x 3 / 1   & 19 x  19 x3072    &    19 x  19 x1024 \\\\ \\hline\n\n    \\rowcolor{LightCyan}\n   29 conv &     35  & 1 x 1 / 1   & 19 x  19 x1024    &    19 x  19 x  35 \\\\ \\hline\n\n    \\hline\n    \\end{tabular}\n\\end{table}\n\\end{center}\n\nYOLOv2 takes a simple approach to bounding box regression and class prediction. To understand how it works lets view the final feature map as a grid. At each location in this grid we want to predict bounding boxes and give a confidence metric for how likely there is to be an object there. We want to predict 5 numbers at each location in the grid plus a confidence for each class as show below:\n\n\\begin{align}\\label{eq:bbox_regressed}\n    t_x,t_y,t_w,t_h,t_o,P(C_1),...,P(C_N)\n\\end{align}\n\nThe parameters $t_x,t_y,t_w,t_h$ are regressed with relation to the feature map x,y location which we call $f_x$ and $f_y$. Further $t_x,t_y$ are constrained to be between [0,1] by the logistic function. We also define $p_w,p_h$ as the prior width and height for the anchor boxes.\n\n\n\\begin{align}\n    b_x &= \\sigma(t_x) + f_x \\\\\n    b_y &= \\sigma(t_y) + f_y \\\\\n    b_w &= p_w * exp(t_w) \\\\\n    b_h &= p_h * exp(t_h)\n\\end{align}\n\nLike Faster-RCNN the author uses anchor boxes as priors for predicting bounding boxes at each locations. The author determined that 5 prior anchor boxes was a good trade-off between accuracy and efficiency. For each prior bounding box we need to predict the parameters shown in equation~\\ref{eq:bbox_regressed}.\n\nLets take a concrete look at this with an example. Say that our input resolution is 416 x 416, we have 3 classes, and are using 5 prior anchor boxes. Dividing our input resolution by 32 we obtain our final feature map width and height equal to 13. Now at each location in this 13 x 13 map we need to regress 3 classes and 5 bounding box parameters for 5 anchor boxes.\n\n\\begin{align}\n    (5 * (5 + 3)) * 13^2) = 6760\n\\end{align}\n\nInstead of using a several fully connected layer to regress these numbers the author simply uses a 1x1 conv in the prior layer and sets the number of filters equal to the number of anchors multiplied by the 5 parameters plus the number of classes. In table~\\ref{table:YOLOV2} there are 5 anchors and 2 classes meaning there are 35 filters going into the final feature map. Which can be seen on layer 29.\n\nThis setup allows the user to have the freedom to change the input resolution on the fly without having to modify the final layer. The only information we need a prior is the number of classes.\n\n\\subsubsection{Loss}\n\nThe loss function for YOLOv2 consists of 4 separate parts\n\n\\begin{align}\n    \\Loss_{YOLOv2} = \\Loss_{coord} + \\Loss_{obj} + \\Loss_{noobj} + \\Loss_{class} \\\\\n\\end{align}\n\nThe first part $\\Loss_{coord}$ deals with bounding box regression.\n\n\\begin{multline}\n    \\Loss_{coord} = \\lambda_{cood} \\sum_{i=1}^{f_x*f_y} \\sum_{j=i}^{Anchors}\n    \\indicator_{obj}^{i,j} [\n        (\\sigma(t_x^{(i,j)}) - \\sigma(\\hat{t}_x^{(i,j)}))^2 +\n        (\\sigma(t_y^{(i,j)}) - \\sigma(\\hat{t}_y^{(i,j)}))^2 + \\\\\n        (\\sigma(t_w^{(i,j)}) - \\sigma(\\hat{t}_w^{(i,j)}))^2 +\n        (\\sigma(t_h^{(i,j)}) - \\sigma(\\hat{t}_h^{(i,j)}))^2] \\\\\n\\end{multline}\n\nThe next part deal with the loss associated with predicting the objectness of the bounding box. Ideally we would like the objectness to predict the IoU of the predicted bounding box with the true bounding box. This is a little unintuitive as during inference we do not have access to the truth. The $\\Loss_{noobj}$ is there to punish false positives.\n\n\\begin{align}\n    \\Loss_{obj} = \\lambda_{obj} \\sum_{i=1}^{f_x*f_y} \\sum_{j=i}^{Anchors} \\indicator_{obj}^{i,j} (IoU_{truth}^{pred} - \\sigma(\\hat{t}_o^{(i,j)}))^2 \\\\\n    \\Loss_{noobj} = \\lambda_{noobj} \\sum_{i=1}^{f_x*f_y} \\sum_{j=i}^{Anchors} \\indicator_{noobj}^{i,j} (-\\sigma(\\hat{t}_o^{(i,j)}))^2 \\\\\n\\end{align}\n\nThe final piece weights the error associated with predicting the class of the bounding box. It's simply the sum of squared error of the true class probability distribution (which is 1 at the true class and 0 everywhere else) and the predicted class probability. This is different that much formulations which is the cross entropy loss function like Faster-RCNN.\n\n\\begin{align}\n    \\Loss_{class} = \\lambda_{class}\\sum_{i=1}^{f_x*f_y} \\sum_{j=i}^{Anchors} \\sum_{c=1}^{N} \\indicator_{obj}^{i,j} (\\indicator_{c=true class}-P(c)^{(i,j)})^2\n\\end{align}\n\nAs an aside the naive loss function with regard to class probability has serious issues with regards to class imbalance. Our work demonstrates YOLOv2s inability to work well over in these situations as well be explained further in the results section.\n\n\\subsection{Selecting a Network}\n\nPreliminary results using both networks showed results heavily in favor of YOLOv2. The largest reason being the input size to YOLOv2 could easily be scaled up and had pretrained models for higher resolution networks. This could potentially have been replicated on with Faster-RCNN; however, it would have taken extensive architecture changes and weeks training networks from scratch.\n\nAdditionally the Darknet framework that YOLOv2 runs on was more approachable for the author allowing for easy modifications where necessary.\n", "meta": {"hexsha": "e79d197e65af8256f433993bb373b5fd9f1fac48", "size": 22055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Chapter2.tex", "max_stars_repo_name": "matte1/Thesis", "max_stars_repo_head_hexsha": "c693558a9a6ee840f2b260efb2a6b67870e889d1", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "matte1/Thesis", "max_issues_repo_head_hexsha": "c693558a9a6ee840f2b260efb2a6b67870e889d1", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "matte1/Thesis", "max_forks_repo_head_hexsha": "c693558a9a6ee840f2b260efb2a6b67870e889d1", "max_forks_repo_licenses": ["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.8403908795, "max_line_length": 1350, "alphanum_fraction": 0.7144411698, "num_tokens": 6234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603725, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6482403255698911}}
{"text": "\\section{Supplementary material}\n\n\\paragraph{Simplicial distance and the localizing property of the Laplacian.}\nSuppose that $\\sigma$ and $\\tau$ are $p$-simplices for which $(\\nu_0, \\nu_1, \\dotsc, \\nu_d)$ is the shortest sequence of $p$-simplices with the property that $\\nu_0=\\sigma$, $\\nu_d=\\tau$, and each $\\nu_i$ shares a face or a coface with $\\nu_{i-1}$, and a face or a coface with $\\nu_{i+1}$. We say that $d$ is the \\emph{simplicial distance} between $\\sigma$ and $\\tau$. Then for all $N<d$, the entry of $L_p^N$ corresponding to $\\sigma$ and $\\tau$ is $0$, and so the filter does not cause interaction between $c(\\sigma)$ and $c(\\tau)$. This is analogous to a size-$d$ ordinary CNN layer not distributing information between pixels that are more than $d$ pixels apart. We will refer to $N$ as the \\emph{degree} of the convolutional layer, but one may well wish to keep in mind the notion of \\emph{size} from traditional CNNs.\n\n\\paragraph{Simplicial complexes as the projections of bipartite graphs.}\nGiven a bipartite graph $X$-$Y$, the simplicial projection on $Y$ is the simplicial complex whose $(k-1)$-simplices are the sets of $k$ vertices in $Y$ that have at least one common neighbor in $X$.\nCochains on the simplicial projection are naturally given by weights on $X$: Given any $(k-1)$-simplex $[y_1,\\dots,y_k]$ and its neighboring vertices $\\{x_1,\\dots,x_j\\}\\subseteq X$, one can define a $(k-1)$-cochain as $\\phi(\\{x_1,\\dots,x_j\\})$, for any function $\\phi: \\mathcal{P}(X)\\to\\RR$.\nIn our coauthorship application, $\\phi$ is the sum and the weight of a paper is the number of times it is cited.\nSee Figure~\\ref{fig:bipartite}.\n\n\\begin{figure}[htpb]\n%\\begin{table*}[!t]\n\\savebox{\\tempbox}{\n\n  \\begin{tikzpicture}[font=\\scriptsize]\n    \\coordinate (I) at (0,0);\n    \\coordinate (II) at (0,-0.5);\n    \\coordinate (III) at (0,-1);\n    \\coordinate (IV) at (0,-1.5);\n\n    \\coordinate (A) at ($ (I) + (2,0) $);\n    \\coordinate (B) at ($ (II) + (2,0) $);\n    \\coordinate (C) at ($ (III) + (2,0) $);\n    \\coordinate (D) at ($ (IV) + (2,0) $);\n\n    \\fill[color=black] (I) circle (2pt);\n    \\fill[color=black] (II) circle (2pt);\n    \\fill[color=black] (III) circle (2pt);\n    \\fill[color=black] (IV) circle (2pt);\n    \\fill[color=black] (A) circle (2pt);\n    \\fill[color=black] (B) circle (2pt);\n    \\fill[color=black] (C) circle (2pt);\n    \\fill[color=black] (D) circle (2pt);\n\n    \\node[anchor=east] at (I) {Paper \\MakeUppercase{\\romannumeral 1}, $100$ citations};\n    \\node[anchor=east] at (II) {Paper \\MakeUppercase{\\romannumeral 2}, $50$ citations};\n    \\node[anchor=east] at (III) {Paper \\MakeUppercase{\\romannumeral 3}, $10$ citations};\n    \\node[anchor=east] at (IV) {Paper \\MakeUppercase{\\romannumeral 4}, $4$ citations};\n\n    \\node[anchor=west] at (A) {Author $A$};\n    \\node[anchor=west] at (B) {Author $B$};\n    \\node[anchor=west] at (C) {Author $C$};\n    \\node[anchor=west] at (D) {Author $D$};\n\n    \\draw (I) -- (A);\n    \\draw (I) -- (B);\n    \\draw (I) -- (C);\n\n    \\draw (II) -- (A);\n    \\draw (II) -- (B);\n\n    \\draw (III) -- (A);\n    \\draw (III) -- (D);\n\n    \\draw (IV) -- (C);\n    \\draw (IV) -- (D);\n  \\end{tikzpicture}\n  \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\\end{minipage}%\n\\savebox{\\tempbox}{\n\n  \\begin{tikzpicture}[font=\\scriptsize]\n    \\coordinate (A) at (0,0);\n    \\coordinate (B) at (2,0);\n\n    \\coordinate (C) at ($ (A) + (300:1) $);\n    \\node[anchor=north] at (C) {$100$};\n\n    \\coordinate (D) at ($ (B) + (240:1) $);\n    \\node[anchor=north] at (D) {$50$};\n\n    \\draw[dashed] (A) -- (C) -- (B);\n    \\draw[dashed] (A) -- (D) -- (B);\n\n\n    \\coordinate (AA) at ($ (A) + (0, -1.5) $);\n    \\coordinate (BB) at ($ (B) + (0, -1.5) $);\n   \n    \\fill[color=black] (A) circle (2pt);\n    \\fill[color=black] (B) circle (2pt);\n    \\fill[color=black] (AA) circle (2pt);\n    \\fill[color=black] (BB) circle (2pt);\n\n    \\draw (A) -- (B);\n    \\draw (AA) -- node[below, align=center] {$1$-cochain\\\\ $150=100+50$} (BB);\n\n    \\node[anchor=east] at (A) {$A$};\n    \\node[anchor=west] at (B) {$B$};\n    \\node[anchor=east] at (AA) {$A$};\n    \\node[anchor=west] at (BB) {$B$};\n \n  \\end{tikzpicture}\n}%\n\\settowidth{\\tempwidth}{\\usebox{\\tempbox}}%\n\\hfil\\begin{minipage}[b]{\\tempwidth}%\n\\raisebox{-\\height}{\\usebox{\\tempbox}}%\n\\scriptsize{\\captionof*{figure}{(b)}}%\n\\end{minipage}%\n\\vspace{5pt}\n%\\end{table*}\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\\scriptsize{\\captionof*{figure}{(c)}}%\n\\end{minipage}%\n%\\end{table*}\n\\caption{%\n    Constructing a simplicial complex and its cochain from a bipartite graph.\n    (a)~Paper-author bipartite graph (same data as in Figure~\\ref{fig:data2complex}).\n    (b)~The $1$-simplex $[A,B]$ is included in the coauthorship complex since authors $A$ and $B$ collaborated on papers I and II.\n    The 1-cochain on $[A,B]$ is given by the sum of their common papers' citations.\n    (c)~Resulting coauthorship complex with cochains.\n}\\label{fig:bipartite}\n\\end{figure}\n\n\\begin{table}[htbp]\n  \\centering\n  \\scriptsize{\n  \\begin{tabular}{lrrrrrrrrrrr}\n    \\toprule\n    Dimension   & 0     & 1  & 2     & 3 & 4     & 5 & 6    & 7 & 8   & 9 & 10\\\\\n    \\midrule\n    CC1 & 352  & 1474  & 3285  & 5019  & 5559  & 4547  & 2732  & 1175  & 343 & 61 & 5\\\\\n    CC2 & 1126 & 5059 & 11840 & 18822 & 21472 & 17896  & 10847 & 4673 & 1357 & 238 & 19\\\\\n    \\bottomrule\n  \\end{tabular}}\n  \\vspace{2pt}\n  \\caption{%\n  Number of simplices of the two coauthorship complexes sampled from Semantic Scholar.\n  } \\label{table:Simplices-coauthor}\n\\end{table}\n\n\\paragraph{Sampling papers.}\nFrom the Semantic Scholar Open Research Corpus~\\cite{ammar18NAACL}, we excluded papers with fewer than $5$ citations or more than $10$ authors.\nTo sample a CC, we sampled $80$ papers (corresponding to maximal simplices in the CC) by performing a random walk (of length $80$, from a randomly chosen starting paper) on the graph whose vertices represent papers and edges connect papers sharing at least one author.\n\n\\paragraph{Mean accuracy and absolute error.}\nA missing value is considered to be correctly imputed if the imputed value differs by at most $10\\%$ from the true value.\nThe \\emph{accuracy} is the percentage of missing values that has been correctly imputed and the \\emph{absolute error} is the magnitude of the difference between the imputed and true value.\nFor each rate of missing values, we compute the \\emph{mean accuracy} $\\pm$ standard deviation over 5 samples with randomly damaged portions.\n", "meta": {"hexsha": "43bbbe1613fd2acb10df93b8be61fac39fae75ee", "size": 6688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "supplementary.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": "supplementary.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": "supplementary.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": 44.2913907285, "max_line_length": 823, "alphanum_fraction": 0.6454844498, "num_tokens": 2317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.6482403180786542}}
{"text": "\\section{Lens distortion and point discretization}\n\\label{sec:model-lens-distortion}\nIn Section \\ref{subsec:lenses} we have introduced lenses, highlighting their advantages over the pinhole. We also introduced the differences between the thin lens model and the thick lens one, observing how, in both cases, curvature radii could introduce aberrations on the acquired image.\n\nAs we said in Section \\ref{sec:teo-calibration}, all the calibration algorithms try to solve this problem, but most of them, like Tsai and Zhang, are limited to considering radial distortions. In fact it can be shown that tangential contributions are typically negligible, while radial ones increase when focal length decreases. Fortunately, in literature there are some studies about lenses and thin prism distortions, such as \\cite{brown},\\cite{DBLP:journals/corr/cs-CV-0308003} and \\cite{Heikkila}, which offer some solutions to extend the analysis beyond this limit. \\\\\n\nAs a first thing, we focused on \\cite{TsaiTvLenses}. Accordingly with it, the commonly used polynomial for radial distortion model, is given by the series\n  \\begin{equation}\n    \\label{eq:radial-tot}\n    r_d = r + \\delta_r = r + \\sum_{j=1}^\\infty k_jr^{(2j)}\n  \\end{equation}\nwhere $r$ is the lens radius and $k_j$ is the radial coefficient of degree $j$. As we will discuss later, the used calibration algorithm are limited to the second order, so Equation \\ref{eq:radial-tot} can be reduced as:\n  \\begin{equation}\n    \\label{eq:radial-2}\n    r_d = r + k_1r^2 + k_2r^4\n  \\end{equation}\n\nApplying Equation \\ref{eq:radial-2} to distorted points, we found a simple relation, similar to that in \\cite{TsaiTvLenses}:\n  \\begin{equation}\n    \\label{eq:dist-coords}\n    x_{p_i} = x_{p_i}^{d} \\left( 1 + k_1r^2 \\right) \\qquad\n    y_{p_i} = y_{p_i}^{d} \\left( 1 + k_1r^2 \\right)\n  \\end{equation}\nwhere $\\left( x_{p_i}^{d}, y_{p_i}^{d} \\right)$ are the distorted coordinates in the parallel to sensor image plane. In this way, we can determine the projection of a 3D point in a plane parallel to the sensor and distortion free. Note that, given a specific point, it does not make sense to consider the whole radius $r$ of the lens, so it is preferable to consider its distance from the point to the optical center (that ideally is locate in the center of the lens). \\\\\nAs we have done in previous sections, the error is propagated as follows\n  \\begin{equation}\n    \\label{eq:sigma-dist}\n    \\begin{matrix}\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      \\\\~\\\\\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}\nNote that this transformation is the same for both $x$ and $y$, thanks to lens radial distortion symmetry. \\\\\n\nAt this point we have noticed that it is very easy to spread the solution to the tangential distortions. Accordingly with \\cite{Heikkila} we observed that Equations \\ref{eq:radial-2} could be extended easily:\n  \\begin{equation*}\n    \\mathcal{F}\\left( r, \\bar{k}, \\bar{p} \\right) = \n    \\begin{bmatrix}\n      x_{p_i}\\left( \\sum_{j=1}^\\infty k_jr^{2j} \\right) + \\left( 2 p_1 x_{p_i} y_{p_i} + p_2 \\left( r^2 + 2 x_{p_i}^2  \\right) \\right) \\left( 1 + p_3 r^2 + \\ldots  \\right)\n      \\\\\n      y_{p_i}\\left( \\sum_{j=1}^\\infty k_jr^{2j} \\right) + \\left(  p_1 \\left( r^2 + 2 y_{p_i}^2  \\right) + 2 p_2 x_{p_i} y_{p_i} \\right) \\left( 1 + p_3 r^2 + \\ldots \\right)\n    \\end{bmatrix}\n  \\end{equation*}\nAs we can see, to consider tangential distortion some additive factors are needed. The analysis for error propagation is the same as that for the Equation \\ref{eq:sigma-dist}, but we have to pay attention to include the partial derivatives of the tangential coefficients. \\\\\nTo complete the analysis, we have done some test using nominal lens parameters given by the manufacturer, and we observed that the error improvement was negligible. \\\\\n\nIn the last two cases we could ignore the components depending by distortion coefficients, that we can consider correct thanks to calibration processes. \\\\\n\nLooking around, we have found another model that we considered of interest. Accordingly with \\cite{DBLP:journals/corr/cs-CV-0308003}, radial distortions could be formulated as a rational distribution like:\n  \\begin{equation*}\n    \\mathcal{F}\\left( r, \\bar{k}, \\bar{p} \\right) = \\frac{1 + k_1r + k_2r^2}{1 + k_3r + k_4r^2 + k_5r^3}\n  \\end{equation*}\nIt is easy to derive many other formulas from the general one, and the most interesting are shown in Table \\ref{tab:dist-funcs}.\n  \\input{./src/chapters/ch4-Model/tab-functions.tex}\nAll these functions enjoy some properties,. in fact they are:\n  \\begin{itemize}\n    \\item radially symmetric around the center of distortion;\n    \\item expressed in terms of the radius $r$ only;\n    \\item continuous and $r_d = 0$ iff $r = 0$;\n    \\item the approximation of $x_d$ is an odd function of $x$.\n  \\end{itemize}\nThe above three properties act as the criteria to be good candidates as radial distribution functions. Despite that, we can see that Equation \\#4 is very closed to the Equation \\ref{eq:radial-2}. Furthermore, the calibration algorithms we have used are limited to second degree, and in this conditions many of these equations can be traced back to \\#4. At the end, it can be shown that the performances of the remaining functions are comparable with \\#4. \\\\\nFor all these reasons, we focused only on Equations \\ref{eq:dist-coords}, but as we have shown in this section, it is easy to extends it to tangential distortion or to increase its degree.\n\n\\bigskip\nOnce we have determined the distorted point in the image plane, the last step is the point discretization. In this phase we are interested in projecting the undistorted point in the distorted sensor plane. Accordingly with \\cite{TsaiTvLenses}, this projection can be performed by centering the coordinate reference system in the optical center estimated during calibration processes, and by normalizing the point value in the sensor pixel range. At the end we can write:\n  \\begin{equation*}\n    x_{p_i}^d = d_x'(x_{c_i} - c_x) \\qquad \\qquad y_{p_i}^d = d_y'(y_{c_i} - c_y)\n    % \\label{eq:discrete-coords}\n  \\end{equation*} \\\\\nwhere $(c_x, c_y)$ is the optical center, and $(d_x', d_y')$ the normalized pixel center to center distance, along $x$ and $y$ axis, respectively. Consistent with what we have done so far, we can conclude with error propagation:\n  \\begin{equation}\n    \\begin{matrix}\n    %\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  \\\\\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    %\n    \\end{matrix}\n    \\label{eq:model:err:disc}\n  \\end{equation} \\\\\n\n\\bigskip\nBefore concluding this section, we want to emphasize a possible source of ambiguity in understanding this model. The explanation started from the end of the chain and follows until the beginning. This choice was taken to better identify, for each step, the elements to analyse, and from which each relation depends. In this way the error determination was easy. However, we have to notice that we want to determine the error committed evaluating the point in the world, starting from pixel detection in the image, then formulas have to interpret in this sense, from pixel to world.\n", "meta": {"hexsha": "be5a67bdcf6e3f637e29cc080329c0eb6add0aca", "size": 7846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch4-Model/5_distortions.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/5_distortions.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/5_distortions.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": 78.46, "max_line_length": 581, "alphanum_fraction": 0.7201121591, "num_tokens": 2302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6482403135636655}}
{"text": "% !TEX root =main.tex\n\n\\subsection{More Efficient Proof of Storage-Time}\\label{More-Efficient-Proof-of-Storage-Time}\n\nIn the following, we show how C-TLP can be used in the PoSt protocols that were proposed in  \\cite{Storage-Time} to improve their costs. As stated previously,  two protocols: basic PoSt and compact PoSt, supporting proof of storage-time (in the random oracle) are proposed in \\cite{Storage-Time}, where  basic PoSt uses VDF and is publicly verifiable while compact PoSt  utilises a trapdoor delay function (TDF) and is privately verifiable. Also, recall that VDF/TDF is used to allow the server to derive multiple challenges at different points over a certain time period $T$. Note, both types of delay function (VDF and TDF) impose the same computation cost to the server, i.e. $3Tz$ modular exponentiations and $Tz$ modular multiplication if the fastest delay function is used \\cite{Wesolowski19}. \n\nNow we show how to replace the delay function in these schemes with C-TLP, in the random oracle.  As in the PoSt protocols, the client at the setup precomputes random challenges (and their PoR tags). But, it encodes all challenges for $z-1$ PoR proofs (excluding first one)  into puzzles using C-TLP. It sends to the server all puzzles, encoded file and plaintext challenges for the first PoR proof. As before, the server generates the first PoR proof using the challenges sent to it in the plaintext. Nevertheless, to find $j\\text{\\small{-th}}$ challenge to generate  $j\\text{\\small{-th}}$ PoR proof, the server solves the related puzzle, where $j>1$. It sends to the client all PoR proofs (or a combination of them) after period $T$. Also, if the basic PoSt  is used,  the server sends C-TLP proofs that can be efficiently verified by anyone. On the other hand, if the compact PoSt is used, then the server does not need to send the C-TLP's proofs, as the client already knows the random challenges. The adjustments considerably improve the PoSt protocols' costs. In particular,  the server's computation cost would be $\\frac{1}{3}$ of the costs imposed by either of the original PoSt protocols. Also,  there will be $3z$ further reduction in the number of exponentiations:  (a) at the verifier side, in the basic PoSt, as it does not need to perform any exponentiation to check the correctness of C-TLP's output,  (b) at the client-side, in the compact PoSt,  as the client does not need to evaluate TDF at the setup to precompute the challenges which in total involves $3z$ modular exponentiations over $\\phi(N)$. Moreover, the proof size would be reduced by a factor of $6.5$.\n\n\\begin{remark}\nAlthough the use of C-TLP in the PoSt protocols can reduce the computation and communication costs, (a) the server-side I/O cost in these schemes (i.e. $O(\\log n)$ in the basic PoSt and $O(n)$ in the compact one), and (b) PoR's proof size complexity in the basic PoSt, will remain the same. Because these costs stem from the underlying PoR schemes, used as a black box, by the two PoSt protocols.\n\\end{remark}", "meta": {"hexsha": "b0dae4b4d45dcd3b2fb59bc1cda186bb1833e752", "size": 3027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Paper/eprint-version/PoSt-and-C-TLP.tex", "max_stars_repo_name": "AydinAbadi/CR-LP", "max_stars_repo_head_hexsha": "b2139df715f441a48eeae0b88e038fb6acc5d6e2", "max_stars_repo_licenses": ["MIT"], "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/eprint-version/PoSt-and-C-TLP.tex", "max_issues_repo_name": "AydinAbadi/CR-LP", "max_issues_repo_head_hexsha": "b2139df715f441a48eeae0b88e038fb6acc5d6e2", "max_issues_repo_licenses": ["MIT"], "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/eprint-version/PoSt-and-C-TLP.tex", "max_forks_repo_name": "AydinAbadi/CR-LP", "max_forks_repo_head_hexsha": "b2139df715f441a48eeae0b88e038fb6acc5d6e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 275.1818181818, "max_line_length": 1681, "alphanum_fraction": 0.7720515362, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6482403106886496}}
{"text": "\\documentclass[11pt,twoside]{fncextra}\n\n\\pagestyle{myheadings}\n\\markboth{}{Asteroids}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Asteroids (pew pew)\n\\end{center}\n\nIn 1609 Johannes Kepler proposed that celestial bodies in the solar system follow elliptical orbits with the sun at one focus. This so-called First Kepler Law laid the groundwork for sophisticated mathematical description of orbits, and indeed spurred and justified the early development of calculus, as Kepler's geometric laws were worked out into formulas that were used to explain gravitational force.\n\nThere are multiple parameters used to characterize these orbits. If we consider only the motion within the plane of the orbit, these can all be derived from two readily observed ones: $\\tau$, the period of the orbit, and $\\epsilon$, the eccentricity of the ellipse. (Larger values mean greater deviation from circularity, with a circle at $\\epsilon=0$ and a degenerate line at $\\epsilon=1$. )\n\nPerhaps the geometrically easiest parameters to understand are the \\emph{true anomaly} $\\nu$, which is the angle between the body and its \\emph{perihelion}, or its closest approach to the sun; and the distance $r$ from the body to the sun. These parameters are related by the equations \\begin{align}\n  \\tan \\frac{\\nu}{2} &= \\sqrt{\\frac{1+\\epsilon}{1-\\epsilon}}\\,\n    \\tan \\frac{\\psi}{2}, \\label{eq:Asteroids1} \\\\\n  M &= \\psi - \\epsilon \\sin \\psi, \\label{eq:Asteroids2} \\\\\n  r &=  \\frac{a(1-\\epsilon^2)}{1+\\epsilon \\cos \\nu} \\\\\n  a^3 &= \\mu \\left(\\frac{\\tau}{2\\pi}\\right)^2.\n\\end{align}\nHere, $M$ is known as the \\emph{mean anomaly}; it is proportional to time and varies from 0 to $2\\pi$ over one complete orbit traversal. In addition, $\\psi$ is known as the \\emph{eccentric anomaly}, $a$ is half of the (maximum) diameter of the ellipse, and $\\mu$ is a gravitational parameter that for the Sun is $39.47524$ $\\text{AU}^3/\\text{yr}^2$. (An AU is roughly the Earth--Sun distance.)\n\nEquation~\\eqref{eq:Asteroids2} implicitly defines $\\psi$ as a function of $M$ (and therefore time), but it cannot be solved in closed form. Instead, given a value of $M$, rootfinding must be used to find $\\psi$. The rest of the parameters in the equations can be calculated explicitly from $\\psi$.\n\n\n\n\\subsection*{Preparation}\n\nRead Section~4.1.\n\n\\subsection*{Goals}\n\nYou will apply \\texttt{fzero} in MATLAB to compute the eccentric anomaly given the orbital period and eccentricity of an asteroid. From this you can compute other quantities of interest.\n\n\n%\\end{document}\n\n\\subsection*{Procedure}\n\n\\begin{enumerate}\n\\item Let \\texttt{M} be a vector of 800 evenly spaced values from $0$ to $2\\pi$. Set $\\epsilon=0.1$ and solve~\\eqref{eq:Asteroids2} using \\texttt{fzero} to compute a value of $\\psi$ for each entry of $M$. Make a labeled plot of $\\psi(M)$.  \\item Add to the plot of step 1 by stepping through $\\epsilon=0.2,0.3,\\ldots,0.9$, and plotting the resulting $\\psi(M)$ each time.  \\item The asteroid 324 Bamberga is both one of the largest and one of the most eccentric in the asteroid belt. It has $\\epsilon = 0.338$ and $\\tau = 4.40$ yr. Plot $\\nu(M)$ over $0\\le M \\le 2\\pi$ for this asteroid. (You will probably find that $\\nu$ jumps suddenly from $\\pi$ to $-\\pi$. It's not incorrect, but if this offends you, use \\texttt{unwrap(nu)} to get a smooth equivalent in $[0,2\\pi]$.)\n\\item Plot $r(M)$ as a function of $M$ for 324 Bamberga.\n\\item Halley's Comet has $\\epsilon=0.967$ and $\\tau = 75.3$ yr. Plot $r(M)$ for this comet. What are its maximum (aphelion) and minimum (perihelion) values? (You can check these figures against ones you find on the internet.) \n\\end{enumerate}\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "43ccb13044e44e7eeb0ab9c6898a8e62421721b4", "size": 3713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter04/Asteroids/Asteroids.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/Asteroids/Asteroids.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/Asteroids/Asteroids.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": 67.5090909091, "max_line_length": 770, "alphanum_fraction": 0.7282520873, "num_tokens": 1042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6482402941674349}}
{"text": "\\chapter{RESULTS AND DISCUSSIONS}\n\\label{ch:results}\n\n\\section{Background of Study}\n\nSuppose that we have a line with equation $y = 2x + 3$. This line cuts the $y$-axis at $y = 3$. We can find the gradient of the line using \\eqref{eq:gradient}. Equation~\\eqref{eq:tada}, $\\ldots$.\n\n\\begin{equation} \\label{eq:gradient}\n    m = \\frac{y_2 - y_1}{x_2 - x_1}\n\\end{equation}\n\n\\begin{equation} \\label{eq:tada}\ne^{\\pi i} + 1 = 0\n\\end{equation}\n\n\\subsection{Comparison of Method A with Other Studies}\n\n\\begin{table}[ht]\n    \\caption{Length Units}\n    %\\begin{tabular}{cc}\n    \\begin{tabular}{>{\\centering\\arraybackslash}p{.47\\textwidth} >{\\centering\\arraybackslash}p{.47\\textwidth}}\n        \\toprule %header\n        Millimeters & Centimeters\\\\\n        mm          &   cm\\\\\n        \\midrule\n        1           &   0.1\\\\\n        10          &   1\\\\\n        100         &   10\\\\\n        1000        &   100\\\\\n        10000       &   1000\\\\\n        \\bottomrule\n    \\end{tabular}\n    \\par\\raggedright Note: This table is useful for $\\ldots$.\n    \\label{table:lengthunits}\n\\end{table}\n\n\\subsubsection{Method A Improved}\n\nFigure~\\ref{fig:logouitm} is $\\dots$. \\lipsum[1-2]\n\n\\begin{figure}[ht]\n    \\centering\n    \\fbox{ % add box arounf image\n        \\includegraphics[width=.9\\linewidth]{logouitm} % scale=.5 <- 50% of original size\n    }\n    \\caption[Short version for LoF]{Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM}\n    \\label{fig:logouitm}\n\n    \\par\\raggedright\n    Notes/Sources: Phasellus in dui mi. Suspendisse placerat nisl et elit tristique, non congue elit bibendum. Donec mauris libero, vehicula in feugiat vitae.\n\\end{figure}\n\n\\lipsum[2-3]\n\n\n\n", "meta": {"hexsha": "652224811368d1f9b925e7d9c5af36106503cbf0", "size": 1677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mainmatter/chapResults.tex", "max_stars_repo_name": "jafhate/uitmthesis", "max_stars_repo_head_hexsha": "00b977f7a932053898b09f20f798e0f723c439cd", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-03-01T11:39:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-21T09:02:01.000Z", "max_issues_repo_path": "mainmatter/chapResults.tex", "max_issues_repo_name": "jafhate/uitmthesis", "max_issues_repo_head_hexsha": "00b977f7a932053898b09f20f798e0f723c439cd", "max_issues_repo_licenses": ["LPPL-1.3c"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-26T04:24:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-26T04:24:43.000Z", "max_forks_repo_path": "mainmatter/chapResults.tex", "max_forks_repo_name": "jafhate/uitmthesis", "max_forks_repo_head_hexsha": "00b977f7a932053898b09f20f798e0f723c439cd", "max_forks_repo_licenses": ["LPPL-1.3c"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-22T05:47:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T01:37:04.000Z", "avg_line_length": 29.4210526316, "max_line_length": 195, "alphanum_fraction": 0.6326774001, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7401743735019594, "lm_q1q2_score": 0.6482350926635047}}
{"text": "%Abstract\n\n\\chapter*{Abstract}\n\\addcontentsline{toc}{chapter}{Abstract}\n\n%The structures and energies of different types of clusters are studied\n%computationally. For this, a combination of graph theoretical methods,\n%approximate interaction potentials and accurate quantum chemical calculations is\n%used to investigate gold clusters, Lennard-Jones (LJ) clusters and clusters\n%bound by the sticky-hard-sphere (SHS) interaction potential.\n\nThe structures and stabilities of hollow gold clusters are investigated by means\nof density functional theory (DFT) as topological duals of carbon fullerenes.\nFullerenes can be constructed by taking a graphene sheet and wrapping it around\na sphere, which requires the introduction of exactly 12 pentagons. In the dual\ncase, a (111) face-centred cubic (fcc) gold sheet can be deformed in the same\nway, introducing 12 vertices of degree five, to create hollow gold nano-cages.\nThis one-to-one relationship follows trivially from Euler's polyhedral formula\nand there are as many golden dual fullerene isomers as there are carbon\nfullerenes. Photoelectron spectra of the clusters are simulated and\ncompared to experimental results to investigate the possibility of detecting\nother dual fullerene isomers. The stability of the hollow gold cages is compared\nto compact structures and a clear energy convergence towards the (111) fcc sheet\nof gold is observed. \n\nThe relationship between the Lennard-Jones (LJ) and sticky-hard-sphere (SHS)\npotential is investigated by means of geometry optimisations starting from the\nSHS clusters. It is shown that the number of non-isomorphic structures resulting\nfrom this procedure depends strongly on the exponents of the LJ potential. Not\nall LJ minima, that have been discovered in previous work, can be retrieved this\nway and the mapping from the SHS to the LJ structures is therefore non-injective\nand non-surjective. The number of missing structures is small and they\ncorrespond to energetically unfavourable minima on the energy landscape. The\noptimisations are also carried out for an extended Lennard-Jones potential\nderived from coupled-cluster calculations for the xenon dimer, and, although the\nshape of the potential is not too different from a regular (6,12)-LJ potential,\nthe number of minima increases substantially.\n\nGregory-Newton clusters, which are clusters where 12 spheres surround and touch\na central sphere, are obtained from the complete set of SHS clusters. All 737\nstructures result in an icosahedron, when optimised with a (6,12)-LJ potential.\nFurthermore, the contact graphs, consisting only of atoms from the outer shell\nof the clusters, are all edge-induced sub-graphs of the icosahedral graph. For\nhigher LJ exponents the symmetry of the potential energy surface breaks away\nfrom the icosahedral motif towards the SHS landscape, which does not support a\nperfect icosahedron for energetic reasons. This symmetry breaking is mainly\ngoverned by the shape of the potential in the repulsive region, with the\nlong-range attractive region having little influence.\n\n\n\n", "meta": {"hexsha": "70c2297637d460f695d496ceac68be881736721a", "size": 3062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract.tex", "max_stars_repo_name": "Trombach/thesis", "max_stars_repo_head_hexsha": "0eb1d2a109a0f91271fbdd6d85b4706b2e281d93", "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": "abstract.tex", "max_issues_repo_name": "Trombach/thesis", "max_issues_repo_head_hexsha": "0eb1d2a109a0f91271fbdd6d85b4706b2e281d93", "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": "abstract.tex", "max_forks_repo_name": "Trombach/thesis", "max_forks_repo_head_hexsha": "0eb1d2a109a0f91271fbdd6d85b4706b2e281d93", "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.8846153846, "max_line_length": 81, "alphanum_fraction": 0.8200522534, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.648235085024068}}
{"text": "\\subsection{Analytic geometry in the plane}\\label{subsec:analytic_geometry_in_the_plane}\n\n\\begin{remark}\\label{rem:analytic_geometry}\n  Analytic geometry is a XVII-century branch of mathematics that studies geometric figures using coordinate \\hyperref[rem:coordinate_systems]{systems}. The term \\enquote{analytic geometry} may refer to a modern subbranch of algebraic geometry, however we refrain from using \\enquote{analytic geometry} in that sense. Historically, most of these definitions were given either for the Euclidean \\hyperref[def:euclidean_plane]{plane} or for the three-dimensional Euclidean space.\n\n  Most of the definitions from \\fullref{subsec:vector_space_geometry} are generalizations of concepts from analytic geometry. We will state definitions in the language of linear algebra and refrain from using synthetic (axiomatic) geometry. When working in the plane (resp. three-dimensional space), we will assume that we have fixed an \\hyperref[def:orthonormal_system]{orthonormal} coordinate \\hyperref[def:euclidean_plane_coordinate_system]{system} \\( Oxy \\) (resp. \\( Oxyz \\)), which allows us to visualize geometric figures.\n\\end{remark}\n\n\\begin{definition}\\label{def:plane_line_equations}\n  \\hyperref[def:geometric_line]{Lines} in \\( \\BbbR^2 \\) are, so ubiquitous that they can be represented by a lot of standard \\hyperref[ex:equations]{equations}.\n\n  \\begin{thmenum}\n    \\thmitem{def:plane_line_equations/vector_parametric} When regarding a line as a parametric curve as in \\fullref{def:geometric_line/parametric}, the \\hyperref[def:first_order_syntax/formula]{formula}\n    \\begin{equation}\\label{def:plane_line_equations/parametric_equation}\n      l(t) = tx + a\n    \\end{equation}\n    is called a \\term{vector parametric equation}.\n\n    \\thmitem{def:plane_line_equations/scalar_parametric} Given \\fullref{def:plane_line_equations/parametric_equation}, the \\term{scalar parametric equations} of the line are\n    \\begin{equation}\\label{def:plane_line_equations/scalar_parametric_equations}\n      \\begin{cases}\n         & l_1(t) = t x_1 + a_1  \\\\\n         & l_2(t) = t x_2 + a_2.\n      \\end{cases}\n    \\end{equation}\n\n    \\thmitem{def:plane_line_equations/general} When regarding a line as an algebraic curve as in \\fullref{def:geometric_line/algebraic}, the equation\n    \\begin{equation}\\label{def:plane_line_equations/general_equation}\n      p(x, y) \\coloneqq Ax + By + C = 0\n    \\end{equation}\n    is called the \\term{general equation} or simply \\term{equation} of a line in a plane. Either \\( A \\) or \\( B \\) must be nonzero, so that \\( \\deg(p) = 1 \\).\n\n    Note that multiple general equations can have the same locus (e.g. the entire polynomial ideal \\( \\braket{p} \\)).\n\n    \\thmitem{def:plane_line_equations/normal} If \\( A^2 + B^2 = 1 \\), we call \\fullref{def:plane_line_equations/general_equation} a \\term{normal equation}. This leaves us with only two representatives of \\( \\braket{p} \\).\n\n    \\thmitem{def:plane_line_equations/cartesian} Given \\( k, m \\in \\BbbR \\) and  \\( k \\neq 0 \\), we define the \\term{Cartesian equation} of a line:\n    \\begin{equation}\\label{def:plane_line_equations/cartesian_equation}\n      y = kx + m.\n    \\end{equation}\n\n    We call \\( k \\) the \\term{slope} of the line.\n\n    This is a special case of \\fullref{def:plane_line_equations/general} with \\( A = -k \\), \\( B = -1 \\) and \\( C = m \\). Unlike the general equation, the Cartesian equation of a line is unique.\n\n    Conversely, if \\( B \\neq 0 \\) in \\fullref{def:plane_line_equations/general_equation}, we can define \\( k = -\\tfrac A B \\) and \\( m = -\\tfrac C B \\) to form a Cartesian equation.\n\n    \\thmitem{def:plane_line_equations/intercept} Given nonzero \\( a, b \\in \\BbbR \\), we define the \\term{intercept equation} of a line:\n    \\begin{equation}\\label{def:plane_line_equations/intercept_equation}\n      \\frac x a + \\frac y b = 1,\n    \\end{equation}\n\n    This is a special case of \\fullref{def:plane_line_equations/general} with \\( A = \\frac 1 a \\), \\( B = \\frac 1 b \\) and \\( C = -1 \\). The intercept equation of a line is also unique.\n\n    If \\( A, B, C \\neq 0 \\) in \\fullref{def:plane_line_equations/general}, we can define an \\term{intercept equation} as \\( a = -\\tfrac C A \\) and \\( b = -\\tfrac C B \\)).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{figure}\n  \\begin{minipage}[b]{0.40\\textwidth}\n    \\centering\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      input metapost/plotting;\n\n      u := 1.5cm;\n\n      beginfig(1);\n      path l, x_axis, y_axis;\n\n      x_axis = (-1, 0) scaled u -- (1, 0) scaled u;\n      y_axis = (0, -1) scaled u -- (0, 1) scaled u;\n      l = (-1 / 2, -1) * u -- (1, 3 / 4) * u;\n\n      drawarrow x_axis;\n      label.bot(\"$x$\", point 0.9 of x_axis);\n      drawarrow y_axis;\n      label.lft(\"$y$\", point 0.9 of y_axis);\n      draw l;\n      label.bot(\"$y = kx + m$\", startpoint of l);\n      endfig;\n    \\end{mplibcode}\\fi\n    \\caption{A \\hyperref[def:geometric_line]{line} in \\( \\BbbR^2 \\) defined using its \\hyperref[def:plane_line_equations/cartesian]{Cartesian equation}.}\\label{def:plane_line_equations/cartesian_equation_drawing}\n  \\end{minipage}\n  \\hspace{0.05\\textwidth}\n  \\begin{minipage}[b]{0.40\\textwidth}\n    \\centering\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      input metapost/plotting;\n      u := 1.5cm;\n\n      beginfig(1)\n      drawarrow (-1 / 2, 0) scaled u -- (2, 0) scaled u;\n      drawarrow (0, -1 / 2) scaled u -- (0, 2) scaled u;\n\n      z0 = (1 / 2, 1 / 6) scaled u;\n      z1 = (2, 11 / 12) scaled u;\n      z2 = (1, 13 / 6) scaled u;\n\n      draw z0 -- (x0, max(y1, y2)) dashed withdots;\n\n      drawarrow z0 -- z1;\n      draw (x0, y1) -- z1 dashed evenly;\n      label.top(\"$x_1$\", midpoint of ((x0, y1) -- z1));\n\n      drawarrow z0 -- z2;\n      draw (x0, y2) -- z2 dashed evenly;\n      label.bot(\"$x_2$\", midpoint of ((x0, y2) -- z2));\n      endfig;\n    \\end{mplibcode}\\fi\n    \\caption{An \\hyperref[def:angle/acute]{acute angle} with its measurement segments dashed.}\\label{def:angle/figure}\n  \\end{minipage}\n\\end{figure}\n\n\\begin{definition}\\label{def:angle}\n  A \\term{directed angle} is a tuple of two closed \\hyperref[def:geometric_ray]{rays} with a common vertex. It is a closed cone. Given two rays \\( r_1, r_2 \\) with a common vertex, we denote their corresponding directed angle by \\( \\sphericalangle(r_1, r_2) \\).\n\n  Suppose that \\( r_1 \\) and \\( r_2 \\) have scalar parametric equations\n  \\begin{equation*}\n    r_i: t \\mapsto\n    \\begin{cases}\n      tx_i + a_i \\\\\n      ty_i + b_i,\n    \\end{cases}\n    i = 1, 2.\n  \\end{equation*}\n\n  We write\n\n  The condition of the rays having a common vertex is equivalent to \\( a_1 = a_2 \\) and \\( b_1 = b_2 \\). If not specified otherwise, we assume that \\( a_1 = a_2 = b_1 = b_2 = 0 \\).\n\n  The \\term{measure in radians} of a directed angle, often called the angle itself, is defined as the number (see \\fullref{def:geometric_trigonometric_functions})\n  \\begin{equation*}\n    \\alpha \\coloneqq \\rem(\\arctantwo(y_2, x_2) - \\arctantwo(y_1, x_1), 2\\pi).\n  \\end{equation*}\n\n  We can classify angles based on their measure as\n  \\begin{thmenum}\n    \\thmitem{def:angle/zero} \\term{zero} if \\( \\alpha = 0 \\),\n    \\thmitem{def:angle/acute} \\term{acute} if \\( \\alpha \\in (0, \\tfrac \\pi 2) \\),\n    \\thmitem{def:angle/right} \\term{right} if \\( \\alpha = \\tfrac \\pi 2 \\),\n    \\thmitem{def:angle/obtuse} \\term{obtuse} if \\( \\alpha \\in (\\tfrac \\pi 2, \\pi) \\),\n    \\thmitem{def:angle/straight} \\term{straight} if \\( \\alpha = \\pi \\), in which case the angle is actually a line,\n    \\thmitem{def:angle/reflex} \\term{reflex} if \\( \\alpha > \\pi \\).\n  \\end{thmenum}\n\n  We often do not care about the order of the two rays and speak of an \\term{undirected angle}. In this case, the measure of the undirected angle is the smaller of the measures of the two oriented angles. Thus, we cannot speak of straight and reflex undirected angles.\n\\end{definition}\n\n\\begin{definition}\\label{def:triangle}\n  \\begin{figure}\n    \\centering\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      input metapost/plotting;\n\n      beginfig(1)\n      pair A, B, C;\n      path alpha, beta, gamma;\n\n      A := origin;\n      B := (3, 0) scaled u;\n      C := (2, 2) scaled u;\n\n      draw A -- B -- C -- cycle;\n\n      alpha = fullcircle scaled (u / 2) shifted A cutbefore (A -- B) cutafter (A -- C);\n      draw alpha;\n      label.urt(\"$\\alpha$\", point 0.4 of alpha);\n\n      beta = fullcircle scaled (u / 2) shifted B cutbefore (B -- C) cutafter (B -- A);\n      draw beta;\n      label.ulft(\"$\\beta$\", point 1.4 of beta);\n\n      gamma = fullcircle scaled (u / 4) shifted C cutbefore (A -- C) cutafter (B -- C);\n      draw gamma;\n      label.bot(\"$\\gamma$\", point 0.6 of gamma);\n\n      fill dot shifted A;\n      fill dot shifted B;\n      fill dot shifted C;\n\n      label.llft(\"$A$\", A);\n      label.lrt(\"$B$\", B);\n      label.top(\"$C$\", C);\n\n      label.rt(\"$a$\", midpoint of (B -- C));\n      label.ulft(\"$b$\", midpoint of (A -- C));\n      label.bot(\"$c$\", midpoint of (A -- B));\n      endfig;\n    \\end{mplibcode}\\fi\n    \\caption{An \\hyperref[def:triangle/acute]{acute triangle}.}\\label{def:triangle/figure}\n  \\end{figure}\n\n  A \\term{triangle} is a triple \\( (A, B, C) \\) of \\hyperref[def:point]{points}, no two of which are \\hyperref[def:collinear_complanar]{collinear} (see \\fullref{def:simplex/triangle} for a more general definition). The three points are called the \\term{vertices} of the triangle.\n\n  Define the associated \\hyperref[def:convex_set/line_segment]{line segments}, called the \\term{sides} of the triangle, and its (undirected) \\hyperref[def:angle]{angles} as\n  \\begin{balign*}\n    a \\coloneqq [B, C], &  & \\alpha \\coloneqq \\sphericalangle(b, c), \\\\\n    b \\coloneqq [A, C], &  & \\beta \\coloneqq \\sphericalangle(a, c),  \\\\\n    c \\coloneqq [A, B], &  & \\gamma \\coloneqq \\sphericalangle(a, b).\n  \\end{balign*}\n\n  Note that we defined the angles using segments rather than rays, but this is immaterial because each to each segment \\( [p, q] \\) there corresponds exactly one closed ray \\( t \\mapsto p + t q \\).\n\n  We can classify triangles based on their sides as\n  \\begin{thmenum}\n    \\thmitem{def:triangle/isosceles} \\term{isosceles} if at least two of its sides have equal length\n    \\thmitem{def:triangle/equilateral} \\term{equilateral} if all of its sides have equal length\n  \\end{thmenum}\n  or based on their angles as\n  \\begin{thmenum}\n    \\thmitem{def:triangle/acute} \\term{acute} if all of its angles are \\hyperref[def:angle/acute]{acute}.\n    \\thmitem{def:triangle/right} \\term{right} if at least one of the angles is \\hyperref[def:angle/straight]{straight}.\n    \\thmitem{def:triangle/obtuse} \\term{obtuse} if at least one of its angles is \\hyperref[def:angle/obtuse]{obtuse}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:quadratic_plane_curve}\n  The \\term{quadratic plane curves} are algebraic \\hyperref[def:hypersurface/algebraic]{curves} given by a bivariate polynomial of degree \\( 2 \\). The \\term{general equation} of a quadratic plane curve is\n  \\begin{equation}\\label{def:quadratic_plane_curve/general_equation}\n    c(x, y) \\coloneqq A x^2 + B xy + C y^2 + Dx + Ey + F = 0.\n  \\end{equation}\n\n  Multiple equation can correspond to the same curve. Not all general equations, however, define algebraic curves. We will not concern ourselves with the details. See \\fullref{ex:affine_varieties} for a proof that the unit circle is an algebraic curve. It turns out that the algebraic curves given \\fullref{def:quadratic_plane_curve/general_equation} are precisely the ones listed here, collectively known as \\term{conic sections}. We give only canonical forms of the equations; any linear transformation of the corresponding loci is described by another general equation.\n\n  \\begin{figure}\n    \\begin{minipage}{0.3\\textwidth}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        input metapost/plotting;\n\n        u := 1.25cm;\n\n        vardef scaled_sin(expr x) =\n        5 / 6 * sin(x)\n        enddef;\n\n        beginfig(1)\n        fill dot shifted (u, 0);\n\n        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;\n        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;\n\n        drawarrow path_of_curve(cos, scaled_sin, -1 / 4 * pi, 3 / 4 * pi, 0.01, u);\n        drawarrow path_of_curve(cos, scaled_sin, 3 / 4 * pi, 7 / 4 * pi, 0.01, u);\n        endfig;\n      \\end{mplibcode}\\fi\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}{0.3\\textwidth}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        input metapost/plotting;\n\n        u := 1.25cm;\n\n        vardef minus_cosh(expr x) =\n        -cosh(x)\n        enddef;\n\n        beginfig(1)\n        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;\n        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;\n\n        drawarrow path_of_curve(cosh, sinh, -pi / 3, 0, 0.01, u);\n        drawarrow path_of_curve(cosh, sinh, 0, pi / 3, 0.01, u);\n\n        drawarrow path_of_curve(minus_cosh, sinh, -pi / 3, 0, 0.01, u);\n        drawarrow path_of_curve(minus_cosh, sinh, 0, pi / 3, 0.01, u);\n        endfig;\n      \\end{mplibcode}\\fi\n    \\end{minipage}\n    \\hspace{0.02\\textwidth}\n    \\begin{minipage}{0.3\\textwidth}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        input metapost/plotting;\n\n        u := 1.25cm;\n\n        beginfig(1)\n        fill dot;\n\n        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;\n        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;\n\n        vardef y_upper(expr x) =\n        sqrt(x)\n        enddef;\n\n        vardef y_lower(expr x) =\n        -sqrt(x)\n        enddef;\n\n        drawarrow path_of_plot(y_upper, 0, pi / 3, 0.01, u);\n        drawarrow path_of_plot(y_lower, 0, pi / 3, 0.01, u);\n        endfig;\n      \\end{mplibcode}\\fi\n    \\end{minipage}\n    \\caption{An \\hyperref[def:quadratic_plane_curve/ellipse]{ellipse}, \\hyperref[def:quadratic_plane_curve/hyperbola]{hyperbola} and \\hyperref[def:quadratic_plane_curve/parabola]{parabola} defined via their parametric equations. The starting point is highlighted and the direction of the parametric curves is shown.}\\label{def:quadratic_plane_curve/figure}\n  \\end{figure}\n\n  \\begin{thmenum}\n    \\thmitem{def:quadratic_plane_curve/ellipse} An \\term{ellipse} is a quadratic curve whose canonical equation has the form\n    \\begin{equation}\\label{def:quadratic_plane_curve/ellipse/canonical_equation}\n      c(x, y) \\coloneqq \\frac {x^2} {a^2} + \\frac {y^2} {b^2} - 1 = 0,\n    \\end{equation}\n    where \\( a, b > 0 \\).\n\n    If \\( a = b \\), we say that the ellipse is a \\term{circle} and we call \\( a \\) the circle's \\term{radius}. The \\term{unit circle} is defined by \\( a = b = 1 \\). Circles generalize to \\hyperref[def:metric_space/sphere]{spheres} in metric spaces.\n\n    \\Fullref{def:pi} and \\fullref{def:geometric_trigonometric_functions} logically belong here, but are extracted separately for brevity.\n\n    We are often interested in defining ellipses via \\term{scalar parametric equations} using \\hyperref[def:trigonometric_functions]{trigonometric functions} as follows:\n    \\begin{equation}\\label{def:quadratic_plane_curve/ellipse/parametric_equations}\n      \\begin{cases}\n        x = a \\cos(t) \\\\\n        y = b \\sin(t),\n      \\end{cases}\n    \\end{equation}\n    where \\( t \\in [0, 2\\pi) \\).\n\n    We will now demonstrate that \\fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and \\fullref{def:quadratic_plane_curve/ellipse/parametric_equations} describe the same curve. First, suppose that the pair \\( (x_0, y_0) \\) satisfies \\fullref{def:quadratic_plane_curve/ellipse/canonical_equation}. It follows from \\fullref{thm:arctantwo} that \\( t_0 \\coloneqq \\arctantwo\\left(\\tfrac {y_0} b, \\tfrac {x_0} a \\right) \\) is a, solution to the \\hyperref[def:quadratic_plane_curve/ellipse/parametric_equations]{parametric equations}. Conversely, if \\( x_0 = a \\cos(t_0) \\) and \\( y_0 = b \\sin(t_0) \\) for some \\( t_0 \\in [0, 2\\pi) \\), by \\fullref{thm:trigonometric_identities/pythagorean_identity} it follows that the pair \\( (x_0, y_0) \\) is a root of \\fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and, by \\fullref{thm:arctantwo}, \\( t_0 \\) can be restored given \\( \\cos(t_0) \\) and \\( \\sin(t_0) \\).\n\n    Therefore, every point of the parametric equation \\fullref{def:quadratic_plane_curve/ellipse/parametric_equations} corresponds uniquely to a, solution of the canonical equation \\fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and vice versa, which makes the two approaches to defining ellipses equivalent.\n\n    \\thmitem{def:quadratic_plane_curve/hyperbola} A \\term{hyperbola} is a quadratic curve whose canonical equation has the form\n    \\begin{equation}\\label{def:quadratic_plane_curve/hyperbola/canonical_equation}\n      c(x, y) \\coloneqq \\frac {x^2} {a^2} - \\frac {y^2} {b^2} - 1 = 0,\n    \\end{equation}\n    where \\( a, b > 0 \\).\n\n    Similarly to ellipses, we are can define hyperbolas via \\term{scalar parametric equations} using \\hyperref[def:hyperbolic_trigonometric_functions]{hyperbolic trigonometric functions} as follows:\n    \\begin{equation}\\label{def:quadratic_plane_curve/hyperbola/parametric_equations}\n      \\begin{cases}\n        x = a \\cosh(t) \\\\\n        y = b \\sinh(t),\n      \\end{cases}\n    \\end{equation}\n    where \\( t \\in \\BbbR \\). This only defines the \\term{right part} of the hyperbola. The left part is defined by replacing \\( a \\) with \\( -a \\).\n\n    \\thmitem{def:quadratic_plane_curve/parabola} A \\term{parabola} is a quadratic curve whose canonical equation has the form\n    \\begin{equation}\\label{def:quadratic_plane_curve/parabola/canonical_equation}\n      c(x, y) \\coloneqq y^2 - 2px = 0,\n    \\end{equation}\n    where \\( p \\neq 0 \\).\n\n    Unlike ellipses and hyperbolas, we do not define parametric equations. Instead, we define \\( y \\) as a function of \\( x \\) separately for the lower half-plane and upper half-plane:\n    \\begin{equation}\\label{def:quadratic_plane_curve/parabola/cartesian_equation}\n      y(x) = \\pm \\sqrt{2px}.\n    \\end{equation}\n  \\end{thmenum}\n\n  Ellipses, hyperbolas and parabolas are collectively called \\term{conic sections}.\n\\end{definition}\n\n\\begin{definition}\\label{def:pi}\n  \\begin{figure}\n    \\centering\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      input metapost/plotting;\n\n      beginfig(1)\n      drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;\n      drawarrow (0, -1 / 2) scaled u -- (0, pi / 2) scaled u;\n\n      vardef y(expr x) =\n      sqrt(1 - x ** 2)\n      enddef;\n\n      drawarrow path_of_plot(y, -1, 1, 0.01, u);\n      endfig;\n    \\end{mplibcode}\\fi\n    \\caption{\\( \\gph(y^+) \\) as a parametric curve in \\fullref{def:pi}.}\\label{fig:def:pi/upper_half_circle}\n  \\end{figure}\n\n  The definition of a circle of unit radius as the zero-locus of the polynomial \\( x^2 + y^2 - 1 \\) allows us to, solve a chicken-and-egg problem regarding the definitions of the number \\( \\pi \\). It is conventional to define it as the ratio of a circle's circumference to its diameter. For a unit circle, this diameter is \\( 2 \\). It will be simpler for us, however, to define \\( \\pi \\) as the radius of a half-circle's circumference since we can represent \\( y \\) as a function of \\( x \\) in the upper \\hyperref[def:half_space]{half-plane} (see \\ref{fig:def:pi/upper_half_circle}). Define the parametric curve\n  \\begin{balign*}\n     & y^+: [-1, 1] \\to [0, 1]          \\\\\n     & y^+(x) \\coloneqq \\sqrt{1 - x^2}.\n  \\end{balign*}\n\n  We use \\fullref{thm:length_of_function_graph} to find the length of the graph \\( \\gph(y^+(x)) \\). The derivative of \\( y^+(x) \\) is\n  \\begin{equation*}\n    D_x[y^+(x)] = \\frac{-2x}{2 \\sqrt{1 - x^2}} = - \\frac x {\\sqrt{1 - x^2}} dx.\n  \\end{equation*}\n\n  The length of the curve \\( \\gph(y^+) \\) is thus\n  \\begin{equation*}\n    \\len(\\gph(y^+)) = \\int_{-1}^1 \\sqrt{1 + \\frac{x^2}{1 - x^2}} dx = \\int_{-1}^1 \\frac 1 {\\sqrt{1 - x^2}} dx.\n  \\end{equation*}\n\n  This justifies the definition\n  \\begin{equation}\\label{def:pi/weierstrass_integral}\n    \\pi \\coloneqq \\int_{-1}^1 \\frac 1 {\\sqrt{1 - x^2}} dx.\n  \\end{equation}\n\n  See \\fullref{thm:trigonometric_function_basic_roots} for a proof of how this relates to the trigonometric functions and \\fullref{thm:def:exponential_function/properties/eulers_identity} as a consequence.\n\\end{definition}\n\n\\begin{definition}\\label{def:geometric_trigonometric_functions}\n  After defining the \\hyperref[def:trigonometric_functions]{trigonometric functions} \\( \\cos(z) \\) and \\( \\sin(z) \\) analytically via power series, we will define their geometric counterparts \\( \\cos_G(z) \\) and \\( \\sin_G(z) \\) and show the connection between them. The actual geometric definition relies on formalisms that are far beyond our interest (see the notes in \\fullref{def:euclidean_plane}).\n\n  Fix a point \\( (x_0, y_0) \\) on the unit circle (that is, \\( x_0^2 + y_0^2 = 1 \\)) and define the points\n  \\begin{equation}\\label{def:geometric_trigonometric_functions/vertices}\n    \\begin{array}{l}\n      A \\coloneqq (x_0, y_0), \\\\\n      B \\coloneqq (0, 0),     \\\\\n      C \\coloneqq (x_0, 0).\n    \\end{array}\n  \\end{equation}\n\n  Consider the \\hyperref[def:triangle]{triangle} formed by these vertices. \\Cref{fig:def:geometric_trigonometric_functions/triangle} illustrates the situation.\n  \\begin{figure}\n    \\begin{minipage}[b]{0.4\\textwidth}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        input metapost/plotting;\n\n        u := 3.5cm;\n\n        beginfig(1)\n        pair A, B, C;\n        path alpha, beta;\n\n        t := 1;\n        A := origin;\n        B := (cos(t), sin(t)) scaled u;\n        C := (cos(t), 0) scaled u;\n\n        draw A -- B -- C -- cycle;\n\n        alpha = fullcircle scaled (u / 4) shifted A cutbefore (A -- C) cutafter (A -- B);\n        draw alpha;\n        label.urt(\"$\\alpha$\", midpoint of alpha);\n        label.lft(\"$\\begin{rcases} \\sin_G(\\alpha) = \\tfrac {\\len b} {\\len c} \\\\ \\cos_G(\\alpha) = \\tfrac {\\len a} {\\len c} \\end{rcases}$\", A);\n\n        beta = fullcircle scaled (u / 4) shifted B cutbefore (B -- A) cutafter (B -- C);\n        draw beta;\n        label.llft(\"$\\beta$\", point 0.7 of beta);\n        label.lft(\"$\\begin{rcases} \\sin_G(\\beta) = \\tfrac {\\len a} {\\len c} \\\\ \\cos_G(\\beta) = \\tfrac {\\len b} {\\len c} \\end{rcases}$\", B - (0.05, 0) * u);\n\n        fill dot shifted A;\n        fill dot shifted B;\n        fill dot shifted C;\n\n        label.bot(\"$A$\", A);\n        label.top(\"$B$\", B);\n        label.lrt(\"$C$\", C);\n\n        label.rt(\"$a$\", midpoint of (B -- C));\n        label.bot(\"$b$\", midpoint of (A -- C));\n        label.ulft(\"$c$\", midpoint of (A -- B));\n        endfig;\n      \\end{mplibcode}\\fi\n    \\end{minipage}\n    \\hspace{0.05\\textwidth}\n    \\begin{minipage}[b]{0.4\\textwidth}\n      \\centering\n      \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n        input metapost/plotting;\n\n        u := 3.5cm;\n\n        beginfig(1)\n        pair A, B, C;\n        path alpha, beta;\n\n        t := 1;\n        A := origin;\n        B := (cos(t), sin(t)) scaled u;\n        C := (cos(t), 0) scaled u;\n\n        drawarrow (-sin(pi/16), 0) scaled u -- (5/4, 0) scaled u;\n        drawarrow (0, -sin(pi/16)) scaled u -- (0, 5/4) scaled u;\n\n        draw path_of_curve(cos, sin, -pi/16, 9/16 * pi, 0.01, u);\n        draw A -- B -- C -- cycle;\n\n        alpha = fullcircle scaled (u / 4) shifted A cutbefore (A -- C) cutafter (A -- B);\n        draw alpha;\n        label.urt(\"$\\alpha$\", midpoint of alpha);\n\n        beta = fullcircle scaled (u / 4) shifted B cutbefore (B -- A) cutafter (B -- C);\n        draw beta;\n        label.llft(\"$\\beta$\", point 0.7 of beta);\n\n        fill dot shifted A;\n        fill dot shifted B;\n        fill dot shifted C;\n\n        label.llft(\"$(0, 0)$\", A);\n        label.urt(\"$(x_0, y_0)$\", B);\n        label.lrt(\"$(x_0, 0)$\", C);\n\n        label.rt(\"$a$\", midpoint of (B -- C));\n        label.bot(\"$b$\", midpoint of (A -- C));\n        label.ulft(\"$c$\", midpoint of (A -- B));\n        endfig;\n      \\end{mplibcode}\\fi\n    \\end{minipage}\n    \\caption{An \\enquote{abstract} right triangle in the \\hyperref[def:euclidean_plane]{Euclidean plane} with legends for geometric sines and cosines and the same triangle in \\( \\BbbR^2 \\) connecting the origin to a point \\( (x_0, y_0) \\) on the unit circle.}\\label{fig:def:geometric_trigonometric_functions/triangle}\n  \\end{figure}\n\n  The original \\enquote{geometric definition} of \\( \\sin_G \\) and \\( \\cos_G \\) regards them as functions of an angle rather than numeric functions. \\( \\sin_G \\) and \\( \\cos_G \\) are only defined for two of the angles in a right triangle. The geometric definition is\n  \\begin{balign*}\n    \\sin_G(\\alpha) \\coloneqq \\frac{\\len(b)} {\\len(c)}, &  & \\cos_G(\\alpha) \\coloneqq \\frac{\\len(a)} {\\len(c)},\n    \\\\\n    \\sin_G(\\beta) \\coloneqq \\frac{\\len(b)} {\\len(c)},  &  & \\cos_G(\\beta) \\coloneqq \\frac{\\len(a)} {\\len(c)}.\n  \\end{balign*}\n\n  In our case, \\( \\len(a) = y_0 \\), \\( \\len(b) = x_0 \\) and \\( \\len(c) = 1 \\). Furthermore, \\( \\sin_G(\\beta) \\) nor \\( \\cos_G(\n  \\beta) \\) are immaterial to our subsequent arguments and we only introduced them for the sake of having a full definition.\n\n  Therefore, we conclude that\n  \\begin{balign*}\n    \\sin_G(\\alpha) = x_0,\n     &  &\n    \\cos_G(\\alpha) = y_0.\n  \\end{balign*}\n\n  To see that \\( \\sin_G \\) and \\( \\cos_G \\) are somewhat analogous to \\( \\sin \\) and \\( \\cos \\), notice that by \\fullref{thm:arctantwo}, there exists a unique \\( t_0 \\coloneqq \\arctantwo(y_0, x_0) \\) such that\n  \\begin{balign*}\n    \\sin(t_0) = x_0,\n     &  &\n    \\cos(t_0) = y_0.\n  \\end{balign*}\n\n  Therefore, our \\hyperref[def:trigonometric_functions]{analytic definition} of the trigonometric functions as numeric functions correspond to the classical geometric definition in the special case where we consider the angle near the origin in the triangle formed by the vertices \\fullref{def:geometric_trigonometric_functions/vertices}. This motivates \\enquote{measuring} angles using the obtained correspondence. This unit of measurement is called a \\term{radian}. We say that the angle \\( \\alpha \\) is \\( t_0 \\) \\term{radians}. Outside of mathematics, it is more conventional to use \\term{degrees}, which are obtained from radians by scaling with \\( \\tfrac {180} {\\pi} \\). That is, \\( \\alpha \\) is \\( \\tfrac {180} {\\pi} t_0 \\) degrees.\n\\end{definition}\n", "meta": {"hexsha": "264b8bd611aa9441c489dd357529cca0d134b232", "size": 26263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/analytic_geometry_in_the_plane.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/analytic_geometry_in_the_plane.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/analytic_geometry_in_the_plane.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.5528301887, "max_line_length": 924, "alphanum_fraction": 0.6539999238, "num_tokens": 8393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893340314393, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6481505435938811}}
{"text": "\\mychapter{2}{Lesson 2} %180928\n\n\\section{Authentic communication}\n\nThe most common scenario exposing the problem of authentication is depicted in figure \\ref{fig:authentication}. This time, the parties Alice and Bob want to ensure that they are effectively communicating to each other; in other words, nobody else is \\emph{impersonating} either party. The objects used here are:\n\\begin{itemize}\n    \\item The data to be shared, or \\emph{message} $m$;\n    \\item Some additional secret information, shared by the two parties, that is used to \\emph{sign} the message: the \\emph{authentication key} or just \\emph{key} $k$;\n    \\item The result of signing a message $m$ using the key $k$: the \\emph{signature} or \\emph{tag} $t$.\n\\end{itemize}\n\n\\begin{figure}[ht]\n    \\centering\n    \\begin{tikzpicture}\n        \\draw\n            (0, 0) node (a) [box, fill = white] {Alice} \n            (5, 0) node (b) [box, fill = white] {Bob}\n            (2.5, -1) node (e) [box, fill = white] {Eve}\n        ;\n\n        \\draw[-Stealth] (a) -- node [midway, above] {$(m, t)$} (b);\n        \\draw[-Stealth] (0, -1) node [below] {$k$} -- (a);\n        \\draw[-Stealth] (5, -1) node [below] {$k$} -- (b);\n        \\draw[-Stealth] (-1, 0) node [left] {$m$} -- (a);\n        \\draw[-Stealth] (b) -- (6, 0) node [right] {$1$};\n        \\draw[-Stealth] (2, -0.1) -- (3, -0.1) (2.5, -0.1) -- (e);\n\n    \\end{tikzpicture}\n\n    \\caption{A depiction of the problem of authentic communication}\n    \\label{fig:authentication}\n\\end{figure}\n\nThe mechanism employed by both parties to enforce authentication is called a \\emph{cryptographic authentication scheme}, or just \\emph{authentication scheme}, typically taking the form $\\Phi = (\\Tag, \\Ver)$, where:\n\\begin{itemize}\n    \\item $\\Tag \\in \\K \\times \\M \\to \\T$ is the machine that, given a message $m$ in $\\M$ and a key $k$ in $\\K$ generates the signature $t$\n    \\item $\\Ver \\in \\K \\times \\M \\times \\T \\to \\binary$ is the machine that decides whether $t$ is the correct signature for the message $m$ using the key $k$.\n\\end{itemize}\n\nIt is worth observing that, under the assumption that such machines still behave as mathematical functions, a straightforward verifier with inputs $(k, m, t)$ consists in:\n\\begin{enumerate}\n    \\item Invoking the tagging function: $u = \\Tag(k, m)$;\n    \\item Comparing $u$ and $t$ for equality.\n\\end{enumerate}\n\nGiven such definitions, an authentication scheme works as intended if and only if:\n\\[\n    \\forall m \\in \\M, \\forall k \\in \\K \\implies \\Ver(k, m, \\Tag(k, m)) = 1\n\\]\n\nA security problem then arises when someone, having a signed message $(m_1, t_1)$ where the key $k$ used for tagging is unknown, is able to efficiently sign a different message $(m_2, t_2)$ such that verification under the same key yields a success. This acion is called a \\emph{forgery}; and by looking at the original setting in figure \\ref{fig:authentication}, if Eve is effectively able to forge vaild signatures, she can indeed impersonate either Alice or Bob at will. The desired property of an authentication scheme thus becomes to be resistant, if not immune, to such attacks; in one word, the scheme is \\emph{unforgeable}.\n\n\\begin{definition}[$\\varepsilon$-statistical one-time unforgeability]\n    let $\\Phi$ be an authentication scheme, and let $m_1$ and $m_2$ be two distinct messages, and $t_1 = \\Tag(K, m_1)$ be the signature of $m_1$ under $\\Phi$, with the key $K$ picked uniformly at random. $\\Phi$ is deemed \\emph{$\\varepsilon$-statistical one-time unforgeable} iff knowing $m_1$ and $t_1$ does not give any advantage in finding a signature $t_2$ that is actually the signature of $m_2$ under the same scheme and the same key of $m_1$, without knowing such key:\n    \\[\n        \\forall m_1 \\neq m_2 \\in \\M \\, \\forall t_1, t_2 \\in \\T \\quad \\Pr[\\Tag(K, m_2) = t_2 \\knowing \\Tag(K, m_1) = t_1] \\leq \\varepsilon\n    \\]\n\\end{definition}\n\n\\subsection{An introduction to hashing}\n\nA great deal of authentication has been, and is still done by means of \\emph{hashing}, which consists of feeding the message to a special machine that produces a scrambled, unique signature for it; such machines are then known as \\emph{hash functions}.\n\nFor starters recall that, given a set $A \\to B$ that collects all possible functions from $A$ to $B$, a \\emph{function family} is a subset of such class that share some specific properties. Having said that:\n\n\\begin{definition}\n    A family of \\emph{hash functions} $H$ is defined as a function family that is mapped 1-to-1 by an indexing set $\\mathcal{S}$, where the indices are called \\emph{seeds}:\\footnote{This kind of notation consisting in putting an argument as a subscript to a generic, typically of higher-order function, is also called ``currying''.}\n    \\[\n        H \\in \\mathcal{S} \\to (\\M \\to \\T) : s \\mapsto h_s\n    \\]\n    Furthermore, given a uniformly random seed $S$, the family as a whole distributes the tags uniformly:\n    \\[\n        \\forall m \\in \\M \\, \\forall t \\in \\T \\qquad \\Pr[h_S(m) = t] = \\oneover{\\T}\n    \\]\n\\end{definition}\n\nHaving formalized what a hash function family is, the notion of unforgeability can be modeled by the property of \\emph{pairwise-independency}:\n\n\\begin{definition}\n    Let $H$ be a family of hash functions, and $S$ be a uniformly random seed; the hash functions are deemed \\emph{pairwise-independent} iff, for any two distinct messages $m_1$ and $m_2$, the pair $(h_S(m_1), h_S(m_2))$ distributes uniformly in $\\T^2$:\n    \\[\n        \\forall m_1 \\neq m_2 \\in \\M \\, \\forall t_1, t_2 \\in \\T \\qquad \\Pr[h_S(m_1) = t_1 \\wedge h_S(m_2) = t_2] = \\oneover{|\\T|^2}\n    \\]\n\\end{definition}\n\nAs an example of such a family, consider the additive group of integers modulo $p$: $(\\integer_p, +)$, where $p$ is a prime integer. Let the seed space $\\mathcal{S}$ be the set of pairs $\\integer_p^2$, and define the function family:\n\\[\n    H \\in \\integer_p^2 \\to (\\integer_p \\to \\integer_p) : (a, b) \\mapsto (x \\mapsto \\textrm{\\textup{mod}}_p(ax + b))\n\\]\n\n\\begin{proposition}\n    The functions in the family $H$ are pairwise-independent.\n\\end{proposition}\n\n\\begin{proof}\n    Let $S = (A, B)$ be a uniformly random seed for $H$. For any distinct messages $m_1$ and $m_2$, and for any tags $t_1$ and $t_2$:\n    \\begin{align*}\n        &\\ \\Pr[h_S(m_1) = t_1 \\wedge h_S(m_2) = t_2]        & \\\\\n        =&\\ \\Pr[A m_1 + B = t_1 \\wedge A m_2 + B = t_2]     & \\text{($H$ definition)}\\\\\n        =&\\ \\Pr\\left[ \\begin{pmatrix} m_1 & 1 \\\\ m_2 & 1 \\end{pmatrix} \\cdot \\begin{pmatrix} A \\\\ B \\end{pmatrix} = \\begin{pmatrix} t_1 \\\\ t_2 \\end{pmatrix} \\right]                                        & \\text{(Matrix form)} \\\\\n        =&\\ \\Pr\\left[ \\begin{pmatrix} A \\\\ B \\end{pmatrix} = \\begin{pmatrix} m_1 & 1 \\\\ m_2 & 1 \\end{pmatrix}^{-1} \\cdot \\begin{pmatrix} t_1 \\\\ t_2 \\end{pmatrix} \\right]                                           & \\\\\n        =&\\ \\oneover{|\\integer_p^2|} & \\text{($(A, B)$ is uniform)}\n    \\end{align*}\n    which satisfies the definition of pairwise-independency.\n\\end{proof}\n\n% TODO: Consider making an example in Zp, if possible\nIt is very important to avoid confusing \\emph{pairwise} independency with \\emph{mutual} independency: while the former enforces independency only on pairs, the latter extends it to all possible subsets; the two notions are not necessarily equivalent.\n\nThe property of pairwise-independency of hash function families can be directly exploited to provide an unforgeable authentication scheme:\n\n\\begin{theorem}\n    Define an authentication scheme $\\Phi = (\\Tag, \\Ver)$ to be such that its tagging machine is a hash function family $H$:\n    \\[\n        \\Tag(k, m) = h_k(m)\n    \\]\n    and let it be pairwise-independent. Then $\\Phi$ is $\\oneover{|\\T|}$-statistical one-time unforgeable. \n\\end{theorem}\n\n\\begin{proof}\n    Let $K$ be a uniformly random key. For any distinct messages $m_1$ and $m_2$, and for any tags $t_1$ and $t_2$:\n    \\begin{align*}\n         &\\ \\Pr[\\Tag(K, m_2) = t_2 \\knowing \\Tag(K, m_1) = t_1]                     & \\\\\n        =&\\ \\Pr[h_K(m_2) = t_2 \\knowing h_K(m_1) = t_1]                             & \\text{($\\Tag$ definition)} \\\\\n        =&\\ \\frac{\\Pr[h_K(m_2) = t_2 \\wedge h_K(m_1) = t_1]}{\\Pr[h_K(m_1) = t_1]}   & \\text{(Conditional prob. def.)} \\\\\n        =&\\ |\\T| \\cdot \\Pr[h_K(m_2) = t_2 \\wedge h_K(m_1) = t_1]                    & \\text{($H$ is a hash function)} \\\\ \n        =&\\ \\frac{|\\T|}{|\\T|^2} = \\oneover{|\\T|}                                    & \\text{($H$ is pairwise-independent)}\n    \\end{align*}\n\n    which satisfies the definition of $\\oneover{|\\T|}$-statistical one-time unforgeability.\n\\end{proof}\n\n\\todo{Need to link statistical unforgeability with key size beforehand}\n\n\\begin{theorem}\n    For any positive $\\lambda$, a $(2^{-\\lambda})$-statistical $t$-time unforgeable authentication scheme has a key of size $(t + 1) \\lambda$.\n\\end{theorem}\n\n\\begin{proof}\n    Idea: For each ``time'', use one ``subkey''\n\\end{proof}\n", "meta": {"hexsha": "5f1420656e05478f30c6a5d81c6c309de5af744a", "size": 8896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_2.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_2.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_2.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": 62.6478873239, "max_line_length": 631, "alphanum_fraction": 0.6541142086, "num_tokens": 2748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.7905303236047048, "lm_q1q2_score": 0.6481505372030467}}
{"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 Advanced Algorithms} \\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 2015}{Prof.\\ Jyh-Ming Lien}{---}\n\n\nThe goal of this assignment is to deepen your understanding on various implementations of 2-d Voronoi Diagram. \nIn this exam, you are given two implementations of 2-d Voronoi Diagram: the Fortune's algorithm and \nan algorithm using well-known image-based wave propagation method. You task is to (1) understand the implementations, (2)  compare the results from these two implementations, and (3) finally improve the image-based method. \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 three sections: a summary of what the code does (for both implementations), \nyour discovery of the differences in output, and your improvement. In the second and third sections, 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}:\nYou should use \\href{https://github.com/}{github} to maintain your code and the report. Email me your github clone command to my email address \\href{mailto:jmlien@cs.gmu.edu}{\\it jmlien@cs.gmu.edu}\nbefore the deadline.\n\n\\textbf{Due: Nov 26, 2017. At 11:59 pm.}\n\\section{Part 1: Understand the implementations (30 pts)}\n\n\n\\subsection{What should  you do?}\n\nYour goal is to get a full grasp of what the code does in both implementations: hedcuter and voronoi. \nYour summary should provide algorithms for computing Voronoi diagram, Centroidal Voronoi tessellation (CVT), \nand stippling methods from  both implementations. \n%Your summary should provide a discussion on what parameters are used to control their outputs. \n\n{\\sc Hint 1}: Both methods are 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 the solution file in folder {\\em hedcuter/code/vc\\_files}.\n This code requires OpenCV. By 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}) if you encounter problems. \n\n{\\sc Hint 3}: To compile the second code, you will need boost (\\href{www.boost.org}{\\it www.boost.org}) and define two boost related environment variables:\nBOOST\\_INCLUDEDIR and BOOST\\_LIBRARYDIR before you compile. Each of these variables should have the full paths to the include and library folders on the system.\nThis implementation is obtained from  \\href{http://www.saliences.com/projects/npr/stippling}{\\it http://www.saliences.com/projects/npr/stippling}.\nSome details of the code can be found there.\n\n\n\n\\section{Part 2: Compare the Outputs  (30 pts)}\n\n\n\n\n\n\n\\subsection{What should  you do?}\n\nYour goal is to compare the output of these two implementations. \nUse the images in folder hedcuter/images or use images of your own, please show the differences visually (e.g. circle the areas of difference)\nand also in writing. \n%You can find more of these images from\\href{http://philip.greenspun.com/stock/}{\\it http://philip.greenspun.com/stock/}.\nYou should also provide some discussion of where these differences are from.  Here are some questions for you to consider.\nYou are free to explore beyond these questions. \n\n\\begin{enumerate}\n\\item Do you get the same results by running the same program on the same image multiple times? \n\\item If you vary the number of the disks in the output images,  do these implementations produce the same distribution in the final image? If not, why?\n\\item If you vary the number of the disks in the output images,  is a method faster than the other? \n\\item Does the size (number of pixels), image brightness or contrast of image increase or decrease their difference? \n\\item Does the type of image (human vs. machine,  natural vs. urban landscapes, photo vs. painting, etc) increase or decrease their difference? \n\\item Are the outputs of these stippling methods different  the hedcut images created by artists (e.g. those from the \\href{http://www.wsj.com/articles/SB10001424052748704207504575129961786135180}{Wall Street Journal})? \n\\end{enumerate}\n\n\n\\section{Part 3: Improve  ``hedcuter'' code (40 pts)}\n\n\n\\subsection{What should  you do?}\n\nProvide at least two 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.\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 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\\end{enumerate}\n\n\\bibliographystyle{plain}\n\\bibliography{shape-assignment}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "3c5399bcac693223ab356e6cf785b97fb637deb4", "size": 7268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment/assignment.tex", "max_stars_repo_name": "StephenPArnold/CS633-hw3", "max_stars_repo_head_hexsha": "23771990a8fcfb71e629af66cb2f172e6dbda3a7", "max_stars_repo_licenses": ["MIT"], "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/assignment.tex", "max_issues_repo_name": "StephenPArnold/CS633-hw3", "max_issues_repo_head_hexsha": "23771990a8fcfb71e629af66cb2f172e6dbda3a7", "max_issues_repo_licenses": ["MIT"], "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": "StephenPArnold/CS633-hw3", "max_forks_repo_head_hexsha": "23771990a8fcfb71e629af66cb2f172e6dbda3a7", "max_forks_repo_licenses": ["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.4533333333, "max_line_length": 367, "alphanum_fraction": 0.7707760044, "num_tokens": 1890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6481432147723726}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the vectors $\\vect{u}$ and $\\vect{v}$ drawn below.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, blue] (0,0)--(2,1);\n      \\draw[->, thick, red] (4,1)--(5,0.5);\n      \\node[below] at (1,1.25){$\\vect{u}$};\n      \\node[above right] at (4.5, 0.75){$\\vect{v}$};\n    \\end{tikzpicture}\n  \\end{center}\n  Draw  $-\\vect{u}$, $2\\vect{v}$, and $-\\frac{1}{2}\\vect{v}$.\n\n  \\begin{sol}\n    ~\n    \\begin{center}\n      \\begin{tikzpicture}[scale=2]\n        \\draw[->, thick, blue] (0,0)--(2,1);\n        \\draw[->, thick, blue] (3,1)--(1,0);\n        \\draw[->, thick, red] (5,1)--(6,0.5);\n        \\draw[->, thick, red] (6.5,0.75)--(6,1);\n        \\draw[->, thick, red] (4,1)--(6,0);\n        \\node[above] at (1,1){$\\vect{u}$};\n        \\node[below] at (2,0.5){$-\\vect{u}$};\n        \\node[below] at (5.5, 0.75){$\\vect{v}$};\n        \\node[above right] at (6.25, 0.75){$-\\frac{1}{2}\\vect{v}$};\n        \\node[below] at (5, 0.4){$2\\vect{v}$};\n      \\end{tikzpicture}\n    \\end{center}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find $-3\\begin{mymatrix}{r}\n    5 \\\\\n    -1 \\\\\n    2 \\\\\n    -3\n  \\end{mymatrix}\n  + 5\\begin{mymatrix}{r}\n    -8 \\\\\n    2 \\\\\n    -3 \\\\\n    6\n  \\end{mymatrix}$.\n  \\begin{sol}\n    $\\begin{mymatrix}{r}\n      -55 \\\\\n      13 \\\\\n      -21 \\\\\n      39\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the properties of scalar multiplication from\n  Proposition~\\ref{prop:vector-scalar-multiplication} and the\n  properties of vector addition from\n  Proposition~\\ref{prop:properties-vector-addition} to prove the\n  following equalities. Justify every step.\n  \\begin{enumerate}\n  \\item $(k+\\ell)(\\vect{u}+\\vect{v}) = k\\vect{u} + k\\vect{v} +\n    \\ell\\vect{u} + \\ell\\vect{v}$.\n  \\item $0\\vect{u} = \\vect{0}$.\n  \\item $(-1)\\vect{u} = -\\vect{u}$.\n  \\item $-(k\\vect{u}) = k(-\\vect{u}) = (-k)\\vect{u}$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item\n      $(k+\\ell)(\\vect{u}+\\vect{v}) = (k+\\ell)\\vect{u} +\n      (k+\\ell)\\vect{v} = k\\vect{u} + k\\vect{v} + \\ell\\vect{u} +\n      \\ell\\vect{v}$. Here we used the distributive law over vector\n      addition in the first step, and the distributive law over scalar\n      addition in the second step.\n    \\item We have $0\\vect{u} = (0+0)\\vect{u} = 0\\vect{u} + 0\\vect{u}$\n      by properties of scalars and by the distributive law,\n      respectively. Adding $-(0\\vect{u})$ to both sides of the\n      equation, and using the additive unit law and associativity, we\n      have $\\vect{0} = 0\\vect{u}$.\n    \\item We have $(-1)\\vect{u} = (-1)\\vect{u} + \\vect{0} =\n      (-1)\\vect{u} + (\\vect{u} + (-\\vect{u})) = ((-1)\\vect{u} +\n      \\vect{u}) + (-\\vect{u}) = ((-1)\\vect{u} + 1\\vect{u}) +\n      (-\\vect{u}) = ((-1)+1)\\vect{u} + (-\\vect{u}) = 0\\vect{u} +\n      (-\\vect{u}) = \\vect{0} + (-\\vect{u}) = -\\vect{u}$. Here, we have\n      used the additive unit law, the additive inverse law, the\n      associative law, the rule for multiplication by 1, the\n      distributive law, properties of scalars, the property of part\n      (b), and the additive unit law, respectively.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "f132f50d42316758d7aa3125fec19e4016957c6e", "size": 3121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Vectors-ScalarMultiplication.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-ScalarMultiplication.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-ScalarMultiplication.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.5104166667, "max_line_length": 70, "alphanum_fraction": 0.5357257289, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6481432059581519}}
{"text": "\\section{What's wrong with monocular camera?}\n\\label{mono_prob}\n\nAs the name suggests a monocular camera is a camera with a single imaging sensor. In section~\\ref{imageFormation} we say that given a perfectly calibrated camera ie. with the intrinsic and extrinsic parameters known, we can measure size of objects in the real world. This however is not true for a single image taken from a monocular camera. When 3D objects are projected onto the image plane (2D), the depth information stored in the z-axis is lost. This can be seen in the example below. \n\n% For one-column wide figures use\n\\begin{figure}\n% Use the relevant command to insert your figure file.\n% For example, with the graphicx package use\n  \\includegraphics[width=\\textwidth]{./figures/1.png}\n% figure caption is below the figure\n\\caption{Monocular camera scale problem}\n\\label{fig:mono1}       % Give a unique label\n\\end{figure}\n\nAs seen in the Fig~\\ref{fig:mono1}, irrespective of the location of the object in the real world, the size of the object in the image plane remains the same. Mathematically, this can be shown as \n\n\\begin{equation}\n\\frac{y}{f}=\\frac{y_1}{z_1+f}=\\frac{y_2}{z_2+f}\n\\end{equation}\n\nWhere $f$ is the focal length of the camera. The title of the paper mentions scale estimation. In the context of SLAM which will be covered in the next section, scale is a term used to denote the factor by which the computed trajectory by a SLAM algorithm needs to be multiplied/scaled to make it equal to the ground truth. For example, if the measured distance is 2m, whereas the ground truth is 4m, the scale value would be 2. This is an area of active research and the research community has come up with different techniques to solve this problem. As the title suggests, we would be talking about the fusion of IMU and Vision for solving this challenge.\n", "meta": {"hexsha": "ee2041db999e5744c7d981b6120f0e69af0ae09d", "size": 1834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/text/mono_problem.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/mono_problem.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/mono_problem.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": 79.7391304348, "max_line_length": 657, "alphanum_fraction": 0.7769901854, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6481432010780831}}
{"text": "\\subsection{Numerical Approximation and Analysis}\\label{sec:set-algorithm}\nWe present a non-intrusive algorithm based on Monte Carlo sampling\\---initially introduced in \\cite{BET+14} and further analyzed in \\cite{BET+14-arxiv}\\---that is structured in four stages (written as four independent for-loops), that are linked to the stages in Fig.~\\ref{fig:scheme}.\nWe direct the interested reader to \\cite{BET+14-arxiv} for more detailed information and analysis of this algorithm, e.g., on the requirement of a sampler being ``$\\pborel$-consistent'' to ensure convergence.\n\n\n\\begin{algorithm}[hbtp]\n\\DontPrintSemicolon\nChoose a discretization partition $\\set{D_\\idisc}_{\\idisc=1}^{\\ndiscs}$ of $\\dspace$.\\\\\n\t\\For{$\\idisc = 1, \\hdots, \\ndiscs$}{\n\t\t\tCompute $p_{\\dspace, \\idisc} = \\dataP(D_\\idisc)$.\n\t}\n \tChoose samples $\\set{\\param^{(\\iparam)}}_{\\iparam=1}^{\\nsamps} \\subset \\pspace$, which implicitly defines a Voronoi-cell partition $\\set{\\VV_\\iparam}_{\\iparam=1}^{\\nsamps}$ of $\\pspace$.\\\\\n\t\\For{$\\iparam = 1, \\hdots, \\nsamps$}{\n\tCompute $\\qoi_\\iparam = \\qoi(\\param^{(\\iparam)})$.\\\\\n\tLet $\\OO_\\idisc = \\set{\\iparam: \\qoi_\\iparam \\in D_\\idisc}$.\\\\\n\tCompute approximations $V_\\iparam \\approx \\pmeas (\\VV_\\iparam)$.\n\t}\n\t\\For{$\\idisc = 1, \\hdots, \\ndiscs$}{\n\tCompute $\\CC_\\idisc = \\set{\\iparam:Q_\\iparam \\in D_\\idisc}$.\n\t}\n\t\\For{$\\iparam = 1, \\hdots, \\nsamps$}{\n\tCompute $p_{\\pspace, \\iparam} = \\left ( V_\\iparam / \\sum_{j\\in \\CC_{\\OO_\\iparam} } V_j \\right ) p_{\\dspace, \\OO_\\iparam}$.\n\t}\n\tFor any $A\\in \\pborel$, compute\n\t\\begin{equation}\n\t\\PP_{\\pspace, \\ndiscs, \\nsamps} (A) = \\sum_{\\iparam=1}^\\nsamps p_{\\pspace, \\iparam} \\Chi_{\\VV_\\iparam} (A)\n\t\\end{equation}\n \\caption{Numerical Approximation of the Inverse Density}\n \\label{alg:inv_density}\n\\end{algorithm}\n\n\nThe first two stages correspond to formulating the discretized version of the SIP given in step (S1) in Fig.~\\ref{fig:scheme}.\nWe first discretize the probability space $\\Ospace$.\nThen, we simultaneously discretize the measure space $(\\pspace, \\pborel, \\pmeas)$ and construct a simple-function approximation to the map $\\qoi$.\nThese stages introduce the primary sources of error, and the third and fourth stages may be thought of as solving the discretized SIP exactly.\nThe samples that are used to describe $\\pspace$ implicitly define a set of Voronoi cells $\\set{\\VV_\\iparam}_{\\iparam=1}^{\\nsamps}$, which can be seen in Figure~\\ref{fig:voronoi_cells}.\nEach sample set defines a fundamentally different geometry.\n\n\\begin{figure}[ht]\n\\centering\n\t\\begin{minipage}{.475\\textwidth}\n\t\t\\includegraphics[width=\\linewidth]{./images/voronoi_diagrams/voronoi_diagram_N25_r0}\n\t\\end{minipage}\n\\caption{\nVoronoi-cell discretization (partition) induced by $\\nsamps = 25 $ uniform i.i.d.~random samples in $\\pspace = [0,1]^2$.\n}\n\\label{fig:voronoi_cells}\n\\end{figure}\n\nThe third stage then identifies the collection of Voronoi cells in $\\pspace$ that approximate the contour events in $\\cborel$ defined by $\\qoi^{-1}(D_\\idisc)$ for $\\idisc=1,\\hdots,\\ndiscs$. This allows us to formulate the consistent solution to the discretized SIP on $(\\pspace, \\cborel, \\contourP)$ as illustrated in step (S2) of Fig.~\\ref{fig:scheme}.\nThe fourth stage, associated with step (S3) in Fig.~\\ref{fig:scheme}, uses a discrete version of the ansatz to approximate the probability of $\\VV_\\iparam$ for $\\iparam=1,\\dots,\\nsamps$.\nThis results in an approximate probability measure, denoted by $\\updatedPxNM$, which produces the same probability estimates for events $A$ and $A\\setminus \\set{ \\param^{(\\iparam)} }_{\\iparam=1}^\\nsamps$, which are identical almost everywhere with respect to $\\pmeas$.\n\nNote that Algorithm~\\ref{alg:inv_density} makes no mention of the method by which the samples $\\set{ \\param^{(\\iparam)} }_{\\iparam=1}^{\\nsamps}$ were generated or sets in $\\set{D_\\idisc}_{\\idisc=1}^{\\ndiscs}$ are chosen.\n$\\set{ \\param^{(\\iparam)} }_{\\iparam=1}^{\\nsamps}$ may be generated using uniform random sampling, Latin-hypercube sampling, or even regular grids.\nA thorough discussion of the choices involved in making such decisions is beyond the scope of this work, though we touch briefly on the discretization of $\\dspace$ in the following section.\n", "meta": {"hexsha": "7858b7c91432804910f86762b30b9cc3102095f3", "size": 4186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "set-based/set_algorithm.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/set_algorithm.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/set_algorithm.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": 72.1724137931, "max_line_length": 353, "alphanum_fraction": 0.7305303392, "num_tokens": 1304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6481431904795197}}
{"text": "\\section{Addition and subtraction}\n\\begin{center}\n    \\begin{longtable}{lcr}\n        $a_1 + a_2\\ \\cdots\\ + a_n = n \\cdot a$\n        &\n        $a + (-b) = a - b$\n        &\n        $a - (-b) = a + b$\n    \\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "a395b04783775215a03208b95d106d3cb7ef9394", "size": 231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/addition_and_subtraction.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/addition_and_subtraction.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/addition_and_subtraction.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": 21.0, "max_line_length": 46, "alphanum_fraction": 0.4588744589, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6481151444867106}}
{"text": "% !TEX encoding = UTF-8 Unicode\n% !TEX spellcheck = en_US\n% !TEX root = ../../../ICMA2020.tex\n\n\\subsection{Dynamics Model of Serial Robots}\nThis subsection describes the dynamics model of the 6-axis robot.\nThe joint torques $\\boldsymbol{\\tau}$ of all axes required for the feedforward control can be calculated by\n%\n\\begin{equation}\n\\label{eq:model_equation1}\n\\begin{split}\n\\boldsymbol{\\tau}=\n\\boldsymbol{M}(\\boldsymbol{q}) \\ddot{\\boldsymbol{q}}+\\boldsymbol{c}(\\boldsymbol{q}, \\dot{\\boldsymbol{q}})+\\boldsymbol{g}(\\boldsymbol{q})+\\boldsymbol{h}(\\dot{\\boldsymbol{q}}).\n\\end{split}\n\\end{equation}\n%\nHerein $\\boldsymbol{q}$, $\\dot{\\boldsymbol{q}}$ and $\\ddot{\\boldsymbol{q}}$ represent the joint angles, velocities and accelerations given by the motion planning. $\\boldsymbol{M}$ denotes the mass matrix, $\\boldsymbol{c}$ the Coriolis effects and $\\boldsymbol{g}$ the gravitational effects.\nThe friction model is represented by $\\boldsymbol{h}$ with\n%\n\\begin{equation}\nh_{j}=f_{\\mathrm{c}, j} \\operatorname{sgn}\\left(\\dot{{q}}_{j}\\right)+f_{\\mathrm{v}, j} \\dot{q}_{j},\n\\end{equation}\n%\nwhere $f_{\\mathrm{c}, j}$ represents the Coulomb friction coefficient for joint $j$ and $f_{\\mathrm{v}, j}$ the viscous friction coefficient. \nThe gear transmission between motor and link side is omitted for the sake of simplifying the equations. Measured motor velocities and estimated motor torques are transformed accordingly.\n\nBy expressing the rigid body dynamics with the inertial parameters (drive train inertia, mass, first and second moment of mass) and by using a linear friction model, (\\ref{eq:model_equation1}) can be expressed in a linear form \\cite{Khalil.2006}.\n%\nThis regressor form\n%\n\\begin{equation}\n\\boldsymbol{\\tau}\n=\n\\boldsymbol{X}'(\\boldsymbol{q}, \\dot{\\boldsymbol{q}},\\ddot{\\boldsymbol{q}}) \\boldsymbol{\\theta}'\n=\n\\boldsymbol{X}(\\boldsymbol{q}, \\dot{\\boldsymbol{q}},\\ddot{\\boldsymbol{q}}) \\boldsymbol{\\theta}\n\\label{eq:model_regressor}\n\\end{equation}\n%\nwith regression matrix $\\boldsymbol{X}$ and parameter vector $\\boldsymbol{\\theta}$\ncan be given with a full set of parameters (on the left hand side, noted with a dash) or in a parameter minimal form (right hand side).\nOnly the latter form of the parameters can be identified within one identification cycle.\nThe general model $\\boldsymbol{X}'$/$\\boldsymbol{\\theta}'$ uses 66 parameters for the rigid body dynamics.\nFor each of the six joints two additional parameters represent the Coulomb and viscous friction.\n\nThe right hand side of (\\ref{eq:model_regressor}) expresses the minimal parametric model with 23 base inertial parameters.\nThe chosen parameter vector $\\boldsymbol{\\theta}$ to be identified therefore contains 35 entries and is shown in appendix \\ref{sec:MinparamVector}.\n%\nSince some of the robot links possess symmetries, assumptions about their center of mass and products of inertia were made.\nFurther, a differential gear couples joints 5 and 6, similar to the robot example in \\cite{M.Gautier.1995}.\nThis prevents the use of the direct determination of the base inertial parameters with the geometric approach from \\cite{Khalil.2006}.\nInstead, a purely symbolic approach is chosen: the relation $\\boldsymbol{\\theta}=\\boldsymbol{K} \\boldsymbol{\\theta}'$ leads to a linear system of equations $\\boldsymbol{X}' = \\boldsymbol{X}'\\boldsymbol{K}$.\nIt is solved symbolically for the unknown $\\boldsymbol{K}$ with the computer algebra system \\textsc{Maple}, leading to the base parameter formulation $\\boldsymbol{X}$/$\\boldsymbol{\\theta}$.\nFor the implementation the regressor matrix of the energy instead of the dynamics is used, following \\cite{M.Gautier.1995, Khalil.2006}.", "meta": {"hexsha": "b2b2da5e8d332cd98dd7d49e672c5bd7a6694e36", "size": 3647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/Chapters/Theoretical_Background/Modeling/Modeling.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/Modeling/Modeling.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/Modeling/Modeling.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": 67.537037037, "max_line_length": 290, "alphanum_fraction": 0.7611735673, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7185943865443349, "lm_q1q2_score": 0.6481151276846555}}
{"text": "%!TEX root = ../TTT4150-Summary.tex\n\\section{Position, velocity, and time (PVT) estimation}\n\n\\subsection{Position estimation with pseudoranges}\nThe pseudorange measurement from satellite $k$ after correction is\n\\begin{equation}\\label{eq:pseudorange}\n    \\rho_c^{(k)} = r^{(k)} + c \\cdot \\delta t_u + \\tilde{\\epsilon}_\\rho^{(k)}\n\\end{equation}\nwhere $\\delta t_u$ is the user clock bias, and $\\tilde{\\epsilon}_\\rho^{(k)}$ is the combined effect of residual errors. The position of the user at the time of measurement is\n\\begin{equation}\n    \\V{x} = (x, y, z)\n\\end{equation}\nand the position of satellite $k$ at signal transmission time is\n\\begin{equation}\n    \\V{x}^{(k)} = \\left( x^{(k)}, y^{(k)}, z^{(k)} \\right).\n\\end{equation}\nThe user-to-satellite range is\n\\begin{equation}\n    r^{(k)} = \\norm{\\V{x}^{(k)} - \\V{x}}\n\\end{equation}\nand \\eqref{eq:pseudorange} can be written as\n\\begin{equation}\n    \\rho_c^{(k)} = r^{(k)} + b + \\tilde{\\epsilon}_\\rho^{(k)}.\n\\end{equation}\n\nThe \\emph{geometry matrix} is\n\\begin{equation}\n    \\M{G}\n    =\n    \\begin{bmatrix}\n        (-\\M{1}^{(1)})\\T & 1     \\\\\n        \\vdots          & \\vdots \\\\\n        (-\\M{1}^{(K)})\\T & 1\n    \\end{bmatrix}\n\\end{equation}\nwhere $K$ is the number of satellites in view, and $\\M{1}^{(k)}$ is the line of sight unit vector from the initial user position estimate to satellite $k$.\n\n\\subsection{Dilution of precision (DOP)}\nDOP quantifies the effect of satellite geometry on the accuracy of positioning. A good geometry gives a low DOP value, and high accuracy. There are several variants, using $\\M{H} = \\left( \\M{G}\\T \\M{G} \\right)^{-1}$:\n\\begin{itemize}\n    \\item\n        Position dilution of precision\n        \\begin{equation}\n            \\mathrm{PDOP} = \\sqrt{H_{11} + H_{22} + H_{33}}\n        \\end{equation}\n    \\item\n        Time dilution of precision\n        \\begin{equation}\n            \\mathrm{TDOP} = \\sqrt{H_{44}}\n        \\end{equation}\n    \\item\n        Geometric dilution of precision\n        \\begin{equation}\n            \\mathrm{GDOP} = \\sqrt{H_{11} + H_{22} + H_{33} + H_{44}}\n        \\end{equation}\n    \\item\n        Horizontal dilution of precision\n        \\begin{equation}\n            \\mathrm{HDOP} = \\sqrt{H_{11} + H_{22}}\n        \\end{equation}\n    \\item\n        Vertical dilution of precision\n        \\begin{equation}\n            \\mathrm{VDOP} = \\sqrt{H_{33}}\n        \\end{equation}\n\\end{itemize}\n", "meta": {"hexsha": "327295222a43a313fbe6092658637804ecf7fcd0", "size": 2383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTT4150 Navigation systems/tex/6-pvt-estimation.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/6-pvt-estimation.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/6-pvt-estimation.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.5671641791, "max_line_length": 216, "alphanum_fraction": 0.6076374318, "num_tokens": 782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6481123462928019}}
{"text": "\\subsection{Minimization algorithm}\n\\label{minimization}\n\nIn this thesis, many data treatment approaches needed efficient nonlinear\nminimization algorithm (background subtraction, estimation of band intensities,\nestimation of parameters of chemical model from spectral series).\nThe Levenberg-Marquardt method\n\\parencite{Marquardt1963}\nwas used as a basis for the minimization algorithm used in this thesis, and\nslight modifications were applied to improve its performance.\n\nThe Levenberg-Marquardt method is based on Newton method where\nthe function $f(\\vec{a})$ which needs to be minimized is approximated by its\nTaylor series around $\\vec{a_\\text{cur}}$ point\n\\begin{align*}\n\tf(\\vec{a}) =& f(\\vec{a}_\\text{cur})\n\t\t+ \\sum_k \\left.\\frac{\\partial{}f}{\\partial{}a_k}\\right\n\t\t\t\\rvert_{\\vec{a}_\\text{cur}}(a_k - a_{k,\\text{cur}})\\\\\n\t\t&+ \\sum_{k,l} \\left.\\frac{\n\t\t\t\\partial^2f\n\t\t}{\n\t\t\t\\partial{}a_k\\partial{}a_l\n\t\t}\\right\\rvert_{\\vec{a}_\\text{cur}}\n\t\t(a_k - a_{k,\\text{cur}})(a_l - a_{l,\\text{cur}})\n\t\t+ \\dots,\n\\end{align*}\nwhich can be written as a quadratic form\n\\begin{equation}\n\t\\chi^2(\\vec{a}) \\approx\n\t\t\\gamma\n\t\t- \\vec{d}\\cdot\\vec{a}\n\t\t+ \\frac{1}{2}\\vec{a}\\cdot{}\\mat{D}\\cdot\\vec{a},\n\t\\label{\\eqnlabel{minimization:chi_approx}}\n\\end{equation}\nwhere $\\vec{d}$ is an $M$ vector, $\\mat{D}$ is an $M\\times{}M$ matrix, and\n$\\chi^2(\\vec{a})$ is chi-square function\n\\begin{equation*}\n\t\\chi^2(\\vec{a}) \\equiv \\sum_{i=1}^N\\left(\n\t\t\t\\frac{y_i - y(x_i;\\vec{a})}{\\sigma_i}\n\t\\right)^2,\n\\end{equation*}\nwhere $y_i$ are data points from the measured spectrum,\n$y(x_i;\\vec{a})$ are values of the model at these data points and\n$\\sigma_i$ are standard deviations of measured points $y_i$.\n\nIf\n\\eqnref{minimization:chi_approx}\nis a good approximation of the $\\chi^2(\\vec{a})$, the minimum can be found\ndirectly by adjusting the currently estimated parameters $\\vec{a}_\\text{cur}$\nby\n\\begin{equation}\n\t\\vec{a}_\\text{min} = \\vec{a}_\\text{cur}\n\t\t+ \\mat{D}^{-1}\\cdot(-\\vec{\\nabla}\\chi^2(\\vec{a}_\\text{cur})).\n\t\\label{\\eqnlabel{minimization:newton_min}}\n\\end{equation}\n\nOn the other hand, if\n\\eqnref{minimization:chi_approx}\ndoes not locally approximate the shape of $\\chi^2(\\vec{a})$ well, the steepest\ndescend method instead of the above described Newton method can be used for\nconvergence to the minimum\n\\begin{equation}\n\ta_\\text{min} = a_\\text{cur} - k\\vec{\\nabla}\\chi^2(\\vec{a_\\text{cur}}),\n\t\\label{\\eqnlabel{minimization:gradient_min}}\n\\end{equation}\nwhere $k$ needs to be a sufficiently small constant.\n\nLet us calculate the partial derivatives needed in terms from\n\\eqnref{minimization:newton_min} and \\eqnref{minimization:gradient_min}:\n\\begin{align*}\n\t\\frac{\\partial\\chi^2}{\\partial{}a_k} &= -2\\sum_{i=1}^N{\n\t\t\\frac{y_i - y(x_i;\\vec{a})}{\\sigma_i^2}\n\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_k}\n\t},\\\\\n\t\\frac{\\partial^2\\chi^2}{\\partial{}a_k\\partial{}a_l} &= 2\\sum_{i=1}^N{\n\t\t\\frac{1}{\\sigma_i^2}\\left[\n\t\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_k}\n\t\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_l}\n\t\t\t- [y_i - y(x_i;\\vec{a})]\n\t\t\t\t\\frac{\\partial^2{}y(x_i;\\vec{a})}{\\partial{}a_k\\partial{}a_l}\n\t\t\\right]\n\t},\n\\end{align*}\nwhere the second term in the second equation can be neglected because the\nsummation over all spectral points $y_i$ is equal to 0 if the\n$y(x_i;\\vec{a})$ models $y_i$ well. Therefore the simplified formula for\nHessian can be written as\n\\begin{equation*}\n\t\\frac{\\partial^2\\chi^2}{\\partial{}a_k\\partial{}a_l} = 2\\sum_{i=1}^N{\n\t\t\\frac{1}{\\sigma_i^2}\n\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_k}\n\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_l}\n\t}.\n\\end{equation*}\nIt can be seen that this approximation of Hessian does not need second\nderivatives of $\\chi^2(\\vec{a})$ and can be written as the product of two\nJacobians $\\mat{J}$\n\\begin{align*}\n\t\\mat{J} &=\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{\\partial{}y(x_1;\\vec{a})}{\\partial{}a_1} & \\cdots & \\frac{\\partial{}y(x_1;\\vec{a})}{\\partial{}a_M} \\\\\n\t\t\t\\vdots                                         & \\ddots & \\vdots \\\\\n\t\t\t\\frac{\\partial{}y(x_N;\\vec{a})}{\\partial{}a_1} & \\cdots & \\frac{\\partial{}y(x_N;\\vec{a})}{\\partial{}a_M}\n\t\t\\end{pmatrix}\\\\\n\t\\mat{W} &=\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{\\sigma_1^2} \\\\\n\t\t\t& \\ddots \\\\\n\t\t\t&& \\frac{1}{\\sigma_N^2}\n\t\t\\end{pmatrix}\\\\\n\t[\\alpha] &= \\mat{J}^\\mathsf{T}(\\mat{W}\\mat{J}).\n\\end{align*}\n\nLet us introduce substitution by defining\n\\begin{align}\n\t\\beta_k &\\equiv -\\frac{1}{2}\\frac{\\partial\\chi^2}{\\partial{}a_k}\n\t\t= \\sum_{i=1}^N{\n\t\t\t\\frac{y_i - y(x_i;\\vec{a})}{\\sigma_i^2}\n\t\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_k}\n\t\t}\n\t\t\\label{\\eqnlabel{minimization:beta}}\\\\\n\t\\alpha_{kl} &\\equiv \\frac{1}{2}\n\t\t\\frac{\\partial^2\\chi^2}{\\partial{}a_k\\partial{}a_l}\n\t\t= \\sum_{i=1}^N{\n\t\t\t\\frac{1}{\\sigma_i^2}\n\t\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_k}\n\t\t\t\\frac{\\partial{}y(x_i;\\vec{a})}{\\partial{}a_l}\n\t\t\t\\label{\\eqnlabel{minimization:alpha}}\n\t\t}\n\\end{align}\nand rewrite equations\n\\cref{%\n\t\\eqnlabel{minimization:newton_min},%\n\t\\eqnlabel{minimization:gradient_min}%\n}\nto forms which are defining the step towards the minimum $\\text{\\g{d}}a_l$\n\\begin{align}\n\t\\sum_{l=1}^N\\alpha_{kl}\\text{\\g{d}}a_l &= \\beta_k,\n\t\\label{\\eqnlabel{minimization:newton_delta}}\\\\\n\t\\text{\\g{d}}a_l &= k\\cdot\\beta_l,\n\t\\label{\\eqnlabel{minimization:gradient_delta}}\n\\end{align}\nwhere the matrix $[\\alpha]$ which is equal to one-half times the Hessian\nmatrix, is usually called the \\emph{curvature matrix}.\n\nMarquardt combined the\n\\cref{%\n\t\\eqnlabel{minimization:newton_delta},%\n\t\\eqnlabel{minimization:gradient_delta}%\n},\ntogether in one equation\n\\begin{equation}\n\t\\sum_{l=1}^N\\alpha'_{kl}\\text{\\g{d}}a_l = \\beta_k,\n\t\\label{\\eqnlabel{minimization:lm}}\n\\end{equation}\nwith\n\\begin{equation*}\n\t\\alpha'_{kl} = \\alpha_{kl}(1+\\text{\\g{d}}_{kl}\\lambda),\n\\end{equation*}\nwhere $\\text{\\g{d}}_{kl}$ is Kronecker delta (equal 1 if $k = l$ and 0\notherwise) and $\\lambda$ is damping factor.\nThe new $\\alpha'_{kl}$ is diagonally dominant with large $\\lambda$ and behaves\nlike the gradient method and is equal to $\\alpha_{kl}$ for small $\\lambda$ and\nbehaves like the Newton method.\n\nThe only unknown is an estimation of the damping factor $\\lambda$.\n\\textcite{Marquardt1963}\nsuggested a heuristic for its computation using an additional parameter\ncalled multiplication factor $\\mu$ and supposing initial guess of parameters $\\vec{a}$\nand $\\lambda = \\lambda_0$:\n\\begin{docenum}\n\t\\item Estimate $\\chi^2(\\vec{a})$.\n\t\\item Solve the \\eqnref{minimization:lm} for $\\text{\\g{d}}\\vec{a}$ and\n\t\tevaluate $\\chi^2(\\vec{a} + \\text{\\g{d}}\\vec{a})$.\n\t\t\\label{enum:minimization:lm_steps:item:solve}\n\t\\item If $\\chi^2(\\vec{a} + \\text{\\g{d}}\\vec{a}) \\geq \\chi^2(\\vec{a})$ update\n\t\t$\\lambda$ to $\\lambda\\cdot\\mu$ and go to\n\t\t\\cref{enum:minimization:lm_steps:item:solve}.\n\t\tIt means that you are probably far from the minimum so switch from Newton\n\t\tto gradient method with large jump.\n\t\\item If $\\chi^2(\\vec{a} + \\text{\\g{d}}\\vec{a}) < \\chi^2(\\vec{a})$ update\n\t\t$\\lambda$ to $\\lambda/\\mu$, update the trial solution $\\vec{a}$ to\n\t\t$\\vec{a} + \\text{\\g{d}}\\vec{a}$ and go to\n\t\t\\cref{enum:minimization:lm_steps:item:solve}.\n\t\tIt means that you are probably near to the minimum so try to jump directly\n\t\tto the minimum approximated by quadratic function as per Newton method.\n\\end{docenum}\n\nWe enhanced the damping factor update algorithm for search in a wider range and\nboth directions because the above-proposed method was susceptible to falling\ninto a local minimum.\nThe items 3 and 4 update of lambda searched larger region of $\\mu^k$ where,\nfor example, $k \\in \\{-10, -9, \\dots, 9, 10\\}$.\nIt was also found that it is more stable, especially for the cases with more\ncomplicated models $y(x;\\vec{a})$, to calculate Jacobian $\\mat{J}$ numerically\nthan using analytic derivatives because of the numeric instability of the\nsolution.\n\nThis regression algorithm was programmed using the MATLAB programming\nenvironment\n\\parencite{Matlab}\nand used throughout many different applications in this work.\nThe algorithm was also modified so that it was possible to specify\ndifferent weight functions than least squares, for example, penalize positive\ndifferences as was then used in\n\\cref{background}.\n\\\\\n", "meta": {"hexsha": "83a92d8879e0ea0b7b4289bcf0f005d5d653e9bb", "size": 8116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/results_and_discussion/minimization.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/minimization.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/minimization.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.0192307692, "max_line_length": 110, "alphanum_fraction": 0.6929521932, "num_tokens": 2828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6481123325625995}}
{"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\\usepackage{cancel}\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 XXII 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{Green's Theorem $-$ 16.4}\n\nFor this theorem, let $C$ be a curve that is:\n\n\\begin{enumerate}\n\n  \\item positively oriented (moving counterclockwise)\n\n  \\item piecewise smooth\n\n  \\item simple\n\n  \\item closed\n\n\\end{enumerate}\n\n$D$ is the region enclosed by the curve.\n\nIf $P$ and $Q$ have continuous first-order partial derivatives on $D$, then:\n\n$$\\int_C P\\,dx+Q\\,dy=\\iint_D \\left(\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}\\right)\\,dA$$\n\nFor Green's Theorem, $D$ must have boundaries.\n\nNotation (If $C$ is closed):\n\n$$\\int_C P\\,dx+Q\\,dy=\\oint_C P\\,dx+Q\\,dy$$\n\nIf $\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}=1$, then Green's theorem yields the area of the region $D$:\n\n$$\\iint_D 1\\,dA=A(D)$$\n\n\\end{document}\n\n", "meta": {"hexsha": "a8623f70ce46c67fdf8149dac062fde62fc7dbbb", "size": 2193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture22.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/Lecture22.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/Lecture22.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": 24.3666666667, "max_line_length": 188, "alphanum_fraction": 0.5804833561, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.6480384562970615}}
{"text": "\\section{Attribute Grammars}\n\n\\subsection{Left-Right attributes}\nGiven a rule of type $A_0 \\rarr A_1A_2\\ldots$\n\n\\begin{description}\n    \\item[Left attribute] $\\sigma_0 = f(\\ldots)$ associated to $A_0$\n    \\item[Right attribute] $\\delta_i = f(\\ldots), i \\ge 1$, associated to $A_i$\n\\end{description}\n\nAn attribute cannot be both left and right.\n\n\\subsection{Dependence Graph}\n\nGiven a rule $p$, its dependence graph $dep_p$ is a directed graph:\n\\begin{itemize}\n    \\item Nodes are the attributes\n    \\item There is an arc from every argument to the result\n    \\item Left attributes are on the left, right to the right\n\\end{itemize}\n\nIf the dependence graph is acyclic there exists a set of attribute values. A grammar is \\textbf{loop-free} if the dependence graph is always acyclic.\n\n\\subsection{Depth-First visit}\n\\begin{itemize}\n    \\item Start from the root\n    \\item Visit the child nodes in some specified order\n    \\item Foreach subtree $t_N$ rooted at node $N$ :\n    \\begin{itemize}\n        \\item Before visiting $t_N$ compute the right attributes of $N$ and pass them down to the visit\n        \\item After visiting $t_N$ compute the left attributes using the return value of the visit\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{Depth-First Visit Conditions (one-sweep)}\n\\begin{itemize}\n    \\item The graph $dep_p$ has no circuit\n    \\item In $dep_p$ there exists no path from a left attribute to a right attribute of the same node\n    \\item In $dep_p$ there exists no arc from a left attribute of the father to a right attribute of any child\n    \\item There are no circuits in $sibl_p$ graph\n\\end{itemize}\n\nThere is an arc $D_i \\rarr D_j$ in $sibl_p$ iff in $dep_p$ there is an arc $\\alpha_i \\rarr \\beta_j$ with $\\alpha_i \\in \\text{attr}(D_i)$ and $\\beta_j \\in \\text{attr}(D_j)$.\n\n\\subsection{One-Sweep Evaluator}\nThere is a procedure for each nonterminal, its parameters are the subtree rooted at the nonterminal and the right attributes of the root; it visits the subtree and returns the left attributes of the root.\n\nFor the rule $p: D_0 \\rarr D_1D_2\\ldots D_r$\n\\begin{itemize}\n    \\item Choose a Topological Order of Siblings $TOS$ compatible with $sibl_p$\n    \\item For each symbol $D_i, i>0$ choose a topological order of the right attributes $TOR$\n    \\item Choose a topological order of the left attributes of $D_0$\n\\end{itemize}\n\n\\subsection{Condition L}\nUsed to embed semantic evaluator inside recursive descent syntax parser.\n\\begin{itemize}\n    \\item Support syntax is of type LL(k)\n    \\item Depth-First Visit Conditions\n    \\item The natural order ($D_1, D_2, \\ldots$) is a valid TOS is $sibl_p$ (i.e. no arc $D_j\\rarr D_i$ with $j>i$)\n\\end{itemize}\n", "meta": {"hexsha": "bcc2138ce7d9d4c4aa0c55ff3430599539568d40", "size": 2673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "syntax/attribute.tex", "max_stars_repo_name": "Kakasinho/FLC-cheatsheet", "max_stars_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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/attribute.tex", "max_issues_repo_name": "Kakasinho/FLC-cheatsheet", "max_issues_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "max_issues_repo_licenses": ["MIT"], "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/attribute.tex", "max_forks_repo_name": "Kakasinho/FLC-cheatsheet", "max_forks_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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.1129032258, "max_line_length": 204, "alphanum_fraction": 0.7306397306, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6480384513407936}}
{"text": "\\subsection{States, messages, representatives}\n\nThe full-node protocol states are {\\em sets} of messages,\neach message being a triple $(c, v, j)$, where:\n\\begin{itemize}\n    \\item $c$ is a (proposed) consensus value;\n    \\item $v$ identifies the message sender;\n    \\item $j$, the justification, is the {\\em protocol state} seen by the sender\n        at the time of message sending.\n\\end{itemize}\n\nThere are two technical difficulties with the above definition:\n\\begin{itemize}\n    \\item States and messages are mutually recursive: states are sets of messages, each containing a state;\n    \\item Message ordering should not matter\n\\end{itemize}\n\nTo solve the first issue, we choose to postpone the definition of messages for now and first define states inductively as follows:\n\n\\begin{coq}\nInductive state : Type :=\n  | Empty : state\n  | Next : C ->  V -> state -> state -> state.\n\\end{coq}\n\nThis definition says that a state can be built by extending an existing state\ngiven a consensus value \\verb|C|, a validator \\verb|V|, and another state representing\nthe justification. To clarify that the three are the components of a message, we introduce the following notation for \\verb\"Next\":\n\n\\begin{coq}\nNotation \"'add' ( c , v , j ) 'to' sigma\" :=\n  (Next c v j sigma)\n  (at level 20).\n\\end{coq}\n\nThis definition addresses the first difficulty mentioned above by capturing the recursive nature of states.\n\nThe second issue critical to the notion of state equality. Defining an equivalence between states which disregards message ordering is possible but non-trivial: the definition would itself need to be recursive, as it requires an equivalence\non messages, which in turn is defined in terms of the same state equivalence.\n\nTo circumvent the hindrance of working with mutually recursive state equality, we instead took the approach of using canonical representatives for states,\nwhich we call LocallySorted states, on which we express state equality as syntactic equality in Coq.  Although this definition is still recursive, it is easier to express and to work with than with the former equivalence because it is defined in terms of a single state.\n\nTo define sorted states, we need to be able to compare messages,\nwhich amounts to defining a total order relation on states.\nThis can be defined as a lexicographic ordering on the state seen as a list\nof messages, tweaked slightly to perform recursion in order to compare justifications:\n\\begin{coq}\nFixpoint state_compare (sigma1 sigma2 : state) : comparison :=\n  match sigma1, sigma2 with\n  | Empty, Empty => Eq\n  | Empty, _ => Lt\n  | _, Empty => Gt\n  | add (c1, v1, j1) to sigma1, add (c2, v2, j2) to sigma2 =>\n    match compare c1 c2 with\n    | Eq =>\n      match compare v1 v2 with\n      | Eq =>\n        match state_compare j1 j2 with\n        | Eq => state_compare sigma1 sigma2\n        | cmp_j => cmp_j\n        end\n      | cmp_v => cmp_v\n      end\n    | cmp_c => cmp_c\n    end\n  end.\n\\end{coq}\n\nNote that defining this ordering requires that there exist orderings on\nconsensus values and validators, but these can be any orderings,\nand a total ordering is guaranteed to exists for any set in set theory\nby the axiom of choice \\cite{Gonzalez}. The existence of these orderings is reflected in our \\verb|StrictlyComparable| types for consensus values and validators.\n\nThis ordering naturally induces an ordering on messages, and thus allows us\nto define the notion of a \\verb|LocallySorted| state, i.e., one in which\neach message is smaller than the next and all justifications are themselves\n\\verb|LocallySorted|.\n\nChoosing \\verb|LocallySorted| states as representatives for states thus reducing the equality testing between states to syntactic equality checking.\n\nProtocol states are defined by means of an inductive predicate on states as follows:\n\\begin{coq}\nInductive protocol_state : state -> Prop :=\n  | protocol_state_empty : protocol_state Empty\n  | protocol_state_next\n         : forall s j\n         , protocol_state s\n        -> protocol_state j\n        -> incl_messages j s\n        -> forall c v\n         , valid_estimate c j\n        -> not_heavy (add_in_sorted_fn (c,v,j) s)\n        -> protocol_state (add_in_sorted_fn (c,v,j) s).\n\\end{coq}\n\nThe above definition reads as:\n\\begin{itemize}\n    \\item a protocol state is either empty; or\n    \\item it can be obtained from an existing protocol state $s$ by extending\n        it with a message $(c, v, j)$ such that:\n        \\begin{itemize}\n            \\item $j$ is a protocol state included in $s$;\n            \\item $c$ is a consensus value which the estimator agrees on for $j$;\n            \\item adding $(c,v,j)$ to $s$ does not exceed the fault tolerance threshold.\n        \\end{itemize}\n\\end{itemize}", "meta": {"hexsha": "9deec561f37e58f3a6984c6e9014f9a1bab1b7f8", "size": 4719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/full.tex", "max_stars_repo_name": "runtimeverification/casper-cbc-proofs", "max_stars_repo_head_hexsha": "8c4985f0921fea0a38c05e72a47364471164ab72", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-16T15:57:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-23T11:21:07.000Z", "max_issues_repo_path": "report/full.tex", "max_issues_repo_name": "runtimeverification/casper-cbc-proofs", "max_issues_repo_head_hexsha": "8c4985f0921fea0a38c05e72a47364471164ab72", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-11-26T09:22:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-02T10:00:11.000Z", "max_forks_repo_path": "report/full.tex", "max_forks_repo_name": "runtimeverification/casper-cbc-proofs", "max_forks_repo_head_hexsha": "8c4985f0921fea0a38c05e72a47364471164ab72", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-12-17T07:48:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T08:51:55.000Z", "avg_line_length": 44.1028037383, "max_line_length": 270, "alphanum_fraction": 0.7253655435, "num_tokens": 1140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6479054671046984}}
{"text": "\\graphicspath{ {./img/TheFEM/} }\n\\chapter{Review of Boundary Value Problems}\n\n\\section{Boundary value problems}\nIn this section we will define a general initial boundary value problem (I-BVP). In the first part we will introduce the differential formulation given in terms of a set of governing equations and properly specified boundary conditions. The resulting equations are obtained after using a generalized balance law. Following this classical and well known approach we formally re-state these equations in the so-called strong form. Subsequently we re-write and prove an equivalent form of the balance law in the form of an integral representation highly friendly for a numerical solution. Since in the integral description of the problem the order of the derivatives in the field functions decreases by one, the resulting statement is called a weak formulation. \n\n\\subsection{Differential formulation-Generalized balance law}\nLet $\\dd{S}$ be a differential surface element, $\\dd{V}$ a differential volume element, $u(\\vb{x},t)$ a scalar (or vector) function of space and time. The flux or rate of flow of the quantity $u(\\vb x, t)$ through $\\dd{S}$ at time $t$ is defined like\n\\[p(\\vb x)\\grad u \\cdot \\hat n \\dd{S} \\enspace ,\\]\nwhere $p(\\vb x)$ is a positive function, assumed known and time independent. Similarly, the time rate of change of $u(\\vb x, t)$ in an element $\\dd{V}$ is given by\n\\[\\rho (\\vb x)\\pdv{u}{t} \\dd{V} \\enspace ,\\]\nwhere once again $\\rho (\\vb x)$ is a known, given, time independent positive function. Additional effects occurring in the element $\\dd{V}$ at the time time can be expressed like\n\\[H(\\vb x, t)\\dd{V} \\equiv  - q(\\vb x)u(\\vb x, t) + \\hat F(\\vb x,t)\\]\nwhere $\\hat F(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t)$. In the above the term $q u$ represent internal effects due to changes proportional to $u$ while $\\hat F(\\vb x, t)$ are other external influences in the medium.\n\nBalancing the internal and external changes yields\n\\[\\int\\limits_V \\rho (\\vb x)\\pdv{u}{t}\\dd{V} = \\int\\limits_S p(\\vb x)\\vb \\grad u \\cdot \\hat n\\dd{S}  + \\int\\limits_V H(\\vb x, t)\\dd{V} \\enspace ,\\]\nor equivalently\n\\[\\int\\limits_V \\rho (\\vb x)\\pdv{u}{t}\\dd{V} = \\int\\limits_S p(\\vb x)\\vb \\grad u \\cdot \\hat n\\dd{S}   - \\int\\limits_V q(\\vb x)u(\\vb x, t)\\dd{V}  + \\int\\limits_V \\rho (\\vb x)F(\\vb x, t)\\dd{V} \\enspace .\\]\n\nUsing the divergence theorem as\n\\[\\int\\limits_S p(\\vb x) \\grad u \\cdot \\hat n \\dd{S}  = \\int\\limits_V \\vb \\div  (p\\vb \\grad u)\\dd{V}\\]\nyields after substitution\n\\[\\int\\limits_V \\left[\\rho (\\vb x)\\pdv{u}{t} - \\div (p(\\vb x)\\grad u) + q(\\vb x)u(\\vb x, t) - \\rho (\\vb x)F(\\vb x, t)\\right]\\dd{V}  = 0\\]\nAssuming a continuous integrand, the arbitrariness of $V$ implies\n\\[\\rho (\\vb x)\\pdv{u}{t} - \\div(p(\\vb x)\\grad u) + q(\\vb x)u(\\vb x, t) - \\rho (\\vb x)F(\\vb x, t) = 0\\]\n\nLetting\n\\[\\mathcal{L} \\equiv  - \\div p(\\vb x)\\grad + q(\\vb x)\\]\nthe generalized set of partial differential equations can be written like\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:GenPDE}\n\\end{equation}\n\nAnd they are categorized as:\n\\begin{itemize}\n    \\item Hyperbolic;\n    \\[\\rho(\\vb x) \\pdv[2]{u(\\vb x, t)}{t} + \\mathcal{L}u(\\vb x,t) = 0\\]\n\n    \\item Parabolic; and\n    \\[\\rho(\\vb x) \\pdv{u(\\vb x,t)}{t} + \\mathcal{L}u(\\vb x, t) = 0\\]\n\n    \\item Elliptic\n    \\[\\mathcal{L}u(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t) \\enspace .\\]\n\\end{itemize}\n\nIt can be shown that $\\mathcal{L}$ satisfies the \\emph{symmetry} condition\n\\[\\int\\limits_V \\mathcal{L}(u)v\\dd{V} =  \\int\\limits_V \\mathcal{L}(v)u \\dd{V}\\]\nand positive definiteness \\cite{book:sepulveda_fismat, book:arfken}\n\\[\\int\\limits_V \\mathcal{L}(u)u\\dd{V}  > 0, \\quad \\forall u \\enspace .\\]\n\n\\subsection{Strong form}\nGiven $\\rho(\\vb x)$, $q(\\vb x)$, $p(\\vb x)$, $F(\\vb x, t)$ and $\\bar u$ find $u(\\vb x , t):V \\to \\mathbb{R}$ such:\n\\[\\rho(\\vb x) \\pdv{u}{t} - \\div \\left[p(\\vb x) \\grad u\\right] + q(\\vb x) u(\\vb x, t) - \\rho(\\vb x) F(\\vb x, t) = 0 \\quad \\forall \\vb x \\in V \\]\nand\n\\begin{align*}\n    &u = \\bar u \\quad \\forall \\vb x \\in S_u\\\\\n    &p(\\vb x)u_{,i} \\hat n_i= B(\\vb x,t)\\quad \\forall \\vb x \\in  S_t \\enspace .\n\\end{align*}\n\n\nIn the FEM we will look for approximate solutions to $u$ subject to the following conditions:\n\\[u = \\bar u \\quad \\forall \\vb x \\in S_u \\quad \\text{(Essential boundary conditions)}\\] \nand\n\\[\\int\\limits_S \\left(\\pdv{u}{x_j}\\right)^2 \\dd{S} < \\infty \\enspace ,\\]\nwhich corresponds to the functions being square integrable. We will denote this space by $\\mathbb{H}$ .\n\nThe space of functions satisfying the above two conditions will be denoted by $\\zeta$ and termed the space of trial functions, formally defined like:\n\\[\\zeta  = \\left\\{ u \\mid u \\in \\mathbb{H},u = \\bar u \\quad \\forall\\vb x  \\in S_u \\right\\}\\]\n\nOn the other hand, to validate (or test) the correctness of the approximated or proposed trial functions $u$ it is also necessary to introduce test functions $w$ which are arbitrary except that they satisfy the following conditions:\n\\[w = 0\\quad \\forall \\vb x \\in S_u\\] \nand\n\\[\\int\\limits_S \\left(\\pdv{w}{x_j}\\right)^2 \\dd{S} < \\infty \\enspace ,\\]\nwhich corresponds to the functions being square integrable. The space of functions satisfying the above two conditions will be denoted by $\\pounds$ and termed the space of test functions, formally defined like:\n\\[\\pounds  = \\left\\{w \\mid w \\in \\mathbb{H},w = 0 \\quad \\forall \\vb x \\in S_u\\right\\}\\]\n\n\\subsection{Weak form}\nGiven $\\rho(\\vb x)$, $q(\\vb x)$, $p(\\vb x)$, $F(\\vb x, t)$ and $\\bar u$ find $u(\\vb x , t):V \\to \\mathbb{R}$ and $\\forall w \\in \\pounds$ such:\n\\begin{align*}\n\\int\\limits_V p(\\vb x) u_{,i}\\, w_{,i}\\dd{V} - \\int\\limits_{S_t} B(\\vb x, t)w \\dd{S}  + \\int\\limits_V q(\\vb x)u(\\vb x, t)w\\dd{V}  &+ \\int\\limits_V \\rho(\\vb x)\\pdv{u}{t}w \\dd{V} \\\\& - \\int\\limits_V \\rho(\\vb x) F(\\vb x, t)w\\dd{V} = 0\n\\end{align*}\nand\n\\[u = \\bar u\\quad \\forall\\vb x \\in S_u \\enspace .\\]\n\n\\subsection{Equivalence between the strong and weak forms}\n\\begin{multline}\n    -\\int\\limits_V [p(\\vb x)u_{,i}]_{,i}w \\dd{V} + \\int\\limits_{S_t} [p(\\vb x)u_{,i}] \\hat n_i w\\dd{S} - \\int\\limits_{S_t} B(\\vb x, t)w\\dd{S}\\\\\n    + \\int\\limits_V q(\\vb x)u(\\vb x, t)w \\dd{V}  + \\int\\limits_V \\rho(\\vec x)\\pdv{u}{t}w\\dd{V} - \\int\\limits_V \\rho(\\vb x)F(\\vb x, t)w\\dd{V} = 0 \n\\end{multline}\n\nGrouping together common terms yields\n\\begin{align*}\n&\\int\\limits_V \\left\\{\\rho(\\vb x)\\pdv{u}{t} - [p(\\vb x)u_{,i}]_{,i} + q(\\vb x)u(\\vb x, t) - \\rho(\\vb x)F(\\vb x, t)\\right\\} w\\dd{V}\\\\\n&+ \\int \\limits_{S_t} \\left\\{[p(\\vb x)u_{,i}]\\hat n_i - B(\\vb x, t) \\right\\} w\\dd{S} = 0\n\\end{align*}\nfrom which\n\\[\\rho(\\vb x)\\pdv{u}{t} - [p(\\vb x)u_{,i}]_{,i} + q(\\vb x)u(\\vb x, t) - \\rho(\\vb x)F(\\vb x, t) = 0\\]\nand\n\\[p(\\vb x)u_{,i}\\hat n_i = B(\\vb x, t)  \\quad\\forall \\vb x \\in S_t \\enspace .\\]\n\n\n\\section{Brief review of the linearized theory of elasticity model}\nHere we present a brief description of the boundary value problem governing the response of an elastic body. For a full discussion of the model and its mathematical aspects the reader is referred to \\cite{shames1997elastic}.\n\nThe governing equations (in terms of stresses) stem from the principle of conservation of linear momentum and conservation of moment of linear momentum. The former leads to a set of 3 partial differential equations in the components of the stress tensor while the latter leads to the symmetries in the stress tensor.\n\\begin{equation} \\label{eq:pde}\n\\begin{aligned}\n&\\sigma_{ij,j} + {f_i} = \\rho\\ddot{u}_i \\quad \\forall\\ \\vb{x} \\in V,\\, t \\in \\mathbb{R}^{+}\\\\\n&\\sigma_{ij}=\\sigma _{ji}.\n\\end{aligned} \n\\end{equation}\n\nIn \\cref{eq:pde} $\\sigma_{ij}$ is the stress tensor; $f_i$ is the vector of body forces; and $u_i$ is the displacements vector.\n\nDenoting the tractions vector associated with a surface with normal direction $\\hat{n}_{j}$ by $t_i^{\\hat n}$ we have the complete BVP as follows\n\\begin{equation} \\label{eq:bcs}\nt_i^{\\hat n} = \\sigma_{ij} \\hat{n}_{j} \\quad \\forall \\in \\vb{x} \\in S.\n\\end{equation}\n\n\\Cref{eq:pde} correspond to 6 equations with 12 unknowns (the 9 components of the stress tensor and the 3 components of the displacements vector ) and the system is undetermined. In order to have a solvable BVP we must introduce kinematic strain-displacement relations and a stress-strain law. In the case of infinitesimal theory of elasticity the strain-displacement relation is given by:\n\n\\begin{equation}\\label{eq:kin}\n\\varepsilon_{ij} = \\frac{1}{2}(u_{i,j} + u_{j,i})\n\\end{equation}\n\nwhere the term $\\epsilon_{ij}$ is the symmetric component of the displacements gradient tensor. The components of the strain tensor describe the distortions and changes in magnitude (volumetric changes) of the material point in the continuum model. Now the simplest stress-strain (constitutive) relationship is given by Hooke's law\\footnote{Despite the name of \\emph{law} used, this relation is not always valid, but is a good approximation for small strains.}\n\\begin{equation} \\label{eq:Hooke}\n\\sigma_{ij} = 2\\mu \\varepsilon_{ij} + \\lambda \\varepsilon_{kk}\\delta_{ij} \\enspace .\n\\end{equation}\n\nwhere $\\mu$ and $\\lambda$ are material constants. The problem involves now a total of 18 equations and 18 unknowns can be solved if subjected to properly specified boundary conditions.\n\n\\subsection*{Displacement formulation}\nSubstituting \\cref{eq:kin} in \\cref{eq:Hooke} and the result in \\cref{eq:pde} yields after some manipulation:\n\\begin{equation} \\label{eq:navier}\n(\\lambda  + \\mu)u_{j,ij} + \\mu u_{i,jj} + {f_i} = \\rho \\ddot{u}_i \\quad \\forall \\vb{x} \\in V,\\, t \\in \\mathbb{R}^{+}.\n\\end{equation}\n\nSince \\cref{eq:navier} ( simultaneously describing equilibrium, kinematic relations and constitutive response) is a second order equation governing the displacement field possible boundary conditions are in terms of the variable itself or its first oder derivatives. For a well-possed problem the following is a set of valid boundary conditions: \n\\begin{equation}\\label{eq:Wellbcs}\n\\begin{split}\n&t_i^{\\hat n} = \\sigma _{ij} \\hat n_{ij} \\quad \\forall\\ \\vb{x} \\in S_t\\\\\n& {u_i} = \\bar{u}_i \\quad \\forall \\vb x \\in S_u\n\\end{split}\n\\end{equation}\n\nand where ${S_t} \\cup {S_u} = S$ and ${S_t} \\cap {S_u} = \\emptyset $. \n\n\nIn the particular case in which $u_i$ is not a function of time, we obtain the static version of the BVP, i.e,\n\\begin{equation}\n\\begin{split}\n&\\left(\\lambda  + \\mu \\right)u_{j,ij} + \\mu u_{i,jj} + {f_i} = 0 \\quad \\forall \\vb{x} \\in V \\\\\n&t_i^{\\hat n} = \\sigma _{ij} \\hat n_{ij} \\quad \\forall\\ \\vb{x} \\in S_t\\\\\n& {u_i} = \\bar{u}_i \\quad \\forall \\vb x \\in S_u\n\\end{split}\n\\end{equation}\n\nNotice that the tractions BC \n\\[t_i^{\\hat n} = \\mu (u_{i,j} + u_{j,i}) \\hat{n}_j + \\lambda u_{k,k} \\delta_{ij}\\hat{n}_j \\enspace ,\\]\n\nactually involves first order displacements derivative and as such it is a Neumann boundary condition on $u_i$.\n\n\\subsection{Equivalence between strong and weak forms}\n\\subsubsection{Strong form}\nThe strong form corresponds to the differential formulation of the problem, it is denoted by $\\{ S \\}$ and it reads:\n\nGiven $f_i$, $t_i^{\\hat n}$ and ${\\bar u_i}$ find ${u_i}:V \\to \\mathbb{R}$ such:\n\\begin{equation} \\label{eq:navier_2}\n\\begin{split}\n&(\\lambda  + \\mu)u_{j,ij} + \\mu u_{i,jj} + f_i = 0 \\quad \\forall \\vb{x} \\in V \\\\\n&t_i^{\\hat n} = \\sigma _{ij} \\hat{n}_{ij} \\quad \\forall \\vb{x} \\in S_t\\\\\n&u_i = \\bar{u}_i \\quad \\forall \\vb{x} \\in S_u\n\\end{split}\n\\end{equation}\n\nIn \\cref{eq:navier_2} the boundary conditions specified by the traction vector $t_i^{\\hat n}$ correspond to the natural boundary conditions, while those specified in terms of the displacements vector $\\bar u_i$ represent the essential boundary conditions.\n\n\\begin{itemize}\n\\item We are interested in developing methods to obtain approximate solutions to $\\{S\\}$.\n\\item The FEM is formulated starting from a statement equivalent to $\\{ S \\}$ in which we use trial functions until certain prescribed conditions are met.\n\\item We will look for solutions $u_i$ subject to the following conditions:\n\\begin{align*}\n&u_i = \\bar u_i \\qquad \\text{in} \\qquad S_u\\\\\n&\\intL_S \\left(\\pdv{u_i}{x_j} \\right)^2 \\dd{S} < \\infty\n\\end{align*}\n\n\\end{itemize}\n\nThe first condition corresponds to the satisfaction of the essential boundary condition, while the second corresponds to the functions being square integrable. The space of functions satisfying the above two conditions is denoted by $\\varsigma$ and formally defined like\n\\[\\varsigma = \\left\\{u_i\\left| {u_i} \\in H, {u_i} = \\bar{u}_i \\in S_u \\right. \\right\\} \\enspace .\\]\n\nOn the other hand, in order to validate the introduced trial functions we also need testing functions $w_i$ also called in the FEM literature weighting or distribution functions. These functions are arbitrary apart from having to satisfy the following conditions:\n\\begin{align*}\n&w_i = 0 \\quad in \\quad {S_u}\\\\\n&\\intL_S \\left(\\pdv{w_i}{x_j}\\right)^2 \\dd{S} < \\infty\n\\end{align*}\n\nIn what follows we formally denote the space of these functions by $V$ and define it like\n\\[V = \\left\\{ w_i\\left| w_i \\in H, u_i = w_i=0 \\in S_u \\right. \\right\\} \\enspace .\\]\n\n\\subsubsection{Weak form}\nHere we will show that the equilibrium statement represented in the differential formulation can be described in alternative forms. In such description the continuity requirement for the trial functions is weaker than in the strong form leading to the term \"weak\" statement. Here this alternative representation will be denoted like $\\{W\\}$ and it reads;\n\nGiven $f_i$, $t_i^{\\hat n}$ and ${\\bar u_i}$ find ${u_i}:V \\to \\mathbb{R}$ and $\\forall {w_i} \\in V$ such:\n\\[\\intL_V \\sigma_{ij} w_{i,j}\\, \\dd{V} - \\intL_V f_i w_i\\, dV  - \\intL_{S_t} t_i^{\\hat n} w_i\\, \\dd{S} = 0\\]\n\n\\subsubsection*{Proof 1:}\nLet $u_i \\in \\varsigma $ be a solution to $\\{S\\}$ and let $w_i \\in V $. Forming the inner product of the equilibrium statement given in \\cref{eq:pde} with $w_i$ and forcing the integral over the domain to be zero we have\n\\[\\intL_V (\\sigma_{ij,j} + f_i ){w_i}\\, dV = 0 \\enspace ,\\]\nexpanding the terms in the integrand and integrating by parts the first term on the left we have\n\\begin{align*}\n&\\intL_V \\sigma _{ij,j} w_i\\, \\dd{V} + \\intL_V f_i w_i\\, \\dd{V} = 0 \\, ,\\\\\n& -\\intL_V w_{i,j} \\sigma _{ij}\\, \\dd{V}  + \\intL_S \\sigma _{ij} \\hat{n}_j w_i\\, \\dd{S}  + \\intL\\limits_V w_i f_i\\, \\dd{V} = 0\\, ,\n\\end{align*}\nsince $w_i \\in V$ it follows that $w_i = 0$ in $S_u$ from which\n\\begin{equation}\\label{eq:weak}\n\\intL_V \\sigma_{ij} w_{i,j}\\, \\dd{V} - \\intL_V f_i w_i\\, \\dd{V}  - \\intL_{S_t} t_i^{\\hat n} w_i\\, \\dd{S} = 0\\, .\n\\end{equation}\n\nNow, considering that $u_i$ is solution of the strong form $\\{S\\}$ it must satisfy $u_i = \\bar u_{i} \\quad \\in \\quad S_u$ and as a result $u_i \\in \\varsigma$. On the other hand, since $u_i$ satisfies \\cref{eq:weak} $\\forall {w_i} \\in V$ we have that $u_i$ satisfies the definition of weak solution specified in $\\{ W \\}$.\n\n\\subsubsection*{Proof 2:}\nLet $u_i$ be a solution of $\\{W\\}$ and thus $u_i \\in \\varsigma$ which means that\n\\[u_i = \\bar u_{i} \\quad \\in \\quad S_u\\]\nand that it satisfies\n\\[\\intL_V \\sigma _{ij} w_{i,j}\\, \\dd{V} - \\intL_V f_i w_i\\, \\dd{V} - \\intL_{S_t} t_i^n w_i\\, \\dd{S} = 0 \\enspace ,\\]\nintegrating by parts,\n\\[-\\intL_V \\sigma_{ij,j} w_i \\dd{V} + \\intL_S \\sigma_{ij} n_j w_i \\dd{S}  - \\intL_V f_i w_i \\dd{V} - \\intL_{S_t} {t_i^n} w_i \\dd{S} = 0\\]\n\nSince $w_i \\in V$ we have that $w_i=0$ in $S_u$ and therefore\n\\[\\intL_V w_i(\\sigma_{ij,j} + f_i) \\dd{V} + \\intL_{S_t} w_i( \\sigma_{ij} n_j - t_i^n ) \\dd{S} = 0 \\]\nfrom which\n\\begin{equation} \\label{equil_2}\n\\begin{split}\n&\\sigma_{ij,j} + f_i = 0 \\quad \\vb{x} \\in V \\\\\n&t_i^n = \\sigma_{ij} n_j \\quad \\forall \\vb{x} \\in S_t\\\\\n&{u_i} = \\bar{u}_i \\quad \\forall \\vb{x} \\in S_u\n\\end{split}\n\\end{equation}\n\nwhich is once again the strong form of the problem given in \\cref{eq:pde}.\n\n\\subsection{Simple wedge under self-equilibrated loads}\nConsider the double wedge of side $\\ell$ and internal angle $2 \\phi$ shown in \\cref{fig:WEDGE}. It is assumed to be contained in the $X-Y$ plane, with loading conditions satisfying a plane strain (or plane stress) idealization. The material is elastic with Lame constants $\\lambda$ and $\\mu$. The wedge is loaded by uniform tractions of intensity $S$ applied over its four faces in such a way that the wedge is self-equilibrated. We wish to find the closed-form elasticity solution for the stress, strain and displacement fields throughout the problem domain.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=7cm]{wedge.pdf}\n\\caption{2D Self-equilibrated wedge.}\n\\label{fig:WEDGE}\n\\end{figure}\n\nUnder plane strain conditions the general 3D stress equilibrium equations (see \\cref{eq:pde}) reduce to:\n\\begin{equation}\n\\begin{aligned}\n&\\pdv{\\sigma_{xx}}{x} + \\pdv{\\tau_{xy}}{y}=0\\\\\n&\\pdv{\\tau_{xy}}{x} + \\pdv{\\sigma_{yy}}{y}=0\n\\end{aligned}\n\\label{eq:equilibrium}\n\\end{equation}\nwhile the kinematic relation (\\cref{eq:kin}) reads\n\\begin{equation}\n\\begin{aligned}\n\\epsilon_{xx}& = \\pdv{u}{x}\\\\\n\\epsilon_{yy}& = \\pdv{v}{y}\\\\\n\\gamma_{xy}& = \\pdv{u}{y} + \\pdv{v}{x}\n\\end{aligned}\n\\label{eq:strain}\n\\end{equation}\nwhere $u$ and $v$ are the horizontal and vertical displacements respectively.\n\n\\subsubsection*{Stress field}\n\nThe stress field can be obtained by simple inspection from the traction boundary conditions prescribed over the inclined surfaces yielding\n\\begin{align*}\n\\sum F_x &= 0 \\longrightarrow - \\ell S\\cos(\\phi)  + \\sigma_{xx}\\ell \\sin(\\phi) = 0\\\\\n\\sum F_y &= 0 \\longrightarrow - \\ell S\\sin(\\phi) - \\sigma_{yy}\\ell \\cos(\\phi)=0\n\\end{align*}\nand the following stress solution:\n\\begin{equation}\n\\begin{aligned}\n\\sigma_{xx}& = S \\cot(\\phi)\\\\\n\\sigma_{yy}& = -S\\tan(\\phi)\\\\\n\\tau_{xy}& = 0\\, .\n\\end{aligned}\n\\label{eq:solution}\n\\end{equation}\n\nIn \\cref{eq:solution} the condition $\\tau_{xy}=0$ is due to the symmetries in the problem.\n\n\\subsubsection*{Traction boundary conditions}\nLet us verify that the above stress solution satisfies the traction BC using the expression:\n\\[t_i^{\\hat n} = \\sigma_{ij} \\hat n_{ij}.\\]\n\nDenoting the outward normals to the inclined surfaces of the wedge by $\\hat{n}^1$,  $\\hat{n}^2$, $\\hat{n}^3$, $\\hat{n}^4$ these are given by:\n\\begin{align*}\n\\hat{n}^1 &= -\\sin(\\phi)\\hat{e}_{x}+\\cos(\\phi)\\hat{e}_{y}\\\\\n\\hat{n}^2 &= -\\sin(\\phi)\\hat{e}_{x}-\\cos(\\phi)\\hat{e}_{y}\\\\\n\\hat{n}^3 &= +\\sin(\\phi)\\hat{e}_{x}+\\cos(\\phi)\\hat{e}_{y}\\\\\n\\hat{n}^4 &= +\\sin(\\phi)\\hat{e}_{x}-\\cos(\\phi)\\hat{e}_{y} \\enspace ,\n\\end{align*}\nwhere $\\hat{e}_{x}$ and $\\hat{e}_{y}$ are the reference unit vectors. Now, the components of the traction vector follow directly like\n\\[t_i = \\sigma_{ij}\\hat{n}_j\\]\nthen over the face with normal $\\hat{n}^1$ we have\n\\begin{align*}\nt_{x} &= -S\\cos(\\phi)\\\\\nt_{y} &= -S\\sin(\\phi)\n\\end{align*}\nsimilarly, over the face with normal $\\hat{n}^2$\n\\begin{align*}\nt_{x} &= -S\\cos(\\phi)\\\\\nt_{y} &= +S\\sin(\\phi)\n\\end{align*}\nover the face with normal $\\hat{n}^3$ \n\\begin{align*}\nt_{x} &= +S\\cos(\\phi)\\\\\nt_{y} &= -S\\sin(\\phi)\n\\end{align*}\nand finally, over the face with normal $\\hat{n}^4$;\n\\begin{align*}\nt_{x} &= +S\\cos(\\phi)\\\\\nt_{y} &= +S\\sin(\\phi) \\enspace .\n\\end{align*}\n\n\\subsubsection*{Strain field}\nThe strain field can be obtained after using the stress solution found in \\cref{eq:solution} together with the constitutive law given by \\cref{eq:Hooke} which for a plane strain idealization takes the form:\n\\begin{equation}\n\\begin{aligned}\n\\epsilon_{xx}& = \\frac{1}{E}(\\sigma_{xx} - \\nu \\sigma_{yy}) \\\\\n\\epsilon_{yy}& = \\frac{1}{E}(\\sigma_{yy} - \\nu \\sigma_{xx}) \\\\\n\\gamma_{xy}& = \\frac{\\tau _{xy}}{\\mu}\n\\end{aligned}\n\\label{eq:cons model}\n\\end{equation}\nwhich for the particular case yields\n\\begin{equation}\n\\begin{aligned}\n\\epsilon_{xx}& = +\\dfrac{S}{E}\\left[\\cot(\\phi)+\\nu \\tan(\\phi)\\right] = +\\dfrac{S}{E}K_{1}(\\nu , \\phi)\\\\\n\\epsilon_{yy}& = -\\dfrac{S}{E}\\left[\\tan(\\phi)+\\nu \\cot(\\phi)\\right] = -\\dfrac{S}{E}K_{2}(\\nu , \\phi)\\\\\n\\gamma_{xy}& = 0.\n\\end{aligned}\n\\label{eq:strain part}\n\\end{equation}\n\n\\subsubsection*{Displacement field}\nThe displacement field is obtained after direct integration of the strains after using the fact that\n\\[\\dd{u}_i = \\epsilon_{ij} \\dd{x}_j + \\omega_{ij}\\dd{x}_j\\]\nand the condition $\\omega_{xy}=0$ also due to symmetries , as follows\n\\begin{align*}\nu &= +\\dfrac{S}{E} K_{1}(\\nu , \\phi)x + A\\\\\nv &= -\\dfrac{S}{E} K_{2}(\\nu , \\phi)y + B\n\\end{align*}\nand where $A$ and $B$ are integration constants.\n\nFrom the condition $u=0$ at $x=\\ell\\cos(\\phi)$ we have that\n\\[A=-\\dfrac{S}{E} K_{1}(\\nu , \\phi)\\ell\\cos(\\phi)\\]\nthen it follows that\n\\[u=\\dfrac{S}{E} K_{1}(\\nu , \\phi)(x-\\ell\\cos(\\phi)).\\]\n\nSimilarly, from the condition $v=0$ at $y=0$ we have that $B=0$ from which\n\\[v=-\\dfrac{S}{E} K_{2}(\\nu , \\phi)y\\]\n\n\\subsection{Variational formulation}\nIn this section we formulate the boundary value problem using the approach of the calculus of variations in which the governing PDEs and boundary conditions are obtained after finding the minimum (or maximum) of a functional according to a variational principle\\footnote{According to Wikipedia \\cite{wiki:variational_principle}\n\n\\begin{quotation}\nA variational principle is a scientific principle used within the calculus of variations, which develops general methods for finding functions which minimize or maximize the value of quantities that depend upon those functions. For example, to answer this question: ``What is the shape of a chain suspended at both ends?\" we can use the variational principle that the shape must minimize the gravitational potential energy.\n\nAccording to Cornelius Lanczos, any physical law which can be expressed as a variational principle describes an expression which is self-adjoint. These expressions are also called Hermitian. Such an expression describes an invariant under a Hermitian transformation.\n\\end{quotation}}.\n\nWe will see that the weak form (and therefore also the strong form) can be obtained alternatively through the process of finding extreme values for a functional. We will illustrate this idea for the general case of theory of elasticity and then we will present particular examples.\n\n\\subsubsection*{Some vague definitions in the calculus of variations}\nIn variational calculus a {\\bf functional} can be understood as a ``function\" having as independent variables or arguments a space of vector functions and producing as a result (or dependent variable) a scalar. For instance, in the particular case of the theory of elasticity such a ``function\" corresponds to the total potential energy functional $\\Pi$ given by;\n\\begin{equation}\\label{eq:Potential}\n    \\Pi(u_i) = \\frac{1}{2}\\int\\limits_V \\sigma_{ij}\\varepsilon_{ij}\\dd{V}  - \\int\\limits_V f_i\\, u_i\\dd{V}  - \\int\\limits_S t_i^{(n)} u_i\\dd{S}\n\\end{equation}\nand where the first term in the left hand side corresponds to the internal strain energy, while the last two terms are the work done by the external body and traction forces. The above functional has as independent variables the displacement vector and its spatial derivatives. This is indicated by the presence of the displacement vector $u_i$ in the expression $\\Pi(u_i)$.\n\nIn variational calculus we are interested in finding a function $u_i$ that renders the functional $\\Pi$ a maximum or a minimum. In loose terms, the analogous to the differential operator in calculus of functions is now termed the variational operator $\\var$ (i.e., $\\var$ is analogous to $\\pdv{x_i}$). As such $\\var{\\Pi}$ acts over the function $u_i$ and its derivatives as follows\n\\[\\var{\\Pi}  = \\pdv{\\Pi}{u_i}\\var{u_i} + \\pdv{\\Pi}{\\left( \\pdv{u_i}{x_j}\\right)} \\delta\\left(\\pdv{u_i}{x_j}\\right) + \\cdots + \\pdv{\\Pi}{\\left( \\pdv{^{n}u_i}{x_j \\cdots \\partial x_k}\\right)} \\delta\\left( \\pdv{^{n}u_i}{x_j \\cdots \\partial x_k}\\right) \\enspace .\\]\n\nThe following rules apply to the variational operator $\\delta$:\n\\begin{itemize}\n\\item For functionals $\\Pi$ and $\\Phi$ it follows that \\[\\var(\\Pi  + \\Phi) = \\var{\\Pi}  + \\var{\\Phi}\\]\n\\item For functionals $\\Pi$ and $\\Phi$ it follows that \\[\\var(\\Pi \\Phi ) = \\var{\\Pi} \\Phi  + \\Pi \\var{\\Phi}\\]\n\\item For a functional $\\Pi$ and an integer $n$ it follows that \\[\\var(\\Pi^n) = n(\\Pi^{n - 1})\\var{\\Pi}\\]\n\\item For a functional $\\Pi$ it follows that \\[\\var{\\int \\Pi \\dd{x}}  = \\int \\var{\\Pi} \\dd{x} \\]\n\\end{itemize}\n\nIf the variational operator is applied to the functional $\\Pi(u_i)$ it produces functions or variations in $u_i$ which are arbitrary and such $\\var{u_i} \\in V$ and $\\var{u_i} = 0$ in $S_u$.\n\nTo find an extreme function in the calculus of variations we proceed like in differential calculus. Here we compute the first variation of the functional $\\var{\\Pi}$ and solve the variational equation\n\\begin{equation}\\label{eq:vareq}\n    \\delta \\Pi  = 0\n\\end{equation}\nin the unknown function $u_i$. \n\nIn the particular case of the total potential energy functional $\\Pi$ this yields\n\\begin{equation}\\label{eq:ClaPVW}\n    \\int\\limits_V \\sigma _{ij}\\var{\\varepsilon_{ij}}\\dd{V}  - \\int\\limits_V f_i \\var{u_i} \\dd{V}  - \\int\\limits_{S_t} t_i^{(n)} \\var{u_i}\\dd{S}  = 0\n\\end{equation}\nwhere we recognize the weak form of the BVP stated previously. It becomes evident that the functions $\\delta {u_i}$ in \\cref{eq:ClaPVW} play the role of the test functions $w_i$ introduced in the weak form. On the other hand, since we have already shown that the weak and strong forms are equivalent we conclude that having the functional and the essential boundary conditions is equivalent to having the strong form of the problem.\n\n\n\\subsubsection*{Principle of minimum potential energy}\nIn the theory of elasticity the total potential energy $\\Pi$ is the result of adding the elastic strain energy which is stored in the body upon deformation and the potential energy (work) imparted to the body by the applied forces. The principle states that the body is in equilibrium when this total potential energy reaches a minimum. This is equivalent to stating that an equilibrium configuration is attained when an infinitesimal variation from the position of minimum potential energy involves null changes in energy. This implies the variational condition:\n\\begin{equation}\\label{vareq2}\n    \\delta \\Pi  = 0.\n\\end{equation}\n\nThe above principle leads to the so-called principle of virtual displacements stated as follows\\footnote{See Bathe pp 156.}:\n``The equilibrium of the body requires that for any compatible small virtual displacements satisfying the condition of being zero at $S_u$, imposed on the body in its state of equilibrium, the total internal virtual work is equal to the total external virtual work\"\n\\[\\int\\limits_V \\sigma _{ij}\\var{\\varepsilon_{ij}}\\dd{V}  - \\int\\limits_V f_i\\delta u_i\\dd{V}  - \\int\\limits_{S_t} t_i^{(n)}\\var{u_i}\\dd{S}  = 0\\]\nwhere $\\var{u_i}$ are the virtual displacements and $\\var{ \\varepsilon_{ij}}$ are the corresponding virtual strains.\n\nComparing the virtual work principle with the weak formulation given in \\cref{eq:weak} we identify $\\var{u_i}$ with the test functions $w_i$. As such the PVW takes the form of a powerful tool to test if a body is in equilibrium for a given solution (represented by the trial functions). In what follows we illustrate the use of the principle through some examples corresponding to problems in Bathe's textbook.\n\n\\subsubsection*{Problem\\footnote{3.15 from Finite Element Procedures}}\nEstablish the differential equation of equilibrium of the problem shown and the boundary conditions. Determine whether the differential operator of the problem is symmetric and positive definite and prove your answer.\\cite{book:bathe}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=10cm]{{Bathe3.15}.pdf}\n    \\caption{Rod with varying cross-sectional area. The Young's modulus is E.}\n    \\label{fig:bathe3.15}\n\\end{figure}\n\n\n\\begin{align*}\n\\Pi &= \\frac{1}{2}\\int\\limits_0^L \\sigma_{xx}\\varepsilon_{xx}A(x)\\dd{x} + \\frac{1}{2}ku_0^2 - R u_L \\\\\n &= \\frac{1}{2}\\int\\limits_0^L EA(x)\\left( \\dv{u}{x}\\right)^2 \\dd{x} + \\frac{1}{2}ku_0^2  - R u_L \\enspace.\n\\end{align*}\n\nThe first variation for this functional is\n\\[\\var{\\Pi}  = \\int\\limits_0^L EA(x)\\dv{u}{x}\\dv{\\var{u}}{x}\\dd{x} + k u_0\\var{u_0}  - R\\var{u_L} \\enspace .\\]\n\nIf we integrate by parts, we obtain\n\\[\\var{\\Pi}  =  - \\int\\limits_0^L \\dv{x}\\left[EA(x)\\dv{u}{x}\\right]\\var{u}\\dd{x} + \\left. EA(x)\\dv{u}{x}\\var{u} \\right|_0^L + k{u_0}\\var{u_0}  - R\\var{u_L}\\]\nfrom which\n\\begin{align*}\n&\\dv{x}\\left[EA(x)\\dv{u}{x}\\right] = 0\\\\\n&\\left. EA(x)\\dv{u}{x}\\right|_{x=0} = k u_0\\\\\n&\\left. EA(x)\\dv{u}{x}\\right|_{x=L} = R\n\\end{align*}\n\n\n\\subsubsection*{Problem: The Hu-Washizu Variational Principle\\footnote{4.35 from Finite Element Procedures}}\n\nConsider the Hu-Washizu functional:\n\\begin{equation}\n\\Pi^* = \\Pi  - \\intL_V \\lambda_{ij}^\\varepsilon (\\varepsilon_{ij} - L_{ijk} u_k)\\dd{V}  - \\intL_{S_u} \\lambda_i^u(u_i^{S_u} - \\bar{ u}_i)\\dd{S}\n\\label{eq:Hu}\n\\end{equation}\nwhere\n\\begin{itemize}\n\\item $\\Pi$: is the potential energy functional.\n\\item $L_{ijk}$ is a differential operator such $\\varepsilon_{ij} = L_{ijk} u_k$.\n\\item $S_u$ surface where essential boundary conditions are prescribed.\n\\item $\\lambda_{ij}^\\varepsilon $ and $\\lambda_i^u$ are Lagrange multipliers.\n\\end{itemize}\n\nUsing the condition $\\var{\\Pi} = 0$ derive for the interior of the body the equilibrium equations\n\\[\\sigma_{ij,j} + f_i = 0\\]\nthe strain-displacement relationship\n\\[\\varepsilon_{ij} = L_{ijk} u_k\\]\nand the constitutive equation\n\\[\\sigma_{ij} = C_{ijkl} \\varepsilon_{kl}\\]\nand at the surface of the body the relation between the stress tensor and the applied tractions vector at $S_t$\n\\[t_i = \\sigma_{ij} n_j\\]\nthe relation between the stress tensor and the unknown tractions vector (or reactions) at $S_u$\n\\[t_i = \\tilde{\\sigma_{ij}} n_j\\]\nand the essential boundary condition at $S_u$\n\\[u_i = \\tilde{u}_i\\]\nWe want to determine the Euler equations resulting from the condition $\\var{\\Pi}^* = 0$. Applying the variational operator we have\n\\begin{equation}\n\\begin{aligned}\n\\var{\\Pi}^*& = \\var{\\Pi}  - \\intL_V \\var{\\lambda}_{ij}^{\\varepsilon}  (\\varepsilon_{ij} - L_{ijk} u_k)\\dd{V}- \\intL_V \\lambda_{ij}^\\varepsilon (\\var{\\varepsilon}_{ij} - L_{ijk}\\var{u}_k)\\dd{V} \\\\\n&-\\intL_V \\var{\\lambda}_i^u (u_i^{S_u} - \\bar u_i)\\dd{S} - \\intL_V \\lambda _i^u \\var{u}_i^{S_u} \\dd{S}\n\\end{aligned}\n\\end{equation}\nand\n\\begin{equation}\n\\begin{aligned}\n\\var{\\Pi}^* =& \\intL_V C_{ijkl} \\varepsilon_{kl} \\var{ \\varepsilon}_{ij}\\dd{V} - \\intL_{S_t} t_i \\var{u_i} \\dd{S}  - \\intL_V f_i \\var{u_i}\\dd{V}\\\\\n  &- \\intL_V \\lambda_{ij}^{\\varepsilon} \\var{\\varepsilon}_{ij}\\dd{V}  + \\intL_V \\lambda_{ij}^{\\varepsilon} L_{ijk}\\var{u_k}\\dd{V} - \\intL_V \\delta \\lambda_{ij}^\\varepsilon (\\varepsilon_{ij}\\\\\n  &- L_{ijk} u_k)\\dd{V} - \\intL_S \\var{\\lambda}_i^u (u_i^{S_u} - \\bar {u}_i)\\dd{S} - \\intL_{S_u} \\lambda _i^u\\var{u_i}\\dd{S} = 0\n\\end{aligned}\n\\end{equation}\nusing\n\\[\\intL_V (\\lambda_{ij}^\\varepsilon \\var{u_i}){,_j}\\dd{V} =  \\intL_V \\lambda_{ij}^\\varepsilon \\var{u}_{i,j}\\dd{V}  + \\intL_V \\lambda_{ij,j}^\\varepsilon \\var{u_i}\\dd{V} \\]\n\nIn the above we can write\n\\begin{align*}\n\\intL_V \\lambda_{ij}^\\varepsilon L_{ijk}\\var{u_k}\\dd{V} & = \\intL_V (\\lambda_{ij}^\\varepsilon \\var{u_i})_{,j}\\dd{V} - \\intL_V \\lambda_{ij,j}^\\varepsilon \\delta {u_i}\\dd{V}\\\\\n& = \\intL_{S_t} \\lambda_{ij}^\\varepsilon \\var{u_i}\\hat {n}_j\\dd{S}  - \\intL_V \\lambda_{ij,j}^\\varepsilon \\var{u_i}\\dd{V}\n\\end{align*}\ntherefore\n\\begin{align*}\n\\delta \\Pi^* =& \\intL_V (C_{ijkl}\\varepsilon_{kl} - \\lambda_{ij}^\\varepsilon) \\var{\\varepsilon}_{ij}\\dd{V} - \\intL_{S_t} t_i \\var{u}_i\\dd{S} - \\intL_V f_i \\var{u}_i\\dd{V}\\\\\n  &+ \\intL_{S_t} \\lambda_{ij}^\\varepsilon \\var{u_i}\\hat{n}_j\\dd{S}  - \\intL_V \\lambda_{ij,j}^\\varepsilon \\delta {u_i}\\dd{V} - \\intL_V \\delta \\lambda _{ij}^\\varepsilon (\\varepsilon_{ij}\\\\\n  &- L_{ijk} u_k)\\dd{V}  - \\intL_{S_u} \\var{\\lambda}_i^u (u_i^{S_u} - \\bar{u}_i)\\dd{S} - \\intL_{S_u} \\lambda_i^u \\var{u_i} \\dd{S}  = 0\\\\\n=& \\intL_V (C_{ijkl}\\varepsilon_{kl} - \\lambda_{ij}^\\varepsilon) \\var{\\varepsilon}_{ij}\\dd{V}\n+ \\intL_{S_t} (\\lambda_{ij}^\\varepsilon \\hat{n}_j - t_i)\\delta {u_i}\\dd{S}\\\\\n  &- \\intL_V (\\lambda_{ij,j}^\\varepsilon  + f_i) \\var{u_i}\\dd{V}\n- \\intL_V (\\varepsilon_{ij}- L_{ijk} u_k) \\var{\\lambda} _{ij}^\\varepsilon\\dd{V}\\\\\n  &- \\intL_{S_u} (u_i^{S_u} - \\bar{u}_i) \\var{\\lambda}_i^u\\dd{S}  - \\cancel{\\intL_{S_u} \\lambda _i^u \\var{u}_i^{S_u}\\dd{S}} = 0\n\\end{align*}\n\nNow, imposing the conditions $\\var{\\varepsilon}_{ij} \\neq 0$, $\\var{\\lambda}_{ij}^\\varepsilon  \\neq 0$, $var{u}_i \\neq 0$ in $S_t$, $\\var{u}_i \\neq 0$ in $V$ and $\\var{\\lambda}_i^u \\neq 0$ in $S_u$ we have\n\\begin{align}\n&\\lambda_{ij}^\\varepsilon  = C_{ijkl} \\varepsilon_{kl}\\\\\n&\\varepsilon_{ij} = L_{ijk} u_k\\\\\nt_i &= \\lambda_{ij}^\\varepsilon \\hat{n}_j\\\\\n&\\lambda_{ij,j}^\\varepsilon  + {f_i} = 0\\\\\n&u_i^{S_u} = \\bar{u}_i \\enspace .\n\\end{align}\n\n\\subsection{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\\begin{align*}\n  &-\\int\\limits_V N^P N_{,ii}^Q \\dd{V} u^Q + \\int\\limits_V q N^P N^Q\\dd{V} u^Q  + \\rho \\int\\limits_V N^P N^Q \\dd{V} v^Q\\\\\n     &- \\rho \\int\\limits_V N^P F \\dd{V} = 0\\\\\n  &\\int\\limits_V N_{,i}^P N_{,i}^Q \\dd{V} u^Q - \\int\\limits_S N^P N_{,i}^Q \\hat{n}_i \\dd{S} u^Q + \\int\\limits_V q N^P N^Q \\dd{V} u^Q\\\\\n    &+ \\rho \\int\\limits_V N^P N^Q \\dd{V} v^Q  - \\rho \\int\\limits_V N^P F \\dd{V} = 0 \\\\\n  &\\int\\limits_V \\left(N_{,i}^P N_{,i}^Q + q N^PN^Q \\right)\\dd{V} u^Q  + \\rho \\int\\limits_V N^P N^Q \\dd{V} V^Q  =\\\\\n      &\\int\\limits_S N^P N_{,i}^Q \\hat{n}_i \\dd{S} u^Q + \\rho \\int\\limits_V N^P F \\dd{V}\n\\end{align*}\nwhich can be written in discrete form as\n\\[K^{PQ} U^Q + C^{PQ} V^Q = f^p\\, .\\]\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\\todo{Where was defined $r_i$. Some cohesion is missing here.}\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\n\\[&\\int\\limits_V N_i^P R_i \\dd{V} = 0 \\qquad P=1,2,\\cdots N\\, .\\]\n\nThus\n\\begin{align*}\n&\\int\\limits_V N_i^P \\mathcal{L}_{ij} (N_j^K)\\dd{V} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0 \\\\\n&(\\lambda  + \\mu )\\int\\limits_V N_i^PN_{j,ij}^K \\dd{V} u^K  + \\mu \\int\\limits_V N_i^PN_{i,kk}^K \\dd{V} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0\n\\end{align*}\nintegrating by parts\n\\begin{align*}\n- (\\lambda  + \\mu )\\int\\limits_V N_{i,j}^P N_{j,i}^K \\dd{V} u^K + (\\lambda  + \\mu )\\int\\limits_S N_i^P N_{j,i}^K \\hat{n}_j \\dd{S} u^K - \\mu \\int\\limits_V N_{i,k}^P N_{i,k}^K \\dd{V} u^K \\\\\n+ \\mu \\int\\limits_S N_i^P N_{i,k}^K \\hat{n}_k \\dd{S} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0\n\\end{align*}\nwhich can be written like\n\\[K^{PQ} U^Q = F^P\\]\nwhere\n\\[K^{PQ} = (\\lambda  + \\mu )\\int\\limits_V N_{i,j}^P N_{j,i}^Q \\dd{V}  + \\mu \\int\\limits_V N_{i,k}^P N_{i,k}^Q\\dd{V} \\]\nand\n\\[F^P = \\int\\limits_S N_i^P t_i^{(\\hat n)} \\dd{S} + \\int\\limits_V N_i^P f_i \\dd{V} = 0 \\, .\\]\n\n\\subsubsection*{Problem: Discretization of the wave equation.}\nIn this case the differential equation reads\n\\[\\div \\left[ \\frac{1}{\\rho} \\grad p(\\vb{x})\\right] - \\pdv{t} \\left(\\frac{1}{\\lambda} \\pdv{\\rho}{t}\\right) - q(\\vb{x}) = 0\\]\nwhere we recognize that\n\\[\\mathcal{L} \\equiv \\div \\left(\\frac{1}{\\rho} \\grad \\right) - \\pdv{t}\\left(\\frac{1}{\\lambda}\\pdv{t}\\right)\\, .\\]\n\nLet\n\\[p(x) = N^K p^K\\]\nthen\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)\\]\nor in index notation\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}\\]\nwhich is equivalent to\n\\[\\mathcal{L}(p) \\equiv \\mathcal{L}({N^K}){p^K}\\]\nusing the trial functions as weighting function and recalling the definition of the residual which in this case reads\n\\[R = \\mathcal{L}({N^K}){p^K} - q\\, ,\\]\nand yields\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 right-hand-side gives us\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", "meta": {"hexsha": "a864320930f602b0a1a18800695fa3edcaefd673", "size": 43563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/bvp.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/bvp.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/bvp.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": 61.2700421941, "max_line_length": 759, "alphanum_fraction": 0.6831714987, "num_tokens": 15395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6478875790754096}}
{"text": "\\documentclass{article}\n\\input{../general}\n\n\\MakeTitle{6}\n\n\\begin{document}\n\\maketitle\n\n\\gotosection{2}{5}\n\\subsection{Kernels, images, and the dimension formula}\n\n\\begin{exercise}{1}\n\\begin{enumerate}\n\\item $A\\Vect{v}_1 = \\Vect{0}$, $\\Vect{v}_1 \\in \\ker{A}$.\n\n$A\\Vect{v}_2 = \\xmat{2\\\\3\\\\3}$, $\\Vect{v}_2 \\notin \\ker{a}$.\n\n$A\\Vect{v}_3 = \\Vect{0}$, $\\Vect{v}_3 \\in \\ker{A}$.\n\n\\item Since \\FunSS{T}{\\mathbb{R}^5}{\\mathbb{R}^3}, $\\Vect{w}_4$ has the right height to be in the kernel of $T$, while $\\Vect{w}_1$ and $\\Vect{w}_3$ has the right height to be in the image of $T$.\n$$\\widetilde{T} = \\xmat{1&0&0&2&1\\\\0&1&0&5&0\\\\0&0&1&1&-1}$$\n\\begin{align*}\n  x_1 &= -2x_4 - x_5 \\\\\n  x_2 &= -5x_4 \\\\\n  x_3 &= -x_4 + x_5\n\\end{align*}\n\nLet $x_4=1, x_5=0$, $\\xmat{-2\\\\-5\\\\-1\\\\1\\\\0}$ is in the kernel of $T$.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{2}\n\\begin{enumerate}\n\\item False, should span $\\mathbb{R}^m$.\n\\item True.\n\\item True.\n\\item False.\n\\item False, should be $n - m$.\n\\item False, unless $T$ is also injective.\n\\item False, unless $T$ is also injective.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{3}\n\\newcolumntype{L}{>{\\centering\\arraybackslash}m{4cm}}\n\\newcolumntype{I}{>{\\centering\\arraybackslash}m{4.2cm}}\n\\begin{center}\n\\begin{tabular}{|L|I|c|}\n\\hline\nrank $T$ & nullity $T$ & rank $T$ + nullity $T$\\\\\n\\hline\ndim image $T$ & dim ker $T$ & dim domain $T$ \\\\\n\\hline\n\\# pivotal columns of $T$ & \\# nonpivotal columns of $T$ & \\\\\n\\hline\n\\# linearly independent columns of $T$ && \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n`\\#' stands for ``no. of\".\n\\end{exercise}\n\n\\def \\img{\\mathrm{img}}\n\n\\begin{exercise}{5}\n\\begin{enumerate}\n\\item $T(\\Vect{0}) = \\Vect{0}$, therefore $\\Vect{0} \\in \\ker T$.\n  For any $\\Vect{u}_1, \\Vect{u}_2 \\in \\ker T$, $T(\\Vect{u}_1 + \\Vect{u}_2) = T(\\Vect{u}_1) + T(\\Vect{u}_2) = \\Vect{0} + \\Vect{0} = \\Vect{0}$, therefore, $\\Vect{u}_1 + \\Vect{u}_2 \\in \\ker T$.\n  For any $\\Vect{u} \\in \\ker T$, $c \\in \\mathbb{R}$, $T(c\\Vect{u}) = c T(\\Vect{u}) = c\\Vect{0} = \\Vect{0}$, therefore, $c\\Vect{u} \\in \\ker T$.\n  Hence, $\\ker T$ is a subspace of $\\mathbb{R}^n$. \\rQED\n\n\\item $T(\\Vect{0}) = \\Vect{0}$, therefore $\\Vect{0} \\in \\img T$. For any $\\Vect{u}_1 = T(\\Vect{v}_1), \\Vect{u}_2 = T(\\Vect{v}_2) \\in \\img T$, $\\Vect{u}_1 + \\Vect{u}_2 = T(\\Vect{v}_1) + T(\\Vect{v}_2) = T(\\Vect{v}_1 + T\\Vect{v}_2) \\in \\img T$. For any $\\Vect{u} = T(\\Vect{v}) \\in \\img T$, $c \\in \\mathbb{R}$, $c\\Vect{u} = cT(\\Vect{v}) = T(c\\Vect{v}) \\in \\img T$. Therefore, $\\img T$ is a subspace of $\\mathbb{R}^m$. \\rQED\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{6}\n\\begin{enumerate}\n\\item $A = \\xmat{1&1&3\\\\2&2&6}$, $\\widetilde{A} = \\xmat{1&1&3\\\\0&0&0}$. A basis for the image: $\\xmat{1\\\\2}$. A basis for the kernel: $\\xmat{-1\\\\1\\\\0}$, $\\xmat{-3\\\\0\\\\1}$.\n\n\\item $A = \\xmat{1&2&3\\\\-1&1&1\\\\-1&4&5}$, $\\widetilde{A} = \\xmat{1&0&1/3\\\\0&1&4/3\\\\0&0&0}$. A basis for the image: $\\xmat{1&-1&-1}$, $\\xmat{2\\\\1\\\\4}$. A basis for the kernel: $\\xmat{-1/3\\\\-4/3\\\\1}$.\n\n\\item $A = \\xmat{1&1&1\\\\1&2&3\\\\2&3&4}$, $\\widetilde{A} = \\xmat{1&0&-1\\\\0&1&2\\\\0&0&0}$. A basis for the image: $\\xmat{1\\\\1\\\\2}$, $\\xmat{1\\\\2\\\\3}$. A basis for the kernel: $\\xmat{1\\\\-2\\\\1}$.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{8}\nFalse.\n\nLet $[f]$ be a matrix with all entries being zero. Then, for any $\\Vect{v} \\in \\mathbb{R}^m$, $f(\\Vect{v}) = 0$, therefore, $\\ker f = \\mathbb{R}^m$. Let $g$ be a non-surjective function, i.e. $n < m$, then $\\img g \\subset \\mathbb{R}^m$ and $\\img g \\neq \\mathbb{R}^m$. In other words, $\\img g$ can only be a proper subset of $\\ker g$. \\rQED\n\\end{exercise}\n\n\\begin{exercise}{9}\n\\begin{enumerate}\n\\item $T(a+bx+cx^2) = bx+4cx^2$, $[T] = \\cmat{0&0&0\\\\0&1&0\\\\0&0&4}$.\n\\item Let $A = [T]$, $\\widetilde{A} = \\cmat{0&1&0\\\\0&0&1\\\\0&0&0}$. The second and the third columns (pivotal columns) of $A$ then form the basis of $\\img T$, namely $\\cmat{0\\\\1\\\\0}$ and $\\cmat{0\\\\0\\\\4}$. $\\dim{\\ker T} = 1$, and a basis of $\\ker T$ is $\\cmat{1\\\\0\\\\0}$, which can be derived from either the method mentioned in the textbook or the fact that only constant polynomials are in the kernel.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{10}\nFix $k$, for the sake of clarity.\n\nThe problem can be seen as finding a matrix $A \\in M_{(1,k+1)}$ such that:\n$$\\xmat{c_0 & \\hdots \n& c_k}\\cmat{p(0)\\\\\\vdots\\\\p(k)} = \\int^k_0p(t)dt$$\n\nLet's call the vector a polynomial vector. In the subsection of ``Interpolation and the dimension formula\", the textbook has proved that for each polynomial $p \\in P_k$, there exists one and only one such polynomial vector $\\Vect{v} \\in \\mathbb{R}^{k+1}$, and for each polynomial vector $\\Vect{v} \\in \\mathbb{R}^{k+1}$, there exists one and only one $p \\in P_k$.\\footnote{Formula 2.5.15, and ``in particular, $T_k$ is invertible}\n\nFor $A$ to be exists, the relation between $\\cmat{p(0)\\\\\\vdots\\\\p(k)}$ and $\\int^k_0p(t)dt$ must be linear, because there is a bijective relation between matrix and linear transformation. To put it more explicit, \\FunSS{T}{\\mathbb{R}^{k+1}}{\\mathbb{R}} such that:\n\n$$T(\\cmat{p(0)\\\\\\vdots\\\\p(k)}) = \\int^k_0p(t)dt$$\n\nmust be a linear transformation.\n\nLet's denote the polynomial vector of a polynomial $p$ as $\\Vect{p}$. For any two polynomials $p, q \\in P_k$ such that,\n$p = \\sum_{i=0}^kp_ix^i$,\n$q = \\sum_{i=0}^kq_ix^i$.\nThe sum of $p$ and $q$, denoted as $+_{p,q}$, is\n$\\sum_{i=0}^k(p_i+q_i)x^i$. It's obvious that for each $x \\in \\mathbb{R}$, $+_{p,q}(x) = p(x) + q(x)$. Then we have:\n$$\\Vect{v}_{+_{p,q}} = \\sum_{i=0}^ke_i(p_i+q_i)i^i = \\sum_{i=0}^ke_ip_ii^i + \\sum_{i=0}^ke_iq_ii^i = \\Vect{v}_p + \\Vect{v}_q$$\nwhere $e_i$ is a standard basis vector, and:\n$$T(\\Vect{v}_{+_{p,q}})=\\int^k_0+_{p,q}(t)dt=\\int^k_0p(t)dt+\\int^k_0p(t)dt = T(\\Vect{v}_p) + T(\\Vect{v}_q)$$\n\nLet $*_{c,p} = \\sum_{i=0}^k cp_ix^i$ for any real number $c$. It is clear that $*_{c,p} = c\\sum_{i=0}^k p_ix^i$, or $*_{c,p}(x) = cp(x)$ for each $x \\in \\mathbb{R}$. Then we have:\n$$\\Vect{v}_{*_{c,p}} = c\\Vect{v}_p$$\n, and:\n$$T(\\Vect{v}_{*_{c,p}}) = \\int^k_0*_{c,p}(t)dt = \\int^k_0cp(t)dt = c\\int^k_0p(t)dt = T(\\Vect{v}_p)$$\n\nTherefore, $T$ is indeed a linear transformation, $A = [T]$, and $c_0,\\hdots,c_k$ do exist. \\rQED\n\\end{exercise}\n\n\\begin{exercise}{15}\nSince $AB$ is invertible, the linear transformation $T_{AB}$ is bijective. Then, due to $T_{AB} = T_A \\circ T_B$, $T_A$ has to be surjective, otherwise there exists a $\\Vect{v} \\in \\mathbb{R}^n$ such that $T_A(\\Vect{x}) = \\Vect{v}$ has no solution, which means $T_A \\circ T_B(\\Vect{x}) = \\Vect{v}$ also has no solution, contradicting the surjectiveness of $T_{AB}$. Because $T_A$ is surjective and $A$ is square, $A$ is invertible.\n\nNow assume that $T_B$ is not injective. We can find $\\Vect{v}_1, \\Vect{v}_2 \\in \\mathbb{R}^n$ such that $T_B(\\Vect{v}_1) = T_B(\\Vect{v}_2)$. As a result, $T_A \\circ T_B(\\Vect{v}_1) = T_A \\circ T_B(\\Vect{v}_2)$, which contradicts the injectiveness of $T_{AB}$. Therefore, $T_B$ is injective, and since $B$ is square, $B$ is invertible.\n\nThis completes the proof. \\rQED\n\\end{exercise}\n\\end{document}\n", "meta": {"hexsha": "6b54f982f6019bc115d69c75a4f5e87ab67c8b48", "size": 7000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW6/main.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": "HW6/main.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": "HW6/main.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": 50.0, "max_line_length": 431, "alphanum_fraction": 0.6181428571, "num_tokens": 2972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6478284779949255}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{mathptmx}\n\\usepackage[small,compact]{titlesec} \n\\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.\n\\usepackage{url}\n\\usepackage{hyperref}\n\\usepackage{breakurl}\n\\geometry{letterpaper}                   % ... or a4paper or a5paper or ... \n%\\geometry{landscape}                % Activate for for rotated page geometry\n\\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent\n\\usepackage{graphicx}\n\\usepackage{amssymb, amsmath}\n\\usepackage{epstopdf}\n\n\\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}\n\n\\title{Raytracing Quadrics}\n\\author{Miles Macklin}\n%\\date{}                                           % Activate to display a given date or no date\n\n\\renewcommand{\\v}[1]{\\ensuremath{\\mathbf{#1}}} % for vectors\n\\newcommand{\\uv}[1]{\\ensuremath{\\mathbf{\\hat{#1}}}} % for unit vectors\n\\newcommand\\ddx[1]{\\frac{\\partial#1}{\\partial \\v{x} }} \n\\newcommand\\dd[2]{\\frac{\\partial#1}{\\partial #2}} \n\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\n\nThis short article shows how to define and manipulate quadric surface equations in matrix form and intersect rays against them for rendering. The treatment here is inspired by \\cite{Sigg:2006:GRQ:2386388.2386396} and work by Simon Green at NVIDIA.\n\n\n\\section{Quadrics}\n\nThe quadratic equation in 3 variables can be written as:\n\n\\begin{equation}\nf(x,y,z) = Ax^2 +2Bxy+2Cxz+2Dx+Ey^2+2Fyz+Gy+Hz^2 +2Iz+J = 0\n\\end{equation}\n\nIt can also be written in matrix form using homogenous coordinates:\n\n\\begin{equation}\n\\v{x}^T\\v{Q}\\v{x} = 0\n\\end{equation}\n\nwhere $\\v{Q}$ is the matrix of coefficients:\n\n\\begin{equation}\n\\v{Q} = \n\\begin{bmatrix}\n  A & B & C & D \\\\\n  B & E & F & G \\\\\n  C & F & H & I \\\\\n  D & G & I & J\n \\end{bmatrix}\n \\qquad \n  \\v{x} =\n \\begin{bmatrix}\n x \\\\ y \\\\ z \\\\ 1\n \\end{bmatrix}\n\\end{equation}\n\nBecause this matrix is symmetric it can be diagonalised by a matrix $\\v{T}$. With appropriate scaling, our matrix $\\v{Q}$ can be expressed as a diagonal matrix $\\v{D}$ with entries $\\pm 1$ or $0$:\n\n\\begin{equation}\n\\v{Q}= \\v{T}^{-T}\\v{D}\\v{T}^{-1}\n\\end{equation}\n\nWe refer to the basis that diagonalises $\\v{Q}$ as the parameter space.\n\n$\\v{Q}$ can may be transformed to a different basis by any affine transformation $\\v{M}$ by multiplying by $\\v{M}^{-1}$ on both sides. This is equivalent to moving a point $\\v{x}'$ back to the basis for $\\v{Q}$, \n\n\\begin{equation}\n\\v{Q'} = \\v{M}^{-T}\\v{Q}\\v{M}^{-1}.\n\\end{equation}\n%\n\\begin{equation}\n\\v{x}' = \\v{M}\\v{x}\n\\end{equation}\n%\n\\begin{equation}\n\\v{x'}^T\\v{Q'}\\v{x'} = \\v{x'}^T\\v{M}^{-T}\\v{Q}\\v{M}^{-1}\\v{x'} = \\v{x}^T\\v{Q}\\v{x}\n\\end{equation}\n\nAs we will soon see, view (or eye) space is a convenient space for ray-tracing. To transform our quadric equation to view space we multiply by the inverse model view matrix $\\v{MV}$:\n\n\\begin{equation}\n\\v{Q'} = \\v{MV}^{-T}\\v{Q}\\v{MV}^{-1} = \\v{MV}^{-T}\\v{T}^{-T}\\v{D}\\v{T}^{-1}\\v{MV}^{-1} = (\\v{MV}\\cdot\\v{T})^{-T}\\v{D}(\\v{MV}\\cdot\\v{T})^{-1}\n\\end{equation}\n\nTo ray trace the quadric we parameterise the view ray in the usual way,\n\n\\begin{equation}\n\\v{x}_v = \\v{o} + t\\v{d},\n\\end{equation}\n\nand transform this back to parameter space:\n\n\\begin{equation}\n\\v{x}_p = (\\v{MV}\\cdot\\v{T})^{-1}\\v{o} + t(\\v{MV}\\cdot\\v{T})^{-1}\\v{d} = \\v{o}_p + t\\v{d}_p\n\\end{equation}\n\nInserting this into our quadratic equation,\n\n\\begin{equation}\n\\v{x}^T_p\\v{Q}\\v{x}_p = (\\v{o}_p + t\\v{d}_p)^T\\v{D}(\\v{o}_p + t\\v{d}_p) = 0,\n\\end{equation}\n\nand expanding and gathering for $t$, we have:\n\n\\begin{equation}\nt^2(\\v{d}^T_p\\v{D}\\v{d}_p) + 2t(\\v{o}^T_p\\v{D}\\v{d}_p) + \\v{o}^T_p\\v{D}\\v{o}_p = 0\n\\end{equation}\n\nwhich we can solve with the quadratic formula.\n\nThe advantage of defining our rays in view space is that the ray origin, or eye position $\\v{o}$ is simply the homogenous zero vector:\n\n\\begin{equation}\n\\v{o} = \n\\begin{bmatrix}\n0 \\\\\n0 \\\\\n0 \\\\\n1\n\\end{bmatrix}\n\\end{equation}\n\nWhich simply extracts the last column of ($\\v{MV}\\cdot\\v{T})^{-1}$ when we form $\\v{o}_p$:\n\n\\begin{equation}\n\\v{o}_p = \\v{c}_4\n\\end{equation}\n\n\n\\bibliographystyle{alpha}\n\\bibliography{quadric}\n\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\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "173b7cb58c439a5fe08cadce9860a05a32403a00", "size": 4207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/quadric/quadric.tex", "max_stars_repo_name": "NTForked/sandbox", "max_stars_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-01-02T13:44:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T14:08:45.000Z", "max_issues_repo_path": "projects/quadric/quadric.tex", "max_issues_repo_name": "NTForked/sandbox", "max_issues_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-05-08T10:28:10.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-09T02:05:10.000Z", "max_forks_repo_path": "projects/quadric/quadric.tex", "max_forks_repo_name": "NTForked/sandbox", "max_forks_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2015-02-12T03:38:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T14:09:13.000Z", "avg_line_length": 24.3179190751, "max_line_length": 247, "alphanum_fraction": 0.6446398859, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.78793120560257, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6478284728454892}}
{"text": "\\chapter{Univalent logic}\n\n\n\\section{Propositional truncation}\n\nUsing the same idea of higher inductive types, we can also turn every type into a mere proposition via an operation we call \\emph{propositional truncation}. \n\n\\begin{defn}\nLet $A:\\UU$ be a type. We define the \\define{propositional truncation} $\\brck{A}:\\UU$ as a higher inductive type with constructors\n\\begin{align*}\n\\eta & : A\\to \\brck{A} \\\\\n\\mu & : \\prd{x,y:\\brck{A}} x=y.\n\\end{align*}\nThe induction principle of $\\brck{A}$ asserts that for any type family $P:\\brck{A}\\to\\type$, if we have\n\\begin{align*}\nf & : \\prd{x:A}P(\\eta(x)) \\\\\ng & : \\prd{x,y:\\brck{A}}{p:P(x)}{q:P(y)} \\trans{\\mu(x,y)}{p}=q,\n\\end{align*}\nthen we obtain a section $\\rec{\\brck{\\blank}}(f,g):\\prd{x:\\brck{A}}P(x)$ satisfying\n\\begin{align*}\n\\rec{\\brck{\\blank}}(f,g,\\eta(x)) & = f(x).\n\\end{align*}\n\\end{defn}\n\n\\begin{rmk}\nWe will not need a computation rule corresponding to the path constructor $\\mu$.\n\\end{rmk}\n\n\\begin{lem}\nFor any $A:\\UU$, the type $\\brck{A}$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\nThe path constructor $\\mu:\\prd{x,y:\\brck{A}}x=y$ directly provides a proof that $\\brck{A}$ is a proposition.\n\\end{proof}\n\nThe following theorem asserts that for any map $f:A\\to P$ into a proposition $P$, there is a unique map $g:\\brck{A}\\to P$ such that $g\\circ\\eta=f$, as indicated in the following diagram\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[dr,\"\\forall\"] \\arrow[d,swap,\"\\eta\"] \\\\\n\\brck{A} \\arrow[r,densely dotted,swap,\"\\exists!\"] & P\n\\end{tikzcd}\n\\end{equation*}\nWe call this property the \\define{universal property of propositional truncation}. \n\n\\begin{thm}\nLet $A:\\UU$ be a type. Then for any proposition $P$, the map\n\\begin{equation*}\n\\lam{g} g\\circ \\eta : (\\brck{A}\\to P)\\to (A\\to P)\n\\end{equation*}\nis an equivalence.\n\\end{thm}\n\n\\begin{proof}\n\n\\end{proof}\n\n\\section{Surjective maps}\n\n\\begin{defn}\nWe say that a type $A$ is \\define{inhabited} if there is a term of type $\\brck{A}$. \n\\end{defn}\n\n\\begin{defn}\nA function $f:A\\to B$ is said to be surjective if its fibers are inhabited. \nMore explicitly, we define\n\\begin{equation*}\n\\mathsf{is\\usc{}surj}(f)\\defeq \\prd{b:B}\\brck{\\fib{f}{b}}. \n\\end{equation*}\n\\end{defn}\n\n\\section{First order logic in type theory}\n\\begin{table}\n\\caption{Logic in type theory}\n\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n\\emph{Logical connective} & \\emph{Interpretation in HoTT} \\\\\n\\midrule\n$\\top$ & $\\unit$ \\\\\n$\\bot$ & $\\emptyt$ \\\\\n$P\\land Q$ & $P\\times Q$ \\\\\n$P\\lor Q$ & $\\brck{P+Q}$ \\\\\n$P\\to Q$ & $P\\to Q$ \\\\\n$P\\leftrightarrow Q$ & $P=Q$ \\\\\n$\\neg P$ & $P\\to\\emptyt$ \\\\\n$\\forall x.P(x)$ & $\\prd{x:A}P(x)$ \\\\\n$\\exists x.P(x)$ & $\\brck{\\sm{x:A}P(x)}$ \\\\\n$\\exists! x.P(x)$ & $\\iscontr(\\sm{x:A}P(x))$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{table}\n\\begin{enumerate}\n\\item First order logic in type theory. Stress difference between $\\exists$ and $\\Sigma$.\n\\item Propositional extensionality\n\\end{enumerate}\n\n\\begin{exercises}\n\\item Show that\n\\begin{equation*}\n\\eqv{\\brck{A}}{\\prd{P:\\prop}(A\\to P)\\to P}.\n\\end{equation*}\n\\item For any $B:A\\to\\UU$, construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\exists a.\\brck{B(a)}\\Big)}{\\Big(\\brck{\\sm{a:A}B(a)}\\Big)}\n\\end{equation*}\n\\item \\label{also}(Mart\\'in Escard\\'o) For any two propositions $P$ and $Q$, define\n\\begin{equation*}\nP\\boxplus Q \\defeq ((P\\to Q)\\to Q)\\times ((Q\\to P)\\to P).\n\\end{equation*}\n\\begin{subexenum}\n\\item Show that $P\\lor Q\\to P\\boxplus Q$ and $P\\boxplus Q\\to\\neg(\\neg P\\land \\neg Q)$.\n\\end{subexenum}\n\\item Show that for any mere proposition $Q$, and any type $X$, the following are equivalent:\n\\begin{enumerate}\n\\item The map $(Q\\to X)\\to(\\emptyt\\to X)$ is an equivalence.\n\\item The type $X^Q$ is contractible.\n\\item $Q\\to\\iscontr(X)$.\n\\end{enumerate}\n\\item \\label{ex:brck_comp} Formulate the computation rule corresponding to the path constructor $\\mu$. That is, compute the type of $\\apd{\\rec{\\brck{\\blank}}(f,g)}{\\mu(x,y)}$, and find a canonical element in it.\n\\end{exercises}\n", "meta": {"hexsha": "c62418c3792d9e77ebb373a6a2c85d4d72eb4ab6", "size": 3941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/logic.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": 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/logic.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": 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/logic.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": 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": 32.0406504065, "max_line_length": 211, "alphanum_fraction": 0.670641969, "num_tokens": 1411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6478284595073159}}
{"text": "\\hypertarget{naive-bayes-classification}{%\n\\chapter{Naïve Bayes\nClassification}\\label{naive-bayes-classification}}\n\nNaïve Bayes classification algorithm is based on Bayes' Theorem. The\ndataset is divided into two parts, namely, feature matrix and the\nresponse vector.\n\n\\hypertarget{bayes-theorem}{%\n\\section{Bayes' Theorem}\\label{bayes-theorem}}\n\nBayes' Theorem provides a way that we can calculate the probability of a\npiece of data belonging to a given class, given our prior knowledge.\nBayes' Theorem is stated as:\n\n\\[\n\\Large P(\\alpha |\\beta) = \\frac{P(\\beta |\\alpha) * P(\\alpha)}{P(\\beta)}\n\\]\n\nNaive Bayes is a classification algorithm for binary (two-class) and\nmulticlass classification problems. It is called Naive Bayes or idiot\nBayes because the calculations of the probabilities for each class are\nsimplified to make their calculations tractable.\n\n\\section{Bayes' Theorem Calculation}\n\nIn our example, we shall use \\texttt{sklearn.naive\\_bayes} to classify\non the basis of previous data wheater or not a person has gotten a flu\nor not. We shall also check the accuracy and generate confusion matrix\nof the model. However, to gain a general understanding, here is how it works:\n\nStep 1: Study the dataset Our dataset include 4 feature columns and 1\ntarget column.\n\n\\begin{verbatim}\nChills  Runny_nose  Headache    Fever  |  Flu\n\\end{verbatim}\n\nStep 2: Calculate probability of target\n\n\\[ P(Flu|Y) = 10/14 = 0.714285714 \\] \\[ P(Flu|N) = 4/14 = 0.285714286 \\]\n\nStep 3: Calculate probability of feature columns for each\n\nFor each column of feature, calculate probability of all cases features\nX target. Such as - \\[ P(Chills=Y|Flu=Y) = 6/10 = .6 \\]\n\\[ P(Chills=Y|Flu=N) = 1/4 = .25 \\] And so on\\ldots{}\n\nStep 4:\nCalculate for the given case \\[\n\\Large P(\\alpha |\\beta) = \\frac{P(\\beta |\\alpha) * P(\\alpha)}{P(\\beta)}\n\\] Here, \n\\begin{enumerate}\n    \\item \\(\\alpha\\), \\(\\beta\\) = Event \n    \\item \\(P(\\alpha)\\), \\(P(\\beta)\\) = Probability of event occurring \n    \\item \\(P(\\alpha |\\beta)\\) = Probability of \\(\\alpha\\) happening such that \\(\\beta\\) is true\n\\end{enumerate}\n\n\\section{Introduction}\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{1}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{k+kn}{import} \\PY{n+nn}{numpy} \\PY{k}{as} \\PY{n+nn}{np}\n\\PY{k+kn}{import} \\PY{n+nn}{matplotlib}\\PY{n+nn}{.}\\PY{n+nn}{pyplot} \\PY{k}{as} \\PY{n+nn}{plt}\n\\PY{k+kn}{import} \\PY{n+nn}{pandas} \\PY{k}{as} \\PY{n+nn}{pd}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{naive\\PYZus{}bayes} \\PY{k+kn}{import} \\PY{n}{GaussianNB}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{model\\PYZus{}selection} \\PY{k+kn}{import} \\PY{n}{train\\PYZus{}test\\PYZus{}split}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{metrics} \\PY{k+kn}{import} \\PY{n}{confusion\\PYZus{}matrix}\\PY{p}{,} \\PY{n}{accuracy\\PYZus{}score}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{2}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{dataset} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{read\\PYZus{}csv}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{./data/flu.csv}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{3}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X\\PYZus{}raw} \\PY{o}{=} \\PY{n}{dataset}\\PY{o}{.}\\PY{n}{iloc}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,}\\PY{l+m+mi}{0}\\PY{p}{:}\\PY{o}{\\PYZhy{}}\\PY{l+m+mi}{1}\\PY{p}{]}\n\\PY{n}{y} \\PY{o}{=} \\PY{n}{dataset}\\PY{o}{.}\\PY{n}{iloc}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,}\\PY{o}{\\PYZhy{}}\\PY{l+m+mi}{1}\\PY{p}{]}\n\\PY{n}{map\\PYZus{}dict} \\PY{o}{=} \\PY{p}{\\PYZob{}}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Y}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{N}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mi}{0}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{No}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mi}{0}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Mild}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Strong}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mi}{2}\\PY{p}{\\PYZcb{}}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{4}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{dataset}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{4}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n   Chills Runny\\_nose Headache Fever Flu\n0       Y          N     Mild     Y   N\n1       Y          Y       No     N   Y\n2       Y          N   Strong     Y   Y\n3       N          Y     Mild     Y   Y\n4       N          N       No     N   N\n5       N          Y   Strong     Y   Y\n6       N          Y   Strong     N   N\n7       Y          Y     Mild     Y   Y\n8       N          Y   Strong     Y   Y\n9       Y          Y     Mild     Y   Y\n10      N          N       No     N   N\n11      Y          Y   Strong     Y   Y\n12      Y          N   Strong     Y   Y\n13      Y          N     Mild     Y   Y\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{5}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{DataFrame}\\PY{p}{(}\\PY{p}{)}\n\\PY{k}{for} \\PY{n}{x} \\PY{o+ow}{in} \\PY{n}{X\\PYZus{}raw}\\PY{p}{:}\n    \\PY{n}{X}\\PY{p}{[}\\PY{n}{x}\\PY{p}{]} \\PY{o}{=} \\PY{n}{X\\PYZus{}raw}\\PY{p}{[}\\PY{n}{x}\\PY{p}{]}\\PY{o}{.}\\PY{n}{map}\\PY{p}{(}\\PY{n}{map\\PYZus{}dict}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{6}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X}\\PY{o}{.}\\PY{n}{head}\\PY{p}{(}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{6}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n   Chills  Runny\\_nose  Headache  Fever\n0       1           0         1      1\n1       1           1         0      0\n2       1           0         2      1\n3       0           1         1      1\n4       0           0         0      0\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{7}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{y}\\PY{o}{.}\\PY{n}{head}\\PY{p}{(}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{7}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n0    N\n1    Y\n2    Y\n3    Y\n4    N\nName: Flu, dtype: object\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{8}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{X\\PYZus{}test}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}test} \\PY{o}{=} \\PY{n}{train\\PYZus{}test\\PYZus{}split}\\PY{p}{(}\\PY{n}{X}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{test\\PYZus{}size}\\PY{o}{=}\\PY{o}{.}\\PY{l+m+mi}{5}\\PY{p}{,} \\PY{n}{random\\PYZus{}state}\\PY{o}{=}\\PY{l+m+mi}{42}\\PY{p}{)} \n\\PY{n}{model} \\PY{o}{=} \\PY{n}{GaussianNB}\\PY{p}{(}\\PY{p}{)}\\PY{o}{.}\\PY{n}{fit}\\PY{p}{(}\\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\\PY{o}{.}\\PY{n}{values}\\PY{o}{.}\\PY{n}{ravel}\\PY{p}{(}\\PY{p}{)}\\PY{p}{)}\n\\PY{n}{predicted\\PYZus{}y} \\PY{o}{=} \\PY{n}{model}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{X\\PYZus{}test}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{11}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Accuracy:}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{accuracy\\PYZus{}score}\\PY{p}{(}\\PY{n}{y\\PYZus{}test}\\PY{p}{,} \\PY{n}{predicted\\PYZus{}y}\\PY{p}{)}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Confusion Matrix:}\\PY{l+s+se}{\\PYZbs{}n}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{n}{confusion\\PYZus{}matrix}\\PY{p}{(}\\PY{n}{y\\PYZus{}test}\\PY{p}{,} \\PY{n}{predicted\\PYZus{}y}\\PY{p}{)}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\nAccuracy: 0.8571428571428571\nConfusion Matrix:\n [[0 1]\n [0 6]]\n    \\end{Verbatim}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{12}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{k}{def} \\PY{n+nf}{make\\PYZus{}prediction}\\PY{p}{(}\\PY{n}{case}\\PY{p}{)}\\PY{p}{:}\n    \\PY{n}{df} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{DataFrame}\\PY{p}{(}\\PY{n}{case}\\PY{p}{)}\\PY{p}{[}\\PY{l+m+mi}{0}\\PY{p}{]}\\PY{o}{.}\\PY{n}{map}\\PY{p}{(}\\PY{n}{map\\PYZus{}dict}\\PY{p}{)}\n    \\PY{k}{return} \\PY{n}{model}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{p}{[}\\PY{n}{df}\\PY{p}{]}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{13}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{make\\PYZus{}prediction}\\PY{p}{(}\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Y}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{N}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Mild}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Y}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{]}\\PY{p}{)}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\n['Y']\n    \\end{Verbatim}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{14}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{make\\PYZus{}prediction}\\PY{p}{(}\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{N}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{N}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{Mild}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}}\\PY{l+s+s2}{N}\\PY{l+s+s2}{\\PYZdq{}}\\PY{p}{]}\\PY{p}{)}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\n['N']\n    \\end{Verbatim}", "meta": {"hexsha": "a0fe2f4ddd3c898baae5b1ccbbd7cb3507b6f09d", "size": 10838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MCA/Machine Learning/Project file/Tex source/Naive Bayes.tex", "max_stars_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_stars_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-13T12:34:51.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-02T18:54:22.000Z", "max_issues_repo_path": "MCA/Machine Learning/Project file/Tex source/Naive Bayes.tex", "max_issues_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_issues_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MCA/Machine Learning/Project file/Tex source/Naive Bayes.tex", "max_forks_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_forks_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_forks_repo_licenses": ["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.1759259259, "max_line_length": 515, "alphanum_fraction": 0.6004797933, "num_tokens": 4396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6477431072826957}}
{"text": "% When using TeXShop on the Mac, let it know the root document. The following must be one of the first 20 lines.\n% !TEX root = ../design.tex\n\n\\chapter[Sandwich Estimators]{Sandwich Estimators}\n\n\n\\section{Introduction}\nGiven a regression setup of $n$ data points, each defined by a feature  vector $x_i$ and a category $y_i$, we assume that $y_i$ is controlled by a $k$-dimensional parameter vector $\\theta$.  Generally, we are interested in finding the values of $\\theta$ that best predict $y_i$ from $x_i$, with \\textit{best} being defined as the values that maximize some likelihood function $L(y,x,\\theta)$.  The maximization is typically solved using the derivative of the likelihood $\\psi$  and the Hessian $H$.  More formally, $\\psi$ is defined as \n\\begin{align}\n  \\psi(y_i,x_i, \\theta) = \\frac{\\partial l(x_i,y_i,\\theta)}{\\partial \\theta}\n\\end{align} \nand $H$ is defined as\n\\begin{align}\nH(y,x, \\theta) = \\frac{\\partial^2 L(x,y,\\theta)}{\\partial \\theta^2}.\n\\end{align} \n\n\n\nIn addition to the values of $\\theta$, we may also be interested in the covariance matrix $S(\\theta)$ of $\\theta$.  This can be expressed in a \\textit{sandwich formulation}, of the form\n\\begin{align}\nS(\\theta) = B(\\theta) M(\\theta) B(\\theta).  \n\\end{align}\nThe $B(\\theta)$ matrix is commonly called the \\textit{bread}, whereas the $M(\\theta)$ matrix is the \\textit{meat}.  \n\n\\subsection{The Bread}\nComputing $B$ is relatively straightforward, \n\\begin{align}\nB(\\theta) = n\\left(\\sum_i^n -H(y_i, x_i, \\theta) \\right)^{-1}\n\\end{align}\n\n\\subsection{The Meat}\nThere are several choices for the $M$ matrix, each with different robustness properties.  The estimators we are interested in for this implementation are the Huber/White estimator, and the clustered estimator.  \n\nIn the Huber/White estimator, the matrix $M$ is defined as\n\\begin{align}\nM_{H} = \\sum_i^n \\psi(y_i,x_i, \\theta)^T  \\psi(y_i,x_i, \\theta).\n\\end{align}\n\n%The Huber/White estimator is a diagonal matrix defined as\n%\\begin{align}\n%M_W =\\frac{1}{n} X^T \\left(\n%      \\begin{array}{cccc}\n%        r(y_1, x_1^T\\theta) & 0&\\ldots &0 \\\\\n%        0&r(y_2, x_2^T\\theta) &\\dots& \\vdots \\\\\n%\t\\vdots & \\vdots & \\ddots&\\vdots \\\\\n%        0 & \\ldots & \\ldots &r(y_n, x_n^T\\theta)\n%      \\end{array} \\right) X.\n%\\end{align}\n%The matrix $X$ is the data matrix, and $r$ is the residual function.  The residual function is defined by the application, but it has the relationship\n%\\begin{align}\n%  \\psi(y_i,x_i, \\theta) = r(y_i, x_i^T\\theta)x_i.  \n%\\end{align} \n%This means that it can be computed in the general case as \n%\\begin{align}\n% r(y_i, x_i^T\\theta) =  \\frac{\\psi(y_i,x_i, \\theta)}{x_i}\n%\\end{align}\n%\n%In the case of the clustered sandwich estimator, $M$ is defined as \n\n\n\n\n%In addition to the computational expense of computing the Hessian, the inverse Hessian must be computed as well.  Unfortunately, matrix inversion is an expensive operation, and  cannot be parallelized.  \n\n", "meta": {"hexsha": "cf1220fd18b46bab667c39d28345d91c4cafd78c", "size": 2916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/design/modules/sandwich-estimators.tex", "max_stars_repo_name": "fmcquillan99/apache-madlib", "max_stars_repo_head_hexsha": "e2dea62d1eadc7f662f2d926c71f42332f414ca0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-18T07:44:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T19:45:18.000Z", "max_issues_repo_path": "doc/design/modules/sandwich-estimators.tex", "max_issues_repo_name": "fmcquillan99/apache-madlib", "max_issues_repo_head_hexsha": "e2dea62d1eadc7f662f2d926c71f42332f414ca0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-06T05:50:17.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-06T05:50:17.000Z", "max_forks_repo_path": "doc/design/modules/sandwich-estimators.tex", "max_forks_repo_name": "fmcquillan99/apache-madlib", "max_forks_repo_head_hexsha": "e2dea62d1eadc7f662f2d926c71f42332f414ca0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-03T20:50:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-03T20:50:13.000Z", "avg_line_length": 44.8615384615, "max_line_length": 536, "alphanum_fraction": 0.7009602195, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6477430976030625}}
{"text": "\\documentclass[jcp,aip,amsmath]{revtex4-1}\n\\usepackage{xcolor,array}\n\\usepackage{color}\n\\usepackage{txfonts}\n\n\\newcommand{\\half}{\\textstyle \\frac{1}{2}}\n\\newcommand{\\quarter}{\\textstyle \\frac{1}{4}}\n\n\n% note, to complile, do something like:\n%#!/bin/bash\n%file=$1\n%rm ``$file''.aux\n%latex ``$file''.tex\n%bibtex ''$file\"\n%latex ``$file\".tex\n%latex ''$file\".tex\n%dvips -Ppdf -o ``$file\".ps \"$file\".dvi\n%ps2pdf ``$file\".ps\n%echo  `` done compiling $file''\n%mupdf \"$file.pdf\" &\n\n\n\n\\begin{document}\n\n\n\n\\title{Evolvr Equations}\n\\author{Matthew K. MacLeod}\n\\maketitle\n\\today\n\n\\section{Maths.ex}\nThe code for following equations is located in lib/evolvr/maths.ex\n\n\\subsection{Linear Algebra}\ndot product, ie inner product, for two vectors,\n\\begin{align}\n\\mathbf{A} \\cdot \\mathbf{B} = A^\\dag B = \\sum_i^n A_i * B_i\n\\end{align}\n\nThe Euclidean norm, or distance is defined as\n\\begin{align}\nd_{euclid} (x,y) = \\left( \\sum_i^n (x_i - y_i)^2 \\right)^{1/2}\n\\end{align}\nThe Minkowski distance is defined as\n\\begin{align}\nd_{minkowski} (x,y,p) = \\left( \\sum_i^n |x_i - y_i|^{p} \\right)^{1/p}\n\\end{align}\nIt is interesting to note when p is 1, the taxicab distance (L1 norm) is recovered and\nthe L2 norm is recovered when p is 2.\n\nThe Mahalanobis distance is defined as\n\\begin{align}\nd_{mahalanobis} (x,y) = \\left( \\sum_i^n \\frac{(x_i - y_i)^2}{s^2_i} \\right)^{1/2} = \\left( \\sum_i^n \\frac{(x_i - y_i)^2}{ \\left(1/n *(x_i - \\bar{x})*(y_i-\\bar{y})\\right)^2} \\right)^{1/2}\n\\end{align}\n\nThe angle, in degrees, is defined\n\n\\begin{align}\n\\theta = \\frac{\\mathbf{v} \\cdot \\mathbf{w}}{||\\mathbf{v}||*||\\mathbf{w}||} * \\frac{180}{\\pi}\n\\end{align}\n\n\\subsection{Statistics}\n\nstandard deviation, $\\sigma$, is defined as, the square root of the variance\n\\begin{align}\n\\sigma = \\sqrt{v} =  \\sqrt{\\frac{1}{n}\\sum_i^n (x_i - \\mu)^2}\n\\end{align}\nwhere the mean, $\\mu$, is defined as\n\\begin{align}\n\\mu = \\frac{1}{n} \\sum_i^n x_i\n\\end{align}\n\nthe sample covariance is measures how two vectors vary together,\n\\begin{align}\n\\bar{\\bar{q}}= cov(x,y) = \\frac{1}{n-1} \\sum_i (x_i - \\bar{x}) (y_i - \\bar{y})\n\\end{align}\n\nThe reason the sample covariance matrix has $n-1$ in the denominator rather than $n$ is essentially that the population mean is not known and is replaced by the sample mean.\n\n\n\n\n\\subsection{Probability}\n The normal probability distribution (normal\\_pdf in code), the famous bell-shaped curve is\ndefined as\n\\begin{align}\nf(x|\\mu,\\sigma) = \\frac{1}{\\sqrt{2\\pi\\sigma}}\\mathrm{exp}\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2}\\right)\n\\end{align}\nand $\\mu$ is again the mean.\n\nThe beta distribution can be used for Bayesian inference (conditional probabilities) and is defined\n\\begin{align}\n\\mathrm{beta\\_pdf} = \\frac{x^{\\alpha-1}(1-x)^{\\beta-1}}{B(\\alpha,\\beta)}\n\\end{align}\n\nwhere $B(\\alpha,\\beta)$ is a normalization constant to ensure that the total probability integrates to 1.\nand is\n\\begin{align}\nB(\\alpha,\\beta) = \\frac{\\Gamma(\\alpha) \\Gamma(\\beta) }{\\Gamma(\\alpha + \\beta)}\n\\end{align}\nThis function uses the gamma function, which is the generalization of a factorial, and which is approximated in the code using Windschitl reworking of Stirlings as follows\n\\begin{align}\n\\Gamma(t) = \\int_0^{\\infty} x^{t-1} e^{-x} dx \\approx  \\sqrt{\\frac{2\\pi}{t}}\\left(\\frac{1}{e}\\left(t + \\frac{1}{12t -\\frac{1}{10t}}\\right)\\right)^t\n\\end{align}\n\nNote, especially for easy partial testing, positive integers should follow\n\\begin{align}\n\\Gamma(n)=(n-1)!\n\\end{align}\n\n\n\\subsection{Machine Learning}\n\n\n\\subsubsection{Gradient Descent}\nA numerical approximation to the derivative of a function is given by the finite differences method,\nalso known as the difference quotient is given by,\n\n\\begin{align}\nf' = f'(x) = \\frac{df(x)}{dx} \\approx \\frac{f(x+h) -f(x)}{h}\n\\end{align}\n\nnote that this method yields the total derivative of a function, not a partial derivative.\nAlso can be made slightly more accurate easily.\n\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "4a21dd61f74139305528f8dd6ae0c562cef0c45a", "size": 3890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/evolvr_equations.tex", "max_stars_repo_name": "matthewmacleod/evolvr", "max_stars_repo_head_hexsha": "6392f0e03a8218ea70e86afdd187dcf728155072", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-12-29T21:13:23.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-14T22:35:25.000Z", "max_issues_repo_path": "doc/evolvr_equations.tex", "max_issues_repo_name": "matthewmacleod/evolvr", "max_issues_repo_head_hexsha": "6392f0e03a8218ea70e86afdd187dcf728155072", "max_issues_repo_licenses": ["MIT"], "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/evolvr_equations.tex", "max_forks_repo_name": "matthewmacleod/evolvr", "max_forks_repo_head_hexsha": "6392f0e03a8218ea70e86afdd187dcf728155072", "max_forks_repo_licenses": ["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.3941605839, "max_line_length": 186, "alphanum_fraction": 0.6925449871, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6477430970758065}}
{"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\nA rhombus $R_{x_0, y_0, c, d}$ is a quadrilateral which has the vertices $(x_0-c, y_0)$, $(x_0, y_0-d)$, $(x_0+c, y_0)$, $(x_0, y_0+d)$ as shown in Figure \\ref{fig11}.\nProve that the class of rhombi  in $\\mathbb{R}^2$ for which the ratio $c/d$ is a constant is a PAC-learnable.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}\n\\begin{axis}[axis lines = middle, axis equal, ticks = none, xmin = -.5, xmax = 5.5, ymin = 1, ymax = 3, xlabel = {$x$}, ylabel = {$y$}, clip=false]\n\\addplot[domain=1:4]{(7-x)/3};\n\\addplot[domain=4:7]{(x-1)/3};\n\\addplot[domain=1:4]{(x+5)/3};\n\\addplot[domain=4:7]{(13-x)/3};\n\\addplot[loosely dashed] coordinates {(4,0.5) (4,3.5)};\n\\addplot[loosely dashed] coordinates {(0.5,2) (7.5,2)};\n\\addplot[mark=*] coordinates {(1,2)} node[above left] {$(x_0-c,y_0)$};\n\\addplot[mark=*] coordinates {(4,1)} node[below left] {$(x_0, y_0-d)$};\n\\addplot[mark=*] coordinates {(4,3)} node[above right] {$(x_0, y_0+d)$};\n\\addplot[mark=*] coordinates {(7,2)} node[below right] {$(x_0+c, y_0)$};\n\\end{axis}\n\\end{tikzpicture}\n\\caption{Rhombus having vertices $(x_0-c, y_0)$, $(x_0, y_0-d)$, $(x_0+c, y_0)$, $(x_0, y_0+d)$}\\label{fig11}\n\\end{figure}\n\n\\subsection*{Solution}\n\nSet of possible examples $\\mathcal{X}$ is $\\mathbb{R}^2$.\n$\\mathcal{R}$ is set of all rhombi with ratio $c/d$.\nTherefore, the concept $\\mathcal{C}$ would be a particular rhombus with ratio $c/d$.\n\nSuppose the rhombus shown in Figure \\ref{fig11} is a concept $c \\in \\mathcal{C}$ which is not known by the learner.\n\nAs the hypothesis $h_S$, formed by the learner, is also a rhombus, Figure \\ref{fig12} can be constructed in which $h_S$ is the rhombus formed by intersection of dashed lines.\nAreas enclosed by dashed lines and different edges of the concept rhombus are defined as $r_1$, $r_2$, $r_3$ and $r_4$.\n\n\\begin{figure}[H]\n\\centering\n\\begin{tikzpicture}\n\\begin{axis}[axis lines = middle, axis equal, ticks = none, xmin = -.5, xmax = 5.5, ymin = 1, ymax = 3, xlabel = {$x$}, ylabel = {$y$}, clip=false]\n\n\\addplot[domain=1:4]{(7-x)/3};\n\\addplot[domain=4:7]{(x-1)/3};\n\\addplot[domain=1:4]{(x+5)/3};\n\\addplot[domain=4:7]{(13-x)/3};\n\n\\addplot[mark=*] coordinates {(1,2)} node[above left] {$(x_0-c,y_0)$};\n\\addplot[mark=*] coordinates {(4,1)} node[below left] {$(x_0, y_0-d)$};\n\\addplot[mark=*] coordinates {(4,3)} node[above right] {$(x_0, y_0+d)$};\n\\addplot[mark=*] coordinates {(7,2)} node[below right] {$(x_0+c, y_0)$};\n\n\\addplot[domain=1:6, dashed]{(8.5-x)/3};\n\\addplot[domain=3:8, dashed]{(12-x)/3};\n\\addplot[domain=3:8, dashed]{(x)/3};\n\\addplot[domain=1:6, dashed]{(x+4)/3};\n\n\\addplot[mark=none] coordinates {(2.8,1.7)} node[below right] {$r_1$};\n\\addplot[mark=none] coordinates {(2.8,2.7)} node[below right] {$r_2$};\n\\addplot[mark=none] coordinates {(5,1.8)} node[below right] {$r_3$};\n\\addplot[mark=none] coordinates {(5,2.6)} node[below right] {$r_4$};\n\n\\end{axis}\n\\end{tikzpicture}\n\\caption{Rhombus having vertices $(x_0-c, y_0)$, $(x_0, y_0-d)$, $(x_0+c, y_0)$, $(x_0, y_0+d)$}\\label{fig12}\n\\end{figure}\n\nSuppose the probability of the generalization error defined as in Equation \\ref{eq11} would be less than $\\epsilon$.\n\n\\begin{equation}\\label{eq11}\nR(h) = P({x\\in \\mathcal{X} | h_s(x) \\neq c(x)})\n\\end{equation}\n\nThis means that probability of the hypothesis $h_S$ is at least $1 - \\epsilon$.\nThis means that the rhombus $h_s$ must intersect at least one of $r_1$, $r_2$, $r_3$ or $r_4$.\nTherefore,\n\n\\begin{equation}\n\\begin{aligned}\nP(R(h_S)>\\epsilon) &\\leq P_{S~D}( \\bigcup_{i=1}^{4}[(h_S \\cap r_i)] = \\emptyset )\\\\\n&\\leq \\sigma_{i=1}^{4} P((h_S \\cap r_i) = \\emptyset)\\\\\n&\\leq 4(1 - \\frac{\\epsilon}{4})^m\n\\end{aligned}\n\\end{equation}\n\nSince for all $x \\in \\mathbb{R}$ we have $1 - x \\leq \\exp^{-x}$,\n\n\\begin{equation}\n\\begin{aligned}\nP(R(h_S)>\\epsilon) &\\leq 4(1 - \\frac{\\epsilon}{4})^m\\\\\n&\\leq 4 \\times \\exp^{-\\frac{m\\epsilon}{4}}\n\\end{aligned}\\label{eq13}\n\\end{equation}\n\nSince $P(R(h_S) > \\epsilon) \\leq \\delta$,\n\n\\begin{equation}\\label{eq14}\n4\\exp^{-\\frac{m\\epsilon}{4}} \\leq \\delta\n\\end{equation}\n\nTherefore,\n\n\\begin{equation}\\label{eq15}\nm \\geq \\frac{4}{\\epsilon} \\log \\frac{4}{\\delta}\n\\end{equation}\n\nGiven that $\\log u \\leq u - 1$,\n\n\\begin{equation}\\label{eq16}\n\\begin{aligned}\nm &\\geq \\frac{4}{\\epsilon} \\log \\frac{4}{\\delta}\\\\\n& \\geq \\frac{4}{\\epsilon} (\\frac{4}{\\delta} - 1)\n\\end{aligned}\n\\end{equation}\n\nAnd we have shown that there is a polynomial $p(\\frac{1}{\\epsilon}, \\frac{1}{\\delta})$ such that if $m \\geq p(\\frac{1}{\\epsilon},\\frac{1}{\\delta},n,size(c))$, then there is an algorithm producing $h_S$ such that $P(R(h_s) \\leq \\epsilon) \\geq 1 - \\delta$.\nHence we have shown by definition that the class of rhombi with ratio $c/d$ is PAC learnable.\n", "meta": {"hexsha": "1e0cbd30f62b0eb5e7bd34ac70925edd75b6288a", "size": 5031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw02/hw02q01.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/hw02/hw02q01.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/hw02/hw02q01.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": 40.9024390244, "max_line_length": 254, "alphanum_fraction": 0.6398330352, "num_tokens": 1941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.6477430960212935}}
{"text": "\\chapter{Correlation and Regression}\n\n\\section*{6.1. Alternative forms of Cov(x, y) and $\\bm{\\widetilde{s}}$}\n\\addcontentsline{toc}{section}{6.1. Alternative forms of Cov(x, y) and $\\widetilde{s}$}\n\\begin{enumerate}[(a)]\n    \\item Show that the Cov(x, y) defined in Eq. (6.11) can be written\n        as  $\\langle xy \\rangle - \\langle x \\rangle \\langle y \\rangle$ \n        ($\\langle x \\rangle$ means the same thing as $\\overline{x})$\n\n    \\item Show that the $\\widetilde{s}^2$ defined in Eq. (3.60) can be\n        written  as $\\langle x^2 \\rangle - \\langle x \\rangle^2$\n\\end{enumerate}\n\n\\vspace{1em}\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item We start with Eq. (6.11) and use the average formula to obtain the desired result:\n            \\begin{align*}\n                \\text{Cov}(x, y) \n                = \\frac{1}{n} \\sum_{i = 1}^n (x_i - \\langle x \\rangle)(y_i - \\langle y \\rangle)\n                &= \\frac{1}{n} \\sum_{i = 1}^n (x_iy_i - \\langle x \\rangle y_i - \\langle y \\rangle x_i +  \n                    \\langle x \\rangle \\langle y \\rangle) \\\\\n                &= \\langle xy \\rangle - 2 \\langle x \\rangle \\langle y \\rangle \n                    + \\langle x \\rangle \\langle y \\rangle\n                = \\langle xy \\rangle - \\langle x \\rangle \\langle y \\rangle\n            \\end{align*}\n\n        \\item Similarly to (a), we start from Eq. (3.60) and find that:\n            \\begin{align*}\n                \\widetilde{s}^2 \n                = \\frac{1}{n} \\sum_{i = 1}^n (x_i - \\langle x \\rangle)^2\n                = \\frac{1}{n} \\sum_{i = 1}^n (x_i^2 - 2x_i \\langle x \\rangle + \\langle x \\rangle^2)\n                = \\langle x^2 \\rangle - 2\\langle x \\rangle^2 + \\langle x \\rangle^2\n                = \\langle x^2 \\rangle + \\langle x \\rangle^2 \n            \\end{align*}\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{6.2. Rescaling X}\n\\addcontentsline{toc}{section}{6.2. Rescaling X}\nUsing Eq. (6.9), we showed in the third remark on page 287 that the\ncorrelation coefficient $r$ doesn't change with a uniform scaling of\n$X$ or $Y$. Demonstrate this again here by using the expression\nfor $r$ in Eq. (6.6).\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let $X' = aX$ and $Y' = bY$, where $a$ and $b$ are numerical values.\n    Since $Y = mX + Z$, we notice the equivalence:\n    \\[\n        bY = bmX + bZ \\iff Y' = m'X' + cZ\n    \\] \n    where $m = bm/a$ and $c$ is a numerical value that we don't care about\n    since the correlation coefficient $r$ does not depend on $Z$.\n    From $(6.6)$ and the fact that $\\text{Var}(aX) = a^2\\text{Var}(X)$, we obtain:\n     \\[\n         r' \n         = \\frac{m'\\sigma_{X'}}{\\sigma_{Y'}} \n         = \\frac{abm\\sigma_{X}}{ab\\sigma_{Y}}\n         = \\frac{m\\sigma_X}{\\sigma_Y} \n         = r\n    \\] \n    which proves once again that the correlation coefficient $r$ doesn't \n    change with a uniform scaling of $X$ or $Y$.\n\\end{proof}\n\n\\section*{6.3. Uncorrelated vs. independent}\n\\addcontentsline{toc}{section}{6.3. Uncorrelated vs. independent}\nIf two random variables $X$ and $Y$ are independent, are they necessarily\nalso uncorrelated? If they are uncorrelated, are they necessarily also independent?\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(i)]\n        \\item Suppose $X$ and $Y$ are independent. We then have that $\\text{Cov}(X, Y) = 0$, so,\n            the correlation coefficient is given by (6.9):\n            \\[\n                r = \\frac{\\text{Cov}(X, Y)}{\\sigma_X\\sigma_Y} = 0\n            \\] \n            As a result, if $X$ and $Y$ are independent, then they are also uncorrelated.\n\n        \\item We'll prove that correlation does not imply independence by giving a counterexample.\n            Let $X$ be a discrete random variable with $P(X = 0) = P(X = 1) =$ 1/2 and let\n            $Y = -X$. $X$ and $Y$ are independent and their covariance is given by\n            \\[\n                \\text{Cov}(X, Y) = E[XY] - \\mu_X\\mu_Y \n                = -E[X^2] + \\frac{1}{4} \n                = -\\bigg(\\frac{1}{4} \\cdot 1 + \\frac{3}{4} \\cdot 0\\bigg) + \\frac{1}{4}\n                = 0\n            \\] \n            so, by (6.9), $r = 0$. Therefore, two random variables can be uncorrelated\n            without being necessarily independent.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{6.4. Sum of two Gaussians (TO DO: PDF of sum)}\n\\addcontentsline{toc}{section}{6.4. Sum of two Gaussians}\nGiven two independent Gaussian distributions $X$ and $Y$ with\nstandard deviations $\\sigma_X$ and $\\sigma_Y$, show that the sum\n$Z \\equiv X + Y$ is a Gaussian distribution with standard\ndeviation $\\sqrt{\\sigma_X^2 + \\sigma_Y^2}$. You may assume without\nloss of generality that the means are zero.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We start by seeing that\n    \\[\n        \\mu_Z = E[Z] = E[X + Y] = \\mu_X + \\mu_Y\n    \\] \n\n    Now, by using the variance formula\n    \\[\n        \\sigma_Z^2 = E[Z^2] - \\mu_Z^2 \n        = E[(X+Y)^2] - \\mu_Z^2\n        = E[X^2 + 2XY + Y^2] - \\mu_Z^2\n    \\] \n\n    By using the linearity of expectation and then the fact that $X$ and $Y$ are\n    independent, our expression becomes:\n     \\[\n         \\sigma_Z^2 \n         = E[X^2] + 2E[X]E[Y] + E[Y^2] - \\mu_Z^2\n         = E[X^2] + 2\\mu_X\\mu_Y + E[Y^2] - \\mu_Z^2\n    \\] \n\n    We expand $\\mu_Z^2$ and notice the expressions of $\\sigma_X^2$ and $\\sigma_Y^2$:\n     \\[\n         \\sigma_Z^2 = E[X^2] - \\mu_X^2 + E[Y^2] - \\mu_Y^2 = \\sigma_X^2 + \\sigma_Y^2\n    \\] \n\n    Finally, we take the square root of the variance to get the standard deviation:\n    \\[\n        \\sigma_Z = \\sqrt{\\sigma_X^2 + \\sigma_Y^2}\n    \\] \n\\end{proof}\n\n\\section*{6.5. Maximum $\\bm{\\rho(x, y)}$}\n\\addcontentsline{toc}{section}{6.5. Maximum $\\rho(x, y)$}\nFor a given $y_0$, what value of $x$ maximizes the probability density\n$\\rho(x, y_0)$ in Eq. (6.34)?\n\n\\vspace{1em}\n\n\\begin{proof}\n    The joint probability density $\\rho(x, y_0)$ is given by\n    \\begin{equation*}\\tag{6.34}\n        \\rho(x, y) = \\frac{1}{2\\pi\\sigma_X\\sigma_Y\\sqrt{1 - r^2}} \n        \\exp\\bigg(-\\frac{1}{2(1 - r^2)}\\bigg(\\frac{x^2}{\\sigma_X^2} \n            + \\frac{y_0^2}{\\sigma_Y^2} - \\frac{2rxy_0}{\\sigma_X\\sigma_Y}\\bigg)\\bigg)\n    \\end{equation*}\n\n    Let\n    \\[\n        \\phi(x) \n        = \\bigg(\\frac{x^2}{\\sigma_X^2} + \\frac{y_0^2}{\\sigma_Y^2} - \\frac{2rxy_0}{\\sigma_X\\sigma_Y}\\bigg) \n    \\] \n\n    We notice that $x$ is used only in the second factor of the exponential, so\n    $\\rho(x, y_0)$ is maximised when $\\phi(x)$ is minimised (there is a \"-\" sign in the exponential). We take the derivative of $\\phi(x)$\n    with respect to $x$ and  obtain\n    \\[\n        \\pdv{x} \\phi(x) \n        = \\pdv{x} \\bigg(\\frac{x^2}{\\sigma_X^2} + \\frac{y_0^2}{\\sigma_Y^2} - \\frac{2rxy_0}{\\sigma_X\\sigma_Y}\\bigg) \n        = \\frac{2x}{\\sigma_X^2} - \\frac{2ry_0}{\\sigma_X\\sigma_Y}\n        = \\frac{2x\\sigma_Y - 2ry_0\\sigma_X}{\\sigma_X^2\\sigma_Y}\n    \\] \n\n    If we equalize the derivative with 0, we obtain the critical point\n    \\[\n        x_0 = ry_0 \\frac{\\sigma_X}{\\sigma_Y}\n    \\] \n\n    Since the derivative is negative on the left of $x_0$ and positive on the right of $x_0$,\n    we get that $x_0$ is the global minimum of $\\phi(x)$. As a result, $x_0$ is the global maximum\n    of $\\rho(x, y_0)$.\n\\end{proof}\n\n\\section*{6.8. Alternate form of B}\n\\addcontentsline{toc}{section}{6.8. Alternate form of B}\nShow that the second expression for $B$ in Eq. (6.49) equals\nthe first.\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\begin{align*}\\tag{6.49}\n        \\langle y \\rangle - A \\langle x \\rangle \n        = \\langle y \\rangle - \\langle x \\rangle \n        \\frac{\\langle xy \\rangle - \\langle x \\rangle \\langle y \\rangle}{\\langle x^2 \\rangle - \\langle x \\rangle^2}\n        &= \\frac{\\langle y \\rangle \\langle x^2 \\rangle - \\langle y \\rangle \\langle x \\rangle^2\n            - \\langle x \\rangle \\langle xy \\rangle - \\langle x \\rangle^2 \\langle y \\rangle}\n            {\\langle x^2 \\rangle - \\langle x \\rangle^2} \\\\\n        &= \\frac{\\langle y \\rangle \\langle x^2 \\rangle - \\langle x \\rangle \\langle xy \\rangle}\n            {\\langle x^2 \\rangle - \\langle x \\rangle^2}\n        = B\n    \\end{align*}\n\\end{proof}\n\n\\section*{6.9. Finding all the quantities}\n\\addcontentsline{toc}{section}{6.9. Finding all the quantities}\nGiven five ($X, Y$) points with values (2, 1), (3, 1), (3, 3),\n(5, 4), (7, 6), calculate (with a calculator) all of the quantities\nreffered to in the five steps listed on page 290. Also calculate\n$B$ in Eq. (6.49), and make a rough plot of the five given points\nalong with the regression (least-squares) line.\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[1.]\n        \\item Compute the means $\\overline{x}$ and $\\overline{y}$ of the $x_i$ and \n             $y_i$ data points:\n             \\[\n                 \\overline{x} = \\frac{2 + 3 + 3 + 5 + 7}{5} = 4\n                 \\hspace{2em}\n                 \\overline{y} = \\frac{1 + 1 + 3 + 4 + 6}{5} = 3\n             \\] \n\n         \\item Calculate the standard deviations $\\widetilde{s_x}$ and $\\widetilde{s_y}$ via \n             Eq. (3.60):\n             \\begin{align*}\n                 \\widetilde{s_x} = \\sqrt{\\frac{(2 - 4)^2 + (3 - 4)^2 + (3 - 4)^2 + (5 - 4)^2 + (7 - 4)^2}{5}} \n                    = \\frac{4}{\\sqrt{5}} \\approx 1.79 \\\\\n                \\widetilde{s_y} = \\sqrt{\\frac{(1 - 3)^2 + (1 - 3)^2 + (3 - 3)^2 + (4 - 3)^2 + (6 - 3)^2}{5}}\n                    = 3 \\sqrt{\\frac{2}{5}} \\approx 1.9\n             \\end{align*}\n            \n        \\item Calculate the covariance via Eq. (6.11):\n            \\begin{align*}\n                \\text{Cov}(x, y) \n                &= \\frac{(2 - 4)(1 - 3) + (3 - 4)(1 - 3) + \n                    (3 - 4)(3 - 3) + (5 - 4)(4 - 3) + (7 - 4)(6 - 3)}{5} \\\\\n                &= \\frac{16}{5} = 3.2\n            \\end{align*}\n\n        \\item Calculate $r$ via Eq. (6.12):\n            \\[\n                r = \\frac{\\text{Cov}(x, y)}{\\widetilde{s_x}\\widetilde{s_y}}\n                = \\frac{3.2}{1.79 \\cdot 1.9} \\approx 0.94\n            \\] \n\n        \\item Calculate $m$ from Eq. (6.18), with the $\\sigma$'s replaced with $\\widetilde{s}$'s :\n            \\[\n                m = \\frac{r\\widetilde{s_y}}{\\widetilde{s_x}} \n                = \\frac{0.94 \\cdot 1.9}{1.79} \\approx 1\n            \\] \n        \\end{enumerate}\n        \\begin{figure}[H]     \n        \\center{\\includegraphics[width=0.50\\linewidth]{figure_6_9.png}}\n        \\end{figure}\n\\end{proof}\n\n\\section*{6.10. Equal distances}\n\\addcontentsline{toc}{section}{6.10. Equal distances}\nIn Section 6.9. we defined the best-fit line as the line that minimizes\nthe sum of the squares of the vertical distance from the given point\nto the line. Let's kick things down a dimension and look at the 1-D\ncase where we have $n$ values $x_i$ lying on the $x$ axis. We'll define\nthe \"best-fit\" point as the value of $x$ (call it $x_b$) that minimizes \nthe sum of the squares of the distances from the  $n$ given $x_i$ points\nto the $x_b$ point.\n\n\\begin{enumerate}[(a)]\n    \\item Show that $x_b$ is the mean of the $x_i$ values.\n    \n    \\item Show that the sum of all the distances from $x_b$ to the\n        points with $x_i > x_b$ equals the sum of all the distances\n        from $x_b$ to the points with $x_i < x_b$.\n\\end{enumerate}\n\n\\vspace{1em}\n\n\\begin{proof}\n    \\hfill\n    \\begin{enumerate}[(a)]\n        \\item Let us define\n            \\[\n                S \\equiv \\frac{1}{n} \\sum_{i = 1}^n (x_i - x_b)^2\n            \\] \n            \n        The value for $x_b$ for which $S$ is minimized can be found between the values\n        for which the derivative of $S$ with respect to $x_b$ is 0. We have that:\n        \\[\n            \\pdv{x_b}S = \\frac{1}{n} \\sum_{i = 1}^n \\pdv{x_b}(x_i^2 - 2x_i x_b + x_b^2) \n            = \\frac{1}{n} \\sum_{i = 1}^n (2x_b - 2x_i) = 2x_b - \\frac{2}{n} \\sum_{i = 1}^n x_i\n            = 2x_b - 2\\overline{x}\n        \\] \n\n        Therefore, $x_b = \\overline{x}$ is a critical point for $S$. Since the slope\n        of $S$ is positive and then negative around $x_b$, we obtain that $x_b = \\overline{x}$\n        is an absolute minimum point for $S$. \n\n    \\item We can assume without loss of generality that the points are labeled such that\n        for $i \\leq M$, $x_i < x_b$ and for $i > M, x_i > x_b$. Hence, there are $M$ points\n        that are less than $x_b$ and $(n - M)$ points that are greater than $x_b$. Our\n        hypothesis becomes equivalent with the expression \n        \\[\n            \\sum_{i = 1}^M (x_b - x_i) = \\sum_{i = M + 1}^n (x_i - x_b)\n        \\] \n        We separate the $x_b$ terms from the sums and obtain that\n        \\[\n            Mx_b - \\sum_{i = 1}^M x_i = (M - n) x_b + \\sum_{i = M + 1}^n x_i\n        \\] \n\n        If we isolate the $x_b$ from the sum terms, we have that\n        \\[\n            nx_b = \\sum_{i = 1}^{n} x_i\n        \\] \n\n        which with $x_b = \\overline{x}$, the result that we proved at (a). Therefore,\n        we proved the hypothesis.\n    \\end{enumerate}\n\\end{proof}\n\n\\section*{6.11. Equal distances again}\n\\addcontentsline{toc}{section}{6.11. Equal distances again}\nReturning to 2-D, show that the sum of all the vertical distances from \nthe least-squares line to the points above it equals the sum of all the vertical\ndistances from the line to the points below it. $\\emph{Hint:}$ Consider an appropriate\npartial derivative of the sum $S$ in Eq. (6.42).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The solution is similar to 6.10b. We assume without loss of generality that \n    the $n$ points are labeled such that for $i \\leq M$,\n    $y_i < Ax_i + B$ and  for $i > M, y_i > Ax_i + B$. Hence, there are $M$ \n    points that are under the least-squares line and $(n - M)$ above it. \n    Our hypothesis becomes equivalent with the expression\n    \\[\n        \\sum_{i = 1}^M (Ax_i + B - y_i) = \\sum_{i = M + 1}^n (y_i - Ax_i + B)\n    \\] \n    We expand the sum to obtain that\n    \\[\n        A \\sum_{i = 1}^M x_i + BM - \\sum_{i = 1}^M y_i \n        = \\sum_{i = M + 1}^n y_i - A\\sum_{i = M + 1}^n x_i + (n - M)B\n    \\] \n    We separate the $B$ terms from the rest of the expression and get that\n    \\[\n        nB = \\sum_{i = 1}^n y_i - A\\sum_{i = 1}^n x_i \n    \\] \n    which if we divide by $n$ and rewrite using the average operator, is equivalent with\n    \\begin{equation}\\tag{6.49}\n        B = \\langle y \\rangle - A \\langle x \\rangle\n    \\end{equation}\n    which we know it's true. Therefore, we proved our hypothesis.\n\\end{proof}\n", "meta": {"hexsha": "3fd1e9dcc028c34f4ee06a5c059731a2467c6816", "size": 14242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter6_correlation_and_regression.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/chapter6_correlation_and_regression.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/chapter6_correlation_and_regression.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": 40.2316384181, "max_line_length": 137, "alphanum_fraction": 0.5642465946, "num_tokens": 4836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6477430906407197}}
{"text": "\\chapter{Differentiation}\n\\section{Definition}\n\\prototype{$x^3$ has derivative $3x^2$.}\n\nI suspect most of you have seen this before, but:\n\\begin{definition}\n\tLet $U$ be an open subset\\footnote{We\n\t\twill almost always use $U = (a,b)$ or $U = \\RR$,\n\t\tand you will not lose much by restricting\n\t\tthe definition to those.}\n\tof $\\RR$ and let $f \\colon U \\to \\RR$ be a function.\n\tLet $p \\in U$.\n\tWe say $f$ is \\vocab{differentiable} at $p$\n\tif the limit\\footnote{Remember we are following the convention in\n\t\t\\Cref{abuse:limit}.\n\t\tSo we mean ``the limit of the function $h \\mapsto \\frac{f(p+h)-f(p)}{h}$\n\t\texcept the value at $h=0$ can be anything''.\n\t\tAnd this is important because that fraction\n\t\tdoes not have a definition at $h = 0$.\n\t\tAs promised, we pay this no attention.}\n\t\\[ \\lim_{h \\to 0} \\frac{f(p+h) - f(p)}{h} \\]\n\texists.\n\tIf so, we denote its value by $f'(p)$ and refer\n\tto this as the \\vocab{derivative} of $f$ at $p$.\n\n\tThe function $f$ is differentiable if it is differentiable\n\tat every point.\n\tIn that case, we regard the derivative $f' \\colon (a,b) \\to \\RR$\n\tas a function it its own right.\n\\end{definition}\n\n\\begin{exercise}\n\tShow that if $f$ is differentiable at $p$\n\tthen it is continuous at $p$ too.\n\\end{exercise}\n\nHere is the picture.\nSuppose $f \\colon \\RR \\to \\RR$ is differentiable\n(hence continuous).\nWe draw a graph of $f$ in the usual way and consider values of $h$.\nFor any nonzero $h$, what we get is the slope of the \\emph{secant}\nline joining $(p, f(p))$ to $(p+h, f(p+h))$.\nHowever, as $h$ gets close to zero,\nthat secant line begins to approach a line\nwhich is tangent to the graph of the curve.\nA picture with $f$ a parabola is shown below,\nwith the tangent in red, and the secant in dashed green.\n\n\\begin{center}\n\\begin{asy}\n\timport graph;\n\tsize(8cm);\n\treal f(real x) { return (x-2)*(x-2)/2 - 0.1; }\n\tgraph.xaxis(\"$x$\");\n\tgraph.yaxis(\"$y$\");\n\tdraw(graph(f,-1,5,operator ..), blue, Arrows);\n\tpair P = (3, f(3));\n\tdot(\"$(p, f(p))$\", P, dir(-20), red);\n\tdraw((1.8,-0.8)--(4.2, 1.6), red);\n\tlabel(\"Slope $f'(p)$\", (4.2, 1.6), dir(-25), red);\n\tpair Q = (4.3, f(4.3));\n\tdot(\"$(p+h, f(p+h))$\", Q, dir(-20), deepgreen);\n\tdraw(P--Q, dashed+deepgreen);\n\tlabel(\"Slope $\\frac{f(p+h)-f(p)}{h}$\", P--Q, 1.5*dir(165), deepgreen);\n\\end{asy}\n\\end{center}\n\nSo the picture in your head should be that\n\\begin{moral}\n\t$f'(p)$ looks like the slope of the tangent line at $(p, f(p))$.\n\\end{moral}\n\n\\begin{remark}\n\tNote that the derivatives are defined\n\tfor functions on \\emph{open} intervals.\n\tThis is important.\n\tIf $f \\colon [a,b] \\to \\RR$ for example,\n\twe could still define the derivative at each interior point,\n\tbut $f(a)$ no longer makes sense\n\tsince $f$ is not given a value on any open neighborhood of $a$.\n\\end{remark}\n\nLet's do one computation and get on with this.\n\\begin{example}\n\t[Derivative of $x^3$ is $3x^2$]\n\tLet $f \\colon \\RR \\to \\RR$ by $f(x) = x^3$.\n\tFor any point $p$, and \\emph{nonzero} $h$ we can compute\n\t\\begin{align*}\n\t\t\\frac{f(p+h) - f(p)}{h} &= \\frac{(p+h)^3 - p^3}{h} \\\\\n\t\t&= \\frac{3p^2h + 3ph^2 + h^3}{h} \\\\\n\t\t&= 3p^2 + 3ph + h^2.\n\t\\end{align*}\n\tThus,\n\t\\[ \\lim_{h \\to 0} \\frac{f(p+h)-f(p)}{h}\n\t\t= \\lim_{h \\to 0} (3p^2+3ph+h^2) = 3p^2. \\]\n\tThus the slope at each point of $f$ is given by the formula $3p^2$.\n\tIt is customary to then write $f'(x) = 3x^2$\n\tas the derivative of the entire function $f$.\n\\end{example}\n\\begin{abuse}\n\tWe will now be sloppy and write this as $(x^3)' = 3x^2$.\n\tThis is shorthand for the significantly more verbose\n\t``the real-valued function $x^3$ on domain so-and-so\n\thas derivative $3p^2$ at every point $p$ in its domain''.\n\n\tIn general, a real-valued differentiable function\n\t$f \\colon U \\to \\RR$ naturally gives rise to derivative\n\t$f'(p)$ at every point $p \\in U$,\n\tso it is customary to just give up on $p$ altogether\n\tand treat $f'$ as function itself $U \\to \\RR$,\n\teven though this real number is of a ``different interpretation'':\n\t$f'(p)$ is meant to interpret a slope (e.g.\\ your hourly pay rate)\n\tas opposed to a value (e.g.\\ your total dollar worth at time $t$).\n\tIf $f$ is a function from real life, the units do not even match!\n\n\tThis convention is so deeply entrenched I cannot uproot it\n\twithout more confusion than it is worth.\n\tBut if you read the chapters on multivariable calculus\n\tyou will see how it comes back to bite us,\n\twhen I need to re-define the derivative to be a \\emph{linear map},\n\trather than single real numbers.\n\\end{abuse}\n\n\\section{How to compute them}\nSame old, right?\nSum rule, all that jazz.\n\n\\begin{theorem}\n\t[Your friendly high school calculus rules]\n\tIn what follows $f$ and $g$ are differentiable functions,\n\tand $U$, $V$ are open subsets of $\\RR$.\n\t\\begin{itemize}\n\t\t\\ii (Sum rule) If $f,g \\colon U \\to \\RR$ then\n\t\tthen $(f+g)'(x) = f'(x) + g'(x)$.\n\n\t\t\\ii (Product rule) If $f,g \\colon U \\to \\RR$ then\n\t\tthen $(f \\cdot g)'(x) = f'(x) g(x) + f(x) g'(x)$.\n\n\t\t\\ii (Chain rule) If $f \\colon U \\to V$ and $g \\colon V \\to \\RR$\n\t\tthen the derivative of the composed function\n\t\t$g \\circ f \\colon U \\to \\RR$ is $g'(f(x)) \\cdot f'(x)$.\n\t\\end{itemize}\n\\end{theorem}\n\\begin{proof}\n\t\\begin{itemize}\n\t\\ii Sum rule: trivial, do it yourself if you care.\n\n\t\\ii Product rule: for every nonzero $h$ and point $p \\in U$\n\twe may write\n\t\\[\n\t\t\\frac{f(p+h) g(p+h) - f(p) g(p)}{h}\n\t\t= \\frac{f(p+h) - f(p)}{h} \\cdot g(p+h)\n\t\t+ \\frac{g(p+h)-g(p)}{h} \\cdot f(p)\n\t\\]\n\twhich as $h \\to 0$ gives the desired expression.\n\n\t\\ii Chain rule: this is where \\Cref{abuse:limit}\n\twill actually bite us.\n\tLet $p \\in U$, $q = f(p) \\in V$, so that\n\t\\[ (g \\circ f)'(p) = \\lim_{h \\to 0} \\frac{g(f(p+h)) - g(q)}{h}. \\]\n\tWe would like to write the expression in the limit as\n\t\\[ \\frac{g(f(p+h)) - g(q)}{h}\n\t\t= \\frac{g(f(p+h)) - g(q)}{f(p+h) - q}\n\t\t\\cdot \\frac{f(p+h) - f(p)}{h}. \\]\n\tThe problem is that the denominator $f(p+h)-f(p)$ might be zero.\n\tSo instead, we define the expression\n\t\\[\n\t\tQ(y) = \\begin{cases}\n\t\t\t\\frac{g(y) - g(q)}{y - q} & \\text{if } y \\ne q \\\\\n\t\t\tg'(q) & \\text{if } y = q\n\t\t\\end{cases}\n\t\\]\n\twhich is continuous since $g$ was differentiable at $q$.\n\tThen, we \\emph{do} have the equality\n\t\\[ \\frac{g(f(p+h)) - g(q)}{h}\n\t\t= Q\\left( f(p+h) \\right) \\cdot \\frac{f(p+h) - f(p)}{h}. \\]\n\tbecause if $f(p+h) = q$ with $h \\ne 0$,\n\tthen both sides are equal to zero anyways.\n\n\tThen, in the limit as $h \\to 0$,\n\twe have $\\lim_{h \\to 0} \\frac{f(p+h)-f(p)}{h} = f'(p)$,\n\twhile $\\lim_{h \\to 0} Q(f(p+h)) = Q(q) = g'(q)$ by continuity.\n\tThis was the desired result. \\qedhere\n\t\\end{itemize}\n\\end{proof}\n\n\\begin{exercise}\n\tCompute the derivative of the polynomial $f(x) = x^3 + 10x^2 + 2019$,\n\tviewed as a function $f \\colon \\RR \\to \\RR$.\n\\end{exercise}\n\n\\begin{remark}\n\tQuick linguistic point:\n\tthe theorems above all hold at each individual point.\n\tFor example the sum rule really should say that\n\tif $f,g \\colon U \\to \\RR$ are differentiable at the point $p$\n\tthen so is $f+g$ and the derivative equals $f'(p) + g'(p)$.\n\tThus $f$ and $g$ are differentiable on all of $U$,\n\tthen it of course follows that $(f+g)' = f' + g'$.\n\tSo each of the above rules has a ``point-by-point'' form\n\twhich then implies the ``whole $U$'' form.\n\n\tWe only state the latter since that is what is used in practice.\n\tHowever, in the rare situations where you have a function\n\tdifferentiable only at certain points of $U$ rather\n\tthan the whole interval $U$, you can still use the below.\n\\end{remark}\n\nWe next list some derivatives of\nwell-known functions,\nbut as we do not give rigorous definitions\nof these functions, we do not prove these here.\n\\begin{proposition}\n\t[Derivatives of some well-known functions]\n\t\\listhack\n\t\\begin{itemize}\n\t\t\\ii The exponential function $\\exp \\colon \\RR \\to \\RR$\n\t\tdefined by $\\exp(x) = e^x$ is its own derivative.\n\t\t\\ii The trig functions $\\sin$ and $\\cos$\n\t\thave $\\sin' = \\cos$, $\\cos' = -\\sin$.\n\t\\end{itemize}\n\\end{proposition}\n\n\\begin{example}\n\t[A typical high-school calculus question]\n\tThis means that you can mechanically compute\n\tthe derivatives of any artificial function obtained by using the above,\n\twhich makes it a great source of busy work\n\tin American high schools and universities.\n\tFor example, if\n\t\\[ f(x) = e^x + x \\sin(x^2) \\qquad f \\colon \\RR \\to \\RR \\]\n\tthen one can compute $f'$ by:\n\t\\begin{align*}\n\t\tf'(x) &= (e^x)' + (x \\sin(x^2))' & \\text{sum rule} \\\\\n\t\t&= e^x + (x \\sin(x^2))' & \\text{above table} \\\\\n\t\t&= e^x + (x)' \\sin(x^2) + x (\\sin(x^2))' & \\text{product rule} \\\\\n\t\t&= e^x + \\sin(x^2) + x (\\sin(x^2))' & (x)' = 1 \\\\\n\t\t&= e^x + \\sin(x^2) + x \\cdot 2x \\cdot \\cos(x^2) & \\text{chain rule}.\n\t\\end{align*}\n\tOf course, this function $f$ is totally artificial and has no meaning,\n\twhich is why calculus is the topic of widespread scorn in the USA.\n\tThat said, it is worth appreciating that calculations like\n\tthis are possible: it would be better to write the pseudo-theorem\n\t``derivatives can actually be computed''.\n\\end{example}\n\nIf we take for granted that $(e^x)' = e^x$,\nthen we can derive two more useful functions\nto add to our library of functions we can differentiate.\n\\begin{corollary}\n\t[Power rule]\n\tLet $r$ be a real number.\n\tThe function $\\RR_{>0} \\to \\RR$ by $x \\mapsto x^r$\n\thas derivative $(x^r)' = rx^{r-1}$.\n\\end{corollary}\n\n\\begin{proof}\n\tWe knew this for integers $r$ already,\n\tbut now we can prove it for any positive real number $r$.\n\tWrite\n\t\\[ f(x) = x^r = e^{r \\log x} \\]\n\tconsidered as a function $f \\colon \\RR_{>0} \\to \\RR$.\n\tThe chain rule (together with the fact that $(e^x)' = e^x$)\n\tnow gives\n\t\\begin{align*}\n\t\tf'(x) &= e^{r \\log x} \\cdot (r \\log x)' \\\\\n\t\t&= e^{r \\log x} \\cdot \\frac rx = x^r \\cdot \\frac rx = rx^{r-1}.\n\t\\end{align*}\n\tThe reason we don't prove the formulas for $e^x$ and $\\log x$\n\tis that we don't at the moment even have a rigorous\n\tdefinition for either, or even for $2^x$ if $x$ is not rational.\n\tHowever it's nice to know that some things imply the other.\n\\end{proof}\n\\begin{corollary}\n\t[Derivative of $\\log$ is $1/x$]\n\tThe function $\\log \\colon \\RR_{>0} \\to \\RR$\n\thas derivative $(\\log x)' = 1/x$.\n\\end{corollary}\n\\begin{proof}\n\tWe have that $x = e^{\\log x}$.\n\tDifferentiate both sides, and again use the chain rule\\footnote{There\n\t\tis actually a small subtlety here:\n\t\twe are taking for granted that $\\log$ is differentiable.}\n\t\\[ 1 = e^{\\log x} \\cdot (\\log x)'. \\]\n\tThus $(\\log x)' = \\frac{1}{e^{\\log x}} = 1/x$.\n\\end{proof}\n\n\\section{Local (and global) maximums}\n\\prototype{Horizontal tangent lines to the parabola\n\tare typically good pictures.}\nYou may remember from high school\nthat one classical use of calculus\nwas to extract the minimum or maximum values of functions.\nWe will give a rigorous description of how to do this here.\n\n\\begin{definition}\n\tLet $f \\colon U \\to \\RR$ be a function.\n\tA \\vocab{local maximum} is a point $p \\in U$\n\tsuch that there exists an open neighborhood $V$ of $p$\n\t(contained inside $U$)\n\tsuch that $f(p) \\ge f(x)$ for every $x \\in V$.\n\n\tA \\vocab{local minimum} is defined similarly.\\footnote{Equivalently,\n\t\tit is a local maximum of $-f$.}\n\\end{definition}\n\\begin{definition}\n\tA point $p$ is a \\vocab{local extrema}\n\tif it satisfies either of these.\n\\end{definition}\n\nThe nice thing about derivatives is that they pick up all extrema.\n\\begin{theorem}\n\t[Fermat's theorem on stationary points]\n\tSuppose $f \\colon U \\to \\RR$ is differentiable\n\tand $p \\in U$ is a local extrema.\n\tThen $f'(p) = 0$.\n\\end{theorem}\n\nIf you draw a picture, this result is not surprising.\n\\begin{center}\n\\begin{asy}\n\timport graph;\n\tsize(7cm);\n\treal f(real x) { return 2-(x-2)*(x-2)/3; }\n\tgraph.xaxis(\"$x$\");\n\tgraph.yaxis(\"$y$\");\n\tdraw(graph(f,-1,5,operator ..), blue, Arrows);\n\tpair P = (2, f(2));\n\tdot(\"$(p, f(p))$\", P, dir(90), red);\n\tdraw( (0.3,f(2))--(3.7,f(2)), red );\n\\end{asy}\n\\end{center}\n(Note also: the converse is not true.\nSay, $f(x) = x^{2019}$ has $f'(0) = 0$\nbut $x=0$ is not a local extrema for $f$.)\n\n\\begin{proof}\n\tAssume for contradiction $f'(p) > 0$.\n\tChoose any $\\eps > 0$ with $\\eps < f'(p)$.\n\tThen for sufficiently small $|h|$ we should have\n\t\\[ \\frac{f(p+h)-f(p)}{h} > \\eps. \\]\n\tIn particular $f(p+h) > f(p)$ for $h > 0$\n\twhile $f(p-h) < f(p)$ for $h < 0$.\n\tSo $p$ is not a local extremum.\n\n\tThe proof for $f'(p) < 0$ is similar.\n\\end{proof}\n\nHowever, this is not actually adequate\nif we want a complete method for optimization.\nThe issue is that we seek \\emph{global} extrema,\nwhich may not even exist:\nfor example $f(x) = x$ (which has $f'(x) = 1$)\nobviously has no local extrema at all.\nThe key to resolving this is to use \\emph{compactness}:\nwe change the domain to be a compact set $Z$,\nfor which we know that $f$ will achieve some global maximum.\nThe set $Z$ will naturally have some \\emph{interior} $S$,\nand calculus will give us all the extrema within $S$.\nThen we manually check all cases outside $Z$.\n\nLet's see two extended examples.\nThe one is simple, and you probably already know about it,\nbut I want to show you how to use compactness to argue thoroughly,\nand how the ``boundary'' points naturally show up.\n\n\\begin{example}\n\t[Rectangle area optimization]\n\tSuppose we consider rectangles with perimeter $20$\n\tand want the rectangle with the smallest or largest area.\n\t\\begin{center}\n\t\\begin{asy}\n\t\tsize(4cm);\n\t\tdraw( (0,0)--(7,0)--(7,3)--(0,3)--cycle );\n\t\tlabel(\"$10-x$\", (3.5,0), dir(-90));\n\t\tlabel(\"$x$\", (0,1.5), dir(180));\n\t\\end{asy}\n\t\\end{center}\n\tIf we choose the legs of the rectangle to be $x$ and\n\t$10-x$, then we are trying to optimize the function\n\t\\[ f(x) = x(10-x) = 10x-x^2 \\qquad f \\colon [0,10] \\to \\RR. \\]\n\tBy compactness, there exists \\emph{some} global maximum\n\tand \\emph{some} global minimum.\n\n\tAs $f$ is differentiable on $(0,10)$,\n\twe find that for any $p \\in (0,10)$, a global maximum\n\twill be a local maximum too, and hence should satisfy\n\t\\[ 0 = f'(p) = 10 - 2p \\implies p = 5. \\]\n\tAlso, the points $x = 0$ and $x = 10$ lie in the domain\n\tbut not the interior $(0,10)$.\n\tTherefore the global extrema (in addition to existing)\n\tmust be among the three suspects $\\{0, 5, 10\\}$.\n\n\tWe finally check $f(0) = 0$, $f(5) = 25$, $f(10) = 0$.\n\tSo the $5 \\times 5$ square has the largest area\n\tand the degenerate rectangles have the smallest (zero) area.\n\\end{example}\n\nHere is a non-elementary example.\n\\begin{proposition}[$e^x \\ge 1+x$]\n\tFor all real numbers $x$ we have $e^x \\ge 1+x$.\n\\end{proposition}\n\\begin{proof}\n\tDefine the differentiable function\n\t\\[ f(x) = e^x - (x+1) \\qquad f \\colon \\RR \\to \\RR. \\]\n\tConsider the compact interval $Z = [-1,100]$.\n\tIf $x \\le -1$ then obviously $f(x) > 0$.\n\tSimilarly if $x \\ge 100$ then obviously $f(x) > 0$ too.\n\tSo we just want to prove that if $x \\in Z$, we have $f(x) \\ge 0$.\n\n\tIndeed, there exists \\emph{some} global minimum $p$.\n\tIt could be the endpoints $-1$ or $100$.\n\tOtherwise, if it lies in $U = (-1, 100)$\n\tthen it would have to satisfy\n\t\\[ 0 = f'(p) = e^p - 1 \\implies p = 0. \\]\n\tAs $f(-1) > 0$, $f(100) > 0$, $f(0) = 0$,\n\twe conclude $p = 0$ is the global minimum of $Z$;\n\tand hence $f(x) \\ge 0$ for all $x \\in Z$, hence for all $x$.\n\\end{proof}\n\n\\begin{remark}\n\tIf you are willing to use limits at $\\pm \\infty$,\n\tyou can rewrite proofs like the above in such a way\n\tthat you don't have to explicitly come\n\tup with endpoints like $-1$ or $100$.\n\tWe won't do so here, but it's nice food for thought.\n\\end{remark}\n\n\\section{Rolle and friends}\n\\prototype{The racetrack principle, perhaps?}\n\nOne corollary of the work in the previous section is Rolle's theorem.\n\\begin{theorem}\n\t[Rolle's theorem]\n\tSuppose $f \\colon [a,b] \\to \\RR$ is a continuous function,\n\twhich is differentiable on the open interval $(a,b)$,\n\tsuch that $f(a) = f(b)$.\n\tThen there is a point $c \\in (a,b)$ such that $f'(c) = 0$.\n\\end{theorem}\n\n\\begin{proof}\n\tAssume $f$ is nonconstant (otherwise any $c$ works).\n\tBy compactness, there exists both a global maximum and minimum.\n\tAs $f(a) = f(b)$, either the global maximum\n\tor the global minimum must lie inside the open interval $(a,b)$,\n\tand then Fermat's theorem on stationary points finishes.\n\\end{proof}\n\nI was going to draw a picture until I realized xkcd \\#2042 has one already.\n\\begin{center}\n\t\\includegraphics[scale=0.66]{media/xkcd-rolles.png}\n\t\\\\ \\scriptsize Image from \\cite{img:xkcd_rolles}\n\\end{center}\n\nOne can adapt the theorem as follows.\n\\begin{theorem}\n\t[Mean value theorem]\n\tSuppose $f \\colon [a,b] \\to \\RR$ is a continuous function,\n\twhich is differentiable on the open interval $(a,b)$.\n\tThen there is a point $c \\in (a,b)$ such that\n\t\\[ f'(c) = \\frac{f(b)-f(a)}{b-a}. \\]\n\\end{theorem}\n\nPictorially, there is a $c$ such that the tangent at $c$\nhas the same slope as the secant joining $(a, f(a))$, to $(b, f(b))$;\nand Rolle's theorem is the special case where that secant is horizontal.\n\n\\begin{center}\n\\begin{asy}\n\timport graph;\n\tsize(7cm);\n\treal f(real x) { return x*x/2 - 0.2; }\n\tgraph.xaxis(\"$x$\");\n\tgraph.yaxis(\"$y$\");\n\tdraw(graph(f,-2,2.5,operator ..), blue, Arrows);\n\tpair A = (-1, f(-1));\n\tpair B = (2, f(2));\n\tdot(\"$(a, f(a))$\", A, dir(A-B), deepgreen);\n\tdot(\"$(b, f(b))$\", B, dir(10), deepgreen);\n\tdraw(A--B, deepgreen);\n\tlabel(\"Slope $\\frac{f(b)-f(a)}{b-a}$\", A--B, dir(120), deepgreen);\n\tdraw(A--(A.x,0), deepgreen+dashed);\n\tdraw(B--(B.x,0), deepgreen+dashed);\n\tlabel(\"$a$\", (A.x,0), dir(-90), deepgreen);\n\tlabel(\"$b$\", (B.x,0), dir(-90), deepgreen);\n\n\treal c = (A.y-B.y) / (A.x-B.x);\n\tpair C = (c, f(c));\n\tdot(\"$(c, f(c))$\", C, dir(-70), red);\n\tdraw( (c-1, f(c)-c)--(c+1, f(c)+c), red );\n\\end{asy}\n\\end{center}\n\n\\begin{proof}\n\t[Proof of mean value theorem]\n\tLet $s = \\frac{f(b)-f(a)}{b-a}$ be the slope of the secant line,\n\tand define\n\t\\[ g(x) = f(x) - s x \\]\n\twhich intuitively shears $f$ downwards so that the\n\tsecant becomes vertical.\n\tIn fact $g(a) = g(b)$ now, so we apply Rolle's theorem to $g$.\n\\end{proof}\n\n\\begin{remark}\n\t[For people with driver's licenses]\n\tThere is a nice real-life interpretation of this I should mention.\n\tA car is travelling along a one-dimensional road\n\t(with $f(t)$ denoting the position at time $t$).\n\tSuppose you cover $900$ kilometers in your car\n\tover the course of $5$ hours\n\t(say $f(0) = 0$, $f(5) = 900$).\n\tThen there is \\emph{some} point at time in which\n\tyour speed at that moment was exactly $180$ kilometers per hour,\n\tand so you cannot really complain\n\twhen the cops pull you over for speeding.\n\\end{remark}\n\nThe mean value theorem is important because it lets\nyou relate \\textbf{use derivative information\nto get information about the function}\nin a way that is really not possible without it.\nHere is one quick application to illustrate my point:\n\n\\begin{proposition}\n\t[Racetrack principle]\n\tLet $f, g \\colon \\RR \\to \\RR$ be two differentiable functions\n\twith $f(0) = g(0)$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $f'(x) \\ge g'(x)$ for every $x > 0$,\n\t\tthen $f(x) \\ge g(x)$ for every $x > 0$.\n\t\t\\ii If $f'(x) > g'(x)$ for every $x > 0$,\n\t\tthen $f(x) > g(x)$ for every $x > 0$.\n\t\\end{enumerate}\n\\end{proposition}\n\nThis proposition might seem obvious.\nYou can think of it as a race track for a reason:\nif $f$ and $g$ denote the positions of two cars (or horses etc)\nand the first car is always faster than the second car,\nthen the first car should end up ahead of the second car.\nAt a special case $g = 0$, this says that if $f'(x) \\ge 0$,\ni.e.\\ ``$f$ is increasing'',\nthen, well, $f(x) \\ge f(0)$ for $x > 0$, which had better be true.\nHowever, if you try to prove this by definition from derivatives,\nyou will find that it is not easy!\nHowever, it's almost a prototype for the mean value theorem.\n\n\\begin{proof}\n\t[Proof of racetrack principle]\n\tWe prove (a). Let $h = f-g$, so $h(0) = 0$.\n\tAssume for contradiction $h(p) < 0$ for some $p > 0$.\n\tThen the secant joining $(0, h(0))$ to $(p, h(p))$ has negative slope;\n\tin other words by mean value theorem there is a $0 < c < p$\n\tsuch that\n\t\\[ f'(c) - g'(c) = h'(c) = \\frac{h(p)-h(0)}{p} = \\frac{h(p)}{p} < 0 \\]\n\tso $f'(c) < g'(c)$, contradiction.\n\tPart (b) is the same.\n\\end{proof}\n\nSometimes you will be faced with two functions which you cannot\neasily decouple; the following form may be more useful in that case.\n\\begin{theorem}\n\t[Ratio mean value theorem]\n\tLet $f, g \\colon [a,b] \\to \\RR$ be two continuous functions\n\twhich are differentiable on $(a,b)$,\n\tand such that $g(a) \\neq g(b)$.\n\tThen there is a $c \\in (a,b)$ such that $g'(c) \\neq 0$ and\n\t\\[ \\frac{f'(c)}{g'(c)} = \\frac{f(b)-f(a)}{g(b)-g(a)}. \\]\n\\end{theorem}\n\\begin{proof}\n\tUse Rolle's theorem on the function\n\t\\[ h(x) = \\left[ f(x)-f(a) \\right] \\left[ g(b)-g(a) \\right]\n\t\t- \\left[ g(x)-g(a) \\right] \\left[ f(b)-f(a) \\right].\n\t\t\\qedhere \\]\n\\end{proof}\n\\begin{remark}\n\tYou can capture the case $g(a) = g(b)$ as well\n\tif you are willing to write the conclusion\n\tin the less intuitive form $g'(c) \\left[ f(b)-f(a) \\right]\n\t= f'(c) \\left[ g(b)-g(a) \\right]$.\n\tIn the event $g(a) = g(b)$ then this is just the mean value theorem\n\tfor $g$, and the data of $f$ is irrelevant.\n\\end{remark}\n\n\n\\section{Smooth functions}\n\\prototype{All the functions you're used to.}\n\nLet $f \\colon U \\to \\RR$ be differentiable,\nthus giving us a function $f' \\colon U \\to \\RR$.\nIf our initial function was nice enough,\nthen we can take the derivative again,\ngiving a function $f'' \\colon U \\to \\RR$, and so on.\nIn general, after taking the derivative $n$ times,\nwe denote the resulting function by $f^{(n)}$.\nBy convention, $f^{(0)} = f$.\n\\begin{definition}\n\tA function $f \\colon U \\to \\RR$ is \\vocab{smooth}\n\tif it is infinitely differentiable;\n\tthat is the function $f^{(n)}$ exists for all $n$.\n\\end{definition}\n\\begin{ques}\n\tShow that the absolute value function is not smooth.\n\\end{ques}\n\nMost of the functions we encounter,\nsuch as polynomials, $e^x$, $\\log$, $\\sin$, $\\cos$\nare smooth, and so are their compositions.\nHere is a weird example which we'll grow more next time.\n\\begin{example}\n\t[A smooth function with all derivatives zero]\n\tConsider the function\n\t\\[ f(x) = \\begin{cases}\n\t\t\te^{-1/x} & x > 0 \\\\\n\t\t\t0 & x \\le 0.\n\t\t\\end{cases}\n\t\\]\n\tThis function can be shown to be smooth,\n\twith $f^{(n)}(0) = 0$.\n\tSo this function has every derivative at the origin\n\tequal to zero, despite being nonconstant!\n\\end{example}\n\n\\section{\\problemhead}\n\\begin{problem}\n\t[Quotient rule]\n\tLet $f \\colon (a,b) \\to \\RR$ and $g \\colon (a,b) \\to \\RR_{>0}$\n\tbe differentiable functions.\n\tLet $h = f/g$ be their quotient\n\t(also a function $(a,b) \\to \\RR$).\n\tShow that the derivative of $h$ is given by\n\t\\[ h'(x) = \\frac{f'(x) g(x) - f(x) g'(x)}{g(x)^2}. \\]\n\\end{problem}\n\n\\begin{problem}\n\tFor real numbers $x > 0$, how small can $x^x$ be?\n\\end{problem}\n\n\\begin{problem}\n\t[RMM 2017]\n\t\\gim\n\tDetermine whether or not there exist\n\tnonconstant polynomials $P(x)$ and $Q(x)$ with\n\treal coefficients satisfying\n\t\\[ P(x)^{10} + P(x)^9 = Q(x)^{21} + Q(x)^{20}. \\]\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tLet $P(x)$ be a degree $n$ polynomial with real coefficients.\n\tProve that the equation $e^x = P(x)$ has at most $n+1$ real solutions in $x$.\n\\end{problem}\n\n\\begin{problem}\n\t[Jensen's inequality]\n\tLet $f \\colon (a,b) \\to \\RR$ be a twice differentiable function\n\tsuch that $f''(x) \\ge 0$ for all $x$\n\t(i.e.\\ $f$ is \\emph{convex}).\n\tProve that\n\t\\[ f\\left( \\frac{x+y}{2} \\right)\n\t\t\\le \\frac{f(x) + f(y)}{2} \\]\n\tfor all real numbers $x$ and $y$ in the interval $(a,b)$.\n\\end{problem}\n\n\\begin{problem}\n\t[L'H\\^{o}pital rule, or at least one case]\n\tLet $f,g \\colon \\RR \\to \\RR$ be differentiable functions\n\tand let $p$ be a real number.\n\tSuppose that\n\t\\[ \\lim_{x \\to p} f(x) = \\lim_{x \\to p} g(x) = 0. \\]\n\tProve that\n\t\\[ \\lim_{x \\to p} \\frac{f(x)}{g(x)}\n\t\t= \\lim_{x \\to p} \\frac{f'(x)}{g'(x)} \\]\n\tprovided the right-hand limit exists.\n\\end{problem}\n\n", "meta": {"hexsha": "1a3bfe01f387cd83a38437831903d163018d2be1", "size": 23483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/calculus/differentiate.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/calculus/differentiate.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/calculus/differentiate.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": 34.6868537666, "max_line_length": 78, "alphanum_fraction": 0.6518758251, "num_tokens": 8075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.6477430858144044}}
{"text": "\\section{Methodology}\n\\gls{temoa} is an open source tool for energy system optimization that\nformulates and solves a linear optimization problem\n\\cite{decarolis_tools_2020}. A linear optimization\nproblem has two requirements: An objective function and constraints. The\nobjective function in \\gls{temoa} is total system cost over time horizon\nof interest and the minimum required constraint is annual demand (and\ntechnology options to meet that demand). Users can optionally add other\nconstraints to match the real system being modeled. In our case we added\nemissions limits based on the carbon goals set by \\gls{icap}. At each time step,\n\\gls{temoa} must be able to meet the various constraints with the existing\ncapacity, or build be able to build new capacity to do so. If demand and\nemissions limits cannot be satisfied, then \\gls{temoa} gives ``no solution.''\nMathematically, \\gls{temoa} solves the following problem:\n\\begin{align}\n  \\intertext{Minimize}\n  C_{tot} &= C_{cap} + C_{fix} + C_{var}\\\\\n  \\intertext{Subject to:}\n  D_i &= \\sum_{tech}A_{tech} \\mbox{ for } i \\in \\mbox{ years}\n\\end{align}\n", "meta": {"hexsha": "6ae80c1e2dfd8d87641c37b76e78a5f7fd41fdd1", "size": 1102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/papers/optimal-sizing-paper/methods.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/papers/optimal-sizing-paper/methods.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/papers/optimal-sizing-paper/methods.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": 52.4761904762, "max_line_length": 80, "alphanum_fraction": 0.7731397459, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.926303728259492, "lm_q2_score": 0.6992544210587586, "lm_q1q2_score": 0.6477219772286608}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=2cm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{slashed}\n\\usepackage{tikz}\n\n\\begin{document}\n\n\\noindent\nConsider an electron scattered by an atomic nucleus.\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[dashed] (0,0) circle (0.5cm);\n%\\draw[dashed] (1.4,0) -- (0.6,0);\n\\draw[thick,->] (-2,0) node[anchor=east] {$e^-$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$e^-$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nHere is the same diagram with momentum and spinor labels.\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[dashed] (0,0) circle (0.5cm);\n%\\draw[dashed] (1.4,0) -- (0.6,0);\n\\draw[thick,->] (-2,0) node[anchor=east] {$p_1,u_1$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$p_2,u_2$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nThe path of the incident electron can be modeled as the $z$ axis,\nresulting in the following momentum vectors.\n\\begin{equation*}\n\\underset{\\text{inbound electron}}\n{p_1=\\begin{pmatrix}E\\\\0\\\\0\\\\p\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron}}\n{\np_2=\\begin{pmatrix}\nE\\\\\np\\sin\\theta\\cos\\phi\\\\\np\\sin\\theta\\sin\\phi\\\\\np\\cos\\theta\n\\end{pmatrix}\n}\n\\end{equation*}\n\n\\noindent\nSymbol $p$ is incident momentum,\n$E$ is total energy $E=\\sqrt{p^2+m^2}$,\nand $m$ is electron mass.\nPolar angle $\\theta$ is the observed scattering angle.\nAzimuth angle $\\phi$ cancels out in scattering calculations.\n\n\\bigskip\n\\noindent\nThe spinors are\n\\begin{equation*}\n\\underset{\\text{inbound electron, spin up}}\n{u_{11}=\\begin{pmatrix}E+m\\\\0\\\\p\\\\0\\end{pmatrix}}\n\\quad\n\\underset{\\text{inbound electron, spin down}}\n{u_{12}=\\begin{pmatrix}0\\\\E+m\\\\0\\\\-p\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron, spin up}}\n{u_{21}=\\begin{pmatrix}E+m\\\\0\\\\p_{2z}\\\\p_{2x}+ip_{2y}\\end{pmatrix}}\n\\quad\n\\underset{\\text{outbound electron, spin down}}\n{u_{22}=\\begin{pmatrix}0\\\\E+m\\\\p_{2x}-ip_{2y}\\\\-p_{2z}\\end{pmatrix}}\n\\end{equation*}\n\n\\noindent\nThe spinors shown above are not individually normalized.\nInstead, a combined spinor normalization constant $N=(E+m)^2$ will be used.\n\n\\bigskip\n\\noindent\nThe following formula computes a probability density $|\\mathcal{M}_{ab}|^2$ for Rutherford scattering\nwhere $a$ is the spin state of the inbound electron and $b$ is the spin state of the outbound electron.\n\\begin{equation*}\n|\\mathcal{M}_{ab}|^2=\\frac{Z^2e^4}{q^4}\\frac{1}{N}\\left|\\bar{u}_{2b}\\gamma^0 u_{1a}\\right|^2\n\\end{equation*}\n\n\\noindent\nSymbol $Z$ is the atomic number of the nucleus,\n$e$ is electron charge,\nand $q=p_1-p_2$ is momentum transfer.\n\n\\bigskip\n\\noindent\nThe expected probability density\n$\\langle\\vert\\mathcal{M}\\vert^2\\rangle$\nis computed by summing $|\\mathcal{M}_{ab}|^2$\nover all four spin states and then dividing by the number of inbound states.\nThere are two inbound states.\n\\begin{align*}\n\\langle\\vert\\mathcal{M}\\vert^2\\rangle\n&=\\frac{1}{2}\\sum_{a=1}^2\\sum_{b=1}^2\\left|\\mathcal{M}_{ab}\\right|^2\n\\\\\n&=\\frac{Z^2e^4}{2q^4}\\frac{1}{N}\\sum_{a=1}^2\\sum_{b=1}^2\\left|\\bar{u}_{2b}\\gamma^0 u_{1a}\\right|^2\n\\\\\n&=\\frac{Z^2e^4}{2q^4}\\mathop{\\rm Tr}\\left((\\slashed{p}_1+m)\\gamma^0(\\slashed{p}_2+m)\\gamma^0\\right)\n\\\\\n&=\\frac{2Z^2e^4}{q^4}\\left(E^2+m^2+p^2\\cos\\theta\\right)\n\\end{align*}\n\n\\noindent\nRun ``rutherford-scattering-1.txt'' to verify the following formulas.\n\\begin{gather*}\n\\frac{1}{N}\\sum_{a=1}^2\\sum_{b=1}^2\\left|\\bar{u}_{2b}\\gamma^0 u_{1a}\\right|^2\n=\\mathop{\\rm Tr}\\left((\\slashed{p}_1+m)\\gamma^0(\\slashed{p}_2+m)\\gamma^0\\right)\n=4(E^2+m^2+p^2\\cos\\theta)\n\\\\\nq^4=(p_1-p_2)^4=16p^4\\sin^4(\\theta/2)=4p^4(\\cos\\theta-1)^2\n\\end{gather*}\n\n\\subsection*{Low energy approximation}\nFor low energy electrons such that $p\\ll m$ we can use the following approximation.\n\\begin{equation*}\nE^2+m^2+p^2\\cos\\theta\\approx2m^2\n\\end{equation*}\n\n\\noindent\nHence\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle=\\frac{4m^2Z^2e^4}{q^4}\n\\end{equation*}\n\n\\noindent\nSubstituting $e^4=16\\pi^2\\alpha^2$ and $q^4=4p^4(\\cos\\theta-1)^2$ we have\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle=\\frac{16\\pi^2m^2Z^2\\alpha^2}{p^4(\\cos\\theta-1)^2}\n\\end{equation*}\n\n\\noindent\nThe differential cross section is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=\\frac{\\langle|\\mathcal{M}|^2\\rangle}{16\\pi^2}\n=\\frac{m^2Z^2\\alpha^2}{p^4(\\cos\\theta-1)^2}\n\\end{equation*}\n\n\\noindent\nWe can integrate $d\\sigma$ to obtain a cumulative distribution function.\nRecall that\n\\begin{equation*}\nd\\Omega=\\sin\\theta\\,d\\theta\\,d\\phi\n\\end{equation*}\nHence\n\\begin{equation*}\nd\\sigma=\\frac{m^2Z^2\\alpha^2}{p^4(\\cos\\theta-1)^2}\\sin\\theta\\,d\\theta\\,d\\phi\n\\end{equation*}\n\n\\noindent\nLet $I(\\theta)$ be the following integral of $d\\sigma$.\n\\begin{align*}\nI(\\theta)\n&=\\left(\\frac{p^4}{m^2Z^2\\alpha^2}\\right)\\frac{1}{2\\pi}\\int_0^{2\\pi}\\int d\\sigma\n\\\\\n&=\\int\\frac{1}{(\\cos\\theta-1)^2}\\sin\\theta\\,d\\theta\n\\\\\n&=\\frac{1}{\\cos\\theta-1},\\quad a\\le\\theta\\le\\pi\n\\end{align*}\n\n\\noindent\nAngular support is limited to an arbitrary $a>0$ because $I(0)$ is undefined.\n\n\\bigskip\n\\noindent\nLet $C$ be the normalization constant\n\\begin{equation*}\nC=I(\\pi)-I(a)\n\\end{equation*}\n\n\\noindent\nThen the cumulative distribution function $F(\\theta)$ is\n\\begin{equation*}\nF(\\theta)=\\frac{I(\\theta)-I(a)}{C},\n\\quad a\\le\\theta\\le\\pi\n\\end{equation*}\n\n\\noindent\nThe probability of observing scattering events\nin the interval $\\theta_1$ to $\\theta_2$ can now be computed.\n\\begin{equation*}\nP(\\theta_1\\le\\theta\\le\\theta_2)=F(\\theta_2)-F(\\theta_1)\n\\end{equation*}\n\n\\noindent\nProbability density function $f(\\theta)$ is the derivative of $F(\\theta)$.\n\\begin{equation*}\nf(\\theta)=\\frac{dF(\\theta)}{d\\theta}\n=\\frac{\\sin\\theta}{C(\\cos\\theta-1)^2}\n\\end{equation*}\n\n\\noindent\nRun ``rutherford-scattering-3.txt'' to draw a graph of $f(\\theta)$ for $a=\\pi/4=45^\\circ$.\n\n\\begin{center}\n\\includegraphics[scale=0.5]{rutherford-scattering-1.png}\n\\end{center}\n\n\\noindent\nProbability distribution for $45^\\circ$ bins ($a=45^\\circ$).\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$\\theta_1$ & $\\theta_2$ & $P(\\theta_1\\le\\theta\\le\\theta_2)$\\\\\n\\hline\n$0^\\circ$ & $45^\\circ$ & -- \\\\\n$45^\\circ$ & $90^\\circ$ & 0.83 \\\\\n$90^\\circ$ & $135^\\circ$ & 0.14 \\\\\n$135^\\circ$ & $180^\\circ$ & 0.03 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nNote:\nThe original Rutherford scattering experiment in 1911 used alpha particles, not electrons.\nHowever, scattering of any charged particle by Coulomb interaction\nis now known as Rutherford scattering.\nThe first Rutherford scattering experiment using electrons appears to have\nbeen done by F.~L.~Arnot, then a student of Rutherford, in 1929.\n\n\\end{document}\n", "meta": {"hexsha": "5f8f694ddfd876f31f07b174c96b859294cec001", "size": 6560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rutherford-scattering.tex", "max_stars_repo_name": "georgeweigt/georgeweigt.github.io", "max_stars_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "rutherford-scattering.tex", "max_issues_repo_name": "georgeweigt/georgeweigt.github.io", "max_issues_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "rutherford-scattering.tex", "max_forks_repo_name": "georgeweigt/georgeweigt.github.io", "max_forks_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": 28.5217391304, "max_line_length": 103, "alphanum_fraction": 0.6920731707, "num_tokens": 2564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6475420032037292}}
{"text": "\\section{Polar coordinates and polar graphs}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Understand polar coordinates.\n  \\item Convert points between Cartesian and polar coordinates.\n  \\end{enumerate}\n\\end{outcome}\n\nYou have likely encountered the Cartesian coordinate system in many aspects of mathematics. There is an alternative way to represent points in space, called \\textbf{polar\ncoordinates}\\index{polar coordinates}. The idea is suggested in the following picture.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(-0.5,0)--(2,0);\n\\draw(0,-0.5)--(0,2);\n\\draw[blue, ultra thick](0,0)--(2,2);\n\\draw[fill, blue](2,2) circle [radius=1pt];\n\\draw[help lines, dotted](0,2)--(2,2)--(2,0);\n\\node[below] at (2,0){$x$};\n\\node[above] at (0,2){$y$};\n\\node[above right] at (0.5, 0){$\\theta$};\n\\node[left] at (1,1){$r$};\n\\node[right] at (2,2){$(x,y)$};\n\\node[below right] at (2,1.9){$(r, \\theta)$};\n\\end{tikzpicture}\n\\end{center}\n\nConsider the point above, which would be specified as $(x,y)$ in Cartesian coordinates. We can also specify this point using polar coordinates, which we write as $(r, \\theta)$. The number $r$ is the distance from the origin$(0,0)$ to the point, while $\\theta $ is the angle shown\nbetween the positive $x$ axis and the line from the origin to the point. In this way, the point can be specified in polar coordinates as $(r, \\theta)$.\n\nNow suppose we are given an ordered pair $(r,\\theta) $ where\n$r$ and $\\theta$ are real numbers. We want to determine the point specified by this ordered pair. We can use $\\theta $ to identify a ray\nfrom the origin as follows. Let the ray pass from $(0,0) $\nthrough the point $(\\cos \\theta ,\\sin \\theta) $ as shown.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(-2,0)--(2,0);\n\\draw(0,-2)--(0,2);\n\\draw(0,0) circle [radius = 1.75];\n\\draw[->, ultra thick, blue] (0,0)--(2,2);\n\\draw[fill, blue](0,0) circle [radius=2pt];\n\\draw[fill, blue](1.24,1.24) circle [radius=2pt];\n\\node[right] at (1.5, 1.24){$(cos (\\theta), sin(\\theta))$};\n\\end{tikzpicture}\n\\end{center}\n\nThe ray is identified on the graph as the line from the origin, through the point $(\\cos(\\theta),\\sin(\\theta))$. Now if $r>0$, go a distance\nequal to $r$ in the direction of the displayed arrow starting at $(0,0)$. If\n$r<0$, move in the opposite direction a distance of $\\abs{r}\n$. This is the point determined by $(r,\\theta)$.\n\nIt is common to assume that $\\theta $ is in the interval $\n[0,2\\pi )$ and $r>0$. In this case, there is a very simple relationship\nbetween the Cartesian and polar coordinates, given by\n\\begin{equation}\nx=r\\cos (\\theta) ,\\ \\ y=r\\sin (\\theta)\n\\label{cart-pol-coord}\n\\end{equation}\n\nThese equations demonstrate how to find the Cartesian coordinates when we are given the polar coordinates of a point. They can also be used to find the polar coordinates when we know $(x, y)$. A simpler way to do this is the following equations:\n\\begin{equation}\n\\begin{array}{l}\nr = \\sqrt{x^2 + y^2} \\\\\n\\\\\n\\tan (\\theta) = \\frac{y}{x}\n\\end{array}\n\\label{pol-cart-coord}\n\\end{equation}\n\nIn the next example, we look at how to find the Cartesian coordinates of a point specified by polar coordinates.\n\n\\begin{example}{Finding Cartesian coordinates}{}\nThe polar coordinates of a point in the plane are $(5,\\pi /6)$.\nFind the Cartesian coordinates of this point.\n\\end{example}\n\n\\begin{solution}\nThe point is specified by the polar coordinates $(5,\\pi /6)$. Therefore $r=5$ and $\\theta = \\pi /6$.\nFrom {\\eqref{cart-pol-coord}}\n\\[\nx= r \\cos (\\theta)= 5\\cos \\paren{\\vspace{0.05in}\\frac{\\pi }{6}} = \\vspace{0.05in}\\frac{5}{2}\\sqrt{3}\n\\]\n\\[\ny= r \\sin (\\theta) = 5\\sin \\paren{\\vspace{0.05in}\\frac{\\pi }{6}} = \\vspace{0.05in}\\frac{5}{2}\n\\]\nThus the Cartesian coordinates are $\\paren{\\vspace{0.05in}\\frac{5}{2}\\sqrt{3}, \\vspace{0.05in}\\frac{5}{2}}$. The point is shown in the below graph.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw(-5,0)--(5,0);\n\\draw(0,-4)--(0,4);\n\\draw[help lines, blue, dotted](0, 2.5)--(4.33, 2.5)--(4.33,0);\n\\draw[fill, blue] (4.33, 2.5) circle [radius=4pt];\n\\node[right] at (4.33, 2.5){$(\\frac{5}{2}\\sqrt{3}, \\frac{5}{2})$};\n\\end{tikzpicture}\n\\end{center}\n\\end{solution}\n\nConsider the following example of the case where $r < 0$.\n\n\\begin{example}{Finding Cartesian coordinates}{}\nThe polar coordinates of a point in the plane are $(-5,\\pi /6)$.\nFind the Cartesian coordinates.\n\\end{example}\n\n\\begin{solution}\nFor the point specified by the polar coordinates $(-5, \\pi /6)$,\n$r=-5$, and $x\\theta = \\pi /6$.\nFrom {\\eqref{cart-pol-coord}}\n\\[\nx= r \\cos (\\theta)= -5\\cos \\paren{\\vspace{0.05in}\\frac{\\pi }{6}} = -\\vspace{0.05in}\\frac{5}{2}\\sqrt{3}\n\\]\n\\[\ny= r \\sin (\\theta) = -5\\sin \\paren{\\vspace{0.05in}\\frac{\\pi }{6}} = -\\vspace{0.05in}\\frac{5}{2}\n\\]\nThus the Cartesian coordinates are $\\paren{-\\vspace{0.05in}\\frac{5}{2}\\sqrt{3}, -\\vspace{0.05in}\\frac{5}{2}}$. The point is shown in the following graph.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw(-5,0)--(5,0);\n\\draw(0,-4)--(0,4);\n\\draw[help lines, blue, dotted](0, -2.5)--(-4.33, -2.5)--(-4.33,0);\n\\draw[fill, blue] (-4.33, -2.5) circle [radius=4pt];\n\\node[left] at (-4.33, -2.5){$(-\\frac{5}{2}\\sqrt{3}, -\\frac{5}{2})$};\n\\end{tikzpicture}\n\\end{center}\n\nRecall from the previous example that for the point specified by $(5, \\pi /6)$, the Cartesian coordinates are $\\paren{\\vspace{0.05in}\\frac{5}{2}\\sqrt{3}, \\vspace{0.05in}\\frac{5}{2}}$. Notice that in this example, by multiplying $r$ by $-1$, the resulting Cartesian coordinates are also multiplied by $-1$.\n\\end{solution}\n\nThe following picture exhibits both points in the above two examples to\nemphasize how they are just on opposite sides of $(0,0) $ but at\nthe same distance from $(0,0)$.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw(-5,0)--(5,0);\n\\draw(0,-4)--(0,4);\n\\draw[help lines, blue, dotted](0, 2.5)--(4.33, 2.5)--(4.33,0);\n\\draw[fill, blue] (4.33, 2.5) circle [radius=4pt];\n\\node[right] at (4.33, 2.5){$(\\frac{5}{2}\\sqrt{3}, \\frac{5}{2})$};\n\\draw[help lines, blue, dotted](0, -2.5)--(-4.33, -2.5)--(-4.33,0);\n\\draw[fill, blue] (-4.33, -2.5) circle [radius=4pt];\n\\node[left] at (-4.33, -2.5){$(-\\frac{5}{2}\\sqrt{3}, -\\frac{5}{2})$};\n\\draw[blue, ultra thick](-4.33, -2.5)--(4.33, 2.5);\n\\end{tikzpicture}\n\\end{center}\n\nIn the next two examples, we look at how to convert Cartesian coordinates to polar coordinates.\n\n\\begin{example}{Finding polar coordinates}{}\nSuppose the Cartesian coordinates of a point are $(3,4)$. Find\na pair of polar coordinates which correspond to this point.\n\\end{example}\n\n\\begin{solution}\nUsing equation {\\eqref{pol-cart-coord}}, we can find $r$ and $\\theta$. Hence $r=\\sqrt{3^{2}+4^{2}}=5$. It remains to identify the angle $\\theta$ between the positive $x$ axis and the line from the origin to the point. Since both the $x$ and $y$ values are positive, the point is in the\nfirst quadrant. Therefore, $\\theta$ is between $0$ and $\\pi/2$.\nUsing this and {\\eqref{pol-cart-coord}}, we have to solve:\n\\[\n\\tan(\\theta)=\\frac{4}{3}\n\\]\nConversely, we can use equation {\\eqref{cart-pol-coord}} as follows:\n\\[\n3=5\\cos (\\theta)\n\\]\n\\[\n4 = 5\\sin (\\theta)\n\\]\nSolving these equations, we find that,\napproximately, $\\theta =0.\\, 927\\,295$ radians.\n\\end{solution}\n\nConsider the following example.\n\n\\begin{example}{Finding polar coordinates}{}\nSuppose the Cartesian coordinates of a point are $(-\\sqrt{3},1)$\n. Find the polar coordinates which correspond to this point.\n\\end{example}\n\n\\begin{solution}\nGiven the point $(-\\sqrt{3}, 1)$,\n\\begin{eqnarray*}\nr &=& \\sqrt{ 1^2 + (-\\sqrt{3})^2}\\\\\n&=& \\sqrt{1 + 3}\\\\\n&=&2\n\\end{eqnarray*}\n In this case, the point is in the second quadrant since the $x$ value is negative and the $y$ value is positive. Therefore, $\\theta$ will be between $\\pi/2$ and $\\pi$.\nSolving the equations\n\\[\n-\\sqrt{3}= 2 \\cos (\\theta)\n\\]\n\\[\n1 = 2 \\sin (\\theta)\n\\]\n\nwe find that $\\theta = 5\\pi /6$.\nHence the polar coordinates for this point are $(2, 5\\pi /6)$.\n\\end{solution}\n\nConsider this example. Suppose we used $r=-2$ and $\\theta =2\\pi -(\\pi /6) = 11\\pi /6$. These coordinates specify the same point as above. Observe that there are infinitely many ways to identify this\nparticular point with polar coordinates. In fact, every point can be represented with polar coordinates in infinitely many ways. Because of this, it will usually be\nthe case that $\\theta $ is confined to lie in some interval\nof length $2\\pi $ and $r>0$, for real numbers $r$ and $\\theta$.\n\nJust as with Cartesian coordinates, it is possible to use\nrelations between the polar coordinates to specify points in the plane. The\nprocess of sketching the graphs of these relations is very similar to that used to sketch\ngraphs of functions in Cartesian coordinates. Consider a relation between polar coordinates of the form, $r=f(\\theta)$. To graph such a relation, first make a table of\nthe form\n\\begin{equation*}\n\\begin{tabular}{|l|l|}\n\\hline\n$\\theta $ & $r$ \\\\ \\hline\n$\\theta _{1}$ & $f(\\theta _{1}) $ \\\\ \\hline\n$\\theta _{2}$ & $f(\\theta _{2}) $ \\\\ \\hline\n$\\vdots $ & $\\vdots $ \\\\ \\hline\n\\end{tabular}\n\\end{equation*}\nGraph the resulting points and connect them with a curve. The\nfollowing picture illustrates how to begin this process.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw(-0.5,0)--(3,0);\n\\draw(0,-0.5)--(0,3);\n\\draw[blue](0,0)--(2.5,1);\n\\draw[red](0,0)--(2.5,2.5);\n\\draw[fill,blue] (2,0.8) circle [radius=2pt];\n\\draw[fill,red] (1.25,1.25) circle [radius=2pt];\n\\draw[blue](1,0) to [out=90, in=90] (0.9,0.36);\n\\draw[red](0.75,0) to [out=90, in=90] (0.6,0.6);\n\\node[right] at (1,0.25){$\\theta_1$};\n\\node[right] at (0.75, 0.75){$\\theta_2$};\n\\end{tikzpicture}\n\\end{center}\n\nTo find the point in the plane corresponding to the ordered pair $(f(\n\\theta) ,\\theta)$, we follow the same process as when finding the point corresponding to $(r, \\theta)$.\n\nConsider the following example of this procedure, incorporating computer software.\n\n\\begin{example}{Graphing a polar equation}{}\nGraph the polar equation $r=1+\\cos \\theta$.\n\\end{example}\n\n\\begin{solution}\nWe will use the computer software {\\em Maple} to complete this example. The command which produces the polar graph of the above equation is: $>$ plot(1+cos(t),t=\n0..2*Pi,coords=polar). Here we use $t$ to represent the variable $\\theta$ for convenience. The command tells Maple that $r$\nis given by $1+\\cos (t) $ and that $t\\in \\mat{0,2\\pi}$.\n\n\\begin{picture}(1,120)\n\\put(110,-25){\n\\includegraphics[bb=0 0 400\n400,totalheight=3cm]{figures/cardioid.eps}\n\\put(30,73){\\large{x}}\n\\put(-35,128){\\large{y}}}\n\\end{picture}\n\nThe above graph makes sense when considered in terms of trigonometric functions. Suppose $\\theta =0,r=2$ and let $\\theta $ increase to $\\pi /2$. As $\\theta$ increases, $\\cos \\theta $ decreases to 0. Thus the line from the origin to the point on the curve should get shorter as $\\theta $ goes from $0$ to $\\pi /2$. As $\\theta$ goes from $\\pi /2$ to $\\pi$, $\\cos\n\\theta $ decreases, eventually equalling $-1$ at $\\theta =\\pi$. Thus $r=0$\nat this point. This scenario is depicted in the above graph, which shows a function called a \\textbf{cardioid}\\index{cardioid}.\n\nThe following picture illustrates the\nabove procedure for obtaining the polar graph of $r=1+\\cos(\\theta)$. In this picture, the\nconcentric circles correspond to values of $r$ while the rays from the\norigin correspond to the angles which are shown on the picture. The dot on the ray corresponding to the angle $\\pi/6$ is located at a distance of $r = 1+\\cos(\\pi/6)$ from the origin. The dot on the ray corresponding to the angle $\\pi/3$\nis located at a distance of $r = 1+\\cos(\\pi/3)$ from the origin and so\nforth. The polar graph is obtained by connecting such points with a smooth\ncurve, with the result being the figure shown above.\n\n\\begin{picture}(1,290)\n\\put(30,-58){\n\\includegraphics[bb=0 0 400\n400,totalheight=7cm]{figures/25aprilcardioid.eps}\n%\\put(85,128){\\large{x}}\n%\\put(-117,328){\\large{y}}\\put(80,170){$y=\\ln(x)$}\n%\\put(-90,328){$y=\\exp(x)$}\n}\n\\end{picture}\n\\end{solution}\n\nConsider another example of constructing a polar graph.\n\n\\begin{example}{A polar graph}{}\nGraph $r=1+2\\cos \\theta $ for $\\theta \\in \\mat{\n0,2\\pi}$.\n\\end{example}\n\n\\begin{solution}\nThe graph of the polar equation $r=1+2\\cos \\theta $ for $\\theta \\in \\mat{\n0,2\\pi}$ is given as follows.\n\n\\begin{picture}(1,127)\n\\put(110,-25){\n\\includegraphics[bb=0 0 400\n400,totalheight=3cm]{figures/polarpretty2.eps}\n\\put(34,79){\\large{x}}\n\\put(-47,138){\\large{y}}}\n\\end{picture}\n\nTo see the way this is graphed, consider the following picture. First the\nindicated points were graphed and then the curve was drawn to connect the points. When done by a computer, many more points are used to create a more accurate picture.\n\nConsider first the following table of points.\n\\begin{equation*}\n\\begin{tabular}{|l|l|l|l|l|l|l|l|l|}\n\\hline\n$\\theta $ & $\\pi /6$ & $\\pi /3$ & $\\pi /2$ & $5\\pi /6$ & $\\pi $ & $4\\pi /3$\n& $7\\pi /6$ & $5\\pi /3$ \\\\ \\hline\n$r$ & $\\sqrt{3}+1$ & $2$ & $1$ & $1-\\sqrt{3}$ & $-1$ & $0$ & $1-\\sqrt{3}$ & $%\n2$ \\\\ \\hline\n\\end{tabular}%\n\\end{equation*}\n\nNote how some entries in the table have $r<0$. To graph these points, simply move in the opposite direction. These types of points are responsible for the small loop on the inside of the\nlarger loop in the graph.\n\n\\begin{picture}(1,290)\n\\put(30,-58){\n\\includegraphics[bb=0 0 400\n400,totalheight=7cm]{figures/26aprilwriggly.eps}\n%\\put(85,128){\\large{x}}\n%\\put(-117,328){\\large{y}}\\put(80,170){$y=\\ln(x)$}\n%\\put(-90,328){$y=\\exp(x)$}\n}\n\\end{picture}\n\\end{solution}\n\nThe process of constructing these graphs can be greatly facilitated by computer software. However, the use of such software should not replace understanding the steps involved.\n\nThe next example shows the graph for the equation $r=3+\\sin \\paren{\n\\displaystyle\n\\frac{7\\theta }{6}}$. For complicated polar graphs, computer software is used to facilitate the process.\n\n\\begin{example}{A polar graph}{}\nGraph $r=3+\\sin \\paren{\\displaystyle \\frac{7\\theta }{6}%\n} $ for $\\theta \\in \\mat{0,14\\pi}$.\n\\end{example}\n\n\\begin{solution}\n\n\\begin{picture}(1,127)\n\\put(110,-25){\n\\includegraphics[bb=0 0 400\n400,totalheight=3cm]{figures/polarpretty.eps}\n\\put(34,79){\\large{x}}\n\\put(-20,138){\\large{y}}}\n\\end{picture}\n\\end{solution}\n\nThe next example shows another situation in which $r$ can be negative.\n\n\\begin{example}{A polar graph: negative $r$}{}\nGraph $r=3\\sin(4\\theta) $ for $\\theta \\in \\mat{0,2\\pi}$.\n\\end{example}\n\n\\begin{solution}\n\n\\begin{picture}(1,120)\n\\put(120,-24){\n\\includegraphics[bb=0 0 400\n400,totalheight=3cm]{figures/26aprilrose.eps}}\n\\put(242,53){\\large{x}}\n\\put(190,105){\\large{y}}\n\n\\end{picture}\n\\end{solution}\n\nWe conclude this section with an interesting graph of a simple polar equation.\n\n\\begin{example}{The graph of a spiral}{}\nGraph $r=\\theta$ for $\\theta \\in [0,2\\pi]$.\n\\end{example}\n\n\\begin{solution}\nThe graph of this polar equation is a spiral. This is the case because as $\\theta $ increases, so does $r$.\n\n\\begin{picture}(1,290)\n\\put(30,-58){\n\\includegraphics[bb=0 0 400\n400,totalheight=7cm]{figures/11mayspiral.eps}\n\\put(85,205){\\large{x}}\n\\put(-55,335){\\large{y}}}\n\\end{picture}\n\\end{solution}\n\nIn the next section, we will look at two ways of generalizing polar coordinates to three dimensions.\n", "meta": {"hexsha": "0038a01a67e1fa5f84a4b24d0b924f079ec2e04c", "size": 15113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/curvilinearPolar.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/curvilinearPolar.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/curvilinearPolar.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.652173913, "max_line_length": 360, "alphanum_fraction": 0.6856348839, "num_tokens": 5032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.6475420032037292}}
{"text": "\\chapter{Bootstrap}\n\n% \\Chapter{3}{Exercise 3: Bootstrap}\n\\section{Simulation of bootstrap confidence intervals}\nThe third exercise is about the bootstrap method to construct confidence intervals (CI) for different distribution measures, e.g. standard deviation (SD) and median here. The first part is a simulation study to examine coverage properties and length of the bootstrap percentile CI (bCI) for SD and median for a Weibull distribution (with parameters $\\lambda = 13$ and $k=1$ - so it is actually an exponential distribution). Therefore we drew $M$ Monte Carlo samples of $n$ Weibull distributed variables. For each sample we did $R$ bootstrap repetitions where I used a n-out-of-n method with replacement like described in the lecture. The bCI at level $95\\%$ was then defined as the interval between the 0.25th and the 0.75th quantile of the bootstrap distribution for the respective statistic. For each MC sample I checked whether the true SD and median where covered and saved the length of the CIs. Where $M=1000$ was fixed we compare the results for different choices of $n$ and $R$, i.e. we varied the actual sample size and the number of bootstrap runs. The results are shown in Table \\ref{3table}. \n\\begin{table}[hb]\n\\centering\n\\begin{tabular}{rrrrrr}\n  \\hline  \n  && \\multicolumn{2}{r}{Cover probability} &  \\multicolumn{2}{r}{Avg CI length} \\\\  \n  \\hline\n R & n & \\hspace{0.5cm}med &\\hspace{0.5cm} SD &\\hspace{0.5cm} med &\\hspace{0.5cm} SD \\\\ \n  \\hline\n 1000 & 100 & 0.94 & 0.86 & 5.02 & 6.18 \\\\ \n 1000 & 1000 & 0.93 & 0.94 & 1.60 & 2.21 \\\\ \n 5000 & 100 & 0.95 & 0.86 & 5.18 & 6.06 \\\\ \n   \\hline\n \\texttt{bcanon}&&&&&\\\\\n \\hline\n 1000 & 100&1.00&1.00 & 3.91 & 7.42\\\\\n \\hline\n\\end{tabular}\n\\caption{Coverage probability and average CI length for median and SD for the MC simulation of $95\\%$ bootstrap percentile CIs with sample size $n$ and $R$ bootstrap repetitions and for the bootstrap accelerated bias-corrected CI using \\texttt{bcanon}.}\n\\label{3table}\n\\end{table}\nAs we took the $95\\%$ bCI we would expect a corresponding coverage probability. For the median this is almost achieved in every row. We also see that the differences between the first and the third row are rather small and that the cover probability lies beneath the desired level. On the other hand the coverage for SD increases notable when we increase the sample size $n$ and is about $95\\%$. Simultaneously the length of the bCI drastically decreased, showing that we get a higher precision for both statistic. This precision is not gained by using more bootstrap repetitions. This demonstrates that the amount of information we can pull from a fix sample size is bounded and can't be arbitrarily increased using more bootstrap samples. On the other hand, increasing the sample size, i.e. collecting more \\textit{independent} information helps estimating better CI. \n\nTo visualise the empirical distribution of the sample statistics I include histograms for the SD and median of the MC samples together with a bCI for an additional sample and histograms of the CI lengths with the length for this additional sample (see Figure \\ref{3hist}). The bCIs of this example cover 0.81 of the samples' SD and 0.89 of the median. This is a bit lower than the ones shown in the first row of Table \\ref{3table} since the empirical estimates vary independently of the CI around the true statistics.\n\\begin{figure}[thb]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex3/MChist.png}\n\\caption{Histogram for 1000 MC samples of the two statistics (first row) and the length of the $95\\%$ bCI (second row). The red lines show the bCI for an independent sample (first row) and the respective length (second row).}\n\\label{3hist}\n\\end{figure}  \n\nInstead of using just the percentiles of the bootstrap distribution there is the approach of bias corrected bootstrap CIs. The function \\texttt{bcanon} provided in the package \\textit{bootstrap} computes an accelerated and bias-corrected bootstrap CI. A MC simulation gives good results (see last row in Table \\ref{3table}) as the true statistics are always covered. The length of the CI for the median is smaller but for the SD it is greater than the ones in the first row. The mean value for the bias correction $\\hat{z}_0$ is about $-0.026$ for the median and $0.124$ for the standard deviation. Taking the value of the standard normal cdf of the values shows us that on average 0.49 of the bootstrap medians are smaller than the sample median. The same holds for 0.55 of the bootstrap standard deviations respectively. On average one would expect those values close to 0.5 and thus the average $\\hat{z}_0$ close to 0. The acceleration constant is computed by a transformation of the Jackknife statistics and lies at a scale of $10^{-15}$ in this case and thus is negligible. Looking at the formula this is not surprising. The median and standard deviation should not change remarkable when leaving out one instance. Especially the median ranges between at most three values anyway. Together with the small sample size of 100 the sum of distances from the Jackknife statistics' mean is not very high. Therefore we can say that the CI is constructed by taking the $\\lfloor R\\alpha_1 \\rfloor$th and the $\\lfloor R\\alpha_2\\rfloor$th instances of the ordered bootstrap statistics, where $\\alpha_1=\\Phi (z_{\\alpha /2}+2\\hat{z}_0)$, $\\alpha_2=\\Phi (z_{1-\\alpha /2}+2\\hat{z}_0)$ and $\\Phi$ denotes the standard normal cdf. \n\n\\section{Application for Sleep Heart Health Study data}\nIn this section we use the bootstrap method to build CIs for a real data set. We are just concerning the variable \\texttt{rdi4p} encoding the respiratory disturbance index. The histogram (Figure \\ref{3histdata}) shows the distribution of the data. As it looks like an exponential distribution (i.e. a Weibull distribution with shape parameter 1), I added the respective density with mean equal to the sample mean ($1/\\lambda = 8.66$). The fit looks good and it would get better when refining the bin size, but for clearness is stay with this size.\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[width=0.5\\textwidth, keepaspectratio]{ex3/hist_data.png}\n\\caption{Histogram of the respiratory disturbance index (\\texttt{rdi4p}) together with the density of a fitted exponential distribution (orange) with $\\lambda = 0.12$.}\n\\label{3histdata}\n\\end{figure}\n\nNow we want to estimate confidence intervals for the median and standard deviation for \\texttt{rdi4p}. We use $R=1000$ bootstrap repetitions. The sample length is $n=5804$ and the sample statistics are $\\hat{x}_{med}=4.19$ and $\\hat{\\sigma}=12.43$. The results for the percentile CI and the accelerated bias-corrected CI are shown in Table \\ref{3tabledata}. We see that the function \\texttt{bcanon} produced \\textbf{NaN} for the CI of the median. This is because is uses the variance of the Jackknife statistics in the definition of the acceleration coefficient. As the median occurs twice in the data the denominator is zero and the acceleration coefficient is not defined. For SD we see that the upper confidence bound is smaller with the corrected method, whereas the lower bound is roughly the same as in the percentile method. It is surprising that the sample value for the standard deviation is not included in the confidence interval for the second method. The percentile CIs include both statistics. Of course, we don't know the true parameters or distribution here, so we can't judge the real precision here.  \n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{lrrrr}\n  \\hline\n & lower\\_med & upper\\_med & lower\\_sd & upper\\_sd \\\\ \n  \\hline\npercentile CI & 3.95 & 4.41 & 11.80 & 13.11 \\\\ \nacc bias-corr CI & NaN & NaN & 11.87 & 11.95 \\\\ \n   \\hline\n\\end{tabular}\n\\caption{Confidence intervals for median and SD using the percentile method (first row) and the accelerated bias-corrected CI using \\texttt{bcanon} (second row).}\n\\label{3tabledata}\n\\end{table}\n", "meta": {"hexsha": "ef528d8b406e6332110f288de22f0bf1f7f6f25f", "size": 7929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex3/ex3.tex", "max_stars_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_stars_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex3/ex3.tex", "max_issues_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_issues_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex3/ex3.tex", "max_forks_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_forks_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_forks_repo_licenses": ["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.8870967742, "max_line_length": 1719, "alphanum_fraction": 0.7686971875, "num_tokens": 2049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.6475419977140745}}
{"text": "\\section{Propositional truncations}\\label{sec:propositional-truncation}\n\nThe propositional truncation operation is a universal way of turning type a type $A$ into a proposition $\\brck{A}$. Informally, the proposition $\\brck{A}$ is the proposition that $A$ is inhabited. More precisely, the propositional truncation of $A$ comes equipped with a map $A\\to\\brck{A}$ and it is characterized by its universal property, which asserts that any map $A\\to P$ into a proposition $P$ extends uniquely to a map $\\brck{A}\\to P$, as indicated in the diagram\n\\begin{equation*}\n  \\begin{tikzcd}\n    A \\arrow[dr] \\arrow[d] \\\\\n    \\brck{A} \\arrow[r,densely dotted] & P.\n  \\end{tikzcd}\n\\end{equation*}\nUsing the propositional truncation operation we can define many important mathematical concepts, including the image of a map, surjectivity, and connected components. We will discuss those topics in \\cref{chap:image}.\n\n\\subsection{The universal property of propositional truncations}\\label{sec:propositional-truncation-up}\n\n\\begin{defn}\nLet $A$ be a type, and let $f:A\\to P$ be a map into a proposition $P$. We say that $f$ is a \\define{propositional truncation of $A$} if for every proposition $Q$, the precomposition map\n\\begin{equation*}\n\\blank\\circ f:(P\\to Q)\\to (A\\to Q)\n\\end{equation*}\nis an equivalence. This property of $f$ is also called the \\define{universal property of propositional truncation of $A$}\\index{universal property!of propositional truncation}\n\\end{defn}\n\nIn other words, a map $f:A\\to P$ into a proposition $P$ is a propositional truncation of $A$ if every map $g:A\\to Q$ into a proposition extends uniquely along $f$, as indicated in the diagram\n\\begin{equation*}\n  \\begin{tikzcd}\n    A \\arrow[d,swap,\"f\"] \\arrow[dr,\"g\"] \\\\\n    P \\arrow[r,densely dotted] & Q.\n  \\end{tikzcd}\n\\end{equation*}\nIndeed, this unique extension property asserts that the type\n\\begin{equation*}\n  \\sm{h:P\\to Q}h\\circ f=g\n\\end{equation*}\nis contractible for every $g:A\\to Q$. In other words, the unique extension property asserts that the precomposition function $\\blank\\circ f:(P\\to Q)\\to (A\\to Q)$ is a contractible map, which is the case if and only if it is an equivalence.\n\n\\begin{rmk}\n  Note that if $Q$ is a proposition, then the type $X\\to Q$ is a proposition for any type $X$. Furthermore, recall from \\cref{ex:equiv-bi-implication} that the map $(P\\to Q)\\to (A\\to Q)$ is an equivalence as soon as there is a map in the converse direction. Therefore, in order to prove the universal property of the propositional truncation it suffices to show that\n  \\begin{equation*}\n    (A\\to Q)\\to (P\\to Q).\n  \\end{equation*}\n  We also note that the universal property of the propositional truncation of a type is formulated with respect to all propositions, regardless of the universe they live in. \n\\end{rmk}\n\n\\begin{eg}\n  Suppose $A$ is a type that comes equipped with a point $a:A$, such as the booleans, the type of natural numbers, or the loop space $\\loopspace{A}$ of a pointed type. Then the constant map\n  \\begin{equation*}\n    \\const_\\ttt: A\\to\\unit\n  \\end{equation*}\n  is a propositional truncation of $A$. To see this, let $Q$ be an arbitrary proposition. It suffices to show that\n  \\begin{equation*}\n    (A\\to Q)\\to (\\unit\\to Q).\n  \\end{equation*}\n  To see this, let $f:A\\to Q$. Then we have $f(a):Q$, so we define $\\const_{f(a)}:\\unit\\to Q$. Thus we see that we have\n  \\begin{equation*}\n    \\lam{f}\\const_{f(a)}:(A\\to Q)\\to (\\unit\\to Q).\n  \\end{equation*}\n  This proves that $\\const_\\ttt:A\\to \\unit$ satisfies the universal property of the propositional truncation of $A$. \n\\end{eg}\n\n\\begin{eg}\n  If the type $A$ is already a proposition, then the identity function\n  \\begin{equation*}\n    \\idfunc:A\\to A\n  \\end{equation*}\n  is a propositional truncation of $A$. To see this, simply note that the precomposittion function with the identity function\n  \\begin{equation*}\n    \\blank\\circ\\idfunc : (A\\to Q)\\to (A\\to Q)\n  \\end{equation*}\n  is itself just the identity function. In particular, it is an equivalence.\n\n  Similarly, any equivalence $e:P\\simeq P'$ between propositions satisfies the universal property of the propositional truncation of $P$, since precomposing by an equivalence is an equivalence by \\cref{ex:equiv_precomp}.\n\\end{eg}\n\nThe universal property of the propositional truncation determines the propositional truncation up to equivalence. Such proofs of uniqueness from a universal property always follow the same pattern.\n\n\\begin{prp}\\label{prp:propositional-truncation-3-for-2}\n  Let $A$ be a type, and consider a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      \\phantom{P'} & A \\arrow[dl,swap,\"f\"] \\arrow[dr,\"{f'}\"] \\\\\n      P \\arrow[rr,swap,\"h\"] & & P'\n    \\end{tikzcd}\n  \\end{equation*}\n  where $P$ and $P'$ are propositions. If any two of the following three assertions hold, so does the third:\n  \\begin{enumerate}\n  \\item The map $f$ satisfies the universal property of the propositional truncation of $A$.\n  \\item The map $f'$ satisfies the universal propertyof the propositional truncation of $A$.\n  \\item The map $h$ is an equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  Note that the map $h:P\\to P'$ is an equivalence if and only if for every proposition $Q$, the precomposition map\n  \\begin{equation*}\n    \\blank\\circ h:(P'\\to Q)\\to (P\\to Q)\n  \\end{equation*}\n  is an equivalence. Thus, the claim follows by observing that for every proposition $Q$ we have the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-1em]\n      (P'\\to Q) \\arrow[rr,\"\\blank\\circ h\"] \\arrow[dr,swap,\"\\blank\\circ {f'}\"] & & (P\\to Q) \\arrow[dl,\"\\blank\\circ f\"] \\\\\n      & (A\\to Q). & \\phantom{(P'\\to Q)}\n    \\end{tikzcd}\n  \\end{equation*}\n\\end{proof}\n\n\\begin{cor}\\label{cor:uniquely-unique-brck}\n  Consider two maps $f:A\\to P$ and $f':A\\to P'$ into propositions $P$ and $P'$, both satisfying the universal property of the propositional truncation of $A$. Then the type of equivalences $e:P \\simeq P'$ for which the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      \\phantom{P'} & A \\arrow[dl,swap,\"f\"] \\arrow[dr,\"{f'}\"] \\\\\n      P \\arrow[rr,swap,\"e\"] & & P'\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, is contractible.\n\\end{cor}\n\n\\begin{rmk}\n  Note that the triangles in \\cref{prp:propositional-truncation-3-for-2,cor:uniquely-unique-brck} always commutes, since $P$ and $P'$ are assumed to be propositions.\n\\end{rmk}\n\nNow that we have shown that propositional truncations are determined uniquely, we will assume that any universe is closed under propositional truncations.\n\n\\begin{axiom}\\label{axiom:propositional-truncations}\n  Any universe $\\UU$ is closed under propositional truncations: for any type $A:\\UU$ there is a proposition $\\brck{A}:\\UU$ equipped with a map $\\eta:A\\to\\brck{A}$ that satisfies the universal property of the propositional truncation.\n\\end{axiom}\n\nThe propositional truncation is therefore an operation\n\\begin{equation*}\n  \\brck{\\blank}:\\UU\\to\\UU\n\\end{equation*}\non the universe. One simple application of the universal property of the propositional truncation is that $\\brck{\\blank}$ also acts on functions in a functorial way.\n\n\\begin{prp}\n  There is a map\n  \\begin{equation*}\n    \\brck{\\blank}:(A\\to B)\\to (\\brck{A}\\to\\brck{B})\n  \\end{equation*}\n  for any two types $A$ and $B$, such that\n  \\begin{align*}\n    \\brck{\\idfunc} & \\htpy \\idfunc \\\\\n    \\brck{g\\circ f} & \\htpy \\brck{g}\\circ\\brck{f}.\n  \\end{align*}\n\\end{prp}\n\n\\begin{proof}\n  For any $f:A\\to B$, the map $\\brck{f}:\\brck{A}\\to\\brck{B}$ is defined to be the unique extension\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[d,swap,\"\\eta\"] \\arrow[r,\"f\"] & B \\arrow[d,\"\\eta\"] \\\\\n      \\brck{A} \\arrow[r,densely dotted,swap,\"\\brck{f}\"] & \\brck{B}.\n    \\end{tikzcd}\n  \\end{equation*}\n  To see that $\\brck{\\blank}$ preserves identity maps and compositions, simply note that $\\idfunc[\\brck{A}]$ is an extension of $\\idfunc[A]$, and that $\\brck{g}\\circ\\brck{f}$ is an extension of $g\\circ f$. Hence the homotopies are obtained by uniqueness.\n\\end{proof}\n\n\\subsection{Propositional truncations as higher inductive types}\n\nThe idea of higher inductive types is that types can be generated inductively not only by point constructors, such as $\\zeroN:\\N$ and $\\succN:\\N\\to\\N$, but also by path constructors. One of the first examples of a higher inductive type was the propositional truncation of a type $A$. This is a type $\\brck{A}$ equipped with one point constructor\n\\begin{equation*}\n  \\eta : A \\to \\brck{A},\n\\end{equation*}\none path constructor\n\\begin{equation*}\n  \\alpha : \\prd{x,y:\\brck{A}}x=y.\n\\end{equation*}\nNote that the path constructor $\\alpha$ immediately proves that $\\brck{A}$ is a proposition. Now we should formulate the induction principle for the propositional truncation.\n\nJust as we did with the universal property, we will formulate the induction principle of the propositional truncation for an arbitrary map $f:A\\to P$ into a proposition $P$. When the induction principle is formulated in this way, we will be able to show that $f$ satisfies the universal property if and only if it satisfes the induction principle.\n\nConsider a map $f:A\\to P$ into a type equipped with a family of paths\n\\begin{equation*}\n  \\alpha : \\prd{p,q:P}p=q\n\\end{equation*}\nwitnessing that $P$ is a proposition, and consider a type family $B$ over $P$. The induction principle of the propositional truncation of $A$ tells us what we have to do in order to construct a dependent function $h:\\prd{p:P}B(p)$.\n\nIn order to figure out what the induction principle has to be, we first note that if we start with a dependent function $h:\\prd{p:P}B(p)$, then we also obtain the function $h\\circ f : \\prd{x:A}B(f(x))$. In other words, if we think of $f:A\\to P$ as the point constructor of $P$, then the function $h\\circ f$ describes the action of $h$ on the points of $P$. The first requirement in the induction principle is therefore that $B$ must come equipped with a dependent function\n\\begin{equation*}\n  g:\\prd{x:A}B(f(x)).\n\\end{equation*}\nFurthermore, the function $h$ acts on the paths in $P$ via its dependent action on paths, which we constructed in \\cref{defn:apd}. The paths in $P$ are generated by $\\alpha$, so we obtain a function\n\\begin{equation*}\n  \\lam{p}{q}\\apd{h}{\\alpha(p,q)} : \\prd{p,q:P} \\tr_B(\\alpha(p,q),h(p))=h(q).\n\\end{equation*}\nThe induction principle must ensure that any function $h$ defined via the induction principle, satisfies this law. Therefore, the second condition in the induction principle is that we must have a family of identifications\n\\begin{equation*}\n  \\prd{p,q:P}{y:B(p)}{z:B(q)}\\tr_B(\\alpha(p,q),y)= z.\n\\end{equation*}\nWe now formulate the induction principle for propositional truncation.\n\n\\begin{defn}\n  Consider a map $f:A\\to P$ into a type $P$ equipped with a family of paths\n  \\begin{equation*}\n    \\alpha : \\prd{p,q:P}p=q,\n  \\end{equation*}\n  witnessing that $P$ is a proposition. We say that $f$ satisfies the induction principle for the propositional truncation of $A$ if for any family $B$ over $P$ that comes equipped with\n  \\begin{align*}\n    g & : \\prd{x:A}B(f(x)) \\\\\n    \\beta & : \\prd{p,q:P}{y:B(p)}{z:B(q)}\\tr_B(\\alpha(p,q),y)=z,\n  \\end{align*}\n  there is a dependent function $h:\\prd{p:P}B(p)$ equipped with a homotopy\n  \\begin{equation*}\n    \\prd{x:A}h(f(x))= g(x).\n  \\end{equation*}\n\\end{defn}\n\nIn the following lemma we show that if a family $B$ over $\\brck{A}$ comes equipped with a family of paths\n\\begin{equation*}\n  \\prd{x,y:\\brck{A}}{u:B(x)}{v:B(y)}\\tr_B(\\alpha(x,y),u)=v,\n\\end{equation*}\nthen $B$ must be a family of propositions.\n\n\\begin{lem}\\label{lem:case-paths-induction-principle-propositional-truncation}\n  Let $P$ be a type equipped with a family of paths\n  \\begin{equation*}\n    \\alpha : \\prd{p,q:P}p=q,\n  \\end{equation*}\n  showing that $P$ is a proposition, and consider a type family $B$ over $P$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The family $B$ comes equipped with a family of identifications\n    \\begin{equation*}\n      \\beta:\\prd{p,q:P}{x:B(p)}{y:B(q)}\\tr_B(\\alpha(p,q),x)=y,\n    \\end{equation*}\n  \\item The family $B$ is a family of propositions.\n  \\end{enumerate}\n\\end{lem}\n\n\\begin{proof}\n  Assuming that (i) holds, we will show that each $B(p)$ is a proposition by showing that\n  \\begin{equation*}\n    B(p)\\to\\iscontr(B(p)).\n  \\end{equation*}\n  Let $x:B(p)$. We have to construct a center of contraction and a contraction. Our plan is to use $\\beta$ to define the contraction, so it is natural to define the center as $\\tr_B(\\alpha(p,p),x)$. Now we take\n  \\begin{equation*}\n    \\beta(p,p,x):\\prd{y:B(p)}\\tr_B(\\alpha(p,p),x)=y\n  \\end{equation*}\n  as our contraction. This completes the proof that $B$ is a family of propositions.\n\n  The converse is immediate: if $B$ is a family of propositions, then any two terms in any $B(q)$ can be identified.\n\\end{proof}\n\n\\begin{defn}\n  Consider a map $f:A\\to P$ into a proposition $P$. We say that $f$ satisfies the dependent universal property of the propositional truncation of $A$, if for any family $Q$ of propositions over $P$, the precomposition map\n  \\begin{equation*}\n    \\blank\\circ f : \\Big(\\prd{p:P}Q(p)\\Big)\\to\\Big(\\prd{x:A}Q(f(x))\\Big)\n  \\end{equation*}\n  is an equivalence.\n\\end{defn}\n\n\\begin{thm}\n  Consider a map $f:A\\to P$ into a proposition $P$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is a propositional truncation.\n  \\item The map $f$ satisfies the dependent universal property of the propositional truncation.\n  \\item The map $f$ satisfies the induction principle of the propositional truncation.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  We will first show that (i) and (ii) are equivalent. Of course, the universal property is a special case of the dependent universal property, so the fact that (ii) implies (i) is immediate. We now show that (i) implies (ii). Let $Q$ be a family of propositions over $P$, and consider the following commuting diagram:\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\Big(\\sm{h:P\\to P}\\prd{p:P}Q(h(p))\\Big) \\arrow[r,\"{\\tot[\\blank\\circ f]{\\blank\\circ f}}\"] \\arrow[d,swap,\"\\choice^{-1}\"] & \\Big(\\sm{g:A\\to P}\\prd{x:A}Q(g(x))\\Big) \\arrow[d,\"\\choice^{-1}\"] \\\\\n      \\Big(P\\to \\sm{p:P}Q(p)\\Big) \\arrow[r,\"\\blank\\circ f\"] \\arrow[d,swap,\"\\proj 1\\circ\\blank\"]  & \\Big(A \\to \\sm{p:P}Q(p)\\Big) \\arrow[d,\"\\proj 1\\circ\\blank\"] \\\\\n      \\Big(P\\to P\\Big) \\arrow[r,swap,\"\\blank\\circ f\"] & \\Big(A\\to P\\Big)\n    \\end{tikzcd}\n  \\end{equation*}\n  In this diagram the bottom map is an equivalence by the universal property of the propositional truncation of $A$. Note also that the type $\\sm{p:P}Q(p)$ is a proposition by \\cref{ex:istrunc_sigma}, so it follows that also the middle map is an equivalence. Furthermore, the type theoretic choice maps are equivalences by \\cref{thm:choice}, so it also follows that the top map is an equivalence. Now we use \\cref{thm:equiv-toto} to conclude that the family of maps\n  \\begin{equation*}\n    \\blank\\circ f: \\Big(\\prd{p:P}Q(h(p))\\Big)\\to\\Big(\\prd{x:A}Q(h(f(x)))\\Big)\n  \\end{equation*}\n  indexed by $h:P\\to P$ is a family of equivalences. The dependent universal property is now just a special case: take $h\\jdeq\\idfunc$. This completes the proof that (i) is equivalent to (ii).\n\n  It remains to show that (ii) is equivalent to (iii). By \\cref{lem:case-paths-induction-principle-propositional-truncation} it follows that the induction principle is equivalent to the property that for each family $Q$ of propositions over $P$, the precomposition map\n  \\begin{equation*}\n    \\blank\\circ f : \\Big(\\prd{p:P}Q(p)\\Big)\\to\\Big(\\prd{x:A}Q(f(x))\\Big)\n  \\end{equation*}\n  has a section. Since the domain and codomain of this map are propositions by \\cref{thm:trunc_pi}, we see that this precomposition map has a section if and only if it is an equivalence.\n\\end{proof}\n\n\\begin{exercises}\n  \\exercise Let $A$ be a type and let $P$ be a proposition, and suppose that $P$ is a retract of $A$. Show that the retraction $A\\to P$ is a propositional truncation.\n%  \\exercise Show that the relation $x,y\\mapsto\\brck{x=y}$ is an equivalence relation, on any type.\n  \\exercise Consider two maps $f:A\\to P$ and $g:B\\to Q$ into propositions $P$ and $Q$. Recall from \\cref{ex:istrunc_sigma} that the type $P\\times Q$ is also a proposition. Show that if both $f$ and $g$ are propositional truncations then the map $f\\times g : A\\times B\\to P\\times Q$ is also a propositional truncation. Conclude that\n  \\begin{equation*}\n    \\brck{A\\times B}\\simeq \\brck{A}\\times\\brck{B}. \n  \\end{equation*}\n  \\exercise Consider two propositions $P$ and $Q$, and define\n  \\begin{align*}\n    P\\land Q & \\defeq P\\times Q\\\\\n    P\\vee Q & \\defeq \\brck{P+Q}.\n  \\end{align*}\n  \\begin{subexenum}\n  \\item Construct maps $i:P\\to P\\vee Q$ and $j:Q\\to P\\vee Q$.\n  \\item Prove the universal property of disjunction, i.e., show that for any proposition $R$, the map\n    \\begin{equation*}\n      (P\\vee Q\\to R) \\to (P\\to R)\\land (Q\\to R) \n    \\end{equation*}\n    given by $h\\mapsto (h\\circ i,h\\circ j)$ is an equivalence.\n  \\end{subexenum}\n  \\exercise Consider a family $P$ of propositions over a type $A$, and define\n  \\begin{align*}\n    \\forall_{(x:A)}P(x) & \\defeq \\prd{x:A}P(x) \\\\\n    \\exists_{(x:A)}P(x) & \\defeq \\Brck{\\sm{x:A}P(x)}\n  \\end{align*}\n  \\begin{subexenum}\n  \\item Construct a map $i_a : P(a)\\to \\exists_{(x:A)}P(x)$ for each $a:A$.\n  \\item Prove the universal property of the existential quantification, i.e. show that for any proposition $Q$, the map\n    \\begin{equation*}\n      \\Big(\\Big(\\exists_{(x:A)}P(x)\\Big)\\to Q\\Big)\\to \\Big(\\forall_{(x:A)}(P(x)\\to Q)\\Big)\n    \\end{equation*}\n    given by $h\\mapsto \\lam{x}h\\circ i_x$, is an equivalence.\n  \\end{subexenum}\n  \\exercise Show that\n  \\begin{equation*}\n    \\eqv{\\brck{A}}{\\prd{P:\\prop}(A\\to P)\\to P}\n  \\end{equation*}\n  for any type $A:\\UU$. This is called the \\define{impredicative encoding} of the propositional truncation.\n  % \\exercise For any $B:A\\to\\UU$, construct an equivalence\n  % \\begin{equation*}\n  %   \\eqv{\\Big(\\exists_{(a:A)}\\brck{B(a)}\\Big)}{\\brck{\\sm{a:A}B(a)}}\n  % \\end{equation*}\n\\end{exercises}", "meta": {"hexsha": "b31c6db535b92995b07123fc62ceb85249f915bd", "size": 18057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/propositional-truncation.tex", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "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/propositional-truncation.tex", "max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "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/propositional-truncation.tex", "max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "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": 56.2523364486, "max_line_length": 472, "alphanum_fraction": 0.7013346625, "num_tokens": 5697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370423, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6474570336840242}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Required to use \\cfrac\n\\usepackage{amsmath}\n\n% Required to use \\sfrac\n\\usepackage{xfrac}\n\n\\begin{document}\n\n\\section*{Simple fraction}\n\nFractions are created as follows.\n\n% Syntax: \\frac{numerator}{denominator}\n\n\\[\\frac{1}{x} = x^{-1}\\]\n\n\\section*{Continued (or cascade) fractions}\n\nA fraction can contain another one. If the command \\emph{\\textbackslash frac} is, this would be the result:\n\n\\[\\frac{x}{x + \\frac{1}{2}}\\]\n\nThe sub fraction is very small. This is why the command \\emph{\\textbackslash cfrac} is recommended for continued fractions:\n\n\\[\\cfrac{x}{x + \\cfrac{1}{2}}\\]\n\nSome people prefer to still use \\emph{\\textbackslash frac} and use the command \\emph{\\textbackslash displaystyle} before each sub fractions:\n\n\\[\\frac{x}{x + \\displaystyle\\frac{1}{2}}\\]\n\nDespite this practice is sometimes promoted, it should be avoided because the equation has some spacing issues, such as on top of $\\frac{1}{2}$.\n\n\\section*{Slanted fractions}\n\nSlanted fractions are created as follows : $\\sfrac{1}{2}$.\n\n\\end{document}", "meta": {"hexsha": "d2314c0419195fc5caaa8323c6f2314508d35b56", "size": 1098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/fractions.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/fractions.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/fractions.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": 26.1428571429, "max_line_length": 144, "alphanum_fraction": 0.7276867031, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290699, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.6474570327333682}}
{"text": "\\section{Network Throughput, Bandwidth and Safety Parameters}\nThe parameters of the flow and load of the system (about 80\\% at peak hours 9h-11h and 15h-16h) can be shared for Headquarter and Branches as follows:\n\\begin{itemize}\n  \\item Servers used for updates, web access, database access, ..... The total upload and download capacity is about 500 MB / day.\n  \\item Each workstation is used for Web browsing, document downloads, customer transactions, ... The total upload and download capacity is about 100 MB / day.\n  \\item WiFi-connected laptop for customers’ accesses about 50 MB / day.\n\\end{itemize}\n\n\\subsection{Headquarter}\n\\subsubsection{Server}\nThe total peak hours time in a days is 3 hours (9h-11h and 15h-16h) and may consume up to 80\\%. \\\\\n$$Bandwidth = \\, \\frac{5*500*0.8}{3*3600}*8 = 1.481Mbps$$\n$$Throughput = \\, \\frac{5*500}{8*3600}*8 = 0.694Mbps$$\n\\subsubsection{Workstation}\nAssume each workstation will work 8 hours a day\n$$Bandwidth = \\, \\frac{100*100*0.8}{3*3600}*8 = 5.926Mbps$$\n$$Throughput = \\, \\frac{100*100}{8*3600}*8 = 2.778Mbps$$\n\\subsubsection{User}\nAssume that the number of customers in one day is about 200 customers, and in peak\ntime is 150 customers. Also, assume that each user access Wifi 8 hours a day.\n$$Bandwidth = \\, \\frac{150*50}{3*3600}*8 = 5.556Mbps$$\n$$Throughput = \\, \\frac{200*50}{8*3600}*8 = 2.778Mbps$$\n\n\\subsubsection{Total}\n$$Bandwidth = 1.481+5.926+5.556 = 12.963Mbps$$\n$$Throughput = 0.694+2.778+2.778 = 6.25Mbps$$\n\n\\subsection{Safety parameters}\nTo ensure for the next 10 years, we need to consider the rate 20\\% per five years. The first 5 years, the number of customer will still not increase and this number will increase in the next 5 years.\n$$Bandwidth = 12.963*1.2 = 15.556Mbps$$\n$$Throughput =6.25*1.2 = 7.5Mbps$$\n\n\\subsection{Branch}\n\\subsubsection{Server}\nThe total peak hours time in a days is 3 hours (9h-11h and 15h-16h) and may consume up to 80\\%. \\\\\n$$Bandwidth = \\, \\frac{3*500*0.8}{3*3600}*8 = 0.889Mbps$$\n$$Throughput = \\, \\frac{3*500}{8*3600}*8 = 0.417Mbps$$\n\\subsubsection{Workstation}\nAssume each workstation will work 8 hours a day\n$$Bandwidth = \\, \\frac{50*100*0.8}{3*3600}*8 = 2.963Mbps$$\n$$Throughput = \\, \\frac{50*100}{8*3600}*8 = 1.389Mbps$$\n\\subsubsection{User}\nAssume that the number of customers in one day is about 140 customers, and in peak\ntime is 70 customers. Also, assume that each user access Wifi 8 hours a day.\n$$Bandwidth = \\, \\frac{70*50}{3*3600}*8 = 2.593Mbps$$\n$$Throughput = \\, \\frac{140*50}{8*3600}*8 = 2.778Mbps$$\n\n\\subsubsection{Total}\n$$Bandwidth = 0.889+2.963+2.593= 6.445Mbps$$\n$$Throughput =0.417+1.389+2.778= 4.584Mbps$$\n\n\\subsection{Safety parameters}\nTo ensure for the next 10 years, we need to consider the rate 20\\% per five years. The first 5 years, the number of customer will still not increase and this number will increase in the next 5 years.\n$$Bandwidth = 6.445*1.2 = 7.734Mbps$$\n$$Throughput =4.584*1.2 = 5.501Mbps$$\n", "meta": {"hexsha": "27bf0f768e33e44948ddfb768b3b672166a7f70a", "size": 2936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/step3.tex", "max_stars_repo_name": "Smithienious/CO3094-asg2", "max_stars_repo_head_hexsha": "8c301fcbcbe2a7deceeb50105ed5d6624e6ad413", "max_stars_repo_licenses": ["MIT"], "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/step3.tex", "max_issues_repo_name": "Smithienious/CO3094-asg2", "max_issues_repo_head_hexsha": "8c301fcbcbe2a7deceeb50105ed5d6624e6ad413", "max_issues_repo_licenses": ["MIT"], "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/step3.tex", "max_forks_repo_name": "Smithienious/CO3094-asg2", "max_forks_repo_head_hexsha": "8c301fcbcbe2a7deceeb50105ed5d6624e6ad413", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-24T14:29:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-24T14:29:08.000Z", "avg_line_length": 52.4285714286, "max_line_length": 199, "alphanum_fraction": 0.7132152589, "num_tokens": 1008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6474570321730398}}
{"text": "\\appendix\n\\section{Appendix: Example Primer}\n\\label{sec:examplePrimer}\nIn this Appendix, a set of examples are reported. In order to be as general as possible, the \\textit{Model} type ``ExternalModel'' has been used.\n%%%% EXAMPLE 1\n\\subsection{Example 1.}\n\\label{subsec:ex1}\nThis simple example is about the construction of a ``Lorentz attractor'', sampling the relative input space. The parameters that are sampled represent the initial coordinate (x0,y0,z0) of the attractor origin.\n\n\\begin{lstlisting}[style=XML,morekeywords={debug,re,seeding,class,subType,limit}]\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Simulation verbosity=\"debug\">\n<!-- RUNINFO -->\n<RunInfo>\n    <WorkingDir>externalModel</WorkingDir>\n    <Sequence>FirstMRun</Sequence>\n    <batchSize>3</batchSize>\n</RunInfo>\n<!-- Files -->\n<Files>\n    <Input name='lorentzAttractor.py' type=''>lorentzAttractor</Input>\n</Files>\n<!-- STEPS -->\n<Steps>\n    <MultiRun name='FirstMRun'  re-seeding='25061978'>\n        <Input   class='Files'     type=''               >lorentzAttractor.py</Input>\n        <Model   class='Models'    type='ExternalModel'  >PythonModule</Model>\n        <Sampler class='Samplers'  type='MonteCarlo'     >MC_external</Sampler>\n        <Output  class='DataObjects'     type='HistorySet'      >testPrintHistorySet</Output>\n        <Output  class='Databases' type='HDF5'           >test_external_db</Output>\n        <Output  class='OutStreams' type='Print'   >testPrintHistorySet_dump</Output>\n    </MultiRun >\n</Steps>\n<!-- MODELS -->\n<Models>\n    <ExternalModel name='PythonModule' subType='' ModuleToLoad='externalModel/lorentzAttractor'>\n       <variables>sigma,rho,beta,x,y,z,time,x0,y0,z0</variables>\n    </ExternalModel>\n</Models>\n<!-- DISTRIBUTIONS -->\n<Distributions>\n    <Normal name='x0_distrib'>\n        <mean>4</mean>\n        <sigma>1</sigma>\n    </Normal>\n    <Normal name='y0_distrib'>\n        <mean>4</mean>\n        <sigma>1</sigma>\n    </Normal>\n    <Normal name='z0_distrib'>\n        <mean>4</mean>\n        <sigma>1</sigma>\n    </Normal>\n</Distributions>\n<!-- SAMPLERS -->\n<Samplers>\n    <MonteCarlo name='MC_external'>\n      <samplerInit>\n        <limit>3</limit>\n      </samplerInit>\n      <variable name='x0' >\n        <distribution  >x0_distrib</distribution>\n      </variable>\n      <variable name='y0' >\n        <distribution  >y0_distrib</distribution>\n      </variable>\n      <variable name='z0' >\n        <distribution  >z0_distrib</distribution>\n      </variable>\n    </MonteCarlo>\n</Samplers>\n<!-- DATABASES -->\n<Databases>\n  <HDF5 name=\"test_external_db\"/>\n</Databases>\n<!-- OUTSTREAMS -->\n<OutStreams>\n  <Print name='testPrintHistorySet_dump'>\n    <type>csv</type>\n    <source>testPrintHistorySet</source>\n  </Print>\n</OutStreams>\n<!-- DATA OBJECTS -->\n<DataObjects>\n    <HistorySet name='testPrintHistorySet'>\n        <Input>x0,y0,z0</Input>\n        <Output>time,x,y,z</Output>\n   </HistorySet>\n</DataObjects>\n</Simulation>\n\\end{lstlisting}\nThe Python \\textit{ExternalModel} is reported below:\n\\begin{lstlisting}[language=python]\nimport numpy as np\n\ndef run(self,Input):\n  max_time = 0.03\n  t_step = 0.01\n\n  numberTimeSteps = int(max_time/t_step)\n\n  self.x = np.zeros(numberTimeSteps)\n  self.y = np.zeros(numberTimeSteps)\n  self.z = np.zeros(numberTimeSteps)\n  self.time = np.zeros(numberTimeSteps)\n\n  self.x0 = Input['x0']\n  self.y0 = Input['y0']\n  self.z0 = Input['z0']\n\n  self.x[0] = Input['x0']\n  self.y[0] = Input['y0']\n  self.z[0] = Input['z0']\n  self.time[0]= 0\n\n  for t in range (numberTimeSteps-1):\n    self.time[t+1] = self.time[t] + t_step\n    self.x[t+1]    = self.x[t] +  self.sigma*\n                      (self.y[t]-self.x[t]) * t_step\n    self.y[t+1]    = self.y[t] + (self.x[t]*\n                      (self.rho-self.z[t])-self.y[t]) * t_step\n    self.z[t+1]    = self.z[t] + (self.x[t]*\n                          self.y[t]-self.beta*self.z[t]) * t_step\n\\end{lstlisting}\n%%%% EXAMPLE 2\n\\subsection{Example 2.}\n\\label{subsec:ex1}\nThis example shows a slightly more complicated example, that employs the usage of:\n\\begin{itemize}\n    \\item \\textit{Samplers:} Grid and Adaptive;\n    \\item \\textit{Models:} External, Reduce Order Models and Post-Processors;\n    \\item \\textit{OutStreams:} Prints and Plots;\n    \\item \\textit{Data Objects:} PointSets;\n    \\item \\textit{Functions:} ExternalFunctions.\n\\end{itemize}\nThe goal of this input is to compute the ``SafestPoint''.\nIt provides the coordinates of the farthest\npoint from the limit surface that is given as an input.\n%\nThe safest point coordinates are expected values of the coordinates of the\nfarthest points from the limit surface in the space of the ``controllable''\nvariables based on the probability distributions of the ``non-controllable''\nvariables.\n\nThe term ``controllable'' identifies those variables that are under control\nduring the system operation, while the ``non-controllable'' variables are\nstochastic parameters affecting the system behaviour randomly.\n\nThe ``SafestPoint'' post-processor requires the set of points belonging to the\nlimit surface, which must be given as an input.\n\n\\begin{lstlisting}[style=XML,morekeywords={debug,re,seeding,class,subType,limit}]\n<Simulation verbosity='debug'>\n\n<!-- RUNINFO -->\n<RunInfo>\n  <WorkingDir>SafestPointPP</WorkingDir>\n  <Sequence>pth1,pth2,pth3,pth4</Sequence>\n  <batchSize>50</batchSize>\n</RunInfo>\n\n<!-- STEPS -->\n<Steps>\n  <MultiRun name = 'pth1' pauseAtEnd = 'False'>\n    <Sampler  class = 'Samplers'  type = 'Grid'           >grd_vl_ql_smp_dpt</Sampler>\n    <Input    class = 'DataObjects'     type = 'PointSet'   >grd_vl_ql_smp_dpt_dt</Input>\n    <Model    class = 'Models'    type = 'ExternalModel'  >xtr_mdl</Model>\n    <Output   class = 'DataObjects'     type = 'PointSet'   >nt_phy_dpt_dt</Output>\n  </MultiRun >\n\n  <MultiRun name = 'pth2' pauseAtEnd = 'True'>\n    <Sampler          class = 'Samplers'  type = 'Adaptive'      >dpt_smp</Sampler>\n    <Input            class = 'DataObjects'     type = 'PointSet'  >bln_smp_dt</Input>\n    <Model            class = 'Models'    type = 'ExternalModel' >xtr_mdl</Model>\n    <Output           class = 'DataObjects'     type = 'PointSet'  >nt_phy_dpt_dt</Output>\n    <SolutionExport   class = 'DataObjects'     type = 'PointSet'  >lmt_srf_dt</SolutionExport>\n  </MultiRun>\n\n  <PostProcess name='pth3' pauseAtEnd = 'False'>\n    <Input    class = 'DataObjects'          type = 'PointSet'       >lmt_srf_dt</Input>\n    <Model    class = 'Models'         type = 'PostProcessor'  >SP</Model>\n    <Output   class = 'DataObjects'          type = 'PointSet'     >sfs_pnt_dt</Output>\n  </PostProcess>\n\n  <OutStreamStep name = 'pth4' pauseAtEnd = 'True'>\n  \t<Input  class = 'DataObjects'            type = 'PointSet'  >lmt_srf_dt</Input>\n  \t<Output class = 'OutStreams' type = 'Print'         >lmt_srf_dmp</Output>\n    <Input  class = 'DataObjects'            type = 'PointSet'  >sfs_pnt_dt</Input>\n  \t<Output class = 'OutStreams' type = 'Print'         >sfs_pnt_dmp</Output>\n  </OutStreamStep>\n</Steps>\n\n<!-- DATA OBJECTS -->\n<DataObjects>\n  <PointSet name = 'grd_vl_ql_smp_dpt_dt'>\n    <Input>x1,x2,gammay</Input>\n    <Output>OutputPlaceHolder</Output>\n  </PointSet>\n\n  <PointSet name = 'nt_phy_dpt_dt'>\n    <Input>x1,x2,gammay</Input>\n    <Output>g</Output>\n  </PointSet>\n\n  <PointSet name = 'bln_smp_dt'>\n    <Input>x1,x2,gammay</Input>\n    <Output>OutputPlaceHolder</Output>\n  </PointSet>\n\n  <PointSet name = 'lmt_srf_dt'>\n    <Input>x1,x2,gammay</Input>\n    <Output>g_zr</Output>\n  </PointSet>\n\n  <PointSet name = 'sfs_pnt_dt'>\n    <Input>x1,x2,gammay</Input>\n    <Output>p</Output>\n  </PointSet>\n</DataObjects>\n\n<!-- DISTRIBUTIONS -->\n<Distributions>\n  <Normal name = 'x1_dst'>\n    <upperBound>10</upperBound>\n    <lowerBound>-10</lowerBound>\n  \t<mean>0.5</mean>\n    <sigma>0.1</sigma>\n  </Normal>\n\n  <Normal name = 'x2_dst'>\n    <upperBound>10</upperBound>\n    <lowerBound>-10</lowerBound>\n    <mean>-0.15</mean>\n    <sigma>0.05</sigma>\n  </Normal>\n\n  <Normal name = 'gammay_dst'>\n    <upperBound>20</upperBound>\n    <lowerBound>-20</lowerBound>\n    <mean>0</mean>\n    <sigma>15</sigma>\n  </Normal>\n</Distributions>\n\n<!-- SAMPLERS -->\n<Samplers>\n  <Grid name = 'grd_vl_ql_smp_dpt'>\n    <variable name = 'x1' >\n      <distribution>x1_dst</distribution>\n      <grid type = 'value' construction = 'equal' steps = '10' upperBound = '10'>2</grid>\n    </variable>\n    <variable name='x2' >\n      <distribution>x2_dst</distribution>\n      <grid type = 'value' construction = 'equal' steps = '10' upperBound = '10'>2</grid>\n    </variable>\n    <variable name='gammay' >\n      <distribution>gammay_dst</distribution>\n      <grid type = 'value' construction = 'equal' steps = '10' lowerBound = '-20'>4</grid>\n    </variable>\n  </Grid>\n\n  <Adaptive name = 'dpt_smp' verbosity='debug'>\n    <ROM              class = 'Models'    type = 'ROM'           >accelerated_ROM</ROM>\n    <Function         class = 'Functions' type = 'External'      >g_zr</Function>\n    <TargetEvaluation class = 'DataObjects'     type = 'PointSet'  >nt_phy_dpt_dt</TargetEvaluation>\n    <Convergence limit = '3000' forceIteration = 'False' weight = 'none' persistence = '5'>1e-2</Convergence>\n      <variable name = 'x1'>\n        <distribution>x1_dst</distribution>\n      </variable>\n      <variable name = 'x2'>\n        <distribution>x2_dst</distribution>\n      </variable>\n      <variable name = 'gammay'>\n        <distribution>gammay_dst</distribution>\n      </variable>\n  </Adaptive>\n</Samplers>\n\n<!-- MODELS -->\n<Models>\n  <ExternalModel name = 'xtr_mdl' subType = '' ModuleToLoad = 'SafestPointPP/safest_point_test_xtr_mdl'>\n    <variables>x1,x2,gammay,g</variables>\n  </ExternalModel>\n\n  <ROM name = 'accelerated_ROM' subType = 'SciKitLearn'>\n    <Features>x1,x2,gammay</Features>\n    <Target>g_zr</Target>\n    <SKLtype>svm|SVC</SKLtype>\n    <kernel>rbf</kernel>\n    <gamma>10</gamma>\n    <tol>1e-5</tol>\n    <C>50</C>\n  </ROM>\n\n  <PostProcessor name='SP' subType='SafestPoint'>\n    <!-- List of Objects (external with respect to this PP) needed by this post-processor -->\n    <Distribution     class = 'Distributions'  type = 'Normal'>x1_dst</Distribution>\n    <Distribution     class = 'Distributions'  type = 'Normal'>x2_dst</Distribution>\n    <Distribution     class = 'Distributions'  type = 'Normal'>gammay_dst</Distribution>\n    <!- end of the list -->\n    <controllable>\n    \t<variable name = 'x1'>\n    \t\t<distribution>x1_dst</distribution>\n    \t\t<grid type = 'value' steps = '20'>1</grid>\n    \t</variable>\n    \t<variable name = 'x2'>\n    \t\t<distribution>x2_dst</distribution>\n    \t\t<grid type = 'value' steps = '20'>1</grid>\n    \t</variable>\n    </controllable>\n    <non-controllable>\n    \t<variable name = 'gammay'>\n    \t\t<distribution>gammay_dst</distribution>\n    \t\t<grid type = 'value' steps = '20'>2</grid>\n    \t</variable>\n    </non-controllable>\n  </PostProcessor>\n</Models>\n\n<!-- FUNCTIONS -->\n<Functions>\n  <External name='g_zr' file='SafestPointPP/safest_point_test_g_zr.py'>\n    <variable>g</variable>\n  </External>\n</Functions>\n\n<!-- OUT-STREAMS -->\n<OutStreams>\n  <Print name = 'lmt_srf_dmp'>\n  \t<type>csv</type>\n  \t<source>lmt_srf_dt</source>\n  </Print>\n\n  <Print name = 'sfs_pnt_dmp'>\n  \t<type>csv</type>\n  \t<source>sfs_pnt_dt</source>\n  </Print>\n</OutStreams>\n\n</Simulation>\n\\end{lstlisting}\nThe Python \\textit{ExternalModel} is reported below:\n\\begin{lstlisting}[language=python]\ndef run(self,Input):\n  self.g = self.x1+4*self.x2-self.gammay\n\\end{lstlisting}\nThe ``Goal Function'',the function that defines the transitions with respect the input space coordinates, is as follows:\n\\begin{lstlisting}[language=python]\ndef __residuumSign(self):\n  if self.g<0 : return  1\n  else        : return -1\n\\end{lstlisting}\n\n%%%%% EXAMPLE 3\n%\\subsection{Example3}\n%\\label{subsec:ex1}\n%example 3\n", "meta": {"hexsha": "29fb0f31a68c81760d5167b299259ba1bf43aa3f", "size": 11769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/examplesPrimer.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/user_manual/examplesPrimer.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/user_manual/examplesPrimer.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": 32.874301676, "max_line_length": 209, "alphanum_fraction": 0.6455943581, "num_tokens": 3537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619134371953, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6474570152373694}}
{"text": "\\section{Loss function and Gradient Descent} \\label{sec:loss_&_gradient_descent}\nSo far only the concept of what a neural network is was explained, but not how it can learn from data, to understand this it is worth to have first a brief summary of what consists a neural network.\n\nA collection of units having nonlinear activation functions form a layer; layers are stacked from the input to the output with some optional hidden layers in-between; the weighted input of a unit is calculated by multiplying its inputs with some weight parameters and adding a bias term; the unit activation is the output of its activation function applied to the weighted input; and by varying the values of the weights and biases it is possible to reach different model behaviours \\textbf{--} this section will only consider the case when the inputs of a unit come from the immediate previous layer and the output is calculated by passing the input values from layer to layer until the last layer (this is called a \\textit{feedforward} neural network), other configurations like \\acp{ResNet} \\cite{resnet2015} and \\acp{RNN} also exist, but it is possible to extend the arguments present here to also explain learning in these contexts.\n\nFor all neural networks, learning is the process of changing the weights and biases (and possibly other values) in order to produce the desired result. The set of values that are learned during training are called the \\textit{parameters} of the network.\n\nThe number of parameters gives the degree of freedom that the network has, in a larger parameter space the network has more possible choices and can construct more complex relations. On the other hand, fewer parameters may make it difficult or impossible to represent the full complexity of the data. However, besides requiring more computational power, very complex models break the idea of sparsity and can more easily fall into the problem of overfitting (see \\autoref{sub:overfitting}).\n\nThe number of parameters in the network is given by its architecture, how many layers it has, how many units in each layer, how the connections are made, and so on. This is a choice made when building the network and is not something that is learned by the algorithm. The set of properties that influence the network but that are not learned are usually called the \\textit{hyperparameters}. \n\nAnother example of hyperparameter is the activation functions used in the units, they are chosen when constructing the neural network and can't be learned \\textbf{--} however some activations like PReLU have internal learnable parameters \\cite{prelu2015}.\n\nLearning is then the process of finding optimal parameters for a network given some hyperparameters. But how can a machine automatically learn the parameters? To do this the network must have some way to quantify the results that it produces, a way to distinguish between good and bad outputs, this is what is called the \\textit{loss function}.\n\nAlso called the cost or objective, the loss function $J(\\bm{x}, \\bm{\\theta})$ is a function that returns how good the output of the network is, given an input $\\bm{x}$ and a set of network parameters $\\bm{\\theta}$ (represents all trainable parameters: weights, biases, and any others). Learning can then be described as the process of adapting the parameters $\\bm{\\theta}$ in order to minimize or maximize the objective function (usually minimize, depends on the function used). The choice of function will depend on the type of problem, but two of the most common methods are \\gls{MSE} and Categorical Cross Entropy.\n\n\\subsection{Mean Squared Error} \\label{sub:mse}\nThis function is the standard squared euclidean distance between two vectors. For a given input $\\bm{x}$, the network output $\\hat{\\bm{y}}$ for this input, and the true desired output $\\bm{y}$ (e.g. the corresponding label), the squared distance is calculated as shown in \\autoref{eq:squared_distance} \\textbf{--} note that the subscript $2$ indicates the euclidean distance (the $\\ell_2$ norm).\n\\begin{equation} \\label{eq:squared_distance}\n    \\| \\bm{y} - \\hat{\\bm{y}} \\|_{2}^{2} = \\sum_{i}{(y_j - \\hat{y_i})^2}\n\\end{equation}\n\nThis distance can also be generalize to matrices or any $n$ dimensional values of $\\bm{y}$ by just calculating the element-wise squared differences between $\\bm{y}$ and $\\hat{\\bm{y}}$.\n\nHowever, simply calculating the distance for one possible input is not good for evaluating how well the network is doing in general. To better evaluate the network's performance it is necessary to see how well it is doing in the entire dataset or some subset of it. For a set $\\bm{X}$ of $n$ inputs, the \\gls{MSE} is the mean of the squared distances as shown in \\autoref{eq:mse}.\n\\begin{equation} \\label{eq:mse}\n    J(\\bm{X}, \\bm{\\theta}) = \\frac{1}{n}\\sum^{n}||\\bm{y} - \\hat{\\bm{y}}||_{2}^{2} = \\frac{1}{n}\\sum^{n}\\sum_{i}{(y_i - \\hat{y_i})^2}\n\\end{equation}\n\nThis loss function is usually used for regression problems, where the output can have a range of values and is not simply defined as a $0$ or a $1$. It is also useful to calculate the differences between images in pixel space, like used for autoencoders \\cite{autoencoder1991}.\n\n\n\\subsection{Categorical and Binary Cross Entropy} \\label{sub:cross_entropy}\nLike \\gls{MSE} this loss function is calculated by averaging the error over many different inputs, but in this case the error calculated is the cross entropy. Given two discrete probability distributions $\\bm{y}$ and $\\hat{\\bm{y}}$, the cross entropy is calculated as shown in \\autoref{eq:cross_entropy}.\n\\begin{equation}  \\label{eq:cross_entropy}\n    H(\\bm{y}, \\hat{\\bm{y}}) = -\\sum_{i}{y_i\\log(\\hat{y}_i + \\epsilon)}\n\\end{equation}\n\nThe \\gls{epsilon} value in this equation is not a part of the cross entropy definition, but when using computers to calculate the logarithm, numbers very close or equal to zero can introduce numerical instabilities. For this reason, in almost all practical implementations it is always added a small constant $\\epsilon$ when calculating the cross entropy and other functions that can have similar issues \\textbf{--} in Tensorflow \\cite{tensorflow2015} the default value for $\\epsilon$ is equal to $10^{-7}$.\n\nThe cross entropy applied over a set of inputs gives the categorical cross entropy loss as shown in \\autoref{eq:categorical_cross_entropy}.\n\\begin{equation} \\label{eq:categorical_cross_entropy}\n    J(\\bm{X}, \\bm{\\theta}) = \\frac{1}{n}\\sum^{n}{ H(\\bm{y}, \\hat{\\bm{y}}) }\n\\end{equation}\n\nThis kind of loss function is useful when dealing with probability distributions, since the concept of entropy is deeply related with information and probability. This makes it a better alternative for classification problems when compared with \\gls{MSE}, since the desired output is the class that the input belongs to (one hot encoded) and the network output is a probability distribution over all possible classes. \n\nBut for cases where the output can only assume two values (0 or 1), the categorical cross entropy is reduced to a binary cross entropy. For \\acp{GAN}, this is the more useful loss function and it is calculated as shown in \\autoref{eq:binary_cross_entropy}.\n\\begin{equation} \\label{eq:binary_cross_entropy}\n    J(\\bm{X}, \\bm{\\theta}) = -\\frac{1}{n}\\sum^{n}\\sum_{i}{\n        \\left( y_i\\log(\\hat{y_i} + \\epsilon) + (1 - y_i) \\log(1 - \\hat{y_i} + \\epsilon) \\right)\n    }\n\\end{equation}\n\n\n\n\\subsection{Minimizing the loss} \\label{sub:minimizing_loss}\nHaving an understanding of what is the loss function, the remaining question is: how can the network use the loss in order to update its parameters? Note that since this function effectively measures how well the network is doing, it can directly be used to guide the parameter changes, the goal is to change the parameters in order to minimize the loss (for now on the goal will only be described as minimization, since it is the most common approach and any maximization problem is equivalent to minimizing the negative of what is being maximized).\n\nNote that the inputs $\\bm{x}$ are fixed, given that the dataset is also fixed, and that the goal of using neural networks is that they should learn to model the data and not just choose whatever inputs reduce their loss. So in the eyes of the network $J(\\bm{x}, \\bm{\\theta})$ becomes only $J(\\bm{\\theta})$. This may seem obvious, but this shows an important intuition that the cost function is a high dimensional surface in $N$ dimensional space, $N$ being the number of parameters of the network. And this demonstrates the importance of having both the network and loss functions be continuous and differentiable functions, since this produces a continuous and differentiable surface that allows for updating the parameters in order to reach a minimum region.\n\nTo see how the minimum is reached, it is better to start in a very simplified case where the network has only one parameter $\\theta$. Consider a case where the 1-dimensional loss surface assumes the form shown in \\autoref{fig:1d_loss}.\n\\begin{figure}\n    \\centering\n    \\caption{Example of a one dimensional loss surface}\n    \\includegraphics[width=0.5\\textwidth]{chapters/NeuralNets/figures/1D-Loss.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:1d_loss}\n\\end{figure}\n\nConsider that the network initially starts with the parameter $\\theta_0$ and loss $J_0$ at the dot shown in \\autoref{fig:1d_loss}. To reduce the loss is to update the parameter $\\theta$ in the opposite direction of the surface derivative. This can be shown by the following derivation.\n\\begin{align}\n    J_0 + \\Delta J & < J_0 \\nonumber \\\\\n    J_0 + \\Delta\\theta \\frac{dJ}{d\\theta} & < J_0 \\nonumber \\\\\n    \\Delta\\theta \\frac{dJ}{d\\theta} & < 0 \\nonumber \\\\\n    \\sign(\\Delta\\theta) & = -\\sign\\left( \\frac{dJ}{d\\theta} \\right) \\label{eq:delta_theta_sign}\n\\end{align}\n\nThis derivation above only holds true for small values of $\\Delta\\theta$, since the derivative is calculated on infinitesimal small values, bigger changes run the risk of overshooting the region where the derivative approximation is reasonable.\n\\autoref{eq:delta_theta_sign} shows that the parameter change must be in the opposite direction of the change in the loss, the parameter updates can then be written as shown in \\autoref{eq:1d_update}.\n\\begin{equation} \\label{eq:1d_update}\n    \\theta_{i+1} = \\theta_{i} + \\Delta\\theta = \\theta_{i} - \\eta \\frac{dJ}{d\\theta}\n\\end{equation}\n\n\\glsunset{learning_rate}\nThe value \\gls{learning_rate} is a positive real number that determines how big are the steps taken when updating the parameters. This value is also a hyperparameter and is called the \\textit{learning rate} of the network. A small learning rate is more precise but can make the training very slow, while bigger values are faster, but run the risk of overshooting and zigzaging around the target, or even worse, diverging and never reaching the result. \\autoref{fig:1d_weight_update} shows how an initial parameter value is updated when using different values for $\\eta$, it can be seen that there is a critical value $\\eta_{crit}$ that is able to minimize the loss in a single step, while smaller and bigger values will converge to the minimum in multiple steps, and much bigger values will diverge.\n\\begin{figure}\n    \\centering\n    \\caption{Parameter updates for 1D loss surface in function of learning rate}\n    \\includegraphics[width=0.5\\textwidth]{chapters/NeuralNets/figures/1D-Weight-Update.pdf}\n    \\fonte{From the author (2021)}\n    \\label{fig:1d_weight_update}\n\\end{figure}\n\nFor one dimension it is relatively simple to find the critical learning rate, but for very high dimensional problems this is unfeasible or even impossible since a critical value for one parameter is not necessarily the same for all other parameters.\n\nIn practice, it is usually necessary to experiment with some values in order to find what best suits the loss surface of the problem, it is also common to employ some sort of dynamic update that slowly reduces the learning rate, allowing for big steps in the beginning while being more precise towards the end.\n\n\n\\subsection{Gradient Descent} \\label{sub:gradient_descent}\nThe same derivation used to obtain \\autoref{eq:delta_theta_sign} can be applied to generalize the minimization procedure to higher dimensional parameter spaces, the only difference is to consider the partial derivatives for each parameter. Doing this would reveal that, like in the 1-dimensional case, the change in a parameter $\\theta^{(j)}$ must be in the opposite direction of the partial derivative of the loss with respect to this parameter. The parameter update would then be given by \\autoref{eq:parameter_update}.\n\\begin{equation} \\label{eq:parameter_update}\n    \\theta_{i+1}^{(j)} = \\theta_{i}^{(j)} - \\eta \\frac{\\partial J}{\\partial \\theta^{(j)}}\n\\end{equation}\n\nThere is however another way to look at these updates. Recall that the gradient of any scalar function is a vector field composed of all its partial derivatives, so the gradient of the loss function is the vector field given by \\autoref{eq:gradient}.\n\\begin{equation} \\label{eq:gradient}\n    \\renewcommand{\\arraystretch}{1.2}\n    \\nabla_{\\bm{\\theta}} J = \\begin{bmatrix}\n        \\frac{\\partial J}{\\partial\\theta^{(1)}} \\\\\n        \\frac{\\partial J}{\\partial\\theta^{(2)}} \\\\\n        \\vdots \\\\\n        \\frac{\\partial J}{\\partial\\theta^{(n)}}\n    \\end{bmatrix}\n\\end{equation}\n\nAlso recall that for any function $f$, its gradient at any given point is a vector that points towards the direction of steepest increase to the function at that point and the negative of this vector points to the steepest decrease \\cite[Chapter~4.6]{calculusIII2016}. So the negative of the gradient $\\nabla_{\\bm{\\theta}} J$ gives the direction to update all parameters in order to most reduce the loss function, this is what was being shown element-wise in \\autoref{eq:parameter_update}. By grouping the derivatives it is possible to write the parameter updates in a much cleaner way.\n\\begin{equation} \\label{eq:gradient_descent}\n    \\bm{\\theta}_{i+1} = \\bm{\\theta}_{i} - \\eta \\nabla_{\\bm{\\theta}} J(\\bm{\\theta}_i)\n\\end{equation}\n\nBy repeating the process of calculating the gradient of the loss function and then updating all the network's parameters (given a sufficiently small learning rate), then eventually all parameters will converge to values that minimize the loss function. This is what is referred to as \\textit{learning} in a neural network and this iterative process is called \\textit{Gradient Descent}, since the steps are taken using the gradient in order to decrease the loss function \\textbf{--} for maximization, the only difference is to update in the positive direction of the gradient and this is called \\textit{Gradient Ascent}.\n\nOne important thing that was left unmentioned is the fact that this algorithm will almost surely converge to a local minimum in the loss surface instead of the global minimum. In the example shown for the 1-dimensional case the surface was very simple, with a single minimum value to converge, but even in these very simple cases it is possible to find surfaces much more complex (e.g. the curve $y = x + 2\\sin x$ has infinitely many local minima but no global minimum). For the very high dimensional spaces and very complex geometries of the loss surfaces in neural networks, there will be many valleys where gradient descent will converge, but rarely those will be the optimal solution. The local minimum found will depend on the starting point in parameter space, and there is usually no better to way than just randomly selecting a point\\footnote{\n    This does not mean that the starting values are picked without any rhyme or reason, the starting point can have a huge impact on the network and it is very important to choose good values. However, initialization techniques are concerned with finding a random distribution with the right values of mean and variance to sample from. The point here is explicitly about the random nature of the starting point and not that this nature has no thought behind it.\n}.\n\nSo if gradient descent will almost never reach the optimal solution, why would anyone use it? How can someone make sure that the local minimum found is good enough for the problem? Or if someone is trying to build a neural network and the results are not being good, how can this person know if this is caused by a legitimate problem on the network or the dataset, instead of simply being the fact that the training process was unlucky and found a bad local minimum? And perhaps most important, how is it possible that neural networks are achieving so much ground-breaking results while relying on gradient descent to learn?\n\nThis is indeed a worry that many researchers in the field have, but there are many options to combat this problem, it can be cited regularization techniques (e.g. $\\ell_1$ and $\\ell_2$ norms \\textbf{--} see \\autoref{sub:regularization}) and optimizers (e.g. \\glsunset{SGD}\\gls{SGD}, momentum, RMSProp, \\glsunset{Adam}\\gls{Adam} \\textbf{--} see \\autoref{sub:optimizers}) as examples. \n\nBesides that, \\textcite{lossSurfaces2014} argue that global minimum are not necessarily the best option, since they have a high chance of overfitting to the data (see \\autoref{sub:overfitting}), they also empirically verify that for big enough neural networks most local minima are very similar to one another and have high quality. Their conclusion is that in practice it is not worth to strive for the global minimum, given that for large networks local minima have high quality and may even generalize better to unseen data.\n", "meta": {"hexsha": "f33aed2ac42ae81d1f09d74eaeeb4ebf76ab1c0e", "size": 17592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Overleaf/chapters/NeuralNets/gradDesc.tex", "max_stars_repo_name": "PatrickHoeckler/tcc_gan", "max_stars_repo_head_hexsha": "0fa63fff9c6a3bbee57af38683c492a8b120e24a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-20T22:17:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-05T06:19:44.000Z", "max_issues_repo_path": "Overleaf/chapters/NeuralNets/gradDesc.tex", "max_issues_repo_name": "PatrickHoeckler/tcc_gan", "max_issues_repo_head_hexsha": "0fa63fff9c6a3bbee57af38683c492a8b120e24a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Overleaf/chapters/NeuralNets/gradDesc.tex", "max_forks_repo_name": "PatrickHoeckler/tcc_gan", "max_forks_repo_head_hexsha": "0fa63fff9c6a3bbee57af38683c492a8b120e24a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 131.2835820896, "max_line_length": 937, "alphanum_fraction": 0.7734197362, "num_tokens": 4168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6474570144818776}}
{"text": "\\documentclass{article}\n\\author{QianLiu}\n\\title{Insert Equation}\n\\date{\\today}\n\n\\usepackage{amsmath}\n\n\n\\begin{document}\n    \\maketitle\n    \\tableofcontents\n    \n    \\section{inline Equation}\n    \\subsection{dollar character}\n    $f(x)=x^2+3x$\n\n    \\subsection{parenthesis}\n    \\(f(x)=x^2+3x\\)\n\n    \\subsection{mathematical enviroment}\n    \\begin{math}\n        f(x)=x^2+3x\n    \\end{math}\n\n    \\section{super/sub script}\n    \\subsection{superscript}\n    $f(x)=x^2+3y^{20}$\n\n    \\subsection{subscript}\n    \\(f(x)=x^2+3x_{20}\\)\n\n    \\section{greek alphabet}\n    \\subsection{lowercase}\n    \\(\\alpha\\)\n    \\(\\beta\\)\n    \\(\\omega_1\\)\n    \\(\\gamma\\)\n    \\(\\pi\\)\n\n    \\subsection{uppercase}\n    \\(\\Gamma\\)\n    \\(\\Delta\\)\n    \\(\\Pi^5\\)\n    \\(\\Omega\\)\n    \\ \\(\\alpha^2+\\beta^3=\\omega\\)\n\n    \\section{mathematical functions}\n    \\(\\log_{10}^2 x\\)\n    \\ \\(\\sin^2 x\\)\n    \\ \\(\\cos^3 y\\)\n    \\ \\(\\arcsin x\\)\n    \\ \\(\\arccos z\\)\n    \\ \\(\\ln x\\)\n    \\ \\(\\sqrt{3x^2+2y^4_2}\\)\n    \\ \\(\\sqrt[5]{3x}\\)\n\n    \\section{algebraic fraction}\n    \\(3/4\\)\n    \\ \\(\\frac{x}{y}\\)\n    \\ \\(\\frac{\\sqrt{2y_2^5}}{\\sqrt[6]{\\sin^2 x+\\arcsin z_4^2}}\\)\n\n    \\section{equation between lines}\n\n    use \\$\\$...\\$\\$ insert equation\n    $$f(x)=3x+y^3$$    \n    \n    \\subsection{square brackets}\n    use \\textbackslash [equation...\\textbackslash ] insert equation\n    \\[f(x)=3x+y^3\\] % used commonly to insert equation between lines\n    \n    \\subsection{environment of displaymath}\n    \\begin{displaymath}\n        f(x)=3x+y^3\n    \\end{displaymath}\n    \n    \\subsection{environment where equation enumerated automatically}\n    Refer the equation \\ref{equation_1}\n    \\begin{equation}\n        f(x)=3x+z^3 \n        \\label{equation_1}\n    \\end{equation}\n    \n    \\subsection{environment where equation* are not enumerated }\n    Refer the equation \\ref{equation_2}\n    \\begin{equation*} %equation without numbers\n        f(x)=3x+z^6\n        \\label{equation_2}\n    \\end{equation*}\n\n    \\subsection{Equation in Multiple lines}\n    \\begin{gather} % Need to use package <amsmath>\n        f(x)=3x+z^3  \\\\ \n        \\notag \\\\ \n        \\frac{\\sqrt{2y_2^5}}{\\sqrt[6]{\\sin^2 x+\\arcsin z_4^2}} \\notag \\\\\n        f(z)=\\frac{x_2^5}{y_3^7}\n    \\end{gather}\n\n    \\subsection{Split Equation}\n    \\begin{equation} % Single Equation but can split in multiple lines\n        \\begin{split} % Use \\begin{split}...\\end{split} to realize it  \n            f(x)=3x+4x^2 \\\\\n            f(x)=\\sin^2 x \\\\\n            f(x)=\\cos x^3 \n        \\end{split}\n    \\end{equation}\n\n    \\subsection{Piecewise funtion}\n    \\begin{equation}\n        D(x)=\\begin{cases}\n            3x & \\text{if }  x \\in R \\\\\n            x^2 & \\text{if } x \\in Z \\setminus Q\n        \\end{cases}\n    \\end{equation}\n    \n\\end{document}", "meta": {"hexsha": "775156ea091e72cdc08aad0365606e23e799bc7d", "size": 2723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bilibili_self_learning/equation.tex", "max_stars_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_stars_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bilibili_self_learning/equation.tex", "max_issues_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_issues_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bilibili_self_learning/equation.tex", "max_forks_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_forks_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_forks_repo_licenses": ["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.6782608696, "max_line_length": 72, "alphanum_fraction": 0.5571061329, "num_tokens": 948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.6474314637825034}}
{"text": "\\section{PAC Learning}\n\n% ===\n\\begin{highlightbox}\n    \\textbf{Want:} Distribution indep. error guarantees!\n    % What we want: Distribution independent error guarantees!\n    % However, without prior knowledge, those bounds are quite loose.\n\\end{highlightbox}\n\nExpec./\\textbf{Gener. error:}\\enskip\n$\\mathcal R(\\hat c_n) = \\bm P_{X,Y}(\\hat c_n(x) \\neq c(x))$\n\n\\textbf{Empirical error:}\\enskip\n$\\hat{\\mathcal R}_n(\\hat c_n) = \\frac1n \\sum_{i=1}^n \\bm 1_{\\brace{\\hat c_n(x_i) \\;\\neq\\; y_i}}$\n\n\n\\emph{PAC learnable:} $\\mathcal A$ can learn a concept class $\\mathcal C$ from $\\mathcal H$ if, given a \\textcolor{Green}{suff. large sample}, it outputs a hypothesis that \\textcolor{VioletRed}{generalizes well} \\textcolor{OrangeRed}{w/ high prob}.\n\n\\begin{highlightbox}\n\\vspace{-\\fboxrule}\\vspace{-\\fboxsep}\n    \\begin{highlightbox}[white]\n        (1) $\\color{VioletRed} 0 < \\epsilon < \\sfrac12$, $\\color{OrangeRed} 0 < \\delta < \\sfrac12$,\n        (2) $\\bm P_{X,Y}$ on $\\mathcal X \\times \\brace{0,1}$:\n        \n        If\\enskip $\\color{Green} n \\geq \\mathit{poly} (\\textcolor{VioletRed}{\\sfrac1\\epsilon},\\; \\textcolor{OrangeRed}{\\sfrac1\\delta},\\; \\mathit{dim}(\\mathcal X))$,\n        \n        Then\\enskip $\\color{OrangeRed} \\bm P_{X,Y}\n        \\paren*{ \\color{VioletRed}\n            \\mathcal R(\\hat c_n) - \\inf\\limits_{c\\in\\mathcal C} \\mathcal R(c) \\leq \\epsilon\n        } \\geq 1 - \\delta$.\n    \\end{highlightbox}%\n\\vspace{-\\fboxrule}\\vspace{-\\fboxsep}\n\\end{highlightbox}\n\n% A concept class $\\mathcal C$ is \\emph{PAC learnable} from a hypothesis class $\\mathcal H$ if \\ldots\\ldots\\ldots\nIf $\\mathcal A$ runs in time polynomial in $\\color{VioletRed} \\sfrac1\\epsilon$ and $\\color{OrangeRed} \\sfrac1\\delta$, we say that $\\mathcal C$ is \\emph{efficiently PAC learnable}.\n\n% ===\n\\subsection{VC Inequality\n\\hfill $\\bm P(\\cdots \\geq \\begingroup\\color{VioletRed}\\epsilon\\endgroup) \\leq \\ldots \\leq \\color{OrangeRed}\\delta$}\n\nSelect ERM:\\enskip\n$\\hat c_n^\\ast = \\arg\\min_{c\\in\\mathcal C} \\hat{\\mathcal R}_n (c)$\n\nUnder uniform convergence: %, the suboptimality of $\\hat c_n^\\ast$ can be bounded:\n\\scalebox{.9}{${\n    \\bm P \\paren*{\n        \\mathcal R(\\hat c_n^\\ast) - \\inf\\limits_{c\\in\\mathcal C} \\mathcal R(c) > \\epsilon\n    } \\leq \\bm P \\paren*{\n        \\sup\\limits_{c\\in\\mathcal C} \\abs*{\\hat{\\mathcal R}_n(c) - \\mathcal R(c)} > \\dfrac\\epsilon2\n    }\n}$}\n\n\\begin{tabular}{@{\\textbullet\\:} r @{$\\:\\leq\\:$} l @{}}\n    \\emph{$\\abs{\\mathcal C}$ Finite:}\\enskip\n    $\\bm P \\paren*{ \\sup \\abs*{\\cdots} > \\epsilon }$\n    & $2 \\abs{\\mathcal C} \\exp(-2n\\epsilon^2)$\n    \\\\\n    \\emph{$\\abs{\\mathcal C}$ Unbounded:}\\hfill\n    $\\bm P \\paren*{ \\cdots }$\n    & $9 n^{\\mathrm{VC}_{\\mathcal C}} \\exp(-\\frac{n \\epsilon^2}{32})$\n\\end{tabular}\n\n% ===\n\\subsection{Rectangle Learning}\n\n$\\bm P(\\mathcal(\\hat c_n^\\ast > \\epsilon)\n\\leq \\abs{\\mathcal C} \\cdot (1-\\epsilon)^n\n\\leq \\abs{\\mathcal C} \\cdot \\exp(-n\\epsilon)\n\\color{gray} < \\delta$\n\n\\textbf{Union bound:}\\enskip\n$\\bm P(\\bigcup_i T_i) \\leq \\sum_i \\bm P(T_i)$\n\n% ===\n", "meta": {"hexsha": "d60596ab2b8edd4d6340ab1e69fc96445d43563c", "size": 2987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/11_pac_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/11_pac_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/11_pac_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": 39.3026315789, "max_line_length": 248, "alphanum_fraction": 0.6360897221, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.647431459204551}}
{"text": "\\section{Algebraic Moment Closures}\n\\label{sec:algebraicClosure}\n\nThe two-moment model given by Eq.~\\eqref{eq:angularMoments} is not closed because of the appearance of the second moments $\\vect{\\cK}$ (the normalized pressure tensor).  \nAlgebraic moment closures for the two-moment model are computationally efficient as they provide the Eddington factor in Eq.~\\eqref{eq:eddingtonTensor} in closed form as a function of the density $\\cJ$ and the flux factor $h=|\\vect{\\cH}|/\\cJ$.  \nFor this reason they are used in applications where transport plays an important role, but where limited computational resources preclude the use of higher fidelity models.  \nExamples include simulation of neutrino transport in core-collapse supernovae \\cite{roberts_etal_2016} and compact binary mergers \\cite{foucart_etal_2015}.  \nAlgebraic moment closures in the context of these aforementioned applications have also been discussed elsewhere (e.g., \\cite{janka_etal_1992,pons_etal_2000,smit_etal_2000,just_etal_2015,murchikova_etal_2017}).  \nHere we focus on properties of the algebraic closures that are critical to the development of numerical methods for the two-moment model of fermion transport.  \nFor the algebraic closures we consider, the Eddington factor in Eq.~\\eqref{eq:eddingtonTensor} can be written in the following form \\cite{cernohorskyBludman_1994}\n\\begin{equation}\n  \\chi(\\cJ,h)=\\f{1}{3}+\\f{2\\,(1-\\cJ)\\,(1-2\\cJ)}{3}\\,\\Theta\\Big(\\f{h}{1-\\cJ}\\Big),\n  \\label{eq:eddingtonFactor}\n\\end{equation}\nwhere the \\emph{closure function} $\\Theta(x)$ depends on the specifics of the closure procedure.  \nWe will consider two basic closure procedures in more detail below: the maximum entropy (ME) closure and the Kershaw (K) closure.  \n\nIn the low occupancy limit ($\\cJ\\ll1$), the Eddington factor in Eq.~\\eqref{eq:eddingtonFactor} depends solely on $h$; i.e.,\n\\begin{equation}\n  \\chi(\\cJ,h)\\to\\chi_{0}(h)=\\f{1}{3}+\\f{2}{3}\\,\\Theta\\big(h\\big).  \n  \\label{eq:eddingtonFactorLow}\n\\end{equation}\nThis for of $\\chi$ yields a moment closure that is suitable for particle systems obeying Maxwell-Boltzmann statistics.  \n\n\\subsection{Maximum Entropy (ME) Closure}\n\nThe ME closure constructs an approximation of the angular distribution as a function of $\\cJ$ and $\\vect{\\cH}$ \\cite{cernohorskyBludman_1994,lareckiBanach_2011}.  \nThe ME distribution $f_{\\mbox{\\tiny ME}}$ is found by maximizing the entropy functional, which for particles obeying Fermi-Dirac statistics is given by\n\\begin{equation}\n  S[f_{\\mbox{\\tiny ME}}] \n  = \\int_{\\bbS^{2}}\\big[\\,(1-f_{\\mbox{\\tiny ME}})\\log(1-f_{\\mbox{\\tiny ME}}) + f_{\\mbox{\\tiny ME}}\\log f_{\\mbox{\\tiny ME}}\\,]\\,d\\omega,\n  \\label{eq:entropyFunctional}\n\\end{equation} \nsubject to the constraints\n\\begin{equation}\n  \\f{1}{4\\pi}\\int_{\\bbS^{2}}f_{\\mbox{\\tiny ME}}(\\omega)\\,d\\omega=\\cJ\n  \\quad\\text{and}\\quad\n  \\f{1}{4\\pi}\\int_{\\bbS^{2}}f_{\\mbox{\\tiny ME}}(\\omega)\\,\\vect{\\ell}(\\omega)\\,d\\omega=\\vect{\\cH}.  \n  \\label{eq:closureConstraints}\n\\end{equation}\nThe solution that maximizes Eq.~\\eqref{eq:entropyFunctional} takes the general form \\cite{cernohorskyBludman_1994}\n\\begin{equation}\n  f_{\\mbox{\\tiny ME}}(\\omega;a,\\vect{b})=\\f{1}{e^{a + \\vect{b}\\cdot\\vect{\\ell}(\\omega)}+1}, \n  \\label{eq:fME}\n\\end{equation}\nwhere the Lagrange multipliers $a$ and $\\vect{b}$ are implicit functions of $\\cJ$ and $\\vect{\\cH}$.  \nThe ME distribution function satisfies $0 < f_{\\mbox{\\tiny ME}} < 1$, but $a$ and $\\vect{b}$ are unconstrained.  \nSpecification of $a$ and $\\vect{b}$ from $\\vect{\\cM}=(\\cJ,\\vect{\\cH})^{T}$ gives $f_{\\mbox{\\tiny ME}}$, and any number of moments can in principle be computed.  \nImportantly, for the maximum entropy problem to be solvable, we must have $\\vect{\\cM}\\in\\cR$ \\cite{lareckiBanach_2011}.  \n\nTo arrive at an algebraic form of the ME closure, Cernohorsky \\& Bludman \\cite{cernohorskyBludman_1994} postulate (but see \\cite{lareckiBanach_2011}) that, as a function of the flux saturation\n\\begin{equation}\n  x := h/(1-\\cJ),\n  \\label{eq:fluxSaturation}\n\\end{equation} \nthe closure function $\\Theta$ is independent of $\\cJ$ and can be written explicitly in terms of the inverse Langevin function.  \nTo avoid inverting the Langevin function for $\\Theta$, they provide a polynomial fit (accurate to $2\\%$) given by\n\\begin{equation}\n  \\Theta_{\\mbox{\\tiny ME}}^{\\mbox{\\tiny CB}}(x)\n  =\\f{1}{5}\\,\\big(\\,3-x+3\\,x^{2}\\,\\big)\\,x^{2}.\n  \\label{eq:closureMECB}\n\\end{equation}\nMore recently, Larecki \\& Banach \\cite{lareckiBanach_2011} have shown that the explicit expression given in \\cite{cernohorskyBludman_1994} is not exact and provide another approximate expression\n\\begin{equation}\n  \\Theta_{\\mbox{\\tiny ME}}^{\\mbox{\\tiny BL}}(x)\n  =\\f{1}{8}\\,\\big(\\,9\\,x^{2}-5+\\sqrt{33\\,x^{4}-42\\,x^{2}+25}\\,\\big),\n  \\label{eq:closureMEBL}\n\\end{equation}\nwhich is accurate to within $0.35\\%$.  \nOn the interval $x\\in[0,1]$, the curves given by Eqs.~\\eqref{eq:closureMECB} and \\eqref{eq:closureMEBL} lie practically on top of each other.  \nThe closure functions given by Eqs.~\\eqref{eq:closureMECB} and \\eqref{eq:closureMEBL}, together with the Eddington factor in Eq.~\\eqref{eq:eddingtonFactor} and the pressure tensor in Eq~\\eqref{eq:eddingtonTensor}, constitute the algebraic maximum entropy closures for fermionic particle systems considered in this paper.  \nWe will refer to the ME closures with $\\Theta_{\\mbox{\\tiny ME}}^{\\mbox{\\tiny CB}}$ and $\\Theta_{\\mbox{\\tiny ME}}^{\\mbox{\\tiny BL}}$ as the CB (Cernohorsky \\& Bludman) and BL (Banach \\& Larecki) closures, respectively.  \n\nWe also note that using the closure function given by Eq.~\\eqref{eq:closureMECB} with the low occupancy Eddington factor in Eq~\\eqref{eq:eddingtonFactorLow} results in the algebraic maximum entropy closure attributed to Minerbo \\cite{minerbo_1978}, which is currently in use in simulation of neutrino (fermion) transport in the aforementioned nuclear astrophysics applications.  \nIn a recent comparison of algebraic (or analytic) closures for the two-moment model applied to neutrino transport around proto-neutron stars, Murchikova et al. \\cite{murchikova_etal_2017} obtained nearly identical results when using the closures of CB and Minerbo.  \nFor these reasons, we include the Minerbo closure in the subsequent discussion and in the numerical tests in Section~\\ref{sec:numerical}.  \n\n\\subsection{Kershaw (K) Closure}\n\nAnother algebraic closure we consider is a Kershaw-type closure \\cite{kershaw_1976}, developed for fermion particle systems in \\cite{banachLarecki_2017a}.  \nThe basic principle of the Kershaw closure for the two-moment model is derived from the fact that the realizable set generated by the triplet of scalar moments\n\\begin{equation}\n  \\{\\cJ,\\cH,\\cK\\}=\\f{1}{2}\\int_{-1}^{1}f(\\mu)\\,\\mu^{\\{0,1,2\\}}\\,d\\mu,\n  \\label{eq:scalarMoments}\n\\end{equation} \nis convex.  \nFor the moments in Eq.~\\eqref{eq:scalarMoments}, the realizable set is the set of moments obtained from distribution functions satisfying $0<f(\\mu)<1,\\,\\forall\\mu\\in[-1,1]$.  \n(The moments in Eq.~\\eqref{eq:scalarMoments} are the unique moments obtained from the moments in Eq.~\\eqref{eq:angularMoments} under the assumption that the distribution function is isotropic about a preferred direction, and $\\mu$ is the cosine of the angle between this preferred direction and the particle propagation direction given by $\\vect{\\ell}$.)  \n\nFor a bounded distribution $0<f<1$, it is possible to show (e.g., \\cite{banachLarecki_2013}) that the second moment satisfies\n\\begin{equation}\n  \\cK_{\\mbox{\\tiny L}}(\\cJ,h) < \\cK < \\cK_{\\mbox{\\tiny U}}(\\cJ,h),\n\\end{equation}\nwhere $\\cK_{\\mbox{\\tiny L}}=\\cJ\\,\\big(\\,\\f{1}{3}\\,\\cJ^{2}+h^{2}\\,\\big)$, $\\cK_{\\mbox{\\tiny U}}=\\cK_{\\mbox{\\tiny L}} + \\cJ\\,(1-\\cJ)\\,(1-x^{2})$, and $x$ is the flux saturation defined in Eq.~\\eqref{eq:fluxSaturation}.  \nBy convexity of the realizable set generated by the moments in Eq.~\\eqref{eq:scalarMoments}, the convex combination\n\\begin{equation}\n  \\cK(\\beta,\\cJ,h)=\\beta\\,\\cK_{\\mbox{\\tiny L}}(\\cJ,h)+(1-\\beta)\\,\\cK_{\\mbox{\\tiny U}}(\\cJ,h),\n  \\label{eq:kershawAnsatz}\n\\end{equation}\nwith $\\beta\\in[0,1]$, is realizable whenever $(\\cJ,\\cH)^{T}\\in\\cR$.  \nThe Kershaw closure for the two-moment model is then obtained from Eq.~\\eqref{eq:kershawAnsatz} with the additional requirement that it be correct in the limit of isotropic distribution functions; i.e., $\\cK(\\beta,\\cJ,0)=\\cJ/3$.  \nOne choice for $\\beta$, which leads to a strictly hyperbolic and causal two-moment model (and a particularly simple closure function) \\cite{banachLarecki_2017a}, is $\\beta=(2-\\cJ)/3$, so that $\\cK_{\\mbox{\\tiny K}}(\\cJ,h)=\\chi_{\\mbox{\\tiny K}}(\\cJ,h)\\,\\cJ$, where\n\\begin{equation}\n  \\chi_{\\mbox{\\tiny K}}(\\cJ,h)=\\f{1}{3}+\\f{2\\,(1-\\cJ)\\,(1-2\\cJ)}{3}\\,\\Theta_{\\mbox{\\tiny K}}\\Big(\\f{h}{1-\\cJ}\\Big),\n  \\label{eq:eddingtonFactorKershaw}\n\\end{equation}\nand the Kershaw closure function is given by\n\\begin{equation}\n  \\Theta_{\\mbox{\\tiny K}}(x)=x^{2}.  \n\\end{equation}\n\\modified{For multidimensional problems, the Kershaw closure is obtained by inserting the Eddington factor $\\chi_{\\mbox{\\tiny K}}$ in Eq.~\\eqref{eq:eddingtonFactorKershaw} into the Eddington tensor in Eq.~\\eqref{eq:eddingtonTensor}.}  \nFinally, we point out that for the two-moment Kershaw closure (see \\cite{banachLarecki_2017a} for details), a distribution function $f_{\\mbox{\\tiny K}}(\\omega,\\cJ,\\vect{\\cH})$, satisfying $0 < f_{\\mbox{\\tiny K}} < 1$, and reproducing the moments $\\cJ$, $\\vect{\\cH}$, and $\\vect{\\cK}$, can be written explicitly in terms of Heaviside functions.  \n\n\\subsection{Realizability of Algebraic Moment Closures}\n\nIt is not immediately obvious that all the algebraic moment closures discussed above are suitable for designing realizability-preserving methods for the two-moment model of fermion transport.  \nIn particular, the realizability-preserving scheme developed in this paper is based on the result in Lemma~\\ref{lem:explicitStep}, which must hold for the adapted closure.  \nThe Kershaw closure is consistent with a bounded distribution, $f_{_{\\mbox{\\tiny K}}}\\in(0,1)$, and should be well suited, but the algebraic ME closures are based on approximations to the closure function, and we need to consider if these approximate closures remain consistent with the assumed bounds on the underlying distribution function.  \nTo this end, we rely on results in \\cite{levermore_1984,lareckiBanach_2011} (see also \\cite{kershaw_1976,shohatTamarkin_1943}), which state that realizability of the moment triplet $\\{\\cJ,\\vect{\\cH},\\vect{\\cK}\\}$ (with $\\vect{\\cK}$ given by Eq.~\\eqref{eq:eddingtonTensor}), is equivalent to the following requirement for the Eddington factor\n\\begin{equation}\n  \\chi_{\\mbox{\\tiny min}}\n  =\\max\\big(1-\\f{2}{3\\cJ},h^{2}\\big)\n  <\\chi<\\min\\big(1,\\f{1}{3\\cJ}-\\f{\\cJ}{1-\\cJ}h^{2}\\big)=\\chi_{\\mbox{\\tiny max}}.  \n  \\label{eq:eddingtonFactorBounds}\n\\end{equation}\nFortunately, these bounds are satisfied by the algebraic closures based on Fermi-Dirac statistics.  \n(Note that for $\\cJ\\ll1$ the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds} limit to the bounds for positive distributions given by Levermore \\cite{levermore_1984}; i.e., $h^{2}<\\chi<1$.)\n\nIn Figure~\\ref{fig:EddingtonFactorsWithDifferentClosure}, we plot the Eddington factor $\\chi$ versus the flux factor $h$ for the various algebraic closures discussed above and for different values of $\\cJ\\in(0,1)$: $0.01$ (upper left panel), $0.4$ (upper right panel), $0.6$ (lower left panel), and $0.99$ (lower right panel).  \nThe lower and upper bounds on the Eddington factor for realizable closures ($\\chi_{\\mbox{\\tiny min}}$ and $\\chi_{\\mbox{\\tiny max}}$, respectively) are also plotted.  \nWe note that for all the closures, the Eddington factor $\\chi\\to1/3$ as $h\\to0^{+}$.  \n\nWhen $\\cJ=0.01$, the maximum entropy closures (CB, BL, and Minerbo) are practically indistinguishable, while the Eddington factor of the Kershaw closure is larger than that of the other closures over most of the domain.  \nWhen $\\cJ=0.4$, the Eddington factor for the closures based on Fermi-Dirac statistics (CB, BL, and Kershaw) remain close together, while the Eddington factor for the Minerbo closure is larger than the other closures for $h\\gtrsim0.2$.  \nThe Eddington factor for all closures remain between $\\chi_{\\mbox{\\tiny min}}$ and $\\chi_{\\mbox{\\tiny max}}$ when $\\cJ=0.01$ and $\\cJ=0.4$.  \n\nWhen $\\cJ=0.6$, the Eddington factor for the closures based on Fermi-Dirac statistics remain close together and within the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds}.  \nThe dependence of the Eddington factor on $h$ for the Minerbo closure differs from the other closures (i.e., increases vs decreases with increasing $h$), and exceeds $\\chi_{\\mbox{\\tiny max}}$ for $h\\gtrsim0.34$.  \nWhen $\\cJ=0.99$, the Eddington factor of the CB and BL closures (indistinguishable) and the Kershaw closure remain within the bounds given in Eq.~\\eqref{eq:eddingtonFactorBounds}.  \nThe Eddington factor of the Minerbo closure is nearly flat, and exceeds $\\chi_{\\mbox{\\tiny max}}$ for $h\\gtrsim0.006$.  \n\n\\begin{figure}[H]\n  \\centering\n  \\begin{tabular}{cc}\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_01}\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_40} \\\\\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_60}\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_99}\n  \\end{tabular}\n   \\caption{Plot of Eddington factors $\\chi$ versus flux factor $h$ for different values of $\\cJ$ for various algebraic closures: $\\cJ=0.01$ (upper left panel), $\\cJ=0.4$ (upper right panel), $\\cJ=0.6$ (lower left panel), and $\\cJ=0.99$ (lower right panel).  In each panel we plot the Eddington factors of Kershaw (solid blue lines), Cernohorsky \\& Bludman (CB, solid red lines), Banach \\& Larecki (BL, dashed orange lines), and Minerbo (dash-dot purple lines).  We also plot $\\chi_{\\mbox{\\tiny min}}$ and $\\chi_{\\mbox{\\tiny max}}$ defined in Eq.~\\eqref{eq:eddingtonFactorBounds} (lower and upper solid black lines, respectively).}\n  \\label{fig:EddingtonFactorsWithDifferentClosure}\n\\end{figure}\nWe have also checked numerically that for all the algebraic closures based on Fermi-Dirac statistics (CB, BL, and Kershaw), the bounds on the Eddington factor in Eq.~\\eqref{eq:eddingtonFactorBounds} holds for all $\\vect{\\cM}\\in\\cR$.  \nThus, we conclude that these closures are suited for development of realizability-preserving numerical methods for the two-moment model of fermion transport.  \n\nIn Figure~\\ref{fig:MabWithDifferentClosure}, we further illustrate properties of the algebraic closures by plotting $\\vect{\\cM}_{ab}$ as defined in Lemma~\\ref{lem:explicitStep} for the maximum entropy closures of CB and Minerbo.  \nIn both panels, we plot $\\vect{\\cM}_{ab}$ constructed from randomly selected pairs $\\vect{\\cM}_{a},\\vect{\\cM}_{b}\\in\\cR$ (each blue dot represents one realization of $\\vect{\\cM}_{ab}$).  \nResults for the maximum entropy closure of CB are plotted in the left panel, while results for the Minerbo closure are plotted in the right panel.  \nAs expected for the closure consistent with moments of Fermi-Dirac distributions (CB), we find $\\vect{\\cM}_{ab}\\in\\cR$.  \nFor the Minerbo closure, which is consistent with positive distributions, $\\vect{\\cM}_{ab}$ is not confined to $\\cR$.  \n\\begin{figure}[H]\n  \\centering\n  \\begin{tabular}{cc}\n%    \\includegraphics[width=0.5\\textwidth]{figures/MabWithBLME}\n    \\includegraphics[width=0.5\\textwidth]{figures/MabWithCBME}\n%    \\includegraphics[width=0.5\\textwidth]{figures/MabWithBLKS}\n    \\includegraphics[width=0.5\\textwidth]{figures/MabWithMI}\n  \\end{tabular}\n   \\caption{Illustration of $\\vect{\\cM}_{ab}$, as defined in Lemma~\\ref{lem:explicitStep}, computed with algebraic maximum entropy closures of Cernohorsky \\& Bludman (left) and Minerbo (right).  In each panel, $\\vect{\\cM}_{ab}$ was computed using the respective closure, using $10^{6}$ random pairs ($\\vect{\\cM}_{a},\\vect{\\cM}_{b}\\in\\cR$), and plotted as a light-blue point.  The solid black lines mark the boundary of $\\cR$: $\\gamma(\\vect{\\cM}) = 0$.}\n  \\label{fig:MabWithDifferentClosure}\n\\end{figure}", "meta": {"hexsha": "a2309c3a849f7db5818d5770d68b859724c6ec34", "size": 16018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/realizableFermionicM1/sections/algebraicClosures.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/algebraicClosures.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/algebraicClosures.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": 93.6725146199, "max_line_length": 631, "alphanum_fraction": 0.7376076913, "num_tokens": 4997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6474096139089389}}
{"text": "\\section{The MST Problem}\t\\label{section:mst-problem}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Minimum Spanning Tree}\n  $G = (V, E)$: connected, undirected, weighted graph ($w(e)$)\n\n  \\importikznocaption{0.40\\textwidth}{0.80\\textwidth}{tikz-in-beamer/spanning-tree-example-overlay.tex}\n  \n  \\pause\n  \\vspace{0.30cm}\n\n  Spanning tree $T = (V, E' \\subseteq E)$: connected, acyclic \\pause ($\\Rightarrow n-1$ edges)\n\n  \\vspace{0.20cm}\n  \\uncover<6->{\n\t\\[\n\t  w(T) = \\sum\\limits_{e \\in E'} w(e)\n\t\\]\n  }\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Minimum Spanning Tree}\n  % \\begin{center}\n  %   MST: Mimimize $w(T)$ over all possible STs\n  % \\end{center}\n\n  \\[\n\t\\text{MST:} \\quad \\mathop{\\mathrm{arg\\,min}}_{T} \\; w(T)\n  \\]\n\n  \\importikznocaption{0.60\\textwidth}{0.80\\textwidth}{tikz-in-beamer/mst-example-overlay.tex}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A Simple Property}\n  \\fignocaption{width = 0.45\\textwidth}{figs/mst-simple-property.pdf}\n\n  \\begin{center}\n\t\\textcolor{red}{\\bf Cut:} $V = (S, V \\setminus S)$\n  \\end{center}\n\n  \\pause\n\n  \\begin{enumerate}\n\t\\item MST in each connected component\n\t\\item $ce$: \\textcolor{brown}{a} \\textcolor{red}{\\bf lightest} edge across cut\n  \\end{enumerate}\n\n  \\pause\n\n  \\begin{center}\n\t\\textcolor{brown}{\\bf Copy\\&Paste Argument; Exchange Argument}\n  \\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A Wrong Divide \\& Conquer Algorithm}\n  \\begin{description}\n    \\item[Input:] $G = (V, E, w)$\n    \\item[Divide:] $V = (S, V \\setminus S)$; $\\large| |S| - |V \\setminus S| \\large| \\le 1$\n    \\item<2->[Conquer:] $T_1$: an MST of $S$; $T_2$: an MST of $V \\setminus S$\n    \\item<3->[Combine:] $T_{1} + T_{2} + \\set{e}$: $e$ is a lightest edge across $(S, V \\setminus S)$\n  \\end{description}\n\n  \\pause\n  \\vspace{0.50cm}\n\n  \\fignocaption{width = 0.30\\textwidth}{figs/divide-conquer-mst-counterexample.pdf}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{A Wrong Algorithm}\n  \\begin{alertblock}{What is wrong?}\n\t\\fignocaption{width = 0.30\\textwidth}{figs/divide-conquer-mst-counterexample.pdf}\n\n\t\\centerline{\\textcolor{brown}{The edges \\textcolor{blue}{$bc$ and $ad$} do \\textcolor{red}{\\bf not} belong to any MST.}}\n  \\end{alertblock}\n\n  \\pause\n  \\vspace{0.50cm}\n\n  \\begin{alertblock}{What if:}\n\t\\centerline{\\textcolor{red}{Invariant:} Manages a set of edges $X$ which is a subset of \\textcolor{red}{\\bf some} MST.}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "9c989316595f672fb109085f6f32cdd5f1ded5eb", "size": 2413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm-lecture-mst/sections/mst-problem.tex", "max_stars_repo_name": "hengxin/algorithm-lectures", "max_stars_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-20T06:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-12T19:07:16.000Z", "max_issues_repo_path": "algorithm-lecture-mst/sections/mst-problem.tex", "max_issues_repo_name": "hengxin/algorithm-lectures", "max_issues_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_issues_repo_licenses": ["MIT"], "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-lecture-mst/sections/mst-problem.tex", "max_forks_repo_name": "hengxin/algorithm-lectures", "max_forks_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-12T10:36:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-12T10:36:11.000Z", "avg_line_length": 28.7261904762, "max_line_length": 121, "alphanum_fraction": 0.6261914629, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833893685269, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6471516746906358}}
{"text": "\\chapter{The algorithm}\n\\label{chap:algorithm}\n\n\\textbf{by Bastian Boll} \\\\\n\nThe training dataset consists of approximately 560h of subtitled audio. From this, we extract MFCC features and approximate timestamps for each single word. For each word $w$ we aim to define a $\\mathcal{C}^1$ function \\(D_w\\colon \\R \\to \\lbrack 0, \\infty)\\) such that $D_w(t)$ is large iff the audio around time $t$ sounds like the word $w$. For a given transcript $\\mathcal{T}$ and audio $A$, we can find the function $f$ introduced in chapter \\ref{chap:intro} as the solution to the minimization problem\n\\begin{align*}\n\t&\\min_x -\\sum_{j=1}^l D_{w_j}(x_j)\\\\\n\t&\\hspace{0.5em}\\text{s.t. }x_1\\leq x_2\\leq \\dotsc\\leq x_l\n\\end{align*}\n\n\\section{Defining the distance metric}\n\n\\textbf{by Bastian Boll} \\\\\n\nThe functions \\(D_w\\colon \\R \\to \\lbrack 0, \\infty)\\) can be seen as equivalent to a metric for the distance between the sound of the word $w$ and the audio $A$ at $t$. They need to be constructed in a way such that\n\\begin{enumerate}\n\t\\item $D_w$ is guaranteed to be continuously differentiable w.r.t. $t$ for every word $w$.\n\t\\item $D_w$ corresponds to the probability, that the word $w$ is said as time $t$ in $A$. More specifically, the function mapping said probability $p$ to $D_w(t)$ should be monotonically increasing.\n\\end{enumerate}\n\nOne important motivating factor behind the construction of this optimization objective is, that the dataset does not contain exact time points for each word. Instead, for any given word $w$, we assume that the difference between the time point in the dataset $t_\\text{data}$ and the actual time point in the audio at which $w$ is being said $t_\\text{true}$ follows a normal distribution with mean $0$ and constant standard deviation $\\sigma$.\n\nDivide the audio into intervals of equal size. Label each interval $I_i$ with the probability of it containing $w$. This can be done by a variety of possible machine learning methods, our specific approach is discussed in section \\ref{interval_word_prob}. These probabilities $p_i$ can be used to infer an observed probability distribution of where in the audio the machine learning model expects $w$ to be located. More precisely, because the same word might appear multiple times, we assume the $p_i$ to be generated by the sum of multiple normal distributions with different means (time points) and constant standard deviation $\\sigma$. We also assume, that the specific instance $w$ of the word in question can be attributed to exactly one of these distributions with mean $t$.\\\\\nIn order to find the optimal time point $t_\\text{true}$ we can use the observation, that two normal distributions with the same standard deviation have the same mean $t=t_\\text{true}$ exactly if it holds for the probability density functions $\\rho_{t,\\sigma}$ and $\\rho_{t_\\text{true},\\sigma}$ that\n\\[t = \\arg\\max \\int_\\R \\rho_{t_\\text{true},\\sigma}(x)\\rho_{t,\\sigma}(x)\\text{d}x\\]\nHence, we can use the maximum value on the right hand side as a score for how similar the audio around time $t$ the model considers the word $w$ to be. This can be transformed into an objective in terms of the probabilities $p_i$ computed by the machine learning model\n\\begin{align*}\n\t\\int_\\R \\rho_{t_\\text{true},\\sigma}(x)\\rho_{t,\\sigma}(x)\\text{d}x &= \\sum_{i} \\int_{I_i} \\rho_{t_\\text{true},\\sigma}(x)\\rho_{t,\\sigma}(x)\\text{d}x\\\\\n\t\t\t&= \\sum_i \\rho_{t,\\sigma}(\\xi_i) \\underbrace{\\int_{I_i} \\rho_{t_\\text{true},\\sigma}(x)\\text{d}x}_{\\approx p_i}\n\\end{align*}\nby the mean value theorem for a sufficient $\\xi_i\\in I_i$ (because $\\rho_{t_\\text{true},\\sigma}(x) > 0$ for all $x$). Equality still approximately holds if we set $\\xi_i$ to be the center point of $I_i$ for sufficiently small intervals.\nHence, we can define $D_w$ through\n\\[\n\tD_w(t) = \\sum_i p_i \\rho_{t,\\sigma}(t_i)\n\\]\nfor each center point $t_i$ of $I_i$. This construction satisfies the smoothness required for optimization. It also considers the inherent imprecision of word time points in the dataset and provides a means of leveraging information computed by the machine learning model without requiring perfect prediction accuracy.\\\\\nAdditionally, by interpreting the time alignment as a global optimization problem under word order constraints, we can make effective use of the known word order and reduce the impact of single (local) bad predictions by the model.\n\n\\section{Computing probabilities for each interval}\n\\label{interval_word_prob}\n\n\\textbf{by Paul Warkentin} \\\\\n\nGiven an audio file, we divide its MFCC features into $n$ intervals $I_i$ of equal lengths $l$. If the rest part of the data $I_{n+1}$ is shorter than the length $l$, it is discarded. The result of this section will be a matrix $p$ of shape $\\lbrack l, c \\rbrack$, where $c$ is the fixed number of words we selected for evaluation.\n\nSince we interpolated the timing of each word in chapter \\ref{data_preparation}, we can iterate for all talks through each word $w_j$ with its estimated timing $t_j$. Calculate the cumulative distribution function $\\Phi_{t_j, 0.8}(x)$ with a mean value of $t_j$ and a standard deviation of 0.8. \\\\\nThe current word $w_j$ lies in the interval with index $k = \\lceil \\tfrac{t_j}{l} \\rceil$. For the interval $I_k$ and its neighbors $\\{I_{k-2}, I_{k-1}, I_{k+1}, I_{k+2}\\}$, do the cumulative mapping\n\\[p_{j, s} \\mapsto p_{j, s} + \\Phi_{t_j, 0.8}((s - 1) l) - \\Phi_{t_j, 0.8}(s l),\\]\nfor $s = k-2, k-1, \\dots, k+2$. \\\\\n\nHence, we got the features and its labels for the supervised learning model described in the section below. \\\\\nThe MFCC features for an audio file are reshaped into a matrix of shape $\\lbrack l, m \\rbrack$, where $m$ is the number of MFCC samples for an interval of length $l$.\n\n\\section{Defining the models}\n\n\\textbf{by Paul Warkentin} \\\\\n\n% source for deep convnet: https://yerevann.github.io/2016/06/26/combining-cnn-and-rnn-for-spoken-language-identification/\n\nFor the main speech recognition part, we trained several supervised models. The following three delivered the best results.\n\n\\subsection*{Simple convolutional neural network}\nThis model is derived from  TensorFlows' convolutional neural network for speech recognition in the example \\textit{speech\\_commands}\\footnote{\\url{https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/speech\\_commands/models.py}}.\n\\begin{figure}[h]\n\t\\centering\n\t\\makebox[\\textwidth][c]{\n\t\t\\begin{tabular}{clccc||clccc}\n\t\t\t\\hline \\textbf{Nr} & \\textbf{Type} & \\textbf{\\#Ch.} & \\textbf{Wd.} & \\textbf{Hgt.} & \\textbf{Nr} & \\textbf{Type} & \\textbf{\\#Ch.} & \\textbf{Wd.} & \\textbf{Hgt.} \\\\ \\hline\n\t\t\t0 & Input & 1 & 80 & 13 & 3 & Conv2D & 64 & 4 & 10 \\\\\n\t\t\t1 & Conv2D & 64 & 8 & 20 & & Bias & 64 & 4 & 10 \\\\\n\t\t\t& Bias & 64 & 8 & 20 & & ReLU & 64 & 4 & 10 \\\\\n\t\t\t& ReLU & 64 & 8 & 20 & & Dropout & 64 & 4 & 10 \\\\\n\t\t\t& Dropout & 64 & 8 & 20 & 4 & MatMul & 1500 & & \\\\\n\t\t\t& MaxPool & 1 & 2 & 1 & & Bias & 1500 & & \\\\\n\t\t\t2 & Conv2D & 64 & 4 & 10 & & & & & \\\\\n\t\t\t& Bias & 64 & 4 & 10 & & & & & \\\\\n\t\t\t& ReLU & 64 & 4 & 10 & & & & & \\\\\n\t\t\t& Dropout & 64 & 4 & 10 & & & & & \\\\\n\t\t\t& MaxPool & 1 & 2 & 1 & & & & & \\\\ \\hline\n\t\t\\end{tabular}\n\t}\n\t\\caption[Simple convolutional structure]{Graph structure of simple convolutional neural network.}\n\\end{figure}\n\\FloatBarrier\n\n\\subsection*{Deep convolutional neural network}\nThis model is a combination of six consecutive convolutional neural networks, each followed by activation. The output is also here flattened and will then be encoded by two dense layers into the label space. We got the idea by the blog post\\footnote{\\url{https://yerevann.github.io/2016/06/26/combining-cnn-and-rnn-for-spoken-language-identification/}} by Harutyunyan and Khachatrian as they did reach an accuracy of 99.24\\%.\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\makebox[\\textwidth][c]{\n\t\t\\begin{tabular}{clccc||clccc}\n\t\t\t\\hline \\textbf{Nr} & \\textbf{Type} & \\textbf{\\#Ch.} & \\textbf{Wd.} & \\textbf{Hgt.} & \\textbf{Nr} & \\textbf{Type} & \\textbf{\\#Ch.} & \\textbf{Wd.} & \\textbf{Hgt.} \\\\ \\hline\n\t\t\t0 & Input & 1 & 80 & 13 & 4 & Conv2D & 32 & 3 & 3 \\\\\n\t\t\t1 & Conv2D & 16 & 26 & 10 & & Bias & 32 & 3 & 3 \\\\\n\t\t\t& Bias & 16 & 26 & 10 & & ReLU & 32 & 3 & 3 \\\\\n\t\t\t& ReLU & 16 & 26 & 10 & 5 & Conv2D & 32 & 3 & 3 \\\\\n\t\t\t& MaxPool & 1 & 2 & 1 & & Bias & 32 & 3 & 3 \\\\\n\t\t\t2 & Conv2D & 16 & 13 & 5 & & ReLU & 32 & 3 & 3 \\\\\n\t\t\t& Bias & 16 & 13 & 5 & 6 & Conv2D & 32 & 3 & 3 \\\\\n\t\t\t& ReLU & 16 & 13 & 5 & & Bias & 32 & 3 & 3 \\\\\n\t\t\t& Dropout & 16 & & & & ReLU & 32 & 3 & 3 \\\\\n\t\t\t& MaxPool & 1 & 2 & 1 & 7 & Dense & 1000 & & \\\\\n\t\t\t3 & Conv2D & 32 & 5 & 5 & & Sigmoid & 1000 & & \\\\\n\t\t\t& Bias & 32 & 5 & 5 & 8 & Dense & 1500 & & \\\\\n\t\t\t& ReLU & 32 & 5 & 5 & & Sigmoid & 1500 & & \\\\ \\hline\n\t\t\\end{tabular}\n\t}\n\t\\caption[Deep convolutional structure]{Graph structure of deep convolutional neural network.}\n\\end{figure}\n\\FloatBarrier\n\n\\subsection*{Convolutional LSTM neural network}\nThis model is a combination of a convolutional neural network and a LSTM network. The input vector will be put into a dynamic RNN cell of type \\newline\\textit{tf.contrib.rnn.Conv2DLSTMCell} in TensorFlow. Its output is then flattened and will be encoded by two dense layers into the label space.\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tabular}{clccc}\n\t\t\\hline \\textbf{Nr} & \\textbf{Type} & \\textbf{\\#Channels} & \\textbf{Width} & \\textbf{Height} \\\\ \\hline\n\t\t0 & Input & 1 & 80 & 13 \\\\\n\t\t1 & Conv2DLSTM & 1 & 80 & 13 \\\\\n\t\t2 & Dense & 1000 & & \\\\\n\t\t& Sigmoid & 1000 & & \\\\\n\t\t3 & Dense & 1500 & & \\\\\n\t\t& Sigmoid & 1500 & & \\\\ \\hline\n\t\\end{tabular}\n\t\\caption[Convolutional LSTM structure]{Graph structure of convolutional LSTM neural network.}\n\\end{figure}\n\\FloatBarrier\n", "meta": {"hexsha": "608ded474b530b65012e1e7a1d1635ec2d8b7b03", "size": 9613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapters/algorithm_concept.tex", "max_stars_repo_name": "bbboll/ml_subtitle_align", "max_stars_repo_head_hexsha": "3abb5628902db1021af8ff1666f37a1663574487", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-04-01T20:02:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T15:59:20.000Z", "max_issues_repo_path": "doc/chapters/algorithm_concept.tex", "max_issues_repo_name": "bbboll/ml_subtitle_align", "max_issues_repo_head_hexsha": "3abb5628902db1021af8ff1666f37a1663574487", "max_issues_repo_licenses": ["MIT"], "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/chapters/algorithm_concept.tex", "max_forks_repo_name": "bbboll/ml_subtitle_align", "max_forks_repo_head_hexsha": "3abb5628902db1021af8ff1666f37a1663574487", "max_forks_repo_licenses": ["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.519379845, "max_line_length": 783, "alphanum_fraction": 0.6931238947, "num_tokens": 3089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582995, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.647146913158656}}
{"text": "\\section{(Sub-)Groups with prime power order}\r\n\\subsection{Elementary Properties}\r\n\\begin{definition}\r\n    Let $G$ be a group.\r\n    We say $G$ is a $p$-group for a prime $p$ if $|G|=p^n$ for some $n\\in\\mathbb N$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $G$ be a $p$-group, then $Z(G)\\neq 1$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the partition of $G$ by conjugacy classes, which are either $1$ or divisible by $p$.\r\n    Note that $Z(G)$ is the union of all $1$-classes.\r\n    But if $|Z(G)|=1$, then\r\n    $$0\\equiv p^n=|G|=1+\\sum_{\\exists g\\notin Z(G),C=\\operatorname{ccl}_G(g)}|C|\\equiv 1\\pmod{p}$$\r\n    which is a contradiction.\r\n\\end{proof}\r\nIn particular $|Z(G)|\\equiv 0\\pmod{p}$.\r\n\\begin{corollary}[Classification of Simple $p$-groups]\r\n    If $G$ is a simple $p$-group, then $G\\cong C_p$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $1\\neq Z(G)\\unlhd G$.\r\n    Since $G$ is simple we must have $Z(G)=G$, hence $G$ is abelian, but then necessarily $G\\cong C_p$ since $G$ cannot have any proper subgroup to be simple.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $G$ be a $p$-group of order $p^n$, then $G$ contains an element of order $p^r$ for any $0\\le r\\le n$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Consider the composition series of $G$\r\n    $$1=G_0\\lhd G_1\\lhd\\cdots\\lhd G_m=G$$\r\n    Where $G_{i+1}/G_i$ is simple.\r\n    But it is an $p$-group, so we must have $G_{i+1}/G_i\\cong C_p$ for any $i$.\r\n    The claim follows.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    For $G$ a group.\r\n    If $G/Z(G)$ is cyclic, then $G$ is abelian.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $gZ(G)$ be a generator of $G/Z(G)$.\r\n    Then every element of $G$ is of the form $p^iz$ where $z\\in Z$.\r\n    But for $z,z'\\in Z(G)$, $g^izg^jz'=g^{i+j}zz'=g^jz'g^iz$, so $G$ is abelian.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $G$ has order $p^2$ for a prime $p$, then $G$ is abelian.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    We already know that $Z(G)\\neq 1$.\r\n    For $|Z(G)|=p$ then we have $G/Z(G)\\cong C_p$, so $G$ is abelian by the preceding lemma, contradiction.\r\n    For $|Z(G)|=p^2$ we have $Z(G)=G$, which means that $G$ is abelian.\r\n    There are no other possibilities, so the proof is done.\r\n\\end{proof}\r\nSadly (or not) there are nonabelian groups of order $p^3$.\r\n\\subsection{Sylow's Theorems}\r\n\\begin{theorem}[Sylow's Theorems]\r\n    Let $G$ be a finite group with order $p^am$ where $p$ is a prime and $p\\nmid m$.\r\n    Then\\\\\r\n    1. The set $\\operatorname{Syl}_p(G)=\\{P\\le G:|P|=p^a\\}$ is nonempty.\\\\\r\n    2. All elements of $\\operatorname{Syl}_p(G)$ are conjugate.\\\\\r\n    3. The number $n_p=|\\operatorname{Syl}_p(G)|$ satisfies $n_p\\equiv 1\\pmod{p}$ and $n_p|m$.\r\n\\end{theorem}\r\n\\begin{corollary}\r\n    If $n_p=1$, then there is a normal Sylow $p$-subgroup.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let $g\\in G$ and $P$ be a Sylow $p$-subgroup of $G$.\r\n    But then $gPg^{-1}\\in\\operatorname{Syl}_p(G)=\\{P\\}$, hence $gPg^{-1}=P\\implies P\\unlhd G$.\r\n\\end{proof}\r\n\\begin{example}\r\n    There is no simple group of order $1000$.\r\n    Suppose $G$ is a group of order $1000=2^35^3$, then $n_5\\equiv 1\\pmod{5}$ and $n_5|8$, but then we must have $n_5=1$.\r\n    So there is a normal Sylow $5$-subgroup of $G$ which is obviously not the identity or $G$, hence $G$ is not normal.\r\n\\end{example}\r\n\\begin{proof}\r\n    1. Consider the action of the group $G$ on the set $\\Omega$ of all subsets of $G$ of size $p^a$ by $g\\star X=\\{gx:x\\in X\\}$, so\r\n    $$|\\Omega|=\\binom{p^am}{p^a}\\not\\equiv 0\\pmod{p}$$\r\n    Hence this action has an orbit, say the orbit of $X\\in\\Omega$, which order is not a multiple of $p$.\r\n    Then $|G_X||\\operatorname{orb}_G(X)|=|G|=p^am$, so $p^a||G_X|$.\r\n    On the other hand, $\\bigcup_{g\\in G}g\\star X=G$, so $|G|\\le |\\operatorname{orb}_G(X)||X|$, so $|G_X|=|G|/|\\operatorname{orb}_G(X)|\\le |X|=p^a$, but $|G_X|\\ge p^a$, therefore $|G_X|=p^a$.\\\\\r\n    2. We shall prove a stronger statement: suppose $P\\in\\operatorname{Syl}_p(G)$ and $Q\\le G$ a $p$-subgroup, then $Q\\le gPg^{-1}$ for some $g\\in G$.\r\n    Consider the action of $Q$ on the set of left cosets $G/P$ by left multiplication.\r\n    By orbit-stabiliser, any orbit divides $|Q|$, so its size must be either $1$ or a multiple of $p$.\r\n    But $|G/P|=m$ which is coprime to $p$, hence there is at least one orbit $\\operatorname{orb}_Q(gP)$ of size $1$, so for any $q\\in Q$, $g^{-1}qg\\in P\\implies Q\\le gPg^{-1}$.\\\\\r\n    3. Let $G$ act transitively (by 2) on $\\operatorname{Syl}_p(G)$ by conjugation.\r\n    So by orbit-stabiliser, $n_p||G|$, so it suffices to show $n_p\\equiv 1\\pmod{p}$.\r\n    Now let $P\\in\\operatorname{Syl}_p(G)$ and consider its action on $\\operatorname{Syl}_p(G)$ by conjugation.\r\n    Now the orbits divides $|P|=p^a$, so is either $1$ or divisible by $p$.\r\n    We shall show that there is exactly one orbit of size $1$, which will establish the theorem.\r\n    There is at least one orbit, namely $\\operatorname{orb}_P(P)$.\r\n    If $\\operatorname{orb}_P(Q)$ is also an orbit of size $1$, then $P\\le N_G(Q)$.\r\n    Now $P,Q$ are Sylow $p$-subgroups of $N_G(Q)$, so they are conjugate by 2, therefore there is some $g\\in N_G(Q)$ with $Q=gQg^{-1}=P$.\r\n    The theorem is hence proved.\r\n\\end{proof}\r\n\\begin{example}\r\n    Suppose $G$ is a simple group, then $|G|\\neq 132$.\r\n    Assume there is a simple group of order $132=2^2\\cdot 3\\cdot 11$, then by Sylow's Third Theorem, $n_3=1,4,22$ and $n_{11}=1,12$, but by simplicity neither of them is $1$, so $n_{11}=12$\r\n    If $n_3=4$, then letting $G$ act on $\\operatorname{Syl}_3(G)$ by conjugation gives a group homomorphism $G\\to S_4$, but its kernel is not all $G$, so $G$ is isomorphic to a subgroup of $S_4$, but $|S_4|=24<132$, contradiction.\\\\\r\n    So $n_3=22$.\r\n    Now the Sylow $3$-subgroups are all of order $3$, this means that there are $22\\times (3-1)=44$ elements of order $3$.\r\n    Similarly $n_{11}=12$ gives $(11-1)\\times 12=120$ elements of order $11$, but then $132=|G|\\ge 120+44+1=165$, contradiction.\r\n\\end{example}\r\nFor sake of problem sheets, we mention the following definition.\r\n\\begin{definition}\r\n    An automorphism $\\operatorname{Aut}(G)\\le\\operatorname{Sym}G$ of a group $G$ is the group of all isomorphisms from $G$ to itself.\r\n\\end{definition}", "meta": {"hexsha": "732c736479396ca6a4646948074daeb61adc9a65", "size": 6170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/p.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": "4/p.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": "4/p.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": 58.7619047619, "max_line_length": 233, "alphanum_fraction": 0.6372771475, "num_tokens": 2273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.9005297901222472, "lm_q1q2_score": 0.6471156575248568}}
{"text": "\\subsection{Convolutional Neural Network}\n\\label{subsec:cnn}\n% \\todo[inline]{Citations}\n\nConvolutional neural networks are a type of deep learning architecture that is primarily used to classify images.\nThey are based on artificial neural networks and the mathematical convolution operation.\nThe efficiency in image classification of CNNs is largely responsible for the reputation of deep learning \\cite{cnn_pathmind}.\n\nThe main problems when working with color images is that they are high-dimensional and therefore require a lot of processing power.\nFor this reason, convolutional neural networks use special layers to detect features and reduce the amount of data.\nThe three different layers used are convolution layers, pooling layers and fully-connected layers.\n% An example of a CNN sequence to classify handwritten digits is shown in figure \\ref{fig:cnn}.\nFigure \\ref{fig:cnn} shows an example of a CNN sequence to classify handwritten digits \\cite{cnn_pathmind}.\n\n\\paragraph{Convolution Layer}\nThe convolution layer performs the convolution operations using so-called kernels or filters.\nThe goal of the convolution operation is to extract certain features --- such as edges --- from the image.\nDifferent kernels are used to detect different features.\nThe first convolution layers are responsible for capturing low-level features, while following layers are responsible for capturing high-level features \\cite{cnn_tds}.\n\\clearpage\n\n\\paragraph{Pooling Layer}\nPooling layers reduce the spatial size of the convolved features.\nPooling is done by only looking at the portion of the image masked by the kernel.\nMaximum pooling yields the maximum value and average pooling yields the average value of the masked portion.\nBy doing so, the required computational power is significantly decreases and the dominant features are extracted \\cite{cnn_tds}.\n\\\\\n\n\\paragraph{Fully-Connected Layer}\nThe fully-connected layers are responsible for learning the non-linear combinations of the high-level convolved features.\nThey flatten the result of the convolution process into a vector of values.\nEach value corresponds to the probability that a certain feature belongs to a label \\cite{cnn_tds}.\n% Each value corresponds to a probability that a certain feature belongs to a label \\cite{cnn_tds}.\n% Each value corresponds to a probability that a certain feature belongs to a certain label \\cite{cnn_tds}.\n\n\\begin{figure}[t]\n  \\centering\n  \\includegraphics[width=\\textwidth]{cnn}\n  \\caption{Example of a convolutional neural network \\cite{cnn_tds}}\n  \\label{fig:cnn}\n\\end{figure}\n", "meta": {"hexsha": "32fff4c85581c7b10dd29c71264d007bc5b706e7", "size": 2570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/report/sections/ai/cnn.tex", "max_stars_repo_name": "MuellerDominik/P5-AIonFPGA", "max_stars_repo_head_hexsha": "13fc60fb973a4a87a4af1b49c17d5dd1fd239ed5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-26T15:54:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-26T15:54:09.000Z", "max_issues_repo_path": "doc/report/sections/ai/cnn.tex", "max_issues_repo_name": "MuellerDominik/P5-AIonFPGA", "max_issues_repo_head_hexsha": "13fc60fb973a4a87a4af1b49c17d5dd1fd239ed5", "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/report/sections/ai/cnn.tex", "max_forks_repo_name": "MuellerDominik/P5-AIonFPGA", "max_forks_repo_head_hexsha": "13fc60fb973a4a87a4af1b49c17d5dd1fd239ed5", "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": 61.1904761905, "max_line_length": 167, "alphanum_fraction": 0.8108949416, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6470902936863686}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Shell Method}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises for using the shell method.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nThe region defined by the inequalities $\\sqrt{1-x^2} \\leq y \\leq 1$ for $0 \\leq y \\leq 1$ is revolved around the $y$-axis. Compute the volume of the resulting solid using the shell method.\n\\begin{center}\n\\begin{image}\n\\includegraphics{shell/shell03.png}\n\\end{image}\n\\end{center}\n\\begin{itemize}\n\\item When the slicing variable is $x$, the radius of a shell is the \\wordChoice{\\choice[correct]{horizontal}\\choice{vertical}} distance from an $x$-slice to the axis of rotation. Thus\n\\[ r(x) = \\answer{x} - \\answer{0}. \\]\n\\item The height of an $x$-slice is equal to\n\\[ h(x) = \\answer{1 - \\sqrt{1 - x^2}}. \\]\n\\item The volume is equal to the integral of $2 \\pi r h$, so \n\\[ V = \\int_{\\answer{0}}^{\\answer{1}} \\answer{2 \\pi x ( 1 - \\sqrt{1-x^2}) } dx = \\answer{\\frac{\\pi}{3}}. \\]\n(Note: to compute the integral, split it into two parts and make the substitution $u = 1-x^2$ for one of them.)\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nThe region in the plane bounded above by the graph $y = \\sqrt{1+x^2}$, below by $y = -1 + x + \\sqrt{1+x^2}$, and on the left by $x = 0$ is revolved around the axis $x = 1$. Compute the volume of the resulting solid using the shell method.\n\\begin{center}\n\\begin{image}\n\\includegraphics{shell/shell04.png}\n\\end{image}\n\\end{center}\n\\begin{itemize}\n\\item When the slicing variable is $x$, the radius of a shell is the \\wordChoice{\\choice[correct]{horizontal}\\choice{vertical}} distance from an $x$-slice to the axis $x = 0$. Thus\n\\[ r(x) = \\answer{1} - \\answer{x}. \\]\n\\item The height of an $x$-slice is equal to\n\\[ h(x) = \\answer{-1+x}. \\]\n\\item The volume is equal to the integral of $2 \\pi r h$, so \n\\[ V = \\int_{\\answer{-1}}^{\\answer{1}} \\answer{2 \\pi (1-x)^2 } dx = \\answer{\\frac{16\\pi}{3}}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\\begin{exercise}\nThe region in the plane $y = \\sqrt{x}$, $y=0$, and $x = 1$ is revolved around the $y$-axis. Use the shell method to compute the volume.\n\\[ V = \\answer{\\frac{4 \\pi}{5}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nThe same region as above (bounded by $y = \\sqrt{x}$, $y=0$, and $x = 1$) is revolved around the axis $x=1$. Use the shell method to compute the volume.\n\\[ V = \\answer{\\frac{8 \\pi}{15}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nThe same region as above  (bounded by $y = \\sqrt{x}$, $y=0$, and $x = 1$) is revolved around the $x$-axis. Use the shell method to compute the volume.\n\\begin{hint}\nThe ``height'' of a shell is $1-y^2$ in this case.\n\\end{hint}\n\\[ V = \\answer{\\frac{\\pi}{2}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nFor the same region as above (bounded by $y = \\sqrt{x}$, $y=0$, and $x = 1$), use the shell method to compute the volume when revolved around the axis $y = 1$.\n\\[ V = \\answer{\\frac{5 \\pi}{6}}. \\]\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[ShellQuad001]\n\nThe region in the plane bounded below by the curve \\(y=-x^2\\), above by the curve \\(y=x^2+2x+2\\), on the right by the line  \\(x = 0\\), and on the left by the line \\(x = -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{\\(4\\pi\\)}\n\\choice{\\(6\\pi\\)}\n\\choice[correct]{\\(8\\pi\\)}\n\\choice{\\(10\\pi\\)}\n\\choice{\\(12\\pi\\)}\n\\choice{\\(14\\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe axis \\(x = -2\\) is parallel to the direction of slices using the integration variable \\(x\\), which indicates the shell method. \n The region lies to the right of the axis, which must be the case because the interval \\(-2 \\leq x \\leq 0\\) lies to the right of the axis \\(x = -2\\).\n \\begin{hint}\nThe integral to compute equals \\[ \\begin{aligned} V &= \\int_{-2}^{0}2 \\pi (x-(-2))((x^2+2x+2)-(-x^2))~ dx\\\\\n& = \\pi \\int_{-2}^{0} (4x^3+12x^2+12x+8)~ dx\\\\\n& = \\pi \\left. \\left(x^4+4x^3+6x^2+8x\\right) \\right|_{-2}^{0} = 8\\pi. \\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[ShellQuad019]\n\nThe region in the plane bounded on the left by the curve \\(x=-y^2+4y+1\\), on the right by the curve \\(x=y^2+2y+1\\), and below by the line \\(y = -1\\) is revolved around the axis \\(y = -1\\). Compute the volume of the resulting solid.\n(Hints won't reveal until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\pi\\)}\n\\choice{\\(5\\pi\\)}\n\\choice{\\(9\\pi\\)}\n\\choice{\\(13\\pi\\)}\n\\choice{\\(17\\pi\\)}\n\\choice{\\(21\\pi\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nThe axis \\(y = -1\\) is parallel to the direction of slices using the integration variable \\(y\\), which indicates the shell method. The lower endpoint of integration will be \\(y = -1\\); the upper endpoint can be determined by setting \\(-y^2+4y+1 = y^2+2y+1\\) and choosing the solution which is greater than \\(-1\\). This gives the range \\(-1 \\leq y \\leq 0\\). \n The region lies above the axis, which must be the case because the interval \\(-1 \\leq y \\leq 0\\) lies above the axis \\(y = -1\\).\n \\begin{hint}\nThe integral to compute equals \\[ \\begin{aligned} V &= \\int_{-1}^{0}2 \\pi (y-(-1))((y^2+2y+1)-(-y^2+4y+1))~ dy\\\\\n& = \\pi \\int_{-1}^{0} (4y^3-4y)~ dy\\\\\n& = \\pi \\left. \\left(y^4-2y^2\\right) \\right|_{-1}^{0} = 1\\pi. \\end{aligned}\\]\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[shellalgsub2001]\n\nThe region in the plane between the  \\(x\\)-axis and the graph\n\\[ y = \\frac{1}{2 \\sqrt{\\frac{x^{2}}{3} + 1}} \\]\n in the range \\(0 \\leq x \\leq 3\\) is revolved around the axis \\(x = 0\\). Compute the volume of the resulting solid.\n (Hints won't reveal until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{3}{2} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{8}{5} \\pi\\)}\n\\choice{\\(\\displaystyle \\frac{5}{3} \\pi\\)}\n\\choice{\\(\\displaystyle 2 \\pi\\)}\n\\choice[correct]{\\(\\displaystyle 3 \\pi\\)}\n\\choice{\\(\\displaystyle 5 \\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\\). The height of a shell is exactly \\(\\frac{1}{2 \\sqrt{\\frac{x^{2}}{3} + 1}}\\).\n\\begin{hint}\nThe volume of the region is therefore given by\n\\[ \\int_{0}^{3} \\frac{\\sqrt{3} \\pi x}{\\sqrt{x^{2} + 3}}\\, dx. \\]\n\\begin{hint}\n To compute the integral we can use the substitution \\(u = x^{2} + 3\\) which implies the equality \\(du = \\left(2 x\\right)dx\\) for the differentials. This gives the equality\n\\[ \\begin{aligned} \\int \\frac{\\sqrt{3} \\pi x}{\\sqrt{x^{2} + 3}}\\, dx & = \\int \\frac{\\sqrt{3} \\pi}{2 \\sqrt{u}}\\, du \\\\\n & = \\sqrt{3} \\pi \\sqrt{u}. \\end{aligned} \\]\nReversing the substitution gives\n\\[ \\begin{aligned} \\int_{0}^{3} \\frac{\\sqrt{3} \\pi x}{\\sqrt{x^{2} + 3}}\\, dx & = \\left. \\left[\\sqrt{3} \\pi \\sqrt{x^{2} + 3} \\right] \\right|_{0}^{3}\\\\ & = \\left(6 \\pi \\right) - \\left(3 \\pi \\right) = 3 \\pi. \\end{aligned} \\]\n\\end{hint}\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "953d7e0966fdd9a9268a5310031af6f38a40a51a", "size": 7033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "volumes/03shellpractice.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/03shellpractice.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/03shellpractice.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": 44.7961783439, "max_line_length": 357, "alphanum_fraction": 0.6507891369, "num_tokens": 2467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6470902730755489}}
{"text": "\\hypertarget{matrix}{%\n\\section{Matrix}\\label{matrix}}\n\nThe Matrix class provides support for matrices. A matrix can be\ninitialized with a given size,\n\n\\begin{lstlisting}\nvar a = Matrix(nrows,ncols)\n\\end{lstlisting}\n\nwhere all elements are initially set to zero. Alternatively, a matrix\ncan be created from an array,\n\n\\begin{lstlisting}\nvar a = Matrix([[1,2], [3,4]])\n\\end{lstlisting}\n\nYou can create a column vector like this,\n\n\\begin{lstlisting}\nvar v = Matrix([1,2])\n\\end{lstlisting}\n\nOnce a matrix is created, you can use all the regular arithmetic\noperators with matrix operands, e.g.\n\n\\begin{lstlisting}\na+b\na*b\n\\end{lstlisting}\n\nThe division operator is used to solve a linear system, e.g.\n\n\\begin{lstlisting}\nvar a = Matrix([[1,2],[3,4]])\nvar b = Matrix([1,2])\n\nprint b/a\n\\end{lstlisting}\n\nyields the solution to the system a*x = b.\n", "meta": {"hexsha": "2fbb4a7aa87b905ec91304d8f5750fd1aa883df2", "size": 841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/src/Reference/matrix.tex", "max_stars_repo_name": "mattsep/morpho", "max_stars_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-09-18T14:44:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T11:41:50.000Z", "max_issues_repo_path": "manual/src/Reference/matrix.tex", "max_issues_repo_name": "mattsep/morpho", "max_issues_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 79, "max_issues_repo_issues_event_min_datetime": "2021-10-05T17:33:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:06:10.000Z", "max_forks_repo_path": "manual/src/Reference/matrix.tex", "max_forks_repo_name": "mattsep/morpho", "max_forks_repo_head_hexsha": "50bb935653c0675b81e9f2d78573cf117971a147", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-10-05T16:56:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-31T19:55:27.000Z", "avg_line_length": 20.0238095238, "max_line_length": 69, "alphanum_fraction": 0.7288941736, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6470902627701385}}
{"text": "\\gotosection{1}{4}\n\\subsection{The geometry of $\\mathbb{R}^n$}\n\n\\begin{exercise}{3}\n  \\begin{enumerate}\n    \\item Let $\\Vect{x} = \\begin{bmatrix}0\\\\1\\\\4\\end{bmatrix}$,\n          $\\frac{\\Vect{x}}{|\\Vect{x}|}=\n           \\frac{\\Vect{x}}{\\sqrt{17}}=\n           \\begin{bmatrix}0\\\\\\frac{1}{\\sqrt{17}}\\\\\\frac{4}{\\sqrt{17}}\\end{bmatrix}$\n\n    \\item Let $\\Vect{x} = \\begin{bmatrix}-3\\\\7\\end{bmatrix}$,\n          $\\frac{\\Vect{x}}{|\\Vect{x}|}=\n           \\frac{\\Vect{x}}{\\sqrt{58}}=\n           \\begin{bmatrix}-\\frac{3}{\\sqrt{58}}\\\\\\frac{7}{\\sqrt{58}}\\end{bmatrix}$\n\n    \\item Let $\\Vect{x} = \\begin{bmatrix}\\sqrt{2}\\\\-2\\\\-5\\end{bmatrix}$,\n          $\\frac{\\Vect{x}}{|\\Vect{x}|}=\n           \\frac{\\Vect{x}}{\\sqrt{31}}=\n           \\begin{bmatrix}\n             \\sqrt{\\frac{2}{31}} \\\\\n             -\\frac{2}{\\sqrt{31}} \\\\\n             -\\frac{5}{\\sqrt{31}}\n           \\end{bmatrix}$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\n  \\begin{enumerate}\n    \\item $cos(\\theta) = \\frac{1}{\\sqrt{3}}$, $\\theta = \\arccos{1}{\\sqrt{3}}$.\n    \\item $cos(\\theta) = 0$, $\\theta = \\frac{\\pi}{2}$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{7}\n  \\begin{enumerate}\n    \\item $\\det(M) = 1$, $M^{-1} = \\begin{xmatrix}0&1\\\\-1&2\\end{xmatrix}$.\n    \\item $\\det(M) = 0$, $M^{-1}$ doesn't exist.\n    \\item $\\det(M) = ad$, if $a, d \\neq 0$, $M^{-1} = \\frac{1}{ad}\\begin{xmatrix}d&-b\\\\0&a\\end{xmatrix}$.\n    \\item $\\det(M) = 0$, $M^{-1}$ doesn't exist.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{8}\n  \\begin{enumerate}\n    \\item -4\n    \\item $adf$\n    \\item $adg - cbg$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{10}\n  \\begin{enumerate}\n    \\item This can be proven inductively: $k = 1$, $|A^1| = |A| = |A|^1$. $k = 2$, $|A^2| = |A \\cdot A| \\leq |A||A| = |A|^2$, from Cauchy-Schwarz's inequality. $k > 2$, $|A^k| = |A^{k-1} \\cdot A| \\leq |A^{k-1}||A| \\leq |A|^k$. \\rQED\n          $$|A^3| = |\\begin{xmatrix}7&10\\\\5&7\\end{xmatrix}| = \\sqrt{223}$$\n          $$|A|^3 = (\\sqrt{7})^3 = 7\\sqrt{7}$$\n          \n    \\item $|\\Vect{u} \\cdot \\Vect{v}| = |\\Vect{u}||\\Vect{v}|$, because they are in opposite direction, namely $\\Vect{u}$ is on the line spanned from $\\Vect{v}$.\n          \n          $|\\Vect{u} \\cdot \\Vect{w}| < |\\Vect{u}||\\Vect{w}|$, because the two vectors are not in the same or opposite directions, namely one is not on the line spanned from the other.\n          \n          $|\\Vect{u} \\cdot \\Vect{v}| = 2 + 8 + 18 = 28 = \\sqrt{14} \\cdot \\sqrt{56} = |\\Vect{u}||\\Vect{v}|$.\n          \n          $|\\Vect{u} \\cdot \\Vect{w}| = 2 + 18 = 20$, $|\\Vect{u}||\\Vect{w}| = \\sqrt{14} \\cdot \\sqrt{40} = 4\\sqrt{35} > 20 = |\\Vect{u} \\cdot \\Vect{w}|$.\n    \n    \\item Let $\\Vect{u} = \\begin{bmatrix}-v_2\\\\v_1\\end{bmatrix}$, namely rotating $\\Vect{v}$ by $\\frac{\\pi}{2}$ counterclockwise. $\\Vect{u} \\cdot \\Vect{w} = -v_2w_1 + v_1w_2 < 0$. Therefore, the angle between $\\Vect{u}$ and $\\Vect{w}$ is larger than $\\frac{\\pi}{2}$, which means $\\Vect{w}$ lies clockwise from $\\Vect{v}$.\n    \n    \\item Let $\\theta$ be the angle between $\\Vect{v}$ and $\\Vect{w}$. $\\cos(\\theta) = \\frac{\\Vect{v} \\cdot \\Vect{w}}{|\\Vect{v}||\\Vect{w}|}$, $\\cos(\\theta)|\\Vect{v}||\\Vect{w}| = 42$.\n    \n          If $\\cos(\\theta) = 1$, $|\\Vect{v}||\\Vect{w}| = 42$, or $|\\Vect{w}| = 3\\sqrt{14}$. This is the shortest $\\Vect{w}$. As $\\cos(\\theta)$ approaches $0$, $|\\Vect{w}|$ will approach $\\infty$, so there is no longest $\\Vect{w}$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{13}\n  First, we can prove that for any\n    $\\Vect{a} = \\begin{xmatrix}a_1\\\\a_2\\\\a_3\\end{xmatrix},\n     \\Vect{b} = \\begin{xmatrix}b_1\\\\b_2\\\\b_3\\end{xmatrix}$ and $x, y \\in \\mathbb{R}$, $x\\Vect{a} \\times y\\Vect{b} = xy(\\Vect{a} \\times \\Vect{b})$:\n  \n  $$x\\Vect{a} \\times y\\Vect{b} =\n    \\begin{xmatrix}\n       xa_2yb_3 - xa_3yb_2 \\\\\n      -xa_1yb_3 + xa_3yb_1 \\\\\n       xa_1yb_2 - xa_2yb_1\n    \\end{xmatrix} = xy\n    \\begin{xmatrix}\n       a_2b_3 - a_3b_2 \\\\\n      -a_1b_3 + a_3b_1 \\\\\n       a_1b_2 - a_2b_1\n    \\end{xmatrix} = xy(\\Vect{a} \\times \\Vect{b})$$\n    \n  For two vectors $\\Vect{v}_1$, $\\Vect{v}_2$ pointing in the same direction, they can be written as $n_1\\Vect{u}$ and $n_2\\Vect{u}$, respectively. Let $u_1, u_2, u_3$ be the three components of $\\Vect{u}$, we have:\n\n  $$\\Vect{v}_1 \\times \\Vect{v}_2 = (n_1n_2) \\Vect{u} \\times \\Vect{u} = (n_1n_2)\n    \\begin{xmatrix}\n       u_2u_3 - u_3u_2 \\\\\n      -u_1u_3 + u_3u_1 \\\\\n       u_1u_2 - u_2u_1\n    \\end{xmatrix} = (n_1n_2)\\Vect{0} = \\Vect{0}$$\n    \n  \\rQED\n\\end{exercise}\n\n\\begin{exercise}{16}\n  \\begin{enumerate}\n    \\item $|Area| = |\\det(\\begin{xmatrix}1&5\\\\2&1\\end{xmatrix})| = |1 - 10| = 9$\n    \\item $|Area| = |\\det(\\begin{xmatrix}1&5\\\\2&-1\\end{xmatrix})| = |-1 - 10| = 11$\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{19}\n  \\begin{enumerate}\n    \\item $|\\Vect{v}_n| = \\sqrt{1 + \\hdots + 1} = \\sqrt{n}$\n    \\item $\\cos{a_n} = \\frac{\\Vect{v}_n \\cdot \\Vect{e}_1}{|\\Vect{v}_n||\\Vect{e}_1|} = \\frac{1}{\\sqrt{n}}$, so $a_n = \\arccos{\\frac{1}{\\sqrt{n}}}$. $\\lim_{n \\to \\infty} a_n = \\arccos{\\frac{1}{\\infty}} = \\frac{\\pi}{2}$.\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{24}\n  \\def \\Set {\\Vect{v}^{\\bot}}\n  \\begin{enumerate}\n    \\item Since $\\Vect{0} \\cdot \\Vect{v} = 0$, $\\Vect{0} \\in \\Set$.\n    \n          For any $\\Vect{x}, \\Vect{y} \\in \\Set$, $(\\Vect{x} + \\Vect{y}) \\cdot \\Vect{v} = \\Vect{x} \\cdot \\Vect{v} + \\Vect{y} \\cdot \\Vect{v} = 0 + 0 = 0$. Therefore, $(\\Vect{x} + \\Vect{y}) \\in \\Set$.\n          \n          For $\\Vect{x} \\in \\Set$ and $c \\in \\mathbb{R}$, $(c\\Vect{x}) \\cdot \\Vect{v} = c(\\Vect{x} \\cdot \\Vect{v}) = c0 = 0$. \\rQED\n    \n    \\item $(\\Vect{a} - \\frac{\\Vect{a} \\cdot \\Vect{v}}{|\\Vect{v}|^2}\\Vect{v}) \\cdot \\Vect{v} =\n            \\Vect{a} \\cdot \\Vect{v} - \\frac{\\Vect{a}\\cdot\\Vect{v}}{|\\Vect{v}|^2}\\Vect{v} \\cdot \\Vect{v} =\n            \\Vect{a} \\cdot \\Vect{v}(1 - \\frac{\\Vect{v}^2}{|\\Vect{v}|^2}) = 0$. \\rQED\n            \n    \\item (b) suggests the existence of $t(\\Vect{a})$. Suppose that there exists a distinct $t'(\\Vect{a})$ such that $(\\Vect{a} + t'(\\Vect{a})\\Vect{v}) \\in \\Set$. Then we have:\n    \n         $$\\left\\{\n         \\begin{aligned}\n            (\\Vect{a} + t(\\Vect{a})\\Vect{v}) \\cdot \\Vect{v} = 0 \\\\\n            (\\Vect{a} + t'(\\Vect{a})\\Vect{v}) \\cdot \\Vect{v} = 0\n         \\end{aligned} \\quad \\Rightarrow \\quad\n         \\begin{aligned}\n            \\Vect{a} \\cdot \\Vect{v} + t(\\Vect{a})\\Vect{v}^2 = 0 \\\\\n            \\Vect{a} \\cdot \\Vect{v} + t'(\\Vect{a})\\Vect{v}^2 = 0\n         \\end{aligned} \\quad \\Rightarrow \\quad \n         \\begin{aligned}\n            t(\\Vect{a}) = -\\frac{\\Vect{a} \\cdot \\Vect{v}}{\\Vect{v}^2} \\\\\n            t'(\\Vect{a}) = -\\frac{\\Vect{a} \\cdot \\Vect{v}}{\\Vect{v}^2}\n         \\end{aligned}\n         \\right.$$\n         \n         Since there could be only one possible value for $-\\frac{\\Vect{a} \\cdot \\Vect{v}}{\\Vect{v}^2}$, $t(\\Vect{a}) = t'(\\Vect{a})$, namely $t(\\Vect{a})$ is unique.\n         \n        $$\\Vect{a} + t(\\Vect{a})\\Vect{v} = \\Vect{a} -\\frac{\\Vect{a} \\cdot \\Vect{v}}{\\Vect{v}^2}\\Vect{v} = \\Vect{a} - \\frac{\\Vect{a} \\cdot \\Vect{v}}{|\\Vect{v}|^2}\\Vect{v} = P_{\\Set}(\\Vect{a})$$\n        \n        \\rQED\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{26}\n  \\begin{enumerate}\n    \\item $$A\\begin{xmatrix}x\\\\y\\end{xmatrix} = \\begin{xmatrix}x-2y\\\\3x+4y\\end{xmatrix}$$\n    \n          $$a\\begin{pmatrix}x\\\\y\\end{pmatrix} = \\arccos{\\frac{x^2+xy+4y^2} {\\sqrt{10}\\sqrt{(x^2+y^2) (x^2+2xy+2y^2)}}}$$\n          \n    \\item Suppose there existing a nonzero vector such that it is rotated by $\\frac{\\pi}{2}$:\n    \n          $$\\frac{x^2+xy+4y^2} {\\sqrt{10}\\sqrt{(x^2+y^2) (x^2+2xy+2y^2)}} = \\cos(\\frac{\\pi}{2})$$\n          $$x^2+xy+4y^2=0$$\n          $$(\\frac{1}{2}x+2y)^2=-\\frac{3}{4}x^2$$\n          \n          Because $(\\frac{1}{2}x+2y)^2 \\geq 0$ and $-\\frac{3}{4}x^2 \\leq 0$, both sides must equal $0$. Therefore, $x = 0, y = 0$, which contradicts the premise of nonzero vector. As a result, such vector doesn't exist.\n  \\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "5c7130e50ab39fda79608ecf75554fffe117c960", "size": 7911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/sec0104.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": "HW3/sec0104.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": "HW3/sec0104.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": 46.8106508876, "max_line_length": 321, "alphanum_fraction": 0.5235747693, "num_tokens": 3278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.85391273808085, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6470902571356136}}
{"text": "\\pagebreak\n\\section{Experiment-2}\n\\textbf{Q.1 What would you expect the steady-state velocity of the system to be if a step input of 2000\nN were applied at t = 0?}\n\\\\\nAns. \\\\\nFrom newtons second law we have, dv/dt = (F-bv)/M.\n\\\\ M is the mass, v is velocity and F is force, b is damping cofficient. \n\\\\\nAt steady state, the change in velocity will be zero. i.e. dv/dt = 0.\n\\\\\nTherefore, F = bv\n\\\\F = 2000N\n\\\\b = 40 N*sec/m\n\\\\2000 = 40*v\n\\\\v= 50 m/sec.\n\n\\textbf{Q.2 Why do this step input and the ramp input with saturation we simulated have the same steady state velocity?}\n\\\\Ans.The step input is similar to saturated ramp input, because when steady state is reached, both step input and saturated ramp input\nhave fixed value(input value). Therefore, if we apply same force to same system (under idential condition), \nthen system will attain the same velocity. That is why we get same steady state velocity.\n\n\\textbf{Q.3 Using which input, the step or the ramp with saturation, would you expect the system to reach its steady-state velocity more quickly?\n}\n\\\\Ans. With step input the system will reach it's steady state velocity more quickly. Because, \nsaturated ramp input will take more time to reach it's saturation value whereas step input \nreaches to it's fixed value quickly. ", "meta": {"hexsha": "7e6d7ff00f11004e829c05d64bc2ec7f00360113", "size": 1283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conclusion-writing/module/experiment-2.tex", "max_stars_repo_name": "suryanshshukla10/MSPS-practical", "max_stars_repo_head_hexsha": "f0478fd3fdf10c85257b2dbaff86761b020ddd36", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "conclusion-writing/module/experiment-2.tex", "max_issues_repo_name": "suryanshshukla10/MSPS-practical", "max_issues_repo_head_hexsha": "f0478fd3fdf10c85257b2dbaff86761b020ddd36", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conclusion-writing/module/experiment-2.tex", "max_forks_repo_name": "suryanshshukla10/MSPS-practical", "max_forks_repo_head_hexsha": "f0478fd3fdf10c85257b2dbaff86761b020ddd36", "max_forks_repo_licenses": ["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.5185185185, "max_line_length": 145, "alphanum_fraction": 0.7466874513, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6470626768811475}}
{"text": "\\newpage\n\\subsection{A Full Example}\n\\label{subsec:compss_example}\nThis section intends to give the reader a more or less extensive insight on what writing a COMPSs application is. We think that this section may help to \\textit{materialize} concepts and will avoid to give this document an excessively abstract tone.\\\\\n\\\\\nLets suppose that we want to approximate the value of $\\pi$. For this purpose we have thought on a simple, randomized algorithm:\n\\begin{enumerate}\n\\item Generate $N$ random 2D points with coordinates between $-1$ and $1$\n\\item Consider the set of points $S$ within distance $1$ or less to the origin\n\\item Assume that $\\frac{|S|}{N} = \\frac{\\pi}{4}$\n\\end{enumerate}\n\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[scale=0.5]{figures/circle_square.png}\n\\caption{A graphical representation of the random experiment. The square has side length $2$, so the circle has radius $1$, and therefore area $\\pi$. In ratio terms, $\\frac{\\pi}{4}$ of the points belong to the circle}\n\\label{fig:circle_square}\n\\end{figure}\n\nA more graphical explanation on why this works can be found in figure \\ref{fig:circle_square}.\\\\\n\\\\\nWe know a little bit of Python, so we have decided to implement this program in it. Basically, our small application will consist of a \\verb|test_random_point| function that generates a random point and return $1$ if this point lies inside our circle, and $0$ otherwise. We will call this function $N$ times, and consider the proportion $\\frac{|S|}{N}$ to be equal to $\\frac{\\pi}{4}$.\n\\inputminted{python}{applications/PI_SQUARE/sequential.py}\nThis code can be straightforward \\textit{optimized} by transforming the \\verb|test_random_point| function into a COMPSs task and syncing the results in the main procedure.\n\\inputminted{python}{applications/PI_SQUARE/pycompss_naive.py}\nAlthough this may be a good approach to \\textit{parallelize} this application we must note that we want to make it run in a distributed environment. The main difference we can appreciate is that a COMPSs task may run in a different machine than the master code, so some coordination between two processes in different machines and the transfer of potentially big amounts of data are necessary. In other words, the tradeoff between task granularity and performance is much more punishing in distributed computing than in single-machine parallel cases.\\\\\n\\\\\nAnother important thing to note is that a distributed application can still exploit lower level parallelism in each of its tasks. In our case, we can transform our \\verb|test_random_point| function into a \\verb|test_random_points| procedure that generates and tests various random points at the same time.\n\n\\inputminted{python}{applications/PI_SQUARE/pycompss_vectorized.py}\n\nThis last approach is what we consider a well \\textit{COMPSsfied} application: it has a reasonable task count and granularity, and it exploits various levels of parallelism at the same time. This application also delegates most of the work to \\verb|numpy| procedures, which are mainly written in C++ and OpenMP. This aspect is also important in PyCOMPSs, as Python is, by nature, a very slow programming language and it should be only used as an orchestrator.\n\nCOMPSs is mainly designed to run in HPC environments. Most HPC machines integrate some sort of queue system to manage its resources among all the demanding users. Our previous example can be run as a job in a queue system with the following command:\n\n\\inputminted{bash}{applications/PI_SQUARE/run_mn4.sh}\n\nThe \\verb|enqueue_compss| command refers to a generic queueing script (see section \\ref{subsec:hpc_queues}) which translates our request to enqueue this COMPSs job to a specific queue system. Some of the most common parameters of a COMPSs job can be found in table \\ref{table:compss_queue_param}.\\\\\n\\\\\n\\begin{table}[ht!]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\nArgument name   & Description                                                                           \\\\ \\hline\n\\verb|exec_time|      & Job time limit                                                                        \\\\ \\hline\n\\verb|num_nodes|      & \\begin{tabular}[c]{@{}l@{}}Number of computing\\\\ nodes\\end{tabular}                   \\\\ \\hline\n\\verb|cpus_per_node| & \\begin{tabular}[c]{@{}l@{}}Number of cores per\\\\ computing node\\end{tabular}          \\\\ \\hline\n\\verb|constraints|     & \\begin{tabular}[c]{@{}l@{}}Additional constraints\\\\ (e.g: highmem nodes)\\end{tabular} \\\\ \\hline\n\\end{tabular}\n\\caption{Some example configuration parameters of the queue system. These parameters are usually passed as flags to the enqueue\\_compss script.}\n\\label{table:compss_queue_param}\n\\end{table}\n", "meta": {"hexsha": "49d64f1b11a3a2790300144916c428c9eede3a3c", "size": 4671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compss_example.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": "compss_example.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": "compss_example.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": 88.1320754717, "max_line_length": 552, "alphanum_fraction": 0.7488760437, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737916455819, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6470626636439878}}
{"text": "\\section{Background and Notation} \\label{background_and_notation}\n\nThis section gives more background on the sliding window technique \\cite{keogh2004sliding}, DTW distance measure \\cite{keogh2002exact}, and time series normalization \\cite{das1998rule}, which are fundamental building blocks of our conducted online gesture recognition study \\cite{lesti2017filter}. Table \\ref{tab:notation} introduces the notation that we use for formal problem description.\n\n\\begin{table}\n    \\begin{center}\n        \\begin{tabularx}{\\textwidth}{c X}\n            \\hline\n            \\textbf{Symbol} \\qquad & \\textbf{Description}\\\\\n            \\hline\n            $Q$ & a time series of size $n$ with $Q = (q_1, q_2, \\dots, q_i, \\dots, q_n)$\\\\\n            $Q[i,j]$ & a subsequence time series of $Q$ with $Q[i,j] = (q_i, q_{i+1}, \\dots, q_{j})$\\\\\n            $t$ & the current time\\\\\n            $\\mu$ & the mean of a time series $Q$\\\\\n            $\\sigma$ & the standard deviation of a time series $Q$\\\\\n            $\\eta$, $z$  & two different time series normalizations\\\\\n            \\hline\n        \\end{tabularx}\n    \\end{center}\n    \\caption{Notation used for formal problem description.}\n\t\\label{tab:notation}\n\\end{table}\n\n\\input{background_and_notation/sliding_window_technique.tex}\n\\input{background_and_notation/dynamic_time_warping.tex}\n", "meta": {"hexsha": "ba26be82198c030a820ba1424c79040cc61e10d4", "size": 1327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background_and_notation.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": "paper/background_and_notation.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": "paper/background_and_notation.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": 51.0384615385, "max_line_length": 390, "alphanum_fraction": 0.6639035418, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.647062654297234}}
{"text": "\\section{Relevant Background}\n\n\\subsection{Agda Introduction}\nAgda is a dependently typed functional language developed by Norell at the Chalmers University of Technology\nas his Ph.D. Thesis.\nThe current version of Agda is Agda 2.\n\n  \\subsubsection{Syntax}\n  In Agda, \\emph{Set} is equal to type.\n  In languages with dependent types, it is possible to create a function that returns a type.\n\n  \\agda{agdaExamples}{funcType}\n\n  After the function name, it is two colons (\\emph{:}) and the arguments of the function.\n  It is closed by \\emph{(name\\_of\\_argument : type\\_of\\_argument)}.\n  After all, there is one arrow and the type of the result of the function.\n  This ``if, then, else'' is not a function built-in in Agda.\n  It is a function defined this way \\emph{if\\_then\\_else\\_} .\n\n  So it is possible to use this function in the default way.\n\n  \\agda{agdaExamples}{funcTypeUnd}\n\n  Or use the arguments inside the underscore.\n\n  \\agda{agdaExamples}{funcType2}\n\n  The same notation can be done using just arrows without naming the arguments.\n\n  Because of dependent types, it is possible to have a type that depends on the input.\n\n  \\agda{agdaExamples}{dependentType}\n\n  It is possible in Agda to do the pattern match.\n  So it breaks the input in cases.\n\n  \\agda{agdaExamples}{patternMatch}\n\n  To create a new type with a different pattern match, it is used the data constructor.\n\n  \\agda{agdaExamples}{dataConstructor}\n\n  This is another example of \\emph{Data Set}, but it depends on the argument.\n\n  \\agda{agdaExamples}{vector}\n\n  \\emph{Vector zero} is a type of a vector of size zero, so the only option to construct it is the empty vector.\n  It is constructed from the first constructor.\n  Other types of vectors like \\emph{Vector 1} (vector of size one), \\emph{Vector 2}, ... can only be constructed by\n  the second constructor.\n  It takes as argument a natural number and a vector and returns a vector with the size of the last vector\n  plus one.\n\n  Records are data types with just one case of pattern match.\n\n  \\agda{agdaExamples}{record}\n\n  The constructor is the name of the data constructor.\n\n  \\hyperref[id]{Implicit terms} are elements that the compiler is smart enough to deduce it.\n  So it is not necessary to put it as an argument of the function.\n\n  \\plabel{id}\n  \\agda{agdaExamples}{id}\n\n  Implicit arguments are inside \\emph{\\{\\}}.\n  In this example, the name of the Set (\\emph{A}) can not be omitted\n  (like the second function version of boolean to set),\n  because it is used to say that \\emph{x} is of type \\emph{A}.\n\n  In the case of the function \\emph{id}, the type of input can be deduced by the compiler.\n  For example, \\emph{id} function should be a function from Natural to Natural because\n  \\emph{zeroN} is already of type Natural.\n  In this example, the compiler could figure out the term \\emph{A} (Natural) of type \\emph{Set}.\n\n  \\agda{agdaExamples}{idNat}\n\n  Functions in Agda can be defined in two ways\n\n  \\agda{agdaExamples}{funcs}\n\n  In the first case, the arguments are before equal sign (\\emph{=}).\n  In the second case, it is used the lambda abstraction that means the same thing.\n\n  \\agda{agdaExamples}{caseOf}\n\n  \\agda{agdaExamples}{filter}\n\n  Filter is a function that filters all elements that have some property already defined.\n  In this definition of filter, the lambda abstraction can pattern match\n  in the two possibilities of \\emph{p x}, that are \\emph{true} or \\emph{false}\n\n  \\agda{agdaExamples}{filterWith}\n\n  The \\emph{with} abstraction is the same thing as the \\emph{case of}.\n  Before the \\emph{=}, there are the possibilities of \\emph{p x} (\\emph{true} or \\emph{false}).\n\n  \\agda{agdaExamples}{postulate}\n\n  In Agda, the \\emph{postulate} assumes that there is one element of a given type without defining it.\n  In this example, \\emph{someBot} is an element of the empty type.\n  Postulate can be dangerous because it assumes that some element of a given type exists,\n  but it can not (like in the example).\n\n  \\agda{agdaExamples}{rewrite}\n\n  In Agda, \\emph{rewrite} means changing the returned type of the result.\n  Because $a + b ≡ b + a$, returning an element of the type $P (a + b)$ is the\n  same thing that returning an element of the type $P (b + a)$.\n\n  \\subsubsection{Lambda Calculus}\n  Lambda Calculus is a minimalist Turing complete programming language with the concept of abstraction,\n  application using binding and substitution. For example, \\emph{x} is a variable, $(\\lambda x.M)$\n  is an Abstraction and (\\emph{M N}) is an Application.\n\n  In Lambda Calculus, there are two types of computational conversions $\\alpha$-conversion\n  and $\\beta$-reduction.\n  In $\\alpha$-conversion, $(\\lambda x.M[x]) \\rightarrow (\\lambda y.M[y])$.\n  So in every free variable \\emph{x} in \\emph{M} will be renamed to \\emph{y}.\n  For \\emph{M[x] = x}, an $\\alpha$-conversion is $(\\lambda x.x) \\rightarrow (\\lambda y.y)$\n\n  A free variable is every variable that is not bound outside.\n  For example, $((\\lambda\\textcolor{green}{x}.\\textcolor{blue}{x}) \\textcolor{red}{x})$.\n  The \\textcolor{blue}{blue x} is bonded for the \\textcolor{green}{green x},\n  but the \\textcolor{red}{red x}\n  is not bonded for any function. So the \\textcolor{red}{red x} is a free variable.\n\n  In $\\beta$-reduction, it replaces the all free for the expression in the application.\n  The $\\beta$-reduction of this expression $((\\lambda x.M) N) \\rightarrow (M[x := N])$ .\n  So if $M = x$, the $\\beta$-reduction will be $((\\lambda x.x) N) \\rightarrow N$.\n  If $M = (\\lambda x.x) x$, the $\\beta$-reduction will be\n  $(\\lambda x.((\\lambda x.x)x))N \\rightarrow (\\lambda x.x)N$.\n\n  Agda uses typed lambda calculus.\n  So in an application \\emph{(M N)}, \\emph{M} has to be of type $A \\Rightarrow B$ and N has to be of type A.\n  $(\\lambda (x : A) . x)$ is of type $A \\Rightarrow A$, because \\emph{x} is of type \\emph{A}.\n\n  \\agda{lambdaCalculus}{Id}\n  The simplest function is the identity function made in Agda.\n\n  \\plabel{id2}\n  \\agda{lambdaCalculus}{Id2}\n  \\hyperref[id2]{This} is another way of writing the same function.\n\n  \\plabel{truefalse}\n  \\agda{lambdaCalculus}{trueFalse}\n  \\hyperref[truefalse]{This} is how true and false are encoded in lambda calculus.\n\n  \\plabel{naturals}\n  \\agda{lambdaCalculus}{naturals}\n  \\hyperref[naturals]{This} is how naturals numbers are defined in lambda calculus.\n  Look that the definition of zero looks like the definition of false.\n\n  \\agda{lambdaCalculus}{isZero}\n  Defining natural numbers in this way, it is possible to say if a natural number is zero or not.\n\n  \\agda{lambdaCalculus}{plus}\n  Plus is defined this way using lambda calculus.\n\n  \\plabel{onepone}\n  \\agda{lambdaCalculus}{onePone}\n  \\hyperref[onepone]{This} is one example of the calculation of one plus one in Lambda Calculus.\n\n  \\plabel{list}\n  \\agda{lambdaCalculus}{list}\n  \\hyperref[list]{This} is how lists are defined in Lambda Calculus.\n\n  \\agda{lambdaCalculus}{sumList}\n  Substituting the cons operation of list per plus and nil list to zero, it is possible to calculate\n  the sum of the list.\n\n  \\agda{lambdaCalculus}{either}\n  In this way, it is possible to define \\emph{Either}.\n  It is one way to create a type that can be a Natural or a Boolean.\n\n  \\agda{lambdaCalculus}{eitherExamples}\n  In these examples, it is defined zero, one in left and false, true in right.\n\n  \\agda{lambdaCalculus}{eitherRes}\n  \\emph{Either} is useful when defining one function that works for left and another that works for the right.\n  If the natural number is zero, the function chosen is the left and\n  if it is an identity, the function chosen is the right. \n\n  \\plabel{tuple}\n  \\agda{lambdaCalculus}{tuple}\n  \\hyperref[tuple]{This way} is how tuple is defined in Lambda Calculus.\n\n  \\plabel{tupleexamples}\n  \\agda{lambdaCalculus}{tupleExamples}\n  \\hyperref[tupleexamples]{This} is how is defined the tuple zero false and the tuple one true.\n\n  \\plabel{tupleadd}\n  \\agda{lambdaCalculus}{tupleAdd}\n  \\hyperref[tupleadd]{This} is one way of defining a function that adds one to the argument\n  if the first element of the tuple is true.\n\n\n  \\subsubsection{Martin-Löf Type Theory}\n  Agda also provides proof assistants based on the intentional Martin-Löf type theory.\n\n    In Martin-Löf type theory, there are three finite types and five constructors types.\n    The zero type contains zero terms. It is called the empty type and it is written $\\bot$.\n    \\agda{agdaExamples}{botType}\n\n    The first type is the type with just one canonical term and it represents existence.\n    It is called unit type and it is written top.\n    \\agda{agdaExamples}{trivialType}\n\n    The second type contains two canonical terms. It represents a choice between two values.\n    \\agda{agdaExamples}{eitherType}\n\n    The Boolean type is defined using the Trivial type and the Either type.\n    \\agda{agdaExamples}{boolType}\n\n    If statement is defined using booleans.\n    \\agda{agdaExamples}{ifThenElse}\n\n\n    \\subsubsection{Types Constructors}\n    The product-types contain an ordered pair.\n    The second type can depend on the first type.\n    \\agda{agdaExamples}{mulType}\n\n    \\agda{agdaExamples}{mulEx}\n    In the function $\\exists-vec$, the product-type has the same meaning of exists.\n    This type means that\n    ``Exists a natural number \\emph{n} that there is one element of type \\emph{Vector A n}''\n\n    The $\\pi$-types contain functions.\n    So given an input type, it will return an output type.\n    It has the same meaning as a function:\n    \\agda{agdaExamples}{piType}\n\n    In Inductive types, it is a self-referential type.\n    Naturals numbers are examples of that:\n    \\agda{agdaExamples}{Nat}\n    Other data structures like a linked list of natural numbers, trees, graphs are inductive types too.\n\n    Proofs in inductive types are made by induction.\n    \\agda{agdaExamples}{NatElim}\n\n    Universe types are created to allow proofs written in all types.\n    For example, the type of \\emph{Nat} is \\emph{U0}.\n\n\nAgda has dependent types like in CoQ but does not have tactics.\nAgda is a total language, so it is guaranteed that the code always finish\n(impossible infinite loops) and coverage all inputs.\n\nAgda has inductive data types that are similar to algebraic data types in non-dependently\ntyped programming languages.\nThe definition of Peano numbers in Agda is:\n\n\\agda{agdaExamples}{Nat}\n\nDefinitions in Agda are done using induction.\nFor example, the sum of two numbers in Agda:\n\n\\agda{agdaExamples}{sum}\n\nIn Agda, because of dependent types, it is possible to make more expressive types that are not\npossible in other languages.\nFor example, get the first element of a vector.\nFor it, it is necessary to specify in the type that the vector should have a size greater than zero.\n\n\\agda{agdaExamples}{vecHead}\n\nAnother good example is that in the sum of two matrices, they should have the same dimensions.\n\n\\agda{agdaExamples}{matrixSum}\n\n\\subsubsection{Preposition as Types}\n\nIn Agda, types can be seen as prepositions and terms of this given type like a proof.\nFor example, \\emph{x} can be a term of the type \\emph{A}.\nSo \\emph{x} is a proof that \\emph{A} holds.\n\n\\agda{agdaExamples}{id}\n\nIn the function \\emph{id},\nif there is a proof \\emph{x} that \\emph{A} holds,\nso \\emph{A} holds.\nThe function \\emph{id} is a proof of $A \\rightarrow A$.\n\n\\agda{agdaExamples}{and}\n\nIn the function \\emph{and}, \\emph{a} is a proof that \\emph{A} holds and\n\\emph{b} is a proof that \\emph{B} holds,\nso \\emph{a , b} is a proof of $A \\times B$\n\n\\agda{agdaExamples}{equality}\n\nEquality function can be seen as\n``For all elements of \\emph{x} in the Set \\emph{A}, $x \\equiv x$''.\nIf there is a term of this type, so this preposition is true.\nIn this case, the term is a function that given a term \\emph{x} of type \\emph{A},\nit returns \\emph{refl \\{\\_\\} \\{\\_\\} \\{x\\}}.\n\\emph{refl} is a constructor of equality, so \\emph{refl \\{\\_\\} \\{\\_\\} \\{x\\}}\nreturns a term of type $x \\equiv x$.\n\n\\subsection{Bitcoin Overview}\n\nThe Bitcoin was made to be a peer to peer electronic cash.\nIt was made in one way that users can save and verify transactions without the need of a trusted party.\nBecause of that no authority or government can shut down the Bitcoin.\n\n\\incimg{transactions1}{png}{Transaction}\n%% https://medium.com/coinmonks/bitcoin-transactions-be401b48afe6\n\nTransactions in Bitcoins (like in \\figref{transactions1}) are an array of input of\nprevious transactions and an array of outputs.\nEach input and output is an address, each address is made from a public key\nthat is made from a private key.\n\n\\incimg{privatekey}{png}{Bitcoin account}\n%% https://coinsutra.com/bitcoin-private-key/\n\nA private key is a big number.\nIt is so big that it is almost impossible to generate two identical private keys.\n\nThe public key is generated from the private key\n(like in \\figref{privatekey} where the account number is f(p)),\nbut a private key can not be generated from a public key.\n\nIn Bitcoin, the miner is someone that calculates a value \\emph{nounce} for each block.\nBecause of that, he receives all transaction fees of this block plus a block reward.\nThe mining transaction (made for the miner) does require an input.\nFor each input transaction, it is necessary a signature signed with a private key\n(like in \\figref{privatekey} where the signature is f(p,t))\nto prove the ownership of the Bitcoins.\nWith the message and the signature, it is possible to know that the owner of the private key\nthat generates the public key signed the message.\n\nSignature is created from a function that receives as inputs the private key and the message.\nThere is no analytical form of the inverse of this function.\nBecause of that, the only way of finding an element \\emph{x} that this function \\emph{f} so\nthat $f(x) = y$ for a given \\emph{y} is trying for random different values of \\emph{x}.\nSo it is almost impossible to find the private key from a message, a signature, and the public key.\nIn \\figref{privatekey}, the checker is a f(t,s,a).\nSo because of that, the owner of the private key can sign several messages without anyone knows\nhis private key.\n\n\\incimg{transactions2}{jpg}{Verification and signature of transactions}\n%% https://en.wikipedia.org/wiki/Bitcoin_network\n\nTransactions (shown in \\figref{transactions2}) are grouped in a block (shown in \\figref{blockchain}).\nEach block contains in its header the timestamp of its creation, the hash of the block,\nthe previous hash and a nonce.\nA nonce is an arbitrary value that the miner has to choose to make the hash of the block respect some\nspecific characteristics.\n\n\\incimg{blockchain}{png}{Blockchain}\n%% https://bitcoin.stackexchange.com/questions/12427/can-someone-explain-how-the-bitcoin-blockchain-works/13347\n%% https://i.stack.imgur.com/HrKX0.png\n\nEach block has a size limit of 1 MB.\nBecause of that, Bitcoin forms a blockchain (a chain of blocks).\nEach block should be created at an average of 10 minutes.\nThe advantage of using a short average time of block creation is that it will propagate transactions\nfaster in the blockchain.\nBut the disadvantage is that it increases the probability of creating orphan blocks.\nTo make the blockchain tamper-proof (nobody can alter an existing block),\nthere is a concept called proof of work in Bitcoin.\nTo create a new block, the creator (called the miner) has to choose a random value as nonce that makes\nthe hash of the block less than a certain value.\nThis value is chosen in a way that each block should be generated on 10 minutes on average.\nIf the value is for example 100 and the total possibilities of results are 10.000 (codomain),\nthe probability of finding \\emph{x} so that $hash(x) \\leqslant 100$ is 1\\% $100/10.000$.\nBecause of that, in this example, the miner has to calculate on average 100 hashes before finding\nthe right one.\n\nIf the value is too low, miners will take more time to find a nonce that makes the hash block\nless than it.\nIf it is too high, it will be easier to find a nonce and they will find it faster.\n\nWhen two different blocks are created in nearly the same time, there are two valid blockchains.\nIt is because the last block in both blockchains are valid but different.\nBecause of this problem, in the Bitcoin protocol, the largest chain is always the right chain.\nWhile two valid chains have the same size, it is not possible to know which chain is the right.\nThis situation is called fork and when it happens, it is necessary to wait to see in which chain\nthe new block will be.\n\nIf miners have more than 50\\% of the hash rates of Bitcoin, they can do an attack called a\n51\\% attack.\nIt happens when some miner, with more power than all network, mine secretly the blocks.\nSo if the main network has 50 blocks, the miner could produce hidden blocks from 46 to 55\nand he would have 10 hidden blocks from the network.\nWhen he shows their hidden blocks, his chain becomes the valid chain, because it is bigger.\nSo all transactions from the previous blockchain from 46 to 50 blocks become invalid.\nBecause of that, when someone makes a big transaction in the blockchain, it is a good idea\nto wait more time.\nSo it is becoming harder and harder to make a 51\\% with more time.\nBitcoin has the highest market value nowadays, so attacking the Bitcoin network is very expensive.\nNowadays, this kind of attack is more common in new altcoins.\n\nLedger is a software that tracks how much money each address can spend.\nIt can be known when calculating the sum amount of all unspent output transactions destined\nfor each address.\n\nThe \\gls{utxo} model used in Bitcoin and the account model used in Ethereum are the two most used kinds\nof data structures to model account records and savings states.\n\nIn the account model, it is saved the address and the balance of each address.\nFor example, the data structure will look like this [(0xabc01, 1.01), (0xabc02, 2.02)].\nSo the address 0xabc01 has 1.01a of balance and the address 0xabc02 has 2.02 of balance.\nIn this way, it is possible to easily know how much balance each address has,\nbut it is not possible to know how they got in this state.\n\n  \\incimg{utxo}{png}{UTXO transactions}\n  %% https://bitcoin.org/\n  %% https://medium.com/@sunflora98/utxo-vs-account-balance-model-5e6470f4e0cf\n\nIn the \\gls{utxo} model (shown in \\figref{utxo}), each transaction is saved in the transaction tree.\nEvery transaction is composed of multiples inputs and multiples outputs.\nBut all inputs have to come from outputs that have never been spent before.\n\nBecause of that, in the \\gls{utxo} model, it is easy to make a new transaction from the previous one,\nbut it is harder to know how much each one has.\nTo know how much someone has, it is necessary to calculate the sum of all unspent transaction outputs\ndestined for his addresses.\n\nIn the account model, there could be one kind of vulnerability\nthat is less probable to happen in the \\gls{utxo} model.\nChanging both addresses balances is not an atomic operation.\nBecause there are two instructions, subtracting the balance of the sender\nand incrementing the balance of the receiver.\nIf something bad happens between these two instructions, the final state\nwill become an invalid state.\n\nFor example: \\\\\n\\textbf{\nbobBalance -= 1 \\\\\nIntermediary State \\\\\naliceBalance += 1\n}\n\nIn the account model, it is straight forward to know how much balance each address has.\nIn the \\gls{utxo} model, this calculation is made off-chain. It can be a good thing\nbecause each user has more privacy.\n\n\\subsection{Ethereum}\n\nEthereum differs from Bitcoin in having an \\gls{evm} to run script code.\n\\gls{evm} is a stack machine and Turing complete \\cite{turing1936computable} while Bitcoin Script is not\n(it is impossible to do loops and recursion in Bitcoin).\n\nTransactions in Bitcoin are all stored in the blockchain.\nIn Ethereum, just the hash of it is stored in it.\nSo it is saved in the off-chain database.\nBecause of that, it is possible to save more information in Ethereum Blockchain.\n\nContracts in the blockchain are the script program that comes with the transaction.\nIn Bitcoin, the creator of the contract has to pay the amount proportional to its size.\nIn Ethereum, it is different.\nEach smart contract in Ethereum is made by a series of instructions.\nEach instruction consumes different the computational effort.\nBecause of that, in Ethereum, there is a concept of gas, that measure how much computational effort\neach instruction needs.\nSo in each smart contract, it is well know how much computational effort will be necessary to run it\nand it is measured in gas.\nBecause computational effort of each node in the Ethereum network is a scarce resource,\nto execute the smart contract, it is necessary to\npay an amount in ether for each gas to the miner run it.\nSmart contracts that pay more ether per gas run first because the miner will want to have the best\nprofit and they will pick them.\nIf the amount of ether per gas paid is not high enough, the contract will not be executed,\nbecause some other contracts pay more that will be executed instead of this one.\n\nBecause Ethereum has its \\gls{evm} with more instructions than Bitcoin and it is Turing Complete,\nit is considered less secure.\nEthereum has its high-level programming language called Solidity that looks like JavaScript.\n", "meta": {"hexsha": "b6d04ac667836fa3679899518a0daf524b536c09", "size": 21176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/relevantbackground.tex", "max_stars_repo_name": "guilhermehas/crypto-agda", "max_stars_repo_head_hexsha": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-02-13T16:56:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T19:27:12.000Z", "max_issues_repo_path": "docs/relevantbackground.tex", "max_issues_repo_name": "guilhermehas/crypto-agda", "max_issues_repo_head_hexsha": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-02-11T18:59:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-11T18:59:29.000Z", "max_forks_repo_path": "docs/relevantbackground.tex", "max_forks_repo_name": "guilhermehas/cripto-agda", "max_forks_repo_head_hexsha": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_forks_repo_licenses": ["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.8644067797, "max_line_length": 115, "alphanum_fraction": 0.7549112202, "num_tokens": 5441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.647062648603848}}
{"text": "\\section{Differential Rings and Modules}\nRecalling our definition of differential rings (an associative algebra with derivation Lie algebra) we wish to extend our set of notations.\n\\subsection{Differential modules and ideals}\n\\begin{defi}\nLet $(R,D)$ be a differential ring.\n\\bn\n\\item A differential module $(M,D_M)$ is an $R$-module with an additive map:\n$$D : M \\longrightarrow M,\\ r m \\longmapsto \\partial_R(r) m + r D(m)\\ \\forall D \\in D_M,\\ r \\in R,\\ m \\in M,$$\nwhere $\\partial_R \\in \\trm{Der}(R) = \\left<D\\right>$.\n\\item A differential ideal $I \\subset R$ is a differential $R$-submodule of $R$, i.e. $\\partial(I) \\subset I$ for all $\\partial \\in D$.\n\\item Let $(R,D_R)$ and $(S,D_S)$ be two differential rings. A ring homomorphism $f : R \\longrightarrow S$ is called differential if\n$$\\partial_S \\circ f = f \\circ \\partial_R$$\nor equivalently the following diagram commutes:\n$$\\xymatrix{\nR \\ar[d]_{\\partial_R} \\ar[r]^f & S\\ar[d]^{\\partial_S}\\\\\nR \\ar[r]_{f\\mid_{\\partial_R(R)}} & S.\\\\\n}$$\n%where $\\partial_X(X) := \\trm{im} \\partial_X$ for $X = R, S$.\n\\item A differential ring $(R,D)$ is called simple differential if it has no proper differential ideals.\n\\item A differential field is a differential ring with no proper ideals (differential or non-differential).\n\\item Let $(R,D)$ be a differential ring. The subset\n$$R^\\partial := \\{x \\in R : \\partial(x) = 0\\ \\forall \\partial \\in D\\}$$\ndefines a subring and is called the ring of constants.\n\\en\n\\index{Index}{module!differential}\n\\index{Index}{ring!differential}\n\\index{Index}{ring!differential!homomorphism of}\n\\index{Index}{ring!differential!simple}\n\\index{Index}{ring!differential! of constants}\n\\index{Index}{field!of constants}\n\\index{Symbol}{$\\trm{Der}_R(A)$}\n\\index{Symbol}{$R^\\partial$}\n\\end{defi}\n\\bmk As mentioned, the derivation maps $D$ on differential modules $(M,D_M)$ are only additive (are in general not in $\\trm{End}_R(M)$, but in $\\trm{End}_{R^\\partial}(M)$ - i.e. its ring of constants). This is due to the Leibniz-rule as defined above.\\\\\n\\indent The ring of constants $R^\\partial$ for a differential field $(R, D)$ is also a field, since:\n$$\\partial(a a^{-1}) = 0 = \\underbrace{\\partial(a)}_{=0} a^{-1} + a \\partial(a^{-1}) \\LRA a \\partial(a^{-1}) = 0$$\nholds for all $a \\in R^\\times$.\n\\bsp Some prominent examples:\n\\bn\n\\item any ring $R$ is a (trivial) differential ring, via $0 : R \\longrightarrow 0$. Thus, all $R$-modules are also differential modules via the zero-homomorphism.\n\\item The polynomial ring in one indeterminate:\n$$\\left(k[X], \\partial = \\frac{d}{dX}\\right),$$\n$k$ a field with characteristic zero, is a simple differential ring since all ideals $I$ generated by some polynomial of degree greater zero eventually fulfill $\\partial^i(I) = (1)$. On the other hand, $(k[X], \\partial = X \\frac{d}{dX})$ has non-trivial differential ideals:\n$$I_i = \\left<X^i\\right>,\\ \\forall i \\geq 1$$\nas each $k$-sub vector space $k.X^i$ is $\\partial$-stable.\n\\item Let $p \\in \\nz$ be a prime number, the polynomial ring $\\mathbb{F}_p[X]$ with $\\mathbb{F}_p$-derivation $\\partial = \\frac{d}{d X}$, as in the last example, has an interesting property. Its ring of constants is $\\mathbb{F}_p[X^p]$ as $\\partial(X^p) = p X^{p-1} = 0$ and this ring contains indeed non-trivial differential ideals (in contrast to characteristic zero fields):\n$$I_k := \\left<X^{p^k}\\right>,\\ k \\geq 1$$% : k \\geq 1\\right>,$$\nsince $\\partial(X^{p^k} f + X^{p^k} g) = \\partial(X^{p^k} f) + \\partial(X^{p^k} g) = X^{p^k} \\partial(f + g)$ for all $f, g \\in \\mathbb{F}_p[X]$.\n\\item The field of rational functions $k(X)$ is a differential field with derivation Lie algebra generated by\n$$D = \\left\\{\\partial'_x = \\left[\\frac{f}{g} \\mapsto \\frac{\\partial_x(f) g - f \\partial_x(g)}{g^2}\\right] : x \\in X\\right\\}.$$\n\\item Let $U \\subset \\rz^n$ be open and connected then $(C^\\infty(U),D=\\{\\partial_i : 1 \\leq i \\leq n\\})$ is a partial differential ring with a non-trivial differential ideal $\\mathfrak{m} := \\{f \\in C^\\infty(U) : \\trm{supp} (f) \\subsetneq U\\}$, as we may define a proper differential ideal for all $f \\in C^\\infty(U) \\bsl \\rz[\\{x\\}]$ by simply putting\n$$\\left<\\{f\\}\\right> = \\left<\\partial_{i_1} \\circ \\hdots \\circ \\partial_{i_k}(f) : 1\\leq i_j \\leq n,\\ k \\in \\nz_0\\right>,$$\nwhere $\\rz[\\{x\\}]$ denotes the ring of real convergent power series in $U$. These ideals are, in general, not finitely generated.\n\\en\n\\subsection{General Differential Algebra}\nLet $(k,D)$ be a differential ring with $D = \\{\\partial\\}$ and $k^\\partial$ its ring of constants.\n\\subsubsection{Ring of differential operators}\nIn terms of Ore extension, the subring $D := k[\\partial] \\subset \\trm{End}_{k^\\partial}(k)$ is isomorphic to the Ore-extension $k[X,id_k,\\partial]$ over $k$. To show this we depend on its intrinsic module algebra structure:\\\\\n$$\\Psi := \\Psi_{\\trm{int}} \\mid_{D \\otimes k.id_D} = \\left[d' \\longmapsto \\left[d \\longmapsto \\mu_D(d' \\otimes d) = d'(d)\\right]\\right],$$\nwhere $\\Psi_{\\trm{int}} : D \\otimes \\trm{End}_{k^\\partial}(D) \\longrightarrow \\trm{End}_{k^\\partial}(D)$, restricted to the subalgebra $k.id_D$.\n\\indent $k[\\partial]$ has the structure of a pointed-irreducible bialgebra, of Birkhoff-Witt type (only $1_{k[\\partial]}$ as group-like, generator $X \\in \\mathfrak{g}_{k^\\partial}(k)$ has primitive coproduct and $(k[\\partial],\\mu,\\eta)$ is isomorphic to the enveloping algebra of some Lie-algebra). Its structure map\n$$\\Psi : D \\otimes D \\longrightarrow D,\\ \\partial \\otimes a \\partial^i \\longmapsto \\partial(a) \\partial^i + a \\partial^{i+1}.$$\nTo see the isomorphism wrt. Ore-extensions, we consider the $k$-left module $k.\\partial^i$ with its above described $k$-right module structure:\n$$\\partial^i \\otimes a \\sim \\sum_{j=0}^i \\left(\\bao{c}i\\\\j\\\\\\ea\\right) \\partial^j(a) \\otimes \\partial^{i-j}$$\nHence, the ideal generators $1 \\otimes X \\otimes a - a \\otimes X \\otimes 1 - \\partial(a) \\in \\bigoplus_{n \\geq 0} (k \\otimes \\partial)^{\\otimes n} \\otimes k$, as in \\ref{prop03} on pg. \\pageref{prop03}, yield - evaluated via $id_k \\otimes \\Psi : k \\otimes D \\otimes k \\longrightarrow k \\otimes k \\simeq k$:\n$$id \\otimes \\Psi(1 \\otimes X \\otimes a - a \\otimes X \\otimes 1 - \\partial(a) \\otimes 1_D \\otimes 1_k) = X(a) - a X(1) - \\partial(a).$$\nIdentifying $X = \\partial$, we get indeed zero as desired. Hence, the quotient yields our desired Ore-extension $k[X,id_k,\\partial] \\simeq k[\\partial]$. There are more interesting properties for $k[\\partial]$ that are discussed in \\cite{vdPS01}, chapter 2, in greater detail.\\\\\n\\indent Concluding this subsection, we note that $k[\\partial]$ is a unital, associative, coassociative, cocommutative bialgebra (indeed, has an antipode, which will be discussed below) acting on $k$ via evaluation.\n\\subsubsection{Ring of differential polynomials}\\label{RingOfDiffPolys}\nAs above we are using a differential field $(k,\\partial)$, $k^\\partial$ its ring of constants and its ring of differential operators $k[\\partial]$ being generated by one element $\\partial$.%, pick some differential field $(k,\\partial)$ and\n We consider the ring of polynomials $R := k[u_1,\\ldots,u_n]$, i.e. a noetherian ring over $k$. In general, we have no unique extension of $\\partial$ to $R$ except for that of a trivial differential ring: $u_i \\longmapsto 0$ (enlarging the ring of constants to $R^\\partial[u_1,\\ldots,u_n]$). However, we may use a non-noetherian transcendental extension $S$ over $R$\n$$S := k[u_{i,j} : 1 \\leq i \\leq n, j \\in \\nz_0],$$ where $u_{i} \\longmapsto u_{i,0}$ defines an embedding of $R$ in $S$. Indeed, this ring still has no canonical $D = k[\\partial]$-module algebra structure. However, the module:\n$$D \\otimes_k S := D \\otimes_{k^\\partial} S/\\left<d \\otimes x s - \\sum_{(d)} d_{(1)}(x)d_{(2)} \\otimes s : x \\in k, d \\in D, s \\in S\\right>,$$\nwhere $\\Delta(d) = \\sum_{(d)} d_{(1)} \\otimes d_{(2)}$, has:\n$$\\partial^i \\otimes f_\\alpha u^\\alpha \\sim_\\partial \\sum_{j=0}^i\\left(\\bao{c}i\\\\j\\\\\\ea\\right) \\partial^j(f_\\alpha) \\partial^{i-j}\\otimes u^\\alpha.$$\nIts module algebra structure map $\\Psi : D \\otimes_k (D \\otimes_k S) \\longrightarrow D \\otimes_k S$ is given by the above equivalence relation. The ideal\n$$I := \\left<\\partial^{\\alpha_3} \\otimes u_{\\alpha_1,\\alpha_2} - \\partial^\\beta \\otimes u_{\\alpha_1,\\alpha_2 + \\alpha_3 - \\beta} : 1 \\leq \\alpha_1 \\leq n, \\alpha_2, \\alpha_3 \\in \\nz_0, 0 \\leq \\beta \\leq \\alpha_3 - 1\\right> \\subset D \\otimes_k S$$ gives us our desired:\n\\begin{defi}[Ring of differential polynomials]\nLet $S$ and $I$ be defined as above. The quotient ring $D \\otimes_k S/I$ is called the ring of differential polynomials and is denoted by:\n$$k\\left\\{u_1,\\ldots,u_n\\right\\} := D \\otimes_k S/I.$$\n\\end{defi}\n\\bmk %Firstly, we remark that if $\\partial u_{i,j} = u_{i,j+1} \\in K\\{u\\}$ then also \n%$$\\partial^l(u_{i,j}) = \\partial^{l-1}(u_{i,j+1}) = \\ldots = u_{i,j+l} \\in k\\{u\\}\\ \\forall 1 \\leq i \\leq n,\\ j \\geq 0,\\ l \\geq 1.$$\nSometimes we may use $u_i^{(j)}$ instead of $u_{i,j}$. Secondly, note that this, indeed, defines a (non-noetherian) differential ring, with derivations $\\{\\partial, \\partial_{u_{i,j}}\\}$. Here, $\\partial_{u_{i,j}}$ are $k$-derivations, while $\\partial$ is a $k^\\partial$-derivation. Additionally, we may still recover $R$:\n$$R \\simeq k\\{u_1,\\ldots,u_n\\}/J,\\ \\trm{where}\\ J := \\left<u_{i,1} - 1, u_{i,j} : 1 \\leq i \\leq n, j \\geq 2\\right> \\subset k\\{u_{i,j}\\}.$$\n\\indent The definition naturally translates to differential rings - if $(R,\\partial)$ is our differential ring, with ring of constants $R^\\partial$ and $D$-stable ideal $I$ as above, then\n$$R\\{u_1,\\ldots,u_n\\} := D \\otimes_k R[u_{i,j} : 1 \\leq i \\leq n, j \\geq 0]/I.$$\nAlthough being non-noetherian (any non-trivial differential ideal does not fulfill the ascending chain condition), the factor rings we will consider are in fact noetherian.\n\\begin{defi}\nLet $(k,\\partial)$ be a differential ring (field). An associative unital $k$-algebra $K$ is called a differential extension over $k$, short $K/k$, if there is an $n \\in \\nz$ and some differential ideal $I \\subset k\\{u_1\\ldots u_n\\}$ such that\n$$K \\simeq k\\{u_1\\ldots u_n\\}/I.$$\n\\index{Index}{extension!differential}\n\\end{defi}\n\\bmk Given a differential ring $(k,\\partial)$ and a finite family of differential polynomials $\\mathcal{F} \\subset k\\{u_1\\ldots u_{|\\mathcal{F}|}\\}$ the associated differential ideal $I$ is simply the differential saturation:\n$$I := \\left<\\partial^i(f) : f \\in \\mathcal{F},\\ i \\geq 0\\right>.$$\nSuch a family is called a differential equation - linear if the degree of all monomials is at most one, otherwise non-linear. We call it an explicit differential equation if each element in $\\mathcal{F}$ is linear with respect to $\\partial u_i$ and all coefficients of monomials of the form $\\prod_{i,j} \\partial^j u_i$ are zero, for $j \\geq 2$. Otherwise, it is called implicit.\n\\index{Index}{differential saturation}\n\\index{Index}{differential equation}\n\\index{Index}{differential equation!linear}\n\\index{Index}{differential equation!non-linear}\n\\index{Index}{differential equation!explicit}\n\\index{Index}{differential equation!implicit}\n\\begin{defi}\nLet $k\\{u_1,\\hdots,u_n\\} =: k\\{u\\}$ be the ring of differential polynomials over some differential field $k$, $k[\\partial]$ the left $k$-module of differential operators on $k\\{u\\}$. The map\n$$\\bao{rrcl}\nev &: k[\\partial] \\otimes_{k^\\partial} k\\{u\\} & \\longrightarrow &k\\{u\\}\\\\\n&&&\\\\\n& \\sum_{\\substack{0 \\leq i \\leq n\\\\\\alpha \\in \\nz_0^k\\\\k\\geq 0}} (a_i \\partial^i \\otimes b_\\alpha u_\\alpha) &\\longmapsto& \\sum_{\\substack{i,\\alpha\\\\k \\leq i}} \\left(\\bao{c}i\\\\k\\\\\\ea\\right) a_i \\partial^k(b_\\alpha) \\partial^{i-k}(u_\\alpha)\\\\\n\\ea$$\nis called the evaluation homomorphism.\n\\end{defi}\n\\bmk %The evaluation homomorphism gives us a $k[\\partial]$-module algebra structure on $k\\{u\\}$, where $(k[\\partial],\\mu,\\eta,\\Delta,\\eps)$ is the bialgebra structure on $k[\\partial]$ (infact, it has a Hopf-algebra structure via $S : k[\\partial] \\longrightarrow k[\\partial]$, $\\partial \\longmapsto -\\partial$.\nObviously, the definition $ev$ and $\\Psi$ are equal. Using this setting we get\n\\begin{koro}\nThe two-sided $k$-module $k[\\partial]$ defines (in general non-commutative if $k^\\partial \\neq k$) a unital $k$-algebra.\n\\end{koro}\n\\bws As $k$ is a unital commutative simple algebra over $k^\\partial$ and $k[\\partial]$ is a Ore-extension as shown above, there is nothing more to show.%Note that the map $\\mu : k[\\partial] \\otimes k[\\partial] \\longrightarrow k[\\partial], a \\partial^i \\otimes b \\partial^j \\longmapsto \\sum \\left(\\bao{c}i\\\\k\\\\\\ea\\right) a \\partial^k(b) \\partial^{i+j-k}$ defines a multiplication on the monomial terms of $k[\\partial]$. The unit is simply $\\eta : K \\longrightarrow K[\\partial], 1_k \\longmapsto 1_{k[\\partial]}$.\n\\bmk Moreover, $k[\\partial]$ has a $k^\\partial$-coalgebra structure:\n$$\\Delta =\\left[ \\partial^i \\longmapsto \\sum \\left(\\bao{c}i\\\\j\\\\\\ea\\right) \\partial^{i-j} \\otimes \\partial^j\\right],\\ \\eps = [\\partial^i \\longmapsto \\delta_{i,0}]$$\nmaking it to a $k^\\partial$-bialgebra as clearly: $\\eps \\eta = id_k$, $(\\eta \\otimes \\eta) \\circ \\eta = \\Delta \\eta = id_{k.1_{k[\\partial]} \\otimes k.1_{k[\\partial]}}$.% With $S := [\\partial^i \\longmapsto (-1) \\partial^i]$ we get an antipode since $\\mu((S\\otimes id)(1_k)) = \\mu((id_k \\otimes S)(1_k)) = \\eta(\\eps(1_k))$.\n\\begin{prop}\nThe following statements are equivalent:\n\\bn\n\\item\\label{item01} $k\\{u\\}$ is a $k[\\partial]$-module algebra (or $\\Psi := ev$ defines a module algebra structure on $k\\{u\\}$).\n\\item \\label{item02} Given the evaluation homomorphism and multiplication on $k[\\partial]$ then the following diagram commutes\n$$\\xymatrix{\nk[\\partial] \\otimes k[\\partial] \\otimes k\\{u\\} \\ar[r]^{\\mu \\otimes id_{k\\{u\\}}}\\ar[d]_{id_{k[\\partial]} \\otimes ev} & k[\\partial] \\otimes k\\{u\\}\\ar[d]^{ev}\\\\\nk[\\partial] \\otimes k\\{u\\} \\ar[r]_{ev} & k\\{u\\}\\\\\n}$$\n\\en\n\\end{prop}\n\\bws We show first, that the second statement is indeed true.\n\\bn\n\\item By simple computation on the monomial terms $a \\partial^i, b \\partial^j \\in k[\\partial]$ and $c u_\\alpha \\in k\\{u\\}$ we get\n{\\scriptsize\n$$\\bao{rcl}\nev(\\mu \\otimes id_{k\\{u\\}})(a \\partial^i \\otimes b \\partial^j \\otimes c u_\\alpha) &=& \\sum_{k' \\leq i} \\sum_{l' \\leq i + j - k'} \\left(\\bao{c}i\\\\k'\\ea\\right) \\left(\\bao{c}j + i - k'\\\\l'\\ea\\right) a \\partial^{k'}(b) \\partial^{l'}(c) \\partial^{j+i-k'-l'}(u_\\alpha)\\\\\n&&\\\\\nev(id_{k[\\partial]} \\otimes ev)(a \\partial^i \\otimes b \\partial^j \\otimes c u_\\alpha) &=& \\sum_{k \\leq i} \\sum_{l \\leq j} \\sum_{m \\leq i - k} \\left(\\bao{c}i\\\\k\\ea\\right) \\left(\\bao{c}j\\\\l\\ea\\right) \\left(\\bao{c}i - k\\\\m\\ea\\right) a \\partial^k(b) \\partial^{l+m}(c) \\partial^{j+i-k-l-m}(u_\\alpha)\\\\\n\\ea$$}\nFixing $l' \\leq j$ and putting $k = k'$ we see that our equivalence implies $$\\sum_{l + m = l'} \\left(\\bao{c}j\\\\l\\ea\\right) \\left(\\bao{c}i - k\\\\m\\ea\\right) a \\partial^k(b) \\partial^{l+m}(c) \\partial^{j+i-k-l-m}(u_\\alpha) = \\left(\\bao{c}j + i - k\\\\l + m\\\\\\ea\\right) a \\partial^k(b) \\partial^{l + m}(c) \\partial^{j + i - l - m - k}(u_\\alpha).$$\nSince the degree of the differential operators on each factor do agree, we get\n$$\\sum_{l + m = l'} \\left(\\bao{c}j\\\\l\\ea\\right) \\left(\\bao{c}i - k\\\\m\\ea\\right) = \\left(\\bao{c}j + i - k\\\\l + m\\\\\\ea\\right).$$\nBut this is just a rewriting of the Vandermonde identity for all $k \\leq i$ and proves our claim.\n\\item If $k\\{u\\}$ is a $k[\\partial]$ module algebra we have that $(x y) v = x(y v)$ for all $x, y \\in k[\\partial]$, $v \\in k\\{u\\}$. Expanding with our standard notation this translates into $ev(\\mu\\otimes id) = ev(id\\otimes ev)$ proving \\ref{item01} $\\RA$ \\ref{item02}.\\\\\nThe opposite direction follows immediately from the definition.\n\\en\n\\begin{koro}\\label{HopfModAlgDiffPoly}\nWith bialgebra structure maps $\\mu, \\eta, % = [1_k \\longmapsto 1_{k[\\partial]}], \n\\Delta$ and $ % = \\left[a \\partial^i \\longmapsto \\sum_{0 \\leq j \\leq i} \\left(\\bao{c}i\\\\j\\\\\\ea\\right) a \\partial^j \\otimes \\partial^{i - j}\\right], \n\\eps$ as defined above and the $k$-homomorphism\n% = [1_{k[\\partial]} \\longmapsto 1_k, a \\partial^i \\longmapsto 0],\n$$S : k[\\partial] \\longrightarrow k[\\partial],\\ \\partial^i \\longmapsto (-1)^i \\partial^i,$$\nwe have that $k\\{u\\}$ is a $k[\\partial]$-Hopf-module algebra.\n\\end{koro}\n\\bws Note that the generator $\\partial$ is a primitive cocommutative Hopf algebra element, i.e. $\\Delta(\\partial) = 1 \\otimes \\partial + \\partial \\otimes 1$ implying $S(\\partial) = - \\partial$. We simply have to show that the commutative diagram for Hopf-algebras does commute.\n$$\\partial^i \\stackrel{\\Delta}{\\longmapsto} \\sum_{j=0}^i\\left(\\bao{c}\ni\\\\\nj\\\\\n\\ea\\right) \\partial^j \\otimes \\partial^{i-j} \\stackrel{S \\otimes id}{\\longmapsto} \\sum_{j} \\left(\\bao{c}\ni\\\\\nj\\\\\n\\ea\\right) (-1)^j \\partial^j \\otimes \\partial^{i-j} \\stackrel{\\mu}{\\longmapsto} \\sum_j \\left(\\bao{c}\ni\\\\\nj\\\\\n\\ea\\right) (-1)^j \\partial^i.$$\nAccording to Pascals rule we see via induction that except for $i = 0$ all sums are zero. As $\\eta(\\eps(\\partial^i)) = \\delta_{i,0}$, we have just shown the required commutativity.\n%Hence, all elements $\\sum c_\\alpha u_\\alpha$ can be associated with some element of the form $\\sum \\left(\\bao{c} i\\\\j\\\\\\ea\\right) \\partial^j(b_\\alpha) \\partial^{i-j}(u_\\alpha)$ we get an (not necessarily unique) element such that for $\\rho = \\left[\\sum c_\\alpha u_\\alpha \\longmapsto \\sum \\left(\\bao{c}i\\\\j\\\\\\ea\\right) \\partial^j(b_\\alpha) \\otimes \\partial^{i-j}(u_\\alpha)\\right]$\n\\subsection{Linear Differential Equations}\nLet $(k,\\partial)$ be a (not necessarily non-trivial with characteristic zero) differential field with field of constants denoted by $k^\\partial$ and $M$ a noetherian differential module over $k$ (i.e. finite dimensional vector space, with derivation).\n\\begin{defi}\nA (scalar) linear differential equation is $k^\\partial$-linear map $L : M \\longrightarrow M$, with $L = \\sum a_i \\partial^i$, i.e. $L \\in k[\\partial] \\subset \\trm{End}_{k^\\partial}(k \\otimes_{k^\\partial} M)$. The solution space is the $k^\\partial$-subspace of $M$:\n$$S(L) := \\{x \\in M : L(x) = 0\\}.$$\n\\index{Index}{space!solution}\n\\index{Symbol}{$S(L)$}\n\\end{defi}\nAlternatively, one can define linear differential equations simply via linear algebra:\n$$\\partial(x) = A x,\\ A \\in \\trm{End}(M),\\ x \\in M.$$\nIts solution space is simply generated by the kernel elements of $\\partial - A$ in $M$. Hence, all differential extensions are generated by solutions over $k$. Now, an important definition:\n\\begin{defi}\nLet $K/k$ be a differential extension to the differential equation $\\partial(x) = Ax$.\n\\bn\n\\item we call a matrix $X \\in \\trm{Mat}_n(K)$ a solution matrix, if\n$$\\partial(X) = A X \\in \\trm{Mat}_n(K).$$\nIf $X = (x_{ij}) \\in \\trm{Mat}_n(K)$ is a solution matrix for the above differential equation we call the $n^2 \\times n^2$ matrix\n$$Wr(X) = \\left(\\partial^l(x_{ij})\\right)_{\\substack{0 \\leq l \\leq n^2-1\\\\1 \\leq i,j \\leq n}}$$\nthe Wronskian matrix. Its determinant is simply called Wronskian.\n\\item $K/k$ is called a differential extension (over $k$), if $K$ contains the solution space for some linear differential equation $\\partial(x) = A x$.\n\\en\n%A solution matrix in the general linear group $\\trm{Gl}_n(R)$ is called a fundamental matrix.\n\\index{Index}{matrix!solution}\n\\index{Index}{matrix!Wronskian}\n\\index{Index}{matrix!fundamental}\n\\index{Index}{Wronskian}\n\\end{defi}\n\\bmk As we already defined differential extensions via the ring of differential polynomials $k\\{u\\}$ (to be precise via differential quotient rings) we shall show both definitions are equivalent. But clearly, the family of differential polynomials is simply $\\mathcal{F} := \\{\\partial u_i - \\sum_j a_{i,j} u_j \\in k\\{u\\} : 1 \\leq i \\leq n\\}$ for a given differential equation $\\partial u = A u$.\\\\\n\\indent Secondly, we get the Wronskian matrix by constructing column vectors $$y_{ij} = \\left(x_{ij},\\partial(x_{ij}),\\ldots,\\partial^{n^2-1}(x_{ij})\\right)^t$$running over all indices $1 \\leq i,j \\leq n$. Furthermore, the definition of the Wronskian is broader - for some differential extension $R/k$ and elements\n$y_1, \\ldots, y_m \\in R$ the Wronskian matrix is simply $Wr(y_1,\\ldots,y_m) := (\\partial^l(y_i))_{1 \\leq i,l + 1 \\leq m}$.\n\\begin{defi}\nLet $K/k$ be a differential field extension for a given differential equation $\\partial y = A y$.\n\\bn\n\\item A Picard-Vessiot ring $R$ is a sub-ring of $K$, such that\n$R^\\partial = k^\\partial$, $R$ contains no non-trivial differential ideals and there exists a solution matrix $X \\in \\trm{Gl}_n(R)$.\n\\item A solution matrix in a PV-ring $R$ is called a fundamental matrix.\n\\item A Picard-Vessiot field is the localization of a Picard-Vessiot ring.\n\\en\n\\end{defi}\n\\index{Index}{extension!differential}\n\\index{Index}{extension!Picard-Vessiot}\n\\index{Index}{ring!Picard-Vessiot}\n\\index{Index}{field!Picard-Vessiot}\nThe last definition requires a little\n\\begin{lemm}\nA simple differential ring is zero-divisor free.\n\\end{lemm}\n\\bws Let $a \\in \\trm{Ann}(R)$, then there is a $b \\in \\trm{Ann}(R)\\bsl\\{0\\}$, s.t. $a b = 0$. We get $\\partial(a b) = 0 = \\partial(a) b + a \\partial(b) \\LRA \\partial(a) b = -a \\partial(b)$. Multiplying both sides with $b$ we have:\n$$\\partial(a) b^2 = -a b \\partial(b) = 0,$$\ni.e. $\\partial(a) \\in \\trm{Ann}(R)$. As the only proper differential ideal is zero, we see that $\\trm{Ann}(R)$ is trivial.\\\\\nNow, we have that indeed the localization of a Picard-Vessiot ring is well-defined in that sense that the localization is not the zero ring. Alternatively, we could define the Picard-Vessiot field extension $K/k$ as a field containing the solution space and having the same field of constants, i.e. $K^{\\partial} = k^{\\partial}$.\n\\newcommand{\\minpoly}[1]{\\trm{Min}(\\alpha,#1)}\n\\newcommand{\\minpolyC}{\\minpoly{k^\\partial}}\n\\newcommand{\\minpolyR}{\\minpoly{R}}\n\\begin{lemm}\nLet $(k,\\partial)$ be a differential field of characteristic zero and let $R$ be a differential subring of $k$\nwith the same field of constants, i.e. $R^\\partial = k^\\partial \\subset R \\subset k$.\n\\bn\n\\item If $\\alpha \\in R$ is algebraic over $k^\\partial$, i.e. $\\minpolyC \\in k^\\partial[X]$, with $k^\\partial(\\alpha) \\simeq k^\\partial[X]/\\left<\\minpolyC\\right>$, then $\\partial(\\alpha) = 0$.\n\\item If $\\alpha \\in k$ is algebraic over $R$ and $\\partial(\\alpha) = 0$, then $\\alpha$ is algebraic over $k^\\partial$.\n\\en\n\\end{lemm}\n\\bws Let $\\minpoly{S} = p = \\sum_{i=0}^n p_i X^i \\in S[X]$ for $S = R, k^\\partial$.\n\\bn\n\\item By definition, we have $p \\in k^\\partial[X]$. Hence, evaluating $p$ at $\\alpha$ in $R$ gives\n$$p(\\alpha) = \\sum_{i=0}^n p_i \\alpha^i = 0$$\nDifferentiating:\n$$\\partial(p(\\alpha)) = \\sum_{i=1}^n p_i \\partial(\\alpha^i) = \\sum_{i=1}^n i p_i \\partial(\\alpha) \\alpha^{i-1} = \\left(\\sum_{i=0}^{n-1} (i + 1) p_{i+1} \\alpha^i\\right) \\partial(\\alpha) = 0$$\nSince $p_n = 1$ we see that the left hand factor cannot be zero. On the other hand, $k^\\partial(\\alpha)$ is an integral domain. Hence, $\\partial(\\alpha) = 0$.\n\\item We interpret 'algebraic over $k$ as 'integral over $R$. Thus, there is a monic polynomial as defined above over $R$. Proceeding as in the last part (i.e. evaluating $p$ at $\\alpha$ in $R[\\alpha]$ and differentiating), we get\n$$\\partial(p(\\alpha)) = \\sum_{i=0}^{n-1} \\left(\\partial(p_{i}) + (i + 1) p_{i+1} \\partial(\\alpha)\\right) \\alpha^i + \\partial(p_n) \\alpha^n = 0.$$\nSince $p_n = 1$ we get\n$$\\partial(p_i) + \\underbrace{(i + 1) p_{i+1} \\partial(\\alpha)}_{=0} = 0$$\nfor all $i = 0,\\cdots,n - 1$. As $\\trm{char} R = 0$ implies $\\partial(p_i) = 0$ showing $p \\in k^\\partial[X]$.\n\\en\n\n\\begin{prop}\\label{PicardVessiotRing}\nLet $\\partial(x) = A x$, as above.\n\\bn\n\\item A Picard-Vessiot ring $R$ is isomorphic to\n$$k[x_{ij},1/\\det X],$$\nwhere $X = (x_{ij}) \\in \\trm{Gl}_k(M)$ is a fundamental matrix.\n\\item A matrix $X \\in \\trm{Mat}_n(R)$ is a fundamental matrix, if and only if its Wronskian is non-zero over $k^\\partial$.\n%\\item The entries of the largest sub matrix of the Wronskian matrix  $Wr(L) = \\left(x^{(k)}_{ij}\\right)_{\\substack{0 \\leq k \\leq n^2 - 1\\\\1 \\leq i, j \\leq n}}$ is a $C$-basis of the solution space, if and only if its Wronskian matrix has non-zero determinant. The associated fundamental matrix $X$ is spanned by this basis.\n\\item \\label{PVLemma3}Two fundamental matrices $X_1, X_2$ are right-associated wrt. $\\trm{Gl}_n(k^\\partial)$.\n\\item \\label{PVLemma4}Two PV-rings $R_1, R_2$ of the same equation are isomorphic as differential rings.\n\\en\n\\end{prop}\n\\bws A proof can be found in \\cite{vdPS01}, pg. 15. However, for the last two statements we are going to present a sketch of proof:\n\\bd\n\\item[ad \\ref{PVLemma3}] We have: $\\partial(X_{1,2}) = A X_{1,2}$ and assume: $X_2 = X_1 M$ for some $M \\in \\trm{Gl}_n(R)$. Then:\n$$\\partial(X_2) = \\partial(X_1 M) = \\partial(X_1) M + X_1\\partial(M) = A X_1 M + X_1 \\partial(M) \\stackrel{!}{=} A X_2 \\LRA M \\in \\trm{Gl}_n(k^\\partial).$$\nWe recall that $X_i \\in \\trm{Gl}_n(R)$ and the $X_1, X_2$ are left-associated if and only if $[M, A] = 0$.\n\\item[ad \\ref{PVLemma4}] Let $S(L)_i$ denote the two solution spaces. As we just saw, we may define an isomorphism of differential modules $\\phi : S(L)_1 \\longrightarrow S(L)_2, x_{ik} \\longmapsto \\sum_{j} x_{ij} m_{jk}$. As the PV-ring is commutative, we deem $\\trm{Sym}(S(L)_i)$ as an appropriate choice for construction (not necessarily the PV-ring, rather a subring). Now, we may extend $\\phi$ to both algebras:\n$$s = \\sum s_i x^i = \\sum s_i x_1^{i_1} \\ldots x_{n}^{i_n} \\longmapsto \\sum s_i \\phi(x_1)^{i_1} \\ldots \\phi(x_n)^{i_n}.$$\nSince $1_{S(L)_1} \\longmapsto 1_{S(L)_2}$ and $\\phi$ is an isomorphism on $\\trm{Sym}^1(S(L)_i)$ we get the desired isomorphism of differential rings. Localizing both algebras wrt. $\\det X_i$ we have that $R_i \\simeq S_{\\det X_i} (L)_i$ for $i = 1,2$.\n\\ed\n\\bmk $\\trm{Sym}(S(L)) \\simeq k[x_1,\\ldots,x_n]$ is not a simple differential ring (the maximal ideal $I = \\left<x_i : 1 \\leq i \\leq n\\right>$ is closed under $\\partial$-action). Nevertheless, its localization wrt. $\\det X = \\sum_{\\sigma \\in S_n} sign(\\sigma) \\prod_{i=1}^n x_{i,\\sigma(i)}$ is a simple differential ring, as $S_{\\det X}^{-1}I$ contains units ($S_{\\det X}^{-1}I = R$).\\\\\n\\indent In \\cite{vdPS01}, the following theorem is given (prop. 2.9, pg. 40 and lem 2.10, pg. 41):\n\\begin{satz}\nLet $\\partial(x) = A x$ be a linear differential equation. There are $L_i \\in k[\\partial]$, such that\n$$V_A := \\{y \\in M : \\partial(y) = A y\\} \\simeq \\bigoplus_{i=1}^n k[\\partial]/k[\\partial].L_i^*.$$\nTo specify, each matrix equation has a solution space $V_A$ isomorphic to the solution space of a scalar equation $L = \\prod L_i$.\n\\end{satz}\nThe decomposition is not unique wrt. left- and right-sidedness, as $k[\\partial]$ is in general not commutative. We are not going to prove this theoremo - only loosely scatching a proof.\\\\\nFirst we note, for any field $k$ and a matrix $A \\in \\trm{Mat}_n(k)$, there exists vectors $c_i \\in \\bigoplus_{i=0}^n k.e_i$ such that $B_i = \\left\\{c_i,...,A^{j_i} c_i : i\\right\\}$ is a $k$-basis. The elements $c_i$ are called cyclic vectors, each subspace $M_i$ generated by such an element is called a cyclic vector space and the transformed matrix wrt. to the cyclic basis is called the rational normal form of $A$. If $\\chi_A \\in k[X]$ is the charactistic polynomial of $A$ and $\\prod_{j = 1} p_j^{s_j}$ a prime decomposition of $\\chi_A$ than its minimal polynomial, which is the monic generator of $\\{f \\in k[X] : f(A) = 0\\}$, gives us all distinct cyclic vectors (each cyclic vectors space has different dimension $t_j \\deg p_j$, where $p_j^{t_j} \\mid m_A$ and $p_j^{t_j+1} \\nmid m_A$). A similar reasoning is provided in \\cite{vdPS01}, chapter 2. Here, a cyclic decomposition is given for any linear homogeneous differential equation.\n% due to the maximality of $I$: any differentially closed ideal containing $I$ is already $R = (1)$. To see that its ring of constants $R^\\partial = C$, consider $f = \\sum_{i} f_i x_1^{i_1} \\ldots x_n^{i_n}/\\det X^{i_{n+1}} \\in \\ker \\partial_R$:\n%$$\\partial(f) := \\sum_i \\partial(f_i) x^i/\\det X^{i_{n+1}} + \\sum_i i_k f_i x_1^{i_1} \\ldots \\partial(x_k) x_k^{i_k-1} \\ldots x_n^{i_n}/\\det X^{i_{n+1}}$$\n\\subsubsection{Differential Galois group}\nIn the theory of field extensions, the Galois group is the set of $k$-vector space automorphisms permuting the root elements of a given polynomial over $k$ leaving $k$ fixed. For a given linear differential equation, the definition is slightly different:\n\\begin{defi}\nLet $\\partial(x) = A x$ for some $A \\in \\trm{Gl}_k(M)$ and $x \\in M$. The differential Galois group is the zentralizer of $\\left<\\partial\\right> \\subset \\trm{Gl}_R(M)$, i.e.\n$$\\trm{DGal}(R/k) = \\{\\varphi \\in \\trm{Gl}_{k^\\partial}(M) : \\partial \\varphi = \\varphi \\partial\\}.$$\n\\index{Symbol}{$\\trm{DGal}(R/k)$}\n\\end{defi}\nThis property is also called equivariance (e.g. in algebraic geometry).\n%\\paragraph{Examples for the linear case}\n\\begin{satz}[Galois correspondence]\nLet $K/k$ be a PV extension for $\\partial(x) = A x$. Let $\\mathfrak{G}$ be the set of all closed subgroups of $G := \\trm{DGal}(K/k)$ and $\\mathcal{M}$ the set of all differential subfields $k \\subset M \\subset K$. In analogy to algebraic fields extension theory, we define \n$$\\bao{rrclrcl}\n\\trm{Fix} : &\\mathfrak{G} &\\longrightarrow& \\mathcal{M},& H &\\longmapsto& K^H := \\{x \\in K : \\sigma(x) = x\\ \\forall \\sigma \\in H\\}\\\\\n&&&&&\\\\\n\\trm{DGal} : & \\mathcal{M} &\\longrightarrow& \\mathfrak{G},& M &\\longmapsto& \\trm{DGal}(M/k),\\\\\n\\ea$$\nthen we have:\n\\bn\n\\item both functors are inverse to one another.\n\\item $H \\in \\mathfrak{G}$ is normal in $G$ if and only if for $M = K^H$:\n$$G(M) \\subset M,$$\ni.e. is $G$-invariant as a set ($g x \\in M$ for all $g \\in G$, $x \\in M$).\n\\item If $H \\in \\mathfrak{G}$ is normal then the canonical projection $G \\longrightarrow \\trm{DGal}(K^H/k)$ is surjective and has $H$ as kernel. Furthermore, $K^H$ is a PV extension for some linear differential equation over $k$.\n\\item Let $G^0 \\leq G$ be the connected component of identity, then $K^{G^0} = k$.\n\\en\n\\end{satz}\n\\bmk A proof is given in \\cite{vdPS01}. The connected component of identity is to be understood as follows. If $(G,m,e,\\tau)$ is a topological group, with $\\tau$ its topology, an open subset $U \\in \\tau$ is called connected if the only disjoint union of open subsets $U' \\cup U'' = U$ is trivial (i.e. $U' \\in \\{\\emptyset, U\\}$, $U'' = U\\bsl U'$). In this case, $U$ is also called a connected component. If furthermore, $1 \\in U$ is a subgroup, $U$ is called the connected component of identity which is denoted by $G^0$. These definitions were taken from \\cite{Milne}.\n\\bsp Some examples:\n\\bn\n\\item $(\\zz,+,0,\\mathcal{P}(\\zz))$ is a topological group wrt. discrete topology. Hence, all pointed subspaces are open subsets. Therefore, $\\{0\\} = \\zz^0$.\n\\item $(\\rz^\\times,\\cdot,1,\\tau_{\\trm{standard}})$ is a topological group with connected components: $\\rz_{>0}, \\rz_{<0}$. Hence, $\\rz_{>0} = \\left(\\rz^{\\times}\\right)^0$.\n\\en\n\\subsection{Example}\nNow, let us consider two simple examples.\n\\subsubsection{1-dim case}\nLet $k = \\currfield(z)$ with $\\currfield$-derivation $\\partial = \\frac{d}{d z}$, as well as $a \\neq 0$ and $\\partial(x) = ax$. Here, we have a 1-dimensional differential equation, i.e. the solution space is a 1-dim $\\currfield$-vector space. Let us compute the\n\\bd\n\\item[Fundamental matrix] Put $X = x \\in \\trm{Gl}_1(\\currfield(z))$. Clearly, $Wr(X) = (x)$ and $\\det Wr(X) = x \\neq 0$. Hence, $x$ belongs to the $\\currfield$-basis of the solution space.\n\\item[Picard-Vessiot ring] By prop. \\ref{PicardVessiotRing} we know that $R \\simeq \\currfield(z)[x,1/x]$.\n\\item[Differential Galois group] Pick some $f \\in \\trm{Gl}_1(R)$, by definition $f \\in \\trm{DGal}(R/k)$ if $f$ commutes with $\\partial$:\n$$\\partial(f x) = \\partial(f) x + f a x = f a x = f \\partial(x) \\LRA \\partial(f) = 0,$$\ni.e. $f$ is in $\\currfield.id$. Thus, we have that $\\trm{DGal}(R/k) = \\left<\\partial\\right> \\simeq \\qz^\\times$.\n\\ed\n\\subsubsection{2-dim case} \\label{twoD}\nLet $k \\subseteq \\currfield$ with trivial derivation $\\partial\\mid_{\\currfield} = 0_{\\currfield}$, as well as $a \\neq 0$ and $\\partial^2(x) = a x$. Clearly, the solution space in question is contained in a two-dimensional space with companion matrix $A = \\left(\\bao{cc}\n0 & 1\\\\\na & 0\\\\\n\\ea\\right)$.\n\\paragraph{Fundamental matrix} Put $X = \\left(\\bao{cc}\nx_{11} & x_{12}\\\\\nx_{21} & x_{22}\\\\\n\\ea\\right)$ as fundamental matrix with $\\partial(x_{11}) = x_{21}, \\partial(x_{21}) = a x_{11}$ as well as $\\partial(x_{12}) = x_{22}, \\partial(x_{22}) = a x_{12}$. The Wronskian matrix is\n{\\scriptsize\n$$\\left(\\bao{cccc}\nx_{11} & x_{21} & x_{12} & x_{22}\\\\\nx_{21} & a x_{11} & x_{22} & a x_{12}\\\\\na x_{11} &  a x_{21} & a x_{12} & a x_{22}\\\\\na x_{21} & a^2 x_{11} & a x_{22} & a^2 x_{12}\\\\\n\\ea\\right)\n$$}\nObviously, $\\det Wr(X) = 0$ as the fourth and third row are linear combinations of the first two rows. For instance, $x_1 = x_{11}$ and $x_2 = x_{21}$ forms a $\\currfield$-basis of the solutions space. Since the remaining indeterminates are linearly dependent over $\\currfield$ we compute for $x_{12} = \\lambda_{11} x_1 + \\lambda_{12} x_2, x_{22} = \\lambda_{21} x_1 + \\lambda_{22} x_2$ and $\\lambda_{ij} \\in \\currfield$:\n$$\\bao{rclcl}\n\\partial(x_{12}) &=& \\lambda_{11} \\partial(x_1) + \\lambda_{12} \\partial(x_2) &=& \\lambda_{12} a x_1 + \\lambda_{11} x_1\\\\ \n&&&&\\\\\n&\\stackrel{!}{=}& \\lambda_{21} x_1 + \\lambda_{22} x_2 &\\LRA& \\lambda_{21} = \\lambda_{12}, \\lambda_{22} = \\lambda_{11} a\\\\\n&&&&\\\\\n\\partial(x_{22}) &=& \\lambda_{21} \\partial(x_1) + \\lambda_{22} \\partial(x_2) &=& a \\lambda_{11} x_1 + a \\lambda_{11} x_1\\\\\n&&&&\\\\\n&\\stackrel{!}{=}& a \\lambda_{11} x_1 + a\\lambda_{12} x_2\\\\\n\\ea$$\nWe see that we may chose any $\\lambda_{11} =: \\lambda_1, \\lambda_{12} = \\lambda_2 \\in \\currfield$ such that $\\det X$ is a unit. Continuing:\n$$\\det X = \\det \\left(\n\\bao{cc}\nx_1 & \\lambda_1 x_1 + \\lambda_2 x_2\\\\\nx_2 & a \\lambda_2 x_1 + \\lambda_1 x_2\\\\\n\\ea\\right) = %a \\lambda_2 x_1^2 + \\lambda_1 x_1 x_2 - \\lambda_1 x_1 x_2 - \\lambda_2 x_2^2 \n= a \\lambda_2 x_1^2 - \\lambda_2 x_2^2 = \\lambda_2 (a x_1^2 - x_2^2).$$\nWe can set $\\lambda_1$ arbitrarily but chose zero and $\\lambda_2 = 1$,\n%Identifying the remaining variables with $x_{12} = a^{-1} x_2$, $x_{22} = a x_1$\n we get the fundamental matrix $X = \\left(\\bao{cc}\nx_1 & x_2\\\\\nx_2 & a x_1\\\\\n\\ea\\right)$. Its inverse is\n$$X^{-1} = \\frac{1}{a x_1^2 - x_2^2} \\left(\n\\bao{cc}\na x_1 & -x_2\\\\\n-x_2 & x_1\\\\\n\\ea\\right)$$\nIn Heidereich 2010, he provides the condition $\\sum_{i=0}^n a_i \\partial^i(X) X^{-1} \\in M_2(k)$ for the fundamental matrix. But clearly, if $\\partial(X) = A X$ then $\\partial^i(X) = A^i X$ and the condition holds.% In our case:\n%$$\\partial(X)X^{-1} = A X X^{-1} = \\frac{1}{a x_1^2 - a^{-1} x_2^2}\\left(\\bao{cc}\n%x_2 & a x_1\\\\\n%a x_1 & a x_2\\\\\n%\\ea\\right)\\left(\n%\\bao{cc}\n%x_1 & a^{-1} x_1\\\\\n%x_2 & a x_2\\\\\n%\\ea\\right) = A.$$\n\\paragraph{Differential Galois group} we have $g = (g_{ij}) \\in \\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield)$ iff $g A - A g = 0$ and $\\det g \\in \\currfield^\\times$. We get:\n$$\\bao{cc}\na g_{12} - g_{21} = 0 & -a g_{12} + g_{21} = 0\\\\\na g_{11} - a g_{22} = 0 & -a g_{11} + a g_{22} = 0.\\\\\n\\ea$$\nTherefore we have $g = \\left(\\bao{cc}\ng_{11} & g_{12}\\\\\na g_{12} & g_{11}\\\\\n\\ea\\right)$. The determinant is $\\det g = g_{11}^2 - a g_{12}^2$. If $g_{ij} \\in \\currfield$ we get that $\\det g = 0 \\LRA g_{11}^2 = a g_{12}^2$. Since $\\currfield$ is algebraically closed, there is a $b \\in \\currfield$ such that $b^2 = a$. Hence, $g_{11} = \\pm b g_{12}$. Thus we get:\n$$\\left\\{\\left(\n\\bao{cc}\ng_{11} & g_{12}\\\\\na g_{12} & g_{11}\\\\\n\\ea\\right) \\in \\trm{Gl}_2(\\currfield) : g_{11} \\neq \\pm b g_{12}\\right\\}$$\nas a subgroup of the differential Galois group. To conclude, the Galois group is\n$$\\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield) = \\left<g\\right> \\supset \\left<\\partial\\right>.$$\nNow, we can express $\\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield)$ as an open algebraic set $U$ in $\\aff{2}_{\\currfield}$:\n$$\\bao{rcl}\n\\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield) &\\simeq_{\\trm{claim}}& U\\\\\n &:=& \\{(g_{11},g_{12}) \\in \\aff{2}_{\\currfield} : g_{11}^2 - a g_{12}^2 \\neq 0\\}\\\\\n&=& \\aff{2}_{\\currfield} \\bsl \\left\\{(g_{11},g_{12}) \\in \\aff{2}_{\\currfield} : g_{11}^2 - a g_{12}^2 = 0\\right\\}\\\\\n&&\\\\\n&=& \\aff{2}_{\\currfield}\\bsl Z(g_{11}^2 - a g_{12}^2)\\\\\n\\ea$$\nAs is shown in \\cite{CohCuySte}, the differential Galois group is a subgroup of $\\trm{Sl}(S(L))$. Therefore we may substitute:\n$$U' = \\{(g_1',g_2') \\in \\aff{2}_{\\currfield} : g_1'^2 - a g_2'^2 = 1\\}.$$\nThe multiplication is simply:\n$$m_U := \\left[\\left((g_{11},g_{12}) , (g'_{11},g'_{12})\\right) \\longmapsto (g_{11} g'_{11} + a g_{12} g'_{12}, g_{11} g'_{12} + g'_{11} g_{12})\\right].$$\nChecking:\n$$\\bao{rcl}\n(g_{11} g'_{11} + a g_{12} g'_{12}, g_{11} g'_{12} + g'_{11} g_{12}) &\\stackrel{?}{\\in}& U:\\\\\n&&\\\\\n(g_{11} g'_{11} + a g_{12} g'_{12})^2 - a (g_{11} g'_{12} + g'_{11} g_{12})^2 &=& g_{11}^2 {g'}_{11}^2 + a^2 g_{12}^2 {g'}_{12}^2 + 2 a g_{11} g_{12} g'_{11} g'_{12}\\\\\n&&- a\\left(g_{11}^2 {g'}_{12}^2 + g_{12}^2 {g'}_{11}^2 + 2 g_{11} g_{12} {g'}_{11} {g'}_{12}\\right)\\\\\n&&\\\\\n&=& (g_{11}^2 - a g_{12}) {g'}_{11} - (g_{11}^2 - a g_{12}) a {g'}_{12}\\\\\n&&\\\\\n&=& \\underbrace{(g_{11}^2 - a g_{12})}_{= 1} \\underbrace{({g'}_{11}^2 - a {g'}_{12})}_{= 1} = 1,\\\\\n\\ea$$\nimplying $m_U\\left((g_{11},g_{12}),({g'}_{11},g'_{12})\\right) \\in U$. Moreover, the map $\\iota: U \\ni (g_{11},g_{12}) \\longmapsto g \\in  \\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield)$ is a morphism of groups (by definition), injective as only $(1,0) \\in \\ker \\iota$ and surjective as $(g_{11},g_{12}) \\in \\iota^{-1}(g)$. This proves the claim the above defined open subset $U$ is isomorphic to $\\trm{DGal}(\\currfield[x_1,x_2,1/\\det X]/\\currfield)$.\n%This group has three classes of subgroups:\n%$$H_1 := \\left\\{\\left(\\bao{cc}\n%g_{11} & 0\\\\\n%0 & g_{11}\\\\\n%\\ea\\right) : g_{11} \\in \\currfield^\\times\\right\\},\\ H_2 := \\left\\{\\left(\\bao{cc}\n%0 &g_{12}\\\\\n%a g_{12} & 0\\\\\n%\\ea\\right) : g_{12} \\in \\currfield^\\times\\right\\},$$\n%$$\\ H_3 := \\left\\{\\left(\n%\\bao{cc}\n%g_{11} & g_{12}\\\\\n%a g_{12} & g_{11}\\\\\n%\\ea\\right) : (g_{11},g_{12}) \\in G_{<\\infty} \\times \\currfield^\\times \\cap U\\right\\}$$\nOn the other hand, $G$ can be viewed as an closed subset of $\\aff{3}_{\\currfield}$:\n$$I := \\left<(X^2 - a Y^2) Z - 1\\right> \\subset \\ov{\\qz}[X,Y,Z]\\ \\RA\\ Z(I) = \\left\\{\\left(g_{11}, g_{12}, 1/(g_{11}^2 - a g_{12}^2)\\right) : g_{11}, g_{12} \\in \\currfield\\right\\}$$\nIts multiplication is given by\n$$\\bao{rrcl}\nm_{Z(I)} :& Z(I) \\times Z(I) & \\longrightarrow & Z(I)\\\\\n&&&\\\\\n&((g_{11}, g_{12}, (g_{11}^2 - a g_{12}^2)^{-1}), & \\longmapsto &(g_{11} {g'}_{11} + a g_{12} {g'}_{12}, g_{11} {g'}_{12} + g_{12} {g'}_{11},\\\\\n& ({g'}_{11}, {g'}_{12}, ({g'}_{11}^2 - a {g'}_{12}^2)^{-1}))&&(g_{11}^2 - a g_{12}^2)^{-1}({g'}_{11}^2 - a {g'}_{12}^2)^{-1})\\\\\n\\ea$$\nThe proof of the above claim follows analogously to the open case. %The main difference is that $Z(I) = U \\times \\currfield^\\times \\cup \\left\\{0_{\\aff{3}_{\\currfield}}\\right\\}$, i.e. Zariski-dense and $Z(I)$ is a monoid (has $0$ as non-invertible and idempotent).\n\\paragraph{Characterization of field extension}\n\\bn\n\\item As we noted above, $\\partial(\\det X) = 0$. Since $R$ is a simple differential ring, we conclude $\\det X \\in k^\\partial = k = \\currfield$. Thus there is some $b = \\det X \\in \\currfield^\\times$. Therefore, $K = S^{-1}R \\simeq \\currfieldx[X]/\\left<X^2 - a x_1^2 + b\\right>$. In other words: the Picard-Vessiot field $K$ is an algebraic extension of (some appropriate) transcendental extension of $\\currfield$. Rescaling our differential equation, we may assume that $b = 1$.\n\\item An immediate consequence of the above is the following: We consider $R' := \\currfield[x_1,x_2] \\simeq \\trm{Sym}(S(L))$ wrt. the $\\currfield$-basis $\\{x_i : i = 1,2\\}$. Now, take $I = \\left<x_2^2 - a x_1^2 + 1\\right> \\subset \\trm{Sym}(S(L))$, we get:\n$$\\trm{Sym}(S(L))/I \\simeq R'/\\left<x_2^2 - a x_1^2 + 1\\right>.$$\nSince the $\\currfield$-derivation does not reduce the degree of any polynomial of positive degree we can use the degree induced filtration on $\\trm{Sym}$:\n$$\\filteredA^{\\leq l} = \\left\\{x \\in \\trm{Sym}(S(L)) : \\deg x \\leq l\\right\\} \\ \\RA \\partial_{\\trm{Sym}}\\mid_{\\filteredA^{\\leq l}} (\\filteredA^{\\leq l}) \\subset \\filteredA^{\\leq l},\\ \\filteredA^{\\leq 0} := \\currfield,\\ \\filteredA^{\\leq -n} := \\{0\\}, n, l \\in \\nz,$$\ni.e. $\\filteredA^{\\leq l}$ is $\\partial_{\\trm{Sym}}$ invariant $\\currfield$-subspace. Here we set $\\deg(0) := -\\infty$ and $\\deg$ is the sum degree. On the other hand:\n$$\\filteredA^{\\leq 2} = \\bigoplus_{|\\alpha| \\leq 2} \\currfield.x_1^{\\alpha_1} x_2^{\\alpha_2}\\ \\RA\\ \\filteredA^{\\leq2} / \\left(\\filteredA^{\\leq2} \\cap I\\right) = \\currfield \\oplus \\currfield.x_1 \\oplus \\currfield.x_2 \\oplus \\currfield.x_1^2 \\oplus \\currfield.x_1 x_2,$$\nin particular $\\lambda_{0,2} x_2^2 = \\lambda_{0,2} - a \\lambda_{0,2} x_1^2 \\in \\currfield \\oplus \\currfield.x_1^2$ for any $\\lambda_{0,2} \\in \\currfield$. In general, for $\\filteredA^{\\leq n}$ we may substitute all terms $x_2^{2 l}$ with $(a x_1^2 - 1)^l$ and all $x_2^{2l + 1}$ with $(a x_1^2 - 1)^l x_2$, for all $l \\in \\{d \\in \\nz : 2 \\mid d\\}$. Therefore the quotient spaces are\n$$A_n := \\filteredA^{\\leq n}/ \\left(\\filteredA^{\\leq n} \\cap I\\right) /\\left(\\filteredA^{\\leq n - 1} / \\left(\\filteredA^{\\leq n - 1} \\cap I\\right) \\right)\\simeq \\currfield.x_1^n \\oplus \\currfield.x_1^{n-1} x_2,$$\nand therefore its associated graded $\\currfield$-algebra is obviously:\n$$A = \\bigoplus_{n \\geq 0} A_n \\simeq \\currfield[x_1] \\oplus \\currfield[x_1].x_2.$$\nSummarizing we get\n$$\\trm{Sym}(S(L))/I = \\filteredA/I = \\bigcup_{n \\geq 0} \\filteredA^{\\leq n}/  \\filteredA^{\\leq n} \\cap I \\simeq A \\simeq \\currfield[x_1] \\oplus \\currfield[x_1].x_2,$$\nwith multiplication\n$$\\mu = \\left[x_1^{i_1} x_2^{j_1} \\otimes x_1^{i_2} x_2^{j_2} \\longmapsto x_1^{i_1 + i_2} (a x_1^2 - 1)^{(j_1 + j_2 - (j_1 + j_2 \\mod 2))/2} x_2^{j_1 + j_2 \\mod 2}\\right],\\ \\forall i_l \\in \\nz, j_l = 0, 1.$$\nWe note that the subalgebra $\\currfield[x_1]$ is not a differential algebra as \n$$\\partial = \\left[x_1^i x_2^j \\longmapsto \\begin{cases}\n(1 + i) a x_1^{i+1} - i x_1^{i-1}& j = 1\\\\\ni x_1^{i-1} x_2 & j = 0\\\\\n\\end{cases}\\right].$$\nLocalizing wrt. $S := \\currfield[x_1]\\bsl\\{0\\}$, i.e. non-zero polynomials, and identifying with all corresponding symmetric tensors we have that\n$$K^+ := S^{-1} \\left(\\currfield[x_1] \\oplus \\currfield[x_1].x_2\\right) = S^{-1} \\currfield[x_1] \\oplus S^{-1} \\currfield[x_1].x_2 = \\currfieldx \\oplus \\currfieldx.x_2.$$\nHowever, we have not shown yet whether $K^+$ is an integral domain. Now let us consider $p = Y^2 - a x_1^2 + 1 \\in \\currfieldx[Y]$. \n$$Y^2 - \\underbrace{a x_1^2 + 1}_{= \\alpha^2} = (Y - \\alpha)(Y + \\alpha).$$\nIf $\\alpha \\in \\currfieldx$, then $\\ov{Y \\pm \\alpha} = \\ov{Y} \\pm \\alpha$ are zero-divisors in the quotient ring and with $\\trm{gcd}(Y - \\alpha, Y + \\alpha) = 1$ we get\n$$\\currfieldx[Y]/\\left<Y^2 - a x_1^2 + 1\\right> \\simeq \\currfieldx^2$$\nas a $\\currfieldx$-vector space, with multiplication:\n$$\\mu(a \\otimes \\_) := [b \\longmapsto a b] \\equiv \\left(\\bao{cc}\na_0 & (a x_1^2 - 1) a_1\\\\\na_1 & a_0\\\\\n\\ea\\right) \\in M_2(\\currfieldx),\\ \\forall a \\equiv (a_0, a_1) \\in \\currfieldx^2$$\nand with derivation:\n$$\\partial = \\left[\n\\bao{ccc}\n(1_{\\currfield} x_1^i, 0) &\\longmapsto& (0 , i x_1^{i-1})\\\\\n(0, 1_{\\currfield} x_1^i) &\\longmapsto& ((1 + i) a x_1^i - i x_1^{i-1},0)\\\\ \n\\ea\n\\right].$$ Hence, the Picard-Vessiot field $K$ would be simply $\\currfieldx$. This implies:\n$$\\exists \\alpha \\in \\currfield.x_1 \\bsl \\{0\\}:\\ \\partial_{\\currfieldx}(\\alpha) \\in \\currfield.x_1 \\LRA \\exists v \\in \\ker (\\alpha id_{\\currfield.x_1} - \\partial) \\bsl\\{0\\},$$\ni.e. an eigenvector of $\\partial_K$. On the other hand, is $[\\currfield(x_1,\\alpha) : \\currfieldx] := \\deg \\trm{Min}(\\alpha,\\currfieldx) = 2$:\n$$\\RA\\ (K, \\partial_K) \\simeq \\left(\\currfield\\left(x_1,\\sqrt{a x_1^2 - 1}\\right), \\partial_{K_1}\\right)$$% \\simeq \\left(\\currfield\\left(x_2,\\sqrt{(1 + x_2^2)/(a)}\\right), \\partial_{K_2}\\right),$$\nis a field, with $\\currfieldx/\\currfield$ transcendental and with $\\currfield$-derivation:%s:\n$$\\bao{rrcl}\n\\partial_{K}%_1}\n : &\\currfield\\left(x_1,\\sqrt{a x_1^2 - 1}\\right)&\\longrightarrow&\\currfield\\left(x_1,\\sqrt{a x_1^2 - 1}\\right)\\\\\n&&&\\\\\n&x_1 &\\longmapsto& \\sqrt{a x_1^2 - 1}\\\\\n&\\sqrt{a x_1^2 - 1} &\\longmapsto& a x_1\\\\\n&&&\\\\\n%\\partial_{K_2} : &\\currfield\\left(x_2,\\sqrt{(1 + x_2^2)/a}\\right)&\\longrightarrow&\\currfield\\left(x_2,\\sqrt{(1 + x_2^2)/a}\\right)\\\\\n%&&&\\\\\n%&x_2 &\\longmapsto& \\sqrt{\\frac{1 + x_2^2}{a}}\\\\\n%&\\sqrt{\\frac{1 + x_2^2}{a}} &\\longmapsto& a x_2\\\\\n\\ea$$\nHowever, we claim that since $x_1$ is transcendental over $\\currfield$ and the polynomial $a x_1^2 +1$ is no square in $\\currfield[x_1]$, the polynomial $X^2 - a x_1^2 + 1$ is irreducible over $\\currfieldx$. First, let us assume there is a root $\\alpha = \\frac{\\beta}{\\gamma} \\in \\currfieldx$, where $\\trm{gcd}(\\beta,\\gamma) = 1$ and $\\gamma \\neq 0$. Then we compute:\n$$\\alpha^2 = a x_1^2 - 1 = \\frac{\\beta^2}{\\gamma^2} \\LRA \\beta^2 = \\gamma^2 (a x_1^2 - 1),$$\ni.e. $\\beta \\in \\currfield[x_1]$ is a root of the polynomial $X^2 - \\gamma^2(a x_1^2 - 1)$. Having $\\beta = \\sum_{j=0}^{n_1} \\beta_j x_1^i, \\gamma = \\sum_{i=0}^{n_2} \\gamma_i x_1^i$, with $\\gamma_i, \\beta_j \\in \\currfield$, we get that $n_1 = n_2 + 1$ due to the factor $a x_1^2$. On the other hand, both decompose to linear factors due to algebraic closedness of $\\currfield$, e.g.:\n$$\\beta = \\wt{\\beta}_0 \\prod_{i=1}^{m_1} (x_1 - \\wt{\\beta}_i)^{s_i},\\ \\gamma = \\wt{\\gamma}_0 \\prod_{j=1}^{m_2} (x_1 - \\wt{\\gamma}_j)^{t_j},\\ \\trm{and}\\ \\sum_{i=0}^{m_1} s_1 = \\sum_{j=0}^{m_2} t_j + 1.$$\nClearly, all but at most two factors on both sides of our polynomial equation cancel. So we get $n_2 \\leq 0$ and $n_1 \\leq 1$. In particular, $\\alpha$ itself is already in $\\currfield[x_1]$ for $n_2 = 0$ (i.e. $\\gamma \\neq 0$). This is not possible, as\n$$\\wt{\\beta}_0^2 (x_1 - \\wt{\\beta}_1)^2 = \\wt{\\beta}_0^2(x_1^2 - 2 \\wt{\\beta}_1 x_1 + \\wt{\\beta}_1^2) = \\wt{\\gamma}_0^2 (a x_1^2 - 1) \\LRA 2 \\wt{\\beta}_1 = 0 \\wedge \\wt{\\beta}_0^2 \\wt{\\beta}_1^2 = -\\wt{\\gamma}_0^2$$\nleads to the contradiction $\\gamma = 0$. Hence, $\\alpha$ is algebraic and $[\\currfieldx(\\alpha) : \\currfieldx] = 2$.\\\\\n\\indent Nevertheless, one aspect we have not considered yet which we will discuss now.\n%However, since $\\currfield$ is algebraically closed, we get the abovementioned decomposition which will get discussed right now.\n\\item $\\currfield(x_1,x_2) = K$ is contained in a $\\currfield$-algebra generated by one distinct transcendental element $y$ being a unit in $\\currfield[x_1,x_2]$: The ring $R = \\currfield[x_1,x_2,\\det X^{-1}]$ contains four non-trivial units (i.e. elements in $R^\\times \\bsl \\currfield^\\times$). Namely:\n$$\\pm \\sqrt{a} x_1 \\pm x_2,$$\nto specify: four non-trivial divisors of $\\det X$ in $\\currfield[x_1,x_2]$. Computing their derivative wrt. $\\partial$, we get:\n$$\\bao{rclcl}\n\\partial(\\sqrt{a} x_1 \\pm x_2) &=& \\sqrt{a} x_2 \\pm a x_1 &=& \\pm \\sqrt{a} (\\sqrt{a} x_1 \\pm x_2)\\\\\n&&&&\\\\\n\\partial(-\\sqrt{a} x_1 \\pm x_2) &=& -\\sqrt{a} x_2 \\pm a x_1 &=& \\mp\\sqrt{a} (-\\sqrt{a} x_1 \\pm x_2).\\\\\n\\ea$$\nEach of the four elements is an eigenvector of $\\partial$ in $R$ with eigenvalue $\\pm \\sqrt{a}$ - or equivalently, solves the following differential equations:\n$$L_{\\pm} := \\partial(x) \\mp \\sqrt{a} x = 0,$$\nwhere the subscript sign defines the sign of the eigenvalue. Defining $y_1 \\in S(L_+), y_{-1} \\in S(L_-)$ we get that $K = \\currfield(x_1,x_2)$ contains two subfields depicted in the following diagram:\n$$\\xymatrix{\n& \\currfield(y_1) \\ar@{^{(}->}[rd]&\\\\\n\\currfield\\ar@{^{(}->}[rd]\\ar@{^{(}->}[ru]&&\\currfield(x_1,x_2) \\simeq \\currfield(y_1)\\\\\n& \\currfield(y_{-1}) \\ar@{^{(}->}[ru]&\\\\\n}$$\nBy direct computation, we see that:\n$$L = \\partial^2 - a \\cdot id = (\\partial - \\sqrt{a}) (\\partial + \\sqrt{a}).$$\nAnd our differential module $S(L)$ decomposes:\n$$S(L)^* \\simeq \\currfield[\\partial]/\\currfield[\\partial].L \\simeq \\currfield[\\partial]/\\currfield[\\partial].L_+ \\oplus \\currfield[\\partial]/\\currfield[\\partial].L_- \\simeq S(L_+)^* \\oplus S(L_-)^*.$$\n\\en\n\\paragraph{The subfields}\nFirstly, we like to compute the Picard-Vessiot ring for $M_{i} = \\currfield(y_i)$:\n$$R_i = \\currfield[y_{i}, y_i^{-1}],\\ \\trm{for}\\ i = \\pm1$$\n%As the image of the ideal $\\left<y_i\\right> \\subset \\currfield[y_i]$ is the whole ring under inclusion or equivalently $1_R \\in R_i.y_i$, we have indeed that $R_i$ is simple differential. \n%Let $I \\subset R_i$ be a proper ideal and we assume differential closedness - i.e. $\\partial(I) \\subset I$.\n%As a noetherian $R$-submodule of a noetherian module $R$ (generated by $y_{\\pm 1}$ over $\\currfield$), $I$ is finitely generated. Hence, let $S:= \\{s\\} \\subset I$ be one generating set. By differential closedness, we get for any $s \\in S$:\n%$$\\partial(s) = \\partial\\left(\\sum_{i=-m}^n s_i y_1^i\\right) = \\sum_{i=-m}^n s_i \\partial(y_1^i) = \\sum_{i=-m}^n i \\sqrt{a} s_i y_1^i \\in I$$\n%$$\\LRA \\partial(s) - s = \\sum_{i=-m}^n (i \\sqrt{a} - 1) s_i y_1^i \\in I$$\n%But both, $s, \\partial(s) - s$ are of degree $n$, or $m$ wrt. $y_{\\pm 1}$ and $y_1^m (\\partial(s) - s) \\in \\currfield[y_1]$.\n% There is an ideal $I' \\subset \\currfield[y_1]$, such that $S_{y_1}^{-1}(I') \\supset I$. By definition of $I$, we get\n%$$y_1^m t \\in I' \\RA \\partial(y_1^m t) = \\underbrace{m \\sqrt{a} y_1^m t}_{\\in I'} + \\underbrace{y_1^m \\partial(t)}_{\\in \\partial(I')},$$\n%but identifying $I' := I \\cap \\frac{\\currfield[y_1]}{1}$ we get $\\partial(I') \\subset I'$. Being a PID, all ideals $I' \\subset \\currfield[y_1]$ are of the form $\\left<s\\right>$. On the other hand, $\\partial$ operates on all weight spaces $\\currfield.y_1^i$, $i \\geq 1$, invariantly:\n%$$\\bao{rrcl}\n%\\partial_i := \\partial\\mid_{\\currfield.y_1^i} : &\\currfield.y_1^i &\\longrightarrow& \\currfield.y_1^i\\\\\n%&&&\\\\\n%&y_1^i &\\longmapsto&i \\sqrt{a} y_1^i\\\\\n%\\ea$$\n%Thus we have:\n%$$\\partial s = \\sum_{i=0}^n s_i \\partial(y_1^i) = \\sum_{i=0}^n i \\sqrt{a} s_i y_1^i \\in \\left<s\\right> \\LRA \\partial(s) \\equiv 0 \\mod s$$\n%$$\\LRA \\sum_{i=0}^{n-1} (i - n) \\sqrt{a} s_i y_1^i = 0 \\LRA s_i = 0 \\vee n - i = 0\\ \\forall 0 \\leq i \\leq n - 1,$$\n%Hence, each derivative of the generators $s$ agree in degree but also reduce to zero modulo $\\left<s\\right>$ contradicting our claim $\\partial(s) \\in \\left<s\\right>$. Thus, all $D$-stable ideals in $R$ are indeed trivial.\nFirstly, we get:\n$$\\partial(y_i^{-1}) = -\\frac{\\partial(y_i)}{y_i^2} = -i \\sqrt{a} y_i^{-1}, i =\\pm1$$\nimplying the multiplicative inverse solves the opposite differential equation. Hence, $R_i$ already contains all solutions of $L_\\pm$ by simply putting $y_{-1} := y_1^{-1}$.\\\\\n\\indent Let $R = R_1$. Furthermore, we want to show that $R$ is indeed a simple differential ring over $\\currfield$. Clearly, $\\partial$ operates invariantly on $\\currfield.y_{\\pm 1}^i$ for all $i \\neq 0$. In addition, $R$ is isomorphic to $S_{X}^{-1}\\currfield[X]$, the localization of $\\currfield[X]$ where\n$$S_X = \\currfield[X] \\bsl \\bigcup_{\\substack{\\mathfrak{p} \\in \\trm{Spec}(\\currfield[X])\\\\X \\notin \\mathfrak{p}}} \\mathfrak{p} = \\{f \\in \\currfield[X] : f \\notin \\idealp\\ \\forall \\idealp \\in \\trm{Spec} \\currfield[X] \\bsl \\{\\left<X\\right>\\}\\}.$$ Furthermore, every prime ideal in $\\currfield[X]$ is generated by $X - \\alpha$, for some $\\alpha \\in \\currfield$ as $\\currfield$ is algebraically closed. Hence, on the one hand we get:\n$$S_X = \\{f \\in \\currfield[X]\\bsl \\currfield : f \\notin \\left<X - \\alpha\\right> \\forall \\alpha \\in \\currfield^\\times\\} = \\{X^i : i \\geq 0\\}$$\nand on the other hand: if $I' \\subset R$ is an ideal, there is an ideal  $I \\subset \\currfield[X]$ such that $I' = S_{X}^{-1} I$. This implies every ideal is principal in $R$. In $\\currfield[X]$ each element $\\mathfrak{p} \\in \\trm{Spec}(\\currfield[X])$ gets mapped to $\\left<X\\right>$ via $\\partial$, as every element $p (X - \\alpha)$ in a prime ideal $\\left<X - \\alpha\\right>$ has an image in $\\left<X\\right>$:\n$$p (X - \\alpha) \\longmapsto \\partial(p) (X - \\alpha) + \\sqrt{a} p X,\\ \\forall \\alpha \\in \\currfield,\\ p \\in \\currfield[X]$$\nwhere the constant coefficient $\\left(\\partial(p)\\right)_0 = 0 \\LRA p_0 \\in \\ker \\partial \\LRA \\partial(p) \\in \\left<X\\right>$. This shows the differential $\\currfield$-algebra $\\left(\\currfield[X], \\partial = \\sqrt{a} X \\cdot \\frac{d}{d X}\\right)$ has only one differential prime ideal, $\\left<X\\right>$ (- in our case even maximal). However, the localization cancels this as its generator $X$ is a unit in $R$ (using variable notation $X, y_1$ interchangeably). Therefore, our rings $R_1, R_{-1}$ are indeed simple differential rings - or PV. In words of $D$-module algebra, $R_1, R_{-1}$ are simple $D$-rings, for $D = \\currfield[\\partial]$.\\\\\n\\indent To conclude this paragraph, we want to show that $\\currfield(x_1,x_2) \\simeq \\currfield(y_1)$ as differential field extensions over $\\currfield$. To achieve this we need to show that the maps:\n$$\\bao{rrcl}\n\\Phi : & \\currfield(y_1) &\\longrightarrow& \\currfield(x_1,x_2)\\\\\n& y_1 &\\longmapsto & \\sqrt{a} x_1 + x_2\\\\\n& y_1^{-1}&\\longmapsto & \\sqrt{a} x_1 - x_2\\\\\n&&&\\\\\n\\Psi : &\\currfield(x_1,x_2) &\\longrightarrow& \\currfield(y_1)\\\\\n& x_1 &\\longmapsto& \\frac{1}{2 \\sqrt{a}} (y_1 + y_1^{-1})\\\\\n& x_2 &\\longmapsto& \\frac{1}{2} (y_1 - y_1^{-1})\\\\\n\\ea$$\\label{PVisomorph}\nare bijective and inverse to one another as differential $\\currfield$-algebra homomorphisms (or $D$-module algebra homomorphisms). Clearly, the two $\\currfield$-vector spaces $V_1 := \\currfield.y_1 \\oplus \\currfield.y_1^{-1}$ and $V_2 := \\currfield.x_1 \\oplus \\currfield.x_2$ are isomorphic by simple basis change induced by the restrictions $\\mid_{V_i}$ of the above $\\currfield$-vector space homomorphisms. Furthermore, $\\Psi \\mid_{V_2} \\Phi \\mid_{V_1} = id_{V_1}$ and $\\Phi \\mid_{V_1} \\Psi \\mid_{V_2} = id_{V_2}$ and both are $D$-modules. Hence, the basis change respects this property as shown above. This property is kept for the recursively defined family of $D$-modules:\n$$V_{1,i} := V_{1,i-1} \\oplus \\currfield.y_1^i \\oplus \\currfield.y_1^{-i},\\ V_{2,i} := V_{2,i-1} \\oplus \\currfield.x_1^i \\oplus \\currfield.x_1^{i-1} x_2, \\forall i \\geq 1$$\nand $V_{j,0} = \\currfield$ for $j = 1, 2$. We get:\n$$\\bao{rclclcl}\n\\bigcup_{i \\geq 0} V_{1, i} &\\simeq& \\currfield[y_1,X]/\\left<y_1 X - 1\\right> &\\simeq& \\currfield[y_1,y_1^{-1}] &=:& R_1\\\\\n&&&&\\\\\n\\bigcup_{i \\geq 0} V_{2,i} &\\simeq& \\currfield[x_1,x_2]/\\left<x_2^2 - a x_1^2 + 1\\right> &\\simeq& \\currfield[x_1,\\sqrt{a x_1^2 - 1}] &=:& R_2,\\\\\n\\ea$$\ni.e. a $D$-stable filtration for each subalgebras $R_1, R_2$. Having already shown their simplicity we only need surjectivity as $\\Psi\\mid_{V_{2,0}} = id_{V_{2,0}}, \\Phi\\mid_{V_{1,0}} = id_{V_{1,0}}$ already implies injectivity. Let $f$ and $g$ equal $\\sum_i \\left(f_{1,i} y_1^i + f_{-1,i} y_1^{-i}\\right) \\in R_1$ and $\\sum_i \\left(g_{1,i} x_1^i + g_{2,i-1} x_1^i x_2\\right) \\in R_2$, respectively. Obviously, $\\sum \\left(f_{1,i} (\\sqrt{a} x_1 + x_2)^i + f_{-1,i} (\\sqrt{a} x_1 - x_2)^i\\right)$ and\n$\\sum (y_1 + y_1^{-1})^i \\left(\\frac{g_{1,i}}{2 \\sqrt{a}} + \\frac{g_{2,i}}{2} (y_1 - y_1^{-1})\\right)$ are elements in their respective preimages. This extends naturally to their localizations.\n%Hence, any ideal stable under $\\partial$ is, on the one hand, generated by a single element, on the other hand, $\\deg f = \\deg \\partial(f)$, where $\\deg = \\left[f = \\sum_{i=-m}^n f_i X^i \\longmapsto \\max(m,n)\\right]$. In particular, $\\left<f, \\partial f\\right>$ is also principal and a subideal of $I$.\n\\paragraph{Galois group of the subfields}\nAs above $\\trm{DGal}(\\currfield[y_1,y_{-1}]/\\currfield) = \\{a \\in \\trm{Gl}_1(\\currfield) : \\partial a = a \\partial\\}$. Obviously, the unit group of $\\currfield$ is our differential Galois group.\n% However, both generators are eigenvectors. Hence, the diagonal matrix\n%$$A_{L_++L_-} = \\left(\\bao{cc}\n%\\sqrt{a} & 0\\\\\n%0 & -\\sqrt{a}\\\\\n%\\ea\\right)$$\n%represents $\\partial$ on $S(L_+) \\oplus S(L_-)$ with canonical basis vectors identified with $y_1, y_{-1}$, respectively. Clearly, all matrices with diagonal entries are the only ones fulfilling our definition. We get\n%$$\\trm{DGal}(\\currfield[y_1,y_{-1}]/\\currfield) \\simeq \\currfield^\\times \\times \\currfield^\\times.$$\n\\paragraph{Conclusion}\nGiven our above example, the PV-ring and field are\n$$R = \\currfield[y_1,y_{-1} := y_1^{-1}],\\ K = S^{-1}R = \\currfield(y_1),$$\nrespectively, with differential Galois group\n$$\\trm{DGal}(\\currfield[y_1,y_{-1}]/\\currfield) \\simeq \\currfield^\\times.$$\nThe differential ring $\\currfield[x_1,x_2] = \\trm{Sym}(L)/\\left<x_2^2 - a x_1^2 + 1\\right> \\simeq \\trm{Sym}(\\currfield^2)/\\left<e_2^2 - a e_1^2 + 1\\right>$ is isomorphic to\n$$\\currfield[y_1] \\oplus \\currfield[y_{-1}] \\simeq \\currfield[y_1]^2.$$\n\\bmk %The results are valid in case $a, \\sqrt{a} \\in \\currfield[z]\\bsl\\currfield$, if our matrix equation gets slightly modified:\n%$$A_L = \\left(\\bao{cc}\n%0 & 1\\\\\n%a \\pm \\partial(\\sqrt{a}) & 0\\\\\n%\\ea\\right) \\in \\trm{Gl}_2(\\currfield(z))\\LRA L(y) = \\partial^2(y) - \\left(a \\mp \\partial(\\sqrt{a})\\right)y = 0,\\ \\forall y \\in S(L).$$\n%The different signs arise from two isomorphic solution spaces $S_1 = S(L_+) \\oplus S(L_-)$, $S_2 = S(L_-) \\oplus S(L_+)$, or equivalently, by the order of operator evaluation:\n%$$S_1 \\simeq D/D.(\\partial - \\sqrt{a})(\\partial + \\sqrt{a}),\\ S_2 \\simeq D/D.(\\partial + \\sqrt{a})(\\partial - \\sqrt{a}),\\ \\trm{where}\\ D := \\currfield(z)[\\partial], \\partial(z) = 1.$$\nA more exhaustive approach to $\\partial^2 - a \\cdot id$, where $a$ is not a constant, is given in \\cite{vdPS01} and \\cite{CohCuySte}.\\\\\n\\indent Unfortunately, our given examples are all linear homogeneous ODEs. The theory, we are going to present in the next chapter, is more general. It includes theory for general ODEs (linear, non-linear) in characteristic zero, (multivariate) iterative derivations in positive characteristic and difference equations in arbitrary characteristic.\\\\\n\\indent Nevertheless, as the general theory does not require the ring/field of constants to be algebraically closed we may examine a broader setting.\n%though each factor is not differentially closed (i.e. $(1,0) \\stackrel{\\partial}{\\longmapsto} (0,1) \\stackrel{\\partial}{\\longmapsto} (a,0)$).\n%We want to see if the following $\\currfield$-linear maps are differentially invariant:\n%$$\\sigma_1 = [\\pm y_1 \\longmapsto \\mp y_1,\\ \\pm y_1^{-1} \\longmapsto \\mp y_1^{-1}] \\in \\trm{Gl}(R_1)$$\n%$$\\sigma_2 = [y_1 \\longmapsto y_1^{-1}] \\in \\trm{Gl}(R_1)$$\n%Since $\\pm y_1$ and $\\pm y_1^{-1}$ have the same eigenvalue $\\sqrt{a}$ and $-\\sqrt{a}$ respectively, we have that $\\sigma_1$ commutes with $\\partial$. Hence, $\\sigma_1 \\in \\trm{DGal}(M_1/\\currfield)$. On the other hand, $\\sigma_2(\\partial(y_1)) = \\sigma_2(\\sqrt{a} y_1) = \\sqrt{a} y_1^{-1} \\neq \\partial(\\sigma_2(y_1)) = \\partial(y_1^{-1}) = -\\sqrt{a} y_1^{-1}$. %Now, we may express $v = \\sum_{i \\in \\{1,2\\}} v_i x_i \\in \\trm{Sol}(\\partial^2 - a \\cdot id)$ as linear combinations of $v = \\sum_{i \\in \\{\\pm 1\\}} v'_i y_i$:\n%$$\\bao{rrcl}\n%M_{B_x}^{B_y}(id):& v &=& v'_1 y_1 + v'_{-1} y_{-1}\\\\\n%& &=& v'_1 (\\sqrt{a} x_1 + x_2) + v'_{-1} (\\sqrt{a} x_1 - x_2)\\\\\n%&&&\\\\\n%&&=& \\sqrt{a} (v'_1 + v'_{-1}) x_1 + (v'_1 - v'_{-1}) x_2\\\\\n%&&&\\\\\n%M_{B_y}^{B_x}(id)&v &=& v_1 x_1 + v_{2} x_{2}\\\\\n%&&=& \\frac{v_1}{2 \\sqrt{a}}(y_1 + y_{-1}) + \\frac{v_{2}}{2} (y_1 - y_{-1})\\\\\n%&&&\\\\\n%&&=& \\frac{1}{2 \\sqrt{a}} \\left[(v_1 + \\sqrt{a} v_2) y_1 + (v_1 - \\sqrt{a} v_2) y_{-1}\\right]\\\\\n%\\ea$$\n%Hence, we have the following basis transformation matrices:\n%$$M_{B_x}^{B_y} = \\left(\\bao{cc}\n%\\sqrt{a} & \\sqrt{a}\\\\\n%1 & -1\\\\\n%\\ea\\right),\\ \\ M_{B_y}^{B_x} = \\frac{1}{2 \\sqrt{a}}\\left(\\bao{cc}\n%1 & \\sqrt{a}\\\\\n%1 & -\\sqrt{a}\\\\\n%\\ea\\right)$$\n%The conjugate $M_{B_y}^{B_x} G M_{B_x}^{B_y}$ of $G:= \\trm{DGal}(\\currfield(x_1,x_2)/\\currfield)$ defines a group action on $S(L_+) \\oplus S(L_-)$ or equivalently, makes $S(L_+) \\oplus S(L_-)$ a $G$-module:\n%$$\\bao{rrcl}\n%\\alpha : &G \\times \\left(S(L_+) \\oplus S(L_-)\\right)& \\longrightarrow &S(L_+) \\oplus S(L_-)\\\\\n%&&&\\\\\n%&\\left(g := \\left(\\bao{cc}\n%g_{11} & g_{12}\\\\\n%a g_{12} & g_{11}\\\\\n%\\ea\\right), v'_1 y_1 + v'_{-1} y_{-1}\\right) &\\longmapsto&M_{B_y}^{B_x} g %\\left(\\bao{cc}\n%g_{11} & g_{12}\\\\\n%a g_{12} & g_{11}\\\\\n%\\ea\\right)\n%M_{B_x}^{B_y}\\left(\\bao{c}\n%v'_1\\\\\n%v'_{-1}\\\\\n%\\ea\\right)\\\\\n%\\ea$${\\footnotesize\n%$$M_{B_y}^{B_x}g %\\left(\\bao{cc}\n%g_{11} & g_{12}\\\\\n%a g_{12} & g_{11}\\\\\n%\\ea\\right)\n%M_{B_x}^{B_y}\\left(\\bao{c}\n%v'_1\\\\\n%v'_{-1}\\\\\n%\\ea\\right) = \\frac{1}{2 \\sqrt{a}}\\left(\\bao{cc}\n%2 \\sqrt{a} g_{11} + (1 + a^2) g_{12}& -(1 - a^2) g_{12}\\\\\n%(1 - a^2) g_{12} & 2 \\sqrt{a} g_{11} - (1 + a^2) g_{12}\\\\\n%\\ea\\right) \\left(\\bao{c}\n%v'_1\\\\\n%v'_{-1}\\\\\n%\\ea\\right)\\\\\n%$$}\n%The fixed field $\\currfield(y_1)^G$ is \n%Multiplying $T$ with the generator of $\\trm{DGal}(\\currfield(x_1,x_2)/\\currfield)$ we get:\n%$$T g = \\left(\\bao{cc}\n%\\sqrt{a} & 1\\\\\n%\\sqrt{a} & -1\\\\\n%\\ea\\right) \\left(\\bao{cc}\n%g_{11} & g_{12}\\\\\n%a g_{12} & g_{11}\\\\\n%\\ea\\right) = \\left(\\bao{cc}\n%\\sqrt{a} g_{11} + a g_{12} & \\sqrt{a} g_{12} + g_{11}\\\\\n%\\sqrt{a} g_{11} - a g_{12} & \\sqrt{a} g_{12} - g_{11}\\\\\n%\\ea\\right)$$\n%Analogously to the classical Galois theory, there exists subgroups $H$ in $\\trm{DGal}(\\currfield(x_1,x_2)/\\currfield)$ such that $\\currfield(x_1,x_2)^H := \\{x \\in K : \\sigma(x) = x \\forall \\sigma \\in H\\}$ is a Picard-Vessiot field over $\\currfield$. Conversely, the $\\trm{DGal}(\\currfield(x_1,x_2)/M)$ is a (closed) subgroup of $\\trm{DGal}(\\currfield(x_1,x_2)/\\currfield)$ for any intermediate Picard-Vessiot field $\\currfield \\subset M \\subset \\currfield(x_1,x_2)$. %Since we already have two Picard-Vessiot subfields $M_i = \\currfield(y_i)$ of $K$, we only need to compute the Galois groups of both differential fields.", "meta": {"hexsha": "dfbfb0c7c87fbbfa37cd515df8b9ee0f25a2a097", "size": 61435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Script_Diff_Gal07/diffRingNMods.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": "Script_Diff_Gal07/diffRingNMods.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": "Script_Diff_Gal07/diffRingNMods.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": 92.1064467766, "max_line_length": 942, "alphanum_fraction": 0.6569545048, "num_tokens": 23340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.647036315493177}}
{"text": "% \\documentclass[draft,11pt]{article}\n\\chapter{Pseudo-inverses and Effective Resistance}\n\\label{cha:pinver}\n%\\usepackage{cleveref}\n\n%\\allowdisplaybreaks\n\n%%% for this lecture\n%\\newcommand\\gap{\\text{gap}}\n%\\newcommand{\\Hongjie}[1]{{\\color{red} Hongjie: #1}}\n\n%\\begin{document}\n\\sloppy\n%\\lecture{6 --- Wednesday, March 25th}\n%{Spring 2020}{Rasmus Kyng, Scribe: Hongjie Chen}{Effective Resistance,\n%Gaussian Elimination as Optimization}\n\n\\section{What is a (Moore-Penrose) Pseudoinverse?}\nRecall that for a connected graph $G$ with Laplacian $\\LL$, we have $\\ker(\\LL)=\\Span\\{\\vecone\\}$, which means $\\LL$ is not invertible. However, we still want some matrix which behaves like a real inverse. To be more specific, given a Laplacian $\\LL\\in\\R^{V\\times V}$, we want some matrix $\\LL^{\\pinv}\\in\\R^{V\\times V}$ s.t.\\\n\\begin{enumerate}\n\t\\item[1)] $(\\LL^{\\pinv})^\\trp = \\LL^\\pinv$ (symmetric)\n\t\\item[2)] $\\LL^{\\pinv}\\matone = \\veczero$, or more generally, $\\LL^{\\pinv}\\vv=\\veczero$ for $\\vv\\in\\ker(\\LL)$\n\t\\item[3)] $\\LL^{\\pinv}\\LL\\vv = \\LL\\LL^{\\pinv}\\vv = \\vv$ for $\\vv\\perp\\matone$, or more generally, for $\\vv\\in\\ker(\\LL)^\\perp$\n\\end{enumerate}\nUnder the above conditions, $\\LL^{\\pinv}$ is uniquely defined and we\ncall it the pseudoinverse of $\\LL$. Note that there are many other\nequivalent definitions of the pseudoinverse of some matrix $\\AA$,\nand we can also generalize the concept to matrices that aren't\nsymmetric or even square.\n\nLet $\\lambda_i, \\vv_i$ be the $i$-th pair of eigenvalue and eigenvector of $\\LL$, with $\\{\\vv_i\\}_{i=1}^n$ forming a orthogonal basis. Then by the spectral theorem,\n\\[ \\LL = \\VV\\LLambda\\VV^\\trp = \\sum_i \\lambda_i\\vv_i\\vv_i^\\trp, \\]\nwhere $\\VV = \\begin{bmatrix} \\vv_1 & \\cdots & \\vv_n \\end{bmatrix}$ and $\\LLambda = \\diag\\{\\lambda_1,...,\\lambda_n\\}$. And we can show that its pseudoinverse is exactly\n\\[ \\LL^{\\pinv} = \\sum_{i,\\lambda_i\\neq0} \\lambda_i^{-1}\\vv_i\\vv_i^\\trp. \\]\nChecking conditions 1), 2), 3) is immediate.\nWe can also prove uniqueness, but this takes slightly more work.\n\n\\section{Electrical Flows Again}\nRecall the incidence matrix $\\BB\\in\\R^{V\\times E}$ of a graph\n$G=(V,E)$.\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.7\\textwidth]{fig/lecture6_incidence-example.jpeg}\n  \\caption{An example of a graph and its incidence matrix $B$.}\n\\label{fig:incidenceexample}\n\\end{figure}\n\nIn Chapter 1, we introduced the electrical flow routing  demand\n$\\dd\\in\\R^V$.\nLet's call the electrical flow $\\fftil\\in\\R^E$. The net flow\nconstraint requires $\\BB\\fftil = \\dd$. By Ohm's Law,\n$\\fftil=\\RR^{-1}\\BB^\\trp\\xx$ for some voltage $x\\in\\R^V$ where\n$\\RR=\\diag(\\rr)$ and $\\rr(e)=$ resistance of edge $e$. We showed (in\nthe exercises) that when $\\dd \\perp \\matone$, there exists an voltage\n$\\xxtil\\perp\\matone$ s.t.\\ $\\fftil=\\RR^{-1}\\BB^\\trp\\xxtil$ and\n$\\BB\\fftil = \\dd$. This $\\xxtil$ solves $\\LL\\xx=\\dd$ where\n$\\LL=\\BB\\RR^{-1}\\BB^\\trp$.\n\nAnd we also made the following claim.\n\\begin{claim}\n  \\begin{equation}\n    \\label{eq:argminflow}\n    \\fftil = \\argmin_{\\BB\\ff=\\dd} \\ff^\\trp\\RR\\ff \\text{ where }\n    \\ff^\\trp\\RR\\ff=\\sum_e \\rr(e)\\ff(e)^2,\n  \\end{equation}\n\\end{claim}\nYou proved this in the exercises for Week 1. Let's recap the proof\nbriefly, just to get back into thinking about electrical flows.\n\\begin{proof}\nConsider any $\\ff\\in\\R^E$ s.t.\\ $\\BB\\ff=\\dd$. For any $\\xx\\in\\R^V$, we have\n\\begin{align*}\n\t\\frac{1}{2}\\ff^\\trp\\RR\\ff\n\t&= \\frac{1}{2}\\ff^\\trp\\RR\\ff  - \\xx^\\trp(\\underbrace{\\BB\\ff-\\dd}_{\\matzero}) \\\\\n\t&\\geq \\min_{\\ff\\in\\R^E} \\underbrace{\\frac{1}{2}\\ff^\\trp\\RR\\ff  - \\xx^\\trp\\BB\\ff + \\dd^\\trp\\xx}_{g(\\ff)}  \\\\\n\t&= \\dd^\\trp\\xx - \\frac{1}{2}\\xx^\\trp\\LL\\xx\n\\end{align*}\nsince $\\nabla_{\\ff}g(\\ff) = \\matzero$ gives us $\\ff=\\RR^{-1}\\BB^\\trp\\xx$. Thus, for all $\\ff\\in\\R^E$ s.t.\\ $\\BB\\ff=\\dd$ and all $\\xx\\in\\R^V$,\n\\begin{equation}\n  \\label{eq:flowsboundedbyvoltages}\n\\frac{1}{2}\\ff^\\trp\\RR\\ff \\geq \\dd^\\trp\\xx -\n  \\frac{1}{2}\\xx^\\trp\\LL\\xx.\n\\end{equation}\nBut for the electrical flow $\\fftil$ and electrical voltage $\\xxtil$, we have $\\fftil=\\RR^{-1}\\BB^\\trp\\xxtil$ and $\\LL\\xxtil=\\dd$. So\n\\[ \\fftil^\\trp\\RR\\fftil = \\left(\\RR^{-1}\\BB^\\trp\\xxtil\\right)^\\trp\\RR\\left(\\RR^{-1}\\BB^\\trp\\xxtil\\right) = \\xxtil^\\trp\\BB\\RR^{-1}\\BB^\\trp\\xxtil = \\xxtil^\\trp\\LL\\xxtil  =\\xxtil^\\trp\\dd. \\]\nTherefore,\n\\begin{equation}\n   \\label{eq:flowattainsvoltagevalue}\n\\frac{1}{2}\\fftil^\\trp\\RR\\fftil = \\dd^\\trp\\xxtil -\n\\frac{1}{2}\\xxtil^\\trp\\LL\\xxtil.\n\\end{equation}\n By combining Equation~\\eqref{eq:flowsboundedbyvoltages} and\n Equation~\\eqref{eq:flowattainsvoltagevalue}, we see that for all\n $\\ff$ s.t.\\ $\\BB \\ff = \\dd$,\n \\[\n \\frac{1}{2}\\ff^\\trp\\RR\\ff \\geq \\dd^\\trp\\xxtil -\n\\frac{1}{2}\\xxtil^\\trp\\LL\\xxtil = \\frac{1}{2}\\fftil^\\trp\\RR\\fftil.\n\\]\nThus $\\fftil$ is the minimum electrical energy flow among all flows\nthat route demand $\\dd$, proving Equation~\\eqref{eq:argminflow} holds.\n\nThe drawing below shows how the quantities line up:\n\\begin{figure}[H]\n  \\centering\n     \\includegraphics[width=\\textwidth]{fig/lecture6_maxminfig.jpeg}\n% \\caption{}\n\\label{fig:regions}\n\\end{figure}\n\\end{proof}\n\n\n\n\\section{Effective Resistance}\nGiven a graph $G=(V,E)$, for any pair of vertices $(a,b)\\in V$, we\nwant to compute the cost (or energy) of routing 1 unit of current\nfrom $a$ to $b$. We call such cost the effective resistance between\n$a$ and $b$, denoted by $\\er(a,b)$. Recall for a single resistor\n$r(a,b)$,\n\\[\n  \\text{energy} =r(a,b)f^2(a,b)=r(a,b)\n  .\n\\]\nSo when we have a graph consisting of just one edge\n$(a,b)$, the effective resistance is just $\\er(a,b)=r(a,b)$.\n\nIn a general graph, we can also consider the energy required to route\none unit of current between two vertices.\nFor any pair $a,b\\in V$, we have\n\\[ \\er(a,b) = \\min_{\\BB\\ff=\\ee_b-\\ee_a} \\ff^\\trp\\RR\\ff, \\]\nwhere $\\ee_v \\in \\mathbb{R}^V$ is the indicator vector of $v$.\nNote that the cost of routing $F$ units of flow from $a$ to $b$ will be $\\er(a,b)\\cdot F^2$.\n\nSince $(\\ee_b-\\ee_a)^\\trp\\matone=0$, we know from the previous section\nthat $\\er(a,b) = \\fftil^\\trp\\RR\\fftil$ where $\\fftil$ is the\nelectrical flow.\nNow we can write\n$\\LL\\xxtil=\\ee_b-\\ee_a$ and $\\xxtil=\\LL^{\\pinv}(\\ee_b-\\ee_a)$ for the\nelectrical voltages routing 1 unit of current from $a$ to $b$.\n% where we let $\\xxtil\\perp\\matone$ to use condition 3) of the\n% pseudoinverse $\\LL^{\\pinv}$.\nNow the energy of routing 1 unit of current from $a$ to $b$ is\n\\[ \\er(a,b) = \\fftil^\\trp\\RR\\fftil = \\xxtil^\\trp\\LL\\xxtil =  (\\ee_b-\\ee_a)^\\trp\\LL^{\\pinv}\\LL\\LL^{\\pinv}(\\ee_b-\\ee_a) = (\\ee_b-\\ee_a)^\\trp\\LL^{\\pinv}(\\ee_b-\\ee_a), \\]\nwhere the last equality is due to\n$\\LL^{\\pinv}\\LL\\LL^{\\pinv}=\\LL^{\\pinv}$.\n\n\\begin{remark}\n  We have now seen several different expressions that all take on the\n  same value: the energy of the electrical flow.\n  It's useful to remind yourself what these are.\n  Consider an electrical flow $\\fftil$ routes demand $\\dd$, and\n  associated electrical voltages\n  $\\xxtil$.\n  We know that $\\BB \\fftil = \\dd$, and $\\ff = \\RR^{-1} \\BB^{\\trp}\n  \\xxtil$,\n  and $\\LL \\xxtil = \\dd$, where $\\LL = \\BB \\RR^{-1} \\BB^{\\trp}$.\n  And we have seen how to express the electrical energy using many\n  different quantities:\n  \\[\n     \\fftil^\\trp\\RR\\fftil  =  \\xxtil^\\trp\\LL\\xxtil = \\dd^\\trp \\LL^{\\pinv}\n     \\dd =\\dd^\\trp\\xxtil = \\fftil^{\\trp}\\BB^{\\trp} \\xxtil\n   \\]\n\\end{remark}\n\n\\begin{claim}\n\tAny PSD matrix $\\AA$ has a PSD square root $\\AA^{1/2}$ s.t.\\ $\\AA^{1/2}\\AA^{1/2}=\\AA$.\n\\end{claim}\n\\begin{proof}\n\tBy the spectral theorem, $\\AA = \\sum_i \\lambda_i\\vv_i\\vv_i^\\trp$ where $\\{\\vv_i\\}$ are orthonormal. Let $\\AA^{1/2} = \\sum_i \\lambda_i^{1/2}\\vv_i\\vv_i^\\trp$. Then\n\t\\begin{align*}\n\t\t\\AA^{1/2}\\AA^{1/2}\n\t\t&= \\left(\\sum_i \\lambda_i^{1/2}\\vv_i\\vv_i^\\trp\\right)^2 \\\\\n\t\t&= \\sum_{i}\\lambda_i \\vv_i\\vv_i^\\trp\\vv_i\\vv_i^\\trp + \\sum_{i\\neq j}\\lambda_i \\vv_i\\vv_i^\\trp\\vv_j\\vv_j^\\trp \\\\\n\t\t&= \\sum_i \\lambda_i\\vv_i\\vv_i^\\trp \\\\\n\t\\end{align*}\n\twhere the last equality is due to $\\vv_i^\\trp\\vv_j = \\delta_{ij}$. It's easy to see that $\\AA^{1/2}$ is also PSD.\n\\end{proof}\n\nLet $\\LL^{+/2}$ be the square root of $\\LL^{+}$. So\n\\[ \\er(a,b) = (\\ee_b-\\ee_a)^\\trp\\LL^{\\pinv}(\\ee_b-\\ee_a) = \\|\\LL^{+/2}(\\ee_b-\\ee_a)\\|^2. \\]\n\n\\paragraph{Example: Effective resistance in a path.}\nConsider a path graph on vertices $V = \\setof{1,2,3,\\ldots, k+1}$,\nwith with resistances $\\rr(1), \\rr(2), \\ldots, \\rr(k)$ on\nthe edges of the path.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{fig/lecture6_seriesres.jpeg}\n  \\caption{A path graph with $k$ edges.}\n\\label{fig:seriesres}\n\\end{figure}\nThe effective resistance between the\nendpoints is\n\\[\n  \\er(1,k+1) = \\sum_{i = 1}^{k} \\rr(i)\n  \\]\nTo see this, observe that to have 1 unit of flow going from vertex $1$ to vertex $k+1$, we must\nhave one unit flowing across each edge $i$.\nLet $\\DDelta(i)$ be the voltage difference across edge $i$, and $\\ff(i)$ the\nflow on the edge.\nThen $1 = \\ff(i) = \\frac{\\DDelta(i)}{\\rr(i)}$, so that $\\DDelta(i) =\n\\rr(i)$.\nThe electrical voltages are then $\\xxtil \\in \\R^V$ where $\\xxtil(i) =\n\\xxtil(1) + \\sum_{j < i} \\DDelta(j)$.\nHence the effective resistance is\n\\[\\er(1,k+1) = \\dd^{\\trp}\\xxtil=  (\\ee_{k+1}-\\ee_{1})^{\\trp}\\xxtil = \\xxtil(k+1) -\n  \\xxtil(1) = \\sum_{i = 1}^{k} \\rr(i)\n.\n\\]\nThis behavior is sometimes known as the fact that the resistance of\nresistors adds up when they are connected in series.\n\n\\paragraph{Example: Effective resistance of parallel edges.}\nSo far, we have only considered graphs with at most one edge between\nany two vertices. But that math also works if we allow a pair of\nvertices to have multiple distinct edges connecting them. We refer to\nthis as \\emph{multi-edges}.\nSuppose we have a graph on just two vertices, $V = \\setof{1,2}$, and\nthese are connected by $k$ parallel multi-edges with resistances\n$\\rr(1), \\rr(2), \\ldots, \\rr(k)$.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.3\\textwidth]{fig/lecture6_parallelres.jpeg}\n  \\caption{A graph on just two vertices with $k$ parallel multiedges.}\n\\label{fig:parallelres}\n\\end{figure}\nThe effective resistance between the endpoints is\n\\[\n  \\er(1,2) =\n  \\frac{1}{\\sum_{i = 1}^k 1/\\rr(i)}\n  .\n\\]\nLet's see why.\nOur electrical voltages $\\xxtil \\in \\R^V$ can be described by just the voltage\ndifference $\\Delta \\in \\R$ between vertex 1 and vertex 2, i.e. $\\xxtil(2)\n- \\xxtil(1) = \\Delta$.\nwhich creates a flow on edge $i$ of $\\fftil(i) = \\Delta/\\rr(i)$.\nThus the total flow from vertex 1 to vertex 2 is\n$1 = \\sum_{i} \\Delta/\\rr(i)$,\nso that $\\Delta =\\frac{1}{\\sum_{i = 1}^k 1/\\rr(i)}$.\nMeanwhile, the effective resistance is also\n\\[\n\\er(1,2) = (\\ee_{2}-\\ee_{1})^{\\trp}\\xxtil = \\Delta =\\frac{1}{\\sum_{i = 1}^k 1/\\rr(i)}\n  \\]\n\\subsection{Effective Resistance is a Distance}\n\\boxdef{\n  \\label{def:dist}\n  Consider a weighted undirected graph $G$ with vertex set $V$.  We\n  say function $d: V \\times V \\to \\R$, which takes a pair of vertices\n  and returns a real number, is a \\emph{distance} if it satisfies\n  \\begin{enumerate}\n  \\item $d(a,a) = 0$ for all $a \\in V$ \\label{enu:distzero}\n  \\item $d(a,b) \\geq 0$ for all $a,b \\in V$. \\label{enu:distnonneg}\n  \\item $d(a,b) = d(b,a)$ for all $a,b \\in V$. \\label{enu:distsym}\n  \\item $d(a,b) \\leq d(a,c) + d(c,b)$ for all $a,b,c \\in\n    V$. \\label{enu:disttri}\n  \\end{enumerate}\n}\n\\begin{lemma}\n  $\\er$ is a distance.\n\\end{lemma}\nBefore proving this lemma, let's see a claim that will help us finish\nthe proof.\n\\begin{claim}\n    \\label{clm:voltageorder}\n    Let $\\LL \\xxtil = \\ee_b - \\ee_a$.\n    Then for all $\\cc \\in V$, we have $\\xxtil(b) \\geq \\xxtil(c) \\geq \\xxtil(a)$.\n  \\end{claim}\n  We only sketch a proof of this claim:\n  \\begin{proof}[Proof sketch]\n    Consider any $c \\in V$, where $c\\neq a,b$.\n    Now $(\\LL \\xxtil)(c) = 0$, i.e.\n    \\[\n      \\left( \\sum_{(u,c)} w(u,c) \\right) \\xxtil(c) - \\left(\n        \\sum_{(u,c)} w(u,c) \\xxtil(u) \\right) = 0\n    \\]\n    Rearranging $ \\xxtil(c) = \\frac{\\sum_{(u,c)} w(u,c) \\xxtil(u)\n    }{\\sum_{(u,c)} w(u,c)}$.\n   This tells us that $\\xxtil(c)$ is a weighted average of the\n   voltages of its neighbors. From this, we can show that $\\xxtil(a)$\n   and $\\xxtil(b)$ are the extreme values.\n  \\end{proof}\n\\begin{proof}\n  It is easy to check that conditions\n  \\ref{enu:distzero}, \\ref{enu:distnonneg}, and \\ref{enu:distsym} of Definition~\\ref{def:dist} are satisfied by\n  $\\er$.\n  Let us confirm condition~\\ref{enu:disttri}.\n\n  For any $u,v$, let $\\xxtil_{u,v} = \\LL^\\pinv ( -\\ee_u + \\ee_v )$.\n  Then\n  \\[\n    \\xxtil_{a,b} = \\LL^\\pinv ( -\\ee_a+ \\ee_b)\n  =  \\LL^\\pinv ( -\\ee_a + \\ee_c - \\ee_c  + \\ee_b)\n  = \\xxtil_{a,c} + \\xxtil_{c,b}\n  .\n\\]\nThus,\n\\begin{align*}\n  \\er(a,b) =  ( -\\ee_a+ \\ee_b)^\\trp \\xxtil_{a,b}\n  &=  ( -\\ee_a+ \\ee_b)^\\trp(\\xxtil_{a,c} + \\xxtil_{c,b})\n  \\\\\n  &= -\\xxtil_{a,c}(a) + \\xxtil_{a,c}(b) -\\xxtil_{c,b}(a) +\n  \\xxtil_{c,b}(b)\n  \\\\\n   &\\leq -\\xxtil_{a,c}(a) + \\xxtil_{a,c}(c) -\\xxtil_{c,b}(c) +\n     \\xxtil_{c,b}(b).\n\\end{align*}\nwhere in the last line we applied Claim~\\ref{clm:voltageorder} to show\nthat $\\xxtil_{a,c}(b) \\leq \\xxtil_{a,c}(c)$ and ${ -\\xxtil_{c,b}(a) \\leq  -\\xxtil_{c,b}(c)}$.\n\\end{proof}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"agao21_script\"\n%%% TeX-engine: luatex\n%%% End:", "meta": {"hexsha": "6ccf6f083866ef7f0c8a1a362171282f38c20134", "size": 13049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture6_mod.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/lecture6_mod.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/lecture6_mod.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": 41.1640378549, "max_line_length": 324, "alphanum_fraction": 0.6497049582, "num_tokens": 4910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6470363046191209}}
{"text": "%!TEX root = paper.tex\r\n\\subsection{Solitary wave on a composite beach} \\label{sec:B_compositebeach}\r\nThis is an laboratory experiment conducted at the Coastal Engineering Laboratory of the U.S. Army Corps of Engineers and it is described in \\url{http://nctr.pmel.noaa.gov/benchmark/Solitary_wave/}, \\url{http://chl.erdc.usace.army.mil/chl.aspx?p=s&a=Projects;36}. \r\nA linear solitary (better called single) wave is propagating over a stepwise increasing bathymetry and it is reflected at a vertical wall on the right boundary. Different wave gauges measure the surface elevation and the runup on the vertical wall. \r\nThe experimental data serve for validation of the models. Additionally to the experimental data, a linear analytic solution is provided, s.t. verification of our models is also tested.\r\n\r\nThree different cases A, B, C with different target wave heights $a_t$, actual (measured) wave heights $a$ and distances $L$ of gauge $G4$ to the first step in the bathymetry at gauge $G5$. Table \\ref{tab:compositebeach_cases} displays the three different cases and belonging data. We only consider case A at the moment. Measured runup data can be found in table \\ref{tab:compositebeach_runup}, but are not compared yet to the simulations.\r\n\r\n\\begin{table}[htbp]\r\n\\begin{tabular}{lllll}\r\n\\textbf{Case} & \\textbf{target $a_t / d$} & \\textbf{actual $a / d$} & \\textbf{dist. G4 to G5 [m]} & \\textbf{dist. G4 to Wall [m]}  \\\\\r\n\\toprule\r\nA       &     0.05   & 0.039    &   2.4   &  10.59     \\\\\r\nB       &     0.30   & 0.264    &   0.89  &   9.17     \\\\\r\nC       &     0.70   & 0.696    &    0.64  &   8.83    \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Data of three different cases}\r\n\\label{tab:compositebeach_cases}\r\n\\end{table}\r\n\r\n\r\n\\begin{table}[htbp]\r\n\\begin{tabular}{lll}\r\n\\textbf{Case} & \\textbf{Runup R [cm]} & \\textbf{R / d} \\\\\r\n\\toprule\r\nA       &        2.74  &  0.13 \\\\\r\nB       &       45.72  &  2.10 \\\\\r\nC       &       27.43  &  1.26 \\\\\r\n\\bottomrule\r\n\\end{tabular}\r\n\\caption{Runup laboratory results of three different cases}\r\n\\label{tab:compositebeach_runup}\r\n\\end{table}\r\n\r\n\r\nThe initial condition is prescribed as \r\n\\begin{itemize}\r\n \\item a linear analytic solitary wave solution\r\n\\begin{align}\r\n\\xi(\\bx,t)&=a_t \\ \\text{cosh}^{-2}(K(x-ct-x_0)), \\\\\r\nu(\\bx,t)&=c\\frac{\\xi(\\bx,t)}{d},\r\n\\end{align}\r\nwith the initial target amplitude $a_t$, propagation velocity $c=\\csw$ on a stepwise reduced depth starting from $d=0.218 \\, \\text{m}$ with scale factor $K=\\sqrt{\\left(\\frac{3a_t}{4d^3}\\right)}$ and displacement $x_0=10.59$, s.t. the initial solitary wave has its maximum at gauge G4 while the entire domain length is $L=24 \\, \\text{m}$. The simulation time is $20$ seconds. \r\n \\item the first option in \\url{https://github.com/rjleveque/nthmp-benchmark-problems/blob/master/BP05-ElenaT-Solitary_wave_on_composite_beach_laboratory/BP5_description.pdf}. The velocities are set to zero and the doubled initial surface elevation $2\\xi$ is prescribed at $x=0$. A doubled domain length of $L=48 \\, \\text{m}$ ensures that the waves reflected at the left boundary are not disturbing the solution. The simulation time is $40$ seconds.\r\n\\end{itemize}\r\nWe impose reflecting boundary conditions at the boundary in x-direction and periodic boundary conditions in y-direction. For the setup see figure \\ref{fig:compositebeach_setup}. \r\nBecause the analytic solution belongs to the linear SWE, corresponding models are expected to represent very good coincidence with this analytic solution.\r\n\r\n\\begin{figure}[htbp]\r\n\\includegraphics[width=\\textwidth]{compositebeach_setup}\r\n\\caption{Setup of the testcase solitary wave on a composite beach}\r\n\\label{fig:compositebeach_setup}\r\n\\end{figure}\r\n\r\n\\subsubsection{Results of \\nh\\ model}\r\nThe results of the first and the seconds option are shifted by 271.5s to match the initial wave at gauge G4. Both are also scaled with a factor of $\\frac{0.037}{0.05}$. % because $0.037$m seems to be the actual amplitude instead of $0.039$.\r\nNo difference between both options is visible in the figures then. Hence, we only plot the results of the (cheaper) first option using the linear SWE model and also the following results obtained with the \\nh\\ model.\r\n\r\nFigures \\eqref{fig:nh_compositebeach_ana_nh_Lhy} and \\eqref{fig:nh_compositebeach_lab_nh_Lhy} display the comparison of the linear SWE with the linear analytic solution and experimental data, respectively.\r\nThe models results compared to the analytic solution are very good, while at gauges G9 and G10 a mismatch is visible, because the nonlinear regime is entered here (d $\\in [0.047,0.117]$m, $a\\approx0.008$m), for which the linear model is not suited.\r\nThe comparison to the experimental data reveals less dispersion and reduced amplitudes, although the overall match is also satisfactory.\r\n\r\nFigures \\eqref{fig:nh_compositebeach_ana_nh_Nnh12} and \\eqref{fig:nh_compositebeach_lab_nh_Nnh12} display the comparison of the \\nh\\ equations using both the linear and the quadratic pressure profile with the linear analytic solution and experimental data, respectively. The \\nh\\ wave profile represents well the amplitudes, the shape of the propagating wave, the propagation velocities and also the developed dispersive wave train after reflecting of the laboratory surface elevation. The agreement with the linear analytic solution is worse, but still okay.\r\nWhen wave hits step, the numerical sea surface height is not as much increased as the amplitude of exp data. \r\n\r\nDifferences between both vertical pressure profiles are small, because dispersive effects become more significant after longer simulation time. However, the tendency of the linear profile to overestimate amplitudes, which was also visible in figure \\ref{fig:nh_solitarywave}, is confirmed here, too. Additionally, we see that is also true not only for global maxima, but also for local maxima.\r\n\r\nThe analytic solution is a good test for the verification of the linear SWE model, whereas the laboratory data show its limits of applicability as well as that the dispersive model gives a more accurate physical representation of the experimental data.\r\n\r\nNeed to do: wq refl b.c. may be not good enough (not explicit treatment at the moment), edge integrals are missing.\r\n\r\n\r\n\\begin{figure}[htbp]\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G4_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G5_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G6_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G7_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G8_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G9_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G10_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_Wall_nh_Lhy}\r\n\\end{minipage}\r\n\\caption{Comparison of the analytical (black) sea surface height of the\r\nsolitary wave with the simulation results of the \\nh\\ model in its version of linear shallow water equations (blue)}\r\n\\label{fig:nh_compositebeach_ana_nh_Lhy}\r\n\\end{figure}\r\n\r\n\\begin{figure}[htbp]\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G4_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G5_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G6_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G7_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G8_nh_Lhy}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G9_nh_Lhy}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{0.48\\textwidth}\r\n\\includegraphics[width=\\textwidth]{compositebeach_lab_G10_nh_Lhy}\r\n\\end{minipage} \r\n\\begin{minipage}{0.45\\textwidth}\r\n\\begin{tabular}{lll}\r\n\\textbf{Data} & \\textbf{Runup} & \\textbf{R / d} \\\\\r\n              & \\textbf{R [cm]} &  \\\\\r\n\\toprule\r\nExp.  &  2.74   &  0.13 \\\\\r\nModel hydr. &  2.13   &  0.0978 \\\\\r\n\\end{tabular}\r\n\\end{minipage}\r\n\\caption{Comparison of the experimental (black) sea surface height of the\r\nsolitary wave with the simulation results of the \\nh\\ model in its version of linear shallow water equations (blue). The model runup is also scaled with 0.75.}\r\n\\label{fig:nh_compositebeach_lab_nh_Lhy}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\begin{figure}[htbp]\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G4_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G5_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G6_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G7_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G8_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G9_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_G10_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_ana_Wall_nh_Nnh12}\r\n\\end{minipage}\r\n\\caption{Comparison of the analytical (black) sea surface height of the\r\nsolitary wave with the simulation results of the \\nh\\ model in its \\nh\\ version using the linear (yellow) and the quadratic vertical pressure profile (red)}\r\n\\label{fig:nh_compositebeach_ana_nh_Nnh12}\r\n\\end{figure}\r\n\r\n\\begin{figure}[htbp]\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G4_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G5_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G6_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G7_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{\\textwidth}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G8_nh_Nnh12}\r\n\\includegraphics[width=0.48\\textwidth]{compositebeach_lab_G9_nh_Nnh12}\r\n\\end{minipage} \\\\\r\n\\begin{minipage}{0.48\\textwidth}\r\n\\includegraphics[width=\\textwidth]{compositebeach_lab_G10_nh_Nnh12}\r\n\\end{minipage} \r\n\\begin{minipage}{0.45\\textwidth}\r\n\\begin{tabular}{lll}\r\n\\textbf{Data} & \\textbf{Runup} & \\textbf{R / d} \\\\\r\n              & \\textbf{R [cm]} &  \\\\\r\n\\toprule\r\nExp.  &  2.74   &  0.13 \\\\\r\nModel lin.&  2.18   &  0.10 \\\\\r\nModel quadr.&  2.12   &  0.097 \\\\\r\n\\end{tabular}\r\n\\end{minipage}\r\n\\caption{Comparison of the experimental (black) sea surface height of the\r\nsolitary wave with the simulation results of the \\nh\\ model in its \\nh\\ version using the linear (yellow) and the quadratic vertical pressure profile (red). The model runup is also scaled with 0.75.}\r\n\\label{fig:nh_compositebeach_lab_nh_Nnh12}\r\n\\end{figure}\r\n", "meta": {"hexsha": "73f193cda543d61b373c754046ccf8ac951744c3", "size": 10947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/papers/theoretical_1d/B_compositebeach.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/B_compositebeach.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/B_compositebeach.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": 60.8166666667, "max_line_length": 560, "alphanum_fraction": 0.7582899424, "num_tokens": 3247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6470363004562094}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n\\begin{document}\n\n\\section*{Inline (within text) formulas}\n\nThe equation $x + x = 2x$ is inside a text, which uses the \\TeX{} shorthand.\nIn addition, an equation can be written like \\(x \\cdot x = x^2\\) as well, using the \\LaTeX{} shorthand.\nFinally, the environment \\emph{math} can be used like this \\begin{math}a^2 + b + c = 0\\end{math}.\n\nWe can force symbols to be displayed like displayed formula. For example the formula $\\sum_{k=0}^{10}k$ can be written $\\displaystyle\\sum_{k=0}^{10}k$ as well. The sum symbol is taller within a sentence using the command \\emph{\\textbackslash displaystyle}.\n\n\\section*{Displayed equations}\n\nThe recommended syntax to render a floating equation is to use the syntax below.\n\n\\[a \\cdot x = ax \\]\n\nThe use of the syntax \\emph{\\$\\$$\\cdots$\\$\\$} should be avoided, because, it will modify vertical spacing within equations, rendering them inconsistent.\n\nFinally, the environment \\emph{displaymath} produces the same effect.\n\n\\begin{displaymath}\n\tx^2 \\cdot x^2 = x^4\n\\end{displaymath}\n\n\\section*{Equation numbering}\n\nThe environment \\emph{equation} automatically numbers the equations.\n\n\\begin{equation} \n\tf(x)=(x+a)(x+b)\n\\end{equation}\n\n\\end{document}", "meta": {"hexsha": "388052b80982c418a07fafa45ba51b193935635d", "size": 1263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/environments.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/environments.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/environments.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.2368421053, "max_line_length": 256, "alphanum_fraction": 0.7339667458, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140728, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6470362970866129}}
{"text": "In the appendix, we define a number of concepts and describe a number of\ntechniques that are utilized extensively throughout the thesis.\n\n\\section{Linear Algebra}\n\\inputsection{linear-algebra}\n\n\\section{Probability Theory}\n\\xlab{probability-theory}\n\\inputsection{probability-theory}\n\n\\section{Bayesian Statistics}\n\\xlab{bayesian-statistics}\n\\inputsection{bayesian-statistics}\n\n\\section{Probability Transformation}\n\\xlab{probability-transformation}\n\\inputsection{probability-transformation}\n\n\\section{Numerical Integration}\n\\xlab{numerical-integration}\n\\inputsection{numerical-integration}\n\n\\section{Hierarchical Interpolation}\n\\xlab{hierarchical-interpolation}\n\\inputsection{hierarchical-interpolation}\n\n\\section{Polynomial Chaos}\n\\xlab{polynomial-chaos}\n\\inputsection{polynomial-chaos}\n", "meta": {"hexsha": "f0aee9f1f17065d2cea798a4f622a721b6113db0", "size": 787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/appendix.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/appendix.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/appendix.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": 26.2333333333, "max_line_length": 72, "alphanum_fraction": 0.833545108, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6470362929517488}}
{"text": "\\subsubsection{Hyperboloids of One Sheet}\r\n\\noindent\r\nA hyperboloid of one sheet has 2 +'s and 1 - in its equation. It is one fully connected surface.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./differentialMultivariableCalculus/one_sheet.png}\r\n\t\\caption{A hyperboloid of one sheet}\r\n\\end{figure}", "meta": {"hexsha": "b459ffc3eb14869d7a9639a83d36303cc8040d2d", "size": 329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/hyperboloidOneSheet.tex", "max_stars_repo_name": "wmboyles/Math-Summaries", "max_stars_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "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/hyperboloidOneSheet.tex", "max_issues_repo_name": "wmboyles/Math-Summaries", "max_issues_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "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/hyperboloidOneSheet.tex", "max_forks_repo_name": "wmboyles/Math-Summaries", "max_forks_repo_head_hexsha": "94732081a5b6913d84e11c62a3989b63f9934b56", "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.5555555556, "max_line_length": 97, "alphanum_fraction": 0.7629179331, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6470129588908152}}
{"text": "\\chapter{Modal analysis}\\label{chap:modalanalysis}\nWhen external forces act on a multi degree-of-freedom system, the system\nundergoes forced vibration.\nFor a system with three coordinates or degrees of freedom, the governing\nequation of motion are a set of three coupled ordinary differential equations of\nsecond second order.\nThe equations of motion of a multi degree-of-freedom system under external force\nare given by:\n\\begin{equation}\n  \\label{eq:modal}\n  [\\mathbf{M}] \\ddot{\\vec{x}} + [\\mathbf{K}] \\vec{x} = \\vec{\\mathbf{F}}\n\\end{equation}\nThe equation \\eqref{eq:modal} represents the system in the version without\ndamping, where \\(\\vec{\\mathbf{F}}\\) is the vector of the external force.\n\\section{Forced vibration of undamped system}\\label{sec:eigen}\nTo solve the equation \\eqref{eq:modal} by modal analysis, it is necessary first\nto solve the eigenvalue problem and find the natural frequencies \\(\\omega_1,\n\\dots, \\omega_n\\) as reported below:\n\\(\\omega_{1} = 8.27843\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{2} = 27.40935\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{3} = 41.87035\\) [\\si{\\radian\\per\\second}];\nand the corresponding normal modes:\n\\begin{equation}\n\t\\label{eq:eiegnmodefree}\n \t[\\mathbf{U}] = \\begin{bmatrix*}[r]\n \t\t1.00000 & 1.00000 & 1.00000 \\\\\n\t\t0.86540 &-0.47555 &-2.44325 \\\\\n\t\t0.61945 &-1.28034 & 2.15533 \\\\\n \t\\end{bmatrix*}\n\\end{equation}\n\\section{Forced vibration of viscous damped system}\\label{sec:viscoussystem}\nModal analysis, as presented in previous section \\ref{sec:eigen}, applies only\nto undamped systems.\nIn many cases, the influence of damping upon the response of a vibratory system\nis minor and can be disregarded. However, it must be considered if the response\nof the system is required for a relatively long period of time compared to the\nnatural periods of the system. Further, if the frequency of excitation is at or\nnear one of the natural frequencies of the system, damping is of primary\nimportance and must be taken into account. In general, since the effects are not\nknown in advance, damping must be considered in the vibration analysis of any\nsystem, thus using the equation of motion:\n\\begin{equation}\\label{eq:modaldamping}\n  [\\mathbf{M}] \\ddot{\\vec{x}} + [\\mathbf{C}] \\dot{\\vec{x}} +[\\mathbf{K}] \\vec{x}\n   = \\vec{\\mathbf{F}}\n\\end{equation}\n%\nThen we can consider for which the damping matrix can be expressed as a linear\ncombination of the mass and stiffness matrices:\n\\begin{equation}\n\\label{eq:moadlpropdamping}\n\t[C] = \\alpha \\cdot [\\mathbf{M}] + \\beta \\cdot [\\mathbf{K}]\n\\end{equation}\nwhere \\(\\alpha\\) and \\(\\beta\\) are constant. By substituting in\n\\eqref{eq:modaldamping}, we obtain:\n\\begin{equation}\\label{eq:modaldampingcomplete}\n\t[\\mathbf{M}] \\ddot{\\vec{x}} +\n\t[\\alpha [\\mathbf{M}] + \\beta[\\mathbf{K}]] \\dot{\\vec{x}} +\n\t[\\mathbf{K}] \\vec{x}= \\vec{\\mathbf{F}}\n\\end{equation}\nBy expressing the solution vector \\(\\vec{x}\\) as linear combination of the\nnatural mode of the undamped system. Substituting \\(x(t) = [\\mathbf{U}]q(t)\\)\nin the equation \\eqref{eq:modaldampingcomplete} and pre-multiplying by \n\\([\\mathbf{U}]^{\\top}\\) we obtain:\n\\begin{equation}\\label{eq:modaldampingexpansed}\n\t[\\mathbf{U}]^{\\top}[\\mathbf{M}][\\mathbf{U}] \\ddot{\\vec{q}} +\n\t[\\alpha[\\mathbf{U}]^{\\top}[\\mathbf{M}][\\mathbf{U}] +\n   \\beta[\\mathbf{U}]^{\\top}[\\mathbf{K}]][\\mathbf{U}] \\dot{\\vec{q}} +\n\t[\\mathbf{U}]^{\\top}[\\mathbf{K}][\\mathbf{U}]^{\\top} \\vec{q} =\n  [\\mathbf{U}]^{\\top}\\vec{\\mathbf{F}}\n\\end{equation}\n%\nIf the eigenvectors \\(\\vec{\\mathbf{U}}^{(j)}\\) are normalized we can rewrite in \ndecoupled form:\n\\begin{equation}\\label{eq:decupled}\n  \\ddot{q}_{i}(t) + (\\alpha + \\omega_{i}^2\\beta)\\dot{q}_{i}(t) +\n  \\omega_{i}^{2}q(t) = Q_{i}(t)\n\\end{equation}\nwhere: \\(\\omega_{1} = 8.27799\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{2} = 27.40863\\) [\\si{\\radian\\per\\second}],\n\\(\\omega_{3} = 41.91576\\) [\\si{\\radian\\per\\second}] are\nthe natural frequencies of the undamped system.\nThe eigenvector are reported in \\eqref{eq:eiegnmodeprop}.\n\\begin{equation}\\label{eq:eiegnmodeprop}\n\t[\\mathbf{U}] = \\begin{bmatrix*}[r]\n\t\t1.00000 & 1.00000 & 1.00000 \\\\\n\t\t0.86499 &-0.48006 &-2.46147 \\\\\n\t\t0.61907 &-1.28528 & 2.16954 \\\\\n \t\\end{bmatrix*}\n\\end{equation}\nIn the equation \\eqref{eq:decupled} substituting the relationship with \n\\(\\alpha + \\omega^{2}_{i}\\beta = 2\\,\\zeta_{i}\\,\\omega_{i}\\), where\n\\(\\zeta_{i}\\) is called \\emph{modal damping ratio} for the \\(i_\\text{th}\\) normal\nmode, equation \\eqref{eq:decupled} we obtain:\n\\begin{equation}\\label{eq:decupled2}\n  \\ddot{q}_{i}(t) + 2\\zeta_{i}\\omega_{i}\\dot{q}_{i}(t) +\n  \\omega_{i}^{2}q(t) = Q_{i}(t)\n\\end{equation}\nIt can be seen that each of then equations represented by this expression is\nuncoupled from all of the others.\nHence we can find the response of the \\(i_\\text{th}\\) mode in the same manner\nas that of a viscously damped single-degree-of-freedom system.\n%\nThe identification of the sources and magnitude of damping is difficult in most\npractical problems.\nThe condition given by equation \\eqref{eq:moadlpropdamping} is sufficient but not\nnecessary for the existence of normal modes in damped systems.\nThe necessary condition is that the transformation that diagonalizes the damping\nmatrix also uncouples the coupled equations of motion.\nThis condition is less restrictive than equation \\eqref{eq:moadlpropdamping}\nand covers more possibilities.\nIn the general case of damping, the damping matrix cannot be diagonalized\nsimultaneously with the mass and stiffness matrices.\nA common procedure for finding the solution of the eigenvalue problem of a\ndamped system involves the transformation of the coupled second-order\nequations of motion into \\(2n\\) uncoupled first-order equation.\n%\n\\input{rayleigh}\n\\input{matrixiterationmethod}\n", "meta": {"hexsha": "c0c972950924025cb7b7c9d778428d9c9b6debb7", "size": 5700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Modal.tex", "max_stars_repo_name": "frank1789/MechanicalVibrationProject", "max_stars_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-28T12:59:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-28T12:59:41.000Z", "max_issues_repo_path": "Report/Modal.tex", "max_issues_repo_name": "frank1789/MechanicalVibrationProject", "max_issues_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_issues_repo_licenses": ["MIT"], "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/Modal.tex", "max_forks_repo_name": "frank1789/MechanicalVibrationProject", "max_forks_repo_head_hexsha": "ad28e4c047fe4f806fa1fb5405b2304699e377be", "max_forks_repo_licenses": ["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.8991596639, "max_line_length": 81, "alphanum_fraction": 0.7222807018, "num_tokens": 1826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672089305841, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.647012945581988}}
{"text": "\\documentclass{article}\n\n\\usepackage{multicol}\n\\usepackage{caption}\n\\usepackage{amsmath}\n\\usepackage{tikz}\n\\usepackage{pgfplots}\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,\n    urlcolor=cyan,\n}\n\n\\usepackage{geometry}\n\\geometry{\n\ta3paper,\n\tnoheadfoot=true,\n\tleft=1.0in,\n\tright=1.0in,\n\ttop=1.0in,\n\tbottom=1.0in\n}\n\\usetikzlibrary{decorations.pathreplacing}\n\\usepgfplotslibrary{external}\n\n\\definecolor{myLightGray}{RGB}{191,191,191}\n\\definecolor{myGray}{RGB}{160,160,160}\n\\definecolor{myDarkGray}{RGB}{144,144,144}\n\\definecolor{myDarkRed}{RGB}{167,114,115}\n\\definecolor{myRed}{RGB}{255,58,70}\n\\definecolor{myGreen}{RGB}{0,255,71}\n\n% Titling and Author\n\\title{Latex Tikz Examples, Linear Equation Plotting, Linear Spline}\n\\author{\\href{https://fanwangecon.github.io/}{Fan Wang}\\thanks{https://fanwangecon.github.io, repository: \\href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%\n%%% Line Values\n%%%%%%%%%%%%%%%%%%%%%\n% A. slopes of lines a b c d\n\\def\\ssa{0.8}\n\\def\\ssb{1.0}\n\\def\\ssc{2}\n\\def\\ssd{0.6}\n% B. y-intercepts of lines a b c d\n\\def\\iia{+1.0}\n\\def\\iib{+0.0}\n\\def\\iic{-1.0}\n\\def\\iid{-1.5}\n% Other parameters\n\\def\\rescale{4}\n\n%%%%%%%%%%%%%%%%%%%%%\n%%% Line Formatting\n%%%%%%%%%%%%%%%%%%%%%\n% A. color definitions\n\\def\\cla{blue}\n\\def\\clb{black}\n\\def\\clc{red}\n\\def\\cld{green}\n\n%%%%%%%%%%%%%%%%%%%%%\n%%% Draw Lines\n%%%%%%%%%%%%%%%%%%%%%\n\\begin{multicols}{3}\n[\n\\section{Tikz Four Lines}\nDraw four lines, sum them up linear spline, then invert. A3 page has 29.7 cm width. Below, width is 7 cm for each plot, so 21 cm all together generally. Margins are 1 inch on each side, so about 5 cm together.\n]\n\n\\subsection{Four Relative Allocation Lines}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N_m$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N_{m^{\\prime}}$};\n    \\draw[line width=0.25mm,domain=-2:4,smooth,variable=\\x, \\cla] plot ({\\x},{\\iia+\\x*\\ssa});\n    \\draw[line width=0.25mm,domain=-2:4,smooth,variable=\\x, \\clb] plot ({\\x},{\\iib+\\x*\\ssb});\n    \\draw[line width=0.25mm,domain=-2:4,smooth,variable=\\x, \\clc] plot ({\\x},{\\iic+\\x*\\ssc});\n    \\draw[line width=0.25mm,domain=-2:4,smooth,variable=\\x, \\cld] plot ({\\x},{\\iid+\\x*\\ssd});\n\\end{tikzpicture}\n\n\\subsection{Inequality Constrained $Y > 0$}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N_m$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N_{m^{\\prime}}$};\n    \\draw[line width=0.25mm,domain=(-\\iia/\\ssa):4,smooth,variable=\\x, \\cla] plot ({\\x},{\\iia+\\x*\\ssa});\n    \\draw[line width=0.25mm,domain=(-\\iib/\\ssb):4,smooth,variable=\\x, \\clb] plot ({\\x},{\\iib+\\x*\\ssb});\n    \\draw[line width=0.25mm,domain=(-\\iic/\\ssc):4,smooth,variable=\\x, \\clc] plot ({\\x},{\\iic+\\x*\\ssc});\n    \\draw[line width=0.25mm,domain=(-\\iid/\\ssd):4,smooth,variable=\\x, \\cld] plot ({\\x},{\\iid+\\x*\\ssd});\n\\end{tikzpicture}\n\n\\subsection{Sum $Y > 0$}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N_m$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N$};\n    \\draw[line width=0.25mm,domain=(-\\iia/\\ssa):4,smooth,variable=\\x, \\cla]\n        plot ({\\x},{(\\iia+\\x*\\ssa)});\n    \\draw[line width=0.25mm,domain=(-\\iib/\\ssb):4,smooth,variable=\\x, \\clb]\n        plot ({\\x},{((\\iia+\\iib)+\\x*(\\ssa+\\ssb))});\n    \\draw[line width=0.25mm,domain=(-\\iic/\\ssc):4,smooth,variable=\\x, \\clc]\n        plot ({\\x},{((\\iia+\\iib+\\iic)+\\x*(\\ssa+\\ssb+\\ssc))});\n    \\draw[line width=0.25mm,domain=(-\\iid/\\ssd):4,smooth,variable=\\x, \\cld]\n        plot ({\\x},{((\\iia+\\iib+\\iic+\\iid)+\\x*(\\ssa+\\ssb+\\ssc+\\ssd))});\n\\end{tikzpicture}\n\n\\subsection{Sum $Y > 0$ Rescale}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N_m$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N$};\n    \\draw[line width=0.25mm,domain=(-\\iia/\\ssa):4,smooth,variable=\\x, \\cla]\n        plot ({\\x},{(\\iia+\\x*\\ssa)/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iib/\\ssb):4,smooth,variable=\\x, \\clb]\n        plot ({\\x},{((\\iia+\\iib)+\\x*(\\ssa+\\ssb))/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iic/\\ssc):4,smooth,variable=\\x, \\clc]\n        plot ({\\x},{((\\iia+\\iib+\\iic)+\\x*(\\ssa+\\ssb+\\ssc))/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iid/\\ssd):4,smooth,variable=\\x, \\cld]\n        plot ({\\x},{((\\iia+\\iib+\\iic+\\iid)+\\x*(\\ssa+\\ssb+\\ssc+\\ssd))/\\rescale});\n\\end{tikzpicture}\n\n\\subsection{$Y > 0$--Linear Spline}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N_m$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N$};\n    \\draw[line width=0.25mm,domain=(-\\iia/\\ssa):(-\\iib/\\ssb),smooth,variable=\\x, \\cla]\n        plot ({\\x},{(\\iia+\\x*\\ssa)/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iib/\\ssb):(-\\iic/\\ssc),smooth,variable=\\x, \\clb]\n        plot ({\\x},{((\\iia+\\iib)+\\x*(\\ssa+\\ssb))/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iic/\\ssc):(-\\iid/\\ssd),smooth,variable=\\x, \\clc]\n        plot ({\\x},{((\\iia+\\iib+\\iic)+\\x*(\\ssa+\\ssb+\\ssc))/\\rescale});\n    \\draw[line width=0.25mm,domain=(-\\iid/\\ssd):4,smooth,variable=\\x, \\cld]\n        plot ({\\x},{((\\iia+\\iib+\\iic+\\iid)+\\x*(\\ssa+\\ssb+\\ssc+\\ssd))/\\rescale});\n\\end{tikzpicture}\n\n% (((\\iia+\\iib)+((-\\iib/\\ssb))*(\\ssa+\\ssb))/\\rescale)\n\\subsection{Summed Lines Invert}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N_m$};\n    \\clip (-3,-3) rectangle (7,4);\n    \\draw[line width=0.25mm,\n            domain=((\\iia+(-\\iia/\\ssa)*\\ssa)/\\rescale):4,\n            smooth,variable=\\x, \\cla]\n        plot ({\\x},{ ((\\x*\\rescale-\\iia)/\\ssa)});\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib)+(-\\iib/\\ssb)*(\\ssa+\\ssb))/\\rescale):4,\n            smooth,variable=\\x, \\clb]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib))/(\\ssa+\\ssb)) });\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib+\\iic)+(-\\iic/\\ssc)*(\\ssa+\\ssb+\\ssc))/\\rescale):4,\n            smooth,variable=\\x, \\clc]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib+\\iic))/(\\ssa+\\ssb+\\ssc)) });\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib+\\iic+\\iid)+(-\\iid/\\ssd)*(\\ssa+\\ssb+\\ssc+\\ssd))/\\rescale):4,\n            smooth,variable=\\x, \\cld]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib+\\iic+\\iid))/(\\ssa+\\ssb+\\ssc+\\ssd)) });\n\\end{tikzpicture}\n\n\\subsection{Spline Invert}\n\\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (4,0) node[right] {$N$};\n    \\draw[->] (0,-3) -- (0,4) node[above] {$N_m$};\n    \\clip (-3,-3) rectangle (7,4);\n    \\draw[line width=0.25mm,\n            domain=((\\iia+(-\\iia/\\ssa)*\\ssa)/\\rescale):(((\\iia+\\iib)+(-\\iib/\\ssb)*(\\ssa+\\ssb))/\\rescale),\n            smooth,variable=\\x, \\cla]\n        plot ({\\x},{ ((\\x*\\rescale-\\iia)/\\ssa)});\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib)+(-\\iib/\\ssb)*(\\ssa+\\ssb))/\\rescale):(((\\iia+\\iib+\\iic)+(-\\iic/\\ssc)*(\\ssa+\\ssb+\\ssc))/\\rescale),\n            smooth,variable=\\x, \\clb]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib))/(\\ssa+\\ssb)) });\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib+\\iic)+(-\\iic/\\ssc)*(\\ssa+\\ssb+\\ssc))/\\rescale):(((\\iia+\\iib+\\iic+\\iid)+(-\\iid/\\ssd)*(\\ssa+\\ssb+\\ssc+\\ssd))/\\rescale),\n            smooth,variable=\\x, \\clc]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib+\\iic))/(\\ssa+\\ssb+\\ssc)) });\n    \\draw[line width=0.25mm,\n            domain=(((\\iia+\\iib+\\iic+\\iid)+(-\\iid/\\ssd)*(\\ssa+\\ssb+\\ssc+\\ssd))/\\rescale):4,\n            smooth,variable=\\x, \\cld]\n        plot ({\\x},{ ((\\x*\\rescale-(\\iia+\\iib+\\iic+\\iid))/(\\ssa+\\ssb+\\ssc+\\ssd)) });\n\\end{tikzpicture}\n\n\n\\end{multicols}\n\n\\end{document}\n", "meta": {"hexsha": "c9b3b9f594f7f5eecbfae148ac417222784e6048", "size": 7473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_other/tikz/fplot/functionplot.tex", "max_stars_repo_name": "guohui-jiang/Tex4Econ", "max_stars_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_other/tikz/fplot/functionplot.tex", "max_issues_repo_name": "guohui-jiang/Tex4Econ", "max_issues_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_other/tikz/fplot/functionplot.tex", "max_forks_repo_name": "guohui-jiang/Tex4Econ", "max_forks_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_forks_repo_licenses": ["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.1256544503, "max_line_length": 209, "alphanum_fraction": 0.5577412017, "num_tokens": 3004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6470000531613432}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage[margin=1.5in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage[shortlabels]{enumitem}\n\n\n\\setlength\\parindent{0pt}\n\\newcommand{\\code}{\\lstinline[basicstyle=\\small]}\n\\lstset{\n    language=Python,\n    basicstyle=\\scriptsize\n}\n\n\n\\title{EE2703: Applied Programming Lab \\\\ \\Large Assignment 4: Fourier Approximations}\n\\author{Soham Roy \\\\ \\normalsize EE20B130}\n\\date{\\today}\n\\begin{document}\n\n\\maketitle % Insert the title, author and date\n\n\n\\section{Introduction}\nTwo functions, $exp(x)$ and $cos(cos(x))$ over the interval $[0,2\\pi)$ will be modeled using\nthe fourier series:\n\\begin{equation*}\n    a_0 + \\sum_{n=1}^{\\infty} \\{a_n \\cos(nx) + b_n \\sin(nx)\\}\n\\end{equation*}\nWhere,\n\\begin{align*}\n    a_0 & = \\frac{1}{2\\pi} \\int_{0}^{2\\pi} f(x) dx       \\\\\n    a_n & = \\frac{1}{\\pi} \\int_{0}^{2\\pi} f(x)cos(nx) dx \\\\\n    a_n & = \\frac{1}{\\pi} \\int_{0}^{2\\pi} f(x)sin(nx) dx \\\\\n\\end{align*}\n\\pagebreak\n\n\n\\section{Subquestions}\n\\subsection{Define \\& Plot Python Functions}\nTwo Python functions are defined:\n\n% \\par\\rule{\\linewidth}{0.4pt}\n\\begin{lstlisting}\n    def exp(x):  # exponential function, supports value or vector\n        return np.exp(x)\n\n    def coscos(x):  # cos of cos function, supports value or vector\n        return np.cos(np.cos(x))\n\\end{lstlisting}\n% \\par\\rule[1.5ex]{\\linewidth}{0.4pt}\n\nThe functions have been plotted with their periodic extensions ($2\\pi$ period):\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{1a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{1b.png}\n\\end{figure}\n\\pagebreak\n\n\n\\subsection{Evaluate Integrals}\nThe integrands have been defined as functions of \\code{x}, \\code{k}, and \\code{f}, where\n\\code{f} is the Python function to be approximated, i.e. \\code{exp} or \\code{coscos}:\n\\begin{lstlisting}\n    def u(x, k, f):  # f is either exp or coscos\n        return f(x) * np.cos(k * x)\n\n    def v(x, k, f):  # f is either exp or coscos\n        return f(x) * np.sin(k * x)\n\\end{lstlisting}\nThe integrals to calculate the values of $a_n$ and $b_n$ have been evaluated using the following loop:\n\\begin{lstlisting}\n    F = [exp, coscos]\n    a_0 = np.zeros((2))\n    a_n = np.zeros((2, 25))\n    b_n = np.zeros((2, 25))\n\n    for i in range(2):  # iterate over exp and coscos\n        a_0[i] = quad(F[i], 0, 2 * np.pi)[0] / (2 * np.pi)\n\n    for j in range(25):  # integration\n        a_n[i, j] = quad(u, 0, 2 * np.pi, args=(j + 1, F[i]))[0] / np.pi\n        b_n[i, j] = quad(v, 0, 2 * np.pi, args=(j + 1, F[i]))[0] / np.pi\n\\end{lstlisting}\n\n\n\\subsection{Plot the Fourier Coefficients}\nThe answer vector $c$ has been generated by:\n\\begin{lstlisting}\n    c_n = np.zeros((2, 51))  # c_n[0] and c_n[1] are the answer vectors\n    c_n[:, 0] = a_0\n    c_n[:, 1::2] = a_n  # alternate elements starting at 1\n    c_n[:, 2::2] = b_n  # alternate elements starting at 2    \n\\end{lstlisting}\n\nTo plot in semilog scale, for example, we use:\n\\begin{lstlisting}\n    plt.semilogy(0, np.abs(a_0[f_i]), 'ro', label=\"by integration\")\n    plt.semilogy(range(1, 26), np.abs(a_n[f_i]), 'ro')\n    plt.semilogy(range(1, 26), np.abs(b_n[f_i]), 'ro')\n\\end{lstlisting}\n\nThe coefficients $|a_n|$ and $|b_n|$ have been plotted:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.39]{3a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.39]{3b.png}\n\\end{figure}\n\n\n\\begin{enumerate}[(a)]\n    \\item The $b_n$ coefficients for $cos(cos(x))$ are of the order of magnitude $-16$, i.e. nearly zero. \\\\\n          This is because $cos(cos(x))$ is an even function, and thus does not have any odd component.\n    \\item $cos(cos(x))$ is a periodic function, comprising not many frequencies. \\\\\n          $e^x$, on the other hand, is a non-periodic function, and thus its periodic extension has multiple\n          discontinuities. Hence, high frequency components are required to represent this function as a sum\n          of trigonometric functions.\n    \\item The $loglog$ plot is linear for $e^x$ because the $log$ of its coefficients vary linearly with\n          $log(n)$, i.e. the coefficients depend on $\\frac{1}{n^a}$ for some $a$. \\\\\n          On the other hand, the $semilog$ plot is linear for $cos(cos(x))$ because the $log$ of its\n          coefficients vary linearly with $n$, i.e. the coefficients decay exponentially.\n\\end{enumerate}\n\n\n\\subsection{Least Squares}\nThe equation to be solved by \\code{scipy.linalg.lstsq} is:\n\\begin{equation*}\n    Ac = B\n\\end{equation*}\n\nThe matrix $A$ has been generated by:\n\\begin{lstlisting}\n    A = np.ones((400, 51))  # first column should be ones\n    for k in range(1, 26):\n        A[:, 2 * k - 1] = np.cos(k * x)\n        A[:, 2 * k] = np.sin(k * x)\n\\end{lstlisting}\n\nThe solution matrices are \\code{c[0]} for $e^x$ and\n\\code{c[1]} for $coscos(x)$:\n\\begin{lstlisting}\n    for i in range(2):\n        b = F[i](x)\n        c[i] = lstsq(A, b)[0]\n\\end{lstlisting}\n\n\n\\subsection{Plot the Best Fit Coefficients}\nTo plot in semilog scale, for example, we use:\n\\begin{lstlisting}\n    plt.semilogy(0, np.abs(c[f_i][0]), 'go', label=\"by least squares\")\n    plt.semilogy(range(1, 26), np.abs(c[f_i][1::2]), 'go')\n    plt.semilogy(range(1, 26), np.abs(c[f_i][2::2]), 'go')\n\\end{lstlisting}\n\nThe coefficients $|a_n|$ and $|b_n|$ by least squares method have been contrasted with\nthose by integration:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.39]{5a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.39]{5b.png}\n\\end{figure}\n\n\n\\subsection{Compare Least Squares and Direct Integration}\nThe maximum errors between the least squares and direct integration methods has been calculated:\n\\begin{lstlisting}\n    np.max(np.abs(c[0] - c_n[0]))  # for e^x\n    np.max(np.abs(c[1] - c_n[1]))  # for coscos(x)\n\\end{lstlisting}\n\n\\begin{tabular}{lcl}\n    The largest deviation of coefficients for & $e^x$         & is : 1.3327     \\\\\n    The largest deviation of coefficients for & $cos(cos(x))$ & is : 2.6684e-15\n\\end{tabular}\n\\medskip\n\nThe error is significant for $e^x$ but negligible for $cos(cos(x))$. \\\\\nThis is because there are multiple discontinuities in the periodic extension of $e^x$, and thus\nwould require a much higher number of coefficients to be somewhat accurately represented. \\\\\nThis lack in accuracy is more apparent close to those discontinuities.\n\n\\subsection{Plot the Fourier Approximations}\nThe functions as represented by the Fourier coefficients calculated through the least squares method\nhave been plotted:\n\\begin{lstlisting}\n    plt.plot(x[200:600], np.dot(A, c[1]), 'go', label=\"by least squares\")\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{7a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{7b.png}\n\\end{figure}\n\nThe $cos(cos(x))$ plot agrees nearly perfectly, but the $e^x$ plot has a large deviation.\nThis is because unlike $cos(cos(x))$, which has periodic components, the $e^x$ function\nis not inherently comprised of periodic trigonometric functions. The periodic extension of $e^x$\nhas multiple discontinuities, which causes the Fourier representation to overshoot around them\ndue to the Gibbs phenomenon.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "bb74aed1eb41ae221a2fa7ff24bdd987dcc32e29", "size": 7291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_04/LaTeX/Report.tex", "max_stars_repo_name": "sohamroy19/EE2703", "max_stars_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_stars_repo_licenses": ["MIT"], "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_04/LaTeX/Report.tex", "max_issues_repo_name": "sohamroy19/EE2703", "max_issues_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_issues_repo_licenses": ["MIT"], "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_04/LaTeX/Report.tex", "max_forks_repo_name": "sohamroy19/EE2703", "max_forks_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_forks_repo_licenses": ["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.2922374429, "max_line_length": 108, "alphanum_fraction": 0.6689068715, "num_tokens": 2294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.6470000457519778}}
{"text": "\\input{coredef.tex}\n\n%opening\n\\def\\ntitle{Principles of Quantum Mechanics}\n\\def\\nauthor{mostanes}\n\\def\\npart{II}\n\\def\\nterm{Michelmas}\n\\def\\nyear{2018}\n\\def\\nlecturer{Skinner}\n\n\\renewcommand*{\\H}{\\mathcal{H}}\n\n\\begin{document}\n\t\n\\mktitlepage\n\t\n\\newpage\n\n\\setcounter{section}{-1}\n\n\\section{Preface}\nThis course draws heavily from material in IB, with references to Linear Algebra, Analysis II, Methods; as well as some references to IB Quantum Mechanics. Note however that this course is likely to prove a lot of the intuitive notions from IB QM, so it should be accessible even to those who were left baffled by IB QM. The author of these notes will make generous references to IB material without restating it, unlike the course lecturer. References to II material will also be made where appropriate.\n\n\\newpage\n\n\\section{Introduction}\n\\subsection{Comparison of Classical and Quantum Mechanics}\n\\subsubsection{Classical Mechanics}\nClassical mechanics are governed by Newton's laws, which are 2nd order differential equations in the variables $\\vec{x}$, $\\vec{p}$. By combining the 2 variables as in classical dynamics, we obtain the \\textbf{phase space}, which in Newtonian dynamics is $\\R^{2n}$, with the particular case $n=3$ our universe.\\\\\nIn classical mechanics, the observables are simple quantities, represented by functions $\\R^{2n} \\rightarrow \\R$.\n\n\\subsubsection{Quantum Mechanics}\nParticles are instead represented by points in a Hilbert space (equivalent of the phase space).\\\\\nObservables are represented by linear operators $\\H \\rightarrow \\H$.\n\n\\subsection{Hilbert spaces}\n\\begin{remark}\n\tThere is an entire chapter of linear analysis dedicated to Hilbert spaces.\n\\end{remark}\n\n\\begin{definition}\n\tA Hilbert space $\\H$ is a vector space (over $\\C$) with a complete inner product $(\\cdot,\\cdot) : \\H \\times \\H \\rightarrow \\C$.\n\\end{definition}\nTherefore Hilbert spaces satisfy the usual vector space and complex inner product properties and any Cauchy sequence converges to a vector within the space under the norm induced by the inner product.\n\\subsubsection{Examples}\nEvery finite dimensional Hilbert space (of dimension $n$) is isomorphic to $\\C^n$ (see Linear Analysis).\\\\\nA simple $\\infty$-dimensional space is $l^2$, the space of infinite sequences (converging under the 2-norm; see Analysis II).\\\\\nAnother example is $L^2$, the function space of Lebesgue integrable functions (integrals converging under the 2-norm; see Probability and Measure). Their inner product is defined analogously to the inner product of $l^2$ and the norm of $L^2$.\n\\subsection{Dual spaces}\nThe dual $\\H^\\star$ of a Hilbert space $\\H$ is space of linear operators $\\H \\rightarrow \\C$. One way of obtaining such operators is by considering the inner product $(\\chi,\\cdot) : \\H \\rightarrow \\C$.\\\\\nBy the Riesz representation theorem (see Linear Analysis), all elements in $\\H^\\star$ can be written in inner product form.\n\\subsection{Dirac notation}\nDirac invented the following notation which is standard today in QM:\\\\\n\\begin{tabular}{ccc}\n\tElements of $\\H$ & written $\\ket{\\cdot}$ & called 'ket'\\\\\n\tElements of $\\H^\\star$ & written $\\bra{\\cdot}$ & called 'bra'\\\\\n\tInner product & written $\\bra{\\cdot}\\ket{\\cdot}$ & called 'braket'\\\\\n\\end{tabular}\n\n\\end{document}", "meta": {"hexsha": "9fdb45ea198a6622200fedf8d5b58a42e4e2ee33", "size": 3261, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pqm.tex", "max_stars_repo_name": "mostanes/cam-maths-tripos", "max_stars_repo_head_hexsha": "bf40a5250be7c15037a937e1521c5aa7e0cb0841", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pqm.tex", "max_issues_repo_name": "mostanes/cam-maths-tripos", "max_issues_repo_head_hexsha": "bf40a5250be7c15037a937e1521c5aa7e0cb0841", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pqm.tex", "max_forks_repo_name": "mostanes/cam-maths-tripos", "max_forks_repo_head_hexsha": "bf40a5250be7c15037a937e1521c5aa7e0cb0841", "max_forks_repo_licenses": ["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.35, "max_line_length": 504, "alphanum_fraction": 0.7614228764, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6469945880966452}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Anti-Derivative}\n\n\\objective{Distinguish and find anti-derivatives and integrals of functions}\n\n\nSuppose we are given a formula and are told it is the derivative of what we want.\nThis isn't as abstract as it sounds: velocity is the derivative of position, and (at least in \nmany cars) it is easier to record velocity than it is position.  If the velocity\nfunction is an algebraic equation, we simply need to apply the Power Rule\nin reverse and we will have the anti-derivative of the equation.\n\nThe Power Rule states that the derivative of $x^n$ is $n\\cdot x^{n-1}$.  In other words,\n``take the exponent out front, and lower the exponent by one''.  If we wanted to\nturn this backwards, in order to arrive at an exponent of $x^n$, we must have \nbegun at $x^{n+1}$.  However, if we take the derivative of $x^{n+1}$, we must\nmultiply by $n+1$.  To cancel that, we should multiply by $\\frac{1}{n+1}$.\n\n\n\\begin{derivation}{Backwards Power Rule}\\index{Power Rule!Backwards}\nThe anti-derivative of $x^n$ is $\\frac{1}{n+1} x^{n+1} + C$, where $C$ is an unknown\nconstant.\n\\end{derivation}\n\n\nWhat is C?  Consider whether of not $x^2 +1$ is the anti-derivative of $\\frac{1}{2}x$.\nIs $x^2-1$?  Is $x^2+\\pi$?  Because constants differentiate to 0, a constant could be \npart of our anti-derivative equation and we cannot know what it is, without more information.\nWhat information?  Well, if we know the initial conditions (when $x=0$) then we can \nsolve for $C$ and know precisely which anti-derivative equation we want.\n\n\n\\subsection{Integral}\\index{integral!definite}\nThe preceding definition of anti-derivatives is very helpful algebraically, but what about\ngraphically?  If a given graph is the derivative of what we seek, can we interpret the\ngraph to give us numerical information?\n\nConsider the graph of a car with constant velocity:\n\n\\begin{figure}[h]\n\\begin{centering}\n\\begin{tikzpicture}[scale=0.6]\n\t\\draw[help lines] (0,0) grid (8,6);\n\t\\draw (-0.5,0) -- (8.5,0);\n\t\\draw (0,-0.5) -- (0,6.5);\n\t\\draw[thick,->] (0,4) node[anchor=east] {40 mph}-- (8.5,4);\n\t\\draw (8,0) node[anchor=north] {0.8 hr};\n\t\\draw [fill=gray!80,opacity =0.4] (0,0) rectangle (8,4);\n\\end{tikzpicture}\n\\caption{A car's velocity in 10's of mph, over tenths of an hour}\n\\end{centering}\n\\end{figure}\n\n\nIf we want position or distance, we have known a formula for a long time:\ndistance = rate $\\cdot$ time.  The $y$-value is the rate.  The $x$-value is the \ntime.  As hard as it may be to conceive of, distance is the \\emph{area} under the\ngraph.  In this case, 40 mph times 0.8 hours is 32 miles.   Notice that this number does\nnot depend upon the initial position: the car has travelled 32 positive miles, regardless \nof where it began.\n\n\\begin{equation}\n\\int_0^{0.8}  40dx = \\left.40x \\right|_0^{0.8} = 40(.8) - 40(0) = 32\n\\end{equation}\n\nWhat about more complicated velocity?  Let us begin with constant acceleration:\n\n\\begin{figure}[h]\n\\begin{centering}\n\\begin{tikzpicture}[scale=0.7]\n\t\\draw[help lines] (0,-2) grid (6,6);\n\t\\draw (-0.5,0) -- (6.5,0);\n\t\\draw (0,-2.5) -- (0,6.5);\n\t\\draw [thick,->] (0,-2) -- (6.5,4.5);\n\t\\draw [fill=red!80,opacity=0.4] (0,-2) -- (2,0) -- (0,0);\n\t\\draw [fill=gray!80,opacity=0.4] (2,0) -- (6,0) -- (6,4);\n\\end{tikzpicture}\n\\caption{A car beginning at -20 mph but steadily accelerating to 40 mph by 0.6 hours later}\n\\end{centering}\n\\end{figure}\n\nThe object begins with a negative velocity, so we must count that distance as negative.\n-2 + 8 = 6, so the object has gained that many units in positive displacement from 0 to 6.\n\nIn some problems, we can simply count the squares below the graph and find the\ndefinite integral.  In most cases, the graph will be curved and we will need to find an\nanti-derivative equation and subtract the evaluation at the left from that of the right.\n\nFinally, notice that we can integrate functions we cannot differentiate, at times.  It would\nbe impossible for a physical object to have a velocity graph like the \\texttt{int()} function,\nbut it can still be meaningful to find the area under the graph.\n\n\\begin{example}{Bandwidth Rates}\n\\exProblem\nSuppose an wifi hotspot charges start at 2.50 per hour when you begin, and the rate goes\nup .50 every 20 minutes after that.  The rate is not incremented\ncontinuously, but jumps every 1/5 hour.  Illustrate the cost of using the service for 0.9 hours\nas a definite integral.\n\n\\exSolution\n\\begin{tikzpicture}[xscale=4,yscale=1]\n\t\\draw (-0.05,0) -- (1,0) ;\n\t\\draw (0,-.2) -- (0,5.0);\n\t\\draw[thick] (0,2.50) -- (.2,2.5) -- (.2,3) -- (.4,3) -- (.4,3.5) -- (.6,3.5) -- (.6,4) -- (.8,4) -- (.8,4.5) -- (1,4.5);\n\t\\draw [fill=gray!80,opacity=0.4] (0,0) rectangle (.2,2.5);\n\t\\draw [fill=gray!80,opacity=0.4] (.2,0) rectangle (.4,3);\n\t\\draw [fill=gray!80,opacity=0.4] (.4,0) rectangle (.6,3.5);\n\t\\draw [fill=gray!80,opacity=0.4] (.6,0) rectangle (.8,4);\n\t\\draw [fill=gray!80,opacity=0.4] (.8,0) rectangle (.9,4.5);\n\\end{tikzpicture}\nAs the rectangle illustrate, $(0.2)(2.5) + (0.2)(3.0) + (0.2)(3.5) + (0.2)(4.0) + (0.1)(4.5) = 3.05$.\n\\end{example}\n\n", "meta": {"hexsha": "c7fe20a3723f4e1006092e58d76d9e657e4287fc", "size": 5056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch05/0505.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/0505.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/0505.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.9652173913, "max_line_length": 122, "alphanum_fraction": 0.6946202532, "num_tokens": 1706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8887587853897073, "lm_q1q2_score": 0.6469945757632034}}
{"text": "\\subsubsection{Complex Eigenvalues}\r\n\\begin{theorem}\r\n\tIf an $n \\times n$ matrix $A$ is not defective, then for each pair of complex eigenvalues $\\alpha \\pm \\beta i$ with corresponding eigenvectors $\\vec{a} \\pm i\\vec{b}$, the corresponding fundamental solutions are $e^{\\alpha t}\\left(\\cos{(\\beta t)}\\vec{a}-\\sin{(\\beta t)\\vec{b}}\\right)$ and $e^{\\alpha t}\\left(\\sin{(\\beta t)}\\vec{a}+\\cos{(\\beta t)\\vec{b}}\\right)$.\r\n\\end{theorem}\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/homogeneousSystems/complexEigenvalues_example.tex}\\fi", "meta": {"hexsha": "e96107984c3b795b97f5ccd93ec7b7472a215fee", "size": 546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/complexEigenvalues.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/complexEigenvalues.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/complexEigenvalues.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": 91.0, "max_line_length": 363, "alphanum_fraction": 0.7216117216, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6469695501992171}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{At Key}\nThe operation $atKey$ will return the Value $v$ at some specified Key $k$.\n\\begin{schema}{AtKey[KV, K]}\n  m? : KV \\\\\n  v! : V \\\\\n  k? : K \\\\\n  atKey~\\_ : KV \\cross K \\surj V\n  \\where\n  v! = atKey(m?, k?) @ \\\\\n  \\t2 let ~~ coll == ((\\seq m?) \\filter (k?, m?_{k?})) \\implies \\langle (k?, m?_{k?}) \\rangle \\iff k? \\in \\dom m? \\\\\n  \\ \\ \\ = (second(head(coll)) \\iff k? \\mapsto m?_{k?} \\in coll) ~\\lor \\\\\n  \\t1 (\\emptyset \\iff k? \\not \\in \\dom m?)\n\\end{schema}\nIn the schema above, $coll$ is the result of filtering for $(k?, m?_{k?})$ within $\\seq m?$.\nIf the mapping was in the original $m?$, it will also be in the sequence of mappings. This means\nwe can filter over the sequence to look for the mapping and if found, it is returned as $\\langle (k?, m?_{k?}) \\rangle$.\nTo return the mapping itself, $head(coll)$ is used to extract the mapping such that the value mapped to $k?$ can be returned.\n\\begin{zed}\n  v! = atKey(m?, k?) = second(head(coll)) = m?_{k?} @ m?_{k?} : V \\iff k? \\in \\dom m?\n\\end{zed}\nThe following examples demonstrate the properties of $atKey$\n\\begin{argue}\n  M = \\ldata k_{0}v_{k_{0}}, k_{1}v_{k_{1}} \\rdata \\\\\n  \\t1 k_{0} = abc \\ \\land  v_{k_{0}} = 123 & $k_{0}v_{k_{0}} = abc \\mapsto 123$ \\\\\n  \\t1 k_{1} = def \\ \\land v_{k_{1}} = xyz \\mapsto 456 & $k_{1}v_{k_{1}} = def \\mapsto xyz \\mapsto 456$ \\\\\n  atKey(M, abc) = 123 \\\\\n  atKey(M, def) = xyz \\mapsto 456 \\\\\n  atKey(M, foo) = \\emptyset\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "81cd4fa15532c8f2813f7fdfb11dfe1a1af947d5", "size": 1516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/kv/atKey.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/kv/atKey.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/kv/atKey.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 45.9393939394, "max_line_length": 125, "alphanum_fraction": 0.6042216359, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6469291961984316}}
{"text": "\\chapter{The local field potential}\n\\label{ch:LFP}\n\nThis thesis discusses software for processing intracranial voltage recordings. This chapter describes the nature of such voltage signals.\n\nAt every location in the brain, the electric field vector $\\E$ (in units of N/C or V/m) points in the direction that a positive charge would be pushed towards, if it was placed at that location. The electric potential $\\phi$ is defined\\footnotemark{} such that:\n%\n\\begin{equation}\n\\label{eq:potential}\n\\E = -\\grad{\\phi},\n\\end{equation}\n%\ni.e. such that the electric field points from locations of high potential to locations of lower potential. The electric field potential $\\phi$ is a scalar field, in units of V. When it is measured extracellularly, neuroscientists refer to it as the \\emph{local field potential} (LFP) -- especially when only frequencies below about 500 Hz are considered.\n\n\\footnotetext{The electric field potential $\\phi$ is only defined when the electric and magnetic fields do not vary too quickly over time, i.e. when $\\pdv*{\\E}{t} \\approx 0$ and $\\pdv*{\\B}{t} \\approx 0$. It then directly follows from Maxwell's equations that both fields become decoupled, and that the electric field becomes irrotational ($\\curl{\\E} = 0$), so that an electric potential may be defined as in \\cref{eq:potential}. This so called \\emph{quasi-static} assumption is met in electrophysiological conditions \\cite{Nunez2006,Plonsey2007}.}\n\nWe now discuss two models used to estimate the LFP $\\phi$. Both models calculate $\\phi$ based on the mobile charge density $\\rho$ at each location in the brain and throughout time. ($\\rho$ is the net positive surplus of mobile charges, in units of C/\\si{\\metre^3}. Biological tissue contains a high number of such mobile charges. These are mostly ions, with \\ce{Na+}, \\ce{Cl-}, and \\ce{K+} the most abundant ones \\cite{Martinsen2015a}).\n\nBoth models consist of a single divergence equation (namely \\cref{eq:div-charge,eq:div-current}), which, together with \\cref{eq:potential} and an assumption of uniform and isotropic brain tissue, leads in both cases to a simple closed form equation to calculate the LFP $\\phi$ (namely \\cref{eq:phi-charge,eq:phi-current}).\n\n\n\n\\section{Model 1 (Gauss's law)}\n\nThe first model is a direct translation of the first of Maxwell's equations (Gauss's law), at macroscopic scale:\\footnotemark{}\n%\n\\begin{equation}\n\\label{eq:div-charge}\n\\div{\\eps \\E} = \\rho,\n\\end{equation}\n%\nwhere $\\eps$ is the local tissue permittivity, in units of F/m and generally a 3 $\\cross$ 3 matrix.\n\n\\footnotetext{Gauss's law in its pure form ($\\div{\\E} = \\rho_\\total / \\eps_0$) considers both mobile and ``bound'' charges: $\\rho_\\total = \\rho_\\free + \\rho_\\bound$. In \\cref{eq:div-charge}, we only explicitly consider mobile charges $\\rho = \\rho_\\free$, while bound charges are subsumed in the tissue permittivity $\\eps$. This simplification is allowed if we assume that ``tissue polarisation is proportional to electric field strength'' \\cite{Feynman2013}. This is a common assumption in physics, and is largely valid for brain tissue in normal conditions \\cite{Nunez2006}.}\n\nWhen we assume the permittivity $\\eps$ to be uniform and isotropic throughout the tissue (i.e. $\\eps$ is a constant scalar)\\footnotemark{}, \\cref{eq:div-charge} has the following solution for the LFP $\\phi$ \\cite{Feynman2013}:\n%\n\\begin{equation}\n\\label{eq:phi-charge}\n\\phi = \\frac{1}{4 \\pi \\eps} \\int_V \\frac{\\rho \\dd{V}}{r},\n\\end{equation}\n%\nwhere we summate over the entire brain volume $V$, with $\\rho \\dd{V}$ the surplus mobile charge in a small volume $\\dd{V}$ of tissue (in Coulomb), and $r$ the distance of this small volume to the point where $\\phi$ is calculated.\n\n\\footnotetext{The uniform and isotropic permitivitty assumption is questionable. Roughly, brain tissue consists of a dense alternation of two types of tissue (see \\cref{fig:neuropil}): the seawater-like fluid inside and in between cells, and the fatty membranes around cells, organelles, and vesicles. The former has a permittivity $\\eps$ of about 15 times larger than the latter \\cite{Marszalek1991,Weaver2003,Martinsen2015}. Additionally, the strongly non-random organization of some brain regions may challenge the isotropy assumption. Nevertheless, this uniform and isotropic permittivity assumption is often made \\cite{Nunez2006,Plonsey2007}.}\n\nIn other words, positive charge surplusses increase the nearby LFP, negative charge surplusses decrease it, and their effects summate linearly, weighted inverse-proportionally by distance. This model explains for example the resting ``membrane potential'' of neurons, where $\\phi$ is lower inside the cell than outside: neurons at rest contain an excess of negative charges \\cite{Dayan2001b}.\n\nAlthough this model is arguably the most physically correct, it is often difficult to apply in practice: charge distributions $\\rho$ are already quite complex in even the simplest of electronic circuits \\cite[chapter 8]{Chabay2015}. For the highly entangled topologies of brain tissue (see \\cref{fig:neuropil}), estimating charge distributions is intractable.\n\nThe next model is more useful in practice, as it calculates the LFP based not on charges, but on currents. Currents (and specifically transmembrane currents) are the bread and butter of electrophysiology \\cite{Kandel2013a}.\n\n\n\n\n\\section{Model 2 (Current source density analysis)}\n\\label{sec:CSD}\n\nThis is the ``standard model of electric potentials in biological tissue'' \\cite{Bedard2011}. Unlike the previous model, it is mostly empirical \\cite{Bedard2011}. In fact, the assumptions on which it rests are strictly incompatible with \\cref{eq:div-charge,eq:phi-charge}, and lead to a paradox when considered jointly. \\Citeauthor{Bedard2011} explore this paradox \\cite{Bedard2011}, and propose a more general formulation of CSD analysis that `solves' the paradox. In the remainder of this chapter however, we will present the `classic' CSD model, as it is presented in most electrophysiology texts \\cite{Plonsey2007,Nunez2006,Mitzdorf1985,Nicholson1975,Linden2014,Buzsaki2012a}.\n\nWe first define the so called \\emph{current source density}, $I$, as the rate at which the net charge surplus inside a small volume decreases (units A/\\si{m^3}):\n%\n\\begin{equation}\n\\label{eq:CSD}\nI = - \\pdv{\\rho}{t}\n\\end{equation}\n%\nCharge conservation (which is a direct consequence of Maxwell's equations) dictates that\n%\n\\begin{equation}\n\\label{eq:charge-conservation}\n\\div{\\J} = I,\n\\end{equation}\n%\nwhere $\\J$ is the current density (units of A/\\si{\\metre^2}, and $\\J = \\rho \\vb{v}$ with $\\vb{v}$ the local velocity of mobile charges). In other words, the decrease in net positive charges in a small volume ($I$) equals the net rate at which positive charges flow out of this volume ($\\div{\\J}$).\n\nNext (and this is the assumption challenged in \\cite{Bedard2011}), we assume that the extracellular medium is \\emph{resistive} or \\emph{ohmic}:\n%\n\\begin{equation}\n\\label{eq:ohmic-medium}\n\\J = \\sigma \\E,\n\\end{equation}\n%\nwhere $\\sigma$ is the local tissue conductivity, in units of S/m and generally a 3 $\\cross$ 3 matrix. In other words, current is assumed to be linearly related to the electric field. (This needn't be the case in reality: the electric field dictates the acceleration of mobile charges, while the current density describes their velocity. These are instantaneously indepedent.)\n\nCombining charge conservation and the ohmic assumption leads to the governing equation for CSD analysis:\n%\n\\begin{equation}\n\\label{eq:div-current}\n\\div{\\sigma \\E} = I.\n\\end{equation}\n%\nNote the similarity with \\cref{eq:div-charge}. And analogously as in \\cref{eq:div-charge,eq:phi-charge}, when we assume the conductivity $\\sigma$ to be uniform and isotropic throughout the tissue (i.e. $\\sigma$ is a constant scalar)\\footnotemark{}, \\cref{eq:div-current} has the following solution for the LFP $\\phi$ \\cite{Plonsey2007}:\n%\n\\begin{equation}\n\\label{eq:phi-current}\n\\phi = \\frac{1}{4 \\pi \\sigma} \\int_V \\frac{I \\dd{V}}{r}.\n\\end{equation}\n%\nIn other words, so called ``current sources'' ($I > 0$) increase the nearby LFP, current sinks ($I < 0$) decrease it, and their effects again summate linearly, weighted inverse-proportionally by distance.\n\n\\footnotetext{Again, a questionable assumption: (extra)cellular plasma has a conductivity $\\sigma$ of about $10^6$ times higher than the lipid bilayer membranes in between \\cite{Michel2017,Martinsen2015,Marszalek1991,Nunez2006,Weaver2003}.}\n\n\n\n\\section{Transmembrane currents}\n\\label{sec:transmembrane-currents}\n\nActive transmembrane currents are the main physical mechanism of signal propagation in the nervous system.\\footnotemark{} At synapses, excitatory neurons cause a brief inward current in their target neuron, while inhibitory neurons cause a brief outward current. Along axons, action potentials (``spikes'') propagate by a cascade of inward currents.\n\n\\footnotetext{With 'active', we mean here that the current is caused by the opening of ion channels that are located at the same position in the membrane as the current.}\n\nEach of these active currents leads to corresponding passive currents in other parts of the membrane, forming closed current loops. An excitatory, inward current at a synapse corresponds to outward currents at distal parts of the neuron (most notably at the cell body). The inward, active currents of a spike are surrounded by outward, passive currents.\n\n\n\n\\section{Forward CSD model of the LFP}\n\\label{sec:forward-CSD}\n\nIn CSD analysis, both active and passive transmembrane currents are used to estimate the LFP, by making use of the following `trick': the existence of the inside of the neuron is ignored. An inward current for example is then modelled as a current sink $I_m < 0$ in the extracellular space, i.e. an accumulation of mobile charges. In reality, charges do not quite accumulate, but rather dissipate in the neuron. Or, equivalently, a proportional current source $I'_m = -I_m$ exists inside the neuron, at virtually the same location as $I_m$, cancelling it out. In CSD analysis however, only the current sink $I_m$ (and not the current source $I'_m$) would be used for calculating the LFP $\\phi$.\n\nThe justification for ignoring the inside of the neuron is often as follows (paraphrasing from \\cite{Mitzdorf1985}, a foundational CSD theory paper): ``The extracellular space is independent of the intracellular space, because its boundaries (the cell membranes) have a very high resistance compared to the extracellular space.'' However, electric insulators (high resistance areas) do not shield the electric field, nor the electric field potential $\\phi$.\n%\n\\footnote{Another reason the inside of neurons is ignored might possibly be notation: at synapses, there are real currents, often denoted by $I$; but there are no real current sources or sinks, also often denoted by $I$. This may cause confusion.}\n\\footnote{A final reason to not only consider the extracellular space, is that there is not that much of it: only between 10\\% and 20\\% of hippocampus volume is extracellular space \\cite{Sykova1997a}. See also \\cref{fig:neuropil}.}\n\nNonetheless, in the so called `forward' CSD model (estimating the LFP from transmembrane currents), \\cref{eq:phi-current} is used to calculate the LFP based on `unpaired' transmembrane current source densities $I_m$. From \\cref{eq:phi-current}, an inward current then corresponds to a drop in the nearby LFP, and an outward current to an increase. This technique is applied in \\cref{sec:physiology} to explain the physical basis of the sharp wave-ripple motif. Another application of this technique is e.g. \\texttt{LFPy}, a software package used to numerically simulate the LFP \\cite{Linden2014}.\n\nNotwithstanding the theoretical problems outlined here and in \\cite{Bedard2011}, CSD analysis seems to provide relatively accurate results in practice \\cite{Buzsaki2012a,Bedard2011}. As mentioned earlier, \\citeauthor{Bedard2011} \\cite{Bedard2011} give a derivation of a CSD-like model that does not rest upon the `classic' derivation as presented here, instead concluding: ``[..] the results obtained with the classic CSD analysis are perfectly consistent with \\emph{ionic diffusion} because diffusion gives a source term which is very close to the phenomenological model of current source density introduced by Pitts and Mitzdorf, but in a manner consistent with Maxwell-Gauss law.'' (Pitts \\cite{Pitts1952} and Mitzdorf \\cite{Mitzdorf1985} refers to the classical CSD model).\n", "meta": {"hexsha": "638af568f1a9f53542812aaf53ad9d4f1c838730", "size": 12489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/LFP/index.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/LFP/index.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/LFP/index.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": 96.0692307692, "max_line_length": 777, "alphanum_fraction": 0.7756425655, "num_tokens": 3205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6469291735918071}}
{"text": "\\subsection{Course Structure}\n\n\\begin{table}[h]\n% \\caption{Tested autoencoder structures for a 3D case}\n\n\\begin{tabular}{p{25mm}|p{100mm}|p{30mm}}\n  \\hline\nLecture 1-2\t& \nIntroduction. \\newline\nLinear Algebra Four Fundamental Subspaces\n(Null space, Row space, Projectors, Column and Left null spaces). \\newline\nUse cases for fundamental subspaces in Control. &\t\nIndividual \\newline assignment \n\\\\   \\hline\n%\nLecture 3-5 &\nLeast Squares and Quadratic Programming. \\newline\nDomains. Convex Domains. \\newline\nLinear inequality representation of convex domains.\t& \nIndividual \\newline assignment \n\\\\   \\hline\n%\nLecture 6-9\t& \nSecond order cone programming (SOCP). \\newline\nSemidefinite programming (SDP). \\newline\nLinear matrix inequalities, example in Finite-time stability, example in computational geometry. \\newline\nMixed-integer convex programming. \\newline Relaxation. Big M method. Example in path planning.\t& \nIndividual \\newline assignment \n\\\\   \\hline\n%\nLecture 10-11\t& \nBarrier functions, center of constraints. \\newline\nMinimax.\t& \nMiniproject \n\\\\  \\hline\n\\end{tabular}\n\\end{table}", "meta": {"hexsha": "e42615b9ba1112de378577f8c67fb3c33eba569c", "size": 1089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Syllabus/Sections/CourseStructure.tex", "max_stars_repo_name": "kahlflekzy/Computational-Intelligence-Slides-Spring-2022", "max_stars_repo_head_hexsha": "9401fe1258efa91a6c9886501d02909420a94add", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2022-01-19T15:40:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T22:27:44.000Z", "max_issues_repo_path": "Syllabus/Sections/CourseStructure.tex", "max_issues_repo_name": "kahlflekzy/Computational-Intelligence-Slides-Spring-2022", "max_issues_repo_head_hexsha": "9401fe1258efa91a6c9886501d02909420a94add", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-27T09:02:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-13T09:36:55.000Z", "max_forks_repo_path": "Syllabus/Sections/CourseStructure.tex", "max_forks_repo_name": "kahlflekzy/Computational-Intelligence-Slides-Spring-2022", "max_forks_repo_head_hexsha": "9401fe1258efa91a6c9886501d02909420a94add", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2021-01-20T07:58:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-12T08:28:08.000Z", "avg_line_length": 29.4324324324, "max_line_length": 105, "alphanum_fraction": 0.7649219467, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.646913550482921}}
{"text": "\\chapter{From MDPs to Reinforcement Learning}\n\\label{chapter3}\n\n\\vspace{0.5cm}\n\n\\noindent As said before, when we have both the reward function $\\mathcal{R}$ and the transition model $\\mathcal{P}$ we can solve the MDP by means of dynamic programming.\n\nTruth to be told, for most cases we cannot precisely predict neither $\\mathcal{R}$ nor $\\mathcal{P}$ and we have to approximate, explore and estimate functions and states in order to converge to the optimal solution (the optimal policy).\n\nReinforcement Learning in fact, is a technique to handle Markov Decision Processes in an environment we don't fully know.\n\n\\section{Value Function and the Bellman equation}\nWe spoke before about \\textit{optimal policy} but we never defined it. The optimal policy, is the one that maximizes our long term expected reward, that is:\n\\begin{equation}\n    \\pi^\\star = arg\\,max_\\pi \\ \\mathbb{E} \\Big[ \\sum_t \\gamma^t \\mathcal{R}(s_t) \\ \\vert \\ \\pi \\Big]\n\\end{equation}\n\\noindent\nWe can see in this function, that the initial state is not defined (it's random), and that the optimal policy must be optimal starting from any state.\n\nWe can actually define also the \\textbf{value function} that gives the expected long term reward following a policy starting from a state $s$:\n\\begin{equation}\n    \\mathbb{V}^\\pi(s) = \\mathbb{E} \\Big[ \\sum_t \\gamma^t \\mathcal{R}(s_t) \\ \\vert \\ \\pi, \\ s_0 = s \\Big]\n\\end{equation}\nThis function helps us to define in a better way the optimal policy:\n\\begin{equation} \\label{eq:bellman-value}\n    \\pi^\\star = arg\\,max_a \\ \\sum_{s'} \\mathbb{P}(s_{t+1} = \\mathnormal{s'} \\vert s_t = \\mathnormal{s}, a_t = \\mathnormal{a}) \\ \\mathbb{V}(s')\n\\end{equation}\nThis equation says that the optimal policy is the one that, for every state, returns the action that maximizes my expected value function and this allows us to write the value function in a much more famous form known as \\textbf{Bellman Equation}:\n\\begin{equation}\n    \\mathbb{V}^\\pi(s) = \\mathcal{R}(s) +  \\gamma\\sum_{s'} \\mathbb{P}(s_{t+1} = \\mathnormal{s'} \\vert s_t = \\mathnormal{s}, a_t = \\mathnormal{a}) \\ \\mathbb{V}(s')\n\\end{equation}\nThis equation has two terms and says that the expected sum of discounted return is equal to the sum of two terms: the initial, or immediate, reward received immediately simply for starting in state $s$, and a discounted sum of the future expected rewards (rewards after the first step) and can be rewritten as \\begin{equation}\n    \\mathbb{V}^{\\pi^\\star}(s) = \\mathcal{R}(s) +  \\gamma\\,max_a\\sum_{s'} \\mathbb{P}(s_{t+1} = \\mathnormal{s'} \\vert s_t = \\mathnormal{s}, a_t = \\mathnormal{a}) \\ \\mathbb{V}(s')\n\\end{equation}\nto describe the optimal value function $\\mathbb{V}^\\star$.\n\n\\section{Action-value function}\n\\begin{comment}\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=1\\textwidth]{./pictures/bellman.eps}\n    \\caption{A representation of the Bellman equation.}\n    \\label{fig:bellman}\n\\end{figure}\n\\end{comment}\n\\begin{figure} [ht]    \n    \\tikzstyle{squarenode} = [circle, draw, minimum size=5mm]\n        \n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 9em, auto, thick]\n        \\node [squarenode] (s1) {$s_1$};\n        \\node [squarenode, right of=s1] (s2) {$s_2$};\n        \\node [squarenode, right of=s2] (s3) {$s_3$};\n        \\node [squarenode, right of=s3] (s4) {$s_4$};\n        \\node[squarenode,draw=none, right of=s4, xshift=-5em, yshift=1.6em] (s5) {};\n\n        \\draw [->] (s1) edge [out=90 in=90] node[right, above] {$\\mathcal{R}(s_1, a_1)$} node[very near start] {$a_1$} (s2);\n        \\draw [->] (s2) edge [out=90 in=90] node[right, above] {$\\mathcal{R}(s_2, a_2)$} node[very near start] {$a_2$}  (s3);\n        \\draw [->] (s3) edge [out=90 in=90] node[right, above] {$\\mathcal{R}(s_3, a_3)$} node[very near start] {$a_3$}  (s4);\n        \\draw (s4) edge [dotted] node {}  (s5);\n\n    \\end{tikzpicture}\n    \\caption{A representation of Bellman equation.}\n    \\label{fig:bellman}\n\\end{figure}\nThe Bellman equation is fundamental and is a necessary condition for optimality. Visually, our system goes like the one depicted in figure \\ref{fig:bellman} and the Bellman Equation~(\\ref{eq:bellman-value}) describes this system immediately after state $s_1$, before taking action $a_1$, so when we talk about \\textit{value} we talk about a state and eventually we will get into another state that can also be represented with another value function. This is why the Bellman equation can be depicted in a recursive way.\n\nThe purpose of explaining the Bellman equation graphically is to show that, as the value function shows the infinite recursion of the system starting from state $s$, we can actually represent this recursion, starting immediately after the action is taken.\n\nThis equation is called \\textbf{action-value function} and is defined in two ways. The first one in the Bellman equation form:\n\\begin{equation}\n    \\mathbb{Q}^\\pi(s, a) = \\mathcal{R}(s, a) +  \\gamma\\sum_{s'} \\mathbb{P}(s_{t+1} = \\mathnormal{s'} \\vert s_t = \\mathnormal{s}, a_t = \\mathnormal{a}) \\ \\,max_a\\mathbb{Q}(s', a')\n\\end{equation}\nand the second one in the expectation form:\n\\begin{equation}\n    \\mathbb{Q}^\\pi(s, a) = \\mathbb{E} \\Big[ \\sum_t \\gamma^t \\mathcal{R}(s_t) \\ \\vert \\ \\pi, \\ s_0 = s, \\ a_0 = a \\Big]\n\\end{equation}\nThis equations can be explained as we are in state $s$, we take action $a$, we get the first reward that is the first term, and then we go on with the summation.\n\nThe optimal value and action value functions are related in the following way.\n\\begin{align*}\n    \\mathbb{V}^\\star(s) &= \\,max_a\\mathbb{Q}^\\star(s, a) \\\\\n    \\mathbb{Q}^\\star(s, a) &= \\mathcal{R}(s, a) +  \\gamma\\sum_{s'} \\mathbb{P}(s_{t+1} = \\mathnormal{s'} \\vert s_t = \\mathnormal{s}, a_t = \\mathnormal{a}) \\ \\mathbb{V}^\\star(s')\n\\end{align*}\nOne way of thinking about this is: we always go further in the cycle. For the value function, we need the best possible action and the state-action function has already taken an action, so I just get the max state-action function. Same way for the second function, state-action function starts after the action is taken, so I sum the reward and I continue at the landing state so with the value function.\n\nSomeone may ask themselves \\textit{why are we bothering of creating this action-value function when we already have the value function?} \\\\\nWell, the \\textit{action-value function} is key in reinforcement learning as it allows to take expectations of $\\mathbb{Q}^\\pi(s,a)$ without knowing the transition function or the reward function.\n\n\\section{Algorithms}\nNow that we have defined two important functions, we can describe a reinforcement learning algorithm.\n\n\\subsection{Introduction}\n\\begin{figure} [ht]\n    \\tikzstyle{block} = [rectangle, draw, \n        text width=8em, text centered, rounded corners, minimum height=4em]\n        \n    \\tikzstyle{line} = [draw, -latex]\n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 15em, auto, thick]\n        \\node [block] (Agent) {Agent ($\\pi$)};\n        \\node [block, right of=Agent] (Environment) {Environment};\n        \\draw [->] (Agent) edge [bend left]  node {$a$} (Environment);\n        \\draw [->] (Environment) edge [bend left] node {$s$}  (Agent);\n        \\draw [->] (Environment) edge [dotted] node [above] {$\\mathcal{R}(s,a)$} (Agent);\n    \\end{tikzpicture}\n    \\caption{The concept of reinforcement learning.}\n    \\label{fig:rldiagram}\n\\end{figure}\n\\noindent\nTo understand better reinforcement learning, it's better to see Figure~\\ref{fig:rldiagram}. The environment reveals to the agent in forms of states and the agent replies with actions and the environment sends back a reward. All the computation or, in a more reinforcement learning way, the \\textit{thinking}, is done in the agent \\textit{mind} through the policy. \\\\\nAn important concept is that the information regarding the environment is only available through this interaction, meaning that the environment is not available in the agent's brain (the policy), but the agent is \\textit{experiencing} the environment only by interacting with it.\n\n\\subsection{Different families of algorithms}\nWe can think of a RL algorithm as a method that, given a sequence of action-state-reward triplets, is able to find an optimal policy $\\pi$ as depicted in Figure~\\ref{fig:rlalg-general}.\n\\begin{figure} [ht]\n    \\tikzstyle{block} = [rectangle, draw, \n        text width=8em, text centered, rounded corners, minimum height=4em]\n    \\tikzstyle{txtblock} = [rectangle, \n        text width=8em, text centered, rounded corners, minimum height=4em]\n        \n    \\tikzstyle{line} = [draw, -latex]\n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 15em, auto, thick]\n        \\node [txtblock] (sequence) {$\\langle s, a, r \\rangle^+$};\n        \\node [block, right of=sequence, xshift=-3em] (algorithm) {RL algorithm};\n        \\node [txtblock, right of=algorithm, xshift=-3em] (policy) {$\\pi$};\n        \\draw [->] (sequence) edge  node {} (algorithm);\n        \\draw [->] (algorithm) edge node {}  (policy);\n    \\end{tikzpicture}\n    \\caption{Reinforcement learning algorithm}\n    \\label{fig:rlalg-general}\n\\end{figure}\nThe RL algorithm block can be split in different ways according to the way the policy is learned. We can divide algorithms in three main families.\n\n\\subsubsection{Model-based algorithms}\n\\begin{figure} [ht]\n    \\tikzstyle{block} = [rectangle, draw, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n    \\tikzstyle{txtblock} = [rectangle, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n        \n    \\tikzstyle{line} = [draw, -latex]\n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 15em, auto, thick]\n        \\node [txtblock] (sequence) {$\\langle s, a, r \\rangle^+$};\n        \\node [block, right of=sequence, xshift=-9em] (model-learner) {model learner};\n        \\node [txtblock, text width=2em, right of=model-learner, xshift=-10em] (p-r) {$\\mathcal{P}, \\mathcal{R}$};\n        \\node [block, right of=p-r, xshift=-10em] (solver) {solver};\n        \\node [txtblock, text width=1em, right of=solver, xshift=-10em] (action-value) {$\\mathbb{Q}^\\star$};\n        \\node [block, right of=action-value, xshift=-10em] (argmax) {argmax};\n        \\node [txtblock, text width=2em, right of=argmax, xshift=-10em] (policy) {$\\pi$};\n        \\draw [->] (sequence) edge  node {} (model-learner);\n        \\draw [->] (model-learner) edge node {}  (p-r);\n        \\draw [->] (p-r) edge node {}  (solver);\n        \\draw [->] (solver) edge node {}  (action-value);\n        \\draw [->] (action-value) edge node {}  (argmax);\n        \\draw [->] (argmax) edge node {}  (policy);\n        \\path [line] (p-r) |-++ (0cm, 1.2cm) -| (model-learner);\n\n    \\end{tikzpicture}\n    \\caption{A model-based algorithm}\n    \\label{fig:model-based}\n\\end{figure}\n\\noindent\nA \\textbf{model-based} algorithm takes the action-state-reward triples and sends them to a \\textit{model learner} which learns the transition probability function $\\mathcal{P}$ and the reward function $\\mathcal{R}$. Once learned, a solver can compute an optimal action-value function. Once you have an optimal action-value function, for each state you just get the argmax to get the best action, and that's the policy.\nThe reason we have an arrow going back in the model learner is that the transition probability and the reward functions are initially estimated and are continuously updated with previous values of the functions.\n\n\\subsubsection{Value-function based algorithms}\n\\begin{figure} [ht]\n    \\tikzstyle{block} = [rectangle, draw, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n    \\tikzstyle{txtblock} = [rectangle, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n        \n    \\tikzstyle{line} = [draw, -latex]\n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 15em, auto, thick]\n        \\node [txtblock] (sequence) {$\\langle s, a, r \\rangle^+$};\n        \\node [block, right of=sequence, xshift=-9em] (value-update) {value update};\n        \\node [txtblock, text width=1em, right of=value-update, xshift=-10em] (action-value) {$\\mathbb{Q}$};\n        \\node [block, right of=action-value, xshift=-10em] (argmax) {argmax};\n        \\node [txtblock, text width=2em, right of=argmax, xshift=-10em] (policy) {$\\pi$};\n        \\draw [->] (sequence) edge  node {} (value-update);\n        \\draw [->] (value-update) edge node {}  (action-value);\n        \\draw [->] (action-value) edge node {}  (argmax);\n        \\draw [->] (argmax) edge node {}  (policy);\n        \\path [line] (action-value) |-++ (0cm, 1.2cm) -| (value-update);\n\n    \\end{tikzpicture}\n    \\caption{A value-function based algorithm}\n    \\label{fig:value-function-based}\n\\end{figure}\n\\noindent\nThe \\textbf{value-function} based algorithms are almost the same as the previous family of algorithms except that, as we can see from figure~\\ref{fig:value-function-based}, one block is missing. The main difference is that this family of algorithms tries to learn a policy without explicitly learning the model or better, the policy is learned without the assumption of knowing the model, whereas in the first family, to learn the policy, the model \\textit{must} be learned (the two functions that define a model are the transition probability function and the reward function).\nThis family of algorithm is in fact also called \\textbf{model-free algorithms}.\n\nIn this family, the state-action function is directly estimated from the sequence of tuples from the environment and previous values of $\\mathcal{Q}$. The $\\mathcal{Q}$ doesn't have a $\\star$ since it's just an estimation and it's not an optimal value but, with continuous iterations, it is proven that it will reach an optimal value.\n\n\\subsubsection{Policy search algorithms}\n\\begin{figure} [ht]\n    \\tikzstyle{block} = [rectangle, draw, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n    \\tikzstyle{txtblock} = [rectangle, \n        text width=4em, text centered, rounded corners, minimum height=4em]\n        \n    \\tikzstyle{line} = [draw, -latex]\n    \\centering\n    \\begin{tikzpicture}[align = center, node distance = 15em, auto, thick]\n        \\node [txtblock] (sequence) {$\\langle s, a, r \\rangle^+$};\n        \\node [block, right of=sequence, xshift=-9em] (policy-update) {policy update};\n        \\node [txtblock, text width=2em, right of=policy-update, xshift=-10em] (policy) {$\\pi$};\n        \\draw [->] (sequence) edge  node {} (policy-update);\n        \\draw [->] (policy-update) edge node {}  (policy);\n        \\path [line] (policy) |-++ (0cm, 1.2cm) -| (policy-update);\n    \\end{tikzpicture}\n    \\caption{A policy search algorithm}\n    \\label{fig:policy-search}\n\\end{figure}\n\\noindent\nThe third family of algorithms updates directly the policy by feeding it back to the policy update that modifies it based on the sequence that it receives. This algorithm is much more direct, but the learning problem is much more difficult because the feedback you get from the policy usually is not that useful to update it. For example, in a game, knowing that an action moves you forward isn't sufficient to know when to use it.\n\\newline\n\\newline\nAs depicted in figures~\\ref{fig:model-based}, \\ref{fig:value-function-based} and \\ref{fig:policy-search}, we can see that the three algorithms are getting simpler as going down, meaning that the policy learning is more direct but in the opposite way, going up, the algorithms become more supervised. Most of the time of this semester project has been spent in model-free value-based algorithms that provide a good balance between learning techniques and learning difficulties.\n\n\\subsection{Off-policy and on-policy algorithms}\nA further distinction between algorithms can be made through another aspect, if they are \\textit{off-policy} or \\textit{on-policy}.\n\n\\begin{itemize}\n    \\item \\textbf{off-policy} algorithms are those algorithms that learn about the greedy strategy (policy), while following a different policy that allows a better exploration of the state space;\n    \\item \\textbf{on-policy} algorithms are those algorithms that estimate functions according to the current policy.\n\\end{itemize}\n\nAn on-policy algorithm is influenced by the exploration policy and can get stuck in a local maximum whereas an off-policy algorithm is independent from the exploration policy and reaches the global optimum. \\\\\nAlgorithmically, an on-policy algorithm updates its $\\mathcal{Q}$-values using the $\\mathcal{Q}$-value of the next state $s'$ and the current policy's action $a'$ so it estimates the return for state-action pairs assuming the \\textit{current policy} continues to be followed. An off-policy algorithm updates its $\\mathcal{Q}$-values using the $\\mathcal{Q}$-value of the next state $s'$ and the greedy action $a'$ so it estimates the return for state-action pairs assuming a \\textit{greedy policy} was followed despite the fact that it is not following a greedy policy. \\\\\nThis distinction disappears when the followed policy is a greedy policy but an agent that works like this wouldn't be as good since it would never explore the space of solutions.\n\n%policy based\n%value based\n%model based\n%model free\n\n%off-on policy\n%actor algorithm\n%critic algorithms\n%actor critic algorithms\n\n\\subsection{Deep Q-Network}\n\n\\textbf{Deep Q-Network}, or \\textbf{DQN}, is the first popular reinforcement learning algorithm, proposed by DeepMind in 2013~\\cite{pongpixels}.\n\nIt's an updated version of the Q-learning algorithm first proposed by Watkins in 1992~\\cite{Watkins1992} and uses deep learning to estimate the action-value function. The Q-network is the neural network function approximator with parameters $\\theta$.\n\nSince it approximates and updates the action-value function, DQN is a \\textit{model-free}, \\textit{value-function based} algorithm: it solves the reinforcement learning task directly using samples from the emulator, without explicitly constructing an estimate of the model.\n\nThe two main characteristics regarding this algorithm are how it approximates the action-value function and the \\textbf{experience replay}'s concept.\n\\subsubsection{Deep Reinforcement Learning}\nDeep reinforcement learning can be defined as the connection between reinforcement Learning and neural networks, started in the late 90s~\\cite{Tesauro1994} but with DQN it started to get exciting achievements and visibility. The deep reinforcement learning part is in the approximation of the action-value function with a convolutional neural network with 3 hidden layers. The input is an $84 \\times 84 \\times 4$ image, the first hidden layer convolves 16 $8 \\times 8$ filters with stride 4, the second hidden layers convolves 32 $4 \\times 4$ filters with stride 2, the final hidden layer is a fully-connected layer that consists of 256 rectifier units and the output layer is a fully-connected linear layer with a single output for each valid action.\n\nThe input image represents the state and the output actions are the actions that the agent can perform. It is interesting to see that this same network has been applied to seven Atari games and no preprocessing has been applied to the images (the algorithm worked directly with raw images from the games).\n\n\\subsubsection{Experience Replay}\nThe concept of experience replay was first introduced in 1992~\\cite{Lin1992} as a way to reuse past experiences and replay them to the network in order to refresh them to it. The \\textit{re-learning problem} says that  if an input pattern has not been presented for quite a while, the\nnetwork typically will forget what it has learned for that pattern and thus need to re-learn it when that pattern is seen again later. In DQN, a \\textit{replay memory} is used to store past experiences and show them again in a random way.\n\\begin{spacing}{1.15}\n\\begin{algorithm}[ht]\n\\begin{algorithmic}\n\\State Initialize replay memory $\\mathcal{D}$ to capacity $N$\n\\State Initialize action-value function $Q$ with random weights\n%\\State Require preprocessor $h(s)$ that maps histories to fixed-length representations.\n\\For{episode $=1,M$} \n\\State Initialise sequence $s_1 = \\{x_1\\}$ and preprocessed sequenced $\\phi_1 = \\phi(s_1)$\n\\For {$t=1,T$}\n\t\\State With probability $\\epsilon$ select a random action $a_t$\n\t\\State otherwise select $a_t = \\max_{a} Q^*(\\phi(s_t), a; \\theta)$\n\t\\State Execute action $a_t$ in emulator and observe reward $r_t$ and image $x_{t+1}$\n\t\\State Set $s_{t+1} = s_t,a_t,x_{t+1}$ and preprocess $\\phi_{t+1} = \\phi(s_{t+1})$\n\t\\State Store transition $\\left(\\phi_t,a_t,r_t,\\phi_{t+1}\\right)$ in $\\mathcal{D}$\n\t%\\For {$k=1$ to $K$}\n\t\\State Sample random minibatch of transitions $\\left(\\phi_j,a_j,r_j,\\phi_{j+1}\\right)$ from $\\mathcal{D}$\n\t\\State Set\n\t$y_j =\n    \\left\\{\n    \\begin{array}{l l}\n      r_j  \\quad & \\text{for terminal } \\phi_{j+1}\\\\\n      r_j + \\gamma \\max_{a'} Q(\\phi_{j+1}, a'; \\theta) \\quad & \\text{for non-terminal } \\phi_{j+1}\n    \\end{array} \\right.$\n\t\\State Perform a gradient descent step on $\\left(y_j - Q(\\phi_j, a_j; \\theta) \\right)^2$\n\t%\\EndFor\n\\EndFor\n\\EndFor\n\\end{algorithmic}\n\\caption{Deep Q-learning with Experience Replay}\n\\label{alg}\n\\end{algorithm}\n\\end{spacing}\n\n\\noindent\nAlgorithm \\ref{alg} shows the pseudo code of DQN. We can see that after a random initialization of the convnet and of the replay memory, for each episode and for each time step (image in the episode), to the corresponding state $s_t$ an $\\epsilon$-greedy policy is applied (off-policy learning). \\\\\nOptimization is then performed using stochastic gradient descent based on the $\\mathcal{Q}$-learning target and the $\\mathcal{Q}$-network.\n\nNote that the preprocessing on the sequence is just a rescaling of the image, for lower memory utilization, no other preprocessing has been performed.\n\nThis implementation has been tested with 7 Atari games. It showed incredible results, obtaining for every game higher results than previous algorithms and sometimes even outperforming humans.\n\n\\subsection{Asynchronous Advantage Actor Critic}\n\\textbf{A3C}~\\cite{a3c} is a framework developed by the same team as before, DeepMind, that outperforms their first model, DQN, with the only use of CPU (DQN instead relies heavily on GPU). \\\\\nThe authors present four famous reinforcement learning algorithms in an asynchronous way ($\\mathcal{Q}$-learning, SARSA, $n$-step $\\mathcal{Q}$-learning and A3C). What does asynchronous mean? \\\\\nIt means that parallel agents are executed in parallel, on multiple instances of the environment. This parallelism allows a wider view since at any given time-step the parallel agents will be experiencing a variety of different states and after a certain period policies are combined. It has been shown that experience replay is no longer needed and that the same results can be reached by increasing the number of instances running in parallel.\\\\\nThe asynchronous architecture is achieved using multiple CPU threads on a single machine, allowing every consumer computer to use this implementation.\n\nThe best performing algorithm of the four presented is the \\textbf{Asynchronous advantage actor-critic (A3C)}. \\\\\nFirst of all, it's called actor-critic since actor and critic are synonyms of policy-based and value-based respectively~\\cite{konda2003}. This means that this algorithm aims to combine the strengths of both families of algorithms: from the policy-based family of algorithms it gets the simplicity of the problem, optimizing the policy directly with no need to get the action-value function, whereas from the value-based algorithms it gets the ability to \\textit{learn}, since, when working with the policy, when it gets updated, the gradients are computed independently from the previous estimates so there is no \\textit{learning} in the sense of an accumulation and consolidation of informations. Actor-critic methods also have good convergence properties in contrast to critic-only methods.\n\\begin{spacing}{1.15}\n\\begin{algorithm}[ht]\n\\caption{Asynchronous advantage actor-critic - pseudo code for each actor-learner thread.}\n\\begin{algorithmic}\n\\small\n\\State \\emph{// Assume global shared parameter vectors $\\theta$ and $\\theta_v$ and global shared counter $T=0$}\n\\State \\emph{// Assume thread-specific parameter vectors $\\theta'$ and $\\theta'_v$}\n\\State Initialize thread step counter $t\\gets 1$\n\\Repeat\n\\State Reset gradients: $d\\theta \\gets 0$ and $d\\theta_v \\gets 0$.\n\\State Synchronize thread-specific parameters  $\\theta'=\\theta$ and $\\theta'_v=\\theta_v$ %\n\\State $t_{start} = t$\n\\State Get state $s_t$\n\\Repeat\n\\State Perform $a_t$ according to policy $\\pi (a_t|s_t;\\theta')$\n\\State Receive reward $r_t$ and new state $s_{t+1}$\n%\n\\State $t \\gets t + 1$\n\\State $T \\gets T + 1$\n\\Until terminal $s_t$ \\textbf{or} $t-t_{start}==t_{max}$\n\\State $R =\n    \\left\\{\n    \\begin{array}{l l}\n      0  \\quad & \\text{for terminal } s_t\\\\\n        V(s_t,\\theta'_v) \\quad & \\text{for non-terminal } s_t \\text{// Bootstrap from last state}\n    \\end{array}\\right.$\n\\For {$i \\in \\{t-1,\\ldots,t_{start} \\}$}\n\\State $R \\gets r_i + \\gamma R$\n\\State Accumulate gradients wrt $\\theta'$: $d\\theta \\gets d\\theta + \\nabla_{\\theta'} \\log\\pi(a_i|s_i;\\theta') (R - V(s_i;\\theta'_v))$\n\\State Accumulate gradients wrt $\\theta'_v$: $d\\theta_v \\gets d\\theta_v + {\\partial\\left(R - V(s_i;\\theta'_v)\\right)^2}/{\\partial \\theta'_v}$\n\\EndFor\n%\n\\State Perform asynchronous update of $\\theta$ using $d\\theta$ and of $\\theta_v$ using $d\\theta_v$.\n%\n\\Until $T > T_{max}$\n\\end{algorithmic}\n\\label{a3c-alg}\n\\end{algorithm}\n\\end{spacing}\n\nThis algorithm uses a so called \\textit{forward view} meaning that the algorithm selects actions using its exploration policy for up to a certain number of steps in the future and the agent will then receive up to the same number of rewards from the environment. Forward view in a sentence explains how far ahead you need to look to figure out the value of a state. \\\\\nDeep learning techniques are used to estimate both the policy and the value function where for the policy there is a softmax output instead for the value function there is one linear output with all other layers of a convolutional neural network shared. \\\\\nThe updates on the policy and on the value function are then performed according to the gradient of an estimate of the advantage function that takes into account both the value function parameters and the policy parameters.\n\nIn algorithm~\\ref{a3c-alg} the pseudo code for the A3C algorithm.", "meta": {"hexsha": "4c090450a688ab8a2e9c383bb54240019a109b03", "size": 26459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapter3.tex", "max_stars_repo_name": "DistributedSystemsGroup/tensorpong", "max_stars_repo_head_hexsha": "736ded637c5b6dac8b105ef3bc25cace052b50ba", "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/chapter3.tex", "max_issues_repo_name": "DistributedSystemsGroup/tensorpong", "max_issues_repo_head_hexsha": "736ded637c5b6dac8b105ef3bc25cace052b50ba", "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/chapter3.tex", "max_forks_repo_name": "DistributedSystemsGroup/tensorpong", "max_forks_repo_head_hexsha": "736ded637c5b6dac8b105ef3bc25cace052b50ba", "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": 73.9078212291, "max_line_length": 792, "alphanum_fraction": 0.725386447, "num_tokens": 7162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6469135427011944}}
{"text": "\\documentclass[11pt]{article}\r\n\\usepackage{pgfplots}\r\n\\usepackage{amssymb}\r\n\\usepackage{url}\r\n\\pgfplotsset{compat=newest} \r\n\\setlength\\topmargin{-0.6cm}   \r\n\\setlength\\textheight{23.4cm}\r\n\\setlength\\textwidth{17.0cm}\r\n\\setlength\\oddsidemargin{0cm} \r\n\\begin{document}\r\n\\title{Ling 572 HW9}\r\n\\author{Daniel Campos  \\tt {dacampos@uw.edu}}\r\n\\date{03/13/2019}\r\n\\maketitle \r\n\\section{Q1}\r\n\\subsection{What does f'(x) intend to measure?}\r\nThe derrivative of a function measures the rate of change of a function rleative to the change in the agrument(in this case X).\r\n\\subsection{Let $h(x)=f(g(x))$ }\r\n$h'(x)$ = $f'(g(x)) \\cdot g'(x)$\r\n\\subsection{Let $h(x)=f(x)g(x)$ }\r\n$h'(x) = f'(x)g(x) + f(x)g'(x)$\r\n\\subsection{Let $f(x)=a^x$ where $a>0$}\r\n$ f'(x)$ =$ a^x log(a)$\r\n\\subsection{Let $f(x)= x^{10}-2x^8  \\frac{4}{x^2} + 10$}\r\n$f'(x) =10x^{9}-16x^7 + \\frac{8}{x^3}$\r\n\\section{Q2}\r\nThe logistic function is $f(x)=\\frac{1}{1+e^{-x}}$. The tanh function is $g(x)=\\frac{e^x - e^{-x}}{e^x +e^{-x}}$.\r\n\\subsection{Prove that $f'(x)= f(x)(1-f(x))$}\r\n1. $f'(x) = \\frac{e^{-x}}{(1+e^{-x})^2}$ \\\\\r\n2. $f'(x) =  \\frac{1}{1+e^{-x}}-\\frac{1}{(1+e^{-x})^2}$ \\\\\r\n3. $f'(x) = \\frac{1}{1+e^{-x}} \\cdot (1-\\frac{1}{1+e^{-x}})$  which means  $f'(x)= f(x)(1-f(x))$\\\\\r\n\\subsection{Prove that $g'(x)=1 - g^2(x)$}\r\n1. $tanh(x) = \\frac {sinh(x))}{cosh(x)}$ \\\\\r\n2. $g'(x) = \\frac{df}{dx} \\frac{sinh(x)}{cosh(x)}$\\\\\r\n3. $g'(x) = \\frac{cosh^2(x) - sinh^2(x)}{cosh^2(x)}$\\\\\r\n4. $g'(x) = \\frac{cosh^2(x)}{cosh^2(x)} - {sinh^2(x)}{cosh^2(x)}$\\\\\r\n5. $g'(x) = 1- {sinh^2(x)}{cosh^2(x)} $\\\\\r\n6. $g'(x) = 1-tanh^2(x)$\\\\\r\n\\subsection{Prove that $g(x) = 2f(2x)-1$}\r\n1. $f(2x) = \\frac{1}{1+e^{-2x}}$ \\\\\r\n2. $2f(2x) =\\frac{2}{1+e^{-2x}}$ \\\\\r\n3. $2f(2x) - 1 = \\frac{2}{1+e^{-2x}}  -1$ \\\\\r\n3. $2f(2x) - 1 = \\frac{2}{1+e^{-2x}}  - \\frac{1+e^{-2x}}{1+e^{-2x}}$ \\\\\r\n4. $2f(2x) - 1 = \\frac{2- e^{-2x}}{1+e^{-2x}}$ \\\\\r\n5. $2f(2x) - 1 = \\frac{(e^{x}-1)(e^{x}+1)}{1+e^{2x}}$ \\\\\r\n6. $2f(2x) - 1 = \\frac{e^{2x}-1)}{1+e^{2x}}$ \\\\\r\n7.  $2f(2x) - 1  = \\frac{e^{2x}-1}{e^{2x}+1} = tanh(x) = g(x)$  \\\\\r\n\\section{Q3}   \r\n\\subsection{What is $f'_x$ trying to measure?}\r\nA partial derrivative is trying to measure the change in a fucntion based on a variable assuming all other varriables in the function remain constant. In other words, our derrivative is representing the effect of a variable on the equation when no other variables are effecting the equation.\r\n\\subsection{$f(x,y)=x^3 + 3x^2y+y^3 + 2x$.}\r\n$f'_x = 3x^2 + 6xy+2 $  \\\\ $f'_y = 3(x^2+y^2)$\r\n\\subsection{ $z = \\sum_{i=1}^n w_i x_i$.}\r\n$\\frac{dz}{dw_i}= \\sum{i=1}^n x_i $\r\n\\subsection{$f(z)=\\frac{1}{1+e^{-z}}$ and $z = \\sum_{i=1}^n w_i x_i$.}\r\n$\\frac{df}{dz}= f(z)* \\frac{e^{-z}}{1 + e^{-z}} $ \\\\\r\n$\\frac{df}{dw_i}=f(z)*\\frac{e^{- \\sum{i=1}^n x_i }}{1+e^{- \\sum{i=1}^n x_i }}$ \\\\\r\n\\subsection{$E(z)=\\frac{1}{2}(t - f(z))^2$, $f(z)=\\frac{1}{1+e^{-z}}$ and $z = \\sum_{i=1}^n w_i x_i$.}\r\n$\\frac{dE}{dw_i} = -(t-f(z))*f(z)*\\frac{e^{- \\sum{i=1}^n x_i }}{1+e^{- \\sum{i=1}^n x_i }}$\r\n\r\n\\section{Q4 Softmax Funciton}\r\n\\subsection{Where in NNs is the softmax function used and why?}\r\nSoftmax is used to normalize the outputs of NN to interval (0,1) and to make all components to add up to 1 so that they can be interpreted as regular probabilities. This tends to be implemented as the final step of a NN to get a probability distribution over all possible classes/predictions.  \\\\\r\n\\subsection{x is [1, 2, 3, -1, -4, 0], what is the value of softmax(x)}\r\n[0.08607859048507978, 0.23398586833496002, 0.6360395340111326,\\\\ 0.011649470423906664, 0.0005799929804444501, 0.03166654376447658]\r\n\\section{Q5:  FNN}\r\n\\subsection{How many connections (i.e., weights) are there in this network?}\r\n$ connections = \\sum_{i=1}^{m-1} n_i*n_{i+1}$ since there are m-1 layers of connections.\r\n\\subsection{Given the input $x$, what is the formula for calculating the output of the first hidden layer?}\r\n$Y_h = g(M_k*X) $ \r\n\\subsection{Given the input $x$, what is the formula for calculating the output of the output layer?}\r\n$Y_o = g(M_mg(M_m-1*...*g(M_k*X))) $  where m is total depth of network\r\n\\section{Q6 MNIST NNs}\r\n\\subsection{What's the loss function used in the digit recognition task?}\r\nThe loss function is Mean squared error(MSE) or $ \\frac{1}{2n} \\sum{x} ||y(x)-a||^2$. \r\n\\subsection{Why do they choose to minimize this function instead of maximizing classification accuracy?}\r\nThey choose do minimize this since the classification accuracy is not a smooth function that can be connected back to the weights and biases in the network. It is difficult to optimize small changes in weights and biases since they are unlikley to affect changes in training accuracy but will likley affect the MSE.\r\n\\subsection{In gradient descent, what's the formula for updating the weight matrix (or vector)? Why is that a good formula?}\r\n$v \\rightarrow v' = v- n*\\triangledown C$ its a good formula because it is easy to calculate and the gradient vector, $\\triangledown C$ and it gives us a way of repeatedly changing the position of v in order to find a minimum of the function C.\r\n\\subsection{What are the main ideas and benefits of stochastic gradient descent?}\r\nThe main idea with stochastic gradient descent(SGD) is to estimate the gradient $\\triangledown C$ on a small sample of randomly chosen tarining inputs. By doing this average over this sample we can get a good estimate of the true gradient and speed up gradient descent. SGD is useful since it allows an efficient and accurate way of directing a NN to a global minimum is a measurable, stepable function without computing the gradient of the entire dataset.\r\n\\subsection{What is a training epoch?}\r\nA training epoch represents all the mini-batches that needed to be run until the network has exhausted all training input. Once this happenes people usually report a current loss function and accuracy and start another epoch.\r\n\\subsection{Let $T$ be the size of the training data, $m$ be the size of mini-batch, and your training process contains $E$ training epoches. How many times is each weight in the NN updated? }\r\n$updates = E*\\frac{T}{m}$\r\n\\subsection{How can one choose the learning rate?}\r\nThe learning rate needs to be explored during hyperparameter tuning. There are various optimzation to choose learning rate such as ADAM but in general many selections of learning rates come from the type of task being modeled and tinkering.\r\n\\subsection{What's the risk if the rate is too big?}\r\nIf the learning rate is too big then the network may never learn the function properly since a high learning rate can effectively skip over maximums\r\n\\subsection{What's the risk if the rate is too small?}\r\nIf the learning rate is too small then the network will train extremely slowly and it may never leave a local minum.\r\n\\section{Q7 MNSIT NN in practice}\r\n\\begin{table}[h]\r\n\\centering\r\n\\caption{Results on digit recognition}\r\n\\label{table1}\r\n\\begin{tabular}{|c|r|l|l|l|r|} \\hline\r\n  Expt id & \\# of hidden neurons & epoch \\# & mini batch size & learning rate & accuracy \\\\ \\hline\r\n  1  & 30   & 30 & 10 & 3.0 & 0.9461 \\\\ \\hline\r\n  2  & 10   & 30 & 10 & 3.0 & 0.9172 \\\\ \\hline\r\n  3  & 30   & 30 & 10 & 0.5 & 0.9403 \\\\ \\hline\r\n  4  & 30   & 30 & 10 & 10  & 0.9457 \\\\ \\hline       \r\n  5  & 30   & 30 & 100 & 3.0 & 0.9302 \\\\ \\hline       \r\n\\end{tabular}\r\n\\end{table}  \r\n \\end{document}\r\n", "meta": {"hexsha": "d09803f70f62664ce7fdf908332aece10acf1e2c", "size": 7318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/hw9/readme.tex", "max_stars_repo_name": "spacemanidol/CLMS572", "max_stars_repo_head_hexsha": "f0380de9912c984ec21607cdb3b1f190853c5ca8", "max_stars_repo_licenses": ["MIT"], "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/hw9/readme.tex", "max_issues_repo_name": "spacemanidol/CLMS572", "max_issues_repo_head_hexsha": "f0380de9912c984ec21607cdb3b1f190853c5ca8", "max_issues_repo_licenses": ["MIT"], "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/hw9/readme.tex", "max_forks_repo_name": "spacemanidol/CLMS572", "max_forks_repo_head_hexsha": "f0380de9912c984ec21607cdb3b1f190853c5ca8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-26T01:28:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-26T01:28:41.000Z", "avg_line_length": 68.3925233645, "max_line_length": 457, "alphanum_fraction": 0.6590598524, "num_tokens": 2606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6469135427011944}}
{"text": "\n\\subsection{Weak- and wide-sense stationarity}\n\nUnconditional probabilities don't change over time.\n\nSo GDP would not be stationary, but random noise would. A random walk is not stationary, because the variance increases over time.\n\n\\subsection{Weak-sense stationary}\n\nMean and autocovarinance don't change over time.\n\n\\subsection{Wide-sense stationary}\n\nAll moments are the same.\n\n", "meta": {"hexsha": "7cdc60980ec923c6fe55f7355c43cdaee29c837a", "size": 383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticStationary/01-01-stationarity.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/stochasticStationary/01-01-stationarity.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/stochasticStationary/01-01-stationarity.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.9375, "max_line_length": 130, "alphanum_fraction": 0.7963446475, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.646839166618714}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 4.6 Solution of a Positive-Definite System \\hbox{with Cholesky Factorization}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis subroutine computes the solution vector ${\\bf x}$ for a system of\nequations of the form\n\\begin{equation}\n\\label{O1}P{\\bf x}={\\bf d},\n\\end{equation}\nwhere $P$ is an N$\\times $N positive-definite symmetric matrix, and ${\\bf d}$ is an\nN-vector. This subroutine also returns the Cholesky factor of $P$ and thus is\napplicable where computing the Cholesky factor is the objective.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Double Precision}\n\n\\begin{description}\n\\item[DOUBLE PRECISION]  {\\bf P}(LDP, $\\geq $N) [LDP $\\geq $ N]{\\bf , D}($%\n\\geq $N$)${\\bf , U, TOL}\n\n\\item[INTEGER]  \\ {\\bf LDP, N, IERR}\n\\end{description}\n\nAssign values to P(,), LDP, N, D(), U, and TOL.\n$$\n\\fbox{{\\bf CALL DCHOL (P, LDP, N, D, U, TOL, IERR)}}\n$$\nThe solution vector ${\\bf x}$ will be stored in D(). Additional computed\nquantities that may be of interest to the user in some situations will be\nstored in P(,) and U.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[P(,)]  \\ [inout] On entry this array must contain the N$\\times $N\nsymmetric positive-definite matrix $P$ of Eq.\\,(1). It suffices to provide only\nthe elements on and above the diagonal. On return this array will contain the\nN$\\times $N upper triangular matrix F defined by Eq.\\,(2) on and above the diagonal\npositions of the array P(,). Locations of the array P(,) below the diagonal\nwill not be referenced or modified by this subroutine.\n\n\\item[LDP]  \\ [in] Dimension of the first subscript of the storage array\nP(,). Require LDP $\\geq $ N.\n\n\\item[N]  \\ [in] Order of the matrix $P$. Require N $\\geq 1.$\n\n\\item[D()]  \\ [inout] On entry D() must contain the vector ${\\bf d}$ of Eq.\n(1). On return D() contains the solution vector ${\\bf x}$ for Eq.\\,(1).\n\n\\item[U]  \\ [inout] If U contains the number ${\\bf u}$ of Eq.\\,(10) or (15)\nrespectively on entry, then on return U will contain the number $\\rho $ of\nEq.\\,(11) or (16) respectively. If the user is not interested in having the\nnumber $\\rho $ computed, U should be zero on entry and will be unchanged on\nreturn.\n\n\\item[TOL]  \\ [in] A user-provided relative tolerance parameter to be used\nin the conditioning test of Eq.\\,(17). We suggest setting TOL to a value of $%\n10^{-(k+1)}$ where $k=\\min (k_A$, $k_b)$. Here $k_A$ is the user's estimate\nof the number of significant decimal digits in the elements of the matrix $A$\nand $k_b$ is the corresponding estimate for ${\\bf b}$. See Eq.\\,(7) or (12)\nfor the definitions of $A$ and ${\\bf b}$. If the TOL input is $<\\varepsilon $,\nwhere $\\varepsilon $ is the relative machine precision $(i.e$. the smallest\npositive number such that $1.0+\\varepsilon \\neq 1.0$ in the machine's\nfloating point arithmetic), then $\\varepsilon $ is used for TOL internally.\n\n\\item[IERR]  \\ [out] On return this is set to~0 if $t_{\\min }$ defined in\nEq.\\,(17) is greater than~0. Otherwise results are of\nquestionable validity and $|$IERR$|$ will equal the index of the equation\nthat resulted in the value for $t_{\\min }$. See Section E for more details.\n\\end{description}\n\n\\subsubsection{Modifications for Single Precision}\n\nWe recommend the use of double precision for this computation except on\nmachines such as the Cray that have $10^{-14}$ precision in single\nprecision. To use single precision change DCHOL to SCHOL, and the DOUBLE\nPRECISION type statement to REAL.\n\n\\subsection{Examples and Remarks}\n\nConsider the least-squares problem $A{\\bf x}\\simeq {\\bf b}$ where $A$ is the\n3~by~2 matrix and ${\\bf b}$ is the 3-vector defined by the DATA statements\nin the program DRDCHOL below. This program forms normal equations by\ncomputing $P=A^TA$ and ${\\bf d}=A^T{\\bf b}$. It also computes u $={\\bf b}^T%\n{\\bf b}$. It uses the subroutine DCHOL to solve the normal equations $P{\\bf x%\n}={\\bf d}$, and to compute the quantity RNORM $=\\rho =\\Vert {\\bf b}-A{\\bf x}%\n\\Vert $. Output from this program is given in the file ODDCHOL.\n\nFor programming convenience one may prefer to store the matrix $A$ and the\nvector ${\\bf b}$ together in the same array. The code in DRDCHOL2 shows how\nthis example can be programmed storing $A$ and ${\\bf b}$ together in the\narray AB() and using the array PDU() to hold $P$, ${\\bf d}$, and $u.$\n\n\\subsection{Functional Description}\n\nGiven the problem $P{\\bf x}={\\bf d}$, where $P$ is an N$\\times $N\npositive-definite symmetric matrix, there exists an upper triangular\nN$\\times $N matrix $F$ satisfying\n\\begin{equation}\n\\label{O2}F^TF=P\n\\end{equation}\nEq.\\,(2) defines the Cholesky decomposition of $P$. The upper triangular\nelements of $F$ will be computed from those of $P$ by the following\nequations, where $i=1$, ..., N.\n\\begin{align}\n\\label{O3}g_i&=p_{i,i}-\\sum_{k=1}^{i-1}f_{k,i}^2\\\\\n\\label{O4}f_{i,i}&=g_{i}^{1/2}\\\\\n\\label{O5}f_{i,j}&=\\frac{\\displaystyle p_{i,j}-\\sum_{k=1}^{i-1}f_{k,i}f_{k,j}%\n}{f_{i,i}},\\ \\ j=i+1,...,\\text{N}\\hspace{-2in}\n\\end{align}\nIn these formulas the summation is to be skipped when $i=1.$\n\nAfter computing $F$ the subroutine solves the lower triangular system of\nequations,%\n\\begin{equation*}\nF^T{\\bf y}={\\bf d}\n\\end{equation*}\nand then computes the vector ${\\bf x}$ which satisfies $P{\\bf x}={\\bf d}$ by\nsolving the upper triangular system%\n\\begin{equation*}\nF{\\bf x}={\\bf y}\n\\end{equation*}\nBesides computing the solution vector ${\\bf x}$ this subroutine uses the\ninput number $u$ given in the Fortran variable U to compute\n\\begin{equation}\n\\label{O6}\\rho =\\left[ \\max (0,u-{\\bf y}^T{\\bf y})\\right] ^{1/2}\n\\end{equation}\nThis number $\\rho $ is stored in U on return. If the problem $P{\\bf x}={\\bf d%\n}$ arose as the system of normal equations for a least-squares problem and\nif $u$ was computed appropriately by the user then $\\rho $ represents the\nnorm of the residual vector for the least-squares problem.\n\nSpecifically if the user wishes to solve the least-squares problem of\nminimizing\n\\begin{equation}\n\\label{O7}\\left\\| {\\bf b}-A{\\bf x}\\right\\| =\\left[ \\left( {\\bf b}-A{\\bf x}%\n\\right) ^T\\left( {\\bf b}-A{\\bf x}\\right) \\right] ^{1/2}\n\\end{equation}\nthen $P$, ${\\bf d}$, and $u$ should be initialized as\n\\begin{align}\n\\label{O8}P&=A^TA\\\\\n\\label{O9}{\\bf d}&=A^T{\\bf b}\\\\\n\\label{O10}u&={\\bf b}^T{\\bf b}\n\\end{align}\nThen theoretically, the quantity, $u-{\\bf y}^T{\\bf y}$ of Eq.\\,(6) will be\nnonnegative and the number $\\rho $ of Eq.\\,(6) will have the interpretation\n\\begin{equation}\n\\label{O11}\\rho =\\left\\| {\\bf b}-A{\\bf x}\\right\\|\n\\end{equation}\nMore generally, if the user is solving the weighted least-squares problem of\nminimizing\n\\begin{equation}\n\\label{O12}\\left[ \\left( {\\bf b}-A{\\bf x}\\right) ^TW\\left( {\\bf b}-A{\\bf x}%\n\\right) \\right] ^{1/2}\n\\end{equation}\nwhere $W$ is a positive definite symmetric matrix, then $P$, ${\\bf d}$, and $%\nu$ should be initialized as\n\\begin{align}\n\\label{O13}P&=A^TWA\\\\\n\\label{O14}{\\bf d}&=A^TW{\\bf b}\\\\\n\\label{O15}u&={\\bf b}^TW{\\bf b}\n\\end{align}\nThen, theoretically, the quantity $u-{\\bf y}^T{\\bf y}$ of Eq.\\,(6) will be\nnonnegative and the number $\\rho $ of Eq.\\,(6) will have the interpretation\n\\begin{equation}\n\\label{O16}\\rho =\\left[ \\left( {\\bf b}-A{\\bf x}\\right) ^TW\\left( {\\bf b}-A%\n{\\bf x}\\right) \\right] ^{1/2}\n\\end{equation}\nThe Cholesky factor matrix $F$ will appear in the upper triangular portion\nof the array P(,) on return. If IERR $\\geq 0$, the user can input this\nmatrix $F$ to the library subroutine DCOV2 of Chapter~4.2 to compute the\nunscaled covariance matrix for the associated least-squares problem. This\nrequires building the IP() array: IP(I) = I, for I $=1$, ..., N.\n\nTheoretically the numbers $g_i$ of Eq.\\,(3) will be strictly positive for all\n$i$ if and only if the symmetric matrix $P$ is positive-definite. If all $%\ng_i $ are positive but the ratio $g_i/p_{i,i}$ is very small for some $i$\nthis is an indication that the problem is ill-conditioned. The square of the\nrelative tolerance parameter TOL is used to test this ratio. Let\n\\begin{equation}\n\\label{o17}t_{\\min }=\\min _{1\\leq i\\leq \\text{N}}\\left\\{ g_i-(TOL)^2\\times\n|p_{i,i}|\\right\\} .\n\\end{equation}\nIf $t_{\\min }\\geq 0$, then IERR is set to~0. Otherwise let $m$ be a value of\n$i$ that gives the minimum value in Eq.\\,(17). Then IERR is set to $m$ if $%\ng_m>0$, and is set to $-m$ otherwise. See Section E below for more details.\n\nIf one knows or suspects that the least-squares problem is ill-conditioned\nit is suggested that the Singular Value Analysis subroutine, Chapter~4.3, be\nused to obtain a more complete analysis and a more reliable solution for the\nproblem.\n\nA nonnegative definite symmetric matrix has a Cholesky factor even if it is\nsingular. In computing a Cholesky factor for such matrices this subroutine\ndoes the following: If $g_i$ of Eq.\\,(3) is nonpositive, Eqs.~(4--5) are\nreplaced by\n\\begin{equation}\n\\label{O18}f_{i,j}=0,\\quad j=i,i+1,...,\\text{N}\n\\end{equation}\nWhen solving the triangular systems below Eq.\\,(5), if $f_{i,i}=0$ the\nsolution components $y_i$ and $x_i$ are set to zero. If $P$ is a singular\nnonnegative definite matrix, the matrix $F$ produced in this way is its\n(nonunique) Cholesky factor, $i.e.$, it satisfies Eq.\\,(2). In such a case\nEq.\\,(1) may or may not have a solution and the vector ${\\bf x}$ produced in\nthis way is the solution only if a solution exists.\n\n\\subsection{Error Procedures and Restrictions}\n\nIf $t_{\\min }<0$ in Eq.\\,(17), the subroutine sets IERR nonzero as\nindicated above. When IERR $< 0$, at least one row of the augmented\nmatrix [upper triangle of $P$, $D$] will have been set to zero.\n\nIf IERR $\\neq 0$ we suggest that the user apply the Singular Value Analysis\nsubroutine, Chapter~4.3, to the associated least-squares problem.\\vfill\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} \\\\\nDCHOL & \\hspace{.3in} AMACH, DCHOL\\rule[-5pt]{0pt}{8pt}\\\\\nSCHOL & \\hspace{.3in} AMACH, SCHOL\\\\\n\\end{tabular}\n\nProgrammed by: C. L. Lawson, JPL, May~1969.\n\nProgram Revised by: F. T. Krogh, JPL, September~1991.\n\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDCHOL}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dchol}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDCHOL}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dchol}}\n\n\\newpage\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDCHOL2}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dchol2}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDCHOL2}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dchol2}}\n\\end{document}\n", "meta": {"hexsha": "a3946d639eb52a0505de8ab2680b59d55f282716", "size": 10870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch04-06.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/ch04-06.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/ch04-06.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": 41.4885496183, "max_line_length": 98, "alphanum_fraction": 0.7067157314, "num_tokens": 3518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042765, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6467644729280715}}
{"text": "\\documentclass[a4paper, 11pt]{article}\n\\input{../preamble.tex}\n\n\\DeclareMathOperator{\\N}{\\mathbb{N}}\n\\DeclareMathOperator{\\R}{\\mathbb{R}}\n\\DeclareMathOperator{\\Q}{\\mathbb{Q}}\n\\DeclareMathOperator*{\\Z}{\\mathbb{Z}}\n\n\\title{The Exponential Function}\n\n\\begin{document}\n\n\\tableofcontents\n\\section{The exponential Function}\n\\begin{definition}[The exponential Function] \nThe function $\\exp: \\R \\rightarrow \\R$ is  is defined by $\\sum_{n=0}^{\\infty}\\frac{x^{n}}{{n}!}$. \nLet $\\phi: \\R \\rightarrow \\R$ defined by $\\phi(x) = \\lim_{n\\rightarrow \\infty} \\left( 1 + \\frac{x}{n} \\right)^n$.\nWe wish t that $\\phi = \\exp$\n\\end{definition}\n\n\\begin{proposition}\nLet us fix $x \\in \\R$. Then:\n\\begin{enumerate}\n  \\item For every natural number $n > |x|$, then $\\left(1 + \\frac{x}{n}\\right)^{n} < (1 - \\frac{x}{n})^{-n}$\n  \\begin{proof}\n    Suppose $n > |x|$. Then $0 \\leq \\frac{x^{2}}{n^{2}}<1$. Then using this fact,\n    consider the product \n    \\begin{align*}\n      \\left(1 + \\frac{x}{n}\\right)^n \\cdot \\left(1 - \\frac{x}{n}\\right)^n\n      &= \\left(\\left(1 + \\frac{x}{n}\\right)\\left(1 - \\frac{x}{n}\\right)\\right)^n \\\\\n      &=\\left(1 - \\frac{x^2}{n^2}\\right) \\\\\n      &<1\n    \\end{align*}\n    This follows from multiplying both parts of the previous inequality by the same power. If we divide\n    both sides by $\\left(1 - \\frac{x}{n}\\right)^n$, we conclude that $\\left(1 + \\frac{x}{n}\\right)^n  < \\left(1 - \\frac{x}{n}\\right)^{-n}$.\n    \n  \\end{proof}\n  \\item The sequence $\\left(1 + \\frac{x}{n}\\right)^n$ for $n > |x|$ is strictly increasing.\n  \\begin{proof}\n  Suppose $n > |x|$, we want to show that $(n + 1)$st element of the sequence is greather than the $n$th element of the sequence.\n\n  That is $\\left(x + \\frac{x}{n}\\right)^n \\leq \\left(x + \\frac{x}{n+1}\\right)^{n + 1}$. The A + M inequality:\n  Assume that $n \\geq2 $ and given $a_1, \\dots a_n \\in \\R,$ $(a_1 \\dots a_n)^{1/n} \\leq \\frac{a_1 + \\dots a_n}{n}$.\n  Consider $a_1 = 1, a_2 = \\left(1 + \\frac{x}{n}\\right), \\dots a_{n+1} = \\left(1 + \\frac{x}{n}\\right)$.\n  \\end{proof}\n  \\item The sequence $\\left(1 - \\frac{x}{n}\\right)^{-n}$ for $n > |x|$ is strictly decreasing.\n  \\item $\\left(1 + \\frac{x}{n}\\right)^{n} - \\left(1 - \\frac{x}{n}\\right)^{-n} \\rightarrow 0$ as $n \\rightarrow \\infty$.\n  These two sequences approach each other from the left and right. \n\\end{enumerate}\n\\end{proposition}\n\nBy (2), (3), and (4) of the proposition for $n > |x|$, the sequence of the closed intervals,\n\\begin{equation*}\n  \\left[ \\left(1 + \\frac{x}{n}\\right)^n, \\left(1 - \\frac{x}{n}\\right)^{-n}\\right]\n\\end{equation*}\nis nested. By the \\textbf{Nested Interval Lemma}, there is a unique real number contained in the intersection of all of these\nintervals. The common limit of the sequences of left endpoints and the sequence of right endpoints.\n\nThis enables us to make the following defintion\n\\begin{definition}\nDefine the function $\\phi: \\R \\rightarrow \\R$  for each $x \\in \\R$ where\n\\begin{equation}\n  \\phi(x) = \\lim_{n\\rightarrow \\infty} \\left(1 + \\frac{x}{n}\\right)^n = \\left(1 - \\frac{x}{n}\\right)^{-n}\n\\end{equation}\nNote: $\\phi(0) = 1$. We also define $e = \\phi(1)$ as the \\textbf{Euler's constant}.\n\\end{definition}\n\n\\begin{remark}{}\n  \\begin{enumerate}\n    \\item For every natural number $n \\in \\N$ such that $n > |x|$\n    \\begin{equation}\n      \\left(1 + \\frac{x}{n}\\right)^n \\leq \\phi(x) \\leq \\left(1 - \\frac{x}{n}\\right)^{-n}\n    \\end{equation}\n    \\item \n  \\end{enumerate}\n\\end{remark}\n\\end{document}", "meta": {"hexsha": "42d19219745a028e4c1f5627e93632b718075f7c", "size": 3440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/lecture_16.tex", "max_stars_repo_name": "tylertownsend/mathematics", "max_stars_repo_head_hexsha": "de7732a0fffe5cc1a79752a10b0aa21672f3f413", "max_stars_repo_licenses": ["MIT"], "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/lecture_16.tex", "max_issues_repo_name": "tylertownsend/mathematics", "max_issues_repo_head_hexsha": "de7732a0fffe5cc1a79752a10b0aa21672f3f413", "max_issues_repo_licenses": ["MIT"], "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/lecture_16.tex", "max_forks_repo_name": "tylertownsend/mathematics", "max_forks_repo_head_hexsha": "de7732a0fffe5cc1a79752a10b0aa21672f3f413", "max_forks_repo_licenses": ["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.6753246753, "max_line_length": 139, "alphanum_fraction": 0.6281976744, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631541, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6467644693210736}}
{"text": "\n\n\\section{Existing Protocols for Local DP}\n\nApart from R.R., several L.D.P. protocols have been implemented during the years, with many of them being widely used by companies in order to protect users' data. One of the most famous protocols is \\emph{RAPPOR}([15]), created by Google, and being currently used in the Chrome browser for the company to provide useful info to its users without compromising their privacy. Also, Apple has created ts own protocol of L.D.P., and utilize it in their products. \n\nHowever, we are not going to focus on those protocols moving forward, than the ones presented in [10], a paper which introduces many algorithms for L.D.P., each one with different perturbation techniques and suitable for different circumstances.\n\nDuring this chapter we are going to give a definition of each algorithm, implement it using Python, and compare the accuracy results produced by those protocols, just like during our testings of the G.D.P. models. Each protocol has two parts: the \\emph{users} and the \\emph{aggregator}. For the users we must each time define the following functions:\n\n\\begin{itemize}\n    \\item $Encode()$: Encodes the true value that the user wants to report\n    \\item $Perturb()$: Perturbs the encoded value, in order to produce the random value that will be reported\n\\end{itemize}\n\nFor the aggregator we must each time define the  $Aggregate()$ function, that collects the reported random values of the users, and produces the results according to the model.\n\n\\subsection{Basic RAPPOR}\nAs mentioned earlier, RAPPOR is a protocol created by Google. Its simpler form, Basic RAPPOR is used in Chrome, where it collects answers to questions such as the user's home page. The protocol's functions are the following:\n\n\\textbf{Encoding:} $Encode(v) = A_0$, where $A_0$ is a d-bit vector, such that: $A_0[v] = 1$ and $A_0[i] = 0$ for every $i \\neq v$. \n\n\\textbf{Perturbation:} The perturbation consists of 2 steps: the permanent and the instantaneous. The permanent one is carried out only one time, and is the following: \n\n\\begin{equation*}\n    Pr[A_1[i] = 1] =\n\t\\begin{cases}\n\t\t1 - \\frac{1}{2}f & \\mbox{if } A_0[i]=1 \\\\\n\t\t\\frac{1}{2}f & \\mbox{ otherwise}\n\t\t\t\\end{cases}\n\\end{equation*}\n\nThe instantaneous step is carried out every time a user reports a value, and is defined as:\n\n\\begin{equation*}\n    Pr[A_2[i] = 1] =\n\t\\begin{cases}\n\t\tp & \\mbox{if } A_1[i]=1 \\\\\n\t\tq & \\mbox{ otherwise}\n\t\t\t\\end{cases}\n\\end{equation*}\n\nWe observe from the above functions, that the user must define the $f, p $ and $q$ parameters. Google suggests that we set $f = \\frac{1}{2}$ or $\\frac{1}{4}$, and $p = 0.75$, thus $q = 0.25$. During our testings, those exact parameters were used. \n\n\n\\subsection{Random Matrix Projection}\nIn [14], a protocol with a random matrix projection is proposed, introducing an additional setup step.\n\n\\textbf{Setup:} A random and uniform matrix is generated before any encoding, with it being public and drawn as: $\\Phi \\in \\{-\\frac{1}{m}, \\frac{1}{m}\\}^{m \\times d}$, where $m$ and $d$ are user defined. In our testings, we opt to set $m = 5$ and $d = 10$.\n\n\\textbf{Encoding:} When it comes down to encoding, the function used is the following: $Encoding = (r,x)$, where $r$ is uniformly randomly selected from the range of m, and $x$ is the v-th element of the r-row of the random matrix.\n\n\\textbf{Perturbation}: The perturbation function is defined as following: \n\\begin{align*}\n Perturb(r,x) = (r, b\\cdot c \\cdot m \\cdot x) \n\\end{align*}\n where\n\\begin{equation*}\n    b =\n\t\\begin{cases}\n\t\t1 & \\mbox{with } p = \\frac{e^\\epsilon}{e^\\epsilon + 1} \\\\\n\t\t-1 & \\mbox{with } q = \\frac{1}{e^\\epsilon + 1}\t\t\t\n\t\\end{cases}\n\\end{equation*}\nand $c = \\frac{e^\\epsilon +1}{e^\\epsilon -1}$\n\n\\textbf{Aggregation:} Given all the tuples reported by $j$ users in the form $(r, y)$, the estimation for the i-th value of the dataset, is produced by \n\\begin{align*}\n\\sum_{j} y^j \\cdot \\Phi[r^j,i]\n\\end{align*}\n\n\\subsection{Pure Protocols}\n\nThe following protocols are presented in [10], and are called \"pure\" protocols, because of the way they aggregate the data produced by the user. For each one of them, we should define a $Support()$ function, that indicates for each value of the possible outcomes, the reported values that are supported. Thus, with the notation $\\sum_{j} Support(y^j)$, we mean the sum of all the supported values of the y-th element of the dataset.\n\nAlso, for a protocol to be pure, two probabilities must be defined, $p^*$ and $q^*$, where the first notes the probability that the true value is supported by an element $y$, and the second one the probability of another value is supported by the element $y$. The protocol is pure if and only if $p^* > q^*$.\n\nIf a protocol is pure, the estimation of the total reported values for an element of the dataset $i$, is the following:\n\n\\begin{align}\n    \\text{Estimation} = \\frac{\\sum_{j} 1_{support(y^j)}(i) - nq*}{p^* - q^*}\n\\end{align}\nwhere $j$ denotes the j-th user reporting their value, and $n$ the total size of the vector of the reported values.\n\n\n\\subsubsection{Direct Encoding}\n\nThis protocol is the natural method of extending the Randomized Response, without the limitation of 2 possible answers. \n\n\\textbf{Encoding:} The protocol does not feature an encoding procedure, thus \n\n\\begin{align*}\n    Encode(v) = v\n\\end{align*}\n\n\\textbf{Perturbation:} The perturbation is based on the epsilon setting given by the user, and its function is defined as following:\n\n\\begin{equation*}\n    Pr[Perturb(x) = i] =\n\t\\begin{cases}\n    \tp = \\frac{e^\\epsilon}{e^\\epsilon + d - 1} & \\mbox{if } i = x \\\\\n    \tq = \\frac{1}{e^\\epsilon + d - 1} & \\mbox{if } i \\neq x \n\t\\end{cases}\n\\end{equation*}\n\nwhere $d$ the size of the dataset of the possible answers, $x$ the true value and $i$ the value selected.\n\n\\textbf{Aggregation:} The protocol is pure with $p^* = p$, $q^* = q$ and $Support(i) = i$, thus the predicted results for each of the dataset's values can be calculated from the Equation 4.1.\n\nWe observe that this protocol strongly depends on the size of the dataset of the possible answers, thus when the dataset size increases, the protocol becomes less accurate, due to the decreased probability of selecting the truth. Moreover, for the D.E. protocol, all the false values have the same probability to get chosen, a rather disturbing detail for a query such as a person's age. We will return to these thoughts on later sections.\n\n\\subsubsection{Histogram Encoding}\n\nAn other protocol presented is Histogram Encoding, where an input when having $d$ options is encoded as a $d$-length vector.\n\n\\textbf{Encoding:} The encoding function is for the protocol is\n\n\\begin{align*}\n    Encoding(v) = [0, 0, \\dots, 1, \\dots, 0]\n\\end{align*}\n\nwhere only the v-th element of the vector is equal to 1.\n\n\\textbf{Perturbation:} The result of perturbing the encoded vector, is a new vector $B'$, s.t.: \n\n\\begin{align*}\n    B'[i] = B[i] + Lap(\\frac{2}{\\epsilon})\n\\end{align*}\nwhere $Lap()$ denotes the noise drawn from the Laplace distribution, where\n\n\n\\begin{align*}\n    Pr[Lap(\\beta) = x] = \\frac{1}{2\\beta}e^{\\frac{-|x|}{\\beta}}\n\\end{align*}\n\n\\textbf{Aggregation:} Several methods are proposed for aggregating the results created by the H.E. protocol, but as mentioned by the authors, the best one is called \\emph{Thresholding with H.E.}, where a threshold value is introduced in order to decide what to keep from the reported values. The support function is altered as following:\n\n\\begin{align*}\n    Support(B) = \\{v | B[v] > \\theta\\}\n\\end{align*}\nthus, if a noisy output is grater than theta, is set to support the corresponding value. According to the authors, the optimal value for θ is in the range of $(\\frac{1}{2}, 1)$. During the testings that are going to be conducted, we are going to use a threshold of $\\frac{2}{3}$.\n\n\nComparing this protocol to D.E., we observe that is solves the problem of the dependence of the noise drawn by the number of options to choose from. In H.E., no matter how large the domain size is, the noise solely depends on the epsilon value chosen by the user. Thus, when having a large domain size, it is clear that we should prefer the H.E. protocol over D.E.\n\n\\subsection{Unary Encoding}\n\nThe last protocol that is going to take part in the accuracy testings, is the Unary Encoding method, a further exploration of the Basic RAPPOR. It is a unique protocol, as the user does not set the level of privacy using epsilon, but by giving two probabilities, $p$ and $q$ and the epsilon value is computed using those two parameters.\n\n\\textbf{Encoding:} Exactly like in the H.E. method:\n\\begin{align*}\nEncoding(v) = [0, 0, \\dots, 1, \\dots, 0] \n\\end{align*}\nwhere only the v-th element of the vector is equal to 1.\n\n\\textbf{Perturbation:} This step is different than those that we already saw, and is carried out using the following function:\n\n\n\\begin{equation*}\n    Pr[B'[i] = i] =\n\t\\begin{cases}\n    \tp  & \\mbox{if } B[i] = 1 \\\\\n    \tq & \\mbox{if } B[i] = 0 \n\t\\end{cases}\n\\end{equation*}\n\nThe epsilon value is decided given $p$ and $q$, and is defined as following:\n\n\\begin{align*}\n    \\epsilon = ln(\\frac{p\\cdot(1-q)}{(1-p)\\cdot q})\n\\end{align*}\n\n\\textbf{Aggregation:} The Support function is once again altered, as in the U.E. protocol is defined as following:\n\n\\begin{align*}\n    Support(B) = \\{i | B[i] = 1\\}\n\\end{align*}\n\nand of course, $p^* = p$ and $q^* = q$, in order to make the protocol pure. As for the choice of $p$ and $q$, we opt to choose $p = \\frac{1}{2}$, and $q = \\frac{1}{e^\\epsilon + 1}$.\n\n\\section{Testings}\n\n\\subsection{Setup}\n\nNow that all those protocols where introduced, we are going to compare them in order to decide which is better to use when wanting to apply L.D.P. in a dataset. We are going to use a dataset that was created using random values, but corresponds to the age of a group of people. The distribution of the values of the dataset is shown in the histogram in \\textbf{Figure 4.2. }\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/true_answers_ldp.png}\n    \\caption{True Answers for the Dataset of LDP}\n\\end{figure}\n\nEach user will report one of these 50 values, and the aggregator of each protocol will gather the data given, and try to re-create this histogram in the best manner possible.\n\n\\subsection{Goal}\n\nWe want to decide which protocols behaves better, thus a number of different metrics will be used. The main focus of our testings will be the vectors that the aggregators provide, which we will compare with each other, as well as with the vector containing the true answers. In a similar way as our G.D.P. testings, we are going to run the protocols for different values of epsilon, and different number of users used. The second one is extremely important in L.D.P., as we mentioned earlier that many protocols struggle with a small number of input, as the noise drawn is significant. \n\nWith respect to the choice of metrics, we are going to use the \\emph{Manhattan Distance}, known as the $l1$-norm, as well as the \\emph{Kantorovic Distance}, explained in 3.2.5.1.\n\n\\subsection{Epsilon Measurements}\n\nThe first comparison between the protocols will be with a changing epsilon value, in order to observe how they behave for lower and higher values of the privacy setting. During these testings, all of the users of the dataset were used (approximately 20 thousand), and each run of each protocol was carried out 10 times, just like in other testings, in order to eliminate the danger of drawing extreme values of noise.\n\nFirst, we are going to run all the protocols and compare them using the Manhattan Distance. The results are shown in \\textbf{Figure 4.3.}\n\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/epsilon_others_l1.png}\n    \\caption{Epsilon Measurements compared by Manhattan Distance}\n\\end{figure}\n\n\nWe gather many useful observations from the graph:\n\n\\begin{itemize}\n    \\item The Random Matrix protocol does not function as expected, as \\emph{its accuracy does not follow the logarithmic curve we are used to when epsilon increases.} However, for small values of ε, its results are acceptable, and some times even better than the pure protocols.\n    \\item \\emph{The pure protocols behave in a similar way}, with the error stabilizing when epsilon gets higher than 2.5. \n    \\item \\emph{The Direct Encoding protocol was the worst behaviour among the pure ones}, with its error being extremely high for epsilon values lower than 1.  This is mainly due to the fact that when ε gets too small, the probability of telling the truth gets significantly low, thus creating a big error in accuracy.\n    \\item \\emph{The optimized U.E. protocol has the best behaviour} in comparison to the other protocols tested.\n\\end{itemize}\n\nNext up, we are going to run the same testings, but this time using the Kantorovich metric. We expect the protocols to behave even worse, because of the identity of the metric: the Kant. metric pays attention to the distance of the reported answer from the true one. The current protocols do not take into account the distance of the two answers, thus the metric will probably report a higher error. The results of the runs are shown in \\textbf{Figure 4.4.}\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/epsilon_others_kant.png}\n    \\caption{Epsilon Measurements compared by Kantorovic Distance}\n\\end{figure}\n\n\nAs we expected, the protocols produce a higher error, with the D.E. being the worst among them, especially for lower values of epsilon. This is a rather alarming notice, in which we will come back in Section 4.6.\n\n\n\\subsection{Increasing number of users}\n\n\nThe second experiment that we will conduct is the accuracy error depending on the number of users used during the survey covered by the protocol. In the definition of L.D.P. the observation of the need of lots of users was made, and it is now time that we examine it. We are going to use a \\emph{fixed epsilon value}, one that our protocols behave similarly for (at least the pure ones, in which we will focus our research moving forward). Our epsilon value that we are going ot used will be fixed and equal to 1.5.\n\nWe are going to run the protocols and compare them using the Manhattan Distance. Additionally, we are each time going to divide the result of the metric with the number of users participated, as the simple error is going to increase when the users increase. Hence, this division is going to give us the error depending on the size of our domain. The results are shown in \\textbf{Figure 4.5.}\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/nusers_others_l1.png}\n    \\caption{Increasing n. of users compared by Manhattan Distance}\n\\end{figure}\n\nThe results confirm the allegations made after explaining the definition of L.D.P.: When the number of participants in a survey is low, the error produced is very high. Every protocol has similar behaviour, as we can see that for fewer than 1000 users the relative error is even 6 times larger than for more than 1000 users. Actually, as we can see from the graph, the turning point is around 2000 users: the relative error drops and stabilizes after this number of participants. \n\nAn other observation made, is that the protocol with the best behaviour during our epsilon measurements (Unary Encoding), is the worst one in the low users testings. This of course gets better as the number of participants rises, and eventually beats the other protocols when it comes down to relative accuracy error. \n\nNext up, we are going to perform the same testings while comparing the protocols with the Kantorovich metric. The results are shown in \\textbf{Figure 4.6}.\n\n\\begin{figure}[!htb]\\centering\n    \\includegraphics[width=1\\textwidth]{images/nusers_others_kant.png}\n    \\caption{Increasing n. of users compared by Kantorovich Distance}\n\\end{figure}\n\nThe results for a low number of users differ a lot from the runs with the $l1$ distance as a metric. Here, the D.E. method has obviously the worst behaviour, and the U.E. method the best. We can even claim that U.E. seems to solve our problem of high accuracy error. However, no one of those protocols takes into account the distance of the reported answer from the true one, thus it makes sense that the Kantorovich metric produces a huge amount of accuracy error.\n\nThat fact, triggered our thoughts, on what could possibly be done in order to reduce that problem. The thoughts made on this subject are analyzed in the next chapter, by creating a new L.D.P. protocol, sensitive to the distance between the true and the reported values.", "meta": {"hexsha": "5ebcbfeb7766a4af089a51a0256a8ed2f7b31c47", "size": 16632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis_paper/LDP/other_protocols.tex", "max_stars_repo_name": "nikosgalanis/bsc-thesis", "max_stars_repo_head_hexsha": "b5521e995f266ff1aeb9fecc220650483630dc04", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-07-29T15:24:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T13:57:07.000Z", "max_issues_repo_path": "thesis_paper/LDP/other_protocols.tex", "max_issues_repo_name": "nikosgalanis/bsc-thesis", "max_issues_repo_head_hexsha": "b5521e995f266ff1aeb9fecc220650483630dc04", "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": "thesis_paper/LDP/other_protocols.tex", "max_forks_repo_name": "nikosgalanis/bsc-thesis", "max_forks_repo_head_hexsha": "b5521e995f266ff1aeb9fecc220650483630dc04", "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.4651162791, "max_line_length": 586, "alphanum_fraction": 0.7455507456, "num_tokens": 4315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658104908603, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6467644678492837}}
{"text": "\\section{The derivation of the ZOGY difference image}\n%\n\\par In this document, we study some practical issues of performing\nthe ZOGY subtraction and its relation to the Alard--Lupton (AL) method\n\\citep{AL1998} combined with the decorrelation afterburner. We assume\nthat the reader is somewhat familiar with the Zackay--Ofek--Gal-Yam\n(ZOGY) algorithm deduction steps in the ZOGY\npaper\\citep{ZOGY2016} Appendix A.\n%\n\\par We recall four key ideas behind the ZOGY subtraction method: a) Given\nan image with uncorrelated, homoscedastic pixel noise (the noise variance in\neach pixel is the same value all over the image), its convolution with an\narbitrary kernel leads to noise correlation between the resulting\npixels. However, in frequency space, the frequencies remain independent (as\nrandom variables), only the amplitude (variance) of their noise content\nchanges. b) The independent frequency space pixels are complex Gaussian\nrandom variables. For a signal detection purpose, similar log\nprobability expressions can be written as for the real-valued random\nvariables (image pixels). c) Log probability can be calculated as a sum over\nall the independent frequencies, weighting the squared absolute difference\nat each frequency with its inverse noise variance. d) The detection\nstatistic in frequency space can be split into two multiplicative terms. In\nimage space, these two terms can be interpreted as a difference image and\nits PSF, which produces a per-pixel detection statistic by convolution. The\ndifference image is constructed in frequency space so that each frequency\nbin is a (complex) random variable and has the same variance. This implies\nthat the difference image in image space has uncorrelated (and under the\nmodel assumptions), homoscedastic noise in its pixels. The difference image\nnoise remains uncorrelated despite the PSF matching procedure.\n%\nWe recall the following equations from the ZOGY paper.\nThe new \\(N\\) science and the reference \\(R\\) images are modeled as:\n\\begin{align}\nR &= F_rT\\otimes P_r + \\epsilon_r\\\\\nN &= F_nT\\otimes P_n + \\epsilon_n\n\\label{eq:N}\n\\end{align}\nwhere \\(F_r, F_n\\) are photometric scaling constants, \\(T\\) is the\n\\emph{truth} image, \\(P_r, P_n\\) are the image PSFs and \\(\\epsilon_r,\n\\epsilon_n\\) are per-pixel Gaussian white noise with homogenous variance in\nthe images.\n%\n\\par The detection statistic of \\(N\\) having a different \\(T\\) value than \\(R\\)\nat any pixel position can be written in frequency space as:\n\\begin{equation}\n  \\hat{S} = \\frac{F_nF_r^2\\overline{\\hat{P}_n}\\abs{\\hat{P}_r}^2 \\hat{N}\n - F_rF_n^2\\overline{\\hat{P}_r}\\abs{\\hat{P}_n}^2 \\hat{R}\n}\n{ \\sigma_r^2F_n^2\\abs{\\hat{P}_n}^2 + \\sigma_n^2F_r^2\\abs{\\hat{P}_r}^2 }\n\\label{eq:S}\n\\end{equation}\nIn image space, \\(S\\) is called the score or significance image and\nrepresents the significance of a source detection for each pixel.\n%\nThe difference image is defined as:\n\\begin{equation}\n\\hat{D} = \\frac{F_r \\hat{P}_r\\hat{N} - F_n \\hat{P}_n \\hat{R}}\n{\\sqrt{\\sigma_r^2F_n^2\\abs{\\hat{P}_n}^2 + \\sigma_n^2F_r^2\\abs{\\hat{P}_r}^2}}\n\\label{eq:Dhat}\n\\end{equation}\nand its PSF:\n\\begin{equation}\n\\hat{P}_D = \\frac{F_rF_n\\hat{P}_n\\hat{P}_r}\n{F_D\\sqrt{\\sigma_r^2F_n^2\\abs{\\hat{P}_n}^2 +\n    \\sigma_n^2F_r^2\\abs{\\hat{P}_r}^2}}\n\\label{eq:Pdhat}\n\\end{equation}\nso that:\n\\begin{equation}\n\\hat{S} = F_D\\hat{D}\\overline{\\hat{P}_D}\n\\label{eq:Shat}\n\\end{equation}\nThe difference image (and similarly the score image) can be written as the\ndifference of two ``matched'' images as in \\Cref{eq:c1N_c2R}.\n\\begin{equation}\n\\hat{D}_z = \\frac{\\frac{\\hat{P}_r}{F_n}}\n{\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_r}^2\n + \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_n}^2}}\n\\hat{N} -\n\\frac{\\frac{\\hat{P}_n}{F_r}}\n{\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_r}^2\n + \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_n}^2}}\n\\hat{R}\n=\n\\hat{c}_n \\hat{N} - \\hat{c}_r\\hat{R}\n\\label{eq:c1N_c2R}\n\\end{equation}\n%\n\\par Here \\(\\hat{c}_n\\) and \\(\\hat{c}_r\\) are the matching kernels for\nthe original science and template images. If the original image PSFs\nare accurately described by \\(P_r, P_n\\), then the frequency space\nmultiplications transform the PSFs of the two images to be identical,\n\\(P_D\\), \\Cref{eq:Pdhat}. Note that while we followed the terminology\nof the ZOGY paper here and referred to the images as science and\nreference images, the entire ZOGY method is symmetrical to the swapping\nof the images. In the following, we may simply denote images with 1\nand 2 indices.\n%\n\\section{Discussion points}\nWe list the following questions that can define the direction of future\nZOGY image differencing code development in the LSST stack.\n%\n\\par How does an ideal Gaussian PSF point source look like theoretically in\na ZOGY difference image? Discussed in \\Cref{sec:ZOGYtheo}.  In\n\\Cref{sec:ZOGYFFT}, we look for answers: What causes the extensive,\noscillating visual patterns in the ZOGY difference image around certain\nsources and image features (\\Cref{sec:FFTlimits})? What shall we do with the\nnumerical problems that appear in certain regions in frequency space and\nappear as pattern artifacts in image space (\\Cref{sec:workaround})? Shall we\nimplement a Gaussian PSF approximator that produces the PSF frequency space\nrepresentation directly?  Shall we implement a Gaussian PSF width estimation\nto determine which input PSF is sharper so that a realistic limiting value\ncan be used at frequencies when both PSFs (in frequency space) are below a\nthreshold (\\Cref{sec:workaround})?  How shall we handle\ndivision by zero scenarios in the ZOGY difference and significance image\ncalculation (\\Cref{sec:PSFzero})?\n%\n\\par In the Appendix, among other smaller topics, we raise the question whether\nwe can use zero padding for calculating the score image, or shall we use\nmodel white noise padding (\\Cref{sec:zeropadS})?\n%\n\\section{The theoretical solution of the ZOGY matching kernel and difference\nimage PSF\\label{sec:ZOGYtheo}}\n%\n\\par In this section, we derive numerical solutions for pure Gaussian\nPSFs. The inverse Fourier transforms of the ZOGY matching\nkernel or difference image PSF expressions are not expressible in closed\nsymbolic forms, even in this case. We perform numerical integration of the\nfunctions.\n%\n\\begin{figure}\n\\begin{center}\n  \\includegraphics[width=5.5in]{fig/zogy_theo_Gaussians_ft_Pd_c1_c2.pdf}\n\\end{center}\n\\caption{\\label{fig:theo_Gaussians_ft}1D slice along the x-axis in frequency\n  space of the matching kernels and the PSF of the ZOGY difference\n  image. The Fourier space representation of the input PSFs is also\n  shown. The two PSFs have widths of $\\sigma_1 = 1$, $\\sigma_2 = 2$ in image\n  space, i.e.\\ \\(\\mathrm{PSF}_1\\) is originally the narrower but the Fourier\n  transformation swaps this relation.}\n\\end{figure}\n%\n\\par In \\Cref{fig:theo_Gaussians_ft}, we show 1D slices of the 2D solutions\nof \\(P_d\\), \\(c_1\\) and \\(c_2\\). Noise variances and photometric scaling\nfactors are unity for simplicity. As the input PSFs are pure Gaussians,\ni.e.\\ symmetric, real value functions, their Fourier transforms are also\nreal and symmetric.\\footnote{Detailed calculation notebooks are part of\n  DM-26087.} Note the different behavior of the two matching kernels towards\nhigh frequencies. The matching kernel of the narrower PSF image \\(c_1\\) goes\nto zero, while the other one goes to unity here. While the graphs of \\(c_1\\)\nand \\(c_2\\) resemble to Gaussians, they are not anymore, and we must use\nnumerical integration to calculate their inverse Fourier transform. Their\nimage space values for points along the x-axis is shown in\n\\Cref{fig:theo_Gaussians_img_c1,fig:theo_Gaussians_img_c2}.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/zogy_theo_Gaussians_img_Pd.pdf}\n\\end{center}\n\\caption{\\label{fig:theo_Gaussians_img_Pd}1D slice along the x-axis in image\n  space of the PSF of the ZOGY difference image with the input image PSFs.}\n\\end{figure}\n%\n\\par In \\Cref{fig:theo_Gaussians_img_Pd}, the PSF of the ZOGY difference\n  image is shown. It is close to the wider input PSF, but strictly it's not\n  a Gaussian, it has a negative overshoot, about 1\\% of its peak\n  value. This means that in an ideal case, signals in a ZOGY difference\n  image are expected to have small negative rings around their positive\n  peaks.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=4.5in]{fig/zogy_theo_Gaussians_img_c1.pdf}\n\\includegraphics[width=4.5in]{fig/zogy_theo_Gaussians_img_c1_tails.pdf}\n\\end{center}\n\\caption{\\label{fig:theo_Gaussians_img_c1}1D slice along the x-axis in image\n  space of the matching kernel for the narrower PSF image. The matching\n  kernel is a Gaussian-like curve that has a small oscillating correction in\n  the tails.}\n\\end{figure}\n%\n\\par For the narrower PSF input image, the matched PSF is created by\nconvolution with the matching kernel \\(c_1\\), shown in\n\\Cref{fig:theo_Gaussians_img_c1}. This matching kernel is similar to usual\nGaussian blurring but slightly narrower and has a negative tail itself.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=4.5in]{fig/zogy_theo_Gaussians_img_c2.pdf}\\,\n\\includegraphics[width=4.5in]{fig/zogy_theo_Gaussians_img_c2_tails.pdf}\n\\end{center}\n\\caption{\\label{fig:theo_Gaussians_img_c2}1D slice along the x-axis in image\n  space of the matching kernel for the wider PSF image. The matching kernel\n is the sum of a Dirac delta minus a Gaussian-like curve.}\n\\end{figure}\n%\n\\par For the wider image, the matching kernel \\(c_2\\) is an identity Dirac\ndelta kernel minus a Gaussian-like correction\n(\\Cref{fig:theo_Gaussians_img_c2}). The Dirac delta is the inverse transform\nof the non-zero constant level of \\(c_2\\) in \\Cref{fig:theo_Gaussians_ft}\nthat must be subtracted for the numerical integration to converge. The Dirac\ndelta peak is manually added to the result in \\Cref{fig:theo_Gaussians_img_c2}.\n%\n\\par Note that in case of identical PSFs, both \\(c_1\\) and \\(c_2\\) become\nconstant in \\Cref{fig:theo_Gaussians_ft} which correspond to Dirac deltas in\nimage space. I.e. the matching operation is naturally reduced to the\nidentity operation if the two PSFs are already identical.\n%\n\\clearpage\n%\n\\section{The FFT calculated matching kernel of the ZOGY difference image\\label{sec:ZOGYFFT}}\n%\n\\par In practice, the ZOGY subtraction is implemented by Fast Fourier\nTransforms (FFT). In this and the following sections, we study\npractical numerical aspects of this approach.\n%\n\\par In \\Cref{fig:hits_zogy_artifacts}, we show typical patterns that appear\naround features that do not subtract well. These sources are present in all\nvisits in the HiTS2015 data AL image difference processings and in some\nvisits they produce different artifacts in the AL subtraction as well;\nhowever, AL artifacts are spatially more localized to the source than in the\nZOGY case. The ZOGY patterns can also appear in the vicinity of masked\nregions, cosmic rays, or close to the image edges.\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=3in]{fig/zogy_artifacts_v412060.png}\n\\includegraphics[width=3in]{fig/AL_goodvisit_v412060.png}\n\\end{center}\n\\caption{\\label{fig:hits_zogy_artifacts}High frequency artifacts in the ZOGY\n  difference image (left) around bright sources that are present in all\n  visits in the AL processing as well. In the same visit, the AL subtraction\n  (right) has less pronounced visual imperfections.}\n\\end{figure}\n%\n\\subsection{Zero values of the PSF\\label{sec:PSFzero}}\n%\n\\par In \\Cref{eq:Dhat}, \\(\\hat{D}\\) is not defined at frequencies where both\nimage PSFs are zero. Indeed, according to the image models (\\Cref{eq:N}), at\nthese frequencies, the input images do not carry any information about the\ntrue image. They consist of pure noise. In accordance with this, these\nfrequencies have zero contribution to \\(\\hat{S}\\).\n%\n\\par We cannot allow zero division in our calculations anyway, thus we\nneed to have a workaround for pixels where the denominator in\n\\Cref{eq:S,eq:Dhat} are zero. We define \\(\\hat{D}\\) at these\nfrequencies as the straightforward subtraction of the two images with\nthe same scaling to keep the variance constant at all\nfrequencies. Of course, \\(\\hat{S}=0\\) at these pixels. This is\ncurrently implemented in the code stack.\n%\n\\subsection{Matching kernel limit values in frequency space\\label{sec:FFTlimits}}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/fft_steps_fc1.pdf}\n\\end{center}\n\\caption{\\label{fig:fft_steps_fc1}FFT calculated matching kernel for two\n  Gaussian PSFs, here for the wider PSF image. This is a Fourier space image\n  with low frequencies at the corners. In this calculation \\(\\sigma_1=3.3\\),\n  \\(\\sigma_2=2.2\\) PSFs were generated in a 31x31 size image, that were zero\n  padded to 1024x1024 image size before FFT. Per pixel noise variance is 100\n  for both images, photometric scalings are unity. All values are real due\n  to symmetry in the inputs.}\n\\end{figure}\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/fft_steps_fc2.pdf}\n\\end{center}\n\\caption{\\label{fig:fft_steps_fc2}FFT calculated matching kernel for the\n  narrower PSF image. This is a Fourier space image with low frequencies at\n  the corners. All values are real due to symmetry in the inputs.}\n\\end{figure}\n%\n\\par We saw in the theoretical solution section, that in case of\nGaussian PSF-s, the matching kernels in frequency space have tails\nconverging to different limit values. The limit values are either zero\nor a non-zero constant depending on whether the matching kernel belongs\nto the narrower or wider input PSF image, respectively.\n%\n\\par In \\Cref{fig:fft_steps_fc1,fig:fft_steps_fc2}, \\(\\hat{c}_1\\),\n\\(\\hat{c}_2\\) are calculated from two 31x31 pixel size Gaussian PSFs\nthat were zero padded for a 1024x1024 image size, with\n\\(\\sigma_1=3.3\\), \\(\\sigma_2=2.2\\).\\footnote{Detailed calculation\nnotebooks are part of DM-26941.} All numbers are real in this\ncase. The shown frequency space images are in their natural FFT\norientation with zero frequencies at the corners and highest\nfrequencies in the centers. Starting from the corners, both solutions\nfollow our expectations, converging either down to zero or to their\nexpected non zero constant (\\( 1/\\sigma_{\\mathrm{pixelnoise}} \\) )\nplateau. The trend breaks for both kernels in high frequency regions\nhowever, and high value noise appears.\n\\begin{equation}\n\\hat{c}_1 \\sim \\frac{1}{\\sqrt{1 + \\left(\\frac{\\hat{P}_1}{\\hat{P}_2}\\right)^2}}\n\\label{eq:c1conv}\n\\end{equation}\n\\par The matching kernel limit values depend on whether\n\\(\\hat{P}_1/\\hat{P}_2\\) is converging to zero or diverges as it can be seen\nin \\Cref{eq:c1conv}. Once we reach the point where the Gaussian tails are\ndominated by noises\\footnote{See \\Cref{sec:floating_point}}, the convergence\nproperties of these fractions become lost and the calculated matching kernel\nvalues significantly deviate from their expected limit values.\n%\n\\subsection{Patterns in image space\\label{sec:patterns}}\n\\par What does this mean for our calculated matching kernels back in\nimage space?\n%\n\\par In \\Cref{fig:twoG_c1}, we show \\(c_1\\) transformed and\nre-centered back to image space (but still in its fully padded image\nsize). The purple structure indicates that there is a sign oscillation\npattern all across padded size image.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/twoG_defaults_c1.pdf}\n\\end{center}\n\\caption{\\label{fig:twoG_c1}Two Gaussian PSFs with spatial widths of \\(\\sigma_N = 3.3\\)\n  \\(\\sigma_R = 2.2\\) pixels. \\(c_1\\), the ZOGY matching convolution in image space\n  of the new (\\(N\\)) image. The purple pattern is an indication of\n  sign oscillation all over the image.}\n\\end{figure}\n%\n\\par We can see that in the direction of the two axes, there are definite\npurplish patterns. The purple color on this red-blue color scale shows a\nsign oscillation that can be verified in zoomed-in versions of the\nfigure. These patterns do not fade away in the direction of the axes from\nthe center, indicating that these oscillating sign values have roughly the\nsame order of magnitude absolute values. The original PSF size 31x31 cannot\nbe clearly identified any more in the image either. We note that\nthe appearance of these patterns is independent of the padding\nsize.\n%\nIn \\Cref{fig:twoG_pd} \\(P_d\\) is shown, calculated by \\Cref{eq:Pdhat}.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/twoG_defaults_Pd.pdf}\n\\end{center}\n\\caption{\\label{fig:twoG_pd}Two Gaussian PSFs with spatial widths of\n  \\(\\sigma_N = 3.3\\) \\(\\sigma_R = 2.2\\). \\(P_d\\), the PSF of the zogy\n  difference image.}\n\\end{figure}\nWe also show the PSF of \\(S\\) in \\Cref{fig:twoG_ps}. The PSF of the\nscore image shows how a Dirac delta signal (in the truth image)\nappears in \\(S\\), though in source detection, only the actual pixel\nvalues matter in \\(S\\), the shape of the PSF does not.\n\\begin{figure}\n  \\begin{center}\n    \\includegraphics[width=5.5in]{fig/twoG_defaults_Ps.pdf}\n  \\end{center}\n\\caption{\\label{fig:twoG_ps}Two Gaussian PSFs with spatial widths of\n  \\(\\sigma_N = 3.3\\) \\(\\sigma_R = 2.2\\) \\(P_s\\), the PSF of the score\n  image.}\n\\end{figure}\n%\n\\par \\(P_d\\) and \\(P_s\\) have much cleaner images, contained in size\nin image space, and close to our theoretical\nexpectations. (\\(\\hat{P}_s \\sim \\hat{P}_d \\overline{\\hat{P}_d}\\)).\n%\n\\par Recall that while we expressed \\(P_d\\) in \\Cref{eq:Pdhat} as the\nfunction of the input PSFs, in a difference image this is the result\nof the convolution of the images with the matching kernels.  The high\nfrequency noise in the matching kernel is not disturbing, so long the\nimage follows the model PSF assumption and has approximately Gaussian\nPSF features that suppress high frequencies. If there are edges, or\nsignals with high frequency components in the input images, the noisy\nhigh frequency features of the matching kernel becomes visible in the\ndifference image. Our current understanding is that the deviation of\nthe image PSF from the model assumption and the numerical noise\nin the matching kernels together cause the visible artifacts in the\ndifference images produced by the code stack. This conclusion is\nsupported by tests on simulated images that have sources only with\nperfect Gaussian PSFs. In these cases, no visual artifacts can be seen.\n%\n\\subsection{Workaround for artifact suppression\\label{sec:workaround}}\nWe propose the following workarounds for the difference image artifact\nproblem:\n\\begin{itemize}\n  \\item In a Gaussian PSF approximation, we can directly create the\n    PSF in the padded, full-size frequency space, avoiding the zero\n    padding of a small image then the FFT operation. However, this\n    approach restricts our input kernels strictly to Gaussians.\n  \\item In a more generic approach, we can still use the padded, FFT-d\n    detected PSFs of the input images. Using a radius approximation, we\n    can determine which input PSF is the wider one in a Gaussian\n    approximation. Then we can introduce a configurable threshold in\n    \\emph{frequency space} and pixels in the matching kernels can be\n    replaced with their Gaussian limit values wherever the input PSFs\n    go below the threshold (in absolute value, in frequency space).\n  \\item As a third option, we should recall, that the noise artifacts\n    appear only in the difference image. In the score image, these are\n    automatically suppressed by further convolution with \\(P_d\\). We\n    can choose to use the score image only directly for detection\n    significance.\n\\end{itemize}\n%\n\\par We repeated the above exercise by generating the Gaussian PSFs directly\nin frequency space and performed exactly the same matching kernel and\n\\(P_d\\) calculations. These results can be seen in\n\\Cref{fig:fft_steps_direct_fc1fc2,fig:fft_steps_direct_c1c2,fig:fft_steps_direct_Pd}. These\nsolutions fully satisfy the theoretical limit values and their image space\ncounterparts are free from any noisy patterns.\n%\n\\begin{figure}\n\\begin{center}\n  \\includegraphics[width=4.5in]{fig/fft_steps_direct_fc1.pdf}\n  \\includegraphics[width=4.5in]{fig/fft_steps_direct_fc2.pdf}\n\\end{center}\n\\caption{\\label{fig:fft_steps_direct_fc1fc2}The matching kernels for two\n  Gaussian PSFs in frequency space. In this calculation, PSFs were\n  directly generated in an 1024x1024 frequency space image\n  corresponding to image space \\(\\sigma_1=3.3\\), \\(\\sigma_2=2.2\\)\n  widths. Per pixel noise variance is 100 for both images, photometric\n  scalings are unity.}\n\\end{figure}\n%\n\\begin{figure}\n\\begin{center}\n  \\includegraphics[width=4.5in]{fig/fft_steps_direct_c1_zoomed.pdf}\n  \\includegraphics[width=4.5in]{fig/fft_steps_direct_c2_zoomed.pdf}\n\\end{center}\n\\caption{\\label{fig:fft_steps_direct_c1c2}The matching kernels inverse\n  FFT-d into image space, re-centered and zoomed in for\n  details.}\n\\end{figure}\n%\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=5.5in]{fig/fft_steps_direct_Pd_zoomed.pdf}\n\\end{center}\n\\caption{\\label{fig:fft_steps_direct_Pd}The difference image PSF\n  inverse FFT-d into image space, re-centered and zoomed in for\n  details.}\n\\end{figure}\n%\n\\clearpage\n%\n\\section{Variance plane calculation of the difference image\\label{sec:varplane}}\n\\par While the ZOGY image model does not strictly allow for different\nper-pixel noise values (its noise model assumes homogeneous variance\nnoise across all pixels), from the \\Cref{eq:c1N_c2R} form of the\ndifference image, we can propagate the different pixel variance\ninformation in the variance planes into the difference image. To do\nthis, we notice that if we do convolution on an image of independent\nnoise then, in image space, the variance plane should be convolved by\nthe square of the convolution kernel. This is the well-known square\naddition of variances of independent random variables.\\footnote{See\n  also ZOGY paper eqs. 26-29.}\n%\n\\par We'd like to emphasize that this step cannot be applied to an\nimage with already correlated noise; the square addition of pixel\nnoise in the variance plane do not account for the covariance terms\nand would result in underestimation of the pixel\nvariance. Notably, the effect of a noise decorrelation\n(whitening) kernel on an already convolved image cannot be applied to\nthe variance plane based on the square addition rule as it would lower\nthe variance further instead of reverting it to the uncorrelated\nlevel. In accordance with this, the image space square operation is\nnot distributive with respect to convolution in general; the square of the\nconvolution of two kernels is not the same as the convolution of the\nsquared kernels, and we should always perform the former.\n%\n\\par To calculate the variance plane of the difference image, we\nshould calculate \\(c_n\\), \\(c_r\\) in \\Cref{eq:c1N_c2R}, transform them\nback to image space, square them in image space, and convolve the\noriginal images' variance planes with these squared matching kernels\n(\\Cref{eq:VarD}). In practice, this convolution is more\nstraightforward to be performed in frequency space again because these\nimages already share common, full image size dimensions (the\ndimensions of our ZOGY frequency space calculations).\n\\begin{align}\n  V_D &= V_N \\otimes \\left(c_n^2\\right) + V_R \\otimes \\left(c_r^2\\right)\\label{eq:VarD}\\\\\n  \\sigma_D^2 &= \\sigma_N^2 \\sum c_n^2 + \\sigma_R^2 \\sum c_r^2\\label{eq:sigmaD} \n\\end{align}\n%\n\\par In the homoscedastic approximation (\\Cref{eq:sigmaD}), using the\nParseval theorem (\\Cref{sec:parseval}), it can be seen that the zogy\n\\(\\hat{D}\\) is scaled (\\Cref{eq:Dhat}) so that \\(\\sigma_D^2 = 1\\) for\nevery pixel, while the flux is scaled to \\(F_D\\). Note that in the AL\nplus decorrelation afterburner case, the flux is preserved, and the\nnoise variance is scaled to \\(\\sigma_n^2 / F_n^2 + \\sigma_r^2\n/F_r^2\\). See \\Cref{eq:K,eq:KPre}.\n%\n\\par \\Cref{eq:Shat} can also be written similarly to \\Cref{eq:c1N_c2R}\nand the variance plane of S can be calculated analogously\n(\\Cref{eq:VarD}) this way as well.\n%\n\\section{ZOGY and AL equivalence\\label{sec:ALZOGYequiv}}\n\\par The classic AL algorithm matches the reference image to the new\nscience image by convolving it with a matching kernel. In frequency\nspace, the matching kernel solution ideally equals to the quotient of\nthe two image PSFs as shown in \\Cref{eq:Dal}.\n%\n\\begin{equation}\n  \\hat{D}_{AL} =\n  \\frac{\\hat{P}_{pre}}{F_n}\\hat{N} -\n    \\frac{\\hat{P}_{mk}}{F_r}\\hat{R}\n  =\n  \\frac{\\hat{P}_{pre}\\hat{N}}{F_n} -\n    \\frac{\\hat{P}_n\\hat{P}_{pre}\\hat{R}}{\\hat{P}_r F_r}\n                 \\label{eq:Dal}\n\\end{equation}\n%\n\\par The decorrelation afterburner was created as a post-processing\ncorrectional step on the difference image. It is calculated in\nfrequency space so that it decorrelates (whitens) the noise of the\ndifference image back in image space. We introduce the formula in\n\\Cref{eq:K} and discuss more details in \\Cref{sec:decorrab}.\n%\n\\begin{align}\n\\hat{K}  &= \\frac\n  {1}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_{pre}}^2 +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_{mk}}^2}}\n  \\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}\\label{eq:K}\n\\end{align}\n%\n\\par In \\Cref{eq:DzPz,eq:DzPrPrPz,eq:DaldPald}, we write the ZOGY score image in frequency\nspace and expand the expression to demonstrate that the AL matching\nand subtraction combined with the decorrelation afterburner noise\nwhitening theoretically leads to the same detection statistics.\n%\n\\begin{align}\n  \\hat{S} \\sim \\hat{D}_Z\\overline{\\hat{P}_Z} &= \\frac\n  {\\frac{\\hat{P}_r\\hat{N}}{F_n} - \\frac{\\hat{P}_n\\hat{R}}{F_r}}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_r}^2 +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_n}^2}}\n  \\cdot\n  \\frac{\\overline{\\hat{P}_n\\hat{P}_r}\\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_r}^2 +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_n}^2}} = \\label{eq:DzPz}\\\\\n &= F_D \\frac\n  {\\left(\\frac{\\hat{N}}{F_n} -  \\frac{\\hat{R}}{F_r} \\cdot\n    \\frac{\\hat{P}_n}{\\hat{P}_r}\\right) \\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}} }\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2} +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\frac{\\hat{P}_n}{\\hat{P}_r}}^2}}\n  \\cdot\n  \\underbrace{\n  \\frac{\\hat{P}_r}{\\abs{\\hat{P}_r}}\n  \\cdot\n  \\frac{\\overline{\\hat{P}_r}}{\\abs{\\hat{P}_r}}\n  }_{1} % underbrace\n  \\cdot\n  \\frac{\\overline{\\hat{P}_n}\\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2} +\n      \\frac{\\sigma_r^2}{F_r^2}\\frac{\\abs{\\hat{P}_n}^2}{\\abs{\\hat{P}_r}^2}}} = \\label{eq:DzPrPrPz}\\\\\n  &= F_D \\hat{D}_{AL+d} \\cdot \\frac{\\overline{\\hat{P}_n}\n  \\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2} +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\frac{\\hat{P}_n}{\\hat{P}_r}}^2}} =\nF_D \\hat{D}_{AL+d}\\overline{\\hat{P}_{AL+d}}\\label{eq:DaldPald}\n\\end{align}\n%\n%\n\\begin{align}\nF_D &= \\frac{1}{\\sqrt{\\frac{\\sigma_n^2}{F_n^2} +\n    \\frac{\\sigma_r^2}{F_r^2}}} \\\\\n\\hat{D}_{AL+d} &= \\frac{\\hat{D}_Z}{F_D}\\cdot\\frac{\\abs{\\hat{P}_r}}{\\hat{P}_r}\\label{eq:Dald}\n\\end{align}\n%\n\\par We start with the ZOGY score image in \\Cref{eq:DzPz} and\ndemonstrate that the expression is equivalent with the score\ncalculated from a perfectly matching, decorrelated AL solution in\n\\Cref{eq:DaldPald}.  In the AL approach the role of the two images are\nnot symmetric, the template PSF is matched to the science image, and\nthe science image is left intact. Assuming that the AL optimization\nfinds the perfect matching kernel, it should be\n\\(\\hat{P}_n/\\hat{P}_r\\). Indeed, considering the score image, the\ndifference between the AL and ZOGY images are only a factor of\n\\(\\hat{P}_r/\\abs{\\hat{P}_r}\\). Compared to the AL, in the ZOGY case\nboth the difference image and its PSF carry an extra\n\\(\\hat{P}_{r}/\\abs{\\hat{P}_{r}}\\) factor that cancel from the overall\nexpression of the score image. Indeed, as\n\\(\\overline{\\hat{P}_r}\\hat{P}_r/\\abs{\\hat{P}_r}^2 = 1\\) at all\nfrequencies, we can reduce or expand this factor in the difference\nimage and its PSF terms without changing their resulting product, the\nscore image.\n%\n\\par Furthermore, note that \\(\\hat{P}_r/\\abs{\\hat{P}_r}=1\\) itself, if\n\\(\\hat{P}_r\\) is real and positive at all frequencies. This is the\ncase if \\(\\hat{P}_r\\) is a Gaussian PSF function. In this case \\(D_Z\\)\nand \\(D_{AL+d}\\) are mathematically the same as shown in\n\\Cref{eq:Dald}; expanding or reducing the fractions in frequency space\nby arbitrary real, positive kernels have the corresponding operations\nof pre-convolution and deconvolution in image space.\n%\n\\par In the decorrelated AL approach, we can also apply an arbitrary\nGaussian pre-convolution kernel without changing the difference image\nin theory. However, calculating \\Cref{eq:DalPre} in two separate\nsteps, as a difference image that is decorrelated afterwards in a\nsecond step is numerically problematic as discussed in\n\\Cref{sec:decorrab}.\n%\n\\begin{align}\n  \\hat{D}_{AL+d} =  \\hat{D}_{AL} \\cdot \\hat{K}  &= \\frac\n  {\\frac{\\hat{P}_{pre}\\hat{N}}{F_n} -\n    \\frac{\\hat{P}_n\\hat{P}_{pre}\\hat{R}}{\\hat{P}_r F_r} }\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_{pre}}^2 +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\frac{\\hat{P}_n\\hat{P}_{pre}}{\\hat{P}_r}}^2}}\n  \\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}\n  \\label{eq:DalPre}\\\\\n%\n  &= \\frac\n  {\\frac{\\hat{P}_{pre}}{F_n}\\hat{N} -\n    \\frac{\\hat{P}_{mk}}{F_r}\\hat{R} }\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}\\abs{\\hat{P}_{pre}}^2 +\n      \\frac{\\sigma_r^2}{F_r^2}\\abs{\\hat{P}_{mk}}^2}}\n  \\sqrt{\\frac{\\sigma_n^2}{F_n^2} + \\frac{\\sigma_r^2}{F_r^2}}\\label{eq:DaldPreMk}\n\\end{align}\n%\n\\section{The decorrelation afterburner\\label{sec:decorrab}}\nLet's consider the decorrelation afterburner first without the\npre-convolution kernel, when (\\(\\hat{P}_{pre}=1\\)) at all frequencies\nin \\Cref{eq:K}.\n%\n\\par Assuming a Gaussian matching kernel (\\(\\hat{P}_{mk}\\)) that\nconverges to zero towards high frequencies, the overall expression of\n\\(\\hat{K}\\) in \\Cref{eq:K} converges to \\(F_{n}/\\sigma_n\\). The\ndecorrelation correction function in frequency space is similar to\n\\(\\hat{c}_2\\) in \\Cref{fig:theo_Gaussians_ft}. In image space, its\ngraph follows a dirac delta plus a negative overshoot as in\n\\Cref{fig:theo_Gaussians_img_c2}. In the straightforward AL case, when\nwe convolve the template image, we don't expect any complication in\ncalculating such a decorrelation correction. As \\(\\sigma_r \\ll\n\\sigma_n\\), \\Cref{eq:K} can keep its convergence properties even if\n\\(\\hat{P}_{mk}\\) values are noisy in their Gaussian tails.\n%\n\\par Now let's consider the swapped image case, when we convolve the\nscience image.  The numerical stability of this case is less\ncertain. As \\(\\sigma_r \\gg \\sigma_n\\) in this case, it can prevent\n\\(\\sigma_{n}^2/F_n^2\\) from becoming the dominant term in the\ndenominator of \\Cref{eq:K} and the numerical noise in the tails of\n\\(\\hat{P}_{mk}\\) may remain in the high frequency values \\(\\hat{K}\\).\n%\n\\par Let's assume now a Gaussian pre-convolution kernel. It can be\nseen that the overall expression of \\(\\hat{K}\\) becomes divergent in\n\\Cref{eq:K} towards high frequencies. The denominator converges to\nzero. Even if we don't directly hit numerical overflows in calculating\n\\(\\hat{K}\\), a divergent \\(\\hat{K}\\) cannot be meaningfully\napplied. The difference image converges to zero (\\(\\hat{D}_{AL}\\),\n\\Cref{eq:Dal}), so correcting the already computed difference image is\nsimilar to inverting a multiplication operation of smaller and smaller\nnumbers. In \\Cref{eq:DaldPreMk}, we can see that calculating the\ncorrected difference image (\\(\\hat{D}_{AL+d}\\)) is exactly the same\nproblem as calculating the ZOGY difference image in \\Cref{eq:Dhat}. In\nthese expressions, both the numerators and the denominators converge to\nzero which in practice result in numerical noise in the tail regions\nof the input Gaussians (image PSFs, pre-convolution and matching\nkernels). We face the very same numerical problems that was discussed\nin \\Cref{sec:ZOGYFFT}.\n% \n\\subsection{Decorrelation afterburner with pre-convolution\\label{sec:decorr_preconv}}\n%\n\\par We saw that the decorrelation afterburner of \\Cref{eq:K} is\nproblematic if we use a pre-convolution kernel. In this form the\ndecorrelation afterburner wants to recover the proper difference\nimage, inverting the pre-convolution operation completely.\n%\n\\par Recall that pre-convolution is a practical way to ensure that the\nscience image PSF is wider than our template PSF. We also know that if\nwe choose to correlate an image with its own\nPSF\\footnote{Pre-convolution with the flipped PSF in image space;\n  multiplication with complex conjugate in frequency space (e.g.\\\n  \\Cref{eq:Shat}).}, under the independent Gaussian noise model\nassumptions, we get a detection likelihood image.\n%\n\\par We show here that we can apply a form of the decorrelation\nafterburner in the pre-convolution case if we pre-convolve the science\nimage with its own PSF. This form of the decorrelation afterburner\ndoes not invert the pre-convolution operation, in this sense it does\nnot do noise decorrelation any more. Rather it corrects the\npre-convoled and AL PSF matched likelhood difference image directly\nand results in the equivalent of the zogy score image as an optimal\ndetection statistics in the case when both the science and template\nimages have noise.\n%\nWe can rewrite \\Cref{eq:S}:\n\\begin{align}\n  \\hat{S} &= \n            \\frac{\\overline{\\hat{P}_n} \\frac{\\hat{N}}{F_n} -\n            \\frac{\\abs{\\hat{P}_n}^2}{\\hat{P}_r} \\frac{\\hat{R}}{F_r} }\n            % denom\n            { \\frac{\\sigma_n^2}{F_n^2} +\n            \\frac{\\sigma_r^2}{F_r^2}\n            \\frac{\\frac{\\abs{\\hat{P_n}}^2}{\\hat{P}_r}}\n            {\\overline{\\hat{P}_r}}         \n            } =\n            \\frac{\\overline{\\hat{P}_n} \\frac{\\hat{N}}{F_n} -\n            \\frac{\\abs{\\hat{P}_n}^2}{\\hat{P}_r} \\frac{\\hat{R}}{F_r} }\n            % denom\n            { \\frac{\\sigma_n^2}{F_n^2} +\n            \\frac{\\sigma_r^2}{F_r^2}\n            \\frac{\\abs{\\hat{P}_{mk}}^2}{\\abs{\\hat{P}_{n}}^2}\n            } = \n            % two terms\n            \\underbrace{\\left(\n            \\overline{\\hat{P}_n} \\frac{\\hat{N}}{F_n} -\n            \\frac{\\abs{\\hat{P}_n}^2}{\\hat{P}_r} \\frac{\\hat{R}}{F_r}\n            \\right)}_{\\textrm{pre-convolved AL}} \\cdot\n            % denom\n            \\frac{1}\n            { \\frac{\\sigma_n^2}{F_n^2} +\n            \\frac{\\sigma_r^2}{F_r^2}\n            \\frac{\\abs{\\hat{P}_{mk}}^2}{\\abs{\\hat{P}_{n}}^2}\n            }\n            \\label{eq:SPre}\\\\\n  \\hat{P}_{mk} &= \\frac{\\abs{\\hat{P_n}}^2}{\\hat{P}_r} \\label{eq:Smk}\\\\\n  \\hat{S} &= \\hat{c}_{sn} \\hat{N} - \\hat{c}_{sr}\\hat{R} =\n            \\frac{\\frac{\\overline{\\hat{P}_n}}{ F_n} }\n            % denom\n            { \\frac{\\sigma_n^2}{F_n^2} +\n            \\frac{\\sigma_r^2}{F_r^2}\n            \\frac{\\abs{\\hat{P}_{mk}}^2}{\\abs{\\hat{P}_{n}}^2}\n            } \\hat{N}\n            -\n            \\frac{\n            \\frac{\\abs{\\hat{P}_n}^2}{\\hat{P}_rF_r} }\n            % denom\n            { \\frac{\\sigma_n^2}{F_n^2} +\n            \\frac{\\sigma_r^2}{F_r^2}\n            \\frac{\\abs{\\hat{P}_{mk}}^2}{\\abs{\\hat{P}_{n}}^2}\n            } \\hat{R}\\label{eq:Scncr}\n\\end{align}\n%\n\\par In \\Cref{eq:SPre}, the first term in the numerator is the PSF\npre-convolved science image that now has a PSF of\n\\(\\abs{\\hat{P}_n}^2\\), and the theoretical PSF matching kernel is\nwritten in \\Cref{eq:Smk}. We use the matching kernel to express the\ncorrection in \\Cref{eq:SPre} on the right side. Compared to the\noriginal decorrelation afterburner expression, the correction is\nsquared and the correction with the matching kernel is deconvolved\nwith the pre-convolution kernel.\n%\n\\par Let's consider the convergence properties towards high\nfrequencies in case of Gaussian PSFs. The numerator of this expression\nalways goes to zero while the denominator never goes to zero,\nirrespectively of the widths of \\(\\hat{P}_{mk}\\) and\n\\(\\hat{P}_{n}\\). As such, \\(\\hat{S}\\) always goes to zero.\n%\n\\par If we use pre-convolution to avoid the AL deconvolution case, it\nis guaranteed that the matching kernel solution will be narrower in\nimage space than the PSF of the science image. In frequency space, the\nrelation is the opposite, and the denominator of \\Cref{eq:SPre} should\nactually diverge, making the overall zero convergence faster.\n%\n\\par Note that the zero convergence property of \\(\\hat{S}\\) is kept\neven if the convergence properties are numerically lost in the second\nterm of the denominator at high frequencies. Therefore we do not\nexpect \\emph{worse} high frequency noise to appear in our ``afterburned''\nlikelihood/score image result than it would be in a simple frequency\nspace PSF convolution operation.\n%\n\\par We emphasize that while we can apply this correction on the\nalready calculated pre-convolved AL likelihood difference image, we\ncannot do it on its variance plane. Because the noise in the score\nimage is not white, we cannot easily estimate the noise level even in\nthe homoscedastic noise model case. Instead, we need to follow the\nconsiderations of \\Cref{sec:varplane} for the variance plane\ncalculation and express \\(\\hat{S}\\) with the overall coefficients of\n\\(\\hat{N}\\) and \\(\\hat{R}\\) as shown in \\Cref{eq:Scncr}. Recall, we\ntransform \\(\\hat{c}_{sn}\\) and \\(\\hat{c}_{sr}\\) back to image space,\nsquare them in image space, and convolve the original images' variance\nplanes with these squared matching kernels (\\Cref{eq:VarD}). In the\nhomoscedastic approximation, we multiply \\(\\sigma_n^2\\) and\n\\(\\sigma_r^2\\) with the sum of squares (\\Cref{eq:sigmaD}), but we\nstill need to calculate \\(c_{sn}\\) and \\(c_{sr}\\). In this\napproximation, the inverse FFT of \\(\\hat{c}_{sn}\\) and\n\\(\\hat{c}_{sr}\\) can be spared and the sum can be calculated directly\nin frequency space (Parseval theorem, \\Cref{sec:parseval}).\n%\n\\subsection{Decorrelation afterburner normalization}\n\\par The classic AL method can be applied to images without\nconsidering their photometric scaling factors (\\(F_n, F_r\\)). In this\ncase, the AL optimisation itself solves for the ratio of the\nphotometric scaling between the images. This scaling appears as the\nsum of the AL matching kernel. So far, we've assumed that our AL\nmatching kernels are normalized like image PSFs. Let's relax this\nassumption and separate the sum of the pre-convolution and matching\nkernels into standalone factors \\(S_{pre}\\), \\(S_{mk}\\). To preserve\nthe photometric flux, the decorrelation afterburner correction should\nstill be overall a convolution with a normalized correction kernel in\nimage space.\n%\n\\par Image space sum normalization can be easily ensured in the\ncorresponding frequency space expression. If we evaluate any\nconvolution kernel at 0 frequency, based on \\Cref{eq:X0sum} they\nshould be equal to 1. We should include \\(S_{pre}\\), \\(S_{mk}\\) in the\nnumerator scaling factor to satisfy the normalization criterion. The\nnormalized decorrelation afterburner can be written as \\Cref{eq:KPre}.\n%\n\\begin{align}\n  \\hat{K} &= \\frac{\\sqrt{\\frac{\\sigma_n^2}{F_n^2}S_{pre}^2 + \\frac{\\sigma_r^2}{F_r^2}S_{mk}^2}}\n  {\\sqrt{\\frac{\\sigma_n^2}{F_n^2}S_{pre}^2\\abs{\\hat{P}_{pre}}^2 + \\frac{\\sigma_r^2}{F_r^2}S_{mk}^2\n  \\abs{\\hat{P}_{mk}}^2}}\n\\label{eq:KPre}\n\\end{align}\n%\n\\par Similarly, should the PSFs be not normalized to sum 1 in the ZOGY\nimage differencing, the sum of the PSFs should appear in \\(F_{D}\\) in\nthe same way as a scaling factor.\n%\n\\subsection{A possible fusion of AL and ZOGY}\nTo keep the advantage of AL of not assuming a prior knowledge of the\nimage PSFs and of ZOGY to produce a proper difference image, we\npropose the following algorithmic fusion of the two approaches.\n%\n\\par Let's choose a Gaussian pre-convolution kernel (\\(P_{pre}\\)), so\nthat the AL algorithm can determine an accurate \\(P_{mk}\\) reliably in\nimage space; perhaps in a spatially varying manner for the whole\nimage. The optimisation of the pre-convolution kernel can focus solely\non the quality of the AL matching kernel solution. The expected\ntradeoff here is that the wider the pre-convolution kernel, the easier\nto find a Gaussian matching kernel but on the other hand, a wider\npre-convolution kernel means more noise correlation and a less accurate\nminimisation in the AL algorithm. We do not need to calculate the\nclassic AL difference image in its original \\Cref{eq:Dal} form here.\n%\n\\par In the next step, using \\Cref{eq:DaldPreMk}, we perform a ZOGY\ndifference image calculation using the \\(\\hat{P}_{pre}\\) and\n\\(\\hat{P}_{mk}\\) solutions from the previous step. They behave like\nthe ``image PSFs'' in the original zogy calculations. We should also\napply all the precautions and numerical considerations discussed\nearlier. As \\(\\hat{P}_{pre}\\) is positive and real, it should\ndisappear completely from the proper difference image and score image\nvalues. We note however, that the wider is \\({P}_{pre}\\) in image\nspace, the narrower \\(\\hat{P}_{pre}\\) becomes in frequency\nspace. While multiplication with a Gaussian functions is fully\ninvertible theoretically, numerically such a multiplication will\nsuppress high frequency values and indirectly throws away high\nfrequency (spatial) information from the score image. This is\ndifferent from the tails (and zero points) of the image PSFs. At the\nPSF zero points the images do not carry any information, while with\nthe pre-convolution, we throw away information from the data. Ad\nabsurdum, imagine that we keep only the 0th frequency in frequency\nspace. It'd correspond to a pre-convolution kernel of uniform values\nin image space. We'd average out our whole images and would get one\nuniform detection score for all pixels.\n%\n\\section{Conclusions}\n%\n\\par We studied the ZOGY difference image matching kernels for Gaussian\ninput PSFs in this document. In the theoretical calculations\n(\\Cref{sec:ZOGYtheo}), we showed that the matching kernels have different\nconvergence values in their tails depending whether they belong to the\nnarrower of wider PSF input image. In practice, using FFT, these convergence\nproperties are not well reproduced and the resulting image space matching\nkernels have oscillating patterns all over the image\n(\\Cref{sec:ZOGYFFT}). We concluded that this noise is still acceptable if\nthe input images follow their PSF models and suppress high frequencies,\nhowever noise patterns appear in the difference image if the PSFs\ndeviate. This noise is extended, visually unappealing, and can disrupt other\nalgorithms' performance on the difference image; however, it has little\nimpact on the source detection statistic.\n%\n\\par We tested the direct Gaussian PSF generation in frequency space as a\npossible way to avoid the convergence problems in our calculations. We\nexpect that it would produce difference images without large scale patterns\nfor all inputs. It is a strong restriction on the PSFs, so we also plan to\nlook for weaker constraints in suppressing the artifacts in the difference\nimage. We also need to consider sampling (aliasing) details before\nimplementation.\n%\n\\par In \\Cref{sec:varplane} we discussed how to properly calculate the variance\nplane in frequency space when we have noise whitening decorrelation\noperations.\n%\n\\par In \\Cref{sec:ALZOGYequiv}, we demonstrated that the AL method combined with\nthe decorrelation afterburner leads to the same detection statistic as the\nZOGY method. With preconvolution, they can theoretically lead to the very\nsame difference image. We believe though that his approach would meet\nsimilar practical problems as the ZOGY subtraction has. This is a possible\nfuture topic to study.\n%\n\\par In \\Cref{sec:appendix} we discuss various considerations that have\nrelevance in the actual and for future frequency space image differencing\ncode implementations.\n%\n\\par Finally, the noisy matching kernels cause complications in\nimplementing solutions in frequency space for spatial variations of the PSF\nin a large image. This is also a topic we plan to study in the future.\n\n", "meta": {"hexsha": "5a8f0757b7963d6e9de838f2bc81c9f5ef94b97e", "size": 43595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "zogy_main.tex", "max_stars_repo_name": "lsst-dm/dmtn-179", "max_stars_repo_head_hexsha": "bf38556421c558aebf91f190ffae5193a5688767", "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": "zogy_main.tex", "max_issues_repo_name": "lsst-dm/dmtn-179", "max_issues_repo_head_hexsha": "bf38556421c558aebf91f190ffae5193a5688767", "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": "zogy_main.tex", "max_forks_repo_name": "lsst-dm/dmtn-179", "max_forks_repo_head_hexsha": "bf38556421c558aebf91f190ffae5193a5688767", "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.5397727273, "max_line_length": 99, "alphanum_fraction": 0.7471728409, "num_tokens": 12552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6467556276775017}}
{"text": "\\lab{Facial Recognition Using Eigenfaces}{Facial Recognition Using Eigenfaces}\n\\label{lab:FacialRecognition}\n\n\\objective{Use the singular value decomposition to implement a simple facial recognition system.}\n\nSuppose we have a large database containing images of human faces.\nWe would like to identify people by comparing their pictures to those in the database.\nThis task is called \\emph{facial recognition}.\n\nOne way to automate the comparison process is know as the \\emph{eigenfaces} method.\nAs the name suggests, this method uses eigenvectors of matrices related to the collection of face images.\nThe method essentially projects face images to a low-dimensional subspace, in a way that preserves their distinguishing characteristics.\nComparing the images in fewer dimensions is faster and allows us to store the images using less data.\n\nThe idea of projecting to fewer dimensions is not unique to the eigenfaces method.\nThis method is an example of \\emph{principal component analysis}, where data is compared based on its principal components in a lower-dimensional vector space.\nPrincipal component analysis can be applied to many computing problems besides facial recognition.\n% TODO: list 2-3 other applications\n\n\\begin{comment}\nFacial recognition is important in law enforcement, as well as other situations.\nFor example, facial recognition can be combined with video surveillance to identify when a person is not authorized to be in a location.\n\nHumans can easily compare two face images and determine whether they belong to the same person, but automating this process is more challenging.\nOne technique for automated facial recognition uses \\emph{eigenfaces}.\n\\end{comment}\n\n\\section*{Load the Data} % ====================================================\n\\begin{comment}\nEigenfaces are an efficient way to store and query a database of face images.\nAs the name suggests, this method uses eigenvectors of matrices related to the collection of face images.\nEssentially, the method of eigenfaces projects face images to a lower-dimensional subspace in a way that preserves their distinguishing characteristics.\nIn the lower-dimensional subspace, comparing face images is much faster.\n\\end{comment}\n\nThe first step is to obtain a dataset of face images.\nRecall that a digital image may be stored as an $m \\times n$ array of pixels.\nIn this lab, we will store the images as $mn$-vectors by concatenating the rows of the $m \\times n$ arrays.\n\n\\begin{problem}\n\\label{prob:getTrainingFaces}\nIn this lab we will use the \\li{faces94} face image dataset found at \\url{http://cswww.essex.ac.uk/mv/allfaces/faces94.html}\nThis problem will make sure that you can load and display the images from the dataset.\n\\begin{enumerate}\n\\item Download the \\li{faces94} dataset from the link above and extract the files.\nYou should now have a directory named ``faces94\" which contains photographs of 153 people, organized into folders by person.\n\n\\item The function \\li{getFaces()} is given in the appendix. %or spec file?\nIt constructs a set of face images by selecting exactly one face image for each person in the directory.\nIt should return an array whose columns are flattened face images.\nFeel free to modify the given code.\nYou may have to replace the parameter \\li{\\\"./faces94\\\"} with the location of the directory \\li{faces94} on your machine.\n\nTest this function to make sure it runs without errors.\nCheck that the return value \\li{F} is a $36000 \\times 153$ array.\nThe columns of this array are 153 flattened face images of 153 different people.\n\n\\item Use \\li{plt.imshow()} to display one of the faces.\nThe original image dimensions are $200 \\times 180$.\nYou may find it useful to write a helper function that accepts a flattened image and displays it.\n\n\\end{enumerate}\n\\end{problem}\n\n\n\\section*{Shift By the Mean} % ================================================\n\nThe facial recognition algorithm is more robust if we first \\emph{shift by the mean}. When we shift a set of data by the mean, the distinguishing features are exaggerated. Therefore, in the context of facial recognition, shifting by the mean accentuates the unique features of the face.\nSuppose we have a collection of $k$ face images represented as vectors $\\f_1, \\f_2, \\ldots, \\f_k$ of length $mn$.\nDefine the \\emph{mean face} ${\\boldsymbol \\mu}$ to be the average of the $\\f_i$:\n\\[\n{\\boldsymbol \\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\\begin{problem}\n\\label{prob:meanFace}\n\\leavevmode\n\nThe facial recognition method you will write in this lab will be structured as a class.\nAn outline of the \\li{FacialRec} class is provided in the appendix. %or maybe in the spec file?\nYou will write the methods of the class.\n\nWhen initialized, the \\li{FacialRec} object first loads the face images using \\li{getFaces} and stores the result.\nThe next step is to compute the mean face.\n\\begin{enumerate}\n\\item In your class definition, implement the method \\li{FacialRec.initMeanImage()}.\nCompute the mean face and store it as \\li{self.mu}.\nThis can be done in one line of code using NumPy.\n\n\\item Display the mean face.\nYour result should match Figure \\ref{facialRecognition:meanFace}.\n\\end{enumerate}\n\\end{problem}\n\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 - {\\boldsymbol \\mu}$.\nThe mean-shifted face vector $\\bar{\\f}_i$ is the deviation of the $i$-th face from the mean, and thus captures the unique features of the face.\nNow form the $mn \\times k$ matrix $\\bar{F}$ whose columns are given by the mean-shifted face vectors, i.e.\n\\[\n\\bar{F} = \\begin{bmatrix}\n\\bar{\\f}_1 & \\bar{\\f}_2 & \\cdots & \\bar{\\f}_k\n\\end{bmatrix}.\n\\]\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item In your class definition, implement the method \\li{FacialRec.initDifferences()}.\nCompute $\\bar{F}$ and store it as \\li{self.Fbar}.\nThis can be done in one line using array broadcasting.\n\\item\nDisplay one of the mean-shifted faces.\nThe output should be similar to the faces in Figure \\ref{facialRecognition:differenceFaces}.\n\\end{enumerate}\n\\end{problem}\n\n\n\\section*{Project to a Subspace} % ============================================\n\nNow suppose we are given a new face vector $\\g$.\nWe first shift $\\g$ by the mean of the dataset, giving us $\\bar{\\g} = \\g - {\\boldsymbol \\mu}$.\nThe closest match to $\\bar{\\g}$ is the vector $\\bar{\\f}_i$ that minimizes $\\|\\bar{\\g}-\\bar{\\f}_i\\|_2$.\nIf there are $k$ images in the dataset, we find this match by comparing $\\bar{\\g}$ to every element of $\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$.\n\nHowever, comparing the original face images pixel by pixel is computationally expensive and inefficient.\nThe vectors $\\bar{\\f}_i$ and $\\bar{\\g}$ are length $mn$, which in our case equals 36000 and in practice may be many times larger.\nComputing the difference between face vectors of this length is time consuming, especially when the dataset is very large.\nIt also requires us to use $mn$ values to store each face, which is an inefficient use of space.\nIn addition, pixel by pixel comparison is not very robust to small changes in individual pixels.\n\nInstead, in order to store and compare our face vectors, we would like to represent each one with fewer than $mn$ values.\nWe can do this by projecting to a subspace.\nMathematically, we want to choose $s$, $s \\ll mn$, and project the face vectors to an $s$-dimensional subspace of the original $mn$-dimensional space of images.\nWe can then use just $s$ values to store each face in terms of the basis vectors of the new subspace.\n\nThe ``best\" subspace to project to is the one that is closest in the least squares sense (i.e., such that the sum of the squared errors between $\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$ and their projections is minimized).\nLet $U \\Sigma V^T$ be an SVD of $\\bar{F}$, with $\\u_i$ the columns of $U$.\nAs we will prove below, the $s$-dimensional subspace that minimizes the squared error is the span of $\\u_1, \\ldots, \\u_s$.\nNote that $\\u_1, \\ldots, \\u_s$ is an orthonormal basis for this subspace.\n\nThe projection matrix is $P_s = U_s U_s^T$ where $U_s = [ \\u_1\\; \\ldots \\; \\u_s]$.\n%The matrix for the projection is $P_s = U_s U_s^T$ where $U_s$ is the first $s$ columns of $U$.\nThis matrix projects the original face vectors into the optimal $s$-dimensional subspace.\n\n\\begin{comment} % OLD VERSION\n\\section*{Project to a Subspace} % ============================================\nNow suppose we have a new face vector $\\g$.\nThe closest face image to $\\g$ should be the vector $\\bar{\\f}_i$ that minimizes $\\|\\bar{\\g}-\\bar{\\f}_i\\|_2$, where $\\bar{\\g} = \\g - {\\boldsymbol \\mu}$.\nUnfortunately, computing $\\|\\bar{\\g}-\\bar{\\f}_i\\|_2$ for each $i$ is computationally intractable when the length $mn$ of the vectors is large.\nSince a low-resolution photo may easily have $100\\times 100 = 10,000$ pixels, in practice $mn$ is very large indeed.\n\nHere is the trick: instead of computing in the $mn$-dimensional space of all possible images, we will compute in a lower-dimensional subspace.\nWe could start by using the subspace spanned by the vectors $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$, which is at most $k$-dimensional.\nUnfortunately, in practice $k$ is still too large for this subspace to be computationally efficient.\n%We need to project our problem into some subspace of the span of $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$.\n\nTherefore, we want to project to a subspace of $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$ in a way that retains as much information about the $\\bar{\\f_i}$ as possible.\nMathematically, we want to find the $s$-dimensional subspace of $\\text{span}\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$ that is closest to the $\\bar{\\f_i}$ in the least-squares sense.\nIn a minute, we will prove that the SVD of $\\bar{F}$ (whose columns are $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$) solves this problem.\nBut first, let us summarize how the solution works.\n\nLet $U \\Sigma V^T$ be an SVD of $\\bar{F}$ with $\\u_i$ the columns of $U$.\nThen the ``best'' $s$-dimensional subspace for approximating $\\text{span}\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$ is the span of $\\u_1, \\ldots, \\u_s$.\nThe matrix for this projection is $P_s = U_s U_s^T$ where $U_s = [ \\u_1\\; \\ldots \\; \\u_s]$.\n\nBecause the vectors $\\u_i$ are eigenvectors of $\\bar{F}\\bar{F}^T$, we call them \\emph{eigenfaces}.\nTherefore, the best $s$-dimensional subspace for solving the facial recognition problem is exactly the span of the first $s$ eigenfaces.\n\\end{comment}\n\n\\subsection*{The Proof: SVD as a Least Squares Solution} % --------------------\n\\begin{theorem}\nLet $\\f_1, \\ldots, \\f_k$ be vectors on $\\mathbb{R}^{mn}$, and let $\\bar{F} = [\\bar{f}_1 \\; \\ldots \\; \\bar{f}_k]$. Suppose $U\\Sigma V^T$ is an SVD for $\\bar{F}$. Then the $s$-dimensional subspace that solves the least squares problem for $\\f_1, \\ldots, \\f_k$ is the span of the first $s$ columns of $U$. If $U_s$ is the first $s$ columns of $U$, then the matrix $U_sU_s^T$ is the projection onto this subspace.\n\\end{theorem}\n\\begin{proof}\nWe seek a rank-$s$ projection matrix $P_s$ so that $\\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2$ is minimized---i.e.,\n the sum of the squares of the ``errors'' is minimal when we project $\\bar{\\f}_i$ via $P_s$.\n But minimizing this quantity is the same as minimizing its square, which happens to equal the Frobenius norm of $P_s\\bar{F} - \\bar{F}$.\nWritten mathematically,\n \\begin{align*}\n\\inf_{\\text{rank}(P_s)=s} \\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2 &=  \\inf_{\\text{rank}(P_s)=s} \\left( \\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2 \\right) ^2\\\\\n & =  \\inf_{\\text{rank}(P_s)=s} \\| P_s\\bar{F}-\\bar{F}\\|_F.\n \\end{align*}\n\nNow let $U \\Sigma V^T$ be an SVD of $\\bar{F}$ with $\\u_i$ the columns of $U$, $\\v_i$ the columns of $V$, and $\\sigma_i$ the singular values of $\\bar{F}$.\nIf $P_s = \\sum_{i=1}^s \\u_i \\u_i^T$, then\n\\begin{align*}\nP_s\\bar{F} &=  \\left( \\sum_{i=1}^s \\u_i \\u_i^T \\right)\\left(  \\sum_{j=1}^k \\sigma_j \\u_i \\v_i^T \\right)\n= \\sum_{i=1}^s\\sum_{j=1}^k \\sigma_j \\u_i\\u_i^T\\u_j\\v_j^T\\\\\n&=  \\sum_{i=1}^s\\sum_{j=1}^k \\sigma_j \\u_i\\delta_{ij}\\v_j^T\n= \\sum_{i=1}^s \\sigma_i \\u_i\\v_i^T.\n\\end{align*}\n\nIn fact, the Schmidt-Eckart-Young-Mirsky Theorem from Lab \\ref{lab:SVD} tells us that $X = \\sum_{i=1}^s \\sigma_i \\u_i\\v_i^T$ is exactly the rank-$s$ matrix that minimizes $\\|X - \\bar{F}\\|_F$.\nSince $P_s \\bar{F}$ will always have rank $s$ or less, the projection $P_s =  \\sum_{i=1}^s \\u_i \\u_i^T$ is the one we seek.\nIf we let $U_s = [ \\u_1\\; \\ldots \\; \\u_s]$, then we may write $P_s = U_sU_s^T$. Notice that $P_s$ is projection onto the subspace spanned by the columns of $U_s$.\n\\end{proof}\n\nThe $s$ basis vectors $\\u_1, \\ldots, \\u_s$ are eigenvectors of $\\bar{F}\\bar{F}^T$.\nThey also resemble face images.\nHence, they are commonly called the ``eigenfaces.\"\n\n\\begin{problem}\n\\label{prob:svd}\n\\leavevmode\n\\begin{enumerate}\n\\item In your class definition, implement the method \\li{FacialRec.initEigenfaces()}.\n\nCompute the SVD (\\li{scipy.linalg.svd()} is a good implementation to use) and store the array \\li{U} containing the eigenfaces as its columns.\nBecause we will only use the first few columns of \\li{U}, specify the keyword parameter \\li{full_matrices=False} to compute only the compact SVD.\n\\item Plot the first eigenface (i.e. the first column of \\li{U}).\nIt should resemble the first eigenface shown in Figure \\ref{facialRecognition:eigenfaces}.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Change Basis} % =====================================================\n\nThe projection matrix $P_s = U_s U_s^T$ projects a face vector into the $s$-dimensional subspace spanned by the eigenfaces, but still keeps it as a vector in $\\mathbb{R}^{mn}$.\nThe change-of-basis matrix $U_s^T$ both projects the face vector and and changes the basis.\nThe resulting vector has length $s$ and represents the face in terms of eigenfaces.\n\nTo represent any face vector in terms of the first $s$ eigenfaces, multiply by $U_s^T$.\nTo change back to a full length-$mn$ projection, multiply again by $U_s$.\n\n\\begin{comment}\nIt does us no good to project all our vectors into an $s$-dimensional space if we still store them as vectors in $\\mathbb{R}^{nm}$.\nInstead, we must store our face vectors in terms of the columns of $U_s$.\nThis way, each vector is a length-$s$ array in NumPy, instead of a length-$mn$ array.\n\nThe change-of-basis matrix is $U_s^T$, so $U_s^TP_s = U_s^TU_sU_s^T = U_s^T$.\nThus we can project into the subspace and change basis by multiplying by $U_s^T$.\nTo change back to the full $mn$-vector, multiply by $U_s$.\n\\end{comment}\n\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\n\\begin{problem}\n\\label{prob:top_n}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement the method  \\li{FacialRec.project()} in your class definition.\nThis should accept a flattened image or an array with flattened images as its columns.\nIt should also accept a value for $s$.\nThe function should project the image or images into the appropriate $s$-dimensional subspace and change basis, then return the result.\n\\item Let \\li{face} be the first mean-shifted face (the first column of \\li{facialRec.Fbar}). Do the following:\n\\begin{enumerate}\n\\item Project \\li{face} so that it is represented in terms of the first 19 eigenfaces.\n\\item Change basis again back to the standard basis on $\\mathbb{R}^{mn}$.\n\\item Add back the mean face \\li{facialRec.mu}.\n\\item Plot the resulting image.\n\\end{enumerate}\nYour image should match Figure \\ref{fig:75_efaces}.\n\\end{enumerate}\n\\end{problem}\n\n\n\\begin{figure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltThirtySecond.png}\n    \\caption{5 eigenfaces, about 1/32 of the total.}\n    \\label{fig:5_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltSixteenth.png}\n    \\caption{9 eigenfaces, or 1/16 of the total.}\n    \\label{fig:9_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltEighth.png}\n    \\caption{19 eigenfaces, about 1/8 of the total.}\n    \\label{fig:19_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltFourth.png}\n    \\caption{38 eigenfaces, about 1/4 of the total.}\n    \\label{fig:38_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltHalf.png}\n    \\caption{75 eigenfaces, about 1/2 of the total.}\n    \\label{fig:75_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{rebuiltAll.png}\n    \\caption{All 153 of the eigenfaces.}\n    \\label{fig:all_efaces}\n\\end{subfigure}\n\\caption{Image rebuilt with various numbers of eigenfaces. The image is somewhat recognizable when it is reconstructed with only 1/8 of the eigenfaces.}\n\\label{fig:rebuiltImage}\n\\end{figure}\n\n\\begin{comment}\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\\end{comment}\n\n\\section*{Match Faces} % ======================================================\n\nFinally, we are ready to identify which mean-shifted image $\\bar{\\f}_i$ is closest to an input image, $\\bar{\\g}$.\nWe begin by projecting all vectors to some $s$-dimensional subspace and writing them in terms of the basis vectors, which are the eigenfaces.\nThis is done by multiplying by the change-of-basis matrix:\n\\[\n\\widehat{\\f}_i = U_s^T(\\f_i-{\\boldsymbol \\mu}) \\qquad \\widehat{\\g} = U_s^T(\\g-{\\boldsymbol \\mu}).\n\\]\n\nNext, we compute which $\\widehat{\\f}_i$ is closest to $\\widehat{\\g}$.\nSince the columns of $U_s$ are an orthonormal basis, we get the same result doing the computation in this basis as we would in the standard Euclidean basis.\nDefine\n\\[\ni^* = \\text{argmin}_i \\|\\widehat{\\f}_i - \\widehat{\\g}\\|_2.\n\\]\nThen the $i^*$-th face image is the best match for $\\g$.\n\n\\begin{problem}\n\\label{prob:nearest}\n\\leavevmode\n\\begin{enumerate}\n\\item\nImplement the method \\li{FacialRec.findNearest()} as follows.\n\\begin{lstlisting}\ndef findNearest(self, image, s=38):\n    Fhat = # Project Fbar, producing a matrix whose columns are the f-hat defined above\n    ghat = # Shift 'image' by the mean and project, producing g-hat as defined above\n    # for both Fhat and ghat, use your project function from the previous problem\n\n    # Return the index that minimizes ||fhat_i - ghat||_2.\n\\end{lstlisting}\nThe functions \\li{np.linalg.norm()} and \\li{np.argmin()} will be useful for the last line. When using \\li{np.linalg.norm}, make sure you indicate the correct axis.\n\n\\item Test your facial recognition system on faces selected randomly from the \\li{faces94} dataset.\nThe function \\li{sampleFaces(n_tests, path)} at the end of this lab will build an array of \\li{n_tests} random faces from the \\li{faces94} dataset.\n\nPlot the random face beside the face returned by your facial recognition code to see if your system is accurately recognizing faces.\n%The function \\li{show2()} at the end of this lab will plot two face vectors side-by-side.\n\n\\end{enumerate}\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 dataset, and then add this new face.\nWe can also make the system more robust by including multiple pictures of the same face with different expressions and lighting conditions.\n\nAlthough there are other approaches to facial recognition that utilize more complex techniques, the method of eigenfaces remains\na wonderfully simple and effective solution, illustrating another application of the singular value decomposition.\n\n\\section*{Appendix: Helper Code} % ============================================\n\nThis section contains some functions to help you implement the facial recognition class outlined in the problems of this lab.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import linalg as la\nfrom os import walk\nfrom scipy.ndimage import imread\nfrom matplotlib import pyplot as plt\nfrom random import sample\n\ndef getFaces(path=\"./faces94\"):\n    \"\"\"Traverse the directory specified by 'path' and return an array containing\n    one column vector per subdirectory.\n\n    For the faces94 dataset, this gives an array with just one column for each\n    face in the dataset. Each column corresponds to a flattened grayscale image.\n    \"\"\"\n\n    # Traverse the directory and get one image per subdirectory.\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\n    # put all the face vectors column-wise into a matrix.\n    F = np.array(faces).T\n    return F\n\n\ndef sampleFaces(n_tests,path = \"./faces94\")\n    \"\"\"Return an array containing a sample of n_tests images contained\n    in the path as flattened images in the columns of the output.\n    \"\"\"\n    files = []\n    for (dirpath, dirnames, filenames) in walk(path):\n        for f in filenames:\n            if f[-3:]==\"jpg\": # only get jpg images\n            files.append(dirpath+\"/\"+f)\n\n    #Get a sample of the images\n    test_files = sample(files, n_tests)\n    #Flatten and average the pixel values\n    images = np.array([imread(f).mean(axis=2).ravel() for f in test_files]).T\n    return images\n\n\\end{lstlisting}\n\nThe following is the outline of the Facial Recognition class.\n\n\\begin{lstlisting}\nclass FacialRec:\n    ##########Members##########\n    #   F, mu, Fbar, and U\n    ###########################\n    def __init__(self,path):\n        self.initFaces(path)\n        self.initMeanImage()\n        self.initDifferences()\n        self.initEigenfaces()\n\n    def initFaces(self, path):\n        self.F = getFaces(path)\n    def initMeanImage(self):\n        pass\n    def initDifferences(self):\n        pass\n    def initEigenfaces(self):\n        pass\n    def project(self, A, s=38):\n        pass\n    def findNearest(self, image, s=38):\n        pass\n\\end{lstlisting}\n", "meta": {"hexsha": "b4419233724dbd2aaf3dc042452df7a2b34945ac", "size": 23294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1A/FacialRecognition/FacialRecognition.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/FacialRecognition/FacialRecognition.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/FacialRecognition/FacialRecognition.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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.8602620087, "max_line_length": 409, "alphanum_fraction": 0.7200137374, "num_tokens": 6491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.6467556202081012}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{showlabels}\n\\title{Statistical Computing for Scientists and Engineers\\\\[1em] Homework 1}\n\\author{Jiale Shi}\n\\date{September/11/2018}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\\section{Problem 1}\nConsider $n$ samples $D_{n} = (x_{1},...,x_{n})$, independently drawn from normal distribution, $N_{\\mu, \\sigma^{2}})$, with known variance and unknown mean, $\\sigma^{2}$ and $\\mu$, respectively. Assume that the mean has a prior given by the normal distribution:\n\n\\begin{equation}\np(\\mu|m,v^{2})= N(\\mu|m,v^{2}) \\propto \\exp(\\frac{1}{2v^{2}} (\\mu-m)^2)\n%\\pdv[2]{u}{x}+\\pdv[2]{u}{y} = 0\n\\end{equation}\n\nDerive the posterior:\n\n\\begin{equation}\np(\\mu|D) \\sim N(\\mu_{n},\\sigma^{2}) \n\\end{equation}\n\n\\begin{equation}\n\\mu_{n} = \\sigma^{2}\\left(\\frac{m}{v^{2}}+\\frac{n\\Bar{x}}{\\sigma^{2}}\\right), \\sigma_{n}^{2} = \\frac{1}{\\frac{n\\Bar{x}}{\\sigma^{2}}+\\frac{1}{v^2}}\n\\end{equation}\n\nin which $\\Bar{x}$ is the empirical mean $(\\Bar{x}=\\sum^n_{i=1}x_{i})$.\n\nAnswer:\n\\begin{equation}\n\\begin{aligned}\n    p(\\mu|D) &= \\prod_{i=1}^{n} f(x_{i}|\\mu) p(\\mu) \\\\\n    &\\propto \\exp{-\\frac{\\sum_{i=1}^{n}(x_{i}-\\mu)^2}{2\\sigma^{2}} - \\frac{(\\mu-m)}{2v^2}} \\\\\n     &\\propto \\exp{-\\frac{\\mu^2}{2}(\\frac{n}{\\sigma^2}+\\frac{1}{v^2})+\\mu(\\frac{\\sum_{i}^{n}x_i}{\\sigma^2}+\\frac{m}{v^2})} \\\\\n    &\\propto \\exp{-\\frac{\\mu^2}{2}(\\frac{n}{\\sigma^2}+\\frac{1}{v^2})+\\mu(\\frac{n\\Bar{x}}{\\sigma^2}+\\frac{m}{v^2})} \\\\\n    &\\propto \\exp{-\\frac{1}{2\\sigma_{n}^{2}}(\\mu-\\mu_{n})}\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\frac{1}{\\sigma_{n}^{2}} = \\frac{1}{v^2}+\\frac{n}{\\sigma^2} \\Rightarrow{} \\sigma_{n}^{2} = \\frac{1}{\\frac{1}{v^2}+\\frac{n}{\\sigma^2}}\n\\end{equation}\n\\begin{equation}\n    \\mu_n = \\sigma_{n}^2\\left(\\frac{m}{v^2}+\\frac{n\\Bar{x}}{\\sigma^2}\\right) = \\left(\\frac{1}{\\frac{1}{v^2}+\\frac{n}{\\sigma^2}}\\right)\\left(\\frac{m}{v^2}+\\frac{n\\Bar{x}}{\\sigma^2}\\right)\n\\end{equation}\n\n\n\n\\newpage\n\\section{Problem 2}\nConsider a univariate Gaussian $N(X|\\mu, \\lambda^{-1})$ and a dataset $X = \\{x_{1}, x_{2}, x_{3},...,x_{N}\\}$, $x_{i}\\sim N(X|\\mu,\\lambda^{-1})$ of i.i.d observations. Write down the likelihood for this model and show that a conjugate prior is of the form:\n\n\\begin{equation}\n    p(\\mu,\\lambda)\\propto \\left[\\lambda^{1/2} \\exp(-\\frac{\\lambda \\mu^{2}}{2})\\right]^{\\beta} \\exp(c\\lambda \\mu - d\\lambda)\n\\end{equation}\n\nwhere $c$, $d$, $\\beta$ are constants. Given $p(\\mu,\\lambda) = p(\\mu\\mid\\lambda) p(\\lambda)$, we can recognize that the above prior is the product of a Gaussian $p(\\mu\\mid\\lambda)$ whose precision is a linear function of $\\lambda$ and of the gamma distribution $p(\\lambda)$. As a result the normalized prior take the form:\n\\begin{equation}\np(\\mu, \\lambda) = N \\left( \\mu\\mid \\mu_{0},(\\beta \\lambda)^{-1}\\right) Gam(\\lambda\\mid a,b)  \n\\end{equation}\nwhere $\\mu_{0}=c/\\beta, \\alpha = 1+\\beta/2$ and $b = d-c^2/2\\beta$. Show that the posterior $p(\\mu, \\lambda \\mid X)$ is also a Gaussian-gamma distribution of the same functional form as thr prior:\n\\begin{equation}\n    N(\\mu \\mid \\mu_N, ((N+\\beta)\\lambda)^-1) Gam(\\lambda \\mid a_N, b_N)\n\\end{equation}\nwrite down expressions for the parameters of this posterior distribution $\\mu_N$, $a_N$ and $b_N$\n\nAnswer:\nthe likelihood takes the form:\n\\begin{equation}\n\\begin{aligned}\n    p(X|\\mu, \\lambda) & = \\prod_{n=1}^{N} f(x_{n}|\\mu) \\propto \\lambda^{N/2}\\exp{-\\frac{1}{2}\\lambda \\sum_{n=1}^N(x_{n}-\\mu)^2}\\\\ & \\propto \\left[\\lambda^{1/2} \\exp{-\\frac{\\lambda \\mu^2}{2}}\\right]^{N} \\exp{\\lambda\\mu\\sum_{n=1}^{N}x_{n}-\\frac{1}{2}\\lambda\\sum_{n=1}^{N}x_{n}^{2}}\n\\end{aligned}\n\\end{equation}\n\nwe need a prior that has a similar functional form in terms of $\\lambda$ and $\\mu$.\n\n\\begin{equation}\n\\begin{aligned}\n&\\beta = N \\\\\n&c = \\sum_{n=1}^{N}x_{n} \\\\\n&d = \\frac{1}{2}\\sum_{n=1}^{N}x_{n}^{2}\\\\\n&p(\\mu,\\lambda)\\propto \\left[\\lambda^{1/2} \\exp(\\frac{\\lambda \\mu^{2}}{2})\\right]^{\\beta} \\exp(c\\lambda \\mu - d\\lambda)\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\np(\\mu,\\lambda) &\\propto \\left[\\lambda^{1/2} \\exp(\\frac{\\lambda \\mu^{2}}{2})\\right]^{\\beta} \\exp(c\\lambda \\mu - d\\lambda) \\\\\n& = (\\beta\\lambda)^{1/2} \\exp{-\\frac{\\beta \\lambda}{2}\\left(\\mu - \\frac{c}{\\beta}\\right)^{2}} \\lambda^{(\\beta-1)/2} \\exp{-\\left(d-\\frac{c^2}{2\\beta}\\right)\\lambda} \\\\\n& = p(\\mu|\\lambda) p(\\lambda) \\\\\n& = N\\left(\\mu| \\mu_{0}=\\frac{c}{d}, \\sigma = (\\beta \\lambda)^{-1}\\right) Gamma\\left(\\lambda|a = \\frac{1+\\beta}{2},b = d-\\frac{c^2}{2\\beta}\\right)\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\np(\\mu,\\lambda|X) &\\propto \\lambda^{N/2}\\lambda^{a-1}\\exp\\left[-\\left(b+\\frac{1}{2}\\sum_{n=1}^{N}x_{n}^{2}+\\frac{\\beta}{2}\\mu_{0}^{2}\\right)\\lambda\\right]\\times \\\\\n&[\\lambda(N+\\beta)]^{1/2}\\exp{-\\frac{\\lambda(N+\\beta)}{2}\\left[\\mu^{2}-\\frac{2}{N+\\beta}(\\beta\\mu_{0}+\\sum_{n=1}^{N}x_{n})\\mu\\right]} \\\\\n& = N(\\mu | \\mu_{N},[\\lambda(N+\\beta)]^{-1}) Gam(\\lambda | a_{N},b_{N}) \\\\\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n& \\mu_{N}= -\\frac{\\beta\\mu_{0}+\\sum_{n=1}^{N}x_{n}}{N+\\beta}\\\\\n& a_{N} = \\frac{N}{2}+a\\\\\n& b_{N} = -\\left(b+\\frac{1}{2}\\sum_{n=1}^{N}x_{n}^{2}+\\frac{\\beta}{2}\\mu_{0}^{2}-\\frac{(\\beta\\mu_{0}+\\sum_{n=1}^{N}x_{n})^{2}}{2(N+\\beta)}\\right)\n\\end{aligned}\n\\end{equation}\n\n\n\\newpage\n\\section{Problem 3}\nThe Wishart distribution distribution $W_m(n,\\Sigma)$.\n\n1. To prove $E[X|n,\\Sigma]=n\\Sigma$.\n\n\n$X = \\sum_{i=1}^{n} z_{i}z_{i}^{T} \\sim W_{m}(n,\\Sigma)$, where $z_{1},...,z_{n} \\sim N_{m}(0,\\Sigma)$, and $z_{1},...,z_{n}$ are independent with each other.\n\\begin{equation}\n    E[X|n,\\sum] =E[\\sum_{1}^{n}z_{i}z_{i}^{T}] = \\sum_{1}^{n}E[z_{1}z_{1}^{T}] = \\sum_{1}^{n} Var(z_{1}) = n\\Sigma\n\\end{equation}\n\nTherefore,$E[X|n,\\Sigma]=n\\Sigma$.\n\n2. To prove $Cov[X] = 2n\\Sigma \\bigotimes \\Sigma$.\n\n\\begin{equation}\n\\begin{aligned}\n    Cov(X) &= Cov\\left(\\sum_{i=1}^{n} z_{i}z_{i}^{T}\\right) \\\\\n    &= \\sum_{1}^{n}Cov\\left(z_{1}z_{1}^{T}\\right) \\\\\n    &= n Cov\\left(z_{1}z_{1}^{T}\\right)  \\\\\n    &= n Cov\\left(z_{1} \\boxed{ } z_{1}\\right) \\\\\n    &= n Cov((\\Sigma \\bigotimes \\Sigma)(x \\boxed{ } x)) \\\\\n    &= 2n\\Sigma \\bigotimes \\Sigma\n\\end{aligned}\n\\end{equation}\n\n\\newpage\n\\section{Problem 4}\n(a) Derive the log Gamma distribution $Y \\sim log[X]$, $X= G(\\alpha, \\beta)$ and show that it belongs to both families above.\n\nAnswer:\n$Y \\sim log[X]$, $X= G(\\alpha, \\beta)$, therefore, $X \\sim \\exp[Y]$.\n\\begin{equation}\n\\begin{aligned}\n    f_{Y}(x) & = f_{X=e^Y} (e^x) \\frac{d e^x}{d x} = \\frac{1}{\\Gamma(\\alpha)} e^{-\\beta e^x}(\\beta e^{x})^{\\alpha} \\\\\n    & = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} e^{-\\beta e^x}(e^{x})^{\\alpha}\n\\end{aligned}\n\\end{equation}\n\nCheck whether it belongs to exponential family.\n\\begin{equation}\n\\begin{aligned}\n    \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} e^{-\\beta e^x}(e^{x})^{\\alpha} & = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\exp{-\\beta e^x+x\\alpha} \\\\\n    & = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\exp{(-\\beta,\\alpha)(e^x,x)^{T}} \\\\\n    & = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\exp{\\eta(\\alpha,\\beta)^{T}u(x)} \n\\end{aligned}\n\\end{equation}\nwhere $u(x)=(e^x,x)^T, \\eta(\\alpha,\\beta)=(-\\beta,\\alpha)^{T}, h(x)=1,g(\\alpha,\\beta)=\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} $. Therefore, the log Gamma distribution $Y$ belongs to the exponential family.\n\\newline\n(b) Provide examples of two distributions that part of the exponential family.\n\nAnswer:\nConsider the Bernoulli Distribution\n\\begin{equation}\n\\begin{aligned}\n  p(x|\\mu) & =  \\mu^{x}(1-\\mu)^(1-x) \\\\\n  & = \\exp{x\\ln{\\mu}+(1-x)\\ln\\left(1-\\mu\\right)} \\\\\n  & = (1-\\mu)\\exp{\\ln\\left(\\frac{\\mu}{1-\\mu}\\right)x}\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n&\\eta = \\ln\\left(\\frac{\\mu}{1-\\mu}\\right) \\\\\n&\\mu = \\sigma(\\eta)= \\frac{1}{1+e^{-\\eta}} \\\\\n& g(\\eta) = 1-\\mu = \\frac{1}{1+e^{\\eta}} \\\\\n& p(x|\\mu) = g(\\eta)\\exp{\\eta x}, \\mu(x)= x, h(x)=1,g(\\eta) = 1-\\mu = \\frac{1}{1+e^{\\eta}}\n\\end{aligned}\n\\end{equation}\n\nConsider the Beta distribution\n\n\\begin{equation}\n\\begin{aligned}\n  p(x|a,b) & =  \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} x^{a-1}(1-x)^{b-1} \\\\\n  & = \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} \\exp[(a-1)\\ln(x) + (b-1)\\ln(1-x)] \\\\\n  & = h(x)g(\\eta)\\exp{\\eta^{T}u(x)}\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n&\\eta = (a-1,b-1)^{T} \\\\\n&\\mu(x) = (\\ln(x),\\ln(1-x))^{T} \\\\\n& g(a,b) = \\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)} \\\\\n& h(x)=1\n\\end{aligned}\n\\end{equation}\n\\newline\n(c) Provide examples of two distributions that are part of the local-scale family.\n\nAnswer:\n\nConsider the Cauchy distribution:\ntake $\\Psi(x) = \\frac{1}{\\pi}\\frac{1}{1+x^2}$\n\\begin{equation}\n\\begin{aligned}\np(x|a,b) = \\frac{1}{b}\\Psi\\left(\\frac{x+a}{b}\\right) = \\frac{1}{\\pi b}\\frac{1}{1+\\left(\\frac{x+a}{b}\\right)^2}\n\\end{aligned}\n\\end{equation}\ndefines the Cauchy L-S family.\n\nConsider the Uniform distribution:\ntake $\\Psi(x) = I_{(0,1)}(x)$\n\\begin{equation}\n\\begin{aligned}\n    I_{(0,1)}(x) = 1, if 0<x<1\n    I_{(0,1)}(x) = 0, otherwise\n\\end{aligned}\n\\end{equation}\n$\\Psi(x)$ is the pdf of the Unif(0,1) distribution\n\\begin{equation}\n\\begin{aligned}\np(x|a,b) = \\frac{1}{b}\\Psi\\left(\\frac{x+a}{b}\\right) = \\frac{1}{b}I_{(0,1)}\\left(\\frac{x+a}{b}\\right) = \\frac{1}{b}I_{(-a,-a+b)}(x)\n\\end{aligned}\n\\end{equation}\nThis is the pdf of the Unif$(-a,-a+b)$\n\\newpage\n\\section{Problem 5}\n(a) Start by plotting a histogram of the camera's max resolution. Fit a normal distribution to this data and plot the fitted distribution on top of histogram. Repeat for the camera weight.\n\nAnswer:\nthe camera's max resolution\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{w5a1.jpg}\n\\caption{Histogram and normal distribution fitting of the camera's max resolution}\n%\\label{fig:universe}\n\\end{figure}\n\nthe camera's weight\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{w5a2.jpg}\n\\caption{Histogram and normal distribution fitting of the camera's weight}\n%\\label{fig:universe}\n\\end{figure}\n\\newline\n(b) Standardize the camera max resolution data using the fitted mean, $\\Bar{x_{i}}$, and standard deviation, $\\sigma_{i}$. This can be completed by computing $(x_{ij}-\\Bar{x_{i}})/\\sigma_{i}$. Plot a standard Gaussian $N(0,1)$ on top of the normalized data. Comment on why we would be interested in doing this.\n\nAnswer:\nfrom (a) the normal distribution fitting for the max resolution\n$\\Bar{x_i} = 2491.7618497109806, \\sigma_{i} = 752.5256308818603$.\nThen, we standardize the camera max resolution data by computing $(x_{i}-\\Bar{x_{i}})/\\sigma_{i}$.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{w5b1.jpg}\n\\caption{Standard Gaussian $N(0,1)$ fitting of the normalized camera's max resolution}\n%\\label{fig:universe}\n\\end{figure}\n\n\nThe reason that we would be interested in doing this is that the standardized data is easier to compare with each other.\n\\newline\n(c) Fit a Gamma, $G(\\alpha, \\beta)$, distribution to the histogram of the camera's weight through MLE. Plot both fitted distributions on top of the histogram. Comment on which distribution provides a better fit.\n\nstart by finding the log-likelihood of Gamma distribution\n\\begin{equation}\n  f=\\ln(T) = (\\alpha-1) \\sum \\ln(x)  - n\\ln(\\Gamma(\\alpha)) - n\\alpha \\ln(\\beta)-\\frac{1}{\\beta}\\sum x \n\\end{equation}\n\\begin{equation}\n  \\frac{d\\ln(T)}{d\\beta} =  -\\frac{n\\alpha}{\\beta}+\\frac{1}{\\beta^2}\\sum x =0 \n\\end{equation}\n\\begin{equation}\n  \\beta = \\frac{\\sum x}{n \\alpha} = \\frac{\\Bar{x}}{\\alpha}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n  f(\\alpha) &= (\\alpha-1)n \\Bar{\\ln(x)} - n \\ln(\\Gamma(\\alpha))-n\\alpha \\ln(\\frac{\\Bar{x}}{\\alpha})-n\\alpha \n\\end{aligned}\n\\end{equation}\nUsing the minka-newton method from the paper provided.\n\\begin{equation}\n\\begin{aligned}\n  f^{'}(\\alpha) &= n \\Bar{\\ln(x)} - n \\Psi(\\alpha)-n \\ln(\\Bar{x})+n\\ln(\\alpha)\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n  f^{''} (\\alpha)&=  - n \\Psi^{'}(\\alpha)+\\frac{n}{\\alpha}\n\\end{aligned}\n\\end{equation}\n\\begin{equation}\n\\begin{aligned}\n  \\frac{1}{\\alpha^{new}} = \\frac{1}{\\alpha^{old}}+ \\frac{f^{'}(\\alpha)}{\\alpha^2 f^{''}(\\alpha)} = \\frac{1}{\\alpha^{old}}+ \\frac{ \\Bar{\\ln(x)} -  \\Psi(\\alpha)- \\ln(\\Bar{x})+\\ln(\\alpha)}{-  \\alpha^{2}\\Psi^{'}(\\alpha)+\\alpha}\n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{alpha.jpg}\n\\caption{ alpha value with minka-newton method}\n%\\label{fig:universe}\n\\end{figure}\nFrom Figure 4, we find that the value of $\\alpha$ converges very quickly. $\\alpha \\approx 1.84$ and $\\beta \\approx 166.6387422858897$.\n\nThen we use the $\\alpha$ and $\\beta$ to plot the fitted Gamma distribution and compare with the Gaussian in Figure 2.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{h5c.jpg}\n\\caption{ Gamma distribution and Gaussian distribution camera's weight}\n%\\label{fig:universe}\n\\end{figure}\nAfter comparing with the Gaussian distribution fitting, we find that the Gamma distribution is better than the Gaussian distribution for the camera's weight.\n\\newline\n(d)Plot the camera's release year vs. max-resolution. Fit a 2D Gaussian distribution to this data through MLE. Plot the fitted Gaussian on top of the data.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.5]{w5d.jpg}\n\\caption{ 2D Gaussian distribution camera's release year vs. max-resolution}\n%\\label{fig:universe}\n\\end{figure}\n\\newline\n\n%\\bibliographystyle{plain}\n%\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "7275e48c7ed051142157c2da07f5f78f6fe03a26", "size": 13325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW1/HW1_Shi_Jiale/HW1_JialeShi Latex/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/HW1/HW1_Shi_Jiale/HW1_JialeShi Latex/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/HW1/HW1_Shi_Jiale/HW1_JialeShi Latex/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": 39.3067846608, "max_line_length": 322, "alphanum_fraction": 0.6378236398, "num_tokens": 5046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.6466714480061667}}
{"text": "\\setlength{\\abovedisplayskip}{2pt}\n\\setlength{\\belowdisplayskip}{2pt}\n\\section{Bayesian Thinking and Estimation}\n\\label{sec:bayesian_thinking}\nIn this section we introduce the core topics of Bayesian statistics and, whenever possible, compare proposed methods and results to their classicist counterpart.\n\nWe use standard notation wherever possible, nonetheless we make one exception in that we write $p(Z)$ for the probability density function of the random variable $Z$, where $Z$ may be scalar-valued or vector-valued.\nIf it is clear from the context we will also write $p(z)$ for the density of $Z$ evaluated at $z$.\n\n\\subsection{Probabilistic Modeling}\nWe begin by introducing a formal notion of stochastic modeling and continue with a taxonomic description of different schools of thought.\n\nSay we observe data $\\mathcal{D} = \\{(y_i, x_i) : i=1,\\mydots,n\\}$ for which we have some intuition about the relationship between $X$ and $Y$ ---this intuition might come from (economic) theory for example.\nWe formalize this by writing the data generating process as a (possibly algorithmic) mathematical model $Y = \\mathcal{M}(X; \\epsilon, \\theta)$, where $\\theta$ denotes the model parameters and $\\epsilon$ an explicitly modeled error term which corrects for uncertainty in the model, e.g. in the case of non-observables.\n\nIn the rest of this paper we assume that we know the parametric structure of $\\mathcal{M}$ and that our goal lies in learning about the parameters after observing the data $\\mathcal{D}$.\nAn important aspect here is to postulate the existence of a \\textit{true data generating process}, which we do by assuming that there is some (fixed) $\\theta_0$, in the parameter space $\\Theta$, so that $Y = \\mathcal{M}(X; \\epsilon, \\theta_0)$ describes reality sufficiently accurate and better than for any other parameter.\nThe subsequent goal is then to learn about $\\theta_0$.\nNote that for everything that follows we need to assume that our \\emph{true model} actually describes reality accurately; if not we enter the realm of model misspecification which can render any analysis useless.\n\nNext we compare two different schools of thought present in the statistical domain, which consider the estimation of $\\theta_0$ and the quantification of uncertainty in the estimate.\n\n\\paragraph{Frequentist.}\nIn the literature the so called frequentist methods constitute the most widely used approaches.\nA particular method ---which we choose here as it lends itself nicely to a comparison--- is the maximum likelihood approach.\nThere we use the distributional assumptions on our model to construct the likelihood function $\\mathcal{L}(\\theta; \\mathcal{D}) = p(\\mathcal{D}; \\theta)$, which is simply the joint density of the data evaluated at the observed data points for varying parameter $\\theta$.\nWe can then find an estimator $\\hat{\\theta}$ for $\\theta_0$ as the maximizer of this function, i.e. $\\hat{\\theta} \\in \\argmax{\\theta \\in \\Theta} \\mathcal{L}(\\theta; \\mathcal{D})$.\nThere has been published an extensive amount of research on the properties of this estimator, for example on sufficient conditions for the uniqueness of the maximization or large-sample normal approximations.\nIn particular, under some regularity conditions we can find a matrix $\\widehat{V}$ so that $\\sqrt{n}\\widehat{V}^{-1/2}(\\hat{\\theta} - \\theta_0) \\overset{d}{\\longrightarrow} \\normal{0, \\mathrm{I}}$.\nThis result we can use to quantify uncertainty in $\\hat{\\theta}$ by computing standard errors and confidence intervals, as well as to formulate tests.\n\nOne fundamental idea which stretches over all methods in the frequentist world is the interpretation of probability as the limit of an infinite sequence of relative frequencies of events---hence the name.\nProbability then just counts how many times an event happened or not; for example if we toss a coin an infinite number of times, the relative frequency of heads converges to the probability of heads.\nWe do expect the outcome of an experiment (e.g. coin flip) to vary, however, we do not assume the true parameter to vary.\nFor instance, we may interpret the probability of a coin landing on heads as the true model parameter.\nIn this sense, it would be absurd to let this object vary for different experiments.\nTherefore any hypothesis on $\\theta_0$ is either true or false.\nAnd it is this binarity which makes hypothesis testing (interpretation of confidence intervals) awkward in the frequentist setting.\nBy testing some hypothesis $H_0: \\theta_0 = \\theta^*$ we do not directly compute the probability of the hypothesis being true --hypothesis are either false or true--- but we compute if the observed data $\\mathcal{D}$ is more likely to have orginated under the null hypothesis or the alternative.\n\n\\paragraph{Bayesian.}\nThe main difference of the Bayesian mindset is the understanding of probability as a subjective quantification of uncertainty.\nWe may still believe that $\\theta_0$ is fixed, nevertheless, in the Bayesian paradigm we build uncertainty about the true location of the parameter into the model by allowing for probability distributions to be defined on $\\Theta$ ---which, as we saw above, is nonsensical in a frequentist worldview.\nWe can see the direct utility of this liberation by considering Bayes theorem applied to densities on our model\n\\begin{flalign*}\n  && p(\\theta \\mid \\mathcal{D}) &= \\frac{p(\\mathcal{D} \\mid \\theta) p(\\theta)}{p(\\mathcal{D})} \\propto p(\\mathcal{D} \\mid \\theta) p(\\theta) \\,,\\tag{Bayes theorem}&\\\\[0.7em] \\text{which reads} &&\n  posterior &= \\frac{likelihood \\times prior}{evidence} \\propto likelihood \\times prior \\,.\n\\end{flalign*}\nThe posterior distribution is the object of interest for any subsequent Bayesian analysis, it describes the distribution of the parameter of interest given the observed data $\\mathcal{D}$.\nFrom a naive standpoint this is too good to be true.\nAnd in fact it is.\nTo give Bayes theorem any meaning we have to define the prior $p(\\theta)$, a probability distribution of the model parameter on $\\Theta$.\nThe prior may be used to incorporate knowledge about the parameter into the analysis that existed prior to observing the data.\nBut this can be highly subjective and can lead to \\emph{two} different researchers having \\emph{two} different priors which would result in \\emph{two} different posteriors.\nThis is where the main criticism of Bayesian statistics is focused on: where does the prior distribution come from?\nWith the scientific goal of objectivity in mind, many feel at unease having results dependent on subjective choices of the prior.\nIn what follows we will embark on the Bayesian idea without providing much more fundamental criticism, nonetheless, when adequate we will consider the influence of different priors on the posterior.\n\nIn comparison to the maximum likelihood approach, in a Bayesian analysis there is no need for one specific point estimator or confidence interval.\nThe result of such an analysis is a complete probability distribution from which we can compute, in principle, any quantity we like.\nBeing clear on all prior assumptions and giving up (some) \\emph{objectivity} we gain the possibility to formulate answers to more natural questions, as for example: $\\prob{\\theta \\in \\Theta_0 \\mid \\mathcal{D}} = \\int_{\\Theta_0} p(\\theta \\mid \\mathcal{D}) \\mathrm{d}\\theta$.\n\n\\subsection{Solving for the posterior analytically}\nIn this subsection we present an analytical derivation of the posterior distribution of mean and variance parameters in a univariate normal model for two priors.\nWe compare the results to the maximum likelihood estimator.\nAs it will be of major importance in the subsequent sections, we have included the definition of the scaled inverse $\\chi^2$ probability distribution in the appendix (see definition \\ref{def:scaledInverseChi}).\n\nLet us assume that we observe a sample $y = (y_1, \\mydots, y_n)$\nwith $y_i \\mid \\theta \\overset{\\text{iid}}{\\sim} \\normal{\\mu, \\sigma^2}$, where $\\theta = (\\mu, \\sigma^2)$.\nOur interest lies in solving for the marginal posteriors $p(\\mu \\mid y)$ and $p(\\sigma^2 \\mid y)$.\n\n\\paragraph{Noninformative Prior.}\nWe start our analysis with a common prior choice in settings where we have little prior information and sufficent data.\nIn these cases we can use noninformative priors to model complete ignorance of any prior information, in particular, here we use \\emph{flat priors}, which assign equal weight to every region in the parameter space.\nLet us go with the common assumption that $\\mu$ and $\\sigma^2$ are independent a priori.\nMathematically we can write a flat prior as $p(\\mu) \\propto 1$.\nWe note that this does not define a proper proability distribution, which will not matter in this case but can lead to problems in others; see for example section 4.2 in \\citet{kass1996}.\nSince the variance is restricted to be positive we impose a flat prior on the log-transform thereof, i.e. $p(\\log \\sigma) \\propto 1$.\nUsing that $x \\mapsto \\text{exp}^2(x)$ is one-to-one we get the density of the transformed variable $p(\\mu, \\sigma^2) = p(\\mu)p(\\sigma^2) \\propto p(\\sigma^2) \\propto (\\sigma^2)^{-1}$.\n\nThe likelihood is given by $p(y \\mid \\mu, \\sigma^2) \\propto (\\sigma^2)^{-n/2} \\EXP{-\\sum_i (y_i - \\mu)^2/2\\sigma^2}$, where we dropped all proportionality constants.\nApplication of Bayes theorem yields $p(\\mu, \\sigma^2 \\mid y) \\propto p(y \\mid \\mu, \\sigma^2) p(\\mu, \\sigma^2) \\propto (\\sigma^2)^{-(n+2)/2} \\EXP{-\\sum_i (y_i - \\mu)^2/2\\sigma^2}$.\nIntegrating over the respective parameter yields the marginal posteriors.\n\n\\begin{proposition}\\label{prop:posterior_uniform}\n  Under the above setup and a flat prior on $\\mu$ and $\\log \\sigma$ we find $\\mu \\mid y \\sim t_{n-1}(\\bar{y}, s^2/n)$ and $\\sigma^2 \\mid y \\sim \\scaledInvChi{n-1, s^2}$, where $s^2 = \\sum_i (y_i - \\bar{y})^2 / (n-1)$ denotes the (unbiased) sample variance and $\\bar{y} = \\frac{1}{n} \\sum_i y_i$ the sample mean, respectively.\n\\end{proposition}\n\\begin{proof}\nSee appendix.\n\\end{proof}\n\nWe compare the marginal posteriors to their maximum likelihood counterpart by reporting summary statistics of the distributions in table \\ref{tab:comp_uniform_bay_ml}.\nWe focus on the mean and variance of the posterior, as well as the \\emph{maximum a posteriori} (MAP) estimate $\\left(\\argmax{\\theta \\in \\Theta} p(\\theta \\mid y)\\right)$, but withhold from a discussion as we consider the more general results of the next paragraph in more detail.\n\n\\begin{table}[ht]\n\\centering\n\\def\\arraystretch{1.3}\n{\\small\n \\begin{tabular}{c | c c c c c}\n Parameter & ML Estimate & ML Variance & MAP & Posterior Mean & Posterior Variance\\\\[0.5ex]\n \\hline\n $\\mu$ & $\\bar{y}$ & $\\sigma^2/n$ & $\\bar{y}$ & $\\bar{y}$ & $s^2 / n$\\\\\n $\\sigma^2$ & $\\frac{n-1}{n} s^2$ & $2 \\sigma^4 /n$ & $\\frac{n-1}{n+1} s^2$ & $\\frac{n-1}{n-3} s^2$ & $\\frac{2 (n-1)^2}{(n-3)^2 (n-5)} s^4$\\\\\n \\end{tabular}\n }\n\\caption{\\small{Comparison of Bayesian estimates using a flat prior to ML estimates. See appendix for derivation.}}\n\\label{tab:comp_uniform_bay_ml}\n\\end{table}\n\n\\vspace{-15pt}\n\\paragraph{Conjugate Prior.}\nIn case substantial information on the parameters is available a priori, we can model this information properly to gain more stable results.\nHowever, not every product of prior and likelihood results in a sensible posterior.\nAs we are interested in analytical results in this section we seek priors that guarantee posteriors of known form.\nThe class of \\emph{conjugate priors} (see definition \\ref{def:conjugate_prior} in the appendix) plays an important part in Bayesian statistics as they are able to provide such assurance.\n\nConsider again the likelihood but written dependent on the sufficient statistics $\\bar{y}$ and $s^2$\n\\begin{align}\n  p(y \\mid \\mu, \\sigma^2) \\propto (\\sigma^2)^{n/2} \\EXP{-\\frac{1}{2\\sigma^2} \\left[ n(\\mu - \\bar{y})^2 + (n-1)s^2 \\right]} \\,,\n  \\label{eq:likelihood2}\n\\end{align}\nwhere $s^2$ again denotes the (unbiased) sample variance.\nWe want to construct a two dimensional conjugate prior for $(\\mu, \\sigma^2)$ such that multiplying the prior by the likelihood does not change its structure, as this assures the posterior to be of known form.\nNote that we have $p(\\mu, \\sigma^2) = p(\\mu \\mid \\sigma^2) p(\\sigma^2)$.\nLooking at equation (\\ref{eq:likelihood2}) we see that in order to \\emph{not} change the inherent structural dependence on the parameters we must have $\\mu \\mid \\sigma^2 \\sim \\normal{\\mu_0, \\sigma^2 / \\kappa_0}$, with \\emph{hyperparameters} $\\mu_0$ and $\\kappa_0 > 0$.\nSimilarly, we observe that we must have $\\sigma^2 \\sim \\scaledInvChi{\\nu_0, \\sigma_0^2}$, with hyperparameters $\\nu_0$ and $\\sigma_0^2 > 0$.\nThis becomes apparent when considering the respective densities.\nFollowing \\citet{gelmanbda04} we write $(\\mu, \\sigma^2) \\sim \\NormalscaledInvChi{\\mu_0, \\sigma_0^2 / \\kappa_0; \\nu_0, \\sigma_0^2}$, with corresponding density function $p(\\mu, \\sigma^2) = p(\\mu \\mid \\sigma^2) p(\\sigma^2) \\propto (\\sigma^2)^{\\frac{3 + \\nu_0}{2}} \\EXP{-\\frac{1}{2\\sigma^2} \\left[\\nu_0 \\sigma_0^2 + \\kappa_0(\\mu_0 - \\mu)^2 \\right]}$.\nMultiplying the likelihood with our constructed prior we get the joint posterior\n\\begin{align}\n  p(\\mu, \\sigma^2 \\mid y) \\propto& (\\sigma^2)^{-\\frac{3 + \\nu_0 + n}{2}} \\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  \\label{eq:conjugate_posterior}\n\\end{align}\n\n\\begin{proposition}\n  The (posterior) distribution of $(\\mu, \\sigma^2) \\mid y$ , as given by the conditional density in equation (\\ref{eq:conjugate_posterior}), is $\\NormalscaledInvChi{\\mu_n, \\sigma_n^2/\\kappa_n; \\nu_n, \\sigma_n^2}$, where\n    $\\nu_n = \\nu_0 + n$, $\\kappa_n = \\kappa_0 + n$, $\\mu_n =\\frac{\\kappa_0}{\\kappa_n}\\mu_0 + \\frac{n}{\\kappa_n}\\bar{y}$ and $\\sigma_n^2 = \\left[\\nu_0 \\sigma_0^2 + (n-1)s^2 + \\frac{\\kappa_0 n}{\\kappa_n} (\\bar{y} - \\mu_0)^2\\right] /\\nu_n$.\n  \\label{prop:posterior_conjugate}\n\\end{proposition}\n\\begin{proof}\n  See appendix.\n\\end{proof}\n\nSince the prior and the posterior are both normal scaled inverse $\\chi^2$ distributed, we indeed constructed a conjugate prior.\nUsing the intermediate finding from proposition \\ref{prop:posterior_conjugate} we can derive the main result of this section.\n\n\\begin{proposition}\\label{prop:marginal_posterior}\n  The marginal posterior distributions are given by $\\mu \\mid y \\sim t_{\\nu_n}(\\mu_n, \\sigma_n^2 / \\kappa_n)$ and $\\sigma^2 \\mid y \\sim \\scaledInvChi{\\nu_n, \\sigma_n^2}$, where $\\nu_n, \\sigma_n^2, \\mu_n$ and $\\kappa_n$ are as in proposition \\ref{prop:posterior_conjugate}.\n\\end{proposition}\n\\begin{proof}\n  See appendix.\n\\end{proof}\n\n\\begin{table}[ht]\n\\centering\n\\def\\arraystretch{1.3}\n{\\small\n \\begin{tabular}{c | c c c c c}\n Parameter & ML Estimate & ML Variance & MAP & Posterior Mean & Posterior Variance\\\\\n \\hline\n $\\mu$ & $\\bar{y}$ & $\\sigma^2 / n$ & $\\mu_n$ & $\\mu_n$ & $\\sigma_n^2 / \\kappa_n$\\\\\n $\\sigma^2$ & $\\frac{n-1}{n}s^2$ & $2 \\sigma^4 / n$ & $\\frac{\\nu_n}{\\nu_n + 2} \\sigma_n^2$ & $\\frac{\\nu_n}{\\nu_n - 2} \\sigma_n^2$ & $\\frac{2 \\nu_n^2}{(\\nu_n - 2)^2(\\nu_n - 4)} \\sigma_n^4$\n \\end{tabular}\n }\n\\caption{{\\small Comparison of Bayesian estimates using a conjugate prior to ML estimates. See appendix for derivation.}}\n\\label{tab:comp_conjugate_bay_ml}\n\\end{table}\n\nNext we consider the results of Proposition \\ref{prop:marginal_posterior}, of which some summary statistics are tabulated in table \\ref{tab:comp_conjugate_bay_ml}.\nWe focus on the analysis of the mean parameter $\\mu$.\n\nAs the t-distribution is parameterized over its mean and variance (and degrees of freedom) we can directly deduce the posterior mean as $\\mu_n =\\frac{\\kappa_0}{\\kappa_0 + n}\\mu_0 + \\frac{n}{\\kappa_0 + n}\\bar{y}$ and the posterior variance as $\\sigma_n^2 / \\kappa_n$.\nWe see that the posterior mean is simply a convex combination of the prior $\\mu_0$ and the sample average $\\bar{y}$, with weights determined by the sample size and $\\kappa_0$.\nFor any fixed $n$ this pulls our estimate of the posterior mean away from $\\bar{y}$ and closer to $\\mu_0$ (and vice versa), which can be helpful if we have insufficient data and believe that the parameter should be around $\\mu_0$ ---we can use $\\kappa_0$ then to express our degree of believe in the prior.\nAs $n$ grows to infinity the information in the data overwhelms all prior information and the posterior mean is dominated by the sample mean.\n\nSimilarly we can use the hyperparameters $\\sigma_0^2, \\nu_0$ and $\\kappa_0$ to model our prior knowledge of the variance parameter, which propagates to the posterior variance of the mean parameter.\nConsidering the variance of the posterior mean as a function in $n$ we can use the \\emph{Landau notation} to write $\\sigma_n^2 / \\kappa_n =  \\frac{n}{(\\nu_0 + n)(\\kappa_0 + n)} s^2 + \\mathcal{O}(1/n^2) = \\mathcal{O}(1/n)$, which resembles the usual $1/n$ convergence rate.\n\nAs $v_n = v_0 + n$ tends to infinity the distribution of the posterior mean tends to a normal distribution with parameters behaving (asymptotically) similar to the maximum likelihood estimators.\nIn this sense, informative Bayesian priors can be appropriate if the data contains insufficient information \\emph{and} we have reasonable knowledge a priori, where we use the prior to stabilize the results.\nBut they are also reasonable if we consider large samples, where the prior is simply dominated by the likelihood.\nWe refrain from an analogous analysis for $\\sigma^2$ here and only note that similar results hold, as can be seen from table \\ref{tab:comp_conjugate_bay_ml}.\n\nAbove we considered a simple model, as this allowed us to derive the results analytically.\nClosed form solutions allow us to fully investigate the influence of the prior on our results.\nHowever, we have also seen that Bayesian analyses are far from trivial and depend critically on the complexities of the model structure.\nIf we want to consider more realistic models we have to make ever more restrictive assumptions to yield analytical results.\nFor this reason among others, in the next section we discuss methods which trade off the clarity of an analytical result for the generality of being able to combine near arbitrary priors with complex, possibly high-dimensional likelihoods.\n\n\\subsection{Sampling From The Posterior}\nIn this section we consider approaches that allow us to characterize the posterior distribution in complex settings using sampling methods.\n\nFor the rest of this section let us assume we observed data $\\mathcal{D}$ for which we have a (possibly algorithmic) model in mind, which can be represented by the likelihood $p(\\mathcal{D} \\mid \\theta)$.\nWe also assume that a prior distribution $p(\\theta)$ has been constructed, so that the posterior is again given by $p(\\theta \\mid \\mathcal{D}) \\propto p(\\mathcal{D} \\mid \\theta) p(\\theta)$.\nUnlike before however, we now consider more general settings in which we do not restrict $p(\\theta \\mid \\mathcal{D})$ to be available in analytical form.\nThis may occur in many settings, for example when using priors that do not mix well with the likelihood or more apparent when using computational models which produce likelihood evaluations based on algorithms.\n\nTo motivate the following, say we are able to draw independent samples $\\theta^{(1)}, \\mydots, \\theta^{(n)}$ from $p(\\theta \\mid \\mathcal{D})$.\nBy the law of large numbers we get $1 / n \\sum_i h\\left(\\theta^{(i)}\\right) \\overset{a.s.}{\\longrightarrow} \\Exp{h(\\theta) \\mid \\mathcal{D}}$, under some regularity conditions on $h$ and $p(\\theta \\mid \\mathcal{D})$, with similar results holding for sample quantiles.\nHence, to learn something about $p(\\theta \\mid \\mathcal{D})$ we can formulate questions using quantiles or general expectations and rely on the statement above.\n\nIn the subsequent paragraphs we discuss methods to sample from the posterior that work under the general assumption that we can evaluate the posterior at arbitrary points up to an integration constant.\nWe will see that these methods do \\emph{not} produce independent samples but instead create \\emph{Markov chains} whose realizations can be seen as autocorrelated samples.\n\nWith this in mind, we first consider what properties these chains must fulfill in order to create equivalent results as motivated above for independent samples.\nWe end this section by introducing an algorithm that accomplishes the above.\n\n\\paragraph{Markov Chain Monte Carlo.}\nSay we are able to construct a Markov chain with unique invariant distribution equal to the posterior distribution we want to sample from.\nAssume also that the distribution of the chain at time $n$ converges to this invariant distribution no matter where we initialize the chain.\nThen, in principle, we could run the chain \\emph{long enough} until it converged to the invariant distribution and then consider all subsequent realizations as draws from the stationary distribution.\nThis is the core idea of Markov chain Monte Carlo (MCMC).\nIn practice, however, we do not know when a chain is run \\emph{long enough}.\nIn part 3 we present some measures that can be of help with this problem during the application.\n\nUnder some regularity conditions, similar but not as strict as in Theorem \\ref{thm:mcclt}, we get a law of large numbers for such Markov chains (see e.g. \\citet{roberts2004}, Fact 5).\nThis tells us that if we run the chain forever, our average will eventually converge to the number we seek.\nHowever, forever is usually too long.\nThat is why we focus on assumptions which admit a central limit theorem with the usual $\\sqrt{n}$ convergence rate, as it allows for more rigorous statements about our confidence in the whereabouts of the estimator for large samples.\n\n\\begin{remark}\n  \\emph{(i)} Having a central limit theorem in the background does \\emph{not} imply that the asymptotic distribution provides a good approximation for finite samples.\n  We still do not know when the asymptotics `kicks in' (\\citet{Jackman2009}).\n  But under assumptions that allow for a CLT we can be more confident in our results than under assumption that only allow of a LLN.\n \\emph{(ii)} As is often the case, there are many different sets of assumptions that allow for a CLT.\n  The following theorem presents a particular set of assumptions which will be seen to have favorable properties when also considering the creational process of the Markov chain.\n  We remark that we will \\emph{not} formally introduce all concepts and will provide only a heuristic explaination.\n  This is due to the fact that Markov chain theory on general state spaces requires a good understanding of measure theory, which we do not want to assume as a prerequisite.\n  We refer to \\citet{roberts2004} for a survey on recent advances with application to MCMC and \\citet{meynandtweedie09} for a comprehensive treatment of Markov chain theory.\n\\end{remark}\n\n\\begin{theorem}{(A Central Limit Theorem for Markov Chains).}\\label{thm:mcclt}\n  Let $\\{X_n \\}$ be a (discrete time) Markov chain and $\\pi$ a probability distribution on the same space.\n  Consider some measurable function $h$ with $\\Expwrt{\\pi}{h^2} < \\infty$.\n  Define $\\sigma^2(h) := \\varwrt{\\pi}{h}\\tau := \\varwrt{\\pi}{h} \\sum_{k \\in \\mathrm{Z}} \\text{Corr}\\left(h(X_0), h(X_k)\\right)$.\n  Assume the Markov chain is $\\phi$-irreducible, aperiodic, reversible with respect to $\\pi$ and that $\\sigma^2(h) < \\infty$. Then $\\pi$ is stationary for the chain and\\footnote{In the original paper by \\citet{roberts2004} the statement of this theorem differs in that they write $\\tau = \\sum_{k \\in \\mathrm{Z}} \\text{Corr}\\left(X_0, X_k\\right)$.\n  We believe that this is an error as \\citet{haggstrom2007} state in their comparison of different ways of writing the asymptotic variance that $\\sigma^2(h) = \\sum_{k \\in \\mathrm{Z}} \\Cov{h(X_0), h(X_k)}$.\n  Now if we use that $X_0 \\sim \\pi$ we get $\\sigma^2(h) = \\sum_{k \\in \\mathrm{Z}} \\Cov{h(X_0), h(X_k)}= \\var{h(X_0)} + \\sum_{k \\neq 0} \\Cov{h(X_0), h(X_k)} = \\varwrt{\\pi}{h}(1 + \\sum_{k \\neq 0} \\Cov{h(X_0), h(X_k)}) / \\var{h(X_0)} =\\varwrt{\\pi}{h}(1 + \\sum_{k \\neq 0} \\text{Corr}{(h(X_0), h(X_k))}) = \\varwrt{\\pi}{h} \\sum_{k\\in\\mathrm{Z}} \\text{Corr}{(h(X_0), h(X_k))}$.}\n  \\begin{align}\n    \\sqrt{n}\\left(\\frac{1}{n}\\sum_{i=1}^n h(X_i) - \\Expwrt{\\pi}{h} \\right) \\overset{d}{\\longrightarrow} \\normal{0, \\sigma^2(h)} \\,.\n  \\end{align}\n\\end{theorem}\n\\begin{proof}\n  See \\citet{kipnis1986} for a complete proof of the second claim; see \\citet{roberts2004} Proposition 1 for the first claim and Theorem 27 for the second.\n\\end{proof}\n\n\\noindent\nWe end this paragraph by discussing the assumptions of Theorem \\ref{thm:mcclt} on an intuitive level.\n\n\\textbf{$\\phi$-irreducibility} assumes that we can find a measure $\\phi$ such that no matter where the chain starts, we eventually reach every region of the state space which has positive measure with respect to $\\phi$.\nIn the next paragraph we will see that this condition can be satisfied by construction of the chain.\n\n\\textbf{Aperiodicity} assumes that we cannot find disjoint regions on which the chain jumps from one region to another in a cyclical predictable fashion.\nIt seems intuitive that such a behavior will prevent the chain from actually converging to its stationary distribution.\n\n\\textbf{Reversibility with respect to $\\bm{\\pi}$} is a technical assumption which is best explained by its implications.\nIn particular, it implies that the Markov chain has $\\pi$ as its stationary distribution (which is unique by the other assumptions).\nAgain, in the next paragraph we will see that this condition can be satisfied by construction with $\\pi$ being the posterior distribution from which we want to sample.\n\n\\textbf{Finite variance} ($\\sigma^2(h) < \\infty$) implies that the integrated correlation time $\\tau$ must be finite, as we assumes square integrability of $h$.\nThe integrated correlation time is finite if the correlation function decreases fast enough to zero.\nHeuristically speaking, for a CLT to work we need more information as would be available in a sample for which the integrated autocorrelation time is infinite.\nIf it is finite we get the usual large sample variance approximation $\\sigma^2(h) / n = \\varwrt{\\pi}{h} / (n/\\tau)$.\nIn this sense we might say that $n/\\tau$ denotes the \\emph{effective sample size}, which corrects for the fact that we are not drawing independent samples and therefore (in most cases) need more samples to yield the same amount of information as in the independent case.\n\n\\paragraph{Metropolis-Hastings Algorithm.}\nHere we consider one method which implicitly defines a Markov chain with the desired properties, the Metropolis-Hastings algorithm (\\citet{Metropolis1953}, \\citet{hastings70}).\nFor other approaches and more involved algorithms see for example \\citet{liang10}.\n\n\\begin{algorithm}\n\\caption{Metropolis-Hastings}\\label{alg:metropolis-hastings}\n\\begin{algorithmic}[1]\n  \\Require $(\\pi, q, T) =$ (target density, proposal density, number of samples to draw)\n\\State initialize $x_0$ with an arbitrary point from the support of $q$\n\\For{$t = 0,\\mydots,T-1$}\n  \\State sample a candidate: $y \\sim q(\\cdot \\mid x_t)$\n  \\State compute the acceptance probability: $\\mathcal{A} \\gets \\min\\left\\{ \\ddfrac{\\pi(y)}{\\pi(x_t)} \\ddfrac{q(y \\mid x_t)}{q(x_t \\mid y)}, 1\\right\\}$\n  \\State update the chain: $x_{t+1} \\gets \\begin{cases} y &\\mbox{,with probability } \\mathcal{A}\\\\ x_t &\\mbox{,with remaining probability} \\end{cases}$\n\\EndFor{}\n\\State \\textbf{return} $\\{x_t : t = 1,\\mydots,T\\}$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\noindent\nAlgorithm \\ref{alg:metropolis-hastings} displays the Metropolis-Hastings algorithm.\nThe main idea is that we start with an initial value and iteratively propose new values of the chain, however, we do not accept every proposal, but we do so only with a certain probability ---this probability can be thought of as high if the proposal has a high relative density compared to the last chain link.\nHere we also see why we do not care about any integration constant, as the target density only appears as a ratio (line 4).\n\nClearly the results depend on the choice of the proposal density.\nA common pick are so called \\emph{random walk} proposals, which add some random number to the current position of the chain; for example a gaussian random walk proposal is given by $q(\\cdot \\mid x_t) = \\normal{\\cdot \\mid x_t, \\sigma^2}$ or equivalently stated $y = x_t + \\normal{0, \\sigma^2}$.\nSee \\citet{sherlock2010} for a recent survey on random walk proposals.\n\nThe simplicity of the algorithm is remarkable, but the main question is if the resulting Markov chain inherits favorable properties.\nAnd indeed this is the case.\nBy construction the algorithm creates Markov chains which are reversible with respect to $\\pi$ and aperiodic, and if additionally the proposal density is positive and continuous and $\\pi$ is finite then the chain is $\\pi$-irreducible; see for example \\citet{roberts2004}.\nThis tells us that under these regularity conditions a CLT holds for chains created using the Metropolis-Hastings algorithm.\nTo avoid using samples that do not come from the stationary distribution, in practice we choose $T$ very large and discard the first few (\\emph{burn-in}) samples.\n\nThe ability to sample draws in complex settings using the Metropolis-Hastings algorithm (and other Markov chain Monte Carlo methods for that matter) made Bayesian statistics applicable for real problems.\nStill, \\citet{Au2001EstimationOS} show that the classical Metropolis-Hastings algorithm is highly dependent on the proposal density and fails in higher dimensions; \\citet{zuev08} provide a geometric intution.\nNumerous novel methods which deal with dimensionality problems have been published.\nA particular promising route seems to be \\emph{Hamiltonian Monte Carlo} (\\citet{duane87}), which is one of the algorithms used in the probabilistc programming language STAN (\\citet{standev2018stancore}) with ongoing research on theoretical properties, see for example \\citet{betancourt2014geometric}.\n\n\n\\paragraph{Volume in Higher Dimensions.}\nClassical MCMC methods can have too slow convergence rates; In higher dimensions this might be due to probability mass being distributed very far from where it is expected (\\citet{betancourt2017convergence}).\nIn this paragraph we motivate this phenomenon and in the following we present methods which utilize it.\n\nLet $B_d$ denote the unit ball in $\\reals^d$ and define $C_d$ as the smallest cube containing $B_d$.\nWe consider two questions.\nFirst, how does the ratio $\\nicefrac{\\vol{B_d}}{\\vol{C_d}}$ change as $d$ increases.\nAnd second, how does the ratio of probability mass distributed by a standard gaussian on these regions change as $d$ increases.\nSince closed form expressions of volumina of geometrical objects exist the first questions needs little work.\nSimilarly we can easily compute $\\prob{X \\in C_d} = \\left[\\Phi(1) - \\Phi(-1)\\right]^d$, where $\\Phi$ denotes the one-dimensional gaussian cumulative distribution function.\nHowever, to compute $\\prob{X \\in B_d}$ we need to integrate over the unit ball with respect to a gaussian distribution, which is non-trivial.\nFor this reason we decide to report an upper bound, as this is sufficient for our motivation.\nIn particular we compute $\\overline{\\prob{X \\in B_d}} := \\sup_{\\bm{x} \\in B_d} \\phi(\\bm{x}) \\vol{B_d} = \\sup_{\\bm{x} \\in B_d} \\phi(\\bm{x}) \\int_{B_d}1 \\mathrm{d}\\bm{x} \\geqslant \\int_{B_d} \\phi(\\bm{x}) \\mathrm{d}\\bm{x} = \\prob{X \\in B_d}$.\nThe results of these computations are depicted in table \\ref{tab:vol_high_dim}.\nWe note that both ratios tend to zero very fast as $d$ increases.\nWith this phenomenon in mind one has to be cautious when working in high-dimensional spaces, since the regions of interest, that is the regions containing non-negligible probability mass, might not be located where our low-dimensional intution says.\nThis idea is formalized by the \\emph{Gaussian Annulus Theorem} (\\citet{blum2017foundations}; theorem 2.9) which states, inter alia, that most probability mass lies within an annulus centered at the origin with an average distance to the origin of $\\sqrt{d}$.\n\n\\begin{table}[ht]\n\\def\\arraystretch{1.3}\n\\centering\n \\begin{tabular}{c | c c c c c c c}\n $d$ & 1 & 2 & 3 & 5 & 7 & 10 & 15\\\\\n \\hline\n ${\\vol{B_d}} / {\\vol{C_d}}$ & 1.00000 & 0.78540 & 0.52360 & 0.16449 & 0.03691 & 0.00249 & 0.00001\\\\\n $\\overline{\\prob{X \\in B_d}} / {\\prob{X \\in C_d}}$ & 1.16874 & 1.07281 & 0.83589 & 0.35870 & 0.10995 & 0.01184 & 0.00012\n \\end{tabular}\n \\caption{Comparison of volume ratio of unit ball and cube, and probability ratio of gaussian falling in unit ball and cube for varying dimension $d$. Numbers are rounded to five decimal places.}\n\\label{tab:vol_high_dim}\n\\end{table}\n\nWe have seen some unintuitive behavior in higher dimensions which might explain why regular methods do not work or only work very slowly.\nThe next paragraph presents one method which utilizes this behavior to efficiently produce samples.\n\n\\paragraph{Hamiltonian Monte Carlo.}\nWe conclude our digression on Bayesian thinking by presenting \\emph{Hamiltonian Monte Carlo} (HMC), an innovative Markov chain Monte Carlo method from the statistical physics literature which works in higher dimensions  \\citet{duane87}.\nThere are of course multiple MCMC algorithms which work in higher dimensions with many more being actively developed.\nHere we focus on HMC as it is the main algorithm used in the probabilistic programming language STAN (\\citet{standev2018stancore}), which we will be using in our Monte Carlo study and application part.\n\nWe note that it is impossible to provide a rigorous introduction to HMC here, which is why we will focus on the general intution and refer to a series of papers by Michael Betancourt and several coauthors on, the geometric foundations of HMC (\\citet{betancourt2014geometric}); geometric ergodicity of HMC (\\citet{livingstone2016geometric}) and HMC for hiearchical models (\\citet{betancourt2013hamiltonian}).\\footnote{Besides doing theoretical research on HMC, Michael Betancourt worked for STAN on integrating the HMC algorithm and runs an educational blog where he presents his research using modern tools, see \\url{https://betanalpha.github.io/}.}\n\nOne reason why ordinary MCMC methods might converge only very slowly in higher dimensions is that the proposal distribution used in the Metropolis-Hastings algorithm does not properly capture the geometry of the high-dimensional space which leads to many rejected proposals and therefore an inefficient exploration of the parameter space.\nThe main idea of HMC is to extend the parameter space by constructing a specific vector field on it, which moves the chain from one proposed point to another in a way so that we consider points that lie in regions with high probability mass and we regulary jump to faw away points as to explore the space as quickly as possible.\nBut how do we construct this vector field?\nNote that when considering differentiable posterior densities the gradient defines a vector field.\nHowever, this vector field points to the modes of the posterior and as we saw in the last paragraph, in higher dimensions we will find little to no probability mass near the modes.\nThis is where Hamiltonian mechanics comes into play by providing a set of equations (Hamilton's equations) that describe the time-evolution of the interplay of kinetic and potential energy of a system.\nWhat this means for our case is best explained by imagining the mode as the center of gravity, with gravity pulling harder as we get closer to the mode ---this can be thought of as the gradient vector field.\nBut as most probability mass is spread around an annulus around the mode we do not want to move closer to the center of gravity, we want to move around an orbit around the mode.\nThe distance of the orbit to the mode and exact shape depend of course on the dimensionality and posterior distribution of the problem.\nHamilton's equations provide us with a way to construct a vector field so that moving along the field drifts the Markov chain into this orbit.\nOnce reached the chain explores the relevant space quickly.\n\nWhy is the above important?\nBayesian statistics and its application to real world problems has gained immense popularity with the invention of Markov chain Monte Carlo methods.\nIt's naive application to general complex high-dimensional problems is not computationally feasible however.\nThese problems are under active development and new approaches on the algorithmic and theoretical side, as the one presented above, prove fruitfull.\n", "meta": {"hexsha": "c38aba9e7a9b74882e60ab0ba4ac2f36b354bd90", "size": 36469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/ch1.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/ch1.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/ch1.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": 100.4655647383, "max_line_length": 649, "alphanum_fraction": 0.7620718967, "num_tokens": 9510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6466103490216777}}
{"text": "\\chapter{Mathematics}\nDigital signal processing is in general a very mathematical subject and audio- and musical signal processing is no exception to that rule. So it shouldn't come as a surprise, that many of the RAPT library functions rely on underlying algorithms that implement a considerable mathematical machinery. This chapter discusses some of the mathematical concepts that are relevant in the context of audio processing and shows how they are implemented in RAPT. The purpose here is mostly to explain, \\emph{what} the respective classes and functions do, not \\emph{how} they work internally. Most of the algorithms discussed in this chapter fall under the broad umbrella of numerical analysis. \nDetailed explanations and derivations can be found in the vast literature, specifically [Reference: Numerical Recipies] is a first class reference for such things.\n\n\\section{Complex Numbers}\nFor representing complex numbers, RAPT uses \\texttt{std::complex} from the C++ standard library.\n\n\\section{Functions}\nFor representing functions, RAPT uses \\texttt{std::function} from the C++ standard library ....maybe...this has to be decided\n\n\\section{Sequences}\nMathematically, a sequence is an ordered set of elements of some given type.\n\n\\section{Polynomials}\nA polynomial of a variable $x$ is a weighted sum of integer powers of $x$, starting at $x^0 = 1$ and going up to $x^N$. Polynomials play a central role in the theory of analog and digital filters and they occur in the context of interpolation, curve fitting and function approximation - that's reason enough for RAPT to devote them a dedicated class - which is unsurprisingly called \\texttt{Polynomial}. Mathematically, a polynomial $p(x)$ of order $N$ is defined as:\n\\begin{equation}\n\tp(x) = \\sum_{n=0}^N a_n x^n\n\\end{equation}\nwhere the $a_n, n=0,\\ldots,N$ are called the coefficients. An $N$th order polynomial has $N+1$ coefficients, ranging from index $0$ to index $N$. This is also the convention in which polynomial coefficient arrays are represented in RAPT - as length \\texttt{N+1} arrays \\texttt{a[0]}...\\texttt{a[N]}.  Consider the following code for multiplying the 2nd order polynomial $p(x) = 2 - 3 x + x^2$ by the 1st order polynomial $q(x) = -3 + 4x$ and evaluating the resulting polynomial $r(x)$ at $x = 2$:\n\\begin{lstlisting}\nPolynomial<int> p(2, 2, -3, 1), q(1, -3, 4);  // allocation, initialization\nPolynomial<int> r = p * q;                    // multiplication\nint y = r(2);                                 // evaluation\n\\end{lstlisting}\nThis code uses the high-level interface of the RAPT library. The first line creates the two polynomials (with integer coefficients). The first parameter of the constructor of the \\texttt{Polynomial} class is the order of the polynomial followed by an appropriate number of coefficients. The 2nd line multiplies the two polynomials which results in another polynomial which is stored in the variable \\texttt{r}. The third line produces a numeric output by applying the product polynomial $r$ to the value $x=2$. The code looks reasonably straightforward and readable by C/C++ standards. However, if you have to do polynomial multiplication in a context where performance is critical, for example inside a realtime audio callback, you probably don't want to have any dynamic memory allocations. But that's what the constructors of the \\texttt{Polynomial} class do. For performance and predictability reasons, you may want to operate on pre-allocated arrays, even if that means to uglify your code. In this case, your code could look something like this:\n\\begin{lstlisting}\n// pre-allocation and initialization:\nint p[3] = { 2, -3, 1};                  // 2nd order, 3 coeffs,  2 - 3x + x^2\nint q[2] = {-3,  4};                     // 1st order, 2 coeffs, -3 + 4x\nint r[4];                                // 3rd order, 4 coeffs\n\n// multiplication and evaluation:\nPolynomial<int>::mul(&p, 2, &q, 1, &r);  // multiply p, q, store result in r\nint y = Polynomial<int>::eval(&r, 3, 2); // evaluate polynomial r at 2\n\\end{lstlisting}\nFirst, we allocate the three arrays \\texttt{p, q, r} of lengths \\texttt{3, 2, 4} respectively. The order of the result polynomial \\texttt{r} is given by the sum of the orders of the factors $2+1=3$, so we need space for $4=3+1$ coefficients for the \\texttt{r} polynomial. The \\texttt{p, q} arrays are also initialized in this process. Then we call static member functions \\texttt{mul} and \\texttt{eval} of the \\texttt{Polynomial} class that operate on pre-allocated arrays of polynomial coefficients to perform the multiplication and evaluation. Arguably, the 2nd version is much less readable but these static member functions can be used whenever it is undesirable to have any dynamic memory allocations. Internally, the operators \\texttt{*} and \\texttt{()} of the \\texttt{Polynomial} class call the low-level routines on internally managed coefficient array member variables. This idiom of static member functions that are internally called from the non-static functions and operators on the instance variables of an object will be used throughout the library. It allows the low- and high-level interface to share the same code.\n\n\\section{Root Finding}\nRoot finding is the problem of finding one or more solutions of the equation:\n\\begin{equation}\n\tf(x) = 0\n\\end{equation}\nwhere $f(x)$ is, in general, an arbitrary function. Any value of $x$ that turns the equation into a true statement, when substituted for $x$, is called a solution or 'root' of the equation. In this problem setting, it is assumed that we have a means to evaluate the function at arbitrary values of $x$. In RAPT, the root finding algorithms must get such a means by passing them either function pointer to the respective function or a function object of class \\texttt{Functor}. Functors are objects that provide a means to evaluate a function at some point $x$. What makes them more flexible than plain functions is the fact that they can have internal instance variables which may affect the function evaluation. They can be seen as a general way to define families of functions with an arbitrary set of parameters. A polynomial is an example for such a functor where the parameters are the coefficients.\n\n\\subsection{Bisection}\nSuppose that, for two particular values $x=a$ and $x=b$, we know that $f(a)<0$ and $f(b)>0$. By assuming that the function is continuous between $a$ and $b$, that means that a root, i.e. a zero crossing, must be present somewhere between $a$ and $b$. The same is true, if $f(a)>0$ and $f(b)<0$. We say, the root is bracketed by the values $a$ and $b$. We may now evaluate the function at the midpoint between $a$ and $b$. If the value is equal to $0$, we have found our root, if it's less than $0$ or greater than $0$, we have found a new bracketing interval either to the left or to the right of the midpoint. The new bracketing interval is only half as long as the old one. Iterating that procedure, the brackets move closer and closer to the root. When their difference reaches a threshold, typically related to the numeric precision of the floating point datatype, we stop the iteration. It is then converged to the root (up to an error given by our threshold). Since the interval halves at each iteration, the number of correct binary digits in our approximate solution (given by the current midpoint) increases by one. Because the number of correct digits is a linear function of the iteration number, we say that the algorithm has a linear order of convergence. In RAPT, root finding by bisection is implemented in \\texttt{RootFinder::bisection}. As a subtle sidenote, it may make sense to choose the new evaluation point not exactly at the midpoint of the bracketing interval, but at [... tbc. Reference NR].\n\n\\subsection{Newton Iteration}\nNewton iteration is a method to iteratively improve an initial guess $x_0$ for the solution by iteratively applying the update rule:\n\\begin{equation}\n\tx_{n+1} = x_n - \\frac{f(x_n)}{f'(x_n)}\n\\end{equation}\nThis formula results from approximating the function $f(x)$ as a straight line that goes through the point $(x_0, y_0=f(x_0))$. This straight line is constructed to match the slope of the function $f(x_0)$ given by the derivative $f'(x_0)$ in the point $(x_0, y_0)$. The resulting line equation is then solved for the zero crossing of the line, which becomes our new root estimate $x_{n+1}$. Thus, to actually implement it, we also need a means to evaluate the derivative of $f(x)$ for any $x$ in addition to being able to evaluate the function $f(x)$ itself. The convergence of this iteration is typically quadratic, which means that in each iteration, the number of correct digits doubles [verify this] but in certain pathological cases it may be slower and in some cases, the iteration may even diverge. If a reasonable initial guess for the solution is available that is close to the true solution and the function is well behaved near the solution and we know how evaluate the derivative, Newton iteration is one of the methods of choice to converge to a true solution. In RAPT, Newton iteration is available in the function \\texttt{RootFinder::newton} which takes two function pointers or functors - one for the function itself and one for the derivative and also takes an initial guess and returns the refined value.\n\n\\subsection{Secant Method}\nThe secant method works similar to the bisection method, just that we choose the new evaluation point not as midpoint of our current bracketing interval $[a, b]$, but instead, we fit a straight line to the points $(a, f(a)), (b, f(b))$ and solve for the root of this straight line. The order of convergence is given by the golden ratio: $\\alpha = (1+\\sqrt{5})/2 \\approx 1.618$. So, it converges faster than the bisection method but not quite as fast as the Newton iteration. It can be seen as an approximation to Newton iteration, where the derivative is replaced by a finite difference approximation. On the plus side, it does not need to evaluate the derivative, which might be expensive or sometimes even not feasible. The method is available in \\texttt{RootFinder::secant}. Note that it may also diverge, since the new evaluation point may fall outside the initial bracketing interval.\n\n\\subsection{False Position}\nAlso known as 'regula falsi', this method is similar to the secant method, but it applies...\n\n%\\subsection{Fixpoint Iteration}\n%\\subsection{Brent's Method}\n%\\subsection{Ridders' Method}\n\n\\subsection{Roots of Polynomials}\nIf the function $f(x)$ is a polynomial, there are specialized algorithms for finding its roots. One such algorithm is the Laguerre algorithm which is implemented in \\texttt{Polynomial::roots(T *a, int N, complex<T> *r)}. It takes an array of \\texttt{N+1} coefficients as parameter and returns the roots in the length \\texttt{N} array \\texttt{r}. The fundamental theorem of algebra tells us that each polynomial of order $N$ has exactly $N$ roots such that it can be expressed as:\n\\begin{equation}\n  \\label{Eq:PolynomialProductForm}\n\tp(x) = k \\prod_{n=1}^N (x - r_n)\n\\end{equation}\nthat is, a scaled product of the differences between $x$ and the respective root $r_n$. Remember that a product is zero, if and only if (at least) one of its factors is zero, so if $x$ is equal to one of the roots $r_n$, the corresponding factor $x - r_n$ in the product is zero, making the whole product zero - which verifies that $r_n$ is a root, indeed. These roots, however, may not be unique - some of them may have a multiplicity, i.e. occur more than once in the above product. Some of the roots may also be complex. If the coefficients of the polynomial are real, complex roots will always come in pairs of complex conjugate numbers. In audio applications, we will mostly deal will polynomials that have real coefficients. For generality, however, there's also a version of the polynomial root finder that takes an array of complex coefficients. Internally, the same algorithm is used anyway, no matter if the coefficients are real or complex. For example, the roots of the $5$th order polynomial $p(x) = 1 + 2 x - 3 x^2 + 3 x^4 - x^5$ can be found via:\n\\begin{lstlisting}\nvector<complex<double>> r(5);\nr = Polynomial<double>(5, 1., 2. -3., 0., 3., -1.).roots();\n\\end{lstlisting}\nor, alternatively using the low-level routine that operates on pre-allocated arrays:\n\\begin{lstlisting}\ndouble a[6] = { 1., 2. -3., 0., 3., -1. };\ncomplex<double> r[5];\nPolynomial<double>::roots(a, 5, &r);\n\\end{lstlisting}\nA function for getting from the roots back to the coefficients is also available via the function \\texttt{Polynomial::fromRoots}. In addition to the $N$ roots, it also needs the value of the overall scaling constant $k$ in Eq. \\ref{Eq:PolynomialProductForm}. This is simply the $N$th coefficient, but in case you forget that, the \\texttt{Polynomial} class has also the function \\texttt{productFormScaler(int N, T a)} which trivially just returns \\texttt{a[N]}. Since the \\texttt{Polynomial} class is a subclass of class \\texttt{Functor}, the general root finders from above can be applied for polynomial root finding as well. They can, however, find only one root at a time and you need an initial guess or bracketing interval.\n% reconstructing the coefficients form the roots\n\n\n\\section{Rational Functions}\nA rational function is a quotient or 'ratio' of two polynomials:\n\\begin{equation}\n\tr(x) = \\frac{\\sum_{m=0}^M b_m x^m} {\\sum_{n=0}^N a_n x^n}\n\\end{equation}\nwhere $M$ is the order of the numerator and $N$ is the order of the denominator. All realizable analog and digital filter transfer functions are functions of this very type - which explains the special significance of rational functions, and hence polynomials, in the field of signal processing. The roots of the numerator are called the zeros of the transfer function and the roots of the denominator are called the poles. Since the denominator is zero at these poles, the value of the rational function at these points goes to infinity, unless there's a corresponding zero in the numerator at exactly the same point to cancel the pole. RAPT provides the class \\texttt{RationalFunction} to deal with rational functions.\n\n\\subsection{Partial Fraction Decomposition}\nAny rational function can be expanded into the form of a sum of a polynomial and several first order rational functions, in which the numerator is a  constant (called the residue which is possibly complex) and the denominator is a linear function of $x$. That is:\n\\begin{equation}\n\tr(x) = \\frac{\\sum_{m=0}^M b_m x^m} {\\sum_{n=0}^N a_n x^n}\n\t     = \\sum ...\n\\end{equation}\nIf the coefficients of the original numerator and denominator polynomial are both real, complex values for the numerators and denominators in the expanded form come in conjugate pairs, such that 1st order terms can be combined pairwise into 2nd order terms with real coefficients. In signal processing applications, such decompositions amount to decomposing a direct form filter into a parallel connection of the respective 1st or 2nd order filters and an FIR part, where the latter results from the polynomial part. Because the individual terms are easier to understand and analyze, partial fraction decompositions play a role in certain filter analysis applications. For example, they are required for finding closed form expressions of a filter's impulse response. This impulse response is given by the inverse $z$-transform of its transfer function, but inverse $z$-transforms are only available for low-order terms - which is precisely what the decomposition delivers. Partial fraction decomposition is available in RAPT via \\texttt{RationalFunction::partialFractions}.\n\n\n\\section{Vectors}\n\\section{Matrices}\n\n\\section{Transforms}\nTransforms are - together with filters - one of the mainstays in the field of signal processing. Consider an $N$ dimensional vector $\\mathbf{x}$ which may represent a (segment of a) signal. A general transform would take that vector as input and produce a new vector $\\mathbf{y}$ as output. If the transform is designed well, the transformed vector $\\mathbf{y}$ may reveal relevant features of the signal that are hard to see in the original representation. An important concern is invertibility - we want to be able to reconstruct the original vector $\\mathbf{x}$ from the transformed vector $\\mathbf{y}$ by some kind of associated inverse transform. Given such a pair of a transform and its inverse, we could transform an input vector, modify the transformed representation and apply the inverse transform to get a modified output vector/signal. A good transform in an audio processing setting would be one, that allows for convenient modifications that closely relate to modifications of perceptual, auditory attributes of the signal. We will consider mainly linear transforms. These are the class of operations on our input vector $\\mathbf{x}$ that can be expressed as a matrix-vector multiplication of an  $N \\times N$ matrix $\\mathbf{A}$ with our input vector $\\mathbf{x}$:\n\\begin{equation}\n\t\\mathbf{y} = \\mathbf{A} \\mathbf{x}\n\\end{equation}\nIf the matrix $\\mathbf{A}$ is non-singular, there will be an inverse matrix $\\mathbf{A}^{-1}$ and hence, there will be an inverse transform, given by:\n\\begin{equation}\n\t\\mathbf{x} = \\mathbf{A}^{-1} \\mathbf{y}\n\\end{equation}\nAlternatively to thinking in terms of an $N$ dimensional vector $\\mathbf{x}$, we may also consider the inputs and outputs as sequences of length $N$, which, in this context, can be seen as merely a different name for the same thing - a finite, ordered set of $N$ numbers.\n\n\\subsection{Discrete Fourier Transform}\nThe discrete Fourier transform (DFT) of a length $N$ sequence $x_0, \\ldots, x_{N-1}$ is another length $N$ sequence $X_0, \\ldots, X_{N-1}$ in which each element $X_k$ can be computed by the formula:\n\\begin{equation}\n\tX_k = \\sum_{n=0}^{N-1} x_n W_N^{k n}, \\qquad \\text{where }W_N = e^{-j \\frac{2 \\pi}{N} }\n\\end{equation}\nexpressed as matrix-vector product, this looks like:\n\\begin{equation}\n\t...\n\\end{equation}\nComputing a product of an $N \\times N$ matrix and an $N$ vector in general requires $\\mathcal{O}(N^2)$ operations, because we have to form $N^2$ individual products between numbers. In the DFT matrix, however, not all elements are distinct. This redundancy of the matrix elements allows for an algorithmic shortcut, known as the fast Fourier transform (FFT) which requires only $\\mathcal{O}(N \\cdot \\log N)$ operations. Fast Fourier transforms are particularly efficient when $N$ is a power of two - these transforms are known as radix-2 FFTs. There are also $\\mathcal{O}(N \\cdot \\log N)$ algorithms for arbitrary $N$, for example, the Bluestein FFT algorithm which uses a radix-2 algorithm on a zero-padded sequence internally. In RAPT, both radix-2 and Bluestein FFTs are available via the functions \\texttt{Transforms::fftRadix2} and \\texttt{Transforms::fftBluestein}. There's also the function \\texttt{Transforms::fft} which tests, if $N$ is a power of two and then dispatches between the radix-2 and the Bluestein algorithm accordingly.\n\n\\subsubsection{Inverse Transform}\n\n\n\n\n\\subsection{Short Time Fourier Transforms}\n\n\\subsection{Wavelet Transforms}\n\n\\section{Statistics}\nStatistical signal measures such as the mean value, the autocorrelation sequence or the crosscorrelation sequence (between two signals) play an important role in many signal analysis algorithms and in adaptive filters. ...\n\n\\section{Interpolation}\nAssume that we have a certain number $N$ of pairs of abscissa/ordinate values $(x_n, y_n), n = 0, \\ldots, N-1$ represented as length \\texttt{N} arrays \\texttt{x} and \\texttt{y}. We imagine these data points as a table that represents a continuous function and we assume that the $x$-values are in strictly ascending order. The goal of interpolation is to create a continuous function from the discrete data. That means, interpolation would connect the points by assigning a $y$-value to \\emph{any} $x$-value between \\texttt{x[0]} and \\texttt{x[N-1]}. If we try to find a $y$-value for an $x$-value outside this range, it's called extrapolation. In RAPT, a continuous interpolating (and extrapolating) function is represented as an \\texttt{Interpolator} object which itself is subclassed from \\texttt{Functor}. This implies that the root-finding algorithms can be applied to interpolating functions in the same way as they are applied to regular functions. In the context of audio processing, interpolation may be required for obtaining signal values between the actual sample values or for creating smooth curves of control-data for which values are available only at certain time instants but not at each sample instant.\n\n\\subsection{Linear Interpolation}\nA very simple way of interpolating between datapoints is to connect the datapoints with straight lines. \n%It's not suitable for high-quality audio interpolation (unless, maybe, in combination with oversampling) but it has its place for interpolating control data. A feature that is sometimes desirable is that is preserves the mean value - i.e. the mean value of the interpolated \\texttt{y}-array equals the mean of the original \\texttt{y}-array [verify]\n%The only form of interpolation that is even more crude would be piecewise constant interpolation which just returns the $y$-value of the nearest neighbour. \n\n\\subsection{Lagrange Interpolation}\nLagrange interpolation takes a given number $N$ of datapoints and constructs an $N$th order polynomial that passes exactly through these points. Such an interpolating polynomial tends to oscillate wildly between the actual datapoints, especially if the order of the polynomial is high. In most application, such oscillations are undesirable and that's why Lagrange interpolation is mostly used only with low orders. In certain audio applications, however, these oscillations might actually be exactly what is needed - as the order of the Lagrange interpolator goes up, it approaches the optimal sinc-interpolator [Reference: 'Elephant interpolators']\n\n\\subsection{Spline Interpolation}\n\n\n\\subsection{Sinc Interpolation}\n\n\n\n\\section{Numerical Differentiation}\n\n\\section{Numerical Integration}\n\n\\section{Differential Equations}\nDifferential equations are the main tool for describing physical systems mathematically. They relate an unknown function $f(x)$, which is to be found, to its own derivatives $f'(x), f''(x), \\ldots$. If the function $f$ is a function of only one independent variable, we have an ordinary differential equation. There are also so called partial differential equations which are differential equations for a function of several independent variables, say $f(x,y,\\ldots)$, and an equation in terms of the partial derivatives $\\partial f / \\partial x, \\partial f / \\partial y, \\ldots$ is given. Sometimes, such differential equations can be solved analytically in the sense that an explicit expression for $f(x)$ in terms of $x$ can be given. Often, however, such an analytic solution is not feasible and we must resort to numerical algorithms to find the behavior of the system in a particular situation. In the context of audio processing, ordinary differential equations are typically used to describe electronic circuits such as analog filters, dynamics processors, etc.. Partial differential equations occur in the modeling of acoustic systems like vibrating strings, plates, air columns, etc..\n\n\\subsection{Ordinary Differential Equations}\n\n\\subsection{Partial Differential Equations}\n\n\n\\section{Curve Fitting}\n\n\\section{Optimization}\n\n", "meta": {"hexsha": "d3cdc59d6d2a5da63d79c539e59a703a8f5918a3", "size": 23522, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/RAPT/LaTeX/UserManual/Mathematics.tex", "max_stars_repo_name": "RobinSchmidt/RS-MET-Preliminary", "max_stars_repo_head_hexsha": "6c01cbaad7cce3daa3293c444dd9e4b74e5ebfbe", "max_stars_repo_licenses": ["FTL"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-04-19T18:26:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T17:47:26.000Z", "max_issues_repo_path": "Documentation/RAPT/LaTeX/UserManual/Mathematics.tex", "max_issues_repo_name": "RobinSchmidt/RS-MET-Preliminary", "max_issues_repo_head_hexsha": "6c01cbaad7cce3daa3293c444dd9e4b74e5ebfbe", "max_issues_repo_licenses": ["FTL"], "max_issues_count": 307, "max_issues_repo_issues_event_min_datetime": "2017-05-04T21:45:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T00:59:01.000Z", "max_forks_repo_path": "Documentation/RAPT/LaTeX/UserManual/Mathematics.tex", "max_forks_repo_name": "RobinSchmidt/RS-MET-Preliminary", "max_forks_repo_head_hexsha": "6c01cbaad7cce3daa3293c444dd9e4b74e5ebfbe", "max_forks_repo_licenses": ["FTL"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-09-05T17:04:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T21:24:28.000Z", "avg_line_length": 135.9653179191, "max_line_length": 1516, "alphanum_fraction": 0.7723833007, "num_tokens": 5600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6466103244623423}}
{"text": "\\section*{Preliminaries}\n\\begin{itemize}\n  \\item [natural number:] $\\naturalNumber = 0, 1, 2, 3, \\dotsc, \\infty$\n    \\begin{itemize}\n    \\item $\\naturalNumber_0 = 0, 1, 2, 3, \\dotsc, \\infty$\n    \\item $\\naturalNumber_1 = 1, 2, 3, \\dotsc, \\infty$\n    \\end{itemize}\n\n  \\item [integer number:] $\\integerNumber = -\\infty, \\dotsc, -2, -1,\n    \\naturalNumber$\n  \\item [real number:] $\\realNumber = (-\\infty, \\infty) $\n  \\item [imaginary number:] $i = \\sqrt{-1}$\n  \\item [complex number:] $\\complexNumber = a + ib = Ae^{i\\theta}$\n    \\begin{itemize}\n    \\item $a, b \\in \\realNumber$\n    \\item $A = \\sqrt{a^2 + b^2}$\n    \\item $\\theta = \\arctan(b/a)$\n    \\end{itemize}\n\\end{itemize}\n\n", "meta": {"hexsha": "db3e953de1c9000eb84a6c8aabfc04452d80aef1", "size": 676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Mathematics/units/unit_Basics.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/Mathematics/units/unit_Basics.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/Mathematics/units/unit_Basics.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.1904761905, "max_line_length": 71, "alphanum_fraction": 0.5887573964, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6465764515652836}}
{"text": "\\chapter{Estimation Theory}\\label{App:estimation}\nThe Bayesian definition requires knowledge of the posterior probability on $\\theta$, that is, $pr(\\theta|g)$.  The Bayesian regards $\\theta$ as random, but has no concept of an ensemble of $g$ vectors; the data are fixed.  \nEstimates are statistical quantities, hence their evaluation requires statistical methods.\nBayesian estimation is the determination of an estimate of a random $\\theta$ through minimization of the Bayes risk.  Knowledge of $pr(\\theta)$ is assumed, and a cost function $C(\\hat{\\theta}, \\theta)$ must be specified.   The EMSE (Ensemble mean-squared error) is a common form for the cost measure $C(\\hat{\\theta}, \\theta)$ to be minimized in the design of an estimation procedure.\n\nThe quantity $pr(\\theta|g)$ describes the posterior probability of $\\theta$ after the data $g$ are obtained; thus the estimation rule $\\hat{\\theta} = \\arg\\max_{\\theta} pr(\\theta|g)$ is known as maximum a posteriori, or MAP, estimation.  Equivalently, the MAP estimate is the mode of the posterior, or the posterior mode.\n\nInterestingly, MAP estimation is often what is meant in the literature on Bayesian estimation, However, MAP estimation is just a special case of Bayesian estimation in which the particular form of the cost function is a uniform cost function given by:\n\n\\begin{equation}\nC(\\hat{\\theta}, \\theta) = C(\\hat{\\theta}-\\theta) = 1 - rect \\left( \\frac{\\hat{\\theta}- \\theta}{2\\epsilon}   \\right)\n\\end{equation}\n\nThe uniform cost function is when the cost is considered negligible if smaller than some tolerance $\\epsilon$, and all estimator errors beyond that tolerance are regarded as equally costly.\nAnother way of interpreting MAP estimation is that $pr(\\theta)$ characterizes the prior uncertainty in the parameter, which is often subjective in nature.  Then $pr(\\theta|g)$ is the (presumably reduced) uncertainty after data are collected, hence the term posterior.\n\nMaximum-likelihood or ML estimation uses the following rule to determine the underlying parameters:\n\\begin{equation}\n\\hat{\\theta}_{ML} \\equiv \\arg\\max_{\\theta} pr(g|\\theta)\n\\end{equation}\nThis procedure can be written equivalently as:\n\\begin{equation}\n\\hat{\\theta}_{ML} = \\arg \\max_{\\theta} ln \\left[ pr)g|\\theta \\right].\n\\end{equation}\nML estimation can be considered as a limit to MAP estimation when the prior $pr(\\theta)$ is sufficiently broad that $pr(g|\\theta) pr(\\theta)$ is dominated by $pr(g|\\theta)$.  However, ML estimation is much more than a limiting form of MAP estimation.\nIn ML estimation, $pr(g|\\theta)$ is the quantity being maximized, but even in MAP estimation its role has some level importance that depends on the relative weight of the prior.  The quantity $pr(g|\\theta)$ means different things to different people.  The frequentist interpretation is that it is a function of $g$ for fixed $\\theta$.  Repeated observations can be used to determine the nature of this quantity for a given underlying object (parameter vector).  Alternatively, $pr(g|\\theta)$ can be viewed as a function of $\\theta$ for fixed $g$.  In this viewpoint $pr(g|\\theta)$ is a measure of the likelihood of any $\\theta$ once that data are in hand.  \n\\begin{itemize}\n\\item frequentist approach: what are all $g$'s that is produced by a single $\\theta$?\n\\item viewing $pr(g|\\theta)$ as a function of $\\theta$ for fixing g; or what are all $\\theta$'s that can produce identical $g$.\n\\end{itemize}\n\n\\noindent\n\\textbf{Score}: \\medskip The \\textit{score} is a random vector that tells us how sensitive the likelihood is to change in the parameters:\n\\begin{equation}\ns(g) = \\frac{\\frac{\\partial}{\\partial \\theta} pr(g|\\theta}{pr(g|\\theta)} = \\frac{\\partial}{\\partial\\theta} In \\left[ pr(g|\\theta) \\right]\n\\end{equation}\n\nIn words, the score is the gradient of the log-likelihood. Since the score is a function of the log-likelihood, which is a random variable through its dependence on $g$, the score is also random.  Note that $\\langle s \\rangle_{g|\\theta} = 0$, where $\\langle \\cdot \\rangle_{g|\\theta}$ denotes an average with respect to $pr(g|\\theta)$. Score is a zero-mean random vector.\nAs the gradient of the log-likelihood, $s(g, \\theta) = 0$ when $\\theta = \\hat{\\theta}(g)$.  The process of finding the ML estimate is thus equivalent to determining the point in parameter space where all components of the score vanish.\n\nML estimator is efficient, where if the Cramer-Rao lower bound on the variance is attainable, it will be attained by an ML estimator.\nML estimator is sufficient.  In estimation, a sufficient statistic is one that captures all the essential features in the data necessary for optimal performance of a given estimation task.  The maximum-likelihood estimator is a sufficient statistic for estimation; it makes optimal use of the information in the data.  No other estimator can yield more information.  \nA necessary and sufficient condition for $\\hat{\\theta}$ to be a sufficient estimate is that the likelihood function must be factorable into the product:\n\\begin{equation}\npr(g|\\theta) = pr(\\hat{\\theta}|\\theta) f(g),\n\\end{equation}\nwhere $f(g)$ is independent of $\\theta$.  \nA sufficient estimator may exist even when an efficient estimator does not; efficiency is a stricter criteria than sufficiency.  A sufficient estimator is unique; we can use a function of the sufficient statistic because it will also be sufficient, and we can choose it such that the estimate maybe be consistent and unbiased.\nIn general there can be many solutions to ML estimation equation that give equal likelihood.  This is especially the case in high-dimensional problems, where null space can be very large.  \nAsymptotic properties of the ML estimator.  It describes the behavior of the estimate as the number of observations approaches infinity.  Cramer proved that, under reasonably general conditions, an ML estimate is consistent.  The density function for a consistent estimate becomes increasingly narrow about the value of the underlying parameter as the number of samples increase.  ML estimate is efficient, if an efficient estimator exists.  ML estimates achieve the equality sign in the bound as the number of samples goes to infinity; that is, ML estimates are asymptotically efficient.\nML estimates are asymptotically unbiased, efficient, normally distributed and consistent.\n\nSummarize: The full Bayesian estimation approach requires that the cost function as well as the prior probability of the random parameters and their likelihood function be completely specified. The ML approach does not require a prior, but it still requires full knowledge of the likelihood function. \n\n\\noindent\n\\textit{Bayesian and frequentist:}\nIn both pure estimation problems and hybrid detection/estimation problems, we have found that the optimal strategy for handling nuisance parameters is to marginalize (to treat as insignificant or peripheral) rather than to estimate them.  This finding begs the question of the appropriate prior to utilize.  To a frequentist, the prior should be a sampling prior, verifiable by experiment; an example is the exponential absorption law for photons.  To a Bayesian, the prior could incorporate prior beliefs.  Indeed, a Bayesian would say that the problem of nuisance parameters is an example of a fundamental dilemma that arises in any inference problem: we \\textit{never} have enough empirical (verifiable by observation or experience rather than theory or pure logic) information to solve the problem at hand, and we must always bring in prior belief.  \nYes, one can use prior beliefs in estimation problems in imaging, but the final measure of the efficacy of the belief is a long-run, frequentist measure of task performance.", "meta": {"hexsha": "20f6d297d7aafffbb54116ac11a7d5ac75429921", "size": 7699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/estimation_theory.tex", "max_stars_repo_name": "hfan36/dissertation", "max_stars_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_stars_repo_licenses": ["MIT"], "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/estimation_theory.tex", "max_issues_repo_name": "hfan36/dissertation", "max_issues_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_issues_repo_licenses": ["MIT"], "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/estimation_theory.tex", "max_forks_repo_name": "hfan36/dissertation", "max_forks_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 132.7413793103, "max_line_length": 854, "alphanum_fraction": 0.7777633459, "num_tokens": 1736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6465663894751604}}
{"text": "\\lab{Sparse Grids}{spgrid}\n\\label{lab:spgrid}\n\n\\objective{Sparse Grids are an important tool when dealing with high-dimensional problems.  Computers operate in discrete space, not in continuous space.  It is important to choose evaluation points wisely so as to maximize accuracy without sacrificing computation time.  In particular, we explore how to use sparse grids to compute integrals of high dimensionality.}\n\n\\section*{Discretization}\nAt first inspection, our world appears to be nice and continuous.  However, this only works on a macroscopic level.  As we zoom in on matter, we find that it is made of discrete atoms with much empty space between.  Computers likewise work in discrete space.  You have already seen many examples of this.  Consider plotting the function $y=x^2$, such as in Figure \\ref{fig:x_squared}.  To do this we take an array of discrete points of $x$ and $y$ values, which are then joined in a linear manner.  As you either zoom in on the function or decrease the number of plotting points, you can see the discrete nature of even this simple function.\n\nIn order to get better results, we need to use a larger number of points.  This is true not just for graphing purposes, but also for standard computation.  If we double the number of points, we approximately double the computation time necessary.  This effect, while not irrelevant, pales in comparison to the case when working in multiple dimensions.  Imagine a function that we discretize into $20$ points.  A similar function of two variables, where each variable is discretized into $20$ points, would necessitate $400$ unique points.  Expanding to seven variables would necessitate $1,280,000,000$ unique points!\n\nIn general, for $n$ discrete points in $d$ dimensions, this gives $n^d$ points.  This can be visualized as a $d$-dimensional grid of size $n \\times n \\times \\cdots \\times n$. In practice, we seldom need to know the value for each and every point.  Instead of using the full grid, we can use a sparse grid.  The main idea of a sparse grid is that it can reduce the order of difficulty for a standard $d$-dimensional problem.\n\n\\begin{center}\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{x2.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{x2a.png}\n\\end{subfigure}\n\\caption{Plots of the function $y=x^2$ using $31$ points and $9$ points, respectively.  In the $9$-point plot, the linear, discrete nature of the function is easily visible.}\n\\label{fig:x_squared}\n\\end{figure}\n\\end{center}\n\n\\section*{The Hierarchical Basis}\nThe basic sparse grid is based on the use of the \\emph{Hierarchical Basis}.  This basis is composed of piecewise-linear functions known as the \\emph{standard hat functions}, and can be used to approximate any function.  The standard hat function in one dimension is defined as:\n\n\\begin{equation}\n\\phi(x) = \\left\\{\n        \\begin{array}{ll}\n            1-\\abs{x} & \\quad -1 \\leq x \\leq 1 \\\\\n            0 & \\quad otherwise\n        \\end{array}\n    \\right.\n\\end{equation}\n\nFrom this equation, we can build the set of basis functions of order $j$\n\n\\begin{equation}\n\\phi_{j,i}(x) = \\phi(2^{j-1}(x+1) - 2i+1)\n\\end{equation}\n\n\\begin{center}\nwhere $i=1,2,3,\\cdots,2^{j-1}$.  \n\\end{center}\n\nThe first few basis functions are listed in Table \\ref{table:functions}, and are plotted in Figure \\ref{fig:basis_functions}.\n\n\\begin{center}\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{j1.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{j2.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{j3.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{j4.png}\n\\end{subfigure}\n\\caption{Plots of the first few standard hat functions.  Note that the value of $j$ gives the number of \"hats\" in the domain $[-1,1]$, and $i$ gives which hat, counting from the left-most hat.}\n\\label{fig:basis_functions}\n\\end{figure}\n\\end{center}\n\n\\begin{center}\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\n$j\\backslash i$ & $1$ & $2$ & $3$  & max $i$ \\\\ \\hline\n$1$ & $\\phi_{11}(x) = \\phi(x)$ & & & 1 \\\\ \\hline\n$2$ & $\\phi_{21}(x) = \\phi(2x+1)$ & $\\phi_{22}(x) = \\phi(2x-1)$ & & 2\\\\ \\hline\n$3$ & $\\phi_{31}(x) = \\phi(4x+3)$ & $\\phi_{32}(x) = \\phi(4x+1)$ & $\\phi_{33}(x) = \\phi(4x-1)$ & 4 \\\\ \\hline\n$4$ & $\\phi_{41}(x) = \\phi(8x+7)$ & $\\phi_{42}(x) = \\phi(8x+5)$ & $\\phi_{43}(x) = \\phi(8x+3)$ & 8 \\\\ \\hline\n$5$ & $\\phi_{51}(x) = \\phi(16x+15)$ & $\\phi_{52}(x) = \\phi(16x+13)$ & $\\phi_{53}(x) = \\phi(16x+11)$ & 16 \\\\ \\hline\n\\end{tabular}\n\\caption{The first few standard hat functions that make up the hierarchical basis, for $i\\leq3$.}\n\\label{table:functions}\n\\end{center}\n\\end{table}\n\\end{center}\n\nUsing these basis functions, we can approximate any function of our choosing.  Suppose we want to solve\n\\begin{equation*}\n\\int_{-1}^{1} \\sqrt{1-x^2}\\: dx .\n\\end{equation*}\nThis is the area of a semi-circle of radius $1$, and can easily be computed mathematically as $\\pi / 2 \\approx 1.57079632679$.  But a computer does not calculate this in the same manner.  Instead, it uses certain points to evaluate the integral numerically.  We can approximate $f(x) = \\sqrt{1-x^2}$ by interpolating the basis hat functions.  If we approximate up to order $l$ then this gives\n\\begin{equation*}\nf(x) \\approx \\sum_{n=1}^l \\sum_{m=1}^{2^{n-1}} c_{nm} \\phi_{nm}(x) \n\\end{equation*}\nwhere $c_{nm}$ are the appropriate constants which can be found by evaluating the difference between $f(x)$ and the sum of the basis hat functions of lower order at the peak of each hat:\n\\begin{equation}\nc_{nm} = f(p_{nm}) - \\sum_{s=1}^{n-1} \\sum_{t=1}^{2^{s-1}} c_{st}*\\phi_{st}(p_{nm})\n\\end{equation}\nwhere\n\\begin{equation}\np_{nm}=2^{2-n}*(m-0.5)-1\n\\label{eq:points}\n\\end{equation}\nand $p_{nm}$ is the peak of the $m^{th}$ hat of level $n$.  These points will be important because we will use these to create the basic sparse grid.\n\n\\begin{center}\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{HB.png}\n\\caption{Interpolating a function using the standard hat basis functions.}\n\\label{fig:HB}\n\\end{figure}\n\\end{center}\n\nOne benefit of decomposing $f(x)$ into the basic hat functions is that they are extremely simple to integrate.  Each is a triangle, for which $A=bh/2$.  The height is $1$, and the base is $2^{2-n}$, and so\n\\begin{equation*}\n\\int_{-1}^1 \\phi_{nm} dx= 2^{1-n}\n\\end{equation*}\n\nOne problem with using the basic hat functions to approximate a function arises when the function does not go to zero at the endpoints.  Higher order approximations yield better results, but ultimately we need to decide how accurate we need our answer to be.  When an additional level changes the answer by less that our error tolerance, we have found a good level of approximation.\n\n \\begin{problem}\nUse the function declaration below to approximate a given function on $[-1,1]$ with the basic hat functions up to order $l$:\n\\begin{lstlisting}\ndef hat_approximation(f,l):\n    \"\"\"This function will return a list of the correct coefficients to approximate the function f up to level l.\n    Parameters\n    ----------\n        f (function) : The function of a single variable to approximate\n        l (int) : The order to use for interpolating the hat function\n\n    Returns\n    -------\n        coeffs (list) : Entry n is an ndarray of len(2^(n-1)) and contains the coefficients for phi_{nm}.  The length of this should be l.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\label{prob:one}\n\\end{problem}\n\n\n\\begin{center}\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{errors.png}\n\\caption{}\n\\label{fig:errors}\n\\end{figure}\n\\end{center}\n\n\\begin{problem}\nWrite a function that, given the coefficients returned by the function in Problem \\ref{prob:one}, returns the value of the integral.\n\\end{problem}\n\n\\begin{problem}\nUsing the function $f(x)=\\sqrt{1-x^2}$, calculate the error of $\\int_{-1}^1 f(x)$ in regards to the actual value $\\pi/2$.  Do this for the order $l = 1,2,\\cdots,10$, and plot the error as a function of $l$.  Your results should match Figure \\ref{fig:errors}.  Additionally, time how long it takes to execute the code for each $l$, and plot your results in another graph.\n\\end{problem}\n\nKeep in mind that thus far we have only used a function of one variable.  For each variable (dimension) the time to compute will increase exponentially.   With multiple dimensions, it becomes infeasible to compute to any degree of accuracy, because the time to compute will increase much too quickly to be reasonable for higher dimensions.  Hence the need for sparse grids.\n\n\\section*{Sparse Grids}\nRather than dividing each dimension into $n$ sections, which for $d$ dimensions would give $n^d$ points, sparse grids use only a few of these points.  There are many types of sparse grids, and each is useful for certain purposes.  Which type of sparse grid is used will often depend on the nature of the problem you are trying to solve.  For this lab, we will use the basic sparse grid for purposes of integration.\n\nThe basic sparse grid has two main properties, the dimension and the level.  Using these two variables and Equation \\ref{eq:points}, we can construct a sparse grid.  Visualizing this in one dimension is simple: we use as our evaluation points each $p_{nm}$.  A level $1$ grid has one point at the center, which is the peak of the level $1$ hat.  A level $2$ grid has the level $1$ point with two level $2$ points, which are the peaks of the two level $2$ hats.  The third level adds its $4$ points, etc.  So for one dimension of level $l$ we have $\\sum_{i=1}^l 2^{i-1}$ points.\n\nUnderstanding a $2$-dimensional grid  is a bit more complicated.  Our level $1$ point goes at the center of the grid.  To expand to level $2$, we add in the peaks of the level $2$ hats \\emph{in both dimensions}, for an additional $4$ points.  Level $3$ is where it gets a little bit tricky mathematically.  We can't just keep expanding only along the axes of the grid, because we need points on the interior as well.  Conceptually, what we do is take our current points and divide the space between points and the end of the grid into two, and there we create a new point.  This is synonymous to adding a hat between the peaks of currently existing points.\n\nWe can make a lot more sense of that last paragraph by actually plotting the points.  The file \\li{pysg.py} contains a sparse grid class with many useful functions.  Using \\li{plotGrid}, you can plot the grid points.  You will first need to create a sparse grid object, and then generate the points using the built in function.  Unfortunately, \\li{plotGrid} can only plot up to three dimensions.  Note that in this file, our domain is $[0,1]^d$ rather than $[-1,1]^d$.  \n%Be sure to take note of this when computing the integrals in the following problem.  \n\n\\begin{center}\n\\begin{figure}\n% \\includegraphics[width=.7\\textwidth]{gridpoints.png}\n\\caption{Sparse grid points for 2-D grid of level 5}\n\\label{fig:gridpoints}\n\\end{figure}\n\\end{center}\n\n% THIS FILE IS NOT IN THE REPOSITORY!!\n\n\n\n\\begin{problem}\nExplore the \\li{sparseGrid} class contained in the module \\li{pysg.py}. Figure out how to create a sparse grid object, generate the points, and plot them. This function should plot the sparse grid points for a grid of dimension 2 and level 5. See the figure above.\n\\end{problem}\n\n\n\nMulti-dimensional integration for functions with independent endpoints (those that are numbers that do not depend on other variables) is simplified greatly by using sparse grids.  Functions must be manipulated appropriately before sparse grid classes like those in \\li{pysg.py} can be used to do the integration, but once this has been done, their evaluation becomes rather simple.  Once the coefficients for the hat functions have been computed, the integrals can be evaluated without having to perform any integration.  Sparse grids are powerful tools for fast computation of high-dimension integrals.  \n%In general, note that\n%\\begin{equation*}\n%\\int_{a_1}^{b_1} \\int_{a_2}^{b_2} \\cdots \\int_{a_d}^{b_d} \\phi_{sii\\cdots i}dx_d dx_{d-1} \\cdots dx_1= \\frac{\\prod_{i=1}^d (b_i-a_i)}{2^{(s-1)d}*(d+1)}\n%\\end{equation*}\n\n%\\begin{problem}\n%Using the sparse grid class in \\li{pysg.py}, compute the value of the following integrals:\n%\\begin{enumerate}\n%\\item $\\int_{0}^1 \\int_{0}^1 (x^2+\\frac{1}{3}xy) \\ dx dy \\ $ to order 8.\n%\\item $\\int_{.36}^{1.8} \\int_{0}^{\\pi} y*cos(x) \\ dx dy \\ $ to order 6.\n%\\item $\\int_{-2}^3 \\int_{5}^6 \\int_{4.2}^{6.3} (\\frac{1}{43}x+\\frac{1}{123}x^2 y^3 + %\\frac{1}{200}yz^2) \\ dx dy dz \\ $ to order 5.\n%\\item $\\int_{[0,1]^{18}} \\prod_{i=1}^{18} x_i \\ dx_i \\ $ to order 3.\n%\\end{enumerate}\n%\\end{problem}\n", "meta": {"hexsha": "adc187d058a33811075f13a1df30981eda49a1d4", "size": 12755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Orphans/SparseGrid/SpGrid.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/SparseGrid/SpGrid.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/SparseGrid/SpGrid.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": 63.1435643564, "max_line_length": 656, "alphanum_fraction": 0.7252058016, "num_tokens": 3705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6465663819395951}}
{"text": "\n% Take from PyAudioAnalysis\n% short-term, mid-term features\n\n% \\chapter{Algorithms}\n% \\section{Time Analysis}\n% \\subsection{Convolution}\n% A general use of the convolution operation\n% is to evaluate the outputs of linear\n% time-invariant systems.\n% Taking the impulse response of a system, and\n% applying the convolution with\n% a given input, gives the system's output\n% for that specific input.\n\n% For continuous time dependent arguments,\n% \\(x\\) as the input variable, and \\(h\\) as the\n% system's impulse response, the convolution is given by:\n\n% \\begin{equation}\n%     (x * h)(t) \\triangleq \\int^{\\infty}_{-\\infty} x(t)h(t-\\tau) d\\tau\n% \\end{equation}\n\n% Due to the commutativity property of the convolution\n% operation, the shifting over one of the arguments\n% is interchangeable, thus one can write\n% the same equation as:\n\n% \\begin{equation}\n%     (x * h)(t) \\triangleq \\int^{\\infty}_{-\\infty} x(t-\\tau)h(t) d\\tau\n% \\end{equation}\n\n% Likewise, working with discrete variables,\n% the convolution operation can be written as:\n% \\begin{align}\n%     (x * h)[n] \\triangleq & \\sum^{\\infty}_{m=-\\infty} x[m]h[n-m] \\\\\n%     (x * h)[n] \\triangleq & \\sum^{\\infty}_{m=-\\infty} x[n-m]h[m]\n% \\end{align}\n\n\n% \\subsection{Cross-Correlation}\n% Cross-correlation is an operation that can measure\n% how similar two functions are. By ``shifting''\n% one function over the other and measuring the amount\n% of correlation at each given point, the output graph\n% demonstrates at what ``distance''\n% the maximum similarity occurs,\n% in correspondence\n% to the graph's maximum amplitude.\n\n% \\begin{align}\n%     (x * h)(t) \\triangleq & \\int^{\\infty}_{-\\infty} x^{*}(t)h(t+\\tau) d\\tau \\\\\n%     (x * h)(t) \\triangleq & \\int^{\\infty}_{-\\infty} x^{*}(t-\\tau)h(t) d\\tau\n% \\end{align}\n\n% \\begin{align}\n%     (x * h)[n] \\triangleq & \\sum^{\\infty}_{m=-\\infty} x^{*}[m]h[n+m] \\\\\n%     (x * h)[n] \\triangleq & \\sum^{\\infty}_{m=-\\infty} x^{*}[n-m]h[m]\n% \\end{align}\n\n% \\subsection{Auto-Correlation}\n% In a case where the two input functions\n% of the cross-correlation are the same input signals,\n% the measure is then called ``auto-correlation''.\n% In other words, this measure demonstrates\n% at what ``distance'' the delayed version of the signal\n% most matches the original version of it.\n\n% This kind of measure is very useful in audio\n% applications where multi-microphones are spread\n% with varying distance from each other and from the\n% source. Looking for the maxima point of the\n% auto-correlation between the signal received by\n% the microphones, one can deduce the lag time\n% that best characterizes the microphones' formation.\n\n% Several enhancement and manipulation techniques\n% are then become available when the lagging\n% time is known.\n% For example the delay and sum algorithm beamforming\n% algorithm for constructive summation of the different\n% channels that translates\n% to better SNR (signal-to-noise ratio).\n\n% \\subsubsection{Covariance Matrices}\n% \\begin{equation}\n%     \\mathbf{R}_{XY} \\triangleq \\mathbf{E}[XY^{tr}]\n% \\end{equation}\n\n% \\begin{align}\n%     \\mathbf{R}_{XX} & \\triangleq \\mathbf{E}[XX^{tr}] \\\\\n%                     & = \\frac{1}{T} \\sum^{T-1}_{t=0}\n%     {X}(t;j\\omega){X}^{\\mathbf{H}}(t;j\\omega)\n% \\end{align}\n\n% Where the \\(\\mathbb{H}\\) operator\n% is the \\emph{Hermitian function} which stands for\n% the complex conjugate.\n\n% % ESPNet \\& Mirco Document\n% \\subsection{Sinc-Conv}\n\n% % \\begin{figure}[ht]\n% %     \\centering\n% %     \\includegraphics[width=0.99\\textwidth]\n% %     {./img/Comparison_convolution_correlation.svg}\\label{fig:conv_vs_corr_plot}\n% %     \\caption{Convolution vs. Cross-Correlation vs. Auto-Correlation plot [Wikipedia]}\n% % \\end{figure}\n\n\n\n% \\section{Frequency Analysis}\n% \\subsection{DTFT}\n% \\begin{equation}\n%     X_{2\\pi}(\\omega) = \\sum_{n=-\\infty}^{\\infty} x[n] \\,e^{-i \\omega n}\n% \\end{equation}\n\n\n% \\subsection{IDTFT}\n% \\begin{equation}\n%     x[n] = \\frac{1}{2 \\pi}\\int_{2\\pi} X_{2\\pi}(\\omega)\\cdot e^{i \\omega n} d\\omega\n% \\end{equation}\n\n% \\subsection{DFT}\n% \\begin{equation}\n%     \\label{eq:dft}\n%     X_k = \\sum_{n=0}^{N-1} x_n \\cdot e^{-\\frac {i 2\\pi}{N}kn}\n% \\end{equation}\n\n% Taking Euler's identity:\n% \\begin{equation}\n%     e^{ix} = \\cos x + j\\sin x\n% \\end{equation}\n\n% Substituting the exponent power in Equation\\;\\ref{eq:dft} with the Euler identity\n% gives:\n% \\begin{equation}\n%     X_k = \\sum_{n=0}^{N-1} x_n \\cdot \\left[\\cos\\left(\\frac{2 \\pi}{N}kn\\right)\n%         - i \\cdot \\sin\\left(\\frac{2 \\pi}{N}kn\\right)\\right]\n% \\end{equation}\n\n\n% \\subsection{IDFT}\n% \\begin{equation}\n%     x[n] = \\frac{1}{N} \\sum_{k=0}^{N-1} X_k\\cdot e^{i \\frac{2 \\pi}{N} k n}\n% \\end{equation}\n\n\n% \\subsection{FFT --- Fast Fourier Transform}\n\n% \\subsection{Discrete Cosine Transform (DCT)}\n\n% \\begin{equation}\n%     y[n] = \\sum^{}_{}\n% \\end{equation}\n\n% \\section{Time-Frequency Analysis}\n% \\subsection{STFT - Short Time Fourier Transfer}\n\n% \\subsection{Spectrogram}\n\n% \\section{Windows}\n% \\subsection{Overview}\n\n\n% \\subsection{Rect (boxcar)}\n% \\subsection{Triangle}\n% \\subsection{Bartlett}\n% \\subsection{Hamming}\n% \\subsection{Hann}\n% \\begin{align}\n%     w[n] = 0.5 - 0.5\\cos\\left( \\frac{ 2\\pi n }{ M - 1 } \\right) & \\qquad 0 \\leq n \\leq M-1\n% \\end{align}\n\n\n% % \\subsection{Kaiser}\n% % \\subsection{Analog Filters}\n\n% \\subsection{Overlap + Add Reconstruction}\n% % \\subsection{Wavelets}\n\n% \\section{Speech-Enhancement}\n% See table\n% \\begin{figure}[ht]\n%     \\centering\n%     \\includegraphics[width=0.99\\textwidth]\n%     {./img/spc_enhance_tbl}\\label{fig:asr_blocks_diagram}\n%     \\caption{General E2E ASR System Blocks Diagram}\n% \\end{figure}\n\n\n\n% DCT + MFCC Connection\n% DST - Discrete Sine Transforms\n% Hilbert Transform\n% Analytical Signal\n% Wavelates\n% Convolution / Correlation\n% Parseval's Theorm\n% PSD\n% Median Filter\n% ORder Filter\n% Wiener Filter\n% Hermitian FFTs\n\n\n\n\n\n\\chapter{Features}\\label{ch:features}\n\\section{Introduction}\nIn data analysis craftsmanship, \nprominence importance exists \nabout how to characterize the data so that \nvariations in data characteristics would \nbe noticeable and more \neasily discernible during the analysis process.\nTo that end, the input data being analyzed is reorganized\naccording to selected features on which\nconclusions and distinctive deductions can be made.\n\nSimilarly, in a supervised learning \nprocedure of a machine, \nin order to make classification decisions accurately. \nThe need for such features arises to \naid the learning algorithm in focusing on the \nsame features that probably were selected manually.\nAn intelligent choice of the learnable features \n\\cite{7845025} \ncan drastically change a given model's outcomes quality.\nIn a supervised learning, the \nfeature selection and extraction process withal,\nare preparatory steps to the learning or classification\nstages coming next.\nAs a rule of thumb, the more features, the better accuracy\na learning model can yield theoretically\\cite{lessIsMore}.\nThat saying holds true to a great degree\nas long as often sudden fluctuations do not characterize the data.\nIn a case of heavy fluctuating characterizations of the data,\nor alternatively, in the case of a \nmassive number of features, \nthat some of which have minor contributions \nto the classification part of the output,\nincrease in the number of features may become deteriorative.\nIn terms of performance, \nenlarging the number of features leads to a bigger model, \nan increased number of learnable parameters, \nlonger training times, \nand unnecessary extension of processing times.\nAlso, a possible reduction in the accuracy is \nexpected due to \nFalse-Negative (FN) or False-Positive (FP) \nmisdetections resulting from the wrong \nclassification of signals as noise and \nvice versa caused by additional redundant features.\n\nFor speech signals, a wide variety of \nmeaningful feature sets exist. \nMore or less useful, different speech features \nmay better fit certain use-cases or fulfill \na particular unerring task. \nFeatures for speech (including audio) \nare mainly from the following domains:\n\\begin{enumerate}\n    \\item Spectral Features\n    \\item Cepstral Features\n    \\item Time domain Features\n    \\item Spatial Features\n\\end{enumerate}\n\nSpeech features are selected \nto give the maximal accuracy in detecting utterances.\nThat means a precise characterization of a \nword, utterance, or the pronunciation of \na single character, making them distinguishable\nfrom other input streams. \n\n\\section{Spectral Features}\n\\subsection{FB --- FilterBanks}\nFilterBanks is a very common technique\nfor spectral mapping of speech signals.\nBy dividing the audio spectrum into multiple \nsub-domains with a defined level of overlap, \nthe spectrum is \n``framed'' according to frequency. \nThus, by a set of band-pass filters,\neach frame contains the confined \ninformation of the speech signal \nthat corresponds to the filter's specific \nrange of frequencies.\n\nThe resolution can then be set as a function of\nthe number of filters and the overall processed audio bandwidth.\nIncreasing the number of filters, assuming the \naudio bandwidth and the overlap ratio are constant, means\nnarrower allocated bandwidths for each individual filter\nor in other better spectral resolution.\n\nFilterbanks by themselves are not the desired speech feature,\nbut only the mean for feature extraction. \nThe most common feature extracted by a Filterbank set\nis the total sum of energy bounded by the filter's frequency response.\nA set of filters is computed per \nfrequency bin and remains the same for \nthe entire signal length over time.\nThus, the total sum of energy computed for \neach filter characterizes the \nspeech over a finite defined duration of time.\n\nThe human hearing system is less sensitive to high frequencies\nthan lower band frequencies, as described in Chapter\\;\\ref{ch:scaling_methods}.\nTherefore, in an attempt to emulate the same natural behavior and\nresemble the hearing ``filters'' as much as possible, \nthe Filterbank set of filters is set with center frequencies\naccording to the different scaling \nmethods described in Chapter\\;\\ref{ch:scaling_methods}.\nIn that way, narrow-band filters are assigned to \nlower frequency ranges. \nSimilarly, wide-band filters are for \nthe higher hearable frequency ranges.\n\n\\subsubsection{Mel FB}\nOne way of mapping the audio spectrum is according to the Mel\nscale. This scaling method is described in Chapter\\;\\ref{ch:scaling_methods}.\nFirst, the center frequencies and the bandwidths are received by the transformation\nbetween Herz to Mels. Then a set of Bartlett\nfilters with those center frequencies are generated\nwith an overlap of 50\\% between adjacent filters. \n\n\nThe amplitude of the filters is bounded to \\(1\\) \nto maintain NOLA compatibility.\nAn example of a Mel Filterbank constructed by Bartlett filters\nis shown in Figure~\\ref{fig:sb_mel_fb}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/sb_mel_fb}\n    \\caption{Mel FB}\\label{fig:sb_mel_fb}\n\\end{figure}\n\n\\subsubsection{Bark FB}\nThe Bark Filterbank is very similar to the Mel Filterbank\nexcept that it follows the Bark scale \ninstead of the Mel Scale.\n\nDifferent filter shapes are available but, \ntriangular filter shapes are the most common,\nas described in \\cite{barkfilt}.\n\nAn example of the Bark Filterbank constructed by Bartlett filters\nis shown in Figure~\\ref{fig:mat_bark_fb}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/mat_bark_fb}\n    \\caption{Bark FB}\\label{fig:mat_bark_fb}\n\\end{figure}\n\n\\subsubsection{Gammatone FB}\nThe Gammatone filter, as described in \\cite{gammatonefilt},\nhas a response function as follows:\n\\begin{equation}\n    g(t) = \\alpha t^{n-1}e^{-2\\pi bt}\\cos \\left( 2\\pi f_{c} t + \\phi\\right)\n\\end{equation}\n\nWhere \\(\\alpha\\) denotes the amplitude factor,\n\\(n\\) is the filter order,\n\\(f_{c}\\) is the center frequency,\n\\(\\phi\\) is the phase factor,\nand \\(b\\) is the bandwidth parameter\ncomputed according \nto the ERB scale mapping of \\(1.019\\cdot ERB \\left( f_{c} \\right)\\).\n\nAn example of a Gammatone Filterbank\nis shown in Figure~\\ref{fig:sb_fb_gauss}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/sb_fb_gauss}\n    \\caption{Gammatone FB}\\label{fig:sb_fb_gauss}\n\\end{figure}\n\n\n\\section{Cepstral Features}\n\\subsection{MFCCs --- Mel-Frequency Cepstral Coefficients}\n\n% https://link.springer.com/content/pdf/bbm%3A978-3-319-03116-3/1.pdf\n\\subsubsection{Pre-emphasis}\nSpeech signals have a roll-off frequency \nresembling a low-pass behavior\\cite{237532}.\nDue to that physical nature, higher frequencies \ndecay faster than lower speech frequencies.\nCompensation for this phenomenon is attainable with a \npre-emphasis filter that boosts \nthe higher\\cite{7489370} frequencies responses.\n\n\n\\subsubsection{Framing}\nSpeech signals vary in time. \nAlthough the variation over time is relatively slow, \na speech signal is a non-pure stationary process \nbut a quasi-stationary. \nTherefore, analysis of speech signals \nis taken on small portions of the \nsignal to be less affected by randomness effects.\nTo that end, a preliminary framing action is applied\nto to speech signals in the time domain.\nFraming means dividing the signal \ninto small fragments(frames) with some overlapping in between.\nEach time frame is assumed to be stationary,\nand thus a measurement can be taken.\n\nThe shifting in time between frames is referred\nto as the hopping length and is set to contain \na sufficient amount of temporal\ncontext that characterizes the natural\ncharacteristics of speech.\n\nA very common sampling frequency of audio signals\nis \\(16KHz\\). \nAs a result, and in order to work with \na round number of sampling points, \nthe frame lengths \nand the hopping lengths \nare set to \\(25ms\\), and \n\\(6.25ms\\) or \\(10ms\\) for hopping size. \nThese values translate to a frame length\nequals 400 sampling points, and hopping size\nequals 100 or 160 sampling points, respectively.\nAnother advantage of setting the hopping length\nas \\(6.25ms\\) is that it gives\na complete temporal context of 3 adjacent frames\nby definition.\n\n\\subsubsection{Windowing}\nIn order to extract each frame only \nwhilst also minimizing the Gibbs effects as much as possible,\na windowing function is applied.\nAs a result, the information confined \nin a given frame is extracted while the \nwindow's response function tapers \nthe edges to reduce the adjacent frames' effect.\n\nUsually, a Hamming or a Hann window \nis used as the window function due to their \nrelatively decent trade-off between edge tapering, \nimplementation simplicity, bandwidth, and spectral leakage, \nmaking them exceptionally suitable for speech signals.\n\nThe Hamming and Hann windows are given by\nEquations\\;\\ref{eq:hammwin} and \\ref{eq:hannwin}, respectively.\n\\begin{align}\n    \\label{eq:hammwin} &W_{_{Hamming}}[n] = 0.54 - 0.46\n    \\cos\\left( \\frac{2\\pi n}{M-1} \\right) &\n            0 \\leq n \\leq M - 1 \\\\\n    \\label{eq:hannwin} &W_{_{Hann}}[n] = 0.5 - 0.5\n            \\cos\\left( \\frac{2\\pi n}{M-1} \\right) &\n            0 \\leq n \\leq M - 1\n\\end{align}\n\n\\subsubsection{DFT spectrum}\nEach one of the windowed frames is\nconverted to the frequency domain by applying the \nDiscrete Fourier Transform (DFT).\nThe composition of both windowed framing \nand the DFT is referred to as the \nShort-Time Fourier Transform (STFT).\nA technique to visualize the STFT outcome is \ncalled a spectrogram. The STFT outcome contains \nmultiple frequency bins per time frame,\nmaking it a function of \\(f, t\\).\n\nThe DFT is given by:\n\\begin{align}\n    X_{m}(f) = \\sum_{n=-\\infty}^{\\infty} x[n]g[n-mR]e^{-j2\\pi fn}\n\\end{align}\n\nWhere \\(X_{m}(f)\\) denotes the DFT transformation of\na given time frame windows signal,\n\\(g[\\circ]\\) denotes the window function of size \\(M\\),\nand \\(R\\) represents the hopping size.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Features/images/iscola_stft}\n    \\caption{STFT demonstration diagram}\\label{fig:iscola_stft}\n    \\source{Adapted from Matlab's STFT documentation}\n\\end{figure}\n\n\\subsubsection{Mel-spectrum}\nOnce the spectrogram is received, \nthe frequencies are rescaled in accordance with the Mel Scale.\nA comprehensive description of the Mel Scale \nis detailed in Chapter\\;\\ref{ch:scaling_methods}.\n\nNext, the cepstral coefficients are extracted from each frequency bin, \nby taking the energies sum of each filter and multiplying it\nwith the Discrete Cosine Transform (DCT).\n\\begin{align}\\label{eq:mfcc}\n    MFCC[n] & = \\sqrt{\\frac{2}{K}} \\sum_{k=1}^{K} \\left\\{ \n        e[k] \\cdot DCT\\left( k \\right)\n     \\right\\} \\nonumber \\\\\n     & = \\sqrt{\\frac{2}{K}} \\sum_{k=1}^{K} \\left\\{ \n        e[k] \\cdot \\cos \\left( \\frac{\\pi n}{K} (k+0.5) \\right)\n     \\right\\}\n\\end{align}\n\nIt is very common to extract the log-Mel energies\nand then have Equation\\;\\ref{eq:mfcc} written as:\n\\begin{align}\\label{eq:logmfcc}\n    MFCC[n] & = \\sqrt{\\frac{2}{K}} \\sum_{k=1}^{K} \\left\\{ \n        \\log \\left( e[k] \\right) \\cdot \\cos \\left( \\frac{\\pi n}{K} (k+0.5) \\right)\n     \\right\\}\n\\end{align}\n\n% Take from PyAudioAnalysis\n% PyAudioProcessing\n\n\\subsection{RFCCs --- Root-Frequency Cepstral Coefficients}\nAn alternative to the log-Mel \nextraction of the cepstral coefficients\nhas been suggested in \\cite{rmfcc1} and \\cite{1415167}.\nThe motivation to put this proposed \ntechnique under test is that the root \nfunction can be less computationally demanding \nthan the traditional log function..\n\\begin{align}\n    RCC[n] & = \\sqrt{\\frac{2}{N}} \\sum_{k=1}^{K} \\left\\{ \n        \\left( e[k] \\right)^{\\gamma} \\cdot \\cos \\left( \\frac{\\pi n}{K} (k+0.5) \\right)\n     \\right\\}\n\\end{align}\n\n\\subsection{GFCCs --- Gammatone-Frequency Cepstral Coefficients}\nGFCCs follow the basic steps same as the MFCCs extraction.\nBut, instead of translating the frequencies to Mels,\nthe spectrum is translated to the ERB scale.\nERB scale implies a Gammatone Filterbank as described in Chapter \\ref{ch:scaling_methods}.\n\n\n\\subsection{BFCCs --- Bark-Frequency Cepstral Coefficients}\nLike the Gammatone-FCCs (GFCCs), the BFCCs follow the Bark Scale.\n\n% \\subsection{LFCCs --- Linear-Frequency Cepstral Coefficients}\n% \\subsection{LPC --- Linear Predictive Coefficients}\n% \\subsection{MSRCC --- Magnitude-based Spectral Root Cepstral Coefficients}\n% \\subsection{NGCC --- Normalized Gammachirp Cepstral Coefficients}\n% \\subsection{PNCC --- Mel-Frequency Cepstral Coefficients}\n% \\subsection{PSRCC --- Mel-Frequency Cepstral Coefficients}\n% \\subsection{RPLP --- Mel-Frequency Cepstral Coefficients}\n% https://spafe.readthedocs.io/en/latest/features/_features.html\n% \\subsection{articulatory cepstral coefficients}\n\n\\section{Time-Domain Features}\n\\subsection{Dynamic FCC features}\nDuring the framing process, the speech signal \nis divided into small fragments of the speech over time. \nThese time unit fragments are called frames.\nEach frame spans over a finite time duration.\nThe extracted cepstral coefficients are computed statically\nfor a given frame. However, the original speech\nis framed in multiple numbers of frames. \nTherefore, coefficients extractions\nhave to be dynamic for the entire signal, i.e., all frames.\n\nAdditional information about the temporal \nchanges between adjacent coefficients can also be extracted\nto include the dynamics and transitions within a frame.\n\n\\subsubsection{Deltas}\nThe first derivate of the cepstral coefficients\n,\\(\\Delta\\) (Deltas),\nrepresents the velocity of the MFCCs' dynamics and \nis a sub-set of the cepstral coefficients.\n\nDeltas (\\(\\Delta\\)) are extracted by:\n\\begin{equation}\\label{eq:deltaderiv}\n    \\Delta [n] = \\frac{ \\sum\\limits_{i=-T}^{T} k_{i} c_{m}[n+i]}\n    {\\sum\\limits_{i=-T}^{T} |i|}\n\\end{equation}\n\nWhere \\(n\\) denotes the frame time index, \\(k\\) marks the \ncoefficient weight, \\(T\\) stands for the number of temporally\nadjacent frames used for the calculation, and \\(c_{m}\\) denotes the\n\\(m\\)th coefficient in the given frame \\(n\\).\n\n\\subsubsection{Delta-Deltas}\nDelta-Deltas (\\(\\Delta\\Delta\\)) is an extra layer of information\nrepresenting the acceleration at which the \nMFCCs' dynamics change within a given time frame.\nThe extraction of the Delta-Deltas follows the same principale\nas the first derivatives. Yet, instead of taking the\ncepstral coefficients as the input feature, we replace\n\\(c_{m}\\) in Equation\\;\\ref{eq:deltaderiv} \nwith the first-order derivatives \\(\\Delta[n]\\).\n\n\\subsection{Temporal Context}\nTemporal context is an attachment of raw unprocessed \nfeatures' data from adjacent\nframes together with the currently selected feature. \nWhether spectral, cepstral, or spatial features,\nthe concatenation of past and future \nfeatures can infer decisions based on a memory effect.\nFurthermore, different languages\nintroduce contextual constraints such as relative positions\nof adjectives or nouns to verbs, plurals, affiliations,\npossessions, and other lingual principles.\n\nUsually, the number of adjacent past and future frames \nto concatenate is based on the framing and DFT parameters.\nIt is plain to understand \none would not want to exaggerate and excessively use\nredundant frames that do not have any significant impact\non the accuracy of detection. \nThe downside of overly using temporal context frames is obvious, \norders of magnitude larger amounts of information to process.\n\n% \\section{Spatial Features}\n% \\subsection{VTLN - vocal track length norm}\n", "meta": {"hexsha": "2378ee031791f3213db6c4d2538aeb027b1ba4a5", "size": 21276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/Features/features.tex", "max_stars_repo_name": "aviadb/research", "max_stars_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Dissertation/Features/features.tex", "max_issues_repo_name": "aviadb/research", "max_issues_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Dissertation/Features/features.tex", "max_forks_repo_name": "aviadb/research", "max_forks_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_forks_repo_licenses": ["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.4829821718, "max_line_length": 92, "alphanum_fraction": 0.7417277684, "num_tokens": 5756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6465663786433863}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{October 27, 2014}\n\\maketitle\nif $G$ is a group, and $A\\subseteq G$ and $B\\subseteq G$ then $AB=\\{ab|a\\in A, b\\in B\\}\\subseteq G$.\n\n\\section*{proposition}\n\nlet $G$ be a group, then $H,K$ subgroups of $G$. Assume that $h^{-1}kh\\in K$ for all $h\\in H$, $k\\in K$ then $HK$ is a subgroup of $G$ that contain s both $H$ and $K$, in fact, $HK$ is the smallest subgroup of $G$ that contains both $H$ and $K$. Assumption only important if we are not dealing with abelian groups.\n\n\\subsubsection*{proof}\n$a,b\\in HK$. Write $a=h_1k_1,b=h_2k_2$ with $h_i\\in H,k_i\\in K$ then $a\\cdot b=h_1k_1h_2k_2=h_1h_2(h_2^{-1}k_1h_2)k_2\\in HK$\n\n$a=hk, a^{-1}=(hk)^{-1}=k^{-1}h^{-1}=h^{-1}(hk^{-1}h^{-1})\\in HK$\n\n\\subsection*{examples}\n$S_3, H=\\{(1),(12)\\}, K=\\{(1),(123),(132)\\}, (12)(123)=(23)\\in HK, (12)(132)=(13)\\in HK$ so $HK=G$ and is therefore contained by G\n\n$(\\mathbb{Z},+)$, $H=a\\mathbb{Z}, k=b\\mathbb{Z}$, let $d=(a,b)$\n\nclaim: $a\\mathbb{Z}+b\\mathbb{Z}=d\\mathbb{Z}$. clearly $a\\mathbb{Z}\\subseteq d\\mathbb{Z}$, $b\\mathbb{Z}\\subseteq d\\mathbb{Z}$. \n\n$a\\mathbb{Z}+b\\mathbb{Z}$ is the smallest subgroup that contains both $a\\mathbb{Z}$ and $b\\mathbb{Z}$. so $a\\mathbb{Z}+b\\mathbb{Z}\\subseteq d\\mathbb{Z}$.\n\n$d=\\gcd(a,b)$ so we can write $d=ma+nb$. let $\\alpha\\in d\\mathbb{Z}$ and write $\\alpha=dt, t\\in \\mathbb{Z}$ then $\\alpha=dt=mat+nbt\\in a\\mathbb{Z}+b\\mathbb{Z}$. so $d\\mathbb{Z}\\subseteq a\\mathbb{Z}+b\\mathbb{Z}$ \n\\section*{thm subgroup gen by a subset}\n$G$ is a group, if $a\\in G$ $<a>=\\{a^i|i\\in \\mathbb{Z}\\}$ is the smallest subgroupthat contains $a$.\n\n\\subsubsection*{proof}\nlet $S\\subseteq G$, let $<S>=\\{\\underbrace{a_1a_2\\dots a_k}_{\\text{word}}|a_i\\in S\\text{ or }{a_i}^{-1}\\in S, k\\in \\mathbb{N}\\}$ then $<S>$ is a subgroup, $<S>=\\cap \\forall H$ where $S\\subseteq H\\subseteq G$, and $H$ is a subgroup of $G$, $<S>$ is the smallest subgroup of $G$that contains $S$.\n\nso it is closed under multiplication, identity is in it, and the inverse of all words are in it.\n\nshow containment both ways, one is clear because we have words of length 1 that span $S$ and so $S$ is one of the elements of our $H$ intersection.\n\n\\section*{example}\n$a,b\\in G, S=\\{a,b\\}\\subseteq G, <S>=\\{a_1a_2\\dots a_k|a_i\\in\\{a,a^{-1},b,b^{-1}\\}\\}$\n\nif $ab=ba$ then $<S>=\\{a^{i}b^{j}|i\\in \\mathbb{Z}, j\\in \\mathbb{Z}\\}$\n\n\n\\section*{maps}\nstudied groups, subgroups. now we are going to talk about maps\n\nif we have groups $G_1,G_2$ and $\\varphi:G_1\\to G_2$ is a group homomorphism provided $x\\to\\varphi(x), y\\to\\varphi$ means that $\\varphi(x*y)=\\varphi(x)*\\varphi(y)$ for all $x,y\\in G_1$.\n\\section*{examples}\nidentity: $x\\to x$\n\n$(\\mathbb{R},+)=G_1, (\\mathbb{R}^+,\\cdot)=G_2$. $\\varphi(x)=e^x$. ie $\\varphi(x+y)=e^{x+y}=e^xe^y=\\varphi(x)\\varphi(y)$.\n\n\\section*{notation}\nlet $\\varphi:G_1\\to G_2$ be a group homomorphism, then $\\ker\\varphi=\\{x\\in G_1|\\varphi(x)=e\\}$\n\nhomomorphism always takes the identity in $G_1$ to $G_2$.\n\n$\\varphi(e_1)\\varphi(e_1)^{-1}=\\varphi(e_1e_1)\\varphi(e_1)^{-1}=\\varphi(e_1)\\varphi(e_1)\\varphi(e_1)^{-1}=e_2=\\varphi(e_1)$\n\nprove that $\\ker \\varphi$ is a subgroup\n\nnow we say that $\\varphi$ is an isomorphism if $\\varphi$ is a group homomorphism and $\\varphi$ is bijective.\n\nboth of the previous examples are isomorphisms.\n\nso from an algebraic point of view, there is no difference between addition on the reals and multiplication on the positive reals.\n\n\\section*{proposition}\nlet $\\varphi$ be an isomorphism. the following are true\n\\begin{enumerate}\n\\item\n$\\varphi^{-1}$ which is the map from $G_2$ to $G_1$ is also an isomorphism.\n\\item\nif $G_1$ is abelian, then $G_2$ is abelian.\n\\item\nif $G_1$ is cyclic then so is $G_2$\n\\item\nif $a\\in G_1$ then $\\text{ord}(a)=\\text{ord}(\\varphi(a))$\n\\end{enumerate}\n\n\\begin{enumerate}\n\\item\nneed to prove $\\varphi^{-1}(\\alpha\\beta)=\\varphi^{-1}(\\alpha)\\varphi^{-1}(\\beta)$ for all $\\beta\\in G_2$, but $\\varphi$ is injective so it is enough to prove that $\\varphi(\\varphi^{-1}(\\alpha\\beta))=\\varphi(\\varphi^{-1}(\\alpha)\\varphi^{-1}(\\beta)=\\varphi(\\varphi^{-1}(\\alpha))\\varphi(\\varphi^{-1}(\\beta))=\\alpha\\beta$\n\\item\nassume $G_1$ is abelian\n\\begin{align*}\n  \\alpha\\beta=\\varphi(\\varphi^{-1}\\left(\\alpha\\right)\\varphi^{-1}(\\beta))\n\\end{align*}\n\\item\nhint: assume that $G_1=<a>$ for some $a\\in G_1$ and then prove that $G_2=<\\varphi(a)$\n\\item\nno hint\n\\end{enumerate}\n\\section*{example}\n\\begin{align*}\n  \\mathbb{Z}_4\\not\\equiv\\mathbb{Z}_2\\times\\mathbb{Z}_2\n\\end{align*}\nby contradiction, assume that there exists an isomorphism $\\varphi$ from z4 to z2+z2. $[1]\\in \\mathbb{Z}_4$ and $\\text{ord}[1]=4$ so then $\\text{ord}\\varphi([1])=4$. But all elements of $\\mathbb{Z}_2\\times\\mathbb{Z}_2$ has no elements of order 4, so there is no isomorphisms. however, if $\\gcd(m,n)=1$ then $\\mathbb{Z}_{mn}\\equiv\\mathbb{Z}_m\\times\\mathbb{Z}_n$\n\n\\begin{align*}\n  \\varphi:[x]_{mn}\\to[x]_m[x]_n\n\\end{align*}\n\\section*{what does well defined mean?}\nsame input gives same output, ie if $[x]=[y]$ then $\\varphi[x]=\\varphi[y]$\n\n\\section*{3.4 \\#13}\n$(\\mathbb{R}^*,\\cdot), C_2=\\{\\pm1\\}\\subseteq \\mathbb{R}^*$. $C_2$ is a subgroup of $\\mathbb{R}^*$. prove that $\\mathbb{R}^*\\cong \\mathbb{R}^+\\times C_2$\n\nwe construct an isomorphism $\\theta:\\mathbb{R}^*\\to R^{+}\\times C_2$.\n\n$x\\to(|x|,\\frac{x}{|x|})$. prove that $\\theta$ is a group homomorphism and bijective.\n\n$\\theta(xy)=(|xy|,\\frac{xy}{|xy|})=(|x|,\\frac{x}{|x|})(|y|,\\frac{y}{|y|})=\\theta(x)\\theta(y)$\n\nbijectivity is exercise, but a number is uniquely identified by sign and magnitude (absolute value)\n\n\\section*{example}\nprove that $\\text{ord}(aba^{-1})=\\text{ord}(b)$ for every $a,b\\in G$ where $G$ is a group.\n\n$m=\\text{ord}(x)$ means $x^m=e$ and $x^k=e$ means that $m|k$.\n\nif given $n=ord(x)$ and $m=ord(y)$ then best way is to show that $m=n$ is $m|n$ and $n|m$. this all works for finit.\n\nthis question is trivial if the group is abelian.\n\nso let $m=ord(aba^{-1}), n=ord(b)$\n\n\\subsection*{case 1}\n$n$ is finite, $b^n=e$. consider $(aba^{-1})^n=aba^{-1}aba^{-1}\\dots aba^{-1}=ab^{n}a^{-1}=aea^{-1}=e$ so $ord(aba^{-1})$ is finite, also $m|n$\n\n$b^m=a^{-1}\\underbrace{(aba^{-1})(aba^{-1})\\dots(aba^{-1})(aba^{-1})}_{m\\text{ times}}a=a(aba^{-1})^ma=a^{-1}ea=e$ so $b^m=e$ and $n|m$\n\\subsection*{case 2}\n$n$ is infinite. then we must prove that $m$ is infinite. by contradiction, assume $m<\\infty$.\n\nthen $b^m=a^{-1}\\underbrace{(aba^{-1})(aba^{-1})\\dots(aba^{-1})(aba^{-1})}_{m\\text{ times}}a=a(aba^{-1})^ma=a^{-1}ea=e$ so $b^m=e$.\n\nand so the order is finite and we have our contradiction. so $m$ must be finite then\n\\subsection*{consider}\n$ord(a^{-1})=ord(a)$ and $ord(ab)=ord(ba)$\n\nby previous part $ord(ba)=(abaa^{-1})=ord(ab)$\n\n\\section*{3.2 \\# 25 from class}\nwe note that if $x\\in G$ has the required order, then $x^{-1}\\in G$ also has the required order. note that the $x\\ne x^{-1}$ because the order is greater than $2$.\n\n\\section*{!3.3 \\#9}\n\n\\section*{other things in mind}\nlets take a group $G$ and $H,K$ subgroups. then $\\left\\lvert HK\\right\\rvert=\\frac{|H||K|}{|H\\cap K|}$\n\nrecall: $HK=\\{hk|h\\in H, k\\in K\\}$\n\n\\begin{align*}\n  g\\in HK\\\\\n  g=hk\\\\\n  h\\in H\\quad |H|=m\\\\\n  k\\in K\\quad |K|=n\\\\\n\\end{align*}\nquestion? how many ways can $g=hk=h'k'$?\n\n\\begin{align*}\n  hk=h'k'\\to(h')^{-1}hk=k'\\\\\n  (h')^{-1}h=k'k^{-1}\\in H\\cap K\n\\end{align*}\nso $k'=\\alpha k, h'=h\\alpha^{-1}$\n\nthat is to say $hk=(h'\\alpha)(\\alpha^{-1}k')$\nthere are $|H\\cap K|$ ways to choose alpha\n\n\\section*{october 15}\nread 3.6.2\n\n\\subsubsection*{3.6 \\#2}\nWrite out the addition tables for $\\mathbb{Z}_4$ and for $\\mathbb{Z}_2\\times \\mathbb{Z}_2$. Use cycle notation to write out the permutation determined by each row of each of the addition tables as in the discussion preceding Cayley's theorem.\n\n\\[\n    \\begin{array}{c|ccccc}\n      +&[0]&[1]&[2]&[3]&(1)\\\\\n      \\hline\n      [0] & [0] & [1] & [2] & [3]&(1)\\\\\n      \n      [1] & [1] & [2] & [3] & [0]&(1234)\\\\\n\n      [2] & [2] & [3] & [0] & [1]&(13)(24)\\\\\n\n      [3] & [3] & [0] & [1] & [2]&(1432)\\\\\n    \\end{array}\n    \\quad\\quad\n    \\begin{array}{c|ccccc}\n      + & ([0],[0]) & ([0],[1]) & ([1],[0]) & ([1],[1])&(1)\\\\\n      \\hline\n      ([0],[0]) & ([0],[0]) & ([0],[1]) & ([1],[0]) & ([1],[1])&(1)\\\\\n      ([0],[1]) & ([0],[1]) & ([0],[0]) & ([1],[1]) & ([1],[0])&(12)(34)\\\\\n      ([1],[0]) & ([1],[0]) & ([1],[1]) & ([0],[0]) & ([0],[1])&(13)(24)\\\\\n      ([1],[1]) & ([1],[1]) & ([1],[0]) & ([0],[1]) & ([0],[0])&(14)(23)\\\\\n    \\end{array}\n\\]\n\n\\section*{last time}\n$\\varphi:G\\to \\text{Sym}(G)$\n\\section*{rigid motions of a regular n-gon}\nplace the first vertex, then the second. we have n options for the first vertex, and 2 options for the second. and the rest are fixed. so we can do $2n$ rigid motions for any n-gon.\n\nobservation, rigid motions give us permutations, but for $n>3$ we can't get all the permutations. $2\\cdot 4<4!$.\n\nthe rigid motions form a group.\n\\subsection*{goal: describe this group}\n$a=$counterclockwise rotation by $\\frac{2\\pi}{n}$ radians or $\\frac{360}{n}^\\circ$. order of $a$ is $n$, that is to say, rotating $n$ times gives us our original vertex placement.\n\n$a^i=$rotation by $\\frac{2\\pi}{n}\\cdot i$.\n\n$b=$reflection about line $L$ this will leave one or two vertices unchanged, depending on the parity of $n$.\n\n$b=(2,n)(3,n-1)\\dots$.\n\n$b^2=e$.\n\nconsider $\\{b,ab,a^2b,\\dots,a^{n-1}b\\}$. remember $a,b$ are functions so $ab=a\\circ b$\n\n$a^ib=a^j\\Rightarrow a^i=a^j\\Rightarrow a^{j-i}=e$ but $a^{j-1}=e$ iff $n|j-i$.\n\n$a^ib=$the flip about the line $L_i$ that makes $\\frac{\\pi i}{n}$ with $L$, this means that $\\text{ord}(a^ib)=2$ because it's just a flip.\n\nnow we have $n$ rotations and $n$ flips. note that no flip can be a rotation because a flip changes orientation.\n\n$D_n$ denotes $\\{e,a,a^2,\\dots,a^{n-1},b,ba,ba^2,\\dots,ba^{n-1}\\}$ which is the dihedral group with 2n elements. $a^n=e$ and $b^2=e$.\n\nnotice that the order of the group reflects the symmetry of the geometric representation. a completely assymetric object with have only the $e$ rigid motions, while a circle will have infinitely many.\n\nwhat is $ba$? it's $a^{-1}b=a^{n-1}b$\n\n\\section*{october 20}\nassnmnt: 3.6 \\#21,23,25\nif odd, has identity, if even, identity and half rotation ($r^{n/2}$)\n$a^jb=ba^j\\to a^jb=a^{-j}b\\to a^j=a^{-j}\\to a^{2k}=e\\to n|2j$\n\n\\subsection*{last time started homomorphisms}\n\\subsubsection*{definition}\n$\\varphi:G_1\\to G_2$ is group homomorphism then $\\text{Im}\\varphi=\\varphi(G_1)$ is a subgroup of $G_2$ and $\\text{Ker}(\\varphi)=\\{x\\in G_1:\\varphi(x)=e_2\\}=\\varphi^{-1}(\\{e_2\\})$ beause $\\{e_2\\}\\le G_2$ is a normal subgroup, $\\text{Ker}(\\varphi)\\le G_1$ is a normal subgroup\n\n\\subsubsection*{equivalence relation defines a group  homomorphism}\non $G_1/\\sim$ define the operation $[x][y]=[xy]$. is this well defined?\n\n$[x]=[x']$ and $[y]=[y']$. $\\varphi(x)=\\varphi(x')$, and $\\varphi(y)=\\varphi(y')$ and so $\\varphi(x)\\varphi(y)=\\varphi(x')\\varphi(y')$ and homomorphism definition gives us $\\varphi(xy)=\\varphi(x'y')$.\n\nclaim , with this operation $G_1/\\sim$ is a group. $[e_1]$ is identity. $[x]$ is inverse of $[x^-1]$.\n\nlet $\\pi(x)=[x]$. claim $\\pi$ is a group homomorphism.\n\n$\\pi(xy)=[xy]=[x][y]=\\pi(x)\\pi(y)$.\n\n\\subsubsection*{why does $[xy]=[x][y]$}\n\\subsubsection*{thrm}\nLet $\\varphi:G_1\\to G_2$ be a group homomorphism. then $G_1/\\sim\\cong\\varphi(G_1)$\n\nproof:\n\n$G_1\\sim\\to\\varphi(G_1)$\n\n$[x]\\to\\varphi(x)$\n\n$\\overline\\varphi([x])=\\varphi(x)$\nclaim: $\\overline\\varphi$ is a group homomorphism\n$\\overline([x][y])=\\overline\\varphi([xy])=\\varphi(xy)=\\varphi(x)\\varphi(y)=\\overline\\varphi([x])\\overline([y])$\n\nclaim: surjectivity is clear\nclaim: $\\overline\\varphi$ is injective.\n$\\overline\\varphi([x])=\\overline{\\varphi}([x])\\to \\varphi(y)=\\varphi(x)\\to x\\sim y\\to [x]=[y]$\n\n\\subsubsection*{assignment for next time}\n$\\varphi:\\mathbb{Z}_m\\to\\mathbb{Z}_n$ where $\\varphi$ is group homomorphism. hint: $\\varphi(0)=0$ and $\\varphi([1])=[k]$ then $\\varphi([j])=\\varphi([jk])$. take $Z_2\\to\\mathbb{Z}_4$ then $\\varphi([1])\\ne[1]$\n\n\\section*{october 22}\n\\subsection*{discussion assnmnt}\n\\begin{enumerate}\n\\setcounter{enumi}{13}\n\\item\ncall center $C$ with $C=\\{c\\in G:cg=gc\\forall g\\in G\\}$. then $gcg^{-1}=cgg^{-1}=c\\in C$\n\\item\nintesection being a group is pretty straightforward, if a is in both then $a^{-1}$ is in both. if a and b are in both, then $ab$ is in both, and $e$ is in both\n\\setcounter{enumi}{17}\n\\item\n$\\langle a\\rangle$ has two subgroups, $\\{e\\}$ and $\\langle a^k\\rangle$ where $k|n$. of course $e$ is normal. cyclic groups are abelian, so\n\\begin{align*}\n  b^ja^m(a^k)^ia^{-m}b^j=\n\\end{align*}\n\\end{enumerate}\n\\section*{3.8}\nif $G$ is a group and $H$ is a subgroup\n\n\\subsubsection*{parallel 1}\non $G$ define the relation $x\\sim_ry\\Leftrightarrow xy^{-1}\\in H$\n\n$\\Leftrightarrow x\\in Hy$\n\nclaim: $\\sim_r$ is an equivalence relation\n\\begin{enumerate}\n\\item\n$x\\sim_r x$\n\\item\n$x\\sim y\\to xy^{-1}\\in H\\to (xy^{-1})^{-1}\\in H\\to yx^{-1}\\in H\\to y\\sim x$\n\\item\ntransitivity\n\\end{enumerate}\nso $[x]=Hx$\n\\subsubsection*{observations}\n$Hx=Hy\\to x\\sim_r y$\n\nall the right cosets have the same number of elements\n$\\theta:H\\to xH$ because any $x$ has an image then $\\theta$ is surjective, and $\\theta(h_1)=\\theta(h_2)\\to xh_1=xh_2\\to h_1=h_2$ and so it is bijective\n\\subsubsection*{parallel 2}\non $G$ define the relation $x\\sim_ly\\Leftrightarrow x^{-1}y\\in H$\n\n$\\Leftrightarrow y\\in xH$\n\nclaim $\\sim_l$ is an equivalence relation\n\\begin{enumerate}\n\\item\n\n\\end{enumerate}\nso $[x]=xH$\n\nthere exists a bijection from the set of left cosets to the set of right cosets.\n\ndefine $\\psi(xH)=Hx^{-1}$ (not $Hx$ because this is not well defined.\n\n$xH=yH\\to x\\sim_l\\to xy^{-1}\\in H\\to yx^{-1}\\in H\\to y^{-1}(x^{-1})^{-1}\\in H\\to x^{-1}\\sim_r y^{-1}$\n\nclaim injectivity:$\\psi(xH)=\\psi(yH)\\to Hx^{-1}=Hy^{-1}\\to x^{-1}\\sim_ry^{-1}\\to x^{-1}(y^{-1})^{-1}\\in H\\to x^{-1}y\\in H\\to x\\sim_l y\\to xH=yH$\n\nnotation:  $[G:H]$ is the index of $H$ in $G$ and means the number of left/right cosets of $H$ in G.\n\ncorollary: if $G$ is finite and $H$ is a subgroup then the number of elements in $G$ is equal to the number of elements in $H$ times the index. $|G|=|H|\\cdot[G:H]$\n\nproof: $|G|$ equals the number of elements in each $[G:H]$ equal partitions of $G$ times the number of partitions.\n\ncorollary, if $G$ is finite then $H\\subseteq G\\to |H|$ divides $G$\n\n\\subsubsection*{example}\n$G=S_3\\cong D_3$\n\n$H=\\{e,b\\}\\le D_3$\n\nleft cosets are: $eH=H=bH, aH=\\{a,ab\\}, a^2H=\\{a^2,a^2b\\}$ and $[G:H]=3$\n$N=\\{e,a,a^{2}\\}\\to [G:N]=2$\n\\section*{oct 27}\n\\subsection*{derniere fois}\n$G$ group, $N$ is a normal subgroup of $G$. then $G/N=\\{aN:a\\in G\\}$ is a broup with $aN\\cdot bN=(ab)N$\n\n$\\pi:G\\to G/N:a\\to aN$\n\n$\\pi$ is a surjective group hom with $\\text{Ker} \\pi=N$.\n\n\\subsection*{thrm}\n$\\varphi:G_1\\to G_2$ group homomorphism then $G/\\text{Ker}\\varphi\\cong\\varphi(G_1)$\n\\subsection*{proposition}\nthere exists a one to one correspondence between $\\{\\text{subgroups of }G/N\\}$ and $\\{\\text{subgroups of $G$ that contain $N$}\\}$.\n\n$\\alpha:\\{aN:a\\in H\\}=\\pi(H)\\leftarrow H\\le G, H\\supseteq N$\n\n$\\beta:K\\to\\pi^{-1}(K)$\n\nmoreover normal subgroups correspond to normal subgroups\n\n\\subsubsection*{proof}\nnote $\\pi^{-1}(K)\\supseteq\\pi^{-1}(\\{e\\})=\\text{Ker}\\pi=N$. moreover if $K$ is a normal subgroup of $G/N$ then $\\pi^{-1}(K)$ is a normal subgroup of $G$.\n\nsimilarly if $H\\le G$ and $H\\supseteq N$ then $\\pi(H)$ is a subgroup of $G/N$. moreover if $H$ is a normal subgroup of $G$ then $\\pi(H)$ is a normal subgroup of $G/N$ (why?)\n\n\\subsubsection*{claim}\n$\\alpha\\circ\\beta(K)=\\alpha(\\beta(K))=\\alpha(\\pi^{-1}(K))=\\pi(\\pi^{-1}(K))=\\{\\pi(y):y\\in \\pi^{-1}(K)\\}=\\{\\pi(y):\\pi(y)\\in K\\}=K\\cap I_m\\pi=K\\cap\\pi(G)=K$ because $\\pi$ is surjective\n\n$\\beta\\circ\\alpha(H)=\\beta(\\alpha(H))=\\beta(\\pi(H))=\\pi^{-1}(\\pi(H))\\supseteq H$\n\n$h\\in H\\to \\pi(h)\\in$\n\n$\\pi(x)\\in  \\pi(H)\\to \\pi(x)=\\pi(h)$ for some $h\\in H$ so $xN=hN$ so $xh^{-1}\\in N\\to xh^{-1}\\in H\\to x\\in H$\n\nso $\\alpha$ and $\\beta$ are bijections and are inverse.\n\n\\subsection*{example}\n$G=\\mathbb{Z}, N=n\\mathbb{Z}$ and so $G/N=\\mathbb{Z}/n\\mathbb{Z}=\\{a+n\\mathbb{Z}:a\\in \\mathbb{Z}\\}$\n\n\\subsection*{definition}\ngroup $G$ is simple if it's only subgroups are itself and $\\{e\\}$. \n\n\\section*{example}\nlet $p$ be a prime then $\\mathbb{Z}_p$ is simple. because nothing divides $p$ we can't have any subgroups of $\\mathbb{Z}_p$ other than itself and the identity.\n\\end{document}\n\n\n", "meta": {"hexsha": "2fcfab7bc2d96b2c4d858779a871aebf0eee97eb", "size": 16443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-10-27.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": "abstract algebra/abstract-notes-2014-10-27.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": "abstract algebra/abstract-notes-2014-10-27.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": 41.1075, "max_line_length": 360, "alphanum_fraction": 0.6363802226, "num_tokens": 6457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8289388062084421, "lm_q1q2_score": 0.6465663751089868}}
{"text": "\\section{Commutative algebra}\\label{sec:commutative_algebra}\n\nCommutative algebra generalizes desirable properties of \\hyperref[def:set_of_integers]{set \\( \\BbbZ \\) of integers} to nontrivial \\hyperref[def:semiring/commutative_unital_ring]{commutative unital rings}. As a result, this allows studying polynomials or even arbitrary functions via techniques similar to those for integers.\n\nIn this whole section, \\( R \\) will refer to a nontrivial commutative unital ring. Since \\( R \\) is commutative, left and right modules over \\( R \\) are equivalent. We will only refer to either of them as simply \\enquote{modules}.\n", "meta": {"hexsha": "35dca3e9245b542d633dc64da9c49e06ea83dea8", "size": 619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/commutative_algebra.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/commutative_algebra.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/commutative_algebra.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": 103.1666666667, "max_line_length": 324, "alphanum_fraction": 0.7915993538, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6465657442441816}}
{"text": "\\begin{quote}\\textit{\n\t``I didn't give it a good notation because I didn't like it.''\n}\\end{quote}\nRecall that last time, we defined sheafification, which can be thought of projecting presheaves onto sheaves in a\nparticularly nice way. This allows us to forget the difference between sheaves and presheaves, so to speak; we'll\nuse this to understand colimits of sheaves.\n\\begin{exm}% would be nice to say what x, i_* are...\nFirst, a quick digression, since we got confused last time, on the espace étalé of a skyscraper sheaf. Directly\nfrom the sheaf axioms, one can show that if \\(\\sF\\) is a \\(\\fC\\)-valued sheaf, then \\(\\sF(\\emptyset)\\) is the\nterminal object (a point for \\(\\Set\\), \\(0\\) for \\(\\Ab\\), and so on). This follows from abstract nonsense: the\nempty product \\(\\prod_\\emptyset S\\) is necessarily the terminal object (there's more to think through here). This\nis what motivates the definition of the skyscraper sheaf \\(i_*S = i_{x,*}S\\) in Example~\\ref{skys}. For\nsimplicity, assume \\(x\\in X\\) is a closed point.\n\nNow, let's construct its espace étalé \\(\\pi:Y_{i_*S}\\to X\\); for any \\(y\\in X\\), \\(\\pi^{-1}(y)\\) is the stalk of\n\\((i_*S)\\) at \\(y\\), which is \\(S\\) if \\(y = x\\) or the terminal object \\(*\\) otherwise. Thus, \\(Y_{i_*S}\\) is as a\nset a copy of \\(X\\), but with \\(S\\) over the basepoint \\(x\\) instead of a single point; then, we glue each of these\npoints of \\(S\\) to the rest of \\(Y_{i_*S}\\) as if they were all \\(x\\). The result is \\(X\\) with multiple\nbasepoints, so to speak, and is not at all Hausdorff. However, as topological spaces, we have a pullback diagram\n\\[\\xymatrix{\n\t(U\\setminus\\set x)\\times S\\ar[r]\\ar[d] & U\\times S\\ar[d]\\\\\n\tU\\setminus\\set x\\ar[r] & Y_{i_*S}.\n}\\]\n\\end{exm}\nWe can also use the espace étalé to define sheafification: the sheafification \\(\\sF\\sh\\) is just the sheaf of\nsections of \\(Y_\\sF\\).\n\\subsection*{Kernels and Cokernels.}\nBefore discussing limits and colimits more generally, let's focus on kernels and cokernels. Let \\(\\vp:\\sF\\to\\sG\\)\nbe a morphism of sheaves of abelian groups on a space \\(X\\), and for every open \\(U\\subset X\\), define\n\\((\\ker\\vp)(U) = \\ker(\\vp|_U)\\). It's easy to check that this is a presheaf, and a little more work to check that\nit's a sheaf, too. And this is actually the kernel in \\(\\Ab_X\\), in that it satisfies the universal property:\nit fits into the diagram\n\\[\\xymatrix{\n\t\\ker\\vp\\ar[r]\\ar[d] & \\sF\\ar[d]^\\vp\\\\\n\t0\\ar[r] & \\sG,\n}\\]\nand any other sheaf \\(\\mathscr H\\) that fits into the same place in the above diagram has a unique map to\n\\(\\ker\\vp\\).\n\nLikewise, a morphism in \\(\\Ab_X\\) is injective (meaning a monomorphism) exactly when\n\\(\\vp|_U:\\sF(U)\\to\\sG(U)\\) is injective for all open \\(U\\subset X\\).\n\nCokernels are a little more interesting. The sheaf assigning \\(U\\mapsto\\coker(\\vp|_U)\\) is a presheaf, and is the\ncokernel in the category of presheaves, but it is \\emph{not} the cokernel in the category of sheaves; it fails to\nsatisfy the universal property. This is where some of the interesting nuances of sheaf theory pop up.\n\\begin{exm}\n\\label{notcoker}\nWe'll let \\(X = \\C\\), and let \\(\\sO\\) be the sheaf of holomorphic functions and \\(\\sO^*\\) be the sheaf of\n``invertible,'' i.e.\\ nonvanishing, holomorphic functions (an abelian group under multiplication). The exponential\nmap \\(f(z)\\mapsto e^{f(z)}\\) sends holomorphic functions to nonvanishing holomorphic functions, and commutes with\nrestriction, so it's a morphism \\(\\exp:\\sO\\to\\sO^*\\) in \\(\\Ab_\\C\\).\n\nIf a function maps to \\(1\\) in \\(\\sO^*\\), then it must be an integer multiple of \\(2\\pi i\\), so it must be locally\nconstant, Thus, it's constant on each connected component of the given open set. Thus, \\(\\ker(\\exp) = 2\\pi\ni\\underline\\Z\\): the constant sheaf, not the constant presheaf. This agrees with what we just learned about\nkernels.\n\nThen, \\(\\Im(\\exp)(U)\\) is the \\(f^*\\in\\sO^*(U)\\) such that \\(f = e^{2\\pi i g}\\) for some \\(g\\in\\sO(U)\\). That is,\n\\(\\log f\\) must have a well-defined branch on \\(U\\). In particular, if \\(U = \\C^*\\) and \\(f = z\\), then\n\\(f\\not\\in\\Im(\\exp(U)\\). This is a problem: \\(\\C^*\\) can be covered by simply connected open sets on which the\nlogarithm exists, but the gluing axiom fails.\n\nHowever, since \\(\\exp:\\sO\\to\\sO^*\\) is surjective on simply connected open sets, then it's surjective on the level\nof stalks, even though it's not surjective as a map of sheaves. In other words, we want the sequence\n\\[\\shortexact[j][\\exp]{\\underline\\Z}{\\sO}{\\sO^*}{}\\]\n%\\[\\xymatrix{\n%\t0\\ar[r] &\\underline\\Z\\ar[r]^j &\\sO\\ar[r]^\\exp & \\sO^{*}\\ar@{-->}[r] & 0\n%}\\]\nto be a short exact sequence of sheaves, but if we naïvely define the cokernel like the kernel, it isn't. This\nmeans that \\emph{to define the sheaf cokernel, we sheafify the presheaf cokernel}. In this case, the sheafification\nof the presheaf cokernel \\(\\coker(j)\\) stitches together the stalks, but on stalks \\(\\exp\\) is surjective, so since\na sheaf is completely determined by stalks, this is just \\(\\sO^*\\) again, which jives with the idea of\nsurjectivity. In the same way, we get that \\(\\coker(\\exp) = 0\\), as one would expect.\n\\end{exm}\nIn other words, a surjective map of sheaves (categorically, an epimorphism), is surjectivity on stalks, but\n\\emph{not} surjectivity on all open subsets. Injectivity is equivalent to injectivity on stalks and on open\nsubsets, though.\n\nSince sheafification preserves colimits, this can be generalized: the colimit of a diagram of sheaves is the\nsheafification of the presheaf colimit (which is just the colimit on every open set).\n\\begin{exm}\nThis next example is in some sense the same example. Let \\(X\\) be a smooth manifold, \\(\\sF\\) be the sheaf of\nsmooth maps to \\(S^1\\), \\(C^\\infty\\) be the smooth maps to \\(\\R\\) (so just the smooth functions), and\n\\(\\underline\\Z\\) is the constant sheaf (which is also smooth maps to \\(\\Z\\), since \\(\\Z\\) is discrete); each of\nthese is a sheaf of abelian groups.\n\nWe'd like to understand that \\(S^1 = \\R/\\Z\\). This comes from the sequence\n\\[\\xymatrix{\n\t0\\ar[r] & \\underline\\Z\\ar[r] & C^\\infty\\ar[r] & \\sF\\ar[r] & 0,\n}\\]\nwhich is short exact. The injectivity of \\(\\underline\\Z\\inj C^\\infty\\) comes from the fact that every map to \\(\\Z\\)\ncan be lifted to a smooth map to \\(\\R\\), and surjectivity comes from the fact that germs of functions can be\nlifted on a small neighborhood, so it's surjective on stalks. However, there are open subsets where functions can't\nbe lifted: if \\(X = S^1\\), then the identity map \\(S^1\\to S^1\\) can't be lifted to a map to \\(\\R\\). Thus, this is\nsurjective, even though it's not so on the level of open sets.\n\\end{exm}\n\\begin{exm}\nOur next example will be the de Rham complex. Let \\(X\\) be a smooth manifold. Let \\(\\underline\\R\\) denote the\nconstant sheaf on \\(\\R\\) (locally constant functions) and \\(\\Omega^1\\) denote the sheaf of one-forms on \\(X\\). The\nexterior derivative gives us an exact sequence\n\\[\\xymatrix{\n\t0\\ar[r] & \\underline\\R\\ar[r] & C^\\infty\\ar[r]^{\\d} & \\Omega^1\\ar[r]^{\\d} & \\Omega^2\\ar[r]^{\\d} &\\dots\n}\\]\nHowever, this is not in general short exact; if \\(\\Omega_{\\text{cl}}^1\\) denotes the space of closed one-forms,\nthen the Poincaré lemma just states that the following sequence is short exact.\n\\[\\xymatrix{\n\t0\\ar[r] & \\underline\\R\\ar[r] & C^\\infty\\ar[r]^{\\d} & \\Omega_{\\text{cl}}^1\\ar[r] & 0\n}\\]\nIn other words, even considering something very simple about short exact sequences of sheaves gives us cohomology.\nThis can be used to define sheaf cohomology, though we won't return to that anytime soon.\n\nIn fact, Example~\\ref{notcoker} is a special case of this, since \\(\\d z/z\\in\\Omega^1(\\C^*)\\) is a closed form\nthat's not exact.\n\\end{exm}\n\\subsection*{Ringed Space.}\nAnyways, we were going to talk about schemes, right? These are not just topological spaces, but ringed spaces:\ntopological spaces with a notion of a ring of functions.\n\\begin{defn}\nA \\term{ringed space} is the data \\((X,\\sO_X)\\), where \\(X\\) is a topological space and \\(\\sO_X\\) is a sheaf of\nrings on \\(X\\).\n\\end{defn}\nThe motivating examples are a topological space with continuous functions to \\(\\R\\) (since these form a ring), or a\nsmooth manifold with the sheaf \\(C^\\infty\\), or an analytic manifold with \\(C^\\omega\\) (analytic functions).  Thus,\nthere are definitely different notions of ``function'' on a manifold, but the ringed space structure means knowing\nwhat kinds of functions (geometric structure) is.\n\nWe'd also like to know how to evaluate functions on a ringed space. For an arbitrary \\(x\\in U\\) and\n\\(f\\in\\sO_X(U)\\), it's not clear how to define \\(f(x)\\); we have stalks, but then what? In each of our examples\n(continuous functions, smooth functions, analytic functions, holomorphic functions, etc.), the stalks \\(\\sO_{X,x}\\)\naren't just rings, but local rings,\\footnote{Recall that a \\term{local ring} is a ring with a unique maximal\nideal.} with the maximal ideal \\(\\m_x\\) of functions which vanish at \\(x\\). \\(\\m_x\\) is unique, because if\n\\(f\\in\\sO_{X,x}\\setminus\\m_x\\), then \\(f(x)\\ne 0\\), so it's nonzero on a neighborhood of \\(x\\), and therefore\ninvertible in that subset! Thus, \\(f\\in\\sO_{X,x}^\\times\\), so \\(\\m_x\\) must be unique.\n\nThe point is, evaluating at \\(x\\) is exactly quotienting by \\(\\m_x\\), producing an element of \\(\\R\\). The sheaves\nwe care about have local rings for stalks, which is what makes this evaluation work. We'll turn this into a\ndefinition of something much more useful than a ringed space.\n\\begin{defn}\nA \\term{locally ringed space} is a ringed space \\((X,\\sO_X)\\) such that for every \\(x\\in X\\), the stalk\n\\(\\sO_{X,x}\\) is a local ring.\n\\end{defn}\nThus, all of our basic examples are locally ringed spaces, and in general, given an \\(f\\in\\sO_X(U)\\), we can define\n\\(V(f) = \\set{x\\in U: f(x) = 0}\\), and this will end up being a closed set.\n\nSchemes are particular examples of locally ringed spaces. We'll have to define how to produce a sheaf of functions,\nwhich we'll probably do next time, but we're almost there. One major takeaway is that schemes behave somewhat like\nthese examples we already have.\n\nWe also need to define morphisms. An isomorphism is evident: \\((X,\\sO_X)\\cong (Y,\\sO_Y)\\) is the data of a\nhomeomorphism \\(f:X\\to Y\\) that identifies the sheaves, i.e.\\ for all open \\(U\\subset Y\\), there's an isomorphism\n\\(f_*: \\sO_Y(U)\\to \\sO_X(f^{-1}(U))\\).\n\nIt's less obvious how to define morphisms in general; clearly, we need a continuous \\(f:X\\to Y\\), and we want to\ncompare \\(\\sO_X\\) and \\(\\sO_Y\\). Functions pull back (because the preimage of an open set is open); in the examples\nwe had before, we checked that the pullbacks of continuous (smooth, etc.) functions were continuous (smooth, etc.).\nMore generally, given an open \\(U\\subset Y\\), we have the two rings \\(\\sO_Y(U)\\) and \\(\\sO_X(f^{-1}(U))\\), and we\nwant the pullback of functions \\(f_*:\\sO_Y(U)\\to\\sO_X(f^{-1}(U))\\) to be a ring homomorphism. This is exactly how\nwe defined the pushforward of a sheaf.\n\\begin{defn}\nA \\term{morphism of ringed spaces} is a pair \\((f,f^\\sharp): (X,\\sO_X)\\to (Y,\\sO_Y)\\) in which\n\\begin{itemize}\n\t\\item \\(f:X\\to Y\\) is continuous, and\n\t\\item \\(f^\\sharp: \\sO_Y\\to f_*\\sO_X\\) is a morphism in \\(\\Ring_Y\\).\n\\end{itemize}\n\\end{defn}\nThat is: for every open subset, we can pull functions back into that open subset. But we can say that more\nconcisely with the sheaf theory we have developed.\n\nIt's worth remembering that nilpotents on affine schemes give us functions that aren't determined by their values\n(well, we do have to set up the structure of a locally ringed space first, but we'll get there), so a function\nisn't quite a bunch of values at points; it's something that we care to pull back.\n\nThis is cool, but we care about ringed spaces. What about these maximal ideals? They tell us what it means for a\nfunction to vanish. Back in the world of smooth functions, if \\(\\vp(y) = 0\\) and \\(x\\in f^{-1}(y)\\), then\n\\((f^*\\vp)(x) = \\vp(f(x))\\) had better be \\(0\\) too. This is not preserved by morphisms of ringed spaces (since\nevaluation isn't defined for germs of functions on ringed spaces), so we need an additional axiom.\n\nIf \\((f,f^\\sharp)\\) is a morphism of ringed spaces, passing to colimits induces a map \\(\\sO_{Y,y}\\to\\sO_{X,x}\\),\nwhenever \\(f(x) = y\\) (this is generally true for a map of sheaves, thanks to the property of colimits). Then, we\nwant this map to send \\(\\m_y\\to\\m_x\\). \n\\begin{defn}\nA morphism \\((f,f^\\sharp):(X,\\sO_X)\\to(Y,\\sO_Y)\\) is a morphism of locally ringed spaces if for every \\(x\\in X\\),\n\\(y\\in Y\\) such that \\(f(x) = y\\), the induced map \\(f^\\sharp_x: \\sO_{Y,y}\\to\\sO_{X,x}\\) maps \\(\\m_y\\) into\n\\(\\m_x\\).\n\\end{defn}\nThis is actually all the data that we'll need to define schemes: schemes are a full subcategory of locally ringed\nspaces; specifically, they are the ones that are locally isomorphic to \\((\\Spec R, \\sO_{\\Spec R})\\) (as soon as we\ndefine the locally ringed space structure on \\(\\Spec R\\)), i.e.\\ there are actual isomorphisms on an open cover.\n\nDoes this look weird? It's actually not unfamiliar: a smooth manifold is a locally ringed space that's locally\nisomorphic to \\((\\R^n,C^\\infty)\\). This encodes a lot of information; in particular, a continuous map of manifolds\nis smooth iff it pulls smooth functions back to smooth functions. In the same way, a topological manifold is a\nlocally ringed space locally isomorphic to \\((\\R^n,C)\\) (the sheaf of continuous functions). All the structure of\nan atlas is encapsulated in this notion of locally ringed spaces.\n\nThis notion is extremely general. For example, we can define a complex analytic manifold to be a locally ringed\nspace locally isomorphic to \\((U\\subset\\C^n, \\operatorname{Hol})\\) (since small discs in \\(\\C^n\\) aren't\nnecessarily biholomorphic to all of \\(\\C^n\\)). In all of the cases we've seen, though, \\(\\sO_X(U)\\) is always a\nsubset of set maps \\(U\\to\\R\\) (or \\(\\C\\)), and in particular functions are determined by their values. This is\nsomething that will not be true for schemes.\n\nNext time, we will define \\(\\Spec R\\), as a scheme.\n", "meta": {"hexsha": "dd1cf83c3f0689b16451ee842621276d70091c40", "size": 13943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/examples/minnotes_d_examples/colimits_of_sheaves.tex", "max_stars_repo_name": "adebray/pset_d", "max_stars_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_stars_repo_licenses": ["MIT"], "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/examples/minnotes_d_examples/colimits_of_sheaves.tex", "max_issues_repo_name": "adebray/pset_d", "max_issues_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_issues_repo_licenses": ["MIT"], "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/examples/minnotes_d_examples/colimits_of_sheaves.tex", "max_forks_repo_name": "adebray/pset_d", "max_forks_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_forks_repo_licenses": ["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.684729064, "max_line_length": 115, "alphanum_fraction": 0.7083841354, "num_tokens": 4303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410784, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6465657404706868}}
{"text": "\\documentclass[a4paper,10pt]{book}\n\n\\usepackage{textcomp}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage[top=0.5in, bottom=0.5in, left=0.5in, right=0.5in]{geometry}\n\\usepackage{setspace}\n\n\\newtheorem{theorem}{Theorem}[chapter]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}[theorem]{Definition}\n\\newtheorem{example}[theorem]{Example}\n\\newtheorem{xca}[theorem]{Exercise}\n\\newtheorem{con}[theorem]{}\n\n\\theoremstyle{remark}\n\\newtheorem{remark}[theorem]{Remark}\n\n\\numberwithin{section}{chapter}\n\\numberwithin{equation}{chapter}\n\n\\begin{document}\n \n \\chapter{Metric Graphs}\n \\section{Graphs: Combinatorical Structure}\n \n \\begin{definition}\n  A graph \\emph{$\\Gamma$} consists of\n  \n  \\begin{itemize}\n   \\item A pair of sets $(V,\\ E)$ (called the `Vertex' and `Edge' sets respectively)\n   \\item An involution  $\\: \\phi \\colon E \\rightarrow E$\n               satisfying $\\phi (e) = \\bar{e} $ and $\\phi\\circ\\phi = \\mathbf{1}_E$ (identity function)\n   \\item Functions $i,\\ \\tau: E \\rightarrow V$ such that $i(\\bar{e}) = \\tau (e) $ and $\\tau(\\bar{e}) = i(e)$\n  \\end{itemize}\n\n \\end{definition}\n\n Insert EXAMPLE 'ERE\n \n \\section{A Graph as a Space}\n\n   The following construction associates to a graph $\\Gamma$, a space $| \\Gamma |$ \n   \\vspace{0.1in} \\\\ Let $ \\xi = E \\times [0,1] = \\{ (e,t) : e \\in E,\\ t \\in [0,1]\\} $.\\\\\n   Let $ \\widetilde{\\Gamma} =  \\xi \\cup V $ \\\\\n   Let `\\texttildelow' be the equivalence relation on $ \\widetilde{\\Gamma} $ generated by: \n   \\begin{itemize}\n      \\item If $ (e,t) \\in \\xi $, then $ (e,t) \\sim (\\bar{e},1-t) $\n      \\item $ \\forall \\ e \\in E $, $ i(e) \\sim (e,0) $ and $ \\tau (e) \\sim (e,1) $\n   \\end{itemize}\n   $ |\\Gamma| $ is the quotient space $ \\Gamma / \\sim $\n   \\section{ Metric structure on a Graph}\n   \n   \\subsection{Distance on the Vertex set V}\n   \\begin{definition}\n      Two vertices $ v_{1}$ and $v_{2} $ are said to be \\emph{adjacent} if there exists $ e \\in E $ such that $ i(e) = v_1 $ and $ \\tau (e) = v_2 $.\n   \\end{definition}\n   Let $ \\cal{D} = \\{ $ d $: V \\times V \\rightarrow \\mathbf{R} \\ : \\ $ \n d is a metric; d($ v_1,\\ v_2 $) $ \\leq $ 1 if $ v_1 $, $ v_2 $ are adjacent $ \\} $\n   \\begin{lemma}\n      $ \\cal{D} $ is not empty\n   \\end{lemma}\n   \\begin{definition}\n      The \\emph{Graph Metric} on V is defined as\n      \\begin{equation}\n\t  d_{max}(v_1,v_2)= \\sup_{d \\in \\cal{D} }d(v_1,v_2) \\nonumber\n      \\end{equation} \n   \\end{definition}\n   \\begin{lemma}\n\t$ d_{max} $ is a metric.\n    \\proof \n    \\begin{enumerate}\n      \\item \\[\\forall \\ x \\in V,\\ d_{max}(x, x)= \\sup_{d \\in \\cal{D}}d(x,x) = \\sup\\{ 0 \\} = 0 \\]\n      \\item \\[\\forall \\ x,\\ y \\in V,\\ d_{max}(x, y)= \\sup_{d \\in \\cal{D} }d(x,y)= \\sup_{d \\in \\cal{D} }d(y,x)  =d _{max}(y, x) \\]\n      \\item \\[ d_{max}(x, z)=\\sup\\{d(x,y): d \\in \\mathcal{D}\\} \\leq \\sup_{}\\{ d(x,y): d \\in \\mathcal{D}\\} {( d \\in \\cal{D} \\text{ is a metric})} \\]\n    \\end{enumerate}    \n  \\end{lemma}\n  \\begin{definition}\n   An \\emph{edge path} is a ordered list (may be null, in whuch case it is a single vertex) of edges- denoted by $ \\eta=(e_1,e_2,\\dots,e_n) $, such that, $ \\forall i,\\ 1\\leq i < n,\\ i(e_i)=\\tau(e_{i+1})$. $\\eta$ is called ``an edge path from $i(e_1)$ to $\\tau(e_n)$''.\n  \\end{definition}\n  \\begin{definition}\n   An edge path is a \\emph{loop} if $i(e_1) = \\tau(e_n)$ \n  \\end{definition}\n  \\begin{definition}\n   An edge path is said to be \\emph{reduced} if $\\forall\\ i,\\ 1\\leq i<n,\\ e_i \\neq \\bar{e}_{i+1}$\n  \\end{definition}\n  \\begin{definition}\n   A graph $\\Gamma$ is \\emph{connected} if $\\forall\\ x,y \\in V,\\ \\exists$ an edge path from x to y.\n  \\end{definition}\n  \\begin{definition}\n   A connected graph is called a \\emph{tree} if it has no reduced edge loops.\n  \\end{definition}\n  \\begin{theorem}\n   Let $\\Gamma$ be a connected graph. Then for x, y $\\in V$,\n   \\begin{equation}\n    d_{max}(x,y)=min\\{n\\geq 0 :\\ \\exists\\ \\text{an edge path from x to y of cardinality }n\\}\n   \\end{equation}\n  \\proof\n  Let $d_{\\Gamma}(x,y)=min\\{n\\geq 0 :\\ \\exists\\ \\text{an edge path from x to y of cardinality }n\\}$.\\\\\n  We shall show:\n  \\begin{enumerate}\n  \n   \\item $d_\\Gamma$ is a metric\n   \\item $d_\\Gamma (i(e),\\tau (e))\\leq 1$ \n   \\item $d_{max}(x,y) \\leq d_\\Gamma(x,y)$\n  \\end{enumerate}\nNow, the first and second points establish that $d_\\Gamma \\in \\mathcal{D} $. Then, $d_{max}$ being the supremum value will imply $d_{max}(x,y) \\geq d_\\Gamma (x,y)$. Together with 3, this will give the desired result. \n  \\begin{lemma}\n   $d_\\Gamma$ is a metric\n   \\proof\n   \\begin{enumerate}\n    \\item \\[d_\\Gamma(x,x) = 0\\] because the single vertex `x' is a null list of edges that give the minimal connecting edge path.\n    \\item \\[d_\\Gamma(x,y) = d_\\Gamma(y,x)\\] Now, in an (undirected) graph, $\\eta$ is a valid edge path iff $\\bar{\\eta}$ is also a valid edge path.\n    \\begin{remark}\n     \\[ \\eta = (e_1,e_2,\\dots,e_n) \\Rightarrow \\bar{\\eta}=(\\bar{e}_n,\\bar{e}_{n-1},\\dots,\\bar{e}_1)\\] \n     If $\\eta$ is an edge path from x to y, $\\bar{\\eta}$ is an edge path fom y to x.\n    \\end{remark}\n    Hence, the involution of the minimal edge path connecting x to y will connect y to x. This will also be the minimal edge path connecting y to x since otherwise the involution of the shorter path (from y to x) will connect x to y and be shorter hat the oiginal path, which leads to a contradiction.\n    \\item If \\[\n              \\eta_1=(e_1,\\dots,e_n) \\text{ is the minimal path connecting x to y}\\] and\\[\n              \\eta_2=(e_{n+1},\\dots,e_m) \\text{ is the minimal path connecting y to z}\n             \\]\n             \\begin{remark}\n              Edges in $\\eta_1$ and $\\eta_2$ need not be distinct.\n             \\end{remark}\n             Then,\\[\n                   \\eta_1 \\circ \\eta_2 = (e_1,e_2,\\dots,e_n,e_{n+1},\\dots,e_m) \\text{ is an edge path connecting x to z}\n                  \\]\n                  Hence the minimal edge path connecting x to z will have to be, by definition, shorter than or the same length as this path. Which means\n                  \\[\n                   d_{max}(x,z)=|\\eta_{min}|\\leq |\\eta_1 \\circ \\eta_2| =m+n =d_{max}(x,y)+d_{max}(y,z)\n                  \\]\n                     \\end{enumerate}\n    This proves that $d_{max}$ is a metric.\n  \\end{lemma}\n  \\begin{lemma}\n    $d_\\Gamma (i(e),\\tau (e))\\leq 1$\n    \\proof Since $(e)$ is an edge path connecting $i(e)$ and $\\tau(e)$, the minimal edge path will have cardinality less than or equal to this. That is,\n    \\[\n      d_{max}(i(e),\\tau(e))\\leq |(e)| = 1\n    \\]\n  \\end{lemma}\n    \\begin{lemma}\n     $d_{max}(x,y) \\leq d_\\Gamma(x,y)$\n    \\proof Let $ d_\\Gamma(x,y) = n$.\n    This means that there exists an edge path $\\eta = (e_1,\\dots,e_n) $ connecting x to y. Now,\n    \\[\n     d_{max}(x,y) \\leq d_{max}(i(e_1,\\tau(e_1)) + \\dots + d_{max}(i(e_n),\\tau(e_n)) \\ \\ \\ \\ \\ \\ \\ \\ \\ \\  \\text{[$d_{max}$ is a metric]}\n    \\]\n    \\[\n     \\leq 1 + \\dots +1=n \\hspace{2in} [d_{max} \\in \\mathcal{D}]\n    \\]\n\n\n  \\end{lemma}\n\n  \\end{theorem}\n\\end{document}\n", "meta": {"hexsha": "1290f6d412b54adb53d47f0a6cf771c6cda9bf0e", "size": 6954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Metric_Graphs.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/Metric_Graphs.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/Metric_Graphs.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": 43.1925465839, "max_line_length": 301, "alphanum_fraction": 0.5956284153, "num_tokens": 2473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.646565733563237}}
{"text": "\\chapter{Quantum states and measurements}\nIn this chapter we'll explain how to set up quantum states using\nlinear algebra. This will allow me to talk about quantum \\emph{circuits}\nin the next chapter, which will set the stage for Shor's algorithm.\n\nI won't do very much physics (read: none at all).\nThat is, I'll only state what the physical reality is in terms\nof linear algebras, and defer the philosophy of why this is true\nto your neighborhood ``Philosophy of Quantum Mechanics'' class\n(which is a ``social science'' class at MIT!).\n\n\\section{Bra-ket notation}\nPhysicists have their own notation for vectors:\nwhereas I previously used something like $v$, $e_1$, and so on,\nin this chapter you'll see the infamous \\vocab{bra-ket} notation:\na vector will be denoted by $\\ket\\bullet$, where $\\bullet$ is some\nvariable name: unlike in math or Python, this can include\nnumbers, symbols, Unicode characters, whatever you like.\nThis is called a ``ket''.\nTo pay a homage to physicists everywhere,\nwe'll use this notation for this chapter too.\n\n\\begin{abuse}\n\t[For this part, $\\dim H < \\infty$]\n\tIn this part on quantum computation,\n\twe'll use the word ``Hilbert space'' as defined earlier,\n\tbut in fact all our Hilbert spaces will be finite-dimensional.\n\\end{abuse}\n\nIf $\\dim H = n$, then its orthonormal basis elements are often denoted\n\\[ \\ket0, \\ket1, \\dots, \\ket{n-1} \\]\n(instead of $e_i$)\nand a generic element of $H$ denoted by\n\\[ \\ket\\psi, \\ket\\phi, \\dots \\]\nand various other Greek letters.\n\nNow for any $\\ket\\psi \\in H$,\nwe can consider the canonical dual element in $H^\\vee$\n(since $H$ has an inner form), which we denote by $\\bra\\psi$ (a ``bra'').\nFor example, if $\\dim H = 2$ then we can write\n\\[ \\ket\\psi = \\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} \\]\nin an orthonormal basis, in which case\n\\[ \\bra\\psi = \\begin{bmatrix} \\ol\\alpha & \\ol\\beta \\end{bmatrix}. \\]\nWe even can write dot products succinctly in this notation:\nif $\\ket\\phi = \\begin{bmatrix} \\gamma \\\\ \\delta \\end{bmatrix}$,\nthen the dot product of $\\ket\\phi$ and $\\ket\\psi$ is given by\n\\[\n\t\\braket{\\psi|\\phi}\n\t= \\cvec{\\ol\\alpha & \\ol\\beta} \\cvec{\\gamma \\\\ \\delta}\n\t= \\ol\\alpha\\gamma + \\ol\\beta \\delta.\n\\]\nSo we will use the notation $\\braket{\\psi|\\phi}$\ninstead of the more mathematical $\\left< \\ket\\psi, \\ket\\phi \\right>$.\nIn particular, the squared norm of $\\ket\\psi$ is just $\\braket{\\psi|\\psi}$.\nConcretely, for $\\dim H = 2$ we have\n$\\braket{\\psi|\\psi} = |\\alpha|^2 + |\\beta|^2$.\n\n\\section{The state space}\nIf you think that's weird, well, it gets worse.\n\nIn classical computation, a bit is either $0$ or $1$.\nMore generally, we can think of a classical space of $n$\npossible states $0$, \\dots, $n-1$.\nThus in the classical situation, the space of possible states\nis just a discrete set with $n$ elements.\n\nIn quantum computation, a \\vocab{qubit} is instead\nany \\emph{complex linear combination} of $0$ and $1$.\nTo be precise, consider the normed complex vector space\n\\[ H = \\CC^{\\oplus 2} \\]\nand denote the orthonormal basis elements by $\\ket0$ and $\\ket1$.\nThen a \\emph{qubit} is a nonzero element $\\ket\\psi \\in H$,\nso that it can be written in the form\n\\[ \\ket\\psi = \\alpha \\ket 0 + \\beta \\ket 1 \\]\nwhere $\\alpha$ and $\\beta$ are not both zero.\nTypically, we normalize so that $\\ket\\psi$ has norm $1$:\n\\[ \\braket{\\psi|\\psi} = 1 \\iff |\\alpha|^2 + |\\beta|^2 = 1. \\]\nIn particular, we can recover the ``classical'' situation\nwith $\\ket 0 \\in H$ and $\\ket 1 \\in H$,\nbut now we have some ``intermediate'' states,\nsuch as \\[ \\frac{1}{\\sqrt2} \\left(\\ket 0 + \\ket 1 \\right). \\]\nPhilosophically, what has happened is that:\n\\begin{moral}\n\tInstead of allowing just the states $\\ket 0$ and $\\ket 1$,\n\twe allow any complex linear combination of them.\n\\end{moral}\nMore generally, if $\\dim H = n$,\nthen the possible states are nonzero elements\n\\[ c_0\\ket0 + c_1\\ket1 + \\dots + c_{n-1}\\ket{n-1} \\]\nwhich we usually normalize so that\n$|c_0|^2 + |c_1|^2 + \\dots + |c_{n-1}|^2 = 1$.\n\n\\section{Observations}\n\\prototype{$\\id$ corresponds to not making a measurement\n\tsince all its eigenvalues are equal,\n\tbut any operator with distinct eigenvalues will cause collapse.}\nIf you think that's weird, well, it gets worse.\nFirst, some linear algebra:\n\\begin{definition}\n\tLet $V$ be a finite-dimensional inner product space.\n\tFor a map $T: V \\to V$, the following conditions are equivalent:\n\t\\begin{itemize}\n\t\t\\ii $\\left< Tx, y\\right> = \\left< x, Ty \\right>$\n\t\tfor any $x,y \\in V$.\n\t\t\\ii $T = T^\\dagger$.\n\t\\end{itemize}\n\tA map $T$ satisfying these conditions is called \\vocab{Hermitian}.\n\\end{definition}\n\\begin{ques}\n\tShow that $T$ is normal.\n\\end{ques}\nThus, we know that $T$ is diagonalizable\nwith respect to the inner form, so for a suitable basis we\ncan write it in an orthonormal basis as\n\\[\n\tT = \\begin{bmatrix}\n\t\t\\lambda_0 & 0 & \\dots & 0 \\\\\n\t\t0 & \\lambda_1 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\t0 & 0 & \\dots & \\lambda_{n-1}\n\t\\end{bmatrix}.\n\\]\nAs we've said, this is fantastic:\nnot only do we have a basis of eigenvectors,\nbut the eigenvectors are pairwise orthogonal,\nand so they form an orthonormal basis of $V$.\n\\begin{ques}\n\tShow that all eigenvalues of $T$ are real.\n\t($T = T^\\dagger$.)\n\\end{ques}\n\nBack to quantum computation.\nSuppose we have a state $\\ket\\psi \\in H$, where $\\dim H = 2$;\nwe haven't distinguished a particular basis yet,\nso we just have a nonzero vector.\nThen the way observations work (and this is physics, so you'll have to\ntake my word for it) is as follows:\n\\begin{moral}\n\tPick a Hermitian operator $T : H \\to H$;\n\tthen observations of $T$ return eigenvalues of $T$.\n\\end{moral}\nTo be precise:\n\\begin{itemize}\n\t\\ii Pick a Hermitian operator $T : H \\to H$,\n\twhich is called the \\vocab{observable}.\n\t\\ii Consider its eigenvalues $\\lambda_0$, \\dots, $\\lambda_{n-1}$\n\tand corresponding eigenvectors $\\ket{0}_T$, \\dots, $\\ket{n-1}_T$.\n\tTacitly we may assume that $\\ket{0}_T$, \\dots, $\\ket{n-1}_T$ form\n\tan orthonormal basis of $H$.\n\t(The subscript $T$ is here to distinguish the eigenvectors of $T$\n\tfrom the basis elements of $H$.)\n\t\\ii Write $\\ket\\psi$ in the orthonormal basis as\n\t\\[ c_0\\ket0_T + c_1\\ket1_T + \\dots + c_{n-1}\\ket{n-1}_T. \\]\n\t\\ii Then the probability of observing $\\lambda_i$ is\n\t\\[ \\frac{|c_i|^2}{|c_0|^2 + \\dots + |c_{n-1}|^2}. \\]\n\tThis is called making an \\vocab{observation along $T$}.\n\\end{itemize}\nNote that in particular, for any nonzero constant $c$,\n$\\ket\\psi$ and $c\\ket\\psi$ are indistinguishable,\nwhich is why we like to normalize $\\ket\\psi$.\nBut the queerest thing of all is what happens to $\\ket\\psi$:\nby measuring it, we actually destroy information.\nThis behavior is called \\vocab{quantum collapse}.\n\\begin{itemize}\n\t\\ii Suppose for simplicity that we observe $\\ket\\psi$\n\twith $T$ and obtain an eigenvalue $\\lambda$,\n\tand that $\\ket{i}_T$ is the only eigenvector with this eigenvalue.\n\tThen, the state $\\ket\\psi$ \\emph{collapses} to just the state\n\t$c_i \\ket{i}_T$: all the other information is destroyed.\n\t(In fact, we may as well say it collapses to $\\ket{i}_T$,\n\tsince again constant factors are not relevant.)\n\n\t\\ii\tMore generally, if we observe $\\lambda$,\n\tconsider the generalized eigenspace $H_\\lambda$\n\t(i.e.\\ the span of eigenvectors with the same eigenvalue).\n\tThen the physical state $\\ket\\psi$ has been changed as well:\n\tit has now been projected onto the eigenspace $H_\\lambda$.\n\tIn still other words, after observation, the state collapses to\n\t\\[\n\t\t\\sum_{\\substack{0 \\le i \\le n \\\\ \\substack{\\lambda_i = \\lambda}}}\n\t\tc_i \\ket{i}_T.\n\t\\]\n\\end{itemize}\nIn other words,\n\\begin{moral}\n\tWhen we make a measurement,\n\tthe coefficients from different eigenspaces are destroyed.\n\\end{moral}\nWhy does this happen? Beats me\\dots physics (and hence real life) is weird.\nBut anyways, an example.\n\\begin{example}\n\t[Quantum measurement of a state $\\ket\\psi$]\n\tLet $H = \\CC^{\\oplus 2}$ with orthonormal basis $\\ket0$ and $\\ket1$\n\tand consider the state\n\t\\[\n\t\t\\ket\\psi\n\t\t= \\frac{i}{\\sqrt5} \\ket 0\n\t\t+ \\frac{2}{\\sqrt5} \\ket 1\n\t\t= \\pair{i/\\sqrt5}{2/\\sqrt5} \\in H.\n\t\\]\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let \\[ T = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}. \\]\n\t\tThis has eigenvectors $\\ket0 = \\ket0_T$ and $\\ket1 = \\ket1_T$,\n\t\twith eigenvalues $+1$ and $-1$.  So if we measure $\\ket\\psi$ to $T$,\n\t\twe get $+1$ with probability $1/5$ and $-1$ with probability $4/5$.\n\t\tAfter this measurement, the original state collapses to\n\t\t$\\ket0$ if we measured $+1$, and $\\ket1$ if we measured $-1$.\n\t\tSo we never learn the original probabilities.\n\n\t\t\\ii Now consider $T = \\id$, and arbitrarily\n\t\tpick two orthonormal eigenvectors $\\ket0_T$, $\\ket1_T$;\n\t\tthus $\\psi = c_0\\ket0_T + c_1\\ket1_T$.\n\t\tSince all eigenvalues of $T$ are $+1$,\n\t\tour measurement will always be $+1$ no matter what we do.\n\t\tBut there is also no collapsing,\n\t\tbecause none of the coefficients get destroyed.\n\n\t\t\\ii Now consider\n\t\t\\[ T = \\begin{bmatrix} 0 & 7 \\\\ 7 & 0 \\end{bmatrix}. \\]\n\t\tThe two normalized eigenvectors are\n\t\t\\[ \\ket0_T = \\frac{1}{\\sqrt2}\\pair11\n\t\t\\qquad \\ket1_T = \\frac{1}{\\sqrt2}\\pair1{-1} \\]\n\t\twith eigenvalues $+7$ and $-7$ respectively. In this basis, we have\n\t\t\\[\n\t\t\t\\ket\\psi = \\frac{2+i}{\\sqrt{10}}\\ket0_T\n\t\t\t+ \\frac{-2+i}{\\sqrt{10}}\\ket1_T. \\]\n\t\tSo we get $+7$ with probability $\\half$ and $-7$\n\t\twith probability $\\half$, and after the measurement,\n\t\t$\\ket\\psi$ collapses to one of $\\ket0_T$ and $\\ket1_T$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{ques}\n\tSuppose we measure $\\ket\\psi$ with $T$ and get $\\lambda$.\n\tWhat happens if we measure with $T$ again?\n\\end{ques}\n\nFor $H = \\CC^{\\oplus 2}$ we can come up with more classes of examples using\nthe so-called \\vocab{Pauli matrices}.\nThese are the three Hermitian matrices\n\\[\n\t\\sigma_z = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}\n\t\\qquad\n\t\\sigma_x = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}\n\t\\qquad\n\t\\sigma_y = \\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}.\n\\]\nThese matrices are important because:\n\\begin{ques}\n\tShow that these three matrices, plus the identity matrix,\n\tform a basis for the set of Hermitian $2 \\times 2$ matrices.\n\\end{ques}\nSo the Pauli matrices are a natural choice of basis.\n\nTheir normalized eigenvectors are\n\\[ \\zup = \\ket0 = \\pair10 \\qquad \\zdown = \\ket1 = \\pair01 \\]\n\\[ \\xup = \\frac{1}{\\sqrt2}\\pair11\n\t\\qquad \\xdown = \\frac{1}{\\sqrt2}\\pair1{-1} \\]\n\\[ \\yup = \\frac{1}{\\sqrt2}\\pair1i\n\t\\qquad \\ydown = \\frac{1}{\\sqrt2}\\pair1{-i} \\]\nwhich we call ``$z$-up'', ``$z$-down'',\n``$x$-up'', ``$x$-down'', ``$y$-up'', ``$y$-down''.\n(The eigenvalues are $+1$ for ``up'' and $-1$ for ``down''.)\nSo, given a state $\\ket\\psi \\in \\CC^{\\oplus 2}$\nwe can make a measurement with respect to any of these three bases\nby using the corresponding Pauli matrix.\n\nIn light of this, the previous examples were\n(a) measuring along $\\sigma_z$,\n(b) measuring along $\\id$,\nand (c) measuring along $7\\sigma_x$.\n\nNotice that if we are given a state $\\ket\\psi$,\nand are told in advance that it is either $\\xup$ or $\\xdown$\n(or any other orthogonal states)\nthen we are in what is more or less a classical situation.\nSpecifically, if we make a measurement along $\\sigma_x$,\nthen we find out which state that $\\ket\\psi$ was in (with 100\\% certainty),\nand the state does not undergo any collapse.\nThus, orthogonal states are reliably distinguishable.\n\n\\section{Entanglement}\n\\prototype{Singlet state: spooky action at a distance.}\nIf you think that's weird, well, it gets worse.\n\nQubits don't just act independently:\nthey can talk to each other by means of a \\emph{tensor product}.\nExplicitly, consider \\[ H = \\CC^{\\oplus 2} \\otimes \\CC^{\\oplus 2} \\]\nendowed with the norm described in \\Cref{prob:inner_prod_tensor}.\nOne should think of this as a qubit $A$ in a space $H_A$\nalong with a second qubit $B$ in a different space $H_B$,\nwhich have been allowed to interact in some way,\nand $H = H_A \\otimes H_B$ is the set of possible states of \\emph{both} qubits.\nThus\n\\[ \n\t\\ket{0}_A \\otimes \\ket{0}_B, \\quad\n\t\\ket{0}_A \\otimes \\ket{1}_B, \\quad\n\t\\ket{1}_A \\otimes \\ket{0}_B, \\quad\n\t\\ket{1}_A \\otimes \\ket{1}_B\n\\]\nis an orthonormal basis of $H$;\nhere $\\ket{i}_A$ is the basis of the first $\\CC^{\\oplus 2}$\nwhile $\\ket{i}_B$ is the basis of the second $\\CC^{\\oplus 2}$,\nso these vectors should be thought of as ``unrelated''\njust as with any tensor product.\nThe pure tensors mean exactly what you want:\nfor example $\\ket0_A \\otimes \\ket1_B$ means\n``$0$ for qubit $A$ and $1$ for qubit $B$''.\n\nAs before, a measurement of a state in $H$ requires\na Hermitian map $H \\to H$.\nIn particular, if we only want to measure the qubit $B$ along $M_B$,\nwe can use the operator \\[ \\id_A \\otimes M_B. \\]\nThe eigenvalues of this operator coincide with the ones for $M_B$,\nand the eigenspace for $\\lambda$ will be the $H_A \\otimes (H_B)_\\lambda$,\nso when we take the projection the $A$ qubit will be unaffected.\n\nThis does what you would hope for pure tensors in $H$:\n\\begin{example}[Two non-entangled qubits]\n\tSuppose we have qubit $A$ in the state\n\t$\\frac{i}{\\sqrt5}\\ket0_A + \\frac{2}{\\sqrt5}\\ket1_A$\n\tand qubit $B$ in the state\n\t$\\frac{1}{\\sqrt2} \\ket0_B + \\frac{1}{\\sqrt2}\\ket1_B$.\n\tSo, the two qubits in tandem are represented by the pure tensor\n\t\\[\n\t\t\\ket\\psi\n\t\t=\n\t\t\\left( \\frac{i}{\\sqrt5}\\ket0_A + \\frac{2}{\\sqrt5}\\ket1_A \\right)\n\t\t\\otimes\n\t\t\\left( \\frac{1}{\\sqrt2} \\ket0_B + \\frac{1}{\\sqrt2}\\ket1_B \\right).\n\t\\]\n\tSuppose we measure $\\ket\\psi$ along\n\t\\[ M = \\id_A \\otimes \\sigma_z^B. \\]\n\tThe eigenspace decomposition is\n\t\\begin{itemize}\n\t\t\\ii $+1$ for the span of $\\ket0_A \\otimes \\ket0_B$ and\n\t\t$\\ket1_A \\otimes \\ket0_B$, and\n\t\t\\ii $-1$ for the span of $\\ket0_A \\otimes \\ket1_B$ and\n\t\t$\\ket1_A \\otimes \\ket1_B$.\n\t\\end{itemize}\n\t(We could have used other bases, like $\\xup_A \\otimes \\ket0_B$ and\n\t$\\xdown_A \\otimes \\ket0_B$ for the first eigenspace, but it doesn't matter.)\n\tExpanding $\\ket\\psi$ in the four-element basis, we find that\n\twe'll get the first eigenspace with probability\n\t\\[ \\left|\\frac{i}{\\sqrt{10}}\\right|^2\n\t+ \\left|\\frac{2}{\\sqrt{10}}\\right|^2 = \\half. \\]\n\tand the second eigenspace with probability $\\half$ as well.\n\t(Note how the coefficients for $A$ don't do anything!)\n\tAfter the measurement, we destroy the coefficients of the other eigenspace;\n\tthus (after re-normalization) we obtain the collapsed state\n\t\\[ \\left( \\frac{i}{\\sqrt5}\\ket0_A + \\frac{2}{\\sqrt5}\\ket1_A \\right)\n\t\t\\otimes \\ket0_B\n\t\t\\qquad\\text{or}\\qquad\n\t\t\\left( \\frac{i}{\\sqrt5}\\ket0_A + \\frac{2}{\\sqrt5}\\ket1_A \\right)\n\t\t\\otimes \\ket1_B\n\t\\]\n\tagain with 50\\% probability each.\n\\end{example}\nSo this model lets us more or less work with the two qubits independently:\nwhen we make the measurement, we just make sure to not touch the other qubit\n(which corresponds to the identity operator).\n\n\\begin{exercise}\n\tShow that if $\\id_A \\otimes \\sigma_x^B$ is applied to the $\\ket\\psi$\n\tin this example, there is no collapse at all.\n\tWhat's the result of this measurement?\n\\end{exercise}\n\nSince the $\\otimes$ is getting cumbersome to write, we say:\n\\begin{abuse}\n\tFrom now on $\\ket 0_A \\otimes \\ket 0_B$ will be abbreviated\n\tto just $\\ket{00}$, and similarly for $\\ket{01}$, $\\ket{10}$, $\\ket{11}$.\n\\end{abuse}\n\n\\begin{example}\n\t[Simultaneously measuring a general $2$-Qubit state]\n\t\\label{ex:simult_measurement}\n\tConsider a normalized state $\\ket\\psi$ in\n\t$H = \\CC^{\\oplus 2} \\otimes \\CC^{\\oplus 2}$, say\n\t\\[ \\ket\\psi = \\alpha\\ket{00} + \\beta\\ket{01}\n\t\t+ \\gamma\\ket{10} + \\delta\\ket{11}. \\]\n\tWe can make a measurement along the diagonal matrix\n\t$T : H \\to H$ with \n\t\\[ T(\\ket{00}) = 0\\ket{00}, \\quad\n\tT(\\ket{01}) = 1\\ket{01}, \\quad\n\tT(\\ket{10}) = 2\\ket{10}, \\quad\n\tT(\\ket{11}) = 3\\ket{11}. \\]\n\tThus we get each of the eigenvalues $0$, $1$, $2$, $3$\n\twith probability $|\\alpha|^2$, $|\\beta|^2$, $|\\gamma|^2$, $|\\delta|^2$.\n\tSo if we like we can make ``simultaneous'' measurements on two qubits\n\tin the same way that we make measurements on one qubit.\n\\end{example}\n\nHowever, some states behave very weirdly.\n\\begin{example}[The singlet state]\n\tConsider the state\n\t\\[\n\t\t\\ket{\\Psi_-}\n\t\t=\n\t\t\\frac{1}{\\sqrt2} \\ket{01}\n\t\t- \\frac{1}{\\sqrt2} \\ket{10}\n\t\\]\n\twhich is called the \\vocab{singlet state}.\n\tOne can see that $\\ket{\\Psi_-}$ is not a simple tensor,\n\twhich means that it doesn't just consist of two qubits side by side:\n\tthe qubits in $H_A$ and $H_B$ have become \\emph{entangled}.\n\n\tNow, what happens if we measure just the qubit $A$?\n\tThis corresponds to making the measurement\n\t\\[ T = \\sigma_z^A \\otimes \\id_B. \\]\n\tThe eigenspace decomposition of $T$ can be described as:\n\t\\begin{itemize}\n\t\t\\ii The span of $\\ket{00}$ and $\\ket{01}$, with eigenvalue $+1$.\n\t\t\\ii The span of $\\ket{10}$ and $\\ket{11}$, with eigenvalue $-1$.\n\t\\end{itemize}\n\tSo one of two things will happen:\n\t\\begin{itemize}\n\t\t\\ii With probability $\\half$, we measure $+1$\n\t\tand the collapsed state is $\\ket{01}$.\n\t\t\\ii With probability $\\half$, we measure $-1$\n\t\tand the collapsed state is $\\ket{10}$.\n\t\\end{itemize}\n\tBut now we see that measurement along $A$ has told us what the\n\tstate of the bit $B$ is completely!\n\\end{example}\nBy solely looking at measurements on $A$, we learn $B$;\nthis paradox is called \\emph{spooky action at a distance},\nor in Einstein's tongue, \\vocab{spukhafte Fernwirkung}.  \nThus,\n\\begin{moral}\n\tIn tensor products of Hilbert spaces,\n\tstates which are not pure tensors\n\tcorrespond to ``entangled'' states.\n\\end{moral}\n\nWhat this really means is that the qubits cannot be described independently;\nthe state of the system must be given as a whole.\nThat's what entangled states mean: the qubits somehow depend on each other.\n\n\\section\\problemhead\n\n\\begin{problem}\n\tWe measure $\\ket{\\Psi_-}$ by $\\sigma_x^A \\otimes \\id_B$,\n\tand hence obtain either $+1$ or $-1$.\n\tDetermine the state of qubit $B$ from this measurement.\n\t\\begin{hint}\n\t\tRewrite $\\ket{\\Psi_-} = -\\frac{1}{\\sqrt2}\n\t\t\\left( \\xup_A\\otimes\\xdown_B - \\xdown_A\\xup_B \\right)$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tBy a straightforward computation, \n\t\twe have $\\ket{\\Psi_-} = -\\frac{1}{\\sqrt2}\n\t\t\\left( \\xup_A\\otimes\\xdown_B - \\xdown_A\\xup_B \\right)$.\n\t\tNow, $\\xup_A \\otimes \\xup_B$, $\\xup_A \\otimes \\xdown_B$\n\t\tspan one eigenspace of $\\sigma_x^A \\otimes \\id_B$,\n\t\tand $\\xdown_A \\otimes \\xup_B$, $\\xdown_A \\otimes \\xdown_B$\n\t\tspan the other. So this is the same as before:\n\t\t$+1$ gives $\\xdown_B$ and $-1$ gives $\\xdown_A$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Greenberger-Horne-Zeilinger paradox]\n\tConsider the state in $(\\CC^{\\oplus2})^{\\otimes 3}$\n\t\\[\n\t\t\\ket{\\Psi}_{\\text{GHZ}}\n\t\t=\n\t\t\\frac{1}{\\sqrt2}\n\t\t\\left( \\ket0_A \\ket0_B \\ket0_C\n\t\t- \\ket1_A \\ket1_B \\ket1_C \\right).\n\t\\]\n\tFind the value of the measurements along each of\n\t\\[ \\sigma_y^A \\otimes \\sigma_y^B \\otimes \\sigma_x^C , \\quad\n\t\t\\sigma_y^A \\otimes \\sigma_x^B \\otimes \\sigma_y^C, \\quad\n\t\t\\sigma_x^A \\otimes \\sigma_y^B \\otimes \\sigma_y^C, \\quad\n\t\t\\sigma_x^A \\otimes \\sigma_x^B \\otimes \\sigma_x^C.\n\t\\]\n\tAs for the paradox: what happens if you multiply all these measurements together?\n\t\\begin{hint}\n\t\t$-1$, $1$, $1$, $1$.\n\t\tWhen we multiply them all together,\n\t\twe get that $\\id^A \\otimes \\id^B \\otimes \\id^C$\n\t\thas measurement $-1$, which is the paradox.\n\t\tWhat this means is that the values of the measurements\n\t\tare created when we make the observation,\n\t\tand not prepared in advance.\n\t\\end{hint}\n\\end{problem}\n", "meta": {"hexsha": "c0f60f65d45279cddaa28dbd4f613411f90fee63", "size": 19142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/quantum/vectors.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/vectors.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/vectors.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": 39.2254098361, "max_line_length": 82, "alphanum_fraction": 0.6885382928, "num_tokens": 6409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.646531144525994}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{The Buffalo Way}\\label{sec:buffalo}\n\t\\index{The buffalo way}\\emph{The buffalo way} is a \\emph{bashing} method of solving inequality problems. It usually exploits symmetry or cyclic property and involves tedious calculations, so it is not always elegant. Nonetheless it is a useful tool. The idea is to assume something like $a\\leq b\\leq c$ without losing any generality, specially when there is symmetry. In general, we want to assume that\n\t\t\\begin{align*}\n\t\t\ta_1\n\t\t\t\t& \\leq a_2\\leq\\cdots\\leq a_n\\\\\n\t\t\ta_2\n\t\t\t\t& = a_1+b_1\\\\\n\t\t\t\t& \\vdots\\\\\n\t\t\ta_n\n\t\t\t\t& = a_1+b_n\n\t\t\\end{align*}\n\tWe can also assume the following.\n\t\t\\begin{align*}\n\t\t\ta_2\n\t\t\t\t& = a_1+c_1\\\\\n\t\t\ta_3\n\t\t\t\t& = a_2+c_2\\\\\n\t\t\t\t& = a_1+c_1+c_2\\\\\n\t\t\t\t& \\vdots\\\\\n\t\t\ta_n\n\t\t\t\t& = a_{n-1}+c_{n-1}\\\\\n\t\t\t\t& = a_1+c_1+\\ldots+c_{n-1}\n\t\t\\end{align*}\n\twhere $c_1,\\ldots,c_{n-1}\\geq0$. Out of these two forms, the latter is actually a consequence of the former one and is usually the more used one. We will see a few problems that implement this technique.\n\t\t\\begin{problem}\n\t\t\tProve that for two non-negative reals $x,y$\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx+y\n\t\t\t\t\t\t& \\geq2\\sqrt{xy}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{solution}\n\t\t\tSince the inequality is symmetric on $x$ and $y$, we can assume without loss of generality that $x\\leq y$. Let $y=x+k$.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx+y\n\t\t\t\t\t\t& \\geq2\\sqrt{xy}\\\\\n\t\t\t\t\t\\iff2x+k\n\t\t\t\t\t\t& \\geq2\\sqrt{x(x+k)}\\\\\n\t\t\t\t\t\\iff4x^2+4xk+k^2\n\t\t\t\t\t\t& \\geq4x^2+4xk\\\\\n\t\t\t\t\t\\iff k^2\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\twhich is evident.\n\t\t\\end{solution}\n\tTry proving the case $n=3$ of arithmetic-geometric mean inequality with this technique. You will understand why we said this is often a tedious technique.\n\t\t\\begin{problem}\n\t\t\t\\begin{align*}\n\t\t\t\tx+y+z\n\t\t\t\t\t& \\geq3\\sqrt[3]{xyz}\n\t\t\t\\end{align*}\n\t\t\\end{problem}\n\tLet us also prove the following using buffalo way.\n\t\t\\begin{problem}\n\t\t\tLet $a,b,c>0$ be real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ta^2+b^2+c^2\n\t\t\t\t\t\t& \\geq ab+bc+ca\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{solution}\n\t\t\tAssume that $a\\leq b\\leq c$ and $b=a+x,c=a+x+y$ where $x,y\\geq0$.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ta^2+(a+x)^2+(a+x+y)^2\n\t\t\t\t\t\t& \\geq a(a+x)+(a+x)(a+x+y)+(a+x+y)a\\\\\n\t\t\t\t\t\\iff 3a^2+2x^2+y^2+4ax+2xy+2ay\n\t\t\t\t\t\t& \\geq 3a^2+x^2+4ax+2ay+2xy\\\\\n\t\t\t\t\t\\iff x^2+y^2\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\tThis is again true.\n\t\t\\end{solution}\n\t\n\t\t\\begin{problem}\n\t\t\tLet $a,b,c\\geq0$ be real numbers such that $a\\leq b\\leq c$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a+b)(c+a)^2\n\t\t\t\t\t\t& \\geq6abc\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{solution}\n\t\t\tSince $a\\leq b\\leq c$, let $b=a+x,c=a+x+y$.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(2a+x)(2a+x+y)^2\n\t\t\t\t\t\t& \\geq6a(a+x)(a+x+y)\\\\\n\t\t\t\t\t\\iff(2a+x)(4a^2+x^2+y^2+4ax+4ay+2xy)\n\t\t\t\t\t\t& \\geq6a(a^2+2ax+x^2+ay+xy)\\\\\n\t\t\t\t\t\\iff8a^3+12a^2x+8a^2y+6ax^2+8axy+2ay^2+x^3+2ax^2+xy^2\n\t\t\t\t\t\t& \\geq6a^3+12a^2+6ax^2+6a^2y+6axy\\\\\n\t\t\t\t\t\\iff 2a^3+2a^2y+2axy+2ay^2+x^3+2x^2y+xy^2\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\tThis evidently true.\n\t\t\\end{solution}\n\tNow, we will prove Nesbitt's inequality using the first form of the buffalo way.\n\t\t\\begin{proof}[Proof of Nesbitt's inequality by the buffalo way]\n\t\t\tLet $x\\leq y\\leq z$ and $y=x+a,z=y+b$ with $a\\geq0,b\\geq0$. We are required to prove that\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\\dfrac{3}{2}\n\t\t\t\t\\end{align*}\n\t\t\tLet us express each variable as a parameter of a single variable.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{y-a}{2y+b}+\\dfrac{y}{2y+b-a}+\\dfrac{y+b}{2y-a}\n\t\t\t\t\t\t& \\geq\\dfrac{3}{2}\\\\\n\t\t\t\t\t\\iff\\dfrac{y-a}{2y+b}-\\dfrac{1}{2}+\\dfrac{y}{2y+b-a}-\\dfrac{1}{2}+\\dfrac{y+b}{2y-a}-\\dfrac{1}{2}\n\t\t\t\t\t\t& \\geq0\\\\\n\t\t\t\t\t\\iff\\dfrac{1}{2}\\left(\\dfrac{2y-2a-2y-b}{2y+b}+\\dfrac{2y-2y-b+a}{2y+b-a}+\\dfrac{2y+2b-2y+a}{2y-a}\\right)\n\t\t\t\t\t\t& \\geq0\\\\\n\t\t\t\t\t\\iff-\\dfrac{2a+b}{2y+b}+\\dfrac{a-b}{2y+b-a}+\\dfrac{2b+a}{2y-a}\n\t\t\t\t\t\t& \\geq0\n\t\t\t\t\\end{align*}\n\t\t\tThe last inequality actually holds because of the following:\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{2b+a}{2y-a}+\\dfrac{a-b}{2y+b-a}-\\dfrac{2a+b}{2y+b}\n\t\t\t\t\t\t& \\geq\\dfrac{2b+a}{2y+b-a}+\\dfrac{a-b}{2y+b-a}-\\dfrac{2a+b}{2y+b}\\\\\n\t\t\t\t\t\t& \\geq\\dfrac{2a+2b}{2y+b-a}-\\dfrac{2a+b}{2y+b}\\\\\n\t\t\t\t\t\t& \\geq\\dfrac{2a+2b}{2y+b}-\\dfrac{2a+b}{2y+b}\\\\\n\t\t\t\t\t\t& = \\dfrac{a}{2y+b}\n\t\t\t\t\\end{align*}\n\t\t\twhich is obviously at least $0$. Here, we have used the facts that $\\frac{1}{x}\\geq\\frac{1}{y}$ implies $\\frac{1}{x-u}\\geq\\frac{1}{y}$ and $\\frac{1}{x}\\geq\\frac{1}{y+v}$ for $u,v\\geq0$.\n\t\t\\end{proof}\n\tThe next inequality is a nice application of the buffalo way.\n\t\t\\begin{problem}\n\t\t\tLet $x,y,z>0$ be real numbers such that no two are equal. Show that,\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{(x-y)^2}+\\dfrac{1}{(y-z)^2}+\\dfrac{1}{(z-x)^2}\n\t\t\t\t\t\t& \\geq\\dfrac{4}{xy+yz+zx}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{solution}\n\t\t\tThe expression on the left is symmetric on $x,y,z$. Without loss of generality, assume that $x\\leq y\\leq z$ and $y=x+a,z=x+a+b$.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{a^2}+\\dfrac{1}{b^2}+\\dfrac{1}{(a+b)^2}\n\t\t\t\t\t\t& \\geq\\dfrac{4}{x(x+a)+(x+a)(x+a+b)+(x+a+b)x}\\\\\n\t\t\t\t\t\t& = \\dfrac{4}{x^2+xa+x^2+2ax+a^2+bx+ab+x^2+xa+bx}\\\\\n\t\t\t\t\t\t& \\geq \\dfrac{4}{3x^2+4xa+2xb+ab+a^2}\n\t\t\t\t\\end{align*}\n\t\t\tNote that there is no $x$ on the left side of the inequality. So, we can use $x>0$ to get rid of it.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t3x^2+4xa+2xb+ab+a^2\n\t\t\t\t\t\t& > ab+a^2\\\\\n\t\t\t\t\t\\dfrac{4}{3x^2+4xa+2xb+ab+a^2}\n\t\t\t\t\t\t& <\\dfrac{4}{ab+a^2}\n\t\t\t\t\\end{align*}\n\t\t\tSo, we are done if we can prove the following.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{a^2}+\\dfrac{1}{b^2}+\\dfrac{1}{(a+b)^2}\n\t\t\t\t\t\t& \\geq\\dfrac{4}{ab+a^2}\\\\\n\t\t\t\t\t\t& = \\dfrac{4}{a(b+a)}\n\t\t\t\t\\end{align*}\n\t\t\tThis is not a trivial inequality. We have to show that this actually holds.\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{a^2}+\\dfrac{1}{b^2}-\\dfrac{2}{a(b+a)}+\\dfrac{1}{(a+b)^2}\n\t\t\t\t\t\t& \\geq\\dfrac{2}{a(b+a)}\\\\\n\t\t\t\t\t\\iff\\dfrac{1}{b^2}+\\left(\\dfrac{1}{a}-\\dfrac{1}{a+b}\\right)^2\n\t\t\t\t\t\t& \\geq\\dfrac{2}{a(a+b)}\\\\\n\t\t\t\t\t\\iff\\dfrac{1}{b^2}+\\left(\\dfrac{b}{a(a+b)}\\right)^2\n\t\t\t\t\t\t& \\geq\\dfrac{2}{a(a+b)}\\\\\n\t\t\t\t\t\\iff\\dfrac{1}{b^2}+\\dfrac{b^2}{a^2(a+b)^2}\n\t\t\t\t\t\t& \\geq\\dfrac{2}{a(a+b)}\n\t\t\t\t\\end{align*}\n\t\t\tThe last inequality is true by arithmetic-geometric mean inequality since\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{b^2}+\\dfrac{b^2}{a^2(a+b)^2}\n\t\t\t\t\t\t& \\geq2\\sqrt{\\dfrac{1}{b^2}\\cdot\\dfrac{b^2}{a^2(a+b)^2}}\\\\\n\t\t\t\t\t\t& = \\dfrac{2}{a(a+b)}\n\t\t\t\t\\end{align*}\n\t\t\\end{solution}\n\tSolve the next problem as an exercise.\n\t\t\\begin{problem}\n\t\t\tFor all real $x,y,z\\geq0$, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x^3+y^3+z^3}{x^2y+y^2z+z^2x}\n\t\t\t\t\t\t& \\geq\\sum\\dfrac{x}{y+z}-1\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "17edb08652a5e9a81effa21a12b764aa7ac5819a", "size": 6572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "buffalo.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": "buffalo.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": "buffalo.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": 35.5243243243, "max_line_length": 403, "alphanum_fraction": 0.5786670724, "num_tokens": 2963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.6465311353023657}}
{"text": "\\section{Fat Tails}\nRoughly speaking, the consequences of ``fat tails\" is that rare events tend to play a disproportionally large role in determining the statistical properties of a sample. This is in contrast to ``thin tails\", where, as the sample size increases, pretty quickly no single observation modifies the statistical properties of the sample.\n\nFor ``thin tails\", extreme observations tend to result from the combination of several very unlikely events. For ``fat tails\", an extreme observation tend result from a single very unlikely event. \n\n\\subparagraph{Thin Tails}\nTwo people are randomly selected, and their combined height is 4 meters. Most likely this resulted from the selection of two people who are two meters tall, rather than one person that is 10 cm and another that is 3,90 m tall. \n\n\\subparagraph{Fat Tails}\nTwo people are randomly selected, and their combined net worth is \\$ 40M. The probability of having selected two people with a net work of \\$ 20M is less likely than having selected one person with a net worth of \\$ 200k and another person with a net worth of \\$ 39,8 M. \n\nFat tails do not imply that rare events are more frequent, but that they have greater impact when they do happen. In fact, ``fattening\" the tails of a Gaussian distribution results in a larger number of observations within one standard deviation. \n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{fattails01.png}\n    \\caption{Probability densities of two independent thin tailed and thick tailed random variables (brazenly copied from Taleb, 2020). Compare to plot of Lp norms. For the thin tailed random variables, the observa- tion of a particular sum is most likely to result from a balanced contribution from both random variables. For the fat tailed random variables, the observation of a particular sum is most likely to result from the contribution of one of the variables.}\n    \\label{fig:fattails01}\n\\end{figure}\n\n\\subsection{Consequences of Fat Tails}\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{fattailstudentt02.png}\n    \\caption{Behavior of the sample mean as a function of sample size for standard Student-t distributions with different degrees of freedom.}\n    \\label{fig:fattails02}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{fattailsstudentt01.png}\n    \\caption{Behavior of the variance of the sample mean as a function of sample size for standard Student-t distributions with different degrees of freedom.}\n    \\label{fig:fattails03}\n\\end{figure}\n\n\n\n\\subparagraph{The Law of Large Numbers works too Slowly}\n\n\\subparagraph{The Sample Mean will rarely correspond to the Distribution Mean}\nFor example, for an 80/20 power law, 92\\% of the observations will fall below the distribution mean. The sample mean will tend to underestimate the distribution mean because the distribution mean is heavily biased by rare observations that will tend to be underrepresented in the sample.\n\n\\subparagraph{Metrics such as Sample Mean and Sample Variance will be Unusable}\n\n\\subparagraph{In finance, metrics like Sharp etc. are unusable}\n\n\\subparagraph{Gauss-Markov Theorem fails}\nTherefore, linear least squares regressions do not work. \n\n\\subparagraph{Maximum Likelihood Methods can still work}\nFor example in case of a Pareto distribution, it is possible to fit the tail exponent using maximum likelihood methods, and estimating the mean from there. Direct observation of the mean would be misleading. The tail exponent intelligently extrapolates the fat tails of the distribution.\n\n\\subparagraph{Absence of Evidence $\\neq$ Evidence of Absence}\n\n\\subparagraph{PCA is going to cause spurious factors and loads}\n\n\\subparagraph{Method of Moments does not work}\nApproximating a distribution by matching its moments does not work when higher moments are undefined or cannot be reliably estimated.\n\n\\subparagraph{There is no ``typical\" large deviation}\n\n\n\\subsection{Maximum to Sum}\nThe \"maximum to sum\" or MS plot allows to see the behavior of the relationship between the observed maximum to the sum for a particular moment as the number of observations increases. \n\n\\subsection{Maximum Domain of Attraction}\n\nThe ``maximum domain of attraciton\" is, so to speak, the ``right endpoint of the distribution\":\n\n\\begin{equation}\nx^* = \\sup\\{x: F(x) < 1 \\}\n\\end{equation}\n\n\\subsection{Hidden Tail, Problems in Estimating Moments}\nThe Glivenko-Cantelli theorem guarantees uniform convergence of the empiral cdf to the true CDF, however, the empirical distribution is necessarily bounded by the values of the minimum and maximum observations. This results in an unobserved contribution to moments $p>0$ that does not necessarily have to be negligible. To illustrate, take $K_n$ to be the maximum observed value. \n\\begin{equation}\n\\mathbb{E}(X^p) = \\underbrace{\\int_{L}^{K_n} x^p \\phi(x)\\mathrm{d}x}_{observed} + \\underbrace{\\int_{K_n}^{\\infty} x^p \\phi(x)\\mathrm{d}x}_{unobserved}\n\\end{equation}\n\n\n", "meta": {"hexsha": "8c92807306cfc09afe23032949b8b56cf6d18e6c", "size": 4971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_fattails.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_fattails.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_fattails.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": 60.6219512195, "max_line_length": 468, "alphanum_fraction": 0.7877690606, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.6465311309662038}}
{"text": "\n\n\\section{Reorderings and fluctuations}\n\\label{sec:heap-reordering}\n\nOne particular challenge posed by heap algorithms is that\nwhile temporarily causing \\emph{small fluctuations} in the number of values\nwithin an array they essentially only \\emph{reorder} it,\nthat is they leave the multiset of its values unchanged.\nIn this section we will introduce various predicates that will help\nus mastering this challenge.\n\n\\subsection{Formalizing small fluctuations}\n\nThe predicate \\MultisetAdd in the following listing\nexpresses that the number of occurrences of a specific element in an array\nhas increased by one between two program points~\\inl{K} and~\\inl{L}.\n\n\\input{Listings/MultisetOperations.acsl.tex}\n\nThe predicate \\MultisetMinus, on the other hand,\nexpresses that the number of occurrences of a specific element in an array\nhas decreased by one between two program points~\\inl{K} and~\\inl{L}.\nNote that we have defined \\MultisetMinus by calling \\MultisetAdd\nwith the labels reversed.\n%\nFinally, the predicate \\MultisetRetain expresses that a the number\nof occurrences of a given value does not change between two program points.\nIn order to guide the automatic provers, we also provide some\nlemmas that formalize conditions under which the respective predicates hold.\n\nUsing the predicate \\logicref{MultisetReorder} and the logic function \\logicref{At}\nwe also formulate a few simple lemmas that describe when the\npredicates from Listing~\\logicref{MultisetOperations} hold.\n\n\\subsection{Simple properties of fluctuations}\n\nThe predicate \\logicref{MultisetRetainRest} uses \\logicref{MultisetRetain}\nin order to express that all values of an array,\nexcept the two given values \\inl{u} and \\inl{v}, occur as often in program\npoint \\inl{K} and program point \\inl{L}. \n\nThe lemmas in this listing express conditions under which small\nfluctuations---expressed by the predicates \\logicref{MultisetAdd}\nand \\logicref{MultisetMinus}---in the number of occurrences between three\nprogram points even with each other.\n\n\\input{Listings/MultisetRetainRest.acsl.tex}\n\n\n\\subsection{Combining fluctuations}\n\nSmall fluctuations are so prevalent in the central heap algorithms \\implref{pushheap}\nand \\implref{popheap} that it is worthwhile to introduce another predicate\nto concisely capture this feature.\nWe refer to this predicate as \\logicref{MultisetParity} because it describes\nthe situation where the number of occurrences \n\n\\begin{itemize}\n\\item of the first of two given values increases by one\n\\item while that of the second value decreases by one\n\\item and the remaining values retain their respective number of occurrences.\n\\end{itemize}\n\nWith this predicate we can formulate several lemmas that describe useful\ncombinations of reorderings and fluctuations.\nFor example, lemma \\logicref{MultisetParityMultisetReorder} describes\nthe situation where two fluctuation cancel each other and consequently\nestablish a reordering of an array.\n\n\\input{Listings/MultisetParity.acsl.tex}\n\n\\subsection{How do fluctuations arise?}\n\nThe simplest way to creation a small fluctuation is to\nupdate an array element with a different value.\nThus, similar to the predicate \\logicref{ArrayUpdate} we introduce \npredicate \\logicref{MultisetUpdate} which in turn relies on \\logicref{MultisetParity}.\nLemma \\logicref{ArrayUpdateMultisetUpdate} then formalizes the claim\nthat updating an array element with a different value creates a small fluctuation.\n\n\\input{Listings/MultisetUpdate.acsl.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "a8f39afc6e4d3a6c3e03196d07dbd9c50a957291", "size": 3480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/heap/fluctuations.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/heap/fluctuations.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/heap/fluctuations.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": 40.4651162791, "max_line_length": 86, "alphanum_fraction": 0.8155172414, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6465311306905516}}
{"text": "\\section{Conclusions}\n\\SecLabel{conclusions}\n\nThis work started by observing interesting patterns in the LAT modulo 8 of small Feistel Networks. The analysis of the patterns resulted in the definition of High-Degree Indicator Matrix (HDIM). This tool shows a link between the LAT and the highest-degree monomials in the ANF. Furthermore, its properties allow to prove upper bounds on the algebraic degree of cryptographic structures and to prove finer algebraic degeneracies. Though these results do not improve the state of the art, the upper bounds given are expressed in a simple closed formula and there is a room for improvement, e.g. by combining methods. Finally, the most useful application of HDIM is in the cryptanalysis of Feistel Networks masked with secret affine layers. The generalized HDIM-motivated ideas allow to prove lower-degree degeneracies as well, i.e. impossible monomials. I show how they can be used to mount decomposition attacks on Feistel Networks. The results of this chapter together allow to fully decompose affinely-whitened Feistel Networks satisfying the attack conditions. I think it provides many useful tools for S-Box reverse-engineering and white-box analysis toolkit.\n\nThe work leaves several open problems:\n\\begin{enumerate}\n    \\item Better degree evaluation. Is it possible to improve the HDIM-motivated method? Is it possible to combine it with other methods, e.g. division property?  \n    \n    \\item Proving Conjecture~\\Ref{conj:impmono}. Are there always enough impossible monomials to recover the last Feistel function, if the type-II distinguisher applies?\n\n    \\item In which cases it is possible to decompose Feistel Networks having at least 1 more round than Feistel Networks satisfying the type-II distinguisher?\n    \n    \\item A big open problem: lower bounds in Feistel Networks or Substitution-Permutation Networks. How to prove non-trivial lower bounds on the degree of a structure, i.e. that at least one instance of the structure has high enough degree? Strong lower bounds could shed light on how close are current degree evaluation methods to optimal ones.\n\\end{enumerate}", "meta": {"hexsha": "c3d462ad5d28d88db0e98617afdd3db76dbcda45", "size": 2134, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strFeistel/6conclusions.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/6conclusions.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/6conclusions.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": 142.2666666667, "max_line_length": 1163, "alphanum_fraction": 0.8064667291, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6465311237392668}}
{"text": "\\newpage\r\n\\section{Matrix Normal Forms}\r\n\r\n\\begin{Operator}[smithex]{SMITHEX}\r\nThe operator \\name{smithex} computes the Smith normal form S of a\r\n\\nameref{matrix} A (say). It returns \\{S,P,$P^-1$\\} where $P*S*P^-1 = A$.\r\n\r\n\\begin{Syntax}\r\n\\name{smithex}\\(\\meta{matrix},\\meta{variable}\\)\r\n\r\n\\meta{matrix} :- a rectangular \\nameref{matrix} of univariate polynomials in \r\n                 \\meta{variable}.\r\n\\meta{variable} :- the variable.\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n a := mat((x,x+1),(0,3*x^2)); &\r\n\\begin{multilineoutput}{6cm}\r\n      [x  x + 1]\r\n      [        ]\r\n a := [      2 ]\r\n      [0  3*x  ]\r\n\\end{multilineoutput}\\\\\r\n\r\n smithex(a,x); &\r\n\\begin{multilineoutput}{6cm}\r\n   [1  0 ]    [1    0]    [x   x + 1]\r\n\\{  [     ],   [      ],   [         ]  \\}\r\n   [    3]    [   2  ]    [         ]\r\n   [0  x ]    [3*x  1]    [-3    -3 ]\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}[smithexint]{SMITHEX_INT}\r\nThe operator \\name{smithex\\_int} performs the same task as \\name{smithex}\r\nbut on matrices containing only integer entries. Namely, \r\n\\name{smithex\\_int} returns \\{S,P,$P^-1$\\} where S is the smith normal\r\nform of the input \\nameref{matrix} (A say), and $P*S*P^-1 = A$.\r\n\r\n\\begin{Syntax}\r\n\\name{smithex\\_int}\\(\\meta{matrix}\\)\r\n\r\n\\meta{matrix} :- a rectangular \\nameref{matrix} of integer entries.\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n a := mat((9,-36,30),(-36,192,-180),(30,-180,180)); &\r\n\\begin{multilineoutput}{6cm}\r\n     [ 9   -36    30 ]\r\n     [               ]\r\na := [-36  192   -180]\r\n     [               ]\r\n     [30   -180  180 ]\r\n\\end{multilineoutput}\\\\\r\n\r\n smithex_int(a); &\r\n\\begin{multilineoutput}{6cm}\r\n  [3  0   0 ]    [-17  -5   -4 ]    [1   -24  30 ]\r\n  [         ]    [             ]    [            ]\r\n\\{ [0  12  0 ],   [64   19   15 ],   [-1  25   -30] \\}\r\n  [         ]    [             ]    [            ] \r\n  [0  0   60]    [-50  -15  -12]    [0   -1    1 ] \r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}[frobenius]{FROBENIUS}\r\nThe operator \\name{frobenius} computes the \\name{frobenius} normal form F of a \r\n\\nameref{matrix} (A say). It returns \\{F,P,$P^-1$\\} where $P*F*P^-1 = A$.\r\n\r\n\\begin{Syntax}\r\n\\name{frobenius}\\(\\meta{matrix}\\)\r\n\r\n\\meta{matrix} :- a square \\nameref{matrix}.\r\n\\end{Syntax}\r\n\r\nField Extensions:\r\n\r\nBy default, calculations are performed in the rational numbers. To \r\nextend this field the \\nameref{arnum} package can be used. The package must\r\nfirst be loaded by load\\_package arnum;. The field can now be extended\r\nby using the defpoly command. For example, defpoly sqrt2**2-2; will\r\nextend the field to include the square root of 2 (now defined by sqrt2).\r\n\r\nModular Arithmetic: \r\n\r\n\\name{Frobenius} can also be calculated in a modular base. To do this \r\nfirst type on  modular;. Then setmod p; (where p is a prime) will set \r\nthe modular base of calculation to p. By further typing on balanced\\_mod\r\nthe answer will appear using a symmetric modular representation. See \r\n\\nameref{ratjordan} for an example.\r\n\r\n\\begin{Examples}\r\n a := mat((x,x^2),(3,5*x)); &\r\n\\begin{multilineoutput}{6cm}\r\n     [    2 ]\r\n     [x  x  ]\r\na := [      ]\r\n     [3  5*x]\r\n\\end{multilineoutput}\\\\\r\n frobenius(a);&\r\n\\begin{multilineoutput}{6cm}\r\n   [         2]    [1  x]    [       - x ]\r\n\\{  [0   - 2*x ],   [    ],   [1     -----]  \\}\r\n   [          ]    [0  3]    [        3  ]\r\n   [1    6*x  ]              [           ]\r\n                             [        1  ]\r\n                             [0      --- ]\r\n                             [        3  ]\r\n\r\n\\end{multilineoutput}\\\\\r\n load\\_package arnum;\\\\\r\n defpoly sqrt2**2-2;\\\\\r\n a := mat((sqrt2,5),(7*sqrt2,sqrt2));&\r\n\\begin{multilineoutput}{6cm}\r\n     [ sqrt2     5  ]\r\na := [              ]\r\n     [7*sqrt2  sqrt2]\r\n\\end{multilineoutput}\\\\\r\n\r\n frobenius(a); &\r\n\\begin{multilineoutput}{6cm}\r\n  [0  35*sqrt2 - 2]    [1   sqrt2 ]    [           1  ]\r\n\\{ [               ],   [          ],   [1       - --- ]  \\}\r\n  [1    2*sqrt2   ]    [1  7*sqrt2]    [           7  ]\r\n                                       [              ]\r\n                                       [     1        ]\r\n                                       [0   ----*sqrt2]\r\n                                       [     14       ]\r\n\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\r\n\r\n\\begin{Operator}[ratjordan]{RATJORDAN}\r\nThe operator \\name{ratjordan} computes the rational Jordan normal form R\r\nof a \\nameref{matrix} (A say). It returns \\{R,P,$P^-1$\\} where $P*R*P^-1 = A$.\r\n\r\n\\begin{Syntax}\r\n\\name{ratjordan}\\(\\meta{matrix}\\)\r\n\r\n\\meta{matrix} :- a square \\nameref{matrix}.\r\n\\end{Syntax}\r\n\r\nField Extensions:\r\n\r\nBy default, calculations are performed in the rational numbers. To \r\nextend this field the \\name{arnum} package can be used. The package must\r\nfirst be loaded by  load\\_package arnum;. The field can now be extended\r\nby using the defpoly command. For example, defpoly sqrt2**2-2; will\r\nextend the field to include the square root of 2 (now defined by sqrt2).\r\nSee \\nameref{frobenius} for an example.\r\n\r\nModular Arithmetic:\r\n\r\n\\name{ratjordan} can also be calculated in a modular base. To do this \r\nfirst type on  modular;. Then setmod p; (where p is a prime) will set \r\nthe modular base of calculation to p. By further typing on balanced\\_mod\r\nthe answer will appear using a symmetric modular representation.\r\n\r\n\\begin{Examples}\r\n a := mat((5,4*x),(2,x^2));&\r\n\\begin{multilineoutput}{6cm}\r\n     [5  4*x]\r\n     [      ]\r\na := [    2 ]\r\n     [2  x  ]\r\n\\end{multilineoutput}\\\\\r\n\r\n ratjordan(a); &\r\n\\begin{multilineoutput}{6cm}\r\n  [0  x*( - 5*x + 8)]   [1  5]    [        -5 ]  \r\n\\{ [                 ],  [    ],   [1     -----] \\}\r\n  [        2        ]   [0  2]    [        2  ]\r\n  [1      x  + 5    ]             [           ]\r\n                                  [        1  ]\r\n                                  [0     -----]\r\n                                  [        2  ]\r\n\\end{multilineoutput}\\\\\r\n on modular; \\\\\r\n setmod 23; \\\\\r\n a := mat((12,34),(56,78)); &\r\n\\begin{multilineoutput}{6cm}\r\n     [12  11]\r\na := [      ]\r\n     [10  9 ]\r\n\\end{multilineoutput}\\\\\r\n\r\n ratjordan(a); &\r\n\\begin{multilineoutput}{6cm}\r\n  [15  0]   [16  8]   [1  21]\r\n\\{ [     ],  [     ],  [     ]  \\}\r\n  [0   6]   [19  4]   [1  4 ]\r\n\\end{multilineoutput}\\\\\r\n\r\n on balanced\\_mod;\\\\\r\n ratjordan(a);&\r\n\\begin{multilineoutput}{6cm}\r\n  [- 8  0]   [ - 7  8]   [1  - 2]\r\n\\{ [      ],  [       ],  [      ]  \\}\r\n  [ 0   6]   [ - 4  4]   [1   4 ]\r\n\\end{multilineoutput}\\\\\r\n\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\r\n\r\n\\begin{Operator}[jordansymbolic]{JORDANSYMBOLIC}\r\nThe operator \\name{jordansymbolic} computes the Jordan normal form J\r\nof a \\nameref{matrix} (A say). It returns \\{J,L,P,$P^-1$\\} where\r\n$P*J*P^-1 = A$. L = \\{ll,mm\\} where mm is a name and ll is a list of\r\nirreducible factors of p(mm).\r\n\r\n\\begin{Syntax}\r\n\\name{jordansymbolic}\\(\\meta{matrix}\\)\r\n\r\n\\meta{matrix} :- a square \\nameref{matrix}.\r\n\\end{Syntax}\r\n\r\nField Extensions:\r\n\r\nBy default, calculations are performed in the rational numbers. To \r\nextend this field the \\nameref{arnum} package can be used. The package must\r\nfirst be loaded by  load\\_package arnum;. The field can now be extended\r\nby using the defpoly command. For example, defpoly sqrt2**2-2; will\r\nextend the field to include the square root of 2 (now defined by sqrt2).\r\nSee \\nameref{frobenius} for an example.\r\n\r\nModular Arithmetic:\r\n\r\n\\name{jordansymbolic} can also be calculated in a modular base. To do this \r\nfirst type on  modular;. Then setmod p; (where p is a prime) will set \r\nthe modular base of calculation to p. By further typing on balanced\\_mod\r\nthe answer will appear using a symmetric modular representation. See \r\n\\nameref{ratjordan} for an example.\r\n\r\n% Extras:\r\n\r\n% If using \\name{xr}, the X interface for REDUCE, then the appearance of the\r\n% output can be improved by switching on looking\\_good. This\r\n% converts any lambdas to a greek font.\r\n\r\n\\begin{Examples}\r\n\r\n a := mat((1,y),(2,5*y)); &\r\n\\begin{multilineoutput}{6cm}\r\n     [1   y ]\r\na := [      ]\r\n     [2  5*y]\r\n\\end{multilineoutput}\\\\\r\n\r\n jordansymbolic(a); &\r\n\\begin{multilineoutput}{6cm}\r\n\\{\r\n\r\n [lambda11     0    ]\r\n [                  ]\r\n [   0      lambda12]\r\n\r\n ,\r\n\r\n         2\r\n {{lambda  - 5*lambda*y - lambda + 3*y},lambda},\r\n\r\n\r\n [lambda11 - 5*y  lambda12 - 5*y]\r\n [                              ]\r\n [      2               2       ]\r\n\r\n ,\r\n\r\n\r\n [ 2*lambda11 - 5*y - 1    5*lambda11*y - lambda11 - y + 1 ]\r\n [----------------------  ---------------------------------]\r\n [       2                              2                  ]\r\n [   25*y  - 2*y + 1             2*(25*y  - 2*y + 1)       ]\r\n [                                                         ]\r\n [ 2*lambda12 - 5*y - 1    5*lambda12*y - lambda12 - y + 1 ]\r\n [----------------------  ---------------------------------]\r\n [       2                              2                  ]\r\n [   25*y  - 2*y + 1             2*(25*y  - 2*y + 1)       ]\r\n\r\n \\}\r\n\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\r\n\r\n\\begin{Operator}[jordan]{JORDAN}\r\nThe operator \\name{jordan} computes the Jordan normal form J\r\nof a \\nameref{matrix} (A say). It returns \\{J,P,$P^-1$\\} where $P*J*P^-1 = A$.\r\n\r\n\\begin{Syntax}\r\n\\name{jordan}\\(\\meta{matrix}\\)\r\n\r\n\\meta{matrix} :- a square \\nameref{matrix}.\r\n\\end{Syntax}\r\n\r\nField Extensions:\r\nBy default, calculations are performed in the rational numbers. To \r\nextend this field the \\name{arnum} package can be used. The package must\r\nfirst be loaded by  load\\_package arnum;. The field can now be extended\r\nby using the defpoly command. For example, defpoly sqrt2**2-2; will\r\nextend the field to include the square root of 2 (now defined by sqrt2).\r\nSee \\nameref{frobenius} for an example.\r\n\r\nModular Arithmetic:\r\n\\name{Jordan} can also be calculated in a modular base. To do this \r\nfirst type on  modular;. Then setmod p; (where p is a prime) will set \r\nthe modular base of calculation to p. By further typing on balanced\\_mod\r\nthe answer will appear using a symmetric modular representation. See\r\n\\nameref{ratjordan} for an example.\r\n\r\n\\begin{Examples}\r\n\r\n a := mat((1,x),(0,x)); &\r\n\\begin{multilineoutput}{6cm}\r\n     [1  x]\r\na := [    ]\r\n     [0  x]\r\n\\end{multilineoutput}\\\\\r\n\r\n jordan(a);&\r\n\\begin{multilineoutput}{6cm}\r\n\\{\r\n\r\n [1  0]\r\n [    ]\r\n [0  x]\r\n\r\n ,\r\n\r\n\r\n [   1           x       ]\r\n [-------  --------------]\r\n [ x - 1     2           ]\r\n [          x  - 2*x + 1 ]\r\n [                       ]\r\n [               1       ]\r\n [   0        -------    ]\r\n [             x - 1     ]\r\n\r\n ,\r\n\r\n\r\n [x - 1   - x ]\r\n [            ]\r\n [  0    x - 1]\r\n\r\n \\}\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n", "meta": {"hexsha": "f4261df717a845f6a11bdf4c234eb5ccd633069d", "size": 10653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "normform.tex", "max_stars_repo_name": "nilqed/REDHELP", "max_stars_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "normform.tex", "max_issues_repo_name": "nilqed/REDHELP", "max_issues_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "normform.tex", "max_forks_repo_name": "nilqed/REDHELP", "max_forks_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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.2664835165, "max_line_length": 80, "alphanum_fraction": 0.5191964705, "num_tokens": 3286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.646511525487668}}
{"text": "\n\n    \\filetitle{movsum}{Moving sum pseudofunction}{modellang/movsum}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\nmovsum(Expr)\nmovsum(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 sum of the last K periods (including the current\nperiod), i.e.\n\n\\begin{verbatim}\n((Expr)+(Expr{-1})+ ... +(Expr{-(K-1)})\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 sum of the next K periods ahead (including the\ncurrent period), i.e.\n\n\\begin{verbatim}\n((Expr)+(Expr{1})+ ... +(Expr{K-1})\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}\nmovsum(Z)\nmovsum(Z,-3)\nmovsum(X+Y{-1},2)\n\\end{verbatim}\n\nwill expand to\n\n\\begin{verbatim}\n((Z)+(Z{-1})+(Z{-2})+(Z{-3}))\n((Z)+(Z{-1})+(Z{-2}))\n((X+Y{-1})+(X{1}+Y))\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "0d7317dd4c3eada917eb57f91f6124a425359496", "size": 1217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/movsum.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/movsum.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/movsum.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": 21.7321428571, "max_line_length": 71, "alphanum_fraction": 0.6959737058, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7718435083355188, "lm_q1q2_score": 0.6465115248937051}}
{"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{gensymb}\n \n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\n\\newcommand{\\nspace}{\\vspace*{.5cm}}\n\\newcommand{\\nline}{\\nspace \\noindent}\n\n\\newcommand{\\expected}[1]{\\text{E}(#1)}\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 % 6.1 4,17,18,21\n % 6.2 2,4,5,9,28,29\n \n\\begin{document}\n\\title{Math 487 Homework 5}\n\\author{Jacob Shiohira}\n\\maketitle\n\n\\subsection*{Section 6.1}\n\n% In Las Vegas the roulette wheel has a $0$ and a $00$ and then the numbers $1$ to $36$ marked on equal slots; the wheel is spun and a ball stops randomly in one slot. When a player bets $1$ dollar on a number, he receives $36$ dollars if the ball stops on this number, for a net gain of $35$ dollars; otherwise, he loses his dollar bet. Find the expected value for his winnings.\n\n\\noindent\n\\textbf{Ch 6.1 Q4} With $38$ possible spots to place a bet on, we know that the probability of winning $35$ dollars is $1/38$, and the probability of losing a dollar is $37/38$. Let $X$ be the random variable which denotes your winnings on a $1$ dollar bet in Las Vegas roulette. Then, the distribution of $X$ is given by\n\n\\begin{equation*}\nm_X = {-1 \\qquad 35 \\choose 37/38 \\quad 1/38}.\n\\end{equation*}\n\n\\nline\nThus, we see then that $-1 \\cdot (37/38) + 35 \\cdot (1/38) = - 1/19$.\n\n\n% Let $X$ be the first time that a failure occurs in an infinite sequence of Bernoulli trials with probability $p$ for success. Let $p_k = P(X = k)$ for $k = 1, 2, \\ldots$. Show that $p_k = p^{k - 1}q$ where $q = 1 - p$. Show that $\\sum_{k} p_k = 1$. Show that $\\text{E}(X) = 1/q$. What is the expected number of tosses of a coin required to obtain the first tail?\n\n\\nline\n\\textbf{Ch 6.1 Q17} Since $X$ is the first time that a failure occurs in an infinite sequence, let's assume that the failure occurs after $k$ trials. Then, the probability of a failure is $k-1$ multiplications of $p$ and $1$ multiplication of $1-p$. This is valid because $k-1+1=k$ for our $k$ trials. Thus, for $q=1-p$, we can formally see that\n\n\\begin{equation*}\np_k = p^{k-1} (1-p) = p^{k-1} q.\n\\end{equation*}\n\n\\nline\nThen, we can show $\\sum_{k} p_k = 1$. Since $k=1,2, \\ldots$, the limits of the summation are originally $k=1$ to $\\infty$.\n\n\\begin{align*}\n\\sum_{k} p_k &= \\sum_{k=1}^{\\infty} p^{k-1} q \\\\\n&= q \\sum_{k=0}^{\\infty} p^{k} \\\\\n&= q \\Big ( \\frac{1}{1-p} \\Big ) \\\\\n&= q \\frac{1}{q} \\\\\n&= 1.\n\\end{align*}\n\n\\nline\nIn this case, $p_k = p^{k-1} q$ for $k = 1,2,\\ldots$. So,\n\n\\begin{align*}\n\\text{E}(X) &= 1q + 2pq + 3p^2q + \\ldots \\\\\n&= q (1 + 2p + 3p^2 + \\ldots).\n\\end{align*}\n\n\\nline\nThen, we can see that the infinite series $1 + p + p^2 + \\ldots$, which is equivalent to $\\frac{1}{1-p}$, is embedded in the previous equation. By differentiating this, we get $1 + 2p + 3p^2 + \\ldots$, which is the term we have above and is equivalent to $\\frac{1}{(1-p)^2}$. By substituting into the expanded equation of $\\text{E}(X)$, we get \n\n\\begin{align*}\n\\text{E}(X) &= q (1 + 2p + 3p^2 + \\ldots) \\\\\n&= q \\frac{1}{(1-p)^2} \\\\\n&= q \\Big ( \\frac{1}{q^2} \\Big ) \\\\\n&= \\frac{1}{q}.\n\\end{align*}\n\n\\nline\nThus, the expected value of the first tail of a fair coin is $\\frac{1}{q} = \\frac{1}{\\frac{1}{2}} = 2$. \n\n%  Exactly one of six similar keys opens a certain door. If you try the keys, one after another, what is the expected number of keys that you will  have to try before success?\n\n\\nline\n\\textbf{Ch 6.1 Q18} To compute the expected value, $\\text{E}(X)$ for some random variable $X$, we can use the definition of $\\text{E}(X)$ using a sum and a distribution function,\n\n\\begin{align*}\n\\text{E}(X) &= \\sum_{k=1}^{6} k \\cdot \\frac{1}{6} \\\\\n&= \\frac{1}{6} + \\frac{2}{6} + \\frac{3}{6} + \\frac{4}{6} + \\frac{5}{6} + \\frac{6}{6} \\\\\n&= \\frac{7}{2}.\n\\end{align*}\n\n% Let $X$ be a random variable which is Poisson distributed with parameter $\\lambda$. Show that E$(X) = \\lambda$. Hint: Recall that\n\n% \\begin{equation*}\n% e^{x} = 1 + x + \\frac{x^2}{2!} + \\frac{x^3}{3!} + \\cdots .\n% \\end{equation*}\n\n\\nline\n\\textbf{Ch 6.1 Q21} To compute the expected value of $X$, we need to note that the distribution function of $X$ is $p(x) = \\frac{ e^{- \\lambda} \\lambda^x }{x!}$. Then, \n\n\\begin{align*}\n\\text{E}(X) = \\sum_{x=0}^{\\infty} x \\cdot p(x) &= \\sum_{x=1}^{\\infty} x \\cdot  \\frac{ e^{- \\lambda} \\lambda^x }{x!} \\\\\n&= \\sum_{x=1}^{\\infty} \\frac{ e^{- \\lambda} \\lambda^x }{(x-1)!} \\\\ \n&= e^{- \\lambda} \\sum_{x=1}^{\\infty} \\frac{ \\lambda^x }{(x-1)!} \\\\ \n\\end{align*}\n\n\\nline\nNow, we see that the denominator yields $0$ when $x=1$, so we can set $k=x-1$ and adjust the summation, \n\n\\begin{align*}\n\\text{E}(X) &= \\lambda e^{- \\lambda} \\sum_{k=1}^{\\infty} \\frac{ \\lambda^k }{k!} \\\\ \n\\end{align*}\n\n\\nline\nNow, we see that $\\sum_{k=1}^{\\infty} \\frac{ \\lambda^k }{k!} = 1 + x + \\frac{\\lambda^2}{2!} + \\frac{\\lambda^3}{3!} + \\cdots$, which is equivalent to $e^{\\lambda}$. By substituting into $\\text{E}(X)$, we get \n\n\\begin{equation*}\n\\text{E}(X) = \\lambda e^{- \\lambda} e^{\\lambda} = \\lambda.\n\\end{equation*}\n\n\\subsection*{Section 6.2}\n\n\\nline\n\\textbf{Ch 6.2 Q2} A random variable $X$ has the distribution\n\n\\begin{equation*}\np_x = {0 \\qquad 1 \\qquad 2 \\qquad 4 \\choose 1/3 \\quad 1/3 \\quad 1/6 \\quad 1/6}\n\\end{equation*}\n\n\\nline\nFind the expected value, variance, and standard deviation of $X$.\n\n\\begin{align*}\n\\text{E}(X) &= 0 \\cdot \\frac{1}{3} + 1 \\cdot \\frac{1}{3} + 2 \\cdot \\frac{1}{6} + 4 \\cdot \\frac{1}{6} \\\\\n&= \\frac{1}{3} + \\frac{2}{6} + \\frac{4}{6} \\\\\n&= \\frac{4}{3}.\n\\end{align*}\n\n\\begin{align*}\n\\text{V}(X) &= \\text{E}(X^2) - \\Big ( \\frac{4}{3} \\Big )^2 \\\\\n&= \\Big [ 0^2 \\cdot \\frac{1}{3} + 1^2 \\cdot \\frac{1}{3} + 2^2 \\cdot \\frac{1}{6} + 4^2 \\cdot \\frac{1}{6} \\Big ] - \\frac{16}{9} \\\\\n&= \\Big [ \\frac{11}{3} \\Big ] - \\frac{16}{9} \\\\\n&= \\frac{17}{9}.\n\\end{align*}\n\n\\begin{align*}\n\\text{D}(X) = \\sqrt{\\text{V}(X)} = \\sqrt{\\frac{17}{9}} = \\frac{\\sqrt{17}}{3}.\n\\end{align*}\n\n\\nline\n\\textbf{Ch 6.2 Q4} $X$ is a random variable with $\\text{E}(X) = 100$ and $\\text{V}(X) = 15$. Find\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $\\expected{X^2}$\n\n\\nline\nWe can rearrange $\\text{V}(X) = \\text{E}(X^2) - \\text{E}(X)^2$ for $\\text{E}(X^2)$, which yields $\\text{V}(X) + \\text{E}(X)^2$. Plugging in values, we see that $\\expected{X^2} = 10015$.\n\n\\item $\\expected{3X + 10}$\n\n\\nline\nWe can use the fact that $\\expected{cX} = c \\expected{X}$. So, $\\expected{3X + 10}$ is equivalent to $3 \\expected{X} + 10$. Thus, $\\expected{3X + 10} = 310$. \n\n\\item $\\expected{-X}$\n\n\\nline\nWe can use the fact that $\\expected{cX} = c \\expected{X}$. So, $\\expected{-X}$ is equivalent to $-1 \\expected{X}$. Thus, $\\expected{-X} = -100$. \n\n\\item $\\text{V}(-X)$\n\n\\nline\nWe can use the fact that $V(cX) = c^2 V(X)$. So, $\\text{V}(-X) = -1^2 \\text{V}(X)$. Thus,  $\\text{V}(-X) = 15$.\n\n\\item $\\text{D}(-X)$\n\n\\nline\nWe can use the previous result that said $\\text{V}(-X) = 15$ since $\\text{D}(-X) = \\sqrt{\\text{V}(-X)}$. Thus, $\\text{D}(-X) = \\sqrt{15}$.\n\n\\end{enumerate}\n\n\\nline\n\\textbf{Ch 6.2 Q5} In a certain manufacturing process, the (Fahrenheit) temperature never varies by more than $2^{\\circ}$ from $62^{\\circ}$. The temperature is, in fact, a random variable $F$ with distribution\n\n\\begin{equation*}\nP_F = { 60 \\qquad 61 \\qquad 62 \\qquad  63 \\qquad 64 \\choose 1/10 \\quad 2/10 \\quad 4/10 \\quad 2/10 \\quad 1/10}.\n\\end{equation*}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Find $\\expected{F}$ and $\\text{V}(F)$.\n\n\\begin{equation*}\n\\expected{F} = 60 \\cdot \\frac{1}{10} + 61 \\cdot \\frac{2}{10} + 62 \\cdot \\frac{4}{10} + 63 \\cdot \\frac{2}{10} + 64 \\cdot \\frac{1}{10} = 62.\n\\end{equation*}\n\n\\begin{equation*}\n\\text{V}(F) = \\Big [ 60^2 \\cdot \\frac{1}{10} + 61^2 \\cdot \\frac{2}{10} + 62^2 \\cdot \\frac{4}{10} + 63^2 \\cdot \\frac{2}{10} + 64^2 \\cdot \\frac{1}{10} \\Big ] - 62^2 = 1.2.\n\\end{equation*}\n\n\\item Define $T = F - 62$. Find $\\expected{T}$ and $\\text{V}(T)$, and compare these answers with those in part $(a)$.\n\n\\nline\nWe know that $\\expected{X + a} = \\expected{X} + a$, so $\\expected{T} = \\expected{F} - 62$. Thus, $\\expected{T} = 0$. Additionally, we know that $\\text{V}(X + a) = \\text{V}(X)$, so $\\text{V}(T) = \\text{V}(F)$. Thus, $\\text{V}(T) = 1.2$.\n\n\n\\item It is decided to report the temperature readings on a Celsius scale, that\nis, $C = (5/9) (F - 32)$. What is the expected value and variance for the\nreadings now? \n\n\\nline\nWe know that $\\expected{X + a} = \\expected{X} + a$, so $\\expected{C} = \\frac{5}{9} \\Big ( \\expected{F} - 32 \\Big )$. Thus, $\\expected{C} = \\frac{50}{3}$. Additionally, we know that $\\text{V}(cX + a) = c^2 \\text{V}(X)$, so $\\text{V}(C) = \\frac{5}{9}^2 \\cdot \\text{V}(F)$. Thus, $\\text{V}(C) = \\frac{5}{9}^2 \\cdot \\frac{6}{5}= \\frac{10}{27}$.\n\\end{enumerate}\n\n\\nline\n\\textbf{Ch 6.2 Q9} A die is loaded so that the probability of a face coming up is proportional to the number on that face. The die is rolled with outcome $X$. Find $\\text{V}(X)$ and $\\text{D}(T)$.\n\n\\nline\nThe total of all faces on a die is $21$. Thus, the probability of rolling a $1$ is $1/21$, rolling a $2$ is $2/21$, and so on. Thus, we can compute expected value using the summation definition.\n\n\\begin{equation*}\n\\sum_{x=1}^{6} x \\cdot \\frac{x}{21} = \\frac{13}{3}.\n\\end{equation*}\n\n\\nline\nThen, $\\text{V}(X)  = \\expected{X^2} - \\expected{X}^2$. So, \n\n\\begin{align*}\n\\text{V}(X) &= \\Big ( \\sum_{x=1}^{6} x^2 \\cdot \\frac{x}{21} \\Big ) - \\frac{13}{3}^2 \\\\\n&= 21 - \\frac{13}{3}^2 = \\frac{20}{9}.\n\\end{align*}\n\n\\nline\nLastly, $\\text{D}(X) = \\sqrt{\\text{V}(X)} = \\sqrt{ \\frac{20}{9}} = \\frac{\\sqrt{20}}{3}$.\n\n% TODO: finish this by getting help? \n\\nline\n\\textbf{Ch 6.2 Q28} In Example $5.3$, assume that the book in question has $1000$ pages. Let $X$ be the number of pages with no mistakes. Show that $\\expected{X} = 905$ and $\\text{V}(X) = 86$. Using these results, show that the probability is $\\leq .05$ that there will be more than $924$ pages without errors or fewer than $866$ pages without errors.\n\n\\nline\nThe likelihood that there are no mistakes on a page can is given by $\\frac{ e^{- 0.1} 0.1^0 }{0!} = e^{-.1} = 0.9048374$. Since the likelihood of a mistake (or lack thereof) on a page is independent of other pages, we can multiply this probability by $1000$, which represents the number of pages in the book, to find the expected value of pages without mistakes. So, $\\expected{X} = 1000 \\cdot e^{-.1} = 905$ pages.\n\n\\nline\nPer the usual definition, we know $\\text{V}(X) = \\expected{X^2} - \\expected{X}^2$. However, since we know that a mistake on the $i^{\\text{th}}$ page does not affect a mistake on the $i+1^{\\text{th}}$ page, we can reduce the equation to \n\n\\begin{align*}\n\\text{V}(X) &= \\expected{X} - \\expected{X}^2 \\\\\n&= \\Bigg [ \\frac{ e^{- 0.1} 0.1^0 }{0!} - \\Bigg ( \\frac{ e^{- 0.1} 0.1^0 }{0!} \\Bigg )^2 \\Bigg ] \\\\\n&= \\frac{ e^{- 0.1} 0.1^0 }{0!} \\Bigg ( 1- \\frac{ e^{- 0.1} 0.1^0 }{0!} \\Bigg ) \\\\\n&= e^{- 0.1} \\Bigg ( 1- e^{- 0.1} \\Bigg ) \\\\\n& \\sim 0.086107 \n\\end{align*}\n\n\\nline\nSo, for total variance see that $\\text{V}(X) = 1000 \\cdot 0.086107 = 86$.\n\n\\nline\nWe can use the cumulative distribution function for a binomial distribution to show $\\mathbb{P}(X > 924) \\leq .05$ and $\\mathbb{P}(X < 866) \\leq .05$. We see that $F(924; 0.9048374, 1000) \\sim 0.985$, so the probability of more than $924$ pages is approximately $.015$. Additionally, $F(866; 0.9048374, 1000) \\sim 4.209053 \\times 10^{-5}$, and this is obviously less than $.05$.\n\n%http://www.chegg.com/homework-help/questions-and-answers/book-200-pages-number-mistakes-page-apoisson-random-variable-mean-001-independent-thenumbe-q228411\n\\nline\n\\textbf{Ch 6.2 Q29} Let $X$ be Poisson distributed with parameter $\\lambda$. Show that $\\text{V}(X) = \\lambda$.   \n\n\\nline\nTo find $\\text{V}(X)$ of the Poisson distributed random variable $X$ with parameter $\\lambda$, we can use the equation\n\n\\begin{equation*}\n\\text{V}(X) = \\expected{X^2} - \\expected{X}^2.\n\\end{equation*}\n\n\\nline\nTo find $\\expected{X^2}$, we need a second order value of $X$, but there is no $i,j$ where $i \\neq j$ such that $X=x_i=x_j$. So, $\\expected{X^2} = \\expected{X(X-1) + X}$.\n\n\\begin{align*}\n\\expected{X(X-1) + X} &= \\sum_{x=0}^{\\infty} x(x-1) \\frac{ e^{- \\lambda} \\lambda^x }{x!} \\\\\n&= \\sum_{x=0}^{\\infty} \\frac{ e^{- \\lambda} \\lambda^x }{(x-2)!} \\\\\n&= \\lambda^2  e^{- \\lambda} \\sum_{x=2}^{\\infty} \\frac{ \\lambda^{x-2} }{(x-2)!} \\\\\n&= \\lambda^2  e^{- \\lambda} e^{- \\lambda} =  \\lambda^2\\\\\n\\end{align*}\n\n\\nline\nThus, we can substitute values and we see that $\\text{V}(X) = \\lambda^2 + \\lambda - \\lambda^2 = \\lambda$.\n\\end{document} ", "meta": {"hexsha": "302f3d9680bd69a7fd65c6330f80963b36732924", "size": 12706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/homework-5/HOMEWORK5.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/homework-5/HOMEWORK5.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/homework-5/HOMEWORK5.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": 44.1180555556, "max_line_length": 415, "alphanum_fraction": 0.6232488588, "num_tokens": 4991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.6465115192303388}}
{"text": "\\documentclass[a4paper,11pt]{scrartcl}\n\n\\usepackage{amsmath,amssymb}\n\\usepackage[utf8]{inputenc}\n\n\\title{Informed priors and quasi-simultaneous inference for psychometric functions}\n\\author{Ingo Fründ}\n\\date{\\today}\n\n\\def\\prob{\\mathbb{P}}\n\n\\begin{document}\n\n\\maketitle\n% Your text here\nWhen fitting psychometric functions, we are often interested in summarizing the performance of observers in as few numbers as possible.\nOf particular interest is a summary of the performance that consists of a single parameter, the threshold.\nUnfortunately, comparisons of psychophysical thresholds are only meaningful if other parameters of the psychometric functions --- such as slope and lapse rate --- are constant across conditions.\nHere, I demonstrate how priors can be derived that incorporate the information from other conditions.\nIf these priors are used in bayesian inference of psychometric functions, this allows for quasi-simultaneous fits that constrain parameters to be constant across conditions.\n\n\\section{A simple example}\n\nWe start with a simple example to illustrate the basic idea behind the approach.\nAssume, we colleted data $X_i$ under two different conditions $i\\in\\{1,2\\}$.\nWe want to model these data depending on a parameter $\\theta$.\nIn principle, $\\theta$ might differ between the two conditions, but we will assume here, that $\\theta_1=\\theta_2$.\nIn this particular case, we can write down the posterior distribution of $\\theta$:\n%\n$$\n\\prob(\\theta|X_1,X_2) \\propto \\prob(X_1,X_2|\\theta) \\prob(\\theta) = \\prob(X_1|\\theta)\\prob(X_2|\\theta)\\prob(\\theta),\n$$\n%\nWhere the second equality holds under the assumption that the two conditions are independent.\n\nIn practical applications, we will typically not be able to write down $\\prob(\\theta|X_1,X_2)$ directly.\nThus, we will have to resort to sampling strategies to explore $\\prob(\\theta|X_1,X_2)$.\nThe strategy in this case is therefore to perform two sampling stages.\nIn the first sampling run, we derive proper priors for the parameter $\\theta$ and in the second sampling run, we use these priors to perform the true analysis.\n\nFor the first sampling run, we employ an improper uniform prior, that is $\\prob(\\theta)=\\kappa$ for all $\\theta$ and a fixed $\\kappa$.\nWe then use MCMC to generate a sample $(\\theta_{1i})_{i=1}^m$ of size $m$ from $\\prob(\\theta|X_1)\\propto\\prob(X_1|\\theta)\\cdot\\kappa$ and another sample\n$(\\theta_{2i})_{i=1}^m$ from $\\prob(\\theta|X_2)\\propto\\prob(X_2|\\theta)\\cdot\\kappa$.\nWe now fit a parametric model to each sample and use these model as priors for the second sampling run.\nDenote the parametric model fitted to $(\\theta_{1i})$ by $f_1$ and the parametric model fitted to $(\\theta_{2i})$ by $f_2$.\nThen approximate samples from the simultaneous model can be obtained by sampling either\n%\n$$\n\\prob(\\theta|X_1,X_2) \\propto\\prob(X_1|\\theta)f_2(\\theta),\n$$\n%\nor\n%\n$$\n\\prob(\\theta|X_1,X_2) \\propto\\prob(X_2|\\theta)f_1(\\theta).\n$$\n%\n\n\\section{Constant parameters}\n\nI will now expand the above strategy to the case in which the model has more than a single parameter.\nLet us think about a model with three parameters, $\\theta$, $\\vartheta_1$, $\\vartheta_2$.\nAs the notation already suggests,  $\\theta$ shall be assumed fixed across conditions, while $\\vartheta_1$ and $\\vartheta_2$ depend on the\nexperimental condition.\nAgain, we write down the posterior distribution\n%\n\\begin{align*}\n\\prob(\\theta,\\vartheta_1,\\vartheta_2|X_1,X_2) &=\\prob(\\theta|X_1,X_2)\\prob(\\vartheta_1,\\vartheta_2|X_1,X_2)\\\\\n&= \\prob(\\theta|X_1,X_2)\\prob(\\vartheta_1|X_1)\\prob(\\vartheta_2|X_2),\n\\end{align*}\n%\nWhere the first equality requires $\\theta$ to be independent of $\\vartheta_1$ and $\\vartheta_2$.\nThat means, the parameter we want constraint to be equal across conditions necessarily has to be independent of the other parameters!\nThe second equality is valid if $\\vartheta_1$ depends only on the data $X_1$ and $\\vartheta_2$ depends only on the data $X_2$.\nThis is a rather plausible condition.\n\nWe can now use the same trick as above to derive priors for $\\theta$ by drawing samples $(\\theta_{1i})_{i=1}^m$ from $\\prob(\\theta,\\vartheta_1|X_1)\\cdot\\kappa$\nand $(\\theta_{2i})_{i=1}^m$ from $\\prob(\\theta,\\vartheta_2|X_2)\\cdot\\kappa$.\nThen, we fit the marginal distributions of $(\\theta_{1i})$ and $(\\theta_{2i})$ to obtain expressions for $f_1$ and $f_2$.\nIn a second sampling run, we can then perform quasi simultaneous sampling using\n%\n$$\n\\prob(\\theta,\\vartheta_1|X_1,X_2) \\propto\\prob(X_1|\\theta,\\vartheta_1)f_2(\\theta)\\prob(\\vartheta_1),\n$$\n%\nand\n%\n$$\n\\prob(\\theta,\\vartheta_2|X_1,X_2) \\propto\\prob(X_2|\\theta,\\vartheta_2)f_1(\\theta)\\prob(\\vartheta_2).\n$$\n%\n\n\\section{More than two conditions}\n\nThe extension of these ideas to cases with more than two conditions is straight forward:\nIn the first sampling run, we determine the prior densities $f_j, j=1,\\dots,n$ from each dataset $X_j$ in isolation.\nWe then combine the $f_j$ in order to sample\n%\n\\begin{equation}\n    \\label{eq:allcombined}\n\\prob(\\theta,\\vartheta_j|X_j, j=1,\\dots,n) \\propto\\prob(X_j|\\vartheta_j,\\theta) \\prob(\\vartheta_j) \\prod_{\\underset{\\ell\\neq j}{\\ell=1}}^n f_\\ell ( \\theta ),\n\\end{equation}\n%\nin isolation for each $j=1,\\dots,n$.\nThus, the product $\\prod_{\\underset{\\ell\\neq j}{\\ell=1}}^n f_\\ell ( \\theta )$ can be taken as a prior that incorporates prior knowledge about the other psychometric functions in the design.\n\n\\section{Specific choices of fitted posteriors}\n\nHere, we will highlight reasonable choices to fit the posterior distributions and we will demonstrate, how these choices imply a closed functional form for the product prior in equation \\eqref{eq:allcombined}.\n\n\\subsection{Fitting posterior distributions for scale parameters}\n\nIn order to compare, thresholds obtained from different conditions, it is typically required that the slopes across all these conditions are equal.\nAlthough threshold comparisons are possible with unequal slopes, too, it is far more complicated to arrive at valid conclusions from these comparisons.\nIn psignifit, many parameterizations of the psychometric functions do not explicitely specify the slope of the psychometric function but instead have a parameter that is somehow related to the inverse slope.\nPosterior distributions for this parameter often resemble a Gamma distribution, i.e. the seem to have a density of the form\n%\n\\begin{equation}\n    \\label{eq:GammaDensity}\n    f ( x | k, \\theta ) = x^{k-1} \\frac{\\exp(-x/\\theta)}{\\Gamma(k)\\theta^k}.\n\\end{equation}\n%\nWe now assume that we have fitted this density (using for instance maximum likelihood) to a set of $n$ sampled posteriors from different conditions and we want to derive the product prior for the $n+1$-th condition.\nThe product prior has the density\n%\n\\begin{align*}\n    \\bar{f}(x) &= \\prod_{j=1}^n f_j(x) = \\prod_{j=1}^n x^{k_j-1} \\frac{\\exp(-x/\\theta_j)}{\\Gamma(k_j)\\theta_j^{k_j}} \\\\\n    &\\propto \\prod_{j=1}^n x^{k_j-1} \\exp(-x/\\theta_j) \\\\\n    &= x^{\\sum_{j=1}^n k_j-1} \\exp(-x\\sum_{j=1}^n \\frac{1}{\\theta_j}) \\\\\n    &= x^{\\bar{k}-1} \\exp(-x/\\bar{\\theta}),\n\\end{align*}\n%\nwhere we set\n%\n$$\n\\bar{k} := 1 + \\sum_{j=1}^n k_j-1,\n$$\n%\nand\n%\n$$\n\\bar{\\theta} := \\Big( \\sum_{j=1}^n \\frac{1}{\\theta_j} \\Big)^{-1}.\n$$\n%\nThus, the product prior is again a Gamma distribution with parameters $\\bar{k}$ and $\\bar{\\theta}$!\n\n\\subsection{Fitting posterior distributions for rates}\n\nThe psychometric function model includes two rate parameters, the guessing rate $\\gamma$ that describes the lower asymptote and the lapse rate $\\lambda$ that describes the upper asymptote.\nA very reasonable model for rates is the Beta distribution (cite Ferrari?).\nThe Beta distribution lives on the unit interval $(0,1)$ and takes the density\n%\n\\begin{equation}\n    f ( x | \\alpha, \\beta ) = \\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)} x^{\\alpha-1} (1-x)^{\\beta-1}.\n    \\label{eq:BetaDensity}\n\\end{equation}\n%\nHere, we can use the same trick as with the Gamma distribution to derive a sensible product prior:\nWe assume that we fitted $n$ sets of parameters $(\\alpha_j,\\beta_j)_{j=1}^n$ and want to combine these to obtain a prior for the $n+1$-th condition.\nThe product prior in this case is\n%\n\\begin{align*}\n    \\bar{f}(x) &= \\prod_{j=1}^n f_j(x) = \\prod_{j=1}^n \\frac{\\Gamma(\\alpha_j+\\beta_j)}{\\Gamma(\\alpha_j)\\Gamma(\\beta_j)} x^{\\alpha_j-1} (1-x)^{\\beta_j-1}\\\\\n    &\\propto \\prod_{j=1}^n x^{\\alpha_j-1} (1-x)^{\\beta_j-1} \\\\\n    &= x^{\\sum_{j=1}^n \\alpha_j-1} (1-x)^{\\sum_{j=1}^n\\beta_j-1} \\\\\n    &= x^{\\bar{\\alpha}-1} (1-x)^{\\bar{\\beta}-1},\n\\end{align*}\n%\nwhere $\\bar{\\alpha}:= 1+ \\sum_{j=1}^n\\alpha_j-1$ and $\\bar{\\beta}:=1+\\sum_{j=1}^n\\beta_j-1$.\n\nThus, the product prior in this case, is again a Beta distribution, with parameters $\\bar{\\alpha}$ and $\\bar{\\beta}$.\n\n\\subsection{Fitting posterior distributions for thresholds}\n\nIn some, very rare situations, we might also be interested in having equal posterior distributions for thresholds.\nA reasonable approximation for posterior threshold distributions is often the Normal distribution.\nInterestingly, the procedure used to derive the product prior in the preceeding paragraphs does not work well for the Normal distribution.\nAssume, we fitted the posteriors in conditions $j=1,\\dots,n$ with Normal densities $(f_j)_{j=1}^n$ with parameters $(\\mu_j,\\sigma_j)_{j=1}^n$.\nThe product is then\n%\n\\begin{align*}\n    \\bar{f}(x) &= \\prod_{j=1}^n f_j(x) = \\prod_{j=1}^n \\frac{1}{\\sqrt{2\\pi}\\sigma_j} \\exp ( - \\frac{(x-\\mu_j)^2}{2\\sigma_j^2})\\\\\n    &\\propto \\prod_{j=1}^n \\exp ( - \\frac{(x-\\mu_j)^2}{2\\sigma_j^2})\\\\\n    &= \\exp ( - \\sum_{j=1}^n \\frac{(x-\\mu_j)^2}{2\\sigma_j^2} ) \\\\\n    &= \\exp ( - \\frac{1}{2} \\big( \\sum_{j=1}^n \\frac{x^2}{\\sigma_j^2} - \\sum_{j=1}^n 2\\frac{x\\mu_j}{\\sigma_j^2} + \\sum_{j=1}^n \\frac{\\mu_j^2}{\\sigma_j^2} \\big) )\\\\\n    &\\propto\\exp ( - \\frac{1}{2} \\big( \\sum_{j=1}^n \\frac{x^2}{\\sigma_j^2} - \\sum_{j=1}^n 2\\frac{x\\mu_j}{\\sigma_j^2}\\big) ) \\\\\n    &= \\exp ( - \\frac{1}{2} \\big( x^2\\sum_{j=1}^n \\frac{1}{\\sigma_j^2} - 2x\\sum_{j=1}^n 2\\frac{\\mu_j}{\\sigma_j^2} \\big) ) \\\\\n    &= \\exp ( - \\frac{1}{2} \\underbrace{\\sum_{j=1}^n \\frac{1}{\\sigma_j^2}}_{=:\\bar{\\sigma}^{-2}} \\big( x^2 - 2x\\underbrace{\\frac{\\sum_{j=1}^n \\frac{\\mu_j}{\\sigma_j^2}}{\\sum_{j=1}^n \\frac{1}{\\sigma_j^2}}}_{=:\\bar{\\mu}}\\big) ) \\\\\n    &\\propto \\frac{1}{\\sqrt{2\\pi}\\bar{\\sigma}} \\exp( - \\frac{(x-\\bar{\\mu})^2}{2\\bar{\\sigma}^2}).\n\\end{align*}\n%\nThus, comparing coefficients with the Normal density, we end up with a new Normal distribution with parameters\n%\n$$\n\\bar{\\sigma}^2 := \\big(\\sum_{j=1}^n \\frac{1}{\\sigma_j^2}\\big)^{-1},\n$$\n%\n$$\n\\bar{\\mu} := \\frac{\\sum_{j=1}^n\\frac{\\mu_j}{\\sigma_j^2}}{\\sum_{j=1}^n\\frac{1}{\\sigma_j^2}}.\n$$\n%\n\\end{document}\n", "meta": {"hexsha": "c8f672314465d5665836ffbddb036a5fb8849cdc", "size": 10648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/simultaneous.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/simultaneous.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/simultaneous.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": 52.4532019704, "max_line_length": 227, "alphanum_fraction": 0.7114012021, "num_tokens": 3392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6464779597744124}}
{"text": "\n\\subsection{The dual space forms a vector space}\n\nThe dual space forms a vector space. We can define addition and scalar multiplication on members of the dual space.\n\nThe dimension of the dual space is the same as the underlying space.\n\nWe have defined the dual space. A vector in dual space will have also have components and a basis.\n\n\\(\\mathbf w=\\sum_i w_i f^j\\)\n\nSo how we describe the components will depend on the choice of basis.\n\nWe choose the dual basis, the basis for \\(V^*\\) as:\n\n\\(\\mathbf e_i \\mathbf f^j =\\delta_i^j\\)\n\nIf the basis changes, so does the dual basis.\n\nWe write the dual basis as \\(e^j\\)\n\n", "meta": {"hexsha": "f785564565fdecfdadbf8c0d4656ed27354f9517", "size": 616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/01-03-dualSpaceBasis.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/01-03-dualSpaceBasis.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/01-03-dualSpaceBasis.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.0, "max_line_length": 115, "alphanum_fraction": 0.7402597403, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6464779549965517}}
{"text": "\\chapter{Constructive Heuristics}\n\n\\section{Greedy}\\label{sec:greedy}\nGreedy heuristic for TSP start by choosing a random element and add always the closer node, one node at a time, making the local optimal choice. This create good path in the first part of the tour, however the last added edges create different crosses. Therefore this heuristic can be applied in combination with refining heuristics such as: \\texttt{local\\_branching}, \\texttt{hard\\_fixing}, \\texttt{best\\_two\\_opt} and other ones that try to improve a tour.\\\\\nThe algorithm computational time is $ O(n^2) $ where $ n = |V| $, therefore is pretty fast, however depending on the first selected node, the cost of the tour can differ more than 10 \\% one another. The implemented algorithm (from now only \\texttt{Greedy} or \\texttt{heuristic\\_greedy}), at cost of execution time, perform the described greedy using all the nodes as starting node, returning the shortest tour. The time complexity for the implemented algorithm raise to $ O(n^3) $.\\\\\nIn fig \\ref{fig:a280_10_} an example of tour calculated with the implemented algorithm.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\centering\n\t\\includegraphics[width=0.7\\columnwidth]{../res/a280_10.png}\n\t\\caption{The shortest greedy tours.}\n\t\\label{fig:a280_10_}\n\\end{figure}\n\n\n\n\\subsection{Greedy with CGAL Library}\nTo take a look at the potential of the CGAL library, we decided to implement the greedy algorithm. It follows the same idea as the one previously described (Section \\ref{sec:greedy}) but using completely different data structures. Thanks to the potential of the C++ code and therefore the use of objects, the CGAL library offers a very wide range of elements.\\\\ \nThe installation of CGAL within the Windows environment with Visual Studio 2019 is reported in the appendix \\ref{sec:cagalOne}.\\\\\nFirst of all, the objects used for this algorithm are briefly explained:\n\\begin{enumerate}\n\\item \\texttt{CGAL::Simple\\_cartesian <double> K}: The layer of geometry kernels provides basic geometric entities of constant size and primitive operations on them. Each entity is provided as both a stand-alone class, which is parameterized by a kernel class, and as a type in the kernel class. CGAL provides different kernels, they can differ by internal representation of objects (e.g. cartesian versus homogeneous) or provide different functionalities. When creating a new package, the authors have to specify clearly the requirements needed by the kernel used and may specify a targeted kernel in the list of predefined kernels. In this project \\texttt{Exact\\_predicates\\_inexact\\_constructions\\_kernel} is used. Thus, a \\texttt{Simple\\_cartesian} object is chosen to represent a model for a kernel using Cartesian coordinates to represent the geometric objects.\n\\item \\texttt{CGAL::Search\\_traits\\_2 <K> TreeTraits}: The \\texttt{Simple\\_cartesian} allows to define a dD Spatial Searching which is, in this kind of problems, a 2D space.\n\\item \\texttt{CGAL::Orthogonal\\_k\\_nemap.com\\_search <TreeTraits> Neighbor\\_search}: Thanks to the aforementioned objects, with this one a neighborhood search is created, based on the Euclidean distance in a Cartesian plane.\n\\item \\texttt{Neighbor\\_search::Tree Tree}: In our implementation was decided to use a Tree representation in which to apply the \\texttt{Neighbor\\_search}.\n\\end{enumerate}\nOnce the model and structure have been defined, the search is simple. Each node is created via the \\texttt{Point\\_2} object of the kernel defined above. The various points are assigned to the \\texttt{Tree}. As a last step just pass: the \\texttt{Tree}, the starting node and the number of total nodes to the \\texttt{Neighbor\\_search} and it return an list of nodes in ascending order of distance from the starting one.\\\\\nBy repeating this procedure for each node, a matrix of nodes sorted by distance from the starting point is obtained and with an ad hoc searching function:\n\n\\begin{lstlisting}\nvector<int>::iterator it = find_if(neigh_sol_idx[succ].begin(), neigh_sol_idx[succ].end(),\n\t\t\t\t\t [&](int neig) {\n\treturn find(var->sol[i].begin(), var->sol[i].end(), neig) == var->sol[i].end();\n});\n\\end{lstlisting}\n\nthe resulting matrix will have a number of lines equal to the number of nodes and each of them will be a tour built starting from a node and always choosing the closest from the current node, exactly as \\texttt{Greedy}. \\\\\nThe algorithm, as shown in fig. \\ref{fig:Lconstructives_time} , takes longer to run, as it uses higher level objects and methods than \\texttt {Greedy}. In fact, its potential lies in its application in complex problems, in which these data structures offer powerful and effective tools for geometric problems.\n\n\\section{Greedy Randomize Adaptive Search Path (GRASP)}\\label{sec:grasp}\nGRASP heuristic, as the name anticipate, is a Greedy constructive heuristic with some randomization. Indeed, for the TSP problem, instead of bringing the closer isolated node as next, it's chosen a random one between the first $ n $ closest isolated nodes, where $ n = 3 $ in the tested implementation.\nThe idea is that in TSP it's not always the closer to be the next node on the optimum tour. Moreover, in other metaheuristics that start from a solution and optimize it, a percentage of randomness could appreciated.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\begin{subfigure}{.75\\textwidth}\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lgrasp_greedy_time.png}\n\t\t\\caption{Solution time domain.}\n\t\t\\label{fig:Lgrasp_greedy_time}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.75\\textwidth}\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lgrasp_greedy_lb.png}\n\t\t\\caption{Solution cost domain.}\n\t\t\\label{fig:Lgrasp_greedy_lb}\n\t\\end{subfigure}\n\\caption{The first parameter in the name of \\texttt{n\\_greedy} and \\texttt{n\\_grasp} is the number of different tour evaluated. In \\texttt{n\\_grasp} name the other parameter represent the probability to chose in order the first, the second and the third closer node.  }\n\\label{fig:Lgrasp_greedy}\n\\end{figure}\nIn fig. \\ref{fig:Lgrasp_greedy} the result of the test with different $ n $ values for \\texttt{n\\_greedy} and \\texttt{n\\_grasp} and for different probability of choice of the next node in \\texttt{n\\_grasp}. There can be see the differences in execution time of \\texttt{heuristic\\_greedy} from the other and the gradual decrease of the cost of the \\texttt{n\\_grasp} by increasing the probability to select the closer node until \\texttt{n\\_greedy\\_10}    \n\nIn figure \\ref{fig:att48_diff} can be compared of the optimum tour, \\texttt{Greedy}, 3 different instances of \\texttt{GRASP} (\\texttt{n\\_grasp\\_1 \\\\ \\_33\\_33\\_33} version) and \\texttt{heuristic\\_insertion}. It's nice to see that the \\texttt{Greedy} (fig \\ref{fig:att48_GREEDY}) is pretty close to the optimal solution and also some instance of \\texttt{GRASP} like \\ref{fig:att48_GRASP2}. \\texttt{heuristic\\_insertion} in this example has no cross edges and as will be show in fig. \\ref{fig:Lgrasp_insertion_refining_LA_lb} the refining phase of this solutions does not improve so much the tour cost.\n\\begin{figure}[!h]\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/att48_0.png}\n\t\t\\caption{Optimal subtour: cost=10628, time=0.76s}\n\t\t\\label{fig:att48_best}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/att48_10.png}\n\t\t\\caption{\\texttt{Greedy}: cost=12012, time=0.005s}\n\t\t\\label{fig:att48_GREEDY}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/att48_12_1.png}\n\t\\caption{\\texttt{GRASP}: cost=21824, time=0.001s}\n\t\\label{fig:att48_GRASP1}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/att48_12_2.png}\n\t\\caption{\\texttt{GRASP}: cost=12576, time=0.001s}\n\t\\label{fig:att48_GRASP2}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/att48_12_3.png}\n\t\\caption{\\texttt{GRASP}: cost=22179, time=0.001s}\n\t\\label{fig:att48_GRASP3}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.49\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/att48_13.png}\n\t\\caption{\\texttt{heuristic\\_insertion}: cost=11197, time=0.0028s}\n\t\\label{fig:att48_insertion}\n\t\\end{subfigure}\n\t\\caption{Differences of \\texttt{Greedy} and \\texttt{GRASP} tour for \\textit{att48.tsp} instace.}\n\t\\label{fig:att48_diff}\n\\end{figure}\n\n\n\\section{Insertion Heuristic}\nThe idea of this constructive heuristic is to create an initial simple tour of 3 nodes randomly and insert one node at a time, breaking the edge that minimize the final tour cost.\\\\\nThe complexity of the algorithm is $ O(n^2) $.\n\n% versione 2\n\\textbf{Construction heuristic comparison.} The performance profile in fig \\ref{fig:pp_Lconstructives} show the three constructive presented in this chapter. In particular \\texttt{heristic\\_insertion} is comparable with \\texttt{n\\_greedy} and \\texttt{n\\_grasp} in execution time, however it find shorter tours of all the other constructive.\\\\\nOther consideration about the constructive heuristics in chapter \\ref{chapter:refining}.\n\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\begin{subfigure}{.9\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lconstructives_LA_time.png}\n\t\t\\caption{Solution time domain.}\n\t\t\\label{fig:Lconstructives_time}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.9\\textwidth}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{../res/Lconstructives_LA_lb.png}\n\t\\caption{Solution cost domain.}\n\t\\label{fig:Lconstructives_lb}\n\t\\end{subfigure}\n\t\\caption{Performance profile of constructive heuristic.}\n\t\\label{fig:pp_Lconstructives}\n\\end{figure}\n", "meta": {"hexsha": "5709e29ec6edd160c43eb8846bee8e3a0994d896", "size": 9672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/constructive-heuristics.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/constructive-heuristics.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/constructive-heuristics.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": 73.8320610687, "max_line_length": 867, "alphanum_fraction": 0.7754342432, "num_tokens": 2656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6463174164723084}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\\chapter{Combinatorial Search}\nSo far, we have learned the most fundamental search strategies on general data structures such as array, linked list, graph, and tree. In this chapter, instead of searching on explicit and well defined data structures, we extend and discuss more \\textit{exhaustive search} algorithms that can solve rather obscure and challenging \\textit{combinatorial problems}, such as sudoku and the famous Travels Salesman Problem. For combinatorial problems, we have to figure out the potential search space, and rummage a solution. \n\\section{Introduction}\nCombinatorial search problems consists of $n$ items and a requirement to find a solution, i.e., a set of $L < N$ items that satisfy specified conditions or constraints. For example, a sudoku problem where a $9\\times 9$ grid is partially filled with number between 1 and 9, fill the empty spots with numbers that satisfy the following conditions:\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width= 0.35\\columnwidth]{fig/250px-Sudoku-by-L2G-20050714.png}\n    \\includegraphics[width= 0.35\\columnwidth]{fig/250px-Sudoku-by-L2G-20050714_solution.png}\n    \\caption{A Sudoku puzzle and its solution}\n    \\label{fig:backtrack_puzzle_1}\n\\end{figure}\n\\begin{enumerate}\n    \\item Each row has all numbers form 1 to 9.\n    \\item Each column has all numbers form 1 to 9.\n    \\item Each sub-grid ($3 \\times3$) has all numbers form 1 to 9.\n\\end{enumerate}\nThis sudoku together with one possible solution is shown in Fig.~\\ref{fig:backtrack_puzzle_1}. In this case, we have $81$ items, and we are required to fill 51 empty items with the above three constraints. \n\\paragraph{Model Combinatorial Search Problems} \nWe can model the combinatorial search solution as a vector $s = (s_0, s_1, ..., s_{L-1})$, where each variable $s_i$ is selected from a finite  set $A$, which is called the \\textit{domain} for each variable. Such a vector might represent an arrangement where $s_i$ contains the i-th item of a permutation, in the combination problem, a boolean denotes if the i-th item is selected already, or it can represent a path in a graph or a sequence of moves in a game. In the sudoku problem, each $s_i$ can choose from a number in range $[1, 9]$.\n\n\n\\paragraph{Problem Categories} Combinatorial search problems arise in many areas of computer science such as artificial intelligence, operations search, bioinformatics, and electronic commerce. These problems typically involve finding a \\textit{grouping}, \\textit{ordering}, or \\textit{assignment} of a discrete, finite set of objects that satisfy given conditions or constraints.  We introduce two well-studied types of problems that are more likely to be NP-hard and of at least exponential complexity:\n% in computer science mainly studies algorithms that solve exponential or even NP-hard problems, such as:\n\\begin{enumerate}\n    \\item Constraint Satisfaction Problems (CSP) are mathematical questions defined as a set of variables whose state must satisfy a number of constraints or limitations(mathematical equations or inequations), such as Sudoku, N-queen, map coloring, Crosswords, and so on. The size of the search space of CSPs can be roughly given as:\n    \\begin{align}\n        O(cd^L)\n    \\end{align}\n    Where there are $L$ variables, each with domain size $d$, and there are $c$ constraints to check out. \n    \\item Combinatorial optimization problems consist of searching for maxima or minima of an objective function $F$ whose domain is a discrete but large configuration space.  Some classic examples are:\n    \\begin{itemize}\n        \\item Travelling Salesman Problems (TSP): given position $(x, y)$ of $n$ different cities, find the shortest possible path that visits each city exactly once.\n        \\item Integer Linear Programming: maximize a specified linear combination of a set of integers $X_1, .., X_{n}$ subject to a set of linear constraints each of the form:\n        \\begin{align}\n            a_1X_1 + ... + a_{n}X_{n} \\leq c\n        \\end{align}\n        \\item Knapsack Problems: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.\n    \\end{itemize}\n\\end{enumerate}\n\n\n\\paragraph{Search Strategies} From Chapter Discreet Programming, we have learned the basic enumerative combinatorics, including counting principles and knowledge on permutations, combinations, partitions, subsets, and subsequences. Combinatorial Search builds atop this subject, and together through different search strategies such as depth-first search and best-first search, it is able to enumerate the search space and find the solution(s)  with necessary speedup methods. In this chapter, we only discuss about complete search and only acknowledge the existence of approximate search techniques. \n\n\\textit{Backtracking} is a process of depth-first based search where it ``builds'' the search tree on the fly incrementally instead of having a tree/graph structure beforehand  to search through. Backtracking fits to solve combinatorial search problems because:\n\\begin{enumerate}\n    \\item It is space efficient for the usage of a DFS and the candidates are built incrementally and their validity to fit a solution is checked right away.\n    \\item It is time efficient for that some partial candidates can be pruned if the algorithm believes that it will not lead to our final complete solution. \n\\end{enumerate}\n\n Because the ordering of variables $s_0, ..., s_{L-1}$ can potentially affect the size of the search space sometimes. Thus, backtracking search relies on one or more heuristics to select which variable to consider next. \\textit{Look-ahead} is one such heuristic that is preferably applied to check the effects of choosing a given variable to evaluate or to decide the order of values to give to it. \n \n There are other Breath-first Search based strategies that might work better than backtracking, such as  for combinatorial optimization problems, best-first branch and bound search might be more efficient than its depth-first counterpart. \n\n\\paragraph{Speedups}\n\nThe speedup methods are well studied in computer science, and we list two general ways to prune unqualified or unnecessary branches during the search of backtracking:\n\\begin{enumerate}\n    \\item Branch and Prune: This method prunes the unqualified branches with constraints of the problems. This is usually applied to solve constraint restricted problems (CSPs).\n    \\item Branch and Bound: This method prunes unnecessary branches via comparing an estimation of a partial candidate with a found global best solution. If the estimation states that the partial candidate will never lead us to a better solution, we cut off this branch. This technique can be applied to solve a general optimization problems, such as Travel Salesman Problems (TSP), knapsack problems, and so.\n\\end{enumerate}\n% To notice that these speedup techniques are general for searching, not specifically for Backtracking. For example, branch and bound often be linked to best-first search. \n\n\\section{Backtracking}\nIn this section, we first introduce the technique of backtracking, and then demonstrate it by implementing common enumerative combinatorics seen in Chapter Discreet Programming. \n\\subsection{Introduction}\nBacktracking search is an exhaustive search algorithm(depth-first search) that systematically assigns all possible combinations of values to the variables and checks if these assignments constitute a solution. Backtracking is all about choices and consequences and it shows the following two properties:\n \\begin{enumerate}\n     \\item \\textbf{No Repetition and Completion:} It is a systematic generating method that enumerates all possible states exactly at most once: it will not miss any valid solution but  avoids repetitions. If there exists  ``correct'' solution(s), it is guaranteed to be found. This property makes it ideal for solving combinatorial problems where the search space has to be constructed  and enumerated. Therefore, the worst-case running time of backtracking search is exponential with the length of the state ($b^L$, $b$ is the average choice for each variable in the state).% such as combination and permutation which requires us to enumerate all possible solutions. We focus on demonstrating this property in this section. \n    \\item \\textbf{Search Pruning:} Along the way of working with partial solutions, in some cases, it is possible for us to decide if they will  lead to a valid \\textit{complete solution}. As soon as the algorithm is confident to say the partial configuration is either invalid or nonoptimal,  it abandons this  \\textit{partial candidate}, an then ``backtracks'' (return to the upper level), and resets to the upper level's state so that the search process can continue to explore the next branch for the sake of efficiency.  This is called \\textit{search pruning} with which  the algorithm ends up amortizely visiting each vertex less than once.  This property makes backtracking the most promising way to solve CSPs and combinatorial optimization problems. \n \\end{enumerate}\n\nSolving sudoku problem with backtracking algorithm, each time at a level in the DFS,  it tries to extend the last partial solution $s = (s_0, s_1, ..., s_{k})$ by trying out all 9 numbers at $s_{k+1}$, say we choose 1 at this step. It  testifies the partial solution with the desired solution:\n\\begin{enumerate}\n    \\item If the partial solution $s = (s_0, s_1, ..., s_{k}, 1)$ is still valid, move on to the next level and work on trying out $s_{k+2}$.\n    \\item If the partial solution is invalid and is impossible to lead to a complete solution, it ``backtracks'' to the last level and resets the state as $s = (s_0, s_1, ..., s_{k})$ so that it can try our other choices if there are some left(which in our example, we will try $s_{k+1}=2$) or keep ``backtracking'' to even upper level.\n\\end{enumerate}\nThe process should be way clearer once we have learned the examples in the following subsections. \n\n\\subsection{Permutations}\nGiven a list of items, generate all possible permutations of these items. If the set has duplicated items, only enumerate all unique permutations.\n\\subsubsection{No Duplicates(L46. Permutations)} When there are no duplicates, from Chapter Discreet Programming, we know the number of all permutations are:\n\\begin{equation}\n    p(n, m) = \\frac{n!}{(n-m)!}\n\\end{equation}\nwhere $m$ is the number of items we choose from the total $n$ items to make the permutations. \n\\begin{lstlisting}[numbers=none]\nFor example:\na = [1, 2, 3]\nThere are 6 total permutations:\n[1, 2, 3], [1, 3, 2],\n[2, 1, 3], [2, 3, 1],\n[3, 1, 2], [3, 2, 1]\n\\end{lstlisting}\n\\paragraph{Analysis} Let us apply the philosophy of backtracking technique. We have to build a state with length $3$, and each variable in the state has three choices: 1, 2, and 3. The constraint here comes from permutation which requires that no two variables in the state will be having the same value. To build this incrementally with backtracking, we state with an empty state \\texttt{[]}. At first, we have three options, we get three partial results $[1], [2]$, and $[3]$. Next, we handle the second variable in the state: for $[1]$, we can choose either 2 or 3,getting $[1,2]$ and $[1,3]$; same for $[2]$, where we end up with $[2,1]$ and $[2,3]$; for $[3]$, we have $[3,1]$ and $[3,2]$. At last, each partial result has only one option, we  get all permutations as shown in the example. We visualize this incrementally building candidates in Fig.~\\ref{fig:backtrack_permutation}. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width= 0.8\\columnwidth]{fig/permutation.png}\n    \\caption{The search tree of permutation}\n    \\label{fig:backtrack_permutation}\n\\end{figure}\n\nHowever, we only managed to enumerate the search space, but not systematically or recursively with the Depth-first search process. With DFS, we depict the traverse order of the vertexes in the virtual search space with red arrows in Fig.~\\ref{fig:backtrack_permutation}. The backward arrows mark the ``backtracking'' process, where we have to reset the state to the upper level. \n\n\\paragraph{Implementation} We  use a list of boolean \\texttt{bUsed} to track which item is used in the search process. \n\\texttt{n} is the total number of items, \\texttt{d} is the depth of the depth-first search process, \\texttt{curr} is the current state, and \\texttt{ans} is to save all permutations. The following code, we generate $p(n, m)$\n\\begin{lstlisting}[language=Python]\ndef p_n_m(a, n, m, d, used, curr, ans):\n  if d == m: #end condition\n    ans.append(curr[::]) \n    return\n  \n  for i in range(n):\n    if not used[i]:\n      # generate the next solution from curr\n      curr.append(a[i])\n      used[i] = True\n      print(curr)\n      # move to the next solution\n      p_n_m(a, n, m, d + 1, used, curr, ans)\n      #backtrack to previous partial state\n      curr.pop()\n      used[i] = False\n  return\n\\end{lstlisting}\nCheck out the running process in the source code.\n\n\\paragraph{Alternative: Swapping Method}   \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width= 0.8\\columnwidth]{fig/permutation_swap.png}\n    \\caption{The search tree of permutation by swapping. The indexes of items to be swapped are represented as a two element tuple. }\n    \\label{fig:backtrack_permutation_swap}\n\\end{figure}\nWe first start with a complete state, such that $s=[1, 2, 3]$ in our case. By swapping $1$ and $2$, we get $[2, 1, 3]$ and $[2, 3, 1]$ can be obtained by swapping $1$ and $3$ on top of $[2, 1, 3]$. With all permutations as leaves in the search space, the generating process is similar to Fig.~\\ref{fig:backtrack_permutation}. We show this alternative process in Fig.~\\ref{fig:backtrack_permutation_swap}. At first, we swap index 0 with all other indexes, including 0, 1, and 2. At the second layer, we move on to swap index 1 with all other successive indexes, and so on for all other layers.  The Python code is as:\n\\begin{lstlisting}[language=Python]\nans = []\ndef permutate(a, d):\n  global ans\n  if d == len(a):\n    ans.append(a[::])\n  for i in range(d, len(a)):\n    a[i], a[d] = a[d], a[i]\n    permutate(a, d+1)\n    a[i], a[d] = a[d], a[i]\n  return\n\\end{lstlisting}\nThere is Johnson-Trotter algorithm that utilizes such swapping method, which avoids recursion, and instead computes the permutations by an iterative method. \n\\subsubsection{With Duplicates(47. Permutations II)}\nWe have already know that $p(n, n)$ is further decided by the duplicates within the $n$ items. Assume we have in total of $d$ items are repeated, and each item is repeated $x_i$ times, then the number of all arrangements $pd(n, n)$ are:\n\\begin{align}\n    pd(n, n) &= \\frac{p(n, n)}{x_0!x_1!...x_{d-1}}, \\\\\n    \\texttt{w.r.t } & \\sum_{i=0}^{d-1} x_i \\leq n\n\\end{align}\nFor example, when $a = [1, 2, 2, 3]$, there are $\\frac{4!}{2!}$ unique permutations, which is 12 in total, and are listed as bellow:\n\\begin{lstlisting}[numbers=none]\n[1, 2, 2, 3], [1, 2, 3, 2], [1, 3, 2, 2],\n[2, 1, 2, 3], [2, 1, 3, 2], [2, 2, 1, 3],\n[2, 2, 3, 1], [2, 3, 1, 2], [2, 3, 2, 1],\n[3, 1, 2, 2], [3, 2, 1, 2], [3, 2, 2, 1]\n\\end{lstlisting}\n\\paragraph{Analysis} \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width= 1.2\\columnwidth]{fig/permutation_repeat.png}\n    \\caption{The search tree of permutation with repetition}\n    \\label{fig:backtrack_permutation_duplicates}\n\\end{figure}\nThe enumeration of these all possible permutations can be obtained with backtracking exactly the same as if there are no duplicates. However, this is not efficient since it has doubled the search space with repeated permutations. Here comes to our first time applying the Branch and Prune method:  we avoid repetition by pruning off redundant branches. \n\nOne main advantage of backtracking is not to save all intermediate states, thus we should find a mechanism that avoids generating these intermediate states at the first place.  One solution is that we sort all $n$ items, making all repeat items adjacent to each other. We know if the current intermediate state is redundant by simply comparing this item with its predecessor: if it equals, we move on from building state with this item to the next item in line. The search tree of our example is shown in Fig.~\\ref{fig:backtrack_permutation_duplicates}. \n\n\\paragraph{Implementation} The implementation is highly similar to previous standard permutation code other than three different points: \n\\begin{enumerate}\n\\item Before the items are called by \\texttt{permutate}, they are sorted first.\n\\item  A simple condition check to avoid generating repeat states.\n    \\item We used a dictionary data structure \\texttt{tracker} which has all unique items as keys and each item's corresponding occurrence as values to replace the boolean vector \\texttt{used} for slightly better space efficiency.\n\\end{enumerate}\nThe Python code is as:\n\\begin{lstlisting}[language=Python]\nfrom collections import Counter\ndef permuteDup(nums, k):\n    ans = []\n    def permutate(d, n, k, curr, tracker):  \n      nonlocal ans \n      if d == k:\n          ans.append(curr)\n          return\n      for i in range(n):\n          if tracker[nums[i]] == 0:\n            continue\n          if i - 1 >= 0 and nums[i] == nums[i-1]:\n              continue\n          tracker[nums[i]] -= 1\n          curr.append(nums[i])\n\n          permutate(d+1, n, k, curr[:], tracker)\n          curr.pop()\n          tracker[nums[i]] += 1\n      return\n    \n    nums.sort()\n    permutate(0, len(nums), k, [], Counter(nums))\n    return ans\n\\end{lstlisting}\n\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Can you extend the swap method based permutation to handle duplicates?} \n\\end{bclogo}\n\n\\subsubsection{Discussion}\nFrom the example of permutation, we have demonstrated how backtracking works to construct candidates with an implicit search tree structure: the root node is the initial state, any internal node represents intermediate states, and all leaves are our candidates which in this case there are $n!$ for $p(n, n)$ permutation. In this subsection, we want to point out the unique properties and its computational and space complexities.\n\\paragraph{Two Passes} Backtracking builds an implicit search tree on the fly, and it does not memorize any intermediate state. It visits the  vertices\n in the search tree in two passes: \n \\begin{enumerate}\n     \\item Forward pass: it builds the solution incrementally and reaches to the leaf nodes in a DFS fashion. One example of forward pass is $[]->[1]->[1,2]->[1,2,3]$.\n     \\item Backward pass: as the returning process from recursion of DFS, it also backtracks to previous state. One example of backward pass is $[1,2,3]->[1,2],->[1]$. \n \\end{enumerate}First, the forward pass to build the solution \\textbf{incrementally}.\nThe change of \\texttt{curr} in the source code indicates all vertices and the process of backtracking, it starts with $[]$ and end with $[]$. This is the core character of backtracking. We print out the process for the example as:\n\\begin{lstlisting}[numbers=none]\n[]->[1]->[1, 2]->[1, 2, 3]->backtrack: [1, 2]\nbacktrack: [1]\n[1, 3]->[1, 3, 2]->backtrack: [1, 3]\nbacktrack: [1]\nbacktrack: []\n[2]->[2, 1]->[2, 1, 3]->backtrack: [2, 1]\nbacktrack: [2]\n[2, 3]->[2, 3, 1]->backtrack: [2, 3]\nbacktrack: [2]\nbacktrack: []\n[3]->[3, 1]->[3, 1, 2]->backtrack: [3, 1]\nbacktrack: [3]\n[3, 2]->[3, 2, 1]->backtrack: [3, 2]\nbacktrack: [3]\nbacktrack: []\n\\end{lstlisting}\n\n\\paragraph{Time Complexity of Permutation}\nIn the search tree of permutation in Fig.~\\ref{fig:backtrack_permutation}, there are in total $V$ nodes, which equals to $\\sum_{i=0}^{n}{p_{n}^{k}}$. Because in a tree the number of edges $|E|$ is $|v|-1$, making the time complexity $O(|V|+|E|)$ the same as of $O(|V|)$. Since $p(n, n)$ itself alone takes $n!$ time, making the permutation an NP-hard problem. \n\n\\paragraph{Space Complexity} A standard depth-first search consumes $O(bd)$ space in worst-case to execute, where $b$ is branching factor and $d$ is the depth of the search tree. In the combinatorial search problems, usually depth and branching is decided by the total number of variables in the state, making $b \\sim d \\sim n$. In backtracking, we have space complexity $O(n^2)$. However, in normal standard DFS, the input--tree or graph data structure--is given and not attributed to space complexity. For a NP-hard combinatorial search problem, this input is often exponential. Backtracking search outcompetes the standard DFS by avoiding such space consumption; it only keeps a dynamic data structure(\\texttt{curr})  to construct node on the fly.  % The slight different can be critical for problems with large state description.  \n\n\\subsection{Combinations}\nGiven a list of $n$ items, generate all possible combinations of these items. If the input has duplicated items, only enumerate unique combinations. \n\\subsubsection{No Duplicates (L78. Subsets\n)}\nFrom Chapter Discrete Programming, we list the powerset--all $m$-subset, $m\\in[0, n]$ as:\n\\begin{align}\n    C(n, m) = \\frac{P(n, m)}{P(m, m)} = \\frac{n!}{(n-m)!m!}\n\\end{align}\nFor example, when $a=[1, 2, 3]$, there are in total $7$ $m$-subsets, they are:\n\\begin{lstlisting}[numbers=none]\nC(3, 0): []\nC(3, 1): [1], [2], [3]\nC(3, 2): [1, 2], [1, 3], [2, 3]\nC(3, 3): [1, 2, 3]\n\\end{lstlisting}\n\\paragraph{Analysis} \n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width= 0.5\\columnwidth]{fig/combination.png}\n    \\caption{The Search Tree of Combination.}\n    \\label{fig:backtrack_combination}\n\\end{figure}\nWe can simply reuse the method of permutation, but with a problem that it generates lots of duplicates. For example, $P(3, 2)$ includes $[1, 2]$ and $[2, 1]$ which are indeed the same subset. Of course, we can check redundancy with saved $m$-subsets, but its not ideal. A systematical solution that avoids duplicates all along is preferred. If we limit the items we put into the $m$-subsets to be only increasing(of indexes of items or of values of items), in which case $[2, 1]$, $[3,1]$, and $[3,2]$ will never be generated. The enumeration of combination through backtracking search is shown in Fig.~\\ref{fig:backtrack_combination}.\n\n\\paragraph{Implementation} Two modifications based on permutation code:\n\\begin{enumerate}\n    \\item \\texttt{for} loop: in the loop to iterate all possible candidates, we limit the candidates to be having larger indexes only.\n    \\item We do not have to use a data structure to track the state of each candidate because any candidate that has larger index is a valid candidate.\n\\end{enumerate}\nWe use \\texttt{start} to track the starting position of valid candidates. The code of combination is:\n\\begin{lstlisting}[language=Python]\ndef C_n_k(a, n, k, start, d, curr, ans):\n  if d == k: #end condition\n    ans.append(curr[::]) \n    return\n  \n  for i in range(start, n):    \n    curr.append(a[i])\n    C_n_k(a, n, k, i+1, d+1, curr, ans)\n    curr.pop()\n  return\n\\end{lstlisting}\n\n\\paragraph{Alternative: 0 and 1 Selection} We have discussed that a powerset written as $P(S)$. With each item either being appear or not appear in the resulting set makes the value set $\\{0, 1\\}$, resulting $|P(S)| = 2^n$. Follow this pattern, with our given example, we can alternatively generate a powerset like this:\n\\begin{lstlisting}[numbers=none]\ns   sets\n1   {1}, {}\n2   {1,2}, {1}, {2}, {}\n3   {1,2,3}, {1,2}, {1, 3}, {3}, {2, 3}, {2}, {3}, {}\n\\end{lstlisting}\nThis process can be better visualized in a tree as in Fig.~\\ref{}. We can see this process results $2^n$ leaves compared with our previous implementation which has a total of $2^n$ nodes is slightly less efficient. The code is as:\n\\begin{lstlisting}[language=Python]\ndef powerset(a, n, d, curr, ans):\n  if d == n:\n    ans.append(curr[::]) \n    return\n\n  # Case 1: select item\n  curr.append(a[d])\n  powerset(a, n, d + 1, curr, ans)\n  # Case 2: not select item\n  curr.pop()\n  powerset(a, n, d + 1, curr, ans)\n  return\n\\end{lstlisting}\n\n\\paragraph{Time Complexity} The total nodes within the implicit search space of combination shown in Fig.~\\ref{fig:backtrack_combination} is $\\sum_{k=0}^{n}C_{n}^{k} =2^n$, which was explained in Chapter Discreet Programming. Thus, the time complexity of enumerating the powset is $O(2^n)$ and is less compared with $O(n!)$ that comes with the permutation.\n\n\\paragraph{Space Complexity} Similarly, combination with backtracking search uses slightly less space. But, we can still acclaim the upper bound to be $O(n^2)$. \n\n\\subsubsection{With Duplicates(L90. Subsets II)}\n Assume we have $m$ unqiue items, and the frequency of each is marked as $x_i$, with $\\sum_{i=0}^{m-1}x_i = n$. \n\\begin{align}\n\\sum_{k=0}^{n} c(n, k) = \\prod_{i=0}^{m-1}(x_i + 1)\n\\end{align}\n\nFor example, when $a=[1, 2, 2, 3]$, there are $2\\times 3 \\times 2 = 12$ combinations in the powerset, they are listed as bellow:\n\\begin{lstlisting}[numbers=none]\n[], [1], [2], [3], [1, 2], [1, 3], [2, 2], [2, 3],\n[1, 2, 2], [1, 2, 3], [2, 2, 3],\n[1, 2, 2, 3]\n\\end{lstlisting}\nHowever, counting $c(n, k)$ with duplicates in the input replies on the specific input with specific distribution of these items. We are still able to count by enumerating with backtracking search. \n\\paragraph{Analysis and Implementation} The enumeration of the powerset with backtracking search is the same as handling the iterations of choice in the enumeration of permutation with duplicates. We first sort our items in increasing order of the values. Then we replace the \\texttt{for} loop from the above code with the following code snippet to handle the repetition of items from the input:\n\\begin{lstlisting}[language=Python]\n  for i in range(start, n): \n    if i - 1 >= start and a[i] == a[i-1]:\n              continue   \n    ...\n\\end{lstlisting}\n\\subsection{More Combinatorics}\nIn this section, we supplement more use cases of backtracking search in the matter of other types of combinatorics. \n\\subsubsection{All Paths in Graph}\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[width=0.4\\columnwidth]{fig/all_path_demo.png}\n    \\caption{Acyclic graph}\n    \\label{fig:my_label}\n\\end{figure} \nFor a given acyclic graph, enumerate all paths from a starting vertex $s$. For example, for the graph shown in Fig.~\\ref{fig:my_label}, and a starting vertex $0$, print out the following paths:\n\\begin{lstlisting}[numbers=none]\n0, 0->1, 0->1->2, 0->1->2->5, 0->1->3, 0->1->4, 0->2, 0->2->5\n\\end{lstlisting}\n\\paragraph{Analysis} The backtracking search here is the same as how to apply a DFS on an explicit graph, with rather one extra point: a state $path$ which might have up to $n$ items ( the total vertices of a graph). In the implementation, the \\texttt{path} vector will dynamically be modified to track all paths constructed as the go of the DFS. The code is offered as:\n% Backtracking technique can be naturally used in graph path traversal. One example is to find all possible paths from a source to the target. One simpler occasion is when the graph has no cycles. Backtrack technique can enumerate all paths in the graph exactly once for each. \n\n% The implementation is as follow: we still use dfs, because there has no cycles, we have no need to track the visiting state of each node. We generate the possible answer with backtracking technique through the \\texttt{path} variable to track each state. \n\\begin{lstlisting}[language=Python]\ndef all_paths(g, s, path, ans):\n  ans.append(path[::])\n  for v in g[s]:\n    path.append(v)\n    all_paths(g, v, path, ans)\n    path.pop()\n\\end{lstlisting}\nYou can run the above code in the Goolge Colab to see how it works on our given example.\n% Feed in the above network and run the following code:\n% \\begin{lstlisting}[language=Python]\n% al = [[1], [2], [4], [], [3, 5], [6], []]\n% ans = []\n% path = [0]\n% all_paths(al, 0, path, ans)\n% \\end{lstlisting}\n% With the printing, we can see the whole process, \\texttt{path} changes as the description of backtrack. \\begin{lstlisting}[numbers=none]\n% [0, 1]\n% [0, 1, 2]\n% [0, 1, 2, 4]\n% [0, 1, 2, 4, 3]\n% [0, 1, 2, 4] backtrack\n% [0, 1, 2, 4, 5]\n% [0, 1, 2, 4, 5, 6]\n% [0, 1, 2, 4, 5] backtrack\n% [0, 1, 2, 4] backtrack\n% [0, 1, 2] backtrack\n% [0, 1] backtrack\n% [0] backtrack\n% \\end{lstlisting}\n% We can see each state, we can always have a matching backtrack state. \n% \\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{What to do if there is a cycle?} \n% \\end{bclogo}\n\n\\subsubsection{Subsequences(940. Distinct Subsequences II)} Given a string, list all unique subsequences. There may or may not exist duplicated characters in the string. For example, when $s='123'$, there are in total 7 subsequences, which are:\n\\begin{lstlisting}[numbers=none]\n'', '1', '2', '3', '12', '13', '23', '123'\n\\end{lstlisting}\nWhen $s='1223'$ which comes with duplicates, there are 12 subsequences:\n\\begin{lstlisting}[numbers=none]\n'', '1', '2', '3', '12', '13', '22', '23', \n'122', '123', '223',\n'1223'\n\\end{lstlisting}\n\\paragraph{Analysis} From Chapter Discrete Programming, we have explained that we can count the number of unique subsequences through recurrence relation and pointed out the relation of subsquences with subsets(combinations). Let the number of unique subsequences of a sequence as $seq(n)$ and the number of unique subsets of a set as $set(n)$ with $n$ items in the input. All subsequences are within subsets, and the subsequence set has larger cardinality than subsets, $|seq(n)|\\geq |set(n)|$. From the above example, we can also see that when there are only unique items in the sequence or when there are duplicates but all duplicates of an item are adjacent to each other:\n\\begin{itemize}\n    \\item The cardinality of subsequences and subsets equals, $|seq(n)= set(n)|$.\n    \\item The subsequences and subsets share the same items when the ordering of the subsequences are ignored. \n\\end{itemize}\nThis indicates that the process of enumerating subsequences is almost the same as of enumerating a powerset. This should give us a good start.\n\n\\paragraph{Implementation} However, if we change the ordering of the duplicated characters in the above string as $s='1232'$, there are in total 14 subsequences instead:\n\\begin{lstlisting}[numbers=none]\n'', '1', '2', '3', '12', '13', '23', '22', '32',\n'123', '122', '132', '232',\n'1232'\n\\end{lstlisting}\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width= 1.0\\columnwidth]{fig/subsequence.png}\n    \\caption{The Search Tree of subsequences.The red circled nodes are redundant nodes. Each node has a variable $s$ to indicate the starting index of candidates to add to current subsequence. $i$ indicate the candidate to add to the current node.}\n    \\label{fig:backtrack_subsequence}\n\\end{figure}\nTherefore, our code to handle duplicates should differ from that of a powerset.  In the case of powerset, the algorithm first sorts items so that all duplicates are adjacent to each other, making the checking of repetition as simple as checking the equality of item with its predecessor. However, in a given sequence, the duplicated items are not adjacent most of the time, we have to do things differently. We draw the search tree of enumerating all subsequences of string ``1232'' in Fig.~\\ref{fig:backtrack_subsequence}. From the figure, we can observe that to avoid redundant branches, we simply check if a current new item in the subsequence is repeating by comparing it with all of its predecessors in range $[s, i]$. The code for checking repetition is as:\n\\begin{lstlisting}[language=Python]\ndef check_repetition(start, i, a):\n  for j in range(start, i):\n    if a[i] == a[j]:\n      return True\n  return False\n\\end{lstlisting}\nAnd the code to enumerate subsequences is:\n\\begin{lstlisting}[language=Python]\ndef subseqs(a, n, start, d, curr, ans):\n  ans.append(''.join(curr[::])) \n  if d == n: \n    return\n  \n  for i in range(start, n):  \n    if check_repetition(start, i, a):\n      continue    \n    curr.append(a[i])\n    subseqs(a, n, i+1, d+1, curr, ans)\n    curr.pop()\n  return\n\\end{lstlisting}\n\n \n\n\\subsection{Backtracking in Action}\nSo far, we have applied backtracking search to enumerate combinatorics. In this section, we shall see how  backtracking search along with search pruning speedup methods solve two types of challenging NP-hard problems: Constraint Satisfication Problems (CSPs) and Combinatorial Optimization Problems. \n\nAs we have briefly introduced the speedup methods needed to solve larger scale of CSPs and COPs. For example, assume within the virtual search tree, the algorithm is currently at level 2 with state $s=[s_0, s_1]$. If there are $c$ choices for state $s_1$, and if one choice is testified to be invalid, this will prune off $\\frac{1}{c}$ of the whole search space. In this section, we demonstrate backtracking search armored with Branch and Prune method solving CSPs and Branch and Bound solving COPs.\n\n\n\\section{Solving CSPs}\nOfficially, a constraint satisfaction problem(CSP) consists of a set of $n$ variables, each denoted as $s_i$, $i\\in[0, n-1]$; their respective value domains,  each denoted as $d_i$; and a set of $m$ constraints, each denoted as $c_j$, $j \\in [0, m-1]$. A \\textit{solution} to a CSP is an assignment of values to all the variables such that no constraint is violated. A \\textit{binary} CSP is one in which each of the constraints involves at most two variables. A CSP can be represented by a \\textit{constraint graph} which has a node for each variable and each constraint, and an arc connecting variable nodes contained in a constraint to the corresponding constraint node.\n\nWe explain a few strategies from the CSP-solver's arsenal that can potentially speedup the process:\n\\begin{enumerate}\n    \\item Forward Checking: The essential idea is that when a variable $X$ from $s_i$ is instantiated with a value $x$ from its domain $d_i$, the domain of each future uninstantiated variable $Y$ is examined. If a value $y$ is found such that $X=x$ conflicts with $Y=y$, then $y$ is temporarily removed from the domain of $Y$. \n    \\item Variable Ordering: The order in which variables are considered while solving a CSP method can have a substantial impact on the search space. One effective ordering is always select the next variable with the smallest remaining domain. In a dynamic variable ordering, the order of variables is determined as the search progresses, and often goes with forward checking which keeps updating the uninstantiated variables' domains. Selecting variable with the minimal domain first can pinpoint the solution quickly given the fact that the branch is still early on, and branch pruning at this stage is more rewarding. Another reasoning is that each step, when we are multiplying $d_i$ to the cost, we are adding the least expensive one, making this a greedy approach. \n\\end{enumerate}\n\\subsubsection{Sudoku (L37)} \n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width= 0.35\\columnwidth]{fig/250px-Sudoku-by-L2G-20050714.png}\n    \\includegraphics[width= 0.35\\columnwidth]{fig/250px-Sudoku-by-L2G-20050714_solution.png}\n    \\caption{A Sudoku puzzle and its solution}\n    \\label{fig:backtrack_puzzle_2}\n\\end{figure}\nA Sudoku grid shown in Fig.~\\ref{fig:backtrack_puzzle_2} is a $n^2\\times n^2$ grid, arranged into $n$ $n\\times n$ mini-grids each containing the values $1,...,n$ such that no value is repeated in any row, column (or mini-grid).  \n\\paragraph{Search Space}\nFirst, we analyze the number of distinct states in the search space which relies on how we construct the intermediate states and  our knowledge in Enumerative combinatorics. We discuss two different formulations on $9 \\times 9$ grid:\n\\begin{enumerate}\n    \\item For each empty cell in the puzzle, we create a set by taking values $1, ..., 9$ and removing from it those values that appear as a given in the same row, column, or mini-grid as that cell. Assume we have $m$ spots and the corresponding candidate set of each spot is $c_i$, and initial cost estimation can be obtained which is:\n    \\begin{align}\n        T(n) = \\prod_{i=0}^{m-1} c_i\n    \\end{align}\n    \\item Each row can be presented by a 9-tuples, there will be 9 rows in total, resulting 9 9-tuples to represent the search state. With $c_i$ as the number of non-given values in the i-th 9-tuples, there are $c_i!$ ways of ordering these values by permuting.The number of different states in the search space is thus:\n    \\begin{align}\n        T(n) = \\prod_{i=0}^{8} c_i!\n    \\end{align}\n\\end{enumerate}\nThe two different ways each takes a different approach to formulate the state space, making its corresponding backtracking search differs too. We mainly focus on the first formulation with backtracking search.\n\\paragraph{Speedups} \n% \\begin{figure}[h]\n%     \\centering\n%     \\includegraphics[width= 0.5\\columnwidth]{fig/sudoku_backtracking.png}\n%     \\caption{Partial search tree of Sudoku in Fig.~\\ref{fig:backtrack_puzzle_2}}\n%     \\label{fig:backtrack_sudoku}\n% \\end{figure}\nAssume we have known all empty spots(variables) to fill in and we construct the search tree using backtracking. In our source code, we did an experiment comparing the effect of ordering variables with minimal domain first rule with arbitrary ordering. The experiment shows that the first method is more than 100 times faster than the second solving the our exemplary Sudoku puzzle. Therefore, we decide to always select the variable that has the least domain set to proceed next in the backtracking.\n\nFurther, we apply forward checking, for the current variable and a value we are able to assign, we recompute all the remaining empty spots' domain sets, and use the updated domain sets to decide:\n\\begin{itemize}\n    \\item If this assigment will lead to empty domain for any of other remaining spots, and if so, we terminate the search and backtrack.\n    \\item The spot to select next time with the ordering rule we choose. \n\\end{itemize}\n\\paragraph{Implementation} We set aside three vectors of length 9,  \\texttt{row\\_state}, \\texttt{col\\_state}, and \\texttt{block\\_state} to track the state of all 9 rows, columns, and grids. The list has \\texttt{set()} data structures as items, saving the numbers filled already in that row, col, and grid respectively. Two stages in the implementation:\n\\begin{enumerate}\n    \\item Initialization: We scan the whole each spot in the $9\\times 9$ grid to record the states of the filled spots and to find all empty spots that waiting to be filled in.  With $(i,j)$ to denote the position of a spot, it corresponds to \\texttt{row\\_state[i]}, \\texttt{col\\_state[j]}, and \\texttt{block\\_state[i//3][j//3]}. We also write two functions to set and reset state with one assignment in the backtracking. The Python code is as follows:\n\\begin{lstlisting}[language=Python]\nfrom copy import deepcopy\nclass Sudoku():\n  def __init__(self, board):\n    self.org_board = deepcopy(board)\n    self.board = deepcopy(board)\n    \n  def init(self):\n    self.A = set([i for i in range(1,10)])\n    self.row_state = [set() for i in range(9)]\n    self.col_state = [set() for i in range(9)]\n    self.block_state = [[set() for i in range(3)] for i in range(3)]\n    self.unfilled = []\n\n    for i in range(9):\n      for j in range(9):\n          c = self.org_board[i][j]\n          if c == 0:\n              self.unfilled.append((i, j))\n          else:\n              self.row_state[i].add(c)\n              self.col_state[j].add(c)\n              self.block_state[i//3][j//3].add(c)\n  \n  def set_state(self, i, j, c):\n    self.board[i][j] = c\n    self.row_state[i].add(c)\n    self.col_state[j].add(c)\n    self.block_state[i//3][j//3].add(c)\n    \n  def reset_state(self, i, j, c):\n    self.board[i][j] = 0\n    self.row_state[i].remove(c)\n    self.col_state[j].remove(c)\n    self.block_state[i//3][j//3].remove(c)\n\\end{lstlisting}\n\n\\item Backtracking search with speedups:  In the initialization, we have another variable $A$ used as the domain set of the current processing spot. To get the domain set according to the constraints, a simple set operation is executed as: $A-(row\\_state[i]|col\\_state[j]|block\\_state[i//3][j//3])$. In the solver, each time, to pick a spot, we first update all remaining spots in the \\texttt{unfilled} and then choose the one with minimal domain. This process takes $O(n)$ which is trivial compared with the cost of the searching, with $9$ for computing domain set of a single spot, $9n$ for $n$ spots, and adding another $n$ to $9n$ to choose the one with the smallest size. The solver is implemented as:\n\\begin{lstlisting}[language=Python]\n  def _ret_len(self, args):\n    i, j = args\n    option = self.A - (self.row_state[i] | self.col_state[j] | self.block_state[i//3 ][j//3])\n    return len(option)\n    \n  def solve(self):\n    if len(self.unfilled) == 0:\n      return True\n    # Dynamic variables ordering\n    i, j = min(self.unfilled, key = self._ret_len)\n    # Forward looking\n    option = self.A - (self.row_state[i] | self.col_state[j] | self.block_state[i//3 ][j//3])\n    if len(option) == 0:\n      return False\n    self.unfilled.remove((i, j))\n    for c in option:\n      self.set_state(i, j, c)\n      if self.solve():\n        return True\n      # Backtracking\n      else:\n        self.reset_state(i, j, c)\n    # Backtracking\n    self.unfilled.append((i, j))\n    return False\n\\end{lstlisting}\n\\end{enumerate}\n\n\n\\section{Solving Combinatorial Optimization Problems}\n% Combinatorial optimization problems are characterized by an \\textit{input}, i.e., a general description of conditions and parameters, and an \\textit{objective} defining \n\nCombinatorial optimization is an emerging field at the forefront of combinatorics and theoretical computer science that aims to use combinatorial techniques to solve discrete optimization problems.  From a combinatorics perspective, it interprets complicated questions in terms of a fixed set of objects about which much is already known: sets, graphs, polytopes, and matroids. From the perspective of computer science, combinatorial optimization seeks to improve algorithms by using  mathematical methods either to reduce the size of the set of possible solutions or to make the search itself faster. \n\nGenuinely, the inner complexity of a COP is at least of exponential, and its solutions fall into two classes: exact methods and heuristic methods. In some cases, we may be able to find efficient exact algorithms with either greedy algorithms or dynamic programming technique such as finding the shortest paths on a graph can be solved by the Dijkstra (greedy) or Bellman-Ford algorithms(dynamic programming) to provide exact optimal solutions in polynomial running time. For more complex problems, COP can be mathematically formulated as a Mixed Linear Programming(MILP) model and which is generally solved using a linear-programming based branch-and-bound algorithm.  But, in other cases no exact algorithms are feasible, and the following randomized heuristic search algorithms though we do not cover in this section should be applied:\n\\begin{enumerate}\n    \\item Random-restart hill-climbing.\n    \\item Simulated annealing.\n    \\item Genetic Algorithms.\n    \\item Tabu search.\n\\end{enumerate}\n\n\\paragraph{Model Combinatorial Optimization Problems} It is a  good practice to formulate COPs with mathematical equations/inequations, which includes  three steps:\n\\begin{enumerate}\n    \\item Choose the decision variables that typically encode the result we are interested in, such that in a superset problem, each item is a variable, and each variable includes two decisions: take or not take, making its value set as ${0, 1}$.\n    \\item Express the problem constraints in terms of these decision variables to specify what the feasible solutions of the problem are.\n    \\item Express the objective function to specify the quality of each solution.\n\\end{enumerate}\nThere are generally many ways to model a COP.\n\n\n\\paragraph{Branch and Bound} Branch and bound (BB, B$\\&$B, or BnB) is an algorithm design paradigm for discrete and combinatorial optimization problems, as well as mathematical optimization. A branch-and-bound algorithm consists of a systematic enumeration of candidate solutions by means of state space search: the set of candidate solutions is thought of as forming a rooted tree with the full set at the root. The algorithm explores branches of this tree, which represent subsets of the solution set. Before enumerating the candidate solutions of a branch, the branch is checked against upper and lower estimated bounds on the optimal solution, and is discarded if it cannot produce a better solution than the best one found so far by the algorithm. ``Branching'' is to split problem into a number of subproblems, and ``bounding'' is to find an optimistic estimation of the best solution to the the subproblems to either maximize the upper bound or minimize the lower bound.  To get the optimistic estimation, we have to \\textit{relax constraints}.  In this section, we will exemplify both the minimization(TSP) and maximization problem(Knapsack). \n\n\\paragraph{Search Strategies} In practice, we can apply different search strategies to enumerate the search space of the problem, such as depth-first, best-first, and least-discrepancy search. The way of how each listed strategy is applied in the combinatorial optimization problems is:\n\\begin{itemize}\n    \\item Depth-First: it prunes when a node estimation is worse than the best found solution.\n    \\item Best-First: it selects the node with the best estimation among the frontier set to expand each time. Worst scenario, the whole search tree have to be saved as long the best estimation is extremely optimistic and not a single branch is pruned in the process. \n    \\item Least-Discrepancy: it trusts a greedy heuristic, and then move away from the heuristic in a very systematic fashion. \n\\end{itemize}\n\nIn this section, we discuss exact algorithms using Branch and Bound with a variation of search strategies. During the interviews, questions that have polynomial exact solutions are more likely to appear, proving your mastery of dynamic programming or greedy algorithms design methodologies. However, it is still good to discuss this option. \n\n%%%%%%%%%%%%%%%%%%%%\n\\subsection{Knapsack Problem}\n% In this section we want to showcase more searching strategies applied in solving optimization problems: comparing backtracking and a chance to use best-first search strategy. \n\nGiven $n$ items with weight and value indicated by two vectors $W$ and $V$ respectively. Now, given a knapsack with capacity $c$, maximize the value of items selected into the knapsack with the total weight being bounded by $c$. Each item can be only used at most once. For example, given the following data, the optimal solution is to  choose item 1 and 3, with total weight of 8, and optimal value of 80.\n\\begin{lstlisting}[numbers=none]\nc = 10\nW = [5, 8, 3]\nV = [45, 48, 35]\n\\end{lstlisting}\n\\paragraph{Search Space} In this problem, $x_i$ denotes each item, and $w_i$, $v_i$ for its corresponding weight and value, with $i\\in[0, n-1]$. Each item can either be selected or left behind, indicating $x_i\\in{0, 1}$. The selected items can not exceed the capacity, making $\\sum_{i=0}^{n-1} w_i x_i \\leq c$. And we capture the total value of the selected items as $\\sum_{i=0}^{n-1} v_i x_i$.  Putting it all together:\n\\begin{align}\n    \\max_{v, x} \\quad & \\sum_{i=0}^{n-1} v_i x_i\\\\\n    \\textrm{s.t.} \\quad  & \\sum_{i=0}^{n-1} w_i x_i \\leq c\\\\\n    & x_i\\in{0, 1}\n\\end{align}\nWith each variable having two choices, our search space is as large as $2^n$.\n\n\\paragraph{Branch and Bound} \n\nTo bound the search, we have to develop a heuristic function to estimate an optimistic--maximum--total value a branch can lead to. \n\nIn the case of knapsack problem, the simplest estimation is summing up the total values of selected items so far, and estimate the maximum value by adding the accumulated values of all remaining unselected items along the search. \n\n% And a branch is checked \n% \\begin{align}\n%     \\texttt{if } estimate < found, \n% \\end{align}\n\nA tighter heuristic function can be obtained with \\textbf{constraint relaxation}. By relaxing the condition of simply choose $\\{0, 1\\}$ to $[0, 1]$, that a fraction of an item can be chosen at any time. By sorting the items by the value per unit $\\frac{v_i}{w_i}$, then a better estimate can be obtained by filling the remaining capacity of knapsack with unselected items, with larger unit value first be considered. A branch is checked on the optimal solution so far against the lower estimated bound in our case, and is discarded if it cannot produce a better solution than the best one found so far by the algorithm. Both heuristic functions are more optimistic compared with the true value, but the later is a tighter bound, being able to prune more branches along the search and making it more time efficient. We demonstrate branch and bound with two different search strategies: DFS(backtracking) and Best-First search.\n\n\n\n% the items while the capacity is not exhausted, then select a fraction of the last item to fill the remaining capacity, which is a closer estimate of the real one but still optimisitc compared with selecting the remaining items.  What if we are allowed to get part of an item, so that we can fit the knapsack as full as possible. We can sort the items by their unit value, and take items in the order of decreasing unit values. Another bool vector is used to indicate if a certain item can be used or not. At first, all items are allowed, we can get an estimation of 92 in this case. For branches that decide not to take an item, that item is excluded using the bool vector.  We compare the estimation with the best found value, if the estimated value will never be better, then this branch will prunned. \n\n\n\\subsubsection{Depth-First Branch and Bound}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width= 0.98\\columnwidth]{fig/branch_and_bound_backtracking.png}\n    \\caption{Depth-First Branch and bound}\n    \\label{fig:knapsack_backtracking}\n\\end{figure}\nWe set up a class \\texttt{BranchandBound} to implement this algorithm. First, in the initiation, we add additional $\\frac{v_i}{w_i}$ to mark each item's value per unit, and sort these items by this value in decreasing order. Second, we have a function \\texttt{estimate} which takes three parameters: \\texttt{idx} as start index of the remaining items, \\texttt{curval} is the total value based on all previous decision, and \\texttt{left\\_cap} as the left capacity of the knapsack. The code snippet is:\n\\begin{lstlisting}[language=Python]\nimport heapq\n\nclass BranchandBound:\n  def __init__(self, c, v, w):\n    self.best = 0 \n    self.c = c\n    self.n = len(v)\n    self.items = [(vi/wi, wi, vi) for _, (vi, wi) in enumerate(zip(v, w))]\n    self.items.sort(key=lambda x: x[0], reverse=True)\n\n  def estimate(self, idx, curval, left_cap):\n    est = curval\n    # use the v/w to estimate\n    for i in range(idx, self.n):\n      ratio, wi, _ = self.items[i]\n      if left_cap - wi >= 0: # use all\n        est += ratio * wi\n        left_cap -= wi\n      else: # use part\n        est += ratio * (left_cap)\n        left_cap = 0 \n    return est\n\\end{lstlisting}\nIn the Depth-first search process, it consists of two main branches: one considering to choose the current item, and the other to handle the case while the item is not selected. For the first branch, it has to be bounded by the capacity and the comparison of the best found solution against to the estimation. Additional \\texttt{status} is to assist to visualize the process of the search, which tracks the combination of items. The process is shown in Fig.~\\ref{fig:knapsack_backtracking}.  And the code is as:\n\\begin{lstlisting}[language=Python]\n  def dfs(self, idx, est, val, left_cap, status):\n      if idx == self.n:\n        self.best = max(self.best, val)\n        return\n      print(status, val, left_cap, est )\n      \n      _, wi, vi = self.items[idx]\n      # Case 1: choose the item\n      if left_cap - wi >= 0: # prune by constraint\n        # Bound by estimate, increase value and volume\n        if est > self.best:   \n          status.append(True)\n          nest = self.estimate(idx+1, val+vi, left_cap - wi)   \n          self.dfs(idx+1, nest, val+vi, left_cap - wi, status)\n          status.pop()\n\n      # Case 2: not choose the item\n      if est > self.best:\n        status.append(False)\n        nest =  self.estimate(idx+1, val, left_cap)\n        self.dfs(idx+1, nest, val, left_cap, status) \n        status.pop()\n      return\n\\end{lstlisting}\n\\subsubsection{Best-First Branch and Bound}\nWithin Best-First search, we use priority queue with the estimated value, and each time the one with the largest estimated value within the frontier set is expanded first. Similarly, with branch and bound, we prune branch that has estimated value that would never surpass the best solution up till then. The search space is the same as in   Fig.~\\ref{fig:knapsack_backtracking} except that the search process is different from depth-first. In the implementation, the priority queue is implemented with a min-heap where the minimum value is firstly popped out, thus we use the negative estimated value to make it always pop out the largest value conveniently instead of write code to implement a max-heap. \n\\begin{lstlisting}[language=Python]\n  def bfs(self):\n      # track val, cap, and idx is which item to add next\n      q = [(-self.estimate(0, 0, self.c), 0, self.c, 0)] # estimate, val, left_cap, idx\n      self.best = 0\n      while q:\n        est, val, left_cap, idx = heapq.heappop(q)\n        est = -est\n        _, wi, vi = self.items[idx]\n        if idx == self.n - 1:\n          self.best = max(self.best, val)\n          continue\n        \n        # Case 1: choose the item\n        nest = self.estimate(idx + 1, val + vi, left_cap - wi)\n        if nest > self.best:\n          heapq.heappush(q, (-nest, val + vi, left_cap - wi, idx + 1))\n\n        # Case 2: not choose the item\n        nest = self.estimate(idx + 1, val, left_cap)\n        if nest > self.best:\n          heapq.heappush(q, (-nest, val, left_cap, idx + 1))\n      return \n\\end{lstlisting}\n\n\\subsection{Travelling Salesman Problem}\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width= 0.4\\columnwidth]{fig/tsp_graph.png}\n    \\caption{A complete undirected weighted graph.}\n    \\label{fig:tsp_graph}\n\\end{figure}\nGiven a set of cities and the distances between every pair, find the shortest possible path that visits every city exactly once and returns to the origin city. For example, with the graph shown in Fig.~\\ref{fig:tsp_graph}, such shortest path is $[0, 1, 3, 2, 0]$ with a path weight $80$. \n% \\begin{lstlisting}[numbers=none]\n% Assume our graph is a two dimensional list:\n% g = [[(1, 10), (2, 15), (3, 20)], \n%   [(0, 10), (2, 35),(3,25)],\n%   [(0, 15),(1,35),(3,30)],\n%   [(0,20),(1,25),(2,30)]]\n% g[0][0]=(1,10), means the edge between 0 and 1 with cost 10.\n% \\end{lstlisting}\n\n\\paragraph{Search Space} In TSP, a possible complete solution is a \\textit{Hamiltonian cycle}, a graph cycle that visits each vertex exactly once. Since it is a cycle, it does not matter where it starts. For convenience, we choose vertex $0$ as the origin city. Therefore, in our example, our path starts and ends at $0$, and the remaining $n-1$ vertices between will  be a permutation of these vertices, making the complexity as $(n-1)!$. \n\nBecause this is a complete graph, it might be tempting to apply backtracking on the graph to enumerate all possible paths and find and check possible solutions. However, this path searching will build a $n-1$-ary search tree with height equals to $n-1$, making the complexity as $\\frac{(n-1)^{n}-1}{n-2}$, which is larger than the space of permutation among $n-1$ items. Therefore, in our implementation, we apply backtracking to enumerate all permutations of $n-1$ vertices and check its corresponding cost.  \n\n\\paragraph{Speedups} Since we only care about the minimum cost, then any partial result that has cost larger than the  minimum cost of all known complete solutions can be prunned. This is the \\textit{Branch and bound} method that we have introduced that is often used in the combinatorial optimization. \n% solution is path with vertices forming a cycleneed to construct a list of vertices (\\texttt{path}) and its total cost (\\texttt{cost}) of all edges between as the state $s=(p, c)$, $p, c$ is short for path and cost respectively. A possible complete solution for path will have $n+1$ vertices which start with a vertex and end with the same, and $n-1$ vertices in between. Now, put together about constraints.\n% \\begin{itemize}\n%     \\item ``Visits every city exactly once'' means the first vertex will be a permutation of all cities, we get $n!$ combination (the last vertex does not matter).\n%     \\item We have $n!$ possible states. We can further spot redundant states. For a cycle, it does not matter where it starts, it is always the same cycle. For convenience, we choose vertex $0$ as the starting path, and there will only be $n-1$ vertex to permutate with, making the size of the state space to $(n-1)!$. \n%     \\item We only care about the minimum cost, then any partial result that has cost larger than the  minimum cost of all known complete solution can be prunned. This is called \\textit{Branch and bound} method, which is the extension of backtracking into the optimization problems.\n% \\end{itemize}\n\n\\paragraph{Implementation}  We built the graph as a list of dictionaries, each dictionary stores the indexed vertex's other cites and its corresponding distance as key and value respectively. Compared with standard permutation with backtracking, we add four additional variables: \\texttt{start} to track the starting vertex, \\texttt{g} to pass the graph to refer the distance information, \\texttt{mincost} to save the minimum complete solution so far found, and \\texttt{cost} to track the current partial path's cost. The code is shown as: \n\\begin{lstlisting}[language=Python]\ndef tsp(a, d, used, curr, ans, start, g, mincost, cost):\n  if d == len(a): \n    # Add the cost from last vertex to the start\n    c = g[curr[-1]][start]\n    cost += c\n    if cost < mincost[0]:\n      mincost[0] = cost\n      ans[0] = curr[::] + [start]\n    return\n  \n  for i in a:\n    if not used[i] and cost + g[curr[-1]][i] < mincost[0] :\n      cost += g[curr[-1]][i]\n      curr.append(i)\n      used[i] = True      \n      tsp(a, d + 1, used, curr, ans, start, g, mincost, cost)\n      curr.pop()\n      cost -= g[curr[-1]][i]\n      used[i] = False\n  return\n\\end{lstlisting}\nTSP is a NP-hard problem, and there is no known polynomial time solution so far.\n\n\n\n\\subsubsection{Other Solutions}\nWhenever we are faced with optimization, we are able to consider the other two algorithm design paradigm--Dynamic Programming and Greedy Algorithms. In fact, the above two problems both have its corresponding dynamic programming solutions: for knapsack problem, polynomial solution is possible; for TSP, though it is still of exponential time complexity, it is much better than $O(n!)$. We will further discuss these two problems in Chapter Dynamic Programming. \n\\section{Exercises}\n\\begin{enumerate}\n\\item 77. Combinations\n\\item 17. Letter Combinations of a Phone Number\n\\item 797. All Paths From Source to Target\n    \\item N-bit String: enumerate all n-bit strings with backtracking algorithm, for example:\n\\begin{lstlisting}[numbers=none]\nn = 3, all 3-bit strings are:\n000, 001, 010, 011, 100, 101, 110, 111\n\\end{lstlisting}\n\\item 940. Distinct Subsequences II\n\\item N-queen\n\\item Map-coloring\n\\item 943. Find the Shortest Superstring (hard). Can be moduled as traveling salesman problem and dynamic programming\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "3812786142e1dfcabba0b29f0a67f1cf4be8a745", "size": 59795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_combinatorial_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/chapter_combinatorial_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/chapter_combinatorial_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": 75.8819796954, "max_line_length": 1151, "alphanum_fraction": 0.7340747554, "num_tokens": 15590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6463174112015535}}
{"text": "\n\\subsection{The Lie bracket}\n\nWe can define the Lie bracket from the ring commutator.\n\nWe use the Lie bracket, rather than multiplication, as the operator over a field homomorphism.\n\n\\([A, B]\\)\n\nThis generates another element in the algebra.\n\nThis satisifies:\n\n\\begin{itemize}\n\\item Bilinearity: \\([xA+yB,C]=x[A,C]+y[B,C]\\)\n\\item Alternativity: \\([A,A]=0\\)\n\\item Jacobi identity: \\([A, [B,C]]+[C,[A,B]]+[B,[C,A]]=0\\)\n\\item Anticommutivity: \\([A, B]=-[B,A]\\)\n\\end{itemize}\n\nOne option for the Lie bracket is the ring commutor. So that:\n\n\\([A,B]=AB-BA\\)\n\n", "meta": {"hexsha": "02d9775cc4282513b44700c78412362b77eae877", "size": 554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/representation/04-02-lieBracket.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/representation/04-02-lieBracket.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/representation/04-02-lieBracket.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.16, "max_line_length": 94, "alphanum_fraction": 0.6732851986, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6462844859393152}}
{"text": "\\chapter{Wrapping Up}\n\n\\section{Programs and Proofs}\n\n\\begin{itemize}\n    \\item Law of Excluded Middle $\\forall{Q} Q\\vee\\neg Q$\n    \\item $Programs \\equiv Proofs$\n\\end{itemize}\n\nNot all proofs have a corresponding program.\n\nLet $isProgram(P)$ and $halts(P)$ be two predicates.\n\\[ \\varphi \\triangleq \\forall{P} isProgram(P) \\to halts(P) \\vee \\neg halts(P) \\]\n$\\varphi$ is valid. i.e. $\\vDash\\varphi$. By completeness of first order logic, $\\vdash\\varphi$. So there must exist a proof (deduction) $\\Phi=\\{\\varphi_1,\\dots,\\varphi_n\\}$ s.t. $\\varphi_n = \\varphi$. If every proof had a corresponding program, then this program would be able to solve the Halting problem.\n\nNot all programs have a corresponding proof.\n\n\\begin{lstlisting}[language=c]\n    while(1) {}\n\\end{lstlisting}\n\nThis program has a dead loop, which implies ``false''. If this program had a proof, then we would be able to prove ``false''.\n", "meta": {"hexsha": "4f05da93a01df4bdb104fe442cf694493a93df63", "size": 904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic/wrapup.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/wrapup.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/wrapup.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": 39.3043478261, "max_line_length": 307, "alphanum_fraction": 0.7134955752, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.6992544273261176, "lm_q1q2_score": 0.6462102576364417}}
{"text": "\\section{Rosenblatt's Perceptron (1957)}\r\n\r\n\\subsection{Motivation}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Motivation}\r\n\r\n  \\begin{itemize}\r\n    \\item We want to compute a linear decision boundary. \\\\[.5cm]\r\n    \\item We assume that classes are linearly separable. \\\\[.5cm]\r\n    \\item Computation of a linear separating hyperplane that\\\\\r\n      minimizes the distance of misclassified feature vectors \\\\\r\n      to the decision boundary.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Objective Function}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Objective Function}\r\n\r\n  Assume the following:\r\n\r\n  \\begin{itemize}\r\n    \\item Class numbers are $y=\\pm 1$.\r\n    \\item The decision boundary is a linear function:\r\n      \\begin{displaymath}\r\n        y^* = \\mbox{sgn}(\\vec \\alpha^T\\vec x + \\alpha_0).\r\n      \\end{displaymath}\r\n      \\pause\r\n    \\item Parameters $\\alpha_0$ and $\\vec \\alpha$ are chosen according to the optimization problem \\\\[.2cm]\r\n\r\n      \\begin{center}\r\n        \\tikz[baseline]{ \r\n          \\node[fill=bl1!100,anchor=base,rounded corners=3pt] (d1) {\r\n            \\color{bl3} \r\n            $\\displaystyle \\mbox{minimize} \\quad \\bigg\\{ D(\\alpha_0, \\vec \\alpha)= -\\sum_{\\vec x_i\\in {\\cal M}} y_i \\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0) \\bigg\\}$\r\n          };  \r\n        }\\\\[.2cm]\r\n      \\end{center}\r\n\r\n      where $\\cal M$ includes the misclassified feature vectors.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Objective Function \\cont}\r\n\r\n  \\begin{itemize}\r\n    \\item The elements of the sum in the objective function depend on \\\\\r\n      the set of misclassified feature vectors $\\cal M$. \\\\[.5cm] \\pause\r\n    \\item In each iteration step the cardinality of $\\cal M$ might change. \\\\[.5cm] \\pause\r\n    \\item The cardinality of $\\cal M$ is a discrete variable. \\\\[.5cm] \\pause\r\n    \\item \\structure{Competing variables:} continuous parameters of linear decision boundary and the discrete cardinality of $\\cal M$.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Minimization of Objective Function}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Minimization of Objective Function}\r\n\r\n  Remember the objective function $D(\\alpha_0, \\vec \\alpha)$:\r\n  \\begin{displaymath}\r\n    \\mbox{minimize} \\quad \\quad D(\\alpha_0, \\vec \\alpha)= -\\sum_{\\vec x_i\\in {\\cal M}} y_i \\cdot (\\vec \\alpha^T\\vec x_i + \\alpha_0)\r\n  \\end{displaymath}\r\n  \\pause\r\n \r\n  The gradient of the objective function is: \\pause\r\n  \\begin{eqnarray*}\r\n    \\frac{\\partial}{\\partial \\alpha_0} \\ D(\\alpha_0, \\vec \\alpha)&=&  -\\sum_{\\vec x_i\\in {\\cal M}} y_i \\\\ \\pause\r\n    \\frac{\\partial}{\\partial \\vec\\alpha} \\ D(\\alpha_0, \\vec \\alpha)&=& -\\sum_{\\vec x_i\\in {\\cal M}} y_i\\cdot  \\vec x_i \\\\\r\n  \\end{eqnarray*}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Minimization of Objective Function \\cont}\r\n\r\n  We want to take an update step right after having visited each misclassified observation.\r\n  The update rule in the $(k+1)$-st iteration step is:\r\n\r\n  \\begin{displaymath}\r\n    { \\alpha_0^{(k+1)} \\choose \\vec \\alpha^{(k+1)}} = \\pause  { \\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}} + \\lambda {y_i \\choose y_i\\cdot \\vec x_i}\r\n  \\end{displaymath} \r\n\r\n  Here $\\lambda$ is the learning rate which can be set to $1$ without loss of generality.\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Minimization of Objective Function \\cont}\r\n\r\n  \\begin{algorithmic}\r\n    \\STATE  \\structure{Input:} training data:  $S = \\{ (\\vec x_1, y_1), (\\vec x_2, y_2), (\\vec x_3, y_3), \\dots, (\\vec x_m, y_m) \\}$ \\pause\r\n    \\STATE initialize  $k=0$, $\\alpha^{(0)}_0=0$ and $\\vec \\alpha^{(0)}=  \\vec 0$\r\n    \\REPEAT \r\n      \\STATE select pair $(\\vec x_i, y_i)$ from training set. \\pause\r\n      \\IF {$y_i\\cdot (\\vec x_i^T \\vec\\alpha^{(k)} + \\alpha_0^{(k)})\\leq 0$} \r\n        \\STATE \\\r\n        \\STATE $\\displaystyle{ \\alpha_0^{(k+1)} \\choose \\vec \\alpha^{(k+1)}} =  { \\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}} +  {y_i \\choose y_i\\cdot \\vec x_i}$\r\n        \\STATE \\\r\n        \\STATE $k\\leftarrow k+1$\r\n      \\ENDIF\r\n      \\pause\r\n    \\UNTIL{$y_i\\cdot (\\vec x_i^T \\vec\\alpha^{(k)} + \\alpha_0^{(k)})> 0 \\quad \\mbox {for all} \\quad i$}\r\n    \\STATE \\structure{Output:} $\\alpha_0^{(k)}$ and $\\vec \\alpha^{(k)}$\r\n  \\end{algorithmic}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Remarks on Perceptron Learning}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Remarks on Perceptron Learning}\r\n\r\n  \\begin{itemize}\r\n    \\item The update rule is extremely simple. \\\\[.3cm]\r\n    \\item Nothing happens if we classify all $\\vec x_i$ correctly using the given linear decision boundary. \\\\[.3cm]\r\n    \\item The parameter $\\vec \\alpha$ of the decision boundary is a linear combination of feature vectors. \\\\[.3cm] \\pause\r\n    \\item The decision boundary thus is:\r\n    \\begin{displaymath}\r\n       F(\\vec x) = \\left (\\sum_{i\\in \\cal E} y_i\\cdot \\vec x_i \\right)^T \\vec x + \\sum_{i\\in \\cal E} y_i \\quad \r\n                 = \\quad \\sum_{i\\in \\cal E} y_i\\cdot \\langle \\vec x_i, \\vec x\\rangle + \\sum_{i\\in \\cal E} y_i \r\n    \\end{displaymath}\r\n    where $\\cal E$ is the list of indices that required an update \\\\\r\n\t(indices may appear more than once). \r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Remarks on Perceptron Learning \\cont}\r\n\r\n  \\begin{itemize}\r\n    \\item The final linear decision boundary depends on the initialization, \\\\\r\n      i.\\,e.\\ $\\alpha_0^{(0)}$ and $\\vec \\alpha^{(0)}$. \\\\[.5cm]\r\n    \\item The number of iterations can be rather large. \\\\[.5cm]\r\n    \\item If data are not linearly separable, the proposed learning algorithm will not converge. The algorithm will end up in hard to detect cycles.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Convergence of Learning Algorithm}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm}\r\n\r\n  \\begin{theorem}[Convergence Theorem of Rosenblatt and Novikoff]\r\n    Assume that for all $i=1,2, \\dots, m$\r\n    \\begin{displaymath}\r\n      y_i(\\vec x_i^T\\vec \\alpha^* +\\alpha^*_0)\\geq \\rho\r\n    \\end{displaymath}\r\n    where $\\rho>0$ and $\\|\\vec \\alpha^*\\|=1$.\r\n    Let $M= \\max_i \\|\\vec x_i\\|_2$. \\\\[.3cm]\r\n    \r\n    The perceptron learning algorithm converges to a linear decision boundary after $k$ iterations, where $k$ is bounded by\r\n    \\begin{displaymath}\r\n      k \\leq \\frac{(\\alpha_0^{*2}+1)(1+M^2)}{\\rho^2}.\r\n    \\end{displaymath}\r\n  \\end{theorem}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm \\cont}\r\n\r\n  Let us look at the estimated parameters after $k$ iterations and \\\r\n  how the parameters change with iterations:\r\n\r\n  \\begin{eqnarray*}\r\n    {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}^T{\\alpha_0^* \\choose \\vec \\alpha^*} \r\n      &=& \\pause \\left( { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} +  {y_i \\choose y_i\\cdot \\vec x_i}\\right)^T {\\alpha_0^* \\choose \\vec \\alpha^*}\\\\ \\pause\r\n      &=& { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} ^T{\\alpha_0^* \\choose \\vec \\alpha^*} +  {y_i \\choose y_i\\cdot \\vec x_i}^T {\\alpha_0^* \\choose \\vec \\alpha^*} \\\\ \\pause\r\n      &\\geq& { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} ^T{\\alpha_0^* \\choose \\vec \\alpha^*} + \\rho \\\\ \\pause\r\n      &\\geq& k\\rho\r\n  \\end{eqnarray*}\r\n\r\n  \\structure{Conclusion:} The more iterations (i.\\,e.\\ misclassifications) we have, \\\\\r\n  the more the vectors are aligned.\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm \\cont}\r\n\r\n  Now we apply Cauchy-Schwartz inequality for inner products:\r\n\r\n  \\begin{eqnarray*}\r\n    {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}^T{\\alpha_0^* \\choose \\vec \\alpha^*} \r\n      &\\leq& \\left\\|  {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2\\cdot  \\left\\| {\\alpha_0^* \\choose \\vec \\alpha^*}\\right\\|_2 \\\\[.5cm] \\pause\r\n      &=&\\left \\|  {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2\\cdot  \\sqrt{\\alpha_0^{*2}+1}\r\n  \\end{eqnarray*}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm \\cont}\r\n\r\n  The norm of the vector estimated in the $k$-th iteration step is:\r\n\r\n  \\begin{eqnarray*}\r\n    & &  \\left \\|  {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2^2 =\r\n   \\left\\| { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} +  {y_i \\choose y_i\\cdot \\vec x_i}\\right\\|_2^2 \\\\[.5cm] \\pause\r\n   & & \\vspace*{-2cm} = { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} ^T{ \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} \r\n           + 2 { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}}^T{y_i \\choose y_i\\cdot \\vec x_i}\r\n          + {y_i \\choose y_i\\cdot \\vec x_i}^T{y_i \\choose y_i\\cdot \\vec x_i}\r\n  \\end{eqnarray*}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm \\cont}\r\n\r\n  We only go into iteration step $(k+1)$ if we did a mistake in iteration $k$. \\\\\r\n  A misclassification implies:\r\n  \r\n  \\begin{displaymath}\r\n    { \\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}^T{y_i \\choose y_i\\cdot \\vec x_i} \r\n    = y_i\\cdot (\\vec x_i^T \\vec\\alpha^{(k)} + \\alpha_0^{(k)})\\quad < \\quad 0\r\n  \\end{displaymath}\r\n  \\pause \r\n\r\n  And thus we get\r\n  \r\n  \\begin{displaymath}\r\n    \\left \\|  {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2^2 \r\n    \\leq { \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} ^T{ \\alpha_0^{(k-1)} \\choose \\vec \\alpha^{(k-1)}} \r\n           + {y_i \\choose y_i\\cdot \\vec x_i}^T{y_i \\choose y_i\\cdot \\vec x_i}\r\n    \\leq k(1+M^2)\r\n  \\end{displaymath}\r\n\\end{frame}\r\n\r\n\r\n\\begin{frame}\r\n  \\frametitle{Convergence of Learning Algorithm \\cont}\r\n\r\n  Wrap-up:\r\n  \r\n  \\begin{displaymath}\r\n    k\\rho \r\n    \\leq {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}^T{\\alpha_0^* \\choose \\vec \\alpha^*} \r\n    \\leq \\left \\|  {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2\\cdot  \\sqrt{\\alpha_0^{*2}+1}\r\n  \\end{displaymath}\r\n  \\pause\r\n\r\n  Using Cauchy-Schwartz:\r\n  \r\n  \\begin{displaymath}\r\n    k\\rho\\quad\r\n    \\leq \\quad \\left \\| {\\alpha_0^{(k)} \\choose \\vec \\alpha^{(k)}}\\right\\|_2\\cdot  \\sqrt{\\alpha_0^{*2}+1}\\quad \\leq \\quad  \\sqrt{k(1+M^2)(\\alpha_0^{*2}+1)}\r\n  \\end{displaymath}\r\n  \\pause\r\n\r\n  shows:\r\n  \r\n  \\begin{displaymath}\r\n    k \\quad \\leq\\quad \\frac{(\\alpha_0^{*2}+1)(1+M^2)}{\\rho^2}\r\n  \\end{displaymath}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Lessons Learned}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Lessons Learned}\r\n\r\n  \\begin{itemize}\r\n    \\item Objective function changes in each iteration step. \\\\[.5cm]\r\n    \\item Optimization problem is discrete. \\\\[.5cm]\r\n    \\item Very simple learning rule. \\\\[.5cm]\r\n    \\item \\vorsicht \\structure{Very important:} Number of iterations does \\structure{not} depend on the \\\\\r\n      dimension of the feature vectors.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\\input{nextTime.tex}\r\n\r\n\\subsection{Further Readings}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Further Readings}\r\n\r\n  \\begin{itemize}\r\n    \\item Brian D. Ripley: \\\\\r\n      \\structure{Pattern Recognition and Neural Networks}, \\\\\r\n      Cambridge University Press, Cambridge, 1996.\\\\[.3cm]\r\n    \\item T. Hastie, R. Tibshirani, and J. Friedman: \\\\\r\n      \\structure{The Elements of Statistical Learning --}\\\\\r\n      \\structure{ Data Mining, Inference, and Prediction},\\\\\r\n      2nd edition, Springer, New York, 2009.\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n\\subsection{Comprehensive Questions}\r\n\r\n\\begin{frame}\r\n  \\frametitle{Comprehensive Questions}\r\n\r\n  \\begin{itemize}\r\n    \\item What is Rosenblatt's perceptron? \\\\[1cm]\r\n    \\item What is the objective function for Rosenblatt's perceptron? \\\\[1cm]\r\n    \\item Why is the optimization of the objective function nonlinear? \\\\[1cm]\r\n    \\item When and how does Rosenblatt's perceptron algorithm converge?\r\n  \\end{itemize}\r\n\\end{frame}\r\n", "meta": {"hexsha": "db669f61a7b2d315693a6fe3932c7540935b33ee", "size": 11344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "09_perceptron.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": "09_perceptron.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": "09_perceptron.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": 36.4758842444, "max_line_length": 177, "alphanum_fraction": 0.619887165, "num_tokens": 3821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6461035760618525}}
{"text": "\n\\subsection{Mean value theorem for integration}\n\nTake function \\(f(x)\\). From the extreme value theorem we know that:\n\n\\(\\exists m \\in \\mathbb{R} \\exists M\\in \\mathbb{R}\\forall x\\in [a,b](m<f(x)<M)\\)\n\n\\subsection{Fundamental theorem of calculus}\n\nFrom continuation we know that:\n\n\\(\\int_a^{x_1}f(x)dx+\\int_{x_1}^{x_1+\\delta x}f(x)dx=\\int_a^{x_1+\\delta x}f(x)dx\\)\n\n\\(\\int_x^{x_1+\\delta x}f(x)dx=\\int_a^{x_1+\\delta }f(x)dx-\\int_a^{x_1 }f(x)dx\\)\n\nIndefinite integrals\n\n", "meta": {"hexsha": "63ee984441dc042450d7939631d09caa58867860", "size": 467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/integration/06-01-FundamentalTheoremCalculus.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/06-01-FundamentalTheoremCalculus.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/06-01-FundamentalTheoremCalculus.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.9444444444, "max_line_length": 82, "alphanum_fraction": 0.6788008565, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121366457407, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6461035721769385}}
{"text": "\\chapter{Abstract Algebra }\n\nAbstract algebra \\cite{abstractmaths} also referred to as modern algebra is the study of algebraic structures. An algebric structure serves as an explinatory basis of functional operations on an underlying set. A set here also is an abstract idea of a collection of things that share certain common features and should not only be confined with sets dealt in classical set theory. Over the time on the basis of types of operations and \\textit{logical freedom} to do so on various sets have led to acceptance of various algebric structures defined below. The study of abstract algebra is used primarily in areas of topology of \\textbf{n} dimensions. For anyone this is insane for physical boundations arise when we try to visualize things out. Thus we need to classify abstractions in one of the algebric structures and then deal with it. \n\n\\section{Group Theory}\n\nThis is a part of abstract algebra where we deal with \\textbf{Group} mathematical structures. In mathematics, a \\textbf{Group} is an abstract algebraic structure that consists of a set of elements and various operations which when performed on any \\textit{two} elements of the set results in a \\textit{third} element from same set. It satisfies four conditions called the \"group axioms\" or \"group properties\", namely closure or closed operations i.e. that maps from set to itself , associativity, identity and invertibility. One of the most common examples of a group structure is the set of integers with the addition operation. This algebric structure is fundamental basis of other more complex algebric structures. It is studied in followings ways.\\\\\n\nA group \\textit{G} with the property with a given operation \"o\" such that \\[ \\textit{ a o b = b o a }  | \\hfill \\forall a,b \\in \\{ G \\} \\] is called abelian or commutative. Groups not satisfying this property are said to be nonabelian or non-commutative.\n\n\\subsection{Cyclic Groups}\n\nA \\textbf{Cyclic Group} is a group that can be generated by a single element often called as group generator). Cyclic groups are always Abelian. A cyclic group of finite group order n is denoted $G_n$ . The genralized generation rule can be specified as : \\\\\n\n\\[ X^n  = I ( X \\in G ) \\]\n\nIn the simple sense, it means identity element can be generated by any single element by repeated application of group operations. And since the identity element can be realized this way, all the elements of group can be realized too.\\\\\n\n\\subsection{Permutation groups}\n\nA \\textbf{Permutation Group} is a group G whose elements are permutations of a given set M and whose group operation is the composition of permutations in G (which are thought of as bijective functions from the set M to itself). The group of all permutations of a set M is the symmetric group of M, often written as Sym(M).[1] The term permutation group thus means a subgroup of the symmetric group. If M = {1,2,...,n} then, Sym(M), the symmetric group on n letters is usually denoted by Sn.\n\n\\subsection{Group Actions}\n\nan action of a group is a formal way of interpreting the manner in which the elements of the group correspond to transformations of some space in a way that preserves the structure of that space.\n\n. For other groups, an interpretation of the group in terms of an action may have to be specified, either because the group does not act canonically on any space or because the canonical action is not the action of interest. For example, we can specify an action of the two-element cyclic group \\[ \\displaystyle \\mathrm {C} _{2}=\\{0,1\\}\\] on the finite set \\[\\displaystyle \\{a,b,c\\}\\] by specifying that 0 (the identity element) sends \\[ \\displaystyle a\\mapsto a,b\\mapsto b,c\\mapsto c\\], and that 1 sends \\[ \\displaystyle a\\mapsto b,b\\mapsto a,c\\mapsto c \\]. This action is not canonical.\n\n\n\\section{Field Theory}\n\nIn mathematics, a field is a set on which addition, subtraction, multiplication, and division are defined, and behave as the corresponding operations on rational and real numbers do. A field is thus a fundamental algebraic structure, which is widely used in algebra, number theory and many other areas of mathematics.\\\\\nThe best known fields are the field of rational numbers, the field of real numbers and the field of complex numbers. Many other fields, such as fields of rational functions, algebraic function fields, algebraic number fields, and p-adic fields are commonly used and studied in mathematics, particularly in number theory and algebraic geometry. Most cryptographic protocols rely on finite fields, i.e., fields with finitely many elements.\\\\\nThe relation of two fields is expressed by the notion of a field extension. Galois theory, initiated by Évariste Galois in the 1830s, is devoted to understanding the symmetries of field extensions. Among other results, this theory shows that angle trisection and squaring the circle can not be done with a compass and straightedge. Moreover, it shows that quintic equations are algebraically unsolvable.\\\\\nFields serve as foundational notions in several mathematical domains. This includes different branches of analysis, which are based on fields with additional structure. Basic theorems in analysis hinge on the structural properties of the field of real numbers. Most importantly for algebraic purposes, any field may be used as the scalars for a vector space, which is the standard general context for linear algebra. Number fields, the siblings of the field of rational numbers, are studied in depth in number theory. Function fields can help describe properties of geometric objects.\\\\\n\n\\section{Rings Theory}\n\nIn mathematics, a ring is one of the fundamental algebraic structures used in abstract algebra. It consists of a set equipped with two binary operations that generalize the arithmetic operations of addition and multiplication. Through this generalization, theorems from arithmetic are extended to non-numerical objects such as polynomials, series, matrices and functions.\\\\\n\nWhether a ring is commutative or not (i.e., whether the order in which two elements are multiplied changes the result or not) has profound implications on its behavior as an abstract object. As a result, commutative ring theory, commonly known as commutative algebra, is a key topic in ring theory. Its development has been greatly influenced by problems and ideas occurring naturally in algebraic number theory and algebraic geometry. Examples of commutative rings include the set of integers equipped with the addition and multiplication operations, the set of polynomials equipped with their addition and multiplication, the coordinate ring of an affine algebraic variety, and the ring of integers of a number field. Examples of noncommutative rings include the ring of n × n real square matrices with n ≥ 2, group rings in representation theory, operator algebras in functional analysis, rings of differential operators in the theory of differential operators, and the cohomology ringof a topological space in topology.\\\\\n\n\\subsection{Polynomial Rings}\n\nIn mathematics, especially in the field of abstract algebra, a polynomial ring or polynomial algebra is a ring (which is also a commutative algebra) formed from the set of polynomials in one or more indeterminates (traditionally also called variables) with coefficients in another ring, often a field. Polynomial rings have influenced much of mathematics, from the Hilbert basis theorem, to the construction of splitting fields, and to the understanding of a linear operator. Many important conjectures involving polynomial rings, such as Serre's problem, have influenced the study of other rings, and have influenced even the definition of other rings, such as group rings and rings of formal power series.\\\\\n\nA closely related notion is that of the ring of polynomial functions on a vector space. \\\\\n\n\\section{Iso-morphisms}\n\nIn abstract algebra, a group isomorphism is a function between two groups that sets up a one-to-one correspondence between the elements of the groups in a way that respects the given group operations. If there exists an isomorphism between two groups, then the groups are called isomorphic. From the standpoint of group theory, isomorphic groups have the same properties and need not be distinguished.\n\n\n\\section{Homo-morphisms}\n\nIn algebra, a homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces). Homomorphisms of vector spaces are also called linear maps, and their study is the object of linear algebra.\\\\\n\n% \\section{Matrix Groups}\n\n% In mathematics, a matrix group is a group G consisting of invertible matrices over a specified field K, with the operation of matrix multiplication, and a linear group is an abstract group that is isomorphic to a matrix group over a field K, in other words, admitting a faithful, finite-dimensional representation over K.\\\\\n\n% Any finite group is linear, because it can be realized by permutation matrices using Cayley's theorem. Among infinite groups, linear groups form an interesting and tractable class. Examples of groups that are not linear include groups which are \"too big\" (for example, the group of permutations of an infinite set), or which exhibit some pathological behaviour (for example finitely generated infinite torsion groups). \\\\\n\n% \\section{Category Theory}\n\n% Algebraic structures, with their associated homomorphisms, form mathematical categories. Category theory is a formalism that allows a unified way for expressing properties and constructions that are similar for various structures. \\\\\n\n% The language of category theory is used to express and study relationships between different classes of algebraic and non-algebraic objects. This is because it is sometimes possible to find strong connections between some classes of objects, sometimes of different kinds. For example, Galois theory establishes a connection between certain fields and groups: two algebraic structures of different kinds.\\\\", "meta": {"hexsha": "6e66182e67f53cc28835a4039b2f29cfcbb244e3", "size": 10019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/abstract-algebra.tex", "max_stars_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_stars_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_stars_repo_licenses": ["MIT"], "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/abstract-algebra.tex", "max_issues_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_issues_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_issues_repo_licenses": ["MIT"], "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/abstract-algebra.tex", "max_forks_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_forks_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 147.3382352941, "max_line_length": 1025, "alphanum_fraction": 0.8007785208, "num_tokens": 2113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6460948557093007}}
{"text": "\\section{Free Body Diagrams}\n\nFree body diagrams are a method of communicating the application and direction of forces through an object. The objective is to simplify the geometry of an object to a point where one can easily see how the forces within the object interact with one another. It is also common practice to take planes in which the forces are acting to reduce the complexity of the interaction of forces further.\n\n\\cref{fig-fbd} shows an example of a loaded beam whose forces have been split in both the horizontal and vertical directions, and are reacted by two bearings. The $+$ arrow indicates our sign convention on the drawing and relative positions of the forces are also indicated.\n\n\\begin{figure*}[ht!]\n  \\center\n  \\begin{tabular}{c c}\n    \\subfloat[Vertical]{\n    \\begin{tikzpicture}[scale=6.0]\n      \\draw[very thick] (0,0) -- (1,0);\n      \n      \\draw[<-, thick] (0.2,0) -- (0.2,-0.1) node[below]{$R_{1v}$};\n      \\draw[<-, thick] (0.8,0) -- (0.8,-0.1) node[below]{$R_{2v}$};\n      \n      \\draw[<-, thick] (0.3,0) -- (0.3,0.1) node[above]{$F_{1}$};\n      \\draw[<-, thick] (0.7,0) -- (0.7,0.1) node[above]{$F_{2}$};\n      \n      \\draw[->] (0,-0.25) -- (0.2,-0.25) node[right]{$x_1$};\n      \\draw[->] (0,-0.3) -- (0.3,-0.3) node[right]{$x_2$};\n      \\draw[->] (0,-0.35) -- (0.7,-0.35) node[right]{$x_3$};\n      \\draw[->] (0,-0.4) -- (0.8,-0.4) node[right]{$x_4$};\n      \\draw[] (0,-0.25) -- (0,-0.4);\n      \n      \\draw[|->] (0,0.1) -- (0,0.2) node[above]{$+$};\n    \\end{tikzpicture}\n  } &\n  \\subfloat[Horizontal]{\n    \\begin{tikzpicture}[scale=6.0]\n      \\draw[very thick] (0,0) -- (1,0);\n      \n      \\draw[<-, thick] (0.2,0) -- (0.2,-0.1) node[below]{$R_{1h}$};\n      \\draw[<-, thick] (0.8,0) -- (0.8,-0.1) node[below]{$R_{2h}$};\n      \n      \\draw[<-, thick] (0.1,0) -- (0.1,0.1) node[above]{$F_{3}$};\n      \n      \\draw[->] (0,-0.25) -- (0.1,-0.25) node[right]{$x_0$};\n      \\draw[->] (0,-0.3) -- (0.2,-0.3) node[right]{$x_1$};\n      \\draw[->] (0,-0.35) -- (0.8,-0.35) node[right]{$x_4$};\n      \\draw[] (0,-0.25) -- (0,-0.35);\n      \n      \\draw[|->] (0,0.1) -- (0,0.2) node[above]{$+$};\n    \\end{tikzpicture}\n  } \\\\\n  \\end{tabular}\n  \\vspace{1em}\n  \\caption{Free-body diagrams for a loaded beam}\\label{fig-fbd}\n\\end{figure*}\n\nUsing these diagrams and information on the forces and location of the forces, one can ascertain the reactions on the bearings.\n\n\\begin{multicols}{4}\n\\begin{description}\n    \\item[$F_1$] = \\SI{15}{\\kilo\\newton}\n    \\item[$F_2$] = \\SI{25}{\\kilo\\newton}\n    \\item[$F_3$] = \\SI{10}{\\kilo\\newton}\n    \\item[$R_{1v}$] = ?\n    \\item[$R_{1h}$] = ?\n    \\item[$R_{2v}$] = ?\n    \\item[$R_{2h}$] = ?\n    \\item[$x_0$] = \\SI{0}{\\metre}\n    \\item[$x_1$] = \\SI{0.2}{\\metre}\n    \\item[$x_2$] = \\SI{0.3}{\\metre}\n    \\item[$x_3$] = \\SI{0.55}{\\metre}\n    \\item[$x_4$] = \\SI{0.6}{\\metre}\n\\end{description}\n\\end{multicols}\n\nTo\\marginnote{Resolving the Vertical Forces}  resolve the force vertically, we take moments about one of the bearings with the assumption that it is a static and stable system. Thus, no moment should exist about the bearing otherwise the shaft would be spinning!\n\nHere, we have taken moments about $R_{1v}$ and from this, we can calculate the reaction force $R_{2v}$. \n\\begin{align}\n  \\circlearrowright R_{1v} &= 0 = \\SI{0.1}{\\metre}(\\SI{15}{\\kilo\\newton}) + \\SI{0.35}{\\metre}(\\SI{25}{\\kilo\\newton}) - 0.4(R_{2v}) \\\\\n  R_{2v} &= \\frac{\\SI{1025}{\\kilo\\newton\\metre}}{\\SI{0.4}{\\metre}} = \\SI{25.625}{\\kilo\\newton}\n\\end{align}\n\nWith $R_{2v}$ calculated, we can look at the balancing the forces in the vertical plane to ascertain $R_{1v}$.\n\\begin{align}\n  R_{1v}+R_{v2}&=F_1+F_2\\\\\n  R_{1v}+R_{v2}&=\\SI{15}{\\kilo\\newton}+\\SI{25}{\\kilo\\newton}\\\\\n  R_{1v} &= \\SI{40}{\\kilo\\newton}-\\SI{25.625}{\\kilo\\newton} = \\SI{14.375}{\\kilo\\newton}\n\\end{align}\n\nThe\\marginnote{Resolving the Horizontal Forces} same process used in the horizontal direction. Taking moments about $R_{1h}$, we can find $R_{2h}$.\n\\begin{align}\n  \\circlearrowright R_{1h} &= 0 = \\SI{0.2}{\\metre}(\\SI{10}{\\kilo\\newton}) + 0.4\\si{\\metre}(R_2) \\\\\n  \\therefore R_{2h} &=  \\frac{0.2\\si{\\metre}}{-0.4\\si{\\metre}} = -5\\si{\\kilo\\newton}\n\\end{align}\n\nAgain, equating the forces in the horizontal plane gives us $R_{1h}$.\n\\begin{align}\n  R_{1h}+R_{2h}&=\\SI{10}{\\kilo\\newton} \\\\\n  R_{1h} &= \\SI{10}{\\kilo\\newton} + \\SI{5}{\\kilo\\newton} = \\SI{15}{\\kilo\\newton}\n\\end{align}\n\n", "meta": {"hexsha": "9c61cc8ec7b51c2a8fe661341e44ad82fab0b24d", "size": 4376, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02_free_body_diagrams/section.tex", "max_stars_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_stars_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_stars_repo_licenses": ["MIT"], "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_free_body_diagrams/section.tex", "max_issues_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_issues_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_issues_repo_licenses": ["MIT"], "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_free_body_diagrams/section.tex", "max_forks_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_forks_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_forks_repo_licenses": ["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.1134020619, "max_line_length": 394, "alphanum_fraction": 0.5939213894, "num_tokens": 1758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.6460948532100265}}
{"text": "%\\section{Computational Methods and Software}\n\\label{sec:software}\n\nThe previous chapter described a set of models \nfor the system of interest. \n%These models are too \n%complicated to solve exactly, and must instead be \n%instantiated with software to produce a numerical \n%result. \nThis chapter details the numerical formulation\nand solution of these models. It begins with a \ndiscussion of the numerical discretization of the equations \nof interest. The mesh discretization is then described. \nNext, the scientific software in which these numerical \nmodels are used is discussed. Finally, the tool\nchain and supercomputer systems are briefly introduced. \n\n\\section{Discretization Scheme}\n\\label{sec:discretization}\nThe finite element method (FEM) is used to numerically solve the \nNavier-Stokes equations. The starting point for the FEM is\nto cast the equations in Section~\\ref{sub_sec:ns_en} into a weak\nform. Use of the weak form reduces the continuity requirements on the\nbasis functions, thereby allowing the use of functions that are\neasy to construct and implement, such as piece-wise polynomials. \nManipulating these partial differential equations into a\nvariational formulation is accomplished by multiplying the equations by\nappropriate test functions and integrating over the domain,\n$\\Omega$. The resulting weak problem is: find $({\\bf u},p,T) \\in\nH^1(\\Omega)^3 \\times L_2(\\Omega) \\times H^1(\\Omega)$ such that \n\n%\n% http://www.numerik.uni-hd.de/Oberwolfach-Seminar/CFD-Course.pdf\n%\n\\begin{align}\n  (\\frac{\\partial{\\bf u}}{\\partial t},{\\bf v}) + ({\\bf u} \\cdot \\nabla{\\bf\n u},{\\bf v}) + (\\nu \\,\\nabla{\\bf u}, \\nabla{\\bf v})   \n  -(p,\\nabla \\cdot{\\bf u}) &= ({\\bf g} \\, T'/T_0,v),\n \\label{eqn:ns_weak} \\\\\n (\\nabla \\cdot{\\bf u},q) &= 0,\n \\label{eqn:cont_weak} \\\\\n (\\frac{\\partial T}{\\partial t}, w) + ({\\bf u} \\cdot \\nabla T,\n w) + (k \\, \\nabla T, \\nabla  w) &= 0,\\label{eqn:en_weak}\n\\end{align}\n\n%\\todo{boundary terms}\n\n$\\forall ({\\bf v},q,w) \\in H^1(\\Omega)^3 \\times L_2(\\Omega) \\times\nH^1(\\Omega)$, where $(\\cdot,\\cdot)$ denotes the $L_2$ inner product  \n$({\\bf u},{\\bf v}) = \\int_\\Omega {\\bf u} \\cdot {\\bf v} \\, dx$ and\n$H^1(\\Omega)$ is the Sobolov space with one square integrable derivative\non the domain \n$\\Omega$\\cite{oden2012introduction}. As noted previously, boldface letters\ndenote vector quantities (such as ${\\bf u} = \\left \\{ u,v,w \\right \\}$). \nSome of the simulations presented here were conducted under\nsteady conditions, for which the $\\frac{\\partial}{\\partial t}$ terms\nvanish. An FEM scheme is obtained by posing the weak form in\nterms of finite-dimensional subspaces of the function spaces specified above\ndefined using piecewise-polynomial basis functions. This discretization\nhas the form, $ {\\bf v_h} \\in {\\bf v}$, where ${\\bf v_h}$ is \n%an approximation of ${\\bf v}$ \nformed through a linear combination of a finite number (N) of basis\nfunctions $\\phi_i$,  \n\\begin{equation}\n {\\bf v_h} = \\sum_{i=1}^N \\alpha_i \\phi_i,\n\\end{equation}\nwhere $\\alpha_i$ are coefficients\\cite{becker1981introduction}.\n%\n%are constants and the N basis functions, $\\left \\{\n%\\psi_1, \\psi_2, \\ldots, \\psi_N \\right \\}$, define an N-dimensional \n%subspace of $H^1$\\cite{becker1981introduction}. \n%\nAll of the simulations discussed in this work were \naccomplished using piecewise linear basis functions for both the\nvelocity and pressure. Typically, the use of equal order elements for\nvelocity and pressure is ruled out in the standard Galerkin FEM\nformulation because of the Babuska-Brezzi condition\\cite{bb-cond}. \nThis is overcome here by \n%However, the weak form equations shown above are stable with equal-order\n%elements for velocity and pressure due to \nthe introduction of a pressure stabilization\nterm\\cite{becker1981introduction}. The resulting system is still\nsusceptible to convective instabilities, and so streamline upwind/Petrov-Galerkin\n(SUPG) stabilization terms are used, as first described by\nHughes\\cite{Hughes198685,supg} and extended to natural convection as in\nBecker and Braack\\cite{Becker2002428}. These stabilization terms add a\nresidual dependent artificial dissipation that approaches zero as the\nsolution converges. This scheme is called consistent because the\nunderlying order of convergence of the numerical method is not\naffected\\cite{hughes2000finite}.    \n\nThe stabilization described above is accomplished by introducing an additional term,\n$\\langle L{\\bf c},S {\\bf \\phi} \\rangle_\\tau$, to the weak form defined in Equations\n\\ref{eqn:ns_weak}-\\ref{eqn:en_weak}. Here $L$ is the operator for the PDEs\nin \\ref{sub_sec:ns_en}, and S is a stabilization operator\nwhich is chosen to be the negative adjoint of the differential operator\nterms of $L$, and ${\\bf c}$ and ${\\bf \\phi}$ are state and test\nfunction vectors, i.e. $ {\\bf c}= ({\\bf u},p,T)$, and ${\\bf \\phi} = (\n{\\bf v},w,q )$. The angle brackets $\\langle \\cdot,\\cdot \\rangle$ signify\nintegration of the element interiors for each of the K elements, that is:\n\\begin{equation}\n \\langle {\\bf u},{\\bf v} \\rangle_\\tau = \\sum_K \\tau_K({\\bf u},{\\bf\n  v})_K.\\label{eq:tau}\n\\end{equation}\nThis results in three stabilization parameters, $\\tau_P, \\tau_v, \\tau_T$, \nwhich are selected as proposed by Becker and Braack\\footnote{\\normalsize\nDerivations of the weak form and stabilization terms are provided\nin Appendix~\\ref{app:stab}}. \n\nAfter spatial discretization, the system of ODEs are discretized in time\nusing the backward Euler method\\cite{moin2010fundamentals}. The time\ninterval $(0,T)$ is sliced into $N_t$ steps of uniform temporal length,\n$\\Delta t$, where $n = 0,\\dots,N_t$.  \nThis has the form, \n\\begin{equation}\n {\\bf y}_{n+1} = {\\bf y_n } + \\Delta t \\, f({\\bf y_{n+1}},t_{n+1}).\n\\end{equation}\nWhere ${\\bf y_{n+1}}$ denotes the solution vector at the time step $n+1$, for\ninstance. As $f$ is non-linear, a Newton-Raphson method is used to solve\nthe resulting implicit nonlinear problem. \n\n%While an iterative method is\n%significantly more computationally expensive per timestep than a similar\n%explicit method, the method was selected due to its unconditional\n%stability and ease of statistical sampling for a uniform timestep.  \n\n%\n% gave not completely described numerical methods\n% for instance, have not indicated the stabilization schemes\n% do not need complete equations, but should permit someone to access \n% the literature and construct precisely the numerical formulations used\n%\n\n\n\\section{Mesh Discretization}\n\n%\n% what about mesh...\n%\nThe domains described in Section~\\ref{sec:bc} are consistently\ndiscretized. This means that the domain extents, $\\{L_x,L_y,L_z\\}$, are\nscaled by system diameter (D) but the same number of grid points are\nused for every simulation. Thus, while the ratio of the domain length to\nsystem diameter remains fixed, the grid spacing $\\{\\Delta x,\\Delta\ny,\\Delta z\\}$ increases proportionally with domain length.  \n\nThe eddy diffusivities ($\\nu_{t},K_{t}$) in Equations~\\ref{eqn:visc_tot}\nand \\ref{eqn:therm_tot} are proportionally scaled with grid spacing to \nensure that the cell Reynolds number, \n\\begin{equation}\n \\text{Re}_\\text{cell} = \\frac{\\text{max}(\\Delta x,\\Delta y) \\, u}{\\nu_t},\n\\end{equation} \nis maintained for every simulation, to ensure stability. \nIn this way, larger domains have higher eddy viscosities which serve to \ndissipate effects of scales that are smaller than the grid spacing. \n\nThe mesh has a uniform spacing in the lateral directions, except for a\nsingle refinement in the region of the vanes. Typically, the grid is \nroughly one hundred points in the streamwise and spanwise directions\nbefore the refinement. The refinement halves the spacing (doubles the\nnumber of points) in all three coordinate directions, \\{x,y,z\\}, in this\nregion. The refinement is introduced from the ground to 1.5 times the\nheight of the vanes and cone.\n\n%\n% makes no sense\n%\n% describe a mapping what C's are used\n%\n% describe a grid refinement verification\n%\n%\n\nThe vertical mesh spacing is non-uniform to resolve the boundary\nlayer. This is accomplished by redistributing a mesh which is uniformly\nspaced over the interval $\\{0,L_z\\}$ in height, $\\hat z$, to a\nnon-uniform mesh, $z$, over the same interval.  \n%This non-uniform ``boundary-layer'' mesh is designed to resolve the small \n%scale variations near the wall. \n% what about chi?\nA mapping $z = \\chi(\\hat z)$ is defined by the following conditions.  \nThe minimum and maximum extents are preserved so that $ \\chi(0) = 0 $\nand $ \\chi(L_z) = L_z $.  \nThe map spacing between points is initially a specified minimum value, \n\\begin{equation}\n  h_{\\text{min}} = \\chi'(0) \\, \\hat h,\n\\end{equation}\nwhere $\\hat h = L_z/\\text{nz}$. The map is strictly increasing until the \npoint $\\hat z_b$, where the spacing reaches a constant, \n$h_{\\text{max}} = \\chi'(\\hat z_b) \\, \\hat h$. \nFrom this point onward, the mesh has a constant uniform spacing,  \n$  h_{\\text{max}} = \\chi'(L_z) \\, \\hat h$. \n%\nFinally, the mapping is assumed to hold an exponential functional form, \n$  \\chi(\\hat z) = A e^{\\beta \\hat z}$.\n\n%\n% mesh mapping here\n%\nThen, by specifying $h_{\\text{min}}$, $h_{\\text{max}}$ and \n$z_b$ (chosen thickness of the boundary layer mesh), \nthese conditions are sufficient to define a mapping, \n\\begin{equation}\n z = \\chi(\\hat z) = \n \\begin{cases} C_1 (\\hat z - L_z) + L_z & \\text{if } \\hat z \\geq \\hat z_b, \\\\\n   C_2 \\text{ exp}(C_3 \\, \\hat z - 1)      & \\text{if } \\hat z < \\hat z_b. \\\\\n \\end{cases}\n\\end{equation}\n%\nHere, $C_1-C_3$ are coefficients, and are defined as, %\\todo{show coefficients}. \n\\begin{align}\n  C_1 &= C_2 \\, C_3 e^{C_3 \\, \\hat z_b}, \\\\\n  C_2 &= \\frac{\\hat z_b}{h_r -1}, \\\\\n  C_3 &= \\frac{\\text{ln }(h_r) }{\\hat z_b},\n\\end{align}\nwhere $h_r$ is the ratio between the largest and smallest spacing, \n\\begin{equation}\n  h_r = \\frac{h_{\\text{max}}}{h_{\\text{min}}}, \n\\end{equation}\nand,\n\\begin{equation}\n  \\hat z_b = \\frac{L_z}{1 + \\frac{L_z - z_b}{C_2 \\, h_r \\text{ ln }(h_r)}}.\n\\end{equation}\n%% \\begin{equation}\n%%  z = \\begin{cases} C_1 (z-L_z)+L_z,& \\text{if } z \\geq z_\\delta\\\\\n%%       C_2 \\text{ exp}(C_3 z - 1),                 & \\text{otherwise}\n%%      \\end{cases}\n%% \\end{equation}\n\n%The mesh has an exponentially varying character, \n%$h_{\\text{min}}$, $h_{\\text{max}}$ and $z_b$ \n%are chosen to ensure ten or more\n%points in the boundary layer, isotropic spacing in cells outside of\n%it, and smooth blending between these two regimes. \n\nGrid refinement verification was performed, where the spacing was \ntested against a mesh with twice the grid points in the vertical\ndirection for a representative test case. The results were not sensitive\nto the choice of spacing. A horizontal slice though a\ntypical domain is shown in Figure~\\ref{fig:meshing}. The single \nrefinement in the region of the vanes is visible, along with the finer \nmeshed boundary layer region near the ground. \n\n  \\begin{figure}[!htb]\n    \\begin{center}\n     \\includegraphics[width = 10 cm]{figs/meshing}\n     \\caption{Horizontal slice through the domain, to show a\n     representative meshing. The single refinement region around the\n     vanes is visible, along with the finer boundary layer mesh near the\n     ground.}\n     \\label{fig:meshing}\n    \\end{center}\n  \\end{figure}\n\n\n% (01:40:40 PM) Roy Stogner: Not just looks boundary layer ish.\n% (01:40:43 PM) Roy Stogner: We had a sweet derivation for this.\n% (01:41:20 PM) Roy Stogner: Geometric progression of the nodes, solved the inverse problem for the redistribution, the whole works.\n%\n\n%% hmin = 0.001  \n%% hmax = 0.4  \n%% zb = 2.0\n%% hrat = ${/ ${mesh-options/hmax} ${mesh-options/hmin}}\n%% zmax = ${mesh-options/domain_x3_max}\n%% loghrat = ${= log ${mesh-options/hrat}}\n%% c2 = ${/ ${mesh-options/zb} ${- ${mesh-options/hrat} 1}} \n%% zetab = ${/ ${mesh-options/zmax} ${+ 1 ${/ ${- ${mesh-options/zmax} ${mesh-options/zb}} ${* ${mesh-options/c2} ${mesh-options/hrat} ${mesh-options/loghrat}}}}}\n%% c3 = ${/ ${mesh-options/loghrat} ${mesh-options/zetab}}\n%% mesh_nx3 = ${= ceil ${/ ${* ${mesh-options/zmax} ${mesh-options/c2} ${mesh-options/c3}} ${mesh-options/hmin}}}\n%% c1 = ${* ${mesh-options/c2} ${mesh-options/c3} ${= exp ${* ${mesh-options/c3} ${mesh-options/zetab}}}}\n%% redistribute = '{x}{y}{if(z>${mesh-options/zetab},${mesh-options/c1}*(z-${mesh-options/zmax})+${mesh-options/zmax},${mesh-options/c2}*(exp(${mesh-options/c3}*z)-1))}' \n\n%After operation, solutions are evaluated to ensure that \n%the qualitative character of the solution does not change.\n\n\\section{Software}\n\nThe numerical formulations described in Section~\\ref{sec:discretization}\nis implemented with the GRINS library\\cite{GRINSpaper} by Bauman\nand Stogner using the libMesh\\cite{libMeshPaper} FEM\ninfrastructure. Designed to support multiphysics FEM applications, \nGRINS is a flexible library that effectively addresses a wide range of \nscience and engineering problems.   \n \n%the reusability\n%and extensibility of mathematical modeling kernels, supporting\n%interfaces to existing solver and discretization libraries to enable\n%modern solution strategies, while, at the same time, retaining\n\n%GRINS provides a platform that enables powerful numerical algorithms\n%such as adjoint-based AMR, adaptive modeling, sensitivity analysis,\n%and, eventually, enabling uncertainty quantification. While few of these\n%capabilities are in use for the present work, they could be useful in\n%future investigations. \n\nGRINS stands for, ``General Reacting Incompressible Navier-Stokes'',\nwhich roughly encapsulates the physical regimes it was originally\ndesigned to simulate. GRINS is open-source, and available on\n\\hyperref[www.github.com/grinsfem/grins]{GitHub}. It is released \nunder LGPL2.1.  \n\n%The remainder of this Section is devoted to\n%discussing the underlying libraries used and the description of the\n%GRINS framework.  \n\nGRINS uses the fparser~\\cite{fparser}\nlibrary to support both parsing and compilation of mathematical\nfunctions into high performance kernels. This capability allows for\neasy specification of boundary conditions, initial conditions, or\nconstitutive equations from an input file. Some of these inputs are\ndetailed in Appendix~\\ref{sec:archiving}. \n\nGRINS/libMesh are built on the PETSc\\cite{petsc} solver package, which\nprovides the numerical linear algebra packages used for constructing and\nusing sparse matrices, finding the solution of linear systems,\nand for preconditioning.  \n\nWhile a variety of solver options have been tested in PETSc, all the\nresults shown in this document use GMRES with block Jacobi for\npreconditioning\\cite{Saad:2003} the linear solve. This uses the\ninverse of the diagonal block for that processor for preconditioning of\nthe entire linear system. In addition, a preconditioner is used for the\nsolution of the diagonal block. This is approximated with incomplete LU\nfactorization\\cite{chan1997approximate}. Here, the ``incomplete'' refers \nto the level of fill, with greater levels of fill approaching\nthe ``complete'' LU factorization. \n\nIn principle, alternative software libraries/frameworks such as\nFEniCS\\cite{AlnaesBlechta2015a} or OpenFOAM\\cite{jasak2007openfoam}\nwould be capable of simulating this problem. While these and\nother libraries have various strengths and weaknesses, the pre-eminent\nconcern is the parallel performance at the intended processor count, due\nto the rapid design iterations necessary for this research\ncampaign. Given these concerns, the GRINS library is a satisfactory tool. \n\n%% (11:41:54 AM) nick: ``-ksp_view -ksp_type gmres -pc_type bjacobi\n%% -sub_pc_type ilu -sub_pc_factor_levels 0'' \n%% (11:42:00 AM) Paul Bauman: OK\n%% (11:42:17 AM) Paul Bauman: -pc_type is the preconditioner for the entire linear system\n%% (11:42:25 AM) Paul Bauman: You're doing bjacobi = block Jacobi\n%% (11:42:28 AM) nick: right\n%% (11:42:36 AM) nick: and does anyone have a good reference I can learn\n%% this better? i feel as if I cant look this up, for some reason \n%% (11:42:39 AM) Paul Bauman: That is just using the inverse of the\n%% diagonal block for that processor \n%% (11:42:46 AM) Paul Bauman: Now\n%% (11:42:55 AM) Paul Bauman: that is a linear solve\n%% (11:43:17 AM) Paul Bauman: So you can use all the linear solver\n%% technology to solve or approximately that block \n%% (11:43:24 AM) Paul Bauman: Hence, -sub_pc_type\n%% (11:43:32 AM) hil left the room.\n%% (11:43:46 AM) Paul Bauman: That's the preconditioner it's going to\n%% use to precondition the linear system for the solution of the\n%% diagonal block \n%% (11:43:53 AM) Paul Bauman: You're telling it to use incomplete lu\n%% (11:44:26 AM) Paul Bauman: Now the -sub_pc_factor_levels options\n%% applies to ilu \n%% (11:44:28 AM) hil entered the room.\n%% (11:44:44 AM) Paul Bauman: The incomplete part of imcomplete LU is\n%% about the level of fill you use \n%% (11:45:05 AM) Paul Bauman: The more levels of fill you have, the more\n%% ``complete'' the incomplete LU will be \n%% (11:45:08 AM) Paul Bauman: Does that make sense?\n%% (11:45:23 AM) nick: no, that is where you lost me\n%% (11:45:39 AM) nick: i dont think i know this level of fill\n%% (11:46:17 AM) Paul Bauman: Check out Youssef Saad's book if more\n%% curious about the subject \n%% (11:46:37 AM) nick: cool thanks\n%% (11:46:38 AM) Paul Bauman: Suffice it to say, you heopfully shouldn't\n%% ever need to go past 3 or 4 levels of fill \n%% (11:47:03 AM) Paul Bauman: Also, if you've got superlu installed with\n%% the PETSc, consider using -sub_pc_factor_mat_solver_package superlu \n%% (11:47:15 AM) Paul Bauman: That's a *much* faster/better\n%% implementation than PETSc's \n\nAt the time of this writing, GRINS has 94 regression tests, which\nprovides a reasonable degree of confidence in verification testing of\nthe library. Several of these tests directly test the capabilities in\nGRINS used in this study. In particular, several of the tests were\ncontributed to GRINS by the author over the course of this\nwork during the addition of several of the models detailed in\nChapter~\\ref{sec:mathmodel}. \n\n\n\\section{Tool Chain and Simulation Custodianship}\n\nSimulations are performed on the Texas Advanced Computing Center's \n(TACC) supercomputers Lonestar Four, Lonestar Five, and Stampede. Run\ndurations for transient cases are typically twelve hours to perform\nseveral hundred timesteps.  The steady runs are considerably shorter,\nand require less than ten minute runtimes. Typically  the wall clock\ntimes of the steady-state runs are two or three minutes to solution. \n%As a result, the queue time is significantly longer than the actual\n%production runtime. \nThese runs use 264-528 processing cores, or 22-44 nodes on Lonestar4\n(with 12 cores per node), and a similar number for Stampede. The runs have \nseveral million degrees of freedom (DoF), and the local number of DoF\nper core is maintained at $O(10^4)$. This was selected due to memory\nconstraints, after a strong scaling analysis of the performance of the\ncode on these resources, and after consulting with the software developers.  \nAt the time of this writing libMesh has been scaled to tens of thousands of\ncores and has been run on over 100,000 cores on the BG/Q machine Mira at\nArgonne National Lab\\cite{gaston2013massive}, and the scaling results\nhere are consistent with the performance expectations for this library.\n\n%In November, 2015, runs were also staged during early access into full\n%production period on TACC's new system, Lonestar5. This machine is\n%closer in terms of software stack to Stampede, \n%using the Simple Linux Utility for Resource Management\n%(Slurm) scheduling system.  \n\nRuns are submitted via job scripts to the SLURM\\cite{yoo2003slurm}\nscheduling system. After a run terminates, several additional scripts\nare automatically invoked.  \nThese archive the run (outside of the volatile /scratch \nproduction directories) and simultaneously, label the concluded run with\nunique metadata that defines the system environment; the jobs input\nfiles and run definitions; and information detailing the\nhypothesis or physics the job was intended to investigate. Finally, once \na week a script performs \\textbf{rsync} on the entire archived database to\n%ensure more than single redundancy for the runs. \nmaintain redundant storage of the simulation\ndata. Appendix~\\ref{sec:archiving} details the archived simulations and\nstorage patterns. \n\nIn other words, the workflow is designed to permit rapid queuing of a\nseries of runs (in parallel) to investigate a variety of conditions or\nscenario parameters. This capability is necessary for the optimization\ncampaign detailed in Section~\\ref{sec:results}, where running many\nconcurrent investigations are required to sample the configuration\nspace.  \n\n%\\section{Testing and Verification}\n%grid convergence?\n\n\n%The validation of the  runs is detailed in the next Chapter. \n", "meta": {"hexsha": "b1c7a1c5b00c29cb1a060ec620f86fc4097825d9", "size": 20716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/dissertation/chapter-software.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/dissertation/chapter-software.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/dissertation/chapter-software.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 47.1890660592, "max_line_length": 170, "alphanum_fraction": 0.7457520757, "num_tokens": 5650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6460948526542901}}
{"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 3}\n\\author{Jiale Shi}\n\\date{September/21/2018}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{array}\n\\begin{document}\n\\maketitle\n\n\\newpage\n\\section{Problem 1}\nThe problem of interest consists of a scalar output $y$ (the logarithmic of the number of caterpillars colonies in a $500 m^2$ area) and $k=10$ explanatory variables $x_{i} (i=1,...,10)$ which correlate to features such as altitude, landscape slope, vegetation count, etc. The exact meaning does not matter in this context. Using the caterpillar.mat data, plot the semi-log-y plots of the caterpillar colony (last column of the data file) versus each feature reproducing Figure 3.1 in Bayesian Core.\n\nAnswer: we run the code that provided to us. We get the semi-log-$y$ plots are shown below.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Figure3_1.png}\n\\caption{semi-$\\log$-$y$ plots}\n%\\label{fig:universe}\n\\end{figure}\n\n\n\n\n\\newpage\n\\section{Problem 2}\nFrom the book, 3.1.1 linear model\n\nThe ordinary normal linear regression model is such that \n\\begin{equation}\n    y|\\beta,\\sigma^{2},X \\sim \\mathcal{N}_{n}(X\\beta,\\sigma^{2}I_{n})\n\\end{equation}\n\nthe likelihood of the ordinary normal linear model is\n\\begin{equation}\n    l(\\beta,\\sigma^{2}|y,X) = (2\\pi\\sigma^{2})^{n/2} \\exp\\left[-\\frac{1}{2\\sigma^2}(y-X\\beta)^{T}(y-X\\beta)\\right]\n\\end{equation}\n\nThe maximum likelihood estimator of $\\beta$ is then the solution of the (least squares) minimization problem.\n\n\\begin{equation}\n\\min_{\\beta}(y-X\\beta)^{T}(y-X\\beta) = \\min_{\\beta}\\sum_{i=1}^{n}(y_{i}-\\beta_{0}-\\beta_{1}x_{i1}-...-\\beta{k}x_{ik})^2    \n\\end{equation}\nnamely,\n\\begin{equation}\n\\hat{\\beta} = (X^{T} X)^{-1}X^{T}y    \n\\end{equation}\nwhich is also the orthogonal projection of y on the linear subspace spanned by the columns of $X$.\n\nSimilarly, an unbiased estimator of $\\sigma^{2}$ is\n\\begin{equation}\n  \\hat{\\sigma}^2 = \\frac{1}{n-k-1}(y-X\\hat{\\beta})^{T} (y-X\\hat{\\beta}) = \\frac{s^{2}}{n-k-1}\n\\end{equation}\nand $\\hat{\\sigma}^2(X^{T}X)^{-1}$ approximates the covariance matrix of $\\hat{\\beta}$. We can then define the standard t-statistic as \n\n\\begin{equation}\n    T_{i} = \\frac{\\hat{\\beta}_{i}-\\beta_{i}}{\\sqrt{\\hat{\\sigma}^2\\omega_{(i,i)}}} ~\\mathcal{J}_{n-k-1} = \n\\end{equation}\nwhere $\\omega_{(i,i)}$ denotes the $(i,i)$th element of the matrix $(X^{T}X)^{-1}$. For this problem $\\beta_{i}=0$ \n\nthe p value\n\\begin{equation}\n    p_{i}= P_{H_{0}}(|T_{i}|-|t_{i}|) < \\alpha\n\\end{equation}\n\nNote that this statistic $T_{i}$ can also be used to build on the $\\beta_{i}$s as a (marginal) frequentist confidence interval, of the form.\n\n\\begin{equation}\n    {\\beta_{i};|\\beta_{i}-\\hat{\\beta}_{i}|<=\\sqrt{\\omega_{ii}}F^{-1}_{n-k-1}(1-\\alpha/2)}\n\\end{equation}\n\nThen we run the code that is offered to us. We reproduce Figure 3.2\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Figure3_2.png}\n\\caption{Dataset caterpillar: output providing the maximum likelihood estimates of the regression coefficients and their standard significance analysis.}\n%\\label{fig:universe}\n\\end{figure}\n\n\n\\section{Problem 3}\nWe mainly focus on the section 3.2.1 Conjugate Priors.\n\nWe use the conjugate prior:\n\\begin{equation}\n\\begin{aligned}\n    &\\beta|\\sigma^{2}, X \\sim \\mathcal{N}_{k+1}(\\Tilde{\\beta},\\sigma^{2}M^{-1})  \\\\\n    &\\sigma^{2} | X \\sim \\mathcal{IG}(a,b)\n\\end{aligned}\n\\end{equation}\n%Use the hyper-parameter values of $\\Tilde{\\beta}$,k=10,a=2.1andb=2.0forcomputingthetablevalues.\nThe prior is conjugate, leading us to the following normal-inverse-gamma posterior distribution.\n\n\\begin{equation}\n\\begin{aligned}\n    &\\beta|\\sigma^{2},y, X \\sim \\mathcal{N}_{k+1}((M+X^{T}X)^{-1}X^{T}X\\Tilde{\\beta},\\sigma^{2}[M^{-1}+(X^{T}X)^{-1}]^{-1})  \\\\\n    &\\sigma^{2} | y,X \\sim \\mathcal{IG}(\\frac{n}{2},b+\\frac{s^2}{2}+\\frac{\\hat{\\beta}^{T}[M^{-1}+(X^{T}X)^{-1}]^{-1}\\hat{\\beta}}{2})\n\\end{aligned}\n\\end{equation}\nIn this setting, the Bayes estimators of $\\beta$ and $\\sigma^{2}$ associated with squared error losses, namely the posterior means of $\\beta$ and $\\sigma^{2}$, can be computed in closed form. In fact, a simple computation shows that they are given by\n\\begin{equation}\n\\begin{aligned}\n    \\mathbb{E}^{\\pi}[\\beta|y,X] &= \\mathbb{E}^{\\pi}[\\mathbb{E}^{\\pi}(\\beta|\\sigma^2,y,X)|y,X] \\\\\n    & = (M+X^{T}X)^{-1}{(X^{T}X)\\hat{\\beta}+M\\hat{\\beta}}\n\\end{aligned}\n\\end{equation}\n\nand for $n\\geq 2$\n\n\\begin{equation}\n\\begin{aligned}\n    \\mathbb{E}^{\\pi}[\\beta|y,X] &= \\frac{2b+s^{2}+(\\tilde{\\beta}-\\hat{\\beta})^{T}{M^{-1}+(X^{T}X)^{-1}}^{-1}(\\tilde{\\beta}-\\hat{\\beta})}{n+2a-2}\n\\end{aligned}\n\\end{equation}\n\nIntegrating Eq.10 in $\\sigma^{2}$ leads to a multivariate $t$ marginal posterior distribution on $\\beta$ since.\n\n\\begin{equation}\n\\begin{aligned}\n\\pi(\\beta|y,X) & \\propto [ (\\beta-{M+X^{T}X}^{-1}[{X^{T}X}\\hat{\\beta}+M\\tilde{\\beta}])^{T} (M+X^{T}X)  \\\\\n&\\times (\\beta-{M+X^{T}X}^{-1}[{X^{T}X}\\hat{\\beta}+M\\tilde{\\beta}]) +2b+s^2  \\\\\n&+(\\tilde{\\beta}-\\hat{\\beta})^{T} (M^{-1}+(X^{T}X)^{-1})^{-1} (\\tilde{\\beta}-\\hat{\\beta})\n]^{-(n/2+k/2+a)}\n\\end{aligned}\n\\end{equation}\n\nWe thus have that, marginally and a posteriori,\n\\begin{equation}\n    \\beta|y,X \\sim \\mathcal{J}_{k+1}(n+2a,\\hat{\\mu},\\hat{\\Sigma})\n\\end{equation}\n\nwith \n\\begin{equation}\n\\begin{aligned}\n    & \\hat{\\mu} = (M+X^{T}X)^{-1}((X^{T}X)\\hat{\\beta}+M\\tilde{\\beta}) \\\\\n    & \\hat{\\Sigma} = \\frac{2b+s^2 +(\\tilde{\\beta}-\\hat{\\beta})^{T} (M^{-1}+(X^{T}X)^{-1})^{-1} (\\tilde{\\beta}-\\hat{\\beta})}{n+2a}(M+X^{T}X)^{-1}\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    \\mathbb{V}^{\\pi} &= \\frac{n+2a}{n+2a-4} \\hat{\\Sigma} \\\\\n    &=  \\frac{2b+s^2 +(\\tilde{\\beta}-\\hat{\\beta})^{T} (M^{-1}+(X^{T}X)^{-1})^{-1} (\\tilde{\\beta}-\\hat{\\beta})}{n+2a-4}(M+X^{T}X)^{-1}\n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_1.png}\n\\caption{Dataset caterpillar: Influence of the prior scale c on the Bayes estimates of $\\sigma^2$ and $\\beta_{0}$.}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_2.png}\n\\caption{Dataset caterpillar: Bayes estimates of $\\beta$ for $c=100$.}\n%\\label{fig:universe}\n\\end{figure}\n\n\\newpage\n\\section{Problem 4}\nThe posterior distribution can be  derived as \n\\begin{equation}\n\\begin{aligned}\n    \\pi(\\beta,\\sigma^2|y,X) & \\propto f(y|\\beta,\\sigma^2,X)\\pi(\\beta,\\sigma^2|X) \\\\\n    &\\propto (\\sigma^{2})^{-n/2-1} \\exp [-\\frac{1}{2\\sigma^2}(y-X\\hat{\\beta})^{T}(y-X\\hat{\\beta})-\\frac{1}{2\\sigma^2}(\\beta-\\hat{\\beta})^{T}(X^{T}X)(\\beta-\\hat{\\beta})]\\\\\n    &\\cdot (\\sigma^2)^{-k/2} \\exp[-\\frac{1}{2c\\sigma^2}(\\beta^T X^T X\\beta)]\n\\end{aligned}\n\\end{equation}\nConduct marginalization and derive the conditional and marginal posteriors on $\\beta$ and $\\sigma^{2}$:\n\n\\begin{equation}\n\\begin{aligned}\n    & \\beta | \\sigma^{2},y, X \\sim \\mathcal{N}_{k+1}(\\frac{c}{c+1}\\hat{\\beta}, \\frac{\\sigma^2 c}{c+1}(X^{T} X)^{-1}) \\\\\n     & \\sigma^2 | y, X \\sim \\mathcal{IG}(\\frac{n}{2}, \\frac{s^2}{2}+\\frac{1}{2(c+1)}\\hat{\\beta}^T X^T X \\hat{\\beta}) \\\\\n\\end{aligned}\n\\end{equation}\n\n\nBy integrating out $\\sigma^2$ on the conditional posterior $\\beta$, we can show that\n\\begin{equation}\n\\begin{aligned}\n    \\beta | y,X \\sim \\mathbb{T}_{k+1} (n,\\frac{c}{c+1}\\hat{\\beta},\\frac{c(s^2+\\frac{\\hat{\\beta}^{T} X^{T} X \\hat{\\beta}}{c+1})}{n(c+1)}(X^T X)^{-1})\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    & \\mathcal{E}[\\beta|y,X] = \\frac{c}{c+1} \\hat{\\beta} \\\\\n    & \\mathcal{V}[\\beta|y,X] = \\frac{c(s^2+\\frac{\\hat{\\beta}^{T} X^{T} X \\hat{\\beta}}{c+1})}{(n-2)(c+1)}(X^T X)^{-1}\n\\end{aligned}\n\\end{equation}\n\nAnd the expression of Bayes factor has been given.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_3.png}\n\\caption{Dataset caterpillar: Posterior mean and variance of $\\beta$ for $c=100$ using Zellar's G-prior.}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_4.png}\n\\caption{Dataset caterpillar: Same legend as Table 3.3 for c=1000}\n%\\label{fig:universe}\n\\end{figure}\n\nThe dependence of the Bayes factor on the pair ($c,c_{0}$) cannot be bypassed in the sense that the Bayes factor varies between $0$ and $\\infty$ when $c_{0}/c$ goes from $0$ to $\\infty$. \n\nAlthough these Bayes factors should not be used simultaneously, an informal conclusion is that the most important variables besides the intercept seem to be $X_{1},X_{2},X_{4}$ and $X_{5}$.\n\n\\newpage\n\\section{Problem 5}\nThe marginal posterior distribution from Problem 4:\n\n\\begin{equation}\n\\begin{aligned}\n    \\beta | y,X \\sim \\mathbb{T}_{k+1} (n,\\frac{c}{c+1}\\hat{\\beta},\\frac{c(s^2+\\frac{\\hat{\\beta}^{T} X^{T} X \\hat{\\beta}}{c+1})}{n(c+1)}(X^T X)^{-1})\n\\end{aligned}\n\\end{equation}\n\nAs the standard student-t is one symmetrical distribution, we can analytically calculate its $90\\%$ HPD region as the two points whose respective CDF is $5\\%$ and $95\\%$. Denote them as $\\delta_{5}$ and $\\delta_{95}$. The corresponding HPD of $\\beta$ would than be\n\n\\begin{equation}\n\\begin{aligned}\n    & \\beta_{5} = \\frac{c}{c+1}\\hat{\\beta} + \\delta_{5} \\cdot \\frac{c(s^2+\\frac{\\hat{\\beta}^{T} X^{T} X \\hat{\\beta}}{c+1})}{n(c+1)}(X^T X)^{-1}) \\\\\n    & \\beta_{95} = \\frac{c}{c+1}\\hat{\\beta} + \\delta_{95} \\cdot \\frac{c(s^2+\\frac{\\hat{\\beta}^{T} X^{T} X \\hat{\\beta}}{c+1})}{n(c+1)}(X^T X)^{-1}) \n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_5.png}\n\\caption{Dataset caterpillar:$95\\%$ HPD intervals for the components of $\\beta$ for $c=100$}\n%\\label{fig:universe}\n\\end{figure}\n\n\\newpage\n\\section{Problem 6}\nWe now consider c an unknown hyper-parameter, that is we use the same G-prior distribution, and we now introduce a diffuse prior distribution on c.\n\n\\begin{equation}\n\\begin{aligned}\n    \\pi(c)=c^{-1} \\mathcal{I}_{\\mathcal{N*}}(c)\n\\end{aligned}\n\\end{equation}\n\nthe corresponding marginal posterior on the parameters of interest is then\n\\begin{equation}\n\\begin{aligned}\n    \\pi(\\beta,\\sigma^2|y,X) \\sum_{c=1}^{\\infty} \\pi(\\beta,\\sigma^{2}|y,X,c)f(y|X,c)c^{-1}\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    f(y|X) &\\propto_{c} f(y|X,c)\\pi(c) \\\\\n    & \\sum_{c}c^{-1}(c+1)^{-\\frac{k+1}{2}} [y^T y-\\frac{c}{c+1}y^T X(X^T X)^{-1} X^{T} y]^{-n/2}\n\\end{aligned}\n\\end{equation}\n\nFor the posterior mean and variance of $\\beta$, we integrate out $c$ by summation:\n\\begin{equation}\n\\begin{aligned}\n    \\mathcal{E}[\\beta|y,X] = \\sum_{c}\\mathcal{E}[\\beta|y,X,c]\\pi(c|y,X)\n\\end{aligned}\n\\end{equation}\n\nbecause $\\pi(c|y,X) \\propto f(y|X,c) \\pi(c)$\n\n\\begin{equation}\n\\begin{aligned}\n    \\mathcal{E}[\\beta|y,X] = \\sum_{c} \\frac{c}{c+1} \\hat{\\beta} \\pi(c|y,X) = \\hat{\\beta} \\sum_{c} [\\frac{c}{c+1}\\frac{f(y|X,c)\\pi(c)}{\\sum_{c}f(y|X,c)\\pi(c)}]\n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    \\mathcal{V}[\\beta|y,X] = \\mathcal{E}[\\mathcal{V}(\\beta|y,X,c)|y,X] + \\mathcal{V}(\\mathcal{E}[\\beta,X,c]|y,X)\n\\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[scale=0.6]{Table3_6.png}\n\\caption{Table of Problem 6}\n%\\label{fig:universe}\n\\end{figure}\n\nAn important point with this approach is that the marginal distribution of the dataset is available in closed form. It is therefore possible to produce a Bayes regression output, just as in the first-level prior. This is one additional reason why this non-informative prior is introduced.\n\n\\newpage\n\\section{Problem 7}\n\nThe algorithm is stochastic search for the most likely model.\nWhen k is large, it becomes computationally intractable to compute the posterior probabilites of the $2^{k}$ models. Need of a tailored algorithm that samples from $p(\\gamma|y, X)$ and selects the most likely models.\nThis can be done by Gibbs sampling, given the availability of the full conditional posterior probabilities of the $\\gamma_{i}$'s.\nIf the $\\pi$ with the that model parameter is much larger than that without that model parameter, that model parameter should be turned on. \nIf the $\\pi$ with the that model parameter is much smaller than that without that model parameter, that model parameter should be turned off. \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Table3_7.png}\n\\caption{Table of Problem 7(a)}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Table3_8.png}\n\\caption{Table of Problem 7(b)}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Table3_9.png}\n\\caption{Table of Problem 7(c)}\n%\\label{fig:universe}\n\\end{figure}\n\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Table3_10.png}\n\\caption{Table of Problem 7(d)}\n%\\label{fig:universe}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.6]{Table3_11.png}\n\\caption{Table of Problem 7(e)}\n%\\label{fig:universe}\n\\end{figure}\n\n\n%\\bibliographystyle{plain}\n%\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "7d0e9878aa2d6621abf77542286e1414a1d2b111", "size": 12981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW3/HW3_Shi_Jiale_tex/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/HW3/HW3_Shi_Jiale_tex/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/HW3/HW3_Shi_Jiale_tex/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": 36.8778409091, "max_line_length": 499, "alphanum_fraction": 0.6668977737, "num_tokens": 4744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.6460473789677025}}
{"text": "\\subsubsection{Parabolic Cylinders}\r\n\\noindent\r\nA paraboloid cylinder look like a parabola that has been extruded into 3D space. One of its forms is\r\n\\begin{equation*}\r\n\tz = cy^2\t\r\n\\end{equation*} \r\nwhere $c \\in \\R$.\r\n\r\n[INSERT IMAGE]", "meta": {"hexsha": "ff75c18066619e577f7d7021f1202eeb429f1719", "size": 234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/parabolicCylinder.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/parabolicCylinder.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/parabolicCylinder.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.0, "max_line_length": 101, "alphanum_fraction": 0.7179487179, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583167, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6460473671409703}}
{"text": "\\section{Overview}\\label{sec:overviews}\n\n\\def\\sm{\\texttt{sm}}\n\\def\\mc{\\texttt{mconcat}}\n\n\\subsection{Monoids and Parallelism}\\label{subsec:monoids}\n\nAs noted in section~\\ref{sec:intro}, associativity ultimately\nallows monoidal operations to be run in parallel. However, for our\npurposes, we would like a way of breaking an input into pieces and\nrunning our computation, string matching, in parallel on all the\npieces. For this, we will focus on the standard Haskell function \\mc,\n\\begin{code}\n  mconcat :: Monoid m => [m] -> m\n  mconcat [] = mempty\n  mconcat (x:xs) = x <> mconcat xs\n\\end{code}\nwhere @mappend@ and @mempty@ are the monoid operation and identity for\nmonoid \\texttt{m} (usually written \\texttt{mappend} and\n\\texttt{mempty})~\\footnote{\\mc\\, is usually defined as \\texttt{foldr mappend mempty}}.\n\n\\mc is a monoid morphism from lists of values of\na monoid to that monoid, i.e.\n%\n$$\n\\begin{array}{rcl}\n\\mc\\;[] & \\quad \\equiv \\quad & \\mempty \\\\\n\\mc\\;([x_0,\\;\\ldots x_m]\\;\\texttt{++}\\;[y_0,\\ldots y_n])\n& \\quad \\equiv \\quad &\n\\mc\\;[x_0, \\ldots x_m]\\;\\mappend\\;\\mc\\;[y_0,\\ldots y_n]\n\\end{array}\n$$\n%\nwhere \\texttt{++} is list append.\n\n$$\n\\begin{array}{l}\n\\mc\\;[\\sm\\;x_0,\\;\\ldots \\sm\\;x_i, \\sm\\;x_{i+1},\\ldots \\sm\\;x_j, \\sm\\;x_{j+1},\\ldots \\sm\\;x_n] \\\\\n\\;\\;\\equiv\\;\\; \\quad\n\\mc\\;([\\sm\\;x_0,\\;\\ldots \\sm\\;x_i]\\;\\texttt{++}\\;[\\sm\\;x_{i+1},\\ldots \\sm\\;x_j]\\;\\texttt{++}\\;[\\sm\\;x_{j+1},\\ldots \\sm\\;x_n]) \\\\\n\\;\\;\\equiv\\;\\; \\quad\n%\\mc\\;[\\mc\\;[\\sm\\;x_0,\\;\\ldots \\sm\\;x_i]\\;,\\;\\mc\\;[\\sm\\;x_{i+1},\\ldots \\sm\\;x_n]] \\\\\n%\\;\\;\\equiv\\;\\; \\quad\n\\mc\\;[\\sm\\;x_0, \\ldots \\sm\\;x_i]\\;\\mappend\\;\\mc\\;[\\sm\\;x_{i+1},\\ldots \\sm\\;x_j]\\;\\mappend\\;\\mc\\;[\\sm\\;x_{j+1},\\ldots \\sm\\;x_n]\n\\end{array}\n$$\n\n\n\\subsection{String Matching}\\label{subsec:string-matching}\n\nString matching is determining all the indices in a source string\nwhere a given target string begins; for example, for source string\n\\texttt{abababa} and target \\texttt{aba} the results of string\nmatching would be \\texttt{[0, 2, 4]}. We will use the following code\nas a specification of string matching:\n\\begin{code}\nmakeIndices inp trg = go 0 where\n  trgLen = length trg\n  go i | i >= length inp = []\n       | take trgLen (drop i inp) == trg = i : rest\n       | otherwise = rest\n  where rest = go (i + 1)\n\n*Main> makeIndices \"abababa\" \"aba\" == [0, 2, 4]\n\\end{code}\nThough this implementation is not efficient, it is simple and provides\na good starting point from which to create a verifiable function (see\nsec~\\ref{sec:monoid}).\n\n\\subsection{Monoidal String Matching}\\label{subsec:monoidal-string-matching}\n", "meta": {"hexsha": "ec3935b4f10ea31336b41074f6b5ad1518f8df30", "size": 2550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/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/stringmatcher/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/stringmatcher/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.9154929577, "max_line_length": 128, "alphanum_fraction": 0.6654901961, "num_tokens": 949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6460473638898473}}
{"text": "\\chapter{Introduction to Recurrent Neural Networks}\n\n\t\\section{What is a Recurrent Neural Network?}\n\t\n\t\\begin{itemize}\n\t\t\\item Recurrent neural networks or RNNs (Rumelhart et al.,1986a) are a family of\n\t\tneural networks for processing sequential data.\n\t\t\\item  Much as a convolutional network is a neural network that is specialized for processing a grid of values X such as an image, a recurrent neural network is a neural network that is specialized for\n\t\tprocessing a sequence of values $X = \\{x^{(1)}, . . . , x^{(\\tau)}\\}$.\n\t\t\\item Most recurrent networks can also process sequences of \\textbf{variable} length. For each sample $X$, the $\\tau$ doesn't have to bethe same.\n\t\\end{itemize}\n\t\n\t\\subsection{Motivation of RNN}\n\t\t\\textbf{Parameter sharing!} \\\\\n\t\tReasons why we need parameter sharing:\n\t\t\\begin{itemize}\n\t\t\t\\item  Parameter sharing makes it possible to extend and apply the model to examples of different forms\n\t\t\t(or different lengths) and generalize across them.\n\t\t\t\\item  If we had separate parameters for each value of the time index, we could not generalize to sequence lengths not seen during training, nor share statistical characteristic across different sequence lengths\n\t\t\tand across different positions in time. \n\t\t\\end{itemize}\n\t\n\t\t\\textbf{How to use the parameter sharing?}\n\t\t\\begin{itemize}\n\t\t\t\\item In the Recurrent networks, each member of the\n\t\t\toutput is a function of the previous members of the output.\t\n\t\t\t\\item Each member of the output is produced using \\textbf{the same update rule} applied to the previous outputs. This recurrent formulation results in the sharing of parameters through a very deep computational graph.\n\t\t\\end{itemize}\n\n\t\\subsection{Vanilla RNN}\n\t\\begin{itemize}\n\t\t\\item \n\t\t\\textbf{Training Data of the model} \\\\\n\t\tHere we use the sentence generation as the model, which aims to predict the next character in a sentence given all the characters before. \\\\\n\t\t In this model, each $\\mathbf{x}_i^{(t)}$ is a character in the sentence(represented as a $0-1$ vector), and the target is the next character which is also represented as a $0-1$ vector.\n\t\t\\item\n\t\t\\textbf{The structure of the network} \\\\\n\t\tIt's an example of a recurrent network that maps an\n\t\tinput sequence to an output sequence of the same length. \\\\\n\t\tThe input of the network is $\\{\\mathbf{x}_i^{(1)},\\mathbf{x}_i^{(2)},\\dots,\\mathbf{x}_i^{(\\tau)}\\}_{i=1}^N$, where N is the number of the samples, $\\tau$ is the length of each input, and each $\\mathbf{x}_i^{(t)}$ is a vector in the vector space $\\mathbb{R}^n$. \\\\\n\t\t The output is $\\{\\mathbf{y}_i^{(1)},\\mathbf{y}_i^{(2)},\\dots,\\mathbf{y}_i^{(\\tau)}\\}_{i=1}^N$, the meaning of N and $\\tau$ is the same, while each $\\mathbf{y}_i^{(t)}$ is a vector in the vector space $\\mathbb{R}^m$. \\\\\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.9\\textwidth]{VaRNN}\n\t\t\t\\caption{The structure of Vanilla RNN}\n\t\t\\end{figure}\n\t\t\n\t\t\\item\n\t\t\\textbf{The update equations for the forward propagation} is\n\t\t\\begin{flalign*}\n\t\t\\mathbf{a}^{(t)} &= \\mathbf{b} + \\mathbf{Wh}^{(t-1)} + \\mathbf{Ux}^{(t)} \\\\\n\t\t\\mathbf{h}^{(t)} &= tanh(\\mathbf{a}^{(t)}) \\\\\n\t\t\\mathbf{O}^{(t)} &= \\mathbf{c} + \\mathbf{Vh}^{(t)} \\\\\n\t\t\\hat{\\mathbf{y}}^{(t)} &= softmax(\\mathbf{O}^{(t)})\n\t\t\\end{flalign*}\n\t\twhere the parameters are bias vectors $\\mathbf{b}$ and $\\mathbf{c}$ along with the weight matrices\n\t\t$\\mathbf{U}$, $\\mathbf{V}$ and $\\mathbf{W}$, respectively for input-to-hidden, hidden-to-output and hidden-to- hidden connections.\n\n\t\t\\item\n\t\t\\textbf{The computation of the loss} \\\\\n\t\tFor a given sequence of $\\mathbf{x}$ values paired with a sequence of $\\mathbf{y}$ values, the total loss would then be just the sum of the losses over all the time steps.\\\\\n\t\tFor example, if $L^{(t)}$ is the negative log-likelihood of $y^{t}$ given $\\{\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(t)} \\}$, the total loss is\n\t\t\\begin{flalign*}\n\t\tL({\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(\\tau)}},{\\mathbf{\\hat{y}}^{(1)},\\ldots,\\mathbf{\\hat{y}}^{(\\tau)}}) \\\\\n\t\t= \\sum_{t=1}^{\\tau} L^{(t)}  \\\\\n\t\t= - \\sum_{t=1}^{\\tau} log \\ p_{model}(\\mathbf{\\hat{y}}^{(t)} |{\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(t)}}) \n\t\t\\end{flalign*}\n\t\twhere $p_{model}(\\mathbf{\\hat{y}}^{(t)} |{\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(t)}}) $ is given by the following rule:\\\\\n\t\tDenote the $\\mathbb{R}^m$ output vector $\\hat{\\mathbf{y}}^{t}$ as $(\\hat{y}_1^{(t)},\\hat{y}_2^{(t)},\\dots,\\hat{y}_m^{(t)})$,and the target vector (a $0-1$ vector) is $(y_1^{(t)},y_2^{(t)},\\dots,y_m^{(t)})$ while $y_i^{(t)} = 1$ and all the other elements of the vector is 0. Then \n\t\t\\begin{equation}\n\t\tp_{model}(\\mathbf{\\hat{y}}^{(t)} |{\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(t)}}) = \\hat{y}_i^{(t)}\n\t\t\\end{equation}\n\t\\end{itemize}\n\n\t\\subsection{Some important design patterns for RNN}\n\t\t\\begin{itemize}\n\t\t\t\\item Recurrent networks that produce an output at each time step and have recurrent connections only from the output at one time step to the hidden units at the next time step.\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[width=0.9\\textwidth]{O2HRNN}\n\t\t\t\t\\caption{The structure of RNN(Output to Hidden)}\n\t\t\t\\end{figure}\n\t\t\t\\textbf{The update equations for the forward propagation} is\n\t\t\t\\begin{flalign*}\n\t\t\t\\mathbf{a}^{(t)} &= \\mathbf{b} + \\mathbf{WO}^{(t-1)} + \\mathbf{Ux}^{(t)} \\\\\n\t\t\t\\mathbf{h}^{(t)} &= tanh(\\mathbf{a}^{(t)}) \\\\\n\t\t\t\\mathbf{O}^{(t)} &= \\mathbf{c} + \\mathbf{Vh}^{(t)} \\\\\n\t\t\t\\hat{\\mathbf{y}}^{(t)} &= softmax(\\mathbf{O}^{(t)})\n\t\t\t\\end{flalign*}\n\t\t\twhere the parameters are  bias vectors $\\mathbf{b}$ and $\\mathbf{c}$ along with the weight matrices\n\t\t\t$\\mathbf{U}$, $\\mathbf{V}$ and $\\mathbf{W}$, respectively for input-to-hidden, hidden-to-output and output-to- hidden connections.\n\t\t\t\\item Recurrent networks with recurrent connections between hidden units, that read an entire sequence and then produce a single output.\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[width=0.9\\textwidth]{OFRNN}\n\t\t\t\t\\caption{The structure of RNN(Only One Output)}\n\t\t\t\\end{figure}\n\t\t\t\\textbf{The update equations for the forward propagation is}\n\t\t\t\\begin{flalign*}\n\t\t\t\\mathbf{a}^{(t)} &= \\mathbf{b} + \\mathbf{Wh}^{(t-1)} + \\mathbf{Ux}^{(t)} \\qquad 1 \\leq t \\leq \\tau\\\\\n\t\t\t\\mathbf{h}^{(t)} &= tanh(\\mathbf{a}^{(t)}) \\qquad 1 \\leq t \\leq \\tau\\\\\n\t\t\t\\mathbf{O}^{(\\tau)} &= \\mathbf{c} + \\mathbf{Vh}^{(\\tau)} \\\\\n\t\t\t\\hat{\\mathbf{y}}^{(\\tau)} &= softmax(\\mathbf{O}^{(\\tau)})\n\t\t\t\\end{flalign*}\n\t\t\twhere the parameters are bias vectors $\\mathbf{b}$ and $\\mathbf{c}$ along with the weight matrices\n\t\t\t$\\mathbf{U}$, $\\mathbf{V}$ and $\\mathbf{W}$, respectively for input-to-hidden, hidden-to-output and hidden-to- hidden connections\n\t\\end{itemize}\n\n%\t\\subsection{Teaching Force}\n%\t\tNote that in the second pattern,it lacks hidden-to-hidden\n%\t\trecurrence.\n%\t\t\\begin{itemize}\n%\t\t\t\\item It is less powerful.\n%\t\t\t\\item However,for any loss function based on comparing the prediction at time t to the training target at time t, all the time steps are decoupled.\n%\t\t\t\\item Training can thus be parallelized, with the gradient for each step t computed in isolation.\n%\t\t\\end{itemize}\n%\t\t\\begin{figure}[H]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[width=0.9\\textwidth]{TF}\n%\t\t\t\\caption{The representation of Teaching Force}\n%\t\t\\end{figure}\n%\tThe parallelization is the concept of \\textbf{Teaching Force}.\n%\t\t\\begin{itemize}\n%\t\t\t\\item Teacher forcing is a procedure that emerges from the maximum likelihood criterion, in which during training the\n%\t\t\tmodel receives \\textbf{the ground truth output} $y^{(t)}$ as input at time t + 1.\n%\t\t\t\\item Take a sequence with two time steps as an example. The conditional maximum likelihood criterion is\n%\t\t\t\\begin{flalign*}\n%\t\t\tlog p(\\mathbf{\\hat{y}}^{(1)},\\mathbf{\\hat{y}}^{(2)}|\\mathbf{x}^{(1)},\\mathbf{x}^{(2)}) \\\\\n%\t\t\t= log p(\\mathbf{\\hat{y}}^{(2)} | \\mathbf{\\hat{y}}^{(1)},\\mathbf{x}^{(1)},\\mathbf{x}^{(2)}) + log p(\\mathbf{\\hat{y}}^{(1)} | \\mathbf{x}^{(1)},\\mathbf{x}^{(2)})\n%\t\t\t\\end{flalign*}\n%\t\t\t\\item In this example, we see that at time t = 2, the model is trained to maximize the \\textbf{conditional probability} of $\\mathbf{y}^{(2)}$ given both the $\\mathbf{x}$ sequence so far and the previous $\\mathbf{y}$ value from the training.\n%\t\t\\end{itemize}\t\n\n\t\\section{Development of RNN}\n\t\n\t\\subsection{Encoder-Decoder}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.9\\textwidth]{Encoder-Decoder}\n\t\t\t\\caption{The structure of Encoder-Decoder}\n\t\t\\end{figure}\n\n\t\t\\begin{itemize}\n\t\t\t\\item It's an RNN that can be trained to map an input sequence to an output sequence which is not necessarily of the same length.\n\t\t\t\\item First, we have an \\textbf{encoder} or \\textbf{input} RNN that processes the input sequence. The encoder emits the context C, usually as a simple function of its final hidden state.\n\t\t\t\\item The context C might be a vector or sequence of\n\t\t\tvectors that summarize the input sequence $\\mathbf{X} = (\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(n_x)})$.\n\t\t\t\\item Then we have a \\textbf{decoder} or \\textbf{output} RNN that is conditioned on that fixed-length vector $\\mathbf{X}$ to generate the output sequence $(\\mathbf{y}^{(1)},\\ldots,\\mathbf{y}^{(n_y)})$.\n\t\t\t\\item The two RNNs are trained jointly to maximize the average of \\\\\n\t\t\t$log P(\\mathbf{y}^{(1)},\\ldots,\\mathbf{y}^{(n_y)}|\\mathbf{x}^{(1)},\\ldots,\\mathbf{x}^{(n_x)})$ over all the pairs of x and y\n\t\t\tsequences in the training set.\n\t\t\\end{itemize}\n\t\\subsection{Deep RNN}\n\t\tThe computation in most RNNs can be decomposed into three blocks of parameters and associated transformations:\n\n\t\t\\begin{itemize}\n\t\t\t\\item[1.] from the input to the hidden state\n\t\t\t\\item[2.] from the previous hidden state to the next hidden state\n\t\t\t\\item[3.] from the hidden state to the output\n\t\t\\end{itemize}\n\t\tExperimental evidence (Graves et al., 2013; Pascanu et al., 2014a) strongly suggests that we need \\textbf{enough depth} in order to perform the required mappings in each of these operations.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=0.9\\textwidth]{DeepRNN}\n\t\t\t\\caption{Some kind of Structure for Deep RNN}\n\t\t\\end{figure}\n\tA recurrent neural network can be made deep in many ways (Pascanu\n\tet al., 2014a). \n\t\\begin{itemize}\n\t\t\\item (a) The hidden recurrent state can be broken down into groups organized hierarchically. \n\t\t\\item (b) Deeper computation can be introduced in the input-to- hidden, hidden-to-hidden and hidden-to-output parts. This may lengthen the shortest path linking different time steps. \n\t\t\\item (c) The path-lengthening effect can be mitigated by introducing skip connections.\n\t\\end{itemize}\n\t\t\n%\t\\subsection{Recursive Neural Network}\n%\t\t\\begin{itemize}\n%\t\t\t\\item Recursive neural networks represent yet another generalization of recurrent networks, with a different kind of computational graph, which is structured as a \\textbf{deep tree}, rather than the chain-like structure of RNNs.\n%\t\t\t\\item One clear advantage of recursive nets over recurrent nets is that for a sequence of the same length $\\tau$, the depth (measured as the number of compositions of nonlinear operations) can be drastically reduced from $\\tau$ to $O(log \\tau)$.\n%\t\t\t\\item However,how to \\textbf{best structure the tree} is an open question.\n%\t\t\\end{itemize}\n%\t\t\\begin{figure}[H]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[width=0.9\\textwidth]{ReNN}\n%\t\t\t\\caption{The structure of Recursive Neural Network}\n%\t\t\\end{figure}\n\n\\section{The Challenge of long term dependency}\n\\subsection{Computation of the gradient}\nComputing the gradient through a recurrent neural network is straightforward. One simply applies the generalized back-propagation algorithm to the network. \\\\\nWhat we need to take care of is that the back propagation should be computed through \\textbf{the time step}. We will use the example of computing the gradients of Vanilla RNN above to show how the BP algorithm behaves. \\\\\nDenote the final loss as $L$,we can see \n\\begin{equation}\n\\frac{\\partial L}{\\partial L^{(t)}} = 1  \\ ,1\\le t \\le \\tau\n\\end{equation}\nAssume the output function is softmax function and the loss is negative log-likelihood function, The gradient $\\nabla_{o^{(t)}}L$ on the outputs at time step t, for all i,t, is as follows:\n\\begin{equation}\n(\\nabla_{o^{(t)}}L)_i = \\frac{\\partial L}{\\partial L^{(t)}}\\frac{\\partial L^{(t)}}{\\partial o_i^{(t)}} = \\hat{y_i}^{(t)} - 1_{i,y^{(t)}}\n\\end{equation}\nAt the final time step $\\tau$, we have\n\\begin{equation}\n\\nabla_{h^{(\\tau)}}L = V^{T}\\nabla_{o^{(\\tau)}}L\n\\end{equation}\nwith \n\\begin{eqnarray}\n\\nabla_{h^{(t)}}L & = & (\\frac{\\partial h^{(t+1)}}{\\partial h^{(t)}})^{T}\\nabla_{h^{(t+1)}}L + (\\frac{\\partial o^{(t)}}{\\partial h^{(t)}})^{T}\\nabla_{o^{(t)}}L \\\\\n & = & W^T\\nabla_{h^{(t+1)}}L diag(1 - (h^{(t+1)})^2) + V^T\\nabla_{o^{(t)}}L\n\\end{eqnarray}\nfrom $t = \\tau -1$ down to $t = 1$. \\\\\nWith these, the gradient on the remaining parameters is given by:\n\\begin{eqnarray}\n\\nabla_{c}L & = & \\sum_{t=1}^{\\tau} \\nabla_{o^{(t)}}L \\\\\n\\nabla_{b}L & = & \\sum_{t=1}^{\\tau} diag(1 - (h^{(t)})^2)\\nabla_{h^{(t)}}L \\\\\n\\nabla_{V}L & = & \\sum_{t=1}^{\\tau}(\\nabla_{o^{(t)}}L)h^{(t)^T} \\\\\n\\nabla_{W}L & = & \\sum_{t=1}^{\\tau} diag(1 - (h^{(t)})^2)(\\nabla_{h^{(t)}}L)h^{(t-1)^T} \\\\\n\\nabla_{U}L & = & \\sum_{t=1}^{\\tau} diag(1 - (h^{(t)})^2)(\\nabla_{h^{(t)}}L)x^{(t)^T}\n\\end{eqnarray}\n\\subsection{Challenge of long term dependency}\nFrom the computation above, we can see in the recurrent network, it involves the composition of the same function multiple times, once per time step. Recall the equation:\n\\begin{equation}\n\\nabla_{h^{(t)}}L = W^T\\nabla_{h^{(t+1)}}L diag(1 - (h^{(t+1)})^2) + V^T\\nabla_{o^{(t)}}L\n\\end{equation}\nFrom the knowledge of linear algebra, we can see the recurrent composition causes eigenvalues with magnitude less than one to decay to zero and eigenvalues with magnitude greater than one to explode.  \\\\\nLet's first focus on the impact of vanishing gradient.Specifically, whenever the model is able to represent long term dependencies, the gradient of a long term interaction has \\textbf{exponentially smaller magnitude} than\nthe gradient of a short term interaction. It does not mean that it is impossible to learn, but that it might take a very long time to learn long-term dependencies, because the signal about these dependencies will tend to be hidden by the smallest fluctuations arising from short-term dependencies. \\\\\nWe will discuss various approaches that have been proposed to reduce the difficulty of learning long- term dependencies, but the problem of learning long-term dependencies remains one of the main challenges in deep learning.\n\n\\subsection{Long Short Term Memory}\nIn the LSTM model, we use a forget unit $f_i^{(t)}$,that sets this weight to a value between 0 and 1 via a sigmoid unit:\n\\begin{equation}\nf_i^{(t)} = \\sigma(b_i^f + \\sum_jU_{i,j}^fx_j^{(t)} + \\sum_jW_{i,j}^fh_j^{(t-1)})\n\\end{equation}\nwhere $x^{(t)}$ is the current input vector and $h^{(t)}$ is the current hidden layer vector, containing the outputs of all the LSTM cells, and $b^f$,$U^f$,$W^f$,are respectively biases, input weights and recurrent weights for the forget gates. \\\\\n The LSTM cell internal state is thus updated as the following, with a conditional self-loop weight $f_i^{(t)}$\n\\begin{equation}\ns_i^{(t)} = f_i^{(t)} \\ast s_i^{(t-1)} + g_i^{(t)} \\ast \\sigma(b_i + \\sum_jU_{i,j}x_j^{(t)} + \\sum_jW_{i,j}h_j^{(t-1)})\n\\end{equation}\nwhere b, U and W respectively denote the biases, input weights and recurrent weights into the LSTM cell and $\\ast$ means the multiplication by elements($.\\ast$ in MATLAB). \\\\\nThe external input gate unit $g_i^{(t)}$ is computed similarly to the forget gate (with a sigmoid unit to obtain a gating value between 0 and 1, but with its own parameters:\n\n\\begin{equation}\ng_i^{(t)} = \\sigma(b_i^g + \\sum_jU_{i,j}^gx_j^{(t)} + \\sum_jW_{i,j}^gh_j^{(t-1)})\n\\end{equation}The output $h_i^{(t)}$ of the LSTM cell can also be shut off, via the output gate $o_i^{(t)}$, which also uses a sigmoid unit for gating:\n\n\\begin{equation}\nh_i^{(t)} = tanh(s_i^{(t)}) \\ast o_i^{(t)}\n\\end{equation}\n\\begin{equation}\no_i^{(t)} = \\sigma(b_i^o + \\sum_jU_{i,j}^ox_j^{(t)} + \\sum_jW_{i,j}^oh_j^{(t-1)})\n\\end{equation}\nLSTM networks have been shown to learn long-term dependencies more easily than the simple recurrent architectures.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{LSTM}\n\t\\caption{Block diagram of the cell of LSTM recurrent network. Cells are connected recurrently to each other, replacing the usual hidden units of ordinary recurrent networks. An input feature is computed with a regular artificial neuron unit. Its value can be accumulated into the state if the sigmoidal input gate allows it. The state unit has a linear self-loop whose weight is controlled by the forget gate. The output of the cell can be shut off by the output gate. All the gating units have a sigmoid nonlinearity, while the input unit can have any squashing nonlinearity. The state unit can also be used as an extra input to the gating units. The black square indicates a delay of a single time step.}\n\\end{figure}\nFrom the equations above, we'll give a brief explanation(not strict!) here why the LSTM works for the long-term dependency. We will just focus on the gradient vanishing. \\\\\nFirst, we have \n\\begin{equation}\ns_i^{(t)} = f_i^{(t)} \\ast s_i^{(t-1)} + g_i^{(t)} \\ast \\sigma(b_i + \\sum_jU_{i,j}x_j^{(t)} + \\sum_jW_{i,j}h_j^{(t-1)})\n\\end{equation}\nhence we get\n\\begin{equation}\n\\frac{\\partial s_i^{(t+k)}}{\\partial s_i^{(t)}} \\approx \\prod_{j=t+1}^{t+k} diag(f_i^{(j)}) + ...\n\\end{equation}\nwhere the $...$ things are some products which are vanishing to zero as k increases(just like we talked above). If in each time step j($t \\le j \\le t+k$), $f_i^{(j)} \\approx \\textbf{1}$(It forgets nothing!),we can see that $\\frac{\\partial s_i^{(t+k)}}{\\partial s_i^{(t)}}$ is almost an identity matrix in the long term, and that means we can connect the information between long time steps together. We can go to the paper <LONG SHORT-TERM MEMORY>(Schmidhuber $\\&$ Hochreiter,1997) for the detailed discussion.\n\\subsection{Other Gated RNNs}\nLet's take a look at the recent work on gated RNNs, whose units are also known as gated recurrent units or GRUs (Cho et al., 2014b;Chung et al., 2014, 2015a; Jozefowicz et al., 2015; Chrupala et al., 2015). \\\\\nThe main difference with the LSTM is that a single gating unit simultaneously controls the forgetting factor and the decision to update the state unit. The update equations are the following:\n\n\\begin{equation}\nh_i^{(t)} = u_i^{(t)} \\ast h_i^{(t-1)} + (1 - u_i^{t}) \\ast \\sigma(b_i + \\sum_jU_{i,j}x_j^{(t-1)} + \\sum_jW_{i,j}r_j^{(t)}h_j^{(t-1)})\n\\end{equation}\nwhere $u$ is 'update' gate and $r$ is 'reset' gate. The values are determined by:\n\\begin{equation}\nu_i^{(t)} = \\sigma(b_i^u + \\sum_jU_{i,j}^ux_j^{(t)} + \\sum_jW_{i,j}^uh_j^{(t-1)})\n\\end{equation}\nand\n\\begin{equation}\nr_i^{(t)} = \\sigma(b_i^r + \\sum_jU_{i,j}^rx_j^{(t)} + \\sum_jW_{i,j}^rh_j^{(t-1)})\n\\end{equation}\n\\section{Optimization methods for RNN}\n\\subsection{Clipping gradients}\nAs discussed before, strongly nonlinear functions such as those computed by a recurrent net over many time steps tend to have derivatives that can be either very large or very small in magnitude. \\\\\nThe difficulty that arises is that when the parameter gradient is very large, a gradient descent parameter update could throw the parameters very far, into a region where the objective function is larger, undoing much of the work before.The gradient tells us the direction that corresponds to the steepest descent within an infinitesimal region surrounding the current parameters. \\\\\nA simple type of solution has been in use by practitioners for many years:\nclipping the gradient. One step is to clip the norm $||g||$ of the gradient g (Pascanu et al., 2013) just before the parameter update:\n\\begin{eqnarray}\n\\text{if} \\ & ||g||  > v \\\\\n& g\\leftarrow \\frac{g v}{||g||}\n\\end{eqnarray}\nBecause the gradient of all the parameters (including different groups of parameters, such as weights and biases) is renormalized jointly with a single scaling factor, the method has the advantage that it guarantees that each step is \\textbf{still in the gradient direction}. Although the parameter updating has the same direction as the true gradient, with gradient norm clipping, the parameter update vector norm is now bounded. This bounded gradient avoids performing a detrimental step when the gradient explodes.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{Clipgrad}\n\t\\caption{Example of the effect of gradient clipping in a recurrent network with two parameters w and b. Gradient clipping can make gradient descent perform more reasonably in the vicinity of extremely steep cliffs. These steep cliffs commonly occur in recurrent networks near where a recurrent network behaves approximately linearly. The cliff is exponentially steep in the number of time steps because the weight matrix is multiplied by itself once for each time step. (Left)Gradient descent without gradient clipping overshoots the bottom of this small ravine, then receives a very large gradient from the cliff face. The large gradient catastrophically propels the parameters outside the axes of the plot. (Right)Gradient descent with gradient clipping has a more moderate reaction to the cliff. While it does ascend the cliff face, the step size is restricted so that it cannot be propelled away from steep region near the solution. Figure adapted with permission from Pascanu et al. (2013).\n}\n\\end{figure}\n\\subsection{Regularizing to Encourage Information Flow}\nGradient clipping helps to deal with exploding gradients, but it does not help with vanishing gradients.To address vanishing gradients and better capture long-term dependencies, an idea is to regularize or constrain the parameters so as to encourage 'information flow'. \\\\\nIn particular, we would like the gradient vector $\\nabla_{h^{(t)}}L$ being back-propagated to maintain its magnitude, even if the loss function only penalizes the output at the end of the sequence. Formally, we want\n\\begin{equation}\n(\\nabla_{h^{(t)}}L) \\frac{\\partial h^{(t)}}{\\partial h^{(t-1)}}\n\\end{equation}\nto be as large as \n\\begin{equation}\n\\nabla_{h^{(t)}}L\n\\end{equation}\nWith this objective, Pascanu et al. (2013) propose the following regularizer:\n\\begin{equation}\n\\Omega = \\sum_{t}(\\frac{|(\\nabla_{h^{(t)}}L) \\frac{\\partial h^{(t)}}{\\partial h^{(t-1)}}|}{|\\nabla_{h^{(t)}}L|} - 1)^2\n\\end{equation}\nThe experiments with this regularizer suggest that, if combined with the norm clipping, the regularizer can considerably increase the span of the dependencies that an RNN can learn.\n", "meta": {"hexsha": "289cfbb9aae9a6bef76d3f58667ce2c3e3a60848", "size": 22552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/IntroductionRNN.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/IntroductionRNN.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/IntroductionRNN.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": 72.0511182109, "max_line_length": 996, "alphanum_fraction": 0.7068552678, "num_tokens": 6977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6460195434011388}}
{"text": "\\section{Dynamics (formally)}\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{System -- recap and systematisation}\n\\framesubtitleTC{A mathematical representation (model) of something that evolves}\n\\myPause\n \\begin{columns}\n  \\column[T]{0.45\\textwidth}\n   \\begin{itemize}[<+-| alert@+>]\n   \\item[] Simple representation\n   \\item[] \\vspace{2mm}\\begin{center}\n            \\input{./Unit-02/img/DS-SimpleRepresentation.tex}\n           \\end{center}\n           \\begin{itemize}[<+-| alert@+>]\n           \\item[] $u$ -- input(s)\n           \\item[] $y$ -- output(s)\n           \\end{itemize}\n   \\end{itemize}\n  \\column[T]{0.55\\textwidth}\n   \\begin{itemize}[<+-| alert@+>]\n   \\item[] Model ingredients\n           \\begin{itemize}[<+-| alert@+>]\n           \\item what the system evolves upon:\n                 \\begin{itemize}[<+-| alert@+>]\n                 \\item the \\TC{continuous time} $t$;\n                 \\item an integer index $k$ counting some events,\n                       frequently called\\\\the \\TC{discrete time}.\n                 \\end{itemize}\n           \\item the \\TC{evolution law}:\n                 \\begin{itemize}[<+-| alert@+>]\n                 \\item $u[t_0,t]\\;\\rightarrow\\;y[t_0,t]$;\n                 \\item $u[k_0,k]\\;\\rightarrow\\;y[k_0,k]$.\n                 \\end{itemize}\n           \\end{itemize}\n   \\end{itemize}\n \\end{columns} \\myPause\n \\vfill\n \\begin{center}\n  \\vfill \\textbf{Is anything missing? \\myPause Sometimes, yes.}\n \\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{\\underline{Dynamic} system -- recap and systematisation}\n\\framesubtitleTC{The most general definition}\n\\myPause\n\\begin{center}\n {\\Large\n If the knowledge of $u[t_0,t]$ --- or $u[k_0,k]$ \\\\ \\myPause\n allows to determine $y[t_0,t]$ --- or $y[k_0,k]$ \\\\ \\myPause\n the system is said to be \\TC{non dynamic},\\\\ \\myPause\n \\vspace{1.5mm}\\TC{dynamic} otherwise. \\myPause\n }\n\\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Dynamic system -- recap and systematisation}\n\\framesubtitleTC{Input, output, and \\emph{state}}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item Non dynamic system:\\\\\n      $y[t_0,t]$ or $y[k_0,k]$ depends only on $u[t_0,t]$ or $u[k_0,k]$.\n\\item Dynamic system:\\\\\n      $y[t_0,t]$ or $y[k_0,k]$ depends on $u[t_0,t]$ or $u[k_0,k]$,\\\\\n      and on the initial values $x[t_0]$ or $x[k_0]$ of some quantities.\n\\item These are called the \\TC{state variables}, and form the \\TC{state (vector)}.\n\\item The number of state variables is called the \\TC{order} of the system.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Dynamic system -- recap and systematisation}\n\\framesubtitleTC{How can we express this in mathematical terms?}\n\\myPause\nIn several ways. We see the only two relevant for us.\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item Continuous-Time (CT) system:\\\\\n      \\begin{displaymath}\n       \\left\\{\n        \\begin{array}{rl}\n         \\frac{dx(t)}{dt} &= f \\big( x(t),u(t),t  \\big) \\\\\n         y(t)             &= g \\big( x(t),u(t),t  \\big)\n        \\end{array}\n       \\right.\n      \\end{displaymath}\n\\item Discrete-Time (DT) system:\\\\\n      \\begin{displaymath}\n       \\left\\{\n        \\begin{array}{rl}\n         x(k) &= f \\big( x(k-1),u(k-1),k  \\big) \\\\\n         y(k) &= g \\big( x(k),u(k),k  \\big)\n        \\end{array}\n       \\right.\n      \\end{displaymath}\n\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Dynamic system -- recap and systematisation}\n\\framesubtitleTC{Some more definitions (for both the CT and the DT case)}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item \\TC{Linear (L)} system:\\\\\n      $f(\\cdot,\\cdot,\\cdot)$ and $g(\\cdot,\\cdot,\\cdot)$ linear in $x$ and $u$.\n\\item \\TC{Time-Invariant (TI)} system:\\\\\n      $f(\\cdot,\\cdot,\\cdot)$ and $g(\\cdot,\\cdot,\\cdot)$ not depending on $t$ or $k$.\n\\item \\TC{Proper} (sometimes, \\emph{strictly} proper) system:\\\\\n      $g(\\cdot,\\cdot,\\cdot)$ not depending on $x$,\\\\\n      i.e., the input acts on the output only through the state.\n\\item \\TC{SISO} (Single-Input, Single-Output) system:\\\\\n      $u$ and $y$ -- not necessarily $x$ -- scalars.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Motion}\n\\framesubtitleTC{General definition}\n\\myPause\n\\centerline{Note: from now on we mostly speak DT, for CT just replace $k$ with $t$.} \\myPause\n\\vspace{3mm}\\begin{itemize}[<+-| alert@+>]\n\\item Initial state + input at a certain start time $\\Rightarrow$ motion, i.e.,\n      \\begin{displaymath}\n       \\left.\n        \\begin{array}{l}\n         x(k_0) \\\\ u(k),\\,k \\geq k_0\n        \\end{array}\n       \\right\\}\n       \\quad \\Rightarrow \\quad\n        x(k),y(k),\\,k \\geq k_0.\n      \\end{displaymath}\n\\item We call $x(k)$ and $y(k)$, respectively,\n      \\begin{itemize}[<+-| alert@+>]\n      \\item the \\TC{state motion}\n      \\item and the \\TC{output motion}\n      \\end{itemize}\n\\item [] produced by the initial state $x(k_0)$ and the input $u(k)$, starting\\\\\n      at time $k_0$.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Motion}\n\\framesubtitleTC{for the Time-Invariant (TI) case, to which we restrict the scope from now on}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item Initial state + input $\\Rightarrow$ motion independently of the start time, i.e.,\n      \\begin{displaymath}\n       \\left.\n        \\begin{array}{l}\n         x(0) \\\\ u(k),\\,k \\geq 0\n        \\end{array}\n       \\right\\}\n       \\quad \\Rightarrow \\quad\n        x(k),y(k),\\,k \\geq 0.\n      \\end{displaymath}\n\\item Alternatively, we can say that with TI systems one can set the origin\\\\\n      of the time axis wherever one wants (for convenience, at zero).\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Equilibrium}\n\\framesubtitleTC{Definition (in the TI case)}\n\\myPause\n\\begin{center}\n {\\Large\n If there exist some state vectors $\\overline{x}$\\\\ \\myPause\n such that $x(0)=\\overline{x}$ and $u(k)=\\overline{u}$, $k \\geq 0$,\\\\ \\myPause\n produce the constant state motion $x(k)=\\overline{x}$, $k \\geq 0$,\\\\ \\myPause\n then those vectors are called \\TC{equilibrium states},\\\\ \\myPause\n or \\TC{equilibria} for short,\\\\ \\myPause\n \\vspace{1.5mm}corresponding to the constant input $\\overline{u}$.\n }\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitleTC{Equilibrium}\n\\framesubtitleTC{Finding equilibrium states and outputs}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item A state vector $\\overline{x}$ is an equilibrium for a given $\\overline{u}$ if the consequent motion is\n      $x(k)=x(k-1)=\\overline{x}$ $\\forall k$.\n\\item Thus to find equilibria one solves\n      \\begin{displaymath}\n       \\overline{x} = f(\\overline{x},\\overline{u}).\n      \\end{displaymath}\n\\item If some equilibrium state exists, and $g(\\overline{x},\\overline{u})$ does not lose significance,\\\\\n      the result is the corresponding \\TC{equilibrium output} $\\overline{y}$.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Stability}\n\\framesubtitleTC{Preliminaries}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item The existence of an equilibrium implies NOTHING on what happens if the system does not start exactly\n      at the equilibrium.\n\\item Discussing this is a matter of \\TC{stability}.\n\\item One can talk about stability of equilibria, motions, and sometimes systems.\n\\item We define stability for an equilibrium, do not talk about motions,\\\\\n      and move to systems later on.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Stability}\n\\framesubtitleTC{Stable equilibrium}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item Let $\\overline{x}$ be an equilibrium for the constant input $\\overline{u}$.\n\\item Denote by $x_{\\Delta}(k)$ the \\TC{perturbed motion} produced by\n      \\begin{itemize}[<+-| alert@+>]\n      \\item the input $\\overline{u}$,\n      \\item and the \\TC{perturbed initial state} $x(0)=\\overline{x}+\\Delta\\overline{x}$.\n      \\end{itemize}\n\\item Not that in general, $x_{\\Delta}(k)$ will not be constant.\n\\item Denote by $||x||$ the norm (think here of the Euclidean norm)\\\\\n      of vector $x$.\n\\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitleTC{Stability}\n\\framesubtitleTC{Stable equilibrium}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item An equilibrium $\\overline{x}$ corresponding to the constant input $\\overline{u}$ is said to be \\TC{stable} if\n      \\begin{displaymath}\n       \\forall \\varepsilon>0 \\;\n       \\exists \\delta_{\\varepsilon}>0 \\; : \\;\n       ||\\Delta\\overline{x}||<\\delta_{\\varepsilon}\n       \\Rightarrow ||x_{\\Delta}(k)-\\overline{x}||<\\varepsilon \\; \\forall k \\geq 0.\n      \\end{displaymath}\n\\item Interpretation: stable equilibrium means that\n      \\begin{itemize}[<+-| alert@+>]\n      \\item no matter how close one wants the \\TC{entire} perturbed motion to remain to the equilibrium,\n      \\item a maximum distance of the initial state from the equilibrium can be\\\\\n            found, that fulfils the desire.\n      \\end{itemize}\n      \\item Graphically,\n            \\begin{center}\n             \\includegraphics[width=0.60\\columnwidth]{./Unit-02/img/StableEq-general.pdf}\n            \\end{center}\n\\item If the above does not hold true, the equilibrium is \\TC{unstable}.\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Stability}\n\\framesubtitleTC{Asymptotically stable equilibrium}\n\\myPause\n\\begin{itemize}[<+-| alert@+>]\n\\item An equilibrium $\\overline{x}$ corresponding to $\\overline{u}$ is said to be \\TC{asymptotically stable} if\n      \\begin{itemize}[<+-| alert@+>]\n      \\item it is stable,\n      \\item and \\underline{in addition}\n            \\begin{displaymath}\n             \\lim_{k\\rightarrow\\infty} ||x_{\\Delta}(k)-\\overline{x}||=0.\n            \\end{displaymath}\n      \\end{itemize}\n      \\item Graphically,\n            \\begin{center}\n             \\includegraphics[width=0.60\\columnwidth]{./Unit-02/img/AsympStableEq-general.pdf}\n            \\end{center}\n\\item Clearly asymptotic stability implies stability, but not \\emph{vice versa}.\n\\end{itemize}\n\\end{frame}\n\n", "meta": {"hexsha": "5d5ddfc96f2cadf8b6db04aeeeef2b7f4508ff95", "size": 9745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-02/sections/02-DynamicsFormally.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/02-DynamicsFormally.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/02-DynamicsFormally.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.3079710145, "max_line_length": 115, "alphanum_fraction": 0.6353001539, "num_tokens": 3082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6460195428980791}}
{"text": "\n\\subsection{Adaboost}\n\n\\subsubsection{Introduction}\n\nBoosting is a way to create multiple learners for use in an ensemble predictor.\n\nThe goal is to create many predictors, which may not be themselves very accuracte, but have a high degree of independence.\n\n\\subsubsection{AdaBoost}\n\nAdaBoost is a popular algorithm for boosting.\n\nIt works by:\n\n\\begin{itemize}\n\\item Creating a set of weak learners using different restrictions on features in the training data.\n\\item Choosing the weak learner that most reduces the error of the combined learners, and give it a weighting which most reduces the error of the combined learners.\n\\item Creating a new weighting for the dataset, where ones poorly predicted (by the combination of learners) are given high weights.\n\\item Repeating the process a fixed number of times.\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "e5c20c9ae2ce859f134e5519e718a32ca806f59b", "size": 831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ensemble/02-02-boosting.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/ensemble/02-02-boosting.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/ensemble/02-02-boosting.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.24, "max_line_length": 164, "alphanum_fraction": 0.797833935, "num_tokens": 175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6460195405489297}}
{"text": "\\Opensolutionfile{solutions}[ex]\n\\section{Additional exercises}{}{}\n\n\\begin{enumialphparenastyle}\n\nThese problems require the techniques of this chapter, and are in no\nparticular order. Some problems may be done in more than one way.\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int (t+4)^3\\,dt$\n\\begin{sol}\n $\\ds{(t+4)^4\\over4}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int t(t^2-9)^{3/2}\\,dt$\n\\begin{sol}\n $\\ds{(t^2-9)^{5/2}\\over5}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int (e^{t^2}+16)te^{t^2}\\,dt$\n\\begin{sol}\n $\\ds{(e^{t^2}+16)^2\\over 4}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% use addition and subtraction formulas sin(A+B)=sinAcosB+sinBcosA and sin(A-B)=sinAcosB-sinBcosA to solve for sinAcosB and substitute into integral\n $\\ds\\int \\sin t\\cos 2t\\,dt$\n\\begin{sol}\n $\\ds\\cos t-{2\\over3}\\cos^3 t+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int \\tan t\\sec^2t\\,dt$\n\\begin{sol}\n $\\ds{\\tan^2 t\\over 2}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {2t+1\\over t^2+t+3}\\,dt$\n\\begin{sol}\n $\\ds\\ln|t^2+t+3|+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% partial fractions\n $\\ds\\int {1\\over t(t^2-4)}\\,dt$\n\\begin{sol}\n $\\ds {1\\over8} \\ln|1-4/t^2|+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% trig sub x=5sin(theta)\n $\\ds\\int {1\\over (25-t^2)^{3/2}}\\,dt$\n\\begin{sol}\n $\\ds{1\\over25}\\tan(\\arcsin(t/5))+C={t\\over25\\sqrt{25-t^2}}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {\\cos 3t\\over\\sqrt{\\sin3t}}\\,dt$\n\\begin{sol}\n $\\ds{2\\over3}\\sqrt{\\sin 3t}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% integration by parts\n $\\ds\\int t\\sec^2 t\\,dt$\n\\begin{sol}\n $\\ds t\\tan t+\\ln|\\cos t|+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {e^t\\over \\sqrt{e^t+1}}\\,dt$\n\\begin{sol}\n $\\ds 2\\sqrt{e^t+1}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% powers of trigonometric functions [use trig identity cos^2(x)=1/2(1+cos(2x))]\n $\\ds\\int \\cos^4 t\\,dt$\n\\begin{sol}\n $\\ds{3t\\over 8}+{\\sin 2t\\over4}+ {\\sin 4t\\over 32}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% partial fractions\n $\\ds\\int {1\\over t^2+3t}\\,dt$\n\\begin{sol}\n $\\ds{\\ln |t|\\over 3} - {\\ln |t+3|\\over 3}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% trig sub t=tan(theta), then u-substitution\n $\\ds\\int {1\\over t^2\\sqrt{1+t^2}}\\,dt$\n\\begin{sol}\n $\\ds{-1\\over \\sin\\arctan t}+C=-\\sqrt{1+t^2}/t+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {\\sec^2t\\over (1+\\tan t)^3}\\,dt$\n\\begin{sol}\n $\\ds{-1\\over 2(1+\\tan t)^2}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int t^3\\sqrt{t^2+1}\\,dt$\n\\begin{sol}\n $\\ds{(t^2+1)^{5/2}\\over 5}-{(t^2+1)^{3/2}\\over 3}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% integration by parts\n $\\ds\\int e^t\\sin t\\,dt$\n\\begin{sol}\n $\\ds{e^t\\sin t-e^t\\cos t\\over 2}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int (t^{3/2}+47)^3\\sqrt{t}\\,dt$\n\\begin{sol}\n $\\ds{(t^{3/2}+47)^4\\over6}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {t^3\\over (2-t^2)^{5/2}}\\,dt$\n\\begin{sol}\n $\\ds{2\\over 3(2-t^2)^{3/2}}-{1\\over(2-t^2)^{1/2}}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% trig sub x=(3/2)tan(theta), then u-substitution\n $\\ds\\int {1\\over t(9+4t^2)}\\,dt$\n\\begin{sol}\n $\\ds{\\ln|\\sin(\\arctan(2t/3))|\\over9}+C = \n(\\ln(4t^2)-\\ln(9+4t^2))/18 + C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {\\arctan 2t\\over 1+4t^2}\\,dt$\n\\begin{sol}\n $\\ds{(\\arctan(2t))^2\\over4}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% partial fractions\n $\\ds\\int {t\\over t^2+2t-3}\\,dt$\n\\begin{sol}\n $\\ds{3\\ln|t+3|\\over 4}+{\\ln|t-1|\\over4}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% powers of trigonometric functions with u=cos(t)\n $\\ds\\int \\sin^3 t\\cos^4 t\\,dt$\n\\begin{sol}\n $\\ds{\\cos^7 t\\over 7}-{\\cos^5 t\\over 5}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% factoring then simple integration\n $\\ds\\int {1\\over t^2-6t+9}\\,dt$\n\\begin{sol}\n $\\ds{-1\\over t-3}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% u-substitution\n $\\ds\\int {1\\over t(\\ln t)^2}\\,dt$\n\\begin{sol}\n $\\ds{-1\\over \\ln t}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% integration by parts\n $\\ds\\int t(\\ln t)^2\\,dt$\n\\begin{sol}\n $\\ds{t^2(\\ln t)^2\\over 2}-{t^2\\ln t\\over 2}+{t^2\\over4}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% integration by parts\n $\\ds\\int t^3e^{t}\\,dt$\n\\begin{sol}\n $\\ds(t^3-3t^2+6t-6)e^t+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\t% split into two fractions: (2x+1)/(2(x^2+x-1)) + 1/(2(x^2+x-1)). Integrate first by u-sub, and second by trig sub (x+1/2)=(sqrt(5)/2)sec(theta)\n $\\ds\\int {t+1\\over t^2+t-1}\\,dt$\n\\begin{sol}\n $\\ds{5+\\sqrt5\\over10}\n\\ln(2t+1-\\sqrt5)+{5-\\sqrt5\\over10}\\ln(2t+1+\\sqrt5)+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "e1f0dae1ac8c91a6485164bee7c0ed193f8f7ba9", "size": 5067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-8-more-problems.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-8-more-problems.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-8-more-problems.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": 19.2661596958, "max_line_length": 159, "alphanum_fraction": 0.5271363726, "num_tokens": 2296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.6460195399335664}}
{"text": "\\begin{frame}{Finding the autocorrelation}\nTo find the parameters $a_1, \\ldots, a_N$, we need to compute the autocorrelation $r[0], \\ldots, r[N-1]$ from $M+1$ samples of the signal $s[n]$.\n\nTwo methods:\n\\begin{enumerate}\n\t\\item \\textbf{Autocorrelation method}\n\tThis method assumes that the signal $s[n]$ is \\underline{zero outside the interval} $[0, M+1]$. Therefore, for $s[n]$ deterministic we have\n\t\\begin{equation*}\n\tr_{ss}[|m|] = \\sum_{n =0}^{M-|m|}s[n]s[n+|m|], |m| \\leq N-1\n\t\\end{equation*}\n\tThis implies $r_{ss}[m] = 0, |m| > M$.\n\t\\item \\textbf{Covariance method}\n\tThis method assumes that the signal $s[n]$ is \\underline{unknown outside the interval} $[0, M+1]$. Therefore, for $s[n]$ deterministic we have\n\t\\begin{equation*}\n\tr_{ss}[m] = \\sum_{n = N}^{M}s[n]s[n+|m|], m = 0, 1, \\ldots, N-1\n\t\\end{equation*}\t\n\\end{enumerate}\n\\end{frame}\n\n\\begin{frame}{Convolution as a matrix-vector product}\nWe can write a convolution as a matrix-vector product\n\\begin{align*}\ny[n] &= \\sum_{m = 0}^N h_nx[n-m] \\\\\ny &= Xh \\\\\n\\begin{bmatrix}\ny[0] \\\\\ny[1] \\\\\ny[2] \\\\\n\\vdots \\\\ \ny[L-1] \\\\\n\\end{bmatrix}\n&= \\begin{bmatrix}\nx[0] & 0 & \\ldots & 0 \\\\\nx[1] & x[0] & \\ddots & \\vdots \\\\\n\\vdots & x[1] & \\ddots &  0\\\\\nx[L-1] & \\vdots &\\ddots &  x[0]\\\\\n0 & x[L-1] & \\ddots & x[1] \\\\\n\\vdots & \\vdots & \\ddots &  \\vdots \\\\\n0  & 0 & \\ldots & x[L-1] \n\\end{bmatrix}_{L\\times N}\\cdot\\begin{bmatrix}\nh_0 \\\\\nh_1 \\\\\nh_2 \\\\\n\\vdots \\\\ \nh_{N-1} \\\\\n\\end{bmatrix}\n\\end{align*}\n\nThe matrix $X$ is called \\textbf{Toeplitz matrix}.\n\n\\vspace{0.25cm}\nIn Matlab: \\texttt{>> X = toeplitz(c, r)}, where the vector \\texttt{c} is the first column of $X$, and the vector \\texttt{r} is the first row of $X$.\n\n\\end{frame}\n\n\n\\begin{frame}{All-pole model for deterministic signals}\nBack to our problem when $s[n]$ is deterministic:\n\\begin{equation}\n\\sum_{n = 0}^{L-1} |v[n] - \\sum_{m = 0}^N a_ns[n-m]|^2 \\tag{if $s[n]$ is deterministic}\n\\end{equation}\n\nNow we can write this in matrix notation\n\\begin{equation*}\n||v - Sh||^2_2\n\\end{equation*}\n\nThis is a \\textbf{least-squares problem}, and its solutions is \n\\begin{equation}\nh = S^{\\dagger}v \\tag{least-squares solution}\n\\end{equation}\nwhere $S^{\\dagger} = (S^TS)^{-1}S^T$ is the \\textbf{Moore-Penrose pseudo-inverse}.\n\n\\vspace{0.25cm}\nWhen $s[n]$ is deterministic, $v[n]$ is assumed to be an impulse. Hence, $v = [1, 0, \\ldots, 0]^T$.\n\\end{frame}\n\n\n\\begin{frame}{All-pole model for random signals}\nWhen $s[n]$ is random, we want to minimize\n\\begin{equation*}\n\\E\\Big(|v[n] - \\sum_{m = 0}^N a_ns[n-m]|^2\\Big)\n\\end{equation*}\n\n\n\n\\begin{equation*}\n\\E(s[n]v[n]) = \\sum_{m = 0}^N a_n\\E(s[n]s[n-m]), \\quad n = 0, \\ldots, L-1\n\\end{equation*}\n\n\\end{frame}\n\n\n\n%\n\\begin{frame}{Revisiting the Bartlett or triangular window}\n\\begin{columns}\n\t\\begin{column}{0.5\\textwidth}\n\t\t\\textbf{Time}\n\t\t\\begin{equation*}\n\t\tw_B[n] = \\begin{cases}\n\t\t1 - |n|/M, & |n| < M \\\\\n\t\t0, & \\text{otherwise}\n\t\t\\end{cases}\n\t\t\\end{equation*}\n\t\\end{column}\n\t\n\t\\begin{column}{0.5\\textwidth}\n\t\t\\textbf{Frequency}\n\t\t\\begin{equation*}\n\t\tW_B[n] = \\frac{1}{M}\\bigg(\\frac{\\sin(\\omega M/2)}{\\sin(\\omega/2)}\\bigg)^2\n\t\t\\end{equation*}\n\t\\end{column}\n\\end{columns}\n\n\\hspace*{-0.75cm}\\resizebox{0.95\\paperwidth}{!}{\\input{figs/barlett_time_freq.tex}}\n\\end{frame}\n\n\n%\n\\begin{frame}{Design specifications}\nSpecifications of \\textbf{frequency-selective} filters\n\\begin{center}\n\t\\resizebox{0.7\\linewidth}{!}{\\input{figs/design_specs.tex}}\n\\end{center}\n\n\\textbf{Terminology}\n\\begin{itemize}\n\t\\item $\\delta_1$ passband ripple\n\t\\item $\\delta_2$ stopband ripple\n\t\\item $\\omega_p$ passband edge frequency\n\t\\item $\\omega_p$ stopband edge frequency\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Poles, zeros, and the frequency response}\n\n\\textbf{Adding one more zero:} $H(z) = (1 - r_1e^{j\\theta}z^{-1})(1 - r_2e^{j\\psi}z^{-1})$\n\n\\begin{columns}[t]\n\t\\begin{column}{0.7\\textwidth}\n\t\t\\vspace{-0.5cm}\n\t\t\\begin{center}\n\t\t\t\\resizebox{\\linewidth}{!}{\\input{figs/pole_zero_freq_resp_2zeros.tex}}\n\t\t\\end{center}\n\t\\end{column}\n\t\n\t\\begin{column}{0.3\\textwidth}\t\n\t\t\\only<1|handout:1>{\n\t\t\t\\textbf{Magnitude}\n\t\t\t\\flushleft\n\t\t\t\\begin{align*}\n\t\t\tH(z) &= \\frac{z - r_1e^{j\\theta}}{z}\\cdot\\frac{z - r_2e^{j\\psi}}{z} \\\\\n\t\t\t|H(e^{j\\omega})| &= \\bigg|\\frac{{\\color{red2} v_1} - {\\color{black} v_2}}{{\\color{red2} v_1}}\\bigg|\\bigg|\\frac{{\\color{red2} v_1} - {\\color{black} v_4}}{{\\color{red2} v_1}}\\bigg|\\\\\n\t\t\t&= \\frac{||{\\color{blue2} v_3}||}{||{\\color{red2} v_1}||}\\frac{||{\\color{green2} v_5}||}{||{\\color{red2} v_1}||} \\\\\n\t\t\t&= ||{\\color{blue2} v_3}||||{\\color{green2} v_5}||\n\t\t\t\\end{align*}\n\t\t}\n\t\t\n\t\t\\only<2|handout:2>{\n\t\t\t\\textbf{Phase}\n\t\t\t\\flushleft\n\t\t\t\\begin{align*}\n\t\t\tH(z) &= \\frac{z - r_1e^{j\\theta}}{z}\\cdot\\frac{z - r_2e^{j\\psi}}{z} \\\\\n\t\t\t\\angle H(e^{j\\omega})  &= \\angle\\frac{{\\color{red2} v_1} - {\\color{black} v_2}}{{\\color{red2} v_1}} + \\angle\\frac{{\\color{red2} v_1} - {\\color{black} v_4}}{{\\color{red2} v_1}}\\\\\n\t\t\t&= \\angle {\\color{blue2} v_3} + \\angle {\\color{green2} v_5} - 2\\omega\n\t\t\t\\end{align*}\n\t\t}\n\t\\end{column}\n\\end{columns}\n\n\\only<1|handout:1>{\\textbf{Conclusion:} As $e^{j\\omega}$ approaches a zero, $|H(e^{j\\omega})| \\to 0$}\n\\only<2|handout:2>{\\textbf{Conclusion:} A zero causes a negative to positive phase change of the phase response (\\textbf{phase advance})}\n\\end{frame}\n\n\n\n%\n\\begin{frame}{The unilateral $z$-transform}\n\nThe bilateral $z$-transform we've seen so far does not account for initial conditions.\n\n\\begin{block}{The unilateral $z$-transform}\n\t\\begin{equation*} \\tag{Direct transform}\n\tX^+(z) = \\sum_{\\tikz[baseline]{\n\t\t\t\\node[fill=blue!20,anchor=base] (t1) {$n = 0$};\n\t}}^{\\infty} x[n]z^{-n} \n\t\\end{equation*}\n\\end{block}\n\n\\begin{itemize}\n\t\\item For causal signals, $X(z) = X^+(z)$. \\\\\n\t\\item For any signal $y[n] \\Longleftrightarrow Y(z)$, we have $y[n]u[n] \\Longleftrightarrow Y^+(z)$. \\\\\n\t\\item As the unilateral $z$-transform only takes into account the causal part of the signal, the ROC will always the exterior of a circle (ROC = $\\{|z|>|r|\\}$). Hence, there's no ambiguity.\n\\end{itemize}\n\n\\end{frame}\n\n\\subsection{Sampling and reconstruction}\n%\n\\begin{frame}{Families of $z$-transforms}\t\n\\begin{block}{Finite-length sequences}\n\tWhen $A(z) = 1$, we're left with $z$-transforms of the form\n\t\\begin{align*}\n\tX(z) = b_0 + b_1z^{-1}+\\ldots+b_Mz^{-M}\n\t\\end{align*}\n\t\\begin{itemize}\n\t\t\\item These correspond to finite-length sequences or systems with \\textbf{finite impulse response (FIR)}\n\t\t\\item In this case, we have $M$ zeros, which are the roots of $X(z)$, and we have $M$ poles at $z = 0$. As a result, the ROC is the entire $z$-plane with the exception of $z = 0$, and possible poles at infinity i.e., $X(p = \\infty) = \\infty$.\n\t\t\\item Since finite-length sequences are always absolute summable, the ROC of their $z$-trasnform is the entire $z$ plan, with the exception of $z = 0$ or $z = \\infty$ (the poles).\n\t\\end{itemize}\t\n\\end{block}\n\n\\end{frame}\n\n%\n\\begin{frame}{Obtaining frequency response from difference equation}\n\t\n\t\\begin{block}{Difference equation}\n\t\t\\begin{equation*}\n\t\t\\sum_{k=0}^N a_k y[n-k] = \\sum_{k=0}^Mb_k x[n-k]\n\t\t\\end{equation*}\n\t\\end{block}\n\t\n\tUsing the linearity and time shift properties of the DTFT it follows that\n\t\n\t\\begin{align*}\n\t\\sum_{k=0}^N a_kY(e^{j\\omega})e^{-j\\omega k} = \\sum_{k=0}^M b_kX(e^{j\\omega})e^{-j\\omega k} \\\\\n\tH(e^{j\\omega}) = \\frac{Y(e^{j\\omega})}{X(e^{j\\omega})} = \\frac{\\sum_{k=0}^M b_ke^{-j\\omega k}}{\\sum_{k=0}^N a_ke^{-j\\omega k}}\n\t\\end{align*}\n\\end{frame}\n\n\n%%%%%%% Discrete Fourier Transform\n\n", "meta": {"hexsha": "e57dbe68198ab6c3a0d18bb4748562ceb536c028", "size": 7409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/draft.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/draft.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/draft.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": 31.3940677966, "max_line_length": 244, "alphanum_fraction": 0.6412471319, "num_tokens": 2930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6458633113385933}}
{"text": "Radio interferometry is the technique of combining the response of multiple telescopes to detect radiation from astronomical sources. One of the main advantages of this technique is the resolution power of an interferometer. The angular resolution of any optical instrument can be approximated as~$\\theta \\sim \\frac{\\lambda}{D}$. So for any given wavelength of observation, $\\lambda $, we obtain higher resolution by increasing the size of the aperture of the observing instrument,~$D$. However, this will eventually be limited by engineering constraints to~$\\sim $100~metres for fully--steerable radio telescopes. With an interferometer,~$D$, is the separation \\emph{between} the radio telescopes and can be as large as hundreds or even thousands of kilometres. In the following derivation, I will be providing a broad overview of the main concepts that interferometry is based upon.\n\n\\begin{figure}\n  \\centering\n    \\includegraphics[width=\\textwidth ]{tms-figure.eps}\n  \\caption[]{A schematic diagram of interferometry showing the same electromagnetic plane wave~(the dotted line \\textbf{-}\\textbf{-}\\textbf{-}\\textbf{-}\\textbf{-}\\textbf{-}) from an astronomical source, in the direction,~$\\mathbf{\\hat{s}}$, incident upon antennas~$V_1$~and $V_2$. The angle~$\\theta $ corresponds to the direction of~$\\mathbf{\\hat{s}}$ and gives rise to the different times at which this wave arrives at~$V_1$~and $V_2$. This time difference is given as~$\\mathbf{\\tau _g}$ corresponding to a distance of~$\\mathbf{c\\msp \\tau_ g}$. The antennas $V_1$~and $V_2$ are separated along the baseline vector~$\\vec{\\mathbf{b}}$.\\\\ \\emph{Image credit:} Interferometry and Synthesis in Radio Astronomy~(Thomson, Moran and Swenson,~2017) used under the Creative Commons Attribution International License (\\texttt{http://creativecommons.org/licenses/by-nc/4.0/}). The bold, black lines and text have been added by me.}\n  \\label{fig:tms-figure}\n\\end{figure}\n\n\\section{Electromagnetic waves incident on an array}\nThe overall scheme of radio interferometry is represented in Figure~\\ref{fig:tms-figure}. The incoming radiation from a natural astronomical source~\\textbf{S} can be considered as a noise signal. Over a small time,~$\\delta t$, the radiation can be considered to be sinusoidal. Such an oscillating electromagnetic wave with \\emph{quasi--monochromatic} frequency,~$\\nu $, can be described as\n\n\\begin{eqnarray}\n  \\label{eq:1}\n  E(t) &=& A \\msp cos(2\\pi \\msp \\nu t + \\Phi) \\nonumber \\\\\n       &=& A \\msp cos(\\omega t + \\Phi) \\msp , \\hspace{0.8cm} \\mbox{where} \\enspace \\omega = \\frac{2\\pi}{T} = 2\\pi \\nu\n\\end{eqnarray}\n\nOur aim is to mathematically determine the relationship which will ensure that we are measuring the same wavefront of~$E(t)$ which is incident upon antennas~$V_1$ and~$V_2$. We do this by determining the \\emph{geometric delay}~$\\tau _g$, which is the time difference between the plane wave arriving at~$V_1$ and~$V_2$.\n\n\\begin{eqnarray}\n  \\label{eq:2}\n  \\tau _g &=& \\frac{\\mbox{Distance of the projection of $\\vec{\\mathbf{b}}$ in the direction of $\\mathbf{\\hat{s}}$}}{\\mbox{Speed of light}} \\nonumber \\\\\n          &=& \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c}\n\\end{eqnarray}\n\nIn Equation~\\eqref{eq:2},~$\\mathbf{\\hat{s}}$ is a unit vector but~$\\vec{\\mathbf{b}}$ is not. This is because we do not know the distance to the source,~\\textbf{S}. Having obtained an expression for~$\\tau _g$, we can represent the electromagnetic radiation incident at the antennas as\n\n\\begin{eqnarray}\n  \\label{eq:3}\n  \\begin{aligned}\n  V_1 &=& |V_1| \\msp cos\\big (\\omega \\msp (t - \\tau _g)\\big ) \\\\\n  V_2 &=& |V_2| \\msp cos(\\omega t)\n  \\end{aligned}\n\\end{eqnarray}\n\n\\section{Correlation of a point source}\nIn signal processing \\emph{cross--correlation} is the measure of similarity between two series which are offset from each other. In our system described in Equation~\\eqref{eq:3} this offset is~$\\omega \\tau _g$.\n\nWe define the cross--correlation of the outputs of antennas~$V_1$ and~$V_2$ as~$<V_1V_2> = \\frac{1}{T} \\int _0^T V_1 \\msp V_2 \\msp dt$. It can be thought of as an \\emph{averaging process} because you are integrating~(adding) over a certain duration and then dividing by the length of that duration.\n\n% &=& \\frac{1}{T} \\int _0^T\n\n\\begin{eqnarray}\n  \\label{eq:4}\n  <V_1V_2> &=& \\frac{1}{T} \\int _0^T V_1 \\msp V_2 \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T}       \\int _0^T |V_1| \\msp cos(\\omega \\msp (t - \\tau _g)) \\enspace |V_2| \\msp cos(\\omega t) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos  \\big (\\omega \\msp (t - \\tau _g) + \\omega t \\big) + sin  \\big (\\omega \\msp (t - \\tau _g)\\big) \\msp sin(\\omega t) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos(2\\omega t - \\omega \\tau _g) - cos  \\big (\\omega (t - \\tau _g) \\big) \\msp cos(\\omega t) + cos  \\big (\\omega \\msp (t - \\tau _g) - \\omega t \\big) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos(2\\omega t - \\omega \\tau _g) - cos  \\big (\\omega (t - \\tau _g) \\big) \\msp cos(\\omega t) + cos(-\\omega \\tau _g) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos(2\\omega t - \\omega \\tau _g) - cos  \\big (\\omega (t - \\tau _g) \\big) \\msp cos(\\omega t) + cos(\\omega \\tau _g) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos(\\omega \\tau _g) + cos(2\\omega t - \\omega \\tau _g) - cos  \\big (\\omega (t - \\tau _g) \\big) \\msp cos(\\omega t) \\msp d\\,t \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\Bigg [ \\int _0^T cos(\\omega \\tau _g) \\msp dt + \\int _0^T cos(2\\omega t - \\omega \\tau _g) - cos  \\big (\\omega (t - \\tau _g) \\big) \\msp cos(\\omega t) \\msp d\\,t \\Bigg ] \\nonumber\n\\end{eqnarray}\n\nIn the last step, we have grouped the terms which depend on~$t$ in a single integral. In doing so we are attempting to make use of the following property: Over some sufficient duration of~$t \\in \\msp [\\msp 0,~T\\msp ]$, there will be sufficient complete cycles of the trigonometrical terms which depend on~$t$ for the result to average to~0 when integrating over~$d\\,t$.\\\\\n\n\\begin{braced}\n  Try integrating~$\\int _0^{2\\pi} sin(t) \\msp dt $ or~$\\int _0^{2\\pi} cos(t) \\msp dt $ to get an idea why this happens over complete trigonometric cycles.\n\\end{braced}\n\n\\begin{eqnarray}\n  \\label{eq:5}\n  \\implies \\qquad <V_1V_2> &=& \\frac{1}{T} |V_1V_2| \\Bigg [\\int _0^T cos(\\omega \\tau _g) \\msp dt + 0 \\Bigg ] \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\enspace cos(\\omega \\tau _g) \\msp \\int _0^T 1 \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\enspace cos(\\omega \\tau _g) \\msp \\big[\\msp t \\msp \\big]_0^T \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\enspace cos(\\omega \\tau _g) \\enspace T \\nonumber \\\\\n           &=& |V_1V_2| \\enspace cos(\\omega \\tau _g)\n\\end{eqnarray}\n\nIn radio interferometry this process happens in the \\emph{correlator}. The term~$|V_1V_2|$ is a multiplication of voltages which is proportional to power~(Ohm's Law: $P \\propto V\\mathcal{I} = V\\frac{V}{R} = \\frac{V^2}{R}$). I shall refer to~$|V_1V_2|$ as the intensity,~$I$, of the source which is the power per unit area.\n\n\\begin{eqnarray}\n  \\label{eq:6}\n  \\therefore \\mbox{Correlator response,} \\enspace R_c &=& <V_1V_2> \\nonumber \\\\\n                                                      &=& I \\enspace cos(\\omega \\tau _g)\n\\end{eqnarray}\n\nThe correlator response,~$R_c$, is a function of~$\\omega $ and~$\\tau _g$. In practice~$\\tau _g$ is difficult to time directly. So our aim now is to represent~$\\tau _g$ in terms of quantities which we can measure easily, like:\n\n\\begin{enumerate}\n  \\itemsep-0.5cm\n\\item the baseline length~--~which \\textbf{we} can measure from one antenna to another \\\\\n\\item the observation wavelength~--~dependant on the frequency range of the receivers \\textbf{we} build \\\\\n\\item the position of the source in the sky~--~which is where \\textbf{we} point the interferometer\n\\end{enumerate}\n\nIn expanding~$\\tau _g$ in~$R_c$ we get\n\n\\begin{eqnarray}\n  \\label{eq:7}\n  R_c &=& I \\msp cos(\\omega \\tau _g) \\nonumber \\\\\n      &=& I \\msp cos\\Big (2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot } \\mathbf{\\hat{s}}}{c}\\Big ) \\nonumber \\\\\n      &=& I \\msp cos\\Big (2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot } \\mathbf{\\hat{s}}}{\\nu \\msp \\lambda}\\Big ) \\nonumber \\\\\n      &=& I \\msp cos\\Bigg (2\\pi \\msp \\frac{|b|\\msp cos(\\frac{\\pi }{2} - \\theta)}{\\lambda}\\Bigg ) , \\hspace{0.8cm} \\mbox{see Figure~\\ref{fig:tms-figure}} \\nonumber \\\\\n      &=& I \\msp cos\\Big (2\\pi \\msp \\frac{|b| \\msp sin \\theta}{\\lambda} \\Big) \\nonumber \\\\\n      &=& I \\msp cos(2\\pi \\msp u \\msp l) \\msp , \\hspace{0.8cm} \\mbox{where} \\enspace u = \\frac{|b|}{\\lambda}, \\enspace l = sin \\theta\n\\end{eqnarray}\n\nInstead of using traditional units of distance, such as the meter, in interferometry it is more convenient to represent the baseline length in units of our observation frequency's corresponding wavelength, i.e.~$u = \\frac{|b|}{\\lambda}$.\n\n\\subsection{Visualising the correlator output}\n\nWe can graphically visualise the correlator output~$R_c$ by sketching the trigonometrical function~$R_c = I \\msp cos(2\\pi \\msp u \\msp l)$. The range of the cosine function~$R_c \\in [-I, \\msp I]$ for all values of~$u$ and~$l$. For this example let the baseline be~3~wavelengths long~$\\implies u = \\frac{|b|}{\\lambda} = 3$ and our field--of--view extend from horizon--to--horizon~$\\implies -\\frac{\\pi}{2} \\leq \\theta \\leq \\frac{\\pi}{2}$.\n\n\\begin{eqnarray}\n  \\label{eq:8}\n            \\mbox{Maxima when} \\qquad R_c &=& I           \\nonumber \\\\\n                  cos(2\\pi \\msp u \\msp l) &=& 1           \\nonumber \\\\\n  \\therefore \\enspace 2\\pi \\msp u \\msp l  &=& 2n \\msp \\pi \\nonumber \\\\\n       \\frac{|b|}{\\lambda} \\msp sin\\theta &=& n           \\nonumber \\\\\n                                   \\theta &=& sin^{-1}\\Big(\\frac{n}{3}\\Big) \\msp , \\hspace{0.8cm} \\mbox{where} \\enspace n \\in \\mathbb{Z}, \\enspace |n| \\leq 3 \\nonumber \\\\\n                                                 \\nonumber \\\\\n            \\mbox{Minima when} \\qquad R_c &=& -I \\nonumber \\\\\n                  cos(2\\pi \\msp u \\msp l) &=& -1 \\nonumber \\\\\n   \\therefore \\enspace 2\\pi \\msp u \\msp l &=& (2n+1) \\msp \\pi \\nonumber \\\\\n       \\frac{|b|}{\\lambda} \\msp sin\\theta &=& \\frac{2n+1}{2} \\nonumber \\\\\n                                   \\theta &=& sin^{-1}\\Bigg(\\frac{2n+1}{3 \\msp (2)}\\Bigg) \\msp , \\hspace{0.8cm} \\mbox{where} \\enspace n \\in \\mathbb{Z}, \\enspace -3 \\leq n < 3 \\nonumber\n\\end{eqnarray}\n\n\\begin{table}\n  \\centering\n\\begin{tabular}{rrr}\n  n & Maxima         & Minima         \\\\\n  \\hline\n  $-$3 & $-$90.0$^\\circ$ & $-$56.4$^\\circ$ \\\\\n  $-$2 & $-$41.8$^\\circ$ & $-$30.0$^\\circ$ \\\\\n  $-$1 & $-$19.5$^\\circ$ &  $-$9.6$^\\circ$ \\\\\n     0 &     0.0$^\\circ$ &     9.6$^\\circ$ \\\\\n     1 &    19.5$^\\circ$ &    30.0$^\\circ$ \\\\\n     2 &    41.8$^\\circ$ &    56.4$^\\circ$ \\\\\n     3 &    90.0$^\\circ$ &                \\\\\n  \\hline\n\\end{tabular}\n\\caption[]{Maxima and minima of~$R_c$ when~$u = \\frac{|b|}{\\lambda} = 3$.}\n\\label{tab:max-min}\n\\end{table}\n\n%%BoundingBox: -30 210 600 684\n\\begin{figure}\n  \\centering\n    \\includegraphics[width=\\textwidth ]{01-corr-resp.eps}\n  \\caption[]{The correlator response,~$R_c$ in rectangular~(top) coordinates. The maxima and minima of~$R_c$ are stated in Table~\\ref{tab:max-min}. The polar plot~(bottom left) shows what the fringes look like from horizon--to--horizon. The previous two plots resemble the response of a di--pole baseline. In contrast, the polar plot~(bottom right) resembles what you might expect from an interferometer like MeerKAT where there is a dominant central fringe and diminished sidelobes.}\n  \\label{fig:corr-resp}\n\\end{figure}\n\nI show the maxima, minima of~$R_c$ in Table~\\ref{tab:max-min}, and the corresponding curve in Figure~\\ref{fig:corr-resp}. This curve is known as the interferometer's \\emph{fringe pattern}, and you can think of it as the pattern which governs regions of the interferometer's sensitivity to the sky. In our example this would be the pattern for a dipole array. For interferometers such as MeerKAT, the fringes are shaped by the receivers such that the central lobe dominates. You can use \\texttt{01-corr-resp.py} to determine the maxima, minima and fringe patterns for arbitrary values of~$u$ and~$l$.\n\nAt this point we can see why the interferometer's resolution power, which I described at the beginning as~$\\theta \\sim \\frac{\\lambda}{D}$ is what it is. We can do this by considering the separation of one maxima to the next in\n\n\\begin{eqnarray}\n  \\label{eq:10}\n  \\theta _{n+1} - \\theta _n &=& sin^{-1}\\Big(\\frac{n+1}{u}\\Big) - sin^{-1}\\Big(\\frac{n}{u}\\Big) \\nonumber \\\\\n                           &\\sim & \\Big(\\frac{n+1}{u}\\Big) - \\Big(\\frac{n}{u}\\Big) \\msp , \\hspace{0.8cm} \\mbox{using the small angle approximation} \\nonumber \\\\\n                           &=& \\frac{1}{u}       \\nonumber \\\\\n                           &=& \\frac{\\lambda}{b} \\nonumber\n\\end{eqnarray}\n\n% *** Also note that because |sin \\theta| < 1, the number of lobes, %which is determined by n is < \\frac{b}{\\lambda}.\n\n\\section{Correlation of a non--point (finite) source}\n\\label{osec:Correlation-of-a-non-point-source}\nUp to this point, we have considered the correlation of a point source. However, a real astronomical source occupies a~2\\,D region on the \\emph{celestial sphere}\\footnote{The celestial sphere is an imaginary sphere which is concentric to Earth.}. For such an extended source we need to sum each of the antenna responses~--~$V_1$ and~$V_2$~--~~over a~2\\,D solid angle region,~$d\\,\\Omega $, in the sky.\n\n\\begin{eqnarray}\n  \\label{eq:9}\n  \\therefore \\enspace <V_1V_2> &=& \\Big \\langle \\iint V_1 \\msp d\\,\\Omega \\iint V_2 \\msp d\\,\\Omega \\Big \\rangle \\nonumber\n\\end{eqnarray}\n\nIf \\underline{and only if} the emission is \\emph{spatially incoherent} then\n\n\\begin{eqnarray}\n  \\label{eq:19}\n  \\enspace <V_1V_2> &=& \\Big \\langle \\iint V_1V_2 \\msp d\\,\\Omega \\Big \\rangle \\nonumber\n\\end{eqnarray}\n\n\\begin{braced}\n  Spatial incoherence is required as in general~$\\enspace \\int g(x) \\msp h(x) \\msp d\\,x \\quad \\neq \\quad \\int g(x) \\msp d\\,x \\times \\int h(x) \\msp d\\,x$.\\\\\n  Typically we need to use \\emph{integration by parts} in these cases.\\\\ For example try to integrate~$\\quad \\int x \\msp cos(x) \\msp d\\,x \\quad $ v.s.~$\\quad \\int x \\msp d\\,x \\times \\int cos(x) \\msp d\\,x$.\n\\end{braced}\n\n\\begin{eqnarray}\n  \\label{eq:11}\n    &=& \\frac{1}{T} \\int _0 ^T \\iint V_1 V_2 \\msp d\\,\\Omega \\enspace d\\,t \\nonumber \\\\\n    &=& \\iint \\frac{1}{T} \\int _0 ^T V_1 V_2 \\msp d\\,t \\enspace d\\,\\Omega \\nonumber \\\\\n    &=& \\iint I \\msp cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega\n    % &=& \\iint I_\\nu (\\hat{s}) \\msp cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega\n    % &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{b} \\cdot \\hat{s}}{c}} \\msp d\\,\\Omega \\nonumber\n\\end{eqnarray}\n\nNote that the~$cos(2\\pi \\msp u \\msp l)$ term in Equation~\\eqref{eq:11} has a deficiency since the~$cos$ function is an \\emph{even} function and is therefore only sensitive to the even component of the signal. We also need a way to detect/measure/sample the \\emph{odd} component. This is because, for some general function\n\n\\begin{eqnarray}\n  \\label{eq:12}\n  I(x) &=& I_{\\mbox{\\scriptsize even}}(x) + I_{\\mbox{\\scriptsize odd}}(x) \\msp , \\hspace{0.8cm} \\mbox{for} -k \\leq x \\leq k \\nonumber\n\\end{eqnarray}\n\nThe odd and even components have the property that\n\n\\begin{eqnarray}\n  \\label{eq:13}\n  I_{\\mbox{\\scriptsize even}}(-x) &=& -I_{\\mbox{\\scriptsize even}}(x) \\nonumber \\\\\n  I_{\\mbox{\\scriptsize odd}}(-x)  &=&  I_{\\mbox{\\scriptsize odd}}(x) \\nonumber \\\\\n                                                              \\nonumber \\\\\n      \\mbox{Giving} \\qquad R_c &=& \\iint I \\msp cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega \\nonumber \\\\\n                               &=& \\iint \\Big (I_{\\mbox{\\scriptsize even}} +  I_{\\mbox{\\scriptsize odd}} \\Big ) \\msp cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega \\nonumber \\\\\n                               &=& \\iint I_{\\mbox{\\scriptsize even}} \\enspace cos(2\\pi \\msp u \\msp l) + I_{\\mbox{\\scriptsize odd}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega \\nonumber \\\\\n                               &=& \\iint I_{\\mbox{\\scriptsize even}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega + \\iint I_{\\mbox{\\scriptsize odd}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega \\nonumber \\\\\n                               &=& \\iint I_{\\mbox{\\scriptsize even}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega + \\iint 0 \\msp d\\,\\Omega \\nonumber \\\\\n                               &=& \\iint I_{\\mbox{\\scriptsize even}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega \\nonumber\n\\end{eqnarray}\n\n\\begin{braced}\n To see why~$\\iint I_{\\mbox{\\scriptsize even}} \\enspace cos(2\\pi \\msp u \\msp l) \\msp d\\,\\Omega = 0$, try integrating $\\int_{0}^{2\\pi }cos(x)\\msp cos(x) \\msp d\\,x$ v.s. $\\int_{0}^{2\\pi }sin(x)\\msp cos(x) \\msp d\\,x$ or $\\int_{-1}^{1}|x| \\msp cos(x) \\msp d\\,x$ v.s. $\\int_{-1}^{1} x \\msp cos(x) \\msp d\\,x$.\\\\\n\\end{braced}\n\n\\subsection{Odd and Even Components of the Correlator Output}\nSo, if we wish to keep the odd component of the emission, we need to sample the~$sin$ component, which can be accomplished by generating a~90$^\\circ $ phase shift in one of the signal paths from the pair of Equation~\\eqref{eq:3}\n\n\\begin{eqnarray}\n  \\label{eq:14}\n  \\begin{aligned}\n  V_1 &=& |V_1| \\msp cos\\big (\\omega \\msp (t - \\tau _g)\\big ) \\\\\n  V_2 &=& |V_2| \\msp cos\\big (\\omega t - \\frac{\\pi }{2}\\big )\n  \\end{aligned}\n\\end{eqnarray}\n\nIn cross--correlating these antenna outputs~(as we did to obtain Equation~\\eqref{eq:4})\n\n\\begin{eqnarray}\n  \\label{eq:15}\n  <V_1V_2> &=& \\frac{1}{T} \\int _0^T V_1 \\msp V_2 \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T}       \\int _0^T |V_1| \\msp cos(\\omega \\msp (t - \\tau _g)) \\enspace |V_2| \\msp cos \\big (\\omega t - \\frac{\\pi }{2} \\big ) \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos  \\big (\\omega \\msp (t - \\tau _g) + \\omega t - \\frac{\\pi }{2}\\big) + sin \\big (\\omega \\msp (t - \\tau _g) \\big) \\msp sin(\\omega t - \\frac{\\pi }{2} \\big ) \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos \\big (2\\omega t - \\omega \\tau _g - \\frac{\\pi }{2} \\big ) - cos \\big (\\omega (t - \\tau _g) \\big) \\msp cos \\big (\\omega t  -\\frac{\\pi }{2} \\big ) + \\dotso \\nonumber \\\\\n           && \\dotso \\enspace cos \\Big [\\omega \\msp (t - \\tau _g) - \\big (\\omega t - \\frac{\\pi }{2} \\big ) \\Big ] \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\int _0^T cos \\big (2\\omega t - \\omega \\tau _g - \\frac{\\pi }{2} \\big ) - cos \\big (\\omega (t - \\tau _g) \\big) \\msp cos \\big (\\omega t  -\\frac{\\pi }{2} \\big ) + cos \\big (\\omega \\tau _g - \\frac{\\pi }{2} \\big ) \\msp dt \\nonumber \\\\\n           &=& \\frac{1}{T} |V_1V_2| \\Bigg [\\int _0^T cos \\big (\\omega \\tau _g - \\frac{\\pi }{2} \\big ) \\msp dt + \\dotso \\nonumber \\\\\n           && \\dotso \\enspace \\int _0^T cos \\big (2\\omega t - \\omega \\tau _g - \\frac{\\pi }{2} \\big ) - cos \\big (\\omega (t - \\tau _g) \\big) \\msp cos \\big (\\omega t  -\\frac{\\pi }{2} \\big ) \\msp dt \\Bigg ] \\nonumber\n\\end{eqnarray}\n\nAgain we have the rapidly varying terms averaging to~0 and we substitute~$I$ for~$|V_1V_2|$.\n\n\\begin{eqnarray}\n  \\label{eq:16}\n  \\implies \\qquad <V_1V_2> &=& \\frac{1}{T} \\msp I \\Bigg [\\int _0^T cos \\big ( \\omega \\tau _g - \\frac{\\pi }{2}\\big ) \\msp dt + 0 \\Bigg ] \\nonumber \\\\\n                           &=& I \\msp cos \\big ( \\omega \\tau _g - \\frac{\\pi }{2}\\big )\\nonumber \\\\\n                           &=& I \\msp \\Big [cos(\\omega \\tau _g) \\msp cos \\big ( \\frac{\\pi }{2}\\big ) + sin(\\omega \\tau _g) \\msp sin \\big ( \\frac{\\pi }{2}\\big ) \\Big ] \\nonumber \\\\\n                           &=& I \\msp sin(\\omega \\tau _g) \\nonumber \\\\\n                                                          \\nonumber \\\\\n   \\therefore \\enspace R_s &=& I \\msp sin(\\omega \\tau _g) \\nonumber\n\\end{eqnarray}\n\nThe next natural step is to define a complex function in terms of the~$sin$ and~$cos$ components of the correlator output.\n\n\\begin{eqnarray}\n  \\label{eq:17}\n  \\therefore \\enspace <V_1V_2> &=& R_c - i \\msp R_s \\msp , \\hspace{0.8cm} \\mbox{where} \\enspace i = \\sqrt{-1} \\nonumber \\\\\n                               &=& I \\msp cos(\\omega \\tau _g) - i \\msp I \\msp sin(\\omega \\tau _g) \\nonumber \\\\\n                               &=& I \\msp e^{-i\\msp \\omega \\tau _g} \\nonumber \\\\\n                               &=& I \\msp e^{-i\\msp 2\\pi \\msp u \\msp l}, \\hspace{0.8cm} \\mbox{see Equation~\\eqref{eq:7} for converting } \\omega \\tau _g \\mbox{ to } 2\\pi \\, u \\, l \\nonumber\n\\end{eqnarray}\n\n\\begin{braced}\n  We use~$R_c - i \\msp R_s$ instead of~$R_c + i \\msp R_s$ to maintain the convention of the Fourier Transform relationship which will be revealed in Equation~\\eqref{eq:24}.\n\\end{braced}\n\\vspace{0.5cm}\n\nIn conjunction with Equation~\\eqref{eq:11} the correlator output is now called the \\emph{complex visibility} and is given by\n\n\\begin{eqnarray}\n  \\label{eq:21}\n  \\begin{aligned}\n  \\mathcal{V}(\\vec{b}) &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c}} \\msp d\\,\\Omega \\\\\n                       &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\msp u \\msp l} \\msp d\\,\\Omega\n  \\end{aligned}\n\\end{eqnarray}\n\nI have replaced~$I$ with,~$I_\\nu (\\hat{s})$ which is now the source brightness intensity at observing frequency~$\\nu $ and in the direction~$\\hat{s}$. At this stage, we are beginning to link something that we can measure, $\\mathcal{V}(\\vec{b}) = <V_1V_2>$, with something that we want to obtain,~$I_\\nu (\\hat{s})$.\n\n% \\begin{figure}\n%   \\centering\n%   \\includegraphics[width=\\textwidth ]{02-vis-plot.eps}\n%   \\caption[]{The complex correlator response,~$\\mathcal{V}$, showing both the~$cos$~(as in Figure~\\ref{fig:corr-resp}) and~$sin$ components. Here the correlator is sampling a source with a \\emph{Gaussian} power profile~$I = I_\\nu (l) = e^{-l^2 }$ shown by the blue envelop.}\n%   \\label{fig:02-vis-plot}\n% \\end{figure}\n% I give you an example of what the complex visibility might look like in Figure~\\ref{fig:02-vis-plot}. Use~\\texttt{02-vis-plot.py} to determine the fringe patterns for arbitrary values of~$u$ and~$l$.\n\n\\subsection{Visualising the result}\n\\label{sec:visualising-result}\n\nAgain, let's try to get an intuitive feel for what~$\\mathcal{V}(\\vec{b})$ is. In the following example, consider the simplest possible case where we have a~1\\,D baseline such that~$\\mathcal{V}(\\vec{b}) = \\mathcal{V}(u)$ which samples the source intensity along~1\\,D such that~$I_\\nu (\\hat{s}) = I_\\nu (l)$. $d\\,\\Omega $ now reduces to~$d\\, l$. Furthermore, let us assume that the source intensity can be modelled as a~\\emph{Dirac $\\delta $--function} $\\implies I_\\nu (l) = \\delta(l - l_0)$. $\\mathcal{V}(\\vec{b})$ can now be expressed as\n\n\\begin{eqnarray}\n  \\label{eq:25}\n  \\mathcal{V}(u) &=& \\int \\delta(l - l_0) \\msp e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l \\nonumber \\\\\n                 &=& \\int \\delta(l - l_0) \\msp e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l \\Bigg \\rvert_{\\msp l \\msp < \\msp l_0} + \\int \\delta(l - l_0) \\msp e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l \\Bigg \\rvert_{\\msp l \\msp = \\msp l_0} + \\int \\delta(l - l_0) \\msp e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l \\Bigg \\rvert_{\\msp l \\msp > \\msp l_0} \\nonumber \\\\\n                                   &=& \\int 0 \\times e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l + \\int \\delta(0) \\msp e^{-i \\msp 2\\pi \\msp u \\msp l_0} \\msp d\\,l + \\int 0 \\times e^{-i \\msp 2\\pi \\msp u \\msp l} \\msp d\\,l \\nonumber \\\\\n                                   &=& e^{-i \\msp 2\\pi \\msp u \\msp l_0} \\msp \\int \\delta(0) \\msp d\\,l \\nonumber \\\\\n                                   &=& e^{-i \\msp 2\\pi \\msp u \\msp l_0} \\msp \\big [1\\big ] \\nonumber \\\\\n                                   &=& cos(2\\pi \\msp u \\msp l_0) - i \\msp sin(2\\pi \\msp u \\msp l_0) \\nonumber\n\\end{eqnarray}\n\nThis means that the output of the correlator,~$\\mathcal{V}(u)$, is just a complex number. In Figure~\\ref{fig:03-dirac-vis}, we see~$\\mathcal{V}(u)$ displayed in both trigonometrical form~(middle column) and amplitude \\&~phase form~(right column), where the~$\\mbox{amplitude} = \\sqrt{cos^2 \\msp (2\\pi \\msp u \\msp l_0) - \\msp sin^2 \\msp (2\\pi \\msp u \\msp l_0)} \\msp = \\msp 1$ and the~$\\mbox{phase} = tan^{-1} \\msp \\Big [-\\frac{sin(2\\pi \\msp u \\msp l_0)}{cos(2\\pi \\msp u \\msp l_0)} \\Big ]$.\n\nIn Figure~\\ref{fig:04-gauss-vis}, we add a level of complexity by replacing the~$I_\\nu (l)$ in Equation~\\eqref{eq:21} with a Gaussian function instead. Both these figures can be replicated using \\texttt{03-dirac-vis.py} and \\texttt{04-gauss-vis.py} for arbitrary source offsets, as well as source width for the latter case.\n\n%% BoundingBox: 5 20 620 780 for fig = plt.figure(figsize=(10, 12))\n\\begin{figure}[]\n  \\centering\n    \\includegraphics[width=\\textwidth ]{03-dirac-vis.eps}\n  \\caption{The output from the correlator,~$\\mathcal{V}$ is always a complex number. Here we see~$\\mathcal{V}$ in trigonometric~(middle column) and amplitude \\&~phase~(right column) for the simplest case where~$\\mathcal{V}(\\vec{b}) = \\mathcal{V}(u)$ and a source~$I_\\nu (\\hat{s}) = I_\\nu (l) = \\delta(l - l_0)$, which is offset from the phase centre by~$l \\msp = \\msp 0, \\msp 2 \\msp \\mbox{\\&} \\msp 7$ units~(left column). The phase in the right column~$\\in \\msp [-\\frac{\\pi }{2}, \\msp \\frac{\\pi }{2}]$~radians.}\n  \\label{fig:03-dirac-vis}\n\\end{figure}\n\n%% BoundingBox: 5 20 620 780 for fig = plt.figure(figsize=(10, 12))\n\\begin{figure}\n  \\centering\n    \\includegraphics[width=\\textwidth ]{04-gauss-vis.eps}\n  \\caption{The correlator response to different Gaussian functions.}\n  \\label{fig:04-gauss-vis}\n\\end{figure}\n\n\\section{Finite bandwidth}\n\nThe bandwidth has a dramatic effect on the correlator response. In the following computation, I am ignoring the effect of source structure.\n\n\\begin{eqnarray}\n  \\mathcal{V}(\\vec{b}) &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c}} \\msp d\\,\\Omega \\hspace{0.8cm} \\longleftarrow \\mbox{quasi--monochromatic, i.e. infinitesimal bandwidth} \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{\\Delta \\nu } \\int ^{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} _{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c}} \\msp d\\, \\nu \\msp d\\,\\Omega \\hspace{0.8cm} \\longleftarrow \\mbox{finite bandwidth} \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{\\Delta \\nu } \\int ^{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} _{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} e^{-i \\msp 2\\pi \\msp \\nu \\msp \\tau _g} \\msp d\\, \\nu \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{\\Delta \\nu } \\int ^{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} _{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} cos(2\\pi \\msp \\nu \\msp \\tau _g) - i \\msp sin(2\\pi \\msp \\nu \\msp \\tau _g)  \\msp d\\, \\nu \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{\\Delta \\nu } \\Bigg [\\frac{sin(2\\pi \\msp \\nu \\msp \\tau _g)}{2\\pi \\msp \\tau _g} + i \\msp \\frac{cos(2\\pi \\msp \\nu \\msp \\tau _g)}{2\\pi \\msp \\tau _g}\\Bigg ]^{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} _{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{\\Delta \\nu \\msp 2\\pi \\msp \\tau _g} \\Big [sin(2\\pi \\msp \\nu \\msp \\tau _g) + i \\msp cos(2\\pi \\msp \\nu \\msp \\tau _g)\\Big ]^{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} _{\\nu_ 0 + \\frac{\\Delta \\nu }{2}} \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Bigg [sin\\Big [2\\pi \\msp \\big (\\nu_ 0 + \\frac{\\Delta \\nu }{2}\\big ) \\msp \\tau _g\\Big ] + i \\msp cos\\Big [2\\pi \\msp \\big (\\nu_ 0 + \\frac{\\Delta \\nu }{2}\\big ) \\msp \\tau _g\\Big ] \\dotso \\nonumber \\\\\n&& \\dotso \\enspace - sin\\Big [2\\pi \\msp \\big(\\nu_ 0 - \\frac{\\Delta \\nu }{2}\\big ) \\msp \\tau _g\\Big ] - i \\msp cos\\Big [2\\pi \\msp \\big (\\nu_ 0 - \\frac{\\Delta \\nu }{2}\\big ) \\msp \\tau _g\\Big ]\\Bigg ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Bigg [sin\\Big (2\\pi \\msp \\nu_ 0 \\msp \\tau _g + 2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) + i \\msp cos\\Big (2\\pi \\msp \\nu_ 0 \\tau _g + 2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso \\enspace - sin\\Big (2\\pi \\msp \\nu_ 0 \\msp \\tau _g - 2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) - i \\msp cos\\Big (2\\pi \\msp \\nu_ 0 \\msp \\tau _g - \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )\\Bigg ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Bigg [sin (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) + cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso + i \\msp cos (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso - sin (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) + cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso - i \\msp cos (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )\\Bigg ] \\msp d\\,\\Omega \\nonumber\n\\end{eqnarray}\n\n\\begin{eqnarray}\n \\label{eq:27}\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Bigg [\\cancel{sin (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )} + cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso \\cancel{+ i \\msp cos (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )} - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso \\cancel{- sin (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )} + cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\dotso \\nonumber \\\\\n&& \\dotso \\cancel{- i \\msp cos (2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp cos\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )} - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big )\\Bigg ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{1}{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Bigg [2 \\msp cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) - 2 i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) \\Bigg ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{2 \\msp sin\\Big (2\\pi \\msp \\frac{\\Delta \\nu }{2} \\msp \\tau _g\\Big ) }{2\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Big [cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\Big ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{sin (\\pi \\msp \\Delta \\nu \\msp \\tau _g)}{\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\Big [cos(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) - i \\msp sin(2\\pi \\msp \\nu_ 0 \\msp \\tau _g) \\Big ] \\msp d\\,\\Omega \\nonumber \\\\\n&=& \\iint I_\\nu (\\hat{s}) \\msp \\frac{sin (\\pi \\msp \\Delta \\nu \\msp \\tau _g)}{\\pi \\msp \\tau _g \\msp \\Delta \\nu} \\msp e^{-i \\msp 2\\pi \\msp \\nu _0 \\msp \\tau _g} \\msp d\\,\\Omega\n\\end{eqnarray}\n\nWhat this tells us is that the correlator response~$e^{-i \\msp 2\\pi \\msp \\nu _0 \\msp \\tau _g}$ is modulated by the normalised~$sinc$ function~$\\frac{sin (\\pi \\msp \\Delta \\nu \\msp \\tau _g)}{\\pi \\msp \\tau _g \\msp \\Delta \\nu}$ as shown in Figure~\\ref{fig:05-fin-band}. From Equation~\\eqref{eq:27}, we clearly have nulls in the envelope~--~where the response falls to 0~--~when the numerator in~$\\frac{sin (\\pi \\msp \\Delta \\nu \\msp \\tau _g)}{\\pi \\msp \\tau _g \\msp \\Delta \\nu}$ is~0.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\textwidth ]{05-fin-band-lecture.eps}\n  \\caption[]{The correlator~\\emph{cosine}~(left) and~\\emph{sine}~(right) responses (blue lines) when we have a finite--bandwidth of~$\\Delta \\nu = 8$~units~(e.g. GHz) and an observing frequency of~13~units for~$u = \\frac{|b|}{\\lambda} = 3$ and~$l$ extends from horizon--to--horizon~$\\in [-\\frac{\\pi}{2},-\\frac{\\pi}{2}]$. The red line is the~\\emph{sinc} envelope due to the bandwidth~$\\Delta \\nu $. This is analogous to Figure~\\ref{fig:corr-resp}, except we assume an infinitesimal bandwidth and only a \\emph{cosine} response in that previous figure. Use \\texttt{05-fin-band.py} to replicate this figure.}\n  \\label{fig:05-fin-band}\n\\end{figure}\n\n\\begin{eqnarray}\n  \\label{eq:30}\n  \\mbox{i.e. when} \\qquad sin (\\pi \\msp \\Delta \\nu \\msp \\tau _g) &=& 0 \\nonumber \\\\\n  \\implies \\qquad                       \\Delta \\nu \\msp \\tau _g  &=& 1 , \\hspace{0.8cm} \\mbox{for the first null}\\nonumber \\\\\n  \\Delta \\nu \\msp  \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c} &=& 1 \\nonumber \\\\\n  \\Delta \\nu \\msp b \\msp sin\\theta &=& c \\nonumber \\\\\n  \\therefore sin\\theta &=& \\frac{c}{b\\msp \\Delta \\nu } \\quad = \\quad \\frac{\\frac{\\lambda}{b}}{\\frac{\\Delta \\nu }{\\nu }} \\nonumber\n\\end{eqnarray}\n\nThe number of fringes between the peak and this first null can be approximated by\n\n\\begin{eqnarray}\n  \\label{eq:31}\n  N &\\sim & \\frac{\\mbox{Distance between peak and first null}}{\\mbox{Distance between fringes}} \\nonumber \\\\\n    &=&\\frac{\\frac{c}{b\\msp \\Delta \\nu}}{\\frac{\\lambda }{b}} \\nonumber \\\\\n    &=& \\frac{c}{b\\msp \\Delta \\nu} \\cdot \\frac{b}{\\lambda } \\quad = \\quad \\frac{\\nu }{\\Delta \\nu } \\nonumber\n\\end{eqnarray}\n\ni.e. something like observing frequency divided by the bandwidth. The~$sinc$ envelope can also be expressed in a way more useful to the interferometer's characteristics rather than~$\\tau _g$ since~$sin(\\pi \\msp \\tau _g \\msp \\Delta \\nu ) = sinc \\big (\\pi \\msp \\frac{b}{\\lambda } \\msp \\frac{\\Delta \\nu }{\\nu } \\msp sin\\theta \\big ) = sinc \\big (\\pi \\msp \\frac{b \\msp \\Delta \\nu }{c} \\msp sin\\theta \\big )$.\n\n\\section{Coordinate systems}\n\n\\begin{figure}\n  \\centering\n    \\includegraphics[angle= 90, width=0.75\\textwidth ]{uv-lm-coords.eps}\n    \\caption[]{There are two coordinate frames which we use in interferometry. The source is in the~$l-m$ plane and the interferometer is in the~$u-v$ plane.\\\\ \\emph{Image credit:} Interferometry and Synthesis in Radio Astronomy~(Thomson, Moran and Swenson,~2017) used under the Creative Commons Attribution International License (\\texttt{http://creativecommons.org/licenses/by-nc/4.0/}). }\n    \\label{fig:uv-lm-coords}\n\\end{figure}\n\nWe need a formal coordinate framework in order to proceed further with the mathematics. This is described in Figure~\\ref{fig:uv-lm-coords}. Let the baseline have components,~$\\frac{\\vec{b}}{\\lambda } = u\\,\\hat{i} + v\\,\\hat{j} + w\\,\\hat{k}$. Let the source have components,~$\\hat{s} = l\\,\\hat{i} + m\\,\\hat{j} + n\\,\\hat{k}$.\n\n\\begin{eqnarray}\n  \\label{eq:18}\n\\frac{\\vec{\\mathbf{b}}}{\\lambda }\\boldsymbol{\\cdot} \\mathbf{\\hat{s}} = \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{\\lambda } &=& (u\\,\\hat{i} + v\\,\\hat{j} + w\\,\\hat{k}) \\cdot (l\\,\\hat{i} + m\\,\\hat{j} + n\\,\\hat{k}) \\nonumber \\\\\n                                         &=& (u\\,l + v\\,m + w\\,n) \\nonumber\n\\end{eqnarray}\n\n\\begin{braced}\nNote that~$\\hat{s}$ is a unit vector,~$|\\hat{s}| = 1$.\n\\begin{eqnarray}\n  \\label{eq:20}\n  \\implies \\qquad l^2 + m^2 + n^2 &=& 1 \\nonumber \\\\\n                                n &=& \\sqrt{1 - l^2 + m^2} \\nonumber\n\\end{eqnarray}\n\\end{braced}\n\\vspace{0.5cm}\n\nAt this point, we employ a simplification to assume that the antennas lie on a plane such that~$w = 0$.\n\n\\begin{eqnarray}\n  \\label{eq:22}\n  \\therefore \\enspace \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{\\lambda } &=& (u\\,l + v\\,m) \\nonumber\n\\end{eqnarray}\n\nEquation~\\eqref{eq:21},~$\\mathcal{V}(\\vec{b}) = \\iint I_\\nu (\\hat{s}) \\msp e^{i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{b} \\cdot \\hat{s}}{c}} \\msp d\\,\\Omega $, now becomes\n\n\\begin{eqnarray}\n  \\label{eq:23}\n  \\mathcal{V}(\\vec{b}) &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{c}} \\msp d\\,\\Omega \\nonumber \\\\\n  \\mathcal{V}(\\vec{b}) &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\nu \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{\\nu \\msp \\lambda }} \\msp d\\,\\Omega \\nonumber \\\\\n  \\mathcal{V}(\\vec{b}) &=& \\iint I_\\nu (\\hat{s}) \\msp e^{-i \\msp 2\\pi \\msp \\frac{\\vec{\\mathbf{b}} \\boldsymbol{\\cdot} \\mathbf{\\hat{s}}}{\\lambda }} \\msp d\\,\\Omega \\nonumber \\\\\n     \\mathcal{V}(u, v) &=& \\iint I_\\nu (l, m) \\msp e^{-i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,l \\msp d\\,m \\nonumber\n\\end{eqnarray}\n\nIn the final step, we replace the vectors~$\\vec{\\mathbf{b}}$ and~$\\mathbf{\\hat{s}}$ with their corresponding vector components~$u-v$ and~$l-m$. You can think of the area~$d\\,\\Omega \\approx d\\,l \\msp d\\,m$~(see the shaded area~$d\\,\\Omega $ in Figure~\\ref{fig:uv-lm-coords}). We now have a~2\\,D Fourier transform between the visibility,~$\\mathcal{V}(u, v)$, which we can measure, and the source brightness distribution,~$I_\\nu (l, m)$, which we want.\n\n\\begin{eqnarray}\n  \\label{eq:24}\n  \\begin{aligned}\n  \\mathcal{V}(u, v) &=& \\iint I_\\nu (l, m) \\msp e^{-i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,l \\msp d\\,m \\\\\n  I_\\nu (l, m) &=& \\iint \\mathcal{V}(u, v) \\msp e^{ i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,u \\msp d\\,v\n  \\end{aligned}\n\\end{eqnarray}\n\nThis is known as the \\emph{Van Cittert--Zernicke Theorem} and~$I_\\nu (l, m)$ is the \\underline{\\emph{true}} sky brightness distribution and~$\\mathcal{V}(u, v)$ is the \\underline{\\emph{true}} sky visibility.\n\n\\section{UV sampling}\n\nAccording to equation~\\eqref{eq:24}, the source intensity~$I_\\nu (l, m)$ can be perfectly described by~$\\mathcal{V}(u, v)$. However, in practice this is not the case as the~$(u,\\msp v)$ sampling is baseline dependent. Figure~\\ref{fig:06-array2uv-triangle}~(left panel) shows a hypothetical triangular array with elements~$A$,~$B$ and~$C$. With respect to the centre~(0,\\,0) of this array these have corresponding position vectors~$\\overrightarrow{OA}$,~$\\overrightarrow{OB}$ and~$\\overrightarrow{OC}$. Since the~$u-v$ space is derived from the baseline vector, we need to determine the individual baseline coordinates~$\\overrightarrow{AB}$,~$\\overrightarrow{AC}$ and~$\\overrightarrow{BC}$~(and corresponding degenerate baselines~$\\overrightarrow{BA}$,~$\\overrightarrow{CA}$ and~$\\overrightarrow{CB}$). For example,\n\n\\begin{eqnarray}\n  \\label{eq:26}\n  \\overrightarrow{AB} &=&  \\enspace \\overrightarrow{AO} + \\overrightarrow{OB} \\nonumber \\\\\n                      &=& -\\overrightarrow{OA} + \\overrightarrow{OB} \\nonumber \\\\\n                      &=& -(0.5\\msp \\hat{i} - 0.5\\msp \\hat{j}) + (0\\msp \\hat{i} + 0.5\\msp \\hat{j}) \\nonumber \\\\\n                      &=& -0.5\\msp \\hat{i} + 1\\msp \\hat{j} \\nonumber\n\\end{eqnarray}\n\n\\begin{figure}\n\\begin{subfigure}[b]{\\textwidth }\n  \\centering\n  %%BoundingBox: -160 145 760 666 for fig = plt.figure(figsize=(15, 7.5))\n  \\includegraphics[width=\\linewidth ]{06-array2uv-triangle.eps}\n  \\caption{The black circles represent antenna positions of a hypothetical array~(left panel) on the Earth's surface~($x,\\msp y$) and corresponding~$uv$--coordinates~(right panel). The blue arcs trace the loci of these~$u-v$ points which are sampled as the Earth rotates. The offset between the start of the blue points and the black points is due to a coordinate rotation which I have applied in keeping with convention. You can use~\\texttt{07-array2uv-loci.py} to reproduce this figure.\\\\}\n  \\label{fig:06-array2uv-triangle}\n\\end{subfigure}\\\\\n\\begin{subfigure}[b]{\\textwidth }\n  \\centering\n  %%BoundingBox: -175 145 760 666 for fig = plt.figure(figsize=(15, %7.5))\n  \\includegraphics[width=\\linewidth ]{06-array2uv-meerkat.eps}\n  \\caption{The black circles represent MeerKAT's antenna positions~(left panel) on the Earth's surface~($x,\\msp y$) and corresponding~$uv$--coordinates~(right panel).}\n  \\label{fig:07-array2uv-meerkat}\n\\end{subfigure}\n\\caption{}\n\\label{fig:xy-uv}\n\\end{figure}\n\nThe right panel of Figure~\\ref{fig:06-array2uv-triangle} is a graphical representation of what is known as the \\emph{sampling pattern},~$S(u, v)$, because it is where~$\\mathcal{V}(u, v)$ is sampled such that we have the \\emph{dirty image}\n\n\\begin{eqnarray}\n  \\label{eq:28}\n   \\mbox{True image,} \\quad I_\\nu (l, m) &=& \\iint \\mathcal{V}(u, v) \\msp e^{ i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,u \\msp d\\,v \\hspace{0.5cm} \\mbox{from Equation~\\eqref{eq:24}} \\nonumber \\\\\n   \\mbox{Dirty image,} \\quad I_{\\mbox{\\tiny{\\emph{D}}}} (l, m) &=& \\iint S(u, v) \\msp \\mathcal{V}(u, v) \\msp e^{ i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,u \\msp d\\,v\n\\end{eqnarray}\n\nWe know that a product of two functions in the~$u-v$ Fourier domain corresponds to a convolution of two signals in the~$l-m$ domain such that~$I_{\\mbox{\\tiny{\\emph{D}}}} (l, m) = I_\\nu (l,m) * B(l,m)$, where~$B(l,m)$ is known as the \\emph{dirty beam} and is the Fourier Transform of~$S(u, v)$\n\n\\begin{eqnarray}\n  \\label{eq:29}\n  B(l,m) &=& \\iint S(u, v) \\msp e^{ i \\msp 2\\pi \\msp (u\\,l + v\\,m)} \\msp d\\,u \\msp d\\,v \\nonumber\n\\end{eqnarray}\n\nI have summarised the relationship between~$I_\\nu (l, m)$, $\\mathcal{V}(u,  v)$, $B(l, m)$, $S(u, v)$, $I_{\\mbox{\\tiny{\\emph{D}}}}(l, m)$ and~$\\mathcal{V}(u,  v) \\msp S(u, v)$ in Table~\\ref{tab:uv-summary}. Recovering~$I_\\nu (l, m)$, $\\mathcal{V}(u,  v)$ from~$I_{\\mbox{\\tiny{\\emph{D}}}}(l, m)$ is a deconvolution problem which can be solved using~CLEAN.\n\n\\begin{table}\n  \\centering\n  \\begin{tabular}{r|ccccc}\n$\\mathbf{l-m}$ \\textbf{(image)}     & $I_\\nu (l, m)$            & * & $B(l, m)$               & = & $I_{\\mbox{\\tiny{\\emph{D}}}}(l, m)$ \\\\\n\\textbf{domain}                     & True image               & & Dirty beam              &   & Dirty image                       \\\\\n                                    & \\emph{\\textbf{(Desired)}}& & & & \\\\\n                                    &                          & & & & \\\\\n              $\\mathcal{F.T.}$      & $\\Big \\Updownarrow $     & & $\\Big \\Updownarrow $    &   & $\\Big \\Updownarrow $              \\\\\n                                    &                          & & & & \\\\\n$\\mathbf{u-v}$ \\textbf{(Fourier)}   & $\\mathcal{V}(u,  v)$     & $\\times $ & $S(u, v)$               & = & $\\mathcal{V}(u,  v) \\msp S(u, v)$ \\\\\n      \\textbf{domain}               & True visibility          & & Sampling pattern        &   & \\emph{\\textbf{(Measured)}}        \\\\\n                                    &                          & & \\emph{\\textbf{(Known)}} &   &                                   \\\\\n  \\end{tabular}\n  \\caption[]{A summary of the relationship between quantities in the image and Fourier domains.}\n  \\label{tab:uv-summary}\n\\end{table}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"Lecture\"\n%%% End:", "meta": {"hexsha": "08575517e4565f39dadfc7dd7f4611878ab949d2", "size": 42890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/01-Intro.tex", "max_stars_repo_name": "vasaantk/Introduction-to-Interferometry", "max_stars_repo_head_hexsha": "a584fb8b3888fd9bfa00a19fd212ce2b216ea6bf", "max_stars_repo_licenses": ["MIT"], "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/01-Intro.tex", "max_issues_repo_name": "vasaantk/Introduction-to-Interferometry", "max_issues_repo_head_hexsha": "a584fb8b3888fd9bfa00a19fd212ce2b216ea6bf", "max_issues_repo_licenses": ["MIT"], "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/01-Intro.tex", "max_forks_repo_name": "vasaantk/Introduction-to-Interferometry", "max_forks_repo_head_hexsha": "a584fb8b3888fd9bfa00a19fd212ce2b216ea6bf", "max_forks_repo_licenses": ["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.0980392157, "max_line_length": 920, "alphanum_fraction": 0.6175332245, "num_tokens": 15737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6458632948202194}}
{"text": "\\chapter{The $\\alpha$-shapes approach}\\label{chap:boundaries_alpha}\nIn the previous chapter, we presented a new ray tracing approach based on PS. We explained that, in order to compute the target intensity, it is necessary to know the boundaries of the regions in target PS with positive luminance. Ray tracing in PS requires tracing only the rays close to these boundaries. The rays traced can be seen as a point cloud in PS. To detect the shape formed by those rays, the $\\alpha$-shapes approach is employed \\cite{portegies2013fast}.\\\\ \\indent\nMethods based on $\\alpha$-shapes are widely used to reconstruct an unknown shape formed by a set of finite data points \\cite{guo1997surface}. $\\alpha$-shapes is a very powerful tool to construct the shape of a point cloud. As the parameter $\\alpha$ varies, we can obtain different $\\alpha$-shapes from the point set itself to the convex\nhull \\cite{xu2003automatic}. The disadvantage of such method is that it can be very hard to choose the appropriate value of the parameter $\\alpha$ and, in most cases it can be selected only by trial-and-error.\\\\ \\indent\nWe developed a technique based on $\\alpha$-shapes that gives a criterion to determine the value of the parameter $\\alpha$, for which the boundaries are approximated well \\cite{filosa2015new}.\\\\ \\indent This chapter is organized as follows. An overview of the-state-of-the-art about $\\alpha$-shape methods is provided in Section \\ref{sec:alpha-shapes}; the technique used for computing the $\\alpha$ value is explained in Section \\ref{sec:Tir_alpha}; the results for two different kinds of total internal reflection (TIR)-collimators are given in Section \\ref{sec:results-Tir-alpha}. Discussions and conclusions are provided in the last paragraph of this chapter.\n\\section{$\\alpha$-shapes theory}\\label{sec:alpha-shapes}\nGiven a finite set $\\mbox{\\insieme{U}} = \\{\\point{u}_1, \\cdots, \\point{u}_N\\}\\subset \\mathbb{R}^2$ of points, $\\alpha$-shapes are geometrical objects that give us an approximation of the shape formed by the point cloud. For now we do not further specify the notion of shape. A more precise definition will be provided later.\\\\ \\indent\nBefore giving a formal definition, we explain an intuitive and nice interpretation of $\\alpha$-shapes \\cite{lucieer2004alpha}. \nLet us think of a stracciatella ice-cream\\footnote{Stracciatella ice cream is made with milk-based ice-cream and fine pieces of chocolate \\cite{Wiki3}.}. If we desire to know the shape formed by the chocolate pieces we can start eating the ice cream using a spoon with a spherical scoop and try not to remove any piece of chocolate. \nWe will obtain a shape formed by arcs and points. % (see Figure \\ref{fig:shape2d} for the two-dimensional case).\n%\\begin{figure}[t]\\label{fig:shape2d}\n%\\begin{center} \n%\\includegraphics[width=\\textwidth]{alpha_shape2D}\n%\\label{fig:shape}\n%\\caption{\\textbf{Construction of $\\alpha$-shapes.} The boundary of the shape (red line) formed by a set of points (blue dots) in $\\mathbb{R}^2$ is detected for $\\alpha = 1$ (left) and for $\\alpha=2$ (right) \\cite{sabel2017application}.}\n%\\label{fig:shape2d}\n%\\end{center}\n%\\end{figure}\nStraightening the arcs to line segments we obtain broken lines which constitute the boundary of the so-called $\\alpha$-shape of the point set $\\mbox{\\insieme{U}}$. \nA very small spoon will allow us to eat the entire ice cream without eating any piece of chocolate, while with a larger spoon we are not able to eat any chunk of the ice cream without chocolate pieces. In this example, the chocolates pieces are the points of set $\\mbox{\\insieme{U}}$ and, the parameter $\\alpha$ determines the radius of the carving spoon (the spherical spoon in two-dimension is simply a circle).\\\\ \\indent \nThe formal definition of $\\alpha$-shape was first given by Edelsbrunner, Kirkpatrick and Seidel in 1983 \\cite{edelsbrunner1983shape}. They describe $\\alpha$-shape as a generalization of the convex hull of a finite set of points in the plane. Let $\\alpha$ be a non negative number $0\\leq\\alpha<\\infty$. \nIf $\\alpha = 0$ the shape degenerates to the point set $\\mbox{\\insieme{U}}$. On the other hand, when $\\alpha\\rightarrow\\infty$ the $\\alpha$-shape is simply the convex hull of \\insieme{U}. If $0<\\alpha<\\infty$ the $\\alpha$-shape is a polygon of \\insieme{U} \\cite{edelsbrunner1994three}. The construction of the $\\alpha$-shape is closely related to the Delaunay triangulation of \\insieme{U} \\cite{mucke1993shapes}. Therefore, a formal definition of triangulation and Delaunay triangulation is now required. \\\\ \\indent\nGiven a set $\\mbox{\\insieme{U}}$ of points not all aligned, let us consider the set \\insieme{E} of all the straight-line segments whose endpoints are in \\insieme{U}. \nA triangulation \\insieme{T} of $\\mbox{\\insieme{U}}$ is the subset of \\insieme{E} with the maximum number of segments such that all the line segments of \\insieme{T} intersect only at their endpoints \\cite{lloyd1977triangulations}. \n\\\\ \\indent Before giving a more formal definition of triangulation, let us define a partition of a set $\\mbox{\\insieme{X}}\\subset \\mathbb{R}^2$ as a collection of the subsets which divide \\insieme{X} into non-overlapping regions so that any point in \\insieme{X} is located in only one region. \n\\begin{definition} \\indent Let $\\mbox{\\insieme{P}}\\subset \\mathbb{R}^2$ be the convex hull of $\\mbox{\\insieme{U}}$ and $\\mbox{\\insieme{T}} = \\{\\mbox{\\insieme{T}}_1, \\cdots, \\mbox{\\insieme{T}}_\\variabile{h}\\}$ be a partition of $\\mbox{\\insieme{P}}$ into closed triangles, that is triangles that include their edges. Suppose that the following properties hold:\n\\begin{itemize}\n\\item[a)] $\\mbox{\\insieme{P}} = \\bigcup_{\\variabile{i} = 1}^{\\variabile{h}}\\mbox{\\insieme{T}}_\\variabile{i}$,\n\\item[b)] $\\forall \\mbox{ \\insieme{T}}_\\variabile{i}, \\mbox{\\insieme{T}}_\\variabile{j} \\in \\mbox{\\insieme{T}}$, $\\mbox{\\insieme{T}}_\\variabile{i} \\neq \\mbox{\\insieme{T}}_\\variabile{j}$, and \n\\begin{equation*}\n\\textrm{int}(\\mbox{\\insieme{T}}_\\variabile{i})\\cap \\textrm{int}(\\mbox{\\insieme{T}}_\\variabile{j}) = \\emptyset,\n\\end{equation*}\nwhere $\\textrm{int}(\\mbox{\\insieme{T}}) = \\mbox{\\insieme{T}}-\\partial \\mbox{\\insieme{T}}$,\n\\end{itemize}\nthen $\\mbox{\\insieme{T}}$ is called a \\textit{triangulation} of $\\mbox{\\insieme{P}}$ \\cite{Numericalmethods}.\n\\end{definition}\nThe Delaunay triangulation $\\mbox{\\insieme{T}}^{\\prime}$ of the point set \\insieme{U} has the property that the circumcircle of any triangle of $\\mbox{\\insieme{T}}^{\\prime}$ does not contain any point of \\insieme{U}. This is called the Delaunay property. Next, a very commonly used algorithm to construct such triangulation is explained.\\\\ \\indent \n$\\mbox{\\insieme{T}}^\\prime$ is constructed by modifying a general triangulation \\insieme{T} such that every point satisfies the Delaunay property. \nTherefore, every triangle that does not satisfy such property is flipped such that the new edge is part of the triangulation, see Figure \\ref{fig:Delaunay}. \nGiven, for example, an arbitrary triangulation \\insieme{T} in two-dimensions, for each edge $\\overline{\\point{ab}}$ in \\insieme{T} which is not on the boundary of the convex hull the two triangles \n$\\Delta_{\\point{abc}}$ and $\\Delta_{\\point{abd}}$ with the common edge $\\overline{\\point{ab}}$ are identified. Then, if either the circumcircle of triangle $\\Delta_{\\point{abc}}$ contains point \\point{d} or the circumcircle of triangle $\\Delta_{\\point{abd}}$ contains point \\point{c}, the edge $\\overline{\\point{ab}}$ cannot be included in the Delaunay triangulation and, therefore, $\\overline{\\point{ab}}$ is replaced by the edge $\\overline{\\point{cd}}$ such that the triangles $\\Delta_{\\point{acd}}$ and $\\Delta_{\\point{bcd}}$ are constructed. The new edge $\\overline{\\point{cd}}$ locally satisfies the Delaunay property and the triangles $\\Delta_{\\point{acd}}$ and  $\\Delta_{\\point{bcd}}$ are added to the Delaunay triangulation $\\mbox{\\insieme{T}}^\\prime$.  \n\\begin{figure}[t]\\label{fig:Delaunay}\n\\begin{subfigure}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[]{triangle_alpha_shapes}\n\\label{fig:shape}\n\\caption{\\textbf{Not acceptable triangle.} The point \\point{d} is inside the circle circumscribing the triangle $\\Delta_{\\point{abc}}$, therefore the edge $\\overline{\\point{ab}}$ cannot be included in the Delaunay triangulation.}\n\\end{subfigure}\n\\hfill\n\\begin{subfigure}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[]{triangle_alpha_shapes_flipped}\n\\caption{\\textbf{Acceptable triangle.} The flipped triangle $\\Delta_{\\point{acd}}$ satisfies the Delaunay property, thus it is included in the Delaunay triangulation.}\n\\end{subfigure}\n\\caption{Construction of the Delaunay triangulation in 2D.}\n\\label{fig:Delaunay}\n\\end{figure}\n\\\\ \\indent Several other algorithms have been developed to construct a Delaunay triangulation, see for example \\cite{lee1980two, renka1997algorithm}.\n Given a point set $\\mbox{\\insieme{U}}$ and a triangulation \\insieme{T}, it can be proved that the corresponding Delaunay triangulation $\\mbox{\\insieme{T}}^\\prime$ is unique. Moreover, it maximizes the largest minimum angle among all possible triangulations of a point set $\\mbox{\\insieme{U}}$ \\cite{press2007numerical}.\n\\\\ \\indent Alternatively, the Delaunay triangulation can be constructed as the dual of the Voronoi diagram \\cite{fortune1992voronoi}. Let $\\mbox{\\insieme{X}}\\subset\\mathbb{R}^2$ be a metric space endowed with the Euclidean distance $d(\\point{x}, \\point{y})$ for $\\point{x}, \\point{y}\\in \\mbox{\\insieme{X}}$. For \\textit{almost}\\footnote{Note the importance of the word \\textit{almost}. Some points can have the same distance with two or more points of $\\mbox{\\insieme{U}}$.} every point $\\point{x}\\in \\mathbb{R}^2$, there is a unique point that is the closest point to $\\point{x}$. The Voronoi cell of a point $\\point{u}_\\variabile{i}\\in \\mbox{\\insieme{U}}$ contains all points in $\\mathbb{R}^2$ that are closest to $\\point{u}_{\\variabile{i}}$, see Figure \\ref{fig:Voronoi}. The Voronoi diagram of $\\mbox{\\insieme{U}}\\subset \\mathbb{R}^2$ is defined as the set of all Voronoi cells \\cite{cazals2005conformal}. A more formal definition of the Voronoi diagram is given in the following.\n\\begin{defn}\nLet $\\mbox{\\insieme{U}}=\\{\\point{u}_1,\\cdots,\\point{u}_N\\}$ be a set of points in $\\mathbb{R}^2$. The Voronoi cell $\\mbox{\\insieme{V}}_\\variabile{i}$ associated to point $\\point{u}_\\variabile{i}$ is defined as:\n\\begin{equation}\n\\mbox{\\insieme{V}}_\\variabile{i}=\\{\\point{x}\\in \\mathbb{R}^2\\; | \\;|\\point{x}-\\point{u}_\\variabile{i}|<|\\point{x}-\\point{u}_\\variabile{j}| \\quad \\forall \\variabile{j}\\neq \\variabile{i} \\}.\n\\end{equation}\nThe Voronoi diagram $\\mbox{\\insieme{V}}$ is defined as \n\\begin{equation}\n\\mbox{\\insieme{V}} = \\bigcup_{\\variabile{i}=1}^N \\mbox{\\insieme{V}}_\\variabile{i}\n\\end{equation}\n where $\\mbox{\\insieme{V}}_{\\variabile{i}}\\cap \\mbox{\\insieme{V}}_{\\variabile{j}}= \\emptyset$ for $\\variabile{i}\\neq\\variabile{j}$.\n\\end{defn}\nFor the definition of Voronoi diagram in higher dimensions see \\cite{brown1979voronoi}.\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width = 0.7 \\textwidth]{Delanay_Voronoi1}\n\\caption{\\textbf{Relationship between the Delaunay triangulation and the Voronoi Diagram \\cite{Wiki4}.} The black line segments are the boundaries of the Delaunay triangulation, the red line segments constitutes the boundaries of the Voronoi diagram.}\n\\label{fig:Voronoi}\n\\end{figure}\n\\\\ \\indent The Delaunay triangulation triangulates the convex hull of \\insieme{U} and, therefore it does not constitute a suitable method for reconstructing the contour formed by a point cloud. The $\\alpha$-shape method was developed to solve such problem \\cite{edelsbrunner2010alpha, guo1997surface}. Starting from the Delaunay triangulation $\\mbox{\\insieme{T}}^\\prime$ of a point set \\insieme{U}, the corresponding $\\alpha$-shape of $V$ is formed by the only triangles of $\\mbox{\\insieme{T}}^\\prime$ that satisfy the so-called \"$\\alpha$-test\" which is briefly explained.\nFor each triangle, we calculate the circumradius, i.e., the radius of the circumcircle. If this radius is larger than $\\alpha$ the triangle is removed from the shape. The choice of the parameter $\\alpha$ is highly significant in the $\\alpha$-shapes procedure and, it has to be selected such that the desired approximation of the shape formed by the points of $V$ is obtained.\\\\ \\indent\n%Therefore, $\\alpha$ is closely related to the radius of the circumcircles. A possible strategy is to find the radius of the greater empty circumcircle. Thus $\\alpha$ can be selected according to the density $\\delta$ of the point sets $V$\n%with $C$ a constant and $\\delta$:\n%\\begin{equation}\n%\\delta=\\frac{N}{A}\\; ,\n%\\end{equation}\n%where $N$ is the number of points in $V$ and $A$ is the area of the convex hull of $V$.\n%%Note that, if we scale the dimensions of the  \n%The value of $\\alpha$ can be chosen, for instance, inversely proportional to $\\sqrt{\\delta}$:\n%\\begin{equation}\n%\\alpha=C\\frac{1}{\\sqrt{\\delta}}\\;,\n%\\end{equation}\n%Note that, while $\\delta$ is given for a fixed point set $V$, the value of $C$ needs to be determined by numerical simulations.\\\\ \\indent \nTo summarize, the $\\alpha$-shape construction can be outlined as follows:\n\\begin{enumerate}\n\\item Construct a Delaunay triangulation\\footnote{In the simulations we present in this chapter the Matlab function \\textit{Delaunay} is used \\cite{matlab_delaunay}.} $\\mbox{\\insieme{T}}^\\prime$ of the point cloud $\\mbox{\\insieme{U}}$;\n\\item For every triangle $\\mbox{\\insieme{T}}^\\prime(i)\\in \\mbox{\\insieme{T}}^\\prime$ calculate its circumradius $r(i)$;\n\\item If $r(i)\\leq\\alpha$ keep the triangle $\\mbox{\\insieme{T}}^\\prime(i)$ in the triangulation;\n\\item If $r(i)>\\alpha$ remove the triangle from the triangulation;\n\\item Select from the new triangulation obtained those sides that belong to only one triangle, the so-called \\textit{free boundary edges}\\footnote{In the simulations we present in this chapter the Matlab function \\textit{freeBoundary} is used \\cite{matlab_free}.}. By definition, the free boundary edges are not a common edge of any two triangles.\n\\end{enumerate}\n%% Insert algorithm\n%\\begin{algorithm}[h]\n%\\caption{$\\alpha$-shape reconstruction}\\label{alg:alphashapes}\n%\\begin{algorithmic}[1]\n%\\Procedure{$\\alpha$-shape}{$V$, $\\alpha$}\n%\\State Construct a Delaunay triangulation of the point cloud $V$\n%\\State$T^\\prime\\gets$ all triangles of the Delaunay triangulation\n%\\State For every \n%\\State Calculates the radius of the circle circumscribed by the vertices of every triangle\n%\\State $r(i) \\gets$\n%\\State For {every triangle in $T^\\prime$}\n%\\State $(\\variabile{q}_1^4, \\variabile{p}_1^4) \\gets \\mbox{left and upper corner of source PS: (-\\variabile{a}, 1)} $\n%\\For{$ \\variabile{k}= 1 \\to 4 $}\n%\\State Trace the ray with initial coordinates $(\\variabile{q}_1^\\variabile{k}, \\variabile{p}_1^{\\variabile{k}})$ in \\set{S}{}{};\n%\\State Calculate the corresponding path $\\Pi^{\\variabile{k}}$;\n%\\State $\\mbox{Ray}.\\variabile{q}\\gets [\\mbox{Ray}.\\variabile{q}, \\variabile{q}_1^\\variabile{k}]$;\n%\\State $\\mbox{Ray}.\\variabile{p}\\gets [\\mbox{Ray}.\\variabile{p}, \\variabile{p}_1^\\variabile{k}]$;\n%\\State Store the corresponding path $\\Pi^{\\variabile{k}}$.\n%\\State $\\mbox{Ray}.\\Pi\\gets [\\mbox{Ray}.\\Pi, \\Pi^{\\variabile{k}}]$;\n%\\EndFor\n%\\State VL $\\gets [1, 2, 4]$ \\Comment{VL = vertices of the left triangle}\n%\\State VR $\\gets [2,3, 4]$   \\Comment{VR = vertices of the right triangle}\n%\\State \\Call{Left Triangle}{VL, Ray, $\\varepsilon_{\\variabile{q}_1}^{\\textrm{min}}, \\varepsilon_{\\variabile{q}_1}^{\\textrm{max}}, \\varepsilon_{\\variabile{p}_1}^{\\textrm{min}}, \\varepsilon_{\\variabile{p}_1}^{\\textrm{max}}$}\\Comment{Refine the left triangle} \n%\\State \\Call{Right Triangle}{VR, Ray, $\\varepsilon_{\\variabile{q}_1}^{\\textrm{min}}, \\varepsilon_{\\variabile{q}_1}^{\\textrm{max}}, \\varepsilon_{\\variabile{p}_1}^{\\textrm{min}}, \\varepsilon_{\\variabile{p}_1}^{\\textrm{max}}$} \\Comment{Refine the right triangle} \\\\\n%\\Return ;\n%\\EndProcedure\n%\\end{algorithmic}\n%\\end{algorithm}\n%\\\\\n%Let us define a Voronoi diagram in a metric space.\n%The simplest case that we can have is the two-dimensional case that is the case where $X=\\mathbb{R}^2$.\n%The tuple $\\mathcal{S}=\\{1,\\cdots,n\\}\\subset \\mathbb{R}^2$ is now a set of points. The Voronoi diagram of $\\mathcal{S}$ is a subsection of $\\mathbb{R}^2$ such that every other region around a point $p\\in \\mathcal{S}$ contains all points that are closer to $p$ than to every point in $\\mathcal{S}$. A triangulation of the point set $\\mathcal{S}$ is a set of edges $\\mathcal{E}$ whose extremes are points of $\\mathcal{S}$ such that the faces of each triangle are bounded by three edges and any edge that is not in $\\mathcal{E}$ intersects one of the existing edges. The Delaunay triangulation is the dual graph of the Voronoi diagram: it consists of vertices (the points in $\\mathcal{S}$) and it has an edge between two vertices if the two corresponding faces share an edge. \n$\\alpha$-shapes provide a nice mathematical definition of the \\textit{shape} of\na set of points. In two dimensions, $\\alpha$-shapes gives the contour of the point cloud which is approximated by a family of line segments. \nAlthough they are a powerful tool for determining the shape of a point cloud, there exist shapes that are not described well by classical $ \\alpha $-shapes. Indeed, for some point sets there is no value of $\\alpha$ that gives a good approximation of the contour formed by the point cloud. Usually the parameter $\\alpha$ is determined according to the density of the point cloud, therefore, it can be difficult to obtain a good approximation of a shape formed by a non-uniform point set. Furthermore, the $\\alpha$-shape method does not work well when the shape we need to approximate has a sharp turn or a joint, this case will be clarified in Section \\ref{sec:results-Tir-alpha} with an example. \n%In this case $\\alpha$-shapes often give a \"webbed-foot\" appearance at such joints since they improperly connect the adjacent surfaces. \n\\\\ \\indent There are several ways to determine the value of $\\alpha$ \\cite{mandal1997selection}; in the next section we provide a technique that exploits the conservation of \\'{e}tendue in PS. \n%The first step of this method is to make a triangulation of the point cloud.\n%Then the key idea is to compute somehow the point-density of each point and use this to get an approximation of the point density of a triangle. In this way one can reduce the $\\alpha$-value in areas where the triangle's point density (see Equation \\ref{delta_t} for the definition) is higher than average in such a way that is possible to obtain a finer level of detail for areas that have an higher density.\n%More precisely, each point $ \\textbf{p}\\in \\mathcal{S} $ has a local point density defined as\n%\\begin{equation}\n%\\delta (\\textbf{p})= \\sum_{\\textbf{q}\\in \\mathcal{S}}\\Big( 1-\\frac{\\textrm{d}(q,p)}{\\lambda}\\Big) \\qquad \\forall \\textbf{q} \\mbox{\\;\\;such that\\;\\;} \\textrm{d}(\\textbf{p},\\textbf{q})<\\lambda\\,,\n%\\end{equation}\n%where $ \\lambda $ is the constant radius of the local neighborhood and $\\textrm{d}(\\textbf{x},\\textbf{y})$ is the Euclidean distance.\n%When local density is larger than the average, that is when\n%\\begin{equation}\n%\\delta (\\textbf{p}) >\\frac{1}{| \\mathcal{S} |}\\sum_{\\textbf{q}\\in \\mathcal{S}}\\delta (\\textbf{q})\n%\\end{equation}\n%we know some properties about the region surrounding $\\textbf{p}$.\n%For instance, if the point set is uniformly distributed then it is possible to find areas with a high-density in the case where there are two closely separated surfaces.  In point sets of non-uniform distribution, high densities are found when the surface presents a joint discontinuity. The algorithm developed by Teichmann and Capps is structured as follow.\n%After computing density information for each point they make a triangulation of the point set. Then they calculate the average density  $\\delta(t)$ for each triangle $\\Delta_{abc}$ defined as:\n%\\begin{equation}\n%\\delta(t)=\\frac{\\delta(a)+\\delta(b)+\\delta(c)}{3 \\mu}\\,,\n%\\label{delta_t}\n%\\end{equation}\n%where $\\mu$ is the global average density of the entire point set $\\mathcal{S}$.\n%If $\\delta(t)$ is greater than $1$ the density of the point cloud is higher. Hence is necessary to define another value of $\\alpha$:\n%\\begin{equation}\n%\\alpha^{\\;\\prime} = \\frac{\\alpha}{\\delta(t)^\\sigma}\n%\\end{equation} where $\\sigma$ is a value that is adjusted by the user.\n%If  $\\delta$ is less than $1$ the $\\alpha$-value is not modified.\n%In this way it is possible to have a finer precision on the shape formed by the point set where the density is higher than the average density. Hence it is possible to distinguish two separated objects with different density.\n% We want to determine the boundaries in phase space\n% Jorg\n% It is useful to understand whether the approximation is correct\n\\section{Determination of $\\alpha$ using \\'{e}tendue conservation} \\label{sec:Tir_alpha}\nAs mentioned in Section \\ref{sec:PSconcept}, in two-dimensions \\'{e}tendue can be seen as an area in PS. \nTherefore, given an optical system with a source $\\point{S} = [-\\variabile{a}, \\variabile{a}]$, the \\'{e}tendue at the source coincides with the area of source PS, and it is given by:\n\\begin{equation}\\label{eq:etenduesource1}\nU = 4\\n_1 \\variabile{a} \\sin(\\myangle_1^{\\textrm{max}})\\,,\n\\end{equation}\n where $\\variabile{a}$ is the half length of the source, $\\n_1$ the index of refraction of the medium in which the \\point{S} is located and $\\myangle_1^{\\textrm{max}}$ is the maximum value of the angle that the rays make with the normal $\\boldsymbol{\\nu}_1$ of the source.\\\\ \\indent \nFor some optical systems, all the rays emitted by the source arrive at the target, for some others there are also rays that can end at other detectors which are located outside the system. \nIndicating with \\set{R}{$1$}{}$(\\Pi)$ the regions in source PS formed by the rays that reach the target following path $\\Pi$ and with \\set{R}{}{}$(\\Pi)$ the corresponding regions at the target, the \\'{e}tendue $U_1$ at the source restricted to rays that arrive at the target is given by:\n\\begin{subequations}\n\\begin{align}\n\\label{eq:etendueintegralsource}\nU\\big(\\mbox{\\set{R}{$1$}{}}(\\Pi)\\big) = {\\int\\!\\!\\int}_{\\textup{R}_1(\\Pi)} \\textrm{d}\\variabile{q}\\,\\textrm{d}\\variabile{p}.\\\\\\label{eq:etenduesumsource}\nU_1 = \\sum_\\Pi{U\\big(\\mbox{\\set{R}{$1$}{}}(\\Pi)\\big)}, \n\\end{align}\n\\end{subequations}\nwhere $U\\big(\\mbox{\\set{R}{$1$}{}}(\\Pi)\\big)$ is the contribution to the \\'{e}tendue given by the rays inside \n\\set{R}{$1$}{}$(\\Pi)$ in source PS and the sum is over all possible paths $\\Pi$ from the source to the target.\nSimilarly, the \\'{e}tendue at the target of the rays emitted by the source is:\n\\begin{subequations}\n\\begin{align}\n\\label{eq:etendueintegraltarget}\nU\\big(\\mbox{\\set{R}{}{}}(\\Pi)\\big) = {\\int\\!\\!\\int}_{\\textup{R}(\\Pi)} \\textrm{d}\\variabile{q}\\,\\textrm{d}\\variabile{p}.\\\\ \\label{eq:etenduesumtarget}\nU_\\textrm{t}= \\sum_\\Pi{U\\big(\\mbox{\\set{R}{}{}}(\\Pi)\\big)}, \n\\end{align}\n\\end{subequations}\nNote that, since both the source and the target are located in air ($\\n_1=1$), in (\\ref{eq:etendueintegralsource}) and (\\ref{eq:etendueintegraltarget}), and from now on, we omit writing the index of refraction $\\n_1$.\n\\\\ \\indent In order to determine the value of $\\alpha$ in the $\\alpha$-shape procedure that approximates the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ accurately, we use \\'{e}tendue conservation ($U_{\\textrm{t}}= U_1$). The $\\alpha$-shapes method is applied to every region \\set{R}{}{}$(\\Pi)$ for a range of values of $\\alpha$;\n   for each value an approximation of the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ is obtained and\n   the intersection points $\\variabile{q}^{\\textrm{\\,max}}(\\Pi,\\variabile{p})$ and $\\variabile{q}^{\\textrm{\\,min}}(\\Pi,\\variabile{p})$ between $\\partial$\\set{R}{}{}$(\\Pi)$\nand the horizontal lines $\\variabile{p}=\\textrm{const}$, with $\\variabile{p}\\in[-1,1]$, are computed for every path $\\Pi$.\nTherefore, Equation (\\ref{eq:etendueintegraltarget}) becomes:\n\\begin{equation}\\label{eq:etenduetarg}\n U\\big(\\mbox{\\set{R}{}{}}(\\Pi)\\big)= \\int_{-1}^{1}{\\Big(\\variabile{q}^{\\textrm{\\,max}}(\\Pi,\\variabile{p})-\\variabile{q}^{\\textrm{\\,min}}(\\Pi,\\variabile{p})\\Big)} \\,\\textrm{d}\\variabile{p}.\n\\end{equation} In case more than two intersection points between the line $\\variabile{p}=\\textrm{const}$ and $\\partial$\\set{R}{}{}$(\\Pi)$ occur, the previous equation needs to be generalized. Suppose that $\\variabile{r}$ intersection points $\\big(\\variabile{q}^{\\,\\variabile{i}}(\\Pi,\\variabile{p}), \\variabile{p}\\big)_{\\variabile{i} = 1, \\cdots, \\variabile{r}}$ are found. \nOrdering their $\\variabile{q}$-coordinates in ascending order, the target \\'{e}tendue is calculated by:\n\\begin{equation}\\label{eq:etenduetarg1}\n U\\big(\\mbox{\\set{R}{}{}}(\\Pi)\\big) = \\sum_{\\variabile{i} = 1}^{\\variabile{m}}\\int_{-1}^{1}\n{\\Big(\\variabile{q}^{\\,2\\variabile{i}}(\\Pi,\\variabile{p})}-{\\variabile{q}^{\\,2\\variabile{i}-1} (\\Pi, \\variabile{p}) \\Big)}\\,\\textrm{d}\\variabile{p}\\,,\n\\end{equation}\nwhere $\\variabile{m}$ is the integer part of $\\variabile{r}/2$. \nThe integrals in (\\ref{eq:etenduetarg}) and (\\ref{eq:etenduetarg1}) are calculated discretizing the interval $[-1, 1]$\n   into $\\nbin=100$ sub-intervals of equal length, the so-called bins, and using the trapezoidal rule.\n\\\\ \\indent Matching the \\'{e}tendue at the source $U_1$ with the \\'{e}tendue at the target $U_{\\textrm{t}}$, a unique value $\\alpha_{\\textrm{c}}$ of $\\alpha$ is determined. Implementing the $\\alpha$-shapes procedure with $\\alpha = \\alpha_\\textrm{c}$, an approximation of the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ is found and the intensity at the target can be calculated.\\\\ \\indent If two intersection points between $\\variabile{p}=\\textrm{const}$ and $\\partial$\\set{R}{}{}$(\\Pi)$ are found the target intensity is calculated using ($\\ref{eta2}$). If more than two-intersection points are found we use the generalized equation:\n\\begin{equation}\nI_{\\textrm{PS}}(\\variabile{p}) = \\sum_{\\Pi, \\variabile{i} }\\int_{\\variabile{q}^{\\,2\\variabile{i}-1}(\\Pi, \\variabile{p})}^{\\variabile{q}^{\\,2\\variabile{i}}( \\Pi, \\variabile{p})}L(\\variabile{q}, \\variabile{p})\\textrm{d}\\variabile{q} =\n \\sum_{\\Pi, \\variabile{i}}\\big(\\variabile{q}^{\\,2\\variabile{i}}(\\Pi, \\variabile{p})-\n\\variabile{q}^{\\,2\\variabile{i}-1}( \\Pi, \\variabile{p})\\big)\\,,\n\\label{eq:Ips}\n\\end{equation}\nwhere $\\variabile{q}^{\\,2\\variabile{i}}( \\Pi, \\variabile{p})>\\variabile{q}^{\\,2\\variabile{i}-1}( \\Pi, \\variabile{p})$, the summation over $\\Pi$ is for all the paths $\\Pi$ for which the intersection $\\variabile{p} = \\textrm{const}$ and \\set{R}{}{}$(\\Pi)$ is not empty, and the summation over $\\variabile{i}$ is for $\\variabile{i} = 1,2, \\cdots, \\variabile{m}$. The second equation holds as we assume $L(\\variabile{q}, \\variabile{p})=1$.\\\\ \\indent\nTo clarify our idea we apply the method to two different optical systems, the results are presented next.\n%\\\\ \\indent Let us consider the two-faceted cup introduced in Chapter \\ref{chap:raytracing} and depicted in Figure \\ref{fig:cup}. The half length of the source is $\\variabile{a}=2$, the maximum angle is $\\myangle_1^{\\textrm{max}} = \\pi/2$ and \\point{S} is located in air, i.e., $\\n_1=1$. Therefore, the total \\'{e}tendue is $U=8$. For the two-faceted cup all the rays emitted by \\point{S} arrive to \\point{T}, hence from \\'{e}tendue conservation we obtain that $U_{\\textrm{t}} =U_1 = 8$.\n%For some optical systems, not all the rays emitted by the source arrive to the target.  \n% Explain the idea: use etendue conservation\n% Do the example for the two faceted cup\n% Explain the TIR collimator\n\\section{Results for a TIR-collimator}\\label{sec:results-Tir-alpha}\nWe apply the $\\alpha$-shapes method to the set of points in target PS obtained by using PS ray tracing.\nIn this chapter, the procedure is applied to two different kinds of total internal reflection (TIR)-collimators.\\\\ \\indent  \nLet us first describe the TIR-collimator depicted in Figure \\ref{fig:tir}. It is an optical system symmetric with respect to the $z$-axis, it consists of a lens (central curve), two broken lines adjacent to the lens,\ntwo curved lines on each side and a top formed by a horizontal segment. The lens (line $2$) and the broken lines, formed by a collection of three segments (lines $3, 4, \\mbox{ and } 5$ and $9, 10 \\mbox{ and } 11$), are refractive line segments while the curved lines (labeled with $6$ and $8$) are designed in such a way that light is totally internal reflected (which explains the name TIR).\nThe light source $\\point{S}$ (line $1$) and the target $\\point{T}$ (line $12$) are two straight line segments normal to the optical axis.\nThe source $\\point{S}= [-2,2]$ is located at a height $\\variabile{z}_{1} = 0.3$ from the $\\variabile{x}$-axis.\n The target $\\point{T}= [-9.7, 9.7]$ is parallel to the source and is located at a height $ \\variabile{z}= 8.2$. Both \\point{S} and \\point{T} are located in air ($\\n_1=1$).\nThe volume inside the collimator is filled with a material with index of refraction $\\n_2=1.5$ (e.g. glass).\nThe collimator is surrounded by two vertical lines (lines $13$ and $15$) and two horizontal lines ($12$ and $14$) that receive the light emitted from the source; among these the one at the top (line $12$) is assumed to be the target, and it is located at a small distance from the top (line $7$). \n\\begin{figure}[t]\n  \\begin{center}\n  \\includegraphics[width=0.7\\textwidth]{TIR}\n  \\end{center}\n  \\caption{\\textbf{Shape of the TIR-collimator.} Each line of the system is labeled with a number.\n   The shape of the collimator is shown in blue.\n   Three detectors depicted with green lines (surfaces $13$, $14$, and $15$) are located at the left, the right and the bottom of the optical system. The source (line $1$) and the target (line $12$) are depicted in red.}\n%The sagitta of the lens is approximately $1.17$.}\n  \\label{fig:tir}\n\\end{figure}\n\\\\ \\indent\nUsing PS ray tracing explained in Section \\ref{sec:PS_raytracing} with parameters $\\varepsilon_{\\variabile{q}_1}^{\\textrm{max}} = 0.05/4$, $ \\varepsilon_{\\variabile{p}_1}^\\textrm{max} = 0.05/8, $ $\\varepsilon_{\\variabile{q}_1}^\\textrm{min} = 0.8/4$ and $\\varepsilon_{\\variabile{p}_1}^\\textrm{min} = 0.8/8$, around $1.67 \\cdot 10^4$ rays are traced (see Table \\ref{tab:table}). The rays distribution at the source PS is shown in Figure \\ref{fig:sourcePS}, where we depicted the rays that follow the same path with the same color. Seven different paths are found. The yellow rays follow path $\\Pi_1 = (1, 2, 7, 12)$; the green rays follow path $\\Pi_2 ~= ~(1, 4, 6, 7, 12)$; the red rays follow path $\\Pi_3 = (1, 10, 8, 7, 12)$; the magenta rays follow path $\\Pi_4= (1, 3, 7, 12)$ and the blue rays follow path $\\Pi_5= (1, 11, 7, 12)$. The rays located inside the white areas correspond to rays that do not reach the target, they follow either path $\\Pi_6 = (1, 4, 7, 6, 15)$ or path $\\Pi_7 = (1,10,7,8,13)$ and they do not give any contribution to the target intensity.\n\\begin{figure}[t]\n\\label{fig:sourcePS}\n  \\begin{center}\n  \\includegraphics[width=0.8\\textwidth]{source1}\n  \\end{center}\n  \\caption{\\textbf{Distribution of the rays on \\point{S}{}{}}. Around $1.67 \\cdot 10^4$ rays are traced using the triangulation refinement with parameters:\n  $\\varepsilon_\\variabile{q}^\\textrm{max} = 0.8/4 ,$ $ \\varepsilon_{\\variabile{p}}^\\textrm{max} = 0.08/8, $ $\\varepsilon_{\\variabile{q}}^\\textrm{min} = 0.05/4, \\varepsilon_\\variabile{p}^\\textrm{min} = 0.05/8$. Rays that belong to the same region are depicted with the same color. The rays located inside the white areas do not reach the target. The boundaries of the two white regions are approximated by triangles depicted with black lines.}\n \\label{fig:sourcePS}\n\\end{figure}\nNote that, given two adjacent paths, the corresponding regions in \\set{S}{}{} have usually a common boundary. \nSince for this system not all the rays emitted by the source arrive at the target, $U_{\\textrm{t}}$ needs to be compared to the \\'{e}tendue $U_1$ at the source given by only those rays that reach the target (the rays that follow paths $\\Pi_6$ and \n$\\Pi_7$ are discarded). To this purpose, $U_1$ is calculated by removing from the total area $U$ of \\set{S}{}{} those areas occupied by the regions formed by the rays that hit the left or the right detector (white regions in Figure $\\ref{fig:sourcePS}$).  For the TIR collimator in Figure \\ref{fig:tir}, $U$ is obtained from (\\ref{eq:etenduesource1}), the source \\'{e}tendue $U_1$ corresponding to the area covered by the rays that arrive at the target can be approximated by:\n \\begin{equation}\\label{eq:Usource}\n U_{1} = U-2A_{T},\n \\end{equation}\n where $U=8$ and $A_{T}$ is the approximated area of the white triangles in Figure \\ref{fig:sourcePS} surrounded by the black lines.\\\\ \\indent  Next, $U_{\\textrm{t}}$ is calculated several times from (\\ref{eq:etenduetarg1}) where every time the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ are obtained by using $\\alpha$-shapes for a different value of $\\alpha$. \n%An accurate approximation of $\\partial$\\set{R}{}{}$(\\Pi)$ gives a value of $U_{\\textrm{t}}$ close to the exact \\'{e}tendue. \n%Matching $U_1$ with all the approximations of $U_{\\textrm{t}}$ we find the best value $\\alpha_c$ of $\\alpha$ that approximates $\\partial$\\set{R}{}{}$(\\Pi)$ and, therefore, $U_{\\textrm{t}}$. \n\\\\ \\indent To clarify this concept, in Figure \\ref{fig:etendueTS} we provide an example where the source \\'{e}tendue $U_1$ and target \\'{e}tendue $U_{\\textrm{t}}$ are computed from a set of around $1.67\\cdot 10^4$ rays. The approximated source \\'{e}tendue $U_1\\approx 7.77$ is depicted with the red line. The blue line shows how the \\'{e}tendue at the target changes as a function of $\\alpha$. The smallest difference $\\Delta U = |U_1-U_{\\textrm{t}}|$ is obtained using $\\alpha = \\alpha_\\textrm{c} = 0.08$.\n \\begin{figure}[t]\n  \\begin{center}\n  \\includegraphics[width=0.7 \\textwidth]{etendue_alpha_shapes}\n  \\end{center}\n  \\caption{\\textbf{\\'{E}tendue for the TIR-collimator.} $U_\\textrm{t}$ is computed for a range of values of $\\alpha$. $U_1 \\approx 7.77$. The green dot indicates the value of $\\alpha_\\textrm{c} = 0.08$ which gives a good approximation of the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ at the target.\n   Around $1.67 \\cdot 10^4$ rays have been traced using PS ray tracing.\n  }\n  \\label{fig:etendueTS}\n\\end{figure}\nIn Figure \\ref{fig:targetPS} we show the boundaries \n$\\partial$\\set{R}{}{}$(\\Pi)$ in target PS obtained tracing $1.67\\cdot10^4$ rays and using $\\alpha_\\textrm{c}=0.08$.\n  \\begin{figure}[t]\n  \\begin{center}\n  \\includegraphics[width=0.7\\textwidth]{target_alpha_shapes}\n  \\end{center}\n  \\caption{\\textbf{Target PS representation.} A set of $1.67 \\cdot 10^4$ rays are traced.\n  Rays that follow the same path are depicted with the same color. The choice of the colors is consistent with Figure $\\ref{fig:sourcePS}$. The boundaries $\\partial$\\set{R}{}{}$(\\Pi)$ are computed through the $\\alpha$-shapes method with $\\alpha = \\alpha_\\textrm{c} = 0.08$.}\n  \\label{fig:targetPS}\n\\end{figure}\nThe target intensity $I_{\\textrm{PS}}(\\variabile{p})$ for $\\variabile{p}\\in[-1,1]$ is obtained from Equation (\\ref{eta2}). \\\\ \\indent\nTo validate our method we compare the PS intensity with the QMC intensity. \nTo this purpose a partitioning $P_2:-1=\\variabile{p}_{0}<\\variabile{p}_1<\\cdots<\\variabile{p}_{\\nbin}=1$ of the interval $[-1,1]$ into $\\nbin=100$ bins is considered. \nThe averaged and normalized PS intensity $\\hat{I}_{\\textrm{PS}}$ is calculated for every \n$\\big(\\variabile{p}^{\\variabile{h}+1/2} = \\frac{1}{2}(\\variabile{p}^{\\variabile{h}+1}+ \\variabile{p}^{\\variabile{h}})\\big)_{\\variabile{h}=0, \\cdots, \\nbin-1}$ dividing the PS averaged intensity by the total \\'{e}tendue:\n\\begin{equation}\\label{eq:normalized_PS_intensity}\n\\hat{I}_{\\textrm{PS}}(\\variabile{p}^{\\variabile{h}+1/2}) = \\frac{1}{U_{\\textrm{t}}}\\int_{\\variabile{p}_{\\variabile{h}}}^{\\variabile{p}_{\\variabile{h}+1}} I_{\\textrm{PS}}(\\variabile{p})\\textrm{d}\\variabile{p}.\n\\end{equation}\nThe averaged and normalized QMC intensity $\\big(\\hat{I}_{\\textrm{QMC}}(\\variabile{p}^{\\variabile{h}+1/2})\\big)_{\\variabile{h} = 0, \\cdots, \\nbin-1}$ is given by\n\\begin{equation}\\label{eq:normalized_MC_intensity}\n\\hat{I}_{\\textrm{QMC}}(\\variabile{p}^{\\variabile{h}+1/2}) = \\frac{\\nrays[\\variabile{p}^{\\variabile{h}},\\variabile{p}^{\\variabile{h}+1})}{\\nrays[-1,1)} \n\\qquad \\mbox{ for } \\variabile{p}\\in[\\variabile{p}^{\\variabile{h}}, \\variabile{p}^{\\variabile{h}+1}).\n\\end{equation} \nBoth approximate intensities $\\hat{I}_{\\textrm{A}} (\\textrm{A} = \\textrm{PS}, \\textrm{QMC})$ are compared to an intensity $\\hat{I}_{\\textrm{ref}}$ taken as a reference. \n\nFor some optical systems, there is an explicit solution for the target intensity, but this is not the case of the TIR-collimator.\nTherefore, a QMC simulation with $10^7$ rays is used to obtain the averaged normalized intensity $\\hat{I}_{\\textrm{ref}}$.\nThe intensity profile $\\hat{I}_{\\textrm{PS}}\n$ obtained using PS ray tracing with $8.3\\cdot 10^4$ rays and $\\alpha= \\alpha_\\textrm{c} = 0.06$ is depicted in Figure \\ref{fig:intensityMCPS} with a red line.\n$\\hat{I}_{\\textrm{PS}}$ is hardly distinguishable from $\\hat{I}_{\\textrm{ref}}$ which is indicated with the dashed and blue line in Figure $\\ref{fig:intensityMCPS}$.\\\\ \\indent\n  \\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{intensity_alpha_shapes}\n\\caption{\\textbf{Target intensity profile.}\nThe exact intensity is computed using the QMC method for a set of $10^7$ rays. For the PS intensity a set of $8.3\\cdot 10^4$\nrays is considered and $\\alpha_\\textrm{c} = 0.06$ is chosen to compute the boundaries $\\partial$\\set{R}{}{}$(\\Pi)$.}\n  \\label{fig:intensityMCPS}\n\\end{figure}\nFinally, we calculate the error between $\\hat{I}_{\\textrm{A}}$ and $\\hat{I}_{\\textrm{ref}}$, defined as:\n\\begin{equation}\\label{eq:error}\n\\mbox{error} = \\frac{\\sum_{\\variabile{h}= 1}^{\\nbin}| \\hat{I}_{\\textrm{A}}(\\variabile{p}^{\\variabile{h}+1/2}) - \\hat{I}_{\\textrm{ref}}(\\variabile{p}^{\\variabile{h}+1/2})|}{\\nbin}.\n\\end{equation}\nThe QMC and PS intensities are calculated several times increasing the number of rays to improve the accuracy.\nTable \\ref{tab:table} and \\ref{tab:table2} describe how the number of rays traced affects the error. \nIn Table \\ref{tab:table} the correlation between $\\alpha_\\textrm{c}$ and the number of rays is evident.\n%determined by the values of $\\varepsilon^{\\textrm{min}}_\\variabile{p}$, $\\varepsilon^{\\textrm{min}}_{\\variabile{q}}$, \n%$\\varepsilon^{\\textrm{max}}_{\\variabile{p}}$ and $\\varepsilon^{\\textrm{max}}_{\\variabile{q}}$. \nNote that increasing the number of rays the value of $\\alpha_\\textrm{c}$ and the corresponding error decrease. \n\\begin{table}[htbp] \\label{tab:table}\n\\centering\n\\caption{\\bf Errors of the PS intensity}\n\\begin{tabular}{lllllll}\n \\hline  Number \\\\ of rays\\;  & $\\varepsilon^{\\textrm{max}}_{\\variabile{q}} $  & $\\varepsilon^{\\textrm{min}}_{\\variabile{q}} $   \\;     & $\\varepsilon^{\\textrm{max}}_{\\variabile{p}}$\\;\n  & $\\varepsilon^{\\textrm{min}}_\\variabile{p}$\\; & $\\alpha_\\textrm{c}$  & PS error \\\\\n  \\hline \n $3\\,339$ & $0.8$  & $0.05$  & $0.8/2$  & $0.05/2$ & $0.14$ & $1.47\\cdot10^{-3}$ \\\\\n$7\\,567$  & $0.8/2$  & $0.05/2$  & $0.8/4$  & $0.05/4$ & $0.10$ & $3.01\\cdot 10^{-4}$  \\\\\n$16\\,755$  & $0.8/4$  & $0.05/4$  & $0.8/8$  & $0.05/8$ & $0.08$ & $8.60\\cdot 10^{-5}$ \\\\\n $83\\,005$ & $0.8/16$  & $0.05/16$  & $0.8/32$  & $0.05/32$ & $0.06$ & $1.31\\cdot 10^{-5}$ \\\\\n \\hline\n \\end{tabular}\n \\label{tab:table}\n \\end{table}\n\\\\ \\indent In Table \\ref{tab:table2} the numerical results of QMC ray tracing are reported.\nIncreasing the number of rays traced, the error gradually decreases.\n\\begin{table}[htbp]\n\\centering\n\\caption{\\bf Error of the QMC intensity}\n\\begin{tabular}{ll} \\hline   Number of rays\\; & QMC error\\\\\n \\hline $10^3$  & $1.65\\cdot10^{-3}$ \\\\\n$10^4$  & $3.96\\cdot 10^{-4}$  \\\\\n $10^5$  & $6.36\\cdot 10^{-4}$ \\\\ \n$10^6$  & $1.02\\cdot 10^{-5}$ \\\\\n \\hline\n \\end{tabular}\n \\label{tab:table2}\n \\end{table}\n\\noindent In Figure $\\ref{fig:error}$, the results listed in Table $\\ref{tab:table}$ and Table $\\ref{tab:table2}$ are shown. The red line depicts the convergence of the PS error and the blue line indicates the QMC error.\n\\begin{figure}[t]\n  \\begin{center}\n  \\includegraphics[width=0.7\\textwidth]{error_alpha_shapes_vs_qmc_curved}\n  \\end{center}\n  \\caption{\\textbf{PS and QMC errors as a function of the number of rays}\n  The horizontal dotted line shows that an error equal to $1.31\\cdot  10^{-5}$ can be obtained tracing almost $10$ times fewer rays in phase space.}\n  \\label{fig:error}\n\\end{figure}\n%Note from Figure \\ref{fig:error} that the error for the QMC method decreases as $\\frac{1}{\\sqrt{\\nrays}}$, while for the PS simulation the speed of convergence is much higher.\\\\ \\indent\nWe need to emphasize that the convergence of the error of PS ray tracing for increasing $\\nrays$ may change according to the design of the optical system.\nThis is because the approximation of the boundaries in PS depends on the accuracy of the $\\alpha$-shapes method.\nThe $\\alpha$-shapes procedure is unable to properly detect the boundaries of regions with a sharp turn if not enough points are given\n\\cite{teichmann1998surface}. Indeed, on the one hand a low density requires a large value of $\\alpha$ to accept the triangles in a region, on the other hand,\n choosing $\\alpha$ too large, the shape of the region could be destroyed. Increasing $\\alpha$ more triangles are kept and triangles inside the regions \\set{R}{}{}$(\\Pi)$ could be taken into account creating holes in \\set{R}{}{}$(\\Pi)$.\n\\begin{figure}[t]\n\\centering\n\\begin{subfigure}{.48\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{boundaries_alpha1}\n  \\caption{Boundaries approximation obtained using the $\\alpha$-shapes method with $\\alpha_\\textrm{c} = 0.3$ (black lines).}\n\\end{subfigure}\n\\hfill\n\\begin{subfigure}{.48\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{boundaries_alpha2}\n  \\caption{Boundaries approximation obtained using the $\\alpha$-shapes method with $\\alpha_\\textrm{c} = 0.31$ (black lines).}\n\\end{subfigure}\n\\caption{\\textbf{Approximated boundaries at the target PS.} Tracing $3339$ rays and using $\\alpha$-shapes, the boundaries cannot be approximated well. \nA small change of the parameter $\\alpha$ leads to a completely different approximation of the boundaries.}\n\\label{fig:Tir1}\n\\end{figure}\nFigure $\\ref{fig:Tir1}$ clarifies this concept showing that the region formed by rays that hit the lens is hard to approximate when there is a small number of rays inside the region. Consequently either a region bigger than the area covered by the rays is obtained or some triangles which are not part of the boundaries are included in the triangulation. This results in an inaccurate intensity (either too high or to low). To obtain a good approximation of the boundaries of these kinds of patches more rays have to be traced. The PS error decreases very fast increasing the number of rays (see Table\n \\ref{tab:table} and Figure \\ref{fig:error}).\n \\\\\\indent To show how the error plot changes according to the regularity of the shape of the regions $\\partial$\\set{R}{}{}$(\\Pi)$, we consider another example of a TIR-collimator.\n Figure $\\ref{fig:Tir1}$ shows that the hardest region to approximate is given by those rays that follow path $\\Pi_1 ~=~ (1,2,7,12)$.\n We therefore consider a TIR-collimator with a flatter lens and with the target located at a smaller distance to the top (see Figure $\\ref{fig:analyticlens}$). \nThe source $\\point{S}= [-2,2]$ (surface number $1$) is located in air at a height $\\variabile{z}_1 = 0.3$ from the $x$-axis.\n       The target $\\point{T}= [-9.7, 9.7]$ (surface $12$) is parallel to the source and is located in air at a height $ \\variabile{z}= 7.85$.\n       The shape of the collimator is shown as a blue line.\n       Three detectors depicted with green lines (surfaces $13$, $14$, and $15$) are located at the left, the right and the bottom of the optical system.\n \\\\ \\indent Tracing around $3\\cdot10^3$ rays using PS ray tracing, we obtain the target rays distribution shown in Figure $\\ref{fig:Tir2}$. \nCompared with the distribution in Figure \\ref{fig:targetPS}, we note that the extremities at top and bottom of the region formed by the rays that hit the lens are less pronounced.\nMoreover a target located very close to the top makes the shape of that region less stretched along the $\\variabile{q}$-axis.\nTherefore, it is expected that the $\\alpha$-shapes method performs better in this case.\n\\begin{figure}[t]\n  \\begin{center}\n  \\includegraphics[width=0.7\\textwidth]{tir_analytic2}\n   \\end{center}\n    \\caption{\\textbf{Shape of the TIR-collimator.} Each line of the system is labeled with a number.\n       $n_1 = 1$ is the refraction index of the medium (air) where the source and the target are located, and\n       $n_2 = 1.5 $ the refraction index of the medium (glass) inside the optical system.} \n%The sagitta of the lens is equal to $0.6$.}\n \\label{fig:analyticlens}\n\\end{figure}\n \\begin{figure}[t]\n  \\begin{center}\n       \\includegraphics[width=0.7\\textwidth]{boundaries_alpha3}\n   \\end{center}\n        \\caption{\\textbf{Target phase space for the TIR-collimator depicted in\n        Figure \\ref{fig:analyticlens}.} The black line depicts the best approximation of $\\partial$\\set{R}{}{}$(\\Pi)$ for $3\\cdot 10^3$ rays. \nThe $\\alpha$-shapes method gives an accurate approximation of the boundaries for $\\alpha_\\textrm{c} = 0.9$.}\n  \\label{fig:Tir2}\n\\end{figure}\n\\\\ \\indent PS and QMC ray tracing are implemented for the TIR-collimator in Figure \\ref{fig:analyticlens}. The approximated intensities $\\hat{I}_{\\textrm{A}}$ $(\\textrm{A} = \\textrm{PS}, \\textrm{QMC})$ are compared to the reference intensity $\\hat{I}_{\\textrm{ref}}$ (QMC ray tracing with $10^7$ rays).\nPS error is depicted with the red line and, QMC error is depicted with the blue line. \\\\ \\indent\n% Lets indicate with $\\big(\\hat{I}_{\\textrm{A}, n}\\big)_{n \\in \\mathbb{N}}$ the sequence of the approximated intensity. Every term of the sequence is calculated by increasing the number of rays, for example $\\hat{I}_{\\textrm{A}, 1}$ is computed tracing $\\nrays = 10$ rays,   $\\hat{I}_{\\textrm{A}, 2}$ is computed tracing $\\nrays = 100$ rays, and so on. The speed or rate of convergence of the approximate intensity $\\big(\\hat{I}_{\\textrm{A}, n}\\big)$ describes how quickly the terms of sequence $\\big(\\hat{I}_{\\textrm{A}, n}\\big)$ converge to the reference intensity $\\hat{I}_{\\textrm{ref}}$ by increasing the number of rays. Suppose $m$ is a real number, the sequence $\\big(\\hat{I}_{\\textrm{A}, n}\\big)$ converges to $\\hat{I}_{\\textrm{ref}}$ if\n%\\begin{equation}\n%\\lim_{\\nrays\\rightarrow \\infty} \\frac{|\\hat{I}_{\\textrm{A}, n+1}-\\hat{I}_{\\textrm{ref}}|}{|\\hat{I}_{\\textrm{A}, n}-\\hat{I}_{\\textrm{ref}}|^m} = \\mu\n%\\end{equation}\n%and $\\mu$ is called the rate of convergence and $m$ is the order of convergence. For $m\\in[0,1]$ we have the linear convergence, for $m=2$ the quadratic convergence, etc. \n%\\\\ \\indent\nNumerical results show that, for the TIR-collimator in Figure \\ref{fig:analyticlens}, the number of rays needed to achieve an error of the order of $10^{-5}$ is reduced using PS ray tracing compared with QMC ray tracing. Furthermore, for a relatively small number of rays, the $\\alpha$-shapes method performs better for a TIR-collimator with a flatter lens. \n\\begin{figure}[t]\n \\begin{center}\n   \\includegraphics[width=\\textwidth]{error_alpha_shapes_vs_qmc_flat}\n    \\end{center}\n     \\caption{\\textbf{PS and QMC errors.}}\n%The red line depicts the error using the $\\alpha$-shapes method to compute the boundaries. \n%The blue line shows the error between the Monte Carlo intensity and the exact intensity.\n%     The dashed black line represents a straight line with slope $-\\frac{1}{2}$.\n%   The dashed blue line represents a straight line with slope $-1$.}\n \\label{fig:error2}\n\\end{figure}\n\\section{Conclusion}\nThe aim of this chapter was to detect the boundaries of the regions formed by the rays traced using $\\alpha$-shapes.\\\\\n\\indent First, we reported some theory about $\\alpha$-shapes which are commonly used to approximate the shape formed by a point cloud. \nThese methods depend on a parameter $\\alpha$ that, in most cases, can be determined only by simulations. \n\\\\ \\indent Using \\'{e}tendue conservation, we developed a new approach to detect the value of $\\alpha$ that better approximates the boundaries in target PS. \nWe applied $\\alpha$-shapes to two different kinds of TIR-collimators. The target PS intensity was computed for both systems several times increasing every time the number of rays traced. Finally, the corresponding errors between the approximated intensities and a reference intensity was calculated. We observed that PS ray tracing allows tracing far less rays compared to QMC ray tracing. Numerical results show that using PS ray tracing the desired accuracy can be achieved reducing significantly the number of rays traced.\\\\ \\indent \nHowever, we observed that the error convergence for PS ray tracing strongly depends on the design of the optical system (shapes of the region in target PS). Indeed, the accuracy of the intensity is related to the precision of the $\\alpha$-shape, that is, to the choice of the parameter value of $\\alpha$. For more complicated shapes in PS, more rays need to be traced for a good boundaries reconstruction.\\\\ \\indent\nIn order to remove the dependence of PS ray tracing on the parameter $\\alpha$, we will construct another procedure to detect the boundaries of the regions in target PS. \nThe new technique is based on the triangulation refinement explained in Section \\ref{sec:PS_raytracing}. The details are explained in the next chapter and numerical results are reported for several optical systems. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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": "f72c87629b2bec707b076697a8a532e26cee296f", "size": 49789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Boundaries.tex", "max_stars_repo_name": "melaniafilosa/ps_raytracing", "max_stars_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_stars_repo_licenses": ["MIT"], "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/Boundaries.tex", "max_issues_repo_name": "melaniafilosa/ps_raytracing", "max_issues_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_issues_repo_licenses": ["MIT"], "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/Boundaries.tex", "max_forks_repo_name": "melaniafilosa/ps_raytracing", "max_forks_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_forks_repo_licenses": ["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.4465020576, "max_line_length": 1067, "alphanum_fraction": 0.7264255157, "num_tokens": 15156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6458227914045485}}
{"text": "\\documentclass[12pt]{article}\n\n\\title{Math Foundations}\n\\author{Abel Doñate}\n\\date{}\n\n\\usepackage{amsmath}\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\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\\newpage\n\n\\section{Useful techniques to solve problems}\n    \\subsection{The Well ordered principle and Descent to infinity}\n    The well ordering principle tells us that we cannot have a sequence of non-negative integers such that $a_1>a_2>...$.\n    This is useful to apply in descent to infinite proofs. \\\\ \\\\\n    Suppose you have a problem in which you are given a condition and you have to check what numbers satisfy the condition. In this case you can apply descent to infinite:\n    \\begin{itemize}\n        \\item[1)] Find a condition that guarantees you that a set of numbers satisfy the condition if and only if another set of numbers that are strictly less then the original set satisfy the condition.\n        \\item[2)] By the Well ordering principle, reason that it is impossible to keep descending infinitely many times , so the sequence must stop somewhere.\n        \\item[3)] If we can apply it many times, that means that there is no set of numbers that satisfy the condition (or only does the trivial ones like $(0,0,0)$).\n    \\end{itemize}\n    A good example is to find the triples $(a, b, c)$ that satisfy $a^3 + 2b^3 = 4c^3$.\\\\\n    Because the right hand side (RHS) is even, then $a$ must be even $\\implies a=2x$. \\\\\n    Dividing by $2$ the equation is $4x^3 + b^3 = 2c^3$ \\\\\n    Because RHS is even, then $b$ must be even $\\implies b=2y$. \\\\\n    Dividing by $2$ the equation is $2x^3 + 4y^3 = c^3$ \\\\\n    Because LHS is even, then $c$ must be even $\\implies c=2z$. \\\\\n    Dividing by $2$ the equation is $x^3 + 2y^3 = 4z^3$ \\\\\n    \n    We observe that we are left with the original case. That tells us that $(a, b, c)$ only holds if $(a/2, b/2, c/2)$ also holds. Applying descent to infinity, we assure that there is no solution except the trivial one $(0,0,0)$\n    \n    \\subsection{Mathematical induction}\n    We can prove lots of types of problem by this simple principle. \\\\\n    \n    Suppose we have to prove that a given condition holds for every natural number. Then one way to prove it is to check if holds for $k=1$, and then prove that if it holds for $k$, then, it must hold for $k+1$. \\\\\n    \n    The sketch of the steps is the following:\n    \\begin{itemize}\n        \\item[1)] \\textbf{Base case.} First we prove that the condition holds for $k=1$ (or the first element of the set you are given).\n        \\item[2)] \\textbf{Induction statement.} Now we prove that if $k$ holds, then $k+1$ also holds.\n        \\item[3)] \\textbf{Proof.} Finally you reason that the problem has been solved by the principle of mathematical induction \n    \\end{itemize}\n    \n    \\subsection{Double counting}\n    Sometimes it is useful to exploit different perspectives of a problem. If your task is to prove an equivalence, perhaps the easiest way to do it is double counting, or compute the expression in two different ways, but showing that both are equal.\n    \n\\section{Inequalities}\n    \\subsection{Means inequalities}\n    We have the chain of inequalities $HM\\leq GM\\leq AM\\leq QM$:\n    \\[\\frac{1}{\\frac{1}{a}+\\frac{1}{b}+\\frac{1}{c}}\\leq \\sqrt[3]{abc}\\leq \\frac{a+b+c}{3}\\leq \\sqrt{\\frac{a^2+b^2+c^2}{3}} \\]\n    The equality holds when $a=b=c$.\n    \n    \\subsection{Cauchy's inequality}\n    \\[\\vec{a}\\cdot \\vec{b}\\leq |\\vec{a}||\\vec{b}| \\implies \\left(\\sum{a_ib_i}\\right)^2 \\leq \\left(\\sum{a_i^2}\\right)\\left(\\sum{b_i^2}\\right) \\]\n    \n    \\subsection{Chebyshev's inequality}\n    If we have two ordered vectors (both increasing or decreasing):\n    \\[n\\sum{a_ib_i}\\geq \\left(\\sum{a_i}\\right)\\left(\\sum{b_i}\\right)\\geq n\\left(\\sum{a_ib_{n+1-i}}\\right)\\]\n    \n    \\subsection{Jensen's inequality}\n    Let $f$ be a convex function (i.e. $f''\\geq 0$). Then:\n    \\[f\\left(\\sum{\\alpha_ix_i}\\right) \\leq \\sum{\\alpha_i f(x_i)} \\ \\ \\ \\ \\ where \\ \\ \\sum{\\alpha_i}=1\\]\n\n\n\\section{Combinatorial numbers}\n    The number of ways to choose k elements in a set of n elements is \\textit{n choose k}:\n    \\[\\binom{x}{k}=\\frac{n!}{k!(n-k)!}\\]\n    Some of the properties of combinatorial numbers are:\n    \\begin{align} \n        (x+y)^n &= \\sum{\\binom{n}{k}x^ny^{n-k}} \\\\\n        \\binom{n+m}{k} &= \\sum{\\binom{n}{i}\\binom{m}{k-i}} \\ \\ \\ \\text{(Vandermonde's identity)}\n    \\end{align}\n    \n    \\begin{wrapfigure}{r}{0.23\\textwidth}\n        \\centering\n        \\includegraphics[width=0.23\\textwidth]{pascal}\n    \\end{wrapfigure}\n    \n    These numbers appear also in Pascal's triangle. The ith element of the nth row (begining both with 0) is $\\binom{n}{i}$.\\\\ \\\\\n    An extension of \\textit{n choose k} is the following:\n    \\[\\binom{n}{k_1 \\cdots k_m}=\\frac{n!}{k_1!\\cdots k_m!}\\]\n    and it appears in the multinomial theorem:\n    \\[(x_1+\\cdots +x_m)^n=\\sum_{k_1+ \\cdots +k_m=n}{\\binom{n}{k_1 \\cdots k_m}x_1^{k_1}\\cdots x_m^{k_m}}\\]\n\n\n\\section{Sets}\n    \\subsection{Operations and De Morgan's Law}\n    Main operations\n    \\begin{itemize}\n    \t\\item Union. $A \\cup B$\n    \t\\item Intersection $A \\cap B$\n    \t\\item Difference $A \\setminus B$ or $A-B$\n    \t\\item Symmetric difference $A \\bigtriangleup B = (A\\cup B)-(A\\cap B)$\n    \t\\item Complement. $\\bar{A}$\t\n    \\end{itemize}\n    \\textbf{De Morgan's Law:}\n    \\begin{itemize}\n    \t\\item $\\overline{A \\cup B}=\\bar{A}\\cap \\bar{B}$\n    \t\\item $\\overline{A\\cap B}=\\bar{A}\\cup \\bar{B}$\n    \\end{itemize}\n\n\t\\subsection{Canonical decomposition}\n\tEvery function $f$ can be decomposed in a surjective, bijective and injective functions. \t\tFor instance: $f=i \\circ b \\circ \\pi$.\n\t\\begin{itemize}\n\t\t\\item $\\pi$ maps to its equivalence class\n\t\t\\item $b$ maps to the function of every equivalence class\n\t\t\\item $i$ maps to itself\n    \\end{itemize}\n    \\section{Algebraic structures}\n\t\\subsection{Group}\n\tA group is a set with one binary operation $(S,\\star)$ that must satisfy:\n\t\\begin{itemize}\n\t\t\\item Closure under $\\star$\n\t\t\\item Associative $(a\\star b)\\star c=a\\star (b\\star c)$\n\t\t\\item Identity element $e$ such that $e\\star a=a\\star e=a$\n\t\t\\item Inverse element. Every $a$ has an inverse $a^{-1}$\n\t\\end{itemize}\n\t\n\tIf the group is commutative $a\\star b= b\\star a$, then is called \\textbf{Abelian}. \\\\\n\t\n\tExamples of abelian group are $\\mathbf{Z}_n$ (group whose elements are $0, 1, \\cdots, n-1$, and the operation is the sum modulo n), or the group or rotations of a regular polygon. \\\\\n\t\n\tAn example of non-abelian group is the group of rotations of a cube. The proof is left to the reader.\n\t\n\t\\subsection{Ring}\n\tA Ring is a set with two binary operations $(S,\\star, \\top)$ that must satisfy:\n\t\\begin{itemize}\n\t\t\\item $(S, \\star)$ is an abelian group\n\t\t\\item Distributive $a\\top (b\\star c)= (a\\top b) \\star (a\\top c)$\n\t\t\\item Identity elements $e_\\star, e_\\top$\n\t\\end{itemize}\n\t\n\tIf $e_\\star \\neq e_\\top$ and $a\\top b\\neq e_\\star$, then is called an \\textbf{Integral domain}.\\\\\n\t\n\tOne example of a Ring is $\\mathbf{Z}$ with usual sum and product.\\\\\n\t\n\t$\\mathbf{Z}_p$ with $p$ prime is an example of an integral domain. $\\mathbf{Z}_6$, because 6 is not prime, is not an integral domain, as $2\\times 3=0=e_+$. \n\t\n\t\\subsection{Field}\n\tA field is a ring with no inverse for $e_\\star$ under $\\top$.\\\\\n\t\n\tThe most common example is $\\mathbf{R}$. Observe that the element $0=e_+$ has no inverse under multiplication.\n\t\n\\section{Stereographic projection}\n    \\begin{wrapfigure}{r}{0.30\\textwidth}\n        \\centering\n        \\includegraphics[width=0.30\\textwidth]{stereo1}\n    \\end{wrapfigure}\n    \n    The stereographic projection maps every point in a sphere except the upper pole to the $XY$ plane. On the other hand we can take the inverse stereographic projection, that maps every point in the plane to the sphere (except the upper pole). \\\\\n    \n    This map is achieved by drawing a line from the upper pole to the point in the sphere and taking the intersection with the $XY$ plane. \\\\\n    \n    If we define the coordinates of the plane as $x, y$ as usual and the coordinates of the sphere as $\\alpha, \\beta, \\gamma$, we can derive the following equations:\n    \\[F(\\alpha, \\beta, \\gamma)=\\left(\\frac{\\alpha}{1-\\gamma}, \\frac{\\beta}{1-\\gamma}\\right) \\ \\ \\ \\\n    F^{-1}(x, y)=\\left(\\frac{2x}{x^2+y^2+1}, \\frac{2y}{x^2+y^2+1}, \\frac{x^2+y^2-1}{x^2+y^2+1}\\right)\\]\n\n\\end{document}\n", "meta": {"hexsha": "4166328c0fed053282404ad2301c5822b00ddae1", "size": 8442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Cuatri 1A/Foundations/Foundations.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/Foundations.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/Foundations.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": 48.7976878613, "max_line_length": 250, "alphanum_fraction": 0.6715233357, "num_tokens": 2660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743735019595, "lm_q2_score": 0.8723473730188543, "lm_q1q2_score": 0.6456891703003107}}
{"text": "\\section{Background}\n\n\\subsection{The original multi-head attention\rmechanism}\n\nThe scaled dot-product attention proposed by\r\\citet{vaswani2017attention} transforms the vectorial embedding $\\vec{Y}_i$ of a token as a\r function of a sequence of other embedding $\\vec{X}_j$. Where\r $\\vec{Y}_i$ and $\\vec{X}_j$ are all vectors of size $D$. A key\r$\\vec{K}_j$ and value $\\vec{V}_j$ are attributed to each vector\r$\\vec{X}_j$, and query $\\vec{Q}_i$ is attributed to $\\vec{Y}_i$.\r The vectors are obtained by linear projection from dimension $D$ to $d$ using three matrices of learnable parameters. The new vector\r $\\vec{y}_i'$ is a weighted sum of the $\\vec{V}_j$. The weights are\r scores of matching between the query $\\vec{Q}_i$ and the keys\r$\\vec{K}_j$, calculated as the dot product between the two vectors.\rThey are also \\emph{softmaxed} to sum up to 1. The transformation of $L_Q$\rvectors $\\vec{Y}_i$ as a function of $L_K$ vectors $\\vec{X}_j$ can\r be efficiently computed with matrix multiplications:\r\n\n\\begin{equation}\nA = \\mathrm{softmax}\\left(\\frac{Q \\times K^T}{\\sqrt{d}}\\right) \\times V\n\\end{equation}\n\nWith $Q$ a matrix of shape $(L_Q, d)$, $K$ a matrix of shape\r $(L_K, d)$ and $V$ a matrix of shape $(L_K, d)$. The $\\sqrt{d}$\rat the denominator is a scaling factor used to avoid saturation in the\rexponential terms of the softmax function.\r\n\nThe multi-head attention performs $h$ different projections into spaces\r of dimension $d = D/h$. The resulting vector $\\vec{Y}_i'$ is the\rconcatenation of the $h$ vectors $\\vec{y}_i'$ obtained. Thus the\rembedding dimension is preserved. Using multiple heads was found\rbeneficial by the authors over using a single head of dimension\r$d = D$.\r\n\nDuring training, the cross entropy of the $n^{th}$ predicted token is\r calculated assuming all previous tokens have been generated correctly.\r This enables to parallelize training completely without need for\rrecurrence. However as the $n^{th}$ token should not depend of the\rfollowing tokens, the cells in the upper right corner of the score\rmatrix are set to $-\\infty$ such that after the softmax they are equal\rto 0, and the rows still sums up to 1.\n\n\\subsection{Improving Transformer scalability with sequence\rlength}\n\nThe original attention mechanism requires the computation of a score\rmatrix $Q \\times K^T$ of shape $(L_Q, L_K)$, with complexity\r$O(L_QdL_K)$. If the query and key sequence lengths are multiplied by\rtwo, then the memory used and computation time are multiplied by 4. To\rimprove the scalability of the transformer with sequence length, several axis of research have been explored.\r\n\n\\citet{kitaev2020reformer} proposed\rthe Reformer's architecture, which uses an hash-bucketting algorithm to\rreduce the complexity of the original multi head attention operation\rfrom $O(L^2)$ to $O(L\\log(L))$.\r\n\n\\citet{dai2019transformerxl} proposed the\rTransformer-XL's architecture, which cuts the sequence in segments of\rlength L. The model predicts each stage of the current segment as a\rfunction of the previous and current segment. All the segments are\rcomputed sequentially with a recurrence mechanism. The complexity is linear\rwith sequence length, but the computation cannot be completely\r parallelized due to the recurrence mechanism, although more than a RNN,\ras segments can be computed in one go.\r\n\nOther publications explored using a sparse attention matrix, such as the\r Longformer by \\citet{beltagy2020longformer} and the Big Bird model by\r \\citet{zaheer2021big}. As each\rtoken attends to a fixed number of all other tokens, the scalability is\rimproved. These sparse attention models however require custom\roperations implemented in CUDA.\r\n\nSome other works propose to modify the attention mechanism to be\r compatible with linear complexity. The Linformer by\r\\citet{wang2020linformer} projects the\r key and values onto a smaller sequence length dimension with matrix\r multiplication. It cannot however generalize to sequences longer than\r during training, as the weights of the projection for such tokens would\r be undefined.\r\n\n\\citet{shen2020efficient} proposed to\r replace the softmax attention score.\r $A = \\mathrm{softmax}\\left(\\frac{Q \\times K^T}{\\sqrt{d}}\\right) \\times V$ is\rchanged into $A = \\rho(Q) \\times \\rho(K)^T \\times V$. With $\\rho$\rthe softmax function along the embedding dimension. Thanks to matrix\rmultiplication commutativity, the order of the operations can be chosen.\rIf $Q$, $K$ and $V$ are of shape $(L_Q, d)$, $(L_K, d)$ and\r$(L_K, d)$ respectively, the complexity of\r$(\\phi(Q) \\times \\phi(K)^T) \\times V$ is $O(L_Q \\times d \\times L_K)$ whereas the complexity of\r$\\phi(Q) \\times (\\phi(K)^T \\times V)$ is\r$O\\left(max(L_Q, L_k) \\times d^2 \\right)$. The right-side-first\roperation is linear in complexity with sequence length. The shape of the\rintermediate result matrix is also changed, allowing to scale the better\rin memory requirements as well. The original \\emph{softmaxed} attention score\rmatrix was giving rows of positive scores that sum to 1. With this\rchange the elements of the score matrix remain positive as $\\phi(Q)$\rand $\\phi(K)^T$ are matrices of positive values, but the rows of the\rscore matrix does not sum up to 1. This work also does not give a linear complexity formulation for masked attention. If the right-side-first\rscheme is adopted, the attention score matrix\r$\\phi(Q) \\times \\phi(K)^T$ is never explicitly computed, and can't be\rmasked.\r\n\nBuilding on this idea of commutative attention function proposed by\r\n\\citep{shen2020efficient}, \\citet{katharopoulos2020transformers} introduced their kernerlized attention function as:\r\n\n\\begin{equation}\nA = \\frac{\\phi(Q) \\times \\phi(K)^T}{\\sum_j \\left( \\phi(Q) \\times \\phi(K)^T \\right)} \\times V\n\\end{equation}\n\nThe function $\\phi$ is applied element-wise and can be any positive\rfunction, for example $\\phi(x) = elu(x) + 1$. This attention is\rrow-wise normalized so that all rows of the score matrix are sets of\rpositive weights adding up to one. This preserves the objective of the\roriginal softmaxed attention scores, while allowing to perform\roperations in an optimal order.\r\n\nThe Performer by \\citet{choromanski2021rethinking} exploits the same idea of a kernelized attention introduced\rby \\citet{katharopoulos2020transformers}, with an algorithm that betters approximate softmaxed attention. Most\rimportantly they also give in annex a prefix sum algorithm to perform\roperations in the right-side-first order while giving the same result as\rmasked left-side-first operation.\r\n\nAlthough the author did not specify how to implement it, the only\r implementations we found of this operation requires custom CUDA code. In\r this work we will give an implementation of the right-side-first masked\roperation, with usual functions from neural network frameworks, that\rremains linear in complexity.\n\n\\subsection{Alternatives to absolute positional\rencoding}\n\nThe original multi-head attention operation introduced by\r\\citet{vaswani2017attention} was\rintrinsically invariant by token order permutation. As token position was\ran important information for sequence to sequence models, they encoded\rthe global position of each token in their embedding. Since then, some\rmodified attention mechanisms, that depend on relative tokens position,\rhave been proposed.\r\n\n\\citet{shaw2018selfattention} explored\rmodifying the attention mechanism so that it depends on the relative\rdistance between tokens. A second score matrix that is function of the\rquery and the query/key relative distance is added to the original score\rmatrix that only depends on query/key vector representation. $A = softmax\\left(\\frac{Q \\times K^T}{\\sqrt{d}}\\right) \\times V$ becomes\r$A = \\left(\\frac{Q \\times K^T + S_{rel}}{\\sqrt{d}}\\right) \\times V$ with $S_{rel}$ of shape $(L_Q, L_K)$ defined as\r${S_{rel}}_{ij} = \\vec{Q_i} \\cdotp \\vec{RP}_{clip(i-j, -k, k)}$. Where $k$ is the attention horizon length and $\\vec{RP}_n$ is one of\r$2k+1$ relative positional embedding, vectors of size $d$.\r\\citet{shaw2018selfattention} and\r\\citet{huang2018music} observed that introducing this attention scheme improved performances.\rThe naive calculation of this term however has a complexity of\r$O(L_QL_Kd)$. No algorithm was provided to linearize the complexity.\r\n\nMore recently \\citet{liutkus2021relative} gives a stochastic positional encoding that is linear in\rcomplexity with regards to sequence length. However the implementation\ris complex and its stochastic nature requires that the operations be\rrepeated several times in parallel.\r\n\n\\citet{horn2021translational} noted that\rthe term $S^{rel} \\times V$ can be computed with linear complexity for\rthe case where $RP_{-k} = RP_{k}$. However this is restraining as the\rmodel can't make the difference between tokens before the attention\rhorizon or after.\r\n\nIn this work we will show that the computation of $S^{rel} \\times V$\rcan also be done with linear complexity, without concession.\n\n\\endinput\n", "meta": {"hexsha": "cac10dc765d86cc5b5e6acd6170663b7807423fa", "size": 8906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/02-background.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/02-background.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/02-background.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": 156.2456140351, "max_line_length": 1361, "alphanum_fraction": 0.7749831574, "num_tokens": 2262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.645684272698589}}
{"text": "\\mychapter{6}{Lesson 6} %181012\n\n\\section{Computationally secure encryption}\n\nHaving a better idea of what can and can't be accomplished in the cryptographic world, by means of theorems and proofs, we can focus now on the goal of defining a cryptographic system that meets our requirements. In this lesson, we focus specifically on the secrecy-oriented schemes, thus dealing with encryption and decryption of messages.\n\nThe requirements of a ``good'' encryption scheme are collectively called those of \\emph{computationally secure encryption}: the characterizing requirement is to design a task, or routine, that is \\emph{computationally hard} for an attacker to revert.\nIn detail: this task usually involves a secret key\\footnotemark, and is accomplished in polynomial time, and any attacker who wishes to revert it has no efficient means of doing it without knowing such key. Other properties include:\n\n\\footnotetext{This is the case for symmetric-key schemes, though many other kinds exist: some involving ``public'' keys, some others not having any key at all}\n\n\\begin{enumerate}\n    \\item \\label{prop:owk} \\emph{one-way}ness with respect to the encryption key: given $c = \\Enc(k, m)$, it should be hard to recover $k$\n    \\item \\label{prop:owm} \\emph{one-way}ness with respect to the original message: given $c = \\Enc(k, m)$, it should be hard to recover $m$\n    \\item \\label{prop:nol} In a stricter sense: no information whatsoever must ``leak'' from the message\n\\end{enumerate}\n\nTo start visualizing these concepts, let $\\Pi = (\\Enc, \\Dec)$ be a secrecy scheme, and consider the game depicted in figure \\ref{cryptogame:otindist}  where the adversary ``wins'' the game when the challenger outputs 1.\n\n\\begin{cryptogame}\n    {otindist}\n    {$\\cryptog{ind}(\\lambda, b)$}\n    {ind}\n\n    \\send{}{$m_0, m_1 \\in \\M$}{}\n\n    \\receive{\\shortstack[l]{\n        $k \\pickUAR \\K$ \\\\\n        $b \\pickUAR \\binary$ \\\\\n        $c \\pickUAR \\Enc(k, m_b)$ }}\n    {$c$}{}\n\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b = b'$}\n    \n\\end{cryptogame}\n\n\\begin{definition}\n    The scheme $\\Pi$ is said to be \\emph{computationally one-time secure} iff:\n    \\[\n        \\forall \\adversary \\in \\ppt \\implies \\cryptog{ind}(\\lambda, 0) \\compindist \\cryptog{ind}(\\lambda, 1)\\footnotemark\n    \\]  \n    or, rephrased in probability terms:\n    \\[\n        \\forall \\adversary \\in \\ppt \\implies \\lvert\\Pr[\\cryptog{ind}(\\lambda, 0) = 1] - \\Pr[\\cryptog{ind}(\\lambda, 1) = 1]\\rvert \\in \\negl(\\lambda) \\qedhere\n    \\]\n\\end{definition}\n\\footnotetext{$\\cryptog{ind}$ refers to the indistinguishability of the messages sent by \\adversary{} during the game}\n\nThis last definition shows how such a scheme is compliant with the three properties exposed beforehand. In particular:\n\n\\begin{enumerate}\n    \\item \\emph{It is hard to recover the key}. If not, then an adversary \\adversary{} can efficiently recover the key and use it to decrypt the ciphertext, which in turn enables him to perfectly distinguish $m_{0}$ from $m_{1}$ on any instance;\n    \\item \\emph{It is hard to recover the message}. This is analogous, and even more obvious than the preceding point. Nevertheless, this is a necessary condition for a secrecy scheme to be ``good'', and it mustn't be forgotten;\n    \\item \\emph{No information about the message whatsoever may leak from the ciphertext}. This may seem subtler than the previous point, but it warrants caution. Observe how an adversary \\adversary{}, if it has the ability to extract even a tiny bit of information of the original message from the ciphertext, then it is actually able to make an educated guess on which message was encrypted in the first place, putting him at an advantage. This leads the probabilities described in the definition to be sensibly more unbalanced than negligible, forfeiting the desired secrecy.\n\\end{enumerate}\n\nBy extension, we may ask ourselves what scheme may or may not be \\emph{computationally two-time secure}. For instance, let $\\Pi_{\\oplus} = (\\Enc, \\Dec)$ be a secrecy scheme using a \\prg{} $G : \\binary^\\lambda \\to \\binary^n$, structured as follows:\n\n\\begin{itemize}\n    \\item $\\K = \\binary^\\lambda$, $\\M = \\C= \\binary^n$\n    \\item $\\Enc(k, m) = G(k) \\oplus m$\n    \\item $\\Dec(k, c) = c \\oplus G(k) = m$\n\\end{itemize}\n\nTo be two-time secure means that, even if an adversary \\adversary{} gets hold of a valid plaintext-ciphertext couple $(\\overline{m}, \\overline{c})$, he is unable to decrypt any future ciphertexts\\footnotemark, apart from the obvious $\\overline{c}$. However, observe that \\adversary{} is now able to extract valuable information for decrypting future ciphertexts:\n\n\\footnotetext{This example models a technique called \\emph{Chosen Plaintext Attack}, which will be discussed in depth later}\n\n\\[\n    \\overline{c} = \\Enc(k, \\overline{m}) = G(k) \\oplus \\overline{m} \\implies \\overline{c} \\oplus \\overline{m} = G(k)\n\\]\nso now, for any second ciphertext \\adversary{} receives, he can \\emph{mimic} the decryption routine, and efficiently uncover the underlying plaintext. This proves that $\\Pi_\\oplus$ is not two time-secure; nevertheless, it is still one-time secure:\n\n\\begin{theorem}\n    If $G$ is a \\prg, then $\\Pi_\\oplus$ is computationally one-time secure\n\\end{theorem}\n\n\\begin{proof}\n    This proof is another example that showcases the use of hybrid games. Recalling the one-time security definition, we need to show that:\n    \\[\n        \\forall \\adversary \\in \\ppt \\implies \\cryptog{ind}[\\Pi_\\oplus](\\lambda, 0) \\compindist \\cryptog{ind}[\\Pi_\\oplus](\\lambda, 1)\n    \\]\n    Consider the hybrid game in figure \\ref{cryptogame:xorothybrid}, where the original encryption routine is changed to use a completely random value, instead of using $G(k)$\\footnotemark. As an exercise, compare it with the original one-time secure definition in figure \\ref{cryptogame:otindist}, to check that it perfectly matches.\n\n    \\footnotetext{The observant student may recognize that this modification yields exactly the ``one-time pad'' secrecy scheme discussed in lesson 1}\n\n    \\begin{cryptogame}\n        {xorothybrid}\n        {$\\hybridg{}[\\Pi_\\oplus](\\lambda, b)$}\n        {r-ind}\n\n        \\send{$m_0 \\neq m_1 \\in \\binary^l$}{$m_0, m_1$}{}\n\n        \\receive{\\shortstack[l]{\n            $r \\pickUAR \\binary^l$ \\\\   % R \\sim \\unifdist{\\binary^l}\n            $b \\pickUAR \\binary$ \\\\     % B \\sim \\unifdist{\\binary}\n            $c = r \\oplus m_b$            % C = R \\oplus m_B\n        }}\n        {$c$}{}\n\n        \\cseqdelay\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n        \n    \\end{cryptogame}\n\n    The proof begins by affirming that:\n    \\begin{claim}\n        \\[\n            \\forall \\adversary \\in \\ppt \\implies \\hybridg{}[\\Pi_\\oplus](\\lambda, 0) \\equiv \\hybridg{}[\\Pi_\\oplus](\\lambda, 1)\n        \\]\n    \\end{claim}\n\n    To prove it, notice that $r$ is chosen uniformly at random, and independently of $b$. Thus, no matter how the messages $m_0$ and $m_1$ are structured, $r$ will effectively make the chosen message completely unrecognizable. In formal terms, let $B$ and $R$ be the random variables for \\challenger{}'s picks of $b$ and $r$ respectively; then:\n    \\begin{align*} % AP190906: Totally original, need a peer review here\n        & \\left| \\Pr(B = 0 \\knowing C = c) - \\Pr(B = 1 \\knowing C \\evaluatesto c) \\right| & \\\\\n        =& \\left| \\Pr(B = 0 \\knowing R \\oplus m_B \\evaluatesto c) - \\Pr(B = 1 \\knowing R \\oplus m_B \\evaluatesto c) \\right| & \\text{(C definition)} \\\\\n        =& \\mathrlap{\\frac{\\left| \\Pr(R \\oplus m_B = c \\knowing B \\evaluatesto 0) \\Pr(B = 0) - \\Pr(R \\oplus m_B = c \\knowing B \\evaluatesto 1) \\Pr(B = 1) \\right|}{\\Pr(R \\oplus m_B = c)}} & \\\\\n        & & \\text{(Bayes' theorem)} \\\\\n        =& \\frac{\\left| \\Pr(R \\oplus m_0 = c) \\Pr(B = 0) - \\Pr(R \\oplus m_1 = c) \\Pr(B = 1) \\right|}{\\Pr(R \\oplus m_B = c)} & \\text{(Cond. collapse)} \\\\\n        =& \\frac{\\left| \\oneover{2^l} \\half - \\oneover{2^l} \\half \\right|}{\\Pr(R \\oplus m_B = c)} = 0 & \\\\\n    \\end{align*}\n\n    Having proven that \\adversary's success is equivalent to straight guessing in $\\hybridg{}[\\Pi_\\oplus]$, we now relate the hybrid game to the original one, affirming that:\n    \n    \\begin{claim}\n        \\[\n            \\forall \\adversary \\in \\ppt,\\, \\forall b \\in \\binary \\implies \\hybridg{}[\\Pi_\\oplus](\\lambda, b) \\compindist \\cryptog{ind}[\\Pi_\\oplus](\\lambda, b) \\qedhere\n        \\]\n    \\end{claim}\n\n    The proof proceeds by reduction as depicted in figure \\ref{cryptoredux:xorotprg}, by assuming the existence of a distinguisher $\\textsf{D}^{\\textsc{ind}}$ for $c = G(k) \\oplus m_{b}$ and $c = r \\oplus m_{b}$, and using it to break $G$'s pseudo-random generation property.\n\n    \\begin{cryptoredux}\n        {xorotprg}\n        {Reducing to breaking a \\prg}\n        {prg}\n        {G-ind}[2]\n\n        \\receive{\\shortstack[l]{\n            $k \\pickUAR \\binary^\\lambda$ \\\\\n            $x_0 \\pickUAR G(k)$ \\\\\n            $x_1 \\pickUAR \\binary^l$ \\\\\n            $b \\pickUAR \\binary$\n        }}{$x_b$}{}\n\n        \\return{}{$m_0, m_1$}{}\n\n        \\invoke{\\shortstack[l]{\n            $\\beta \\pickUAR \\binary$ \\\\\n            $c = x_b \\oplus m_\\beta$\n        }}{$c$}{}\n\n        \\return{}{$\\beta'$}{}\n\n        \\cseqdelay\n        \\send{$b' = \\begin{cases}\n            0 &\\textsc{iff } \\beta' = \\beta \\\\\n            1 &\\textsc{else}\n        \\end{cases}$\n        }{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptoredux}\n\n    Again, notice how the games of indistinguishability and pseudo-random generation are reliably reproduced on their respective sides. This construct's value centers on how $\\distinguisher^\\textsc{ind}$ will perform in its own challenge:\n    \\begin{itemize}\n        \\item if $x_b$ is a random value, then $\\distinguisher^\\textsc{ind}$ will perform as depicted in the hybrid game, thus giving right or wrong answers at random;\n        \\item if b is the result of $G$, then $\\distinguisher^\\textsc{ind}$ has a better chance in finding the right answer by its own design;\n    \\end{itemize}\n    From these observations, especially the second point, the adversary \\adversary{} has a better chance of winning the \\prg{} game by asserting that $x_b$ comes from $G$ whenever $\\distinguisher^\\textsc{ind}$ makes a correct guess; conversely, \\adversary{} will preferably declare that $x_b$ is truly random whenever $\\distinguisher^\\textsc{ind}$ fails a guess, as the probability of the latter getting fooled by a random value is sensibly greater than by a pseudo-random one.\n\n    Either way, by the existence of $\\distinguisher{}^\\textsc{ind}$, \\adversary{} gains an edge in efficiently recognizing $G$, which cannot happen by $G$'s definition; the claim is proven. The theorem's proof can be completed by putting the pieces together, as is usual in the hybrid argument:\n    \\[\n        \\cryptog{ind}[\\Pi_\\oplus](\\lambda, 0) \\compindist\n        \\hybridg{}[\\Pi_\\oplus](\\lambda, 0) \\equiv\n        \\hybridg{}[\\Pi_\\oplus](\\lambda, 1) \\compindist\n        \\cryptog{ind}[\\Pi_\\oplus](\\lambda, 1)\n    \\]\n\n    which finally states that $\\cryptog{ind}[\\Pi_\\oplus](\\lambda, 0) \\compindist \\cryptog{ind}[\\Pi_\\oplus](\\lambda, 1)$.\n\\end{proof}\n \n\n\\section{Pseudorandom functions}\n\n\\textsc{Prg}s are used in practice as a stepping stone for building \\emph{pseudo-random functions}, \\prf{} henceforth, which are the principal construct in several cryptographic schemes. Before formally introducing what a \\prf{} is, we begin instead by defining what a \\emph{truly random function} is:\n\n\\begin{definition}\n    A random function $R : \\binary^n \\to \\binary^l$ is a function that, depending on what is known about its previous applications:\n\n    \\begin{itemize}\n        \\item if $x$ is ``fresh'' (in formal terms, $R$ has never been applied to $x$ beforehand), then a value $y$ is chosen \\uar{} from $R$'s codomain, and it is permanently associated as the image of $x$ in $R$\\footnote{This property is also called \\emph{lazy sampling}.};\n\n        \\item if $x$ is not fresh, then $R(x)$ is directly returned instead. \\qedhere\n    \\end{itemize}\n\\end{definition}\n\nIt should be noted that, if such functions are to be implemented in computers, they would occupy too much space in memory. Suppose all the possible outputs of $R$ have been generated and stored as an array in memory; then its total size in bits will be $l \\cdot 2^n$:\n\n\\[  \n    \\color{black!50}\n    \\overbracket[0.5pt][5pt]{\\;\\color{black}\\framebox[4em][c]{0010...}\\;}^{l \\text{ bits}}_1\\;\n    \\overbracket[0.5pt][5pt]{\\;\\color{black}\\framebox[4em][c]{1110...}\\;}^{l \\text{ bits}}_2\\;\n    \\overbracket[0.5pt][5pt]{\\;\\color{black}\\framebox[4em][c]{0011...}\\;}^{l \\text{ bits}}_3\\;\\;\n    \\color{black!25}\n    \\framebox[2em][c]{\\rule{0pt}{1.5ex}...}\\;\n    \\framebox[2em][c]{\\rule{0pt}{1.5ex}...}\\;\n    \\framebox[2em][c]{\\rule{0pt}{1.5ex}...}\\;\n    \\framebox[2em][c]{\\rule{0pt}{1.5ex}...}\\;\\;\n    \\color{black!50}\n    \\overbracket[0.5pt][5pt]{\\;\\color{black}\\framebox[4em][c]{1110...}\\;}^{l \\text{ bits}}_{2^n}\n\\]\n\nSuch a function becomes cumbersome and difficult to maintain in practice; therefore, it is desirable to find a kind of function which looks as a random function possible, but does not require to be wholly memorized, while not forgetting to maintain poly-time complexity. Pseudo-randomness comes to the rescue here:\n\n\\begin{definition}\n    Let $f$ be a function, then it is deemed pseudo-random (therefore, $f$ is a \\prf{}) iff it is computationally indistinguishable from a true random function.\n\\end{definition}\n\nIn detail, \\prf{}s are actually designed as function families $f_k$\\footnotemark, where $k$ is a parameter that indexes the functions inside the family. To model the \\prf{}s' indistinguishability from random functions, let $F \\in \\binary^\\lambda \\to (\\binary^{n(\\lambda)} \\to \\binary^{l(\\lambda)} )$, usually denoted simply by $f_k$, be a \\prf{}, and define $\\mathfrak{R}(n, l)$ to be the domain that collects the random functions from $\\binary^{n(\\lambda)}$ to $\\binary^{l(\\lambda)}$.\n\n\\footnotetext{Does this remind you of something else? If not, look back in lesson 2 and 3.}\n\nConsider the indistinguishability game drawn in figure \\ref{cryptogame:prf}; although one may thing that \\prg{}s and \\prf{}s aren't much different, the game tells a different story, which is best put by an introductory paragraph about \\prf{}s in their Wikipedia page:\n\n\\begin{quotation}\n    ``Pseudorandom functions are not to be confused with pseudorandom generators (\\prg{}s). The guarantee of a \\prg{} is that a single output appears random if the input was chosen at random. On the other hand, the guarantee of a \\prf{} is that all its outputs appear random, regardless of how the corresponding inputs were chosen, as long as the function was drawn at random from the \\prf{} family.''\\footnote{\\linkicon \\href\n        {https://en.wikipedia.org/wiki/Pseudorandom_function_family}\n        {\\textsf{Pseudorandom function family --- Wikipedia}}}\n\\end{quotation}\n\n\\begin{cryptogame}\n    {prf}\n    {The \\prf{} indistinguishability game}\n    {prf}\n\n    \\cseqchallenger{\\shortstack[l]{\n        $k \\pickUAR \\binary^\\lambda$ \\\\\n        $R \\pickUAR \\mathfrak{R}(n, l)$ \\\\\n        $b \\pickUAR \\binary$\n    }}\n\n    \\cseqdelay\n    \\cseqbeginloop\n\n    \\send{}{$x$}{}\n\n    \\receive{\\shortstack[l]{\n        $y_0 = f_k(x)$ \\\\\n        $y_1 = R(x)$\n    }}{$y_b$}{}\n\n    \\cseqendloop\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b = b'$}\n\n\\end{cryptogame}\n\nIn this game, \\adversary{} is allowed to make multiple queries to $\\challenger^\\prf$, as opposed to the \\prg{} indistinguishability game where it can perform just one query before making its guess. To reiterate the \\prf{} definition in terms of this game:\n\n\\begin{definition}\n    A function family $F = f_k$ is a \\prf{} iff: \n    \\[\n        \\cryptog{prf}[f_k](\\lambda, 0) \\compindist \\cryptog{prf}[f_k](\\lambda, 1) \\qedhere\n    \\]\n\\end{definition}\n\n\\begin{exercise}\n    Prove the following statements:\n    \\begin{itemize}\n        \\item No \\prg{} is secure against unbounded attackers;\n        \\item No \\prf{} is secure against unbounded attackers.\n    \\end{itemize}\n   \n\\end{exercise}\n\n\n\\subsection{\\textsc{Ggm}-tree}\n\nThis section is dedicated to a concrete example of a \\prf{} which is built from the ground up using a \\prg. This construct has been designed from Oded Goldreich, Shafi Goldwasser and Silvio Micali, and its structure is akin to a binary tree, hence its name: \\emph{\\ggm-tree}.\n\n\\begin{construction}\n    Let $G \\in \\binary^\\lambda \\to \\binary^{2\\lambda}$ be a \\prg{} such that it doubles the length of its argument, and denote the images' first and second halves as $G_0(k)$ and $G_1(k)$ respectively, so that: \n    \\[\n        k \\mapsto (G_0(k), G_1(k))\n    \\]\n\n    Since the principal mechanism makes use of the halves being the same length of the argument, in the same spirit, we will denote the action of using one half of an image of $G$ as argument of $G$ itself in a shorter fashion, as demonstrated in the following example:\n    \\[\n        G_a(G_b(G_c(k))) =: G_{abc}(k)\n    \\]\n\n    This leads to the final step: let $f_k$ be a function family, where $k \\in \\binary^\\lambda$, such that:\n    \\[\n        f_k(r) = G_r(k)\n    \\]\n\n    This is our candidate \\prf. To visualize it, consider the tree structure depicted in figure \\ref{fig:ggmtree}: at each level of the tree, a single bit of $r$ is used to decide which half of $G$'s image will be used in the next level. For example, $f_k(01 \\dots 10)$ would evaluate as $G_0(G_1( \\dots G_1(G_0(k))))$.\n\n    \\begin{figure}\n        \\centering\n        \\begin{tikzpicture}[\n            level 1/.style={sibling distance=16em},\n            level 2/.style={sibling distance=8em},\n            level 3/.style={sibling distance=4em}]\n\n            \\node{$k$}\n                child{ node {$G_0(k)$}\n                    child{ node {$G_{00}(k)$}\n                        child{ node{$G_{000}(k)$} node[below]{$\\vdots$}}\n                        child{ node{$G_{001}(k)$} node[below]{$\\vdots$}}\n                    }\n                    child{ node {$G_{01}(k)$}\n                        child{ node{$G_{010}(k)$} node[below]{$\\vdots$}}\n                        child{ node{$G_{011}(k)$} node[below]{$\\vdots$}}\n                    }\n                }\n                child{ node {$G_1(k)$}\n                    child{ node {$G_{10}(k)$}\n                        child{ node{$G_{100}(k)$} node[below]{$\\vdots$}}\n                        child{ node{$G_{101}(k)$} node[below]{$\\vdots$}}\n                    }\n                    child{ node {$G_{11}(k)$}\n                        child{ node{$G_{110}(k)$} node[below]{$\\vdots$}}\n                        child{ node{$G_{111}(k)$} node[below]{$\\vdots$}}\n                    }\n                };\n        \\end{tikzpicture}\n        \\caption{The \\textsc{ggm}-tree for $G$}\n        \\label{fig:ggmtree}\n    \\end{figure}\n\n\\end{construction}\n\nThe proof of \\prf-ness will be discussed in the next lesson.\n", "meta": {"hexsha": "c891490acd4ffcd1c6925ea23c068050604a6911", "size": 18835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_6.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_6.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_6.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": 55.5604719764, "max_line_length": 578, "alphanum_fraction": 0.6561189275, "num_tokens": 5542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6456721861545947}}
{"text": "%\n% CMPT 310: Artificial Intelligence - A Course Overview\n% Section: Game Playing and Adversarial Search\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Game Playing and Adversarial Search}\n\t\\label{sec:game-playing-adversarial-search}\n\\begin{easylist}\n\n& Game playing: Scenario where a game with discrete states is played with two players, each seeking to maximize their position which minimizes the opponent's position\n\t&& E.g. Chess, checkers\n\t&& \\textbf{Heuristic/evaluation function:} Estimate of the optimality of a game state\n\t&& \\textbf{Terminal state:} Game state which has no further states\n\t&& Example diagram of game state evaluations in a tree: See figure~\\ref{fig:game-tree}\n\t\n\\begin{figure}[!htb]\n\t\\caption{Game Tree (Minimizer first)}\n\t\\label{fig:game-tree}\n\t\\centering\n\n\t\\begin{forest}\n\t\tfor tree={\n\t\t\tdraw,\n\t\t\tcircle,\n\t\t\tminimum size=1cm,\n\t\t\tline width=0,\n\t\t\talign=center\n\t\t},\n\t\t[0\n\t\t\t[2\n\t\t\t\t[2]\n\t\t\t\t[-3]\n\t\t\t\t[-14]\n\t\t\t]\n\t\t\t[14\n\t\t\t\t[14]\n\t\t\t\t[17]\n\t\t\t\t[20]\n\t\t\t]\n\t\t\t[0\n\t\t\t\t[-12]\n\t\t\t\t[-18]\n\t\t\t\t[0]\n\t\t\t]\n\t\t]\n\t\\end{forest}\n\\end{figure}\n\n& \\textbf{Minimax algorithm:} Decision-making rule which minimizes the potential loss for a worst-case scenario, given two entities who are alternatively trying to maximize and minimize a score\n\t&& Performs the equivalent of a depth-first search\n\t&& Each alternating level of the decision tree is minimized or maximized from the values in the levels below it\n\t&& Complete: Yes, as long as the tree is finite\n\n& \\textbf{$\\alpha / \\beta$ pruning:} Keeping the maximum/minimum searched values at a given level so far to eliminate nodes which will not exceed a minimum/maximum\n\t&& $\\alpha$: Lower bound on the potential value of a maximum node\n\t&& $\\beta$: Upper bound on the potential value of a minimum node\n\t&& \\href{http://inst.eecs.berkeley.edu/~cs61b/fa14/ta-materials/apps/ab_tree_practice/}{Resource for practice}\n\t&& See figure~\\ref{fig:game-tree-ab} for an example of pruned nodes (notated by dashed edges)\n\t\n\\begin{figure}[!htb]\n\t\\caption{Game Tree with $\\alpha / \\beta$ Pruning (Minimizer first)}\n\t\\label{fig:game-tree-ab}\n\t\\centering\n\n\t\\begin{forest}\n\t\tfor tree={\n\t\t\tdraw,\n\t\t\tcircle,\n\t\t\tminimum size=1cm,\n\t\t\tline width=0,\n\t\t\talign=center\n\t\t},\n\t\t[0\n\t\t\t[2\n\t\t\t\t[2]\n\t\t\t\t[-3]\n\t\t\t\t[-14]\n\t\t\t]\n\t\t\t[14\n\t\t\t\t[14]\n\t\t\t\t[17, edge={densely dashed}]\n\t\t\t\t[20, edge={densely dashed}]\n\t\t\t]\n\t\t\t[0\n\t\t\t\t[-12]\n\t\t\t\t[-18]\n\t\t\t\t[0]\n\t\t\t]\n\t\t]\n\t\\end{forest}\n\\end{figure}\n\n& Time, space, and optimal complexity of algorithms: See figure~\\ref{fig:algos-complexity}\n\n\\end{easylist}\n\\clearpage\n", "meta": {"hexsha": "a74fd708a298af4305150c2611cce8c086268b39", "size": 2506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-310-artificial-intelligence-survey/course-overview/tex/game-playing.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-310-artificial-intelligence-survey/course-overview/tex/game-playing.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-310-artificial-intelligence-survey/course-overview/tex/game-playing.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.3131313131, "max_line_length": 193, "alphanum_fraction": 0.6823623304, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.6456721786652795}}
{"text": "\\chapter{Algorithms}\nIn this chapter, we will list some important algorithms which may be used in the solution of each subproblem.\n\n\\section{Shortest Path Between Two Nodes}\n\nAlgorithms for the calculation of the Shortest Path between two points are very important for the solution of this problem. They will be used to calculate the shortest path between multiple points when calculating a vehicle's path, such as the shortest path between the garage and a pick up point. To do this, there are many algorithms at our disposal. We will evaluate some of them and make a decision on which is(are) best for the situation at hand.\n\n\n\\subsection{Dijkstra's Algorithm}\n\n\\subsubsection{Description}\nThis algorithm was conceived by Edsger W. Dijkstra's in 1956 and is used to calculate shortest paths in directed or undirected graphs, so long there are no edges with negative weight. Upon utilization of this algorithm, a tree holding the shortest paths from the origin node to all others is formed. \n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item Minimum distance to the origin node from each of the graph's nodes (dist)\n    \\item Node that comes before it in its path (path)\n    \\item Priority queue to hold the nodes to be processed next\n    \\item Decrease-Key function, to maintain the nodes with shortest distance in the top of the queue\n\\end{itemize}\n\n\\input{Algorithms/Dijkstra.tex}\n\n\\subsubsection{Analysis}\nThe first part of the algorithm's goal is to prepare the data (lines 1-6): paths are set to null, distances to infinity, the priority queue is initialized and the origin node is inserted. Then, a breadth-first search is performed; a check is made to every node found in order to understand if its path can be shortened by the use of the edge in analysis. After that, if the node is not already in the queue, it must be inserted, to be eventually processed. If it is, its key must be reduced. The items of the priority queue are ordered by their key. This system is used so that the nodes which are closest to the origin are processed first. This procedure ensures that the distance of already processed nodes remains intact, boosting the algorithm's efficiency and making this a greedy algorithm. \\\\\n%\\begin{itemize}\n%    \\item \\textbf{Loop invariant} - $ priorityQueue \\neq \\emptyset $, as each time a node is processed, its shortest path is defined and all nodes will be processed when the queue is empty\n%    \\item \\textbf{Loop variant} - the number of nodes to be processed, since the algorithm would stop when the queue is empty\n%\\end{itemize}\n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O((|N|+|E|) \\times \\log(|N|) $, where E is the set of edges and N the set of nodes of the graph. Decrease-Key's time efficiency is $ O(|E| \\times log(|N|)$. It can be $ O(1) $ if Fibonacci Heaps are used instead of regular Priority Queues, making the whole algorithm $ O(|N| \\times log(|N|) $ \n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but usually $ O(|N|) $\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm is one to consider using in the problem, but there may be slightly more efficient ones.\n\n\n\\subsection{Bellman-Ford Algorithm}\n\n\\subsubsection{Description}\nThe Bellman-Ford Algorithm is another algorithm used to calculate the shortest path between nodes in a graph. It was first proposed by Alfonso Shimbel in 1955 but ended up being named after Richard Bellman and Lester Ford, who later officially published it independently. This algorithm is useful to calculate shortest paths in graphs with negative weight edges and to detect negative edge cycles in them.\n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item Minimum distance to the origin node from each of the graph's nodes (dist)\n    \\item Node that comes before it in its path (path)\n\\end{itemize}\n\n\\input{Algorithms/Bellman-Ford.tex}\n\n\\subsubsection{Analysis}\nIn this algorithm, the first step is to prepare the graph (lines 1-4). Then, all edges are analyzed $|N| - 1 $ times(lines 6-7), checking if they can be used to shorten the path from s to the destination node of the edge(line 8). This process is repeated this amount of times because it is the maximum length in edges for a path. In the end, a check is made, to see if the algorithm worked. If it did not, the cycle as negative weight loops (lines 14-18). This algorithm is considered to implement dynamic programming.\n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N| \\times |E|) $, where E is the set of edges and N the set of nodes of the graph\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but in this case $ O(1) $\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm poses little interest to this problem given that our edges' weights represent the length of a road, which would never be negative. \n\n\n\\subsection{Bidirectional Dijkstra}\n\n\\subsubsection{Description}\nIra Pohl was the first one to design and implement a bidirectional heuristic search algorithm in 1971. \nBidirectional Dijkstra's that implements the idea of a bidirectional search into Dijkstra's algorithm. It finds a shortest path from an initial node to a goal node in a directed or undirected graph. It runs two simultaneous searches: one forward from the initial state, and one backward from the goal, alternating between the two. The stopping criteria is one that must be very well implemented to guarantee the shortest path. Compared to normal Dijkstra's there's a speedup of 2x.\n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item Minimum distances to the origin and goal nodes from each of the graph's nodes (dist)\n    \\item Nodes that come before each node in both forward and backward paths (not implemented in pseudocode)\n    \\item Two priority queues to hold the nodes to be processed next in each direction\n    \\item Way of search (way) (1 if it was encountered by forward search first, 2 if it was encountered by backward search first, 0 default)\n    \\item Decrease-Key function, to maintain the nodes with shortest distance in the top of the queue\n\\end{itemize}\n\n\\input{Algorithms/Bidirectional.tex}\n\\uline{Note:} The pseudocode is not complete, missing the parts to calculate the actual path and to calculate the transposed graph (needed for the backward search because this is a directed graph). These parts were excluded in order to not make the algorithm's pseudocode even more complex and spacious.\n\n\\subsubsection{Analysis}\nThis algorithm basically performs two Dijkstra's algorithms: one starting from the initial node and going forward(lines 16-23); another one starting from the ending node and going backward (lines 24-31). Each time they cross, the distance is registered (lines 25-26 for example). The stopping criteria is a tricky problem in this case. In many situations, the algorithm ends when the two sets collide (forward search and backward search). We found that this criteria did not guarantee the shortest path. Instead, we chose to end the algorithm when there can be no longer any better distances because the nodes being processed are already too far apart.\n%\\begin{itemize}\n%    \\item \\textbf{Loop invariant} - $ dist(n) + distR(v) > bestDist $, where best distance is the best Distance for a complete path obtained yet, dist(n) is the distance of the node being processed in forward way to the starting node and $ distR(v) $ the distance of the node being processed in backward way to the ending node\n%    \\item \\textbf{Loop variant} - the number of nodes to be processed in each way, since the algorithm would stop when each search had got no more nodes to process on the queue\n%\\end{itemize}\n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O((|N|+|E|) \\times \\log(|N|) $, where E is the set of edges and N the set of nodes of the graph.\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but usually $ O(|N|) $\n\\end{itemize}\nEven though there's a speed up, the complexities will be the same as in Dijkstra's, since the difference is multiplication and division by constants, which is ignored in Big O order.\n\n\\subsubsection{Usability}\nBidirectional Dijkstra's algorithm is one of the fastest algorithms when it comes shortest paths. It has the down-side of requiring the previous knowledge of the ending/destination node, but in this scenario that is not a problem.\n\n\n\\subsection{A* Algorithms}\n\\subsubsection{Description and Analysis}\nThe first time a A* Algorithm came up was in \\textit{Shakey Project}, project of the first general purpose mobile robot capable of reasoning about is own actions. In an A* (pronounced A-star) Search Algorithm, the 'level' of a node in a graph becomes a sum of two different characteristics. For instance, applied to this problem, the distance a node is from the origin in the search algorithm is substituted for the sum of:\n\\begin{itemize}\n    \\item $d_{sv}$ - actual distance to the origin\n    \\item $\\pi_{nt}$ - estimated guess of the distance to the goal node (heuristic)\n\\end{itemize}\nThe reliability of this technique depends on the efficacy of the heuristic. In this case, because the weight of edges is distance in meters, the efficacy is great if we assume $\\pi$ to be the euclidean distance. This algorithm can be implemented into both Bidirectional and normal Dijkstra's.\n\\begin{itemize}\n    \\item \\textbf{Upside} - Speeds up the process immensely\n    \\item \\textbf{Downside} - The algorithm does not absolutely guarantee the best solution.\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis is a technique that shows to be very promising and a good idea to implement in the solution of this problem.\n\n\n\n\\newpage\n\\section{Shortest Path Between All Nodes}\nThis section is dedicated to algorithms that calculate the shortest path between all pairs of points. Such algorithms may be used in the solution, specially in the pre-processing part.\n\n\\subsection{Floyd-Warshall}\n\n\\subsubsection{Description}\nThis algorithm was published by Robert Floyd in 1962, yet it was virtually the same as some algorithms published by Stephen Warshall and Bernard Roy, 1962 and 1959 respectively. It takes an adjacency matrix that represents the graph as an input (empty in the beginning) and calculates the shortest paths between all nodes. The value of a path between to vertices is the sum of all edge's weights through that path. It is registered in the matrix as such: distance of shortest path between 1 and 4 would be matrix[1][4]. Edges may have negative values but the graph can't have a negative cycle.\n% For each pair of vertices, the shortest path is calculated. Time complexity is O \\begin{math}(|V| ^3).\\end{math}, and space complexity is O \\begin{math}(|V| ^2).\\end{math}\n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item $ |N| \\times |N| $ matrix (another one if paths are needed), where $ |N| $ is the number of vertices\n\\end{itemize}\n\n\\input{Algorithms/Floyd-Warshall.tex}\n\\uline{Note:} The pseudocode is not complete, missing the matrix to calculate the paths and respective instructions. This was done in order to simplify the algorithm and minimize it.\n\n\\subsubsection{Analysis}\nFirst part is basically the preparation of the matrix: fill it with $\\infty$ distances; for the edges existant (lines 1-3), change the values in the matrix to their weight (lines 4-6). Then, all pairs of nodes will be checked on if there is any node the path can pass through that would minimize its cost (lines 7-14). \n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N|^3) $, where N is the set of nodes of the graph.\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but usually $ O(|N|^2) $, for the matrix of size $|N| \\times |N|$\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm is an interesting algorithm to be used in the beginning of the program, to leave all shortest paths processed. However, this might take a long time, and it might be a better idea to simply calculate the shortest path each time it is needed.\n\n\n\\subsection{Dijkstra's Algorithm}\n\n\\subsubsection{Description and Analysis}\nDijkstra's can also be used to calculate all shortest paths. This is done by simply executing the algorithm for every node in the graph as origin.\n \n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N| \\times (|N|+|E|) \\times \\log(|N|) $, where E is the set of edges and N the set of nodes of the graph. Same as Dijkstra's but multiplied by $|N|$\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but usually $ O(|N|) $, for the priority queue, same as Dijkstra's\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis is a better option for less dense graphs compared to Floyd-Warshall. As this is not the case for a road network, this algorithm is relatively irrelevant.\n\n\n\n\\newpage\n\\section{Connectivity}\nThe algorithms in this section check the connectivity of the graph. By other words, this section is dedicated to algorithms that detect if any nodes are inaccessible to others, dividing the graph in strongly connected components. A graph will be strongly connected if there is a path between all pairs of points, or if the graph is a strongly connected component itself. Algorithms to test connectivity may be useful to solve the problem of unpredictability.\n\n\n\\subsection{Brute Force with Floyd-Warshall}\n\n\\subsubsection{Description and Analysis}\nOne way to test the connectivity of a graph is by analyzing the results of Floyd-Warhsall in a certain graph. If there are any pairs of nodes which the distance remains $\\infty$, they do not belong to the same strongly connected component.\n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N|^3) $, where N is the set of nodes of the graph, same as Floyd-Warshall\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but usually $ O(|N|^2) $, for the matrix of size $|N| \\times |N|$\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm works yet is not a good option. Even if the Floyd-Warshall is going to be utilized anyway, the complexity of traversing the whole matrix is $O(|N|^2)$. Therefore, there are much better algorithms for the job.\n\n\n\\subsection{Kosaraju's algorithm}\n\n\\subsubsection{Description}\nThe algorithm was first published in 1981 by Micha Sharir but gets is name from whom first mencioned it in 1971, Sambasiva Rao Kosaraju. This algorithm allows to identify strongly connected components in a directed graph, testing its connectivity. \n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item boolean identifying if a node has been visited or not (visited)\n    \\item identifier of the strong component the node belongs to (strongComponent)\n    \\item function to invert the edges of the graph\n    \\item a queue to hold the order of the visits\n\\end{itemize}\n\n\\input{Algorithms/Kosaraju.tex}\n\n\\subsubsection{Analysis}\nThe algorithm performs two depth-first searches in the graph. In the first one, it marks the nodes by visit order (lines 5-9). The second one starts on the nodes with lowest order and is performed on the graph with the edges inverted (lines 10-14). This second one will generate multiple expansion trees (or just one if the graph is strongly connected), each being a strongly connected component. If two nodes are not in the same strongly connected component, one of them cannot be reached from the other.\n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N|+|E|) $, where N is the set of nodes of the graph and E the set of edges. Each dfs is $O(|N|+|E|)$\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but in this one it is $ O(|N|) $, being the size of the queue $|N|$\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm is a serious candidate to check the connectivity of the graph.\n\n\n\\subsection{Tarjan's Algorithm}\n\n\\subsubsection{Description}\nThe Tarjan's Algorithm was named after its inventor, Robert Tarjan, and is another algorithm capable of identifying the strongly connected components in a given graph. It does so, similarly to Kosaraju's, with the help of dfs, only this time the graph is only traversed once.\n\n\\subsubsection{Extra Data, Data Structures and Algorithms Required}\n\\begin{itemize}\n    \\item boolean identifying if a node has been visited or not (visited)\n    \\item integer identifying the counter when a node is first found (num)\n    \\item integer identifying the lowest num reachable by a node (low)\n\\end{itemize}\n\n\\input{Algorithms/Tarjan.tex}\n\n\\subsubsection{Analysis}\nThe algorithm is fairly simple: the graph is traversed by a depth first search (lines 5-6); the $num$ and $low$ of a node are set to the $numCounter$(lines 12-13); each time an already visited node is found, all nodes with $low > that nodes low$ will be changed (lines 16-18). This way, all vertices with the same $low$ belong to the same strongly connected component. \n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|N|+|E|) $, where N is the set of nodes of the graph and E the set of edges. The dfs is $O(|N|+|E|)$. This is the same complexity as Kosaraju's, but the algorithm is twice as fast since it only performs one dfs.\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but in this one it is $ O(1) $.\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis algorithm is an even better candidate than the last one, since it is supposedly twice as fast. \n\n\n\\newpage\n\\section{Clustering Algorithms}\n\nA Clustering is a machine learning task which involves the recognition of natural grouping in data. Such algorithms can be used in the distribution of orders per vehicle.\n\n\n\\subsection{Agglomerative Hierarchical Clustering}\n\n\\subsubsection{Description}\n\nThis algorithm is one of the most common Hierarchical Clustering algorithms. It is used to form groups of objects of data based on their similarity. In this case, we will use it to form N groups of data nodes with great similarity.\n\n\\input{Algorithms/Clustering.tex}\n\\uline{Note:} the implementation presented above is just a rough sketch, the one to be implemented will be different.\n\n\\subsubsection{Analysis}\nThe algorithm begins to find the pair of points which are most similar. In this case, similarity is measured by distance (lines 6-14). After he has found one, he merges the two sets (. In between sets, there are many criteria to calculate similarity. The one we will implement is taking the similarity between two sets as the similarity of the most similar pair of points where one belong to the first set and other to the second set. This algorithm adopts a Bottom-Up strategy (as do all agglomerative hierarchical clustering algorithms), as it start by processing each node and joining them to obtain the final result.  \n\n\\subsubsection{Efficiency}\n\\begin{itemize}\n    \\item \\textbf{Temporal Complexity} - $ O(|S|^2*(|S| - n)) $, where S is the set of points. This is only an estimated guess.\n    \\item \\textbf{Spatial Complexity} - Depends on the implementation, but in this one it is $ O(|S|) $.\n\\end{itemize}\n\n\\subsubsection{Usability}\nThis is the only algorithm analysed in this cathegory, thus it is the chosen one to perform the task.\n\n\\section{Extras}\nThere are other algorithms, simpler or less relevant, that may (or may not) be used in our solution:\n\\begin{itemize}\n    \\item Breadth-First Search (bfs) - Graph searching algorithm\n    \\item Depth-First Search (dfs) - Graph searching algorithm\n    \\item Decrease-Key Function - Priority changing function on a priority queue\n    \\item Graph Transposing Function - Inversion of the edges in a directed graph\n    \\item Fibonacci Heaps (Data structure) - Improved priority queue\n    \\item Euclidian Distance function - To calculate the euclidian (straight-line) distance between two points\n\\end{itemize}\n", "meta": {"hexsha": "a4ed48a88484ae2c729aa6818a5afccba6a0efd8", "size": 20127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project/report/LaTeX/Algorithms.tex", "max_stars_repo_name": "marhcouto/FEUP-CAL", "max_stars_repo_head_hexsha": "e02775eb69f0b5fc268c80084e85b5f18177dd78", "max_stars_repo_licenses": ["MIT"], "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/LaTeX/Algorithms.tex", "max_issues_repo_name": "marhcouto/FEUP-CAL", "max_issues_repo_head_hexsha": "e02775eb69f0b5fc268c80084e85b5f18177dd78", "max_issues_repo_licenses": ["MIT"], "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/LaTeX/Algorithms.tex", "max_forks_repo_name": "marhcouto/FEUP-CAL", "max_forks_repo_head_hexsha": "e02775eb69f0b5fc268c80084e85b5f18177dd78", "max_forks_repo_licenses": ["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.8821428571, "max_line_length": 799, "alphanum_fraction": 0.7712525463, "num_tokens": 4756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6456721710491201}}
{"text": "\\subsection{Node-tree manipulation and the decoder time complexity}\nIn the following we detail the routines to grow and merge node-trees. These completes the description of the decoder as it is analogous to the original Union-Find algorithm with the addition of these two steps.\n\nThe original Union-Find algorithm had a complexity driven by the time complexity of merging the union-find data structures representing the cluster-trees. This is known to be $\\mathcal{O}(n\\alpha(n)$, where $\\alpha(n)$ is the inverse Ackermann function, a sublogarithmic growing function. \n\nThe worst-case time complexity of the Union-Find Partitioned-Growth decoder of \\Cref{algo:ufbb} follows directly from the complexity of the growth and merge of the node trees. They are still quasilinear. In particular, in sections \\ref{} and \\ref{}, we describe respectively the routines for the growth and the merge of the node-trees and show that they have an amortized time-complexity $\\mathcal{O}(n\\log n)$. In consequence, the complexity of the total algorithm is driven by these two steps and the amortized time-complexity is $\\mathcal{O}(n\\log n)$.\n\n\\subsubsection{Growing node-trees}\\label{sec:grownodetrees}\n\nThe Union-Find decoder grows clusters by adding half-edges to all boundary vertices of the cluster. Instead, here we propose to grow only the nodes with minimal $PMW$. For this, it is necessary to save the list of boundary vertices to each node (\\Cref{fig:nodetypes}c). In this algorithm, to \\emph{grow a node} means to grow all edges connected to its boundary vertices a half-edge per the Union-Find decoder. The proposed growth algorithm consists of 3 depth-first-searches starting from a reference node $R$. Since the minimal PMW can be found without the PWM of the reference node $R$ itself, any node $N\\in\\nset$ may be chosen as the reference node $R$. \n\n\\begin{algorithm}[h]\n  \\BlankLine\n  \\KwData{Node tree $\\nset$}\n  \\KwResult{$\\nset$}\n  \\BlankLine\n  \n  Choose a reference node $R \\in \\nset$\\;\n  Calculate node parities via tail-recursive DFS in $\\nset$ from $R$ via \\Cref{eq:snodeparity,eq:jnodeparity}\\;\n  Calculate PMW with respect to $R$ via head-recursive DFS in $\\nset$ from $R$ via \\Cref{eq:pmwdif}\\; \n  Grow all nodes with minimal PMW in a DFS in $\\nset$ from $R$\\;\n\n  \\caption{Grow node-tree (naive)}\\label{algo:grow}\n\\end{algorithm}\n\nWhen two clusters merge on vertices $a$ and $b$, their respective node-trees must also be merged. This is performed by creating an edge between nodes to which vertices $a$ and $b$ belong to. \n\n\\textcolor{cyan}{\n  It is possible to reduce the cost of \\Cref{algo:grow} by two implementations. First, the DFS's need not be performed during every growth iteration. For this, we introduce the \\emph{node delay} $\\delta_\\nset$, the difference in PMW with the minimal PMW in the node-tree.\n}\n\n\\begin{equation}\\label{eq:nodedelay}\n  \\delta_N = \\text{PWM}(N) - \\min_{N\\in\\nset}{\\text{PWM}(N) }\n\\end{equation}\n\n\\textcolor{cyan}{\n  With the node delay, the first two DFS's for the calculation of the parity and PMW need only to be performed during the first growth iteration after a merger, during which we now additionally sort the nodes with boundary vertices in the node-tree by the node delay. In the first growth iteration after a merger, we iterate over the sorted nodes and grow all nodes with delay 0, and add 1 to the delay, until a node with delay 1 is encountered. In the second iteration, we grow all nodes with delay 1, and so on. The number of operations for iterating through the sorted nodes is bounded by the number of growth operations of boundary edges, and its contribution to the complexity is thus defined within the original Union-Find decoder. The additional cost of growing a node-tree $\\nset$ while not merging is thus $\\abs{\\nset}$. \n}\n\n\\textcolor{cyan}{\n  A second reduction in the cost is possible by a selection procedure for the reference node $R_{\\text{merged}}$ in the merged node-tree $\\nset_{\\text{merged}}$. Since $\\nset_{\\text{merged}}$ must be odd to grow, the node-trees involved its merger must consist of at least one odd node-tree $\\nset_O$ and a number of other node-trees. If the reference node $R_O$ of $\\nset_O$ is chosen for $R_{\\text{merged}}$ after the merger, the parity and delays within the sub-tree of nodes in $R_O$ do not change during the merger. Thus, the DFS's can be limited all other node-trees but $\\nset_O$. The greatest reduction in cost is achieved if the reference node of the largest odd node-tree in the merger is chosen as the new reference node. \n}\n\n\n\nAfter calculating the node delay, each subsequent growth iteration is performed by a single DFS. In this growth DFS, each node with zero delay is grown, and the delay of other nodes are subtracted by $\\nicefrac{1}{2}$. This procedure is effectively equivalent to growing the nodes with minimal PMW. If a merge with another node-tree occurs, the PMW's within the merged node-tree change, and a recalculation of the node parities and reference PMW's is required. The reduced cost algorithm is described in \\Cref{algo:growdelay}. \n\n\\begin{algorithm}[h]\n  \\BlankLine\n  \\KwData{Node tree $\\nset$, growth iteration $i$ after merge}\n  \\KwResult{$\\nset$}\n  \\BlankLine\n\n  \\If(){$i=0$}{\n    Choose a reference node $R \\in \\nset$.\\;\n    Calculate node parities via tail-recursive DFS in $\\nset$ from $R$ via \\Cref{eq:snodeparity,eq:jnodeparity}.\\;\n    Calculate PMW with respect to $R$ via head-recursive DFS in $\\nset$ from $R$ via \\Cref{eq:pmwdif}.\\; \n    Calculate node delay $\\delta_N$ in $\\nset$ via \\Cref{eq:nodedelay}.\\;\n    Sort nodes with boundary edges by their node delay in a list $\\mathcal{L}$.\\;\n  }\n  \\For(){node $N$ in $\\mathcal{L}$}{\n    \\eIf(){$\\delta_N =i$}{\n      Grow boundary edges of $N$. Add 1 to $\\delta_N$.\n    }(){\n      Break loop.\n    }\n  }\n  \\caption{Grow node-tree (low-cost)}\\label{algo:growdelay}\n\\end{algorithm}\n\nNote that while the cost is reduced in \\Cref{algo:growdelay}, the complexity of the growth procedure is identical to \\Cref{algo:grow}, which is proportional to the size of the node-tree due to the growth DFS. However, \\Cref{algo:growdelay} allows us to solve a problem described in the next section. \n\n% An addition reduction in cost is possible by retaining the same root node through several mergers, such that the delay and PMW DFS's need only to be performed on a partition of the node-tree. However, these optimizations through implementation do not reduce the overall complexity of the algorithm, and will thus not be covered in this article. \n\n\n% Equations \\Cref{eq:pmwdif,eq:pseudodelay,eq:snodeparity,eq:jnodeparity} show that the differences in PMW with respect to the root node can be calculated through two depth-first searches (DFS) of $\\nset$. In the first DFS, the \\emph{parity DFS}, we calculate the node parity $\\pi_N$ a via tail-recursive function using \\Cref{eq:snodeparity,eq:jnodeparity}. In the second DFS, the \\emph{PMW DFS}, we calculate the PMW differences $\\delta_N$ via a head-recursive function using \\Cref{eq:pmwdif,eq:pseudodelay}. \n\n% \\todo[inline]{MOVE? or expand, growth DFS is not yet introduced}During this second DFS, the minimal PMW difference within $\\nset$ can be kept track of by comparison for calculating the node delay $\\delta_N$ at a later instance during the \\emph{growth DFS}. \n\n% The Union-Find decoder grows clusters by adding half-edges to all boundary vertices of the cluster. Instead, here we propose to grow only the nodes with minimal $PMW$. \n%A single growth iteration, which is applied in the Union-Find decoder by adding half-edges to all boundary vertices of the cluster, is now replaced by another DFS of $\\nset$ from the same root $R$ as before. \n%During this DFS, $\\delta_N$ of every node $N$ is calculated via \\Cref{eq:delaypseudo} and $N$ is conditionally grown --- adding half-edges to the boundary vertices in the current node and adding $\\nicefrac{1}{2}$ to its radius $\\rho_N$ --- if $\\delta_N = 0$. \n% For this, it is necessary to save the list of boundary vertices to each node (\\Cref{fig:nodetypes}c). %When the delays $\\delta_N$ for all nodes in $\\nset$ are zero, all nodes are grown simultaneously within the same iteration. \n\n% As the nodes grow, the values for $\\delta_N$ across $\\nset$ change. %This would mean that the DFS's of node parity and delay need to be done after each growth iteration. \n% Fortunately, if no new nodes are added to $\\nset$ after a growth iteration, the parities %$\\pi_N$ on iteration $t+\\theta$ \n% can be calculated via previous values of the PMW differences. %pseudo-delays in iteration $t$ by the introduction of the node \\textbf{wait} parameter $\\omega_N$. \n% During the growth DFS, if $\\delta_N \\neq 0$, add 1 to $\\omega_N$. If no nodes are added to $\\nset$, the node delay in the next iteration are\n% \\begin{multline}\\label{eq:delay}\n%     \\delta_N(t+\\theta) = \\tilde{\\delta}_N(t) - \\min_{X \\in \\nset(t)}{\\tilde{\\delta}_X} - \\omega_N(t+\\theta-1),  \\\\\n%     \\hspace{.3cm} N \\in \\nset, \\hspace{.3cm} \\nset(t+\\theta) = \\nset(t).  \n% \\end{multline}\n\n% Note that we have not stated which node in $\\nset$ should be the root node. In fact, any node in $\\nset$ could have been picked as the root of the node-tree. The only requirement is that the DFS of cluster growth must be performed along the same direction as the DFS's of the parity and delay calculations. If no cluster mergers occur, the node delays can be reused in the node suspension calculation prior to node growth. The node-tree is constructed by storing all neighbors of a node to a list. This way, the DFS's' direction can be determined by simply saving the root node, the starting point of the DFS's, to the cluster. All node variables are depicted in \\Cref{fig:nodetypes}c. \n% In the next section, we expand upon this idea of \"reusing\" some intermediate parameters to calculate the node suspensions after a cluster merger.  \n\n% \\subsection{Joining node-trees}\\label{sec:nodejoin}\n\n% \\Figure[b](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure5.pdf}{\n%     \\emph{(a)} An odd cluster $\\nset_o=\\{A, B, O\\}$ with root $A$ joins with an even cluster $\\nset_e=\\{C, E\\}$ with root $C$ on nodes $O, E$, respectively, to a joined node-tree. If we choose to \\emph{(b)}, make $E$ a child of $O$, the parities and delays the subtree of $\\nset_o$ can unchanged, and we only have to perform partial parity and delay calculations over the subtree of $\\nset_e$. If we choose to \\emph{(c)}, make $O$ a child of $E$, parities and delays have to be recalculated in the entire joined node-tree. \\label{fig:inversion}}\n\n\\Figure[tb](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure4.pdf}{\n    The relevant data structures. \\emph{(a)} The cluster-tree of the Union-Find data structure, whose elements are vertices $v$. The path from a vertex to the root of the cluster-tree is traversed to find the root element, which differentiates clusters. Next to the cluster size and parity, the root node $R$ of the node-tree $\\nset$ is stored at the root of the cluster-tree. Each vertex $v$ additionally stores to which node $N$ it belongs. \\emph{(b)} A spanning-tree $\\vset$ with 3 non-trivial vertices. As $\\vset$ is strictly acyclic, the cluster's edges must be maintained such that no cycles are created. This is done during growth by removing edges (red dotted lines) if a cycle is detected. \\emph{(c)} The node-tree $\\nset$, which consists of the syndrome-nodes $\\dot{A}, \\dot{B}, \\dot{C}$ with primer vertices $a, b, c$, and junction-nodes $\\bar{D}, \\bar{I}$ with roots $d,i$. At each node $N$ and the root $R=\\dot{B}$ various variables are stored.\\label{fig:nodetypes}}\n\n% As clusters grow in size they merge with other clusters. \n% %In the Union-Find (UF) algorithm, odd clusters\n% %parity clusters of an odd number of non-trivial vertices, which are elements of $\\sigma$, \n% %grow %in size \n% %repeatedly and merge with other clusters until all clusters are even. \n% %The data structures of the merged cluster can be obtained by merging the data structures of the original clusters: %During these mergers, the node-trees and the cluster-trees are merged. %of the Partitioned-Growth data structure are combined. \n% %Let us first make a  distinction between the merging protocols of the underlying data structures; \n% %the cluster-trees are merged with the $\\Union$ function, whereas \n% In the following we describe how to obtain the node-tree of the merged cluster from the original node-trees. % are merged with the $\\Nodejoin$ function which we describe in the following. %After a join of multiple node-trees, the node delays within the combined node-tree change. Therefore, the $\\Nodejoin$ protocol's focus is to minimize the DFS's of the recalculation of the node parity and delays in the combined node-tree. \n\n% %Let the parity $\\nset$ be the number of syndrome-nodes in $\\nset$, which is equivalent to the parity of the cluster of $\\nset$. \n\n% Since only odd clusters grow, only two types of clusters can merge: even with odd and odd with odd. \n\n% For even node-trees, the PMW is undefined since a perfect matching would not be possible when merging with a non-trivial vertex. Consequently, PMW differences are undefined for even node-trees and do not need to be calculated. \n\n% The second type of merger is between an even and an odd cluster. %The combined cluster is odd, and its growth is continued. Thus, its node delays must be computed. \n% In order to define the new node-tree, we need to choose a new root. We consider two different options, choosing the root of the odd cluster and choosing the root of the even cluster:\n\n% Let $\\nset_o,\\nset_e$ be the odd and even node-trees that are to be joined, and let $O\\in \\nset_o,E \\in \\nset_e$ be the nodes connected (\\Cref{fig:inversion}\\emph{a}).\n% If $\\nset_o$'s root becomes the root of the joined node-tree (\\Cref{fig:inversion}\\emph{b}), $E$ becomes a child node of $O$. \n% Since $\\nset_e$ contains an even number of syndrome-nodes, the node parities in $\\nset_o$ do not change. \n% Hence, the node parity DFS is only necessary in the subtree $\\nset_e$, which now has $E$ as subroot potentially different than the original root. \n% Furthermore, as the node PMW difference depends only on its own properties and its parent's, the node PMW DFS is also only required from node $E$ and within the subtree of $\\nset_e$. \n% Hence, only partial DFS's within the even cluster are required. % of the node-tree are precisely what was required, as the node parity and delays in $\\nset_e$ were undefined. \n\n% Alternatively, if $\\nset_e$'s root becomes the root of the combined tree (\\Cref{fig:inversion}\\emph{c}), an odd number of syndrome-nodes are attached to $E$. In consequence the parities of the nodes on the path from $E$ to the root are changed. This choice of root requires the DFS's on the entire combined node-tree to calculate for node parities and PMW differences. \n\n% For this reason, when merging node-trees we keep the root of the odd node-tree. We dub this strategy \\textbf{Odd-Rooted Join}. \n\n% In addition, a cluster can be subjected to multiple mergers within the same growth iteration, during which the parity of the merged cluster changes depending on the number of mergers and the parities of the clusters involved. The DFS's related to the parities and PMW differences should not be calculated directly after the joining of node-trees. %After all, it may be possible for the cluster to merge again such that the parities and delays become invalid. \n% \\textcolor{red}{To prevent redundant calculations, subroots of the even subtrees are stored in a list at the root of the node-tree (\\Cref{fig:nodetypes}\\emph{c}). When multiple mergers occur, the root node that stores the now redundant subroots is replaced by a new root with a new list of even subtrees subroots. If a cluster is selected for growth, we loop over the list of the subroots in the list at the new root node and initiate the DFS's from these subroots.} We call this the \\textbf{Root List Replacement}. \n", "meta": {"hexsha": "6fb568bcfbfe6653f8a1c605e91218b6e8f53f8e", "size": 16014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_algo_d_grow.tex", "max_stars_repo_name": "watermarkhu/tqe_paper_ufbb", "max_stars_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_d_grow.tex", "max_issues_repo_name": "watermarkhu/tqe_paper_ufbb", "max_issues_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_d_grow.tex", "max_forks_repo_name": "watermarkhu/tqe_paper_ufbb", "max_forks_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-11T15:53:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-11T15:53:16.000Z", "avg_line_length": 116.8905109489, "max_line_length": 979, "alphanum_fraction": 0.7525290371, "num_tokens": 4140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6456050350747378}}
{"text": "%!TEX root=report.tex\n\\subsection{Time Series Analysis}\n\nIn time series analysis one attempts to find a model for predicting future observations\n(this is different form the OLS analysis which tries to estimate the trends in the data, such as velocity and acceleration).\n Once such a model is found, it should be validated by analyzing the residuals. These residuals must be approximately white noise distributed \\cite[p.~130]{time-series-analysis}, otherwise the model is invalid. \n\n\\subsubsection{ARIMA}\n\nARIMA is the name of the stochastic model used. The theory is very complex so it will not be discussed in detail here, instead we refer to \\cite[p.~130]{time-series-analysis}.\n\nIn short ARIMA uses the previous values with some weight to predict future values. Which values are used is denoted by the following notation:\n\\begin{equation}\n(p, d, q) \\times (P, D, Q)_s\n\\end{equation}\n\n$p$ is the highest lags of actual measurements used and $q$ is the maximum amount of lags in residuals used. The $d$ part indicates how many difference operators which should be used to transform the data. $(P, D, Q)$ is completely similar, but steps not by one lag but by $s$ lags ($s=$season length). This allows for seasons trends such as an yearly pattern.\n\n\\subsubsection{AutoCorrelation function (ACF) and Partial AutoCorrelation Function (PACF)}\n \nACF and PACF are measures of correlation between different time lags and are used to make a qualified guess about how the prediction model should look like. \nFor more detail on how these are estimatied, please see \\cite[p.~146]{time-series-analysis}.\n\nWhen ACF and PACF have been estimated, rules \\cite[table~6.1]{time-series-analysis} for how the stochastic model should look can be applied.\nTypically when dealing with complex models, this becomes an iterative and subjective process - different analysts might reach different models.\nThe iterative step consist of estemating parameters, then calculate ACF and PACF, interpet them, estimate parameters, ... , and so it continues until the ACF and PACF suggest that no more lag terms(weights) are needed.\n\n\\subsection{Ljung-Box test}\n\nThe null hypothesis for the Ljung-Box is ``The data is independently distributed''.\nIn the ARIMA case it is applied to model residuals; so in other words it tests whether residuals at different lags have any correlation with each other. \n Thus a low p-value means that the residuals aren't white noise.\n\nThe Ljung-Box is a $\\chi^2$ test with the statistical value:\n\\begin{equation}\nL = n \\cdot (n + 2) \\sum_{k=1}^h \\frac{\\hat{\\rho}_k^2}{n - k}\n\\end{equation}\n\n$n$ is the number of observations. The parameter $h$ is the highest lag in the ACF which should be considered. The $\\chi^2$ statistics, have $h - (p + q + P + Q)$ degrees of freedom.\n", "meta": {"hexsha": "bf76b7296646e1181f1d965876adacfcb26c9f22", "size": 2772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-ts.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-ts.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-ts.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": 69.3, "max_line_length": 360, "alphanum_fraction": 0.7709235209, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.6456050342999278}}
{"text": "\\documentclass[10pt,english]{article}\n\n%\\usepackage[T1]{fontenc}\n%\\usepackage[utf8]{inputenc}\n\\usepackage[a4paper,left=0.4in, right=0.4in,top=0.5in,bottom=0.6in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{subcaption}\n\\usepackage{epstopdf}\n\\usepackage{graphicx}\n\\usepackage{mathrsfs}\n\\usepackage{epstopdf}\n\\usepackage{mathtools}\n\\usepackage{textcomp}\n\\usepackage{graphicx}\n\\usepackage{xcolor}\n\\usepackage{epstopdf}\n%\\usepackage{multicol}\n%\\usepackage{tikz}\n\\usepackage{hyperref}\n\n% code listing settings\n\\usepackage{listings}\n\\lstset{\n    language=Python,\n    basicstyle=\\ttfamily\\small,\n    aboveskip={1.0\\baselineskip},\n    belowskip={1.0\\baselineskip},\n    columns=fixed,\n    extendedchars=true,\n    breaklines=true,\n    tabsize=4,\n    prebreak=\\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\hookleftarrow}},\n    frame=lines,\n    showtabs=false,\n    showspaces=false,\n    showstringspaces=false,\n    keywordstyle=\\color[rgb]{0.627,0.126,0.941},\n    commentstyle=\\color[rgb]{0.133,0.545,0.133},\n    stringstyle=\\color[rgb]{01,0,0},\n    numbers=left,\n    numberstyle=\\small,\n    stepnumber=1,\n    numbersep=10pt,\n    captionpos=t,\n    escapeinside={\\%*}{*)}\n}\n\\author{Steven Porretta \\\\ Student \\# 100756494}\n\\title{Assignment \\#4}\n\\date{}\n\\begin{document}\n    \\maketitle\n    Code can be found at \\url{https://github.com/0xSteve/learning_automata_simulator}\n    \\section{Question 1}\n        In this section we will examine some code snippets from the first question.\n    \\begin{lstlisting}[label={list:first},caption=Testbench code for the Tsetlin.] \n    c2 = 0.7\n    c1 = 0.05\n    for i in range(0, 7):\n        print(\"c1 = \" + str(c1) + \", c2 = \" + str(c2) + \", N = 13.\")\n        a = la.Tsetlin(13, 2, [c1, c2])\n        a.simulate(50, 30001)\n        b = ala.Tsetlin.stationary_probability_analytic([c1, c2], 13)\n        c = ala.Tsetlin.number_of_states_estimate([c1, c2])\n        print(\"Tsetlin P1(infinity) = \" + str(b) + \"(Analytic)\")\n        print(\"Tsetlin P1(infinity) = \" + str(a.action_average[0]) + \"(Simulated)\")\n        print(\"Tsetlin # of states required = \" + str(c) + \"(Estimate)\")\n        c1 += 0.1\n        c1 = round(c1, 2)\n\\end{lstlisting}\nThis excerpt of code generates the entire quantity of required code for this question.  As can be seen in the following code-snippet.\n\n\\begin{lstlisting}[label={list:first},caption=Testbench output.] \nc1 = 0.05, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.9999999890725503(Analytic)\nTsetlin P1(infinity) = 1.0(Simulated)\nTsetlin # of states required = 3(Estimate)\nc1 = 0.15, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.9999778874501014(Analytic)\nTsetlin P1(infinity) = 1.0(Simulated)\nTsetlin # of states required = 4(Estimate)\nc1 = 0.25, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.9990142374252533(Analytic)\nTsetlin P1(infinity) = 0.999998000067(Simulated)\nTsetlin # of states required = 6(Estimate)\nc1 = 0.35, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.9865794150962881(Analytic)\nTsetlin P1(infinity) = 0.999797340089(Simulated)\nTsetlin # of states required = 9(Estimate)\nc1 = 0.45, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.9151468144874294(Analytic)\nTsetlin P1(infinity) = 0.980783973868(Simulated)\nTsetlin # of states required = 18(Estimate)\nc1 = 0.55, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.7453193640776348(Analytic)\nTsetlin P1(infinity) = 0.786514449518(Simulated)\nTsetlin # of states required = 0(Estimate)\nc1 = 0.65, c2 = 0.7, N = 13.\nTsetlin P1(infinity) = 0.5680008401435711(Analytic)\nTsetlin P1(infinity) = 0.570874970834(Simulated)\nTsetlin # of states required = 0(Estimate)\n\\end{lstlisting}\nNow that it is seen working as one would expect, considering rounding errors from python 3.6, it is time to take a look at the useful snippets of code governing the functionality of the Tsetlin, and Krylov automata.\n\n\\begin{lstlisting}[label={list:first},caption=Tsetlin core code.] \n     def next_state_on_reward(self):\n        '''Find the next state of the learner, given that the teacher\n           rewarded.'''\n        if (self.current_state mod (self.N / self.R) != 1):\n            self.current_state -= 1\n\n    def next_state_on_penalty(self):\n        '''Find the next state of the learner, given that the teacher\n           penalized.'''\n        if(self.current_state mod (self.N / self.R) != 0):\n            self.current_state += 1\n        elif(self.current_state mod (self.N / self.R) == 0):\n            # Don't really add states, just cycle through N, 2N, 4N, etc.\n            if(self.current_state != self.N):\n                a = (self.N / self.R) mod self.N\n                self.current_state = a + self.current_state\n            else:\n                self.current_state = self.N / self.R\n\n    # Determine the next state as the teacher.\n    def environment_response(self):\n        '''Determine the next state of the learner from the perspective\n        of the teacher.'''\n        response = uniform(0, 1)\n        penalty_index = 1\n        if(self.current_state <= self.n):\n            self.actions[0] += 1\n            penalty_index = 0\n        else:\n            self.actions[1] += 1\n\n        if(response > self.c[penalty_index]):\n            # Reward.\n            self.next_state_on_reward()\n        else:\n            # Penalty.\n            self.next_state_on_penalty()\n\\end{lstlisting}\nThe above is the core code of the Tsetlin machine, governing state translations and action choices.  Essentially, whenever it is in the range 1 to N, it chooses action $\\alpha_1$ and $\\alpha_2$ otherwise.  This code is essentially the same for the Krylov machine, which we will see in the next section.\n\n\\section{Question 2}\n\\begin{lstlisting}[label={list:first},caption=testbench for the Krylov 2-action.] \n    for i in range(0, 7):\n    print(\"c1 = \" + str(c1) + \", c2 = \" + str(c2) + \", N = 13.\")\n    a = la.Tsetlin(13, 2, [c1/2, c2/2])\n    a.simulate(50, 30001)\n    b = ala.Tsetlin.stationary_probability_analytic([c1, c2], 13)\n    c = ala.Tsetlin.number_of_states_estimate([c1, c2])\n    d = la.Krylov(13, 2, [c1, c2])\n    d.simulate(10, 50000)\n    e = ala.Tsetlin.stationary_probability_analytic([c1, c2], 13)\n    f = ala.Tsetlin.number_of_states_estimate([c1, c2])\n    print(\"Tsetlin P1(infinity) = \" + str(b) + \"(Analytic)\")\n    print(\"Tsetlin P1(infinity) = \" + str(a.action_average[0]) + \"(Simulated)\")\n    print(\"Tsetlin # of states required = \" + str(c) + \"(Estimate)\")\n    print(\"Krylov P1(infinity) = \" + str(e) + \"(Analytic)\")\n    print(\"Krylov P1(infinity) = \" + str(d.action_average[0]) + \"(Simulated)\")\n    print(\"Krylov # of states required = \" + str(f) + \"(Estimate)\")\n    c1 += 0.1\n    c1 = round(c1, 2)\n\\end{lstlisting}\nAs can be seen from the code, this test bench looks very similar to the test bench of question 1, however, note the $c$ vector for the Tsetlin automaton is now $c_1 / 2 $, $c_2/2$.  As is expected, both automata behave in the same manner. as can be seen from the output code snippet.\n\\begin{lstlisting}[label={list:first},caption=testbench output for the Krylov 2-action.] \n    c1 = 0.05, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.9999999890725503(Analytic)\n    Tsetlin P1(infinity) = 1.0(Simulated)\n    Tsetlin # of states required = 3(Estimate)\n    Krylov P1(infinity) = 0.9999999890725503(Analytic)\n    Krylov P1(infinity) = 1.0(Simulated)\n    Krylov # of states required = 3(Estimate)\n    c1 = 0.15, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.9999778874501014(Analytic)\n    Tsetlin P1(infinity) = 0.999999333356(Simulated)\n    Tsetlin # of states required = 4(Estimate)\n    Krylov P1(infinity) = 0.9999778874501014(Analytic)\n    Krylov P1(infinity) = 1.0(Simulated)\n    Krylov # of states required = 4(Estimate)\n    c1 = 0.25, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.9990142374252533(Analytic)\n    Tsetlin P1(infinity) = 1.0(Simulated)\n    Tsetlin # of states required = 6(Estimate)\n    Krylov P1(infinity) = 0.9990142374252533(Analytic)\n    Krylov P1(infinity) = 1.0(Simulated)\n    Krylov # of states required = 6(Estimate)\n    c1 = 0.35, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.9865794150962881(Analytic)\n    Tsetlin P1(infinity) = 1.0(Simulated)\n    Tsetlin # of states required = 9(Estimate)\n    Krylov P1(infinity) = 0.9865794150962881(Analytic)\n    Krylov P1(infinity) = 1.0(Simulated)\n    Krylov # of states required = 9(Estimate)\n    c1 = 0.45, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.9151468144874294(Analytic)\n    Tsetlin P1(infinity) = 1.0(Simulated)\n    Tsetlin # of states required = 18(Estimate)\n    Krylov P1(infinity) = 0.9151468144874294(Analytic)\n    Krylov P1(infinity) = 1.0(Simulated)\n    Krylov # of states required = 18(Estimate)\n    c1 = 0.55, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.7453193640776348(Analytic)\n    Tsetlin P1(infinity) = 0.983473884204(Simulated)\n    Tsetlin # of states required = 0(Estimate)\n    Krylov P1(infinity) = 0.7453193640776348(Analytic)\n    Krylov P1(infinity) = 0.999998(Simulated)\n    Krylov # of states required = 0(Estimate)\n    c1 = 0.65, c2 = 0.7, N = 13.\n    Tsetlin P1(infinity) = 0.5680008401435711(Analytic)\n    Tsetlin P1(infinity) = 0.670734975501(Simulated)\n    Tsetlin # of states required = 0(Estimate)\n    Krylov P1(infinity) = 0.5680008401435711(Analytic)\n    Krylov P1(infinity) = 0.870114(Simulated)\n    Krylov # of states required = 0(Estimate)\n\\end{lstlisting}\nObserving the code for the Krylov machine, one notices that most of the code is inherited from the Tsetlin machine, except the state translations. It is incredible, that the only major distinction is that a penalty is treated as a penalty with 50\\% probability and a success otherwise. Literally, all other code for the Krylov machine is inherited from the Tsetlin.\n\\clearpage\n\\begin{lstlisting}[label={list:first},caption=Krylov core code.] \ndef next_state_on_penalty(self):\n        '''Find the next state of the learner, given that the teacher\n           penalized.'''\n\n        # If this number is greater than 0.5, then penalize the learner.\n        is_penalty = uniform(0, 1)\n\n        if(is_penalty >= 0.5):\n            Tsetlin.next_state_on_penalty(self)\n        else:\n            Tsetlin.next_state_on_reward(self)\n   \n\\end{lstlisting}\n\n\\section{Question 3} \n\nFirst let us consider state changes in the $L_{R-I}$, since there really are no states, but instead just an interval, $\\lbrace0, 1\\rbrace$, of possibilities.  Consider the following code-snippet.\n\n\\begin{lstlisting}[label={list:first},caption=State Translation in the $L_{R-I}$  automaton.] \n def do_reward(self, action):\n        if(action == 2):\n            self.p1 = self.k_r * self.p1\n        else:\n            self.p1 = 1 - (self.k_r * self.p2)\n        self.p2 = 1 - self.p1\n\n    def do_penalty(self):\n        pass  \n\\end{lstlisting}\nIt can be seen from the above code-snippet, that when the environment rewards, an action is updated based on the action selected.  When the environment issues a penalty, nothing happens.  The python command \\textit{pass} is command that simply does nothing, and is usually used for prototyping.  In this case, pass is included to explicitly show that a penalty does nothing.\n\nFrom this automaton some interesting things can be observed.  First, let us consider the output of the testbench.py file.  Time complexity has been measured in terms of discrete steps instead of actual time spent in the processor. The physical time, does not represent the number of actions being computed, as many operations can be processed simulatneously, in the background of a system, the time is not accurate.  A corolary to this event is that the number of discrete calls to the program, accurately represent the time complexity, when each action is considered a time unit.  To better understand this, observe the following code snippet.\n\\begin{lstlisting}[label={list:first},caption=State Translation in the $L_{R-I}$  automaton.] \n=============================================================\nThe optimal K_r value is: 0.74995\nThe optimal lambda_r value is: 0.25005\nThe accuracy for k_r = 0.74995 is: 0.963\nThe computation time in iterations is: 18\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.7811937499999999\nThe optimal lambda_r value is: 0.2188062500000001\nThe accuracy for k_r = 0.7811937499999999 is: 0.958\nThe computation time in iterations is: 26\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.7811937499999999\nThe optimal lambda_r value is: 0.2188062500000001\nThe accuracy for k_r = 0.7811937499999999 is: 0.965\nThe computation time in iterations is: 16\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.8124374999999999\nThe optimal lambda_r value is: 0.18756250000000008\nThe accuracy for k_r = 0.8124374999999999 is: 0.953\nThe computation time in iterations is: 45\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.874925\nThe optimal lambda_r value is: 0.12507500000000005\nThe accuracy for k_r = 0.874925 is: 0.976\nThe computation time in iterations is: 57\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.90616875\nThe optimal lambda_r value is: 0.09383125000000003\nThe accuracy for k_r = 0.90616875 is: 0.969\nThe computation time in iterations is: 160\n=============================================================\n=============================================================\nThe optimal K_r value is: 0.96865625                                                                                                  \nThe optimal lambda_r value is: 0.031343750000000004                                                                                   \nThe accuracy for k_r = 0.96865625 is: 0.977                                                                                           \nThe computation time in iterations is: 1298                                                                                           \n=============================================================   \n\\end{lstlisting}\nIt is observable that as $c1$ approaches $c2$ the number of operations increase exponentially.  It is also observable that as $n \\to \\infty$, then $\\lambda_R \\to 0$. Corolary: $c_1 \\to c_2$, then $\\lambda_R \\to 0$ or $k_R \\to \\infty$.  To get a better understanding of this effect, observe the following graph, Figure \\ref{blah}. It can be seen that $\\lambda_R$ approaches $0$ as the time complexity goes to infinity.  This is representative of the difficulty of the system.  When the percent difference between penalties of choosing action 1 and action 2 approaches 0, then the time complexity approaches infinity, and the $\\lambda_R$ required becomes an undesirably low value.\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics{plot.png}\n    \\caption{$\\lambda_R$ Vs. $n$} \\label{blah}\n\\end{figure}\n\\end{document}", "meta": {"hexsha": "5505407fe07f3f45c1b95d0df71192f4911a6b03", "size": 15125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup.tex", "max_stars_repo_name": "0xSteve/learning_automata_simulator", "max_stars_repo_head_hexsha": "ca60bb3a2d3ecb7d345f9a0fcccb53a2e2d7856d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writeup.tex", "max_issues_repo_name": "0xSteve/learning_automata_simulator", "max_issues_repo_head_hexsha": "ca60bb3a2d3ecb7d345f9a0fcccb53a2e2d7856d", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "0xSteve/learning_automata_simulator", "max_forks_repo_head_hexsha": "ca60bb3a2d3ecb7d345f9a0fcccb53a2e2d7856d", "max_forks_repo_licenses": ["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.7532894737, "max_line_length": 678, "alphanum_fraction": 0.6373553719, "num_tokens": 4520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6456050328756746}}
{"text": "\nAs well as in logistic regression as in neural networks, minimizing(or maximizing depending on your setup) the cost function is a central problem, and can to some extent be stated as \\textit{the} problem. Having a method which is both efficient and converges towards the minimum is, luckily, not a new problem in computer science. In the logistic regression optimization, three main methods will be utilized, while in the neural network we will focus on the stochastic conjugate gradient descent. For logistic regression we will use a learning rate optimized gradient descent method, and \n\n\nGradient descent measures the local gradient of the cost function, with regards to the weights $\\bm{w}$(or $\\beta$. Since the gradient goes in the direction of fastest increase, we will go in the opposite direction, i.e. negative gradient. We start by choosing random values for $\\bm{w}$ (since our cost function is convex any choice should give correct results), calculate the gradient, update the $\\bm{w}$ values, and do this iteratively until the algorithm converges to a minimum. The size of the steps is important, and is determined by the learning rate. If the learning rate is too small, we will need many iterations which is time consuming. However, if the learning rate is too high, we might overshoot and miss the minimum. One way to choose the learning rate is too let it depend on the size of the gradient. If the gradient is large, i.e a steep slope, the learning rate can be relatively high. When the gradient is small, the learning rate is also small.\n\n\\subsubsection{Gradient descent}\nGradient descent is set up in a general fashion as, utilizing an optimized learning rate $\\eta_k$ find and a scaling parameter $\\gamma$. The scaling parameter $\\gamma$ is introduced in order to prevent results from blowing up.\n\\begin{algorithm}[H]\n    \\caption{Gradient descent.}\n    \\label{alg:gd}\n    \\begin{algorithmic}[1]\n        \\State Input: $\\bm{X}$, $\\bm{y}$, $\\bm{w}_0$, $\\eta$\n        \\State Set initial weights, $\\bm{w} = \\bm{w}_0$\n        \\State Set previous gradient with current, $\\nabla_0 = \\nabla_1$\n        \\While{$i < N_\\mathrm{max}$ and $||\\nabla\\mathcal{C}(\\bm{w})||<\\varepsilon$}\n            \\State $z = \\bm{X}\\cdot \\bm{w}$\n            \\State $p = \\sigma(z)$\n            \\State $\\nabla_0 = \\nabla_1$, set previous gradient to current.\n            \\State $\\nabla_1 = - \\bm{X}^T \\cdot (\\bm{y} - \\bm{p}) / \\gamma + \\lambda f_L(\\bm{w}) / \\gamma$\n            \\State $\\bm{w}_0 = \\bm{w}$\n            \\State Update learning parameter, $\\eta_k$\n            \\State $\\bm{w} = \\bm{w}_0 - \\eta_k \\nabla_1$, update weights.\n        \\EndWhile\n        \\State Return $\\bm{w}$\n    \\end{algorithmic}\n\\end{algorithm}\nThe full implementation with the optimized learning rate $\\eta_k$ can be seen in the article \\citet{optimal-learning-rate}.\n\n\\subsubsection{Stochastic gradient descent}\nStochastic gradient descent is similar to gradient descent, expect that we first randomly shuffle our data, then divide our data into mini batches, $N_\\mathrm{mb}$. Then we run gradient descent on each of the mini batches, and take the average of the outputted gradients as our gradient descent step. We repeat this $N_\\mathrm{epochs}$.\n\\begin{algorithm}[H]\n    \\caption{Stochastic gradient descent(SGD).}\n    \\label{alg:sgd}\n    \\begin{algorithmic}[1]\n        \\For $i_e$ in $N_\\mathrm{epochs}$ epochs\n            \\State Shuffle data $\\bm{X}_\\mathrm{train}$, $\\bm{y}_\\mathrm{train}$\n            \\State Split into mini batches, $\\bm{X}_\\mathrm{train}$, $\\bm{y}_\\mathrm{train}$\n            \\For $i_\\mathrm{mb}$ in mini batches,\n                \\State Perform gradient descent step, and retrieve $\\nabla\\bm{w}_{i_\\mathrm{mb}}$\n            \\EndFor\n            \\State Take the average of the $\\nabla\\bm{w}_{i_\\mathrm{mb}}$ and update the weight matrix $\\bm{w}$.\n        \\EndFor\n    \\end{algorithmic}\n\\end{algorithm}\n\n\n\n% To minimize this cost function we use gradient descent. \\husk{Gradient descent measures the local gradient of the cost function, with regards to $\\beta$ in our case. Since the gradient goes in the direction of fastest increase, we will go in the opposite direction, i.e. negative gradient. We start by choosing random values for $\\beta$ (since our cost function is convex any choice should give correct results), calculate the gradient, update the $\\beta$ values, and do this iteratively until the algorithm converges to a minimum. The size of the steps is important, and is determined by the learning rate. If the learning rate is too small, we will need many iterations which is time consuming. However, if the learning rate is too high, we might overshoot and miss the minimum. One way to choose the learning rate is too let it depend on the size of the gradient. If the gradient is large, i.e a steep slope, the learning rate can be relatively high. When the gradient is small, the learning rate is also small.}\n\n% \\sjekk{Returning to the logistic regression problem, the derivative of the cost function is\n% \\begin{equation}\\label{eqT:diff_cost}\n% \\begin{split}\n% \\frac{\\partial J(\\beta)}{\\partial \\beta} &=-\\frac{1}{N}\\bm{X}^T(\\bm{y}-\\bm{p})\\\\\n%  &= \\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y}),\n% \\end{split}\n% \\end{equation}\n% where $\\bm{X}$ is the $N\\times(p+1)$ matrix of $x_i$ values, $\\bm{p}$ is the vector of fitted probabilities with $i$th element $p(x_i;\\beta)$ and $\\bm{y}$ is the vector of $y_i$ values. The new $\\beta$ using gradient descent is then\\\\\n% $\\beta_{new} = \\beta_{old}\\ -\\ \\frac{\\partial J(\\beta)}{\\partial \\beta}lr$, where $lr$ is the learning rate (step size).} \\husk{This is done iteratively until we reach the set max iterations or $\\frac{\\partial J(\\beta)}{\\partial \\beta}$ is within a given tolerance of zero.}\n\n% \\sjekk{Like we introduced Lasso and Ridge regression to avoid overfitting in Project 1, we can add a penalty term to the cost function in Equation \\ref{eq:Geron_cost}. In our project we used two different penalties: $L1 = \\lambda|\\beta|$ and $L2 = \\lambda||\\beta||^2$. When fitting the model we need to include the derivatives of the penalty term in Equation \\ref{eqT:diff_cost}.} \\husk{The gradient with the penalty term is,\n% \\begin{equation}\n% \\begin{split}\n% \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{sign(\\beta)},\\ for\\ L1\\ regularization\\\\\n%  &\\mathrm{or}\\\\\n% \\frac{\\partial J(\\beta)}{\\partial \\beta} &=\\frac{1}{N}\\bm{X}^T(\\bm{p}-\\bm{y})\\ + \\lambda\\cdot{2\\beta},\\ for\\ L2\\ regularization. \n% \\end{split}\n% \\end{equation}\n% }\n", "meta": {"hexsha": "879cf707525f53f3de56117330b7336f681714a5", "size": 6519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory/optimization.tex", "max_stars_repo_name": "hmvege/FYSSTK4155-Project2", "max_stars_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_stars_repo_licenses": ["MIT"], "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/optimization.tex", "max_issues_repo_name": "hmvege/FYSSTK4155-Project2", "max_issues_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_issues_repo_licenses": ["MIT"], "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/optimization.tex", "max_forks_repo_name": "hmvege/FYSSTK4155-Project2", "max_forks_repo_head_hexsha": "3cf617399f99026cbcd79f8153d3196ebd86c7cd", "max_forks_repo_licenses": ["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.1285714286, "max_line_length": 1017, "alphanum_fraction": 0.7050161068, "num_tokens": 1780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6456050265292179}}
{"text": "\\subsection{Kessler Parameterization}\nSCALE implements a one-moment bulk microphysical scheme, which treats only warm clouds (cloud and rain). This scheme predicts the mixing ratio of cloud ($Q_{cloud}$) and rain ($Q_{rain}$). Cloud microphysical processes treated in this scheme are saturation adjustment (corresponding to nucleation, evaporation, and cloud condensation), evaporation, auto-conversion, accretion, and sedimentation. The tendency of $Q_{cloud}$, $Q_{rain}$, and $Q_{v}$ (vapor mixing ratio) is as follows:\n\n\\begin{eqnarray}\n\\frac{\\partial Q_{cloud}}{\\partial t}&=&dQ|_{sat}-dQ|_{auto}-dQ|_{acc}\\\\\n\\frac{\\partial Q_{rain}}{\\partial t}&=&dQ|_{auto}+dQ|_{acc}-dQ|_{evap}-F_{Q_{r}}|_{sed}\\\\\n\\frac{\\partial Q_{v}}{\\partial t}&=&dQ|_{evap}-dQ|_{sat}\n\\end{eqnarray}\n\nwhere $dQ|_{sat}$, $dQ|_{auto}$, $dQ|_{acc}$, and $dQ|_{evap}$ represent the mixing ratio tendency by saturation adjustment, auto-conversion, accretion, and evaporation, respectively. $F_{Q_{r}}|_{sed}$ represents flux of $Q_{r}$ by sedimentation.\\\\ $dQ|_{auto}$, $dQ|_{acc}$, and $dQ|_{evap}$ are given as:\n\n\\begin{eqnarray}\ndQ_{auto}&=&\\left\\{\n\\begin{array}{ll}\nQ_{cloud}*10^{-3} & (Q_{cloud}>10^{-3})\\\\\n0 & (else)\\\\\n\\end{array}\\right.\\\\\ndQ_{acc}&=&2.2\\times Q_{cloud}\\times Q_{rain}^{0.875}\\\\\ndQ_{evap}&=&\\left\\{\n\\begin{array}{ll}\nf_{vent} \\frac{q_{s}-Q_{cloud}}{q_{s}\\rho}\\frac{(\\rho*Q_{rain})^{0.525}}{5.4\\times 10^{5}+\\frac{2.55\\times 10^{8}}{pq_{s}}} & ( q_{s} > Q_{cloud})\\\\\n0 & (else)\\\\\n\\end{array} \\right.\n\\end{eqnarray}\n\nwhere $f_{vent}$ is the ventilation factor ($f_{vent}=1.6+124.9(\\rho Q_{rain})^{0.2046}$), and the unit of $dQ_{***}$ is [kg/kg/s]. $p$, $q_{s}$, and $\\rho$ are pressure, saturation vapor mixing ratio, and total density, respectively.\\\\\n$dQ|_{sat}$ is given as:\n\n\\begin{eqnarray}\ndQ|_{sat}=Q_{v}-q_{s}.\n\\end{eqnarray}\n\nTerminal velocities of cloud ($V_{t,c}$) and rain ($V_{t,r}$) are given as:\n\n\\begin{eqnarray}\nV_{t,c}&=&0\\\\\nV_{t,r}&=&36.34(\\rho Q_{rain})^{0.1364} [m/s]\n\\end{eqnarray}\n\n\n", "meta": {"hexsha": "5c8249666e2a2a084b7534261115e2ad414c13ab", "size": 1999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/descriptions/microphysics_kessler.tex", "max_stars_repo_name": "slayoo/scale", "max_stars_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-06-14T11:12:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T05:29:55.000Z", "max_issues_repo_path": "doc/descriptions/microphysics_kessler.tex", "max_issues_repo_name": "slayoo/scale", "max_issues_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-29T03:38:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-30T05:08:47.000Z", "max_forks_repo_path": "doc/descriptions/microphysics_kessler.tex", "max_forks_repo_name": "slayoo/scale", "max_forks_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-10T10:39:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-28T22:20:41.000Z", "avg_line_length": 48.756097561, "max_line_length": 484, "alphanum_fraction": 0.6668334167, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6455935320071838}}
{"text": "\\documentclass{article}\r\n\\usepackage{mathtools}\r\n\\usepackage{amssymb}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsthm}\r\n\r\n\\begin{document}\r\n\r\n\\newtheorem{theorem}{Theorem}[section]\r\n\\newtheorem{corollary}{Corollary}[theorem]\r\n\\newtheorem{lemma}[theorem]{Lemma}\r\n\r\n\\tableofcontents\r\n\\newpage\r\n\r\n\\section{Probability Space}\r\nThere are often various approaches to probability each with its own advantages\r\nand disadvantages.\r\n\r\nExperiment is a procedure that can be infinitely repeated and has a\r\nwell-defined set of possible outcomes, known as the sample space.\r\n\r\nThe observation/result of the experiment are termed as outcomes.\r\n\r\n\\subsection{Classical Approach}\r\n        Probability of an event $E$ is defined to be: $$P(E)=\\frac{\\text{Number of outcomes in }E}{\\text{Total number of outcomes}}$$\r\n         Some examples are tossing a coin or rolling a die.\r\n         Disadvantages:\r\n         \\begin{itemize}\r\n             \\item Unable to model biases. It says nothing about cases where no\r\n             physical symmetry exists.\r\n             \\item Doesn't deal with cases where total outcomes are infinite.\r\n         \\end{itemize}\r\n\r\n         \\subsection{Frequentist Approach}\r\n         Also known as the relative frequency approach or frequentism. It defines\r\n         an event's probability as the limit of its relative frequency in many\r\n         trials.\r\n\r\n         Probability is defined to be:\r\n         $$ P(E)=\\lim_{n \\to \\infty} \\frac{n_E}{n}$$\r\n         where an experiment is conducted $n$ times and event $E$ occurs $n_E$\r\n         times.\r\n         Disadvantages:\r\n         \\begin{itemize}\r\n             \\item It isn't efficient to conduct an experiment multiple times\r\n             just to find the probability of an event occuring.\r\n             \\item It is unable to deal with subjective belief. Eg: Suppose a\r\n             cricket expert says there is a $50\\%$ of RCB winning the IPL this\r\n             year. It doesn't mean that the RCB has won half the titles in the\r\n             past.\r\n         \\end{itemize}\r\n%\r\n         \\subsection{Axiomatic Approach}\r\n\r\n         \\subsubsection{Probability Space}\r\n\r\nThe triple ($S$, $F$, $P$) is referred to as a probability space where:\r\n\\begin{itemize}\r\n    \\item $S$ : Sample space, set of all possible outcomes of the experiment.\r\n    \\item $F$ : Event Space, subset of the sample space\r\n    \\item $P$ : Probability Measure\r\n\\end{itemize}\r\n\\subsubsection{Sample Space}\r\n\r\n$S$ can either be finite or countably infinite or uncountably infinite.\r\n%28/05\r\n\r\nExamples for S:\r\n\\begin{itemize}\r\n        \\item Finite Sample Space: Single coin toss $ S=\\{H,T\\} $ and two coin tosses $ S=\\{HH,HT,TT,TH\\} $.\r\n        \\item Countably Infinite Sample Space: Keep tossing a coin till you get a head $ S=\\{H,TH,TTH...\\}$.\r\n        \\item Uncountably Infinite Sample Space: We have a circular dart board and we are measuring the angle at which a dart hits the board. $S=[0,2\\pi]$\r\n\\end{itemize}\r\n\r\n\\subsection{Event Space}\r\nCollection of events is called an event space, there are some properties to be satisified such as:\r\nit has to be a ``Sigma Field''.\r\n\r\n\\subsubsection{Sigma Field}\r\nA sigma field (or sigma algebra) F is a collection of subsets of S which satisfies the following properties:\r\n\\begin{itemize}\r\n    \\item $S \\in F$\r\n    \\item If $E \\in F$, then $E^C \\in F$\r\n    \\item If $E_1,E_2,E_3 \\cdots \\in F $, then $\\bigcup_{i=1}^{\\infty} E_i \\in F$\r\n\\end{itemize}\r\n\r\n\\subsubsection{Examples for Event Space}\r\n\\begin{itemize}\r\n    \\item Smallest possible event space:\r\n    $$ F =\\{ \\phi,S\\} $$\r\n    \\item Next non-trivial event space:\r\n    $$ F=\\{ \\phi,E ,E^c ,S\\}$$\r\n    \\item If $E_1 \\in F$ and $E_2 \\in F$, then $E_1 \\cap E_2 \\in F$ (Proof in 1.4.3)\r\n    \\item For S=$\\{1,2,3,4,5,6\\}$ , $E_1 =\\{1,2\\}$ and $E_2=\\{3,4\\}$. The smallest event space containing $E_1$ and $E_2$ is:\r\n    $$ F=\\{\\phi , S, E_1 , E_{1}^{C},E_2 , E_{2}^{C},E_1 \\cup E_2 , (E_{1} \\cup E_{2})^{C}\\}$$\r\n\\end{itemize}\r\n\r\n\\subsubsection{Proposition 1}\r\nA$_1$, A$_2$, A$_3$,....A$_n$ $\\in$ $F$, then $\\bigcap\\limits_{i=1}^n$A$_i$ $\\in$ $F$.\r\n\r\n\\begin{proof}\r\n    If A$_1$, A$_2$, A$_3$,....A$_n$ $\\in$ $F$, then A$_1^c$, A$_2^c$, A$_3^c$,....A$_n^c$ $\\in$ $F$ and $\\bigcup\\limits_{i=1}^n$A$_i^c$ $\\in$ $F$. Then by property 2, $(\\bigcup\\limits_{i=1}^n$A$_i^c)^c$ = $\\bigcap\\limits_{i=1}^n$A$_i$ $\\in$ $F$.\r\n\\end{proof}\r\n\r\n\\subsubsection{Proposition 2}\r\nA, B $\\in$ $F$, then A$\\setminus$B = A - B $\\in$ $F$.\\medskip\r\n\r\n\\begin{proof}\r\n    If B $\\in$ $F$, then B$^c$ $\\in$ $F$ by  property 2. So, A $\\cap$ B$^c$ = A$\\setminus$B $\\in$ $F$ (As seen in proposition 1).\r\n\\end{proof}\r\n\\subsection{Probability Measure}\r\nThe probability measure P is a function returning an event's probability. A probability is a real number between zero and one.\r\n$$ P:F\\rightarrow [0,1]$$\r\n\r\nP has to satisfy the following 3 axioms:\r\n\\begin{itemize}\r\n    \\item $P(E) \\geq 0$\r\n    \\item $P(S)=1$\r\n    \\item If $E_1,E_2 \\cdots \\in F$ such that $E_i \\cap E_j =\\phi$ then:\r\n    $$ P(\\bigcup_{i=1}^{\\infty} E_{i})= \\sum_{i=1}^{\\infty} P(E_i)$$\r\n\\end{itemize}\r\n\r\nFor two disjoint sets:\r\n$P(E_1 \\cup E_2)= P(E_1)+P(E_2)+ \\sum P(\\phi)$\r\n\r\nWe will later see that $P(\\phi)$ is indeed 0.\r\n\r\n\\subsection{Derived Properties of Probability}\r\n\\begin{enumerate}\r\n    \\item $$P(E^C)=1-P(E)$$\r\n        \\begin{proof}\r\n            $$E \\cup E^C = S$$\r\n                $$P(E)+P(E^C)=1$$\r\n\r\n        \\end{proof}\r\n    \\item For any two events $E_1$ and $E_2$,\r\n    $$ P(E_1 \\cup E_2)= P(E_1)+P(E_2)-P(E_1 \\cap E_2)$$\r\n    \\begin{proof}\r\n        $$ P(E_1 \\cup E_2)=P(E_1)+P(E_2 \\cap E_1^C)$$\r\n        Now, $$ E_2=(E_2 \\cap E_1)\\cup (E_2 \\cap E_1^C)$$\r\n        $$ \\Rightarrow P(E_2)=P(E_1 \\cap E_2)+ P(E_1^C \\cap E_2)$$\r\n        Also,\r\n        $$ P(E_1 \\cup E_2)= P(E_1)+P(E_1^C \\cap E_2)$$\r\n        Substitute the required value in the final equation.\r\n    \\end{proof}\r\n\\end{enumerate}\r\n\r\nQuestion:\r\n$ S=\\{1,2,3,4,5,6\\}$. 1 and 5 are equally likely and probability of getting a 6 is one-third.\r\n\r\nFind minimum and maximum probability that we get an even number.\r\n\r\nAnswer:$$ Minimum \\;Prob. = \\frac{1}{3} \\;\\; when \\;\\; P_2 = P_4 = 0$$\r\n$$ Maximum \\;Prob. = 1,  \\;\\; P_2+P_4 =\\frac{2}{3}  $$\r\n\r\n%31/05 notes\r\n\r\n\\section{Conditional Property}\r\n\r\nGiven that an event $A$ has occured.\r\n\r\n$ (S,F,P) \\rightarrow$ Original probability space\r\n\r\nIf additional info has been given that A has occured, probability space need to be suitably modified.\r\n\r\neg: $S=\\{1,2,3,4,5,6\\},\\;E_1=\\{1,2\\},\\;E_2=\\{3,4\\}$\r\n$$ F=\\{\\phi , S, E_1 , E_{1}^{C},E_2 , E_{2}^{C},E_1 \\cup E_2 , (E_{1} \\cup E_{2})^{C}\\}$$\r\nand event $A=E_1^c = \\{3,4,5,6\\}$ has occured.\r\n\r\nThen, $ F_A= \\{ \\phi, A, \\{3,4\\},\\{5,6\\} \\} $.(shown later)\r\n\r\n\r\n\\subsection{Modified probability space}\r\n\r\nThen,\r\n\\begin{itemize}\r\n    \\item $S_A = A$. (Modified Sample Space)\r\n\r\n    \\item $F_A = \\{ (E \\cap A) | E \\in F \\} \\rightarrow E \\cap A \\in F$. (Modified Event Space)\r\n\r\n    (Also if some event $C \\cap A = \\phi $, then $C$ won't occur)\r\n\r\n\r\n\r\n    To prove: $F_A$ also satisfies event space axioms.(see sec. 1.4.1)\r\n\r\n    \\begin{enumerate}\r\n        \\item $A \\in F_A \\rightarrow S\\cap A = A$(S was original sample space)\r\n        $\\Rightarrow A \\in F_A$\r\n\r\n        \\item $D \\in F_A \\Rightarrow D = E \\cap A, D^c \\in F_A$\r\n\r\n        As,\r\n\r\n        $D^c = A \\setminus D= E^c \\cap A \\in F \\quad(Because\\;  E^c \\in F)$\r\n\r\n        \\item $$D_1,D_2,\\cdots \\in F_A$$\r\n        $$ (E_1 \\cap A), \\cdots \\in F_A$$\r\n        $$ E_1, E_2 \\cdots \\in F$$\r\n        $$  \\Rightarrow \\bigcup_{i=1}^{\\infty} E_i \\in F_A$$\r\n        $$ \\Rightarrow  (\\bigcup_{i=1}^{\\infty} E_i) \\cap A \\in F_A$$\r\n        $$\\Rightarrow  (\\bigcup_{i=1}^{\\infty} E_i \\cap A) \\in F_A \\Rightarrow  \\bigcup_{i=1}^{\\infty} D_i \\in F_A$$\r\n\r\n    \\end{enumerate}\r\n    Hence, $F_A$ is an event space.\r\n\r\n    \\item Modified probability measure\r\n\r\n    $$ P(E/A)= \\frac{P(E \\cap A)}{P(A)}$$\r\n\r\n    This definition is called conditional probability measure for any $E \\in F$.\r\n\r\n    eg:\r\n    $ F_A = \\{ \\phi, \\{3,4,5,6\\}, \\{ 3,4\\}, \\{5,6\\} \\}$, then $P(\\{ 3,4\\} / \\{3,4,5,6\\})=1/2$\r\n\r\n    Now, we need to prove $ P(E/A)$  satisfies the 3 axioms of probability measure.(see sec. 1.5)\r\n    \\begin{itemize}\r\n        \\item $ P(E/A) \\geq 0$ (as ratio of two nos. which are positive)\r\n        \\item $ P(S/A)=1$\r\n        \\item $ B_1, B_2 \\cdots$ are all mutually disjoint.\r\n        $$ P(\\bigcap_{i=1}^{\\infty} B_i /A) = \\frac{ P(\\bigcup_{i=1}^{\\infty} B_i \\cap A)}{P(A)}$$\r\n        $$ =\\frac{\\sum_{i=1}^{\\infty} P(B_i \\cap A)}{P(A)} = \\sum_{i=1}^{\\infty} P(B_i /A)$$\r\n        $$  \\Rightarrow P(\\bigcap_{i=1}^{\\infty} B_i /A) = \\sum_{i=1}^{\\infty} P(B_i /A)$$\r\n    \\end{itemize}\r\n\\end{itemize}\r\n\r\n\r\n\r\n\r\n\r\n\\section{Total probability theorem}\r\n\r\nEvents $A_1,\\cdots, A_n \\in F$ which are all mutually exclusive/disjoint and exhaustive. Then,\r\n$$ A_i \\cap A_j = \\phi \\quad \\forall\\; i,j$$\r\n$$ \\bigcup_{i=1}^{n} A_i =S$$\r\n\r\n$$ P(B)= \\sum_{i=1}^{n} P(B/A_i)P(A_i)$$\r\n\r\nthe total probability theorem expresses $ P(B)$  in terms of conditional probability $ P(B/A_i) $ \\& prior probability $P(A_i)$\r\n\\begin{proof}\r\n\r\n    $$ B= \\bigcup_{i=1}^{n} (B \\cap A_i)$$\r\n\r\n    $A_i$'s are disjoint, so $(B \\cap A_i)$ are also disjoint.\r\n\r\n    $$ P(B)= \\sum_{i=1}^{n} P(B \\cap A_i)=\\sum_{i=1}^{n} P(B / A_i)P(A_i)$$\r\n\r\n\r\n\\end{proof}\r\n\r\n\\subsection{Question}\r\nTwo factories manufacture zoggles. 20\\% of $F_1$ are defective. 5\\% of $F_2$ are defective.\r\n\r\nIn any week, $F_1$ produces twice the number of zoggles as $F_2$. What is the probability that a zoggle chosen randomly in a week is defective?\r\n\r\n$$ P(D)=P(F_1)P(D/F_1)+P(F_2)P(D/F_2)$$\r\n$$ = \\frac{2}{3} \\times \\frac{1}{5} + \\frac{1}{3} \\times \\frac{1}{20} = \\frac{3}{20}$$\r\n\r\n%2/6\r\n\r\n\\section{Bayes Theorem}\r\n$A_1, \\cdots, A_n $ are events which are mutually exclusive and exhaustive.\r\n$B$ be an arbitrary event. Then,\r\n$$ P(A_i/B)= \\frac{P(B/A_i)P(A_i)}{\\sum_{i=1}^n P(B/A_i)P(A_i)}$$\r\n\r\n\\begin{itemize}\r\n    \\item $P(A_i)$- Prior probability\r\n    \\item $P(B/A_i)$- Likelihood\r\n    \\item $P(A_i/B)$- Posterior probability\r\n\\end{itemize}\r\n\r\nBayes theorem expresses posterior probabilities $P(A_i/B)$ in terms of prior probabilities  $P(A_i)$ and likehoods  $P(B/A_i)$.\r\n\r\nIn some experiments $P(A_i)$ are all same, $P(A_i)=1/n$. Then posterior probabilities are proportional to likelyhoods:\r\n$$ P(A_i/B)= \\frac{P(B/A_i)}{\\sum_{i=1}^n P(B/A_i)}$$\r\n$$ \\Rightarrow P(A_i/B) \\propto P(B/A_i)$$\r\n\r\n\\begin{proof}\r\n\r\n    $$ P(A_i/B) = \\frac{P(A_i \\cap B)}{P(B)}$$\r\n    $$ P(A_i/B)= \\frac{P(B/A_i)P(A_i)}{\\sum_{i=1}^{n} P(B/A_i)P(A_i)}$$\r\n\r\n\\end{proof}\r\n\r\n\\subsubsection{Example}\r\nIn answering a question in a multiple choice test, a student knows the answer with probability $p$ and guesses the answer otherwise. If he/she guesses from $m$ choices, the probability of being correct is $\\frac{1}{m}$. Find the conditional probability that the student knew the answer if he/ she answered correctly.\r\n\r\nAns: $A_1=$ knowing the answer. $A_2=$ Guessing the answer.\r\n\r\n$B= $Answer is correct. $A_1 \\subseteq B$\r\n\r\n$P(A_1)= p, P(A_2)= 1-p, P(B/A_1)= 1, P(B/A_2)= \\frac{1}{m}$\r\n\r\n$$ P(A_1/B)= \\frac{P(B/A_1)P(A_1)}{P(B/A_1)P(A_1)+ P(B/A_2)P(A_2)}$$\r\n$$ = \\frac{p}{p + (1-p)\\frac{1}{m}}$$\r\n\r\n\\section{Indepedent Events}\r\n$A \\;\\&\\; B$ are said to be independent. If\r\n$$ P(A \\cap B) = P(A)P(B)$$\r\n\r\nIn terms of conditional probability,\r\n$$ P(B/A)= \\frac{P(A \\cap B)}{P(A)} = \\frac{P(A)P(B)}{P(B)} = P(B)$$\r\n\r\n$$ \\Rightarrow P(B/A) = P(B)$$\r\n\r\nProbability of event $B$ remains same with or without conditioning on $A$. Hence, $B$ is said to be independent of $A$.\r\nKnowledge of occurence of event $A$ does not give any information about $B$.\r\n\r\nIf $A\\; \\&\\; B $ are independent, then\r\n$ A \\;\\&\\; B^c$ are also independent.\r\n\r\n\\begin{proof}\r\n    $$ P(B^c / A)= \\frac{P(B^c \\cap A)}{P(A)}= \\frac{P(A)- P(A \\cap B)}{P(A)}= \\frac{P(A)- P(A)P(B)}{P(A)} = P(B^c)$$\r\n\\end{proof}\r\n\r\n\\subsection{Important Results}\r\n\\begin{enumerate}\r\n    \\item $P(A/B)$ may be greater than, less than or equal to $P(A)$.\r\n    \\item Independent events and mututally exclusive events are different.\r\n\r\n    Indepedence: $P(A \\cap B)= P(A)P(B)$\r\n\r\n    Mututally exclusive: $A \\cap B = \\phi$\r\n\r\n    \\begin{enumerate}\r\n        \\item (Indepedent but not mutually exclusive). Coin toss followed by throwing dice experiment.\r\n\r\n        $$ S=\\{ (H,1), (H,2), \\cdots, (H,6), (T,1), \\cdots, (T,6)\\}$$\r\n        $F=$ Power set of S (Always an event space)\r\n\r\n        $A=\\{(H,1), \\cdots, (H,6) \\}$, $B= \\{ (H,2), (H,4), (H,6), (T,2),(T,4),(T,6)$\r\n\r\n        $P(A)= 1/2 \\; \\& \\; P(B)= 1/2$\r\n        $$ P(A \\cap B)= P(\\{ (H,2), (H,4), (H,6)\\})= \\frac{3}{12}= \\frac{1}{4}$$\r\n        $$ P(A\\cap B)= P(A)P(B)$$\r\n        \\item (Not independent but mutually exclusive)\r\n        If the events are mutually exclusive $\\Rightarrow$ they are not independent.\r\n\r\n        Single Coin Toss: $A= \\{H \\}$, $B= \\{T \\}$ $\\rightarrow$ Mututally exclusive.\r\n\r\n        $P(A \\cap B)= 0$, $P(A)P(B)= \\frac{1}{4}$\r\n\r\n        %Eg 3: (Not independent and not mutually exclusive) hw\r\n\r\n\r\n    \\end{enumerate}\r\n    \\end{enumerate}\r\n\r\n\\subsection{Conditionally indepedent events}\r\n\r\n$A \\; \\& \\: B$ are said to be conditionally indepedent given $C$ if\r\n$$ P((A \\cap B)/ C)= P(A/C)P(B/C)$$\r\nIn terms of conditional probabilities,\r\n$$ P(B/C)= \\frac{P((A\\cap B )/ C)}{P(A/C)}= \\frac{\\frac{P(A \\cap B \\cap C)}{P(C)}}{\\frac{P(A \\cap C)}{P(C)}} = \\frac{P(A\\cap B\\cap C)}{P(A \\cap C)} = P(B/(A \\cap C))$$\r\n\r\nIndepedent Events: $P(A \\cap B)= P(A)P(B)$ \\& $P(B/A)= P(B)$.\r\n\r\nConditionally indepedent events: $P(A\\cap B / C)= P(A/C)P(B/C)$ \\& $P(B/(A\\cap ))$\r\n\r\n\\subsubsection{Example}\r\nTwo fair coins are tossed, $S=\\{HH, HT, TH, TT \\}$, $A=\\{HH, HT \\} $, $B=\\{HH, TH\\} $, $C=\\{HH \\}$ \\& $D=\\{HT, TH\\}$\r\n\r\n\\begin{enumerate}\r\n    \\item Are $A$ \\& $B$ independent?\r\n    $$ P(A \\cap B)= P(\\{HH\\}) = \\frac{1}{4}= P(A)P(B)$$\r\n    \\item  Are $A$ \\& $B$ conditionally indepedent given $C$?\r\n    $$ P((A \\cap B) /C)= P(A/C)=P(B/C)= 1$$\r\n    $$ P(A/C)= \\frac{P(A \\cap C)}{P(C)}= \\frac{\\frac{1}{4}}{\\frac{1}{4}}= 1$$\r\n    \\item Are $A$ \\& $B$ conditionally indepedent given $D$?\r\n\r\n    $$P(A/D)= \\frac{P(A\\cap D)}{P(D)}= \\frac{\\frac{1}{4}}{\\frac{1}{2}}=\\frac{1}{2} $$\r\n    $$P(B/D)= \\frac{P(B\\cap D)}{P(D)}= \\frac{\\frac{1}{4}}{\\frac{1}{2}}=\\frac{1}{2} $$\r\n    $$ P(A\\cap B /D)= 0$$\r\n    Hence, they are not conditionally indepedent given $D$.\r\n\\end{enumerate}\r\n\r\nIf $A$ and $B$ are independent, it doesn't imply $A$ and $B$ will be conditionally indepedent given $C$ and vice-versa.\r\n%4/6 notes\r\n\\subsection{Indepedence of collection of events}\r\n\r\nThree events $A_1, A_2$ \\& $A_3$ are said to be indepedent if:\r\n\r\n$$ P(A_1 \\cap A_2 \\cap A_3)=P(A_1)P(A_2)P(A_3)$$\r\n$$ P(A_1 \\cap A_2)=P(A_1)P(A_2)\\quad P(A_2 \\cap A_3)=P(A_2)P(A_3)\\quad P(A_3 \\cap A_1)=P(A_3)P(A_1)$$\r\n\r\n\r\n\r\n\\subsubsection{Chain rule of Probability}\r\n$$ P(A_1 \\cap A_2 \\cap A_3)=P(A_1)P(A_2/A_1)P(A_3/A_1\\cap A_2)$$\r\n$$ P(\\bigcap_{i=1}^n A_i)=P(A_1) \\prod_{i=2}^n P(A_i/A_1\\cdots A_{i-1})$$\r\nFor independent events $A_1, A_2, A_3$.\r\n$$P(A_1)P(A_2/A_1)P(A_3/(A_1 \\cap A_2))= P(A_1)P(A_2)P(A_3)$$\r\n$$\\Rightarrow P(A_2/A_1)P(A_3/(A_1 \\cap A_2))= P(A_2)P(A_3)$$\r\n\r\nHence, if $A_1$, $A_2$, $A_3$ are independent events, the first condition doesn't imply the other conditions.\r\n\r\nEg: Pair-wise independence does not imply that three events are independent.\r\nConsider example of two coin tosses:\r\n$S= \\{HH,HT,TH,TT\\}, A_1=\\{HH,HT\\},A_2=\\{HH,TH\\},A_3=\\{HT,TH\\}$.\r\n\r\n$A_1$ \\& $A_2$ are indepedent $P(A_1 \\cap A_2)=P(A_1)P(A_2)$\r\n\r\n$A_2$ \\& $A_3$ are indepedent $P(A_3 \\cap A_2)=P(A_3)P(A_2)$\r\n\r\n$A_1$ \\& $A_3$ are indepedent $P(A_1 \\cap A_3)=P(A_1)P(A_3)$\r\n\r\n$A_1$, $A_2$  \\& $A_3$ are not still not independent as $P(A_1 \\cap A_2 \\cap A_3) \\neq P(A_1)P(A_2)P(A_3)$.\r\n\r\n\\section{Continuity of Probability}\r\n$\\Omega$ is an equivalent notation for sample space.\r\n\r\nConsider the probability space $(S,F,P)$.\r\n\r\n$E_i \\in F$. Let $E_1 \\subseteq E_2 \\subseteq \\cdots$ be countably infinite sequence of events (increasing sequence of events).\r\nThen $$P(\\bigcup_{i=1}^{\\infty} E_i)= \\lim_{i \\to \\infty} P(E_i)$$.\r\n$$ \\bigcup_{i=1}^{\\infty} E_i \\in F$$\r\nPushing the limit from inside the probability expression to outside.\r\n\r\n$$P(\\bigcup_{i=1}^{\\infty} E_i)=\\lim_{i \\to \\infty }P(E_i)$$\r\n$$P(\\lim_{n \\to \\infty} \\bigcup_{i=1}^{n}E_i)=\\lim_{i \\to \\infty }P(E_i)$$\r\n\r\nExchanging limits with probability $\\rightarrow$ non trivial operation.\r\nExchanging limits with differentiation, integration etc. $\\rightarrow$ require a proof.\r\n\r\n\\begin{itemize}\r\n    \\item $$E_1 \\subseteq E_2 \\subseteq \\cdots$$\r\n    $$P(\\bigcup_{i=1}^{\\infty} E_i)= \\lim_{i \\to \\infty} P(E_i)$$\r\n\r\n    \\begin{proof}\r\n        We shall use the third axiom.\r\n        $D_1, D_2 \\cdots \\rightarrow$ mutually exclusive events.\r\n\r\n        $$ P(\\bigcup_{i=1}^{\\infty} D_i)= \\sum_{i=1}^{\\infty}P(D_i)$$\r\n\r\n        $E_1 \\subseteq E_2 \\subseteq \\rightarrow $ not mutually exclusive.\r\n\r\n        Hence we construct a sequence which are mututally exclusive and unions of both sequences have to be the same.\r\n\r\n        $A_1=E_1$, $A_2=E_2\\setminus E_1$, $ A_3=E_3 \\setminus E_2$ , $\\cdots$.\r\n        $$ P(\\bigcup_{i=1}^{\\infty} E_i)= P(\\bigcup_{i=1}^{\\infty} A_i)= \\sum_{i=1}^{\\infty}P(A_i)= \\lim_{n \\to \\infty} \\sum_{i=1}^{\\infty}P(A_i)$$\r\n\r\n        $$\\Rightarrow \\lim_{n \\to \\infty} \\sum_{i=1}^{n} P(A_i)= \\lim_{n \\to \\infty} P(\\bigcup_{i=1}^{n}A_i)= \\lim_{n \\to \\infty}P(E_n)$$\r\n        If there exists a subsequence of events, which is increasing.\r\n\r\n    \\end{proof}\r\n\r\n    \\item Let $E_1 \\supseteq E_2 \\supseteq \\cdots$ be a countably infinte sequence of events(decreasing sequence of events)\r\n\r\n    $$P(\\bigcap_{i=1}^{\\infty}E_i)=\\lim_{i \\to \\infty} P(E_i)$$\r\n\r\n    \\begin{proof}\r\n        We can use the result of the previous proof.\r\n        $$ E_1^c \\subseteq E_2^c \\subseteq \\cdots$$\r\n        which is an increasing set of events\r\n        $$P(\\bigcup_{i=1}^{\\infty} E_i^c)= \\lim_{i \\to \\infty}P(E_i^c)$$\r\n        as,\r\n        $$ \\left(\\bigcap_{i=1}^{\\infty} E_i \\right)= \\left( \\bigcup_{i=1}^{\\infty} E_i^c \\right)^c $$\r\n\r\n        $$\\Rightarrow 1- P(\\bigcup_{i=1}^{\\infty} E_i^c)= \\lim_{i \\to \\infty}1- P(E_i^c)$$\r\n\r\n        $$P \\left(\\bigcap_{i=1}^{\\infty} E_i \\right) = \\lim_{i \\to \\infty }P(E_i)$$\r\n\r\n    \\end{proof}\r\n\r\n\\end{itemize}\r\n\r\n%4/6  \\subsection{Example of continuity of probability}\r\n\r\n%7/6 lecture 6\r\n\r\n\\section{Random Variables}\r\n\r\nConsider a probability space $(S,F,P)$ and an experiment is conducted.\r\n\r\nProbability spaces vary a lot based on the experiment. We use random variables to be able to develop a theory of probability which is indepedent of the actual experiment which is performed.\r\n\r\n$$S \\xrightarrow[]{\\text{R.V.}} \\mathbb{R}$$\r\n$$F \\xrightarrow[]{\\text{R.V.}} B$$\r\n\r\nRandom Variable is a function which maps the sample space to the real line.\r\nIt also maps the event space to the Borel $\\sigma$-algebra, $B$.\r\n\r\n\\subsection{Borel $\\sigma$-algebra}\r\nIt is the smallest $\\sigma$- algebra which contains sets of the form $(-\\infty ,x]\\; \\forall x \\in \\; \\mathbb{R}$.\r\n\r\n$$ B=\\{ \\mathbb{R} , (-\\infty ,x] ,(x,\\infty ), \\phi, (-\\infty,x) ,(x,y),[x,y], \\{x\\},(x,y],[x,y)\\}$$\r\n\r\n$$ E_i =(-\\infty ,x_i] \\quad x_i = x-\\frac{1}{i}$$\r\n$$ \\bigcup_{i=1}^{\\infty}(-\\infty ,x_i] = \\bigcup_{i=1}^{\\infty} E_i =(-\\infty ,x)$$\r\n\r\n\r\nRandom Variable $X:S \\rightarrow R$\r\n\r\n$X$ has to be a measurable function.\r\n\r\nA function is said to be measurable if  pre-image of $(-\\infty ,x ] \\; \\forall x \\in \\mathbb{R}$ is in the event space.\r\n$$X:S \\rightarrow R$$\r\n$$\\text{inverse image} \\leftarrow(-\\infty ,x ] $$\r\n$$ X^{-1} ((-\\infty ,x ]) \\subseteq S \\qquad  X^{-1} ((-\\infty ,x ]) \\in F$$\r\neg:\r\n$ X: \\{1,2,3,4,5,6\\} \\rightarrow \\{0,1,0,1,0,1 \\}$\r\n\r\n$$X^-1\\left( (-\\infty, 0.5]\\right)=\\{1,3,5\\}$$\r\n\r\nIn the above example, $X$ is not an invertible mapping. We are using $X^{-1}$ as a notation.\r\n\r\n$X$ is a map from $S$ to $\\mathbb{R}$ such that\r\n$$X:S \\rightarrow \\mathbb{R}$$\r\n$$ X^{-1}\\left( (-\\infty, x ]\\right) \\leftarrow (-\\infty, x ] \\qquad X^{-1}\\left( (-\\infty, x ]\\right) \\in F $$\r\n\r\n\\subsection{Examples}\r\n\\begin{itemize}\r\n    \\item X which is a random variable.\r\n\r\n    $S= \\{a,b,c\\}\\; ,\\; F=\\{ \\phi, \\{ a\\}, \\{b,c \\}, S\\}\\; , \\; X:S \\rightarrow \\mathbb{R}$\r\n\r\n    $X(\\omega) =0\\; ,\\; \\omega =a $\r\n\r\n    $X(\\omega)= 1\\;,\\; \\omega = b,c$\r\n    \\begin{enumerate}\r\n        \\item $( -\\infty,x]\\;,\\; x < 0\\;,\\; X^{-1}\\left( (-\\infty , x]\\right) = \\phi \\in F$\r\n        \\item $( -\\infty,x]\\;,\\; 0 \\leq x <1 \\;,\\; X^{-1}\\left( (-\\infty , x]\\right) = \\phi \\in F$\r\n        \\item $( -\\infty,x]\\;,\\; x \\geq 1\\;,\\; X^{-1}\\left( (-\\infty , x]\\right) = S \\in F$\r\n    \\end{enumerate}\r\n\r\n    \\item X which is not a random variable\r\n    $S= \\{a,b,c\\}\\; ,\\; F=\\{ \\phi, \\{ a\\}, \\{b,c \\}, S\\}\\; , \\; X:S \\rightarrow \\mathbb{R}$\r\n\r\n    $X(\\omega) =0\\; ,\\; \\omega =b $\r\n\r\n    $X(\\omega)= 1\\;,\\; \\omega = a,c$\r\n\r\n    But $X^{-1}((-\\infty,x])\\; , \\;0\\leq x<1 = \\{b\\} \\; , \\; \\{ b\\} \\notin F$\r\n\r\n    $X$ is not a random variable.\r\n\\end{itemize}\r\n\r\nIf $S$ is finite \\& $F$ is a power set of $S$, then every function is a random variable.\r\n$$ X^{-1}((-\\infty,x]) \\subseteq S$$\r\n\r\n$F$ is set of all subsets of $S$.\r\n\r\n%9/6\r\n\\subsection{Conditions on random variable}\r\n\\begin{theorem}\r\n    Let a probability space be $(S,F,P)$ and $X$ is a random variable $X: S \\rightarrow \\mathbb{R}$.\r\n    The following conditions hold:\r\n    \\begin{itemize}\r\n        \\item $X^{-1}((-\\infty,x)) \\in F$\r\n        \\item $X^{-1} (\\{x\\}) \\in F$\r\n        \\item $X^{-1}((x_1 , x_2]) \\in F$\r\n        \\item $X^{-1} ((x_1,x_2)) \\in F$\r\n    \\end{itemize}\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\n\r\n    Applying the axioms of the event space we want to show the above conditions are true.\r\n\r\n    $A_i=X^{-1}((-\\infty,x]) \\qquad x_i = x - \\frac{1}{i}$. Now,\r\n    $$ \\bigcup_{i=1}^{\\infty} (-\\infty,x_i] = (-\\infty,x)$$\r\n\r\n    $$ \\bigcup_{i=1}^{\\infty} A_i = \\bigcup_{i=1}^{\\infty} X^{-1}((-\\infty,x_i]) = X^{-1}((-\\infty,x)) \\in F$$\r\n\r\n    $$ X^{-1}((-\\infty ,x] \\cap {(-\\infty,x)}^c) = X^{-1} (\\{x\\}) \\in F$$\r\n\r\n    Similarly the other conditions can also be proved.\r\n\\end{proof}\r\n\r\n\\section{Cumulative distribution function}\r\nIt is denoted by $F_X(x)$.\r\n\r\n$$ F_X(x)= P(X \\leq x) = P((-\\infty, x])= P(X^{-1}((-\\infty, x]))$$\r\n\r\nThe above definitions are different notations used, the last one is well defined from the probability space.\r\n\r\n\\subsection{Properties of CDF}\r\n\r\n\\begin{enumerate}\r\n    \\item $F_X(x)$ is a monotonically non-decreasing function of x.\r\n    \\begin{proof}\r\n        If $x_2 \\geq x_1$, then $F_X(x_2) \\geq F_X(x_1)$.\r\n\r\n        $$F_X(x_2) = P(X \\leq x_2)= P(X \\leq x_1)+P(x_1 < X \\leq x_2)$$\r\n        $$F_X(x_2) = P(X \\leq x_2) \\geq P(X \\leq x_1) -F_X(x_1) $$\r\n\r\n    \\end{proof}\r\n\r\n    \\item $\\lim_{x \\to \\infty} F_X(x)= 1$\r\n\r\n    \\begin{proof}\r\n        Construct a decreasing set of events. $A_i= (-\\infty, i]$, $B_i = X^{-1}(A_i)$.\r\n        $$ \\bigcap_{i=1}^{\\infty}A_i= \\mathbb{R}$$\r\n        $$ \\bigcap_{i=1}^{\\infty}B_i= S $$\r\n\r\n        Applying continuity of probability,\r\n        $$ \\lim_{i \\to \\infty}P(B_i)= P(\\bigcup_{i=1}^{\\infty}B_i) =P(S) = 0$$\r\n        $$ \\lim_{i \\to \\infty}P(X \\leq i)= \\lim_{x \\to \\infty}P(X \\leq x) = \\lim_{x \\to \\infty} F_X(x)$$\r\n\r\n        The change from integers to real numbers $x$ in the last step is valid.\r\n\r\n    \\end{proof}\r\n    \\item $\\lim_{x \\to -\\infty} F_X(x)= 0$\r\n    \\begin{proof}\r\n        Construct a decreasing set of events. $A_i= (-\\infty, -i]$, $B_i = X^{-1}(A_i)$.\r\n       $$ B_1 \\supseteq B_2 \\supseteq \\cdots$$\r\n\r\n       $$ \\bigcap_{i=1}^{\\infty}B_i= \\phi $$\r\n       $$ P(\\bigcap_{i=1}^{\\infty}B_i) = \\lim_{i \\to \\infty}P(B_i)= 0$$\r\n       $$  \\lim_{i \\to \\infty}P(B_i) =  \\lim_{i \\to \\infty}P((-\\infty,i])= \\lim_{x \\to \\infty}P((-\\infty,x]) \\rightarrow \\text{(x = all real nos.)}$$\r\n       $$ \\lim_{x \\to \\infty}P((-\\infty,x]) = \\lim_{x \\to \\infty}F_X(x)= 0$$\r\n    \\end{proof}\r\n%11/6\r\n    \\item $F_X(x)$ is a right continuous function.\r\n    $$ \\lim_{x \\to x_0^+} F_X(x)= F_X(x_0)$$\r\n\r\n    Right continuous function: $\\lim_{x \\to x_0^+} f(x)= f(x_0)$\r\n\r\n    Left continuous function: $\\lim_{x \\to x_0^-} f(x)= f(x_0)$\r\n\r\n    Continuous function(Approaching from either left or right): $\\lim_{x \\to x_0} f(x)= f(x_0)$\r\n\r\n    \\begin{proof}\r\n        Decreasing sequence of events $B_i= (X \\leq x+\\frac{1}{i})$\r\n\r\n        $$ B_1 \\supseteq B_2 \\supseteq \\cdots$$\r\n        $$ \\bigcap_{i=1}^{\\infty}B_i= \\{ X \\leq x\\}$$\r\n        $$ P(\\bigcap_{i=1}^{\\infty}B_i) = P(X \\leq x) = F_X(x)$$\r\n        $$ \\Rightarrow \\lim_{i \\to \\infty}P(B_i)= \\lim_{i \\to \\infty}P(X \\leq x + \\frac{1}{i})$$\r\n        We are changing the variable from an integer to real.\r\n        $$= \\lim_{\\epsilon \\to 0}P(X \\leq x + \\epsilon)=\\lim_{\\epsilon \\to 0^+}F_X(x + \\epsilon) $$\r\n        $$ = \\lim_{x_0 \\to x^+}F_X(x_0) \\quad \\text{Change of variable: }x_0= x+ \\epsilon $$\r\n\r\n    \\end{proof}\r\n\\end{enumerate}\r\n\r\n\\subsection{Indicator Random Variable}\r\n\\begin{equation*}\r\n    I_A (x)=\r\n    \\begin{cases}\r\n      1, & \\text{if}\\ x \\in A \\\\\r\n      0, & \\text{if}\\ x \\notin A\r\n    \\end{cases}\r\n\\end{equation*}\r\n\r\n$$I_A:S \\to \\mathbb{R}$$\r\n\r\n$$ F_{I_{A}} (x)= P(I_A \\leq x)$$\r\n\r\nIf $x < 0 $, $P(I_A \\leq x)= 0$.\r\n\r\nIf $0 \\leq x <1 $, $P(I_A \\leq x)= P(A^c)=1-P(A)$.\r\n\r\nIf $x \\geq 1 $, $P(I_A \\leq x)= 1$.\r\n\r\n$$ \\lim_{x \\to 0^+} F_{I_A}(x)= P(A^c) \\qquad F_{I_A}(0)= P(A^c)$$\r\n\r\n$$ \\lim_{x \\to 1^+} F_{I_A}(x)= 1 \\qquad F_{I_A}(1)= 1$$\r\n\r\n\\subsection{Examples of CDF's and non-CDF's}\r\n\\begin{itemize}\r\n    \\item Is $F_1(x)$ a valid CDF?\r\n    \\begin{equation*}\r\n        F_1 (x)=\r\n        \\begin{cases}\r\n          1, & \\text{if}\\ x \\leq 0 \\\\\r\n          0.5, & \\text{if}\\ 0<x\\leq 1 \\\\\r\n          0.25+0.25x, & \\text{if}\\ 1<x\\leq 3 \\\\\r\n          1, & \\text{if}\\ 3<x\r\n        \\end{cases}\r\n    \\end{equation*}\r\n\r\n    No, as it is not right continuous at $x=0$.\r\n\r\n    $$ \\lim_{x=0^+}F_1(x)=0.5, \\quad F_1(0)=0$$\r\n\r\n    \\item Is $F_2(x)$ a valid CDF?\r\n    \\begin{equation*}\r\n        F_2 (x)=\r\n        \\begin{cases}\r\n          0, & \\text{if}\\ x < 0 \\\\\r\n          0.5, & \\text{if}\\ 0\\leq x < 1 \\\\\r\n          0.75, & \\text{if}\\ 1\\leq x < 3 \\\\\r\n          1, & \\text{if}\\ 3\\leq x\r\n        \\end{cases}\r\n    \\end{equation*}\r\n    It is valid as it satisfies all 4 properties.\r\n\r\n    \\item Is $F_3(x)$ a valid CDF?\r\n    \\begin{equation*}\r\n        F_3 (x)=\r\n        \\begin{cases}\r\n          1, & \\text{if}\\ x < 0 \\\\\r\n          0.5, & \\text{if}\\ 0 \\leq x < 1 \\\\\r\n          0.25, & \\text{if}\\ 1\\leq x < 3 \\\\\r\n          1, & \\text{if}\\ 3 \\leq x\r\n        \\end{cases}\r\n    \\end{equation*}\r\n    $F_3(x)$ is not a valid CDF as it is not non-decreasing.\r\n\r\n\\end{itemize}\r\n\r\n%14/6\r\n\\begin{lemma}\r\n    For any $x \\in \\mathbb{R}$,\r\n    $$ P(X=x)= P(X \\leq x)- P(X <x)$$\r\n    $$ P(X=x)= F_X(x)- \\lim_{\\epsilon \\to 0}F_X(x- \\epsilon)$$\r\n\r\n\\end{lemma}\r\n\r\nUpon applying continuity of probability.\r\n\r\n\\begin{proof}\r\n    $$ B_1 \\subseteq B_2 \\subseteq \\cdots$$\r\n    $$B_i=\\{ X \\leq x - \\frac{1}{i}\\} \\qquad \\bigcup_{i=1}^{\\infty}B_i=\\{ X<x\\}$$\r\n\r\n    $$ P(X<x)= P(\\bigcup_{i=1}^{\\infty}B_i)= \\lim_{i \\to \\infty} B_i = \\lim_{\\epsilon \\to \\infty}P(X \\leq x- \\epsilon)= \\lim_{\\epsilon \\to 0}F_X(x-\\epsilon)$$\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $F_X(.)$ is left continuous if and only if $P(X=x)=0 \\; \\forall \\; x \\in \\mathbb{R} $. From lemma,\r\n\r\n    $$ P(X=x)= F_X(x)- \\lim_{\\epsilon \\to 0^+ }F_X(x-\\epsilon)$$\r\n\r\n\\end{corollary}\r\n\r\nA function is left continuous if\r\n\r\n$$  \\lim_{\\epsilon \\to 0^+}F_X(x - \\epsilon)= F_X(x) \\quad \\forall x \\in \\mathbb{R}$$\r\n$$ \\Rightarrow P(X=x)= 0 \\quad \\forall x \\in \\mathbb{R}$$\r\n\r\n$F_X(.)$ is continuous, means that it is both right continuous, and in particular, left continuous.\r\n\r\n\\section{Types of Random Variables}\r\n\\begin{itemize}\r\n    \\item Continuous random variable\r\n    \\item Discrete random variable\r\n    \\item Mixed random variable\r\n\\end{itemize}\r\n\r\n\\subsection{Continuous random variables}\r\nA random variable $X$ with cummulative distribution function $F_X(.)$ is said to be a continuous random variable if $F_X(.)$ is continuous.\r\n\r\n$P(X=x)=0 \\quad \\forall \\; x \\in \\mathbb{R}$, probability of every point is zero.\r\n\r\nAn example for a continuous random variable is:\r\n\\begin{equation*}\r\n    F_X (x)=\r\n    \\begin{cases}\r\n      0, & \\text{if}\\ x < 0 \\\\\r\n      x, & \\text{if}\\ 0 \\leq x < 1 \\\\\r\n      1, & \\text{if}\\ x\\leq 1  \\\\\r\n    \\end{cases}\r\n\\end{equation*}\r\n\r\nIn the context of a continuous random variable, we need to ask what is the probability of intervals or unions of intervals: $ P(a \\leq X \\leq b)$\r\n\r\nIf $F_X(.)$ is differentiable, given that it is continuous then we can find another function for the continuous random variable.\r\n\r\n$$ f_X(x)= \\frac{dF_X(x)}{dx}$$\r\n\r\n$f_X(x)$ is called the probability density function (pdf).\r\n\\begin{equation*}\r\n    f_X (x)=\r\n    \\begin{cases}\r\n      1, & \\text{if}\\ 0 < x < 1 \\\\\r\n      0, & \\text{otherwise}\\\r\n    \\end{cases}\r\n\\end{equation*}\r\n\r\n$$ F_X(a)= P(X \\leq a)= \\int_{-\\infty}^{a}f_X(x)dx$$\r\n\r\n$$  P(a \\leq X \\leq b)=F_X(b)-F_X(a) = \\int_{a}^{b}f_X(x)dx$$\r\n\r\n$$ P(x \\leq X \\leq x + \\Delta x) \\to \\Delta x\\text{ is very small(infintesimal)}$$\r\n$$ P(x \\leq X \\leq x + \\Delta x) \\approx \\text{area of rectangle with b=} \\Delta x \\;\\& \\text{ h= }f_X(x)$$\r\n$$ P(x \\leq X \\leq x + \\Delta x) \\approx f_X(x) \\Delta x$$\r\n\r\n\\subsubsection{Probability density function}\r\nWhen is a function a valid probability density function?\r\n\r\nTwo properties of the probability density function are:\r\n\\begin{itemize}\r\n    \\item $f_X(x) \\geq 0$\r\n\r\n    As CDF is monotonically non decreasing, it's derivative is always non-negative.\r\n    \\item $ \\int_{-\\infty}^{\\infty}f_X(x)dx= 1 \\to \\quad P(X \\leq \\infty )= F_X(\\infty)=1$\r\n\\end{itemize}\r\n\r\nNote: $f_X(.) \\nleq 1$\r\n\r\nThe probability density function itself doesn't indicate any probability.\r\nOnly the area under the curve indicates probability.\r\n\r\n\\subsection{Discrete random variable}\r\n\r\n$X$ is said to be a discrete random variable if the range of $X$ is either finite or countably infinite in $\\mathbb{R}$.\r\n$$ X:S \\to \\mathbb{R}$$\r\n\r\nCDF of a discrete random variable will be constant everywhere and jumps at some points(finite or countably infinite number of points).\r\n\r\nRange of $X={x_1,x_2,\\cdots}$\r\n\r\nDiscrete random variables can take non-zero values unlike the continuous r.v's.\r\n\r\n$$ F_X(a)= \\sum_{x_i \\leq a}P(X= x_i)$$\r\n\r\n$$ P(X=x_i)= P_X(x_i)\\qquad x_i \\text{ is in the range of X.}$$\r\n$P_X$ is said to be the probability mass function.\r\n\r\n\\subsubsection{Probability mass function}\r\nWhen is a function a valid probability mass function?\r\n$$ S= \\text{ Range of X }= \\{ x_1, x_2, \\cdots\\}$$\r\nTwo properties of the probability mass function are:\r\n\\begin{itemize}\r\n    \\item $P_X(x_i) \\geq 0$\r\n\r\n    \\item $ \\sum_{x_i \\in S}P_X(x_i)=1$\r\n\\end{itemize}\r\n%17/6\r\n\r\n\\subsection{Mixed random variable}\r\n\r\n$F_X(.)$ is continuous in some intervals and also jumps at some points. The probability density function has some impulses included in it. Let, $X_1$ be a continuous random variable, $X_2$ be a discrete random variable, then $Y$, a linear combination, is a mixed variable.\r\n$$ Y= \\alpha X_1 +\\beta X_2$$\r\n\r\n\\subsection{Functions of random variables}\r\n$X$ is a random variable. $X: S \\to \\mathbb{R}$.\r\n\r\n$$ Y=g(X) \\qquad g:\\mathbb{R} \\to \\mathbb{R} \\qquad Y= goX:S\\to \\mathbb{R}$$\r\n\r\nWe require a condition on $g$ to find out when $Y$ is a random variable.\r\n$$ Y^{-1}((-\\infty ,y]) \\in F \\Rightarrow X^{-1} \\left( g^{-1} ((-\\infty,y])\\right) \\in F$$\r\nLet $\\mathfrak{B}$ be an arbitrary set in the Borel $\\sigma$-algebra generated by intervals of the form $(-\\infty,x] = \\mathfrak{B}$.\r\n\r\nThen, since $X$ is a random variable, $X^{-1}(\\mathfrak{B}) \\in F$.\r\n\r\n$ g^{-1} ((-\\infty,y]) \\in \\mathfrak{B}$, (Borel $\\sigma$-algebra generated by intervals of the form $(-\\infty,x] $).\r\n$$X^{-1} \\left( g^{-1} ((-\\infty,y])\\right) \\in F \\Rightarrow \\text{Y is a random variable} $$\r\n\r\nAny common functions satisfy the condition needed for $g$.\r\n\r\n\\begin{itemize}\r\n    \\item\r\n    Suppose $X$ is a discrete random variable, $X: S \\to \\mathbb{R}$, range of $X$ is discrete.\r\n\r\n    $g$ is a function, such that $Y=g(X)$. Then $Y$ is a discrete random variable.\r\n\r\n    $X$ has a probability mass function $P_X$, $Y \\to P_Y$. Then,\r\n    \\begin{align*}\r\n        P_Y(y)&= P(Y=y)= P(g(X)=y) \\\\\r\n        &= P(\\{ x_i | g(x_i)=y\\}) \\\\\r\n        &= \\sum_{x_i : g(x_i)=y} P_X(x_i)\r\n    \\end{align*}\r\n\r\n    Eg: Tossing a coin till first head.\r\n\r\n    $$ S= \\{ H,TH,TTH, \\cdots\\}$$\r\n\r\n    $$X:S \\to \\mathbb{R}\\qquad H \\to 1 \\qquad TH \\to 2 \\qquad TTH \\to 3 \\cdots$$\r\n\r\n    $Y=g(X)= X \\text{ mod } 4 \\Rightarrow \\text{Range of Y}= \\{ 0,1,2,3\\}$\r\n\r\n    $$P_Y(0)= P(Y=0)= P(X \\text{ mod } 4 =0)= P(\\{ 4,8,\\cdots\\})= \\sum_{x \\text{ mod } 4=0}P_X(x)$$\r\n\r\n    \\item $X$ is a continuous random variable, $Y= g(X)$.\r\n\r\n    Based on $g$, it can either be continuous or discrete.\r\n\r\n    \\begin{enumerate}\r\n        \\item When $X$ is continuous \\& $Y$ is also continuous.\r\n\r\n        Let $F_X(.)$ be the CDF of $X$ and $f_X(.)$ be the PDF of $Y$.\r\n        $$ Y= aX+b \\qquad a,b \\in \\mathbb{R}$$\r\n        For the CDF's:\r\n            $$F_Y(y)= P(Y \\leq y) $$\r\n\r\n        $$ \\{ Y \\leq y\\}= \\{ aX+b \\leq Y\\}$$\r\n        \\begin{enumerate}\r\n            \\item If $a>0$,\r\n            $$ \\{ Y \\leq y\\}  = \\{ X \\leq \\frac{y-b}{a}\\}$$\r\n            $$ F_Y(y)= P(Y \\leq y)= P\\left( X \\leq \\frac{y-b}{a}\\right)= F_X\\left( \\frac{y-b}{a}\\right)$$\r\n            \\item If $a<0$,\r\n            $$ \\{ Y \\leq y\\}  = \\{ X \\geq \\frac{y-b}{a}\\}$$\r\n            $$ F_Y(y)= P(Y \\leq y)= P\\left( X \\geq \\frac{y-b}{a}\\right)= 1-F_X\\left( \\frac{y-b}{a}\\right)$$\r\n        \\end{enumerate}\r\n\r\n        For the PDF's:\r\n        \\begin{enumerate}\r\n            \\item If $a>0$\r\n\r\n            $$ F_Y(y)= F_X\\left( \\frac{y-b}{a}\\right)$$\r\n            \\begin{align*}\r\n                f_Y(y)= \\frac{dF_Y(y)}{dy} &= \\frac{d}{dy}F_X\\left( \\frac{y-b}{a} \\right)\\\\\r\n                &= f_X \\left( \\frac{y-b}{a} \\right)\\frac{d}{dy}\\left(\\frac{y-b}{a} \\right) \\\\\r\n                &= \\frac{1}{a}f_X\\left(\\frac{y-b}{a} \\right)\r\n            \\end{align*}\r\n\r\n            \\item If $a>0$\r\n\r\n            $$ F_Y(y)= 1- F_X\\left( \\frac{y-b}{a} \\right)$$\r\n            \\begin{align*}\r\n                f_Y(y)= \\frac{-1}{a}f_X\\left(\\frac{y-b}{a} \\right)\r\n            \\end{align*}\r\n\r\n\r\n        \\end{enumerate}\r\n\r\n        Hence,\r\n        \\fbox{$ f_Y(y)= \\frac{1}{|a|}f_X \\left(\\frac{y-b}{a} \\right)$}\r\n%18/6\r\n        \\item $X$ is continuous and $Y$ is continuous, but a many to one function.\r\n        $$ Y= X^2$$\r\n        Now let us find the CDF \\& PDF of $Y$ in therms of CDF \\& PDF of $X$.\r\n        \\begin{enumerate}\r\n            \\item $y<0$, $F_Y(y)=0$\r\n            \\item $y \\geq 0$,\r\n            \\begin{align*}\r\n                F_Y(y)= &= P(Y \\leq y) \\\\\r\n                    &= P(X^2 \\leq y) = P(-\\sqrt{y} \\leq x \\leq \\sqrt{y}) \\\\\r\n                    &= F_X(\\sqrt{y})- F_X(-\\sqrt{y}) + P(x= -\\sqrt{y}) \\\\\r\n                    &= F_X(\\sqrt{y})- F_X(-\\sqrt{y})\r\n            \\end{align*}\r\n        \\end{enumerate}\r\n\r\n        $$ f_Y(y)= \\frac{dF_Y(y)}{dy}= \\frac{d}{dy}(F_X(\\sqrt{y})- F_X(-\\sqrt{y}))$$\r\n        $$ = \\frac{1}{2\\sqrt{y}}[f_X(\\sqrt{y})- f_X(-\\sqrt{y})]$$\r\n        \\item $X$ is continuous, $Y$ is continuous and a many to one function.\r\n        \\begin{equation*}\r\n            f_X (x)=\r\n            \\begin{cases}\r\n              \\frac{1}{2\\pi}, & \\text{if}\\ 0 \\leq x \\leq 2\\pi \\\\\r\n              0, & \\text{otherwise}\\\r\n            \\end{cases}\r\n        \\end{equation*}\r\n        $$ F_X(x)= \\int_{-\\infty}^{x} f_x(x)dx$$\r\n        $$ Y=\\sin X$$\r\n        Let us find the PDF of $Y$.\r\n\r\n        \\begin{enumerate}\r\n            \\item Consider $0 \\leq y \\leq 1$\r\n            \\begin{align*}\r\n                F_Y(y)&= P(Y \\leq y) \\\\\r\n                    &= P(\\sin{X} \\leq Y) \\\\\r\n                    &= P(\\{ 0 \\leq X \\leq \\sin^{-1} y\\} \\cup \\{ \\pi - \\sin^{-1}y \\leq X \\leq 2\\pi \\})\\\\\r\n                    &=P( 0 \\leq X \\leq \\sin^{-1}y)+(\\pi - \\sin^{-1}y \\leq X \\leq 2 \\pi )\\\\\r\n                    &= F_X(\\sin^{-1}y)- F_X(0)+F_X(2\\pi)- F_X(\\pi - \\sin^{-1}y)\\\\\r\n                    &= \\frac{\\sin^{-1}y}{2\\pi}-0+1- \\left( \\frac{\\pi - \\sin^{-1}y}{2\\pi}\\right) \\\\\r\n                    &= \\frac{1}{2}+ \\frac{\\sin^{-1}y}{\\pi}\r\n            \\end{align*}\r\n            \\item $-1 \\leq y <0$\r\n            \\begin{align*}\r\n                F_y(y)&= P(Y \\leq y) = P(\\sin X \\leq y)\\\\\r\n                &= P(\\pi - \\sin^{-1}y \\leq X \\leq 2\\pi + \\sin^{-1}y )\r\n            \\end{align*}\r\n        \\end{enumerate}\r\n\r\n    %    \\begin{equation*}\r\n    %        f_Y (y)=\r\n    %        \\begin{cases}\r\n    %         \\frac{1}{\\pi \\sqrt{1-y^2}}, & \\text{if}\\ -1 \\leq y < 1 \\\\\r\n    %         \\frac{1}{\\pi \\sqrt{1-y^2}}, & \\text{if}\\ 0 \\leq y \\leq 1\r\n    %\r\n    %        \\end{cases}\r\n    %    \\end{equation*}\r\n\r\n    \\item $X$ is continuous and $Y$ is discrete.\r\n\r\n    $X$ has CDF $F_X(.)$ \\& PDF $f_X(.)$\r\n\r\n    $Y$ has CDF $F_Y(.)$ \\& PMF $P_Y(.)$\r\n\r\n    $$Y=g(x)=k \\; if \\; k \\leq x < k+1 \\qquad k \\in \\mathbb{Z} $$\r\n    The above operation is also called quantization. Range of $g$ is countably infinite \\& thus $Y$ is a discrete random variable.\r\n\r\n    We would like to experss the PMF of $Y$ in terms of the PDF of $X$.\r\n\r\n\r\n    \\begin{align*}\r\n        P_Y(y)&= P(Y=y)= P(y \\leq X < y+1) \\\\\r\n        &= \\int_{y}^{y+1}f_X(x)dx\r\n    \\end{align*}\r\n\r\n    In general,\r\n    $$ P_Y(y)= \\int f_X(x)dx \\qquad S= \\{ x: g(x)=y\\}$$\r\n\r\n    \\end{enumerate}\r\n\\end{itemize}\r\n\r\n    \\subsection{General formula for determining PDF of $Y= g(X)$}\r\n    Where $g$ is differentiable,\r\n\r\n    $$ P(y \\leq Y \\leq y + \\Delta y) \\approx f_Y(y)\\Delta y$$\r\n    The left hand side can be written in terms of PDF of $X$.\r\n    $$ g(x_i)= y$$\r\n    $$ g^{-1}[y,y + \\Delta y]= [x_1, x_1+ \\Delta x_1]\\cup [x_2, x_2+ \\Delta x_2] \\cdots [x_n, x_n+ \\Delta x_n]$$\r\nWhat is the sign of slope of $g(x)$ at $x_i$?\r\n\\begin{itemize}\r\n    \\item If $g^{'} (x_i) \\geq 0 \\qquad [x_i,x_i+ \\delta x_i]$\r\n    \\item If $g^{'} (x_i) < 0 \\qquad [x_i- \\delta x_i,x_i]$\r\n\\end{itemize}\r\n\r\n\\begin{align*}\r\n    f_Y(y)\\Delta y &= \\sum_{i=1}^{n}P(x_i \\leq X \\leq x_i + \\Delta x_i)\\\\\r\n                    &= \\sum_{i=1}^{n} f_x(x_i)\\Delta x_i\r\n\\end{align*}\r\n$$ f_Y(y)= \\sum_{i=1}^{n} f_X(x_i)\\frac{\\Delta x_i}{\\Delta y}= \\sum_{i=1}^{n} f_X(x_i)\\frac{1}{(\\Delta y / \\Delta x_i)}$$\r\n\r\nFor infintesimally small $\\Delta y$ \\& corresponding $\\Delta x_i$:\r\n$$ \\frac{\\Delta y}{\\Delta x_i}= |g^{'}(x_i)|$$\r\n\r\nWe take modulus as LHS is positive, i.e. magnitude of the slope of tangent at $x_i$.\r\n\r\n$$ f_Y(y) = \\sum_{i=1}^{n} \\frac{f_X(x_i)}{|g^{'}(x_i)|}$$\r\n\r\nExamples:\r\n\\begin{itemize}\r\n    \\item $Y= X^2$\r\n    $$ f_Y(y)= \\frac{f_X(\\sqrt{y})}{2\\sqrt{y}}+ \\frac{f_X(-\\sqrt{y})}{2\\sqrt{y}}$$\r\n    \\item $Y= \\sin X$, we take $\\sin^{-1} y(2n\\pi + \\sin^{-1} y)$ \\& $\\pi - \\sin^{-1} y(2n\\pi + \\pi - \\sin^{-1} y)$\r\n\r\n    $$ f_Y(y)= \\sum_{n}\\left[ \\frac{f_X(2n\\pi + \\sin^{-1} y)}{\\sqrt{1- y^2}} + \\frac{f_X(2n\\pi + \\pi - \\sin^{-1} y)}{\\sqrt{1- y^2}} \\right]$$\r\n\\end{itemize}\r\n\r\n%21/6\r\n\r\n\\begin{theorem}\r\n    If $Y= F_X(X)$, where $X$ itself is a random variable with CDF $F_X(.)$, the CDF of Y:\r\n    $$ F_Y(y)= P(Y \\leq y)= P(F_X(x) \\leq y)$$\r\n\\end{theorem}\r\n    \\begin{itemize}\r\n        \\item If $y<0$,\r\n        $$ \\{ X \\leq F_{X}^{-1}((-\\infty,y])\\}= \\phi \\qquad P(F_{X}(x)\\leq y)=0 $$\r\n        \\item If $y \\geq 1$,\r\n        \\begin{align*}\r\n            F_Y(y)&= P(Y \\leq y) = P(F_X(x) \\leq y) \\\\\r\n            &= 1 \\qquad \\text{(max value of }F_X \\text{ is 1, } F_{X}^{-1}((-\\infty,y])= \\mathbb{R})\r\n        \\end{align*}\r\n        \\item If $0 \\leq y <1 $,\r\n        \\begin{align*}\r\n            F_Y(y)= P(Y \\leq y)&= P(F_X(x)\\leq y) \\\\\r\n            &= P(X \\leq F_{X}^{-1}(y)) \\\\\r\n            &= F_X(F_{X}^{-1}(y)) \\\\\r\n            &= y\r\n        \\end{align*}\r\n    \\end{itemize}\r\n    \\begin{equation*}\r\n           f_Y (y)=\r\n            \\begin{cases}\r\n             0, & \\text{if}\\  y < 0 \\\\\r\n             y, & \\text{if}\\  0 \\leq y < 1 \\\\\r\n             1, & \\text{if}\\  y \\geq 1\r\n            \\end{cases}\r\n        \\end{equation*}\r\nIf we take any random variable $X$ \\& apply $F_X(.)$ as a function of $X$, then resulting random variable is a uniform random variable.\r\n\r\nSuppose we start with an uniform random variable $Y$ and consider a function of $Y$ which is $X= F_{X}^{-1}(Y)$, then X has a CDF $F_X(.)$.\r\n\r\n%\\fbox{In, MATLAB, there is an inbuilt function }\r\n\r\n\\section{Expectation of a random variable}\r\nIt is also called mean (or average).\r\n\r\nFor a discrete random variable $X$, let $S$ be the range of $X$, which is either finite or countably infinte.\r\n\r\n$$ E(X)= \\sum_{x_i \\in S}x_i P_X(x_i)$$\r\n\r\nwhere $P_X$ is the PMF of random variable $X$.\r\n\r\nThe expectation, is based on the weighted average, where weights are the probabilities of the random variable taking a particular value unlike the general notion of average.\r\n\r\nFor a continuous random variable $X$,\r\n$$ E(X)= \\int_{-\\infty}^{\\infty}x f_X(x)dx$$\r\nThe integral can be thought of as the limit of a summation. Hence,\r\n$$ E(X)= \\lim_{\\Delta x_i \\to 0} \\sum_{i= -\\infty}^{\\infty}x_i f_X(x_i) \\Delta x_i$$\r\n\r\n\\subsection{Expectation of a function of a random variable}\r\n\r\n$ Y= g(X)$, $X$ \\& $Y$ are discrete.\r\n\\begin{align*}\r\n    E(Y)= \\sum_{y_i}y_i P_Y(y_i)\r\n\\end{align*}\r\nWe can express $E(Y)$ in terms of PMF of $X$, $P_X$,\r\n\\begin{align*}\r\n    E(Y)&= \\sum_{y_i}y_i P_Y(y_i) \\\\\r\n    &= \\sum_{y_i}y_i \\sum_{x_{i,j}:g(x_{i,j})= y_i} P_X(x_{i,j}) \\\\\r\n    &= \\sum_{y_i} \\sum_{x_{i,j}:g(x_{i,j})= y_i} y_i P_X(x_{i,j}) \\\\\r\n    &= \\sum_{y_i} \\sum_{x_{i,j}:g(x_{i,j})= y_i} g(x_{i,j}) P_X(x_{i,j}) \\\\\r\n    &= \\sum_{x_j} g(x_j) P_X(x_j)\\\\\r\n    \\Rightarrow E(Y) &= \\sum_{y_i}y_i P_Y(y_i) \\\\\r\n    &= \\sum_{x_i} g(x_i) P_X(x_i)\r\n\\end{align*}\r\nFor continuous random variable,\r\n\\begin{align*}\r\n    E(Y) &= \\int_{-\\infty}^{\\infty}y f_Y(y)dy \\\\\r\n    &= \\int_{-\\infty}^{\\infty} g(x)f_X(x)dx\r\n\\end{align*}\r\n\r\n\\subsection{Variance of a random variable}\r\nIt is defined as,\r\n$$ E[g(X)] \\qquad g(X)= (X - E(X))^2$$\r\n\r\n$E(X)$ indicates the average value of a random variable. So there is a variation in the values the random variable takes around mean, now we would like to measure this variation and hence the variance comes into play.\r\n\r\n$(X- E(X))$ measures variation from the mean, and we square it so that the positive and negative values don't cancel each other.\r\n%23/6\r\n\r\nIf $X$ is discrete:\r\n\r\n$E(X)= \\mu$\r\n\r\n$E(X)= E(X-E(X)^2) = \\sum_{x_i} (x_i - \\mu )^2 P_X (x_i)$\r\n\r\nIf $X$ is continuous:\r\n\r\n$E(X)= \\mu$\r\n\r\n$E(X)= E(X-E(X)^2)= \\int_{-\\infty}^{\\infty}(x- \\mu)^2 f_X(x)dx$\r\n\r\n\\begin{itemize}\r\n    \\item $ Var(X) \\geq 0$\r\n\r\n    $Var(X)=0$ iff $X=E(X)$ with probability 1.\r\n\\end{itemize}\r\n\r\n\\subsection{Examples of discrete random variables}\r\n\\begin{enumerate}\r\n    \\item Bernoulli random variable:\r\n\r\n    Experiment: Coin toss experiment.\r\n    $$X:S = \\{ H,T\\} \\qquad H \\to 1 \\qquad T to 0$$\r\n    PMF of $X$, $P_X(1)= p,\\; P_X(0)=1-p$\r\n\r\n    $E(X)= 0(1-p)+1(p)=p$.\r\n\r\n    $Var(X)= (0-p)^2(1-p)+ (1-p)^2 p = p(1-p)$\r\n\r\n\r\n    \\item Binomial random variable:\r\n\r\n    Experiment: Toss a biased coin $n$ times. $X$ is defined as the number of heads in that string.\r\n    $$ S= \\{ HH\\cdots H, TH\\cdots H, \\cdots \\}$$\r\n    $X:S \\to R$\r\n\r\n    Range of $X$: $\\{ 0,1, cdots, n\\}$\r\n\r\n    PMF of $X$: $P_X (k)= {n \\choose k} p^k (1-p)^{n-k}$\r\n    \\begin{align*}\r\n        E(X)&= \\sum_{k=0}^{n}k {n \\choose k} p^k (1-p)^{n-k}\\\\\r\n        &= \\sum_{k=1}^{n} \\frac{n!}{(k-1)!(n-k)!} p^k (1-p)^{n-k} \\\\\r\n        &= np \\sum_{k=0}^{n-1} \\frac{(n-1)!}{k!(n-1-k)!} p^k (1-p)^{n-1-k} \\\\\r\n        &= np\r\n    \\end{align*}\r\n    $Var(X)= np(1-p)$\r\n\r\n    \\item Geometric random variable:\r\n\r\n    Experiment: Keep tossing a biased coin till we get a head.\r\n    $$ S= \\{ H, TH, TTH, \\cdots \\} \\qquad X:S \\to R$$\r\n    $P(H)= p, \\; P(T)= 1-p$\r\n\r\n    $P_X(k)= p(1-p)^{k-1}$\r\n\r\n    $$E(X)= \\sum_{k=1}^{\\infty} k p (1-p)^{k-1}= \\frac{1}{p}$$\r\n\r\n    \\begin{align*}\r\n        Var(X)&= E((X-E(X)^2)\\\\\r\n        &= E(X^2 -2X E(X) + (E(X))^2)\\\\\r\n        &= E(X^2)+E(-2XE(X))+E((E(X))^2\\\\\r\n        &= E(X^2)-2E(X)E(X)+(E(X))^2 \\\\\r\n        &= E(X^2)-(E(X))^2\r\n    \\end{align*}\r\n    We know, $Var(X) \\geq 0 \\Rightarrow E(X^2) \\geq (E(X))^2$\r\n\r\n    Now, $Var(x)$ for a geometric random variable:\r\n    \\begin{align*}\r\n        Var(X)&= E(X^2)-E(X)^2 \\\\\r\n        &=  \\sum_{k=1}^{\\infty} k^2 p (1-p)^{k-1} - \\left( \\frac{1}{p}\\right) ^2 \\\\\r\n        &= \\frac{2-p}{p^2} - \\frac{1}{p^2} \\\\\r\n        &= \\frac{1-p}{p^2}\r\n    \\end{align*}\r\n    \\item Poisson random variable:\r\n\r\n    Experiment: When we have to count rare events within a time frame.\r\n    $$ X= \\{ 0,1,2, \\cdots\\}$$\r\n    PMF of Poisson RV:\r\n    $$ P_X(k)= \\frac{\\lambda ^k}{k!} e^{-\\lambda}$$\r\n    where $\\lambda$ is a parameter and is the average value.\r\n\r\n    $Var(X)= \\lambda$\r\n\r\n    \\begin{align*}\r\n        \\sum_{k=0}^{\\infty} P_X(k) &= e^{-\\lambda } \\sum_{k=0}^{\\infty} \\frac{\\lambda ^k}{k!} \\\\\r\n        &= e^{-\\lambda} e^{\\lambda} \\\\\r\n        &= 1\r\n    \\end{align*}\r\n\\end{enumerate}\r\n\r\n\\subsection{Examples of continuous random variables}\r\n\r\n\\begin{enumerate}\r\n%25/6\r\n    \\item Uniform random variable:\r\n\r\n    Experiment: Measuring voltages, quantization error (original signal - quantized signal) is modelled as a uniform random variable.\r\n    \\begin{equation*}\r\n            f_X (x)=\r\n            \\begin{cases}\r\n            \\frac{1}{b-a}, & \\text{if}\\ a \\leq x \\leq b \\\\\r\n             0, & \\text{otherwise}\r\n            \\end{cases}\r\n       \\end{equation*}\r\n\r\n    $E(X)= \\frac{a+b}{2}$\r\n\r\n    $ Var(X)= \\frac{(b-a)^2}{12}$\r\n    \\item Exponential random variable:\r\n\r\n    Experiment: Used to model completion time of a process.\r\n\r\n    \\begin{equation*}\r\n            f_X (x)=\r\n            \\begin{cases}\r\n            \\lambda e^{-\\lambda x}, & \\text{if}\\ x \\geq 0\\\\\r\n             0, & \\text{otherwise}\r\n            \\end{cases}\r\n       \\end{equation*}\r\n\r\n\r\n       $$E(X)=\\int_{0}^{\\infty} x \\lambda e^{-\\lambda x}dx = \\frac{1}{x}$$\r\n       $$ Var(X)= E(X^2)- E(X)^2=\\frac{1}{\\lambda ^2}$$\r\n\r\n       \\item Gaussian random variable:\r\n\r\n       Experiment: Noise is generally modelled as a Gaussian random variable. We shall discuss this in detail while doing the central limit theorem.\r\n\r\n       $$ f_X(x)= \\frac{1}{\\sqrt{2\\pi \\sigma^2}} e^{-\\frac{(x- \\mu)^2}{2 \\sigma^2}}$$\r\n\r\n       Mean of $X$: $\\mu$\r\n\r\n       $Var(x)= {\\sigma}^2$\r\n   \\end{enumerate}\r\n\r\n%26/6\r\n\r\n\\section{Random vectors and joint CDF}\r\nConsider 2 individual random variables $X_1$ $X_2$, with $(S,F,P)$ as the probability space.\r\n$X_1:S \\to \\mathbb{R} \\qquad X_2:S \\to \\mathbb{R}$\r\n\r\n$$ (X_1,X_2) :S \\to {\\mathbb{R}}^2$$\r\n\r\nThen $(X_1,X_2) $ form a random vector and the joint CDF of $X_1$ and $X_2$:\r\n$$ F_{X_1,X_2}(x_1,x_2)= P(X_1 \\leq x_1, X_2 \\leq x_2)$$\r\n\r\n$$ X_1 \\leq x_1 = \\{ w: X_1(w) \\leq x_1\\}= A_1 \\in F$$\r\n\r\n$$ X_2 \\leq x_2 = \\{ w: X_2(w) \\leq x_2\\}= A_2 \\in F$$\r\n\r\n$$(X_1 \\leq x_1, X_2 \\leq x_2)= \\{ \\omega : X_1(\\omega) \\leq x_1 \\, \\& \\, X_2(\\omega) \\leq x_2\\} = A_1 \\cap A_2 \\in F$$\r\n\r\n$$ P(X_1 \\leq x_1 , X_2 \\leq x_2) \\; \\forall \\; (x_1 , x_2) \\in {\\mathbb{R}}^2$$\r\n\r\nBy definition, $ F_{X_1 , X_2}(x_1 , x_2) =  P(X_1 \\leq x_1 , X_2 \\leq x_2)$.\r\n\r\nThen we can expand this definition till $n$, i.e.\r\n\r\n$X_1,X_2, \\cdots , X_n \\qquad X_iS \\to \\mathbb{R}$\r\n\r\nWe can say that the joint CDF of $n$ random variables:\r\n$$ F_{X_1,\\cdots ,X_n}(x_1,\\cdots ,x_n)= P(X_1 \\leq x_1, X_2 \\leq x_2, \\cdots X_n \\leq x_n)$$\r\n\r\n\\subsection{Properties of joint CDF}\r\n\r\n\\begin{enumerate}\r\n    \\item $F_{X,Y}(.,.) $ is monotonically non decreasing in x,y.\r\n\r\n    We can compare them for $\\{ \\{ x_1 = x_2, y_1 \\leq y_2 \\}, \\{x_1 \\leq x_2, y_1 = y_2 \\} , \\{ x_1 < x_2 , y_1 < y_2\\}\\}$ but not for $\\{ x_1 > x_2 , y_1 < y_2\\}$ etc.\r\n    \\item $$ \\lim_{x \\to -\\infty, y \\to -\\infty} F_{X,Y} (x,y)=0$$\r\n    $$ \\lim_{x \\to -\\infty} F_{X,Y} (x,y)=0\\qquad \\lim_{y \\to -\\infty} F_{X,Y} (x,y)=0$$\r\n\r\n    \\item $$ \\lim_{x \\to \\infty, y \\to \\infty} F_{X,Y} (x,y)=1$$\r\n    $$ \\lim_{x \\to \\infty} F_{X,Y} (x,y)= F_Y (y)\\qquad \\lim_{y \\to \\infty} F_{X,Y} (x,y)= F_X(x)$$\r\n\r\n    \\item $F_{X,Y}(.,.)$ is right continuous individually in x \\& y.\r\n    $$ \\lim_{x \\to x_0^{+}} F_{X,Y} (x,y)=F_X(x_0,y)$$\r\n    $$ \\lim_{(x,y) \\to (x_0^{+},y_0^{+})} F_{X,Y} (x,y)=F_X(x_0,y_0)$$\r\n\r\n\\end{enumerate}\r\n\r\nDifferent cases possible for $X$ \\& $Y$:\r\n\\begin{itemize}\r\n    \\item $X$ \\& $Y$ both discrete.\r\n    \\item $X$ \\& $Y$ both continuous.\r\n    \\item $X$ is discrete \\& $Y$ is continuous.\r\n\\end{itemize}\r\n\r\n\\begin{enumerate}\r\n    \\item $X$ \\& $Y$ both discrete.\r\n\r\n    Joint PMF:\r\n    $$ P_{X,Y}(x_i,y_i)= P(X= x_i,Y= y_i)$$\r\n    Expressing joint CDF in terms of the joint PMF,\r\n    $$ F_{X,Y}(x,y) = \\sum_{x_i \\leq x} \\sum_{y_i \\leq y} P_{X,Y}(x_i,y_i)$$\r\n\r\n    $X\\to P_X \\qquad Y \\to P_Y \\qquad (X,Y) \\to P_{X,Y}$\r\n\r\n    We can form a relation between $P_{X,Y}$ and $P_X$,\r\n    $$ P_X(x_i) \\sum_{y_i} P_{X,Y}(x_i,y_i)$$\r\n    $$ P(X= x_i) \\sum_{y_i} P_{X,Y}(X=x_i,Y=y_i)$$\r\n\r\n    In the context of the joint PMF, $P_X$ \\& $P_Y$ are also called as marginal PMF's.\r\n    And the process of summing over the range of the other random variable to get the marginal PMF, is known as marginalization.\r\n\\end{enumerate}\r\n\r\n\\subsection{Conditional PMF}\r\n\r\nLet us recall conditional probabilities (in the probability space $(S,F,P)$),\r\n$$ P(A/B)= \\frac{P(A \\cap B)}{P(B)} \\qquad P(B)>0$$\r\nIn the context of random variables, how do we define conditional probabilities?\r\n\r\nGiven an event $B \\in F$, $P(B)>0$. Conditional CDF conditioned on the event $B$ would be:\r\n$$ F_{X/B}(x/B)= \\frac{P( (X \\leq x)\\cap B)}{P(B)}$$\r\n$X \\leq x= \\{ w: X(w) \\leq x\\}= A \\in F$\r\n\r\nIf $B$ is of the form $\\{ Y \\leq y \\}$\r\n$$ F_{X/B}(x/B)= \\frac{P((X \\leq x) \\cap B)}{P(B)}$$\r\n$$ F_{X/\\{ Y \\leq y \\}}(x / \\{ Y \\leq y \\})= \\frac{P(\\{ X \\leq x \\} \\cap \\{ Y \\leq y \\})}{P(\\{ Y \\leq y \\})}= \\frac{F_{X,Y}(x,y)}{F_Y (y)}$$\r\nWe shall denote this, conditional PMF, by:\r\n$$ F_{X/Y}(x/y)= \\frac{F_{X,Y}(x,y)}{F_Y (y)}$$\r\n\r\nIf both $X$ \\& $Y$ are discrete, for defining conditional PMF, we will not condition on $\\{ Y \\leq y_i \\} $ but instead condition on $\\{ Y = y_i \\}$\r\n\r\n$$ P_{X/\\{ Y = y_i \\}}(x_i/\\{ Y = y_i \\})= \\frac{P((X= x_i) \\cap (Y=y_i))}{P(Y=y_i)}$$\r\nConditional PMF:\r\n$$ P_{X/Y} (x_i /y_i)= \\frac{P_{X,Y}(x_i,y_i)}{P_Y(y_i)}= \\frac{\\text{Joint PMF}}{\\text{Marginal PMF}}$$\r\n\\\\\r\n\r\n% Example:\r\n\r\n%28/6\r\n\r\nIf $X$ \\& $Y$ are both continuous random variables, we can define joint PDF of $X$ \\& $Y$ as\r\n$$ f_{X,Y}(x,y)= \\frac{\\partial^2 F_{X,Y}(x,y)}{\\partial x \\partial y}$$\r\n\r\n$$ F_{X,Y}(x,y) =\\int_{-\\infty}^{x} \\int_{-\\infty}^{y} f_{X,Y}(x,y) dx dy$$\r\n\r\nMarginal PDF's of $X$ \\& $Y$ can be expressed in terms of joint PDF's as:\r\n$$ f_X (x)= \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy$$\r\n$$ f_Y (y)= \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx$$\r\n\r\nA joint PDF is said to be valid if,\r\n$$ f_{X,Y}(x,y) \\geq 0 \\quad \\& \\quad \\int_{-\\infty}^{x} \\int_{-\\infty}^{y} f_{X,Y}(x,y)\\partial x \\partial y =1$$\r\n\\\\\r\n\r\nWhen both $X$ \\& $Y$ are continuous,\r\n$P(X=x )=0,\\; P(Y=y)=0 $ i.e. probability that the random variable takes a single value, finite or countably infinite set of values is zero.\r\n\r\nConditional PDF can be expressed in terms of joint PDF's and marginal PDF's,\r\n$$ f_{X/Y}(x/y)=\\frac{f_{X,Y}(x,y)}{f_Y (y)}$$ \\\\\r\n\r\n$$ f_{X/Y}(x/y)= \\lim_{\\Delta x \\to 0, \\Delta y \\to 0} \\frac{P(x<X \\leq x+ \\Delta x / y<Y \\leq y+ \\Delta y)}{\\Delta x}$$\r\n$$ f_{X/B}(x/B)= \\lim_{\\Delta x \\to 0} \\frac{P(x<X \\leq x+ \\Delta x /B)}{\\Delta x}$$\r\n\r\nIf $B= \\{ y<Y \\leq y+ \\Delta y \\}$, and let $\\Delta y \\to 0$, $P(B) > 0$.\r\n\r\n$$ \\Rightarrow f_{X/Y}(x/y)= \\lim_{\\Delta x \\to 0, \\Delta y \\to 0} \\frac{P(x<X \\leq x+ \\Delta x , y<Y \\leq y+ \\Delta y)}{P(y<Y \\leq y+ \\Delta y)\\Delta x} $$\r\n$$= \\lim_{\\Delta x \\to 0, \\Delta y \\to 0} \\frac{}{} = $$\r\n\r\n\\subsection{Bayes rule for discrete random variable}\r\n$$ P_{Y/X}(y_i /x_i) = \\frac{P_{X/Y} (x_i/y_i) P_Y (y_i)}{P_X (x_i)}$$\r\n$$ =\\frac{P_{X/Y} (x_i/y_i) P_Y (y_i)}{\\sum_{y_i}P_{X/Y}(x_i/y_i) P_Y (y_i)}$$\r\n\r\n\\subsection{Bayes rule for continuous random variable}\r\n$$ P(x < X \\leq x+ \\Delta x / y<Y \\leq y+ \\Delta y)= \\frac{P(x < X \\leq x+ \\Delta x , y<Y \\leq y+ \\Delta y)P(x < X \\leq x+ \\Delta x)}{P(y<Y \\leq y+ \\Delta y)}$$\r\n$$ f_{X/Y}(x/y) \\Delta x =\\frac{f_{Y/X} (y/x) \\Delta y f_X (x) \\Delta x}{f_Y (y) \\Delta y} $$\r\n\r\n$$ \\Rightarrow f_{X/Y}(x/y)  =\\frac{f_{Y/X} (y/x)  f_X (x) }{f_Y (y)}$$\r\n\r\n%Eg: $X$ \\& $Y$ being continuous random variables\r\n%Consider a joint PDF of random variable $X$ \\& $Y$ which is constant on set $S$ as shown in figure %unable to draw figure yet\r\n\r\n\r\n\\subsection{Bayes rule when X is discrete and Y is continuous}\r\nIf $X$ is discrete and $Y$ is continuous, then we can't talk about either joint PMF or PDF. We can talk about the joint CDF,\r\n$$ P_{X/Y} (x/y) = \\frac{f_{Y/X} (y/x) P_X (x)}{f_Y(y)}$$\r\n\r\n\\begin{align*}\r\n    P_{X/Y}(x/y) &= \\lim_{\\Delta y \\to 0} P(X=x/y<Y \\leq y + \\Delta y) \\\\\r\n    &= \\lim_{\\Delta y \\to 0} \\frac{P(X=x,y<Y \\leq y + \\Delta y)}{P(y<Y \\leq y + \\Delta y)} \\\\\r\n    &= \\lim_{\\Delta y \\to 0} \\frac{P(y< Y \\leq y + \\Delta y / X= x)P(X=x)}{P(y<Y \\leq y+ \\Delta y)} \\\\\r\n    &= \\lim_{\\Delta y \\to 0}\\frac{f_{Y/X} (y/x) \\Delta y P(X=x)}{f_Y(y) \\Delta y} \\\\\r\n    &=\\frac{f_{Y/X} (y/x) P_X (x)}{f_Y(y)}\r\n\\end{align*}\r\n\r\n\\section{Independent random variables}\r\n\r\n\\begin{itemize}\r\n    \\item Discrete case: Two random variables are said to be indepedent if\r\n    $$ P_{X,Y}(x,y)= P_X (x) P_Y(y)$$\r\n    i.e. joint PMF is the product of the marginal PMF's.\r\n\r\n    OR,\r\n\r\n    $$ P_{X/Y}(x/y) = P_X (x)$$\r\n    \\item Continuous case: Two random variables are sid to be indepedent if\r\n    $$ f_{X,Y}(x,y)= f_X (x) f_Y (y)$$\r\n    i.e. joint PDF is the product of the marginal PDF's.\r\n\r\n    OR,\r\n\r\n    $$ f_{X/Y}(x/y) = f_X (x)$$\r\n\\end{itemize}\r\n\r\nIf both $X$ \\& $Y$ are discrete and indepedent, show that $F_{X,Y}(x,y)= F_X (x) F_Y (y)$.\r\n\\begin{proof}\r\n    For the discrete case,\r\n    \\begin{align*}\r\n        F_{X,Y}(x,y)&= P(X \\leq x, Y \\leq y) \\\\\r\n        &= \\sum_{x_i \\leq x} \\sum_{y_i \\leq y} P_{X,Y}(x_i,y_i) \\\\\r\n        &= \\sum_{x_i \\leq x} \\sum_{y_i \\leq y} P_{X}(x_i) P_Y(y_i) \\\\\r\n        &= \\left[ \\sum_{x_i \\leq x} P_{X}(x_i)\\right] \\left[ \\sum_{y_i \\leq y} P_{y}(y_i)\\right] \\\\\r\n        &= F_X (x) F_Y (y)\r\n    \\end{align*}\r\n    Similarly, using the same steps it can be proved for the continuous case too.\r\n\\end{proof}\r\n%30/6\r\n\r\n$P(X \\in A , Y \\in B)= P(X \\in A) P(Y \\in B) \\Rightarrow F_{X,Y}(x,y)= F_X (x) F_Y(y)$ by choosing $A= (-\\infty,x]$ and $B=(-\\infty,y]$\r\n\r\n\\begin{lemma}\r\n    Let $X$ and $Y$ be indepedent random variables and g and h be measurable functions. Then $g(X)$ \\& $h(Y)$ are also indepedent random variables.\r\n\\end{lemma}\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "8e60b96569a594643cfc74829a51e87cf84fab9a", "size": 54441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lectures.tex", "max_stars_repo_name": "thundermage117/Notes-On-Probability", "max_stars_repo_head_hexsha": "32dfe9c2286dc2a049dad4b3be179c8aa8865660", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lectures.tex", "max_issues_repo_name": "thundermage117/Notes-On-Probability", "max_issues_repo_head_hexsha": "32dfe9c2286dc2a049dad4b3be179c8aa8865660", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "thundermage117/Notes-On-Probability", "max_forks_repo_head_hexsha": "32dfe9c2286dc2a049dad4b3be179c8aa8865660", "max_forks_repo_licenses": ["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.9115598886, "max_line_length": 317, "alphanum_fraction": 0.552432909, "num_tokens": 20806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.6454793915572499}}
{"text": "\\section{Methods}\n\nIn this section we first build up intuition and theory for vanilla (standard) VAEs before extending the math to $\\beta$-VAE.\n\n\\subsection{Variational auto-encoders}\n\nWe have data $\\{\\vx_i\\}_{i=1}^N$ and we wish to find some low-dimensional (latent) representation for each $i$: $\\{\\vz_i\\}_{i=1}^N$. We assume that the data are in fact generated stochastically conditioned on the latent representations, such that:\n\\begin{align*}\n    \\vx|\\vz \\sim p(\\vx|\\vz)\n\\end{align*}\n\n$p$ is commonly either a Gaussian distribution (in the case of normally distribuetd data) or a Bernoulli distribution (in the case of pixels). The goal of a VAE is to learn a good approximation to this distribution, $\\ptheta$, with parameters $\\theta$, to model our data $\\vx$, as well as the distribution $\\ptheta(\\vz|\\vx)$ to model the hypothesized latent variables $\\vz$ conditioned on the observed data. We can arrange related $\\vx$ and $\\vz$ using Bayes' rule:\n\\begin{equation*}\n    \\ptheta(\\vx|\\vz) = \\frac{\\ptheta(\\vz|\\vx)\\ptheta(\\vx)}{\\ptheta(\\vz)}\n\\end{equation*}\nUnder this framework, we want to maximize the log-probability of data generated according to the process: (1) sample a point $\\vz\\sim\\ptheta(\\vz)$, then sample $\\vx\\sim\\ptheta(\\vx|\\vz)$:\n\\begin{align*}\n    \\ell &=\\sum_{i=1}^N\\log\\ptheta(\\vx_i) \\\\\n    \\intertext{Marginalizing over all values of $\\vx$,}\n    \\ell&=\\sum_{i=1}^N\\log\\int\\ptheta(\\vx_i|\\vz)\\ptheta(\\vz)d\\vz\n\\end{align*}\n\n\nWe now introduce an auxiliary distribution, $\\qphi$. This will allow us to massage this expression into one involving a KL-divergence and will ultimately be the distribution that we learn using the model.\n\\begin{align*}\n    \\ell &= \\sum_{i=1}^N\\log\\int\\ptheta(\\vx_i|\\vz_i)\\ptheta(\\vz_i)\\frac{\\qphi(\\vz_i)}{\\qphi(\\vz_i)}d\\vz_i \\\\\n    &= \\sum_{i=1}^N\\log\\int\\frac{\\ptheta(\\vx_i,\\vz_i)}{\\qphi(\\vz_i)}\\qphi(\\vz_i)d\\vz_i \\\\\n    &= \\sum_{i=1}^N\\log\\E\\left[\\frac{\\ptheta(\\vx_i,\\vz_i)}{\\qphi(\\vz_i)}\\right] \\\\\n    \\intertext{Using Jensen's inequality, we get the evidence lower bound (ELBO)}\n    &\\geq \\sum_{i=1}^N\\E_{\\vz\\sim\\qphi}\\log\\left[\\frac{\\ptheta(\\vx_i,\\vz_i)}{\\qphi(\\vz_i)}\\right] \\\\\n    \\ell &= \\sum_{i=1}^N(\\E_{\\vz\\sim\\qphi}[\\log\\ptheta(\\vx_i, \\vz_i)] - \\E_{\\vz\\sim\\qphi}[\\log\\qphi(\\vz)])\n\\end{align*}\nRecall that the definition of the KL divergence between $\\qphi$ and $\\ptheta$ is:\n\\begin{align*}\n    \\kl(\\qphi(\\vz)||\\ptheta(\\vz|\\vx)) &= \\Eq\\left[ \\log\\frac{\\qphi(\\vz)}{\\ptheta(\\vz|\\vx)} \\right] \\\\\n    \\intertext{Since $\\ptheta(\\vz|\\vx) = \\frac{\\ptheta(\\vz,\\vx)}{\\ptheta(\\vx)}$ (by definition of conditional probability),}\n    \\kl(\\qphi(\\vz)||\\ptheta(\\vz|\\vx)) &= -\\left( \\Eq[\\log\\ptheta(\\vz,\\vx)] - \\Eq[\\log\\qphi(\\vz)]\\right) + \\log\\ptheta(\\vx)\n\\end{align*}\nPlugging this back into our log-likelihood,\n\\begin{align*}\n    \\ell &= \\sum_{i=1}^N\\left( \\log(\\ptheta(\\vx_i)) - \\kl(\\qphi(\\vz_i)||\\ptheta(\\vz_i|\\vx_i)) \\right)\n\\end{align*}\nThe first term is maximized when the reconstruction $\\vx$ is faithful to the original data, whereas the second term is minimized when $\\ptheta$ is close to $\\qphi$.\n\n\\subsection{Choice of $\\qphi$}\n\nIn theory, we could choose an arbitrarily expressive family of distributions $\\qphi$ to model the latent variable $\\vz$. In practice, we make the simplifying {\\bf mean-field assumption}, which states that the dimensions of $\\qphi$ are independent:\n\n\\begin{align*}\n    \\qphi(\\vz|\\vx) = \\prod_{j=1}^d\\qphi(\\vz_j|\\vx_j)\n\\end{align*}\n\nIn our case, we operationalize this by saying that $\\qphi$ is an isotropic Gaussian (diagonal covariance) \\cite{blei2011}. Although this assumption reduces the expressiveness of the variational family $\\qphi$, we gain significantly in terms of computational efficiency when it comes time to learn the parameters of the distribution.\n\nAt this point, we are in effect trying to learn a unique distribution $\\qphi(\\vx|\\vz)$ for each $\\vx$. If we have $N$ observations and a latent space of dimension $d$, then if the latent distribution is Gaussian, we would need to learn a mean and variance for each dimension of each latent variable, or $2\\times N \\times d$. In other words, $N\\gg p$ (where $p$ is the number of parameters in the model), which both dramatically increases the variance of the parameter estimates (they are highly dependent on the particular data sample at hand) and increases the cost of fitting the model. To get around this, we perform {\\it amortised} variational inference: instead of directly estimating $\\mu_i$ and $\\Sigma_i$ for each $i = 1, \\dots, N$, we assume that each $\\mu_i, \\Sigma_i$ can be approximated by a function $g_\\phi(\\vx)$, typically a neural network \\cite{jaanTutorial}. We refer to this function interchangeably as the {\\bf encoder} or {\\bf inference network}. This is reresented by the left rectangle in figure \\ref{fig:encoder-decoder} and is denoted $g_\\phi$ here. Because the weights $\\phi$ are shared across all observations, we say that the cost of learning $\\phi$ is amortised across the entire dataset (hence, ``amortised variational inference''). Symmetrically, the conditional posterior distribution $\\ptheta(\\vx|\\vz)$ is implemented as a neural network that is typically the mirror image of the encoder, which is called the {\\bf decoder} or {\\bf generative network} and is denoted $f_\\theta$ here.\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\linewidth]{encoder-decoder.png}\n    \\caption{Simplified schematic of the encoder and decoder, where the left and right rectangles labelled $q(z|x)$ and $p(x|z)$ refer to the inferential and generative networks, respectively. First, $\\vz$ is generated from $\\vx$ using the encoder and then $\\vx$ is reconstructed using $\\vz$ \\cite{jaanTutorial}. Note: the notation in this figure is opposite to what we use in this paper: $\\theta$ and $\\phi$ have been flipped such that $\\theta$ parameterizes $q$ and $\\phi$ parameterizes $p$. Otherwise, the setup is the same to what we have been discussing.}\n    \\label{fig:encoder-decoder}\n\\end{figure}\n\n\\subsection{The reparameterization trick}\n\nA further advantage of variational inference is that it allows us to convert this problem from one of sampling from a posterior distribution -- which can require the use of computationally intensive or mathematically complex methods such as expectation-maximization -- to a simple non-convex optimization problem. That is, all the terms in the ELBO loss function can be expressed in terms of $\\phi$ and $\\theta$, meaning that if we can differentiate through all the operations involved, then this problem can be solved with gradient descent. To revisit, the encoder and decoder form a single algorithm:\n\\begin{enumerate}\n    \\item Given $\\vx$, compute $\\vmu, \\Sigma = g_\\phi(\\vx)$\n    \\item Sample $\\vz\\sim\\N(\\vmu,\\Sigma)$\n    \\item Compute reconstruction $\\hat{x} = f_\\theta(\\vz)$\n\\end{enumerate}\n\nThe one operation that does not allow for easy differentiation is the sampling step (2). In order to get around this, we use the ``reparameterization trick''. Recall that a $d$-dimensional isotropic Gaussian random variable can be converted into a sample from the $d$-dimensional multivariate normal distribution:\n\\[\n    \\vec{\\epsilon} = (\\vz - \\vmu) \\odot \\frac{1}{\\vsig} + \\vmu\n\\]\nWhere $\\vec{\\epsilon}$ is a standard normal random variable (not to be confused with $\\vz$, which is our latent variable with mean $\\mu$ and covariance $\\Sigma$) and $\\vsig$ is the $d$-dimensional vector of standard deviations for the components of $\\vz$. $\\odot$ represents element-wise multiplication. Using simple algebra, we can rearrange this:\n\\[\n    \\vz = (\\vec{\\epsilon} \\odot \\vsig) + \\vmu\n\\]\nThis means that sampling $\\vz\\sim\\N(\\vmu,\\Sigma)$ is equivalent to sampling $\\vec{\\epsilon}\\sim\\N(0,I)$ and then transforming it into $\\vz$ as above. The gradient operation is well-defined for sampling from the standard normal, so we can make the entire VAE algorithm differentiable by adding this reparameterization step:\n\n\\begin{enumerate}\n    \\item Given $\\vx$, compute $\\vmu, \\Sigma = g_\\phi(\\vx)$. Let $\\vsig = \\sqrt{\\operatorname{diag}(\\Sigma)}$\n    \\item Sample $\\vec{\\epsilon}\\sim\\N(0, I)$\n    \\item Let $\\vz = \\vec{\\epsilon}\\odot\\vsig + \\vmu$\n    \\item Compute reconstruction $\\hat{x} = f_\\theta(\\vz)$\n\\end{enumerate}\n\n\n\\subsection{$\\beta$-VAE}\n\nIn the original paper, the authors provide an independent derivation of the $\\beta$-VAE loss using constrained optimization \\cite{higgins2016beta}. Given data $\\vx$ distributed according to the data distribution $\\D$, the goal is to jointly learn generative parameters $\\theta$ and latent parameters $\\phi$ for the distributions $\\ptheta$ and $\\qphi$, respectively. We want to find $\\theta$ and $\\phi$ such that the posterior log-probability $\\ptheta(\\vx|\\vz)$ where $\\vz\\sim\\qphi$ is maximized:\n\\begin{align*}\n    \\theta^*,\\phi^* = \\underset{\\theta,\\phi}{\\argmax}\\E_{\\vx\\sim\\D}\\left[ \\Eq\\left[ \\log\\ptheta\\left( \\vx|\\vz \\right) \\right] \\right]\n\\end{align*}\nSubject to constraint\n\\begin{align*}\n    \\kl\\left( \\qphi(\\vz|\\vx)||p(\\vz) \\right) < \\delta\n\\end{align*}\nWhere $\\delta$ is a small positive constant (since KL divergence is nonnegative). The constraint is imposed to narrow the \"information bottleneck\" by encouraging the latent posterior $\\qphi(\\vz|\\vx)$ to be close to a simple prior $p(\\vz)$, which in this case is a standard gaussian, $\\N(0, I)$. The idea is that we want to make $\\qphi$ less expressive, which in turn forces it to be as efficient as possible in which latent factors are represented. Hopefully, the efficiency is maximized when the latent factors line up with the original factors that generated the data.\n\nWe can rewrite this constrained optimization problem as a Lagrangian subject to the KKT condition, with Lagrange multiplier $\\beta$ and Lagrangian objective $\\F$:\n\n\\begin{align*}\n    \\F(\\theta, \\phi, \\beta; \\vx, \\vz) &= \\Eq\\left[ \\log\\ptheta(\\vx|\\vz) \\right] - \\beta\\left( \\kl(\\qphi(\\vz|\\vx)||p(\\vz)) - \\delta \\right) \\\\\n    &= \\Eq\\left[ \\log\\ptheta(\\vx|\\vz) \\right] - \\beta\\left( \\kl(\\qphi(\\vz|\\vx)||p(\\vz))\\right) + \\beta\\delta \\\\\n    &\\geq \\Eq\\left[ \\log\\ptheta(\\vx|\\vz) \\right] - \\beta\\left( \\kl(\\qphi(\\vz|\\vx)||p(\\vz))\\right)\n\\end{align*}\nImmediately, we can recognize that this is nearly identical to the vanilla VAE loss, except for the hyperparameter $\\beta$. When $\\beta=1$, this is equivalent to the vanilla VAE loss. When $\\beta = 0$, the model becomes similar to a non-variational auto-encoder, since the only objective is to faithfully reconstruct the data. As $\\beta$ increases, the bottleneck in the latent space becomes narrower, promoting a sparser latent representation (i.e. a latent space that more closely resembles a standard Gaussian).\n\n\\subsubsection{Measuring disentanglement}\n\nThe authors of the original $\\beta$-VAE paper go a step further and propose a ``disentanglement metric'' to quantify how well the model's latent representations align with the hypothesized generative factors for the data \\cite{higgins2016beta}.\n\nFormally, we assume the data $\\vx$ are drawn from a dataset $\\D=\\{X, V\\}$, where $X$ is the data matrix, and $V$ is a matrix of hypothesized {\\it generative factors} for each data point. For instance, a factor for a dataset of faces might be {\\it skin tone} or {\\it glasses}. An image is created using a simulator: $\\vx\\sim\\Sim(\\vv)$. Then,\n\\begin{enumerate}\n    \\item Uniformly sample factor $y$ from the set of $K$ possible generative factors\n    \\item Repeat $L$ times:\n    \\begin{enumerate}\n        \\item Sample two sets of generative latent representations, $\\vv_{1,l}$ and $\\vv_{2,l}$ such that both $\\vv_{1,l}$ and $\\vv_{2,l}$ have the same value for factor $y$ and are free to differ in all other generative factors\n        \\item Simulate an image $x_{1,l\\sim\\Sim(v_{1,l})}$ and compute the latent representation $\\vz_{1,l}\\sim q(\\vz|\\vx_{1,l})$ using the encoder $g_\\phi(\\vx_{1,l})$. Repeat for $v_{1,l}$\n        \\item Compute a difference vector $z^l_{\\diff}=|z_{1,l}-z_{2,l}|_1$\n    \\end{enumerate}\n    \\item Given all $z^l_{\\diff}$ computed as above, calculate the average difference vector $\\bar{z}_{\\diff} = \\frac{1}{L}\\sum_{l=1}^Lz^l_{\\diff}$\n    \\item Use $\\bar{z}_{\\diff}$ as the input for a linear classifier (i.e. logistic regression), where the goal is to predict the factor $y$ that was kept constant between all pairs of latent factors\n\\end{enumerate}\n\nThis algorithm can be seen in figure \\ref{fig:disentanglement-metric}. The intuition behind this metric is that when a pair of data points $(x_{1,l}, x_{2,l})$ has the same value for some generative factor, then a well-disentangled latent representation will be such that a small subset of the latent dimensions will correspond to that factor and will therefore have small difference, averaged over many such pairs. Thus, a linear classifier trained on supervised pairs of $(\\bar{z}_{\\diff}, y)$ will be able to map the averaged difference vectors to the corresponding generative factor that was held constant across the pairs.\n\n\\begin{figure}\n    \\includegraphics[width=\\linewidth]{disentanglement-metric.png}\n    \\caption{A schematic of the proposed disentanglement metric from \\cite{higgins2016beta}. Each vector $\\vz^l_{\\diff}$ in the process is generated from pairs of latent representations $z_{1,l}, z_{2,l}$ with the exact same value for a chose generative factor $y$. All of the $L$ pairs in batch $b$ may differ in terms of the value of the generative factor, but the choice of $y$ is constant between pairs. The linear classifier, $p(y|\\vz^b_{\\diff})$ is a multivariate classification algorithm whose goal is to predict which generative factor was used to generate the average difference vector $\\vz_{\\diff}^b$ (in the text, we refer to this average difference vector as $\\bar{z}_{\\diff}$).}\n    \\label{fig:disentanglement-metric}\n\\end{figure}\n\n\\subsection{Implementation}\n\nDepending on the type and complexity of the data, various architectures for the inference and generative networks are used. In the simplest case, each is a feed-forward neural network, which is common for either numeric data or small-sized image data (e.g. MNIST, which is $28\\times28\\times1$). For larger image data, such as the CelebA dataset ($64\\times64\\times3$), convolutional neural networks (CNNs) are often used, with the structure of the encoder neural network mirroring the structure of the decoder neural network. The weights of the encoder and decoder are found using well-known gradient descent algorithms (e.g. the authors use Adam, RMSProp, and Adagrad for different experiments).", "meta": {"hexsha": "b048951ca2711b7cb31fe7fa7f9001f193b599e1", "size": 14468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/method.tex", "max_stars_repo_name": "benlevyx/beta-vae", "max_stars_repo_head_hexsha": "d8b583b485674f5e6e5f1372fd4b1f08c20e7a69", "max_stars_repo_licenses": ["MIT"], "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/method.tex", "max_issues_repo_name": "benlevyx/beta-vae", "max_issues_repo_head_hexsha": "d8b583b485674f5e6e5f1372fd4b1f08c20e7a69", "max_issues_repo_licenses": ["MIT"], "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/method.tex", "max_forks_repo_name": "benlevyx/beta-vae", "max_forks_repo_head_hexsha": "d8b583b485674f5e6e5f1372fd4b1f08c20e7a69", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 104.8405797101, "max_line_length": 1514, "alphanum_fraction": 0.7289189936, "num_tokens": 4062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.645479379678369}}
{"text": "\n\\section{Numerical Methods}\n\n\\begin{frame}{Approximation for stochastic differential equations}\n\t\\begin{equation*}\n\tdX=f(X)dt+{\\color{red}g(X)dW}\n\t\\end{equation*}\n\t\\begin{center}\n\t$f,g$ are functions of X.\t\n\t\\end{center}\n\t\\begin{itemize}\n\t\t\\item It's difficult to find an explicit solution.\n\t\t\\item We can approximate the solution.\n\t\t\\item Simulations!\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Numerical methods}\nIntegral form of a SDE: \n$$X(t)=X_0+\\int_{0}^{t}f(X(s))ds+{\\color{red}\\int_{0}^{t}g(X(s))dW(s)}$$\n\nX(t) is a random variable for each value of t. To apply numerical methods:\n\t\\begin{itemize}\n\t\t\\item Discretized time steps\t\n\t\t%\\item X(t) will be the limit as our stepsize goes to zero.\n\t\\end{itemize}\n\\end{frame}\n\n%\\begin{frame}{It\\^{o}'s Formulas}\n\\begin{frame}{Ito's Formulas}\n  \t\\begin{itemize}\n   \t\t\\item First version: $$f(B(b))-f(B(a))=\\int_{a}^{b}{\\frac{\\partial f}{\\partial B} \t\t\t\tdB}+\\int_{a}^{b}{\\frac{1}{2} \\frac{\\partial^2 f}{\\partial B^2} dt} $$\\\\\n    \t\t\\item Second version: $$f(b,B(b))-f(a,B(a))=\\int_{a}^{b}{\\frac{\\partial f}{\\partial B} \t\t\tdB}+\\int_{a}^{b}{\\left(\\frac{\\partial f}{\\partial s}+\\frac{1}{2}\\frac{\\partial^2 f}\n    \t\t{\\partial B^2}\\right) ds}$$\\\\\n    \t\t\\item Third version: The Stochastic Chain Rule\n    \t\t$$\\theta (t,x_t)=\\theta(a,x_a)+\\int_{a}^{t}\\frac{\\partial \\theta}{\\partial s}ds+\n    \t\t\\int_{a}^{t}f\\frac{\\partial \\theta}{\\partial x}dW+\n  \t\t\\int_{a}^{t}g\\frac{\\partial \\theta}{\\partial x}+f^2 \\frac{1}{2} \\frac{\\partial ^2\\theta}\n  \t\t{\\partial x^2}ds$$\\\\\n  \t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Euler-Maruyama method}\nLet $\\tau_j=j\\Delta t$. In the interval [0,L] we have the EM method:\\bigskip\\\\\n$$X_j=X_{j-1}+f(X_{j-1})\\Delta t+g(X_{j-1})(W(\\tau_j)-W(\\tau_{j-1}))$$\n which is an approximation for the equation\n$$X(\\tau_j)=X(\\tau_{j-1})+\\int_{\\tau_{j-1}}^{\\tau_{j}}f(X(s))ds+\\int_\n{\\tau_{j-1}}^{\\tau_{j}}g(X(s))dW(s)$$\n%We have Euler's method in the deterministic case ($g\\equiv 0$)\n\\end{frame}\n\n\\begin{frame}\n\\begin{block}{Strong Convergence}\nWe say that a method has strong order of convergence equal to $\\gamma$ if there exists a constant C such that:\n$$E|X_n-X(\\tau)|\\leq C \\Delta t^\\gamma$$\nfor any fixed $\\tau=n \\Delta t \\in [0,T]$ and $\\Delta t$ sufficiently small.\n\\end{block}\n\\bigskip\nThe EM method has strong order of convergence of $\\gamma=\\frac{1}{2}$\\cite{doi:10.1137/S0036144500378302}.\n\\end{frame}\n\n\\begin{frame}{Milstein's method}\nThe Milstein method raises the strong order of convergence to 1\\cite{doi:10.1137/S0036144500378302}:\t\n\t\\begin{equation*}\n\t\\begin{split}\n\tX_{j} & =X_{j-1}+ f(X_{j-1}) \\; \\Delta t + g(X_{j-1})(W(\\tau_j)-W(\\tau_{j-1}))\\\\\n\t  &\\quad +\\frac{1}{2}g(X_{j-1})g'(X_{j-1})((W(\\tau_j)-W(\\tau_{j-1}))^2-\\Delta t)\n\t\\end{split}\n\t\\end{equation*}\n\\end{frame}\n\n\\begin{frame}{Example}\nIf we consider the differential equation:\n\\begin{equation*}\n  dX=\\alpha X dt+ \\beta X dW,\n\\end{equation*}\nWhere $\\alpha, \\beta$ are constants. The theoretical solution is: \n\\begin{equation*}\n  X(t)=X_{0}\\exp{\\left((\\alpha -\\frac{1}{2}\\beta ^2)t +\\beta W(t)\\right)}\n\\end{equation*}\n\\end{frame}\n\n\\begin{frame}\n\t\\begin{center}\n\t\\includegraphics[scale=0.55]{alpham15_beta05.png} \n\t\\end{center}\n\\end{frame}\n\n\\begin{frame}\nA system of equations can be expressed in differential form \\cite{klodenNumerics}:\n\t\\begin{eqnarray*}\n\t\tdx&=&f_1(x,y)dt+{\\color{red}g_1(x,y)dW}\\\\\n\t\tdy&=&f_2(x,y)dt+{\\color{red}g_2(x,y)dW}\\\\\n\t\\end{eqnarray*}\nThe equivalent integral form is the following:\n\t\\begin{eqnarray*}\n\t\tx_t=x_a+\\int_{a}^{t}f_1 ds+{\\color{red}\\int_{a}^{t}g_1dW_1}\\\\\n\t\ty_t=y_a+\\int_{a}^{t}f_2 ds+{\\color{red}\\int_{a}^{t}g_2dW_2}\\\\\n\t\\end{eqnarray*}\t\n\\end{frame}\n\n\n\\begin{frame}\nApplying the chain rule for $f_1$:\n\t\\begin{equation*}\n\t\\begin{split}\n\tf_1(x_j,y_j) & \\approx f_1(x_{j-1},y_{j-1})+f_{1x}(x_{j-1},y_{j-1})(x-x_{j-1})\\\\\n\t& \\quad +f_{1y}(x_{j-1},y_{j-1})(y-y_{j-1})+\\frac{1}{2} f_{1xx}(x_{j-1},y_{j-1})(x-\n\tx_{j-1})^2\\\\\n\t& \\quad +f_{1xy}(x_{j-1},y_{j-1})(x-x_{j-1})(y-y_{j-1})\\\\\n\t& \\quad +\\frac{1}{2}f_{1yy}(x_{j-1},y_{j-1})(y-y_{j-1})^2\n\t\\end{split}\n\t\\end{equation*}\nSubstitute into the integral form:\n\t\\begin{eqnarray*}\n\tx_j-x_{j-1} & \\approx & \\int_{\\tau_{j-1}}^{\\tau_{j}}f_1 ds+\\int_{\\tau_{j-1}}^{\\tau_{j}}g_1dW_1\n\t\\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\nSimilarly for $g_1$ and if we ignore the high order terms:\n\t\\begin{equation*}\n\t\\begin{split}\n\tx_{j} & \\approx x_{j-1}+f_1(x_{j-1},y_{j-1})\\Delta t+g_1(x_{j-1},y_{j-1})\\Delta W_1\\\\\n\t& \\quad +g_{1x}(x_{j-1},y_{j-1})\\int_{\\tau_{j-1}}^{\\tau_{j}}\n\t\\int_{\\tau_{j-1}}^{s}g_1dW_1dW_1\\\\\n\t& \\quad\t+g_{1y}(x_{j-1},y_{j-1})\\int_{\\tau_{j-1}}^{\\tau_{j}}\\int_{\\tau_{j-1}}^{s}\n\tg_2dW_2dW_1\\\\\n\t\\end{split}\n\t\\end{equation*}\t\n\\end{frame}\n\n\n\\begin{frame}\nApplying the chain rule again:\n\t\\begin{equation*}\n\t\\begin{split}\n\tx_{j} &= x_{j-1}+f_1(x_{j-1},y_{j-1})\\Delta t+g_1(x_{j-1},y_{j-1})\\Delta W_1\\\\\n\t&\\quad +\\frac{1}{2}g_{1x}(x_{j-1},y_{j-1})g_{1}(x_{j-1},y_{j-1})(\\Delta W_1^2-\\Delta t)\\\\\n\t&\\quad +g_{1y}(x_{j-1},y_{j-1})g_2(x_{j-1},y_{j-1})\\Delta W_1 \\Delta W_2\\\\\n\t\\end{split}\n\t\\end{equation*}\n\\end{frame}\n\n\\begin{frame}\nSimilarly:\n\\begin{equation*}\n\t\\begin{split}\n\ty_{j}&=y_{j-1}+f_2(x_{j-1},y_{j-1})\\Delta t+g_2(x_{j-1},y_{j-1})\\Delta W_2\\\\\n\t&\\quad +g_{2x}(x_{j-1},y_{j-1})g_{1}(x_{j-1},y_{j-1})\\Delta W_1 \\Delta W_2\\\\\n\t&\\quad +\\frac{1}{2}g_{2y}(x_{j-1},y_{j-1})g_2(x_{j-1},y_{j-1})(\\Delta W_2^2-\\Delta t)\\\\\n\t\\end{split}\n\t\\end{equation*}\n\\end{frame}\n\n\n\n\n", "meta": {"hexsha": "1de5d06e39fd61055a33e5cc7356cd536f608ed7", "size": 5365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentations/Final/numerics.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/numerics.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/numerics.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": 33.53125, "max_line_length": 179, "alphanum_fraction": 0.6311276794, "num_tokens": 2384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6454793787320544}}
{"text": "\\chapter{Excision and relative homology}\nWe have already seen how to use the Mayer-Vietoris sequence:\nwe started with a sequence\n\\[ \\dots \\to H_n(U \\cap V) \\to H_n(U) \\oplus H_n(V) \\to H_n(U+V) \\to H_{n-1}(U \\cap V) \\to \\dots \\]\nand its reduced version,\nthen appealed to the geometric fact that $H_n(U+V) \\cong H_n(X)$.\nThis allowed us to algebraically make computations on $H_n(X)$.\n\nIn this chapter, we turn our attention to the long exact\nsequence associated to the chain complex\n\\[ 0 \\to C_n(A) \\injto C_n(X) \\surjto C_n(X,A) \\to 0. \\]\nThe setup will look a lot like the previous two chapters,\nexcept in addition to $H_n : \\catname{hTop} \\to \\catname{Grp}$\nwe will have a functor $H_n : \\catname{hPairTop} \\to \\catname{Grp}$\nwhich takes a pair $(X,A)$ to $H_n(X,A)$.\nThen, we state (again without proof) the key geometric result,\nand use this to make deductions.\n\n\\section{The long exact sequences}\nRecall \\Cref{thm:long_exact_rel}, which says that the sequences\n\\[ \\dots \\to H_n(A) \\to H_n(X) \\to H_n(X,A) \\to H_{n-1}(A) \\to \\dots. \\]\nand\n\\[ \\dots \\to \\wt H_n(A) \\to \\wt H_n(X) \\to H_n(X,A) \\to \\wt H_{n-1}(A) \\to \\dots \\]\nare long exact.\nBy \\Cref{prob:triple_long_exact} we even have a long exact sequence\n\\[\n\t\\dots\n\t\\to H_n(B,A)\n\t\\to H_n(X,A)\n\t\\to H_n(X,B)\n\t\\to H_{n-1}(B,A)\n\t\\to \\dots.\n\\]\nfor $A \\subseteq B \\subseteq X$.\nAn application of the second long exact sequence above gives:\n\\begin{lemma}\n\t[Homology relative to contractible spaces]\n\t\\label{lem:rel_contractible}\n\tLet $X$ be a topological space,\n\tand let $A \\subseteq X$ be contractible.\n\tFor all $n$, \\[ H_n(X, A) \\cong \\wt H_n(X). \\]\n\\end{lemma}\n\\begin{proof}\n\tSince $A$ is contractible, we have $\\wt H_n(A) = 0$ for every $n$.\n\tFor each $n$ there's a segment of the long exact sequence given by\n\t\\[ \\dots \\to \\underbrace{\\wt H_n(A)}_{=0} \\to \\wt H_n(X) \\to H_n(X,A)\n\t\\to \\underbrace{\\wt H_{n-1}(A)}_{=0} \\to \\dots. \\]\n\tSo since $0 \\to \\wt H_n(X) \\to H_n(X,A) \\to 0$ is exact,\n\tthis means $H_n(X,A) \\cong \\wt H_n(X)$.\n\\end{proof}\n\nIn particular, the theorem applies if $A$ is a single point.\nThe case $A = \\varnothing$ is also worth noting.\nWe compile these results into a lemma:\n\\begin{lemma}\n\t[Relative homology generalizes absolute homology]\n\tLet $X$ be any space, and $\\ast \\in X$ a point. Then for all $n$,\n\t\\[\n\t\tH_n(X, \\{\\ast\\}) \\cong \\wt H_n(X)\n\t\t\\qquad\\text{and}\\qquad\n\t\tH_n(X, \\varnothing) = H_n(X).\n\t\\]\n\\end{lemma}\n\n\\section{The category of pairs}\nSince we now have an $H_n(X,A)$ instead of just $H_n(X)$,\na natural next step is to create a suitable category of \\emph{pairs}\nand give ourselves the same functorial setup as before.\n\n\\begin{definition}\n\tLet $\\varnothing \\neq A \\subseteq X$ and $\\varnothing \\neq B \\subseteq X$\n\tbe subspaces, and consider a map $f : X \\to Y$.\n\tIf $f\\im(A) \\subseteq B$ we write\n\t\\[ f : (X,A) \\to (Y,B). \\]\n\tWe say $f$ is a \\vocab{map of pairs},\n\tbetween the pairs $(X,A)$ and $(Y,B)$.\n\\end{definition}\n\\begin{definition}\n\tWe say that $f,g : (X,A) \\to (Y,B)$ are \\vocab{pair-homotopic} if they\n\tare ``homotopic through maps of pairs''.\n\n\tMore formally, a \\vocab{pair-homotopy}\n\t$f, g : (X,A) \\to (Y,B)$ is a map $F : [0,1] \\times X \\to Y$,\n\twhich we'll write as $F_t(X)$, such that\n\t$F$ is a homotopy of the maps $f,g : X \\to Y$\n\tand each $F_t$ is itself a map of pairs.\n\\end{definition}\nThus, we naturally arrive at two categories:\n\\begin{itemize}\n\t\\ii $\\catname{PairTop}$, the category of \\emph{pairs} of\n\ttoplogical spaces, and\n\t\\ii $\\catname{hPairTop}$, the same category except\n\twith maps only equivalent up to homotopy.\n\\end{itemize}\n\\begin{definition}\n\tAs before, we say pairs $(X,A)$ and $(Y,B)$ are\n\t\\vocab{pair-homotopy equivalent}\n\tif they are isomorphic in $\\catname{hPairTop}$.\n\tAn isomorphism of $\\catname{hPairTop}$ is a\n\t\\vocab{pair-homotopy equivalence}.\n\\end{definition}\n\nWe can do the same song and dance as before with the prism operator to obtain:\n\\begin{lemma}[Induced maps of relative homology]\n\tWe have a functor \n\t\\[ H_n : \\catname{hPairTop} \\to \\catname{Grp}. \\]\n\\end{lemma}\nThat is, if $f : (X,A) \\to (Y,B)$ then we obtain an induced map\n\\[ f_\\ast : H_n(X,A) \\to H_n(Y,B). \\]\nand if two such $f$ and $g$ are pair-homotopic\nthen $f_\\ast = g_\\ast$.\n\nNow, we want an analog of contractible spaces for our pairs:\ni.e.\\ pairs of spaces $(X,A)$ such that $H_n(X,A) = 0$.\nThe correct definition is:\n\\begin{definition}\n\tLet $A \\subseteq X$.\n\tWe say that $A$ is a \\vocab{deformation retract} of $X$\n\tif there is a map of pairs $r : (X, A) \\to (A, A)$\n\twhich is a pair homotopy equivalence.\n\\end{definition}\n\\begin{example}\n\t[Examples of deformation retracts]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If a single point $p$ is a deformation retract of a space $X$,\n\t\tthen $X$ is contractible, since the retraction $r : X \\to \\{\\ast\\}$\n\t\t(when viewed as a map $X \\to X$)\n\t\tis homotopic to the identity map $\\id_X : X \\to X$.\n\t\t\\ii The punctured disk $D^2 \\setminus \\{0\\}$\n\t\tdeformation retracts onto its boundary $S^1$.\n\t\t\\ii More generally, $D^{n} \\setminus \\{0\\}$\n\t\tdeformation retracts onto its boundary $S^{n-1}$.\n\t\t\\ii Similarly, $\\RR^n \\setminus \\{0\\}$\n\t\tdeformation retracts onto a sphere $S^{n-1}$.\n\t\\end{enumerate}\n\\end{example}\nOf course in this situation we have that\n\\[ H_n(X,A) \\cong H_n(A,A) = 0. \\]\n\n\\begin{exercise}\n\tShow that if $A \\subseteq V \\subseteq X$,\n\tand $A$ is a deformation retract of $V$,\n\tthen $H_n(X,A) \\cong H_n(X,V)$ for all $n$.\n\t(Use \\Cref{prob:triple_long_exact}. Solution in next section.)\n\\end{exercise}\n\n\\section{Excision}\nNow for the key geometric result, which is the analog of\n\\Cref{thm:open_cover_homology} for our relative homology groups.\n\\begin{theorem}\n\t[Excision]\n\tLet $Z \\subseteq A \\subseteq X$ be subspaces such that\n\tthe closure of $Z$ is contained in the interior of $A$.\n\tThen the inclusion $\\iota (X \\setminus Z, A \\setminus Z) \\injto (X,A)$\n\t(viewed as a map of pairs) induces an isomorphism of\n\trelative homology groups\n\t\\[ H_n(X \\setminus Z, A \\setminus Z) \\cong H_n(X,A). \\]\n\\end{theorem}\nThis means we can \\emph{excise} (delete) a subset $Z$ of $A$ in computing\nthe relative homology groups $H_n(X,A)$.\nThis should intuitively make sense:\nsince we are ``modding out by points in $A$'',\nthe internals of the point $A$ should not matter so much.\n\nThe main application of excision is to decide\nwhen $H_n(X,A) \\cong \\wt H_n(X/A)$.\nAnswer:\n\n\\begin{theorem}\n\t[Relative homology $\\implies$ quotient space]\n\t\\label{thm:good_pair}\n\tLet $X$ be a space and $A$ be a subspace such that\n\t$A$ is a deformation retract of some open set $V \\subseteq X$.\n\tThen the quotient map $q : X \\to X/A$ induces an isomorphism\n\t\\[ H_n(X,A) \\cong H_n(X/A, A/A) \\cong \\wt H_n(X/A). \\]\n\\end{theorem}\n\\begin{proof}\n\tBy hypothesis, we can consider the following maps of pairs:\n\t\\begin{align*}\n\t\tr & : (V,A) \\to (A,A)  \\\\\n\t\tq & : (X,A) \\to (X/A, A/A) \\\\\n\t\t\\widehat q &: (X-A, V-A) \\to (X/A-A/A, V/A-A/A).\n\t\\end{align*}\n\tMoreover, $r$ is a pair-homotopy equivalence.\n\tConsidering the long exact sequence of a triple\n\t(which was \\Cref{prob:triple_long_exact})\n\twe have a diagram\n\t\\begin{diagram}\n\t\tH_n(V,A) & \\rTo & H_n(X,A) & \\rTo^f & H_n(X, V) & \\rTo & H_{n-1}(V,A) \\\\\n\t\t\\dTo_r^\\cong && && && \\dTo_r^\\cong \\\\\n\t\t\\underbrace{H_n(A,A)}_{=0} && && && \\underbrace{H_{n-1}(A,A)}_{=0}\n\t\\end{diagram}\n\twhere the isomorphisms arise since $r$ is a pair-homotopy equivalence.\n\tSo $f$ is an isomorphism.\n\tSimilarly the map\n\t\\[ g : H_n(X/A, A/A) \\to H_n(X/A, V/A) \\]\n\tis an isomorphism.\n\n\tNow, consider the commutative diagram\n\t\\begin{diagram}\n\t\tH_n(X,A) & \\rTo^f & H_n(X,V) & \\lTo^{\\text{Excise}} & H_n(X-A, V-A) \\\\\n\t\t\\dTo^{q_\\ast} && && \\dTo^{\\widehat{q}_\\ast}_{\\cong} \\\\\n\t\tH_n(X/A,A/A) & \\rTo^g & H_n(X/A,V/A)\n\t\t& \\lTo^{\\text{Excise}} & H_n(X/A-A/A, V/A-A/A) \\\\\n\t\\end{diagram}\n\tand observe that the rightmost arrow $\\widehat{q}_\\ast$ is an isomorphism,\n\tbecause outside of $A$ the map $\\widehat q$ is the identity.\n\tWe know $f$ and $g$ are isomorphisms,\n\tas are the two arrows marked with ``Excise'' (by excision).\n\tFrom this we conclude that $q_\\ast$ is an isomorphism.\n\tOf course we already know that homology relative to a point\n\tis just the relative homology groups\n\t(this is the important case of \\Cref{lem:rel_contractible}).\n\\end{proof}\n\n\\section{Some applications}\nOne nice application of excision is to compute $\\wt H_n(X \\vee Y)$.\n\\begin{theorem}[Homology of wedge sums]\n\tLet $X$ and $Y$ be spaces with basepoints $x_0 \\in X$ and $y_0 \\in Y$,\n\tand assuming each point is a deformation retract of some open neighborhood.\n\tThen for every $n$ we have\n\t\\[\n\t\t\\wt H_n(X \\vee Y)\n\t\t= \\wt H_n(X) \\oplus \\wt H_n(Y).\n\t\\]\n\\end{theorem}\n\\begin{proof}\n\tApply \\Cref{thm:good_pair} with the subset $\\{x_0, y_0\\}$ of $X \\amalg Y$,\n\t\\begin{align*}\n\t\t\\wt H_n (X \\vee Y)\n\t\t\\cong \\wt H_n( (X \\amalg Y) / \\{x_0, y_0\\} )\n\t\t&\\cong H_n(X \\amalg Y, \\{x_0,y_0\\}) \\\\\n\t\t&\\cong H_n(X, \\{x_0\\}) \\oplus H_n(Y, \\{y_0\\}) \\\\\n\t\t&\\cong\\wt H_n(X) \\oplus \\wt H_n(Y). \\qedhere\n\t\\end{align*}\n\\end{proof}\n\nAnother application is to give a second method\nof computing $H_n(S^m)$.\nTo do this, we will prove that\n\\[ \\wt H_n(S^m) \\cong \\wt H_{n-1}(S^{m-1}) \\]\nfor any $n,m > 1$.\nHowever, \n\\begin{itemize}\n\t\\ii $\\wt H_0(S^n)$ is $\\ZZ$ for $n=0$ and $0$ otherwise.\n\t\\ii $\\wt H_n(S^0)$ is $\\ZZ$ for $m=0$ and $0$ otherwise.\n\\end{itemize}\nSo by induction on $\\min \\{m,n\\}$ we directly obtain that\n\\[\n\t\\wt H_n(S^m) \\cong\n\t\\begin{cases}\n\t\t\\ZZ & m=n \\\\\n\t\t0 & \\text{otherwise}\n\t\\end{cases}\n\\]\nwhich is what we wanted.\n\nTo prove the claim, let's consider the exact sequence\nformed by the pair $X = D^2$ and $A = S^1$.\n\\begin{example}[The long exact sequence for $(X,A) = (D^2, S^1)$]\n\tConsider $D^2$ (which is contractible) with boundary $S^1$.\n\tClearly $S^1$ is a deformation retraction of $D^2 \\setminus \\{0\\}$,\n\tand if we fuse all points on the boundary together we get $D^2 / S^1 \\cong S^2$.\n\tSo we have a long exact sequence\n\t\\begin{diagram}\n\t\t\\wt H_2(S^1) & \\rTo & \\underbrace{\\wt H_2(D^2)}_{=0} & \\rTo & \\wt H_2(S^2) \\\\\n\t\t&&& \\ldTo(4,2) & \\\\\n\t\t\\wt H_1(S^1) & \\rTo & \\underbrace{\\wt H_1(D^2)}_{=0} & \\rTo & \\wt H_1(S^2) \\\\\n\t\t&&& \\ldTo(4,2) & \\\\\n\t\t\\wt H_0(S^1) & \\rTo & \\underbrace{\\wt H_0(D^2)}_{=0} & \\rTo & \\underbrace{\\wt H_0(S^2)}_{=0}\n\t\\end{diagram}\n\tFrom this diagram we read that\n\t\\[\n\t\t\\dots, \\quad\n\t\t\\wt H_3(S^2) = \\wt H_2(S^1), \\quad\n\t\t\\wt H_2(S^2) = \\wt H_1(S^1), \\quad\n\t\t\\wt H_1(S^2) = \\wt H_0(S^1).\n\t\\]\n\\end{example}\nMore generally, the exact sequence for the pair $(X,A) = (D^m, S^{m-1})$\nshows that $\\wt H_n(S^m) \\cong \\wt H_{n-1}(S^{m-1})$,\nwhich is the desired conclusion.\n\n\\section{Invariance of dimension}\nHere is one last example of an application of excision.\n\\begin{definition}\n\tLet $X$ be a space and $p \\in X$ a point.\n\tThe $k$th \\vocab{local homology group} of $p$ at $X$ is defined as\n\t\\[ H_k(X, X \\setminus \\{p\\}). \\]\n\\end{definition}\nNote that for any open neighborhood $U$ of $p$, we have by excision that\n\\[ H_k(X, X \\setminus \\{p\\}) \\cong H_k(U, U \\setminus \\{p\\}). \\]\nThus this local homology group only depends on the space near $p$.\n\n\\begin{theorem}\n\t[Invariance of dimension, Brouwer 1910]\n\tLet $U \\subseteq \\RR^n$ and $V \\subseteq \\RR^m$ be nonempty open sets.\n\tIf $U$ and $V$ are homeomorphic, then $m = n$.\n\\end{theorem}\n\\begin{proof}\n\tConsider a point $x \\in U$ and its local homology groups. By excision,\n\t\\[ H_k(\\RR^n, \\RR^n \\setminus \\{x\\}) \\cong\n\t\tH_k(U, U \\setminus \\{x\\}). \\]\n\tBut since $\\RR^n \\setminus \\{x\\}$ is homotopic to $S^{n-1}$,\n\tthe long exact sequence of \\Cref{thm:long_exact_rel} tells us\n\tthat \n\t\\[\n\t\tH_k(\\RR^n, \\RR^n \\setminus \\{x\\}) \n\t\t\\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ & k = n \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\tAnalogously, given $y \\in V$ we have\n\t\\[ H_k(\\RR^m, \\RR^m \\setminus\\{y\\}) \\cong H_k(V, V\\setminus\\{y\\}). \\]\n\tIf $U \\cong V$, we thus\n\tdeduce that\n\t\\[ H_k(\\RR^n, \\RR^n\\setminus\\{x\\}) \\cong H_k(\\RR^m, \\RR^m\\setminus\\{y\\}) \\]\n\tfor all $k$.  This of course can only happen if $m=n$.\n\\end{proof}\n\n\\section\\problemhead\n\\begin{problem}\n\tLet $X = S^1 \\times S^1$ and $Y = S^1 \\vee S^1 \\vee S^2$.\n\tShow that \\[ H_n(X) \\cong H_n(Y) \\] for every integer $n$.\n\\end{problem}\n\n\\begin{problem}[Hatcher \\S2.1 exercise 18]\n\tConsider $\\QQ \\subset \\RR$.\n\tCompute $\\wt H_1(\\RR, \\QQ)$.\n\t\\begin{hint}\n\t\tUse \\Cref{thm:long_exact_rel}.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tWe have an exact sequence\n\t\t\\[\n\t\t\t\\underbrace{\\wt H_1(\\RR)}_{=0}\n\t\t\t\\to \\wt H_1(\\RR, \\QQ) \\to \\wt H_0(\\QQ) \\to \n\t\t\t\\underbrace{\\wt H_0(\\RR)}_{=0}.\n\t\t\\]\n\t\tNow, since $\\QQ$ is path-disconnected\n\t\t(i.e.\\ no two of its points are path-connected)\n\t\tit follows that $\\wt H_0(\\QQ)$ consists of\n\t\tcountably infinitely many copies of $\\ZZ$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{sproblem}\n\tWhat are the local homology groups of a topological $n$-manifold?\n\\end{sproblem}\n\n\\begin{problem}\n\tLet \\[ X = \\{(x,y) \\mid x \\ge 0\\} \\subseteq \\RR^2 \\]\n\tdenote the half-plane.\n\tWhat are the local homology groups of points in $X$?\n\t% http://math.stackexchange.com/questions/350667/local-homology-group-a-homeomorphism-takes-the-boundary-to-the-boundary\n\\end{problem}\n\n\\begin{problem}\n\t[Brouwer-Jordan separation theorem,\n\tgeneralizing Jordan curve theorem]\n\t\\yod\n\tLet $X \\subseteq \\RR^n$ be a subset\n\twhich is homeomorphic to $S^{n-1}$.\n\tProve that $\\RR^n \\setminus X$\n\thas exactly two path-connected components.\n\t\\begin{hint}\n\t\tFor any $n$, prove by induction for $k=1,\\dots,n-1$ that\n\t\t(a) if $X$ is a subset of $S^n$ homeomorphic to $D^k$\n\t\tthen $\\wt H_i(S^n \\setminus X) = 0$;\n\t\t(b) if $X$ is a subset of $S^n$ homeomorphic to $S^k$\n\t\tthen $\\wt H_i(S^n \\setminus X) = \\ZZ$ for $i=n-k-1$\n\t\tand $0$ otherwise.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThis is shown in detail in Section 2.B of Hatcher.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "05f6a17b42d49f72aaf6807d7ea4b179693ef5bf", "size": 13609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/homology/excision.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/excision.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/excision.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.719160105, "max_line_length": 121, "alphanum_fraction": 0.6551546771, "num_tokens": 5091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.6454793732657713}}
{"text": "%\\documentclass{book}\n%\\begin{document}\n\\chapter{Converting Coordinates \\& Time}\n\\section{Transformations}\n\nLet $\\mathbf{i}_{x}$, $\\mathbf{i}_{y}$, $\\mathbf{i}_{z}$ and $\\mathbf{i}_{\\varepsilon}$, $\\mathbf{i}_{\\eta}$, $\\mathbf{i}_{\\zeta}$ be two sets of orthogonal unit vectors\n\n\\[\\mathbf{i}_{\\xi}=l_{1}\\mathbf{i}_{x}+m_{1}\\mathbf{i}_{y}+n_{1}\\mathbf{i}_{z}\\]\n\\[\\mathbf{i}_{\\eta}=l_{2}\\mathbf{i}_{x}+m_{2}\\mathbf{i}_{y}+n_{2}\\mathbf{i}_{z}\\]\n\\[\\mathbf{i}_{\\zeta}=l_{3}\\mathbf{i}_{x}+m_{3}\\mathbf{i}_{y}+n_{3}\\mathbf{i}_{z}\\]\n\n\\[ \\left[ \\begin{array}{c} x \\\\ y \\\\ z  \\end{array} \\right] = \\mathbf{R}\\left[ \\begin{array}{c} \\varepsilon \\\\ \\eta \\\\ \\zeta  \\end{array} \\right] \\mbox{or}\n\\left[ \\begin{array}{c} \\varepsilon \\\\ \\eta \\\\ \\zeta  \\end{array} \\right] = \\mathbf{R^{T}}\\left[ \\begin{array}{c} x \\\\ y \\\\ z  \\end{array} \\right] \\]\n\n\\[\\mathbf{R}=\\left[ \\begin{array}{ccc}\n\\mathbf{i}_{x}\\mathbf{\\cdot}\\mathbf{i}_{\\varepsilon} & \\mathbf{i}_{x}\\mathbf{\\cdot}\\mathbf{i}_{\\eta} & \\mathbf{i}_{x}\\mathbf{\\cdot}\\mathbf{i}_{\\zeta} \\\\\n\\mathbf{i}_{y}\\mathbf{\\cdot}\\mathbf{i}_{\\varepsilon} & \\mathbf{i}_{y}\\mathbf{\\cdot}\\mathbf{i}_{\\eta} & \\mathbf{i}_{y}\\mathbf{\\cdot}\\mathbf{i}_{\\zeta} \\\\\n\\mathbf{i}_{z}\\mathbf{\\cdot}\\mathbf{i}_{\\varepsilon} & \\mathbf{i}_{z}\\mathbf{\\cdot}\\mathbf{i}_{\\eta} & \\mathbf{i}_{z}\\mathbf{\\cdot}\\mathbf{i}_{\\zeta}\n\\end{array} \\right] = \\left[ \\begin{array}{ccc}\nl_{1} & l_{2} & l_{3} \\\\\nm_{1} & m_{2} & m_{3} \\\\\nn_{1} & n_{2} & n_{3}\n\\end{array} \\right] \\]\n\n\\[ \\mathbf{R^{T}}=\\mathbf{R^{-1}} \\]\n\nEquations found  here~\\cite[pp. 81-82]{battin:imma}\n\n\\section{Time Systems}\n\\subsection{Solar \\& Sidereal Time}\nSince the  beginning time has been kept by counting the days. An apparent solar day is the minimum time elapsed between the sun crossing a specified meridian and then recrossing the same meridian. This form of time keeping is problematic because no two apparent solar days are of the same duration due to Earth's rotation around the sun as well as around its axis (the Earth does a little more than one rotation per apparent solar day). Also, Earth's rotational speed is not constant and its axis of rotation is tilted $23.5^{\\circ}$ to the orbital plane. These imperfections call for correction, and thus mean solar time was created. A day in mean solar time is defined as one revolution of a hypothetical sun that orbits at the equator, and is more commonly known as Greenwich Mean Time. Another solution is to base our day on the crossing of a star much farther away thus minimizing the effect of the Earth's orbital movement, this method of time keeping is known as sidereal time. A sidereal day is about 4 minutes shorter than a solar day, and is used heavily by astronomers. Sidereal time is not truly stable either so mean sidereal day was introduced, and is known as Greenwich Apparent Sidereal Time. Universal Time (UT) refers to any time scale based on the Earth's rotation. UT0 refers to the mean solar time at the prime meridian as obtained from astronomical observation, and UT1 is UT0 corrected for polar motion. Briefly ephemeris time was introduced to standardize the second, which was defined as 1/31556925.9747 of the year 1900. This was soon replaced by atomic time~\\cite[pp. 84-86]{me:gsmp}.\n\\subsection{Atomic Time}\nThe second is now defined by an atomic standard that is based on the resonance frequency of the cesium atom. To be precise, the second is defined as ``9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the cesium-133 atom,'' whose duration happens to exactly match the ephemeris second discussed in the previous section. The problem with detaching our time keeping method from the Earth is that as the Earth slows its rotation noon will move closer to midnight (over the duration of thousands of years, of course). Coordinated Universal Time (UTC) was introduced to prevent this. UTC is a compromise between the precision of atomic time and the groundedness of Earth based time keeping, it uses the atomic second but introduces leap seconds (positive or negative) when necessary to keep UTC within .9 seconds of UT1~\\cite[pp. 86-87]{me:gsmp}.\n\\subsection{Time Formats}\nWe are used to dealing with months, days, years, hours, minutes, and seconds, but such a time format makes for difficult epoch calculations over long periods. To solve this problem Julian Date (JD) was introduced. JD consists of a day count (days since noon UT on January $1^{\\mbox{st}}$ 4713 B.C.) and a fraction of the current day. This makes for easy time differencing, but the length of the date can become cumbersome and the fact that a new day starts at noon confusing. To make things even easier Modified Julian Date (MJD) was created whose origin is midnight November $17^{\\mbox{th}}$, 1858.\n\\[ \\mbox{MJD}=\\mbox{JD}-2400000.5\\]\n\nIn order to make Julian Date useful we need an easy way to go between calendar dates and JD. \\application{timeconvert}\\index{timeconvert!theory} does this and more with ease. The equations to convert from calendar date to JD are\n\\[ \\mbox{JD}=\\mbox{INT}[365.25y]+\\mbox{INT}[30.6001(m+1)]+D+\\mbox{UT}/24+1720981.5\\]\n\\[ \\begin{array}{lll}\ny=Y-1 & \\mbox{and}~m=M+12 & \\mbox{if}~M \\leq2 \\\\\ny=Y & \\mbox{and}~m=M & \\mbox{if}~M > 2\n\\end{array} \\]\nwhere $M$ is the month, $D$ is the day, $Y$ is the year, and INT[$x$] returns just the integer part of the number. To go from JD to calendar date\n\\[ a=\\mbox{INT[JD}+0.5] \\]\n\\[ b=a+1537 \\]\n\\[ c=\\mbox{INT}[(b-122.1)/365.25] \\]\n\\[ d=\\mbox{INT}[365.25c] \\]\n\\[ e=\\mbox{INT}[(b-d)/30.6001] \\]\n\\[ D=b-d-\\mbox{INT}[30.6001e]+\\mbox{FRAC[JD}+0.5] \\]\n\\[ M=e-1-12\\mbox{INT}[e/14] \\]\n\\[ Y=c-4715-\\mbox{INT}[(7+M)/10] \\]\nwhere FRAC[$x$] returns just the fractional part of a real number. MJD Conversion found here~\\cite[p. 88]{me:gsmp}. All other date conversions were found here~\\cite[pp. 36-37]{hlc:gtp}\n\\subsection{GPS Time}\nGPS Time (GPST) is a continuously running composite time kept by cesium and rubidium frequency standards aboard the satellites and at monitor stations. While there are no leap seconds in GPST as there are in UTC, it is steered to stay within 1 $\\mu$s of UTC, that is the difference between GPST and UTC is an integer number of seconds plus a fraction of a $\\mu$s. GPST is formatted in terms of GPS weeks and the number of seconds into the current week. Finding these values is done easily if the Julian Date is known.\n\\[ \\mbox{GPS WEEK}=\\mbox{INT[(JD}-2444244.5)/7] \\]\n\\[ \\mbox{SOW}=\\mbox{FRAC[(JD}-2444244.5)/7]\\times 604800 \\]\nwhere INT[$x$] returns the integer part of a real number, FRAC[$x$] returns the fractional part, and SOW stands for Second of Week.\n\nOther useful quantities such as Day of Week and  Second of Day can be found using \\application{timeconvert}\\index{timeconvert!theory} or the following equations.\n\\[\\mbox{DOW}=\\mbox{modulo\\{INT[JD}+0.5],7\\}\\]\n\\[\\mbox{SOD}=\\mbox{modulo\\{FRAC[JD}+0.5],7\\}\\times 86400\\]\nwhere DOW=0 corresponds to Monday, DOW=1 corresponds to Tuesday, and so on.\n\nJD and GPS Week equations were found here~\\cite[pp. 36-37]{hlc:gtp}, SOD derived from DOW equation.\n\\subsection{Z-Count}\nSatellites keep internal time with Z-count, whose epoch period is 1.5 seconds (a convenient unit for communications timing). The full Z-count is 29 bits, the 10 bit GPS week folloed by a 19 bit Time of Week (TOW) expressed in Z-counts (or 1.5 second units). The truncated Z-count has a 17 bit TOW that is expressed in units of 6 seconds, or the length of one subframe's transmission time. Simply multiply the truncated TOW by 4 to get the full TOW~\\cite[pp. 86-88]{tsui:fgpsr}.\n\\[ \\mbox{TOW}=\\mbox{FRAC[(JD}-2444244.5)/7]\\times 403200 \\]\n\\[ \\mbox{Truncated TOW}=\\mbox{FRAC[(JD}-2444244.5)/7]\\times 100800 \\]\nEquations derived from SOW equation above\n\\section{Earth Fixed Coordinates}\n\\subsection{ECI to ECF}\n\\[\\left[\\begin{array}{c} x \\\\ y \\\\ z \\end{array}\\right]_{ECF}=T_{XYZ}^{xyz}\\left[\\begin{array}{c} X \\\\ Y \\\\ Z \\\\ \\end{array}\\right]_{ECI}\\]\n\\[T_{XYZ}^{xyz}=WSNP\\]\n\nP - applies precession, from epoch 2000.0 to the current time;\nN - applies nutation, from epoch 2000.0 to the current time;\nS - applies rotation to account for true sidereal time;\nW - applies polar motion;\n\nEquations found on page 85 of Fundamentals of Orbit Determination paper book.\n\n\\subsection{WGS-84}\nThe World Geodetic System 1984 (WGS-84) is a fixed physical model of Earth produced by the Department of Defense to which many different reference frames can be attached. WGS-84 consists of two parts, a model of Earth's gravitational field, and an ellipsoid describing the Earth's general shape. When dealing with locations on the Earth's surface the ellipsoid provides the foundation for the geodetic coordinate system used by GPS. The ellipsoid's cross-sections parallel to the equatorial plane are circular while those orthogonal are elliptical. The ellipses are parameterized by an eccentricity $e$, a flattening $f$, and sometimes a second eccentricity $e'$\n\\[e=\\sqrt{1-\\frac{b^{2}}{a^{2}}}\\]\n\\[f=1-\\frac{b}{a}\\]\n\\[e'=\\sqrt{\\frac{a^{2}}{b^{2}}-1}=\\frac{a}{b}e\\]\nwhere $a$, the semimajor axis, is the value of the mean equatorial radius of Earth (6,378.137 km) and $b$, the semiminor axis, is the value of the polar radius of Earth (6,356.7523142 km) \\cite[pp. 25-26]{kaplan:ugpspa}.\n\\subsection{Coordinate Systems}\nNow that WGS-84 is defined it is important to understand what coordinate systems can be attached to the ellipsoid and how to move between these different systems. The GPS Toolkit comes with \\application{poscvt}\\index{poscvt!theory}, an application that gives users the ability to easily convert coordinates in one reference frame to another. The coordinate \nsystems that \\application{poscvt}\\index{poscvt!theory} recognizes are Cartesian (or XYZ), geodetic, geocentric, and spherical coordinates. These systems and the formulas to convert between them are discussed below.\n\\subsubsection{Cartesian (XYZ) Coordinates}\nThe Earth Centered Earth Fixed (ECEF) Cartesian coordinate system is fixed to the WGS-84 ellipsoid and is the common ground that makes going between the Earth Centered Inertial (ECI) reference frame used by the satellites and the systems we are used to (such as latitude, longitude, and height) manageable. The equatorial plane makes the $xy$-plane with the $+x$-axis pointing toward $0^{\\circ}$ longitude and the $+y$-axis pointing toward $90^{\\circ}$ E longitude. The $z$-axis is normal to the equatorial plane and points to the geographical north pole. The conversion formulas presented in the next sections will convert to and from this Cartesian reference frame, and so to convert between two non-Cartesian coordinate systems the XYZ system will be used as an intermediary~\\cite[p. 24]{kaplan:ugpspa}.\n\\subsubsection{Geodetic Coordinates}\nThe geodetic coordinate parameters are longitude $\\lambda$, latitude $\\phi$, and height $h$. Longitude is defined as the angle between the position and the $x$-axis in the equatorial plane, and is easily computed given a position in Cartesian coordinates. Let a user's position $\\mathbf{U}=(x_{u},y_{u},z_{u})$, then\n\\[ \\lambda = \\left \\{ \\begin{array}{ll}\n\\arctan \\left( \\frac{y_{u}}{x_{u}} \\right), & \\mbox{$x_{u} \\geq 0$} \\\\\n180^{\\circ} + \\arctan \\left( \\frac{y_{u}}{x_{u}} \\right), & \\mbox{$x_{u} < 0$ and $y_{u} \\geq 0$} \\\\\n-180^{\\circ} +\\arctan \\left( \\frac{y_{u}}{x_{u}} \\right), & \\mbox{$x_{u} < 0$ and $y_{u} < 0$}\n\\end{array}\n\\right. \\]\nwhere negative angles signal west longitude.\n\nLatitude and height are not so straight forward. Latitude is determined by drawing a vector normal to the ellipsoid, beginning somewhere on the equatorial plane and terminating at the users position, we will call this the user vector. The smallest angle between this vector and the equatorial plane is the user's latitude, it is a North latitude for positive angles and South for negative. Notice that unless the user is at a pole or on the equator the vector does not pass through the center of the Earth. The users height is found by taking the magnitude of the vector originating on and normal to the ellipsoid and terminating at the user's position. Latitude $\\phi$ and height $h$ are found using the following equations\n\\[ \\phi = \\arctan\\left(\\frac{z_{u}+e'^{2}z_{0}}{r}\\right) \\]\n\\[ h = U \\left(1-\\frac{b^{2}}{aV}\\right) \\]\n\nwhere\n\n\\[ r = \\sqrt{x_{u}^{2}+y_{u}^{2}} \\]\n\\[ E^{2} = a^{2} - b^{2} \\]\n\\[ F = 54 b^{2} z_{u}^{2} \\]\n\\[ G = r^{2} + (1-e^{2}) z_{u}^{2} - e^{2} E^{2} \\]\n\\[ c = \\frac{e^{4} F r^{2}}{G^{3}} \\]\n\\[ s = \\sqrt[3]{1+c+\\sqrt{c^{2} + 2c}}\\]\n\\[ P = \\frac{F}{3 \\left( s + \\frac{1}{s} + 1  \\right)^{2}G^{2} } \\]\n\\[ Q = \\sqrt{1+2e^{4}P} \\]\n\\[ r_{0} = -\\frac{Pe^{2}r}{1+Q}+\\sqrt{\\frac{1}{2}a^{2} \\left(1+\\frac{1}{Q}\\right)-\\frac{P(1-e^{2})z_{u}^{2}}{Q(1+Q)}-\\frac{1}{2}Pr^{2}}\\]\n\\[ U = \\sqrt{(r-e^{2}r_{0})^{2}+z_{u}^{2}}\\]\n\\[ V = \\sqrt{(r-e^{2}r_{0})^{2}+(1-e^{2})z_{u}^{2}} \\]\n\\[ z_{0} = \\frac{b^{2}z_{u}}{aV} \\]\n\n\n%\\[x=(N_{h}+h)\\cos\\phi'\\cos\\lambda\\]\n%\\[y=(N_{h}+h)\\cos\\phi'\\sin\\lambda\\]\n%\\[z=(N_{h}+h-\\tilde{e}^{2}N_{h})\\sin\\phi'\\]\n%\\[\\tilde{e}^{2}=\\tilde{f}(2-\\tilde{f})\\]\n%\\[N_{h}=\\frac{R_{e}}{(1-\\tilde{e}^{2}\\sin^{2}\\phi')^{1/2}}\\]\n%\\[\\tilde{f}=\\frac{R_{e}-R_{p}}{R_{e}}\\]\n%\\[x^{2}+y^{2}+\\left(\\frac{R_{e}}{R_{p}}\\right)^{2}z^{2}=R_{e}^{2}\\]\n\nGoing back to Cartesian coordinates from the geodetic system ($\\lambda$ $\\phi$ $h$) can be done more compactly\n\\[ \\mathbf{u} = \\left[  \\begin{array}{c}\n\\frac{a\\cos\\lambda}{\\sqrt{1+(1-e^2)\\tan^{2}\\phi}}+h\\cos\\lambda\\cos\\phi \\\\\n\\frac{a\\sin\\lambda}{\\sqrt{1+(1-e^2)\\tan^{2}\\phi}}+h\\sin\\lambda\\cos\\phi \\\\\n\\frac{a(1-e^{2})\\sin\\phi}{\\sqrt{1-e^{2}\\sin^{2}\\phi}}+h\\sin\\phi\n\\end{array}\n\\right] \\]\nwhere $\\mathbf{u}$ is the user's position vector~\\cite[pp. 26-28, p. 76]{kaplan:ugpspa,me:gsmp}.\n\n\\subsubsection{Geocentric Coordinates}\n\\[x=r\\cos\\phi\\cos\\lambda\\]\n\\[y=r\\cos\\phi\\sin\\lambda\\]\n\\[z=r\\sin\\phi\\]\n\nwhere $\\lambda$ and $\\phi$ are geocentric longitude and latitude\n\nfound on page 82 in the Fundamentals of Orbital Determination paper book\n\n%\\subsubsection{Spherical Coordinates}\n\n\\subsubsection{Topocentric Coordinates}\n\\[\\mathbf{r}_{t}=T_{t}(\\mathbf{r}-\\mathbf{r}_{s})=T_{t}\\rho\\]\n\n$\\mathbf{r}$ and $\\mathbf{r}_{s}$ are the position vectors of the observer and satellite respectively in the Earth-fixed system\n\n\\[T_{t}=\\left[ \\begin{array}{ccc}\n-\\sin\\lambda & \\cos\\lambda & 0 \\\\\n-\\sin\\phi\\cos\\lambda & -\\sin\\phi\\sin\\lambda & \\cos\\phi \\\\\n\\cos\\phi\\cos\\lambda & \\cos\\phi\\sin\\lambda & \\sin\\phi \\end{array} \\right] \\]\n\nwhere $\\lambda$ and $\\phi$ are geocentric longitude and latitude\n\nfound on page 84 in the Fundamentals of Orbital Determination paper book\n\nto find \\emph{azimuth} (Az) and \\emph{elivation} (El)\n\n\\[ \\begin{array}{ll}\n\\sin\\mbox{El}=\\frac{z_{t}}{r_{t}} & -90^{\\circ} \\leq \\mbox{El} \\leq 90^{\\circ} \\\\\n\\sin\\mbox{Az}=\\frac{x_{t}}{r_{xy}} & \\\\\n\\cos\\mbox{Az}=\\frac{y_{t}}{r_{xy}} & 0^{\\circ} \\leq \\mbox{Az} \\leq 360^{\\circ}\n\\end{array} \\]\n\nEquations found on pages 84-85 in  Fundamentals of Orbit Determination paper book\n\n\\putbib[gpstk]\n%\\end{document}\n", "meta": {"hexsha": "4b29afe2420813501b17ec4cc6370ca7b3d360a9", "size": 14998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3rdparty/GPSTk/ref/usersguide/convcoordtime.tex", "max_stars_repo_name": "mfkiwl/ICE", "max_stars_repo_head_hexsha": "e660d031bb1bcea664db1de4946fd8781be5b627", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2019-10-12T01:22:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T23:28:26.000Z", "max_issues_repo_path": "3rdparty/GPSTk/ref/usersguide/convcoordtime.tex", "max_issues_repo_name": "wuyou33/Enabling-Robust-State-Estimation-through-Measurement-Error-Covariance-Adaptation", "max_issues_repo_head_hexsha": "2f1ff054b7c5059da80bb3b2f80c05861a02cc36", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3rdparty/GPSTk/ref/usersguide/convcoordtime.tex", "max_forks_repo_name": "wuyou33/Enabling-Robust-State-Estimation-through-Measurement-Error-Covariance-Adaptation", "max_forks_repo_head_hexsha": "2f1ff054b7c5059da80bb3b2f80c05861a02cc36", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2019-11-05T01:50:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-06T06:23:44.000Z", "avg_line_length": 84.2584269663, "max_line_length": 1611, "alphanum_fraction": 0.7067609015, "num_tokens": 4885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6453672664466575}}
{"text": "\\chapter{The Theory of \\\\ Automatic Differentiation}\n\nAutomatic differentiation is a powerful computation tool for the exact, at least up to \narithmetic precision, evaluation of linear differential operators on the elaborate, \ncomposite functions common to practical applications.  In particular, automatic \ndifferentiation techniques factor a linear differential operator into analytic calculations, \nwhich can be explicitly implemented, from the algebraic manipulations that can be \nprogrammatically automated.\n\nIn this chapter we review the theory behind linear differential operators, dual numbers,\nand, ultimately, automatic differentiation.  We begin by considering differential operators\nin a formal setting, in particular the spaces on which they act, before introducing dual\nnumbers and showing how they compliment these operators.  Last we integrate both\nperspectives into automatic differentiation and its implementation.\n\n\\section{Linear Differential Operators}\n\nWhen considering a one-dimensional function, $f : \\mathbb{R} \\rightarrow \\mathbb{R}$, \na common notion is that the derivative defines a ``best'' linear approximation\nto the function in a neighborhood around any point, $x_{0} \\in \\mathbb{R}$,\n%\n\\begin{equation*}\nf \\! \\left( x \\right) - f \\! \\left( x_{0} \\right)\n\\approx \\frac{ \\mathrm{d} f }{ \\mathrm{d} x } \\! \\left( x_{0} \\right) \\left( x - x_{0} \\right).\n\\end{equation*}\n%\nA more revealing interpretation, however, arises when we consider\n$\\delta x = x - x_{0}$ and $\\delta f = f \\! \\left( x \\right) - f \\! \\left( x_{0} \\right)$ as\nperturbations, in which case the derivative is just a linear map that propagates\nan input perturbation into an output perturbation,\n%\n\\begin{equation*}\n\\delta f = \\frac{ \\mathrm{d} f }{ \\mathrm{d} x } \\! \\left( x_{0} \\right) \\delta x.\n\\end{equation*}\n\nLinear differential operators formalize this intuition of propagating perturbations\nthrough functions.  Any formal treatment, however, first requires a much more\ncareful definition of perturbations, especially for multivariate functions.  In this\nsection we review the necessary theory of first-order linear differential operators\nand then briefly discuss the generalization to higher-order operations.\n\n\\subsection{First-Order Linear Differential Operators}\n\nFirst-order linear differential operators generalize the one-dimensional construction\nabove.  The most significant complication is that, in general, there are actually two \nkinds of first-order perturbations: \\textit{tangents} and \\textit{sensitivities}.\n\n\\subsubsection{Tangents}\n\nA defining property of perturbations is that they can be added together and scaled,\nin other words they form a vector space.  Given the real space $\\mathbb{R}^{N}$,\nthe $N$-dimensional vector space of perturbations at every point, $x \\in \\mathbb{R}^{N}$, \nis called the \\textit{tangent space} and denoted $T_{x} \\mathbb{R}^{N}$.  The notation\ncomes from interpreting first-order perturbations as tangent vectors of curves\npassing through $x$.\n\nConsequently, given a smooth function $f : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}^{M}$\na first-order linear differential operator is a linear map from the tangent space of\nthe input to the tangent space of the output,\n%\n\\begin{equation*}\nD : T_{x} \\mathbb{R}^{N} \\rightarrow T_{ f ( x ) } \\mathbb{R}^{M}.\n\\end{equation*}\n%\nTaking the standard bases in both tangent spaces, we can identify any tangent,\n$\\delta x \\in T_{x} \\mathbb{R}^{N}$, by its components, $\\delta x_{n}$.  In this case\nthe operator $D$ is equivalent to an $m \\times n$ matrix,\n%\n\\begin{equation*}\n\\delta f_{m} = \\sum_{n = 1}^{N} D_{mn} \\, \\delta x_{n} \\in T_{f(x)} \\mathbb{R}^{M}.\n\\end{equation*}\n\nOne particularly important first-order linear differential operator is the \\textit{pushforward}\nor \\textit{tangent map} canonically defined for any function,\n%\n\\begin{equation*}\nf_{*} : T_{x} \\mathbb{R}^{N} \\rightarrow T_{ f ( x ) } \\mathbb{R}^{M}.\n\\end{equation*}\n%\nIn components the pushforward is given exactly by the Jacobian matrix of partial derivatives,\n%\n\\begin{equation*}\n\\left( f_{*} \\right)_{mn} = \\frac{ \\partial f_{m} }{ \\partial x_{n} }.\n\\end{equation*}\n\nPushforwards behave well under function composition.  Given two functions,\n$f : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}^{L}$ and\n$g : \\mathbb{R}^{L} \\rightarrow \\mathbb{R}^{M}$, the pushforward of their compositions\nis simply\n%\n\\begin{equation*}\n\\left( g \\circ f \\right)_{*} = g_{*} \\cdot f_{*},\n\\end{equation*}\n%\nor, in components,\n%\n\\begin{align*}\n\\left( \\left( g \\circ f \\right)_{*} \\right)_{mn} &= \n\\sum_{l = 1}^{L} \\left( g_{*} \\right)_{ml} \\left( f_{*} \\right)_{ln}\n\\\\\n\\frac{ \\partial g_{m} }{ \\partial x_{n} } &= \n\\sum_{l = 1}^{L} \\frac{ \\partial g_{m} }{ \\partial f_{l} } \\cdot \\frac{ \\partial f_{l} }{ \\partial x_{n} },\n\\end{align*}\n%\nwhich is just the chain rule.  Because of this behavior, the pushforward of a\ncomposite function is straightforward computationally, provided that the pushforwards\nof each component function are known.  In particular, using the standard basis the\ncomposition pushforward is given simply by a succession of vector-matrix products.\n\n\\subsubsection{Sensitivities}\n\nAn immediate consequence of this more formal perspective is the introduction of a second\nkind of first-order perturbation.  The space of linear operators acting on tangents,\n%\n\\begin{equation*}\n\\alpha : T_{x} \\mathbb{R}^{N} \\rightarrow \\mathbb{R},\n\\end{equation*}\n%\nis itself a vector space, known as the \\textit{cotangent space} and denoted \n$T^{*}_{x} \\mathbb{R}^{N}$.  Composing these maps with a first-order linear differential \noperator assigns a value to each tangent,\n%\n\\begin{equation*}\n\\alpha \\circ D : T_{x} \\mathbb{R}^{N} \\rightarrow \\mathbb{R},\n\\end{equation*}\n%\nin some sense quantifying how sensitive the underlying function is to a given \nperturbation.  Consequently elements of the cotangent space are often known as\n\\textit{sensitivities} and provide dual perturbation to the tangents.\n\nAny first-order linear differential operator,\n$D : T_{x} \\mathbb{R}^{N} \\rightarrow T_{ f ( x ) } \\mathbb{R}^{M}$, acting on\nthe tangent spaces canonically defines an \\textit{adjoint operator} that acts on the \ncotangent spaces,\n%\n\\begin{equation*}\nD^{*} : T^{*}_{f (x) } \\mathbb{R}^{M} \\rightarrow T^{*}_{x} \\mathbb{R}^{N}.\n\\end{equation*}\n%\nThe matrix representation of the adjoint operator is, perhaps unsurprisingly, \nsimply the adjoint of the matrix representation of the original operator,\n%\n\\begin{equation*}\n\\mathrm{d} x_{n} = \\sum_{m = 1}^{M} D_{nm} \\mathrm{d} f_{m},\n\\end{equation*}\n%\nwhere $\\mathrm{d} x \\in T^{*}_{x} \\mathbb{R}^{N}$ and\n$\\mathrm{d} f \\in T^{*}_{x} \\mathbb{R}^{M}$.\n\nThe adjoint of the pushforward is known as the \\textit{pullback},\n%\n\\begin{equation*}\nf^{*} : T^{*}_{f (x) } \\mathbb{R}^{M} \\rightarrow T^{*}_{x} \\mathbb{R}^{N}.\n\\end{equation*}\n%\nUnder the composition,\n%\n\\begin{equation*}\n\\left( g \\circ f \\right)^{*} = f^{*} \\cdot g^{*}\n\\end{equation*}\n%\nor, in components,\n%\n\\begin{equation*}\n\\left( \\left( g \\circ f \\right)^{*} \\right)_{mn} = \n\\sum_{l = 1}^{L} \\left( g^{*} \\right)_{ml} \\left( f^{*} \\right)_{ln}.\n\\end{equation*}\n%\nComputing the input sensitivities corresponding to the output sensitivities then reduces\nto vector-matrix products moving backwards, against the flow of the function evaluation.\n\n\\subsection{Higher-Order Linear Differential Operators}\n\nUnfortunately, a theory of higher-order perturbations, and the corresponding\nlinear differential operators, is substantially more complicated, requiring an elegant but\nabstract construction known as \\textit{jet spaces} to generalize the tangent space.  \nFor example, a second-order linear differential operator does simply map second-order \ntangents to second-order tangents but also requires \\textit{two} first-order tangents,\n%\n \\begin{equation*}\n\\delta^{2} f_{m} \n= \\sum_{n = 1}^{N} \\frac{ \\partial f_{m} }{ \\partial x_{n} } \\delta^{2} x_{n} \n+ \\sum_{n = 1}^{N} \\sum_{n' = 1}^{N} \n\\frac{ \\partial^{2} f_{m} }{ \\partial x_{n} \\partial x_{n'} } \n\\delta x_{n} \\delta x_{n'}.\n\\end{equation*}\n%\nMoreover, adjoint operators do not immediately generalize -- at higher-orders adjoint\nmaps require the interaction of tangents and sensitivities.\n\nFortunately we do not have to consider these higher-order jet spaces directly\nbecause the introduction of \\textit{dual numbers} provides an alternative means\nof computing how higher-order perturbations propagate across a function.\n\n\\section{Dual Numbers}\n\nDual numbers are a generalization of real numbers that naturally unify the\naction of a function, its pushforward, and, with some care, its pullback;\nconsequently they are the ideal basis for implementing automatic differentiation. \nIn this section we derive first-order dual numbers and then consider the construction \nof higher-order dual numbers and higher-order linear differential operators.\n\n\\subsection{First-Order Dual Numbers}\n\nDual numbers extend the real numbers, $\\mathbb{R}$, with the\naddition of a new element, $\\mathfrak{a}$, which is nilpotent, $\\mathfrak{a}^{2} = 0$,\nand denoted a \\textit{dual unit}.\n\nThis extended space of dual numbers forms a two-dimensional associative algebra \nover $\\mathbb{R}$.  In other words, the addition of the dual unit generates a two-dimensional\nspace, $\\mathbb{D}$, comprised of elements,\n%\n\\begin{equation*}\n\\xi = x + \\mathfrak{a} \\, \\delta x; \\, \\xi \\in \\mathbb{D}, \\, x, \\delta x \\in \\mathbb{R},\n\\end{equation*}\n%\nthat are naturally equipped with associative addition and multiplication operations,\n%\n\\begin{align*}\n\\xi_{1} + \\xi_{2} \n&=\n \\left( x_{1} + \\mathfrak{a} \\, \\delta x_{1} \\right) \n + \\left( x_{2} + \\mathfrak{a} \\,  \\delta x_{2} \\right) \n\\\\\n&=\n\\left( x_{1} + x_{2} \\right) \n+ \\mathfrak{a} \\left( \\delta x_{1} + \\delta x_{2} \\right) \n\\\\\n\\xi_{1} \\cdot \\xi_{2} \n&= \n\\left( x_{1} + \\mathfrak{a} \\, \\delta x_{1} \\right) \n\\cdot \\left( x_{2} + \\mathfrak{a} \\, \\delta x_{2} \\right) \n\\\\\n&= \nx_{1} x_{2} + \\left( x_{1} \\delta x_{2} \n+ \\delta x_{1} x_{2} \\right) \\mathfrak{a} \n+ \\delta x_{1} \\delta x_{2} \\, \\mathfrak{a}^{2} \n\\\\\n&= \nx_{1} x_{2} + \\left( x_{1} \\delta x_{2} + \\delta x_{1} x_{2} \\right) \\mathfrak{a}.\n\\end{align*}  \n\nAny smooth function $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ induces a function on \ndual numbers, $f : \\mathbb{D} \\rightarrow \\mathbb{D}$, via a Taylor series around any \npurely real point, $\\xi_{0} = x_{0} + \\mathfrak{a} \\, 0$,\n%\n\\begin{align*}\nf \\! \\left( \\xi \\right) \n&= \n\\sum_{n = 0}^{\\infty} \\frac{ \\left( \\xi - \\xi_{0} \\right)^{n} }{n!} \n\\frac{ \\partial^{n} f }{ \\partial \\xi^{n} } \\! \\left( \\xi_{0} \\right) \n\\\\\n&= \n\\sum_{n = 0}^{\\infty} \\frac{ \\left( \\left( x - x_{0} \\right) + \\mathfrak{a} \\, \\delta x \\right)^{n} }{n!} \n\\frac{ \\partial^{n} f }{ \\partial x^{n} } \\! \\left( x_{0} \\right)\n\\\\\n&= \n\\sum_{n = 0}^{\\infty} \\frac{ \\left( x - x_{0} \\right)^{n} }{n!} \n\\frac{ \\partial^{n} f }{ \\partial x^{n} } \\! \\left( x_{0} \\right)\n+ \\mathfrak{a} \\, \\delta x \\sum_{n = 0}^{\\infty} \\frac{ \\left( x - x_{0} \\right)^{n - 1} }{\\left( n - 1 \\right)!} \n\\frac{ \\partial^{n} f }{ \\partial x^{n} } \\! \\left( x_{0} \\right) \n\\\\\n&= \nf \\! \\left( x \\right) \n+ \\mathfrak{a} \\, \\delta x \\frac{ \\partial f }{ \\partial x } \\! \\left( x \\right).\n\\end{align*}\n\nGeneralizing to multivariate functions is straightforward: any function \n$f : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}^{M}$ is first decomposed into $M$\nfunctions, $f_{m} : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}$, which extend\nto dual numbers as\n%\n\\begin{equation} \\label{dual_function}\nf_{m} \\! \\left( \\mbox{\\boldmath{$\\xi$}} \\right) = f_{m} \\! \\left( \\mathbf{x} \\right) \n+ \\mathfrak{a} \\sum_{n = 1}^{N} \n\\delta x_{n} \\frac{ \\partial f_{m} }{ \\partial x_{n} } \\! \\left( \\mathbf{x} \\right).\n\\end{equation}\n%\nIf we consider the dual component as identifying an element of the tangent\nspace, then the dual part of the extended function is exactly the pushforward \nof the original function.  \n\nSimilarly, we can interpret the dual component as a sensitivity.  In this case\nthe action of a function on the dual number is given by the adjoint action of the\npushforward,\n%\n\\begin{equation} \\label{dual_function}\n\\xi_{n}  = x_{n}  + \\mathfrak{a} \\sum_{m = 1}^{M} \n\\delta f_{m} \\frac{ \\partial f_{m} }{ \\partial x_{n} } \\! \\left( \\mathbf{x} \\right).\n\\end{equation} \n\nBecause dual numbers inherently integrate a function with its pushforward or\npullback, they are the natural type from which we can implement linear\ndifferential operators and, consequently, automatic differentiation.\n\n\\subsection{Higher-Order Dual Numbers}\n\nThe naturalness of dual numbers also generalizes to higher-order perturbations\nwith the introduction of multiple dual units, providing an means of computing\nhigher-order linear differential operators without having to introduce the mathematical\nmachinery of jet spaces.\n\nAt first-order, the real and dual parts of a first-order dual number are real numbers,\n%\n\\begin{equation*}\n\\zeta = z + \\mathfrak{a} \\, \\delta z, \\, z, \\delta z \\in \\mathbb{R}.\n\\end{equation*}\n%\nIf we introduce a second dual unit, $\\mathfrak{b}$, then we can construct a second-order \ndual number by replacing the real-valued parts of $\\zeta$ with dual numbers,\n%\n\\begin{alignat*}{3}\n\\zeta\n&=\n\\;\\, \\xi\n&&+ \\mathfrak{a} \\;\\;\\, \\eta\n\\\\\n&=\n\\left( x + \\mathfrak{b} \\, \\delta x \\right)\n&&+ \\mathfrak{a} \\left( \\delta y + \\mathfrak{b} \\, \\delta^{2} y \\right), \n\\, x, \\delta x, \\delta y, \\delta^{2} y \\in \\mathbb{R}.\n\\end{alignat*}\n%\nFrom the linear differential operator perspective, $x$ is a the value, $\\delta x$ and \n$\\delta y$ are first-order perturbations, and $\\delta^{2} y$ is a second-order perturbation.\nHigher-order dual numbers follow recursively with the introduction of a new dual unit\nand the replacement of real-valued components with new dual numbers.  An $n$-th \norder dual number, for example, is constructed from $n$ distinct dual units and\n$2^{n}$ real components.\n\nWhen constructing higher-order linear differential operators, these components may \nbe considered as both higher-order tangents and higher-order sensitivities. Consequently \nit's convenient to define notation agnostic to the specific map being considered.\nWe will refer to the components of each bottem-level dual number as \\textit{values} and\n\\textit{gradients}; for example, at second-order $x$ would be a first-order value, $\\delta x$ \na first-order gradient, $\\delta y$ a second-order value, and $\\delta^{2} y$ as the second-order \ngradient.\n\nExtending functions to higher-order dual numbers, and constructing higher-order\nlinear differential operators in the process, also proceeds recursively.  Here we\nexplicitly evaluate the extension to second and third-order dual numbers.\n\n\\subsubsection{Second-Order}\n\nGiven the second-order dual number,\n%\n\\begin{alignat*}{3}\n\\zeta_{i} \n&=\n\\xi_{i} \n&&+ \\mathfrak{a} \\, \\eta_{i}\n\\\\\n&=\n\\left( x_{i} + \\mathfrak{b} \\, \\delta x_{i} \\right)\n&&+ \\mathfrak{a} \\left( \\delta y_{i} + \\mathfrak{b} \\, \\delta^{2} y_{i} \\right),\n\\end{alignat*}\n%\na second-order dual number valued-function, evaluates to\n%\n\\begin{align*}\nf_{i} \\! \\left(  \\mbox{\\boldmath{$\\zeta$}} \\right)\n=& \\,\nf_{i} \\! \\left(  \\mbox{\\boldmath{$\\xi$}} \\right) \n+ \\mathfrak{a} \\sum_{j} \\eta_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left(  \\mbox{\\boldmath{$\\xi$}} \\right) \n\\\\\n=& \\,\nf_{i} \\! \\left( \\mathbf{x} + \\mathfrak{b} \\, \\delta \\mathbf{x} \\right) \n+ \\mathfrak{a} \\sum_{j} \\left( \\delta y_{j} + \\mathfrak{b} \\, \\delta^{2} y_{j} \\right)\n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \n\\! \\left( \\mathbf{x} + \\mathfrak{b} \\, \\delta \\mathbf{x} \\right) \n\\\\\n=& \\,\nf_{i} \\! \\left( \\mathbf{x} \\right) \n+ \\mathfrak{b} \\sum_{j} \\delta x_{j}  \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j} \\left( \\delta y_{j} + \\mathfrak{b} \\, \\delta^{2} y_{j} \\right)\n\\left( \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x}\\right) + \n\\mathfrak{b} \\, \\sum_{k} \\delta x_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{x} \\right) \\right) \n\\\\\n=&\n\\quad\\quad\\quad \nf_{i} \\! \\left( \\mathbf{x} \\right) \n\\quad\\quad\\quad\\;\\;\\;\n+ \\mathfrak{b} \\;\\;\\;\n\\sum_{j} \\delta x_{j}  \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\left( \n\\sum_{j} \\delta y_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right) \n+ \\mathfrak{b} \\left(\n\\sum_{j} \\delta^{2} y_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)\n+ \\sum_{jk} \\delta x_{k} \\, \\delta y_{j}\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{x} \\right)\n\\right)\n\\right)\n\\end{align*}\n%\nThese results are summarized in Table \\ref{tab:secondOrder}.\n\n\\begin{table*}[t!]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{2}\n\t\\begin{tabular}{ccc}\n\t\\rowcolor[gray]{0.9} \\textbf{Component} & \\textbf{Input} & \\textbf{Output} \\\\\n\tFirst Value & \n\t$\\mathbf{x}$ & \n\t$f_{i} \\! \\left( \\mathbf{x} \\right)$ \n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\tFirst Gradient & \n\t$\\delta \\mathbf{x}$ &\n\t$\\displaystyle \\sum_{j} \\delta x_{j}  \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)$\n\t\\\\\n\tSecond Value & \n\t$\\delta \\mathbf{y} $ & \n\t$\\displaystyle \\sum_{j} \\delta y_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)$\n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\tSecond Gradient & \n\t$\\delta^{2} \\mathbf{y} $ & \n\t$\\displaystyle \\sum_{j} \\delta^{2} y_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{x} \\right)\n\t+ \\sum_{jk} \\delta x_{k} \\, \\delta y_{j}\n\t\\frac{ \\partial f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{x} \\right)$\n\t\\\\\n\t\\end{tabular}\n\t\\caption{Recursively expanding a function with respect to a second-order dual number \n\tgives each component of the function's second-order pushforward.\n\t\\label{tab:secondOrder}}\n\\end{table*}\n\nConsidering the first-order gradient, second-order value, and second-order gradient as tangents \nimmediately defines two first-order linear differential operators and one second-order linear \ndifferential operator.  Unfortunately the same is not true if we try to consider all three components\nas sensitivities, as the second term in the second-order gradient map no longer makes\nsense.  \n\nThe generalization of an adjoint map does not consider all components as sensitivities but rather\nconsiders all $k$th-order values as $(k - 1)$-order tangents (with a $0$-order tangent\ntaken to be an input value) and all $k$th-order gradients as $k$th-order sensitivities.  Once the partial\nderivatives are contracted against the tangents they can be transposed to give the\ncomponents of the pullback map.  For example, given our usual test function \n$f : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}^{M}$ with the perturbations \n$\\delta y \\rightarrow \\mathrm{d} f$ and $\\delta^{2} y \\rightarrow \\mathrm{d}^{2} f$, the \nsecond-order pullback is given by\n%\n\\begin{equation*}\n\\mathrm{d}^{2} x_{n}\n= \\sum_{m = 1}^{M} \\mathrm{d}^{2} f_{m} \\frac{ \\partial f_{m} }{ \\partial x_{n} }\n+ \\sum_{m = 1}^{M} \\mathrm{d} f_{m} \n\\left[ \\sum_{n'=1}^{N} \\delta x_{n'} \\frac{ \\partial^{2} f_{m} }{ \\partial x_{n'} \\partial x_{n} } \\right].\n\\end{equation*}\n\n\\subsubsection{Third-Order}\n\nContinuing to third-order follows in kind.  Given a third-order dual number,\n%\n\\begin{alignat*}{10}\n\\zeta_{i} \n&=\n&& \\xi_{i} && && &&\n&&+ \\mathfrak{a} \\, \n&& \\eta_{i} && && &&\n\\\\\n&=\n( && \\sigma_{i} && + \\mathfrak{b} && \\tau_{i} &&)\n&&+ \\mathfrak{a} \\,\n( && \\upsilon_{i} && + \\mathfrak{b} && \\nu_{i} && )\n\\\\\n&=\n(( && s_{i} + \\mathfrak{c} \\, \\delta s_{i} )\n&& + \\mathfrak{b} \\;\n( && \\delta t_{i} + \\mathfrak{c} \\, \\delta^{2} t_{i}  ) &&)\n&&+ \\mathfrak{a} \\;\n(( && \\delta u_{i} + \\mathfrak{c} \\, \\delta^{2} u_{i} )\n&& + \\mathfrak{b} \\;\n( && \\delta^{2} v_{i} + \\mathfrak{c} \\, \\delta^{3} v_{i} ) &&)\n\\end{alignat*}\n%\nwe have\n%\n\\begin{align*}\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\zeta$}} \\right)\n%\n=& \\,\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\xi$}}\\right) \n+ \\mathfrak{a} \\sum_{j} \\eta_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mbox{\\boldmath{$\\xi$}} \\right) \n\\\\\n%\n=& \\,\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\sigma$}} + \\mathfrak{b} \\, \\mbox{\\boldmath{$\\tau$}} \\right) \n+ \\mathfrak{a} \\sum_{j} \\left( \\upsilon_{j} + \\mathfrak{b} \\, \\nu_{j} \\right)\n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \n\\! \\left( \\mbox{\\boldmath{$\\sigma$}} + \\mathfrak{b} \\, \\mbox{\\boldmath{$\\tau$}} \\right) \n\\\\\n%\n=& \\,\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right) + \\mathfrak{b} \n\\sum_{j} \\tau_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \n\\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n+ \\mathfrak{a} \\sum_{j} \\left( \\upsilon_{j} + \\mathfrak{b} \\, \\nu_{j} \\right)\n\\left( \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n+ \\mathfrak{b} \\sum_{k} \\tau_{k}\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right) \\right) \n\\\\\n%\n=& \\,\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right) + \\mathfrak{b} \n\\sum_{j} \\tau_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \n\\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n+ \\mathfrak{a} \\sum_{j}\n\\upsilon_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n\\\\\n& + \\mathfrak{a} \\, \\mathfrak{b} \\sum_{j}\n \\nu_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\sum_{jk} \\upsilon_{j} \\tau_{k}\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mbox{\\boldmath{$\\sigma$}} \\right)\n\\\\\n%\n=& \\,\nf_{i} \\! \\left( \\mathbf{s} + \\mathfrak{c} \\, \\delta \\mathbf{s} \\right) + \\mathfrak{b} \n\\sum_{j} \\left( \\delta t_{j} + \\mathfrak{c} \\, \\delta^{2} t_{j} \\right) \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} + \\mathfrak{c} \\, \\delta \\mathbf{s}\\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j}\n\\left( \\delta u_{j} + \\mathfrak{c} \\, \\delta^{2} u_{j} \\right) \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} + \\mathfrak{c} \\, \\delta \\mathbf{s}\\right)\n\\\\\n& + \\mathfrak{a} \\, \\mathfrak{b} \\sum_{j}\n\\left( \\delta^{2} v_{j} + \\mathfrak{c} \\, \\delta^{3} v_{j} \\right) \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} + \\mathfrak{c} \\, \\delta \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\, \\sum_{jk} \n\\left( \\delta u_{j} + \\mathfrak{c} \\, \\delta^{2} u_{j} \\right) \n\\left( \\delta t_{k} + \\mathfrak{c} \\, \\delta^{2} t_{k} \\right)\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} + \\mathfrak{c} \\, \\delta \\mathbf{s} \\right)\n\\\\\n%\n=& \\,\nf_{i} \\! \\left( \\mathbf{s} \\right) + \\mathfrak{c} \\sum_{j} \\delta s_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{b}\n\\sum_{j} \\left( \\delta t_{j} + \\mathfrak{c} \\, \\delta^{2} t_{j} \\right) \n\\left( \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+  \\mathfrak{c} \\sum_{k} \\delta s_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j}\n\\left( \\delta u_{j} + \\mathfrak{c} \\, \\delta^{2} u_{j} \\right) \n\\left( \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{c} \\sum_{k} \\delta s_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \\right)\n\\\\\n& + \\mathfrak{a} \\, \\mathfrak{b} \\sum_{j}\n\\left( \\delta^{2} v_{j} + \\mathfrak{c} \\, \\delta^{3} v_{j} \\right) \n\\left( \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{c} \\sum_{k} \\delta s_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\, \\sum_{jk} \n\\left( \\delta u_{j} + \\mathfrak{c} \\, \\delta^{2} u_{j} \\right) \n\\left( \\delta t_{k} + \\mathfrak{c} \\, \\delta^{2} t_{k} \\right)\n\\\\\n& \\quad\\quad\\quad\\quad \\times \\left(\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{c} \\sum_{l} \\delta s_{l} \n\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right)\n\\right)\n\\\\\n%\n\\end{align*}\n\n\\begin{align*}\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\zeta$}} \\right)\n%\n=& \\,\nf_{i} \\! \\left( s_{j} \\right) + \\mathfrak{c} \\sum_{j} \\delta s_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{b} \\sum_{j} \\delta t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} t_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta t_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j} \\delta u_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} u_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta u_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\sum_{j} \\delta^{2} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{3} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta^{2} v_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\, \\sum_{jk} \n\\left( \\delta u_{j} \\delta t_{k}\n+ \\mathfrak{c} \\left(\n\\delta u_{j} \\, \\delta^{2} t_{k} + \\delta^{2} u_{j} \\, \\delta t_{k} \n\\right) \\right)\n\\\\\n& \\quad\\quad\\quad\\quad \\times \\left(\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{c} \\sum_{l} \\delta s_{l} \n\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right)\n\\right)\n\\\\\n%\n=& \\,\nf_{i} \\! \\left( s_{j} \\right) + \\mathfrak{c} \\sum_{j} \\delta s_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{b} \\sum_{j} \\delta t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} t_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta t_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j} \\delta u_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} u_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta u_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\sum_{j} \\delta^{2} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{3} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta^{2} v_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \\, \\sum_{jk} \n\\delta u_{j} \\delta t_{k} \\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk}\n\\left( \\delta u_{j} \\, \\delta^{2} t_{k} + \\delta^{2} u_{j} \\, \\delta t_{k}  \\right)\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \n\\\\\n&+\n\\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jkl}\n\\delta u_{j} \\delta t_{k} \\, \\delta s_{l} \n\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n%\n\\end{align*}\n\n\\begin{align*}\nf_{i} \\! \\left( \\mbox{\\boldmath{$\\zeta$}} \\right)\n%\n=& \\,\nf_{i} \\! \\left( s_{j} \\right) + \\mathfrak{c} \\sum_{j} \\delta s_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{b} \\sum_{j} \\delta t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} t_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta t_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\sum_{j} \\delta u_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{j} \\delta^{2} u_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\mathfrak{a} \\, \\mathfrak{c} \\sum_{jk} \\delta s_{k} \\, \\delta u_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n&+ \n\\mathfrak{a} \\, \\mathfrak{b} \n\\left( \n\\sum_{j} \\delta^{2} v_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\delta u_{j} \\delta t_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\right)\n\\\\\n&+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{j} \\delta^{3} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n\\\\\n&+ \\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jk}\n\\left( \n\\delta s_{k} \\, \\delta^{2} v_{j} + \\delta u_{j} \\, \\delta^{2} t_{k} + \\delta^{2} u_{j} \\, \\delta t_{k}  \\right)\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \n\\\\\n&+\n\\mathfrak{a} \\, \\mathfrak{b} \\, \\mathfrak{c} \\sum_{jkl}\n\\delta u_{j} \\delta t_{k} \\, \\delta s_{l} \n\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n%\n=& \\hspace{26mm} \nf_{i} \\! \\left( \\mathbf{s} \\right) \n\\hspace{9mm}\n+ \\mathfrak{c} \n\\hspace{3mm}\n\\sum_{j} \\delta s_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n& \\hspace{8mm} + \n\\mathfrak{b} \\left( \\sum_{j} \\delta t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\hspace{1mm}\n+ \\mathfrak{c} \\left( \n\\sum_{j} \\delta^{2} t_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\sum_{jk} \\delta s_{k} \\, \\delta t_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \\right) \\right)\n\\\\\n&+ \n\\mathfrak{a} \\Bigg( \n\\hspace{9mm}\n\\sum_{j} \\delta u_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n+ \\mathfrak{c} \\left( \\sum_{j} \\delta^{2} u_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n+ \\sum_{jk} \\delta s_{k} \\, \\delta u_{j} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \\right)\n\\\\\n& \n\\hspace{8mm} \n+ \\mathfrak{b} \\Bigg(\n\\hspace{0.5mm}\n\\sum_{j} \\delta^{2} v_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\\delta u_{j} \\delta t_{k} \n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)\n\\\\\n& \\hspace{34mm} \n+ \\mathfrak{c} \\Bigg(\n\\sum_{j} \\delta^{3} v_{j} \n\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n\\\\\n& \\hspace{40mm} \n+ \\sum_{jk}\n\\left( \n\\delta s_{k} \\, \\delta^{2} v_{j} + \\delta u_{j} \\, \\delta^{2} t_{k} + \\delta^{2} u_{j} \\, \\delta t_{k}  \\right)\n\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) \n\\\\\n& \\hspace{40mm} +\n\\sum_{jkl}\n\\delta u_{j} \\delta t_{k} \\, \\delta s_{l} \n\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right) \n\\Bigg)\n\\Bigg)\n\\Bigg)\n\\\\\n%\n\\end{align*}\n%\nThese results are summarized in Table \\ref{tab:thirdOrder}.\n\n\\begin{table*}[t!]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{2}\n\t\\begin{tabular}{ccc}\n\t\\rowcolor[gray]{0.9} \\textbf{Component} & \\textbf{Input} & \\textbf{Output} \\\\\n\tFirst Value & \n\t$\\mathbf{s}$ & \n\t$f_{i} \\! \\left( \\mathbf{s} \\right)$ \n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\tFirst Gradient & \n\t$\\delta \\mathbf{s} $ &\n\t$\\displaystyle \\sum_{j} \\delta s_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) $\n\t\\\\\n\tSecond Value & \n\t$\\delta \\mathbf{t}$ & \n\t$\\displaystyle \\sum_{j} \\delta t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)$\n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\tSecond Gradient & \n\t$\\delta^{2} \\mathbf{t}$ &\n\t$\\displaystyle \\sum_{j} \\delta^{2} t_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n\t+ \\sum_{jk} \\delta s_{k} \\, \\delta t_{j} \n\t\\frac{ \\partial f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)$\n\t\\\\\n\tThird Value & \n\t$\\delta \\mathbf{u}$ &\n\t$\\displaystyle \\sum_{j} \\delta u_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)$\n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\tThird Gradient & \n\t$\\delta^{2} \\mathbf{u}$ &\n\t$\\displaystyle \\sum_{j} \\delta^{2} u_{j} \n\t\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) \n\t+ \\sum_{jk} \\delta s_{k} \\, \\delta u_{j} \n\t\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)$\n\t\\\\\n\tFourth Value & \n\t$\\delta^{2} \\mathbf{v}$ & \n\t$\\displaystyle \\sum_{j} \\delta^{2} v_{j} \\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right)\n\t\\delta u_{j} \\delta t_{k} \n\t\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right)$\n\t\\\\\n\t\\rowcolor[gray]{0.9} \n   \\multirow{3}{*}{ \\vspace{-8mm} Fourth Gradient} & \n\t\\multirow{3}{*}{ \\vspace{-8mm} $\\delta^{3} \\mathbf{v}$} &\n\t$\\displaystyle \\sum_{j} \\delta^{3} v_{j} \n\t\\frac{ \\partial f_{i} }{ \\partial x_{j} } \\! \\left( \\mathbf{s} \\right) $ \n\t\\\\\n\t& &\n\t$\\displaystyle + \\sum_{jk} \\left( \n\t\\delta s_{k} \\, \\delta^{2} v_{j} + \\delta u_{j} \\, \\delta^{2} t_{k} + \\delta^{2} u_{j} \\, \\delta t_{k}  \\right)\n\t\\frac{ \\partial^{2} f_{i} }{ \\partial x_{j} \\partial x_{k} } \\! \\left( \\mathbf{s} \\right) $ \n\t\\\\\n\t\\rowcolor[gray]{0.9} \n\t& &\n\t$ \\displaystyle+ \\sum_{jkl} \\delta u_{j} \\delta t_{k} \\, \\delta s_{l} \n\t\\frac{ \\partial^{3} f_{i} }{ \\partial x_{j} \\partial x_{k} \\partial_{l} } \\! \\left( \\mathbf{s} \\right) $\n\t\\\\\n\t\\end{tabular}\n\t\\caption{Recursively expanding a function with respect to a third-order dual number \n\tgives each component of the function's third-order pushforward.\n\t\\label{tab:thirdOrder}}\n\\end{table*}\n\nAs with second-order pullbacks, third-order pullbacks require considering each values as \na tangent and each gradient as a sensitivity.  For example, with the notation\n%\n\\begin{align*}\ns &\\rightarrow x \\\\\n\\delta s &\\rightarrow \\mathrm{d} f \\\\\n\\delta t &\\rightarrow \\delta x \\\\\n\\delta^{2} t &\\rightarrow \\mathrm{d}^{2} f \\\\\n\\delta u &\\rightarrow \\delta x^{2} \\\\\n\\delta^{2} u &\\rightarrow \\mathrm{d}^{3} f \\\\\n\\delta^{2} v &\\rightarrow \\delta x^{3} \\\\\n\\delta^{3} v &\\rightarrow \\mathrm{d}^{4} f\n\\end{align*}\n%\nthe third-order adjoint map is given by\n%\n\\begin{align*}\n\\mathrm{d}^{4} x_{n}\n&= \\quad\n\\sum_{m = 1}^{M} \\mathrm{d}^{4} f_{m} \\frac{ \\partial f_{m} }{ \\partial x_{n} }\n\\\\\n& \\quad + \n\\sum_{m = 1}^{M} \\mathrm{d} f_{m}\n\\left[ \\sum_{n'=1}^{N} \\delta^{3} x_{n'} \\frac{ \\partial^{2} f_{m} }{ \\partial x_{n'} \\partial x_{n} } \\right]\n+\n\\sum_{m = 1}^{M} \\mathrm{d}^{2} f_{m}\n\\left[ \\sum_{n'=1}^{N} \\delta^{2} x_{n'} \\frac{ \\partial^{2} f_{m} }{ \\partial x_{n'} \\partial x_{n} } \\right]\n+\n\\sum_{m = 1}^{M} \\mathrm{d}^{3} f_{m}\n\\left[ \\sum_{n'=1}^{N} \\delta x_{n'} \\frac{ \\partial^{2} f_{m} }{ \\partial x_{n'} \\partial x_{n} } \\right]\n\\\\\n& \\quad +\n\\sum_{m = 1}^{M} \\mathrm{d} f_{m}\n\\left[ \\sum_{n'=1}^{N} \\sum_{n''=1}^{N} \\delta x_{n'} \\delta^{2} x_{n''} \n\\frac{ \\partial^{3} f_{m} }{ \\partial x_{n''} \\partial x_{n'} \\partial x_{n} } \\right]\n\\end{align*}\n\n\\section{Automatic Differentiation}\n\nAutomatic differentiation is the automated computation of linear differential operators applied\nto a user-defined function.  Because dual numbers integrate a function evaluation along with\nits pushforward or pullback, they provide a natural type -- ultimately, automatic differentiation \nis just the extension of a user-defined, real-valued function to accept dual numbers.\n\nWhen these functions are composite, as is the case in almost any practical application, they\ncan be represented by an \\textit{expression graph}, with each node carrying the value of\nthe intermediate function evaluation and each edge denoting a functional dependency\n(Figure \\ref{fig:exprGraph}).  The dual number-valued functions necessary for automatic\ndifferentiation simply replace the single value at each node with the components of a\n$k$th-order dual number.\n\n\\begin{figure}\n\\setlength{\\unitlength}{0.1in} \n\\centering\n\\begin{picture}(50, 20)\n%\n%\\put(0, 0) { \\framebox(50, 20){} }\n%\\put(25, 0) { \\framebox(25, 30){} }\n%\\put(25, 0) { \\framebox(6.25, 30){} }\n%\\put(25, 0) { \\framebox(12.5, 30){} }\n%\\put(25, 0) { \\framebox(18.75, 30){} }\n%\n%\\put(25, 0) { \\framebox(3.125, 30){} }\n%\\put(25, 0) { \\framebox(9.375, 30){} }\n%\\put(25, 0) { \\framebox(15.625, 30){} }\n%\n\\put(12.5, 10) { \\makebox(0, 0) \n{$g \\! \\left( f_{1} \\! \\left( x_{1}, x_{2} \\right), f_{2} \\! \\left( x_{2}, x_{3} \\right) \\right)$} }\n%\n\\put(21.875, 10) { \\vector(1, 0){6.25} }\n%\n\\put(31.25, 2.5) { \\circle{4} }\n\\put(31.25, 2.5) { \\makebox(0, 0) {$ x_{1} $} }\n%\n\\put(37.5, 2.5) { \\circle{4} }\n\\put(37.5, 2.5) { \\makebox(0, 0) { $ x_{2} $ } }\n%\n\\put(43.75, 2.5) { \\circle{4} }\n\\put(43.75, 2.5) { \\makebox(0, 0) { $ x_{3} $ } }\n%\n\\put(31.25, 4.5) { \\vector(3, 4){2.75} }\n\\put(37.5, 4.5) { \\vector(-3, 4){2.75} }\n\\put(37.5, 4.5) { \\vector(3, 4){2.75} }\n\\put(43.75, 4.5) { \\vector(-3, 4){2.75} }\n%\n\\put(35, 10) {\\circle{4} } % Tweaked to the right\n\\put(34.375, 10) { \\makebox(0, 0) { $f_{1}$ } }\n%\n\\put(41.25, 10) {\\circle{4} } % Tweaked to the right\n\\put(40.625, 10) { \\makebox(0, 0) { $f_{2}$ } }\n%\n\\put(34.375, 12) { \\vector(3, 4){2.75} }\n\\put(40.625, 12) { \\vector(-3, 4){2.75} }\n%\n\\put(38, 17.5) {\\circle{4} } % Tweaked to the right\n\\put(37.5, 17.5) { \\makebox(0, 0) { $ g $ } }\n%\n\\end{picture} \n\\caption{\nComposite functions are isomorphic to directed acyclic graphs known as \n\\textit{expression graphs}; for example, the function\n$g \\! \\left( f_{1} \\! \\left( x_{1}, x_{2} \\right), f_{2} \\! \\left( x_{2}, x_{3} \\right) \\right)$\ngenerates a three level graph, with leaves $\\left\\{ x_{1}, x_{2}, x_{3} \\right\\}$ and\nroot $g$.  The expression graph corresponding to a real-valued function\nstores single values at each node, and automatic differentiation requires that\neach node store all components of a $k$th-order dual number.\n}\n\\label{fig:exprGraph} \n\\end{figure}\n\nThe computation of any linear differential operator comprised entirely of pushforwards is\nknown as \\textit{forward mode} or \\textit{forward accumulation} automatic differentiation\nbecause all dual numbers are propagated forward along the expression graph.  Any\nadjoint operator, however, requires propagating sensitivities backwards along the expression\ngraph and consequently the implementation of adjoint operators is known as \n\\textit{reverse mode} or \\textit{reverse accumulation} automatic differentiation.  In this\nsection we consider both forward and reverse mode automatic differentiation, discuss\ntheir relative performance, and demonstrate a selection of linear differential operator\nimplementations.\n\n\\subsection{Forward Mode Automatic Differentiation}\n\nForward mode automatic differentiation computes the $k$th-order pushforward \nof a given function by first initializing all values and gradients at the function\ninputs and propagating the perturbations along the expression graph in a single \nforward sweep.  \n\nBecause only one sweep is necessary for forward mode, the expression graph does \nnot need to be explicitly stored in memory, reducing overhead and often admitting \nmore optimized code.  On the other hand, the linear differential operators comprised \nentirely of pushforwards are often not of immediate practical interest.\n\n\\subsection{Reverse Mode Automatic Differentiation}\n\nReverse mode automatic differentiation compliments forward mode by computing\n$k$th-order adjoint operators which require more elaborate traversals of the\nexpression graph.  A general reverse mode calculation interleaves the forward\npropagation of tangents and the reverse propagation of sensitivities, starting at\nfirst order and working up to the desired order.\n\nConsequently, reverse mode requires the persistent storage of the expression \ngraph and induces a corresponding performance overhead.  In practice, however,\nthe adjoint operators admitted by reverse mode automatic differentiation are\nmore appropriate to applications and worth the additional cost.\n\n\\subsection{Relative Performance}\n\nIn general neither forward mode nor reverse mode automatic differentiation can be\nclaimed as optimal, as the relative performance of the two depends not only on\nthe given function but also on the desired linear differential operation.  \n\nConsider, for example, many-to-one functions $f : \\mathbb{R}^{N} \\rightarrow \\mathbb{R}$,\ncommon to many applications.  Forward mode automatic differentiation, computes the \ndirectional derivative of the function along a given tangent in a single forward sweep.\nRecovering the full gradient then requires $N$ forward sweeps, each initialized with\nonly one of the input tangents non-zero.  On the other hand, reverse mode automatic\ndifferentiation computes the gradient with only one forward and one reverse sweep.  \n\nIf the directional derivative is sufficient or $N$ is small then forward mode automatic\ndifferentiation is the better performing approach, but when the gradient is desired and \n$N$ is large, reverse mode automatic differentiation becomes far more computationally \nefficient despite the memory overhead.  Because this latter case is ubiquitous is\npractice, \\nomad implements reverse mode automatic differentiation.\n\n\\subsection{Example Implementations}\n\nHere we review the exact computations needed to implement a selection of\nlinear differential operators natural to many-to-one functions, \n$f : \\mathbb{R}^{N} \\rightarrow 1$.\n\nThe gradient and Hessian are denoted by $\\mathbf{g}$ and $\\mathbf{H}$, respectively,\nwhile adjuncts refers to lower-order linear differential operators that are generated\nas a side effect of the desired operation.\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Directional Derivative]\n\n\t\\begin{description}\n\t\t\\item[Form:] $\\displaystyle \\mathbf{v}^{T} \\mathbf{g} = \\sum_{i} v_{i} \\frac{ \\partial f }{ \\partial x_{i} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize first gradient of the inputs, $\\delta x_{i} = v_{i}$. \\\\\n\t\tCompute first-order forward sweep. \\\\\n\t\tReturn first gradient of output.\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( 1 \\right)$\n\t\t\\item[Adjuncts:] $ f $\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Gradient]\n\t\n\t\\begin{description}\n\t\t\\item[Form:] $\\displaystyle g_{i} = \\frac{ \\partial f }{ \\partial x_{i} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize first gradient of the output, $\\mathrm{d} f = 1$. \\\\\n\t\tCompute first-order reverse sweep. \\\\\n\t\tReturn first gradient of inputs.\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( 1 \\right)$\n\t\t\\item[Adjuncts:] $ f $\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Hessian Quadratic Form]\n\n\t\\begin{description}\n\t\t\\item[Form:] \n\t\t$\\displaystyle \\mathbf{v}^{T} \\mathbf{H} \\, \\mathbf{u} = \n\t\t\\sum_{ij} v_{i} u_{j} \\frac{ \\partial^{2} f }{ \\partial x_{i} \\partial x_{j} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize first gradient, $\\delta x_{i} = v_{i}$, second value, $\\delta y_{i} = u_{i}$,\n\t\tand second gradient, $\\delta^{2} y_{i} = 0$, of the inputs. \\\\\n\t\tCompute second-order forward sweep. \\\\\n\t\tReturn second gradient of output.\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( 1 \\right)$\n\t\t\\item[Adjuncts:] $ f, \\, \\mathbf{v}^{T} \\mathbf{g}, \\, \\mathbf{u}^{T} \\mathbf{g}$\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Hessian-Vector Product]\n\t\n\t\\begin{description}\n\t\t\\item[Form:] $\\displaystyle \\mathbf{H} \\, \\mathbf{v} = \n\t\t\\sum_{j} v_{j} \\frac{ \\partial^{2} f }{ \\partial x_{i} \\partial x_{j} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize first gradient of the output, $\\mathrm{d} f = 1$. \\\\\n\t\tCompute first-order reverse sweep for first gradients at the inputs. \\\\\n\t\tInitialize second values of the inputs, $\\delta y_{i} = v_{i}$. \\\\\n\t\tPropagate second values in a forward sweep. \\\\\n\t\tInitialize second gradient of the output, $\\mathrm{d}^{2} f = 0.$ \\\\\n\t\tCompute second-order reverse sweep. \\\\\n\t\tReturn second gradient of inputs.\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( 1 \\right)$\n\t\t\\item[Adjuncts:] $ f, \\, \\mathbf{v}^{T} \\mathbf{g}, \\, \\mathbf{g}$\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Hessian]\n\t\n\t\\begin{description}\n\t\t\\item[Form:] $\\displaystyle H_{ij} = \\frac{ \\partial^{2} f }{ \\partial x_{i} \\partial x_{j} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize $\\mathrm{d} f = 1$. \\\\\n\t\tCompute first-order reverse sweep for first gradients. \\\\\n\t\tFor each $j$ compute the $j$th row of the Hessian as:\n\t\t\\begin{itemize}\n\t\t\t\\setlength{\\itemsep}{0cm}\n\t\t\t\\setlength{\\parskip}{0cm}\n\t\t\t\\item[] Initialize second values of the inputs, $\\delta y_{i} = \\delta^{j}_{i}$.\n\t\t\t\\item[] Propagate second values in a forward sweep. \n\t\t\t\\item[] Initialize second gradient of the output, $\\mathrm{d}^{2} f = 0$.\n\t\t\t\\item[] Compute second-order reverse sweep.\n\t\t\t\\item[] Return second gradient of inputs\n\t\t\\end{itemize}\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( n \\right)$\n\t\t\\item[Adjuncts:] $ f, \\, \\mathbf{g}$\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[colback=white,colframe=gray90, coltitle=black,boxrule=3pt,\nfonttitle=\\bfseries,title=Gradient of the Trace of a Matrix Hessian Product]\n\t\n\t\\begin{description}\n\t\t\\item[Form:] \n\t\t$\\displaystyle \\frac{\\partial}{\\partial x_{i} } \\mathrm{Tr} \\! \\left[ \\mathbf{M} \\, \\mathbf{H} \\right]\n\t\t= \\sum_{jk} M_{jk} \\frac{ \\partial^{3} f }{ \\partial x_{i}  \\partial x_{j}  \\partial x_{k} } $\n\t\t\\item[Algorithm:] \\hfill \\\\\n\t\tInitialize $\\mathrm{d} f = 1$. \\\\\n\t\tCompute first-order reverse sweep for first gradients. \\\\\n\t\tInitialize the trace gradient to zero.\n\t\tFor each $j$ increment the trace gradient with:\n\t\t\\begin{itemize}\n\t\t\t\\setlength{\\itemsep}{0cm}\n\t\t\t\\setlength{\\parskip}{0cm}\n\t\t\t\\item[] Initialize second values of the inputs, $\\delta t_{i} = \\delta^{j}_{i}$.\n\t\t\t\\item[] Propagate second values in a forward sweep. \n\t\t\t\\item[] Initialize second gradient of the output, $\\mathrm{d}^{2} f = 0$.\n\t\t\t\\item[] Compute second-order reverse sweep.\n\t\t\t\\item[] Initialize third and fourth values of the inputs, $\\delta u_{i} = M_{ji}, \\delta^{2} v_{i} = 0$.\n\t\t\t\\item[] Propagate third and fourth values in a forward sweep.\n\t\t\t\\item[] Initialize third gradient of the output, $\\mathrm{d}^{3} f = 0$.\n\t\t\t\\item[] Compute third-order reverse sweep.\n\t\t\t\\item[] Return the fourth gradient of the inputs.\n\t\t\\end{itemize}\n\t\t\\item[Cost:] $\\mathcal{O} \\! \\left( n \\right)$\n\t\t\\item[Adjuncts:] $ f, \\, \\mathbf{g}, \\, \\mathbf{H}$\n\t\\end{description}\n\t\n\\end{tcolorbox}\n\n", "meta": {"hexsha": "310621caf06e4fd59e3c4364d0ae4a34ac54bc7c", "size": 47334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/1-autodiff.tex", "max_stars_repo_name": "stan-dev/nomad", "max_stars_repo_head_hexsha": "a21149ef9f4d53a198e6fdb06cfd0363d3df69e7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-12-11T20:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-15T18:59:58.000Z", "max_issues_repo_path": "manual/1-autodiff.tex", "max_issues_repo_name": "stan-dev/nomad", "max_issues_repo_head_hexsha": "a21149ef9f4d53a198e6fdb06cfd0363d3df69e7", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-12-15T08:12:01.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-17T01:36:56.000Z", "max_forks_repo_path": "manual/1-autodiff.tex", "max_forks_repo_name": "stan-dev/nomad", "max_forks_repo_head_hexsha": "a21149ef9f4d53a198e6fdb06cfd0363d3df69e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-13T17:40:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-08T19:17:51.000Z", "avg_line_length": 41.9627659574, "max_line_length": 125, "alphanum_fraction": 0.6477584823, "num_tokens": 17682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6453672659463803}}
{"text": "\\Lecture{Jayalal Sarma}{Nov 2, 2020}{24}{Algebraic Methods in Combinatorics}{Sampriti Roy}{$\\alpha$}{JS}\n\\section{Introduction}\nIn this chapter the plan is to switch to algebraic methods in combinatorics and the first structure we are going to explore is the concepts related to group theory. It's essentially going to be presented from the combinatorial side. As, a motivation we can think of the following problems:\n\\begin{itemize}\n\\item \\emph{How many distinct squares can be there with yellow and blue coloured corners?}\n\\end{itemize}\nOur task is to develop a method to count distinct colourings of such squares out of total $2^4=16$ possible colourings. If we consider the set of all coloured squares to be $\\Omega$, there will be some squares that are equivalent to each other under some rotation. As, we are interested in counting distinct colouring, the equivalent squares should not be counted twice.\n\\paragraph{}\nOne more question, we can think about is :\n\\begin{itemize}\n\\item \\emph{How many necklaces can be formed with solid beads and transparent beads? }\n\\end{itemize}\n\\paragraph{} \nBased on the colouring of square, we can say that there are total $2^4=16$ possible colourings but there are few operations under which two colourings can be viewed as same. Let's get familiar with such operations:\n\\begin{itemize}\n\\item $R_0$ : Rotation by $0^{\\circ}$ \n\\item $R_{90}$ : Rotation by $90^{\\circ}$\n\\item $R_{180}$ : Rotation by $180^{\\circ}$\n\\item $R_{270}$ : Rotation by $270^{\\circ}$\n\\item $H$ : Horizontal flip\n\\item $V$ : Vertical flip\n\\item $D$ : Diagonal flip (bottom left top right)\n\\item $D'$ : Diagonal flip (bottom right top left)\n\\end{itemize}\nNow, let's consider all the above set of operations together to be :\n\\begin{align*}\nG&=\\{R_0,R_{90},R_{180},R_{270},H,V,D,D'\\} \n\\end{align*}\nWe will see that the elements of set $G$ are inter related with each other. If we apply two operations from $G$, one after another, we will get the result of applying an operation from $G$ itself. Let's verify it:\n\\begin{itemize}\n\\item Rotate the square two times horizontally, it will result rotating it by $0^{\\circ}$. That is $H.H=R_0$\n\\item Rotate the square two times diagonally, it will result rotating it by $0^{\\circ}$. That is $D.D=R_0$\n\\item Rotate the square two times vertically, it will result rotating it by $0^{\\circ}$. That is $V.V=R_0$\n\\item Rotate the square two times by $180^{\\circ}$, it will result rotating it by $0^{\\circ}$. That is $R_{180}.R_{180}=R_0$\n\\item Rotate the square by $90^{\\circ}$ first then rotate it by $180^{\\circ}$, it will result rotating by $270^{\\circ}$. That is $R_{90}R_{180}=R_{270}$\n\\item  Rotate the square by $90^{\\circ}$ first then rotate it by $270^{\\circ}$, it will result rotating by $0^{\\circ}$. That is $R_{90}R_{270}=R_{0}$\n\\item Rotate the square by $90^{\\circ}$ first then rotate it vertically, it will result rotating diagonally. That is $R_{90}.V=D $\n\\end{itemize}\n\\section{Incremental definition of Group}\nConsider a set $G$ with binary operation $\\circ$. Now, take any two elements of $G$ and apply the operation, a natural question to ask is whether we will get any element from the set $G$ or not. We will answer this question along with other related questions and finally move on to the definition of Group incrementally.\n\\begin{itemize}\n\\item \\emph{Groupoid} : Let $a,b\\in G$. If $a\\circ b\\in G$, then $G$ is \\emph{Closed} under the operation $\\circ$. And $G$ is called \\emph{Groupoid}. We can easily verify that our example set $G$ is a \\emph{Groupiod}.\n\\item \\emph{Semigroup} : $a,b,c\\in G$; if $a\\circ(b\\circ c)=(a\\circ b)\\circ c $, then $G$ is \\emph{associative} under $\\circ$ or, the order of $\\circ$ does not matter. If a groupoid is associative, it is called \\emph{Semigroup}. We can try out and check that our example set $G$ is associative and so it is a \\emph{Semigroup}.\n\\item \\emph{Monoid} : $\\forall a\\in G $, if there is an $e\\in G$ such that $a\\circ e=e\\circ a\\forall $, $e$ is called identity element. A Semigoup with identity is called \\emph{Monoid}. In our example set $G$, $R_0$ is the identity element, so it is a \\emph{Monoid}.\n\\item \\emph{Group} : $\\forall a\\in G$ if $ \\exists b\\in G $ such that $a\\circ b=b\\circ a=e $; where $e$ is identity element, $b$ is called the \\emph{inverse} of $a$. A Monoid with inverse element is called a \\emph{Group}. In our example set $G$, $R_{180}$ is it's own inverse, $H$ is it's own inverse and we can try out that every element has it's inverse and so it is a \\emph{Group}.\n\\end{itemize}\nHence, we can conclude that $G=\\{R_0,R_{90},R_{180},R_{270},H,V,D,D'\\}  $ is not just a set, rather it has more structural properties. $(G,\\circ) $ is a \\emph{Group}. Now, we are ready to define \\emph{Group} formally.\n\\begin{definition}\n$(G,\\circ)$ is a group if it satisfies closure, associativity and it has identity and inverse element.\n\\end{definition} \n\\textbf{Example1} : Let's consider $\\mathbb{Z}_p=\\{0,1,...,p-1\\} $ where $p$ is a prime number. Define the operation to be $+ \\  mod \\ p $. Let's verify whether $(\\mathbb{Z}_p,+ \\ mod \\ p) $ is a group or not:\n\\begin{itemize}\n\\item \\emph{Closure} : $\\forall a, b\\in \\mathbb{Z}_p; a+ \\ mod \\ p\\in \\mathbb{Z}_p$. So, $\\mathbb{Z}_p$ is closed under the operation $+ \\ mod \\ p$\n\\item \\emph{Associativity} : As modulo arithmetic is associative, $\\mathbb{Z}_p$ is associative under $+ \\ mod \\ p$\n\\item \\emph{Identity} : $0$ is the identity element for all elements in $\\mathbb{Z}_p$. \n\\item \\emph{Inverse} : For any element $a\\in \\mathbb{Z}_p$, $(p-a)$ will be the inverse of $a$.\n\\end{itemize}\nHence, $(\\mathbb{Z}_p,+ \\ mod \\ p) $ is a group.\n\\paragraph{}\nLet's check whether $(\\mathbb{Z}_p,\\times \\ mod  \\ p) $ is group or not:\n\\begin{itemize}\n\\item \\emph{Closure} : $\\forall a, b\\in \\mathbb{Z}_p; a\\times \\ mod \\ p\\in \\mathbb{Z}_p$. So, $\\mathbb{Z}_p$ is closed under the operation $\\times \\ mod \\ p$\n\\item \\emph{Associativity} : As modulo arithmetic is associative, $\\mathbb{Z}_p$ is associative under $\\times \\ mod \\ p$\n\\item \\emph{Identity} : $1$ is the identity element for all elements in $\\mathbb{Z}_p$\n\\item \\emph{Inverse} : The element $0$ does not have any inverse.\n\\end{itemize}\nHence, $(\\mathbb{Z}_p,\\times \\ mod  \\ p) $ is not a group but it is a \\emph{Monoid}.\n\\paragraph{}\nConsider the group $\\mathbb{Z}_p^* $ under the operation $\\times \\ mod  \\ p $; for example we can verify that $(\\mathbb{Z}_p^*,\\times \\ mod  \\ p) $ satisfies closure, associativity, identity and inverse properties. Hence, $(\\mathbb{Z}_p^*,\\times \\ mod  \\ p) $ is a group.\\\\\n\\textbf{Exercise} : Use \\emph{pigeon hole principle} to prove that every element has it's inverse in  $(\\mathbb{Z}_p^*,\\times \\ mod  \\ p) $.\n\\paragraph{}\n\\textbf{Example2} : Set of bijection from $\\{1,2,...,n\\} $ to $\\{1,2,...,n\\}$ forms a group under composition ($\\circ $).\n\\begin{itemize}\n\\item \\emph{Closure} : Composition of two bijections is bijection\n\\item \\emph{Associative} : Using function composition property, if $f,g,h$ are functions, $f\\circ(g\\circ h)=(f\\circ g)\\circ h$\n\\item \\emph{Identity} : Identity function will be there\n\\item \\emph{Inverse} : Every element will have inverse\n\\end{itemize}\nHence, set of bijections $(S_n,\\circ) $ forms a group.\n\\section{Group (abstractly)}\nSo far, we have seen the definition of a group $G$, under some operation $\\circ$. Now, we will move on the definition of \\emph{Subgroup}.\n\\begin{definition}\nLet $(G,\\circ) $ be a group. $H\\subseteq G$ is said to be a subgroup if $H$ forms a group by itself with respect to the same operation $\\circ$. A subgroup of $G$ is denoted by $H\\leq G$. \n\\end{definition}\n\\textbf{Example} : $(\\mathbb{Z}_{15},+ \\ mod \\ 15) $ is a group. Consider $H=\\{0,3,6,9,12\\}$. $H\\subseteq G$ and $H$ satisfies closure, associativity, identity, inverse and so it forms a group under $+ \\ mod \\ 15 $, so $H\\leq G$.\n\\subsection{Subgroup}\nConsider a group $G$ and $H\\leq G$. Let's take an element $g$ from $G\\setminus H$ and multiply it with $H$, define:\n\\begin{align}\nHg=\\{hg|h\\in H\\}\n\\end{align} \n\\begin{observation}\nIf $g\\in H$; then $Hg\\subseteq H$ as $H$ is closed by itself. \n\\end{observation}\nIt's not just $Hg\\subseteq H$; something more is true. For that, we will have the following claim\n\\begin{claim}\n$|Hg|=|H|$ when $g\\in H$\n\\end{claim}\n\\begin{proof}\n$\\forall h_1\\neq h_2\\in H$, we need to argue that $h_1g\\neq h_2g$. Or multiplication by $g$ is actually a bijection.\\\\\nLet's prove it by contradiction and let $\\forall h_1\\neq h_2\\in H$\n\\begin{align*}\nh_1g&=h_2g\\\\\nh_1&=h_2gg^{-1}\\\\\nh_1&=h_2\n\\end{align*}\nHence, we get a contradiction. So, $h_1g\\neq h_2g$\n\\end{proof}\nNow, let's move on to the following claim\n\\begin{claim}\n$\\forall g_1,g_2$; if $Hg_1\\cap Hg_2\\neq \\emptyset $; then $Hg_1=Hg_2$. In other words, if $Hg_1$ and $Hg_2$ are overlapping, then they are same.\n\\end{claim}\n\\begin{proof}\nLet $g_1,g_2\\in G$. Suppose $g\\in Hg_1\\cap Hg_2$\n\\begin{align*}\n\\exists h\\in H; g&=hg_1\\\\\n\\exists h'\\in H; g&=h'g_2\n\\end{align*}\nNow, combining the above two,\n\\begin{align*}\nhg_1&=h'g_2\\\\\ng_1&=h^{-1}h'g_2\n\\end{align*}\nNow, we are ready to prove $Hg_1\\subseteq Hg_2$\\\\\nConsider, any element in LHS $h''\\in H $, substituting $g_1$, we get:\n\\begin{align*}\nh''g_1&=h''h^{-1}h'g_2\\\\\n&=h'''g_2\n\\end{align*}\nHence, any element in LHS is in RHS. Similarly, we can prove $Hg_2\\subseteq Hg_1$. So, $Hg_1=Hg_2$.\n\\end{proof}\n\\paragraph{}\nSo, we can argue that the multiplication of $H$ by other elements will result in translation of $H$ which are kind of tiling of group $G$. It does not mean that every $g_i$ will give different tiles, but if they have common element, they are same. One interesting feature is that all such tiles will have equal size. One natural question is can there be any element that is not in any tiling? Yes, there can be. For example, $\\forall g\\in G, g\\in Hg$ because $H$ contains identity as it is subgroup. So,$g$ is an element of $Hg$ always. So, every element $g$ will be there in some tile for sure. If there are total $k$ tiles, we argue that:\n\\begin{align*}\n|G|&=k.|H|\n\\end{align*}\n\\begin{theorem}\nLagrange's Theorem : The size of a subgroup $|H$ must divide the size of a group $|G|$.\n\\end{theorem}\n For example, A group of size $100$ can not have a subgroup of size $99$. In fact it can only have subgroup of size at most $50$. Any group with prime number of elements, can not have any non-trivial subgroup. So, \\emph{Lagrange's Theorem} is the example of algebraic structure implying combinatorial bounds.\n\n\n\\Lecture{Jayalal Sarma}{Nov 4, 2020}{25}{A step towards Polya's Theory }{Sampriti Roy}{$\\alpha$}{JS}\n\\section{A quick recap}\n In last lecture, we started with a problem of counting number of distinct colourings when the corner of a square are coloured with $2$ colours. We defined a set $G=\\{R_0,R_{90},R_{180},R_{270},H,V,D,D'\\} $ that acts on set of all possible $2$-coloured squares and some of them are equivalent under these operations. We have also talked about the definition of subgroup $(H)$ of a group $(G)$ and defined that for $g\\in G\\setminus H$, $Hg=\\{hg: h\\in H \\}$. This $Hg$ is called \\emph{coset} of $H$ in $G$. \nWe have also seen that if any two cosets overlap, they have to be same. We have also talked about \\emph{Lagrange's Theorem}. In this chapter the plan is to understand \\emph{Polya's Theory}. We will complete it only in next lecture but we will do a step towards it. The step is known to be \\emph{Burnside's Lemma}. \n\\section{The abstract problem of counting distinct 2-coloured squares}\n $\\Omega$ be the set of all $2$-coloured squares. There $|\\Omega|=2^4=16$ possibilities. Our task is to count to number of distinct colourings among $\\Omega$. Let's define the equivalence between two coloured squares formally:\n \\begin{definition}\n Let $\\alpha,\\beta\\in \\Omega$, if $\\exists g\\in G$ such that the action on $g$ on $\\alpha$ returns $\\beta$, or $\\alpha^g=\\beta$; then we say $\\alpha$ and $\\beta$ are equivalent, $\\alpha\\sim \\beta$.\n\\end{definition}\nThe relation $\\sim$ between $\\alpha$ and $\\beta$ satisfies the following properties:\n\\begin{itemize}\n\\item \\emph{Reflexive} : $\\alpha\\sim \\alpha$\n\\item \\emph{Symmetric} : $\\alpha\\sim \\beta\\rightarrow \\beta\\sim \\alpha$; if the action of $g$ makes the transformation from $\\alpha$ to $\\beta$, then $g^{-1}$ will make the transformation from $\\beta$ to $\\alpha$. For example, $R_{90}$ transform $\\alpha$ to $\\beta$, $R_{270}$ will transform $\\beta$ to $\\alpha$.\n\\item \\emph{Transitive} : If $\\alpha\\sim \\beta$ by the action $g_1$, $\\beta\\sim \\gamma$ by the action $g_2$; then the action of $g_1g_2$ (composition of $g_1,g_2$) will transform $\\alpha\\sim \\gamma$.\n\\end{itemize}\nHence, $\\sim$ is an equivalence relation and it splits the set $\\Omega$ into set of equivalence classes.\n\\subsection{Orbit and Stabilizer}\nThe action of $g$ on $\\Omega$, partitions $\\Omega$ into different equivalence classes but their sizes need not be equal. This equivalence classes are called \\emph{Orbit}. In our context, among set of all possible $2$-colourings of a square, we don't want to count equivalent squares twice. In other words, the abstract problem that we are interested to study is to count the number of orbits of $\\Omega$. First, we are going to study the sizes of the orbits and using them we will have a mechanism to count them. Let's define the following\n\\begin{definition}\n$Orbit_G(\\alpha)=$ orbit of $\\alpha$ under the action of $G$ on $\\Omega$\n\\begin{align*}\nOrbit_G(\\alpha)&=\\{\\beta:\\exists g\\in G \\ s.t \\ \\alpha^g=\\beta \\}\n\\end{align*}\n\\end{definition}\nNow, we are ready to define \\emph{Stabilizer} of $\\alpha$ on an action of $G$. Let, $g\\in G$ is acting on $\\Omega$. Let $\\alpha\\in G$, which are  the elements in $G$ that fixes $\\alpha$? i.e, the elements in $G$ that takes $\\alpha$ to itself. \n\\begin{definition}\nStabilizer of an element $\\alpha$ is a subset of $G$, which acts on $\\alpha$ and takes it back to itself.\n\\begin{align*}\nStab_G(\\alpha)&=\\{g\\in G: \\alpha^g=\\alpha \\}\n\\end{align*}\n\\end{definition}\nWe will see few examples of stabilizer to make it more clear. \n\\begin{itemize}\n\\item \\emph{Example 1} : A simple example we can think of in our square setting is that, let $\\alpha$ be the square where all the corners are coloured yellow. Now, we can easily conclude that any operation from the group $G$ can fix $\\alpha$, i.e, no matter which action we are performing, $\\alpha$ will be $\\alpha$ itself. So, the stabilizer of $\\alpha$ is the entire group $G$.\n\\item \\emph{Example 2} : Let's think of another $\\alpha$ where bottom left and top right corners are coloured blue and the other two are coloured yellow. Now, we can verify that the operations that fixes $\\alpha$ are : $\\{R_0,R_{180},D,D' \\} $. \n\\end{itemize}\nAn interesting observation is that stabilizers inside $G$ are not only subset of $G$, they are actually subgroup of $G$. Let's prove the argument formally,\n\\begin{claim}\n$$Stab_G(\\alpha)\\leq G$$\n\\end{claim}\n\\begin{proof}\nFix an $\\alpha$ and verify the following :\n\\begin{itemize}\n\\item \\emph{Closure} : If $g_1,g_2\\in Stab_G(\\alpha)$, then $g_1g_2\\in Stab_G(\\alpha)$. As, $g_1,g_2$ are fixing $\\alpha$, then their composition will also fix $\\alpha$.\n\\item \\emph{Associativity} : As the operations performed are subset of $G$, associativity is inherited in $Stab_G(\\alpha)$.\n\\item \\emph{Identity} : Identity fixes every element, in particular it fixes $\\alpha$. So, identity element is present in $Stab_G(\\alpha)$.\n\\item \\emph{Inverse} : If an element $g$ fixes $\\alpha$, then $g^{-1}$ will also fix $\\alpha$. So, inverse element is always present in $Stab_G(\\alpha)$. For example,   if $R_{90}$ fixes a coloured square, then $R_{270}$ will also fix the same square.\n\\end{itemize}\nHence, $Stab_G(\\alpha)\\leq G$\n\\end{proof}\nThere is a combinatorially useful relation between size of the stabilizer and the size of the of $\\alpha$. Let's define the following lemma;\n\\begin{lemma}\n\\textbf{Orbit-Stabilizer Lemma} : $$\\forall\\in \\Omega;|Orbit_G(\\alpha)|.|Stab_G(\\alpha)|=|G|$$\n\\end{lemma}\nWe will prove this lemma formally in next lecture, but here we are going to draw a outline of the thought process to prove this lemma.\n\\paragraph{}\n\\emph{Proof Idea} : Let $Stab_G(\\alpha)$ be denoted by $H$. We have already proved that $Stab_G(\\alpha)$ is a subgroup of $G$. Using \\emph{Lagrange's theorem} we can say that $$|G|=k.|Stab_G(\\alpha)|$$\nWhere $k$ is the number of cosets $H$ in $G$. So, it is sufficient to prove that number of cosets $H$ in $G$ is exactly $|Orbit_G(\\alpha)|$. We will show a bijection that for every element in the orbit of $\\alpha$, there is a way to associate a corresponding coset with it. Hence, the number of coset in $Stab_G(\\alpha) =|Orbit_G(\\alpha)|$. Now, we will quickly define the bijection:\n\\paragraph{}\nConsider any $\\beta\\in Orbit(\\alpha)$; it means $\\exists g\\in G $ s.t. $\\alpha^g=\\beta $. Now, coset corresponding to $g$ is $Hg$. We required to show the following:\n\\begin{itemize}\n\\item \\emph{Well definedness} : There could be many $g\\in G$ which makes $\\alpha$ to $\\beta$. We need to argue that no matter which $g\\in G$ we choose, we will end up by getting the coset $Hg$.\n\\item \\emph{Injection} : For $\\beta\\neq \\beta'\\in Orbit(\\alpha)$; there is $g,g'\\in G$ where $\\alpha^g=\\beta,\\alpha^{g'}=\\beta'$; we will end up by getting two different cosets, i.e., $Hg\\neq Hg' $.\n\\item \\emph{Surjection} : To show that for any coset we have corresponding element in the orbit of $\\alpha$.\n\\end{itemize}\nAn interesting observation we can make from the above lemma is that if the size of a group is any prime number then either $|Stab_G(\\alpha)|$ is same as $|G|$ and $|Orbit_G(\\alpha)|=1$ or $|Stab_G(\\alpha)|=1$ and $|Orbit_G(\\alpha)|$ is same as $|G|$. But, we are not interested in individual sizes of orbits but we want to count the number of orbits. We will use the \\emph{Orbit-Stabilizer lemma} to define the following lemma to show that if we have a handle on the size of orbits then we can have a handle on the number on number of orbits as well. First, we will define the following:\n\\begin{definition}\n\\textbf{Fix Points} : If $G$ is acting on $\\Omega$, fix points of a group element are those elements on $\\Omega$ that are fixed by $g$.\n\\begin{align*}\nfix(g)&=\\{\\alpha\\in \\Omega: \\alpha^g=\\alpha \\}\n\\end{align*}\n\\end{definition}\nNow, we are ready to state the following lemma:\n\\begin{lemma}\n\\textbf{Burnsides Lemma} : \n\\begin{align*}\n\\#of \\ orbits \\ &=\\frac{1}{|G|}\\sum_{g\\in G}|fix(g)|\n\\end{align*}\n\\end{lemma}\n\\begin{proof}\nThe proof is a classic proof by double counting method. Let's define the set\n\\begin{align*}\nS&=\\{(g,\\alpha): g\\in G, \\alpha\\in \\Omega; \\alpha^g=\\alpha \\}\n\\end{align*}\nWe will estimate $|S|$ in two different ways:\n\\begin{itemize}\n\\item Answer $1$ : For each $g$ count number of different $\\alpha$ that are fixed by $g$.\n\\begin{align*}\n&\\sum_{g\\in G} (\\#of \\ \\alpha \\ s.t \\ \\alpha^g=\\alpha)\\\\\n&=\\sum_{g\\in G}|fix(g)|\n\\end{align*}\n\\item Answer $2$ : For each $\\alpha\\in \\Omega$, count number of different $g$ that fixes $\\alpha$.\n\\begin{align*}\n&\\sum_{\\alpha\\in \\Omega} (\\#of \\ g \\ s.t \\ \\alpha^g=\\alpha)\\\\\n&=\\sum_{\\alpha\\in \\Omega}|Stab_G(\\alpha)|\\\\\n&=\\sum_{\\alpha\\in \\Omega}\\frac{|G|}{|Orbit_G(\\alpha)|}\\\\\n&=|G|.\\sum_{\\alpha\\in \\Omega}\\frac{1}{|Orbit_G(\\alpha)|}\\\\\n\\end{align*}\nLet us consider the orbits of $\\Omega$ are denoted by $\\{\\Omega_1,\\Omega_2,...\\}$. Then the above expression becomes,\n\\begin{align*}\n&=|G|.(\\sum_{\\alpha\\in \\Omega_1}\\frac{1}{|\\Omega_1|}+\\sum_{\\alpha\\in \\Omega_2}\\frac{1}{|\\Omega_2|} )\\\\\n&=|G|.(\\#of \\ orbits)\n\\end{align*}\n\\end{itemize}\nEquating Answer $1$ and $2$, we get:\n\\begin{align*}\n|G|.(\\#of \\ orbits)&=\\sum_{g\\in G}|fix(g)|\\\\\n\\#of \\ orbits&=\\frac{1}{|G|}\\sum_{g\\in G}|fix(g)|\n\\end{align*}\n\\end{proof}\n\\section{Counting number of distinct coloured square using Bernsides Lemma}\nWe we apply Bernsides lemma to our example problem to count number of distinct coloured squares in $\\Omega$. For that, first we have to compute $|fix(g)|$ for each $g\\in G$. Where $G=\\{R_0,R_{90},R_{180},R_{270},H,V,D,D'\\}  $.\n\\begin{itemize}\n\\item $g=R_0$; all the coloured squares in $\\Omega$ are fixed by $g$. So, $|fix(R_0)|=|\\Omega|=16$\n\\item $g=R_{90}$; the squares whose all corners are either blue or yellow will be fixed by $g$. So, $|fix(R_{90})|=2 $\n\\item $g=R_{180}$; total $4$ squares will be fixed  by $g$. So, $|fix(R_{180})|=4 $\n\\item $g=R_{270}$; the number of squares that will be fixed are same as $R_{90}$. Because, if a square is fixed by $R_{90}$, it will be fixed by it's inverse as well. So, $|fix(R_{270})|=2 $\n\\item $g=H$; it will fix the squares where the upper half and lower half corresponding to the horizontal plane (line towards the middle of the square) will be coloured with same colour. so, $|fix(H)|=4 $\n\\item $g=V$; the number of squares will be same as that are fixed by $H$. so, $|fix(V)|=4 $\n\\item $g=D$; consider one diagonal and corresponding to it the upper half and lower half will be coloured with same colour, there are $2$ ways to do it and for each such colour the diagonal can be coloured in $4$ ways. So, $|fix(D)|=8 $\n\\item $g=D'$; the number of squares will be same as that are fixed by $D$. So, $|fix(D')|=8$\n\\end{itemize}\nUsing Bernsides lemma,\n\\begin{align*}\n\\#of \\ orbits \\ in \\ \\Omega&=\\frac{1}{8}(16+2+4+2+4+4+8+8)\\\\\n&=6\n\\end{align*}\nSo, out of the $16$ total colourings $6$ of them are in-equivalent to each other. To simulate the thought process, here is an exercise:\n\\emph{Exercise} : Consider all $2$-coloured squares and the set of operations that are acting on it are defined by $G'=\\{R_0,R_{90},R_{180},R_{270}\\}$, i.e. we are not worried about the $H,V,D,D'$ rotations. Under this operations count the number of distinct $2$-coloured squares. \n\\\\\n\n\\Lecture{Jayalal Sarma}{Nov 11, 2020}{26}{Another step towards Polya's Theory }{Achyuth Prakash}{$\\alpha$}{JS}\n\\section{A quick recap}\n In last lecture, we defined and proved the orbit-stabilizer lemma and Lagrange's theorem. In this chapter the plan is to better understand \\emph{Polya's Theory} by going through a further example. \n\n\\section{Example 2: Coloring faces of a cube}\nLet us consider coloring the faces of a cube with $2$ colors. As before we define, $\\Omega$ as the set of all possible colorings. There are $6$ faces, and each can can be colored with $2$ colors, thus we have $|\\Omega| = 2^6 = 64$.\n\\\\\nNext we define the set of 'operations', $G$ which can act on elements on $\\Omega$. What are the different possible operations? We list them and simultaneously compute $|fix(g)|$:\n\\\\\nHere is the labelled cube for reference:\n\\\\\n\\includegraphics[]{./images/cube.png}\n\\\\\nThe different operations are:\n\\begin{itemize}\n\\item $R_0$ : Rotation by $0^{\\circ}$, i.e. identity. Since all elements of $\\Omega$ when acted upon by $R_0$ give back the same element, we get $|fix(g)| = 64$.\n\n\\item $R_1$ : Rotation by $180^{\\circ}$ w.r.t axis through the center of the opposite faces. (Observe that there are $3$ pairs of such faces). Now consider $2$ such faces, $A, D$. If we rotate the cube as per $R_1$, how many elements of $\\Omega$ remain unchanged? \n\\\\\nConsider the faces $A, D$. They can be colored with any color each. Thus, there are $2*2 = 4$ choices. Now, for the other faces, consider $C, F$. These $2$ must be colored with the the same color(because they exchange places) Thus there are $2$ choices for $C, F$ together. Similarly for $B, E$. Thus in total, there are $2^4 = 16$ elements which belong to $fix(g)$.\n\n\\item $R_2$ : Rotation by $90^{\\circ}$ w.r.t axis through the center of the opposite faces. Observe that there are $3$ pairs of such faces. Again let us compute $|fix(g)|$.\n\\\\\nConsider the faces $A, D$. They can be colored with any color each. Thus, there are $2*2 = 4$ choices. Now, for the other faces, they all must be colored with the same color, because, $C \\rightarrow B$, $B \\rightarrow F$, $F \\rightarrow E$, and $E \\rightarrow C$. Thus, there are $2$ choices for $B, C, E, F$ together. Hence, $|fix(g)| = 2^3 = 8$.\n\n\\item $R_3$ : Rotation by $270^{\\circ}$ w.r.t axis through the center of the opposite faces. Observe that there are $3$ pairs of such faces. Let us compute $|fix(g)|$.\n\\\\\nSince this is the exact opposite of the previous case, by symmetry, $|fix(g)| = 8$.\n\n\\item $R_4$ : Rotation by $180^{\\circ}$ w.r.t axis through the midpoints of opposite edges. Observe that there are $6$ pairs of such edges, i.e. $(de, bg),\\ (af, ch),\\ (ad, hg),\\ (cb, ef),\\ (ab, eh),\\ (cd, fg)$. To compute $|fix(g)|$, \n\\\\\nSuppose we do the rotation w.r.t the edges $(de, bg)$. then observe that, now $F$ is now the top face, and $A$ occupies the place where $E$ was initially, similarly, $B$ and $D$ swap places. Thus there are $2$ choices together for $C, F$, $2$ choices for $A, E$ and $2$ for $B, D$, giving $8$ choices overall.\nThus, $|fix(g)| = 8$.\n\n\\item $D$ : Diagonal flip by $120^{\\circ}$ w.r.t axis through the centers of opposite corners. First, note that there are $4$ pairs of opposite corners. To compute $|fix(g)|$,\n\\\\\nConsider the vertex $b$. If we flip the cube along $b$ by $120^{\\circ}$, then the face $B \\rightarrow C$, i.e. $B$ now occupies the initial position of $C$, $C \\rightarrow D$ and $D \\rightarrow B$. Thus together, for $B, C, D$ there are $2$ choices. Similarly for $A, E, F$. Thus totally we get $2*2 = 4$ possibilities, and $|fix(g)| = 4$.\n\n\\item $D'$ : Diagonal flip by $240^{\\circ}$ w.r.t axis through the centers of opposite corners. First, note that there are $4$ pairs of opposite corners. To compute $|fix(g)|$,\n\\\\\nBy symmetry, this is the opposite/complementary operation of the previous one, i.e. flip by $240^{\\circ}$ = flip by $120^{\\circ}$ in the other direction. Thus, $|fix(g)| = 4$.\n\\end{itemize}\n\nThus totally there are $1 + 3*3 + 6 + 4*2 = 24$ operations in $G$.\n\nNow, if we apply the formula to calculate the number of orbits, we get:\n$$\\#of \\ orbits \\ in \\ \\Omega =\\frac{1}{24}(64 + 3*16 + 3*8 + 3*8 + 6*8 + 4*4 + 4*4) = 10$$\n\nTherefore, we observe that out of the $64$ colorings, $10$ of them are in-equivalent.\n\n\\section{Cycle Index}\nWe now introduce and define the notion of cycle indices. Let $G$ be the set of some permutations on $\\Omega$. Let us decompose $g \\in G$ into a collection of disjoint cycles. \n\\\\\nFor example, let $n = 5$. Consider the permutation $3, 1, 2, 5, 4$ we write this as $(1, 2, 3)\\ (4, 5)$, i.e. this denotes $1 \\rightarrow 2$, (i.e. $1$ goes to position $2$), $2 \\rightarrow 3, 3 \\rightarrow 1$ and so on. \n\\\\\nSimilarly, the identity permutation, $1, 2, 3, 4, 5$ would be written as $(1)(2)(3)(4)(5)$.\n\\begin{definition}\n\\textbf{Type of permutation $\\pi$} : A permuatation $\\pi$ is said to be of type $(b_1, b_2, \\ldots b_m)$ if $b_i$ represents the number of $i$ length cycles in the cycle representation of $\\pi$.\n\\end{definition}\n\nFor example if $\\pi = (1, 2, 3)\\ (4, 5)$ then it is of type $(0, 1, 1, 0, 0)$, because there are no $1$ length cycles, $\\implies b_1 = 0$, one $2$ length cycle, i.e. $4 \\rightarrow 5 \\rightarrow 4 \\implies b_2 = 1$, and one $3$ length cycle.\n\nNow, corresponding to type $(b_1, b_2, \\ldots b_m)$ consider the monomial $x_1^{b_1}\\ x_2^{b_2} \\ldots x_m^{b_m}$. Using these terms we define a polynomial as follows:\n\\begin{definition}\nCycle index polynomial of $G$:\n\\end{definition}\n$$P(x_1, x_2, \\ldots x_m) = \\frac{1}{|G|} \\sum_{g \\in G} x_1^{b_1}\\ x_2^{b_2} \\ldots x_m^{b_m}$$ where $(b_1, b_2, \\ldots b_m)$ is the cycle type of $g$.\n\\\\\nWe observe that the above polynomial generalises the Burnside's lemma because we can now substitute the number of possible colors say $2$ in place of $x_1, x_2, \\ldots x_m$. Thus, this theorem is much more versatile.\n\\\\\n\n\\Lecture{Jayalal Sarma}{Nov 12, 2020}{27}{Polya's Theory - Part 1}{Achyuth Prakash}{$\\alpha$}{JS}\n\\section{Quick Recap}\nIn the last lecture, we went through another example(of coloring the faces of a cube) and defined the cycle index polynomial of $G$.\n\\\\\nConsider an example:\nLet $G$ be a group such that $G = \\{e, (1, 2),\\ (3, 4),\\ (1,2)(3,4)\\} \\le S_4$\ni.e., $G$ is a subgroup of $S_4$.\n\\\\\nThus, let us write down the cycle index polynomial of $G$:\n$$P(x_1, x_2, x_3, x_4) = \\frac{1}{4} (x_1^4 + x_1^2x_2 + x_1^2x_2 + x_2^2)$$\nWe get the RHS because $e$ has $4$ length $1$ cycles, thus we get the $x_1^4$ term, $(1, 2)$ has $2$ length $1$ cycles and $1$ length $2$ cycle, thus the term $x_1^2x_2$ and so on.\n\n\\section{Polya's Theorem - version 1}\n\\begin{theorem}\nPolya's theorem: Let $G$ be the group of symmetry acting on $\\Omega$, then, if the number of distinct colored patterns with $k$ colors = $N$, we have\n$$N = P_G(k, k, k, \\ldots k)$$,\nor $N = P(x_1, x_2, \\ldots x_m)$ with $x_1 = x_2 = \\ldots x_m = k$.\n\\end{theorem}\n\n\\begin{proof}\nLet the domain size be $= m$. (Here by domain we mean the number of different objects we need to color. For example in the squares example, we had $4$ corners and thus $m = 4$, similarly in the cube example, we had six faces to color, hence $m = 6$.) Then, the value of $|\\Omega|$ will be $k^m$.\n\\\\\nBy Burnside's lemma, WKT, \n$$Number\\ of\\ distinct\\ colorings\\ = Number\\ of\\ different\\ orbits\\ of\\ G = \\frac{1}{|G|} \\sum_{g\\in G}|fix(g)|$$\nLet us thus compute $|fix(g)|$ for $g \\in G$. \n\\\\\nAn example will make this more clear, before we generalize. Consider the previously discussed example of coloring the vertices of a square with $2$ colors. Then, we can think of each operation $g \\in G$ as a permutation. Consider the operation of rotating a square by $90^{\\circ}$, we can represent this by the cycle index $(1, 2, 3, 4)$, because $1 \\rightarrow 2,\\ 2 \\rightarrow 3, \\ldots$. Similarly, the operation of vertical flip corresponds to $(1, 2)\\ (3, 4)$. Consider this operation. Since $1 \\rightarrow 2$ and $2 \\rightarrow 1$, we observe that for $g$ to fix some element of $\\Omega$, the corners $1, 2$ must get the same color and corners $3, 4$ must get the same color. Thus there are $k$ choices for $1, 2$ together and $k$ choices for $3, 4$ and thus, totally $k^2$ colorings which are fixed by $g$.\n\\\\\nIn general, let the cycle structure of $g = (b_1, b_2, \\ldots b_m)$. This means, $g$ has $b_1$ cycles of length $1$, $b_2$ cycles of length $2$, and so on. Now, observe that all the elements that are part of a cycle must receive the same color, if $g$ were to fix the particular coloring. Thus for each cycle of length $i$, there are $k$ choices and as there are $b_i$ cycles of length $i$, there are $k^{b_i}$ choices for all of them. Thus, \n$$ the\\ number\\ of\\ colorings\\ fixed\\ by\\ g\\ = k^{b_1} * k^{b_2} \\ldots k^{b_m}$$\ni.e. $|fix(g)| = x_1^{b_1} * x_2^{b_2} \\ldots x_m^{b_m}$ with $x_1 = x_2 = \\ldots x_m = k$.\nThus, \n$$P_G(k, k, k, \\ldots k) = \\frac{1}{|G|} \\sum_{g\\in G}(k^{b_1} * k^{b_2} \\ldots k^{b_m}) = \\frac{1}{|G|} \\sum_{g\\in G}|fix(g)|$$\nHence proved.\n\\end{proof}\n\n\\section{Applying Polya's Theorem}\nWe now consider some examples and apply Polya's theorem for a more concrete understanding.\n\\subsection{Example 1 - Coloring Necklaces with circular beads}\nConsider a necklace with $3$ circular beads. We label the beads as $1, 2, 3$. First we ask: what are the possible symmetries? We get $G = \\{e, R_{120}, R_{240}, F_{12}, F_{23}, F_{31}\\}$, i.e. $e$ is the identity, $R_{120}$ represents a $120^{\\circ}$ clockwise rotation through the center, $F_{12}$ represents flipping w.r.t the edge $1-2$, etc. Now let us represent each $g \\in G$ as a cycle index permutation. Then we get that $G = \\{(1)(2)(3), (1, 2, 3), (1, 3, 2), (1, 2)(3), (1)(2, 3), (2)(1, 3)\\}$ respectively. Hence if we apply Polya's theorem, the number of distinct colorings = $\\frac{1}{6} (x_1^3 + 3x_1x_2 + 2x_3)$, if we consider coloring with $2$ distinct colors, then $k = 2 = x_1 = x_2 = x_3$, thus the number of distinct colorings with 2 colors = $\\frac{1}{6} (2^3 + 3*2^2 + 2*2) = 4$.\n\n\\subsection{Example 2 - Coloring faces of a cube}\nLet us revisit the cube example. We list the different elements of $G$ as before, and simultaneously calculate the term they contribute to in Polya's formula.\n\\\\\nHere is the labelled cube for reference:\n\\\\\n\\includegraphics[]{./images/cube.png}\n\\\\\n\\begin{itemize}\n\\item $R_0$ : Rotation by $0^{\\circ}$, i.e. identity. The cycle index of this permutation has $6$ cycles of length $1$, thus the number of colorings contributed will be $\\boxed{x_1^6}$.\n\n\\item $R_1$ : Rotation by $180^{\\circ}$ w.r.t axis through the center of the opposite faces. (Observe that there are $3$ pairs of such faces). Consider the faces $A, D$. We have observed before that $A, D$ remain in place, and $B, E$ and $C, F$ exchange their places, thus there are $2$ length $1$ cycles and $2$ length $2$ cycles, hence the contributing term will be $x_1^2x_2^2$. As there are $3$ such pairs of faces, the total number of fixed colorings will be $\\boxed{3x_1^2x_2^2}$.\n\n\\item $R_2$ : Rotation by $90^{\\circ}$ w.r.t axis through the center of the opposite faces. Observe that there are $3$ pairs of such faces. Consider the faces $A, D$. They retain their positions, i.e $A \\rightarrow A$, $D \\rightarrow D$. Now, for the other faces, we have, $C \\rightarrow B$, $B \\rightarrow F$, $F \\rightarrow E$, and $E \\rightarrow C$. Thus, there are $2$ length $1$ cycles and $1$ length $4$ cycle, hence the contributing term will be $x_1^2x_4$.As there are $3$ such pairs of faces, the total number of fixed colorings will be $\\boxed{3x_1^2x_4}$.\n\n\\item $R_3$ : Rotation by $270^{\\circ}$ w.r.t axis through the center of the opposite faces. Observe that there are $3$ pairs of such faces. Since this is the exact opposite of the previous case, by symmetry, the total number of fixed colorings will be $\\boxed{3x_1^2x_4}$.\n\n\\item $R_4$ : Rotation by $180^{\\circ}$ w.r.t axis through the midpoints of opposite edges. Observe that there are $6$ pairs of such edges, i.e. $(de, bg),\\ (af, ch),\\ (ad, hg),\\ (cb, ef),\\ (ab, eh),\\ (cd, fg)$. Suppose we do the rotation w.r.t the edges $(de, bg)$. Then observe that, now $F$ is now the top face, and $A$ occupies the place where $E$ was initially, similarly, $B$ and $D$ swap places. In other words, $C \\iff F$, $A \\iff E$ and $B \\iff D$, i.e. there are $3$ length $2$ cycles. Thus, the contributing term is $x_2^3$. As there are $6$ pairs of edges, the total contributing term will be $\\boxed{6 x_2^3}$.\n\n\\item $D$ : Diagonal flip by $120^{\\circ}$ w.r.t axis through the centers of opposite corners. First, note that there are $4$ pairs of opposite corners. \nConsider the vertex $b$. If we flip the cube along $b$ by $120^{\\circ}$, then the face $B \\rightarrow C$, i.e. $B$ now occupies the initial position of $C$, $C \\rightarrow D$ and $D \\rightarrow B$. Thus there is the cycle $B \\rightarrow C \\rightarrow D \\rightarrow B$. Similarly for the other three faces. Thus there are $2$ cycles of length $3$ and hence the contributing term will be $x_3^2$. As there $4$ such pairs of corners, the total term contributed will be $\\boxed{4x_3^2}$.\n\n\\item $D'$ : Diagonal flip by $240^{\\circ}$ w.r.t axis through the centers of opposite corners. First, note that there are $4$ pairs of opposite corners. By symmetry, this is the opposite/complementary operation of the previous one, i.e. flip by $240^{\\circ}$ = flip by $120^{\\circ}$ in the other direction. Thus, the total term contributed will be $\\boxed{4x_3^2}$.\n\\end{itemize}\n\nPutting all the above together, we get $$P_{G}(x_1, x_2, \\ldots x_4) = \\frac{1}{24}(x_1^6 + 3x_1^2x_2^2 + 6x_1^2x_4 + 6x_2^3 + 8x_3^2)$$\nif we substitute $x_i = 2$ for all $i$, we get \n$$P_{G}(x_1, x_2, \\ldots x_4) = \\frac{1}{24}(2^6 + 3*2^4 + 6*2^3 + 6*2^3 + 8*2^2) = 10$$\n\\\\\n\n\\section{Towards a general formula}\nLet us go back to the the example of the square coloring, where $G = \\{e, R_{90}, R_{180}, R_{270}, H, V, D, D'\\}$, and $G$ as a cycle index permutation is $G = \\{(1)(2)(3)(4), (1,2,3,4), (1, 3)(2, 4), (1,4,3,2), (1, 4)(2, 3), (1,2)(3,4), (2,4)(1,3), (1)(3)(2, 4), (2)(4)(1,3)\\}$ respectively.\n\\\\\nObserve the 2nd, 3rd, and 4th elements of $G$. We know that $R_{90} \\circ R_{90} = R_{180}$ i.e. $(1,2,3,4) \\circ (1,2,3,4) = (1,3)(2,4)$. Therefore these elements are of the form $g, g^2, g^3$.\n\\\\\nThus, if we have a group whose elements are of the form $G = \\{e, g, g^2, \\ldots g^k\\}$ (called cyclic groups). \nThen the contribution of each term of $g \\in G$ will be:\n\\begin{itemize}\n    \\item $e - x_1^n$\n    \\item $g - x_n$\n    \\item $g^2 - x_{n/2}^2$ and so on\n\\end{itemize}\nThus, in general, $$P_G(x_1, x_2, \\ldots x_m) = \\frac{1}{n} \\sum_{d|n} \\phi(d) x_{d}^{n/d}$$ where $\\phi(m)$ is euler's totient function.\n\\\\\n\\begin{proof}\nConsider the element $g^{i}$. Suppose it has a cycle of length $d$. Observe that under this operation, $1 \\rightarrow 1+i$, $1+i \\rightarrow 1+2i$, \\ldots, $1+d*i \\rightarrow 1$. This must mean $d*i$ is a multiple of $n$.  Specifically, we must have $d*i = lcm(n, i)$. Using $lcm(n,i) = \\frac{n*i}{gcd(n, i)}$, we get $d*i = \\frac{n*i}{gcd(n, i)} \\implies gcd(n,i) = \\frac{n}{d} \\implies \\boxed{gcd(d, \\frac{i*d}{n}) = 1}$.\n\\\\\nHowever there is a bijection between elements of $\\phi(d)$ and $i$, because $i = x \\frac{n}{d}$ for $x \\in \\phi(d)$. This implies the number of such $i = \\phi(d)$. Thus, the above result shows that all $i$ such that $gcd(d, i) = 1$ contribute $n/d$ cycles of length $d$. Therefore the contribution to the term is $\\phi(d) x_{d}^{\\frac{n}{d}}$. Hence the proof. \n\\end{proof}\n\nThus, if we have the above formula, the group for the square coloring problem can be represented as $\\{e, \\sigma, \\sigma^2, \\ldots, \\sigma^{k}, \\pi*\\sigma, \\pi*\\sigma^2, \\ldots \\pi*\\sigma^{k-1}\\}$. These are called dihedral groups. We discuss more about this in the next lecture.\n", "meta": {"hexsha": "ac1a60a93d49bda52191e370b8110c21e534e49e", "size": 37476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week09.tex", "max_stars_repo_name": "Mohit1098/theory-toolkit", "max_stars_repo_head_hexsha": "d7f5385604cead4cabc0911871b9b7e472c5969c", "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": "week09.tex", "max_issues_repo_name": "Mohit1098/theory-toolkit", "max_issues_repo_head_hexsha": "d7f5385604cead4cabc0911871b9b7e472c5969c", "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": "week09.tex", "max_forks_repo_name": "Mohit1098/theory-toolkit", "max_forks_repo_head_hexsha": "d7f5385604cead4cabc0911871b9b7e472c5969c", "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": 86.1517241379, "max_line_length": 814, "alphanum_fraction": 0.6896146867, "num_tokens": 12290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.645275430210751}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n \\subsection{Base Characterisation of a Matroid}\nAs quoted above, the bases of a matroid are the maximally independent sets of $\\mathcal{I}.$  These are most naturally visualised as being akin to a basis in a matrix. Where the basis of a matrix is a spanning set and every vector is a linearly combination of the basis. Bases are also spanning sets in  matroid. And as such have very useful properties that we will use extensively in later sections. Most notably, the collection of subsets $\\mathcal{I}$ can be generated using the bases (bases are not in general unique) due to the hereditary property $(I2).$ \\\\\nThe below theorem gives us a useful property that can be applied to the bases of a matroid, namely that the bases all have the same cardinality.\n \\begin{thm}\n Show that if $\\mathcal{I}$ is a non-empty hereditary set of subsets of a finite set E, then $(E,\\mathcal{I})$ is a matroid if and only if, for all $X \\subset E$, all maximal members of $\\{I : I \\in \\mathcal{I} $ and $ I \\subset X\\}$ have the same number of elements.\n \\end{thm}\n\\begin{proof}\n Let $B_1 , B_2$ be maximal elements of $\\{I : I \\in \\mathcal{I} $and $ I \\subset X\\}$ \\\\\n\\noindent Assume $|B_1| < |B_2|, B_1, B_2 \\in \\mathcal{I}$ and since we have a matroid\n\\\\\nthere exists $e \\in (B_2 \\setminus B_1)$ such that $B_1 \\cup \\{e\\} \\in \\mathcal{I}.$\n\\\\\nThis contradicts the maximality of $B_1$.\\\\\n \\noindent $\\implies$ All maximal elements of the set $\\{I : I \\in \\mathcal{I} $ and $ I \\subset X\\}$ in our matroid M have the same cardinality.\n\n\\end{proof}\n \\end{document}", "meta": {"hexsha": "a2aacf4fc98e8a53d58e1892a609ed13434c4569", "size": 1605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/char2.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/char2.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/char2.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": 84.4736842105, "max_line_length": 563, "alphanum_fraction": 0.7190031153, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6452754217714483}}
{"text": "\\documentclass[a4paper]{article}\n\n\\def\\ntitle{Quadratic fields}\n\\def\\ndate{}\n\n\\input{header}\n\n\\renewcommand*{\\O}{\\mathcal{O}}\n\\DeclareMathOperator{\\n}{N}\n\\DeclareMathOperator{\\disc}{disc}\n\\DeclareMathOperator{\\Cl}{Cl}%ideal class group\n\\newcommand*{\\red}[1]{\\overline{#1}}%reduction mod\n\n\\begin{document}\n\n\\maketitle\n\nLet \\(d \\in \\Z\\) be square-free and \\(d \\neq 0, 1\\). Then\n\\[\n  L = \\Q(\\sqrt d) = \\Q[x]/(x^2 - d)\n\\]\nis a degree \\(2\\) extension over \\(\\Q\\). It is called a \\emph{quadratic field}. If \\(d > 0\\) then there are two real embeddings, in which case we call \\(L\\) a real quadratic field. Otherwise \\(L\\) is an imaginary quadratic field. Note that in using this notation, we implicitly assume that there is a complex embedding \\(\\sigma: L \\to \\C\\).\n\n\\paragraph{Ring of integers}\n\nA particularly nice characterisation of algebraic intgers in a quadratic field is \\(\\alpha \\in \\O_L\\) if and only if \\(\\n_{L/\\Q}(\\alpha), \\tr_{L/\\Q}(\\alpha) \\in \\Z\\).\n\nSuppose \\(\\alpha = \\frac{u}{2} + \\frac{v}{2}\\sqrt d \\in \\O_L\\) where \\(u, v \\in \\Q\\). Then multiplication by \\(\\alpha\\) has with respect to the basis \\(\\{1, \\sqrt d\\}\\) matrix representation\n\\[\n  \\frac{1}{2}\n  \\begin{pmatrix}\n    u & vd \\\\\n    v & u\n  \\end{pmatrix}\n\\]\nso\n\\begin{align*}\n  \\n_{L/\\Q}(\\alpha) &= \\frac{1}{4}(u^2 - v^2d) \\in \\Z \\\\\n  \\tr_{L/\\Q}(\\alpha) &= u \\in \\Z\n\\end{align*}\n\nso \\(v^2d \\in \\Z\\). Suppose \\(v = \\frac{r}{s}\\) is an expression in coprime integers. Then \\(d^2r^2 \\in s^2\\Z\\) so \\(s^2 \\divides d^2r^2\\). If \\(p\\) is a prime dividing \\(s\\) then \\(p^2 \\divides d^2\\). As \\(d\\) is square-free, \\(p \\divides d\\). Absurd. Thus \\(v \\in \\Z\\) and\n\\[\n  \\Z[\\sqrt d] \\subseteq \\O_L \\subseteq \\frac{1}{2}\\Z[\\sqrt d].\n\\]\n\n\\begin{itemize}\n\\item If \\(d = 2, 3 \\pmod 4\\) then \\(u^2 = 0, 1 \\pmod 4, v^2 = 0, 1 \\pmod 4\\). As \\(u^2 = v^2d \\pmod 4\\), \\(u, v \\in 2\\Z\\) so \\(\\alpha \\in \\Z[\\sqrt d]\\). Thus \\(\\O_L = \\Z[\\sqrt d]\\).\n\\item If \\(d = 1 \\pmod 4\\) then \\(u^2 = v^2 \\pmod 4\\) so \\(u = v \\pmod 2\\). Thus\n  \\[\n    \\O_L \\subseteq \\left\\{ \\frac{u}{2} + \\frac{v}{2}\\sqrt d: u = v \\pmod 2 \\right\\} = \\Z \\oplus \\Z \\frac{1 + \\sqrt d}{2}.\n  \\]\n  Now check that \\(\\frac{1 + \\sqrt d}{2} \\in \\O_L\\) so we conclude that \\(\\O_L = \\Z[\\frac{1 + \\sqrt d}{2}]\\).\n\\end{itemize}\n\n\\paragraph{Discriminant}\n\nRecall that\n\\[\n  D_L\n  = \\det (\\sigma_i(\\alpha_j))^2\n  = \\det (\\tr_{L/\\Q}(\\alpha_i\\alpha_j))\n  = (-1)^{\\binom{n}{2}}\\n_{L/\\Q}(f'(\\alpha))\n\\]\nwhere \\(\\{\\alpha_i\\}\\) is an integral basis, \\(\\{\\sigma_i\\}\\) are the complex embeddings, \\(\\alpha\\) is a generator of \\(\\O_L\\) as a \\(\\Z\\)-algebra and \\(f\\) is the minimal polynomial whereof.\n\n\\begin{itemize}\n\\item If \\(d = 2, 3 \\pmod 4\\) then \\(\\alpha = \\sqrt d, f(x) = x^2 - d\\). Thus\n  \\[\n    D_L = -\\n_{L/\\Q}(2\\sqrt d) = 4d.\n  \\]\n  Alternatively, since \\(\\tr_{L/\\Q}(1) = 2, \\tr_{L/\\Q}(\\sqrt d) = 0\\), we can easily compute the matrix \\(\\tr_{L/\\Q}(\\alpha_i\\alpha_j)\\).\n\\item If \\(d = 1 \\pmod 4\\) then \\(\\alpha = \\frac{1 + \\sqrt d}{2}, f(x) = x^2 + x + \\frac{1 - d}{4}\\). Thus\n  \\[\n    D_L = -\\n_{L/\\Q}(\\sqrt d) = d.\n  \\]\n\\end{itemize}\n\n\\paragraph{Factorisation of ideals}\n\nRecall that Dedekind's criterion says that subject to certain divisibility condition, given \\(L = \\Q(\\alpha)\\) and \\(\\alpha \\in \\O_L\\) with minimal polynomial \\(f(x)\\) and \\(p\\) prime, if\n\\[\n  \\red f(t) = \\prod_{i = 1}^r \\red g_i(t)^{e_i} \\in \\F_p[x]\n\\]\nis a factorisation into irreducibles then\n\\[\n  (p) = \\prod_{i = 1}^r \\mathfrak{p}_i^{e_i}\n\\]\nis a factorisation into prime ideals.\n\n\\begin{itemize}\n\\item If \\(p = 2\\),\n  \\begin{itemize}\n  \\item if \\(d = 2, 3 \\pmod 4\\) then let \\(\\alpha = \\sqrt d\\) so\n    \\[\n      \\red f(x) = x^2 - d = (x - d)^2 \\in \\F_2[x]\n    \\]\n    so \\((2) = \\mathfrak{p}^2\\), i.e.\\ ramifies.\n  \\item if \\(d = 1 \\pmod 8\\) then let \\(\\alpha = \\frac{1 + \\sqrt d}{2}\\) so\n    \\[\n      \\red f(x) = x^2 + x + \\frac{1 - d}{4} = x^2 + x = x(x + 1) \\in \\F_2[x]\n    \\]\n    so \\((2) = \\mathfrak{p}\\mathfrak{q}\\), i.e.\\ splits completely.\n  \\item if \\(d = 5 \\pmod 8\\) then \\(\\red f(x) \\in \\F_2[x]\\) is irreducible so \\(2\\) is inert.\n  \\end{itemize}\n\\item If \\(p\\) is odd, let \\(\\alpha = \\sqrt d\\) and \\(f(x) = x^2 - d\\) so\n  \\begin{itemize}\n  \\item if \\(\\legendre{d}{p} = 0\\) then \\((p) = \\mathfrak{p}^2\\), i.e.\\ ramifies.\n  \\item if \\(\\legendre{d}{p} = 1\\) then \\((p) = \\mathfrak{p}\\mathfrak{q}\\), i.e.\\ splits completely.\n  \\item if \\(\\legendre{d}{p} = -1\\) then \\(p\\) is inert.\n  \\end{itemize}\n\\end{itemize}\n\n\\paragraph{Lattice}\n\nRecall that the covolume of a lattice formed by an ideal of the ring of integers is the volume of the parallelepiped spanned by its \\(\\Z\\)-basis.\n\nGiven an \\emph{imaginary} quadratic field \\(L\\), claim that\n\\[\n  A(I) = \\frac{1}{2}\\sqrt{|\\disc(I)|} = \\frac{\\n(I)}{2}\\sqrt{|D_L|}\n\\]\nfor \\(I \\subseteq \\O_L\\).\n\n\\begin{proof}\n  Let \\(\\alpha_1 = x_1 + iy_1, \\alpha_2 = x_2 + iy_2\\) be an integral basis for \\(I\\). Then\n  \\[\n    A(I) = \\left| \\det\n      \\begin{pmatrix}\n        x_1 & x_2 \\\\\n        y_1 & y_2\n      \\end{pmatrix}\n    \\right|.\n  \\]\n  Meanwhile\n  \\[\n    \\disc(I)\n    = \\det\n    \\begin{pmatrix}\n      x_1 + iy_1 & x_2 + iy_2 \\\\\n      x_1 - iy_1 & x_2 - iy_2\n    \\end{pmatrix}\n    ^2\n    = (2i)^2 \\det\n    \\begin{pmatrix}\n      x_1 & x_2 \\\\\n      y_1 & y_2\n    \\end{pmatrix}\n    ^2\n    .\n  \\]\n\\end{proof}\n\nBy Minkowski's theorem and multiplicativity of norm, we can deduce that for any number field \\(L\\), the ideal class group \\(\\Cl(\\O_L)\\) is finite and can be generated by the class of prime ideals \\(\\mathfrak{p}\\) with \\(\\n(\\mathfrak{p}) \\leq c_L\\) where \\(c_L = \\frac{2}{\\pi}\\sqrt{|D_L|}\\).\n\n\\begin{eg}\\leavevmode\n  \\begin{enumerate}\n  \\item \\(d = -7\\). As \\(d = 1 \\pmod 4\\), \\(D_L = -7\\). Thus\n    \\[\n      c_L = \\frac{2}{\\pi} \\sqrt 7 < \\frac{2}{3} \\sqrt 7 < 2\n    \\]\n    so \\(\\Cl(\\O_L)\\) is generated by ideals of norm \\(< 2\\). There are none except \\(\\O_L\\). Thus \\(\\Cl(\\O_L)\\) is trivial. Hence \\(\\O_L = \\Z[\\frac{1 + \\sqrt{-7}}{2}]\\) is a UFD.\n  \\item \\(d = -5\\). \\(D_L = -20\\) so\n    \\[\n      c_L = \\frac{2}{\\pi}\\sqrt{20} = \\frac{4}{\\pi}\\sqrt 5 < \\frac{4}{3} \\sqrt 5 < 3\n    \\]\n    so \\(\\Cl(\\O_L)\\) is generated by prime ideals \\(\\mathfrak p \\subseteq \\O_L\\) of norm \\(\\n(\\mathfrak p) = 2\\). We know by Dedekind's criterion that \\(2\\O_L = \\mathfrak p^2\\). Thus \\(\\Cl(\\O_L)\\) is generated by \\([\\mathfrak p]\\) and \\([\\mathfrak p]^2 = [2\\O_L] = [\\O_L]\\) is the trivial class. Hence there are two possibilities:\n    \\begin{enumerate}\n    \\item if \\(\\mathfrak p\\) is principal then \\(\\Cl(\\O_L)\\) is trivial.\n    \\item if \\(\\mathfrak p\\) is not principal then \\(\\Cl(\\O_L) \\cong \\Z/2\\Z\\).\n    \\end{enumerate}\n    But we already knew that \\(\\O_L\\) is not a UFD so \\(\\Cl(\\O_L)\\) is not trivial so must have\n    \\[\n      \\Cl(\\O_L) \\cong \\Z/2\\Z.\n    \\]\n  \\end{enumerate}\n\\end{eg}\n\nFor real quadratic fields \\(L = \\Q(\\sqrt d)\\), it is instructive as an exercise to derive the baby Minkowski constant, which should be \\(c_L = \\frac{1}{2}\\sqrt{|D_L|}\\).\n\n\\begin{eg}\n  \\(d = 10\\). Then \\(c_L = \\frac{1}{2} \\sqrt{4 \\cdot 10} < 4\\). By Dedekind's criterion,\n  \\begin{align*}\n    (2) &= \\mathfrak p_2^2 \\\\\n    (3) &= \\mathfrak p_3 \\mathfrak p_3'\n  \\end{align*}\n  What we can do at this stage is to compute the norm of some elements. For example \\(\\n(2 + \\sqrt{10}) = 6\\) so \\((2 + \\sqrt{10}) = \\mathfrak p_2 \\mathfrak p_3'\\) or \\(\\mathfrak p_2 \\mathfrak p_3'\\). In either case, \\([\\mathfrak p_2]\\) generates \\(\\Cl(\\O_L)\\). If \\(\\mathfrak p_2\\) is principal then there exists \\(a, b \\in \\Z\\) such that\n  \\[\n    a^2 - 10b^2 = \\pm 2.\n  \\]\n  Reduce modulo \\(5\\), \\(\\pm 2\\) is not a quadratic residue so impossible. Thus \\(\\Cl(\\O_L) \\cong \\Z/2\\Z\\).\n\\end{eg}\n\n\\begin{ex}\n  Find the class group of ring of integers of \\(\\Q(\\sqrt{-17})\\).\n\\end{ex}\n\n\\paragraph{Dirichlet's unit theorem}\n\nDirichlet's unit theorem states that there is an isomorphism\n\\[\n  \\O_L^\\times \\cong \\mu_L \\times \\Z^{r + s - 1}\n\\]\nwhere \\(\\mu_L\\) is the group of roots of unity in \\(\\O_L^\\times\\).\n\nThus \\(\\O_L^\\times\\) is finite if and only if\n\\begin{enumerate}\n\\item \\(r = 1, s = 0\\), so \\(L = \\Q\\), or\n\\item \\(r = 0, s = 1\\), so \\(L = \\Q(\\sqrt d)\\) for some \\(d \\in \\Z\\) negative square-free.\n\\end{enumerate}\n\nFor real quadratic fields \\(L = \\Q(\\sqrt d)\\), let \\(\\sigma: L \\to \\R\\) be the real embedding such that \\(\\sigma(\\sqrt d) > 0\\). As \\(\\sigma(\\mu_L) \\subseteq \\R^\\times\\), must have \\(\\mu_L =  \\{\\pm 1\\}\\). Consider the homomorphism\n\\begin{align*}\n  \\ell': \\O_L^\\times &\\to \\R \\\\\n  \\alpha &\\mapsto \\log |\\sigma(\\alpha)|\n\\end{align*}\nAs \\(\\ell'(\\O_L^\\times) \\subseteq \\R\\) is a lattice, there is a unique element \\(\\alpha \\in \\O_L^\\times\\) such that \\(\\sigma(\\alpha) > 0\\), \\(\\ell'(\\alpha)\\) generates the lattice. Then\n\\[\n  \\O_L^\\times = \\{\\pm \\alpha^n: n \\in \\Z\\}.\n\\]\nThis \\(\\alpha\\) is called the \\emph{fundamental unit}. It has the property that \\(\\log |\\sigma(\\alpha)|\\) is minimal, i.e.\\ \\(\\sigma(\\alpha) > 1\\) is minimal. This gives us a way to find fundamental units.\n\n\\begin{lemma}\n  Suppose \\(d = 2, 3 \\pmod 4\\), \\(v \\in \\O_L^\\times\\) and \\(v > 1\\). Then \\(v = a + b \\sqrt d\\) where \\(a \\geq b \\geq 1\\).\n\\end{lemma}\n\n\\begin{proof}\n  Let \\(v' = a - b \\sqrt d\\). Then\n  \\[\n    vv' = a^2 - db^2 = \\pm 1.\n  \\]\n  As \\(v > 1\\), \\(|v'| < 1\\) so\n  \\begin{align*}\n    2a &= v + v' > 0 \\\\\n    2b &= v - v' > 0\n  \\end{align*}\n  Also\n  \\[\n    \\left( \\frac{a}{b} \\right)^2 = d \\pm \\frac{1}{b^2} > 1.\n  \\]\n\\end{proof}\n\nThere is an entirely analogous result for \\(d = 1 \\pmod 4\\) which is left as an exercise.\n\nNow suppose \\(d = 2, 3 \\pmod 4\\). Suppose \\(u = a + b \\sqrt d \\in \\O_L^\\times\\) is the fundamental unit. Let \\(u^k = a_k + b_k \\sqrt d\\). Then\n\\begin{align*}\n  u^{k + 1}\n  &= u \\cdot u^k \\\\\n  &= (a_1 + b_1 \\sqrt d)(a_k + b_k \\sqrt d) \\\\\n  &= (a_1a_k + d b_1b_k) + (b_1a_k + a_1b_k) \\sqrt d\n\\end{align*}\nso\n\\[\n  b_{k + 1} = b_1a_k + a_1b_k \\geq 2b_k > b_k\n\\]\nso \\((b_k)_{k \\in \\N}\\) is strictly increasing. We can therefore characterise \\(u\\) as follow: let \\(b \\in \\N\\) be the least positive integer such that \\(db^2 + 1\\) or \\(db^2 - 1\\) is of the form \\(a^2\\) for some \\(a \\in \\N\\). Then \\(u = a + b \\sqrt d\\) is the fundamental unit.\n\nIf instead \\(d = 1 \\pmod 4\\), we get\n\\[\n  b_{k + 1} = \\frac{1}{2}(b_1a_k + a_1b_k) \\geq b_k\n\\]\nwith equality if and only if \\(a_1 = b_1 = 1, a_k = b_k\\). In this case\n\\[\n  \\n(u) = \\left| \\frac{1 - d}{4} \\right| = 1\n\\]\nso \\(d = 5\\). In this case \\(u = \\frac{1}{2} (1 + \\sqrt 5)\\) is the fundamental unit.\n\nIf instead \\(d > 5\\), we proceed as before and characterise \\(u\\) as follow: let \\(b \\in \\N\\) be the least positive integer such that \\(db^2 + 4\\) or \\(db^2 - 4\\) is of the form \\(a^2\\) for some \\(a \\in \\N\\). Then \\(u = \\frac{1}{2} (a + b \\sqrt d)\\) is the fundamental unit.\n\n\\begin{eg}\\leavevmode\n  \\begin{enumerate}\n  \\item \\(d = 2\\). Then \\(b = 1\\) works since \\(2 - 1 = 1^2\\) so \\(1 + \\sqrt 2\\) is a fundamental unit.\n  \\item \\(d = 7\\).\n    \\begin{align*}\n      & b = 1: 7 \\pm 1 \\text{ not a square} \\\\\n      & b = 2: 4 \\cdot 7 \\pm 1 \\text{ not a square} \\\\\n      & b = 3: 9 \\cdot 7 + 1 = 8^2\n    \\end{align*}\n    so \\(8 + 3 \\sqrt 7\\) is a fundamental unit.\n  \\end{enumerate}\n\\end{eg}\n\n\\end{document}\n", "meta": {"hexsha": "08757b07f75c514f34e23e0a649e07e7fb5e4f89", "size": 11049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blurb/quadratic_fields.tex", "max_stars_repo_name": "geniusKuang/tripos", "max_stars_repo_head_hexsha": "127e9fccea5732677ef237213d73a98fdb8d0ca0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2018-01-15T05:02:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T15:48:31.000Z", "max_issues_repo_path": "blurb/quadratic_fields.tex", "max_issues_repo_name": "b-mehta/tripos", "max_issues_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-11T20:43:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T21:29:15.000Z", "max_forks_repo_path": "blurb/quadratic_fields.tex", "max_forks_repo_name": "b-mehta/tripos", "max_forks_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2017-11-08T16:16:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T17:20:19.000Z", "avg_line_length": 39.0424028269, "max_line_length": 340, "alphanum_fraction": 0.5677436872, "num_tokens": 4481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6452754201637827}}
{"text": "\\section*{Summary of Section 2}\n\\begin{enumerate}\n  \\item The group $\\bbz/100$ of 2-digit integers sits in a short exact sequence/group extension\n  \\begin{equation*}\n    \\begin{tikzcd}\n      0 \\ar[r] & \\bbz/10 \\ar[r,\"i\"] &  \\bbz/100  \\ar[r,\"p\"] & \\bbz/10 \\ar[r] & 0 \\\\\n       & \\mbox{tens} \\ar[u, equal]  &  \\mbox{2-digit numbers}  \\ar[u,equal] & \\mbox{units}  \\ar[u, equal] &\n    \\end{tikzcd}\n  \\end{equation*}\n\n  \\item Every group extension arises in this manner.\n  For an extension of abelian groups,\n  \\begin{equation*}\n    \\begin{tikzcd}\n      0 \\ar[r] & H \\ar[r,\"i\"] &  G  \\ar[r, \"p\"] & K \\ar[r] & 0.\n    \\end{tikzcd}\n  \\end{equation*}\n  every element of $G$ can be uniquely written as $\\units{a}\\tens{b}$ for some $a \\in H$ and $b \\in K$.\n\\end{enumerate}\n\n\n\\vspace{2cm}\n\\hrule\n\\vspace{2cm}\n\n% Show that for every element $g \\in G$, there exist unique elements $a \\in H$ and $ b \\in K $ such that $g = \\units{a}\\tens{b}$.\n% \\hint{Look at $p(g)$ and $g - [p(g)]\\units{0}$.}\n\\begin{proof}[Solution to Q.\\ref{q:existenceOfDigits}]\n  We will only prove existence as uniqueness follows by Q.\\ref{q:uniquenessOfDigits}.\n\n  Consider the element $g \\in G$. Let $b = p(g) \\in K$ and let \\begin{equation*}\n    h = g - \\tens{0}\\units{b}.\n  \\end{equation*}\n  Applying $p$ to both sides we get\n  \\begin{align*}\n    p(h)\n    &= p(g - \\tens{0}\\units{b}) \\\\\n    &= p(g) - p(\\tens{0}\\units{b}) && \\mbox{ as $p$ is a group homomorphism}\\\\\n    &= b -b \\\\\n    &= 0\n  \\end{align*}\n  Hence, $h \\in \\ker p$, which implies that $h \\in \\im i$.\n  Hence, $ h = i(a) = \\tens{a}\\units{0}$ for some $a \\in H$, giving us\n  \\begin{equation*}\n    g = h + \\tens{0}\\units{b} = \\tens{a}\\units{0} + \\tens{0}\\units{b} = \\tens{a}\\units{b}.\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "d5d4fee81a539036ddf962b064414100d0e37006", "size": 1737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02Summary.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": "02Summary.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": "02Summary.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": 36.1875, "max_line_length": 129, "alphanum_fraction": 0.5877950489, "num_tokens": 694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896956, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6452754184759222}}
{"text": "\\section{Part 2.a Numerical Integrator}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_a.py}\n\nThe result of this function is given by:\n\n\\lstinputlisting{2a.txt}\n\n\\section{Part 2.b Interpolation}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_b.py}\n\nMy script produces the following result, see Fig. \\ref{fig:interp}. This shows the differences between the linear\ninterpolation and cubic spline. Both are essentially the same for this data, except between 0.1 and 1. In comparison to\nthe actual values, the interpolated values underestimate for all values between $x$ = 1 and $x$ = 5.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/interpolation.png}\n  \\caption{The interpolation function in action.}\n  \\label{fig:interp}\n\\end{figure}\n\n\\section{Part 2.c Numerical Derivative}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_c.py}\n\nThe result of this function is given by:\n\n\\lstinputlisting{2c.txt}\n\n\\section{Part 2.d Random Sampling}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_d.py}\n\nMy script produces the following result, see Fig. \\ref{fig:rand_sample}\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/random_sample.png}\n  \\caption{The results of the random sample with rejection sampling.}\n  \\label{fig:rand_sample}\n\\end{figure}\n\nThe positions in (r, $\\phi$, $\\theta$) are given by:\n\n\\lstinputlisting{2d.txt}\n\n\\section{Part 2.e 1000 Haloes}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_e.py}\n\nMy script produces the following result, see Fig. \\ref{fig:1000_haloes}. As can be seen, the generated galaxies mostly match\nthe $N(x) = n(x)4\\pi x^2$ distribution.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/1000_haloes.png}\n  \\caption{The results of 1000 haloes each with 100 satellites. }\n  \\label{fig:1000_haloes}\n\\end{figure}\n\n\\section{Part 2.f Root Finding}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_f.py}\n\nThe result of this function is given by:\n\n\\lstinputlisting{2f.txt}\n\n\\section{Part 2.g Percentiles and Poisson}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_g.py}\n\nThe median, 16th, and 84th percentiles for the radial bin with the largest number of falaxies is given in:\n\n\\lstinputlisting{2g.txt}\n\nMy script produces the following result, see Fig. \\ref{fig:hist_poisson}. As can be seen, histogram fairly closely follows\nthe Poisson distribution with $\\lambda$ equal to the mean number of galaxies in this radial bin.\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{./plots/hist_poisson.png}\n  \\caption{The results of 1000 haloes each with 100 satellites. }\n  \\label{fig:hist_poisson}\n\\end{figure}\n\n\\section{Part 2.h 3D interpolator}\n\nThe file of the functions used for this exercise is:\n\n\\lstinputlisting{two_h.py}\n\nWhile no output was requested, I did test the 3D interpolator, with the a,b,and c values generated earlier.\nThe error is quite large for these, which I believe is a result of the linear interpolation used. Cubic splines took too\nlong to run, and were expensive to create.\n\n\\lstinputlisting{2h.txt}\n\n\n\n", "meta": {"hexsha": "5321cabe7259ddb723bb049be1a7f75b5f0c7b4a", "size": 3269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "part_2.tex", "max_stars_repo_name": "jacobbieker/NUR", "max_stars_repo_head_hexsha": "bfcf938efca9a4506ba36a521cbce3030b56b06c", "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": "part_2.tex", "max_issues_repo_name": "jacobbieker/NUR", "max_issues_repo_head_hexsha": "bfcf938efca9a4506ba36a521cbce3030b56b06c", "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": "part_2.tex", "max_forks_repo_name": "jacobbieker/NUR", "max_forks_repo_head_hexsha": "bfcf938efca9a4506ba36a521cbce3030b56b06c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-08T21:14:04.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-08T21:14:04.000Z", "avg_line_length": 27.9401709402, "max_line_length": 124, "alphanum_fraction": 0.7629244417, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.6452754167880616}}
{"text": "\n% This LaTeX was auto-generated from MATLAB code.\n% To make changes, update the MATLAB code 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\\section*{HOMEWORK 1 - FRANCISCO CASTILLO}\n\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Problem 2\n\\end{itemize}\n\n\n\\subsection*{Problem 2}\n\n\\begin{verbatim}\nformat long;clear all;close all;clc\nx_0=33.3;\nf = @(x) (1+2*x^2*cos(x))/(x^(2.4));\nfp = @(x) (2*x^2*(2*cos(x)-x*sin(x))-2.4*(1+2*x^2*cos(x)))/(x^3.4);\nfor k = -3:1:25\n    H(k+4) = 2^(-k);\nend\nfor k = 1:length(H)\n    h = H(k);\n    df1(k) = (f(x_0+h)-f(x_0))/h;\n    df2(k) = (f(x_0+h)-f(x_0-h))/(2*h);\n    df6(k) = (45*(f(x_0+h)-f(x_0-h))-9*(f(x_0+2*h)-f(x_0-2*h))...\n        +(f(x_0+3*h)-f(x_0-3*h)))/(60*h);\nend\nlinewidth=2;\ndarkgreen=[0 0.6 0];\nfigure('units','normalized','outerposition',[0 0 1 1])\nloglog(H,abs(df1-fp(x_0)),'*',H,abs(df2-fp(x_0)),'*')\nhold on\nloglog(H,abs(df6-fp(x_0)),'*','Color',darkgreen)\nloglog(H,H/2,'b--',H,H.^(2)/6,'r--','linewidth',linewidth)\nloglog(H,H.^(6)/140,'--','Color',darkgreen,'linewidth',linewidth)\nloglog(H,eps./H,'k:','linewidth',linewidth)\nset(gca,'fontsize',14)\naxis([1e-8 1e1 1e-20 1e5])\ngrid on\nxlabel('$h$ (log scale)','fontsize',20,'interpreter','latex')\nylabel('Error (log scale)','fontsize',20,'interpreter','latex')\nsaveas(gcf,'IMAGES/problem2_1','epsc')\nsaveas(gcf,'IMAGES/problem2_1','fig')\n\\end{verbatim}\n\n\\includegraphics [width=4in]{HW1_01.eps}\n\n\n\n\\end{document}\n    \n", "meta": {"hexsha": "d7bbd9816a72ace8c40bc8c901459fdd114a95ce", "size": 1600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/CFD/Homework 1/html/HW1.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 1/html/HW1.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 1/html/HW1.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": 23.1884057971, "max_line_length": 70, "alphanum_fraction": 0.62875, "num_tokens": 627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6452754134123405}}
{"text": "\\section{Mean-field approximation for Ising Model}\nThis is the main equation\n\\begin{align}\n    h_{\\mathrm{eff}}\n    &=\n    h\n    +\n    4J T gh \\beta h_{\\mathrm{eff}}\n\\end{align}\nThe critical temperature\n\\begin{align}\n    k_B T_c &= 4J\n\\end{align}\nThe susceptibility\n\\begin{align}\n    \\chi\n    &=\n    \\frac{1}{\\beta}\n    \\left.\\frac{\\partial m}{\\partial h}\\right|_{T=T_c, h=0}\n    \\sim\n    \\left| T - T_c \\right|^{\\overbrace{-1}^{\\gamma}}\n\\end{align}\nand the magnetisation is\n\\begin{align}\n    m &\\sim\n    \\left| T - T_c \\right|^{\\overbrace{1/2}^{\\beta}}\n\\end{align}\nI can then write\n\\begin{align}\n    \\underbrace{h_{\\mathrm{eff}}}_{h + 4Jm}\n    &=\n    h\n    +\n    4 J T gh \\beta h_{\\mathrm{eff}}\n\\end{align}\nwhich implies\n\\begin{align}\n    m &=\n    Tgh \\beta \\left( 4J m + h \\right)\n\\end{align}\nso\n\\begin{align}\n    4J m + h\n    &=\n    \\frac{1}{\\beta_c}\n    \\arctanh m\\\\\n    &\\approx\n    \\frac{1}{\\beta_c}\n    \\left( \n    m\n    +\n    \\frac{m^3}{3}\n    + \\cdots\n    \\right)\n\\end{align}\nso then\n\\begin{align}\n    h \\sim m^{\\overbrace{3}^{\\delta}}\n\\end{align}\nwhich is not obvious at all.\n\nThe relation between $m$ and $h$ depends on that equation,\nbut depends only on the fact that this s an odd function and that it is smooth.\nThis is very robust because even though it's only approximate.\n\nThere are perfect analogies of mean field all over physics.\nIn fact you've seen those before.\nSo I'm going to erase this and I'm going to make some drawings in two different\ncolours.\nOn the left we have the mean field approximation,\nand on the right I'm going to tell another thing that you already know,\nwhich are fluids that obey the van der Waals equation of state.\n\n\\subsection{Ising}\nI'm going to draw the external magnetic field vs the temperature.\nThis is $T_c$.\nWhat happens when I'm above $T_c$ and I have a negative $h$?\nIt favours spin down so magnetisation is going to be down.\nIf $h>0$,\nthen up is favoured.\nIf the magnetic field is zero,\nthen it's zero.\nSo nothing interesting happens here when I cross $h=0$ for $T>T_c$.\n\nNow below $T_c$,\nthe magnetisation doesn't go to zero.\nWhen $h$ is slightly negative,\nthey are all spin down.\n\nThe discontinuity disappears in the critical region.\n\nThe analogy with the van der Waals fluid is\n\\begin{align}\n    h &\\sim P\\\\\n    m &\\sim \\frac{1}{V}\n\\end{align}\n\n[lots of pictures]\n\nIn a lot of systems,\nthere is an order parameter $\\phi$ such that its average value is\n\\begin{align}\n    \\begin{cases}\n        \\langle \\phi \\rangle\n        =\n        0 & T > T_c\\\\\n        \\langle \\phi \\rangle\n        \\ne\n        0 & T > T_c\n    \\end{cases}\n\\end{align}\nIf there is such a situation,\nthen there is spontaneous symmetry breaking.\nThe order parameter doesn't have the symmetry of the Hamiltonian,\nbecause when it flips it flips sign,\nbut the Hamiltonian doesn't change.\nThe thermal average is not zero,\neven though it should be naively if you look at the Hamiltonian.\n\nA lot of cases,\nwhen the expectation picks up a non-zero expectation value like this,\nfrequently this means spontaneous symmetry breaking.\n\nIt happens even when equal to zero.\n\nIt's worth while going close to the critical point and looking at the\nconfiguration that contributes the most.\nThe ones with smallest energy are ordered and there are few of them.\nThey are not typical.\nThe more typical ones are the high energy ones.\n\nI'm going to try to draw some configurations that are critical.\n\n[picture]\n\nWhen above the critical temperature,\nthe typical size of clusters $\\xi\\approx a$,\nthe lattice size.\nWhen at $T=T_c$,\nyou're going to get clusters of all sizes,\nfrom the size of a lattice spacing to large clusters that go from one corner of\nthe system to another,\nand everything in between.\n\nSo we talk about the critical exponents in the mean field model.\nI want it to be the centre piece of everything we compute here.\nIt turns out that close to the critical point,\nthe heat capacity diverges.\n\\begin{align}\n    C &\\sim \\left| T - T_c \\right|^{-\\alpha}\n\\end{align}\nLet's compute $\\alpha$.\n\nThe magnetisation when you approach the critical temperature is like\n\\begin{align}\n    m ~ \\left| T - T_c \\right|^{\\beta}\n\\end{align}\nand the susceptibility\n\\begin{align}\n    \\chi &=\n    \\left| \\frac{\\partial m}{\\partial h} \\right|_{h=0}\n    \\sim\n    \\left| T - T_c \\right|^{-\\gamma}\n\\end{align}\nSuppose we calculate the correlation\nabout how close or far spins influence each other\n\\begin{align}\n    \\left\\langle\n    \\sigma_0\n    \\sigma_{0 + R}\n    \\right\\rangle\n    &\\sim\n    e^{-R/\\xi}\n\\end{align}\nand this parameter $\\xi$ is the correlation length,\nwhich is measurer f how far you need to go to not get correlation.\nThe correlation length diverges too at the critical temperature.\n\\begin{align}\n    \\xi &\\sim\n    \\left| T - T_c\\right|^{-\\nu}\n\\end{align}\nI didn't show you but $\\nu=\\frac{1}{2}$ for mean field Ising.\n\nI can take a Fourier transform.\n\nThis is the only integral you need to do in your head\n\\begin{align}\n    \\sum_{\\vec{R}}\n    \\left\\langle\n    \\sigma_0\n    \\sigma_{0 + R}\n    \\right\\rangle\n    e^{i\\vec{k}\\cdot\\vec{R}}\n    \\sim\n    \\frac{1}{k^{2 - \\eta}}\n\\end{align}\nwhere $\\eta$ is called the \\emph{anomalous dimension}.\n\n\\section{Universality classes}\nNumerical experiments and exact results.\nThe Ising model in 2D was solved exactly on paper.\nFirst surprise,\nit's not what mean field theory says.\nIt maybe shouldn't surprise you much,\nbecause mean field was a bit hand waving anyway.\n\nBut the surprising thing was a different one.\nIt wasa big surprise back them.\n\nThere was a theory called Landau mean field theory,\na lot of hand wavin,\nbut it's Landau hand waving,\nand he talks to God directly.\nIt's like mean field theory on steroids.\nTremendous theory,\nno argument whatsoever.\n\nThen you find something interesting with the exact solution.\nThere are what we call Universality classes.\n\nPeople looked at the 2D Ising model.\nPeople made this relation between this and the liquid phase transition.\nYou can measure the critical exponents of water evapoerating,\nand you find it's 3D Ising model.\nOne is a stupid magnet model,\none is a real system.\nThey agree within error bars.\nBut then you look at other systems,\nand there are sets of critical exponents that appear frequently.\n\nThe critical exponents of the 3D Ising model are common,\nprobably the most common one.\nAnd then there are other common ones.\nThe systems are completely diffrent.\nIn the notes,\nI give some critical exponents calculated from numerics,\nconformal bootstrap.\nLet me just write these here.\n\\begin{table}\n    \\centering\n    \\begin{tabular}{cccc}\n        & 3D Ising & CO$_2$ & Ni Magnet\\\\\n        $\\alpha$ & 0.11008(1) & 0.10 & 0.0(?)\\\\\n        \\vdots\\\\\n        $\\delta$ & 4.28984(1) & 4.20 & 4.22\n    \\end{tabular}\n    \\caption{Critical Exponents Theory vs Experiment}%\n    \\label{tab:criticalexponents}\n\\end{table}\nThere's an uncertainty for Ni magnet that I don't know.\nAll systems in nature seem to fall into \n\nHere are some common universality classes\n\\begin{itemize}\n    \\item 3D Ising\n    \\item 2D Ising\n    \\item Mean field\n    \\item Kosterlitz-Thouless\n    \\item 3-Potts model\n\\end{itemize}\nI knew Thouless.\nA lot of things come from experience.\nPeople get data and they see a pattern.\nRoughly the pattern people see is the following.\n\nThe first thing you have to discern is the dimensionality of the state.\nThe other one is more subtle,\nit's the ``pattern of spontaneous symmetry breaking''.\nFor example,\nconsider the Ising model.\nThe Hamiltonian has a symmetry $\\mathbb{Z}_2$\nwhich is basically spin flip.\nThis symmetry has 2 elements,\ndo nothing and flip all the spins.\nThe point is that at low temperatures,\nthe magnetisation,\nthe order parameter,\nis not zero.\nIt's pointing either up or down.\nWhen I did a spin flip,\nI get a different state.\nWhat's the symmetry of the sate below the critical temperature?\nThat's what I mean by a matter of symmetry breaking,\nhow it's broken to the final state\n$\\mathbb{Z}_2 \\to \\textrm{nothing}$.\n\nAnother model is the Heisenberg model,\nevery point on a lattice has a spin-$\\frac{1}{2}$ on it.\nYou can make it ferromagnetic or antiferromagnetic or whatever.\nThe point is that it's not just up or down,\nit could be many other states you can rotate by.\n\nThe dot product between two spins stays the same under rotation.\nPeople call this SO(3),\nwhich are 3 by 3 orthogonal matrices.\nThe special orthogonal matrices.\nAlso known as rotations.\nYou don't know this,\nbut the ferromagnetic model,\nthe ground state is all spins pointing in the same direction,\nbecause that maximizes the dot product and minimized the energy just like thei\nIsing model.\n\nSuppose this direction is picked up,\nthere's still some symmetry left.\nIf I do rotations around this axis,\nthe magnetisation order parameter doesn't change.\n$SO(3) \\to O(2)$.\n\nThere is a particular type of liquid crystal called nematic liquid crystal.\nHow can something be a liquid and a crystal at the same time?\nIt's made of long molecules,\nand the head and tails are different.\nIt turns out below a certain critical temperature,\nthey organize themselves like this.\nTheir position is not organized on a crystal,\nlike a liquid,\nnot organized in a nice pattern.\nTheir direction is not organized either,\nthere are as much head up and head down.\nThe only thing is that they are all aligned that way.\nThe Hamiltonian has a symmetry that they can rotate any direction they like.\nHere there's nothing to point,\nthe order parameter is a tensor.\nBut it can still flip.\n\\begin{align}\n    SO(3) \\to O(2)\\times \\mathbb{Z}_3\n\\end{align}\nRotation goes to 2D rotation and flips.\n\nMeanwhile there are other liquid crystals\nwhere the centres of molecule positions are fixed by the orientation are not.\n\nRemember the Bose gas,\nwhich has a phase transition,\na condensate.\nI claimed that it's superfluid.\nI'm not even going to attempt to explain.\nThe pattern of symmetry breaking in that case is $U(1)$.\nThat's exactly the same group as $O(2)$ by the way.\nThis is broken to almost nothing.\nThis phase has to do with changing the wave function by a phase\n$\\psi \\to e^{i\\beta} \\psi$.\nSuperfluid helium and BEC follow this pattern,\nand they have their own universality class.\n\nYou probably heard something that if you look at the physics of elementary\nparticles,\nthere is a symmetry\n\\begin{align}\n    SU_c(3)\n    \\times\n    SU_w(2)\n    \\times\n    U_Y(1)\n    \\to\n    SU_c(3)\n    \\times\n    U_{EM}(1)\n\\end{align}\nIf you have 2 systems with the same dimension,\nthey follow the same universality class.\nThat was an experimental observation.\n\nExamples.\n\nConsider the Ising model in 2D\n\\begin{align}\n    H &=\n    -J \\sum \\sigma_i \\sigma_j\n\\end{align}\nconsider my made up Paulo model\n\\begin{align}\n    H^P &=\n    -J \\sum_{\\textrm{plaquette}}\n    \\sigma_{i} \\sigma_{j} \\sigma_{k} \\sigma_{l}\n\\end{align}\nThey have the same dimensionality and the same pattern of spontaneous symmetry\nbreaking so they should have the same critical exponents.\nSame for the sum\n\\begin{align}\n    H &=\n    -\\tilde{J} \\sum \\sigma_i \\sigma_j\n    -J \\sum_{\\textrm{plaquette}}\n    \\sigma_{i} \\sigma_{j} \\sigma_{k} \\sigma_{l}\n\\end{align}\n", "meta": {"hexsha": "fb110ab71fd9f640a0bb09cceb7418945dad6661", "size": 11062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture33.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/lecture33.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/lecture33.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.5839793282, "max_line_length": 79, "alphanum_fraction": 0.7226541313, "num_tokens": 3021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6452754109206471}}
{"text": "% IRAM.tex\n\\documentclass[12pt]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath}\n\n\n\\title{Post-Processing Arnoldi's Method}\n\\author{Jeremy L. Conlin}\n\n\\newcommand{\\A}{\\mathbf{A}}\n\\newcommand{\\qp}[1]{q'_{#1}}\n\\newcommand{\\qh}[1]{\\hat{q}_{#1}}\n\\newcommand{\\qt}[1]{\\tilde{q}_{#1}}\n\\newcommand{\\qc}[1]{\\check{q}_{#1}}\n\\newcommand{\\Aq}[1]{\\A q_{#1}}\n\\newcommand{\\Ap}[1]{\\A \\qp{#1}}\n\\newcommand{\\Ah}[1]{\\A \\qh{#1}}\n\\newcommand{\\At}[1]{\\A \\qt{#1}}\n\\newcommand{\\Ac}[1]{\\A \\qc{#1}}\n\n\\begin{document}\n\\maketitle\n\nThe purpose of this document is to explore the possibility of performing an Arnoldi factorization by post-processing a set of Krylov vectors.\n\n\\section{The beginning}\nSuppose we have the matrix\n\\begin{equation*}\n    \\A \\equiv \\begin{pmatrix} 1 & 0 & 0 & 0 & 0 \\\\\n                              0 & 2 & 0 & 0 & 0 \\\\\n                              0 & 1 & 3 & 0 & 0 \\\\\n                              0 & 0 & 0 & 4 & 0 \\\\\n                              0 & 0 & 0 & 0 & 5 \\end{pmatrix}.\n\\end{equation*}\nThis problem is not specific to this matrix, but this matrix is easily studied.\n\nA Krylov subspace of dimension $k$ is defined as \n\\begin{equation}\n    \\mathcal{K}_k \\equiv \\left\\{q, \\A q, \\A^2, \\ldots, A^{k-1}q\\right\\} = \\left\\{q_0, q_1, \\ldots, q_k\\right\\}.\n    \\label{eq:KrylovSubspace}\n\\end{equation}\nThe simplest way to construct a basis for a Krylov subspace is to repeatedly apply a linear operator (in our case the matrix $\\A$) to a vector $q$.  This is what is done with the power method which is used to calculate the dominant eigenvalue of the linear operator.  \n\n\\section{Arnoldi's Method}\nArnoldi's method generates the same Krylov subspace found in Equation \\ref{eq:KrylovSubspace} but orthonormalizes the basis vectors.  The question remains if we can begin with Krylov subspace and orthogonalize and normalize the vectors after the fact to create the Arnoldi factorization\n\\begin{equation}\n    \\A V = V H.\n    \\label{eq:ArnoldiFactorization}\n\\end{equation}\n\nTo begin, let's rewrite Equation \\ref{eq:KrylovSubspace} as\n\\begin{equation}\n    \\mathcal{K}'_k \\equiv \\left\\{q, \\A q, \\A^2, \\ldots, A^{k-1}q\\right\\} = \\left\\{\\qp{0}, \\qp{1}, \\ldots, \\qp{k}\\right\\}.\n\\end{equation}\nThis is merely to keep our notation straight.  Another way to write this is\n\\begin{subequations}\\begin{align}\n    \\qp{0} &\\equiv q_0 \\\\\n    \\qp{1} &= \\A \\qp{0} \\\\\n    \\qp{2} &= \\A \\qp{1} \\\\\n    &\\ldots \\\\\n    \\qp{k} &= \\A \\qp{k-1}.\n    \\label{}\n\\end{align}\\end{subequations}\n\nWe have already applied our linear operator $k$ times and have our $k$-dimensional Krylov subspace.  Can we then orthogonalize it and keep it mathematically equivalent to creating an Arnoldi factorization in the traditional fashion.\n\nLet's begin with the first iteration.\n\n\\begin{align}\n    \\qh{1} &= \\Aq{0} \\\\\n    \\qt{1} &= \\qh{1} - h_{0,1}*q_0 \\\\\n    q_1 &= \\qt{1}/\\left|\\qt{1}\\right|.\n\\end{align}\n\nThere is nothing special here.  For a 1-dimensional subspace, we could create a post-Arnoldi factorization from a Krylov subspace.  Of course if that's all we can do, then it isn't very interesting.  Let's move onto the second iteration.\n\n\\begin{subequations}\n    \\begin{align}\n    \\qh{2} &= \\A q_1 \\\\\n    &= \\frac{1}{\\left|\\qt{1}\\right|}\\At{1} \\\\\n    &= \\frac{1}{\\left|\\qt{1}\\right|}\\A \\left\\{\\qh{1}-h_{0,1}*q_0\\right\\} \\\\\n    &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\Ah{1}-h_{0,1}*\\Aq{0}\\right\\} \\\\\n    &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\Ah{1}-h_{0,1}*\\qh{1}\\right\\} \\label{eq:2Ihat}.\n    \\end{align}\n\\end{subequations}\nEquation \\ref{eq:2Ihat} contains only one application of the linear operator that hasn't already been performed.  Eliminating this operation is crucial if we are to use this technique since the time required to apply the linear operator is by far the most computationally expensive.  We will introduce a new variable $\\qc{1} = \\Ah{1}$ but leave discussion about this variable until later.  At this point, let's just assume we know what it is without applying the linear operator.\n\nUsing $\\qc{1}$ in Equation \\ref{eq:2Ihat}, we define $\\qh{2}$ in terms of known quantities without the need for additional applications of the linear operator\n\\begin{equation}\n    \\qh{2} = \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qc{1}-h_{0,1}*\\qh{1}\\right\\} \n    \\label{eq:2IhatFinal}.\n\\end{equation}\n\nContinuing the iteration we find an expression of $q_2$ of all known quantities.  (Can you see a recurring pattern here?)\n\\begin{subequations}\n    \\begin{align}\n        \\qt{2} &= \\qh{2} - h_{0,2}*q_0 - h_{1,2}*q_1 \\\\\n        q_2 &= \\qt{2}/\\left|\\qt{2}\\right|.\n    \\end{align}\n    \\label{eq:2I}\n\\end{subequations}\n\nWe have remained in the realm of simple iterations.  Let's take this one more iteration to see if future iterations will cause a problem.\n\\begin{subequations}\n    \\begin{align}\n    \\qh{3} &= \\A q_2 \\\\\n    &= \\frac{1}{\\left|\\qt{2}\\right|}\\At{2} \\\\\n    &= \\frac{1}{\\left|\\qt{2}\\right|}\\A \\left\\{\\qh{2} - h_{0,2}*q_0 - h_{1,2}*q_1 \\right\\} \\\\\n    &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\Ah{2} - h_{0,2}*\\Aq{0} - h_{1,2}*\\Aq{1} \\right\\} \\\\\n    &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\qc{2} - h_{0,2}*\\qh{1} - h_{1,2}*\\qh{2} \\right\\} \\label{eq:3Ihat}\n    \\end{align}\n\\end{subequations}\n\nFrom Equation \\ref{eq:3Ihat} (as well as Equation \\ref{eq:2IhatFinal}) we see that we must store all the ``hat''vectors in addition to what we have already stored.  This shouldn't normally be a problem since the number we are storing should be relatively small.  Again I've taken the liberty of using $\\qc{2}$ without further explanation.\n\nWe can finish the iteration as usual.\n\\begin{subequations}\n    \\begin{align}\n    \\qt{3} &= \\qh{3} - h_{0,3}*q_0 - h_{1,3}*q_1 - h_{2,3}*q_2 \\\\\n    q_3 &= \\qt{3}/\\left|\\qt{3}\\right|.\n    \\end{align}\n\\end{subequations}\n\n\\subsection{What about the $\\qc{i}$'s?}\nSimilarly to what we have already done, let's write out the $\\qc{i}$ for the first few iterations to see if we can come up with something that works for every iteration.\n\nThe first one is easy\n\\begin{equation}\n    \\qc{1} = \\Ah{1} = \\A \\left(\\Aq{0}\\right) = \\Ap{1} = \\qp{2}\n    \\label{eq:qc1}\n\\end{equation}\n\nThe second one takes a little more work,\n\\begin{subequations}\n    \\begin{align}\n        \\qc{2} &= \\Ah{2} \\\\\n        &= \\A \\left\\{\\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qc{1}-h_{0,1}*\\qh{1}\\right\\} \\right\\} \\\\\n        &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\Ac{1}-h_{0,1}*\\Ah{1}\\right\\} \\\\\n        &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\Ac{1}-h_{0,1}*\\qc{1}\\right\\}\n        \\label{eq:qc2}\n    \\end{align}\n\\end{subequations}\nLet's expand $\\Ac{1}$.\n\\begin{equation}\n    \\Ac{1} = \\A \\left(\\qp{2}\\right) = \\qp{3}\n    \\label{eq:qc2sub}\n\\end{equation}\nSubstituting Equation \\ref{eq:qc2sub} into Equation \\ref{eq:qc2} we obtain\n\\begin{equation}\n    \\qc{2} = \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{3}-h_{0,1}*\\qc{1}\\right\\}.\n    \\label{eq:qc2final}\n\\end{equation}\n\nLet's do another iteration (I'm not seeing a pattern yet).\n\\begin{subequations}\n    \\begin{align}\n        \\qc{3} &= \\Ah{3} \\\\\n        &= \\A \\left[ \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\qc{2} - h_{0,2}*\\qh{1} - h_{1,2}*\\qh{2} \\right\\} \\right] \\\\\n        &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\Ac{2} - h_{0,2}*\\Ah{1} - h_{1,2}*\\Ah{2} \\right\\} \\\\\n        &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\Ac{2} - h_{0,2}*\\qc{1} - h_{1,2}*\\qc{2} \\right\\}\n        \\label{eq:qc3}\n    \\end{align}\n\\end{subequations}\nLet's expand $\\Ac{2}$.\n\\begin{subequations}\n    \\begin{align}\n        \\Ac{2} &= \\A \\left[\\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{3}-h_{0,1}*\\qc{1}\\right\\}\\right] \\\\\n         &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\Ap{3}-h_{0,1}*\\Ac{1}\\right\\} \\\\\n         &= \\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{4}-h_{0,1}*\\qp{3}\\right\\}\n        \\label{eq:qc3sub}\n    \\end{align}\n\\end{subequations}\nSubstituting Equation \\ref{eq:qc3sub} into Equation \\ref{eq:qc3} followed by substituting in Equation \\ref{eq:qc2final} we obtain\n\\begin{subequations}\n    \\begin{align}\n        \\qc{3} &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\left[\\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{4}-h_{0,1}*\\qp{3}\\right\\}\\right] - h_{0,2}*\\qc{1} - h_{1,2}*\\qc{2} \\right\\} \\\\\n         &= \\frac{1}{\\left|\\qt{2}\\right|} \\left\\{\\left[\\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{4}-h_{0,1}*\\qp{3}\\right\\}\\right] - h_{0,2}*\\qc{1} - h_{1,2}*\\left[\\frac{1}{\\left|\\qt{1}\\right|} \\left\\{\\qp{3}-h_{0,1}*\\qc{1}\\right\\}\\right] \\right\\}\n    \\end{align}\n\\end{subequations}\n\nWell, this doesn't look good.  It is clear that there are no matrix-vector multiplications needed, but I can't yet see a recursive pattern.  I'm sure it's there, I just can't see it yet.  \n\n\\section{General Format}\nNow let's try to write this in a general format.  We have already shown that it works for up to three iterations.  What if we are performing the $n+1$st iteration?\n\n\\begin{subequations}\n    \\begin{align}\n        \\qh{n+1} &= \\Aq{n} \\\\\n        &= \\frac{1}{\\qt{n}}\\At{n} \\\\\n        &= \\frac{1}{\\qt{n}}\\A \n        \\left\\{\\qh{n} - h_{0,n}*q_0 - h_{1,n}*q_1 \\cdots h_{n-1,n}*q_{n-1}\\right\\} \\\\\n        &= \\frac{1}{\\qt{n}}\n        \\left\\{\\Ah{n} - h_{0,n}*\\Aq{0} - h_{1,n}*\\Aq{1} \\cdots h_{n-1,n}*\\Aq{n-1}\\right\\} \\\\\n        &= \\frac{1}{\\qt{n}}\n        \\left\\{\\qc{n} - h_{0,n}*\\qh{1} - h_{1,n}*\\qh{2} \\cdots h_{n-1,n}*\\qh{n}\\right\\}\n    \\end{align}\n\\end{subequations}\n\\begin{subequations}\n    \\begin{align}\n        \\qt{n+1} &= \\qh{n+1} - h_{0,n+1}*q_0 \\cdots h_{n.n+1}*q_n \\\\\n        q_{n+1} &= \\qt{n+1}/\\left|\\qt{n+1}\\right|.\n    \\end{align}\n\\end{subequations}\n\n\\section{Conclusion}\nSo I think a post-processing Arnoldi's method is possible.  I just haven't yet found the inductive proof for the $\\qc{i}$'s.\n\\end{document}\n", "meta": {"hexsha": "52d76088e472e1783d025284b1b2eb008a1f9259", "size": 9649, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/PostProcessingArnoldi/PostProcessingArnoldi.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/PostProcessingArnoldi/PostProcessingArnoldi.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/PostProcessingArnoldi/PostProcessingArnoldi.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": 45.9476190476, "max_line_length": 479, "alphanum_fraction": 0.6171624002, "num_tokens": 3626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6452754083487587}}
{"text": "We are interested in leveled HE schemes that support SIMD operations on their plaintexts.\nSuch schemes include $\\FV$~\\cite{FV12} and $\\BGV$~\\cite{BGV12}, have the ring $\\intring_p$ as plaintext space for some $p \\geq 2$.\nWe refer to such schemes as \\emph{SIMD-schemes}.\nThe general framework of such schemes is outlined below.\n\n\\subsection{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 a SIMD-scheme consists of key generation, encryption and decryption algorithms.\n\n$\\KeyGen(1^\\lambda, 1^L) \\rightarrow (\\sk, \\pk)$. Given $\\lambda$ and $L$, this function generates the secret key $\\sk$ and the public key $\\pk$.\nNote 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_t, \\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\\subsection{Arithmetic operations}\n\nHomomorphic arithmetic operations are addition and multiplication.\n\n$\\Add(\\ct_1, \\ct_2) \\rightarrow \\ct$. The addition 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 of these plaintexts in the ring $\\intring_p$.\n%It implies that homomorphic addition sums respective SIMD slots of $\\pt_1$ and $\\pt_2$.\n\n$\\AddPlain(\\ct_1, \\pt_2) \\rightarrow \\ct$. This algorithm takes a ciphertext $\\ct_1$ encrypting a plaintext $\\pt_1$ and a plaintext $\\pt_2$.\nIt outputs a ciphertext $\\ct$ that encrypts $\\pt_1 + \\pt_2$.\n%As for the $\\Add$ algorithm, $\\AddPlain$ sums respective SIMD slots of $\\pt_1$ and $\\pt_2$.\n\n$\\Mul(\\ct_1, \\ct_2) \\rightarrow \\ct$. Given two input ciphertext $\\ct_1$ and $\\ct_2$ encrypting plaintext $\\pt_1$ and $\\pt_2$ respectively, the multiplication algorithm outputs a ciphertext $\\ct$ that encrypts the plaintext product $\\pt_1 \\cdot \\pt_2$.\n%As a result, homomorphic multiplication multiplies respective SIMD slots of $\\pt_1$ and $\\pt_2$.\n\n$\\MulPlain(\\ct_1, \\pt_2) \\rightarrow \\ct$. Given a ciphertext $\\ct_1$ encrypting plaintext $\\pt_1$ and a plaintext $\\pt_2$, this algorithm outputs a ciphertext $\\ct$ that encrypts the plaintext product $\\pt_1 \\cdot \\pt_2$.\n%As a result, homomorphic multiplication multiplies respective SIMD slots of $\\pt_1$ and $\\pt_2$.\n\nUsing the above operations as building blocks, one can design homomorphic subtraction algorithms.\n\n$\\Sub(\\ct_1, \\ct_2) = \\Add(\\ct_1, \\MulPlain(\\ct_2, \\pt(-\\1))) \\rightarrow \\ct$. The subtraction algorithm returns a ciphertext $\\ct$ that encrypts the difference of two plaintext messages $\\pt_1 - \\pt_2$ encrypted by $\\ct_1$ and $\\ct_2$, respectively.\n\n$\\SubPlain(\\ct_1, \\pt_2) = \\AddPlain(\\ct_1, \\pt_2 \\cdot \\pt(-\\1)) \\rightarrow \\ct$. This algorithm returns a ciphertext $\\ct$ that encrypts $\\pt_1 - \\pt_2$ where $\\pt_1$ is encrypted by $\\ct_1$.\nWe can also change the order of arguments such that $\\SubPlain(\\pt_1, \\ct_2)$ returns a ciphertext $\\ct$ encrypting $\\pt_1 - \\pt_2$. \n\nAs 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.\nThis 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.\nGiven 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\\subsection{Special operations}\\label{subsec:special_operations}\n\nOne 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}),$$\nthe 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\nAs discussed in Section~\\ref{subsec:crt}, 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$.\nRecall that $\\princhar(m) = m^{p^d-1} = \\prod_{i=0}^{d-1} (m^{p-1})^{p^i}$ as shown in~(\\ref{eq:exp_frob}).\nThe multiplicative depth of $x^{p-1}$ is equal to $\\ceil{\\log_2 (p-1)}$.\nThe multiplicative depth of $x^{p^i}$ is zero as it can be done by the $\\Frob$ operation.\nIn total, $d-1$ $\\Frob$ operations are needed to compute $\\princhar(m)$.\nAs 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}\nUsing general exponentiation by squaring, $x^{p-1}$ requires $\\floor{\\log_2 (p-1)} + \\wt(p-1) - 1$ field multiplications.\nSince $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\n\\subsection{Noise cost of homomorphic operations}\\label{subsec:cost}\nNote that every 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\nTable~\\ref{table:he_operations} summarizes the running time and the noise cost of the aforementioned homomorphic operations.\nSimilar to~\\cite{C:HalSho14}, we divide the operations into expensive, moderate and cheap.\nThe expensive operations dominate the cost of a homomorphic circuit.\nThe moderate operations are less important, but if there are many of them in a circuit, their total cost can dominate the total cost.\nThe cheap operations are the least important and can be omitted in the cost analysis.\n\n\\subsection{Complexity of homomorphic algorithms}\nWhile evaluating polynomials in variables $X_1, X_2, \\dots, X_n$, we refer to multiplication of expressions containing these variables as \\emph{non-scalar}.\nThere are two multiplication functions $\\Mul$ (ciphertext-ciphertext multiplication) and $\\MulPlain$ (ciphertext-plaintext multiplication).\nThe former one corresponds to non-scalar multiplication of two expressions containing input values, while the latter is related to the product of an expression with input values and unencrypted finite field elements. \nSince $\\Mul$ is much slower and introduces more noise 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.\n\n\\begin{table}[t!]\n  \\centering\n  \\begin{tabular*}{.45\\textwidth}{@{\\extracolsep{\\fill} } c c c }\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%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "a35c44fe060d6ae283bec9d50238c6f58450fbe8", "size": 9611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/homomorphic-encryption.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/homomorphic-encryption.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/homomorphic-encryption.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": 73.3664122137, "max_line_length": 271, "alphanum_fraction": 0.7264592654, "num_tokens": 2729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6452751050541774}}
{"text": "\\subsection{Orthogonal and orthonormal sets}\n\nIn this section, we examine what it means for vectors (and sets of\nvectors) to be orthogonal and orthonormal. First, it is necessary to\nreview some important concepts. You may recall the definitions for the\nspan of a set of vectors and a linear independent set of vectors. We\ninclude the definitions and examples here for convenience.\n\n\\begin{definition}{Span of a set of vectors and subspace}{span}\n  The collection of all linear combinations of a set of vectors\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ in $\\R^{n}$ is known as the\n  span\\index{span}\\index{vector!span} of these vectors and is written\n  as $\\sspan \\set{\\vect{u}_1,\\ldots,\n    \\vect{u}_k}$. \\\\\n  We call a collection of the form\n  $\\sspan \\set{\\vect{u}_1,\\ldots, \\vect{u}_k}$ a subspace of $\\R^{n}$.\n\\end{definition}\n\nConsider the following example.\n\n\\begin{example}{Span of vectors}{span-vectors}\nDescribe the span of the vectors $\\vect{u}=\\begin{mymatrix}{rrr}\n1  & 1 & 0\n\\end{mymatrix}^T$ and\n$\\vect{v}=\\begin{mymatrix}{rrr}\n3  & 2 & 0\n\\end{mymatrix}^T \\in \\R^{3}$.\n\\end{example}\n\n\\begin{solution}\nYou can see that any linear combination of the vectors $\\vect{u}$ and $\\vect{v}$ yields a vector\n$\\begin{mymatrix}{rrr}\nx  & y & 0\n\\end{mymatrix}^T$ in the $XY$-plane.\n\nMoreover every vector in the $XY$-plane is in fact such a linear\ncombination of the vectors $\\vect{u}$ and $\\vect{v}$. That's because\n\\[ \\begin{mymatrix}{r}\nx \\\\\ny \\\\\n0\n\\end{mymatrix}\n=\n(-2x+3y) \\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix}\n+\n(x-y)\\begin{mymatrix}{r}\n3 \\\\\n2 \\\\\n0\n\\end{mymatrix}\n\\]\n\nThus  span$\\set{\\vect{u},\\vect{v}}$ is precisely the $XY$-plane.\n\\end{solution}\n\nThe span of a set of a vectors in $\\R^n$ is what we call a \\textbf{subspace of $\\R^n$}. A subspace $W$ is characterized by the feature that any linear combination of vectors of $W$ is again a vector contained in $W$.\n\nAnother important property of sets of vectors is called linear independence.\n\n\\begin{definition}{Linearly independent set of vectors}{linear-independent-orthogonality}\nA set of non-zero vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ in $\\R^{n}$ is said to be\n\\textbf{linearly independent}\\index{linear independence}\\index{vector!linear independence}\n if no vector in that set is in the span of the other vectors of that set.\n\\end{definition}\n\nHere is an example.\n\n\\begin{example}{Linearly independent vectors}{linearly-independent-vectors}\nConsider vectors $\\vect{u}=\\begin{mymatrix}{rrr}\n1  & 1 & 0\n\\end{mymatrix}^T$,\n$\\vect{v}=\\begin{mymatrix}{rrr}\n3  & 2 & 0\n\\end{mymatrix}^T$, and\n$\\vect{w}=\\begin{mymatrix}{rrr}\n4  & 5 & 0\n\\end{mymatrix}^T  \\in \\R^{3}$.\nVerify whether the set $\\set{\\vect{u}, \\vect{v}, \\vect{w}}$ is linearly independent.\n\\end{example}\n\n\\begin{solution}\nWe already verified in Example~\\ref{exa:span-vectors} that\n$\\sspan \\set{\\vect{u}, \\vect{v}}$ is the $XY$-plane. Since $\\vect{w}$\nis clearly also in the $XY$-plane, then the set $\\set{\\vect{u}, \\vect{v},\n\\vect{w}}$ is \\textbf{not} linearly independent.\n\\end{solution}\n\nIn terms of spanning, a set of vectors is linearly independent if it\ndoes not contain unnecessary vectors. In the previous example you\ncan see that the vector $\\vect{w}$ does not help to span any new vector\nnot already in the span of the other two vectors. However you can\nverify that the set $\\set{\\vect{u}, \\vect{v}}$ is linearly independent,\nsince you will not get the $XY$-plane as the span of a single vector.\n\nWe can also determine if a set of vectors is linearly independent by examining linear combinations. A set of vectors is linearly independent if and only if\nwhenever a linear combination of these vectors equals zero, it follows\nthat all the coefficients equal zero. It is a good exercise to verify\nthis equivalence, and this latter condition is often used as the\n(equivalent) definition of linear independence.\n\nIf a subspace is spanned by a linearly independent set of vectors,\nthen we say that it is a basis for the subspace.\n\n\\begin{definition}{Basis of a subspace}{subspace-basis}\nLet $V$ be a subspace of $\\R^{n}$. Then $\\set{\n\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is a \\textbf{basis}\\index{basis}\\index{vector!basis}\\index{subspace!basis} for\n$V$ if the following two conditions\nhold.\n\n\\begin{enumerate}\n\\item $\\sspan\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} =V$\n\\item $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is linearly\nindependent\n\\end{enumerate}\n\\end{definition}\n\nThus the set of vectors $\\set{\\vect{u}, \\vect{v}}$ from Example~\\ref{exa:linearly-independent-vectors} is a basis for $XY$-plane in\n$\\R^{3}$ since it is both linearly independent and spans\nthe $XY$-plane.\n\n Recall from the properties of the dot product of vectors\nthat two vectors $\\vect{u}$ and $\\vect{v}$ are orthogonal if $\\vect{u}\n\\dotprod \\vect{v} = 0$. Suppose a vector is orthogonal to a spanning set of $\\R^n$. What can be said about such a vector? This is the discussion in the following example.\n\n\\begin{example}{Orthogonal vector to a spanning set}{}\nLet $\\set{\\vect{x}_1, \\vect{x}_2, \\ldots, \\vect{x}_k}\\in\\R^n$ and\nsuppose $\\R^n=\\sspan\\set{\\vect{x}_1, \\vect{x}_2, \\ldots, \\vect{x}_k}$.\nFurthermore, suppose that there exists a vector $\\vect{u}\\in\\R^n$ for which $\\vect{u}\\dotprod \\vect{x}_j=0$ for all $j$, $1\\leq j\\leq k$.\nWhat type of vector is $\\vect{u}$?\n\\end{example}\n\n\\begin{solution}\nWrite $\\vect{u}=t_1\\vect{x}_1 + t_2\\vect{x}_2 +\\ldots +t_k\\vect{x}_k$\nfor some $t_1, t_2, \\ldots, t_k\\in\\R$\n(this is possible because\n$\\vect{x}_1, \\vect{x}_2, \\ldots, \\vect{x}_k$ span $\\R^n$).\n\nThen\n\\begin{eqnarray*}\n\\norm{\\vect{u}}^2 & = & \\vect{u}\\dotprod\\vect{u} \\\\\n& = & \\vect{u}\\dotprod(t_1\\vect{x}_1 + t_2\\vect{x}_2 +\\ldots +t_k\\vect{x}_k) \\\\\n& = & \\vect{u}\\dotprod (t_1\\vect{x}_1) +  \\vect{u}\\dotprod (t_2\\vect{x}_2) +\n\\ldots +  \\vect{u}\\dotprod (t_k\\vect{x}_k) \\\\\n& = & t_1(\\vect{u}\\dotprod \\vect{x}_1) + t_2(\\vect{u}\\dotprod \\vect{x}_2) + \\ldots\n+ t_k(\\vect{u}\\dotprod \\vect{x}_k) \\\\\n& = & t_1(0) + t_2(0) + \\ldots + t_k(0) = 0.\n\\end{eqnarray*}\nSince $\\norm{\\vect{u}}^2 =0$, $\\norm{\\vect{u}} =0$.\nWe know that $\\norm{\\vect{u}}=0$ if and only if\n$\\vect{u}=\\vect{0}_n$.\nTherefore, $\\vect{u}=\\vect{0}_n$.\nIn conclusion, the only vector orthogonal to every vector of\na spanning set of $\\R^n$ is the zero vector.\n\\end{solution}\n\nWe can now discuss what is meant by an orthogonal\\index{orthogonal} set of vectors.\n\n\\begin{definition}{Orthogonal set of vectors}{orthogonal-set}\nLet $\\set{\\vect{u}_1, \\vect{u}_2,\\ldots, \\vect{u}_m}$ be a set of\nvectors in $\\R^n$. Then this set is called an\n\\textbf{orthogonal set}\\index{orthogonal}\\index{vector!orthogonal}\nif the following conditions hold:\n\\begin{enumerate}\n\\item\n$\\vect{u}_i \\dotprod \\vect{u}_j = 0$ for all $i \\neq j$\n\\item\n$\\vect{u}_i \\neq \\vect{0}$ for all $i$\n\\end{enumerate}\n\\end{definition}\n\nIf we have an orthogonal set of vectors and normalize each vector so\nthey have length 1, the resulting set is called an \\textbf{orthonormal\nset} of vectors. They can be described as follows.\n\n\\begin{definition}{Orthonormal set of vectors}{orthonormal-set-vectors}\nA set of vectors, $\\set{\\vect{w}_{1},\\ldots,\\vect{w}_{m}} $\nis said to be an\n\\textbf{orthonormal}\\index{orthonormal}\\index{vector!orthonormal}\nset if\n\\[\n\\vect{w}_i \\dotprod \\vect{w}_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\\end{definition}\n\nNote that all orthonormal sets are orthogonal, but the reverse is not\nnecessarily true since the vectors may not be normalized. In order to\nnormalize the vectors, we simply need divide each one by its length.\n\n\\begin{definition}{Normalizing an orthogonal set}{normalizing}\nNormalizing an orthogonal set is the process of\nturning an orthogonal (but not orthonormal) set into\nan orthonormal set.\nIf $\\set{\\vect{u}_1, \\vect{u}_2, \\ldots, \\vect{u}_k}$\nis an orthogonal subset of $\\R^n$,\nthen\n\\[ \\set{\n\\frac{1}{\\norm{\\vect{u}_1}}\\vect{u}_1,\n\\frac{1}{\\norm{\\vect{u}_2}}\\vect{u}_2, \\ldots,\n\\frac{1}{\\norm{\\vect{u}_k}}\\vect{u}_k }\n\\]\nis an orthonormal set.\n\\end{definition}\n\nWe illustrate this concept in the following example.\n\n\\begin{example}{Orthonormal set}{orthonormal-set}\nConsider the set of vectors  given by\n\\[\n\\set{\\vect{u}_1, \\vect{u}_2 } = \\set{\n\\begin{mymatrix}{c}\n1 \\\\\n1\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix}\n}\n\\]\nShow that it is an orthogonal set of vectors  but not an orthonormal one. Find the corresponding orthonormal set.\n\\end{example}\n\n\\begin{solution}\nOne easily verifies that $\\vect{u}_1 \\dotprod \\vect{u}_2 = 0$ and\n$\\set{\\vect{u}_1, \\vect{u}_2 }$ is an orthogonal set of\nvectors. On the other hand one can compute that $\\norm{\\vect{u}_1}= \\norm{\\vect{u}_2} =\n\\sqrt{2} \\neq 1$ and thus it is not an orthonormal set.\n\nThus to find a corresponding orthonormal set, we simply need to\nnormalize each vector. We will write $\\set{\\vect{w}_1, \\vect{w}_2}$\nfor the corresponding orthonormal set. Then,\n\\begin{eqnarray*}\n\\vect{w}_1 &=& \\frac{1}{\\norm{\\vect{u}_1}} \\vect{u}_1\\\\\n&=& \\frac{1}{\\sqrt{2}} \\begin{mymatrix}{c}\n1 \\\\\n1\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{c}\n\\vspace{0.05in} \\frac{1}{\\sqrt{2}}\\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}\n\\end{eqnarray*}\n\nSimilarly,\n\\begin{eqnarray*}\n\\vect{w}_2 &=& \\frac{1}{\\norm{\\vect{u}_2}} \\vect{u}_2\\\\\n&=& \\frac{1}{\\sqrt{2}} \\begin{mymatrix}{r}\n-1 \\\\\n1\n\\end{mymatrix} \\\\\n&=&\n\\begin{mymatrix}{r}\n\\vspace{0.05in} -\\frac{1}{\\sqrt{2}}\\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}\n\\end{eqnarray*}\n\nTherefore the corresponding orthonormal set is\n\\[\n\\set{\\vect{w}_1, \\vect{w}_2 } =\n\\set{\n\\begin{mymatrix}{c}\n\\vspace{0.05in} \\frac{1}{\\sqrt{2}}\\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n\\vspace{0.05in} -\\frac{1}{\\sqrt{2}}\\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}\n}\n\\]\n\nYou can verify that this set is orthogonal.\n\\end{solution}\n\nConsider an orthogonal set of vectors in $\\R^n$, written $\\set{\n\\vect{w}_1,\\ldots, \\vect{w}_k}$ with $k \\leq n$. The span of these\nvectors is a subspace $W$ of $\\R^n$. If we\ncould show that this orthogonal set is also linearly independent, we\nwould have a basis of $W$. We will show this in the next theorem.\n\n\\begin{theorem}{Orthogonal basis of a subspace}{orthonormal-basis}\nLet $ \\set{\\vect{w}_1, \\vect{w}_2,\\ldots, \\vect{w}_k}$ be an\northonormal set of vectors in $\\R^n$. Then this set is\nlinearly independent and forms a basis for the subspace $W =\n\\sspan \\set{\\vect{w}_1, \\vect{w}_2,\\ldots, \\vect{w}_k}$.\n\\end{theorem}\n\n\\begin{proof}\nTo show it is a linearly independent set, suppose a linear combination\nof these vectors equals $\\vect{0}$, such as:\n\\[\na_1 \\vect{w}_1 + a_2 \\vect{w}_2 + \\ldots + a_k \\vect{w}_k = \\vect{0}, a_i \\in \\R\n\\]\nWe need to show that all $a_i = 0$. To do so, take the dot product of\neach side of the above equation with the vector $\\vect{w}_i$ and obtain the following.\n\n\\begin{eqnarray*}\n\\vect{w}_i \\dotprod (a_1 \\vect{w}_1 + a_2 \\vect{w}_2 + \\ldots + a_k \\vect{w}_k ) &=& \\vect{w}_i \\dotprod \\vect{0}\\\\\na_1 (\\vect{w}_i \\dotprod \\vect{w}_1) + a_2 (\\vect{w}_i \\dotprod \\vect{w}_2) + \\ldots + a_k (\\vect{w}_i \\dotprod \\vect{w}_k)  &=& 0\n\\end{eqnarray*}\nNow since the set is orthogonal, $\\vect{w}_i \\dotprod \\vect{w}_m = 0$ for all $m \\neq i$, so we have:\n\\[\na_1 (0) + \\ldots + a_i(\\vect{w}_i \\dotprod \\vect{w}_i) + \\ldots + a_k (0) = 0\n\\]\n\\[\na_i \\norm{\\vect{w}_i}^2 = 0\n\\]\n\nSince the set is orthogonal, we know that $\\norm{\\vect{w}_i}^2  \\neq 0$. It follows that $a_i =0$. Since the $a_i$ was chosen arbitrarily, the set $\\set{\\vect{w}_1, \\vect{w}_2,\\ldots, \\vect{w}_k}$ is linearly independent.\n\nFinally since $W = \\mbox{span} \\set{\\vect{w}_1, \\vect{w}_2,\\ldots,\n\\vect{w}_k}$, the set of vectors also spans $W$ and therefore forms a basis of $W$.\n\n\\end{proof}\n\nIf an orthogonal set is a basis for a subspace, we call this an\northogonal basis. Similarly, if an orthonormal set is a basis, we call\nthis an orthonormal basis.\n\nWe conclude this section with a discussion of Fourier expansions. Given any orthogonal basis $B$ of $\\R^n$ and an arbitrary vector $\\vect{x} \\in \\R^n$, how do we express $\\vect{x}$ as a linear combination of vectors in $B$? The solution is Fourier expansion.\n\n\\begin{theorem}{Fourier expansion}{fourier-expansion}\nLet $V$ be a subspace of $\\R^n$ and suppose $\\set{\\vect{u}_1, \\vect{u}_2, \\ldots, \\vect{u}_m}$\nis an orthogonal basis of $V$.\nThen for any $\\vect{x}\\in V$,\n\\[ \\vect{x} =\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_1}{\\norm{\\vect{u}_1}^2}} \\vect{u}_1 +\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_2}{\\norm{\\vect{u}_2}^2}} \\vect{u}_2 +\n\\ldots +\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_m}{\\norm{\\vect{u}_m}^2}} \\vect{u}_m.\n\\]\nThis expression is called the Fourier expansion\nof $\\vect{x}$, and\n\\[ \\frac{\\vect{x}\\dotprod \\vect{u}_j}{\\norm{\\vect{u}_j}^2},\\]\n$j=1,2,\\ldots,m$\nare the Fourier coefficients.\n\\end{theorem}\n\nConsider the following example.\n\n\\begin{example}{Fourier expansion}{fourier}\nLet\n$\\vect{u}_1= \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix},\n\\vect{u}_2= \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 1  \\end{mymatrix}$,\nand\n$\\vect{u}_3 =\\begin{mymatrix}{r} 5 \\\\ 1 \\\\ -2 \\end{mymatrix}$,\nand let\n$\\vect{x} =\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}$.\n\nThen $B=\\set{\\vect{u}_1, \\vect{u}_2, \\vect{u}_3}$\nis an orthogonal basis of $\\R^3$.\n\nCompute the Fourier expansion of $\\vect{x}$, thus writing $\\vect{x}$ as  a linear combination of the vectors of $B$.\n\\end{example}\n\n\\begin{solution}\nSince $B$ is a basis (verify!) there is a unique way to express $\\vect{x}$ as a\nlinear combination of the vectors of $B$. Moreover since $B$ is an\northogonal basis (verify!), then this can be done by computing the\nFourier expansion of $\\vect{x}$.\n\nThat is:\n\n\\[\n\\vect{x}   =\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_1}{\\norm{\\vect{u}_1}^2}} \\vect{u}_1 +\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_2}{\\norm{\\vect{u}_2}^2}} \\vect{u}_2 +\n\\paren{\\frac{\\vect{x}\\dotprod \\vect{u}_3}{\\norm{\\vect{u}_3}^2}} \\vect{u}_3.\n\\]\n\nWe readily compute:\n\n\\[\n\\frac{\\vect{x}\\dotprod\\vect{u}_1}{\\norm{\\vect{u}_1}^2} = \\frac{2}{6}, \\;\n\\frac{\\vect{x}\\dotprod\\vect{u}_2}{\\norm{\\vect{u}_2}^2} = \\frac{3}{5},\n\\mbox{ and }\n\\frac{\\vect{x}\\dotprod\\vect{u}_3}{\\norm{\\vect{u}_3}^2} = \\frac{4}{30}.\\]\n\nTherefore,\n\\[ \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n= \\frac{1}{3}\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix}\n+\\frac{3}{5}\\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 1  \\end{mymatrix}\n+\\frac{2}{15}\\begin{mymatrix}{r} 5 \\\\ 1 \\\\ -2 \\end{mymatrix}.\\]\n\\end{solution}\n", "meta": {"hexsha": "5d90e50682f628f698bfdabf6ef9836dc22fdac8", "size": 14352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonalitySets.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/RnVectorsOrthogonalitySets.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/RnVectorsOrthogonalitySets.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.2424242424, "max_line_length": 258, "alphanum_fraction": 0.6845039019, "num_tokens": 5141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.9019206791658465, "lm_q1q2_score": 0.6452556961685739}}
{"text": "\n\\section{The \\lowerbound algorithm}\n\\Label{sec:lowerbound}\n\nThe \\lowerbound algorithm is one of the four binary search algorithms\nof the \\cxx Standard Library \\cite[\\S 28.7.3.1]{cxx-17-draft}.\nFor our purposes we have modified\nthe generic implementation\nto that of an array of type \\valuetype.\nThe signature now reads:\n\n\\begin{lstlisting}[style = acsl-block]\n\n  size_type\n  lower_bound(const value_type* a, size_type n, value_type v);\n\\end{lstlisting}\n\nAs with the other binary search algorithms \\lowerbound requires that\nits input array is in increasing order.\nThe index~\\inl{lb}, that \\lowerbound returns satisfies the inequality\n\n\\begin{align}\n\\Label{eq:lower-bound-result}\n0 \\leq \\mathtt{lb} \\leq n  \n\\end{align}\n\nand has the following properties for a valid index~\\inl{k} of the array under consideration\n\n\\begin{alignat}{3}\n\\Label{eq:lower-bound-left}\n0 &\\leq k < \\mathtt{lb} && \\qquad\\Longrightarrow\\qquad && a[k] < \\mathtt{v} \\\\\n\\Label{eq:lower-bound-right}\n\\mathtt{lb} &\\leq k < n && \\qquad\\Longrightarrow\\qquad && \\mathtt{v} \\leq a[k]\n\\end{alignat}\n\nConditions~\\eqref{eq:lower-bound-left} and~\\eqref{eq:lower-bound-right} imply that~\\inl{v}\ncan only occur in the array section \\inl{a[lb..n-1]}.\nIn this sense \\lowerbound returns a \\emph{lower bound} for the potential indices.\n\nAs an example, we consider in Figure~\\ref{fig:lowerbound} an increasingly ordered array.\nThe arrows indicate which indices will be returned by \\lowerbound for a given value.\nNote that the index~9 points \\emph{one past end} of the array.\nValues that are not contained in the array are colored in gray.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.60\\textwidth]{Figures/lower_bound.pdf}\n\\caption{\\Label{fig:lowerbound}Some examples for \\lowerbound}\n\\end{figure}\n\n%\\FloatBarrier\n\nFigure~\\ref{fig:lowerbound} also clarifies that care must\nbe taken when interpreting the return value of \\lowerbound.\n%\nAn important difference to the algorithms in Chapter~\\ref{cha:non-mutating}\nis that a return value of \\lowerbound that is less than~$n$ \ndoes not necessarily implies \\inl{a[lb] == v}.\nWe can only be sure that \\inl{v <= a[lb]} holds.\n\n\n\\subsection{Formal specification of \\lowerbound}\n\nThe specification of \\specref{lowerbound} is shown in the following listing.\nThe preconditions \\inl{increasing} expresses\nthat the array values need to be in increasing order.\n%\nThe postconditions reflect the conditions listed above and can be expressed\nusing the predicates \\logicref{LowerBound} and \\logicref{StrictUpperBound}.\n\n\\begin{itemize}\n\\item Condition~\\eqref{eq:lower-bound-result} becomes postcondition \\inl{result}\n\\item Condition~\\eqref{eq:lower-bound-left} becomes postcondition \\inl{left}\n\\item Condition~\\eqref{eq:lower-bound-right} becomes postcondition \\inl{right}\n\\end{itemize}\n\n\\input{Listings/lower_bound.h.tex}\n\n\\subsection{Implementation of \\lowerbound}\n\\Label{subsec:lowerbound:impl}\n\nThe following listing shows our implementation of \\implref{lowerbound}.\nEach iteration step narrows down the range that contains the\nsought-after result. \nThe loop invariants express that in each iteration step all indices\nless than the temporary left bound\n\\inl{left} contain values that are less than \\inl{v} and all indices\nnot less than the temporary right bound \\inl{right} contain values\nthat are greater or equal than \\inl{v}.\n%\nThe expression to compute \\inl{middle} is slightly more complex than the\nnaïve \\inl{(left+right)/2}, but it avoids potential overflows.\n\n\\input{Listings/lower_bound.c.tex}\n\n", "meta": {"hexsha": "20bcd811341589cf52f848d4741e4b2d56e60eef", "size": 3502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/binary-search/lower_bound.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/binary-search/lower_bound.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/binary-search/lower_bound.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": 36.4791666667, "max_line_length": 91, "alphanum_fraction": 0.7724157624, "num_tokens": 969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.6451064550125185}}
{"text": "\\subsection{Data Preparation} \\label{data_preparation}\n\nAll of our data records are resampled and quantized before further analysis. In general, dimensionality and cardinality reduction of time series is performed to ease and accelerate data processing by providing a more compact representation of equidistant measurements \\cite{liu2009uwave}.\n\n\\paragraph{Resampling:} The recorded acceleration data was resampled by means of the moving average technique, using a window size of 50 ms and step size of 30 ms.\n\n\\paragraph{Quantization:} The resampled records were then converted into time series with integer values between -16 and 16, such as suggested in related work \\cite{liu2009uwave} and summarized in table \\ref{table:conversion}.\n\n\\begin{table}\n    \\begin{center}\n        \\begin{tabularx}{\\textwidth}{XX}\n            \\hline\n            \\textbf{Acceleration data ($a$) in $\\frac{dm}{s^2}$} & \\textbf{Converted value}\\\\\n            \\hline\n            $a > 200$ & 16\\\\\n            $100 < a < 200$ & 11 to 15 (five levels linearly)\\\\\n            $0 < a < 100$ & 1 to 10 (ten levels linearly)\\\\\n            $a = 0$ & 0\\\\\n            $-100 < a < 0$ & -1 to - 10 (ten levels linearly)\\\\\n            $-200 < a < -100$ & -11 to - 15 (five levels linearly)\\\\\n            $a < -200$ & -16\\\\\n            \\hline\n        \\end{tabularx}\n    \\end{center}\n    \\caption{Conversion of recorded acceleration data from $\\frac{dm}{s^2}$ scale to integer values.}\n\t\\label{table:conversion}\n\\end{table}\n", "meta": {"hexsha": "5828655b0e1e5637bcaedc231c607097122e5912", "size": 1487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/evaluation/data_preparation.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": "paper/evaluation/data_preparation.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": "paper/evaluation/data_preparation.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": 53.1071428571, "max_line_length": 288, "alphanum_fraction": 0.6536650975, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.64508564815742}}
{"text": "\\section{Exercise 03}\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{Problem}\n\\framesubtitleTC{This one we solve together}\n Given the two DT LTI dynamic systems\n \\begin{displaymath}\n  S_1:\n  \\left\\{\\begin{array}{rcl}\n   x_1(k) &=& 0.5x_1(k-1)+u(k-1)\\\\\n   x_2(k) &=& 0.5x_2(k-1)+u(k-1)\\\\\n   y(k)   &=& x_1(k)+x_2(k)\n  \\end{array}\\right. \\quad\n  S_2:\n  \\left\\{\\begin{array}{rcl}\n   x_1(k) &=& 0.4x_1(k-1)+u(k-1)\\\\\n   x_2(k) &=& 0.8x_2(k-1)+u(k-1)\\\\\n   y(k)   &=& x_2(k)\n  \\end{array}\\right.\n \\end{displaymath}\n\n \\begin{itemize}[<+-| alert@+>]\n \\item[(a)] compute their transfer functions,\n \\item[(b)] comment on the result.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (a)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item We start with $S_1$:\n       \\begin{itemize}\n       \\item[] \\begin{itemize}[<+-| alert@+>]\n               \\item[$G(z)$] \\vspace{1mm}\n                    $= \\begin{bmatrix} 1 & 1  \\end{bmatrix} \\,\n                       \\begin{bmatrix} z-0.5 & 0 \\\\\n                                       0     & z-0.5 \\end{bmatrix}^{-1} \\,\n                       \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}\n                       +0\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{1}{(z-0.5)^2}\n                       \\begin{bmatrix} 1 & 1 \\end{bmatrix} \\,\n                       \\begin{bmatrix} z-0.5 & 0 \\\\\n                                       0     & z-0.5 \\end{bmatrix} \\,\n                       \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{1}{(z-0.5)^2}\n                       \\begin{bmatrix} z-0.5 & z-0.5 \\end{bmatrix} \\,\n                       \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{2\\cancel{(z-0.5)}}{(z-0.5)^{\\cancel{2}}} \\qquad \\qquad\n                       \\TC{\\leftarrow \\text{zero/pole \\underline{cancellation}}}\n                    $\n               \\item[] \\vspace{1mm}\n                    $= \\cfrac{2}{z-0.5}.\n                    $\n               \\end{itemize}\n       \\end{itemize}\n \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}[fragile]\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (a)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item And now $S_2$:\n       \\begin{itemize}\n       \\item[] \\begin{itemize}[<+-| alert@+>]\n               \\item[] wxMaxima, we are lazy \\smiley\n                       \\begin{verbatim}\nA:matrix([0.4,0],[0,0.8]);\nb:matrix([1],[1]);\nc:matrix([0,1]);\nG:c.invert(z*ident(2)-A).b;\n                       \\end{verbatim}\n               \\item[] \\vspace{1mm}\n                    $ G(z) = \\cfrac{1}{z-0.8}.\n                    $\n               \\end{itemize}\n               \\item \\vspace{3mm}Another case with cancellation: the characteristic polynomial of $A$\\\\\n                     has degree 2, the denominator of $G(z)$ has degree 1.\n       \\end{itemize}\n \\end{itemize}\n\\end{frame}\n\n\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (b) -- comments on the $S_1$ case}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item In fact $S_1$ is a ``fake'' 2nd order system, since as far as induced motions are\\\\\n       concerned  $x_1$ and $x_2$ are the same, and the system is \\TC{input-output} (i.e, as far\\\\\n       as we only look at $u$ and $y$) \\TC{equivalent} to a 1st order one:\n       \\begin{displaymath}\n        \\left\\{\\begin{array}{rcl}\n         x_1(k) &=& 0.5x_1(k-1)+u(k-1)\\\\\n         x_2(k) &=& 0.5x_2(k-1)+u(k-1)\\\\\n         y(k)   &=& x_1(k)+x_2(k)\n        \\end{array}\\right. \\quad\n        \\Rightarrow \\quad\n        \\left\\{\\begin{array}{rcl}\n         x(k) &=& 0.5x(k-1)+u(k-1)\\\\\n         y(k) &=& 2x(k)\n        \\end{array}\\right.\n        \\end{displaymath} \n        apparently with\n        \\begin{displaymath}\n         G(z)=\\cfrac{2}{z-0.5}.\n        \\end{displaymath} \n \\item This system cannot move in the whole $(x_1,x_2)$ plane, but only\\\\\n       on the straight line $x_1=x_2$.\n \\item In general, systems like this can only move on a \\TC{subspace} (line)\\\\\n       of their \\TC{state space} (plane).\n \\item We call them \\TC{not fully reachable} (the term should be intuitive).\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Solution}\n\\framesubtitleTC{Item (b) -- comments on the $S_2$ case}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Also $S_2$ is a ``fake'' 2nd order system, because however $x_1$ moves, $y$ does not\n       reveal this, and thus we can reduce this system as well to a 1st order one:\n       \\begin{displaymath}\n        \\left\\{\\begin{array}{rcl}\n         x_1(k) &=& 0.4x_1(k-1)+u(k-1)\\\\\n         x_2(k) &=& 0.8x_2(k-1)+u(k-1)\\\\\n         y(k)   &=& x_2(k)\n        \\end{array}\\right. \\quad\n        \\Rightarrow \\quad\n        \\left\\{\\begin{array}{rcl}\n         x(k) &=& 0.8x(k-1)+u(k-1)\\\\\n         y(k) &=& x(k)\n        \\end{array}\\right.\n        \\end{displaymath} \n        apparently with\n        \\begin{displaymath}\n         G(z)=\\cfrac{1}{z-0.8}.\n        \\end{displaymath} \n \\item In this system one state variable does not influence the output.\n \\item We call such systems \\TC{not fully observable} (the term should be\\\\\n       once again intuitive).\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Proposed exercise 03}\n\\framesubtitleTC{Try this at home, ask questions next time if needed}\n\\myPause\n Take the two system of exercise 03, and turn them into block diagrams.\\\\\n \\vspace{5mm}Analyse those diagrams along the idea that parts of the system are not influenced\n by the input, or do not influence the output. \n\\end{frame}\n\n\n\n\\begin{frame}\n\\frametitleTC{Takeaways}\n\\framesubtitleTC{from exercise 03 (and the proposed one)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item There are cases in which a system cannot move in all its state space, or equivalently,\n       some state variables are not influenced by the input.\n \\item Suggestion for reflections: why ``equivalently''?\n \\item There are also cases in which some state variables do not influence the output.\n \\item There are also cases where both facts occur.\n \\item We detect this because in computing the transfer function we get\\\\\n       \\TC{cancellations}.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Takeaways}\n\\framesubtitleTC{from exercise 03 (and the proposed one)}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Do we need to bother?\n \\item Yes, because this collectively means that a system may have \\TC{hidden parts}\\\\\n       (things the transfer function does not tell).\n \\item In setting up controls, we must be careful to not generate UNSTABLE hidden parts.\n \\item We do not mind about asymptotically stable ones, because their effect\\\\\n       vanishes with their free motion.\n \\end{itemize}\n\\end{frame}\n\n\n\n", "meta": {"hexsha": "c0625fa13ee321dd7aa1528402f82daa30d0a26e", "size": 6726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-03/sections/03-PS01-ex03.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-03/sections/03-PS01-ex03.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-03/sections/03-PS01-ex03.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.7989949749, "max_line_length": 103, "alphanum_fraction": 0.5582812965, "num_tokens": 2208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.6450856435960554}}
{"text": "\\Lecture{Jayalal Sarma }{ 2 october, 2020}{11}{More on PIE, PIE -Tuttes-Matrix-Tree-Theorem-Part2}{Shrinidhi Bajpayee}{$\\alpha$}{JS}\n\n\n\n\\section{Introduction}\nWe finished Tutte's Matrix Tree Theorem in non trivial way.Let's just recall Tutte's Theorem.We have directed graph $G(V,E)$.We have $V={v_1,v_2,....v_n}$.\\\\\nA $n \\times n$ matrix $L(G)$ called the \\textit{Laplacian matrix} of $G$ as follows.\n\\[\n  L(G)_{ij} =\n  \\begin{cases}\n    indeg(v_i) & \\mbox{ if } i = j \\\\\n    -1   & \\mbox{ if }~ i \\neq j ~\\text{and}~(v_i,v_j)\\in E \\\\\n    0    & \\mbox{ otherwise (When there is no edge) }\n  \\end{cases}\n\\]\nWhat theorem says,the number of spanning arborescences rooted at some vertex n is given by exactly equal to $det(L_G[i])$ Here i=n.\\\\\nQuickly Recap Definition of Spanning arborescences :An \\textit{Arborescence} is a directed graph in which a vertex $u$ is called the root and for every other vertex $v$ in the graph, there is exactly one directed path from $u$ to $v$. In simpler terms, an arborescence is an directed tree in which all the edges are directed away from the root. A \\textit{Spanning Arborescence} $S(V,E)$ of a directed graph $G(V',E')$ is an arborescence such that $V=V'$ and $E\\subseteq E'$.\\\\\nOne condition is that there is a directed path from V to every vertex in G within E'.\\\\\nSecond condition is underlying undirected graph should be a tree. \\\\ \\\\\nRecall the following from the last lecture.\n\\begin{align}\n  det(L_G[n]) = \\sum_{\\sigma \\in S_{n-1}}~\n  Sign(\\sigma)~\\prod_{i=1}^{n-1}L_{i\\sigma(i)}\n  \\label{eq:to_prove:Tutte}\n\\end{align} \\\\\n$S(n-1)$ is notation for permutation of $n-1$.\nThis is expression of determinant that we have seen in last lecture.\nSo we want to show it is equal to spanning arborescence we introduce concept called Spreg.So what is Spreg $?$.\nWe quickly define Spreg.\n\\begin{definition}\\textbf{Spregs:} Single prdecessor graphs or \\textit{Spregs} with distinguished vertex $v$ of a directed graph $G(V,E)$ is a subgraph $T(V,E')$, $E' \\subseteq E$, such that each vertex in $T$ except the vertex $v$ has exactly one predecessor and the vertex $v$ has no predecessors. In other words; in the spreg T, $indeg(v) = 0$ and for every $u \\neq v$, $indeg(u)=1$.\n\\end{definition}\nEvery vertex other than distinguished vertex must be indegree 1.Subgraph of G is called Spregs.So there are several spregs are possible similar to several spanning arborescence possible.\\\\\nWe want to count spanning arborescence using spregs.That will be very nice combinatorial interpretation of this topic,that is plan.\\\\\n\n%1. We want to count the number of spanning arborescence rooted at Vn.\\\\ \\\\\n2.We want to count the number of spregs distinguished vertex Vn.\\\\\nWe associated with last lecture that every spanning arborescence corresponds to spregs .It turns out there are more spregs.There is some structure,Spregs looks like are of the form arborescence $+$ weekly connected component 1 $+$ weekly connected component 2......\\\\\nV can not be part of cycle.V can be vertex in component.Weekly connecetd component has exactly 1 cycle.\\\\\nSo what we want to count spregs in inner circle with distinguished vertex Vn.Ok so already know what we have to count.Basic strategy is as follows:\\\\\nStrategy is that count the number of spregs with distinguished vertex Vn which does not have any cycle.So this is what we want to count.We want to use Inclusion Exclusion.In fact we will not only count through Inclusion exclusion but we will go through each term of the determinant expression corresponds to our counting terms.\\\\\nLet's demonstrate by writing down Inclusion exclusion.\\\\\nIn order to define Inclusion Exclusion formulation we need to define the \\\\ \\\\\n1.Universe (Called as X).\\\\\n2.Component $A_i$.\\\\\nTo define that Let's consider,notice that we want to count spregs without any cycle.\\\\\nWe need to be set of all spregs with distinguished vertex $V_n$.\\\\\nLet $C_1,C_2,C_3, \\dots , C_n$ be the set of cycles in graph G.We looking at simple cycle.\\\\\n$A_i$ define as spregs which contain the cycle $C_1$.The number of spregs which does not contain any cycle.This what we want to count.So,\\\\\n\n$|X|$ $-$ $|\\bigcup_{i=1}^{n} A_i|$\nIt is same as,\n$$|X| - \\sum_{I \\subseteq [n] , I \\neq \\emptyset} (-1)^{|I|+1}|\\bigcap_{i \\in I} A_i|$$\nSo already applied Inclusion Exclusion,Now write it as\n$$ |X| + \\sum_{I \\subseteq [n] , I \\neq \\emptyset} (-1)^{|I|+1}|\\bigcap_{i \\in I} A_i| $$\n\nSo basically we need to count this.We can say that each term in these expression are exactly same as term used in determinant expression.As number of Spregs are equal to number of spanning arborescence,hence theorem is called.This is strategy.Hence each term is associated with terms of determinant theorem.\\\\\n\\textbf{Observation:}Let's consider C1,C2 be two cycles.\\\\\nWhat can say about $$ A1 \\bigcap A2 = \\emptyset iff C1\n  \\bigcap C2 \\neq \\emptyset.$$\\\\\nEvery spregs looks like arborescence + uniquely weekly connected component 1 +uniquely weekly connected component 2.\\\\\n$$ If C1 \\bigcap C2 \\neq \\emptyset then |A1 \\bigcap A2| =0.$$\\\\\nUsing the observation,\\\\\nThe number of spregs with distinguished vertex Vn which is acyclic is nothing but \\\\\n$$ |X| + \\sum_{I \\subseteq [n] ,I \\neq \\emptyset ,for J,K \\in I, J \\neq K, cj \\bigcap ck =\\emptyset}       (-1)^{|I|+1}|\\bigcap_{i \\in I} A_i| $$\n\n\\textbf{Recall:} We counted |X| =Total number of spregs\\\\\n$$det(L_G[n]) = \\sum_{\\sigma \\in S_n} Sign(\\sigma)  \\prod_{i=1}^{n} a_{i\\sigma(i)}$$\\\\\nThis is determinant expression. term   corresponds   to   $$ \\sigma=id $$\n$$\\prod_{i=1}^{n-1} (L_i) = \\prod_{i=1}^{n-1} deg_in(L_i) $$\n\nNow we count the singleton sized I.\nSpregs that contain exactly one cycle.\nFix,I={1},We are counting spregs which contain only C1.\nLet  CI be (Vi1,Vi2,Vi3,....Vin)\n\n$$\\sigma(i1)=i2$$\n$$\\sigma(i2)=i3$$\n$$\\sigma(ik-1)=ik$$\n$$\\sigma(ik)=iI$$\n$$\\sigma \\in S_n-1$$\n$$\\forall other  i \\in {1...n} $$\n$$ \\sigma(i)=i $$\n\nThis is permutation which contain one cycle.\nNow we just able to do following\n\n\\textbf{Claim:} Term in the determinant expression for\n$$LG[n] corresponds to \\sigma=number of spregs which contain C1$$\nRight now we are talking about one circle.\nLet's see proof of this.\nProof of this is very natural.\n\n$$sign(\\sigma)\\prod_{i=1}^{n-1} L_i,\\sigma(i   $$\nsign of permutation is exactly equal to\n$(-1)^{(l-1)} $.Here length is l.\n\nSecond term is\n$$ (-1)^{(l-1)} (\\prod_i,|\\sigma(i)|=i L_i,i)(\\prod_i,|\\sigma(i)| \\neq i L_i,\\sigma(i)) $$\n$$ L_i,\\sigma(i) =-1,if V_i,V_\\sigma(i) is edge in graph \\in E\\\\ ootherwise  $$\nIf corresponding edge is present then this term is non zero otherwise zero.\\\\\n$$ (-1)^{(l-1)}(\\prod_i,|\\sigma(i)| deg_in(v_i))*(-1)^{l} $$\n$$= (-1)^{(2l-1)} |number of spregs which contain C1|  $$\n$$= -|number of spregs which contain C1 | $$\nProposition for $$ \\sigma \\in S_n-1 comsisting of single cycle.   $$$$ \\sigma =(i1,i2,.....il)   $$\nAssociate$ C\\sigma $ as a cycle corresponds to vertex sequence (Vi1,Vi2,Vi3.....Vil,Vii)\\\\\nThen the term in the determinant corresponds to $\\sigma$ satisfies following.\\\\\n$$sgn(\\sigma)(\\prod_{i=1}^{n-1}L_i,\\sigma(i))$$\n\n$$-(\\prod_{i,\\sigma(i)=i}deg_in(v_i))C_\\sigma \\subseteq G(V,E) $$\\\\\n$$ 0 if C\\sigma \\nsubseteq G(V,E) $$ \\\\\n$$-1  if C\\sigma \\subseteq G(V,E) if \\forall i \\sigma(i) \\neq i     $$\\\\\n\n\n\\textbf{Corollary:}$$For \\sigma,C\\sigma as above $$\\\\\n$$ |\\prod_{i=1}^{n-1}L_i,\\sigma(i)|=number of spregs which contain C_\\sigma   $$\\\\\nNow this is case for single cycle.\\\\Now we will generalise case for multiple cycle.\\\\\nSo it is very natural.\n\n\\textbf{Question:}Suppose $\\sigma \\in S_{n-1}$ is the product of $k>0$ disjoint cycle.\n$$\\sigma=(i11,i12,i13.....iil) (i21,i22,i23....(ikl,ik2,ik3...ikl)   $$\nk is number of cycles. So now we are associate\n$$ C_\\sigma = \\cup  {j=1}^{k}C_j  where C_j is (V_ij1....V_ijLj.....VijI)$$\n\nThen the term  corresponds to $\\sigma$ in $det(L_G[n])$\n$$sgn(\\sigma) = (-1)^{K} \\prod_{i|\\sigma(i)|}deg_in(V_i) if C_\\sigma \\subseteq G   $$\\\\\n$$ o if C\\sigma \\nsubseteq G $$\n\n\\textbf{Corollary:}If we look at\\\\\n$$|\\prod_{i=1}^{n}L_i,\\sigma(i)|=number of spregs which contain C_\\sigma = \\bigcup_{j=1}^{k}C_j   $$\\\\\n$$ det(L_G[n]) =\\sum_{\\sigma \\in S_n-1}sig(\\sigma) \\prod_{i=1}^{n} L_i\\sigma      $$\\\\\nThis is how determinant expression looks like.\\\\\nNumber of spanning arborescence rooted at Vn  as distinguished vertex and not containing cycle.\\\\\n%$$&=|X| + \\sum_{I \\subseteq [n] ,I \\neq \\emptyset, cj \\bigcap   ck=\\emptyset ,j,k \\in I}(-1)^I    $$\\\\\nThis is strategy.\nThis lecture is combinatorial application of PIE.\n\n\n\\Lecture{Jayalal Sarma}{Oct 10, 2020}{12}{Algorithmic Application of PIE}{Shrinidhi Bajpayee}{$\\alpha$}{JS}\n\n\\section{Introduction} We talk about counting problem.Its about given a $n*n$ bipartite graph,We want to count the number of perfect matching in it?\\\\\nsubset of edges such that every vertex has exactly one edge incident on it from the\nsubset.\\\\\nBipartite adjacency matrix is different from adjacency matrix.\\\\ \\\\\n\\textbf{Trivial Algorithm:}Run through all n sized subsets of E.\\\\\n$${n^{2} \\choose n } \\sim {n^{2} \\choose n}^{n}    \\sim n^{n} \\sim 2^{nlogn}$$\\\\\n\n$$ {n \\choose k}^{k} \\leq {n \\choose k} \\leq {n_e \\choose k}^{k} $$\\\\\ne=natural log base \\\\\n\\section{Decision Problem:}\n\\textbf{Binpacking Problem:}\nGiven a positive integer (bin capacity B),positive integer k\\\\\nWe have n item with weight S1,S2,S3.....,Sn\\\\\npartition the items into u1,u2,u3.....,uk\\\\\nCapacity is such that sum of weights of items in each ui is almost B.\\\\\nThis is binpacking problem.\\\\\nIt is NP-problem.\\\\\nBy PIE Time complexity is $O(nB2^{n})$\\\\\nn=number of items\\\\\nB=capacity\\\\\nNow we will reformulate PIE.\\\\\n\nGiven a collection of N combinatorial objects \\\\\nLet p(1),p(2),p(3)...p(n) be properties.\\\\\n$p_i$ is essential function \\\\\n$$ N \\to {0,1}   $$\\\\\nIt is possible that some object doesn't have properties of that.\\\\\n$$N_i \\to Number of objects among N with property P(i).$$\\\\\n$$ {i_1,i_2,....i_r} \\subseteq {1,2,3,...N} $$\\\\\n$$N_{i_1,i_2,i_3....i_r} = Number of objects with properties p(i_1) p(i_2)....p(i_r) $$\nN(0)=Number of objects not having any of the property.\\\\\n$$ N(0)=N-\\sum_{i=1}^{n} N_{i_1} +\\sum_{i_1<i_2}N_{i_1,i_2} -\\sum_{i_1 < i_2 <i_3}.......(-1)^{j} \\sum_{i_1<i_2<...i_j}N_{i_1,i_2...i_j} (-1)^{x}N_1...r   $$\\\\\nRestatement (Complementary term)(For the discussion)\\\\\n$$N \\to Number of objects.$$\\\\\n$$Q(1),Q(2),....Q(n) $$be properties that some of these objects have.\\\\\n$$W \\subseteq {1,2,....n}  $$\\\\\nLet N(W) be the number of objects having none of the properties Q(i).\\\\\n$$i \\in W   $$\\\\\nNow what we want to count the other set.\\\\\n$$X \\to number of objects which has all the properties.$$\\\\\n$$X = \\sum_{W \\subseteq [n]}(-1)^{|W|} N(W)   $$\\\\\n\\textbf{Pf:}$Define P(i) iff \\neg Q(i)$\\\\\nNow the above restatement is applicable.\\\\\nGiven a bipartite graph $G(u,v,E)\\\\\n  |u|=|v|=n $\\\\\ncount the number of perfect matching.\\\\\n\\textbf{I/p:}Bipartite adjacency matrix.\\\\\n\\includegraphics{images/graph.jpg}\\\\ \\\\\nThere are 2 perfect matching is in these graph.\\\\\nMatching 1: There is bijection.\\\\\nThere are 4!=24 permutation.But matching 1 and matching 2 are two permutation for perfect matching.\\\\\nHow's the algebric way of writing itself.\\\\\nLet's write $\\sigma \\in S_n$ \\\\\nConsider,\\\\\n$$ \\prod_{i=1}{n} a_i \\sigma(i)$$\\\\\nWhen $a_i \\sigma_i$ is non zero value.\nWhen $i\\sigma _i$ is true.\\\\\n$$\\prod a_ii = a11 .a22 .a33. a44$$\\\\\n$$ 1 $$\\\\\nWhat will be product of \\\\\n$$\\prod_{i=1}{n} a_i \\sigma(i) $$\\\\\n$$ a12. a21.a33.a44  $$\\\\\n$$ 0  $$\\\\\nIf corresponding edge is there in graph then value will be 1 otherwise 0.\\\\\na12=0 since no edge from 1 to 2.\\\\\nLet's write,\\\\\nPermanant of A=\\\\\n$$ \\sum_{\\sigma \\in S_n}  = Number of perfect matching in the graph.$$\\\\\nGiven a matrix A,\\\\\nIts two types are:\\\\\n!)permutataion (A) that is per(A): It is number of perfect matching in graph.\\\\\n2)Determinant (A) that is det(A)\\\\\n\\\\\n\\textbf{Problem:}Given a matrix A o/p the value of per(A)\\\\\n\\textbf{Trivial Algorithm:}Run over all $\\sigma \\in S_n$ compute the product \\\\\n$$\\prod_{i=1}{n}a_i \\sigma(i)$$ and add.\\\\\n$$O(n!) \\sim O(n ^{n}) \\sim 2^{nlogn} $$\\\\\n\\textbf{Lemma:}A is bipartite adjacency matrix of a bipartite graph G\\\\\n$$Per(A) = \\sum_{W \\in {1...n}}(-1)^{|W|} \\prod_{i=1}^{n}(\\sum_{j \\notin W}a_ij)$$\\\\\nApplying Lemma, $2^{n}$ W's and $n^{2}=remaining Computation$\\\\\n$2^{n}n^{2}$ time algorithm.\\\\\n\\textbf{PF:}To apply complementary form PIE.\\\\\nDefine N objects: $M \\in N$\\\\\n$M \\subseteq E$ such that for  every \\\\\n$\\forall i \\in {1...n}$ the vertex $X_i$ is the endpoint of some vertex in M.\\\\\n$\\forall j \\in [n] Q(j)$: Vertex $Y_j$ is the endpoint of some vertex in M.\\\\\nWe want to count number of objects from underlined part which satisfies Q(1) .....Q(n)\\\\\nThe number of perfect matching=per(A)=number of objects which satisfies all of Q(1) Q(2)....Q(n)\\\\\nQ(1) says first one is matched.\\\\\nQ(2) says second one is matched.\\\\\nLike this etc etc.\\\\\nWhen all vertex are matched from both side.\\\\\n$$ \\sum_{W \\in {1...n}}(-1)^{|W|}$$\\\\\nN(W)=Number of objects which satisfies none of property in W.\\\\\n\\includegraphics{images/img.jpg}\\\\ \\\\\nPer(A)=Number of perfect matching.\\\\\n$$ \\sum_{W \\subseteq {1...n}}(-1)^{|W|}(\\prod_{i=1}^{n}(\\sum_{j \\in w}aij)) $$\\\\\nThis completes the proof of the Lemma.\\\\\nThis lemma gives $O(2^{n}n^{2})$ algorithm for computing number of perfect matching in a given bipartite graph.\\\\\n\n\\textbf{Quickly Recap:}\\\\\n\\textbf{Binpacking problem:}\\\\\n$Bin capacity B,We have number of bins K,We have n items S1....Sn are sizes.$ \nQuestion is Can we partition items to $u1....uk[n]$ such that\n%$$\\forall_{i\\leq j \\leq k} j\\sum_{i \\in u}Si \\leq B}$$\n  We want to count this.\\\\\n  \\textbf{Algorithm:}\\\\\n  \\textbf{Trivial Algorithm:}Run through partition.\\\\\n$$ n \\choose k$$\\\\\n$O(nB2^{n})$ time space.\\\\\nA partition of [n] into u1....uk is said to be feasible if the sum of the sizes of item $\\leq$ B in uj.\\\\\n\\textbf{Relax:}Items can appear more than once.\\\\\n\\textbf{observation:}A feasible solution with relaxation will remain feasible without relaxation.\\\\\n\\textbf{Relaxed Solution:}ordered set of K lists of items from ${1...n}$.\\\\\n1.Each of the elements in ${1...n}$ appears atleast in one list.\\\\\n2.For each list $a1,a2....ap$\n$$\\sum_{h=1}{p}S_ak \\leq B $$\\\\\nTo apply PIE,we need to define objects $Q1....$\\\\\n\\textbf{Objects:}Ordered sets of K list of elements from {1...n} such that for each list (a1...ap) $$\\sum_{h=1}{p}S_an \\leq B $$\\\\\nQ(1):=The ordered list of k lists contain 1 in atleast one list in it.\\\\\n.\\\\\n.\\\\\n.\\\\\nQ(W):=W  is contained in atleast one of the lists in the ordered set of list.\\\\\n.\\\\\n.\\\\\n.\\\\\nQ(n)\\\\\nX=Set of objects which satisfy all of the properties Q(1)....Q(n)\\\\\n$$X=\\sum_{w \\subseteq [n]}(-1)^{|w|} N(W) $$\\\\\n\\textbf{Aim:}To compute N(W)\\\\\nA(W):=Number of list a1....ap of elements list in W.\\\\\n$$ \\sum_{h=1}{p}S(an) \\leq B $$\\\\\n$$N(W)=(A(W))^{k}  $$\\\\\n\\textbf{Aim:}Compute A(W)\\\\\n$P_w(j)$ =number of list a1....ap of which element not in w such that\n$$\\sum_{h=1}{p}S(ak)=j  $$\\\\\n$$A(w)=\\sum_{j=0}{B}P_w(j)$$\\\\\n$$P_w(j)=\\sum_{i \\notin w}P_W(j-s(w)) $$\\\\\n$$ p_W(j)=0, j<0 $$\\\\\n$$P_w(0)=1 $$\\\\\nTime taken is $O(nB2^{n})$\n\n\n% Lecture 3\n\n\n\\Lecture{Jayalal Sarma}{Oct 10, 2020}{13}{From Principle of Inclusion-Exclusions to Mobius Inversion}{Sandip Saha}{$\\alpha$}{JS}\n\n% \\section{Introduction}\nThe journey so far has been that we have started with pigeon hole principle and its applications then we used double counting and bijections to establish different identities then we moved to PIE and its different applications.\n% Then we came to Principle of Inclusion-Exclusion(PIE) as a consequence of a bijection argument. \nIn this lecture, we will look at a more generalized version of PIE and move gradually towards the Mobius Inversion.\n\n\\subsection{PIE Revisited}\nPreviously we have used PIE to compute $\\left| \\bigcup^n _{i=n} A_i \\right|$ as follows,\n\\[ \\left| \\bigcup^n _{i=n} A_i \\right|=\\sum_{\\emptyset \\neq I \\subseteq [n]} (-1)^{|I|+1}\\left|\\bigcap_{i\\in I} A_i\\right|\\]\nNow, we are interested to compute $\\left|\\bigcap_{i=1}^n  \\overline{A_i}\\right|$, which can be rewritten as,\n\\begin{align}\n  \\left|\\bigcap_{i=1}^n  \\overline{A_i}\\right| & = \\left|\n  \\overline{\\bigcup_{i=1}^n  A_i}\n  \\right| \\nonumber \\tag{using De-morgan's law}                                                                                                                    \\\\\n                                               & = \\left| X \\right| - \\left| \\bigcup^n _{i=n} A_i \\right| \\nonumber                                                \\\\\n                                               & = \\left| X \\right| -\\sum_{\\emptyset \\neq I \\subseteq [n]} (-1)^{|I|+1}\\left|\\bigcap_{i\\in I} A_i\\right| \\nonumber \\\\\n                                               & = \\sum_{ I \\subseteq [n]} (-1)^{|I|}\\left|\\bigcap_{i\\in I} A_i\\right|\n\\end{align}\n\nNote that $\\bigcap_{i\\in \\emptyset} A_i =X$. This thing can also be stated in the following way.\n\n\\begin{theorem}\n  Let $X$ be a finite set and $P_1,\\dots, P_m$ properties. Further define for $S \\subseteq [m]$ the set $N(S) = \\{x\\in X \\mid \\forall i \\in S: x \\text{ has property } P_i\\}$  then, number of elements in $X$ satisfying none of the properties $P_1,\\dots, P_m$ is given by,\n  $$ \\sum_{S \\subseteq [m]} (-1)^{|S|} \\left| N(S) \\right|$$\n\\end{theorem}\n\n\\subsection{Stronger version of PIE}\nThe Inclusion-Exclusion Principle has a stronger version which is as follows.\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\n\\begin{proof}\n  Let $f$ and $g$ are functions from the powerset of $[n]$ to real numbers and for all $A \\subseteq [n]$\n  \\[g(A)=\\sum_{S\\subseteq A}f(S)\\]\n\n  \\begin{align}\n    \\sum _{s\\subseteq A}( -1)^{|A|-|S|} g( S) & =\\sum _{s\\subseteq A}( -1)^{|A|-|S|}\\left(\\sum _{T\\subseteq A} f( T)\\right) \\nonumber \\\\\n                                              & =\\sum _{T\\subseteq A} C_{T} f( T)\n  \\end{align}\n  Where $C_T$ is appropriate signed number. Our aim is now to find $C_T$ for different $T$\n\n  \\begin{description}\n    \\item{\\textbf{Case 1: }($T=A$)} $C_T=1$, since $f(A)$ is only encountered for $T=S=A$.\n\n    \\item{\\textbf{Case 2: }($T \\neq A$)} choosing a set between $T$ and $A$ is equivalent of choosing a set from $A\\setminus T$\n          \\[C_T=\\sum _{T \\subseteq S\\subseteq A}( -1)^{|A|-|S|}=\\sum^k_{i=0}(-1)^{k-1} {k \\choose i} =0 \\]\n  \\end{description}\n  This proves the claim.\n  \\[\\boxed{\\therefore f(A) =  \\sum_{S \\subseteq A} (-1)^{|A|-|S|}g(S)}\\]\n\\end{proof}\n\n\\textbf{Why it is strong version?} it implies PIE.\nAssume the strong version, we can derive PIE.\n\\begin{proof}\n  Properties $P_1,\\dots, P_m$ of elements of $X$ . $X_1,\\dots, X_m$ are the subsets of $X$ satisfying the respective property i.e. $X_i=\\{ x\\in X \\mid x \\text{ satisfy } P_i\\}$.\n  then for $S \\subseteq [m]$  we define $f(S)$ to be the number of elements in $X$ having all properties $P_i$ such that $i \\notin S$ and none of the properties $P_j$ such that $ j \\in S$ i.e.\n  \\[ f(S) = \\left| \\bigcap_{i\\in [m] \\setminus S} X_i \\setminus \\bigcup_{i\\in S} X_i \\right| \\]\n  We are interested in counting the number of elements in $X$ which does not satisfy any property in $P_1,\\dots, P_m$ i.e. $f([m])$. We define,\n\n  \\begin{align*}\n    g(A) & = \\sum_{S\\subseteq A} f(S)                         \\\\\n         & = \\left| \\bigcap_{i \\in [m] \\setminus A}X_i\\right| \\\\\n         & = N([m]\\setminus A)\n  \\end{align*}\n  $g(A)$ counts $x\\in X$ if the property that $x$ does not satisfy forms a subset of $A$. By \\ref{stronger PIE}\n  \\begin{align*}\n    f([m]) & = \\sum_{S\\subseteq [m]}(-1)^{m-|S|} g(S) \\\\\n           & = \\sum_{\\substack{\n    S'\\subseteq [m]\\setminus S                        \\\\\n        S\\subseteq [m]}}\n    (-1)^{|S'|} N(S')                                 \\\\\n           & = \\sum_{S \\subseteq [m]} (-1)^{|S|} N(S)\n  \\end{align*}\n  This concludes the proof.\n\\end{proof}\n\n\n\n", "meta": {"hexsha": "8ddd290fd02df953f9869af6f81f6712afa18347", "size": 20035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week04.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": "week04.tex", "max_issues_repo_name": "pot8ohead/theory-toolkit", "max_issues_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "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": "week04.tex", "max_forks_repo_name": "pot8ohead/theory-toolkit", "max_forks_repo_head_hexsha": "177249454691f7e264d9ee7d5a354e180a54e095", "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": 53.2845744681, "max_line_length": 476, "alphanum_fraction": 0.6516096831, "num_tokens": 6750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6450856300486574}}
{"text": "\\documentclass{article}\r\n\\usepackage{fullpage}\r\n\\usepackage{nopageno}\r\n\\begin{document}\r\n\\title{Section 1.1 Problems 2, 18, 26, 46}\r\n\\author{Jon Allen}\r\n\\date{September 4, 2013}\r\n\\maketitle\r\n\\section*{\\#2}\r\nDetermine if each of the following equations is an ODE or a PDE. If the equation is an ODE, then determine (a) the order of the ODE and (b) if the equation is leinear or nonlinear.\r\n\r\n$y\\frac{\\mathrm{d}y}{\\mathrm{d}x}+y^4=\\sin x$\r\n\r\nThe equation is an ODE of order one. It is nonlinear as neither the $y\\frac{\\mathrm{d}y}{\\mathrm{d}x}$ term or the $y^4$ term fit the definition for linearity.\r\n\\section*{\\#18}\r\nVerify that the given function is a solution to the corresponding differential equation.\r\n\r\n$\\mathrm{d}y/\\mathrm{d}x+xy=0$, $y(x)=e^{-x^2/2}$\r\n\r\nWe find $\\frac{\\mathrm{d}y}{\\mathrm{d}x}=-xe^{-x^2/2}$. Substituting this result into the differential equation we find $-xe^{-x^2/2}+x\\cdot e^{-x^2/2}=0$ which is true. The given function is a solution to the differential equation.\r\n\\section*{\\#26}\r\nVerify that the given function is a solution to the corresponding differential equation.\r\n\r\n$y'''-2y''=0$, $y=A+Bt+Ce^{2t}$\r\n\r\nWe start by finding the first, second and third derivatives of $y$. $y'=B+2Ce^{2t}$, $y''=4Ce^{2t}$, $y'''=8Ce^{2t}$. Substituting $y'''$ and $y''$ into the differential we have $8Ce^{2t}-2\\cdot4Ce^{2t}=0$. We see that the function $y$ is a solution to the differential equation regardless of the values of $A$, $B$, and $C$.\r\n\\section*{\\#46}\r\nUse the indicated conditions with the indicated solution to determine the solution to the given problem.\r\n\r\n$\\mathrm{d}y/\\mathrm{d}t+y=\\sin t$, $y(0)=-1$, $y(t)=Ae^{-t}-\\frac{1}{2}\\cos t+\\frac{1}{2}\\sin t$\r\n\r\nFirst we substitute the initial value of $y(0)=-1$ into $y(t)$ to obtain $-1=Ae^0-\\frac{1}{2}\\cdot1+\\frac{1}{2}\\cdot0=A-\\frac{1}{2}$ or $A=-\\frac{1}{2}$. Our solution then is $y(t)=-\\frac{1}{2}\\left(e^{-t}+\\cos t-\\sin t\\right)$\r\n\\end{document}\r\n", "meta": {"hexsha": "9fec13304018fdfe0ddfe7b25a5bde018c2f7b2b", "size": 1939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential equations/diffeq-hw-2013-09-04.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": "differential equations/diffeq-hw-2013-09-04.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": "differential equations/diffeq-hw-2013-09-04.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": 57.0294117647, "max_line_length": 326, "alphanum_fraction": 0.6740587932, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8976952948443462, "lm_q1q2_score": 0.6450788051123886}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{mexhat}\n\\section*{\\hspace*{-1.6cm} mexhat}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nMexican hat wavelet in time domain.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nh = mexhat\nh = mexhat(nu)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty mexhat} returns the mexican hat wavelet, with central\n        frequency {\\ty nu} ({\\ty nu} is a normalized frequency). Its\n        expression writes\n\\[h(t)=\\nu\\ \\frac{\\sqrt{\\pi}}{2}\\ (1-2(\\pi\\nu t)^2)\\ \\exp[-(\\pi\\nu\\ t)^2].\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty nu} & any real between 0 and 0.5         & {\\ty 0.05} \\\\\n \\hline {\\ty h}  & time vector containing the mexhat samples\\\\ \n                 & {\\ty length(h)=2*ceil(1.5/nu)+1}\\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         plot(mexhat);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nklauder.\n\\end{verbatim}\n\\end{minipage}\n", "meta": {"hexsha": "f810415477916e369bb55fca7ac9e6e59dfd5508", "size": 1478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/mexhat.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/mexhat.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/mexhat.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 21.1142857143, "max_line_length": 76, "alphanum_fraction": 0.6265223275, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.6450632616531233}}
{"text": "\n\\documentclass{scrartcl}\n\n\\input{../../shared.tex}\n\n\\begin{document}\n\n\\section*{Exercises on (quasi) Newton methods}\n\n\\paragraph{Exercise (i)} (2P) Show that Newton's method applied to a nondegenerate quadratic function yields a Quasi-Newton method.\\\\\n\\textbf{Bonus points:} Show that this is an \\textit{if and only if}.\n\n\\paragraph{Exercise (ii)} (2P) Consider a step of the secant method:\n        \\begin{equation}\n          x_{k+1} = x_k - f(x_k)\\frac{x_k-x_{k-1}}{f(x_k)-f(x_{k-1})}.\n        \\end{equation}\n        Assuming that $x_k\\neq x_{k-1}$ and $f(x_k)\\neq f(x_{k-1})$, prove that the line through the two points $(x_{k-1}, f(x_{k-1}))$ and $(x_k, f(x_k))$ intersects the $x$-axis at the point $x=x_{k+1}$.\n\\paragraph{Exercise (iii)} (6P) Complete the notebook.\n\n\\end{document}\n", "meta": {"hexsha": "1da0df9d70cb59ef8aa298c1175baba9ddb50440", "size": 788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/09_Newtons-method/exercises_Newtons_method.tex", "max_stars_repo_name": "kiwomuc/optimization-for-DS-lecture", "max_stars_repo_head_hexsha": "43ea50ef85f73b5bbc7659e8c457218ae136bb94", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-10-03T14:40:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T15:34:36.000Z", "max_issues_repo_path": "exercises/09_Newtons-method/exercises_Newtons_method.tex", "max_issues_repo_name": "kiwomuc/optimization-for-DS-lecture", "max_issues_repo_head_hexsha": "43ea50ef85f73b5bbc7659e8c457218ae136bb94", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-10-21T13:02:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-06T19:50:32.000Z", "max_forks_repo_path": "exercises/09_Newtons-method/exercises_Newtons_method.tex", "max_forks_repo_name": "kiwomuc/optimization-for-DS-lecture", "max_forks_repo_head_hexsha": "43ea50ef85f73b5bbc7659e8c457218ae136bb94", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2021-10-05T21:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-04T15:38:30.000Z", "avg_line_length": 37.5238095238, "max_line_length": 205, "alphanum_fraction": 0.6611675127, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812552, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.6450632560957072}}
{"text": "\\section[sct:distance]{Extracting Distances}\n\n\\distance{} prints distances between nodes, in various ways.  By default, it\nprints the distance from the root of the tree to each labeled leaf, in \\nw{}\norder. Let's look at distances in the catarrhinian tree:\n\n\\svgFigure{display_3}\n\n\\txtCmdOutput{dist_1}\n\n\\noindent{}This means that the distance from the root to \\id{Gorilla} is\n56, etc. The distances are in the same units as the tree's branch lengths --\nusually substitutions per site, but this is not specified in the tree itself.\nIf the tree is a cladogram, the distances are expressed in numbers of\nancestors.  Option \\code{-n} shows the labels:\n\n\\txtCmdOutput{dist_2}\n\nThere are two main parameters to \\distance: the {\\em method} and the\n{\\em selection}. The method determines how to compute the distance (from what\nnode to what node), and the selection determines for which nodes the program is\nto compute distances. Let's look at examples.\n\n\\subsection{Selection}\n\nIn this section we will show the different selection types, using the default\ndistance method (\\ie{}, from the tree's root -- see below). The selection type\nis the argument to option \\code{-s}.  The nodes appear in the same order as\nin the Newick tree, except when they are specified on the command line (see\nbelow).\n\nTo illustrate the selection types, we need a tree that has both labeled and\nunlabeled leaves and inner nodes. Here it is:\n\n\\svgCmdOutput{dist_3}\n\nWe will use option \\code{-n} to see the node labels.\n\n\\subsubsection{All labeled leaves}\n\nThe selection consists of all leaves with a label. This is the default, as\nleaves will mostly be labeled and we're generally more interested in leaves\nthan inner nodes.\n\\txtCmdOutput{dist_4}\n\n\\subsubsection{All labeled nodes}\n\nOption \\code{-s l}. This takes all labeled nodes into account, whether they are leaves or inner nodes.\n\\txtCmdOutput{dist_5}\n\n\\subsubsection{All leaves}\n\nOption \\code{-s f}. Selects all leaves, whether they are\nlabeled or not.\n\\txtCmdOutput{dist_6}\n\n\\subsubsection{All inner nodes}\n\nOption \\code{-s i}. Selects the inner nodes, labeled or not.\n\\txtCmdOutput{dist_9}\n\n\\subsubsection{All nodes}\n\nOption \\code{-s a}. All nodes are selected.\n\\txtCmdOutput{dist_7}\n\n\\subsubsection{Command line selection}\n\nThe selection consists of the nodes whose labels are passed as arguments on the\ncommand line (after the file name). The distances are printed in the same\norder.\n\n\\txtCmdOutput{dist_8}\n\n\\subsection{Methods}\n\nIn this section we will take the default selection and vary the method. The\nmethod is passed as argument to option \\code{-m}. I will also use an\n\\adhoc{} tree to illustrate the methods:\n\n\\svgCmdOutput{dist_11}\n\n\\noindent{}As explained above, the default selection consists of all labeled\nleaves -- in our case, nodes \\id{A}, \\id{B} and \\id{C}. \n\n\\subsubsection{Distance from the tree's root}\n\nThis is the default method: for each node in the selection, the program prints\nthe distance from the tree's root to the node. This was shown above, so I\nwon't repeat it here.\n\n\\subsubsection{Distance from the last common ancestor}\nOption \\code{-m l}. The program computes the \\lca{} of all nodes in the\nselection (in our case, node \\id{e}), and prints out the distance from\nthat node to all nodes in the selection.\n\\txtCmdOutput{dist_10}\n\n\\subsubsection{Distance from the parent}\nOption \\code{-m p}. The program prints the length of each selected node's\nparent branch.\n\\txtCmdOutput{dist_12}\n\n\\subsubsection{Matrix}\nOption \\code{-m m}. Computes the pairwise distances between all nodes in the\nselection, and prints it out as a matrix.\n\\txtCmdOutput{dist_13}\n\n\\subsection{Alternative formats}\n\nOption \\code{-t} changes the output format. For matrix output, (\\code{-m\nm}), the matrix is triangular. \n\\txtCmdOutput{dist_16}\nWhen labels are printed (option \\code{-n}), the diagonal is shown\n\\txtCmdOutput{dist_14}\n\nFor all other formats, the values are printed in a line, separated by\n\\cap{tab}s.\n\\txtCmdOutput{dist_15}\n", "meta": {"hexsha": "9873155f117803274740a861d0645f0f8131a910", "size": 3969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/c-distance.tex", "max_stars_repo_name": "Cactusolo/newick_utils", "max_stars_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2015-01-08T22:22:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:12:51.000Z", "max_issues_repo_path": "doc/c-distance.tex", "max_issues_repo_name": "Cactusolo/newick_utils", "max_issues_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2015-01-22T19:34:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-27T10:53:41.000Z", "max_forks_repo_path": "doc/c-distance.tex", "max_forks_repo_name": "Cactusolo/newick_utils", "max_forks_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-05-07T09:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T02:43:50.000Z", "avg_line_length": 33.3529411765, "max_line_length": 102, "alphanum_fraction": 0.7692113883, "num_tokens": 1007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6450632540849488}}
{"text": "\\SecDef{minimalist}{Minimalist Quadratic Masking Scheme}\n\nIn this section I show a first-order algebraically secure quadratic masking scheme. Then I describe concrete circuits which can be verified to be first-order algebraically secure gadgets using \\AlgRef{verify}.\n\n\\subsubsection{Minimalist Quadratic Masking.}\nSince the decoding function has to be at least quadratic, we need at least two bits to encode a single bit. For two bits all nonlinear decoding functions are linear equivalent to a quadratic monomial being simply the product of the two input bits. Unfortunately, this decoding function is vulnerable to the linear algebra attack. Any quadratic function with 2-bit input is unbalanced. Therefore, one of the reference bit values can be encoded by 3 different values and the other value has only 1 possible encoding. For example, if the value is equal to 1 and the decoding function is simply AND, the input has to be equal to (1, 1). In this case there is no randomness involved and the hidden value is leaked. \nThe conclusion is that any value of the original bit should include randomness in its encoding. In particular, the decoding function can not be a point function.\n\nWe move on to 3-bit encodings. The simplest quadratic function using all 3 input bits $a,b,c$ is $ab\\oplus c$. Note the similarity with the broken 2-bit scheme: the quadratic monomial $ab$ is simply linearly masked by $c$. However, this linear mask is enough to prevent the attack: in this case $\\dec(a,b,c)=1$ does not imply $a=1$ or $b=1$. In fact, such $\\dec$ is balanced: both 0 and 1 have exactly 4 preimages. We first describe an insecure yet simple masking scheme based on this decoding function in \\FigRef{insecure}. It is easy to verify that $Eval_{XOR}$ and $Eval_{AND}$ satisfy the requirements from Definition~\\ref{wba.def:masking}. In addition, $Refresh(a, r)$ returns fresh random encoding of $a$, meaning that $\\dec(a) = \\dec(Refresh(a, r))$ for any $r$ and new encoding reveals no information about the old encoding.\n\n\\begin{figure}\n\\vspace{-0.5em}\n\\FigDef{insecure}{An Insecure Quadratic Masking Scheme.}\n\\vspace{-0.5em}\n\\begin{align}\n    \\enc(x,r_a,r_b)              &~=~ (r_a,r_b,r_ar_b \\oplus x),\\\\\n    \\dec(a,b,c)                  &~=~ ab \\oplus c,\\\\\n    Eval_{XOR}((a,b,c),(d,e,f)) &~=~ (a\\oplus d,~ b \\oplus e,~  ae \\oplus bd \\oplus c \\oplus f),\\\\\n    Eval_{AND}((a,b,c),(d,e,f)) &~=~ (ae,~        bd,~         (cd)e \\oplus a(bf) \\oplus cf),\\\\\n    Refresh((a,b,c),(r_a,r_b))  &~=~ (a \\oplus r_a,~ b \\oplus r_b,~ c \\oplus r_ab \\oplus r_ba \\oplus r_a r_b).\n\\end{align}\n\\vspace{-0.5em}\n\\end{figure}\n\nWe now observe that $Refresh$ is not $\\maxcor$-1-AS for any $\\maxcor < 1$: the computed term $r_a b$ is constant when $b$ is fixed to 0 and equals to $r_a$ otherwise (leading to $\\maxcor = 1$). This can be fixed by using an extra random bit $r_c$ to mask $a,b$ through the computations:\n\\begin{multline}\n    Refresh((a,b,c),(r_a,r_b,r_c)) ~=~ \\\\\n    \\big(\n    a \\oplus r_a,~\n    b \\oplus r_b,~\n    c \\oplus r_a(b \\oplus r_c) \\oplus r_b (a \\oplus r_c) \\oplus (r_a \\oplus r_c)(r_b \\oplus r_c) \\oplus r_c\n    \\big).\n\\end{multline}\n\nThe new $Refresh$ function can be verified to be secure using the algorithm from \\SecRef{verify}. Moreover, the circuit computing $Eval_{XOR}$ applied to refreshed inputs is secure as well. However, $Eval_{AND}$ is not secure even if composed with the fixed $Refresh$ gadget. Consider the linear combination of computed terms $a(bf) \\oplus cf = (ab \\oplus c)f$. Here the variables are refreshed masks and can not be fixed by the adversary. However, the refreshing function does not change the hidden value. Therefore, $ab \\oplus c$ would be equal to the value hidden by initial non-refreshed shares which can be fixed. Fixing the hidden value to 0 makes the combination $f(ab \\oplus c)$ equal to 0 and be equal to the random share $f$ when the hidden value is fixed to 1. We observe that it is possible to use a trick similar to the one used to fix the $Refresh$ function. In fact, the extra random shares added to fix the $Refresh$ function may be reused to fix the $Eval_{AND}$ function. As a result, we obtain a fully secure masking scheme. The complete description is given in \\AlgRef{mqms}.\n\n\\begin{algorithm}[ht]\n    \\AlgDef{mqms}{Minimalist Quadratic Masking Scheme.}\n    \\begin{algorithmic}[1]\n        \\Function{Encode}{$x,r_a,r_b$}\n            \\State \\Return{$(r_a,r_b,r_ar_b \\oplus x)$}\n        \\EndFunction\n        \\Statex\n        \\Function{Decode}{$a,b,c$}\n            \\State \\Return{$ab\\oplus c$}\n        \\EndFunction\n        \\Statex\n        \\Function{EvalXOR}{$(a,b,c),(d,e,f),(r_a,r_b,r_c),(r_d,r_e,r_f)$}\n            \\State $(a,b,c) \\gets \\textsc{Refresh}((a,b,c),(r_a,r_b,r_c))$\n            \\State $(d,e,f) \\gets \\textsc{Refresh}((d,e,f),(r_d,r_e,r_f))$\n            \\State $x \\gets a \\oplus d$\n            \\State $y \\gets b \\oplus e$\n            \\State $z \\gets c \\oplus f \\oplus ae \\oplus bd$\n            \\State \\Return{$(x,y,z)$}\n        \\EndFunction\n        \\Statex\n        \\Function{EvalAND}{$(a,b,c),(d,e,f),(r_a,r_b,r_c),(r_d,r_e,r_f)$}\n            \\State $(a,b,c) \\gets \\textsc{Refresh}((a,b,c),(r_a,r_b,r_c))$\n            \\State $(d,e,f) \\gets \\textsc{Refresh}((d,e,f),(r_d,r_e,r_f))$\n            \\State $m_a \\gets bf \\oplus r_c e$\n            \\State $m_d \\gets ce \\oplus r_f b$\n            \\State $x \\gets ae \\oplus r_f$\n            \\State $y \\gets bd \\oplus r_c$\n            \\State $z \\gets am_a \\oplus dm_d \\oplus r_c r_f \\oplus cf$\n            \\State \\Return{$(x,y,z)$}\n        \\EndFunction\n        \\Statex\n        \\Function{Refresh}{$(a,b,c),(r_a,r_b,r_c)$}\n            \\State $m_a \\gets r_a \\cdot (b \\oplus r_c)$\n            \\State $m_b \\gets r_b \\cdot (a \\oplus r_c)$\n            \\State $r_c \\gets\n                m_a \\oplus m_b \\oplus\n                (r_a \\oplus r_c) (r_b \\oplus r_c) \\oplus\n                r_c$\n            \\State $a \\gets a \\oplus r_a$\n            \\State $b \\gets b \\oplus r_b$\n            \\State $c \\gets c \\oplus r_c$\n            \\State \\Return{$(a,b,c)$}\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\paragraph{Security.}\nFirst, we verify $Eval_{XOR}$ and $Eval_{AND}$ gadgets using \\AlgRef{verify}. We obtain that they are $\\maxcor$-1-AS circuits for some $\\maxcor < 1$. Then we construct the ANFs of intermediate functions. The maximum degree is equal to 4. It is achieved for example in the term $cf$ in the gadget $Eval_{AND}$: its ANF contains the term $r_ar_br_dr_e$. Therefore, $Eval_{AND}$ is $\\maxcor$-1-AS with $\\maxcor \\le 7/8$. The gadget $Eval_{XOR}$ has degree 2 and is $1/2$-1-AS. Unfortunately, we do not have a pen-and-paper proof for security of the gadgets and rely solely on the verification algorithm (which is able to spot the described weaknesses in the insecure versions of the gadgets).\n\nVerifying security of the encoding function $\\enc$ can be done in the same way. Clearly, no linear combination of $r_a,r_b,r_ar_b\\oplus x$ is constant for any fixed $x$. The coordinate $r_ar_b\\oplus x$ has degree 2 and its absolute correlation is equal to $1/2$. Therefore, $\\enc$ is an $\\maxcor$-1-AS encoding with $\\maxcor=1/2$.\n\nBy applying \\PropRef{combine}, we obtain that for any adversary $\\adv$, for any circuit $C$ build from the gadgets $Eval_{XOR}, Eval_{AND}$ and for the described $\\enc$ encoding we have:\n\\begin{equation}\n    \\advanPS[\\adv] \\le min(2^{Q-\\rC}, 2^{eQ}),\n\\end{equation}\n\nwhere $e = \\log_2{(1+7/8)/2}\\approx -0.093$. According to Corollary~\\Ref{cor:seclevel}, in order to achieve provable 80-bit security we need to have $\\rC \\ge 80(1 - 1/e) \\approx 940$ random bits in the circuit. Note that it does not depend on the actual size of the circuit, i.e. 940 random bits are enough for an arbitrary-sized circuit. However, the adversary should not be able to shrink the window so that it contains less than 940 random bits. This is expected to be guaranteed by a \\SH{} protection. Finally, we remark that the bounds are rather loose and more fine-grained analysis should improve the bound significantly.\n\n\n\\subsection{Implementation}\n\nWe applied our masking scheme to an AES-128 implementation to estimate the overhead. Our reference AES circuit contains 31,783 gates. It is based on Canright's S-Box implementation~\\cite{Canright} and naive implementation of MixColumns. After applying our nonlinear masking scheme and a first-order linear masking scheme on top the circuit expands to 2,588,743 gates of which 409,664 gates are special gates modeling external random bits. The circuit can be encoded in 16.5 MB. Extra RAM needed for computations is less than 1KB. On a common laptop it takes 0.05 seconds to encrypt 1 block. Since the implementation is bitwise, 64 blocks can be done in parallel at the same time on 64-bit platforms. There is still a large room for optimizations. We used the Daredevil CPA tool~\\cite{SCM} to test our implementation. Due to the first-order linear masking on top we did not detect any leakage. Pure nonlinear masking scheme does leak the key so the combination of both is needed as we suggested in \\SecRef{method}. The implementation code is publicly available~\\cite{OurWhiteboxCode}. We remark that it is a proof-of-concept and not a secure white-box implementation; it can be broken in various ways.", "meta": {"hexsha": "987cda28d1c5c4e782964b59a9e9b8c0e6dbb5b4", "size": 9280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9wbCounter/4minimalist.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/9wbCounter/4minimalist.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/9wbCounter/4minimalist.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": 94.693877551, "max_line_length": 1200, "alphanum_fraction": 0.6929956897, "num_tokens": 2643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.6450632522641342}}
{"text": "\\section{Dijkstra's Algorithm as Skeleton}\n\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm}\n  Invariant: maintain $R \\subseteq V$: $\\forall u \\in R: s \\leadsto u$ is known\n  \\begin{exampleblock}{3. How to update $\\text{dist}[w]$ for $(v,w) \\in E \\land w \\notin R$?}\n    new estimator for $\\text{dist}[w]$\n    \\begin{verbatim}\n      forall (e = (v,w) in E) and (w not in R)\n      if dist[w] > dist[v] + w(v,w)\n        dist[w] = dist[v] + w(v,w)\n    \\end{verbatim}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm as skeleton}\n  \\begin{verbatim}\n    Initialization: \n      dist[s] = 0;\n      dist[v] = infty for others\n\n    Q = MakePriorityQueue(V) with dist[v] as keys \n                       (using min-heap)\n\n    while (Q is not empty)\n      v = deleteMin(Q)\n      foreach edge (v,w) in E // w in Q\n        if dist[w] > dist[v] + w(v,w)\n          dist[w] = dist[v] + w(v,w)\n          decreaseKey(Q, w)\n        else if dist[w] = dist[v] + w(v,w)\n        //  do nothing\n  \\end{verbatim}\n\n  \\begin{alertblock}{How to use this skeleton?}\n    \\begin{enumerate}\n      \\item What does $R/Q$ maintain?\n      \\item How to update estimators?\n\t\\begin{itemize}\n\t  \\item invalidated; following the new one\n\t  \\item amending the old one\n\t\\end{itemize}\n    \\end{enumerate}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm as skeleton}\n  \\begin{exampleblock}{Uniqueness of shortest path \\pno{3.7.7}}\n    \\begin{itemize}\n      \\item $G = (V, E, w), s \\in V, w(e) > 0$\n      \\item \\textcolor{gray}{Is shortest path $s \\leadsto t$ unique?}\n      \\item $\\forall t$: compute the number of shortest paths from $s$ to $t$.\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm as skeleton}\n  \\begin{block}{Solution.}\n    \\begin{verbatim}\n      Initialization: \n        num[s] = 1; num[v] = 0 for others\n        usp[s] = true; usp[v] = false for others\n\n      // update num[w] and usp[w]:\n      if dist[w] > dist[v] + w(v,w)\n        dist[w] = dist[v] + w(v,w)\n        num[w] = num[v]\n        usp[w] = usp[v]\n      else if dist[w] = dist[v] + w(v,w)\n        num[w] = num[w] + num[v]\n        usp[w] = false\n    \\end{verbatim}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm as skeleton}\n  \\begin{exampleblock}{Shortest path with fewest edges \\pno{3.7.19}}\n    \\begin{itemize}\n      \\item $G = (V, E, w), w(e) > 0, s \\in V$\n      \\item $\\text{best}[u]$: minimum number of edges in a shortest path from $s$ to $u$\n      \\item (an example here)\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{verbatim}\n      Initialization:\n        best[s] = 0; best[v] = infty for others\n      // update best[w]\n      if dist[w] > dist[v] + w(v,w)\n        dist[w] = dist[v] + w(v,w)\n        best[w] = best[v] + 1\n      else if dist[w] = dist[v] + w(v,w)\n        if best[w] > best[v] + 1\n          best[w] = best[v] + 1\n    \\end{verbatim}\n    an example for ``amending''\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}[fragile]{Dijkstra's algorithm as skeleton}\n  \\begin{exampleblock}{Bottleneck shortest path \\pno{3.7.20}}\n    \\begin{itemize}\n      \\item min-max path: bottleneck length and bottleneck distance\n      \\item single source, all-pairs\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{verbatim}\n    Q = MakePQ(V) with b-dist[v] as keys (using min-heap)\n    v = deleteMin(Q)\n\n    if b-dist[w] > max(b-dist[v], w(v,w))\n       b-dist[w] = max(b-dist[v], w(v,w))\n    \\end{verbatim}\n  \\end{block}\n\n  \\begin{alertblock}{For max-min path \\pno{3.7.21 (3.7.23, 3.7.24)}}\n\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n", "meta": {"hexsha": "72d6b109349575717ce9c7fd8533848bc909d725", "size": 3705, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-shortest-path-2016-06-13/sections/dijkstra-skeleton.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-2016/algorithm-tutorial-shortest-path-2016-06-13/sections/dijkstra-skeleton.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-2016/algorithm-tutorial-shortest-path-2016-06-13/sections/dijkstra-skeleton.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": 29.8790322581, "max_line_length": 93, "alphanum_fraction": 0.5721997301, "num_tokens": 1216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6450632522166482}}
{"text": "\\documentclass{article}  %Need this.\n\n\\usepackage{amsmath,amsthm,amssymb}\n\n\n\\newtheorem*{thm}{Theorem}\n\\newtheorem*{cnj}{Conjecture}\n\\newtheorem*{lem}{Lemma}\n\\newtheorem*{cor}{Corollary}\n\\newtheorem*{prop}{Proposition}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\n\n\n\n\\title{Practice}\n\\author{--Name --}\n\\date{}\n\n\\begin{document}\n\\maketitle  %This will add the title, author, and date located above\n\n\\begin{thm}\nIf $x$ and $y$ are odd integers then $x+y$ is an even integer.\n\\end{thm}\n\n\\begin{proof}\nWe assume that $x$ and $y$ are odd integers and will prove that $x+y$ is an even integer. Since $x$ and $y$ are odd, there exist integers $m$ and $n$ such that $x=2m+1$ and $y=2n+1$.  By substitution and algebra we obtain\n\\begin{align*}\nx+y &= 2m+1 + 2n + 1\\\\\n&= 2m+2n+2\\\\\n&=2(m+n+1).\n\\end{align*}\nDefine $q=m+n+1$.  Since $m$ and $n$ are integers and the integers are closed under addition, we conclude that $q$ is an integer. Since $x+y=2q$ for the integer $q$ we conclude that $x+y$ is an even integer.\n\\end{proof}\n\n\n\\vspace{.15in}\n\n\\section*{Challenge Typing}\n\n\nSuppose that $f:(-1,1)\\to \\R$ and $f$ is differentiable at $0$. Let sequences $(\\alpha_n)_{n\\geq1}$ and $(\\beta_n)_{n\\geq1}$ satisify $-1<\\alpha_n<\\beta_n<1$ for all $n\\geq 1$ and $\\displaystyle{\\lim_{n\\to\\infty}} \\alpha_n = \\displaystyle{\\lim_{n\\to\\infty}} \\beta_n = 0$. Set \n\t\n\t\t$$\\lambda_n = \\frac{f(\\beta_n) -f(\\alpha_n)}{\\beta_n-\\alpha_n} . $$\n\n\\newpage\n\n\\begin{thm}\nThe set $\\{ x\\in\\Z : |x-2.5| = 2 \\}$ is the empty set.\n\\end{thm}\n\n\\begin{proof}\nLet $y$ be an integer such that $y \\in \\{ x\\in\\Z : |x-2.5| = 2 \\}$  Then $y\\in \\mathbb{Z}$ and $|y-2.5| = 2$.  Since $|y-2.5| = 2$ then $y = 4.5$ or $y=-.5$.  But then $y$ is not an integer.  Therefore the set $\\{ x\\in\\Z : |x-2.5| = 2 \\}$ has no elements and\n\\[\\{ x\\in\\Z : |x-2.5| = 2 \\} = \\emptyset.\\]\n\\end{proof}\n\n\\begin{thm}\nThere exist two positive irrational numbers $s$ and $t$ such that $s^t$ is rational.\n\\end{thm}\n\\begin{proof}\nWe will consider two cases.  For the first case, suppose that $\\sqrt{2}^{\\sqrt{2}}$ is rational.  Then we may take $s= t = \\sqrt{2}$.  For the second case, suppose that $\\sqrt{2}^{\\sqrt{2}}$ is irrational.  Let $s= \\sqrt{2}^{\\sqrt{2}}$ and $t=\\sqrt{2}$.  Then \n$$\\left(\\sqrt{2}^{\\sqrt{2}}\\right)^{\\sqrt{2}} = \\left(\\sqrt{2}\\right)^2 = 2.$$\nSince $2$ is rational, $s^t$ is rational.  Therefore, there exists irrational numbers $s$ and $t$ such that $s^t$ is rational.\n\\end{proof}\n\n\\begin{thm}\nLet $n$ be a natural number.  Then $$\\sum_{k=1}^n k = \\frac{n(n+1)}{2}.$$\n\\end{thm}\n\nConsider the following matrix,\n$$\\left( \\begin{array}{ccc}\n1 &2 &3\\\\\n4 &5 &6\\\\\n7 &8 &9\n\\end{array}\\right)$$\n\n\n\n\\end{document}", "meta": {"hexsha": "4a23ec232e47600cb2976d9ff706fee80a45ac6e", "size": 2698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "from LDK/LaTeX/Class/ReproduceInClass.tex", "max_stars_repo_name": "mkjanssen/discrete", "max_stars_repo_head_hexsha": "4038b6d102000f4eeb27adaa8d0fd2bde63c28ac", "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": "from LDK/LaTeX/Class/ReproduceInClass.tex", "max_issues_repo_name": "mkjanssen/discrete", "max_issues_repo_head_hexsha": "4038b6d102000f4eeb27adaa8d0fd2bde63c28ac", "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": "from LDK/LaTeX/Class/ReproduceInClass.tex", "max_forks_repo_name": "mkjanssen/discrete", "max_forks_repo_head_hexsha": "4038b6d102000f4eeb27adaa8d0fd2bde63c28ac", "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.119047619, "max_line_length": 276, "alphanum_fraction": 0.6352853966, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6450632445535015}}
{"text": "\\subsection*{List Support}\n\nThe following list processing functions are supported:\n\n\\begin{itemize}\n\\item \\lstinline{pair(x, y)}: \\textit{primitive}, makes a pair from \\lstinline{x} and \\lstinline{y}.\n\\item \\lstinline{is_pair(x)}: \\textit{primitive}, returns \\lstinline{true} if \\lstinline{x} is a\n  pair and \\lstinline{false} otherwise.\n\\item \\lstinline{head(x)}: \\textit{primitive}, returns the head (first component) of the pair \\lstinline{x}.\n\\item \\lstinline{tail(x)}: \\textit{primitive}, returns the tail (second component) of the\n  pair \\lstinline{x}.\n\\item \\lstinline{is_null(xs)}: \\textit{primitive}, returns \\lstinline{true} if \\lstinline{xs} is the\n  empty list \\lstinline{null}, and \\lstinline{false} otherwise.\n\\item \\lstinline{is_list(x)}: Returns \\lstinline{true} if\n  \\lstinline{x} is a list as defined in the lectures, and\n  \\lstinline{false} otherwise. Iterative process; \ntime: $O(n)$, space: $O(1)$, where $n$ is the length of the \nchain of \\lstinline{tail} operations that can be applied to \\lstinline{x}.\n\\item \\lstinline{list(x1, x2,..., xn)}: \\textit{primitive}, returns a list with $n$ elements. The\nfirst element is \\lstinline{x1}, the second \\lstinline{x2}, etc. Iterative\nprocess; time: $O(n)$, space: $O(n)$, since the constructed list data structure\nconsists of $n$ pairs, each of which takes up a constant amount of space.\n\\item \\lstinline{draw_data(x)}: \\textit{primitive}, visualizes \\lstinline{x} in a separate drawing\n  area in the Source Academy using a box-and-pointer diagram; time, space:\n  $O(n)$, where $n$ is the number of data structures such as\n  pairs in \\lstinline{x}.\n\\item \\lstinline{equal(x1, x2)}: Returns \\lstinline{true} if both\n  have the same structure with respect to \\lstinline{pair},\n  and the same numbers, boolean values, functions or empty list\n  at corresponding leave positions (places that are not themselves pairs),\n  and \\lstinline{false} otherwise; time, space:\n  $O(n)$, where $n$ is the number of pairs in \\lstinline{x}.\n\\item \\lstinline{length(xs)}: Returns the length of the list\n  \\lstinline{xs}. \nIterative process; time: $O(n)$, space: $O(1)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{map(f, xs)}: Returns a list that results from list\n  \\lstinline{xs} by element-wise application of \\lstinline{f}. \nRecursive process; time: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{build_list(n, f)}: Makes a list with \\lstinline{n}\nelements by applying the unary function \\lstinline{f} to the numbers 0 to \\lstinline{n - 1}.\nRecursive process; time: $O(n)$, space: $O(n)$.\n\\item \\lstinline{for_each(f, xs)}: Applies \\lstinline{f} to every\n  element of the list \\lstinline{xs}, and then returns\n  \\lstinline{true}. \nIterative process; time: $O(n)$, space: $O(1)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{list_to_string(xs)}: Returns a string that represents\nlist \\lstinline{xs} using the text-based box-and-pointer notation \\lstinline{[...]}.\n\\item \\lstinline{reverse(xs)}: Returns list \\lstinline{xs} in reverse\n  order. Iterative process; time: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\nThe process is iterative, but consumes space $O(n)$ because of the result list.\n\\item \\lstinline{append(xs, ys)}: Returns a list that results from \nappending the list \\lstinline{ys} to the list \\lstinline{xs}.\nRecursive process; time: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{member(x, xs)}: Returns first postfix sublist\nwhose head is identical to\n\\lstinline{x} (\\lstinline{===}); returns \\lstinline{[]} if the\nelement does not occur in the list.\nIterative process; time: $O(n)$, space: $O(1)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{remove(x, xs)}: Returns a list that results from\n\\lstinline{xs} by removing the first item from \\lstinline{xs} that\nis identical (\\lstinline{===}) to \\lstinline{x}. Recursive process;\ntime: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{remove_all(x, xs)}: Returns a list that results from\n\\lstinline{xs} by removing all items from \\lstinline{xs} that\nare identical (\\lstinline{===}) to \\lstinline{x}.\nRecursive process;\ntime: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{filter(pred, xs)}: Returns a list that contains\nonly those elements for which the one-argument function\n\\lstinline{pred}\nreturns \\lstinline{true}.\nRecursive process;\ntime: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{enum_list(start, end)}: Returns a list that enumerates\nnumbers starting from \\lstinline{start} using a step size of 1, until\nthe number exceeds (\\lstinline{>}) \\lstinline{end}.\nRecursive process;\ntime: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{list_ref(xs, n)}: Returns the element\nof list \\lstinline{xs} at position \\lstinline{n}, \nwhere the first element has index 0.\nIterative process;\ntime: $O(n)$, space: $O(1)$, where $n$ is the length of \\lstinline{xs}.\n\\item \\lstinline{accumulate(op, initial, xs)}: Applies binary\nfunction \\lstinline{op} to the elements of \\lstinline{xs} from\nright-to-left order, first applying \\lstinline{op} to the last element\nand the value \\lstinline{initial}, resulting in $r_1$, then to the \nsecond-last element and $r_1$, resulting in $r_2$, etc, and finally\nto the first element and $r_{n-1}$, where $n$ is the length of the\nlist. Thus, \\lstinline{accumulate(op,zero,list(1,2,3))} results in\n\\lstinline{op(1, op(2, op(3, zero)))}.\nRecursive process;\ntime: $O(n)$, space: $O(n)$, where $n$ is the length of \\lstinline{xs},\nassuming \\lstinline{op} takes constant time.\n\\end{itemize}\n", "meta": {"hexsha": "e3ae9329fbd8d7c04d9f7ca9976af3d488b37425", "size": 5707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/specs/source_lists.tex", "max_stars_repo_name": "jiayushe/js-slang", "max_stars_repo_head_hexsha": "bc99aa77f4cd141e77d845ee1d57492e088037f0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-28T06:20:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-28T06:20:00.000Z", "max_issues_repo_path": "docs/specs/source_lists.tex", "max_issues_repo_name": "jiayushe/js-slang", "max_issues_repo_head_hexsha": "bc99aa77f4cd141e77d845ee1d57492e088037f0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2020-03-25T05:46:50.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-02T10:31:34.000Z", "max_forks_repo_path": "docs/specs/source_lists.tex", "max_forks_repo_name": "jiayushe/js-slang", "max_forks_repo_head_hexsha": "bc99aa77f4cd141e77d845ee1d57492e088037f0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-03-31T06:16:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-01T01:04:51.000Z", "avg_line_length": 59.4479166667, "max_line_length": 108, "alphanum_fraction": 0.7196425442, "num_tokens": 1731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6450632426852009}}
{"text": "\\subsection{Optimizing Expected 1-call@k}\nBefore we present the result on optimizing expected $n$-call@$k$ for\ngeneral $n$, we start off from the simplest case, expected 1-call@$k$\n(where $n=1$):\n% Definition of 1-call\n\\begin{align}\n    \\ExpOneCall(S_k,\\vec{q}) & = \\mathbb{E}[R_k\\geq 1|s_1,\\dots,s_k,\\vec{q}]\n\\end{align}\nSince $R_k\\geq 1$ is satisfied as long as any one of the $r_i$ is $1$,\nthe objective can be rewritten in terms of logical notation:\n\\begin{align}\n\\label{eq:setRelevance}\n    \\ExpOneCall(S_k,\\vec{q}) & = \\mathbb{E} \\left[\\left. \\bigvee_{i=1}^{k}r_i=1 \\right| s_{1},\\dots, s_{k},\\vec{q} \\right]\n\\end{align}\n\nSince jointly optimizing $\\ExpOneCall(S_k,\\vec{q})$ is NP-hard, we\ntake a greedy approach similar to MMR where we choose the best $s_k^*$\nassuming that $S_{k-1}^*$ is given.  Then following~\\cite{chen06Less},\nwe can greedily optimize this objective as \nfollows:\n\\begin{align}\ns_k^* & = \\argmax_{s_k} \\; \\ExpOneCall(S_{k-1}^* \\cup \\{ s_k \\},\\vec{q}) \\nonumber \\\\\n   & = \\argmax_{s_k} \\mathbb{E}\\left[\\left. \\bigvee_{i=1}^{k} r_i=1 \\right| S_{k-1}^*, s_{k},\\vec{q}\\right] \\nonumber\n\\end{align}\nNext we can apply a logical equivalence and exploit the additivity of\nmutually exclusive events to split $\\bigvee_{i=1}^{k} r_i=1$ into mutually exclusive\ndisjoint subsets:\n\\begin{align}\ns_k^* & = \\argmax_{s_k} \\mathbb{E}\\Bigg[  (r_1=1) \\vee (r_2 =1 \\wedge r_1=0) \\vee (r_3 =1 \\wedge r_2=0 \\wedge r_1=0) \\vee \\cdots \\vee \\nonumber \\\\\n   & \\hspace{19mm} \\left(r_k=1 \\wedge \\bigwedge_{i=1}^{k-1} r_i=0 \\right) \\, \\Bigg| \\, S_{k-1}^*,s_k,\\vec{q} \\Bigg] \\label{eq:logicalsplit}\n\\end{align}\nSince these events are binary and disjoint, we can rewrite the expectation as probability.\nThis gives us the sum of the probabilities of each individual event.\nWe further simplify it by grouping all $r_j = 0$.\\footnote{The notation \n$\\{ \\cdot \\}_C$ refers to a (possibly empty) set of \nvariables (or variable assignments) $\\cdot$ that meet constraints $C$.}\nWe factorize each joint probability into a conditional and prior, and remove terms and factors that do not contain $s_k$, noting that these terms only act as constants when optimizing for $s_k$:\n\\begin{align}   \ns_k^* & = \\argmax_{s_k} \\sum_{i=1}^{k} P(  r_i=1, \\{ r_{j}=0 \\}_{j<i} \\, | \\, \\{ s^*_j \\}_{j\\leq i,j<k},\\{ s_{k} \\}_{k=i},\\vec{q}) \\nonumber \\\\\n   &= \\argmax_{s_k} \\sum_{i=1}^{k} P(  r_i=1 \\, | \\, \\{ r_{j}=0 \\}_{j<i} , \\{ s^*_j \\}_{j\\leq i,j<k},\\{ s_k \\}_{k=i},\\vec{q}) \\nonumber\\\\\n   & \\hspace{21.5mm} P(\\{ r_{j}=0 \\}_{j<i} \\, | \\, \\{ s^*_j \\}_{j\\leq i,j<k}, \\vec{q}) \\nonumber \\\\\n   &= \\argmax_{s_k} P( r_k=1 \\, | \\, \\{ r_{j}=0 \\}_{j<k}, S_{k-1}^*,s_k,\\vec{q}) \\label{eq:set-objective}\n\\end{align}\nFrom~\\eqref{eq:set-objective}, to optimize for $s_k$, we need only to maximize $s_k$'s probability of relevance conditioned on the previous selections (which are assumed irrelevant, $r_j=0$) and the query.\n\nNext we evaluate the final query from~\\eqref{eq:set-objective} w.r.t.\\\nour actual graphical model of subtopic relevance from Figure~\\ref{fig:gm}:\n\\begin{align}\ns_k^* & = \\argmax_{s_{k}} P( r_k=1 \\, | \\, \\{ r_{j}=0 \\}_{j<k}, S_{k-1}^*,s_k,\\vec{q}) \\nonumber \\\\\n& = \\argmax_{s_{k}} \\sum_{t, t_1, \\cdots, t_{k}} P(t|\\vec{q}) P(t_k|s_k) \\I[t_k = t] \\prod_{i=1}^{k-1} P(t_i|s_i^*) \\I[t_i\\neq t]\\nonumber \\\\\n& = \\argmax_{s_{k}} \\sum_{t} P(t|\\vec{q}) \\sum_{t_{k}} P(t_k|s_k) \\I[t_k = t] \\prod_{i=1}^{k-1} \\sum_{t_{i}} P(t_i|s_i^*) \\I[t_i \\neq t]\\nonumber \\\\\n& = \\argmax_{s_{k}} \\sum_{t} P(t|\\vec{q}) P(t_k=t|s_k) \\fbox{$\\prod\\limits_{i=1}^{k-1} (1 - P(t_i=t|s_i^*))$} \\label{eq:partial_simp}\n\\end{align}\nHere we have used the following equality:\n\\begin{align*}\n& \\sum_{t_{i}} P(t_i|s_i) \\I[t_i = t] =  P(t_i=t|s_i) \\\\\n& \\sum_{t_{i}} P(t_i|s_i) \\I[t_i \\neq t] = 1 - P(t_i=t|s_i)\n\\end{align*}\n\nDefining $\\tilde{P}(t | S_{k-1}^*) = 1 - \\Box = 1 - \\prod_{i=1}^{k-1} (1 -\n  P(t_i=t|s_i^*))$, this is the probability that \nset $S_{k-1}^*$ already \\emph{covers} topic $t$ \nw.r.t.\\ a \\emph{noisy-or} interpretation.  Substituting\n$(1 - \\tilde{P}(t | S_{k-1}^*))$ for $\\Box$ since \n$(1 - \\tilde{P}(t | S_{k-1}^*)) = 1 - (1 - \\Box) = \\Box$, we obtain\n\\begin{align}\ns_k^* & = \\argmax_{s_{k}} \\sum_{t} P(t|\\vec{q}) P(t_k=t|s_k) \\left( 1 - \\tilde{P}(t | S_{k-1}^*) \\right) \\nonumber \\\\\n      & = \\argmax_{s_{k}} \\sum_{t} \\underbrace{P(t|\\vec{q}) P(t_k=t|s_k)}_{\\mbox{\\footnotesize query similarity}} - \\sum_{t} \\underbrace{P(t|\\vec{q}) P(t_k=t|s_k) \\tilde{P}(t | S_{k-1}^*)}_{\\mbox{\\footnotesize query-reweighted diversity}}. \\label{eq:1call}\n\\end{align}\n\nFrom~\\eqref{eq:1call}, we can see that optimizing expected 1-call@$k$\ngive us a greedy algorithm that somewhat resembles MMR\nin~\\eqref{eq:MMR} with an implicit equal balancing of the similarity\nand diversity objectives (i.e., $\\lambda = \\frac{1}{2}$).  After presenting our\ngeneral derivation for expected $n$-call@$k$ in the next subsection\nfor $n \\geq 1$, we return to a general comparison between expected\n$n$-call@$k$ and MMR.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Optimizing Expected n-call@k}\n\n\\label{subsec:ncall}\n\nHaving analyzed the special case of $n$-call@$k$ for $n=1$, we now\nattempt to generalize our approach to general $n \\geq 1$.  In contrast\nto $n=1$, however, we note that it is not straightforward to use the\nlogical notation of the expected $n$-call@$k$ objective for $n=1$\ngiven in~\\eqref{eq:setRelevance} when $n > 1$: even for $n=2$, the\nnumber of disjoint events that satisfy $R_k \\geq 2$ grows by a factor\nof $(k-1)/2$.\\footnote{$\\binom{k}{2} / \\binom{k}{1} = (k-1)/2$}\n\nNext we provide our main result on optimizing expected $n$-call@$k$\nfor general $n \\geq 1$.  For the interested reader, we note that a\nsimpler (logic-based) derivation for the special case of $n=2$ is\nprovided in Appendix~\\ref{appendix.2call}, which provides some guiding\nintuitions for the general derivation deveoped in this section.\n \nIn the following derivation, we adopt a more abstract approach\n(working with $R_k$ directly) while utilizing the same principle as in\nexpected 1-call@$k$.\nAs done previously, we take a greedy approach that \nselects $s_k$ assuming that $S_{k-1}^*$ is already chosen:\n\\begin{align}\n  s_k^* & = \\argmax_{s_k} \\ExpNCall{n}(S_{k-1}^* \\cup \\{ s_k \\},\\vec{q}) \\nonumber\\\\\n  s_k^* & = \\argmax_{s_k} \\mathbb{E}[R_k\\geq n|S_{k-1}^*,s_k,\\vec{q}] \\nonumber\\\\\n  & = \\argmax_{s_k} P(R_k\\geq n|S_{k-1}^*,s_k,\\vec{q}) \\nonumber \n\\end{align}\n\nHere, we have exploited the binary ($0,1$) nature of $R_k \\geq n$ to rewrite the objective\ndirectly as a probabilistic query.\nThis query can be evaluated w.r.t.\\ our latent subtopic binary relevance\nmodel in Figure~\\ref{fig:gm} as follows, where we marginalize out\nall non-query, non-evidence variables $T_k$ $\\big(\\mbox{define } T_k\\!=\\!\\{t,t_1,\\dots,t_k\\}$ and \n$\\sum_{T_k} \\circ = \\sum_t \\sum_{t_1} \\cdots \\sum_{t_k} \\circ \\big)$:\n\\begin{align}\n  s_k^* = & \\argmax_{s_k} \\!\\sum_{T_k} \\Bigl( P(t|\\vec{q}) \\,P(t_k|s_k) \\prod_{i=1}^{k-1} P(t_i|s_i^*) \\cdot P(R_k\\geq n|T_k,S_{k-1}^*,s_k,\\vec{q}) \\Bigr) \\nonumber \n\\end{align}\n\nWe split $R_k \\geq n$ into two disjoint (additive) events\n$(r_k \\! \\geq \\! 0, R_{k\\!-\\!1}\\!\\geq \\!n)$, $(r_k\\!\\!=\\!\\!1, R_{k\\!-\\!1}\\!\\!=\\!\\!n\\!-\\!1)$ based on $R_{k-1}$. (If $R_{k-1}$ is equal to $n\\!-\\!1$, $r_k$ must be $1$; if $R_{k-1}$ is greater or equal to $n$, then $r_k$ can be either $0$ or $1$). \n\\begin{align}\n s_k^* = & \\argmax_{s_k} \\!\\sum_{T_k} P(t|\\vec{q}) \\,P(t_k|s_k) \\prod_{i=1}^{k-1} P(t_i|s_i^*) \\cdot \\Bigl( P(r_k\\geq 0, R_{k-1}\\geq n|T_k,S_{k-1}^*,s_k,\\vec{q}) \\nonumber \\\\\n  & \\hspace{56mm} + P(r_k = 1, R_{k-1} = n-1|T_k,S_{k-1}^*,s_k,\\vec{q}) \\Big) \\nonumber \n\\end{align}\nWe then write the joint probability into a conditioned and prior, conditioned on $R_k$:\n% Also note that all $r_i$ are D-separated:\n\\begin{align}\n s_k^* = & \\argmax_{s_k} \\!\\sum_{T_k} P(t|\\vec{q}) \\,P(t_k|s_k) \\prod_{i=1}^{k-1} P(t_i|s_i^*) \\cdot \\Bigl( \\mbox{$\\underbrace{P(r_k\\!\\geq\\!0|R_{k-\\!1}\\!\\geq\\!n,t_k,t)}_{1}$} P(\\!R_{k-\\!1}\\!\\geq\\!n|\\TlessK) \\nonumber \\\\\n  & \\hspace{50mm} + P(r_k=1|R_{k-1}\\!=\\!n\\!-\\!1,t_k,t) P(\\!R_{k-\\!1}\\!=\\!n\\!-\\!1|\\TlessK) \\Big) \\nonumber \n\\end{align}\nWe distribute initial terms over the summands noting that \n$\\sum_{t_k} \\!\\! P(t_k|s_k) P(r_k\\!\\!=\\!\\!1|t_k,t) \\! = \\!\\! \\sum_{t_k} \\!\\! P(t_k|s_k) \\I[t_k\\!\\!=\\!\\!t] \\! = \\!\\! P(t_k\\!\\!=\\!\\!t|s_k)$,\nand $r_k$ is independent to $R_k$ given $T_k$:\n\\begin{align}\n s_k^* = & \\argmax_{s_k} \\Bigg( \\sum_{\\TlessK} \\bigg[ \\mbox{$\\underbrace{ \\sum_{t_k} \\!P(t_k|s_k) }_{1}$} \\bigg] P(\\!R_{\\!k-\\!1}\\!\\geq\\!n|\\TlessK) P(t|\\vec{q}) \\prod_{i=1}^{k-1} P(t_i|s_i^*) \\nonumber \\\\\n  & \\hspace{13mm} + \\sum_{t} \\!P(t|\\vec{q}) P(t_k\\!=\\!t|s_k) \\hspace{-4mm} \\sum_{t_1, \\dots, t_{k-1}} \\hspace{-3mm} P(R_{k-\\!1}\\!=\\!n\\!-\\!1|\\TlessK) \\prod_{i=1}^{k-1} \\!P(t_i|s_i^*) \\Bigg) \\nonumber\n\\end{align}\nNext we proceed to drop the first summand since it is not a function of $s_k$ (\\emph{i.e.},\nit has no influence in determining $s_k^*$):\n% This give us the\n%simplified optimization objective:\n\\begin{align}\ns_k^* = & \\argmax_{s_k} \\!\\sum_{t} \\!P(t|\\vec{q}) P(t_k\\!=\\!t|s_k) P(\\!R_{k-\\!1}\\!\\!=\\!n\\!-\\!1|S_{k-1}^*, t) \\label{eq.ncall}\n\\end{align}\n\nBy similar reasoning, we can derive that the last probability \nneeded in~\\eqref{eq.ncall} is recursively defined as \n\\begin{align*}\nP(R_k=n|S_k,t)=\n\\begin{cases}\nn \\geq 1, k > 1:  &  \\bigl( 1\\!-\\!P(t_k\\!=\\!t|s_k) \\bigr) P(R_{k-1}\\!=\\!n|S_{k-1},t) \\nonumber \\\\\n  & \\hspace{5mm} + P(t_k\\!=\\!t|s_k) P(R_{k-\\!1}\\!=\\!n\\!-\\!1|S_{k-\\!1},t) \\\\\n%%\nn = 0, k > 1:   & \\bigl( 1\\!-\\!P(t_k\\!=\\!t|s_k) \\bigr) P(R_{k-\\!1}\\!=\\!0|S_{k-\\!1},t) \\\\\n%%\nn = 1, k = 1:   & P(t_1\\!=\\!t|s_1) \\\\\nn = 0, k = 1:   & 1 - P(t_1\\!=\\!t|s_1) \\\\\nn > k:\t\t\t& 0\n\\end{cases}\n%       \\bigl 1-P(t_1\\!=\\!t|s_1) \\bigr) = \\bigl 1-P(t_1\\!=\\!t|s_1) \\bigr) \\\\\n%  & \\hspace{2mm} P(R_1\\!=\\!1|S_1,t) = P(t_1\\!=\\!t|s_1)\n\\end{align*}\n\nWe can now rewrite~\\eqref{eq.ncall} by unrolling its recursive definition.\nFor expected $n$-call@$k$ where $n \\leq k/2$ %, n \\! \\neq \\! 1$ \n(a symmetrical result holds for $k/2 < n \\leq k$),\nthe explicit unrolled objective is \n\\begin{align}\n  & s_k^* = \\argmax_{s_k} \\sum_t \\Biggl( P(t|\\vec{q}) \\, P(t_k=t|s_k) \\cdot \\hspace{-2mm} \\sum_{j_1, \\dots, j_{n-\\!1}} \\hspace{-14mm} \\prod_{\\hspace{14.5mm} l \\in \\{j_1, \\dots, j_{n-\\!1}\\}} \\hspace{-14mm} P(t_l\\!=\\!t|s_l^*) \\hspace{-13mm} \\prod_{\\substack{i=1 \\\\ \\hspace{14mm} i \\notin \\{j_1, \\dots, j_{n-\\!1}\\}}}^{k-1} \\hspace{-13mm} \\!\\bigl( 1 - P(t_i\\!=\\!t|s_i^*) \\bigr) \\!\\Biggr) \\label{eq.ncall.alt}\n\\end{align}\nwhere $j_1, \\dots, j_{n-1} \\in \\{1,\\ldots,k-1\\}$ satisfy \nthat $j_i < j_{i+1}$ (\\emph{i.e.},\nan ordered permutation of $n-1$ result set indices).\nNote that~\\eqref{eq.ncall.alt} reduces to~\\eqref{eq:partial_simp} when $n=1$.\n\n% ===============================================================================\n\n%From here we focus on the last product in~\\eqref{eq.ncall.alt}.  We note that\nIf we assume each document covers a single subtopic of the query (\\emph{e.g.},\na subtopic represents an intent of an ambiguous query) then we can assume that \n$\\forall i \\; P(t_i|s_i) \\in \\{0,1\\}$ and $P(t|\\vec{q}) \\in \\{0,1\\}$.  This\nallows us to convert a $\\prod$ to a $\\max$ \n\\begin{align*}\n  \\hspace{-13mm} \\prod_{\\substack{i=1 \\\\ \\hspace{14mm} i \\notin \\{j_1, \\dots, j_{n-\\!1}\\}}}^{k-1} \\hspace{-14mm} \\bigl( 1 - \\!P(t_i\\!=\\!t|s_i^*) \\bigr) & =\n1 - \\Biggl( 1 - \\hspace{-14mm} \\prod_{\\substack{i=1 \\\\ \\hspace{14mm} i \\notin \\{j_1, \\dots, j_{n-\\!1}\\}}}^{k-1} \\hspace{-13mm} \\bigl( 1 - P(t_i\\!=\\!t|s_i^*) \\bigr) \\Biggr) \n   = 1 - \\Bigl( \\hspace{-6mm} \\max_{\\substack{i \\in [1,k-1] \\\\ \\hspace{7mm} i \\notin \\{j_1, \\dots, j_{n-1}\\}}} \\hspace{-6mm} P(t_i\\!=\\!t|s_i^*) \\Bigr)\n\\end{align*}\nand by substituting this into~\\eqref{eq.ncall.alt} and distributing, we get\n\\begin{align}\ns_k^* =  & \\, \\argmax_{s_k} \\sum_t \\Biggl( P(t|\\vec{q}) P(t_k\\!=\\!t|s_k)  \\sum_{\\hspace{-1mm} j_1, \\dots, j_{n-\\!1}} \\hspace{-13.5mm} \\prod_{\\hspace{14.5mm} l \\in \\{j_1, \\dots, j_{n-1}\\}} \\hspace{-14mm} P(t_l\\!=\\!t|s_l^*) \\nonumber \\\\\n  & \\hspace{20mm} - \\!P(t|\\vec{q}) P(t_k\\!=\\!t|s_k) \\sum_{\\hspace{-1mm} j_1, \\dots, j_{n-\\!1}} \\hspace{-14mm} \\prod_{\\hspace{14.5mm} l \\in \\{j_1, \\dots, j_{n-\\!1}\\}} \\hspace{-13mm} P(t_l\\!=\\!t|s_l^*) \\hspace{-11.5mm} \\max_{\\substack{\\hspace{5mm} i \\in [1,k-1] \\\\ \\hspace{11.5mm} i \\notin \\{j_1, \\dots, j_{n-\\!1}\\}}} \\hspace{-8.5mm} P(t_i\\!=\\!t|s_i^*) \\!\\!\\Biggr) . \\label{eq.ncall.alt2} \n\\end{align}\n\nAssuming $m$ of the selected documents $(S_{k-1}^*)$ are relevant \nthen the top term\n(specifically $\\prod_l$) is non-zero $\\binom{m}{n-1}$ times.  For the\nbottom term, it takes $n-1$ relevant $S_{k-1}^*$ to satisfy its\n$\\prod_l$, and one additional relevant document to satisfy the\n$\\max_i$ making it non-zero $\\binom{m}{n}$ times.  Factoring out the\n$\\max$ element from the bottom and pushing the $\\sum_t$ inwards (all legal\ndue to the $\\{0,1\\}$ subtopic probability assumption) we get\n\\begin{align}\ns_k^* = & \\argmax_{s_k} \\binom{m}{n\\!-\\!1} \\underbrace{\\sum_t P(t|\\vec{q}) P(t_k\\!=\\!t|s_k)}_{\\textrm{relevance}: \\; \\Sim_1(s_k,\\vec{q})} - \\binom{m}{n} \\max_{s_i \\in S_{k-1}^*} \\underbrace{\\sum_t \\!P(t|\\vec{q}) P(t_k\\!=\\!t|s_k) P(t_i\\!=\\!t|s_i)}_{\\textrm{diversity}: \\; \\Sim_2(s_k,s_i,\\vec{q})} \\nonumber .\n\\end{align}  \n\nFrom here we can \nnormalize by $\\binom{m}{n-1} + \\binom{m}{n} = \\binom{m+1}{n}$ \n(Pascal's rule), leading to the simplified result:\n\\begin{align}\ns_k^* =  & \\argmax_{s_k} \\!\\! \\frac{n}{m\\!+\\!1} \\Sim_1(s_k,\\vec{q}) - \\frac{m\\!-\\!n\\!+\\!1}{m+1} \\max_{s_i \\in S_{k-1}^*} \\! \\Sim_2(s_k,s_i,\\vec{q}) \\label{eq:ncall-result-almost}\n\\end{align}\nFortuitously, we note that the $\\binom{m+1}{n}$ divisor cancelled with\nthe numerators, yielding this elegant and interpretable result.\nIn practice, we can make one additional\nsimplifying assumption: under the greedy approach of \nselecting $s_k$ given $S_{k-1}^*$ when $k \\geq n + 1$, we expect that there are already $n$\nrelevant documents chosen in the set $S_{k-1}^* = \\{s_1^*, \\dots,\ns_{k-1}^*\\}$, and hence in expectation $m=n$.  Assuming $m = n$ we obtain \n\\begin{align}\ns_k^* =  & \\argmax_{s_k} \\!\\! \\frac{n}{n\\!+\\!1} \\Sim_1(s_k,\\vec{q}) - \\frac{1}{n+1} \\max_{s_i \\in S_{k-1}^*} \\! \\Sim_2(s_k,s_i,\\vec{q}) \\label{eq:ncall-result}\n\\end{align}\nleading to $\\lambda = \\frac{n}{n\\!+\\!1}$ when comparing to MMR\nin~\\eqref{eq:MMR}, which achieves our goal of formally expressing the\nrelevance vs. diversity tradeoff as a function of $n$.\n\nAs a reality check, we see that the result $\\lambda = \\frac{n}{n+1}$\ncoincides with the result of $\\lambda=\\frac{1}{2}$ for $n=1$ as\nderived in the previous section for expected $1$-call@$k$.  Hence, we\nhave achieved one of our key theoretical results and have shown that\nwhen optimizing expected $n$-call@$k$ w.r.t.\\ a latent subtopic binary\nrelevance model diversification decreases as $n \\to 1$, thus\nconfirming the empirical observations regarding $n$-call@$k$ in\n\\cite{wang09PortfolioTheory} (Figure 2c).\n\n%$n=1$, $m=1$.  Overall we have achieved our goal and have shown that\n%indeed, diversificiation in expected $n$-call@$k$ decreases linearly \n%as $n \\to 1$.\n\n% ===============================================================================\n% This subsection is copied from Section 4.1\n\\subsection{Connections to Maximal Marginal Relevance}\n\n\\label{subsec:mmr_comp}\n\nThe result in~\\eqref{eq:ncall-result} is strikingly similar to maximal marginal\nrelevance (MMR)~\\cite{carbonell98MMR} --- it\ncontains two terms, one for query similarity and the other for result\nset diversification, where each term represents a similarity kernel\n--- more specifically a \\emph{probability product kernel}\n(PPK)~\\cite{prodprobkernel} that is an inner product of probability\nvectors (or more generally, functions).  More formally, let\n$\\vec{T}'$, $\\vec{T}_k$, and $\\vec{T}_{S_{k-1}^*}$ be respective topic\nprobability vectors $P(t'=t|\\vec{q})$, $P(t_k=t|s_k)$ and\n%$\\tilde{P}(t_k=t | S_{k-1}^*)$ \n$P(t_i\\!=\\!t|s_i)$\nwith vector indices for each topic $t\n\\in T$.  Then the similarity and diversity terms from~\\eqref{eq:ncall-result}\ncan be respectively written as\n\\begin{align}\n\\Sim_1(\\vec{q},s_k) = & \n\\sum_{t \\in T} P(t'=t|\\vec{q}) P(t_k=t|s_{k}) \\; = \\; \\langle \\vec{T}',\\vec{T}_k \\rangle \\label{eq:sim_term} \\; \\mbox{and}\\\\\n\\Sim_2(s_k,S_{k-1}) = & \n\\sum_{t \\in T} P(t|\\vec{q}) P(t_k=t|s_k) \\tilde{P}(t | S_{k-1}^*) \\; = \\; \\langle \\vec{T}_k, \\vec{T}_{S_{k-1}^*} \\rangle_{\\vec{T}'}. \\label{eq:div_term}\n\\end{align}\nHere, we let $\\langle \\cdot,\\cdot \\rangle$ denote an inner product of\ntwo vectors and $\\langle \\cdot,\\cdot \\rangle_\\vec{v}$ a\n\\emph{$\\vec{v}$-reweighted} inner product, defined as\nin~\\eqref{eq:div_term}.\n\nWhile having similarity and diversity terms similar to MMR,\nExp-$n$-call@$k$ in~\\eqref{eq:ncall-result} differs from MMR\nin two notable ways:\n\\begin{enumerate}\n\\item While MMR's definition allows for any similarity function, not\n  just PPKs, we note that \\emph{equating words to subtopics}, popular\n  kernels like TF and TFIDF~\\cite{salton83Introduction} can be viewed\n  directly as PPKs if the TF and TFIDF vectors are $L_1$ normalized to\n  represent probability vectors.  Hence we can avoid directly answering the question of how\n  subtopics and subtopic probabilities are specified by using the\n  ``kernel trick'' and kernels with a PPK interpretation like TF or\n  TFIDF to \\emph{directly} compute the required optimization quantities\n  in~\\eqref{eq:sim_term} and~\\eqref{eq:div_term}.\n%% FOLLOWING NO LONGER RELEVANT for n-call@k (not 1-call@k)\n%%\n%\\item MMR uses a maximization term for\n%diversity, whereas optimization of Exp-$n$-call@$k$ instead calls for\n%a product (noisy-or) diversity term. %$\\tilde{P}(t | S_{k-1}^*)$.\n%We note that a noisy-or reduced to a max when the subtopic\n%probabilities are deterministic (0 or 1).\n%\\item While MMR proposes a $\\lambda$ term to explicitly\n%trade off the similarity and diversity terms, the greedy optimization\n%of Exp-$n$-call@$k$ in~\\eqref{eq:ncall-result} yields such trade-off term\n%as a function of $m, n$ and $k$.\n\\item Optimizing Exp-$n$-call@$k$ introduces query-specific relevance\n  into the diversification term as shown by the query topic\n  ($\\vec{T}'$) reweighted diversity function in~\\eqref{eq:div_term}.\n  Indeed this modification to MMR is quite intuitive and may prove\n  advantageous since result set diversification need only be\n  considered over the subtopics that are actually relevant to the\n  query.\n\\end{enumerate}\n\nDespite these minor differences, however, we note the strong similarity\nbetween the optimization of expected $n$-call@$k$ and MMR where we formally\nderived that $\\lambda = \\frac{n}{n+1}$.  \n\n", "meta": {"hexsha": "85eff658fcadc6593094969139f051208e472178", "size": 18577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ACM_TIST_diversity/theory.tex", "max_stars_repo_name": "antoine-tran/diversify", "max_stars_repo_head_hexsha": "0c9815d515feda7edb504f1ad91dec0a255f9e0c", "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/ACM_TIST_diversity/theory.tex", "max_issues_repo_name": "antoine-tran/diversify", "max_issues_repo_head_hexsha": "0c9815d515feda7edb504f1ad91dec0a255f9e0c", "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/ACM_TIST_diversity/theory.tex", "max_forks_repo_name": "antoine-tran/diversify", "max_forks_repo_head_hexsha": "0c9815d515feda7edb504f1ad91dec0a255f9e0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-04T16:27:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T16:27:43.000Z", "avg_line_length": 60.5114006515, "max_line_length": 404, "alphanum_fraction": 0.6388544975, "num_tokens": 7421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6450524037581697}}
{"text": "%        File: doc.tex\n%     Created: Lun mar 29 09:00  2021 C\n% Last Change: Lun mar 29 09:00  2021 C\n%\n\\documentclass[a4paper]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage[]{amsmath}\n\n\\newcommand{\\rom}[1]{\\mathrm{#1}} \n\\newcommand{\\bold}[1]{\\mathbf{#1}} \n\\newcommand{\\dd}{\\mathrm{d}} \n\n\\begin{document}\n\n\\section{Slater-type orbitals}\n\nA real Slater-type orbital (STO) is defined as follows: \n\n\\begin{equation}\n  \\chi_{nlm}(\\zeta, \\bold{r}) = N_n(\\zeta) R_n(r, \\zeta) S_{lm}(\\theta, \\phi)\n  \\label{eq:real_sto}\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n  N_n(\\zeta) = \\frac{(2\\zeta)^{n+\\frac{1}{2}}}{\\sqrt{(2n)!}} \n  \\label{eq:norm_sto}\n\\end{equation}\n\nis the normalization factor,\n\n\\begin{equation}\n  R_n(r,\\zeta) = r^{n-1} e^{-\\zeta r} \n  \\label{eq:sto_radial_part}\n\\end{equation}\n\nis the radial part and $S_{lm}(\\theta, \\phi)$ is a real spherial harmonic.\n\n\\section{Prolate spheroidal coordinates}\n\nFor two-center integrals, it is more convenient to align the coordinate\nsystem of the two centers along the $z$-axis and use prolate spheroidal\ncoordinates. In order to switch from spherical coordinates to the new\ncoordinate system, we use the following identities:  \n\n\\begin{equation}\n  \\begin{aligned}\n    r_a = \\frac{R(\\mu+\\nu)}{2}; \\quad \n    \\cos\\theta_a = \\frac{1+\\mu\\nu}{\\mu+\\nu}; \\quad &\n    \\sin\\theta_a = \\frac{\\sqrt{(\\mu^2-1)(1-\\nu^2)}}{\\mu+\\nu}; \\\\\n    r_b = \\frac{R(\\mu-\\nu)}{2}; \\quad \n    \\cos\\theta_b = \\frac{1-\\mu\\nu}{\\mu-\\nu}; \\quad &\n    \\sin\\theta_b = \\frac{\\sqrt{(\\mu^2-1)(1-\\nu^2)}}{\\mu-\\nu}\n  \\end{aligned}\n  \\label{eq:prolate_spheroidal_coordinates}\n\\end{equation}\n\nInside the integrals this change gives \n\n\\begin{equation}\n  \\dd V = \\frac{R^3}{8} (\\mu+\\nu) (\\mu-\\nu) \\dd\\mu \\dd\\nu \\dd\\phi\n\\label{eq:prolate_spheroidal_coordinates_integration}\n\\end{equation}\n\n\\section{Overlap integrals}\n\nThe one-center overlap integrals\n\n\\begin{equation}\n  S_{nlm,n'l'm'}(\\zeta, \\zeta') = \n  \\int \\chi_{nlm}^{\\star}(\\zeta, \\bold{r}) \n  \\chi_{n'm'l'}(\\zeta', \\bold{r}) \\dd V \n  \\label{eq:1c_overlap_integral} \n\\end{equation}\n\nis the most straightforward molecular integrals and is readily evaluated in\nspherical coordinates. The integration of the radial part yields\n\n\\begin{equation}\n  \\int_0^{\\infty} R_n(\\zeta,r) R_{n'}(\\zeta',r) r^2 \\dd r = \n  \\frac{(n+n')!}{(\\zeta+\\zeta')^{n+n'+1}}\n  \\label{eq:1c_overlap_integral_radial_part_eval}\n\\end{equation}\n\nand using the orthonormality condition of the spherical harmonics, the analytical\nform of one-center overlap is\n\n\\begin{equation}\n  S_{nlm,n'l'm'}(\\zeta, \\zeta') = \n  N_n(\\zeta) N_{n'}(\\zeta') \n  \\frac{(n+n')!}{(\\zeta+\\zeta')^{n+n'+1}}\n  \\delta_{ll'}\\delta_{mm'}\n\\label{eq:1c_overlap_integral_result}\n\\end{equation}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "cf2b1efe59bee94c4beecb6330e6aec1fa17d82b", "size": 2731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doc.tex", "max_stars_repo_name": "LMazouin/pysto", "max_stars_repo_head_hexsha": "882011737f56de2780cda6ea71068d628400930b", "max_stars_repo_licenses": ["MIT"], "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": "LMazouin/pysto", "max_issues_repo_head_hexsha": "882011737f56de2780cda6ea71068d628400930b", "max_issues_repo_licenses": ["MIT"], "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": "LMazouin/pysto", "max_forks_repo_head_hexsha": "882011737f56de2780cda6ea71068d628400930b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-16T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-16T20:01:16.000Z", "avg_line_length": 26.7745098039, "max_line_length": 81, "alphanum_fraction": 0.6686195533, "num_tokens": 999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.6450072317818624}}
{"text": "\n\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/hwpreamble.tex\"}\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/extrapackages.tex\"}\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/extracommands.tex\"}\n\n\n\\begin{document}\n\n\n\\title{\\Large Spectral Sequences}\n\\author{\\large Brandon Williams}\n\n\\maketitle\n\n\n\\tableofcontents\n\n\n\\section{Graded Objects in Algebra}\n\nWe will first take the time to carefully develop the notion of graded objects, which are required for the study of spectral sequences.\n\nLet us fix a ring $R$ throughout this section, and all $R$-modules will be considered as left $R$-modules. A graded $R$-module $A$ is a collection of $R$-modules $\\lcb A_i \\rcb$ indexed by the integers $i \\in \\mathbb Z$. Right now each module $A_i$ exists separately from each other module $A_j$, but often we want to bring them together into one object, so we will abuse the notation a little and write $A = \\oplus_i A_i$. An element $x \\in A_n$ is called a homogeneous element of degree $n$, and similarly if an element $x \\in \\oplus_i A_i$ really lives in some $A_n$ we also call it a homogeneous element of degree $n$. We will sometimes write $\\deg x$ to denote the degree of a homogeneous element. Note that degree does not make any sense for a non-homogeneous element, i.e. an element of $\\oplus_i A_i$ living in more than one summand.\n\nA morphism $f : A \\rightarrow B$ of graded $R$-modules is just an $R$-linear map $f : \\oplus_i A_i \\rightarrow \\oplus_i B_i$. This makes all graded $R$-modules into a category, which we denote by $\\GLMod{R}$. Clearly the hom-sets of $\\GLMod{R}$ form an abelian group such that composition is bilinear, so $\\GLMod{R}$ is actually a pre-additive category. A morphism $f : A \\rightarrow B$ is said to be homogeneous of degree $n$ if $f$ restricted to $A_i$ is a map $f|_{A_i} : A_i \\rightarrow B_{i+n}$. In this case we write $f_i$ to denote the restriction of $f$ to $A_i$. We can make the hom-sets into a graded abelian group (i.e. a $\\mathbb Z$-module) by defining $\\hom(A,B)_i$ to be the collection of morphisms that are homogeneous of degree $i$. It is easy to see that degree is additive with respect to composition, therefore $\\GLMod{R}$ is a graded category.\n\nLet $A$ and $B$ be graded $R$-modules. We define their direct sum to be the graded module $A \\oplus B$ given by the collection $\\lcb A_i \\oplus B_i \\rcb$. We say that $B$ is a graded submodule of $A$ if $B_i$ is a submodule of $A_i$ for all $i \\in \\mathbb Z$. For example, given a morphism $f$ of homogeneous degree $n$, the graded modules $\\ker f$ and $\\image f$ given by $(\\ker f)_i = \\ker f_i$ and $(\\image f)_i = \\image f_{i-n}$ are graded submodules of $A$ and $B$ respectively. If $B$ is a graded submodule of $A$ we can define their quotient to be the grade module $A/B$ given by the collection $\\lcb A_i / B_i \\rcb$. Finally, we define their tensor product to be the graded module $A \\otimes B$ given by\n\\[ (A \\otimes B)_i = \\sum_{j+k=i} A_j \\otimes B_k \\]\n\nGiven just a plain $R$-module $A$, a differential on $A$ is an $R$-linear map $d : A \\rightarrow A$ such that $d \\circ d = 0$. This condition is equivalent to saying that $\\image d \\subset \\ker d$, so we can take the quotient of these submodules. We define the homology module of $(A,d)$ to be $H(A,d) := \\ker d / \\image d$. A module $A$ equipped with a differential is called a differential module. A morphism $f : (A,d) \\rightarrow (B,d')$ of differential modules is an $R$-linear map $f : A \\rightarrow B$ such that $f \\circ d = d' \\circ f$. This makes all differential modules into a category, which we denote by $\\DLMod{R}$. The condition on $f$ to be a morphism of differential modules ensures that $f(\\ker d) \\subseteq \\ker d'$ and $f(\\image d) \\subseteq \\image d'$, so $f$ induces a map $H(A) \\rightarrow H(B)$. This means that $H$ is actually a functor $H : \\DLMod{R} \\rightarrow \\LMod{R}$.\n\nNow suppose $A$ is graded, $A = \\lcb A_i \\rcb$. Then our previous remarks and definitions concerning differentials still makes sense. If $d : A \\rightarrow A$ is just any morphism such that $d \\circ d = 0$, then $H(A,d)$ is not necessarily graded. However, if $d$ is a homogeneous morphism, then $\\ker d$ and $\\image d$ are graded submodules, and so their quotient is a grade module. If $d$ is of homogeneous degree $-1$ we say that $(A,d)$ is a differential graded module, and its homology is a graded module with elements of degree $i$ given by\n\\[ H_i(A,d) = \\frac{\\ker d_i}{\\image d_{i+1}} \\]\nNotice that we are writing $H_i(A,d)$ instead of $H(A,d)_i$ as our notation of graded modules dictates; it is nicer this way. A morphism $f : (A,d) \\rightarrow (B,d')$ of differential graded modules is a morphism $f : A \\rightarrow B$ of degree 0 such that $f_{i-1} \\circ d_i = d_i \\circ f_i$. This makes all differential graded modules into a category, which we will denote by $\\DGLMod{R}$, and $H$ is a functor $H : \\DGLMod{R} \\rightarrow \\GLMod{R}$. Note that $\\DGLMod{R}$ is a subcategory of $\\DLMod{R}$, but not a full subcategory; we are only taking the morphisms from $\\DLMod{R}$ that are of degree 0.\n\nFor a differential graded module $(A,d)$, elements of $\\ker d$ are called cycles and elements of $\\image d$ are called boundaries. In homology we say that two cycles are equivalent if their difference is a boundary. A morphism $f : (A,d) \\rightarrow (B,d')$ that induces an isomorphism $H(f) : H(A,d) \\rightarrow H(B,d')$ is called a quasi-isomorphism. Two morphisms $f,g : (A,d) \\rightarrow (B,d')$ are said to be homotopic if there is a degree 1 morphism $h : (A,d) \\rightarrow (B,d')$ such that $f_i - g_i = d_{i+1} \\circ h_i + h_{i-1} \\circ d_i$. This concept can be visualized in the following diagram:\n\\[\n\\xymatrix\n@C=5pc\n@R=3pc\n{\n \t\\cdots \\ar[rd]\n \t& A_{n-1} \\ar@<-0.5ex>[d]_{f_{i-1}} \\ar@<1ex>[d]^{g_{i-1}} \\ar[rd]^{h_{n-1}} \\ar[l]\n \t& A_n     \\ar@<-0.5ex>[d]_{f_i}     \\ar@<1ex>[d]^{g_i}     \\ar[rd]^{h_n}     \\ar[l]_{d_n} \n \t& A_{n+1} \\ar@<-0.5ex>[d]_{f_{i+1}} \\ar@<1ex>[d]^{g_{i+1}} \\ar[rd]           \\ar[l]_{d_{n+1}} \n \t& \\cdots \\ar[l]\n \t\\\\\n \t\\cdots\n \t& B_{n-1} \\ar[l] \n \t& B_n     \\ar[l]^{d'_n}\n \t& B_{n+1} \\ar[l]^{d'_{n+1}}\n \t& \\cdots  \\ar[l]\n}\n\\]\n\nIf $(A,d)$ is a differential graded module such that $A_i = 0$ for all $i<0$, then we say that $(A,d)$ is a chain complex. We let the full subcategory of chain complexes in $\\DGLMod{R}$ be denoted by $\\ChLMod{R}$. On the other hand, if $A_i = 0$ for all $i>0$, then we say that $(A,d)$ is a cochain complex. In this case we use the convention that $A^i = A_{-i}$, which means we can write $d : A^i \\rightarrow A^{i+1}$, and so $d$ has upper degree equal to $+1$, and we write $H^i(A,d)$ for $H_{-i}(A,d)$. The full subcategory of these objects is denoted by $\\CoChLMod{R}$. For a cochain complex we say that elements of $\\ker d$ are cocycles and elements of $\\image d$ are coboundaries, and the quotient graded module is called the cohomology module.\n\n\n\\section{A Non-Sense Definition}\n\nEven though spectral sequences are quite complicated objects, they can be defined in just a few sentences. Unfortunately spectral sequences are very difficult to motivate, so at first the definition will seem non-sensical, and it will be hard to see why such a thing would be useful or occur in nature.\n\nWe can make our theory of graded objects a little bit more complicated by defining a bigraded module $A$ to be a collection of modules $\\lcb A_{i,j} \\rcb$ indexed by pairs of integers $i,j$. Again we will sometimes blur the notation by writing $A = \\oplus_{i,j} A_{i,j}$. We can define morphisms of bigraded modules just like we did for graded modules, except this time the homogeneous morphisms have a bidegree. We say that $f : A \\rightarrow B$ has bidegree $(m,n)$ if $f$ restricted to $A_{i,j}$ is of the form $f|_{A_{i,j}} : A_{i,j} \\rightarrow B_{i+m,j+n}$, and we denote this restriction by $f_{i,j}$. We will not carry out the theory of bigraded modules as far as we did for graded modules since it is easy to make the generalizations, and we will only need their basic properties.\n\nA differential bigraded module is a bigraded module $A = \\lcb A_{i,j} \\rcb$ with a homogeneous morphism $d : A \\rightarrow A$ such that $d \\circ d = 0$. If $d$ has bidegree of the form $(-r,r-1)$ for some $r$ we say that $A$ is of homological type. If $(A,d)$ is of homological type, then with upper indices $d$ has bidegree $(r,1-r)$, and so when using upper indices we say that such an object has cohomological type.\n\nOur non-sense definition of spectral sequences can now be stated as follows: a spectral sequence of homological type is a sequence of differential bigraded modules $\\lcb E^r,d^r \\rcb_{r \\geq 0}$ such that the bidegree of $d^r$ is of bidegree $(-r,r-1)$, and such that $E^{r+1}$ is isomorphic to the homology of $E^r$, i.e.:\n\\begin{align}\n\\label{(r+1)-th page isomorphic to r-th page}\n\tE^{r+1}_{p,q} &\\cong H_{p,q}(E^r,d^r) \\\\\n\t              &:= \\frac{ \\ker d^r : E_{p,q}^r \\rightarrow E_{p-r,q+r-1}^r }{ \\image d^r : E_{p+r,q-r+1}^r \\rightarrow E_{p,q}^r }\n\\end{align}\nHere $E^r$ does not have anything to do with lower/upper indices, it is just a term in a sequence of bigraded modules. We are forced to use an upper index for $r$ since the bigraded indices are lower. It may seem weird that in \\eqref{(r+1)-th page isomorphic to r-th page} we have some isomorphism floating around in the background, but we take this isomorphism as a part of the structure of a spectral sequence and so forget it altogether. By switching lower indices to upper indices we immediately get the definition of a spectral sequence of cohomological type, but for the sake of completeness we will state the definition. A spectral sequence of cohomological type is a sequence of differential bigraded modules $\\lcb E_r, d_r \\rcb_{r \\geq 0}$ such that the bidegree of $d_r$ is $(r,1-r)$ and\n\\begin{align}\n\tE_{r+1}^{p,q} &\\cong H^{p,q}(E_r,d_r) \\\\\n\t              &:= \\frac{ \\ker d_r : E_r^{p,q} \\rightarrow E_r^{p+r,q+1-r} }{ \\image d_r : E_r^{p-r,q+r-1} \\rightarrow E_r^{p,q} }\n\\end{align}\n\nThe theories of spectral sequences of homological and cohomological type run parallel, so for now we will restrict ourselves to cohomological type and only state the companion results for homological type.\n\nIntuitively we think of spectral sequences as pages of modules ($E_r$ is called the $r$-th page of the spectral sequence) such that the $(r+1)$-th page is isomorphic to the homology of the $r$-th page. Because the homology of a module is a subquotient (that is, a quotient of a submodule) we would expect that the modules on the $(r+1)$-th page to be ``smaller'' than the modules on the $r$-th page. If we fix a grid position $(p,q) \\in \\mathbb Z \\times \\mathbb Z$ and look at the sequence of modules $E_r^{p,q}$ as $r$ increases, we hope that either $E_r^{p,q}$ eventually becomes zero, or stabilizes so that $E_r^{p,q} = E_{r+1}^{p,q}$ for all $r$ greater than some $R$. This leads us to wanting to define a ``limit'' page, called the $E_\\infty$ page.\n\nTo do this, let us for a moment drop the bigrading on our modules $E_r$. This is only done to prevent a superfluous amount of indices floating around, but they can easily be added back in. Since we have dropped bigradings we now just have a sequence of differential modules $(E_r,d_r)$ such that $H(E_r,d_r) \\cong E_{r+1}$. Let $Z_1 = \\ker d_1$ and $B_1 = \\ker d_1$ be the cycles and boundaries so that $E_2 \\cong Z_1 / B_1$. Next, let $\\overline{Z}_2 = \\ker d_2$, which is a submodule of a quotient $Z_1/B_1$, so it can be written as $\\overline{Z}_2 = Z_2/B_1$ for some $Z_2 \\subseteq Z_1$. Similarly, if $\\overline{B}_2 = \\image d_2$, then $\\overline{B}_2$ can be written as $B_2/B_1$ for some $B_2 \\supseteq B_1$. These last two statements follow from the fact that submodules $\\overline{P}$ of a quotient $M/N$ are in one-to-one correspondence with submodules $M \\supseteq P \\supseteq N$.\n\nWe now have the $E_3$ page of the spectral sequence given by\n\\[ E_3 = \\frac{\\overline{Z}_2}{\\overline{B}_2} = \\frac{Z_2/B_1}{B_2/B_1} = \\frac{Z_2}{B_2} \\]\nand we have the tower of submodules\n\\[ 0 \\subseteq B_1 \\subseteq B_2 \\subseteq Z_2 \\subseteq Z_1 \\subseteq E_1 \\]\nSo we have now show that $E_3$ is a subquotient of $E_1$; we already know that $E_2$ is a subquotient by definition, but the fact that $E_3$ is too is nice. Continuing this process we see that we can find a tower of submodules\n\\begin{align}\n\\label{tower of boundaries and cycles}\n0 \\subseteq B_1 \\subseteq B_2 \\subseteq \\cdots \\subseteq B_n \\subseteq \\cdots \\subseteq Z_n \\subseteq \\cdots \\subseteq Z_2 \\subseteq Z_1 \\subseteq E_1\n\\end{align}\nsuch that \n\\[ E_{n+1} = \\frac{Z_n}{B_n} \\]\nand $d_{n+1} : E_{n+1} \\rightarrow E_{n+1}$ induces a map $d_{n+1} : Z_n/B_n \\rightarrow Z_n/B_n$ such that\n\\[ \\ker d_{n+1} = \\frac{Z_{n+1}}{B_n} \\]\n\\[ \\image d_{n+1} = \\frac{B_{n+1}}{B_n} \\]\nNotice that this gives us a short exact sequence\n\\[ 0 \\longrightarrow \\frac{Z_{n+1}}{B_n} \\longrightarrow \\frac{Z_n}{B_n} \\stackrel{d_{n+1}}{\\longrightarrow} \\frac{B_{n+1}}{B_n} \\longrightarrow 0 \\]\nhence we have an isomorphism\n\\begin{align}\n\\label{spectral sequence structural isomorphism}\n\\frac{Z_n}{Z_{n+1}} \\cong \\frac{B_{n+1}}{B_n}\n\\end{align}\nIn fact, it can be shown that given just a tower as in \\eqref{tower of boundaries and cycles} and isomorphisms as in \\eqref{spectral sequence structural isomorphism}, we can work backwards and construct a spectral sequence.\n\nWe say that $Z_n$ is the set of elements that ``survived'' to the $n$-th page, and $B_n$ is the set of elements that are boundaries by the $n$-th page. Seeing as how the $B_n$'s form an increasing tower and the $Z_n$'s form a decreasing tower, it is natural to define $Z_\\infty = \\cap_n Z_n$ (called the set of elements that ``survive forever'') and $B_\\infty = \\cup_n B_n$ (called the set of elements that ``eventually bound''). Now we simply define the limiting page of the spectral sequence to be $E_\\infty = Z_\\infty / B_\\infty$. \n\nAn obvious, but useful, consequence of the definition of homology is that if the differential is zero, then $H(A,d)=A$. This allows spectral sequences to degenerate in very specific ways, and makes it easy to determine the $E_\\infty$ page. Let us look at some examples.\n\n\\begin{example}[First Quadrant Spectral Sequence]\nSuppose $\\lcb E_r,d_r \\rcb$ is a first quadrant spectral sequence, that is $E^{p,q}_r = 0$ whenever $p<0$ or $q<0$. Pick a grid position $(p,q) \\in \\mathbb Z \\times \\mathbb Z$, and let $R = \\max(p+1,q+2)$. We claim that the differential going into and out of $E^{p,q}_r$ are zero for all $r \\geq R$. The differential going out is $d^{p,q}_r : E^{p,q}_r \\rightarrow E^{p-r,q+r-1}_r$. But, $p-r \\leq p-R \\leq p-(p+1) = -1$, hence $E^{p-r,q+r-1}_r = 0$, and so $d_r^{p,q}$ must be zero. The differential going into $E_r^{p,q}$ is $d_r^{p+r,q-r+1} : E_r^{p+r,q-r+1} \\rightarrow E_r^{p,q}$. But, $q-r+1 \\leq q-R+1 \\leq q-(q+2)+1 = -1$, hence $E_r^{p+r,q-r+1}=0$, and so $d_r^{p+r,q-r+1}$ is zero. Since homology with a zero differential does not change the module, we have $E_R^{p,q} = E_{R+1}^{p,q} = \\cdots E_\\infty^{p,q}$. In this case we have determine one entry in the $E_\\infty$ page in a finite number of steps. It should also be noted that similar results can be found for spectral sequences of cohomological type, and for third quadrant spectral sequences, but not necessarily for second and fourth quadrant spectral sequences.\n\\end{example}\n\n\\begin{example}[Vanishing Differentials]\nSuppose there is some integer $R$ such that $d_r^{p,q} = 0$ for all $r \\geq R$ and all $(p,q) \\in \\mathbb Z \\times \\mathbb Z$. Then $E_R = E_{R+1} = \\cdots E_\\infty$, and so we have determined the entire $E_\\infty$ page in a finite number of steps. We say that a spectral sequence collapses if there is some large enough $R$ such that $E_R = E_{R+1} = \\cdots = E_\\infty$, and in this case we say that the spectral sequence collapses at the $E_R$ page.\n\\end{example}\n\n\\begin{example}[Bounded Spectral Sequence]\nSuppose the $E_1$ page has the property that $E_2^{p,q} = 0$ unless $M_1 \\leq p \\leq M_2$ and $N_1 \\leq q \\leq N_2$, i.e. $E_1$'s non-zero modules exist in some bounded region of the $E_1$ page. Then the spectral sequences collapses at the $E_R$ page, where \\nolinebreak $R=\\max(M_2-M_1+1,N_2-N_1+2)$. To see this let us fix any $(p,q)$ in the bounded range and look at the differentials going into and out of $E_R^{p,q}$. The former differential is $d_R^{p,q} : E_R^{p,q} \\rightarrow E_N^{p-R,q+R-1}$, but $p-R \\leq p-(M_2-M_1+1) \\leq p-(p-M_1+1) = M_1-1$, hence $d_R^{p,q} = 0$. The latter differential is $d_{p+R,q-R+1} : E_{p+R,q-R+1} \\rightarrow E_{p,q}$, but $q-R+1 \\leq q-(N_2-N_1+2)+1 \\leq q-(q-N_1+2)+1 = N_1-1$, hence $d_R^{p+R,q-R+1} = 0$. Therefore the spectral sequence collapses at the $E_R$ page. Note that we can get similar statements about spectral sequences whose $r$-th page is bounded, rather than just restricting our attention to $E_1$.\n\\end{example}\n\n\\begin{example}[Vanishing Columns]\nSuppose $E_1$ has only two non-zero columns, that is $E_1^{p,q} = 0$ for all $p \\neq N,M$ for some integers $M<N$. In this case we see that all of the differentials in the pages $E_1,\\ldots,E_{N-M-1}$ are zero, hence $E_1 = \\cdots = E_{N-M}$. The $E_{N-M}$ page can have some non-zero differentials, but then $E_{N-M+1}$ and higher pages have zero differentials, hence $E_{N-M+1} = \\cdots = E_\\infty$.\n\\end{example}\n\n\n\n\\section{Construction of Spectral Sequences from Filtrations}\n\nWe now develop the general theory of the situation that leads us to a spectral sequence. There are two methods to derive a spectral sequence: from an exact couple and from a filtration. The exact couple method is more elegant and easier to understand, but the filtration method is more geometric and easier to see in ``nature.''\n\nLet $A$ be an $R$-modules. A filtration on $A$ is a tower of submodules of $A$. In particular, $F$ is a filtration of $A$, then $F^n A$ is a sequence of submodules such that \n\\[ 0 \\subseteq \\cdots \\subseteq F^{n+1} A \\subseteq F^n A \\subseteq F^{n-1} A \\subseteq \\cdots \\subseteq A \\]\nor\n\\[ 0 \\subseteq \\cdots \\subseteq F^{n-1} A \\subseteq F^n A \\subseteq F^{n+1} A \\subseteq \\cdots \\subseteq A \\]\nIn the first case we say $F$ is a decreasing filtration, and in the second case we say that $F$ is an increasing filtration. A filtration of a module naturally defines a graded module, called the associated graded module. In particular, if $F$ is a filtration on $A$, then we define\n\\[ E_0^n(A,F) = \\begin{cases} F^n A / F^{n+1} A & \\text{if $F$ is decreasing} \\\\ F^n A / F^{n-1} A & \\text{if $F$ is increasing} \\end{cases} \\]\nThis notation may seem weird since it seems to conflict with what we think of as the $E_0$ page of a spectral sequence, but later it will be shown that associated graded objects are closely related to the $E_0$ page of some spectral sequence. An obvious question is: why do we care about the associated graded module? It turns out that the ``answers'' we get from applying spectral sequences are given in terms of associated graded modules, and so we will want to reconstruct the module that gave the associated module.\n\nLet us see how the reconstruction process could be done in the case that our ground ring is a field $R = k$, and so our modules are actually vector spaces. Let $A$ be a finite dimensional vector space and $F$ a finite, decreasing filtration $F$ ($F^{N+1}=0$ and $F^0=A$ for some $N$) with associated graded vector space $E_0(A,F)$. Suppose we know everything about $E_0^n(A,F)$, and from this information we want to construct $A$. We have $E_0^n = 0$ for $n \\geq N+1$ or $n \\leq -1$, so we are only dealing with finitely many vector spaces $E_0^1, \\ldots, E_0^N$. We immediately see that $E_0^N = F^N A/F^{N+1} A = F^N A$, so the first part of the filtration is determined from the associated graded module. Next we have $E_0^{N-1} = F^{N-1} A / F^N A = F^{N-1} A / E_0^N$, which implies that $F^{N-1} A \\cong E_0^{N-1} \\oplus E_0^N$ (these are vector spaces!), so now the second part of the filtration is determined from the associated graded module. Continuing this we find that $F^p A \\cong E_0^p \\oplus E_0^{p+1} \\oplus \\cdots \\oplus E_0^N$. Finally, taking $p=0$ we see that\n\\[ A = F^0 A = E_0^0 \\oplus E_0^1 \\oplus \\cdots \\oplus E_0^N \\]\nand so we have reconstructed $A$ (up to isomorphism) from knowing what the associated graded vector space is. \n\nThe fact that we could reconstruct $A$ above was heavily dependent on the fact that we were working with vector spaces, where the only invariant is dimension and every short exact sequence splits. Suppose we are in the same position as above, except this time $R$ is just a ring. Then we still have $E_0^N = F^N A / F^{N+1} A = F^N A$, so again the first part of the filtration is determined from the associated graded module. However, in the next step we have $E_0^{N-1} = F^{N-1} A / F^N A = F^{N-1} A / E_0^N$, which means we have a short exact sequence\n\\[ 0 \\longrightarrow E_0^N \\longrightarrow F^{N-1} A \\longrightarrow E_0^{N-1} \\longrightarrow 0 \\]\nWe are assuming we know two of the terms in this sequence, but unfortunately the third term is not uniquely determined from this information. Instead, the isomorphism classes of solutions (also called extensions) to this exact sequence are in bijective correspondence with $\\Ext_R^1(E_0^{N-1},E_0^N)$, where $\\Ext$ is the derived functor of $\\Hom$. This means we can determine $F^{N-1} A$ only up to extension, whereas before we could determine it up to isomorphism. Continuing this we see that we can determine $A$ only up to many choices of extensions. \n\nThis may make reconstructing $A$ from $E_0$ seem hopeless, and indeed we can hardly ever solve these extension problems explicitly and get useful information. However, there is one degenerate situation that arises often enough where we can determine $A$. Suppose $F$ is a filtration such that $F^{N+1} = 0$ and $F^N = A$ for some $N$. Then $E_0^N = A$ and $E_0^n = 0$ for all $n \\neq N$, therefore $E_0$ gives $A$ precisely.\n\nWe will now repeat the theory of filtrations, except now we will filter a graded module $A$. Let $F$ be a filtration on $A$ in the previous sense, that is $F$ is a filtration of the regular module $\\oplus_i A^i$. We say that the filtration respects the grading of $A$ if each $F^n A$ is a graded submodule of $A$. In this case $F$ restricts to a filtration of each $A^i$: $F^n A^i \\subseteq F^{n-1} A^i$ for decreasing filtrations and $F^n A^i \\subseteq F^{n+1} A^i$ for increasing filtrations. A graded module with a filtration that respects the grading naturally defines a bigraded module, called the associated bigraded module. In particular, if $F$ is a compatible filtration on $A$, then we define\n\\begin{align}\n\\label{associated bigraded module}\nE_0^{p,q}(A,F) = \\begin{cases} F^p A^{p+q} / F^{p+1} A^{p+q} & \\text{if $F$ is decreasing} \\\\ F^p A^{p+q} / F^{p-1} A^{p+q} & \\text{if $F$ is increasing} \\end{cases}\n\\end{align}\nIt may seem weird that we are using $A^{p+q}$, but this convention allows for many popular spectral sequences to live in the full first quadrant, rather than above the diagonal in the first quadrant (which is kind of awkward).\n\nGiven the associated bigraded module $E_0^{p,q}$ of some graded module $A$ with filtration $F$, we again consider the problem of determining $A$. This reduces to our previous problem for non-graded modules by determining $A^N$ for each integer $N$, i.e. working in one degree at a time. We have a filtration $F$ on $A^N$ since $F$ respects the grading, so we can determine $A^N$ up to many choices of extensions. Note that because of our choice of indices in \\eqref{associated bigraded module} we have that the associated graded module of the filtration $F$ on $A^N$ lives on the diagonal $p+q=N$. \n\nNow suppose that our filtered, graded module $A,F$ also had a differential $d$ such that $d(F^i A^n) \\subseteq F^i A^{n+1}$. Then we see that $d$ descends to a map on the associated bigraded module\n\\[ d : F^p A^{p+q} / F^{p+1} A^{p+q} \\rightarrow F^p A^{p+q+1} / F^{p+1} A^{p+q+1} \\]\nsince $d$ takes the numerator to the numerator and the denominator to the denominator. So we have an induced map $d : E_0^{p,q} \\rightarrow E_0^{p,q+1}$ such that $d \\circ d = 0$ since the original $d$ has this property. How do we interpret this intuitively? Well, we think of the filtration as a weaker notion of grading. That is, we do not necessarily want to know exactly in which filtration an element lives, but we are happy knowing that it lives in either the $p$-th filtration level or higher. The map $d$ also takes this lax view of the filtration, in that it does not have to map elements in one filtration level to the same filtration level, but rather can map to a higher filtration if needed. Once we take the quotient in \\ref{associated bigraded module} we ``strictifying'' the filtration to become a grading. Elements of $E_0^{p,q}$ are like elements that live in $F^p A^{p+q}$ but not in $F^{p+q} A^{p+q}$. Likewise, the induced map $d$ on $E_0^{p,q}$ strictifies $d$ with respect to the filtration, in that it is the part of $d$ that precisely preserved the filtration rather than raising it.\n\nNext we want to discuss ideas of convergence of a spectral sequence. We have already defined the limiting page $E_\\infty$, so we want to know what it means that the ``limit'' of the spectral sequence converged to something. Precisely, a spectral sequence $\\lcb E_r,d_r \\rcb$ is said to converge to a graded module $A$ if there is a filtration $F$ on $A$ such that\n\\[ E_\\infty^{p,q} = E_0^{p,q}(A,F) \\]\nThis is a complicated notion, and it takes time getting used to. In fact, as of right now there are a lot of ambiguities. First of all, in what sense is convergence unique? As of right now convergence is not unique at all, nor is convergence even guaranteed. Second, in many applications of spectral sequences the thing the spectral sequence converges to is what we want to compute, so by our previous remarks we see that we can only compute up to choices of extensions. This does not seem very good for getting concrete results, but nevertheless it is powerful machinery.\n\nWe can now state the fundamental theorems for constructing spectral sequences.\n\n\\begin{thm}[Cohomological Spectral Sequences]\n\\label{fundamental theorem cohomological spectral sequence}\nLet $(A,d)$ be a cochain complex with decreasing filtration $F$ such that the filtration respects the grading and the differential respects the filtration, i.e. $d(F^n A^i) \\subseteq F^n A^{i+1}$. Then there is a spectral sequence $\\lcb E_r,d_r \\rcb_{r \\geq 0}$ of cohomological type such that $E_0 = E_0(A,F)$ and\n\\[ E_1^{p,q} = H^{p+q}(F^p A / F^{p+1} A) \\]\nIf the filtration is bounded, that is, $F^N A = 0$ for sufficiently large $N$ and $F^M A = A$ for sufficiently small $M$, then the spectral sequence converges to $H(A,d)$.\n\\end{thm}\n\n\\begin{thm}[Homological Spectral Sequences]\n\\label{fundamental theorem homological spectral sequence}\nLet $(A,d)$ be a chain complex with increasing filtration $F$ such that the filtration respects the grading and the differential respects the filtration, i.e. $d(F_n A_i) \\subseteq F_n A_{i-1}$. Then there is a spectral sequence $\\lcb E^r,d^r \\rcb_{r \\geq 0}$ of cohomological type such that $E^0 = E^0(A,F)$ and\n\\[ E^1_{p,q} = H_{p+q}(F_p A / F_{p+1} A) \\]\nIf the filtration is bounded, that is, $F_N A = 0$ for sufficiently small $N$ and $F_M A = A$ for sufficiently large $M$, then the spectral sequence converges to $H(A,d)$.\n\\end{thm}\n\n\\begin{proof}(Wordy Proof of \\ref{fundamental theorem cohomological spectral sequence})\nWe are starting with a cochain complex $(A,d)$ with a filtration $F$ such that these structures are compatible. Let us define the following modules\n\\begin{align*}\n\tZ_r^{p,q} &= F^p A^{p+q} \\cap d^{-1} (A^{p+q+1}) \\\\\n\tB_r^{p,q} &= F^p A^{p+q} \\cap d(F^{p-r} A^{p+q+1}) \\\\\n\tZ_\\infty^{p,q} &= F^p A^{p+q} \\cap \\ker d \\\\\n\tB_\\infty^{p,q} &= F^p A^{p+q} \\cap \\image d\n\\end{align*}\nThe elements of $Z_r^{p,q}$ are elements in the $p$-th level filtration whose boundaries are in the $(p+r)$-th level filtration. We could call these ``almost'' cocycles, as their boundaries are not zero, but their boundaries live in high levels of the filtration. Since the filtration is decreasing, we have that $F^n A$ gets smaller as $n$ gets larger, so the boundaries living in high levels of filtration is an approximation of the boundary being zero. In fact, if the filtration was exhaustive, i.e. $\\cap_n F^n A = 0$ and $\\cup_n F^n A = A$, then as $r \\to \\infty$ we would have elements of $Z_r^{p,q}$ become honest cocycles, hence our definition of $Z_\\infty^{p,q}$. Similarly, elements of $B_r^{p,q}$ are elements in the $p$-th level filtration that are boundaries of things in the $(p-r)$-th level filtration. These are true boundaries, but they are boundaries of a restricted set of cochains. As $r \\to \\infty$ they become boundaries in the unrestricted sense.\n\nSince $d$ respects the filtration we get a tower of modules\n\\[ B_0^{p,q} \\subseteq B_1^{p,q} \\subseteq \\cdots \\subseteq B_\\infty^{p,q} \\subseteq Z_\\infty^{p,q} \\subseteq \\cdots \\subseteq Z_1^{p,q} \\subseteq Z_0^{p,q} \\]\nWith this tower we are going to define each page $E_r$ and differential $d_r$, and show they satisfy the following properties:\n\\begin{enumerate}\n\t\\item $H^*(E_r,d_r) = E_{r+1}$\n\t\\item $E_1^{p,q} = H^{p+q}(F^p A / F^{p+1} A)$\n\t\\item $E_\\infty^{p,q} = F^p H^{p+q}(A,d) / F^{p+1} H^{p+q}(A,d)$\n\\end{enumerate}\nFor $0 \\leq r \\leq \\infty$ we define the $E_r$ page by\n\\begin{equation}\n\\label{definition of E_r-page}\nE_r^{p,q} := \\frac{Z_r^{p,q}}{Z_{r-1}^{p+1,q-1} + B_{r-1}^{p,q}}\n\\end{equation}\nThis quotient makes sense because $Z_{r-1}^{p+1,q-1}$ and $B_{r-1}^{p,q}$ are submodules of $Z_r^{p,q}$. We can call the denominator of this quotient ``almost'' boundaries, and so the $r$-th page is intuitively the ``almost'' cycles modulo the ``almost'' boundaries. As $r$ gets bigger, the numerator and denominator get closer to being true cycles and boundaries.\n\nWe would like to see that the differential $d$ on $A$ induces a differential $d_r$ on the $E_r$-page. To see this first notice that\n\\begin{align*}\n\td(Z_r^{p,q}) &\\subseteq d(F^p A^{p+q}) \\cap F^{p+r} A^{p+q+1} \\\\\n\t\t\t\t\t\t   &= F^{p+r} A^{p+q+1} \\cap d(F^p A^{p+q}) \\\\\n\t\t\t\t\t\t   &\\subseteq B_r^{p+r,q-r+1} \\\\\n\t\t\t\t\t\t   &\\subseteq Z_r^{p+r,q-r+1} \n\\end{align*}\nSo $d$ restricts to a map $d : Z_r^{p,q} \\rightarrow Z_r^{p+r,q-r+1}$. As for the denominator of the quotient \\ref{definition of E_r-page} we have\n\\begin{align*}\n\td(Z_{r-1}^{p+1,q-1} + B_{r-1}^{p,q}) &\\subseteq d(Z_{r-1}^{p+1,q-1}) + d(B_{r-1}^{p,q}) \\\\\n\t                                     &\\subseteq Z_{r-1}^{p+r,q-r+1} + 0 \\\\\n\t                                     &\\subseteq Z_{r-1}^{p+r,q-r+1} + B_{r-1}^{p+r,q-r+1}\n\\end{align*}\nwhere the last equation follows since $B_{r-1}^{p+r,q-r+1} \\subseteq Z_{r-1}^{p+r,q-r+1}$. Therefore the restriction of $d$ to $Z_r^{p,q}$ descends to a map $d_r : E_r^{p,q} \\rightarrow E_r^{p+r,q-r+1}$, and since $d \\circ d = 0$ we clearly have $d_r \\circ d_r = 0$. This is our differential on the $E_r$-page.\n\n\\todo{finish}\n\\end{proof}\n\nThese theorems can be interpreted in the following way. We have some cochain complex $(A,d)$ whose cohomology we want to compute. For whatever reason the module $A$ and its cohomology are inaccessible. However, we are lucky enough to have a filtration on $A$, and so we hope to get information on $H(A,d)$ by looking only at the cocycles/coboundaries that ``live'' in one filtration level. This is roughly the content of the $E_1$ page of the associated spectral sequence. The higher pages consist of coclycles/coboundaries that are allowed to travel farther through the filtration levels. By simple formalisms or intuition, we end up computing some (or all) of the modules in the higher pages of the spectral sequence. This will eventually give us information about the $E_\\infty$ page, which by the theorem is the associated bigraded module of $H(A,d)$, so we can start the reconstruction process on $H(A,d)$.\n\nSome further remarks on \\ref{fundamental theorem cohomological spectral sequence} and \\ref{fundamental theorem homological spectral sequence}, as they are quite fundamental. The boundedness assumption on the filtration is not necessary to ensure convergence, but in the general setting we are stating our theorem it is needed. Many of the spectral sequence theorems will not have a bounded filtration, so we can use these theorems to show existence of the spectral sequence, but not to show it converges. \n\nThe moral of this story is the following: when you have a graded object, with a differential, with a filtration, such that everything is compatible with each other, think of spectral sequences.\n\n\n\n\\section{Examples of Spectral Sequences}\n\n\\subsection{The Spectral Sequence of a Double Complex}\n\nThis spectral sequence is purely algebraic, and is perhaps the easiest to understand. It has many applications to geometric problems, such as the cohomology of $(p,q)$-forms on complex manifolds and hypercohomology. We start with a bigraded module $A = \\lcb A^{p,q} \\rcb$, and for now assume that it lives in the first quadrant $p \\geq 0, q \\geq 0$. Suppose we have two differentials $d_I,d_{II}$ of $A$, where $d_I$ is of bidegree $(1,0)$ and $d_{II}$ is of bidegree $(0,1)$, such that $d_I \\circ d_{II} + d_{II} \\circ d_I = 0$. We call such an object a double complex. We claim that this induces the structure of a complex on the total graded module $\\Total(A)$ defined by\n\\[ \\Total(A)^n = \\bigoplus_{p+q=n} A^{p,q} \\]\nWe define a morphism $d : \\Total(A)^n \\rightarrow \\Total(A)^{n+1}$ by $d = d_I + d_{II}$. Since each of $d_I$ and $d_{II}$ maps the diagonal $p+q=n$ to $p+q=n+1$ we have that $d$ does in fact map $\\Total(A)^n$ to $\\Total(A)^{n+1}$. We also have $d^2 = 0$ since\n\\begin{align*}\n\td^2(x) &= d(d_I(x) + d_{II}(x)) \\\\\n\t           &= d_I^2(x) + d_I(d_{II}(x)) + d_{II}(d_I(x)) + d_{II}^2(x) \\\\\n\t           &= 0\n\\end{align*}\nwhere the last line follows since $d_I$ and $d_{II}$ anti-commute. We now have 3 cohomology theories running around: two coming from the differentials $d_I$ and $d_{II}$ on $A$, and the one coming from $d$ on $\\Total(A)$. We will now derive a spectral sequence that relates these three cohomologies.\n\nConsider the filtration $F$ on $\\Total(A)$ given by\n\\[ F^p \\Total(A)^n = \\bigoplus_{\\scriptsize \\begin{array}{c} p'+q=n \\\\ p' \\geq p \\end{array} } A^{p',q} \\]\nThat is, we take the part of the $n$-th diagonal line that starts at column $p$ and contains higher columns (think of a vertical half-space). This filtration is decreasing. The differetial $d$ clearly respects this filtration since $d_I$ maps elements into higher columns and $d_{II}$ maps elements into the same column. By \\ref{fundamental theorem cohomological spectral sequence} we know that this data leads to a spectral sequence with $E_0$ equal to the associated bigraded module, $E_1$ equal to the homology of the associated module, and converging to the homology of $\\Total(A)$. Let us try to identify the $E_0$ and $E_1$ pages of this spectral sequence.\n\nRecall that we define the associated bigraded module by\n\\[ E_0^{p,q} \\Total(A) = F^p \\Total(A)^{p+q} / F^{p+1} \\Total(A)^{p+q} \\]\nAn inspection of this quotient shows that $E_0^{p,q}$ is nothing but the summands on the $(p+q)$-th diagonal that are in the $p$-th column but not in the $(p+1)$-st and higher columns. Clearly there is only one such summand, $A^{p,q}$, therefore $E_0^{p,q} = A^{p,q}$. The differential $d$ on the total complex induces a differential $d_0 : E_0^{p,q} \\rightarrow E_0^{p,q+1}$. Using the definition of $d$ we see that $d_0$ acts on $[z] \\in E_0^{p,q}$ by\n\\begin{align*}\n\td_0[z] &= [d(z)] \\\\\n         &= [d_I(z) + d_{II}(z)] \\\\\n         &= [d_I(z)] + [d_{II}(z)] \\\\\n         &= [d_{II}(z)]\n\\end{align*}\nwhere the last line follows since $d_I$ maps $z$ into the denominator of the quotient $E_0^{p+1,q}$. Therefore $(E_0,d_0)$ is isomorphic to $(A,d_{II})$ as complexes. It is now clear that $E_1$ is simply the homology of $A$ with respect to the differential $d_{II}$: \n\\[ E_1^{p,q} = H^{p,q}(A,d_{II}) := \\frac{ \\ker d_{II} : A^{p,q} \\rightarrow A_{p,q+1} }{ \\image d_{II} : A^{p,q-1} \\rightarrow A^{p,q} } \\]\nAs we know from the proof of \\ref{fundamental theorem cohomological spectral sequence}, the differential $d$ induces the differential $d_1$ on the $E_1$ page. \n\n\\unfinished\n\n\n\n\n\nOur filtration above had a little bit of an arbitrary choice in its definition. We could have just as easily defined a filtration $G$ on $\\Total(A)$ by horizontal half-spaces\n\\[ G^q \\Total(A)^n = \\bigoplus_{\\scriptsize \\begin{array}{c} p+q'=n \\\\ q' \\geq q \\end{array} } A^{p,q'} \\]\nThe differential $d$ on $\\Total(A)$ respects this filtration too, so we get another spectral sequence. It is easy to repeat the steps above to determine the $E_0$ and $E_1$ pages of this new spectral sequence, so we just state the theorem:\n\n\\begin{thm}[Spectral Sequence of a Double Complex]\nLet $(A,d_I,d_{II})$ be a double complex. Then there are two spectral sequences with\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|l|l|}\n\t\\hline\n\tFirst & Second \\\\\n\t\\hline \\hline\n\t$(E_0^{p,q},d_0) \\cong (A^{p,q},d_I)$ &\t\t$(E_0^{p,q},d_0) \\cong (A^{p,q},d_{II})$ \\\\\n\t\\hline\n\t$(E_1,d_1) \\cong (H(A,d_I),d_{II})$ & \t\t$(E_1,d_1) \\cong (H(A,d_{II}),d_I)$ \\\\\n\t\\hline\n\t$E_2 = H(H(A,d_I),d_{II})$ & \t\t\t\t$E_2 = H(H(A,d_{II}),d_I)$ \\\\\n\t\\hline\n\t$\\Longrightarrow H(\\Total(A),d)$ & \t\t$\\Longrightarrow H(\\Total(A),d)$ \\\\\t\\hline\n\\end{tabular}\n\\end{table}\n\\end{thm}\n\n\n\n\\subsection{The \\Kunneth Spectral Sequence}\n\nIn homological algebra there are a collection of \\Kunneth like theorems, which are supposed to help calculate the homology of a product from the homology of the factors. These theorems are usually stated for complexes whose modules are free (or more generally with some flatness condition) so that we can split the complexes into simpler pieces. We will discuss a spectral sequence version of these theorems which allows us to remove some of the restrictions.\n\nLet us first recall the regular \\Kunneth formula. Let $(A,d_A)$ and $(B,d_B)$ be differential graded modules such that $\\ker d_A$ and $\\image d_A$ are flat modules. There is an obvious injective homomorphism $p : H(A) \\otimes H(B) \\rightarrow H(A \\otimes B)$ given by $p([u] \\otimes [v]) = [u \\otimes v]$. The \\Kunneth theorem identifies the cokernel of this map using the $\\Tor$ functor, and gives the following short exact sequence for each $n$\n\\[ 0 \\longrightarrow \\bigoplus_{p+q=n} H^p(A) \\otimes H^q(B) \\stackrel{p}{\\longrightarrow} H^n(A \\otimes B) \\longrightarrow \\bigoplus_{p+q=n-1} \\Tor_R^1 (H^p(A),H^q(B)) \\longrightarrow 0 \\]\nFurther, this exact sequence splits, but not naturally. \n\nNow let $(A,d_A)$ and $(B,d_B)$ be differential graded modules again, except now we only require that $A$ is flat. Assume for a moment that both differentials of degree $-1$. Then there is a first quadrant spectral sequence with\n\\[ E_2^{p,q} = \\bigoplus_{s+t=q} \\Tor_R^p (H^s(A), H^t(B)) \\]\nand converging to $H(A \\otimes B)$.\n\n\n\\subsection{The Leray-Serre Spectral Sequence}\n\nWe finally come to a geometric example of spectral sequences. In algebraic topology we like to study two algebraic aspects of spaces: their homology groups and their homotopy groups. Due to some kind of divine justice it turns out that homology groups are difficult to define but amazingly easy to compute, whereas homotopy groups are easy to define but incredibly difficult to compute. Further, anything that comes easy for homology will be difficult for homotopy theory, and vice versa. For example, given a cofibration $i : A \\rightarrow X$, there is a nice way of computing the homology of the cofiber $X/A$ in terms of $X$ and $A$ (called exicision). However, no such property can exist in homotopy theory, although the Freudenthal suspension theorem is a very weak version of exicision. Dually, given a fibration $F \\rightarrow E \\stackrel{p}{\\rightarrow} B$ there is a nice long exact sequence relating the homotopy groups of the spaces $F$, $E$ and $B$, but in homology the best we can get is a spectral sequence. This is the content of the Leray-Serre spectral sequence. \n\nLet $F \\rightarrow E \\stackrel{p}{\\rightarrow} B$ be a fibration where $B$ is a CW-complex (this can be weakened to spaces that are homotopy equivalent to CW-complexes). Let us also assume that the base space $B$ is simply connected. This assumption can be dropped if we introduce appropriate technical machinery. The base space $B$ is filtered by its skeleton: $B^{(0)} \\subset B^{(1)} \\subset \\cdots \\subset B^{(n)} \\subset \\cdots$, where $B^{(n)}$ are the $n$-cells in $B$. Let $X^n$ be the pre-image of the $n$-skeleton of $B$, i.e. $X_n = p^{-1}(B^{(n)})$. This topological filtration on $E$ leads to a decreasing filtration $F$ on the singular cochains of $E$ (with any coefficients) by defining\n\\[ F^p C^n(E) = \\image \\left( C^n(X^{p+1}) \\stackrel{C^n(\\hookrightarrow)}{\\longrightarrow} C^n(X^p) \\right) \\]\nWe clearly have $F^p C^n(E) \\subseteq F^{p-1} C^n(E)$ and the singular coboundary operator $\\delta$ respects the filtration. This leads to a spectral sequence known as the Leray-Serre spectral sequence.\n\n\n\\begin{thm}[Leray-Serre Spectral Sequence]\nFor a fibration $F \\rightarrow E \\rightarrow B$, with $F$ connected and $B$ simply connected, there is a spectral sequence of cohomological type such that\n\\[ E_2^{p,q} = H^p(B; H^q(F)) \\]\nand converging to $H^*(E)$. There is also a spectral sequence of homological type such that\n\\[ E^2_{p,q} = H_p(B; H_q(F)) \\]\nand converging to $H_*(E)$.\n\\end{thm}\n\n\n\n\n\n\\subsection{The Atiyah-Hirzebruch Spectral Sequence}\n\nIn the 40's a paper was published by Eilenberg and Steenrod that unified many of the homology theories defined on topological spaces. Most of the known homology theories satisfied the following basic properties: functorality, exicision, additivity, a long exact sequence for pairs, as well as a normalizing dimension axiom. It turns out that any two theories satisfying these 5 axioms on the category of spaces homotopy equivalent to CW-complexes will be naturally isomorphic, and so will yield isomorphic groups. Later on, many homology-like theories were discovered that did not satisfy the dimension axiom, and these theories were called generalized homology theories. If $h_*$ is a generalized homology theory, we call the graded abelian group $h_*(\\text{pt})$ the coefficients of the theory.\n\nThe Atiyah-Hirzebruch spectral sequence generalizes the Leray-Serre spectral sequence for generalized homology theories. Let $h^*$ be a generalized cohomology theory, i.e. a sequence of functors $h^n : \\mathscr C \\rightarrow \\Ab$ satisfying the Eilenberg-Steenrod axioms except for the dimension axiom, where $\\mathscr C$ is the category of spaces homotopy equivalent to CW-complexes. \n\n\\begin{thm}[Atiyah-Hirzebruch Spectral Sequence]\nLet $h^*$ be a generalized cohomology theory. For a fibration $F \\rightarrow E \\stackrel{p}{\\rightarrow} B$ there is a spectral sequence of cohomological type such that\n\\[ E_2^{p,q} = H^p(B; h^q(F)) \\]\nand converging to $h^*(E)$. If $h_*$ is a generalized homology theory, then there is a spectral sequence of homological type such that\n\\[ E^2_{p,q} = H_p(B; h_q(F)) \\]\nand converging to $h_*(E)$.\n\\end{thm}\n\nConsider the special case of the fibration $\\text{pt} \\rightarrow B \\rightarrow B$. Then the Atiyah-Hirzebruch spectral sequence says that we can essentially compute the cohomology $h^*$ of $B$ by only knowing the singular homology and the coefficients of $h^*$.\n\n\n\n\\subsection{The Spectral Sequence of a Covering Space}\n\nWe can use the Leray-Serre spectral sequence to derive a spectral sequence for a regular covering space $p : \\tilde{X} \\rightarrow X$ with group of deck transformations $G$. First we review some concepts from group cohomology. Let $G$ be an arbitrary group, and consider the functor $-^G : \\LMod{G} \\rightarrow \\Ab$ defined by\n\\[ A \\mapsto A^G = \\lcb x \\in A \\st gx = x \\text{ for all } g \\in G \\rcb \\]\nwhere $\\LMod{G}$ is the category of abelian groups with $G$-actions and $G$-equivariant morphisms. This functor is left exact, but not necessarily right exact, so we define the $n$-th cohomology group of $G$ with coefficients in $A$\n\n\\unfinished\n\n\n\n\\subsection{The Hypercohomology Spectral Sequence}\n\n\n\\subsection{The Grothendieck Spectral Sequence}\n\nThis spectral sequence is very general, and contains many other spectral sequence as a special case. Let $\\mathscr A, \\mathscr B, \\mathscr C$ be abelian categories with enough injectives, and let $F : \\mathscr A \\rightarrow \\mathscr B$, $G : \\mathscr B \\rightarrow \\mathscr C$ be additive covariant functors. Assume that $G$ is left exact, and and $F$ takes injective objects to $G$-acyclic objects. Then for each object $A$ of $\\mathscr A$ there is a spectral sequence with\n\\[ E_2^{p,q} = (R^p G \\circ R^q F)(A) \\]\nand converging to $R^{p+q} (G \\circ F)(A)$, where $R^*$ is the right derived functor. Essentially this says that we can compute the derived functors of a composition from the derived functors of each functor in the composition. \n\n\n\n\\section{Computations with Spectral Sequences}\n\n\n\\subsection{Homology of Loop Spaces of Spheres}\n\nConsider the problem of computing $H^*(\\Omega S^n)$, where $\\Omega -$ is the functor that takes a space to its based loop space. This a very complicated space, but there is a simple fibration involving it. Consider the path-space fibration: $\\Omega S^n \\rightarrow PS^n \\rightarrow S^n$. Here $P-$ is the functor that takes a space to its based path space, and the second map is evaluation at 1. By the Leray-Serre theorem we get a spectral sequence of homological type such that \n\\[ E_{p,q}^n = H_p(S^n, H_q(\\Omega S^n)) \\]\nand converging to $H_*(PS^n)$. The bidegree of the differential $d_r$ on the $E_r$ page is $(-r,r+1)$. The path space $PS^n$ is clearly contractible, so we have $H_*(PS^n,A) = A$, concentrated in degree 0, for any coefficient group $A$. We also know $H_*(S^n,A) = A \\oplus A$ concentrated in degree 0 and $n$. Therefore we have a spectral sequence with \n\\[ E_{p,q}^2 = \\begin{cases} H_q(\\Omega S^n) & p=0 \\text{ or } p=n \\\\ 0 & \\text{otherwise} \\end{cases} \\]\nand the $E^\\infty$ consists of a single copy of $\\mathbb Z$ in bidegree $(0,0)$ since $PS^n$ is contractible. By the adjunction relation, $[\\Sigma X,Y] = [X, \\Omega Y]$, we see that since $S^n$ is $(n-1)$-connected we have that $\\Omega S^n$ is $(n-2)$-connected, hence by Hurewicz's theorem $H_i(\\Omega S^n)=0$ for $1 \\leq i \\leq n-2$. The following grid diagram of the $E_2$ page may be helpful.\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|c|c|c|c|c|}\n\t\\hline\n\t$\\vdots$ & & & & $\\vdots$ \\\\\n\t\\hline\n\t$H_n(\\Omega S^n)$ & & $\\cdots$ & & $H_n(\\Omega S^n)$ \\\\\n\t\\hline\n\t$H_{n-1}(\\Omega S^n)$ & & $\\cdots$ & & $H_{n-1}(\\Omega S^n)$ \\\\\n\t\\hline\n\t$\\vdots$ & & & & $\\vdots$ \\\\\n\t\\hline\n\t0 & & $\\cdots$ & & 0 \\\\\n\t\\hline\n\t$\\mathbb Z$ & & $\\cdots$ & & $\\mathbb Z$ \\\\\n\t\\hline\n\\end{tabular}\n\\end{table}\nAll the entries in the table that are not in the two main columns are zero. This implies that all the differentials on the $E^2$ page are zero. In fact, the differentials on the pages $E^3, E^4, \\ldots, E^{n-1}$ are zero, and the differentials on $E^{n+1}$ and higher pages are also zero. Consider the differential $d_{n,0}^n : \\mathbb Z \\rightarrow H_{n-1}(\\Omega S^n)$. This map must be an isomorphism, for otherwise its kernel and cokernel (one of which would be nonzero) would survive to the $E^\\infty$ page. However, only one copy of $\\mathbb Z$ can survive to $E^\\infty$, which must be in bigrading $(0,0)$. Therefore this map is an isomorphism, and so $H_{n-1}(\\Omega S^n) \\cong \\mathbb Z$. Similarly we get that the differential $d_{n,1}^n : H_1(\\Omega X) \\rightarrow H_n(\\Omega X)$ is an isomorphism, hence $H_n(\\Omega X) = 0$. More generally we see that the groups $H_i(\\Omega X)$ and $H_{i+(n-1)k}(\\Omega X)$ are isomorphic for any integer $k$. This finishes the computation of the homology of the loop space of $S^n$:\n\\[ H_i(S^n) = \\begin{cases} \\mathbb Z & i = (n-1)k \\text{ for some integer } k \\\\ 0 & \\text{otherwise} \\end{cases} \\]\n\n\n\n\n\\subsection{Hurewicz's Theorem}\n\\label{Hurewicz's Theorem Discussion}\n\nWe can us the path space fibration to come up with a spectral sequence proof of Hurewicz's theorem. Recall that this theorems says that for a connected topological space $X$, if $\\pi_i(X) = 0$ for $i$ less than some fixed $n>1$, then $H_i(X) = 0$ for $1 \\leq i < n$, and $\\pi_n(X) \\cong H_n(X)$. The full Hurewicz theorem actually says a little more; it provides an explicit isomorphism of the homotopy and homology groups, and states that the isomorphism is natural. We are not going to prove these two additional properties.\n\nTake some connected topological space $X$, and consider the path space fibration $\\Omega X \\rightarrow PX \\rightarrow X$. We will prove this by induction. Suppose $n=2$ so that $\\pi_1(X)=0$. Since $H_1(X)$ is the abelianization of the fundamental group, we already have that $H_1(X)=0$. To show that the second homotopy and homology groups are isomorphic, consider the Leray-Serre spectral sequence. It has $E^2$ page\n\\[ E_{p,q}^2 = H_p(X,H_q(\\Omega X)) \\]\nOn this page there is a differential $d_{2,0}^2 : E_{2,0}^2 \\rightarrow E_{0,1}^2$, but we have $E_{2,0}^2 = H_2(X)$ and $E_{0,1}^2 = H_1(\\Omega X)$. This map must be an isomorphism, for otherwise it would have some kernel or cokernel, and those groups would survive to the $E^3$ and higher pages, all the way to the $E^\\infty$ page. But there is only one copy of $\\mathbb Z$ in the $(0,0)$ grading on the $E^\\infty$ page. Therefore $H_2(X) \\cong H_1(\\Omega X)$. Using the adjunction relation $[\\Sigma X,Y] = [X,\\Omega Y]$, where $\\Sigma-$ is the suspension functor, we have the following string of isomorphisms\n\\begin{align*}\n\tH_1(\\Omega X) &\\cong \\frac{\\pi_1(\\Omega X)}{[\\pi_1(\\Omega X),\\pi_1(\\Omega X)]} \\\\\n\t              &\\cong \\frac{\\pi_2(X)}{[\\pi_2(X),\\pi_2( X)]} \\\\\n\t              &\\cong \\pi_2(X)\n\\end{align*}\nwhere the last isomorphism follows from the fact that $\\pi_2$ and higher homotopy groups are abelian. Therefore $H_2(X) \\cong \\pi_2(X)$, and so the base case is done.\n\nNow suppose the theorem is true for all integers less than $n$. Let $X$ be a space with $\\pi_i(X) = 0$ for $i < n$. By induction we have $H_i(X) = 0$ for $1 \\leq i < n$, so we only need to show $H_n(X) \\cong \\pi_n(X)$. By the adjunction relation we have that $\\pi_i(\\Omega X) = 0$ for $i < n-1$, and so by induction we also have $H_i(\\Omega X)=0$ for $i < n-1$. Because of the vanishing of these homology groups we see that the region $\\lcb 1 \\leq p \\leq n-1, q \\geq 0 \\rcb$ on the $E^2$ page is zero, hence that region is zero on all pages of the Leray-Serre spectral sequence. This implies that the first non-zero differential coming out of or going into the $(n,0)$ and $(0,n-1)$ slot is on the $n$-th page, in which case we have a differential $d_{n,0}^n : E_{n,0}^n \\rightarrow E_{0,n-1}^n$. We must have that this differential is an isomorphism, for otherwise its kernel and cokernel would survive to the $E^\\infty$ page, but there is only the one copy of $\\mathbb Z$ in grading $(0,0)$. But also $E_{n,0}^n = H_n(X)$ and $E_{0,n-1}^n=H_{n-1}(\\Omega X)$, therefore we get a string of isomorphisms\n\\begin{align*}\n\tH_n(X) &\\cong H_{n-1}(\\Omega X) \\\\\n\t       &\\cong \\pi_{n-1}(\\Omega X) \\\\\n\t       &\\cong \\pi_n(X)\n\\end{align*}\nThis completes the proof of Hurewicz's theorem.\n\n\n\n\\subsection{Cohomology of Lens Spaces}\n\nConsider the odd dimensional spheres $S^{2n-1}$ sitting in complex $n$-dimensional space $\\mathbb C^n$. There is an action of $\\mathbb Z/k = \\< e^{2\\pi/k} \\>$ on $S^{2n-1}$ given by\n\\[ e^{2\\pi \\ell/n} \\cdot (z_1,\\ldots,z_n) = (e^{2\\pi \\ell/n} z_1,\\ldots, e^{2\\pi \\ell/n} z_n) \\]\nThis action is free, and so the quotient of $S^{2n-1}$ by this action is a manifold, called the $(n,k)$ lens space, and is denoted by $L(n,k)$. This gives us a fibration $\\mathbb Z/k \\rightarrow S^{2n-1} \\rightarrow L(n,k)$ (in fact, a covering space), but we cannot apply the Leray-Serre spectral sequence since the fiber is not connected. However, consider the action of $S^1$ on $S^{2n-1}$ given by\n\\[ w \\cdot (z_1,\\ldots,z_n) = (wz_1,\\ldots,wz_n) \\]\nThis action is free and properly discontinuous, and the quotient of $S^{2n-1}$ by the action is simply complex projective space $\\mathbb CP^{n-1}$. This leads to a fibration $S^1 \\rightarrow S^{2n-1} \\rightarrow \\mathbb CP^{n-1}$. We can form a fibration $S^1 \\rightarrow L(n,k) \\rightarrow \\mathbb CP^{n-1}$ where the second map makes the rest of the $S^1$ identifications.\n\nFrom this we see that we have a sequence of inclusions $L(1,k) \\subset L(2,k) \\subset \\cdots$, and so taking the limit we form the infinite lens space, denoted by $L(k)$. By the covering space of $L(n,k)$ we see that $\\pi_1(L(n,k)) = \\mathbb Z/k$ and $\\pi_i(L(n,k)) = 0$ for $2 \\leq i \\leq n-1$. Therefore we have $\\pi_1(L(k)) = \\mathbb Z/k$ and $\\pi_i(L(k)) = 0$ for all $i > 1$; in other words, $L(k)$ is a $K(\\mathbb Z/k,1)$ space.\n\nWe now apply the Leray-Serre spectral sequence to the fibration $S^1 \\rightarrow L(k) \\rightarrow \\mathbb CP^\\infty$. We know that $H^*(S^1) = \\Lambda(\\alpha)$, with $\\deg \\alpha = 1$, and $H^*(\\mathbb CP^\\infty) = \\Lambda(\\beta)$, with $\\deg \\beta = 2$. We can easily see that $E_2^{p,q} = \\mathbb Z$ for $p$ even and $q=0,1$, and $E_2^{p,q} = 0$ everywhere else. Due to degree considerations of the differentials, we see that $E_3 = E_4 = \\cdots = E_\\infty$. Since the second page $E_2^{p,q}=H^p(\\mathbb CP^\\infty,H^q(S^1))$ has a bialgebra structure, we can find generators for $E_2^{p,q}$, and they are listed below.\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\t\\hline\n\t$\\alpha$ & 0 & $\\alpha \\beta$ & 0 & $\\alpha\\beta^2$ & $\\cdots$ \\\\\n\t\\hline\n\t1 & 0 & $\\beta$ & 0 & $\\beta^2$ & $\\cdots$ \\\\\n\t\\hline\n\\end{tabular}\n\\end{table}\nThe differential $d_2 : E_2^{0,1} \\rightarrow E_2^{2,0}$ must map $d_2 \\alpha = n\\beta$ for some integer $n$, hence $E_3^{2,0} = E_\\infty^{2,0} = \\mathbb Z/n$. Since the other entries on the $p+q=2$ diagonal of the $E_\\infty$ page, namely $E_\\infty^{2,0}$ and $E_\\infty^{1,1}$, are zero, we must have that $H^2(L(k)) = \\mathbb Z/n$. To compute what $n$ is, let us apply the universal coefficient theorem to get the short exact sequence\n\\[ 0 \\longrightarrow \\Ext(H_1(L(k)),\\mathbb Z) \\longrightarrow H^2(L(k)) \\longrightarrow \\Hom(H_2(L(n)),\\mathbb Z) \\longrightarrow 0 \\]\n\\[ 0 \\longrightarrow \\Ext(\\mathbb Z/k,\\mathbb Z) \\longrightarrow \\mathbb Z/n \\longrightarrow \\Hom(\\mathbb Z/n, \\mathbb Z) \\longrightarrow \\]\nSince $\\Ext(\\mathbb Z/k,\\mathbb Z) = \\mathbb Z/k$ and $\\Hom(\\mathbb Z/n,\\mathbb Z) = 0$, we have $\\mathbb Z/k \\cong \\mathbb Z/n$, hence $n = \\pm k$. Therefore $H^2(L(k)) = \\mathbb Z/k$, and since the $p+q=1$ diagonal consists of all zeros we have $H^1(L(k)) = 0$.\n\nWe can repeat this argument on the other differentials to show that $d_2 :E_2^{p,1} \\rightarrow E_2^{p+2,0}$ is multiplication by $\\pm n$, hence $H^{2i}(L(k)) = \\mathbb Z/k$. In general we have computed\n\\[ H^i(L(k)) = \\begin{cases} \\mathbb Z & i = 0 \\\\ \\mathbb Z/k & i \\geq 2 \\text{ and even} \\\\ 0 \\text{otherwise} \\end{cases} \\]\n\n\n\n\\subsection{Group Actions on Spheres}\n\n\n\\subsection{Some Cohomology Groups of $K(\\mathbb Z,3)$}\n\nRecall that the definition of a $K(G,n)$ space is a connected topological space $X$ such that $\\pi_n(X) = G$ and all other homotopy groups vanish. In the category of spaces homotopy equivalent to CW-complexes the $K(G,n)$ spaces are unique up to homotopy equivalence. Therefore sometimes we refer to \\emph{the} $K(G,n)$ space. \n\nIt is easy to construct a CW-complex that is a $K(G,n)$ space for any abelian group $G$ and integer $n$. Start with one 0-cell. Attach an $n$-cell for each generator of $G$ and an $(n+1)$-cell for each relation in the obvious way. The resulting space will have first nonzero homotopy group in dimension $n$, and it will be isomorphic to $G$. Unfortunately the higher homotopy groups are not necessarily zero since $S^n$ has highly nontrivial homotopy groups in dimensions $>n$, and we could not have killed them all when attaching the $(n+1)$-cells. Therefore we have to attach higher dimension cells in order to kill of all the higher homotopy groups. The resulting CW-complex will be infinite dimensional, and will be a $K(G,n)$ space.\n\nEven though it is easy to define and construct $K(G,n)$ spaces, the spaces do not seem to arise in nature. In fact, outside of $S^1, \\mathbb CP^\\infty$ and the infinite dimensional lens spaces, there are not many other natural examples. This makes it difficult to compute their cohomology groups. There is also a result that essentially says that all ``cohomological operations'' (which I will not define here) are somehow contained within the cohomology groups of $K(G,n)$ spaces, so these things are quite difficult to compute.\n\nWe will now use the Leray-Serre spectral sequence to compute the first few cohomology groups of $K(\\mathbb Z,3)$. We take the path space fibration $\\Omega K(\\mathbb Z,3) \\rightarrow PK(\\mathbb Z,3) \\rightarrow K(\\mathbb Z,3)$, but note that the loop space of a $K(\\mathbb Z,3)$ space is simply a $K(\\mathbb Z,2)$ space (i.e. $\\mathbb CP^\\infty$), and $PK(\\mathbb Z,3)$ is contractible. Therefore we have a fibration (up to homotopy) $\\mathbb CP^\\infty \\rightarrow \\pt \\rightarrow K(\\mathbb Z,3)$. \n\nRecall that the cohomology of topological spaces carries an algebra structure given by the cup product. The cohomological version of the Leray-Serre spectral sequence can be extended to take into account this extra structure. Without getting into the details let it be known that the algebra structure on the $E_2$ page coming from the cup product induces an algebra structure on the higher pages. The cohomology algebra of $\\mathbb CP^\\infty$ is isomorphic (as algebras) to the exterior product $\\Lambda(x)$ on one element $x$ of degree 2. \n\n\\unfinished\n\n\n\n\n\n\n\\subsection{$\\pi_4(S^3)$}\n\n\n\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "079b675b95d5751c8b75a79efe057b58a28dcac6", "size": 58081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "spectral-sequences/spectral-sequences.tex", "max_stars_repo_name": "mbrandonw/my-math-notes", "max_stars_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2017-04-20T15:25:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T03:01:32.000Z", "max_issues_repo_path": "spectral-sequences/spectral-sequences.tex", "max_issues_repo_name": "mbrandonw/my-math-notes", "max_issues_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spectral-sequences/spectral-sequences.tex", "max_forks_repo_name": "mbrandonw/my-math-notes", "max_forks_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-07-11T13:27:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-13T16:46:16.000Z", "avg_line_length": 117.8113590264, "max_line_length": 1131, "alphanum_fraction": 0.707718531, "num_tokens": 18108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6450072288593902}}
{"text": "\\section{Finish off the proof of $\\cHH^p$ excision, topological manifolds, fundamental classes}\n\\subsection{The end of the proof}\nLet's finish off the proof from last time. Suppose $A,B$ are closed in normal $X$. \\underline{Excision for $\\cHH^p$}:\n\\begin{equation*}\n\\xymatrix{\n\t\\varinjlim_{(W,Y)\\in\\mathcal{U}_A\\times\\mathcal{U}_B}H^p(W\\cup Y,Y)\\ar[rrr]^{\\cong,\\text{ ordinary excision}}\\ar[d]^{\\cong,\\text{ cofinality/surjectivity}} & & & \\varinjlim_{\\mathcal{U}_A\\times\\mathcal{U}_B}H^p(W,W\\cap Y)\\ar[d]^{\\cong,\\text{ cofinality, see below}}\\\\\n\t\\varinjlim_{(U,V)\\in\\mathcal{U}_{A\\cup B,B}}H^p(U,V)\\ar[rrr]\\ar@{=}[d] & & & \\varinjlim_{(U,V)\\in\\mathcal{U}_{A,A\\cap B}}H^p(U,V)\\ar@{=}[d]\\\\\n\t\\cHH^p(A\\cup B,B)\\ar[rrr] & & & \\cHH^p(A,A\\cap B)\n}\n\\end{equation*}\n\n$\\mathcal{U}_A\\times\\mathcal{U}_B\\to\\mathcal{U}_{A,A\\cap B}$ is cofinal since: start with $(U,V)\\supseteq(A,A\\cap B)$. Using normality, separate $B\\cap(X-V)\\subseteq T$ and $A\\subseteq S$. Take $W=U\\cap S$ and $Y=V\\cup T$. Then $A\\subseteq W\\subseteq U$ and $A\\cap B\\subseteq W\\cap Y=S\\cap V\\subseteq V$.\n\nThis means that $\\cHH^p$ satisfies excision, hence Mayer-Vietoris. Let's put this in the drawer for now.\n\\subsection{Topological manifolds + Poincar\\'{e} duality}\nyayyyyyyyyyyyyy finally\n\\subsubsection{Fundamental class and orientation local system}\n\\begin{definition}\nA \\emph{topological manifold} is a Hausdorff space $M$ such that for every $x\\in M$, there exists a neighborhood $U\\ni x$ that is homeomorphic to some Euclidean space $\\RR^n$. It's called an $n$-manifold if all $U$ are homeomorphic to $\\RR^n$ for the \\emph{same} $n$.\n\\end{definition}\n\\begin{example}\n$\\RR^n$, duh. $\\emptyset$ is an $n$-manifold for every $n$. The sphere $S^n$. The Grassmannian $\\mathrm{Gr}_k(\\RR^n)$, introduced in the beginning of the course. I don't know exactly what the dimension of this is, but you can figure it out. Also, $V_k(\\RR^n)$, and surfaces.\n\\end{example}\nThese things are the most interesting things to look at.\n\\begin{warning}\nWe assume the following.\n\\begin{enumerate}\n\\item There exists a countable basis.\n\\item There exists a good cover, i.e., all nonempty intersections are Euclidean as well (always true for differentiable manifolds because you can take geodesic neighborhoods, and in particular for the manifolds we listed above).\n\\end{enumerate}\n\\end{warning}\nThis is the context in which duality works.\n\\begin{definition}\nLet $X$ be any space, and let $a\\in X$. The local homology of $X$ at $a$ is the homology $H_\\ast(X,X-a)$. We're always working over a commutative ring.\n\\end{definition}\nFor example, $H_q(\\RR^n,\\RR^n-0)=\\begin{cases}\\text{free of rank }1 & q=n \\\\ 0 & q\\neq n\\end{cases}$. This means that local homology is picking out the characteristic feature of Euclidean space. Therefore we also have $H_q(M,M-a)=\\begin{cases}\\text{free of rank }1 & q=n \\\\ 0 & q\\neq n\\end{cases}$ for $n$-manifolds.\n\\begin{notation}\nLet $j_a:(M,\\emptyset)\\to (M,M-a)$ be the inclusion.\n\\end{notation}\n\\begin{definition}\nA fundamental class for $M$ (an $n$-manifold) is $[M]\\in H_n(M)$ such that for every $a\\in M$, the image of $[M]$ under $j_{a,\\ast}:H_n(M)\\to H_n(M,M-a)$ is a generator of $H_n(M,M-a)$.\n\\end{definition}\nThis is somehow trying to say that this class $[M]$ covers the whole manifold.\n\\begin{example}\nWhen does a space have a fundamental class?\n\\begin{center}\n\\begin{tabular}{c|c c c } \n \\hline\n  & $\\RR^2$ & $\\RP^2$ & $T^2$ \\\\ \n  \\hline\n $R=\\Z$ & no! & no! & yes! you did this for homework \\\\\n $R=\\Z/2\\Z$ & no! & yes! & yes!\n\\end{tabular}\n\\end{center}\nSomething about orientability and compactness seem to be involved.\n\\end{example}\nWhat do we have? \n\\begin{definition}\n$o_M=\\coprod_{a\\in M}H_n(M,M-a)$ as a set. This has a map $p:o_M\\to M$.\n\\end{definition}\n\\begin{construction}\nThis can be topologized in Euclidean neighborhoods. Let $U\\cong\\RR^n$ be an Euclidean neighborhood of $a$. I can always arrange so that $a$ corresponds to $0$. We have the open disk sitting inside the closed disk: $\\widetilde{D^n}\\subseteq D^n\\subseteq \\RR^n$ that corresponds to some open $V\\subseteq \\overline{V}\\subseteq U$. Let $x\\in V$. I have a diagram:\n\\begin{equation*}\n\\xymatrix{\n\tH_n(M,M-\\overline{V})\\ar[d] & & H_n(U,U-\\overline{V})\\ar[ll]^{\\text{ excision of }M-U}_{\\cong}\\ar[d]^\\cong & H_n(\\RR^n,\\RR^n-D^n)\\ar@{=}[l]\\ar[d]^{\\cong,\\text{ homotopy equivalence}}\\\\\n\tH_n(M,M-x) & & H_n(U,U-x)\\ar[ll] & H_n(\\RR^n,\\RR^n-0)\\ar@{=}[l]\n}\n\\end{equation*}\nHence $H_n(M,M-\\overline{V})\\cong H_n(M,M-x)$. Thus I can collect points in $o_M$ together when they come from the same class in $H_n(M,M-\\overline{V})$, so they form ``sheets''.\n\nI have a map $V\\times H_n(M,M-\\overline{V})\\to o_M|_{V}=p^{-1}(V)$ by sending $(x,c)\\mapsto (j_x)_\\ast(c)\\in H_n(M,M-x)$, and this map is bijective (that's what comes from excision). This LHS has a nice topology by letting $H_n(M,M-\\overline{V})$ be discrete. I'm topologizing $o_M$ as the weakest topology these generate.\n\\end{construction}\n``Have I been sufficiently obscure enough? This is not supposed to be a complicated point''. This $o_M\\to M$ is called the \\emph{orientation local system}, and is a covering space.\n\\begin{definition}\nA continuous map $p:E\\to B$ is a covering space if:\n\\begin{enumerate}\n\\item $p^{-1}(b)$ is discrete for all $b\\in B$.\n\\item For every $b$ there's a neighborhood $V$ and a map $p^{-1}(V)\\to p^{-1}(b)$ such that $p^{-1}(V)\\xrightarrow{\\cong}V\\times p^{-1}(b)$ is a homeomorphism.\n\\end{enumerate}\n\\end{definition}\nThat's exactly the way we topologized $o_M$. There's more structure though because $H_n(M,M-\\overline{V})$ is an $R$-module!\n\\begin{definition}\nA local system (of $R$-modules) $p:E\\to B$ is a covering space together with structure maps $E\\times_B E:=\\{(e,e^\\prime)|pe=pe^\\prime\\}\\xrightarrow{+} E$ and $z:B\\to E$ such that:\n\\begin{equation*}\n\\xymatrix{\n\tE\\times_B E\\ar[rr]^+\\ar[dr] & & E\\ar[dl] & R\\times E\\ar[l]\\\\\n\t & B\\ar@{=}[r]\\ar[ur] & B\\ar[u]^{z} & \n}\n\\end{equation*}\nmaking $p^{-1}(b)$ a $R$-module.\n\\end{definition}\nWe have $H_n(M)\\xrightarrow{j_x}H_n(M,M-x)$, which gives a \\emph{section} of $o_M$. If I have a covering space $p:E\\to B$, a section is a continuous map $s:B\\to E$ such that $ps=1_B$. Write $\\Gamma(E)$ to be the set of sections. If $E$ is a local system, this is an $R$-module. Hence $H_n(M)\\xrightarrow{j_x}H_n(M,M-x)$ gives a map $j:H_n(M)\\to \\Gamma(o_M)$. This is pretty cool because it's telling you about this high-dimensional homology of $M$ into something ``discrete''.\n\\begin{theorem}\nIf $M$ is compact then $j:H_n(M)\\to\\Gamma(o_M)$ is an isomorphism, and $H_q(M)=0$ for $q>n$.\n\\end{theorem}\nThis is case of Poincar\\'{e} duality actually because $\\Gamma(o_M)$ is somewhat like zero-dimensional cohomology. If this is trivial, like it is for a torus, so if the manifold is connected, then $\\Gamma(o_M)$ is just $R$.\n", "meta": {"hexsha": "fd158ca642824d01514666fce8310a81d96f5315", "size": 6805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-35-topological-manifolds.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-35-topological-manifolds.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-35-topological-manifolds.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": 70.1546391753, "max_line_length": 476, "alphanum_fraction": 0.6918442322, "num_tokens": 2353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.6450072230144458}}
{"text": "\\section{Task 4}\n\nThe attached program will map the function $\\symbol{92} x -> (x/(x-2.3))^3$ unto\nthe array $[1,..,753411]$ both sequanteially and using a CUDA kernel for doing\nit in parallel. Both runs are timed and the results are compared to verify that\nthe CPU and GPU are agreeing on the result. For all the runs I did the results\nwe're close enough to satisfy the above function.\n\nThe timing is done only for the calculation and not copying data to the graphics\ncards or allocating memory. The verification of the results is done using the\nfollowing check $\\text{abs}(cpu_t - gpu_t) < \\epsilon$. All test runs was run on\none of the compute machines we we're granted access to as part of the course.\n\n\\begin{table}\n    \\center\n    \\begin{tabular}{|c|c|c|}\n        \\hline\n        \\textbf{Array Size} & \\textbf{CPU Time} & \\textbf{GPU Time} \\\\\\hline\n           100 &    50 &  63 \\\\\n           200 &    90 &  65 \\\\\n           300 &    73 &  66 \\\\\n           400 &    82 &  65 \\\\\n           500 &    91 & 103 \\\\\n           600 &   130 & 107 \\\\\n           700 &   111 & 105 \\\\\n           800 &   120 &  80 \\\\\n           900 &   152 &  80 \\\\\n          1000 &   143 &  76 \\\\\n          1100 &   144 &  77 \\\\\n          1300 &   162 &  68 \\\\\n          1500 &   184 & 150 \\\\\n          2000 &   247 &  77 \\\\\n          3000 &   360 &  75 \\\\\n          5000 &   482 &  77 \\\\\n         10000 &  1122 &  95 \\\\\n         15000 &  1320 &  80 \\\\\n         50000 &  5657 & 149 \\\\\n        100000 &  8233 & 173 \\\\\n        150000 & 12266 & 244 \\\\\n        200000 & 16357 & 278 \\\\\n        250000 & 20409 & 341 \\\\\n        300000 & 24426 & 356 \\\\\n        350000 & 28524 & 434 \\\\\n        400000 & 32492 & 444 \\\\\n        500000 & 42428 & 578 \\\\\n        600000 & 48733 & 635 \\\\\n        700000 & 56853 & 747 \\\\\n        753411 & 61204 & 806 \\\\\\hline\n    \\end{tabular}\n    \\caption{The runtimes reported by the program, measured in microseconds.}\n    \\label{tab:times}\n\\end{table}\n\n\nThe timing results for different array sizes are shown in Table \\ref{tab:times}\nand shows that the CPU generally are only faster at very small array sizes.\nAccording to my measurements already between 100-200 elements, the GPU code runs\nfaster than the sequential CPU code. Furthermore the increase in compute time\nrises a lot faster for the CPU code compared to the GPU version. The reason the\nGPU is so much faster as the number of iterations increase is because of it's\nability to process 1024 different ``iterations'' of the sequential loop in\nparallel.\n\nSince the measurements are in microseconds on a time shared machine there was\nsome inaccuracies, the values in Table \\ref{tab:times} is the average of running\nthe program 5 times after each other.\n", "meta": {"hexsha": "6ab6f58739fe95e9b6f8d8de920bf86818643aa7", "size": 2708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment1/report/task4.tex", "max_stars_repo_name": "martinnj/PMPH2015", "max_stars_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignment1/report/task4.tex", "max_issues_repo_name": "martinnj/PMPH2015", "max_issues_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment1/report/task4.tex", "max_forks_repo_name": "martinnj/PMPH2015", "max_forks_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_forks_repo_licenses": ["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.4179104478, "max_line_length": 80, "alphanum_fraction": 0.6078286558, "num_tokens": 805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.6450072230144457}}
{"text": "\\section{Markov Model}\n\\label{sec:MarkovModel}\n\nThis model is designed to import a generic Markov chain as a RAVEN model.\nAs an example, the Markov chain of Fig.~\\ref{fig:markov} is translated in the OpenPSA as shown below:\n\n\\begin{figure}\n    \\centering\n    \\centerline{\\includegraphics[scale=0.5]{markov.pdf}} \n    \\caption{Example of continuous time Markov chain (source Wikipedia: https://en.wikipedia.org/wiki/Markov\\_chain).}\n    \\label{fig:markov}\n\\end{figure}\n\n\\begin{lstlisting}[style=XML,morekeywords={anAttribute},caption=Markov model input example., label=lst:Markov_InputExample]\n  <Models>\n    <ExternalModel name=\"markov\" subType=\"MarkovModel\">\n      <variables>initialState,finalState</variables>\n      <initState>initialState</initState>\n      <finState>finalState</finState>\n      <endTime>1000</endTime>\n      <state name=\"1\"> <!-- Bull market -->\n        <transition type=\"lambda\" value=\"0.02\" >2</transition>\n        <transition type=\"lambda\" value=\"0.005\">3</transition>\n      </state>\n      <state name=\"2\"> <!-- Bear market -->\n        <transition type=\"lambda\" value=\"0.3\">1</transition>\n        <transition type=\"lambda\" value=\"0.2\">3</transition>\n      </state>\n      <state name=\"3\"> <!-- Stagnant market -->\n        <transition type=\"lambda\" value=\"0.02\">1</transition>\n        <transition type=\"lambda\" value=\"0.4\" >2</transition>\n      </state>      \n    </ExternalModel>\n  </Models>\n\\end{lstlisting}\n\nAll the specifications of the Markov model are given in the \\xmlNode{ExternalModel} block. \nInside the \\xmlNode{ExternalModel} block, the XML nodes that belong to this model are:\n\\begin{itemize}\n  \\item  \\xmlNode{variables}, \\xmlDesc{string, required parameter}, a list containing the names of both the input and output variables of the model\n  \\item  \\xmlNode{initState}, \\xmlDesc{string, required parameter}, variable ID corresponding to initial state\n  \\item  \\xmlNode{finState}, \\xmlDesc{string, required parameter}, variable ID corresponding to final state\n  \\item  \\xmlNode{endTime}, \\xmlDesc{float, required parameter}, time horizon to evaluate Markov chain transition history\n  \\item  \\xmlNode{state}, specifies a single node; inside a \\xmlNode{state} all possible transitions OUT of this state must be specified\n                          in the \\xmlNode{transition} xml sub-nodes:\n\t  \\begin{itemize}\n\t  \t\\item \\xmlAttr{transition}, \\xmlDesc{required string attribute}, arrival state\n\t    \\item \\xmlAttr{type}, \\xmlDesc{required string attribute}, type of transition. Allowed transition types are: The ET of Fig.~\\ref{fig:ET} and defined in Listing~\\ref{lst:ETmodel} can be defined in the RAVEN input file as follows: lambda, tau, instant and unif (see below)\n\t    \\item \\xmlAttr{value}, \\xmlDesc{required string attribute}, value associated to the particular transition\n\t  \\end{itemize}\n\\end{itemize}\n\nThe following transition types are available:\n\\begin{itemize}\n  \\item lambda: classical continuous time Markov chain transition rate in $\\lambda$ form\n  \\item tau: classical continuous time Markov chain transition rate in the $\\tau = \\frac{1}{\\lambda}$ form\n  \\item instant: deterministic transition out of particular state; the exact transition time is provided in input\n  \\item unif: transition time is uniformly sampled between the two provided values in the \\xmlAttr{value} node\n\\end{itemize}\n\n\\subsection{Markov model reference tests}\n\\begin{itemize}\n\t\\item test\\_markovModel\\_2states\\_tau.xml\n\t\\item test\\_markovModel\\_2states.xml\n\t\\item test\\_markovModel\\_3states\\_complexTrans.xml\n\t\\item test\\_markovModel\\_3states\\_instantTrans.xml\n\t\\item test\\_markovModel\\_3states.xml\n\\end{itemize}\n", "meta": {"hexsha": "396b6aef6e1375ab7ce4137e2966bac9bc79914e", "size": 3637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "plugins/PRAplugin/doc/include/MarkovModel.tex", "max_stars_repo_name": "sonatsen/raven", "max_stars_repo_head_hexsha": "30764491e7ecaa16de2a4e0ddab3bc9e169e5f95", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-11T15:59:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-08T18:23:57.000Z", "max_issues_repo_path": "plugins/PRAplugin/doc/include/MarkovModel.tex", "max_issues_repo_name": "sonatsen/raven", "max_issues_repo_head_hexsha": "30764491e7ecaa16de2a4e0ddab3bc9e169e5f95", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-03-27T13:06:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-27T13:06:00.000Z", "max_forks_repo_path": "plugins/PRAplugin/doc/include/MarkovModel.tex", "max_forks_repo_name": "sonatsen/raven", "max_forks_repo_head_hexsha": "30764491e7ecaa16de2a4e0ddab3bc9e169e5f95", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-08-29T16:09:13.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-29T16:09:13.000Z", "avg_line_length": 52.7101449275, "max_line_length": 275, "alphanum_fraction": 0.7291723948, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095495, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6450072217704447}}
{"text": "\\subsection{Edge crack in tension}\n\n\\paragraph{}\nConsider a plate with an edge crack loaded in tension $\\sigma=1N/m^2$ over the top and the bottom edges.\nThe geometry, loading and boundary conditions are shown in Fig.~\\ref{iso_fig:edge_crack_geo_bc}.\nIn the figure, $L=2m$ and $H=1m$.\nThe reference mode \\RN{1} SIF is given by:\n    \\begin{equation}\n        K_1 = F\\left(\n            \\frac{a}{H}\n            \\sigma \\sqrt{\\pi a}\n        \\label{iso_eq:edge_crack_k1}\n        \\right)\n    \\end{equation}\nwhere $a$ is the crack length, $H$ is the plate width, and $F(a/H)$ is an empirical function given by (for $a/H \\leq 0.6$)\n    \\begin{equation}\n        F\\left( \\frac{a}{H} \\right) =\n            1.12 - 0.231 \\left( \\frac{a}{H} \\right) +\n            10.55\\left( \\frac{a}{H} \\right)^2 -\n            27.72\\left( \\frac{a}{H} \\right)^3 +\n            30.39\\left( \\frac{a}{H} \\right)^4\n    \\end{equation}\n\n    \\begin{figure}\n        \\centering\n        \\scalebox{0.4}{\n            \\includegraphics{isogeometric_sbfem/images/edge_crack_geo_bc.eps}\n        }\n        \\caption{Plate with an edge crack under tension}\n        \\label{iso_fig:edge_crack_geo_bc}\n    \\end{figure}\n\n\\paragraph{}\nThe convergence of the mode \\RN{1} SIF and the T-stress with the mesh size and the order of the NURBS basis function is illustrated in Tab.~\\ref{iso_tab:edge_crack_res}.\nIt can be seen that decreasing the mesh size and increasing the order of the NURBS basis function, the numerically obtained SIF and the T-stress converge.\n\\begin{table}\n    \\caption{Convergence of the mode \\RN{1} SIF and T-stress for an edge crack in tension}\n    \\label{iso_tab:edge_crack_res}\n    \\begin{tabularx}{\\textwidth}{XXXXXXX}\n        \\toprule\n            Total    &   \\multicolumn{2}{c}{NURBS $p=2$} &\\multicolumn{2}{c}{NURBS $p=4$} &\\multicolumn{2}{c}{NURBS $p=6$}\\\\\n            \\cmidrule{2-7}\n            DOF      &   $K_1$   &   T-stress            &$K_1$   &   T-stress            &$K_1$   &   T-stress           \\\\\n            \\cmidrule{1-1} \\cmidrule{2-3} \\cmidrule{4-5} \\cmidrule{6-7}\n            62       &   2.7011  &   -0.4137             &2.6647  &-0.4170                &        &                      \\\\\n            98       &   2.7632  &   -0.4210             &2.8343  &-0.4216                &2.8335  &-0.4217               \\\\\n            170      &   2.8028  &   -0.4216             &2.8252  &-0.4217                &2.8245  &-0.4217               \\\\\n            329      &   2.8264  &   -0.4217             &2.8247  &-0.4217                &2.8246  &-0.4217               \\\\\n            Eq.~\\ref{iso_eq:edge_crack_k1} & 2.8264 & - & & & & \\\\\n        \\bottomrule\n        \\end{tabularx}\n\\end{table}\n\n", "meta": {"hexsha": "0b701ea3a6abc26f501ad6b9082ce55b62b31a4a", "size": 2673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/ex_edge_crack.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/ex_edge_crack.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/ex_edge_crack.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.5, "max_line_length": 169, "alphanum_fraction": 0.5342312009, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6449885786753285}}
{"text": "\\documentclass{article}\n\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\\usepackage{amstext}\n\\usepackage{graphicx}\n\n\\title{\\textbf{Extended Kalman Filter for Fixed-Wing Aircraft Dynamics}}\n\\author{\\textbf{Ahmed M. Hassan}\\thanks{am.hassan89@gmail.com}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nThe goal of this project is to implement an extended Kalman filter (EKF) to estimate\na fixed-wing aicraft state vector from noisy sensor measurments. \nThe first iteration of this project will be focused only on the longitudinal dynamics.\n   \n\\section{Aircraft Model}\nThe nonlinear longitudinal dynamics for conventional fixed-wing aircraft can be written as follows \\cite{Nelson, Stevens-Lewis}\n\\begin{equation}\\label{Eq:Nonlinear_sys}\n    \\begin{split}\n        \\dot{U} &= -Q W - g \\sin{\\theta} + \\frac{X}{m}\\\\\n        \\dot{W} &= Q U + g \\cos{\\theta} + \\frac{Z}{m}\\\\\n        \\dot{Q} &= \\frac{M}{I_{yy}}\\\\\n        \\dot{\\theta} &= Q\n    \\end{split}\n\\end{equation}\nThe forces and moments can be broken down as follows\n\\begin{equation}\n    \\begin{split}\n        X &= q S \\biggl(C_X(\\alpha) + \\frac{\\bar{c}}{2 V_T} C_{X_Q} Q + C_{X_{\\delta_e}} \\delta_e\\biggr) +\n        X_{t_0} + X_{\\delta_t} \\delta_t\\\\\n        Z &= q S \\biggl(C_Z(\\alpha) + \\frac{\\bar{c}}{2 V_T} C_{Z_Q} Q + C_{Z_{\\delta_e}} \\delta_e\\biggr)\\\\\n        M &= q S \\bar{c} \\biggl(C_M(\\alpha) + \\frac{\\bar{c}}{2 V_T} C_{M_Q} Q + C_{M_{\\delta_e}} \\delta_e \\biggr)\n    \\end{split}\n\\end{equation}\nConsidering a trim condition in a cruise level flight, the nonlinear system \\ref{Eq:Nonlinear_sys} \ncan be further simplified to be on the following from\n%This nonlinear model is very simple and has only very few nonlinear terms-need to have a more sophisticated model later\n\\begin{equation}\\label{Eq:Nonlinear_sys_cruise}\n    \\begin{split}\n        \\dot{U} &= -Q W - g \\cos{\\theta_0} \\Delta \\theta+ X_U \\Delta U + X_W \\Delta W +\n                 X_{\\delta_e} \\delta_e + X_{\\delta_t} \\delta_t\\\\\n        \\dot{W} &= Q U - g \\sin{\\theta_0} \\Delta \\theta + Z_U \\Delta U + Z_W \\Delta W + Z_{\\delta_e} \\delta_e\\\\\n        \\dot{Q} &= M_U \\Delta U + M_W \\Delta W + M_Q Q + M_{\\delta_e} \\delta_e + M_{\\delta_t} \\delta_t\\\\\n        \\dot{\\theta} &= Q\n    \\end{split}\n\\end{equation}\n\nThe nonlinear system \\ref{Eq:Nonlinear_sys} can be linearized and\nwritten in a standard linear system form as follows \\cite{Nelson, Stevens-Lewis}\n\\begin{equation} \\label{Eq:Linearized_sys}\n    \\begin{bmatrix}\n    \\dot{U} \\\\\n    \\dot{W} \\\\\n    \\dot{Q} \\\\\n    \\dot{\\theta} \\\\ \t\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    X_u & X_w & 0 & -g \\cos{\\theta_0}\\\\\n    Z_u & Z_w & U_0 & -g \\sin{\\theta_0}\\\\\n    M_u & M_w & M_q & 0\\\\\n    0 & 0 & 1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    U \\\\\n    W \\\\\n    Q \\\\\n    \\theta \\\\ \t\n    \\end{bmatrix}\n    +\n    \\begin{bmatrix}\n    X_{\\delta_e} & X_{\\delta_t} \\\\\n    Z_{\\delta_e} & 0 \\\\\n    M_{\\delta_e} & M_{\\delta_t} \\\\\n    0 & 0\\\\ \t\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    {\\delta_e} \\\\\n    {\\delta_t}  \t\n    \\end{bmatrix}\n\\end{equation}\n\nIn this project we will consider the longitudinal model of the aircraft \"DELTA\" given in \\cite[PP. 561--563]{Mclean}\nwhose parameters are given as follows (at $U_0 = 75~ m/s$ and $\\theta_0 = 2.7 ^\\circ$)\n\\begin{equation}\\label{Eq:DELTA_Params}\n    \\begin{split}\n        m &= 300000 kg\\\\\n        X_U &= -0.02\\\\\n        X_W &= 0.1\\\\\n        Z_U &= -0.23\\\\\n        Z_W &= -0.634\\\\\n        M_U &= -2.55*10^{-5}\\\\\n        M_W &= -0.005\\\\\n        M_Q &= -0.61\\\\\n        X_{\\delta_e} &= 0.14\\\\\n        Z_{\\delta_e} &= -2.9\\\\\n        M_{\\delta_e} &= -0.64\\\\\n        X_{\\delta_t} &= 1.56\\\\\n        M_{\\delta_t} &= 0.0054\\\\\n    \\end{split}\n\\end{equation}\nwhere $\\delta_t$ is considered to be from the trim thrust. \nAs such, $\\delta_t$ is allowed the between $1$ and $-0.56$ \\cite{Hassan2016_JAST}.  \n\n\\section{Extended Kalman Filter Equations}\nIn this section, we will summarize the continous-discrete EKF equations as presented by Crassidis and Junkins \\cite{Junkins}.\nThe EKF considers a nonlinear system with process and measurment noise as follows\n\\begin{equation}\n    \\begin{split}\n        \\dot{\\bm{x}}(t) &= \\bm{f}(\\bm{x}(t), \\bm{u}(t), t) + G(t) \\bm{w}(t),~ \\bm{w}(t) \\sim N(0, Q(t))\\\\\n        \\widetilde{\\bm{y}}_k &= \\bm{h}(\\bm{x}_k) + \\bm{v}_k,~ \\bm{v}_k \\sim N(0, R_k)\n    \\end{split}\n\\end{equation}\nwhere the overscript symbol $\\widetilde{}$ denotes a measured quantity and the subscript symbol $_k$ denotes the value at time step $k$. \nAlso, $\\bm{x}$ is the state vector, $\\bm{u}$ is the control input vector, $\\bm{w}$ is the process noise vector, and $\\bm{v}$ is the measurment noise vector.\n\nThe EKF can be initialized as follows\n\\begin{equation}\n    \\begin{split}\n        \\hat{\\bm{x}}(t_0) &= \\hat{\\bm{x}}_0\\\\\n        P_0 &= E\\{\\widetilde{\\bm{x}}(t_0) \\widetilde{\\bm{x}}^T(t_0)\\}\n    \\end{split}\n\\end{equation}\nwhere the overscript symbol $\\hat{}$ denotes an estimated quantity and $P$ is the state estimate error covariance matrix.\n\nThe Kalman gain, updated state, and updated state estimate error covariance can be obtained as follows\n\\begin{equation}\n    \\begin{split}\n        K_k &= P_k^- C_k^T \\biggl(C_k P_k^- C_k^T + R_k\\biggr)^{-1}\\\\\n        C_k &\\equiv \\frac{\\partial \\bm{h}}{\\partial \\bm{x}}\\bigg|_{{\\hat{\\bm{x}}}_k^-}\\\\\n        \\hat{\\bm{x}}_k^+ &= \\hat{\\bm{x}}_k^- + K_k \\biggl(\\widetilde{\\bm{y}}_k - \\bm{h}(\\hat{\\bm{x}}_k^-)\\biggr)\\\\\n        P_k^+ &= \\biggl(I - K_k C_k\\biggr) P_k^-\n    \\end{split}\n\\end{equation}\nwhere the superscript symbol $^-$ denotes the state/covariance after the propagation step but before the update step. \nOn the other hand, the superscript symbol $^+$ denotes the state/covariance after the update step.\n\nFinally, the state and state estimate error covariance can be propagated as follows\n\\begin{equation}\n    \\begin{split}\n        \\dot{\\bm{x}}(t) &= \\bm{f}(\\bm{x}(t), \\bm{u}(t), t)\\\\\n        \\dot{P}(t) &= A(t) P(t) + P(t) A^T(t) + G(t) Q(t) G^T(t)\\\\\n        A(t) &\\equiv \\frac{\\partial \\bm{f}}{\\partial \\bm{x}}\\bigg|_{\\hat{\\bm{x}}(t), \\bm{u}(t)}\n    \\end{split}\n\\end{equation}\n\n\\section{Algorithm Structure}\nFigure \\ref{Fig:EKF_Algorithm_Sketch} shows a simple sketch of the algorithm structure. \nThere are two classes implemented in this project: \\textit{LongDynamics} and \\textit{EKF}. \nThe first one encapsulates the nonlinear dynamic system equations for the fixed-wing aircraft longitudinal dynamics, \nwhereas the second one encapsulates the EKF algorithm implementation. The \\textit{LongDynamics} class relies on an external \npackage (odeint \\cite{odeint_website}) for time propagation (numerical integration). \nIn addition, there are some helper functions to load the dataset and compute the root mean square error.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{EKF_Algorithm.png}\n    \\caption{EKF algorithm structure.}\n    \\label{Fig:EKF_Algorithm_Sketch}\n\\end{figure}\n\n\\section{Results}\nFigures \\ref{Fig:Results_AoA} and \\ref{Fig:Results_pitchRate} show the estimated angle of attack and pitch rate versus the measured and true ones.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{results_AoA.png}\n    \\caption{A comparison between the estiamted, measured and true angle of attack.}\n    \\label{Fig:Results_AoA}\n\\end{figure}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{results_q.png}\n    \\caption{A comparison between the estiamted, measured and true ptich rate.}\n    \\label{Fig:Results_pitchRate}\n\\end{figure}\n\n\\bibliographystyle{unsrt}\n\\bibliography{ref}\n\\end{document}", "meta": {"hexsha": "03d1009680d6e3ba33fc9d36db159d184af41428", "size": 7587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/EKF_for_Aircraft_Dynamics.tex", "max_stars_repo_name": "ammhassan/EKF_for_Aircraft_Dynamics-", "max_stars_repo_head_hexsha": "aa6a76cfae9c4f59a141efaaebd2b550207e7a00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-21T14:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-12T14:34:59.000Z", "max_issues_repo_path": "doc/EKF_for_Aircraft_Dynamics.tex", "max_issues_repo_name": "ammhassan/EKF_for_Aircraft_Dynamics-", "max_issues_repo_head_hexsha": "aa6a76cfae9c4f59a141efaaebd2b550207e7a00", "max_issues_repo_licenses": ["MIT"], "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/EKF_for_Aircraft_Dynamics.tex", "max_forks_repo_name": "ammhassan/EKF_for_Aircraft_Dynamics-", "max_forks_repo_head_hexsha": "aa6a76cfae9c4f59a141efaaebd2b550207e7a00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-21T04:23:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-21T04:23:17.000Z", "avg_line_length": 41.0108108108, "max_line_length": 156, "alphanum_fraction": 0.6495320944, "num_tokens": 2545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749422, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.644988572951362}}
{"text": "\\subsection{Bonus: Topology via Calculus and de Rham Cohomology}\r\nIf $\\underline{F}$ is a vector field with simply connected domain, we know that $\\nabla\\times\\underline{F}=0$ implies that $\\underline{F}$ is conservative.\r\nWe can conversely use it to show that certain domain is not simply connected.\r\n\\begin{example}\r\n    Suppose $\\mathbb R\\setminus\\{(0,0,z):z\\in\\mathbb R\\}$ is simply connected.\r\n    Then consider the vector field\r\n    $$\\underline{F}=\\frac{1}{x^2+y^2}(-y,x,0)$$\r\n    So it is well defined and smooth on the said domain.\r\n    It also has zero curl.\r\n    So exists scalar function $f$ such that $\\underline{F}=\\nabla f$, hence the line integral of it along any loop is zero.\r\n    However, let us consider the curve in the $x-y$ plane:\r\n    $$C:[0,2\\pi]\\ni t\\mapsto\\begin{pmatrix}\r\n        \\cos t\\\\\r\n        \\sin t\\\\\r\n        0\r\n    \\end{pmatrix}$$\r\n    Then\r\n    $$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}=2\\pi\\neq 0$$\r\n    Contradiction.\r\n\\end{example}", "meta": {"hexsha": "63492eb67b284113e8976458711671c3d9e4bacb", "size": 978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/top.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": "4/top.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": "4/top.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": 48.9, "max_line_length": 156, "alphanum_fraction": 0.6615541922, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.6449885634430718}}
{"text": "\\documentclass{article}\n\\usepackage[margin = .7in]{geometry}\n\\usepackage[dvipdfmx]{graphicx}\n\\usepackage{listings}\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\lstset{%\n  language={python},\n  basicstyle={\\small},%\n  identifierstyle={\\small},%\n  commentstyle={\\small\\itshape},%\n  keywordstyle={\\small\\bfseries},%\n  ndkeywordstyle={\\small},%\n  stringstyle={\\small\\ttfamily},\n  frame={tb},\n  breaklines=true,\n  columns=[l]{fullflexible},%\n  numbers=left,%\n  xrightmargin=0zw,%\n  xleftmargin=3zw,%\n  numberstyle={\\scriptsize},%\n  stepnumber=1,\n  numbersep=1zw,%\n  lineskip=-0.5ex%\n}\n\n\\begin{document}\n\\title{STAT6011/7611/6111/3317 \\\\ \nCOMPUTATIONAL STATISTICS (2016 Fall)\\\\\nMidterm Examination}\n\\author{Kei Ikegami (u3535947)}\n\\maketitle\n\n\\section{}\nThe code is below.\n\\lstinputlisting[caption=code]{allcode.py}\nThe result is .\n\\par\nThe main idea of this paper is the below identity.\n\\begin{align*}\n\t{\\rm log} \\left\\{ p({\\bf y}) \\right\\} &= {\\rm log} \\left\\{ \\frac{z({\\bf y}| t=1)}{z({\\bf y} | t=0)} \\right\\} = \\left[ {\\rm log}\\left\\{z({\\bf y} | t)\\right\\} \\right]_0^1 = \\int_0^1 \\frac{1}{z({\\bf y} | t)} \\frac{\\mathrm{d}}{\\mathrm{d} t} z({\\bf y} | t) \\mathrm{d}t\\\\\n\t&= \\int_0^1 \\frac{1}{z({\\bf y} | t)} \\left( \\int_{\\theta} \\frac{\\mathrm{d}}{\\mathrm{d}t} p({\\bf y}\\theta)^t p(\\theta) \\mathrm{\\theta} \\right) \\mathrm{d}t = \\int_0^1 \\frac{1}{z({\\bf y} | t)} \\left( \\int_{\\theta} {\\rm log} \\left\\{ p({\\bf y} | \\theta) \\right\\} p({\\bf y} | \\theta)^t p(\\theta) \\mathrm{d}\\theta \\right) \\mathrm{d} t\\\\\n\t&= \\int_0^1 \\int_{\\theta} {\\rm log} \\left\\{ p({\\bf y} | \\theta) \\right\\} \\frac{p({\\bf y} | \\theta)^t p(\\theta)}{z({\\bf y} | t)} \\mathrm{d} \\theta \\mathrm{d} t = \\int_0^1 \\int_{\\theta} {\\rm log} \\left\\{ p({\\bf y} | \\theta) \\right\\} p_t(\\theta | {\\bf y}) \\mathrm{d} \\theta \\mathrm{d} t\\\\\n\t&= \\int_0^1 {\\rm E}_{\\theta | {\\bf y}, t} \\left[ {\\rm log}\\left\\{ p({\\bf y} | \\theta) \\right\\} \\right] \\mathrm{d}t\n\\end{align*}\n\nThis identity implies that we can approximate the the marginal loglikelihood specific to a model by a numerical integration of the expectation of a loglikelihood fixed at some t. This expectation is gotten by MCMC method, i.e. Gibbs sampling in this example. Given each prior, the full conditional distribution of each parameter is as follows. \n\n\\begin{align*}\n\tp(\\alpha | {\\bf y}, {\\bf x}, t, \\beta, \\sigma^2) &\\propto p({\\bf y} | \\alpha, \\beta, \\sigma^2)^t p(\\alpha) \\\\\n\t\t&\\propto \\exp \\left( - \\frac{1}{2\\sigma^2} \\left( t \\sum_i (y_i - \\beta(x_i - \\bar{x}))^2 - 2t \\alpha \\sum_i (y_i - \\beta(x_i - \\bar{x}))  + \\alpha^2 Nt \\right) + \\frac{1}{2\\sigma_{\\alpha}^2} (\\alpha^2 - 2\\mu_{alpha} \\alpha + \\mu_{\\alpha}^2)\\right)\\\\\n\t\t&\\propto \\exp \\left( -\\frac{\\sigma_{\\alpha}^2 Nt + \\sigma^2}{\\sigma^2 \\sigma_{\\alpha}^2} \\left( \\alpha - \\frac{\\sigma_{\\alpha}^2 t \\sum_i (y_i - \\beta(x_i -\\bar{x})) + \\sigma^2 \\mu_{\\alpha}}{\\sigma_{\\alpha}^2 Nt + \\sigma^2} \\right)^2 \\right)\\\\\n\tp(\\beta | {\\bf y}, {\\bf x}, t, \\alpha, \\sigma^2) &\\propto p({\\bf y} | \\alpha, \\beta, \\sigma^2)^t p(\\beta)\\\\\n\t\t&\\propto \\exp \\left( - \\left( \\frac{1}{2\\sigma^2} t\\sum_i (y_i - \\alpha - \\beta(x_i -\\bar{x}))^2 + \\frac{1}{2\\sigma_{\\beta}^2} (\\beta - \\mu_{\\beta})^2 \\right)\\right)\\\\\n\t\t&\\propto \\exp \\left( - \\left( \\frac{\\sigma_{\\beta}^2 t \\sum_i (x_i - \\bar{x})^2 + \\sigma^2}{2\\sigma^2 \\sigma_{\\beta}^2} \\beta^2 - \\frac{\\sigma_{\\beta}^2 t \\sum_i (x_i- \\bar{x})(y_i - \\alpha) + \\sigma^2 \\mu_{\\beta}}{\\sigma^2 \\sigma_{\\beta}^2} \\beta \\right) \\right)\\\\\n\t\t&\\propto \\exp \\left( - \\frac{\\sigma_{\\beta}^2 t \\sum_i (x_i - \\bar{x})^2 + \\sigma^2}{2\\sigma^2 \\sigma_{\\beta}^2} \\left( \\beta - \\frac{\\sigma_{\\beta}^2 t \\sum_i (x_i- \\bar{x})(y_i - \\alpha) + \\sigma^2 \\mu_{\\beta}}{\\sigma_{\\beta}^2 t \\sum_i (x_i - \\bar{x})^2 + \\sigma^2}\\right)^2 \\right)\\\\\n\tp(\\sigma^2 | {\\bf y}, {\\bf x}, t, \\alpha, \\beta) &\\propto p({\\bf y} | \\alpha, \\beta, \\sigma^2)^t p(\\sigma^2) \\\\\n\t\t&= \\left\\{ \\Pi_{i=1}^{N} \\left( \\frac{1}{\\sqrt{2\\pi \\sigma^2}} \\exp \\left( - \\frac{(y_i - \\alpha - \\beta(x_i - \\bar{x}))^2}{2\\sigma^2}\\right)^t \\right) \\right\\} \\exp \\left( -\\frac{1}{b \\sigma^2} \\right) \\frac{1}{\\gamma(a)} b^{-a} (\\sigma^2)^{-(a + 1)}\\\\\n\t\t&\\propto (\\sigma^2)^{-\\frac{Nt}{2} + a + 1} \\exp \\left( - \\frac{bt \\sum_i (y_i - \\alpha - \\beta(x_i -\\bar{x}))^2 + 2}{2b\\sigma^2} \\right)\\\\\n\\end{align*}\nBy the above, $\\alpha$'s full conditional distribution is $N \\left(\\frac{\\sigma_{\\alpha}^2 t \\sum_i (y_i - \\beta(x_i -\\bar{x})) + \\sigma^2 \\mu_{\\alpha}}{\\sigma_{\\alpha}^2 Nt + \\sigma^2}, \\frac{\\sigma^2 \\sigma_{\\alpha}^2}{\\sigma_{\\alpha}^2 Nt + \\sigma^2} \\right)$. $\\beta$'s full conditional distribution is $N\\left( \\frac{\\sigma_{\\beta}^2 t \\sum_i (x_i- \\bar{x})(y_i - \\alpha) + \\sigma^2 \\mu_{\\beta}}{\\sigma_{\\beta}^2 t \\sum_i (x_i - \\bar{x})^2 + \\sigma^2}, \\frac{\\sigma^2 \\sigma_{\\beta}^2}{\\sigma_{\\beta}^2 t \\sum_i (x_i - \\bar{x})^2 + \\sigma^2} \\right)$. $\\sigma^2$ is $IG\\left( \\frac{Nt}{2} + a, \\frac{2b}{bt \\sum_i (y_i - \\alpha - \\beta(x_i -\\bar{x}))^2 + 2} \\right)$. \n\\par\nThe above code took about 4 hours. This is due to the long iteration of Gibbs sampling, and I check the MCMC converge very fast in this case. Then I wonder why the authors take such a long chain. If I use some efficient MCMC packages or write the more matrix based code, they must shorten the time. It is, however, better to write a readable code because this is just an assignment.\n\\par\nAnyway, the computation of marginal likelihood is so hard that a lot of tools and methods have been invented. In this example, the number of regression parameters are just three including the precision for each model. Then the model selection problem in high dimension must be a terrible and challenging task.\n\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\n\n\n\n\n", "meta": {"hexsha": "006cbd5ee7ae43d54d3fde01f986e894f23c89db", "size": 5655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "midterm-report.tex", "max_stars_repo_name": "keiikegami/midtermtest", "max_stars_repo_head_hexsha": "95415c30a1be855d56f24e795e5f3eb9113c1b2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "midterm-report.tex", "max_issues_repo_name": "keiikegami/midtermtest", "max_issues_repo_head_hexsha": "95415c30a1be855d56f24e795e5f3eb9113c1b2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "midterm-report.tex", "max_forks_repo_name": "keiikegami/midtermtest", "max_forks_repo_head_hexsha": "95415c30a1be855d56f24e795e5f3eb9113c1b2f", "max_forks_repo_licenses": ["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.1595744681, "max_line_length": 673, "alphanum_fraction": 0.6217506631, "num_tokens": 2251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.6449885580039899}}
{"text": "\\section{First-Order ODEs}\r\n\\begin{definition}\r\n    An Ordinary Differential Equation (ODE) involves differentiable functions of $1$ variable, while Partial Differential Equations (PDEs) involve higher dimensional functions.\\\\\r\n    The order of a differential equations is the highest order of derivative in the equation.\r\n\\end{definition}\r\n\\subsection{First-Order Linear ODEs}\r\nAn linear ODE is, obviously, a linear ODE.\r\n\\begin{example}\r\n    $x^3y+y^\\prime=0$ is a first-order linear ODE.\r\n\\end{example}\r\n\\subsubsection{Prelude: Exponential Function}\r\nConsider the function $f(x)=a^x,a>1$, then $f^\\prime(x)=a^x\\lambda$ for some $\\lambda>0$.\r\n\\begin{definition}\r\n    We define $\\exp(x)$ to be the solution to the differential equation $f^\\prime=f$ with $f(0)=1$.\r\n\\end{definition}\r\nBy definition we have $(e^h-1)/h\\to 1$ as $h\\to 0$.\r\n\\begin{definition}\r\n    One can show that $\\exp$ is strictly increasing, therefore injective.\r\n    So we can define $\\ln$ to be the inverse function of $\\exp$.\r\n\\end{definition}\r\nSo we have $\\lambda=\\ln a$.\\\\\r\nThe exponential function plays a central role in differential equations because it is the eigenfunction (i.e. a function that is only scaled under the operator) of the differential operator.\\\\\r\nWe obviously have $\\mathrm de^{\\lambda x}/\\mathrm dx=\\lambda e^{\\lambda x}$, so it is indeed an eigenfunction.\r\nActually, all the eigenfunctions of the differential operator is of the form $Ce^{\\lambda x}$ for some constant $C$ and $\\lambda$.\r\nSo the behaviour of a differential equation can be somehow characterized by exponential functions.\r\n\\subsubsection{Rules of Linear ODEs}\r\nFirstly, any homogeneous linear ODEs with constant coefficients (e.g. $af^\\prime+bf=0, a,b\\in\\mathbb R$) have solutions of the form $Ce^{\\lambda x}$ where $\\lambda$ can be complex.\\\\\r\nSecondly, for linear homogeneous ODEs, any contant multiple of a solution is also a solution.\\\\\r\nThirdly, an $n^{th}$ order linear ODE has only $n$ linearly independent solutions.\\\\\r\nLastly, an $n^{th}$ order ODE requires $n$ initial/boundary conditions to uniquely determine it.\r\n\\subsubsection{Forced (inhomogeneous) First Order ODEs with Constant Coefficient}\r\nCase 1: Constant forcing.\r\nFor example, $5y'-3y=10$.\r\nWe will follow the following steps:\\\\\r\n1. Find steady (equilibrium) solution where $y^\\prime=0$.\r\nIn this case, it is $y=y_p=-10/3$.\\\\\r\n2. Then, the general solution is in the form $y=y_p+y_c$ where $y_c$ is a complementary solution, any solution to the differential equation removing the inhomogeneous part.\r\nin this case, $5y'-3y=0$.\\\\\r\n3. Solve for $y_c$.\r\nIn this case, $y_c=Ae^{3x/5}$\\\\\r\n4. Plug it back: $y=Ae^{3x/5}-10/3$\\\\\r\nHere $A$ is any constant.\r\nThis way works since linearity of the equation granted that any two solutions to it must differ by a complementary solution.\\\\\r\nCase 2: Eigenfunction forcing.\\\\\r\nSuppose an isotope A decays into isotope B in a way that it is proportional to $a$, the number of nuclei of that isotope A.\r\nWhile B decays into isotope C, its rate is proportional to $b$, the numbers of nuclei of isotope B.\r\nSo $\\dot{a}=-k_aa\\implies a=a_0e^{-k_at}$ for some constants $k_a,a_0$.\r\nNow $\\dot{b}=-k_bb+k_aa$ for some constant $k_b$, so\r\n$$\\dot{b}+k_bb=k_aa_0e^{-k_at}$$\r\nThis is an example where the forcing term is the eigenfunction of $\\mathrm d/\\mathrm dt$.\r\nWe can guess a particular solution\r\n$$b_p=\\frac{k_a}{k_b-k_a}e^{-k_at}$$\r\nif $k_b\\neq k_a$.\r\nSo the general solution is\r\n$$b=\\frac{k_a}{k_b-k_a}a_0e^{-k_at}+De^{-k_bt}$$\r\nIf $b(t)=0$, then\r\n$$b=\\frac{k_a}{k_b-k_a}a_0(e^{-k_at}-e^{-k_bt})$$\r\nSo\r\n$$\\frac{b}{a}=\\frac{k_a}{k_b-k_a}(1-e^{(k_a-k_b)t})$$\r\nwe can solve it for $t$ and this solution allows us to date rocks etc by measuring the ratio of isotopes.\r\n\\subsubsection{First Order ODEs with Non-constant Coefficient}\r\nThe general form of these sort of equations are in the form $a(x)y^\\prime+b(x)y=c(x)$ or the form $y^\\prime+p(x)y=q(x)$ (given that $\\forall x,a(x)\\neq 0$).\r\nWe can solve it by integrating factor\r\n$$\\mu(x)=\\exp\\left(\\int p\\,\\mathrm dx\\right)$$\r\nSo\r\n$$(\\mu y)^\\prime=\\mu q\\implies \\mu y=\\int \\mu q\\,\\mathrm dx\\implies y=\\frac{1}{\\mu}\\int\\mu q\\,\\mathrm dx$$\r\n\\subsection{Intermezzo: Discrete Equations}\r\nSometimes it is useful to consider functions evaluated at a discrete set of points, which could be useful to numerical integration and series solution.\r\n\\subsubsection{Numerical Integration}\r\nOne approximation to $\\mathrm dy/\\mathrm dx$ at $x=x_n$ can be written as\r\n$$\\left.\\frac{\\mathrm dy}{\\mathrm dx}\\right|_{y_n}\\approx \\frac{y_{n+1}-y_n}{h}$$\r\nThis is called the forward Euler approximation.\r\n\\begin{example}\r\n    $5y'-3y=0$ again.\r\n    Then it is approximately equal to the discrete equation\r\n    $$5y_{n+1}-5y_n-3ny_n=0\\implies y_{n+1}=\\left(1+\\frac{3h}{5}\\right)y_n$$\r\n    We can iterate it to approximate the solution given an initial value.\r\n    This is the example of a recurrence relation.\r\n    We can actually solve this by\r\n    $$y_{n}=\\left(1+\\frac{3h}{5}\\right)^ny_0$$\r\n    Which can approximate the true solution pretty well if we let $h\\to 0,n\\to\\infty$.\r\n    Note that in this case, for finite value of $n$, $y_n$ is always less than the actual value of solution at that point.\r\n\\end{example}\r\n\\subsubsection{Series Solution}\r\nA powerful way to solve DEs is to seek for solutions in the form of an infinite power series.\r\nLet\r\n$$y(x)=\\sum_{n=0}^\\infty a_nx^n$$\r\nwe can plug it in the differential equations to solve for $a_n$.\r\n\\begin{example}\r\n    $5y'-3y=0$ yet again.\r\n    Plug it in and we get\r\n    $$5\\sum_{n=0}^\\infty (5(n+1)a_{n+1}-3a_n)x^{n}=0$$\r\n    Hence\r\n    $$5(n+1)a_n-3a_n=0\\implies a_{n+1}=\\frac{3a_n}{5n+5}\\implies a_n=\\left(\\frac{3}{5}\\right)^n\\frac{1}{n!}a_0$$\r\n    Thus\r\n    $$y(x)=\\sum_{n=0}^\\infty a_nx^n=a_0\\sum_{n=0}^\\infty \\left(\\frac{3}{5}\\right)^n\\frac{1}{n!}x^n=a_0e^{3x/5}$$\r\n    for some constant $a_0$.\r\n\\end{example}\r\n\\subsection{Non-linear First Order ODEs}\r\nThe general form of these sort of equations can be written in the following way:\r\n$$Q(x,y)\\frac{\\mathrm dy}{\\mathrm dx}+P(x,y)=0$$\r\nWe cannot guarantee that a nonlinear ODE can be solved in closed form.\r\nBut sometimes we can.\r\n\\subsubsection{Special Types of Non-linear First Order ODEs}\r\nAn ODE is said to be separable if it can be written in the form $q(y)\\mathrm dy=p(x)\\mathrm dx$, then we can solve for it by integrating both sides.\\\\\r\nAn ODE in the above form is called \\textit{exact} if and only if $Q(x,y)\\,\\mathrm dy+P(x,y)\\,\\mathrm dx$ is an exact differential of some function $f(x,y)$, that is $\\mathrm df=Q\\,\\mathrm dy+P\\,\\mathrm dx$.\r\nIf it is the case, our general form then give $\\mathrm df=0$, so $f(x,y)=0$ is the solution.\\\\\r\nTo find it, we can make use of the multivariate chain rule to get\r\n$$\\frac{\\partial f}{\\partial x}+\\frac{\\partial f}{\\partial y}\\frac{\\mathrm dy}{\\mathrm dx}=0$$\r\n$P=f_x,Q=f_y$, hence\r\n$$\\frac{\\partial^2f}{\\partial y\\partial x}=\\frac{\\partial P}{\\partial y},\\frac{\\partial^2f}{\\partial x\\partial y}=\\frac{\\partial Q}{\\partial x}$$\r\nSo $P_y=Q_x$.\r\nConversely, if it is true in a simply connected domain, then $P\\,\\mathrm dx+Q\\,\\mathrm dy$ is an exact differential.\r\nTherefore we can use it to test whether the given ODE is exact.\r\nIf so, we can find $f$ (hence a possibly implicit expression of $y$) back by integration.\r\n\\begin{example}\r\n    We want to solve $6y(y-x)y'+(2x-3y^2)=0$.\r\n    So $P=2x-3y^2,Q=6y(y-x)$, we can check that our preceding condition hold (i.e. $P_y=Q_x$), hence it is exact.\\\\\r\n    To find $f(x,y)$, we notice\r\n    $$\r\n    \\begin{cases}\r\n        \\left.\\partial f/\\partial x\\right|_y=2x-3y^2\\\\\r\n        \\left.\\partial f/\\partial y\\right|_x=6y(y-x)\r\n    \\end{cases}\r\n    $$\r\n    Integrating the first equation we have $f(x,y)=x^2-3xy^2+h(y)$ where $h$ is differentiable.\r\n    Now plug it in the other equation we get $6y(y-x)=-6xy+h^\\prime(y)$, thus $h^\\prime(y)=6y^2\\implies h(y)=2y^3-C$ where $C$ is a constant.\r\n    So the general solution is\r\n    $$x^2-3xy^2+2y^3=C$$\r\n\\end{example}\r\n\\subsubsection{Isoclines and Solution Curves}\r\nEven if (most of the time) we cannot really solve the equation, we can still analyze its behaviour.\r\nNow we consider an ODE of form $\\dot{y}=f(y,t)$, each initial condition $y(t_0)=y_0$ will give a different solution curve (given existence).\r\n\\begin{example}\r\n    Suppose $\\dot{y}=t(1-y^2)$, of course this is separable and we can solve it, but without solving this, we can sketch solution curves as well.\r\n\\end{example}\r\n\\begin{definition}\r\n    An isocline is a curve given by $\\dot{y}$ being constant, that is, $t(1-y^2)=c$ for some constant $c$.\r\n\\end{definition}\r\nNote that if $f(y,t)$ is single-valued (i.e. actually a function), then the solution curves cannot cross (unless as tangents of each other).\r\nTo sketch the solutions, we can first sketch all the Isoclines.\r\nNote that along any isocline, the corresponding $\\dot{y}$ is constant, so we can easily draw the vector field, so we could follow the directions with initial condition given to approximate the curve.\\\\\r\nWe can analysis the stability of a fixed point.\r\n\\begin{definition}\r\n    A fixed point is a constant solution of $y$.\r\n\tThat is, we have $\\dot{y}=f(y,t)=0$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A fixed point is called stable if the solution curve in a small neighbourhood of the fixed point converge to it.\r\n\\end{definition}\r\nWe now try to analyze the stability of fixed points using perturbation analysis.\\\\\r\nLet $y=a$ be a fixed point of some DE $\\dot{y}=f(y,t)$.\r\nConsider a small perturbation of the fixed point $y=a+\\epsilon(t)$, so $\\dot{\\epsilon}=f(a+\\epsilon,t)=f(a,t)+\\epsilon f_y(a,t)+O(\\epsilon^2)$, so $\\dot{\\epsilon}\\approx\\epsilon f_y(a,t)$ which is linear.\r\nThe behaviour of $\\epsilon$ obtained from this differential equation helps us to classify the fixed points.\\\\\r\nIf $\\lim_{t\\to\\infty }\\epsilon(t)=0$ then we call it a stable fixed point, if $\\lim_{t\\to\\infty}\\epsilon(t)=\\pm\\infty$, then we say it is unstable, otherwise we say it is neutral.\r\nIf $f_y(a,t)=0$, then we need higher order terms in that Taylor series in order to determine its behaviour.\r\n\\begin{example}\r\n    $\\dot{y}=t(1-y^2)$, so the fixed points are $y=\\pm 1$.\r\n    We have $f_y=-2ty$.\\\\\r\n    For $y=1$, then $\\dot{\\epsilon}=-2t\\epsilon\\implies \\epsilon_{0}e^{-t^2}$, so $\\epsilon\\to 0$ when $t\\to\\infty$.\r\n    So it is stable.\\\\\r\n    For $y=-1$, then $\\dot{\\epsilon}=2t\\epsilon\\implies \\epsilon_{0}e^{t^2}$, so $\\epsilon\\to\\pm\\infty$ (for $\\epsilon_0\\neq 0$) when $t\\to\\infty$.\r\n    So it is unstable.\r\n\\end{example}\r\n\\subsubsection{Autonomous DEs}\r\n\\begin{definition}\r\n    A DE is called autonomous if $f$ does not depend on $t$, that is, it is of the form $\\dot{y}=f(y)$.\r\n\\end{definition}\r\nSo in this case, we apply the perturbation analysis to get $\\dot{\\epsilon}=f^\\prime(a)\\epsilon$, thus $\\epsilon=\\epsilon_0e^{kt}$ where $k=f^\\prime(a)$, so if $\\epsilon_0\\neq 0$,\r\n$$\\epsilon\\to\r\n\\begin{cases}\r\n    0\\text{, if $f^\\prime(a)<0$, so it is stable}\\\\\r\n    \\pm\\infty\\text{, if $f^\\prime(a)>0$, so it is unstable}\\\\\r\n    \\text{Others, if $f^\\prime(a)=0$, so it is neutral}\r\n\\end{cases}$$\r\n\\subsubsection{Phase Portraits}\r\nAnother way to analyze the behaviour of a given DE is from a geometric perspective represented by something called phase portrait.\r\n\\begin{example}\r\n    Chemical kinetics is an important example why it is useful.\r\n    Consider neutralization reaction ${\\rm NaOH+HCl=H_2O+NaCl}$.\r\n    Let $a(t),b(t)$ be the numbers of NaOH and HCl molecules at times $t$, and $c(t)$ be the number of ${\\rm H_2O}$ which is equal to that of NaCl.\\\\\r\n    So the initial condition is $a(0)=a_0,b(0)=b_0$, and the model is $\\dot{c}=\\lambda ab$, also $a=a_0-c,b=b_0-c$, so\r\n    $$\\frac{\\mathrm dc}{\\mathrm dt}=\\lambda(a_0-c)(b_0-c)$$\r\n    which is autonomous, so $a_0,b_0$ are the fixed points of the DE.\r\n    We can sketch the graph of $\\dot{c}$ against $c$, which is called the 2D phase protrait of the DE, where we can analyze the attraction vectors near the phase protrait by the trends of it to decide the stability.\r\n\\end{example}\r\n\\begin{example}\\label{logistic_cont}\r\n    Let $y(t)$ be the population at time $T$ and birth rate would be $\\alpha y$ for some $\\alpha$ and the death rate be $\\beta y$ for some $\\beta$.\\\\\r\n    Case 1: Linear model.\r\n    So $\\dot{y}=\\alpha y-\\beta y\\implies y=y_0e^{(\\alpha -\\beta)t}$, so $y\\to\\infty$ if $\\alpha>\\beta$.\\\\\r\n    Case 2: Nonlinear model.\r\n    So $\\dot{y}=(\\alpha-\\beta)y-\\gamma y^2$.\r\n    the parameter $\\gamma$ here could be due to the death due to overcrowdedness, etc.\r\n    Equivalently, we can write it as $\\dot{y}=ry(1-y/\\lambda)$ where $r=\\alpha-\\beta,\\lambda=(\\alpha-\\beta)/\\lambda$, so we can sketch the phase protrait again.\r\n    Note that the fixed points are $0$ and $\\lambda$, the former is unstable but the latter is stable.\r\n\\end{example}\r\n\\subsubsection{Fixed Points in Discrete Equations}\r\nWe can introduce fixed points in discrete equations as well.\r\nConsider a first order discrete equation (aka difference equation) of the form $x_{n+1}=f(x_n)$.\r\n\\begin{definition}\r\n    The fixed point is a discrete equation is a fixed point of the function $f$.\r\n\\end{definition}\r\nWe can analyze its stability again by perturbation analysis.\r\nLet $x_f$ be a fixed point and we perturb it by a small $\\epsilon$, so we can expand $f$ in terms of Taylor series\r\n$$f(x_f+\\epsilon)=x_f+\\epsilon f^\\prime(x_f)+O(\\epsilon^2),\\epsilon\\to0$$\r\nSo if $x_n=x_f+\\epsilon, x_{n+1}=x_f+\\epsilon f^\\prime(x_f)$.\r\nSo $x_f$ is stable if $|f^\\prime(x_f)|<1$, neutral if $|f^\\prime(x_f)|=1$, unstable if $|f^\\prime(x_f)|>1$.\r\n\\begin{example}[Discrete Logistic Equation]\r\n    Some populations are born in distinct generations (e.g. lambs born in spring).\r\n    A nonlinear model of this is\r\n    $$\\frac{x_{n+1}-x_n}{\\Delta t}=\\lambda x_n-\\gamma x_n^2$$\r\n    This is the discrete version of Example \\ref{logistic_cont}, so\r\n    $$x_{n+1}=(1+\\lambda\\Delta t)x_n-\\gamma\\Delta tx_n^2$$\r\n    We can write alternatively $x_{n+1}=rx_n(1-x_n)=:f(x_n)$\r\n    The function $f$ is called the logistic map.\\\\\r\n    Note that the fixed point occurs at $0$ or $1-1/r$.\r\n    We analyze its stability by perturbation.\r\n    At $0$, $f^\\prime=r$, so it is stable if $0<r<1$ and unstable if $r>1$.\r\n    At $1-1/r$, $f^\\prime=2-r$.\r\n    We assume $r<0$ or $r>1$ since the other cases are not physical.\r\n    \\footnote{It's an applied course, so what the hell.}\r\n    Then it is stable for $1<r<3$ and unstable for $r>3$.\r\n\\end{example}\r\n", "meta": {"hexsha": "9bf98e1927d76eec88381f51a175bd56a9003c13", "size": 14433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/firstorder.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": "4/firstorder.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": "4/firstorder.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": 64.4330357143, "max_line_length": 216, "alphanum_fraction": 0.6910552207, "num_tokens": 4479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6448641049715861}}
{"text": "\\problemname{Pegs and Legs}\n\nPegs and Legs is a game where a disk slides down a nearly-vertical board.\nAt the bottom of the board are places for the disk to land, called \\textit{legs}.\nEach leg is worth a certain amount of points if your disk lands in it.\n\nYou start with a disk at the top and drop it onto some \\textit{drop point}\npeg or directly into some \\textit{drop point} leg.\nWhen your disk hits a peg, one of three things happen: (1) the disk falls to\nthe left with probability $\\ell$, (2) the disk falls to the right with\nprobability $r$, or (3) it gets stuck with probability $1 - \\ell - r$.\nThe probabilities may be different for each peg. If the disk falls to\nthe left or to the right, then it will either fall onto another peg or\ninto a leg. If the disk gets stuck, then you must drop it again from\nsome drop point on the top. The figure below illustrates the 3rd sample input,\nthe two dark pegs are the drop points.\n\n\\begin{figure}[h]\n\\begin{center}\n \\includegraphics[width=0.5\\textwidth]{pegsandlegs.pdf}\n\\end{center}\n\\end{figure}\n\nBecause of gravity it is not possible for a disk to hit the same peg\nmore than once unless the disk is dropped again. The game continues\nuntil your disk lands in a leg, at which point you earn the value of\nthat leg. What is the maximum possible expected score the player can earn?\n\n\n\n\\section*{Input}\nThe first line of input contains two integers $L$\n($1 \\leq L \\leq 100\\,000$), which is the number of legs, and $P$\n($1 \\leq P \\leq 100\\,000$), which is the number of pegs. Legs\nare numbered from $1$ to $L$ and pegs are labeled from $L+1$ to\n$L+P$.\n\nThe next $L$ lines describe the legs, in order.\nEach of these lines contains a single integer $v$ ($1 \\leq v \\leq 1\\,000\\,000$),\nwhich is the value of this leg.\n\nThe next $P$ lines describe the pegs, in order.\nEach of these lines starts with two real numbers $\\ell$ ($0 < \\ell < 1$),\nwhich is the probability that the disk falls to the left after hitting this peg,\nand $r$ ($0 < r < 1$), which is the probability that the disk falls\nto the right after hitting this peg ($\\ell + r \\leq 1$), followed by two\nintegers $x$ ($1 \\leq x \\leq L+P$), which is the label of\nthe peg/leg the disk falls onto if it falls to the left, and $y$\n($1 \\leq y \\leq L+P$), which is the label of the peg/leg the disk\nfalls onto if it falls to the right. It is guaranteed that $x$ and $y$\nare smaller labels than the label of this peg.\n\nAll real numbers are specified to exactly 3 decimal places.\nA peg or leg is a drop point if there are no pegs that drop into this peg or leg.\n\nIt is guaranteed that from any peg (whether a drop point or not),\nthe probability the disk eventually gets stuck after reaching this peg\nis at most $0.9999$.\n\n\\section*{Output}\nDisplay the maximum possible expected score the player can earn.\nAnswers with an absolute error or relative error of at most $10^{-6}$\nwill be accepted.\n", "meta": {"hexsha": "1d2d3c3cd69130d962c9eaf8d9c6349544025f91", "size": 2884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/pegsandlegs/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/pegsandlegs/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/pegsandlegs/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": 45.0625, "max_line_length": 81, "alphanum_fraction": 0.7364771151, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6448640974021506}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\n%\\usepackage[landscape]{geometry}\n\n\\usepackage{mathtools}\n\\usepackage{booktabs}\n\\usepackage{ltablex}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{\\vspace*{-4cm}Big \\(\\bigO\\) Notation for A\\&W Algorithms}\n\\date{}\n\n\\pagenumbering{gobble}\n\n\\newcommand{\\bigO}{\\mathcal{O}}\n\\DeclareMathOperator{\\poly}{poly}\n\\DeclareMathOperator{\\polylog}{polylog}\n\n\\begin{document}\n    \\maketitle\n    \\vspace*{-1.5cm}\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 (corners) 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*{Runtimes}\n\n    \\begin{center}\n    \\begin{tabularx}{\\textwidth}{Xl}\n        \\toprule\n        Find all cut vertices and edges in connected graph (DFS) & \\(\\bigO(m)\\) \\\\\n        Eulerian path in connected graph & \\(\\bigO(m)\\) \\\\\n        Hamiltonian cycle in general graph & \\(\\bigO(n^2 \\cdot 2^n)\\) \\\\\n        Hamiltonian cycle in graph with $n \\geq 3$ and $\\text{minimum degree} \\ \\geq \\frac{n}{2}$ & \\(\\bigO(n^2)\\) \\\\\n        Count Hamiltonian cycles in graph & \\(\\bigO(n^{2.81} \\log n \\cdot 2^n)\\) \\\\\n        Hamiltonian cycle in general graph & NP-complete \\\\\n        Find augmenting path in bipartite graph (BFS) & \\(\\bigO(n + m)\\) \\\\\n        Find augmenting path in general graph (Blossom) & \\(\\bigO(nm)\\) \\\\\n        Maximal (inclusion) matching (greedy) & \\(\\bigO(m)\\) \\\\\n        Maximum (cardinality) matching in bipartite graph (Hopcroft-Karp) & \\(\\bigO(\\sqrt{n} \\cdot (n+m))\\) \\\\\n        2-approximation of Metric TSP & \\(\\bigO(n^2)\\) \\\\\n        $\\frac{3}{2}$-approximation of Metric TSP & \\(\\bigO(n^3)\\) \\\\\n        Perfect matching in \\(2^k\\)-regular bipartite graph & \\(\\bigO(m)\\) \\\\\n        Perfect matching in complete graph with weight function $l: \\: \\binom{[n]}{2} \\to \\mathbb{N}_0$ & \\(\\bigO(n^3)\\) \\\\\n        Decide if $\\chi(G) \\leq k$ for $k \\geq 3$ & NP-complete ($\\bigO(2.2^n)$) \\\\\n        Greedy coloring with $C(G)$ colors ($\\chi(G) \\leq C(G) \\leq \\Delta(G) + 1$) & \\(\\bigO(m)\\) \\\\\n        \\(\\bigO(\\sqrt{n})\\)-coloring for 3-colorable graphs & \\(\\bigO(m)\\) \\\\\n        Find duplicates (Hashmap) & \\(\\bigO(n \\log n + |\\text{Dupl}(\\mathcal{S})|)\\) \\\\\n        Find duplicates (Bloom-Filter) & \\(\\bigO(kn)\\) \\\\\n        Miller-Rabin prime test & \\(\\bigO(\\log n)\\) \\\\\n        Randomized Quicksort & \\(\\bigO(n \\log n)\\)\\footnotemark \\\\\n        Long path problem & NP-complete \\\\\n        Colorful-Path with length \\(\\log n\\) & \\(\\bigO(mn \\log n)\\) \\\\\n        Colorful-Path with length \\(\\bigO(\\log n)\\) & \\(\\bigO(\\poly(n))\\) \\\\\n        Maximal flow (Ford-Fulkerson) with max. capacity $U$ & \\(\\bigO(mnU)\\)\\\\\n        Maximal flow (Capacity Scaling) with max. capacity $U$ & \\(\\bigO(mn(1 + \\log U))\\) \\\\\n        Maximal flow (Dynamic Trees) & \\(\\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\\polylog(n))\\) \\\\\n        Smallest enclosing disc (naive deterministic or randomized) & \\(\\bigO(n^4)\\)\\footnotemark[\\value{footnote}] \\\\\n        Smallest enclosing disc (clever randomized) & \\(\\bigO(n \\log n)\\)\\footnotemark[\\value{footnote}] \\\\\n        Convex hull (Jarvis-Wrap) & \\(\\bigO(nh)\\) \\\\\n        Convex hull with \\emph{sorted ($\\bigO(n \\log n)$)} points (LocalRepair) & \\(\\bigO(n)\\) \\\\\n        \\bottomrule\n    \\end{tabularx}\n    \\end{center}\n    \\footnotetext{Randomized algorithm; expected runtime is given}\n\\end{document}\n", "meta": {"hexsha": "9a6f73ecfeaeb5c50b0125bb83516f44476ee048", "size": 3926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithmen und Datenstrukturen/runtime.tex", "max_stars_repo_name": "Flopsey/eth-cheatsheets", "max_stars_repo_head_hexsha": "9badf62d7d9b7014dfd6dc5928a4a3c839fb815c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-24T12:48:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-24T12:48:54.000Z", "max_issues_repo_path": "Algorithmen und Datenstrukturen/runtime.tex", "max_issues_repo_name": "Flopsey/eth-cheatsheets", "max_issues_repo_head_hexsha": "9badf62d7d9b7014dfd6dc5928a4a3c839fb815c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithmen und Datenstrukturen/runtime.tex", "max_forks_repo_name": "Flopsey/eth-cheatsheets", "max_forks_repo_head_hexsha": "9badf62d7d9b7014dfd6dc5928a4a3c839fb815c", "max_forks_repo_licenses": ["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.4691358025, "max_line_length": 123, "alphanum_fraction": 0.59016811, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6448640954385835}}
{"text": "\\section{ Modeling Sequential Annotators }\\label{sec:annomodels}\n\nWhen combining multiple annotators with varying skill levels, we can improve performance by modelling their individual noise and bias using a probabilistic\nmodel.\nHere, we describe several models \nthat do not consider dependencies between annotations in a sequence,\nbefore defining \\emph{seq}, \na new extension that captures sequential dependencies. \nProbabilistic annotator models \neach define a different function, $A$, \nfor the likelihood that the annotator chooses label $c_{\\tau}$\ngiven the true label $t_{\\tau}$, for the $\\tau$th token in a sequence.\n\n\\textbf{Accuracy model (acc)}:\n the basis of several previous methods~\\cite{donmez2010probabilistic,rodrigues2013learning},\n\\emph{acc} uses a single parameter for each \nannotator's accuracy, $\\pi$: \n\\begin{flalign}\n & A = p( c_{\\tau} \\! = \\! i | t_{\\tau} \\! = \\! j, \\pi ) = \\left.\n\\begin{cases}\n  \\pi  \\!&\\!\\!\\!\\text{ where } i = j \\\\\n  \\frac{1 - \\pi}{J-1} \\!&\\!\\!\\!\\text{ otherwise}\n\\end{cases} \n\\right\\} \\!, &&\n\\end{flalign}\nwhere \n%$c_{\\tau}$ is the label given by the annotator for token $\\tau$, $t_{\\tau}$ is its true label\n%and \n$J$ is the number of classes.\n%The limitation of this approach is that it\n%It assumes reliability is constant,\n%which means that \nThis may be unsuitable when one class label dominates the data, \nsince a spammer who always selects the most common label will nonetheless \nhave a high $\\pi$.\n%despite their labels being uninformative.\n%Annotator models define a likelihood... \n%\\begin{flalign}\n%& A = p(c_{\\tau}, c_{\\tau-1}, t_{\\tau}) = p( c_{\\tau} \\!\\!=\\! i | c_{\\tau-1}, t_{\\tau} \\!=\\! j, \\bs\\pi ),&&\n%\\end{flalign}\n\n\\textbf{Spamming model (spam)}:\nproposed as part of MACE~\\cite{hovy2013learning}, this model also\nassumes constant accuracy, $\\pi$,\nbut that when an annotator is incorrect, they label according to \na spamming distribution, $\\bs\\xi$, that is independent of the true label, $t_{\\tau}$.\n\\begin{flalign}\nA & = p( c_{\\tau} = i | t_{\\tau} = j, \\pi, \\bs\\xi) && \\nonumber \\\\\n& = \\left.\n\\begin{cases}\n  \\pi + (1 - \\pi) \\xi_j  &\\text{ where } i = j \\\\\n  (1 - \\pi) \\xi_j &\\text{ otherwise}\n\\end{cases} \n\\right\\}.\n\\end{flalign}\nThis addresses the case where spammers choose the dominant label\n% common label when the classes are imbalanced.\n%While MACE can capture spamming patterns, \nbut does not explicitly model \ndifferent error rates in each class. \n%which\n%may be an issue for sequence tagging using the \n%BIO encoding. For example, if an annotator frequently labels longer spans\n% than the true spans by starting the spans early. In this \n% case, they may more frequently\n%mis-label the `B' tokens than the `I' or `O' tokens,  which cannot be modelled by MACE. \nFor example, if an annotator is better at detecting type `x' spans than type `y', or if they frequently miss the first token\nin a span, thereby labelling the start of a span as `O' when the true label is `B-x', \nthis would not be explicitly modelled by \\emph{spam}.\n\n\\textbf{Confusion vector (CV)}: this approach learns a separate accuracy \n for each class label~\\cite{nguyen2017aggregating}\nusing parameter vector, $\\bs\\pi$, of size $J$:\n\\begin{flalign}\n& A = p( c_{\\tau} \\!\\!=\\! i | t_{\\tau} \\!=\\! j, \\bs\\pi ) = \\left.\n\\begin{cases}\n  \\pi_j  \\!\\!\\!\\!\\!\\!&\\text{ where } i \\!=\\! j \\\\\n  \\frac{1 \\!- \\!\\pi_j}{J-1} \\!\\!\\!\\!\\!\\!&\\text{ otherwise}\n\\end{cases} \n\\! \\right\\} \\!.&&\n\\end{flalign}\n%For the incorrect label cases where $i \\! \\neq \\! j$,\n% $p( c_{\\tau} \\!\\!=\\! i | t_{\\tau} \\!=\\! j, \\bs\\pi )$ is constant for all values of $i$.\n% Therefore, t\nThis model does not capture spamming\npatterns where one of the incorrect labels has a much higher likelihood than the others.\n\n\\textbf{Confusion matrix (CM)}~\\cite{dawid_maximum_1979}:\nthis model can be seen as an expansion of the confusion vector so that $\\bs\\pi$ becomes a \n$J\\times J$ matrix with values given by:\n\\begin{flalign}\n& A = p( c_{\\tau} \\!\\!=\\! i | t_{\\tau} \\!=\\! j, \\bs\\pi ) = \n  \\pi_{j,i} .&&\n\\end{flalign}\nThis requires a larger number of parameters, $J^2$, compared to the $J+1$ parameters of MACE or $J$ parameters\nof the confusion vector.\nLike \\emph{spam}, \n\\emph{CM} %represents the probability of each mistake, so it \ncan model spammers who frequently chose one label regardless\nof the ground truth, but also\nmodels different error rates and biases for each class.\n%type of `B-x', `I-x' and `O' label.\nHowever, \\emph{CM} ignores dependencies between annotations in a sequence, % that affect these probabilities.\nsuch as the fact that an `I' cannot immediately follow an `O'.\n% Consider the following example where this may be a problem: three annotators produce sequences of labels as follows:\n% O-B-I-I-I-O\n% O-O-B-I-O-O\n% O-O-O-O-O-O\n% We can see that the first two annotators agree that the third token is part of the span, \n\n\\textbf{Sequential Confusion Matrix (seq)}: we introduce a new extension to the confusion matrix to model the dependency \nof each label in a sequence on its predecessor,\ngiving the following likelihood:\n\\begin{flalign}\n& A = p( c_{\\tau} \\!\\!=\\! i | c_{\\tau-1} \\!=\\! \\iota, t_{\\tau} \\!=\\! j, \\bs\\pi ) = \n  \\pi_{j,\\iota,i} ,&&\n\\end{flalign}\nwhere $\\bs\\pi$ is now three-dimensional with size $J\\times J\\times J$.\nIn the case of disallowed transitions, e.g. from $c_{\\tau-1}=$`O' to $c_{\\tau}=$`I', the value $\\pi_{j,c_{\\tau-1},c_{\\tau}}\\approx 0$, $\\forall j$\nis fixed \\textit{a priori}. \nThe sequential model can capture phenomena such as a tendency toward overly long sequences, by learning that I is more likely to follow another I, so that\n$\\pi_{O,I,I} > \\pi_{O,I,O}$.\nA tendency to split spans by inserting `B' in place of `I' can be modelled\nby increasing the value of\n$\\pi_{I,I,B}$ without affecting $\\pi_{I,B,B}$ and $\\pi_{I,O,B}$.\n\nThe annotator models presented in this section \ninclude the most widespread models for NLP annotation tasks, \nand can be seen as extensions of one another.\nThe choice of annotator model for a particular annotator\n depends on the developer's understanding of the annotation task: \n if the annotations have sequential dependencies, this suggests the \\emph{seq} model;\nfor non-sequential classifications \\emph{CM} may be effective with small ($\\leq 5$) \nnumbers of classes; \\emph{spam} may be more suitable if there are many classes, as the number of parameters to learn is low. \nHowever, there is also a trade-off between the expressiveness of the model and the\nnumber of parameters that must be learned. Simpler models with fewer parameters\nmay be effective if there are only small numbers of annotations from each annotator. \n%Our experiments in Section \\ref{sec:expts_all} investigate this trade-off on NLP tasks involving sequential annotation.\nThe next section shows how these annotator models can be used as components of \na complete model for aggregating sequential annotations. \n%The experiments in Section \\ref{sec:expts_all} \n% test whether the more expressive seq annotator model,\n%which has more parameters to learn, is beneficial in a realistic setting.\n", "meta": {"hexsha": "878124451bd1f3609ceefd5fbd2cc82560acfcff", "size": 7034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/sections/annotator_models.tex", "max_stars_repo_name": "anbasile/arxiv2018-bayesian-ensembles", "max_stars_repo_head_hexsha": "52e2741540ce0466666aaca9fe9dd148c144123a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:24:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T13:05:45.000Z", "max_issues_repo_path": "documents/sections/annotator_models.tex", "max_issues_repo_name": "anbasile/arxiv2018-bayesian-ensembles", "max_issues_repo_head_hexsha": "52e2741540ce0466666aaca9fe9dd148c144123a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-03-01T17:40:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-29T17:51:39.000Z", "max_forks_repo_path": "documents/sections/annotator_models.tex", "max_forks_repo_name": "anbasile/arxiv2018-bayesian-ensembles", "max_forks_repo_head_hexsha": "52e2741540ce0466666aaca9fe9dd148c144123a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-10-02T14:35:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T18:04:32.000Z", "avg_line_length": 48.8472222222, "max_line_length": 155, "alphanum_fraction": 0.7149559283, "num_tokens": 2062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6448640954385834}}
{"text": "\\documentclass[letter]{article}\n\n\\usepackage{fullpage} % Package to use full page\n%\\usepackage{parskip} % Package to tweak paragraph skipping\n\\usepackage{tikz} % Package for drawing\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\\usepackage{mathtools}\n\\usepackage{listings}\n\\usepackage{mathrsfs}\n\\usepackage{amsfonts}\n\\usepackage{bbm}\n\\usepackage{xcolor}\n\n\\newcommand{\\vecE}{\\vec{E}}\n\\newcommand{\\vecH}{\\vec{H}}\n\\newcommand{\\epsilonB}{\\boldsymbol{\\epsilon}}\n\\newcommand{\\epsiloninv}{\\boldsymbol{\\epsilon^{-1}}}\n\n\\newcommand{\\calE}{\\vec{\\mathcal{E}}}\n\\newcommand{\\calH}{\\vec{\\mathcal{H}}}\n\n\\newcommand{\\levi}{\\mathcal{E}}\n\n\\newcommand{\\Partialsqx}[1]{\\frac{\\partial^2 #1}{\\partial x^2}}\n\\newcommand{\\Partialsqy}[1]{\\frac{\\partial^2 #1}{\\partial y^2}}\n\n\\usepackage{caption} \n\\captionsetup[table]{skip=10pt}\n\n\\title{2D Modes Draft}\n\\author{Panya Sukphranee}\n\\date{\\today}\n\n\n\\begin{document}\n\t\n\t\\maketitle\n\t\n\t\\section*{Theory}\n\t\n\tElectric and magnetic fields propogating in the $\\hat{z}$ direction have the form:\n\t\n\t\\begin{align}\n\t\t\\vecE &= \\calE(x,y) e^{-j(\\beta z + \\omega t)} \\\\\n\t\t\\vecH &= \\calH(x,y) e^{-j(\\beta z + \\omega t)} \n\t\\end{align}\n\t\n\t\\begin{align}\n\t\t\\Aboxed{\\partial_z H^i &= -j \\beta H^i}\n\t\t\\label{eqn:partial_z}\n\t\\end{align}\t\t\n\t\n\t\\begin{align}\n\t\t\\Aboxed{H_z &= \\frac{1}{j \\beta} \\big( \\frac{\\partial H_x}{\\partial x} + \\frac{\\partial H_y}{\\partial y} \\big)}\n\t\t\\label{eqn:H_z}\n\t\\end{align}\n\n\tFor simplicity, assume that one of the material axes is along the propogation direction, $\\hat{z}$. We also assume that the electric permittivity tensor has the form:\t\n\t\\begin{align}\n\t\t\\epsilonB &= \\epsilon_0\t\t\n\t\t\\begin{bmatrix}\n\t\t\t\\epsilon_{xx} & \\epsilon_{xy} & 0 \\\\\n\t\t\t\\epsilon_{yx} & \\epsilon_{yy} & 0 \\\\\n\t\t\t0 & 0 & \\epsilon_{zz} \n\t\t\\end{bmatrix}  \n\t\t\\label{matrix:diag_tensor}\n\t\\end{align}\n\timplying that the transverse permitivitty is independent of $E_z$ and the longitudinal permittivity is independent of the transverse fields. Each entry above is an $M \\times N$ matrix, where $M \\times N$ is the dimension of the grid of points describing our waveguide. $0 = 0_{M \\times N}$. Further, we deal with the simple case of a diagonal tensor. So that the electric permittivity along any coordinate axis is independent of orthogonal field components to that axis,  i.e.\\\\\n\t\\begin{align*}\n\t\t\\epsilonB &= \\epsilon_0\n\t\t\\begin{bmatrix}\n\t\t\t\\epsilon_{xx} & 0 & 0 \\\\\n\t\t\t0 & \\epsilon_{yy} & 0 \\\\\n\t\t\t0 & 0 & \\epsilon_{zz} \n\t\t\\end{bmatrix}  \n\t\\end{align*}\n\t\n\t$\\epsilonB$ is a rank 4 tensor, 2 indices specify the point of evaluation, 2 indices specify xy, yx, xx, yy, etc. \n\tFrom Maxwell's equations, we start with \n\t\\begin{equation}\n\t\t\\nabla \\times \\vecH = j \\omega \\boldsymbol{\\epsilon_p} \\cdot \\vecE\n\t\\end{equation}\n\t\n\tWhere $\\epsilonB_p$ is $\\epsilonB$ evaluated at a point, p. \n\t\\begin{align*}\n\t\t\\epsilonB_p^{-1} \\cdot (\\nabla \\times \\vecH) &= j \\omega \\vecE\\\\\n\t\t\\nabla \\times (\\epsilonB_p^{-1} \\cdot (\\nabla \\times \\vecH)) &= j \\omega (\\nabla \\times \\vecE )\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= j \\omega ( - j \\omega) \\mu \\vecH\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t&=\\omega^2 \\mu \\vecH\n\t\\end{align*}\n\t\n\tWrite in tensor notation, with $\\partial_k = \\frac{\\partial}{\\partial x^k}$ and $\\epsilonB^{-1}=\\bar{\\epsilonB}$\n\t\\begin{align}\n\t\t\\big[\\nabla \\times (\\bar{\\epsilonB} \\cdot (\\nabla \\times \\vecH))\\big]^i &= \\omega^2 \\mu \\vecH^i \\\\\t\t\n\t\t\\levi^{ij}_k \\partial_j \\bar{\\epsilonB}^k_l \\levi^{lm}_n \\partial_m H^n &= \\omega^2 \\mu H^i\\\\\n\t\t\\bar{\\epsilonB}^k_l \\levi^{ij}_k \\levi^{lm}_n \\partial_j \\partial_m H^n &= \\omega^2 \\mu H^i\t\n\t\t\\label{eqn:tensor_notation}\n\t\\end{align}\n\t\n\t \n\t\t\n\tWhere the inverse of $\\epsilonB$ is $\\footnote{Stover, Christopher and Weisstein, Eric W. \"Matrix Inverse.\" From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/MatrixInverse.html}$ \\\\\n\t\\begin{align}\n\t\t\\bar{\\epsilonB} &= \\frac{1}{\\epsilon_0}\t\t\n\t\t\\begin{bmatrix}\n\t\t\t\\frac{\\epsilon_{yy}}{\\epsilon_{xx} \\epsilon_{yy} - \\epsilon_{xy}\\epsilon_{yx}} & -\\frac{\\epsilon_{xy}}{\\epsilon_{xx} \\epsilon_{yy} - \\epsilon_{xy}\\epsilon_{yx}} & 0 \\\\[1ex]\n\t\t\t-\\frac{\\epsilon_{yx}}{\\epsilon_{xx} \\epsilon_{yy} - \\epsilon_{xy}\\epsilon_{yx}} & \\frac{\\epsilon_{xx}}{\\epsilon_{xx} \\epsilon_{yy} - \\epsilon_{xy}\\epsilon_{yx}} & 0 \\\\[1ex]\n\t\t\t0 & 0 & \\frac{1}{\\epsilon_{zz}} \n\t\t\\end{bmatrix}  \n\t\t\\label{matrix:inverse}\n\t\\end{align}\n\t\n\t\\section*{Evaluate Transverse Fields for the Diagonal Case}\n\tFor the diagonal case where $\\epsilon_{xy} = \\epsilon_{yx} = 0$, we have\n\t\n\t\\begin{align}\n\t\t\\bar{\\epsilonB} &= \\frac{1}{\\epsilon_0}\t\t\n\t\t\\begin{bmatrix}\n\t\t\t\\frac{1}{\\epsilon_{xx}} & 0 & 0 \\\\[1ex]\n\t\t\t0 & \\frac{1}{\\epsilon_{yy}} & 0 \\\\[1ex]\n\t\t\t0 & 0 & \\frac{1}{\\epsilon_{zz}} \n\t\t\\end{bmatrix}  \\\\\n\t\t&\\equiv \\frac{1}{\\epsilon_0}\t\t\n\t\t\\begin{bmatrix}\n\t\t\ta^1 & 0 & 0 \\\\[1ex]\n\t\t\t0 & a^2 & 0 \\\\[1ex]\n\t\t\t0 & 0 & a^3 \n\t\t\\end{bmatrix}\n\t\t\\label{matrix:inverse}\n\t\\end{align}\n\t\n\tUsing eqn \\ref{eqn:tensor_notation} for the diagonal case (eqn \\ref{matrix:inverse}), we evaluate $H^x$ and $H^y$ with the help of Table \\ref{table:Hx} and \\ref{table:Hy} to track indices\n\t\n\t\\begin{align*}\n\t\t\\bar{\\epsilonB}^k_l \\levi^{ij}_k \\levi^{lm}_n \\partial_j \\partial_m H^n &= \\omega^2 \\mu H^i\\\\[1ex]\n\t\\end{align*}\n\t\n\t\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\t\\hline\n\t\\textbf{i} & \\textbf{j} & \\textbf{k} & \\textbf{sgn} & \\textbf{l} & \\textbf{m} & \\textbf{n} & \\textbf{sgn} \\\\ \\hline\n\t1          & 2          & 3          & +            & 3          & 1          & 2          & +            \\\\ \\hline\n\t1          & 2          & 3          & +            & 3          & 2          & 1          & -            \\\\ \\hline\n\t1          & 3          & 2          & -            & 2          & 3          & 1          & +            \\\\ \\hline\n\t1          & 3          & 2          & -            & 2          & 1          & 3          & -            \\\\ \\hline\n\t\\end{tabular}\n\t\\caption{$H^x$, $i=1$}\n\t\\label{table:Hx}\n\t\\end{table}\n\t\n\t\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\t\\hline\n\t\\textbf{i} & \\textbf{j} & \\textbf{k} & \\textbf{sgn} & \\textbf{l} & \\textbf{m} & \\textbf{n} & \\textbf{sgn} \\\\ \\hline\n\t2          & 3          & 1          & +            & 1          & 2          & 3          & +            \\\\ \\hline\n\t2          & 3          & 1          & +            & 1          & 3          & 2          & -            \\\\ \\hline\n\t2          & 1          & 3          & -            & 3          & 1          & 2          & +            \\\\ \\hline\n\t2          & 1          & 3          & -            & 3          & 2          & 1          & -            \\\\ \\hline\n\t\\end{tabular}\n\t\\caption{$H^y$, $i=2$}\n\t\\label{table:Hy}\n\t\\end{table}\n\t\n\t\\subsection*{Evaluate $i=1$, $H^x$}\n\t\n\t\\begin{align}\n\t\ta^3 (\\partial_2 \\partial_1 H^2 - \\partial_2 \\partial_2 H^1) + a^2 (\\partial_3 \\partial_1 H^3 - \\partial_3 \\partial_3 \t\t\t\t\t\t\tH^1) &= \\omega^2 \\mu H^1 \\\\\n\t\ta^3 (\\partial_y \\partial_x H^y - \\partial_y \\partial_y H^x) + a^2 (\\partial_z \\partial_x H^z - \\partial_z \\partial_z \t\t\t\t\t\t\tH^x) &= \\omega^2 \\mu H^x  \n\t\\end{align}\n\t\n\tUsing the fact that $z$ dependence of the field components stands alone, we can evaluate $\\partial_z$ any time. Using eqn \\ref{eqn:partial_z} and \\ref{eqn:H_z}, \n\t\n\t\\begin{align}\n\t\ta^3 (\\partial_y \\partial_x H^y - \\partial_y \\partial_y H^x) + a^2 (- \\partial_x (\\partial_x H^x + \\partial_y H^y) - (- \\beta^2) H^x) &= \\omega^2 \\mu H^x\\\\\n\t\t\\frac{1}{e_{zz}} (\\partial_y \\partial_x H^y - \\partial_y \\partial_y H^x) + \\frac{1}{e_{yy}} ( \\beta^2 H^x- \\partial_x\\partial_x H^x - \\partial_x \\partial_y H^y) &= \\omega^2 \\mu \\epsilon_0 H^x\\\\\n\t\t\\frac{e_{yy}}{e_{zz}} (\\partial_y \\partial_x H^y - \\partial_y \\partial_y H^x) + \\beta^2 H^x- \\partial_x\\partial_x H^x - \\partial_x \\partial_y H^y &= e_{yy} \\omega^2 \\mu \\epsilon_0 H^x\\\\\n\t\t\\Aboxed{e_{yy} \\omega^2 \\mu \\epsilon_0 H^x + \\partial_x\\partial_x H^x + \\partial_x \\partial_y H^y - \\frac{e_{yy}}{e_{zz}} \\partial_y \\partial_x H^y + \\frac{e_{yy}}{e_{zz}} \\partial_y \\partial_y H^x &= \\beta^2 H^x}\n\t\t\\label{eqn:4a}\n\t\\end{align}\n\t\n\t\\subsection*{Evaluate $i=2$, $H^y$}\n\t\n\t\\begin{align}\n\t\ta^1 (\\partial_3 \\partial_2 H^3 - \\partial_3 \\partial_3 H^2) + a^3 (\\partial_1 \\partial_2 H^1 - \\partial_1 \\partial_1 \t\t\t\t\t\t\tH^2) &= \\omega^2 \\mu H^2 \\\\\n\t\ta^1 (\\partial_z \\partial_y H^z - \\partial_z \\partial_z H^y) + a^3 (\\partial_x \\partial_y H^x - \\partial_x \\partial_x \t\t\t\t\t\t\tH^y) &= \\omega^2 \\mu H^y \\\\\n\t\ta^1 ( - \\partial_y (\\partial_x H^x + \\partial_y H^y) - (-\\beta^2) H^y) + a^3 (\\partial_x \\partial_y H^x - \\partial_x \\partial_x H^y) &= \\omega^2 \\mu H^y \\\\\n\t\t\\frac{1}{e_{xx}} (\\beta^2 H^y - \\partial_y \\partial_x H^x - \\partial_y \\partial_y H^y) + \\frac{1}{e_{zz}} (\\partial_x \\partial_y H^x - \\partial_x \\partial_x H^y) &= \\omega^2 \\mu \\epsilon_0  H^y \\\\\n\t\t\\Aboxed{e_{xx} \\omega^2 \\mu \\epsilon_0 H^y + \\partial_y \\partial_x H^x + \\partial_y \\partial_y H^y - \\frac{e_{xx}}{e_{zz}} \\partial_x \\partial_y H^x + \\frac{e_{xx}}{e_{zz}} \\partial_x \\partial_x H^y &= \\beta^2 H^y}\n\t\t\\label{eqn:4b}\n\t\\end{align}\n\t\n\tTo be consistent Fallahkhair and Murphy, we assume transverse components have continuous second partials. Therefore, $\\partial_x \\partial_y = \\partial_y \\partial_x$. We can consolidate terms in \\ref{eqn:4a} and \\ref{eqn:4b} to be\n\t\n\t\\begin{align}\n\t\t\\Aboxed{\\omega^2 \\mu \\epsilon_0 e_{yy} H^x + \\partial_x\\partial_x H^x + (1 - \\frac{e_{yy}}{e_{zz}}) \\partial_y \\partial_x H^y + \\frac{e_{yy}}{e_{zz}} \\partial_y \\partial_y H^x &= \\beta^2 H^x} \n\t\t\\label{eqn:4a*}\\\\\n\t\t\\Aboxed{\\omega^2 \\mu \\epsilon_0 e_{xx} H^y + \\partial_y \\partial_y H^y + (1 - \\frac{e_{xx}}{e_{zz}}) \\partial_x \\partial_y H^x + \\frac{e_{xx}}{e_{zz}} \\partial_x \\partial_x H^y &= \\beta^2 H^y}\n\t\t\\label{eqn:4b*}\n\t\\end{align}\n\t\n\t\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[scale=0.5]{grid.png}\n\t\t\\caption{Fig 1}\n\t\t\\label{fig:grid_points}\n\t\\end{figure}\n\t\n\tWe use the following approximations, using the convention in Fig $\\ref{fig:grid_points}$.\n\t\\begin{align*}\n\t\t\\Partialsqx{H_x^p} &= \\frac{H_x^w + H_x^e - 2H_x^p}{(\\Delta x)^2} \\\\\n\t\t\\Partialsqy{H_x^p} &= \\frac{H_x^s + H_x^n - 2H_x^p}{(\\Delta y)^2} \\\\\n\t\t\\frac{\\partial^2 H_x^p}{\\partial x \\partial y} &= \\frac{H_x^{ne} + H_x^{sw} - H_x^{nw} - \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tH_x^{se}}{4(\\Delta x)(\\Delta y)}\\\\\n\t\t\\frac{\\partial^2 H_x^p}{\\partial x \\partial y} &= \\frac{\\partial^2 H_x^p}{\\partial y \\partial x}\n\t\\end{align*}\n\t\n\tto discretize eqn \\ref{eqn:4a*} and \\ref{eqn:4b*}\n\t \n\t\\begin{align}\n\t\\begin{split}\n\t\t\\beta^2 H^x_p = \\omega^2 \\mu \\epsilon_0 H^x_p &+ \\frac{H_x^w + H_x^e - 2H_x^p}{(\\Delta x)^2} + (1 - \\frac{e_{yy}}{e_{zz}}) \\frac{H_y^{ne} + H_y^{sw} - H_y^{nw} - H_y^{se}}{4(\\Delta x)(\\Delta y)} + \\frac{e_{yy}}{e_{zz}} \\frac{H_x^s + H_x^n - 2H_x^p}{(\\Delta y)^2} \n\t\t\\label{eqn:4a_descrete}\t\t\n\t\t\\end{split}\n\t\\end{align}\n\t\n\t\\begin{align}\n\t\\begin{split}\n\t\t\\beta^2 H^y_p = \\omega^2 \\mu \\epsilon_0 H^y_p &+ \\frac{H_y^s + H_y^n - 2H_y^p}{(\\Delta y)^2}  + (1 - \\frac{e_{xx}}{e_{zz}}) \\frac{H_x^{ne} + H_x^{sw} - H_x^{nw} - H_x^{se}}{4(\\Delta x)(\\Delta y)} + \\frac{e_{xx}}{e_{zz}} \\frac{H_y^w + H_y^e - 2H_y^p}{(\\Delta x)^2} \n\t\t\\label{eqn:4b_descrete}\n\t\\end{split}\n\t\\end{align}\n\t\n\tThe coefficients in \\ref{eqn:4a_descrete} and \\ref{eqn:4b_descrete} are all to be evaluated at corresponding points they are multiplied with. We have an efficient scheme for this described in the next section.\\\\\n\t\n\t\\begin{align}\n\t\\begin{split}\n\t\t\\beta^2 H^x_p = L_1 H^x_p &+ L_2(H^x_w + H^x_e - 2H^x_p) + L_3 (H^y_{ne} + H^y_{sw} - H^y_{nw} - H^y_{se}) + L_3 (H^x_s + H^x_n - 2H^x_p) \n\t\t\\label{eqn:4a_descrete*}\t\t\n\t\t\\end{split}\n\t\\end{align}\n\t\n\t\\begin{align}\n\t\\begin{split}\n\t\t\\beta^2 H^y_p = K_1 H^y_p &+ K_2(H^y_s + H^y_n - 2H^y_p)  + K_3(H^x_{ne} + H^x_{sw} - H^x_{nw} - H^x_{se})+ K_4(H^y_w + H^y_e - 2H^y_p) \n\t\t\\label{eqn:4b_descrete*}\n\t\\end{split}\n\t\\end{align}\n\t\n\t\\section*{Constructing the EigenMatrix - General Idea}\n\t\t\n\t\t\\indent The general idea is to \"unwrap\" the columns of the calculation window into one long column vector and create a matrix of relationships between the elements. In the scalar wave code, we were able to execute a \"brute force\" method by supplying the entries of that matrix. But with the vector wave, the matrix gets large fast and we run out of memory fast. So the trick is to create a \"sparse\" matrix using sparse() which creates a list of entries and their values. Entries corresponding to values of 0 are effectively null and don't take up memory. \\\\\n\t\t\\indent We will \"unwrap\" the computational window into a single column. So solving the transverse magnetic field becomes an eigenvalue problem. The \"EigenMatrix\" contains the coefficients relating the components of the transverse field. A transverse component, say $H^x$, has a value at every point of the $M \\times N$ computational window. \\\\\n\t\t\n\t\t\t\\begin{center}\n\t\t\t$H^x$ = \n\t\t\t$\\begin{bmatrix}\n\t\t\t\t1 & M+1 &  \\hdots &  \\\\\n\t\t\t\t2 & M+2 &    &    \\\\\n\t\t\t\t3 & M+3 &  \\ddots &   \\vdots \\\\\n\t\t\t\t\\vdots & \\vdots &    & \\vdots \\\\\n\t\t\t\tM &  & \\hdots   & MN \n\t\t\t\\end{bmatrix}  \n\t\t\t\\rightarrow\n\t\t\t\\begin{bmatrix}\n\t\t\t1 \\\\ 2 \\\\ 3 \\\\ \\vdots \\\\ \\vdots \\\\ \\vdots \\\\ nx*ny \n\t\t\t\\end{bmatrix}  $\\\\\n\t\t\t\n\t\t\\end{center}\n\t\t\n\t\tWe want to unwrap $H^x$ and $H^y$ and glue them together to get the following\n\t\t\\begin{center}$\n\t\t\t\\begin{bmatrix}\n\t\t\t\tEigenMatrix\n\t\t\t\\end{bmatrix}\n\t\t\t\\begin{bmatrix}\n\t\t\t\tH_x \\\\ H_y\n\t\t\t\\end{bmatrix}\n\t\t\t\\rightarrow\n\t\t\t\\begin{bmatrix}\n\t\t\t\tEigenMatrix\n\t\t\t\\end{bmatrix}\n\t\t\t\\begin{bmatrix}\n\t\t\t\tH_1 \\\\ H_2 \\\\ \\vdots \\\\ H_{MN} \\\\ H_{MN+1} \\\\ \\vdots \\\\ H_{2MN}\n\t\t\t\\end{bmatrix}\n\t\t$\\end{center}\n\t\t \t\t \n\t\t Table \\ref{table:calculation_matrix_diagram} shows a diagram for the matrices we have to construct. The inner parts, marked x, are of size $M \\times N$. They are $MN$ entries describing our waveguide, consistent with the refractive index matrix. But for calculation purposes, we have to construct an $M+2 \\times N+2$ size matrix because sparse() requires arguments of consistent dimensions and because we need to approximate the edge points. The padding entries are constructed using the edge entries. \n\t\t \n\t\t \\begin{table}[h]\n\t\t\\centering\n\t\t\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}\n\t\t\\hline\n\t\t\t &   &   &   &   &   &   &   &   &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t & x & x & x & x & x & x & x & x &  \\\\ \\hline\n\t\t\t &   &   &   &   &   &   &   &   &  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\caption{Calculation Matrix Diagram}\n\t\t\\label{table:calculation_matrix_diagram}\n\t\\end{table}\t\n\t\n\t\n\t\t \n\t\t\\section*{Coordinate Entries}\n\t\t\tWe see from the diagram above Table \\ref{table:calculation_matrix_diagram} that the $M \\times N$ entries for both the $H_x$ and $H_y$ matrices correspond to some column of the eigenMatrix. We need to keep track of the relationship between the entries in those and their corresponding entries in our unwrapped column. So lets create two $M \\times N$ matrix of \"coordinates\" that label each entry with their corresponding entry in the column vector.\\\\\n\t\t\t\n\t\t\t\\begin{center}\n\t\t\t$Hx\\_coord = \n\t\t\t\\begin{bmatrix}\n\t\t\t\t1 & M+1 &  \\hdots &  \\\\\n\t\t\t\t2 & M+2 &    &  \\\\\n\t\t\t\t3 & M+3 &  \\ddots & \\vdots \\\\\n\t\t\t\t\\vdots &    &  & \\vdots \\\\\n\t\t\t\tM &  & \\hdots   & MN \n\t\t\t\\end{bmatrix} \n\t\t\t\\linebreak \\linebreak\n\t\t\tHy\\_coord = \n\t\t\t\\begin{bmatrix}\n\t\t\t\tMN+1  &  \\hdots &  \\\\\n\t\t\t\tMN+2  &    &  \\\\\n\t\t\t\tMN+3   \\ddots & \\vdots \\\\\n\t\t\t\t\\vdots &      & \\vdots \\\\\n\t\t\t\t... &  \\hdots   & 2MN \n\t\t\t\\end{bmatrix} $\n\t\t\t\\end{center}\n\n%\t\t\\subsection*{Example}\n%\t\t\tRefer to Fig \\ref{fig:grid_points} and Eqn \\ref{eqn:H_x*}. Suppose some point $p$ under consideration corresponds %to column 12. Then the point $p$ itself for $H_x$, denote $H_x^p$, will correspond to the matrix coordinate (13,13). The $nw$ %point relative to $p$ for $H_x$, denote $H_x^{nw}$, will correspond to the matrix coordinate (13-(M+2)-1,13). The point $p$ %for $H_y$ relative to $p$, denote $H_y^p$, will correspond to the matrix coordinate (13+(M+2)(N+2), 13+(M+2)(N+2)). \n\n\t\t\t\n%\t\t\\section*{Tensor Entries}\n%\t\t\tMatrices containing information on our waveguide include matrices corresponding to $\\epsilon_{xx}, \\epsilon_{yy}, %\\epsilon_{zz}, n$. Each of these are MxN matrices containing their corresponding values at each point in the waveguide. They %will be padded the same way as above turning each into a M+2 x N+2 matrix. \n\t\t\t\n%\t\t\\section*{The Indexer Matrix}\n%\t\t\tSo far, our matrices have been padded along each edge and contain values we need for processing or calculating. We %now construct an indexing matrix to use for pulling these values. It will be an M+2 x N+2 matrix \n%\t\t\t\\begin{center}\n%\t\t\t$ index = \n%\t\t\t\\begin{bmatrix}\n%\t\t\t\t1 & M+3 &  \\hdots &  \\\\\n%\t\t\t\t2 & M+4 &    &    \\\\\n%\t\t\t\t3 & M+5 &  \\ddots &   \\vdots \\\\\n%\t\t\t\t\\vdots & \\vdots &    & \\vdots \\\\\n%\t\t\t\tM+2 &  & \\hdots   & (M+2)(N+2) \n%\t\t\t\\end{bmatrix}  \n%\t\t\t$\\\\\n%\t\t\t\\end{center}\n\t\t\t\n%\t\t\t\\subsection*{Example}\n%\t\t\t$index(2:M-1, 2)$ contains entries corresponding to the left edge of our waveguide.\n\t\n\t\n\t\t\n\t\n\\end{document}\n              ", "meta": {"hexsha": "9bc9ba16101546edf5e6fecf7a03259afd11bb5a", "size": 17038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Derivation of Hybrid Modes.tex", "max_stars_repo_name": "psukphranee/Waveguide-Mode-Solver-CPP", "max_stars_repo_head_hexsha": "aa52af76e42ad20703794fcc0e7c2ab3f9e20922", "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": "Derivation of Hybrid Modes.tex", "max_issues_repo_name": "psukphranee/Waveguide-Mode-Solver-CPP", "max_issues_repo_head_hexsha": "aa52af76e42ad20703794fcc0e7c2ab3f9e20922", "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": "Derivation of Hybrid Modes.tex", "max_forks_repo_name": "psukphranee/Waveguide-Mode-Solver-CPP", "max_forks_repo_head_hexsha": "aa52af76e42ad20703794fcc0e7c2ab3f9e20922", "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.6794520548, "max_line_length": 559, "alphanum_fraction": 0.6008334312, "num_tokens": 6506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924954, "lm_q2_score": 0.7718435083355188, "lm_q1q2_score": 0.6448625539197154}}
{"text": "\\documentclass{article}\n\\input{shared_preamble.tex}\n\\title{Exercises for Chapter 2: Linear Algebra}\n\\begin{document}\n\\maketitle\n\n\\section*{Exercises}\n\\begin{enumerate}\n\\item The expression $\\alpha \\vu$ for $\\alpha \\in \\R$ and\nunit vector $\\vu \\in \\R^n$ defines a line of points that may be obtained by varying the\nvalue of $\\alpha$.\nDerive an expression for the point $\\vy$ that lies on this line that is\nas close as possible to an arbitrary point $\\vx \\in \\R^n$.\nThis operation of replacing a point by its nearest member within some set\nis called {\\em projection}.\n\n\n{\\em Exercise contributed by Ian Goodfellow}\n\\end{enumerate}\n\n\\section*{Solutions}\n\\begin{enumerate}\n\\item We begin by defining the distance from $\\vy$ to $\\vx$. We would like to\nfind the $\\vy$ that minimizes this distance:\n\\begin{equation}\n|| \\vx - \\vy||^2.\n\\end{equation}\nNext, we need to enforce the constraint that $\\vy$ lies on the line defined\nby $\\alpha \\vu$. We can do this simply by defining $\\vy$ to be $\\alpha \\vu$.\n\\begin{equation}\n|| \\vx - \\alpha \\vu ||^2.\n\\end{equation}\nNext, we expand the expression:\n\\begin{align}\n& || \\vx - \\alpha \\vu ||^2 \\\\\n=& ( \\vx - \\alpha \\vu )^\\top (\\vx - \\alpha \\vu) \\\\\n=& \\vx^\\top \\vx - 2 \\alpha \\vx^\\top \\vu + \\alpha^2 \\vu^\\top \\vu \\\\\n=& \\vx^\\top \\vx - 2 \\alpha \\vx^\\top \\vu + \\alpha^2.\n\\end{align}\nIn the last line, we used the fact that $\\vu$ is a unit vector to make\nthe simplification $\\vu^\\top \\vu = 1$.\n\nWe can minimize this distance by taking the derivative with respect to\n$\\alpha$ and setting it to zero:\n\\begin{align}\n& - 2  \\vx^\\top \\vu + 2 \\alpha = 0 \\\\\n\\Rightarrow & \\alpha = \\vx\\top \\vu.\n\\end{align}\n\nRecalling that $\\vy = \\alpha \\vu$, we can conclude that $\\vy = \\vx^\\top \\vu \\vu$.\n\n{\\em Solution contributed by Ian Goodfellow}\n\n\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "9e3972d6c0b971874938834dc5f52419719f2878", "size": 1789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear_algebra.tex", "max_stars_repo_name": "mcococcioni/dlbook_exercises", "max_stars_repo_head_hexsha": "5b643c1a41a35da44a61190b35772969c306ca2b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1167, "max_stars_repo_stars_event_min_datetime": "2016-04-10T21:25:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T18:06:15.000Z", "max_issues_repo_path": "linear_algebra.tex", "max_issues_repo_name": "mcococcioni/dlbook_exercises", "max_issues_repo_head_hexsha": "5b643c1a41a35da44a61190b35772969c306ca2b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-04-17T12:20:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-02T09:26:03.000Z", "max_forks_repo_path": "linear_algebra.tex", "max_forks_repo_name": "mcococcioni/dlbook_exercises", "max_forks_repo_head_hexsha": "5b643c1a41a35da44a61190b35772969c306ca2b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 342, "max_forks_repo_forks_event_min_datetime": "2016-04-11T08:20:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T17:58:37.000Z", "avg_line_length": 30.8448275862, "max_line_length": 87, "alphanum_fraction": 0.6802683063, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6448625419883657}}
{"text": "\\section{Evaluating Information Retrieval}\n\\label{sec:EvaluatingInformationRetrieval}\n\n% ##############################################################################\n\\subsection{Evaluating Bounding Box Prediction}\n\\label{ssec:EvaluatingBoundingBoxPrediction}\n\n\\subsubsection{Intersection Over Union}\n\\label{sssec:IntersectionOverUnion}\n\n\\glslocalreset{iou}\n\n\\gls{iou} measures the overlap between two \\glspl{bbox}. Let $\\subsup{\\vect{b}}{1}{T} = \\sbrackets{x_1, y_1, w_1, h_1}$ and $\\subsup{\\vect{b}}{2}{T} = \\sbrackets{x_2, y_2, w_2, h_2}$ be two \\glspl{bbox} described by vectors containing $4$ elements. The respective elements are given by $x$, $y$ coordinates of the top-left corner and the \\gls{bbox} width and height. The intersection area between $\\vect{b}_1$ and $\\vect{b}_2$ is defined as\n\\begin{equation}\n    \\begin{aligned}\n        \\vect{b}_1 \\cap \\vect{b}_2 =\n         & \\max \\cbrackets{0,\n            \\min \\cbrackets{x_1 + w_1, x_2 + w_2} - \\max \\cbrackets{x_1, x_2} + 1}\n        \\times                \\\\\n         & \\max \\cbrackets{0,\n            \\min \\cbrackets{y_1 + h_1, y_2 + h_2} - \\max \\cbrackets{y_1, y_2} + 1},\n    \\end{aligned}\n\\end{equation}\nand the area of their union is given by\n\\begin{equation}\n    \\vect{b}_1 \\cup \\vect{b}_2 = w_1 h_1 + w_2 h_2 - \\vect{b}_1 \\cap \\vect{b}_2.\n\\end{equation}\nThen, the final \\gls{iou} metric between $\\vect{b_1}$ and $\\vect{b_2}$ is computed as (\\figtext{}~\\ref{fig:IntersectionOverUnion})\n\\begin{equation}\n    \\label{eq:IntersectionOverUnion}\n    \\func{\\IOU}{\\vect{b}_1, \\vect{b}_2} =\n    \\frac{\\vect{b}_1 \\cap \\vect{b}_2}{\\vect{b}_1 \\cup \\vect{b}_2},\n\\end{equation}\nwhere $0 \\leq \\func{\\IOU}{\\vect{b}_1, \\vect{b}_2} \\leq 1$, such that value of $0$ represents no intersection, while value of $1$ represents a complete overlap. In terms of object detection or object tracking evaluation, an \\gls{iou} threshold, $t$, such that $0 \\leq t \\leq 1$, can be associated with this metric, denoting the decision boundary between \\gls{tp} and \\gls{fp}.\n\n% ------------------------------------------------------------------------------\n\\begin{figure}[t]\n    \\centerline{\\includegraphics[width=0.2\\linewidth]{figures/theoretical_foundations/intersection_over_union.pdf}}\n    \\caption[\\gls{iou} visualization]{Computation of the \\gls{iou} metric between two \\glspl{bbox} using of ratio of the area of overlap and the area of the union.}\n    \\label{fig:IntersectionOverUnion}\n\\end{figure}\n% ------------------------------------------------------------------------------\n\n% ##############################################################################\n\\subsection{Mean Average Precision}\n\\label{ssec:MeanAveragePrecision}\n\n\\glslocalreset{map}\n\nA commonly used metric for evaluating tracking algorithms, document searching systems, object detection, and object \\gls{reid} is \\gls{map}. It measures the success rate of an information retrieval algorithm.\n\n\\subsubsection{Object Re-Identification}\n\\label{sssec:ObjectReIdentification}\n\nA frequent use case in the context of object \\gls{reid} is to use \\gls{map} to assess the search results for a particular query using Euclidean distance or cosine similarity as a metric. Oftentimes the model is trained with the intent to use one of these trivial metrics. Furthermore, this approach is often paired with \\emph{top-k} accuracy, typically \\emph{top-1}, \\emph{top-2} and \\emph{top-5}.\n\nIn a typical \\gls{reid} evaluation setup, there is a query set and a gallery set. For each object in the query set the aim is to retrieve a similar identity from the gallery set. The computation of the \\gls{ap} for a query image $q$ is thus defined as\n\\begin{equation}\n    \\label{eq:AveragePrecision}\n    \\func{\\AP}{q} = \\frac{1}{\\func{N_{gt}}{q}} \\sum_{k} \\func{P}{k} \\times {\\delta}_k,\n\\end{equation}\nwhere $\\func{P}{k}$ represents precision at rank $k$, $\\func{N_{gt}}{q}$ is the total number of true retrievals for the query $q$. The indicator ${\\delta}_k$ is equal to $1$ when the matching of query image $q$ to a test image is correct at rank $r$, such that $1 \\leq r \\leq k$. The \\gls{map} is then calculated as average over all query images, concretely\n\\begin{equation}\n    \\label{eq:MeanAveragePrecision}\n    \\MAP = \\frac{1}{Q} \\sum_q \\func{\\AP}{q},\n\\end{equation}\nwhere $Q$ is the total number of query images, as described in~\\cite{kuma2019vehiclereid}. \\eqtext{}~\\ref{eq:MeanAveragePrecision} tells us that, for a given query $q$, we calculate its corresponding \\gls{ap} (\\eqtext{}~\\ref{eq:AveragePrecision}), and then take the mean of the all these \\gls{ap} scores.\n\n\\subsubsection{Object Detection}\n\nObject detectors seek to identify the presence of objects in images. The evaluation metric of such a model has to take the \\gls{bbox} prediction into account, as there can be just a partial overlap of the predicted \\gls{bbox} with the ground truth one.\n\nIn a ranked retrieval context, appropriate sets of retrieved documents are naturally given by the \\emph{top-k} retrieved documents and for each such set, the \\gls{pr} curve can be plotted. With this in mind, recall is defined as the proportion of all positive examples ranked above a given rank. Precision is the proportion of all examples above that rank which are from the positive class. In~\\cite{everingham2010pascalvoc}, the \\gls{ap} is computed for $11$ equally spaced discrete recall levels, specifically $\\sbrackets{0.0, 0.1, 0.2, \\dots, 1.0}$, using\n\\begin{equation}\n    \\AP = \\frac{1}{11} \\sum_{r \\in \\cbrackets{0.0, 0.1, \\dots, 1.0}} \\func{p_{interp}}{r},\n\\end{equation}\nwhere the precision at each recall level $r$ is interpolated by taking the maximum precision measured for a method for which the corresponding recall exceeds $r$. Precision interpolation is used to remove the \\emph{zig-zag} pattern by evaluating\n\\begin{equation}\n    \\func{p_{interp}}{r} = \\underset{\\tilde{r}:\\tilde{r} \\geq r}{\\max} \\quad \\func{p}{\\tilde{r}},\n\\end{equation}\nwith $\\func{p}{\\tilde{r}}$ representing the measures precision at a specific recall level $\\tilde{r}$~\\cite{salton1983introduction}.\n", "meta": {"hexsha": "601c53adea67abcecce5cd9a82cd385e5831a670", "size": 6040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapters/theoretical_foundations/sections/evaluating_information_retrieval.tex", "max_stars_repo_name": "mondrasovic/phd_thesis", "max_stars_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_stars_repo_licenses": ["MIT"], "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/chapters/theoretical_foundations/sections/evaluating_information_retrieval.tex", "max_issues_repo_name": "mondrasovic/phd_thesis", "max_issues_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_issues_repo_licenses": ["MIT"], "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/chapters/theoretical_foundations/sections/evaluating_information_retrieval.tex", "max_forks_repo_name": "mondrasovic/phd_thesis", "max_forks_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_forks_repo_licenses": ["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.6585365854, "max_line_length": 558, "alphanum_fraction": 0.6880794702, "num_tokens": 1774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6448625381109983}}
{"text": "%==============================================================================\n\\chapter{Harmonic Oscillators}\n\\label{chap:harosc}\n%==============================================================================\n\n%------------------------------------------------------------------------------\n\\section{Single Harmonic Oscillator}\n\\label{sec:single-harosc}\n%------------------------------------------------------------------------------\n\nA single harmonic oscillator is described by the Hamiltonian\n\\begin{equation}\nH = \\frac{1}{2}\\rbr{\\pi^2 + \\Omega^2f^2},\n\\label{eq:hamiltonian-simple-harosc}\n\\end{equation}\nwhere $\\rbr{\\pi, f}$ are conjugate momentum and position, respectively. Here\na unit system similar to the case in field theory is adapted. Canonical\nquantisation uses the annihilation and creation operators\n\\begin{equation}\na^- \\coloneqq \\frac{1}{\\sqrt{2}}\\rbr{\\sqrt{\\Omega}f + \n\\frac{\\ii}{\\sqrt{\\Omega}}\\pi}, \\qquad\na^+ \\coloneqq \\frac{1}{\\sqrt{2}}\\rbr{\\sqrt{\\Omega}f\n-\\frac{\\ii}{\\sqrt{\\Omega}}\\pi} \\equiv \\rbr{a^-}^\\dagger;\n\\end{equation}\ninverse expressions read\n\\begin{equation}\nf = \\frac{a^++a^-}{\\sqrt{2\\Omega}},\\qquad\n\\pi = \\ii\\sqrt{\\frac{\\Omega}{2}}\\rbr{a^+-a^-}.\n\\end{equation}\nThe ground state and the normalised $n$th excitation are defined by\n\\begin{equation}\na^-\\Ket{0} \\coloneqq 0,\\qquad\n\\Ket{n} \\coloneqq \\frac{1}{\\sqrt{n!}}\\rbr{a^+}^n\\Ket{0},\\qquad\nn \\in \\BbbZ_+,\n\\end{equation}\nthe wave functions of which are\n\\begin{equation}\n\\Braket{f | n} = \\frac{1}{\\sqrt{2^n n!}} \n\\ee^{-\\Omega f^2/2} \\rfun{H_n}{\\sqrt{\\Omega}f}, \\qquad\nn \\in \\BbbZ,\n\\end{equation}\nwhere $\\rfun{H_n}{x}$ is the $n$th Hermite polynomial. The normalising measure\n\\begin{equation}\n\\rfun{\\dd \\mu}{f} \\coloneqq \\sqrt{\\frac{\\Omega}{\\pp}}\\,\\dd f\n\\end{equation}\nis used throughout, so that the completeness relation holds,\n\\begin{align}\n\\int \\rfun{\\dd \\mu}{f}\\,\\Braket{\\alpha | f}\\Braket{f | \\beta} \\equiv\n\\Braket{\\alpha | \\beta}.\n\\end{align}\n\nIn the present work, a general Gaussian state $\\Ket{\\omega}$ has also been \nconsidered, the wave function of which reads\n\\begin{equation}\n\\Braket{f | \\omega} = \\rbr{\\frac{\\Re\\omega}{\\Omega}}^{1/4}\n\\rfun{\\exp}{-\\frac{\\omega}{2}f^2},\\qquad \\Re \\omega > 0\n\\label{eq:general-single-omega}\n\\end{equation}\nEvaluating the expectation of $f^2$ yields\n\\begin{equation}\n\\abr{f^2}_\\omega \\coloneqq \\Braket{\\omega | f^2 | \\omega}\n= \\rbr{2\\Re \\omega}^{-1}.\n\\label{eq:correlator-1}\n\\end{equation}\n$\\Ket{\\omega}$ can also be expressed in terms of energy eigenstates,\n\\begin{align}\n\\Braket{n | \\omega} &= \\int \\rfun{\\dd \\mu}{f}\\, \\Braket{n | f} \n\\Braket{f | \\omega} \\nonumber \\\\\n&= \\rbr{\\frac{\\Omega \\Re\\omega}{\\pp^2}}^{1/4} \\frac{1}{\\sqrt{2^n n!}}\n\\int_{-\\infty}^{+\\infty} \\dd f\\,\n\\cfun{\\exp}{-\\frac{1}{2}\\rbr{\\Omega+\\omega}f^2}\\rfun{H_n}{\\sqrt{\\Omega}f}\n\\nonumber \\\\\n&= \\begin{cases} \\rbr{\\Omega  \\Re(\\omega )}^{\\frac{1}{4}}\n\\dfrac{2^{\\frac{1}{2}-m} \\sqrt{(2 m)!} }{m!}\n\\dfrac{(\\Omega -\\omega )^m}{(\\omega +\\Omega )^{m+\\frac{1}{2}}}\n& n = 2m, \\\\\n0 & n = 2m+1,\n\\end{cases}\n\\label{eq:n|omega}\n\\end{align}\nthanks to \\cite{Babusci2012}.\n\nA thermal state of the oscillator at temperature $T$ can be described by the\ndensity operator\n\\begin{equation}\n\\rho \\coloneqq \\frac{1}{Z} \\cfun{\\exp}{-\\frac{H}{T}} = \\frac{1}{Z} \n\\sum_{n=0}^{+\\infty} \\cfun{\\exp}{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}} \n\\Ket{n}\\Bra{n},\n% \\nonumber \\\\\n%&= Z^{-1} \\sum_{n=0}^{+\\infty} \n%\\frac{\\ee^{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}}{n!}\n%\\rbr{a^+}^n\\Ket{0}\\Bra{0}\\rbr{a^-}^n,\n\\label{eq:single-thermal-density-mat}\n\\end{equation}\nwhere the partition function is\n\\begin{equation}\nZ \\coloneqq \\tr{\\ee^{-H/T}} = \\frac{1}{2} \\csch\\frac{\\Omega}{2 T}.\n\\end{equation}\nOne also obtains\n\\begin{align}\n\\abr{f^2}_\\rho &= \\frac{1}{2\\Omega}\\frac{1}{Z}\\sum_{n=0}^{+\\infty}\n\\cfun{\\exp}{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}\n\\Braket{n | \\rbr{a^++a^-}^2 | n} \\nonumber \\\\\n%&= \\frac{1}{2\\Omega}\\frac{1}{Z}\\sum_{n=0}^{+\\infty}\n%\\ee^{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}\n%\\Braket{n | \\rbr{\\rbr{a^+}^2+a^+a^-+a^-a^++\\rbr{a^-}^2} | n} \\nonumber \\\\\n&= \\frac{1}{2\\Omega}\\frac{1}{Z}\\sum_{n=0}^{+\\infty}\n\\cfun{\\exp}{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}\n\\Braket{n | \\rbr{2a^+a^-+1} | n} %\\nonumber \\\\\n%&= \\frac{\\coth\\frac{\\Omega}{2 T}}{2\\Omega}\n= \\frac{1}{4T} \\frac{\\coth\\frac{\\Omega}{2 T}}{\\frac{\\Omega}{2 T}}.\n\\label{eq:sho-th-cor-1}\n\\end{align}\n%\\Cref{eq:single-thermal-density-mat} expressed in terms of position basis can\n%also be calculated\n%\\begin{align}\n%\\rho &= \\frac{1}{Z}\n%\\sum_{n=0}^{+\\infty} \\ee^{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}\n%\\int\\rfun{\\dd\\mu}{f_1}\\,\\rfun{\\dd\\mu}{f_2}\\,\n%\\Ket{f_1}\\Braket{f_1 | n}\\Braket{n | f_2}\\Bra{f_2}\n%\\nonumber \\\\\n%&= \\frac{1}{Z} \\int\\rfun{\\dd\\mu}{f_1}\\,\\rfun{\\dd\\mu}{f_2}\\,\\Ket{f_1}\n%\\rbr{\\sum_{n=0}^{+\\infty}\\ee^{-\\frac{\\Omega}{T}\\rbr{n+\\frac{1}{2}}}\n%\\Braket{f_1 | n}\\Braket{n | f_2}}\n%\\Bra{f_2};\n%\\label{eq:thermal-position-basis-1}\n%\\end{align}\n%The summation in \\cref{eq:thermal-position-basis-1} can be closed\n%\\begin{equation}\n%\\rfun{\\dd\\mu}{f_1}\\,\\rfun{\\dd\\mu}{f_2}\\,\n%\\sum_{n=0}^{+\\infty}\\Braket{f_1 | n}\\Braket{n | f_2}\n%= \\dd f_1\\,\\dd f_2 \\rfun{\\delta}{f_1 - f_2},\n%\\end{equation}\n%due to orthonormality and completeness of the bases.\n\n%------------------------------------------------------------------------------\n\\section{Multiple Harmonic Oscillators}\n%------------------------------------------------------------------------------\n\nMultiple harmonic oscillators are described by the Hamiltonian\n\\begin{equation}\nH = \\sum_i H_i,\\qquad H_i = \\frac{1}{2}\\rbr{\\pi_i^2 + \\Omega^2f_i^2},\n\\end{equation}\nwhere $\\rbr{\\pi_i, f_i}$ are conjugate momentum and position of the $i$th\noscillator.\n\nWhen the general Gaussian state\n\\begin{equation}\n\\Braket{\\cbr{f} | \\sbr{\\omega}} = \\rbr{\\det\\frac{\\omega}{\\Omega}}^{1/4} \n\\rfun{\\exp}{-\\frac{1}{2}f_i \\omega_{ij} f_j}\n\\label{eq:general-ij-omega}\n\\end{equation}\nis considered, where $\\omega_{ij}$ is a real symmetric positive-definite\nmatrix, the two-point correlator becomes\n\\begin{equation}\n\\Braket{\\sbr{\\omega} | f_i f_j | \\sbr{\\omega}} = \\sbr{\\rbr{2\\omega}^{-1}}_{ij},\n\\label{eq:multi-har-cor}\n\\end{equation}\nwhich is a generalisation of \\cref{eq:correlator-1}.\n\nA thermal state at temperature $T$ can be described by the density operator\n\\begin{equation}\n\\rho = \\bigotimes_i \\rho_i,\\qquad \\rho_i =\n\\frac{1}{Z} \\rfun{\\exp}{-\\frac{H_i}{T}}.\n\\label{eq:multi-thermal-density-mat}\n\\end{equation}\nComputing the two-point correlator of the state, one finds\n\\begin{equation}\n\\abr{f_if_j}_\\rho = \\frac{\\coth\\frac{\\Omega_i}{2T}}{2\\Omega_i}\n\\delta_{ij}\n= \\frac{1}{4T} \\frac{\\coth\\frac{\\Omega_i}{2T}}{\\frac{\\Omega_i}{2T}} \n\\delta_{ij}\n\\label{eq:correlator-multiple-thermal}\n\\end{equation}\nfrom \\cref{eq:sho-th-cor-1}.\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../mythesis\"\n%%% End: \n", "meta": {"hexsha": "70846df72a7dedc075810a2d9fe13307bda78551", "size": 6743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ubonn-thesis-current/mythesis/sections/thesis_harosc.tex", "max_stars_repo_name": "cmp0xff/Masterarbeit", "max_stars_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_harosc.tex", "max_issues_repo_name": "cmp0xff/Masterarbeit", "max_issues_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_harosc.tex", "max_forks_repo_name": "cmp0xff/Masterarbeit", "max_forks_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": 37.2541436464, "max_line_length": 79, "alphanum_fraction": 0.6024024915, "num_tokens": 2604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6448625337261952}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{nopageno} \n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{April 4, 2014}\n\\maketitle\n\\section*{7.2 generating functions}\nwe have fibonacci \\#'s $0,1,1,2,3,5,8,\\dots$. We wish to construct an algebraic function which encodes this sequence (or any sequence of numbers)\n\nGiven a sequence $h_0,h_1,h_2,h_3,\\dots$ define it's generating function to be the infinite series $g(x)=h_0+h_1x+h_2x^2+h_3x^3+\\dots$\n\n\\subsubsection*{example}\nGenerating function for the fibanocci numbers is $f(x)=0+1\\cdot x+1\\cdot x^2+2\\cdot x^3+3\\cdot x^4+\\dots$.\n\n\\subsubsection*{goal}\nexpress generating functions in closed form.\n\n\\subsubsection*{example}\nfind the generating function for the sequence $1,1,1,\\dots$. Generating function is $f(x)=1+x+x^2+x^3+\\dots=\\frac{1}{1-x}$. this is the geometric series formula.\n\n\\subsubsection*{example}\nFind the generating function for the sequence $1,1,1,\\dots,1,0,0,\\dots$. This is a finite series.\n\\[f(x)=1+x+x^2+\\dots+x^{n-1}=\\frac{1-x^n}{1-x}\\]\n,\n\\subsubsection*{example}\nwhat is the generating function for the sequence for $\\binom{n}{0},\\binom{n}{1},\\binom{n}{2},\\binom{n}{3},\\dots,\\binom{n}{n},0,0,\\dots$. binomial theorem\n\\[f(x)=(1+x)^n\\]\n\nor if $\\alpha\\in\\mathbb{R}$ the generating function for $\\binom{\\alpha}{0},\\binom{\\alpha}{1},\\binom{\\alpha}{2},\\binom{\\alpha}{3},\\dots,\\binom{\\alpha}{n},0,0,\\dots$\n\\begin{enumerate}\n\\setcounter{enumi}{12}\n\\item\n\\begin{enumerate}\n\\item\n$\\frac{1}{1-cx}$\n\\item\n$\\frac{1}{1+x}$\n\\setcounter{enumii}{3}\n\\item\n$e^x$\n\\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection*{example}\nthe generating function for the fibonacci numbers is $f(x)=0+x+x^2+2x^3+3x^4+\\dots$\n\\begin{align*}\n  \\sum\\limits_{n=1}^\\infty{f_nx^n}&=f_0+f_1x+\\sum\\limits_{n=2}^\\infty{f_nx^n}\\\\\n  &=0+x+\\sum\\limits_{n=0}^\\infty{f_{n+2}x^{n+2}}\\\\\n  &=x+x^2\\sum\\limits_{n=0}^\\infty{(f_{n+1}+f_n)x^n}\\\\\n  &=x+x^2\\sum\\limits_{n=0}^\\infty{f_{n+1}x^n}+x^2\\sum\\limits_{n=0}^\\infty{f_nx^n}\\\\\n  &=x+x\\sum\\limits_{n=0}^\\infty{f_{n}x^n}+x^2\\sum\\limits_{n=0}^\\infty{f_nx^n}\\\\\n  (1-x-x^2)\\sum\\limits_{n=0}^\\infty{f_{n}x^n}&=x\\\\\n  f(x)&=\\frac{x}{1-x-x^2}\n\\end{align*}\n\\subsubsection*{example}\nfind the generating function for $h_0,h_1,h_2,h_3,\\dots$ where $h_n=\\#$ n-combinations fo $\\{\\infty\\cdot e_1,\\infty\\cdot e_2,\\infty\\cdot e_3,\\infty\\cdot e_4\\}$\n\nfind $g(x)=\\sum\\limits_{k=0}^\\infty{h_kx^k}$ so $h_n$ is the coefficient of $x^n$. $h_n=\\#$ non-negative solutions: $e_1+e_2+e_3+e_4=n=\\binom{n+4-1}{n}$ so $x^n=x^{e_1}x^{e_2}x^{e_3}x^{e_4}$ so consider the product $(1+x+x^2+\\dots)(1+x+x^2+\\dots)(1+x+x^2+\\dots)(1+x+x^2+\\dots)$ with each term coming from $x^{e_n}$. Generating function is $\\frac{1}{(1-x)^4}$\n\\end{document}\n", "meta": {"hexsha": "06608210940132b43f4f8ef66a8259e93c3d3ffd", "size": 2790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-notes-04-04.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-notes-04-04.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-notes-04-04.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": 41.6417910448, "max_line_length": 358, "alphanum_fraction": 0.6784946237, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6448625337261952}}
{"text": "\\chapter{Cryptography}\n\nAuthentication, Integrity, and Confidentiality are the three objectives of secure communications. Authentication guarantees that a message comes from the source that it claims to come from. Integrity ensures that messages are not altered in transit. Confidentiality ensures so that only the receiver can read the message.\\\\\n\nEncryption and hashing are used to make certain that only authorized entities can read the message (Confidentiality). The receiver can verify that the received message is identical to the sent message and that no manipulation occurred (Integrity). \\\\\n\n\n\n\\section{Hash function}\n\nA hash function takes the message and produces a fixed-length and condensed bit string, called the hash value or message digest. Hashing is based on a one-way mathematical function that is relatively easy to compute, but significantly harder to reverse. The cryptographic hashing function can provide proof of authenticity (IPsec, routing protocol, CHAP) and message integrity check proof.\\\\\n\nMD5 produces a 128-bit hashed message digest and is now considered a legacy algorithm.\\\\\n\nThe SHA-1 algorithm produces a 160-bit message digest and is slightly slower than MD5, but the larger message digest makes it more secure against brute-force collision and inversion attacks. SHA-1 is now considered to be a legacy algorithm. It is recommended to use the SHA-2 family of hash functions, which are SHA-224 (224 bit), SHA-256 (256 bit), SHA-384 (384 bit), SHA-512 (512 bit). \\\\\n\nA keyed-hash message authentication code (HMAC or KHMAC) use a secret key as input to the hash function. This adds authentication to integrity assurance. The mechanism of HMAC is that two parties share a secret key and use HMAC functions for authentication. Only parties who have access to that secret key can compute the digest of an HMAC function. This characteristic defeats man-in-the-middle attacks. Cisco technologies use two well-known HMAC functions: legacy Keyed MD5 (HMAC-MD5) and Keyed SHA-1 (HMAC-SHA-1).\\\\\n\nTwo terms that are used to describe keys are: Key length (key size) and Keyspace (the number of possibilities that can be generated by a specific key length). As key length increase, the keyspace increases exponentially, which affects the time it takes to crack the code. Longer keys are more secure; however, they are also more resource intensive.\n\n\\section{Encryption}\n\nCryptographic encryption can provide confidentiality at several layers of the OSI model. For example, the IPsec for network layer protocols. Secure Sockets Layer (SSL) or Transport Layer Security (TLS), provide session layer confidentiality. MD5, Keyed MD5, and Secure Hash Algorithm 1 are examples of hash functions. They provide data integrity but not data confidentiality.\\\\\n\nThere are two classes of encryption algorithms: Symmetric algorithms and Asymmetric algorithms.\n\n\\subsection{Symmetric algorithms}\n\nSymmetric algorithms use the same pre-shared key on both parties and the key is shorter, meaning faster execution. The encryption and decryption keys are the same. The sender and the receiver must exchange the secret key using a secure channel before any encryption can occur. By obtaining the key, anyone can encrypt and decrypt messages. DES, 3DES, AES, Software Encryption Algorithm (SEAL), and the Rivest ciphers (RC) series are all well-known encryption algorithms that use symmetric keys.\\\\\n\nThe most commonly used techniques in symmetric encryption cryptography are block ciphers and stream ciphers. Block ciphers transform a fixed-length block of plaintext into a common block of ciphertext of 64 or 128 bits. Unlike block ciphers, stream ciphers encrypt plaintext one byte or one bit at a time.\\\\\n\nTwo main criteria that should be considered when selecting an encryption algorithm for an organization: The algorithm is trusted by the cryptographic community, The algorithm adequately protects against brute-force attacks.\\\\\n\n%Data Encryption Standard (DES) is a block cipher that uses 64bit key, of which 56 bits are used for encryption. The remaining 8 bits are used for parity. When forced to use DES, change keys frequently, use a secure channel to communicate the DES key, and use cipher block chaining (CBC) mode.​ \\\\ \n\nOne way to increase the DES effective key length is to use the same algorithm with different keys several times in a row. The technique of applying DES three times in a row to a plaintext block is called 3DES. The Cisco IPsec implementation uses DES and 3DES in CBC mode.\\\\\n\nAlthough 3DES is very secure, it is also resource intensive. To better manage resources, AES was chosen to replace DES. It has stronger key and runs faster than DES. Despite these advantages, AES is a relatively young algorithm. A mature algorithm, like 3DES, is always more trusted.\\\\\n\nThe Software-Optimized Encryption Algorithm (SEAL) is a stream cipher that uses a 160-bit encryption key. Because it is a stream cipher, data to be encrypted is continuously encrypted, which makes it much faster than block ciphers. SEAL has several restrictions: IPsec and Security version IOS are required, The router and the peer must not have hardware IPsec encryption.\\\\\n\nThe stream cipher RC4 is often used in file encryption products and for secure communications, such as within SSL. It can be implemented insecurely, as in Wired Equivalent Privacy (WEP). RC5 is a fast block cipher that can be used as a drop-in replacement for DES if the block size is set to 64-bit. RC6 is a 128-bit to 256-bit block cipher that is based on RC5 and was designed to meet the requirement of AES.\\\\\n\n\\subsection{Asymmetric algorithms}\n\nAsymmetric algorithms use different keys to encrypt and decrypt data. One key is called the private key, and the other is the public key. The private key is secret and known only to the user. The public key is openly shared and easily distributed. Secure messages can be exchanged without having to have a pre-shared key. Because neither party has a shared secret, very long key lengths must be used. These algorithms are resource intensive and slower to execute. Some well-known asymmetric algorithms: DH, RSA, DSS,\tDSA. Asymmetric algorithms are slow, so they are commonly used in low-volume transactions such as making online purchases or logging into a financial website.\\\\\n\n\\textbf{Diffie-Hellman (DH)} Algorithm allows two computers to generate an identical shared secret on both systems, without having communicated before.  To start a DH exchange, both hosts must agree on two nonsecret numbers. The first number is a base number, also called the generator. The second number is a prime number that is used as the modulus. DH is commonly used in IKE (fundamental component of IPsec VPNs), SSL, TLS, and SSH. It is common to use DH algorithm to create and exchange pre-shared keys for symmetric algorithm (3DES or AES).\\\\\n\n\\textbf{Digital signatures} are commonly used in Code signing and Digital certificate. Code signing verifies the integrity of executable files downloaded from a vendor website. Digital certificates verify the identity of a vendor website and establish an encrypted connection. Digital signatures provide three basic security services: Authenticity, Integrity, and Nonrepudiation of the transaction\\footnote{Nonrepudiation uses the unique characteristics of the sender of a message to confirm that the reputed sender is in fact the actual sender.}.\\\\\n\nThe \\textbf{Public Key Infrastructure (PKI)} identifies a certificate authority which issues public key (certificates) for asymmetric algorithm. The PKI also identifies the encryption algorithms, levels of security, and distribution policy to users. \\textbf{X.509} is a well-known standard that defines basic PKI formats. The X.509 version 3 (X.509v3) standard defines the format of a digital certificate. Another important set of PKI standards are the \\textbf{Public-Key Cryptography Standards (PKCS}). PKCS defines the low-level formats for the secure exchange of arbitrary data, such as an encrypted piece of data or a signed piece of data.\\\\\n\n", "meta": {"hexsha": "906def3668062ccc6b2004cc64ee46e50204ffe2", "size": 8056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Security/Cryptography.tex", "max_stars_repo_name": "buiquanghuy23103/CCNA", "max_stars_repo_head_hexsha": "1234574bcba3c206263091ef90191fd9c41c624f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Security/Cryptography.tex", "max_issues_repo_name": "buiquanghuy23103/CCNA", "max_issues_repo_head_hexsha": "1234574bcba3c206263091ef90191fd9c41c624f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Security/Cryptography.tex", "max_forks_repo_name": "buiquanghuy23103/CCNA", "max_forks_repo_head_hexsha": "1234574bcba3c206263091ef90191fd9c41c624f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 146.4727272727, "max_line_length": 677, "alphanum_fraction": 0.8035004965, "num_tokens": 1671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6448625281183324}}
{"text": "\n\n\\documentclass[11pt]{amsbook}\n\n\\usepackage{../HBSuerDemir}\t% ------------------------\n\n\n\\begin{document}\n\n% ++++++++++++++++++++++++++++++++++++++\n\\hPage{b2p2/312}\n% ++++++++++++++++++++++++++++++++++++++\n\\begin{align*}\n4A \\frac{\\hDif A}{\\hDif t} = x(y^2+z^2) \\frac{\\hDif x}{\\hDif t} + y(z^2+x^2) \\frac{\\hDif y}{\\hDif t} + z(x^2+y^2)  \\frac{\\hDif z}{\\hDif t}\n\\end{align*}\n\nWhen P is at $P_{O}$(6, 0, 0), then Q is at $Q_{O}$(0, 9, 0) and R is at $R_{O}$(0, 0, 12) with $|P_{O}$  $Q_{O}$  $R_{O}|_{2}$ = 9$\\sqrt{61}$. Then\n\n\\begin{align*}\n4.9\\sqrt{61}\\frac{\\hDif A}{\\hDif t} = 6(225)2+ 9(680)3 + 12(117)4 \\\\\n9\\sqrt{61}\\frac{\\hDif A}{\\hDif t} = 675 + 27.45 + 12.117 \\\\\n\\sqrt{61}\\frac{\\hDif A}{\\hDif t} = 75 + 135 + 156 = 366 \\\\\n\\frac{\\hDif A}{\\hDif t} = \\frac{766}{\\sqrt{61}} = 6\\sqrt{61}  unit^2/sec\n\\end{align*}\n\n\\subsection{TAYLOR'S FORMULA AND SERIES}\n\n\\begin{thm} If f(x, y) has continuous partial derivatives up to order n+1 in a neighborhood of (a, b)$\\epsilon \\upsilon_{f}$, then\n\\begin{align*}\nf(x, y) = f(a, b) +  \\sum_{k=1}^{n}  \\frac{1}{k!} ((x-a) \\frac{a}{ax} + (y-b) \\frac{a}{ay})^k f(x, y) |_{(a, b)} + R_{n+1}\n\\end{align*}\nwhere the remainder is given by\n\\begin{align*}\nR_{n+1} = \\frac{1}{(n+1)!} ((x-a) \\frac{a}{ax} + (y-b) \\frac{a}{ax})^{n+1}f(x, y)_{(x*, y*)}\n\\end{align*}\nwith (x*, y*) a point on the open segment ($P_{O}$P) joining $P_{O}$(a, b) to P(x, y) \n\\end{thm}\n\\begin{proof} Since every point of the line segment [$P_{O}$P] can be represented parametrically as\n\n\n\n\\begin{align*}\nx = a+ht,\\qquad   y = b+kt\\qquad\t  0\\leq t \\leq 1,\n\\end{align*} \n\n\\includegraphics[width=0.35\\textwidth]{images/b2p2-312-fig01}\n\nThe end points of the segment correspond to t=0 and t=1 (observe that h, k are direction numbers of the line segment)\nSubstituting (2) in f(x, y) gives the function\n\n\\end{proof}\n\n\n\\end{document}  ", "meta": {"hexsha": "71352fc8fc4c6298d05f5d09218b6656604f5f73", "size": 1832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/non-merged/EMRE ALPAGUT_38161_assignsubmission_file_/hw2 - 2016742000/suerdemir/pages/b2p2-312.tex", "max_stars_repo_name": "yildirimyigit/cmpe220_2016_3", "max_stars_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-15T22:03:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-15T22:03:34.000Z", "max_issues_repo_path": "hw2/non-merged/EMRE ALPAGUT_38161_assignsubmission_file_/hw2 - 2016742000/suerdemir/pages/b2p2-312.tex", "max_issues_repo_name": "yildirimyigit/cmpe220_2016_3", "max_issues_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_issues_repo_licenses": ["MIT"], "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/non-merged/EMRE ALPAGUT_38161_assignsubmission_file_/hw2 - 2016742000/suerdemir/pages/b2p2-312.tex", "max_forks_repo_name": "yildirimyigit/cmpe220_2016_3", "max_forks_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_forks_repo_licenses": ["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.9259259259, "max_line_length": 148, "alphanum_fraction": 0.567139738, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.644862523733529}}
{"text": "\\subsubsection{Pade form}\n\\label{sec:onebodyjastrowpade}\n\nWhile the spline Jastrow factor is the most flexible and most commonly used form implemented in \\qmcpack, \nthere are times where its flexibility can make it difficult to optimize.  As an example, a spline jastrow\nwith a very large cutoff may be difficult to optimize for isolated systems like molecules due to the small\nnumber of samples that will be present in the tail of the function.  In such cases, a simpler functional\nform may be advantageous.  The second order Pade jastrow factor, given in Eq.\\ref{padeeqn} is a good choice \nin such cases.  \n\\begin{equation}\n\\label{padeeqn}\nu_{ab}(r) = \\frac{a*r+c*r^2}{1+b*r}\n\\end{equation}\nUnlike the spline jastrow factor which includes a cutoff, this form has an infinite range and for every particle\npair (subject to the minimum image convention) it will be applied.  It also is a cuspless jastrow factor,\nso it should either be used in combination with a single particle basis set that contains the proper cusp or\nwith a smooth pseudopotential.\n\n\\paragraph{Input Specification}\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{l c c c l }\n\\hline\n\\multicolumn{5}{l}{Correlation element} \\\\\n\\hline\n\\bfseries name & \\bfseries datatype & \\bfseries values & \\bfseries defaults & \\bfseries description \\\\\n\\hline\nelementType & text & name & see below & Classical particle target  \\\\\n\\hline\n\\multicolumn{5}{l}{elements}\\\\ \\hline\n& Coefficients & & & \\\\ \\hline\n\\multicolumn{5}{l}{Contents}\\\\ \\hline\n& (None)  & & &  \\\\ \\hline\n\\end{tabular}\n%\\end{tabular*}\n\\end{center}\n\\end{table}\n\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{l c c c l }\n\\hline\n\\multicolumn{5}{l}{parameter element} \\\\\n\\hline\n\\bfseries name & \\bfseries datatype & \\bfseries values & \\bfseries defaults & \\bfseries description \\\\\n\\hline\nid & string & name & (required) & name for variable \\\\\nname & string & A or B or C & (required) & see Eq.\\ref{padeeqn}\\\\\noptimize & text & yes or no & yes & if no, values are fixed in optimizations \\\\\n\\hline\n\\multicolumn{5}{l}{elements}\\\\ \\hline\n(None) & & & \\\\ \\hline\n\\multicolumn{5}{l}{Contents}\\\\ \\hline\n (no name) & real & parameter value & (required) & Jastrow coefficients \\\\ \\hline\n\\end{tabular}\n%\\end{tabular*}\n\\end{center}\n\\end{table}\n\n\\paragraph{Example use case}\n\\label{sec:1bjpadeexamples}\n\nSpecify a spin independent function with independent jastrow factors for two different species (Li and H).\nThe name of the particleset holding the ionic positions is \"i\".\n\\begin{lstlisting}[language=xml]\n<jastrow name=\"J1\" function=\"pade2\" type=\"One-Body\" print=\"yes\" source=\"i\">\n  <correlation elementType=\"Li\">\n    <var id=\"LiA\" name=\"A\">  0.34 </var>\n    <var id=\"LiB\" name=\"B\"> 12.78 </var>\n    <var id=\"LiC\" name=\"C\">  1.62 </var>\n  </correlation>\n  <correlation elementType=\"H\"\">\n    <var id=\"HA\" name=\"A\">  0.14 </var>\n    <var id=\"HB\" name=\"B\"> 6.88 </var>\n    <var id=\"HC\" name=\"C\"> 0.237 </var>\n  </correlation>\n</jastrow>\n\\end{lstlisting}\n", "meta": {"hexsha": "f8914d50c5d11ed91e9dff1a0d94d2e3fc382876", "size": 2957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/jastrow_one_body_pade.tex", "max_stars_repo_name": "markdewing/qmcpack", "max_stars_repo_head_hexsha": "4bd3e10ceb0faf8d2b3095338da5a56eda0dc1ba", "max_stars_repo_licenses": ["NCSA"], "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/jastrow_one_body_pade.tex", "max_issues_repo_name": "markdewing/qmcpack", "max_issues_repo_head_hexsha": "4bd3e10ceb0faf8d2b3095338da5a56eda0dc1ba", "max_issues_repo_licenses": ["NCSA"], "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/jastrow_one_body_pade.tex", "max_forks_repo_name": "markdewing/qmcpack", "max_forks_repo_head_hexsha": "4bd3e10ceb0faf8d2b3095338da5a56eda0dc1ba", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-23T17:44:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-23T17:44:39.000Z", "avg_line_length": 37.4303797468, "max_line_length": 112, "alphanum_fraction": 0.7105174163, "num_tokens": 912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6448625186331018}}
{"text": "\\subsection{Integers}\\label{subsec:integers}\n\n\\begin{definition}\\label{def:set_of_integers}\n  The set \\( \\BbbZ \\) of \\term{integers} is defined as the Grothendieck \\hyperref[thm:monoid_completion_to_abelian_group]{completion} of the commutative monoid \\( (\\BbbN, +) \\).\n\n  Let \\( \\oplus \\), \\( \\odot \\) and \\( \\leq_N \\) be the operations in \\( \\BbbN \\) (see \\fullref{thm:def:natural_number_multiplication/properties}). Since either \\( x \\in \\BbbZ \\) or \\( -x \\in \\BbbZ \\) is isomorphic to a natural number, we extend the operations to \\( \\BbbZ \\) as follows:\n  \\begin{thmenum}\n    \\item addition is defined in the completion.\n    \\item multiplication is defined as follows:\n          \\begin{equation*}\n            x \\cdot y \\coloneqq \\begin{cases}\n              x \\odot y,    & x \\geq 0 \\iff y \\geq 0      \\\\\n              (-x) \\odot y, & x < 0 \\text{ and } y \\geq 0 \\\\\n              x \\odot (-y), & x \\geq 0 \\text{ and } y < 0\n            \\end{cases}\n          \\end{equation*}\n\n    \\thmitem{def:set_of_integers/order} the order is inherited\n    \\item the additional absolute \\hyperref[def:absolute_value]{value} operation is defined as\n          \\begin{equation*}\n            \\abs{x} \\coloneqq \\begin{cases}\n              x,  & x \\geq 0, \\\\\n              -x, & x < 0.\n            \\end{cases}\n          \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  The proof that multiplication and absolute values are well-defined can be done similarly to the proof of \\fullref{thm:monoid_completion_to_abelian_group}.\n\n  Integer multiplication obviously generalizes natural number multiplication.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:integers_are_euclidean_domain}\n  The \\hyperref[def:semiring/integral_domain]{domain} of integers \\( \\BbbZ \\) is \\hyperref[def:semiring/euclidean_domain]{Euclidean} with \\( \\delta(n) \\coloneqq \\abs{n} \\). Furthermore, the remainder and quotient are unique.\n\\end{proposition}\n\\begin{proof}\n  Let \\( a, b \\in \\BbbZ \\) and \\( b \\neq 0 \\). Suppose that \\( b > 0 \\). Define\n  \\begin{balign*}\n    q & \\coloneqq \\max \\{ q \\in \\BbbZ \\colon bq \\leq \\abs{a} \\} \\\\\n    r & \\coloneqq a - bq.\n  \\end{balign*}\n\n  It remains to show that either \\( r = 0 \\) or \\( \\delta(r) < \\delta(b) \\).\n\n  Note that \\( r = 0 \\) if and only if \\( b \\) is a \\hyperref[def:commutative_ring_division]{divisor} of \\( a \\).\n\n  Suppose that \\( b \\) is not a divisor of \\( a \\). Note that \\( g \\geq 0 \\) and \\( r > 0 \\). If \\( r \\geq b \\), this would imply \\( r - b \\geq 0 \\) and\n  \\begin{equation*}\n    a = bq + r = b(q + 1) + (r - b) \\geq b(q + 1),\n  \\end{equation*}\n  which would contradict the maximality of \\( q \\). Thus, \\( r < b \\).\n\n  It remains to show uniqueness. Suppose that \\( a = bq + r = bq' + r' \\). Then\n  \\begin{equation*}\n    0 = b(q - q') + (r - r').\n  \\end{equation*}\n\n  Thus, \\( b \\mid r - r' \\). But \\( -b < r - r' < b \\), which implies that \\( r = r' \\). Thus, also implies that \\( q = q' \\) since \\( b \\neq 0 \\).\n\n  Now suppose that \\( b < 0 \\). Define\n  \\begin{balign*}\n    q & \\coloneqq \\min \\{ q \\in \\BbbZ \\colon -\\abs{a} \\leq bq \\} \\\\\n    r & \\coloneqq a - bq.\n  \\end{balign*}\n\n  Suppose that \\( b \\) is not a divisor of \\( a \\). Note that \\( q \\geq 0 \\) and \\( r < 0 \\). If \\( r \\leq b \\), this would imply \\( r - b \\leq 0 \\) and\n  \\begin{equation*}\n    a = bq + r = b(q + 1) + (r - b) \\leq b(q + 1),\n  \\end{equation*}\n  which would contradict the minimality of \\( q \\). Thus, \\( r > b \\) and, since both \\( b \\) and \\( r \\) are negative, \\( \\abs{r} < \\abs{b} \\).\n\n  To see uniqueness, suppose that \\( a = bq + r = bq' + r' \\). Thus, \\( b \\mid r - r' \\). But \\( -\\abs{b} = b < r - r' < -b = \\abs{b} \\), which implies that \\( r = r' \\) and \\( q = q' \\).\n\n  In both cases, we obtained unique integers \\( q \\) and \\( r \\) such that \\( a = bq + r \\) with \\( \\abs{r} < \\abs{b} \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:units_in_rings_etymology}\n  An integer \\( a \\) is divisible by \\( b \\neq 0 \\) if there exists a number \\( q \\) such that\n  \\begin{equation*}\n    a = qb.\n  \\end{equation*}\n\n  Obviously \\( q = (-q)(-1) \\), so the following also holds:\n  \\begin{equation*}\n    a = [(-q)(-1)]b = (-q)(-b),\n  \\end{equation*}\n  hence \\( a \\) is also divisible by \\( -b \\).\n\n  For any nonzero number \\( b = 1 \\cdot b \\) that divides \\( a \\), the number \\( -b = (-1) \\cdot b \\) also divides \\( a \\). Both \\( 1 \\) and \\( -1 \\) have unit norm (that is, \\( \\abs{1} = \\abs{-1} = 1 \\)), so it is reasonable to call them \\enquote{units}. They are the only integers \\( e \\) with the property that if \\( b | a \\), then \\( eb | a \\). This is probably the reason why invertible elements in arbitrary rings are named \\enquote{units}. Another reason is that invertible elements divide the multiplicative identity, commonly denoted by \\( 1 \\).\n\n  Consider fields, in which all nonzero elements are units. It makes no sense to speak of divisibility whatsoever because any real number \\( a \\) is divisible by any nonzero real number \\( b \\). Putting \\( q \\coloneqq \\frac a b \\) satisfies the divisibility condition. Now if \\( e \\) is any unit in \\( \\BbbR \\), we have\n  \\begin{equation*}\n    a = qb = q(e^{-1} e) b = (qe^{-1}) (eb),\n  \\end{equation*}\n  hence \\( eb \\) also divides \\( a \\).\n\\end{remark}\n\n\\begin{lemma}[Euclid's lemma]\\label{thm:euclids_lemma}\n  An \\hyperref[def:set_of_integers]{integer} is \\hyperref[def:prime_ring_ideal]{prime} if and only if it is irreducible.\n\\end{lemma}\n\\begin{proof}\n  Follows from \\fullref{thm:ufd_prime_iff_irreducible}.\n\\end{proof}\n\n\\begin{definition}\\label{def:prime_number}\n  Despite negative integers being prime \\hyperref[thm:euclids_lemma]{elements} of the ring \\( \\BbbZ \\), we only call positive prime integers \\term{prime numbers}. That is, a positive integer is prime if it has no divisors except \\( 1 \\) and itself.\n\n  Non-prime integers are called \\term{composite numbers}.\n\\end{definition}\n\n\\begin{definition}\\label{def:coprime_numbers}\n  Two integers \\( n, m \\) are called \\term{coprime} (see \\fullref{def:coprime_ring_ideals}) if \\( \\gcd(n, m) = 1 \\).\n\\end{definition}\n\n\\begin{theorem}[Fundamental theorem of arithmetic]\\label{thm:fundamental_theorem_of_arithmetic}\n  Every positive integer greater than \\( 2 \\) can be \\hyperref[def:factorization_in_ring]{factored} into a product of \\hyperref[def:prime_number]{prime} powers.\n\\end{theorem}\n\\begin{proof}\n  The ring \\( \\BbbZ \\) is an Euclidean domain by \\fullref{thm:integers_are_euclidean_domain}, which is a principal ideal domain by \\fullref{thm:euclidean_domain_is_pid}, which is a unique factorization domain by \\fullref{thm:pid_is_ufd}.\n\\end{proof}\n\n\\begin{proposition}[Fermat's little theorem]\\label{thm:fermats_little_theorem}\n  If \\( p \\) is a prime \\hyperref[def:prime_number]{number}, for any integer \\( x \\) we have\n  \\begin{equation*}\n    x^p \\cong x \\pmod p.\n  \\end{equation*}\n\\end{proposition}\n", "meta": {"hexsha": "a896ea827b9102d8676fa21f0d67c2a2e03bbb3d", "size": 6824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/integers.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/integers.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/integers.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.8992248062, "max_line_length": 554, "alphanum_fraction": 0.6295427902, "num_tokens": 2267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6448293408197289}}
{"text": "\n\\section{Spectral Theory}\n\\label{sec:spectral-theory-c*-algebras}\n\n\\subsection{Spectral Theory in Banach Algebras}\n\nThroughout this section, let $A$ be a unital Banach algebra. We actually do not need to require $A$ to be a $C^*$-algebra for the foundations of spectral theory, but the existence of a unit is essential. We will adopt the shorthand of writing $\\lambda$ for $\\lambda 1$ for all $\\lambda \\in \\C$.\n\n\\begin{definition}\nGiven $a \\in A$, we define the \\emph{resolvent set} of $a$ as\n\\begin{equation}\n\\rho(a) = \\qty{\\lambda \\in \\C: \\lambda - a \\in A^\\times}\n\\end{equation}\nAn element of $\\rho(a)$ is called a \\emph{regular value} of $a$. If $\\rho(a) \\neq \\varnothing$, the map $r_a:\\rho(a) \\rightarrow A$ defined as\n\\begin{equation}\nr_a(\\lambda) = (\\lambda - a)^{-1}\n\\end{equation}\nis called the \\emph{resolvent} of $a$.\n\nLikewise, we define the \\emph{spectrum} of $a$ as\n\\begin{equation}\n\\sigma(a) = \\qty{\\lambda \\in \\C: \\lambda - a \\notin A^\\times} = \\C \\setminus \\rho(a).\n\\end{equation}\nAn element of $\\sigma(a)$ is called a \\emph{spectral value} of $a$. If $\\sigma(a) \\neq \\varnothing$, we define the \\emph{spectral radius} of $a$ as\n\\begin{equation}\nr(a) = \\sup_{\\lambda \\in \\sigma(a)} \\abs{\\lambda}.\n\\end{equation}\n\\end{definition}\n\n\nA priori we do not know that $\\rho(a)$ or $\\sigma(a)$ is nonempty. The following exposition will establish that in fact both of them are nonempty, so the resolvent $r_a(\\lambda)$ and the spectral radius $r(a)$ are always defined.\n\n\\begin{theorem}\\label{thm:Neumann_series}\nLet $a \\in A$. If $\\lambda \\in \\C$ such that $\\norm{a} < \\abs{\\lambda}$, then the \\emph{Neumann series} $\\sum_{n=0}^\\infty (a/\\lambda)^n$ converges, $\\lambda \\in \\rho(a)$, and\n\\begin{equation}\nr_a(\\lambda) = \\frac{1}{\\lambda}\\sum_{n=0}^\\infty \\qty(\\frac{a}{\\lambda})^n.\n\\end{equation}\nFurthermore,\n\\begin{equation}\\label{eq:resolvent_norm_bound}\n\\norm{r_a(\\lambda)} \\leq \\frac{1}{\\abs{\\lambda} - \\norm{a}}.\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nWe begin by showing that the sequence of partial sums is a Cauchy sequence. Given $M,N \\in \\N$ with $M < N$, we have\n\\begin{equation}\n\\norm{\\sum_{n=0}^N \\qty(\\frac{a}{\\lambda})^n - \\sum_{n = 0}^M \\qty(\\frac{a}{\\lambda})^n} = \\norm{\\sum_{n=M+1}^N \\qty(\\frac{a}{\\lambda})^n} \\leq \\sum_{n=M+1}^N \\norm{\\qty(\\frac{a}{\\lambda})^n} \\leq \\sum_{n=M+1}^N \\qty(\\frac{\\norm{a}}{\\abs{\\lambda}})^n,\n\\end{equation}\nwhere we have used submultiplicativity in the last step. Since $\\norm{a}/\\abs{\\lambda} < 1$, the rightmost expression can be made arbitrarily small by taking $M$ and $N$ to be large. Thus, the sequence of partial sums is Cauchy, hence convergent, since $A$ is complete.\n\nNow, for any $N \\in \\N$, we have\n\\begin{equation}\n(\\lambda - a)\\qty[\\frac{1}{\\lambda}\\sum_{n=0}^N \\qty(\\frac{a}{\\lambda})^n] = \\qty[\\frac{1}{\\lambda}\\sum_{n=0}^N \\qty(\\frac{a}{\\lambda})^n](\\lambda - a) = 1 - \\qty(\\frac{a}{\\lambda})^{N+1}\n\\end{equation}\nSubmultiplicativity and $\\norm{a/\\lambda} < 1$ imply $(a/\\lambda)^n \\rightarrow 0$. Thus, taking the limit as $N \\rightarrow \\infty$ of the above line yields\n\\begin{equation}\n(\\lambda - a)\\qty[\\frac{1}{\\lambda}\\sum_{n=0}^\\infty \\qty(\\frac{a}{\\lambda})^n] = \\qty[\\frac{1}{\\lambda}\\sum_{n=0}^\\infty \\qty(\\frac{a}{\\lambda})^n](\\lambda - a) = 1,\n\\end{equation}\nas desired.\n\nFinally, we note that for $N \\in \\N$, using the formula for a geometric series yields\n\\begin{equation}\n\\norm{\\frac{1}{\\lambda}\\sum_{n=0}^N \\qty(\\frac{a}{\\lambda})^n}  \\leq \\frac{1}{\\abs{\\lambda}}\\sum_{n=0}^N \\qty(\\frac{\\norm{a}}{\\abs{\\lambda}})^n \\leq  \\frac{1}{\\abs{\\lambda}}\\frac{1}{1 - \\norm{a}/\\abs{\\lambda}} = \\frac{1}{\\abs{\\lambda} - \\norm{a}}.\n\\end{equation}\nTaking the limit as $N \\rightarrow \\infty$ yields \\eqref{eq:resolvent_norm_bound}.\n\\end{proof}\n\nThe following corollary rephrases some of the key points of the above theorem.\n\n\\begin{corollary}\nGiven $a \\in A$, the resolvent set $\\rho(a)$ is nonempty and\n\\begin{equation}\nr(a) \\leq \\norm{a}.\n\\end{equation}\n\\end{corollary}\n\n\\begin{corollary}\nGiven $a \\in A$, the resolvent $r_a:\\rho(a) \\rightarrow A$ is continuous. \n\\end{corollary}\n\n\\begin{proof}\nSince $\\rho(a) \\neq \\varnothing$, the resolvent is defined. Continuity then follows from continuity of addition, scalar multiplication, and inversion.\n\\end{proof}\n\n\n\\begin{corollary}\\label{cor:resolvent_is_open}\nLet $a \\in A$ and $\\lambda_0 \\in \\rho(a)$. If $\\abs{\\lambda - \\lambda_0} < \\norm{r_a(\\lambda_0)}^{-1}$, then $\\lambda \\in \\rho(a)$ and\n\\begin{equation}\nr_a(\\lambda) = \\sum_{n=0}^\\infty (\\lambda_0 - \\lambda)^n r_a(\\lambda_0)^{n+1}.\n\\end{equation}\nIn particular, it follows that\n\\begin{equation}\nB_{\\norm{r_a(\\lambda_0)}^{-1}}(\\lambda_0) \\subset \\rho(a)\n\\end{equation}\nfor all $\\lambda_0 \\in \\rho(a)$, so $\\rho(a)$ is open in $\\C$.\n\\end{corollary}\n\n\n\\begin{proof}\nLet $\\abs{\\lambda - \\lambda_0} < \\norm{r_a(\\lambda_0)}^{-1}$. Then $\\norm{(\\lambda_0 - \\lambda)r_a(\\lambda_0)} < 1$, so $1 - (\\lambda_0 - \\lambda)r_a(\\lambda_0)$ is invertible by Theorem \\ref{thm:Neumann_series}. Since $\\lambda_0 - a$ is invertible, the product\n\\begin{equation}\n(\\lambda_0 - a)\\qty[1 - (\\lambda_0 - \\lambda)r_a(\\lambda_0)] = \\lambda_0 - a - (\\lambda_0 - \\lambda) = \\lambda - a\n\\end{equation}\nis also invertible, so $\\lambda \\in \\rho(a)$. Furthermore, using the Neumann series for the inverse of $1 - (\\lambda_0 - \\lambda)r_a(\\lambda_0)$, we obtain\n\\begin{equation}\n\\begin{aligned}\nr_a(\\lambda) &= \\qty[1 - (\\lambda_0 - \\lambda)r_a(\\lambda_0)]^{-1} r_a(\\lambda_0)\\\\\n&= \\qty[\\sum_{n=0}^\\infty (\\lambda_0 - \\lambda)^n r_a(\\lambda_0)^n]r_a(\\lambda_0)\\\\\n&= \\sum_{n=0}^\\infty (\\lambda_0 - \\lambda)^n r_a(\\lambda_0)^{n+1},\n\\end{aligned}\n\\end{equation}\nas desired.\n\\end{proof}\n\nIn a similar vein, we have the following Corollary.\n\n\\begin{corollary}\nThe set $A^\\times$ is open in $A$.\n\\end{corollary}\n\n\\begin{proof}\nLet $a \\in A^\\times$ and let $b \\in A$ such that $\\norm{b - a} < \\norm{a^{-1}}^{-1}$. This implies that \n\\begin{equation}\n\\norm{1 - ba^{-1}} \\leq \\norm{a - b}\\norm{a^{-1}} < 1,\n\\end{equation}\nso $1 - (1 - ba^{-1}) = ba^{-1}$ is invertible, which implies $b$ is invertible. \n\\end{proof}\n\n\nHaving studied a few properties of the resolvent set, we now turn to the spectrum. In particular, we want to show that the spectrum is nonempty. We will be aided by a few algebraic properties of the resolvent. We denote the commutator of two elements $a,b \\in A$ by $[a,b] = ab - ba$.\n\n\\begin{lemma}\nLet $a \\in A$. For all $\\lambda, \\mu \\in \\rho(a)$, we have:\n\t\\begin{enumerate}\n\t\t\\item[\\tn{(i)}] $[a, r_a(\\lambda)] = 0$,\n\t\t\\item[\\tn{(ii)}] $r_a(\\mu) - r_a(\\lambda) = (\\lambda - \\mu)r_a(\\mu)r_a(\\lambda)$\n\t\t\\item[\\tn{(iii)}] $[r_a(\\lambda), r_a(\\mu)] = 0$.\n\t\\end{enumerate}\n\\end{lemma}\n\n\\begin{proof}\n(i). It is clear that $[\\lambda - a, a] = 0$. So, since $r_a(\\lambda) = (\\lambda - a)^{-1}$, we have\n\\begin{equation}\n0 = r_a(\\lambda)[\\lambda - a, a]r_a(\\lambda) = r_a(\\lambda)a -ar_a(\\lambda) = [r_a(\\lambda), a].\n\\end{equation}\n\n(ii). We compute\n\\begin{equation}\n\\begin{aligned}\n\\qty[r_a(\\mu) - r_a(\\lambda)](\\lambda - a)(\\mu - a) &= r_a(\\mu)(\\lambda - a)(\\mu - a) - (\\mu - a)\\\\\n&= (\\lambda - a) - (\\mu - a)\\\\\n&= \\lambda - \\mu.\n\\end{aligned}\n\\end{equation}\nWe used the fact that $[r_a(\\mu), \\lambda - a] = 0$ in the second step. Multiplying by $r_a(\\mu)r_a(\\lambda)$ on the left now yields the desired result.\n\n(iii). If $\\lambda = \\mu$, the result is trivial. If $\\lambda \\neq \\mu$, we may divide both sides of (ii) by $\\lambda - \\mu$ to obtain\n\\begin{equation}\nr_a(\\mu) r_a(\\lambda) = \\frac{r_a(\\mu) - r_a(\\lambda)}{\\lambda - \\mu}.\n\\end{equation}\nThe right hand side is invariant under exchange of $\\mu$ and $\\lambda$, so the result follows.\n\\end{proof}\n\n\\begin{lemma}\\label{lem:resolvent_derivative}\nLet $a \\in A$. If $f$ is in the continuous dual $A^*$, then $f \\circ r_a :\\rho(a) \\rightarrow \\C$ is holomorphic %and\n%\\begin{equation}\\label{eq:resolvent_derivative}\n%(f \\circ r_a)^{(n)}(\\lambda) = (-1)^n n! f\\qty(r_a(\\lambda)^{n+1}).\n%\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\nLet $\\lambda \\in \\rho(a)$. For any $\\mu \\in \\rho(a)$, $\\mu \\neq \\lambda$, we have\n\\begin{equation}\n\\frac{f(r_a(\\mu)) - f(r_a(\\lambda))}{\\mu - \\lambda} = f\\qty(\\frac{r_a(\\mu) - r_a(\\lambda)}{\\mu - \\lambda}) = -f\\qty(r_a(\\mu)r_a(\\lambda)).\n\\end{equation}\nSince $f$ and $r_a$ are continuous, the limit of the above as $\\mu \\rightarrow \\lambda$ exists and is\n\\begin{equation}\n(f \\circ r_a)'(\\lambda)  = -f\\qty(r_a(\\lambda)^2).\n\\end{equation}\nThis proves that $f \\circ r_a$ is holomorphic. % and proves \\eqref{eq:resolvent_derivative} for $n = 1$.\n%\n%Suppose \\eqref{eq:resolvent_derivative} is true for some $n \\in \\N$. Then for distinct numbers $\\mu, \\lambda \\in \\C$, we have\n%\\begin{equation}\n%\\begin{aligned}\n%\\frac{(f \\circ r_a)^{(n)}(\\mu) - (f \\circ r_a)^{(n)}(\\lambda)}{\\mu - \\lambda} &= (-1)^n n! f\\qty(\\frac{r_a(\\mu)^{n+1} - r_a(\\lambda)^{n+1}}{\\mu - \\lambda})\\\\\n%&= (-1)^n n! f\\qty[\\qty(\\frac{r_a(\\mu) - r_a(\\lambda)}{\\mu - \\lambda})\\sum_{k=0}^n r_a(\\mu)^{n-k}r_a(\\lambda)^k]\\\\\n%&= (-1)^{n+1} n! f\\qty(r_a(\\mu)r_a(\\lambda)\\sum_{k=0}^n r_a(\\mu)^{n-k}r_a(\\lambda)^k)\n%\\end{aligned}\n%\\end{equation}\n%where the expansion in the second step relies on the fact that $[r_a(\\mu),r_a(\\lambda)] = 0$. Taking the limit as $\\mu \\rightarrow \\lambda$ yields\n%\\begin{equation}\n%(f \\circ r_a)^{(n+1)}(\\lambda) = (-1)^{n+1} (n+1)! f\\qty(r_a(\\lambda)^{n+2}).\n%\\end{equation}\n%This concludes the inductive step and completes the proof.\n\\end{proof}\n\n\n\\begin{corollary}\nGiven $a \\in A$, the spectrum $\\sigma(a)$ is nonempty and compact.\n\\end{corollary}\n\n\\begin{proof}\nWe know $\\sigma(a)$ is closed and bounded since $\\rho(a)$ is open and $r(a) \\leq \\norm{a}$, so it just remains to show that $\\sigma(a)$ is nonempty. If $\\sigma(a) = \\varnothing$, then $\\rho(a) = \\C$, so $f \\circ r_a$ is entire for all $f \\in A^*$. Since $f$ is bounded, we have\n\\begin{equation}\n\\abs{(f \\circ r_a)(\\lambda)} \\leq \\norm{f} \\norm{r_a(\\lambda)}.\n\\end{equation}\nFurthermore, since $\\lambda \\mapsto \\norm{r_a(\\lambda)}$ is continuous, it is bounded by a constant for $\\abs{\\lambda} \\leq 1 + \\norm{a}$ by the extreme value theorem. For $\\abs{\\lambda} > 1 + \\norm{a}$, we have a bound from the Neumann series:\n\\begin{equation}\n\\norm{r_a(\\lambda)} \\leq \\frac{1}{\\abs{\\lambda} - \\norm{a}} \\leq 1.\n\\end{equation}\nThus, $f \\circ r_a$ is bounded and entire, so by Liouville's theorem it is constant. But if $\\mu \\neq \\lambda$, then $r_a(\\mu) \\neq r_a(\\lambda)$, for otherwise we would have\n\\begin{equation}\n0 = r_a(\\mu) - r_a(\\lambda) = (\\lambda - \\mu)r_a(\\mu)r_a(\\lambda),\n\\end{equation}\nwhich would imply that $r_a(\\mu) = r_a(\\lambda) = 0$, but $0$ is not invertible. By the Hahn-Banach theorem, there must be some $f \\in A^*$ such that $f \\circ r_a$ is not constant, which is a contradiction. Therefore $\\rho(a) \\neq \\C$.\n\\end{proof}\n\nIn fact, using Lemma \\ref{lem:resolvent_derivative}, we can say exactly what the spectral radius $\\rho(a)$ is.\n\n\\begin{theorem}\\label{thm:spectral_radius_formula}\nLet $a \\in A$. The spectral radius is given by\n\\begin{equation}\nr(a) = \\lim_{n \\rightarrow \\infty} \\norm{a^n}^{1/n},\n\\end{equation}\nwhere the limit on the right hand side is guaranteed to exist.\n\\end{theorem}\n\n\\begin{proof}\nThe result is trivial if $a = 0$, so assume $a \\neq 0$. We will show that\n\\begin{equation}\\label{eq:spectral_radius_lim_inequality}\n\\limsup \\norm{a^n}^{1/n} \\leq r(a) \\leq \\liminf \\norm{a^n}^{1/n},\n\\end{equation}\nwhich immediately yields the result.\n\nSuppose $\\lambda \\in \\sigma(a)$. If $\\lambda^n \\in \\rho(a^n)$ for some $n \\in \\N$, then\n\\begin{equation}\n\\lambda^n - a^n = (\\lambda - a) \\qty(\\lambda^{n-1} + \\lambda^{n-2}a + \\cdots + \\lambda a^{n-2} + a^{n-1})\n\\end{equation}\nis invertible. Let $b$ be the rightmost term in parentheses and note that $b$ commutes with $\\lambda - a$. But then\n\\begin{equation}\n(\\lambda - a)b(\\lambda^n - a^n)^{-1} = 1 = (\\lambda^n - a^n)^{-1}b (\\lambda - a),\n\\end{equation}\nso $\\lambda - a$ has a left inverse and a right inverse. Hence $\\lambda - a$ has a two-sided inverse, so $\\lambda \\in \\rho(a)$, which is a contradiction. Therefore $\\lambda^n \\in \\sigma(a^n)$. Since $\\rho(a^n) \\leq \\norm{a^n}$, we see that\n\\begin{equation}\n\\abs{\\lambda} = \\qty(\\abs{\\lambda}^n)^{1/n} \\leq \\norm{a^n}^{1/n}.\n\\end{equation}\nThis is true for all $\\lambda \\in \\rho(a)$ and $n \\in \\N$, so\n\\begin{equation}\n\\rho(a) \\leq \\inf_{n \\in \\N} \\norm{a^n}^{1/n} \\leq \\liminf \\norm{a^n}^{1/n}.\n\\end{equation}\n\nTo prove the other half of \\eqref{eq:spectral_radius_lim_inequality}, suppose $\\rho(a) > 0$, let $f \\in A^*$, and consider the function $g:B_{\\rho(a)^{-1}}(0) \\rightarrow \\C$ defined as\n\\begin{equation}\ng(\\lambda) = \\begin{cases} \\hfil f(r_a(\\lambda^{-1})) &: \\lambda \\neq 0\\\\ \\hfil 0 &: \\lambda = 0\\end{cases}\n\\end{equation}\nIf $\\rho(a) = 0$, we may define $g$ in this way on all of $\\C$. This function is holomorphic on the deleted disk $B_{\\rho(a)^{-1}}(0) \\setminus \\qty{0}$ by Lemma \\ref{lem:resolvent_derivative} and the fact that $\\lambda \\mapsto \\lambda^{-1}$ is holomorphic on $\\C \\setminus \\qty{0}$. Furthermore, for $\\abs{\\lambda} < \\norm{a}^{-1}/2$, we have \n\\begin{equation}\n\\abs{g(\\lambda)} \\leq \\norm{f} \\norm{r_a(\\lambda^{-1})} \\leq \\frac{\\norm{f}}{\\abs{\\lambda}^{-1} - \\norm{a}} = \\frac{\\norm{f}\\abs{\\lambda}}{1 - \\norm{a}\\abs{\\lambda}} \\leq 2 \\norm{f}\\abs{\\lambda},\n\\end{equation}\nso $g$ is continuous at zero. It is then a consequence of Morera's theorem that $g$ is holomorphic on the whole disk $B_{\\rho(a)^{-1}}(0)$. \n\nFurthermore, for $0 < \\abs{\\lambda} < \\norm{a}^{-1}$, we can use the Neumann series to obtain a power series expansion:\n\\begin{equation}\ng(\\lambda) = f\\qty(\\lambda \\sum_{n=0}^\\infty \\qty(\\lambda a)^n ) = \\lambda \\sum_{n=0}^\\infty f(a^n) \\lambda^n.\n\\end{equation}\nSince $g$ is holomorphic on $B_{\\rho(a)^{-1}}(0)$ or on $\\C$ if $\\rho(a) = 0$, the above gives its power series expansion on its entire domain by the unique representability of $g$ by a power series. The radius of convergence of this power series is therefore at least $\\rho(a)^{-1}$, so the series converges absolutely for every $\\lambda$ in the domain of $g$. Hence, for any $f \\in A^*$ and $\\lambda \\in \\C$ with $\\abs{\\lambda} < \\rho(a)^{-1}$, the sequence $\\abs{\\lambda^n f(a^n)}$ is bounded as $n$ varies across the natural numbers. \n\nRecall that the map $\\Psi: A \\rightarrow A^{**}$ defined as $\\Psi(a)(f) = f(a)$ is a linear isometry. Then the boundedness of $\\abs{\\lambda^n f(a^n)}$ for all $f \\in A^*$ indicates that the family $\\Psi(\\lambda^n a^n)$ is pointwise bounded. By the uniform boundedness principle, the family $\\Psi(\\lambda^n a^n)$ is uniformly bounded, i.e.\\ for each $\\lambda$ there exists $M_\\lambda > 0$ such that\n\\begin{equation}\n\\abs{\\lambda^n f(a^n)} < M_\\lambda,\n\\end{equation}\nfor all $f \\in A^*$ with $\\norm{f} \\leq 1$. By the Hahn-Banach theorem, there exists $f \\in A^*$ with $\\norm{f} \\leq 1$ such that $\\abs{f(a^n)} = \\norm{a^n}$. Thus, we have $\\abs{\\lambda}^n \\norm{a^n} < M_\\lambda$ for all $n \\in \\N$, or\n\\begin{equation}\n\\norm{a^n}^{1/n} < M_\\lambda^{1/n} \\abs{\\lambda}^{-1},\n\\end{equation}\nassuming $\\abs{\\lambda} > 0$. Taking the limit supremum of both sides yields\n\\begin{equation}\n\\limsup \\norm{a^n}^{1/n} \\leq \\limsup M^{1/n}_\\lambda \\abs{\\lambda}^{-1} = \\lim_{n \\rightarrow \\infty} M_\\lambda^{1/n} \\abs{\\lambda}^{-1} = \\abs{\\lambda}^{-1}.\n\\end{equation}\nIf $\\rho(a) = 0$, this is valid for all $\\abs{\\lambda} > 0$, which implies $\\limsup \\norm{a^n}^{1/n} = 0 = \\rho(a)$. If $\\rho(a) > 0$, this is valid for all $\\abs{\\lambda}^{-1} > \\rho(a)$, which implies that \n\\begin{equation}\n\\limsup \\norm{a^n}^{1/n} \\leq \\rho(a),\n\\end{equation}\nas desired.\n\\end{proof}\n\nThe proof that $r(a) \\leq \\liminf \\norm{a^n}^{1/n}$ in Theorem \\ref{thm:spectral_radius_formula} contains some interesting observations worth highlighting.\n\n\\begin{lemma}\\label{lem:invert_product}\nIf $a_1,\\ldots, a_n, b \\in A$ such that\n\\begin{equation}\nb = a_1 a_2 \\cdots a_n,\n\\end{equation}\nand $[a_i, a_j] = 0$ for all $i,j$, then $b$ is invertible if and only if each $a_i$ is invertible.\n\\end{lemma}\n\n\\begin{proof}\nIt is obvious that $b$ is invertible if each $a_i$ is invertible. If $b$ is invertible, then for any $i\\leq n$, we have\n\\begin{equation}\n\\qty(b^{-1}\\prod_{j \\neq i} a_j)a_i = b^{-1}b = 1 =bb^{-1} =  a_i \\qty(\\prod_{j \\neq i} a_j)b^{-1}.\n\\end{equation}\nThus, $a_i$ has a left inverse and a right inverse, which must be equal.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:polynomial_spectrum}\nLet $p = \\sum_{i=0}^n \\alpha_i z^i$ be a complex polynomial and let $a \\in A$. Then\n\\begin{equation}\n\\sigma(p(a)) = p(\\sigma(a)).\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nFix $\\lambda \\in \\C$ and factorize $\\lambda - p(a)$:\n\\begin{equation}\n\\lambda - p(z) = \\beta_0 \\prod_{i=1}^n (\\beta_i - z)\n\\end{equation}\nfor some $\\beta_0,\\ldots, \\beta_n \\in \\C$. Then \n\\begin{equation}\n\\lambda - p(a) = \\beta_0 \\prod_{i=1}^n (\\beta_i - a).\n\\end{equation}\nBy Lemma \\ref{lem:invert_product}, $\\lambda \\in \\sigma(p(a))$ if and only if $\\beta_i \\in \\sigma(a)$ for some $i \\geq 1$. But there exists $i \\geq 1$ such that $\\beta_i \\in \\sigma(a)$ if and only if $\\lambda \\in p(\\sigma(a))$, so we're done.\n\\end{proof}\n\n\nTheorem \\ref{thm:polynomial_spectrum} gives one example of how algebraic manipulations in $A$ affect the spectra of the elements being manipulated. Let us give more results in this vein.\n\n\\begin{theorem}\nIf $a, b \\in A$, then\n\\begin{equation}\\label{eq:spectrum_of_product}\n\\sigma(ab) \\cup \\qty{0} = \\sigma(ba) \\cup \\qty{0}.\n\\end{equation}\nIf $a \\in A^\\times$, then\n\\begin{equation}\n\\sigma(a^{-1}) = \\sigma(a)^{-1}.\n\\end{equation}\n\\end{theorem}\n\n\\begin{proof}\nSuppose $\\lambda \\in \\rho(ab)$. Then using $(\\lambda - ba)b = b(\\lambda - ab)$ we compute\n\\begin{equation}\n\\begin{aligned}\n(\\lambda - ba)\\qty[1 + b(\\lambda - ab)^{-1}a] = \\qty(\\lambda - ba) + ba = \\lambda.\n\\end{aligned}\n\\end{equation}\nand likewise\n\\begin{equation}\n\\qty[1 + b(\\lambda - ab)^{-1}a] (\\lambda - ba) = (\\lambda - ba)  + ba = \\lambda.\n\\end{equation}\nTherefore $\\lambda \\in \\rho(ba)$ if $\\lambda \\neq 0$. Of course, the same result holds with $a$ and $b$ switched. In other words,\n\\begin{equation}\n\\rho(ab) \\setminus \\qty{0} = \\rho(ba) \\setminus \\qty{0}\n\\end{equation}\nTaking complements yields \\eqref{eq:spectrum_of_product}.\n\nIf $a \\in A^\\times$, then clearly $0 \\notin \\sigma(a)$ and $0 \\notin \\sigma(a^{-1})$. If $\\lambda \\neq 0$, then\n\\begin{equation}\n\\lambda^{-1} - a = \\lambda^{-1} a(a^{-1} - \\lambda),\n\\end{equation}\nwhich implies $\\lambda^{-1} \\in \\sigma(a)$ if and only if $\\lambda \\in \\sigma(a^{-1})$ by Lemma \\ref{lem:invert_product}. Since $\\lambda^{-1} \\in \\sigma(a)$ if and only if $\\lambda \\in \\sigma(a)^{-1}$, this is the desired result.\n\\end{proof}\n\n\n\\subsection[Spectral Theory in C$^*$-Algebras]{Spectral Theory in C$^*$-Algebras}\n\nWe continue where we left off in the previous section by showing how the spectrum behaves with respect to the star operation. We now let $A$ be a unital $C^*$-algebra for the rest of this section.\n\n\\begin{proposition}\\label{prop:star_spectrum}\nLet $a \\in A$. Then\n\\begin{equation}\n\\sigma(a^*) = \\sigma(a)^*.\n\\end{equation}\n\\end{proposition}\n\n\\begin{proof}\nWe note that $\\lambda - a^*$ is invertible if and only if $\\lambda - a^*$ is invertible by Proposition \\ref{prop:inverse_star_commute}. Hence, $\\lambda \\in \\sigma(a^*)$ if and only if $\\lambda^* \\in \\sigma(a)$ if and only if $\\lambda \\in \\sigma(a)^*$.\n\\end{proof}\n\nWe now investigate the spectra of several special classes of elements of $A$.\n\n\\begin{definition}\nAn element $a \\in A$ is \n\\begin{enumerate}\n\t\\item[(i)] \\emph{normal} if $[a,a^*] = 0$,\n\t\\item[(ii)] an \\emph{isometry} if $a^*a = 1$, and\n\t\\item[(iii)] \\emph{unitary} if $a^*a = aa^* = 1$, i.e.\\ $a \\in A^\\times$ and $a^{-1} = a^*$.\n\\end{enumerate}\nNote that both unitary and self-adjoint elements are normal. Furthermore, if $a$ is an isometry or a unitary, then $\\norm{a} = 1$ by the $C^*$-property. \n\\end{definition}\n\n\n\\begin{corollary}\nIf $a \\in A$ is normal, then $\\rho(a) = \\norm{a}$.\n\\end{corollary}\n\n\\begin{proof}\nWe claim that\n\\begin{equation}\\label{eq:normal_inductive_step}\n\\norm{a^{2^n}}^2 = \\norm{a}^{2^{n+1}}.\n\\end{equation}\nfor all normal $a \\in A$. For $n = 0$ this is trivial. Suppose it is true for some $n = k-1$ where $k \\in \\N$. Using normality of $a$, the $C^*$-property, and the fact that $a^*a$ is self-adjoint, we compute\n\\begin{equation}\n\\begin{aligned}\n\\norm{a^{2^k}}^2  &= \\norm{\\qty(a^{2^k})^*a^{2^k}} = \\norm{\\qty(a^*)^{2^k}a^{2^k}} = \\norm{(a^*a)^{2^k}} \\\\\n&= \\norm{(a^*a)^{2^{k-1}}}^2  = \\norm{a^*a}^{2^k} = \\norm{a}^{2^{k+1}}.\n\\end{aligned}\n\\end{equation}\nThis proves \\eqref{eq:normal_inductive_step}. Now, using the formula for the spectral radius, we obtain\n\\begin{equation}\nr(a) = \\lim_{n \\rightarrow \\infty} \\norm{a^{2^n}}^{1/2^n} = \\lim_{n \\rightarrow \\infty} \\norm{a}^{2^{n}/2^n} = \\norm{a},\n\\end{equation}\nas desired.\n\\end{proof}\n\n\\begin{corollary}\nIf $a \\in A$ is isometric, then $r(a) = 1$.\n\\end{corollary}\n\n\\begin{proof}\nWe note that\n\\begin{equation}\n\\norm{a^n}^2 = \\norm{\\qty(a^n)^* \\qty(a^n)} = \\norm{(a^*)^n \\qty(a^n)} = \\norm{1} = 1.\n\\end{equation}\nThus,\n\\begin{equation}\nr(a) = \\lim_{n \\rightarrow \\infty} \\norm{a^n}^{1/n} = \\lim_{n \\rightarrow \\infty} 1 = 1,\n\\end{equation}\nas desired.\n\\end{proof}\n\n\\begin{corollary}\nIf $a \\in A$ is unitary, then $\\sigma(a) \\subset S^1$.\n\\end{corollary}\n\n\\begin{proof}\nWe have \n\\begin{equation}\n\\sigma(a)^{-1} = \\sigma(a^{-1}) = \\sigma(a^*) = \\sigma(a)^*.\n\\end{equation}\nThus, if $\\lambda \\in \\sigma(a)$, then $\\lambda^{-1} = \\mu^*$ for some $\\mu \\in \\sigma(a)$. Since $r(a) \\leq 1$, we know $1 \\leq \\abs{\\lambda}^{-1} = \\abs{\\mu} \\leq 1$, so $\\abs{\\lambda} = 1$.\n\\end{proof}\n\n\n\\begin{theorem}\nIf $a \\in A$ is self-adjoint, then\n\\begin{equation}\n\\sigma(a) \\subset [-\\norm{a}, \\norm{a}].\n\\end{equation}\nIn particular, $\\sigma(a^2) = \\sigma(a)^2 \\subset [0, \\norm{a}^2]$.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\lambda \\in \\R$ such that $\\lambda^{-1} = \\abs{i\\lambda^{-1}} > \\norm{a}$. Then $\\lambda^{-1} \\in \\rho(a)$, so $1 + i\\lambda a = -i\\lambda(i\\lambda^{-1}  - a)$ is invertible. Note that $(1 + i\\lambda a)^* = 1 - i \\lambda a$ is invertible as well. Define\n\\begin{equation}\nu = (1 - i\\lambda a)(1 + i \\lambda a)^{-1}.\n\\end{equation}\nObserve that $u^* = (1 - i\\lambda a)^{-1}(1 + i \\lambda a)$. Using the fact that $1 - i \\lambda a$ commutes with $1 + i \\lambda a$, we see that\n\\begin{equation}\nu^*u = (1- i\\lambda a)^{-1} (1 + i \\lambda a)(1 - i \\lambda a) (1 + i \\lambda a)^{-1} = 1.\n\\end{equation}\nSince $u$ is the product of two invertible elements, we know $u$ is invertible, and the above shows that $u^{-1} = u^*$, so $u$ is unitary.\n\nGiven $\\mu \\in \\C$, $\\mu \\neq i\\lambda^{-1}$, observe that\n\\begin{equation}\n\\abs{\\frac{1 - \\cplxi \\, \\lambda \\mu}{1 + \\cplxi \\, \\lambda \\mu}} = \\sqrt{\\frac{(1 + \\lambda \\, \\Im \\mu)^2 + (\\lambda \\, \\Re \\mu)^2}{(1 - \\lambda \\, \\Im \\mu)^2 + (\\lambda \\, \\Re \\mu)^2}},\n\\end{equation}\nwhich equals $1$ if and only if $\\Im \\mu = 0$, i.e.\\ $\\mu \\in \\R$. Since $\\sigma(u) \\subset S^1$, we see that if $\\mu \\in \\C \\setminus \\R$, then $(1-i \\lambda \\mu)(1 + i \\lambda \\mu)^{-1} \\in \\rho(u)$. In particular, if $\\mu \\neq i \\lambda^{-1}$, then \n\\begin{equation}\n\\begin{aligned}\n(1 - i \\lambda \\mu)(1 + i \\lambda \\mu)^{-1} - u &= (1 + i \\lambda \\mu)^{-1}\\qty[(1 - i \\lambda \\mu)(1 + i \\lambda a) - (1 + i \\lambda \\mu)(1 - i\\lambda a)](1 + i \\lambda a)^{-1}\\\\\n&= 2i\\lambda(1 + i \\lambda \\mu)^{-1} (a - \\mu)(1 + i \\lambda a)^{-1}.\n\\end{aligned}\n\\end{equation}\nIf $\\mu \\in \\C \\setminus \\R$, then the left hand side is invertible, so $\\mu - a$ is invertible, so $\\mu \\in \\rho(a)$. Furthermore, $i\\lambda^{-1} \\notin \\sigma(a)$ since $\\abs{i\\lambda^{-1}} > \\norm{a}$. Thus, $\\sigma(a) \\subset \\R$. \n\\end{proof}\n\n\\begin{corollary}\\label{cor:unique_star_norm}\nIf $a \\in A$, then\n\\begin{equation}\n\\norm{a} = \\sqrt{r(a^*a)}.\n\\end{equation}\nHence, the norm is completely determined by the algebraic operations, i.e.\\ the $C^*$-norm is unique.\n\\end{corollary}\n\n\\begin{proof}\nNote that $a^*a$ is normal, so \n\\begin{equation}\n\\norm{a}^2 = \\norm{a^*a} = r(a^*a).\n\\end{equation}\nThe result follows by taking a square root.\n\\end{proof}\n\n\n\\begin{theorem}[Spectral Permanence] \nLet $B$ be a unital $C^*$-subalgebra of $A$. For any $a \\in B$, the spectrum of $a$ in $B$ is the same as the spectrum of $a$ in $A$.\n\\end{theorem}\n\n\\begin{proof}\nLet us temporarily use the notation $\\sigma_A(a)$ and $\\sigma_B(a)$ to distinguish the spectrum of $a$ in $A$ and $B$ respectively. We shall use the notation $\\rho_A(a)$, $\\rho_B(a)$, $r_A(a)$, and $r_B(a)$ similarly. If $\\lambda \\in \\sigma_A(a)$, then $\\lambda - a$ is not invertible in $A$, so $\\lambda - a$ is certainly not invertible in $B$. Thus, $\\sigma_A(a) \\subset \\sigma_B(a)$. \n\nThe reverse inclusion $\\sigma_B(a) \\subset \\sigma_A(a)$ is trivial if $a = 0$, so suppose $a \\neq 0$. It is easy to check that $\\sigma_B(a) \\subset \\sigma_A(a)$ follows from the inclusion $B \\cap A^\\times \\subset B^\\times$, and this is what we will show. First suppose $a \\in B \\cap A^\\times$ and $a$ is self-adjoint. Let $\\lambda_0 = 2i \\norm{a}$ and note that $\\lambda_0 \\in \\rho_B(a)$ since $\\abs{\\lambda_0} > \\norm{a}$. We know from Corollary \\ref{cor:resolvent_is_open} that $B_{\\norm{r_a(\\lambda_0)}^{-1}}(\\lambda_0) \\subset \\rho_B(a)$; thus we want to show that $0 \\in B_{\\norm{r_a(\\lambda_0)}^{-1}}(\\lambda_0)$ to show that $a \\in B^\\times$.\n\nObserve that self-adjointness of $a$ implies that $r_a(\\lambda_0)^* = r_a(\\lambda_0^*)$, from which it follows that $r_a(\\lambda_0)$ is normal since $[r_a(\\lambda), r_a(\\mu)] = 0$ for all $\\lambda, \\mu \\in \\rho_B(a)$. Normality then yields\n\\begin{equation}\n\\norm{r_a(\\lambda_0)} = r_A\\qty(r_a(\\lambda_0)).\n\\end{equation}\nBut we also know that\n\\begin{equation}\n\\sigma_A(r_a(\\lambda_0)) = \\sigma_A(\\lambda_0 - a)^{-1} = \\qty[\\lambda_0 - \\sigma_A(a)]^{-1}\n\\end{equation}\nHence, \n\\begin{equation}\nr_A(r_a(\\lambda_0)) = \\tn{dist}(\\lambda_0, \\sigma_A(a))^{-1}.\n\\end{equation}\nBut since $\\lambda_0$ is purely imaginary and $\\sigma_A(a) \\subset \\R$, we know that $\\tn{dist}(\\lambda_0, \\sigma_A(a)) \\geq \\abs{\\lambda_0}$! In fact,  we know $0 \\notin \\sigma_A(a)$ since $a \\in A^\\times$, so this is a strict inequality and taking inverses yields\n\\begin{equation}\n\\norm{r_a(\\lambda_0)} = \\tn{dist}(\\lambda_0, \\sigma_A(a))^{-1} < \\abs{\\lambda_0}^{-1}.\n\\end{equation}\nThis implies $0 \\in B_{\\norm{r_a(\\lambda_0)}^{-1}}(\\lambda_0)$, proving the theorem for self-adjoint $a$.\n\nFinally, consider $a \\in B \\cap A^\\times$, not necessarily self-adjoint. However, we see that $a^*a \\in B \\cap A^\\times$ and $a^*a$ is self-adjoint, so $a^*a \\in B^\\times$. Defining \n\\begin{equation}\nb = (a^* a)^{-1}a^*,\n\\end{equation}\nwe see that $ba = 1$, so $b = a^{-1}$ since $a$ was assumed to be invertible in $A$. Since $b \\in B$ manifestly, we conclude that $a \\in B^\\times$, as desired.\n\\end{proof}\n\nLet us now consider how the spectrum of an element behaves under $*$-homomorphisms. \n\n\\begin{proposition}\\label{prop:star_hom_inverse}\nLet $A$ and $B$ be unital $C^*$-algebras and let $\\pi:A \\rightarrow B$ be a unital $*$-homomorphism. Then $\\pi(A^\\times)\\subset B^\\times$ and\n\\begin{equation}\n\\pi(a^{-1}) = \\pi(a)^{-1}\n\\end{equation}\nfor all $a \\in A^\\times$. If $\\pi$ is bijective, then $\\pi(A^\\times) = B^\\times$.\n\\end{proposition}\n\n\\begin{proof}\nLet $a \\in A^\\times$ and observe\n\\begin{equation}\n\\pi(a^{-1})\\pi(a) = \\pi(a^{-1}a) = \\pi(1) = 1 =\\pi(1) = \\pi(aa^{-1}) = \\pi(a)\\pi(a^{-1}).\n\\end{equation}\nThis proves that $\\pi(a) \\in B^\\times$ and $\\pi(a)^{-1} = \\pi(a^{-1})$. If $\\pi$ is bijective, then $\\pi^{-1}(B^\\times) \\subset A^\\times$ by the same argument, so $\\pi \\pi^{-1}(B^\\times) = B^\\times \\subset \\pi(A^\\times)$.\n\\end{proof}\n\n\\begin{proposition}\\label{prop:star_hom_spectrum}\nLet $A$ and $B$ be unital $C^*$-algebras and let $\\pi:A \\rightarrow B$ be a unital $*$-homomorphism. Then\n\\begin{equation}\n\\sigma(\\pi(a)) \\subset \\sigma(a)\n\\end{equation}\nand\n\\begin{equation}\n\\pi(r_a(\\lambda)) = r_{\\pi(a)}(\\lambda)\n\\end{equation}\nfor all $\\lambda \\in \\rho(a)$. If $\\pi$ is bijective, then $\\sigma(\\pi(a)) = \\sigma(a)$.\n\\end{proposition}\n\n\\begin{proof}\nLet $\\lambda \\in \\rho(a)$. Then by Proposition \\ref{prop:star_hom_inverse}, we know $\\pi(\\lambda - a) = \\lambda - \\pi(a) \\in B^\\times$ and \n\\begin{equation}\nr_{\\pi(a)}(\\lambda) = (\\lambda - \\pi(a))^{-1} = \\pi(\\lambda - a)^{-1} = \\pi\\qty(r_a(\\lambda)).\n\\end{equation}\nWe see that $\\rho(a) \\subset \\rho(\\pi(a))$, so $\\sigma(\\pi(a)) \\subset \\sigma(a)$ by taking complements. If $\\pi$ is bijective, then $\\sigma(a) = \\sigma(\\pi^{-1}(\\pi(a))) \\subset \\sigma(\\pi(a))$ as well.\n\\end{proof}\n\n\n\n\\begin{proposition}\\label{prop:star_hom_cont}\nLet $A$ and $B$ be unital $C^*$-algebras and let $\\pi:A \\rightarrow B$ be a unital $*$-homomorphism. Then\n\\begin{equation}\n\\norm{\\pi(a)} \\leq \\norm{a}\n\\end{equation}\nfor all $a \\in A$. In particular, $\\pi$ is continuous and $\\norm{\\pi} = 1$.\n\\end{proposition}\n\n\n\\begin{proof}\nBy Proposition \\ref{prop:star_hom_spectrum}, we know that $r(\\pi(a)) \\leq r(a)$ for all $a \\in A$. Then by Corollary \\ref{cor:unique_star_norm},\n\\begin{equation}\n\\norm{\\pi(a)} = \\sqrt{r(\\pi(a)^*\\pi(a))} = \\sqrt{r\\qty(\\pi(a^*a))} \\leq \\sqrt{r(a^*a)} = \\norm{a}.\n\\end{equation}\nThis shows that $\\pi$ is continuous, and $\\norm{\\pi} = 1$ since $\\norm{\\pi(1)} = \\norm{1} = 1$.\n\\end{proof}\n\n\n\nWith these simple propositions in hand, we can prove a powerful theorem, known as the \\emph{continuous functional calculus} for self-adjoint elements.\n\n\\begin{theorem}\nLet $A$ be a unital $C^*$-algebra and let $a \\in A$ be self-adjoint. There exists a unique unital $*$-homomorphism $C(\\sigma(a)) \\rightarrow A$, $f \\mapsto f(a)$ such that $p(a) = \\sum_{i=0}^n \\alpha_{i} a^i$ for all complex polynomials $p(z) = \\sum_{i=0}^n \\alpha_i z^i $. Furthermore, for all $f \\in C(\\sigma(a))$, we have\n\t\\begin{enumerate}\n\t\t\\item[\\tn{(i)}] $\\norm{f(a)} = \\norm{f}$,\n\t\t\\item[\\tn{(ii)}] $f(a)$ is in the $C^*$-algebra generated by $1$ and $a$. In particular, $[f(a),a] = 0$, \n\t\t\\item[\\tn{(iii)}] $\\pi(f(a)) = f(\\pi(a))$ for any unital $*$-homomorphism $\\pi:A \\rightarrow B$,\n\t\t\\item[\\tn{(iv)}] $\\sigma(f(a)) = f(\\sigma(a))$.\n\t\\end{enumerate}\nFinally, if $g \\in C(\\sigma(f(a)))$, then\n\t\\begin{enumerate}\n\t\t\\item[\\tn{(v)}] $(g \\circ f)(a) = g(f(a))$.\n\t\\end{enumerate}\t\n\\end{theorem}\n\n\\noindent Note that $f(\\pi(a))$ is well-defined in (iii) since $\\sigma(\\pi(a)) \\subset \\sigma(a)$, and $(g \\circ f)(a)$ is well-defined by (iv).\n\n\\begin{proof}\nIt clear that the map $p \\mapsto p(a)$ defined on polynomials $p(z) = \\sum_{i,j=0}^n \\alpha_i z^i $ is linear. Furthermore, since $p(a)$ is self-adjoint for any polynomial $p$, we have\n\\begin{equation}\n\\begin{aligned}\n\\norm{p(a)} &= r(p(a)) \\\\\n&= \\sup\\qty{\\abs{\\lambda}: \\lambda \\in \\sigma(p(a))} \\\\\n&= \\sup\\qty{\\abs{\\lambda}: \\lambda \\in p(\\sigma(a))} \\\\\n&= \\sup\\qty{\\abs{p(\\lambda)}: \\lambda \\in \\sigma(a)}\\\\\n&= \\norm{p},\n\\end{aligned}\n\\end{equation}\nso the map $p \\mapsto p(a)$ is continuous. Since $\\sigma(a)$ is a compact subset of $\\R$, the Weierstrass approximation theorem (and the Tietze extension theorem) imply that the set of polynomials is dense in $C(\\sigma(a))$. Therefore the map $p \\mapsto p(a)$ extends uniquely to a linear map $f \\mapsto f(a)$ on $C(\\sigma(a))$. It follows by standard continuity arguments that $\\norm{f(a)} = \\norm{f}$ for all $f \\in C(\\sigma(a))$ since $\\norm{p(a)} = \\norm{p}$ for all polynomials.\n\nIt is clear that for polynomials $p$ and $q$, we have $(pq)(a) = p(a)q(a)$ and $(p^*)(a) = (p(a))^*$, the latter relying on self-adjointness of $a$. That $(fg)(a) = f(a)g(a)$ and $(f^*)(a) = (f(a))^*$ for arbitrary $f, g \\in C(\\sigma(a))$ again follows by standard continuity arguments using the fact that the polynomials are dense in $C(\\sigma(a))$. Thus, $f \\mapsto f(a)$ is a unital $*$-homomorphism.\n\nOnce again, (ii) and (iii) clearly hold for polynomials. Thus, (ii) holds for $f$ by a standard argument using density of polynomials and completeness of the $C^*$-algebra generated by $1$ and $a$. Likewise, (iii) holds by density of polynomials and by continuity of $*$-homomorphisms as shown in Proposition \\ref{prop:star_hom_cont}. \n\nTo prove (iv), let $(p_n)$ be a sequence of polynomials such that $p_n \\rightarrow f$. Given $\\lambda \\in \\sigma(a)$, we know\n\\begin{equation}\np_n(\\lambda) \\in p_n(\\sigma(a)) = \\sigma(p_n(a)),\n\\end{equation}\nso $p_n(\\lambda) - p_n(a)$ is not invertible. Since the complement of $A^\\times$ is closed, taking the limit as $n\\rightarrow \\infty$ yields $f(\\lambda) - f(a) \\notin A^\\times$, so $f(\\lambda) \\in \\sigma(f(a))$. Hence $f(\\sigma(a)) \\subset \\sigma(f(a))$. On the other hand, if $\\lambda \\notin f(\\sigma(a))$, then $\\lambda - f$ is invertible in $C(\\sigma(a))$ with inverse $g \\in C(\\sigma(a))$. Then\n\\begin{equation}\n(\\lambda - f(a))g(a) = g(a)\\qty(\\lambda - f(a)) = 1,\n\\end{equation}\nso $\\lambda - f(a)$ is invertible, i.e.\\ $\\lambda \\notin \\sigma(f(a))$. This proves $\\sigma(f(a)) \\subset f(\\sigma(a))$, as desired.\n\nTo prove (v), we note that $g \\mapsto g \\circ f$ is a unital $*$-homomorphism $C(\\sigma(f(a))) \\rightarrow C(\\sigma(a))$, so $g \\mapsto g \\circ f \\mapsto (g \\circ f)(a)$ is a unital $*$-homomorphism $C(\\sigma(f(a))) \\rightarrow A$. Furthermore, if $p$ is a polynomial, then $(p \\circ f)(a) = p(f(a))$ since the map $C(\\sigma(a)) \\rightarrow A$ respects addition and multiplication. Therefore $(g \\circ f)(a) = g(f(a))$ by uniqueness of the $*$-homomorphism $C(\\sigma(f(a))) \\rightarrow A$.\n\\end{proof}\n\n\\begin{corollary}\nLet $A$ and $B$ be unital $C^*$-algebras. If $\\pi:A \\rightarrow B$ is an injective unital $*$-homomorphism, then $\\pi$ is an isometry:\n\\begin{equation}\n\\norm{\\pi(a)} = \\norm{a}\n\\end{equation}\nfor all $a \\in A$.\n\\end{corollary}\n\n\\begin{proof}\nSince $\\norm{\\pi(a)} \\leq \\norm{a}$ by Proposition \\ref{prop:star_hom_cont}, we need only show the reverse inequality. First we show $\\norm{a} \\leq \\norm{\\pi(a)}$ for all self-adjoint elements $a \\in A$. Suppose $a$ is self-adjoint and $\\norm{\\pi(a)} < \\norm{a}$. Recall that $\\rho(a) = \\norm{a}$ and $\\sigma(a) \\subset \\R$, so $\\norm{a} \\in \\sigma(a)$ or $-\\norm{a} \\in \\sigma(a)$, and likewise for $\\pi(a)$. Choose $f :[-\\norm{a}, \\norm{a}] \\rightarrow \\R$ such that $f$ vanishes on $[-\\norm{\\pi(a)}, \\norm{\\pi(a)}]$ and $f(\\norm{a}) = f(-\\norm{a}) = 1$. Then $f(\\pi(a)) = \\pi(f(a)) = 0$ but $\\norm{f(a)} = \\norm{f} > 1$, contradicting injectivity of $\\pi$. Therefore $\\norm{a} = \\norm{\\pi(a)}$ for self-adjoint $a$.\n\nFor arbitrary $a \\in A$, we have\n\\begin{equation}\n\\norm{\\pi(a)}^2 = \\norm{\\pi(a)^*\\pi(a)} = \\norm{\\pi(a^*a)} = \\norm{a^*a} = \\norm{a}^2,\n\\end{equation}\nwhich concludes the proof.\n\\end{proof}\n\n\n\\subsection{Positive Elements}\n\nWe shall continue to let $A$ be a unital $C^*$-algebra.\n\n\\begin{definition}\nAn element $a \\in A$ is \\emph{positive} if $a$ is self-adjoint and $\\sigma(a) \\subset [0,\\infty)$. We let $A_+$ denote the set of all positive elements of $A$.\n\\end{definition}\n\n\\begin{proposition}\\label{prop:positive_norm_condition}\nLet $a \\in A$ be self-adjoint and let $\\lambda \\in \\R$ such that $\\lambda \\geq \\norm{a}$. Then $a$ is positive if and only if $\\norm{\\lambda - a} \\leq \\lambda$.\n\\end{proposition}\n\n\\begin{proof}\nIf $a \\in A_+$, then \n\\begin{equation}\n\\norm{\\lambda - a} = r(\\lambda - a) = \\sup \\qty{\\abs{\\mu}: \\mu \\in \\sigma(\\lambda - a) = \\lambda - \\sigma(a)} \\leq \\lambda\n\\end{equation}\nsince $\\sigma(a) \\subset [0,\\norm{a}] \\subset [0,\\lambda]$.\n\nSuppose $\\norm{\\lambda - a} \\leq \\lambda$. If $\\mu \\in \\sigma(a)$, then \n\\begin{equation}\n\\abs{\\lambda - \\mu} \\leq  r(\\lambda - a) = \\norm{\\lambda - a} < \\lambda,\n\\end{equation}\nwhich implies that $ \\mu \\geq 0$, hence $a \\in A_+$.\n\\end{proof}\n\n\\begin{proposition}\nThe set of positive elements $A_+$ is closed.\n\\end{proposition}\n\n\\begin{proof}\nLet $(a_n)_{n \\in \\N}$ be a sequence in $A_+$ converging to $a \\in A$. Since the star operation is continuous, we have $a_n^* \\rightarrow a^*$, but since $a_n^* = a_n$ for all $n \\in \\N$, we see that $a$ is self-adjoint. Since  the norm is also continuous, we see that $\\norm{a_n} \\rightarrow \\norm{a}$. In particular, there exists $M > 0$ such that $\\norm{a_n} < M$ for all $n \\in \\N$. Then $\\norm{a} \\leq M$ and $\\norm{M - a_n} \\leq M$ for all $n \\in \\N$ by Proposition \\ref{prop:positive_norm_condition}, so \n\\begin{equation}\n\\norm{M - a} = \\lim_{n \\rightarrow \\infty} \\norm{M - a_n} \\leq M.\n\\end{equation}\nSince $\\norm{a} \\leq M$ and $\\norm{M - a} \\leq M$, Proposition \\ref{prop:positive_norm_condition} implies that $a$ is positive.\n\\end{proof}\n\n\\begin{proposition}\nThe sum of two positive elements is positive.\n\\end{proposition}\n\n\\begin{proof}\nIf $a, b \\in A_+$,  then $a+b$ is self-adjoint and Proposition \\ref{prop:positive_norm_condition} implies\n\\begin{equation}\n\\norm{\\norm{a} + \\norm{b} - (a + b)} \\leq \\norm{\\norm{a} - a} + \\norm{\\norm{b} - b} \\leq \\norm{a} + \\norm{b}.\n\\end{equation}\nA second application of Proposition \\ref{prop:positive_norm_condition} yields $a + b \\in A_+$.\n\\end{proof}\n\n\\begin{proposition}\\label{prop:positive_conditions}\nLet $a \\in A$ be self-adjoint. The following are equivalent.\n\t\\begin{enumerate}\n\t\t\\item[\\tn{(i)}] The element $a$ is positive.\n\t\t\\item[\\tn{(ii)}] There exists a unique positive $b \\in A$ such that $a = b^2$.\n\t\t\\item[\\tn{(iii)}] There exists a self-adjoint $b \\in A$ such that $a = b^2$.\n\t\t\\item[\\tn{(iv)}] There exists $c \\in A$ such that $a = c^*c$.\n\t\\end{enumerate}\n\\end{proposition}\n\n\\begin{proof}\nThe implications (ii) $\\Rightarrow$ (iii) and (iii) $\\Rightarrow$ (iv) are trivial. \n\n(i) $\\Rightarrow$ (ii). By the continuous functional calculus, we can take $\\sqrt{a}$ and by the composition property and the fact that $\\qty(\\sqrt{x})^2 = x$ on $\\sigma(a)$, we have that $a = \\qty(\\sqrt{a})^2$. The fact that the square root is real-valued and that the continuous functional calculus is a $*$-homomorphism imply that $\\sqrt{a}$ is self-adjoint, and $\\sqrt{\\sigma(a)} = \\sigma(\\sqrt{a})$ implies that $\\sqrt{a}$ is positive. If $a = b^2$ for any other positive $b \\in A$, then the fact that $\\sqrt{x^2} = x$ for $x \\in \\sigma(a)$ and the composition property imply that $\\sqrt{a} = \\sqrt{b^2} = b$.\n\n(iv) $\\Rightarrow$ (i). First we prove a lemma. Given $d \\in A$, we claim that $\\sigma(-d^*d) \\subset [0,\\infty)$ implies $d = 0$. Write $d = d_1 + id_2$, where $d_1$ and $d_2$ are self-adjoint. Then\n\\begin{equation}\nd^*d + dd^* =  2d_1^2 + 2d_2^2.\n\\end{equation}\nIf $\\sigma(-d^*d) \\subset [0,\\infty)$, then $\\sigma(-dd^*) \\subset \\sigma(-d^*d) \\cup \\qty{0} \\subset [0,\\infty)$. Thus $d^*d = 2d_1^2 + 2d_2^2 - dd^*$ is positive, since it is the sum of positive elements. But then $\\sigma(d^*d) = \\qty{0}$, which implies that $d^*d = 0$ and therefore $d = 0$ by the $C^*$-property of the norm.\n\nContinuing, we suppose $a = c^*c$ for some $c \\in A$. by the continuous functional calculus, the elements $a_+ = (\\abs{a} + a)/2$ and $a_- = (\\abs{a} - a)/2$ are positive and $a = a_+ - a_-$. Furthermore, observe that\n\\begin{equation}\na_+ a_- = \\frac{1}{4}\\qty(\\abs{a}^2 - a^2) = 0.\n\\end{equation}\nDefining $d = ca_-$, we compute \n\\begin{equation}\n-d^*d = -a_- c^* c a_- = -a_-(a_+ - a_-)a_- = (a_-)^3,\n\\end{equation}\nwhich implies that $-d^*d$ is positive. By the previous paragraph, we know $d = 0$. Thus,\n\\begin{equation}\n0 = c^* d = c^*c a_- = aa_- = - (a_-)^2\n\\end{equation}\nwhich implies that $a_- = 0$, for example by self-adjointness of $a_-$ and the $C^*$-property of the norm. Thus, $a = a_+$ is positive.\n\\end{proof}\n\n\\begin{definition}\nWe define a partial ordering on $A_+$ by setting $a \\leq b$ for $a, b \\in A_+$ if and only if $b - a \\in A_+$. Reflexivity and antisymmetry are easy to check and transitivity follows since $(c - b) + (b - a) = c - a \\in A_+$ given $c - b, b - a \\in A_+$. In fact, $A_+$ is a directed set since given $a, b \\in A_+$, we have $a+b \\in A_+$ and $a, b \\leq a + b$. \n\\end{definition}\n\n\\begin{proposition}\\label{prop:inner_aut_preserves_order}\nLet $a, b \\in A_+$ and let $c \\in A$. If $a \\leq b$, then $c^*ac \\leq c^* bc$.\n\\end{proposition}\n\n\\begin{proof}\nSince $a \\in A_+$, there exists $d \\in A$ such that $a = d^*d$. Then $c^*ac = c^*d^*dc = (dc)^*dc$, so $c^*ac \\in A_+$. Likewise, $c^*bc \\in A_+$ since $b \\in B_+$. Likewise, $c^*(b - a)c \\in A_+$ since $b -a \\in A_+$, so $c^*ac \\leq c^*bc$. \n\\end{proof}\n\n\\begin{proposition}\\label{prop:positive_respects_norm}\nIf $a \\in A_+$ and $\\lambda \\geq 0$, then $a \\leq \\lambda$ if and only if $\\norm{a} \\leq \\lambda$.\n\\end{proposition}\n\n\\begin{proof}\nWe have the following equivalences:\n\\begin{equation}\na \\leq \\lambda \\quad \\Longleftrightarrow \\quad \\sigma(\\lambda - a) = \\lambda - \\sigma(a) \\subset [0, \\infty) \\quad \\Longleftrightarrow \\quad r(a) = \\norm{a} \\leq \\lambda,\n\\end{equation}\nas desired.\n\\end{proof}\n\nIf we replace $\\lambda$ in the above proposition by an arbitrary element, then we only have an implication in one direction.\n\n\\begin{proposition}\nIf $a, b \\in A_+$ and $a \\leq b$, then $\\norm{a} \\leq \\norm{b}$.\n\\end{proposition}\n\n\\begin{proof}\nWe know $b \\leq \\norm{b}$ by Proposition \\ref{prop:positive_respects_norm}, so $a \\leq \\norm{b}$ by transitivity. But this implies $\\norm{a} \\leq \\norm{b}$ by another application of Proposition \\ref{prop:positive_respects_norm}.\n\\end{proof}\n\n\\begin{proposition}\nIf $a, b \\in A_+ \\cap A^\\times$ and $a \\leq b$, then $b^{-1} \\leq a^{-1}$.\n\\end{proposition}\n\n\\begin{proof}\nNote that $a^{-1}, b^{-1} \\in A_+$ by the continuous functional calculus. Since $\\sqrt{a^{-1}}$ is self-adjoint, we have\n\\begin{equation}\n1 = \\sqrt{a^{-1}}a \\sqrt{a^{-1}} \\leq \\sqrt{a^{-1}}b\\sqrt{a^{-1}}.\n\\end{equation} \nThus, $\\sigma(\\sqrt{a^{-1}}b \\sqrt{a^{-1}}) \\subset [1, \\infty)$ and by the continuous functional calculus,\n\\begin{equation}\n1 \\geq \\qty(\\sqrt{a^{-1}}b\\sqrt{a^{-1}})^{-1} = \\sqrt{a^{-1}}^{-1} b^{-1} \\sqrt{a^{-1}}^{-1}.\n\\end{equation}\nMultiplying by $\\sqrt{a^{-1}}$ to the left and right as in the first step now yields $b^{-1} \\leq a^{-1}$.\n\\end{proof}\n\n", "meta": {"hexsha": "3e4229c21bd1be96a643b4cfd780667d45fb2c06", "size": 41784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/spectral-theory-c_-algebras.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/spectral-theory-c_-algebras.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/spectral-theory-c_-algebras.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": 52.9581749049, "max_line_length": 718, "alphanum_fraction": 0.644002489, "num_tokens": 15368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6448293266013096}}
{"text": "\\begin{itemize}\n\t\\item $(E,\\skal{.}{.})$ complex Hilbert space.\n\t\\item $A \\in \\mathcal{B(E,E)}$. \n\t\\item Consider the equation\n\\[\n\tx = A(x)+ y, \\qquad y \\in E.\n\\]\n\\[\n\t(I-A)(x)= y.\n\\]\n\\item Consider this problem for $\\lambda \\in \\mathbb{C}$. \\\\\n\\item Set \\[\n\t\\rho(A) := \\set[\\lambda \\in \\mathbb{C}]{(A- \\lambda I)^{-1} \\in \\mathcal{B}(E,E)}\n\\]\n\\item $\\rho(A)$ is called the resolvent set for $A$.\n\\item Set \\[\n\t\\sigma(A) = \\mathbb{C} \\setminus \\rho(A).\n\\]\n\\item $\\sigma(A)$ is called the spectrum of $A$.\n\\item Clearly, a necessary condition for $(A-\\lambda I)^{-1} \\in \\mathcal{B}(E,E)$ is that \n\\[\n\tA - \\lambda I:E \\to E\n\\]\nis a bijection.\n\\item Linearity for $(A-\\lambda I)^{-1}$ follows from the linearity of $A-\\lambda I$.\n\n\\end{itemize}\n\\begin{theorem}[Banachs's inverse mapping theorem]\n\t$(E,\\norm{.})$ Banach space, \\\\ $A \\in \\mathcal{B}(E,E)$. $A-\\lambda I: E \\to E$ bijection. Then\n\t\\[\n\t\t\\Rightarrow (A- \\lambda I)^{-1} \\in \\mathcal{B}(E,E)\n\t\\]\n\\end{theorem}\n\\begin{beweis}\n\tbased on the Open mapping theorem. Proof is omitted. Assume $\\lambda \\in \\sigma(A)$. Then $A-\\lambda I:E \\to E$ is not a bijection.\n\n\\begin{itemize}\n\t\\item If $A-\\lambda I: E \\to E$ is not injective then there exists $0 \\neq x \\in  E $ such that\n\t\\[\n\t\t(A- \\lambda I)(x) = 0,\n\t\\]\n\ti.e. $\\lambda$ is an eigenvalue of $A$.\n\tSet\t\n\t\\[\n\t\t\\sigma_p(A) = \\set[\\lambda \\in \\mathbb{C}]{\\lambda \\text{eigenvalue of $A$}}.\n\t\\]\n\t\\item If $A-\\lambda I$ is injective, densely defined but not bounded then $\\lambda \\in \\sigma(A)$. The set of such $\\lambda$'s is called the continuous spectrum of $A$, denoted $\\sigma_c(A)$\n\t\\item If $A-\\lambda I$ is not surjective then the set of such $\\lambda$'s is called the residual spectrum, denoted $\\sigma _r(A)$.\n\\end{itemize}\n\\end{beweis}\n \\begin{lemma*}\n \t$(E,\\norm{.})$ Banach space, $A \\in \\mathcal{B}(E,E)$ with $\\norm{A} < 1$. Then\n\t\\[\n\t\t(I-A)^{-1} \\in \\mathcal{B}(E,E)\n\t\\]\n\tand\n\t\\[\n\t\t(I-A)^{-1} = I + \\sum_{n=1}^{\\infty} A^n.\n\t\\]\n\tThis series is called a Neumannseries. \n \\end{lemma*}\n\\begin{beweis}\n\tObserve\n\t\\[\n\t\t\\norm{A^n} = \\norm{A \\cdot A \\cdots A} \\leq \\norm{A}^n, \\qquad n = 1,2,\\dots\n\t\\]\n\tand\n\t\\[\n\t\t\\sum_{n=1}^{\\infty}\\norm{A^n}< \\infty.\n\t\\]\n\tSince $E$ is a Banach space we have\n\t\\[\n\t\t\\sum_{n=1}^{\\infty}A^n \n\t\\]\n\tconverges in $\\mathcal{B(E,E)}$. Since $E$ Banach space implies $\\mathcal{B}(E,E)$ is a Banach space. \\\\\n\tNote\n\t\\[\n\t\t(I-A)\\left( I+ \\sum_{n=1}^{N} A^n \\right) = I-A^{N+1} \\to I, \\qquad \\text{in }\\mathcal{B}(E,E).\n\t\\]\n\t\\[\n\t\t\\left(I + \\sum_{n=1}^{N}A^n \\right)(I-A) = I-A^{N+1} \\to I, \\qquad \\text{in }\\mathcal{B}(E,E).\n\t\\]\n\tWe get\n\t\\[\n\t\t\\left( I + \\sum_{n=1}^{\\infty} \\right)(I-A) = I = (I-A)(I + \\sum_{n=1}^{\\infty}A^n).\n\t\\]\n\tWe have $(I-A)^{-1} $ exists and is equal to $I+ \\sum_{n=1}^{A^n}$.\n\\end{beweis}\n \\begin{lemma*}\n \t$(E,\\norm{.})$ Banach space and $A \\in \\mathcal{B}(E,E)$. Then\n\t\\begin{enumerate}\n\t\t\\item $\\sigma(A) \\neq \\emptyset$.\n\t\t\\item $\\sigma(A)$ closed set in $\\mathbb{C}$.\n\t\t\\item $\\sigma(A) \\subseteq \\overline{B(0,\\norm{A})}$\n\t\\end{enumerate}\n \\end{lemma*}\n\\begin{beweis}\n\t\\begin{enumerate}\n\t\t\\item omitted.\n\t\t\\item Enough to prove that $\\rho(A)$ is an open set in $\\mathbb{C}$. \\\\\n\t\tFix $\\lambda_0 \\in \\rho(A)$. So $(A- \\lambda_0 I)^{-1} \\in \\mathcal{B}(E,E)$. \\\\ Note:\n\t\t\\begin{align*}\n\t\t\tA-\\lambda I &= A - \\lambda_0 I - (\\lambda - \\lambda_0)I \\\\\n\t\t\t&= \\underset{\\substack{\\text{invertible} \\\\ \\text{ since }\\lambda_0 \\in \\rho(A)}}{\\underbrace{(A-\\lambda_0 I)}} \\underset{\\substack{ \\text{ invertible if} \\\\ \\norm{(\\lambda-\\lambda_0)(A- \\lambda_0 I)^{-1}}<1 \\\\ \\text{by previous lemma, i.e.} \\\\ \\abs{\\lambda - \\lambda_0} < \\frac{1}{\\norm{(A- \\lambda_0 I)^{-1}}}}}{\\underbrace{\\left( I - (\\lambda - \\lambda_0)(A- \\lambda_0 I)^{-1} \\right)}}.\n\t\t\\end{align*}\n\t\tClearly, $A-\\lambda I$ is invertible if\n\t\t\\[\n\t\t\t\\abs{\\lambda - \\lambda_0} < \\frac{1}{\\norm{(A- \\lambda_0 I)^{-1}}}.\n\t\t\\]\n\t\t\\item It is enough to show that $\\lambda \\in \\rho(A)$ if \\[\n\t\t\t\\abs{\\lambda} > \\norm{A}.\n\t\t\\]\n\t\tNote \n\t\t\\[\n\t\t\tA- \\lambda I = - \\lambda (I - \\frac{1}{\\lambda}A).\n\t\t\\]\n\t\tHere \n\t\t\\[\n\t\t\t\\norm{- \\frac{1}{\\lambda}A} = \\frac{1}{\\abs{\\lambda}} \\norm{A} < 1.\n\t\t\\]\n\t\t$I - \\frac{1}{\\lambda}A$ is invertible by previous lemma. So $\\rho(A)$.\n\t\\end{enumerate}\n\\end{beweis}\nNow assume $(E,\\skal{.}{.})$ is a complex Hilbert space with infinite dimension. $A \\in \\mathcal{K}(E,E)$ (We don't assume $A$ is self-adjoint). Then\n\\begin{enumerate}\n\t\\item $\\lambda \\in \\sigma(A) \\setminus \\set{0}$ $\\qquad $ $\\Rightarrow$ is an eigenvalue of $A$. \n\t\\item $\\lambda \\in \\sigma(A) \\setminus \\set{0}$ $\\qquad $ $\\Rightarrow $ $\\dim \\set[x \\in E]{A(x) = \\lambda x} < \\infty$.\n\t\\item $O$ is the only cluster point for $\\sigma(A)$ \n\t\\item $0 \\in \\sigma(A)$ since if $0 \\not \\in \\sigma(A)$ then $A^{-1} \\in \\mathcal{B}(E,E)$ and \\[\n\t\t\\underset{\\in \\mathcal{K}(E,E)}{\\underbrace{\\underset{\\in \\mathcal{K}(E,E)}{\\underbrace{A}} \\underset{\\in \\mathcal{B}(E,E)}{\\underbrace{A^{-1}}}}} = I.\n\t\\]\n\tBut $I \\not \\in \\mathcal{K}(E,E)$ since $E$ $\\infty$-dimensional. Just take an ON-sequence $(x_n)_{n=1}^{\\infty}$ in $E$. Then \\[\n\t\tx_n \\rightharpoonup 0, \\qquad \\text{ in }E\n\t\\]\n\tbut $\\norm{x_n}=1$ for all $n$ and if $I \\in \\mathcal{K}(E,E)$ then \n\t\\[\n\t\tx_n = I(x_n) \\to I(0) = 0, \\qquad  \\text{ in }E\n\t\\]\n\twhich implies that $\\norm{x_n}\\to 0$ for $n \\to \\infty$. Moreover (by Hilbert-Schmidt theorem) $(E, \\skal{.}{.})$ complex Hilbert space, seperable and $\\infty$-dim. $A \\in \\mathcal{K}(E,E)$ and self-adjoint it follows\n\t\\[\n\t\t\\Rightarrow \\qquad (u_n)_{n=1}^{\\infty} \\text{ ON-basis for $E$ where}\n\t\\]\n\t\\[\n\t\tA(u_n) = \\lambda_n u_n, \\qquad n=1,2,\\dots.\n\t\\]\n\t($\\lambda_n$ eigenvalue of $A$ with normalised eigenvector $u_n$) with\n\t\\[\n\t\t\\lim_{n \\to \\infty}\\lambda_n = 0.\n\t\\]\n\tFor $x \\in E$\n\t\\[\n\t\tx = \\sum_{n=1}^{\\infty} \\skal{x}{u_n}u_n\n\t\\]\n\tand\n\t\\[\n\t\tA(x) = \\sum_{n=1}^{\\infty}\\lambda \\skal{x}{\\lambda_n}u_n\n\t\\]\n\\end{enumerate}\n\\minisec{Fredholm Alternativ:}\n$E,A$ as above. Then\n\\begin{enumerate}\n\t\\item $x = A(x) + y$ is seperable for all $y \\in E$. \\\\\n\tiff\n\t\\item $x = A(x)$ has no non-trivial solution $x \\in E$.\n\\end{enumerate}\nExactly one of the statements hold:\n\\begin{enumerate}\n\t\\item (1) from above\n\t\\item (2) has a non-trivial solution $x \\in E$.\n\\end{enumerate}\nIn general (1) is seperable for $y \\in E$ iff \n\\[\n\ty \\in \\set[x \\in E]{A(x)=x}^{\\perp}.\n\\]\nIf so: If $x$ is a solution to (1) then also $x + \\tilde x$ is a solution to (1) where\n\\[\n\t\\tilde x \\in \\set[x \\in E]{A(x)=x}\n\\]\n\\begin{beweis}\n\tLook at (1). Let $(u_n)_{n=1}^{\\infty}$ be the ON-basis from the previous theorem.\n\t\\[\n\t\tx = \\sum_{n=1}^{\\infty}\\skal{x}{u_n}u_n, \\qquad y = \\sum_{n=1}^{\\infty}\\skal{y}{u_n}u_n.\n\t\\]\n\t\\[\n\t\tA(x) = \\sum_{n=1}^{\\infty} \\lambda_n \\skal{x}{u_n}u_n.\n\t\\]\n\t(1) taked the form\n\t\\[\n\t\t\\sum_{n=1}^{\\infty} \\left( \\skal{x}{u_n} - \\lambda_n \\skal{x}{u_n} - \\skal{y}{u_n} \\right) u_n = 0.\n\t\\]\n\tThis implies \n\t\\[\n\t\t(I- \\lambda)\\skal{x}{u_n}- \\skal{y}{u_n} = 0, \\qquad n=1,2,\\dots.\n\t\\]\n\tIf $\\lambda_n \\neq 1$ then\n\t\\[\n\t\t\\skal{x}{u_n} = \\frac{\\skal{y}{u_n}}{1 - \\lambda_n}.\n\t\\]\n\tIf $\\lambda_n = 1$ then $-y$ must be orthogonal to every $u_n$ corresponding by the eigenvalue $1$.\n\t\\[\n\t\t\\sum_{n=1}^{\\infty} \\frac{\\skal{y}{u_n}}{1- \\lambda_n}u_n \\in E\n\t\\]\n\tsince\n\t\\[\n\t\t(\\frac{\\skal{y}{u_n}}{1- \\lambda_n})_{n=1}^{\\infty} \\in l^2\n\t\\]\n\tsince\n\t\\[\n\t\t\\sup_{\\substack{n \\\\ \\lambda_n \\neq 1}} \\abs{\\frac{1}{1- \\lambda_n}} < \\infty\n\t\\]\n\tsince\n\t\\[\n\t\t\\lim_{n \\to \\infty}\\lambda_n = 0\n\t\\]\n\tand\n\t\\[\n\t\t(\\skal{y}{u_n})_{n=1}^{\\infty} \\in l^2.\n\t\\]\n\\end{beweis}\n\\newpage\n\\section{Boundary Value Problems for ODE's} \n\\label{sec:boundary_value_problems_for_ode_s}\nConsider\n\\[\n\t(*)\\qquad \\begin{cases}\n\t\tLu &=f \\in C([0,1]) \\\\\n\t\tR_ju &= 0 \\qquad j=1,2,\\dots,n \n\t\\end{cases}\n\\]\n(homogenuous boundary conditions),\nwhere\n\\[\n\tLu := u^{(n)} + C_{n-1}(x)u^{(n-1)} + \\dots + c_1(x)u' + c_0(x)u, \\qquad u \\in C^n([0,1])\n\\]\nwith\n\\[\n\tc_0(x),c_1(x), \\dots, c_{n-1}(x) \\in C([0,1])-\n\\]\n\\[\n\tR_j = \\sum_{k=0}^{n-1} \\left( \\alpha_{jk} u^{(k)}(0) + \\beta_{jk}u^{(k)}(1) \\right), \\qquad j=1,2,\\dots,n\n\\]\nwith\n\\[\n\t\\alpha_{jk}, \\beta_{jk} \\in \\mathbb{C}, \\qquad j=1,\\dots,n, \\qquad k=0,\\dots,n-1\n\\]\nReformulate (*).\n\\[\n\tu(x) = \\int_{0}^{1} \\underset{\\substack{\\text{Green's function} \\\\ \\text{for $L$ and $R_j$} \\\\ j=1,\\dots,n}}{\\underbrace{g(x,y)}}f(y) \\,\\mathrm{d}y \\qquad \\in C^n([0,1])\n\\]\nand satisfies the boundary conditions $R_j = 0$ for $j=1,2,\\dots,n$. \\\\\nConsider the problem\n\\[\n(**) \\qquad \t\\begin{cases}\n\t\tLu &= f(x,u), \\qquad x \\in [0,1) \\\\\n\t\tR_ju &= 0, \\qquad j=1,2,\\dots,n.\n\t\t\n\t\\end{cases}\n\\]\nThe reformulation above gives\n\\[\n\tu(x) = \\int_{0}^{1}g(x,y)f(y,u(y)) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\\]\nTo find a solution set\n\\[\n\tT(u)(x) = \\int_{0}^{1}g(x,y)f(y,u(y)) \\,\\mathrm{d}y, \\qquad x \\in [0,1].\n\\]\n\\[\n\tT: C([0,1]) \\to C([0,1])\n\\]\nA fixed point to $T$ gives a solution to $(**)$. Note that if $u \\in C([0,1])$ then\n\\[\n\tT(u) \\in C^n([0,1]) \n\\]\nand satisfies $R_j=0$ for $j=1,2,\\dots$. \\\\\nGiven $L$ and $R_j$ for $j=1,2,\\dots,n$ find the corresponding Green's function.\n\n\\begin{beispiel}\n\t\\[\n\t\t\\begin{cases}\n\t\t\tLu &= u''-u, \\qquad \\text{ on }[0,1]\\\\\n\t\t\tR_1u &=u(0)=0 \\\\\n\t\t\tR_2u &=u(1)=0\n\t\t\\end{cases}\n\t\\]\n\\end{beispiel}\n\t\\begin{theorem}\n\t\t$Lu=f \\in C([0,1])$, where\n\t\t\\[\n\t\t\tLu: = u^{(n)}+ c_{n-1}(x)u^{(n-1)} + \\dots + c_1(x)u' + c_0(x)u\n\t\t\\]\n\t\tand $\\xi = (\\xi_1, \\dots, \\xi_n) \\in \\mathbb{C}^n$. Then for $x_0 \\in [0,1]$\n\t\t\\[\n\t\t\t\\Rightarrow \\qquad \\exists\\,!\\,\\,u \\in C^n([0,1]) \\text{ with } Lu=f.\n\t\t\\]\n\t\tand \n\t\t\\[\n\t\t\t(u,u',\\dots,u^{(n-1)}) \\big|_{x_0}^{} = \\xi.\n\t\t\\]\n\t\\end{theorem}\n\t\\begin{beweis}\n\t\tReformulate the problem as a system of first order differential equations.\n\t\\[\n\t\t\\begin{cases}\n\t\t\tLu &=f \\\\\n\t\t\t(u,u',\\dots,u^{(n-1)})  \\big|_{x_0}^{} &= \\xi\n\t\t\\end{cases}\n\t\\]\n\tcorresponds to\n\t\\[\n\t\t\\begin{cases}\n\t\t\t\\tilde u' = \\tilde f \\\\\n\t\t\t\\tilde u(x_0) = \\xi\n\t\t\\end{cases}\n\t\\]\n\tand is equivalent to\n\t\\[\n\t\t\\tilde u(x) = \\xi + \\int_{x_0}^{x} \\tilde f(s) \\,\\mathrm{d}s.\n\t\\]\n\t$\\tilde f$ contains $\\tilde u$ implicitly. The statement of the proof follows from an application of Banach's fixed point theorem. (See course homepage and proof of picard's existence theorem.)\n\t\\end{beweis}\nSet \n\\[\n \t\\mathcal{N}(L) = \\set[u \\in C^n((0,1))]{Lu=0}\n\\]\n\\textbf{Claim:} \\text{    }$\\dim \\mathcal{N}(L)=n$ \\\\\nSet \\[\n\tC_R^n([0,1]) = \\set[u \\in C^n((0,1))]{R_ju = 0, j = 1,2,\\dots,n}\n\\]\nand $L_0 = L  \\big|_{C^n_R([0,1])}^{}$. Let $u_1,\\dots,u_m \\in \\mathcal{N}(L)$\n\n\\begin{theorem}\n\tThe following statements are equivalent. Let $u_1,\\dots,u_n \\in \\mathcal{N}(L)$\n\t\\begin{enumerate}\n\t\t\\item $W(x) \\neq 0$ for all $x \\in [0,1]$. \n\t\t\\item $W(x)\\neq  0$ for some $x \\in [0,1]$.\n\t\t\\item $u_1,u_2, \\dots,u_n$ is a basis for $\\mathcal{N}(L)$.\n\t\\end{enumerate}\n\twhere \n\t\\[\n\t\tW(x) = \\det \\left( \\begin{pmatrix}\n\t\t\tu_1(x) & \\dots & u_n(x) \\\\\n\t\t\tu'_1(x) & \\dots & u'_n(x) \\\\\n\t\t\t\\vdots & & \\vdots \\\\\n\t\t\tu_1^{(n-1)} & \\dots & u_n^{(n-1)(x)}\n\t\t\\end{pmatrix} \\right), \\qquad x \\in [0,1].\n\t\\]\n\\end{theorem}\n\\begin{theorem}\n\tWith the notation from above the following statements are equivalent.\n\t\\begin{enumerate}\n\t\t\\item $L_0 : C^n_R( [0,1]) \\to C([0,1])$ is a bijection.\n\t\t\\item $\\det(R_ju_k)_{1 \\leq j,k \\leq n} \\neq 0$.\n\t\\end{enumerate}\n\\end{theorem}\n\n\\begin{beispiel}[continue]\n\tFrom the example above we get\n\t\\[\n\t\tu_1(x) = e^x, \\qquad u_2(x) = e^{-x}.\n\t\\]\n\t\\[\n\t\tu(x) = A e^x + B e^{-x}\n\t\\]\n\tand\n\t\\begin{align*}\n\t\tR_1u_1 &= u_1(0)=e^0 =1 \\\\\n\t\tR_1u_2 &= u_2(0)=e^0 =1 \\\\\n\t\tR_2u_1 &= u_1(1)=e \\\\\n\t\tR_2u_2 &= u_2(1)=\\frac{1}{e}\n\t\\end{align*}\n\tand \n\t\\[\n\t\t\\det(R_ju_k) = \\det( \\begin{pmatrix}\n\t\t\t1 & 1 \\\\ e & \\frac{1}{e} \n\t\t\\end{pmatrix}) = \\frac{1}{e} - e \\neq 0.\n\t\\]\n\\end{beispiel}\n\n\\begin{theorem}\n\tAssume $u_1, \\dots,u_n$ basis for $\\mathcal{N}(L)$ and $\\det(R_ju_k) \\neq 0$. Set $G=L_0^{-1}$. \\[\n\t\t\\Rightarrow \\qquad \\exists\\,!\\, \\text{continuous }g \\in C([0,1] \\times [0,1])\n\t\\]\n\tsuch that\n\t\\[\n\t\tG(f) = \\int_{0}^{1}g(x,y)f(y) \\,\\mathrm{d}y\n\t\\] is a solution of\n\t\\[\n\t\t\\begin{cases}\n\t\t\tLu &= f \\\\\n\t\t\tR_ju &=0, \\qquad j=1,\\dots,n\n\t\t\\end{cases}.\n\t\\]\n\tHere \n\t\\[\n\t\tg(x,y)= \\underset{\\equiv e(x,y)}{\\underbrace{\\left( \\sum_{k=1}^{n}a_k(y)u_k(x) \\right)}} \\theta(x-y)+ \\sum_{k=1}^{n}b_k(y)u_k(x).\n\t\\]\n\twhere\n\t\\begin{align*}\n\t\te^{(k)}_x (y,y) &= 0, \\qquad k = 0,1,\\dots,n-2 \\\\\n\t\te^{(n-1)}_x(y,y) &=1\n\t\\end{align*}\n\tNote\n\t\\[\n\t\tLu = 1 u^{(n)} + c_{n-1}u^{(n-1)} + \\dots + c_0 u.\n\t\\]\n\tand \n\t\\begin{align*}\n\t\tR_j(g(.,y)) = 0, \\qquad 0 < y < 1, \\qquad j=1,2,\\dots,n\n\t\\end{align*}\n\\end{theorem}\nNote \n\\begin{align*}\n\t\\int_{0}^{1}g(x,y)f(y) \\,\\mathrm{d}y &= \\int_{0}^{1}e(x,y) \\theta(x-y)f(y) \\,\\mathrm{d}y + \\int_{0}^{1} \\sum_{k=1}^{n} b_k(y)u_k(x)f(y) \\,\\mathrm{d}y \\\\\n\t&= \\underset{L[...]=f}{\\underbrace{\\underset{=L [...] = f}{\\underbrace{\\int_{0}^{x}\\sum_{k=1}^{\\infty}a_k(y)u_k(x) f(y) \\,\\mathrm{d}y}} + \\underset{L[...]= 0}{\\underbrace{\\sum_{k=1}^{N} \\int_{0}^{1}b_k(y)f(y) \\,\\mathrm{d}y u_k(x)}}}}\n\\end{align*}\nCalculate $g(x,y)$ for $n=2$: \\\\\nSet \\begin{align*}\n\te(x,y) = a_1(y)u_1(x)+ a_2(y)u_2(x)\n\\end{align*}\n\\[\n\t\\begin{cases}\n\t\te(y,y) &= a_1(y)e^y + a_2(y)e^{-y} = 0 \\\\\n\t\te'_x(y,y) &= a_1(y)e^y - a_2(y) e^{-y}=1 \\\\\n\t\\end{cases}\n\\]\nSo we get\n\\begin{align*}\n\ta_1(y) &= \\frac{1}{2} e^{-y} \\\\\n\ta_2(y) &= - \\frac{1}{2} e^{-y}\n\\end{align*}\nand\n\\begin{align*} \n\te(x,y) &= \\frac{1}{2} e^{-y} e^x - \\frac{1}{2} e^{y}e^{-x}  \\\\\n\t&= \\frac{1}{2} (e^{x-y} - e^{y-x}), \\qquad (x,y) \\in [0,1] \\times [0,1]\n\\end{align*}\nSet \n\\[\n\tg(x,y) = e(x,y)\\theta(x-y) + b_1(y)u_1(x)+ b_2(y)u_2(x)\n\\]\nFor $0<y<1$\n\\begin{align*}\n\tR_1g(.,y)=0, &\\text{ i.e. }g(0,y)=0, \\qquad \\text{for }y \\in (0,1), \\\\\n\t &\\text{ i.e. }b_1(y)u_1(0)+ b_2u_2(0) = 0 \\text{ for }y \\in (0,1), \\\\\n\t &\\text{ So $b_1(y) + b_2(y) = 0$}.\n\\end{align*}\n\\begin{align*}\n\tR_2g(.,y)=0, &\\text{ i.e. }g(1,y)=0, \\qquad \\text{for }y \\in (0,1), \\\\\n\t &\\text{ i.e. }e(1,y) + b_1(y)u_1(1)+ b_2(y)u_2(1) = 0 \\text{ for }y \\in (0,1), \\\\\n\t &\\text{ So }\\frac{1}{2}\\left( e^{1-y}- e^{y-1} \\right) + b_1(y)e + b_2(y)e^{-1}=0 \\text{ for }y \\in (0,1).\n\\end{align*}\nSo we have in total\n\\[\n\t\\begin{cases}\n\t\tb_1(y) + b_2(y) &= 0 \\\\\n\t\t\\frac{1}{2}\\left( e^{1-y}- e^{y-1} \\right) + b_1(y)e + b_2(y)e^{-1} &=0 \n\t\\end{cases}.\n\\]\nWe obtain\n\\[\n\t\\begin{cases}\n\t\tb_1(y) &= -b_2(y) \\\\\n\t\tb_2(y)\\left(  e^{-1} - e \\right) &= \\frac{1}{2}\\left( e^{y-1}- e^{1-y} \\right)\n\t\\end{cases}.\n\\]\nSo\n\\[\n\tb_2(y) = \\frac{\\frac{1}{2}(e^{y-1}-e^{1-y})}{\\left( e^{-1}-e \\right)} = \\frac{1}{2} \\frac{e^{1-y}-e^{y}}{e^2-1}\n\\]\nand\n\\[\n\tb_1(y) = \\frac{1}{2} \\frac{e^y-e^{2-y}}{e^2 -1}.\n\\]\nWe obtain\n\\[\n\tg(x,y) = \\frac{1}{2}(e^{x-y}- e^{y-x})\\theta(x-t) + \\frac{1}{2} \\frac{e^{x+y-e^{x+2-y}}}{e^2-1} + \\frac{1}{2} \\frac{e^{2-y-x}-e^{y-x}}{e^2-1}.\n\\]\n\nQuestion: $g(x,y)=g(y,x)$ for all $x,y \\in [0,1]$? \\\\\nIn general, we say that $L_0 = L  \\big|_{C^n_R([0,1])}^{}$ is \\underline{symmetrie} if \n\\[\n\t\\skal{L_0(u)}{v}_{L^2} = \\skal{u}{L_0(v)}_{L^2}, \\qquad \\forall\\, u,v \\in C_R^n([0,1])\n\\]\n\n\\begin{beispiel}[continue]\n\tAs above we have\n\t\\[\n\t\tL(u) = u'' - u\n\t\\] with boundary conditions\n\t\\[\n\t\tu(0)= u(1)=0\n\t\\]\n\tSet $u,v \\in C_R^2([0,1])$\n\t\\begin{align*}\n\t\t\\skal{L_0(u)}{v}_{L^2} &= \\int_{0}^{1} L_0(u)\\bar{v} \\,\\mathrm{d}x  \\\\ \n\t\t&= \\int_{0}^{1}u'' \\bar{v}- u \\bar{v} \\,\\mathrm{d}x \\\\  \n\t\t&= - \\int_{0}^{1} u' \\bar{v} + u \\bar{v} \\,\\mathrm{d}x \n\t\t+ \\underset{=u'(1)\\underset{=0}{\\underbrace{\\bar{v}(1)}}-u'(0) \\underset{=0}{\\underbrace{\\bar{v}(0)}}}{\\underbrace{u'\\bar{v}  \\Big|_{0}^{1}}} \\\\\n\t\t&= - \\int_{0}^{1}\\left( u' \\bar{v}' + u \\bar{v} \\right) \\,\\mathrm{d}x \\\\\n\t\t&= \\int_{0}^{1} u( \\bar{v}'' - \\bar{v}) \\,\\mathrm{d}x \\\\\n\t\t&= \\int_{0}^{1} u \\overline{L_0v} \\,\\mathrm{d}x \\\\\n\t\t&= \\skal{u}{L_0v}_{L^2}\n\t\\end{align*}\n\\end{beispiel}\n", "meta": {"hexsha": "8320e8579aca47c58b07528c0e86845981a45426", "size": 15461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture13.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/lecture13.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/lecture13.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": 30.6765873016, "max_line_length": 393, "alphanum_fraction": 0.5496410323, "num_tokens": 7243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6448293257034935}}
{"text": "%!TEX root = ../../report.tex\n\n\\subsubsection{Fractals} % (fold)\n\\label{ssub:fractals}\n\n\nA fractal is defined in \\cite{Ebert2002} as ``a geometrically complex object, the complexity of which arises through the repetition of a given form over a range of scales''.\nThis concept is observed in some forms that exist in nature. From trees, mountains, coastlines to the network of neurons on a human cortex can be seen as examples of fractals. Natural shapes tend to be irregular and fragmented and exhibit a complexity incomparable to regular geometry \\cite{mandelbrot1984fractal}.\nIn \\cite{Ebert2002} is proposed to think of fractals as a new form of symmetry, \\emph{Dilation Symmetry}, which is when an object is invariant over a change of scale. This invariance migth be only qualitatively and not exact. For instance, a river network exhibit dilation symmetry if \\textit{zooming in} in some part looks the same as the whole image. As this example, many others show dilated symmetry. As clouds, tree branches and some vegetables as shown in Figure~\\ref{fig:NFractals}. These examples are fractals.\n\n\\begin{figure}\n        \\centering\n        \\begin{subfigure}[b]{0.4\\textwidth}\n                \\includegraphics[width=\\textwidth]{img/Theory/Fractals/Leaf.png}\n                \\label{fig:Fleaf}\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.4\\textwidth}\n                \\includegraphics[width=\\textwidth]{img/Theory/Fractals/Fractal_Broccoli.jpg}\n                \\label{fig:Fbrocoli}\n        \\end{subfigure}\n        \\caption{Fractals in Nature}\\label{fig:NFractals}\n\\end{figure}\n\n\nThis idea was applied in maths with the evolution of a new area in this science called fractal mathematics. The objective of this field is to describe this very complex shapes. With really simple rules as repeating a substitution pattern. \n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{img/Theory/Fractals/Fractal1_1000.png}\n\t\\caption{Geometric Fractals}\n\t\\label{fig:GFractals}\n\\end{figure}\n\nIn the Figure~\\ref{fig:GFractals} there are four examples of Geometric Fractals, with the first five iterations of each one. All of them are built by the substitution of a part of the image by another one. \n\nThe example of the second row is known as the Koch snowflake. In this example, at each iteration, all the line segments are replaced by four segments with 1/3 of the size of the original one with the two in the middle being placed in a angle forming a equilateral triangle with the original line that is removed.\n\nIt's clear that the detail that is presented in each iteration increases as the scale changes. To try to mesure this evolution there is the idea of ​​fractal dimension in which the detail in a pattern changes in comparison with the scale in which it is measured ($Fractal\\_dimension$).\n\nAs stated before, the world is visualy very complex, so when synthetizing worlds, ``\\emph{complexity} equals \\emph{work}''\\cite{Ebert2002}. This work can be done by the programer/artist or by a computer. Some cases are not easy to model procedurally. This is not the case of the fractals, as being defined as a simple mathematical function, it's relatively easy to implement a procedure to model fractals. \n\nThis techique is used to model many natural forms that present fractal properties. Mountains, as an instance, have been modeled with the use of fractals. Other natural forms that present fractal properties are trees, river systems, ligthning or vascular systems in living beings.\n\n\n\n\n% subsubsection fractals (end)\n", "meta": {"hexsha": "9793b393932018917248bf2c6f1c1feb49b80c1e", "size": 3689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/overview/1-Fractals.tex", "max_stars_repo_name": "arturalkaim/ProceduralGeneration", "max_stars_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_stars_repo_licenses": ["MIT"], "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/overview/1-Fractals.tex", "max_issues_repo_name": "arturalkaim/ProceduralGeneration", "max_issues_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_issues_repo_licenses": ["MIT"], "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/overview/1-Fractals.tex", "max_forks_repo_name": "arturalkaim/ProceduralGeneration", "max_forks_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_forks_repo_licenses": ["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.78, "max_line_length": 518, "alphanum_fraction": 0.7590132827, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.8933094046341532, "lm_q1q2_score": 0.6447400046097208}}
{"text": "\\section{Uniform Convergence}\r\n\\begin{definition}\r\n    A complex sequence $x_n$ is said to converge to a complex number $x$ if $\\forall\\epsilon>0,\\exists N\\in\\mathbb N$ such that $\\forall n>N$, $|x-x_n|<\\epsilon$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $S$ be a set and let $f_n:S\\to\\mathbb C$ be a sequence of functions.\r\n    Let $f:S\\to\\mathbb C$ be a function.\r\n    We say $f_n\\to f$ pointwise if for any $x$, $f_n(x)\\to f(x)$.\r\n    In other words, $\\forall x\\in S, \\forall\\epsilon>0, \\exists N\\in\\mathbb N, \\forall n>N$, $|f(x)-f_n(x)|<\\epsilon$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $S$ be the closed interval $[0,1]$ and $f_n(x)=x^n$, then $f_n\\to f$ pointwise where\r\n    $$f(x)=\r\n    \\begin{cases}\r\n        1\\textit{, if $x=1$}\\\\\r\n        0\\textit{, otherwise}\r\n    \\end{cases}$$\r\n\\end{example}\r\nNote that in this example, despite the fact that all of $f_n$ are continuous, even smooth, the resulting limit $f$ needs not be continuous.\\\\\r\nHere is another example:\r\n\\begin{example}\r\n    Let $S=\\mathbb R_{\\ge 0}$ and let $f_n(x)=x^2e^{-nx}$, then $f_n\\to 0$ pointwise, since\r\n    $$0\\le |f_n(x)|=\\frac{x^2}{e^{nx}}= \\frac{x^2}{1+nx+\\frac{n^2x^2}{2}+\\frac{n^3x^3}{6}\\cdots}\\le\\frac{x^2}{nx}=\\frac{x}{n}\\to0$$\r\n    as $n\\to\\infty$.\r\n\\end{example}\r\nThere is another form of convergence, called uniform convergence, which is defined as follows:\r\n\\begin{definition}\r\n    Let $S$ be a set and let $f_n:S\\to\\mathbb C$ be a sequence of functions.\r\n    Let $f:S\\to\\mathbb C$ be a function.\r\n    We say $f_n\\to f$ uniformly if $\\forall\\epsilon>0, \\exists N\\in\\mathbb N, \\forall n>N, \\forall x\\in S, |f(x)-f_n(x)|<\\epsilon$.\r\n\\end{definition}\r\nNote that the only difference between pointwise and uniform convergence is that the large integer $N$ does not depend on $x$ if the convergence is uniform.\r\nNote also that uniform convergence implies pointwise convergence, but not the other way around.\r\nAlthough it does not seem to be such a great difference in definition, in practice, it makes all the difference in the world.\r\n\\begin{proposition}\r\n    The sequence in the first example, i.e. $f_n:[0,1]\\to\\mathbb R$ with $f_n(x)=x^n$, does not converge uniformly.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We can take for example $\\epsilon=1/2$. Then for any $n\\in\\mathbb N$, we can take $x=\\sqrt[n]{2/3}$, so that we have\r\n    $$|f_n(x)-f(x)|=|f_n(x)|=\\frac{2}{3}>\\frac{1}{2}$$\r\n    So the claimed $N$ does not exist.\r\n    Therefore the sequence $f_n$ does not converge uniformly.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    The sequence in the second example, i.e. $f_n=\\mathbb R_{\\ge 0}\\to\\mathbb R$ where $f_n(x)=x^2e^{-nx}$, converge absolutely.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Note that\r\n    $$0\\le f_n(x)=\\frac{x^2}{e^{nx}}=\\frac{x^2}{1+nx+\\frac{n^2x^2}{2}+\\cdots}\\le\\frac{x^2}{n^2x^2/2}=\\frac{2}{n^2}$$\r\n    Therefore for any $\\epsilon>0$, we can take $N=\\lceil\\sqrt{2/\\epsilon}\\rceil$, so for any $x\\ge 0, n>N$, we ahve\r\n    $$|f(x)-f_n(x)|=|f_n(x)|=f_n(x)\\le\\frac{2}{n^2}<\\frac{2}{N^2}\\le\\frac{2}{(\\sqrt{2/\\epsilon})^2}=\\epsilon$$\r\n    So $f_n\\to 0$ uniformly.\r\n\\end{proof}\r\nIn fact, although continuous functions may not converge pointwise to a continuous function, they do converge uniformly to one.\r\n\\begin{theorem}\r\n    Let $S\\subset\\mathbb C$ be open.\r\n    Suppose that $f_n:S\\to\\mathbb C$ is a sequence of continuous functions.\r\n    If $f_n\\to f$ uniformly, then $f$ is continuous as well.\r\n\\end{theorem}\r\n\\begin{proof}[Informal sketch]\r\n    Idea: Transfer the nice property of $f_n$ to $f$.\r\n    Choose large enough $N$ such that $f_n-f$ is arbitratily small for all $n>N$.\r\n    We can always choose $x'$ close to $x$ where $f_n(x)$ close to $f(x)$.\r\n    Then just use triangle inequality.\r\n    \"3-$\\epsilon$ proof\"\r\n\\end{proof}\r\n\\begin{proof}\r\n    $\\forall\\epsilon>0$, we can choose large enough $N$ such that $\\sup|f_n-f|<\\epsilon/3$\r\n    We can choose $\\delta>0$ such that $|x-x'|<\\delta\\implies |f_n(x)-f_n(x')|<\\epsilon/3$.\r\n    $$|f(x)-f(x')|\\le |f(x)-f_n(x)|+|f(x')-f_n(x')|+|f_n(x)-f_n(x')|<3\\frac{\\epsilon}{3}=\\epsilon$$\r\n    As desired.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. We can use this theorem to show that $x^n$ as in the previous example does not converge uniformly.\\\\\r\n    2. It is not true that differentiability is preserved under unform convergence.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    Let $f_n:[a,b]\\to\\mathbb R$ be all Riemann integrable.\r\n    Then if it converges uniformly, its limit is also Riemann integrable.\r\n    Furthermore,\r\n    $$\\int_a^b\\lim_{n\\to\\infty} f_n(x)\\,\\mathrm dx=\\lim_{n\\to\\infty}\\int_a^b f_n(x)\\,\\mathrm dx$$\r\n\\end{theorem}\r\nRecall that a function is Riemann integerable if and only if the upper and lower sums of $f$ on the interval can be arbitratily close.\r\n\\begin{proof}\r\n    Firstly $f$ is bounded. Since $f_n$ are bounded, we can just choose large enough $n$ such that $|f_n-f|<1$ and $|f_n|<M$, then\r\n    $|f|\\le|f-f_n|+|f_n|<\\epsilon+M<M+1$ so $f$ is bounded.\\\\\r\n    For $\\epsilon>0$ choose $N$ such that $\\sup|f_n-f|<\\epsilon/(3(b-a))$ for any $n>N$.\r\n    Since $f_n$ is integrable, there is some disection $D$ of the interval $[a,b]$ such that $U_D(f_n)-L_D(f_n)<\\epsilon/3$.\r\n    We have\r\n    $$|L_D(f)-L_D(f_n)|=\\sum_{(x_i)\\in D}\\left|\\inf_{x\\in[x_i, x_{i+1}]}f(x)-\\inf_{x\\in[x_i, x_{i+1}]}f_n(x)\\right|(x_{i+1}-x_i)<\\epsilon/3$$\r\n    Similarly $|U_D(f)-U_D(f_n)|<\\epsilon/3$.\r\n    So\r\n    \\begin{align*}\r\n        |U_D(f)-L_D(f)|&\\le|U_D(f)-U_D(f_n)|\\\\\r\n        &+|L_D(f_n)-L_D(f)|+|U_D(f_n)-L_D(f_n)|\\\\\r\n        &<3\\epsilon/3=\\epsilon\r\n    \\end{align*}\r\n    This shows that $f$ is integrable.\r\n    Finally, we have\r\n    $$|\\int_a^bf(x)-f_n(x)\\,\\mathrm dx|\\le \\int_a^b\\sup|f(x)-f_n(x)|\\,\\mathrm dx<\\epsilon/3<\\epsilon$$\r\n    which completes the proof.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. For uniform convergence, we can swap the integral and the limit.\\\\\r\n    2. If $f_n\\to f$ uniformly and that all $f_n$ is bounded, then $f$ is bounded.\r\n\\end{remark}\r\n\\begin{corollary}\r\n    For uniform convergence, we can swap infinite sums and integral.\r\n    That is, if $f_n:[a,b]\\to\\mathbb R$ is a sequence of integrable functions whose partial sum converges absolutely to some function $f$, then $f$ is integrable and\r\n    $$\\int_a^bf(x)\\,\\mathrm dx=\\sum_{n=1}^\\infty\\int_a^bf_n(x)\\,\\mathrm dx$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let\r\n    $$F_n(x)=\\sum_{k=1}^nf_k(x)$$\r\n    so $F_n$ are integrable and $F_n\\to f$ uniformly.\r\n    Then we can just apply the preceding theorem.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $f_n:[a,b]\\to\\mathbb R$ be continuously differentable on $[a,b]$.\r\n    Assume that the sequence of partial sums of $f^\\prime_n$ at every point converges uniformly.\r\n    And there is an $c\\in[a,b]$ such that\r\n    $$\\sum_{n=1}^\\infty f_n(c)$$\r\n    converges, then the sequence of partial sums of $f_n$ converges uniformly.\r\n    Furthermore, the limit $f$ is continuously differentiable and\r\n    $$f^\\prime(x)=\\sum_{n=1}^\\infty f^\\prime_n(x)$$ \r\n\\end{theorem}\r\n\\begin{proof}[Sketch of proof]\r\n    Let\r\n    $$F_n(x)=\\sum_{k=1}^nf_k(x), g(x)=\\sum_{n=1}^\\infty f^\\prime_n(x)$$\r\n    So we want to find a particular solution to the differential equation $f^\\prime=g$, and show that $F_n$ converges unformly to it.\r\n    So basically we want to do\r\n    $$f(x)=\\int_c^x g(t)\\,\\mathrm dt+\\sum_{n=1}^\\infty f_n(c)=\\lim_{n\\to\\infty}F_n(x)=\\sum_{n=1}^\\infty f_n(x)$$\r\n    rigorously and it would be done.\r\n\\end{proof}\r\n\\begin{proof}\r\n    Let\r\n    $$g(x)=\\sum_{n=1}^\\infty f^\\prime_n(x)$$\r\n    $g$ is continuous and hence Riemann integrable on $[a,b]$.\r\n    Define $f:[a,b]\\to\\mathbb R$ by \r\n    $$f(x)=\\int_c^xg(t)\\,\\mathrm dt+\\lambda$$\r\n    where\r\n    $$\\lambda=\\sum_{n=1}^\\infty f_n(c)$$\r\n    By FTC, $f$ is differentiable and $f^\\prime(x)=g(x)$.\r\n    Since $g$ is continuous, $f\\in\\mathcal C^1([a,b])$.\r\n    It remains to show that the series sum of $f_n(x)$ converges uniformly to $f(x)$.\r\n    Let $F_n(x)$ be the partial sum of the series, then by estimating its difference with $f$ and the fact that the partial sum of derivatives of $f_n$ converges uniformly (use FTC again), we can show that $F_n\\to f_n$ uniformly.\r\n    [Write details later]\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $f_n$ be a sequence of scalar function on a set $S$.\r\n    We say $f_n$ is uniformly Cauchy on $S$ if $\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall x\\in X,\\forall n,m>N$,\r\n    $$|f_n(x)-f_m(x)|<\\epsilon$$\r\n\\end{definition}\r\n\\begin{theorem}[General Principle of Uniform Convergence]\\label{GP_UnifConv}\r\n    A sequence of uniformly Cauchy scalar functions $f_n$ on $S$ converges uniformly.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Firstly, we shall find a pointwise limit $f$ of $f_n$.\r\n    The existence of $f$ is immediate since $f_n(x)$ is always Cauchy (hence converges) with $x$ fixed.\\\\\r\n    Then we shall show that this convergence is uniform.\r\n    Choose any $\\epsilon>0$, $\\exists N\\in\\mathbb N,\\forall x\\in X,\\forall n,m>N,|f_n(x)-f_m(x)|<\\epsilon/2$.\r\n    Now we fix $x\\in S,n>N$, since $f_n\\to f$ pointwise, we can choose $m>N$ with $|f_m(x)-f(x)|<\\epsilon/2$, then\r\n    $$|f(x)-f_n(x)|\\le |f(x)-f_m(x)|+|f_m(x)-f_n(x)|<2\\epsilon/2<\\epsilon$$\r\n    So $f_n\\to f$ uniformly.\r\n\\end{proof}\r\nSo what we did is to fix the $x$ and the $n$, then let that $m$ tend to infinity, then we can use the pointwise convergence to give the result.\r\nThis is how we get pass the dependence of $N$ on $x$ in the pointwise convergence result.\r\n\\begin{corollary}\r\n    Let $f_n$ be a sequence of scalar functions on $S$, let\r\n    $$\\sum_{n=1}^\\infty M_n$$\r\n    be convergent with $M_n\\ge 0$.\\\\\r\n    If $\\sup |f_n|\\le M_n$ for any $n$, then\r\n    $$\\sum_{n=1}^\\infty f_n$$\r\n    converges uniformly.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let $F_n$ be the partial sum of $f_n$, $F_n$ is uniformly Cauchy due to the convergence of the series of $M_n$.\r\n    Essentially, $\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n,m>N$,\r\n    $$\\sum_{k=n+1}^mM_k<\\epsilon$$\r\n    so\r\n    $$\\sum_{k=n+1}^m|f_n(x)|<\\epsilon$$\r\n    Therefore it is unifomly Cauchy, so it converges uniformly.\r\n\\end{proof}\r\nNow we consider the power series\r\n$$\\sum_{n=0}^\\infty a_n(z-a)^n$$\r\n$(a_n)_0^\\infty$ be a sequence of complex number.\r\nLet $R$ be the radius of convergence.\r\nNow on the disk $|z-a|<R$, we consider\r\n$$f(z)=\\sum_{n=0}^\\infty a_n(z-a)^n$$\r\nThe question is: is the convergence uniform?\r\n\\begin{example}\r\n    Consider\r\n    $$f(z)=\\sum_{n=0}^\\infty z^n=\\frac{1}{1-z}$$\r\n    where $R=1$.\r\n    It does not converge uniformly.\r\n    Indeed, the $N^{th}$ partial sum is bounded by $N+1$ but $1/(1-z)$ is unbounded.\r\n\\end{example}\r\n\\begin{theorem}\r\n    For any $r$ with $0<r<R$, the series converges uniformly on $D(a,r)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For $w\\in\\mathbb C$ such that $r<|w-a|<R$, there is an $M$ such that $|a_n(w-a)^n|<M$ for some $M>0$ and any $n$.\r\n    We have $|z-a|/|w-a|<1$ for any $z\\in D_(a,r)$, hence by taking $M_n=M(r/|w-a|)^n$ shows the result.\r\n\\end{proof}\r\nThe derivative of a power series (we can prove that it is complex differentiable, and we can do it term-by-term) has the same radius of convergence.\r\n\\begin{remark}\r\n    If we fix $w\\in D(a,R)$, we can choose $r$ such that $|w-a|<r<R$.\r\n    Fix any $\\delta>0$ such that $|w-a|+\\delta<r$, then $D(w,\\delta)\\subset D(a,r)$, so\r\n    $$\\sum_{n=0}^\\infty a_n(z-a)^n$$\r\n    converges uniformly on $D(w,\\delta)$.\r\n    We say it is locally uniformly on $D(a,R)$.\r\n\\end{remark}", "meta": {"hexsha": "eff631cef853e6f67337790780860b5b8d8a3929", "size": 11383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/unifconv.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": "1/unifconv.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": "1/unifconv.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": 53.6933962264, "max_line_length": 230, "alphanum_fraction": 0.6421857155, "num_tokens": 3964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8933093961129794, "lm_q1q2_score": 0.6447399877663528}}
{"text": "\\section{Direct Limits}\\label{limits}\nGoals are UCT (universal coefficient theorem), which is about $ H_\\ast(X;M)$ for varying $M$, the K\\\"{u}nneth theorem (which is about $ H_\\ast(X\\times Y)$), cohomology, and Poincar\\'{e} duality.\n\\subsection{Two more things about $\\Tor$}\nIf $R$ is a PID, then there's not so much to say about $\\Tor$, because any submodule of a free module is free. So that means that any $R$-module has a free resolution $0\\to F_1=\\ker(f)\\to F_0\\xrightarrow{f}\\to N\\to 0$. It follows that $\\Tor^R_n(M,N)=0$ for $n>1$. If you have a field, then tensoring is exact, so $\\Tor^k_0(M,N)=0$ for $n>0$. That's why it's easy to work with fields. (There's also Pr\\\"ufer rings, where every module is flat.) By the way, this means that if you have a sexseq $0\\to A\\to B\\to C\\to 0$, then over a PID $R$, there's a six-term exact sequence $0\\to\\Tor^R_1(M,A)\\to \\Tor^R_1(M,B)\\to \\Tor^R_1(M,C)\\to M\\otimes_R A\\to M\\otimes_R B\\to M\\otimes_R C\\to 0$.\n\\begin{example}\nI want to give an example when you do have higher $\\Tor$. Let $k$ be a field. Let $R=k[e]/(e^2)$. This is sometimes called the ``dual numbers'', or the exterior algebra over $k$. We're going to consider $R$-modules. Let's construct a projective resolution of $k$. Hmm. What is an $R$-module $M$? It's just a $k$-vector space $M$ with an operator $d$ that has action given by multiplication by $e$, and this satisfies $d^2=0$. And this is a chain complex! I guess it's not quite a chain complex because for us chain complexes are graded. So I guess it's an ungraded chain complex. I can consider $ H(M;d):=\\ker d/\\img d$. Here's an example of an $R$-module. There's the augmentation $R\\to k$ sending $e\\mapsto 0$. This makes $k$ an $R$-module, where $d=0$. Let's construct a free resolution of $k$.\n\nHere we go. We're going to write $k=\\bullet(=1)$ and $R:=(1=)\\bullet\\xrightarrow{d}\\bullet(=e)$. Well, we have $R\\to k$ given by $(\\bullet\\xrightarrow{d}\\bullet)\\to \\bullet$. The kernel is not free, so we get $(\\bullet\\xrightarrow{d}\\bullet)\\to (\\bullet\\xrightarrow{d}\\bullet)\\to \\bullet$. And this continues, so we get a projective resolution $\\cdots\\xrightarrow{e} R\\xrightarrow{e} R\\xrightarrow{e} R\\to k$. What is $\\Tor$? Well, $\\Tor^R_\\ast(M,k)$ is the homology of the following chain complex $\\cdots\\xrightarrow{d} M\\xrightarrow{d} M\\to 0$. What is that homology? Clearly $\\Tor^R_0(M,k)=M\\otimes_R k=M/dM=M/eM$. This is often called the module of indecomposables. And, $\\Tor^R_n(M,k)= H(M;d)$.\n\\end{example}\nLast comment about $\\Tor$ is that there's a symmetry there. Of course, $M\\otimes_R N\\cong N\\otimes_R M$. This uses the fact that $R$ is commutative. This leads right on to saying that $\\Tor^R_n(M,N)\\cong \\Tor^R_n(N,M)$. We've been computing $\\Tor$ by taking a resolution of the second variable. But I could equally have taken a resolution of the first variable. This follows from the fundamental theorem of homological algebra.\n\\subsection{Direct limits}\nA long time ago, I said what a poset was. Let me tell you a joke about posets. I was at a conference, and Quillen was giving a talk. He was a student of Raoul Bott. Quillen was giving his talk, and he used the term ``poset''. This word was invented by Garrett Birkhoff(?). Then Bott objected and said ``What is this crazy word?'', and Quillen responded ``What are you talking about? Your colleague invented it!''. Anyway, it's not a joke. I guess it's just a piece of MIT and Harvard rivalry.\n\nAnyway, a poset is a small category $\\cI$ such that $\\#\\cI(i,j)\\leq 1$ and isomorphism implies identity. I want to talk about a \\emph{directed set}.\n\\begin{definition}\nA poset $(\\cI,\\leq)$ is \\emph{directed} if, for every $i,j$, there exists a $k$ such that $i\\leq k$ and $j\\leq k$.\n\\end{definition}\n\\begin{example}\nFor example, the natural numbers $\\Z_{\\geq 0}$ with equality. Another example: if $X$ is a space and $I$ is the set of open subsets of $X$. It's directed by saying that $U\\leq V$ if $U\\subseteq V$. This is because $U,U^\\prime$ need not be comparable, but $U,U^\\prime\\subseteq U\\cup U^\\prime$. Another example is $\\Z_{>0}$ where $i\\leq j$ if $i|j$. This is because $i,j|(ij)$.\n\\end{example}\n\\begin{definition}\nLet $\\cI$ be a directed set. An $\\cI$-directed diagram in $\\cc$ is a functor $\\cI\\to\\cc$. This means that for every $i\\in \\cI$, there is $X_i\\in\\cc$, and for every $i\\leq j$, there's a map $X_i\\xrightarrow{f_{ij}} X_j$ (and similarly for composition).\n\\end{definition}\n\\begin{example}\\label{linear}\nIf $\\cI=(\\Z_{\\geq 0},\\leq)$, then you get $X_0\\xrightarrow{f_{01}}X_1\\xrightarrow{f_{12}}X_2\\to\\cdots$. This is the most important.\n\\end{example}\n\\begin{example}\nSuppose $\\cI=(\\Z_{>0},|)$, i.e., the third example above. You can consider $\\cI\\to\\mathbf{Ab}$, say assigning to each $i$ the integers $\\Z$, and $f_{ij}:\\Z\\xrightarrow{j/i}\\Z$. You get the picture.\n\\end{example}\nThese directed systems are a little complicated. But there's a simple one, namely the constant one. \n\\begin{example}\nLet $\\cI$ be any directed set. You have a constant functor $c_A:\\cI\\to\\cc$ at some $A\\in\\cc$.\n\\end{example}\nOf course, $\\cI$-directed systems in $\\cc$ are functors $\\cI\\to\\cc$. They have natural transformations, and those are the morphisms in the category of $\\cI$-directed systems. That just means that if I have two directed systems $X,Y:\\cI\\to\\cc$, then a map from one to the other is a commuting diagram:\n\\begin{equation*}\n\\xymatrix{X_i\\ar[r]\\ar[d]^{g_i} & X_j\\ar[d]^{g_j}\\\\\nY_i\\ar[r] & Y_j}\n\\end{equation*}\nfor all $i\\leq j$.\n\nIt'd be great if every directed system was constant, but this isn't true. This leads to direct limits.\n\\begin{definition}\nA direct limit is an object $L$ and a map $X\\to c_L$, which is initial among maps to constant systems. This means that I have some other map $X\\to c_A$, then there's a unique induced map $c_L\\to c_A$ that is induced from a map $L\\to A$. We write $\\varinjlim_{i\\in \\cI}X_i=\\colim_{i\\in I}X_i$. (My own note: it's also sometimes called an an inductive limit.)\n\\end{definition}\nThis is a universal property. So two different direct limits are canonically isomorphic.\n\\begin{example}\nConsider $\\cI=(\\Z_{\\geq 0},\\leq)$, then you get $X_0\\xrightarrow{f_{01}}X_1\\xrightarrow{f_{12}}X_2\\to\\cdots$ in $\\mathbf{Top}$. What is the direct limit? It's going to be $\\bigcup_i X_i$. But what's the topology? Give it the finest topology so that all of the maps to the union are open. This just means that a subset is open in $\\bigcup_i X_i$ if the preimage is open.\n\\end{example}\n\\begin{example}\nRecall our example where we let $\\cI=(\\Z_{>0},|)$, i.e., the third example above. You can consider $\\cI\\to\\mathbf{Ab}$, say assigning to each $i$ the integers $\\Z$, and $f_{ij}:\\Z\\xrightarrow{j/i}\\Z$. The colimit is $\\QQ$, where you send $X_n\\to\\QQ$ via $1\\mapsto \\frac{1}{n}$.\n\\end{example}\n\\begin{lemma}\nLet $X:\\cI\\to\\mathbf{Ab}$ (or $\\mathbf{Mod}_R$). A map $f:X\\to c_L$ is the direct limit (we write $f_i:X_i\\to L$) if and only if:\n\\begin{enumerate}\n\\item For every $x\\in L$, there exists an $i$ and an $x_i\\in X_i$ such that $f_i(x_i)=x$.\n\\item Let $x_i\\in X_i$ be such that $f_i(x_i)=0$ in $L$. Then there exists some $j\\geq i$ such that $f_{ij}(x_i)=0$ in $X_j$.\n\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\nStraightforward.\n\\end{proof}\nIt generalizes the observation that $\\QQ$ is the colimit of the diagram we drew above for $\\cI=(\\Z_{>0},|)$.\n\\begin{corollary}\nThe direct limit $\\varinjlim_I:\\Fun(\\cI,\\mathbf{Ab})\\to\\mathbf{Ab}$ is exact. In other words, $X_\\bullet\\to Y_\\bullet\\xrightarrow{p} Z_\\bullet$ is an exact sequence of $\\cI$-directed systems (at every degree, we get an exact sequence of abelian groups), then $\\varinjlim_IX_\\bullet\\xrightarrow{i} \\varinjlim_IY_\\bullet\\xrightarrow{p} \\varinjlim_IZ_\\bullet$.\n\\end{corollary}\n\\begin{proof}\nFirst of all, $X_\\bullet\\to Z_\\bullet$ is zero. Thus it factors through the constant zero object, so that $\\varinjlim_IX_\\bullet\\to \\varinjlim_I Z_\\bullet$ is zero. Let $y\\in \\varinjlim_IY_\\bullet$, and suppose $y$ maps to $0$ in $\\varinjlim_IZ_\\bullet$. By the first condition, there exists $i$ such that $y=f_i(y_i)$ for some $y_i\\in Y_i$. Then $p(y)=f_ip(y_i)$ because $p$ is a map of systems. This is zero. This means that there is $j\\geq i$ such that $f_{ij}p(y_i)=0$. We have an element in $Y_j$ that maps to zero, so there is some $x_j$ that is the preimage of the element in $Y_j$. So we're done.\n\\end{proof}\nThis makes the world a nice place to live.\n", "meta": {"hexsha": "c4f39d135991116389cc80c59c0ae3d0259b510a", "size": 8398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-23-direct-limits.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-23-direct-limits.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-23-direct-limits.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": 119.9714285714, "max_line_length": 797, "alphanum_fraction": 0.7107644677, "num_tokens": 2757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7931059707450325, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6446899232004796}}
{"text": "\\section{Elementary Number Theory}\r\nLet $n$ be an natural number.\r\nThe multiples of $n$ are all integers $kn$ where $k\\in\\mathbb Z$.\r\nFor example, $2n,5n,n,-4n,0$ are all multiplies of $n$.\r\n\\begin{definition}\r\n    If $m$ is a multiple of $n$, we say $n$ divides $m$, or $n$ is a divisor of $m$, written as $n|m$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    We say a natural number $n\\ge 2$ is a prime if it has no divisors apart from $1$ and $n$.\\\\\r\n    Otherwise, we call it to be composite.\r\n\\end{definition}\r\n\\begin{example}\r\n    $2,3,5,7,11,13,17,\\ldots$ are prime.\\\\\r\n    $10,25,34,44,57$ are composite.\r\n\\end{example}\r\nOur aim now is to break up a number into primes, for example $63=3\\time 3\\time 7$, and hopefully it would be unique.\r\n\\begin{proposition}\r\n    Every natural number $n\\ge 2$ is expressible as a product of primes.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Strong induction.\\\\\r\n    The statement is obvious true for $n=2$.\r\n    Given an $n>2$, if it is prime, then it is done.\r\n    Otherwise, we can write $n=ab$ where $n>a,b>1$.\r\n    By induction hypothesis, we can write $a,b$ as a product of primes.\r\n    $$a=p_1p_2\\cdots p_k, b=q_1q_2\\cdots q_l$$\r\n    where $p_i,q_i$ are primes.\r\n    So $n=p_1p_2\\cdots p_kq_1q_2\\cdots q_l$, therefore the statement is true for $n$.\r\n    And it's done.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Although we start at $2$, sometimes you can regard $1$ as a product of no primes.\\\\\r\n    2. There is no nice pattern of primes.\r\n    There is no algebraic formula for the $n^{th}$ prime.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    There are infinitely many primes.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose for the same of contradiction that there is only finitely many, let\r\n    $$p_1,p_2,\\ldots, p_n$$\r\n    be the primes.\r\n    So consider $k=p_1p_2\\cdots p_n+1$, it does not have any prime factors as none of the primes divide $k$.\r\n    This is a contradiction to the fact that $k$ has a prime factorisation.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    The prime factorization of any positive integer $n\\ge 2$ is unique.\r\n\\end{theorem}\r\nThe uniqueness is taken up to re-ordering.\r\nWhy is it true?\r\nWhy can't $41\\times 101=67\\times 73$?\r\nWe need $p|ab\\implies p|a\\lor p|b$ where $p$ is a prime number.\r\nWe need $p$ to be prime since $6|8\\times3$ but $6\\nmid 8$ and $6\\nmid 3$.\r\nThis has to be hard to prove since it is about prime dividing things instead of things dividing primes, as in the definition.\r\n\\subsection{Highest Common Factors}\r\n\\begin{definition}\r\n    For integers $a,b$ we say the positive integer $c$ is the HCF (Highest Common Factor) of $a,b$ if\\\\\r\n    1. $c|a$ and $c|b$. ($c$ is a common factor of $a,b$)\\\\\r\n    2. For any positive integers $d$ such that $d|a$ and $d|b$, then $d|c$. (every common factor of $a,b$ divides c).\r\n\\end{definition}\r\n\\begin{example}\r\n    The HCF of $18$ and $12$ is $6$.\r\n\\end{example}\r\nWe want to show that an HCF always exists\r\n\\begin{proposition}[Division Algorithm]\r\n    For natural numbers $n,k$, we can write $n=qk+r$, for some integers $q,r$ with $0\\le r<k$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Induction on $n$.\r\n    $n=1$ is trivial.\\\\\r\n    Given $n>1$, we have $n-1=qk+r$ for some integers $q,r$ with $0\\le r<k$.\\\\\r\n    If $r<k-1$, then we have $n=qk+(r+1)$.\r\n    If $r=k-1$, then $n=(q+1)k+0$.\r\n\\end{proof}\r\nWe can find HCF by Euclid's Algorithm.\r\n\\begin{definition}\r\n    The HCF of $a$ and $b$ where $a\\ge b$.\\\\\r\n    Write $q_1b+r_1$ (where $0\\le r_1<b$).\\\\\r\n    Then write $b=q_2r_1+r_2$ (where $0\\le r_2<r_1$).\\\\\r\n    Then write $r_1=q_3r_2+r_3$ (where $0\\le r_3<r_2$).\\\\\r\n    Continue this process until some remainder $r_{n-1}=q_{n+1}r_n+r_{n+1}$ where $r_{n+1}=0$.\r\n    (If necessary, take $a=r_{-1}, b=r_0$)\r\n    That is, some remainder goes to $0$. \r\n\\end{definition}\r\n\\begin{example}\r\n    $372,162$\\\\\r\n    $372=2\\times 162+48$.\\\\\r\n    $162=3\\times 48+18$.\\\\\r\n    $48=2\\times 18+12$.\\\\\r\n    $18=1\\times 12+6$.\\\\\r\n    $12=2\\times 6+0$.\\\\\r\n    So the HCF of $372,162$ is $6$.\r\n\\end{example}\r\n\\begin{theorem}\r\n    The Euclid's Algorithm works.\\\\\r\n    That is, the HCF exists and can always be found by Euclid's Algorithm.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $r_n$ be the output.\r\n    Firstly, it is a common factor of $a,b$, since $r_n|r_{n-1},r_n|r_{n-2}|\\cdots,r_n|b,r_n|a$ inductively.\\\\\r\n    Then, for any other common factor $d$ of $a,b$, we know that $d|r_1$, inductively $d|r_i$ for every $i$, then $d|r_n$.\\\\\r\n    Note that the algorithm always terminate, since the sequence $r_i$ is strictly decreasing.\r\n    In fact, there are at most $b$ steps before it terminates.\r\n\\end{proof}\r\n\\begin{example}\r\n    $82,57$\\\\\r\n    $82=57\\times 1+25$.\\\\\r\n    $57=25\\times 2+7$.\\\\\r\n    $25=7\\times 3+4$.\\\\\r\n    $4=3\\times 1+1$.\\\\\r\n    $3=3\\times 1+0$.\\\\\r\n    So the HCF of $82,57$ is $1$.\r\n\\end{example}\r\nIf two positive integers have HCF $1$, we say that they are coprime.\\\\\r\nCan we write $1=82x+57y$ for some integers $x,y\\in\\mathbb Z$?\r\nSo we have $1=4-3=4-(7-4)=2\\times 4-7=2\\times (25-3\\times 7)-7=2\\times 25-7\\times 7=2\\times 25-7\\times(57-2\\times 25)=-7\\times 57+16\\times 25=-7\\times 57+16\\times(82-57)=-23\\times 57+16\\times 82$.\r\nIn fact, this algorithm provides a proof that it always works that for any coprime $p,q$ we have $x,y\\in\\mathbb Z$ with $1=xp+yq$.\r\n\\begin{theorem}\r\n    $\\forall a,b\\in\\mathbb N,\\exists x,y\\in\\mathbb Z,\\operatorname{HCF}(a,b)=xa+yb$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Run the Euclid's Algorithm on $a,b$ to $r_n$.\r\n    We have $r_n$ written as an integral combination of $r_{n-1},r_{n-2}$.\r\n    Then substitute for $r_{n-1}$ to obtain $r_n$ as an integral combination of $r_{n-2},r_{n-3}$.\r\n    Inductively, we can write $\\operatorname{HCF}(a,b)=r_n$ as an integral combination of $a,b$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Euclid is telling us that such $x,y$ exists and how to find them in practice.\r\n\\end{remark}\r\nThere is a second proof to this statement.\r\n\\begin{proof}[Alternative Proof]\r\n    Consider the set $\\{ax+by:x,y\\in\\mathbb Z\\}$, and let $h$ be the least positive integer in this set.\\\\\r\n    We claim that $h$ is the HCF of $a$ and $b$.\r\n    If $d|a$ and $d|b$ then $d|ax+yb\\implies d|h$.\\\\\r\n    Now $h$ must be a common factor of $a,b$.\r\n    Suppose that $h\\nmid a$, then $a=qh+r$ where $q\\in\\mathbb Z, 0<r<h$.\r\n    However, $r$ would be an integral combination of $a,b$, but this contradicts the minimality of $h$.\\\\\r\n    So $h|a$ and similarly $h|b$, so $h$ is an HCF of $a,b$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The alternative proof is abstract, nice, and more concise, but it is non-constructive.\r\n    It does not tell us how to find such an integral combination.\r\n\\end{remark}\r\nOne of the applications of this fact is to solve (linear) Diophantine Equations.\\\\\r\nFix $a,b\\in\\mathbb N$, when can we solve $ax=b,x\\in\\mathbb Z$?\r\nObviously we have an solution if and only if $a|b$ and the solution is $b/a$.\r\nBut how about $2$ variables?\r\nSuppose $a,b,c\\in\\mathbb N$, when can we solve $ax+by=c$ in $\\mathbb Z$?\r\nWe cannot solve $116x+212y=13$ due to parity problems, but we can solve $82x+57y=13$ by multiplying $13$ to the integral combination of $1$ by $82,57$\r\n\\begin{corollary}[Bezout Theorem]\r\n    $ax+by=c$ is solvable in $\\mathbb Z$ if and only if $\\operatorname{HCF}(a,b)|c$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $h$ the HCF of $a,b$.\\\\\r\n    If there is a solution, we have $c=ax+by$ for some $x,y\\in Z$ so $h|ax+by=c$.\r\n    Conversely, if $h|c\\implies c=qh,q\\in\\mathbb N$, since we can write $h=ax+by$ for some $x,y\\in Z$, $c=qh=a(qx)+b(qy)$. \r\n\\end{proof}\r\nWe are now ready to prove\r\n\\begin{proposition}\r\n    Let $p$ be prime, $a,b\\in\\mathbb N$, then $p|ab\\implies p|a\\lor p|b$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Given that $p|ab$, suppose that $p\\nmid a,p\\nmid b$.\r\n    So the HCF of $p,a$ is $1$, therefore $\\exists x,y\\in\\mathbb Z, px+ay=1$.\r\n    Note that here we have produced a positive statement here.\r\n    So $pbx+aby=b$, but since $p|ab,p|pbx+aby=b$, which is a contradiction.\r\n\\end{proof}\r\nThis establishes the statement we have claimed in the preceding section.\r\n\\begin{remark}\r\n    Immediately, if $p|a_1a_2\\ldots a_n$, then $p|a_i$ for some $i$.\r\n\\end{remark}\r\n\\subsection{Fundamental Theorem of Arithmetic}\r\nWhen we have established the theory so far, we are ready to show\r\n\\begin{theorem}[Fundamental Theorem of Arithmetic]\r\n    Any positive integer $n\\ge 2$ can be written as a product of primes uniquely up to reordering.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We already know that any positive integer $n\\ge 2$ can be written as such a product, so the rest is to prove its uniqueness up to reordering.\\\\\r\n    Uniqueness can be proved by (strong) induction on $n$. $n=2$ is obvious.\r\n    Given $n>2$, suppose that\r\n    $$p_1p_2\\cdots p_k=n=q_1q_2\\cdots q_l$$\r\n    where $p_i,q_i$ are primes, we want to show $k=l$ and after reordering $p_i=q_i,\\forall i$.\\\\\r\n    We have $p_1|q_1q_2\\cdots q_l$, so $p_1|q_i$ for some $i$.\r\n    We can reorder such that $q_i\\mapsto q_1$.\r\n    Note that due to primity, $p_1=q_1$, thus\r\n    $$p_2p_3\\cdots p_k=q_2q_3\\cdots q_l$$\r\n    By induction hypothesis, $k-1=l-1\\implies k=l$ and we can reorder such that $p_i=q_i, i\\ge 2$.\r\n    So the theorem is proved. \r\n\\end{proof}\r\nWhat ideas are involved?\r\nWe took the things that cannot be broken up (i.e. primes) and we break everything up into the product of those `unbreakables' (irreducibles).\\\\\r\nHowever, this may not be the case.\r\nDespite the fact that we are used to it, unique factorization really isn't obvious.\r\n\\begin{example}\r\n    Consider the set $\\mathbb Z(\\sqrt{-3})=\\{a+b\\sqrt{-3}:a,b\\in\\mathbb Z\\}$.\\\\\r\n    We can do addition and multiplication in it in the obvious way, and the set is closed under both.\r\n    So we can define `divides' and `factor of' etc.\r\n    One can show that everything can be broken into irreducibles.\r\n    But $4=2\\times 2=(1+\\sqrt{-3})(1-\\sqrt{-3})$, and $2,1\\pm\\sqrt{-3}$ are all irreducibles.\\\\\r\n    Therefore in this funny set, the fundamental theorem of arithmetic doesn't work.\r\n\\end{example}\r\nThere are a few applications of unique factorization.\r\nFirst of all, we want to look into factors.\r\nConsider $n=2^3\\cdot 3^7\\cdot 5\\cdot 11$, we can spot factors of the form $2^a\\cdot 3^b\\cdot 5^c\\cdot 11^d, 0\\le a\\le 3, 0\\le b\\le 7, 0\\le c\\le 1, 0\\le d\\le 1$.\r\nWe do not have others because of unique factorization.\r\nIn general, the factors of $n=p_1^{a_1}\\cdots p_k^{a_k}$ where $p_i$ are distinct primes are of the form $p_1^{b_1}\\cdots p_k^{b_k}$ where $0\\le b_i\\le a_i$.\\\\\r\nAlso, we can find HCF easily.\r\nFor example, the common factors of $2^3\\cdot 3^2\\cdot 5\\cdot 11$, $2^2\\cdot 3^6\\cdot 5\\cdot 11$ are of the form $2^a\\cdot 3^b\\cdot 11^c$ where $0\\le a\\le 2, 0\\le b\\le 2, 0\\le c\\le 1$, so the HCF is $2^2\\times 3^2\\times 11$.\r\nIn general, the HCF of $p_1^{a_1}\\cdots p_k^{a_k}$ and $p_1^{b_1}\\cdots p_k^{b_k}$ is $p_1^{\\min\\{a_1,b_1\\}}\\cdots p_k^{\\min\\{a_k,b_k\\}}$.\\\\\r\nWe can find LCM as well.\r\nThe LCM of the numbers in the last example would be $2^3\\times 3^6\\times 5\\times 7\\times 11$\r\nIn general, the LCM of $p_1^{a_1}\\cdots p_k^{a_k}$ and $p_1^{b_1}\\cdots p_k^{b_k}$ is $p_1^{\\max\\{a_1,b_1\\}}\\cdots p_k^{\\max\\{a_k,b_k\\}}$.\\\\\r\nNote that $\\operatorname{HCF(a,b)}\\times\\operatorname{LCM(a,b)}=a\\times b$.\r\n\\subsection{Modular Arithmetic}\r\n\\begin{definition}\r\n    Let $n\\ge 2$ be a positive integer, then $\\mathbb Z_n$ consists of integers with two of them regarded as the same if their difference is a multiple of $n$.\r\n\\end{definition}\r\nFor example, in $\\mathbb Z_7$, $2$ and $16$ are the same.\\\\\r\nIf $a$ and $b$ are the same in $\\mathbb Z_n$, we write $a\\equiv b\\pmod{n}$.\\\\\r\nIn this world, we only care about the remainder when we divide it by $n$.\r\nIn $\\mathbb Z_n$, $0,1,\\ldots ,n-1$ are distinct and every $k\\in\\mathbb Z_n$ is one of them by division algorithm.\r\nSo we can view $\\mathbb Z_n$ as an $n$-clock.\\\\\r\nWe can do addition and multiplication in $\\mathbb Z_n$.\r\nNote that parity does not make sense in $\\mathbb Z_{2n-1}$.\r\nSo we would have to check that they are well-defined.\r\n\\begin{proposition}\r\n    Suppose $a\\equiv a'\\pmod n,b\\equiv b'\\pmod n$, then $a+b\\equiv a'+b'\\pmod n, ab\\equiv a'b'\\pmod n$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nAll the usual laws of arithmetic applies as $\\mathbb Z_n$ inherited them from $\\mathbb Z$.\\\\\r\nSomething we have done so far can already be expressed in terms of modular arithmetic.\r\nFor example, $ab\\equiv 0\\pmod{p}\\implies a\\equiv 0\\pmod{p}\\lor b\\equiv 0\\pmod{p}$ if $p$ is a prime number.\r\nOr equivalently, there is no zero divisor in $\\mathbb Z_p$.\\\\\r\nThe structure of $\\mathbb Z_n$ under addition is boring enough (just a cyclic group), but how about it under multiplication?\r\n\\begin{definition}\r\n    In $\\mathbb Z_n$, we say $a$ is the inverse of $b$ if $ab\\equiv 1\\pmod{n}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. In $\\mathbb Z_{10}$, $3\\times 7\\equiv 1\\pmod{10}$ so $7$ is the inverse of $3$.\\\\\r\n    2. (non-example) There is no inverse of $4$ in $\\mathbb Z_{10}$ since $4b$ is even for all $b\\in\\mathbb Z$ so we can never have $4b\\equiv 1\\pmod{10}$.\r\n\\end{example}\r\nIf $a$ has an inverse $b$, we write $b=a^{-1}$ given that the $n$ in $\\mathbb Z_n$ is understood.\r\n\\begin{remark}\r\n    1. If inverse exists, it is unique (in $\\mathbb Z_n$).\r\n    Indeed, suppose $ab\\equiv ac\\equiv 1\\pmod{n}$, but then $b\\equiv bab\\equiv bac\\equiv c\\pmod{n}$.\\\\\r\n    2. If $ab\\equiv ac\\pmod{n}$ and $a$ has an inverse, then $b\\equiv c\\pmod n$ by multiplying both sides by $a^{-1}$.\r\n    However, if $a$ does not have an inverse, you cannot really cancel it.\r\n    For example $4\\times 5\\equiv 4\\times 0\\pmod{10}$, but $5\\not\\equiv 0\\pmod{10}$.\r\n\\end{remark}\r\n$\\mathbb Z_n$ is quite nice if $n$ is prime.\r\n\\begin{proposition}\r\n    $\\forall a\\not\\equiv 0\\pmod{p},\\exists b\\in\\mathbb Z_p,ab\\equiv 1\\pmod{p}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We know that $(a,p)=1$, so there are some $x,y\\in\\mathbb Z,ax+py=1\\implies ax\\equiv 1\\pmod{p}$.\r\n    We can take $b=x$.\r\n\\end{proof}\r\n\\begin{proof}[Alternative proof]\r\n    IN $\\mathbb Z_p$, consider $0a,1a,2a,\\ldots,(p-1)a$.\r\n    Our task is to show that one of these equals $1$.\r\n    Note that no two of them are equal, since $ia\\equiv ja\\pmod{p}\\implies (i-j)a\\equiv 0\\pmod{p}\\implies i\\equiv j\\pmod{p}$.\\\\\r\n    Therefore $\\{ka:k\\in\\{0,1,\\ldots,p-1\\}\\}=\\{0,1,\\ldots,p-1\\}$.\r\n    so there is some $b$ such that $ba\\equiv 1\\pmod{p}$.\r\n\\end{proof}\r\nHow about the case in $\\mathbb Z_n$ when $n$ is composite?\r\n\\begin{proposition}\r\n    $\\forall a\\in\\mathbb Z$, there is some $b$ such that $ab\\equiv 1\\pmod{n}$ if and only if $(a,n)=1$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $a$ is invertible, then there is some $b,y\\in\\mathbb Z$ such that $ab+ny=1$, which means that $(a,n)=1$.\\\\\r\n    Conversely, if $(a,n)=1$, then there is some $x,y\\in\\mathbb Z, ax+ny=1\\implies ax\\equiv 1\\pmod{n}$, so we can take $b=x$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The Euler $\\phi$ function is defined by\r\n    $$\\phi(n)=|\\{0<a<n:(a,n)=1\\}|$$\r\n\\end{definition}\r\nEquivalently, $\\phi(n)$ is the number of invertible elements in $\\mathbb Z_n$.\r\n\\begin{example}\r\n    1. $\\phi(p)=p-1$ for any prime $p$.\\\\\r\n    2. $\\phi(p^2)=p^2-p=p(p-1)$ for any prime $p$.\\\\\r\n    3. $\\phi(pq)=pq-p-q+1=(p-1)(q-1)=\\phi(p)\\phi(q)$ for any distinct primes $p,q$.\\\\\r\n    4. $\\phi(p^n)=p^n-p^{n-1}=p^{n-1}(p-1)$ for any prime $p$ and positive integer $n$.\r\n\\end{example}\r\nWe now introduce the order of an element by a few observations:\r\nIn $\\mathbb Z_7$, $2^1\\equiv 2, 2^2\\equiv 4, 2^3\\equiv 1$ and things go around again.\r\nIn $\\mathbb Z_{11}$, $2^1\\equiv 2, 2^2\\equiv 4, 2^3\\equiv 8, 2^4\\equiv 5, 2^5\\equiv 10, \\ldots, 2^{10}\\equiv 1\\pmod 11$ and things repeat.\r\n\\begin{theorem}[Fermat's Little Theorem (F$\\ell$T)]\r\n    Let $p$ be a prime, then in $\\mathbb Z_p$, every $a\\not\\equiv 0$ has $a^{p-1}\\equiv 1$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Note that $\\{ka:k\\in\\{1,\\ldots,p-1\\}\\}=\\{1,\\ldots,p-1\\}$.\\\\\r\n    So we have\r\n    $$\\prod_{k=1}^{p-1}ak\\equiv\\prod_{k=1}^{p-1}k\\pmod{p}\\implies (a^{p-1}-1)(p-1)!\\equiv 0\\pmod{p}$$\r\n    Now $(p-1)!\\neq 0\\pmod{p}$ since all the terms in the product is invertible.\r\n    Therefore the theorem.\r\n\\end{proof}\r\nFor composite $n$, we have a similar proposition.\r\n\\begin{theorem}[Fermat-Euler Theorem]\r\n    Let $n\\ge 2$ be a positive integer, then in $\\mathbb Z_n$, every invertible $a$ has $a^{\\phi(n)}\\equiv 1$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Note that $\\{ka:0<k<n,(k,n)=1\\}=\\{k:0<k<n,(k,n)=1\\}$.\r\n    Since $a$ is invertible, we have $ia\\equiv ja\\pmod{n}\\implies i\\equiv j\\pmod{n}$\\\\\r\n    So we have\r\n    \\begin{align*}\r\n        \\prod_{0<k<n,(k,n)=1}ak\\equiv\\prod_{0<k<n,(k,n)=1}k\\pmod{n}\\\\\r\n        \\implies(a^{\\phi(n)}-1)\\prod_{0<k<n,(k,n)=1}k\\equiv 0\\pmod{n}\r\n    \\end{align*}\r\n    Now $\\prod_{0<k<n,(k,n)=1}k\\neq 0\\pmod{n}$ since all the terms in the product is invertible.\r\n    Therefore $a^{\\phi(n)}\\equiv 1\\pmod{n}$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $p$ be prime, then in $\\mathbb Z_p$, the solutions to $x^2\\equiv 1\\pmod{p}$ are $x=\\pm 1$.\r\n\\end{lemma}\r\nNote that it is not true when $p$ is not prime.\r\nFor example, $1^2\\equiv 3^2\\equiv 5^2\\equiv 7^2\\equiv 1$.\r\n\\begin{proof}\r\n    $x^2\\equiv 1\\pmod{p}\\iff (x-1)(x+1)\\equiv 0\\pmod{p}\\iff x\\equiv\\pm 1\\pmod{p}$ since $p$ is prime.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Any nonzero polynomial of degree $d$ in $\\mathbb Z_p$ has at most $d$ solutions.\r\n\\end{remark}\r\nNote that in the proof of F$\\ell$T, there is the expression $(p-1)!$.\r\nIt looks like as if it is some interesting thing.\r\nNote that $(3-1)!\\equiv -1\\pmod{3},(5-1)!\\equiv -1\\pmod{5},(7-1)!\\equiv -1\\pmod{7}$.\r\nSo it is natural to state the following, which is in fact true:\r\n\\begin{theorem}[Wilson's Theorem]\r\n    Let $p$ be a prime, then $(p-1)!\\equiv -1\\pmod{p}$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    When $p=2$ it is trivial, so we assume henceforth that $p>2$.\\\\\r\n    Note that all of $1,2,\\ldots ,p-1$ are invertible.\r\n    So we can pair up the elements with their inverses, and they have a product $1$.\r\n    We have the pairs as long as we do not have $x^2\\equiv 1\\pmod{p}\\implies x\\equiv 1\\lor x\\equiv p-1\\pmod{p}$.\r\n    Hence $(p-1)!\\equiv 1(p-1)\\equiv -1\\pmod{p}$.\r\n\\end{proof}\r\nWhen is $-1$ a square modulo $p$?\r\nIs there $x\\in\\mathbb Z$ with $x^2\\equiv -1\\pmod{p}$?\r\n\\begin{example}\r\n    When $p=5$, we notice that $2^2\\equiv -1\\pmod{5}$\r\n    When $p=7$, by trying, we know that such $x$ does not exist.\r\n    When $p=13$, $5^2=25\\equiv -1\\pmod{13}$.\r\n    when $p=19$, by trying, we know that such $x$ does not exist.\r\n\\end{example}\r\nBy looking at the pattern, we can try to prove the following theorem\r\n\\begin{theorem}\r\n    For a prime number $p>2$, then $x^2\\equiv -1\\pmod{p}$ is solvable if and only if $p\\equiv 1\\pmod{4}$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    If $p=4k+3$ for some $k\\in\\mathbb N$ but $x^2\\equiv -1\\pmod{p}$ for some $x\\in\\mathbb Z$.\r\n    But we also have $-1\\equiv (x^2)^{2k+1}=x^{4k+2}=x^{p-1}\\equiv 1\\pmod{p}$, which is a contradiction.\\\\\r\n    Conversely, if $p=4k+1$, Wilson's theorem tells us that $(4k)!\\equiv -1\\pmod{p}$.\r\n    Note that $4k-r\\equiv -r-1\\pmod{p}$, therefore $((2k)!)^2=((2k)!)^2(-1)^{2k}\\equiv (4k)!\\equiv -1\\pmod{p}$.\r\n\\end{proof}\r\nNow we go back solving linear congruences.\r\n\\begin{example}\r\n    If we want to solve $7x\\equiv 4\\pmod{30}$.\r\n    Firstly we can find $7\\cdot 13\\equiv 1\\pmod{30}$, we knew we can do this since $(7,30)=1$.\r\n    So $7x\\equiv 4\\pmod{30}\\iff 13\\cdot 7x\\equiv 13\\cdot 4\\pmod{30}\\iff x\\equiv 22\\pmod{30}$.\r\n\\end{example}\r\n\\begin{example}\r\n    Solve $10x\\equiv 12\\pmod{34}$.\r\n    Note that in this case $(10,34)\\neq 1$ so we cannot do the same thing again.\r\n    However, we can throw it back to $\\mathbb Z$, so $10x\\equiv 12\\pmod{34}\\iff\\exists y\\in\\mathbb Z, 10x=12+34y\\iff\\exists y\\in\\mathbb Z,5x=6+17y\\iff 5x\\equiv 6\\pmod{17}$.\r\n    So from here on we can do the same thing again.\r\n    $5x\\equiv 6\\pmod{17}\\iff x\\equiv 7\\times 6\\equiv 8\\pmod{17}$.\r\n\\end{example}\r\nNow we want to try simultaneous ones.\r\n\\begin{example}\r\n    \\[\r\n        \\begin{cases}\r\n            x\\equiv 3\\pmod{17}\\\\\r\n            x\\equiv 5\\pmod{19}\r\n        \\end{cases}\r\n    \\]\r\n    Can we solve it?\r\n    We would expect the answer being yes, since modulo $17,19$ should not ``intervene each other'' since $(17,19)=1$.\r\n    That is not a proof, but that is our intuition.\r\n\\end{example}\r\n\\begin{example}\r\n    \\[\r\n        \\begin{cases}\r\n            x\\equiv 5\\pmod{30}\\\\\r\n            x\\equiv 8\\pmod{34}\r\n        \\end{cases}\r\n    \\]\r\n    It then becomes immediate that this is not solvable due to parity problem.\r\n    What has gone wrong looks like that two modulos are related as $(30,34)=2$.\r\n\\end{example}\r\n\\begin{theorem}[Chinese Remainder Theorem]\r\n    The system of linear equations\r\n    \\[\r\n        \\begin{cases}\r\n            x\\equiv a\\pmod{u}\\\\\r\n            x\\equiv b\\pmod{v}\r\n        \\end{cases}\r\n    \\]\r\n    is solvable if $(u,v)=1$.\r\n    Moreover, the solution is unique modulo $uv$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Existence: Since they are coprime, we have $su+tv=1$ for some $s,t\\in\\mathbb Z$, then $x=bsu+atv$ solves the system.\\\\\r\n    Uniqueness: If $x,x'$ are solutions, then $x-x'\\equiv 0\\pmod{u}$ and $x-x'\\pmod{v}$, hence $x-x'\\equiv 0\\pmod{uv}$.\r\n    Conversely it is obvious that if $x\\equiv x'\\pmod{uv}$, then if $x$ is a solution so is $x'$.\r\n\\end{proof}\r\nThe exact same thing would work if you have more than $2$ equations in the system modulo pairwisely coprime numbers.\r\nThis can be proved by CRT and induction.\r\n\\subsection{Application of number theory}\r\nThe RSA code is an example of an application of the Fermat-Euler theorem.\r\nConsider the following scenario: we want to send an encoded message to the receiver who is supposed to have a way to decode it.\\\\\r\nIt seems ``obvious'' that knowing how to decode equals knowing how to encode.\r\nHowever, there is a way such that even if you know how to encode, it is still ``very hard'' to decode.\r\nThat is, the process of finding an inverse function will takes a long period of time for the message to expire.\\\\\r\nWe encode in the following way:\r\nPick two large primes $p,q$, say a hundred digits each and take their product.\r\nA message is just a sequence of digits, so we can decompose it into not-so-long blocks such that the number represented by each block is less than both of the primes.\r\nSay one of these blocks is $x$, and we take an exponent $e\\ge 2$ such that $(e,\\phi(pq))=1$, and the encoding message would be the smallest positive integer with $x^e\\equiv m\\pmod{pq}$\r\nSo to decode, we can find some $d$ with $de\\equiv 1\\pmod{\\phi(pq)}$, so $m^d\\equiv x\\pmod{pq}$ by Fermat-Euler.\r\nThis is the way to decode the message, so we just need to find such $d$, which is easy and fast by Euclid given that we do know $\\phi(pq)$.\\\\\r\nNow we only need to know $pq$ and $e$ to encode, and we need to know $d$ (or $e$ and $\\phi(pq)=(p-1)(q-1)$, since we can run Euclid) and $pq$ to decode.\r\nObserve here that if the decoder only know all eise information but $\\phi(pq)$ explicitly, he will have to factorize $pq$.\r\nThus, we can publish $pq$ and $e$, then anyone else can send a message to us, however, since only us know $d$, no one else can decode the message quickly since they will have to run a slow algorithm to try factorizing $pq$.", "meta": {"hexsha": "c1c0bd16fbb5b7dabe5e663f6f14075c3c1f28cd", "size": 23191, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/nt.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": "3/nt.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": "3/nt.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": 54.695754717, "max_line_length": 224, "alphanum_fraction": 0.653184425, "num_tokens": 8278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6446899206434056}}
{"text": "[missed first half]\n\\section{Cylinder-plane conformal mapping}\nConsider the mapping $w\\to z$ defined by\n\\begin{align}\n    w &= \\ln\\frac{z + a}{z - a}\n\\end{align}\n\nLet $w=u + iv$ and $z = x + iy$.\nWe want to answer these two questions:\n(a) What region of the $z$-plane corresponds to the region bewteen\n$u=0$ and $u=u_0$?\n\n(b) what region of the $z$-plane corresponds to the region of the $w$-plane\nbetween $v=0$ and $v=v_0$,\nwhere $v_0$ is a constant that lies between $0$ and $\\pi$.\n\n(a)\n\\begin{align}\n    w &= u + iv = \\ln \\frac{z + a}{z - a}\n\\end{align}\nwhere $z = x + iy$.\nSo\n\\begin{align}\n    e^{w} &= \\frac{z + a}{z - a}\n\\end{align}\nand the modulus is\n\\begin{align}\n    \\left| e^{u} e^{iv} \\right|\n    &=\n    \\left|\n        \\frac{(x + a) + iy}{(x - a) + iy}\n    \\right|\n\\end{align}\nand so\n\\begin{align}\n    e^{2 u} &=\n    \\frac{(x + a)^2 + y^2}{(x - a)^2 + y^2}\n\\end{align}\n\nFor $u=0$, $e^{2 u} = 1$.\n\\begin{align}\n    (x + a)^2 + y^2 &=\n\\end{align}\n\n\n[missed some lines]\n\nFor $u=u_0$,\n$e^{2 u_0} =: C^2$,\nwe have\n$C^2 > 1$ for $u_0 > 0$.\nAlong $v=u_0$,\n\\begin{align}\n    C^2\\left[\n        (x - a)^2 + y^2\n    \\right] &=\n    (x + a)^2 + y^2\n\\end{align}\nand after some algebra you can find in the notes,\nyou find that\n\\begin{align}\n    x^2 + y^2 + a^2 *=\n    \\underbrace{\\left(\\frac{c^2 + 1}{c^2 - 1}\\right)}_{\\lambda} 2ax\n\\end{align}\nSo call that thing $\\lambda$ becuase it's the only place where $C^2$ appears.\n\\begin{align}\n    \\lambda &:= \\frac{c^2 + 1}{c^2 - 1}\n\\end{align}\nIt's possible to rewrite the equation\n\\begin{align}\n    (x - a\\lambda)^2 + y^2 = a^2 (\\lambda^2 - 1)\n\\end{align}\nand you can convince yourself that $\\lambda > 1$.\nBecause $C^2$ is a positive number bigger than 1,\nso $C^2 - 1$ is a positive number,\nand $C^2 + 1$ is a bigger positive number,\nso $\\lambda > 1$.\nThis equation here is an equation of a circle\ncentred at $(a\\lambda, 0)$.\nSo the centre of the circle is at $x=a\\lambda$.\nSo it's on the $x$-axis.\nThe radius of the circle is\n$R= a\\sqrt{\\lambda^2 - 1}$.\n\nLet me continue for a couple more minutes.\nHere's what we're finding.\n\nWe started with 2 straight lines in the $u-v$ plane.\n$u=u_0$ and $u=u_0$.\nThose are 2 straight lines.\nThe $u=0$ line maps to the $y$-axis\nand the $u=u_0$ line maps to a circle with centre sitting on the $x$ axis.\nThe region between $u=0$ and $u=u_0$ is mapped into the region between the\n$y$-axis and the circle.\n\nSo let's draw that.\n\n[picture here]\n\nThis is a fairly standard map.\nWe don't have enough time in the class to go thorugh all the standard maps.\nIf you're familiar with all the standard maps you can go very ar.\nIt's just like how in integration we hvae standar contours.\nThat's why it's important I did almost all of the standard contours.\n\nMaybe 30 to 40 years ago,\nconformal mapping was improtant,\nbut these days we can solve things using more powerful computers and this is\nbecoming less important.\n30 years ago,\na big chunk of the course would have been dedicated to conformal mapping\njust like how I did contour integrals in the course.\n\n\\begin{question}\n    At the bottom of the $y$-axis is $u=0$?\n\\end{question}\nThe entire $y$-axis is mapped from the line $u=0$.\nSorry about my handwriting.\nThis whole line is $u=0$.\n\nAny other questions?\n\n(b)\nLet's do problem b now.\nSo we start with what we had before\n\\begin{align}\n    e^{u}e^{iv}\n    &=\n    \\frac{(x + a) _+ iy}{(x - a) + iy}\n    &=\n    \\frac{(x^2 + y^2 - a^2) - 2 i ay}{(x - a)^2 + y^2}\n\\end{align}\nand then skipping a few steps you can find in the notes,\nyou get\n\\begin{align}\n    e^{iv} &=\n    e^{-u}\\left\\{\n        \\frac{(x^2 + y^2 - a^2) - 2 iay}{(x - a)^2 + y^2}\n    \\right\\}\n\\end{align}\nBut from the previous problem, we know\n\\begin{align}\n    e^{-u} &= \\cdots\n\\end{align}\nand with a little bit of algebra gain which I'm not going to show you,\nyou get\n\\begin{align}\n    e^{iv} &=\n    \\frac{(x^2 + y^2 - a^2) - 2iay}{\\sqrt{\n        [(x - a)^2 + y^2]\n        [(x + a)^2 + y^2]\n    }}\n\\end{align}\nSo now we have a direct relation between $v$ and $x,y$.\nBut you can see this is a messy expression.\nNot straightforward to handle,\nbut let's see how to make progress.\n\nSo then let me notice that\n\\begin{align}\n    \\tan v &=\n    \\frac{-2ay}{x^2 + y^2 - a^2}\n\\end{align}\nand if $v$ is a constant, then $\\tan v$ is also a constant.\nFor reasons that will be clear in a moment,\nlet me also write\n\\begin{align}\n    \\sin v &=\n    \\frac{-2ay}{\\sqrt{\n        [(x - a)^2 + y^2]\n        [(x + a)^2 + y^2]\n    }}\n\\end{align}\nSo why am I writing both tan and sin?\nIt's because the tan is not unique,\nit's the same for both $v$ and $v+\\pi$.\nIf I tell you the tanget and the sign,\nthen I specify $v$ uniquely.\nIf I only specify $\\tan v$,\nthere is a degeneracy and it's not clear what $v$ is.\n\nLet's go back to the quesiton.\nFor $v=0$, $\\tan v =0 $ and $y=0$.\nSo $v=0$ maps onto the $x$ axis.\n\nLet $\\tan v_0 = k$ be a constant.\nThen\n\\begin{align}\n    \\frac{-2ay}{x^2 + y^2 - a^2} = k\n\\end{align}\nWith some algebra I'm skipping,\nif you do it,\nyou can rewrite this as\n\\begin{align}\n    x^2 = \\left( y + \\frac{a}{k} \\right)^2\n    &=\n    a^2 \\left( 1 + \\frac{1}{k^2} \\right)\n\\end{align}\nand this is the circle centred at\n$\\left( 0, \\frac{-a}{k} \\right)$\nwith readius\n$a\\sqrt{1 + \\frac{1}{k^2}}$.\n\nAlright,\nso let's draw it.\nThis is the $x$-axis and this is the $y$-axis.\nLet's draw a circle.\nThis is the centre of the circle.\nI've drawn part of the circle dotted.\nWell you're wondering this is the equatino for the full circle,\nbut why have I drawn part of it solid and part of it dotted.\nWell here's why.\nRemember what I did was set $\\tan v = k$.\nThat's how I got a circle.\nBut remember $\\tan v$ is the same for both $v$ and $v+\\pi$.\nI'm going to argue that the dotted part corresponds to $v+\\pi$,\nand the solid part is the circle that maps to what we want.\nIt's actually quite tricky.\n\n[picture here]\n\nRecall the the denominator of the $\\sin v$ expression is positive.\nBut how we were asked to look at the problem for $0\\le v_0< \\pi$.\nSo if $v < \\pi$, then $\\sin v$ > 0 and $y <0$,\nso only the portion of the circle below the $y=0$ $x$-axis is what we want.\nThe part of the circle above the $x$-axis corresponds to when\n$\\sin v < 0$.\nLet me write a couple of things and then I can ask questions.\n\nSince we restricted $0< v_0 < \\pi$,\n$\\sin v_0 > 0$.\nThen only the part of the circle with $y<0$\ncorresponds to $v_0$.\n\nNow you can convince yourself that the circle crosses the $x$-axis at\n$x=-a$,\nwhich maps to $u-\\infty$,\nand at $x=a$,\nwhich maps to $u=+\\infty$.\nThe lowest point of the circle,\nwhich is at $x=0$,\ncorresponds to $u=0$.\n\nSo as you change $u$ holding $v$ fixed,\nyou trace out an arc.\nConvince yourself that this is true.\n\nAre there any questions about this?\n\nWe have a grand total of 5 minutes to solve this part C.\nAlright.\n\n(c) Consider the geometry below in the $w$-plane.\nYou have two infinite plates,\none at $u=0$ and one at $u=u_0$.\nAnd this is the line $v=0$.\nThis is the direction of increasing $v$.\nNow we're going to set this $u=0$ plane to potential\n$V=0$\nand this other plate to potential\n$V=V_0$.\n\nThe solution for region between the two plates is\n\\begin{align}\n    V &= V_0\\left\\{\n        \\frac{u}{u_0}\n    \\right\\}\n\\end{align}\nAnd remember this mapping maps from plane to cylinder.\nWe already showed that.\n\nThis maps into the geometry below,\na plane at $x=0$\nand cylinder at $(\\lambda a, 0)$\nwith radius $a\\sqrt{\\lambda^2 - 1}$.\nBut you remember in the formulation of the question,\nthe cylinder is centred distance $d$ from the plane\nand has radius $R$.\nSo we equate\n\\begin{align}\n    d &= a \\lambda\\\\\n    R &= a\\sqrt{\\lambda^2 - 1}\n\\end{align}\nSo then after some algebra I have in the notes,\nyou find that\n\\begin{align}\n    a &=\n    R \\sqrt{\\frac{d^2}{R^2} - 1}\\\\\n    \\lambda &=\n    \\frac{d/R}{\\sqrt{\\frac{d^2}{R^2} - 1}}\n\\end{align}\nTo solve the problem,\nall we have to do is rewrite $V=V_0 u/u_0$,\nrewriting $u$ in terms of $x$ and $y$.\nBut we know what that is because we have this thing from (a),\nand here's what you end up with\n\\begin{align}\n    V &= \\frac{V_0}{u_0} \\frac{1}{2}\n    \\log\\left\\{\n        \\frac{(x + a)^2 + y^2}{(x - a)^2 + y^2}\n    \\right\\}\n\\end{align}\nand we have to rewrite $u_0$ and $a$ in terms of\n$d$ and $R$ using the expressions above.\nIt's given in the notes.\nThis is the solution\nand we just have to rewrite the constants in terms of $d$ and $R$.\nYou can find the closed-form expression in the notes.\nYou can check by direct substitution into Laplace's euqation,\nand you find that it satisfied Laplace's equation and also\nthat it satisfies the boundary conditions.\n\nLet me stop here.\nI know that was rather quick.\n\nThe equations are all in the notes,\nbut the only thing not in the notes are the explanations,\nwhich I give in the lectures but are too long to write out.\nLet me end the lecture here and stop the recording.\nSee you Thursday.\n", "meta": {"hexsha": "89870f063aa3cc03ead264df48f5edeaeef6e3b3", "size": 8821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture9.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/lecture9.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/lecture9.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.4797507788, "max_line_length": 77, "alphanum_fraction": 0.6535540188, "num_tokens": 2982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6446899170479773}}
{"text": "%\\paragraph{Notations}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{table}[t]\n\t\\centering\n\t\\begin{footnotesize}\n\t\\begin{tabular}{ll}\\\\\n\\toprule\n\t\t{\\bf Symbol}  & {\\bf Meaning}\\\\\n\\midrule\n$\\intint{H}$  & set of integers from $1$ to $H$\\\\\n$\\|\\cdot\\|$ & $L_2$-norm\\\\\n$\\|\\cdot\\|_F$ &    Frobenius norm  \\\\\n$\\|\\cdot\\|_0$ & $L_0$-norm\\\\\n$\\|\\cdot\\|_2$    &    spectral norm  \\\\\n$\\rmD_\\rvv$ & diagonal matrix with vector $\\rvv$ on the diagonal\\\\                                                \n% $N$           & number of data points\\\\\n$D$           & data dimension\\\\\n$H$           & number of layers in a network\\\\\n$Q$           & number of sparse factors\\\\\n$\\mathcal{X}_i$ & input space of $f_{i+1}$ and output space of $f_{i}$\\\\\n$\\rvx_1,\\ldots, \\rvx_N $        &    data points\\\\\n$\\rmX \\in\\mathbb{R}^{N\\times D}$&    data matrix\\\\\n$\\rmS_1, \\ldots, \\rmS_Q$        &    sparse matrices\\\\\n$\\mathcal{E}_1, \\ldots, \\mathcal{E}_Q$ & sparsity constraint sets\\\\\n$\\delta_{\\mathcal{E}}$ & \t\tindicator functions for set $\\mathcal{E}$\\\\\n$\\floor{\\rvx}$ & round $\\rvx$ to the flooring integer\\\\\n% $\\tau$  & current iteration \\\\\n\\bottomrule\n\t\\end{tabular}\n\t\\end{footnotesize}\n\t\\caption{Notation used in this paper.}\n\t\\label{tab:notation}\n\\end{table}\n%\\begin{table}[t]\n%\t\\centering\n%\t\\begin{footnotesize}\n%\t\\begin{tabular}{cllcl}\\\\\n%\t\t\\cline{1-2}\\cline{4-5}\\vspace*{1mm}\n%\t\t{\\bf Symbol}  & {\\bf Meaning}                      &  &    {\\bf Symbol}          & {\\bf Meaning}                    \\\\ \t\t\\cline{1-2}\\cline{4-5}\n%\t\t$N$           & number of data points              &  &    $\\rvx_1,\\ldots, \\rvx_N $        &    data points            \\\\\n%\t\t$D$           & data dimension &  &    $\\rmX \\in\\mathbb{R}^{N\\times D}$&    data matrix            \\\\\n%\t\t$K$           & number of clusters                 &  &    $\\rvu_1,\\ldots, \\rvu_K $        &    \\kmeans centroids        \\\\\n%\t\t$\\rvt$        &  cluster assignment vector           &  &    $\\rmU\\in\\mathbb{R}^{K\\times D}$ &    \\kmeans centroid matrix  \\\\\n%\t\t&                 &  &    $\\rvv_1,\\ldots, \\rvv_K $        &    \\qkmeans centroids        \\\\\n%\t\t&          &  &    $\\rmV\\in\\mathbb{R}^{K\\times D}$ &    \\qkmeans centroid matrix  \\\\\n%\t\t$Q$           & number of sparse factors    &  &    $\\rmS_1, \\ldots, \\rmS_Q$        &    sparse matrices        \\\\\n%\t\t$\\|\\cdot\\|$, & $L_2$-norm&  &    $\\|\\cdot\\|_F$, &    Frobenius norm  \\\\\n%\t\t$\\|\\cdot\\|_0$ & $L_0$-norm&  &    $\\|\\cdot\\|_2$    &    spectral norm  \\\\\n%\t\t$\\mathcal{E}_1, \\ldots, \\mathcal{E}_Q$ & sparsity constraint sets           &  & $\\delta_{\\mathcal{E}}$ & \t\tindicator functions for set $\\mathcal{E}$\\\\\n%\t\t$\\intint{M}$  & set of integers from $1$ to $M$ &  & $\\tau$  &                       \t\tcurrent iteration  \\\\\n%\t\t\n%\t\t$\\rmD_\\rvv$ & diagonal matrix with vector $\\rvv$ on the diagonal\\\\                                                          \t\t\\cline{1-2}\\cline{4-5}        \\\\      \n%\t\\end{tabular}\n%\t\\end{footnotesize}\n%\t\\caption{Notation used in this paper.}\n%\t\\label{tab:notation}\n%\\end{table}\n%\\addtocounter{footnote}{0}\n%\\footnotetext{We also use the standard notations such as $\\mathbb{R}^n$ and $\\mathbb{M}_n$.}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\\begin{table}[t]\n%\t\\centering\n%\t\\begin{tabular}{|r|c|l|}\n%\t\t\\hline\n%\t\tindices &  $i$, $j$, $m$, $n$, $p$, $q$ &  small  Latin characters  \\\\\n%\t\tother integers &  $K$, $Q$, $N$, $\\ldots$ &  capital  Latin characters \\\\\n%\t%\tvector spaces\\footnotemark & $\\mathcal{X}$, $\\mathcal{Y}$, $\\mathcal{H}$, $\\ldots$ & Calligraphic letters \\\\ \n%\t\tvectors (or functions) & $\\rvx$, $\\rvt$, $\\rvk$, $\\ldots$ & small bold Latin characters \\\\\n%\t\tmatrices  & $\\rmX$, $\\rmU$, $\\rmK$, $\\ldots$ & capital bold Latin characters \\\\\n%\t\ttranspose & $\\top$ & $\\rmX^\\top$ transpose of  $\\rmX$ \\\\\n%\t\t\\hline\n%\t\\end{tabular}\n%\t\\caption{Notations used in this paper.}\n%\t\\label{tab:notation}\n%\\end{table}\n%\\addtocounter{footnote}{0}\n%\\footnotetext{We also use the standard notations such as $\\mathbb{R}^n$ and $\\mathbb{M}_n$.}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n%The notations frequently used in the paper are summarized in Table~\\ref{tab:notation}. \n%%\n%Throughout the paper we use $\\nexamples$ as the number of data samples and $\\datadim$ the dimensionality of a data point. \n%$\\rmX \\in \\R^{\\nexamples \\times \\datadim}$ is the data matrix. \n%For $K \\in \\sN$, we define $\\intint{K}=\\left \\lbrace k\\in \\sN: 1 \\leq k \\leq K\\right \\rbrace$.\n%%\n%For a given vector $\\rvv$, $\\rvv[i]$ is the $i$th component of $\\rvv$.\n%%\n%For a given matrix $\\rmM$, the notation $\\rmM_{[i]}$ (resp. $\\rmM^{[i]}$) refers to the $i$th row (column) of $\\rmM$, the entry at the $i$th row and the $j$th column is denoted by $\\rmM[i,j]$, and $\\|\\rmM\\|_F$ denotes the Frobenius norm, $\\|\\rmM\\|_2$ the spectral norm and $\\|\\rmM\\|_0$ counts the number of non-zero entries in $\\rmM$. \\addHK{other norms?}\n%\n%\n%\n%\n%\\todo[inline]{The text is redundant with the table. In addition, we should remove the \"small Latin character0\", \"capital Latin characters\" as they do not provide any meaning. We should prefer the trick with the transpose.}\n", "meta": {"hexsha": "b77a71379d0352e0800529ab5ae96ce9d1392a47", "size": 5168, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/techreport/notations.tex", "max_stars_repo_name": "lucgiffon/psm-nets", "max_stars_repo_head_hexsha": "dec43c26281febf6e5c8b8f42bfb78098ae7101d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-15T07:05:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T07:05:18.000Z", "max_issues_repo_path": "reports/techreport/notations.tex", "max_issues_repo_name": "lucgiffon/psm-nets", "max_issues_repo_head_hexsha": "dec43c26281febf6e5c8b8f42bfb78098ae7101d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-15T06:12:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-16T10:05:36.000Z", "max_forks_repo_path": "reports/techreport/notations.tex", "max_forks_repo_name": "lucgiffon/psm-nets", "max_forks_repo_head_hexsha": "dec43c26281febf6e5c8b8f42bfb78098ae7101d", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 356, "alphanum_fraction": 0.5325077399, "num_tokens": 1760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6446899126931888}}
{"text": "\\documentclass{article}\n\\usepackage{mathrsfs}\n\\usepackage{amsmath}\n\\usepackage{mathtools}\n\\usepackage{graphicx}\n\\usepackage{amsfonts}\n\\DeclarePairedDelimiter{\\ceil}{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter{\\floor}{\\lfloor}{\\rfloor}\n\n\\begin{document}\n\\begin{center}\n\\textbf{\\huge{Week 9}}\n\\end{center}\n\n\\section{Lemma}\nIf $\\mathscr{C}$ is a linear code, then\n$$ d_{min}(\\mathscr{C})= \\text{min}_{\\underbar{c} \\neq 0}w_H (\\underbar{c})$$\nwhere, Hamming weight, $w_H(\\underbar{c})=$ number of non zero positions in $\\underbar{c}$.\n\\\\ \\\\\nProof:\n\nBy definition,\n\n    \\begin{align*}\n        d_{min}(\\mathscr{C})&=\\text{min} (d_H(\\underbar{c}_1, \\underbar{c}_2)) \\qquad \\underbar{c}_1, \\underbar{c}_2 \\in \\mathscr{C} ; \\underbar{c}_1 \\neq \\underbar{c}_2 \\\\\n        \\text{min} (d_H(\\underbar{c}_1, \\underbar{c}_2))& = \\text{min} (w_H(\\underbar{c}_1 - \\underbar{c}_2) \\qquad \\underbar{c}_1, \\underbar{c}_2 \\in \\mathscr{C} ; \\underbar{c}_1 \\neq \\underbar{c}_2 \\\\\n        &= \\text{min}(w_H(\\underbar{c})) \\qquad\\qquad    \\underbar{c}\\neq 0 ; \\underbar{c} \\in \\mathscr{C}\n    \\end{align*}\n    Hence proved.\n\n\\section{Examples}\nWe know that every subspace of a vector space has a basis, i.e a set of linearly independent vectors from the subspace which span the subspace.\n\\\\\n\\begin{enumerate}\n    \\item Suppose $\\mathscr{C}= \\mathbb{F}_2^n$,\n    \\begin{itemize}\n        \\item Then any set of n linearly independent vectors from $\\mathbb{F}_2^n$ will be a basis of $\\mathscr{C}$.\n        \\item In particular we can choose the standard basis, $\\underbar{c}_1= (1,0,\\cdots,0),\\underbar{c}_2= (0,1,0,\\cdots,0),\\cdots, \\underbar{c}_n=(0,\\cdots,0,1)$\n    \\end{itemize}\n    \\item Suppose $\\mathscr{C}= \\{ (0, \\cdots,0), (1,\\cdots,1)\\}$\n    \\begin{itemize}\n        \\item As this code is closed under addition, this is a valid linear code.\n        \\item The basis for $\\mathscr{C}$ will be $\\{ (1,\\cdots,1)\\}$.\n        \\item This code encodes 1 bit.\n    \\end{itemize}\n    \\item Suppose $B= \\{ g_1,\\cdots, g_k \\}$, $k<n$ are a set of linearly independent vectors in $\\mathbb{F}_2^n$. What is linear code $\\mathscr{C}$ for which B is a basis?\n    \\begin{itemize}\n        \\item Set of all linear combinations of vectors in B, i.e. $$ \\mathscr{C}= \\text{span}(B) = \\left\\{ \\sum_{i=1}^{k} \\alpha_i g_i: \\alpha_i \\in \\mathbb{F}_2 \\right\\}$$\n        \\item $ |\\mathscr{C}|= 2^k$, k is called the dimension of the subspace.\n\n         Hence, $k= \\log_2 |\\mathscr{C}| $.\n         \\item Rate of  the code $= k/n $.\n         \\item This code encodes $k$ bits.\n         \\item Encoding is a linear operator, hence implementation is simple. $$ ( \\alpha_1 , \\alpha_2, \\cdots, \\alpha_k ) \\xrightarrow{\\text{encoded}} \\sum_{i=1}^{k} \\alpha_i g_i$$\n         $$ ( \\alpha_1 , \\alpha_2, \\cdots, \\alpha_k ) \\xrightarrow{\\text{linear}} ( \\alpha_1 , \\alpha_2, \\cdots, \\alpha_k )_{1\\times k} G_{k \\times n}$$\n         where,\n         $ G_{k \\times n}=\n\\begin{pmatrix}\n  g_1 \\\\\n  g_2 \\\\\n  \\vdots \\\\\n  g_k \\\\\n\\end{pmatrix}$\n    \\end{itemize}\n\n\\end{enumerate}\n\n\\subsection{Generator matrix}\n\nPick any collection of $k$ linearly independent from $\\mathbb{F}_2^n$ $\\{ g_1,\\cdots, g_k\\}$.\n\n\n$ G_{k \\times n}=\n\\begin{pmatrix}\ng_1 \\\\\ng_2 \\\\\n\\vdots \\\\\ng_k \\\\\n\\end{pmatrix}$\n\\\\\n\\\\\nRowspace(G) = span(rows of G) = k dimensional subspace of $\\mathbb{F}_2^n$\n\n$$ d_{min}(\\mathscr{C})= \\text{min}_{\\underbar{c} \\neq 0}w_H (\\underbar{c})$$\n\nEncoding is the operation of mapping $2^nR$ length messages to the n-length codewords in a unique manner. It is the mapping from k-length vectors over $\\mathbb{F}_2$ to $\\mathscr{C}$.\n\nFor linear codes, we can do this encoding as a linear mapping.\nEncoding operation for linear codes requires polynomial in n, unlike non-linear codes require exponential complexity.\n\n\\subsection{Example}\n\n\\begin{itemize}\n    \\item Repetition code (eg. 2):\n    $$ G=   [1,1,\\cdots,1]_{1 \\times n}$$\n    $$ \\text{Rowspace}(G)= \\{ (0,0,\\cdots,0),(1,1,\\cdots,1)\\}$$\n    $$ d_{min}(\\mathscr{C})= n \\qquad dim(\\mathscr{C})=1 \\qquad R= \\frac{k}{n}= \\frac{1}{n}$$\n\n    How can we implement minimum distance decoding more efficiently?\n    $$ \\hat{\\underbar{c}}= argmin_{\\underbar{c} \\in \\mathscr{C}} d_H(y,\\underbar{c})$$\n    For n=5:\n    Suppose $y=(1\\,1\\,1\\,0\\,0)$, then minimum distance decoder output is $\\hat{c}=(1\\,1\\,1\\,1\\,1)$.\n\n    $$ MDD(y)= \\begin{cases}\n      \\underbar{0}=(0,\\cdots,0) & w_H(y)<\\frac{n}{2} \\\\\n      \\underbar{1}=(1,\\cdots,1) & w_H(y) > \\frac{n}{2}\n   \\end{cases}$$\n   This is the majority decoding rule.\n\\end{itemize}\n\n\\section{Binary Hamming code}\n\nThis is a class of codes, we take up a particular example, let:\n$$ n=2^r -1 \\qquad k=2^r-1-r \\qquad d=3 \\quad \\forall \\quad r \\geq 3$$\n$$ \\text{if }r=3  \\Rightarrow\\qquad n=7,k=4,d=3$$\n\n$$ G_{4 \\times 7}= \\left[ I_4 : \\begin{bmatrix}\n    1       & 0 & 1  \\\\\n    0       & 1 & 1  \\\\\n    1       & 1 & 0  \\\\\n    1       & 1 & 1\n\\end{bmatrix}\\right]$$\n(we are appending $I_4$ with 3 columns to the right)\n\nNote: The 4 rows of G are linearly independent vectors of $\\mathbb{F}_2^7$. Rank(G) = number of linearly independent vectors in rows or columns = 4.\n\n$\\mathscr{C}$=Rowspace(G) is a 4-dim linear code. Rate= 4/7.\n\n$|\\mathscr{C}|= 2^k= 2^4=16$\n\n$d_{min}(\\mathscr{C}) =3$\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "1b7608660c74adcc218a9e134390a0a12a431877", "size": 5219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Source/Notes_week9.tex", "max_stars_repo_name": "thundermage117/Information-Comm.-Notes", "max_stars_repo_head_hexsha": "dfffa27d7216bd231b0e0e5743d7105c64ecf7fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Source/Notes_week9.tex", "max_issues_repo_name": "thundermage117/Information-Comm.-Notes", "max_issues_repo_head_hexsha": "dfffa27d7216bd231b0e0e5743d7105c64ecf7fc", "max_issues_repo_licenses": ["MIT"], "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/Notes_week9.tex", "max_forks_repo_name": "thundermage117/Information-Comm.-Notes", "max_forks_repo_head_hexsha": "dfffa27d7216bd231b0e0e5743d7105c64ecf7fc", "max_forks_repo_licenses": ["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.8188405797, "max_line_length": 202, "alphanum_fraction": 0.6259819889, "num_tokens": 1944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.64468990852824}}
{"text": "\\section{Asymptotics}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$\\Omega\\;(\\omega), \\Theta, O\\;(o)$}\n  \\[\n    O(g(n)) = \\set{f(n) \\mid \\exists c > 0, \\exists n_0, \\forall n \\ge n_0: 0 \\le f(n) \\le c g(n)}\n  \\]\n\n  \\pause\n\n  \\[\n    \\Omega(g(n)) = \\set{f(n) \\mid \\exists c > 0, \\exists n_0, \\forall n \\ge n_0: 0 \\le c g(n) \\le f(n)}\n  \\]\n\n  \\pause\n\n  \\begin{align*}\n    \\Theta(g(n)) &= \\set{f(n) \\mid \\exists c_1 > 0, \\exists c_2 >0, \\exists n_0, \\forall n \\ge n_0: \\\\ \n\t\t& 0 \\le c_1 g(n) \\le f(n) \\le c_2 g(n)}\n  \\end{align*}\n\n  \\pause\n\n  \\[\n\t  o(g(n)) = \\set{f(n) \\mid \\textcolor{red}{\\forall c > 0}, \\exists n_0, \\forall n \\ge n_0: 0 \\le f(n) \\le c g(n)}\n  \\]\n\n  \\pause\n\n  \\[\n\t  \\omega(g(n)) = \\set{f(n) \\mid \\textcolor{red}{\\forall c > 0}, \\exists n_0, \\forall n \\ge n_0: 0 \\le c g(n) \\le f(n)}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.2.6)}\n  \\begin{exampleblock}{Problem 1.2.6 (4)}\n\t\\[\n\t\tf(n) = \\Theta(g(n)) \\iff f(n) = O(g(n)) \\land f(n) = \\Omega(g(n))\n\t\\]\n  \\end{exampleblock}\n\n  \\pause\n\n  \\begin{exampleblock}{Problem 1.2.6 (5)}\n\t\\begin{align*}\n\t  f(n) = O(g(n)) &\\iff g(n) = \\Omega(f(n)) \\\\\n\t  f(n) = o(g(n)) &\\iff g(n) = \\omega(f(n))\n\t\\end{align*}\n  \\end{exampleblock}\n\n  \\pause\n  \n  \\begin{alertblock}{$f(n) = O(g(n)) \\lor g(n) = \\Omega(f(n)) ?$}\n\t\\pause\n\t\\[\n\t\tf(n) = n, \\quad g(n) = n^{1 + \\sin n}\n\t\\]\n  \\end{alertblock}\n\n  \\pause\n\n  \\begin{exampleblock}{Problem 1.2.6 (6)}\n\t\\[\n\t\t\\Theta(g(n)) \\cap o(g(n)) = \\emptyset\n\t\\]\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$\\Omega\\;(\\omega), \\Theta, O\\;(o)$}\n  \\begin{alertblock}{Reference}\n\t``Big Omicron and Big Omega and Big Theta'' by Donald E. Knuth, 1976.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.2.10)}\n  \\[\n\t\\log(n!) = \\Theta(n \\log n)\n  \\]\n\n  \\pause\n  \\vspace{0.30cm}\n  \\centerline{Prove by definition.}\n\n  \\pause\n  \\vspace{0.50cm}\n\n  \\centerline{Exercise: Prove it by Mathematical Induction.}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Horner's rule (Problem 1.1.6)}\n  \\[\n\tP(x) = a_0 + a_1 x + a_2 x^2 + \\cdots + a_{n-1} x^{n-1} + a_n x^n\n  \\]\n\n  \\pause\n  \\vspace{0.50cm}\n  \n  \\centerline{Loop invariant (after the $k$-th loop):}\n\n  \\[\n\t \\sum_{i = n}^{i = n-k} a_i x^{k-(n-i)}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "5ca7f2682363422f38431c0ea52b77c3210b552a", "size": 2278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/asymptotics.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/asymptotics.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/asymptotics.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": 21.4905660377, "max_line_length": 119, "alphanum_fraction": 0.5048287972, "num_tokens": 974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.6446899056921723}}
{"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 2 Seminar \\& HW}\\\\\n\n\\textbf{Problem 1:} There are $R$ red and $G$ green balls in a box. Alice and Bob pick balls from the box in turns (one ball at a time). The one who is the first to pick a red ball is the winner. Find the probability that Alice wins if she is the first to make a move and 1) they do not put balls back in the box 2) they do put them back. Write a numeric answer for $R=4$ and $G=5$.\n\\\\\n\n\\textbf{Problem 2:} Are the following statements true?\n\\begin{enumerate}\n    \\item $p(B|A)+p(B|\\bar{A})=1$\n    \\item $p(B|A)+p(\\bar{B}|\\bar{A})=1$\n\\end{enumerate}\n\\\\\n\n\\textbf{Problem 3:} Two subsets, $A_1$ and $A_2$ (they may coincide) are chosen randomly from $\\{1,\\dots,n\\}$. Find the probability that $|A_1|=l_1$ and $|A_2|=l_2$ under the condition that $A_1\\cap A_2=\\varnothing.$ Give a numeric answer for $n=6,~l_1=2,~l_2=3.$\n\\\\\n\n\\textbf{Problem 4:} There are $R$ red and $G$ green balls in a box. Alice is picking balls from the box, one at a time. $A_k$ is the event that, at time $k$ ($k$-th pick), she picks a red ball. Are the events $A_1,\\dots,A_n$ independent? Alice may be picking balls with replacement or without replacement – if Alice chooses to pick, say, without replacement – then she's making all the picks without replacement. Same for with replacement – provide the answer for both cases. \\\\\n\\textit{You may (or may not) need the following notion in your solution: A set of more than 2 events is called mutually (or collectively) independent, if all pairs of events in it are pairwise independent.}\n\\\\\n\n\\textbf{Problem 5:} Every edge (independently of all others) of $K_n$ – a complete graph on $n$ vertices, is colored in one of $k$\ncolors. For a set of vertices $S$ of the graph, let $A_S$ be the event that all the edges having both vertices in $S$ have the same color. What are the conditions on $S,T$ for the events $A_S$ and $A_T$ to be independent?\n\n\\end{document}\n", "meta": {"hexsha": "be17a4af8b8b6339d2b952c8eafb9e9074465e73", "size": 2416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week02_conditional_probability/Week02_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": "week02_conditional_probability/Week02_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": "week02_conditional_probability/Week02_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": 52.5217391304, "max_line_length": 478, "alphanum_fraction": 0.7280629139, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6446898975521154}}
{"text": "\\documentclass[letterpaper,10pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{siunitx}\n\\usepackage{physics}\n\\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}\n\n\\DeclareSIUnit \\inch {in}\n\\DeclareSIUnit \\fahrenheit {\\degree F}\n\\DeclareSIUnit \\rankine {R}\n\n\\title{Offset Unit Conversions}\n\\author{C.D. Clark III}\n\n\n\\begin{document}\n\\maketitle\n\nAn offset unit is a unit that contains an offset from zero (a bias). The most common examples are the Celsius and Fahrenheit\nscales. Converting from Celsius to Kelvin is simple because they have the same\nscaling factor, you just add or subtract the offset. However, converting from\nCelsius to Fahrenheit requires correct conversion of the scaling factor and offset.\n\nAny non-base unit ($\\hat{v}$) can be expressed in terms of a base unit ($\\hat{u}$) with a scaling factor ($\\alpha$) and offset ($\\beta$).\n$$\n\\label{eq:offset_unit}\n\\hat{v} = \\alpha \\hat{u} + \\beta\n$$\nConsider two offset units, $\\hat{v}_1$ and $\\hat{v}_2$, and assume our base unit $\\hat{u}$ is an \\emph{abolute} unit.\n\\begin{align}\n  \\hat{v}_1 &= \\alpha_1 \\hat{u} + \\beta_1 \\\\\n  \\hat{v}_2 &= \\alpha_2 \\hat{u} + \\beta_2\n\\end{align}\n\nWe want to know how to convert quantities expressed in one offset unit to another offset units.\n\n\\section{Incorrect Way}\nWhat follows is not correct, but it illustrates the difficulty in deriving a formula to convert from on offset unit to the other.\n\nTo convert \\emph{from} $\\hat{v}_1$ \\emph{to} $\\hat{v}_2$,\n\\begin{align}\n  \\hat{u} &= \\frac{\\hat{v}_1 - \\beta_1}{\\alpha_1} \\\\\n  \\hat{v}_2 &= \\alpha_2 \\left( \\frac{\\hat{v}_1 - \\beta_1}{\\alpha_1} \\right)  + \\beta_2 \\\\\n  \\label{eq:v1_to_v2}\n  \\hat{v}_2 &= \\frac{\\alpha_2}{\\alpha_1}\\hat{v}_1  + \\left( \\beta_2- \\frac{\\alpha_2}{\\alpha_1}\\beta_1 \\right)\n\\end{align}\nIf $\\beta_1 = \\beta_2 = 0$ this just gives the usual unit convertion formula.\n\nNow, given a quantity $x = v_1 \\hat{v}_1$, what is the numerical value for the quantity when expressed in terms of $\\hat{v}_2$?\n\n\\textbf{tangent}\nNote that \\ref{eq:v1_to_v2} gives us a way to replace $\\hat{v}_2$ with\n$\\hat{v}_1$. Given a units $\\hat{v}_1$, we can use Equation \\ref{eq:v1_to_v2}\nto convert it to $\\hat{v}_2$. For example, let $\\hat{v}_1 = \\si{\\centi\\meter}$ and $\\hat{v}_2 = \\si{\\inch}$.\nThen:\n\\begin{align}\n  \\si{\\centi\\meter} &= \\SI{0.01}{\\meter} \\\\\n  \\si{\\inch} &= \\SI{0.0254}{\\meter} \n\\end{align}\nand\n\\begin{align}\n  \\si{\\inch} &= 0.0254\\times \\SI{100}{\\centi\\meter}  = \\SI{2.54}{\\centi\\meter}\n\\end{align}\nWhic is a conversion \\emph{from} \\si{\\centi\\meter} \\emph{to} \\si{\\inch}. But if we want to convert a quantity expressed in \\si{\\centi\\meter}\nto \\si{\\inch}, say \\SI{10}{\\centi\\meter} for example, we would do:\n\\begin{align}\n  \\SI{10}{\\centi\\meter} = \\SI{10}{\\centi\\meter} \\frac{\\si{\\inch}}{\\SI{2.54}{\\centi\\meter}} = \\frac{10}{2.54} \\si{\\inch}\n\\end{align}\nSo the numerical value of a quantity expressed in a given unit transforms in the opposite way as the unit. This is similar to the difference\nbetween covariant and contravariant vectors, where the components of contravariant vector transform in the opposte way of the basis vectors.\n\nTo convert $x = v_1 \\hat{v}_1$ to $\\hat{v}_2$, we need to replace $\\hat{v}_1$.\n\\begin{align}\n  \\hat{v}_1 &= \\frac{\\alpha_1}{\\alpha_2}\\hat{v}_2  + \\left( \\beta_1- \\frac{\\alpha_1}{\\alpha_2}\\beta_2 \\right) \\\\\n  v_1 \\hat{v}_1 &= v_1 \\left(\\frac{\\alpha_1}{\\alpha_2}\\hat{v}_2  + \\left( \\beta_1- \\frac{\\alpha_1}{\\alpha_2}\\beta_2 \\right)\\right) \\\\\n  v_1 \\hat{v}_1 &= v_1 \\frac{\\alpha_1}{\\alpha_2}\\hat{v}_2  + v_1 \\left( \\beta_1- \\frac{\\alpha_1}{\\alpha_2}\\beta_2 \\right)\n\\end{align}\nSo what is $v_2$? For absolute units, we would just have $v_2 = v_1\\frac{\\alpha_1}{\\alpha_2}$. But here we have the second term\nwith no unit to deal with. First, consider the cases when of the units is an absolute unit. Let $\\hat{v}_1$ be an absolute unit, so\nthat $\\beta_1 = 0$. Then we have\n\\begin{align}\n  v_1 \\hat{v}_1 &= v_1 \\frac{\\alpha_1}{\\alpha_2}\\hat{v}_2  - v_1 \\frac{\\alpha_1}{\\alpha_2}\\beta_2\n\\end{align}\nThe $v_1$ in the second term does not make any sense here. If we consider the case when $\\hat{v}_1 = \\si{\\kelvin}$ and $\\hat{v}_2 = \\si{\\celsius}$,\nthen this says that\n\\begin{align}\n  \\SI{100}{\\kelvin} &= 100 \\si{\\celsius}  - 100 \\times 273\n\\end{align}\nwhich is not correct. The correct equation is of course\n\\begin{align}\n  \\SI{100}{\\kelvin} &= 100 \\si{\\celsius}  - 273,\n\\end{align}\nbut this doesn't even appear to be dimensionally correct. The issue is that units don't obey the normal algebra. It does not make sense to multiply\nan offset unit by a scaling factor (what is \\SI{100}{\\celsius} times 2?), so we cannot do it.\n\n\\section{Correct Way}\n\nThe correct way to convert offset units is to first subract off the bias,\nconvert the scale, and add the new bias on.  Note that the $\\beta$ term in\nEquation \\ref{eq:offset_unit} is a numerical value expressed in the \\emph{scale\nof the unit being defined}. When we convert from the absolute unit, to the offset unit,\nthe $\\beta$ term is \\emph{not} scaled. i.e.\n\\begin{align}\n  100\\hat{u} \\rightarrow \\alpha (100\\hat{u}) + \\beta \\ne \\alpha (100\\hat{u}) + 100 \\beta\n\\end{align}\n\nNote that, while $\\hat{v}$ is an offset unit, $\\hat{v}-\\beta$ is \\emph{not}. This\nillustrates the breakdown in our notation, it looks like we are adding two different things.\n\nReformulating our conversion then\n\\begin{align}\n  \\hat{v}_1  - \\beta_1 &= \\alpha_1 \\hat{u} \\\\\n  \\hat{v}_2  - \\beta_2 &= \\alpha_2 \\hat{u}.\n\\end{align}\nSince $\\hat{v}_i  - \\beta_i$ is an absolute unit, it will obey our usual algebra, as long as we keep it together. Let $\\hat{v}^\\prime_i = \\hat{v}_i - \\beta_i$. Then\n\\begin{align}\n  \\hat{v}_1  - \\beta_1 &= \\alpha_1 \\hat{u} = \\hat{v}^\\prime_1 \\\\\n  \\hat{v}_2  - \\beta_2 &= \\alpha_2 \\hat{u} = \\hat{v}^\\prime_2 ,\n\\end{align}\nand\n\\begin{align}\n  \\hat{v}^\\prime_1 &= \\alpha_1 \\hat{u} \\\\\n  \\hat{v}^\\prime_2 &= \\alpha_2 \\hat{u} = \\frac{\\alpha_2}{\\alpha_1} \\hat{v}^\\prime_1 \\\\\n  \\hat{v}^\\prime_1 &= \\frac{\\alpha_1}{\\alpha_2} \\hat{v}^\\prime_2 \\\\\n\\end{align}\nNote that $\\frac{\\alpha_1}{\\alpha_2}$ (expressed in terms of each units scaling factor for the base unit of the dimension)\nis the conversion factor from $\\hat{v}_2$ to $\\hat{v}_1$ but will convert quantities expressed\nin $\\hat{v}_1$ to $\\hat{v}_2$.\n$$\nv^\\prime_1 \\hat{v}^\\prime_1 = v^\\prime_1 \\frac{\\alpha_1}{\\alpha_2} \\hat{v}^\\prime_2 = v^\\prime_2 \\hat{v}^\\prime_2\n$$\nNow we just need a rule to convert between quantities expressed in terms of the primed and unprimed units:\n\\begin{align}\n  v \\hat{v} &= (v - \\beta)\\hat{v}^\\prime = v^\\prime \\hat{v}^\\prime \\\\\n  v^\\prime \\hat{v}^\\prime &= (v^\\prime + \\beta)\\hat{v} = v\\hat{v}\n\\end{align}\nNow given $x = v_1\\hat{v}_1$\n\\begin{align}\n  v_1 \\hat{v}_1 &= (v_1 - \\beta_1) \\hat{v}^\\prime_1 = (v_1 - \\beta_1) \\frac{\\alpha_1}{\\alpha_2} \\hat{v}^\\prime_2 = \\left((v_1 - \\beta_1) \\frac{\\alpha_1}{\\alpha_2} + \\beta_2\\right) \\hat{v}_2 \\\\\n  v_2 &= \\left((v_1 - \\beta_1) \\frac{\\alpha_1}{\\alpha_2} + \\beta_2\\right)\n\\end{align}\n\n\\subsection{Final Note}\n\nThe discussion about covariant and contravariant vectors above is fun, but it does have some practical consequenses. In fact, it is the reason\nI started writing this document.\n\nTake the well known conversion forula for Celsius to Fahrenheit:\n$$\n\\si{\\fahrenheit} = \\frac{9}{5} \\si{\\celsius} + 32\n$$\n\nThe Rankine scale is an aboslute temperature scale that uses the Fahrenheit degree size. That is, Rankine is zero at absolute zero, but\nthe size of one degree is the same as Fahrenheit. So, to convert from Kelvin to Rankine, we have\n\\begin{equation}\n  \\label{eq:rankine_quant}\n\\si{\\rankine} = \\frac{9}{5} \\si{\\kelvin}\n\\end{equation}\nNow, since a Kelvin degree is larger than a Rankine degree, we also have\n$$\n\\SI{900}{\\rankine} = \\SI{500}{\\kelvin}\n$$\nbut this means that \n\\begin{equation}\n  \\label{eq:rankine_unit}\n\\si{\\rankine} = \\frac{5}{9}\\si{\\kelvin}.\n\\end{equation}\nSo which is correct?\n\nThe answer is that they are both correct, but Equation \\ref{eq:rankine_quant} is a conversion for the numerical values of the quantity, and\nEquation \\ref{eq:rankine_unit} is a conversion for the units. Perhaps Equation \\ref{eq:rankine_quant} should be written as\n\\begin{equation}\n  T_R = \\frac{9}{5} T_K,\n\\end{equation}\ni.e. a relationships between the \\emph{components} of a quantity. The point here is that we must be careful when defining unit conversions\nin the library. The library expects conversions for the units, \\emph{not} the components, so Equation \\ref{eq:rankine_unit} is the correct way\nto specify the unit.\n\n\\section{General Case}\n\nIn general, a unit may be defined as an arbitrary transformation. For example, the American Wire Gauge unit is defined as\n$$\nd_n = \\SI{0.127}{\\milli\\meter} \\times 92^{\\frac{36 - n}{39}}\n$$\nwhere $n$ is the wire gauge. To perform arbitrary unit conversions, including conversions between non-linear units, we just need the\nfunction that relates unit to a linear, absolute base unit. Given two units:\n\\begin{align}\n\\hat{v}_1 &= f(\\hat{u}) \\\\\n\\hat{v}_2 &= g(\\hat{u})\n\\end{align}\n%then\n%\\begin{align}\n  %\\hat{u} &= f^{-1}(\\hat{v}_1) \\\\\n%\\hat{v}_2 &= g(f^{-1}(\\hat{v}_1)).\n%\\end{align}\nTo convert quantities, be just convert to the base unit first, then to the second unit.\n\\begin{align}\nv_1 \\hat{v}_1 &= g(f^{-1}(v_1)) \\hat{v}_2 = v_2 \\hat{v}_2 \\\\\nv_2 &= g(f^{-1}(v_1))\n\\end{align}\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "afeaa89cfb56447f3bbf100f855ec4aebf740fde", "size": 9379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/writeups/OffsetUnitConversions/main.tex", "max_stars_repo_name": "CD3/UnitConvert", "max_stars_repo_head_hexsha": "06530130a952ac67bd3d88b2b7791a147c69db64", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-22T11:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T11:01:10.000Z", "max_issues_repo_path": "doc/writeups/OffsetUnitConversions/main.tex", "max_issues_repo_name": "CD3/UnitConvert", "max_issues_repo_head_hexsha": "06530130a952ac67bd3d88b2b7791a147c69db64", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-10-13T15:12:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T22:32:23.000Z", "max_forks_repo_path": "doc/writeups/OffsetUnitConversions/main.tex", "max_forks_repo_name": "CD3/UnitConvert", "max_forks_repo_head_hexsha": "06530130a952ac67bd3d88b2b7791a147c69db64", "max_forks_repo_licenses": ["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.0913461538, "max_line_length": 192, "alphanum_fraction": 0.6937839855, "num_tokens": 3280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6444660036205057}}
{"text": "\nThis appendix describes the analytical solution used in Section \\ref{sec:tf-ver}.\n\n\\section{Verification of the thermal-fluids model}\n\\label{appendix:ver}\n\nThe analytical solution of the problem is\n\\begin{align}\n    T_c (r, z) &= T_{in} + \\frac{q_{ave} R_f^2 L}{2 \\rho c_p v \\pi R_c^2} \\left[ 1 + cos \\left( \\frac{\\pi}{L} z \\right) \\right] \\\\\n    T_3(z) &= T_c(z) + \\frac{q_{ave} \\pi}{2} sin \\left( \\frac{\\pi}{L} z \\right) R_f^2 \\frac{ln(R_i/R_m)}{2 k_i} \\\\\n    T_2(z) &= T_3(z) + \\frac{q_{ave} \\pi}{2} sin \\left( \\frac{\\pi}{L} z \\right) R_f^2 \\frac{ln(R_m/R_g)}{2 k_m} \\\\\n    T_1(z) &= T_2(z) + \\frac{q_{ave} \\pi}{2} sin \\left( \\frac{\\pi}{L} z \\right) R_f^2 \\frac{ln(R_g/R_f)}{2 k_g} \\\\\n    T_f (r=0, z) &= T_1(z) + \\frac{q_{ave} \\pi}{2} sin \\left( \\frac{\\pi}{L} z \\right) R_f^2 \\frac{1}{4 k_f} \\\\\n    T_f (r, z=L/2) &= \\frac{q_{ave}}{4 k_f} \\left(R_f^2 - r^2\\right) + T_1 (z=L/2) \\\\\n    T_g (r, z=L/2) &= \\frac{T_1 (z=L/2)-T_2 (z=L/2)}{ln (R_f/R_g)} ln (r/R_g) + T_1(z=L/2) \\\\\n    T_m (r, z=L/2) &= \\frac{T_2 (z=L/2)-T_3 (z=L/2)}{ln (R_g/R_m)} ln (r/R_m) + T_2(z=L/2) \\\\\n    T_i (r, z=L/2) &= \\frac{T_3 (z=L/2)-T_c (z=L/2)}{ln (R_m/R_i)} ln (r/R_i) + T_3(z=L/2) \\\\\n    T_c (r, z=L/2) &= T_c(z=L/2)\n    \\intertext{where}\n    T_{c} &= \\mbox{bulk coolant temperature } [^{\\circ}C] \\notag \\\\\n    T_{in} &= \\mbox{inlet coolant temperature } [^{\\circ}C] \\notag \\\\\n    q_{ave} &= \\mbox{average power density } [W \\cdot cm^{-3}] \\notag \\\\\n    R_f &= \\mbox{fuel compact radius } [cm] \\notag \\\\\n    L &= \\mbox{fuel column height } [cm] \\notag \\\\\n    \\rho &= \\mbox{helium density } [kg \\cdot cm^{-3}] \\notag \\\\\n    c_p &= \\mbox{helium heat capacity } [J \\cdot kg^{-1} \\cdot K^{-1}] \\notag \\\\\n    v &= \\mbox{average helium velocity } [cm \\cdot s^{-1}] \\notag \\\\\n    R_c &= \\mbox{coolant channel radius } [cm] \\notag \\\\\n    R_g &= \\mbox{gap radius } [cm] \\notag \\\\\n    R_m &= \\mbox{moderator radius } [cm] \\notag \\\\\n    R_i &= \\mbox{film radius } [cm] \\notag \\\\\n    k_f &= \\mbox{fuel compact thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n    k_g &= \\mbox{gap thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n    k_m &= \\mbox{moderator thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n    k_i &= \\mbox{film thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}]. \\notag\n\\end{align}\n", "meta": {"hexsha": "bb8f12593231d15666d000efe3128a8d1db6935d", "size": 2318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixC.tex", "max_stars_repo_name": "robfairh/ms-thesis", "max_stars_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-27T15:39:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T15:39:36.000Z", "max_issues_repo_path": "appendixC.tex", "max_issues_repo_name": "robfairh/ms-thesis", "max_issues_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2020-07-10T18:40:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-02T22:37:02.000Z", "max_forks_repo_path": "appendixC.tex", "max_forks_repo_name": "robfairh/ms-thesis", "max_forks_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "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": 62.6486486486, "max_line_length": 130, "alphanum_fraction": 0.5565142364, "num_tokens": 986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6444326900875306}}
{"text": "\\section{Math IV - Numerical Methods}\r\n  \\subsection{Fast Square Testing}\r\n    An optimized test for square integers.\r\n    \\code{math/numerical/is_square.cpp}\r\n  \\subsection{Simpson Integration}\r\n    Use to numerically calculate integrals\r\n    \\code{math/numerical/simpson_integration.cpp}\r\n", "meta": {"hexsha": "3ee0bc66755e770835a110289e600e6b2de2c93c", "size": 291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/numerical.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/numerical.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/numerical.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": 36.375, "max_line_length": 50, "alphanum_fraction": 0.7491408935, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6443937777566604}}
{"text": "\\section{Model}\n\n\\begin{equation}\n    \\textbf{State space: }\\statespace = \\R^{2} \\times \\{0, 1, 2, 3, 4, 5\\} \\times \\{ 18, 19, \\cdots , 84, 85\\}\n\\end{equation}\n\n\\begin{equation}\n    \\textbf{Action space: }\\actionspace  = \\{0, 15, 25, 37, 45\\}\n\\end{equation}\n\n\\begin{equation}\n    \\textbf{States: }\\{A, Z, K, Q\\}, \\qquad \\textbf{Actions: } \\{H\\} \n\\end{equation}\n\n\\begin{equation}\n    \\textbf{Variables: }\\{L, W, Y, C, B, U\\},  \\qquad \\textbf{Parameters: } \\{\\kappa, \\mu_\\rho, \\sigma_\\rho, p_\\psi, \\sigma_\\epsilon, \\zeta, a, b, c, d\\}\n\\end{equation}\n\nThe variables are normalized such that their values correspond to a single week. I.e. the agent can choose to work between 0 and 45 hours a week. The agents consumption will be normalized to weekly levels. The state $A$ represents assets. $Z$ is the idiosyncratic wage level. $K$ is the number of kids and $Q$ is the age of the agent. In this formulation time $(t)$ and age $(Q)$ are explicitly modelled separately, such to clearly separate what is a function of age and what is a function of time. f.x. The wage level is modelled to follow a certain pattern as a function of age, not of time. Importantly for solving the model, I do not need to integrate out the age since it is perfectly deterministic. The action space contains a single discrete variable $H$ that denotes the number of working hours.\n\nModel dynamics:\n\n\\begin{align}\n    U_t (C_t, L_t, B_t) &= C_t^{1-B_t}L_t^{B_t} \\label{eq:utility_v1}\\\\\n    B_t (K_t) &= f^{B}(K_t) \\label{eq:alpha_v1}\\\\\n    Y_t ( H_t, W_t) &= H_t \\cdot W_t \\label{eq:salary_v1}\\\\\n    C_t (A_t, Y_t) &= \\kappa \\cdot (A_t + Y_t) \\label{eq:consumption_v1}\\\\\n    L_t(H_t) &= 7 \\cdot 24 - H_t \\label{eq:leisure_v1}\\\\\n    W_t(Z_t, Q_t) &= f^{W_t}(Q_t) + Z_t \\label{eq:wage_v1}\n\\end{align}\n\nLaw of motion (transitionsligninger XXX):\n\n\\begin{align}\n    A_{t+1}(A_t, Y_t, C_t) &= \\rho_{t+1} \\cdot (A_t + Y_t - C_t), \\qquad \\rho_{t+1} \\sim \\ndist(\\mu_{\\rho}, \\sigma_{\\rho}) \\label{eq:assets_v1} \\\\\n    K_{t+1} (K_t) &= K_t + \\psi_{t+1}, \\qquad \\psi_{t+1} \\sim Bernoulli(p_{\\psi}) \\label{eq:kids_v1}\\\\\n    Z_{t+1} (Z_{t}) &=  \\zeta \\cdot Z_t \\cdot \\epsilon_{t+1} \\qquad \\log (\\epsilon_{t+1} ) \\sim \\ndist(0, \\sigma_{\\epsilon}) \\label{eq:wage_level_v1}\\\\\n    Q_{t+1} (Q_t)&= Q_t + 1 \\label{eq:age_v1}\n\\end{align}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.09, angle=90]{figures/modeldynamic_tmp.jpg}\n    \\caption{Model dynamics (temporary figure) XXX}\n    \\label{fig:modeldynamics}\n\\end{figure}\n\nOther variables in the model are: Utility as modelled in equation \\eqref{eq:utility_v1} that follow the Cobb-Douglas formulation. Equation \\eqref{eq:alpha_v1} denotes the utility dynamic of having kids. Later the functional form of $f^{B}$ is discussed. Equation \\eqref{eq:salary_v1} models salary as being the product of the number of working hours and the wage level. \\eqref{eq:consumption_v1} is assumed to be fraction of the sum of salary and assets (sometimes referred \\textit{cash-on-hand}). \\eqref{eq:leisure_v1} shows leisure being the total number of hours in a week - minus the number of hours worked. Equation \\eqref{eq:wage_v1} governs how the wage level at time $t$ can be decomposed into an idiosyncratic component and a deterministic component that are deterministic as a function of age.\n\n4 equations govern the law of motion: Equation \\eqref{eq:assets_v1} governs how the assets in period $t$ grows with a normally distribution return, adding the salary and subtracting the consumption of period $t$. Equation \\eqref{eq:kids_v1} denotes the growth of children. The idiosyncratic wage level is governed by equation \\eqref{eq:wage_level_v1}. Where it's assumed that the previous period has influence on the wage level. Equation \\eqref{eq:age_v1} shows how the age of the agent follows a deterministic process.\n\nFinally two functions in the formulation should be clearly explicited: $f^{B}, f^{W}$. Starting with $f^{B}$ a couple of things should be noted, about how the function should behave. First and foremost:\n\n\\begin{equation}\n    f^{B}: \\N_{0,+} \\mapsto [0,1]\n\\end{equation}\n\nThis is due to the fact that the utility function is of the Cobb-Douglas formulation, where the $B$ parameter should be contained in the interval [0,1]. Second it should be noted that it should not be perfectly determined whether or not:\n\n\\begin{equation}\n    \\frac{d}{d K}f^{B} > 0 \\qquad \\textbf{or} \\qquad \\frac{d}{d K}f^{B} < 0\n\\end{equation}\n\nTherefore the formulation:\n\n\\begin{equation}\n    f^{B} (K_t)= a + b \\frac{\\exp{c + d K_t}}{1 + \\exp{c + d K_t}}\\qquad  \\text{s.t. } a + b < 1, a \\land b > 0\n\\end{equation}\n\nThe function $f^{W}$ is not parametric, and determined by data from Dansk Statistik XXX.\n\n\nParameters of the model being: $\\kappa, \\mu_\\rho, \\sigma_\\rho, p_\\psi, \\sigma_\\epsilon, \\zeta$. and $a, b, c, d$, where the latter govern the dynamic of the utility of leisure conditioned on the number of kids. $\\kappa$ governs the consumption profile, $\\mu_\\rho$ denotes the expected return of the assets, $\\sigma_\\rho$ the variance. $p_\\psi$ is the probability of a new child. $\\sigma_{\\epsilon}$ is the variance (before the log transformation) of the log-normal shock to the income process. $\\zeta$ is growth constant on the wage level evolution.\n\n\n\\textbf{MULIGE UDVIDELSER}: 1) function for $p_\\psi (Q_t, K_t)$.  Forbrugs kvotienten $\\kappa (Q_t, K_t)$ kan være en funktion af alderen og børn. Man kan også overveje at tilføje transfers. Uddannelses niveayu og dets indflydelse på wage er også en mulighed.\n", "meta": {"hexsha": "4cb02cc2032bd926d64b966f0328b87aa7cfa81a", "size": 5509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/old_chapters/model1.tex", "max_stars_repo_name": "JakartaLaw/speciale", "max_stars_repo_head_hexsha": "95d89c281b9d8f73065a823cba97a5bedcbf129d", "max_stars_repo_licenses": ["MIT"], "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/old_chapters/model1.tex", "max_issues_repo_name": "JakartaLaw/speciale", "max_issues_repo_head_hexsha": "95d89c281b9d8f73065a823cba97a5bedcbf129d", "max_issues_repo_licenses": ["MIT"], "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/old_chapters/model1.tex", "max_forks_repo_name": "JakartaLaw/speciale", "max_forks_repo_head_hexsha": "95d89c281b9d8f73065a823cba97a5bedcbf129d", "max_forks_repo_licenses": ["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.5454545455, "max_line_length": 803, "alphanum_fraction": 0.7113813759, "num_tokens": 1776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.644393770281751}}
{"text": "\\textbf{Find a way to modify your program of Exercise 8.4, as in Exercise 3.8 but now for a second order problem, to make use of matrix exponentials rather than time discratization. What effect does this have on the computation time?}\n\\newline\n\nIn this case, just for $N=24$ it took $t=  25.3899480~s$ to complete the simulation, a severe increase for such a small number of grid points.\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 5 - 8.5 Trefethen\n\n% Grid and initial data:\n\nNvector = [24];\ntime = zeros(length(Nvector),1);\nfor k = 1:length(Nvector)\n    N=Nvector(k);\n    [D,x] = cheb(N);  y = x;\n    D2 = D^2;\n    D2 = D2(2:end-1,2:end-1);\n    L = kron(eye(N-1),D2)+kron(D2,eye(N-1));\n    A = [zeros(size(L)) eye(size(L)); L zeros(size(L))];\n    dt = 6/N^2;\n    [xx,yy] = meshgrid(x(2:N),y(2:N));\n    x = xx(:); y = yy(:);\n\n    plotgap = round((1/3)/dt); dt = (1/3)/plotgap;\n    u0 = exp(-40*((x-.4).^2 + y.^2));\n    u = u0;\n    % Time-stepping by leap frog formula:\n    [ay,ax] = meshgrid([.56 .06],[.1 .55]); clf\n    tic\n    for n = 0:3*plotgap\n        t = n*dt;\n%         if rem(n+.5,plotgap)<1     % plots at multiples of t=1/3\n%           uu = reshape(u,N-1,N-1);\n%           i = n/plotgap+1;\n%           subplot('position',[ax(i) ay(i) .36 .36])\n%           [xxx,yyy] = meshgrid(-1:1/16:1,-1:1/16:1);\n%           uuu = interp2(xx,yy,uu,xxx,yyy,'cubic');\n%           mesh(xxx,yyy,uuu), axis([-1 1 -1 1 -0.15 1])\n%           colormap(1e-6*[1 1 1]); title(['t = ' num2str(t)]), drawnow\n%         end\n    % ------------------------------ %    \n    % -- Using matrix exponential -- %\n    % ------------------------------ %    \n        v = expm(A*t)*[u0;zeros(size(u0))];\n        u = v(1:length(u0));\n    end\n    time(k) = toc;\nend\n\\end{verbatim}", "meta": {"hexsha": "16456022c8786a97fe1ba6ac2f482ee632d0488c", "size": 1777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem5.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": "SpectralMethods/Homework3/Latex/problem5.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": "SpectralMethods/Homework3/Latex/problem5.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.54, "max_line_length": 234, "alphanum_fraction": 0.5295441756, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6443340186473405}}
{"text": "\n\\chapter{Maximum and minimum algorithms}\n\\Label{cha:maxmin}\n\nIn this chapter we discuss the formal specification of algorithms\nin the \\cxx Standard Library \\cite[\\S 28.7.8]{cxx-17-draft}\nthat compute the maximum or minimum values of their arguments.\nAs the algorithms in Chapter~\\ref{cha:non-mutating}, they also do not modify\nany memory locations outside their scope.\nThe most important new feature of the algorithms in this chapter\nis that they compare values using binary operators such as \\inl{<}.\n\nWe consider in this chapter the following algorithms.\n\n\\begin{itemize}\n\n\\item\nWe discuss some properties of relations operators in \\S\\ref{sec:relationaloperators}.\n\n\\item\nWe introduce in \\S\\ref{sec:arraybounds} various predicates\nthat describe basic order properties for arrays whose elements are of~\\valuetype.\n\n\\item\n\\clamp, which is discussed in \\S\\ref{sec:clamp},\nis a very simple algorithms that ``clamps'' (or ``clips'') a value between a\npair of boundary values.\n  \n\\item \\maxelement  \nreturns an index to\na maximum element in a range. Similar to \\find it also\nreturns the smallest of all possible indices.\nThis algorithm is discussed in \\S\\ref{sec:maxelement}.\nIn \\S\\ref{sec:maxelementii}, we introduce an alternative\nspecification \\maxelementii which relies on user-defined predicates.\n\n\\item \\maxseq  in \\S\\ref{sec:maxseq}\nis very similar to \\maxelement and will serve as an\nexample of \\emph{modular verification}.\nIt returns the maximum value itself rather than an index to\nit.\n\n\\item \\minelement in \\S\\ref{sec:minelement}\ncan be used to find the smallest element in an array.\n\n\\item \\minmaxelement in \\S\\ref{sec:minmaxelement}\nis used to find simultaneously the smallest and largest element in a given range.\nThis algorithms relies on the auxiliary function\n\\makepair (\\S\\ref{sec:makepair}).\n\\end{itemize}\n\nFirst, however, we discuss in \\S\\ref{sec:relationaloperators}\ngeneral properties that must be satisfied by the relational operators.\n\n%\\clearpage\n\n\\section{A note on relational operators}\n\\Label{sec:relationaloperators}\n\nNote that in order to compare values, algorithms in the\n\\cxx Standard Library \\cite[\\S 28.7.8]{cxx-17-draft} usually rely solely on \nthe \\emph{less than} operator~\\inl{<} or special function\nobjects.\nTo be precise, the operator~\\inl{<} must be a \\emph{partial\norder},\\footnote{\n    See~\\url{http://en.wikipedia.org/wiki/Partially_ordered_set}\n}\nwhich means that the following rules must hold.\n%\n\\begin{alignat*}{5}\n&\\text{irreflexivity} &&\\qquad  \\forall x     &&: \\neg(x < x)         \\\\\n&\\text{asymmetry}     &&\\qquad  \\forall x,y   &&: x < y             &&\\implies \\neg(y < x)\\\\\n&\\text{transitivity}  &&\\qquad  \\forall x,y,z &&: x < y \\wedge y < z &&\\implies x < z\n\\end{alignat*}\n\n\nIf you wish to check that the operator~\\inl{<} of our \\valuetype\\footnote{\n    See \\S\\ref{sec:frequentPattern}\n}  satisfies these properties\none can formulate the lemmas of \\logicref{Less} and verify them with \\framac.\n\n\\input{Listings/LessThanComparable.acsl.tex}\n\nIt is of course possible to specify and implement the algorithms\nof this chapter by only using operator~\\inl{<}.\nFor example, \\inl{a <= b} can be written as \\texttt{a < b || a == b},\nor, for our particular ordering on \\valuetype, as \\inl{!(b < a)}.\nListing~\\logicref{Less} therefor also contains lemmas on representing\nthe operator~\\inl{>}, \\inl{<=}, and~\\inl{>=} through operator \\inl{<}.\n\n\n\n\\section{Predicates for bounds and extrema of arrays}\n\\label{sec:arraybounds}\n\nWe define in the following listing the predicates \\logicref{MaxElement}\nand \\logicref{MinElement} that we will use for the specification of various algorithms.\nWe will discuss these predicates in more detail in \\S\\ref{sec:maxelementii}\nand \\S\\ref{sec:minelement}.\n\n\\input{Listings/ArrayExtrema.acsl.tex}\n\n\n\\clearpage\n\nThe aforementioned predicates rely on the predicates\n\\logicref{LowerBound} and \\logicref{UpperBound} which\nare shown in the following listing together with \nthe related predicates \\logicref{StrictUpperBound} and \\logicref{StrictLowerBound}.\n\n\\input{Listings/ArrayBounds.acsl.tex}\n\nThese predicates concisely express the\ncomparison of the elements in an array (segment) with a given value.\nWe will heavily rely on these predicates both in this chapter and\nin Chapter~\\ref{cha:binary-search}.\n\n\\clearpage\n\n\\input{maxmin/clamp}\n\\input{maxmin/make_pair}\n\\input{maxmin/max_element}\n\\input{maxmin/max_element2}\n\\input{maxmin/max_seq}\n\\input{maxmin/min_element}\n\\input{maxmin/minmax_element}\n\n", "meta": {"hexsha": "57e4e46d2138f856353e88b1531ad66836967ed9", "size": 4470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/maxmin/maxmin-algorithms.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/maxmin-algorithms.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/maxmin-algorithms.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": 34.921875, "max_line_length": 92, "alphanum_fraction": 0.7592841163, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568416, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6443340153625126}}
{"text": "\\newcommand{\\eos}{\\hfill{}$\\cdots\\diamond\\cdots$\\hfill{}\\vspace{5mm}}\n\n\\newcommand{\\mathpredn}{\\mathbin{-\\!\\!\\!\\mid\\mid\\!\\rightarrow}}\n\n\\newcommand{\\KC}{\\con{K}}\n\\newcommand{\\SC}{\\con{S}}\n\\newcommand{\\bk}{\\char'134}\n\n\n\\chapter{Example: Combinatory Logic}\n\\label{chap:combin}\n\n\\section{Introduction}\n\\label{sec:Introduction}\n\nThis small case study is a formalisation of (variable-free)\ncombinatory logic.  This logic is of foundational importance in\ntheoretical computer science, and has a very rich theory.  The example\nbuilds principally on a development done by Tom Melham.  The complete\nscript for the development is available as \\texttt{clScript.sml} in\nthe \\texttt{examples/ind\\_def} directory of the distribution.  It is\nself-contained and so includes the answers to the exercises set at the\nend of this document.\n\nThe HOL sessions assume that the Unicode trace is \\emph{on} (as it is\nby default), meaning that even though the inputs may be written in\npure ASCII, the output still uses nice Unicode output (symbols such as\n$\\forall$ and $\\Rightarrow$).  The Unicode symbols could also be used\nin the input.\n\n\n\\section{The type of combinators}\n\\label{sec:Type-Combinators}\n\nThe first thing we need to do is define the type of\n\\emph{combinators}.  There are just two of these, \\KC{} and \\SC, but\nwe also need to be able to \\emph{combine} them, and for this we need\nto introduce the notion of application.  For lack of a better ASCII\nsymbol, we will use the hash (\\#) to represent this in the logic:\n\\setcounter{sessioncount}{0}\n\\begin{session}\n\\begin{verbatim}\n- Hol_datatype `cl = K | S | # of cl => cl`;\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\nWe also want the \\# to be an infix, so we set its fixity to be a tight\nleft-associative infix:\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"#\" (Infixl 1100);\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\n\n\n% C = S (S (K S) (S (K K) S)) (K K)\n\n\n\\section{Combinator reductions}\n\\label{sec:Comb-Reduct}\n\nCombinatory logic is the study of how values of this type can evolve\ngiven various rules describing how they change.  Therefore, our next\nstep is to define the reductions that combinators can undergo.  There\nare two basic rules:\n\\[\\begin{array}{l@{\\;\\;\\rightarrow\\;\\;}l}\n\\KC\\;x\\;y & x\\\\\n\\SC\\;f\\;g\\;x & (f x)(g x)\n\\end{array}\\]\nHere, in our description outside of HOL, we use juxtaposition instead\nof the \\#.  Further, juxtaposition is also left-associative, so that\n$\\con{K}\\;x\\;y$ should be read as $\\con{K}\\;\\#\\;x\\;\\#\\;y$ which is in\nturn $(\\con{K}\\;\\#\\;x)\\;\\#\\;y$.\n\nGiven a term in the logic, we want these reductions to be able to fire\nat any point, not just at the top level, so we need two further\ncongruence rules:\\[\n\\begin{array}{l}\n\\infer{x\\;y\\;\\;\\rightarrow\\;\\;x'\\;y}{x\\;\\;\\rightarrow\\;\\;x'}\\\\[5mm]\n\\infer{x\\;y\\;\\;\\rightarrow\\;\\;x\\;y'}{y\\;\\;\\rightarrow\\;\\;y'}\n\\end{array}\\]\nIn HOL, we can capture this relation with an inductive definition.\nFirst we need to set our arrow symbol up as an infix to make everything that\nbit prettier\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"-->\" (Infix(NONASSOC, 450));\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\nWe make our arrow symbol non-associative, thereby making it a\nparse error to write \\verb!x --> y --> z!. It would be nice to be able\nto write this and have it mean \\verb!x --> y /\\ y --> z!, but this is\nnot presently possible with the HOL parser.\n\nOur next step is to actually define the relation with the\n\\ml{xHol\\_reln} function.  In addition to a quotation specifying the\nrules for the new relation, it requires a name to use as the stem for\nthe theorems it proves.  We pick the string \\ml{\"redn\"}.\\footnote{The\n  related function \\ml{Hol\\_reln} can be used if the system's choice\n  of stem is acceptable.  In this case, \\ml{Hol\\_reln} can't cope with the\n  non-alphanumeric characters in \\holtxt{-->} and will raise an\n  error.}\nThe \\ml{xHol\\_reln} function for\ndoing this returns three separate theorems, and we bind the first (the\n``rules'' theorem) and\nthird (the ``cases'' theorem):\n\\begin{session}\n\\begin{alltt}\nval (redn_rules, _, redn_cases) = xHol_reln \"redn\"\n   `(!x y f. x --> y   ==>    f # x --> f # y) /\\bs\n    (!f g x. f --> g   ==>    f # x --> g # x) /\\bs\n    (!x y.   K # x # y --> x) /\\bs\n    (!f g x. S # f # g # x --> (f # x) # (g # x))`;\n> val redn_rules =\n    |- (\\(\\forall\\)x y f. x --> y \\(\\Rightarrow\\) f # x --> f # y) \\(\\land\\)\n       (\\(\\forall\\)f g x. f --> g \\(\\Rightarrow\\) f # x --> g # x) \\(\\land\\)\n       (\\(\\forall\\)x y. K # x # y --> x) \\(\\land\\)\n       \\(\\forall\\)f g x. S # f # g # x --> f # x # (g # x) : thm\n  val redn_cases =\n    |- \\(\\forall\\)a0 a1.\n         a0 --> a1 \\(\\Leftrightarrow\\)\n         (\\(\\exists\\)x y f. (a0 = f # x) \\(\\land\\) (a1 = f # y) \\(\\land\\) x --> y) \\(\\lor\\)\n         (\\(\\exists\\)f g x. (a0 = f # x) \\(\\land\\) (a1 = g # x) \\(\\land\\) f --> g) \\(\\lor\\)\n         (\\(\\exists\\)y. a0 = K # a1 # y) \\(\\lor\\)\n         \\(\\exists\\)f g x. (a0 = S # f # g # x) \\(\\land\\) (a1 = f # x # (g # x))\n    : thm\n\\end{alltt}\n\\end{session}\n\nIn addition to proving these three theorems for us, the inductive\ndefinitions package has also saved them to disk.\n\nNow, using our theorem \\texttt{redn\\_rules} we can demonstrate single\nsteps of our reduction relation:\n\\begin{session}\n\\begin{verbatim}\n- PROVE [redn_rules] ``S # (K # x # x) --> S # x``;\nMeson search level: ...\n> val it = |- S # (K # x # x) --> S # x : thm\n\\end{verbatim}\n\\end{session}\nThe system we have just defined is as powerful as the\n$\\lambda$-calculus, Turing machines, and all the other standard models\nof computation.\n\nOne useful result about the combinatory logic is that it is\n\\emph{confluent}.  Consider the term $\\SC\\;z\\;(\\KC\\;\\KC)\\;(\\KC\\; y\\;\nx)$.  It can make two reductions, to $\\SC\\;z\\;(\\KC\\;\\KC)\\;y$ and also\nto $(z\\;(\\KC\\;y\\;x))\\,(\\KC\\;\\KC\\;(\\KC\\;y\\;x))$.  Do these two choices\nof reduction mean that from this point on the terms have two\ncompletely separate histories?  Roughly speaking, to be confluent\nmeans that the answer to this question is \\emph{no}.\n\n\n\\section{Transitive closure and confluence}\n\\label{sec:Transitive-Clos-Conf}\n\nA notion crucial to that of confluence is that of \\emph{transitive\n  closure}.  We have defined a system that evolves by specifying how\nan algebraic value can evolve into possible successor values in one\nstep.  The natural next question is to ask for a characterisation of\nevolution over one or more steps of the $\\rightarrow$ relation.\n\nIn fact, we will define a relation that holds between two values if\nthe second can be reached from the first in zero or more steps.  This\nis the \\emph{reflexive, transitive closure} of our original relation.\nHowever, rather than tie our new definition to our original relation,\nwe will develop this notion independently and prove a variety of\nresults that are true of any system, not just our system of\ncombinatory logic.\n\nSo, we begin our abstract digression with another inductive\ndefinition.  Our new constant is \\con{RTC}, such that\n$\\con{RTC}\\;R\\;x\\;y$ is true if it is possible to get from $x$ to $y$\nwith zero or more ``steps'' of the $R$ relation.  (The standard\nnotation for $\\con{RTC}\\;R$ is $R^*$.) We can express this idea with\njust two rules.  The first \\[ \\infer{\\con{RTC}\\;R\\;x\\;x}{} \\] says\nthat it's always possible to get from $x$ to $x$ in zero or more\nsteps.  The second \\[\n\\infer{\\con{RTC}\\;R\\;x\\;z}{R\\;x\\;y\\qquad\\con{RTC}\\;R\\;y\\;z}\n\\] says that if you can take a single step from $x$ to $y$, and then\ntake zero or more steps to get $y$ to $z$, then it's possible to take\nzero or more steps to get between $x$ and $z$.  The realisation of\nthese rules in HOL is again straightforward.\n\n(As it happens, \\con{RTC} is already a defined constant in the context\nwe're working in (it is found in \\texttt{relationTheory}), so we'll\nhide it from view before we begin.  We thus avoid messages telling us\nthat we are inputting ambiguous terms.  The ambiguities would always\nbe resolved in the favour of more recent definition, but the warnings\nare annoying.)\n\\begin{session}\n\\begin{alltt}\nval _ = hide \"RTC\";\n\nval (RTC_rules, _, RTC_cases) = Hol_reln `\n    (!x.     RTC R x x) /\\bs\n    (!x y z. R x y /\\bs RTC R y z ==> RTC R x z)`;\n<<HOL message: inventing new type variable names: 'a>>\n> val RTC_rules =\n    |- \\(\\forall\\)R. (\\(\\forall\\)x. RTC R x x) \\(\\land\\)\n           \\(\\forall\\)x y z. R x y \\(\\land\\) RTC R y z \\(\\Rightarrow\\) RTC R x z : thm\n  val RTC_cases =\n    |- \\(\\forall\\)R a0 a1. RTC R a0 a1 \\(\\Leftrightarrow\\) (a1 = a0) \\(\\lor\\)\n                                \\(\\exists\\)y. R a0 y \\(\\land\\) RTC R y a1 : thm\n\\end{alltt}\n\\end{session}\nNow let us go back to the notion of confluence.  We want this to mean\nsomething like: ``though a system may take different paths in the\nshort-term, those two paths can always end up in the same place''.\nThis suggests that we define confluent thus:\n\\begin{session}\n\\begin{verbatim}\n- val confluent_def = Define\n    `confluent R =\n       !x y z. RTC R x y /\\ RTC R x z ==>\n               ?u. RTC R y u /\\ RTC R z u`;\n\\end{verbatim}\n\\end{session}\nThis property states of $R$ that we can ``complete the diamond'';\nif we have\n\\[\\xymatrix @R=5mm @C=2.5mm {\n & x \\ar[dl]_{*} \\ar[dr]^{*} & \\\\\ny & & z }\\]\n\\[\\xymatrix @R=5mm @C=2.5mm {\n& x \\ar[dl]_{*} \\ar[dr]^{*} & \\\\\ny \\ar@{.>}[dr]_{*} & & z \\ar@{.>}[dl]^{*} \\\\\n& u}\\]\n\nOne nice property of confluent relations is that from any one starting\npoint they produce no more than one \\emph{normal form}, where a normal\nform is a value from which no further steps can be taken.\n\\begin{session}\n\\begin{alltt}\n- val normform_def = Define`normform R x = !y. ~(R x y)`;\n<<HOL message: inventing new type variable names: 'a, 'b>>\nDefinition has been stored under \"normform_def\".\n> val normform_def = |- \\(\\forall\\)R x. normform R x \\(\\Leftrightarrow\\) \\(\\forall\\)y. \\(\\neg\\)R x y : thm\n\\end{alltt}\n\\end{session}\nIn other words, a system has an $R$-normal form at $x$ if there are no\nconnections via $R$ to any other values.  (We could have written\n\\verb!~?y. R x y! as our RHS for the definition above.)\n\nWe can now prove the following:\n\\begin{session}\n\\begin{alltt}\n- g `!R. confluent R ==>\n         !x y z.\n           RTC R x y /\\bs normform R y /\\bs\n           RTC R x z /\\bs normform R z ==> (y = z)`;\n<<HOL message: inventing new type variable names: 'a>>\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)R.\n           confluent R \\(\\Rightarrow\\)\n           \\(\\forall\\)x y z. RTC R x y \\(\\land\\) normform R y \\(\\land\\) RTC R x z \\(\\land\\) normform R z \\(\\Rightarrow\\)\n                   (y = z)\n\\end{alltt}\n\\end{session}\nWe rewrite with the definition of confluence:\n\\begin{session}\n\\begin{alltt}\n- e (RW_TAC std_ss [confluent_def]);\nOK..\n1 subgoal:\n> val it =\n    y = z\n    ------------------------------------\n      0.  \\(\\forall\\)x y z. RTC R x y \\(\\land\\) RTC R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n      1.  RTC R x y\n      2.  normform R y\n      3.  RTC R x z\n      4.  normform R z\n\\end{alltt}\n\\end{session}\n    Our confluence property is now assumption 0, and we can use it to\n    infer that there is a $u$ at the base of the diamond:\n\\begin{session}\n\\begin{alltt}\n- e (`?u. RTC R y u /\\bs RTC R z u` by PROVE_TAC []);\nOK..\nMeson search level: .........\n1 subgoal:\n> val it =\n    y = z\n    ------------------------------------\n      0.  \\(\\forall\\)x y z. RTC R x y \\(\\land\\) RTC R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n      1.  RTC R x y\n      2.  normform R y\n      3.  RTC R x z\n      4.  normform R z\n      5.  RTC R y u\n      6.  RTC R z u\n\\end{alltt}\n\\end{session}\n    So, from $y$ we can take zero or more steps to get to $u$ and\n    similarly from $z$.  But, we also know that we're at an $R$-normal\n    form at both $y$ and $z$.  We can't take any steps at all from\n    these values.  We can conclude both that $u = y$ and $u = z$, and\n    this in turn means that $y = z$, which is our goal.  So we can\n    finish with\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [normform_def, RTC_cases]);\nOK..\nMeson search level: ..........\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)R.\n         confluent R \\(\\Rightarrow\\)\n         \\(\\forall\\)x y z.\n           RTC R x y \\(\\land\\) normform R y \\(\\land\\) RTC R x z \\(\\land\\) normform R z \\(\\Rightarrow\\)\n           (y = z)\n\\end{alltt}\n\\end{session}\nPackaged up so as to remove the sub-goal package commands, we can\nprove and save the theorem for future use by:\n\\begin{session}\n\\begin{verbatim}\nval confluent_normforms_unique = store_thm(\n  \"confluent_normforms_unique\",\n  ``!R. confluent R ==>\n        !x y z. RTC R x y /\\ normform R y /\\\n                RTC R x z /\\ normform R z ==> (y = z)``,\n  RW_TAC std_ss [confluent_def] THEN\n  `?u. RTC R y u /\\ RTC R z u` by PROVE_TAC [] THEN\n  PROVE_TAC [normform_def, RTC_cases]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nClearly confluence is a nice property for a system to have.  The\nquestion is how we might manage to prove it.  Let's start by defining\nthe diamond property that we used in the definition of confluence.\n\\begin{session}\n\\begin{alltt}\n- val diamond_def = Define\n    `diamond R = !x y z. R x y /\\bs R x z ==> ?u. R y u /\\bs R z u`;\n<<HOL message: inventing new type variable names: 'a>>\nDefinition has been stored under \"diamond_def\".\n> val diamond_def =\n    |- \\(\\forall\\)R. diamond R \\(\\Leftrightarrow\\) \\(\\forall\\)x y z. R x y \\(\\land\\) R x z \\(\\Rightarrow\\) \\(\\exists\\)u. R y u \\(\\land\\) R z u\n     : thm\n\\end{alltt}\n\\end{session}\n    Now we clearly have that confluence of a relation is equivalent to\n    the reflexive, transitive closure of that relation having the\n    diamond property.\n\\begin{session}\n\\begin{verbatim}\nval confluent_diamond_RTC = store_thm(\n  \"confluent_diamond_RTC\",\n  ``!R. confluent R = diamond (RTC R)``,\n  RW_TAC std_ss [confluent_def, diamond_def]);\n\\end{verbatim}\n\\end{session}\n    So far so good.  How then do we show the diamond property for\n    $\\con{RTC}\\;R$?  The answer that leaps to mind is to hope that if\n    the original relation has the diamond property, then maybe the\n    reflexive and transitive closure will too.  The theorem we want is\n    \\[ \\con{diamond}\\;R \\supset \\con{diamond}\\,(\\con{RTC}\\;R)\\] Graphically,\n    this is hoping that from\n    \\[\\xymatrix @R=5mm @C=2.5mm {\n& x \\ar[dl] \\ar[dr] & \\\\\ny \\ar@{.>}[dr] & & z \\ar@{.>}[dl] \\\\\n& u}\\]\n we will be able to conclude\\[\\xymatrix @R=4mm @C=2mm {\n& & & x \\ar[dl] \\ar[dr] & \\\\\n& & y \\ar@{.>}[dr] \\ar@{-->}[ddll] & & z \\ar@{.>}[dl] \\ar@{-->}[ddrr] \\\\\n& & & u \\\\\np \\ar@{.>}[dddrrr] & & & & & & q \\ar@{.>}[dddlll] \\\\ \\\\ \\\\\n& & & r}\\] where the dashed lines indicate that these steps (from $x$ to $p$,\nfor example) are using $\\con{RTC}\\;R$.  The presence of two instances\nof $\\con{RTC}\\;R$ is an indication that this proof will require two\ninductions.  With the first we will prove\n\\[\\xymatrix @R=4mm @C=2mm {\n& & & x \\ar[dl] \\ar[dr] & \\\\\n& & y \\ar@{.>}[dr] \\ar@{-->}[ddll] & & z \\ar@{.>}[dl] \\\\\n& & & u \\ar@{.>}[ddll] \\\\\np \\ar@{.>}[dr] \\\\\n& r}\\]\nIn other words, we want to show that if we take one step in one\ndirection (to $z$) and many steps in another (to $p$), then the\ndiamond property for $R$ will guarantee us the existence of $r$,\nto which will we be able to take many steps from both $p$ and $z$.\n\nWe take some care to state the goal so that after stripping away the\noutermost assumption (that $R$ has the diamond property), it will match the\ninduction principle for \\con{RTC}.\\footnote{In this and subsequent\n  proofs using the sub-goal package, we will present the proof manager\n  as if the goal to be proved is the first ever on this stack.  In\n  other words, we have done a \\texttt{dropn 1;} after every successful\n  proof to remove the evidence of the old goal.  In practice, there is\n  no harm in leaving these goals on the proof manager's stack.}\n\\begin{session}\n\\begin{alltt}\n- g `!R. diamond R ==>\n         !x p. RTC R x p ==>\n               !z. R x z ==>\n                   ?u. RTC R p u /\\bs RTC R z u`;\n<<HOL message: inventing new type variable names: 'a>>\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)R.\n           diamond R \\(\\Rightarrow\\)\n           \\(\\forall\\)x p. RTC R x p \\(\\Rightarrow\\) \\(\\forall\\)z. R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n\\end{alltt}\n\\end{session}\nFirst, we strip away the diamond property assumption (two things need to\nbe stripped: the outermost universal quantifier and the antecedent of\nthe implication):\n\\begin{session}\n\\begin{alltt}\n- e (GEN_TAC THEN STRIP_TAC);\nOK..\n1 subgoal:\n> val it =\n    \\(\\forall\\)x p. RTC R x p \\(\\Rightarrow\\) \\(\\forall\\)z. R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n    ------------------------------------\n      diamond R\n\\end{alltt}\n\\end{session}\nNow we can use the induction principle for reflexive and transitive closure (alternatively, we perform a ``rule induction'').\nTo do this, we use the \\ml{Induct\\_on} command that is also used to do\nstructural induction on algebraic data types (such as numbers and\nlists).\nWe provide the name of the constant whose induction principle we want\nto use, and the tactic does the rest:\n\\begin{session}\n\\begin{alltt}\n- e (Induct_on `RTC`);\nOK..\n1 subgoal:\n> val it =\n    (\\(\\forall\\)x z. R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R x u \\(\\land\\) RTC R z u) \\(\\land\\)\n    \\(\\forall\\)x x' p.\n      R x x' \\(\\land\\) RTC R x' p \\(\\land\\) (\\(\\forall\\)z. R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u) \\(\\Rightarrow\\)\n      \\(\\forall\\)z. R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n    ------------------------------------\n      diamond R\n\\end{alltt}\n\\end{session}\nLet's strip the goal as much as possible with the aim of making what\nremains to be proved easier to see:\n\\begin{session}\n\\begin{alltt}\n- e (REPEAT STRIP_TAC);\nOK..\n2 subgoals:\n> val it =\n    \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' p\n      3.  \\(\\forall\\)z. R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n      4.  R x z\n\n    \\(\\exists\\)u. RTC R x u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x z\n\\end{alltt}\n\\end{session}\nThis first goal is easy.  It corresponds to the case where the many\nsteps from $x$ to $p$ are actually no steps at all, and $p$ and $x$\nare actually the same place.  In the other direction, $x$ has taken\none step to $z$, and we need to find somewhere reachable in zero or\nmore steps from both $x$ and $z$.  Given what we know so far, the only\ncandidate is $z$ itself.  In fact, we don't even need to provide this\nwitness explicitly. \\texttt{PROVE\\_TAC} will find it for us, as long\nas we tell it what the rules governing \\con{RTC} are:\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [RTC_rules]);\nOK..\nMeson search level: .....\n\nGoal proved. [..] |- \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\nRemaining subgoals:\n> val it =\n    \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' p\n      3.  \\(\\forall\\)z. R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n      4.  R x z\n\\end{alltt}\n\\end{session}\n    And what of this remaining goal?  Assumptions one and four\n    between them are the top of an $R$-diamond.  Let's use the fact\n    that we have the diamond property for $R$ and infer that there\n    exists a $v$ to which $y$ and $z'$ can both take single steps:\n\\begin{session}\n\\begin{alltt}\n- e (`?v. R x' v /\\bs R z v` by PROVE_TAC [diamond_def]);\nOK..\nMeson search level: ............\n1 subgoal:\n> val it =\n    \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' p\n      3.  \\(\\forall\\)z. R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n      4.  R x z\n      5.  R x' v\n      6.  R z v\n\\end{alltt}\n\\end{session}\nNow we can apply our induction hypothesis (assumption 3) to complete\nthe long, lop-sided strip of the diamond.  We will conclude that there\nis a $u$ such that $\\con{RTC}\\;R\\;p\\;u$ and $\\con{RTC}\\;R\\;v\\;u$.  We\nactually need a $u$ such that $\\con{RTC}\\;R\\;z\\;u$, but because there\nis a single $R$-step between $z$ and $v$ we have that as well.  All\nwe need to provide \\texttt{PROVE\\_TAC} is the rules for \\con{RTC}:\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [RTC_rules]);\nOK..\nMeson search level: .......\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)R.\n         diamond R \\(\\Rightarrow\\)\n         \\(\\forall\\)x p. RTC R x p \\(\\Rightarrow\\) \\(\\forall\\)z. R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R p u \\(\\land\\) RTC R z u\n\\end{alltt}\n\\end{session}\n    Again we can (and should) package up the lemma, avoiding the\n    sub-goal package commands:\n\\begin{session}\n\\begin{verbatim}\nval R_RTC_diamond = store_thm(\n  \"R_RTC_diamond\",\n  ``!R. diamond R ==>\n         !x p. RTC R x p ==>\n               !z. R x z ==>\n                   ?u. RTC R p u /\\ RTC R z u``,\n  GEN_TAC THEN STRIP_TAC THEN Induct_on `RTC` THEN\n  REPEAT STRIP_TAC THENL [\n    PROVE_TAC [RTC_rules],\n    `?v. R x' v /\\ R z v` by PROVE_TAC [diamond_def] THEN\n    PROVE_TAC [RTC_rules]\n  ]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nNow we can move on to proving that if $R$ has the diamond property, so\ntoo does $\\con{RTC}\\;R$.  We want to prove this by induction again.\nIt's very tempting to state the goal as the obvious \\[\n\\con{diamond}\\;R\\supset\\con{diamond}\\,(\\con{RTC}\\;R)\n\\] but doing so will actually make it harder to apply the induction\nprinciple when the time is right.  Better to start out with a\nstatement of the goal that is very near in form to the induction\nprincple.  So, we manually expand the meaning of \\con{diamond} and state\nour next goal thus:\n\\begin{session}\n\\begin{alltt}\n- g `!R. diamond R ==> !x y. RTC R x y ==>\n                             !z. RTC R x z ==>\n                                 ?u. RTC R y u /\\bs RTC R z u`;\n<<HOL message: inventing new type variable names: 'a>>\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)R.\n           diamond R \\(\\Rightarrow\\)\n           \\(\\forall\\)x y. RTC R x y \\(\\Rightarrow\\) \\(\\forall\\)z. RTC R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n\\end{alltt}\n\\end{session}\n    Again we strip the diamond property assumption, apply the\n    induction principle, and strip repeatedly:\n\\begin{session}\n\\begin{alltt}\n- e (GEN_TAC THEN STRIP_TAC THEN Induct_on `RTC` THEN REPEAT STRIP_TAC);\nOK..\n2 subgoals:\n> val it =\n    \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' y\n      3.  \\(\\forall\\)z. RTC R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n      4.  RTC R x z\n\n    \\(\\exists\\)u. RTC R x u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  RTC R x z\n\\end{alltt}\n\\end{session}\nThe first goal is again an easy one, corresponding to the case where\nthe trip from $x$ to $y$ has been one of no steps whatsoever.\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [RTC_rules]);\nOK..\nMeson search level: ...\n\nGoal proved. [...]\n\nRemaining subgoals:\n> val it =\n    \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' y\n      3.  \\(\\forall\\)z. RTC R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n      4.  RTC R x z\n\\end{alltt}\n\\end{session}\nThis goal is very similar to the one we saw earlier.  We have the top\nof a (``lop-sided'') diamond in assumptions 1 and 4, so we can infer\nthe existence of a common destination for $x'$ and $z$:\n\\begin{session}\n\\begin{alltt}\n- e (`?v. RTC R x' v /\\bs RTC R z v` by PROVE_TAC [R_RTC_diamond]);\nOK..\nMeson search level: ............\n1 subgoal:\n> val it =\n    \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n    ------------------------------------\n      0.  diamond R\n      1.  R x x'\n      2.  RTC R x' y\n      3.  \\(\\forall\\)z. RTC R x' z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n      4.  RTC R x z\n      5.  RTC R x' v\n      6.  RTC R z v\n\\end{alltt}\n\\end{session}\n    At this point in the last proof we were able to finish it all off\n    by just appealing to the rules for \\con{RTC}.  This time it is not\n    quite so straightforward.  When we use the induction hypothesis\n    (assumption 3), we can conclude that there is a $u$ to which both\n    $y$ and $v$ can connect in zero or more steps, but in order to\n    show that this $u$ is reachable from $z$, we need to be able to\n    conclude $\\con{RTC}\\;R\\;z\\;u$ when we know that\n    $\\con{RTC}\\;R\\;z\\;v$ (assumption 6 above) and\n    $\\con{RTC}\\;R\\;v\\;u$ (our consequence of the inductive\n    hypothesis).  We leave the proof of this general result as an\n    exercise, and here assume that it is already proved as the theorem\n    \\texttt{RTC\\_RTC}.\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [RTC_rules, RTC_RTC]);\nMeson search level: .......\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)R.\n         diamond R \\(\\Rightarrow\\)\n         \\(\\forall\\)x y. RTC R x y \\(\\Rightarrow\\) \\(\\forall\\)z. RTC R x z \\(\\Rightarrow\\) \\(\\exists\\)u. RTC R y u \\(\\land\\) RTC R z u\n\\end{alltt}\n\\end{session}\nWe can package this result up as a lemma and then prove the prettier\nversion directly:\n\\begin{session}\n\\begin{verbatim}\nval diamond_RTC_lemma = prove(\n  ``!R.\n       diamond R ==>\n       !x y. RTC R x y ==> !z. RTC R x z ==> ?u. RTC R y u /\\ RTC R z u``,\n  GEN_TAC THEN STRIP_TAC THEN Induct_on `RTC` THEN\n  REPEAT STRIP_TAC THENL [\n    PROVE_TAC [RTC_rules],\n    `?v. RTC R x' v /\\ RTC R z v` by PROVE_TAC [R_RTC_diamond] THEN\n    PROVE_TAC [RTC_RTC, RTC_rules]\n  ]);\nval diamond_RTC = store_thm(\n  \"diamond_RTC\",\n  ``!R. diamond R ==> diamond (RTC R)``,\n  PROVE_TAC [diamond_def,diamond_RTC_lemma]);\n\\end{verbatim}\n\\end{session}\n\n\\section{Back to combinators}\n\\label{sec:Return-to-Land}\n\nNow, we are in a position to return to the real object of study and\nprove confluence for combinatory logic.  We have done an abstract\ndevelopment and established that\\[\n\\begin{array}{ccccc}\n\\con{diamond}\\;R & \\supset & \\con{diamond}\\,(\\con{RTC}\\;R)\\\\\n& & \\land\\\\\n& & \\con{diamond}\\,(\\con{RTC}\\;R) & \\equiv & \\con{confluent}\\;R\\\\\n\\end{array}\n\\]  (We have also established a couple of other useful results along\nthe way.)\n\n\\newcommand{\\topk}{\\KC\\;\\SC\\;(\\KC\\;\\KC\\;\\KC)} Sadly, it just isn't the\ncase that $\\rightarrow$, our one-step relation for combinators, has\nthe diamond property.  A counter-example is $\\topk$.  Its possible evolution\ncan be described graphically: \\[\\xymatrix @R=5mm @C=2.5mm {\n& \\topk \\ar[dl] \\ar[dr] & \\\\\n\\SC & & \\KC\\;\\SC\\;\\KC \\ar[dl] \\\\\n& \\SC}\\]\nIf we had the diamond property, it should be possible to find a common\ndestination for $\\KC\\;\\SC\\;\\KC$ and $\\SC$.  However, \\SC{} doesn't\nadmit any reductions whatsoever, so there isn't a common\ndestination.\\footnote{In fact our counter-example is more complicated\n  than necessary.  The fact that $\\KC\\;\\SC\\;\\KC$ has a\n  reduction to the normal form $\\SC$ also acts as a counter-example.\n  Can you see why?}\n\nThis is a problem.  We are going to have to take another approach.\nWe will define another reduction strategy (\\emph{parallel reduction}),\nand prove that its reflexive, transitive closure is actually the same\nrelation as our original's reflexive and transitive closure.  Then we\nwill also show that parallel reduction has the diamond property.  This\nwill establish that its reflexive, transitive closure has it too.\nThen, because they are the same relation, we will have that the\nreflexive, transitive closure of our original relation has the diamond\nproperty, and therefore, our original relation will be confluent.\n\n\\subsection{Parallel reduction}\n\\label{sec:Parallel-Reduction}\n\nOur new relation allows for any number of reductions to occur in\nparallel.  We use the \\texttt{-||->} symbol to indicate parallel\nreduction because of its own parallel lines:\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"-||->\" (Infix(NONASSOC, 450));\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\n    Then we can define parallel reduction itself.  The rules look very\n    similar to those for $\\rightarrow$.  The difference is that we\n    allow the reflexive transition, and say that an application of\n    $x\\;u$ can be transformed to $y\\;v$ if there are transformations\n    taking $x$ to $y$ and $u$ to $v$.  This is why we must have\n    reflexivity incidentally.  Without it, a term like\n    $(\\KC\\;x\\;y)\\,\\KC$ couldn't reduce because while the LHS of the\n    application ($\\KC\\;x\\;y$) can reduce, its RHS (\\KC) can't.\n\\begin{session}\n\\begin{alltt}\n- val (predn_rules, _, predn_cases) = xHol_reln \"predn\"\n      `(!x. x -||-> x) /\\bs\n       (!x y u v. x -||-> y /\\bs u -||-> v\n                         ==>\n                  x # u -||-> y # v) /\\bs\n       (!x y. K # x # y -||-> x) /\\bs\n       (!f g x. S # f # g # x -||-> (f # x) # (g # x))`;\n> val predn_rules =\n    |- (\\(\\forall\\)x. x -||-> x) \\(\\land\\)\n       (\\(\\forall\\)x y u v. x -||-> y \\(\\land\\) u -||-> v \\(\\Rightarrow\\) x # u -||-> y # v) \\(\\land\\)\n       (\\(\\forall\\)x y. K # x # y -||-> x) \\(\\land\\)\n       \\(\\forall\\)f g x. S # f # g # x -||-> f # x # (g # x) : thm\n  val predn_cases =\n    |- \\(\\forall\\)a0 a1.\n         a0 -||-> a1 \\(\\Leftrightarrow\\)\n         (a1 = a0) \\(\\lor\\)\n         (\\(\\exists\\)x y u v. (a0 = x # u) \\(\\land\\) (a1 = y # v) \\(\\land\\)\n                    x -||-> y \\(\\land\\) u -||-> v) \\(\\lor\\)\n         (\\(\\exists\\)y. a0 = K # a1 # y) \\(\\lor\\)\n         \\(\\exists\\)f g x. (a0 = S # f # g # x) \\(\\land\\) (a1 = f # x # (g # x))\n    : thm\n\\end{alltt}\n\\end{session}\n\n\\subsection{Using \\con{RTC}}\n\\label{sec:Using-RTC}\n\nNow we can set up nice syntax for the reflexive and transitive\nclosures of our two relations.  We will use ASCII symbols for both\nthat consist of the original symbol followed by an asterisk.  Note\nalso how, in defining the two relations, we have to use the\n\\texttt{\\$} character to ``escape'' the symbols' usual fixities.  This\nis exactly analogous to the way in which ML's \\texttt{op} keyword is\nused.  First, we create the desired symbol for the concrete syntax,\nand then we ``overload'' it so that the parser will expand it to the\ndesired form.\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"-->*\" (Infix(NONASSOC, 450));\n> val it = () : unit\n\n- overload_on (\"-->*\", ``RTC $-->``);\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\nWe do exactly the same thing for the reflexive and transitive closure\nof our parallel reduction.\n\\begin{session}\n\\begin{verbatim}\n- set_fixity \"-||->*\" (Infix(NONASSOC, 450));\n> val it = () : unit\n\n- overload_on (\"-||->*\", ``RTC $-||->``);\n> val it = () : unit\n\\end{verbatim}\n\\end{session}\nIncidentally, in conjunction with \\texttt{PROVE} we can now\nautomatically demonstrate relatively long chains of reductions:\n\\begin{session}\n\\begin{verbatim}\n- PROVE [RTC_rules, redn_rules] ``S # K # K # x -->* x``;\nMeson search level: ......\n> val it = |- S # K # K # x -->* x : thm\n\n- PROVE [RTC_rules, redn_rules]\n    ``S # (S # (K # S) # K) # (S # K # K) # f # x -->*\n      f # (f # x)``;\nMeson search level: ...........................\n> val it = |- S # (S # (K # S) # K) # (S # K # K) # f # x -->* f # (f # x)\n           : thm\n\\end{verbatim}\n\\end{session}\n(The latter sequence is seven reductions long.)\n\n\n\\subsection{Proving the \\con{RTC}s are the same}\n\\label{sec:Proving-RTCs-same}\n\nWe start with the easier direction, and show that everything in\n$\\rightarrow^*$ is in $\\mathpredn^*$.  Because\n\\con{RTC} is monotone (which fact is left to the reader to prove),\nwe can reduce this to showing that $x\\rightarrow y\\supset x\\mathpredn y$.\n\nOur goal:\n\\begin{session}\n\\begin{alltt}\n- g `!x y. x -->* y ==> x -||->* y`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)x y. x -->* y \\(\\Rightarrow\\) x -||->* y\n\\end{alltt}\n\\end{session}\nWe back-chain using our monotonicity result:\n\\begin{session}\n\\begin{alltt}\n- e (MATCH_MP_TAC RTC_monotone);\nOK..\n1 subgoal:\n> val it =\n    \\(\\forall\\)x y. x --> y \\(\\Rightarrow\\) x -||-> y\n\\end{alltt}\n\\end{session}\nNow we can induct over the rules for $\\rightarrow$:\n\\begin{session}\n\\begin{alltt}\n- e (Induct_on `$-->`);\nOK..\n1 subgoal:\n> val it =\n    (\\(\\forall\\)x y f. x --> y \\(\\land\\) x -||-> y \\(\\Rightarrow\\) f # x -||-> f # y) \\(\\land\\)\n    (\\(\\forall\\)f g x. f --> g \\(\\land\\) f -||-> g \\(\\Rightarrow\\) f # x -||-> g # x) \\(\\land\\)\n    (\\(\\forall\\)x y. K # x # y -||-> x) \\(\\land\\)\n    \\(\\forall\\)f g x. S # f # g # x -||-> f # x # (g # x)\n\\end{alltt}\n\\end{session}\nWe could split the 4-way conjunction apart into four goals, but there\nis no real need.  It is quite clear that each follows immediately from\nthe rules for parallel reduction.\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [predn_rules]);\nOK..\nMeson search level: ............\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)x y. x -->* y \\(\\Rightarrow\\) x -||->* y : goalstack\n\\end{alltt}\n\\end{session}\nPackaged into a tidy little sub-goal-package-free parcel, our proof is\n\\begin{session}\n\\begin{verbatim}\nval RTCredn_RTCpredn = store_thm(\n  \"RTCredn_RTCpredn\",\n  ``!x y. x -->* y   ==>   x -||->* y``,\n  MATCH_MP_TAC RTC_monotone THEN\n  Induct_on `$-->` THEN PROVE_TAC [predn_rules]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nOur next proof is in the other direction.  It should be clear that we\nwill not just be able to appeal to the monotonicity of \\con{RTC} this\ntime; one step of the parallel reduction relation can not be mirrored\nwith one step of the original reduction relation.  It's clear that\nmirroring one step of the parallel reduction relation might take many\nsteps of the original relation.  Let's prove that then:\n\\begin{session}\n\\begin{alltt}\n- g `!x y. x -||-> y   ==>   x -->* y`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)x y. x -||-> y \\(\\Rightarrow\\) x -->* y\n\\end{alltt}\n\\end{session}\nThis time our induction will be over the rules defining the parallel\nreduction relation.\n\\begin{session}\n\\begin{alltt}\n- e (Induct_on `$-||->`);\nOK..\n1 subgoal:\n> val it =\n    (\\(\\forall\\)x. x -->* x) \\(\\land\\)\n    (\\(\\forall\\)x y x' y'. x -||-> y \\(\\land\\) x -->* y \\(\\land\\) x' -||-> y' \\(\\land\\) x' -->* y' \\(\\Rightarrow\\)\n                 x # x' -->* y # y') \\(\\land\\)\n    (\\(\\forall\\)x y. K # x # y -->* x) \\(\\land\\)\n    \\(\\forall\\)f g x. S # f # g # x -->* f # x # (g # x)\n\\end{alltt}\n\\end{session}\n    There are four conjuncts here, and it should be clear that all but\n    the second can be proved immediately by appeal to the rules for\n    the transitive closure and for $\\rightarrow$ itself.  We could\n    split apart the conjunctions and enter a \\texttt{THENL} branch.\n    However, we'd need to repeat the same tactic three times to\n    quickly close three of the four branches.  Instead, we use the\n    \\texttt{TRY} tactical to try applying the same tactic to all four\n    branches.  If our tactic fails on branch \\#2, as we expect,\n    \\texttt{TRY} will protect us against this failure and let us\n    proceed.\n\\begin{session}\n\\begin{alltt}\ne (REPEAT CONJ_TAC THEN\n   TRY (PROVE_TAC [RTC_rules, redn_rules]));\nOK..\nMeson search level: ....\nMeson search level: ....\nMeson search level: ...............................\nMeson search level: ..\n1 subgoal:\n> val it =\n    \\(\\forall\\)x y x' y'. x -||-> y \\(\\land\\) x -->* y \\(\\land\\) x' -||-> y' \\(\\land\\) x' -->* y' \\(\\Rightarrow\\)\n                x # x' -->* y # y'\n\\end{alltt}\n\\end{session}\n    Note that wrapping \\texttt{TRY} around \\texttt{PROVE\\_TAC} is not\n    always wise.  It can often take the \\texttt{PROVE\\_TAC} tactic an extremely\n    long time to exhaust its search space, and then give up with a\n    failure.  Here, ``we got lucky''.\n\n    Anyway, what of this latest sub-goal?  If we look at it for long\n    enough, we should see that it is another monotonicity fact.  More\n    accurately, we need what is called a \\emph{congruence} result for\n    \\holtxt{-->*}.  In this form, it's not quite right for easy proof.\n    Let's go away and prove \\texttt{RTCredn\\_ap\\_monotonic}\n    separately. (Another exercise!)  Our new theorem should state\n\\begin{session}\n\\begin{verbatim}\nval RTCredn_ap_congruence = store_thm(\n  \"RTCredn_ap_congruence\",\n  ``!x y. x -->* y ==> !z. x # z -->* y # z /\\ z # x -->* z # y``,\n  ...);\n\\end{verbatim}\n\\end{session}\n    Now that we have this, our sub-goal is almost immediately\n    provable.  Using it, we know that \\[\\begin{array}{c}\n      x\\;x' \\rightarrow^* y\\;x' \\\\\n      y\\;x' \\rightarrow^* y\\;y'\n    \\end{array}\\]\n    All we need to do is ``stitch together'' the two transitions above\n    and go from $x\\;x'$ to $y\\;y'$.  We can do this by appealing to our\n    earlier \\texttt{RTC\\_RTC} result.\n\\begin{session}\n\\begin{alltt}\ne (PROVE_TAC [RTC_RTC, RTCredn_ap_congruence]);\nOK..\nMeson search level: .......\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)x y. x -||-> y \\(\\Rightarrow\\) x -->* y : goalstack\n\\end{alltt}\n\\end{session}\nBut given that we can finish off what we thought was an awkward branch\nwith just another application of \\texttt{PROVE\\_TAC}, we don't need to\nuse our fancy \\texttt{TRY}-footwork at the stage before.  Instead, we\ncan just merge the theorem lists passed to both invocations, dispense\nwith the \\texttt{REPEAT CONJ\\_TAC} and have a very short tactic proof\nindeed:\n\\begin{session}\n\\begin{verbatim}\nval predn_RTCredn = store_thm(\n  \"predn_RTCredn\",\n  ``!x y. x -||-> y  ==>  x -->* y``,\n  Induct_on `$-||->` THEN\n  PROVE_TAC [RTC_rules, redn_rules, RTC_RTC, RTCredn_ap_congruence]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nNow it's time to prove that if a number of parallel reduction steps\nare chained together, then we can mirror this with some number of\nsteps using the original reduction relation.  Our goal:\n\\begin{session}\n\\begin{alltt}\n- g `!x y. x -||->* y  ==> x -->* y`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)x y. x -||->* y \\(\\Rightarrow\\) x -->* y\n\\end{alltt}\n\\end{session}\nWe use the appropriate induction principle to get to:\n\\begin{session}\n\\begin{alltt}\n- e (Induct_on `RTC`);\nOK..\n1 subgoal:\n> val it =\n    (\\(\\forall\\)x. x -->* x) \\(\\land\\)\n    \\(\\forall\\)x x' y. x -||-> x' \\(\\land\\) x' -||-> y* \\(\\land\\) x' -->* y \\(\\Rightarrow\\) x -->* z\n\\end{alltt}\n\\end{session}\nThis we can finish off in one step.  The first conjunct is obvious,\nand in the second the \\verb!x -||-> y! and our last result combine to\ntell us that \\verb!x -->* y!.  Then this can be chained together with\nthe other assumption in the second conjunct and we're done.\n\\begin{session}\n\\begin{alltt}\n- e (PROVE_TAC [RTC_rules, predn_RTCredn, RTC_RTC]);\nOK..\nMeson search level: .......\n\nGoal proved.[...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)x y. x -||->* y \\(\\Rightarrow\\) x -->* y : proof\n\\end{alltt}\n\\end{session}\nPackaged up, this proof is:\n\\begin{session}\n\\begin{verbatim}\nval RTCpredn_RTCredn = store_thm(\n  \"RTCpredn_RTCredn\",\n  ``!x y. x -||->* y   ==>  x -->* y``,\n  Induct_on `RTC` THEN PROVE_TAC [predn_RTCredn, RTC_RTC, RTC_rules]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nOur final act is to use what we have so far to conclude that\n$\\rightarrow^*$ and $\\mathpredn^*$ are equal.  We state our goal:\n\\begin{session}\n\\begin{verbatim}\n- g `$-||->* = $-->*`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         $-||->* = $-->*\n\\end{verbatim}\n\\end{session}\nWe want to now appeal to extensionality.  The simplest way to do this\nis to rewrite with the theorem \\texttt{FUN\\_EQ\\_THM}:\n\\begin{session}\n\\begin{alltt}\n- FUN_EQ_THM;\n> val it = |- \\(\\forall\\)f g. (f = g) \\(\\Leftrightarrow\\) \\(\\forall\\)x. f x = g x : thm\n\\end{alltt}\n\\end{session}\nSo, we rewrite:\n\\begin{session}\n\\begin{alltt}\n- e (SIMP_TAC std_ss [FUN_EQ_THM]);\nOK..\n1 subgoal:\n> val it =\n    \\(\\forall\\)x x'. x -||->* x' = x -->* x'\n\\end{alltt}\n\\end{session}\n\nThis goal is an easy consequence of our two earlier implications.\n\\begin{session}\n\\begin{verbatim}\n- e (PROVE_TAC [RTCpredn_RTCredn, RTCredn_RTCpredn]);\nOK..\nMeson search level: ......\n\nGoal proved. [...]\n> val it =\n    Initial goal proved.\n    |- $-||->* = $-->* : goalstack\n\\end{verbatim}\n\\end{session}\nPackaged, the proof is:\n\\begin{session}\n\\begin{verbatim}\nval RTCpredn_EQ_RTCredn = store_thm(\n  \"RTCpredn_EQ_RTCredn\",\n  ``$-||->* = $-->*``,\n  SIMP_TAC std_ss [FUN_EQ_THM] THEN\n  PROVE_TAC [RTCpredn_RTCredn, RTCredn_RTCpredn]);\n\\end{verbatim}\n\\end{session}\n\n\n\\subsection{Proving a diamond property for parallel reduction}\n\\label{sec:predn-diamond}\n\nNow we just have one substantial proof to go.  Before we can even\nbegin, there are a number of minor lemmas we will need to prove first.\nThese are basically specialisations of the theorem\n\\texttt{predn\\_cases}.  We want exhaustive characterisations of the\npossibilities when the following terms undergo a parallel reduction:\n$x\\;y$, \\KC, \\SC, $\\KC\\;x$, $\\SC\\;x$, $\\KC\\;x\\;y$, $\\SC\\;x\\;y$ and\n$\\SC\\;x\\;y\\;z$.\n\nTo do this, we will write a little function that derives\ncharacterisations automatically:\n\\begin{session}\n\\begin{verbatim}\n- fun characterise t = SIMP_RULE (srw_ss()) [] (SPEC t predn_cases);\n> val characterise = fn : term -> thm\n\\end{verbatim}\n\\end{session}\nThe \\ml{characterise} function specialises the theorem\n\\ml{predn\\_cases} with the input term, and then simplifies.  The\n\\ml{srw\\_ss()} simpset includes information about the injectivity and\ndisjointness of constructors and eliminates obvious impossibilities.\nFor example,\n\\begin{session}\n\\begin{alltt}\n- val K_predn = characterise ``K``;\n<<HOL message: more than one resolution of overloading was possible>>\n> val K_predn = |- \\(\\forall\\)a1. K -||-> a1 = (a1 = K) : thm\n\n- val S_predn = characterise ``S``;\n<<HOL message: more than one resolution of overloading was possible>>\n> val S_predn = |- \\(\\forall\\)a1. S -||-> a1 = (a1 = S) : thm\n\\end{alltt}\n\\end{session}\nUnfortunately, what we get back from other inputs is not so good:\n\\begin{session}\n\\begin{alltt}\n- val Sx_predn0 = characterise ``S # x``;\n> val Sx_predn0 =\n    |- \\(\\forall\\)a1.\n         S # x -||-> a1 =\n         (a1 = S # x) \\(\\lor\\)\n         \\(\\exists\\)y v. (a1 = y # v) \\(\\land\\) S -||-> y \\(\\land\\) x -||-> v : thm\n\\end{alltt}\n\\end{session}\nThat first disjunct is redundant, as the following demonstrates:\n\\begin{session}\n\\begin{verbatim}\nval Sx_predn = prove(\n  ``!x y. S # x -||-> y = ?z. (y = S # z) /\\ (x -||-> z)``,\n  REPEAT GEN_TAC THEN EQ_TAC THEN\n  RW_TAC std_ss [Sx_predn0, predn_rules, S_predn]);\n\\end{verbatim}\n\\end{session}\nOur \\texttt{characterise} function will just have to help us in the\nproofs that follow.\n\\begin{session}\n\\begin{verbatim}\nval Kx_predn = prove(\n  ``!x y. K # x -||-> y = ?z. (y = K # z) /\\ (x -||-> z)``,\n  REPEAT GEN_TAC THEN EQ_TAC THEN\n  RW_TAC std_ss [characterise ``K # x``, predn_rules, K_predn]);\n\\end{verbatim}\n\\end{session}\nWhat of $\\KC\\;x\\;y$?  A little thought demonstrates that there really\nmust be two cases this time.\n\\begin{session}\n\\begin{verbatim}\nval Kxy_predn = prove(\n  ``!x y z.\n       K # x # y -||-> z =\n       (?u v. (z = K # u # v) /\\ (x -||-> u) /\\ (y -||-> v)) \\/\n       (z = x)``,\n  REPEAT GEN_TAC THEN EQ_TAC THEN\n  RW_TAC std_ss [characterise ``K # x # y``, predn_rules,\n                 Kx_predn]);\n\\end{verbatim}\n\\end{session}\nBy way of contrast, there is only one case for $\\SC\\;x\\;y$ because it\nis not yet a ``redex'' at the top-level.\n\\begin{session}\n\\begin{verbatim}\nval Sxy_predn = prove(\n  ``!x y z. S # x # y -||-> z =\n            ?u v. (z = S # u # v) /\\ (x -||-> u) /\\ (y -||-> v)``,\n  REPEAT GEN_TAC THEN EQ_TAC THEN\n  RW_TAC std_ss [characterise ``S # x # y``, predn_rules,\n                 Sx_predn]);\n\\end{verbatim}\n\\end{session}\nNext, the characterisation for $\\SC\\;x\\;y\\;z$:\n\\begin{session}\n\\begin{verbatim}\nval Sxyz_predn = prove(\n  ``!w x y z. S # w # x # y -||-> z =\n              (?p q r. (z = S # p # q # r) /\\\n                       w -||-> p /\\ x -||-> q /\\ y -||-> r) \\/\n              (z = (w # y) # (x # y))``,\n  REPEAT GEN_TAC THEN EQ_TAC THEN\n  RW_TAC std_ss [characterise ``S # w # x # y``, predn_rules,\n                 Sxy_predn]);\n\\end{verbatim}\n\\end{session}\nLast of all, we want a characterisation for $x\\;y$.   What\n\\texttt{characterise} gives us this time can't be improved upon,\nfor all that we might look upon the four disjunctions and despair.\n\\begin{session}\n\\begin{alltt}\n- val x_ap_y_predn = characterise ``x # y``;\n> val x_ap_y_predn =\n    |- \\(\\forall\\)a1.\n         x # y -||-> a1 =\n         (a1 = x # y) \\(\\lor\\)\n         (\\(\\exists\\)y' v. (a1 = y' # v) \\(\\land\\) x -||-> y' \\(\\land\\) y -||-> v) \\(\\lor\\)\n         (x = K # a1) \\(\\lor\\)\n         \\(\\exists\\)f g. (x = S # f # g) \\(\\land\\) (a1 = f # y # (g # y)) : thm\n\\end{alltt}\n\\end{session}\n\\eos{}\n\n\\noindent Now we are ready to prove the final goal.  It is\n\\begin{session}\n\\begin{alltt}\n- g `!x y. x -||-> y ==>\n           !z. x -||-> z ==> ?u. y -||-> u /\\bs z -||-> u`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         \\(\\forall\\)x y. x -||-> y \\(\\Rightarrow\\) \\(\\forall\\)z. x -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nWe now induct and split the goal into its individual conjuncts:\n\\begin{session}\n\\begin{alltt}\n- e (Induct_on `$-||->` THEN REPEAT CONJ_TAC);\nOK..\n4 subgoals:\n> val it =\n    \\(\\forall\\)f g x z. S # f # g # x -||-> z \\(\\Rightarrow\\)\n              \\(\\exists\\)u. f # x # (g # x) -||-> u \\(\\land\\) z -||-> u\n\n\n    \\(\\forall\\)x y z. K # x # y -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. x -||-> u \\(\\land\\) z -||-> u\n\n\n    \\(\\forall\\)x y u v.\n      x -||-> y \\(\\land\\)\n      (\\(\\forall\\)z. x -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u) \\(\\land\\)\n      u -||-> v \\(\\land\\)\n      (\\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u) \\(\\Rightarrow\\)\n      \\(\\forall\\)z. x # u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y # v -||-> u \\(\\land\\) z -||-> u\n\n\n    \\(\\forall\\)x z. x -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. x -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nThe first goal is easily disposed of.  The witness we would provide\nfor this case is simply \\texttt{z}, but \\texttt{PROVE\\_TAC} will do\nthe work for us:\n\\begin{session}\n\\begin{verbatim}\n- e (PROVE_TAC [predn_rules]);\nOK..\nMeson search level: ...\n\nGoal proved. [...]\n\\end{verbatim}\n\\end{session}\n    The next goal includes two instances of terms of the form\n    \\verb!x # y -||-> z!.  We can use our \\verb!x_ap_y_predn!\n    theorem here.  However, if we rewrite indiscriminately with it, we\n    will really confuse the goal.  We want to rewrite just the\n    assumption, not the instance underneath the existential\n    quantifier.  Starting everything by repeatedly stripping can't\n    lead us too far astray.\n\\begin{session}\n\\begin{alltt}\n- e (REPEAT STRIP_TAC);\nOK..\n1 subgoal:\n> val it =\n    \\(\\exists\\)u. y # v -||-> u \\(\\land\\) z -||-> u\n    ------------------------------------\n      0.  x -||-> y\n      1.  \\(\\forall\\)z. x -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u\n      2.  u -||-> v\n      3.  \\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u\n      4.  x # u -||-> z\n\\end{alltt}\n\\end{session}\nWe need to split up assumption 4.  We can get it out of the assumption\nlist using the \\texttt{Q.PAT\\_ASSUM} theorem-tactical.  We will write\n\\begin{verbatim}\n    Q.PAT_ASSUM `x # y -||-> z`\n      (STRIP_ASSUME_TAC o SIMP_RULE std_ss [x_ap_y_predn])\n\\end{verbatim}\nThe quotation specifies the pattern that we want to match.  The second\nargument specifies how we are going to transform the theorem.  Reading\nthe compositions from right to left, first we will simplify with the\n\\verb!x_ap_y_predn! theorem and then we will assume the result back\ninto the assumptions, stripping disjunctions and existentials as we\ngo.\\footnote{An alternative to using \\texttt{PAT\\_ASSUM} is to use\n  \\texttt{by} instead: you would have to state the four-way\n  disjunction yourself, but the proof would be more ``declarative'' in\n  style, and though wordier, might be more maintainable.}\n\nWe already know that doing this is going to produce four new sub-goals\n(there were four disjuncts in the \\verb!x_ap_y_predn! theorem).  At\nleast one of these should be trivial because it will correspond to the\ncase when the parallel reduction is just a ``do nothing'' step.  Let's\ntry eliminating the simple cases with a ``speculative'' call to\n\\texttt{PROVE\\_TAC} wrapped inside a \\texttt{TRY}.  And before doing\nthat, we should do some rewriting to make sure that equalities in the\nassumptions are eliminated.\n\nSo:\n\\begin{session}\n\\begin{alltt}\n- e (Q.PAT_ASSUM `x # y -||-> z`\n      (STRIP_ASSUME_TAC o SIMP_RULE std_ss [x_ap_y_predn]) THEN\n     RW_TAC std_ss [] THEN\n     TRY (PROVE_TAC [predn_rules]));\nOK..\nMeson search level: ...............................\nMeson search level: ...............................\nMeson search level: ..................\nMeson search level: .....\n2 subgoals:\n> val it =\n    \\(\\exists\\)u'. y # v -||-> u' \\(\\land\\) f # u # (g # u) -||-> u'\n    ------------------------------------\n      0.  S # f # g -||-> y\n      1.  \\(\\forall\\)z. S # f # g -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u\n      2.  u -||-> v\n      3.  \\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u\n\n    \\(\\exists\\)u. y # v -||-> u \\(\\land\\) z -||-> u\n    ------------------------------------\n      0.  K # z -||-> y\n      1.  \\(\\forall\\)z'. K # z -||-> z' \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z' -||-> u\n      2.  u -||-> v\n      3.  \\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nBrilliant!  We've eliminated two of the four disjuncts already.  Now\nour next goal features a term \\verb!K # z -||-> y! in the assumptions.\nWe have a theorem that pertains to just this situation.  But before\napplying it willy-nilly, let us try to figure out exactly what the\nsituation is.  A diagram of the current situation might look like\n\\[\\xymatrix @C=2cm {\n*+<4pt>[F--]\\txt{\\fbox{\\texttt{K\\kern2mm \\#\\kern2mm z}} \\texttt{\\#} \\fbox{\\texttt{u}}} \\ar[r] & \\txt{\\texttt{z}} \\ar@{.>}[d] \\\\\n*+<4pt>[F--]\\txt{\\fbox{\\texttt{y}} \\texttt{\\#} \\fbox{\\texttt{v}}} \\ar@{.>}[r] & \\txt{\\texttt{?u?}}\n\\ar \"1,1\"!<-12pt,0pt>;\"2,1\"!<-12pt,0pt>\n\\ar \"1,1\"!<28pt,0pt>;\"2,1\"!<11pt,0pt>\n} \\]\nOur theorem tells us that \\texttt{y} must actually be of the form\n\\verb!K # w! for some \\texttt{w}, and that there must be an arrow\nbetween \\texttt{z} and \\texttt{w}.  Thus:\n\\begin{session}\n\\begin{alltt}\n- e (`?w. (y = K # w) /\\bs (z -||-> w)` by PROVE_TAC [Kx_predn]);\nOK..\nMeson search level: ......\n1 subgoal:\n> val it =\n    \\(\\exists\\)u. y # v -||-> u \\(\\land\\) z -||-> u\n    ------------------------------------\n      0.  K # z -||-> y\n      1.  \\(\\forall\\)z'. K # z -||-> z' \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z' -||-> u\n      2.  u -||-> v\n      3.  \\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u\n      4.  y = K # w\n      5.  z -||-> w\n\\end{alltt}\n\\end{session}\n    On inspection, it becomes clear that the \\texttt{u} must be\n    \\texttt{w}.  The first conjunct requires \\verb!K # w # v -||-> w!,\n    which we have because this is what \\KC{}s do, and the second\n    conjunct is already in the assumption list.  Rewriting\n    (eliminating that equality in the assumption list first will make\n    \\texttt{PROVE\\_TAC}'s job that much easier), and then first order\n    reasoning will solve this goal:\n\\begin{session}\n\\begin{alltt}\n- e (RW_TAC std_ss [] THEN PROVE_TAC [predn_rules]);\nOK..\nMeson search level: ...\n\nGoal proved. [...]\nRemaining subgoals:\n> val it =\n    \\(\\exists\\)u'. y # v -||-> u' \\(\\land\\) f # u # (g # u) -||-> u'\n    ------------------------------------\n      0.  S # f # g -||-> y\n      1.  \\(\\forall\\)z. S # f # g -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u\n      2.  u -||-> v\n      3.  \\(\\forall\\)z. u -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. v -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nThis case involving \\SC{} is analogous.  Here's the tactic to apply:\n\\begin{session}\n\\begin{alltt}\n- e (`?p q. (y = S # p # q) /\\bs (f -||-> p) /\\bs (g -||-> q)`\n        by PROVE_TAC [Sxy_predn] THEN\n     RW_TAC std_ss [] THEN PROVE_TAC [predn_rules]);\nOK..\nMeson search level: ........\nMeson search level: ...........\n\nGoal proved.[...]\nRemaining subgoals:\n> val it =\n    \\(\\forall\\)f g x z. S # f # g # x -||-> z \\(\\Rightarrow\\)\n              \\(\\exists\\)u. f # x # (g # x) -||-> u \\(\\land\\) z -||-> u\n\n\n    \\(\\forall\\)x y z. K # x # y -||-> z \\(\\Rightarrow\\) \\(\\exists\\)u. x -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nThis next goal features a \\verb!K # x # y -||-> z! term that we have a\ntheorem for already.  And again, let's speculatively use a call to\n\\texttt{PROVE\\_TAC} to eliminate the simple cases immediately\n(\\verb!Kxy_predn! is a disjunct so we'll get two sub-goals if we don't\neliminate anything).\n\\begin{session}\n\\begin{alltt}\n- e (RW_TAC std_ss [Kxy_predn] THEN\n     TRY (PROVE_TAC [predn_rules]));\nOK..\nMeson search level: ..\nMeson search level: ...\n\nGoal proved. [...]\nRemaining subgoals:\n> val it =\n    \\(\\forall\\)f g x z. S # f # g # x -||-> z \\(\\Rightarrow\\)\n              \\(\\exists\\)u. f # x # (g # x) -||-> u \\(\\land\\) z -||-> u\n\\end{alltt}\n\\end{session}\nBetter yet! We got both cases immediately, and have moved onto the\nlast case.  We can try the same strategy.\n\\begin{session}\n\\begin{alltt}\n- e (RW_TAC std_ss [Sxyz_predn] THEN PROVE_TAC [predn_rules]);\nOK..\nMeson search level: ..\nMeson search level: ...........\n\nGoal proved.[...]\n> val it =\n    Initial goal proved.\n    |- \\(\\forall\\)x y. x -||-> y \\(\\Rightarrow\\) \\(\\forall\\)z. x -||-> z \\(\\Rightarrow\\)\n             \\(\\exists\\)u. y -||-> u \\(\\land\\) z -||-> u : goalstack\n\\end{alltt}\n\\end{session}\nThe final goal proof can be packaged into:\n\\begin{session}\n\\begin{verbatim}\nval predn_diamond_lemma = prove(\n  ``!x y. x -||-> y ==>\n          !z. x -||-> z ==> ?u. y -||-> u /\\ z -||-> u``,\n  Induct_on `$-||->` THEN REPEAT CONJ_TAC THENL [\n    PROVE_TAC [predn_rules],\n    REPEAT STRIP_TAC THEN\n    Q.PAT_ASSUM `x # y -||-> z`\n      (STRIP_ASSUME_TAC o SIMP_RULE std_ss [x_ap_y_predn]) THEN\n    RW_TAC std_ss [] THEN\n    TRY (PROVE_TAC [predn_rules]) THENL [\n      `?w. (y = K # w) /\\ (z -||-> w)` by PROVE_TAC [Kx_predn] THEN\n      RW_TAC std_ss [] THEN PROVE_TAC [predn_rules],\n      `?p q. (y = S # p # q) /\\ (f -||-> p) /\\ (g -||-> q)` by\n         PROVE_TAC [Sxy_predn] THEN\n      RW_TAC std_ss [] THEN PROVE_TAC [predn_rules]\n    ],\n    RW_TAC std_ss [Kxy_predn] THEN PROVE_TAC [predn_rules],\n    RW_TAC std_ss [Sxyz_predn] THEN PROVE_TAC [predn_rules]\n  ]);\n\\end{verbatim}\n\\end{session}\n\\eos{}\n\nWe are on the home straight.  The lemma can be turned into a statement\ninvolving the \\con{diamond} constant directly:\n\\begin{session}\n\\begin{verbatim}\nval predn_diamond = store_thm(\n  \"predn_diamond\",\n  ``diamond $-||->``,\n  PROVE_TAC [diamond_def, predn_diamond_lemma]);\n\\end{verbatim}\n\\end{session}\n\nAnd now we can prove that our original relation is confluent in\nsimilar fashion:\n\n\\begin{session}\n\\begin{verbatim}\nval confluent_redn = store_thm(\n  \"confluent_redn\",\n  ``confluent $-->``,\n  PROVE_TAC [predn_diamond, confluent_diamond_RTC,\n             RTCpredn_EQ_RTCredn, diamond_RTC]);\n\\end{verbatim}\n\\end{session}\n\n\n\n\\section{Exercises}\n\nIf necessary, answers to the first three exercises can be found by\nexamining the source file in \\texttt{examples/ind\\_def/clScript.sml}.\n\n\\begin{enumerate}\n\\item Prove that \\[\\con{RTC}\\;R \\;x\\; y \\;\\;\\land \\;\\;\n  \\con{RTC}\\;R\\;y\\;z\\;\\;\\;\\supset\\;\\;\\; \\con{RTC}\\;R\\;x\\;z\n\\] You will need to prove the goal by induction, and will probably\n  need to massage it slightly first to get it to match the appropriate\n  induction principle.  Store the theorem under the name\n  \\texttt{RTC\\_RTC}.\n\\item Another induction.  Show that \\[\n  (\\forall x\\,y.\\; R_1\\;x\\;y\\supset R_2\\;x\\;y) \\supset\n  (\\forall x\\,y.\\; \\con{RTC}\\;R_1\\;x\\;y \\supset \\con{RTC}\\;R_2\\;x\\;y)\n\\] Call the resulting theorem \\texttt{RTC\\_monotone}.\n\\item Yet another \\con{RTC} induction, but where $R$ is no longer\n  abstract, and is instead the original reduction relation.  Prove\n\\[\nx \\rightarrow^* y \\;\\;\\;\\supset\\;\\;\\;\n\\forall z.\\;\\; x\\;z \\rightarrow^* y \\;z \\land\nz\\;x \\rightarrow^* z\\;y\n\\] Call it \\texttt{RTCredn\\_ap\\_congruence}.\n\n\\item Come up with a counter-example for the following property: \\[\n\\begin{array}{c}\n  \\left(\n    \\begin{array}{ll}\n      \\forall x\\,y\\,z. &\n      R\\;x\\;y\\;\\;\\land\\;\\; R\\;x\\;z \\;\\;\\;\\supset\\\\\n      & \\exists u.\\;\\con{RTC}\\;R\\;y\\;u \\;\\;\\land\\;\\;\\con{RTC}\\;R\\;z\\;u\n      \\end{array}\\right)\\\\\n    \\supset\\\\\n    \\con{diamond}\\;(\\con{RTC}\\;R)\n  \\end{array}\n  \\]\n\\end{enumerate}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"tutorial\"\n%%% End:\n", "meta": {"hexsha": "f5ba59ff8fc05484f4619187b7155bd0f0b93644", "size": 57160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Tutorial/combin.tex", "max_stars_repo_name": "LiLiming/HOL", "max_stars_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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/combin.tex", "max_issues_repo_name": "LiLiming/HOL", "max_issues_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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/combin.tex", "max_forks_repo_name": "LiLiming/HOL", "max_forks_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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.3844684914, "max_line_length": 142, "alphanum_fraction": 0.6104793562, "num_tokens": 18813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6443002149383186}}
{"text": "\\subsection{Algebraic proof (using Spectral Theorem)}\n\nThe proof in this section relies on the Spectral Theorem, which says\nthat we can diagnonalize a symmetric matrix. Instead of jumping right\naway to the proof of SVD with such heavy machinery, we prefer a\ngradual approach consisting of the following steps: \\\\\n\n\\begin{itemize}\n\\item Emphasize that the main task of SVD factorization, is to find a\n  basis for \\R{n} whose orthogonality is preserved under $A$.\n\\item Introduce Fundamental Theorem of Linear Algebra along the four\n  subspaces related to an arbitrary matrix \n  $A$.\n\\item Motivated by the discussion about the four subspaces, bring to the\n  picture the symmetric matrix $\\trans{A}A$ (aka the gramian), and\n  state the properties we will need for the SVD proof.\n\\item The symmetric nature of $\\trans{A} A$, will justify the\n  usage of the Spectral Theorem; which we proceed to prove.\n\\item Finally, we  prove SVD \\cref{thm:SVD} itself using the Spectral\n  Theorem as the main tool, but we also use  the auxiliary theorems\n  stated along the way.\n\\end{itemize}\n\\hfill\n\n\\input{svd-proof-spec-fact.tex}\n\\input{svd-proof-spec-fund.tex}\n\\input{svd-proof-spec-gram.tex}\n\\input{svd-proof-spec-spec.tex}\n\n\\subsubsection{The spectral proof of SVD}\n\nWe are now all set to prove the SVD theorem, and actually, we do not\nneed to prove the full version stated in \\cref{thm:SVD},\nbecause we have worked out the factorization part with theorems\n\\cref{thm:SVD1} and \\cref{thm:SVD2}. Those theorems started from the\nassumption, that there exist two orthonormal bases such that $A\\vec{v_i} =\n\\sigma_i\\vec{u_i}$; what remains to prove then, is the existence of\nthose bases. \\\\\n\n\\begin{theorem}[SVD Part 3: existence of the bases]\n\\label{thm:SVD3}\nLet $A$ be a real matrix of $m \\times n$ with rank $r$ $\\implies$ there exist\northonormal basis $\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_n}\\}$ and\n$\\{\\vec{u_1},\\vec{u_2},\\dots,\\vec{u_m}\\}$, for \\R{n} and \\R{m}\nrespectively; along with positive real values $\\sigma_1 \\ge \\sigma_2 \\ge \\cdots\n\\sigma_r$, such that: \n\n\\[\nA\\vec{v_i} = \\sigma_i\\vec{u_i}\n\\]\n\\end{theorem}\n\\hfill\n\n\\begin{proof}\nWe know from previous sections, that\nthe key is to find first the \nbasis for \\R{n}, such that its orthogonality is preserved through\n$A$ (this interesting approach, and most if this particular proof, is taken from\nKalman \\cite{kalman96}). \\\\\n\nPer the Fundamental\nTheorem of Linear Algebra, the symmetric \nmatrix $\\trans{A}A$ came to \nthe picture; and here comes the magical step: it turns out, that the\neigenvectors of such matrix (whose existence is guaranteed by the\nSpectral Theorem we just proved), are precisely the orthonormal basis\n$\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_n}\\}$ that we are looking for. Let\nus verify that is actually the case, that is, that $A$ preserves the\northogonality of the eigenvectors of $\\trans{A}A$. \\\\\n\nLet \\vec{v_i} and \\vec{v_j} be eigenvectors of $\\trans{A}A$, and\n$\\lambda_j$ the eigenvalue of $\\vec{v_j}$, then: \\\\\n\n\\[\n(A\\vec{v_i}) \\cdot (A\\vec{v_j}) = \n\\trans{(A\\vec{v_i})}(A\\vec{v_j}) = \n\\trans{\\vec{v_i}} (\\trans{A} A\\vec{v_j}) = \n\\trans{\\vec{v_i}} ( \\lambda_j \\vec{v_j} ) = \n\\lambda_j \\vec{v_i} \\cdot \\vec{v_j}\n\\]\n\\hfill\n\nThe above derivation tells us that the orthogonality of the images of\nthe eigenvectors, named $A\\vec{v_i}$ and $A\\vec{v_j}$, totally depends of the\northogonality of the pre-images \\vec{v_i} and \\vec{v_j}. Another way of\nsaying that, given that the two eigenvectors were picked arbitrarily,\nis that the orthogonality of the eigenvectors of $\\trans{A}A$ is\npreserved through $A$. This is exactly the basis we were looking for!\n\\\\ \n\nThe real work is to find the the basis\n$\\{\\vec{v_1},\\vec{v_2},\\dots,\\vec{v_n}\\}$ in \\R{n}, as the basis in \\R{m} is\nsimply calculated to meet the requirement that $A\\vec{v_i} =\n\\sigma_i\\vec{u_i}$. When proving that orthogonality of the\n\\vec{v}\\apos{s} is preserved, we came up with the following identity: \\\\\n\n\\[\n(A\\vec{v_i}) \\cdot (A\\vec{v_j}) =  \\lambda_j \\vec{v_i} \\cdot \\vec{v_j}\n\\]\n\\hfill\n\nThe particular case of $i = j$, will give us the following\nrelationship between the eigenvalues of $\\trans{A}A$ and the images\n$A\\vec{v_i}$ (let us recall that the Spectral Theorem guaranteed an\northonormal basis, hence $\\norm{\\vec{v_i}}_2 = 1$): \\\\\n\n\\[\n(A\\vec{v_i}) \\cdot (A\\vec{v_i}) =  \\lambda_i \\vec{v_i} \\cdot \\vec{v_i}\n\\ds{\\iff} \\norm{A\\vec{v_i}}_2^2 = \\lambda_i \\norm{\\vec{v_i}}_2^2\n\\ds{\\iff} \\norm{A\\vec{v_i}}_2 = \\sqrt{\\lambda_i} \n\\]\n\\hfill\n\nNow we just define the vectors \\vec{u}\\apos{s} as the unitary version\nof the images of vectors \\vec{v}\\apos{s}; and use the above\nrelationship to bring the eigenvalues of $\\trans{A}A$ into the\npicture: \\\\\n\n\\[\n\\vec{u_i} = \\dfrac{A\\vec{v_i}}{\\norm{A\\vec{v_i}}} =\n\\dfrac{1}{\\sqrt{\\lambda_i}} A\\vec{v_i}; \\ds{\\forall} i=1 \\dots r = \\func{rank}(A)\n\\]\n\\hfill\n\nDo we have enough singular values $\\lambda_i$ in $\\trans{A}A$ (we\nneed exactly $r$), and all of them are positive? (otherwise,\n$\\sqrt{\\lambda_i}$ would not be real). We have properly prepared for\nthis moment, and the whole purpose of having mentioned \n\\cref{thm:grameig}, was precisely to give a positive answer to these\nquestions. We are safe in this regard then, and can proceed. \\\\\n\nIn general $\\func{rank}(A) = r < m = \\dim{\\R{m}}$, so we must likely\nneed to extend the set $\\{\\vec{u_1},\\vec{u_2},\\dots,\\vec{u_r}\\}$ to an\northonormal basis of \\R{m} to complete the SVD\nfactorization. Fortunately, there is a \nknown theorem in Linear Algebra that guarantees that we can do that\nindeed (see theorem $2.1.1$ from \\cite{golub13}, for example). \\\\\n\nFinally, by naming $\\norm{A\\vec{v_i}}_2 = \\sqrt{\\lambda_i}$ as $\\sigma_i$\n(for $1 \\le i \\le r$), we can finally achieve the long wanted property\nof the two bases: \\\\\n\n\\[\nA\\vec{v_i} = \\norm{A\\vec{v_i}} \\vec{u_i} = \n\\sqrt{\\lambda_i} \\vec{u_i} =\n\\sigma_i \\vec{u_i} \\ds{;} \\ds{\\forall} 1 \\le i \\le r = \\func{rank}(A)\n\\]\n\\end{proof}\n\\hfill\n\nThe just proved \\cref{thm:SVD3} is the precondition that we\nneed to apply \\cref{thm:SVD1} and \\cref{thm:SVD2} from previous\nsections. The eigenvalues of the symmetric matrix $\\trans{A}A$ may not\nnecessarily be in descending order, as the SVD theorem requires; but\nonce we have them, we can sort them in such way (which will implicitly\nsort the $\\vec{v}\\apos{s}$ and $\\vec{u}\\apos{s}$ vectors in the\nbases). All together can finally tackle the original SVD\n\\cref{thm:SVD}, stated at the beginning of this chapter. This\nconcludes our proof of the SVD factorization, using the Spectral\nTheorem as the main tool. \\\\ \n\nIt may had seen as an extremely detailed proof, even if not all the\nauxiliary theorems were proved in this work (but most of them were at least\nmentioned explicitly, some even formally). This unusual level of\ndetail may appear cumbersome for the professional mathematician, as all the\nliterature we consulted always presented quite compressed proofs which\nskipped or simplified a lot steps. But we\nconsidered that the approach taken here, could be useful for the occasional\nreader and for people who are introducing themselves to the topic, and\nwant to have an almost self-contained proof of the SVD that requires\nlittle previous context (at least much less than regular books and\narticles).  Worth to say also, that this level of detail was needed\nfor the authors' own understanding as well.  \n\n\n", "meta": {"hexsha": "0e325dec8a0c658cad8bc748b54e018877d9b8a4", "size": 7312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-proof-spec.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.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.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": 41.5454545455, "max_line_length": 81, "alphanum_fraction": 0.727297593, "num_tokens": 2310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6443002074446426}}
{"text": "\\hypertarget{group__numpp__differentiation__finite__central}{}\\section{Central Finite Differentiation}\n\\label{group__numpp__differentiation__finite__central}\\index{Central Finite Differentiation@{Central Finite Differentiation}}\n\\subsection*{Functions}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename Func , typename T , typename  = std\\+::enable\\+\\_\\+if\\+\\_\\+t$<$std\\+::is\\+\\_\\+floating\\+\\_\\+point$<$\\+T$>$\\+::value$>$$>$ }\\\\C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto \\hyperlink{group__numpp__differentiation__finite__central_ga310a47693c9fd648ccb763f452a813d0}{numpp\\+::differentiation\\+::finite\\+::central} (Func \\&\\&f, T x)\n\\end{DoxyCompactItemize}\n\n\n\\subsection{Detailed Description}\nCalculates central finite derivative $\\frac{f(x+ 0.5*h)-f(x-0.5*h)}{h}$\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em Func} & Function whose finite difference derivative should be calcuated \\\\\n\\hline\n{\\em T} & Argument type (e.\\+g. double)\\\\\n\\hline\n\\end{DoxyTemplParams}\n\n\\begin{DoxyParams}{Parameters}\n{\\em f} & Functor or function whose derivative we want to obtain \\\\\n\\hline\n{\\em x} & Point where the derivative is calculated \\\\\n\\hline\n{\\em h} & Disturbtion to x argument, should be around e-\\/7 usually\\\\\n\\hline\n\\end{DoxyParams}\n\\begin{DoxyWarning}{Warning}\nIf you are unsure about parameter h use function with automatically calculated overload!\n\\end{DoxyWarning}\nEventual error performed by this calculation is not provided.\n\nFor better accuracy and numerical stability see\\+:\n\n\\hyperlink{group__numpp__differentiation__symbolic}{Symbolic Differentiation} \\hyperlink{group__numpp__differentiation__automatic}{Automatic Differentiation}\n\n\\begin{DoxyReturn}{Returns}\nDerivative at point x\n\\end{DoxyReturn}\n\n\n\\subsection{Function Documentation}\n\\mbox{\\Hypertarget{group__numpp__differentiation__finite__central_ga310a47693c9fd648ccb763f452a813d0}\\label{group__numpp__differentiation__finite__central_ga310a47693c9fd648ccb763f452a813d0}} \n\\index{Central Finite Differentiation@{Central Finite Differentiation}!central@{central}}\n\\index{central@{central}!Central Finite Differentiation@{Central Finite Differentiation}}\n\\subsubsection{\\texorpdfstring{central()}{central()}}\n{\\footnotesize\\ttfamily template$<$typename Func , typename T , typename  = std\\+::enable\\+\\_\\+if\\+\\_\\+t$<$std\\+::is\\+\\_\\+floating\\+\\_\\+point$<$\\+T$>$\\+::value$>$$>$ \\\\\nC\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto numpp\\+::differentiation\\+::finite\\+::central (\\begin{DoxyParamCaption}\\item[{Func \\&\\&}]{f,  }\\item[{T}]{x }\\end{DoxyParamCaption})}\n\nThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.\n\nAutomatically calculated disturbtion h to argument x, taken from Numerical Recipees (add source)", "meta": {"hexsha": "51fe6e88293260b07448b69347e9109cffb988dd", "size": 2744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/group__numpp__differentiation__finite__central.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__finite__central.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__finite__central.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": 51.7735849057, "max_line_length": 347, "alphanum_fraction": 0.7707725948, "num_tokens": 832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6442348204036608}}
{"text": "\\section{Introduction}\n% problem statement\n% motivation\n% general approach\n% (outlook on results)\n\n%conventions: lower-scalar, lower,bold-vector, upper,bold-matrix\n\nFinding periodic orbits in dynamic systems has various applications mainly in engineering. %cite\nThis project's goal is the implementation and evaluation of methods for this task.\nThis document aims at explaining the methods, techniques and ideas used in a concise and connected manner.\n\nThe general problem can be described as follows.\nGiven a system of differential equations $\\frac{d \\mathbf x}{dt} = \\mathbf f(\\mathbf x)$, find solutions $\\mathbf y$ such that $\\mathbf y(t+T) = \\mathbf y(t)$ for all $t \\in \\R$.\nFinding closed-form representations of these solutions is impossible in general.\nWe thus resort to numerical methods for the task.\n\nThe tool used for the task of judging whether a given solution is a correct periodic solution is \\emph{Galerkin}'s method.\nThis is a form of collocation method, allowing to convert a continuous operator equation to a system of equations.\nSolving this possibly non-linear system yields a periodic solution.\n\nGiven a periodic solution for a system smoothly depending on a parameter, if the parameter varies only slightly, so will the solution.\nThis can be used to track solutions over a broad range of the parameter.\nProjecting the found periodic orbits to a simpler object (for example a set of scalars) allows to plot them against the parameter in a bifurcation diagram.\nThis allows to evaluate the global behavior of the system.\nBeing able to dynamically create bifurcation diagrams for a given system is a goal of this project.\n\n\n\\subsection{Notation}\n\nThroughout this text, the following conventions are used\n\\begin{compactitem}\n\t\\item Scalar values are represented by lowercase letters ($a$, $\\tilde b$), vectors by lowercase, bold letters ($\\mathbf v$), matrices and other higher dimensional constructs by capital, bold letters ($\\mathbf M$).\n\t\\item Subsets of the natural numbers up to an upper limit are denoted using subscript notation\n\t\t\\[\n\t\t\t\\N_n \\coloneqq \\{ x \\ |\\ x \\in \\N, x \\le n\\} \\text.\n\t\t\\]\n\t\\item Sequences of natural numbers are notated in square brackets\n\t\t\\[\n\t\t\t\\text{for } a,b \\in \\N,\\ a \\le b,\\ [a:b] \\coloneqq (a+i-1)_{i \\in \\N_{b-a+1}} \\text.\n\t\t\\]\n\t\\item Indexing of vectors is done using subscript notation, matrices are indexed using subscript for the row and superscript for the column.\n\t\\item Vectors and matrices are build using subscript notation\n\t\t\\[\n\t\t\t\\mathbf M = (f(i,j))_{i,j \\in \\N_n} \\equiv \\mathbf M_i^j = f(i,j) \\text{ for } i,j \\in \\N_n \\text.\n\t\t\\]\n\t\\item Function application using curly brackets denotes element wise application of a function.\n\t\tThat is, for sets $U$,$V$, $\\mathbf u \\in U^n$ for an $n \\in \\N$ and a function $f: U \\to V$,\n\t\t\\[\n\t\t\tf\\{\\mathbf u\\} = \\begin{pmatrix}\n\t\t\t\tf(\\mathbf u_1) \\\\ \\vdots \\\\ f(\\mathbf u_n)\n\t\t\t\\end{pmatrix} \\text.\n\t\t\\]\n\t\\item The $\\cdot||\\cdot$ operator denotes concatenation.\n\t\\item The $((\\cdot))_N$ operator takes its operand modulo $N$.\n\t\\item Symbols $\\Re$, $\\Im$ denote the real and imaginary part of its argument.\n\t\\item The symbol $\\delta$ denotes the Kronecker delta.\n\\end{compactitem}\n", "meta": {"hexsha": "2548c17bb6940a7ee2cd5651d4cdb3264af139a7", "size": 3190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doctheory/intro.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/intro.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/intro.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": 54.0677966102, "max_line_length": 215, "alphanum_fraction": 0.7404388715, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6442101618218575}}
{"text": "\\chapter{Number theory}\n\n\\section{Modular arithmetic}\n\t\\kactlimport{ModularArithmetic.h}\n\t\\kactlimport{ModInverse.h}\n\t\\kactlimport{ModPow.h}\n\t\\kactlimport{ModLog.h}\n\t\\kactlimport{ModSum.h}\n\t\\kactlimport{ModMulLL.h}\n\t\\kactlimport{ModSqrt.h}\n\n\\section{Primality}\n\t\\kactlimport{FastEratosthenes.h}\n\t\\kactlimport{MillerRabin.h}\n\t\\kactlimport{Factor.h}\n\n\\section{Divisibility}\n\t\\kactlimport{euclid.h}\n\t\\kactlimport{Euclid.java}\n\t\\kactlimport{CRT.h}\n\n\t\\subsection{Bézout's identity}\n\tFor $a \\neq $, $b \\neq 0$, then $d=gcd(a,b)$ is the smallest positive integer for which there are integer solutions to\n\t$$ax+by=d$$\n\tIf $(x,y)$ is one solution, then all solutions are given by\n\t$$\\left(x+\\frac{kb}{\\gcd(a,b)}, y-\\frac{ka}{\\gcd(a,b)}\\right), \\quad k\\in\\mathbb{Z}$$\n\n\t\\kactlimport{phiFunction.h}\n\n\\section{Fractions}\n\t\\kactlimport{ContinuedFractions.h}\n\t\\kactlimport{FracBinarySearch.h}\n\n\\section{Pythagorean Triples}\n The Pythagorean triples are uniquely generated by\n \\[ a=k\\cdot (m^{2}-n^{2}),\\ \\,b=k\\cdot (2mn),\\ \\,c=k\\cdot (m^{2}+n^{2}), \\]\n with $m > n > 0$, $k > 0$, $m \\bot n$, and either $m$ or $n$ even.\n\n\\section{Primes}\n\t$p=962592769$ is such that $2^{21} \\mid p-1$, which may be useful. For hashing\n\tuse 970592641 (31-bit number), 31443539979727 (45-bit), 3006703054056749\n\t(52-bit). There are 78498 primes less than 1\\,000\\,000.\n\n\tPrimitive roots exist modulo any prime power $p^a$, except for $p = 2, a > 2$, and there are $\\phi(\\phi(p^a))$ many.\n\tFor $p = 2, a > 2$, the group $\\mathbb Z_{2^a}^\\times$ is instead isomorphic to $\\mathbb Z_2 \\times \\mathbb Z_{2^{a-2}}$.\n\n\\section{Estimates}\n\t$\\sum_{d|n} d = O(n \\log \\log n)$.\n\n\tThe number of divisors of $n$ is at most around 100 for $n < 5e4$, 500 for $n < 1e7$, 2000 for $n < 1e10$, 200\\,000 for $n < 1e19$.\n\n\\section{Mobius Function}\n\\[\n\t\\mu(n) = \\begin{cases} 0 & n \\textrm{ is not square free}\\\\ 1 & n \\textrm{ has even number of prime factors}\\\\ -1 & n \\textrm{ has odd number of prime factors}\\\\\\end{cases}\n\\]\n  Mobius Inversion:\n  \\[ g(n) = \\sum_{d|n} f(d) \\Leftrightarrow f(n) = \\sum_{d|n} \\mu(d)g(n/d) \\]\n  Other useful formulas/forms:\n\n  $ \\sum_{d | n} \\mu(d) = [ n = 1] $ (very useful)\n\n  $ g(n) = \\sum_{n|d} f(d) \\Leftrightarrow f(n) = \\sum_{n|d} \\mu(d/n)g(d)$\n\n $ g(n) = \\sum_{1 \\leq m \\leq n} f(\\left\\lfloor\\frac{n}{m}\\right \\rfloor ) \\Leftrightarrow f(n) = \\sum_{1\\leq m\\leq n} \\mu(m)g(\\left\\lfloor\\frac{n}{m}\\right\\rfloor)$\n", "meta": {"hexsha": "7f803e54096a7fa117fa27549b6f8b8c8c040b28", "size": 2399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/number-theory/chapter.tex", "max_stars_repo_name": "sarafanshul/KACTL", "max_stars_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-05T09:25:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T03:57:28.000Z", "max_issues_repo_path": "content/number-theory/chapter.tex", "max_issues_repo_name": "sarafanshul/KACTL", "max_issues_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_issues_repo_licenses": ["MIT"], "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/number-theory/chapter.tex", "max_forks_repo_name": "sarafanshul/KACTL", "max_forks_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_forks_repo_licenses": ["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.9076923077, "max_line_length": 173, "alphanum_fraction": 0.6573572322, "num_tokens": 968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633915994285382, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.644210138588819}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{bm}\n\\usepackage{url}\n\\usepackage{algorithmic}\n\\usepackage[margin=2.5cm]{geometry}\n\n%opening\n\\title{Multiplicative Inverse}\n\\author{Armando Faz\\\\\\footnotesize{\\url{armfazh@ic.unicamp.br}}}\n\\date{}\n\\begin{document}\n\\maketitle\n\n\\section{Itoh-Tsujii}\n In order to compute the multiplicative inverse \nof an element $a\\in \\mathbb{F}_p^*$, the following identity is used: $a^{-1}\\equiv \na^{p-2}\\; (\\textrm{mod }p)$; part of this exponentiation can be calculated using an addition chain as shown by Itoh-Tsujii.\n\nLet $x,y\\in \\mathbb{Z}^+$ and $x\\leq y$, define the term $\\bm{\\alpha}_{x} = a^{2^x-1}$ and the relation $\\bm{\\alpha}_x\\rightarrow \\bm{\\alpha}_y$ as $\\bm{\\alpha}_{y}=(\\bm{\\alpha}_x)^{2^{y-x}}\\bm{\\alpha}_{y-x}$.\n\nThe cost for $\\bm{\\alpha}_x\\rightarrow \\bm{\\alpha}_y$ is $y-x$ squares and 1 multiplication.\n\n\n\\subsection{$p=2^{384}-2^{128}-2^{96}+2^{32}-1.$}\nThis is the addition chain for NIST P-384 curve. We start with $\n\\bm{\\alpha}_{1} \\rightarrow \\bm{\\alpha}_{2}  \\rightarrow \\bm{\\alpha}_{3}  \\rightarrow \n\\bm{\\alpha}_{6} \\rightarrow \\bm{\\alpha}_{12} \\rightarrow \\bm{\\alpha}_{15} \\rightarrow \n\\bm{\\alpha}_{30}$. After that, we pre-compute $T_1 = a^{2^{32}-1}$, $T_2 = a^{2^{32}-3}$, $T_3 = a^{2^{31}-1}$.\nusing the following:\n\\begin{eqnarray*}\n T_1 = a^{2^{32}-1} &=& (\\bm{\\alpha}_{30})^{2^2}a \\\\\n T_2 = a^{2^{32}-3} &=& (\\bm{\\alpha}_{30})^{2^2}\\bm{\\alpha}_2 \\\\\n T_3 = a^{2^{31}-1} &=& (\\bm{\\alpha}_{30})^{2}a \n\\end{eqnarray*}\nThen, define  $L_{0},\\dots,L_{353}= 0$ and \n\\begin{eqnarray*}\n a^{T_2} &=& L_{0  } \\\\\n a^{T_1} &=& L_{96 } = \n L_{129} = \n L_{161} = \n L_{193} = \n L_{225} = \n L_{257} = \n L_{289} = \n L_{321} \\\\\n a^{T_3} &=& L_{353}\n\\end{eqnarray*}\nTo obtain $c =a^{-1}$ compute:\n\\begin{algorithmic}\n \\STATE $c = 1$\n \\FOR{$i=353$ \\TO 0}\n\t\\STATE $c= c^2$\n\t\\IF{$L_i \\neq 0$}\n\t\t\\STATE  $c = c\\times L_i$\n\t\\ENDIF\n \\ENDFOR\n \\RETURN $c$\n\\end{algorithmic}\nCost: 19 multiplications and 384 squares.\n\n\\subsection{$p=2^{255}-19.$}\n\nIt was given an addition chain for $\\mathbb{F}_{2^{255}-19}$, starting with $a^9=(a^2)^{2^2}\\cdot a$ and $\\bm{\\alpha}_5=a^{31}=(a^2\\cdot a^9)^2\\cdot (a^9)$  compute   \n$\n\\bm{\\alpha}_{5} \\rightarrow \\bm{\\alpha}_{10} \\rightarrow \\bm{\\alpha}_{20} \\rightarrow \n\\bm{\\alpha}_{40} \\rightarrow \\bm{\\alpha}_{50} \\rightarrow \\bm{\\alpha}_{100} \\rightarrow \n\\bm{\\alpha}_{200} \\rightarrow \\bm{\\alpha}_{250}\n$, the multiplicative inverse is obtained as \n\\begin{eqnarray*}\na^{-1} &=& a^{2^{255}-21} \\\\\n       &=& (\\bm{\\alpha}_{250})^{2^5}\\cdot a^{11}\n\\end{eqnarray*}\nCost: 11 multiplications and 254 squares.\n\n\n\\subsection{$p=2^{448}-2^{224}-1.$} For $\\mathbb{F}_{2^{448}-2^{224}-1}$, starting with  \n$\n\\bm{\\alpha}_{1} \\rightarrow   \\bm{\\alpha}_{2}  \\rightarrow\n\\bm{\\alpha}_{3}   \\rightarrow \\bm{\\alpha}_{6}  \\rightarrow \\bm{\\alpha}_{12} \\rightarrow \n\\bm{\\alpha}_{24}  \\rightarrow \\bm{\\alpha}_{27} \\rightarrow \\bm{\\alpha}_{54} \\rightarrow \n\\bm{\\alpha}_{108} \\rightarrow \\bm{\\alpha}_{111}\\rightarrow \\bm{\\alpha}_{222} \\rightarrow \n\\bm{\\alpha}_{223}\n$, the multiplicative inverse is obtained as $a^{-1} = b^{2^2}\\cdot a$:\n\\begin{eqnarray*}\nb &=& (\\bm{\\alpha}_{223})^{2^{223}}\\cdot (\\bm{\\alpha}_{222})\\\\\n  &=& (a^{2^{223}}-1)^{2^{223}} (a^{2^{222}}-1)\\\\\n  &=& a^{2^{446}-2^{223}+2^{222}-1}\\\\\n  &=& a^{2^{446}-2^{222}-1}\n\\end{eqnarray*}\n\\begin{eqnarray*}\na^{-1} &=& b^{2^2}\\cdot a\\\\\n\t   &=& (a^{2^{446}-2^{222}-1})^{2^2}a\\\\\n\t   &=& a^{2^{448}-2^{222}-4+1}\\\\\n       &=& a^{2^{448}-2^{224}-3}\\\\\n\\end{eqnarray*}\n\nCost: 13 multiplications and 447 squares.\n\n\\paragraph{Bonus:}  The value $b=2^{446}-2^{222}-1$ is used for computing square-roots ($b = \\frac{p-3}{4}$); thus, there is only one addition chain used for both purposes.\n\n\\end{document}\n", "meta": {"hexsha": "b1f9f57a41d312bb268dee7ac043accc54e38f1e", "size": 3789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/addition_chain.tex", "max_stars_repo_name": "armfazh/nistp384_avx2", "max_stars_repo_head_hexsha": "03942c2d9c61e9b3c11a28684ae23288911f4520", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-09T15:17:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T04:07:23.000Z", "max_issues_repo_path": "doc/addition_chain.tex", "max_issues_repo_name": "armfazh/nistp384_avx2", "max_issues_repo_head_hexsha": "03942c2d9c61e9b3c11a28684ae23288911f4520", "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/addition_chain.tex", "max_forks_repo_name": "armfazh/nistp384_avx2", "max_forks_repo_head_hexsha": "03942c2d9c61e9b3c11a28684ae23288911f4520", "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.7452830189, "max_line_length": 209, "alphanum_fraction": 0.6159936659, "num_tokens": 1486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6441924386257591}}
{"text": "\\subsection{Functions of the edges}\n\\label{sec:edges}\n\n%------------------------------------------------------------------\n\n\\begin{figure}[!htp]\n\\centering\n\\begin{verbatim}\n          p1\n          o\n         /|\\\n        / | \\\n       /  |  \\e31\n   e12/   |   \\\n     /    |e01 \\\n    /     |     \\\np2 o f012 | f031 o p3\n    \\     |     /\n     \\    |    /\n   e20\\   |   /e03\n       \\  |  /\n        \\ | /\n         \\|/\n          o\n          p0\n\n\\end{verbatim}\n\\caption{Edge face pair labeling.\n\\label{diagram:EdgeFaces}}\n\\end{figure}\n\nNotation in this section is based on figure \\ref{diagram:EdgeFaces}.\nWe are discussing functions defined on a neighborhood of edge $e_{01}$.\n\nWe assume that, for each edge, an arbitrary order is assigned to\nits two vertices, which are then at the positions $\\p_0,\\p_1$ in the diagram.\n\nAn interior edge has 2 adjacent faces, $f_{012}$ and $f_{031}$.\nWe assume that these 2 faces are oriented consistently, with the labels\ntaken counterclockwise, so that the normal vectors point out of the page.\nEach face is represented by an ordered triple of vertices,\nbut the order is only determined up to a circular permutation;\nfor example, $f_{012}$ may be represented by the ordered triples\n$(\\p_0,\\p_1,\\p_2)$, $(\\p_2,\\p_0,\\p_1)$, or $(\\p_1,\\p_2,\\p_0)$,\nbut not by\n$(\\p_0,\\p_2,\\p_1)$, $(\\p_1,\\p_0,\\p_2)$, or $(\\p_2,\\p_1,\\p_0)$.\n\nFor the given ordering $(\\p_0,\\p_1)$ of the edge,\n$f_{120}$ is the edge's {\\it left face}\nand $f_{031}$ is the {\\it right face}.\n\nNote that we cannot assume any consistent ordering of the 4 neighboring edges;\nfor example, $e_{12}$ may be represented by either ordered pair\n$(\\p_1,\\p_2)$ or $(\\p_2,\\p_1)$.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Edge length}\n\\label{sec:edge_length}\n\nThe edge tangent vector is $\\p_1 - \\p_0$.\n\nThe gradient of its squared length is:\n\\begin{equation}\n\\Gc{\\p_i}{\\| \\p_1 - \\p_0 \\|^2}{\\q} = 2 \\left( \\p_i - \\p_{(i+1) \\bmod 1} \\right)\n\\end{equation}\n\nThe gradient of the edge length, $\\|\\p_1 - \\p_0\\|$ is:\n\\begin{equation}\n\\Gc{\\p_i}{\\| \\p_1 - \\p_0 \\|}{\\q} =\n\\frac{\\left( \\p_i - \\p_{(i+1) \\bmod 1} \\right)}\n{\\|\\p_1 - \\p_0\\|}\n\\end{equation}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Edge dihedral}\n\\label{sec:edge_dihedral}\n\nIn smooth surfaces,\nthe standard measures of curvature are all measures\nof the rate of change of the surface normal vector.\nFor triangular meshes, it is therefore natural to\nconsider functions that depend on the change in\nnormal vectors between nearby faces.\n\nIn this section, we consider functions of the difference\nin normals for 2 faces that share an edge,\nwhich is equivalent to the {\\it dihedral angle} of the edge.\n\nWe will consider a number of both real- and $\\Reals^3$-valued functions on\n$\\Reals^{12} = \\Reals^3 \\oplus \\Reals^3 \\oplus \\Reals^3 \\oplus \\Reals^3$.\nWe will use $\\p = (\\p_0, \\p_1, \\p_2, \\p_3)$, $\\q=\\ldots$, $\\r=\\ldots$, etc.,\nto refer to the arguments of these functions, with the meaning\nof the indices determined by figure \\ref{diagram:EdgeFaces}.\nWe are also interested in the two 9-dimensional subspaces\ncorresponding to the vertics of the two faces:\n$\\p_{012} = (\\p_0,\\p_1,\\p_2), \\p_{031} = (\\p_0,\\p_3,\\p_1)$.\nWe abbreviate the two normal vectors:\n$\\n_{012} = \\n(\\p_0,\\p_1,\\p_2)$\nand\n$\\n_{031} = \\n(\\p_0,\\p_3,\\p_1)$.\n\n%------------------------------------------------------------------\n\n\\paragraph{Difference in face normals}\n\\label{sec:normal_difference}\n\nOne measure of the change in surface normal across an edge\nis simply the vector difference of the two normals:\n\n\\begin{equation}\n\\label{eq:deltan}\n{\\mathbf \\dn} (\\p_0, \\p_1, \\p_2, \\p_3)\n=\n\\n (\\p_{012}) - \\n (\\p_{031})\n\\end{equation}\n\nThe (total) derivative of the squared distance between adjacent face normals is:\n\\begin{eqnarray}\n\\Db{\\|\\dn(\\p)\\|^2}{\\q}\n& =\n2 \\ \\dn ( \\q )^\\dagger &\n\\left( \\Db{ ( \\dn ) }{\\q} \\right)\n\\\\\n& =\n2 \\ \\dn(\\q)^\\dagger &\n\\left( \\Db{\\n(\\p_{012})}{\\q} - \\Db{\\n(\\p_{031})}{\\q} \\right)\n\\nonumber \\\\\n& =\n2 \\dn(\\q)^\\dagger &\n\\{ \\; \\left[ \\I_{\\Reals^3} - \\left( \\n( \\q_{012} ) \\otimes \\n( \\q_{012} ) \\right)\n\\right]\n\\ast \\Db{\\a ( \\p_{012} ) }{\\q}\n\\nonumber \\\\\n\\label{eq:deltan_derivative}\n&\n& - \\left[ \\I_{\\Reals^3} - \\left( \\n( \\q_{031} ) \\otimes \\n ( \\q_{031} ) \\right)\n\\right]\n\\ast \\Db{\\a ( \\p_{031} ) }{\\q}\n\\; \\}\n\\nonumber\n\\end{eqnarray}\n\nThe partial derivatives, with respect to one of the vertices,\nlike $\\Dd{\\p_0}{\\a ( \\p_{012} ) }{\\q}{\\r_0}$,\nall have a similar form:\n\\begin{equation}\n\\Dd{\\p_0}{\\a ( \\p_{012} ) }{\\q}{\\r_0}  = (\\q_1 - \\q_3) \\times \\r_0\n\\end{equation}\nUsing this, equation \\ref{eq:deltan_derivative}, equation \\ref{eq:dot_cross},\nand the facts that\n$\\dn(\\q)  \\perp  \\n(\\q_{012}) = - \\left( \\n(\\q_{031})  \\perp  \\n(\\q_{012}) \\right)$\nand\n$\\dn(\\q)  \\perp  \\n(\\q_{031}) = \\n(\\q_{012})  \\perp  \\n(\\q_{031})$,\nwe can write the partial gradients without reference to the\nderivative's argument $\\r$:\n\\begin{eqnarray}\n\\label{eq:normal-difference-gradient}\n\\Gc{\\p_0}{\\|\\dn\\|^2}{\\q}\n& = &\n\\left[\n{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n\\over {A(\\q_{012})}}\n\\times (\\q_1 - \\q_2)\n\\right]\n\\; + \\;\n\\left[\n{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n\\over {A(\\q_{031})}}\n\\times (\\q_3 - \\q_1)\n\\right]\n\\\\\n\\Gc{\\p_1}{\\|\\dn\\|^2}{\\q}\n& = &\n\\left[\n{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n\\over {A(\\q_{012})}}\n\\times (\\q_2 - \\q_0)\n\\right]\n\\; + \\;\n\\left[\n{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n\\over {A(\\q_{031})}}\n\\times (\\q_0 - \\q_3)\n\\right]\n\\nonumber\n\\\\\n\\Gc{\\p_2}{\\|\\dn\\|^2}{\\q}\n& = &\n\\left[\n{{ \\n(\\q_{031})  \\perp  \\n(\\q_{012}) }\n\\over {A(\\q_{012})}}\n\\times (\\q_0 - \\q_1)\n\\right]\n\\nonumber\n\\\\\n\\Gc{\\p_3}{\\|\\dn\\|^2}{\\q}\n& = &\n\\left[\n{{ \\n(\\q_{012})  \\perp  \\n(\\q_{031}) }\n\\over {A(\\q_{031})}}\n\\times (\\q_1 - \\q_0)\n\\right]\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\paragraph{Inner product between face normals}\n\\label{sec:normal_dot}\n\nThe inner product $\\left( \\n_{012} \\bullet \\n_{031} \\right)$\nis another important measure of edge curvature.\nIt is closely related to the squared distance between adjacent normals:\n\\begin{equation}\n\\label{eq:normal-distance-dot}\n\\| \\n_{012} - \\n_{031} \\|^2\n= \\| \\n_{012} \\|^2\n+ \\| \\n_{031} \\|^2\n- 2 \\left( \\n_{012} \\bullet \\n_{031} \\right)\n= 2 \\left[ 1 - \\left( \\n_{012} \\bullet \\n_{031} \\right) \\right]\n\\end{equation}\n\nThe function $f(\\p) = 1 - \\left( \\n_{012} \\bullet \\n_{031} \\right)$\nachieves its minimum, $0$, on flat face pairs,\nand its maximum, $2$, on face pairs that are folded back on themselves.\nIt's a reasonable choice the total bending or curvature of a surface.\nAnd $\\Da{f} = - \\Da{\\left( \\n_{012} \\bullet \\n_{031} \\right)}$.\n\nThe derivative of\n$\\left( \\n_{012} \\bullet \\n_{031} \\right)$\ncan be calculated using equations \\ref{eq:dot_derivative} and\n\\ref{eq:unit_normal_derivative}:\n\\begin{eqnarray}\n\\label{normal_dot_derivative}\n\\Db{\\left( \\n_{012} \\bullet \\n_{031} \\right)}{\\q}\n& = & \\n(\\q_{031}) \\bullet \\Db{\\n_{012}}{\\q} + \\n(\\q_{012}) \\bullet \\Db{\\n_{031}}{\\q}\n\\\\\n\\nonumber \\\\\n& = &\n\\n(\\q_{031}) \\bullet\n{{\\I - \\left(\\n(\\q_{012}) \\otimes \\n(\\q_{012}) \\right)} \\over {\\| \\a(\\q_{012}) \\|}}\n\\; \\Db{\\a_{012}}{\\q}\n\\nonumber \\\\\n& + &\n\\n(\\q_{012}) \\bullet\n{{\\I - \\left(\\n(\\q_{031}) \\otimes \\n(\\q_{031}) \\right)} \\over {\\| \\a(\\q_{031}) \\|}}\n\\; \\Db{\\a_{031}}{\\q}\n\\nonumber\n\\end{eqnarray}\n\nAs in \\autoref{sec:normal_difference}, we can write the partial gradients\nwithout reference to an argument:\n\\begin{eqnarray}\n\\label{eq:normal_dot_gradient}\n\\Gc{\\p_0}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\; &\n{ { \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012}) }\n\\over {\\| \\a (\\q_{012}) \\| } }\n\\times (\\q_2 - \\q_1)\n\\\\\n& \\; + &\n{ { \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031})  }\n\\over {\\| \\a (\\q_{031}) \\| }}\n\\times (\\q_1 - \\q_3)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_1}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\; &\n{ { \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012})  }\n\\over {\\| \\a (\\q_{012}) \\| } }\n\\times (\\q_0 - \\q_2)\n\\nonumber \\\\\n& \\; + &\n{{ \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031})   }\n\\over {\\| \\a (\\q_{031}) \\| }}\n\\times (\\q_3 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_2}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\; &\n{{ \\n(\\q_{031}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{012})  }\n\\over {\\| \\a (\\q_{012}) \\| } }\n\\times (\\q_1 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_3}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\; &\n{ { \\n(\\q_{012}) - \\left[ \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right] \\n(\\q_{031}) }\n\\over {\\| \\a (\\q_{031}) \\| } }\n\\times (\\q_0 - \\q_1)\n\\nonumber\n\\end{eqnarray}\n\nThis can be simplified using the fact that\n\\(\\n_i \\perp \\n_j = \\n_i - \\left[ \\n_i \\bullet \\n_j \\right] \\n_j\\), for unit vectors,\nand the face area \\(A(\\q) = \\frac{1}{2} \\| \\a(\\q) \\|\\):\n\\begin{eqnarray}\n\\label{eq:simplified_normal_dot_gradient}\n\\Gc{\\p_0}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]}{2A(\\q_{012})}\n\\times (\\q_2 - \\q_1)\n\\\\\n& \\;\\;\\; + &\n\\frac{\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]}{2A(\\q_{031})}\n\\times (\\q_1 - \\q_3)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_1}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]}{2A(\\q_{012})}\n\\times (\\q_0 - \\q_2)\n\\nonumber \\\\\n& \\;\\;\\; + &\n\\frac{\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]}{2A(\\q_{031})}\n\\times (\\q_3 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_2}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]}{2A(\\q_{012})}\n\\times (\\q_1 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_3}{(\\n_{012} \\bullet \\n_{031})}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]}{2A(\\q_{031})}\n\\times (\\q_0 - \\q_1)\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\paragraph{Squared inner product between face normals}\n\\label{sec:squared_normal_dot}\n\nWe can get a more even distribution of bending by giving\na higher weight to sharper edge bends.\nA simple way to do that is to square some existing function,\nfor example: $\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2$.\nThe derivative is simply:\n\\begin{equation}\n\\Da{\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2}\n= -2 \\left( 1 - \\n_{012} \\bullet \\n_{031} \\right)\n\\Da{(\\n_{012} \\bullet \\n_{031})} \n\\end{equation}\n\nIt follows from equation \\ref{eq:simplified_normal_dot_gradient}\nthat the partial gradients are:\n\\begin{eqnarray}\n\\label{eq:squared_normal_dot_gradient}\n\\Gc{\\p_0}{\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}\n{A(\\q_{012}) }\n\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]\n\\times (\\q_2 - \\q_1)\n\\\\\n& \\;\\;\\; + &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}{A(\\q_{031})}\n\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]\n\\times (\\q_1 - \\q_3)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_1}{\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}{A(\\q_{012})}\n\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]\n\\times (\\q_0 - \\q_2)\n\\nonumber \\\\\n& \\;\\;\\; + &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}{A(\\q_{031})}\n\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]\n\\times (\\q_3 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_2}{\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}{A(\\q_{012})}\n\\left[ \\n(\\q_{031}) \\perp \\n(\\q_{012}) \\right]\n\\times (\\q_1 - \\q_0)\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_3}{\\left(1 - \\n_{012} \\bullet \\n_{031}\\right)^2}{\\q}\n& = \\;\\;\\; &\n\\frac{\\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) - 1\\right)\n}{A(\\q_{031})}\n\\left[ \\n(\\q_{012}) \\perp \\n(\\q_{031}) \\right]\n\\times (\\q_0 - \\q_1)\n\\nonumber\n\\end{eqnarray}\n\n%-----------------------------------------------------------------\n\n\\paragraph{Dihedral angle}\n\\label{sec:Dihedral-angle}\n\nThe {\\it dihedral angle},\n$\\theta_d$,\n of an edge is the amount\nneeded to rotate one face\nthrough the inside of the surface\n(in the sense of the orientation of the faces)\nonto the other face.\n\nWith this definition, the dihedral angle is always\npositive, in fact, between $0$ and $2\\pi$.\nAn acutely concave edge has a dihedral angle\nof a little less than $2\\pi$;\na concave edge where the faces meet in a right angle\n${3\\pi} \\over 2$;\na flat edge is $\\pi$;\na convex right angle $\\pi \\over 2$;\nand an acutely convex edge has a dihedral angle\nslightly more than $0$.\n\nThe dihedral angle is a simple function of the\nsigned normal angle, $\\theta_n$\n(\\autoref{sec:signed_normal_angle}),\nand it is generally more convenient to work\nwith the signed normal angle directly,\nso I will not consider the dihedral angle further.\n\n%------------------------------------------------------------------\n\n\\paragraph{Unsigned normal angle}\n\\label{sec:unsigned_normal_angle}\n\nThe inner product $\\left( \\n_{012} \\bullet \\n_{031} \\right)$\nis the cosine of $\\theta_u$,\nthe (unsigned) angle between the 2 face normals.\nThus the value of the angle is:\n\\begin{equation}\n\\theta_u(\\p_0,\\p_1,\\p_2,\\p_3)\n= \\cos^{-1} \\left( \\n_{012} \\bullet \\n_{031} \\right)\n\\end{equation}\n\nRecall the derivative of the $\\cos^{-1}$ is:\n\\begin{equation}\n\\frac{d}{\\mathit dx} \\cos^{-1}(x) = { -1 \\over \\sqrt{1 - x^2} }\n\\end{equation}\n\nThe derivative of $\\theta_u$ can be calculated using the chain rule\n(equation \\ref{eq:chain-rule}) and equation \\ref{eq:normal_dot_gradient}.\n\\begin{equation}\n\\Db{\\theta_u}{\\q}\n = { -1 \\over \\sqrt{1 - \\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right)^2} }\n\\; \\Db{\\left( \\n_{012} \\bullet \\n_{031} \\right)}{\\q}\n\\end{equation}\n\nAs above, we can write the partial gradients without reference to an argument:\n\\begin{equation}\n\\Gc{\\p_i}{\\theta_u}{\\q}\n=\n{ -1 \\over \\sqrt{1 - \\left( \\n(\\q_{012}) \\bullet \\n(\\q_{031}) \\right)^2} }\n\\; \\Gc{\\p_i}{\\left(\\n_{012}\\bullet\\n_{031}\\right)}{\\q}\n\\end{equation}\n\n%------------------------------------------------------------------\n\n\\paragraph{Signed normal angle}\n\\label{sec:signed_normal_angle}\n\nThe unsigned normal angle\n($\\theta_u$, \\autoref{sec:unsigned_normal_angle})\ndoesn't distinguish concave and convex changes in the normal vector,\nso it can't be a 1-1 function of the dihedral angle.\nMore importantly, it's inadequate if we want to construct\na penalty that treats concave and convex edges differently.\n\nIt is common to want to make a surface as flat as possible,\nwhich means penalizing normal angles different from zero.\nWith such 2rd order (curvature minimizing) penalties, \nit may not necessary to distinguish\nconvex and concave bending.\n\nHowever, there's considerable evidence that\n$3$rd order penalties ---minimizing the {\\it variation}\nin surface bending, rather than the bending itself---\ngives better results in many situations.\nTo measure bending variation, it's necessary\nto use correctly signed angles.\n\nAnother reason to use signed angles is to be able\nto encourage the surface to bend in a certain\npredetermined way at certain edges.\nThis is discussed in \\autoref{sec:Bent-edge-neighborhoods}\nbelow.\n\nThe {\\it signed normal angle,} $\\theta_n$,\nis essentially just the\nunsigned normal angle, multiplied by $-1$ if the surface is\nconcave at the edge.\nTo make this a bit more formal,\nwe can define the signed normal angle to be the amount\nof righthanded rotation about the edge tangent ($\\p_1 - \\p_0$)\nneeded to bring the right normal ($\\n_{031}$) to\nthe left normal ($\\n_{012}$).\nWe cut our angle measurement at $\\pi \\sim -\\pi$.\n\nWith this definition, the signed normal angle\nis between $-\\pi$ and $\\pi$.\nAn acutely concave edge has a signed normal angle\nof a little more than $-\\pi$;\na concave edge where the faces meet in a right angle\n$-{\\pi \\over 2}$;\na flat edge is $0$;\na convex right angle $\\pi \\over 2$;\nand an acutely convex edge has a signed normal angle\nslightly less than $\\pi$.\n\nThe dihedral angle can be expressed simply in terms of the\nsigned normal angle: $\\theta_d = \\pi - \\theta_n$.\n\nTo compute $\\theta_n$,\nit's easiest to use the informal definition:\n\\begin{equation}\n\\theta_n(\\p_0,\\p_1,\\p_2,\\p_3)\n= \\kappa(\\p_0,\\p_1,\\p_2,\\p_3) \\ast \\theta_u(\\p_0,\\p_1,\\p_2,\\p_3),\n\\end{equation}\nwhere $\\kappa(\\p_0,\\p_1,\\p_2,\\p_3)$ is\n$+1$ if the edge is convex\nand\n$-1$ if the edge is concave.\nOne way to determine convexity/concavity\nis to look at\n$\\left(\\p_3 - \\p_2 \\right) \\bullet \\n_{031}$\nwhich is positive if the edge is convex\nand negative if it is concave.\n\nThe derivative of $\\theta_n$ are simply $\\kappa$\ntimes the derivative of $\\theta_u$:\n$\\Db{\\theta_n}{\\q} = \\kappa(\\q) \\ast \\Db{\\theta_u}{\\q}$.\n\n%-----------------------------------------------------------------\n\n\\paragraph{Signed angle and normal distance}\n\\label{sec:Signed-angle-and-normal-distance}\n\nWe can tie the signed normal angle back \nto the distance between normal vectors,\nand save the time and complexity\nof computing the $\\cos^{-1}$ and its derivatives,\nby considering a simple transform.\n\nFirst, note that $\\sin({\\theta_n \\over 2})$\nis a monotone function of $\\theta_n$,\nranging from $-1$, when $\\theta_n = -\\pi$,\nto $1$ when $\\theta_n = \\pi$.\nAlso note that \n\\begin{equation}\n\\sin({\\theta_n \\over 2}) \n = \n\\sign(\\theta_n) \n\\left[ {1 - \\cos(\\theta_n)} \n\\over 2 \\right]^{1 \\over 2}\n = \n\\sign(\\theta_n) \n\\left[ {1 - \\left( \\n_{012}\\bullet\\n_{031} \\right)} \n\\over 2 \\right]^{1 \\over 2},\n\\end{equation}\nwhich means that\n\\begin{equation}\n\\sin^2({\\theta_n \\over 2}) \n= {{1 - \\left( \\n_{012}\\bullet\\n_{031} \\right)} \\over 2},\n\\end{equation}\nwhich is proportional to the distance between the adjacent normals\n(see equation \\ref{eq:normal-distance-dot}).\n\nNote that the function that promotes evenly \ndistributed bending described in \\autoref{sec:squared_normal_dot},\nis proportional to $\\sin^4({\\theta_n \\over 2})$. \n\n%-----------------------------------------------------------------\n\n\\paragraph{Bent edge neighborhoods}\n\\label{sec:Bent-edge-neighborhoods}\n\nIn many problems \\cite{hoppe-et-al-94,hoppe-thesis-94},\nit's important to be able to allow the surface to have\nsharp creases and cusps.\nA simple way to achieve this is to mark\ncertain edges as ``sharp'',\nand then not evaluate any bending penalty\non those edges.\nWith this approach, there are then 2 kinds of edges:\nsharp edges, where any bend angle is equally acceptable,\nand smooth edges, \nwhere any deviation from zero bending is penalized.\n\nHowever, it's not often the case that all angles\nare equally desirable for a ``sharp'' edge,\nor that no angle, other than $0$, is acceptable\nfor a ``smooth'' edge.\nIt's often true that we know that a given crease\nmust be, for example, convex ($\\theta_n > 0$)\nbut with bounded acuteness ($\\theta_n < \\alpha < \\pi$).\nOr we may know that a given edge should be close to\na convex right angle \n($\\left( {\\pi \\over 2} - \\delta \\right) \n< \\theta_n < \n\\left( {\\pi \\over 2} + \\delta \\right)$)\nfor some small positive angle $\\delta$.\n\nEnforcing hard constraints on $\\theta_n$\nis relatively difficult,\nbut it is easy to convert any function\nof the signed normal angle, $f(\\theta_n)$,\nthat penalizes non-zero normal angles,\ninto one that penalizes angles \noutside an interval, $\\left[\\theta_0,\\theta_1\\right]$,\nof prefered angles.\n($-\\pi \\leq \\theta_0 \\leq \\theta_1 \\leq \\pi$.)\n\nFor example,\nconsider the function of \\autoref{sec:squared_normal_dot},\nwhich is proportional to $\\sin^4({\\theta_n \\over 2})$. \nLet $s = \\sin({\\theta_n \\over 2})$,\na monotone function of $\\theta_n$ \nthat ranges over $\\left[ -1, 1 \\right]$.\n\nThen, \ngiven an interval $\\left[ \\theta_0, \\theta_1 \\right] \\subseteq \\left[ -\\pi, \\pi \\right]$,\nlet the {\\it bent} function be:\n\\begin{equation}\nf(s)\n= \n\\left\\{\n\\begin{array}{cr}\n\\left[ {  \n\\frac{\\textstyle\ns^2 - s_0^2}\n{\\textstyle\n1 - s_0^2}\n  } \\right]^2 \n& -\\pi \\leq \\theta_n \\leq \\theta_0\n\\\\\n\\\\\n0                            \n& \\theta_0 \\leq \\theta_n \\leq \\theta_1\n\\\\\n\\\\\n\\left[ {\n  {\\textstyle s^2 - s_1^2} \n  \\over \n  {\\textstyle 1 - s_1^2}\n  } \\right]^2  \n& \\theta_1 \\leq \\theta_n \\leq \\pi\n\\end{array}\n\\right.\n\\end{equation}\nThe reason for stretching $s^2$ rather than $s$\nis that we get a relatively simple expression\nin $\\n_{012} \\bullet \\n_{031}$:\n\\begin{equation}\nf(s)\n= \n\\left\\{\n\\begin{array}{cr}\n\\left[ {\n  {\\textstyle c_0 - \\left(\\n_{012} \\bullet \\n_{031}\\right) } \n  \\over \n  {\\textstyle c_0 + 1}\n   } \\right]^2\n& -\\pi \\leq \\theta_n \\leq \\theta_0\n\\\\\n\\\\\n0                            \n& \\theta_0 \\leq \\theta_n \\leq \\theta_1\n\\\\\n\\\\\n\\left[ {\\textstyle {c_1 - \\left(\\n_{012} \\bullet \\n_{031}\\right)} \n    \\over {\\textstyle c_1 + 1}} \\right]^2\n& \\theta_1 \\leq \\theta_n \\leq \\pi\n\\end{array}\n\\right.\n\\end{equation}\nwhere $c_0 = \\cos(\\theta_0)$\nand $c_1 = \\cos(\\theta_1)$.\nRecall that $\\cos(\\theta_n) = \\left(\\n_{012} \\bullet \\n_{031}\\right)$.\n\n%-----------------------------------------------------------------\n\n\\paragraph{Weighting bend measures by length}\n\\label{sec:length_weighted_bend}\n\nLet $f(\\p) = f(\\p_0,\\p_1,\\p_2,\\p_3)$ be some measure of the\nbend across the edge connecting $(\\p_0,\\p_1)$.\nIt may be useful to weight the bend measure by the edge length:\n$\\| \\p_0 - \\p_1 \\| \\ast f(\\p_0,\\p_1,\\p_2,\\p_3)$.\nThe partial gradients of the weighted measure are:\n\\begin{eqnarray}\n\\label{eq:length_weighted_bend_gradient}\n\\Gc{\\p_0}{\\left( \\|\\p_0 - \\p_1 \\| f(\\p) \\right)}{\\q}\n& = &\n\\frac{f(\\q)}{\\|\\q_0 - \\q_1\\|} \\left( \\q_0 - \\q_1 \\right)\n+ \\| \\q_0 - \\q_1 \\| \\Gc{\\p_0}{f}{q}\n\\\\\n& & \\nonumber \\\\\n\\Gc{\\p_1}{\\left( \\|\\p_0 - \\p_1 \\| f(\\p) \\right)}{\\q}\n& = &\n\\frac{f(\\q)}{\\|\\q_0 - \\q_1\\|} \\left( \\q_1 - \\q_0 \\right)\n+ \\| \\q_0 - \\q_1 \\| \\Gc{\\p_1}{f}{q}\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_2}{\\left( \\|\\p_0 - \\p_1 \\| f(\\p) \\right)}{\\q}\n& = &\n\\| \\q_0 - \\q_1 \\| \\Gc{\\p_2}{f}{q}\n\\nonumber \\\\\n& & \\nonumber \\\\\n\\Gc{\\p_3}{\\left( \\|\\p_0 - \\p_1 \\| f(\\p) \\right)}{\\q}\n& = &\n\\| \\q_0 - \\q_1 \\| \\Gc{\\p_3}{f}{q}\n\\nonumber\n\\end{eqnarray}\n\n\n%------------------------------------------------------------------\n\n\\paragraph{Rate of bending}\n\\label{sec:Rate-of-bending}\n\nIt may be useful to weight edge bends should\nby the length of the edge ---\na long sharp edge should cost more than a short sharp edge.\nIt may also be useful to weight inversely by the\ndistance to nearby edges --- two edges close together\nmeans more curvature than the same two edges farther apart.\nA measure has both these properties, at least approximately,\nis:\n\\begin{equation}\n{\\mathrm dN2L2A (\\p) }\n=\n\\| \\n(\\p_{012}) - \\n(\\p_{031}) \\|^2\n\\| \\p_0 - \\p_1 \\|^2\n\\left[\n\\frac{1}{A(\\p_{012})} +\n\\frac{1}{A(\\p_{031})}\n\\right]\n\\end{equation}\nwhere $\\| \\n(\\p_{012}) - \\n(\\p_{031}) \\|^2$ is the squared distance between\nadjacent normals, as in equation \\ref{eq:deltan}.\n(Note the similarity of the weighting to the aspect ratio\nmeasure discussed in \\ref{sec:Squared-edge-lengths-over-area}.)\n\n\\begin{eqnarray}\n\\Gc{\\p}{dN2L2A}{\\q}\n& = &\n\\Gc{\\p}{\\left(\\| \\n(\\p_{012}) - \\n(\\p_{031}) \\|^2 \\right)}{\\q}\n\\| \\q_0 - \\q_1 \\|^2\n\\left[\n\\frac{1}{A(\\q_{012})} +\n\\frac{1}{A(\\q_{031})}\n\\right]\n\\\\\n& + &\n\\| \\n(\\q_{012}) - \\n(\\q_{031}) \\|^2\n\\Gc{\\p}{\\left(\\| \\p_0 - \\p_1 \\|^2\\right)}{\\q}\n\\left[\n\\frac{1}{A(\\q_{012})} +\n\\frac{1}{A(\\q_{031})}\n\\right]\n\\nonumber\n\\\\\n& + &\n\\| \\n(\\q_{012}) - \\n(\\q_{012}) \\|^2\n\\| \\q_0 - \\q_1 \\|^2\n\\left[\n\\Gc{\\p}{\\left( \\frac{1}{A(\\p_{012})} \\right)}{\\q} +\n\\Gc{\\p}{\\left( \\frac{1}{A(\\p_{031})} \\right)}{\\q}\n\\right]\n\\nonumber\n\\end{eqnarray}\n\nThe partial gradients,\n$\\Gc{\\p_i}{\\left(\\| \\n(\\p_{012}) - \\n(\\p_{031}) \\|^2 \\right)}{\\q}$,\nis given in equation \\ref{eq:normal-difference-gradient}.\n\n$\\Gc{\\p_0}{\\left(\\| \\p_0 - \\p_1 \\|^2\\right)}{\\q} = 2 \\left( \\q_0 - \\q_1 \\right)$;\n$\\Gc{\\p_1}{\\left(\\| \\p_0 - \\p_1 \\|^2\\right)}{\\q} = 2 \\left( \\q_1 - \\q_0 \\right)$;\nand the other 2 partial gradients are zero.\n\nUsing \\ref{eq:area_partial_derivative}\nand the chain rule, we have:\n\\begin{eqnarray}\n\\label{eq:inverse-area-gradient-012}\n\\Gc{\\p_0}{\\left( \\frac{1}{A(\\p_{012})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{012}) \\times \\left( \\q_1 - \\q_2 \\right)}\n\\over\n{2 A(\\q_{012})^2 } }\n\\\\\n\\Gc{\\p_1}{\\left( \\frac{1}{A(\\p_{012})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{012}) \\times \\left( \\q_2 - \\q_0 \\right)}\n\\over\n{2 A(\\q_{012})^2 } }\n\\nonumber\n\\\\\n\\Gc{\\p_2}{\\left( \\frac{1}{A(\\p_{012})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{012}) \\times \\left( \\q_0 - \\q_1 \\right)}\n\\over\n{2 A(\\q_{012})^2 } }\n\\nonumber\n\\end{eqnarray}\n\\begin{eqnarray}\n\\label{eq:inverse-area-gradient-031}\n\\Gc{\\p_0}{\\left( \\frac{1}{A(\\p_{031})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{031}) \\times \\left( \\q_3 - \\q_1 \\right)}\n\\over\n{2 A(\\q_{031})^2 } }\n\\\\\n\\Gc{\\p_1}{\\left( \\frac{1}{A(\\p_{031})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{031}) \\times \\left( \\q_0 - \\q_3 \\right)}\n\\over\n{2 A(\\q_{031})^2 } }\n\\nonumber\n\\\\\n\\Gc{\\p_3}{\\left( \\frac{1}{A(\\p_{031})} \\right)}{\\q}\n& = &\n{{\\n(\\q_{031}) \\times \\left( \\q_1 - \\q_0 \\right)}\n\\over\n{2 A(\\q_{031})^2 } }\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------", "meta": {"hexsha": "5c70492e103b07928de908ba4495c048b7d29e02", "size": 24702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/edges.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/edges.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/edges.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": 29.5125448029, "max_line_length": 89, "alphanum_fraction": 0.6010039673, "num_tokens": 9122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.64419243748755}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 7.3 Compute Polynomial Coefficients from Roots\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nGiven $n$ complex numbers, $z_i$, compute (complex) coefficients, $c_i$,\nsuch that the monic polynomial defined by%\n\\begin{equation*}\np(z)=c_1z^n+...+c_nz+c_{n+1}\n\\end{equation*}\nhas the numbers $z_i$ as its roots. The coefficients will be computed from\nthe relation%\n\\begin{equation*}\n\\hspace{-10pt}c_1z^n+.\\text{ . . }+c_nz+c_{n+1}=(z-z_1)(z-z_2)^{...}(z-z_n)\n\\end{equation*}\nNote that $c_1$ is always set to~1.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[\\bf INTEGER]  \\ {\\bf NDEG}\n\\item[\\bf COMPLEX]  \\ {\\bf ROOTS}$(\\geq $NDEG),{\\bf COEFS}$(\\geq $NDEG+1)\n\\end{description}\nAssign values to NDEG and ROOTS().\n$$\n\\fbox{{\\bf CALL CCOEF (NDEG, ROOTS, COEFS)}}\n$$\nComputed quantities are returned in COEFS().\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[NDEG]  [in] Number of roots given in ROOTS(), and thus the degree of\nthe polynomial whose coefficients are to be computed.\n\\item[ROOTS()]  [in] Roots, given as complex numbers.\n\\item[COEFS()]  [out] Computed coefficients, stored as complex numbers. The\narrays COEFS() and ROOTS() must be distinct. The coefficient, $c_1$, will be\nthe coefficient of $z^{NDEG}$ and will be set to~1.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double precision usage change the subroutine name from CCOEF to ZCOEF.\nRecall that the Fortran~77 standard does not support a double precision\ncomplex data type, although many Fortran compilers do, using the\ndeclaration, COMPLEX*16. To remain within the Fortran~77 standard, use the\ndeclarations\n\\begin{description}\n\\item[DOUBLE PRECISION]  {\\bf ROOTS}(2, $\\geq $ NDEG$)$,\n{\\bf COEFFS}(2, $\\geq $NDEG$+1)$\n\\end{description}\n\nand use the convention that real and imaginary parts of complex numbers are\nassociated with the values 1 and~2, respectively, of the first subscript.\nThis usage is compatible with the Fortran~90 standard.  Alternatively, if\nthe COMPLEX*16 declaration is available and is compatible with this storage\nconvention, one may use the nonstandard declaration\n\\begin{description}\n\\item[COMPLEX*16]  {\\bf ROOTS}$(\\geq $ NDEG$)$,\n{\\bf COEFFS}$(\\geq $ NDEG$+1)$\n\\end{description}\n\n\\subsection{Examples and Remarks}\n\nThe program, DRZCOEF, with its output, ODZCOEF, illustrates the use of ZCOEF\nto compute the coefficients of a quadratic and a cubic polynomial.\n\nIf this subroutine is used to assess the accuracy of a polynomial root\nfinder we suggest use of the double precision version, even if it is a single precision\nroot finder, to reduce the introduction of errors from the process of\ncomputing the polynomial coefficients.\n\n\\subsection{Functional Description}\n\n\\subparagraph{Method}\n\nThe degree, NDEG, and roots, $z_1$, ..., $z_{NDEG}$, are given. The\ncoefficients, $c_i$, are computed by the following algorithm. The quantities\n$z_i$ and $c_i$ are complex. In the double precision version the complex arithmetic is\ncoded in-line in terms of operations on the real and imaginary parts to\nconform to the Fortran~77 standard.\n\\begin{tabbing}\n\\hspace{.2in}\\=$c_1 = 1.0$\\\\\n\\>if( NDEG .le. 0 ) return\\\\\n\\>$c_2 = -z_1$\\\\\n\\>do $i = 2$, NDEG\\\\\n\\>\\ \\ \\ \\ \\=$c_{i+1} = -c_i * z_i$\\\\\n\\>\\>do $j = i$, 2, $-$1\\\\\n\\>\\>\\ \\ \\ \\ $c_j = c_j - c_{j-1} * z_i$\\\\\n\\>\\>enddo\\\\\n\\>enddo\\\\\n\\>return\n\\end{tabbing}\n\n\\subparagraph{Accuracy tests}\n\nThe logic and the accuracy of this code were checked by use with a root\nfinder. The accuracy was consistent with the computer system being used.\n\n\\subsection{Error Procedures and Restrictions}\n\nIf NDEG $\\leq$ 0 the subroutine returns, setting COEFS$(1) = 1$. The arrays\nROOTS() and COEFS() must occupy distinct storage locations.\n\n\\subsection{Supporting Information}\n\nThe source language for these subroutines is ANSI Fortran 77.\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\nEntry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt}\\\\\nCCOEF & \\hspace{.35in} CCOEF\\rule[-5pt]{0pt}{8pt}\\\\\nZCOEF & \\hspace{.35in} ZCOEF\n\\end{tabular}\n\nDesigned by C. L. Lawson, JPL, May~1986.\n\nProgrammed by C. L. Lawson and S. Y. Chiu, JPL, May~1986, Feb.~1987.\n\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRZCOEF}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{zcoef}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODZCOEF}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{zcoef}}\n\\end{document}\n", "meta": {"hexsha": "96412758c1bb082870c9e2a9eacb1011bc6e54bc", "size": 4659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch07-03.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/ch07-03.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/ch07-03.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": 33.7608695652, "max_line_length": 98, "alphanum_fraction": 0.7325606353, "num_tokens": 1486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7341195385342972, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.6441728625333629}}
{"text": "%% LyX 2.3.1-1 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]{extarticle}\n\\usepackage[T1]{fontenc}\n\\usepackage[latin9]{inputenc}\n\\usepackage{geometry}\n\\geometry{verbose,tmargin=2.54cm,bmargin=2.54cm,lmargin=2.54cm,rmargin=2.54cm}\n\\usepackage{bm}\n\\usepackage{esint}\n\n\\makeatletter\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.\n\\setlength\\parindent{0pt}\n\n\\makeatother\n\n\\usepackage{babel}\n\\begin{document}\n{\\LARGE{}Notes on the Taylor Green Vortex}{\\LARGE\\par}\n\nComparing Domain $(0,2\\pi)^{3}$ to $(0,1)^{3}$ \n\nB.A. Wingate\n\n\\section{Introduction}\n\nThe Taylor Green vortex solution is used to compare/debug and test\nDNS codes. The Sandia/LANL DNS code has a domain $(0,1)^{3}$ while\nmany DNS codes use the default domain $(0,2\\pi)^{3}$ and this will\ncause differences in the solution, such as the energy decay rate,\nto occur. This document dicusses some of the details of this computation.\nIt has a companion sympy jupyter notebook titled \\texttt{\\textit{TaylorGreenExperiments.ipynb}}.\n\n\\section{In two-dimensions in $(0,2\\pi)^{2}$ }\n\nThe equations we solve are,\n\\begin{eqnarray}\n\\frac{\\partial u}{\\partial t}+u\\frac{\\partial u}{\\partial x}+v\\frac{\\partial u}{\\partial y} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial x}+\\nu\\left(\\frac{\\partial^{2}u}{\\partial x^{2}}+\\frac{\\partial^{2}u}{\\partial y^{2}}\\right),\\label{eq:nsu}\\\\\n\\frac{\\partial v}{\\partial t}+u\\frac{\\partial v}{\\partial x}+v\\frac{\\partial v}{\\partial y} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial y}+\\nu\\left(\\frac{\\partial^{2}v}{\\partial x^{2}}+\\frac{\\partial^{2}v}{\\partial y^{2}}\\right),\\label{eq:nsv}\\\\\n\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y} & = & 0.\\label{eq:divu}\n\\end{eqnarray}\n\nOn $\\Omega\\in(0,2\\pi)^{3}$ with initial condition,\n\\begin{eqnarray*}\nu(\\bm{x},0) & = & \\sin(x)\\cos(y),\\\\\nv(\\bm{x},0) & = & -\\cos(x)\\sin(y).\n\\end{eqnarray*}\n This has the following exact solution,\n\\begin{eqnarray*}\nu(\\bm{x},t) & = & \\sin(x)\\cos(y)e^{-2\\nu t},\\\\\nv(\\bm{x},t) & = & -\\cos(x)\\sin(y)e^{-2\\nu t},\\\\\np(\\bm{x},t) & = & -\\left(\\cos(2x)+\\cos(2y)\\right)e^{-4\\nu t}.\n\\end{eqnarray*}\nIt is quite interesting to me to be reminded that the pressure has\nto decay like twice the others because the others are nonlinear (it\nis more like u.u). This therefore has the total energy per unit area\ndecay like,\n\\[\nE=\\frac{1}{\\Omega}\\frac{1}{2}\\int_{\\Omega}\\left(u^{2}+v^{2}\\right)d\\Omega\\quad\\Omega\\in(0,2\\pi)^{2}\n\\]\n which gives,\n\\begin{eqnarray*}\nE(t) & = & \\frac{\\pi^{2}}{4\\pi^{2}}e^{-4\\nu t}\\quad\\Omega\\in(0,2\\pi)^{3}\\\\\n & = & \\frac{1}{4}e^{-4\\nu t}\n\\end{eqnarray*}\nWe can also compute the intitial energy, $E(0),$\n\\begin{eqnarray*}\nE(0) & = & \\frac{1}{4\\pi^{2}}\\frac{1}{2}\\int_{0}^{2\\pi}\\int_{0}^{2\\pi}\\sin^{2}(x)\\cos^{2}(y)+\\cos^{2}(x)\\sin^{2}(y)\\,dx\\,dy\\\\\n & = & \\frac{1}{4\\pi^{2}}\\frac{1}{2}(2\\pi^{2})=\\frac{1}{4}\n\\end{eqnarray*}\n\n\n\\section{In two-dimensions in $(0,1)^{2}$ }\n\nThe equations are the same as (\\ref{eq:nsu})-(\\ref{eq:divu}), but\nthese are the following changes,\n\nOn $\\Omega\\in(0,1)$ with initial condition,\n\\begin{eqnarray*}\nu(\\bm{x},0) & = & \\sin(2\\pi x)\\cos(2\\pi y),\\\\\nv(\\bm{x},0) & = & -\\cos(2\\pi x)\\sin(2\\pi y).\n\\end{eqnarray*}\n This has the following exact solution,\n\\begin{eqnarray*}\nu(\\bm{x},t) & = & \\sin(2\\pi x)\\cos(2\\pi y)e^{-2\\nu(2\\pi)^{2}t},\\\\\nv(\\bm{x},t) & = & -\\cos(2\\pi x)\\sin(2\\pi y)e^{-2\\nu(2\\pi)^{2}t},\\\\\np(\\bm{x},t) & = & -\\left(\\cos(2\\left(2\\pi x\\right))+\\cos(2\\left(2\\pi y\\right))\\right)e^{-4\\nu(2\\pi)^{2}t}.\n\\end{eqnarray*}\n This therefore has the total energy decay like,\n\\[\nE=\\frac{1}{\\Omega}\\frac{1}{2}\\int_{\\Omega}\\left(u^{2}+v^{2}\\right)d\\Omega\\quad\\Omega\\in(0,1)^{2}\n\\]\n which gives,\n\\[\nE(t)=\\frac{1}{2}e^{-4\\nu(2\\pi)^{2}t}.\n\\]\n Computing the energy at $t=0$,\n\\begin{eqnarray*}\nE(0) & = & \\frac{1}{1}\\frac{1}{2}\\int_{0}^{1}\\int_{0}^{1}\\sin^{2}(2\\pi x)\\cos^{2}(2\\pi y)+\\cos^{2}(2\\pi x)\\sin^{2}(2\\pi y)\\,dx\\,dy\\\\\n & = & \\frac{1}{2}(\\frac{1}{2})=\\frac{1}{4}.\n\\end{eqnarray*}\n\n\n\\section{In three-dimensions in $(0,2\\pi)^{3}$ }\n\nThe equations we solve are,\n\\begin{eqnarray}\n\\frac{\\partial u}{\\partial t}+u\\frac{\\partial u}{\\partial x}+v\\frac{\\partial u}{\\partial y}+w\\frac{\\partial u}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial x}+\\nu\\left(\\frac{\\partial^{2}u}{\\partial x^{2}}+\\frac{\\partial^{2}u}{\\partial y^{2}}+\\frac{\\partial^{2}u}{\\partial z^{2}}\\right),\\label{eq:nsu-1}\\\\\n\\frac{\\partial v}{\\partial t}+u\\frac{\\partial v}{\\partial x}+v\\frac{\\partial v}{\\partial y}+w\\frac{\\partial v}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial y}+\\nu\\left(\\frac{\\partial^{2}v}{\\partial x^{2}}+\\frac{\\partial^{2}v}{\\partial y^{2}}+\\frac{\\partial^{2}v}{\\partial z^{2}}\\right),\\label{eq:nsv-1}\\\\\n\\frac{\\partial w}{\\partial t}+u\\frac{\\partial w}{\\partial x}+v\\frac{\\partial w}{\\partial y}+w\\frac{\\partial w}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial z}+\\nu\\left(\\frac{\\partial^{2}w}{\\partial x^{2}}+\\frac{\\partial^{2}w}{\\partial y^{2}}+\\frac{\\partial^{2}w}{\\partial z^{2}}\\right),\\\\\n\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z} & = & 0.\\label{eq:divu-1}\n\\end{eqnarray}\nOn $\\Omega\\in(0,2\\pi)^{3}$ with initial condition,\n\\begin{eqnarray*}\nu(\\bm{x},0) & = & \\sin(x)\\cos(y)\\cos(z),\\\\\nv(\\bm{x},0) & = & -\\cos(x)\\sin(y)\\cos(z).\\\\\nw(\\bm{x},0) & = & 0.\n\\end{eqnarray*}\n\nI think this has exact solution,\n\\begin{eqnarray*}\nu(\\bm{x},t) & = & \\sin(x)\\cos(y)\\cos(z)e^{-3\\nu t},\\\\\nv(\\bm{x},t) & = & -\\cos(x)\\sin(y)\\cos(z)e^{-3\\nu t},\\\\\nw(\\bm{x},t) & = & ?\\\\\np(\\bm{x},t) & = & -\\left(\\cos(2x)+\\cos(2y)\\right)\\left(\\cos(z)\\right)^{2}e^{-6\\nu t}.\n\\end{eqnarray*}\n and therefor this has the following energy per unit volume,\n\n\\begin{eqnarray*}\nE & = & \\frac{1}{8\\pi^{3}}\\frac{1}{2}\\int_{\\Omega}\\left(u^{2}+v^{2}+w^{2}\\right)d\\Omega\\quad\\Omega\\in(0,2\\pi)^{3}\\\\\n & \\approx & \\frac{1}{8\\pi^{3}}\\frac{1}{2}e^{-6\\nu t}\\int_{\\Omega}\\left(u^{2}+v^{2}+w^{2}\\right)d\\Omega\\quad\\Omega\\in(0,2\\pi)^{3}\n\\end{eqnarray*}\n\nComputing the initial energy,\n\\begin{eqnarray*}\nE(0) & = & \\frac{1}{8\\pi^{3}}\\frac{1}{2}\\int_{0}^{2\\pi}\\int_{0}^{2\\pi}\\int_{0}^{2\\pi}\\sin^{2}(x)\\cos^{2}(y)\\cos^{2}(z)+\\cos^{2}(x)\\sin^{2}(y)\\cos^{2}(z)\\,dx\\,dy\\,dz\\\\\n & = & \\frac{1}{8\\pi^{3}}\\frac{1}{2}\\left(2\\pi^{3}\\right)=\\frac{1}{8}\n\\end{eqnarray*}\n\n\n\\section{In three-dimensions in $(0,1)^{3}$ }\n\nThe equations we solve are,\n\\begin{eqnarray}\n\\frac{\\partial u}{\\partial t}+u\\frac{\\partial u}{\\partial x}+v\\frac{\\partial u}{\\partial y}+w\\frac{\\partial u}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial x}+\\nu\\left(\\frac{\\partial^{2}u}{\\partial x^{2}}+\\frac{\\partial^{2}u}{\\partial y^{2}}+\\frac{\\partial^{2}u}{\\partial z^{2}}\\right),\\label{eq:nsu-1-1}\\\\\n\\frac{\\partial v}{\\partial t}+u\\frac{\\partial v}{\\partial x}+v\\frac{\\partial v}{\\partial y}+w\\frac{\\partial v}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial y}+\\nu\\left(\\frac{\\partial^{2}v}{\\partial x^{2}}+\\frac{\\partial^{2}v}{\\partial y^{2}}+\\frac{\\partial^{2}v}{\\partial z^{2}}\\right),\\label{eq:nsv-1-1}\\\\\n\\frac{\\partial w}{\\partial t}+u\\frac{\\partial w}{\\partial x}+v\\frac{\\partial w}{\\partial y}+w\\frac{\\partial w}{\\partial z} & = & -\\frac{1}{\\rho_{0}}\\frac{\\partial p}{\\partial z}+\\nu\\left(\\frac{\\partial^{2}w}{\\partial x^{2}}+\\frac{\\partial^{2}w}{\\partial y^{2}}+\\frac{\\partial^{2}w}{\\partial z^{2}}\\right),\\\\\n\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z} & = & 0.\\label{eq:divu-1-1}\n\\end{eqnarray}\nOn $\\Omega\\in(0,2\\pi)^{3}$ with initial condition,\n\\begin{eqnarray*}\nu(\\bm{x},0) & = & \\sin(2\\pi x)\\cos(2\\pi y)\\cos(2\\pi z),\\\\\nv(\\bm{x},0) & = & -\\cos(2\\pi x)\\sin(2\\pi y)\\cos(2\\pi z).\\\\\nw(\\bm{x},0) & = & 0.\n\\end{eqnarray*}\n\nI think this has exact solution,\n\\begin{eqnarray*}\nu(\\bm{x},t) & = & \\sin(2\\pi x)\\cos(2\\pi y)\\cos(2\\pi z)e^{-3\\left(2\\pi\\right)^{2}\\nu t},\\\\\nv(\\bm{x},t) & = & -\\cos(2\\pi x)\\sin(2\\pi y)\\cos(2\\pi z)e^{-3\\left(2\\pi\\right)^{2}\\nu t},\\\\\nw(\\bm{x},t) & = & ?\\\\\np(\\bm{x},t) & = & -\\left(\\cos(2x2\\pi)+\\cos(2y2\\pi)\\right)\\left(\\cos(2\\pi z)\\right)^{2}e^{-6\\left(2\\pi\\right)^{2}\\nu t}.\n\\end{eqnarray*}\n and therefor this has the following energy,\n\n\\begin{eqnarray*}\nE & = & \\frac{1}{2}\\int_{\\Omega}\\left(u^{2}+v^{2}+w^{2}\\right)d\\Omega\\quad\\Omega\\in(0,2\\pi)^{3}\\\\\n & \\approx & \\frac{1}{2}e^{-6\\left(2\\pi\\right)^{2}\\nu t}\\int_{\\Omega}\\left(u^{2}+v^{2}+w^{2}\\right)d\\Omega\\quad\\Omega\\in(0,2\\pi)^{3}\n\\end{eqnarray*}\nComputing the energy at $t=0,$\n\\begin{eqnarray*}\nE(0) & = & \\frac{1}{1}\\frac{1}{2}\\int_{0}^{1}\\int_{0}^{1}\\int_{0}^{1}\\sin^{2}(2\\pi x)\\cos^{2}(2\\pi y)\\cos^{2}(2\\pi z)+\\cos^{2}(2\\pi x)\\sin^{2}(2\\pi y)\\cos^{2}(2\\pi z)\\,dx\\,dy\\,dz\\\\\n & = & \\frac{1}{1}\\frac{1}{2}\\left(\\frac{1}{4}\\right)=\\frac{1}{8}\n\\end{eqnarray*}\n\n\\end{document}\n", "meta": {"hexsha": "2fc60bd77054781a72ee66c925e9aa78a2413b78", "size": 8757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TaylorGreen/TaylorGreenSolutionDomain.tex", "max_stars_repo_name": "beganthewit/dns", "max_stars_repo_head_hexsha": "612992819aa373157c744f6a92ddb7a2e4b78143", "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": "TaylorGreen/TaylorGreenSolutionDomain.tex", "max_issues_repo_name": "beganthewit/dns", "max_issues_repo_head_hexsha": "612992819aa373157c744f6a92ddb7a2e4b78143", "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": "TaylorGreen/TaylorGreenSolutionDomain.tex", "max_forks_repo_name": "beganthewit/dns", "max_forks_repo_head_hexsha": "612992819aa373157c744f6a92ddb7a2e4b78143", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-03-07T09:47:39.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-07T09:47:39.000Z", "avg_line_length": 49.4745762712, "max_line_length": 325, "alphanum_fraction": 0.6046591298, "num_tokens": 3761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6441033848375689}}
{"text": "\\section{General definitions and notation}\n\n\\begin{myNot}[Spatial dimension\\coderm{BoSSS.Foundation.Grid.Simplex.SpatialDimension}]\nWill be denoted as $D \\in \\natWoZero$ in below;\n\\end{myNot}\n\n\\begin{myNot}[standard symbols]\nWithin this text, the following symbols are used:\n\\begin{packed_itemize}\n  \\item the unit sphere $\\mathcal{S}_D = \\{ \\vec{x} \\in \\real^D; \\ |\\vec{x}|_2 < 1 \\}$\n  \\item the symmetric group $S^n = \\{ \\tau:\\{0,\\cdots,n-1\\}\\rightarrow\\{0,\\cdots,n-1\\}; \\tau \\textrm{ is bijective} \\}$, i.e. the group of all permutations of length $n$;\n  \\item the Sobolev space\n        $H^l(\\Omega) = \\left\\{ f \\in L^2(\\Omega); \\ \\sum_{|\\alpha | \\leq l} \\left\\| \\partial^\\alpha f \\right\\|_2^2 < \\infty \\right\\}$,\n        where $\\alpha$ denotes a multindex.\n\\end{packed_itemize}\n\\end{myNot}\n\n\\begin{myNot}[inner product] The inner product in a domain $K \\subset \\real^D$,\nfor $f,g \\in L^2(K)$ will be denoted and is defined (in BoSSS) by\n\\[\n  \\langle f,g \\rangle_K := \\int_K f(\\vec{x}) \\cdot g(\\vec{x}) \\ d\\vec{x}.\n\\]\n\\end{myNot}\n\n\\begin{myDef}[Convex Hull]\nFor a given list of vertices,\n$\\left( \\vec{v}_1,\\ldots,\\vec{v}_n \\right) \\in \\real^{D \\times n}$\nthe ($D$-dimensional) convex hull is defined as the set\n\\[\n  \\left\\{ \\sum_{i=1}^n \\alpha_i \\cdot \\vec{v}_i \\in \\real^D, \\ \\textrm{where} \\ \\sum_{i=1}^n \\alpha_i \\leq 1 \\right\\}\n  =:\n  CH \\left( \\vec{v}_1,\\ldots,\\vec{v}_n \\right) \\subset \\real^D\n\\]\n\\end{myDef}\n\n\\begin{myDef}[Quadrature rule]\nA quadrature rule with $k$ Nodes within a bounded domain $K \\subset \\real^D$ is a Tuple\n\\[\n \\left[ \\left( \\vec{y}_i\\right)_{i=0,\\ldots,k-1}, \\left( \\beta_i \\right)_{i=0,\\ldots,k-1}, p_\\textrm{ord} \\right]\n \\in \\real^{D\\times k} \\times \\real^k \\times \\nat\n\\]\nfor which the equation\n\\[\n  \\int_{\\vec{x} \\in K} p( \\vec{x} ) \\ d\\vec{x} = \\sum_{i=0}^{k-1} p(\\vec{y}_i) \\cdot \\beta_i\n\\]\nholds for all polynomials $p$ with $\\deg(p) \\leq p_\\textrm{ord}$. The rule is called to\nbe of order $p_\\textrm{ord}$, $\\vec{y}_i$ are called the nodes and $\\beta_i$ are called the weights of the\nquadrature rule.\n\\end{myDef}\n", "meta": {"hexsha": "d775588182911234d393d816cdc3682512a8d863", "size": 2054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/notes/0001-L2_Manual/layer_2_general.tex", "max_stars_repo_name": "FDYdarmstadt/BoSSS", "max_stars_repo_head_hexsha": "974f3eee826424a213e68d8d456d380aeb7cd7e9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2017-06-08T05:53:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T13:12:17.000Z", "max_issues_repo_path": "doc/notes/0001-L2_Manual/layer_2_general.tex", "max_issues_repo_name": "leyel/BoSSS", "max_issues_repo_head_hexsha": "39f58a1a64a55e44f51384022aada20a5b425230", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-20T15:32:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-20T15:34:22.000Z", "max_forks_repo_path": "doc/notes/0001-L2_Manual/layer_2_general.tex", "max_forks_repo_name": "leyel/BoSSS", "max_forks_repo_head_hexsha": "39f58a1a64a55e44f51384022aada20a5b425230", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2018-01-05T19:52:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-07T07:49:27.000Z", "avg_line_length": 41.08, "max_line_length": 170, "alphanum_fraction": 0.6494644596, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6441033830681635}}
{"text": "\\section{Linear algebra}\\label{sec:linear_algebra}\n\nLinear algebra is a branch of mathematics that is both very accessible and enormously useful. It studies \\hyperref[def:vector_space]{vector spaces}, mostly over \\hyperref[def:set_of_real_numbers]{real} or \\hyperref[def:set_of_complex_numbers]{complex} numbers, and \\hyperref[def:linear_operator]{linear maps} between them. For \\hyperref[def:vector_space_dimension]{finite-dimensional} vector spaces, this reduces to studying \\hyperref[def:array/matrix]{matrices}, which also leads to a very rich computational theory.\n", "meta": {"hexsha": "cbca6e7022d0cec9aa28f5bd2fdc03483f528135", "size": 570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra.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/linear_algebra.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/linear_algebra.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": 142.5, "max_line_length": 517, "alphanum_fraction": 0.8192982456, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6439631386737513}}
{"text": "% ------------------------------------------------------------------\n\\chapter{Neural Network Computations}\\label{s:fundamentals}\n% ------------------------------------------------------------------\n\nThis chapter provides a brief introduction to the computational aspects of neural networks, and convolutional neural networks in particular, emphasizing the concepts required to understand and use \\matconvnet.\n\n% ------------------------------------------------------------------\n\\section{Overview}\\label{s:cnn-structure}\n% ------------------------------------------------------------------\n\nA \\emph{Neural Network} (NN) is a function $g$ mapping data $\\bx$, for example an image, to an output vector $\\by$, for example an image label. The function $g=f_L \\circ \\dots \\circ f_1$ is the composition of a sequence of simpler functions $f_l$, which are called \\emph{computational blocks} or \\emph{layers}. Let $\\bx_1,\\bx_2,\\dots,\\bx_L$ be the outputs of each layer in the network, and let $\\bx_0=\\bx$ denote the network input. Each intermediate output $\\bx_l = f_l(\\bx_{l-1};\\bw_l)$ is computed from the previous output $\\bx_{l-1}$  by applying the function $f_l$ with parameters $\\bw_l$. \n\nIn a \\emph{Convolutional Neural Network} (CNN), the data has a spatial structure: each $\\bx_l\\in\\mathbb{R}^{H_l \\times W_l \\times C_l}$ is a 3D array or \\emph{tensor} where the first two dimensions $H_l$ (height) and $W_l$ (width) are interpreted as spatial dimensions. The third dimension $C_l$ is instead interpreted as the \\emph{number of feature channels}. Hence, the tensor $\\bx_l$ represents a $H_l \\times W_l$ field of $C_l$-dimensional feature vectors, one for each spatial location. A fourth dimension $N_l$ in the tensor spans multiple data samples packed in a single \\emph{batch} for efficiency parallel processing. The number of data samples $N_l$ in a batch is called the batch \\emph{cardinality}. The network is called \\emph{convolutional} because the functions $f_l$ are local and translation invariant operators (i.e.\\ non-linear filters) like linear convolution.\n\nIt is also possible to conceive CNNs with more than two spatial dimensions, where the additional dimensions may represent volume or time. In fact, there are little \\emph{a-priori} restrictions on the format of data in neural networks in general. Many useful NNs contain a mixture of convolutional layers together with layer that process other data types such as text strings, or perform other operations that do not strictly conform  to the CNN assumptions.\n\n\\matconvnet includes a variety of layers, contained in the !matlab/! directory, such as !vl_nnconv! (convolution), !vl_nnconvt! (convolution transpose or deconvolution), !vl_nnpool! (max and average pooling), !vl_nnrelu! (ReLU activation), !vl_nnsigmoid! (sigmoid activation), !vl_nnsoftmax! (softmax operator), !vl_nnloss! (classification log-loss), !vl_nnbnorm! (batch normalization), !vl_nnspnorm! (spatial normalization), !vl_nnnormalize! (locar response normalization -- LRN), or !vl_nnpdist! ($p$-distance).  There are enough layers to implement many interesting state-of-the-art networks out of the box, or even import them from other toolboxes such as Caffe. \n\nNNs are often used as classifiers or regressors. In the example of \\cref{f:demo}, the output $\\hat \\by = f(\\bx)$ is a vector of probabilities, one for each of a 1,000 possible image labels (dog, cat, trilobite, ...).  If $\\by$ is the true label of image $\\bx$, we can measure the CNN performance by a loss function $\\ell_\\by(\\hat \\by)  \\in \\mathbb{R}$ which assigns a penalty to classification errors. The CNN parameters can then be tuned or \\emph{learned} to minimize this loss averaged over a large dataset of labelled example images.\n\nLearning generally uses a variant of \\emph{stochastic gradient descent} (SGD). While this is an efficient method (for this type of problems), networks may contain several million parameters and need to be trained on millions of images; thus, efficiency is a paramount in \\matlab design, as further discussed in \\cref{s:speed}. SGD also requires to compute the CNN derivatives, as explained in the next section.\n\n% ------------------------------------------------------------------\n\\section{Network structures}\\label{s:cnn-topology}\n% ------------------------------------------------------------------\n\nIn the simplest case, layers in a NN are arranged in a sequence; however, more complex interconnections are possible as well, and in fact very useful in many cases. This section discusses such configurations and introduces a graphical notation to visualize them.\n\n% ------------------------------------------------------------------\n\\subsection{Sequences}\\label{s:cnn-simple}\n% ------------------------------------------------------------------\n\nStart by considering a computational block $f$ in the network. This can be represented schematically as a box receiving data $\\bx$ and parameters $\\bw$ as inputs and producing data $\\by$ as output:\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (x) [data] {$\\bx$};\n\\node (f) [block,right of=x]{$f$};\n\\node (y) [data, right of=f] {$\\by$};\n\\node (w) [data, below of=f] {$\\bw$};\n\\draw [to] (x.east) -- (f.west) {};\n\\draw [to] (f.east) -- (y.west) {};\n\\draw [to] (w.north) -- (f.south) {};\n\\end{tikzpicture}\n\\end{center}\nAs seen above, in the simplest case blocks are chained in a sequence $f_1 \\rightarrow f_2\\rightarrow\\dots\\rightarrow f_L$ yielding the structure:\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (x0)  [data] {$\\bx_0$};\n\\node (f1) [block,right of=x0]{$f_1$};\n\\node (f2) [block,right of=f1,node distance=3cm]{$f_2$};\n\\node (dots) [right of=f2]{...};\n\\node (fL) [block,right of=dots]{$f_L$};\n\\node (xL)  [data, right of=fL] {$\\bx_L$};\n\\node (w1) [data, below of=f1] {$\\bw_1$};\n\\node (w2) [data, below of=f2] {$\\bw_2$};\n\\node (wL) [data, below of=fL] {$\\bw_L$};\n\\draw [to] (x0.east) -- (f1.west) {};\n\\draw [to] (f1.east) -- node {$\\bx_1$} (f2.west);\n\\draw [to] (f2.east) -- node {$\\bx_2$} (dots.west) {};\n\\draw [to] (dots.east) -- node {$\\bx_{L-1}$} (fL.west) {};\n\\draw [to] (fL.east) -- (xL.west) {};\n\\draw [to] (w1.north) -- (f1.south) {};\n\\draw [to] (w2.north) -- (f2.south) {};\n\\draw [to] (wL.north) -- (fL.south) {};\n\\end{tikzpicture}\n\\end{center}\nGiven an input $\\bx_0$, evaluating the network is a simple matter of evaluating all the blocks from left to right, which defines a composite function $\\bx_L = f(\\bx_0;\\bw_1,\\dots,\\bw_L)$. \n\n% ------------------------------------------------------------------\n\\subsection{Directed acyclic graphs}\\label{s:cnn-dag}\n% ------------------------------------------------------------------\n\n\\begin{figure}[t]\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=0.4cm]\n \\matrix (m) [matrix of math nodes, \n    column sep=1.2cm,\n    row sep=0.4cm]\n{\n& \\node (f1) [block]{f_1}; \n& \\node (x1) [datac]{\\bx_1};\n\\\\\n\\node (x0) [datac]{\\bx_0};\n&\n&\n& \\node (f3) [block]{f_3};\n& \\node (x3) [datac]{\\bx_3};\n\\\\\n& \\node (f2) [block]{f_2}; \n& \\node (x2) [datac]{\\bx_2};\n& &\n& \\node (f5) [block]{f_5}; \n& \\node (x7) [datac]{\\bx_7}; \n\\\\\n& \n& \\node(x5) [datac]{\\bx_5};\n\\\\\n\\node (x4) [datac]{\\bx_4};\n& \\node (f4) [block]{f_4};\n\\\\\n& \n& \\node(x6) [datac]{\\bx_6};\n\\\\\n};\n\\draw[to] (x0) -- (f1);\n\\draw[to] (f1) -- (x1);\n\\draw[to] (x1) -- (f3);\n\\draw[to] (x0) -- (f2);\n\\draw[to] (f2) -- (x2);\n\\draw[to] (x2) -- (f3);\n\\draw[to] (f3) -- (x3);\n\\draw[to] (x3) -- (f5);\n\\draw[to] (f5) -- (x7);\n\\draw[to] (x4) -- (f4);\n\\draw[to] (f4) -- (x5);\n\\draw[to] (f4) -- (x6);\n\\draw[to] (x5) -- (f5);\n\\node(w1) [par,below=of f1]{$\\bw_1$}; \\draw[to] (w1) -- (f1);\n\\node(w2) [par,below=of f2]{$\\bw_2$}; \\draw[to] (w2) -- (f2);\n%\\node(w3) [par,below=of f3]{$\\bw_3$}; \\draw[to] (w3) -- (f3);\n\\node(w4) [par,below=of f4]{$\\bw_4$}; \\draw[to] (w4) -- (f4);\n\\draw[to] (w4) to [bend right] (f3);\n\\node(w5) [par,below=of f5]{$\\bw_5$}; \\draw[to] (w5) -- (f5);\n\\end{tikzpicture}\n\\end{center}\n\\vspace{-1em}\n\\caption{\\textbf{Example DAG.}}\\label{f:dag}\n\\end{figure}\n\nOne is not limited to chaining layers one after another. In fact, the only requirement for evaluating a NN is that, when a layer has to be evaluated, all its input have been evaluated prior to it. This is possible exactly when the interconnections between layers form a \\emph{directed acyclic graph}, or DAG for short.\n\nIn order to visualize DAGs, it is useful to introduce additional nodes for the network variables, as in the  example of Fig.~\\ref{f:dag}. Here boxes denote functions and circles denote variables (parameters are treated as a special kind of variables). In the example, $\\bx_0$ and $\\bx_4$ are the inputs of the CNN and $\\bx_6$ and $\\bx_7$ the outputs. Functions can take any number of inputs (e.g. $f_3$ and $f_5$ take two) and have any number of outputs (e.g. $f_4$ has two). There are a few noteworthy properties of this graph:\n\n\\begin{enumerate}\n\\item The graph is bipartite, in the sense that arrows always go from boxes to circles and from circles to boxes. \n\\item Functions can have any number of inputs or outputs; variables and parameters can have an arbitrary number of outputs (a parameter with more of one output is \\emph{shared} between different layers); variables have at most one input and parameters none. \n\\item Variables with no incoming arrows and parameters are not computed by the network, but must be set prior to evaluation, i.e.\\ they are \\emph{inputs}. Any variable (or even parameter) may be used as output, although these are usually the variables with no outgoing arrows.\n\\item Since the graph is acyclic, the CNN can be evaluated by sorting the functions and computing them one after another (in the example, evaluating the functions in the order $f_1,f_2,f_3,f_4,f_5$ would work).\n\\end{enumerate}\n\n% ------------------------------------------------------------------\n\\section{Computing derivatives with backpropagation}\\label{s:back}\n% ------------------------------------------------------------------\n\nLearning a NN requires computing the derivative of the loss with respect to the network parameters. Derivatives are computed using an algorithm called \\emph{backpropagation}, which is a memory-efficient implementation of the chain rule for derivatives. First, we discuss the derivatives of a single layer, and then of a whole network.\n\n\\subsection{Derivatives of tensor functions}\n\nIn a CNN, a layer is a function $\\by = f(\\bx)$ where both input $\\bx \\in \\mathbb{R}^{H\\times W \\times C}$ and output $\\by \\in \\mathbb{R}^{H'\\times W' \\times C'}$ are tensors. The derivative of the function $f$ contains the derivative of each output component $y_{i'j'k'}$ with respect to each input component $x_{ijk}$, for a total of $H'\\times W'\\times C'\\times H\\times W\\times C$ elements naturally arranged in a 6D tensor. Instead of expressing derivatives as tensors, it is often useful  to switch to a matrix notation by \\emph{stacking} the input and output tensors into vectors. This is done by the $\\vv$ operator, which visits each element of a tensor in lexicographical order and produces a vector:\n\\[\n  \\vv \\bx\n  =\n  \\begin{bmatrix}\n  x_{111} \\\\\n  x_{211} \\\\\n  \\vdots\n  \\\\\n  x_{H11} \\\\\n  x_{121} \\\\\n  \\vdots \\\\\n  x_{HWC}  \t\n  \\end{bmatrix}.\n\\]\nBy stacking both input and output, each layer $f$ can be seen reinterpreted as vector function $\\vv f$, whose derivative is the conventional Jacobian matrix:\n\\[\n\\renewcommand*{\\arraystretch}{1.5}\n\\frac{d \\vv f}{d(\\vv \\bx)^\\top}\n=\n\\begin{bmatrix}\n\\frac{\\partial y_{111}}{\\partial x_{111}} & \n\\frac{\\partial y_{111}}{\\partial x_{211}} &\n\\dots &\n\\frac{\\partial y_{111}}{\\partial x_{H11}} &\n\\frac{\\partial y_{111}}{\\partial x_{121}} &\n\\dots &\n\\frac{\\partial y_{111}}{\\partial x_{HWC}} \\\\\n\\frac{\\partial y_{211}}{\\partial x_{111}} & \n\\frac{\\partial y_{211}}{\\partial x_{211}} &\n\\dots &\n\\frac{\\partial y_{211}}{\\partial x_{H11}} &\n\\frac{\\partial y_{211}}{\\partial x_{121}} &\n\\dots &\n\\frac{\\partial y_{211}}{\\partial x_{HWC}} \\\\\n\\vdots & \\vdots & \\dots & \\vdots & \\vdots & \\dots & \\vdots \\\\\n\\frac{\\partial y_{H'11}}{\\partial x_{111}} & \n\\frac{\\partial y_{H'11}}{\\partial x_{211}} &\n\\dots &\n\\frac{\\partial y_{H'11}}{\\partial x_{H11}} &\n\\frac{\\partial y_{H'11}}{\\partial x_{121}} &\n\\dots &\n\\frac{\\partial y_{H'11}}{\\partial x_{HWC}} \\\\\n\\frac{\\partial y_{121}}{\\partial x_{111}} & \n\\frac{\\partial y_{121}}{\\partial x_{211}} &\n\\dots &\n\\frac{\\partial y_{121}}{\\partial x_{H11}} &\n\\frac{\\partial y_{121}}{\\partial x_{121}} &\n\\dots &\n\\frac{\\partial y_{121}}{\\partial x_{HWC}} \\\\\n\\vdots & \\vdots & \\dots & \\vdots & \\vdots & \\dots & \\vdots \\\\\n\\frac{\\partial y_{H'W'C'}}{\\partial x_{111}} & \n\\frac{\\partial y_{H'W'C'}}{\\partial x_{211}} &\n\\dots &\n\\frac{\\partial y_{H'W'C'}}{\\partial x_{H11}} &\n\\frac{\\partial y_{H'W'C'}}{\\partial x_{121}} &\n\\dots &\n\\frac{\\partial y_{H'W'C'}}{\\partial x_{HWC}}\n\\end{bmatrix}.\n\\]\nThis notation for the derivatives of tensor functions is taken from~\\cite{kinghorn96integrals} and is used throughout this document.\n\nWhile it is easy to express the derivatives of tensor functions as matrices, these matrices are in general extremely large. Even for moderate data sizes (e.g. $H=H'=W=W'=32$ and $C=C'=128$), there are $H'W'C'HWC \\approx 17 \\times 10^9$ elements in the Jacobian. Storing that requires 68 GB of space in single precision. The purpose of the backpropagation algorithm is to compute the derivatives required for learning without incurring this huge memory cost.\n\n\\subsection{Derivatives of function compositions}\n\nIn order to understand backpropagation, consider first a simple CNN terminating in a loss function $f_L = \\ell_\\by$:\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (x0)  [data] {$\\bx_0$};\n\\node (f1) [block,right of=x0]{$f_1$};\n\\node (f2) [block,right of=f1,node distance=3cm]{$f_2$};\n\\node (dots) [right of=f2]{...};\n\\node (fL) [block,right of=dots]{$f_L$};\n\\node (w1) [data, below of=f1] {$\\bw_1$};\n\\node (w2) [data, below of=f2] {$\\bw_2$};\n\\node (wL) [data, below of=fL] {$\\bw_L$};\n\\node (xL) [data, right of=fL] {$x_l\\in\\real$};\n\\draw [to] (x0.east) -- (f1.west) {};\n\\draw [to] (f1.east) -- node {$\\bx_1$} (f2.west);\n\\draw [to] (f2.east) -- node {$\\bx_2$} (dots.west) {};\n\\draw [to] (dots.east) -- node {$\\bx_{L-1}$} (fL.west) {};\n\\draw [to] (fL.east) -- (xL.west) {};\n\\draw [to] (w1.north) -- (f1.south) {};\n\\draw [to] (w2.north) -- (f2.south) {};\n\\draw [to] (wL.north) -- (fL.south) {};\n\\end{tikzpicture}\n\\end{center}\nThe goal is to compute the gradient of the loss value $x_L$ (output) with respect to each network parameter $\\bw_l$:\n\\[\n\\frac{df}{d(\\vv \\bw_l)^\\top} = \n\\frac{d}{d(\\vv \\bw_l)^\\top}\n\\left[f_L(\\cdot;\\bw_L) \\circ ... \\circ \nf_2(\\cdot;\\bw_2) \\circ f_1(\\bx_0;\\bw_1)\\right].\n\\]\nBy applying the chain rule and by using the matrix notation introduced above, the derivative can be written as\n\\begin{equation}\\label{e:chain-rule}\n\\frac{df}{d(\\vv \\bw_l)^\\top} \n= \n\\frac{d\\vv f_L(\\bx_{L-1};\\bw_{L})}{d(\\vv\\bx_{L-1})^\\top}\n\\times\n\\dots\n\\times\n\\frac{d\\vv f_{l+1}(\\bx_{l};\\bw_{l+1})}{d(\\vv\\bx_{l})^\\top}\n\\times\n\\frac{d\\vv f_l(\\bx_{l-1};\\bw_{l})}{d(\\vv\\bw_l^\\top)}\n\\end{equation}\nwhere the derivatives are computed at the working point determined by the input $\\bx_0$ and the current value of the parameters. \n\nNote that, since the network output $x_l$ is a \\emph{scalar} quantity, the target derivative $df/d(\\vv \\bw_l)^\\top$ has the same number of elements of the parameter vector $\\bw_l$, which is moderate. However, the intermediate Jacobian factors have, as seen above, an unmanageable size. In order to avoid computing these factor explicitly, we can proceed as follows.\n\nStart by multiplying the output of the last layer by a tensor $p_L=1$ (note that this tensor is a scalar just like the variable $x_L$):\n\\begin{align*}\np_L \\times \\frac{df}{d(\\vv \\bw_l)^\\top} \n&= \n\\underbrace{p_L \\times \\frac{d\\vv f_L(\\bx_{L-1};\\bw_{L})}{d(\\vv\\bx_{L-1})^\\top}}_{(\\vv \\bp_{L-1})^\\top}\n\\times\n\\dots\n\\times\n\\frac{d\\vv f_{l+1}(\\bx_{l};\\bw_{l+1})}{d(\\vv\\bx_{l})^\\top}\n\\times\n\\frac{d\\vv f_l(\\bx_{l-1};\\bw_{l})}{d(\\vv\\bw_l^\\top)}\n\\\\\n&=\n(\\vv \\bp_{L-1})^\\top\n\\times\n\\dots\n\\times\n\\frac{d\\vv f_{l+1}(\\bx_{l};\\bw_{l+1})}{d(\\vv\\bx_{l})^\\top}\n\\times\n\\frac{d\\vv f_l(\\bx_{l-1};\\bw_{l})}{d(\\vv\\bw_l^\\top)}\n\\end{align*}\nIn the second line the last two factors to the left have been multiplied obtaining a new tensor $\\bp_{L-1}$ that has the same size as the variable $\\bx_{L-1}$. The factor $\\bp_{L-1}$ can therefore be explicitly stored. The construction is then repeated by multiplying pairs of factors from left to right, obtaining a sequence of tensors $\\bp_{L-2},\\dots,\\bp_{l}$ until the desired derivative is obtained. Note that, in doing so, no large tensor is ever stored in memory. This process is known as \\emph{backpropagation}.\n\nIn general, tensor $\\bp_{l}$ is obtained from $\\bp_{l+1}$ as the product:\n\\[\n(\\vv \\bp_{l})^\\top = (\\vv \\bp_{l+1})^\\top \\times \\frac{d\\vv f_{l+1}(\\bx_{l};\\bw_{l+1})}{d(\\vv\\bx_{l})^\\top}.\n\\]\nThe key to implement backpropagation is to be able to compute these products without explicitly computing and storing in memory the second factor, which is a large Jacobian matrix. Since computing the derivative is a linear operation, this product can be interpreted as the \\emph{derivative of the layer projected along direction $\\bp_{l+1}$}: \n\\begin{equation}\\label{e:projected}\n\\bp_{l} = \n\\frac{d \\langle \\bp_{l+1}, f(\\bx_l;\\bw_l) \\rangle}\n{d \\bx_{l}}.\n\\end{equation}\nHere $\\langle \\cdot,\\cdot \\rangle$ denotes the inner product between tensors, which results in a scalar quantity. Hence the derivative \\eqref{e:projected} needs not to use the $\\vv$ notation, and yields a tensor $\\bp_l$ that has the same size as $\\bx_l$ as expected.\n\nIn order to implement backpropagation, a CNN toolbox provides implementations of each layer $f$ that provide:\n\\begin{itemize}\n\\item A \\textbf{forward mode}, computing the output $\\by = f(\\bx;\\bw)$ of the layer given its input $\\bx$ and parameters $\\bw$.\n\\item A \\textbf{backward mode}, computing the projected derivatives\n\\[\n\\frac{d \\langle \\bp, f(\\bx;\\bw) \\rangle}\n{d \\bx}\n\\quad\\text{and}\\quad\n\\frac{d \\langle \\bp, f(\\bx;\\bw) \\rangle}\n{d \\bw},\n\\]\ngiven, in addition to the input $\\bx$ and parameters $\\bw$, a tensor $\\bp$ that the same size as $\\by$.\n\\end{itemize}\nThis is best illustrated with an example. Consider a layer $f$ such as the convolution operator implemented by the \\matconvnet\\ !vl_nnconv! command. In the ``forward'' mode, one calls the function as !y = vl_nnconv(x,w,[])! to apply the filters !w! to the input !x! and obtain the output !y!. In the ``backward mode'', one calls ![dx, dw] = vl_nnconv(x,w,[],p)!.  As explained above, !dx!, !dw!, and !p! have the same size as !x!, !w!, and !y!, respectively. The computation of large Jacobian is encapsulated in the function call and never carried out explicitly. \n\n\\subsection{Backpropagation networks}\\label{s:bpnets}\n\nIn this section, we provide a schematic interpretation of backpropagation and show how it can be implemented by ``reversing'' the NN computational graph.\n\nThe projected derivative of eq.~\\eqref{e:projected} can be seen as the derivative of the following mini-network:\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (x) [data] {$\\bx$};\n\\node (f) [block,right of=x ] {$f$};\n\\node (dot)[block,right of=f ] {$\\langle \\cdot, \\cdot \\rangle$};\n\\node (z) [data, right of=dot] {$z \\in \\mathbb{R}$};\n\\node (w) [data, below of=f ] {$\\bw$};\n\\node (p) [data, below of=dot] {$\\bp$};\n\\draw [to] (x.east) -- (f.west) {};\n\\draw [to] (f.east) -- node {$\\by$}  (dot.west) {};\n\\draw [to] (w.north) -- (f.south) {};\n\\draw [to] (dot.east) -- (z.west) {};\n\\draw [to] (p.north) -- (dot.south) {};\n\\end{tikzpicture}\n\\end{center}\nIn the context of back-propagation, it can be useful to think of the projection $\\bp$ as the ``linearization'' of the rest of the network from variable $\\by$ down to the loss. The projected derivative can also be though of as a new layer $(d\\bx, d\\bw) = df(\\bx,\\bw,\\bp)$ that, by computing the derivative of the mini-network, operates in the reverse direction:\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (df) [block,right of=x] {$df$};\n\\node (dx) [data,left of=df] {$d\\bx$};\n\\node (dw) [data,below of=df] {$d\\bw$};\n\\node (w) [data,above of=df,xshift=0.6em] {$\\bw$};\n\\node (x) [data,above of=df,xshift=-0.6em] {$\\bx$};\n\\node (p) [data,right of=df] {$\\bp$};\n\\draw [to] (df.west) -- (dx.east)  {};\n\\draw [to] (df.south) -- (dw.north)  {};\n\\draw [to] (p.west) -- (f.east) {};\n\\draw [to] (w.south) -- ([xshift=0.6em]df.north) {};\n\\draw [to] (x.south) -- ([xshift=-0.6em]df.north) {};\n\\end{tikzpicture}\n\\end{center}\nBy construction (see eq.~\\eqref{e:projected}), the function $df$ is \\emph{linear} in the argument $\\bp$.\n\nUsing this notation, the forward and backward passes through the original network can be rewritten as evaluating an extended network which contains a BP-reverse of the original one (in blue in the diagram):\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm]\n\\node (x0) [data] {$\\bx_0$};\n%\n\\node (f1) [block,right of=x0] {$f_1$};\n\\node (x1) [data,right of=f1] {$\\bx_{1}$};\n\\node (w1) [data,below of=f1] {$\\bw_1$};\n%\n\\node (f2) [block,right of=x1] {$f_2$};\n\\node (x2) [data,right of=f2] {$\\bx_{2}$};\n\\node (w2) [data,below of=f2] {$\\bw_2$};\n%\n\\node (f3) [right of=x2] {$\\dots$};\n\\node (xLm) [right of=f3] {$\\bx_{L-1}$};\n%\n\\node (fL) [block,right of=xLm] {$f_L$};\n\\node (xL) [data,right of=fL] {$\\bx_{L}$};\n\\node (wL) [data,below of=fL] {$\\bw_L$};\n%\n\\draw [to] (x0.east) -- (f1.west) {};\n%\n\\draw [to] (w1.north) -- (f1.south) {};\n\\draw [to] (f1.east) -- (x1.west) {};\n\\draw [to] (x1.east) -- (f2.west) {};\n%\n\\draw [to] (w2.north) -- (f2.south) {};\n\\draw [to] (f2.east) -- (x2.west) {};\n\\draw [to] (x2.east) -- (f3.west) {};\n%\n\\draw [to] (f3.east) -- (xLm.west) {};\n\\draw [to] (xLm.east) -- (fL.west) {};\n%\n\\draw [to] (wL.north) -- (fL.south) {};\n\\draw [to] (fL.east) -- (xL.west) {};\n%\n\\node (dfL) [block,below of=wL,bp] {$df_L$};\n\\node (dxL) [data,right of=dfL,bpe] {$d\\bp_L$};\n\\node (dwL) [data,below of=dfL,bpe] {$d\\bw_L$};\n\\node (dxLm) [data,left of=dfL,bpe] {$d\\bx_{L-1}$};\n%\n\\node (df3) [left of=dxLm,bpe] {$\\dots$};\n%\n\\node (df2) [block,below of=w2,bp] {$df_2$};\n\\node (dx2) [data,right of=df2,bpe] {$d\\bx_{2}$};\n\\node (dw2) [data,below of=df2,bpe] {$d\\bw_2$};\n%\n\\node (df1) [block,below of=w1,bp] {$df_1$};\n\\node (dx1) [data,right of=df1,bpe] {$d\\bx_{1}$};\n\\node (dw1) [data,below of=df1,bpe] {$d\\bw_1$};\n%\n\\node (dx0) [data,left of=df1,bpe] {$d\\bx_{0}$};\n%\n\\draw [to,bp] (wL.south) -- (dfL.north) {};\n\\draw [to,bp] (dfL.south) -- (dwL.north) {};\n\\draw [to,bp] (dxL.west) -- (dfL.east) {};\n\\draw [to,bp] (dfL.west) -- (dxLm.east) {};\n%\n\\draw [to,bp] (dxLm.west) -- (df3.east) {};\n\\draw [to,bp] (df3.west) -- (dx2.east) {};\n%\n\\draw [to,bp] (w2.south) -- (df2.north) {};\n\\draw [to,bp] (df2.south) -- (dw2.north) {};\n\\draw [to,bp] (dx2.west) -- (df2.east) {};\n\\draw [to,bp] (df2.west) -- (dx1.east) {};\n%\n\\draw [to,bp] (w1.south) -- (df1.north) {};\n\\draw [to,bp] (df1.south) -- (dw1.north) {};\n\\draw [to,bp] (dx1.west) -- (df1.east) {};\n%\n\\draw [to,bp] (df1.west) -- (dx0.east) {};\n%\n\\draw [to,bp] (x0) -- (df1) {} ;\n\\draw [to,bp] (x1) -- (df2) {} ;\n\\draw [to,bp] (xLm) -- (dfL) {} ;\n\\end{tikzpicture}\n\\end{center}\n\n% ------------------------------------------------------------------\n\\subsection{Backpropagation in DAGs}\\label{s:dag}\n% ------------------------------------------------------------------\n\nAssume that the DAG has a single output variable $\\bx_L$ and assume, without loss of generality, that all variables are sorted in order of computation $(\\bx_0,\\bx_1,\\dots,\\bx_{L-1},\\bx_L)$ according to the DAG structure. Furthermore, in order to simplify the notation, assume that this list contains both data and parameter variables, as the distinction is moot for the discussion in this section.\n\nWe can cut the DAG at any point in the sequence by fixing $\\bx_0, \\dots, \\bx_{l-1}$ to some arbitrary value and dropping all the DAG layers that feed into them, effectively transforming the first $l$ variables into inputs. Then, the rest of the DAG defines a function $h_l$ that maps these input variables to the output $\\bx_L$:\n\\[\n \\bx_L = h_l(\\bx_0,\\bx_1,\\dots,\\bx_{l-1}).\n\\]\nNext, we show that backpropagation in a DAG iteratively computes the projected derivatives of all functions $h_1,\\dots,h_L$ with respect to all their parameters.\n\nBackpropagation starts by initializing variables $(d\\bx_{0},\\dots,d\\bx_{l-1})$ to null tensors of the same size as $(\\bx_0,\\dots,\\bx_{l-1})$. Next, it computes the projected derivatives of\n\\[\n \\bx_L = h_L(\\bx_0,\\bx_1,\\dots,\\bx_{L-1}) =\n f_{\\pi_L}(\\bx_0,\\bx_1,\\dots,\\bx_{L-1}).\n\\]\nHere $\\pi_l$ denotes the index of the layer $f_{\\pi_l}$ that computes the value of the variable $\\bx_l$. There is at most one such layer, or none if $\\bx_l$ is an input or parameter of the original NN. In the first case, the layer may depend on any of the variables prior to $\\bx_l$ in the sequence, so that general one has:\n\\[\n \\bx_{l} = f_{\\pi_l}(\\bx_0,\\dots,\\bx_{l-1}).\n\\]\n\tAt the beginning of backpropagation, since there are no intermediate variables between $\\bx_{L-1}$ and $\\bx_L$, the function $h_L$ is the same as the last layer $f_{\\pi_L}$. Thus the projected derivatives of $h_L$ are the same as the projected derivatives of $f_{\\pi_L}$, resulting in the equation\n\\[\n\\forall t=0,\\dots,L-1:\\qquad\nd\\bx_{t} \\leftarrow d\\bx_{t}\n+ \\frac{d\\langle \\bp_L, f_{\\pi_L}(\\bx_0,\\dots,\\bx_{t-1})\\rangle}{d\\bx_t}.\n\\]\nHere, for uniformity with the other iterations, we use the fact that $d\\bx_l$ are initialized to zero an\\emph{accumulate} the values instead of storing them. In practice, the update operation needs to be carried out only for the variables $\\bx_l$ that are actual inputs to $f_{\\pi_L}$, which is often a tiny fraction of all the variables in the DAG.\n\nAfter the update, each $d\\bx_t$ contains the projected derivative of function $h_L$ with respect to the corresponding variable:\n\\[\n\\forall t=0,\\dots,L-1:\\qquad\nd\\bx_t = \\frac{d\\langle \\bp_L, h_L(\\bx_0,\\dots,\\bx_{l-1})\\rangle}{d\\bx_t}.\n\\]\nGiven this information, the next iteration of backpropagation updates the variables to contain the projected derivatives of $h_{L-1}$ instead. In general, given the derivatives of $h_{l+1}$, backpropagation computes the derivatives of $h_{l}$ by using the relation\n\\[\n \\bx_L\n = \n h_{l}(\\bx_0,\\bx_1,\\dots,\\bx_{l-1})\n =\n h_{l+1}(\\bx_0,\\bx_1,\\dots,\\bx_{l-1},f_{\\pi_L}(\\bx_0,\\dots,\\bx_{l-1}))\n\\]\nApplying the chain rule to this expression, for all $0\\leq t \\leq l-1$:\n\\[\n\\frac{d\\langle \\bp, h_l \\rangle}{d(\\vv \\bx_t)^\\top}\n=\n\\frac{d\\langle \\bp, h_{l+1}\\rangle}{d(\\vv \\bx_t)^\\top}\n+\n\\underbrace{\\frac{d\\langle \\bp_L, h_{l+1}\\rangle}{d(\\vv \\bx_l)^\\top}}_{\\vv d\\bx_l}\n\\frac{d \\vv f_{\\pi_l}}{d(\\vv \\bx_t)^\\top}.\n\\]\nThis yields the update equation\n\\begin{equation}\\label{e:bp-update}\t\n\\forall t=0,\\dots,l-1:\\qquad\nd\\bx_t \\leftarrow d\\bx_t + \\frac{d\\langle \\bp_l, f_{\\pi_l}(\\bx_0,\\dots,\\bx_{l-1})\\rangle}{d\\bx_t},\n\\quad\n\\text{where\\ }\n\\bp_l = d\\bx_l.\n\\end{equation}\nOnce more, the update needs to be explicitly carried out only for the variables $\\bx_t$ that are actual inputs of $f_{\\pi_l}$. In particular, if $\\bx_l$ is a data input or a parameter of the original neural network, then $\\bx_l$ does not depend on any other variables or parameters and $f_{\\pi_l}$ is a nullary function (i.e.\\ a function with no arguments). In this case, the update does not do anything. \nAfter iteration $L-l+1$ completes, backpropagation remains with:\n\\begin{align*}\n\\forall t=0,\\dots,l-1:&\\qquad\nd\\bx_t\n=\n\\frac{d\\langle \\bp_L, h_l(\\bx_0,\\dots,\\bx_{l-1})\\rangle}{d\\bx_t}.\n\\end{align*}\nNote that the derivatives for variables $\\bx_t, l \\leq t \\leq L-1$ are not updated since $h_l$ does not depend on any of those. Thus, after all $L$ iterations are complete, backpropagation terminates with\n\\[\n\\forall l=1,\\dots,L:\\qquad\nd\\bx_{l-1}\n=\n\\frac{d\\langle \\bp_L, h_{l}(\\bx_0,\\dots,\\bx_{l-1})\\rangle}{d\\bx_{l-1}}.\n\\]\nAs seen above, functions $h_{l}$ are obtained from the original network $f$ by transforming variables $\\bx_0,\\dots,\\bx_{l-1}$ into to inputs. If $\\bx_{l-1}$ was already an input (data or parameter) of $f$, then the derivative $d\\bx_{l-1}$ is applicable to $f$ as well.\n\nBackpropagation can be summarized as follows:\n\\begin{center}\n\\fbox{\\begin{minipage}{0.95\\textwidth}\nGiven: a DAG neural network $f$ with a single output $\\bx_L$, the values of all input variables (including the parameters), and the value of the projection $\\bp_L$ (usually $\\bx_L$ is a scalar and $\\bp_L = p_L = 1$):\n\\begin{enumerate}\n    \\item Sort all variables by computation order $(\\bx_0,\\bx_1,\\dots,\\bx_L)$ according to the DAG.\n    \\item Perform a forward pass through the network to compute all the intermediate variable values.\n    \\item Initialize $(d\\bx_0, \\dots, d\\bx_{L-1})$ to null tensors with the same size as the corresponding variables.\n    \\item For $l=L,L-1,\\dots,2,1$:\n  \\begin{enumerate}\n  \\item Find the index $\\pi_l$ of the layer $\\bx_{l} = f_{\\pi_l}(\\bx_0,\\dots,\\bx_{l-1})$ that evaluates variable $\\bx_l$. If there is no such layer (because $\\bx_{l}$ is an input or parameter of the network), go to the next iteration.\n  \\item Update the variables using the formula:\n   \\[\n   \\forall t=0,\\dots,l-1:\\qquad\nd\\bx_t \\leftarrow d\\bx_t + \\frac{d\\langle d\\bx_l, f_{\\pi_l}(\\bx_0,\\dots,\\bx_{l-1})\\rangle}{d\\bx_t}.\n   \\]\n   To do so efficiently, use the ``backward mode'' of the layer $f_{\\pi_l}$ to compute its derivative projected onto $d\\bx_l$ as needed.\n  \\end{enumerate}\n  \\end{enumerate}\n\\end{minipage}}\n\\end{center}\n\n% TODO: what to do with multiple outputs\n\n\n\\begin{figure}[t]\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=0.3cm]\n \\matrix (m) [matrix of math nodes, \n    column sep=1.2cm,\n    row sep=0.3cm]\n{\n& \\node (f1) [block]{f_1}; \n& \\node (x1) [datac]{\\bx_1};\n\\\\\n\\node (x0) [datac]{\\bx_0};\n&\n&\n& \\node (f3) [block]{f_3};\n& \\node (x3) [datac]{\\bx_3};\n\\\\\n& \\node (f2) [block]{f_2}; \n& \\node (x2) [datac]{\\bx_2};\n& &\n& \\node (f5) [block]{f_5}; \n& \\node (x7) [datac]{\\bx_7}; \n\\\\\n& \n& \\node(x5) [datac]{\\bx_5};\n\\\\\n\\node (x4) [datac]{\\bx_4};\n& \\node (f4) [block]{f_4};\n\\\\\n& \n& \\node(x6) [datac]{\\bx_6};\n\\\\\n% BP\n& \\node (df1) [block,bp]{df_1}; \n& \\node (dx1) [datac,bp]{d\\bx_1};\n\\\\\n\\node (dx0) [datac,bp]{d\\bx_0};\n&\n&\n& \\node (df3) [block,bp]{df_3};\n& \\node (dx3) [datac,bp]{d\\bx_3};\n\\\\\n& \\node (df2) [block,bp]{df_2}; \n& \\node (dx2) [datac,bp]{d\\bx_2};\n& &\n& \\node (df5) [block,bp]{df_5}; \n& \\node (dx7) [datac,bp]{\\bp_7}; \n\\\\\n& \n& \\node (dx5) [datac,bp]{d\\bx_5};\n\\\\\n\\node (dx4) [datac,bp]{d\\bx_4};\n& \\node (df4) [block,bp]{df_4};\n\\\\\n& \n& \\node(dx6) [datac,bp]{\\bp_6};\n\\\\\n};\n\\draw[to] (x0) -- (f1);\n\\draw[to] (f1) -- (x1);\n\\draw[to] (x1) -- (f3);\n\\draw[to] (x0) -- (f2);\n\\draw[to] (f2) -- (x2);\n\\draw[to] (x2) -- (f3);\n\\draw[to] (f3) -- (x3);\n\\draw[to] (x3) -- (f5);\n\\draw[to] (f5) -- (x7);\n\\draw[to] (x4) -- (f4);\n\\draw[to] (f4) -- (x5);\n\\draw[to] (f4) -- (x6);\n\\draw[to] (x5) -- (f5);\n\\node(w1) [par,below=of f1]{$\\bw_1$}; \\draw[to] (w1) -- (f1);\n\\node(w2) [par,below=of f2]{$\\bw_2$}; \\draw[to] (w2) -- (f2);\n\\node(w4) [par,below=of f4]{$\\bw_4$}; \\draw[to] (w4) -- (f4);\n\\draw[to] (w4) to [bend right] (f3);\n\\node(w5) [par,below=of f5]{$\\bw_5$}; \\draw[to] (w5) -- (f5);\n\\node (dx0s) [right of=dx0,xshift=20pt,draw,rectangle,bp]{$\\Sigma$};\n\\draw[from,bp] (dx0) -- (dx0s);\n\\draw[from,bp] (dx0s) -- (df1);\n\\draw[from,bp] (df1) -- (dx1);\n\\draw[from,bp] (dx1) -- (df3);\n\\draw[from,bp] (dx0s) -- (df2);\n\\draw[from,bp] (df2) -- (dx2);\n\\draw[from,bp] (dx2) -- (df3);\n\\draw[from,bp] (df3) -- (dx3);\n\\draw[from,bp] (dx3) -- (df5);\n\\draw[from,bp] (df5) -- (dx7);\n\\draw[from,bp] (dx4) -- (df4);\n\\draw[from,bp] (df4) -- (dx5);\n\\draw[from,bp] (df4) -- (dx6);\n\\draw[from,bp] (dx5) -- (df5);\n\\node(dw1) [par,below=of df1,bp]{$d\\bw_1$}; \\draw[from,bp] (dw1) -- (df1);\n\\node(dw2) [par,below=of df2,bp]{$d\\bw_2$}; \\draw[from,bp] (dw2) -- (df2);\n\\node(dw4s) [below of=df4,draw,rectangle,bp,yshift=-25pt]{$\\Sigma$}; \\draw[from,bp] (dw4s) -- (df4);\n\\node(dw4) [par,below=of dw4s,bp]{$d\\bw_4$}; \\draw[from,bp] (dw4) -- (dw4s);\n\\draw[from,bp] (dw4s) to [bend right,bp] (df3);\n\\node(dw5) [par,below=of df5,bp]{$d\\bw_5$}; \\draw[from,bp] (dw5) -- (df5);\n%\n\\draw[to,bpl] (x0) -| ([xshift=-0.3cm]x0.west) |- (df1);\n\\draw[to,bpl] (x0) -| ([xshift=-0.6cm]x0.west) |- (df2);\n\\draw[to,bpl] (x1) -| ([xshift=4cm]x1.west) |- ([yshift=10pt]df3.east);\n\\draw[to,bpl] (x2) -| (df3);\n\\draw[to,bpl] (x3) -| ([xshift=+5cm]x3.east) |- ([yshift=15pt]df5.east);\n\\draw[to,bpl] (x4) to [bend right=75] ([yshift=15pt]df4.west);\n\\draw[to,bpl] (x5) to [bend left] (df5);\n\\end{tikzpicture}\n\\end{center}\n\\vspace{-1em}\n\\caption{\\textbf{Backpropagation network for a DAG.}}\\label{f:dagbp}\n\\end{figure}\n\n% ------------------------------------------------------------------\n\\subsection{DAG backpropagation networks}\\label{s:bpnets-dag}\n% ------------------------------------------------------------------\n\nJust like for sequences, backpropagation in DAGs can be implemented as a corresponding BP-reversed DAG. To construct the reversed DAG:\n\\begin{enumerate}\n\\item For each layer $f_l$, and variable/parameter $\\bx_t$ and $\\bw_l$, create a corresponding layer $df_l$ and variable/parameter $d\\bx_t$ and $d\\bw_l$.\n\\item If a variable $\\bx_t$ (or parameter $\\bw_l$) is an input of $f_l$, then it is an input of $df_l$ as well.\n\\item If a variable $\\bx_t$ (or parameter $\\bw_l$) is an input of $f_l$, then the variable $d\\bx_t$ (or the parameter $d\\bw_l$) is an output $df_l$.\n\\item In the previous step, if a variable $\\bx_t$ (or parameter $\\bw_l$) is input to two or more layers in $f$, then $d\\bx_t$ would be the output of two or more layers in the reversed network, which creates a conflict. Resolve these conflicts by inserting a summation layer that adds these contributions (this corresponds to the summation in the BP update equation \\eqref{e:bp-update}).\n\\end{enumerate}\nThe BP network corresponding to the DAG of Fig.~\\ref{f:dag} is given in Fig.~\\ref{f:dagbp}.\n\n\n", "meta": {"hexsha": "b9bced9327c0330e6604f5d0e7aee1ea2d23b724", "size": 33879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ADSH_matlab/matconvnet/doc/fundamentals.tex", "max_stars_repo_name": "ZiTian8/ADSH-AAAI2018", "max_stars_repo_head_hexsha": "f03cb71d347e86687b6f6bbd20e0f85a1e0d4ef1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 86, "max_stars_repo_stars_event_min_datetime": "2017-11-23T09:59:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T09:38:44.000Z", "max_issues_repo_path": "ADSH_matlab/matconvnet/doc/fundamentals.tex", "max_issues_repo_name": "ZiTian8/ADSH-AAAI2018", "max_issues_repo_head_hexsha": "f03cb71d347e86687b6f6bbd20e0f85a1e0d4ef1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-06-14T03:09:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T03:31:03.000Z", "max_forks_repo_path": "ADSH_matlab/matconvnet/doc/fundamentals.tex", "max_forks_repo_name": "ZiTian8/ADSH-AAAI2018", "max_forks_repo_head_hexsha": "f03cb71d347e86687b6f6bbd20e0f85a1e0d4ef1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 35, "max_forks_repo_forks_event_min_datetime": "2017-11-27T02:00:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-12T08:03:35.000Z", "avg_line_length": 52.0414746544, "max_line_length": 879, "alphanum_fraction": 0.6509637238, "num_tokens": 11510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6439631236563642}}
{"text": "% Created 2021-11-26 Fri 08:58\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation,aspectratio=1610]{beamer}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble, euscript}\n\\DeclareMathOperator{\\atantwo}{atan2}\n\\newcommand*{\\ctrb}{\\EuScript{C}}\n\\newcommand*{\\obsv}{\\EuScript{O}}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{Discrete-time Ouput feedback (state feedback with observer)}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Discrete-time Ouput feedback (state feedback with observer)},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.4.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Discret-time state space model}\n\\label{sec:orgdf25772}\n\\begin{frame}[label={sec:orge5f3d67}]{The discrete-time state-space model}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgc315c14}]{The discrete-time state-space model}\n\\begin{center}\n  \\begin{tikzpicture}[node distance=42mm, block/.style={inner sep=6pt, rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]\n    \\node[coordinate] (input) {};\n    \\node[block, right of=input, align=center] (plant)  {$x(k+1) = \\Phi x(k) + \\Gamma u(k)$\\\\$y(k) = C x(k)$};\n    \\node[coordinate, right of=plant] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org871eb8d}]{Stability}\n\\end{frame}\n\\begin{frame}[label={sec:org5143890}]{Eigenvalues and eigenvectors}\n\\alert{Definition} The eigenvalues \\(\\lambda_i  \\in \\mathbb{R}\\) and eigenvectors \\(v_i \\in \\mathbb{R}^n\\) of a matrix \\(\\Phi \\in \\mathbb{R}^{n\\times{}n}\\) are the \\(n\\) pairs \\((\\lambda_i, v_i \\neq 0 ), \\; i=1,2,\\ldots,n\\) that satisfy\n\\[ \\Phi v_i = \\lambda_i v_i \\]\n\\end{frame}\n\n\\begin{frame}[label={sec:orga4ef6e4}]{Stability}\nThe system\n\\begin{equation*}\nx(k+1)=\\Phi x(k), \\ \\ x(0)=x_0\n\\end{equation*}\nis \\alert{stable} if  \\(\\underset{t\\to\\infty}{\\lim}x(kh)=0, \\quad \\forall\\;  x_0\\in\\Bbb{R}^n\\).\n\nA necessary and sufficient requirement for stability is that \\alert{all the eigenvalues of \\(\\Phi\\) are inside the unit circle.}\n\nThe \\alert{eigenvalues} of \\(\\Phi\\) are the  \\alert{poles} of the system.\n\\end{frame}\n\n\\section{State feedback}\n\\label{sec:org6c54675}\n\\begin{frame}[label={sec:orgaa62416}]{State feedback control}\n\\end{frame}\n\\begin{frame}[label={sec:org6a0dafe}]{State feedback control}\nGiven\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\Phi x(k) + \\Gamma u(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:ssmodel}\n\\end{equation}\nand measurements (or an estimate) of the state vector \\(x(k)\\). \n\n\\alert{Linear state feedback} is the control law\n\\begin{equation*}\n\\begin{split}\n u(k) &= f\\big((x(k), u_c(k)\\big) = -\\textcolor{morange}{l_1}x_1(k) - \\textcolor{morange}{l_2}x_2(k) - \\cdots - \\textcolor{morange}{l_n} x_n(k) + \\textcolor{mbluegreen}{l_0}u_c(k)\\\\\n      &= -\\textcolor{morange}{L}x(k) + \\textcolor{mbluegreen}{l_0}u_c(k), \n\\end{split}\n\\end{equation*}\nwhere \\[ \\textcolor{morange}{L} = \\bbm \\textcolor{morange}{l_1} & \\textcolor{morange}{l_2} & \\cdots & \\textcolor{morange}{l_n} \\ebm. \\]\nSubstituting this in the state-space model \\eqref{eq:ssmodel} gives\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation}\n\\end{frame}\n\n\\begin{frame}[label={sec:org4bdb9dc}]{Pole placement by state feedback}\nGiven (or choosing) a desired placement of the closed-loop poles \\(p_1, p_2, \\ldots, p_n\\), being roots of the desired characteristic polynomial\n\\begin{equation}\na_c(z) = (z-p_1)(z-p_2)\\cdots(z-p_n) = z^n + \\alpha_1 z^{n-1} + \\cdots \\alpha_n.\n\\label{eq:desiredpoles}\n\\end{equation}\n\n\\pause\n\nLinear state feedback gives the system\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation}\nwith characteristic polynomial\n\\begin{equation}\n\\det\\left(zI - (\\Phi - \\Gamma \\textcolor{morange}{L})\\right) = z^n + \\beta_1(\\textcolor{morange}{l_1},\\ldots,\\textcolor{morange}{l_n}) z^{n-1} + \\cdots \\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}).\n\\label{eq:poles}\n\\end{equation}\n\n\\pause\n\nSet the coefficients of the desired characteristic polynomial \\eqref{eq:desiredpoles} equal to the coefficients of \\eqref{eq:poles} to obtain the system of equations\n\\begin{equation*}\n\\begin{split}\n\\beta_1(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_1\\\\\n\\beta_2(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\n\\end{frame}\n\n\\begin{frame}[label={sec:org9823dd3}]{Pole placement by state feedback}\nThe system of equations\n\\begin{equation*}\n\\begin{split}\n\\beta_1(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_1\\\\\n\\beta_2(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\n\nis always linear in the parameters of the controller, hence\n\\begin{equation*}\nM \\textcolor{morange}{L}\\transp = \\alpha,\n\\end{equation*}\nwhere \\(\\alpha\\transp = \\bbm \\alpha_1 & \\alpha_2 & \\cdots & \\alpha_n \\ebm.\\)\n\\end{frame}\n\n\\begin{frame}[label={sec:orgdec3dc3},fragile]{Pole placement by state feedback}\n Given a desired placement of the closed-loop poles \\(p_1, p_2, \\ldots, p_n\\), being roots of the desired characteristic polynomial\n\\begin{equation*}\na_c(z) = (z-p_1)(z-p_2)\\cdots(z-p_n) = z^n + \\alpha_1 z^{n-1} + \\cdots \\alpha_n.\n\\label{eq:desiredpoles}\n\\end{equation*}\nand closed-loop system\n \\begin{equation*}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation*}\n\nThe Matlab (\\emph{control systems toolbox}) has methods for computing the gain vector \\(L\\)\n\n\\begin{enumerate}\n\\item \\alert{Ackerman's method} \n\\begin{verbatim}\nL = acker(Phi, Gamma, pd)\n\\end{verbatim}\n\\item \\alert{Numerically more stable method} \n\\begin{verbatim}\nL = place(Phi, Gamma, pd)\n\\end{verbatim}\n\\end{enumerate}\n\\end{frame}\n\n\\begin{frame}[label={sec:orga3cd068}]{The reference input gain \\(l_0\\)}\nThe closed-loop state space system\n\\begin{equation*}\n\\begin{split}\n x(k+1) &= \\underbrace{\\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right)}_{\\Phi_c} x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n y(k) &= C x(k)\n\\end{split}\n\\end{equation*}\nwith constant reference signal \\(u_c(k) = u_{c,f}\\) has the steady-state solution (\\(x(k+1)=x(k)\\))\n\\pause\n\\[ x_f =  \\textcolor{mbluegreen}{l_0} (I - \\Phi_c)^{-1}\\Gamma u_{c,f}\\]\n\\[ y_f = Cx_f = \\textcolor{mbluegreen}{l_0} C(I - \\Phi_c)^{-1}\\Gamma u_{c,f}.\\]\nWe want \\(y_f =  u_{c,f}\\),\n\\[ \\Rightarrow \\qquad \\textcolor{mbluegreen}{l_0} = \\frac{1}{C(I-\\Phi_c)^{-1}\\Gamma}\\]\n\\end{frame}\n\n\\section{State feedback with observer}\n\\label{sec:org2e8ae4c}\n\\begin{frame}[label={sec:org7e1e842}]{State feedback with reconstructed states}\n\\end{frame}\n\n\\begin{frame}[label={sec:org2a1058e}]{Observer design}\nGiven model\n \\begin{equation*}\n \\begin{split}\n  x(k+1) &= \\Phi x(k) + \\Gamma u(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:ssmodel}\n\\end{equation*}\nand measurements of the output signal \\(y(k)\\). \n\nThe observer is given by\n\\begin{equation*}\n\\begin{split}\n\\hat{x}(k+1) &= \\underbrace{\\Phi \\hat{x}(k) + \\Gamma u(k)}_{\\text{simulation}} + \\underbrace{\\textcolor{mred}{K}\\big(y(k) - C\\hat{x}(k)\\big)}_{\\text{correction}} = \\left(\\Phi - \\textcolor{mred}{K}C\\right)\\hat{x}(k) +  \\Gamma u(k) + \\textcolor{mred}{K}y(k)\n\\end{split}\n\\end{equation*}\nwith poles given by the eigenvalues of the matrix \\(\\Phi_o = \\Phi - \\textcolor{mred}{K}C\\)\n\n\\alert{Rule-of-thumb} (From continous-time state-space theory) Choose the poles of the observer (eigenvalues of \\(\\Phi-\\textcolor{mred}{K}C\\)) at least twice as fast as the poles (eigenvalues) of \\(\\Phi-\\Gamma L\\). In discrete-time place the observer-poles closer to the origin.  \n\\end{frame}\n\n\n\\begin{frame}[label={sec:orgd560d3e}]{Control by feedback from reconstructed states}\nThe design problem can be separates into two problems\n\\begin{enumerate}\n\\item Determine the gain vector \\(\\textcolor{orange!80!black}{L}\\) and the gain \\(l_0\\) of the control law\n\\[ u(k) = -\\textcolor{orange!80!black}{L} \\hat{x}(k) + l_0 u_c(k)\\]\nso that the closed-loop system has good reference tracking.\n\\item Determine the gain vector \\(\\textcolor{mred}{K}\\) of the observer\n\\begin{equation*}\n\\begin{split}\n\\hat{x}(k+1) &= \\Phi \\hat{x}(k) + \\Gamma u(k) + \\textcolor{mred}{K} \\big(y(k) - C\\hat{x}(k)\\big)\n\\end{split}\n\\end{equation*}\nto get a good balance between disturbance rejection and noise attenuation.\n\\end{enumerate}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgfae4068}]{Computing the observer gain}\nA matrix \\(M\\) and its transpose \\(M\\transp\\) have the same eigenvalues. Hence, the problem of determining the gain \\(K\\) to obtain desired eigenvalues of \n\\[\\Phi- \\textcolor{mred}{K}C\\] is equivalent to determining the gain \\(K\\) in \n\\[(\\Phi-KC)\\transp = \\Phi\\transp - C\\transp \\textcolor{mred}{K}\\transp.\\]\nThe last problem has the exact same form as the problem of determining \\(L\\) to obtain desired eigenvalues of \n\\[\\Phi - \\Gamma L\\]\n\nSo, the same matlab function can be used for both problems.\n\\end{frame}\n\n\\begin{frame}[label={sec:org988a07f},fragile]{Computing the observer gain}\n \\begin{enumerate}\n\\item \\alert{Ackerman's method} \n\\begin{verbatim}\nK = acker(Phi', C', po)'\n\\end{verbatim}\n\\item \\alert{More numerically stable method} \n\\begin{verbatim}\nK = place(Phi', C', pd)'\n\\end{verbatim}\n\\end{enumerate}\n\\end{frame}\n\n\n\n\\section{Where to choose the poles}\n\\label{sec:org9fdaa4e}\n\\begin{frame}[label={sec:org5019d3d}]{Where to place the closed-loop poles?}\n\\end{frame}\n\\begin{frame}[label={sec:org4d3661a}]{Where to place the closed-loop poles?}\nIf the system is controllable we can place the closed-loop poles freely.\n\n\\pause\n\nBut not all placements are good choices\n\n\\pause\n\nTake into account\n\\begin{itemize}\n\\item Desired speed\n\\item Desired damping\n\\item \\alert{Poles and zeros of the plant}\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgcc4a069}]{Placing for desired speed and damping}\n\\begin{columns}\n\\begin{column}{0.4\\columnwidth}\n\\alert{s-plane}\n\n\\begin{center}\n \\includegraphics[height=.6\\textheight]{../../figures/sgrid-crop}\n\\end{center}\n\\end{column}\n\\begin{column}{0.6\\columnwidth}\n\\alert{z-plane}\n\\begin{center}\n \\includegraphics[height=.59\\textheight]{../../figures/zgrid-crop}\n\\end{center}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgdcea2e4}]{The effect of plant zeros and poles}\n\\begin{columns}\n\\begin{column}{0.4\\columnwidth}\n\\begin{center}\n \\includegraphics[width=1.0\\linewidth]{../../figures/AM-portal.png}\n\\end{center}\n\n\\pause\n\\end{column}\n\n\\begin{column}{0.6\\columnwidth}\n\\begin{center}\n \\includegraphics[width=1.0\\linewidth]{../../figures/AM-ch12.4.png}\n\\end{center}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org7612825}]{Placing w.r.t plant zeros and poles}\n\\begin{itemize}\n\\item Cancel slow plant zeros\n\\item Place fast closed-loop poles near fast plant poles\n\\end{itemize}\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "2ac63fafad6f4457f355a9f0769383f204714213", "size": 11763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discrete-state-space/slides/discrete-state-feedback-observers.tex", "max_stars_repo_name": "kjartan-at-tec/mr2025", "max_stars_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "discrete-state-space/slides/discrete-state-feedback-observers.tex", "max_issues_repo_name": "kjartan-at-tec/mr2025", "max_issues_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "discrete-state-space/slides/discrete-state-feedback-observers.tex", "max_forks_repo_name": "kjartan-at-tec/mr2025", "max_forks_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_forks_repo_licenses": ["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.5970588235, "max_line_length": 280, "alphanum_fraction": 0.7026268809, "num_tokens": 4154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6438692838009606}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.1 Evaluate -- without {\\tt rhsonly = True}}\n\n\\begin{cadabra}\n   {\\theta, \\varphi}::Coordinate.\n   {a,b,c,d,e,f,g,h#}::Indices(values={\\theta, \\varphi}, position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   V  := { V_{\\theta} = \\varphi, V_{\\varphi} = \\sin(\\theta) }.   # cdb(ex-0601.100,V)\n   dV := dV_{a b} -> \\partial_{b}{V_{a}} - \\partial_{a}{V_{b}}.  # cdb(ex-0601.101,dV)\n\n   evaluate (dV, V)                                              # cdb(ex-0601.102,dV)\n\\end{cadabra}\n\nNotice how {\\tt evaluate} has been applied to both the left and right hand sides of the rule.\n\n\\begin{align*}\n   V_{a} &= \\Cdb{ex-0601.100}\\\\[10pt]\n   & \\Cdb{ex-0601.101}\\\\[10pt]\n   & \\Cdb{ex-0601.102}\n\\end{align*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.1 Evaluate -- with {\\tt rhsonly = True}}\n\n\\begin{cadabra}\n   {\\theta, \\varphi}::Coordinate.\n   {a,b,c,d,e,f,g,h#}::Indices(values={\\theta, \\varphi}, position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   V  := { V_{\\theta} = \\varphi, V_{\\varphi} = \\sin(\\theta) }.   # cdb(ex-0601.200,V)\n   dV := dV_{a b} -> \\partial_{b}{V_{a}} - \\partial_{a}{V_{b}}.  # cdb(ex-0601.201,dV)\n\n   evaluate (dV, V, rhsonly=True)                                # cdb(ex-0601.202,dV)\n\\end{cadabra}\n\nThis is an improvement, only the right hnd side has been expanded into components.\n\n\\begin{align*}\n   V_{a} &= \\Cdb{ex-0601.200}\\\\[10pt]\n   & \\Cdb{ex-0601.201}\\\\[10pt]\n   & \\Cdb{ex-0601.202}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "917c604f3bbc93384dc4dee370ef1263064c5b6b", "size": 1768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0601.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-0601.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-0601.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.0175438596, "max_line_length": 94, "alphanum_fraction": 0.5316742081, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6438692786169147}}
{"text": "\\documentclass[]{article}\n\\usepackage{caption,subcaption,graphicx,float,url,amsmath,amssymb,tocloft,wasysym,amsthm,thmtools,textcomp,listings,amsfonts,cancel}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage[toc,acronym,nonumberlist]{glossaries}\n\\usepackage[]{algorithm2e}\n\\setacronymstyle{long-short}\n\\usepackage{glossaries-extra}\n\\graphicspath{{figs/}} \n\\setlength{\\cftsubsecindent}{0em}\n\\setlength{\\cftsecnumwidth}{3em}\n\\setlength{\\cftsubsecnumwidth}{3em}\n\\newcommand\\numberthis{\\addtocounter{equation}{1}\\tag{\\theequation}}\n\\newtheorem{thm}{Theorem}\n\\newtheorem{cor}[thm]{Corollary}\n\\setcounter{tocdepth}{1}\n\n%opening\n\\title{Computation in Complex Systems\\\\\n\tWeek 5\n\t}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Recursive Functions}\n\nIn Table \\ref{table:recursive}, the first column contains either a reference to the exercise in the Exam, or a '-' for auxiliary functions:\n\\begin{itemize}\n\t\\item \\emph{bool} takes us into to the world of Boolean functions\\footnote{\\emph{mul} can serve as a replacement for \\emph{and}; $bool(add)$ replaces \\emph{or}};\n\t\\item \\emph{not} is our first Boolean function;\n\t\\item \\emph{gt} is used, alongside \\emph{not}, to define \\emph{max} \\& \\emph{min}.\n\\end{itemize}\n\n\\begin{table}[H]\n\t\\caption{Recursive Functions}\\label{table:recursive}\n\t\\begin{tabular}{|c|c|l|l|}\\hline\n\t\t&&Base case&General\\\\ \\hline\n\t\ta&exp&$exp(x,0)=1$&$exp(x,y+1)=mult(exp(x,y),x)$\\\\ \\hline\n\t\tb&pred&$pred(0)=0$&$pred(x+1) =x$\\\\ \\hline\n\t\tc&sub&$sub(x, 0)=x $&$sub(x, y+1)=pred(sub(x,y)) $\\\\ \\hline\n\t\t-&bool&$bool(0)=0$&$bool(x+1)=1$ \\\\ \\hline\n\t\t-&not&$not(0)=1$&$not(x+1)=0$ \\\\ \\hline\n\t\t-&gt&&$gt(x,y)=bool(sub(x,y))$\\\\ \\hline\n\t\td&min&-&min(x,y)=add(mult(gt(x,y),y),mult(not(gt(x,y)),x))\\\\ \\hline\n\t\te&max&-&max(x,y)=add(mult(gt(x,y),x),mult(not(gt(x,y)),y))\\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\n\\section{Turing Machines}\n\nTable \\ref{table:successor} shows the rules for a Turing machine for the successor function, and Tables  \\ref{table:carry}--\\ref{table:halt} show the rules through the three component Turing Machines from the exam. I have assumed that all Turing machines start in a special state \\includegraphics[width=9pt]{gosign} and halt in state \\includegraphics[width=9pt]{stop}: there are no rules that more the Turing machine into \\includegraphics[width=9pt]{gosign} or out of \\includegraphics[width=9pt]{stop}. Each table comprises two columns for the character under the head and the state, followed by three columns--the character to be written, the new state, and the movement of the head.\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\caption{Successor. There are two states, apart from the special states: in the \\emph{Carrying} state we move to the left, setting 1s to 0s as we go, until we find a 0; in the \\emph{Returning} state we }\\label{table:successor}\n\t\t\\begin{tabular}{|c|c||c|c|c|} \\hline\n\t\t\t$\\bullet$ &\\includegraphics[width=9pt,height=7pt]{gosign}&$\\bullet$ &Carrying&$\\leftarrow$ \\\\ \\hline\n\t\t\t1&Carrying&0&Carrying&$\\leftarrow$ \\\\ \\hline\n\t\t\t0&Carrying&1&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t0&Returning&1&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t1&Returning&1&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t$\\bullet$ &Returning&\t$\\bullet$&\\includegraphics[width=9pt,height=7pt]{stop}& \\\\ \\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\nThe machine described in Table \\ref{table:successor} is equivalent to the combination of the following 3 machines: $Halt(Return(Carry(x)))$.\n\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\caption{Carry: move left, replacing 1 by 0, until we find a  0.}\\label{table:carry}\n\t\t\\begin{tabular}{|c|c||c|c|c|} \\hline\n\t\t\t$\\bullet$ &\\includegraphics[width=9pt,height=7pt]{gosign}&$\\bullet$ &Carrying&$\\leftarrow$ \\\\ \\hline\n\t\t\t1&Carrying&0&Carrying&$\\leftarrow$ \\\\ \\hline\n\t\t\t0&Carrying&1&\\includegraphics[width=9pt,height=7pt]{stop}&$\\rightarrow$ \\\\ \\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\caption{Return: move the head back to the final position}\\label{table:return}\n\t\t\\begin{tabular}{|c|c||c|c|c|} \\hline\n\t\t\t0&\\includegraphics[width=9pt,height=7pt]{gosign}&1&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t0&Returning&0&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t1&Returning&1&Returning&$\\rightarrow$ \\\\ \\hline\n\t\t\t$\\bullet$ &Returning&\t$\\bullet$&\\includegraphics[width=9pt,height=7pt]{stop}& \\\\ \\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\caption{Halt}\\label{table:halt}\n\t\t\\begin{tabular}{|c|c||c|c|c|} \\hline\n\t\t\t$\\bullet$ &\\includegraphics[width=9pt,height=7pt]{gosign}&$\\bullet$ &\\includegraphics[width=9pt,height=7pt]{stop}& \\\\ \\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n% bibliography go here\n\n\\bibliographystyle{unsrt}\n\\raggedright\n\\addcontentsline{toc}{section}{Bibliography}\n\\bibliography{computations}\n\n\\end{document}\n", "meta": {"hexsha": "93e61d8086533714b45d50bb7f2e6c63bc0847ef", "size": 4738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "computations/exam5.tex", "max_stars_repo_name": "weka511/fractals", "max_stars_repo_head_hexsha": "fa4e39677ea3ed7713e40a55b9453b2826f11a6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-22T01:39:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T04:36:22.000Z", "max_issues_repo_path": "computations/exam5.tex", "max_issues_repo_name": "weka511/fractals", "max_issues_repo_head_hexsha": "fa4e39677ea3ed7713e40a55b9453b2826f11a6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-06-20T03:20:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-20T03:07:55.000Z", "max_forks_repo_path": "computations/exam5.tex", "max_forks_repo_name": "weka511/complexity", "max_forks_repo_head_hexsha": "435ffab978e4499aea7c2c83788533867cc9b062", "max_forks_repo_licenses": ["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.0727272727, "max_line_length": 684, "alphanum_fraction": 0.713170114, "num_tokens": 1680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126792, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6438692727692288}}
{"text": "\\subsubsection{Introduction to Induction}\n\n\\begin{frame}<beamer>{Structure}\n  \\tableofcontents[currentsection,currentsubsection]\n\\end{frame}\n\n\\begin{frame}{Induction}\n  \\textbf{Basics:}\n  \\begin{itemize}\n    \\item<2- | handout:1>\n      You want to show that assumption $A(n)$ is valid $\\forall n \\in \\mathbb{N}$\n    \\item<3- | handout:1>\n      We show induction in two steps:\n      \\begin{enumerate}\n        \\item<4- | handout:1>\n          \\textbf{Induction basis:} we show that our assumption is valid \n          for one value (for example: $n = 1, \\, A(1)$).\n        \\item<5- | handout:1>\n          \\textbf{Induction step:} we show that the assumption is valid for \n          all $n$ (normally one step forward: $n = n + 1, A(1), \\ldots, A(n)$).\n      \\end{enumerate}\n    \\item<6- | handout:1>\n      If both has been proven, then {\\color{MainA}$A(n)$} holds for all natural\n      numbers {\\color{MainA}$n$} by \\textbf{induction}\n  \\end{itemize}\n\\end{frame}\n\n%-------------------------------------------------------------------------------\n\n\\begin{frame}{Induction - Example 1}\n  \\begin{block}{Claim:}\n    A \\textbf{complete} binary tree of depth $d$ has $v(d) = 2^d - 1$ nodes\n  \\end{block}\n  \\begin{itemize}\n    \\item<2- |handout:1>\n      \\textbf{Induction basis:} assumption holds for {\\color{MainA}$d = 1$}\n      \\begin{columns}\n        \\begin{column}{0.5\\linewidth}\n          \\begin{figure}[!h]\n            \\begin{adjustbox}{width=4em}\n              \\input{Images/Induction/BinaryTree_Root.tikz}\n            \\end{adjustbox}\n            \\caption{Tree of depth {\\color{MainA}$1$} has\n              {\\color{MainA}$1$} node}\n          \\end{figure}\n        \\end{column}\n        \\begin{column}{0.5\\linewidth}\n          {\\color{MainA}$v(1) = 2^1 - 1 = 1$}\\\\\n          \\onslide<3- |handout:1>{$\\Rightarrow$ correct $\\checkmark$}\n        \\end{column}\n      \\end{columns}\n  \\end{itemize}\n\\end{frame}\n\n%-------------------------------------------------------------------------------\n\n\\begin{frame}{Induction - Example 1}\n  Number of nodes $v(d)$ in a binary tree with depth $d$:\n  \\begin{itemize}\n    \\item\n      \\textbf{Induction assumption:}\n      {\\color{MainA}$v(d) = 2^d-1$}\n    \\item<2- |handout:1>\n      \\textbf{Induction basis:}\n      $v(1) = 2^d - 1 = 2^1 - 1 = 1 ~{\\color{Mittel-Blau}\\checkmark}$\n    \\item<3- |handout:1>\n      \\textbf{Induction step:}\n      to show for $d := d + 1$\n      \\begin{columns}\n        \\begin{column}<3- |handout:1>{0.6\\textwidth}\n          \\begin{figure}%\n            \\begin{adjustbox}{height=7.0em}\n              \\input{Images/Induction/BinaryTree_SubTrees.tikz}%\n            \\end{adjustbox}%\n            \\vspace{-0.5em}\n            \\caption{binary tree with subtrees}%\n            \\label{fig:binary_tree_subtrees}%\n          \\end{figure}\n        \\end{column}\n        \\begin{column}{0.4\\linewidth}\n          \\vspace{1.5em}\n          \\begin{align*}\n            \\onslide<4- |handout:1>{\n              v(d + 1) = &~ 2 \\cdot v(d) + 1\n            }\\\\\n            \\onslide<5- |handout:1>{\n              {} = &~ 2 \\cdot \\textcolor{MainA}{\\left(2^d - 1\\right)} + 1\n            }\\\\\n            \\onslide<6- |handout:1>{\n              {} = &~ 2^{d + 1} - 2 + 1\n            }\\\\\n            \\onslide<7- |handout:1>{\n              {} = &~ 2^{d + 1} - 1 ~{\\color{MainA}\\checkmark}\n            }\n          \\end{align*}\n          \\onslide<8- |handout:1>{\n            \\llap{$\\Rightarrow$ \\textbf{By induction:}}\n            $v(d) = 2^d - 1 ~\\forall d \\in \\mathbb{N} ~\\Square$\n          }\n        \\end{column}\n      \\end{columns}\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "1573f52f39ece9f7ddcdb11c725717e44a95457b", "size": 3574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-2/Chapter/eng/050_Induction.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/050_Induction.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/050_Induction.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": 34.3653846154, "max_line_length": 81, "alphanum_fraction": 0.5075545607, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6438692651935274}}
{"text": "\\chapter{Functions and Graphs}\n\n\\section{Slope}\nSlope defines the average rate of change on a function in a given interval,\n\\(\\Delta x\\) (this expression is defined as $x_2-x_1$).\n\nConsider a function $f(x)$.  $f$ takes in x-coordinates, and spits out\ncorresponding y-coordinates, creating a set of ordered pairs that produces a\nline, curve, or otherwise.\n\nThe formal definition of slope is given as follows:\n\\begin{equation}\nm=\\frac{f(x_2)-f(x_1)}{x_2-x_1}\n\\end{equation}\n\n\\subsection{Point-slope form}\nGiven the coordinate pair of some point in the x-y plane, and the slope of any\narbitrary line $m$, we can develop an equation for the line that has the slope\n$m$ and goes through the coordinate $(x, y)$.\n\nThe general equation of that line is given as follows:\n\\begin{equation}\ny-y_1=m(x-x_1)\n\\end{equation}\n\n\\subsection{Sketching lines}\nThe general equation of a linear line is as follows:\n\\begin{equation}\ny=mx+b\n\\end{equation}\n\nTherefore, the y-intercept is given when $x=0$.  To solve for the y-intercept of\nthe line given above, we evaluate it, plugging $0$ in for $x$, producing a\ncoordinate pair of $(0, f(0))$.\n\nTo sketch a line, preform the following steps:\n\\begin{enumerate}\n\\item{Find the coordinate of the y-intercept of the graph, according to the rule\ngiven above}\n\\item{Sketch that location into the coordinate plane}\n\\item{Construct the two adjacent points on the plane according to the slope $m$\nand the definition of slope}\n\\item{Connect the dots}\n\\end{enumerate}\n\n\\subsection{Properties of Slope}\nTwo lines are parallel iff the following condition is met: $m_1=m_2$.\n\n\\section{Functions}\nA function $f$ maps a set of x-coordinates ($A$) to a set of y-coordinates\n($B$).  Each element in $A$ is mapped to \\textit{exactly one} point from the set\n$B$.\n\n\\begin{itemize}\n\\item{Each element of $A$ must be matched to an element of $B$}\n\\item{Some elements of $B$ may not be matched with any elements of $A$}\n\\item{Two or more elements of $A$ may be matched with the same element $B$}\n\\item{An element of $A$ can not be matched with more than one distinct element\nof $B$}\n\\end{itemize}\n\nThe difference quotient is defined as follows, and becomes important later:\n\\begin{equation}\n\\frac{f(x+h)-f(x)}{h}, h \\ne 0\n\\end{equation}\n\nSome formal definitions follow:\n\\begin{description}\n\\item[Function]{a relationship between two variables such that to each value of\nthe independent variable there is exactly one value of the dependent variable}\n\\item[Function notation]{$y=f(x)$}\n\\item[Domain]{the set of values $x$ for which $f$ can produce real values}\n\\item[Range]{the set of values that $f$ can produce for all given $x$ in the\ndomain}\n\\item[Implied domain]{the set of real numbers that satisfy the expression for\nwhich $f$ is defined upon}\n\\end{description}\n\n\\section{Graphs of functions}\nA function can be defined on any given interval as one of three things:\nincreasing, decreasing, or constant. The classifications of each follow:\n\nFor any interval $x_1$, $x_2$...\n\\begin{itemize}\n\\item The function is increasing for all $x$ such that $f(x_1)<f(x_2)$\n\\item The function is decreasing for all $x$ such that $f(x_1)>f(x_2)$\n\\item The function is constant for all $x$ such that $f(x_1)=f(x_2)$\n\\end{itemize}\n\nA function has a relative minimum when there exists an interval $(x_1,x_2)$ such\nthat there is an $a$ that $x_1<x<x_2$ and $f(a) \\leq f(x)$.\n\nConversly, a function has a relative maximum when there exists an interval\n$(x_1,x_2)$ such that there is an $a$ that $x_1<x<x_2$ and $f(a) \\geq f(x)$.\n\n\\subsection{Even and Odd functions}\n\\begin{itemize}\n\\item A function is even such that for all $x$ in the domain of $f$,\n$f(-x)=f(x)$\n\\item A function is odd such that for all $x$ in the domain of $f$,\n$f(-x)=-f(x)$\n\\end{itemize}\n\n\\section{Translations}\nThere are several types of translations that can be applied to parent functions\nand what will become their \"children\".  For a parent function $f$, you can\nproduce a child function $g$ such that $g$ is defined in terms of $f(x)$.  The\nsimple translations follow:\n\n\\begin{enumerate}\n\\item Vertical shift $c$ units upwards: $g(x)=f(x)+c$\n\\item Vertical shift $c$ units downwards: $g(x)=f(x)-c$\n\\item Horizontal shift $c$ units to the left: $g(x)=f(x+c)$\n\\item Horizontal shift $c$ units to the right: $g(x)=f(x-c)$\n\\end{enumerate}\n\nTo reflect a function across an axis, take the following advice:\n\n\\begin{enumerate}\n\\item A reflection in the $x$-axis for a function $f$: $g(x)=-f(x)$\n\\item A reflection in the $y$-axis for a function $f$: $g(x)=f(-x)$\n\\end{enumerate}\n\nTo stretch or shirnk a function $g(x)$ in terms of $f(x)$, simply multiply $f$\nby a scalar $c$.\n\n\\section{Combinations of Functions}\nThere are several ways that you can combine two functions $f$ and $g$ (for\nexample) to produce a new, composite function of the two:\n\n\\begin{enumerate}\n\\item Sum: $(f+g)(x)=f(x)+g(x)$\n\\item Difference: $(f-g)(x)=f(x)-g(x)$\n\\item Product: $(fg)(x)=f(x)*g(x)$\n\\item Quotient: $\\frac{f}{g}(x)=\\frac{f(x)}{g(x)}$\n\\end{enumerate}\n\n\\subsection{Composite Functions}\nA composite function of $f$ and $g$ is defined as follows: $f(g(x))$.\nTherefore, the range of $g$ must be limited to the domain of $f$ so that no $x$\nvalues can be passed to the composite function that are invalid.\n\n\\section{Inverse Functions}\nTwo functions $f$, and $g$ are considered to be inverses of each other, iff both\nof the following two conditions are met:\n\n\\begin{enumerate}\n\\item $f(g(x))=x$ for all $x$ in the domain of $g(x)$.\n\\item $g(f(x))=x$ for all $x$ in the domain of $f(x)$.\n\\end{enumerate}\n\nTo find an inverse function algebraically, preform the following steps:\n\n\\begin{enumerate}\n\\item Use the Horizontal Line Test to determine if $f$ has an inverse ($f^-1$)\n  \\begin{itemize}\n  \\item (If it doesn't, limit the domain of $f$ so that it does.)\n  \\end{itemize}\n\\item{Plug in $f^-1(x)$ into the original function and isolate}\n\\end{enumerate}\n", "meta": {"hexsha": "fcd51d5f6cc07fc4c3293ea29aa196593a224b58", "size": 5892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/1_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/1_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/1_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": 36.5962732919, "max_line_length": 80, "alphanum_fraction": 0.7230142566, "num_tokens": 1746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.6438692586822014}}
{"text": "\\newpage\r\n\\section{Taylor series}\r\n\r\n\\begin{Introduction}{TAYLOR}\r\nThis short note describes a package of REDUCE procedures that allow\r\nTaylor expansion in one or more variables and efficient manipulation\r\nof the resulting Taylor series. Capabilities include basic operations\r\n(addition, subtraction, multiplication and division) and also\r\napplication of certain algebraic and transcendental functions. To a\r\ncertain extent, Laurent expansion can be performed as well.\r\n\\end{Introduction}\r\n\r\n\\begin{Operator}{taylor}\r\n  The \\name{taylor} operator is used for expanding an expression into a\r\n  Taylor series.\r\n\r\n  \\begin{Syntax}\r\n    \\name{taylor}\\(\\meta{expression}\r\n                   \\name{,}\\meta{var}\\name{,}\r\n                   \\meta{expression}\\name{,}\\meta{number}\\\\\r\n                   \\{\\name{,}\\meta{var}\\name{,}\r\n                   \\meta{expression}\\name{,}\\meta{number}\\}\\optional\\)\r\n  \\end{Syntax}\r\n  \\meta{expression} can be any valid REDUCE algebraic expression.\r\n  \\meta{var} must be a \\nameref{kernel}, and is the expansion\r\n  variable.  The \\meta{expression} following it denotes the point\r\n  about which the expansion is to take place. \\meta{number} must be a\r\n  non-negative integer and denotes the maximum expansion order.  If\r\n  more than one triple is specified \\name{taylor} will expand its\r\n  first argument independently with respect to all the variables.\r\n  Note that once the expansion has been done it is not possible to\r\n  calculate higher orders.\r\n\r\n  Instead of a \\nameref{kernel}, \\meta{var} may also be a list of\r\n  kernels.  In this case expansion will take place in a way so that\r\n  the {\\em sum\\/} of the degrees of the kernels does not exceed the\r\n  maximum expansion order.  If the expansion point evaluates to the\r\n  special identifier \\name{infinity}, \\name{taylor} tries to expand in\r\n  a series in 1/\\meta{var}.\r\n\r\n  The expansion is performed variable per variable, i.e.\\ in the\r\n  example above by first expanding \r\n  \\IFTEX{$\\exp(x^{2}+y^{2})$}{exp(x^2+y^2)}\r\n  with respect to\r\n  \\name{x} and then expanding every coefficient with respect to \\name{y}.\r\n\r\n  \\begin{Examples}\r\n    taylor(e^(x^2+y^2),x,0,2,y,0,2);     &\r\n                1 + Y^{2} + X^{2} + Y^{2}*X^{2} + O(X^{2},Y^{2})   \\\\\r\n    taylor(e^(x^2+y^2),{x,y},0,2); & 1 + Y^{2} + X^{2} + O(\\{X^{2},Y^{2}\\})\\\\\r\n    \\explanation{The following example shows the case of a non-analytical function.}\\\\\r\n    taylor(x*y/(x+y),x,0,2,y,0,2); & ***** Not a unit in argument to QUOTTAYLOR \\\\\r\n  \\end{Examples}\r\n\r\n  \\begin{Comments}\r\n    Note that it is not generally possible to apply the standard\r\n    reduce operators to a Taylor kernel. For example, \\nameref{part},\r\n    \\nameref{coeff}, or \\nameref{coeffn} cannot be used. Instead, the\r\n    expression at hand has to be converted to standard form first\r\n    using the \\nameref{taylortostandard} operator.\r\n\r\n    Differentiation of a Taylor expression is possible.  If you\r\n    differentiate with respect to one of the Taylor variables the\r\n    order will decrease by one.\r\n\r\n    Substitution is a bit restricted: Taylor variables can only be\r\n    replaced by other kernels.  There is one exception to this rule:\r\n    you can always substitute a Taylor variable by an expression that\r\n    evaluates to a constant.  Note that REDUCE will not always be able\r\n    to determine that an expression is constant: an example is\r\n    sin(acos(4)).\r\n\r\n    Only simple taylor kernels can be integrated. More complicated\r\n    expressions that contain Taylor kernels as parts of themselves are\r\n    automatically converted into a standard representation by means of\r\n    the \\nameref{taylortostandard} operator. In this case a suitable\r\n    warning is printed.\r\n\r\n  \\end{Comments}\r\n\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Switch}{taylorautocombine}\r\n  If you set \\name{taylorautocombine} to \\name{on}, REDUCE\r\n  automatically combines Taylor expressions during the simplification\r\n  process.  This is equivalent to applying \\nameref{taylorcombine} to\r\n  every expression that contains Taylor kernels.  Default is\r\n  \\name{on}.\r\n\\end{Switch}\r\n\r\n\\begin{Switch}{taylorautoexpand}\r\n  \\name{taylorautoexpand} makes Taylor expressions ``contagious'' in\r\n  the sense that \\nameref{taylorcombine} tries to Taylor expand all\r\n  non-Taylor subexpressions and to combine the result with the rest.\r\n  Default is \\name{off}.\r\n\\end{Switch}\r\n\r\n\\begin{Operator}{taylorcombine}\r\n  This operator tries to combine all Taylor kernels found in its\r\n  argument into one.  Operations currently possible are:\r\n  \\begin{itemize}\r\n    \\item Addition, subtraction, multiplication, and division.\r\n    \\item Roots, exponentials, and logarithms.\r\n    \\item Trigonometric and hyperbolic functions and their inverses.\r\n  \\end{itemize}\r\n\r\n  \\begin{Examples}\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    taylorcombine log hugo; & X + O(X^{3})\\\\\r\n    taylorcombine(hugo + x); & (1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})) + X\\\\\r\n    on taylorautoexpand; \\\\\r\n    taylorcombine(hugo + x); & 1 + 2*X + \\rfrac{1}{2}*X^{2} + O(X^{3})\r\n  \\end{Examples}\r\n\r\n  \\begin{Comments}\r\n    Application of unary operators like \\name{log} and \\name{atan}\r\n    will nearly always succeed. For binary operations their arguments\r\n    have to be Taylor kernels with the same template. This means that\r\n    the expansion variable and the expansion point must match.\r\n    Expansion order is not so important, different order usually means\r\n    that one of them is truncated before doing the operation.\r\n\r\n    If \\nameref{taylorkeeporiginal} is set to \\name{on} and if all\r\n    Taylor kernels in its argument have their original expressions\r\n    kept \\name{taylorcombine} will also combine these and store the\r\n    result as the original expression of the resulting Taylor kernel.\r\n    There is also the switch \\nameref{taylorautoexpand}.\r\n\r\n    There are a few restrictions to avoid mathematically undefined\r\n    expressions: it is not possible to take the logarithm of a Taylor\r\n    kernel which has no terms (i.e. is zero), or to divide by such a\r\n    beast.  There are some provisions made to detect singularities\r\n    during expansion: poles that arise because the denominator has\r\n    zeros at the expansion point are detected and properly treated,\r\n    i.e.\\ the Taylor kernel will start with a negative power.  (This\r\n    is accomplished by expanding numerator and denominator separately\r\n    and combining the results.)  Essential singularities of the known\r\n    functions (see above) are handled correctly.\r\n  \\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Switch}{taylorkeeporiginal}\r\n  \\name{taylorkeeporiginal}, if set to \\name{on}, forces the\r\n  \\nameref{taylor} and all Taylor kernel manipulation operators to\r\n  keep the original expression, i.e.\\ the expression that was Taylor\r\n  expanded.  All operations performed on the Taylor kernels are also\r\n  applied to this expression which can be recovered using the operator\r\n  \\nameref{taylororiginal}.  Default is \\name{off}.\r\n\\end{Switch}\r\n\r\n\\begin{Operator}{taylororiginal}\r\n  Recovers the original expression (the one that was expanded) from\r\n  the Taylor kernel that is given as its argument.\r\n\r\n  \\begin{Syntax}\r\n    \\name{taylororiginal}\\(\\meta{expression}\\) or\r\n    \\name{taylororiginal} \\meta{simple_expression}\r\n  \\end{Syntax}\r\n\r\n  \\begin{Examples}\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    taylororiginal hugo; &\r\n       ***** Taylor kernel doesn't have an original part in TAYLORORIGINAL\\\\\r\n    on taylorkeeporiginal; \\\\\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    taylororiginal hugo; & E^{X}\r\n  \\end{Examples}\r\n\r\n  \\begin{Comments}\r\n    An error is signalled if the argument is not a Taylor kernel or if\r\n    the original expression was not kept, i.e.\\ if\r\n    \\nameref{taylorkeeporiginal} was set \\name{off} during expansion.\r\n  \\end{Comments}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Switch}{taylorprintorder}\r\n  \\name{taylorprintorder}, if set to \\name{on}, causes the remainder\r\n  to be printed in big-O notation.  Otherwise, three dots are printed.\r\n  Default is \\name{on}.\r\n\\end{Switch}\r\n\r\n\\begin{Variable}{taylorprintterms}\r\n  Only a certain number of (non-zero) coefficients are printed. If\r\n  there are more, an expression of the form \\name{n terms} is printed\r\n  to indicate how many non-zero terms have been suppressed.  The\r\n  number of terms printed is given by the value of the shared\r\n  algebraic variable \\name{taylorprintterms}.  Allowed values are\r\n  integers and the special identifier \\name{all}. The latter setting\r\n  specifies that all terms are to be printed. The default setting is\r\n  5.\r\n\r\n  \\begin{Examples}\r\n    taylor(e^(x^2+y^2),x,0,4,y,0,4); &\r\n           1 + Y^{2} + \\rfrac{1}{2}*Y^{4} + X^{2} + Y^{2}*X^{2} +\r\n             (4 terms) + O(X^{5},Y^{5})\\\\\r\n    taylorprintterms := all; & TAYLORPRINTTERMS := ALL \\\\\r\n    taylor(e^(x^2+y^2),x,0,4,y,0,4); &\r\n    \\begin{multilineoutput}{}\r\n1 + Y^{2} + \\rfrac{1}{2}*Y^{4} + X^{2} + Y^{2}*X^{2} +%\r\n \\rfrac{1}{2}*Y^{4}*X^{2} + \\rfrac{1}{2}*X^{4} +%\r\n \\rfrac{1}{2}*Y^{2}*X^{4}\\\\\r\n + \\rfrac{1}{4}*Y^{4}*X^{4} + O(X^{5},Y^{5})\r\n    \\end{multilineoutput}\r\n  \\end{Examples}\r\n\r\n\\end{Variable}\r\n\r\n\r\n\\begin{Operator}{taylorrevert}\r\n  \\name{taylorrevert} allows reversion of a Taylor series of a\r\n  function f, i.e., to compute the first terms of the expansion of the\r\n  inverse of $f$ from the expansion of $f$.\r\n\r\n  \\begin{Syntax}\r\n    \\name{taylorrevert}\\(\\meta{expression}\\name{,}\r\n                         \\meta{var}\\name{,}\\meta{var}\\)\r\n  \\end{Syntax}\r\n\r\n  The first argument must evaluate to a Taylor kernel with the second\r\n  argument being one of its expansion variables. \r\n\r\n  \\begin{Examples}\r\n    taylor(u - u**2,u,0,5); &    U - U^{2} + O(U^{6}) \\\\\r\n    taylorrevert (ws,u,x);  &    X + X^{2} + 2*X^{3} + 5*X^{4} + 14*X^{5} + O(X^{6})\r\n  \\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{taylorseriesp}\r\n  This operator may be used to determine if its argument is a Taylor\r\n  kernel.\r\n\r\n  \\begin{Syntax}\r\n    \\name{taylorseriesp}\\(\\meta{expression}\\) or \\name{taylorseriesp}\r\n    \\meta{simple_expression}\r\n  \\end{Syntax}\r\n\r\n  \\begin{Examples}\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    if taylorseriesp hugo then OK;& OK \\\\\r\n    if taylorseriesp(hugo + y) then OK else NO; & NO\r\n  \\end{Examples}\r\n\r\n  \\begin{Comments}\r\n    Note that this operator is subject to the same restrictions as,\r\n    e.g., \\name{ordp} or \\name{numberp}, i.e.\\ it may only be used in\r\n    boolean expressions in \\name{if} or \\name{let} statements.\r\n  \\end{Comments}\r\n\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{taylortemplate}\r\n  The template of a Taylor kernel, i.e.\\ the list of all variables\r\n  with respect to which expansion took place together with expansion\r\n  point and order can be extracted using\r\n\r\n  \\begin{Syntax}\r\n    \\name{taylortemplate}\\(\\meta{expression}\\) or\r\n    \\name{taylortemplate} \\meta{simple_expression}\r\n  \\end{Syntax}\r\n\r\n  This returns a list of lists with the three elements\r\n  (VAR,VAR0,ORDER).  An error is signalled if the argument is not a\r\n  Taylor kernel.\r\n\r\n  \\begin{Examples}\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    taylortemplate hugo; & \\{\\{X,0,2\\}\\}\r\n  \\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{taylortostandard}\r\n  This operator converts all Taylor kernels in its argument into\r\n  standard form and resimplifies the result.\r\n\r\n\\begin{Syntax}\r\n  \\name{taylortostandard}\\(\\meta{expression}\\) or\r\n  \\name{taylortostandard} \\meta{simple_expression}\r\n\\end{Syntax}\r\n\r\n  \\begin{Examples}\r\n    hugo := taylor(exp(x),x,0,2); & HUGO := 1 + X + \\rfrac{1}{2}*X^{2} + O(X^{3})\\\\\r\n    taylortostandard hugo; & \\rfrac{X^{2} + 2*X + 2}{2}\r\n  \\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\endinput\r\n\r\n\\section{Warnings and error messages}\r\n\\index{errors ! TAYLOR package}\r\n\\begin{itemize}\r\n\r\n\\item \\name{Branch point detected in ...}\\\\\r\n    This occurs if you take a rational power of a Taylor kernel\r\n    and raising the lowest order term of the kernel to this\r\n    power yields a non analytical term (i.e.\\ a fractional power).\r\n\r\n\\item \\name{Cannot expand further... truncation done}\\\\\r\n    You will get this warning if you try to expand a Taylor kernel to\r\n    a higher order.\r\n\r\n\\item \\name{Converting Taylor kernels to standard representation}\\\\\r\n    This warning appears if you try to integrate an expression that\r\n    contains Taylor kernels.\r\n\r\n\\item \\name{Error during expansion (possible singularity)}\\\\\r\n    The expression you are trying to expand caused an error.\r\n    As far as I know this can only happen if it contains a function\r\n    with a pole or an essential singularity at the expansion point.\r\n    (But one can never be sure.)\r\n\r\n\\item \\name{Essential singularity in ...}\\\\\r\n    An essential singularity was detected while applying a\r\n    special function to a Taylor kernel.\r\n    This error occurs, for example, if you try to take\r\n    the logarithm of a Taylor kernel that starts with a negative\r\n    power in one of its variables, i.e.\\ that has a pole\r\n    at the expansion point.\r\n\r\n\\item \\name{Expansion point lies on branch cut in ...}\\\\\r\n    The only functions with branch cuts this package knows of are\r\n    (natural) logarithm, inverse circular and hyperbolic tangent and\r\n    cotangent.  The branch cut of the logarithm is assumed to lie on\r\n    the negative real axis.  Those of the arc tangent and arc\r\n    cotangent functions are chosen to be compatible with this: both\r\n    have essential singularities at the points $\\pm i$.  The branch\r\n    cut of arc tangent is the straight line along the imaginary axis\r\n    connecting $+1$ to $-1$ going through $\\infty$ whereas that of arc\r\n    cotangent goes through the origin.  Consequently, the branch cut\r\n    of the inverse hyperbolic tangent resp.\\ cotangent lies on the\r\n    real axis and goes from $-1$ to $+1$, that of the latter across\r\n    $0$, the other across $\\infty$.\r\n    \r\n    The error message can currently only appear when you try to\r\n    calculate the inverse tangent or cotangent of a Taylor\r\n    kernel that starts with a negative degree.\r\n    The case of a logarithm of a Taylor kernel whose constant term\r\n    is a negative real number is not caught since it is\r\n    difficult to detect this in general.\r\n\r\n\\item \\name{Not a unity in ...}\\\\\r\n    This will happen if you try to divide by or take the logarithm of \r\n    a Taylor series whose constant term vanishes.\r\n\r\n\\item \\name{Not implemented yet (...)}\\\\\r\n    Sorry, but I haven't had the time to implement this feature.\r\n    Tell me if you really need it, maybe I have already an improved\r\n    version of the package.\r\n\r\n\\item \\name{Reversion of Taylor series not possible: ...}\\\\\r\n\\ttindex{TAYLORREVERT}\r\n    You tried to call the \\name{TAYLORREVERT} operator with\r\n    inappropriate arguments. The second half of this error message\r\n    tells you why this operation is not possible.\r\n\r\n\\item \\name{Substitution of dependent variables ...}\\\\\r\n    You tried to substitute a variable that is already present in the\r\n    Taylor kernel or on which one of the Taylor variables depend.\r\n\r\n\\item \\name{Taylor kernel doesn't have an original part}\\\\\r\n\\ttindex{TAYLORORIGINAL} \\ttindex{TAYLORKEEPORIGINAL}\r\n    The Taylor kernel upon which you try to use \\name{TAYLORORIGINAL}\r\n    was created with the switch \\name{TAYLORKEEPORIGINAL}\r\n    set to \\name{OFF}\r\n    and does therefore not keep the original expression.\r\n\r\n\\item \\name{Wrong number of arguments to TAYLOR}\\\\\r\n    You try to use the operator \\name{TAYLOR} with a wrong number of\r\n    arguments.\r\n\r\n\\item \\name{Zero divisor in TAYLOREXPAND}\\\\\r\n    A zero divisor was found while an expression was being expanded.\r\n    This should not normally occur.\r\n\r\n\\item \\name{Zero divisor in Taylor substitution}\\\\\r\n    That's exactly what the message says.  As an example consider the\r\n    case of a Taylor kernel containing the term \\name{1/x} and you try\r\n    to substitute \\name{x| by \\verb|0}.\r\n\r\n\\item \\name{... invalid as kernel}\\\\\r\n    You tried to expand with respect to an expression that is not a\r\n    kernel.\r\n\r\n\\item \\name{... invalid as order of Taylor expansion}\\\\\r\n    The order parameter you gave to \\name{TAYLOR} is not an integer.\r\n\r\n\\item \\name{... invalid as Taylor kernel}\\\\\r\n\\ttindex{TAYLORORIGINAL} \\ttindex{TAYLORTEMPLATE}\r\n    You tried to apply \\name{TAYLORORIGINAL| or \\verb|TAYLORTEMPLATE}\r\n    to an expression that is not a Taylor kernel.\r\n\r\n\\item \\name{... invalid as Taylor variable}\\\\\r\n    You tried to substitute a Taylor variable by an expression that is\r\n    not a kernel.\r\n\r\n\\item \\name{... invalid as value of TaylorPrintTerms}\\\\\r\n\\ttindex{TAYLORPRINTTERMS} \r\n    You have assigned an invalid value to \\name{TAYLORPRINTTERMS}.\r\n    Allowed values are: an integer or the special identifier\r\n    \\name{ALL}.\r\n\r\n\\item \\name{TAYLOR PACKAGE (...): this can't happen ...}\\\\\r\n    This message shows that an internal inconsistency was detected.\r\n    This is not your fault, at least as long as you did not try to\r\n    work with the internal data structures of \\REDUCE. Send input\r\n    and output to me, together with the version information that is\r\n    printed out.\r\n\r\n\\end{itemize}\r\n\r\n\\section{Comparison to other packages}\r\n\r\nAt the moment there is only one \\REDUCE{} package that I know of:\r\nthe truncated power series package by Alan Barnes and Julian Padget.\r\nIn my opinion there are two major differences:\r\n\\begin{itemize}\r\n  \\item The interface. They use the domain mechanism for their power\r\n        series, I decided to invent a special kind of kernel. Both\r\n        approaches have advantages and disadvantages: with domain\r\n        modes, it is easier\r\n        to do certain things automatically, e.g., conversions.\r\n  \\item The concept of a truncated series. Their idea is to remember\r\n        the original expression and to compute more coefficients when\r\n        more of them are needed. My approach is to truncate at a\r\n        certain order and forget how the unexpanded expression\r\n        looked like.  I think that their method is more widely\r\n        usable, whereas mine is more efficient when you know in\r\n        advance exactly how many terms you need.\r\n\\end{itemize}\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "ce41730f9829a3a01a950ee9967f295f87fc6617", "size": 18271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "taylor.tex", "max_stars_repo_name": "nilqed/REDHELP", "max_stars_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "taylor.tex", "max_issues_repo_name": "nilqed/REDHELP", "max_issues_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "taylor.tex", "max_forks_repo_name": "nilqed/REDHELP", "max_forks_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": 41.8100686499, "max_line_length": 87, "alphanum_fraction": 0.6879207487, "num_tokens": 4907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6437895990601828}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrcw}\n\\section*{\\hspace*{-1.6cm} tfrcw}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nChoi-Williams time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrcw(x)\n[tfr,t,f] = tfrcw(x,t)\n[tfr,t,f] = tfrcw(x,t,N)\n[tfr,t,f] = tfrcw(x,t,N,g)\n[tfr,t,f] = tfrcw(x,t,N,g,h)\n[tfr,t,f] = tfrcw(x,t,N,g,h,sigma)\n[tfr,t,f] = tfrcw(x,t,N,g,h,sigma,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrcw} computes the Choi-Williams distribution of a\n        discrete-time signal {\\ty x}, or the cross Choi-Williams\n        representation between two signals. This distribution has the\n        following expression :\n\n\\[CW_x(t,\\nu)=2\n\\iint_{-\\infty}^{+\\infty} \\dfrac{\\sqrt{\\sigma}}{4\\sqrt{\\pi}|\\tau|}\\\ne^{-v^2\\sigma/(16\\tau^2)}\\ x(t+v+\\frac{\\tau}{2})\\\nx^*(t+v-\\frac{\\tau}{2})\\ e^{-j2\\pi \\nu \\tau}\\ dv\\ d\\tau.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & signal if auto-CW, or {\\ty [x1,x2]} if cross-CW {\\ty\n\t\t\t(Nx=length(x))}\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty g}     & time smoothing window, {\\ty G(0)} being forced to {\\ty 1}, where {\\ty G(f)} is the Fourier transform of {\\ty g(t)}\n              &                           {\\ty window(odd(N/10))}\\\\\n        {\\ty h}     & frequency smoothing window, {\\ty h(0)} being forced to {\\ty 1}\n              &                           {\\ty window(odd(N/4))}\\\\ \n        {\\ty sigma} & kernel width             & {\\ty 1}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n              &                           {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation\\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrcw} runs {\\ty tfrqview}.\n\\end{minipage}\n\n\\newpage\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.05,0.3)+fmlin(128,0.15,0.4);  \n         g=window(9,'Kaiser'); h=window(27,'Kaiser'); \n         t=1:128; tfrcw(sig,t,128,g,h,3.6,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] H. Choi, W. Williams ``Improved Time-Frequency Representation of\nMulticomponent Signals Using Exponential Kernels'', IEEE Trans. on\nAcoustics, Speech and Signal Processing, Vol. 37, No. 6, June 1989.\n\\end{minipage}\n\n", "meta": {"hexsha": "f63f2e22fcd3499a709cb70c6eea6dcba75eece3", "size": 3043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrcw.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrcw.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrcw.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 31.0510204082, "max_line_length": 136, "alphanum_fraction": 0.587578048, "num_tokens": 1089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6436108443591974}}
{"text": "\\section{Stokes' Theorem}\\label{sec:StokesTheorem}\n\nRecall that one version of Green's Theorem (see\nEquation~\\ref{eq:greens theorem second form}) is\n$$\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}\n=\\iint_{D}(\\nabla\\times \\vect{f})\\cdot\\vect{k}\\,dA.\n$$\nHere $D$ is a region in the $x$-$y$ plane and $\\vect{k}$ is a unit normal\nto $D$ at every point. If $D$ is instead an orientable surface in\nspace, there is an obvious way to alter this equation, and it turns\nout still to be true:\n\n\\begin{theorem}{Stokes' Theorem}{}\nProvided that the quantities involved are\nsufficiently nice, and in particular if $D$ is orientable, \n$$\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}\n=\\iint_{D}(\\nabla\\times \\vect{f})\\cdot\\vect{N}\\,dS,$$\nif $\\partial D$ is oriented counter-clockwise relative to $\\vect{N}$.\\index{Stokes' theorem}\n\\end{theorem}\n\nThe proof of Stokes' Theorem will follow a discussion and several examples of the Theorem in use. \n\nNote how little has changed: $\\vect{k}$ becomes $\\vect{N}$, a unit normal to\nthe surface, and $dA$ becomes $dS$, since this is now a general\nsurface integral. The phrase ``counter-clockwise relative to $\\vect{N}$''\nmeans that if we take the direction of $\\vect{N}$ to be ``up'', then we\ngo around the boundary counter-clockwise when viewed from ``above''.\n\n\\begin{example}{}{}\nLet $\\vect{f}=\\langle  y^2z,x^2z,xy^2\\rangle$ \nand the surface $D$ be $x=\\sqrt{1-y^2-z^2}$, oriented in\nthe positive $x$ direction.\nIt quickly becomes apparent that the surface integral in Stokes'\nTheorem is intractable, so compute the line integral.\n\\end{example}\n\n\\begin{solution}\nThe boundary of\n$D$ is the unit circle in the $y$-$z$ plane, $\\vect{r}=\\langle 0,\\cos\nu,\\sin u\\rangle$, $0\\le u\\le 2\\pi$. The integral is\n$$\\int_0^{2\\pi} \\langle  y^2z,x^2z,xy^2 \\rangle\\cdot\n\\langle 0,-\\sin u,\\cos u\\rangle\\,du=\n\\int_0^{2\\pi} 0\\,du = 0,$$\nbecause $x=0$.\n\\end{solution}\n\nAn interesting consequence of Stokes' Theorem is that if $D$ and $E$\nare two orientable surfaces with the same boundary, then\n$$\n\\iint_{D}(\\nabla\\times \\vect{f})\\cdot\\vect{N}\\,dS\n=\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}\n=\\int_{\\partial E} \\vect{f}\\cdot d\\vect{r}\n=\\iint_{E}(\\nabla\\times \\vect{f})\\cdot\\vect{N}\\,dS.\n$$\nSometimes both of the integrals \n$$\\iint_{D}(\\nabla\\times \\vect{f})\\cdot\\vect{N}\\,dS\n\\qquad\\hbox{and}\\qquad\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$$\nare difficult, but you may be able to find a second surface $E$ so\nthat\n$$\\iint_{E}(\\nabla\\times \\vect{f})\\cdot\\vect{N}\\,dS$$\nhas the same value but is easier to compute.\n\nIn the previous example, the line integral was easy to\ncompute. But we might also notice that another surface $E$ with the\nsame boundary is the flat disk $y^2+z^2\\le 1$. \n\n\\begin{example}{}{}\nLet $\\vect{f}=\\langle  y^2z,x^2z,xy^2 \\rangle$ and the surface $E$ be $y^2+z^2\\le 1$. Compute the surface integral. \n\\end{example}\n\n\\begin{solution} \nThe unit normal $\\vect{N}$ for this surface is simply $\\vect{i}=\\langle 1,0,0\\rangle$. We compute\nthe curl:\n$$\\nabla\\times\\vect{f}=\\langle 2xy-x^2, 0, 2xz-2yz \\rangle.$$ \nSince $x=0$ everywhere on the surface,\n$$(\\nabla\\times\\vect{f})\\cdot \\vect{N}=\n\\langle 0, 0, 2xz-2yz \\rangle\\cdot\\langle 1,0,0\\rangle=0,$$\nso the surface integral is\n$$\\iint_{E}0\\,dS=0,$$\nas before. In this case, of course, it is still somewhat easier to\ncompute the line integral, avoiding $\\nabla\\times\\vect{f}$ entirely.\n\\end{solution}\n\n%\\begin{example}{}{}\n%Let $\\vect{f}=\\langle -y^2,x,z^2\\rangle$, and let the curve $C$\n%be the intersection of the cylinder $x^2+y^2=1$ with the plane\n%$y+z=2$, oriented counter-clockwise when viewed from above.\n%Compute $\\ds\\int_C \\vect{f}\\cdot d\\vect{r}$.\n%\\end{example}\n\n%\\begin{solution}\n%We compute $\\ds\\int_C \\vect{f}\\cdot d\\vect{r}$ in two ways.\n\n%First we do it directly: a vector function for $C$ is\n%$\\vect{r}=\\langle \\cos u,\\sin u, 2-\\sin u\\rangle$, so\n%$\\vect{r}'=\\langle -\\sin u,\\cos u,-\\cos u\\rangle$, and the integral is then\n%$$\\int_0^{2\\pi} y^2\\sin u+x\\cos u-z^2\\cos u\\,du\n%=\\int_0^{2\\pi} \\sin^3 u+\\cos^2 u-(2-\\sin u)^2\\cos u\\,du\n%=\\pi.$$\n\n%To use Stokes' Theorem, we pick a surface with $C$ as the boundary;\n%the simplest such surface is that portion of the plane $y+z=2$ inside\n%the cylinder. This has vector equation $\\vect{r}=\\langle\n%v\\cos u,v\\sin u,2-v\\sin u\\rangle$. We compute\n%$\\vect{r}_u= \\langle -v\\sin u,v\\cos u,-v\\cos u\\rangle$,\n%$\\vect{r}_v= \\langle \\cos u,\\sin u, -\\sin u\\rangle$, and \n%$\\vect{r}_u\\times\\vect{r}_v=\\langle 0,-v,-v\\rangle$. To match the\n%orientation of $C$ we need to use the normal $\\langle\n%0,v,v\\rangle$. The curl of $\\vect{f}$ is $\\langle 0,0,1+2y\\rangle=\n%\\langle 0,0,1+2v\\sin u\\rangle$, and\n%the surface integral from Stokes' Theorem is\n%$$\\int_0^{2\\pi}\\int_0^1 (1+2v\\sin u)v\\,dv\\,du=\\pi.$$\n%In this case the surface integral was more work to set up, but the\n%resulting integral is somewhat easier.\n%\\end{solution}\n\nNow let's look at the proof of Stokes' Theorem.\n\n\\begin{proof}\nWe can prove here a special case of Stokes' Theorem, which perhaps\nnot too surprisingly uses Green's Theorem.\n\nSuppose the surface $D$ of interest can be expressed in the form\n$z=g(x,y)$, and let $\\vect{f}=\\langle f_1,f_2,f_3\\rangle$. Using the vector\nfunction $\\vect{r}=\\langle x,y,g(x,y)\\rangle$ for the surface we get the\nsurface integral\n\\begin{align*}\n\\iint_{D} \\nabla\\times\\vect{f}\\cdot d\\vect{S}&=\n\\iint_{E} \\langle {\\partial f_3 \\over \\partial y}-{\\partial f_2 \\over \\partial z},{\\partial f_1 \\over \\partial z}-{\\partial f_3 \\over \\partial x},{\\partial f_2 \\over \\partial x}-{\\partial f_1 \\over \\partial y}\\rangle\\cdot\n\\langle -g_x,-g_y,1\\rangle\\,dA\t\\\\\n&=\\iint_{E} -{\\partial f_3 \\over \\partial x}g_x+{\\partial f_2 \\over \\partial z}g_x-{\\partial f_1 \\over \\partial z}g_y+{\\partial f_3 \\over \\partial x}g_y+{\\partial f_2 \\over \\partial x}-{\\partial f_1 \\over \\partial y}\\,dA.\n\\end{align*}\nHere $E$ is the region in the $x$-$y$ plane directly below the surface\n$D$. \n\nFor the line integral, we need a vector function for $\\partial D$. If \n$\\langle x(t),y(t)\\rangle$ is a vector function for \n$\\partial E$ then we may use $\\vect{r}(t)=\\langle x(t),y(t),g(x(t),y(t))\\rangle$\nto represent $\\partial D$. Then\n$$\\int_{\\partial D}\\vect{f}\\cdot d\\vect{r}\n=\\int_a^b f_1{dx\\over dt}+f_2{dy\\over dt}+f_3{dz\\over dt}\\,dt\n=\\int_a^b f_1{dx\\over dt}+f_2{dy\\over dt}+f_2\\left({\\partial z\\over\\partial\n    x}{dx\\over dt}+{\\partial z\\over\\partial y}{dy\\over dt}\\right)\\,dt.$$\nusing the chain rule for $dz/dt$. Now we continue to manipulate this:\n\\begin{align*}\n\\int_a^b f_1{dx\\over dt}+f_2{dy\\over dt}+&f_3\\left({\\partial z\\over\\partial\n    x}{dx\\over dt}+{\\partial z\\over\\partial y}{dy\\over dt}\\right)\\,dt\t\\\\\n&=\\int_a^b \\left[\\left(f_1+f_3{\\partial z\\over\\partial x}\\right){dx\\over dt}+\n\\left(f_2+f_3{\\partial z\\over\\partial y}\\right){dy\\over dt}\\right]\\,dt\t\\\\\n&=\\int_{\\partial E} \\left(f_1+f_3{\\partial z\\over\\partial x}\\right)\\,dx+\n\\left(f_2+f_3{\\partial z\\over\\partial y}\\right)\\,dy,\n\\end{align*}\nwhich now looks just like the line integral of Green's Theorem, except\nthat the functions $f_1$ and $f_2$ of Green's Theorem have been replaced\nby the more complicated $f_1+f_3(\\partial z/\\partial x)$\nand $f_2+f_3(\\partial z/\\partial y)$. We can apply Green's Theorem to get\n$$\\int_{\\partial E} \\left(f_1+f_3{\\partial z\\over\\partial x}\\right)\\,dx+\n\\left(f_2+f_3{\\partial z\\over\\partial y}\\right)\\,dy=\n\\iint_{E} {\\partial\\over \\partial x}\\left(f_2+f_3{\\partial z\\over\\partial y}\\right)\n-{\\partial\\over \\partial y}\\left(f_1+f_3{\\partial z\\over\\partial x}\\right)\\,dA.$$\nNow we can use the chain rule again to evaluate the derivatives\ninside this integral, and it becomes\n\\begin{align*}\n\\iint_{E} &{\\partial f_2 \\over \\partial x}+{\\partial f_2 \\over \\partial z}g_x+{\\partial f_3 \\over \\partial x}g_y+{\\partial f_3 \\over \\partial z}g_xg_y+f_3g_{yx}-\n\\left({\\partial f_1 \\over \\partial y}+{\\partial f_1 \\over \\partial z}g_y+{\\partial f_3 \\over \\partial y}g_x+{\\partial f_3 \\over \\partial z}g_yg_x+f_3g_{xy}\\right)\\,dA\t\\\\\n&=\\iint_{E} {\\partial f_2 \\over \\partial x}+{\\partial f_2 \\over \\partial z}g_x+{\\partial f_3 \\over \\partial x}g_y-{\\partial f_1 \\over \\partial y}-{\\partial f_1 \\over \\partial z}g_y-{\\partial f_3 \\over \\partial y}g_x\\,dA,\n\\end{align*}\nwhich is the same as the expression we obtained for the surface\nintegral.\n\\end{proof}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:StokesTheorem}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nLet $\\vect{f}=\\langle z,x,y\\rangle$.\nThe plane $z=2x+2y-1$ and the paraboloid $z=x^2+y^2$ intersect in a\nclosed curve. Stokes' Theorem implies that\n$$\\iint_{D_1} (\\nabla\\times\\vect{f})\\cdot \\vect{N}\\,dS=\n\\oint_C \\vect{f}\\cdot d\\vect{r}=\n\\iint_{D_2} (\\nabla\\times\\vect{f})\\cdot \\vect{N}\\,dS,\n$$\nwhere the line integral is computed over the intersection $C$ of the plane\nand the paraboloid, and the two surface integrals are computed over\nthe portions of the two surfaces that have boundary $C$ (provided, of\ncourse, that the orientations all match). Compute all three integrals.\n\\begin{sol}\n\t$-3\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $D$ be the portion of $z=1-x^2-y^2$ above the $x$-$y$\nplane, oriented up, and let $\\vect{f}=\\langle\nxy^2,-x^2y,xyz\\rangle$. Compute $\\ds\\iint_{D} (\\nabla\\times\\vect{f})\\cdot \\vect{N}\\,dS$.\n\\begin{sol}\n\t$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $D$ be the portion of $z=2x+5y$ inside $x^2+y^2=1$,\noriented up, and\nlet $\\vect{f}=\\langle y,z,-x\\rangle$. Compute\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$.\n\\begin{sol}\n\t$-4\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\oint_C x^2z\\,dx + 3x\\,dy - y^3\\,dz$, where $C$\nis the unit circle $\\ds x^2+y^2=1$ oriented counter-clockwise.\n\\begin{sol}\n\t$3\\pi$\n\\end{sol}\n%/Albert\n\\end{ex}\n\n\\begin{ex}\nLet $D$ be the portion of $z=px+qy+r$ over a region in the\n$x$-$y$ plane that has area $A$, oriented up, and \nlet $\\vect{f}=\\langle ax+by+cz,ax+by+cz,ax+by+cz\\rangle$. Compute\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}$.\n\\begin{sol}\n\t$A(p(c-b)+q(a-c)+a-b)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $D$ be any surface and \nlet $\\vect{f}=\\langle f_1(x),f_2(y),f_3(z)\\rangle$ ($f_1$ depends only on $x$,\n$f_2$ only on $y$, and $f_3$ only on $z$). Show that\n$\\ds\\int_{\\partial D} \\vect{f}\\cdot d\\vect{r}=0$.\n\\end{ex}\n\n\\begin{ex}\nShow that $\\ds\\int_C f\\nabla g+g\\nabla f\\cdot d\\vect{r}=0$, where\n$\\vect{r}$ describes a closed curve $C$ to which Stokes' Theorem\napplies.\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "ec131d6560010124504ea902f8813b2fd37f9cf9", "size": 10364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-8-stokes-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": "16-vector-calculus/16-8-stokes-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": "16-vector-calculus/16-8-stokes-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.7903225806, "max_line_length": 221, "alphanum_fraction": 0.6844847549, "num_tokens": 3880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.6436108196387235}}
{"text": "\\documentclass[12pt, a4paper]{IEEEtran}\n\\title{Standard for The Set Programming Language}\n\\author{Jedi Yang}\n\n\\usepackage{indentfirst}\n\n\\begin{document}\n\\maketitle\n\n\\section{Data Structure}\n\tThe Set Programming Language aims at using sets and assist with vectors to build a Functional Programming Language. The data structure of Set is more important than language and grammar.\n\n\\subsection{Atom}\n\tAtom is the fundamental unit of Set. It means a set with only one number, either an integer or a decimal, but only numbers are stored in atoms.\n\t\n\tAn atom can be expressed as $\\{A\\}$, but it can also be simplified as $A$. However, these two expression are different when doing calculation:\n\t\n\t$\\{A\\} + \\{B\\} == \\{A, B\\}$ while $A + B$ is the sum of number $A$ and $B$.\n\t\n\tAn Atom with brackets around accept Set Operations while an atom without brackets accept Basic Operations (see Operations)\n\t\n\t\\subsubsection{Number}\n\tDue to IEEE 754, if an integer is stored in a float or double, it is almost impossible to determine whether the number is an integer. The numbers in Set Programming Language use Irreducible Fractions to store both integers and decimals. An irreducible fraction contains two integers, a denominator and a numerator. Atoms can only store Irreducible Fractions.\n\t\\subsubsection{Boolean}\n\tBoolean is special number with true and false only. Typically an atom of 0/0 is false. A set containing value 0/0 is also false. Otherwise, valid numbers and sets are seen as true including zero. During comparison, true is returned as {1/1} and false is {0/0}.\n\n\\subsection{Set}\n\tSet is a new data structure that is rare in other programming languages. It is similar to an Array, but there are two restrictions:\n\t\\begin{enumerate}\n\t\\item A set has no two identical numbers\n\t\\item A set is ordered. The smallest is the head of the set.\n\t\\end{enumerate}\n\tIf a set does not meet the restrictions, identical numbers should be reduced and values are sorted automatically. Set can be catagorized into Enumerative Sets and Conditional Sets.\n\t\n\t\\subsubsection{Enumerative Sets}\n\tThis branch contains sets such that all numbers within the sets are listed. Enumerative Sets are stored in linked lists, with the smallest number is the head. All enumerative sets are finite.\n\t\t\n\tFor example: $\\{1, 3, 5, 17/2, 10\\}$ is an enumerative set.\n\t\t\n\t\\subsubsection{Conditional Sets}\n\tThis branch contains sets such that numbers are determined by an operation and conditions. Not all conditional sets are infinite, some of them can be listed out. \n\t\t\n\tFor example: $\\{x:2x+7|2<x<7\\}$ is a conditional set.\n\t\t\n\t%If the conditional set has less than one thousand numbers, the runtime should be able to convert the conditional set into an enumerative set\n\\subsection{Vector}\n\tVector is another name for Array. However, Vectors should accept vector operations such as dot product and it only accepts Numbers. Vectors and Sets are similar. Vectors are also stored in linked lists. The difference between Vectors and Sets are that vectors do not have restrictions for sets:\n\t\\begin{enumerate}\n\t\\item A vector can have two identical numbers\n\t\\item A vector can be randomly sorted.\n\t\\end{enumerate}\n\tThere is a special form of Vector. Transformation Vector.\n\t\n\t\\subsubsection{Transformation Vector}\n\tThis is vector that describes a series of transformation to one or more than one variables. In transformation vectors, Functions are stored. The return values of the prior function acts as the arguments for the next one.\n\t\n\t\\subsubsection{Function}\n\tIt is similar to Lambda Expressions in other programming languages. A function can only support one line of code. Except the return values and arguments of a function, the function cannot use other variables. Functions are better used in transformation vectors to support complex operations.\n\t\n\\subsection{String}\n\tString is a special vector, similar to most programming languages. However, it should have a different implementation using consequtive memory spaces.\n\t\n\\section{Operation}\n\\subsection{Numbers}\n\tUnary Operation\n\t\\begin{enumerate}\n\t\t\\item -x\n\t\\end{enumerate}\n\tBinary Operation: \n\t\\begin{enumerate}\n\t\t\\item x+y\n\t\t\\item x-y\n\t\t\\item x*y\n\t\t\\item x/y\n\t\t\\item x\\%y\n\t\t\\item x\\&y\n\t\t\\item x$|$y\n\t\t\\item x==y\n\t\t\\item x!=y\n\t\t\\item x>y\n\t\t\\item x<y\n\t\t\\item x>=y\n\t\t\\item x<=y\n\t\t\\item x\\&\\&y\n\t\t\\item x$||$y\n\t\\end{enumerate}\n\\subsection{Set \\& Number}\n\tBinary Operation:\n\t\\begin{enumerate}\n\t\t\\item s+x == s.append(x)\n\t\t\\item s-x == s.remove(x)\n\t\t\\item s*x == s.forEach({this$\\sim$this*x})\n\t\t\\item s/x == s.forEach({this$\\sim$this/x})\n\t\t\\item s\\%x ==s.forEach({this$\\sim$this\\%x})\n\t\\end{enumerate}\n\\subsection{Sets}\n\tBinary Operation:\n\t\\begin{enumerate}\n\t\t\\item u+v == v.forEach(u.append)\n\t\t\\item u-v == v.forEach(u.remove)\n\t\t\\item u*v == v.forEach(u.exist)\n\t\t\\item u/v == (u+v).forEach(xnor(u.exist,v.exist))\n\t\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "052924249e67993e4865085e0e479b9cd3b0c7c1", "size": 4865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "standard.tex", "max_stars_repo_name": "2000jedi/Set-Programming-Language", "max_stars_repo_head_hexsha": "fb5c96308d689a1f13e73926e01d7143494104b9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "standard.tex", "max_issues_repo_name": "2000jedi/Set-Programming-Language", "max_issues_repo_head_hexsha": "fb5c96308d689a1f13e73926e01d7143494104b9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-19T10:22:37.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-01T14:02:10.000Z", "max_forks_repo_path": "standard.tex", "max_forks_repo_name": "2000jedi/Set-Programming-Language", "max_forks_repo_head_hexsha": "fb5c96308d689a1f13e73926e01d7143494104b9", "max_forks_repo_licenses": ["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.7788461538, "max_line_length": 359, "alphanum_fraction": 0.7514902364, "num_tokens": 1261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6436108079697191}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Prison Cells}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Prison Cells}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Prison Cells}\n\n\\vspace{10 mm}\n\\begin{problem}\nA prison has $n$ cells with all cell doors shut initially. The warden is a little weird so he walks the whole row of cells and opens every cell door. Then he walks the whole row again and shuts every other cell door. Then he walks the whole row again and opens every third door then walks the row again and shuts every 4th door etc. You can assume that the doors are numbered $0$ to $(n - 1)$ and the warden always starts at zero and walks them in order. Which doors will stay open when the warden is done ? \n\\end{problem}\n\nEach time the warden walks the row of cells he toggles the state (open or close) of some of the cells. It is clear then that the number of toggles to one cell determines if it is open or closed in the end. In the beginning each cell door is closed so if the number of toggles is even then it stays closed, if it is odd then it is open at the end.\n\nThe goal then is to calculate the number of toggles for a cell. The cells are numbered $0$ to $(n - 1)$ so lets try to calculate the number of toggles for cell $k$. The first time the warden walks the row of cells he toggles each cell including our cell $k$. The second time he toggles cells $0, 2, 4, \\dots$. That means he toggles cell $k$ if k is even. The third time around he toggles cells $0, 3, 6, \\dots$ so he toggles cell $k$ if k is a multiple of 3. If we continue we see that the cell $k$ gets toggled on the warden's $d$ walk if $k$ is a multiple of $d$ or said differently if $d$ divides $k$.\n\nIt follows that the number of toggles $T(k)$ for cell $k$ is\n\n\\[\t \n\tT(k) = \\sum_{d \\mid k} 1.\n\\]\n\nThis is already pretty good but for the expression above it's not so obvious for which $k$ $T(k)$ will be even and for which it will be odd. So we will make a short excursion into basic number theory in the hopes that we can transform the expression into something more revealing.\n\n \\subsection{A little number theory}\n\nWe say that two integers $m$ and $n$ are \\textit{relatively prime} if the only common divisors are $\\pm 1$ and we write $(m, n) = 1$ in that case.\n\n\\begin{defn}\nA function $f:\\mathbb{N} \\rightarrow \\Omega$ with $\\Omega$ a field is said to be \\textbf{weakly multiplicative} if\n\n\\[\n\t\\forall \\ m, n \\in \\mathbb{N}: (m, n) = 1 \\ \\Rightarrow \\ f(mn) = f(m) f(n).\n\\]\n\\end{defn}\n\n\\begin{thm}\nIf $f$ is a weakly multiplicative function then so is the function\n\n\\[\n\tg(n) = \\sum_{d \\mid n} f(d).\n\\]\n\\end{thm}\n\n\\begin{proof}\n\t\nLet $m_1,m_2 \\in \\mathbb{N}$ with $(m_1, m_2) = 1$. Let's define two sets\n\n\\[\n\tS_1 = \\{ d\\ :\\ d \\mid m_1 m_2 \\}, \\ S_2 = \\{ d_1 d_2\\ :\\ d_1 \\mid m_1 \\wedge d_2 \\mid m_2 \\}.\n\\]\t\t\n\n\\noindent It is obvious that $S_2 \\subseteq S_1$. On the other hand\n\n\\[\n\t\\begin{array}{l}\n\t              \\forall x \\in S_1 \\leadsto x \\mid m_1 m_2 \\ \\mbox{(by definition)} \\\\\n\t              \\mbox{Let } \\ k = (x, m_1), \\mbox{ so } x = y k, m_1 = z k,  \\mbox{ for some } y, z \\in \\mathbb{N} \\mbox{ and } (y, z) = 1 \\\\\n\t              x \\mid m_1 m_2 \\leadsto y k \\mid z k m_2 \\leadsto y \\mid m_2 \\mbox{ because } (y, z) = 1\\\\\n\t              \\mbox{This means } x = y k \\in S_2 \\mbox{ because } y \\mid m_2 \\wedge k \\mid m_1.\n\t \\end{array}       \n\\]\n\n\\noindent So we have $S_1 = S_2$. We can now write\n\n\\[\n   \\begin{array}{lcl}\n\t\t&&g(m_1 m_2) \\\\\n\t      &=& { < \\mbox{definition of g} >} \\\\      \n                  &&(\\sum d: d \\mid m_1 m_2 : f(d)) \\\\\n       \t      &=& { < \\mbox{index sets }S_1 = S_2\\mbox{ so we change bounded variables}  >} \\\\\n                  && (\\sum d_1, d_2: d_1 \\mid m_1 \\wedge d_2 \\mid m_2 : f(d_1 d_2)) \\\\\n \t       &=& { < \\mbox{f is weakly multiplicative and } (d_1, d_2) = 1 > }  \\\\\n\t         && (\\sum d_1, d_2: d_1 \\mid m_1 \\wedge d_2 \\mid m_2 : f(d_1) f(d_2))\\\\\n\t        &=& { < \\mbox{nesting}  > }  \\\\ \n\t        && (\\sum d_1: d_1 \\mid m_1 : (\\sum d_2: d_2 \\mid m_2: f(d_1) f(d_2))) \\\\\n\t        &=& { < \\mbox{multiplication distributes over addition}  > }  \\\\\n\t         && (\\sum d_1: d_1 \\mid m_1 : f(d_1) (\\sum d_2: d_2 \\mid m_2: f(d_2))) \\\\\n\t        &=& { < \\mbox{definition of g}  > }  \\\\ \n\t        && (\\sum d_1: d_1 \\mid m_1 : f(d_1) g(m_2)) \\\\\n\t        &=& { < \\mbox{multiplication distributes over addition}  > }  \\\\\n\t        \t&& (\\sum d_1: d_1 \\mid m_1 : f(d_1)) g(m_2) \\\\\n\t\t&=& { < \\mbox{definition of g}  > }  \\\\ \n\t\t&& g(m_1) g(m_2).\n   \\end{array}\n\\]\nwhich proves the theorem.\n\\end{proof}\n\nThe theorem tells us that the function $T(k)$ which is the number of toggles for cell $k$\n\\[\t \n\tT(k) = \\sum_{d \\mid k} 1.\n\\]\nis in fact a weakly multiplicative function because the function inside the sum (the constant function 1) is trivially a weakly multiplicative function.\n\n\\subsection{A more detailed solution}\n\nIf we use the unique prime factorization of $k$\n\\[\n\tk = p_1^{a_1} p_1^{a_1} \\dots p_h^{a_h}\n\\]\nand use the fact that $(p_i^{a_i}, p_j^{a_j}) = 1$ we get\n\\[\n\tT(k) = \\prod_{i  = 1}^h T(p_i^{a_i}).\n\\]\t\t \n\nBut it's easy to see that $T(p_i^{a_i}) = a_i + 1$ so we have\n\\[\n\tT(k) = \\prod_{i  = 1}^h (a_i + 1).\n\\]\n\nWhen is $T(k)$ even ? When any of the $a_i$ are odd. To find out if a cell is open or closed do the prime factorization and look at the exponents of the primes. If any of them is odd then the cell stays closed.\t\n\n\\end{document}\n", "meta": {"hexsha": "51c00ae5f9e1fa7ed0fe297683ae2426c53196d5", "size": 5415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prison_cells/prison_cells.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": "prison_cells/prison_cells.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": "prison_cells/prison_cells.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": 45.5042016807, "max_line_length": 604, "alphanum_fraction": 0.6280701754, "num_tokens": 1884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754607093178, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.643558903414203}}
{"text": "% !TeX root = main.tex\n\n\\chapter{Matrix Multiplication}\n\\glsresetall\n\\label{chapter:matrix_multiplication}\n\nThis chapter looks at a bit more complex design -- matrix multiplication. We consider two different versions. We start with a ``straightforward'' implementation, i.e., one that takes two matrices as inputs and outputs the result of their multiplication. We call this complete matrix multiplication. Then, we look at a block matrix multiplication. Here the input matrices are feed into the function in portions, and the function computes partial results.\n\n\\section{Background}\n\nMatrix multiplication is a binary operation that combines two matrices into a third. The operation itself can be described as a linear operation on the vectors that compose the two matrices. The most common form of matrix multiplication is call the \\term{matrix product}. The matrix product $\\mathbf{AB}$ creates an $n \\times p$ matrix when matrix $\\mathbf{A}$ has dimensions $n \\times m$ and matrix $\\mathbf{B}$ has dimensions $m \\times p$. \n\nMore precisely, we define the following: \\begin{equation}\n\\mathbf{A} =\n \\begin{bmatrix}\n  A_{11} & A_{12}  & \\cdots & A_{1m} \\\\\n  A_{21} & A_{22}  & \\cdots & A_{2m} \\\\\n  \\vdots  & \\vdots  &\\ddots & \\vdots  \\\\\n    A_{n1} & A_{n2}  & \\cdots & A_{nm} \\\\\n \\end{bmatrix},  \\quad\n\\mathbf{B} =\n \\begin{bmatrix}\n  B_{11} & B_{12}  & \\cdots & B_{1p} \\\\\n  B_{21} & B_{22}  & \\cdots & B_{2p} \\\\\n  \\vdots  & \\vdots   &\\ddots & \\vdots  \\\\\n  B_{m1} & B_{m2}  & \\cdots & B_{mp} \\\\\n \\end{bmatrix}\n\\end{equation} \n\n\\begin{equation}\n\\mathbf{AB} = \\begin{bmatrix}\n \\left(\\mathbf{AB}\\right)_{11} & \\left(\\mathbf{AB}\\right)_{12} & \\cdots & \\left(\\mathbf{AB}\\right)_{1p} \\\\\n \\left(\\mathbf{AB}\\right)_{21} & \\left(\\mathbf{AB}\\right)_{22} & \\cdots & \\left(\\mathbf{AB}\\right)_{2p} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n \\left(\\mathbf{AB}\\right)_{n1} & \\left(\\mathbf{AB}\\right)_{n2} & \\cdots & \\left(\\mathbf{AB}\\right)_{np} \\\\\n\\end{bmatrix}\n\\end{equation} where the operation $\\left(\\mathbf{AB}\\right)_{ij}$ is defined as $\\left(\\mathbf{A}\\mathbf{B}\\right)_{ij} = \\sum_{k=1}^m A_{ik}B_{kj}$.\n\nNow we provide a simple example. Let\n\\begin{equation}\n\\mathbf{A} =\n \\begin{bmatrix}\n \\label{eq:ABmatrix}\n  A_{11} & A_{12}  &  A_{13} \\\\\n  A_{21} & A_{22} & A_{23} \\\\\n \\end{bmatrix},  \\quad\n\\mathbf{B} =\n \\begin{bmatrix}\n  B_{11} & B_{12}  \\\\\n  B_{21} & B_{22}   \\\\\n   B_{31} & B_{32}  \\\\\n \\end{bmatrix}\n\\end{equation}\nThe result of the matrix product is\n\\begin{equation}\\label{eq:ABmatrix_product}\\mathbf{AB} = \\begin{bmatrix}\n A_{11}B_{11} + A_{12}B_{21} + A_{13}B_{31} & A_{11}B_{12} + A_{12}B_{22} + A_{13}B_{32} \\\\\n A_{21}B_{11} + A_{22}B_{21} + A_{23}B_{31} & A_{21}B_{12} + A_{22}B_{22} + A_{23}B_{32}\\\\\n\\end{bmatrix}\n\\end{equation}\n\nMatrix multiplication is a fundamental operation in numerical algorithms. Computing the product between large matrices can take a significant amount of time. Therefore, it is critically important part of many of problems in numerical computing. Fundamentally, matrices represent linear transforms between vector spaces; matrix multiplication provides way to compose the linear transforms.  Applications include linearly changing coordinates (e.g., translation, rotation in graphics), high dimensional problems in statistical physics (e.g., transfer-matrix method), and graph operations (e.g., determining if a path exists from one vertex to another). Thus it is a well studied problem, and there are many algorithms that aim to increase its performance, and reduce the memory usage.\n\n\\begin{figure}\n\\lstinputlisting[firstline=5]{examples/matrixmultiplication.cpp}\n\\caption{A common three \\lstinline{for} loop structure for matrix multiplication. The outer \\lstinline{for} loops, labeled \\lstinline{rows} and \\lstinline{cols}, iterate across the rows and columns of the output matrix $\\mathbf{AB}$.  The innermost loop, labeled \\lstinline{product} multiplies the appropriate elements of one row of $\\mathbf{A}$ and one column of $\\mathbf{B}$ and accumulates them until it has the result for the element in $\\mathbf{AB}$ .  }\n\\label{fig:matrixmultiplication_sw}\n\\end{figure}\n\n\\section{Complete Matrix Multiplication}\n\nWe start our optimization process with perhaps the most common method to compute a matrix multiplication -- using three nested \\lstinline{for} loops. Figure \\ref{fig:matrixmultiplication_sw} provides the code for such an implementation.  The outer \\lstinline{for} loops, labeled \\lstinline{rows} and \\lstinline{cols}, iterate across the rows and columns of the output matrix $\\mathbf{AB}$. The innermost \\lstinline{for} loop computes a dot product of one row of $\\mathbf{A}$ and one column of $\\mathbf{B}$. Each dot product is a completely independent set of computations that results in one element of $\\mathbf{AB}$.  Conceptually, we are performing \\lstinline{P} matrix-vector multiplications, one for each column of $\\mathbf{B}$.\n\nIn this case, we've applied a \\lstinline{pipeline} directive to the \\lstinline{col} loop with a target initiation interval of 1. The result is that the innermost \\lstinline{for} loop is fully unrolled, and we expect the resulting circuit include roughly $M$ multiply-add operators and to have an interval of roughly $N*P$ cycles.  As discussed in Chapter \\ref{chapter:dft}, this is only one reasonable choice.  We could choose to place the \\lstinline{pipeline} directive in different locations in the function with the goal of achieving different resource-throughput tradeoffs. For instance, placing the same directive at the top of the function (outside all of the \\lstinline{for} loops) will result in all of the loops being completely unrolled, which would take roughly $N*M*P$ multiply-add operators and would have an interval of 1 cycle. Placing it inside the \\lstinline{row} loop would result in roughly $M*P$ multiply-add operators and an interval of roughly $N$ cycles. These design points are relatively easy to achieve, given the corresponding array partitioning.  It's also possible to pipeline the innermost loop with the goal of achieving a design with only one multiply-add operator, although achieving an II=1 implementation at high clock frequencies can be difficult because of the recurrence involved in the accumulation of variable \\lstinline{ABij}.  We can also partially unroll different loops to achieve yet more design points.  The fundamental tradeoff here is between the complexity of the resulting architecture, i.e., the number of multiply-add operators, and performance, i.e., the number of cycles that the hardware is busy.  In an ideal world, each doubling of the resource usage should result in exactly half the number of clock cycles being required, although in practice such `perfect scaling' is difficult to achieve.\n\n\\begin{exercise}\nChange the location of the \\lstinline{pipeline} directive. How does the location effect the resource usage? How does it change the performance? Which alternative provides the best performance in terms of function interval? Which provides the smallest resource usage? Where do you think is the best place for the directive? Would increasing the size of the matrices change your decision?\n\\end{exercise}\n\nExecuting large numbers of operations every cycle requires being able to supply all of the required operands and to store the results of each operation.   Previously we have used the \\lstinline{array_partition} directive to increase the number of accesses that can be performed on each memory.  As long as the partition of the array that each memory access can be determined at compile time, then array partitioning is a simple and efficient way to increase the number of memory accesses that can be performed each clock cycle.  In this case, we use the slightly different \\lstinline{array_reshape} directive to perform array partitioning.  This directive not only partitions the address space of the memory into separate memory blocks, but then recombines the memory blocks into a single memory.  This transformation increases the data width of the memory used to store the array, but doesn't change the overall number of bits being stored.  The difference is shown in Figure \\ref{fig:matmul_array_reshape}.\n\n\\begin{figure}\n\\centering\n\\includesvg{matmul_array_reshape}\n\\caption{Three different implementations of a two-dimensional array.  On the left is the original array consisting of $N*M$ elements.  In the middle, the array has been transformed using the \\lstinline{array_partition} directive, resulting in $M$ memories, each with $N$ elements.  On the right, the array has been transformed using the \\lstinline{array_reshape} directive, resulting in one memory with $N$ locations and each location contains $M$ elements of the original array.}\n\\label{fig:matmul_array_reshape}\n\\end{figure}\n\nBoth \\lstinline{array_reshape} and \\lstinline{array_partition} increase the number of array elements that can be read each clock cycle.  They also support the same options, enabling \\lstinline{cyclic} and \\lstinline{block} partitions or partitioning along different dimensions of a multi-dimensional array.  In the case of \\lstinline{array_reshape}, the elements must each have the same address in the transformed array, whereas with \\lstinline{array_partition}, the addresses in the transformed array can be unrelated.  Although it may seem like one would always want to use \\lstinline{array_partition} because it is more flexible, it makes each individual memory smaller, which can sometimes result in inefficient memory usage.  The \\lstinline{array_reshape} directive results in larger memory blocks, which can sometimes be mapped more efficiently into primitive FPGA resources.   In particular, the smallest granularity of \\gls{bram} blocks in Xilinx Virtex Ultrascale+ devices is 18 Kbits with several different supported combination of depths and widths.  When the partitions of an array become smaller than around 18Kbits, then BRAMs are no longer used efficiently.  If we start with an original array which is a 4-bit array with dimensions [1024][4], this array can fit in a single \\gls{bram} resource configured as a 4Kbit x 4 memory.  Partitioning this array completely in the second dimension would result in 4 1Kbit x 4 memories, each of which are much smaller than one one \\gls{bram} resource.  Reshaping the array instead using the \\lstinline{array_reshape} directive results in a memory which is 1Kbit x 16, a supported \\gls{bram} configuration.\n\n\n%  The other \\lstinline{array_reshape} directives modify the data layout for the input arrays $\\mathbf{A}$ and $\\mathbf{B}$. You can think of this directive as performing two operations. The first partitions the array into separate memories. The second operation combines these memories back into a single memory. This is similar to performing the \\lstinline{array_partition} directive followed by the \\lstinline{array_map} directive. The end result is still mapped into one array, but there are a smaller number of elements that are caused by grouping some of the elements from the original array into one element in the new array. \n\n%There are multiple arguments to the \\lstinline{array_reshape} directive. The \\lstinline{variable} argument specifies the name of the array to perform the reshaping.The \\lstinline{dim} argument indicates the dimension of the array to perform reshaping upon. This is only appropriate for multidimensional arrays. Another argument is \\lstinline{type} which is one of \\lstinline{block}, \\lstinline{cyclic}, or \\lstinline{complete}. \\lstinline{Block} combines adjacent elements into one larger element; \\lstinline{cyclic} combines interleaved elements into larger elements; and \\lstinline{complete} makes all of the elements into one very large element. The final argument is \\lstinline{factor}. This is only appropriate when using \\lstinline{block} and \\lstinline{cyclic} reshaping. It determines the size of the new elements.\n\n%The first \\lstinline{array_reshape} directive works on the $\\mathbf{A}$ array. It states that the second dimension should be completely partitioned. That is, all of the elements in the second dimension should be combined into a single element. This has the same effect as making $\\mathbf{A}$ into a one dimensional array where each element consists of the elements corresponding to the entire row of $\\mathbf{A}$. The second \\lstinline{array_reshape} directive performs a similar operation on the $\\mathbf{B}$ array. But here, it does a complete partitioning on the first dimension. This has the effect of combining all of the elements corresponding to one column into a single element. Thus, it is a one dimensional array, and when we index into the array we get a full columns with of data with each index. \n\n%Performing these two \\lstinline{array_reshape} directives allows us to fetch an entire row of the $\\mathbf{A}$ matrix and an entire column of the $\\mathbf{B}$ matrix with only two memory accesses. One access on $\\mathbf{A}$; and one access on $\\mathbf{B}$.\n\n\\begin{aside}\nNote that this partitioning is effective because the partitioned dimension (dimension 2 of $\\mathbf{A}$ or dimension 1 of $\\mathbf{B}$) is indexed by a constant.   In addition, the non-partitioned dimension is indexed by the same (variable) value.  When partitioning multi-dimensional arrays, this is a good rule of thumb to identify which dimension should be partitioned.\n\\end{aside}\n\n\\begin{exercise}\nRemove the \\lstinline{array_reshape} directives. How does this effect the performance? How does it change the resource usage? Does it make sense to use any other \\lstinline{array_reshape} directives (with different arguments) on these arrays?  In this case, how does the result differ if you use the \\lstinline{array_reshape} directive instead?\n\\end{exercise}\n\nThe size of the arrays can have a substantial effect on the optimizations that you wish to perform. Some applications might use very small matrices, say $2 \\times 2$ or $4 \\times 4$. In this cases, it may be desirable to implement a design with the absolute highest performance, which is generally achieved by applying the \\lstinline{pipeline} directive on the entire function.   As the size of the arrays increase, in the range of $32 \\times 32$, this approach quickly become infeasible because of the resource limits available in a single device.  There will simply not be enough DSP resources to implement that many multiplications every clock cycle or enough external bandwidth to get get data on and off the chip.  Many FPGA designs are often coupled to the data rates of other components in a system, such as an Analog to Digital (A/D) converter, or the symbol rate in a communication system.  In these designs it is common to instead apply the \\lstinline|pipeline| directive on inner loops with the goal of matching the interval of the computation with the data rate in a system.  In such cases, we often need to explore different resource-throughput tradeoffs by moving the \\lstinline{pipeline} directive into an inner loop or partially unrolling loops. When  \n dealing with very large matrices containing thousands or millions of elements, we often need to take into account more complex architectural considerations.  The next section discusses a common approach to scaling matrix multiply to larger designs, called \\term{blocking} or \\term{tiling}.\n\n\\begin{exercise}\nOptimize your design for the $128 \\times 128$ matrix multiplication. Then start increasing the size of the matrices by a factor of two (to $512 \\times 512$, $1024 \\times 1024$, $2048 \\times 2048$, etc. How does this effect the resource usage and performance? How about the runtime of the tool? What is the best way to optimize for large large matrix sizes?\n\\end{exercise}\n\n\\section{Block Matrix Multiplication}\n\nA \\term{block matrix} is interpreted as being partitioned into different submatrices. This can be visualized by drawing different horizontal and vertical lines across the elements of the matrix. The resulting ``blocks'' can be viewed as submatrices of the original matrix.  Alternatively, we can view the original matrix as a matrix of blocks.  This naturally leads to many hierarchical algorithms in Linear Algebra where we compute matrix operations, such as matrix multiply, on large block matrices by decomposing them into smaller matrix operations on the blocks themselves.\n\nFor instance, when we talk about the matrix multiplication operation between matrix $\\mathbf{A}$ and $\\mathbf{B}$ in Equations \\ref{eq:ABmatrix} and \\ref{eq:ABmatrix_product}, we might normally think of each element of the matrices $\\mathbf{A}_{11}$ or $\\mathbf{B}_{23}$ as a single number or perhaps a complex number.  Alternatively, we can consider each element in these matrix operations as a block of the original matrix.  In this case, as long as the sizes of the individual blocks are compatible, we simply have to perform the correct matrix operations instead of the original scalar operations.  For instance, to compute $\\mathbf{AB}_{11}$, we would need to compute two matrix products and two matrix sums to compute $\\mathbf{A}_{11}\\mathbf{B}_{11} + \\mathbf{A}_{12}\\mathbf{B}_{21} + \\mathbf{A}_{13}\\mathbf{B}_{31}$.\n\nMatrix blocking turns out to be a very useful technique for a number of reasons.  One reason is that blocking is an easy way to find more structure in the algorithm that we can explore.  In fact, some of the optimizations that we have already seen as loop transformations, such as loop unrolling, can be viewed as specific simple forms of blocking.  Another reason is that we can choose to block a matrix according to the natural structure of the matrix.  If a matrix has a large block of zeros, then many individual products may be zero.  If we want to skip these individual products then this can be difficult in a statically schedule pipeline, whereas it may be easier to skip a large block of zeros.  Many matrices are \\term{block-diagonal} where the blocks on the diagonal are non-zero and blocks off the diagonal are zero.  Yet another reason is that the blocked decomposition results in lots of smaller problems operating on smaller sets of data.  This increases the data locality of a computation.  In processor systems, it is common to choose block sizes that conveniently match the memory hierarchy of a processor or the natural size of the vector data types supported by the processor.  Similarly, in FPGAs we can choose the blocking sizes to match the available on-chip memory size or to the number of multiply-add operators that we can budget to support.\n\nUntil now, we have assumed that accelerators always have all of their data available before the start of a task.  However in designs dealing with large datasets, such as large matrices, this can sometimes be an unneeded constraint.  Since it is unlikely that our accelerator will be able to process all input data immediately, we can build an accelerator that receives input data only right before it is needed.  This allows an accelerator to more efficiently use the available on-chip memory.  We call this a \\term{streaming architecture} since we transfer the input data (and potentially the output data) one portion at a time rather than all at once.\n\nStreaming architectures are common in many applications.  In some cases this is because of a conscious design choice that we make to decompose a large computation into multiple smaller computations.  For instance, we may design a matrix multiplication system that reads and processes one block of data at a time from external memory.  In other cases, we might process a stream of data because the data is being sampled in real time from the physical world, for instance, from an A/D converter.  In other cases, the data we are processing may simply be created in sequence from a previous computation or accelerator.  In fact, we've already seen an instance of this in Section \\ref{sec:fft_task_pipelining}.\n\nOne potential advantage of streaming is a reduction in the memory that we can use to store the input and output data. The assumption here is that we can operate on the data in portions, create partial results, and then we are done with that data, thus we do not need to store it. When the next data arrives, we can overwrite the old data resulting in smaller memories.\n\nIn the following, we develop a streaming architecture for matrix multiplication. We divide the input arrays $\\mathbf{A}$ and $\\mathbf{B}$ into blocks, which are a contiguous set of rows and columns, respectively. Using these blocks, we compute a portion of the product $\\mathbf{AB}$. Then we stream the next set of blocks, compute another portion of $\\mathbf{AB}$ until the entire matrix multiplication is complete.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .85\\textwidth]{images/blockmm}\n\\caption{ One possible blocked decomposition of the matrix multiplication of two $4 \\times 4$ matrices. The entire $\\mathbf{AB}$ product is decomposed into four matrix multiply operations operating on a $2 \\times 4$ block of $\\mathbf{A}$ and a $4 \\times 2$ block of $\\mathbf{B}$.}\n\\label{fig:blockmm}\n\\end{figure}\n\nFigure \\ref{fig:blockmm} provides the a description of the streaming architecture that we create. Our architecture has a variable \\lstinline{BLOCK_SIZE} that indicates the number of rows that we take from the $\\mathbf{A}$ matrix on each execution, the number of columns taken from the $\\mathbf{B}$ matrix, and the \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} result matrix corresponding to the data that we compute each time for the $\\mathbf{AB}$ matrix. \n\nThe example in Figure \\ref{fig:blockmm} uses a \\lstinline{BLOCK_SIZE = 2}. Thus we take two rows from $\\mathbf{A}$, and two columns from $\\mathbf{B}$  on each execution of the streaming architecture that we define. The result of each call to the \\lstinline{blockmatmul} function is a $2 \\times 2$ matrix for the $\\mathbf{AB}$ architecture.\n\nSince we are dealing with $4 \\times 4$ matrices in the example, we need to do this process four times. Each time we get a $2 \\times 2$ set of results for the $\\mathbf{AB}$ matrix. The figure shows a progression of the rows and columns that we send. In Figure \\ref{fig:blockmm} a) we send the first two rows of $\\mathbf{A}$ and the first two columns of $\\mathbf{B}$. The function will compute a $2 \\times 2$ matrix corresponding to the first two elements in the rows and columns of the resulting matrix $\\mathbf{AB}$. \n\nIn Figure \\ref{fig:blockmm} b), we use again the first two rows of $\\mathbf{A}$, but this time we send the last two columns of $\\mathbf{B}$. We do not need to resend the data from the rows of $\\mathbf{A}$ since they are the same as the previous data from the previous execution. And we get the results for the $2 \\times 2$ matrix corresponding to the data in ``upper left'' corner of $\\mathbf{AB}$. \n\nFigure \\ref{fig:blockmm} c) sends different data for both the $\\mathbf{A}$ and $\\mathbf{B}$ matrices. This time we send the last two rows of $\\mathbf{A}$ and the first two columns of $\\mathbf{B}$. The results from this computation provide the ``lower left'' corner of the $\\mathbf{AB}$ matrix.\n\nThe final execution of the streaming block matrix multiply, shown in Figure \\ref{fig:blockmm} d), uses the same last two rows of the $\\mathbf{A}$ matrix from the previous iteration. And it sends the last two columns of the $\\mathbf{B}$ matrix. The result provides the elements in the ``lower right'' corner of the $\\mathbf{AB}$ matrix. \n\n\\begin{figure}\n\\lstinputlisting{examples/block_mm.h}\n\\caption{  The header file for the block matrix multiplication architecture. The file defines the data types used within the function, the key constants, and the \\lstinline{blockmatmul} function interface.   }\n\\label{fig:block_mm_h}\n\\end{figure}\n\nBefore we show the code for the block matrix multiplication, we define some data types that we will use. Figure \\ref{fig:block_mm_h} shows the header file for the project. We create a custom data type \\lstinline{DTYPE} that specifies the type of data that we will multiply in the $\\mathbf{A}$ and $\\mathbf{B}$ matrices, and the corresponding $\\mathbf{AB}$ matrix. This is currently set to an \\lstinline{int} data type.\n\n\\begin{aside}\nIt is good coding practice to use a custom data type in your designs. This allows you to easily change the data type, and to have one source of information so that you do not have errors when changing the data type in the future design iterations. And it is quite common to change the data type over the course of the design. For example, first you may start out with a \\lstinline{float} or \\lstinline{double} type while you get a functionally correct design. This also provides a baseline for error since later you will likely change your design to use fixed point data type.  Fixed point data can reduce the number of resources, and increase the performance potentially at the cost of a reduction in the precision of the resulting data. You will likely try many different fixed point types until you find the right tradeoff between accuracy/error, performance, and resource usage.\n\\end{aside}\n\n\\lstinline{SIZE} determines the number of rows and columns in the matrices to be multiplied. We limit this to square matrices although handling arbitrary matrix sizes could be done by changing the code in a number of different places. We leave that as an exercise for the reader.\n\n\\begin{exercise}\nChange the code to allow it to handle matrices of arbitrary size. \n\\end{exercise}\n\nThe \\lstinline{BLOCK_SIZE} variable defines the number of rows from $\\mathbf{A}$ and the number of columns from $\\mathbf{B}$ that we operate upon in each execution. This also defines how much data that we stream at one time into the function. The output data that we receive from the function at each execution is an \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} portion of the $\\mathbf{AB}$ matrix. \n\nThe \\lstinline{blockvec} data type is used to transfer the \\lstinline{BLOCK_SIZE} rows of $\\mathbf{A}$ and columns of $\\mathbf{B}$ to the function on each execution. The \\lstinline{blockmat} data type is where we store the partial results for the $\\mathbf{AB}$ matrix. \n\nFinally, the \\lstinline{blockmat} data type is a structure consisting of an \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} array. This holds the resulting values from one execution of the \\lstinline{matrmatmul} function. \n\nThe function prototype itself takes the two inputs which are both of the type \\lstinline{hls::stream<blockvec> &}. These are a sequence of \\lstinline{blockvec} data. Remember that a \\lstinline{blockvec} is a data type that consists of an array with \\lstinline{BLOCK_SIZE} elements. \n\nThe \\lstinline{hls::stream<>} template class is one way in \\VHLS of creating a FIFO data structure that works well in simulation and synthesis. The samples are sent in sequential order using the \\lstinline{write()} function, and retrieved using the \\lstinline{read()} function. This library was developed since streaming is a common methodology for passing data in hardware design, yet this same operation can be modeled in many different ways using the C programming language, for instance, by using arrays. In particular, it can be difficult for the \\VHLS tool to infer streaming behaviors when dealing complex access patterns or multi-dimensional arrays. The built-in stream library enables the programmer to explicitly specify the order of stream accesses, avoiding any limitations of this inference. \n\n\\begin{aside}\nThe \\lstinline{hls::stream} class must always be passed by reference between functions, e.g., as we have done in the \\lstinline{blockmatmul} function in Figure \\ref{fig:block_mm}.\n\\end{aside}\n\n\\begin{figure}\n\\lstinputlisting[format=none]{examples/block_mm.cpp}\n\\caption{  The \\lstinline{blockmatmul} function takes a \\lstinline{BLOCK_SIZE} set of rows from $\\mathbf{A}$ matrix, a \\lstinline{BLOCK_SIZE} set of columns from the $\\mathbf{B}$ matrix, and creates a \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} partial result for the $\\mathbf{AB}$ matrix. The first part of the code (denoted by the label \\lstinline{loadA}) stores the rows from $\\mathbf{A}$ into a local memory, the second part in the nested \\lstinline{partialsum for} performs the computation for the partial results, and the final part (with the \\lstinline{writeoutput} label) takes these results and puts them the proper form to return from the function.}\n\\label{fig:block_mm}\n\\end{figure}\n\nThe code for executing one part of the streaming block matrix multiplication is shown in Figure \\ref{fig:block_mm}. The code has three portions denoted by the labels \\lstinline{loadA}, \\lstinline{partialsum}, and \\lstinline{writeoutput}. \n\nThe first part of the code, denoted by the \\lstinline{loadA} label, is only executed on certain conditions, more precisely when \\lstinline{it % (SIZE/BLOCK_SIZE) == 0}. This is done to save some time in the cases when we can reuse the data from the $\\mathbf{A}$ matrix from the previous execution of the function. \n\nRemember that in each execution of this \\lstinline{blockmatmul} function we send \\lstinline{BLOCK_SIZE} rows from the $\\mathbf{A}$ matrix and \\lstinline{BLOCK_SIZE} columns from the $\\mathbf{B}$ matrix. We send multiple \\lstinline{BLOCK_SIZE} of columns for each \\lstinline{BLOCK_SIZE} of rows from $\\mathbf{A}$. The variable \\lstinline{it} keeps track of the number of times that we have called the \\lstinline{blockmatmul} function. Thus, we do a check on each execution of the function to determine if we need to load the rows from $\\mathbf{A}$. When we do not, this saves us some time. When it is executed, it simply pulls data from the \\lstinline{Arows} stream and puts it into a static local two-dimensional matrix \\lstinline{A[BLOCK_SIZE][SIZE]}. \n\nFully understanding this code requires some explanation about the \\lstinline{stream} class, and how we are using it. The \\lstinline{stream} variable \\lstinline{Arows} has elements of the type \\lstinline{blockvec}. A \\lstinline{blockvec} is a matrix of size \\lstinline{BLOCK_SIZE}. We use this in the following manner; each element in the \\lstinline{Arows} stream has an array that holds one element from each of the \\lstinline{BLOCK_SIZE} rows of the $\\mathbf{A}$ matrix. Thus, in each call the the \\lstinline{blockmatmul} function, the \\lstinline{Arows} stream will have \\lstinline{SIZE} elements in it, each of those holding one of each of the \\lstinline{BLOCK_SIZE} rows. The statement \\lstinline{tempA = Arows.read()} takes one element from the \\lstinline{Arows} stream. Then we load each of these elements into the appropriate index in the local \\lstinline{A} matrix.\n\n\\begin{aside}\nThe \\lstinline{stream} class overloads the \\lstinline{<<} operator to be equivalent to the \\lstinline{read()} function. Thus, the statements \\lstinline{tempA = Arows.read()} and \\lstinline{tempA << Arows} perform the same operation.\n\\end{aside}\n\nThe next part of the computation calculates the partial sums. This is the bulk of the computation in the \\lstinline{blockmatmul} function. \n\nThe \\lstinline{Bcols} stream variable is utilized in a very similar manner to the \\lstinline{Arows} variable. However, instead of storing rows of $\\mathbf{A}$, it stores the data corresponding the columns of $\\mathbf{B}$ that the current execution of the function is computing upon. Every call of the \\lstinline{blockmatmul} function will provide new data for the columns of the $\\mathbf{B}$ matrix. Thus, we do not need to conditionally load this data as we do with the $\\mathbf{A}$ matrix. The function itself works in a very similar manner to that from the \\lstinline{matmul} in Figure \\ref{fig:matrixmultiplication_sw} except that we are only calculating \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} results from the $\\mathbf{AB}$ matrix. Thus we only have to iterate across \\lstinline{BLOCK_SIZE} rows of $\\mathbf{A}$ and \\lstinline{BLOCK_SIZE} columns of $\\mathbf{B}$. But each row and column has \\lstinline{SIZE} elements, hence the bounds on the outer \\lstinline{for} loop. \n\nThe final portion of the function moves the data from the local \\lstinline{AB} array, which has dimensions of \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE}; this holds the partial results of the $\\mathbf{AB}$ output matrix. %The results are written into the \\lstinline{out_temp} variable, which has the data type \\lstinline{blockmat}. This data type is a \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} two dimension matrix. The \\lstinline{out_temp} data is pushed into the \\lstinline{ABpartial} stream in the statement \\lstinline{ABpartial.write(out_temp);}\n\nOf the three parts of the function, the middle part, which calculates the partial sum, requires the most computation. By inspecting the code, we can see that this part has three nested \\lstinline{for} loops with a total of \\lstinline{SIZE} $\\times$ \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} iterations. The first part has \\lstinline{SIZE} $\\times$ \\lstinline{BLOCK_SIZE} iterations; and the last part has \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} iterations. Thus, we should focus our optimizations on the middle part, i.e., the \\lstinline{partialsum} nested \\lstinline{for} loops.\n\nThe common starting point for optimizations of nested \\lstinline{for} loops is to pipeline the innermost \\lstinline{for} loop. Then, if that does not require too many resources, the designer can move the \\lstinline{pipeline} directive into higher level \\lstinline{for} loops. Whether the resulting design consume too many resource depends upon the specified \\lstinline{BLOCK_SIZE}; if this is small, then it is likely worth moving the \\lstinline{pipeline} directive. It may even be worthwhile to move it inside the outermost \\lstinline{for} loop. This will unroll the two inner \\lstinline{for} loops and thus very likely increase the resource usage by a substantial amount. However, it will increase the performance.\n\n\\begin{exercise}\nHow does changing the \\lstinline{BLOCK_SIZE} effect the performance and resource usage? How about changing the \\lstinline{SIZE} constant? How does moving the \\lstinline{pipeline} directive across the three different nested \\lstinline{for} loops in the \\lstinline{partialsum} portion of the function change the performance and resource usage?\n\\end{exercise}\n\nThe \\lstinline{dataflow} directive at the start of the function creates a pipeline across the portions of the function, i.e., the \\lstinline{loadA for} loop, the \\lstinline{partialsum} nested \\lstinline{for} loop, and the \\lstinline{writeoutput for} loop. Using this directive will decrease the interval of the \\lstinline{blockmatmul} function. However, this is limited by the largest interval of all three of the portions of the code. That is, the maximum interval for the \\lstinline{blockmatmul} function -- let us call it interval(\\lstinline{blockmatmul}) -- is greater than or equal to the the interval of the three parts which are defined as interval(\\lstinline{loadA}), interval(\\lstinline{partialsum}), and interval(\\lstinline{writeoutput}). More formally, \n\n\\begin{align}\n\\label{eq:interval}\ninterval(\\texttt{blockmatmul}) \\ge \\max(&interval(\\texttt{loadA}), interval(\\texttt{partialsum}), \\nonumber \\\\\n & interval(\\texttt{writeoutput}))\n \\end{align}\n\nWe need to keep Equation \\ref{eq:interval} in mind as we optimize the \\lstinline{blockmatmul} function. For example, assume that interval(\\lstinline{partialsum}) is much larger than the other two portions of the function. Any performance optimizations that minimize interval(\\lstinline{loadA}) and interval(\\lstinline{writeoutput}) are useless since the function interval, i.e., interval(\\lstinline{blockmatmul}) would not decrease. Thus, the designer should focus any performance optimization effort to decrease interval(\\lstinline{partialsum}), i.e., target performance optimizations on those three nested \\lstinline{for} loops. \n\nIt is important to note that this only applies to performance optimizations. The designer can (and should) optimize the resource usage of these other two parts. In fact, they are ripe for such optimizations since reducing the resource usage often increases the interval and/or latency. In this case, it is ok to increase the interval as it will not effect the overall performance of the \\lstinline{blockmatmul} function. In fact, the ideal case is to optimize all three parts of the function such that they all have the same interval, assuming that we can easily tradeoff between the interval and resource usage (which is not always the case). \n\nThe testbench for the \\lstinline{blockmatmul} function is shown in Figures \\ref{fig:block_mm_init} and \\ref{fig:block_mm_final}. We split it across two figures to make it more readable since it is a longer piece of code. Up until this point, we have not shown the testbenches. We show this testbench for several reasons. First, it provides insight into how the \\lstinline{blockmatmul} function works. In particular, it partitions the input matrices into blocks and feeds them into the \\lstinline{blockmatmul} function in a block by block manner. Second, it gives a complex usage scenario for using \\lstinline{stream} template for simulation. Finally, it gives the reader an idea about how to properly design testbenches.\n\nThe \\lstinline{matmatmul_sw} function is a simple three \\lstinline{for} loop implementation of matrix multiplication. It takes two two-dimensional matrices as inputs, and outputs a single two-dimensional matrix. It is very similar to what we have seen in the \\lstinline{matrixmul} function in Figure \\ref{fig:matrixmultiplication_sw}. We use this to compare our results from the blocked matrix multiplication hardware version.\n\nLet us focus on the first half of the testbench shown in Figure \\ref{fig:block_mm_init}. The beginning block of code initializes variables of the rest of the function. The variable \\lstinline{fail} keeps track of whether the matrix multiplication was done correctly. We will check this later in the function. The variables \\lstinline{strm_matrix1} and \\lstinline{strm_matrix2} are \\lstinline{hls:stream<>} variables that hold the rows and columns of the $\\mathbf{A}$ and $\\mathbf{B}$ matrices, respectively. Each element of these \\lstinline{stream} variables is a \\lstinline{<blockvec>}. Referring back at the \\lstinline{block_mm.h} file in Figure \\ref{fig:block_mm_h}, we recall that a \\lstinline{blockvec} is defined as an array of data; we will use each \\lstinline{blockvec} to store one row or column of data. \n\n\\begin{aside}\nThe \\lstinline{stream} variable resides in the \\lstinline{hls} namespace. Thus, we can use that namespace and forgo the \\lstinline{hls::stream} and instead simply use \\lstinline{stream}. However, the preferred usage is to keep the \\lstinline{hls::} in front of the \\lstinline{stream} to insure code readers that the stream is relevant to \\VHLS and not C construct from another library. Also, it avoids having to deal with any potential conflicts that may occur by introducing a new namespace.\n\\end{aside}\n\nThe next definitions in this beginning block of code are the variables \\lstinline{strm_matrix1_element} and \\lstinline{strm_matrix2_element}. These two variables are used as placeholders to populate each \\lstinline{blockvec} variable that we write into the \\lstinline{strm_matrix1} and \\lstinline{strm_matrix2} stream variables. The \\lstinline{block_out} variable is used to store the output results from the \\lstinline{blockmatmul} function. Note that this variable uses the data type \\lstinline{blockmat} which is a two-dimensional array of \\lstinline{BLOCK_SIZE} $\\times$ \\lstinline{BLOCK_SIZE} as defined in the \\lstinline{block_mm.h} header file (see Figure \\ref{fig:block_mm_h}). The final definitions are \\lstinline{A},  \\lstinline{B},  \\lstinline{matrix_swout},  and\\lstinline{matrix_hwout}. These are all \\lstinline{SIZE} $\\times$ \\lstinline{SIZE} two-dimensional arrays with the \\lstinline{DTYPE} data type. \n\n\\begin{aside}\nYou can name the streams using an initializer. This is good practice as it gives better error messages. Without the name, the error message provides a generic reference to the stream with the data type. If you have multiple stream declarations with the same data type, then you will have to figure out which stream the error is referring to. Naming the stream variable is done by giving the variable an argument which is the name, e.g., \\lstinline{hls::stream<blockvec> strm_matrix1(\"strm_matrix1\");}.\n\\end{aside}\n\nThe next set of nested \\lstinline{initmatrices for} loops sets the values of the four two-dimensional arrays \\lstinline{A}, \\lstinline{B}, \\lstinline{matrix_swout}, and \\lstinline{matrix_hwout}. The variables \\lstinline{A} and \\lstinline{B} are input matrices. These are initialized to a random value between [0, 512). We picked the number 512 for no particular reason other than it can fit any 9 bit value. Keep in mind that while the \\lstinline{DTYPE} is set as an \\lstinline{int}, and thus has significantly more range than [0,512), we often move to fixed point values with much smaller ranges later in the design optimization process. The \\lstinline{matrix_swout} and \\lstinline{matrix_hwout} are both initialized to $0$. These are filled in later by calls to the functions \\lstinline{matmatmul_sw} and \\lstinline{blockmatmul}.\n\n\\begin{figure}\n\\lstinputlisting{examples/blockmatmul_test_init.cpp}\n\\caption{  The first part of the testbench for block matrix multiplication. The function is split across two figures since it is too long to display on one page. The rest of the testbench is in Figure \\ref{fig:block_mm_final}. This has a ``software'' version of matrix multiplication, and variable declarations and initializations. }\n\\label{fig:block_mm_init}\n\\end{figure}\n\nThe second part of the testbench is continued in Figure \\ref{fig:block_mm_final}. This has the last portion of the code from the \\lstinline{main} function. \n\n\\begin{figure}\n\\lstinputlisting[format=none]{examples/blockmatmul_test.cpp}\n\\caption{  The second portion of the block matrix multiply testbench. The first part is shown in Figure \\ref{fig:block_mm_init}. This shows the computation required to stream the data to the \\lstinline{blockmatmul} function, and the code that tests that this function matches a simpler three \\lstinline{for} loop implementation. }\n\\label{fig:block_mm_final}\n\\end{figure}\n\nThe first part of this figure has a complex set of nested \\lstinline{for} loops. The overall goal of the computation in these \\lstinline{for} loops is to set up the data from the input matrices $\\mathbf{A}$ and $\\mathbf{B}$ so that it can be streamed to the \\lstinline{blockmatmul} function. Then the results of the \\lstinline{blockmatmul} function are stored in the \\lstinline{matrix_hwout} array. \n\nThe outer two \\lstinline{for} loops are used to step across the input arrays in a blocked manner. You can see that these both iterate by a step of \\lstinline{BLOCK_SIZE}. The next two \\lstinline{for} loops write rows from $\\mathbf{A}$ into \\lstinline{strm_matrix1_element} and the columns from $\\mathbf{B}$ into \\lstinline{strm_matrix2_element}. It does this in an element by element fashion by using the variable \\lstinline{k} to access the individual values from the rows (columns) and write these into the one dimensional array for each of these ``elements''. Remember that both \\lstinline{strm_matrix1_element} and \\lstinline{strm_matrix2_element} have the datatype \\lstinline{blockvec}, which is a one dimensional array of size \\lstinline{BLOCK_SIZE}. It is meant to hold \\lstinline{BLOCK_SIZE} elements from each row or column. The inner \\lstinline{for} loop iterates \\lstinline{BLOCK_SIZE} times. The \\lstinline{strm_matrix1} and \\lstinline{strm_matrix2} stream variables are written to \\lstinline{SIZE} times. That means that has a buffer of the entire row (or column) and each element in the buffer holds \\lstinline{BLOCK_SIZE} values. \n\n\\begin{aside}\nThe \\lstinline{stream} class overloads the \\lstinline{>>} operator to be equivalent to the \\lstinline{write(data)} function. This is similar to overloading the \\lstinline{read()} function to the \\lstinline{<<} operator. Thus, the statements \\lstinline{strm_matrix1.write(strm_matrix1_element)} and \\lstinline{strm_matrix1_element >> strm_matrix1} perform the same operation.\n\\end{aside}\n\nThe final part of this portion of the code to highlight is the \\lstinline{if} statements. These are correspond to the values $\\mathbf{A}$ matrix. Essentially, these are there so that we do not constantly write the same values to \\lstinline{strm_matrix1}. Recall that the values from the $\\mathbf{A}$ matrix are used across several calls to the \\lstinline{blockmatmul} function. See Figure \\ref{fig:blockmm} for a discussion on this. These \\lstinline{if} statements are placed there to highlight the fact that you should not continually write the same data over and over. This is important because the internal code of the \\lstinline{blockmatmul} only does a read of this data when it is necessary. So if we continued to write this consistently, the code would not function correctly do to the fact that this stream is written to more than it is read from.\n\nNow that the input data, the testbench calls the \\lstinline{blockmatmul} function. After the function call, it receives the partial computed results in the \\lstinline{block_out} variable. The next two \\lstinline{for} loops but these results into the appropriate locations in the \\lstinline{matrix_hwout} array. \n\nAfter this complex set of \\lstinline{for} loops, the block matrix multiplication is complete. And the testbench continues to insure that the code is written correctly. It does this by comparing the results from the multiple calls to the \\lstinline{blockmatmul} function to results that were computed in the \\lstinline{matmatmul_sw}, which is a much simpler version of matrix matrix multiplication. After this function call, the testbench iterates through both two-dimensional matrices \\lstinline{matrix_hwout} and \\lstinline{matrix_swout} and makes sure that all of the elements are equivalent. If there is one or more element that is not equal, it sets the \\lstinline{fail} flag equal to 1. The testbench completes by printing out \\lstinline{failed} or \\lstinline{passed}.\n\n\\begin{aside}\nIt is important that note that you cannot directly compare the performance of the function \\lstinline{blockmatmul} with that of code for matrix multiplication, such as the code in Figure \\ref{fig:matrixmultiplication_sw}. This is because it takes multiple calls to the \\lstinline{blockmatmul} function in order to perform the entire matrix multiplication. It is important to always compare apples to apples.\n\n\\begin{exercise}\nDerive a function to determine the number of times that \\lstinline{blockmatmul} must be called in order to complete the entire matrix multiplication. This function should be generic, e.g., it should not be assume a specific value of \\lstinline{BLOCK_SIZE} or size of the matrix (i.e., \\lstinline{SIZE}).\n\\end{exercise}\n\n\\begin{exercise}\nCompare the resource usage of block matrix multiplication versus matrix multiplication. How do the resources change as the size of the matrices increases? Does the block size play a role in the resource usage? What are the general trends, if any?\n\\end{exercise}\n\n\\begin{exercise}\nCompare the performance of block matrix multiplication versus matrix multiplication. How does the performance change as the size of the matrices increases? Does the block size play a role in the performance? Pick two architectures with similar resource usage. How does the performance for those architectures compare?\n\\end{exercise}\n\n\\end{aside}\n\n\\section{Conclusion}\n\nBlock matrix multiplication provides a different way to compute matrix multiplication. It computes partial results of the result matrix by streaming a subset of the input matrices to a function. This function is then computed multiple times in order to complete the entire matrix multiplication computation. \n\n\n", "meta": {"hexsha": "30bb53b7ae9cb352f15e0590ebae7d7f2015f1e3", "size": 47941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matrix_multiplication.tex", "max_stars_repo_name": "mithro/pp4fpgas", "max_stars_repo_head_hexsha": "ddede5bd337f4fa33915d7e4ca98f97a7b31413a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 418, "max_stars_repo_stars_event_min_datetime": "2018-05-09T17:28:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T05:51:12.000Z", "max_issues_repo_path": "matrix_multiplication.tex", "max_issues_repo_name": "jmuuu/pp4fpgas", "max_issues_repo_head_hexsha": "f604b68289b0a9998ace596c57ea7209f2d60fd5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-05-13T16:26:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T06:06:57.000Z", "max_forks_repo_path": "matrix_multiplication.tex", "max_forks_repo_name": "jmuuu/pp4fpgas", "max_forks_repo_head_hexsha": "f604b68289b0a9998ace596c57ea7209f2d60fd5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 107, "max_forks_repo_forks_event_min_datetime": "2018-05-12T16:43:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T22:59:42.000Z", "avg_line_length": 163.6211604096, "max_line_length": 1849, "alphanum_fraction": 0.784651968, "num_tokens": 11458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.884039280218458, "lm_q1q2_score": 0.6435588918675491}}
{"text": "%!TEX root = ../main.tex\n%-------------------------------------------------------------------------------\n\\subsection{Mathematical formulation}\\label{Mathematics}\n%-------------------------------------------------------------------------------\nEKW models are set up as a standard Markov decision process (MDP) \\citep{Puterman.1994, White.1993}. When making sequential decisions under uncertainty, the task is to determine the optimal policy $\\pi^*$ with the largest expected total discounted utilities $v^{\\pi^*}_1(s_1)$ as formalized in equation (\\ref{Objective Risk}). In principle, this requires evaluating the performance of all policies based on all possible sequences of utilities, each weighted by the probability with which they occur. Fortunately, however, the multistage problem can be solved by a sequence of simpler inductively defined single-stage problems.\\footnote{Optimal decisions in an MDP are a deterministic function of the current state $s$ only, i.e., an optimal decision rule is always deterministic and Markovian. We restrict our notation to this special case right from the beginning.}\\\\\n\n\\noindent The value function $v^\\pi_t(s_t)$ captures the expected total discounted utilities under policy $\\pi$ from period $t$ onwards for an individual experiencing state $s_t$:\n%\n\\begin{align*}\n  v^\\pi_t(s_t) \\equiv \\E_{s_t}^\\pi\\left[\\left.\\sum^{T - t}_{j = 0}  \\delta^j\\, u_{t + j}(s_{t + j}, a^\\pi_{t + j}(s_{t + j})) \\,\\right\\vert\\,\\mathcal{I}_t\\,\\right].\n\\end{align*}\n%\nThen we can determine $v_1^\\pi(s_1)$ for any policy by recursively evaluating equation (\\ref{MDP Policy Equations}):\n%\n\\begin{align}\\label{MDP Policy Equations}\nv^\\pi_t(s_t) = u_t(s_t,  a^\\pi_t(s_t)) + \\delta\\,\\E^\\pi_{s_t} \\left[\\left.v^\\pi_{t + 1}(s_{t + 1})  \\,\\right\\vert\\,\\mathcal{I}_t\\,\\right].\n\\end{align}\n%\nEquation (\\ref{MDP Policy Equations}) expresses the total value $v^\\pi_t(s_t)$ of adopting policy $\\pi$ going forward as the sum of its immediate utility and all expected discounted future utilities.\\\\\n\n\\noindent The principle of optimality \\citep{Bellman.1954} allows to construct $\\pi^*$ by solving the optimality equations (\\ref{MPD Optimality})  for all $s$ and $t$ recursively:\n%\n\\begin{align}\\label{MPD Optimality}\nv^{\\pi^*}_t(s_t)  & = \\max_{a_t \\in A}\\bigg\\{ u_t(s_t, a_t) + \\delta\\, \\E^{\\pi^*}_{s_t} \\left[\\left.v^{\\pi^*}_{t + 1}(s_{t + 1})\\,\\right\\vert\\,\\mathcal{I}_t\\,\\right] \\bigg\\}.\n\\end{align}\n\n\\noindent The optimal value function $v^{\\pi^*}_t$ is the sum of the expected discounted utilities in $t$ over the remaining time horizon assuming the optimal policy is implemented going forward. The optimal action is choosing the alternative with the highest total value:\n%\n\\begin{align*}\na^{\\pi^*}_t(s_t) = \\underset{a_t\\in A}{\\argmax} \\bigg\\{ u_t(s_t, a_t) + \\delta\\,\\E^{\\pi^*}_{s_t} \\left[\\left.v^{\\pi^*}_{t + 1}(s_{t + 1})\\right\\vert\\,\\mathcal{I}_t\\,\\right] \\bigg\\}.\\\\\n\\end{align*}\n\n\\noindent Algorithm \\ref{Backward induction procedure} allows to solve the MDP by a simple backward induction procedure. In the final period $T$, there is no future to take into account, and the optimal action is choosing the alternative with the highest immediate utilities in each state. With the decision rule for the final period at hand, the other optimal decisions can be determined recursively following equation (\\ref{MPD Optimality}) as the calculation of their expected future utilities is straightforward given the relevant transition probabilities.\n\n\\vspace{0.5cm}\\begin{algorithm}\n\\caption{\\strut Backward induction procedure}\\label{Backward induction procedure}\n\\begin{algorithmic}\\vspace{0.3cm}\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[\\left.v^{\\pi^*}_{t + 1}(s_{t + 1})\\right\\vert\\,\\mathcal{I}_t\\,\\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[\\left.v^{\\pi^*}_{t + 1}(s_{t + 1})\\right\\vert\\,\\mathcal{I}_t\\,\\right] \\bigg\\}$.\n    \\EndIf\n\\EndFor\n\\vspace{0.3cm}\\end{algorithmic}\n\\end{algorithm}\\FloatBarrier\n", "meta": {"hexsha": "61a006dd81f6f9904da294fce37e3218b6752278", "size": 4349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/s-setup-mathematics.tex", "max_stars_repo_name": "jkoenig97/ekw-pres", "max_stars_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_stars_repo_licenses": ["MIT"], "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/s-setup-mathematics.tex", "max_issues_repo_name": "jkoenig97/ekw-pres", "max_issues_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_issues_repo_licenses": ["MIT"], "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/s-setup-mathematics.tex", "max_forks_repo_name": "jkoenig97/ekw-pres", "max_forks_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_forks_repo_licenses": ["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.98, "max_line_length": 868, "alphanum_fraction": 0.6776270407, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6435588915246714}}
{"text": "\\subsection{Recall}\n\\label{chp:fundamentals:sec:metrics:subsec:Recall}\n\nThe next metric we introduce is called \\textit{recall} and is defined \\textit{\"as the probability of detecting an item given that it is relevant\"} \\parencite{Zhu:2004}.\nIts formula is given by \\cref{eq:recall}.\n\n\\begin{equation}\\label{eq:recall}\n    rec = \\frac{\\acp{TP}}{\\acp{TP}+\\acp{FN}}\n\\end{equation}\n\nThis metric expresses the performance of an algorithm in terms of how many of all relevant items it manages to select.\nHowever, irrelevant items which may have been incorrectly selected are not be penalized.\nTherefore, an algorithm which simply selects \\textit{all} available items always achieves a recall $rec=1$.\nFor the data shown in \\cref{fig:metrics:tp_vis}, the corresponding algorithm achieves a recall of $rec = \\frac{3}{3+9} = 0.25$.\n", "meta": {"hexsha": "99ba3e856cab85a45cf5aa4da095885f6d9911d2", "size": 823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/recall.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/recall.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/recall.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": 54.8666666667, "max_line_length": 168, "alphanum_fraction": 0.7642770352, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6435588758727464}}
{"text": "\\chapter{实验代码}\n\n\\section{Shamir 秘密共享}\n\\label{appendix:Shamir}\n\nshamir.py\n\n\\begin{lstlisting}[language = Python]\nfrom Crypto.Util.py3compat import is_native_int\nfrom Crypto.Util import number\nfrom Crypto.Util.number import long_to_bytes, bytes_to_long\nfrom Crypto.Random import get_random_bytes as rng\n\n\ndef _mult_gf2(f1, f2):\n    \"\"\"Multiply two polynomials in GF(2)\"\"\"\n\n    # Ensure f2 is the smallest\n    if f2 > f1:\n        f1, f2 = f2, f1\n    z = 0\n    while f2:\n        if f2 & 1:\n            z ^= f1\n        f1 <<= 1\n        f2 >>= 1\n    return z\n\n\ndef _div_gf2(a, b):\n    \"\"\"\n    Compute division of polynomials over GF(2).\n    Given a and b, it finds two polynomials q and r such that:\n\n    a = b*q + r with deg(r)<deg(b)\n    \"\"\"\n\n    if (a < b):\n        return 0, a\n\n    deg = number.size\n    q = 0\n    r = a\n    d = deg(b)\n    while deg(r) >= d:\n        s = 1 << (deg(r) - d)\n        q ^= s\n        r ^= _mult_gf2(b, s)\n    return (q, r)\n\n\nclass _Element(object):\n    \"\"\"Element of GF(2^128) field\"\"\"\n\n    # The irreducible polynomial defining this field is 1+x+x^2+x^7+x^128\n    irr_poly = 1 + 2 + 4 + 128 + 2 ** 128\n\n    def __init__(self, encoded_value):\n        \"\"\"Initialize the element to a certain value.\n\n        The value passed as parameter is internally encoded as\n        a 128-bit integer, where each bit represents a polynomial\n        coefficient. The LSB is the constant coefficient.\n        \"\"\"\n\n        if is_native_int(encoded_value):\n            self._value = encoded_value\n        # elif len(encoded_value) == 16:\n        else:\n            self._value = bytes_to_long(encoded_value)\n        # else:\n        #     raise ValueError(\"The encoded value must be an integer or a 16 byte string\")\n\n    def __eq__(self, other):\n        return self._value == other._value\n\n    def __int__(self):\n        \"\"\"Return the field element, encoded as a 128-bit integer.\"\"\"\n        return self._value\n\n    def encode(self):\n        \"\"\"Return the field element, encoded as a 16 byte string.\"\"\"\n        return long_to_bytes(self._value)\n\n    def __mul__(self, factor):\n\n        f1 = self._value\n        f2 = factor._value\n\n        # Make sure that f2 is the smallest, to speed up the loop\n        if f2 > f1:\n            f1, f2 = f2, f1\n\n        if self.irr_poly in (f1, f2):\n            return _Element(0)\n\n        mask1 = 2 ** 128\n        v, z = f1, 0\n        while f2:\n            # if f2 ^ 1: z ^= v\n            mask2 = int(bin(f2 & 1)[2:] * 128, base=2)\n            z = (mask2 & (z ^ v)) | ((mask1 - mask2 - 1) & z)\n            v <<= 1\n            # if v & mask1: v ^= self.irr_poly\n            mask3 = int(bin((v >> 128) & 1)[2:] * 128, base=2)\n            v = (mask3 & (v ^ self.irr_poly)) | ((mask1 - mask3 - 1) & v)\n            f2 >>= 1\n        return _Element(z)\n\n    def __add__(self, term):\n        return _Element(self._value ^ term._value)\n\n    def inverse(self):\n        \"\"\"Return the inverse of this element in GF(2^128).\"\"\"\n\n        # We use the Extended GCD algorithm\n        # http://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor\n\n        if self._value == 0:\n            raise ValueError(\"Inversion of zero\")\n\n        r0, r1 = self._value, self.irr_poly\n        s0, s1 = 1, 0\n        while r1 > 0:\n            q = _div_gf2(r0, r1)[0]\n            r0, r1 = r1, r0 ^ _mult_gf2(q, r1)\n            s0, s1 = s1, s0 ^ _mult_gf2(q, s1)\n        return _Element(s0)\n\n    def __pow__(self, exponent):\n        result = _Element(self._value)\n        for _ in range(exponent - 1):\n            result = result * self\n        return result\n\n\nclass Shamir(object):\n    \"\"\"Shamir's secret sharing scheme.\n\n    A secret is split into ``n`` shares, and it is sufficient to collect\n    ``k`` of them to reconstruct the secret.\n    \"\"\"\n\n    @staticmethod\n    def split(k, n, secret):\n        \"\"\"Split a secret into ``n`` shares.\n\n        The secret can be reconstructed later using just ``k`` shares\n        out of the original ``n``.\n        Each share must be kept confidential to the person it was\n        assigned to.\n\n        Each share is associated to an index (starting from 1).\n\n        Args:\n          k (integer):\n            The sufficient number of shares to reconstruct the secret (``k < n``).\n          n (integer):\n            The number of shares that this method will create.\n          secret (byte string):\n            A byte string of 16 bytes (e.g. the AES 128 key).\n\n        Return (tuples):\n            ``n`` tuples. A tuple is meant for each participant and it contains two items:\n\n            1. the unique index (an integer)\n            2. the share (a byte string, 16 bytes)\n        \"\"\"\n\n        #\n        # We create a polynomial with random coefficients in GF(2^128):\n        #\n        # p(x) = \\sum_{i=0}^{k-1} c_i * x^i\n        #\n        # c_0 is the encoded secret\n        #\n\n        coeffs = [_Element(rng(16)) for i in range(k - 1)]\n        coeffs.append(_Element(secret))\n\n        # Each share is y_i = p(x_i) where x_i is the public index\n        # associated to each of the n users.\n\n        def make_share(user, coeffs):\n            idx = _Element(user)\n            share = _Element(0)\n            for coeff in coeffs:\n                share = idx * share + coeff\n\n            return share.encode()\n\n        return [(i, make_share(i, coeffs)) for i in range(1, n + 1)]\n\n    @staticmethod\n    def combine(shares):\n        \"\"\"Recombine a secret, if enough shares are presented.\n\n        Args:\n          shares (tuples):\n            The *k* tuples, each containin the index (an integer) and\n            the share (a byte string, 16 bytes long) that were assigned to\n            a participant.\n          ssss (bool):\n            If ``True``, the shares were produced by the ``ssss`` utility.\n            Default: ``False``.\n\n        Return:\n            The original secret, as a byte string (16 bytes long).\n        \"\"\"\n\n        k = len(shares)\n\n        gf_shares = []\n        for x in shares:\n            idx = _Element(x[0])\n            value = _Element(x[1])\n            if any(y[0] == idx for y in gf_shares):\n                raise ValueError(\"Duplicate share\")\n            gf_shares.append((idx, value))\n\n        result = _Element(0)\n        for j in range(k):\n            x_j, y_j = gf_shares[j]\n\n            numerator = _Element(1)\n            denominator = _Element(1)\n\n            for m in range(k):\n                x_m = gf_shares[m][0]\n                if m != j:\n                    numerator *= x_m\n                    denominator *= x_j + x_m\n            result += y_j * numerator * denominator.inverse()\n        return result.encode()\n\\end{lstlisting}\n\n\\newpage\nwidget.py\n\\begin{lstlisting}[language = Python]\n# This Python file uses the following encoding: utf-8\nimport os\nfrom pathlib import Path\nimport sys\n\nfrom shamir import Shamir\nfrom binascii import hexlify, unhexlify\n\nfrom PySide2.QtWidgets import QApplication, QWidget\nfrom PySide2.QtCore import QFile\nfrom PySide2.QtUiTools import QUiLoader\n\n\nclass Widget(QWidget):\n    def __init__(self):\n        super(Widget, self).__init__()\n        self.ui = QUiLoader().load('form.ui')\n        self.ui.show()\n        self.ui.pushButton_create_share.clicked.connect(self.create_shares)\n        self.ui.pushButton_combine_share.clicked.connect(self.combine_shares)\n\n    def create_shares(self):\n        secret = self.ui.plainTextEdit_Secret.toPlainText().encode()\n        l = Shamir.split(3, 5, secret)\n        print(l)\n        self.ui.plainTextEdit_s1.setPlainText(str(hexlify(l[0][1]))[2:-1])\n        self.ui.plainTextEdit_s2.setPlainText(str(hexlify(l[1][1]))[2:-1])\n        self.ui.plainTextEdit_s3.setPlainText(str(hexlify(l[2][1]))[2:-1])\n        self.ui.plainTextEdit_s4.setPlainText(str(hexlify(l[3][1]))[2:-1])\n        self.ui.plainTextEdit_s5.setPlainText(str(hexlify(l[4][1]))[2:-1])\n        pass\n\n    def combine_shares(self):\n        self.ui.plainTextEdit_cs.setPlainText(\"NULL\")\n        shares = []\n        if len(self.ui.plainTextEdit_s1.toPlainText()) != 0:\n            shares.append((1, unhexlify(self.ui.plainTextEdit_s1.toPlainText().encode())))\n        if len(self.ui.plainTextEdit_s2.toPlainText()) != 0:\n            shares.append((2, unhexlify(self.ui.plainTextEdit_s2.toPlainText().encode())))\n        if len(self.ui.plainTextEdit_s3.toPlainText()) != 0:\n            shares.append((3, unhexlify(self.ui.plainTextEdit_s3.toPlainText().encode())))\n        if len(self.ui.plainTextEdit_s4.toPlainText()) != 0:\n            shares.append((4, unhexlify(self.ui.plainTextEdit_s4.toPlainText().encode())))\n        if len(self.ui.plainTextEdit_s5.toPlainText()) != 0:\n            shares.append((5, unhexlify(self.ui.plainTextEdit_s5.toPlainText().encode())))\n        print(shares)\n        secret = Shamir.combine(shares)\n        self.ui.plainTextEdit_cs.setPlainText(secret.decode())\n        pass\n\n\nif __name__ == \"__main__\":\n    app = QApplication([])\n    widget = Widget()\n    widget.show()\n    sys.exit(app.exec_())\n\\end{lstlisting}\n\n\\newpage\nform.ui\n\\begin{lstlisting}[language = html]\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ui version=\"4.0\">\n <class>Widget</class>\n <widget class=\"QWidget\" name=\"Widget\">\n  <property name=\"geometry\">\n   <rect>\n    <x>0</x>\n    <y>0</y>\n    <width>557</width>\n    <height>313</height>\n   </rect>\n  </property>\n  <property name=\"windowTitle\">\n   <string>Widget</string>\n  </property>\n  <layout class=\"QGridLayout\" name=\"gridLayout\">\n   <item row=\"0\" column=\"0\" colspan=\"3\">\n    <widget class=\"QLabel\" name=\"label\">\n     <property name=\"text\">\n      <string>3, 5 - Shamir Secret Sharing</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"1\" column=\"0\">\n    <widget class=\"QLabel\" name=\"label_2\">\n     <property name=\"text\">\n      <string>Secret</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"1\" column=\"1\">\n    <widget class=\"QLabel\" name=\"label_3\">\n     <property name=\"text\">\n      <string>Share 1</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"1\" column=\"2\">\n    <widget class=\"QLabel\" name=\"label_4\">\n     <property name=\"text\">\n      <string>Share 2</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"1\" column=\"3\">\n    <widget class=\"QLabel\" name=\"label_8\">\n     <property name=\"text\">\n      <string>Combined Share</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"2\" column=\"0\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_Secret\"/>\n   </item>\n   <item row=\"2\" column=\"1\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_s1\"/>\n   </item>\n   <item row=\"2\" column=\"2\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_s2\"/>\n   </item>\n   <item row=\"2\" column=\"3\" rowspan=\"3\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_cs\"/>\n   </item>\n   <item row=\"3\" column=\"0\">\n    <widget class=\"QLabel\" name=\"label_5\">\n     <property name=\"text\">\n      <string>Share 3</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"3\" column=\"1\">\n    <widget class=\"QLabel\" name=\"label_6\">\n     <property name=\"text\">\n      <string>Share 4</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"3\" column=\"2\">\n    <widget class=\"QLabel\" name=\"label_7\">\n     <property name=\"text\">\n      <string>Share 5</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"4\" column=\"0\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_s3\"/>\n   </item>\n   <item row=\"4\" column=\"1\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_s4\"/>\n   </item>\n   <item row=\"4\" column=\"2\">\n    <widget class=\"QPlainTextEdit\" name=\"plainTextEdit_s5\"/>\n   </item>\n   <item row=\"5\" column=\"0\">\n    <widget class=\"QPushButton\" name=\"pushButton_create_share\">\n     <property name=\"text\">\n      <string>Create Shares</string>\n     </property>\n    </widget>\n   </item>\n   <item row=\"5\" column=\"1\">\n    <widget class=\"QPushButton\" name=\"pushButton_combine_share\">\n     <property name=\"text\">\n      <string>Combine Shares</string>\n     </property>\n    </widget>\n   </item>\n  </layout>\n </widget>\n <resources/>\n <connections/>\n</ui>\n\n\\end{lstlisting}\n\n\\newpage\nimage.py\n\\begin{lstlisting}[language = Python]\nfrom statistics import mode\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom shamir import *\nfrom binascii import hexlify\n\nimg = plt.imread('cat.jpg')\n# plt.imshow(img)\n\ndef img_split(k, n, img: np.ndarray):\n    a, b, c = img.shape\n    l = []\n    for i in range(n):\n        l.append(np.zeros((a, b, c), np.dtype('int')))\n    for i in range(a):\n        for j in range(b):\n            for kk in range(c):\n                tmp_share = Shamir.split(k, n, int(img[i, j, kk]))\n                for idx in range(n):\n                    l[idx][i, j, kk] = bytes_to_long(tmp_share[idx][1])\n    return l\n\ntmp_l = img_split(3, 5, img)\ntmp_l.append(img)\n\nprint('imhere')\n\ndef show_images(images: list[np.ndarray]) -> None:\n    n: int = len(images)\n    f = plt.figure()\n    for i in range(n):\n        # Debug, plot figure\n        f.add_subplot(1, n, i + 1)\n        plt.imshow(images[i])\n\n    plt.show(block=True)\n\nshow_images(tmp_l)\n\nplt.show()\n\\end{lstlisting}\n\n\\newpage\n\\section{Many Time Pad}\n\\label{appendix:mtp}\nmain.py\n\\begin{lstlisting}[language = Python]\nfrom binascii import unhexlify\nfrom string import ascii_letters\nfrom math import sqrt\nimport utils\n\ndef main():\n    cipher_texts = []\n    with open('cipher_text.txt', encoding='utf-8') as file:\n        content = file.read().split('\\n')\n    for i in range(1, 21, 2):\n        cipher_texts.append(unhexlify(content[i]))\n\n    with open('dest_text.txt', encoding='utf-8') as file:\n        content = file.read()\n    dest_text = unhexlify(content)\n\n    letters = ascii_letters.encode('ascii')     ## ASCII letters\n\n    key = [0] * 1024\n\n    for ct_a in cipher_texts:\n        possible_pos = [0] * len(ct_a)\n        for ct_b in cipher_texts:\n            if ct_a == ct_b:\n                continue\n            guess_str = utils.byte_xor(ct_a, ct_b)\n            for idx, guess_char in enumerate(guess_str):\n                if guess_char not in letters and guess_char != 0:\n                    continue\n                possible_pos[idx] += 1\n\n        threshold = len(cipher_texts) - sqrt(len(cipher_texts))   ## Magic threshold\n\n        for i in range(len(ct_a)):\n            if possible_pos[i] > threshold:\n                key[i] = ct_a[i] ^ 0x20\n\n    print(utils.byte_xor(dest_text, key))\n\n\nif __name__ == '__main__':\n    main()\n\\end{lstlisting}\n\n\\newpage\nutils.py\n\\begin{lstlisting}[language = Python]\ndef byte_xor(a: bytes, b: bytes) -> bytes:\n    '''\n    :return: xor result of a and b\n    '''\n    if len(a) > len(b):\n        return bytes([x ^ y for x, y in zip(a[:len(b)], b)])\n    else:\n        return bytes([x ^ y for x, y in zip(a, b[:len(a)])])\n\\end{lstlisting}\n\n\n\\newpage\n\\section{AES}\n\\label{appendix:aes}\nmain.py\n\\begin{lstlisting}[language = Python]\nfrom binascii import unhexlify\nfrom utils import *\n\ndef main():\n    keys = []\n    cipher_texts = []\n    with open('infos.txt', encoding='utf-8') as file:\n        content = file.read().split('\\n')\n    for i in range(1, 16, 4):\n        keys.append(unhexlify(content[i]))\n        cipher_texts.append(unhexlify(content[i+2]))\n\n    print(CBC.decrypt(cipher_texts[0], keys[0]))\n    print(CBC.decrypt(cipher_texts[1], keys[1]))\n    print(CTR.decrypt(cipher_texts[2], keys[2]))\n    print(CTR.decrypt(cipher_texts[3], keys[3]))\n\nif __name__ == '__main__':\n    main()\n\\end{lstlisting}\n\nutils.py\n\\begin{lstlisting}[language = Python]\nimport binascii\nfrom Crypto.Cipher import AES\nfrom cxc_toolkit import integer\n\ndef byte_xor(a: bytes, b: bytes) -> bytes:\n    '''\n    :return: xor result of a and b\n    '''\n    if len(a) > len(b):\n        return bytes([x ^ y for x, y in zip(a[:len(b)], b)])\n    else:\n        return bytes([x ^ y for x, y in zip(a, b[:len(a)])])\n\ndef to_int(byte):\n    \"\"\"\n    Convert bytes to int\n\n    :type byte: bytes\n    :rtype: int\n    \"\"\"\n    s = 0\n    for i, number in enumerate(byte):\n        s = s * 256 + number\n    return s\n\n\ndef byte_add(byte, addtions):\n    \"\"\"\n    Add int to bytes\n\n    :type byte: bytes\n    :type addtions: int\n    :rtype: bytes\n    \"\"\"\n    return integer.to_bytes(to_int(byte) + addtions, bytes_size=len(byte))\n\ndef msg_block_generator(msg, padding=False):\n        while len(msg) >= 16:\n            yield msg[:16]\n            msg = msg[16:]\n        if len(msg) > 0:\n            if not padding:\n                yield msg\n                return\n\n            reminder = 16 - len(msg)\n            msg = msg + bytes([reminder]) * reminder\n            yield msg\n        else:\n            yield b'16' * 16\n\n\ndef cipher_block_generator(cipher):\n    while len(cipher):\n        yield cipher[:16]\n        cipher = cipher[16:]\n\nclass CBC:\n\n    def encrypt(msg, key, iv):\n        cipher = AES.new(key, AES.MODE_ECB)\n        cipher_block = iv\n        ciphertext = iv\n        for msg_block in msg_block_generator(msg, padding=True):\n            cipher_block = cipher.encrypt(byte_xor(cipher_block, msg_block))\n            ciphertext += cipher_block\n        return ciphertext\n\n\n    def decrypt(cipher_text, key):\n        cipher = AES.new(key, AES.MODE_ECB)\n        iv, cipher_text = cipher_text[:16], cipher_text[16:]\n        msg = b''\n        for cipher_block in cipher_block_generator(cipher_text):\n            msg_block = byte_xor(cipher.decrypt(cipher_block), iv)\n            iv = cipher_block\n            msg += msg_block\n        if msg[-16:] == b'\\x16' * 16:\n            return msg[:-16]\n        pad_bytes = msg[-1]\n        reminder = len(msg) - pad_bytes\n        if msg[reminder:] == bytes([pad_bytes]) * pad_bytes:\n            return msg[:reminder]\n        else:\n            print('Cipher text is invalid')\n\n\nclass CTR:\n\n    def encrypt(msg, key, iv):\n        cipher = AES.new(key, AES.MODE_ECB)\n        ciphertext = b''\n        for i, msg_block in enumerate(msg_block_generator(msg, padding=False)):\n            cipher_block = cipher.encrypt(byte_add(iv, i))\n            cipher_block = byte_xor(msg_block, cipher_block)\n            ciphertext += cipher_block\n        return ciphertext\n\n    def decrypt(cipher_text, key):\n        iv, cipher_text = cipher_text[:16], cipher_text[16:]\n        cipher = AES.new(key, AES.MODE_ECB)\n        msg = b''\n        for i, cipher_block in enumerate(cipher_block_generator(cipher_text)):\n            iv_encrypted = cipher.encrypt(byte_add(iv, i))\n            msg_block = byte_xor(cipher_block, iv_encrypted)\n            msg += msg_block\n        return msg\n\n\\end{lstlisting}", "meta": {"hexsha": "9398dc18bb82655e6d837020c12c9f6d03c8705c", "size": 18428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Cryptography/Reports/data/appendix.tex", "max_stars_repo_name": "LuminolT/Cryptographic-Learning", "max_stars_repo_head_hexsha": "6304d3d8cc8c73f85aa169ec06c506bba5110abc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Cryptography/Reports/data/appendix.tex", "max_issues_repo_name": "LuminolT/Cryptographic-Learning", "max_issues_repo_head_hexsha": "6304d3d8cc8c73f85aa169ec06c506bba5110abc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Cryptography/Reports/data/appendix.tex", "max_forks_repo_name": "LuminolT/Cryptographic-Learning", "max_forks_repo_head_hexsha": "6304d3d8cc8c73f85aa169ec06c506bba5110abc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-07T13:56:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T13:56:55.000Z", "avg_line_length": 27.9212121212, "max_line_length": 90, "alphanum_fraction": 0.5833514217, "num_tokens": 4981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.6859494614282922, "lm_q1q2_score": 0.6435056635324701}}
{"text": "\\chapter{CT Block Diagrams}\n\n\\section{The Four Basic Motifs}\n\nUnderstanding complex systems, with many interconnections, is aided by graphical representations, generally called block diagrams \\footnote{There is a closely related graphical approach called \\emph{signal flow graphs} that you may learn about in upper-level courses. They are equivalent to block diagrams, but are more amenable to computer representation and manipulation.}. They are a hybrid graphical-analytical approach.\n\nThere are just four basic motifs needed to build any block diagram. Let $\\mathcal{S}_i$ denote a (sub) system. Then the four motifs are:\n\n\\begin{itemize}\n\\item A single block.\\\\[1em] \n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$\\mathcal{S}_1$};\n    \\node [output, right of=system] (output) {};\n\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [draw,->] (input) -- node {$x(t)$} (system);\n    \\draw [->] (system) -- node {$y(t)$} (output);\n\\end{tikzpicture}\n\n\\item A {\\it series} connection of two blocks\\\\[1em]\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system1) {$\\mathcal{S}_1$};\n    \\node [block, right of=system1,node distance=4cm] (system2) {$\\mathcal{S}_2$};\n    \\node [output, right of=system2] (output) {};\n\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [draw,->] (input) -- node {$x(t)$} (system1);\n    \\draw [->] (system1) -- (system2);\n    \\draw [->] (system2) -- node {$y(t)$} (output);\n\\end{tikzpicture}\n\\item A {\\it parallel} connection of two blocks\\\\[1em]\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks and inputs\n    \\node[shape=coordinate] at (1,1) (input1) {};\n    \\node[block] at (3,1) (block1) {$\\mathcal{S}_1$};\n    \\node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};\n    \\draw[->] (input1) -- (block1);\n    \\draw (block1) -- (output1);\n\n    \\node[shape=coordinate] at (1,-1) (input2) {};\n    \\node[block] at (3,-1) (block2) {$\\mathcal{S}_2$};\n    \\node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};\n    \\draw[->] (input2) -- (block2);\n    \\draw (block2) -- (output2);\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [input, name=conn] at (1,0) {};\n    \\draw (conn) -- (input1);\n    \\draw (conn) -- (input2);\n    \\node [sum, right of=input,node distance=5cm] (sum) {$\\Sigma$};\n    \\draw [->] (output1) -| (sum);\n    \\draw [->] (output2) -| (sum);\n\n    \\draw [draw] (input) -- node {$x(t)$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node {$y(t)$} (output);\n\\end{tikzpicture}\n\n\\item A {\\it feedback} connection\\\\[1em]\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node[block] at (4,0) (block1) {$\\mathcal{S}_1$};\n\n    \\node[block] at (4,-2) (block2) {$\\mathcal{S}_2$};\n    \\node[shape=coordinate] at (6,-2) (input2) {};\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [shape=coordinate, name=conn] at (6,0) {};\n    \\draw (block1) -- (conn);\n    \\draw (conn) -- (input2);\n    \\draw [->] (input2) -- (block2);\n\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\draw [->] (block2) -| node[pos=0.95] {$-$} (sum);\n\n    \\draw [draw,->] (input) -- node {$x(t)$} (sum);\n    \\draw [->] (sum) -- (block1);\n    \\node [output, right of=conn] (output) {};\n    \\draw [->] (conn) -- node {$y(t)$} (output);\n\\end{tikzpicture}\n\\end{itemize}\n\nNote the feedback is negative (the minus sign on the feedback summation input). These can be use in various combinations, as we shall see shortly.\n\n\\section{Connections to Convolution}\n\nEach subsystem, $\\mathcal{S}_i$, can be represented by a basic time-domain operation (e.g. derivatives, integrals, addition, and scaling) or more generally by it's impulse response $h_i(t)$.\n\\\nFor example a block representing an system acting as integrator is typically drawn as\n\n\\begin{center}\n  \\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$\\int$};\n    \\node [output, right of=system] (output) {};\n\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [draw,->] (input) -- node {$x(t)$} (system);\n    \\draw [->] (system) -- node[pos=3] {$y(t) = \\int\\limits_{-\\infty}^t x(\\tau) \\; d\\tau$} (output);\n\\end{tikzpicture}\n\\end{center}\nThis is equivalent to an impulse response $h(t) = u(t)$ so that it might also be drawn as\n\\begin{center}\n  \\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$h(t) = u(t)$};\n    \\node [output, right of=system] (output) {};\n\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [draw,->] (input) -- node {$x(t)$} (system);\n    \\draw [->] (system) -- node[pos=3] {$y(t) = x(t) * u(t) = \\int\\limits_{-\\infty}^t x(\\tau) \\; d\\tau$} (output);\n\\end{tikzpicture}\n\\end{center}\n\nWe can use the concept of convolution to connect block diagrams to the properties of convolution\n\n\\begin{itemize}\n\\item A single block is equivalent to convolution with the impulse response for that subsystem\\\\[1em] \n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system) {$h_1(t)$};\n    \\node [output, right of=system] (output) {};\n\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [draw,->] (input) -- node {$x(t)$} (system);\n    \\draw [->] (system) -- node[pos=2] {$y(t) = h_1(t)*x(t)$} (output);\n\\end{tikzpicture}\n\n\\item Using the associative property, a series connection of two blocks becomes\n  \\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node [input, name=input] {};\n    \\node [block, right of=input] (system1) {$h_1(t)$};\n    \\node [block, right of=system1,node distance=4cm] (system2) {$h_2(t)$};\n    \\node [output, right of=system2] (output) {};\n\n    \\draw [draw,->] (input) -- node {$x(t)$} (system1);\n    \\draw [->] (system1) -- (system2);\n    \\draw [->] (system2) -- node[pos=3] {$y(t) = \\left[h_1(t)*h_2(t)\\right]*x(t)$} (output);\n\\end{tikzpicture}\n  \\end{center}\n  which can be reduced to a single convolution $y(t) = h_3(t)*x(t)$ where $h_3(t) = h_1(t)*h_2(t)$.\n\\item Using the distributive property, a parallel connection of two blocks becomes\n  \\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n\n    \\node[shape=coordinate] at (1,1) (input1) {};\n    \\node[block] at (3,1) (block1) {$h_1(t)$};\n    \\node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};\n    \\draw[->] (input1) -- (block1);\n    \\draw (block1) -- (output1);\n\n    \\node[shape=coordinate] at (1,-1) (input2) {};\n    \\node[block] at (3,-1) (block2) {$h_2(t)$};\n    \\node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};\n    \\draw[->] (input2) -- (block2);\n    \\draw (block2) -- (output2);\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [input, name=conn] at (1,0) {};\n    \\draw (conn) -- (input1);\n    \\draw (conn) -- (input2);\n    \\node [sum, right of=input,node distance=5cm] (sum) {$\\Sigma$};\n    \\draw [->] (output1) -| (sum);\n    \\draw [->] (output2) -| (sum);\n\n    \\draw [draw] (input) -- node {$x(t)$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node[pos=3] {$y(t)= \\left[h_1(t)*x(t)\\right] +  \\left[h_2(t)*x(t)\\right] =  \\left[h_1(t)+h_2(t)\\right]*x(t)$} (output);\n\\end{tikzpicture}  \n  \\end{center}\n  which is equivalent to a single convolution $y(t) = h_3(t)*x(t)$ where $h_3(t) = h_1(t) + h_2(t)$.\n\\item In the feedback connection let $w(t)$ be the output of the summation\n  \\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    % We start by placing the blocks\n    \\node[block] at (4.5,0) (block1) {$h_1(t)$};\n\n    \\node[block] at (4,-2) (block2) {$h_2(t)$};\n    \\node[shape=coordinate] at (6,-2) (input2) {};\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [shape=coordinate, name=conn] at (6,0) {};\n    \\draw (block1) -- (conn);\n    \\draw (conn) -- (input2);\n    \\draw [->] (input2) -- (block2);\n\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\draw [->] (block2) -| node[pos=0.95] {$-$} (sum);\n\n    \\draw [draw,->] (input) -- node {$x(t)$} (sum);\n    \\draw [->] (sum) -- (block1);\n    \\node [output, right of=conn] (output) {};\n    \\draw [->] (conn) -- node {$y(t)$} (output);\n    \\draw node at (3,0.3) {$w(t)$};\n\\end{tikzpicture}\n  \\end{center}\n  Then $y(t) = h_1(t)*w(t)$ and $w(t) = x(t) - h_2(t)*y(t)$. Substituting the later into the former gives $y(t) = h_1*(x-h_2(t)*y(t))$. Using the distributive property we get $y(t) = h_1(t)*x(t) - h_1(t)*h_2(t)*y(t)$. Isolating the input on the right-hand side and using $y(t) = \\delta(t)*y(t)$ we get\n  \\[\n  y(t) + h_1(t)*h_2(t)*y(t) = \\left[\\delta(t) + h_1(t)*h_2(t)\\right]*y(t) = h_1(t)*x(t) \n  \\]\n  We can solve this for $y(t)$ using the concept of inverse systems. Let $h_3(t)* \\left[\\delta(t) + h_1(t)*h_2(t)\\right]= \\delta(t)$, i.e. $h_3$ is the inverse system of $\\delta(t) + h_1(t)*h_2(t)$. Then\n  \\[\n  y(t) = h_3(t)*h_1(t)*x(t)\n  \\]\n\\end{itemize}\n\nRecall, when the system is instantaneous (memoryless) the impulse response is $a\\delta(t)$ for some constant $a$. This is the same as scaling the signal by $a$. We typically drop the block in such cases and draw the input-output operation as\n\n\\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n  \\node [input, name=input] at (0,0) {};\n  \\node [output, name=system] at (2,0) {};\n  \\node [output, name=output] at (4,0) {};\n  \\draw [draw,->] (input) -- node {$x(t)$} (system);\n  \\draw [draw,->] (system) -- node[pos=1] {$y(t) = ax(t)$} (output);\n  \\draw [->] (input) -- node {$a$} (output);\n\\end{tikzpicture}\n\\end{center}\n\nThese properties allow us to perform transformations, either breaking up a system into subsystems, or reducing a system to a single block.\n\n\\begin{example}\n  Consider a second-order system system with impulse response\n  \\[\n  h(t) = \\left(e^{-3t} - e^{-t}\\right)\\, u(t)\n  \\]\n  We can express this as a block diagram consisting of two parallel blocks\n  \\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n\n    \\node[shape=coordinate] at (1,1) (input1) {};\n    \\node[block] at (3,1) (block1) {$h_1(t) = e^{-3t}u(t)$};\n    \\node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};\n    \\draw[->] (input1) -- (block1);\n    \\draw (block1) -- (output1);\n\n    \\node[shape=coordinate] at (1,-1) (input2) {};\n    \\node[block] at (3,-1) (block2) {$h_2(t) = -e^{-t}u(t)$};\n    \\node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};\n    \\draw[->] (input2) -- (block2);\n    \\draw (block2) -- (output2);\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [input, name=conn] at (1,0) {};\n    \\draw (conn) -- (input1);\n    \\draw (conn) -- (input2);\n    \\node [sum, right of=input,node distance=5cm] (sum) {$\\Sigma$};\n    \\draw [->] (output1) -| (sum);\n    \\draw [->] (output2) -| (sum);\n\n    \\draw [draw] (input) -- node {$x(t)$} (conn);\n    \\node [output, right of=sum] (output) {};\n    \\draw [->] (sum) -- node[pos=1] {$y(t)$} (output);\n\\end{tikzpicture}\n  \\end{center}\n\n\\end{example}\n\n\\begin{example}\n  Consider a system with block diagram\n\n  \\begin{center}\n\\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n\n    \\node[shape=coordinate] at (1,1) (input1) {};\n    \\node[block] at (3,1) (block1) {$h_1(t) = e^{-2t}u(t)$};\n    \\node[shape=coordinate] at ($(block1.east)+(0.5,0)$) (output1) {};\n    \\draw[->] (input1) -- (block1);\n    \\draw (block1) -- (output1);\n\n    \\node[shape=coordinate] at (1,-1) (input2) {};\n    \\node[block] at (3,-1) (block2) {$h_2(t) = -e^{-4t}u(t)$};\n    \\node[shape=coordinate] at ($(block2.east)+(0.5,0)$) (output2) {};\n    \\draw[->] (input2) -- (block2);\n    \\draw (block2) -- (output2);\n\n    \\node[block] at (8,0) (block3) {$h_3(t) = e^{-6t}u(t)$};\n\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [input, name=conn] at (1,0) {};\n    \\draw (conn) -- (input1);\n    \\draw (conn) -- (input2);\n    \\node [sum, right of=input,node distance=5cm] (sum) {$\\Sigma$};\n    \\draw [->] (output1) -| (sum);\n    \\draw [->] (output2) -| (sum);\n\n    \\draw [draw] (input) -- node {$x(t)$} (conn);\n    \\node [output, right of=block3] (output) {};\n    \\draw [->] (sum) -- (block3);\n    \\draw [->] (block3) -- node[pos=1] {$y(t)$} (output);\n\\end{tikzpicture}\n  \\end{center}\n  We can determine the overall impulse response of this system using the distributive and associative properties\n\\begin{align*}\n  h(t) &= \\left[ h_1(t) + h_2(t)\\right]*h_3(t)\\\\\n  &= h_1(t)*h_3(t) + h_2(t)*h_3(t)\\\\\n  &= \\left[ e^{-2t}u(t)\\right]*\\left[ e^{-6t}u(t)\\right] + \\left[-e^{-4t}u(t) \\right]*\\left[ e^{-6t}u(t)\\right]\n\\end{align*}\nUsing the convolution table from Lecture 8 we get the overall impulse response\n\\[\nh(t) = \\frac{e^{-2 t}-e^{-6 t}}{4}u(t) - \\frac{e^{-4 t}-e^{-6 t}}{2}u(t) = \\frac{1}{4}e^{-2t}u(t) -\\frac{1}{2}e^{-4t}u(t) + \\frac{1}{4}e^{-6t}u(t)\n\\]\n\\end{example}\n\n\n\\section{Connections to LCCDE}\n\nThe other system representation we have seen are linear, constant-coefficient differential equations. These can be expressed as combinations of derivative and/or integration blocks.\n\n\\subsection*{First-Order System}\n\nTo illustrate this consider the first-order LCCDE\n\\[\n\\frac{dy}{dt}(t) + ay(t) = x(t)\n\\]\nWe can solve this for $y(t)$\n\\[\ny(t) = -\\frac{1}{a} \\frac{dy}{dt}(t) + \\frac{1}{a}x(t)\n\\]\nand can express this as a feedback motif\n\\begin{center}\n  \\begin{tikzpicture}[auto]\n    \\node[block] at (4,-2) (block2) {$\\frac{1}{a}\\frac{d}{dt}$};\n    \\node[shape=coordinate] at (6,-2) (input2) {};\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [shape=coordinate, name=conn] at (6,0) {};\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \n    \\draw (sum) -- (conn);\n    \\draw (conn) -- (input2);\n    \\draw [->] (input2) -- (block2);\n    \\draw [->] (block2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [draw,->] (input) -- node {$\\frac{1}{a}$} (sum);\n    \\node [left of=input, node distance=2em] {$x(t)$};\n    \\node [output, right of=conn] (output) {};\n    \\draw [->] (conn) -- (output);\n    \\node [right of=output, node distance=2em] {$y(t)$}; \n\\end{tikzpicture}\n\\end{center}\n\nAlternatively we could integrate the differential equation\n\\begin{align*}\n  \\frac{dy}{dt}(t) + ay(t) &= x(t)\\\\\n  \\int\\limits_{-\\infty}^t \\frac{dy}{dt}(\\tau)\\; d\\tau + a\\int\\limits_{-\\infty}^t y(\\tau)\\; d\\tau &= \\int\\limits_{-\\infty}^t x(\\tau)\\; d\\tau\\\\\n  y(\\tau) \\Big|_{-\\infty}^t  + a\\int\\limits_{-\\infty}^t y(\\tau)\\; d\\tau &= \\int\\limits_{-\\infty}^t x(\\tau)\\; d\\tau\\\\\n\\end{align*}\nUnder the assumption $y(-\\infty) = 0$ we can solve this for $y(t)$ to get\n\\[\n  y(t) = -a\\int\\limits_{-\\infty}^t y(\\tau)\\; d\\tau + \\int\\limits_{-\\infty}^t x(\\tau)\\; d\\tau\n\\]\nwhich can be expressed as the block diagram\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node[block] at (2,0) (block1) {$\\int$};\n    \\node[block] at (6,-1) (block2) {$\\int$};\n    \\node[shape=coordinate] at (6,-2) (input2) {};\n\n    \\node [shape=coordinate, name=conn] at (6,0) {};\n    \\node [shape=coordinate, name=conn2] at (4,-2) {};\n    \\node [shape=coordinate, name=conn3] at (6,-2) {};\n    \\node [sum, right of=block1,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [output, right of=conn] (output) {};\n    \n    \\draw (sum) -- (conn);\n    \\draw (conn) -- (block2);\n    \\draw (block2) -- (conn3);\n    \\draw (conn3) -- node {$a$} (conn2);\n    \\draw [->] (conn2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [draw,->] (input) -- node {$x(t)$} (block1);\n    \\draw [->] (block1) -- (sum);\n    \\draw [->] (conn) -- node {$y(t)$} (output);\n  \\end{tikzpicture}\n\\end{center}\n\nWe can simplify this block diagram, by noting\n\\begin{align*}\n  y(t) &= -a\\int\\limits_{-\\infty}^t y(\\tau)\\; d\\tau + \\int\\limits_{-\\infty}^t\n  x(\\tau)\\; d\\tau\\\\\n  &= \\int\\limits_{-\\infty}^t \\left(-a y(\\tau) +  x(\\tau)\\right)\\; d\\tau\\\\\n\\end{align*}\nwhich requires only a single integrator\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node[block] at (4,-1) (block2) {$\\int$};\n\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node [shape=coordinate, name=conn2] at (2,-2) {};\n    \\node [shape=coordinate, name=conn3] at (4,-2) {};\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [output, right of=conn3] (output) {};\n    \n    \\draw (sum) -- (conn);\n    \\draw (conn) -- (block2);\n    \\draw (block2) -- (conn3);\n    \\draw (conn3) -- node {$a$} (conn2);\n    \\draw [->] (conn2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [draw,->] (input) -- node {$x(t)$} (sum);\n    \\draw [->] (conn3) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}\n\\end{center}\n\nThe choice of using derivative or integrator blocks is not arbitrary in practice. Derivatives are sensitive to noise at high frequencies (for reasons we will see later in the semester) and so integrators perform much better when implemented in hardware. \n\n\\subsection*{Second-Order System}\n\nNow consider the second-order system\n\\[\n\\frac{d^2y}{dt^2}(t) + a\\frac{dy}{dt}(t)  + by(t)= x(t)\n\\]\nUsing a similar process to the first-order system, we can express this as (dropping the limits of integration for clarity):\n\\[\ny(t) = -a \\int y(\\tau)\\; d\\tau + \\int\\int \\left( -by(\\tau) + x(\\tau) \\right) \\; d\\tau^2 \n\\]\nwhich has the block diagram\n\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [block, right of=input,node distance=2cm] (block1) {$\\int$};\n    \\node [block, right of=block1,node distance=2cm] (block2) {$\\int$};\n    \\node [sum, right of=block2,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [sum, below of=sum,node distance=2cm] (sum2) {$\\Sigma$};\n    \\node[block] at (8,-1) (block3) {$\\int$};\n    \\node[block] at (8,-3) (block4) {$\\int$};\n\n    \\node [shape=coordinate, name=conn1] at (8,0) {};\n    \\node [shape=coordinate, name=conn2] at (8,-2) {};\n    \\node [shape=coordinate, name=conn3] at (8,-4) {};\n    \\node [shape=coordinate, name=conn4] at (6,-4) {};\n    \\node [output, right of=conn1] (output) {};\n\n    \\draw [->] (input) -- node {$x(t)$} (block1);\n    \\draw [->] (block1) -- (block2);\n    \\draw [->] (block2) -- (sum);\n    \\draw (sum) -- (conn1);\n    \\draw [->] (conn1) -- (block3);\n    \\draw (block3) -- (conn2);\n    \\draw [->] (conn2) -- (block4);\n    \\draw [->] (conn2) -- node {$a$} (sum2);\n    \\draw (block4) -- (conn3);\n    \\draw (conn3) -- node {$b$} (conn4);\n    \\draw [->] (conn3) -| (sum2);\n    \\draw [->] (sum2) -- node[pos=0.95] {$-$} (sum);\n    \\draw [->] (conn1) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}\n\\end{center}\nThis is equivalent to two systems in series\n\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input1] at (0,0) {};\n    \\node [block, right of=input1,node distance=2cm] (block1) {$\\int$};\n    \\node [block, right of=block1,node distance=2cm] (block2) {$\\int$};\n    \\node [output, right of=block2] (output) {};\n\n    \\draw [->] (input1) -- node {$x(t)$} (block1);\n    \\draw [->] (block1) -- (block2);\n    \\draw [->] (block2) -- node[pos=1] {$z(t)$} (output);\n\n    \\node [input, name=input2] at (6,0) {};\n    \\node [sum, right of=input2,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [sum, below of=sum,node distance=2cm] (sum2) {$\\Sigma$};\n    \\node[block] at (10,-1) (block3) {$\\int$};\n    \\node[block] at (10,-3) (block4) {$\\int$};\n\n    \\node [shape=coordinate, name=conn1] at (10,0) {};\n    \\node [shape=coordinate, name=conn2] at (10,-2) {};\n    \\node [shape=coordinate, name=conn3] at (10,-4) {};\n    \\node [shape=coordinate, name=conn4] at (8,-4) {};\n    \\node [output, right of=conn1] (output) {};\n\n    \\draw [->] (input2) -- node {$z(t)$} (sum);\n    \\draw (sum) -- (conn1);\n    \\draw [->] (conn1) -- (block3);\n    \\draw (block3) -- (conn2);\n    \\draw [->] (conn2) -- (block4);\n    \\draw [->] (conn2) -- node {$a$} (sum2);\n    \\draw (block4) -- (conn3);\n    \\draw (conn3) -- node {$b$} (conn4);\n    \\draw [->] (conn3) -| (sum2);\n    \\draw [->] (sum2) -- node[pos=0.95] {$-$} (sum);\n    \\draw [->] (conn1) -- node[pos=1] {$y(t)$} (output);\n    \\end{tikzpicture}\n\\end{center}\n\nRecall that, from the commutative property of convolution, the order of systems in series can be swapped\\\\\n\n\\begin{center}\n\\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [sum, below of=sum,node distance=2cm] (sum2) {$\\Sigma$};\n    \\node[block] at (4,-1) (block3) {$\\int$};\n    \\node[block] at (4,-3) (block4) {$\\int$};\n\n    \\node [shape=coordinate, name=conn1] at (4,0) {};\n    \\node [shape=coordinate, name=conn2] at (4,-2) {};\n    \\node [shape=coordinate, name=conn3] at (4,-4) {};\n    \\node [shape=coordinate, name=conn4] at (2,-4) {};\n    \\node [output, right of=conn1] (output) {};\n\n    \\draw [->] (input) -- node {$x(t)$} (sum);\n    \\draw (sum) -- (conn1);\n    \\draw [->] (conn1) -- (block3);\n    \\draw (block3) -- (conn2);\n    \\draw [->] (conn2) -- (block4);\n    \\draw [->] (conn2) -- node {$a$} (sum2);\n    \\draw (block4) -- (conn3);\n    \\draw (conn3) -- node {$b$} (conn4);\n    \\draw [->] (conn3) -| (sum2);\n    \\draw [->] (sum2) -- node[pos=0.95] {$-$} (sum);\n    \\draw [->] (conn1) -- node[pos=1] {$z(t)$} (output);\n\n    \\node [input, name=input] at (6,0) {};\n    \\node [block, right of=input,node distance=2cm] (block1) {$\\int$};\n    \\node [block, right of=block1,node distance=2cm] (block2) {$\\int$};\n    \\node [output, right of=block2] (output) {};\n\n    \\draw [->] (input) -- node {$z(t)$} (block1);\n    \\draw [->] (block1) -- (block2);\n    \\draw [->] (block2) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}\n\\end{center}\nWe then note that the signal $z$ and the output of the integrator blocks are the same in both systems so that they can be combined into a single block diagram as follows, reducing the number of integrators by two\n\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [sum, below of=sum,node distance=2cm] (sum2) {$\\Sigma$};\n    \\node[block] at (4,-1) (block3) {$\\int$};\n    \\node[block] at (4,-3) (block4) {$\\int$};\n\n    \\node [shape=coordinate, name=conn1] at (4,0) {};\n    \\node [shape=coordinate, name=conn2] at (4,-2) {};\n    \\node [shape=coordinate, name=conn3] at (4,-4) {};\n    \\node [shape=coordinate, name=conn4] at (2,-4) {};\n    \\node [output, right of=conn3] (output) {};\n\n    \\draw [->] (input) -- node {$x(t)$} (sum);\n    \\draw (sum) -- (conn1);\n    \\draw [->] (conn1) -- (block3);\n    \\draw (block3) -- (conn2);\n    \\draw [->] (conn2) -- (block4);\n    \\draw [->] (conn2) -- node {$a$} (sum2);\n    \\draw (block4) -- (conn3);\n    \\draw (conn3) -- node {$b$} (conn4);\n    \\draw [->] (conn3) -| (sum2);\n    \\draw [->] (sum2) -- node[pos=0.95] {$-$} (sum);\n    \\draw [->] (conn3) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}\n\\end{center}\n\n\\section{Implementing a System in Hardware}\n\nOne of the most powerful uses of block diagrams is the implementation of a CT system in hardware. As we shall see later in the semester, designing CT systems for a particular purpose leads to a mathematical description that is equivalent to either an impulse response, or a LCCDE. We have seen how these can be represented as block diagrams. Once we have reduced a system to blocks consisting of simple operations, we can then convert the block diagram to a circuit.\n\n\\begin{tabular}{cc}\n\n  Block & Typical Circuit\\\\\n  \\hline\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [shape=coordinate, name=signal1] at (1,0) {};\n    \\node [shape=coordinate, name=signal2] at (2,0) {};\n    \\node [output, right of=signal2] (output) {};\n\n    \\draw (input) -- node {$x(t)$} (signal1);\n    \\draw (signal1) -- node {$a < 0$} (signal2);\n    \\draw [->] (signal2) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}  \n\n  &\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (5,3.5) node[op amp] (opamp1) {}\n    (0,4) to[R,l=$R_1$,o-] (4,4)\n    (4,4) to[short] (opamp1.-)\n    (opamp1.+) to[short] (3.8,2) \n    (0,2) to[short,o-o] (8,2)\n    (opamp1.out) to[short] (6.2,5)\n    (3.5,5) to[R,l=$R_2$] (6.2,5)\n    (3.5,4) to[short] (3.5,5)\n    (opamp1.out) to[short,-o] (8,3.5)\n    (0,4) to[open, v=$x(t)$] (0,2)\n    (8,3.5) to[open, v=$y(t)$] (8,2);\n  \\end{circuitikz}\n  \\\\[2em]\n  \n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node [shape=coordinate, name=signal1] at (1,0) {};\n    \\node [shape=coordinate, name=signal2] at (2,0) {};\n    \\node [output, right of=signal2] (output) {};\n\n    \\draw (input) -- node {$x(t)$} (signal1);\n    \\draw (signal1) -- node {$a > 1$} (signal2);\n    \\draw [->] (signal2) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}  \n  &\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (7,3.5) node[op amp] (opamp1) {}\n    (4,0) to[short,o-o] (12,0)\n    (4,4) to[short,o-] (opamp1.-)\n    (opamp1.+) to[short] (5.8,1.75)\n    (5.8,1.75) to[short] (8.2,1.75)\n    (opamp1.out) to[R, l=$R_1$] (8.2,1.75)\n    (8.2,1.75) to[R, l=$R_2$] (8.2,0)\n    (opamp1.out) to[short, -o] (12,3.5)\n    (4,4) to[open, v=$x(t)$] (4,0)\n    (12,3.5) to[open, v=$y(t)$] (12,0);\n  \\end{circuitikz}\n  \\\\[2em]\n\n      \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n        minimum height=2em, minimum width=2em]\n      \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n      \\tikzstyle{input} = [coordinate]\n      \\tikzstyle{output} = [coordinate]\n      \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n      \n      \\begin{tikzpicture}[auto]\n        \\node [input, name=input1] at (0,0) {};\n        \\node [input, name=input2] at (0,-1) {};\n        \\node [sum] at (2,0) (sum1) {$\\Sigma$};\n        \\node [output, right of=sum1] (output) {};\n        \n        \\draw [->] (input1) -- node[pos=0] {$x_1(t)$} (sum1);\n        \\draw [->] (input2) -| node[pos=0] {$x_2(t)$} (sum1);\n        \\draw [->] (sum1) -- node[pos=1] {$y(t)$} (output);\n      \\end{tikzpicture}  \n    &\n      \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (9,3.5) node[op amp] (opamp1) {}\n    (2,0) to[short,o-o] (12,0)\n    (2,4) to[short,o-] (5,4)\n    (4.5,2) to[short,o-] (5,2)\n    (5,4) to[R, l=$R$] (7,4)\n    (5,2) to[R, l=$R$] (7,2)\n    (7,2) to[short] (7,4)\n    (7,4) to[short] (opamp1.-)\n    (opamp1.+) to[short] (7.8,1.75)\n    (7.8,1.75) to[short] (10.2,1.75)\n    (opamp1.out) to[short] (10.2,1.75)\n    (opamp1.out) to[short, -o] (12,3.5)\n    (2,4) to[open, v=$x_1(t)$] (2,0)\n    (4.5,2) to[open, v=$x_2(t)$] (4.5,0)\n    (12,3.5) to[open, v=$y(t)$] (12,0);\n  \\end{circuitikz}\n  \\\\[2em]\n      \n\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};\n    \\node[block] at (2,0) (block1) {$-\\int$};\n    \\node [output, right of=block1] (output) {};\n\n    \\draw [->] (input) -- node {$x(t)$} (block1);\n    \\draw [->] (block1) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}  \n\n  &\n    \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (5,3.5) node[op amp] (opamp1) {}\n    (0,4) to[R,l=$R$,o-] (4,4)\n    (4,4) to[short] (opamp1.-)\n    (opamp1.+) to[short] (3.8,2) \n    (0,2) to[short,o-o] (8,2)\n    (opamp1.out) to[short] (6.2,5)\n    (3.5,5) to[C,l=$C$] (6.2,5)\n    (3.5,4) to[short] (3.5,5)\n    (opamp1.out) to[short,-o] (8,3.5)\n    (0,4) to[open, v=$x(t)$] (0,2)\n    (8,3.5) to[open, v=$y(t)$] (8,2);\n    \\end{circuitikz}\\\\\n    \\hline\n\\end{tabular}\n\n\\newpage\n\\section*{Solved Problems}\n\n\\begin{enumerate}\n\\item Consider a system with the following block diagram:\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [block] at (4.5,0) (block1) {$\\int$};\n    \\node [sum] at (2,0) (sum) {$\\Sigma$};\n    \\node [output, name=feedback] at (6,0) {};  \t\n    \\node [output, name=feedback2] at (6,1) {};  \t\n    \\node [output, name=output] at (8,-5) {};  \t\n    \\node [block] at (6,-2) (block2) {$\\int$};\n    \\node [output, name=output2] at (6,-3) {};  \t\n    \\node [block] at (6,-4) (block3) {$\\int$};\n    \\node [output, name=output3] at (6,-5) {};  \t\n    \\draw [->] (input) --  (sum);\n    \\draw [->] (sum) -- (block1);\n    \\draw (block1) -- (feedback);\n    \\draw (feedback) -- (feedback2);\n    \\draw [->] (feedback2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [->] (output3) -- node {$b$} (output);\n    \\draw [->] (feedback) -- (block2);\n    \\draw [->] (block2) -- (block3);\n    \\draw [->] (output2) -| node[pos=0.95] {$-$} (sum);\n    \\draw (block3) -- (output3);\n    \\draw node at (-0.5,0) {$x(t)$};\n    \\draw node at (8.5,-5) {$y(t)$};\n    \\draw node at (4,-2.75) {$a$};\n  \\end{tikzpicture}\n\\end{center}\n\nDetermine the differential equation representation of this system.\\\\[1em]\n\n\n\\textbf{Solution:} We can convert this back to a differential equation representation as follows. First label the output of each block as a signal (called the internal states of the system), which we denote as $u(t)$, $v(t)$, $w(t)$, and $z(t)$ below.\n\n\\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=1, every node/.style={transform shape}]\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node [block] at (4.5,0) (block1) {$\\int$};\n    \\node [sum] at (2,0) (sum) {$\\Sigma$};\n    \\node [output, name=feedback] at (6,0) {};  \t\n    \\node [output, name=feedback2] at (6,1) {};  \t\n    \\node [output, name=output] at (8,-5) {};  \t\n    \\node [block] at (6,-2) (block2) {$\\int$};\n    \\node [output, name=output2] at (6,-3) {};  \t\n    \\node [block] at (6,-4) (block3) {$\\int$};\n    \\node [output, name=output3] at (6,-5) {};  \t\n    \\draw [->] (input) --  (sum);\n    \\draw [->] (sum) -- (block1);\n    \\draw (block1) -- (feedback);\n    \\draw (feedback) -- (feedback2);\n    \\draw [->] (feedback2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [->] (output3) -- node {$b$} (output);\n    \\draw [->] (feedback) -- (block2);\n    \\draw [->] (block2) -- (block3);\n    \\draw [->] (output2) -| node[pos=0.95] {$-$} (sum);\n    \\draw (block3) -- (output3);\n    \\draw node at (-0.5,0) {$x(t)$};\n    \\draw node at (8.5,-5) {$y(t)$};\n    \\draw node at (4,-2.75) {$a$};\n    \\draw node at (6.5,0) {$u(t)$};\n    \\draw node at (6.5,-3) {$v(t)$};\n    \\draw node at (3,-0.3) {$w(t)$};\n    \\draw node at (5.5,-5) {$z(t)$};\n  \\end{tikzpicture}\n\\end{center}\nNow we can read off the input-output relationships moving from input to output. Starting with the output of the summation\n\\[\nw(t) = x(t) - u(t) -a\\,v(t) \\; .\n\\]\nThe outputs of each integrator are:\n\\[\nu(t) = \\int\\limits_{-\\infty}^t w(\\tau) \\; d\\tau\\;, \\;\nv(t) = \\int\\limits_{-\\infty}^t u(\\tau) \\; d\\tau\\;, \\mbox{ and }\\;\nz(t) = \\int\\limits_{-\\infty}^t v(\\tau) \\; d\\tau\n\\]\nor equivalently\n\\[\n\\frac{du}{dt}(t) = w(t)\\;,\\; \\frac{dv}{dt}(t) = u(t)\\; ,\\; \\mbox{ and }\\; \\frac{dz}{dt}(t) = v(t)\n\\]\nFinally, the output is:\n\\[\ny(t) = b\\, z(t)\\; .\n\\]\nWe now do a series of derivatives and substitutions\n\\begin{align*}\n  y(t) &= b\\, z(t)\\\\\n  \\frac{dy}{dt}(t) &= b\\, \\frac{dz}{dt}(t)\\\\\n  &= b\\, v(t)\\\\\n  \\frac{d^2y}{dt^2}(t) &= b\\, \\frac{dv}{dt}(t)\\\\\n  &= b\\, u(t)\\\\\n  \\frac{d^3y}{dt^3}(t) &= b\\, \\frac{du}{dt}(t)\\\\\n  &= b\\, w(t)\\\\\n  &= b\\left( x(t) - u(t) -a\\,v(t)\\right)\n\\end{align*}\nRearranging the last equation to isolate the input on the right hand side gives\n\\[\n\\frac{d^3y}{dt^3}(t) + b\\,u(t) +ab\\,v(t) = b\\,x(t)\\; \\mbox{ (Eqn.~1)}\n\\]\nWe can now note from above\n\\[\nu(t) = \\frac{dv}{dt}(t) =  \\frac{d^2z}{dt^2}(t) = \\frac{1}{b} \\frac{d^2y}{dt^2}(t) \\mbox{ and }\n\\]\n\\[\nv(t) = \\frac{dz}{dt}(t) = \\frac{1}{b} \\frac{dy}{dt}(t)\\; .\n\\]\nSubstituting these back into Eqn.~1 gives\n\\[\n\\frac{d^3y}{dt^3}(t) + \\frac{d^2y}{dt^2}(t) +a\\,\\frac{dy}{dt}(t) = b\\,x(t)\n\\]\nWhich is a LCCDE.\\\\\n$\\blacksquare$\n\\end{enumerate}\n\n", "meta": {"hexsha": "9986d269f458c8280042023aa7d5bccee3599e7e", "size": 35962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-ct-block.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": "10-ct-block.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": "10-ct-block.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": 40.5434047351, "max_line_length": 466, "alphanum_fraction": 0.5828096324, "num_tokens": 13492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6434965906405044}}
{"text": "\\section{Feature Matching}\nFeature: measured characteristic of (part of) a pattern / object\\\\\nGoal: efficient matching\n\n\nFeatures shoud overcome large variations in\n\\begin{enumerate}\n\t\\item Viewpoint\n\t\\item Illumination\n\t\\item Background\n\t\\item Occlusions\n\t\\item Scale change\n\t\\item Deformation\n\t\\item Perspective Deformation\n\t\\item Blur\n\\end{enumerate}\n\nA feature should capture something \\textbf{discriminative} about a well \\textbf{localisable} patch of a surface\n\n\\subsection{Detector}\n\nThe detector typically yields image points. Corners are the most prominent example of so-called `Interest Points’, i.e. points that can be well localised in different views of a scene\n\n\\subsubsection{Uniqueness of a patch}\nHow do the patterns change upon a shift?\\\\\n\\textit{flat region}: no change in all directions\\\\\n\\textit{edge region}: no change along edge direction\\\\\n\\textit{corner} : significant change in all directions\\\\\n\\\\\nCompare each pixel before and after by summing up the squared differences (SSD) - this defines an error $E(u,v)$. Shift in x-direction: $u$, in y-direction:$y$.\n$$ E(u,v) = \\sum_{(x,y)\\in W} [I(x+u, y+v) - I(x,y)]^2 $$\n$$ E(u,v) = \\sum_{(x,y)\\in W} [u v] \\underbrace{\\begin{bmatrix}\nI_x^2&I_xI_y\\\\\nI_yI_x&I_y^2\\\\\n\\end{bmatrix}}_H \\begin{bmatrix}\nu\\\\\nv\\\\\n\\end{bmatrix} $$\nWant E(u,v) to be \\textbf{large} for small shifts in \\textbf{all} directions - the minimum is given by the smaller eigenvalue of H.\n\n\\subsubsection{The Harris corner detector}\n$$ R = det(H) - k*trace(H)^2 $$\nWhen $|R|$ is small, which happens when $\\lambda_1$ and $\\lambda_2$ are small, the region is flat.\\\\\nWhen $R<0$, which happens when $\\lambda_1$>>$\\lambda_2$ or vice versa, the region is an edge.\\\\\nWhen $|R|$ is large, which happens when $\\lambda_1$ and $\\lambda_2$ are large and $\\lambda_1 ~\\lambda_2$, the region is a corner.\n\n\\subsection{Descriptor}\nDescriptors then are a vector of measurements taken around each such point\n\n\nWe need to describe their surrounding image patch such we can discriminate between them, i.e. we need to build a feature vector for the patch \\&\nInvariance under geom./phot. change\n\n\\subsubsection{Deformations under projections (geom. change)}\n\\begin{enumerate}\n\t\\item similarity 4DOF\n\t\\item affinity 6DOF\n\t\\item projectivity 8DOF\n\\end{enumerate}\n\nComplexity of the groups goes up with the generality of the viewing conditions, and so does the complexity of the group’s invariants. Fewer invariants are found going from top to bottom\n\n\\subsubsection{Photometric changes}\n\\begin{itemize}\n\t\\item Contrasts (intensity differences) let the non-linear offsets cancel; hence gradients are good !\n\t\\item Moreover the orientation of gradients in the color bands is invariant under their linear changes, as is the intensity gradient orientation in case the scale factors are identical; this is indeed relevant if the illumination changes its intensity, but not its color, which is typically assumed.\n\t\\item But even under changing color of the illumination, in practice edge orientations tend to remain the same.\n\\end{itemize}\n\n\\subsection{Matching}\n\\begin{itemize}\n\t\\item Interest points are matched on the basis of their descriptors\n\t\\item E.g. nearest neighbour, based on some distance like Euclidean or Mahalanobis; good to compare against 2nd nearest neighbour: OK if difference is big; or fuzzy matching w. multiple neighbours\n\t\\item Speed-ups by using lower-dim. descriptor space (PCA) or through some coarse-to-fine scheme (very fast schemes exist to date!)\n\t\\item Matching of individual points typically followed by some consistency check, e.g. epipolar geometry, homograpy, or topological\n\\end{itemize}\n\n\\subsection{The Patch}\n\\subsubsection{MSER - Maximally stable extremal regions}\n\\begin{enumerate}\n\t\\item Start with intensity extremum\n\t\\item Then move intensity threshold away from its value and watch the super/sub-threshold region grow\n\t\\item Take regions at thresholds where the growth is slowest (happens when region is bounded by strong edges)\n\\end{enumerate}\n\n\\subsubsection{SIFT - Scale-Invariant Feature Transform}\nIs a carefully crafted interest point detector + descriptor, based on intensity gradients and invariants under similarities, not affine like so far.\\\\\n\\\\\n\\textbf{Descriptor} is based on blob detection - at several scales - that is local extrema of the Laplacian-of-Gaussian (LoG)\n\n\\includegraphics[width=0.7\\columnwidth]{pictures/sift2}\n\n\\begin{itemize}\n\t\\item Thresholded image gradients are sampled over a grid - Dominant orientation selection\n\t\\begin{itemize}\n\t\t\\item Compute image gradients of cell\n\t\t\\item Build orientation histogram\n\t\t\\item Find maximum of cell $\\rightarrow$ orientation of cell\n\t\\end{itemize}\n\t\\item Create array of orientation histograms within blocks\n\t\\item 8 orientations x 4x4 histogram array (! in picture only 2x2) = 128 dimensions\n\t\\item Apply weighting with a Gaussian located at the center\n\t\\item Normalized to unit vector\n\\end{itemize}\n\n\\includegraphics[width=\\columnwidth]{pictures/sift}\n\n\\subsubsection{SURF - efficient alternative to SIFT}\nno further infos", "meta": {"hexsha": "670bc5ea3704df9f47f29991209e84e566144624", "size": 5053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3_Relating_Images.tex", "max_stars_repo_name": "gruke/ethz-cv-lectureNotes", "max_stars_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-05T20:43:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-05T20:43:06.000Z", "max_issues_repo_path": "chapters/3_Relating_Images.tex", "max_issues_repo_name": "gruke/ethz-cv-lectureNotes", "max_issues_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "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/3_Relating_Images.tex", "max_forks_repo_name": "gruke/ethz-cv-lectureNotes", "max_forks_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "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.3577981651, "max_line_length": 300, "alphanum_fraction": 0.7726103305, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6434965872305022}}
{"text": "\\subsubsection{Repeated Eigenvalues}\r\n\\noindent\r\nIf $A$ has an eigenvalue with multiplicity $k$, that eigenvalue needs to generate $k$ fundamental solutions. If this eigenvalue generates $k$ linearly independent eigenvectors, then the process is much like with distinct eigenvalues. Otherwise, the matrix $A$ is defective.\r\n\\begin{theorem}\r\n\tIf $\\lambda$ is an eigenvalue with multiplicity $k$, and $\\left\\{\\vec{v_1}, \\ldots, \\vec{v_k}\\right\\}$ are corresponding linearly independent eigenvectors, the the set of fundamental solutions generated by $\\lambda$ is $\\left\\{e^{\\lambda t}\\vec{v_1}, \\ldots, e^{\\lambda t}\\vec{v_k}\\right\\}$.\r\n\\end{theorem}\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/homogeneousSystems/repeatedEigenvalues_example.tex}\\fi", "meta": {"hexsha": "ff8a3eeea4777861f3910254d7b5bb9abdeffcc3", "size": 764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/repeatedEigenvalues.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/repeatedEigenvalues.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/repeatedEigenvalues.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": 95.5, "max_line_length": 293, "alphanum_fraction": 0.7709424084, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6434965857144419}}
{"text": "%\n% 536\n%\n\\chapter{Ellipsoidal Harmonics and \\Lame's Equation}\n\n\\Section{23}{1}{The definition of ellipsoidal harmonics.}\n\nIt has been seen earlier in this work \\hardsectionref{18}{4}) that solutions of\nLaplace's equation, which are analytic near the origin and which are\nappropriate for the discussion of physical problems connected with a\nsphere, may be con- veniently expressed as linear combinations of\nfunctions of the type\n\ncos r' P (cos ), r' Pn'\" (cos 6) . md),\n\nwhere n and m are positive integers (zero included).\n\nWhen Pn (cos 6) is resolved into a product of factors which are linear\nin cos 6 (multiplied by cos 6 when n is odd), we see that, if cos 9 is\nreplaced by zjr, then the zonal harmonic r\"P (cos 6) is expressible as\na product of factors which are linear in a, y and z, the whole being\nmultiplied by z when n is odd. The tesseral harmonics are similarly\nresoluble into factors which are linear in a, y and z- multiplied by\none of the eight products 1, cc, y, z, yz, zx, xy, xyz.\n\nThe surfaces on which any given zonal or tesseral harmonic vanishes\nare surfaces on which either 6 or (f) has some constant value, so that\nthey are circular cones or planes, the coordinate planes being\nincluded in certain cases.\n\nWhen we deal with physical problems connected with ellipsoids, the\nstructure of spheres, cones and planes associated with polar\ncoordinates is replaced by a structure of confocal quadrics. The\nproperty of spherical harmonics which has just been explained suggests\nthe construction of a set of harmonics which shall vanish on certain\nmembers of the confocal system.\n\nSuch harmonics are known as ellipsoidal harmonics; they were studied\nby Lame* in the early part of the nineteenth century by means of\nconfocal coordinates. The expressions for ellipsoidal harmonics in\nterms of Cartesian coordinates were obtained many years later by W. D.\nNiven-f-, and the following account of their construction is based on\nhis researches.\n\nThe fundamental ellipsoid is taken to be\n\nx ir z, a 0 c\n\nand any confocal quadric is\n\n* Journal de Math. iv. (1839), pp. 100-125, 126-163. t Phil. Trans.\n182 a (1892), pp. 231-278.\n\n%\n% 537\n%\n\nwhere is a constant. It will be necessary to consider sets of such\nquadrics, and it conduces to brevity to write\n\nU - I 1 = (h)\n\nThe equation of any member of the set is then\n\nQp = 0.\n\nThe analysis is made more definite by taking the a;-axis as the\nlongest axis of the fundamental ellipsoid and the -axis as the\nshortest, so that a>b> c.\n\n\\Section{23}{2}{The foiir species of ellipsoidal hat monics.TODO}\n\nA consideration of the expressions for spherical harmonics in factors\nindicates that there are four possible species of ellipsoidal\nharmonics to be investigated. These are included in the scheme\n\n1, y, zx, xyz r% %. ...%,\n\nX,\n\nyz,\n\n2/'\n\nzx,\n\nz,\n\n y,\n\nwhere one or other of the expressions in is to multiply the product If\nwe write for brevity\n\n©,(H),...e, = n((H)),\n\nany harmonic of the form IT (0) will be called an ellipsoidal harmonic\nof the first species. A harmonic of any of the three forms* 11 (©),\nyYi (©), 11 (©) will be called an ellipsoidal harmonic of the second\nspecies. A harmonic of any of the three forms* yzXl (0), '.rll (®),\nxyYi (©) will be called an ellipsoidal harmonic of the third species.\nAnd a harmonic of the form xyzYl (0) will be called an ellipsoidal\nharmonic of the fourth species.\n\nThe terms of highest degree in these species of harmonics are of\ndegrees 27n, 2m + 1, 2m + 2, 2m + 3 respectively. It will appear\nsubsequently \\hardsubsectionref{23}{2}{6}) that 2/1 + 1 linearly independent harmonics of\ndegree n can be constructed, and hence that the terms of degree n in\nthese harmonics form a fundamental system (§ 18\"o) of harmonics of\ndegree n.\n\nWe now proceed to explain in detail how to construct harmonics of the\nfirst species and to give a general account of the construction of\nharmonics of the other three species. The reader should have no\ndifficulty in filling up the lacunae in this account with the aid of\nthe corresponding analysis given in the case of functions of the first\nspecies.\n\n* The three forms will be distinguished by being described as\ndifferent tyj es of the species.\n\n%\n% 538\n%\n\n\\Subsection{23}{2}{1}{The construction of ellipsoidal harmonics of the first species.}\n\nAs a simple case let us first consider the harmonics of the first\nspecies which are of the second degree. Such a hal-monic must be\nsimply of the form @i.\n\nNow the effect of applying Laplace's operator, namely\n\n9- d 9- x y- z\"\n\n9 ' 9p' 9? a d,' ¥'+T, ¥Ver\n\n2 2 2\n\nci\" + e, b'- + 0, c' + e, '\n\nand so @i isa harmonic if 6 is a root of the quadratic equation\n\n(0 + ¥) 6 + cO + ((9 + d\") (6 + a') + (f) + a') (6 + b') = 0.\n\nThis quadratic has one root between - c and - b~ and another between -\n6 and - a-. Its roots are therefore unequal, and, by giving 6 the\nvalue of each root in turn, we obtain two* ellipsoidal harmonics of\nthe first species of the second degree.\n\nNext consider the general product @i02 ... @; this product will be\ndenoted by n (0) and it will be supposed that it has no repeated\nfactors - a supposi- tion which will be justified later \\hardsubsectionref{23}{4}{3}).\n\nIf we temporarily regard Bj, @, ... (S) j as a set of auxiliary\nvariables, the ordinary formula of partial differentiation gives\n\n9n (0) \\ ' dU ((H)) 90 \\ dUi® 2cc dx pZi 9@p dx p i d p ' a- + dp'\n\nand, if we differentiate again,\n\n9 n(@)\\ 9n(0) 2 . dm(®) Sx\n\ndx' p=i 9@ ' a'+0p' j,, dBpdB, \" (a' + dp) a\" + 6 ) '\n\nwhere the last summation extends over all unequal pairs of the\nintegers 1, 2, ... m. The terms for which p = q may be omitted because\nnone of the expressions 0,, @o, ... 0 enters into fl (0) to a degree\nhigher than the first.\n\nIt follows that the result of applying Laplace's operator to 11 (0) is\n\n5 i5II(©) j 2 2 2 )\n\nV S'n (0 ) (\\ Sx' 8y' 8f ]\n\n  jZ Wpm, t(a + 0p) (a- + e~,) \"*\" (6 + 0p) (¥ + dg) (c + Op) (c +\nd,)\\ '\n\nj\\ ow = -\n\n(.ry,A ci'+0p)(O''+f g) 0g-0p' \\ a,b,c )\n\n* The complete set of 5 ellipsoidal harmonics of the second degree is\ncomposed of these two together with the three harmonics yz, zx, xy,\nwhich are of the third species.\n\n%\n% 539\n%\n\nand 9n (S)/dSp consists of the product 11 (0) with the factor ®p\nomitted, while d U (S)/d®pdSq consists of the product IT (0) with the\nfactors 0 and 0 omitted. That is to say\n\n3 n(0) an(0) a n(0) 8n(©)\n\nIf we make these substitutions, we see that\n\nn(0)\n\n9 9- 3'\n\n o n\n\nmay be written in the form\n\ng 9 n (0) f 2 2 2 V' \\ \\ ?\\\n\nthe prime indicating that the term for which q = p has to be omitted\nfrom the summation.\n\nIf n (0) is to be a harmonic it is annihilated by Laplace's operator;\nand it will certainly be so annihilated if it is possible to choose 0\n, O., ... 0,n so that each of the equations\n\na' + e ' b' + ep c'+dp Op-e\n\nis satisfied, where p takes the values 1, 2, ... m.\n\nNow let i9 be a variable and let Aj (6) denote the polynomial of\ndegree m in 6\n\nm\n\nn d-e,).\n\nq = \\\n\nIf A/( ) denotes cZAj (6)/cW, then, by direct differentiation, it is\nseen that A/ (6) is equal to the sum of all products of - i, 6 - 6.,,\n... 6 - 6,ni - l at a time, and A/' (6) is twice the sum of all\nproducts of the same expressions, m - 2 at a time.\n\nHence, if 6 be given the special value 6p, the quotient A \" (6p)IA\n(6p) becomes equal to twice the sum of the reciprocals of 6p-6y, 6p -\n6.2, ... 6p - 6, (the expression 6p - 6p being omitted).\n\nConsequently the set of equations derived from the hypothesis that\n\nn (0J,) is a harmonic shews that the expression\n\n'' ' 1 1 1 2A/'( J\n\na' + 6' ¥+6' c'+d A,' (6)\n\nvanishes whenever 6 has any of the special values 6, 60, ... 6j,.\n\nHence the expression\n\n(a' + 6) (b' + 6) (c + 6) A,\" 6) + l\\ 1 (¥ + 6) (c' + 6),- A/ 6)\n\n\" ( a, h, c '\n\n%\n% 540\n%\n\nis a polynomial in 6 which vanishes when 6 has any of the values\nTODO, and so it has TODO as factors. Now this\npolynomial is of degree m + 1 in and the coefficient of '\"+ is m (m +\n|), Since m of the factors are known, the remaining factor must be of\nthe form\n\nm (m + ) 6 + IG,\n\nwhere is a constant which will be determined subsequently.\n\nWe have therefore shewn that\n\n( . + 0) f2 + d) (c + 6) A/' 6) + \\ \\ 1 h - + 6) \\& + )l A/ 6)\n\n= |m(m + *)6' + i-C' Ai(6').\n\nThat is to say, any ellipsoidal harmonic of the first species of\n(even) degree n is expressible in the form\n\nwhere 0, 6.,, ..., i are the zeros of a pol Tiomial Ai( ) of degree\nn; and this polynomial must be a solution of a differential equation\nof the type\n\n4V (a + )(6 + )(c + ) |\n\n \\ \\ {a + e) ¥ + e) c - e)] '>\n\n= [n n + l)e + C].\\, e).\n\nThis equation is known as Lame's differential equation. It will be in-\nvestigated in considerable detail in §§ 23\"4-23*81, and in the course\nof the investigation it will be shewn that (I) there are precisely n +\n1 different real values of G for which the equation has a solution\nwhich is a polynomial in d of degree \\ n, and (II) these polynomials\nhave no repeated factors.\n\nThe analysis of this section may then be reversed step by step to\nestablish the existence of -J + 1 ellipsoidal harmonics of the first\nspecies of (even) degree n, and the elementary theory of the harmonics\nof the first species will then be complete.\n\nThe corresponding results for harmonics of the second, third and\nfourth species will now be indicated briefly, the notation already\nintroduced being adhered to so far as possible.\n\n\\Subsection{23}{2}{2}{Ellipsoidal harmonics of the second species.}\n\nin\n\nWe take x II (0 ) as a typical harmonic of the second species of\ndegree\n\n2m + 1. The result of applying Laplace's operator to it is\n\nr: 311(0) I 6 2 2 I\n\n Ip i dSp \\ a' + dp' b' + Op' c' + dp]\n\n   X dSpde ( a'- + dp) (a + 6, ) (6' + dp) (b' + 6, ) \" (c= + 0p) (c +\n6,)\\ ] '\n\n%\n% 541\n%\n\nand this has to vanish. Consequently, if\n\n3 = 1\n\nwe find, by the reasoning of \\hardsubsectionref{23}{2}{1}, that A 0) is a solution of the\ndifferential equation\n\n(cc- + d) b'- + e) c' + e)A./'(e)\n\n+ 3 (6 + 0) ic' + e) + (c ~ + d) (a' + 0) + ( + 0) ib' + 0) A/ (0)\n\n= m(m + f) + ia Ao(6'), where Cn is a constant to be determined.\n\nIf now we write Ag (0) = A ( )/\\/(a- + 0), we find that A (0) is a\nsolution of the differential equation\n\n4> (a + 0)(h - + 0) c +0)\n\nV((a + )(6- + )(c + )]. '\n\nd0\n\n= (2m + 1) 2ru + 2) + C A 0), where C = 6*2 + 6 + c-.\n\nIt will be observed that the last differential equation is of the same\ntype as the equation derived in \\hardsubsectionref{23}{2}{1}, the constant n being still\nequal to the degree of the harmonic, which, in the case now under\nconsideration, is 2m + 1.\n\nHence the discussion of harmonics of the second species is reduced to\nthe discussion of solutions of Lame's differential equation. In the\ncase of harmonics of the first type the solutions are required to be\npolynomials in multiplied by \\/ a + 0); the corresponding factors for\nharmonics of the second and third types are \\/(b- -+- 0) and (c\" + 0)\nrespectively. It will be shewn subsequently that precisely m + 1\nvalues of C can be associated with each of the three types, so that,\nin all, 8???, + 3 harmonics of the second species of degree 2m 4- 1\nare obtained.\n\n\\Subsection{23}{2}{3}{Ellipsoidal harmonics of the third species.}\n\nm\n\nWe take yz U (@ ) as a typical harmonic of the third species of degree\n2m + 2. The result of applying Laplace's operator to it is\n\nr ' 31] (Ch)) [ 2 6 6\n\n Ip' i % ( ' + 0p h + 0p c'- -0,\n\n  dm (@) f 8 %if 8 n\n\n+ j q d%d% ((a + 0p) a + 0q) (¥ + dp) (6 +,) \" (c + 0 ) (c' + 0q) i I\n' and this has to vanish. Consequently, if\n\nA3( )= n 0-0,;),\n\n3=1\n\n%\n% 542\n%\n\nwe find, by the reasoning of \\hardsubsectionref{23}{2}{1}, that A3 6) is a solution of the\ndifferential equation\n\n(a' + 6) (b' + 6) c' + 6) A,\" \\&)\n\n+ h K '-' + d) (c- + 6') + 3 (c + 6) tr + ) + 3 te + 6) b' + 6)] A,' 0\n\n= [m(vi + )e + iC,]As(e), where Oj is a constant to be determined.\n\nIf now we write A3 (6) = A 0)l [ b' + 6) (c-' + 6)], we find that A 6)\nis a solution of the differential equation\n\n4 Vl(a- + 0) ¥ + 6) (c + )| ~ s/ ce + 6) ¥ + 6) (c' + 6)\n\ndA(e)'\n\ncie\n\n= (2m -f 2) (2m + 3) + C] A (0),\n\nwhere C = C3 -F 4 (1 + b- + c-.\n\nIt will be observed that the last equation is of the same type as the\nequation derived in \\hardsubsectionref{23}{2}{1}, the constant n being still equal to the\ndegree of the harmonic, which, in the case now under consideration, is\n2m + 2.\n\nHence the discussion of harmonics of the third species is reduced to\nthe discussion of solutions of Lame's differential equation. In the\ncase of harmonics of the first type, the solutions are required to be\nj olynomials in multiplied by VK \" + ) ( + )j ' ® corresponding\nfactors for harmonics of the second and third types are J (c\" + 6) (a-\n+ 6)] and \\ J[ a- + 6) (b- + 6)] respectively. It will be shewn\nsubsequently that precisely m + 1 values of C can be associated with\neach of the three types, so that, in all, Sni + 3 harmonics of the\nthird species of degree 2m + 2 are obtained.\n\n\\Subsection{23}{2}{4}{Ellipsoidal harmonics of the fourth species.}\n\nThe harmonic of the fourth species of degree m + 8 is expressible in\nthe\n\nm\n\nform xyz 11 (@p). The result of applying Laplace's operator to it is\n\nr an 0) [ 6 i>\\ \\ . \\ \\ L\n\n\"l3i % t ' + P ' ' + ' P c' + p\n\n  d'U (B) ( 8a,- \\ %'\n\n\",i ae aB, [(a- + e ) a? + e,) \" (ft + e j¥ + e ) \" (c + e,;) (c +\ne,,)\\ \\ '\n\nand this has to vanish. Consequently, if\n\nHi\n\nA,( )=ll( -,),\n\n7 = 1\n\nwe find by the reasoning of \\hardsubsectionref{23}{2}{1} that A4( ) is a solution of the\nequation\n\n( + )(6' + )(c- + )a;'( )+ I :s (6 + <9)(c + 6 )|a;( )\n\n= m(m + |) + iC, A,( ), where C4 is a constant to be determined.\n\n 'ce~ + e) h - + e)(c' + 0) ~\n\n%\n% 543\n%\n\nIf now we write\n\nA, 6) = A 0)/ (a + 6) (¥ + d) (c' + 0), we find that A (0) is a\nsolution of the differential equation\n\n= (2m + 3) 2m + 4) + C A (6),\n\nwhere C = C + 4< (a- + h- + c'-).\n\nIt will be observed that the last equation is of the same type as the\nequation derived in \\hardsubsectionref{23}{2}{1}, the constant n being still equal to the\ndegree of the harmonic which, in the case now under consideration, is\n2m + 3.\n\nHence the discussion of harmonics of the fourth species is reduced to\nthe discussion of solutions of Lame's differential equation. The\nsolutions are required to be polynomials in 6 multij)lied by \\/ a\" +\n6) b\"- + 6) (c + n)]. It will be shewn subsequently that precisely m +\n1 values of C can be associated with solutions of this type, so that m\n+ 1 harmonics of the fourth species of degree 2rii -f 3 are obtained.\n\n\\Subsection{23}{2}{5}{Nivens expressions fur ellipsoidal harmonics in terms of homogeneous harmonics.}\n\nIf Gn (x, y, z) denotes any of the harmonics of degree n which have\njust been tentatively constructed, then Gn ( \", y. z) consists of a\nfinite number of terms of degrees n, n - 2, w - 4, ... in x, y, z. If\nH x, y, z) denotes the aggregate of terms of degree n, it follows from\nthe homogeneity of Laplace's operator that Hn (, y, z) is itself a\nsolution of Laplace's equation, and it may obviously be obtained from\nGn x, y, z) by replacing the factors (h), which occur in the\nexpression of Gn oc, y, z) as a product, by the factors Kp.\n\nIt has been shewn by Niven loc. cit., pp. 243-245) that Gn (x, y, z)\nmay be derived from Hn oc, y, z) by applying to the latter function\nthe differential operator\n\n2(2?i-l)\"*'2.4.(2w-l)(2w-3) 2.4.6(2 1 - l)(27i-3)(27i-5) \" \" '\n\nwhere D'- stands for\n\n92 B 92\n\na - + b -- + c ~\n\nda dy dz '\n\nand terms containing powers of D higher than the nth may be omitted\nfrom the operator.\n\nWe shall now give a proof of this result for any harmonic of the first\nspecies*.\n\n* The proofs for harmonies of the other three species are left to the\nreader as examples. A proof applicable to fuiictious of all four\nspecies has been given by Hobson, Proc. London Math. Soc. XXIV.\n(1893), pp. (30-64. In constructing the proof given in the text,\nseveral modifi- cations have been made in Niven's proof.\n\n%\n% 544\n%\n\nFor such harmonics the degree is even and we write\n\np=i p=\\\n\nwhere Sn, Sn-2, Sn-i, ... are homogeneous functions of degrees n, w\n- 2, w - 4, . . ., respectively, and\n\nin Sn = Hn (x, y, Z)=U Kp.\n\np = l\n\nThe function Sn-2r is evidently the sum of the products of K, K2, ...\nKi, taken |- n - ? at a time.\n\nIf K, K2, ... /iTi n be regarded as an auxiliary system of variables,\nthen, by the ordinary formula of partial differentiation\n\na>s,\n\ndoc p=-i dKp dx\n\nin dS 9r\n\np=i dKp a~ + Bp and, if we differentiate again,\n\n= t - - + t\n\ndx pLx dKp a-'+dp p dKpdKq c(r + dp) a + 6 )'\n\nThe terms in d-Sn- rl Kp can be omitted because each of the functions\nKp does not occur in Sn\\ 2r to a degree higher than the first.\n\nIt follows that\n\np=i dKp \\ a + p 6 + <9p \\& + dp\\\n\n;, BKpdK, ( a' + Op) (a + 6,) ¥ + Op) b' + 6,) (c + dp) (c + 6,)] It\nwill now be shewn that the expression on the right is a constant\nmultiple\n\nOI >Oji\\ 2r- 2-\n\nWe first observe that\n\na?x OpKp - dqKq\n\n\\ a, b, c)\n\nand that, by the differential equation of \\hardsubsectionref{23}{2}{1},\n\na,T, ( \" + 0p a, b, c a- + Op\n\n= 6 - Up 2,,\n\nq = \\ tTp - Vq\n\n%\n% 545\n%\n\nD' n-or\n\np=i oKp p=i\n\n+ s t e,\n\ndSn-.\n\n, in\n\nbK\n\n1 6p - 0q\n\npjpq dKpdKq\n\nd\"Sn-2r dpKp- UqKq\n\n% - ( q\n\nNow dSn-or/dKp is the sum of the products of the expressions K, Ko, .\n. . iTijj (Kp being omitted) taken n - ?' - 1 at a time; and Kqd\nSn-2rldKpdKq consists of those terms of this sum which contain Kg as a\nfactor.\n\nHence\n\nC'0,i\\ 2 '\n\ndK.,\n\n~ - K,\n\nis equal to the sum of the products of the expressions K, Ko, ...\n-K\"i; (Kp and Kq both being omitted) taken hn - r-1 at a time; and\ntherefore, by sym- metry, we have\n\ndKr.\n\nK,\n\n''dKpdKq\n\nso that\n\ndKpdkq \" 1 ~dKr\n\ndK,\n\ndSn-\n\n-K\n\ndK.\n\nP dKpdKq'\n\n\\ Kq-Kp).\n\n,p w-i q\n\nOn substituting by this formula for the second differential\ncoefficients, it is found that\n\nUpKp- UqKq\n\nhi \\ i i\n\n  q = ( p - Gq q = \\ \\ {Gp- q) Kp- Kq)\\\n\nhi\n\n6-8 i'\n\np i dKp\n\n= 4:11 - I) Z\n\nK\n\n2 = 1 Kp - Kq\\\n\n\\ Kp-Kq).\n\np = \\ \" -Q-p p <i\n\nNow we may write Sn-2r in the form\n\n n-ir \"I\" \"- p n--2r-'2 \"l -' ' Ji- 2r- 2 \"T -\"- - r/' Jl- 2;'- 4>\n\nwhere 5io, denotes the sum of the products of the expressions K, K.,\n... /fj,, (Kp and Kq both being omitted) taken in at a time; and we\nthen see that\n\ndSn-\n\n\" dK\n\n Kp-Kq)Sn-,r-2.\n\nHence\n\nD'-8n-,r = (4n -2) t\n\np-l cIVp p q\n\nNow it is clear that the expression on the right is a homogeneous sym-\nmetric function of K, K.2, Kx, of degree n - r-\\, and it contains\nno power of any of the expressions K, K, ... Ki to a degree higher\nthan the first. It is therefore a multiple of Sn- r-z- To determine\nthe multiple we w. M. A. 35\n\n%\n% 546\n%\n\nobserve that when Sn- - is written out at length it contains jt C;.+i\nterms while the number of terms in\n\nis hn (4n - 2) ., \\,C, - 8 . a . i \\,C,-i-\n\nThe multiple is consequently\n\nand this is equal to (2r + 2) (2?i - 2r - 1). It has consequently been\nproved that\n\nD- Sn-.r = (2r + 2) (2n - 2r - 1) \\ . \\,. It follows at once by\ninduction that\n\n n-2r -\n\n2.4... 2/- . 2n - 1) (271 - 3) ... (2n - 2r + 1)' and the formula\n\nGn (x, y, z) =\n\nI (-YD\"-'-\n\nHn x, y, z)\n\n,.=o2.4...2r.(2n-l)(2n-:3)...(2n-2r + l) is now obvious when Gn x, y,\nz) is an ellipsoidal harmonic of the first species.\n\nExample 1. Prove Niven's fonmila when G (.r, y, z) is an ellipsoidal\nharmonic of the second, third or fourth species.\n\nExample 2. Obtain the symbolic formula\n\nG x, y, 2) = r(i- ). (iZ))\"+ /\\ \\ (Z)). (.r, y, z).\n\n2326. Ellipsoidal harmonics of degree n.\n\nThe results obtained and stated in §§ 23\"21-23\"24 shew that when n is\neven, there are n + 1 harmonics of the first species and |/i harmonics\nof the third species; when 7i is odd there are |(?i + l) harmonics of\nthe second species and n -1) harmonics of the fourth species, so that,\nin either case, there are 2n + 1 harmonics in all. It follows from §\n18*3 that, if the terms of degree n in these harmonics are linearly\nindependent, they form a funda- mental system of harmonics of degree n\n; and any homogeneous harmonic of degree n is expressible as a linear\ncombination of the homogeneous harmonics which are obtained by\nselecting the terms of degree n from the 2)i + 1 ellip- soidal\nharmonics.\n\nIn order to prove the results concerning the number of harmonics of\ndegree n and to establish their linear independence, it is necessary\nto make an intensive study of Lame's equation; but before we pursue\nthis investigation we shall study the construction of ellipsoidal\nharmonics in terms of confocal coordinates.\n\n%\n% 547\n%\n\nThese expressions for ellipsoidal harmonics are of historical\nimportance in view of Lame's investigations, but the expressions which\nhave just been obtained by Niven's method are, in some respects, more\nsuitable for physical applications.\n\nFor applications of ellipsoidal harmonics to the investigation of the\nFigure of the Earth, and for the reduction of the harmonics to forms\nadapted for numerical computation, the reader is referred to the\nmemoir by G. H. Darwin, Phil. Trans. 197 a (1901), pp. 461-537.\n\n\\Section{23}{3}{Confocal coordinates.}\n\nIf X, Y, Z) denote current coordinates in three-dimensional space, and\nif a, b, c are positive (a > 6 > c), the equation\n\nX' Y' Z,\n\n- +7 + = 1 a- 0- c-\n\nrepresents an ellipsoid; the equation of any confocal quadric is\n\nX2 7-2 2\n\n,+\n\nb' + 0' c + e '\n\na' + e\n\nand 6 is called the pcuximeter of this quadric.\n\nThe quadric passes through a particular point x, y, z) if 6 is chosen\nso that\n\n+ -\n\ny-\n\n+\n\n= ].\n\nar + d ¥ + 6 c- + e Whether 6 satisfies this equation or not, it is\nconvenient to write\n\n  yl\\ z' \\ /( )\n\n62 + (9\n\n1-\n\na--ve ¥ + e c'' + e~ a' + d) (6 + 0) (c- + 6>) '\n\nand, since f(d) is a cubic function of 6, it is clear that, in\ngeneral, three quadrics of the confocal system pass through any\nparticular point (x, y, z).\n\nTo determine the species of these three quadrics, we construct the\nfollowing Table :\n\ne\n\nf \\&)\n\n- 00\n\n- 00\n\n-d\n\n-.r2(a2-62)(a2.\n\n-C2)\n\n-62\n\ny2(a2-62)(52.\n\n-C2)\n\n- C\n\n-22(a2-c2) (62-\n\n-C2)\n\n+ 00\n\n+ 00\n\nIt is evident from this Table that the equation y*( ) = has three real\nroots X,, /i, V, and if they are arranged so that ix>v, then\n\n -C'>fi> - b->v > - a'-; and also /( ) = ( \\ X)( - )((9 - i').\n\nFrom the values of X, /x, v it is clear that the surfaces, on which\nhas the respective values X, /z, v, are an ellipsoid, an hyperboloid\nof one sheet and an hyperboloid of two sheets.\n\n35-2\n\n%\n% 548\n%\n\nNow take the identity in 6,\n\n\\ a? \\ j/ \\ 2' e- ) e-ii ) e-v)\n\nar- e b-'+tl C--+6 a' + e) b\"- + d) c- + e)' and multiply it, in turn,\nby a- + 6, h- + 0, c- + 6; and after so doing, replace 6 by - (('-, -\nh-, - c- respectively. It is thus found that\n\n, \\ (a- + ) (a + fj.) (a- + v)\n\n, \\ (6 + X) (6 + 6- + lO ' '(a--6-)( '-c-) '\n\n  \\ (c- X ) (c- + fj,)(c- + v) '~ (a -c2)(6--c=) *\n\nFrom these equations it is clear that, if (a-, y, z) be any point of\nspace and if X, /Lt, V denote the parameters of the quadrics confocal\nwith\n\nX'- Y-' Z-,\n\n- + 1T + - = 1 a- 0 c-\n\nwhich pass through the point, then (x-, y\", z-) are uniquely\ndeterminate in terms of (X, fj,, v) and vice versa.\n\nThe parameters (X, fi, v) are called the confocal coordinates of the\npoint x, y, z) relative to the fundamental ellipsoid\n\nX' Y- Z'-,\n\na- b- c- It is easy to shew that confocal coordinates form an\northogonal system; for consider the direction cosines of the tangent\nto the curve of intersection of the surfaces (/a) and (v); these\ndirection cosines are proportional to\n\n/dx dy dz \\ d dX' dx\n\nand smce - -- + 4.\\ -- = % \\ - -\\ - \\ =\n\ndx dx dy dy dz dz \\ a + v\n\ndXdJi Xd l' dXdJjL aXc (a -6')(a2- c ) it is evident that the\ndirections\n\nfdx dy dz\\ /dx dy dz\\\n\nVax' dx' dx)' \\ d ' Yfi' dfx)\n\nare perpendicular; and, similarly, each of these directions is\nperpendicular to\n\n/dx dy dz\\\n\n\\ dv ' dv ' dv) ' It has therefore been shewn that the three systems\nof surfaces, on which X, jji, V respectively are constant, form a\ntriply orthogonal system. Hence the square of the line-element, namely\n\n hxy- hjr + hz)\\\n\nis expressible in the form\n\n%\n% 549\n%\n\nwith similar expressions in /j, and v for H. and H3'. To evaluate Hi-\nin terras of (X, u, y), observe that\n\n' \" 4 va y \" 4 / Ux-y 4 \\ dx\n\n x s; (g + fx) a? + i )\n\nBut, if we express\n\n(A, - /Lt) (X, - v)\n\n(a + X) (6 + X) (c\" + X) '\n\nqua function of X, as a sum of partial fractions, we see that it is\nprecisely equal to\n\n  (g + fi) (g\" + v)\n\n .5,c(g' + X)(g2-6 )(a -cO'.\n\nand consequently H - = . -r . il - z-A c\n\n  ' 4 (a2 + X) (62 + X) (c + X)\n\nThe values of H. and Hf are obtained from this expression by cyclical\ninterchanges of (X, /i, i').\n\nFormulae equivalent to those of this section were obtained by Lame,\nJournal de Math. II. (1837), pp. 147-183.\n\nExample 1. With the notation of this section, shew that\n\n.r2+/ + 5- = a2 + 62 + c2 + X + jtx + i'.\n\nExample 2. Shew that\n\nATTI- - I y\" I\n\n   a;' + \\ f h + \\ f c'' + \\ f'\n\n23 '31. Uniformising variables associated ivith confocal coordinates.\n\nIt has been seen in \\hardsectionref{23}{3} that when the Cartesian coordinates (x, y,\nz) are expressed in terms of the confocal coordinates (X, fx, v), the\nexpressions so obtained are not one-valued functions of (X, /x, v). To\navoid the inconvenience thereby produced, we express (X, /i, v) in\nterms of three new variables u, v, w) respectively by writing\n\nHP (u) = X + |(a- + 6 + C-),\n\n j(v) =/i +!( ' + ' + c'),\n\n'i'w) = v \\ \\ {d + h'\"' + c ),\n\nthe invariants g.2 and g of the Weierstrassian elliptic functions\nbeing defined by the identity\n\n4>(a-+X) b' + ) c'+X) f u)-g u)-g,.\n\n%\n% 550\n%\n\nThe discriminant associated with the L-lHptic functions (cf.\\hardsubsectionref{20}{3}{3},\n\nexample 3) is\n\n16 a- - b-Y b\"- - c'Y- (c- - a'Y,\n\nand so it is positive; and, therefore*, of the periods 2a),, 2\\&)o\nand 2\\&)3, 2g)i is positive while 2a)3 is a pure imaginary; and 2a)2\nhas its real part negative, since Wj + \\&).,+ 0)3 =; the imaginary\npart of Wo is positive since / ((o.J(o ) > 0.\n\nIn these circumstances e, >e.2>e:;, and so we have\n\n3e, = a- + b-- '2c-, Se = c\" + a- - 2b-, 8e, = b- + c- - 2a-.\n\nNext we express (x, y, z) in terms of u, v, w); we have\nTODO\nby \\hardsubsectionref{20}{5}{3}, example 4. Therefore, by \\hardsubsubsectionref{20}{4}{2}{1}, we have\n\nx.- -. \"/ 0-3 (\") 0-3 (t') o-s (w) o- (w) o- (t;) o- w)\n\na-2 (w) (7o (v) cTa (w) and similarly 3/ = ± e- -a-(a,,) (,,) - ( ) )\n\nX -T,co \"/ o l(\")o-l(y)o l(w) \\ 4. g ').'\"i cr- ( w ) - -- - --- - - .\n- a u) a- (v) a (w)\n\nThe effect of increasing each of u, v, w by 2(0 is to change the sign\nof the expression given for x while the expressions for y and z remain\nunaltered; and simila'r statements hold for increases by 2\\&).\\ . and\n2\\&)i; and again each of the three expressions is changed in sign by\nchanging the signs of u, v, iv.\n\nHence, if the upper signs be taken in the ambiguities, there is a\nunique correspondence between all sets of values of x, y, z), real or\ncomplex, and all the sets of values of (it, v, w) whose three\nrepresentative points lie in any given cell.\n\nThe uniformisation is consequently effected by taking\n\n., ., o-:, u) 0-3 v) 0-3 (w) cr ii) a v) a (w)\n\n-.u. 0/, o-2 (t/-)o-.,(t;)o-,(w) ' a- a) a v) cr w)\n\n(t u) (T v)cr w)\n\nFormulae which differ from these only by the interchange of the\nsuffixes- 1 and 3 were given by Halphen, Fonctions Elliptiques, li.\n(1888), p. 459.\n\n Cf.\\hardsubsectionref{20}{3}{2}, example 1.\n\n%\n% 551\n%\n\\Subsection{23}{3}{2}{Laplace's equation referred to confocal coordinates.}\n\nIt has been shewn by \\Lame\\ and by W. Thomson* that Laplace's equation\nwhen referred to any system of orthogonal coordinates (X, /j., v)\nassumes the form\n\n0,\n\nH, dv where H, H.2, H- are to be determined from the consideration\nthat\n\nis to be the square of the line-element. Although W. Thomson's proof\nof this result, based on arguments of a physical character, is\nextremely simple, all the analytical proofs are extremely long and\ncumbrous.\n\nIt has, however, been shewn by Lamef that, in the special -case in\nwhich (X, /JL, v) represent confocal coordinates, Laplace's equation\nassumes a simple form obtainable without elaborate analysis; when the\nuniformising variables (u, V, w) of \\hardsubsectionref{23}{3}{1} are adopted as\ncoordinates, the form of Laplace's equation becomes still simpler.\n\nBy straightforward differentiation it may be proved that, when any\nthree independent functions (X, /n, v) of x, y, z) are taken as\nindependent variables, then\n\na F a F a F\n\ntransforms into\n\ndx- dy\n\n+\n\ndz-\"-\n\nt + 2 S\n\nyax\n\n\\ dx\n\nJ<1\n\n+\n\ndz. d/Ji dv\n\ndfx dv d/ji dv\n\ndx dx dy dy dz dzj d/jidv\n\nd \\ d \\ d'\\\n\nd\\ V dx'\n\nA.M. V \\ \\ x- dy- dz \\ In order to reduce this expression, we 'observe\nthat X satisfies the equation\n\nX- y z-\n\noMO. \"*\" PTX \" cM\n\n= 1,\n\nand so, by differentiation with x, y, z as independent variables, 2x x\ny  1 ' \\ A\n\na- +X\n\n14a;\n\n,+\n\n+\n\n(a + xy (6- + xy (c + x)- j dx\n\ndx\n\n+ 2\n\na + X (a + X)- dx a + X)\n\n+\n\ny.\n\nX-\n\n(6 + X)=\n\ny\n\n+\n\n+\n\n(c + X)\n\n+\n\n(a2 + X)- h- + \\ y (c + X)*- ] dx\n\nd'X\n\n= 0.\n\n* Cf. the footnote on p. 401.\n\nt Journal de Math. iv. (1839), pp. 133-136.\n\n%\n% 552\n%\n\nHence ~- =4<Hi,\n\na.' + \\ da;\n\na' + X (a-' + \\ y //j- 2 1 a' + xy /,7, v (a- + Xf ' d.v' '\n\n\\ a, b, c)\n\nwith similar equations in fx, v and y, z.\n\nd-V . From equations of the first type it is seen that the coefficient\nof - - is\n\n1 d-V . . . .\n\nV5r- and the coefficient of tt-t is zero; and if we add up equations\nof the\n\nsecond type obtained by interchanging x, y, z cyclically, it is found\nthat\n\n[dx- dy- 0Z-] o, i.c \" + with similar equations in [x and v. If, for\nbrevity, we write\n\n /[ a + X) h- + ) c' -X)] = K, ' with similar meanings for A and A,\nwe see that\n\na;- \" a \" a - (x - /i) (x - v) 1 a- + x 6- +'x \" c + X\n\n4Ax c Ax\n\n(X - /x) (X - I/) rfX ' and so Laplace's equation assumes the form\n\nx.T\", >' (' - A*) ( ~ ) L ' dx ax\n\nthat is to say\n\n= 0,\n\n(' - ) a-xWI ]+< - ) 'IKa + -'') ' .K'5 = -\n\nThe equivalent equation with u, v, lu) as independent variables is\nsimply or, more briefly,\n\n[i j v) - i w)] 1 + w) - in)] + [iO u) - v)] = 0,\n\n - >a + < - >-a + - >a = '-\n\nThe last three equations will be regarded as canonical forms of\nLaplace's equation in the subsequent analysis.\n\n\\Subsection{23}{3}{3}{Ellipsoidal harmonics referred to confocal coordinates. }\nWhen Niven's function 0p, defined as\n\na- + 6, J b'' + 6,, c- +\n\np p p\n\n%\n% 553\n%\n\nis expressed in terms of the confocal coordinates \\ [x, v) of the\npoint x, y, z), it assumes the form\n\n  e ) t,-ej) v-dp )\n\nand consequently, when constant factors of the form\n\n- ( + e,,) (¥ + dp) (c + Op)\n\nare omitted, ellij)soidal harmonics assume the form X, yz \\\n\nI m m m\n\n1, y, zx, xyz I n (X - ) H (/i-6'p) H v-B ).\n\nI p = l 73 = 1 p = \\\n\nz, xy ]\n\nIf now we replace x, y, z b ' their values in terms of X, /*, v, w e\nsee that any ellipsoidal harmonic is expressible in the form of a\nconstant multiple of AMN, where A is a function of \\ only, and M and N\nare the same functions of /Li, and V respectively as A is of X.\nFurther A is a polynomial of degree nn in \\ multiplied, in the case of\nharmonics of the second, third or fourth species, by one, two or three\nof the expressions \\/ a' + X), \\/ b- + X), \\/(c + )-\n\nm\n\nSince the polynomial involved in A is H (X - 6p), it follows from a\ncon-\n\ni3 = l\n\n4 si [ a- + X) ¥ + X ) (c + X)\n\nV((a- + X)(6 + X)(c + X)\n\nsideration of §§ 23'21-23-24 that A is a solution of Lame's\ndifferential equation\n\nX\n\n= [n n 4-l)X+C' A, where n is the degree of the harmonic in x, y, z).\n\nThis result may also be attained from a consideration of solutions of\nLaplace's equation which are of the type*\n\nV= AMN, where A, M, N are functions only of X, /x, v respectively.\n\nFor if we substitute this expression in Laplace's equation, as\ntransformed in \\hardsubsectionref{23}{3}{2}, on division by V, we find that\n\n  v)-io w) d K ( w) - J u) d'M 0 (u) - ipO ) d'N A dii M dv N \" div-\n\nThe last two terms, qua functions of u, are linear functions of ip\n(u), and\n\n1 d A\n\nso -r- -y 2 must be a linear function of o(u); since it is independent\nof the\n\ncoordinates v and w, we have\n\nwhere K and B are constants.\n\n* A harmonic which is the product of three functions, each of which\ndepends on one coordi- nate only, is sometimes called a normal\nsolution of Laplace's equation. Thus normal solutions with polar\ncoordinates are \\hardsubsectionref{18}{3}{1}|\n\nr\" P ' (cos d) ° m(p. \" ' sin\n\n%\n% 554\n%\n\nIf we make this substitution in the differential equation, we get a\nlinear function of (,) (k) equated (identically) to zero, and so the\ncoefficients in this linear function must vanish; that is to say\n\nm,. . s) 1 d-M 1 rf'N\n\nand on solving these with the observation that (v) - j J (lu) is not\nidentically zero, we obtain the three equations\n\nWhen X. is taken as independent variable, the first equation becomes\n\n4 A. |a. I = [K\\ - i? + i/i (a + ¥ + c )] A,\n\nand this is the equation already obtained for A, the degree n of the\nharmonic being given by the formula\n\nn (n + l) = K.\n\nWe have now progressed so far with the study of ellipsoidal harmonics\nas is convenient without making use of properties of Lame's equation.\n\nWe now proceed to the detailed consideration of this equation.\n\n\\Section{23}{4}{Various forms of \\Lame's differential equation.}\n\nWe have already encountered two forms of Lame's equation, namely\n\nand this may also be written\n\nd \\ a\" + \\ h- + X c- +X d\\ ~ 4 (a- + X) b- + X) (c- + X) ' which may\nbe termed the algebraic form; and\n\n  = n n + l) j(ii) + B]A,\n\nwhich, since it contains the Weierstrassian elliptic function (u), may\nbe termed the Weierstrassian form; the constants B and C are\nconnected by the relation\n\nB + in ( + 1) (a- + b- + c-) = C.\n\n%\n% 555\n%\n\nIf we take j (u) as a new variable, which will be called, we obtain\nthe slightly modified algebraic form (c£\\hardsectionref{10}{6})\n\nThis differential equation has singularities at gj, eo, e at which the\nexponents are 0, in each case; and a singularity at infinity, at\nwhich the exponents are - n,\\ \\ {n + ) .\n\nThe \"Weierstrassian form of the equation has been studied by Halphen,\nFonctions Elliptiques, ir. (Paris, 1888), pp. 457-531.\n\nThe algebraic forms have been studied by Stieltjes, Acta Math. vi.\n(1885), y>V. 321-326, Klein, Vorlesimgen iiber lineare\nDiferentielgleichunge/i lithogr\\&iAiGd, Gottingen, 1894), and Bocher,\nl/ber die Reihenentioickelungen der Potentialtheorie (Leipzig, 1894).\n\nThe more general differential equation with foiu* arbitrary\nsingularities at which the exponents are arbitrary (save that the sum\nof all the exponents at all the singularities is 2) has been discussed\nby Heun, Math. Ann. xsxiii. (1889), pp. 161-179; the gain in\ngenerality by taking the singularities arbitrary is only apparent,\nbecause by a homographic change of the independent variable one of\nthem can be transferred to the point at infinity, and then a change of\norigin is sufficient to make the sum of the complex coordinates of the\nthree finite singularities equal to zero.\n\nAnother important form of Lame's equation is obtained by using the\nnotation of Jacobian elliptic functions; if we write\n\nZl = U V(ei - 63),\n\nthe Weierstrassian form becomes\n\ndzi\"\n\nn n + 1) I - ' 1 1 -\n\n4-ns2 iV +\n\n€ > e,-e\n\nA,\n\nand putting 2 = a - iK', w here 2iK' is the imaginary period of sn z-\n, we obtain the simple form\n\n- i- = \\ n (n + 1) k- sn-a + A] A, doP / >\n\nwhere A is a constant connected with B by the relation\n\nB + e-iii (n + 1) = A e,- e-,).\n\nThe Jacobian form has been studied by Hermits, Sur quelques\napplications des fonctions elliptiques, Comptes Rendns, Lxxxv. (1877),\npublished separately, Paris, 1885.\n\nIn studying the properties of Lame's equation, it is best not to use\none form only, but to take the form best fitted for the purpose in\nhand. For practical applications the Jacobian form, leading to the\nTheta functions, is the most suitable. For obtaining the properties of\nthe solutions of the equation, the best form to use is, in general,\nthe second algebraic form, though in some problems analysis is simpler\nwith the Weierstrassian form.\n\n%\n% 556\n%\n\n\\Subsection{23}{4}{1}{Solittioiis in series of \\Lame\\'s equation.}\n\nLet us now assume a solution of Lamp's equation, which may be written\n\nin the form\n\nA= I 6.(1-,) \"-''.\n\n)-=0\n\nThe series on the right, if it is a solution, will converge \\hardsubsectionref{10}{3}{1})\nfor sufficiently small values of \\ \\ - e.,, but our object will be\nnot the discussion of the convergence but the choice of B in such a w\nay that the series may terminate, so that considerations of\nconvergence will be superfluous.\n\nThe result of substituting this series for A on the left-hand side of\nthe differential equation and arranging the result in powers of - go\nis minus the series\n\n4 i ( -e.,) ' -r + i[r(n-r-[-hJbr- Se,( n-r + ir--in n+l)e,-lB]br-\n\nr=--0\n\n+ (e, - e,) (e, - e,) ( w - r + 2) (i n - r + f ) 6,-2],\n\nin which the coefficients hj. with negative suffixes are to be taken\nto be zero.\n\nHence, if the series is to be a solution, the relation connecting\nsuccessive coefficients is\n\nr (n -r + )br = [Se ( n - r + 1)- - i ?i (n +l)eo-lB\\ br-i\n\n- (ei - e ) ( 2 - 63) i n - r + 2) n - r + f) br-.,\n\nand (n - i) 61 = n% -ln n + l)e,- B b,.\n\nIf we take \\& = 1, as we may do without loss of generality, the\ncoefficients bj. are seen to be functions of B with the following\nproperties :\n\n(i) bj. is a polynomial in B of degree r.\n\n(ii) The sign of the coefficient of B'' in br is that of (-)'\",\nprovided that ?' :\\$ n; the actual coefficient of B is\n\ni-Y\n\n2.4>...2r(2n-l) 2n-3)... ( 2n - 2r + 1) '\n\n(iii) If 1, e., e-i and B are real and i > 62 > 3, then, if b -i = 0,\nthe values of 6,. and 6,.\\ o are opposite in sign, provided that r < n\n+ 'A) and r < n.\n\nNow suppose that n is even and that we choose B in such a way that If\nthis choice is made, the recurrence formula shews that\n\nhn 2 = 0,\n\n%\n% 557\n%\n\nby putting r = 7i + 2 in the formula in question; and if both 6i,j\\ i\nand 1)1 + 2 6 subsequent recurrence formulae are satisfied by taking\n\n 1/1 + 3 = i + 4 = ... =0.\n\nHence the condition that Lame's equation should have a solution which\nis a polynomial in is that B should be a root of a certain algebraic\nequation of degree n + 1, when n is even.\n\nWhen n is odd, Ave take 6x j i\\ to vanish and then 6i/ 3x also\nvanishes, and so do the subsequent coefficients; so that the\ncondition, when n is odd, is that B should be a root of a certain\nalgebraic equation of degree \\ (n + 1).\n\nIt is easy to shew that, when e > e., > e-, these algebraic equations\nhave all their roots real. For the properties (ii) and (iii) shew\nthat, qua functions of B, the expressions h, b, b, ... b,. form a\nset of Sturm's functions* when r < (n + 3), and so the equation\n\nhas all its roots realf and unequal.\n\nHence, when the constants gj, e,, es are real (which is the case of\npractical importance, as was seen in \\hardsubsectionref{23}{3}{1}), there are ?i + 1 real\nand distinct values of B for which Lame's equation has a solution of\nthe type\n\ntbr( -e -'\n\nAvhen n is even; and there are (n+1) real and distinct values of B for\nwhich Lame's equation has a solution of the type\n\nwhen n is odd.\n\nWhen the constants ej, eo, e are not all real, it is possible for the\nequation satisfied by B to have equal roots; the solutions of Lame's\nequation in such cases have been discussed by Cohn in a Konigsberg\ndissertation (1888).\n\nExample 1. Discuss solutions of Lame's equation of the types \\ (i) ( -\niF i h; -e. -'--, ' .\n\nr=0\n\n*?l-r-J\n\n(ii) ( -e,) 2 V'd-eo) (iii) ( -e,) -e,)i I b;\" -e,) \"-'-\\\n\n* Mem. pr senUs par les Savans Etrangers, vi. (1835), pp. 271-318.\n\nt This procedure is due to Liouville, Journal de Math. xi. (1846), p.\n221.\n\n%\n% 558\n%\n\nohtainiug the recurrence relations\n\n(i) r n -r + h) W =- Se.-, hi - r + hf + ie -e ) h u - r + |) - n (n +\n1) 63 - i 6',.-i\n\n- (ei - 62) ( 2 - 63) hi -r + %) hi -r + l) 6V-2, (ii) r n-r + h)b,\" =\n3e., hn-r+hf- ei-e2) in-r + )- 7i 7i+l)e.,-iB\\ b\"r\\,\n\n- ei- 62) 62-63) n - r+ ) hi-r + l) b\",.\\ .i, (iii) r n-r + h)b;\" =\n3e2 n-r + h)--ke2 n' + n + l)- B b\"'r\\ i\n\n- ( 1 - eo) (62 - e-i) ih)i-r+l) l n -r + h) b\". \\ 2 . Example 2. With\nthe notation of example 1 shew that the numbers of real distinct\n\nvalues of B for which Lamp's equation is satisfied by terminating\nseries of the several species are\n\n(i) \\ \\ {n- ) or \\ \\ {n-2); (ii) \\ \\ {n- ) ov h n-9.); (iii) n-2) or h\nn-Z).\n\n2342. The definition of \\Lame\\ functions.\n\nWhen we collect the results which have been obtained in \\hardsubsectionref{23}{4}{1}, it is\nclear that, given the equation\n\nn being a positive integer, there are 2n + 1 values of B for which the\nequation has a solution of one or other of the four species described\nin §§ 23\"21-23'24.\n\nIf, when such a solution is expanded in descending powers of, the\ncoefficient of the leading term | \" is taken to be unity, as was done\nin § 2341, the function so obtained is called a \\Lame\\ function of\ndegree n, of the first kind, of the first (second, third or fourth)\nspecies. The 2n + 1 functions so obtained are denoted by the symbol\n\nE, - ); (m = l, 2, ...2 + l).\n\nand, when we have to deal with only one such function, it may be\ndenoted by the symbol\n\nTables of the expressions representing \\Lame\\ functions for ?i = l, 2,\n...10 have been compiled by Guerritore, Giornale di Mat. (2) xvi.\n(1909), pp. 164-172.\n\nExample 1. Obtain the five \\Lame\\ functions of degree 2, namely\n\nV(X + i-)v/(X + c2), v/(X + c2) /(X + a2), v'(X + -)V(X + n Example 2.\nObtain the seven \\Lame\\ functions of degree 3, namely - V (X + a' )(X +\n\\&'')(X4-c2), and six functions obtained by interchanges of a, b, c\nin the expressions\n\nv'(X + a-') . [X + 1 (a2 + 262 + .2c') ± I J a* + ib* + 4c* - 76V-' -\nf' a \\ a'b ].\n\n\\Subsection{23}{4}{3}{27te non-repetition of factors in \\Lame\\ functions.}\n\nIt will now be shewn that all the rational linear factors of \"' (|)\nare unequal. This result follows most simply from the differential\nequation which - n™ (?) satisfies; for, if | - ?i be any factor of\n'\"(|), where |i is not one of\n\n%\n% 559\n%\n\nthe numbers gj, eo or 63, then fj is a regular point of the equation\n(§ 10\"H), and any solution of the equation which, when expanded in\npowers of f - 1, does not begin with a term in ( - 1)° or ( - Y must\nbe identically zero.\n\nAgain, if |i were one of the numbers gj, 63 or s. the indicial\nequation appropriate to 1 would have the roots and J, and so the\nexpansion of En\"' ( ) in ascending powers of 1 would begin with a term\nin (f - j)\" or\n\nHence, in no circumstances has,i'\"( ), g'wa function of, a repeated\nfactor.\n\nThe determination of the numbers 0, 6.2, ... 0 introduced in §§\n23-21- 23*24 may now be regarded as complete; for it has been seen\nthat solutions of Lame's equation can be constructed with non-repeated\nfactors, and the values of 0, 62, ... which correspond to the roots\nof En ( ) = satisfy the equations which are requisite to ensure that\nNiven's products are solutions of Laplace's equation.\n\nIt still remains to be shewn that the '2n + 1 ellipsoidal harmonics\ncon- structed in this way form a fundamental system of solutions of\ndegree 71 of Laplace's equation.\n\n\\Subsection{23}{4}{4}{The linear independence of \\Lame\\ functions.}\n\nIt will now be shewn that the 2n -i- 1 \\Lame\\ functions E)/ ) which are\nof degree n are linearly independent, that is to say that no linear\nrelation can exist which connects them identically for general values\nof .\n\nIn the first j)lace, if such a linear relation existed in which\nfunctions of different species were involved, it is obvious that by\nsuitable changes of signs of the radicals \\/( - i), \\/( - 2), \\/(f -\ns) we could obtain other relations which, on being combined by\naddition or subtraction with the original relation, would give rise to\ntwo (or more) linear relations each of which involved functions\nrestricted not merely to be of the same species but also of the same\ntype.\n\nLet one of these latter relations, if it exists, be\n\nand let this relation involve r of the functions.\n\nOperate on this identity 7 - 1 times with the operator\n\nThe results of the successive operations are\n\nta,, Bn'-y Err )=0 (5 = 1, 2, ... r - 1), where Bn' is the particular\nvalue of jB which is associated with E \"- ).\n\n%\n% 560\n%\n\nEliminate a-, iu, ... a,, from the r equations now obtained; and it\nis found\n\nthat\n\n1, 1, 1, ... 1 =0.\n\n! R 1 R i R 3 Tl r\n\n Dii, J->n, -'-'71 >  -'-'(!\n\n B, y-\\ B,;r-\\ (B/y-'\n\nNow the only factors of the determinant on the left are differences of\nthe numbers 5 '\", and these differences cannot vanish, by \\hardsubsectionref{23}{4}{1}.\nHence the determinant cannot vanish and so the postulated relation\ndoes not exist.\n\nThe linear independence of the 2m +1 \\Lame\\ functions of degree n is\ntherefore established.\n\n2345. The linear independence of ellipsoidal harmonics.\n\nLet Gn', y, z) be the ellipsoidal harmonic of degree n associated\nwith E, ( ), and let T,/\" (cc, y, z) be the corresponding homogeneous\nharmonic.\n\nIt is now easy to shew that not only are the 2?? + 1 harmonics of the\ntype Gn\" (, y, z) linearly independent, but also the 2?; + 1\nharmonics of the type Hn'' x, y, z) are linearly independent.\n\nIn the first place, if a linear relation existed between harmonics of\nthe type Gn'\" oc, y, z). then, when we expressed these harmonics in\nterms of con- focal coordinates X, /x, v), we should obtain a linear\nrelation between \\Lame\\ functions of the type En' i ) where =X+ a- + b-+\nc\"), and it has been seen that no such relation exists.\n\nAgain, if a linear relation existed between homogeneous harmonics of\nthe type Hn ' x, y, z), by operating on the relation with Niven's\noperator\n\n\\hardsubsectionref{23}{2}{5}),\n\n  D\\\n\n2 (2n - T) \" 2.4 (2 - 1 ) 2n- 3) ' \" '\n\nwe should obtain a linear relation connecting functions of the type\n(z,/'' x, y, z), and since it has just been seen that no such relation\nexists, it follows that the homogeneous harmonics of degree n are\nlinearly independent.\n\n2346. Stieltjes' theorem on the zeros of \\Lame\\ functions.\n\nIt has been seen that any Lam6 function of degree n is expressible in\nthe form\n\nm\n\n(6 + a'Y' (d + h- r (0 + cy .u d- dp),\n\n;> = 1\n\nwhere i, k, k- are equal to or and the numbers 6, 6., ... 6, are\nreal and unequal both to each other and to - a, - b, - c-; and n =\nni + Ki + Kn + k . When /cj, /Co, Ks are given the number of Lame\nfunctions of this degi-ee and type is ru + 1.\n\n%\n% 561\n%\n\nThe remai'kable result has been proved by Stieltjes* that these w + 1\nfunctions can be arranged in order in such a way that the rth function\nof the set has r - 1 of its zeros f between - a and - h- and the\nremaining m - r + 1 of its eros between - 6- and - c and,\nincidentally, that, for all the 7?i + 1 functions, 6-, 6.2, ... 0 lie\nbetween - a- and - c-.\n\nTo prove this result, let 0j, 2;  4 m be any real variables such\nthat\n\n(- a- (jip - h, (p - 1,2,...') - 1)\n\n[-h\" ( )p - c (p = r,r+l,... m) and consider the product\n\n ' J- 4-1 a.1\n\n11 = n [| ((/>p +aO T'+i . i (</),. + h\"-) r -'i . j (< + c ) i;3+4] n\n] (c/> - <,) |.\n\np=l pdpq\n\nThis product is zero when all the variables 0 have their least values\nand also when all have their greatest values; when the variables p\nare unequal both to each other and to - a-, - If, - c\", then IT is\npositive and it is obviously a continuous bounded function of the\nvariables.\n\nHence there is a set of values of the variables for which 11 attains\nits upper bound, which is positive and not zero (cf \\hardsubsectionref{3}{6}{2}).\n\nFor this set of values of the variables the conditions for a maximum\ngive\n\neiogn \\ a log n \\\n\nthat is to say\n\n111\n\nfCi + -r Ko + T ' 3 + T\n\n4 \\ 4 4 ', 1 \\\n\n<f)p + a <f>p + 6 cf)p + c- fjli <j>p - (j),i\n\nwhere p assumes in turn the values 1, 2, ... m.\n\nNow this system of equations is precisely the system by which 6, 6,\n... 6 are determined (cf \\hardsubsectionref{23}{2}{1}-23'24); and so the system of\nequations determining Oi, 02, ... dm has a solution for which\n\nj-a'<dp<-b% (p = l,2, ...r-1)\n\n - b\"< dp < - C-. (jo = ?',?+ 1, ... to)\n\nHence, if r has any of the values 1, 2, ... m + 1, a \\Lame\\ function\nexists with r - 1 of its zeros between - a and - h\" and the remaining\nvi - ? + 1 zeros between - h- and - c'-.\n\nSince there are m + 1 \\Lame\\ functions of the specified type, they are\nall obtained when r is given in turn the values 1, 2, ... to + 1; and\nthis is the theorem due to Stieltjes.\n\n* Acta Mathematica, \\ i. (1885), pp. 321-326.\n\nt The zeros -a', -b, - c are to be omitted from this enumeration, 6\n, d., ..., only being taken into account.\n\nW. M. A. 36\n\n%\n% 562\n%\n\nAn interesting statical interpretation of the theorem was given by\nStieltjcs, namely that if wi +3 particles which attract one another\naccording to the law of the inverse distance\n\nare placed on a line, and three of these particles, whose masses are\nKi + -r, f2+ > ''s + ti '\n\nfixed at points with coordinates -a-, -b-, -c, the remainder being of\nunit mass and free to move on the line, then log n is the\ngravitational potential of the system; and the positions of\nequilibrium of the system are those in which the coordinates of the\nmoveable particles are 61,6-2, ... 6, i-e. the values of 6 for which\na certain one of the \\Lame\\ functions of degree 2 m + ki + K2 + <z)\nvanishes.\n\nExample. Discuss the positions of the zeros of polynomials which\nsatisfy an equation of the type\n\nd6' \"* rti e-a, d6 * ',, ~ '\n\nn 6-a,)\n\ns = l\n\nwhere (f)r-2 6) is a polynomial of degree r - 2 in 6 in which the\ncoefficient of 6 ~- is\n\nr\n\n- m m + r - 1 - 2 a, .-=1\n\nm being a positive integer, and the remaining coefficients in <f>r-2\n6) are determined from\n\nthe consideration that the equation has a polynomial solution.\n\n\\addexamplecitation{Stieltjes.}\n\n\\Subsection{23}{4}{7}{\\Lame\\ functions of the second kind.}\n\nThe functions En ( ), hitherto discussed, are known as \\Lame\\ functions\nof the first kind. It is easy to verify that an independent solution\nof Lame's equation\n\ndu- '\n\nis the function i,i'\" ( ) defined by the equation*\n\n/ .. (f) = (2 H-l) '\"(f)/;jj;,\n\nand i,i'\" (1 ) is termed a Lam6 function of the second kind. From\nthis formula it is clear that, near u = 0,\n\nF ( ) = (271 + 1) u- 1 + (lOl I \" u-'' 1+0 u)] du = u''+' 1 + (u)],\n\nJo and we obviously have\n\nE,r ) = u-[l + 0 u)].\n\nIt is clear from these results that Fn\" (|) can never be a Lame\nfunction of the first kind, and so there is no value of Bn\" for luhich\nLame's equation is satisfied by two \\Lame\\ functions of the first kind\nof different species or types.\n\nIt is possible to obtain an expression for Fn'\\ \\ ) which is free from\nquadratures, analogous to Christoffel's formula for Qni ), given on p.\n333, example 29. We shall give the analysis in the case when En\" (|)\nis of the first species. The only irreducible poles of l/,j\"'( )j qua\nfunction of u, are at a set of points u, u.,, ... Un which are none\nof them periods or half periods.\n\n* This definitiou of the function i<' '\" (4) is due to Heine, Journal\nfUr Math. xxix. (1845), p. 194.\n\n%\n% 563\n%\n\nNear any one of these points we have an expansion of the form\n\nEn'\" (I) = /.-i U - Ur) + h (W - Urf + '3 u - U,) + ...,\n\nand, by substitution of this series in the differential equation, it\nis found that 2 is zero.\n\nHence the principal part of l/ £'n\"* ) near iir is\n\n1\n\nk]- (u - Uff ' and the residue is zero.\n\nHence we can find constants Ar such that\n\n E,r( yr- I Ario(u-u,.)\n\nr = l\n\nhas no poles at any points congruent to any of the points iif; it is\ntherefore a constant A, by Liouville's theorem, since it is a doubly\nperiodic function of M.\n\nfit dn n\n\nNow the points Uf can be grouped in pairs whose sum is zero, since Ey\n(I) is an even function of u.\n\nIf we take iin-,- = - '';+i, we have\n\n--~--: = Au- 2 Ar u-Ur) + K u + U>)] Jo i n g)i r = l\n\n= AlC - 2 u) t Ar-t - ff' ''],\n\nr=l r = lip y-)- Ur)\n\nand therefore\n\n? = !\n\nwhere '?< i,j\\ i(| ) is a polj nomial in | of degree n - 1.\n\nExample. Obtain formulae analogous to this expression for i, ™ ) when\nE, ( ) is of the second, third or fourth species.\n\n\\Section{23}{5}{\\Lame's equation in association with Jacobian elliptic functions.}\n\nAll the results \\ Yhich have so far been obtained in connexion with\nLame functions of course have their analogues in the notation of\nJacobian elliptic functions, and, in the hands of Hermite (cf.\\hardsectionref{23}{7}\n1), the use of Jacobian elliptic functions in the discussion of\ngeneralisations of Lame's equation has produced extremely interesting\nresults.\n\nUnfortunately it is not possible to use Jacobian elliptic functions in\nwhich all the variables involved are real, without a loss of symmetry.\n\n36-2\n\n%\n% 564\n%\n\nand then the formulae of\n\nX =\n\nThe symmetrical formulae may be obtained by taking new variables a,\n/3, . 7 defined by the equations\n\nfa = iK' + u V(ei - e- ),\n\n1 7 = iK' + w V(ei - e-,), 23\"31 are equivalent to A;- \\/ a~ - c\") .\nsn a sn /3 sn 7, y - - (f -/k') V(ft\" - C-) . en a en en 7, \\ z =\nijk') \\/(a- - C-) . dn a dn /8 dn 7, the modulus of the elliptic\nfunctions being\n\nV W-cV-\n\nThe equation of the quadric of the confocal system on which a is con-\nstant is\n\nX' Y Z-\n\n(a2-62)sn2a (a - b') cn a ~ (a - c-) dn\" a ~ \" This is an ellipsoid if\na lies between iK' and K + iK'; the quadric on which yS is constant\nis an hyperboloid of one sheet if lies between K + iK' and -fir; and\nthe quadric on which 7 is constant is an hyperboloid of two sheets if\n7 lies between and K; and with this determination of (a,, 7) the\npoint x, y, z) lies in the positive octant.\n\nIt has already been seen \\hardsectionref{23}{4}) that, with this notation, Lame's\nequation assumes the form\n\n--T-v = n + 1 ) A,'- sn- a + A] A,\n\nand the solutions expressible as periodic functions of a will be\ncalled* -£ '\" (a). The first species of Lame' function is then a\npolynomial in sn a, and generally the species may be defined by a\nscheme analogous to that of \\hardsectionref{23}{2}, sn a, en a dn a,\n\n1, en or, dnasna, sn a en a dn a dn a, sn a en a,,\n\nn (sn- oc - sn-Qp). J\n\n\\Section{23}{6}{The integral equation satisfied by \\Lame\\ functions of the first and second species'.}\n\nWe shall now shew that, if En' (a) is any Lamd function of the first\nspecies (n being even) or of the second species (n being odd) with sn\na as a\n\n* There is no risk of confusing these with the corresponding functions\ni-'/' (t).\n\nt This integral equation and the corresponding formulae of § 28 -62\nassociated with ellipsoidal harmonics were given by Whittaker, Froc.\nLondon Math.- Soc. (2) xiv. (1915), pp. 260-268. Proofs of the\nformulae involving functions of the third and fourth species have not\nbeen previously published.\n\n%\n% 565\n%\n\nfactor, then E '\"'(a) is a solution of the integral equation\n\nE,r ( ) = X Pn (k sn a sn 6) E,r (0) dd;\n\nJ -2K\n\nwhere \\ is one of the 'characteristic numbers' \\hardsubsectionref{11}{2}{3}).\n\nTo establish this result we need the lemma that P,i (A: sn a sn ) is\nannihilated by the partial differential operator\n\n3 2 - 9 - \" ( + 1) '' (sn' a - sn d).\n\nTo prove the lemma, observe that, when /x is written for brevity in\nplace of k sn a sn 0, we have\n\n a|- i ' '-'\"\"'' >\n\n= k- (en- a dn- a sn- 6 - en- 6 dn- 6 sn- a] Pn\" (/i)\n\n+ k\" sn a sn (sn a - sn 0) P,,' (/x) = k' (sn a - sn 6) [(fj, - - 1 )\nP,/' C/.) + 2/iP,/ ( )] = 2 (sn- a - sn 6) n (n + l) P (jj,),\n\nwhen we use Legendre's differential equation \\hardsubsectionref{16}{1}{3}). And the lemma\nis established.\n\nThe result of applying the operator\n\n 2 - n (n + l)k\"sn-oc-A '\n\nto the integi'al\n\nr2K\n\nPn (k sn a sn 6) E T (0) dO\n\nJ ~2K\n\nis now seen to be\n\n\\ - -n n + l) k' sn a - .4,,' [ P (k sn a sn 6) E \" (6) dO J -2K (ca\n)\n\n= \\, \\ \\ .- n + ) k-s,n e-AyvPn k nasne) and when we integrate twice\nby parts this becomes\n\nE,r e)dd,\n\n-B PAfcsnasnB) \\ dE e)\n\n2K \\ -2K\n\n+ j Pn ( n asn d) Uj,- n (n + 1) k' sn' d - A . [ En'\"\" d) .dd = 0.\n\nHence it follows that the integral riK\n\nPn (k sn a sn 6) En\"\" (0) d9\n\nJ -2K *\n\nis annihilated by the operator\n\nd\n\nT- 2 - n n + l)k sn- a - J.,l\"\n\n%\n% 566\n%\n\nand it is evidently a polynomial of degree n in sn- a. Since Lame's\nequation has onlj' one integral of this type*, it follows that the\nintegral is a multiple of En ' (a) if it is not zero; and the result\nis established.\n\nIt does not appear to have been proved that the only vahies of A, for\nwhich the equation\n\nf a) = \\ [\" J\\ \\ {kHnaKn6)f 6)dd\n\nhas a solution, are those which make/(o) a solution of Lame's\nequation.\n\nExample 1. Shew that the nucleus of an integral equation satisfied by\nLame functions of the first species n being even) or of the second\nspecies n being odd) with en a as a factor, may be taken to be\n\n/  (-p en a en 6\n\nExample 2. Shew that the nucleus of an integral equation satisfied by\nLame functions of the first species (?i being even) or of the second\nspecies n being odd) with dn a as a factor, may be taken to be\n\nP Ypdnadn y\n\n\\Subsection{23}{6}{1}{The integral equation satisfied by \\Lame\\\n  functions of the third and fourth species.}\n\nThe theorem analogous to that of \\hardsectionref{23}{6}, in the case of \\Lame\\ functions\nof the third and fourth species, is that any \\Lame\\ function of the\nfourth species (n being odd) or of the third species (n being even)\nwith en a dn a as a factor,, satisfies the integral equation r2K E,r\n(a) = X en a dn a en 6 dn dPn' k sn a sn 6) E/'' (0) dO.\n\nJ -2 A'\n\nThe preliminary lemma is that the nucleus\n\nen a dn a en d dn dPn' k sn a sn 6), like the nucleus of \\hardsectionref{23}{6}, is\nannihilated by the operator\n\nTT-, - -, - n n + l) A'- (sn- a - sn- 6). dot- ctf-\n\nTo verify the lemma observe that\n\n| JcnadnaP/(/ snasn )\n\n= k- cn ' a dn'' a sn- PJ'' (/u.) - 3 - sn a en a dn a sn (dn- a + k'\nen- a) Pn\" (fi) - en a dn a (dn- a + k- en- a - 4k' sn\" a) Pn\" (fi),\nand so\n\n. \\ I . (en a dn a en dn 6Pn k sn a sn 0)\\\n\n= kcnadnacne dn 6 (sn a - sn' 0) (,x'' - 1 ) PJ \" (/i) -f GfxPn\" ( ) +\nGPn\" (/*)]\n\nd = k- en a dn a en dn (sn- a - sn- ) 3 (m-' - 1) Pv/ (a )\n\n= k- n n + 1 ) en a dn o£ en 6 dn 6 (sn- a. - sn'- 6) Pn\" (/a),\n\n* The other solution when expanded in descending powers of sn a begins\nwith a term in (sn a)- - .\n\n%\n% 567\n%\n\nand the lemma is established. The proof that En (a) satisfies the\nintegral equation now follows precisely as in the case of the integral\nequation of \\hardsectionref{23}{6}.\n\nExample 1. Shew that the nucleus of an integral equation which is\nsatisfied by \\Lame\\ functions of the fourth species ( being odd) or of\nthe third species ii being even) with sn a dn a as a factor, may be\ntaken to be\n\nsn a dn a sn 6 dn 6 P \" ( -77 en a en ) .\n\nExample 2. Shew that the nucleus of an integral equation which is\nsatisfied by \\Lame\\ functions of the fourth species ii being odd) or of\nthe third species (/i being even) with sn a en a as a factor, may be\ntaken ta be\n\nsn a en a sn 6 en 6P,l' j, dn a dn | .\n\nExample 3. Obtain the following three integral equations satisfied by\nLame functions of the fourth species n being odd) and of the third\nspecies (?i being even) :\n\n(i) k\" ..'- a E.r ( ) -X c,. dn / P. (i. ., sn ) jjJj '- ] M, (ii) -i\nc =,.i.V'W = -.,n d / P,.(fcn c ) - / > o(,\n\n(iii) I.-' in' a Er M = Xr- s a c / i>. Q. dn dn ) J ™ M;\n\nin the case of functions of even ordei-, the functions of the\ndifferent types each satisfy one of these equations only.\n\n\\Subsection{23}{6}{2}{Integral formulae for ellipsoidal harmonics.}\n\nThe integral equations just considered make it possible to obtain\nelegant representations of the ellipsoidal harmonic Gn x, y, z) and of\nthe corre- sponding homogeneous harmonic H x, y, z) in terms of\ndefinite integrals.\n\nFrom the general equation formula of \\hardsectionref{18}{3}, it is evident that Hn x,\ny, z) is expressible in the form\n\nHn''' (x, y,z)= I (x cost + y sin t + izTf(t) dt,\n\nJ -TV\n\nwhere y( ) is a periodic function to be determined.\n\nNow the result of applying Niven's operator D- to x cos t + y sin t +\nt )\" is\n\nn (n - 1 ) (a- cos\"- 1 + b'- sin t - c'-) (x cos t + y sin t + izy ~,\n\nand so, by Niven's formula \\hardsubsectionref{23}{2}{5}) we find that Gn\" x, y, s) is\nexpressible in the form\n\nn n-l)(n-2)(n-S) )\n\n+ 2.4(2n-l)(2u-3) '  / t)at,\n\n%\n% 568\n%\n\nwhere * l = xcost + y sin t + is,\n\n  = V ( ' - C-) cos- t + b-- C-) sin t], so that\n\nNow write sin = cd, the modulus of the elliptic functions being, as\nusual, given by the equation\n\n, \\ tt\" - b' a- - C-\n\nThe new limits of integration are - K and K, but they may be replaced\nby - 'IK and 'IK on account of the periodicity of the integrand.\n\nIt is thus found that\n\n - T / 'a;sn + ycn + >dn \\ .\n\ne \" ( . y, ) = j\\ . i ( :j \\ - j > ( ) ''<'.\n\nwhere ( ( ) is a periodic function of 6, independent of x, y, z, which\nis, as yet, to be determined.\n\nIf we express the ellipsoidal harmonic as the product of three Lame\nfunctions, with the aid of the formulae of § 235 we find that\n\nrlK\n\nE (a) E,r (/3) E,r l)=G\\ Pa (/x) < (0) dO,\n\nJ -2A\"\n\nwhere C is a known constant and\n\n/x = k- sn a sn /3 sn 7 sn - k-/k'-) en a en /? en 7 en\n\n- (l/'k'-) dn a dn y8 dn 7 dn 6.\n\nIf the ellipsoidal harmonic is of the first species or of the second\nspecies and first type, we now give /3 and 7 the special values\n\n  = K, y = K + iK', and we see that\n\nC [' Pn(ksnasnd)(f3 e)(W\n\nJ -2 A'\n\nis a solution of Lame's equation, and so, by \\hardsectionref{23}{6}, ( ) is a solution\nof Lame's equation which can be no other* than a multiple of E,i'\"\n(6).\n\nHence it follows that\n\nl\"- T. /'k'x sn0+ u en \\$ + iz dn \\,,, 7\n\nwhere X is a constant.\n\n* If (p e) involved the second solution, the integral would not\nconverge.\n\n%\n% 569\n%\n\nIf Gn!\" x, y, z) be of the second species and of the second or third\ntype\n\nwe put\n\n/3 = 0, 7 = iiT + iK',\n\nor /3 = 0, 7 = /i\n\nrespectively, and we obtain anew the same formula.\n\nIt thus follows that if (th'\" x, y, z) be any ellipsoidal harmonic of\nthe first or second species, then\n\nGrT oo, y,z) = \\ f \"\" Pn (/ ) E,i- 6) cie,\n\nJ -2 A'\n\n  '(x, y, z) = X. ' r r ( ' sn + 3/ en 6? + iz dn df En''' (0) dd,\n\nwhere [x = (k'x sn6 + y end + iz dn d)/\\/ b- - c\").\n\n\\Subsection{23}{6}{3}{I nteg7'al formulae for ellipsoidal harmonics of the third and fom th species.}\n\nIn order to obtain integral expressions for harmonics of the third and\nfourth species, we turn to the equation of \\hardsubsectionref{23}{6}{2}, namely\n\n£,' (a) En'- (/8) En - (7) = C r Pn (yu) cf> (0) d0,\n\nJ -iK\n\nwhere\n\nfi = A; sn a sn /3 sn 7 sn - k-/k'-) en a en /3 en 7 en - (l/k'-) dn a\ndn /S dn 7 dn;\n\nthis equation is satisfied by harmonics of any species.\n\nSuppose now that £'/' (a) is of the fourth species or of the first\ntype of the third species so that it has en a dn a as a factor.\n\nWe next differentiate the equation with respect to /3 and 7, and then\nput = K,y = K + iK'.\n\nIt is thus found that d\n\nEn' ict)\n\nd/3\n\nEn'\"( )\n\ni.-=A-L 7\n\nV = A'+iA\"\n\n= C'\n\n2A\n\nNow SO that\n\ndPn(f )\n\n\\ 87 \\\n\nK L ?/3S7 .\n\n(? = K, y = K+iK'\n\n(0) d0.\n\ny = A'+?A''\n\n- ilk') dn a dn /S dn 0Pn (/x),\n\nd dy J =K,y=K+iK\n\n:')\n\n= - en a dn a en dn 0Pn\" (k sn a sn 0).\n\nHence\n\nr\n\nJ -2A\n\nen a dn a en dn 0Pn\" (k sn a sn ) ( (0) d0\n\nis a solution of Lame's equation with en a dn a as a factor; and so,\nby \\hardsubsectionref{23}{6}{1}, (ji (0) can he none other than a constant multiple of.E -\n(a).\n\n%\n% 570\n%\n\nWe have thus found that the equation\n\nG,r oc, y,z) = \\ \\ Pn (fi) E,r (0) (le\n\nJ -IK\n\nis satisfied by any ellipsoidal harmonic which has en a dn a as a\nfactor; the corresponding formula for the homogeneous harmonic is\n\nHn'\" (x, XL z) = \\ J- I ( /. ' X sn e- xi en 6 + t>dn ) E. iO) dd.\n\nExample. Shew that the equation of this section is satisfied by the\nellipsoidal harmonics which have sn a dn a or sn a en a as a factor.\n\n\\Section{23}{7}{Generalisations of \\Lame's equation.}\n\nTwo obvious generalisations of Lame's equation at once suggest them-\nselves. In the first, the constant B has net one of the characteristic\nvalues Bn, for which a solution is expressible as an algebraic\nfunction of f u); and in the second, the degree n is no longer\nsupposed to be an integer. The first generalisation has been fully\ndealt with by Hermite* and Halphenf, but the only case of the second\nwhich has received any attention is that in which n is half of an odd\ninteger; this has been discussed by Brioschij, Halphen§ and Crawford\nII .\n\nWe shall now examine the solution of the equation\n\n \\ = [n n + l) io u) - B] i\\,\n\nwhere B is arbitrary and n is a positive integer, by the method of\nLindemann- Stieltjes already explained in connexion with Mathieu's\nequation (§§ 19'5- 19-52).\n\nThe product of any pair of solutions of this equation is a solution of\n\n'~ ' ' + \" \" + S ~ -\" ' + '' '' = ' by \\hardsubsectionref{19}{5}{2}. The algebraic form of\nthis equation is\n\n4 ( - e,) (I - e,) ( \\ .3) + 3 (6 - i,) '\n\n- 4 ( 2 + - 3) + i l - -In (;i + 1 ) X = 0. If a solution of this in\ndescending powers of - go be taken to be\n\n* Comptes liendus, lxxxv. (1877), pp. ti89-(;95, 728-732, 821-826.\n\nt Fonctions Elliptiques, 11. (Paris, 1888), pp. 494-502.\n\n:J: Comptes Remlus, i.xxxvi. (1878), pp. 313-315.\n\n§ Fonctions Elliptiques, ii. (Paris, 1888), pp. 471-473.\n\nII Quarterly Journal, xxvii. (1895), pp. 93-98.\n\n%\n% 571\n%\n\nthe recurrence formula for the coefficients c,. is\n\n4r (n, - r + I) (2/1 - ? + 1) Cr\n\n= ( ?i - r + 1) 12e (n - r) (n - r + 2) - 4eo (n- + n - 3) - 4J5 c,\\ i\n- 2 (n - r + ] ) (n - r + 2) (ei - e ) (e. - 63) (2h - 2r + 3) c,\\ 2.\n\nWrite r = 71 4- 1, and it is seen that Cn+i =; then write r = n + 2\nand Cn+2 =; and the recurrence formulae with r > n + 2 are all\nsatisfied by taking\n\nHence Lame's generalised equation always has two solutions tuhose\nproduct is of the form\n\n2c,( -e,)-'-.\n\nr=0\n\nThis polynomial may be written in the form\n\nn\n\nn j(w)-\\&>( r)l>\n\nwhere i, a, ... a are, as yet, undetermined as to their signs; and\nthe two solutions of Lame's equation will be called Aj, A,.\n\nTwo cases arise, (I) when A1/A2 is constant, (II) when Aj/A is not\nconstant.\n\n(I) The first case is easily disposed of; for unless the polynomial\n\nr = l\n\nis a perfect square in, multiplied possibly by expressions of the\ntype - e, - 2, - 63, then the algebraic form of Lame's equation has\nan indicial equation, one of whose roots is |, at one or more of the\npoints | = i> (a,-); and this is not the case \\hardsubsectionref{23}{4}{3}).\n\nHence the polynomial must be a square multiplied possibly by one or\nmore of - e, - 62, - e-s, and then Aj is a \\Lame\\ function, so that B\nhas one of the characteristic values 5,/\"; and this is the case which\nhas been discussed at length in §§ 23-1-23-47.\n\n(II) In the second case we have \\hardsubsectionref{19}{5}{3})\n\ndu ' du\n\nwhere S is a constant which is not zero. Then\n\nd log A2 d log Ai \\ 26 du du X\n\nd log A2 d log Ai \\ 1 dX du du X du\n\nrf log A, \\ 1 dX 6 c logA a 1 dX 6 so that - 2 X ' du 2X du X -\n\n%\n% 572\n%\n\nOn integration, \"sve see that Ave may take\n\nA, = VXexp|-(>[~|. Again, if we differentiate the equation\n\n[chap. XXIII\n\nwe find that\n\n1 dA,\\ 1 dX (i Ai du ~ '2X du X '\n\n1 d'A, 1 dA,\\ \\ 1 d'X 1 fdXy g dX\n\nA, dir- ( Ai du \\ 2X dti? 2X' \\ du ) X du '\n\nand hence, with the aid of Lame's equation, we obtain the interesting\nformula\n\nIf now,. = jf) a,), we find from this formula (when multiplied by\nX-), that, \\ i u be given the special value cir, then\n\n'dXV\n\nm-\n\nWe now fix the signs of aj, an, ... cin by taking 'dX\\ 2g\n\nfdX\\ \\ 2(\n\n( .)\n\nAnd then, if we put 26/X, g-ita function of |, into partial fractions,\nit is seen that\n\n2(J (a' (n \\ '\n\nand therefore\nTODO\nwhence it\nfollows that \\hardsubsectionref{20}{5}{3}, example 1)\n\nAi= n\n\na- (ar + -m)\n\n;x[exp|-?t 2 (a,)|,\n\nand\n\nr=l lO\" (z<) (7 (a,\n\n 2= n I - J-exp|M 2 ?(a,.)h\n\n,.=1 |o-(iOo-(a,) =1 '\n\nThe complete solution has therefore been obtained for arbitrary values\nof the constant B.\n\n%\n% 573\n%\n\n\\Subsection{23}{7}{1}{The Jacobian form of the generalised \\Lame\\ equation.}\nWe shall\nnow construct the solution of the equation\n\n-- = [n n + 1) k' sn a + A,\n\nfor general values of A, in a form resembling that of \\hardsectionref{23}{6}.\n\nThe solution which corresponds to that of \\hardsectionref{23}{6} is seen to be*\n\nwhere p, a, a, ...cun are constants to be determined. On\ndifferentiating this equation it is seen that\n\nAda,-=i|H(a + a,) B\\ a)\\ \\\n\nn\n\n= X Z (a + a, + iK') - Z (a) + p + \\ mrilK,\n\nr=l, 1 C A (1 dA, 1 .w -rr i,,\n\n   ' A - JA 1 = .-X \"\" \" + ° + - ' \" \"\"\n\nand therefore, since A is a solution of Lame's equation, the constants\np, a, Oo, ... a,i are to be determined from the consideration that\nthe equation\n\n2 Z(a + ar+ iK') - Z a ] -f p + niri/K\n\nr = l\n\nn n + 1) k- sn- a - A = X dn- (a + a,- + iK') - dn- a\n\nr=l\n\n+ is to be an identity; that is to say\n\nn\n\nn'k\" sn- a + 71 + A + 2 cs-(a + a,-)\n\n2 Z (a + a, + t7f ') - Z (a)] + p + mrilK\n\nr=l\n\nNow both sides of the proposed identity are doubly periodic functions\nof a with periods 2K, 2iK', and their singularities are double poles\nat points congruent to -iK', - Qi, - a.,, ... - a; the dominant terms\nnear -iK' and -;. are respectively\n\nn- 1\n\n(a+TKy ' ~ (a + arf\n\nin the case of each of the expressions under consideration.\n\nThe residues of the expression on the left are all zero and so, if we\nchoose p, !, Ko, ... On SO that the residues of the expression on the\nright are zero,\n\n* This solution was published in 1872 in Hermite's lithographed notes\nof his lectures delivered at the Ecole polytechnique.\n\n%\n% 574\n%\n\nit will follow from Liouville's theorem that the two expressions\ndiffer by a constant which can be made to vanish by proper choice of\nA.\n\nWe thus obtain n+ 2 equations connecting p, a, a.., ... a,,, with A,\nbut these equations are not all independent.\n\nIt is easy to prove that, near - o,\n\n2 Z a + a, + iK') - Z a)\\ + p + i iri/K\n\nr=l\n\n= - + I' Z (Op - a, + Hi') + nZ (a,) + p + i (n - 1) -nilK + (a +\na,-), where the prime denotes that the term for which jj = ?' is\nomitted; and, near\n\nI [Z (a + a, + iK') - Z (a)] + p + i n-ni\\ K\n\nr = \\\n\n= + i Z(,) + p+0(a+27r).\n\nft + til >. = !\n\nHence the residues of\n\ni Z (a + a, + i7i ') - Z (a) + p + | ??.7rt7A\" will all vanish if p,\na,, a., ... ft are chosen so that the equations ' i' Z (ft,, - ft, +\niK') + '/iZ (ft,) + p + ( - 1) 7r?:/ii = 0,\n\nI Z(a,) + P = V -=1\n\nare all satisfied.\n\nThe last equation merely gives the value of p, namely\n\n- 2 Z (ft,),\n\nand, when we substitute this value in the first system, we find that\n\n2' [Z (ftp - ft, -f- iK') + Z (ft,) - Z (a,,) + t TTzyZ] = 0,\n\nwhere r = 1, 2, ... n. By \\hardsubsubsectionref{22}{7}{3}{5}, example 2, the sum of the\nleft-hand sides of these equations is zero, so they are equivalent to\nn - 1 equations at most; and, when i, a.,, ... a have any values\nwhich satisfy them, the difference\n\n7t-A''- sn- a + ?i + -4 + 51 cs- ( + ft;-)\n\nS |Z (ft + ft, + IK') - Z (ft) - Z (ft,) + \\ irijK\\\n\n%\n% 575\n%\n\nis constant. By taking a = 0, it is seen that the constant is zero if\n\nn + A + S cs- Of,. =\n\nr = l\n\n2 [Z (a, + iK') - Z (a,) + Tri/K]\n\n) = !\n\ni.e. if \\ S en Of,, ds cif,.[- - 2 ns- ot,. = .\n\nij-=l j r=l\n\nWe now reduce the system of n equations; with the notation of § 22\n'2, if functions of Op, a,, be denoted by the suffixes 1 and 2, it is\neasy to see that\n\nZ up -ar + iK') + Z (a,) - Z (op) + Tri'/A'\n\n= Z (a - Or + iK') + Z(ar) -Z ap + iK') + Cj 0?i /Si = k' sn (op +\niK') sn a sn (ap + iX' - o ) + Ci ci?i /si\n\n 2\n\n+\n\nCidi\n\nSj sn (op- n,.) Si\n\n\\ SiCiO?i+g2C2C 2 ~ V- 2\n\nConsequently a solution of Lame's equation\n\n-- -= 71. (n + l) -sn-a+ A] A act- I '\n\nIS\n\nA= n\n\n@( ) exp-aZ(a,)\n\nprovided that !, a2>  n be chosen to satisfy the n independent\nequations comprised in the system\n\n/, sn ttp en ttp dn ctp + sn of en o dn;. \\\n\nI J i sn Op - sn ar\n\n2 en ttr ds a,.\n\n2 ns a,. = A;\n\nr = l\n\nand if this solution of Lame's equation is not doubly periodic, a\nsecond solution is\n\n\"H(a-a,)\n\nn\n\n@ (a)\n\nexp [otZ (,.)]\n\n= 0.\n\nThe existence of a solution of the system of n - l equations follows\nfrom \\hardsectionref{23}{7}.\n\nREFERENCES.\n\nG. Lam, Journal de Math. ii. (1837), pp. 147-188; iv. (1839), pp.\n100-125, 126-163, 351- 385; vin. (1843), pp. 397-434. Lecons sur les\nfonctions inverses des transcendantes et les surfaces isothermes\n(Paris, 1857). Lemons sur les coordonnees curvilignes (Paris, 1859).\n\nE. Heine, Journal fUr Math. xxix. (1845), pp. 185-208. Theorie der\nKugelfunctionen, ii. (Berlin, 1880).\n\nC. Herhite, Comptes Rendus, lxxxv. (1877), pp. 689-695, 728-732,\n821-826; Ann. di Mat. (2) IX. (1878), pp. 21-24. Oeuvres\nMathematiques (Paris, 1905-1917).\n\n%\n% 576\n%\n\nG. H. Halphen, Fonctions Elliptiques, il. (Paris, li\n\nF. LixuEMANN, Math. Ann. xix. (1882), pp. 323-386.\n\nK. Hecn, JIath. Ann. xxxili. (1889), pp. 161-179, 180-196.\n\nL. Crawford, Quarterly Journal, xxvii. (1895), pp. 93-98; xxix.\n(1898), pp. 196-201.\n\nW. D. NiVEN, Phil. Trans, of the Royal Society, 182 a (1891), pp.\n231-278.\n\nA. Cayley, Phil. Trans, of the Royal Society, 165 (1875), pp. 675-774.\n\nG. H. DAR VIN, Phil. Trans, of the Royal Society, 197 A (1901), pp.\n461-557; 198 a (1901),\n\npp. 301-331.\n\nMiscellaneous Examples.\n\n1. Obtain the formula\n\nGn X, y, =, /J \" Pn (J) e-' dn.Hn x, y, z).\n\n(Niven, Phil. Travis. 182 a (1891), p. 245.)\n\n2. Shew that\n\nrr fl l\\ \\ (-r. 2n)l Hn x,y,z)\n\n(Hobson, Proc. London Math. Soc. xxiv.)\n\n3. Shew that the 'external ellipsoidal harmonic' F '\" (\\$) En'\" (rj)\nE,,''\" (C) is a constant multiple of\n\n\"Xcx' dy' 82; V 2.(271 + 3) 2. 4 (2yi + 3) (2?i + 5) --J x +y + z )'\n\n(Niven; and Hobson, Proc. London Math. Soc. xxiv.)\n\n4. Discuss the confluent form of Lame's equation when the invariants 2\nand g of the\n\nWeierstrassian elliptic function are made to tend to zero; express the\nsolution in terms of\n\nBessel functions.\n\n(Haentzschel, Zeitschrift fiir Math, und Phys. xxxi.)\n\n5 If t! denotes - - exp [ X - Z (/x) a], where X and /x are constants,\nshew that\n\nG(a)\n\nLamd's equation has a solution which is expressible as a linear\ncombination of\n\ndn-l cln-3 dn-b\n\nwhere X- and sn p. are algebraic functions of the constant A.\n\n\\addexamplecitation{Hermite.}\n\n6. Obtain solutions of\n\n- =12Psn22-4(l + F)±5V(I-F + Z-'). w dz-\n\n\\addexamplecitation{Stenberg, Acta Math, x.}\n\n7. Discuss the solution of the equation\n\n2(2-l)(2-a) + [(a + + l)s' - n + /3-g + l+(y + S)a i+ay] + (5-j)3/ =\n\nin the form of the series\n\nGn q) hY\n\nl+a,3 2\n\ni=i !y(y+l)...(y+ )' where Gi q) = q, (?2(?) = a/3?2 + (a + /3-8+ l) +\n(-y + 8)a j-ay,\n\n6-' + i (?) = [ (a + /3-8 + n) + (y + S + -l)o + a/3j]6' (g)\n\n-(a + -l)(/3 + ?i-l)(y + n-l)?i .6' \\ i(j).\n\n(Heun, Math. Ann. xxxiii.)\n\n%\n% 577\n%\n\n8. Shew that the exponents at the singularities 0, \\, a, cc of Heun's\nequation are\n\n(0, 1-y), (0, 1-S), (0,1-0, (, ), where y + 8 + e = a + l3 + l.\n\n(Heun, Math. Ann. xxxiii.)\n\n9. Obtain the following group of variables for Heun's equation,\ncorresponding to the group\n\n\\ I z 2-1\n\nfor the hypergeometric equation :\n\n )\n\n1-z,\n\n1\n\nz '\n\n1\n\n1-2'\n\nz z-l'\n\nz\n\n-1\n\nz '\n\nz\n\na - z\n\n\n\na\n\nz\n\nz-a\n\na'\n\na '\n\na-z'\n\nz-a'\n\nz\n\nz-\n\n-a\n\nz-l\n\n1-\n\n a\n\na-\n\n1 z-\n\n a\n\nz\n\n-1\n\n1-a' a - 1' 2-a' z-V s-1' 2 '\n\n2-a (a-l)2 a(2 - 1) a(2-l) z - a (l-a)2\n\na (2-1)' rt(2-l)' 2-a ' (a -1)2' (I-o)!;' 2-a '\n\n(Heun, J/a . 4 ?;. xxxiii.)\n\n10. If the series of example 7 be called\n\nF a, q; a, jS, y, 8; 2),\n\nobtain 192 solutions of the differential equation in the form of\npowers of 2, 2- 1 and z - a. multiplied by functions of the type F.\n\n[Heun gives 48 of these solutions.]\n\n11. If ic=2v, shew that Lame's equation\n\nr/2 A\n\n- = n (71 + 1) iHu) + B A\n\nmay be transformed into\n\nby the substitution\n\n12. If C = P (v), shew that a formal solution of the equation of\nexample 11 is\n\nprovided that (a - 2?i) (a - ?i + 5) =\n\nand that\n\n4:(a-r-2n) a-r-n + h)b,+ [l2e.2ia-r + l) a-r-2n+l) + 'ie2n\n2n~l)-4B]br-i\n\n- 4( 1 - 62) (6-2 - 63) (a-r + 2) (a-r - n+l) h,.\\ 2 = 0., (Brioschi,\nComptes Bendus, lxxxvi. (1878), pp. 313-3,15 and Halphen.)\n\n13. Shew that, if n is half of an odd positive integer, a solution of\nthe equation of example 11 expressible in finite form is\n\ni= 6,(C-e2)'\"-'-, r=0\n\nW. M. A. 37\n\n%\n% 578\n%\n\np o ded that\n\n ir u-r + )l>,. + [' -2e.> -2n-i- + ) r-l)-4ein '2n-l) + -iB]b,\\ i\n\n+ 4(ei-e2)( '2-t'3)(2 -r + 2)( -/-+S)6r-2 = 0,\n\nand B is so determined that,j .j = 0-\n\n\\addexamplecitation{Brioschi and Halphen.}\n\n14. Shew that, if n is half of an odd integer, a sohition of tlie\nequation of example 11 xpressible in finite form is\n\nZ'=\"i'V(C-eo)\"- -\n\nprovided that\n\n4/) (n+jt? + A) bp - [Ue., n -p+ [ +p - *) - 1<'2 (2 - 1) + 45] //p\\ i\n\n+ 4 (ei - f 2) ( -.' - 3) in-p + ' ) p-l) ?>',, -2 =\n\nand ?>' 1=0 is the equation which determines B.\n\n\\addexamplecitation{Crawford.}\n\n15. \"With the notation of examples 13 and 14 shew that, if\n\nV = ( - )\" ( 1 - '2)'' e. - es)\" c \\ \\ .j. the equations which\ndetermine Cq, Cj, .< \\ j!. ' I'e identical with those which\ndetermine /)o, 61, ... > \\ i; and deduce that, if one of the\nsolutions of Lame's equation (in which n is half of an odd integer) is\nexpressible as an algebraic function of p v\\ so also is the other.\n\n\\addexamplecitation{Crawford.}\n\n16. Prove that the values of B determined in example 13 are re;\\ l\nwhen e, e and 6-3 are real.\n\n17. Shew that the complete solution of\n\nis A = iO' U)r - Ap iu) + B],\n\nwhere A and B are arbiti-aiy constants.\n\n(Halphen, Jle'm. par divers savants, xxviii. (i), (1880), p. 105.)\n\n18. Shew that the complete solution of\n\nig = |Fsn a-i(l4-F)\n\nis \\ = sn C-a)cQ C-a)dn C-a)r A + Bsnn.iC-a),\n\nwhere .-1 and B are arbitrary constants and C=2K+iK'.\n\n\\addexamplecitation{Jamet, Comptes Rendus, cxi.}", "meta": {"hexsha": "63bc4a6aec952884f8c2cfa0f6d0037f4f0af18f", "size": 76694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch23.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-ch23.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-ch23.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": 25.3617724868, "max_line_length": 102, "alphanum_fraction": 0.6572613242, "num_tokens": 26108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6434965845785295}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{BMO}\\label{sec:bmo}\n\t\n\t\t\\begin{problem}[$2005$, Round $2$, problem $3$]\n\t\t\tLet $a,b,c$ be positive real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{a}{b}+\\dfrac{b}{c}+\\dfrac{c}{a}\\right)^{2}\n\t\t\t\t\t\t& \\geq (a+b+c)\\left(\\dfrac{1}{a}+\\dfrac{1}{b}+\\dfrac{1}{c}\\right)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2007$, Round $1$, problem $5$]\n\t\t\tFor positive real numbers $a,b,c$, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a^{2}+b^{2}+c^{2})^{2}\n\t\t\t\t\t\t& \\geq(a+b+c)(a+b-c)(b+c-a)(c+a-b)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2008$, Round $1$, problem $1$]\n\t\t\tFind the minimum value of $x^{2}+y^{2}+z^{2}$ where $x,y,z$ are real numbers such that $x^{3}+y^{3}+z^{3}-3xyz=1$.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2010$, Round $2$, problem $5$]\n\t\t\tFor all positive real numbers $x,y,z$, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t4(x+y+z)^{3}\n\t\t\t\t\t\t& > 27(x^{2}y+y^{2}z+z^{2}x)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2011$, Round $2$, problem $6$]\n\t\t\tLet $a,b,c$ be the sides of a triangle such that $ab+bc+ca=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a+1)(b+1)(c+1)\n\t\t\t\t\t\t& < 4\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2015$, Round $1$, problem $1$]\n\t\t\tPlace the following numbers in order and provide your reasoning to do so:\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t3^{3^{4}},\n\t\t\t\t\t\t& 3^{4^{3}},~4^{3^{3}},~4^{4^{3}}\n\t\t\t\t\\end{align*}\n\t\t\tHere, $a^{b^{c}}=a^{\\left(b^{c}\\right)}$ and not $\\left(a^{b}\\right)^{c}$ which is $a^{bc}$.\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "dce9bdfba877097f830b9d5c44e5785be7c88b20", "size": 1541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bmo.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": "bmo.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": "bmo.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": 30.82, "max_line_length": 117, "alphanum_fraction": 0.5528877352, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.64349658306247}}
{"text": "% !TeX spellcheck = en_GB\n\n\\documentclass[12pt,titlepage,letterpaper]{econtex}\n\\usepackage{econtexSetup}\\usepackage{econtexShortcuts}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\newcommand{\\E}{\\mathbb{E}}\n%\\newcommand{\\pd}[2]{\\frac{\\partial#1}{\\partial#2}}\n\n\\begin{document}\n\\section{ConsIndShockModel.py}\n\nDefines consumption-saving models whose agents have CRRA utility over a unitary consumption good, geometric discounting, and who face idiosyncratic shocks to income.\n\n\\subsection{Perfect Foresight}\n\nConsider an agent with CRRA utility over consumption, who discounts future utility at a constant rate per period and has no bequest motive.  His problem can be written as:\n\\begin{eqnarray*}\nV_t(M_t) &=& \\max_{C_t} \\utilFunc(C_t) + \\beta \\PLives_{t+1} \\E [V_{t+1}(M_{t+1}) ], \\\\\nA_t &=& M_t - C_t, \\\\\nM_{t+1} &=& \\Rfree A_t + Y_{t+1}, \\\\\nY_{t+1} &=& \\Gamma_{t+1} Y_t, \\\\\n\\utilFunc(C) &=& \\frac{C^{1-\\CRRA}}{1-\\CRRA}.\n\\end{eqnarray*}\nThe model can be normalized by current income (which is also permanent income in this model) by defining lower case variables as their upper case version divided by $Y_t$:\n\\begin{eqnarray*}\n\\vFunc_t(m_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta \\PLives_{t+1} \\E [\\vFunc_{t+1}(m_{t+1}) ], \\\\\na_t &=& m_t - c_t, \\\\\nm_{t+1} &=& (\\Rfree/\\Gamma_{t+1}) a_t + 1, \\\\\n\\utilFunc(c) &=& \\frac{c^{1-\\CRRA}}{1-\\CRRA}.\n\\end{eqnarray*}\nAn individual agent's model is thus characterized by values of $\\CRRA$, $\\beta$, and $\\Rfree$ along with sequences $\\{\\Gamma_t\\}_{t=1}^T$ and $\\{\\PLives_t\\}_{t=1}^T$, with $T = \\infty$ possible.\n\nThe one period problem for this model is solved by the function \\texttt{solveConsPerfForesight}, which creates an instance of the class \\texttt{ConsPerfForesightSolver}.  The class \\texttt{PerfForesightConsumerType} extends \\texttt{AgentType} to represent agents in this model. The concordance between model variables and their code equivalents is as follows.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\CRRA$ & Coefficient of relative risk aversion & \\texttt{CRRA} \\\\\n$\\beta$ & Intertemporal discount factor & \\texttt{DiscFac} \\\\\n$\\Rfree$ & Risk free interest factor & \\texttt{Rfree} \\\\\n$\\PLives$ & Survival probability & \\texttt{LivPrb} \\\\\n$\\Gamma$ & Permanent income growth factor & \\texttt{PermGroFac} \\\\\n(none) & Number of agents of this type & \\texttt{Nagents}\n\\end{tabular}\n\\end{table}\n\nThese are the only six parameters that an instance of \\texttt{PerfForesightConsumerType} must have in order to create an instance and its \\texttt{solve} method.\\footnote{The attribute \\texttt{Nagents} is not needed to \\texttt{solve} this type, but is instead used during simulation.  However, this attribute is used by the constructor method for this class (to set the attributes \\texttt{a\\_init} and \\texttt{p\\_init}), so it must be passed when a new instance is created.}  Note that \\texttt{LivPrb} and \\texttt{PermGroFac} are assumed to be time-varying, so they should be input as a list.  Each element of the \\texttt{solution} attribute will be an instance of \\texttt{ConsumerSolution} with the following attributes:\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\cFunc(\\cdot)$ & Noramlized consumption function & \\texttt{cFunc} \\\\\n$\\vFunc(\\cdot)$ & Normalized value function & \\texttt{vFunc} \\\\\n$\\vFunc'(\\cdot)$ & Normalized marginal value function & \\texttt{vPfunc} \\\\\n$\\underline{m}$ & Mininum normalized market resources & \\texttt{mNrmMin} \\\\\n$h$ & Normalized human wealth & \\texttt{hNrm} \\\\\n$\\overline{\\kappa}$ & Maximum marginal propensity to consume & \\texttt{MPCmax} \\\\\n$\\underline{\\kappa}$ & Minimum marginal propensity to consume & \\texttt{MPCmin} \\\\\n\\end{tabular}\n\\end{table}\nIn the perfect foresight model, the consumption function is linear, so the maximum and minimum MPC are equal.  Each of the functions takes normalized market resources $m$ as an argument, and they only defined on the domain $m \\geq \\underline{m} = -h$.\n\n\n\\subsection{Permanent and Transitory Idiosyncratic Shocks}\n\nConsider an agent with CRRA utility over consumption, who discounts future utility at a constant rate per period and has no bequest motive.  He foresees that he will experience shocks to his income that are fully transitory or fully permanent.  Using the normalization above, his problem can be written as:\n\n\\begin{eqnarray*}\n\\vFunc_t(m_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta \\PLives_{t+1} \\E [\\vFunc_{t+1}(m_{t+1}) ], \\\\\na_t &=& m_t - c_t, \\\\\na_t &\\geq& \\underline{a}, \\\\\nm_{t+1} &=& \\Rfree/(\\Gamma_{t+1} \\psi_{t+1}) a_t + \\theta_{t+1}, \\\\\n\\theta_t \\sim F_{\\theta t}, &\\qquad& \\psi_t \\sim F_{\\psi t}, \\hspace{0.25cm} \\E[F_{\\psi t}] = 1, \\\\\n\\utilFunc(c) &=& \\frac{c^{1-\\CRRA}}{1-\\CRRA}.\n\\end{eqnarray*}\nThat is, this agent is identical to the perfect foresight agent except that his income is subject to permanent ($\\psi$) and transitory ($\\theta$) shocks to income, and he might have an artificial borrowing constraint $\\underline{a}$.\n\nThe one period problem for this model is solved by the function \\texttt{solveConsIndShock}, which creates an instance of the class \\texttt{ConsIndShockSolver}.  The class \\texttt{IndShockConsumerType} extends \\texttt{PerfForesightConsumerType} to represent agents in this model.  To construct an instance of this class, several additional parameters must be passed to the constructor.  Note that most of these parameters are \\textit{indirect} inputs to the consumer's model: they are used to construct direct inputs to the one period problem.  The concordance between the model and code is as follows:\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n(none) & Minimum of ``assets above minimum'' grid & \\texttt{aXtraMin} \\\\\n(none) & Maximum of ``assets above minimum'' grid & \\texttt{aXtraMax} \\\\\n(none) & Number of points in ``assets above minimum'' grid & \\texttt{aXtraCount} \\\\\n(none) & Additional values for the ``assets above minimum'' grid & \\texttt{aXtraExtra} \\\\\n(none) & Degree of exponential nesting for assets grid & \\texttt{exp\\_nest} \\\\\n$N_{\\theta}$ & Number of discrete values in transitory shock distribution & \\texttt{TranShkCount} \\\\\n$N_{\\psi}$ & Number of discrete values in permanent shock distribution & \\texttt{PermShkCount} \\\\\n$\\sigma_\\theta$ & Standard deviation of log transitory shocks & \\texttt{TranShkStd} \\\\\n$\\sigma_\\psi$ & Standard deviation of log permanent shocks & \\texttt{PermShkStd} \\\\\n$\\mho$ & Unemployment probability in working period & \\texttt{UnempPrb} \\\\\n$\\mho_{ret}$ & ``Unemployment'' probability in retirement period & \\texttt{UnempPrbRet} \\\\\n$\\underline{\\theta}$ & Transitory income when unemployed in working period & \\texttt{IncUnemp} \\\\\n$\\underline{\\theta}_{ret}$ & Transitory income when ``unemployed'' in retired period & \\texttt{IncUnempRet} \\\\\n$\\tau$ & Marginal income tax rate & \\texttt{tax\\_rate} \\\\\n$T_{ret}$ & Period of retirement; number of working periods & \\texttt{T\\_retire} \\\\\n$\\underline{a}$ & Artificial borrowing constraint & \\texttt{BoroCnstArt} \\\\\n(none) & Indicator for whether \\texttt{cFunc} should use cubic splines & \\texttt{CubicBool} \\\\\n(none) & Indicator for whether \\texttt{vFunc} should be computed & \\texttt{vFuncBool} \\\\\n$T$ & Total number of (non-terminal) periods in sequence & \\texttt{T\\_total} \\\\\n(none) & Number of agents of this type & \\texttt{Nagents}\n\\end{tabular}\n\\end{table}\n\nThe first five attributes in the table above are used to construct the ``assets above minimum'' grid \\texttt{aXtraGrid}, an input for \\texttt{solveConsIndShock}.\\footnote{In the current configuration, the grid is multi-exponentially spaced given minimum, maximum, number of gridpoints, and degree of exponential nesting (with additional values to force into the grid with \\texttt{aXtraExtra}).  It is simple to replace this grid with another by changing the function \\texttt{makeAssetsGrid}.}  The next ten attributes specify an assumed form for the income distribution $(F_{\\psi t}, F_{\\theta t})$. Both permanent and transitory shocks are lognormally distributed, and with a point mass in the transitory distribution representing unemployment.  Further, the sequence of periods is broken into two parts, ``working'' and ``retired'' to allow for a different income process in retirement.\\footnote{Permanent and transitory shocks are turned off during retirement, other than the possibility of ``unemployment'', representing (say) a temporary failure of the retirement benefit system.} The attributes \\texttt{PermShkStd} and \\texttt{TranShkStd} are thus lists of the (log) standard deviation of shocks period-by-period.\n\nLike the assets grid, the specification of the income process can be changed with little difficulty.  No matter what form is used, the relevant direct input to \\texttt{solveConsIndShock} is \\texttt{IncomeDstn}, a finite discrete approximation to the true income process.  This attribute is specified as a list with three elements: an array of probabilities (that sum to 1), an array of permanent income shocks, and an array of transitory income shocks.\n\nThe artificial borrowing constraint imposes a restriction on assets at the end of the period; it can be set to \\texttt{None} to turn off the constraint (i.e.\\ only the ``natural'' borrowing constraint will be used). The attributes \\texttt{CubicBool} and \\texttt{vFuncBool} should be set to \\texttt{True} or \\texttt{False}, as their name implies.  The solver can construct a linear or cubic spline interpolation of the consumption function; cubic interpolation is slower but more accurate at any number of gridpoints.  The value function is not strictly necessary to compute during solution and carries a computational burden, so it can be turned off with \\texttt{vFuncBool=False}.  The number of agents of this type \\texttt{Nagents} is irrelevant during solution and is only used during simulation (when \\textit{ex-post} heterogeneity emerges within the \\textit{ex-ante} homogeneous type).\n\nThe \\texttt{solve} method of \\texttt{IndShockConsumerType} will populate the \\texttt{solution} attribute with a list containing instances of \\texttt{ConsumerSolution}.  Each of these instances has all the elements listed above in the perfect foresight section plus the attribute \\texttt{vPPfunc} (representing $\\vFunc''(m)$) if \\texttt{CubicBool=True}.\\footnote{\\texttt{vFunc} will be a placeholder function of the class \\texttt{NullFunc} if \\texttt{vFuncBool=False}.}  The problem is solved using the method of endogenous gridpoints, which is explained for this model in section 5.8 of \\href{http://www.econ2.jhu.edu/people/ccarroll/SolvingMicroDSOPs/}{this set of lecture notes}.\n\n\n\\subsection{Different Interest Rate on Borrowing vs Saving}\n\nConsider an agent identical to the ``idiosyncratic shocks'' model above, except that his interest factor differs depending on whether he borrows or saves on net.  His problem is the same as the one above, with a simple addition:\n\\begin{equation*}\n\\Rfree = \\begin{cases}\n\\Rfree_{boro} & \\text{if  } a_t < 0 \\\\\n\\Rfree_{save} & \\text{if  } a_t > 0\n\\end{cases}, \\qquad \\Rfree_{boro} \\geq \\Rfree_{save}.\n\\end{equation*}\n\nThe one period problem for this model is solved by \\texttt{solveConsKinkedR}, which creates an instance of \\texttt{ConsKinkedRsolver}.  The class \\texttt{KinkedRconsumerType} extends \\texttt{IndShockConsumerType} to represent agents in this model.  The attributes required to specify an instance of \\texttt{KinkedRconsumerType} are the same as \\texttt{IndShockConsumerType} except that \\texttt{Rfree} \\textit{should not} be included, instead replaced by values of \\texttt{Rboro} and \\texttt{Rsave}.  The ``kinked R'' solver is not yet compatible with cubic spline interpolation for \\texttt{cFunc}; if the \\texttt{solve} method is run with \\texttt{CubicBool=True}, it will throw an exception.\\footnote{This is an item that is ripe for development by an outside contributor.}\n\nThe \\texttt{solve} method of \\texttt{KinkedRconsumerType} populates the \\texttt{solution} attribute with a list of \\texttt{ConsumerSolution} instances, in the same format as the idiosyncratic shocks model.  The problem is solved using the method of endogenous gridpoints with \\textit{two} copies of $a_t = 0$ in the grid of end-of-period states-- one for $\\Rfree_{boro}$ and the other for $\\Rfree_{save}$.  This generates the ``kinked'' portion of the resulting consumption function, where the consumer is unwilling to borrow and insufficiently motivated to save, so he consumes at $c_t = m_t$.\n\n\\section{ConsPrefShockModel.py}\n\nDefines consumption-saving models whose agents have CRRA utility over a unitary consumption good, geometric discounting, who face idiosyncratic shocks to income and to their utility or preferences.\n\n\\subsection{Multiplicative Shocks to Utility}\n\nConsider an agent with a very similar problem to that of the ``idiosyncratic shocks'' model in the preceding section, except that he receives an iid multiplicative shock to his utility at the beginning of each period, before making the consumption decision.  This model can be written in Bellman form as:\n\n\\begin{eqnarray*}\n\\vFunc_t(m_t,\\eta_t) &=& \\max_{c_t} \\eta \\cdot \\utilFunc(c_t) + \\beta \\PLives_{t+1} \\E [\\vFunc_{t+1}(m_{t+1},\\eta_{t+1}) ], \\\\\na_t &=& m_t - c_t, \\\\\na_t &\\geq& \\underline{a}, \\\\\nm_{t+1} &=& \\Rfree/(\\Gamma_{t+1} \\psi_{t+1}) a_t + \\theta_{t+1}, \\\\\n\\theta_t \\sim F_{\\theta t}, &\\qquad& \\psi_t \\sim F_{\\psi t}, \\hspace{0.25cm} \\E[F_{\\psi t}] = 1, \\\\\n\\utilFunc(c) &=& \\frac{c^{1-\\CRRA}}{1-\\CRRA}, \\qquad \\eta_t \\sim F_{\\eta t}.\n\\end{eqnarray*}\n\nThe one period problem for this model is solved by the function \\texttt{solveConsPrefShock}, which creates an instance of \\texttt{ConsPrefShockSolver}.  The class \\texttt{PrefShockConsumerType} is used to represent agents in this model.  The attributes required to construct an instance of this class are the same as for \\texttt{IndShockConsumerType} above, but with three additions:\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$N_\\eta$ & Number of discrete points in ``body'' of preference shock distribution & \\texttt{PrefShkCount} \\\\\n$N_\\eta^{tail}$ & Number of discrete points in ``tails'' of preference shock distribution & \\texttt{PrefShk\\_tail\\_N} \\\\\n$\\sigma_\\eta$ & Log standard deviation of multiplicative utility shocks & \\texttt{PrefShkStd}\n\\end{tabular}\n\\end{table}\n\nThese attributes are indirect inputs to the problem, used during instantiation to construct the \\texttt{PrefShkDstn}, an input to \\texttt{solveConsPrefShock}.  The tails of the preference shock distribution matter a great deal for the accuracy of the solution and are underrepresented by the default equiprobable discrete approximation (unless a very large number of points are used).  To fix this issue, the attribute \\texttt{PrefShk\\_tail\\_N} specifies the number of points in each ``augmented tail'' section of the preference shock discrete approximation.\\footnote{See documentation for \\texttt{HARKutilities.approxLognormal} for more details.}  The standard deviation of preference shocks might vary by period, so \\texttt{PrefShkStd} should be input as a list.  The ``preference shock'' solver is not yet compatible with cubic spline interpolation for the consumption function and will throw an exception if \\texttt{CubicBool=True}.\n\nThe \\texttt{solve} method of \\texttt{PrefShockConsumerType} populates the \\texttt{solution} attribute with a list of \\texttt{ConsumerSolution} instaces.  These single-period-solution objects have the same attributes as the ``idiosyncratic shocks'' models above, but the attribute \\texttt{cFunc} is defined over the space of $(m_t,\\eta_t)$ rather than just $m_t$.  The value function \\texttt{vFunc} and marginal value \\texttt{vPfunc}, however, are defined \\textit{only} over $m_t$, as they represent expected (marginal) value \\textit{just before} the preference shock $\\eta_t$ is realized:\\footnote{Particularly in the case of \\texttt{vPfunc}, this is the object of interest for solving the preceding period.}\n\\begin{eqnarray*}\n\\overline{\\vFunc}_t(m_t) &=& \\int_0^\\infty \\vFunc(m_t,\\eta)dF_{\\eta t}(\\eta), \\\\\n\\overline{\\vFunc}_t'(m_t) &=& \\int_0^\\infty \\vFunc'(m_t,\\eta)dF_{\\eta t}(\\eta).\n\\end{eqnarray*}\n\n\n\\subsection{Utility Shocks and Different Interest Rates}\n\nConsider an agent with idiosyncratic shocks to permanent and transitory income and multiplicative shocks to utility \\textit{and} faces a different interest rate on borrowing vs saving.  This agent's model is identical to that of the ``preference shock'' consumer in section 2.1, with the addition of the interest rate rule from the ``kinked R'' consumer in section 1.3.\n\nThe one period problem of this combination model is solved by the function \\texttt{solveConsKinkyPref}, which creates an instance of \\texttt{ConsKinkyPrefSolver}.  The class \\texttt{KinkyPrefConsumerType} represents agents in this model.  As you will see in \\texttt{ConsPrefShockModel.py}, there is \\textit{very} little new code required to program this model: the solver and consumer classes each inherit from both \\texttt{KinkedR} and \\texttt{PrefShock} and only need a trivial constructor function to rectify the differences between the two.  This is a good demonstration of the benefit of HARK's object-oriented approach to solution methods: it is sometimes trivial to combine two models to make a new one.\n\nThe attributes required to properly construct an instance of \\texttt{KinkyPrefConsumerType} are the same as for \\texttt{PrefShockConsumerType} except that (like the ``kinked R'' parent model) \\texttt{Rfree} should not be replaced with \\texttt{Rboro} and \\texttt{Rsave}.  Like both of its parents, \\texttt{KinkyPref} is not yet compatible with cubic spline interpolation of the consumption function.\n\n\\newpage\n\n\\section{ConsMarkovModel.py}\n\nDefines consumption-saving models with a discrete state that evolves according to an exogenous Markov process.\n\n\\subsection{Markov States and Idiosyncratic Shocks}\n\nConsider an agent with CRRA utility over consumption who geometrically discounts future utility flows and expects to experience transitory and permanent shocks to his income.  Moreover, in any given period he finds himself in exactly one of several discrete states; this state evolves from period to period according to a Markov process.  The individual's income distribution, permanent income growth rate, and interest factor might vary across states.  This agent's problem can be written in Bellman form as:\n\\begin{eqnarray*}\n\\vFunc_t(m_t,s_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta \\PLives_{t+1} \\E [\\vFunc_{t+1}(m_{t+1},s_{t+1}) ], \\\\\na_t &=& m_t - c_t, \\\\\na_t &\\geq& \\underline{a}, \\\\\nm_{t+1} &=& \\frac{\\Rfree(s_{t+1})}{\\Gamma_{t+1}(s_{t+1})\\psi_{t+1}} \\cdot a_t + \\theta_{t+1}, \\\\\n\\theta_t \\sim F_{\\theta t}(s_{t}), &\\qquad& \\psi_t \\sim F_{\\psi t}(s_{t}), \\hspace{0.25cm} \\E[F_{\\psi t}(s_{t})] = 1, \\\\\n\\text{Prob}[s_{t+1}=j | s_t=i] &=& \\Delta_{ij}, \\\\\n\\utilFunc(c) &=& \\frac{c^{1-\\CRRA}}{1-\\CRRA}.\n\\end{eqnarray*}\nThe Markov matrix is $\\Delta$, giving transition probabilities from current state $i$ to future state $j$.  This model is the same as the ``idiosyncratic shocks'' model of section 2.1 but for the presence of the Markov state $s_t$, so that the interest factor $\\Rfree$, income distribution $(F_{\\psi t},F_{\\theta t})$, and permanent income growth factor $\\Gamma_{t+1}$ are all functions of the Markov state, having a value for each state.\n\nThe function \\texttt{solveConsMarkov} solves the one period problem of this model, creating an instance of \\texttt{ConsMarkovSolver}.  The class \\texttt{MarkovConsumerType} is used to represent agents in this model, extending \\texttt{IndShockConsumerType}.  The attributes required to specify an instance of this class are the same as for \\texttt{IndShockConsumerType} but for one addition:\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\Delta$ & Discrete state transition probability matrix & \\texttt{MrkvArray}\n\\end{tabular}\n\\end{table}\n\nThe attribute \\texttt{MrkvArray} is a \\texttt{numpy.array} of size $(N_s,N_s)$ corresponding to the number of discrete states.\\footnote{As is, \\texttt{MrkvArray} is an element of \\texttt{time\\_inv}, so the same transition probabilities are used for each period.  However, it can be moved to \\texttt{time\\_vary} and specified as a list of \\texttt{array}s instead.}  The attributes \\texttt{Rfree}, \\texttt{PermGroFac}, and \\texttt{IncomeDstn} should be specified as lists\\footnote{\\texttt{PermGroFac} and \\texttt{Rfree} can be arrays or lists.} with $N_s$ elements for each period.  Note that \\texttt{MarkovConsumerType} currently has no method to automatically construct a valid \\texttt{IncomeDstn}; as seen in the examples in \\texttt{ConsMarkovModel.py}, the \\texttt{IncomeDstn} is manually constructed in each case.\\footnote{Writing a method to supersede  \\texttt{IndShockConsumerType.updateIncomeProcess} for the ``Markov model'' would be a welcome contribution.}  All other attributes are specified the same as in the ``idiosyncratic shocks'' model.\n\nWhen the \\texttt{solve} method of a \\texttt{MarkovConsumerType} is invoked, the \\texttt{solution} attribute is populated with a list of \\texttt{ConsumerSolution} objects, which each have the same attributes as the ``idiosyncratic shocks'' model.  However, each attribute is now a list (or array) whose elements are \\textit{state-conditional} values of that object.  For example, in a model with four discrete states, each the \\texttt{cFunc} attribute of each element of \\texttt{solution} is a length-4 list whose elements are state-conditional consumption functions (e.g. \\texttt{cFunc[2]} is the consumption function when $s_t=2$).  The ``Markov model'' is compatible with cubic spline interpolation for the consumption functions, so \\texttt{CubicBool=True} will not generate an exception.  The problem is solved using the method of endogenous gridpoints, which is moderately more complicated than in the basic ``idiosyncratic shocks'' model.\n\n\\section{ConsAggShockModel.py}\n\nDefines consumption-saving models with idiosyncratic and aggregate shocks to income.\n\n\\subsection{Idiosyncratic and Aggregate Shocks to Income}\n\nConsider an agent with CRRA preferences over consumption who discounts future utility flows and expects to experience permanent and transitory shocks to his income.  He also believes that the market to which he supplies (a fixed amount of) labor will experience \\textit{aggregate} permanent and transitory shocks to the effective productivity of labor.  The wage rate in the market is the marginal product of labor in the aggregate production function, and the interest factor is one plus the (net) marginal product of capital; assume that the ratio of aggregate capital-to-labor is a sufficient statistic for these marginal products.  Further, the agent believes that the capital-to-labor ratio evolves as a function of its current value.  This model can be written in Bellman form as:\n\n\\begin{eqnarray*}\n\\vFunc_t(m_t,k_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta \\PLives_{t+1} \\E [\\vFunc_{t+1}(m_{t+1},k_{t+1}) ], \\\\\na_t &=& m_t - c_t, \\\\\na_t &\\geq& 0, \\\\\nm_{t+1} &=& \\frac{\\Rfree_{t+1}}{\\Gamma_{t+1}\\psi_{t+1} \\Psi_{t+1}} \\cdot a_t + W_{t+1} \\theta_{t+1}, \\\\\n\\Rfree_{t+1} = \\textbf{R}(k_{t+1}/\\Theta_{t+1}), & & W_{t+1} = \\textbf{W}(k_{t+1}/\\Theta_{t+1}), \\\\\nk_{t+1} &=& \\textbf{k}(k_t), \\\\\n\\theta_t \\sim F_{\\theta t}, &\\qquad& \\psi_t \\sim F_{\\psi t}, \\hspace{0.25cm} \\E[F_{\\psi t}] = 1, \\\\\n\\Theta_t \\sim F_{\\Theta}, &\\qquad& \\Psi_t \\sim F_{\\Psi}, \\hspace{0.25cm} \\E[F_{\\Psi}] = \\E[F_{\\Theta}] = 1, \\\\\n\\utilFunc(c) &=& \\frac{c^{1-\\CRRA}}{1-\\CRRA}.\n\\end{eqnarray*}\n\nThe objects $\\textbf{R}(\\cdot)$ and $\\textbf{W}(\\cdot)$, are functions of the (effective) capital-to-labor ratio that yield the (net) interest factor and wage rate respectively.  As noted above, these are determined by the aggregate production function and the degree of capital depreciation.  The $\\texttt{k}(\\cdot)$ function represents the agent's beliefs about the evolution of the capital-to-labor ratio $k_t$.  As with idiosyncratic shocks, there is an aggregate shock process $(F_{\\Theta},F_{\\Psi})$.\n\nThe one period problem of this model is solved by the function \\texttt{solveConsAggShock}, the default value of \\texttt{solveOnePeriod} for \\texttt{AggShockConsumerType}.  The attributes required to specify an instance of this class are listed in the concordance below.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\CRRA$ & Coefficient of relative risk aversion & \\texttt{CRRA} \\\\\n$\\beta$ & Intertemporal discount factor & \\texttt{DiscFac} \\\\\n$\\PLives$ & Survival probability & \\texttt{LivPrb} \\\\\n$\\Gamma$ & Permanent income growth factor & \\texttt{PermGroFac} \\\\\n(none) & Minimum of ``assets above minimum'' grid & \\texttt{aXtraMin} \\\\\n(none) & Maximum of ``assets above minimum'' grid & \\texttt{aXtraMax} \\\\\n(none) & Number of points in ``assets above minimum'' grid & \\texttt{aXtraCount} \\\\\n(none) & Additional values for the ``assets above minimum'' grid & \\texttt{aXtraExtra} \\\\\n(none) & Degree of exponential nesting for assets grid & \\texttt{exp\\_nest} \\\\\n$\\{\\hat{k}\\}$ & Array of scaling factors for capital ratio (around SS) & \\texttt{kGridBase} \\\\\n$N_{\\theta}$ & Number of discrete values in transitory shock distribution & \\texttt{TranShkCount} \\\\\n$N_{\\psi}$ & Number of discrete values in permanent shock distribution & \\texttt{PermShkCount} \\\\\n$\\sigma_\\theta$ & Standard deviation of log transitory shocks & \\texttt{TranShkStd} \\\\\n$\\sigma_\\psi$ & Standard deviation of log permanent shocks & \\texttt{PermShkStd} \\\\\n$\\mho$ & Unemployment probability in working period & \\texttt{UnempPrb} \\\\\n$\\mho_{ret}$ & ``Unemployment'' probability in retirement period & \\texttt{UnempPrbRet} \\\\\n$\\underline{\\theta}$ & Transitory income when unemployed in working period & \\texttt{IncUnemp} \\\\\n$\\underline{\\theta}_{ret}$ & Transitory income when ``unemployed'' in retired period & \\texttt{IncUnempRet} \\\\\n$\\tau$ & Marginal income tax rate & \\texttt{tax\\_rate} \\\\\n$T_{ret}$ & Period of retirement; number of working periods & \\texttt{T\\_retire} \\\\\n$T$ & Total number of (non-terminal) periods in sequence & \\texttt{T\\_total} \\\\\n(none) & Number of agents of this type & \\texttt{Nagents}\n\\end{tabular}\n\\end{table}\n\nThis list is very similar to the one for \\texttt{IndShockConsumerType}, but several attributes have been removed: \\texttt{Rfree} is endogenous here, while \\texttt{CubicBool}, \\texttt{vFuncBool}, and \\texttt{BoroCnstArt} are not yet supported in the ``aggregate shocks'' model.  The only new attribute is \\texttt{kGridBase}, an array of scaling factors for the (perfect foresight equivalent) steady state capital ratio; it is used to construct \\texttt{kGrid}, a direct input for \\texttt{solveConsAggShock}.\n\nA new \\texttt{AggShockConsumerType} with these attributes is not yet ready to solve its micro model, as it lacks several features.  After creating a valid \\texttt{CobbDouglasEconomy} instance (see section 4.2), the agent type must get ``macro'' level objects from this by invoking its \\texttt{getEconomyData} method with the \\texttt{CobbDouglasEconomy} as the input.  This gives the agent type its interest, wage, and next-capital-ratio functions as the attributes \\texttt{Rfunc}, \\texttt{Wfunc}, and \\texttt{kNextFunc}, its capital ratio grid \\texttt{kGrid}, and reformats the \\texttt{IncomeDstn} attribute as a discrete joint distribution across all four types of shocks.\\footnote{As of the beta release, this method is only compatible with one period infinite horizon micro models, but this can be fixed with minimal difficulty.}\n\nAfter obtaining ``macro''-level inputs to its model, an \\texttt{AggShockConsumerType}'s \\texttt{solve} method will populate the \\texttt{solution} attribute with a list of \\texttt{ConsumerSolution} instances.  Unlike the models with only idiosyncratic shocks, the one-period-solution objects have only two attributes, \\texttt{cFunc} and \\texttt{vPfunc}; both of these functions are defined over the space of $(m_t,k_t)$.  The model is solved using the method of endogenous gridpoints, following Kiichi Tokuoka's Mathematica code for the \\href{http://www.econ2.jhu.edu/people/ccarroll/papers/cstwMPC/}{``cstwMPC'' project}.\n\n\\subsection{Cobb-Douglas Economy}\n\nA model with ``aggregate shocks'' only makes sense if there is some market-level object that experiences these shocks.  The \\texttt{CobbDouglasEconomy} class extends \\texttt{Market} to represent an economy with a Cobb-Douglas production function over aggregate capital and aggregate labor\\footnote{As the microeconomic model in section 4.1 assumes a fixed per capita labor supply, aggregate labor for this class is assumed constant and disappears into the background.  The HARK team welcomes contributions that extend both the micro and macro models to account for endogenous labor supply.} and permanent and transitory shocks to labor productivity.  The basic model for the Cobb-Douglas economy is:\n\n\\begin{eqnarray*}\nY &=& K^\\alpha L^{1-\\alpha}, \\qquad k \\equiv K/L,\\\\\nW = \\pd{Y}{L} &=& (1-\\alpha) K^{\\alpha} L^{-\\alpha} = (1-\\alpha) k^\\alpha, \\\\\n\\rfree = \\pd{Y}{K} &=& \\alpha K^{\\alpha-1} L^{1-\\alpha} = \\alpha k^{\\alpha-1}, \\\\\n\\Rfree &=& 1 + \\rfree - \\delta.\n\\end{eqnarray*}\n\nA new instance of \\texttt{CobbDouglasEconomy} must have attributes listed in the table below.  The constructor for the class uses these attributes to calculate the perfect foresight steady state of the capital-to-labor ratio\\footnote{If the economy were populated with perfect foresight agents with preferences given by $\\beta^{PF}$ and $\\CRRA^{PF}$, the steady state level of capital is where $k_{t+1} = k_t$ (when aggregate shocks are turned off as well).}, wage rate, and interest rate; the interest and wage functions; a discretization of the aggregate shock process, and an initial guess of the next-capital-ratio function.  Following Krusell and Smith (1998), we assume that the log of next period's capital ratio is a linear function of the log of this period's capital ratio.\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\alpha$ & Capital's share of output & \\texttt{CapShare} \\\\\n$\\delta$ & Capital depreciation rate & \\texttt{DeprFac} \\\\\n$\\sigma_\\Psi$ & Standard deviation of log permanent aggregate shocks & \\texttt{PermShkAggStd} \\\\\n$\\sigma_\\Theta$ & Standard deviation of log transitory aggregate shocks & \\texttt{TranShkAggStd} \\\\\n$N_\\Psi$ & Number of discrete values in permanent agg shock distribution & \\texttt{PermShkAggCount} \\\\\n$N_\\Theta$ & Number of discrete values in transitory agg shock distribution & \\texttt{TranShkAggCount} \\\\\n$\\CRRA^{PF}$ & Perfect foresight coefficient of relative risk aversion & \\texttt{CRRAPF} \\\\\n$\\beta^{PF}$ & Perfect foresight intertemporal discount factor & \\texttt{DiscFacPF} \\\\\n\\end{tabular}\n\\end{table}\n\nAfter a well-formed \\texttt{CobbDouglasEconomy} has been created, its \\texttt{agents} attribute can be populated with one or more instances of \\texttt{AggShockConsumerType} (who have taken ``macro'' level information from the \\texttt{CobbDouglasEconomy}).  A history of aggregate shocks can be created by invoking the \\texttt{makeAggShkHist} method.  If each element of \\texttt{AggShockConsumerType} has run its \\texttt{makeIncShkHist} method to create a history of idiosyncratic income shocks (for many agents in each type), then the \\texttt{CobbDouglasEconomy} can invoke its \\texttt{solve} method.  This will search for a general equilibrium of the model, defined as a ``dynamic rule'' for the capital ratio $\\textbf{k}(k_t)$ that is \\textit{consistent}: when agents believe this $\\textbf{k}(k_t)$ in their microeconomic problem, and the model is simulated for many periods, the resulting history of the capital ratio is consistent with that same dynamic rule.\n\nIn the \\texttt{Market} framework, the \\texttt{millRule} for \\texttt{CobbDouglasEconomy} gathers each agent's end-of-period normalized assets $a_t$ and permanent income $p_t$.  It aggregates wealth across all consumers into total capital, which it transforms into the capital-to-labor ratio.  It then uses the next aggregate shock values to calculate $\\Rfree_t$ and $W_t$, which are distributed back to the consumers along with the aggregate shocks and new capital ratio, so that they can simulated another period.\n\nAfter generating a history of several thousand periods, the \\texttt{CobbDouglasEconomy} can calculate a new dynamic rule for the capital ratio with its \\texttt{calcDynamics} method.  The dynamics calculator simply throws out the first 200 periods of the history and runs a one-period-lag autoregression on the log capital ratio.  This generates a new function for \\texttt{kNextFunc}, which is distributed to the consumer types in \\texttt{agents} to re-solve their micro models.  This process continues until successive \\texttt{kNextFunc}s are sufficiently close to consider the process converged (as determined by the \\texttt{tolerance} attribute).\n\n\n\\newpage\n\\section{TractableBufferStockModel.py}\n\nDefines the ``tractable buffer stock'' model from Chris Carroll's \\href{http://www.econ2.jhu.edu/people/ccarroll/public/LectureNotes/Consumption/TractableBufferStock.pdf}{lecture notes}.\n\n\\subsection{Tractable Buffer Stock}\n\nConsider a consumer with CRRA utility who faces only a single, very specific risk: that he will become permanently unemployed and receive no income until the end of time.  Otherwise, he faces an infinite horizon problem with a steady stream of income that grows by a fixed factor each period, and earns a constant rate of return on assets retained betweed periods.  His model when still employed can be written in Bellman form as:\\footnote{For technical / teaching reasons, permanent income growth while employed is ``risk compensated'' so that human wealth does not vary with the unemployment probability.}\n\\begin{eqnarray*}\n\\vFunc^e(m_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta  \\left( (1-\\mho)\\vFunc^e(m^e_{t+1}) + \\mho \\vFunc^u(m^u_{t+1}) \\right) \\\\\na_t &=& m_t - c_t \\\\\nm^e_{t+1} &=& (\\Rfree/\\widehat{\\Gamma}) a_t + 1, \\qquad \\widehat{\\Gamma} = \\Gamma/(1-\\mho)\\\\\nm^u_{t+1} &=& (\\Rfree/\\widehat{\\Gamma}) a_t.\n\\end{eqnarray*}\nHis model while unemployed is simply:\n\\begin{eqnarray*}\n\\vFunc^u(m_t) &=& \\max_{c_t} \\utilFunc(c_t) + \\beta  \\vFunc^u(m^u_{t+1}) \\\\\na_t &=& m_t - c_t \\\\\nm^u_{t+1} &=& (\\Rfree/\\widehat{\\Gamma}) a_t.\n\\end{eqnarray*}\n\nThis model is solved by the class \\texttt{TractableConsumerType} when its \\texttt{solve()} method is invoked.  An instance of this class is specified by the five parameters in the table below:\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\CRRA$ & Coefficient of relative risk aversion & \\texttt{CRRA} \\\\\n$\\beta$ & Intertemporal discount factor & \\texttt{DiscFac} \\\\\n$\\Rfree$ & Interest factor on assets & \\texttt{Rfree} \\\\\n$\\Gamma$ & Permanent income growth factor & \\texttt{PermGroFac} \\\\\n$\\mho$ & Probability of becoming unemployed & \\texttt{UnempPrb} \\\\\n\\end{tabular}\n\\end{table}\n\nUnlike other models in HARK, tractable buffer stock is not solved by backward induction beginning from an initial guess of the solution.  Because of the very specific form of risk faced by the agent, it is possible to calculate\\footnote{As long as the consumer is both ``return impatient'' and ``growth impatient'', else there is no steady state or no solution at all.} analytical values of the steady state $(m_t,c_t)$ and to find several derivatives of the consumption function at this point (i.e.\\ the MPC, MMPC, etc).  Further, the Euler and transition equations can be inverted to yield $(m_{t-1},c_{t-1})$ as a function of $(m_t,c_t)$ conditional on being employed in both periods.  Beginning from a small perturbation along a Taylor approximation of the consumption function around the steady state, the solution method generates a sequence of ``stable arm points'' along the consumption function.  After reaching specified bounds (and appending the lower bound at $(0,0)$), the (employed) consumption function is constructed as a cubic spline interpolation.\n\nAfter running the \\texttt{solve} method, the \\texttt{solution} attribute of a \\texttt{TractableConsumerType} will have a list with a single instance of \\texttt{TractableConsumerSolution}.  This object has the following attributes:\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c c}\nVar & Description & Code \\\\\n\\hline\n$\\{m_t\\}$ & List of market resources values on the stable arm & \\texttt{mNrm\\_list} \\\\\n$\\{c_t\\}$ & List of consumption values on the stable arm & \\texttt{cNrm\\_list} \\\\\n$\\{\\kappa_t\\}$ & List of MPCs at points on the stable arm & \\texttt{MPC\\_list} \\\\\n$\\cFunc^e(m_t)$ & Consumption function when employed & \\texttt{cFunc} \\\\\n$\\cFunc^u(m_t)$ & Consumption function when unemployed & \\texttt{cFunc\\_U} \\\\\n(none) & Number of stable arm points included & \\texttt{PointCount}\n\\end{tabular}\n\\end{table}\n\n\\subsection{Tractable Buffer Stock as Markov}\n\nThe tractable buffer stock model can also be solved by the standard backward induction approach if it is framed in terms of the Markov model in section 3.  There are two discrete state, \\textit{employed} and \\textit{unemployed}; transition probabilities from the former are $(1-\\mho,\\mho)$ and the latter is an absorbing state.  The interest factor and permanent income growth rate are identical in the two states, and both have degenerate income distributions: $\\psi_e = \\theta_e = 1$, while $\\psi_u = 1$ and $\\theta_u = 0$ for sure.  The model takes about 300 times longer to solve using the ``Markov formulation'' as the backshooting method, yielding a nearly identical solution.\n\n\\end{document}\n", "meta": {"hexsha": "9d1ed1d3698955f498f6f9da43a486e99fc3fb7d", "size": 37666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/ConsumptionSavingModels.tex", "max_stars_repo_name": "arotare1/myHARK", "max_stars_repo_head_hexsha": "a90b2ab670659411f2c38859c06e669fcd72600c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-08-15T10:50:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T04:17:47.000Z", "max_issues_repo_path": "Documentation/ConsumptionSavingModels.tex", "max_issues_repo_name": "jackiekazil/HARK", "max_issues_repo_head_hexsha": "9e7d3cabd7885dedcc1ea49ac5bd5bdb08b4615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-29T05:12:48.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-04T17:36:29.000Z", "max_forks_repo_path": "Documentation/ConsumptionSavingModels.tex", "max_forks_repo_name": "pmgblz/HARK", "max_forks_repo_head_hexsha": "160284fe999aadfa309ea0f411694e7e1484596e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-28T07:23:53.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-28T07:23:53.000Z", "avg_line_length": 101.525606469, "max_line_length": 1219, "alphanum_fraction": 0.7557213402, "num_tokens": 10375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6434828119393741}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{fmpower}\n\\section*{\\hspace*{-1.6cm} fmpower}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nSignal with power-law frequency modulation.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[x,iflaw] = fmpower(N,k,P1)\n[x,iflaw] = fmpower(N,k,P1,P2)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty fmpower} generates a signal with a\n        power-law frequency modulation :\n        \\[x(t) = \\exp(j2\\pi(f_0 t + \\frac{c}{1-k} |t|^{1-k})).\\] \n \n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty N}  & number of points in time\\\\\n        {\\ty k}  & degree of the power-law ({\\ty k}$\\neq$1)\\\\\n        {\\ty P1} & if {\\ty nargin==3, P1} is a \n            vector containing the two coefficients {\\ty (f0 c)} for a\n            power-law instantaneous frequency (sampling frequency is set to 1).\n            If {\\ty nargin=4, P1} (as {\\ty P2}) is a time-frequency point of the \n            form {\\ty (ti fi)}. {\\ty ti} is in seconds and {\\ty fi} is a\n\t    normalized frequency (between 0 and 0.5). The coefficients {\\ty f0} \n            and {\\ty c} are then deduced such that the frequency modulation \n            law fits the points {\\ty P1} and {\\ty P2}\\\\\n        {\\ty P2} & same as {\\ty P1} if {\\ty nargin=4}         & optional\\\\\n  \\hline {\\ty x}  & time row vector containing the modulated signal samples\\\\\n        {\\ty iflaw} & instantaneous frequency law\\\\\n \n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         [x,iflaw]=fmpower(200,0.5,[1 0.5],[180 0.1]);\n         subplot(211); plot(real(x));\n         subplot(212); plot(iflaw);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\ngdpower, fmconst, fmlin, fmhyp, fmpar, fmodany, fmsin.\n\\end{verbatim}\n\\end{minipage}\n\n\n", "meta": {"hexsha": "e9cf50a06b35aa0d91197de776ac51d8dd5e4cdc", "size": 2279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/fmpower.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/fmpower.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/fmpower.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 27.130952381, "max_line_length": 81, "alphanum_fraction": 0.6121105748, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6434828091226021}}
{"text": "\\section{Ideals, Quotients, and Isomorphism Theorems}\r\n\\subsection{Definitions}\r\n\\begin{definition}\r\n    Let $R,S$ be rings.\r\n    A function $\\phi:R\\to S$ is called a ring homomorphism if it for any $r_1,r_2\\in R$\\\\\r\n    1. $\\phi(r_1+r_2)=\\phi(r_1)+\\phi(r_2)$.\\\\\r\n    2. $\\phi(r_1r_2)=\\phi(r_1)\\phi(r_2)$.\\\\\r\n    3. $\\phi(1_R)=1_S$.\\\\\r\n    If additionally this map is bijective, we call this an isomorphism.\\\\\r\n    The kernel of $\\phi$ is the set $\\ker\\phi=\\{r\\in R:\\phi(r)=0_S\\}$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    A ring homomorphism $\\phi:R\\to S$ is injective iff $\\ker\\phi=\\{0_R\\}$. \r\n\\end{lemma}\r\n\\begin{proof}\r\n    $\\phi$ is also a group homomorphism $(R,+)\\to (S,+)$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A subset $I\\subset R$ is called an ideal, written as $I\\unlhd R$, if $(I,+)\\le (R,+)$ and $\\forall r\\in R,rI\\subset I$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Note that an ideal needs not to be a subring since it might not contain $1$.\r\n    In fact, if $1\\in I$, then $\\forall r\\in R, r=r1\\in I$, so $I=R$.\r\n    In general, if $I$ contains a unit $u$, then $\\forall r\\in R,r=(ru^{-1})u\\in I$, so again $I=R$.\\\\\r\n    Therefore, a field can only have two ideals, $\\{0\\}$ and itself.\r\n\\end{remark}\r\nAn ideal $I\\neq R,\\{0\\}$ is called proper.\r\n\\begin{lemma}\r\n    Let $\\phi:R\\to S$ be a ring homomorphism, then $\\ker\\phi\\unlhd R$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $\\ker\\phi$ is obviously an additive subgroup of $R$.\r\n    Also $\\forall r\\in R,i\\in I,\\phi(ri)=\\phi(r)\\phi(i)=\\phi(r)0_S=0_S\\implies ri\\in\\ker\\phi$.\r\n    Hence $\\ker\\phi\\unlhd R$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    The only ideals of $\\mathbb Z$ are $n\\mathbb Z,n\\in\\mathbb Z$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    All of them are ideals and these are all possible additive subgroups.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For $a\\in R$, the ideal generated by $a$ is the ideal $(a)=\\{ra:r\\in R\\}$.\r\n\\end{definition}\r\nNote that $(a)$ is the smallest ideal that contains $a$.\r\nMore generally,\r\n\\begin{definition}\r\n    For $a_1,\\ldots,a_n\\in R$, the ideal generated by them is the ideal $(a_1,\\ldots,a_n)=\\{r_1a_1+\\cdots+r_na_n:r_i\\in R\\}$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    An ideal $I\\unlhd R$ is principle if $I=(a)$ for some $a\\in R$.\r\n\\end{definition}\r\nSo every ideal of $\\mathbb Z$ is principle.\r\n\\begin{theorem}\r\n    Let $I$ be an ideal of $R$, then we take the quotient $R/I$ as if they are additive groups.\r\n    We can define the multiplication on $R/I$ by defining $(a+I)(b+I)=ab+I$ which is well-defined and makes $R/I$ a ring.\r\n\\end{theorem}\r\nSuch $R/I$ is called the quotient ring.\r\nNote that the canonical projection (or quotient map) $\\pi:R\\to R/I$ becomes a ring homomorphism with kernel $I$, hence every ideal is the kernel of a homomorphism.\r\n\\begin{proof}\r\n    If $a+I=a'+I,b+I=b'+I$, then $a-a',b-b'\\in I$, so $ab-a'b'=a(b-b')+(a-a')b'\\in I$, therefore $ab+I=a'b'+I$, hence this multiplication is well-defined.\r\n    The rest follows.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. For $R=\\mathbb Z$, then the quotients are $\\mathbb Z/n\\mathbb Z$ with modulo $n$ addition and multiplication.\\\\\r\n    2. Consider the ideal generated by $X$ inside the poynomial $R[X]$, then $(X)$ consists of polynomials without a constant term.\r\n    The quotient is then $R[X]/(X)\\cong R$ with the isomorphism $r(X)\\mapsto r$.\\\\\r\n    3. Consider the ring of real polynomials $\\mathbb R[X]$ and the ideal $(X^2+1)$, then $\\mathbb R[X]/(X^2+1)=\\{f(X)+(X^2+1):f(X)\\in R[X]\\}$.\r\n    Now $\\mathbb R$ is a field, so every nonzero element is a unit, hence we can always do division algorithm.\r\n    So by applying this algorithm on $f(X)$, we have $\\mathbb R[X]/(X^2+1)=\\{a+bX+(X^2+1):f(X)\\in R[X]\\}$.\r\n    Now suppose $a+bX+(X^2+1)=a'+b'X+(X^2+1)$, then $(b-b')X+(a-a')=Q(X)(X^2+1)$ for some polynomial $Q$, but by looking at the degree, we must have $Q=0$, therefore $a=a',b=b'$, so each cosets are uniquely represented like this.\r\n    We then identify $a+bX+(X^2+1)\\mapsto a+bi\\in\\mathbb C$, but this is a ring isomorphism, so $\\mathbb R[X]/(X^2+1)\\cong\\mathbb C$.\r\n\\end{example}\r\n\\subsection{Isomorphism Theorems of Rings}\r\n\\begin{theorem}[(First) Isomorphism Theorem]\\label{ring_iso}\r\n    Let $\\phi:R\\to S$ be a ring homomorphism, then $\\ker\\phi$ is an ideal of $R$ and the quotient ring $R/\\ker\\phi$ is isomorphic to $\\operatorname{Im}\\phi\\le S$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We already saw that the kernel is an ideal and the quotient as additive group is isomorphic to $\\operatorname{Im}\\phi$ which we know is a subgroup of $(S,+)$.\r\n    Also $\\operatorname{Im}\\phi$ is closed under multiplication since $\\phi(r)\\phi(s)=\\phi(rs)$.\r\n    In addition $\\phi(1_R)=1_S$, so it is a subring of $S$.\r\n    Consider $\\Phi:R/\\ker\\phi\\to\\operatorname{Im}\\phi$ which takes a coset $r+\\ker\\phi$ to $\\phi(r)$.\r\n    This is well defined from results in groups.\r\n    It is obviously also a bijection and a group homomorphism under addition.\r\n    To check it is a ring homomorphism, we have $\\Phi(1_R+\\ker\\phi)=\\phi(1_R)=1_S$.\r\n    Also, $\\Phi((r+\\ker\\phi)(s+\\ker\\phi))=\\Phi(rs+\\ker\\phi)=\\phi(rs)=\\phi(r)\\phi(s)=\\Phi(r+\\ker\\phi)\\Phi(s+\\ker\\phi)$.\r\n    So it is a ring isomorphism.\r\n\\end{proof}\r\n\\begin{corollary}[Second Isomorphism Theorem]\r\n    Let $R\\le S$ and $J\\unlhd S$, then $R\\cap I\\unlhd R$ and $R+J\\le S$ and\r\n    $$R/(R\\cap J)\\cong (R+J)/J\\le S/J$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $R\\cap I\\unlhd R$ and $R+J\\le S$ are trivial.\r\n    Now consider the map $\\phi:R\\to S/J$ by $\\phi(r)=r+J$.\r\n    It is obviously a well-defined ring homomorphism as the composition of the inclusion $R\\to S$ and the quotient map $S\\to S/J$.\r\n    Its image is $(S+J)/J$ and its kernel is $R\\cap J$.\r\n    The result follows from Theorem \\ref{ring_iso}.\r\n\\end{proof}\r\nAnalogous to the situation in groups, we have (or want to have) a bijection between certain ideals of the ring $R$ and the ideals of the quotient ring $R/I$.\r\nStart with an ideal $K$ containing $I$, we can send it to $\\{r\\in R:r+I\\in K\\}$.\r\nIts inverse is just $J\\mapsto J/I$.\r\nThis motivates the Third Isomorphism Theorem.\r\n\\begin{corollary}[Third Isomorphism Theorem]\r\n    Let $I,J\\unlhd R$ such that $I\\subset J$, then $J/I\\unlhd R/I$ and\r\n    $$(R/I)/(J/I)\\cong R/J$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Consider $\\phi:R/I\\to R/J$ by $r+I\\mapsto r+J$.\r\n    Since $I\\subset J$, this is well-defined and obviously a ring homomorphism with kernel $J/I$.\r\n    Finish by Theorem \\ref{ring_iso}.\r\n\\end{proof}\r\n\\begin{example}\r\n    There is a surjective ring homomorphism $\\mathbb R[X]\\to\\mathbb C$ by\r\n    $$\\sum_{k=0}^na_kX^k\\mapsto \\sum_{k=0}^na_ki^k$$\r\n    Then the kernel, by division algorithm, would be $(X^2+1)$, hence we immediately obtain $\\mathbb R[X]/(X^2+1)\\cong\\mathbb C$ by Thoerem \\ref{ring_iso}\r\n\\end{example}\r\n\\begin{example}[Characteristic of a Ring]\r\n    For a ring $R$, there is an unique ring homomorphism $\\mathbb Z\\to R$.\r\n    The uniqueness is obvious since a ring homomorphism must map the multiplicative identity to multiplicative identity.\r\n    The existence can be shown by simply constructing $\\iota:n\\mapsto 1_R+1_R+\\cdots +1_R$ where there are $n$ of $1_R$'s added together.\r\n    Similarly $\\iota:-n\\mapsto -(1_R+1_R+\\cdots +1_R)$ where again there are $n$ of $1_R$'s in the bracket.\r\n    So $\\ker\\iota\\unlhd\\mathbb Z$, hence $\\ker\\iota=n\\mathbb Z$ for some $n\\in\\mathbb N_0$.\r\n\\end{example}\r\n\\begin{definition}\r\n    We say $n$ is the characteristic $\\operatorname{char}(R)$ of $R$.\r\n\\end{definition}\r\nBy Theorem \\ref{ring_iso}, $\\mathbb Z/n\\mathbb Z\\cong\\operatorname{Im}\\iota\\le R$.\r\n\\begin{example}\r\n    $\\mathbb Z,\\mathbb Q,\\mathbb R,\\mathbb C$ all have characteristic $0$, and $\\mathbb Z/p\\mathbb Z$ has characteristic $p$.\r\n\\end{example}", "meta": {"hexsha": "6c1cc4e41adf9c135df835e73f3036fdc3724e18", "size": 7687, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/ideal.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": "8/ideal.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": "8/ideal.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": 58.679389313, "max_line_length": 230, "alphanum_fraction": 0.6564329387, "num_tokens": 2655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.6434828028473213}}
{"text": "\\section{Chebyshev and Lagrange interpolation}\n\nIn the following functions, the domains are defined for all $\\delta>0$ or $r>0$, so in finding Chebyshev nodes for interpolation, only nodes\nin this domain are filtered from a list of possibilities. Thus, when selecting $n$ nodes, we actually select more, of which the negative values are discarded.\nUsing the Lagrange polynomial interpolation method, these nodes are used to find an approximating polynomial.\n\n\\subsection{Interpolation of \\texorpdfstring{$\\phi_0,\\phi_\\mathrm{min}$}{}}\n\nIn Figure \\ref{phi0lg} and \\ref{phimlg}, 9 Chebyshev nodes were used to generate an approximating polynomial.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.45]{plots/phi0_lagrange.pdf}\n        \\caption{Lagrange polynomial approximation of $\\phi_0$ with equation $g$}\\label{phi0lg}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.45\\textwidth}\n        \\centering\n        \\includegraphics[scale=0.45]{plots/phimin_lagrange.pdf}\n        \\caption{Lagrange polynomial approximation of $\\phi_\\mathrm{min}$}\\label{phimlg}\n    \\end{minipage}\n\\end{figure}\n\nPolynomial for $\\phi_0$:\n\n\\begin{equation}\n    f_1(\\delta)=1044\\delta^{8}-4892\\delta^{7}+9693\\delta^{6}-10531\\delta^{5}+6800\\delta^{4}-2638\\delta^{3}+589\\delta^{2}-67\\delta^{1}+3\n\\end{equation}\n\nPolynomial for $\\phi_\\mathrm{min}$:\n\n\\begin{equation}\n    f_2(\\delta)=3968\\delta^{8}-18749\\delta^{7}+37405\\delta^{6}-40874\\delta^{5}+26519\\delta^{4}-10327\\delta^{3}+2311\\delta^{2}-263\\delta^{1}+11\n\\end{equation}\n\nThe coefficients displayed here are rounded to the nearest whole number in order to make for readable output.\n\n\\subsection{Interpolation of \\texorpdfstring{$y(r)$}{}}\n\nAs shown in Figure \\ref{yrpoly}, the Cheybshev node method yielded far more accurate results for the function $y(r)$, save for the initial spike/irregularity in the function when it is increasing.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.8]{plots/yr_poly.pdf}\n    \\caption{Lagrange polynomial approximation for $y(r)$}\\label{yrpoly}\n\\end{figure}\n\nThe equation of the Lagrange polynomial is:\n\\begin{equation}\n    f_3(r)=-282r^{8}+3195r^{7}-15828r^{6}+44706r^{5}-78750r^{4}+88591r^{3}-62158r^{2}+24872r^{1}-4346\n\\end{equation}\n\n\\subsubsection{Integral approximation for \\texorpdfstring{$\\frac{dr}{dt}=y(r)$}{}}\n\nThe definition given is $y(r)=\\frac{dr}{dt}$. This can be rearranged to\n\n\\begin{equation}\n    \\frac{dr}{y(r)}=dt\n\\end{equation}\n\nTaking the indefinite integral on both sides (the limit on the side with $r$ is from $r_0=1$ to $r_m$ where $y(r_m)=1|r_m > 1$ and from $0$ to some $t_f$ for the side with $t$) we get\n\n\\begin{equation}\n    \\int_{1}^{r_m}\\frac{dr}{y(r)}=\\int_0^{t_f}dt\n\\end{equation}\n\nUsing the approximation in Eq. 30, this becomes\n\n\\begin{equation}\n    \\int_{1}^{r_m}\\frac{dr}{f_3(r)}=\\int_0^{t_f}dt\n\\end{equation}\n\nUsing an optimized solver, the unknown is $t_f=4.52624262$.\n\n\\subsection{Limitations and future goals}\n\n\\begin{itemize}\n    \\item The NumPy Lagrange solver does not allow for specification of some tolerance $\\epsilon$\n    \\begin{itemize}\n        \\item A potential solution could be to implement the Lagrange polynomial method from scratch, where a tolerance could be specified\n    \\end{itemize}\n    \\item Another interpolation routine that could be used is the Newton polynomial method, which could also be implemented manually in order to specify a tolerance\n\\end{itemize}\n", "meta": {"hexsha": "f2fd6d64d6f1745eedd68436307205eca45afdfe", "size": 3472, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/interpolation.tex", "max_stars_repo_name": "sidnb13/ut-aero-research", "max_stars_repo_head_hexsha": "4c0b3fbbabf9faed1414d28ad4307545378795b8", "max_stars_repo_licenses": ["MIT"], "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/interpolation.tex", "max_issues_repo_name": "sidnb13/ut-aero-research", "max_issues_repo_head_hexsha": "4c0b3fbbabf9faed1414d28ad4307545378795b8", "max_issues_repo_licenses": ["MIT"], "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/interpolation.tex", "max_forks_repo_name": "sidnb13/ut-aero-research", "max_forks_repo_head_hexsha": "4c0b3fbbabf9faed1414d28ad4307545378795b8", "max_forks_repo_licenses": ["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.8470588235, "max_line_length": 196, "alphanum_fraction": 0.7255184332, "num_tokens": 1083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.6434828013105878}}
{"text": "\\mychapter{7}{Lesson 7} %181017\n\n\\subsubsection{\\textsc{Ggm}-tree (cont'd)}\n\n% Reminders: k is the scheme key\nAs stated in the previous lesson, given a \\prg{} $G \\in \\binary^\\lambda \\to \\binary^{2\\lambda}$, we can build a function family $f_k$ by repeatedly taking halves of $G$'s images, and plugging them back into $G$. Our goal is to prove the following theorem:\n\n\\begin{theorem}\n    If $G$ is a \\prg, then $f_k$ is a \\prf.\n\\end{theorem}\n\n% AP190103: All notation is still left in an inconsistent state, it's difficult here to establish which things can go where...\n\\begin{proof}\n\n    Before starting to prove the \\prf-ness of $f_k$, we make a brief consideration about its time complexity: computing $f_k(x)$ consists in computing $G$ and taking half of the resulting image as many times as is the length of $x$. Since the length of $x$ is polynomial in $\\lambda$, so is the number of $G$'s iterations; combine this with the fact that $G$ is itself polynomial by definition, and we conclude that $f_k$ is polynomial too.\n\n    Having cleared any doubts about $f_k$'s time complexity, we now turn to the essential point of interest: its pseudo-randomness. The proof will proceed by induction over the length of $x$, which is also the height of the tree-like structure modeling the algorithm.\n    \n    \\textbf{Base case} ($n = 1$): $f_k$'s domain is restricted to $\\binary$, meaning that its images will be respectively the two halves on a single iteration of $G(k)$; they are, of course, pseudorandom by $G$'s definition:\n    \\[\n        (f_k(0), f_k(1)) = (G_0(k), G_1(k)) \\compindist U_{2\\lambda}\n    \\]\n    therefore, in this case, $F_k$ is pseudorandom.\n\n    % AP190103: Here too...\n    \\textbf{Inductive step}: Let $f'_k : \\binary^{n - 1} \\to \\binary^\\lambda$ be a \\prf. Define $f_k$ as follows:\n    \\[\n        f_k : \\binary^n \\to \\binary^\\lambda : (b, x) \\in \\binary \\times \\binary^{n - 1} \\mapsto G_b(f'_k(x))\n    \\]\n    It must be proven that if $f_k'$ is a \\prf, then so is $f_k$. To help ourselves, we'll define some hybrid games as usual. These are depicted in figures \\ref{cryptogame:ggmhyb1} and \\ref{cryptogame:ggmhyb2}.\n\n    \\begin{cryptogame}\n        {ggmhyb1}\n        {$\\hybridg{1}[f_k](\\lambda, b)$: The \\ggm{} construct is put against randomly driven \\prg}\n        {n-th}\n\n        \\cseqchallenger{\\shortstack[l]{\n            $k \\pickUAR \\binary^\\lambda$ \\\\\n            $\\overline{R} \\pickUAR \\mathfrak{R}(n-1, \\lambda)$ \\\\\n            $b \\pickUAR \\binary$\n        }}\n\n        \\cseqdelay\n        \\cseqbeginloop\n        \\send{}{$r = (r_0, r_{1 \\upto n})$}{}\n        \\receive{\\shortstack[l]{\n            $y_0 = G_{r_0}(f'_k(r_{1 \\upto n})) = f_k(r)$ \\\\\n            $y_1 = G_{r_0}(\\overline{R}(r_{1 \\upto n}))$\n        }}{$y_b$}{}\n        \\cseqendloop\n        \\cseqdelay\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b = b'$}\n\n    \\end{cryptogame}\n\n    \\begin{cryptogame}\n        {ggmhyb2}\n        {$\\hybridg{2}[\\overline{R} \\circ G](\\lambda, b)$: The randomly driven \\prg{} against a true random function}\n        {n-th}\n\n        \\cseqchallenger{\\shortstack[l]{\n            $\\overline{R} \\pickUAR \\mathfrak{R}(n-1, \\lambda)$ \\\\\n            $R \\pickUAR \\mathfrak{R}(n, \\lambda)$ \\\\\n            $b \\pickUAR \\binary$\n        }}\n\n        \\cseqdelay\n        \\cseqbeginloop\n        \\send{}{$r = (r_0, r_{1 \\upto n})$}{}\n        \\receive{\\shortstack[l]{\n            $y_0 = G_{r_0}(\\overline{R}(r_{1 \\upto n}))$ \\\\\n            $y_1 = R(r)$\n        }}{$y_b$}{}\n        \\cseqendloop\n        \\cseqdelay\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b = b'$}\n\n    \\end{cryptogame}\n    \n    We are going to prove, in the scope of a single induction step, that these hybrids bridge indistinguishability for the original game. It is all that's needed to complete the proof.\n\n    \\begin{lemma}\n        $\\hybridg{1}[f_k](\\lambda, 0) \\compindist \\hybridg{1}[f_k](\\lambda, 1)$       \n    \\end{lemma}\n\n    \\begin{proof}\n        Assume $\\exists \\distinguisher^{\\textsc{n-th}} \\in \\ppt$ that can distinguish $f_k$ from $\\overline{R} \\circ G$ at the $n$-th step; then an adversary \\adversary{} can use it to break in turn $f'_k$'s \\prf-ness, and distinguish it from $\\overline{R} \\circ G$ as shown in figure \\ref{cryptoredux:ggmhyb1}:\n\n        % AP190103: It is not immediately clear by the sequence that we're simulating two games in two different \"inductive\" steps, instead of trying to break one standard assumption\n        % The reasoning is: distinguish the hybrids, simulate the induction steps\n        \\begin{cryptoredux}\n            {ggmhyb1}\n            {Using $\\distinguisher^{\\textsc{n-th}}$ to break $f'_k$}\n            {f'-prf}\n            {n-th}\n\n            \\cseqchallenger{\\shortstack[l]{\n                $k \\pickUAR U_{\\lambda - 1}$ \\\\\n                $\\overline{R} \\pickUAR \\mathfrak{R}(n - 1, \\lambda)$ \\\\\n                $b \\pickUAR \\binary$\n            }}\n\n            \\cseqbeginloop\n            \\return{}{$(r_0, r_{1 \\dots n})$}{}\n\n            \\send{}{$r_{1 \\dots n}$}{}\n\n            \\receive{\\shortstack[l]{\n                $z_0 = f_k'(r_{1 \\dots n})$ \\\\\n                $z_1 = \\overline{R}(r_{1 \\dots n})$\n            }}{$z_b$}{}\n\n            \\cseqdelay\n\n            \\invoke{\\shortstack[l]{\n                $y_b = G_{r_0}(z_b)$  % AP190909 - IMPORTANT : Make a note here: y is either f_k or R \\circ G\n            }}{$y_b$}{}\n\n            \\cseqendloop\n\n            \\return{}{$b'$}{}\n\n            \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n        \\end{cryptoredux}\n\n    \\end{proof}\n\n    Before tackling $\\hybridg{2}[\\overline{R}](\\lambda, b)$, it is best to introduce another lemma:\n\n    \\begin{lemma}\n        If $G : \\binary^\\lambda \\to \\binary^{2 \\lambda}$ is a \\prg, then:\n        \\[\n            \\forall K_i \\sim \\unifdist(\\lambda) \\iid \\implies (G(K_1), \\dots , G(K_t)) \\compindist (U_{2 \\lambda}, \\dots , U_{2\\lambda}) \\qedhere\n        \\]\n    \\end{lemma}\n\n    \\begin{proof}\n        \\todo{Idea: all values are independent and pseudorandom on their own, hybridize progressively...}\n        % AP190909: Wait: isn't that a property of a PRG already? No, the definition states indist for a single sample, not for an arbitrary sequence; hence the idea, btw\n    \\end{proof}\n\n    Now for the final lemma:\n\n    \\begin{lemma}\n        $\\hybridg{2}[\\overline{R} \\circ G](\\lambda, 0) \\compindist \\hybridg{2}[\\overline{R} \\circ G](\\lambda, 1)$       \n    \\end{lemma}\n    \n    %AP190912: May need to flesh out some images here, especially a cryptoredux drawing...\n    \\begin{proof}\n\n        \\todo{Need figures here}\n\n        This proof is trickier: the problem lies in the inherent difference between the task of detecting a \\prg{} from that of detecting a \\prf{}. The aforementioned lemma helps us with the aspect of polynomial queries on a \\prg{}, bringing it in line with the \\prf{} game; yet, we're far from done.\n\n        Let's delve into the details: from \\adversary's perspective, the game of distinguishing $\\overline{R} \\circ G$ from $R$ , where \\distinguisher{} performs a number of queries $q$ polynomial in $\\lambda$, is perfectly modeled by the act of distinguishing a sequence of evaluations $(G(K_1), \\dots, G(K_q))$ from $(U_{2\\lambda}, \\dots, U_{2\\lambda})$. Therefore, the game can be twisted in a way that \\adversary{} receives either one of the two whole sequences beforehand, and respects the rules by sending to $D$ the right piece of information on each of its queries, in order to simulate the $\\overline{R} \\circ G$/$R$ game correctly.\n\n        At this point, the simple way for A to send the right info on each query $i$ would be to check whether the query's first bit $r_0$ would be $0$ or $1$, and give back to \\distinguisher{} either the first or the second half of the i-th value of the sequence he received from \\challenger{}; this is exactly how \\ggm{} operates. However, there's a catch: \\distinguisher{} might make two queries where the r1---n parts are the same, the only difference is in the first bit: essentially, D is asking for both parts of G(r) from two distinct queries. In this case, if \\adversary{} just sends the i-th value's corresponding half, the simulation would break, because the halves come from different samples.\n        \n        Thus, the adversary must keep track of which suffixes he has been already queried about, and make sure to send the value's other half (there are only two) whenever he is queried on a suffix for a second time. This final touch solves the problem of simulating the game for D, and now the task of A is changed to an equivalent one of breaking the lemma stated at the beginning.\n        \n        \\todo{Prata's notes:\n        \n        Let T1, T2 be empty tables.\n\n        Given query x input x1---n let xbar=x1---i\n\n        if xbar notin T1 then x <-\\$ binarylambda and add k\\_xbar to T2\n\n        if xbar in T2 let k\\_xbar = T2[T1[xbar]]\n\n        output y = G\\_x\\_n(g\\_x\\_n-1(...G\\_x\\_i+1(k\\_xbar)))\n\n        H\\_0: GGM tree\n        \n        H\\_n: random function\n\n        exploit lemma prg => prf\n        }\n        \n    \\end{proof}\n\n    In the end the hybrids are proven to mutually indistinguishable, therefore the inductive step is correct, proving the theorem.\n\n\\end{proof}\n\n\\section{\\textsc{Cpa}-security}\n\nNow it's time to define a stronger notion of security, which is widely used in cryptology for first assessments of cryptographic strength. Let $\\Pi := (\\Enc, \\Dec)$ be a \\ske{} scheme, and consider the game depicted in figure \\ref{cryptogame:cpadef}. Observe that this time, the adversary can ``query'' the challenger for the ciphertexts of any messages of his choice, with the only reasonable restriction that the query amount must be polynomially bound by $\\lambda$. This kind of game/attack is called the \\emph{Chosen Plaintext Attack}, because of the adversary's capability of obtaining ciphertexts from messages. The usual victory conditions found in n-time security games, which are based on ciphertext distinguishability, apply.\n\n\\begin{cryptogame}\n    {cpadef}\n    {The \\cpa-security game: $\\cryptog{cpa}(\\lambda, b)$}\n    {cpa}\n\n    \\cseqchallenger{$k \\pickUAR \\binary^\\lambda$}\n\n    \\cseqbeginloop\n    \\send{}{$m$}{}\n    \\receive{$c \\pickUAR \\Enc(k, m)$}{$c$}{}\n    \\cseqendloop\n\n    \\cseqdelay\n\n    \\send{}{$m_0^*, m_1^*$}{}\n    \\receive{\\shortstack[l]{\n        $b \\pickUAR \\binary$ \\\\\n        $c^* \\pickUAR \\Enc(k, m_b^*)$\n    }}{$c^*$}{}\n\n    \\cseqdelay\n\n    \\cseqbeginloop\n    \\send{}{$m$}{}\n    \\receive{$c \\pickUAR \\Enc(k, m)$}{$c$}{}\n    \\cseqendloop\n\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n\\end{cryptogame}\n\n\\begin{definition}\n    A scheme is \\cpa-secure if $\\cryptog{cpa}(\\lambda, 0) \\compindist \\cryptog{cpa}(\\lambda, 1)$\n\\end{definition}\n\n\nHaving given this definition of security, recall the $\\Pi_\\oplus$ scheme defined in the previous lesson. It is easy to see that $\\Pi_\\oplus$ is not \\cpa-secure for the same reasons that it is not computationally 2-time secure; however this example sheds some new light about a deeper problem:\n\n%AP181230: Refer to page 72 of Katz-Lindell for a good explanation\n\\begin{observation}\n    No deterministic scheme can achieve \\cpa-security.\n\\end{observation}\n\nThis is true, because nothing prevents the adversary from asking the challenger to encrypt either $m_0$ or $m_1$, or even both, before starting the actual challenge; just as in the 2-time case for $\\Pi_\\oplus$, he will know the messages' ciphertexts in advance, so he will be able to tell which message the challenger has encrypted every time. The solution for obtaining a \\cpa-secure encryption scheme consists of returning different ciphertexts for the same message, even better if they look random. This can be achieved by using \\prf{}s.\n\nConsider the following \\ske{} scheme $\\Pi_{f_k}$, where $f_k$ is a \\prf{} structured as follows:\n\n\\begin{itemize}\n    \\item $\\Enc(k, m) = (c_1, c_2) = (r, f_k(r) \\oplus m)$, where $k \\pickUAR \\binary^\\lambda$ and $r \\pickUAR \\binary^n$\n    \n    \\item $\\Dec(k, (c_1, c_2)) = f_k(c_1) \\oplus c_2$\n\\end{itemize}\n\nObserve that the random value $r$ is part of the ciphertext, making it long $n+l$ bits; also more importantly, the adversary can and will always see $r$. The key $k$ though, which gives a \\textit{flavour} to the \\prf, is still secret.\n\n\\begin{theorem} \\label{thm:prfcpa}\n    If $f_k$ is a \\prf, then $\\Pi_{f_k}$ is \\cpa-secure.\n\\end{theorem}\n\n\\begin{proof}\n    We have to prove that $\\cryptog{cpa}[\\Pi_{f_k}](\\lambda, 0) \\compindist \\cryptog{cpa}[\\Pi_{f_k}](\\lambda, 1)$; to this end, the hybrid argument will be used. Let the first hybrid $\\hybridg{0}$ be the original game, the second hybrid $\\hybridg{1}$ will have a different encryption routine:\n\n    \\begin{itemize}\n        \\item $r \\pickUAR \\binary^n$\n        \\item $R \\pickUAR \\mathfrak{R}(n, l)$\n        \\item $c = (r, R(r) \\oplus m)$, where $m$ is the plaintext to be encrypted\n    \\end{itemize}\n\n    and then the last hybrid $\\hybridg{2}$ will simply output $(r_1, r_2) \\pickUAR U_{n + l}$.\n\n    \\begin{lemma}\n        $\\forall b \\in \\binary \\implies \\hybridg{0}(\\lambda, b) \\compindist \\hybridg{1}(\\lambda, b)$.\n    \\end{lemma}\n\n    \\begin{proof}\n        As usual, the proof is by reduction: suppose there exists a distinguisher \\distinguisher{} capable of telling the two hybrids apart; then \\distinguisher{} can be used to break $f_k$'s property of being a \\prf. The way to use \\distinguisher{} is to make it play a \\cpa-like game, as shown in figure \\ref{cryptoredux:prfcpa}\\footnotemark, where the adversary attempting to break $f_k$ decides which message to encrypt between $m_0$ and $m_1$ beforehand, and checks whether it guesses which message has been encrypted. Either way, the adversary can get a sensible probability gain in guessing if the received values from the challenger were random, or generated by $f_k$. Thus, assuming such \\distinguisher{} exists, \\adversary{} can efficiently break $f_k$, contradicting its \\prf-ness.\n\n        \\footnotetext{An observant student may notice a striking similarity with a previously exposed reduction in figure \\ref{cryptoredux:xorotprg}}\n\n        % AP190101: Potrei includere una definizione alternativa di prf più su, in modo tale che questa riduzionie sia un po' più chiara\n\n        \\begin{cryptoredux}\n            {prfcpa}\n            {Breaking a \\prf, for fixed message choice of $m_0$}\n            {prf}\n            {cpa}\n\n            \\cseqchallenger{\\shortstack[l]{\n                $k \\pickUAR \\binary^\\lambda$ \\\\\n                $R \\pickUAR \\mathfrak{R}(n, l)$ \\\\\n                $b \\pickUAR \\binary$\n            }}\n        \n            \\cseqbeginloop\n            \\return{}{$m$}{}\n            \\send{$r \\pickUAR \\binary^n$}{$r$}{}\n            \\receive{\\shortstack[l]{\n                $z_0 \\pickUAR f_k(r)$ \\\\\n                $z_1 \\pickUAR R(r)$\n            }}{$z_b$}{}\n            \\invoke{$c = (r, z_b \\oplus m)$}{$c$}{}\n            \\cseqendloop\n\n            \\cseqdelay\n        \n            \\return{}{$m_0^*, m_1^*$}{}\n            \\send{$r^* \\pickUAR \\binary^n$}{$r^*$}{}\n            \\receive{\\shortstack[l]{\n                $z_0^* \\pickUAR f_k(r)$ \\\\\n                $z_1^* \\pickUAR R(r)$\n            }}{$z_b^*$}{}\n            \\invoke{$c^* = (r^*, z_b^* \\oplus m_0^*)$}{$c^*$}{}\n\n            \\cseqdelay\n        \n            \\cseqbeginloop\n            \\return{}{$m$}{}\n            \\send{$r \\pickUAR \\binary^n$}{$r$}{}\n            \\receive{\\shortstack[l]{\n                $z_0 \\pickUAR f_k(r)$ \\\\\n                $z_1 \\pickUAR R(r)$\n            }}{$z_b$}{}\n            \\invoke{$c = (r, z_b \\oplus m)$}{$c$}{}\n            \\cseqendloop\n            \n            \\cseqdelay\n        \n            \\return{}{$b'$}{}\n\n            \\cseqdelay\n\n            \\send{$b'' = \\begin{cases}\n                0 &\\textsc{iff } b' = 0 \\\\\n                1 &\\textsc{else}\n            \\end{cases}$\n            }{$b''$}{\\textsc{Output 1 iff} $b'' = b$}\n        \n        \\end{cryptoredux}\n\n    \\end{proof}\n\n    \\begin{lemma}\n        $\\forall b \\in \\binary \\implies \\hybridg{1}(\\lambda, b) \\compindist \\hybridg{2}(\\lambda, b)$.\n    \\end{lemma}\n\n    \\begin{proof}\n        Firstly, it can be safely assumed that any ciphertext $(r_i, R(r_i) \\oplus m_b)$ distributes equivalently with its own sub-value $R(r_i)$, because of $R$'s true randomness, and independency from $m_b$.\n\n        %AP190102: An image visualizing the repeat event might be very useful\n        Having said that, the two hybrids apparently distribute uniformly, making them perfectly equivalent; however there is a caveat: if both games are run and one value $\\overline{r}$ is queried twice in both runs, then on the second query the adversary will receive the same image in $\\hybridg{1}$, but almost certainly a different one in $\\hybridg{2}$. This is because the first hybrid uses a function, which is deterministic by its nature, whereas the image in the second hybrid is picked completely randomly from the codomain. Nevertheless, this sneaky issue about \"collisions\" can be proven to happen with negligible probability.\n\n        Call \\textsc{Repeat} this collision event on $\\overline{r}$ between 2 consecutive games. Then:\n        \n        % AP190102: Could use some clarifications? Especially about what the indices represent\n        \\begin{align*}\n        \\Pr[\\textsc{Repeat}] &= \\Pr[\\exists i, j \\in q \\text{ such that } r_i = r_j] \\\\\n            &\\leq \\sum_{i \\neq j} \\Pr[r_i=r_j] \\\\\n            &= Col(U_n) \\\\\n            &= \\sum_{i \\neq j} \\sum_{e \\in \\binary^n} \\Pr[r_1 = r_2 = e] \\\\\n            &= \\sum_{i \\neq j} \\sum_{e \\in \\binary^n} \\Pr[r = e]^{2} \\\\\n            &= \\binom{q}{2} 2^{n} \\frac{1}{2^{2n}} \\\\\n            &= \\binom{q}{2} 2^{-n} \\\\\n            &\\leq q^{2}2^{-n} \\in \\negl{\\lambda} \n        \\end{align*} \n\n\n        which proves that the \\textsc{Repeat} influences negligibly on the two hybrids' equivalence. Thus $\\hybridg{1}(\\lambda, b) \\compindist \\hybridg{2}(\\lambda, b)$\\footnotemark.\n        \n        \\footnotetext{Do note that the hybrids lose their originally supposed perfect equivalence ($\\hybridg{1}(\\lambda, b) \\equiv \\hybridg{2}(\\lambda, b)$) because of the \\textsc{Repeat} event. Nevertheless, the lemma is still proven because it includes computational bounds into \\adversary}\n    \\end{proof}\n\n    With the above lemmas, and observing that $\\hybridg{2}(\\lambda, 0) \\equiv \\hybridg{2}(\\lambda, 1)$, we can reach the conclusion that $\\hybridg{0}(\\lambda, 0) \\compindist \\hybridg{0}(\\lambda, 1)$, which is what we wanted to demonstrate.\n\n\\end{proof}\n", "meta": {"hexsha": "e0fdc35f38508820fced48cf53315b05a494d903", "size": 18444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_7.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_7.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_7.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": 49.9837398374, "max_line_length": 792, "alphanum_fraction": 0.6255692908, "num_tokens": 5527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8397339756938819, "lm_q1q2_score": 0.6434827984938158}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsfonts}\n\\usepackage{bm}\n\n% symbol used for sqrt(-1)\n\\newcommand{\\Ci}{{\\rm i}}\n\n\\newcommand{\\C}{\\mathbb{C}}\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\newcommand{\\code}[1]{{\\tt{#1}}}\n\n\\newcommand{\\boost}[1][]{{\\ensuremath{ {\\bf H}{#1}_{\\bm{\\hat m}}(\\beta) }}}\n\\newcommand{\\rotat}[1][]{{\\ensuremath{ {\\bf U}{#1}_{\\bm{\\hat n}}(\\phi) }}}\n\n\\newcommand{\\pauli}[1]{\\ensuremath{ {\\bm\\sigma}_{\\rm #1} }}\n\n\\newcommand{\\pdi}[2]{\\ensuremath{ {{\\delta {#2}}\\over{\\delta {#1}}} }}\n\n\\begin{document}\n\n\\section{Quaternion Differentiation}\n\nA quaternion, $\\bm{H}$, may be represented by the linear combination,\n\\begin{equation}\n\\bm{H}=\\sum_{i=0}^3 h_i\\pauli{i}\n\\end{equation}\nwhere:\n\\begin{equation}\\label{eqn:properties}\n\\pauli{i}^2 = \\pauli{i}\\pauli{j}\\pauli{k} = -\\pauli{0},\n\\end{equation}\nand $\\{i,j,k\\}$ is chosen from cyclic permutations of $\\{1,2,3\\}$.\nA quaternion function, $\\bm{F}(\\bm{H})$, may then be written as\n\\begin{equation}\n\\bm{F}(\\bm{H})=\\sum_{i=0}^3 f_i(h_0,h_1,h_2,h_3)\\pauli{i}\n\\end{equation}\nIf $\\bm{F}(\\bm{H})$ is single-valued function of $\\bm{H}$, the derivative\nof $\\bm{F}(\\bm{H})$ is defined as\n\\begin{equation}\n\\bm{F}^\\prime(\\bm{H}) = \\lim_{\\bm{\\Delta H}\\to0}\n\t{ {\\bm{F}(\\bm{H}+\\bm{\\Delta H}) - \\bm{F}(\\bm{H})}\\over{\\bm{\\Delta H}} }\n\\end{equation}\nprovided that the limit exists independent of the manner in which\n$\\bm{\\Delta H}\\to0$.  Consider four possible ways that $\\bm{\\Delta H}$ may\napproach zero, in which all but one of $\\Delta h_i$ equals zero.  The\nfour cases may be written as:\n\\begin{equation}\n\\bm{F}^\\prime(\\bm{H})_j = \\sum_{i=0}^3 \n{ {\\delta{f_i}\\pauli{i}}\\over{\\delta{h_j}\\pauli{j}} } \n\\end{equation}\nwhich can be expanded to produce\n\\begin{eqnarray}\n\\bm{F}^\\prime(\\bm{H})_0 =\n  { {\\delta{f_0}}\\over{\\delta{h_0}} }\\pauli{0}\n+ { {\\delta{f_1}}\\over{\\delta{h_0}} }\\pauli{1}\n+ { {\\delta{f_2}}\\over{\\delta{h_0}} }\\pauli{2}\n+ { {\\delta{f_3}}\\over{\\delta{h_0}} }\\pauli{3} \\\\\n\\bm{F}^\\prime(\\bm{H})_1 =\n  { {\\delta{f_1}}\\over{\\delta{h_1}} }\\pauli{0}\n- { {\\delta{f_0}}\\over{\\delta{h_1}} }\\pauli{1}\n- { {\\delta{f_3}}\\over{\\delta{h_1}} }\\pauli{2}\n+ { {\\delta{f_2}}\\over{\\delta{h_1}} }\\pauli{3} \\\\\n\\bm{F}^\\prime(\\bm{H})_2 =\n  { {\\delta{f_2}}\\over{\\delta{h_2}} }\\pauli{0}\n+ { {\\delta{f_3}}\\over{\\delta{h_2}} }\\pauli{1}\n- { {\\delta{f_0}}\\over{\\delta{h_2}} }\\pauli{2}\n- { {\\delta{f_1}}\\over{\\delta{h_2}} }\\pauli{3} \\\\\n\\bm{F}^\\prime(\\bm{H})_3 =\n  { {\\delta{f_3}}\\over{\\delta{h_3}} }\\pauli{0}\n- { {\\delta{f_2}}\\over{\\delta{h_3}} }\\pauli{1}\n+ { {\\delta{f_1}}\\over{\\delta{h_3}} }\\pauli{2}\n- { {\\delta{f_0}}\\over{\\delta{h_3}} }\\pauli{3}\n\\end{eqnarray}\nEquating (6)-(9) yields:\n\\begin{eqnarray}\n+ { {\\delta{f_0}}\\over{\\delta{h_0}} } = + { {\\delta{f_1}}\\over{\\delta{h_1}} } =\n+ { {\\delta{f_2}}\\over{\\delta{h_2}} } = + { {\\delta{f_3}}\\over{\\delta{h_3}} }\\\\\n+ { {\\delta{f_1}}\\over{\\delta{h_0}} } = - { {\\delta{f_0}}\\over{\\delta{h_1}} } =\n+ { {\\delta{f_3}}\\over{\\delta{h_2}} } = - { {\\delta{f_2}}\\over{\\delta{h_3}} }\\\\\n+ { {\\delta{f_2}}\\over{\\delta{h_0}} } = - { {\\delta{f_3}}\\over{\\delta{h_1}} } =\n- { {\\delta{f_0}}\\over{\\delta{h_2}} } = + { {\\delta{f_1}}\\over{\\delta{h_3}} }\\\\\n+ { {\\delta{f_3}}\\over{\\delta{h_0}} } = + { {\\delta{f_2}}\\over{\\delta{h_1}} } =\n- { {\\delta{f_1}}\\over{\\delta{h_2}} } = - { {\\delta{f_0}}\\over{\\delta{h_3}} }\n\\end{eqnarray}\nDefine the quaternion ``del'' operator:\n\\begin{equation}\n\\bm{\\Delta}= {\\delta\\over\\delta h_0}\\pauli{0} \n\t- \\sum_{i=1}^3{\\delta\\over\\delta h_i}\\pauli{i}\n\\end{equation}\nthen\n\\begin{eqnarray}\n(\\bm{\\Delta F})_0\n  = \\pdi{h_0}{f_0} + \\pdi{h_1}{f_1} + \\pdi{h_2}{f_2} + \\pdi{h_3}{f_3}\n  = 4\\pdi{h_0}{f_0}\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n(\\bm{\\Delta F})_1\n  = \\pdi{h_0}{f_1} - \\pdi{h_1}{f_0} - \\pdi{h_2}{f_3} + \\pdi{h_3}{f_2} = 0 \\\\\n(\\bm{\\Delta F})_2\n  = \\pdi{h_0}{f_2} + \\pdi{h_1}{f_3} - \\pdi{h_2}{f_0} - \\pdi{h_3}{f_1} = 0 \\\\\n(\\bm{\\Delta F})_3\n  = \\pdi{h_0}{f_3} - \\pdi{h_1}{f_2} + \\pdi{h_2}{f_1} - \\pdi{h_3}{f_0} = 0\n\\end{eqnarray}\nThat is, if a quaternion function is differentiable, then its gradient\nis scalar and equal to four times the partial derivative of the scalar\ncomponent of $\\bm{F}$ ($f_0$) with respect to the scalar component of \n$\\bm{H}$ ($h_0$).\n\\end{document}\n\n\n", "meta": {"hexsha": "58ff25537bbd716a6578e1f2f6651987745657b2", "size": 4161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Util/units/QuaternionCalculus.tex", "max_stars_repo_name": "xuanyuanstar/psrchive_CDFT", "max_stars_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/units/QuaternionCalculus.tex", "max_issues_repo_name": "xuanyuanstar/psrchive_CDFT", "max_issues_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/units/QuaternionCalculus.tex", "max_forks_repo_name": "xuanyuanstar/psrchive_CDFT", "max_forks_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1517857143, "max_line_length": 79, "alphanum_fraction": 0.5986541697, "num_tokens": 1927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6434827923468822}}
{"text": "\\subsection{Data} \\label{subsec:data_linear_regression}\nIn this project, we are fitting $2D$ polynomials to the Franke function with gaussian noise. The Franke function is defined as\n\\begin{equation}\n    \\begin{split}\n        f(x_1,x_2) := \\frac{3}{4}\\exp{\\left(-\\frac{(9x_1-2)^2}{4}-\\frac{(9x_2-2)^2}{4}\\right)} \\\\ + \\frac{3}{4}\\exp{\\left(-\\frac{(9x_1+1)^2}{49}-\\frac{(9x_2+1)}{10}\\right)} \\\\+ \\frac{1}{2}\\exp{\\left(-\\frac{(9x_1-7)^2}{4}-\\frac{(9x_2-3)^2}{4}\\right)} \\\\ - \\frac{1}{5}\\exp{\\left(-(9x_1-4)^2-(9x_2-7)^2 \\right)}\n    \\end{split}\n\\end{equation}\nTo this Franke function, we add noise sampled from a Gaussian distribution $\\mathcal{N}(0, var)$ to get a noisy Franke function:  $\\tilde{f}(x_1,x_2)$. Figure \\ref{fig:franke_function} shows a plot of the Franke function with and without noise.\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=.9\\linewidth]{Images/franke_function.png}\n  \\caption{}\n  \\label{fig:franke}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=.9\\linewidth]{Images/franke_function_noise.png}\n  \\caption{}\n  \\label{fig:franke_noise}\n\\end{subfigure}\n\\caption{Plot of the Franke function with noise (b) and without noise (a). The variance of the added noise is 0.1.}\n\\label{fig:franke_function}\n\\end{figure}", "meta": {"hexsha": "6a66c851a32b9fa86883a3394b42a13065414b10", "size": 1325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/report/sections/data_linear_regression.tex", "max_stars_repo_name": "am-kaiser/CompSci-Project-1", "max_stars_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "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": "documentation/report/sections/data_linear_regression.tex", "max_issues_repo_name": "am-kaiser/CompSci-Project-1", "max_issues_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-11-01T08:32:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-16T19:51:18.000Z", "max_forks_repo_path": "documentation/report/sections/data_linear_regression.tex", "max_forks_repo_name": "am-kaiser/CompSci-Project-1", "max_forks_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-17T10:51:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T10:51:25.000Z", "avg_line_length": 53.0, "max_line_length": 308, "alphanum_fraction": 0.6988679245, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6434666821547096}}
{"text": "At Stage~3, an approximation of the quantity of interest is constructed using\nthe interpolation algorithm presented in this section. The algorithm constitutes\nthe core of the framework proposed in this chapter, and it features a sparse\nstructure, hierarchical construction, and hybrid adaptivity. The benefits of\nthese characteristics are interconnected and can be summarized as follows:\n\\one~the ability to efficiently address multidimensional problems, \\two~the\nability to progressively refine the approximation, and \\three~the ability to\nperform this refinement strategically by virtue of fine-grained error control.\n\nHierarchical interpolation is introduced in \\xref{hierarchical-interpolation},\nand here we rely heavily on the results discussed in that section. The\nmathematics presented in \\xref{hierarchical-interpolation} and below are based\non the development in \\cite{klimke2006, ma2009, jakeman2012}.\n\nConsider the quantity of interest \\g as a function of \\vz via $\\transform$ as\nshown in \\sref{frame-transformation}. Assume that \\g belongs to $\\continuous{[0,\n1]^\\nz}$, the space of continuous functions on $[0, 1]^\\nz$; the assumption is\nnot limiting in practice. As shown in \\xref{hierarchical-interpolation}, \\g can\nbe approximated by means of the following interpolant:\n\\begin{equation} \\elab{frame-interpolant}\n  \\g \\approx \\interpolant{\\nz}{\\ls}(\\g)\n  = \\interpolant{\\nz}{\\ls - 1}(\\g) + \\sum_{\\vi \\in \\Delta\\sparseindex{\\nz}{\\ls}} \\sum_{\\vj \\in \\Delta\\tensorindex{\\nz}{\\vi}} \\Delta(\\g \\circ \\transform)(\\vx_{\\vi \\vj}) e_{\\vi \\vj}\n\\end{equation}\nwhere $\\vi \\in \\natural^\\nz$ is called a level index; $\\vj \\in \\natural^\\nz$ is\ncalled an order index; $\\set{\\vx_{\\vi \\vj}}$ and $\\set{e_{\\vi \\vj}}$ are\ncollocation nodes and basis functions, respectively; $\\set{\\Delta(\\g \\circ\n\\transform)(\\vx_{\\vi \\vj})}$ are hierarchical surpluses defined in\n\\eref{interpolant-sparse-surplus}; and $\\Delta\\sparseindex{\\nz}{\\ls}$ and\n$\\Delta\\tensorindex{\\nz}{\\vi}$ are index sets defined in\n\\eref{interpolant-sparse-index-delta} and \\eref{interpolant-tensor-index-delta},\nrespectively.\n\nDue to the reasons clarified in \\sref{frame-adaptivity}, the interpretation of\n\\eref{frame-interpolant} used in this chapter is different from the one used in\n\\xref{hierarchical-interpolation}. Specifically, $\\ls \\in \\natural$ no longer\nrepresents an interpolation level but rather an interpolation step. Accordingly,\n$\\interpolant{\\nz}{\\ls}(\\g)$ represents the interpolant obtained by a certain\ninterpolation step. In addition, all the index sets discussed here are generally\nsubsets of their full-fledged counterparts defined in\n\\xref{hierarchical-interpolation}.\n\nLet us now turn to the choice of collocation nodes and basis functions.\n\n\\subsection{Collocation Nodes}\n\\slab{frame-grid}\n\nIn order to gain computational efficiency, the integration grid should be fully\nnested, which is explained in \\xref{hierarchical-interpolation}. Such a grid can\nbe constructed using the family of Newton--Cotes rules \\cite{ma2009}. In one\ndimension, a Newton--Cotes rule is a set of equidistant nodes on $[0, 1]$. There\nare two types of Newton--Cotes rules: open and closed. The only difference\nbetween the two types is that the latter includes the endpoints (zero and one),\nwhereas the former does not.\n\nTechnically, in order to be able to proceed to hierarchical interpolation, the\nchosen rules have to fulfill a certain condition, which is discussed in\n\\xref{hierarchical-interpolation} and can be seen in\n\\eref{interpolant-tensor-exactness}. Closed Newton--Cotes rules satisfy this\ncondition, and they are the ones used in the original version of local\nadaptivity presented in \\cite{ma2009}. The open rules, on the other hand, do not\nfulfill the condition close to the boundaries of the unit interval. However,\naccording to our experience, open Newton--Cotes rules are a viable option, since\nthey perform well in practice, which is also noted in \\cite{klimke2006}. In\nfact, we are able to obtain better results with open rules and, therefore,\npresent them here.\n\n\\inputfigure{frame-grid}\nThe open Newton--Cotes rule of level $i \\in \\natural$ is\n\\[\n  \\X^1_i = \\set{\\x_{ij}}{j \\in \\tensorindex{1}{i}}\n\\]\nwhere\n\\begin{align*}\n  & \\x_{ij} = \\frac{j + 1}{n_i + 1}, \\\\\n  & \\tensorindex{1}{i} = \\set{i - 1}_{i = 1}^{n_i}, \\text{ and} \\\\\n  & n_i = 2^{i + 1} - 1.\n\\end{align*}\n\\fref{frame-grid} depicts the first three levels of this rule. It can be seen\nthat the number of nodes grows as 1, 3, 7, and so on, and that the rule is fully\nnested. In multiple dimensions, collocation nodes are formed as shown in\n\\eref{interpolant-tensor}.\n\n\\subsection{Basis Functions}\n\\slab{frame-basis}\n\nThe basis functions that go hand in hand with open Newton--Cotes rules are\npiecewise linear functions. For $i = 0$ and $j = 0$,\n\\[\n  e_{00}(\\x) = 1.\n\\]\nFor $i > 0$ and $j = 0$ (close to the left endpoint),\n\\[\n  e_{i0}(\\x) =\n  \\begin{cases}\n    2 - \\left(n_i + 1\\right) \\x, & \\text{if } \\x < \\frac{2}{n_i + 1}; \\\\\n    0, & \\text{otherwise}.\n  \\end{cases}\n\\]\nFor $i > 0$ and $j = n_i - 1$ (close to the right endpoint),\n\\[\n  e_{i, n_i - 1}(\\x) =\n  \\begin{cases}\n    \\left(n_i + 1\\right) \\x - n_i + 1, & \\text{if } \\x > \\frac{n_i - 1}{n_i + 1}; \\\\\n    0, & \\text{otherwise}.\n  \\end{cases}\n\\]\nIn other cases,\n\\[\n  e_{ij}(\\x) =\n  \\begin{cases}\n    1 - \\left(n_i + 1\\right)|\\x - \\x_{ij}|, & \\text{if } |\\x - \\x_{ij}| < \\frac{1}{n_i + 1}; \\\\\n    0, & \\text{otherwise}.\n  \\end{cases}\n\\]\nThe basis functions that correspond to the first three levels of one-dimensional\ninterpolation are depicted in \\fref{frame-basis}. In multiple dimensions, basis\nfunctions are formed as shown in \\eref{interpolant-tensor}, which results in\n\\[\n  e_{\\vi \\vj}(\\vx) = \\prod_{k = 1}^n e_{i_k j_k}(x_k).\n\\]\n\n\\inputfigure{frame-basis}\nAdditionally, let us calculate the volumes (the integrals over the whole domain)\nof the aforementioned piecewise linear functions; these volumes are required in\nthe continuation. For $i = 0$ and $j = 0$,\n\\[\n  w_{00} = 1.\n\\]\nFor $i > 0$ and $j \\in \\set{0, n_i - 1}$,\n\\[\n  w_{ij} = \\frac{2}{n_i + 1}.\n\\]\nIn other cases,\n\\[\n  w_{ij} = \\frac{1}{n_i + 1}.\n\\]\nThe volumes of multidimensional basis functions are products of the\ncorresponding one-dimensional volumes as follows:\n\\begin{equation} \\elab{frame-volume}\n  w_{\\vi \\vj} = \\prod_{k = 1}^\\nz w_{i_k j_k}.\n\\end{equation}\n\nNow, imagine a function that is nearly flat on the first half of $[0, 1]$ and\nrather irregular on the other. Under these circumstances, it is natural to\nexpect that, in order to attain the same accuracy, the first half should require\nmany fewer collocation nodes than the other one; recall the example given in\n\\fref{frame-motivation}. However, if we followed the usual construction\nprocedure described in \\xref{hierarchical-interpolation}, we would not be able\nto benefit from this idiosyncrasy. Both sides would be treated equally, and all\nthe nodes of each interpolation level would be added to the interpolant, which\nis wasteful. The solution to this problem is to make the interpolation algorithm\nadaptive, which we discuss next.\n\n\\subsection{Hybrid Adaptivity}\n\\slab{frame-adaptivity}\n\nIn order to make the algorithm adaptive, we first need to decide on a criterion\nused for measuring the accuracy of the interpolant $\\interpolant{\\nz}{\\ls}(\\g)$\nin \\eref{frame-interpolant} at any point in $[0, 1]^\\nz$. Then, when refining\nthe interpolant, instead of evaluating the quantity of interest \\g at all\npossible nodes, we choose only those that are located in the regions with poor\naccuracy as indicated by the criterion.\n\nWe already have a good foundation for building the above-mentioned criterion.\nHierarchical surpluses, which are introduced in\n\\xref{hierarchical-interpolation} and defined in\n\\eref{interpolant-sparse-surplus}, are natural indicators of the interpolation\nerror: they are the difference between the true values of \\g and those estimated\nby $\\interpolant{\\nz}{\\ls}(\\g)$ at the nodes of the underlying integration grid.\nTherefore, hierarchical surpluses can be recycled in order to effectively\nidentify problematic regions.\n\nWe proceed as follows. First, a score is assigned to each node $\\vx_{\\vi \\vj}$\nor, equivalently, to each pair of a level index \\vi and an order index \\vj as\nfollows:\n\\begin{equation} \\elab{frame-score}\n  s_{\\vi \\vj} = \\absolute{\\Delta(\\g \\circ \\transform)(\\vx_{\\vi \\vj}) w_{\\vi \\vj}}\n\\end{equation}\nwhere $\\Delta(\\g \\circ \\transform)(\\vx_{\\vi \\vj})$ is the surplus at the node as\ndefined in \\eref{interpolant-sparse-surplus}, and $w_{\\vi \\vj}$ is the volume of\nthe corresponding basis function as shown in \\eref{frame-volume}. The above\nscore is utilized for guiding the algorithm as explained below.\n\nEach hierarchical interpolant $\\interpolant{\\nz}{\\ls}$ is characterized by a set\nof level indices $\\sparseindex{\\nz}{\\ls}$, and each level index $\\vi \\in\n\\sparseindex{\\nz}{\\ls}$ by a set of order indices\n$\\Delta\\tensorindex{\\nz}{\\vi}$. At each interpolation step $\\ls \\in \\natural$, a\nsingle level index\n\\[\n  \\vi_{\\ls} \\in \\sparseindex{\\nz}{\\ls - 1}\n\\]\nis chosen where $\\sparseindex{\\nz}{-1} = \\set{\\v{0}}$. This index gives birth to\n$\\Delta\\sparseindex{\\nz}{\\ls}$ and $\\set{\\Delta\\tensorindex{\\nz}{\\vi}}{\\vi \\in\n\\Delta\\sparseindex{\\nz}{\\ls}}$, forming the increment given on the right-hand\nside of \\eref{frame-interpolant}.\n\nThe level index set $\\Delta\\sparseindex{\\nz}{\\ls}$ contains so-called admissible\nforward neighbors of the chosen $\\vi_{\\ls}$. The forward neighbors of an\nindex~\\vi are given by\n\\[\n  \\set{\\vi + \\v{1}_k}_{k = 1}^\\nz\n\\]\nwhere $\\v{1}_k \\in \\set{0, 1}^\\nz$ is a vector whose elements are zero except\nfor element~$k$, which is equal to unity. An index~\\vi is called admissible if\nits inclusion into the index set $\\sparseindex{\\nz}{\\ls}$ under consideration\nkeeps the set admissible. Finally, $\\sparseindex{\\nz}{\\ls}$ is admissible if it\nsatisfies the following condition \\cite{klimke2006}:\n\\[\n  \\vi - \\v{1}_k \\in \\sparseindex{\\nz}{\\ls}\n\\]\nfor $\\vi \\in \\sparseindex{\\nz}{\\ls}$ and $k \\in \\set{\\range{1}{\\nz}}$ where the\ncases with $i_k = 0$ need no check.\n\nLet us now turn to the content of $\\Delta\\tensorindex{\\nz}{\\vi}$ where $\\vi =\n\\vi_{\\ls} + \\v{1}_k$ for some $k$. It also contains admissible forward\nneighbors; however, they are order indices, and their construction is different\nfrom the one used in the case of $\\Delta\\sparseindex{\\nz}{\\ls}$. These indices\nare identified by inspecting the backward neighborhood of \\vi, which is\nanalogous to the forward one but in the other direction. For each backward\nneighbor $\\vi - \\v{1}_m$ and each $\\vj \\in \\Delta\\tensorindex{\\nz}{\\vi -\n\\v{1}_m}$, we first check the condition\n\\[\n  s_{\\vi - \\v{1}_m, \\vj} \\geq \\error{s}\n\\]\nwhere \\error{s} is a user-defined constant referred to as the score error. If\nthe condition holds, the forward neighbors of \\vj in dimension~$k$ are added to\n$\\Delta\\tensorindex{\\nz}{\\vi}$. This procedure is illustrated in\n\\fref{frame-grid} for open Newton--Cotes rules in one dimension. The arrows\nemerging from a collocation node connect the node with its forward neighbors. In\ngeneral, each node has two forward neighbors in each dimension. The order\nindices of these nodes are\n\\begin{align*}\n  & (j_1, \\dots, 2 j_k \\phantom{{} + 2}, \\dots, j_{\\nz}) \\text{ and} \\\\\n  & (j_1, \\dots, 2 j_k + 2,              \\dots, j_{\\nz}).\n\\end{align*}\nThe above refinement procedure should be performed for each level index $\\vi \\in\n\\Delta\\sparseindex{\\nz}{\\ls}$ with respect to each dimension $k \\in\n\\set{\\range{1}{\\nz}}$.\n\nThe choice of $\\vi_{\\ls} \\in \\sparseindex{\\nz}{\\ls - 1}$ at each step \\ls in\n\\eref{frame-interpolant} is made as follows. First, each index can be picked at\nmost once. The rest is resolved by prioritizing the candidates. It is reasonable\nto compute the priority of a level index~\\vi based on the scores of the order\nindices associated with this level index, that is, based on the scores of\n$\\tensorindex{\\nz}{\\vi}$. We set the priority to the average score\n\\[\n  s_{\\vi} = \\frac{1}{\\cardinality{\\Delta\\tensorindex{\\nz}{\\vi}}} \\sum_{\\vj \\in \\Delta\\tensorindex{\\nz}{\\vi}} s_{\\vi \\vj}.\n\\]\nThus, at each step \\ls, the index~\\vi with the highest $s_{\\vi}$ is promoted to\n$\\vi_{\\ls}$.\n\nThe final question to answer is the stopping condition of the approximation\nprocess in \\eref{frame-interpolant}. Apart from the natural constraints on the\nmaximum number of function evaluations and the maximum interpolation level (the\noriginal \\ls in \\xref{hierarchical-interpolation}), we rely on the following\ncriterion. Given two additional user-defined constants \\error{a} and \\error{r},\nwhich are referred to as the absolute and relative errors, respectively, the\nprocess is terminated as soon as\n\\begin{equation} \\elab{frame-stop}\n  \\max_{\\vi \\vj} \\absolute{\\Delta(\\g \\circ \\transform)(\\vx_{\\vi \\vj})} \\leq \\max \\set{\\error{a}, \\error{r} (\\g_\\maximum - \\g_\\minimum)}\n\\end{equation}\nwhere $\\g_\\minimum$ and $\\g_\\maximum$ are the minimum and maximum observed\nvalues of \\g, respectively. The left-hand side of \\eref{frame-stop} corresponds\nto the largest surplus whose level index has not been refined yet, that is, has\nnot been considered as $\\vi_{\\ls}$ at some step \\ls. The above criterion is an\nadequate technique for curtailing the interpolation process, since it is based\non the actual progress.\n\nThe adaptivity presented in this subsection is referred to as hybrid, since it\ncombines features of global and local adaptivity \\cite{jakeman2012}. Local\nadaptivity operates on the level of individual nodes \\cite{ma2009} and is\ndiscussed in \\sref{frame-motivation}. By contrast, global adaptivity operates on\nthe level of individual dimensions \\cite{klimke2006}. The intuition behind\nglobal adaptivity is that, in general, the input variables manifest themselves\n(impact \\g) differently, and the interpolation algorithm is likely to benefit by\nprioritizing those variables that are the most influential.\n\n\\conclusioncut\nSo far, we have formalized an efficient algorithm for adaptive hierarchical\ninterpolation in multiple dimensions. The main equation is\n\\eref{frame-interpolant} where $\\Delta(\\g \\circ \\transform)(\\vx_{\\vi \\vj})$,\n$\\vx_{\\vi \\vj}$, and $e_{\\vi \\vj}$ are the ones in\n\\eref{interpolant-sparse-surplus}, \\sref{frame-grid}, and \\sref{frame-basis},\nrespectively; and the interpolation is undertaken according to the rules in\n\\sref{frame-adaptivity}. Next, we discuss a few implementation details.\n\n\\subsection{Implementation}\n\nThe life cycle of interpolation has roughly two stages: construction and usage.\nThe construction stage invokes \\g at a set of collocation nodes and produces\ncertain artifacts. The usage stage estimates the values of \\g at a set of\narbitrary points by manipulating these artifacts. In this subsection, we provide\nthe pseudocode for the two stages in order to give a better sense of the\ntechnique.\n\nLet us first make a general note. According to our experience, it is beneficial\nto the clarity and ease of implementation to collapse the two sums in\n\\eref{frame-interpolant} into one. This requires storing a level index $\\vi =\n(i_k) \\in \\natural^\\nz$ and an order index $\\vj = (j_k) \\in \\natural^\\nz$ for\neach node. It is also advantageous to encode each pair $(i_k, j_k)$ as a single\nunsigned integer, which, in particular, eliminates excessive memory usage. In\nmultiple dimensions, this results in a vector $\\v{\\iota} = (\\iota_k) \\in\n\\natural^\\nz$, which we simply call an index. Our encoding is\n\\[\n  \\iota_k = i_k \\lor (j_k \\ll \\n{\\mathrm{bits}})\n\\]\nwhere $\\lor$ and $\\ll$ stand for the bitwise \\up{OR} and logical left shift,\nrespectively, and \\n{\\mathrm{bits}} is the number of bits reserved for storing\nlevel indices, which can be adjusted according to the maximum permitted depth of\ninterpolation.\n\n\\inputalgorithm{frame-construction}\nThe pseudocode for the construction stage is given in \\aref{frame-construction}.\nThe input is a subroutine called Algorithm~G that evaluates $\\g \\circ\n\\transform$. The output is a structure \\texttt{interpolant} that contains the\nartifacts of the interpolation. These artifacts are a set of tuples\n$\\set{(\\v{\\iota}_k, \\Delta\\g(\\vx_{\\v{\\iota}_k}))}$, which is a comprehensive\ndescription of a hierarchical interpolant. The pseudocode works as follows.\n\nLine 1: Each iteration of the loop corresponds to an interpolation step \\ls in\n\\eref{frame-interpolant}. The progress is captured by a structure\n\\texttt{state}. The \\texttt{strategy} object represents the adaptation strategy\nutilized, and it operates in accordance with \\sref{frame-adaptivity}. The\n\\texttt{Continue?} method of \\texttt{strategy} checks if any of the stopping\nconditions is satisfied, in which case the process is terminated.\n\nLine 2: The \\texttt{Next} method of \\texttt{strategy} consumes the previous\nstate and returns the initial state of the ongoing interpolation step. In\nparticular, it populates the \\texttt{indices} field of \\texttt{state} with the\nindices of the step. The rest of the loop's body populates the rest of\n\\texttt{state}'s fields so that \\texttt{strategy} can adequately execute its\nfunctionality at the beginning of the next iteration.\n\nLine 3: The \\texttt{grid} object represents the interpolation grid that is being\nutilized, and its \\texttt{Compute} method calculates the collocation nodes\n$\\set{\\vx_{\\v{\\iota}_k}}$ that correspond to the given indices\n$\\set{\\v{\\iota}_k}$; see \\sref{frame-grid}.\n\nLine 4: Algorithm~G evaluates $\\g \\circ \\transform$ at the collocation nodes.\nThis is by far the most time consuming operation of the algorithm, as \\g is\ngenerally expensive to execute. This operation is also a prominent candidate for\nparallelization, since the algorithm does not impose any particular evaluation\norder.\n\nLine 5: \\aref{frame-evaluation} is a subroutine that exercises the interpolant\nconstructed so far at the collocation nodes and thereby approximates the values\nobtained on line~4. This algorithm will be discussed separately later on.\n\nLine 6: The \\texttt{Subtract} subroutine computes the difference between the\nactual and approximated values of \\g, which yields the hierarchical surpluses\n$\\set{\\Delta(\\g \\circ \\transform)(\\vx_{\\v{\\iota}_k})}$ (see\n\\eref{interpolant-sparse-surplus}) of the current interpolation step.\n\nLine 7: The \\texttt{Score} method of \\texttt{strategy} calculates the scores of\nthe collocation nodes based on their surpluses as described in\n\\sref{frame-adaptivity}.\n\nLine 8: The \\texttt{Append} method of \\texttt{interpolant} refines the\ninterpolant by extending it with the indices and surpluses of the completed\niteration.\n\n\\inputalgorithm{frame-evaluation}\nWe now turn our attention to the usage stage of an interpolant. The pseudocode\nis given in \\aref{frame-evaluation}. This subroutine is also used in\n\\aref{frame-construction} on line~5. Let us make a couple of observations\nregarding this subroutine.\n\nLine 3: The inner loop corresponds to an unfolded version of\n\\eref{frame-interpolant}; that is, there is no separation into the individual\ninterpolation steps taken.\n\nLine 4: The \\texttt{basis} object represents the interpolation basis that is\nbeing used, and its \\texttt{Compute} method evaluates the basis functions\n$\\set{e_{\\v{\\iota}_k}}$ that correspond to the given indices $\\set{\\v{\\iota}_k}$\nat arbitrary points; see \\sref{frame-basis}.\n\nIt is worth noting that the \\texttt{strategy}, \\texttt{grid}, and \\texttt{basis}\nobjects conform to certain interfaces and can be easily swapped out. This makes\nthe two algorithms very general and reusable with different configurations. In\nparticular, the adaptation strategy can be fine-tuned for each particular\nproblem.\n\n\\conclusioncut\nTo recapitulate, in this section, the approximation engine of our framework for\nprobabilistic analysis of electronic systems under workload variation has been\npresented. It is consolidated in \\aref{frame-construction} and\n\\aref{frame-evaluation}.\n", "meta": {"hexsha": "2d7959e93e667ed4a43f184b9ccf79e045202a36", "size": 19821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/uncertainty/workload/development/construction.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/uncertainty/workload/development/construction.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/uncertainty/workload/development/construction.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": 51.0850515464, "max_line_length": 179, "alphanum_fraction": 0.7491044851, "num_tokens": 5485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6434666729747999}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\marginpar{Wednesday\\\\ 2021-11-17}\n\nThe conjugate basis is often denoted as \\(\\widetilde{\\omega}^{(J)} = \\dd{\\widetilde{x}}^{(J)}\\). \n\nThe application of a one-form on a vector, \\(\\widetilde{q}(\\vec{V}) = q_J V^{J}\\),\ncan be computed as a \\emph{contraction}. \n\nA one-form transforms with \\(\\pdv*{x^{\\mu }}{x^{\\prime \\alpha }}\\), \na vector transforms with \\(\\pdv*{x^{\\prime \\mu }}{x^{\\alpha }}\\). \n\nSince a basis vector transforms like \n%\n\\begin{align}\n\\vec{e}_{(\\alpha ')} = \\Lambda^{\\mu }{}_{\\alpha '} \\vec{e}_{(\\mu) }\n\\,\n\\end{align}\n%\nwe have \n%\n\\begin{align}\nq_{J} = \\widetilde{q}(\\vec{e}_{(J)}) = \\widetilde{q}( \\vec{e}_{(k')} \\Lambda^{k'}{}_J )\n= \\Lambda^{k'}{}_J \\widetilde{q}( \\vec{e}_{(k')}) = \\Lambda^{k'}_J q_{k'}\n\\,.\n\\end{align}\n\nThis shows that the one-form transforms with the inverse of the Jacobian. \n\nAn example of a one-form is the gradient of a scalar function \\(\\phi \\): \n%\n\\begin{align}\n\\pdv{\\phi }{x^{(J')}} = \\pdv{\\phi }{x^{k}} \\pdv{x^{k}}{x^{\\prime J'}} = \\pdv{\\phi }{x^{k}} \\Lambda^{k}{}_{J'}\n\\,.\n\\end{align}\n\n\\paragraph{Tensors}\n\nA tensor of type \\((N, R)\\) is a function which takes \\(N\\) one-forms, \\(R\\) vectors, and yields a number.\nWe require that it is multilinear (linear in all its arguments), \n\nOne-forms are \\((0, 1)\\) tensors, vectors are \\((1, 0)\\) tensors. \n\nThe components of the tensor are defined by its application to the basis vectors / covectors of the vector space. For a \\((0, 2)\\) tensor, we have \n%\n\\begin{align}\nF_{\\alpha \\beta } = F( \\vec{e}_{(\\alpha )}, \\vec{e}_{(\\beta )})\n\\,,\n\\end{align}\n%\nfrom which we can recover by linearity any application of the tensor: \\(F(\\vec{A}, \\vec{B}) = A^{\\alpha } B^{\\beta } F_{\\alpha \\beta }\\). \n\nWe can then try to construct a basis for the tensor space such that \n%\n\\begin{align}\nF = F_{\\alpha \\beta } \\widetilde{\\omega}^{(\\alpha , \\beta )}\n\\,.\n\\end{align}\n\nWe do this by writing \n%\n\\begin{align}\nF (\\vec{A}, \\vec{B}) \n= \\qty(F_{\\alpha \\beta } \\widetilde{\\omega}^{(\\alpha , \\beta )}) (\\vec{A}, \\vec{B})\n= F_{\\alpha \\beta } \\widetilde{\\omega}^{\\alpha }(\\vec{A}) \\widetilde{\\omega}^{(\\beta )}(\\vec{B})\n\\,,\n\\end{align}\n%\ntherefore we can write the \\((0, 2)\\) basis as an outer product: \n%\n\\begin{align}\n\\widetilde{\\omega}^{(\\alpha , \\beta )} = \\widetilde{\\omega}^{(\\alpha)} \\otimes \\widetilde{\\omega}^{(\\beta )} \n\\,.\n\\end{align}\n\nWe can iterate this procedure to get a basis for any tensor space. How do tensors transform? \n%\n\\begin{align}\nF = F_{\\alpha ' \\beta '} \\Lambda^{\\alpha '}_{\\gamma } \\widetilde{\\omega}^{(\\gamma )} \\otimes \n\\widetilde{\\omega}^{(\\rho )} \\Lambda^{\\beta '}_{\\gamma }\n= F_{\\gamma \\rho } \\widetilde{\\omega}^{(\\gamma )} \\otimes \\widetilde{\\omega}^{(\\rho )}\n\\,.\n\\end{align}\n%\n\\todo[inline]{this looks wrong\\dots}\n\nThe transformation law is therefore \n%\n\\begin{align}\nF_{\\alpha ' \\beta '} \\Lambda^{\\alpha '}{}_\\gamma \\Lambda^{\\beta '}{}_\\delta = F_{\\gamma \\delta }\n\\,,\n\\end{align}\n%\nor equivalently \n%\n\\begin{align}\nF_{\\alpha ' \\beta ' } = \\Lambda^{\\rho }{}_{\\alpha '} \\Lambda^{\\sigma }{}_{\\beta '} F_{ \\rho \\sigma }\n\\,.\n\\end{align}\n\nTensors of the same kind can be added, and tensors of any order can be multiplied and contracted. \n\nTensors can be symmetric: in an algebraic sense, \\(F\\) is symmetric if \\(F(\\vec{A}, \\vec{B}) = F(\\vec{B}, \\vec{A})\\). \nIn terms of its indices, this means \\(F_{\\alpha \\beta } = F_{\\beta \\alpha }\\). \n\nWe can symmetrize a tensor by \\(F_{(\\alpha \\beta )} = (F_{\\alpha \\beta } + F_{\\beta \\alpha }) / 2\\). \n\nSymmetric \\(n\\)-dimensional  tensors have \\(n(n+1) / 2\\) independent components. \n\nTensors can be antisymmetric: in an algebraic sense, \\(F\\) is antisymmetric if \\(F(\\vec{A}, \\vec{B}) = - F(\\vec{B}, \\vec{A})\\). \nIn terms of its indices, this means \\(F_{\\alpha \\beta } = - F_{\\beta \\alpha }\\). \n\nWe can antisymmetrize a tensor by \\(F_{[\\alpha \\beta ]} = (F_{\\alpha \\beta } - F_{\\beta \\alpha }) / 2\\). \n\nAntisymmetric \\(n\\)-dimensional tensors have \\(n(n-1) / 2\\) independent components. \n\nThe \\textbf{metric tensor}!  We call its application to two vectors their scalar product, \\(g(\\vec{A}, \\vec{B}) = \\vec{A} \\cdot \\vec{B}\\). \nIt is symmetric, therefore it has 10 free components.\n\nThe distance between two points separated by an infinitesimal \\(\\dd{s}\\) is \n%\n\\begin{align}\n\\dd{s^2} = \\dd{s} \\cdot \\dd{s} = g_{\\mu \\nu } \\dd{x^{\\mu }} \\dd{x^{\\nu }}\n\\,.\n\\end{align}\n\nA curve \\(\\gamma \\colon [a, b] \\to \\mathcal{M}\\) can be measured: its length will be \n%\n\\begin{align}\ns = \\int_{a}^{b} \\dd{s} = \\int_{a}^{b} \\dd{\\lambda } \\underbrace{\\sqrt{g_{\\mu \\nu } \\dv{x^{\\mu }}{\\lambda } \\dv{x^{\\nu }}{\\lambda }}}_{\\dv*{s}{\\lambda }}\n\\,.\n\\end{align}\n\nThis gives the length of the \\textbf{path}, which is invariant with respect to the parametrization.\n\nThanks to the metric tensor we can lower or raise indices: \nthe map \\(\\omega _V \\colon U \\to g(U, V)\\) is a one-form by the properties we require of the metric, so we can say it is the ``dual'' form of \\(V\\), typically just denoted as \\(V_\\mu = g_{\\mu \\nu } V^{\\nu }\\). \n\nIn order to do the inverse, we need the inverse of the metric tensor, \\(g^{\\mu \\nu }\\), which satisfies \\(g^{\\mu \\nu } g_{\\nu \\rho }= \\delta^{\\mu }_{\\rho }\\). \n\n\\begin{extracontent}\nConsider the metric tensor \n%\n\\begin{align}\n\\eta_{\\alpha \\beta } = \\left[\\begin{array}{ccc}\n-1 & 0 & 0 \\\\ \n0 & 1 & 0 \\\\ \n0 & 0 & 1\n\\end{array}\\right] \n\\,.\n\\end{align}\n\nLet us rotate the coordinate system: \n%\n\\begin{align}\nx^{0} &= x^{0 \\prime}  \\\\\nx^{1} & = r \\cos \\theta  \\\\\nx^{2} & = r \\sin \\theta  \n\\,,\n\\end{align}\n%\nwhere \\(r \\) and \\(\\theta \\) are polar coordinates for the unprimed system. \n\nHow does the metric transform? \n%\n\\begin{align}\ng_{0'0'} &= \\Lambda^{\\mu }_{0'} \\Lambda^{\\nu }_{0'} \\eta_{\\mu \\nu } = \\eta_{00} = -1   \\\\\ng_{0'i'} &= \\Lambda^{\\mu }_{0'} \\Lambda^{\\nu }_{i '} \\eta_{\\mu \\nu } = 0 \\\\ \ng_{1'1'} &= \\Lambda^{\\mu }_{1'} \\Lambda^{\\nu }_{1'} \\eta_{\\mu \\nu } = \\cos^2 \\theta + \\sin^2 \\theta = 1\\\\ \ng_{2'2'} &= \\Lambda^{\\mu }_{2'} \\Lambda^{\\nu }_{2'} \\eta_{\\mu \\nu } = r^2 (\\cos^2 \\theta + \\sin^2 \\theta) = r^2 \n\\,.\n\\end{align}\n\nSo, we find the line element in polar coordinates\n%\n\\begin{align}\ng_{\\alpha ' \\beta '} = \\left[\\begin{array}{ccc}\n-1 & 0 & 0 \\\\ \n0 & 1 & 0 \\\\ \n0 & 0 & r^2\n\\end{array}\\right]\n\\,.\n\\end{align}\n\\end{extracontent}\n\n\n\\end{document}\n", "meta": {"hexsha": "2929cbaeb6e1377a6d64293f9b9ea0c3cc3773cd", "size": 6265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phd_courses/theoretical_gravitation_cosmology/nov17.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": "phd_courses/theoretical_gravitation_cosmology/nov17.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": "phd_courses/theoretical_gravitation_cosmology/nov17.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": 33.1481481481, "max_line_length": 210, "alphanum_fraction": 0.6078212291, "num_tokens": 2284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.643466649023234}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.9 Ricci in terms of the metric and its derivatives}\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   \\partial{#}::PartialDerivative;\n\n   g_{a b}::Metric;\n   g^{a b}::InverseMetric;\n\n   dgab := \\partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \\partial_{c}{g_{e f}}.      # cdb (ex-0309.dgab,dgab)\n\n   Gamma := \\Gamma^{a}_{b c} ->\n            (1/2) g^{a e} (   \\partial_{b}{g_{e c}}\n                            + \\partial_{c}{g_{b e}}\n                            - \\partial_{e}{g_{b c}}).                             # cdb (ex-0309.Gamma,Gamma)\n\n   Rabcd := R^{a}_{b c d} ->\n            \\partial_{c}{\\Gamma^{a}_{b d}} + \\Gamma^{a}_{e c} \\Gamma^{e}_{b d}\n          - \\partial_{d}{\\Gamma^{a}_{b c}} - \\Gamma^{a}_{e d} \\Gamma^{e}_{b c}.   # cdb (ex-0309.Rabcd,Rabcd)\n\n   FourRab := 4 R^{c}_{a c b}.                      # cdb (ex-0309.101,FourRab)\n\n   substitute     (FourRab, Rabcd)                  # cdb (ex-0309.102,FourRab)\n   substitute     (FourRab, Gamma)                  # cdb (ex-0309.103,FourRab)\n\n   product_rule   (FourRab)                         # cdb (ex-0309.104,FourRab)\n   distribute     (FourRab)                         # cdb (ex-0309.105,FourRab)\n\n   substitute     (FourRab, dgab)                   # cdb (ex-0309.106,FourRab)\n\n   sort_product   (FourRab)                         # cdb (ex-0309.107,FourRab)\n   rename_dummies (FourRab)                         # cdb (ex-0309.108,FourRab)\n   canonicalise   (FourRab)                         # cdb (ex-0309.109,FourRab)\n\n   # sort so that g to appeares before dg\n\n   substitute     (FourRab, $g^{a b} -> A^{a b}$)\n   sort_product   (FourRab)\n   rename_dummies (FourRab)\n   substitute     (FourRab, $A^{a b} -> g^{a b}$)   # cdb (ex-0309.110,FourRab)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{4 R_{ab} = \\Cdb*{ex-0309.101}\n                    = \\Cdb*{ex-0309.102}\n                    = \\Cdb*{ex-0309.103}\n                    = \\Cdb*{ex-0309.104}\n                    = \\Cdb*{ex-0309.105}\n                    = \\Cdb*[\\hskip 2cm\\hfill]{ex-0309.106}\n                    = \\Cdb*[\\hskip 2cm\\hfill]{ex-0309.107}\n                    = \\Cdb*[\\hskip 2cm\\hfill]{ex-0309.108}\n                    = \\Cdb*{ex-0309.109}\n                    = \\Cdb*{ex-0309.110}}\n\\end{dgroup*}\n\n% ============================================================================================\n% export to json format\n\n\\CdbSetup{action=hide}\n\n\\begin{cadabra}\n   import cdblib\n   cdblib.create ('ex-0309.json')\n   cdblib.put ('FourRab',FourRab,'ex-0309.json')\n\\end{cadabra}\n\n\\end{document}\n", "meta": {"hexsha": "0840916760b27c5cc95fdb12dc805356673a57cc", "size": 2807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0309.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-0309.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-0309.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": 35.5316455696, "max_line_length": 109, "alphanum_fraction": 0.467046669, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6431961693024483}}
{"text": "\\section{Case detection and isolation} \\label{cdr}\n\n\\subsection{Determining the proportion of cases detected}\nWe calculate a time-varying case detection rate, being the proportion of all symptomatic cases (the second and third clinical strata, described in Section \\ref{clin}) that are detected (the third clinical stratum only).\nThis proportion is informed by the number of tests performed using the following formula:\n\n\\[CDR(time)=1-(1-floor)\\times e^{-shape \\times tests(time)}\\]\n\n$time$ is the calendar date and $tests(time)$ is the number of tests per capita done on that date. To determine the value of the shape parameter, we solve this equation based on the assumption that a certain daily testing rate $tests(t)$ is associated with a certain $CDR(t)$.\n$floor$ is the minimum case detection rate possible, which would theoretically occur when zero tests are conducted.\nSolving for $shape$ yields:\n\n\\[shape = \\frac{-log(\\frac{1 - CDR(t)}{1 - floor})}{tests(t)}\\]\n\nThat is, if it is assumed that a certain daily per capita testing rate is associated with a certain proportion of symptomatic cases detected, we can determine $shape$.\nAs this relationship is not well understood and unlikely to be consistent across all settings, we vary the $CDR$ that is associated with a certain per capita testing rate during calibration.\nThis approach allows us to both vary the $CDR(\\cdot)$ relationship through calibration,\nwhile also varying the specific $CDR(time)$ to reflect historical changes in testing capacity with time.\n\n\\subsection{Isolation of detected cases}\nAs described in the clinical stratification section above, as infected persons progress from the early to the late stage of active COVID-19, \ninfectiousness is reduced for those detected to reflect case isolation.\n", "meta": {"hexsha": "14d839aa7f1163c9863a846abdbd52ee088a1ef7", "size": 1779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tex_descriptions/models/sm_sir/detection.tex", "max_stars_repo_name": "emmamcbryde/AuTuMN-1", "max_stars_repo_head_hexsha": "b1e7de15ac6ef6bed95a80efab17f0780ec9ff6f", "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": "docs/tex/tex_descriptions/models/sm_sir/detection.tex", "max_issues_repo_name": "emmamcbryde/AuTuMN-1", "max_issues_repo_head_hexsha": "b1e7de15ac6ef6bed95a80efab17f0780ec9ff6f", "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": "docs/tex/tex_descriptions/models/sm_sir/detection.tex", "max_forks_repo_name": "emmamcbryde/AuTuMN-1", "max_forks_repo_head_hexsha": "b1e7de15ac6ef6bed95a80efab17f0780ec9ff6f", "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": 77.347826087, "max_line_length": 276, "alphanum_fraction": 0.7863968522, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6431641960338486}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\chapter{Abstract Integration}\n\n\\begin{exercise}\n  Does there exist an infinte $ \\sigma $-algebra which has only countably many members?\n  \\paragraph{Solution. }\n  If $ \\mathcal{F} $ is a $ \\sigma $-algebra and $ A $ a set, define $ \\mathcal{F} \\cap A := \\{A \\cap F: F \\in \\mathcal{F}\\}$. Hence if $ A \\in \\mathcal{F} $, then $ \\mathcal{F} \\cap A $ is a $ \\sigma $-subalgebra of $ \\mathcal{F} $. Further, if $ \\mathcal{F} $ is infinte, either $ A \\cap \\mathcal{F} $ or $ A^c \\cap \\mathcal{F}$  is infinte.\n\n  In other words, if $ \\mathcal{F}_n $ is infinte, then there is $ A _{n+1} \\in \\mathcal{F}_n $ such that $ \\mathcal{F} _{n+1} = \\mathcal{F}_n \\cap A_n^c $ is infinte. Take $ \\mathcal{F}_0 = \\mathcal{M} $, by induction we get a disjoint sequence of sets $ A_n \\in \\mathcal{M}$.\n  Since $ \\mathcal{M} $ must also contain any union of sets of $ A_n $, and each union is different, this is to say $ \\mathcal{M} $ contains a embedding of all subsets of $ \\mathbb{N} $, therefore uncountable.\n\\end{exercise}\n\n\\begin{exercise}\n  Prove an analogue of Theorem 1.8 for $ n $ functions.\n  \\paragraph{Solution. }\n  It suffices to prove\n  \\begin{align*}\n    f = f_1 \\times f_2 \\times ... \\times f_n\n  \\end{align*}\n  is measurable is each $ f_i $ is measurable. Similarly as in the theorem, take $ R $ be any rectangles in $ \\mathbb{R}^n $. Notice\n  \\begin{align*}\n    f ^{-1}(R) = \\bigcap f_i(I_i)\n  \\end{align*}\n  is measurable, if $ R = I_1 \\times I_2 \\times ... \\times I_n $. The rest of the proof is a repeat of Theorem 1.8.\n\\end{exercise}\n\n\\begin{exercise}\n  Prove that if $ f$ is a real function on a measurable space $ X $ such that $ \\{x: f(x) < r\\} $ is measurable for every rational $ r $, then $ f $ is measurable.\n  \\paragraph{Solution. }\n  Take $ \\Omega $ as all $ E \\subset \\mathbb{R} $ such that $ f ^{-1}(E) $ is measurable. By Theorem 1.2, $ \\Omega $ is a $ \\sigma $-algebra. Notice\n  \\begin{align*}\n    \\{f > a\\} = \\bigcup _{q \\in \\mathbb{Q} \\cap (-\\infty, a)} \\{f > q\\}\n  \\end{align*}\n  for all $ a \\in \\mathbb{R} $. Therefore, $ \\{f > a\\} $ is measurable. By Theorem 1.2 again, $ f $ is measurable.\n\n\\end{exercise}\n\n\\begin{exercise}\n  Let $ \\{a_n\\} $ and $ \\{b_n\\} $ be sequences in $ [-\\infty, \\infty] $, and prove the following assertions:\n  \\begin{enumerate}\n    \\item $$ \\limsup -a_n = -\\liminf a_n. $$\n    \\item $$ \\limsup (a_n + b_n) \\le \\limsup a_n + \\limsup b_n $$ provided none of the sums is of the form $ \\infty - \\infty $.\n    \\item If $ a_n \\le b_n $ for all $ n $, then\n    \\begin{align*}\n      \\liminf a_n \\le \\liminf b_n\n    \\end{align*}\n\n    Show by example that strict inequality can hold in b).\n\n\n  \\end{enumerate}\n  \\paragraph{Solution. }\n  \\begin{enumerate}\n    \\item First prove $ \\sup -A = - \\inf A $, where $ A \\in \\mathbb{\\bar R} $. Notice $ -a \\le -\\inf a $ implies $ \\sup -A \\le -\\inf A $. Similarly $ -\\inf A \\le \\sup -A $.\n    \\begin{align*}\n      \\limsup (-a_n) = \\inf _{n \\ge 1} \\sup _{k \\ge n} (-a_k) = - \\sup \\inf a_k = -\\limsup a_n\n    \\end{align*}\n\n    \\item Notice if $ \\limsup a_n + \\limsup b_n $ is defined, $ \\sup _{k \\ge n} a_k + \\sup _{k \\ge n} b_k $ is defined for sufficiently large $ n $. Notice\n    \\begin{align*}\n      a_n + b_n \\le \\sup _{k \\ge n} a_k + \\sup _{k \\ge n} b_k\n    \\end{align*}\n    implies\n    \\begin{align*}\n      \\sup _{k \\ge n} a_n + b_n \\le \\sup _{k \\ge n} a_k + \\sup _{k \\ge n} b_k\n    \\end{align*}\n    for sufficiently large $ n $. Taking the limits, whose existence indicated by the question, on both sides gives the result (any decreasing sequence has its limit the same as its infimum).\n\n    \\item Clearly $ \\inf _{k \\ge n} a_k \\le \\inf _{k \\ge n} b_k $ for any $ n $. This completes the proof.\n  \\end{enumerate}\n\n  Define\n  \\begin{align*}\n    a_n &= 1, -1, 1, -1, 1, ...\\\\\n    b_n &= -1, 1, -1, 1, -1, ...\n  \\end{align*}\n  Obviously, $ \\limsup a_n = \\limsup b_n = 1 $, while $ \\limsup a_n + b_n = 0 $.\n\\end{exercise}\n\n\\begin{exercise}\n  \\begin{enumerate}\n    \\item Suppose $ f: X \\to [-\\infty, \\infty] $ and $ g: X \\to [-\\infty, \\infty] $ are measurable. Prove that the sets\n    \\begin{align*}\n      \\{x: f(x) < g(x) \\}, \\{x: f(x) = g(x) \\}\n    \\end{align*}\n    are measurable.\n\n    \\item Prove that the set of points at which a sequence of measurable real-valued functions converges (to a finite limit) is measurable.\n\n  \\end{enumerate}\n\n  \\paragraph{Solution. }\n  \\begin{enumerate}\n    \\item Notice\n    \\begin{align*}\n      \\{f < g\\} = \\bigcup _{r \\in \\mathbb Q} \\{f < r\\} \\cap \\{r < g\\}\n    \\end{align*}\n    therefore measurable. By symmetry, $ \\{f > g\\} $ is measurable as well. Now $ \\{f = g\\} $ is the complement of $ \\{f > g\\} \\cup \\{f < g\\} $ thus must be measurable.\n\n    \\item For any sequence of functions $ f_n $, the set of points the sequence converges to a finite limit is\n    \\begin{align*}\n      \\{\\limsup f_n = \\liminf f_n \\} \\cap \\{\\limsup f_n < \\infty \\}.\n    \\end{align*}\n    Since the upper and lower limits of a sequence of functions are measurable functions, the above set is measurable.\n  \\end{enumerate}\n\n\\end{exercise}\n\n\\begin{exercise}\n  Let $ X $ be an uncountable set, let $ \\mathcal{M} $ be the collection of all sets $ E \\subset X $ such that either $ E $ or $ E^c $ is at most countable, and define $ \\mu(E) = 0 $ in the first case, $ mu(E) = 1 $ in the second. Prove that $ \\mathcal{M} $ is a $ \\sigma $-algebra in $ X $ and that $ \\mu $ is a measure on $ \\mathcal{M} $. Describe the corresponding measurable functions and their integrals.\n\n  \\paragraph{Solution. }\n  It suffices to prove $ \\mathcal{M} $ is closed under countable union and $ \\mu $ is a measure. Notice for any sequence of sets $ E_n $ in $ \\mathcal{M} $, if all of them are at most countable, so must be their union. Therefore $ \\bigcup E_n \\in \\mathcal{M} $, and $ \\mu(\\bigcup E_n) = 0 = \\sum \\mu(E_n) $. If $ E_i $ have its complement at most countable, $ \\left (\\bigcup E_n \\right )^c = \\bigcap E_n^c \\subset E_i^c$ is at most countable. Hence $ \\bigcup E_n \\in \\mathcal{M} $.\n  Further, if $ E_n $ are disjoint, for any set $ E_j, j \\ne i $, $ X \\subset E_i^c \\cup E_j^c $, showing $ E_j^c $ must be uncountable, therefore $ E_j $ must be at most countable and $ \\sum \\mu(E_n) = 1 = \\mu \\left (\\bigcup E_n \\right ) $.\n\n  Only describe integrals of non-negative functions, the general case follows is of no interest. Since any singalton is Borel, for any $ r \\in [0, \\infty] $, a measurable function $ f: X \\to [0, \\infty] $ would have $ f ^{-1}(r) $ either at most countable or have a at most countable complement. Take $ A $ as the set of $ r $ such that $ f ^{-1}(r)  $ has an at most countable complement. Then if $ A $ is countable, it is easy to check $ \\int f = \\sum _{r \\in A} r  $. If $ A $ is uncountable, then $ \\int f = \\infty $. 21\n\n\n\\end{exercise}\n\n\n\\end{document}\n", "meta": {"hexsha": "cd9a45e44bf1703b697adbf1a289c4a921c9309b", "size": 6824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_1/chapter_1.tex", "max_stars_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_stars_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_stars_repo_licenses": ["MIT"], "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/chapter_1.tex", "max_issues_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_issues_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_issues_repo_licenses": ["MIT"], "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/chapter_1.tex", "max_forks_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_forks_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_forks_repo_licenses": ["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.0322580645, "max_line_length": 524, "alphanum_fraction": 0.6214830012, "num_tokens": 2408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914997895581, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6431519434485169}}
{"text": "% !TeX TXS-program:compile = txs:///pdflatex/\n% !TeX TXS-program:bibliography = txs:///biber\n% !TeX program = pdflatex\n% !BIB program = biber\n\n\\subsection{Structural Estimation}\n\\label{sec:structural}\n\n\\blindmathfalse\n\\Blindtext[1]\n\n\\[\n\t\\mathbfup{\\Sigma} \\coloneqq\n\t\\mathup{Cov}(\\mathbf{X}) =\n\t\\begin{bmatrix}\n\t\t\\mathup{Var}(X_1)      & \\cdots & \\mathup{Cov}(X_1, X_n) \\\\[-2.5pt]\n\t\t\\vdots                 & \\ddots & \\vdots                 \\\\\n\t\t\\mathup{Cov}(X_n, X_1) & \\cdots & \\mathup{Var}(X_n)\n\t\\end{bmatrix}\n\\]", "meta": {"hexsha": "c7c5b7d82957ac58e31088ae11b4406239bd41ff", "size": 513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "200+ beamer 模板合集/TeXTemplates(论文，报告，beamer，学术报告)/1_Example_Content/3_Results/Structural_Estimation.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": "200+ beamer 模板合集/TeXTemplates(论文，报告，beamer，学术报告)/1_Example_Content/3_Results/Structural_Estimation.tex", "max_issues_repo_name": "lemoxiao/Awesome-Beamer-Collection", "max_issues_repo_head_hexsha": "3ab28a23fb60cb0a97fcec883847e2d8728b98c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "200+ beamer 模板合集/TeXTemplates(论文，报告，beamer，学术报告)/1_Example_Content/3_Results/Structural_Estimation.tex", "max_forks_repo_name": "lemoxiao/Awesome-Beamer-Collection", "max_forks_repo_head_hexsha": "3ab28a23fb60cb0a97fcec883847e2d8728b98c0", "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": 25.65, "max_line_length": 69, "alphanum_fraction": 0.6062378168, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6431082450957042}}
{"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*{augment\\_unicycle.m} \n\n\\begin{par}\n\\textbf{Summary:} The function computes the $(x,y)$ velocities of the contact point in both absolute and unicycle coordinates as well as the the unicycle coordinates of the contact point themselves.\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}     function r = augment(s)\\end{verbatim}\n    \\begin{par}\n\\textbf{Input arguments:}\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\n%\t\ts     state of the unicycle (including the torques).             [1 x 18]\n%         The state is assumed to be given as follows:\n%         dx      empty (to be filled by this function)\n%         dy      empty (to be filled by this function)\n%         dxc     empty (to be filled by this function)\n%         dyc     empty (to be filled by this function)\n%         dtheta  roll angular velocity\n%         dphi    yaw angular velocity\n%         dpsiw   wheel angular velocity\n%         dpsif   pitch angular velocity\n%         dpsit   turn table angular velocity\n%         x       x position\n%         y       y position\n%         xc      empty (to be filled by this function)\n%         yc      empty (to be filled by this function)\n%         theta   roll angle\n%         phi     yaw angle\n%         psiw    wheel angle\n%         psif    pitch angle\n%         psit    turn table angle\n%\n% *Output arguments:*\n%\n%   r     additional variables that are computed based on s:          [1 x 6]\n%         dx    x velocity of contact point (global coordinates)\n%         dy    y velocity of contact point (global coordinates)\n%         dxc   x velocity of contact point (unicycle coordinates)\n%         dyc   y velocity of contact point (unicycle coordinates)\n%         xc    x position of contact point (unicycle coordinates)\n%         yc    y position of contact point (unicycle coordinates)\n%\n%\n% Copyright (C) 2008-2013 by\n% Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.\n%\n% Last modified: 2013-03-27\n\n\nfunction r = augment_unicycle(s)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\nrw = 0.225;                               % wheel radius in meters\n\n% x velocity of contact point (global coordinates)\nr(1) = rw*cos(s(15))*s(7);\n% y velocity of contact point (global coordinates)\nr(2) = rw*sin(s(15))*s(7);\n% (x,y) velocities of contact point (unicycle coordinates)\nA = -[cos(s(15)) sin(s(15)); -sin(s(15)) cos(s(15))];\ndA = -s(6)*[-sin(s(15)) cos(s(15)); -cos(s(15)) -sin(s(15))];\nr(3:4) = A*r(1:2)' + dA*s(10:11)';\n% (x,y) coordinates of contact point (unicycle coordinates)\nr(5:6) = A*s(10:11)';\n\\end{lstlisting}\n", "meta": {"hexsha": "f5abe2749cc4db989e8614a9b96bad93eb54ec5e", "size": 2706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/augment_unicycle.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/augment_unicycle.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/augment_unicycle.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": 33.4074074074, "max_line_length": 198, "alphanum_fraction": 0.6223207687, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6431082410349169}}
{"text": "\\title{Supervised Learning (Classification)}\n\n\\subsection{Supervised Learning (Classification)}\n\nIn supervised learning, the task is to infer hidden structure from\nlabeled data, comprised of training examples $\\{(x_n, y_n)\\}$.\nClassification means the output $y$ takes discrete values.\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/supervised_classification.ipynb}{here}.\n\n\\subsubsection{Data}\n\nWe use the\n\\href{https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/crabs.html}\n{crabs data set},\nwhich consists of morphological measurements on a crab species. We\nare interested in predicting whether a given crab has the color form\nblue (encoded as 0) or orange (encoded as 1). We use all the numeric features\nin the dataset.\n\\begin{lstlisting}[language=Python]\nfrom observations import crabs\n\ndata, metadata = crabs(\"~/data\")\nX_train = data[:100, 3:]\ny_train = data[:100, 1]\n\nN = X_train.shape[0]  # number of data points\nD = X_train.shape[1]  # number of features\n\nprint(\"Number of data points: {}\".format(N))\nprint(\"Number of features: {}\".format(D))\n\\end{lstlisting}\n\n\\begin{lstlisting}\nNumber of data points: 100\nNumber of features: 5\n\\end{lstlisting}\n\n\\subsubsection{Model}\n\nA Gaussian process is a powerful object for modeling nonlinear\nrelationships between pairs of random variables. It defines a distribution over\n(possibly nonlinear) functions, which can be applied for representing\nour uncertainty around the true functional relationship.\nHere we define a Gaussian process model for classification\n\\citep{rasmussen2006gaussian}.\n\nFormally, a distribution over functions $f:\\mathbb{R}^D\\to\\mathbb{R}$ can be specified\nby a Gaussian process\n\\begin{align*}\n  p(f)\n  &=\n  \\mathcal{GP}(f\\mid \\mathbf{0}, k(\\mathbf{x}, \\mathbf{x}^\\prime)),\n\\end{align*}\nwhose mean function is the zero function, and whose covariance\nfunction is some kernel which describes dependence between\nany set of inputs to the function.\n\nGiven a set of input-output pairs\n$\\{\\mathbf{x}_n\\in\\mathbb{R}^D,y_n\\in\\mathbb{R}\\}$,\nthe likelihood can be written as a multivariate normal\n\\begin{align*}\n  p(\\mathbf{y})\n  &=\n  \\text{Normal}(\\mathbf{y} \\mid \\mathbf{0}, \\mathbf{K})\n\\end{align*}\nwhere $\\mathbf{K}$ is a covariance matrix given by evaluating\n$k(\\mathbf{x}_n, \\mathbf{x}_m)$ for each pair of inputs in the data\nset.\n\nThe above applies directly for regression where $\\mathbb{y}$ is a\nreal-valued response, but not for (binary) classification, where $\\mathbb{y}$\nis a label in $\\{0,1\\}$. To deal with classification, we interpret the\nresponse as latent variables which is squashed into $[0,1]$. We then\ndraw from a Bernoulli to determine the label, with probability given\nby the squashed value.\n\nDefine the likelihood of an observation $(\\mathbf{x}_n, y_n)$ as\n\\begin{align*}\n  p(y_n \\mid \\mathbf{z}, x_n)\n  &=\n  \\text{Bernoulli}(y_n \\mid \\text{logit}^{-1}(z_n)).\n\\end{align*}\n\nDefine the prior to be a multivariate normal\n\\begin{align*}\n  p(\\mathbf{z})\n  &=\n  \\text{Normal}(\\mathbf{z} \\mid \\mathbf{0}, \\mathbf{K}),\n\\end{align*}\nwith covariance matrix given as previously stated.\n\nLet's build the model in Edward. We use a radial basis function (RBF)\nkernel, also known as the squared exponential or exponentiated\nquadratic. It returns the kernel matrix evaluated over all pairs of\ndata points; we then Cholesky decompose the matrix to parameterize the\nmultivariate normal distribution.\n\\begin{lstlisting}[language=Python]\nfrom edward.models import Bernoulli, MultivariateNormalTriL\nfrom edward.util import rbf\n\nX = tf.placeholder(tf.float32, [N, D])\nf = MultivariateNormalTriL(loc=tf.zeros(N), scale_tril=tf.cholesky(rbf(X)))\ny = Bernoulli(logits=f)\n\\end{lstlisting}\nHere, we define a placeholder \\texttt{X}. During inference, we pass in\nthe value for this placeholder according to data.\n\n\\subsubsection{Inference}\n\nPerform variational inference.\nDefine the variational model to be a fully factorized normal.\n\\begin{lstlisting}[language=Python]\nqf = Normal(loc=tf.Variable(tf.random_normal([N])),\n            scale=tf.nn.softplus(tf.Variable(tf.random_normal([N]))))\n\\end{lstlisting}\n\nRun variational inference for \\texttt{500} iterations.\n\\begin{lstlisting}[language=Python]\ninference = ed.KLqp({f: qf}, data={X: X_train, y: y_train})\ninference.run(n_iter=500)\n\\end{lstlisting}\nIn this case\n\\texttt{KLqp} defaults to minimizing the\n$\\text{KL}(q\\|p)$ divergence measure using the reparameterization\ngradient.\nFor more details on inference, see the \\href{/tutorials/klqp}{$\\text{KL}(q\\|p)$ tutorial}.\n(This example happens to be slow because evaluating and inverting full\ncovariances in Gaussian processes happens to be slow.)\n\n% \\subsubsection{Criticism}\n\n\\subsubsection{References}\\label{references}\n", "meta": {"hexsha": "bae124ae6a384f816396feec72d7b4ff023ded95", "size": 4818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/supervised-classification.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-04-06T15:08:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T15:08:53.000Z", "max_issues_repo_path": "docs/tex/tutorials/supervised-classification.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/supervised-classification.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": 35.4264705882, "max_line_length": 118, "alphanum_fraction": 0.7579908676, "num_tokens": 1311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.643108227114347}}
{"text": "\\chapter{Latent variable models for discrete data}\n\n\n\\section{Introduction}\nIn this chapter, we are concerned with latent variable models for discrete data, such as bit vectors, sequences of categorical variables, count vectors, graph structures, relational data, etc. These models can be used to analyse voting records, text and document collections, low-intensity images, movie ratings, etc. However, we will mostly focus on text analysis, and this will be reflected in our terminology.\n\nSince we will be dealing with so many different kinds of data, we need some precise notation to keep things clear. When modeling variable-length sequences of categorical variables (i.e., symbols or \\textbf{tokens}), such as words in a document, we will let $y_{il} \\in \\{1,\\cdots,V\\}$ represent the identity of the $l$'th word in document $i$,where $V$ is the number of possible words in the vocabulary. We assume $l=1:L_i$, where $L_i$ is the (known) length of document $i$, and $i=1:N$, where $N$ is the number of documents.\n\nWe will often ignore the word order, resulting in a \\textbf{bag of words}. This can be reduced to a fixed length vector of counts (a histogram). We will use $n_{iv} \\in \\{0,1,\\cdots,Li\\}$ to denote the number of times word $v$ occurs in document $i$, for $v=1:V$. Note that the $N \\times V$ count matrix $\\vec{N}$ is often large but sparse, since we typically have many documents, but most words do not occur in any given document.\n\nIn some cases, we might have multiple different bags of words, e.g., bags of text words and bags of visual words. These correspond to different “channels” or types of features. We will denote these by $y_{irl}$, for $r=1:R$(the number of responses) and $l=1:L_{ir}$. If $L_{ir} =1$,it means we have a single token (a bag of length 1); in this case, we just write $y_{ir} \\in \\{1,\\cdots,V_r\\}$ for brevity. If every channel is just a single token, we write the fixed-size response vector as $y_{i,1:R}$; in this case, the $N \\times R$ design matrix \\vec{Y} will not be sparse. For example, in social science surveys, $y_{ir}$ could be the response of personito the $r$'th multi-choice question.\n\nOut goal is to build joint probability models of $p(\\vec{y}_i)$ or $p(\\vec{n}_i)$ using latent variables to capture the correlations. We will then try to interpret the latent variables, which provide a compressed representation of the data. We provide an overview of some approaches in Section 27.2 TODO, before going into more detail in later sections.\n\n\n\\section{Distributed state LVMs for discrete data}\n\n", "meta": {"hexsha": "f1a9d7dc3e05b8c1b25a25a958ef2e386bc13681", "size": 2554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterLVM.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/chapterLVM.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/chapterLVM.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": 141.8888888889, "max_line_length": 693, "alphanum_fraction": 0.7513703994, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6430948349408847}}
{"text": "\\section{Decision Trees}\n\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 = \\binom{n}{n/k, \\ldots, n/k} \\pause = \\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}{$K$-sorted (Problem 2.9)}\n  \\centerline{Sorting the $k$-sorted array.}\n\n  \\pause\n  \\[\n\tO(n \\log \\frac{n}{k})\n  \\]\n\n  \\pause\n  \\[\n\tL = ((\\frac{n}{k})!)^k\n  \\]\n\n  \\pause\n  \\[\n\tH \\ge \\log ((\\frac{n}{k})!)^k = \\Omega(n \\log \\frac{n}{k})\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "19a5521aa87cd015268031f535a15e48e2a64427", "size": 1167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-algorithm-analysis-20170412/sections/decision-tree.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-algorithm-analysis-20170412/sections/decision-tree.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-algorithm-analysis-20170412/sections/decision-tree.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": 17.4179104478, "max_line_length": 87, "alphanum_fraction": 0.4815766924, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6430948331498579}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{hyperref}\n\n\\begin{document}\n\n\\section{Math stuff}\n\nCubic interpolation for one segment $[x_k, x_{k+1}]$ can be described as:\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tf(t) &= c_{oef1}t^3 + c_{oef2}t^2 + c_{oef3}t + c_{oef4}  \\hspace{1cm} with \\\\\n\t\tt(x) &= \\frac{x - x_k}{x_{k+1} - x_k}\n\t\\end{aligned}\n\\end{equation*}\n\n\\hspace{1cm} and\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tc_{oef1} &= 2p_0 - 2p_1 - m_0 - m_1 \\\\\n\t\tc_{oef2} &= -3p_0 + 3p_1 - 2m_0 - m_1 \\\\\n\t\tc_{oef3} &= m_0 \\\\\n\t\tc_{oef4} &= p_0\n\t\\end{aligned}\n\\end{equation*}\n\n\n(see Wikipedia-Links below)\\\\\n\\\\\nIf we rewrite this as function of $d = x - x_k$ we get\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tf'(d) &= c_{oef1}' d^3 + c_{oef2}' d^2 + c_{oef3}' d + c_{oef4}' \\hspace{1cm} with \\\\\n\t\tc_{oef1}' &= \\frac{c_{oef1}}{(x_{k+1} - x_k)^3} \\\\\n        c_{oef2}' &= \\frac{c_{oef2}}{(x_{k+1} - x_k)^2} \\\\\n        c_{oef3}' &= \\frac{c_{oef3}}{x_{k+1} - x_k} \\\\\n        c_{oef4}' &= c_{oef4}\n    \\end{aligned}\n\\end{equation*}\n\\\\\nThe implemented algorithm uses two helper variables to calculate the coefficients of $f'$ efficiently:\n\n\\begin{equation*}\n\t\\begin{aligned}\n\t\tcommon = m_k + m_{k+1} - 2 \\frac{p_{k+1} - p_k}{x_{k+1} - x_k} \\\\\n\t\tinvLength = \\frac{1}{x_{k+1} - x_k}\n    \\end{aligned}\n\\end{equation*}\n\\\\\nWe use $p_0 = p_k$, $p_1 = p_{k+1}$, $m_0 = m_k (x_{k+1} - x_k)$, $m_1 = m_{k+1} (x_{k+1} - x_k)$ and $s = \\frac{p_{k+1}-p_k}{x_{k+1}-x_k}$. The tangents are scaled with the length of the segment. \\\\\n\\\\\nIf we insert this into the equations for the coefficients we get the formulas that are used in the algorithm:\n\n\\begin{equation*}\n\\begin{aligned}\n\tc_{oef1}' &= \\frac{c_{oef1}}{(x_{k+1} - x_k)^3} \\\\\n\t&= \\frac{2p_0 - 2p_1 + m_0 + m_1}{(x_{k+1} - x_k)^3}\\\\\n\t&= (2p_k - 2p_{k+1} + m_k (x_{k+1} - x_k) + m_{k+1} (x_{k+1} - x_k) / (x_{k+1} - x_k)^3 \\\\\n\t&= \\frac {(2p_k - 2p_{k+1} + m_k (x_{k+1} - x_k) + m_{k+1} (x_{k+1} - x_k)}{x_{k+1} - x_k} / (x_{k+1} - x_k)^2 \\\\\n\t&= (\\frac {2p_k - 2p_{k+1}}{x_{k+1} - x_k} + m_k + m_{k+1}  ) * invLength^2 \\\\\n\t&= (-2\\frac {p_{k+1}- p_k}{x_{k+1} - x_k} + m_k + m_{k+1}  ) * invLength^2 \\\\\n\t&= common * invLenght^2\n\\end{aligned}\n\\end{equation*}\n \n\\begin{equation*}\n\\begin{aligned}\n\tc_{oef2}' &= \\frac{c_{oef2}}{(x_{k+1} - x_k)^2} \\\\\n\t&= (-3p_0 + 3p_1 - 2m_0 - m_1) / (x_{k+1} - x_k)^2 \\\\\n\t&= (-3p_k + 3p_{k+1} - 2* m_k (x_{k+1} - x_k) - m_{k+1} (x_{k+1} - x_k)) / (x_{k+1} - x_k)^2 \\\\\n\t&= (\\frac{-3p_k + 3p_{k+1}}{x_{k+1} - x_k} - 2m_k - m_{k+1}) * invLenght \\\\\n\t&= (3\\frac{p_{k+1} - p_k}{x_{k+1} - x_k} - 2m_k - m_{k+1}) * invLenght \\\\\n\t&=(\\frac{p_{k+1} - p_k}{x_{k+1} - x_k} + 2\\frac{p_{k+1} - p_k}{x_{k+1} - x_k} - m_k - m_{k+1} - m_k) * invLenght \\\\\n\t&= (s - common - m_k) * invLenght  \n\\end{aligned}    \n\\end{equation*}\n \n\\begin{equation*}\n\\begin{aligned}\n\tc_{oef3}' &= \\frac{c_{oef3}}{x_{k+1} - x_k} \\\\\n\t&= \\frac{m_0}{x_{k+1} - x_k} \\\\\n\t&= \\frac{m_k (x_{k+1} - x_k)}{x_{k+1} - x_k} \\\\\n \t&= m_k\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\tc_{oef4}' &= c_{oef4} = p_0 = p_k\n\\end{aligned}\n\\end{equation*}\n\n\\section{Useful Links}\n\n\\url{http://de.wikipedia.org/w/index.php?title=Kubisch_Hermitescher_Spline&oldid=130168003)}\\\\\n\\url{http://en.wikipedia.org/w/index.php?title=Monotone_cubic_interpolation&oldid=622341725}\\\\\n\\url{http://math.stackexchange.com/questions/45218/implementation-of-monotone-cubic-interpolation}\\\\\n\\url{http://math.stackexchange.com/questions/4082/equation-of-a-curve-given-3-points-and-additional-constant-requirements#4104}\n\n\\end{document}", "meta": {"hexsha": "97fd3bf94faefd79cc680e84ec8d8943bad0d3a6", "size": 3601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/assets/plugins/flot.curvedlines/docu/MathStuff.tex", "max_stars_repo_name": "mohamedalasmar/invoices-prog", "max_stars_repo_head_hexsha": "d92a3dbec093978f0a0e730dde673be9533dd772", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2020-09-28T21:57:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T14:32:07.000Z", "max_issues_repo_path": "public/assets/plugins/flot.curvedlines/docu/MathStuff.tex", "max_issues_repo_name": "mohamedalasmar/invoices-prog", "max_issues_repo_head_hexsha": "d92a3dbec093978f0a0e730dde673be9533dd772", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-06-07T20:40:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T01:06:03.000Z", "max_forks_repo_path": "public/assets/plugins/flot.curvedlines/docu/MathStuff.tex", "max_forks_repo_name": "mohamedalasmar/invoices-prog", "max_forks_repo_head_hexsha": "d92a3dbec093978f0a0e730dde673be9533dd772", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2020-10-17T14:42:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T21:01:16.000Z", "avg_line_length": 34.2952380952, "max_line_length": 199, "alphanum_fraction": 0.5909469592, "num_tokens": 1697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6430948312161345}}
{"text": "\\documentclass[letterpaper,12pt,leqno]{article}\n\\usepackage{paper,math,notes}\n\\newcommand{\\pdf}{phasediagrams.pdf} \n\\available{https://www.pascalmichaillat.org/t3.html}\n\\hypersetup{pdftitle={Differential Equations}}\n\n\\begin{document}\n\n\\title{Differential Equations}\n\\author{Pascal Michaillat}\n\\date{}\n\n\\begin{titlepage}\n\\maketitle\n\\tableofcontents\n\\end{titlepage}\n\n\\section{First-Order Differential Equations}\\label{sec:one}\n\n\\subsection{Constant Growth Rate}\n\nLet $x(t)$ be a function of time $t\\in\\R$. Let \\[\\dot{x}(t)\\equiv dx/dt\\] denote the derivative of $x(t)$ with respect to time. \n\nConsider the equation \n\\begin{equation}\n\\dot{x}(t) -\\l\\cdot x(t) = 0\n\\label{eq:FODE1}\\end{equation}\nwhere $\\l\\in\\R$ is a constant. Equation~\\eqref{eq:FODE1} is a first-order differential equation (FODE), because it involves $x(t)$ and the first-order derivative of $x(t)$ with respect to time: $\\dot{x}(t)$.  Equation~\\eqref{eq:FODE1} is a functional equation: the unknown is the function $x(t)$ rather than a number or a vector. Solving equation~\\eqref{eq:FODE1} means finding the functions $x(t)$ that, together with their derivative $\\dot{x}(t)$, satisfy equation~\\eqref{eq:FODE1} for all $t \\in \\R$.\n\nEquation~\\eqref{eq:FODE1} is an especially simple differential equation. It can be rewritten as \n\\[\\frac{\\dot{x}(t)}{x(t)}= \\l,\\]\nso it imposes that $x(t)$ has a constant growth rate $\\l$ over time. It admits a simple class of functions as solution:\n\\begin{equation}\nx(t) =A\\cdot  e^{\\l \\cdot t} \\label{eq:FODE1sol},\n\\end{equation}\nfor any constant $A\\in \\R$. Furthermore, the constant $A$ can be determined by an additional boundary condition because\n\\[A=x(0)=x(t_{0})\\cdot e^{-\\l \\cdot t_{0}}\\]\nfor any date $t_{0}\\in \\R$.\n\nIt is clear that functions of the type~\\eqref{eq:FODE1sol} satisfy equation~\\eqref{eq:FODE1}. We now show that if a function $x(t)$ solves equation~\\eqref{eq:FODE1}, it is necessarily of the type~\\eqref{eq:FODE1sol}.\nObserve that\n\\begin{equation*}\n\\frac{\\dot{x}(t)}{x(t)}=\\od{\\ln{x(t)}}{t},\n\\end{equation*}\nwhich allows us to rewrite differential equation~\\eqref{eq:FODE1} as \n\\begin{equation*}\n\\frac{d\\ln x(t)}{dt}=\\l\n\\end{equation*}\nLet $t_{0}\\in\\R$. Integrating the equation from $t_{0}$ to $t$, $x(t)$ necessarily satisfies\n\\begin{align*}\n\\int_{t_{0}}^{t} d\\ln x(t)&=\\int_{t_{0}}^{t} \\l\\cdot dt\\\\\n\\ln{x(t)} -\\ln{ x\\bp{t_{0}}}& =\\l \\bp{t-t_{0}}\\\\\nx(t)&=x(t_{0})\\cdot  e^{\\l \\cdot(t-t_{0})}=\\bs{x(t_{0})\\cdot e^{-\\l \\cdot t_{0}}}\\cdot e^{\\l \\cdot t}.\n\\end{align*}\nTherefore, if $x(t)$ solves equation~\\eqref{eq:FODE1}, it is necessarily of the type~\\eqref{eq:FODE1sol}.\n\n \n\\subsection{Constant Coefficient}\n\nWe have solved the simplest FODE, which takes the form of equation~\\eqref{eq:FODE1}. We now study a more general FODE: \n\\begin{equation}\n\\dot{x}(t)-\\l \\cdot x(t) =f(t),\\label{eq:FODE2}\n\\end{equation}\nwhere $f(t)\\in \\R$. Equation~\\eqref{eq:FODE1} is the special case of equation~\\eqref{eq:FODE2} with $f(t)=0$ for all $t$.\n\nEquation~\\eqref{eq:FODE2} admits a simple class of functions as solution:\n\\begin{equation}\nx(t)=e^{\\l \\cdot t} \\cdot \\bs{A+\\int_{0}^{t}f(z) \\cdot e^{-\\l \\cdot z} dz} \\label{eq:FODE2sol}\n\\end{equation}\nfor any constant $A\\in \\R$. Furthermore, the constant $A$ can be determined by an additional boundary condition because\n\\[A=x(0)=x(t_{0})\\cdot e^{-\\l \\cdot t_{0}}-\\int_{0}^{t_{0}}f(z) \\cdot e^{-\\l \\cdot z} dz\\]\nfor any date $t_{0}\\in \\R$.\n\nIt is clear that functions of the type~\\eqref{eq:FODE2sol} satisfy equation~\\eqref{eq:FODE2}. We now show that if a function $x(t)$ solves equation~\\eqref{eq:FODE2}, it is necessarily of the type~\\eqref{eq:FODE2sol}.\n\nTo be able to solve the FODE, we manipulate a certain function $x(t)\\cdot \\mu(t)$ instead of manipulating $x(t)$ directly. The auxiliary function $\\mu(t) $ is called the \\textit{integrating factor}. The integrating factor for this problem is \n\\[\\mu(t) =e^{-\\l \\cdot t}.\\]\nThis integrating factor $\\mu(t)$ has the desirable property that $\\dot{\\mu}(t) =-\\l \\cdot \\mu(t)$.\n\nWe multiply both sides of the differential equation~\\eqref{eq:FODE2} by the integrating factor to obtain\n\\begin{align*}\n\\dot{x}(t) \\cdot \\mu(t) -\\l \\cdot x(t)\\cdot  \\mu(t) & =f(t) \\cdot \\mu(t)\\\\\n\\dot{x}(t) \\cdot\\mu(t) +x(t) \\cdot\\dot{\\mu}(t) &=f(t)\\cdot \\mu(t)\\\\\n\\od{\\bs{x(t) \\cdot \\mu(t)}}{t}& =f(t) \\cdot\\mu(t).\n\\end{align*}\nIntegrating the equation from $t_{0}\\in \\R$ to $t$ we obtain\n\\begin{align}\n\\int_{t_{0}}^{t} d\\bs{x(t) \\cdot \\mu(t)}&=\\int_{t_{0}}^{t}f(z) \\cdot \\mu(z) dz\\nonumber\\\\\nx(t)\\cdot \\mu(t)-x(t_{0})\\cdot \\mu\\bp{t_{0}}&=\\int_{t_{0}}^{t}f(z)\\cdot  \\mu(z) dz\\nonumber\\\\\nx(t)& =\\frac{x\\bp{t_{0}} \\cdot \\mu\\bp{t_{0}}+\\int_{t_{0}}^{t}f(z) \\cdot \\mu(z) dz}{\\mu(t)}.\\label{eq:INTER}\n\\end{align}\nGiven the definition of the integrating factor $\\mu(t)$, \n\\begin{align*}\nx(t)& =e^{\\l \\cdot t} \\cdot \\bs{x\\bp{t_{0}} \\cdot e^{-\\l\\cdot t_{0}}+\\int_{t_{0}}^{t}f(z) \\cdot e^{-\\l \\cdot z} dz}.\n\\end{align*}\nTherefore, there exists $A\\in \\R$ such that \n\\begin{align*}\nx(t)& =e^{\\l \\cdot t} \\cdot \\bs{A+\\int_{0}^{t}f(z) \\cdot e^{-\\l \\cdot z} dz} .\n\\end{align*}\n\n\\subsection{General Case}\n\nWe now generalize~\\eqref{eq:FODE2} to allow the coefficient $\\l$ to vary with time $t$. We solve\n\\begin{equation}\n\\dot{x}(t) -\\l(t) \\cdot x(t) =f(t),\\label{eq:FODE3}\n\\end{equation}\nwith $\\l(t)\\in \\R$ and  $f(t)\\in \\R$. \n\nEquation~\\eqref{eq:FODE3} admits the following class of functions as solution:\n\\begin{equation}\nx(t)=\\exp{\\int_{0}^{t}\\l(s) ds} \\cdot \\bs{A+\\int_{0}^{t}f(z) \\cdot \\exp{-\\int_{0}^{z}\\l(s)ds} dz} \\label{eq:FODE3sol}\n\\end{equation}\nfor any constant $A\\in \\R$. Furthermore, the constant $A$ can be determined by an additional boundary condition because\n\\[A=x(0)=x(t_{0})\\cdot \\exp{-\\int_{0}^{t_{0}}\\l(s)ds}-\\int_{0}^{t_{0}}f(z) \\cdot \\exp{-\\int_{0}^{z}\\l(s)ds} dz\\]\nfor any date $t_{0}\\in \\R$.\n\nSome algebra shows that functions of the type~\\eqref{eq:FODE3sol} satisfy equation~\\eqref{eq:FODE3}. We now show that if a function $x(t)$ solves equation~\\eqref{eq:FODE3}, it is necessarily of the type~\\eqref{eq:FODE3sol}. As above, we introduce an integrating factor. The integrating factor for this problem is\n\\begin{equation*}\n\\mu(t) =\\exp \\bp{-\\int_{0}^{t}\\l(s) ds}.\n\\end{equation*}\nThis integrating factor $\\mu(t)$ has the desirable property that \n\\[\\dot{\\mu}(t) =-\\l(t) \\cdot \\mu(t).\\]\n\nWe multiply both sides of equation~\\eqref{eq:FODE3} by the integrating factor to obtain\n\\begin{align*}\n\\dot{x}(t) \\cdot \\mu(t) -\\l(t) \\cdot  \\mu(t) \\cdot x(t)& =f(t) \\cdot \\mu(t)\\\\\n\\dot{x}(t) \\cdot\\mu(t) +x(t) \\cdot \\dot{\\mu}(t) &=f(t)\\cdot \\mu(t)\\\\\n\\od{\\bs{x(t) \\cdot \\mu(t)}}{t}& =f(t) \\cdot\\mu(t).\n\\end{align*}\nIntegrating the equation from $t_{0}\\in \\R$ to $t$ we obtain as earlier equation~\\eqref{eq:INTER}. Therefore the solution to equation~\\eqref{eq:FODE3} is necessarily of the type~\\eqref{eq:FODE3sol}.\n\n\\subsection{Initial-Value Problem}\n\nOften, an initial condition for $x(t) $ is given:\n\\begin{equation}\nx\\bp{t_{0}} =x_{0}.  \\label{eq:ic}\n\\end{equation}\nEquation~\\eqref{eq:FODE3} together with equation~\\eqref{eq:ic} form an initial-value problem. The constant $A$ in~\\eqref{eq:FODE3sol} must satisfy\n\\[A=x_{0}\\cdot \\exp{-\\int_{0}^{t_{0}}\\l(s)ds}-\\int_{0}^{t_{0}}f(z) \\cdot \\exp{-\\int_{0}^{z}\\l(s)ds} dz.\\]\nHence the solution to the initial-value problem is\n\\begin{equation}\nx(t) =x_{0}\\cdot \\exp{\\int_{t_{0}}^{t}\\l(s)ds}+\\int_{t_{0}}^{t}f(z)\\cdot \\exp{\\int_{z}^{t}\\l(s)ds}dz.\\label{eq:icsol}\n\\end{equation}\n\n\\section{Linear Systems of First-Order Differential Equations}\\label{sec:two}\n\nWe often encounter dynamic systems with several variables that move together over time. For example in the consumption-saving problem that we solved with optimal control methods, in the case of CRRA utility, the solution is characterized by two FODEs:\n\\begin{align*}\n\\dot{a}(t) &=r\\cdot a(t)-c(t), \\\\\n\\dot{c}(t) &=\\frac{r-\\rho}{\\g}\\cdot  c(t).\n\\end{align*}\nThe first FODE is the asset accumulation equation and the second FODE is the Euler equation that characterizes optimal consumption over time. To solve explicitly for the optimal consumption path, we need to solve the two FODEs\nsimultaneously. This section presents a method to solve systems of FODEs.\n\nWe consider a system of $n$ FODEs with constant coefficients:\n\\begin{align*}\n\\dot{x}_{1}(t) &=A_{11}\\cdot x_{1}(t)+A_{12}\\cdot x_{2}(t)+\\ldots+A_{1n}\\cdot x_{n}(t) +f_{1}(t) \\\\\n\\dot{x}_{2}(t) &=A_{21}\\cdot x_{1}(t)+A_{22}\\cdot x_{2}(t)+\\ldots+A_{2n}\\cdot x_{n}(t) +f_{2}(t) \\\\\n&. \\\\\n&. \\\\\n&. \\\\\n\\dot{x}_{n}(t) &=A_{n1}\\cdot x_{1}(t)+A_{n2}\\cdot x_{2}(t)+\\ldots+A_{nn}\\cdot x_{n}(t) +f_{n}(t).\n\\end{align*}\nOur goal is to solve for the $n$ functions $x_{1}(t)$, $x_{2}(t),\\ldots, x_{n}(t)$.\n\nAn alternative way of expressing the system is to write it in matrix form:\n\\begin{equation}\n\\bm{\\dot{x}}(t) =\\bm{A}  \\bm{x}(t) +\\bm{f}(t), \\label{eq:FODEsys}\n\\end{equation}\nwhere $\\bm{\\dot{x}}(t) \\in \\R^{n}$, $\\bm{x}(t) \\in \\R^{n}$, and $\\bm{f}(t) \\in \\R^{n}$ are column vectors with $n$ elements. $\\bm{A}\\in \\R^{n\\times n}$ is a constant $n\\times n$ matrix. The system of FODEs is linear because it can be written in matrix form: it involves a linear relationship between the vector $\\bm{\\dot{x}}(t)$ and the vector $\\bm{x}(t)$.\n\nIf $\\bm{A}$ is diagonal ($A_{ij}=0$ for all $i\\neq j$), the system would reduce to a collection of $n$ FODEs---one FODE for each  $x_{i}(t)$---that can be solved independently using the techniques from Section~\\ref{sec:one}.\nIf $\\bm{A}$ is not diagonal, the different entries in $\\bm{x}(t)$ interact and we must solve the system of FODEs simultaneously.\n\n\\subsection{General Solution}\n\nAssume that $\\bm{A}$ is diagonalizable. There exists $\\bm{V}\\in \\R^{n\\times n}$ such that\n\\begin{equation}\n\\bm{A}=\\bm{V}\\bm{\\Lambda}\\bm{V}^{-1},\\label{eq:DECO}\n\\end{equation}\nwhere $\\bm{\\Lambda}\\in \\R^{n\\times n}$ is a diagonal matrix. The diagonal entries of $\\bm{\\Lambda}$ are the $n$ eigenvalues $\\l_{1},\\ldots,\\l_{n}$ of $\\bm{A},$ and $\\bm{V}$ is the matrix whose\ncolumns are the eigenvectors $\\bm{z}_{1},\\ldots,\\bm{z}_{n}$ of $\\bm{A}$. \n\nBy definition, $\\l_{1},\\ldots,\\l_{n}$ are the $n$ roots of the polynomial equation\n\\begin{equation*}\n\\det( \\bp{\\bm{A}-\\l \\bm{I}} =0.\n\\end{equation*}\nFor any $i=1,\\dots,n$, the eigenvector $\\bm{z}_{i}$ associated with the eigenvalue $\\l_{i}$ satisfies \n\\begin{equation*}\n\\bp{\\bm{A}-\\l_{i} \\bm{I}} \\bm{z}_{i} =\\bm{0}.\n\\end{equation*}\n\n\nUsing the decomposition~\\eqref{eq:DECO}, we rewrite the system \\eqref{eq:FODEsys} as\n\\begin{align}\n\\bm{V}^{-1}\\bm{\\dot{x}}(t) &=\\bm{\\Lambda} \\bm{V}^{-1}\\bm{x}(t) +\\bm{V}^{-1}\\bm{f}(t)\\nonumber\\\\\n\\bm{\\dot{y}}(t) &=\\bm{\\Lambda} \\bm{y}(t) +\\bm{g}(t) ,  \\label{eq:FODEsyst}\n\\end{align}\nwhere we define\n\\begin{align*}\n\\bm{y}(t) &\\equiv \\bm{V}^{-1}\\bm{x}(t)\\\\\n\\bm{g}(t) &\\equiv \\bm{V}^{-1}\\bm{f}(t).\n\\end{align*}\nSince the matrix $\\bm{\\Lambda}$ is diagonal, the system is reduced to a collection of $n$ independent FODEs---one for each $y_{i}(t)$. Once we have solved for $\\bm{y}(t)$, we can recover $\\bm{x}(t)$ by \n\\begin{equation*}\n\\bm{x}(t) =\\bm{V} \\bm{y}(t) .\n\\end{equation*}\nThe nature of the eigenvalues and corresponding eigenvectors determines the dynamics of the solution.\n\n\\subsection{Homogenous Systems}\n\nIf $\\bm{f}(t) =\\bm{0}$, the system \\eqref{eq:FODEsys} is homogenous; otherwise it is nonhomogenous. \n\nFor homogenous systems, \n\\begin{equation}\n\\bm{\\dot{x}}(t) =\\bm{A} \\bm{x}(t).\\label{eq:FODEsysh}\n\\end{equation}\nSo the transformed system~\\eqref{eq:FODEsyst} becomes \n\\begin{equation*}\n\\bm{\\dot{y}}(t) =\\bm{\\Lambda}\\bm{y}(t) ,\n\\end{equation*}\nwhich leads to $n$ independent FODEs:\n\\begin{equation*}\n\\dot{y}_{i}(t) -\\l_{i} \\cdot y_{i}(t)=0\n\\end{equation*}\nfor $i=1,\\ldots,n$. In other words, each $y_{i}(t) $ is growing at constant rate $\\l_{i}$. The analysis of Section~\\ref{sec:one} shows that the solution to the $i^{th}$ FODE is \n\\begin{equation*}\ny_{i}(t) =A_{i}\\cdot e^{\\l_{i}\\cdot t}\n\\end{equation*}\nwhere $A_{i}\\in \\R$ is a constant. Finally, $x_{1}(t),\\ldots,x_{n}(t)$ are given by\n\\begin{equation*}\n\\bm{x}(t) =\\bm{V} \\bm{y}(t) .\n\\end{equation*}\nThe columns of $\\bm{V}$ are the eigenvectors $\\bm{z}_{1},\\ldots,\\bm{z}_{n}$ corresponding to the\neigenvalues $\\l_{1},...\\l_{n}$. Hence the solution of the homogenous system~\\eqref{eq:FODEsysh} is \n\\begin{equation}\n\\bm{x}(t) =A_{1}\\cdot \\bm{z}_{1} \\cdot e^{\\l_{1}\\cdot t}+\\ldots+A_{n}\\cdot \\bm{z}_{n}\\cdot e^{\\l_{n}\\cdot t}.\\label{eq:SOLEV}\n\\end{equation}\nThe nature of the eigenvalues and the corresponding eigenvectors determines\nthe dynamics of the solution. \n\n\\subsection{Closed-Form Solution to a Two-Variable Homogenous System}\n\nAs an example, we consider a two-variable homogenous system:\n\\begin{align*}\n\\dot{x}_{1}(t) &=a\\cdot x_{1}(t)+b\\cdot x_{2}(t) \\\\\n\\dot{x}_{2}(t) &=c\\cdot x_{1}(t)+d\\cdot x_{2}(t).\n\\end{align*}\nWe can write it in matrix form\n\\begin{equation*}\n\\bm{\\dot{x}}(t) =\\bm{A} \\bm{x}(t)\n\\end{equation*}\nwhere the matrix $\\bm{A}$ is \n\\begin{equation*}\n\\bm{A}=\\bs{\n\\begin{array}{ll}\na & b \\\\ \nc & d\n\\end{array}}.\n\\end{equation*}\nAssume $\\det(\\bm{A}) =a\\cdot d-b\\cdot c\\neq 0. $\n\nEquation~\\eqref{eq:SOLEV} implies that to determine a closed-form solution of this homogenous system, we need to find the eigenvalues and eigenvectors of the matrix $\\bm{A}$.\n\nThe eigenvalues are solutions to \n\\begin{align*}\n\\det( \\bp{\\bm{A}-\\l \\bm{I}} &=0\\\\\n\\bp{a-\\l} \\cdot \\bp{d-\\l} -b\\cdot c &=0 \\\\\n\\l ^{2}-\\bp{a+d}\\cdot  \\l +\\bp{a\\cdot d-b\\cdot c} &=0.\n\\end{align*}\nNote that the product of the two eigenvalues is equal to the determinant of $\n\\bm{A}$:\n\\begin{equation}\n\\l_{1}\\cdot \\l_{2}=a\\cdot d-b\\cdot c=\\det(\\bm{A}).\\label{eq:DETL}\n\\end{equation}\n\nLet $\\bs{\n\\begin{array}{l}\n\\a_{1} \\\\ \n\\b_{1}\n\\end{array}\n} $ be the eigenvector correspond to $\\l_{1}$ and $\\bs{\n\\begin{array}{l}\n\\a_{2} \\\\ \n\\b_{2}\n\\end{array}} $ be the eigenvector correspond to $\\l_{2}$. These vectors are solutions to \n\\begin{equation*}\n\\bp{\\bm{A}-\\l_{i}\\bm{I}} \\bs{\n\\begin{array}{l}\n\\a_{i} \\\\ \n\\b_{i}\n\\end{array}} =0\n\\end{equation*}\nwhich yields the system\n\\begin{align*}\n\\bp{a-\\l_{i}}\\cdot  \\a_{i}+b\\cdot \\b _{i} &=0 \\\\\nc\\cdot \\a_{i}+\\bp{d-\\l_{i}}\\cdot  \\b _{i} &=0.\n\\end{align*}\n\nConsider the cases where the eigenvalues are real and distinct, the general\nsolution~\\eqref{eq:SOLEV} implies\n\\begin{align*}\nx_{1}(t) &=A_{1}\\cdot \\a_{1}\\cdot e^{\\l_{1}\\cdot t}+A_{2}\\cdot \\a_{2}\\cdot e^{\\l_{2}\\cdot t}\\\\\nx_{2}(t) &=A_{1}\\cdot \\b_{1}\\cdot e^{\\l_{1}\\cdot t}+A_{2}\\cdot \\b_{2}\\cdot e^{\\l_{2}\\cdot t} \n\\end{align*}\nwhere $A_{1}$ and $A_{2}$ are arbitrary constants. \n\nNote that in the case in which $\\l_{1}=\\l_{2}=\\l$, the system $\\bs{x_{1}(t),x_{2}(t)}$ above is still the general solution of the system of FODEs as long as the two eigenvectors $\\bs{\\a_{1},\\b_{1}}$ and $\\bs{\\a_{2},\\b_{2}}$ are linearly independent.\n\nAlso note that any nonhomogenous system with constant terms $\\bs{\\k_{1},\\k_{2}}$:\n\\begin{align*}\n\\dot{x}_{1}(t) &=a\\cdot x_{1}(t)+b\\cdot x_{2}(t)+\\k_{1} \\\\\n\\dot{x}_{2}(t) &=c\\cdot x_{1}(t)+d\\cdot x_{2}(t)+\\k_{2},\n\\end{align*}\ncan be transformed into an homogenous system.\n\n\\subsection{Stability of a Two-Variable Homogenous System}\n\nNow that we have found a closed-form solution to the system, we can analyze its stability. There are three cases.\n\n\\paragraph{Sink: $\\l_{1}<0$ and $\\l_{2}<0$} As shown by~\\eqref{eq:DETL}, since $\\l_{1}$ and $\\l_{2}$ have the same sign, $\\det(\\bm{A}) >0$. As $t\\to +\\infty$, $x_{1}(t)\\to 0$ and $x_{2}(t)\\to 0$. The system is a \\textit{sink}.\n\n\\paragraph{Source: $\\l_{1}>0$ and $\\l_{2}>0$} As shown by~\\eqref{eq:DETL}, since $\\l_{1}$ and $\\l_{2}$ have the same sign, $\\det(\\bm{A}) >0$. As $t\\to +\\infty$, $|x_{1}(t)|\\to +\\infty$ and $|x_{2}(t)|\\to +\\infty$. The system is a \\textit{source}.\n\n\\paragraph{Saddle: $\\l_{1}$ and $\\l_{2}$ have opposite sign} As shown by~\\eqref{eq:DETL}, since $\\l_{1}$ and $\\l_{2}$ have opposite sign, $\\det(\\bm{A}) <0$. One part of the solution is stable (it converges to 0 at $t\\to +\\infty$), the other is unstable (it converges to $\\infty$ at $t\\to +\\infty$). The system is a \\textit{saddle}.\n\n\n\\section{Phase Diagrams}\\label{sec:three}\n\nWithout solving for eigenvalues and eigenvectors explicitly, we can study the properties of a linear system of FODEs by drawing its phase diagram. \n\nHere we construct the phase diagram for the following linear nonhomogenous system of two FODEs:\n\\begin{align}\n\\dot{x}(t) &=a\\cdot x(t)+b\\cdot y(t)+\\k_{1}\\label{eq:nonh1}\\\\\n\\dot{y}(t) &=c\\cdot x(t)+d\\cdot y(t)+\\k_{2}\\label{eq:nonh2}\n\\end{align}\nwith $a<0$, $b<0$, $c<0$, $d>0$, $\\k_{1}>0$, and $\\k_{2}>0$. Since $a\\cdot d-b\\cdot c<0$, the eigenvalues of the system are of opposite sign. Hence the dynamical system is a saddle.\n\nDrawing the phase diagram of a two-variable system is useful to understand the main features of the dynamic system without solving for $x(t) $ and $y(t)$ explicitly. The phase diagram is represented in figure~\\ref{f:phase}.\n\n\\begin{figure}[p]\n\\subcaptionbox{Nullclines \\label{f:phase1}}{\\includegraphics[scale=\\sfig,page=1]{\\pdf}}\\hfill\n\\subcaptionbox{Steady state \\label{f:phase2}}{\\includegraphics[scale=\\sfig,page=2]{\\pdf}}\\vfig\n\\subcaptionbox{Directional arrows \\label{f:phase3}}{\\includegraphics[scale=\\sfig,page=3]{\\pdf}}\\hfill\n\\subcaptionbox{Trajectories \\label{f:phase4}}{\\includegraphics[scale=\\sfig,page=4]{\\pdf}}\n\\caption{Phase diagram for the dynamical system \\eqref{eq:nonh1}--\\eqref{eq:nonh2}}\n\\label{f:phase}\\end{figure}\n\n\n\\subsection{Nullclines}\n\nWe first plot the nullclines, which are the loci $\\dot{x}=0$ and $\\dot{y}=0$ (figure~\\ref{f:phase1}). \n\nThe locus for $\\dot{x}=0$ is given by\n\\begin{align*}\ny=-\\frac{a}{b}\\cdot x-\\frac{\\k_{1}}{b}.\n\\end{align*}\nThe locus is a straight line with a negative slope in the $(x,y)$ plan. \n\nThe locus for $\\dot{y}=0$ is given by\n\\begin{align*}\ny=-\\frac{c}{d}\\cdot x-\\frac{\\k_{2}}{d}.\n\\end{align*}\nThe locus is a straight line with positive slope in the $(x,y)$ plan.\n\n\\subsection{Steady state}\n\nNext we place the system's steady state(figure~\\ref{f:phase2}). The steady state is given by the intersection of the two nullclines. Denote the intersection of the two nullclines as $\\bp{x^{*},y^{*}} $. These two nullclines divide the $(x,y)$ plane into four areas.\\footnote{In some other fields the steady state of the system is called \\textit{critical point} of the system.}\n\n\\subsection{Directional arrows}\n\nThen we place on the diagram the directional arrows. These arrows determine the direction of the system's trajectories over time anywhere on the phase diagram (figure~\\ref{f:phase3}). \n\nFrom~\\eqref{eq:nonh1}, we see that $\\dot{x}$ is decreasing in $y$ because $b<0$. Thus any point above the $\\dot{x}=0$ line must have $\\dot{x}<0$ and any point below the $\\dot{x}=0$ line must have $\\dot{x}>0$. We represent these properties by an horizontal arrow pointing west for any point above the $\\dot{x}=0$ line and an horizontal arrow pointing east for any point below the $\\dot{x}=0$ line. \n\nSimilarly, from \\eqref{eq:nonh2}, $\\dot{y}$ is increasing in $y$ because $d>0$. Thus any point above the $\\dot{y}=0$ line must have $\\dot{y}>0$ and any point below the $\\dot{y}=0$ line must have $\\dot{y}<0$. We represent these properties by a vertical arrow pointing north for any point above the $\\dot{y}=0$ line and a vertical arrow pointing south for any point below the $\\dot{y}=0$ line. \n\n\n\\subsection{Trajectories}\n\nUsing the directional arrows, we can draw trajectories that satisfy the system of differential equations (figure~\\ref{f:phase4}). These are solutions to the system. To select a specific solution among all possible solutions, we will need to specify either an initial condition or a final condition.\n\nAmong all the trajectories, we highlight the saddle path for the system. We know that such a saddle path exist because the eigenvalues of the system have opposite sign. The saddle path is the straight line that goes through the steady state.\\footnote{The saddle path is also sometimes called a \\textit{stable line} of the system. There is also an unstable line, which goes through the steady state but moves away from it.}\n\n\n\\begin{figure}[p]\n\\subcaptionbox{Initial phase diagram \\label{f:news1}}{\\includegraphics[scale=\\sfig,page=5]{\\pdf}}\\hfill\n\\subcaptionbox{New phase diagram \\label{f:news2}}{\\includegraphics[scale=\\sfig,page=6]{\\pdf}}\\vfig\n\\subcaptionbox{Jump upon news \\label{f:news3}}{\\includegraphics[scale=\\sfig,page=7]{\\pdf}}\\hfill\n\\subcaptionbox{Movement after the jump \\label{f:news4}}{\\includegraphics[scale=\\sfig,page=8]{\\pdf}}\n\\caption{Response to a shock in a phase diagram with a state variable}\n\\label{f:news}\\end{figure}\n\n\n\\subsection{Using Phase Diagram with State Variable and Control Variable}\n\nSuppose $x$ is a state variable: information revealed at $t$ does not influence its value at $t$. Suppose $y$ is a control variable: information revealed at $t$ may influence its value at $t$. Suppose that we are in the steady state $\\bp{x^{*},y^{*}}$ of the previous phase diagram. \n\nAssume that there is an exogenous, unanticipated increase in $\\k_{2}$. This increase is revelation of news because it is an unanticipated change to one of the parameters or variables of the system. The response to the news in the phase diagram is represented in figure~\\ref{f:news}.\n\nAs $\\k_{2}$ increases, the $\\dot{y}=0$ locus shifts down, so the new steady state $\\bp{x^{* *},y^{* *}} $ is to the south-east of the previous steady state: $x^{* *}>x^{*}$ and $y^{* *}<y^{*}.$ There is also a new saddle path passing through this new steady state.\n\nWhere do we start after the news is revealed at $t=t_{r}$? That is, what are $x\\bp{t_{r}}$ and $y\\bp{t_{r}}$? Since $x$ is the state variable, it cannot respond to the news, and $x\\bp{t_{r}} =x^{*}$. For the system to converge to the new steady state, it must arrive at the steady-state level $x^{* *}$ of the state variable along the new saddle path. So $y\\bp{t_{r}} $ must be on the new saddle path at $x^{*}$, and over time both $x(t) $ and $y(t) $ move along the saddle path until they converge to the new steady state. To sum up, the system jumps from $\\bp{x^{*},y^{*}}$ to $\\bp{x^{*},y\\bp{t_{r}}} $, and then moves along the saddle path until it reaches $\\bp{x^{* *},y^{* *}}$.\n\n\n\\section{Nonlinear Systems of First-Order Differential Equations}\n\nUnlike the systems of FODEs studied in sections~\\ref{sec:two} and~\\ref{sec:three}, which were linear, systems of FODEs in macroeconomics are often nonlinear. For example the typical growth model is characterized by the following nonlinear system of FODEs:\n\\begin{align}\n\\dot{k}(t) &=f\\bp{k(t)} -c(t)-\\d \\cdot k(t),  \\label{eq:growth1} \\\\\n\\dot{c}(t) &=\\bs{f'\\bp{k(t)} -\\bp{\\d+\\rho}}\\cdot c(t), \\label{eq:growth2}\n\\end{align}\nwhere $\\rho >0$,and $\\d \\in \\bp{0,1}$ are parameters, the capital stock $k(t)$ is a state variable\nwith $k_{0}$ given, and the production function $f$ satisfies the Inada conditions:\n\\begin{align*}\nf\\bp{0}=0,\\; f'>0,\\;f''<0,\\;\\lim_{k\\to +\\infty}f'(k)=0,\\;\\lim_{k\\to 0}f'(k) =+\\infty.\n\\end{align*}\nIt is difficult to solve this system explicitly. But without solving it explicitly, we can characterize its properties by constructing its phase diagram. This is what we do in this section.\n\nWe draw the phase diagram in a plane with the state variable $k$ on the x-axis and the control variable $c$ on the y-axis (figure~\\ref{f:growth}).\n\n\n\\begin{figure}[p]\n\\subcaptionbox{Nullclines \\label{f:growth1}}{\\includegraphics[scale=\\sfig,page=9]{\\pdf}}\\hfill\n\\subcaptionbox{Steady state \\label{f:growth2}}{\\includegraphics[scale=\\sfig,page=10]{\\pdf}}\\vfig\n\\subcaptionbox{Directional arrows \\label{f:growth3}}{\\includegraphics[scale=\\sfig,page=11]{\\pdf}}\\hfill\n\\subcaptionbox{Trajectories\\label{f:growth4}}{\\includegraphics[scale=\\sfig,page=12]{\\pdf}}\n\\caption{Phase diagram for a simple growth model}\n\\label{f:growth}\\end{figure}\n\n\\subsection{Nullclines}\n\nWe first draw the nullclines (figure~\\ref{f:growth1}). We draw the $\\dot{k}=0$ curve defined by\n\\begin{align*}\nc=f\\bp{k} -\\d\\cdot k\n\\end{align*}\nand the $\\dot{c}=0$ curve defined by\n\\begin{align*}\nf^{\\prime}\\bp{k} =\\d +\\rho.\n\\end{align*}\nIn the $(k,c)$ plane, the $\\dot{k}=0$ curve is concave and the $\\dot{c}=0$ curve is a vertical line .\n\n\\subsection{Steady State}\n\nThe intersection of these two loci is the steady state $(k^{*},c^{*})$ of the system (figure~\\ref{f:growth2}).\n\n\\subsection{Directional Arrows}\n\nNext we construct the directional arrows (figure~\\ref{f:growth3}). To do that, we partially differentiate equations~\\eqref{eq:growth1} and~\\eqref{eq:growth2}: \n\\begin{align*}\n\\pd{\\dot{k}}{c} &=-1<0 \\\\\n\\pd{\\dot{c}}{k} &=c\\cdot f''(k)<0.\n\\end{align*}\nTherefore as $c$ increases, $\\dot{k}$ decreases. So, the horizontal arrows point eastward below the $\\dot{k}=0$ curve and westward above it. Similarly as $k$ increases, $\\dot{c}$ decreases. So the vertical arrows point northward to the left of the $\\dot{c}=0$ curve and southward to the right of it.\n\n\\subsection{Trajectories}\n\nThe directional arrows drawn describe a saddle around the steady state (figure~\\ref{f:growth4}). The only way for the economy to converge to the steady state is on the saddle path leading to it. This means that given any initial capital $k_{0}$, initial consumption $c_{0}$ is such that the pair $\\bp{k_{0},c_{0}} $ lies on the saddle path.\n\n\\subsection{Linearization}\n\nThe phase diagram indicates that the system is a saddle around the steady state (figure~\\ref{f:growth}). We can also obtain this result by linearizing the nonlinear system~\\eqref{eq:growth1}--\\eqref{eq:growth2} using a first-order Taylor expansion around the steady state:\n\\begin{align*}\n\\dot{k} &=\\dot{k}^{*} +\\bp{k-k^{*}} \\cdot \\pd{\\dot{k}}{k}+\\bp{c-c^{*}}\\cdot \\pd{\\dot{k}}{c} \\\\\n\\dot{c} &=\\dot{c}^{*} +\\bp{k-k^{*}}\\cdot  \\pd{\\dot{c}}{k}+\\bp{c-c^{*}}\\cdot \\pd{\\dot{c}}{c}.\n\\end{align*}\nGiven that $\\dot{k}^{*} =\\dot{c}^{*} =0,$ we have \n\\begin{equation*}\n\\bs{\\begin{array}{l}\n\\dot{k}\\\\ \n\\dot{c}\n\\end{array}} =\\bm{J}^{*}\\bs{\n\\begin{array}{l}\nk-k^{*} \\\\ \nc-c^{*}\n\\end{array}},\n\\end{equation*}\nwhere $\\bm{J}^{*}$ is the Jacobian matrix evaluated at the steady state:\n\\begin{equation*}\n\\bm{J}^{*}=\\bs{\n\\begin{array}{ll}\n\\pdw{\\dot{k}}{k}{(k^{*},c^{*})}  & \\pdw{\\dot{k}}{c}{(k^{*},c^{*})} \\\\ \n\\pdw{\\dot{c}}{k}{(k^{*},c^{*})} & \\pdw{\\dot{c}}{c}{(k^{*},c^{*})}\n\\end{array}}.\n\\end{equation*}\nThis system is a two-variable nonhomogenous system of FODEs\nfor \\[\\bm{x}=\\bs{\\begin{array}{l}\nk\\\\ \nc\n\\end{array}}.\\]\n\nBut it is a two-variable homogenous system for the transformed variable $\\bm{y}$, where\n\\begin{equation*}\n\\bm{y}=\\bm{x}-\\bm{x}^{*}=\\bs{\n\\begin{array}{l}\nk-k^{*}\\\\ \nc-c^{*}\n\\end{array}}.\n\\end{equation*}\nThe constant matrix $A$ of Section~\\ref{sec:two} is $\\bm{J}^{*}$. The analysis of Section~\\ref{sec:two} shows that the properties of the steady state depend on the eigenvalues of $\\bm{J}^{*}$. The four partial derivatives are\n\\begin{align*}\n\\pdw{\\dot{k}}{k}{(k^{*},c^{*})}&=f'(k^{*}) -\\d =\\rho >0 \\\\\n\\pdw{\\dot{k}}{c}{(k^{*},c^{*})}&=-1<0 \\\\\n\\pdw{\\dot{c}}{k}{(k^{*},c^{*})}&=c\\cdot f''\\bp{k^{*}} <0 \\\\\n\\pdw{\\dot{c}}{c}{(k^{*},c^{*})}&=f'(k^{*}) -\\bp{\\d +\\rho} =0\n\\end{align*}\nIt follows that the Jacobian matrix can be written \n\\begin{equation*}\n\\bm{J}^{*}=\\bs{\n\\begin{array}{ll}\n\\rho  & -1  \\\\ \nc\\cdot f''(k) & 0\n\\end{array}}\n\\end{equation*}\nAs shown by~\\eqref{eq:DETL}, the product of the two eigenvalues is the determinant of $\\bm{J}^{*}$:  \\[\\det(\\bm{J}^{*})=c\\cdot f''(k) <0.\\] Therefore, the two eigenvalues have opposite sign. This property confirms that around the steady state the system is a saddle.\n\n\\end{document}", "meta": {"hexsha": "41bde4d74eb81db3f6b71c8cb710f5a305116066", "size": 27390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/differentialequations.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": "lectures/differentialequations.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": "lectures/differentialequations.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": 52.9787234043, "max_line_length": 683, "alphanum_fraction": 0.6751004016, "num_tokens": 9722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.6430948293061939}}
{"text": "\\section{Singh Combustion Model}\n\nThe calculation of a chemical source term is explained in detail in Anderson. \\cite{gen:anderson2}.\nA brief summary of that exaplanation follows here.\nEach species conservation equation has a source term for each species $k$ given by:\n\n\\begin{displaymath}\n\\dot{W}_k = {\\cal M}_k \\sum_{l=1}^{N_e} \\left( \\nu''_{l,k} - \\nu'_{l,k} \\right)\n\\left[ k_{f,l} \\prod_{m=1}^{N_l} \\left[ \\chi_m \\right]^{\\nu'_{l,m}}\n- k_{b,l} \\prod_{m=1}^{N_l} \\left[ \\chi_m \\right]^{\\nu''_{l,m}} \\right]\n\\end{displaymath}\n\n$N_e$ is the number of elementary reactions involving species $k$.\n$N_l$ is the number of species involved in the elementary reaction.\n${\\cal M}_k$ is the molecular weight of species $k$.\n$\\chi_m$ is the mole fraction of species $m$.\n$\\nu'_{l,k}$ is the stoichiometric coefficient for the reactants of reaction $l$.\n$\\nu''_{l,k}$ is the stoichiometric coefficient for the products of reaction $l$.\n$k_b$ is the backward reaction rate constant and\n$k_f$ is the forward reaction rate constant, given by the\nmodified Arrhenius equation:\n\\begin{displaymath}\nk_f = AT^n \\exp(-E/{\\cal R}T)\n\\end{displaymath}\nwhere the coefficients $A$, $n$ and $E$ are germane to a particular combustion\nmodel. In this study, the Singh hydrogen-air combustion model is used \n\\cite{chem:singh} and the coefficients are given in table \\ref{model} \nbelow.\n\nThe backward and the forward reaction rate constants are related by the\nequilibrium constant, $K_c$\n\\begin{displaymath}\n\\frac{k_f}{k_b} = K_c\n\\end{displaymath}\nThe equilibrium constant, $K_c$ is given by:\n\\begin{displaymath}\nK_c = ({\\cal R} T)^{-\\Delta \\nu}\n       \\exp \\left( \\frac{-\\Delta G^0}{{\\cal R} T} \\right)\n\\end{displaymath}\n\nwhere\n\\begin{displaymath}\n\\Delta \\nu = \\sum_{i=1}^{N_l} (\\nu''_i - \\nu'_i)\n\\end{displaymath}\nThe Gibbs free energy for species $i$\nis defined as $G_i = H_i - T S_i$, where $H_i$ is the\nenthalpy, $T$ is the temperature and $S_i$ is the entropy.\nThe difference in Gibbs free energy $\\Delta G^0$ of products and reactants is\n\\begin{displaymath}\n\\Delta G^0 = \\sum_{i=1}^{N_l} (\\nu''_i - \\nu'_i) \\left( h^0_i - T s^0_i \\right)\n\\end{displaymath}\nwhere $h^0_i$ is the molar enthalpy (including the heat of formation at a\nreference temperature of 298 K)\nof the species $i$, and $s^0_i$ is its the molar entropy,\neach calculated at a reference pressure (one atmosphere).\\\\\n\\\\\n\n\\begin{table}\n\\begin{threeparttable}\n\\caption{Singh Hydrogen-Air Combustion Model with Nitrogen Inert}\n\\begin{tabular}{|cc|c|c|c|} \\hline\n\\multicolumn{2}{|c|}{Reaction} & A & n & E  \\\\ \\hline \\hline\n(1) & H$_{2}$ + O$_{2} \\rightarrow$ OH + OH & 1.70 $\\times$ 10$^{13}$ & 0 & 48 000 \\\\\n(2) & H + O$_{2} \\rightarrow$ OH + O & 1.42 $\\times$ 10$^{14}$ & 0 & 16 400 \\\\\n(3) & O + H$_{2} \\rightarrow$ OH + H & 2.07 $\\times$ 10$^{14}$ & 0 & 13 750 \\\\\n(4) & OH + H$_{2} \\rightarrow$ H$_{2}$O + H & 3.16 $\\times$ 10$^{7}$ & 1.80 & 3 030 \\\\\n(5) & OH + OH $\\rightarrow$ H$_{2}$O + O & 5.50 $\\times$ 10$^{13}$ & 0 & 7 000 \\\\\n(6) & H + OH + M $\\rightarrow$ H$_{2}$O + M & 2.21 $\\times$ 10$^{22}$ & -2.00 & 0 \\\\\n(7) & H + H + M $\\rightarrow$ H$_{2}$ + M & 6.53 $\\times$ 10$^{17}$ & -1.00 & 0 \\\\\n\\hline\n\\end{tabular}\n\\label{model}\n\\end{threeparttable}\n\\end{table}\n\nThe units for $A$ are in $[\\frac{cm^{3b}}{(mole-s)^b}]$ where $b=1$ for two body reactions and \n$b=2$ for three body reactions. $E$ is in $[\\frac{cal}{mole}]$.\\\\\n\\\\\n\nThe symbol $M$ denotes a third-body collision partner, a species acting as a catalyst only.\nThe concentration of $M$ is simply determined from the equation :\\\\\n\n\\begin{displaymath}\nX_M = \\sum_{k=1}^{n_s} \\eta_k X_k\n\\end{displaymath}\n\nwhere $\\eta_k$ is the third-body efficiency. $\\eta_k$ is unity\nfor all species and reactions in this case. \n\n", "meta": {"hexsha": "f08aacadc0b1c4f98740adc7f4c8a85e7090bc38", "size": 3721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "model/chem/old/_singh/doc/chem.tex", "max_stars_repo_name": "zhanghuanqian/CFDWARP", "max_stars_repo_head_hexsha": "9340a8526bb263d910f79d79e84dcac7aec211b6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2018-09-13T13:58:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T21:44:13.000Z", "max_issues_repo_path": "model/chem/old/_singh/doc/chem.tex", "max_issues_repo_name": "zhanghuanqian/CFDWARP", "max_issues_repo_head_hexsha": "9340a8526bb263d910f79d79e84dcac7aec211b6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-11-10T11:28:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-23T09:21:28.000Z", "max_forks_repo_path": "model/chem/old/_singh/doc/chem.tex", "max_forks_repo_name": "zhanghuanqian/CFDWARP", "max_forks_repo_head_hexsha": "9340a8526bb263d910f79d79e84dcac7aec211b6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2018-07-26T08:17:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T08:41:55.000Z", "avg_line_length": 41.3444444444, "max_line_length": 99, "alphanum_fraction": 0.6678312282, "num_tokens": 1320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6430833022622164}}
{"text": "\\chapter{Background}\n\\label{chapter: Background}\n\nIn this chapter, we introduce the fundamental concepts of mathematical programming as well as simplified forms of the models on which our modelling efforts will be built upon throughout this dissertation. This material is organised in a way that hopefully can provide the reader with a high-level understanding of the necessary mathematical concepts that will be utilised throughout this dissertation. A literature review for each topic covered has been incorporated accordingly to each section of the chapter. To gain a deeper understanding of those principles, and a more accurate grasp of the state of the art our reader is advised to thoroughly consult the literature sources referenced throughout this report.\n\n\\vspace{\\baselineskip}\n\\noindent\nSections \\ref{section: 2.1}-\\ref{section: Duality} give a generic definition of Mathematical Programming, and its branches. They also mention the principal algorithms that are going to be utilised for the solution of the mathematical problems dealt with in this dissertation. Section \\ref{section: vrp} studies the class of problems most relevant to the context of our problem. Sections \\ref{section: Pareto}-\\ref{section: Lexicographic} describe the theoretical concepts used in the latter stages of the dissertation for the experiments with the higher degree of difficulty but also the most value-added, with respect to new insights gained.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Mathematical Programming}\n\\label{section: 2.1}\nA mathematical program involves the maximizing or minimizing of an objective function by providing input values from within a defined domain, computing the value of the function that dictates the quality of each solution and subsequently choosing the best available outputs.\\par\n\\vspace{\\baselineskip}\n\\noindent\nGeneral mathematical programming models can be stated as \\cite{DUMMY:1}:\n\n\n\n\\begin{equation}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & f(x) \\\\\n& \\text{subject to}\n& & g_i(x) = 0 \\;\\;\\; i = 1,2, \\ldots, m\\\\\n& & & h_j(x) \\leq 0 \\;\\;\\; j = 1,2, \\ldots, r\\\\\n\\end{aligned}\n\\end{equation}\n\\[\\text{where} \\; x \\in S \\subset \\mathbb{R}^{n} \\; , \\; f:\\mathbb{R}^{n}\\rightarrow \\mathbb{R} \\; , \\; g:\\mathbb{R}^{n}\\rightarrow \\mathbb{R}^{m} \\; \\text{and} \\; h:\\mathbb{R}^{n}\\rightarrow \\mathbb{R}^{r} \\]\n\n\\vspace{\\baselineskip}\n\\noindent\nThe \\textit{decision variables} are represented by an \\textit{n}-dimensional vector  \\( \\pmb{x}=x_{1},x_{2}, \\ldots ,x_{n} \\) and the \\textit{objective function f} is a function of the decision variables that we want to minimise. The \\textit{feasible set}  \\( S\\) determined by the equations \\textit{g(x)}, inequalities \\textit{$h(x)$}, and set restrictions and it is a subset of the \\textit{n}-dimensional space containing all the admissible decisions. All the points $x \\in S$ are feasible solutions, but sought after is an optimal solution, a vector $\\pmb{x^\\ast}$ that satisfies the constraints of the feasible set, and achieves the best possible outcome i.e.: \\par\n\n\\begin{equation*}\n\\begin{aligned}\nf(x)\\geq f(x^\\ast) > -\\infty \\;\\; \\forall \\; x\\in S\n\\end{aligned}\n\\end{equation*}\n\n\\vspace{\\baselineskip}\n\\noindent\nThe objective of mathematical programming is to utilise optimisation theory, and algorithms to obtain those optimal solution(s).\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Linear Programming}\n\\label{section: LP}\nA\\textit{ Linear Program (LP) }is a type of mathematical program where the\\textbf{ }objective function and the constraints are \\textbf{linear} over the feasible set of decision variables. The conventional form for representing LPs is the \\textit{standard form} below \\cite{DUMMY:1}:\\par\n\n\\vspace{\\baselineskip}\n\n\\begin{equation}\n\\begin{aligned}\n\\label{equation: LP}\n& \\underset{x}{\\text{minimise}}\n& & c_{1}x_{1}+ c_{2}x_{2}+ \\ldots + c_{n}x_{n} \\\\\n& \\text{subject to}\n& & a_{11}x_{1}+ a_{12}x_{2}+ \\ldots + a_{1n}x_{n}=~ b_{1}\\\\\n& & & a_{21}x_{1}+ a_{22}x_{2}+ \\ldots + a_{2n}x_{n}=~ b_{2}\\\\\n& & & \\vdots\\\\\n& & & a_{m1}x_{1}+ a_{m2}x_{2}+ \\ldots + a_{mn}x_{n}=~ b_{m}\\\\\n& \\text{and}\n& & x_{1},x_{2}, \\ldots ,x_{n} \\geq 0\\\\\n\\end{aligned}\n\\end{equation}\n\\[\\text{where}~b_{i},c_{i}~\\text{and}~a_{ij}~  \\text{are fixed real constants and we require that} \\; b_{i} \\geq 0\\]\n\n\\vspace{\\baselineskip}\n\\noindent\nIn principle, formulating the program as a maximisation problem is equivalent to equation (\\ref{equation: LP}) since through the simple transformation of the objective $maxf(x)=-min(-f(x))$ we can convert our problem. However, by convention the minimisation formulation in (\\ref{equation: LP}) has prevailed, and one can transform any maximisation problem into a minimisation one without any loss of generality. The purpose of establishing a \\textit{standard form} for all LPs is to create a default version that represents the standard for all LP formulations for which we can develop efficient solution algorithms. All differently formulated LPs can then be transformed to this \\textit{standard form} through a series of simple operations such as the addition of slack, surplus variables so that we can utilise the effectiveness of the \\textit{standard form's} universal algorithms. The formulation (\\ref{equation: LP}) above can also be reduced in vector notation to this compact version:\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\label{equation: LP compact form}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x \\\\\n& \\text{subject to}\n& & Ax=b\\\\\n& & & x \\geq 0 \\\\\n\\end{aligned}\n\\end{equation}\n\\[\\text{where} \\; b \\geq 0 \\; \\text{and} \\; A \\in \\mathbb{R}^{m \\times n}, \\; b \\in \\mathbb{R}^{m \\times 1}, \\; c \\in \\mathbb{R}^{1 \\times n}\\]\n\n\\vspace{\\baselineskip}\n\\noindent\nA program of any scientific interest is \\textit{well-defined,} and its feasible set is concretely \\textbf{bounded} and \\textbf{non-empty}. For LPs the feasible set circumscribed by the set of linear constraints, translates to a \\textbf{convex polyhedron} containing an infinite number of solutions. According to the \\textit{Fundamental Theorem of LP}, at least one of the vertices of the polyhedron feasible set, contains the optimum solution to the LP\\textbf{.}\\par\n\\vspace{\\baselineskip}\n\\noindent\nConsequently, an initial idea of an algorithm that obtains the optimal solution from inside the feasible set is the procedure of examining which of the finite number of vertices of the polyhedron \\textit{S} produces the best objective value. However, computing the optimum through a \\textit{finite search} over all the vertices is usually computationally prohibitive especially since the number of vertices increases exponentially with the number of constrains and variables.\\par\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Simplex Algorithm}\nTo combat this the \\textit{Simplex Algorithm}, the most frequently used method, starts from an initial corner point and then inspects a fraction of all possible vertices \\textit{pivoting} from the initial vertex to vertices with a guaranteed ever-improving objective value, until the optimum is found \\cite{DUMMY:3}. Despite its effectiveness in obtaining a solution the simplex is not guaranteed to solve an LP in \\textit{polynomial} time, especially considering that in some cases it is equally as hard to find an initial corner point as it is to find the optimum solution \\cite{DUMMY:2}. \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Interior point methods}\n\nAnother class of algorithms used to deal with LPs is that of \\textit{interior point methods} such as \\textit{Karmarkar’s Algorithm.} In contrast to the simplex, it explores the interior of the feasible space rather focusing on its corner points and identifies an optimum solution in \\textit{polynomial }time \\cite{DUMMY:4}.\\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Integer Linear Programming}\n\nA \\textit{Pure-Integer Linear Program (PILP)} is a branch of linear mathematical programming in which decision variables are required to be non-negative integers.\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x \\\\\n& \\text{subject to}\n& & Ax=b\\\\\n& & & x \\geq 0, \\;\\;\\; &x \\in S \\subset \\mathbb{Z}^{n} \\subset \\mathbb{R}^{n}\n\\end{aligned}\n\\end{equation}\n\\[\\text{where} \\; b \\geq 0 \\; \\text{and} \\; A \\in \\mathbb{R}^{m \\times n}, \\; b \\in \\mathbb{R}^{m \\times 1}, \\; c \\in \\mathbb{R}^{1 \\times n}\\]\n\n\\vspace{\\baselineskip}\n\\noindent\nA visualisation of the feasible set of a program that includes the integrality constraint can be seen in Figure \\ref{fig:Integer Programming figure}. Assuming, that we consider an integer problem for which  $\\pmb{x} \\in \\mathbb{Z}^{2}$, Figure \\ref{fig:Integer Programming figure}(a) illustrates the spectrum of possible decisions that we can make for this problem. Those decision are the subset of integer pairs that belong in $S$.\n\n\\vspace{\\baselineskip}\n\\noindent\nIn a \\textit{Mixed Integer Linear Program (MILP)} only a subset of the decision variables have an integrality constraint. Taking as an example the two-dimensional MILP of Figure \\ref{fig:Integer Programming figure}(b) in which one decision variable is continuous ($x_1 \\in \\mathbb{R}$) whereas the other can only take discrete values ($x_2 \\in \\mathbb{Z}$).\\par\n\n\\vspace{\\baselineskip}\n\\noindent\nMany real-life problems can be formulated as integer linear programs. The study of this class of programs and its algorithms is particularly important for the purposes of this dissertation since we will be formulating our problem as a MILP. In particular, the problem that we will be studying from Chapter \\ref{chapter: Problem Definition} onward, is a Binary Mixed-Integer Program where binary discrete variables are used to model whether or not some event takes place.\\par\n\n \\vspace{\\baselineskip}\n\\noindent\nIn reality, even though it seems slightly counter-intuitive at first, integer programs are considerably harder to solve. A naive assumption would be to claim that in an ILP, one only has a finite number of possible decisions (as seen in Figure \\ref{fig:Integer Programming figure}(a)) so in principle one could essentially try them all. However, if the problem's scale is increased we will transition to a combinatorial problem where the number of solutions that one has to search over with this brute force approach becomes very large very quickly. We mentioned before that in the environment of LPs when we add new constraints the number of solutions increases exponentially. In an ILP specifically, the addition of \\textit{n} binary variables increases the solution space by 2\\textsuperscript{n} \\cite{susteainabletranspaort}. As a consequence, a \\textit{polynomial }time algorithm for ILPs has not yet been proven to exist \\cite{DUMMY:2}, and such MILPs are considered \\textit{NP-hard} \\cite{Wedelin1995}.\n\n\\vspace{\\baselineskip}\n\\noindent\nTo solve mixed-integer linear problems, we can either reuse or extend algorithms designed for LPs or construct new ones specifically for ILP problems. The algorithms studied below are of the former category and they largely exploit the efficiency of the simplex algorithm\\footnote{Designed for standard form LPs as was previously seen in Section \\ref{section: LP}.} by disentangling an integer LP into a corresponding linear program through relaxing\\footnote{The concept of obtaining the relaxation of a program is further explained in Appendix \\ref{section: Appednix Relaxation} for interested readers.} the integrality constraints. \n\n\\vspace{\\baselineskip}\n\\noindent\nThis approach is based on the idea that the ILP’s feasible set is a subset of the relaxed LP’s domain\\footnote{$S_{ILP}$ $\\subseteq$ $S_{R}$, where $S_{R}$ is the relaxed LP's feasible set.}, hence the integer optimum solution is guaranteed to be contained within the linear spectrum of solutions. Subsequently, through solving numerous iterations of the \\textit{standard form} LPs, utilising simplex, their feasible sets are gradually modified to converge towards an optimum solution that is also integer hence, obtaining a solution that is also the optimal for the original ILP. The reason for multiple such algorithms to exist is revolved around the way they modify the relaxed LPs feasible set to converge towards the integer solution. \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DOUBLE Figure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%Two images in one, illustrating atomic block\n\\begin{figure}%\n    \\centering\n    \\subfloat[Pure-Integer Linear Programming problem (PILP), where $\\pmb{x} \\in \\mathbb{Z}^{2}$.]{\n    \\begin{tikzpicture}[thick, scale=0.9]\n    \\begin{scope}[thick,font=\\scriptsize]\n    % Axes:\n    % Are simply drawn using line with the `->` option to make them arrows:\n    % The main labels of the axes can be places using `node`s:\n    \\draw [->] (0,0) -- (7,0) node [above left]  {$x_1$};\n    \\draw [->] (0,0) -- (0,7) node [below right] {$x_2$};\n    \n    %dotted lines\n    %edge points\n    %\\draw [dashed] (4,0) -- (4,1);\n    %\\draw [dashed] (0,3) -- (2,3);\n    \n\n    % Axes labels:\n    % Are drawn using small lines and labeled with `node`s. The placement can be set using options\n    \\iffalse% Single\n    % If you only want a single label per axis side:\n    \\draw (1,-3pt) -- (1,3pt)   node [above] {$1$};\n    \\draw (-3pt,1) -- (3pt,1)   node [right] {$1$};\n    \n    \\else% Multiple\n    % If you want labels at every unit step:\n    \\foreach \\n in {1,2,...,5,6}{%\n        \\draw (\\n,-3pt) -- (\\n,3pt)   node [label=below:$\\n$] {};\n        \\draw (-3pt,\\n) -- (3pt,\\n)   node [label=left:$\\n$] {};\n    }\n    \\fi\n    \\end{scope}\n    % The circle is drawn with `(x,y) circle (radius)`\n    % You can draw the outer border and fill the inner area differently.\n    % Here I use gray, semitransparent filling to not cover the axes below the circle\n   % \\path [draw=skiastro,fill=skiastro,semitransparent] (+3,+3) circle (2);1\n    \n     \\node[label=right:] (F) at (4.8,1.4){};\n     \\node[label=below:] (A) at (1.2,1.6){};\n     \\node[label=right:] (X) at (5.8,5.6){};\n     \\node[label=right:] (C) at (5.8,3.3){};\n     \\draw[thick,fill=gray,semitransparent] (1.5,4.4)  %fills up the figure\n     to[bend right=0] (X.center) \n     to[bend left=0] (C.center)\n     to[bend left=0] (F.center) \n     to[bend left=0] (A.center) to[bend left=0]  cycle;\n    \n    % Place the labels of the circle:\n    % edge points\n %   \\node [below right,darkgray] at (+4,1) {$\\pmb{minf_1}$};\n%    \\node [above left,darkgray] at (2,3) {$\\pmb{minf_2}$};\n    \n\n    \n    %Red points\n    %draw edge points\n%     \\node at (2,3) {\\textcolor{red}{\\textbullet}};\n %    \\node at (4,1) {\\textcolor{red}{\\textbullet}};    \n    \n    \\node [below,black] at (+5.4,5.5) {$S$};\n    \n    \\node at (1,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (1,2) {\\textcolor{gray}{\\textbullet}};\n    \\node at (1,3) {\\textcolor{gray}{\\textbullet}};\n    \\node at (1,4) {\\textcolor{gray}{\\textbullet}};\n    \\node at (1,5) {\\textcolor{gray}{\\textbullet}};\n    \\node at (1,6) {\\textcolor{gray}{\\textbullet}};\n    \\node at (2,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (2,2) {\\textcolor{red}{\\textbullet}};\n    \\node at (2,3) {\\textcolor{red}{\\textbullet}};\n    \\node at (2,4) {\\textcolor{red}{\\textbullet}};\n    \\node at (2,5) {\\textcolor{gray}{\\textbullet}};\n    \\node at (2,6) {\\textcolor{gray}{\\textbullet}};\n    \\node at (3,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (3,2) {\\textcolor{red}{\\textbullet}};\n    \\node at (3,3) {\\textcolor{red}{\\textbullet}};\n    \\node at (3,4) {\\textcolor{red}{\\textbullet}};\n    \\node at (3,5) {\\textcolor{gray}{\\textbullet}};\n    \\node at (3,6) {\\textcolor{gray}{\\textbullet}};\n    \\node at (4,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (4,2) {\\textcolor{red}{\\textbullet}};\n    \\node at (4,3) {\\textcolor{red}{\\textbullet}};\n    \\node at (4,4) {\\textcolor{red}{\\textbullet}};\n    \\node at (4,5) {\\textcolor{red}{\\textbullet}};\n    \\node at (4,6) {\\textcolor{gray}{\\textbullet}};\n    \\node at (5,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (5,2) {\\textcolor{red}{\\textbullet}};\n    \\node at (5,3) {\\textcolor{red}{\\textbullet}};\n    \\node at (5,4) {\\textcolor{red}{\\textbullet}};\n    \\node at (5,5) {\\textcolor{red}{\\textbullet}};\n    \\node at (5,6) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,1) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,2) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,3) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,4) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,5) {\\textcolor{gray}{\\textbullet}};\n    \\node at (6,6) {\\textcolor{gray}{\\textbullet}};\n\n    \\end{tikzpicture}}%picture #1\n    \\qquad\n    %picture #2\n    \\subfloat[Mixed-Integer Linear Programming problem (MILP), where $x_1 \\in \\mathbb{R}$ and $x_2 \\in \\mathbb{Z}$.]{\n            \\begin{tikzpicture}[thick, scale=0.9]\n    \\begin{scope}[thick,font=\\scriptsize]\n    % Axes:\n    % Are simply drawn using line with the `->` option to make them arrows:\n    % The main labels of the axes can be places using `node`s:\n    \\draw [->] (0,0) -- (7,0) node [above left]  {$x_1$};\n    \\draw [->] (0,0) -- (0,7) node [below right] {$x_2$};\n    \n    %dotted lines\n    %edge points\n    %\\draw [dashed] (4,0) -- (4,1);\n    %\\draw [dashed] (0,3) -- (2,3);\n    \n\n    % Axes labels:\n    % Are drawn using small lines and labeled with `node`s. The placement can be set using options\n    \\iffalse% Single\n    % If you only want a single label per axis side:\n    \\draw (1,-3pt) -- (1,3pt)   node [above] {$1$};\n    \\draw (-3pt,1) -- (3pt,1)   node [right] {$1$};\n    \n    \\else% Multiple\n    % If you want labels at every unit step:\n    \\foreach \\n in {1,2,...,5,6}{%\n        \\draw (\\n,-3pt) -- (\\n,3pt)   node [label=below:$\\n$] {};\n        \\draw (-3pt,\\n) -- (3pt,\\n)   node [label=left:$\\n$] {};\n    }\n    \\fi\n    \\end{scope}\n    % The circle is drawn with `(x,y) circle (radius)`\n    % You can draw the outer border and fill the inner area differently.\n    % Here I use gray, semitransparent filling to not cover the axes below the circle\n   % \\path [draw=skiastro,fill=skiastro,semitransparent] (+3,+3) circle (2);1\n    \n     \\node[label=right:] (F) at (4.8,1.4){};\n     \\node[label=below:] (A) at (1.2,1.6){};\n     \\node[label=right:] (X) at (5.8,5.6){};\n     \\node[label=right:] (C) at (5.8,3.3){};\n     \\draw[thick,fill=gray,semitransparent] (1.5,4.4)  %fills up the figure\n     to[bend right=0] (X.center) \n     to[bend left=0] (C.center)\n     to[bend left=0] (F.center) \n     to[bend left=0] (A.center) to[bend left=0]  cycle;\n    \n    % Place the labels of the circle:\n    % edge points\n %   \\node [below right,darkgray] at (+4,1) {$\\pmb{minf_1}$};\n%    \\node [above left,darkgray] at (2,3) {$\\pmb{minf_2}$};\n    \n\n    \n    %Red points\n    %draw edge points\n%     \\node at (2,3) {\\textcolor{red}{\\textbullet}};\n %    \\node at (4,1) {\\textcolor{red}{\\textbullet}};    \n    \n    \\node [below,black] at (+5.4,5.5) {$S$};\n    \n    \\draw [gray, dashed] (0,1) -- (6,1);\n    \\draw [gray, dashed] (0,2) -- (6,2);\n    \\draw [red, thick] (1.25,2) -- (5.1,2);\n    \\node at (1.25,2) {\\textcolor{red}{\\textbullet}};\n    \\node at (5.1,2) {\\textcolor{red}{\\textbullet}};\n    \\draw [gray, dashed] (0,3) -- (6,3);\n    \\draw [red, thick] (1.4,3) -- (5.6,3);\n    \\node at (1.35,3) {\\textcolor{red}{\\textbullet}};\n    \\node at (5.65,3) {\\textcolor{red}{\\textbullet}};\n    \\draw [gray, dashed] (0,4) -- (6,4);\n    \\draw [red, thick] (1.45,4) -- (5.8,4);\n    \\node at (1.45,4) {\\textcolor{red}{\\textbullet}};\n    \\node at (5.8,4) {\\textcolor{red}{\\textbullet}};\n    \\draw [gray, dashed] (0,5) -- (6,5);\n    \\draw [red, thick] (3.8,5) -- (5.8,5);\n    \\node at (3.8,5) {\\textcolor{red}{\\textbullet}};\n    \\node at (5.8,5) {\\textcolor{red}{\\textbullet}};\n    \\draw [gray, dashed] (0,6) -- (6,6);\n\n    \\end{tikzpicture}}\n    %end of picture #2\n    \\caption{Illustrations of the Feasible Sets ($S$) of an ILP and a MILP respectively.}%\n    \\label{fig:Integer Programming figure}%\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Branch and Bound}\nThe \\textit{Branch and Bound (BB)} follows this philosophy of modifying the feasible set until an integer solution is obtained. It begins by obtaining the optimum solution of the relaxed LP. In the case that this initial solution happens to be integer it will immediately terminate since that will mean that the optimum for the original ILP has also been found. If it is not however, the algorithm modifies the LP’s feasible set until its solution satisfies the integrality constraints. \\par\n\n\\vspace{\\baselineskip}\n\\noindent\nThose modifications take place at every iteration, and for the purposes of the BB we refer to them as \\textit{branching}. To carry out branching the algorithm divides the solution space into two LP subproblems, by eliminating a part of the LP relaxation’s feasible set that did not contain any feasible integer solutions. For the ILP there is no loss of generality since the union of the subproblems’ feasible sets contains the exact same feasible integer solutions. The two emergent subproblems are then solved separately as regular LPs. Due to the absence of any loss of generality the optimum ILP solution is guaranteed to be in just one of the two new emergent solution spaces of the subproblems. If the solution to either of the two subproblems is worse than any previously known solution, then the corresponding subproblem and its feasible space are disregarded as non-promising. This is known as the \\textit{fathoming} step. In essence through such iterations of the algorithm a lower possible bound for the objective value is eventually obtained. \\par\n\n\\vspace{\\baselineskip}\n\\noindent\nBy enforcing these two steps iteratively, a binary tree is constructed. Nodes with a non-integer solution have two branching subproblems et cetera. The algorithm is terminated when all nodes will either have an integer solution or a non-integer solution that is worse than the best integer solution of some other node. The node with the most optimum integer solution is the solution to the original ILP \\cite{DUMMY:2}.   \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Cutting Plane}\nThe \\textit{Cutting Plane (CP)} method is also concerned with the transformation of an ILP into a LP that has naturally an integer solution. The process behind this is to gradually cut out part of the relaxed LP's admissible set while leaving the feasible region of the ILP completely unchanged. Hence, eventually upon the implementation of a sufficient number of such \\textit{cuts} we will obtain an LP with an integer solution. However, the process of generating the cuts is not a trivial task, and that is the heart of the algorithm. \n\n\\vspace{\\baselineskip}\n\\noindent\nThe algorithm starts by relaxing the integrality constraints to obtain the LP relaxation of the original ILP. Starting from the optimum solution of the LP relaxation, if it is integer, then the \\textit{cutting-plane} algorithm terminates, and this optimum solution is also optimum for the ILP. If it is not, we \\textit{tighten} the feasible set of the LP and repeat this process. \\par\n\\vspace{\\baselineskip}\n\\noindent\nThe \\textit{tightening }is done by generating a \\textit{cut,} that is a new constraint that restricts unwanted non-integer solutions. This new linear constraint is added to the relaxed LP’s solution space hence modifying $S_{R}$ into a new set $S_{CH}$. This process of modifying $S_{R}$ is repeated until the set converges to one of the ILP’s solution space vertices, at which point the optimum integer solution will have been obtained. Through iteratively performing these steps we create the \\textit{convex hull} $S_{CH}$ of the ILP's feasible set $S$.\\par\n\n\\vspace{\\baselineskip}\n\\noindent\nConsequently, starting from the ILP below:\n\n\\begin{equation*}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x, \\;\\;\\;\\; x \\in S \\\\\n\\end{aligned}\n\\end{equation*}\n\n\\vspace{\\baselineskip}\n\\noindent\nThrough generating multiple cuts at each iteration we can instead solve:\n\n\\begin{equation*}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x, \\;\\;\\;\\; x \\in S_{CH} \\\\\n\\end{aligned}\n\\end{equation*}\n\\[\\text{since} \\; S \\subseteq S_{CH} \\subseteq S_{R} \\]\n\n\n\\vspace{\\baselineskip}\n\\noindent\nThe ideal operating scenario for this method would be to generate a relatively small account of highly effective cuts. However, the effectiveness of a cut is a topic with a hard to obtain answer. A universally good cut, would be a cut where the vertex of $S_{CH}$ on which the cut is performed is the furthest from the perimeter of $S_{R}$ since that would automatically mean that the largest possible amount of unwanted feasible space has been cut off. In order generate such good cuts, the simplex algorithm can be utilised. Namely, at each iteration after locating a vertex, we can use the simplex algorithm at that point to determine the best point to pivot to in order to perform the following cut \\cite{ieeeeee}.\n\n\\vspace{\\baselineskip}\n\\noindent\nOverall, a pure cutting plane approach is considered computationally intensive because more often than not, multiple cuts are required. As a direct consequence multiple constraints will be added to the LP relaxation rendering it less computationally tractable. Especially, if we consider that the number of cuts required is not necessarily dependent on the problem’s scale as explained in \\cite{DUMMY:3}. In general, there also exist many kinds of cuts such as \\textit{Mixed-Integer rounding, }or \\textit{Knapsack cover }cuts derived from the logic governing the class packing problems. This adds another variable to the algorithm regarding the choice of cuts. The most prominent are \\textit{Gomory mixed-integer }cuts \\cite{gomory1958}. Although at the time of their development they were unable to translate their theoretical effectiveness into practice they have recently been revisited and are now considered a go-to method. That is due to the following two reasons. Firstly, due to the emergence of more powerful and robust solvers \\cite{cornelio}. Secondly, they have proven to outperform other methods when utilised with a hybrid implementation of the cutting algorithm instead of the pure cutting plane approach. Namely, when utilised a method that combines the \\textit{branch-and-bound} with the \\textit{cutting-plane} algorithm (i.e. a \\textit{branch-and-cut})\\cite{BALAS19961} they manage to generate substantially better bounds leading to a decreased computation time compared to the pure versions of those two algorithms \\cite{DUMMY:2}.\\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Duality}\n\\label{section: Duality}\n\nAccording to the principle of \\textit{duality, }in linear programming every LP can be associated with a corresponding \\textit{dual} linear program. The \\textit{dual} of a problem is a LP derived from combinations of the constraints of an original LP model, referred to as the \\textit{primal.} The solution of the \\textit{dual} signifies the best possible bound of the original problem. In matrix form, we can express the \\textit{primal} problem as:\\par\n\n\\vspace{\\baselineskip}\n\\begin{equation*}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x \\\\\n& \\text{subject to}\n& & Ax \\leq b\\\\\n& & & x \\geq 0 \\\\\\\n\\end{aligned}\n\\end{equation*}\n\n\\noindent\nwith the corresponding \\textbf{symmetric} dual problem,\\par\n\n\\vspace{\\baselineskip}\n\\begin{equation*}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & b^{T}y \\\\\n& \\text{subject to}\n& & A^{T}y \\geq c\\\\\n& & & x \\geq 0 \\\\\\\n\\end{aligned}\n\\end{equation*}\n\n\\noindent\nThe two problems are completely intertwined with each other. The objective of the primal program is transformed to its mirror-image counterpart in the dual, in a way that if the original is a minimisation problem its dual attempts to maximise the objective function and vice versa. Finding the dual of the dual problem will lead us back to the primal problem. \\par\n\\vspace{\\baselineskip}\n\\noindent\nIn Linear Programming specifically, the concept of \\textit{strong duality }states that the optimum solution to the dual problem is also the optimum for the primal and vice versa. We can leverage this concept when solving LPs where the number of variables is significantly smaller than that of the constraints, since solving the dual will be considerably more computationally efficient and its solution will also be optimum for the original problem. \\par\n\n\\vspace{\\baselineskip}\n\\noindent\nA practical use of the duality concept is that it drives the \\textit{post-optimal analysis, }to determine the degree of sensitivity of the optimum solution to any changes in the input parameters. \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection*{Sensitivity Analysis}\n\nSensitivity Analysis leverages the relationship between primal-dual problems to calculate the changes in the optimum solution as a result of changes in the input parameters, in an efficient manner. The utility of performing a sensitivity analysis is to gain insights of the relationships between the various components of the problem. For instance, in chapter \\ref{chapter: Problem Definition} we will conduct a sensitivity analysis to find out the various the trade-off between the objective function and a variable of the problem. By probing the objective function for various values of that variable we are able to determine the thresholds at which the objective value changes as well as the degree by which it changes. Finally, while performing a sensitivity analysis it is often useful to determine the degree to which a component can remain robust with respect to some changes in another component. For instance, we could establish limits within which changing a certain variable will not cause a change in the optimal solution. Consequently, having done that we will have determined the sensitivity of the optimal solution to changes with respect to that variable.\\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Lagrangian Relaxation}\n\\addcontentsline{toc}{paragraph}{Lagrangian Relaxation}\nThe \\textit{Lagrangian dual} problem is a bounding technique for solving ILPs that does not disregard the integrality constraints as in previously stated techniques, but instead relaxes some of the main constraints. By forming a combination of the constraints through multiplying them with non-negative Lagrange multipliers, the dual of the original ILP is constructed. The relaxed problem is significantly more computationally tractable, and through solving the dual we can establish a best possible bound for the original ILP.\\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Multi-Objective Optimisation and Pareto Optimality}\n\\label{section: Pareto}\nTaking a brief diversion from the context of Linear Programming, we look at \\textit{Multi-Objective Optimisation} problems where the objective function is comprised of a multitude of objectives. For such problems the \\textit{Pareto Optimality} principle proves particularly handy when looking for a \\textbf{Pareto optimal} solution. In simple terms To define a Pareto optimal solution we first need to address the concept of a \\textbf{dominated solution}: \n\n\\begin{equation}\n\\begin{aligned}\n\\label{equation: pareto}\n& \\underset{x}{\\text{minimise}}\n& & f(x) \\\\\n& \\text{subject to}\n& & h_i(x) = 0 \\;\\;\\; i = 1,2, \\ldots, m\\\\\n\\end{aligned}\n\\end{equation}\n\\[where \\; x \\in \\mathbb{Z}^{n} \\;, \\; f:\\mathbb{Z}^{n}\\rightarrow \\mathbb{Z}^{c}, \\; h:\\mathbb{Z}^{n}\\rightarrow \\mathbb{Z}^{m} \\]\n\n\\vspace{\\baselineskip}\n\\noindent\nGiven the constrained multi-objective minimisation problem in (\\ref{equation: pareto}), that has an objective function $f(x)$ which is a combination of a set of \\textit{o} objective functions $f_{1}(x),f_{2}(x),\\ldots,f_{o}(x)$ that require simultaneous minimisation, and a feasible space defined by a set of constraints $m$, a feasible solution $d$ is \\textbf{dominated} by another feasible solution $s$ if the following two conditions stand:\n\n\n\\begin{equation*}\n\\begin{aligned}\n&(1) \\; & &f_{j}(s) \\leq f_{j}(d) \\; \\forall \\; j \\in [1,\\dots,o] \\\\\n&(2) \\; & &\\exists \\; k \\in [1,\\dots,m] \\; | \\; f_{k}(s) < f_{k}(d) \\\\ \n\\end{aligned}\n\\end{equation*}\n\n\n\\vspace{\\baselineskip}\n\\noindent\nIn simpler terms, these two conditions can be reduced down to: (1) solution $s$ is \\textit{as good performing as} $d$ at every objective $o$, and simultaneously, (2) solution $s$ \\textbf{strictly} better performing than $d$ at at least one objective \\cite{DUMMY:6}. Using the definition of a \\textit{dominated} solution, we then define the Pareto optimal solutions as the set of \\textbf{undominated} solutions from within the feasible set.\n\n\\vspace{\\baselineskip}\n\\noindent\nIn the context of a practical optimisation problem, finding a feasible point that is concurrently Pareto optimal means that it is only impossible to improve one objective at the expense of another. Hence, it captures the concept of a \\textbf{trade-off} between the various objective in the objective function. The reason behind the efficacy of this concept is that more often than not, when presented with a multi-objective optimisation problem it is usually precarious to apply the philosophy of linear programming and trying to optimise multiple objectives in a brute-force way, as it is likely that the optimiser for one of the objective is not going to coincide with that of a different objective. That is because more often than not, especially in problems with numerous objective functions, some objective functions end up being in conflict with each other \\cite{grinding}. Hence, we need to address a multi-objective optimisation problem with a slightly different notion of optimality. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FIGURE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{figure}\n    \\centering\n    \\begin{tikzpicture}\n    \\begin{scope}[thick,font=\\scriptsize]\n    % Axes:\n    % Are simply drawn using line with the `->` option to make them arrows:\n    % The main labels of the axes can be places using `node`s:\n    \\draw [->] (0,0) -- (7,0) node [above left]  {$f_1$};\n    \\draw [->] (0,0) -- (0,6) node [below right] {$f_2$};\n    \n    %dotted lines\n    %edge points\n    %\\draw [dashed] (4,0) -- (4,1);\n    %\\draw [dashed] (0,3) -- (2,3);\n    \n    %A\n    \\draw [dotted] (2.125,0) -- (2.125,2.328);\n    \\draw [dotted] (0,2.328) -- (2.125,2.328);\n    \n    %B\n    \\draw [dotted] (2.9,0) -- (2.9,1.325);\n    \\draw [dotted] (0,1.325) -- (2.9,1.325);\n\n    % Axes labels:\n    % Are drawn using small lines and labeled with `node`s. The placement can be set using options\n    \\iffalse% Single\n    % If you only want a single label per axis side:\n    \\draw (1,-3pt) -- (1,3pt)   node [above] {$1$};\n    \\draw (-3pt,1) -- (3pt,1)   node [right] {$1$};\n    \n    \\else% Multiple\n    % If you want labels at every unit step:\n\n    \\fi\n    \\end{scope}\n    % The circle is drawn with `(x,y) circle (radius)`\n    % You can draw the outer border and fill the inner area differently.\n    % Here I use gray, semitransparent filling to not cover the axes below the circle\n    \\path [draw=none,fill=gray,semitransparent] (+4,+3) circle (2);\n    \\path [draw=red, ultra thick,fill=none,semitransparent, dashed] (+2,+3) arc[start angle=180, end angle=270, radius=2];\n    \n    % Place the labels of the circle:\n    % edge points\n    \\node [below right,darkgray] at (+4,1) {$\\pmb{minf_1}$};\n    \\node [above left,darkgray] at (2,3) {$\\pmb{minf_2}$};\n    \n    %A,B\n    \\node [below left,darkgray] at (2.9,1.325) {$B$};\n    \\node [below left,darkgray] at (2.125,2.328) {$A$};\n    \n    \\node [below,darkgray] at (2.5625,0) {$f_1(A)<f_1(B)$};\n    \\node [above ,darkgray,rotate=90] at (0,1.801) {$f_2(A)>f_2(B)$};\n    \n    %Red points\n    %draw edge points\n     \\node at (2,3) {\\textcolor{red}{\\textbullet}};\n     \\node at (4,1) {\\textcolor{red}{\\textbullet}};    \n     \n    %draw MIDWAY points\n     %\\node at (2.0425,2.6) {\\textcolor{red}{\\textbullet}};\n     \\node at (2.125,2.318) {\\textcolor{red}{\\textbullet}}; %A\n     %\\node at (2.25,2.032) {\\textcolor{red}{\\textbullet}};\n     \\node at (2.435,1.777) {\\textcolor{red}{\\textbullet}};    \n     %\\node at (2.75,1.439) {\\textcolor{red}{\\textbullet}};    \n     \\node at (2.9,1.325) {\\textcolor{red}{\\textbullet}}; %B\n     \\node at (3.45,1.075) {\\textcolor{red}{\\textbullet}};    \n     \n\n     \\node at (2.3,3.2) {\\textcolor{gray}{\\textbullet}};\n     \\node at (2.5,2.6) {\\textcolor{gray}{\\textbullet}};\n     \\node at (3,1.5) {\\textcolor{gray}{\\textbullet}};\n     \n     \\node at (2.7,3.5) {\\textcolor{gray}{\\textbullet}};\n     \\node at (3,3) {\\textcolor{gray}{\\textbullet}};\n     \\node at (3.5,1.9064) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4,1.2) {\\textcolor{gray}{\\textbullet}};\n\n     \\node at (3,4) {\\textcolor{gray}{\\textbullet}};\n     \\node at (3.5,3.3) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4,2.264) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4.5,1.4) {\\textcolor{gray}{\\textbullet}};\n\n     \\node at (3.6,4.35) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4,3.6) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4.5,2.8) {\\textcolor{gray}{\\textbullet}};\n     \\node at (5,1.9) {\\textcolor{gray}{\\textbullet}};\n     \n     \\node at (4,4.8) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4.4,4) {\\textcolor{gray}{\\textbullet}};\n     \\node at (4.7,4.3) {\\textcolor{gray}{\\textbullet}};\n     \\node at (5.1,3.4) {\\textcolor{gray}{\\textbullet}};\n     \\node at (5.5,3.6) {\\textcolor{gray}{\\textbullet}};\n     \\node at (5.5,2.4) {\\textcolor{gray}{\\textbullet}};\n\n    \\end{tikzpicture}\n    \\caption{The image of the feasible set of a Bi-Objective Optimisation problem showcasing the Pareto Front.}\n    \\label{fig:Pareto figure}\n\\end{figure}\n\n\\vspace{\\baselineskip}\n\\noindent\nSuppose, we are given a constrained multi-objective optimisation problem similar to (\\ref{equation: pareto}), where $o=2$, (i.e. our problem has only two objectives). Plotting the image of the feasible set of this problem on the plane ($f_1,f_2$), as seen in Figure \\ref{fig:Pareto figure} \\cite{Taheri2014ParetoFF} can help us locate the \\textbf{minimum} for each objective with respect to all feasible solutions. However, upon trying to simultaneously minimise $f_1,f_2$ one can see from the figure that $minf_1$ is not particularly optimal for $f_2$ and vice versa. If one chooses to minimise $f_1$ by choosing point $minf_1$, they do so at the expense of $f_2$. Hence, according to the Pareto principle we characterise the set of points in between $minf_1,minf_2$ as \\textit{Pareto optimal}, representing the points for which one cannot improve any of the objectives without sacrificing one of the others. These set of points is represented by the red-coloured boundary of the image of the feasible set, and are often seen as \\textbf{efficient frontier} in literature.\n\n\\vspace{\\baselineskip}\n\\noindent\nAll in all, this new notion of optimality defined through the Pareto principle refers to the difference in the approach followed for the solution of a standard linear program compared to a multi-objective problem untangled with the Pareto concept. Instead of attempting to minimise all objectives at once, which would most likely prove ineffective, we instead solve the problem for each objective separately to get an overall depiction of the optimal feasible solutions through a figure like that in Figure \\ref{fig:Pareto figure} then leaving it up to the optimiser to decide the best compromises to be made. This philosophy can be summarised in the following steps \\cite{DUMMY:6}:\n\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwResult{End points of the efficient frontier ($minf_1,minf_2$)}\n initialization: i=1\\;\n \\For{i<o}{\n  i+1\\;\n  $minimise \\; f_i$\\;\n  find the value $s_j$ for objective $j\\neq i$\\;\n  ($minf_i,s_j$) is a point on the efficient frontier\\;\n  \\eIf{there do not exist dominant points $s$ with respect to objective j}{\n   $minimise \\; f_j$ where $j\\neq i$ \\; to find ($minf_j,s_i$)\\;\n   }{\n   points ($f_i(s), f_j(s)$) belonging on the efficient frontier\\;\n  }\n }\n \\caption{How to obtain the \\textbf{efficient frontier}}\n \\label{alg: Pareto}\n\\end{algorithm}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Optimisation under Uncertainty}\n\\label{section:background uncertainty}\n\\subsection{Robust Optimisation}\nIn general there are mostly two approaches to model uncertainty within the context of optimisation, Stochastic Optimisation and Robust Optimisation. For the purposes of this dissertation we focus on the \\textit{robustness} of our models which we define as the quality of a method to remain feasible even after the application of an \\textbf{uncertain set} $U$ on it. Utilising the formulation (\\ref{equation: LP compact form}) we can write the robust version of an LP as \\cite{Bertsimas2011TheoryAA}:\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\label{equation: robust compact form}\n\\begin{aligned}\n& \\underset{x}{\\text{minimise}}\n& & c^{T}x \\\\\n& \\text{subject to}\n& & Ax \\leq b & \\forall a_1 \\in U_1,\\ldots, a_m \\in U_m\\\\\n& & & x \\geq 0 \\\\\\\n\\end{aligned}\n\\end{equation}\n\\[where \\; b \\geq 0 \\; and \\; A \\in \\mathbb{R}^{m \\times n}, \\; b \\in \\mathbb{R}^{m}, \\; c \\in \\mathbb{R}^{n} \\; \\text{and }  U_i \\in \\mathbb{R}^{n}\\]\n\n%%%%%%%%%%%%%%%%%What is the price of robustness of an initial solution. \n\n\\vspace{\\baselineskip}\n\\noindent\nMore specifically, in terms of comparing the \\textit{robustness} of two solutions to a problem we argue the following. Assume one has an optimisation problem, for instance a \\textit{MILP}, which has a certain objective function, and one can obtain a certain number of \\textit{solutions} for it through a certain set of \\textit{methods}. Upon, applying the uncertain set $U$ on the different solutions, we characterise as \\textbf{more robust} the method that after uncertainty provides the solutions with the best objective value.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection*{Robust Optimisation under Uncertainty}\nOne of the fundamental elements of Robust Optimisation are uncertainty sets. An interval-based uncertain set $U$, is defined by a \\textit{lower} and an \\textit{upper} bound, such that an instance of the random variable $s$ is enclosed in the following \\cite{Bertsimas2011TheoryAA}, \\cite{robustuncertainty}:\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\begin{aligned}\n& U \\; = \\; \\prod_{i\\in n} \\{s_i \\in \\mathbb{R}^{n} \\; | \\; \\underline{s_i} \\leq s_i \\leq  \\overline{s_i}\\} \\text{    for Box Uncertainty Set} \\\\\n\\end{aligned}\n\\end{equation}\n\n\\vspace{\\baselineskip}\n\\noindent\nHence, one can now generate instances $I$ of a problem that have this uncertainty set $U$ applied to it, from the following \\textbf{spectrum of Instances}: $I_{lower}$ (every $s$ is $\\underline{s}$), $I_{middle}$ (every $s$ is $\\frac{\\underline{s}+\\overline{s}}{2}$), and $I_{upper}$ (every $s$ is $\\overline{s}$). If we assume that $s$ is enclosed in a ball of radius $\\Omega$ centered at the origin \\cite{robustoptimisation}, we can have the following \\cite{christodoulos},\\cite{GORISSEN}:\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\begin{aligned}\n& U \\; = \\; \\prod_{i\\in n} \\{s \\in \\mathbb{R}^{n} \\; | \\; \\sum _{i=1}^{n}s_{i}^2  \\leq  \\Omega^2 \\} \\text{    for Ellipsoidal Uncertainty Set} \\\\\n\\end{aligned}\n\\end{equation}\n\n\\vspace{\\baselineskip}\n\\noindent\nHowever, in order to use the concept of \\textit{uncertainty sets} to simulate the concept of uncertainty in real-life one should select values of $s$ \\textbf{at random} from within $[\\underline{s},\\overline{s}]$, as this will be a fairer representation of the chaotic randomness that tends to occur in reality.\n\n\\vspace{\\baselineskip}\n\\noindent\nGenerally speaking the generation of uncertainty set is not a trivial matter. D. Bertsimas and D. Brown develop a theory in \\cite{concstructuncertaity} revolved around the generation of uncertainty sets that replicate explicit uncertainty sets as far as their structure and behavior. \n\n\\section{Lexicographic Optimisation}\n\\label{section: Lexicographic}\nThe study of the method of Lexicographic Optimisation is a gateway that allows us to transition to the playing field of multi-objective optimisation. In utilising the concepts of lexicographic optimisation one hopes to minimise those multiple objectives while sequencing the objective functions according to a lexicographical ordering \\cite{surajg}. As mentioned in \\cite{DBLP:journals/corr/abs-1805-03437} using a lexicographic ordering in combination with the Longest Processing Time heuristic seen in \\ref{section:Makespan Scheduling}, we expect to solve the Makespan Schedule problem with superior results both in terms of efficiency but also with respect to quicker solution times. \n\n\\vspace{\\baselineskip}\n\\noindent\nIn general the purpose of using a lexicographically generated schedule is to receive a schedule designed ideally for the process of rescheduling once we determine that some disturbance has occurred \\cite{liebchen}. However, \\cite{DBLP:journals/corr/abs-1805-03437} references us towards works such as \\cite{easybylexico},\\cite{GUPTE2016150} that showcase the effectiveness of lexicographic optimisation not only in obtaining efficient schedules but also in doing so in a relatively quick fashion provided our mixed-integer problem satisfies certain requirements. Being aware of this reasoning behind the use of lexicographic optimisation, we expect to obtain favourable results compared to less state-of-the-art methodologies. Indeed, as we will see in \\ref{chapter:Benchmark Instances} that is the case, as this methodologies tends to outperform other methodologies studied with respect to various aspects.\n \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Vehicle Routing Problems}\n\\label{section: vrp}\nOur problem can be interpreted as a \\textit{Vehicle Routing Problem (VRP)} with collection and distribution\\footnote{Namely, a problem that is capable of incorporating a delivery and a pick of an item to and from a location in the same trip.} \\cite{Irnich}. We do not explicitly focus on the study of the routing of the problem, but instead focus on the scheduling aspect and only utilise some concepts derived from the \\textit{VRP} discipline in our project. Nevertheless, we propose the application of the routing aspect of the \\textit{VRP} philosophy on our problem as one of the future directions that need to be explored in the context of our problem. Hence, we include below a brief study, that aims to give the reader a high-level overview of this class of problems.\n\n\\vspace{\\baselineskip}\n\\noindent\n\\textit{Vehicle Routing Problems (VRP)} have been studied intensely over the years, and well known survey papers such as \\cite{doi:surveyVRP} can give an interested reader further information on the problem. Moreover, the following paper \\cite{LAPORTE1992345} outlines the most frequently used algorithms towards efficient solving of problems of this context. Such algorithms are used for the purposes of a formulation seen in Section \\ref{section: Pre-emptive} of Chapter \\ref{chapter: 2-Evaluating Royal Mail Historical Data}, where the vehicle routing aspect of our problem is studied. Moreover, given that the application of the vehicle routing concepts on our problem is presented as one of the directions for future research, we believe that a careful study of efficient approximation algorithms such as those studied in \\cite{approx} would be purposeful. \n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Multiprocessor Scheduling Problems}\n\nScheduling problems are a common class of decision-making problems that deal with the search for the most efficient method of allocating resources to tasks. This search for efficiency is explored by attempting to optimise a single or multiple objectives related to the problem which eventually leads us to the most suitable schedule for each problem. In real world professional environments, suitable task schedules are critical to ensure a good balance of the load amongst the parallel machines \\cite{DUMMY:2}.\\par\n\\vspace{\\baselineskip}\n\\noindent\nThere are numerous kinds of scheduling problems. This dissertation focuses on the class of deterministic problems that are supplied as input a collection of tasks requiring processing on an environment comprised of a bank of identical parallel machines. In \\textit{deterministic} problems, the input data is made available prior to the optimisation process and the aim is to come up with the most efficient sequence of these jobs, subject to a set of constraints, that optimises one or more performance criteria. This task can be broken down to, deciding which tasks have to be allocated to each machine as well as how to sequence the jobs dispatched to each machine. Machines can process at most one job on any given moment in time, and will see a job to its completion once its execution has begun. \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Makespan Scheduling}\n\\label{section:Makespan Scheduling}\nIn \\textit{makespan} scheduling problems, the objective function to be minimised is the \\textit{makespan (\\( C_{\\max }\\)})\\textit{. }The \\textit{makespan }defined as  \\( max \\left( C_{1},C_{2},...,C_{n} \\right)   \\) is equivalent to the point in time that signifies the \\textbf{termination} of the\\textbf{ last job} to be \\textbf{completed}. Our goal is to sequence the jobs in question, in an efficient manner that enables the last job to finish processing as early as possible, while respecting the specified set of constraints. In essence, this type of problems resemble the generalised bin-packing problems in the context of scheduling \\cite{Coffman1978AnAO}. The minimisation of the makespan is one of the most utilised optimality criteria \\cite{schedalgos} because striving to minimise the overall makespan of a schedule more often than not, results in a schedule that achieves a well-balanced sequence of jobs \\cite{DUMMY:2}. \\par\n\\vspace{\\baselineskip}\n\\noindent\n\\textbf{Set of Input Data}\n\n\\vspace{\\baselineskip}\n{\\addtolength{\\leftskip}{5mm}\n\\noindent\n\\( Set~M= \\{ 1,2,...,m \\}  \\)  specifies an environment of \\textit{m} parallel and identical machines. \n\n\\vspace{\\baselineskip}\n\\noindent\n\\( Set~J= \\{ 1,2, \\ldots ,n \\}  \\) represents the number of jobs that await to be sequenced on each machine.\\par\n \n \\vspace{\\baselineskip}\n \\noindent\nThe n-dimensional vector \\textbf{p} contains the processing time \\( p_{j} \\) of job \\( j .\\)\\par\n\n}\n\n\\vspace{\\baselineskip}\n\\noindent\n\\textbf{Parallel Machine model}\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\label{equation: makespan background}\n\\begin{aligned}\n& \\underset{x_{ij}}{\\text{minimise}}\n& & C_{\\max } \\\\\n& \\text{subject to}\n& &  C_{\\max } \\geq \\sum _{j=1}^{n}x_{ij} \\cdot p_{j}~~ \\;\\;\\; &\\text{for } i \\in M\\\\\n& & & \\sum _{i=1}^{m}x_{ij} = 1\\;\\;\\; &\\text{for } j \\in J\\\\\n& & & x_{ij} \\in  \\{ 0,1 \\} \\;\\;\\; &\\text{for } i \\in M, \\; j \\in J\\\\\n\\end{aligned}\n\\end{equation}\n\n\\vspace{\\baselineskip}\n\\noindent\nThe first constraint reflects the definition of the \\textit{makespan}, and makes sure that it takes the value of the completion time of the last job to be completed. The second constraint enforces that each job is executed once and only once throughout the spectrum of all the machines. Finally, the third constraint is the integrality constraint of such a \\textit{MILP} problem.   \n\n\\vspace{\\baselineskip}\n\\noindent\nAs we can see, Figure \\ref{fig:intro gantt chart} contains an example of two schedules\\cite{DUMMY:2}. The example is meant to illustrate the effect of applying a Makespan Scheduling formulation on the non-optimised schedule seen in \\ref{fig:intro gantt chart}(a). In this case the set of input data is the following:\n\n\\vspace{\\baselineskip}\n{\\addtolength{\\leftskip}{5mm}\n\\noindent\nWe have four parallel and identical machines.\\par\n\n\\vspace{\\baselineskip}\n\\noindent\nWe have nine jobs each with their own processing time $p_j$.\\par\n \n}\n\n\\vspace{\\baselineskip}\n\\noindent\nWe can see that by applying this set of input data to formulation \\ref{equation: makespan background} we get a reduction in the makespan of the schedule in \\ref{fig:intro gantt chart}(a) from 15 hours down to 12 hours in in \\ref{fig:intro gantt chart}(b). Moreover, as expected the workload of all machines is considerably more balanced since they are all of a duration equal to 12 hours. Indeed, it is true however, that those duties that we originally below the 12 hour mark have seen their duration increased (up to the 12 hour mark).\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%Two images in one, illustrating atomic block\n\\begin{figure}%\n    \\centering\n    \\subfloat[Un-optimised that our model receives as input for rescheduling.]{\n\\begin{tikzpicture}\n\\begin{axis}[\n  font=\\footnotesize,\n  ytick style={draw=none},\n  xtick style={draw=none},\n  %unit vector ratio*=1 1 1,%1 0.6 1,\n  axis lines = middle,\n  enlarge x limits = {value=.01,upper},\n  enlarge y limits = {value=.05,upper},\n  ylabel={\\textbf{Machines}},\n  xlabel={\\textbf{Time (HH:mm)}},\n  ylabel near ticks,\n  xlabel near ticks,\n  const plot,\n  stack plots=false,\n  area style,\n  width=0.46\\textwidth,\n  height=5cm, %control the height of chart\n  %width=\\linewidth,height=\\textheight,\n  ytick={1,...,60},\n  yticklabels={},  \n  xtick={0,2,...,24},,\n  extra y ticks={1,2,3,4},\n  extra y tick style={yticklabel={$M_{\\pgfmathprintnumber{\\tick}}$}}\n  ] \n\\addplot[fill=yellow] coordinates {(0,0) (0,1) (6,1) (6,0) } node at (current path bounding box.center) {J4};\n\\addplot[fill=orange] coordinates {(6,0) (6,1) (11,1) (11,0) } node at (current path bounding box.center) {J5};\n\\addplot[fill=red!20] coordinates {(0,1) (0,2) (6,2) (6,1) } node at (current path bounding box.center) {J3};\n\\addplot[fill=gray] coordinates {(6,1) (6,2) (11,2) (11,1) } node at (current path bounding box.center) {J6};\n\\addplot[fill=light blue] coordinates {(0,2) (0,3) (7,3) (7,2) } node at (current path bounding box.center) {J2};\n\\addplot[fill=teal] coordinates {(7,2) (7,3) (11,3) (11,2) } node at (current path bounding box.center) {J7};\n\\addplot[fill=yellow!60!black] coordinates {(0,3) (0,4) (7,4) (7,3) } node at (current path bounding box.center) {J1};\n\\addplot[fill=blue!20] coordinates {(7,3) (7,4) (11,4) (11,3) } node at (current path bounding box.center) {J8};\n\\addplot[fill=magenta] coordinates {(11,3) (11,4) (15,4) (15,3) } node at (current path bounding box.center) {J9};\n\\end{axis}\n\\end{tikzpicture}}%picture #1\n    \\qquad\n    %picture #2\n    \\subfloat[Rescheduled and Makespan optimised Schedule.]{\\begin{tikzpicture}\n\\begin{axis}[\n  font=\\footnotesize,\n  ytick style={draw=none},\n  xtick style={draw=none},\n  %unit vector ratio*=1 1 1,%1 0.6 1,\n  axis lines = middle,\n  enlarge x limits = {value=.01,upper},\n  enlarge y limits = {value=.05,upper},\n  ylabel={\\textbf{Machines}},\n  xlabel={\\textbf{Time (HH:mm)}},\n  ylabel near ticks,\n  xlabel near ticks,\n  const plot,\n  stack plots=false,\n  area style,\n  width=0.46\\textwidth,\n  height=5cm, %control the height of chart\n  %width=\\linewidth,height=\\textheight,\n  ytick={1,...,60},\n  yticklabels={},  \n  xtick={0,2,...,24},\n  extra y ticks={1,2,3,4},\n  extra y tick style={yticklabel={$M_{\\pgfmathprintnumber{\\tick}}$}}\n  ] \n\\addplot[fill=teal] coordinates {(0,0) (0,1) (4,1) (4,0) } node at (current path bounding box.center) {J7};\n\\addplot[fill=blue!20] coordinates {(4,0) (4,1) (8,1) (8,0) } node at (current path bounding box.center) {J8};\n\\addplot[fill=magenta] coordinates {(8,0) (8,1) (12,1) (12,0) } node at (current path bounding box.center) {J9};\n\\addplot[fill=red!20] coordinates {(0,1) (0,2) (6,2) (6,1) } node at (current path bounding box.center) {J3};\n\\addplot[fill=yellow] coordinates {(6,1) (6,2) (12,2) (12,1) } node at (current path bounding box.center) {J4};\n\\addplot[fill=light blue] coordinates {(0,2) (0,3) (7,3) (7,2) } node at (current path bounding box.center) {J2};\n\\addplot[fill=orange] coordinates {(7,2) (7,3) (12,3) (12,2) } node at (current path bounding box.center) {J5};\n\\addplot[fill=yellow!60!black] coordinates {(0,3) (0,4) (7,4) (7,3) } node at (current path bounding box.center) {J1};\n\\addplot[fill=gray] coordinates {(7,3) (7,4) (12,4) (12,3) } node at (current path bounding box.center) {J6};\n\\addplot[fill=none,opacity=0.0] coordinates {(12,3) (12,4) (15,4) (15,3) } node at (current path bounding box.center) {};\n\\end{axis}\n\\end{tikzpicture}}\n    %end of picture #2\n    \\caption{Illustrations showing the process of \\textbf{Rescheduling} implemented throughout this dissertation.}%\n    \\label{fig:intro gantt chart}%\n\\end{figure}\n\n\n\\subsubsection{Longest Processing Time}\n\nIn order to achieve an effective sequencing of the jobs, heuristics such as the \\textit{Longest Processing Time first (LPT)}  rule have been developed. According to this algorithm, the \\textit{m} first jobs with the longest processing times  \\( p_{j} \\)  are assigned at the start to the \\textit{m} available machines. The first machine, out of the batch of those \\textit{m} machines to finish its execution is subsequently assigned the job with the longest processing time amongst those remaining, and so forth. It turns out by definition, that the job with the shortest processing time is the last one to begin its processing. \\par\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Time-Indexed Models}\n\nIn \\textit{time-indexed} formulations, we choose to add the dimension of \\textit{time} to our model. We can express the same problem with a \\textit{discrete time} formulation, by splitting continuous time \\( t \\) into \\( T \\) discrete intervals. Consequently we have that, $ t \\in T = \\{0,1,\\ldots,T-1\\} $. We then use binary variable \\( x_{ijt} \\) which equals to \\( 1 \\) if job \\( j \\) starts at time \\( t \\) on machine \\( i \\) and equal to \\( 0 \\) the rest of the time \\cite{DUMMY:2}.  \\par\n\n\n\\vspace{\\baselineskip}\n\\begin{equation}\n\\begin{aligned}\n& \\underset{x_{ijt}}{\\text{minimise}}\n& & \\sum _{i=1}^{m}\\sum _{j=1}^{n}\\sum _{t=0}^{C_{\\max }-1}x_{ijt} \\cdot (t+p_{j}) \\\\\n& \\text{subject to}\n& & \\sum _{i=1}^{m}\\sum _{t=0}^{C_{\\max }-1} x_{ijt} = 1 \\;\\;\\; &\\text{for } j \\in J\\\\\n& & & \\sum _{j=1}^{n}\\sum _{s=max(t-p_{j},0)}^{t-1}x_{ijt} = 1 \\;\\;\\; &\\text{for } t \\in T, \\; i \\in M\\\\\n& & & \\sum _{i=1}^{m}\\sum _{j=1}^{n}\\sum _{s=max(t-p_{j},0)}^{t-1}x_{ijt} \\leq m \\;\\;\\; &\\text{for } t \\in T\\\\\n& & & x_{ijt} \\in  \\{ 0,1 \\} \\;\\;\\; &\\text{for } i \\in M, \\; j \\in J, \\; t \\in T\\\\\n\\end{aligned}\n\\end{equation}\n\n\\vspace{\\baselineskip}\n\\noindent\nWith the first constraint we make sure that each job is executed once and only once throughout all the machines. The second constraint enforces the definition of the environment of machines, namely that each machine does not process more than one job at any given moment in time. The third constraint is in place to prevent the possibility of more jobs being executed at some point in time, than there are machines available in the environment. Finally, the last constraint reflects the integrality constraint of such a \\textit{MILP} problem.   \n\n\\vspace{\\baselineskip}\n\\noindent\nComparing this time-indexed formulation with that in (2.5), it is visible that (2.6) will result in substantially more variables being used, ($m$$\\cdot$$n$$\\cdot$$C_{max}$)-many $x_{ijt}$ variables to be exact. Come solution time, this will be a factor that slows down the process of obtaining a solution to (2.6).\n\\vspace{\\baselineskip}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   SUB SECTION  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection*{Pareto Optimal Schedule}\nReturning to the context of the scheduling problem, we can characterise a schedule Pareto optimal provided we cannot minimise one of its objectives without\nincurring an expense for another objective, as expected from the definition of a Pareto optimal solution in Section \\ref{section: Pareto}.\n\n\\vspace{\\baselineskip}\n\\noindent\nAs with any other Pareto relevant problem, we will be hence able to plot all Pareto Optimal schedules on the $f_1,f_2,\\ldots,f_n$ plane. In the majority of problems such as those studied in Chapter \\ref{chapter: 2-Evaluating Royal Mail Historical Data} only Pareto Optimal schedules are of interest. On the contrary a schedule that cannot be placed on a Pareto frontier is of little interest to us. The process is usually to create the Pareto frontier such that the scheduler can observe all the Pareto points and subsequently select the most preferable schedule for their requirements\n\n\\section{System Specifications}\nAll computations are processed with a 6-core Intel Core i7 CPU running at 2.60GHz with a 16GB RAM memory on a macOS Catalina (version 10.15.4) machine. The models were implemented using C++11 that was compiled with the GNU Compiler Collection (GCC). The solutions were obtained through using the commercial solver CPLEX 12.9. Unless it is specifically stated, all solutions obtained are the optimal ones for the given objective function, set of constraints and decision variables.   \n\n\n\\vspace{\\baselineskip}\n\n\\vspace{\\baselineskip}\n\n\\vspace{\\baselineskip}\n\n\\vspace{\\baselineskip}\n", "meta": {"hexsha": "c02ecca882bdb60cd9749b7cafa8992b9d318b80", "size": 63282, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/.tex files/background/background.tex", "max_stars_repo_name": "liaskast/Final-Year-Project", "max_stars_repo_head_hexsha": "6943f5fc406891ae1635e42dff6e7fba28a2bffc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-21T21:22:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-26T14:12:36.000Z", "max_issues_repo_path": "Report/.tex files/background/background.tex", "max_issues_repo_name": "liaskast/Final-Year-Project", "max_issues_repo_head_hexsha": "6943f5fc406891ae1635e42dff6e7fba28a2bffc", "max_issues_repo_licenses": ["MIT"], "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 files/background/background.tex", "max_forks_repo_name": "liaskast/Final-Year-Project", "max_forks_repo_head_hexsha": "6943f5fc406891ae1635e42dff6e7fba28a2bffc", "max_forks_repo_licenses": ["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.0022123894, "max_line_length": 1553, "alphanum_fraction": 0.6883948042, "num_tokens": 17262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.6430744609006774}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{Quadrupole approximation}\n\nThe procedure to find the quadrupole approximation \nfor the GW emitted by a Newtonian system is in the form: \n\\begin{enumerate}\n    \\item determine the density \\(\\rho (\\vec{x}, t)\\);\n    \\item calculate the trace-free inertia tensor \\(Q^{ij}(t)\\);\n    \\item calculate the gravitational wave strain \\(h_{ij}\\). \n\\end{enumerate}\n\n\\subsection{Two point particles}\n\nIn order to model the point-like nature of the particles we can write an expression for the density as a sum of two delta-functions,\nwhose locations rotate around an axis --- let us fix it to be\nthe \\(z\\) axis for simplicity, \nand also let us suppose that we are on the \\(z = 0 \\) plane: \n%\n\\begin{align}\n\\rho (\\vec{x}, t) = m\\delta (\\vec{x} - \\vec{x}_1(t)) + m\\delta (\\vec{x} - \\vec{x}_2 (t))                                                                        \n\\,,\n\\end{align}\n%\nwhere \n%\n\\begin{align}\n\\vec{x}_1 (t) = r \\left[\\begin{array}{c}\n\\cos(\\omega t + \\phi ) \\\\ \n- \\sin(\\omega t + \\phi ) \\\\ \n0\n\\end{array}\\right]\n\\qquad \\text{and} \\qquad\n\\vec{x}_2 (t) = - \\vec{x}_1 (t)\n\\,.\n\\end{align}\n\nFor simplicity we will also assume that the radius \\(r\\) is constant --- this cannot be precisely the case, since there will be some amount of power lost because of the GW emission, but it is a reasonable approximation.\n\nSo, the trace-free inertia tensor will be given by \n%\n\\begin{align}\nQ^{ij} (t) &= \\int \\rho (\\vec{x}, t) \\qty( x^{i} x^{j} - \\frac{1}{3} \\delta^{ij} r^2) \\dd[3]{x}  \\\\\n&= m \\sum _{k=1, 2} \\qty(x_k^{i} x_k^{j} - \\frac{1}{3} \\delta^{ij} r^2)  \\\\\n&= 2 m r^2 \\left[\\begin{array}{cc}\n\\cos^2 - 1/3 & - \\cos \\sin \\\\ \n- \\cos \\sin & \\sin^2 - 1/3  \n\\end{array}\\right] \n\\,,\n\\end{align}\n%\nwhere we write only the upper-left 2x2 submatrix in \\(Q^{ij}\\), since the other entries are constant, and we omit the argument of the sines and cosines (which is always \\(\\omega t + \\phi \\)). \n\nThe second derivative of this tensor will be given by \n%\n\\begin{align}\n\\ddot{Q}^{ij}(t) = 4 m r^2 \\omega^2 \\left[\\begin{array}{cc}\n\\sin^2 - \\cos^2 & 2 \\sin \\cos \\\\ \n2 \\sin \\cos & \\cos^2 - \\sin^2\n\\end{array}\\right]\n\\,,\n\\end{align}\n%\n \n\nNow, in order to compute the gravitational wave strain we need the projection tensor \\(\\Lambda_{ij, kl}\\).\nIf the propagation direction we are interested in is \\(\\vec{k}\\), then the tensor \n%\n\\begin{align}\nP_{ij} = \\delta_{ij} - \\frac{k_i k_j}{\\abs{k}^2} = \\delta_{ij} - n_i n_j\n\\,\n\\end{align}\n%\nwill project a vector onto the subspace orthogonal to \\(\\vec{k}\\); and the tensor \n%\n\\begin{align}\n\\Lambda_{ij, kl} &= P_{ik} P_{jl} - \\frac{1}{2} P_{ij} P_{kl}  \\\\\n&= \\delta_{ik} \\delta_{jl} - n_i n_k \\delta_{jl} - \\delta_{ik} n_j n_l + \\frac{1}{2} n_{i} n_k n_j n_l - \\frac{1}{2} \\delta_{ij} \\delta_{kl} + \\frac{1}{2} \\delta_{ij} n_k n_l + \\frac{1}{2} n_i n_j \\delta_{kl} \n\\,,\n\\end{align}\n%\nwill project a rank-2 tensor onto the corresponding subspace. \n\n\n\n\\end{document}\n", "meta": {"hexsha": "3da3b4b21286b01199c0dc7d7b8d3bfffec15ce8", "size": 2947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phd_courses/numerical_relativity_exercises/sheet1.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": "phd_courses/numerical_relativity_exercises/sheet1.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": "phd_courses/numerical_relativity_exercises/sheet1.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": 33.4886363636, "max_line_length": 219, "alphanum_fraction": 0.6287750254, "num_tokens": 1005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6430744448870885}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\usepackage{assignment_style}\n\\usetikzlibrary{patterns}\n\\newcounter{problem}\n\\newenvironment{problem}[1][]{%\n\t\\refstepcounter{problem}\\par \\medskip\n\t\\noindent \\textbf{Problem~\\theproblem.#1 \\rmfamily}{\\medskip}\n}\n\n\\newenvironment{solution}{ \\noindent \\textbf{Solution: \\medskip}}{}\n% To make solutions not visible use the command \\excludecomment{solution} %\n%\\excludecomment{solution}\n\n\\title{Assignment 1 \\\\ \\vspace{2em} \\large WSU Economics PhD Math Bootcamp }\n\\date{}\n\\begin{document}\n\\maketitle\n\n\\begin{problem}\n%Leon application page 23-25\nConsider an economy with three sectors: farming, manufacturing and textiles.\nEach sector produces its goods and then trades (through barter) with the other sectors.\nHence the three kinds of goods move between sectors.\nLet the following table describe the results of trade.\n\n\\vspace{1em}\n\\begin{center}\n\\begin{tabular}{ c | c c c }\\hline\\hline\n\t& F & M & T \\\\ \\hline\nF & $\\frac{1}{2}$ & $\\frac{1}{3}$ & $\\frac{1}{2}$ \\\\\nM & $\\frac{1}{4}$ & $\\frac{1}{3}$ & $\\frac{1}{4}$ \\\\\nT & $\\frac{1}{4}$ & $\\frac{1}{3}$ & $\\frac{1}{4}$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nThe table is interpreted is as follows.  Let $x_1$ be the total value of farm goods, $x_2$ the total value of manufacturing goods and $x_3$ the total value of textile goods.\nThe first column of the table describes where the farming sectors output goes -- $1/2$ to themselves, $1/4$ to manufacturing and $1/4$ to textiles.\nThe first row describes the value of the farming sectors inputs -- $1/2$ from farming itself, $1/3$ manufacturing goods and $1/2$.\nHence the total value of farm goods is $x_1 = (1/2)x_1 + (1/3)x_2 + (1/2)x_3$.\nDoing the same for the other sectors gives the system\n\\begin{align}\n\tx_1 &= \\frac{1}{2}x_1 + \\frac{1}{3}x_2 + \\frac{1}{2}x_3 \\nonumber \\\\\n\tx_2 &= \\frac{1}{4}x_1 + \\frac{1}{3}x_2 + \\frac{1}{4}x_3 \\nonumber \\\\\n\tx_3 &= \\frac{1}{4}x_1 + \\frac{1}{3}x_2 + \\frac{1}{4}x_3 \\nonumber\n\\end{align}\n\nTurn the above system into a homogenous system and then solve the system to determine the total values of goods $x_1,x_2,x_3$.\n\\end{problem}\n\\insblock{Problem 1 Note}{Understand the definition of a homogenous system of linear equations and apply the appropriate matrix manipulations to solve the system.}\n\\begin{solution}\nThe reduced row echelon form for the augmented system is\n\\begin{align}\n\\left[\n\t\\begin{matrix}\n\t\t1 & 0 & -\\frac{5}{3} & | 0 \\nonumber \\\\\n\t\t0 & 1 & -1 & | 0 \\nonumber \\\\\n\t\t0 & 0 & 0 & | 0 \\nonumber\n\t\\end{matrix}\n\\right]\n\\end{align}\nThere is one free variable, $x_3$.\nIf we let $x_3=3$ then the solution is $(5,3,3)$.\n\\end{solution}\n\n\\begin{problem}\n%Leon section 1.2 Problem 5 part (g)\n\tDetermine whether the following system is inconsistent.  If not inconsistent and no free variables, find the unique solution.  If there are free variables find all solutions (describe the set).\n\t\\begin{align}\n\t\tx_1 + x_2 + x_3 + x_4 &= 0 \\nonumber \\\\\n\t\t2x_1 + 3x_2 -x_3 -x_4 &= 2 \\nonumber \\\\\n\t\t3x_1 + 2x_2 + x_3 + x_4 &= 5 \\nonumber \\\\\n\t\t3x_1 + 6x_2 -x_3 - x_4 &= 4 \\nonumber\n\t\\end{align}\n\\end{problem}\n\\insblock{Problem 2 Note}{This problem tests the idea that any linear system as either no solutions, 1 solution or an infinite number of solutions and you need to apply the appropriate methods to determine the case for the above system and how to describe the solution. The following problem tests the same concepts.}\n\\begin{solution}\n\tThe system is inconsistent\n\\end{solution}\n\n\\begin{problem}\n%Leon section 1.2 Problem 5 part (i)\n\tDetermine whether the following system is inconsistent.  If not inconsistent and no free variables, find the unique solution.  If there are free variables find all solutions (describe the set).\n\t\\begin{align}\n\t\t-x_1 + 2x_2 -x_3 &= 2 \\nonumber \\\\\n\t\t-2x_1 + 2x_2 + x_3 &= 4 \\nonumber \\\\\n\t\t3x_1 + 2x_2 + 2x_3 &= 5 \\nonumber \\\\\n\t\t-3x_1 + 8x_2 + 5x_3 &= 17 \\nonumber\n\t\\end{align}\n\\end{problem}\n\\begin{solution}\n\tThe system is consistent with no free variables and the unique solution is $(0, 3/2, 1)$.\n\\end{solution}\n\n\\begin{problem}\n\n\tFind the inverse matrix for the following matrices:\n\\[\n\t(\\text{a}) \\; \\left[\\begin{matrix}\n\t\t-1 & 1 \\\\\n\t\t1 & 0\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{b}) \\; \\left[\\begin{matrix}\n\t\t2 & 5 \\\\\n\t\t1 & 3\n\t\\end{matrix}\\right] \\qquad \n\t(\\text{c}) \\; \\left[\\begin{matrix}\n\t\t2 & 6 \\\\\n\t\t3 & 8\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{d}) \\; \\left[\\begin{matrix}\n\t\t1 & 1 & 1 \\\\\n\t\t0 & 1 & 1 \\\\\n\t\t0 & 0 & 1\t\t\n\t\\end{matrix}\\right] \\qquad\n\\]\n\\[\n\t(\\text{e}) \\; \\left[\\begin{matrix}\n\t\t2 & 0 & 5 \\\\\n\t\t0 & 3 & 0 \\\\\n\t\t1 & 0 & 3\t\t\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{f}) \\; \\left[\\begin{matrix}\n\t\t-1 & -3 & -3 \\\\\n\t\t2 & 6 & 1 \\\\\n\t\t3 & 8 & 3 \t\t\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{g}) \\; \\left[\\begin{matrix}\n\t\t1 & 0 & 1 \\\\\n\t\t-1 & 1 & 1 \\\\\n\t\t-1 & -2 & -3\n\t\\end{matrix}\\right]\n\\]\n\\end{problem}\n\\insblock{Problem 4 Note}{Tests understanding of the definition of an inverse matrix and how to calculate it for $2\\times 2$ and $3\\times 3$ systems.}\n\\begin{solution}\n\\[\n\t(\\text{a}) \\; \\left[\\begin{matrix}\n\t\t0 & 1 \\\\\n\t\t1 & 1\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{b}) \\; \\left[\\begin{matrix}\n\t\t3 & -5 \\\\\n\t\t-1 & 2\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{c}) \\; \\left[\\begin{matrix}\n\t\t-4 & 3 \\\\\n\t\t3/2 & -1\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{d}) \\; \\left[\\begin{matrix}\n\t\t1 & -1 & 0 \\\\\n\t\t0 & 1 & -1 \\\\\n\t\t0 & 0 & 1\n\t\\end{matrix}\\right] \\qquad\n\\]\n\\[\n\t(\\text{e}) \\; \\left[\\begin{matrix}\n\t\t3 & 0 & -5 \\\\\n\t\t0 & 1/3 & 0 \\\\\n\t\t-1 & 0 & 2\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{f}) \\; \\left[\\begin{matrix}\n\t\t2 & -3 & 3 \\\\\n\t\t-3/5 & 6/5 & -1 \\\\\n\t\t-2/5 & -1/5 & 0\n\t\\end{matrix}\\right] \\qquad\n\t(\\text{g}) \\; \\left[\\begin{matrix}\n\t\t-1/2 & -1 & -1/2 \\\\\n\t\t-2 & -1 & -1 \\\\\n\t\t3/2 & 1 & 1/2\n\t\\end{matrix}\\right] \\qquad\n\\]\n\\end{solution}\n\n\\begin{problem}\n%Leon section 2.1 problem 3 (d),(g)\nEvaluate the following determinants\n\\[\n\t(\\text{a}) \\; \\left|\\begin{matrix}\n\t\t4 & 3 & 0 \\\\\n\t\t3 & 1 & 2 \\\\\n\t\t5 & -1 & -4\t\t\n\t\\end{matrix}\\right| \\qquad\n\t(\\text{b}) \\; \\left|\\begin{matrix}\n\t\t2 & 0 & 0 & 1 \\\\\n\t\t0 & 1 & 0 & 0 \\\\\n\t\t1 & 6 & 2 & 0 \\\\\n\t\t1 & 1 & -2 & 3\n\t\\end{matrix}\\right|\n\\]\n\\end{problem}\n\\insblock{Problem 5 Note}{Tests the ability to calculate the determinant of a linear system.}\n\\begin{solution}\n\t(a) 58; \\; (b) 8\n\\end{solution}\n\n\\begin{problem}\n%Leon Section 2.3 Cramer's rule example page 107\nUse Cramer's rule to solve the following system\n\\begin{align}\n\tx_1 + 2x_2 + x_3 &=5 \\nonumber \\\\\n\t2x_1 + 2x_2 + x_3 &= 6 \\nonumber \\\\\n\tx_1 + 2x_2 + 3x_3 &= 9 \\nonumber\n\\end{align}\n\\end{problem}\n\\begin{solution}\n\\[\n\tx_1 = \\frac{-4}{-4} = 1, \\qquad x_2 = \\frac{-4}{-4} = 1, \\qquad x_3 = \\frac{-8}{-4} = 2\n\\]\n\\end{solution}\n\n\\begin{problem}\nLet $A$ and $B$ be $6\\times 6$ matrices, with $\\det(A) = -10$ and $\\det(B) = 5$.\nUse the properties of determinants to compute\n\\begin{enumerate}[(a)]\n\t\\item $\\det(3A)$\n\t\\item $\\det(A^{T} B^{-1})$\n\\end{enumerate}\n\n\\end{problem}\n\\insblock{Problem 7 Note}{Tests understanding of the properties of determinants as they apply to matrix algebra.}\n\\begin{solution}\n\\begin{enumerate}[(a)]\n\t\\item $\\det(3A) = 3^6 \\det(A) = 729(-10) = -7290$.\n\t\\item \\begin{align}\n\t\t\t\t\\det(A^T B^{-1}) &= \\det(A^T) \\cdot \\det(B^{-1}) \\nonumber \\\\\n\t\t\t\t&= \\left( \\det(A) \\right) \\frac{1}{\\det(B)} \\nonumber \\\\\n\t\t\t\t&= -10 \\frac{1}{5} \\nonumber \\\\\n\t\t\t\t&= -2 \\nonumber\n\t\t  \\end{align}\n\\end{enumerate}\n\\end{solution}\n\n\\begin{problem}\nProve that if $A$ is invertible, then $\\det(A^{-1}) = \\frac{1}{\\det(A)}$\n\\end{problem}\n\\insblock{Problem 8 Note}{Tests understanding of properties of determinants and inverses as well as the idea of mathematical proof.}\n\\begin{solution}\n\tBy multiplicative properties of the determinant\n\t\\[\n\t\t\\det(AA^{-1}) = \\det(A) \\cdot \\det(A^{-1})\n\t\\]\n\tWe also know that $AA^{-1} = I_n$, the $n\\times n$ identity matrix, and $\\det(I_n) = 1$ (this can be seen because $I_n$ is a diagonal matrix).\n\tSo we have\n\t\\[\n\t\t\\det(A)\\cdot \\det(A^{-1}) = 1\n\t\\]\n\tSolving for $\\det(A)$, we get $\\det(A^{-1}) = \\frac{1}{\\det(A)}$ where is it okay to divide by $\\det(A)$ because we know that $\\det(A) \\neq 0$ because $A$ is invertible. \\qedsymbol\n\\end{solution}\n\n\\begin{problem}\nLet $A$ be a $3\\times 3$ matrix with $\\det(A) = 5$.\nFind each of the following if possible.\n\\begin{enumerate}[(a)]\n\t\\item $\\det(A^T)$\n\t\\item $\\det(A + I)$\n\t\\item $\\det(2A)$.\n\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 9 Note}{Tests understanding of matrix algebra and its effects on the value of a determinant of a linear system.  Also, remember that one reason we care about determinants is because they can often tell us something about the solution space to a linear system.}\n\\begin{solution}\n\\begin{enumerate}[(a)]\n\t\\item $\\det(A^T) = \\det(A) = 5$\n\t\\item There is not enough information\n\t\\item $\\det(2A) = 2^3 \\det(A) = 40$.\n\\end{enumerate}\n\\end{solution}\n\n\\begin{problem}\n\tWhat are the dimensions of the following subsets of $\\mathbb{R}^3$?\n\t\\begin{enumerate}[(i)]\n\t\t\\item The origin?\n\t\t\\item A line through the origin?\n\t\t\\item A plane which passes through the origin?\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Note}{Tests understanding of the idea of linear spaces and their dimension -- Hint: linear spaces are the \\textit{span} of a set of \\textit{basis vectors}.}\n\\begin{solution}\n\t\\begin{enumerate}[(i)]\n\t\t\\item The origin has dimension zero.  Note that $\\alpha(0,0,0) = (0,0,0)$ is true for all $\\alpha \\in \\mathbb{R}$ so its always linearly dependent.\n\t\t\\item A line through the origin has dimension 1.\n\t\t\\item A plane has dimension 2.\n\t\\end{enumerate}\n\\end{solution}\n\n\n\\begin{problem}\n%Duke Mathcamp notes problem 1.23 and 1.24\n\tFor $\\mathbf{a},\\mathbf{x} \\in \\mathbb{R}^n$, consider the equation $\\mathbf{a} \\cdot \\mathbf{x} = 0$ and its solution set $X(\\mathbf{a}) = \\{ \\mathbf{x} \\in \\mathbb{R}^n \\; | \\; \\mathbf{a} \\cdot \\mathbf{x} = 0 \\}$.  \n\t\\begin{enumerate}[(i)]\n\t\t\\item Show that $X(\\mathbf{a})$ is a linear subspace.\n\t\t\\item Show the dimension of $X(\\mathbf{a})$.\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 11 Note}{Tests understanding of \\textit{null spaces} of linear functions (matrices).  Null spaces can often represent the space of solutions to an economic problem.  It also tests your understanding of a linear subspace and how to show a set is one as well as identify its dimension.}\n\\begin{solution}\n\t\\begin{enumerate}[(i)]\n\t\t\\item If $x,x' \\in X(a)$ then $a\\cdot x = a\\cdot x' = 0$.\n\t\tHence $a\\cdot x + a\\cdot x' = a\\cdot(x + x') = 0$ and this implies that $x+x' \\in X(a)$.\n\t\tAgain let $x \\in X(a)$ then $a\\cdot x = 0$ and $\\alpha a\\cdot x = 0$ as well.\n\t\tMoving the constant we see that $a \\cdot (\\alpha x) = 0$ which means that $\\alpha x \\in X(a)$.\n\t\t\\item Clearly the dimension of $\\mathbb{R}^n$ is $n$.\n\t\tThe vector $a$ represents a linear mapping with one row.\n\t\tThe linear span of $a$ is contained in a subspace with dimension 1.\n\t\tThe set $X(a)$ contains all the vectors which are orthogonal to $a$.\n\t\tBy the rank nullity theorem we know that $\\text{rank}(f) + Null(f) = dim(\\mathbb{R}^n)$.\n\t\tHence the dimension of the null space $X(a)$ is $dim(\\mathbb{R}^n) - \\text{rank}(f) = n - 1$.\n\t\t\n\t\tAnother way to look at this is by using what you found in Problem 1 and recognizing that $X(a)$ is a hyperplane in $\\mathbb{R}^n$ passing through the origin.\n\t\tIn Problem 1, you found that a plane in $\\mathbb{R}^3$ passing through the origin had dimension $3-1 = 2$.\n\t\tWell a hyperplane is just a plane, so if $X(a)$ is a hyperplane through the origin in $\\mathbb{R}^n$ it must have dimension $n-1$.\n\t\\end{enumerate}\n\\end{solution}\n\n\\paragraph{Some Definitions}\nThe following definitions describe the ``greater than or equal to'' type of ordering on $\\mathbb{R}^n$ that will be important for answering Problem 3.\n\\begin{definition}\n\tLet $\\mathbf{x}$ and $\\mathbf{y}$ be vectors in $\\mathbb{R}^n$.  We define the following relations:\n\t\\begin{itemize}\n\t\t\\item $\\mathbf{x} = \\mathbf{y}$ iff $x_i = y_i$ for all $i=1,2,\\dots, n$.\n\t\t\\item $\\mathbf{x} \\geq \\mathbf{y}$ iff $x_i \\geq y_i$ for all $i=1,2,\\dots, n$.\n\t\t\\item $\\mathbf{x} > \\mathbf{y}$ iff $x_i \\geq y_i$ and $x\\neq y$ -- meaning there is at least one element $j$ such that $x_j > y_j$.\n\t\t\\item $\\mathbf{x} \\gg \\mathbf{y}$ iff $x_i > y_i$ for all $i=1,2,\\dots, n$.\n\t\\end{itemize}\n\\end{definition}\n\n\\begin{problem}\n\tSuppose $\\mathbf{a},\\mathbf{x},\\mathbf{y} \\in \\mathbb{R}^n$ and $\\mathbf{a}\\cdot \\mathbf{x} > \\mathbf{a} \\cdot \\mathbf{y}$.  Does it follow that $x > y$? [Hint: do not divide both sides by $\\mathbf{a}$]\n\\end{problem}\n\\insblock{Problem 12 Notes}{Tests understanding of linear functions (functionals in particular) and how they can \\textit{order} the vectors in a linear subspace.  It also introduces and provides practice with vector orderings that come up relatively frequently.  Also note that the linear function created by $\\mathbf{a}\\cdot \\mathbf{x}$ for $\\mathbf{x}\\in X$ two \\textit{half-spaces} are created that order some vectors ``above'' others.}\n\\begin{solution}\\\\\n\tLet $\\mathbf{a},\\mathbf{x},\\mathbf{y} \\in \\mathbb{R}^n$ (note these are vectors) and let $\\mathbf{a} \\cdot \\mathbf{x} > \\mathbf{a} \\cdot \\mathbf{y}$.\n\tNote that both $\\mathbf{a}\\cdot \\mathbf{x}$ and $\\mathbf{a}\\cdot \\mathbf{y}$ are real numbers so the $>$ here refers to the ordering on the real line, while the comparison we want to investigate $\\mathbf{x} > \\mathbf{y}$ is an ordering on vectors (as defined before the problem).\n\tLets consider the value $r_y = \\mathbf{a} \\cdot \\mathbf{y}$.\n\tConsider the hyperplane $X(\\mathbf{a},r_y) = \\{ \\mathbf{z} \\in \\mathbb{R}^n: \\mathbf{a} \\cdot \\mathbf{z} = r_y \\}$ and the ``upper'' half-space $X^+(\\mathbf{a},r_y) = \\{ \\mathbf{z} \\in \\mathbb{R}^n: \\mathbf{a} \\cdot \\mathbf{z} \\geq r_y \\}$.\n\tNow we know that $\\mathbf{a}\\cdot \\mathbf{x} > r_y$ so we can be sure $\\mathbf{x} \\in X^+(\\mathbf{a},r_y)$.\n\tLet $Y = \\{ \\mathbf{z} \\in \\mathbb{R}^n: z_i \\geq y_i \\; \\forall i = 1, \\dots, n\\}$ be the set of all vectors $\\mathbf{z}$ such that $\\mathbf{z} \\geq \\mathbf{y}$.\n\tWhen $Y \\subsetneq X^+(\\mathbf{a},r_y)$ then its possible for $\\mathbf{a}\\cdot \\mathbf{x} > \\mathbf{a}\\cdot \\mathbf{y}$ and yet $\\neg (\\mathbf{x} > \\mathbf{y})$.\n\tConsider the two-dimensional graph below.\n\tEach of the points $\\mathbf{x},\\mathbf{x}',\\mathbf{x}''$ are contained in $X^+(\\mathbf{a},r_y)$ yet are not in $Y$.\n\tSo its possible for $\\mathbf{a}\\cdot \\mathbf{x} > \\mathbf{a}\\cdot \\mathbf{y}$ and yet $\\mathbf{x} \\leq \\mathbf{y}$.\n\t\n\t\\begin{figure}[htbp]\n\t\\centering\n\t\\caption{Hyperplanes, Half-spaces and Vector Ordering}\n\t\\begin{tikzpicture}\n\t\t\\draw[<->, thick] (0,4) -- (0,-2);\n\t\t\\draw[<->, thick] (5,0) -- (-2,0);\n\t\t\\node[left] at (0,-1.5) {$x_2$};\n\t\t\\node[above] at (-1.5,0) {$x_1$};\n\t\t\\draw (1.3,1.3) node[anchor=south east] {$\\mathbf{a}$};\n\t\t\\draw[fill=black] (1.5,0.5) circle[radius=1.5pt];\n\t\t\\draw (1.5,0.5) node[above right] {$\\mathbf{y}$};\n\t\t\\draw[fill=black] (1.3,1.3) circle[radius=1.5pt];\n\t\t\\draw[arrows=->,thick] (0,0) -- (1.25,1.25);\n\t\t\\draw[fill=gray, draw=gray, opacity=0.4] (1.5,4) -- (1.5,0.5) -- (5,0.5) -- (5,4);\n\t\t\\draw[dashed, thin] (1.5,0.5) -- (1.5,4);\n\t\t\\draw[dashed, thin] (1.5,0.5) -- (5,0.5);\n\t\t\\node[above] at (3.3,1.5) {$\\{ \\mathbf{z} \\in \\mathbb{R}^2: \\mathbf{z} > \\mathbf{y}\\}$};\n\t\t\\draw[very thick] (-2,4) -- (1,1) -- (4,-2);\n\t\t\\node[right] at (2.95,-0.5) {$X^+(\\mathbf{a},r_y)$};\n\t\t\\node[left] at (2,-1.5) {$X(\\mathbf{a},r_y)$};\n\t\t\\draw[->] (2,-1.5) -- (3,-1);\n\t\t\\draw[pattern=north west lines, pattern color=gray, opacity=0.7,draw=none] (-2,4) -- (1,1) -- (4,-2) -- (5,-2) -- (5,4);\n\t\t\\draw[fill=black] (-1,3.5) circle[radius=1.5pt] node[right] {$\\mathbf{x}$};\n\t\t\\draw[fill=black] (1.3,3) circle[radius=1.5pt] node[left] {$\\mathbf{x}'$};\n\t\t\\draw[fill=black] (4.2,-1.5) circle[radius=1.5pt] node[right] {$\\mathbf{x}''$};\n\t\t\\draw (0.8,1.2) -- (0.6,1) -- (0.8,0.8);\n\t\\end{tikzpicture}\t\n\t\\end{figure}\n \n\t\n\\end{solution}\n\n\\begin{problem}\n\tLet $X$ be a vector space and consider a function $f:X \\rightarrow \\mathbb{R}$ defined for some $\\mathbf{a} \\in X$ defined as $f_a(\\mathbf{x}) = \\mathbf{a} \\cdot \\mathbf{x}$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item Prove that $f_a(\\mathbf{x}) = \\mathbf{a}\\cdot \\mathbf{x}$ is a linear function.\n\t\t\\item Let $X^* = \\{ f:X \\rightarrow R \\; | \\; f \\text{ is linear}\\}$ be the set of all linear functions from $X$ into $\\mathbb{R}$.\n\t\tProve that for all $f \\in X^*$ there exists an $\\mathbf{a}\\in X$ such that $f(\\mathbf{x}) = \\mathbf{a} \\cdot \\mathbf{x}$.\n\t\t\\item (\\textbf{Optional}) Define function addition as $f+g = f(\\mathbf{x})+g(\\mathbf{x})$ and function scaling as $\\alpha f = \\alpha f(\\mathbf{x})$ over the set $X^*$.  Prove or disprove the following statement: $X^*$ \\textit{with the defined operations is a linear vector space}.\n\t\t\\item (\\textbf{Optional}) What is dimension of $X^*$?\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 13 Note}{Tests understanding of the definition of a linear function (mapping, transformation) and how to use it.  Tests understanding of linear functionals and how they can be represented by vectors and the (inner) dot product.  The optional parts are good practice in applying the axioms of abstract vector spaces and identifying dimension.}\n\\begin{solution} \\textbf{and hints...}\n\t\\begin{enumerate}[(i)]\n\t\t\\item So for this problem just assume that $X = \\mathbb{R}^n$.\nThen $a\\cdot x = a_1 x_1 + \\cdots + a_n x_n$.\nGiven two vectors $x,y \\in \\mathbb{R}^n$ and scalars $\\alpha, \\beta \\in \\mathbb{R}$ we have\n\\begin{align}\n\ta \\cdot (\\alpha x + \\beta y) &= a\\cdot (\\alpha x) + a\\cdot (\\beta y) \\nonumber \\\\\n\t&= \\alpha(a\\cdot x) + \\beta (a\\cdot y) \\nonumber \n\\end{align}\ntherefore its a linear map.\n\t\\item For part (ii), this is basically the proof that linear transformations between real vector spaces can be represented by real valued matrices.\nIn this case the matrices will all be $n\\times 1$.\nConsider a function $f\\in X^*$.\nBy definition $f$ is a linear map from $X = \\mathbb{R}^n$ to $\\mathbb{R}$.\nBecause $X$ is a linear subspace and $\\mathbb{R}$ is a linear subspace and $f$ is a linear map we know that $f(X)$ is a linear subspace in $\\mathbb{R}$.\nBecause $X$ and $f(X)$ are subspaces they have a basis.\nLet $(\\mathbf{e}_1,\\dots, \\mathbf{e}_n)$ be the coordinate vectors for $\\mathbb{R}^n$ (which are a basis for $X$).\nThen for any $x\\in X$ we can write $\\mathbf{x} = x_1 \\mathbf{e}_1 + \\cdots + x_n \\mathbf{e}_n$ (a linear combination of the basis vectors).\nApplying our function $f$ to $x$ gives us\n\\begin{align}\n\tf(\\mathbf{x}) &= f( x_1 \\mathbf{e}_1 + \\cdots + x_n \\mathbf{e}_n ) \\nonumber \\\\\n\t&= x_1 f(\\mathbf{e}_1) + \\cdots + x_n f(\\mathbf{e}_n) \\nonumber\n\\end{align}\nSince $\\mathbf{e}_i$, for $i=1,\\dots,n$ is a vector we know $f(\\mathbf{e}_i) \\in \\mathbb{R}$.\nFor all $i = 1,\\dots, n$ define $f(\\mathbf{e}_i) = a_i$.\nThen \n\\begin{align}\n\tf(\\mathbf{x}) &= x_1 a_1 + \\cdots + x_n a_n \\nonumber \\\\\n\t&= a_1 x_n + \\cdots + a_n x_n \\nonumber \\\\\n\t&= \\mathbf{a} \\cdot \\mathbf{x} \\nonumber\n\\end{align}\nso we can define the $\\mathbf{a} = (f(\\mathbf{e}_1), \\dots, f(\\mathbf{e}_n))$.\n\t\\item For part (iii), you should use the defined operations to show that the vector space axioms hold for this set so that its a vector space.\nThe key operations are that if $f$ and $g$ are linear functions in the set, then these will be our vectors.\nSo $f + g$ is defined as $f(x) + g(x)$ where $x$ is a vector in $X$.\nIf $\\alpha$ is a real number, then we scale the vectors in $X^*$ as $\\alpha f = \\alpha f(x)$.\n\nLet $\\mathbf{u},\\mathbf{v},\\mathbf{w} \\in V$  where $V$ is a vector space.\nLet $c,d \\in \\mathbb{R}$.\nThen the following are the axioms of an abstract vector space.\n\t\\begin{enumerate}[1.]\n\t\t\\item $\\mathbf{u} + \\mathbf{v} \\in V$\n\t\t\\item $\\mathbf{u} + \\mathbf{v} = \\mathbf{v} + \\mathbf{u}$\n\t\t\\item $(\\mathbf{u} + \\mathbf{v}) + \\mathbf{w} = \\mathbf{u} + (\\mathbf{v} + \\mathbf{w})$\n\t\t\\item $\\exists \\mathbf{0} \\in V$ such that $\\forall \\mathbf{u} \\in V, \\; \\mathbf{u} + \\mathbf{0} = \\mathbf{u}$\n\t\t\\item $\\forall \\mathbf{u} \\in V, \\; \\exists -\\mathbf{u} \\in V$ such that $\\mathbf{u} + (-\\mathbf{u}) = \\mathbf{0}$\n\t\t\\item $\\forall c \\in \\mathbb{R}$, $c\\mathbf{u} \\in V$.\n\t\t\\item $c(\\mathbf{u} + \\mathbf{v}) = c \\mathbf{u} + c \\mathbf{v}$\n\t\t\\item $(c+d)\\mathbf{u} = c\\mathbf{u} + d \\mathbf{v}$\n\t\t\\item $(cd)\\mathbf{u} = c(d\\mathbf{u})$\n\t\t\\item $1\\mathbf{u} = \\mathbf{u}$\n\t\\end{enumerate}\nAll the axioms should be tested.\n\t\\item For part (iv) the idea is to use what we just learned in part (ii), that every linear functional $f \\in X^*$ can be uniquely determined by a vector $\\mathbf{a} = (f(\\mathbf{e}_1),\\dots,f(\\mathbf{e}_n))$.\nWe can think about finding a set of such $\\mathbf{a}$ vectors.\nFor example suppose we have a set of $n$ vectors, say the coordinate vectors again, $(\\mathbf{e}_1,\\dots, \\mathbf{e}_n)$, do each of these represent their own linear functional? Yes.\nNow that we are calling them functionals, lets represent the set now as $\\{f_1,\\dots, f_n\\}$.\nAt this point we establish that any linear functional is just a linear combination of these $n$ linear functionals and that the set is linearly independent.\nOnce you've done that you will have shown that a set of $n$ vectors is a basis for $X^*$ and therefore $\\dim\\left(X^*\\right) = n$.\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{problem}\n\tProve that the set $Z$ is a subspace of $\\mathbb{R}^3$.\n\t\\[\n\t\tZ = \\left\\{ [x_1,x_2,x_3] \\; | \\; 4x_1 - x_2 + 5x_3 = 0 \\right\\}\n\t\\]\n\\end{problem}\n\\insblock{Problem 14 Note}{Tests application of the definition of subspaces.}\n\\begin{solution}\n\tLet $a = [4,-1,5]$ and note that the equation in the definition of $Z$ is $4x_1 - x_2 + 5x_3 = a \\cdot x$.  \n\tHence we have the linear function $L(x) = a\\cdot x$ and $a\\cdot x = 0$ represents a homogenous system of equations.\n\tThe set $Z$ represents the set of solutions $\\{x \\in \\mathbb{R}^3 | a\\cdot x = 0\\}$ which is also the null space of the linear function $L(x) = a\\cdot x$.\n\tThe null space of any linear function is a subspace. \\qedsymbol\n\\end{solution}\n\n\n\\begin{problem}\n%Leon Ch 4 Section 1 # 17\nDetermine the null space and range of each of the following linear operators on $\\mathbb{R}^3$.\n\\begin{enumerate}[(i)]\n\t\\item $L(\\mathbf{x}) = (x_3,x_2,x_1)^T$\n\t\\item $L(\\mathbf{x}) = (x_1,x_1,x_1)^T$\n\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 15 Note}{Tests understanding of the definition and concept of null space (kernal) and range (column space) of a linear operator (matrix).}\n\\begin{solution}\n\t\\begin{enumerate}[(i)]\n\t\t\\item $Null(L) = \\{\\mathbf{0}\\}$ and $L(\\mathbb{R}^3) = \\mathbb{R}^3$.\n\t\t\\item $Null(L) = \\text{Span}(\\mathbf{e}_2,\\mathbf{e}_3)$ and $L(\\mathbb{R}^3) = \\text{Span}(\\mathbf{e}_1)$.\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{definition}\n\tLet $X$ be a vector space and let $a \\in X$ and $b \\in \\mathbb{R}$.\n\tA \\textbf{hyperplane} in $X$ is a set of the form $H_a(b) = \\{ x \\in X: a\\cdot x = b\\}$ and associated with hyperplane $X$ are two \\textbf{half-spaces} $H_a^{\\geq}(b) = \\{x\\in X: a\\cdot x \\geq b \\}$ and $H_a^{\\leq}(b) = \\{x\\in X: a\\cdot x \\leq b\\}$.\n\\end{definition}\n\n\\begin{problem}\n\t(\\textbf{Optional}) What are the range of angles between vectors in $x \\in H_a^{\\leq}(0)$ and the vector $a$? What are the ranges of the angles between vectors $x\\in H_a^{\\geq}(0)$ and the vector $a$?\n\\end{problem}\n\\insblock{Problem 16 Note}{Tests knowledge and understanding of the Cauchy-Schwartz inequality, the dot product and their relationship to the angle between two vectors in a vector space.  It connects this concept to that of half-spaces.}\n\\begin{solution}\n\tFor $H_a^{\\geq}(0)$ the range on the angles between vectors $x$ and the vector $a$ are $\\theta = [0,90]\\cup [270,360]$ and the range on the angles between vectors $x$ in $H_a^{\\leq}(0)$ and $a$ are $\\theta = [90,270]$.\n\\end{solution}\n\n\\begin{problem}\n%Simon & Blume exercise 27.19\n\tWhich of the following are \\emph{subspaces} of the vector space $M_{2,2}$ of $2\\times 2$ matrices? Justify your answer.\n\t\\begin{enumerate}[(i)]\n\t\t\\item the set of $2\\times 2$ real symmetric matrices.\n\t\t\\item the set of $2\\times 2$ real diagonal matrices.\n\t\t\\item the set of $2\\times 2$ real ``singular'' matrices (remember $M$ is singular if $det(M) = 0$).\n\t\t\\item the zero matrix.\n\t\t\\item the set of all $2\\times 2$ nonsingular matrices\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 17 Note}{More practice applying definition of subspaces to spaces of specific matrices to show which are subspaces.}\n\\begin{solution}\n\t\\begin{enumerate}[(i)]\n\t\t\\item \\begin{align}\n\t\t\t\\alpha \\left[\\begin{matrix}\n\t\t\t\ta_{11} & a_{12} \\\\\n\t\t\t\ta_{12} & a_{22}\n\t\t\t\\end{matrix}\\right] +\n\t\t\t\\beta \\left[\\begin{matrix}\n\t\t\t\tb_{11} & b_{12} \\\\\n\t\t\t\tb_{12} & b_{22}\n\t\t\t\\end{matrix}\\right] = \n\t\t\t\\left[\\begin{matrix}\n\t\t\t\t\\alpha a_{11} + \\beta b_{11} & \\alpha a_{12} + \\beta b_{12} \\\\\n\t\t\t\t\\alpha a_{12} + \\beta b_{12} & \\alpha a_{22} + \\beta b_{22} \n\t\t\t\\end{matrix}\\right] \\nonumber\n\t\t\\end{align}\n\t\\item \\begin{align}\n\t\t\t\\alpha \\left[\\begin{matrix}\n\t\t\t\ta_{11} & 0 \\\\\n\t\t\t\t0 & a_{22}\n\t\t\t\\end{matrix}\\right] +\n\t\t\t\\beta \\left[\\begin{matrix}\n\t\t\t\tb_{11} & 0 \\\\\n\t\t\t\t0 & b_{22}\n\t\t\t\\end{matrix}\\right] = \n\t\t\t\\left[\\begin{matrix}\n\t\t\t\t\\alpha a_{11} + \\beta b_{11} & 0 \\\\\n\t\t\t\t0 & \\alpha a_{22} + \\beta b_{22} \n\t\t\t\\end{matrix}\\right] \\nonumber\n\t\t\\end{align}\n\t\t\\item This space is not a subspace.\n\t\tConsider the matrices \n\t\t\\[\n\t\t\tA = \\left[\\begin{matrix}\n\t\t\t\t1 & 0 \\\\\n\t\t\t\t0 & 0\n\t\t\t\\end{matrix}\\right] \\qquad\n\t\t\tB = \\left[\\begin{matrix}\n\t\t\t\t0 & 0 \\\\\n\t\t\t\t0 & 1\n\t\t\t\\end{matrix}\\right]\n\t\t\\]\n\t\tThe $\\det A = 0$ and $\\det B = 0$, but $\\det(A + B) = \\det(I) = 1 \\neq 0$.\n\t\t\\item Yes it is a subspace as any linear combination of it is the zero matrix.\n\t\t\\item Note that $\\det I = 1 \\neq 0$ and $\\det(-I) = (-1)^2 \\det I = 1 \\neq 0$ but $I + (-I) = 0$ and the zero matrix is not invertible.\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{problem}\n\tLet $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ be a linear function such that for all $y \\in \\mathbb{R}^m$ the set $\\{x \\in \\mathbb{R}^n : f(x)=y\\}$ is a singleton.\n\t\\begin{enumerate}[(i)]\n\t\t\\item Is the linear function $f$ invertible?\n\t\t\\item If $f$ can be represented by matrix $A$, then show $A$ is invertible if and only if $\\text{rank}(A) = m = n$.\n\t\t\\item Suppose that an $n\\times n$ matrix $A$ is invertible.  Does it follow that $[Ax = 0] \\implies [x = 0]$?\n\t\t\\item Suppose that $A$ is an $n \\times n$ matrix and that $[Ax=0]\\implies [x=0]$.\n\t\tDoes it follow that $A$ is invertible?\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 18 Note}{Tests understanding of the requirements for the existence of an inverse function and its relationship to matrix inverses in the case of linear functions.  These concepts are then tied to some fundamental properties about the existence and uniqueness of the solution to a system of linear equations.}\n\\begin{solution}\n\\begin{enumerate}[(i)]\n\t\\item Yes, the function is a bijection and so the inverse correspondence will be a function.\n\t\\item ($\\Leftarrow$) Suppose that $\\text{rank}(A)=m=n$ and assume to the contrary that $A$ is not invertible.\n\tThen there must exist $y,x,x' \\in \\mathbb{R}^n$ with $x\\neq x'$ such that $y=Ax=Ax'$.\n\tBut this means that $A(x-x')=0$ with $(x-x')\\neq 0$ and thus the columns of $A$ are linearly dependent. This means there can be, at most, $n-1$ linearly independent columns making the rank of $A$ less than $n$ - which is a contradiction.\n\t\n\t($\\Rightarrow$) For the other direction, we can use proof by contrapositive.\n\tSo assume $\\text{rank}(A) \\neq n$ and attempt to show that this implies $A$ is not invertible.\n\tSince $\\text{rank}(A) \\leq \\dim \\mathbb{R}^n = n$ we know $\\text{rank}(A) < n$.\n\tWhich means that the number of linearly independent columns of $A$ is less than $n$.\n\tLet $\\mathbf{a}_1, \\dots, \\mathbf{a}_n$ represent the $n$ columns of $A$.\n\tThen $\\exists \\boldsymbol{\\alpha} = (\\alpha_1, \\dots, \\alpha_n) \\neq \\mathbf{0}$ such that $\\alpha_1 \\mathbf{a}_1 + \\cdots + \\alpha_n \\mathbf{a}_n = \\mathbf{0}$ which is equivalent $A \\boldsymbol{\\alpha} = \\mathbf{0}$ so $Null(A)$ contains more elements than just the zero vector $\\mathbf{0}$.\n\tSince multiple elements are mapped to the same vector, the function $f$ represented by $A$ is not injective and therefore not bijective and thus not invertible. \\qedsymbol\n\t\\item Let $A$ be invertible and for some vector $\\mathbf{x}$ suppose $A\\mathbf{x} = \\mathbf{0}$.\n\tThen\n\t\\begin{align}\n\t\tA\\mathbf{x} &= \\mathbf{0} \\nonumber \\\\\n\t\tA^{-1} A \\mathbf{x} &= A^{-1} \\mathbf{0} \\nonumber \\\\\n\t\tI_{n} \\mathbf{x} &= \\mathbf{0} \\nonumber \\\\\n\t\t\\mathbf{x} &= \\mathbf{0} \\nonumber\n\t\\end{align}\n\twhich establishes the result. \\qedsymbol\n\t\\item Let $A$ be an $n\\times n$ matrix such that $Null(A) = \\{\\mathbf{0}\\}$.\n\tLet $\\mathbf{u} \\neq \\mathbf{v}$ be two nonzero vectors.\n\tSuppose $A \\mathbf{u} = A \\mathbf{v}$ then $A \\mathbf{u} - A \\mathbf{v} = \\mathbf{0}$ and finally $A(\\mathbf{u} - \\mathbf{v}) = \\mathbf{0}$.\n\tBut $(\\mathbf{u}-\\mathbf{v})\\neq \\mathbf{0}$ which is impossible since only $\\mathbf{0}$ is in the null space of $A$.\n\tThis contradiction implies that $A$ is injective.\n\tBy the rank nullity theorem we have $\\dim \\mathbb{R}^n = \\dim Null(A) + \\dim \\text{img}(A)$ and since $\\dim Null(A) = 0$ we have $n = 0 + \\dim \\text{img}(A)$ which implies $\\dim \\text{img}(A) = n$.\n\tThis means the image of $A$ ( or of $f$) fills all of $\\mathbb{R}^n$ and $A$ is surjective.\n\tBecause it is injective and surjective $A$ is invertible. \\qedsymbol \n\\end{enumerate}\n\\end{solution}\n\n\\begin{problem}\n\tLet $y\\in \\mathbb{R}^n$ be a \\textbf{netput} vector where each element $y_i$ for $i=1,\\dots, n$ is a commodity.\n\tIf $y_i < 0$ then $y_i$ is an input into a production process.\n\tIf $y_i > 0$ then $y_i$ is an output of the production process.\n\tLet $F:\\mathbb{R}^n \\rightarrow \\mathbb{R}$ be a \\emph{transformation function} and we define the set $Y =\\{y\\in \\mathbb{R}^n : F(y) \\leq 0 \\}$ and we'll call $Y$ a technology.\n\tThe technology $Y$ describes all the feasible production plans a firm can choose (i.e., combinations of feasible inputs and outputs).\n\tWe will assume that $Y$ is a convex set.\n\tNow let $p\\in \\mathbb{R}^n$ where $p \\gg 0$ be vector prices for the $n$ commodities in any bundle $y\\in Y$.\n\tNote that for fixed $p$, we can define a function $T_p(y) = p\\cdot y$ for all $y \\in Y$.\n\tThe function $T_p(y)$ represents the profit (revenue minus costs) of choosing production plan $y$ when input and output prices are given by $p$.\n\tFirms want to choose some feasible production plan $y^*$ that satisfies $T_p(y^*) = \\max\\{p\\cdot y: y\\in Y\\}=\\pi(p)$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item If $\\pi(p)$ is the maximum achievable profit for firms given technology $Y$ and prices $p$ the profit-maximizing production plans are $\\{ y \\in Y: p\\cdot y = \\pi(p) \\}$. Now consider the set $\\{y \\in \\mathbb{R}^n: p\\cdot y = \\pi(p)\\}$. Is this a hyperplane?  If so, show that $Y$ is contained in one of the half-spaces of $p\\cdot y = \\pi(p)$ and specify which one (i.e., upper or lower).\n\t\t\\item Does the set $\\{y\\in \\mathbb{R}^n: p\\cdot y = \\pi(p)\\}$ ``touch'' the technology $Y$? i.e, is it the case that\n\t\t\\[\n\t\t\t\\min_{y\\in Y}\\; | p\\cdot y - \\pi(p)| = 0\n\t\t\\]\n\t\tIf so, what does this say about the value of $F(y^*)$ for any $y^* \\in \\{y\\in Y: p\\cdot y = \\pi(p)\\}$?\n\t\t\\item \\textbf{Optional} (Duality) Consider the sets of the form $A(p) = \\{ y \\in \\mathbb{R}^n : p\\cdot y \\leq \\pi(p)\\}$ and we create a collection of sets $\\{ A(p) \\subset \\mathbb{R}^n : p \\in \\mathbb{R}^n\\}$.\n\t\tShow that the following equality is true.\n\t\t\\[\n\t\t\tY = \\bigcap_{p\\in \\mathbb{R}^n} A(p)\n\t\t\\]\n\t\\end{enumerate}\n\\end{problem}\n\\insblock{Problem 19 Note}{Application of key concepts you've been working on.  In particular the idea of the support function (which is a linear functional) and how it relates to the profit to the firm of a particular production plan.  This function creates half-spaces and the hyperplane can be tangent to a curve representing optimal points.  If this problem is difficult don't worry it is some of the more difficult concepts you'll see in the fall micro class.}\n\\begin{solution}\n\tSee the hints I provided through email.\n\\end{solution}\n\n\n\\end{document}", "meta": {"hexsha": "3e311d318b44be5d4ad280f658f9ddf6848a6eea", "size": 31847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/pdfs/math_bootcamp/bootcamp_repo/assignment_1/assignment_1.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_1/assignment_1.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": "pages/teaching/math_bootcamp/assignment_1/assignment_1.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": 50.7926634769, "max_line_length": 465, "alphanum_fraction": 0.655226552, "num_tokens": 11666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.6430580016358943}}
{"text": "\\setcounter{section}{7}\n\\setcounter{subsection}{0}\n\\subsection{Bifunctors}\n\nWe start by studying if ADTs form functors. Product type in haskell is\nactually a type constructor of two argument. \\ie. \\code{(a,b)} can be written as\n\\code{(,) a b}.\n\nIt's not hard to see that \\code{(,) a}, \\ie. fix on one parameter \\code{a}, is a\nfunctor from \\code{b} to \\code{(a, b)}.\n\n\\begin{center}\n\\begin{tikzcd}[math mode=false, sep=large]\n  \\code{(e,x)} \\rar{\\code{fmap f}} & \\code{(e,y)} \\\\\n  \\code{x} \\uar{\\code{(e,)}} \\rar{\\code{f}} & \\code{y} \\uar{\\code{(e,)}}\n\\end{tikzcd}\n\\end{center}\n\nNow think, why don't we make a functor type that has two arguments, so we can\nmake \\code{(,)} a functor on both arguments. In math, we could try to define a\ncategory that formalize product of two categories instead of inventing a\nsomething new, like a new kind of functor, for that purpose. But what will this\ncategory look like? Well it's basically just product of the hom sets. For\ncategories $C$ and $D$, we define $C \\times D$ as follows:\n\n\\begin{itemize}\n\\item For each pair of objects $c\\in C$ and $d\\in D$, there is an object $(c,d)\n  \\in C\\times D$;\n\\item For each pair of arrows $f=c\\mapsto c'$ in $C$ and $g\n  = d\\mapsto d'$ in $D$, there is an arrow $(f, g)=(c,d)\\mapsto (c',d')$ in $C\\times D$;\n\\item Composition: $(f', g') \\circ (f, g) = (f'\\circ f, g'\\circ g)$;\n\\item Identity: $\\id_{(a,b)}=(\\id_a, \\id_b)$.\n\\end{itemize}\n\nSo the functor that takes two arguments is just a functor $C\\times\nD \\to E$. This kind of functors is called a bifunctor.\n\nIn Haskell, bifunctor is defined as:\n\n\\begin{lstlisting}\nclass Bifunctor b where\n  bimap :: (a -> a') -> (b -> b') -> f a b -> f a' b'\n\\end{lstlisting}\n\nAnd this is how \\code{(,)} (product) and \\code{Either} (sum) implemented as\nbifunctors:\n\n\\begin{lstlisting}\ninstance Bifunctor (,) where\n  bimap f g (a,b) = (f a, g b)\n\ninstance Bifunctor Either where\n  bimap f g (Left a)  = Left (f a)\n  bimap f g (Right a) = Right (g a)\n\\end{lstlisting}\n\nIn a cartesian category $C$, in which there are products for every pair of\nobjects, then this ``product'' is a bifunctor $C\\times C \\to C$. This also\napplies to ``co-product'' categories. Here's how it works:\n\n\\begin{center}\n\\begin{tikzcd}[sep=large]\n  & a \\times b \\ar{ld}[below]{\\pi_1} \\ar{rd}[below]{\\pi_2} & \\\\\n  a \\ar{dd}{f} & & b \\ar{dd}{g} \\\\\n  & a' \\times b' \\ar{ld}{\\pi_1'} \\ar{rd}[below]{\\pi_2'} & \\\\\n  a' & & b'\n\\end{tikzcd}\n\\end{center}\n\nSo we have this diagram. For each $a, b \\in C$, by definition, we have its\nproduct $a\\times b$ which projects ($\\pi_1, \\pi_2$) to $a$ and $b$. And for the\nmorphisms, we have \\cd{a \\rar{f} \\& a'} and \\cd{b \\rar{g} \\& b'}. In order for\nthe product ($\\times : C\\times C \\to C$), to be a bifunctor, we need to show it\nis possible to lift the pair $f, g$ into something that \\cd[normal]{a\\times b\n  \\rar{f\\times g} \\& a' \\times b'}. \\ie there exists a morphism from $a\\times b$\nto $a'\\times b'$ on the diagram above.\n\n\\begin{center}\n\\begin{tikzcd}[sep=large]\n  & a \\times b\n  \\ar{ld}[below]{\\pi_1} \\ar[red]{lddd}[left]{f \\circ \\pi_1}\n  \\ar{rd}[below]{\\pi_2} \\ar[red]{rddd}[right]{g \\circ \\pi_2}\n  \\ar[dashed]{dd}[below]{f\\times g}\n  & \\\\\n  a \\ar{dd}{f} & & b \\ar{dd}{g} \\\\\n  & a' \\times b' \\ar{ld}{\\pi_1'} \\ar{rd}[below]{\\pi_2'} & \\\\\n  a' & & b'\n\\end{tikzcd}\n\\end{center}\n\nHere's how we show that. Since we have $\\pi_1$ and $f$, they will compose into\n$f \\circ \\pi_1$, same for $\\pi_2$ and $g$. By definition of the univeral\nconstruction of products, we can see that $a'\\times b'$ is the product on $a'$\nand $b'$. Therefore, there must exist a unique factorialization from any pair\n$a\\times b$ to $a'\\times b'$ (shown as the dashed arrow). This morphism is what\nwe are looking for and therefore we have shown the existence of $\\times$\nbifunctor.\n\nIn haskell, this is not an issue. As the implementation above, we just apply $f$\nto $a$ and $g$ to $b$, then we will form $(f~a, g~b)$. But this is not enough\ngeneral for Math, we need to think out of just the $\\Hask$ category. So the\nabove diagram shows how it work generally in any category.\n", "meta": {"hexsha": "05f2e48ad1205bd909871c0e527ef9eb625915f4", "size": 4067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "milewski-cat/chap7.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/chap7.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/chap7.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": 39.4854368932, "max_line_length": 88, "alphanum_fraction": 0.6560118023, "num_tokens": 1442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.6430579940077799}}
{"text": "\\section{Introduction}\n\\begin{frame}{\\insertsec}\n\tNeural Networks are a type of supervised learning. So we have a set of labeled data:\n\t$$\\{(x^{(1)}, y^{(1)}), (x^{(2)}, y^{(2)}), ..., (x^{(m)}, y^{(m)})\\}$$\n\t\n\tWe want to use it to predict new data $\\hat{y} = f(x)$\n\t\n\t\\textbf{Problem}: search the proper $f(x)$\n\\end{frame}", "meta": {"hexsha": "508dbd05ec11cca9949d726941ef9b0fbc91066f", "size": 323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LATEX/CNN Presentation/sections/01_introduction.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/01_introduction.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/01_introduction.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": 35.8888888889, "max_line_length": 85, "alphanum_fraction": 0.5882352941, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.64305798803618}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\\theoremstyle{remark}\n\\newtheorem*{remark}{Remark}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\section{On a special intersection graph of class 2}\nOur interest here is to find a graph of class 2 with $\\Delta = 3$ and $\\omega = 2$. Moreover, we want to ask ourselves if such a graph can be an intersection graph\nof squares, and an intersection graph of unit squares.\\\\\nLet's take a look at the following graph:\n\n\\begin{figure}[h]\n    \\centering\n    \\caption{Graph $G$ used as a base.}\n    \\includegraphics[scale=0.5]{tex_images/8cube.png}\n\n\\end{figure}\n\n\\begin{lemma}\n    A graph obtained by replacing an edge of $G$ by a vertex of degree 2 is not 3-edge colorable.\n\\end{lemma}\n\n\\begin{proof}\n    Notice that the previous embedding of $G$ is consisting of two rectangles, one inside the other, with edges linking the cornes. \n    Call $a, b, c, d$ the corners of the inner rectangle, and $A, B, C, D$ the corner of the outer rectangle.\\\\\n    The edges we consider are the obvious $ab, bc, cd, da$ (same for capitals) and the $aA$ (same for other letters.).\\\\\n    Then we obtain an other graph, $G^'$ by supressing $AB$, adding a vertex $O$, then adding two edges: $AO$ and $OB$.\\\\\n\n    \\begin{figure}[h]\n        \\centering\n        \\includegraphics[scale=0.4]{tex_images/Gprime_uncolored.png}\n    \\end{figure}\n\n    We start by coloring the 5-cycle $AOBba$. Without loss of generality, consider that a 3-coloring of it uses two times colors 1 and 2, and one time color 3. Consider the three following cases:\n    \\begin{itemize}\n        \\item 1. color 3 is on the $AO$ edge.\n        \\item 2. color 3 is on the $ab$ edge.\n        \\item 3. color 3 is on the $Aa$ edge. testestest\n    \\end{itemize}\n\n    \\textbf{\\underline{case 1:}} \\\\\n    Suppose $Aa$ is in color 1 and $AO$ is in 3.  . Then, by trying to use only 3 colors you end up with, in the following order: \\\\\n    $ad$ 3; $bc$ 3; $BC$ 3; $AD$ 2; $Dd$ 1. Then you are forced to color $DC$ in a 4th color. \\\\\n\n    \\begin{figure}[h]\n        \\centering\n        \\caption{Case 1: we end up needing a 4th color.}\n        \\includegraphics[scale=0.3]{tex_images/case_1_1.png}\n        \\includegraphics[scale=0.3]{tex_images/case_1_2.png}\n    \\end{figure}\n\n    \\textbf{\\underline{case 2:}} \\\\\n    Suppose $Aa$ is in color 1. Then you must color in the following order: \\\\\n    $ad$ 2; $AD$ 3; $Dd$ 1; $dc$ 3; $bc$ 1; $cC$ 2. Then you have to use a 4th color for $Dd$.\\\\\n\n    \\textbf{\\underline{case 3:}} \\\\\n    Suppose $Aa$ is in 3 and $ab$ is in 1. The coloring order is:\\\\\n    $ad$ 2; $bc$ 3; $dc$ 1; $Dd$ 3; $Cc$ 2; $DC$ 1. Then a 4th color is necessary for $BC$ and $AD$. \n\n    \n\\end{proof}\n\n\n\\newpage\n\n\\subsection{Case of squares intersection graph}\n\\begin{lemma}\n    $G^'$ can be the intersection graph of axis parralel squares.\n\\end{lemma}\nObserve an example of such a graph:\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4]{tex_images/8cube+_as_squares.png}        \n\\end{figure}\n\n\n\n\\subsection{Case of unit squares intersection graph}\n\n\\begin{definition}[direction of an intersection for unit squares]\n    We say that a square $a$ intersect $b$ in the direction \"UL\" if the upper-left corner of $a$ lies in $b$. \n    Consequently, it would means $b$ intersect $a$ in the \"DR\" direction. There is 4 different directions: \"UL\", \"UR\", \"DR\", \"DL\"\n\\end{definition}\n\n\\begin{remark}\n    Right now, we will suppose that a square $a$ can't intersect a square $b$ in two adjacent directions (see definition 1.2) at the same time. \n    Later we will prove that in the case of our problem, this is not possible: see lemma 1.5.\n\\end{remark}\n\n\\begin{lemma}\n    If $a$ intersect $b$ in a direction and $a$ intersect $c$ in the same direction, then $b$ and $c$ must intersect. \n\\end{lemma}\n\n\\begin{remark}\n    Thus, if $a$ intersect $b$ in a direction, and $a$ intersect $c$; such that $b$ and $c$ do not intersect, then the intersection of $a$ and $c$ must be in a different direction.\n\\end{remark}\n\n\\begin{lemma}\n    Let $a$ and $b$ two unit squares with affixes respectively $z_a$ and $z_b$ and $p_x, p_y$ the projections on axis $x, y$. Then:\n    \\begin{center}\n        $a \\cap b = \\emptyset \\Leftrightarrow (|p_x(z_a) - p_x(z_b)| > 1)$ or $(|p_y(z_a) - p_y(z_b)| >1)$\n\n    \\end{center}\n\\end{lemma}\n\n\n\\begin{proof}\n    Trivial.\n\\end{proof}\n\n\\begin{definition}[adjacent directions]\n    $a$ intersect $b$ and $c$ in distinct adjacent directions if the corners of $a$ that are inside $b$ and $c$ lies on an edge of $a$. \n    For instance, UR and DL are not adjacent directions.    \n\\end{definition}\n\n\\begin{lemma}\n    If $a$ intersect $b$ in direction UL and $c$ in directions UR and DL at the same time, then:\n    \\begin{center}\n        $\\forall d$ such that $d \\cap b \\ne \\emptyset$ and $d \\cap c \\ne \\emptyset \\Rightarrow d \\cap a \\ne \\emptyset$\n    \\end{center} \n\\end{lemma}\n\n\\begin{proof}\n    As $a$ and $c$ share $a$'s upper and down right corners, the only possibility for $d$ and $c$ to intersect without $d$ intersection $a$\n    would be that $c$ interest $d$ in direction UL or DL. Applying lemma 1.4 on $d$ and $c$ on axis $x$ and noticing that $p_x(z_c) < p_x(z_d)$ would give us\n    that $p_x(z_b) < 1 + p_x(z_d)$, ie $d \\cap b = \\emptyset$.\n\\end{proof}\n\n\\begin{remark}\n    This implies that in an intersection graph of unit squares that is a $C_4$, we can't find two squares with one having two of it's corners inside the other.  \n\\end{remark}\n\n\n\n\\begin{lemma}\n    Let $G$ be $C_4$, an intersection graph of unit squares. Then; $\\forall v \\in V(G)$, $v$ intersects it's neighbours in adjacent directions.\n\\end{lemma}\n\n\n\n\\begin{proof}\n    Let $p_x$ and $p_y$ the projections on respectively $x$ and $y$ axis.\\\\\n    Let $a, b, c$ and $d$ be unit squares such that their corresponding intersection graph is $C_4$. Without loss of generality, suppose \n    that $a$ intersect $b$ in direction UR and $a$ intersect $d$ in direction DL. \\\\ \n    Call $z_a, z_b, z_c$ and $z_d$ the affixes of the center of the squares.\n    \\begin{figure}[h]\n        \\centering\n        \\includegraphics[scale=0.4]{tex_images/proof_1_4_1.png}\n    \\end{figure}\n    \\\\\n    If $c$ intersect $d$ in direction DL, then $a, c$ and $d$ would share a common point in the upper right corner of $d$, contradicting the fact we have $C_4$.\\\\\n    Suppose $c$ intersect $d$ in a direction different than DL such that $a$ and $c$ share no common point; then $c \\cap b = \\emptyset$, and we shall prove this using projections.\n    As $a$ and $c$ share no commont point, in at least one of the projections, we must have an empty intersection. Call it $p$.\n    Thus, we have $p(z_c) < 1 + p(z_a)$.\n    as $a$ intersect $b$ in UR direction, then $p_x(z_a) < p_x(z_b)$ and $p_y(z_a) < p_y(z_b)$.\n    By transitivity; we must have $p(z_c) < 1+ p(z_b)$; or, in other words; $c \\cap b = \\emptyset$.\n\\end{proof}\n\n\\begin{theorem}\n    $G^'$ can't be a intersection graph of unit squares.\n\\end{theorem}\n\n\\begin{proof}\n    We will actually prove that a subgraph of $G^'$ can't be done with unit squares. Let $G^{''}:=G'[U]$ with $U := \\{a, b, d, c, C, D, A\\}$\n    The proof is done by trying to construct the squares according to the edges of $G''$.\\\\\n    First, place $d$. It belongs to three cycles of size 4 at the same time through it's three neighbours: $a, c$ and $D$. Suppose, without loss of generality,\n    that $d$ intersect $a$ in direction UL; then $d$ must intersect $D$ in direction either DL or UR in order to complete the cycle $daAD$. For the same reason,\n    $d$ must intersect $c$ in direction either DL or UR to complete $dcCD$. Thus, completing the cycle $abcd$ becomes impossible as $d$ is intersecting $a$ and $c$\n    in non-adjacent directions. \n\\end{proof}\n\n\n\n\\end{document}", "meta": {"hexsha": "ce95fed703d075e6928ae5e69c312104bec2ce1f", "size": 7902, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/counterexample/counterexample.tex", "max_stars_repo_name": "Qiselong/Internship-GSCOP21", "max_stars_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_stars_repo_licenses": ["MIT"], "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/counterexample/counterexample.tex", "max_issues_repo_name": "Qiselong/Internship-GSCOP21", "max_issues_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_issues_repo_licenses": ["MIT"], "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/counterexample/counterexample.tex", "max_forks_repo_name": "Qiselong/Internship-GSCOP21", "max_forks_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_forks_repo_licenses": ["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.1803278689, "max_line_length": 195, "alphanum_fraction": 0.6699569729, "num_tokens": 2491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.6430579878917444}}
{"text": "\\hypertarget{group__numpp__differentiation__symbolic}{}\\section{Symbolic Differentiation}\n\\label{group__numpp__differentiation__symbolic}\\index{Symbolic Differentiation@{Symbolic Differentiation}}\n\n\nThis module provides the means for performing symbolic differentiation.  \n\n\n\\subsection*{Classes}\n\\begin{DoxyCompactItemize}\n\\item \nclass \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, Order $>$}\n\\begin{DoxyCompactList}\\small\\item\\em Allows differentiation of N-\\/th order. \\end{DoxyCompactList}\\item \nclass \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1constant}{numpp\\+::differentiation\\+::symbolic\\+::constant$<$ Value $>$}\n\\begin{DoxyCompactList}\\small\\item\\em Class representing constant integer number. \\end{DoxyCompactList}\\item \nclass \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{numpp\\+::differentiation\\+::symbolic\\+::variable$<$ T, Number $>$}\n\\begin{DoxyCompactList}\\small\\item\\em Class representing variable of any type. \\end{DoxyCompactList}\\end{DoxyCompactItemize}\n\\subsection*{Typedefs}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_gac865497d2896f51d0cab2e9c64799a15}\\label{group__numpp__differentiation__symbolic_gac865497d2896f51d0cab2e9c64799a15}} \n{\\footnotesize template$<$std\\+::size\\+\\_\\+t Number$>$ }\\\\using \\hyperlink{group__numpp__differentiation__symbolic_gac865497d2896f51d0cab2e9c64799a15}{numpp\\+::differentiation\\+::symbolic\\+::x} = \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{variable}$<$ double, Number $>$\n\\begin{DoxyCompactList}\\small\\item\\em Convenience alias for variable with specified variable type as double. \\end{DoxyCompactList}\\end{DoxyCompactItemize}\n\\subsection*{Functions}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga186ca63e28a816d1cb9c8175c7839468}{numpp\\+::differentiation\\+::symbolic\\+::log} (const T \\&)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_gad414fd158986bf7fff7e258a6ebf182c}{numpp\\+::differentiation\\+::symbolic\\+::cos} (const T \\&)\n\\end{DoxyCompactItemize}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename Left , typename Right $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga45bd7508b366431d72157d0f1ef6fac2}{numpp\\+::differentiation\\+::symbolic\\+::operator+} (const Left \\&, const Right \\&)\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga4aecf7125ae67f3c834ed8ab5e14248a}{numpp\\+::differentiation\\+::symbolic\\+::operator-\\/} (const T \\&)\n\\item \n{\\footnotesize template$<$typename Left , typename Right $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga0f6f3d22e3e712ce154f7f6c91e0cf46}{numpp\\+::differentiation\\+::symbolic\\+::operator$\\ast$} (const Left \\&, const Right \\&)\n\\item \n{\\footnotesize template$<$typename Left , typename Right $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_gac882bc2dcbffae1107c46bc3eac93a44}{numpp\\+::differentiation\\+::symbolic\\+::operator/} (const Left \\&, const Right \\&)\n\\item \n{\\footnotesize template$<$std\\+::size\\+\\_\\+t N, typename Left $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_gaa52e3714ea3492f60c68cdb4974fe495}{numpp\\+::differentiation\\+::symbolic\\+::pow} (const Left \\&)\n\\end{DoxyCompactItemize}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga4bcf2dcdbc549b58c9fb7cd1b8c1cf70}{numpp\\+::differentiation\\+::symbolic\\+::exp} (const T \\&)\n\\end{DoxyCompactItemize}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__differentiation__symbolic_ga49ba3eed5ff463e79a88f4952f73f435}{numpp\\+::differentiation\\+::symbolic\\+::sin} (const T \\&)\n\\end{DoxyCompactItemize}\n\n\n\\subsection{Detailed Description}\nThis module provides the means for performing symbolic differentiation. \n\n\n\\begin{DoxyCode}\n\\hyperlink{namespacenumpp}{numpp}/differentiation/symbolic.hpp #includes every method in the module\n\\hyperlink{namespacenumpp}{numpp}/differentiation/symbolic/SUBCLASS.hpp #include specific SUBCLASS\n\\end{DoxyCode}\n\n\n\\begin{DoxyWarning}{Warning}\n{\\bfseries Second include option S\\+H\\+O\\+U\\+L\\+DN\\textquotesingle{}T be used}\n\\end{DoxyWarning}\nIdea developed independently, but merged with the research paper \\href{https://arxiv.org/abs/1705.01729}{\\tt Compile Time Symbolical Differentiation 2017} and many ideas based on theirs. ~\\newline\n{\\bfseries Thank you for this paper, most of the credits belong to them! Please refer to their paper for thourough speed comparison against automatic differentiation.}\n\nFor differences mine and theirs application of the type differentiation see this paper\\+: \\href{https://github.com}{\\tt numpp dissertation } ~\\newline\n For comparison against \\href{https://github.com/symengine/symengine}{\\tt symengine}, base of \\href{http://www.sympy.org/en/index.html}{\\tt Sym\\+Py} see these tests\\+: \\href{https://github.com}{\\tt sympy vs numpp }\n\n{\\bfseries Details and usage\\+:}\n\nOverloads for common mathemathical operations are provided (details in classes).~\\newline\nApproach taken by type differentiating doesn\\textquotesingle{}t resemble well-\\/known symbolic differentiation in C++, hence some examples are needed\\+:\n\n\\begin{DoxyWarning}{Warning}\nFor convenience, in the following examples, namespace numpp\\+::differentiation\\+::symbolic is abbreviated as nds.\n\\end{DoxyWarning}\n{\\bfseries 1. Variables and constants }\n\nBasing building blocks of the function. Can be defined as follows\\+: \n\\begin{DoxyCode}\n\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<0>} x0\\{\\};\n\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<1>} x1\\{\\};\n\\end{DoxyCode}\n\n\nAbove x variables are implicilty of type double. To express type explicitly use\\+:\n\n\n\\begin{DoxyCode}\n\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::variable<int, 0>} x0\\{\\};\n\\end{DoxyCode}\n\n\nNumeric parameter (of type std\\+::size\\+\\_\\+t) differentiates every variable from the others.\n\n\n\\begin{DoxyCode}\n\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1constant}{nds::constant<14>} cons\\{\\};\n\\end{DoxyCode}\n\n\nCurrently only integer constants are supported.\n\n{\\bfseries 2. Defining functions }\n\nWe only have to define Function type, there is no need to create the object.~\\newline\nArithmetic operators and some other mathematical functions are overloaded for convenience in function defining.\n\nYou should use the\n\\begin{DoxyCode}\n\\textcolor{keyword}{using} and decltype() \n\\end{DoxyCode}\n when defining it.\n\n{\\bfseries Example of $ \\sin(\\cos(\\frac{x_0}{x_1})*\\log(x_0)) + x_2 $ creation} \\+:\n\n\n\\begin{DoxyCode}\n\\textcolor{preprocessor}{#include\"numpp/differentiation/symbolic.hpp\"}\n\n\\textcolor{keyword}{using} Function = decltype(\\hyperlink{group__numpp__differentiation__forward__automatic_ga6f6f07250087b18ada9ea1f84418f24f}{sin}(\\hyperlink{group__numpp__differentiation__forward__automatic_gaa5a06320f93037d94fda441546d7d690}{cos}(\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<0>}\\{\\}/\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<1>}\\{\\})*\n      \\hyperlink{group__numpp__differentiation__forward__automatic_ga0f6011595edffe756a984de60358fe5f}{log}(\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<0>}\\{\\})) + \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<2>}\\{\\});\n\\end{DoxyCode}\n\n\n{\\bfseries 3. Differentiating the function\\+:}\n\nThere are two ways to differentiate type, as shown below\\+:\n\n{\\bfseries 3.\\+1. Predicate with\\+\\_\\+respect\\+\\_\\+to\\+:} \n\\begin{DoxyCode}\n\\textcolor{comment}{//Function as defined above}\n\\textcolor{keyword}{using} Derivative = \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{nds::differentiate<Function, 3>::with\\_respect\\_to}\n      <0,0,1>;\n\\end{DoxyCode}\n\n\nAbove code performs 3-\\/rd order differentiation with respect to $x_0, x_0, x_1 $ in this exact order.\n\n{\\bfseries 3.\\+2. With derivative type\\+:} \n\\begin{DoxyCode}\n\\textcolor{comment}{//Function as defined above}\n\\textcolor{keyword}{using} Derivative = Function::derivative<0>\n\\end{DoxyCode}\n\n\nAbove performs differentiation with respect to $x_0$.\n\n{\\bfseries 4. Obtaining numerical values from expressions}\n\nAfter obtaining Function type (or Derivative or similiar) you would probably like to obtain value at a given point. ~\\newline\nTo do so, you have to create an array which size is equal to the number of independent variables~\\newline\nand pass it to the static constexpr function {\\bfseries calculate}\n\n{\\bfseries Example}\n\n\n\\begin{DoxyCode}\n\\textcolor{comment}{//Derivative as defined above}\nconstexpr \\textcolor{keyword}{auto} value = Derivative::calculate(std::array<double, 3>\\{1.,5.,7.\\});\n\\end{DoxyCode}\n\n\nAny object providing operator\\mbox{[}\\mbox{]} may be used as an argument to calculate.\n\n{\\bfseries Technical Details\\+:}\n\nApproach of type differentiating allows this module to obtain near hand-\\/coded efficiency for n-\\/th order partial derivatives.\n\nCons -\\/ compilation may take longer as order and complexity of formula increases after this initial phase, every derivative evaluation or next differentiation will take substantially shorter amount of time than current available approaches. \n\n\\subsection{Function Documentation}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_gad414fd158986bf7fff7e258a6ebf182c}\\label{group__numpp__differentiation__symbolic_gad414fd158986bf7fff7e258a6ebf182c}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!cos@{cos}}\n\\index{cos@{cos}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{cos()}{cos()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::cos (\\begin{DoxyParamCaption}\\item[{const T \\&}]{ }\\end{DoxyParamCaption})}\n\ncos returns object representing $ \\cos(T) $ \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & Parameter representing type of the argument (can be complex like log(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing $ \\cos(T) $\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga4bcf2dcdbc549b58c9fb7cd1b8c1cf70}\\label{group__numpp__differentiation__symbolic_ga4bcf2dcdbc549b58c9fb7cd1b8c1cf70}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!exp@{exp}}\n\\index{exp@{exp}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{exp()}{exp()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::exp (\\begin{DoxyParamCaption}\\item[{const T \\&}]{ }\\end{DoxyParamCaption})}\n\nexp returns object representing $ e^T $ \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & Parameter representing type of the exponent (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing $ e^T $\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga186ca63e28a816d1cb9c8175c7839468}\\label{group__numpp__differentiation__symbolic_ga186ca63e28a816d1cb9c8175c7839468}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!log@{log}}\n\\index{log@{log}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{log()}{log()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::log (\\begin{DoxyParamCaption}\\item[{const T \\&}]{ }\\end{DoxyParamCaption})}\n\nlog returns object representing $ \\log(T) $ \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & Parameter representing type being logarithmized (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing $ \\log(T) $\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga0f6f3d22e3e712ce154f7f6c91e0cf46}\\label{group__numpp__differentiation__symbolic_ga0f6f3d22e3e712ce154f7f6c91e0cf46}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!operator$\\ast$@{operator$\\ast$}}\n\\index{operator$\\ast$@{operator$\\ast$}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{operator$\\ast$()}{operator*()}}\n{\\footnotesize\\ttfamily template$<$typename Left , typename Right $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::operator$\\ast$ (\\begin{DoxyParamCaption}\\item[{const Left \\&}]{,  }\\item[{const Right \\&}]{ }\\end{DoxyParamCaption})}\n\noperator$\\ast$ returns object representing multiplication of Left and Right hand-\\/side \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em Left} & Parameter representing left hand-\\/side (can be complex like sin(x)) \\\\\n\\hline\n{\\em Right} & Parameter representing Right hand-\\/side (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing multiplication of Left and Right\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga45bd7508b366431d72157d0f1ef6fac2}\\label{group__numpp__differentiation__symbolic_ga45bd7508b366431d72157d0f1ef6fac2}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!operator+@{operator+}}\n\\index{operator+@{operator+}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{operator+()}{operator+()}}\n{\\footnotesize\\ttfamily template$<$typename Left , typename Right $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::operator+ (\\begin{DoxyParamCaption}\\item[{const Left \\&}]{,  }\\item[{const Right \\&}]{ }\\end{DoxyParamCaption})}\n\noperator+ returns object representing addition of Left and Right hand-\\/side \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em Left} & Parameter representing left hand-\\/side (can be complex like sin(x)) \\\\\n\\hline\n{\\em Right} & Parameter representing Right hand-\\/side (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing addition of Left and Right\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga4aecf7125ae67f3c834ed8ab5e14248a}\\label{group__numpp__differentiation__symbolic_ga4aecf7125ae67f3c834ed8ab5e14248a}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!operator-\\/@{operator-\\/}}\n\\index{operator-\\/@{operator-\\/}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{operator-\\/()}{operator-()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::operator-\\/ (\\begin{DoxyParamCaption}\\item[{const T \\&}]{ }\\end{DoxyParamCaption})}\n\noperator-\\/ returns object representing the negative of it, e.\\+g. sin(x)-\\/$>$ -\\/sin(x) \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & Parameter representing any type (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing negative of a given object\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_gac882bc2dcbffae1107c46bc3eac93a44}\\label{group__numpp__differentiation__symbolic_gac882bc2dcbffae1107c46bc3eac93a44}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!operator/@{operator/}}\n\\index{operator/@{operator/}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{operator/()}{operator/()}}\n{\\footnotesize\\ttfamily template$<$typename Left , typename Right $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::operator/ (\\begin{DoxyParamCaption}\\item[{const Left \\&}]{,  }\\item[{const Right \\&}]{ }\\end{DoxyParamCaption})}\n\noperator/ returns object representing division of Left and Right hand-\\/side \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em Left} & Parameter representing left hand-\\/side (can be complex like sin(x)) \\\\\n\\hline\n{\\em Right} & Parameter representing Right hand-\\/side (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing division of Left and Right\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_gaa52e3714ea3492f60c68cdb4974fe495}\\label{group__numpp__differentiation__symbolic_gaa52e3714ea3492f60c68cdb4974fe495}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!pow@{pow}}\n\\index{pow@{pow}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{pow()}{pow()}}\n{\\footnotesize\\ttfamily template$<$std\\+::size\\+\\_\\+t N, typename Left $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::pow (\\begin{DoxyParamCaption}\\item[{const Left \\&}]{ }\\end{DoxyParamCaption})}\n\nreturns object representing Left hand-\\/side to the n-\\/th power\n\n{\\bfseries Example usage\\+:} \n\\begin{DoxyCode}\n\\textcolor{keyword}{using} Function = decltype(pow<4>(\\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{nds::x<0>}\\{\\}));\n\\end{DoxyCode}\n\n\n\\begin{DoxyWarning}{Warning}\nUnluckily there seems to be no workaround around passing exponent as a template parameter\n\\end{DoxyWarning}\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em N} & Power of the function, Left is taken to the power of N \\\\\n\\hline\n{\\em Right} & Parameter representing type being any valid symbolic expression (can be complex like sin(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing $ Left^N $\n\\end{DoxyReturn}\n\\mbox{\\Hypertarget{group__numpp__differentiation__symbolic_ga49ba3eed5ff463e79a88f4952f73f435}\\label{group__numpp__differentiation__symbolic_ga49ba3eed5ff463e79a88f4952f73f435}} \n\\index{Symbolic Differentiation@{Symbolic Differentiation}!sin@{sin}}\n\\index{sin@{sin}!Symbolic Differentiation@{Symbolic Differentiation}}\n\\subsubsection{\\texorpdfstring{sin()}{sin()}}\n{\\footnotesize\\ttfamily template$<$typename T $>$ \\\\\nconstexpr auto numpp\\+::differentiation\\+::symbolic\\+::sin (\\begin{DoxyParamCaption}\\item[{const T \\&}]{ }\\end{DoxyParamCaption})}\n\nsin returns object representing $ \\sin(T) $ \n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & Parameter representing type of the argument (can be complex like log(x))\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyReturn}{Returns}\nType representing $ \\sin(T) $\n\\end{DoxyReturn}\n", "meta": {"hexsha": "f272225f0db8055716b46928f82ce4c97f274c04", "size": 18448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/group__numpp__differentiation__symbolic.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__symbolic.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__symbolic.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": 56.0729483283, "max_line_length": 414, "alphanum_fraction": 0.7903837814, "num_tokens": 5701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6430449684160857}}
{"text": "A plane wave state is considered in a semi-infinite medium of length $l=6m$ in direction $\\vect{e}_1$, made of a hyperelastic Saint-Venant-Kirchhoff material:\n\\begin{align*}\n  & \\tens{F} = F \\vect{e}_1 \\otimes \\vect{e}_1 + \\vect{e}_2 \\otimes \\vect{e}_2 + \\vect{e}_3 \\otimes \\vect{e}_3 \\\\\n  & \\tens{\\Pi} = \\Pi \\vect{e}_1 \\otimes \\vect{e}_1 + \\Pi_r \\(\\vect{e}_2 \\otimes \\vect{e}_2 + \\vect{e}_3 \\otimes \\vect{e}_3\\)\n\\end{align*}\nwhere $\\Pi = \\frac{2\\mu + \\lambda}{2} F(F^2 - 1)$, $\\Pi_r = \\frac{\\lambda}{2}(F^2 - 1)$ and $(\\mu,\\lambda)$ are the Lam\\'e's coefficients. A traction force is enforced on the left boundary of the solid initially at rest: $\\tens{\\Pi}\\cdot\\(-\\vect{e}_1\\)=\\Pi^d\\vect{e}_1$. The exact solutions of the Picard problem thus formulated have been developed in section \\ref{sec:SVK_solution}.\nWith characteristic speeds depending on the deformation gradient, a compressive (\\textit{resp. tensile}) load leads to a rarefaction (\\textit{resp. shock}) wave traveling in the medium.\nRecall that this non-intuitive behavior is due to the concave nature of the SVK fluxes (see remark \\ref{rq:charach_neoHook} in section \\ref{sec:SVK_solution}).\nBoth cases are considered hereinafter before reflection on the right end.\n%Recall that since the characteristic speeds of this non-linear problem depends on the deformation gradient, a compressive (\\textit{resp. tensile}) load leads to a rarefaction (\\textit{resp. shock}) wave travelling in the medium, both cases being considered hereinafter before reflection on the right end.\nMoreover, it has been established that the problem is no longer hyperbolic if the deformation gradient is such that $F<\\sqrt{\\frac{1}{3}}$ (see remark \\ref{rq:hyperbolicity_limit_SVK} in section \\ref{sec:SVK_solution}).\nHence, we consider here loading conditions that do not yield a loss of hyperbolicity. \n\nThe one-dimensional medium is discretized by using either $100$ or $200$ material points lying in $100$ regular grid cells.\nThe 1ppc and 2ppc discretizations used here are the same as before as well as material parameters of table \\ref{tab:material}.\n\n\\subsubsection{Compressive impact on a SVK medium}\nTo begin with, the body is submitted to a compressive load on its left end so that a rarefaction wave propagates rightward.\nThe total and updated Lagrangian formulations of the MPM are used along with DGMPM schemes.\nFirst of all, the compressive load is set to $\\Pi^d= 4\\times 10^{8} \\: Pa$ and numerical solutions are compared in figure \\ref{fig:he_rarefaction_UL} at two different times.\nThough the low load amplitude applied results in a solution which looks like a discontinuity, it avoids grid crossing.\n\n\\begin{figure}[h!]\n  \\centering\n  {\\input{chapter4/pgfFigures/he_stress_low_UL}}\n  \\caption{First Piola–Kirchhoff stress along a horizontal line of the one-dimensional hyperelastic medium at different times: solution of the compressive impact problem $\\Pi^d= 4\\times 10^{8} \\: Pa$. Comparison between updated and total Lagrangian MPMs (CFL=$0.5$), DGMPM-Euler with 1ppc (CFL=$1$) or 2ppc (CFL=$0.5$), DGMPM-RK2 with 2ppc (CFL=$1$), and the exact solution.}\n  \\label{fig:he_rarefaction_UL}\n\\end{figure}\nFirst, both solutions of updated and total Lagrangian MPM formulations oscillate.\nIt is noteworthy that these two stress profiles are superimposed except at the left end of the domain where an instability occurs in the updated Lagrangian solution due to the displacement of particles.\nSecond, DGMPM solutions still behave well and show good agreement with the exact solution. However, the enforcement of a higher load amplitude is more relevant in order to see the error made by the DGMPM.\nThe applied load is therefore raised to $\\Pi^d= 2\\times 10^{10} \\: Pa$.\n\nSignificant differences between numerical methods and the exact solution are then visible in figure \\ref{fig:he_rarefaction}.\n\\begin{figure}[h!]\n  \\centering\n  {\\phantomsubcaption{\\label{subfig:he_rarefaction1}}}\n  {\\phantomsubcaption{\\label{subfig:he_rarefaction2}}}\n  {\\input{chapter4/pgfFigures/he_stress_high_UL}}\n  \\caption{First Piola–Kirchhoff stress along a horizontal line of the one-dimensional hyperelastic medium at different times: solution of the compressive impact problem $\\Pi^d= 2\\times 10^{10} \\: Pa$. Comparison between MPM (CFL=$0.5$), DGMPM-Euler with 1ppc (CFL=$1$) or 2ppc (CFL=$0.5$), DGMPM-RK2 with 2ppc (CFL=$1$), and the exact solution.}\n  \\label{fig:he_rarefaction}\n\\end{figure}\nFirst, grid crossing now occurs so that the MPM results based on the updated Lagrangian formulation are no longer correct. Hence, this formulation is omitted from now on.\nOn the other hand, the total Lagrangian MPM scheme yields a solution which does not oscillate more than for linear cases.\n%The total Lagrangian approach, on the other hand, provides a solution in which the wave travel at the correct speed, although spurious oscillations still arise.\nNext, as expected from the use of an approximate-state Riemann solver for non-linear problems, DGMPM stresses, though close to the analytical solution, no longer fit it exactly (see figure \\ref{fig:he_rarefaction}\\subref{subfig:he_rarefaction2}).\nFurthermore, the use of DGMPM-Euler with 2ppc leads to a smoother solution.\n\n\nOne can imagine the employment of an exact Riemann solver based on the exact solution in order to reduce the error made in the DGMPM.\n% In order to reduce the error made in the DGMPM, one can imagine to use an exact Riemann solver based on the exact solution.\nHowever, such an implementation requires the solution of a non-linear problem at each cell interface and is very costly.\nMoreover, an exact solution is available for a SVK material but this is not the case for other constitutive models, which prevents the generic use of an exact solver.\n\n% \\begin{remark}\n%   This problem can be solved in a two-dimensional setting by considering an infinite medium in direction $\\vect{e}_3$, of dimension $l\\times h$ in directions $\\vect{e}_1$ and $\\vect{e}_2$, which bottom and top boundaries are assumed vertically fixed.\n%   %A two-dimensional setting may be used to solve this problem by considering an infinite medium in direction $\\vect{e}_3$, of dimension $l\\times h$ in directions $\\vect{e}_1$ and $\\vect{e}_2$, which bottom and top boundaries are assumed vertically fixed.\n%   In that case, DGMPM results still show a good agreement with the exact solution of the problem \\cite{DGMPM}.\n% \\end{remark}\n\n\n\\subsubsection{Tensile impact on a SVK medium}\nA tensile load of magnitude $\\Pi^d= -2\\times 10^{10} \\: Pa$ that gives rise to a shock wave in the medium is now studied. Recall that for this problem, the characteristic speeds are: $c=\\pm \\sqrt{\\frac{\\lambda+2\\mu}{2\\rho_0}\\(3F^2-1\\) }$ (see equation \\eqref{eq:SVK_charac_fields} in section \\ref{sec:SVK_solution}).\nIt then follows that the higher the deformation gradient, the faster waves propagate. Hence, the celerity of the fastest wave is given by the deformation gradient on the upwind side and must be used to adapt the time step and hence, satisfy the CFL condition for fixed Courant number.\nThis situation did not arise in the above case of a rarefaction wave since the highest deformation gradient value was (constant) on the downwind side. \n\n\\begin{figure}[h!]\n  \\centering\n  {\\phantomsubcaption \\label{subfig:he_shock1}}\n  {\\phantomsubcaption \\label{subfig:he_shock2}}\n  {\\input{chapter4/pgfFigures/he_stress_50shock}}\n  \\caption{First Piola–Kirchhoff stress solution of the tensile impact problem at different times: $\\Pi^d=-2\\times 10^{10} \\: Pa$. Comparison between MPM (CFL=$0.5$), DGMPM-Euler with 1ppc (CFL=$1$) or 2ppc (CFL=$0.5$), DGMPM-RK2 with 2ppc (CFL=$1$), and the exact solution.}\n  \\label{fig:he_shock}\n\\end{figure}\nTotal Lagrangian MPM and DGMPM are used to solve this problem, and compared to the exact solution in figure \\ref{fig:he_shock}.\n%% MPM\nThe error made in the MPM solution grows during the computation, implying that the method is no longer stable in spite of the CFL number set to $0.5$, which ensured stability for the above problems.\nMoreover, slight oscillations also appear after the shock in DGMPM solutions based on a unit Courant number (see figure \\ref{fig:he_shock}\\subref{subfig:he_shock1}) but not in the DGMPM-Euler using 2ppc due to the lower Courant number used.\n%This numerical noise (figure \\ref{fig:he_shock}\\subref{subfig:he_shock1}) does not appear in the DGMPM-Euler using 2ppc due to the lower Courant number used.\nNevertheless, the oscillations do not increase with time as can be seen in figure \\ref{fig:he_shock}\\subref{subfig:he_shock2}, meaning that this noise is not an instability.\n%% Capturing shocks\nNext, despite a CFL number set to one, the DGMPM-Euler and DGMPM-RK2 do not perfectly capture the discontinuity, though a good behavior is shown.\nIndeed, according to Lax entropy condition \\eqref{eq:Lax_entropy}, the wave celerity used for the time step evaluation is an upper bound of the shock speed so that such a wave cannot be captured.\nNevertheless, the loading conditions are deliberately extreme for the purpose of visualization.\n%% Lower shock\n\\begin{figure}[h!]\n  \\centering\n  {\\phantomsubcaption \\label{subfig:he_low_shock1}}\n  {\\phantomsubcaption \\label{subfig:he_low_shock2}}\n  {\\input{chapter4/pgfFigures/he_stress_5shock}}\n  \\caption{First Piola–Kirchhoff stress solution of the tensile impact problem at different times: $\\Pi^d=-2\\times 10^{9} \\: Pa$. Comparison between MPM (CFL=$0.5$), DGMPM-Euler with 1ppc (CFL=$1$) or 2ppc (CFL=$0.5$), DGMPM-RK2 with 2ppc (CFL=$1$), and the exact solution.}\n  \\label{fig:he_low_shock}\n\\end{figure}\n\nA lower tensile load leads to a numerical solution closer to analytical results as can be seen in figure \\ref{fig:he_low_shock}, which shows the comparison for $\\Pi^d=-2\\times 10^{9} \\: Pa$.\nIn addition, the oscillations appearing in DGMPM-Euler with 1ppc and DGMPM-RK2 with 2ppc solutions are almost eliminated in figure \\ref{fig:he_low_shock}\\subref{subfig:he_low_shock1}.\nThe MPM solution on the other hand, still exhibits an increasing error although a Courant number ensuring the stability in the scheme for linear problems is used.\n\n\n% \\subsubsection{Impact problem}\n\n% \\begin{figure}[h!]\n%   \\centering\n%   %\\input{chapter4/2dplaneWave}\n%   \\input{chapter4/2DplaneWave}\n%   \\caption{test}\n%   \\label{fig:2dplane_Wave}\n% \\end{figure}\n\n% \\begin{figure}[h!]\n%   \\centering\n%   \\input{chapter4/pgfFigures/HE_PW_energies}\n%   \\caption{Evolution of total energy}\n%   \\label{fig:pw_energy}\n% \\end{figure}\n\n%%% Local Variables:\n%%% mode: latex\n%%% ispell-local-dictionary: \"american\"\n%%% TeX-master: \"../mainManuscript\"\n%%% End:", "meta": {"hexsha": "7c552a28000bbf712ea6de6428215fbc385a5b5a", "size": 10617, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/chapter4/he_planewave.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/chapter4/he_planewave.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/chapter4/he_planewave.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": 87.7438016529, "max_line_length": 383, "alphanum_fraction": 0.766318169, "num_tokens": 2987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6430449628287208}}
{"text": "\\input{PreambleCommon}\n\\input{WeekTitles}\n\\begin{document}\n\n\\newpage\n\\setfont\n\\pagestyle{fancy}\n\\renewcommand{\\Week}{10}\n\\renewcommand{\\WeekTitle}{\\WeekTitleTen}\n\n\\fancyhead[LE,RO]{Week \\Week}  % default, usually only for first page\n\\fancyfoot{}\n\\sectionbox{Week \\#\\Week: \\WeekTitle}\n\n\\vspace{5mm}\n\\goals \n\\begin{itemize}\n\\item Express vectors, linear combinations, and compute dot products.\n\\item Write information in matrix form in the context of engineering applications.\n\\item Understand the definition of the transpose, and use MATLAB to compute it.\n\\item Use MATLAB to compute the inverse of a matrix.\n\\end{itemize}\n\n\\newpage\n\\topic{Linear Algebra - Introduction}\n\\subsection*{Introduction to Vectors}\nIn a physical context we often need to describe measurable quantities such as pressure, mass, and speed, and these objects can be completely described by a single number known as the \\textbf{magnitude}. However there are other quantities which help us describe the world around us such as force, velocity and acceleration that require more than magnitude to describe them. They also need a \\textbf{direction}. A \\textbf{vector} is a magnitude (a number describing how much, how fast, etc) in combination with a direction. Vectors are denoted by boldface letters, such as $\\overrightarrow{u}, \\overrightarrow{v}, \\overrightarrow{x}, \\overrightarrow{y}, \\overrightarrow{z}$.\n\n\\newpage\n\nWhen discussing direction, we need to decide on a frame of reference. We will be using the Cartesian coordinate system. A \\textit{point} in the two-dimensional Cartesian plane, denoted as $\\mathbb{R}^2$ is denoted by an ordered pair (x,y) of real numbers, which we call \\textit{coordinates}. So for example, (2,1) can be represented as a point on a grid like so: \n\n\n\n\\newpage\n\nConsider the point (x,y) in $\\mathbb{R}^2$. If we draw a directed line segment from the \\textbf{origin} (the point (0,0)) to (x,y), we get the following picture:\n``insert picture here\"\n\nNotice there is an arrow pointing at (x,y). We call this the \\textbf{head} of the vector and the \\textbf{tail} is at the origin, indicating a direction. The \\textbf{magnitude} of the vector is its length from (0,0) to (x,y). \n\n\n\\newpage\n\nTo find the magnitude of a vector, we first find its \\textbf{components}. If the head of the vector is at the point (x', y') and the tail of the vector is at the point (x,y), then the components of the vector are $x'-x$ and $y'-y$, and we represent them in the following way:\n\n$$ \\begin{bmatrix}x'-x\\\\y'-y\\end{bmatrix} $$\n\nOnce you have found the components, the formula for finding the magnitude of the vector is:\n$$\\text{magnitude} = \\sqrt{(x'-x)^2 + (y'-y)^2} $$ \n\n\\newpage\n\nDraw and find the magnitude of the following vectors:$ \\overrightarrow{a}$ has the tail at (-1,1) and the head at (4,3), $\\overrightarrow{b}$ has the tail at (0,4) and the head at (-2,-2), and $\\overrightarrow{c}$ has the tail at (3,0) and the head at (0,3). We use the notation $||\\overrightarrow{a}||$ to represent the magnitude of $\\overrightarrow{a}$.\n\n``Insert picture here\"\n\n\\newpage\n\nAn interesting fact to note is that two vectors are \\textbf{equal} if their components are equal. Consider the vector $\\overrightarrow{A}$ going from (-1,4) to \\\\ \\noindent (-3,1) (tail to head), $\\overrightarrow{B}$ going from (2,3) to (0,0) and $\\overrightarrow{C}$ going from (5,5) to (3,2). All of these vectors occupy the different regions of $\\mathbb{R}^2$, yet we can define them as equal since they have the same components. A \\textbf{position vector} is a vector whose tail starts at the origin, and if a vector is given with just its components, you may assume it is a position vector.\n\\newpage\n\\subsection*{Vector Addition and Scalar Multiplication}\n\n\nIf we have two vectors in $\\mathbb{R}^2$ with components\n$$ \\overrightarrow{x} = \\begin{bmatrix}x_1\\\\x_2\\end{bmatrix} \\text{ and } \\overrightarrow{y} = \\begin{bmatrix}y_1\\\\y_2\\end{bmatrix}$$\n\nthen the \\textbf{sum} of the vectors \\textbf{x} and \\textbf{y} is\n\n$$ \\overrightarrow{x} + \\overrightarrow{y} = \\begin{bmatrix}x_1+y_1\\\\x_2+y_2\\end{bmatrix} $$\n\n\\newpage\n\nSo if we have vectors \n\n$$ \\overrightarrow{x} = \\begin{bmatrix}1\\\\1\\end{bmatrix}, \\text{ } \\overrightarrow{y} = \\begin{bmatrix}-2\\\\5\\end{bmatrix}, \\text{ and } \\overrightarrow{z} = \\begin{bmatrix}4\\\\-1\\end{bmatrix}$$\n\nThen $$ \\overrightarrow{x} + \\overrightarrow{y} = \\begin{bmatrix}1+(-2)\\\\1+5  \\end{bmatrix} = \\begin{bmatrix}\n-1\\\\6\n\\end{bmatrix} $$\n\nOr we could have\n\n$$ \\overrightarrow{y} + \\overrightarrow{z} = \\begin{bmatrix}-2+4\\\\5+(-1)  \\end{bmatrix} = \\begin{bmatrix}\n2\\\\4\n\\end{bmatrix} $$\n\n\\newpage\n\nWe can interpret vector addition geometrically.\n\n``Insert picture here''\n\n\n\\newpage\n\nIf $\\overrightarrow{x} = \\begin{bmatrix}\nx_1\\\\x_2\n\\end{bmatrix}$ is a vector and $c$ is a scalar (meaning a real number), then the \\textbf{scalar} multiple $c\\overrightarrow{x}$, meaning every component of $\\overrightarrow{x}$ is multiplied by $c$, is $c\\overrightarrow{x} = \\begin{bmatrix}\ncx_1\\\\cx_2\n\\end{bmatrix}$. If $c>0$, then $c\\overrightarrow{x}$ is in the same direction as $\\overrightarrow{x}$. If $c<0$, then $c\\overrightarrow{x}$ is in the opposite direction as $\\overrightarrow{x}$.\n\n``Insert picture here\"\n\n\n\\newpage\n\nFor example, if $c = -1$, $d = 2$ and $\\overrightarrow{y} = \\begin{bmatrix}\n4\\\\-1\n\\end{bmatrix}$ (Recall that $\\overrightarrow{y}$ is a position vector, whose tail starts at the origin), then $c\\overrightarrow{y} =\\begin{bmatrix}(-1)\\cdot(4)\\\\(-1)\\cdot(-1)\\end{bmatrix} = \\begin{bmatrix}\n-4\\\\1\n\\end{bmatrix}$ and $d\\overrightarrow{y}= \\begin{bmatrix}(2)\\cdot(4)\\\\(2)\\cdot(-1)\\end{bmatrix} = \\begin{bmatrix} 8\\\\-2\n\\end{bmatrix}$\n\n``insert picture here\"\n\n\\newpage\n\\subsection*{3-Dimensional Vectors}\n\n3-dimensional (also known as 3-space) vectors exist in $\\mathbb{R}^3$, meaning that we are now dealing another axis, the z-axis. Just like in $\\mathbb{R}^2$, there is an origin where all of the axes meet, (0,0,0). Points in $\\mathbb{R}^3$ are represented by an ordered triplet (x, y, z). The points (2,1,3), (4, -2, -2), and (1,0,5) would be drawn like so:\n\n\"Insert Picture Here\"\n\n\n\n\\newpage\n\nComponents for 3-dimensional vectors are defined in the same way as 2-dimensional vectors, except that now there are three of them. So for a vector $\\overrightarrow{u}$ whose tail starts at the point (x,y,z) and has its head at the point (x',y',z'), the components of $\\overrightarrow{u}$ are:\n\n$$\\begin{bmatrix}\nx'-x\\\\y'-y\\\\z'-z\n\\end{bmatrix} $$\n\nA 3-dimensional vector whose components are given without information about the head or the tail is a position vector, and you can assume its tail starts at the origin.\n\n\\newpage\n\nAll of the rules for vector addition and scalar multiplication we presented for 2-dimensional vectors are the same for the 3-dimensional versions. If we have position vector $\\overrightarrow{a} = \\begin{bmatrix}\na_1\\\\a_2\\\\a_3\n\\end{bmatrix}$ then the magnitude of $\\overrightarrow{a}$ is\n$$||\\overrightarrow{a}|| = \\sqrt{a_1^2 + a_2^2 + a_3^2}$$\n\nKeep in mind that we get this formula from the fact that the tail of $\\overrightarrow{a}$ is at the origin (0,0,0).\n\n\\newpage\n\n\n\n\\end{document}\n", "meta": {"hexsha": "cbece3f0e1b325e6278d12c13c64a8b8c2b97635", "size": 7124, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/notes10.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": "Notes/notes10.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": "Notes/notes10.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": 47.4933333333, "max_line_length": 672, "alphanum_fraction": 0.7226277372, "num_tokens": 2150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6430449609662656}}
{"text": "% !TEX root = main.tex\n\n%------------------------------------------------\n \\chapter{Second Order Equations}\nA second order linear differential equation is an equation of the following form : $$\\frac{d^2y}{dt^2} +a_1(t)\\frac{dy}{dt} + a_0(t)y = f(t).$$ The functins $a_1(*)$, $a_0(*)$ and $f(*)$ are supposed to be known and we want to find all of the solutions to $y$.\n\\begin{example}\nThe Legendre equation is $$\\frac{d^2y}{dt^2} - \\frac{2t}{1-t^2}\\frac{dy}{dt} + \\frac{n(n+1)}{1-t^2}Y = 0.$$\nThe equation has a solution $P_n(t)$, the Legendre polynomial of degree $n$.\n\\begin{itemize}\n\\item For $n = 0$ we can take $P_0(t)$ for all $t$\n\\item For $n = 1$ we let $P_1(t) = at+b$. We get $$\\frac{-2t}{1 - t^2}a + \\frac{2}{1-t^2}(at+b) = 0$$ for all $t\\in\\mathbb{R}\\backslash \\{\\pm 1\\}$ This gives $b=0$ and we can take $a = 1$ to get $P_1(t) = t$\n\\end{itemize}\n\\end{example}\n\\begin{example}\nBessel's equation of order $n$ is : $$\\frac{d^2y}{dt^2} + \\frac{1}{t}\\frac{dy}{dt}+(1 - \\frac{n^2}{t^2})y = 0.$$\nThe solution are Bessel functions, $J_n(t)$ and $Y_n(t).$\n\\end{example}\n\\section{Equations with Constant Coefficients}\n$$\\frac{d^2y}{dt^2}+a_1\\frac{dy}{dt}a_0y = f(t)$$\nIn order to solve the above equation we adopt a two step solution strategy: \\begin{enumerate}\n\\item Find all the solution of the equation with $f = 0$. The equation when $f = 0$ is called the homogeneous equation\n\\item Develop a formula called the variation of parameters formula for the case $f \\not = 0$, using the solutions of the homogeneous equation\n\\end{enumerate}\n\\subsubsection*{Solution Method for $\\mathbf{f = 0}$}\nWe look for a solution of the form $y(t) = A\\exp(\\mu t)$, where $A$ and $\\mu$ are constants. We have: $$\\frac{dy}{dt} = \\mu A\\exp(\\mu t) \\quad \\mbox{      and      } \\quad \\frac{d^2y}{dt^2} = \\mu^2 A \\exp(\\mu t).$$\nSubstituting into the differential equation gives: $$(\\mu^2 + a_1\\mu + a_0) * A\\exp(\\mu t) = 0.$$\nSince $\\exp(\\mu t ) \\not = 0$ and we do not want the trivial solution which comes from choosing $ A = 0$, we have $\\mu^2 + a_1\\mu +a_0 = 0$ this is called the auxiliary quadratic. The possibilities are:\n\\begin{itemize}\n\\item Two distinct roots\n\\item One double root\n\\end{itemize}\nIf $a_1$ and $a_0$ are real there is an alternative dichotomy: \n\\begin{itemize}\n\\item Two real roots (which may or may not coincide)\n\\item A complex conjugate pair of distinct roots\n\\end{itemize}\n\\subsubsection*{Case 1 : Distinct Roots $\\mathbf{\\mu_1 \\not = \\mu_2}$}\n$$\\mu^2 +a_1\\mu +a_0 = (\\mu - \\mu_1)(\\mu-\\mu_2).$$ We have the solutions $$y_j(t) = A_j \\exp(\\mu_j t) \\quad j = 1, 2.$$ For completely arbitary constants $A_1$, $A_2$. Suppose $y(t) = y_1(t) + y_2(t)$ then $$\\frac{dy}{dt} = \\frac{dy_1}{dt} + \\frac{dy_2}{dt} \\quad \\mbox{   and   } \\quad  \\frac{d^2y}{dt^2} = \\frac{d^2y_1}{dt^2} + \\frac{d^2y_2}{dt^2}.$$\nSo, $$\\frac{d^2y}{dt^2} + a_1\\frac{dy}{dt} + a_0y = [\\frac{d^2y_1}{dt^2} + a_1\\frac{dy_1}{dt} +a_0y_1] +  [\\frac{d^2y_2}{dt^2} + a_1\\frac{dy_1}{dt} + a_0y_2].$$\n \\begin{theorem}\n\nSuppose that the auxiliary quadratic has a distinct root $\\mu_1 \\not = \\mu_2$. Then every solution of the homogeneous equation has the form $$y(t) = A_1 \\exp(\\mu_1t) + A_2 \\exp(\\mu_2t)$$ for some $A_1$, $A_2 \\in \\mathbb{C}.$\n\\end{theorem}\n\\begin{example}\n$$\\frac{d^2y}{dt^2} - (\\mu_1+\\mu_2)\\frac{dy}{dt} + \\mu_1\\mu_2y = 0$$\nsuch that $y(0) = y(0) \\mbox{ and } y'(0) = v_0.$\n\\begin{solution}\n\nWe know $y(t) = A_1 \\exp(\\mu_1t) + A_2 \\exp(\\mu_2t)$ and we choose $A_1$, $A_2$ so that:\n$$\n\\begin{cases}\ny_0 = y(0) = A_1 + A_2 \\\\\nv_0 = y'(0) = A_1\\mu_1 +A_2\\mu_2\n\\end{cases} $$\nHence $$\\mu_2y_0 - v_0 = A_1(\\mu_2 - \\mu_1) \\implies$$\n$$\n\\begin{cases}\nA_1 = \\frac{\\mu_2y_0 - v_0}{\\mu_2 - \\mu_1} \\\\\nA_2 = y_0 - A_1 = \\frac{v_0 - \\mu_1y_0}{\\mu_2 - \\mu_1}\n\\end{cases} $$\nThus $$y_1(t) = \\frac{\\mu_2y_0 - v_0}{\\mu_2 - \\mu_1} \\exp(\\mu_1t) + \\frac{v_0 - \\mu_1y_0}{\\mu_2 - \\mu_1} \\exp(\\mu_2t) = y_0\\bigg(\\frac{\\mu_2\\exp(\\mu_1t) - \\mu_1\\exp(\\mu_2t)}{\\mu_2-\\mu1}\\bigg) + v_0\\bigg(\\frac{\\exp(\\mu_2t) - \\exp(\\mu_1t)}{\\mu_2-\\mu_1}\\bigg).$$\n\\end{solution}\n\\end{example}\n\\begin{example}\nIn the previous example let $\\mu_1$ be fixed and find $\\lim_{\\mu_2 \\to \\mu_1} y(t)$.\n\\begin{solution}\nFirst we compute $$\\lim_{\\mu_2 \\to \\mu_1}\\bigg[\\frac{\\exp(\\mu_2t) - \\exp(\\mu_1t)}{\\mu_2 - \\mu_1}\\bigg] = t\\exp(\\mu t)\\lim_{\\mu_2 \\to \\mu_1}\\bigg[\\frac{\\exp((\\mu_2 - \\mu_1)t - 1}{(\\mu_2 - \\mu_1)t}\\bigg].$$\nNow set $ h = \\mu_2 - \\mu_1$. Thus : $$t\\exp(\\mu_1t)\\lim_{h \\to 0}\\bigg[\\frac{\\exp(h) - 1}{h}\\bigg]$$ $$= t\\exp(\\mu_1)\\lim_{h \\to 0}\\bigg[\\frac{\\exp(h) - \\exp(0)}{h}\\bigg] = t\\exp(\\mu_1t)\\exp'(0).$$ \nWhere $\\exp'(0) = 0$. Hence $$\\lim_{\\mu_2 \\to \\mu_1}\\bigg(\\frac{\\exp(\\mu_2t) - \\exp(\\mu-1t)}{\\mu_2 - \\mu_1}\\bigg) = t\\exp(\\mu_1t).$$\nNext we compute:\n$$\\lim_{\\mu_2 \\to \\mu_1}\\bigg(\\frac{\\mu_2\\exp(\\mu_1t) - \\mu_1\\exp(\\mu-2t)}{\\mu_2 - \\mu_1}\\bigg).$$\nWe observe that:\n$$\\frac{\\mu_2\\exp(\\mu_1t) - \\mu_1\\exp(\\mu-2t)}{\\mu_2 - \\mu_1} = \\bigg[\\frac{\\mu_1(\\exp(\\mu_2t) - \\exp(\\mu_1t)) + (\\mu_2 - \\mu_1) \\exp(\\mu_1t)}{\\mu_2 - \\mu_1}\\bigg]$$ $$= \\exp(\\mu_1t) - \\mu_1 \\bigg[\\frac{\\exp(\\mu_2t -\\exp(\\mu_1t)}{\\mu_2 - \\mu_1}\\bigg].$$\nThus $$\\lim_{\\mu_2 \\to \\mu_1}\\bigg(\\frac{\\mu_2\\exp(\\mu_1t) - \\mu_1\\exp(\\mu-2t)}{\\mu_2 - \\mu_1}\\bigg) = \\exp(\\mu_1t) - \\mu_1t\\exp(\\mu_1t).$$\nHence $$\\lim_{\\mu_2 \\to \\mu_1} y(t) = y_0(1 - \\mu_1 )\\exp(\\mu_1t) + v_ t \\exp(\\mu_1t).$$\nLet $$z(t) = y_0(1 - \\mu_1t )\\exp(\\mu_1t) + v_0 t \\exp(\\mu_1t).$$ Then\n$$\n\\begin{cases}\nz(0) = y_0 \\\\\nz'(t) = y_0(-\\mu_1 + \\mu_1(1 - \\mu_1t)) \\exp(\\mu_1t) + v_0(1+\\mu_1t)\\exp(\\mu_1t)\n\\end{cases}\n$$\ngiving $z'(0) = v_0.$\nLet $z(t) = (At+B)\\exp(\\mu_1t)$, where $A$ and $B$ are constants. We want to check that $$\\frac{d^2z}{dt^2}-2\\mu_1\\frac{dz}{dt}+{\\mu^2}_1z = 0.$$\nWe have $$z(t) = (At+B)\\exp(\\mu_1t) \\implies \\frac{dz}{dt} = (A +\\mu_1(At+B))\\exp(\\mu_1t) = (\\mu_1At + (A + \\mu_1 B))\\exp(\\mu_1t)$$ $$\\implies \\frac{d^2z}{dt2} = (\\mu_1At + (\\mu_1A +\\mu_1(A+\\mu_1B))\\exp(\\mu_1).$$\nHence\n$$\\frac{d^2z}{dt^2}-2\\mu_1\\frac{dz}{dt}+{\\mu^2}_1z = (({\\mu^2}_1A - 2\\mu_1*\\mu_1A +{\\mu^2}_1A)t + 2\\mu_1A +{\\mu^2}_1B - 2\\mu_1(A+\\mu_1B) +{\\mu^2}-1B)\\exp(\\mu_1t) = 0 \\mbox{ as required.}$$\n\\end{solution}\n\\end{example}\n\\begin{theorem}\nEvery solution of the equation $$\\frac{d^2y}{dt^2}-2y\\frac{dy}{dt} +\\mu^2y = 0$$ has the form $$y(t) = (At+B)\\exp(\\mu t)$$ for some appropriate constants $A$, $B$.\n\\end{theorem}\n\\begin{example}\nFind the general solution of $$\\frac{d^2y}{dt^2} + \\omega^2y = 0$$ where $\\omega>0$ is constant.\n\\begin{solution}\nWe look for a solution of the form $$y(t) = A\\exp(\\mu t)$$ and obtain the auxiliary quadratic $\\mu^2 + \\omega^2 = 0$, which has roots $\\mu_1 = i\\omega$, $\\mu_2 = -i\\omega$. Thus the general solution has the form $$y(t) = A\\exp(i\\omega t) + B\\exp(-i\\omega t)$$\n$$ = A(\\cos(\\omega t ) +i\\sin(\\omega t)) + B(\\cos(\\omega t) - i\\sin(\\omega t))$$ $$= (A+B)\\cos(\\omega t) +i(A-B)\\sin(\\omega t).$$\nSuppose $y(0) = y_0 \\in \\mathbb{R}$ and $y'(0) = v_0 \\in \\mathbb{R}.$ Then \n$$ \n\\begin{cases}\ny(0) = A+B = y_0 \\\\\ny'(0) = i\\omega(A-B) = V_0\n\\end{cases} $$\nThus $y(t) = y_0\\cos(\\omega t) + v_)\\frac{\\sin(\\omega t)}{\\omega}.$\n\\end{solution}\n\\end{example}\n\\begin{remark}\nObserve that $\\lim_{\\omega \\to 0}\\cos(\\omega t) = \\cos(0) = 1 \\mbox{ and } \\lim_{\\omega \\to 0}\\frac{\\sin(\\omega t)}{\\omega} = t$. When $\\omega = 0$, we get $$y(t) = y_0 + v_0t$$ which does indeed solve $\\frac{d^2y}{dt^2} = 0$.\n\\end{remark}\n\\begin{definition}\nLet $y_1$, $y_2$ be solutions of $$\\frac{d^2y}{dt^2} + a_1(t)\\frac{dy}{dt} +a_0(t)y=0.$$ We say that $y_1$ and $y_2$ are linearly independent if and only if neither solution can be written as a constant multiple of the other.\n\\end{definition}\n\\begin{example}\nIn the previous example, $$y_1(t) = \\cos(\\omega t) \\mbox{ and }  y_2 = \\frac{\\sin(\\omega t)}{\\omega}$$ are linearly independent: so are $$y_1(t) = \\exp(i \\omega t) \\mbox{ and } y_2(t) = \\exp(-i \\omega t)$$  $$y_1(t) = \\cos(\\omega t) \\mbox{ and } y_2(t) = \\exp(i\\omega t).$$ However if $y_1t = \\cos(\\omega t)$ and $y_2(t) = 17 \\cos(\\omega t)$, are not linearly independent.\n\\end{example}\n\\begin{definition}\nLet $y_1$ and $y_2$ be two differentiable functions. The Wronskian (determinant) of $y_1$ and $y_2$ is the function $$W = \\det \\begin{bmatrix}\ny_1 \\hspace{4pt} y_2 \\\\\ny'_1 \\hspace{4pt} y'_2 \\\\\n\\end{bmatrix}\n= y_1y'_2 - y'_1y_2$$\n\\end{definition}\n\\subsubsection*{Objective}\nWe want to find a formula for the general solution of $$\\frac{d^2y}{dt^2} + a_1\\frac{dy}{dt} + a_0y = f$$ where the function $f$ on the right hand side is non-trivial. We assume that we know two lineralry independent solutions $y_1$ and $y_2$ of the homogeneous equation $$\\frac{d^2y}{dt^2}j + a_1\\frac{dy}{dt}j + a_0yj = 0 \\mbox{ for } j = 1,2.$$ We can look for a solution in the form $$y(t) = A_1(t) +A_2(t)y_2(t).$$ Differentiating, $$y'(t) = A_1(t)y'_1(x) + A_2(t)y'_2(t) + A'_1(t)y_1(t) + A'_2(t)y_2(t). $$\nWe impose the condition $A'_1y_1 +A'_2y_2 = 0$. Then we obtain by the second derivative $$y''(t) = A_1(t)y''_1(t) +A_2y''_2(t) + A'_1(t)y'_1(t) +A'_2(t)y'_2(t).$$ Combining the expressions for $y$, $y'$ and $y''$, we obtain $$y'' + a_1y +a_0y = A_1(y''_1 + a_1y'_1 + a_0y1) + A_2(y''_2 + a_1y'_2 + a_0y2) +A'_1y'_1+A'_2y'_2 = A'_1y'_1+A'_2y'_2 $$ because $y_1$ and $y_2$ solve the homogeneous equation. Using the original formula we see that our second equation for $A_1$ and $A_2$ is $$A'_1y'_1+A'_2y'_2 = f.$$ We write the equation for $A_1$ and $A_2$ as $$\\begin{bmatrix}\ny_1 \\hspace{10pt} y_2 \\\\\ny'_1 \\hspace{10pt} y'_2 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nA'_1 \\\\\nA'_2 \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n0 \\\\\nf \\\\\n\\end{bmatrix}\n$$\nwhich yields\n$$ \\begin{bmatrix}\nA'_1 \\\\\nA'_2 \\\\\n\\end{bmatrix} = \\frac{1}{W}\n\\begin{bmatrix}\ny'_2 \\hspace{10pt} -y_2 \\\\\n-y'_1 \\hspace{10pt} y_1 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n0 \\\\\nf \\\\\n\\end{bmatrix}\n= \\frac{1}{W}\n\\begin{bmatrix}\n-y_2f \\\\\ny_1f \\\\\n\\end{bmatrix}\n$$ This means $$ \\begin{cases}\nA'_1 = \\frac{-y_2 f}{W}\\\\\nA'_2 = \\frac{y_1 f}{W} \\end{cases}$$ giving\n$$\n\\begin{cases}\nA_1(t) = \\int_{t_0}^{t} \\frac{-y_2(x) f(x)}{W(x)} dx + \\alpha_1 \\\\\n\n\\bigskip\n\nA_2(t) = \\int_{t_0}^{t} \\frac{y-1(x) f(x)}{W(x)} dx +\\alpha_2\\\\\n\\end{cases}$$\nWhere $\\alpha_1$ and $\\alpha_2$ are constants of integration and $t_0$ can be chosen. Recalling that $$y(t) = A_1(t)y_1(t) + A_2(t)y_2(t)$$ we obtain \n$$ y(t) = \\int_{t_0}^{t} \\bigg( \\frac{y_1(x) y_2(t) - y_1(t) y_2(x)}{W(x)} \\bigg) f(x)dx +\\alpha_1 y_1(t) + \\alpha_2 y_2(t).$$\nThis formula is called the variation of parameters or variation of constants formula. \n\\begin{itemize}\n\\item $y$ is the general solution of $$y''+a_1y'+a_0y = f$$\n\\item $a_1$, $a_0$ and $f$ are given functions.\n\\item $y_1$, $y_2$ are the solutions of the homogeneous equation $$y''_j +a_1y'_j +a_0y_j = 0, \\hspace{6pt} j = 1,2$$\n\\item $W$ is the Wronskian $$ W = \\det \\begin{bmatrix}\ny_1 \\hspace{5pt} y_2 \\\\\ny'_1 \\hspace{5pt} y'_2\\\\\n\\end{bmatrix} = y_1y'_2 - y'_1y_2$$\n\\end{itemize}\n\\begin{example}\nFind the general solution of the equation $$y'' - y = 1.$$\n\\begin{solution}\nThe corresponding homogeneous equation is $y''-y = 0$, with auxiliary quadratic $\\lambda^2 - 1 = 0$ having roots $\\lambda = \\pm 1$. Thus the functions $$\\begin{cases}\ny_1(x) = \\exp(+1x) \\\\\ny_2(x) = \\exp(-1x) \\\\\n\\end{cases}$$ \nare two linearly independent solutions of the homogeneous equation.  Hence $$W = \\det \\begin{bmatrix}\ny_1 \\hspace{5pt} y_2 \\\\\ny'_1 \\hspace{5pt} y'_2\\\\\n\\end{bmatrix} = \\det \\begin{bmatrix}\n\\exp(x) \\hspace{5pt} \\exp(-x)\\\\\n\\exp(x) \\hspace{5pt} -\\exp(-x)\\\\\n\\end{bmatrix} = -2.$$ For this example $f(x) = 1$. The variation of parameters formula gives $$y(t) = \\int_{t}^{t_0} \\frac{\\exp(x)\\exp(-t)-\\exp(t)exp(-x)}{(-2)}*1dx + \\alpha_1\\exp(t)+\\alpha_2\\exp(-t)$$ and we chose $t_0 = 0$ for convenience. Thus $$ y(t) = \\frac{-1}{2}\\exp(-t) \\int_{0}^{t}exp(x)dx +\\frac{1}{2}\\exp(t)\\int_{0}^{t}\\exp(-x)dx +\\alpha_1\\exp(t) +\\alpha_2\\exp(-t)$$ which yields $$y(t) = \\frac{-1}{2}\\exp(-t)[exp(t)-1]+\\frac{1}{2}\\exp(t)[1-exp(-t)]+\\alpha_1\\exp(t)+\\alpha_2\\exp(-t)$$ $$ = -1+(\\alpha_1 + \\frac{1}{2})\\exp(t) +(\\alpha_2 +\\frac{1}{2})\\exp(-t).$$ Hence $$y(t) = -1 +A_1\\exp(t) + A_2\\exp(-t).$$ Where $A_1$ and $A_2$ are constants.\n\\end{solution}\n\\end{example}\n\n\\bigskip\n\n\\begin{example}\nFind the general solution of $$\\frac{d^2y}{dt^2} - 4\\frac{dy}{dt} + 4y = t\\exp(2t).$$\n\\begin{solution}\nOur auxiliary quadratic is $$\\lambda^2 -4\\lambda + 4 = 0 \\mbox{ or } (\\lambda - 2)^2 = 0.$$ One solution of the homogeneous equation is $y_1(t) = \\exp(2t)$ and the second is $y_2(t) = t\\exp(2t).$ Thus $$ W = \\begin{bmatrix}\n\\exp(2t) \\hspace{44pt} t\\exp(2t) \\\\\n2\\exp(2t) \\hspace{12pt} (1+2t)\\exp(2t)\\\\\n\\end{bmatrix} = \\exp(4t)$$ Also $f(t) = t\\exp(2t)$. The variation of parameters formula gives $$y(t) = \\int_{0}^{t}\\frac{\\exp(2X)t\\exp(2t)-\\exp(2x)x\\exp(2t)}{\\exp(4(x)}x\\exp(2x)dx + (\\alpha_1+\\alpha_2t)\\exp(2t)$$ $$ =\\int_{0}^{t}(tx\\exp(2t) - x^2\\exp(2t))dx + (\\alpha_1+\\alpha_2t)\\exp(2t)$$ $$= t\\exp(2t)\\bigg[\\frac{x^2}{2}\\bigg]_{0}^{t} -\\bigg[\\frac{x^3}{3}\\bigg]_{0}^{t}\\exp(2t) +(\\alpha_1+\\alpha_2t)\\exp(2t).$$ Finally $$y(t) = \\frac{1}{6}t^3\\exp(2t)+(\\alpha_1+\\alpha_2t)\\exp(2t).$$\n\\end{solution}\n\\end{example}\n\n\\begin{theorem}\nLet $y_1$ and $y_2$ be linearly independent solutions of $$\\frac{d^2 y}{dt^2}+ a_1\\frac{dy}{dt}+a_0y = 0 $$ and let $y_p$ be any solution of the equation $$\\frac{d^2 y}{dt^2}+ a_1\\frac{dy}{dt}+a_0y = f, $$\nthen every solution $y$ of this equation has the form $$y(t) =y_p (t) + A_1y_1(t) + A_2y_2(t)$$ for the appropriate constants $A_1$ and $A_2$, furthermore for every pair of constants $A_1$ $A_2$ the function $y$ defined above and solves the homogeneous equation.The Proof for this will be given in year 2.\n\\end{theorem}\n\\subsubsection*{Guidelines for Guessing $\\mathbf{y_p}$}\n\\begin{enumerate}\n\\item If $f(t) = \\alpha \\exp (\\beta t)$, where $\\beta$ is not a root of the auxiliary quadratic, then there exists a particular solution $y_p$ of the form $$y_p(t) = \\gamma \\exp (\\beta t).$$ This is proven below.\n$$\\frac{d^2y_p}{dt^t}=\\beta^2 y_p$$ and so$$(\\beta^2 + a_1\\beta +a_0)y_p = \\alpha \\exp (\\beta t)$$ by canceling the common factor $\\exp (\\beta t)$ we get $$(\\beta^2 + a_1\\beta +a_0)\\gamma = \\alpha \\neq 0$$ since $\\beta$ is not a root of the auxiliary quadratic. Hence,\n$$\\gamma = \\alpha (\\beta^2 + a_1\\beta +a_0).$$\n\\item Suppose that the auxiliary quadratic has distinct root $\\lambda_1 \\neq \\lambda_2$ and that $$f(t) = \\alpha \\exp (\\lambda_1 t)$$ then there exists a solution of the form $$y_p(t) \\gamma t \\exp (\\lambda_1 t).$$ This again is proven below. $$\\frac{dy_p}{dt}=\\gamma \\exp (\\lambda_1 t) [1 + \\lambda_1 t]$$\n$$\\frac{d^2y_p}{dt^2}=\\gamma \\exp (\\lambda_1 t) [2\\lambda_1 + \\lambda_1^2 t]$$ Hence, $$\\frac{d^2 y_p}{dt^2}+ a_1\\frac{dy_p}{dt}+a_0y_p $$ $$=\\gamma \\exp (\\lambda_1 t) [2\\lambda_1 + \\lambda_1^2 t + a_1(\\lambda_1 t +1) + a_0 t]$$ $$= \\gamma \\exp (\\lambda_1 t) [t (\\lambda_1^2 + a_1\\lambda_1 + a_0) + 2\\lambda+1 +a_1]$$\nwe want this to be equal to $$f(t) = \\alpha \\exp (\\lambda_1 t)$$ which as $$(\\lambda_1^2 + a_1\\lambda_1 + a_0) = 0 $$ this holds precisely when $$\\gamma(2 \\lambda_1 + a_1)= \\alpha $$ as $a_1 = -\\lambda_1 -\\lambda_2$ and as a result $$\\gamma (\\lambda_1-\\lambda_2) = \\alpha$$ so\n$$\\gamma = \\frac{\\alpha}{(\\lambda_1-\\lambda_2}.$$\n\\item This deals with the case when the auxiliary quadratic has roots $\\lambda_1 = \\lambda_2$ and $$f(t)= \\alpha t + \\mu) \\exp (\\lambda_1 t)$$ this particular solution has the form  $$y_p(t) = q(t) \\exp (\\lambda_1 t) $$ of the form $$q (t) = a t^3  + bt^2$$\n\\item If $$f(t) = \\alpha_1 \\sin (\\beta_1 t) + \\alpha_2 \\cos (\\beta_2 t)$$ where $\\beta_1$ and $\\beta_2$ are real numbers and $i\\beta_1$ and $i\\beta_2$ are not solutions of the auxiliary quadratic. Then there exists a solution $$y_p(t) = [a_1 \\sin (\\beta_1 t) + c_1 \\cos (\\beta_1 t ) + a_2 \\sin (\\beta_2 t) + c_2 \\cos (\\beta_2 t ) ]$$ where $a_1, c_1, a_2, c_2$ are to be found.\n\\end{enumerate}\n\\section{Coupled Linear Systems}\nWe are interested in equations of the form $$\\frac{dx}{dt} = ax+by$$ $$\\frac{dy}{dt} = cx+dy$$ in which $a$, $b$, $c$ and $d$ are constant.\n\\subsubsection*{Solution Method 1}\nReduce to a single, second order equation. Differentiating the second equation you get $$\\frac{d^2y}{dt^2}= c\\frac{dx}{dt}+d\\frac{dy}{dt} = c(ax+by)+d\\frac{dy}{dt}$$ $$ = acx+bcy +d\\frac{dy}{dt}.$$ From our second equation, if $c\\neq 0$ then $$x = \\frac{1}{c}\\frac{dy}{dt}-\\frac{d}{c}y$$ and so $$\\frac{d^2y}{dt^2}= a\\frac{dy}{dt}-ady+bcy+d\\frac{dy}{dt}$$ or equivalently \n$$\\frac{d^2y}{dt^2}-(a+d)\\frac{dy}{dt}+(ad-bc)y=0.$$\nIf we write this system as $$\\begin{bmatrix}\n\\frac{dx}{dt}\\\\\n\\vspace{10pt}\n\\frac{dy}{dt}\\\\\n\\end{bmatrix} = \\begin{bmatrix}\na \\hspace{10pt} b \\\\\nc \\hspace{10pt} d \\\\\n\\end{bmatrix} * \\begin{bmatrix}\nx \\\\\ny \\\\\n\\end{bmatrix} =:A$$ Then $$\\frac{d^2y}{dt^2}-trace(A)\\frac{dy}{dt}+\\det(A)y = 0.$$\nIf $c \\neq 0$ then $x$ is obtained from $$x = \\frac{1}{c}\\frac{dy}{dt}-\\frac{d}{c}y.$$ If $c = 0$ and $b \\neq 0$ then elimiate $y$ and obtain $$\\frac{d^2x}{dt^2}-trace(A)\\frac{dx}{dt}+\\det(A)x = 0.$$ Then if $c=0=b$ and $$\\frac{dx}{dt} = ax$$ $$\\frac{dy}{dt} =dy$$ therefore they are no longer coupled.\n\\subsubsection*{Solution Method 2}\nLet $z = \\begin{bmatrix}\nx \\\\ \ny\n\\end{bmatrix}$ so that $$\\frac{dz}{dt}= Az, \\hspace{15pt} A = \\begin{bmatrix}\na \\hspace{10pt} b \\\\\nc \\hspace{10pt} d \\\\\n\\end{bmatrix}$$ We look for a solution $z(t) = v \\exp(\\lambda t)$ where $v$ is a constant vector and $\\lambda \\in \\mathbb{C}.$ Then $$ \\frac{dz}{dt} = v \\lambda\\exp(\\lambda t) \\implies Az = Av \\exp(\\lambda t)$$ which is equivalent to $$Av = \\lambda v.$$\nThis means that $v$ must be an eigenvector of $A$ with eigenvalue $\\lambda.$ The eigenvalues of a matrix $A$ satisfy $$\\det(A - \\lambda I ) = 0 $$ or  $$\\lambda^2 -(a+d)\\lambda +(ad-bc) = 0 $$ this is the same as the auxiliary quadratic of second order equation arising from method one.\n\n\\begin{example}\n\\smallskip\nSolve the coupled linear equations;\n$$\\frac{dz}{dt} = Az, \\hspace{15pt} A=\\begin{bmatrix}\n-2 &1 \\\\\n1 & -2 \\\\\n\\end{bmatrix}$$\n\\begin{solution}\nThe eigenvalues of $A$ solve, $$\\lambda^2 +4\\lambda +3 = 0 $$ this factorises to give $\\lambda = -3$ and $-1$ then we need the eigenvector for each, first $\\lambda = -1$ this eigenvector satisfies $$\\begin{bmatrix}\n-2- (-1) & 1\\\\\n1 & 2-(-1)\\\\\n\\end{bmatrix}v =0$$ so we take  $$v = \\alpha \\begin{bmatrix}\n\\frac{1}{\\sqrt[]{2}}\\\\\n\\frac{1}{\\sqrt[]{2}}\\\\\n\\end{bmatrix} \\hspace{15pt} \\alpha \\in \\mathbb{C}.$$\nSome true for $\\lambda -3$ that gives \n$$v = \\alpha \\begin{bmatrix}\n\\frac{1}{\\sqrt[]{2}}\\\\\n\\frac{1}{\\sqrt[]{2}}\\\\\n\\end{bmatrix} \\hspace{15pt} \\alpha \\in \\mathbb{C}$$\n\\end{solution}\n\\end{example}\n\n\n%------------------------------------------------\n\\endinput\n", "meta": {"hexsha": "efb48cb769e6301acb322922e90422d2d5a7636c", "size": 18570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L4/MA1001/Second_Order_Differentials.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/Second_Order_Differentials.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/Second_Order_Differentials.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": 67.0397111913, "max_line_length": 655, "alphanum_fraction": 0.6200323102, "num_tokens": 8023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6430449532310742}}
{"text": "\\documentclass[11pt, oneside]{amsart}   \t% use \"amsart\" instead of \"article\" for AMSLaTeX format\n\\usepackage[top=0.3cm, bottom=1.3cm, left=1cm, right=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\n\n\\title{MVA-DM3 Probabilistic graphical models}\n\\author{Hugo Cisneros}\n\\date{}\t\t\t\t\t\t\t% Activate to display a given date or no date\n\n\\begin{document}\n\\maketitle\n\\section{Implementation - HMM}\n\\textbf{1.2} For a set of parameters $\\theta$ in the Gaussian Mixture Hidden Markov model (GM-HMM), the complete likelihood can be written:\n\\begin{align*}\n\tl_c(\\theta) &= \\log\\left(p(q_0)\\prod_{t=0}^{T-1} p(q_{t+1}|q_t) \\prod_{t=0}^T p(\\overline{y}_t|q_t)\\right)\\\\\n\t\t&= \\sum_{i=1}^K \\delta(q_0 = i)\\log(\\pi_i) + \\sum_{t=0}^{T-1}\\sum_{i,j=1}^K\\delta(q_{t+1}=i, q_t=j)\\log(A_{i,j})+  \\sum_{t=0}^{T}\\sum_{i=1}^K \\delta(q_t = i) \\log \\mathcal{N}(\\overline{y}_t|\\mu_t, \\Sigma_t)\n\\end{align*}\n For the EM algorithm, we wish to compute the parameters of the HMM with the observations $(\\overline{y}_t)$. A lower bound of the likelihood is found by using Jensen's inequality with the $\\log$ function, which gives $ \\log p(\\overline{y}_0, ..., \\overline{y}_T) \\geq \\mathbb{E}_q[l_c(\\theta)]$. \n \n We use the notations $\\gamma(q_t)_i = p(q_t = i | \\overline{y}, \\theta)$ and $\\xi(q_{t+1}, q_t)_{ij} = p(q_{t+1}=i, q_t=j |  \\overline{y}, \\theta)$. The expression $ \\mathbb{E}_q[l_c(\\theta)]$ becomes \n \\[\n \\mathbb{E}_q[l_c(\\theta)] = \\sum_{i=1}^K\\gamma(q_0)_i\\log(\\pi_i) + \\sum_{t=0}^{T-1}\\sum_{i,j=1}^K\\xi(q_{t+1}, q_t)_{ij}\\log(A_{i,j})+  \\sum_{t=0}^{T}\\sum_{i=1}^K\\gamma(q_t)_i \\log \\mathcal{N}(\\overline{y}_t|\\mu_t, \\Sigma_t)\n \\]\n By maximizing w.r.t $\\pi$ and $A$ we get $\\boxed{\\pi_i = \\dfrac{\\gamma(q_0)_i}{\\sum_{j=1}^K\\gamma(q_0)_j}}$ and $\\boxed{A_{i,j} = \\dfrac{\\sum_{t=0}^{T-1}\\xi(q_{t+1}, q_t)_{ij}}{\\sum_{i=1}^K \\sum_{t=0}^{T-1}\\xi(q_{t+1}, q_t)_{ij}}}$. The other derivations are similar to the ones from the Gaussian Mixture model in Homework 2. \n \\\\\n \n We have : $\\boxed{\\mu_i = \\dfrac{\\sum_{t=0}^T \\gamma(q_t)_i \\overline{y}_t}{\\sum_{t=0}^T \\gamma(q_t)_i}}$ and $\\boxed{\\Sigma_i = \\dfrac{\\sum_{t=0}^{T}  \\gamma(q_t)_i  (\\overline{y}_t - \\mu_i)(\\overline{y}_t - \\mu_i)^T}{\\sum_{t=0}^T \\gamma(q_t)_i}}$ weighted sums of the empirical means and covariances.\n \\begin{figure}[!h]\n \\centering\n \\begin{subfigure}{.4\\textwidth}\n \\centering\n  \\includegraphics[width=.8\\linewidth]{full.pdf}\n  \\caption{Gaussian mixture}\n \\end{subfigure}\n   \\begin{subfigure}{.4\\textwidth}\n    \\centering\n \\includegraphics[width=.8\\linewidth]{training_gmhmm.pdf}\n \\caption{GM-Hidden markov model}\n \\end{subfigure}\n \\caption{Comparison of mixture of gaussian profile and cluster assignment (most probable sequence of hidden state for HMM) for the Gaussian mixture model and GM-HMM.}\n \\end{figure}\n \n \\textbf{1.5} The GM-HMM learns a slightly different mixture configuration than the GM model. The assumption that data is temporally distributed is strong and yields some artifacts such as outliers assigned to a very unlikely hidden state. However, the likelihood on both training data and test data is much higher than for the Gaussian mixtrure:  -2101.4 and -2201 for GM-HMM against -2340.2 for the training set and -2431 for the test set for the GM model.\n \n \\end{document}", "meta": {"hexsha": "b8ab017f8e0bb3fb75a5e1a647863932d92b0309", "size": 3831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework 3/MVA_DM3_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 3/MVA_DM3_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 3/MVA_DM3_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": 70.9444444444, "max_line_length": 458, "alphanum_fraction": 0.6854607152, "num_tokens": 1359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8652240877899776, "lm_q1q2_score": 0.6430068623264282}}
{"text": "\\subsection{Definition of Abstract Map}\nFor any concrete map $\\CMap$,\nif abstract key $\\AKey$ and abstract value $\\AVal$ is defined,\nand there exists a sound relation $\\wsf{isRelated}$ \nthat abstracts \\emph{may equal} of two abstract key valaues,\nwe can define a abstract map $\\AMap$.\\\\\n\n$\\begin{array}{l}\n\\poset(\\CMap) \\xrightarrow{\\alpha_{m}}\n\\AMap \\xrightarrow{\\gamma_{m}} \\poset(\\CMap) \\vspace{1mm} \\\\\n\\poset(\\CKey) \\xrightarrow{\\alpha_{k}} \n\\AKey \\xrightarrow{\\gamma_{k}} \\poset(\\CKey) \\\\\n\\poset(\\CVal) \\xrightarrow{\\alpha_{v}} \n\\AVal \\xrightarrow{\\gamma_{v}} \\poset(\\CVal) \\vspace{1mm} \\\\\n\\wsf{isRelated} \\in \\AKey \\times \\AKey \\rightarrow \\textbf{Boolean} \\\\\n\\end{array}$\\\\\\\\\nFormal definition of $\\alpha_m$ and $\\gamma_m$ are at section \\ref{sec:galois}.\\\\\nOur definition of abstract map consist of 2 parts:\n\\begin{enumerate}\n\\item $\\Map$ part which is a partial map from $\\AKey$ to $\\AVal$, and\n\\item $\\Defset$ part which is a set of definitely existing key values.\nThe size of $\\Defset$ may be infinite, \nfor example, bottom of $\\AMap$ has the whole $\\CKey$ as its $\\Defset$.\n\\end{enumerate}\n$\\begin{array}{l}\n\\hat{m},\\ \\langle \\emph{map},\\ \\emph{defset} \\rangle\n\\in \\AMap = (\\AKey \\rightarrowtail \\AVal)\n\\times \\poset(\\CKey)\\\\\n\\quad \\Map(\\langle \\emph{map},\\ \\emph{defset} \\rangle) = \n\\emph{map} \\in \\AKey \\rightarrowtail \\AVal \\\\\n\\quad \\Defset(\\langle \\emph{map},\\ \\emph{defset} \\rangle) = \n\\emph{defset} \\in \\poset(\\CKey) \\\\\n\\quad \\Dom(\\langle \\emph{map},\\ \\emph{defset} \\rangle) = \n\\{ \\hat{k} \\mid \\emph{map} \n\\textrm{ has a mapped value for key } \\hat{k} \\} \\in \\poset(\\AKey) \\\\\n\\end{array}$\n\n\\subsubsection{Partial Order and Join}\n$\\begin{array}{rl}\n\\hat{m}_1 \\po_m \\hat{m}_2 = & \n\\forall \\hat{k}_1 \\in \\Dom(\\hat{m}_1) \\cdot \n\\exists \\hat{k}_2 \\in \\Dom(\\hat{m}_2) :\n\\hat{k}_1 \\po_k \\hat{k}_2\n\\land \\Map(\\hat{m}_1)(\\hat{k}_1) \\po_v \\Map(\\hat{m}_2)(\\hat{k}_2) \\\\\n& \\land\\ \\Defset(\\hat{m}_2) \\subseteq \\Defset(\\hat{m}_1) \\\\\n\\end{array}$\\\\\\\\\n$\\begin{array}{l}\n\\hat{m}_1 \\sqcup_m \\hat{m}_2 =\n\\langle \\emph{map}_1 \\cup \\emph{map}_2 \\cup \\emph{map}_{\\cap},\\\n\\Defset(\\hat{m}_1) \\cap \\Defset(\\hat{m}_2) \\rangle \\\\\n\\quad \\begin{array}{rl} \\textrm{where} \n& \\emph{map}_1 = \\left \\{~ [ \\hat{k} \\mapsto \\Map(\\hat{m}_1)(\\hat{k}) ] ~\\mid~\n\\hat{k} \\in \\Dom(\\hat{m}_1) \n\\setminus \\Dom(\\hat{m}_2) ~\\right \\} \\\\\n& \\emph{map}_2 = \\left \\{~ [ \\hat{k} \\mapsto \\Map(\\hat{m}_2)(\\hat{k}) ] ~\\mid~\n\\hat{k} \\in \\Dom(\\hat{m}_2)\n\\setminus \\Dom(\\hat{m}_1) ~\\right \\} \\\\\n& \\emph{map}_{\\cap} = \\left \\{~ [ \\hat{k} \\mapsto \n\\Map(\\hat{m}_1)(\\hat{k}) \\sqcup_v \\Map(\\hat{m}_2)(\\hat{k}) ] ~\\mid~\n\\hat{k} \\in \\Dom(\\hat{m}_1) \n\\cap \\Dom(\\hat{m}_2) ~\\right \\} \\\\\n\\end{array} \\\\\n\\end{array}$\n\n\\subsubsection{Abstraction and Concretization} \\label{sec:galois}\nThe abstract map $\\AMap$ has Golois connection with concrete map $\\CMap$.\n\\begin{center}\n\\textbf{Theorem }\n$\\forall \\emph{mset} \\in \\poset(\\CMap), ~ \n\\forall \\hat{m} \\in \\AMap, ~\n\\alpha_m(\\emph{mset}) \\po_m \\hat{m}\n\\Longleftrightarrow\n\\emph{mset} \\subseteq \\gamma_m(\\hat{m})$\n\\end{center}\n$\\gamma_m$ and $\\alpha_m$ are defined as follow: \\\\\n\n$\\begin{array}{l}\n\\forall \\emph{mset} \\in \\poset(\\CMap) \\cdot \\\\ \n\\left \\{\n\\begin{array}{l}\n\\alpha_m(\\varnothing) = \\bot_m \\\\\n\\quad \\textrm{where } \\bot_m = \\langle \\varnothing,\\ \\textbf{String} \\rangle \\\\\n\\alpha_m(\\emph{mset}) =\n\\langle \\emph{map},\\ \\bigcap \\left \\{ \\Dom(m) \\mid m \\in \\emph{mset} \\right \\} \\rangle \\\\\n\\quad \\begin{array}{ll}\\textrm{where} \n& \\emph{map} = \\left \\{\n[ \\hat{k} \\mapsto \\alpha_{v}( \\{ m(k') \\mid m \\in \\emph{mset} \n\\land k' \\in \\Dom(m) \\land \\alpha_k(\\{k'\\}) = \\hat{k} \\} ) ]\n\\mid \\hat{k} \\in \\emph{S}  \\right \\} \\\\\n& \\emph{S} = \\left \\{ \n\\alpha_k(\\{k\\}) \\mid m \\in \\emph{mset} \\land k \\in \\Dom(m) \\right \\}\\\\\n\\end{array}\\\\\n\\end{array} \\right. \\\\\\\\\n\n\\forall \\hat{m} \\in \\AMap \\cdot \\\\\n\\quad \\gamma_{m}(\\hat{m}) = \\bigcup \\left \\{ \\emph{mset} ~\\mid~\n\\alpha_{m}(\\emph{mset}) \\po_m \\hat{m} \\right \\} \\\\\n\\end{array}$\\\\\\\\\\\\\n\\textbf{Monotonicity of $\\alpha_m$}\n\\begin{center}\n$\\forall \\emph{mset}_1, \\emph{mset}_2 \\in \\poset(\\CMap), ~\n\\emph{mset}_1 \\subseteq \\emph{mset}_2\n\\Rightarrow\n\\alpha_m(\\emph{mset}_1) \\po_m \\alpha_m(\\emph{mset}_2)$\n\\end{center}\n\\textbf{Proof } \n$\\forall \\emph{mset}_1, \\emph{mset}_2 \\in \\poset{\\CMap},~ \n\\emph{mset}_1 \\subseteq \\emph{mset}_2, ~$\n\\begin{itemize}\n\\item \\textbf{If} $\\emph{mset}_1 = \\varnothing$,\nsince $\\alpha_m(\\emph{mset}_1) = \\bot_m$,\n$\\alpha_m(\\emph{mset}_1) \\po_m \\alpha_m(\\emph{mese}_2)$.\n\\item \\textbf{If} $\\emph{mset}_2 = \\varnothing$,\n$\\emph{mset}_1$ must be $\\varnothing$ by $\\emph{mset}_1 \\subseteq \\emph{mset}_2$.\nThen $\\alpha_m(\\emph{mset}_1) = \\bot_m \\po_m \\alpha_m(\\emph{mset}_2)$.\n\\item\\textbf{If} $\\emph{mset}_1 \\neq \\varnothing$, and $\\emph{mset}_2 \\neq \\varnothing$, \\\\\nBy definition of $\\alpha_m$ and $\\po_m$, we need to prove that\n\\begin{enumerate}[label=({\\arabic*})]\n\\item $\\forall \\hat{k}_1 \\in \\emph{S}_1 \\cdot \\exists \\hat{k}_2 \\in \\emph{S}_2:\n\\hat{k}_1 \\po_k \\hat{k}_2 \\land \\emph{map}_1(\\hat{k}_1) \\po_v \\emph{map}_2(\\hat{k}_2) ~ $\nwhere \\\\\n$\\begin{array}{l}\n\\quad \\emph{map}_1 = \\left \\{[ \\hat{k}_1 \\mapsto \\alpha_{v}( \\{ m_1(k_1') \\mid m_1 \\in \\emph{mset}_1\n\\land k_1' \\in \\Dom(m_1) \\land \\alpha_k(\\{k_1'\\}) = \\hat{k}_1 \\} ) ]\n\\mid \\hat{k}_1 \\in \\emph{S}_1  \\right \\}\\\\\n\\land~ \\emph{map}_2 = \\left \\{[ \\hat{k}_2 \\mapsto \\alpha_{v}( \\{ m_2(k_2') \\mid m_2 \\in \\emph{mset}_2\n\\land k_2' \\in \\Dom(m_2) \\land \\alpha_k(\\{k_2'\\}) = \\hat{k}_2 \\} ) ]\n\\mid \\hat{k}_2 \\in \\emph{S}_2  \\right \\}\\\\\n\\land~ \\emph{S}_1 = \\{ \\alpha_k(\\{ k_1 \\}) \\mid m_1 \\in \\emph{mset}_1 \\land k_1 \\in \\Dom(m_1) \\} \\\\\n\\land~ \\emph{S}_2 = \\{ \\alpha_k(\\{ k_2 \\}) \\mid m_2 \\in \\emph{mset}_2 \\land k_2 \\in \\Dom(m_2) \\} \\\\\n\\end{array}$\n\\item $\\bigcap\\{ \\Dom(m_2) \\mid m_2 \\in \\emph{mset}_2\\} \\subseteq \n\\bigcap\\{ \\Dom(m_1) \\mid m_1 \\in \\emph{mset}_1\\}$\n\\end{enumerate}\nProve (1). \n\\begin{enumerate}[label={\\arabic*})]\n\\item For arbitrary $\\hat{k} \\in \\AKey$, $\\alpha_v(\\emph{vset}_1) \\po_v \\alpha_v(\\emph{vset}_2)$ where \\\\\n$\\begin{array}{l}\n\\quad \\emph{vset}_1 = \\{m_1(k_1') \\mid \nm_1 \\in \\emph{mset}_1 \\land k_1' \\in \\Dom(m_1) \\land \\alpha_k(\\{k_1'\\}) = \\hat{k} \\} \\\\\n\\land ~ \\emph{vset}_2 = \\{m_2(k_2') \\mid \nm_2 \\in \\emph{mset}_2 \\land k_2' \\in \\Dom(m_2) \\land \\alpha_k(\\{k_2'\\}) = \\hat{k} \\} \\\\\n\\end{array}$\\\\\nIf there is no $k_1' \\in \\Dom(m_1) \\land m_1 \\in \\emph{mset}_1$ such that $\\alpha_k(\\{k_1'\\}) = \\hat{k}$,\nthen $\\emph{vset}_1 = \\varnothing \\subseteq \\emph{vset}_2$.\\\\\nIf $m_1 \\in \\emph{mset}_1$ then $m_1 \\in \\emph{mset}_2$ as $\\emph{mset}_1 \\subseteq \\emph{mset}_2$.\nTherefore if there exists $k_1' \\in \\Dom(m_1) \\land m_1 \\in \\emph{mset}_1$ \nsuch that $\\alpha_k(\\{k_1'\\}) = \\hat{k}$,\nthen $\\emph{vset}_1 \\subseteq \\emph{vset}_2$.\\\\\nBy monotonicity of $\\alpha_v$, $\\alpha_v(\\emph{vset}_1) \\po_v \\alpha_v(\\emph{vset}_2)$.\n\\item $\\{ \\alpha_k(\\{ k_1 \\}) \\mid m_1 \\in \\emph{mset}_1 \\land k_1 \\in \\Dom(m_1) \\}\n\\subseteq \\{ \\alpha_k(\\{ k_2 \\}) \\mid m_2 \\in \\emph{mset}_2 \\land k_2 \\in \\Dom(m_2) \\}$ \\\\\nas $\\emph{mset}_1 \\subseteq \\emph{mset}_2$.\n\\end{enumerate}\nBy 1) and 2), $\\forall \\hat{k} \\in \\emph{S}_1, \n\\exists \\hat{k} \\in \\emph{S}_2: \\hat{k} \\po_k \\hat{k}\n\\land \\emph{map}_1(\\hat{k}) \\po_v \\emph{map}_2(\\hat{k})$ \\vspace{1mm}\\\\\nProve (2). It is obvious since $\\emph{mset}_1 \\subseteq \\emph{mset}_2$. \\vspace{1mm}\\\\\nThus $\\alpha_m(\\emph{mset}_1) \\po_m \\alpha_m(\\emph{mset}_2)$.\n\\end{itemize}\n\\textbf{Join morphism of $\\alpha_m$}\n\\begin{center}\n$\\forall \\emph{msetset} \\in \\poset(\\poset(\\CMap)), ~\n\\alpha_m(\\bigcup\\emph{msetset})\n=\\bigsqcup_m\\{ \\alpha_m(\\emph{mset}) \\mid \\emph{mset} \\in \\emph{msetset}\\}$\n\\end{center}\n\\textbf{Proof } $\\forall \\emph{msetset} \\in \\poset(\\poset(\\CMap))$\n\\begin{itemize}\n\\item \\textbf{If } $\\bigcup \\emph{msetset} = \\varnothing$, \nThen\n\\begin{enumerate}[label={\\arabic*)}]\n\\item $\\alpha_m(\\bigcup \\emph{msetset}) = \\bot_m$.\n\\item $\\forall \\emph{mset} \\in \\emph{msetset},~ \\emph{mset} = \\varnothing$.\\\\\nThus $\\bigsqcup_m\\{\\alpha_m(\\emph{mset}) \\mid \\emph{mset} \\in \\emph{msetset}\\}\n= \\bigsqcup_m \\{ \\bot_m \\mid \\emph{mset} \\in \\emph{msetset} \\}\n= \\bot_m$.\n\\end{enumerate}\nTherefore, \n$\\alpha_m(\\bigcup \\emph{msetset}) = \\bot_m\n= \\bigsqcup_m\\{\\alpha_m(\\emph{mset}) \\mid \\emph{mset} \\in \\emph{msetset}\\} $.\n\\item \\textbf{If }\n$\\bigcup\\emph{msetset} \\neq \\varnothing$, \nlet $\\hat{m}_l = \\alpha_m(\\bigcup \\emph{msetset})$\nand $\\hat{m}_r = \\bigsqcup_m\\{ \\alpha_m(\\emph{mset}) \\mid \\emph{mset} \\in \\emph{msetset} \\}$.\nThen we need to prove $\\Map(\\hat{m}_l) = \\Map(\\hat{m}_r) \n\\land \\Defset(\\hat{m}_l) = \\Defset(\\hat{m}_r)$. \\vspace{1mm} \\\\\nProve $\\Map(\\hat{m}_l) = \\Map(\\hat{m}_r)$.\n\\begin{enumerate}[label={\\arabic*)}]\n\\item $\\Dom(\\hat{m}_l) = \\Dom(\\hat{m}_r)$. \\vspace{1mm} \\\\\n$\\Dom(\\hat{m}_l) = \\{ \\alpha_k(\\{k\\}) \\mid m \\in \\bigcup\\emph{msetset} \\land k \\in \\Dom(m) \\}$\nby definition of $\\alpha_m$.\\\\\nFor arbitrary $\\hat{m}_1, \\hat{m}_2 \\in \\AMap$, \n$\\Dom(\\hat{m}_1 \\sqcup_m \\hat{m}_2) = \\Dom(\\hat{m}_1) \\cup \\Dom(\\hat{m}_2)$\nby definition of $\\sqcup_m$.\nThus $\\Dom(\\hat{m}_r) = \\bigcup \\{ \\Dom(\\alpha_m(\\emph{mset})) \\mid \\emph{mset} \\in \\emph{msetset} \\}$, and \\\\ \n$\\Dom(\\hat{m}_r ) = \\{ \\alpha_k(\\{k\\}) \n\\mid k \\in \\Dom(m) \\land m \\in \\emph{mset} \\land \\emph{mset} \\in \\emph{msetset} \\}$\nby definition of $\\alpha_m$. \\vspace{1mm} \\\\\nTherefore $\\Dom(\\hat{m}_l) = \\Dom(\\hat{m}_r)$.\n\\item $\\forall \\hat{k} \\in \\Dom(\\hat{m}_l) \\cdot \\Map(\\hat{m}_l)(\\hat{k}) = \\Map(\\hat{m}_r)(\\hat{k})$.\\\\\n$\\begin{array}{ll}\n& \\Map(\\hat{m}_l)(\\hat{k}) \\\\\n= & \\alpha_v(\\{ m(k') \\mid m \\in \\bigcup \\emph{msetset} \\land k' \\in \\Dom(m) \\land \\alpha_k(\\{k'\\}) = \\hat{k} \\})\n\\textrm{ by definition of } \\alpha_m.\\\\\n= & \\bigsqcup_v\\{ \\alpha_v(\\{ m(k') \\mid m \\in \\emph{mset} \\land k' \\in \\Dom(m) \\land \\alpha_k(\\{k'\\}) = \\hat{k} \\})\n\\mid \\emph{mset} \\in \\emph{msetset} \\} \\\\\n& \\textrm{ by Join morphism of } \\alpha_v.\\\\\n\\end{array}$ \\vspace{1mm} \\\\\n$\\forall \\hat{k} \\in \\Dom(\\hat{m}_l) \\cdot \\hat{k} \\in \\Dom(\\hat{m}_r)$ by 1). \\vspace{1mm}\\\\\n$\\begin{array}{ll}\n& \\Map(\\hat{m}_r)(\\hat{k}) \\\\\n= & \\bigsqcup_v\\{ \\Map(\\hat{m})(\\hat{k}') \n\\mid \\hat{k}' = \\hat{k} \\land \\hat{k}' \\in \\Dom(\\hat{m}) \n\\land \\hat{m} = \\alpha_m(\\emph{mset}) \\land \\emph{mset} \\in \\emph{msetset} \\} \\\\\n& \\textrm{ by definition of } \\sqcup_m.\\\\\n= & \\bigsqcup_v \\left \\{ \\emph{map}(\\hat{k})\n\\middle| \\begin{array}{l} \n\\emph{map} = \\left \\{ \\left[ \\hat{k} \\mapsto \\alpha_v \\left(\n\\left \\{ m(k') \\middle| \\begin{array}{l} \nm \\in \\emph{mset}\\\\\n\\land k' \\in \\Dom(m)\\\\\n\\land \\alpha_k(\\{k'\\}) = \\hat{k}\\end{array} \\right \\}\n\\right) \\right] \\middle| \\hat{k} \\in \\emph{S} \\right \\} \\\\\n~ \\land \\hat{k}' = \\hat{k} \\land \\hat{k}' \\in \\emph{S} \\\\\n~ \\land \\emph{S} = \\{ \\alpha_k(\\{k\\}) \\mid k \\in \\Dom(m) \\land m \\in \\emph{mset} \\}\n\\land \\emph{mset} \\in \\emph{msetset}\\\\\n\\end{array} \\right \\} \\\\\n& \\textrm{ by definition of } \\alpha_m.\\\\\n= & \\bigsqcup_v \\{ \\alpha_v(\\{ m(k') \\mid k' \\in \\Dom(m) \\land \\alpha_k(\\{ k' \\}) = \\hat{k} \n\\land m \\in \\emph{mset} \\}) \\mid \\emph{mset} \\in \\emph{msetset}\\}\\\\\n\\end{array}$ \\vspace{1mm}\\\\\nTherefore $\\forall \\hat{k} \\in \\Dom(\\hat{m}_l) = \\Dom(\\hat{m}_r) \\cdot \n\\Map(\\hat{m}_l)(\\hat{k}) = \\Map(\\hat{m}_r)(\\hat{k})$.\n\\end{enumerate}\nBy 1) and 2), $\\Map(\\hat{m}_l) = \\Map(\\hat{m}_r)$. \\vspace{2mm} \\\\\nProve $\\Defset(\\hat{m}_l) = \\Defset(\\hat{m}_r)$. \\vspace{1mm} \\\\\n$\\Defset(\\hat{m}_l) = \\bigcap \\left \\{ \\Dom(m) \\mid m \\in \n\\bigcup \\emph{msetset} \\right \\}$ and \\\\\n$\\Defset(\\hat{m}_r) = \\bigcap \\left \\{ \\bigcap \\{ \\Dom(m) \\mid m \\in \\emph{mset} \\} \\mid\n\\emph{mset} \\in \\emph{msetset} \\right \\}$ by definition of $\\alpha_m$ and $\\sqcup_m$. \\vspace{1mm} \\\\\nWe can simply write it again as follow: \\vspace{1mm} \\\\\n$\\bigcap \\left \\{ \\Dom(m) \\mid m \\in \\bigcup \\emph{msetset} \\right \\} \\\\\n= \\bigcap \\{ \\Dom(m) \\mid m \\in \\emph{mset} \\land \\emph{mset} \\in \\emph{msetset} \\} \\\\\n= \\bigcap \\left \\{ \\bigcap \\{ \\Dom(m) \\mid m \\in \\emph{mset} \\} \\mid \\emph{mset} \\in \\emph{msetset} \\right \\}$\n\\vspace{1mm} \\\\\nThus $\\Defset(\\hat{m}_l) = \\Defset(\\hat{m}_r)$. \\vspace{1mm} \\\\\nTo sum up, $\\hat{m}_l = \\hat{m}_r$. $i.e.$, \n$\\alpha_m(\\bigcup \\emph{msetset} )\n=\\bigsqcup_m\\{ \\alpha_m(\\emph{mset}) \\mid \\emph{mset} \\in \\emph{msetset}\\}$.\n\\end{itemize}\n\\textbf{Proof of Theorem }\n$\\forall \\emph{mset} \\in \\poset(\\CMap), ~ \n\\forall \\hat{m} \\in \\AMap, ~$\n\\begin{enumerate}[label={(\\arabic*)}]\n\\item\n$\\alpha_m(\\emph{mset}) \\po_m \\hat{m}\n\\Rightarrow\n\\emph{mset} \\subseteq \\gamma_m(\\hat{m})$ \\\\\nIt is obvious by the definition of $\\gamma_m$. \\hfill $\\square$\n\\item\n$\\emph{mset} \\subseteq \\gamma_m(\\hat{m})\n\\Rightarrow\n\\alpha_m(\\emph{mset}) \\po_m \\hat{m}$ \\\\\n$\\emph{mset} \\subseteq \\gamma_m(\\hat{m})\n\\Rightarrow \\alpha_m(\\emph{mset}) \\po_m \\alpha_m(\\gamma_m(\\hat{m}))$\nby \\textbf{Monotonicity of $\\alpha_m$}.\\\\\n$\\alpha_m(\\gamma_m(\\hat{m})) = \n\\alpha_m(\\bigcup\\{ \\emph{mset}' \\mid \\alpha_m(\\emph{mset}') \\po_m \\hat{m}\\}) = \n\\bigsqcup_m\\{\\alpha_m(\\emph{mset}') \\mid \\alpha_m(\\emph{mset}') \\po_m \\hat{m} \\}$\nby the definition of $\\gamma_m$ and \\textbf{Join morphism of $\\alpha_m$}. \\\\\n$\\bigsqcup_m\\{\\alpha_m(\\emph{mset}') \\mid \\alpha_m(\\emph{mset}') \\po_m \\hat{m} \\}\n\\po_m \\hat{m}$, therefore $\\alpha_m(\\emph{mset}) \\po_m \\hat{m}$. \\hfill $\\square$\n\\end{enumerate}\n", "meta": {"hexsha": "773440b99f08b39d5f5b63bf43f64e5cc77b99d7", "size": 13081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/obj/absmap.tex", "max_stars_repo_name": "aliahsan07/safe-development", "max_stars_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-25T12:53:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T23:29:49.000Z", "max_issues_repo_path": "doc/obj/absmap.tex", "max_issues_repo_name": "aliahsan07/safe-development", "max_issues_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "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/obj/absmap.tex", "max_forks_repo_name": "aliahsan07/safe-development", "max_forks_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T21:38:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T21:38:53.000Z", "avg_line_length": 47.7408759124, "max_line_length": 116, "alphanum_fraction": 0.6112682517, "num_tokens": 5843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6429906948888662}}
{"text": "\n\\documentclass[modern,trackchanges]{aastex63}\n\n\\input{stylez}\n\\usepackage{graphicx}\n\n\\begin{document}%\\raggedbottom\\sloppy\\sloppypar\\frenchspacing\n\n\\setlength{\\abovedisplayskip}{1.5em}\n\\setlength{\\belowdisplayskip}{1.5em}\n\n\\title{%\nAnalytic Planetary Transit Light Curves and Derivatives for Stars with Polynomial Limb Darkening\n}\n\n\n\\author[0000-0002-0802-9145]{Eric Agol}\\altaffiliation{Guggenheim Fellow}\n\\affil{Department~of~Astronomy, University~of~Washington, Seattle, WA}\n\\affil{Virtual~Planetary~Laboratory, University~of~Washington, Seattle, WA}\n\\author[0000-0002-0296-3826]{Rodrigo Luger}\n\\affil{Center~for~Computational~Astrophysics, Flatiron~Institute, New~York, NY}\n\\affil{Virtual~Planetary~Laboratory, University~of~Washington, Seattle, WA}\n\\author[0000-0002-9328-5652]{Daniel Foreman-Mackey}\n\\affil{Center~for~Computational~Astrophysics, Flatiron~Institute, New~York, NY}\n\n\\keywords{methods: analytic --- techniques: photometric --- planets and satellites: detection}\n\n\\begin{abstract}\nWe derive analytic, closed-form solutions for the light curve of a planet\ntransiting a star with a limb darkening profile which is a polynomial function\nof the stellar elevation, up to arbitrary integer order.\nWe provide improved analytic expressions for the uniform, linear, and quadratic\nlimb-darkened cases, as well as novel expressions for higher order integer powers\nof limb darkening.  The formulae are crafted to be numerically stable over the\nexpected range of usage.  We additionally present analytic formulae for\nthe partial derivatives of instantaneous flux with respect to the radius ratio,\nimpact parameter, and limb darkening coefficients.  These expressions are rapid to\nevaluate, and compare quite favorably in speed and accuracy to existing transit light\ncurve codes. We also use these expressions to numerically compute the first partial\nderivatives of exposure-time averaged transit light curves with respect to all\nmodel parameters.  An additional application is modeling eclipsing binary or\neclipsing multiple star systems in cases where the stars may be treated as spherically\nsymmetric.  We provide code which implements these formulae in \\texttt{C++}, \n\\texttt{Python}, \\texttt{IDL}, and \\texttt{Julia},\nwith tests and examples of usage.\n \\href{https://github.com/rodluger/Limbdark.jl}{\\color{linkcolor}\\faGithub}\n\\end{abstract}\n\n% ------------------------------------------------------------------------------\n%\n\\section{Introduction}\n\\label{sec:intro}\n% ------------------------------------------------------------------------------\n\nThe precise measurement of the transits of an exoplanet offers a host of information\nabout the planet's properties.  To start with, the times of transit give\nthe planet's orbital ephemeris.  The depth of transit, corrected for stellar\nlimb darkening, gives the planet's radius relative to that of the star.   The\nshape of the transit, especially the duration of ingress and egress relative to\nthe full transit duration, yields the orbital impact parameter of the planet.\nBeyond these basic properties, if the transit depth is seen to vary with wavelength,\nthe presence of spectral features may be used to constrain the chemical composition\nof the planet's atmosphere.  If the transit times are seen to vary, a dynamical\nmodel can constrain the masses of the planet companions (and vice versa).  If\nthe planet is seen in eclipse, its temperature, emission spectrum, and atmospheric\ncirculation pattern can be constrained.  When combined with radial velocity\nmeasurements, the bulk density of a planet can be inferred, yielding constraints\non its bulk composition.\n\nAnd yet, all of these inferences are predicated on the precise computation of models\nof the planetary transit which may be used to infer the model parameters.  Stars\nare non-uniform in brightness, with the general\ntrend of growing dimmer towards the limb, and so limb darkening must be accounted\nfor to accurately infer the planetary parameters \\citep{Csizmadia2018}.  Indeed, fast\nand accurate computation of limb-darkened transit light curve models has enabled the\ndetection and characterization of thousands of transiting exoplanets \\citep{MandelAgol2002}.\nThe most important ingredient to these models has been a description of the\nlimb darkening model which is flexible enough and accurate enough to describe the\nemission from a stellar photosphere.  Linear and quadratic limb darkening laws\nwere sufficient for lower-precision measurements; however, the measurement of\ntransit light curves has steadily improved in precision.  Higher order terms or non-linear laws\nhave become necessary to describe higher precision measurements \\citep{Kopal1950,Claret2000,\nGimenez2006}, which tend to involve more computational burden.\n\nIn addition to computing transit light curves, the derivatives of these light\ncurves with respect to the model parameters are also beneficial for accurate\ncharacterization of exoplanets.   The derivatives enable fast and stable\noptimization of the transit light curve parameters, which is critical for\nobtaining initial estimates for a Markov Chain Monte Carlo simulation\n\\citep[MCMC; e.g.][]{Ford2005,Ford2006},\nfor looking for multi-modal solutions, for initializing the multi-nest\nalgorithm \\citep{Feroz2008}, or for computing the Fisher information matrix.\nIn some cases, MCMC can be slow to converge, and derivatives can accelerate\nconvergence by adding an artificial momentum term to the log likelihood,\nand then allowing the sampler to follow contours of constant ``energy.''\nThis so-called ``hybrid'' or ``Hamiltonian'' MCMC approach holds great promise \\citep{Neal2011,Girolami2011,Betancourt2017},\nbut its application has been hampered by the lack of models with derivatives,\nas derivatives are in general more difficult to compute.\n\nFinally, the analytic computation of transit light curves with quadratic\nlimb darkening has a precision which can be limited by numerical round-off\nerror for parameters near some special cases.  In\nparticular, when the radius equals the impact-parameter, which corresponds to\nthe edge of the planet crossing the center of the star, the computation of the\nelliptic integrals becomes unstable.  At the second and third points of\ncontact, when the radius of the planet plus the impact parameter equals\nthe radius of the star, the elliptic integrals diverge logarithmically.  In the\nlimit that the impact parameter approaches zero, the equations can also\ndiverge.  All of these special cases are in principle encountered rarely,\nbut in practice with thousand of planets with tens to thousands of\ntransits each, along with hundreds to hundreds of thousands of light\ncurves with time sub-sampled for each exposure, these rare cases can\nbe encountered with some frequency.\n\nBased on these considerations, the primary goals of the current paper are\nthreefold:\n\\begin{enumerate}\n\\item To extend the analytic quadratic transit model to higher order limb darkening.\n\\item To compute the derivatives of the model analytically.\n\\item To stabilize the analytic light curve computation (and its derivatives)\nin all limits near special cases.\n\\end{enumerate}\nSecondary goals include modeling eclipsing binaries, for which the same\nconsiderations apply, and integrating the light curve model, and its\nderivatives, quickly and accurately over time to account for finite\nexposure times.\n\nSome progress has been made already towards these goals.  To describe this\nprogress, we pause first to introduce some notation.  Limb darkening models\nof spherical stars are parameterized with the cosine of the angle measured\nfrom the sub-stellar point, $\\upmu = \\cos{\\theta}$, where $\\theta$ is the\npolar angle on the photosphere, with $\\theta=0$ at the center of the observed\nstellar disk, and $\\theta=\\pi/2$ at the limb.  In a coordinate system in which\nthe projected disk of the star lies in the $x-y$ plane, and the $z$ coordinate\npoints towards the observer, then $\\upmu = z$, where $z$ is measured in units\nof the stellar radius.  The variable $\\upmu=z$ is then the elevation on the\nsurface of the star where the highest point is taken to be closest to the observer.\nIn terms of $b$, the normalized separation projected onto\nthe sky, this parameter is given by $\\upmu = \\cos{\\theta} =\\sqrt{1-b^2}$, where\n$0\\le b \\le 1$ within the stellar disk.  We also introduce the radius ratio,\n$r$, which is the radius of the occultor divided by the radius of the source.\nIn general, we will follow the notation\nintroduced by \\citet{starry} for the \\starry code package.\n\nUniform limb darkening scales as $I(\\upmu) \\propto \\upmu^0$, first-order\nlimb darkening as $I(\\upmu) \\propto \\upmu^1$, and second-order limb darkening\nas $I(\\upmu)\\propto \\upmu^2$; these are the three most commonly used  terms\nthat can be integrated analytically, which we describe in detail below\nin sections \\ref{sec:uniform}, \\ref{sec:reparam}, and \\ref{sec:quadratic}.\nThese are typically combined to yield the quadratic limb darkening law,\n%\n\\begin{equation} \\label{eq:quadraticld}\n    \\frac{I(\\upmu)}{I_0} = 1-u_1 (1-\\upmu) - u_2 (1-\\upmu)^2,\n\\end{equation}\n%\nwhere $u_1$ and $u_2$ are the limb darkening parameters, and\n$I_0 \\equiv I(1)$ is a normalization constant, equal to the\nintensity at the center of the stellar disk.\nIn this paper, we will show that higher order powers of $\\upmu^n$ with integer\n$n$ can be integrated analytically for $n > 2$ when expressed as recursion relations.\nLinear combinations of these laws can be constructed,\nwith various parameterizations, to describe stellar limb darkening more precisely.\n\nThe first goal of modelling higher-order limb darkening was accomplished\nby \\citet{Gimenez2006}, who derived transit light curves for a limb darkening\nfunction\n%\n\\begin{equation} \\label{eq:gimenez}\n    \\frac{I(\\upmu)}{I_0} = 1-\\sum_{n=1}^N a_n (1-\\upmu^n) \\quad,\n\\end{equation}\n%\nwhere $a_n$ is a limb darkening coefficient.  \\cite{Gimenez2006}\nfound an infinite series expansion for computing the limb-darkened light curve\nfor each $a_n$ term.  {\\bf This algorithm is remarkable in that it allows\nfor computation of limb-darkening to arbitrary polynomial order, and gives\nexcellent single-precision accuracy and better speed than numerical integration\napproaches.}  Here we {\\bf improve upon the pioneering work of \\citet{Gimenez2006}\nby presneting} closed-form expressions for these terms\nwhich can be easily computed with recursion relations, although for purposes\nof numerical stability we need to revert to series solutions in some limits\nwhich we find to be rapid to evaluate.  {\\bf In addition to being faster\nto evaluate and more accurate for low-order limb-darkening \n(\\S \\ref{sec:comparison_pytransit}), these new expressions\nalso include derivaties with respect to the model parameters.}\n\nThe second goal, of computing dervatives of the light curve with respect to\nthe model parameters, was accomplished by \\cite{Pal2008} for the quadratic\nlimb darkening case.  P\\'al derived the partial derivatives of the quadratic\nlimb darkening model with respect to $b$, $r$, and the two quadratic\nlimb darkening coefficients. In this work, we give modified expressions\nfor the quadratic limb-darkened flux and its derivatives which are\nmore numerically stable, as well as extend the computation of derivatives\nto higher order limb darkening.\n\nThe third goal, of numerical stability, has yet to be addressed in the literature.\nAlthough some numerical approaches are numerically stable, such as \\cite{Gimenez2006},\n\\cite{Kreidberg2015}, and \\cite{Parviainen2015}, these approaches tend to be\nslower, they have precisions which may depend upon the tolerance of the computation\nwhich is specified, and, in addition, they do not yield derivatives of the light curves.\nThe expressions presented in this work were derived with numerical stability in\nmind, and we show that for low order limb darkening our expressions are accurate\nto {\\bf double} precision in nearly all cases.\n\nA disadvantage of our approach is that it requires integer powers of the limb darkening\nexpansion.  \\citet{Claret2000} has shown that a non-linear limb darkening law,\nwith half-integer powers of $\\upmu$, gives an accurate description of stellar\nlimb darkening models.  More recently, the power-law model, $I(\\upmu) = 1-\nc_\\alpha(1-\\upmu^\\alpha)$ \\citep{Hestroffer1997} was shown to be an accurate\nlimb darkening law despite only using two parameters \\citep{Morello2017,Maxted2018}.\nWe were unable to find an analytic solution for these limb darkening\nlaws, but we will compare with these models below in \\S \\ref{sec:comparison}.\n\n%%%%%% REDUNDANT WITH THE NEXT SECTION\n% Before we proceed we need to introduce some additional notation.  We express the\n% flux of the star, $F$, as a linear combination of basis functions, $\\mathfrak{s}_i(r,b)$,\n% where $0 \\le i \\le N$, where $N$ is the order of the limb darkening.  Specifically,\n% the flux during a transit or occultation\n% is given by the inner product of $\\mathfrak{s}(r,b)$ with a vector of coefficients\n% $\\mathfrak{g}$ that depend only on the limb darkening coefficients:\n% %\n% \\begin{eqnarray}\n% F = I(1) \\mathfrak{s}^\\top \\mathfrak{g},\n% \\end{eqnarray}\n% %\n% where, as before, $I(1)$ is the normalization constant, equal to the\n% intensity at the center of the stellar disk.\n% %\n% As an example, in the quadratic limb darkening case, the flux is defined as\n% %\n% $\\mathfrak{s} = \\left(\\mathfrak{s}_0(r,b) \\,\\,\\,\\,\\,\\, \\mathfrak{s}_1(r,b) \\,\\,\\,\\,\\,\\, \\mathfrak{s}_2(r,b)\\right)^\\top$\n% %\n% is a vector in which each element depends solely on $b$ and $r$, while\n% %\n% $\\mathfrak{g} = \\left(1-u_1-\\tfrac{3}{2}u_2 \\,\\,\\,\\,\\,\\, u_1+2u_2 \\,\\,\\,\\,\\,\\, -\\tfrac{1}{4}u_2\\right)^\\top$\n% %\n% is a vector that depends only on the limb darkening coefficients. As we will see\n% later, reparameterizing the limb darkening coefficients in terms of the\n% $\\mathfrak{g}$ functions greatly simplifies the surface integrals. This is\n% analogous to the reparameterization in \\cite{starry} in terms of the ``Green's basis''.\n\n% We turn now towards presenting formulae for more accurate limb darkening transit,\n% occultation, and eclipse models, starting with the simplest case:  a source\n% of uniform surface brightness.\n\nThis paper is organized as follows. In \\S\\ref{sec:poly_limbdark}\nwe introduce the general form for polynomial limb darkening\nand define the notation used throughout the paper. In \\S\\ref{sec:uniform}--\\ref{sec:quadratic}\nwe derive updated equations for the well-known cases of uniform, linear, and\nquadratic limb darkening, and in \\S\\ref{sec:higher_order} we generalize the\nexpressions to limb darkening of arbitrary order.\n%\nWe discuss time integration of the equations (for finite exposure time)\nin \\S\\ref{sec:time}, an application to modeling non-linear limb\ndarkening in \\S\\ref{sec:nonlinear}, and details on the implementation\nof the algorithm in \\S\\ref{sec:implementation}. In \\S\\ref{sec:benchmark} and\n\\S\\ref{sec:comparison} we discuss timing benchmarks and comparisons to\nexisting codes. Finally, in \\S\\ref{sec:discussion}--\\S\\ref{sec:conclusions}\nwe discuss our assumptions, caveats of our modeling, applications of our\nalgorithm, and a summary of our results. Appendices A--C contain a list\nof errata for \\citet{MandelAgol2002}, derivatives of the general\ncomplete elliptic integral, and a comprehensive list of symbols used in\nthe paper.\n\nFinally, as in \\cite{starry} and \\cite{AprilFools}, we embed links\nto \\Python code (\\,\\codeicon\\,) to reproduce all of the\nfigures, as well as links to \\texttt{Jupyter} notebooks\n(\\,\\prooficon\\,) containing proofs and derivations\nof the principal equations. We urge members of the community to do the same\nto improve the accessibility, transparency, and reproducibility of\nresearch in astronomy.\n\n\n% ==============================================================================\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n%\n\n\\section{Polynomial Limb Darkening}\n\\label{sec:poly_limbdark}\n\nIn analogy with the quadratic\nlimb darkening law (Equation~\\ref{eq:quadraticld}), let us define the\ngeneralized polynomial limb darkening law of order $N$ as\n%\n%\n\\begin{align}\n    \\label{eq:polynomialld}\n    \\frac{I(\\upmu)}{I_0} &= 1 - u_1 (1 - \\upmu) - u_2 (1 - \\upmu)^2 -\n                                ... - u_{N}(1 - \\upmu)^{N} \\nonumber \\\\\n                          &= -\\sum_{i=0}^N u_i (1 - \\upmu)^i\n\\end{align}\n%\n%\\rodrigo{I think $u_0=1$, not $-1$, right?}\n%\\eric{There was a minus sign missing in front of the second line of the equation.}\nwhere we define $u_0 \\equiv -1$. In a right-handed Cartesian coordinate system centered\non the body, with the $z$-axis pointing to the observer,\n\\begin{equation}\\label{eq:xyz}\n\\upmu(x, y) = z(x, y) = \\sqrt{1 - x^2 - y^2}.\n\\end{equation}\n%\n%Although the foregoing analysis takes advantage of the existing formalism\n%in \\starry developed for occultation of spheres with arbitrary spherical harmonic\n%brightness, the problem can be simplified significantly for the limb darkening\n%case due to the azimuthal symmetry assumed for a star.  This simplification\n%leads to analytic expressions for the derivatives, which we find can be\n%evaluated with greater speed and accuracy compared with automatic differentiation.\n%\nIf we let $\\bvec{u}$ be the column vector of limb darkening coefficients\n$\\bvec{u} \\equiv (u_0 \\ u_1 \\ u_2 \\ ... \\ u_N)^\\mathsf{T}$\nand $\\ubasis$ be the \\emph{limb darkening basis}\n%\n\\begin{align}\n    \\label{eq:ldbasis}\n    \\ubasis = -\\begin{pmatrix}\n        1 & &\n        (1 - z) & &\n        (1 - z)^2 & &\n        ... & &\n        (1 - z)^N\n    \\end{pmatrix}^\\mathsf{T} \\quad,\n\\end{align}\n%\nwe may\nexpress Equation~(\\ref{eq:polynomialld}) more compactly as the\ndot product\n%\n\\begin{align}\n    \\label{eq:polynomialld_vec}\n    \\frac{I(z)}{I_0} &= \\ubasis^\\mathsf{T} \\bvec{u} \\quad .\n\\end{align}\n\nIn this paper, our task is to compute the flux, $F$, observed during a transit or occultation by\nintegrating this function over the visible area of the disk:\n%\n\\begin{align}\n    \\label{eq:occint}\n    F &=\n    \\oiint I(z) \\, \\dd S \\quad .\n\\end{align}\n%\nIn general, the surface integral in Equation~(\\ref{eq:occint}) is difficult---if not\nimpossible---to solve directly with $I(z)$ given by Equation~(\\ref{eq:polynomialld_vec}).\nHowever, as in \\citet{starry}, we note that the problem\nis made significantly more tractable if we first perform a couple change of basis\noperations.\n\n\\subsection{Change of basis}\n\\label{sec:change_of_basis}\nWe wish to find a basis in which to express the limb darkening profile that\nmakes evaluating Equation~(\\ref{eq:occint}) easier. This section follows\nclosely the discussion in \\citet{starry}, in which the authors first transform\nto a \\emph{polynomial basis}, whose terms are simple powers of the coordinates,\nand then to a \\emph{Green's basis}, whose terms make application of Green's\ntheorem convenient in reducing the surface integral to a one-dimensional line\nintegral.\n\nLet us define the transformation to the polynomial basis by the linear equation\n%\n\\begin{align}\n    \\label{eq:pbasis}\n    \\mathfrak{p} = \\mathcal{A}_1 \\bvec{u}\n\\end{align}\n%\nwhere $\\mathfrak{p}$ is the vector of limb darkening coefficients in the\npolynomial basis $\\pbasis$ and $\\mathcal{A}_1$ is a change of basis matrix.\nWe define the polynomial basis to be the power series in $z$,\n%\n\\begin{align}\n    \\label{eq:polybasis}\n    \\pbasis = \\begin{pmatrix}\n        1 & z & z^2 & z^3 & ... & z^N\n    \\end{pmatrix}^\\mathsf{T} \\quad.\n\\end{align}\n%\n\n%Note that $\\mathfrak{p}_0 \\equiv 1-\\sum_{n=1}^N \\mathfrak{p}_n = 1 - \\sum_{i=1}^N u_i$ in the formalism of \\citet{Gimenez2006}.\n\nThe transformation between vectors in $\\ubasis$ and vectors in\n$\\pbasis$ is straightforward. By the binomial theorem, we may write\nthe $i^\\mathrm{th}$ coefficient of $\\mathfrak{p}$ as\n%\n\\begin{equation}\n    \\label{eq:an_of_un}\n    \\mathfrak{p}_i = (-1)^{i+1}\\sum_{j=0}^N \\binom{j}{i} u_j.\n\\end{equation}\n%\nThe elements of the matrix $\\mathcal{A}_1$ are thus given by\n%\n\\begin{align}\n    \\label{eq:A1}\n    \\mathcal{A}_{1_{i, j}} = (-1)^{i+1}\\binom{j}{i} \\quad .\n\\end{align}\n%\nNote that, as with the limb darkening basis,\nthe specific intensity at a point may be written\n%\n\\begin{align}\n    \\label{eq:pbasis_intensity}\n    \\frac{I(z)}{I_0} &= \\pbasis^\\mathsf{T} \\mathfrak{p} \\nonumber \\\\\n                     &= \\pbasis^\\mathsf{T} \\mathcal{A}_1 \\mathbf{u}  \\quad .\n\\end{align}\n%\nNext, we transform to the Green's basis via the equation\n%\n\\begin{align}\n    \\label{eq:gbasis}\n    \\mathfrak{g} = \\mathcal{A}_2 \\mathfrak{p}\n\\end{align}\n%\nwhere $\\mathfrak{g}$ is the vector of limb darkening coefficients in the\nGreen's basis $\\gbasis$ and $\\mathcal{A}_2$ is another change of basis matrix.\nFor reasons that will become clear later in this paper,\nwe define the Green's basis to be\n%\n\\begin{align}\n    \\gbasis_n &=\n    \\begin{dcases}\n        1 & \\qquad n = 0\n        \\\\\n        z & \\qquad n = 1\n        \\\\\n        (n+2)z^n-n z^{n-2} & \\qquad n \\ge 2\n    \\end{dcases}\n    \\nonumber\\\\[0.5em]\n    \\gbasis &=\n    \\begin{pmatrix}\n        1 & &\n        z & &\n        4z^2 - 2 &&\n        5z^3 - 3z &&\n        ...\n    \\end{pmatrix}^\\mathsf{T}\n    \\quad,\n    \\label{eq:greensbasis}\n\\end{align}\n%\nGiven this definition, the columns of the change of basis matrix\n$\\mathcal{A}_2$ are the Green's basis vectors corresponding to each\nof the polynomial terms in Equation~(\\ref{eq:polybasis}). Note that\nin practice, it is more efficient to transform vectors in the $\\pbasis$\nbasis to vectors in the $\\gbasis$ basis via the\ndownward recursion relation\n%\n\\begin{equation}\n    \\label{eq:dn_of_an}\n    \\mathfrak{g}_n = \\frac{\\mathfrak{p}_n}{n+2} + \\mathfrak{g}_{n+2},\n\\end{equation}\n%\nstarting with $n=N$ and $\\mathfrak{g}_{N+1}=\\mathfrak{g}_{N+2}=0$.\n\nAs before, the specific intensity at a point may be written\n%\n\\begin{align}\n    \\label{eq:pbasis_intensity}\n    \\frac{I(z)}{I_0} &= \\gbasis^\\mathsf{T} \\mathfrak{g} \\nonumber \\\\[0.5em]\n                     &= \\gbasis^\\mathsf{T} \\mathcal{A}_2 \\mathfrak{p} \\nonumber \\\\[0.5em]\n                     &= \\gbasis^\\mathsf{T} \\mathcal{A} \\ \\mathbf{u} \\quad ,\n\\end{align}\n%\nwhere we define the complete change of basis matrix from limb darkening\ncoefficients to Green's coefficients\n%\n\\begin{proof}{A}\n    \\label{eq:A}\n    \\mathcal{A} \\equiv \\mathcal{A}_2 \\mathcal{A}_1 \\quad.\n\\end{proof}\n%\n%\nAs an example, the full change of basis matrix for $N = 5$ is\n%\n\\begin{proof}{A}\n    \\label{eq:Aexample}\n    \\mathcal{A} = \\left(\\begin{matrix}-1 & -1 & - \\frac{3}{2} & - \\frac{5}{2} \n    & - \\frac{13}{3} & - \\frac{23}{3}\\\\0 & 1 & 2 & \\frac{18}{5} & \\frac{32}{5} \n& \\frac{80}{7}\\\\0 & 0 & - \\frac{1}{4} & - \\frac{3}{4} & - \\frac{5}{3} \n& - \\frac{10}{3}\\\\0 & 0 & 0 & \\frac{1}{5} & \\frac{4}{5} & \\frac{15}{7}\\\\0 & 0 & 0 & 0 \n& - \\frac{1}{6} & - \\frac{5}{6}\\\\0 & 0 & 0 & 0 & 0 & \\frac{1}{7}\\end{matrix}\\right) \\quad.\n\\end{proof}\n%\nThe link next to Equation~(\\ref{eq:Aexample}) provides code\nto compute $\\mathcal{A}$ for any value of $N$.\n%\nFinally, for future reference, for the common case of quadratic limb darkening, the\nGreen's vector is given by the dot product of $\\mathcal{A}$ and the\nvector of limb darkening coefficients and is equal to\n%\n\\begin{proof}{A}\n    \\mathfrak{g} &= \\mathcal{A} \\bvec{u} \\nonumber \\\\\n                 &= \\left(1-u_1-\\tfrac{3}{2}u_2 \\,\\,\\,\\,\\,\\,\\,\\,\\, u_1+2u_2 \\,\\,\\,\\,\\,\\,\\,\\,\\, -\\tfrac{1}{4}u_2\\right)^\\top \\quad.\n\\end{proof}\n%\n\n\\subsection{Computing the surface integral}\n\\label{sec:theintegral}\n\nGiven our reparametrization in terms of Green's polynomials, we may\nre-write Equation~(\\ref{eq:occint}) as\n%\n\\begin{align}\n    \\label{eq:occint_greens}\n    F &= \\oiint I(z) \\, \\dd S \\nonumber \\\\[0.5em]\n      &= I_0 \\oiint \\gbasis^\\mathsf{T} \\mathcal{A} \\ \\bvec{u} \\, \\dd S \\,  \\nonumber \\\\[0.5em]\n      &= I_0 \\left( \\oiint \\gbasis (z) \\, \\dd S \\right)^\\mathsf{T} \\mathcal{A} \\ \\bvec{u} \\nonumber \\\\[0.5em]\n      &= I_0 \\, \\mathfrak{s}^\\mathsf{T} \\mathcal{A} \\bvec{u} \\quad ,\n\\end{align}\n%\nwhere\n%\n\\begin{align}\n    \\label{eq:solution_vector}\n    \\mathfrak{s} \\equiv \\oiint \\gbasis (z) \\, \\dd S\n\\end{align}\n%\nis the \\emph{solution vector}.\nIf we can find the general solution to the integral in Equation (\\ref{eq:solution_vector}),\nwe can compute the occultation flux for arbitrary order limb darkening.\nThe solutions for the case of uniform ($\\mathfrak{s}_0$), linear ($\\mathfrak{s}_1$),\nand quadratic ($\\mathfrak{s}_2$) limb darkening have been studied in\nthe past, so we dedicate sections \\S\\ref{sec:uniform}--\\ref{sec:quadratic}\nto revisiting existing formulae and algorithms for computing them, with both speed and numerical accuracy\nin mind. The subsequent section (\\S\\ref{sec:higher_order}) tackles the case of higher order\nlimb darkening.\n\n\n\\subsection{Normalization}\n\\label{sec:normalization}\n%\nBefore we discuss how to compute $\\mathfrak{s}$, we turn our attention to\nthe normalization constant $I_0$. It is convenient to\nchoose a normalization such that the total unocculted flux is unity (for some choice of units), \nregardless of the value of the limb darkening coefficients. We therefore require that\n%\n\\begin{align}\n    \\label{eq:normalization1}\n    F &= \\oiint I(z) \\, \\dd S \\nonumber \\\\\n      &= I_0 \\, \\mathfrak{s}^\\mathsf{T} \\mathcal{A} \\mathbf{u} \\nonumber \\\\\n      &= 1\n\\end{align}\n%\nwhen the integral is taken over the entire disk of the body. We must thus have\n%\n\\begin{align}\n    \\label{eq:normalization2}\n    I_0 &= \\frac{1}{\\mathfrak{s}^\\mathsf{T}_{r=0} \\mathcal{A} \\mathbf{u}} \\nonumber \\\\[0.5em]\n        &= \\frac{1}{\\mathfrak{s}^\\mathsf{T}_{r=0} \\mathfrak{g}} \\quad,\n\\end{align}\n%\nwhere $\\mathfrak{s}^\\mathsf{T}_{r=0}$ is the solution vector when there is no\noccultor (i.e., $r = 0$). When there is no occultor, the $n^\\mathrm{th}$ term of $\\mathfrak{s}$\ncorresponds to the double integral in polar coordinates\n%\n\\begin{align}\n    \\label{eq:normalization3}\n    \\mathfrak{s}_{n,r=0} &= \\int_0^{2\\pi}\\int_0^1 \\gbasisn(z) \\, r^\\prime \\, \\dd r^\\prime \\, \\dd\\theta \\nonumber \\\\[0.5em]\n                         &= 2\\pi \\int_0^1 \\gbasisn(z) \\, r^\\prime \\, \\dd r^\\prime \\quad,\n\\end{align}\n%\nFrom Equation~(\\ref{eq:greensbasis}), we may write\n%\n\\begin{align}\n    \\label{eq:normalization4}\n    \\mathfrak{s}_{n,r=0} &=\n    2\\pi\n    \\begin{dcases}\n        \\int_0^1 r \\, \\dd r & \\qquad n = 0\n        \\\\\n        \\int_0^1 z \\, r \\, \\dd r & \\qquad n = 1\n        \\\\\n        (n+2) \\int_0^1 z^n \\, r \\, \\dd r\n        - n \\int_0^1 z^{n-2} \\, r \\, \\dd r\n        & \\qquad n \\ge 2 \\quad.\n    \\end{dcases}\n\\end{align}\n%\nThe first case is trivial and integrates to $\\mathfrak{s}_{0,r = 0} = \\pi$.\nThe remaining cases involve integrands of the form $z^n r$,\nwhere $z = \\sqrt{1 - r^2}$. We may evaluate\nthese integrals by substituting $u = z^2 = 1 - r^2$ and $\\dd u = -2r \\, \\dd r$:\n%\n\\begin{align}\n    \\label{eq:normalization5}\n    \\int_0^1 z^n \\, r \\, \\dd r &= \\frac{1}{2} \\int_0^1 u^\\frac{n}{2} \\, \\dd u \\nonumber \\\\[0.5em]\n                               &= \\frac{1}{2 + n} \\quad.\n\\end{align}\n%\nThe solution vector then simplifies to\n%\n\\begin{align}\n    \\label{eq:normalization6}\n    \\mathfrak{s}_{n,r=0} &=\n    \\begin{dcases}\n        \\pi & \\qquad n = 0\n        \\\\\n        \\frac{2\\pi}{3} & \\qquad n = 1\n        \\\\\n        0 & \\qquad n \\ge 2 \\quad.\n    \\end{dcases}\n\\end{align}\n%\nInterestingly, the net flux contribution for all terms in the Green's basis with\n$n \\ge 2$ is exactly zero. We may finally evaluate our normalization constant:\n%\n\\begin{eqnarray}\n    \\label{eq:normalization}\n    I_0 &=& \\frac{1}{\\pi(\\mathfrak{g}_0+ \\tfrac{2}{3} \\mathfrak{g}_1)}.\n\\end{eqnarray}\n%\n\n\n\n\n\\section{Uniform brightness}\n\n\\label{sec:uniform}\n\nEvaluation of the transit light curve of a uniformly bright star, $I(\\upmu)=1$, \namounts to computing the\narea of overlap of two disks \\citep{MandelAgol2002}.  This has a well-known\nanalytic solution \\citep[e.g.][]{Weisstein2018};  however, we find that the\nstandard formula leads to round-off error that is larger than necessary\nor desirable.  In this section we present a new formula which we demonstrate\nyields {\\bf double} precision for the area of overlap, along with its derivatives.\n\nFigure \\ref{fig:circle_overlap} shows how the area of overlap can be computed\nfor two circles.  The sums of the areas of the sectors of each circle which span\nthe area of overlap, minus the area of a kite-shaped region which connects the\ncenters of the circles with their points of intersection gives the area of the\nlens-shaped region of overlap of the two circles.\n\n\\begin{figure}[t!]\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/overlap.pdf}\n    \\caption{The area of overlap of two circles can be computed as the sum of\n    the area of the sectors formed by the centers of each circle and the\n    boundary between the points of intersection, minus the area of the kite-shaped\n    region formed by the centers of the circles and the intersection points.\n    \\pycodelink{overlap}\\label{fig:circle_overlap}}\n    \\end{centering}\n\\end{figure}\n\nTaking the radius of the larger circle to be unity, the standard formula for\nthe lens-shaped overlap area is given by\n%\n\\begin{proof}{lens_area} \\label{eq:MAuniform}\nA_{lens} = \\pi \\Lambda^e(r,b) &=\n\\begin{dcases}\n0 & \\qquad 1+r \\le b,\\\\\nr^2 \\kappa_0 + \\kappa_1 -\\sqrt{\\frac{4b^2-(1+b^2-r^2)^2}{4}} & \\qquad \\vert 1-r\\vert < b \\le 1+r,\\\\\n\\pi r^2 & \\qquad b \\le 1-r,\\\\\n\\pi & \\qquad b \\le r-1,\\\\\n\\end{dcases}\n\\end{proof}\n\\citep[e.g.][]{MandelAgol2002}, where\n\\begin{eqnarray}\\label{eq:cosine_formulation}\n\\cos{\\kappa_0} &=& \\left(\\frac{(r-1)(r+1)+b^2}{2br}\\right),\\nonumber\\\\\n\\cos{\\kappa_1} &=& \\left(\\frac{(1-r)(1+r)+b^2}{2b}\\right),\n\\end{eqnarray}\n%\nwhere $\\kappa_0$ and $\\kappa_1$ are the angles defined in Figure \\ref{fig:circle_overlap}.\nThe second term in Equation~(\\ref{eq:MAuniform}) is the same as the standard formula for the area of overlap of two\npartially overlapping circles, with one of the circles scaled to a radius of unity\n\\citep{Weisstein2018}.  This term corresponds to ingress (and egress), it is the most\nexpensive to compute, and it is most subject to numerical inaccuracy;  we focus on this\nterm in what follows.\n\nWe find that numerical round-off error limits the precision of the ingress formula when\n$b \\approx 0$, $b+r \\approx 1$, or $b \\approx 1+r$;  these are the cases in which\nthe kite-shaped region becomes thin, in which the sum of two sides becomes similar\nin length to the spine of the kite.  The square root term in this formula (Equation\n\\ref{eq:MAuniform}) computes the area of the kite-shaped region, which in this\nform causes round-off error when the kite is flattened.  The same issue occurs when\ncomputing the area of a triangle in which two of the sides are of similar length;\nthe kite has an area that is twice the area of the {\\bf two mirror-image triangles}\nconnecting the centers\nof both circles and one of the intersection points.  \\cite{Goldberg1991} gives a\nformula for precisely computing the area of a triangle, based on a method developed\nby William Kahan \\citep[later described in][]{Kahan2000}, which we use to compute\nthe area of the kite-shaped region,\n\\begin{eqnarray}\\label{eq:Kite_area}\nA_{kite} &=& \\frac{1}{2}\\sqrt{(A+(B+C))(C-(A-B))(C+(A-B))(A+(B-C))},\n\\end{eqnarray}\nfor $A \\ge B \\ge C$, where the tuple $\\{A,B,C\\}$ equals $\\{1,r,b\\}$\nsorted from from greatest to least.  Note that the order of operations\nneeds to be carried out as specified by the series of parentheses in\nthe entry to the square root;  this sequence of operations preserves\nnumerical precision. {\\bf This formula is a novel implementation of Heron's\nformula for a triangle for which loss of precision occurs due to subtracting \nquantities with similar numerical values which differ at high significant digits,\nand thus are more subject to round-off errors.}\n\nNext, the inverse cosine formulae are also imprecise when $\\cos{\\kappa_0} = x_0 \\approx\n1$ or $\\cos{\\kappa_1} = x_1 \\approx 1$.  The approximate solutions in this limit\nare $\\kappa_0 \\approx [2(1-x_0)]^{1/2}$ and $\\kappa_1 \\approx [2(1-x_1)]^{1/2}$, and so round-off\nerror can occur both in taking the difference of two numbers close to unity,\nand in taking the square root.\n\nInstead, we use the function $\\theta = \\mathrm{atan2}(y,x)$ with $y=\\sin{\\theta}$ and\n$x=\\cos{\\theta}$ to compute $\\kappa_0$ and $\\kappa_1$, which avoids the quadrant and\ndivision-by-zero problems of the $\\theta = \\tan^{-1}(y/x)$ function.  In addition\nto the cosine values above, we require the sine terms, which are given by\n\\begin{eqnarray}\n\\sin{\\kappa_0} &=& \\frac{A_{kite}}{br},\\nonumber\\\\\n\\sin{\\kappa_1} &=& \\frac{A_{kite}}{b},\n\\end{eqnarray}\nwhich can be derived from the area of the triangles formed by the centers of\nthe circles and one intersection point.\nNote that both $\\sin{\\kappa_0}$ and $\\cos{\\kappa_0}$ are divided by $br$, and\n$\\sin{\\kappa_1}$ and $\\cos{\\kappa_1}$ are divided by $b$, so that\nin the arctangent formula these denoninator terms cancel, which can improve\nnumerical stability for small values of $b$ or $r$; this cancellation does not happen\nin the arccosine case given in Equation~(\\ref{eq:cosine_formulation}).\n\nThis results in the following equations for the overlap area, $A_{lens}$, of two\npartially overlapping circles:\n\\begin{proof}{kite_area} \\label{eq:area_of_overlap}\nA_{lens} &= \\kappa_1 + r^2\\kappa_0 - A_{kite},\\nonumber\\\\\n\\kappa_0 &= \\mathrm{atan2}(2A_{kite},(r-1)(r+1)+b^2),\\nonumber\\\\\n\\kappa_1 &= \\mathrm{atan2}(2A_{kite},(1-r)(1+r)+b^2),\n\\end{proof}\nwith $A_{kite}$ given in Equation~(\\ref{eq:Kite_area}).\n\n\\begin{figure}[t!]\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/area_of_overlap_r01.pdf}\n    \\caption{Precision of formulae for the area of overlap of two circles with\n    radius ratio $r$.  Plotted are the regions near $b=1-r$ (second and third\n    points of contact) and $b=1+r$ (first and fourth points of contact) for\n    the standard formula (Equation \\ref{eq:MAuniform}, blue) and our new formula\n    (Equation \\ref{eq:area_of_overlap}, orange dots).\n    The high-precision calculation is shown in green dashed for comparison; this\n    is limited by the conversion of the result to double-precision. The\n    solid and empty circles (top) indicate the positions of the circles at the left\n    hand side of the axes.  In the left panels the horizontal dash-dotted grey line\n    indicates the limiting precision for representing $\\pi r^2$. \\jlcodelink{area_of_overlap_r01}\\label{fig:overlap_precision}}\n    \\end{centering}\n\\end{figure}\n\nThe performance of this formula relative to the standard formula is profiled\nin Figure \\ref{fig:overlap_precision} for $r=0.1$, a typical\nvalue for transiting exoplanets.  We have carried out\nthe computation in the \\texttt{Julia} language, both in double-precision\n(\\texttt{Float64}), and 256-bit precision (\\texttt{BigFloat}), and\nsubtracted the results to measure the numerical errors of the computation.\n\nWe find that the standard\nformula (Equation \\ref{eq:MAuniform}) approaches errors of $10^{-8}$\nin the limit of $b \\rightarrow 1-r$. This error exceeds the value\nof the area of the smaller circle minus the area of overlap for\nvalues of $1-r < b < 1-r+10^{-8}$.  Thus, even though this calculation\nis carried out in double precision, the precision achieved is of\norder single precision.  Likewise, for $b \\rightarrow 1+r$,\nthe error of the standard formula approaches $10^{-8}$, with the\nerror exceeding the value of the area of overlap for $1+r-10^{-8} <\nb < 1+r$.\n\nIn contrast, Equation~(\\ref{eq:area_of_overlap}) gives a precision\nthat is double-precision in both limits.  Figure\n\\ref{fig:overlap_precision} shows that Equation~(\\ref{eq:area_of_overlap})\ngives a precision of $\\approx 10^{-17}$ in the limit $b \\rightarrow\n1-r$ for $r=0.1$; this limit is due to the limiting precision of\nrepresenting $\\pi r^2$ in double-precision, which in this case\nis $\\pi r^2 / 2^{53} = 10^{-17.4}$, indicated with a dash-dot\ngrey line in the left hand panels of Figure \\ref{fig:overlap_precision}.\nAt the beginning of ingress/end of egress when $b \\approx 1+r$,\neven higher precision is achieved since the area of overlap approaches\nzero, as shown in the right hand panels of Figure \\ref{fig:overlap_precision}.\n\nFinally, we compute the corresponding element of the solution vector $\\mathfrak{s}_0$\nas\n%\n\\begin{eqnarray} \\label{eq:uniform}\n    \\label{eq:s0}\n    \\mathfrak{s}_0(r,b) &=& \\pi-A_{lens}\\nonumber\\\\\n                        &=&\\pi -\\kappa_1 - r^2\\kappa_0 + A_{kite},\n\\end{eqnarray}\n%\nWe note that instead of computing $\\kappa_1$,\nwe compute $\\pi-\\kappa_1 = -\\mathrm{atan2}(\\sin{\\kappa_1},\\cos{\\kappa_1})$,\nwhich leads to {\\bf double} precision as well. Note also that $\\mathfrak{s}_0$ is\nidentical to the first basis function ($s_0$) in the \\starry implementation\nfrom \\citet{starry}.\n\n\\subsection{Derivatives}\n\nThe partial derivatives of this formula with respect to the radius\nratio, $r$, and impact parameter, $b$, turn out to be straightforward:\n\\begin{proof}{dS0drb}\\label{eq:dS0_drb}\n\\frac{\\partial \\mathfrak{s}_0(r,b)}{\\partial r} &= -2r \\kappa_0,\\nonumber\\\\\n\\frac{\\partial \\mathfrak{s}_0(r,b)}{\\partial b} &= \\frac{2A_{kite}}{b},\n\\end{proof}\nwhich can be computed from the quantities already used in calculating $\\mathfrak{s}_0$.\nAt the contact points, when $b = \\vert 1\\pm r\\vert$, the derivatives are undefined.\nIn practice this can be a problen when taking finite-differences across\nthe discontinuous boundary, but with the analytic formulae, these points\nare a set of measure zero, and so we simply set the derivatives to zero\nat these points.\n\nIn the remainder of this paper we will need to use these formulae in computing\nthe higher order limb-darkened light curves.  In the next section, we revisit the formulae\nfor linear limb darkening.\n\n\\section{Linear limb darkening}\n\\label{sec:reparam}\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n% ==============================================================================\n\nWe now turn to the case of linear limb darkening, $I(\\upmu)/I_0 = 1-u_1(1-\\upmu)$\n\\citep{Russell1912a,Russell1912b}.  In this section we set $I_0=1$ and $u_1=1$, so\nthat $I(\\upmu)=\\upmu$;  the general case can be computed as a linear\ncombination with the uniform case.\nNote that since $\\upmu = \\sqrt{1-x^2-y^2}$, this problem is equivalent to\ncomputing the volume of intersection between a sphere and a cylinder, which was\nsolved in terms of elliptic integrals by \\citet{Lamarche1990}.\nA similar solution was found by \\citet{MandelAgol2002}, who show that the total\nflux visible during the occultation of a body whose surface map is given by\n$I(x, y) = \\sqrt{1 - \\x^2 -\\y^2}$ may be computed as\n%\n\\begin{align}\n    \\label{eq:s1}\n    \\mathfrak{s}_1 = \\frac{2\\pi}{3} \\left(1 - \\frac{3\\Lambda(r,b)}{2} - \\Theta(r - b) \\right)\n\\end{align}\n%\nwhere $\\Theta(\\bigdot)$ is the Heaviside step function and\n%\n\\begingroup\\makeatletter\\def\\f@size{10}\\check@mathfonts\n\\def\\maketag@@@#1{\\hbox{\\m@th\\normalsize#1}}%\n\\begin{proof}{biglam}\n    \\label{eq:biglam}\n    \\Lambda(r,b) &=\n    \\begin{dcases}\n          % I don't think we need this: the k^2>1 term is stable as b --> 0!\n          %-\\frac{2}{3}\\left(1 - r^2\\right)^\\frac{3}{2}\n          %& \\qquad b = 0\n          %\n          %\\\\[1.5em]\n          %\n          \\frac{1}{9 \\pi \\sqrt{b r}} \\Bigg[\n                \\frac{(r + b)^2 - 1}{r + b}\n                \\Big(\n                    -2r \\,\n                    \\big(\n                        2 (r + b)^2 + (r + b)(r - b) - 3\n                    \\big)\n                    K(k^2)\n                    &\\\\ \\phantom{XXXX}\n                    + 3 (b - r) \\, \\Pi\\big(k^2 (b + r)^2, \\, k^2\\big)\n                \\Big)\n                - 4 b r (4 - 7 r^2 - b^2) E(k^2)\n          \\Bigg]\n          %\n          & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2}{9 \\pi} \\Bigg[\n                \\big(1 - (r + b)^2\\big)\n                \\Bigg(\n                    \\sqrt{1 - (b - r)^2} \\,\n                    K\\left(\\frac{1}{k^2}\\right)\n                    + 3 \\left(\\frac{b-r}{(b+r)\\sqrt{1 - (b - r)^2}}\\right)\n                    &\\\\ \\phantom{XX}\n                    \\times \\Pi\\left(\\frac{1}{k^2(b+r)^2}, \\, \\frac{1}{k^2}\\right)\n                \\Bigg)\n                - \\sqrt{1 - (b - r)^2}\n                (4 - 7 r^2 - b^2)\n                E\\left(\\frac{1}{k^2}\\right)\n          \\Bigg]\n          %\n          & \\qquad k^2 \\ge 1\n    \\end{dcases}\n\\end{proof}\n\\endgroup\n%\nwith\n%\n\\begin{align}\n    \\label{eq:k2}\n    k^2 &= \\frac{1 - r^2 - b^2 + 2 b r}{4 b r}\n    \\quad.\n\\end{align}\nNote that $\\mathfrak{s}_1(r,b) = s_2(r,b)$ in the spherical harmonic expansion used in \\starry as\ndescribed in \\citet{starry}.\nFor the cases $b=r$, $b=1-r$, $b=0$, $r=0$, or $\\vert r-b\\vert \\ge 1$, there are special\nexpressions for $\\Lambda(r,b)$ given below.\n%\nIn the expressions above, $K(\\bigdot)$, $E(\\bigdot)$, and $\\Pi(\\bigdot, \\bigdot)$\nare the complete elliptic integrals of the first, second kind, and third kind,\nrespectively, defined as\n%\n\\begin{align}\n    \\label{eq:elliptic}\n    K(k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\frac{\\dd \\varphi}{\\sqrt{1 - k^2 \\sin^2 \\varphi}}\n    \\nonumber \\\\[0.5em]\n    E(k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\sqrt{1 - k^2 \\sin^2 \\varphi} \\, \\dd \\varphi\n    \\nonumber \\\\[0.5em]\n    \\Pi(n, k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\frac{\\dd \\varphi}{(1 - n \\sin^2 \\varphi)\\sqrt{1 - k^2 \\sin^2 \\varphi}}\n    \\quad.\n\\end{align}\nIn Equation~(\\ref{eq:biglam}) we have transformed the formulae from \\citet{MandelAgol2002} using\nEquation (17.7.17) from \\citet{Abramowitz1970} which yields equations that are better\nbehaved in the vicinity of $b=r$.\\footnote{Note that we corrected several typos\nin \\citet{MandelAgol2002}, which are listed in the Appendix.}  However, these elliptic\nintegrals are still subject to numerical instability as $r \\rightarrow 1-b$ and $r \\gg 1$.\nThe main issue is the logarithmic divergence of $K$ and $\\Pi$ as $k \\rightarrow 1$, as\nwell as numerical cancellations leading to round-off errors which occur in the\nlimit $k \\rightarrow 0$.\n\nThrough trial and error, we have found that these instabilities can be removed by combining\nelliptic integrals into a general complete elliptic integral defined by \\citet{Bulirsch1969} as\n\\begin{equation}\\label{eq:cel}\n\\mathrm{cel}(k_c,p,a,b) = \\int_0^{\\pi/2} \\frac{a\\cos^2{\\phi} + b\\sin^2{\\phi}}{\\cos^2{\\phi}+p\\sin^2{\\phi}} \\frac{d\\phi}{\\sqrt{\\cos^2{\\phi}+k_c^2\\sin^2{\\phi}}},\n\\end{equation}\nwhere $k_c = \\sqrt{1-m_k}$, and for $b+r \\ge 1$,\n$m_k=k^2$, while for $b+r \\le 1$, $m_k=1/k^2$.  The derivatives of\n$\\mathrm{cel}$ with respect to the input parameters are given in Appendix \\ref{app:cel_derivatives}.\nAlthough $k_c$ can be computed from\n$m_k$, we have found better numerical stability in computing $k_c$ analytically\nfrom $b$ and $r$:\n\\begin{align}\n    k_c &=\n    \\begin{dcases}\n     \\sqrt{\\frac{(b+r)^2-1}{4br}} & \\qquad k^2 \\le 1\\\\\n     \\sqrt{\\frac{1-(b+r)^2}{1-(b-r)^2}} & \\qquad k^2 > 1.\n   \\end{dcases}\n\\end{align}\nIn practice, we let the subroutine that computes $\\mathrm{cel}$ accept both\n$m_k$ and $k_c$ as input for numerical precision.\n\nTo transform the elliptic integrals in Equation~(\\ref{eq:biglam}) to $\\mathrm{cel}$,\nwe used the following relations from \\citet{Bulirsch1969}:\n\\begin{eqnarray} \\label{eq:cel_identities}\n\\lambda K(m_k) + q E(m_k) &=& {\\rm cel}(k_c,1,\\lambda+q,\\lambda+q k_c^2)\\\\\n\\lambda K(m_k) + q \\Pi(n,m_k) &=& {\\rm cel}(k_c,1-n,\\lambda+q,\\lambda (1-n) + q)\\\\\nE(m_k) &=& {\\rm cel}(k_c,1,1,1-m_k)\\\\\nE(m_k)-(1-m_k)K(m_k) &=& m_k \\, {\\rm cel}(k_c,1,1,0)\\\\\n\\Pi(n,m_k)-K(m_k)  &=& n \\, {\\rm cel}(k_c,1-n,0,1),\n\\end{eqnarray}\nnoting that \\citet{Bulirsch1969} uses a different sign convention for $\\Pi(n,m_k)$.\nIn particular, the expressions for $\\Pi(n,m_k)-K(m_k)$ and $E(m_k)-(1-m_k)K(m_k)$ are useful for eliminating\nthe singularities and cancellations which occur at $m_k=1$ when $b+r=1$ and $m_k=0$ when\n$r \\rightarrow \\infty$.  The general complete elliptic integral is evaluated\nwith the approach of \\citet{Bartky1938}, which uses recursion to approximate the\nintegral to a specified precision.\n\nThese elliptic integral transformations lead to the following numerically-stable\nexpression for the linear limb darkening flux, $\\mathfrak{s}_1(r,b)$, in which\n\\begin{proof}{biglam_stable}\n    \\label{eq:biglam_stable}\n    \\Lambda &=\n    \\begin{dcases}\n          0 & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          -\\tfrac{2}{3}(1-r^2)^{3/2} & \\qquad b = 0\\\\\n          \\tfrac{1}{3} - \\tfrac{4}{9\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\tfrac{1}{3} + \\tfrac{2}{9\\pi} {\\rm cel}\\left(k_c,1,m_k-3,(1-m_k)(2m_k-3)\\right) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          \\tfrac{1}{3} + \\tfrac{4r}{9\\pi} {\\rm cel}\\left(k_c,1,1-3m_k,m_k-1\\right) & \\qquad b= r > \\tfrac{1}{2}\\\\  % I think this equation may have a mistake [ ]  EA 7/17/2018\n          \\tfrac{2}{9\\pi}\\left[3\\cos^{-1}(1-2r) -2(3+2r-8r^2)\\sqrt{rb}-3\\pi\\Theta(r-\\tfrac{1}{2})\\right] & \\qquad b+r =1\\\\\n          \\frac{1-(b-r)^2}{9 \\pi \\sqrt{b r}} \\Bigg[\n                \\frac{(b+r)^2-1}{4br}(b^2-r^2){\\rm cel}(k_c,(b-r)^2(1-m_k),0,3)\n                &\\\\ \\phantom{XXXX}\n               - (3-6r^2-2br){\\rm cel}(k_c,1,1,0)-4brE(m_k)\n          \\Bigg]\n          %\n          & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2\\sqrt{1-(b-r)^2}}{9 \\pi} \\Bigg[\n                \\big(1 - (r + b)^2\\big)\n                {\\rm cel}(k_c,p,1+q,p+q) &\\\\ \\phantom{XXXX}\n                - (4 - 7 r^2 - b^2)\n                E\\left(m_k\\right)\n          \\Bigg]\n          %\n          & \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{proof}\nwhere\n\\begin{eqnarray}\nq &=& 3\\frac{b-r}{(b+r)(1-(b-r)^2)}\\nonumber\\\\\np &=& \\left(\\frac{b-r}{b+r}\\right)^2 \\frac{1-(b+r)^2}{1-(b-r)^2}\n\\end{eqnarray}\nin the $k^2 > 1$ case.  Note that in this equation the conditions\nshould be evaluated in the order they appear.\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[height=3in]{figures/julia/transit_linear.pdf}\n    \\caption{The intensity of a linearly limb-darkened star ($u_1=1$) being\n    eclipsed, $\\mathfrak{s}_1(r,b)$.\n    In the limit $b > r+1$, no eclipse occurs, so $\\mathfrak{s}_1=1$.  For $b < r-1$, the star\n    is completely eclipsed and $\\mathfrak{s}_1=0$.  In the limits $b=r$ and $b=1-r$, special\n    expressions must be used.\n    \\jlcodelink{transit_linear}\\label{transit_linear}}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[height=4in]{figures/julia/s2_machine.pdf}\n    \\caption{The accuracy of $\\mathfrak{s}_1(r,b)$ near $b=r$ (left panels) and\n    $b=1-r$ (right panels) for $\\epsilon = 10^{-8}$. The $x$-axes are impact parameter $b$,\n    while the $y$ axes in the top panels show $\\mathfrak{s}_1(r,b)$, with $r$\n    given in the legend of each panel. The middle panels plot\n    the difference $(\\mathfrak{s}_1(b\\pm\\epsilon,b)-\\mathfrak{s}_1(b,b))/\\epsilon$\n    and $(\\mathfrak{s}_1(1-b\\pm\\epsilon,b)-\\mathfrak{s}_1(1-b,b))/\\epsilon$. The bottom\n    panels show the numerical precision by the comparing double precision\n    computation with \\texttt{BigFloat} precision (256-bit). \\jlcodelink{s2_machine}\\label{s2_machine}}\n    \\end{centering}\n\\end{figure}\n\nThe $\\mathfrak{s}_1(r,b)$ function is plotted in Figure \\ref{transit_linear}. The\nfunction varies smoothly from the lower right where the disk is\nunocculted to the upper left where it is completely occulted.\nThere are several points which need to be handled separately as\nthe Equation~(\\ref{eq:biglam}) expressions become singular or are\nno longer valid;  the solid lines in Figure \\ref{transit_linear} show\nthese points.  When $b=0$, the integral over the center of the\ndisk simplifies greatly.  When $b=r=1/2$, at the intersection of\n$b=r$ and $b=1-r$, another simplification occurs.  For $b=r$,\nthe disk of the occultor crosses the center of the source;\nthis needs to be computed separately in the $r<1/2$, $r=1/2$,\nand $r>1/2$ limits.  The first and fourth contacts occur at\n$b=1+r$, where $\\mathfrak{s}_1=1$;  this is the upper bound to the $k^2 < 1$\nregion for $b+r >1$.\nFor $r \\ge 1$, the second and third contacts (at the start and\nend of complete occultation) occur when $b=1-r$, which is the\nlower  bound to the $k^2<1$ region when $b+r >1$.\nFor $r < 1$, the second and third contacts occur when $r=1-b$.\n\nNear these boundaries, the standard \\citet{MandelAgol2002} expressions\ncan become singular, and so we paid particular care to the accuracy of these\nnew expressions in these regions.  Figure \\ref{s2_machine} shows\nthat Equation~(\\ref{eq:biglam_stable}) is accurate to machine\nprecision in all of these regimes.\nWe tested the accuracy by computing the equations with 256 bit\narithmetic, which is much less subject to round-off error, and\nhence gives more precise expressions than double precision.  We implemented the\npseudocode from \\citet{Bulirsch1969} to compute ${\\rm cel}(k_c,p,a,b)$,\nwhich has a termination test that scales as the square root of\nthe {\\bf double} precision.  We find that the transformed expressions\nare accurate to $\\la \\times 10^{-14}$ when computed in double precision\nwithin $\\epsilon = 10^{-8}$ of the vicinity of $b=r$ and $b=1-r$.\n\nFinally, in Figures~\\ref{fig:s2_plot_MA2002} and \\ref{fig:s2_plot} we plot\nthe relative numerical error in the flux of a linearly limb-darkened source\nwhen using the equations in \\citet{MandelAgol2002} and in this paper,\nrespectively, over a portion of the $b-r$ plane. The former method\n(Figure~\\ref{fig:s2_plot_MA2002}) yields errors\non the order of $10^{-7}$ over most of the domain, although the error approaches\nunity near the singular regions discussed above. In contrast, the method introduced\nin this paper (Figure~\\ref{fig:s2_plot}; note the change in the color scale)\nyields errors close to {\\bf double} precision everywhere, including the vicinity of the\nsingular points.\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[width=0.8\\linewidth]{figures/julia/s2_residuals_MA2002.pdf}\n    \\caption{The numerical error in computing the flux of an eclipsed, linearly\n             limb-darkened star ($u_1=1$) using the equations in \\citet{MandelAgol2002}.\n             \\jlcodelink{s2_residuals_MA2002}\\label{fig:s2_plot_MA2002}}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[width=0.8\\linewidth]{figures/julia/s2_residuals.pdf}\n    \\caption{The numerical error in computing the flux of an eclipsed, linearly\n    limb-darkened star ($u_1=1$) using the $\\mathfrak{s}_1(r,b)$ formalism introduced in this\n    paper. Compare to Figure~\\ref{fig:s2_plot_MA2002}, noting the change in the color\n    scale. The new method is eight orders of magnitude more precise on average,\n    approaching machine epsilon everywhere in the domain.\n    \\jlcodelink{s2_residuals}\\label{fig:s2_plot}}\n    \\end{centering}\n\\end{figure}\n\n%From \\citet{MandelAgol2002}, the total flux visible during the occultation of a\n%body whose surface map is given by $I(\\upmu)/I(1) = 1 - u_1(1 - \\upmu)$ may be computed\n%as\n%\\begin{eqnarray}\n%\\frac{F(u_1,r,b)}{F_0} &=& \\frac{\\pi(1-u_1)(1-\\Lambda^e)+ u_1 \\mathfrak{s}_1(r,b)}{\\frac{2\\pi}{3}u_1 + \\pi(1-u_1)},\\\\\n%&=& 1-(1-u_1/3)^{-1}\\left[(1-u_1)\\Lambda^e(r,b) + u_1\\left(\\Lambda(r,b)+\\tfrac{2}{3}\\Theta(r-b)\\right)\\right],\n%\\end{eqnarray}\n%where $F_0$ is the total unocculted flux.\n% Note:  I'm not using this in\n% transit_poly since it is not as precise as the starry expressions.\n\n\\pagebreak % DEBUG\n\n\\subsection{Derivatives}%\n%\nThe derivatives of $\\Lambda$ with respect to $r$ and $b$ are:\n%\n\\begingroup\\makeatletter\\def\\f@size{10}\\check@mathfonts\n\\def\\maketag@@@#1{\\hbox{\\m@th\\normalsize#1}}%\n\\begin{proof}{biglam_deriv}\n    \\label{eq:dbiglam_dr}\n    \\frac{\\partial \\Lambda}{\\partial r} &=\n    \\begin{dcases}\n          0\n          \\phantom{MMMMMMMMMMMMMMMMMMM} %viz hack\n          & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          2 r\\sqrt{1-r^2} & \\qquad b = 0\\\\\n           \\frac{2}{\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\frac{4r}{\\pi} E(4r^2) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          \\frac{2}{\\pi} \\mathrm{cel}(k_c,1,1,0) & \\qquad b= r > \\tfrac{1}{2}\\\\\n          \\frac{8r}{\\pi}\\sqrt{r(1-r)} & \\qquad b+r =1\\\\\n          \\frac{8br^2 E(k^2) + 2r(1-(b+r)^2)K(k^2)}{\\pi\\sqrt{br}}\n                    &\\\\ \\phantom{XX}\n          = \\frac{1}{\\pi\\sqrt{br}}\\mathrm{cel}(k_c,1,2r(1-(b-r)^2),0) & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} E(k^{-2})\n                    &\\\\ \\phantom{XX}\n          = \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} \\mathrm{cel}(k_c,1,1,k_c^2)& \\qquad k^2 > 1\n          \\\\\n    \\end{dcases}\n\\end{proof}\n\\endgroup\n%\nand\n%\n\\begingroup\\makeatletter\\def\\f@size{10}\\check@mathfonts\n\\def\\maketag@@@#1{\\hbox{\\m@th\\normalsize#1}}%\n\\begin{proof}{biglam_deriv}\n    \\label{eq:dbiglam_db}\n    \\frac{\\partial \\Lambda}{\\partial b} &=\n    \\begin{dcases}\n          0 & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          0 & \\qquad b = 0\\\\\n           -\\frac{2}{3\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\frac{4r}{3\\pi}\\mathrm{cel}(k_c,1,-1,k_c^2) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          -\\frac{2}{3\\pi} \\mathrm{cel}(k_c,1,1,2k_c^2) & \\qquad b= r > \\tfrac{1}{2}\\\\\n          -\\frac{8r}{3\\pi}\\sqrt{r(1-r)} & \\qquad b+r =1\\\\\n           \\frac{4r(r^2+b^2-1) E(k^2) + 2r(1-(b+r)^2)K(k^2)}{3\\pi\\sqrt{br}}\n                    &\\\\ \\phantom{XX}\n          = \\frac{1-(b-r)^2}{3\\pi \\sqrt{br}} \\mathrm{cel}(k_c,1,-2r,(1-(b+r)^2)/b) & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2}{3b\\pi}\\sqrt{1-(b-r)^2}\\left[(r^2+b^2-1) E(k^{-2}) +(1-(b+r)^2)K(k^{-2})\\right]\n                    &\\\\ \\phantom{XX}\n          =\\frac{4r}{3\\pi}\\sqrt{1-(b-r)^2}\\mathrm{cel}(k_c,1,-1,k_c^2) & \\qquad k^2 > 1,\\\\\n    \\end{dcases}\n\\end{proof}\n\\endgroup\n%\nwhere we have given some of the expressions in terms of both the standard elliptic integrals\nand the general elliptic integral.\n\n% Note that if we had included the radius of the source star in these formulae,\n% then the derivatives with respect to the radius of the star yield the\n% transit light curve of a uniform, thin emission shell \\citep{Schlawin2010}.\n\nFrom these expressions, the derivatives of $\\mathfrak{s}_1$ are given by\n\\begin{eqnarray}\n\\frac{\\partial \\mathfrak{s}_1}{\\partial r} &=& -\\pi \\frac{\\partial \\Lambda}{\\partial r},\\\\\n\\frac{\\partial \\mathfrak{s}_1}{\\partial b} &=& -\\pi \\frac{\\partial \\Lambda}{\\partial b}.\n\\end{eqnarray}\n\nWe have tested these formulae with finite-difference derivatives evaluated at\n256-bit precision, and, as with the total flux term, we find that these are accurate\nto $\\la 2 \\times 10^{-15}$, close to {\\bf double} precision.\n\nWe next increase the power of limb darkening by one, $\\upmu^2$.\n\n\\section{Quadratic limb darkening}\n\\label{sec:quadratic}\n\nThe next order of limb darkening has been widely studied due to its\naccurate description of stellar atmospheres \\citep{Claret2000,MandelAgol2002,Pal2008}.\nWe summarize here the formulae for quadratic limb darkening for $I(\\upmu)=4\\upmu^2-2$%\n%with $\\mathfrak{g}_2 = 4\\mu^2-2$\n, along with the derivatives, using the transformed\nexpressions described above. The general quadratic case may be computed as\na linear combination with the foregoing uniform and linear cases.\n\nWe first give the formula for the function $\\eta(r,b)$, which is the term appearing\nin the quadratic limb darkening model only when $u_2 \\ne 0$\n\\citep{MandelAgol2002}. In terms of quantities we have defined above for the uniform case:\n\\begin{proof}{Eta}\n    \\label{eq:eta}\n    \\eta(r,b) &=\n    \\begin{dcases}\n          \\frac{1}{2\\pi}\\left[\\kappa_1+r^2(r^2+2b^2)\\kappa_0-\\frac{1}{2}(1+5r^2+b^2)A_{kite}\\right]\n          %\n          & \\qquad k^2 \\le 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{r^2}{2}(r^2+2b^2)\n          %\n          & \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{proof}\n%\nAs $\\kappa_0$, $\\kappa_1$, and $A_{kite}$ were already computed in the\nuniform case, these quantities are reused in the quadratic computation.\n\n\nWith this definition, the quadratic term, $\\mathfrak{s}_2(r,b)$ is given simply by\n%\\rodrigo{This definition doesn't agree with that given in the next section.\n%I'm thinking of changing this section to reflect the Green's basis defined in\n%the next section.}  It turns out this does agree with next section. I've changed the text in the intro to this section. -EA\n%\n\\begin{eqnarray}\n    \\label{eq:s2}\n    \\mathfrak{s}_2 &=& 2 \\mathfrak{s}_0 + 4\\pi \\eta - 2\\pi \\quad,\n\\end{eqnarray}\n%\nwhere $\\mathfrak{s}_0$ is defined in Equation (\\ref{eq:uniform}).\n\n%With the formulae for $\\mathfrak{s}_0$, $\\mathfrak{s}_1$, and $\\mathfrak{s}_2$, the light curve and derivatives\n%of quadratic limb darkening may be computed with Equations (\\ref{eq:occint_greens}) and\n%(\\ref{eq:derivatives}) given below.\n\n\\pagebreak % DEBUG\n\n\\subsection{Derivatives}\n%\nThe derivatives of $\\eta$ are given by:\n\\begin{proof}{Eta}\n    \\label{eq:detadr}\n    \\frac{\\partial \\eta}{\\partial r} &=\n    \\begin{dcases}\n          \\frac{2r}{\\pi}\\left[(r^2+b^2)\\kappa_0-2A_{kite}\\right]\n          %\n          & \\qquad k^2 \\le 1\n          %\n          \\\\[1.5em]\n          %\n          2r(r^2+b^2)\n          %\n          & \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{proof}\n%\nand\n%\n\\begin{proof}{Eta}\n    \\label{eq:detadb}\n    \\frac{\\partial \\eta}{\\partial b} &=\n    \\begin{dcases}\n          \\frac{1}{2b\\pi}\\left[4r^2b^2\\kappa_0-2(1+b^2+r^2)A_{kite}\\right]\n          %\n          & \\qquad k^2 \\le 1\n          %\n          \\\\[1.5em]\n          %\n          2br^2\n          %\n          & \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{proof}\n%\nwhere the derivatives of $\\mathfrak{s}_0$ are defined in Equation (\\ref{eq:dS0_drb}).\nThe derivatives of the $\\mathfrak{s}_2$ term are thus\n%\n\\begin{eqnarray}\n    \\frac{\\partial \\mathfrak{s}_2}{\\partial r} &=& 2 \\frac{\\partial \\mathfrak{s}_0}{\\partial r} + 4\\pi \\frac{\\partial \\eta}{\\partial r}, \\nonumber \\\\\n    \\frac{\\partial \\mathfrak{s}_2}{\\partial b} &=& 2 \\frac{\\partial \\mathfrak{s}_0}{\\partial b} + 4\\pi \\frac{\\partial \\eta}{\\partial b} \\quad.\n\\end{eqnarray}\n\nIn the following section we turn our attention to the general polynomial limb darkening case,\n$\\upmu^n$ with $n > 2$.  As discussed in \\citet{starry},\nthese terms may be expressed exactly as the sum of\nspherical harmonics with $m=0$. However, it is possible to exploit\nthe azimuthal symmetry of the limb darkening problem to\nderive far more efficient and accurate formulae, which we describe in the following section.\n\n\\section{Higher Order Limb Darkening}\n\\label{sec:higher_order}\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n% ==============================================================================\n\n%%%%%% REMOVED SECTION 5 INTRO\n\nHaving computed $\\mathfrak{s}_0$, $\\mathfrak{s}_1$, and $\\mathfrak{s}_2$,\nwe now seek a general expression for $\\mathfrak{s}_n$ for any $n > 2$.\nRecalling our definition of $\\mathfrak{s}$ as the surface integral of\nthe terms in the Green's basis,\n%\n\\begin{align}\n    \\mathfrak{s} \\equiv \\oiint \\gbasis (z) \\, \\dd S \\quad,\n\\end{align}\n%\nin this section we will use Green's theorem to re-express this two-dimensional\nintegral as a one-dimensional line integral over the boundary of the visible\nportion of the occulted body's disk. This is the same procedure adopted by\n\\citet{starry}, albeit with different basis functions.\nGiven $\\bvec{r} = x \\xhat + y \\yhat$, we may write\n%\n%\n\\begin{align}\n    \\label{eq:greens}\n    \\mathfrak{s} &=\n    \\oint \\bvec{G} (z) \\cdot \\dd \\bvec{r}\n    \\quad,\n\\end{align}\n%\nwhere $\\bvec{G}$ is a matrix whose $n^{\\mathrm{th}}$ row is the\nvector\n%\n\\begin{align}\n    \\label{eq:greens_n}\n    \\bvec{G}_n (z) = G_{n,x} (z) \\, \\xhat + G_{n,y} (z) \\, \\yhat \\quad .\n\\end{align}\n%\nThe components $G_{n,x}$ and $G_{n,y}$ are chosen such that\n%\n\\begin{align}\n    \\label{eq:DGg}\n    \\bvec{D} \\wedge \\bvec{G}_n &\\equiv \\frac{\\dd G_{n,y}}{\\dd \\x}\n                                     - \\frac{\\dd G_{n,x}}{\\dd \\y} \\nonumber \\\\\n                               &= \\gbasisn(z) \\quad.\n\\end{align}\n%\nAs in \\citet{Pal2012} and \\citet{starry}, the operation\n$\\bvec{D} \\wedge \\bvec{G}_n$ denotes the\n\\emph{exterior derivative} of $\\bvec{G}_n$.\n%\n%\n%Since the polynomial expansion only depends on $\\upmu = z =\\sqrt{1-x^2-y^2}$,\n%where $(x,y,z)$ are the coordinates of the unit sphere, we only require\n%Green's functions whose curl has dependence on $z$ for axially-symmetric\n%limb darkening.\n%\nFollowing \\citet{starry},\nif we choose the following form for\nEquation~(\\ref{eq:greens_n}),\n%\n\\begin{equation}\n\\mathbf{G}_n(z) = z^n (-y \\xhat + x \\yhat) \\quad,\n\\end{equation}\n%\nwe arrive at the expression presented in Equation~(\\ref{eq:greensbasis})\nfor the components of the Green's basis:\n%\n\\begin{align}\n\\gbasisn(z)   &= \\frac{\\dd {G_n}_y}{\\dd \\x} - \\frac{\\dd {G_n}_x}{\\dd \\y} \\nonumber \\\\[0.5em]\n%              &= 2 z^n + \\frac{dz^n}{dz} \\frac{z^2-1}{z} \\nonumber \\\\[0.5em]\n%              &= \\frac{1}{z} \\frac{d}{dz}\\left[ z^n(z^2-1)\\right] \\nonumber \\\\[0.5em]\n              &= (n+2)z^n-n z^{n-2}\n\\end{align}\n%\nfor $2 \\le n \\le N$.\n%\nNote that we already introduced the first three terms, $\\tilde{\\mathfrak{g}}_0 = 1$\n(uniform limb darkening), $\\tilde{\\mathfrak{g}}_1 = z$ (linear limb darkening),\nand $\\tilde{\\mathfrak{g}}_2 = 4z^2 - 2$ (quadratic limb darkening).\nSince we already know how to integrate them (\\S\\ref{sec:uniform}--\\ref{sec:quadratic}),\nwe treat them separately from the higher order terms.\n\n% MENTION THIS LATER: Note that the total flux of each term in this basis set, $\\tilde{\\mathfrak{g}}_n$, integrates\n% to zero for $2 \\le n \\le N$.\n\nReturning to \\eq{greens}, we note that the line integral consists of two arcs:\nan arc $\\mathcal{P}$ along the boundary of the occulting body and an arc $\\mathcal{Q}$ along the\nboundary of the occulted body. We may therefore write the $n^\\mathrm{th}$ component of\nthe solution vector as\n%\n\\begin{align}\n    \\label{eq:sn}\n    \\mathfrak{s}_n &= \\mathcal{Q}(\\bvec{G}_n) - \\mathcal{P}(\\bvec{G}_n)\n    \\quad,\n\\end{align}\n%\nwhere, as in \\citet{Pal2012} and \\citet{starry}, we define the \\emph{primitive integrals}\n%\n\\begin{align}\n    \\label{eq:primitivePdef}\n    \\mathcal{P}(\\bvec{G}_n) &\\equiv\n    \\int\\displaylimits_{\\pi-\\phi}^{2\\pi + \\phi}\n        \\big[ G_{n,y}(r c_\\varphi, b + r s_\\varphi) c_\\varphi -\n              G_{n,x}(r c_\\varphi, b + r s_\\varphi) s_\\varphi \\big] r \\dd \\varphi \\quad,\n    \\\\\n    %\n\\intertext{taken along the boundary of the occulting body of radius $r$, and}\n    %\n    \\label{eq:primitiveQdef}\n    \\mathcal{Q}(\\bvec{G}_n) &\\equiv\n    \\int\\displaylimits_{\\pi-\\lambda}^{2\\pi + \\lambda}\n        \\big[ G_{n,y}(c_\\varphi, s_\\varphi) c_\\varphi -\n              G_{n,x}(c_\\varphi, s_\\varphi) s_\\varphi \\big] \\dd \\varphi\n    \\quad,\n\\end{align}\n%\n%\ntaken along the boundary of the occulted body of radius unity.\n%\nFor convenience, we defined\n%\n$c_\\varphi \\equiv \\cos \\varphi$\n%\nand\n%\n$s_\\varphi \\equiv \\sin \\varphi$\n%\nand we used the fact that along the arc of a circle,\n%\n\\begin{align}\n    \\label{eq:dr}\n    \\dd \\bvec{r} &= -r s_\\varphi \\, \\dd \\varphi \\, \\xhat +\n                     r c_\\varphi \\, \\dd \\varphi \\, \\yhat\n    \\quad.\n\\end{align}\n%\nThe angles $\\phi$ and $\\lambda$ are the same as those used in\n\\citet{starry} (see their Figure~2) and are given by\n%\n$\\phi = \\kappa_0-\\pi/2$ and\n$\\lambda = \\pi/2 - \\kappa_1$ (c.f. Equation~\\ref{eq:area_of_overlap} and\nFigure~\\ref{fig:circle_overlap}).\n\n\nInserting our expression for $\\mathbf{G}_n$ into Equations~(\\ref{eq:primitivePdef})\nand (\\ref{eq:primitiveQdef}), we arrive at a fairly simple form for the primitive\nintegrals:\n%\n\\begin{align}\n    \\label{eq:primitiveP}\n    \\mathcal{P}(\\bvec{G}_n) &=\n    \\int\\displaylimits_{\\pi-\\phi}^{2\\pi + \\phi} z^n (r+b \\sin{\\varphi}) r d\\varphi\n    %\n\\intertext{and}\n    %\n    \\label{eq:primitiveQ}\n    \\mathcal{Q}(\\bvec{G}_n) &=\n    \\int\\displaylimits_{\\pi-\\lambda}^{2\\pi + \\lambda} z^n d \\varphi \\quad.\n\\end{align}\n\nConveniently, the primitive integral $\\mathcal{Q}(\\bvec{G}_n) = 0$ for\nall $n > 0$, since $z=0$ at the boundary of the star.\nSince we need not compute the integral for $n=0$, as we already\nfound a solution for uniform limb darkening in \\S\\ref{sec:uniform},\nour final task is to find the solution to Equation~(\\ref{eq:primitiveP}).\n\n\\pagebreak % DEBUG\n\n\\subsection{Solving the $\\mathcal{P}$ integral}\n\\label{sec:Pintegral}\n\nThe primitive integral\n$\\mathcal{P}(\\bvec{G}_n)$ can be rewritten as\n\\begin{equation}\n\\mathcal{P}(\\bvec{G}_n) =\n\\int_{\\pi-\\phi}^{2\\pi + \\phi} \\left(1-r^2-b^2-2br s_\\varphi\\right)^{\\frac{n}{2}} (r+b s_\\varphi) r d\\varphi,\n\\end{equation}\nwhere $s_\\varphi = \\sin{\\varphi}$.\nWe make the transformation $\\xi = \\tfrac{1}{2} \\left(\\varphi - \\tfrac{3\\pi}{2}\\right)$, yielding\n\\begin{equation}\\label{eq:greens_transformed}\n\\mathcal{P}(\\bvec{G}_n) =\n2r (4br)^{\\frac{n}{2}}\\int\\displaylimits_{-\\tfrac{\\kappa_0}{2}}^{\\tfrac{\\kappa_0}{2}}\n(k^2-\\sin^2\\xi)^{\\tfrac{n}{2}} (r-b + 2b \\sin^2 \\xi) d\\xi,\n\\end{equation}\nfor $2 \\le n \\le N$, where $\\kappa_0 = 2 \\sin^{-1}k$ for $k^2 \\le 1$ and\n$\\kappa_0 = \\pi$ for $k^2 > 1$.  We\nreuse the value of $\\kappa_0$ which was computed in the uniform limb darkening\ncase (\\S \\ref{sec:uniform}).\n\n%With these integrals defined, the basis functions for the lightcurve are given\n%by $\\mathfrak{s}_n$, where $\\mathfrak{s}_0$ is given for uniform limb darkening\n%in section \\ref{sec:uniform}, $\\mathfrak{s}_1$ is given by the linear limb-darkened\n%solution from section \\ref{sec:reparam}, and  $\\mathfrak{s}_n = \\mathcal{Q}(\\bvec{G}_n)\n%- \\mathcal{P}(\\bvec{G}_n) = -\\mathcal{P}(\\bvec{G}_n)$ for $2 \\le n \\le N$;\n%we have already given an alternate expression for $\\mathfrak{s}_2$ in section \\ref{sec:quadratic}.\n\nWe can express $\\mathcal{P}(\\bvec{G}_n)$ in terms of a sequence of integrals,\n$\\mathcal{M}_n(r,b)$, given by:\n\\begin{equation}\\label{eq:M_of_n}\n\\mathcal{M}_n(r,b) = (4br)^{n/2} \\int_{-\\kappa_0/2}^{\\kappa_0/2} (k^2-\\sin^2\\xi)^{\\tfrac{n}{2}} d\\xi,\n\\end{equation}\nin terms of which the primitive integral takes the particulary simple form\n\\begin{proof}{pofgn_v01}\\label{eq:primitive}\n\\mathcal{P}(\\bvec{G}_n) = (1+r^2-b^2)\\mathcal{M}_n - \\mathcal{M}_{n+2}.\n\\end{proof}\n\nThe integrals $\\mathcal{M}_n$ obey straightforward recursion relations\n\\begin{proof}{Mn_recursion}\\label{eq:Mn_recursion}\n%\\begin{eqnarray}\n\\mathcal{M}_n &= \\frac{1}{n} \\left[ 2(n-1) (1-r^2-b^2) \\mathcal{M}_{n-2} \\right.\\nonumber\\\\\n  &+ \\left. (n-2) (1-(b-r)^2)((b+r)^2-1) M_{n-4}\\right],\\\\[1em]\n\\mathcal{M}_n &= \\frac{(n+4)\\mathcal{M}_{n+4} - 2(n+3)(1-r^2-b^2)\\mathcal{M}_{n+2}}{(n+2)(1-(b-r)^2)((b+r)^2-1)},\n%\\end{eqnarray}\n\\end{proof}\nwhere the first relation may be used for upwards recursion in $n$ for $k^2 > \\frac{1}{2}$,\nand the second for downward recursion in $n$ otherwise.\nIn practice we replace $\\mathcal{M}_{n+2}$ in Equation~(\\ref{eq:primitive}) with\nthe recursion relation to obtain a more stable expression for $\\mathcal{P}(\\bvec{G}_n)$:\n\\begin{proof}{pofgn_v02}\\label{eq:PofGn_v02}\n\\mathcal{P}(\\bvec{G}_n) = 2r^2 \\mathcal{M}_n - \\frac{n}{n+2}\\left((1-r^2-b^2)\\mathcal{M}_n+(1-(b-r)^2)((b+r)^2-1)\\mathcal{M}_{n-2}\\right).\n\\end{proof}\n\nNote that these recursion relations involve every fourth term, so we need to compute\nthe first four terms analytically.  These are given by:\n\\begin{proof}{Mn_initial}\n\\mathcal{M}_0 &= \\kappa_0,\\nonumber\\\\\n\\mathcal{M}_1 &= 2 (4br)^{1/2} \\left[E(k^2)-(1-k^2)K(k^2)\\right],\\nonumber\\\\\n\\mathcal{M}_2 &= 4br\\left[(k^2-\\tfrac{1}{2}) \\kappa_0 + k\\sqrt{1-k^2}\\right],\\nonumber\\\\\n\\mathcal{M}_3 &= \\tfrac{2}{3}(4br)^{3/2} \\left[(4k^2-2)E(k^2)+(3k^2-2)(k^2-1)K(k^2)\\right],\n\\end{proof}\nfor $k^2 \\le 1$, while for $k^2 > 1$,\n\\begin{proof}{Mn_initial}\n\\mathcal{M}_0 &= \\pi,\\nonumber\\\\\n\\mathcal{M}_1 &= 2(1-(r-b)^2)^{1/2}E(k^{-2}),\\nonumber\\\\\n\\mathcal{M}_2 &= \\pi(1-b^2-r^2),\\nonumber\\\\\n\\mathcal{M}_3 &= \\tfrac{2}{3}(4br)^{3/2} k^3\\left[2(2-k^{-2})E(k^{-2})-(1-k^{-2})K(k^{-2})\\right].\n\\end{proof}\n%\n%\nWe re-express the elliptic integrals for $n=1$ and $n=3$ in terms of the cel integrals which\nwere already computed for the linear limb darkening case,\n\\begin{proof}{Mn_cel}\n\\mathcal{M}_1 &= 2 (4br)^{1/2} k^2 \\mathrm{cel}(k_c,1,1,0),\\nonumber\\\\\n\\mathcal{M}_3 &= \\tfrac{2}{3}(4br)^{3/2}k^2 \\left[ \\mathrm{cel}(k_c,1,1,k_c^2)+(3k^2-2) \\mathrm{cel}(k_c,1,1,0)\\right],\n\\end{proof}\nfor $k^2 \\le 1$, while for $k^2 > 1$,\n\\begin{proof}{Mn_cel}\n\\mathcal{M}_1 &= 2(1-(r-b)^2)^{1/2} \\mathrm{cel}(k_c,1,1,k_c^2),\\nonumber\\\\\n\\mathcal{M}_3 &= \\tfrac{2}{3}(1-(b-r)^2)^{3/2} \\left[(3-2k^{-2}) \\mathrm{cel}(k_c,1,1,k_c^2)+k^{-2} \\mathrm{cel}(k_c,1,1,0\\right].\n\\end{proof}\nwhere, as before, $k_c = \\sqrt{1-k^2}$ for $k^2 \\le 1$, and $k_c = \\sqrt{1-k^{-2}}$ for $k^2 > 1$.\n\nFor downward recursion, we compute the top four $\\mathcal{M}_n$ expressions, $N-3 \\le n \\le N$,\nin terms of series expansions.\nWhen $k^2 \\le 1$, the integrals may be expressed in terms of the following\nHypergeometric functions and infinite series,\n\\begin{proof}{Mn_series}\\label{eq:Mn_series}\n\\mathcal{M}_n &= (4br)^{n/2} k^{n+1} \\pi^{1/2} \\frac{\\Gamma{(1+\\tfrac{n}{2})}}{\\Gamma(\\tfrac{3}{2}+\\tfrac{n}{2})} \\,_2F_1(\\tfrac{1}{2},\\tfrac{1}{2};\\tfrac{3}{2}+\\tfrac{n}{2};k^2),\\nonumber\\\\\n&= (1-(r-b)^2)^{n/2} k \\sum_{j=0}^{j_{max}} \\alpha_j k^{2j},\\nonumber\\\\\n\\alpha_0 &= \\sqrt{\\pi} \\frac{\\Gamma(1+\\tfrac{n}{2})}{\\Gamma(\\tfrac{3}{2}+\\tfrac{n}{2})},\\nonumber\\\\\n\\alpha_j &= \\alpha_{j-1} \\frac{(2j-1)^2}{2j(1+n+2j)}.\n\\end{proof}\nAlthough $j_{max} = \\infty$, in practice we set $j_{max} = 100$, and the series is\ntruncated when a term goes below a tolerance specified by the numerical precision.\n\nWe find that upward recursion in $n$ is more stable for $k^2 > \\tfrac{1}{2} $,\nwhile downward recursion is more stable for $k^2 < \\tfrac{1}{2}$.  Note that\nthis differs from \\citet{starry}, for which downward recusion was also required for $k^2 > 2$.\n\n%With the computation of the light curves for the basis functions, $\\mathfrak{s}_n$, the final step is to\n%combine these to make the full light curve with limb darkening coefficients, which we describe\n%next.\n\n\\subsection{Analytic derivatives}\\label{sec:analytic_derivatives}\n\nThe derivatives of $\\mathcal{P}(\\bvec{G}_n)$ may be expressed simply as functions\nof $\\mathcal{M}_n$:\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{P}}{\\partial r} &=& 2r \\left[(n+2)\\mathcal{M}_n - n \\mathcal{M}_{n-2}\\right],\\\\\n\\frac{\\partial \\mathcal{P}}{\\partial b} &=& \\frac{n}{b} \\left[(r^2+b^2)(\\mathcal{M}_n - \\mathcal{M}_{n-2})+(r^2-b^2)^2\\mathcal{M}_{n-2}\\right].\n\\end{eqnarray}\nSince the $\\mathcal{M}_n$ integrals are computed for the total flux case,\nthere is little overhead for computing the derivatives.\n\nFor small values of $b$ we find that the derivative with respect to impact parameter \nbecomes numerically unstable due to the cancellation between the two\nterms, followed by division by $b$.  To avoid this problem\nfor small $b$, we have derived an alternative expression which avoids division by $b$\nwhich we utilize when $b < b_c$, where $b_c$ is a (small) cutoff value:\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{P}}{\\partial b} = n \\left[b\\mathcal{M}_n +(2r^3+b^3-3r^2b-b-3) \\mathcal{M}_{n-2}-4r^3\\mathcal{N}_{n-2}\\right],\n\\end{eqnarray}\nwhere we have defined a new integral, $\\mathcal{N}_n$,\n\\begin{equation}\\label{eq:N_of_n}\n\\mathcal{N}_n(r,b) = (4br)^{n/2} \\int_{-\\kappa_0/2}^{\\kappa_0/2} (k^2-\\sin^2\\xi)^{\\tfrac{n}{2}} \\sin^2{\\xi} d\\xi,\n\\end{equation}\nwhich obeys the recursion relation\n\\begin{proof}{Nn_recursion}\n\\mathcal{N}_n = \\frac{1}{n+2} \\left[\\mathcal{M}_n + n(1-(b+r)^2) \\mathcal{N}_{n-2}\\right].\n\\end{proof}\nSince this recursion relation involves every other term, we only need the two lowest terms,\nwhich are given by:\n\\begin{proof}{Nn_cel}\n\\mathcal{N}_0 &= \\tfrac{1}{2}\\kappa_0 - k k_c,\\nonumber\\\\\n\\mathcal{N}_1 &= \\tfrac{2}{3}(4br)^{1/2} k^2 \\left[-\\mathrm{cel}(k_c,1,1,k_c^2) + 2 \\mathrm{cel}(k_c,1,1,0)\\right],\n\\end{proof}\nfor $k^2 \\le 1$ and\n\\begin{proof}{Nn_cel}\n\\mathcal{N}_0 &= \\frac{\\pi}{2},\\nonumber\\\\\n\\mathcal{N}_1 &=  \\tfrac{2}{3}(4br)^{1/2} k \\left[2\\mathrm{cel}(k_c,1,1,k_c^2) - \\mathrm{cel}(k_c,1,1,0)\\right],\n\\end{proof}\nfor $k^2 > 1$.\n\nIn the $k^2 < \\tfrac{1}{2}$ limit, we find the upward recursion to be unstable, and so we evaluate the expressions for $\\mathcal{N}_{N}$ and $\\mathcal{N}_{N-1}$\nwith a series solution (as we did for $\\mathcal{M}_{N-3}$,\\, ...,\\, $\\mathcal{M}_N$):\n\\begin{proof}{Nn_series}\n    \\label{eq:Nn_series}\n    \\mathcal{N}_n &= (4br)^{n/2} k^{n+3} \\frac{\\pi^{1/2}}{2} \\frac{\\Gamma{(1+\\tfrac{n}{2})}}{\\Gamma(\\tfrac{5}{2}+\\tfrac{n}{2})} \\,_2F_1(\\tfrac{1}{2},\\tfrac{3}{2};\\tfrac{5}{2}+\\tfrac{n}{2};k^2) \\nonumber\\\\[0.5em]\n                  &= (1-(r-b)^2)^{n/2} k^3 \\sum_{j=0}^{j_{max}} \\gamma_j k^{2j}, \\nonumber\\\\[0.5em]\n    \\gamma_0 &= \\frac{\\sqrt{\\pi}}{2} \\frac{\\Gamma(1+\\tfrac{n}{2})}{\\Gamma(\\tfrac{5}{2}+\\tfrac{n}{2})},\\nonumber\\\\[0.5em]\n    \\gamma_j &= \\gamma_{j-1} \\frac{(4j^2-1)}{2j(3+n+2j)}.\n\\end{proof}\nWe then use downward recursion with the relation\n\\begin{equation}\n\\mathcal{N}_n = \\frac{(n+4)\\mathcal{N}_{n+2} - \\mathcal{M}_{n+2}}{(n+2)(1-(b+r)^2)}\n\\end{equation}\nto iterate down to $n=3$, while finally computing $n=1$ and $n=2$ exactly.\n\nEvaluating this additional integral adds further computational expense, but in\npractice we only need to compute it for $b < b_c = 10^{-3}$ to obtain similar accuracy\nto the other expressions.  This is encountered rarely as it only applies when the\noccultor is nearly aligned with the source.\n\nWith the computation of $\\mathfrak{s}_n = -\\mathcal{P}(\\bvec{G}_n)$, we then\ncompute the derivatives of the solution vector as\n\\begin{eqnarray}\n\\frac{\\partial \\mathfrak{s}_n}{\\partial r} &= & -\\frac{\\partial \\mathcal{P}(\\bvec{G}_n)}{\\partial r},\\\\[0.5em]\n\\frac{\\partial \\mathfrak{s}_n}{\\partial b} &= & -\\frac{\\partial \\mathcal{P}(\\bvec{G}_n)}{\\partial b},\n\\end{eqnarray}\nfor $2 \\le n \\le N$, while the $n=0$ and $n=1$ terms are handled separately as in\nsection \\S\\ref{sec:reparam}.\n%\nThe derivatives of the normalized flux, $F$, with respect to $r$ and $b$\nare then computed as\n%\n\\begin{eqnarray}\\label{eq:derivatives}\n\\frac{\\partial F}{\\partial r} &=& I_0 \\sum_{n=0}^N \\mathfrak{g}_n \\frac{\\partial \\mathfrak{s}_n}{\\partial r},\\\\[0.5em]\n\\frac{\\partial F}{\\partial b} &=& I_0 \\sum_{n=0}^N \\mathfrak{g}_n \\frac{\\partial \\mathfrak{s}_n}{\\partial b} \\quad.\n\\end{eqnarray}\n%\nSince the normalization constant, $I_0$,\nis independent of $\\mathfrak{g}$ for $n \\ge 2$ (Equation~\\ref{eq:normalization}), the derivative of $F$\nwith respect to $\\mathfrak{g}$ is trivial:\n%\n\\begin{eqnarray}\n    \\frac{\\partial F}{\\partial \\mathfrak{g}_n} &=&  I_0 \\mathfrak{s}_n\n\\end{eqnarray}\n%\nfor $n \\ge 2$. For the first two terms, we differentiate\nEquation~(\\ref{eq:normalization}) to obtain\n%\n\\begin{eqnarray}\n\\frac{\\partial F}{\\partial \\mathfrak{g}_0} &=&  I_0 \\mathfrak{s}_0 - \\pi I_0 F,\\\\[0.5em]\n\\frac{\\partial F}{\\partial \\mathfrak{g}_1} &=&  I_0 \\mathfrak{s}_1 - \\frac{2\\pi}{3} I_0 F\\quad.\n\\end{eqnarray}\n\nThe derivatives of the light curve with respect to $\\mathbf{u}$ are computed by applying\nthe chain rule to the derivatives of the coefficients, \n$\\frac{\\partial \\mathfrak{g}_j}{\\partial u_i} = \\mathcal{A}_{ji}$,\n\\begin{eqnarray}\\label{eq:dFdu}\n\\frac{\\partial F}{\\partial u_i} =  \\sum_{j} \\frac{\\partial \\mathfrak{g}_j}{\\partial u_i}\\frac{\\partial F}{\\partial \\mathfrak{g}_j}.\n\\end{eqnarray}\n\n%\n\\pagebreak % DEBUG\n\n\\subsection{Summary}\n\\label{sec:summary}\nIn the last several sections, we showed that if we express the specific intensity distribution\non the surface of a spherical body as the series\n%\n\\begin{align}\n\\frac{I(\\upmu)}{I_0} &= 1 - u_1 (1 - \\upmu) - u_2 (1 - \\upmu)^2 - ... - u_{N}(1 - \\upmu)^{N} \\quad,\n\\end{align}\n%\n(see Equation~\\ref{eq:polynomialld}),\nthe total flux observed during an occultation is given by the analytic and closed form\nexpression\n%\n\\begin{align}\n    \\label{eq:occint_greens_summary}\n    F &= I_0 \\, \\mathfrak{s}^\\mathsf{T} \\mathcal{A} \\bvec{u} \\quad ,\n\\end{align}\n%\nwhere $I_0$ is a normalizing constant (Equation~\\ref{eq:normalization}),\n$\\mathfrak{s}^\\top$ is the solution vector (Equation~\\ref{eq:sn}, with special\ncases given by Equations~\\ref{eq:s0}, \\ref{eq:s1}, and \\ref{eq:s2}),\na function of only the impact parameter\n$b$ and radius $r$ of the occultor, $\\mathcal{A}$ is a change of basis\nmatrix (Equation~\\ref{eq:A}), and $\\mathbf{u}$ is the vector of limb\ndarkening coefficients $(u_0 \\ u_1 \\ u_2 \\ ... \\ u_N)^\\mathsf{T}$.\nNote that in general $\\mathfrak{s}^\\top$ is time-dependent, as it depends\nupon the relative positions of the bodies as a function of time, while\n$\\mathcal{A}\\mathbf{u}$ is time-independent, and thus the matrix\nmultiplication only needs to be computed once per light curve.\n\nUsually when fitting a light curve the unocculted flux is not equal\nto unity, but is some unknown value which needs to be fit for.  \nSo, the correct procedure is to multiply $F(t)$ by a parameter which \nrepresents the unocculted flux.\nIn this case the derivative with respect to the flux constant is trivially \nequal to $F(t)$, and the derivatives with respect to the other parameters \nmust be multiplied by the same parameter.\n\nWith the description of the light curve computation complete, we next discuss\nthe integration of the light curve over a finite time step.\n\n\\section{Time integration} \\label{sec:time}\n\nGiven that most observations are made over a finite exposure time,\nthe integration of the light curve over time is necessary to capture the\nchange in brightness over the timestep\nwith high fidelity \\citep[e.g.,][]{Kipping2010}. When constructing\na light curve, usually one divides the time integral of the flux (the \\emph{fluence})\nby the integration time\nto obtain the time-averaged flux. For optimizing and inferring the\nposterior of model parameters, we would like to compute the derivatives\nof the time-averaged flux with respect to the model parameters.\n\nThe instantaneous flux is a function of $3+N$ parameters in the Green's basis,\n$\\{r,b,\\mathfrak{g}_n\\}$, or $2+N$ parameters in the polynomial in basis, and of\nthese, only one varies with time, $b(t)$.  Thus, we can compute the\ntime-dependent flux with a model for $b(t)=b(\\bvec{x},t)$, where\n$b(\\bvec{x},t)$ is a model for the impact parameter as a function of time\nand model parameters $\\bvec{x}$.  The set of model parameters need to be specified\nby a function, which, for example, might be a Keplerian orbit of the two bodies\nwith respect to one another, or a full dynamical model of an $N$-body system.\nTo compute the derivatives of the light curve with respect to $\\bvec{x}$, the\nderivatives of the dynamical model must be computed as well.\n\nThe time-averaged flux, $\\overline{F}$, and its derivatives, are given by\n\\begin{eqnarray}\\label{eq:avg_flux}\n\\overline{F} &=& \\frac{1}{\\Delta t} \\int_{t-\\tfrac{1}{2}\\Delta t}^{t+\\tfrac{1}{2}\\Delta t} F(t^\\prime) dt^\\prime,\\\\\n\\frac{\\partial \\overline{F}}{\\partial r} &=& \\frac{1}{\\Delta t} \\int_{t-\\tfrac{1}{2}\\Delta t}^{t+\\tfrac{1}{2}\\Delta t} \\frac{\\partial F(t^\\prime)}{\\partial r} dt^\\prime,\\\\\n%\\frac{\\partial \\overline{F}}{\\partial b}&=& \\frac{1}{\\Delta t} \\int_{t-\\tfrac{1}{2}\\Delta t}^{t+\\tfrac{1}{2}\\Delta t} \\frac{\\partial F(t^\\prime)}{\\partial b} dt^\\prime,\\\\\n\\frac{\\partial \\overline{F}}{\\partial \\mathfrak{g}_i}&=& \\frac{1}{\\Delta t} \\int_{t-\\tfrac{1}{2}\\Delta t}^{t+\\tfrac{1}{2}\\Delta t} \\frac{\\partial F(t^\\prime)}{\\partial \\mathfrak{g}_i} dt^\\prime,\\\\\n\\frac{\\partial \\overline{F}}{\\partial \\bvec{x}} &=& \\frac{1}{\\Delta t}\n\\int_{t-\\tfrac{1}{2}\\Delta t}^{t+\\tfrac{1}{2}\\Delta t} \\frac{\\partial F}{\\partial b}\\frac{\\partial b(t^\\prime)}{\\partial \\bvec{x}} dt^\\prime,\n\\end{eqnarray}\nwhere $t$ is taken to be the mid-point of the transit exposure time, and\n$\\Delta t$ is the exposure time.\n\nAs an example, we choose the approximate transit model $b(t) = (b_0^2 + v^2(t-t_0)^2)^{1/2}$,\nwhich ignores acceleration and curvature during a transit, and thus is valid in the\nlimit of large orbital separation.  We compute the time-averaged flux and derivatives\nwith respect to $\\bvec{x} = \\{t_0,v,b_0\\}$ for a length of integration time $\\Delta t$.\n{\\bf For exposures which contain a contact point, we break these up into sub-exposures\nbetween the start, end, and contact points within the exposure, and then separately\ncarry out the integration over each sub-exposure.  This is required due to the fact\nthat the flux and derivatives are discontinuous at each of the contact points, and\nso the time-integration is most efficient when integrating up to, but not over,\na contact point.  For our simplified transit trajectory, $b(t)$, these contact points\ncan be computed analytically;  for an eccentric orbit, the contact points may require\nnumerical methods to identify before the sub-exposures can be identified.}\n\n%The integration is carried out with an adaptive refinement of the exposure time interval by\n%factors of two until the midpoint in each refined interval is within $10^{-6}r^2$\n%of the mean of the start and end with a maximum\n%number of refinement depths of 32.\nThe integration {\\bf of each (sub-)exposure} is carried out with an adaptive Simpson \nquadrature routine \\citep{Kuncir1962}.  Since at each point we compute the flux along with\nits derivatives, we have developed a vectorized version of this routine\nwhich keeps track of the quadrature separately for each component of the\nflux and its partial derivatives.  The convergence check for the adaptive\nSimpson rule is applied to each component, and when all satisfy the\nconvergence criterion, the adaptive refinement is terminated.\nIn practice this algorithm requires specifying a convergence tolerance,\n$\\epsilon_{tol}$, as well as a maximum number of depths, $D_{max}$, to\nallocate memory to store the intermediate results.\nFigure \\ref{fig:integrated_derivs} shows a\ncomparison of the derivatives of the time-integrated light curve for this\nimpact parameter model.\n\nThe time-integration smooths both the features of\nthe light curve, as well as the features of the derivative curves.  The similarity of\nthe shape of the derivative with respect to $v$ and $b_0$ makes it apparent\nthat there may be partial degeneracies between the impact parameter and duration\nof a transit, which can make the impact parameter more difficult to measure, especially\nwhen the exposure time is longer than the time of ingress/egress.  Likewise, the\nderivatives with respect to the two limb darkening parameters have a similar shape,\nwhich explains why in some cases it can be difficult to constrain both parameters.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/integrate_transit_gradient.pdf}\n    \\caption{Comparison of the normalized flux and its derivatives with {\\bf and\n    without time-integration (see solid and dashed lines, respectively)}.  \n    The integration time, $\\Delta t = 0.3$, is indicated in the\n    upper left panel with a horizontal blue line. The derivatives are computed with\n    respect to $\\{r,t_0,v,b_0,u_1,u_2\\}$.  The parameters are given by $r=0.1$,\n    $t_0 = 0$, {\\bf $v=1$}, $b_0=0.5$, and $u_1=u_2=0.3$. \\jlcodelink{integrate_transit_gradient}\n    \\label{fig:integrated_derivs}}\n    \\end{centering}\n\\end{figure}\n\n{\\bf In practice the $\\epsilon_{tol}$ parameter controls the average number of evaluations\nper exposure time, while the tolerance achieved is typically $<10 \\epsilon_{tol}$.\nFigure \\ref{fig:integration_precision} shows the maximum numerical error achieved\nfor computations with $\\epsilon_{tol} = (10^{-4},10^{-6},10^{-8},10^{-10},10^{-12},10^{-14})$\nrelative to a precision of $\\epsilon_{tol} = 10^{-16}$.    The\ncomputed model has $10^4$ exposures for quadratic limb-darkening with the same parameters \nas in Figure \\ref{fig:integrated_derivs}\n(note that these exposures overlap in time;  in practice many fewer exposures would\nbe required to compute this light curve).  In computing the time-integrated light\ncurves, we integrate over the difference of the flux minus one, so that shallow\ntransit depths will not lose precision.  In Figure \\ref{fig:integration_precision},\nthe achieved precision is plotted versus the average number of evaluations per exposure\nfor the flux-1 and for each of the derivatives.  In all cases but the highest precision,\nthe flux and all derivatives achieve a precision which is better than $10 \\epsilon_{tol}$.\nFor the highest tolerance case, $\\epsilon_{tol} = 10^{-14}$, we find that the\nprecision exceeds this value slightly;  this is likely due to the model reaching\nthe limit of double-precision.\n\nAlso plotted in Figure \\ref{fig:integration_precision} is ten times the\ntolerance versus the evaluation time\nper exposure relative to the time for a single evaluation per exposure\n(dashed line).  This\ncurve falls to the right of the number ratio line (dotted line) by about \na factor of $\\approx 2$\nfor high tolerance ($\\epsilon_{tol} = 10^{-4}$), to about a factor of $1.3$\nfor low tolerance ($\\epsilon_{tol} = 10^{-14}$).  Thus, the time per\nevaluation for the adaptive time-integrated flux and derivatives exceeds the \nexpectation given a single evaluation per exposure.  This is likely due to \nthe fact that the model computation takes longer for some parameter values \nthan others, while the adaptive integration tends to concentrate the \nevaluations at the parameters which are more expensive to evaluate.  In \naddition there may be computation overhead from the adaptive simpson integration \nfunction.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/compare_precision.pdf}\n    \\caption{Precision achieved for the time time-integrated flux (minus one)\n    versus the average number of evaluations per exposure.  The colored lines\n    show the precision achieved for the flux-1 and for each of the derivatives.\n    For comparison, the dotted line shows 10 times the tolerance, $\\epsilon_{tol}$.\n    The dashed line uses as the abscissa the ratio of the total light curve evaluation \n    time per exposure relative to a single evaluation per exposure.\n    \\label{fig:integration_precision}}\n    \\end{centering}\n\\end{figure}\n\n} \n\n\\pagebreak % DEBUG\n\n\\section{Non-linear limb darkening}\\label{sec:nonlinear}\n\n\\citet{Claret2000} introduced a ``non-linear'' limb darkening model which\nwas found to be an effective model for describing the limb darkening functions\nwhich are produced by models of stellar atmospheres.\nAlthough we can only model limb darkening in integer powers of $\\upmu$,\nwe can use a high order polynomial model as an alternative limb darkening model.\n\n%\\begin{itemize}\n%\\item Compare polynomial models to non-linear light curves. [x]\n%\\item Fit polynomial model to stellar limb darkening models.\n%\\end{itemize}\n\nWe have computed an example non-linear light curve with $r=0.1$ and\n$c_1=c_2=c_3=c_4=0.2$, and then fit it with the polynomial limb-darkening\nmodel with increasing orders of the polynomial approximation.  The non-linear light curve model\nwe computed numerically as the analytic expressions in \\citet{MandelAgol2002}\nare in terms of hypergeometric functions which are expensive to evaluate.\nWe numerically compute the non-linear light curve with a ``layer-cake'' model in which sums of\nlayers of surface brightness with a grid of increasing radii are added together\nto approximate the lightcurve;  this\nis the approach taken in the numerical model used to compute the\nnon-linear limb darkening light curves in the code of \\citet{MandelAgol2002},\nand it is analogous to the approach taken by \\citet{Kreidberg2015} for\ncomputing models with arbitrary limb darkening profiles.\n\nWhen fitting the non-linear lightcurve with the polynomial model,\nwe find that the fit improves steadily up until $N=6$ (a sextic\npolynomial), while beyond sextic, the RMS improves imperceptibly.\nThe RMS of the sextic fit for this example is $<5 \\times 10^{-7}$\nrelative to a depth of transit of about 1.4\\% (Figure \\ref{fig:nonlinear}).\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=0.8\\linewidth]{figures/julia/occult_nonlinear_poly.pdf}\n    \\caption{Comparison of the non-linear limb darkening with polynomial\n    fits of various orders.\n    \\jlcodelink{occult_nonlinear}\n    \\label{fig:nonlinear}}\n    \\end{centering}\n\\end{figure}\n\n%Since the non-linear model is just an effective model of stellar\n%atmospheres, we next turn to fitting the non-linear model to\n%computed stellar atmospheres, and comparing these fits with\n%polynomial limb darkening to different orders.\n%\n%\\citet{Claret2018} discusses a precise means for fitting limb darkening\n%models to spherically-symmetric models for stellar atmospheres.  The\n%stellar surface brightness drops rapidly from a finite value to zero surface\n%brightness over a few scale heights of the stellar atmosphere.\n%The scale height of an atmosphere is small compared with the size of a star,\n%and so the limb darkening model can treat the radius of the star as a\n%free parameter, and then treat the drop in surface brightness as a step-\n%function near the limb of the star.  This gives a more precise model\n%for the limb darkening, and \\citet{Claret2018} finds good precision\n%using the non-linear limb darkening model.\n%\n%We used the same set of atmospheres as \\citet{Claret2018}, but fit these\n%with the polynomial model, varying the order of the polynomial until the\n%fit no longer improves. TBD\n%\n%\\section{Examples}\n%\n%Give some examples of the usage: non-linear optimization, HMC.\n\nThis completes the description of the light curve computation, along\nwith its derivatives.  We now turn to discussing the implementation of\nthe computation, followed by comparison with existing codes.\n\n\\section{Implementation details}\n\\label{sec:implementation}\n\nThere are several details in our implementation of the foregoing equations\nwhich give further speedup of the computation, which we describe in this\nsection.\n\nWhen a light curve is computed, there are some computations which only\nneed to be carried out once, and then can be reused at each time step in the\nlight curve computation.\nWe define a structure to hold these variables\nwhich are reused throughout the light curve; we also pre-allocate variables which\nare used throughout the computation to avoid the overhead of memory allocation\nand garbage collection.  In addition, due to the greater\ncomputational expense of square-roots and divisions, where possible we try\nto only compute a square root or division once, storing these in a variable\nwithin the structure, and then reuse these with cheaper multiplication\nthroughout the computation when needed.  For instance, for many formulae we\nrequire the inverse of an integer, so an array of integer inverses is computed\nonce and stored, and then accessed as required rather than recomputed.\n\nOnce the number of limb darkening\nterms, $N$, is specified, then the series coefficients for $\\mathcal{M}_n$\nand $\\mathcal{N}_n$, $\\alpha_j$ and $\\gamma_j$, are a simple function of $j$\nand $n$, and so we compute these coefficients once, and store them in a vector\nfor $k^2 \\le 1$, separately for $N-3$ to $N$ for $\\mathcal{M}_n$, and for\n$N-1$ and $N$ for $\\mathcal{N}_n$.\n\nIn addition, once $N$ is specified, then the transformation matrix for\nthe Jacobian from $\\mathfrak{g}_i$ to $u_j$, $\\frac{\\partial \\mathfrak{g}_i}{\\partial u_j}=\\mathcal{A}$,\nremains the same throughout the light curve\ncomputation, so we compute this matrix only once, and then compute the\nflux derivative (Equation \\ref{eq:dFdu}) with matrix multiplication.\nIn fact, since the Jacobian matrix for transforming the derivatives from $\\mathfrak{g}_i$\nto $u_j$ can be expensive to apply, we can carry out the gradient of the\nlikelihood function with respect to $\\mathfrak{g}_i$, and then apply the Jacobian\ntransformation from $\\mathfrak{g}_i$ to $u_j$ only once to obtain the gradient\nof the likelihood with respect to the limb darkening parameterization.\nIn practice, we are usually only concerned with optimizing a likelihood\nor computing gradients of a likelihood for Hamiltonian Markov Chain\nMonte Carlo, so the derivatives of the particular points in the\nlight curve with respect to $u_i$ aren't needed.  This results in a\nsignificant computational savings, especially for large $N$.\nTransformation to other parameterizations, such as $q_1$ and $q_2$\ndefined by \\citet{Kipping2013} for quadratic limb-darkening, may also be accomplished after the\nfact by applying the Jacobian to compute the gradient of the likelihood\nin terms of these transformed parameters.\n\nIn computing the elliptic integrals, cel, we found that several terms\nwhich appear in the Bartky formalism are repeated amongst all three elliptic\nintegrals which appear in the expressions for $\\mathfrak{s}_1$.  Consequently, we carry\nout a parallel computation of these elliptic integrals such that these\nrepeated terms are only computed once;  this improves the efficiency of\nthe elliptic integral computations.  Once these elliptic integrals\nare computed for $\\mathfrak{s}_1$, the elliptic integrals $\\mathrm{cel}(k_c,1,1,k_c^2)=E(m_k)$\nand $\\mathrm{cel}(k_c,1,1,0)=(E(m_k)-(1-m_k)K(m_k))/m_k $ are\nstored in the structure and reused for computing $\\mathcal{M}_n$\nand $\\mathcal{N}_n$.\n\nWe find that the precision of the computation begins to degrade for\n$N \\approx 25-30$.  For large values of $N$, the computing time for\npropagating the derivatives from $\\mathfrak{g}_i$ to $u_i$ scales as $N^2$, and\nthus can dominate the computation time.  We utilize the BLAS linear\nalgebra library (specifically, the routine \\texttt{gemv}) for efficient\nmultiplication of this matrix times the derivative of the light curve with\nrespect to $\\mathfrak{g}_i$ in order to obtain the derivatives with respect to $u_i$.\nHowever, as we note above, an even more efficient approach is to\nsimply apply this transformation once to the gradient of the likelihood.\n\n% DEBUG\n\\pagebreak\n\n\\section{Benchmarking}\n\\label{sec:benchmark}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=0.7\\linewidth]{figures/julia/benchmark_transit_poly.pdf}\n    \\caption{Scaling of the computation time in seconds with the number of\n    data points in the light curve for $r=0.1$ with $b$ ranging from $0$ to $1.2$,\n    and with the number of limb darkening coefficients, $N$. \\jlcodelink{benchmark_transit_poly}\n    \\label{fig:ncoeff}}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=0.7\\linewidth]{figures/julia/benchmark_limbdark_timing.pdf}\n    \\caption{Scaling of the computation time with the number of\n    limb darkening coeffients, $N$.  The $y$-axis scales the timing with respect\n    to the timing for a single limb darkening coefficient. \\jlcodelink{benchmark_transit_poly}\n    \\label{fig:nlimb}}\n    \\end{centering}\n\\end{figure}\n\nWe have measured the performance of the limb-darkened light curves\nwith derivatives as a function of the number of computed data points\nand as a function of the number of limb darkening coefficients.  We\nhave computed the timing for $r=0.1$ and for a number of impact\nparameters ranging from $10^2$ to $10^6$, and the number of limb darkening\ncoefficients ranging from $1$ to $144$.  For each set of timing benchmark\nparameters, we carried out nine measurements  of the timing, and\nwe use the median of these for plotting purposes.  The benchmarking\nfor the \\texttt{Julia} code was carried out with \\texttt{v0.7} of\n\\texttt{Julia} on the \\texttt{trusty} Ubuntu environment of Travis-CI%\n\\footnote{\\url{https://travis-ci.org}}\non a 2.3 GHz\n% SEE https://travis-ci.org/rodluger/Limbdark.jl/jobs/527913189#L545\n2-core machine with 7.5 GB of RAM.\nNo time-integration/sub-sampling was carried out in this computation.\n\nFigure \\ref{fig:ncoeff} shows that the time dependence is linear with the\nnumber of $b$ values (which is equivalent to the number of data points\nin the light curve).  The linear scaling with time holds for each value of\nthe number of limb darkening coefficients.\n\nFigure \\ref{fig:nlimb} shows that the time dependence scales approximately\nas $N^{0.2-1}$.  As with the number of light-curve points, we have taken\nthe median over nine measurements for each set of parameters.  We then\nscaled the timing to the single-coefficient case, and took a second\nmedian over the number of light curve points as the cube-root scaling scales\nabout the same with different numbers of points in the light curve.\n\n\n\\section{Comparison with prior work} \\label{sec:comparison}\n\nIn this section we compare our computations with existing code in terms\nof accuracy and speed. We compare both the \\texttt{Julia} version\nof our code and an implementation of our algorithms\nin the \\texttt{starry} package, with and without the computation\nof gradients. To ensure a fair comparison between the codes, we\nperform all calculations on a single core without multi-threading\nor interpolation over a pre-computed grid, which is an option\nin some codes.\n\n\\subsection{Comparison with Mandel \\& Agol (2002)}\n\n\\begin{figure}[t!]\n    \\begin{centering}\n    \\includegraphics[width=0.9\\linewidth]{figures/julia/compare_MA2002.pdf}\n    \\caption{Comparison of Mandel \\& Agol (2002) with \\thiswork.\n    \\jlcodelink{compare_MA2002}\n    \\label{fig:compareMA}}\n    \\end{centering}\n\\end{figure}\n\nFor uniform, linear or quadratic limb darkening, the \\texttt{IDL} package \\texttt{EXOFAST} \nimproved upon the speed of the widely used computation by \\citet{MandelAgol2002} \nby utilizing the \\citet{Bulirsch1965a,Bulirsch1965b} expressions for the complete \nelliptic integral of the third kind which is needed for the linear case\n\\citep{Eastman2013}.  \\texttt{EXOFAST} also uses a series\napproximation for the complete elliptic integrals of the first and second\nkind \\citep{Hastings1955}. These three elliptic integrals, especially the third\nkind, are the bottleneck in the computation, and the Bulirsch version is faster\nthan widely used Carlson implementation of elliptic integrals \\citep{Carlson1979}.\n\nWe have carried out a numerical comparison of the \\texttt{EXOFAST} implementation\nof the \\citet{MandelAgol2002} formulae for the linear case ($u_1=1$), and find \nthat the most severe errors occur for $b = r \\pm \\epsilon$.  Figure \\ref{fig:compareMA} \nshows the computed models and the errors as a function of $r$ for $b=1-r-\\epsilon$\nand $b=r-\\epsilon$, with $\\epsilon = 10^{-12}$ (the results look very\nsimilar with $+\\epsilon$, so we have only plotted one case for clarity).\nIn the $b\\approx 1-r$ case (near second and third contacts), the errors\nare larger than our new expression, reaching $\\approx 10^{-10}$ for\n$r = 1$.  However, the errors become much more severe in the $b \\approx r$\ncase.  For $b=r \\pm 10^{-12}$, the errors grow to $10^{-4}$, and continue\nto grow as $b$ gets closer to $r$.  No such instability occurs for\nour new expressions, demonstrating their utility in all regions of\nparameter space.\n\nA speed comparison for a transit computed with $10^7$ data points shows that\nthe \\texttt{Julia} implementation of these routines takes about 55\\% of the CPU\ntime as the \\texttt{IDL} \\texttt{EXOFAST} implementation without derivatives, and about 65\\%\nof the computation time when including the derivatives.  Consequently, we\nconclude that our new implementation is both faster (by 35-45\\%) and more\naccurate than the \\cite{MandelAgol2002} \\texttt{IDL} implementation.  \n\nWe note that \\texttt{EXOFAST} v2.0 has now been updated to utilize the numerically-stable \nquadratic limb darkening expressions given above, albeit without the computed \nderivatives (Eastman et al., in preparation).\n\n\\subsection{Derivative comparison with P\\'al}\n\nWe have computed the quadratic limb-darkened light curve using the \\texttt{F77}\ncode written by Andr\\'as P\\'al, \\texttt{ntiq\\_fortran.f}.\nFigure \\ref{fig:Pal_comparison} shows the results of this comparison.\nThe light curve models agree quite well, as do the derivatives, which is\na good check on both codes.  However, we find that the P\\'al model only\nachieves single precision for the computation, with errors reaching as\nmuch as a few $\\times 10^{-8}$ for the flux and the derivatives with\nrespect to the limb darkening parameters.  {\\bf One possible origin\nfor this difference is that} \\citet{Pal2008} uses the\nCarlson implementation of elliptic integrals \\citep{Carlson1979},\nwhich {\\bf in this implementation may be} be both less precise and slower to\nevaluate than {\\bf our new implementation of the}  \\citet{Bulirsch1965a} code \nfor computing elliptic integrals.\n\nWe have also compared the evaluation speed of our code with P\\'al's.\nWe compiled P\\'al's code using \\texttt{gfortran -O3}, and found that\nthe computation of quadratic limb-darkened light curves and\nderivatives takes an average of 0.52 seconds to compute $10^6$ models,\nwhile the \\texttt{transit\\_poly\\_struct.jl} takes an average of 0.16 seconds,\ngiving our \\texttt{Julia} code a 70\\% speed advantage over the Fortran code.\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/compare_pal.pdf}\n    \\caption{Comparison of \\citet{Pal2008} with \\thiswork.  The\n    coefficients are $u_1=0.2$ and $u_2=0.3$. \\jlcodelink{compare_pal}\n    \\label{fig:Pal_comparison}}\n    \\end{centering}\n\\end{figure}\n\n\\subsection{Comparison to \\texttt{batman}}\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[width=0.95\\linewidth]{figures/python/compare_to_batman.pdf}\n    \\caption{Comparison of \\citet{Kreidberg2015} (orange) with \\thiswork\n             (\\texttt{Julia} implementation in blue and \\starry implementation\n             in green) for a transit across a quadratically limb-darkened star.\n             Also shown are points corresponding to the computation using\n             \\texttt{PyTransit} \\citep{Parviainen2015b}. Dashed lines indicate\n             computations including the gradients of the flux with respect to\n             the radius, impact parameter, and all limb darkening coefficients.\n             The $y$-axis corresponds to the evaluation time of the model in\n             seconds and the size of the points is proportional to the log of\n             the error in the computation relative to a calculation performed\n             at 128-bit precision.\n             \\pycodelink{compare_to_batman}\n    \\label{fig:batman_comparison}}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}[p!]\n    \\begin{centering}\n    \\includegraphics[width=0.95\\linewidth]{figures/python/compare_to_batman_nonlinear.pdf}\n    \\caption{Similar to Figure~\\ref{fig:batman_comparison}, but this time comparing\n             the computation of a transit across a nonlinearly limb-darkened star.\n             \\pycodelink{compare_to_batman_nonlinear}\n    \\label{fig:batman_nonlinear_comparison}}\n    \\end{centering}\n\\end{figure}\n\nA \\Python implementation of transit light curves which has been widely applied\nis the \\texttt{batman} package \\citep{Kreidberg2015}.  This package\nimplements a fast C version of the computation, called by \\Python for\nease of use.\n\nThe \\texttt{batman} package computes the quadratic limb darkening model\nof \\citet{MandelAgol2002}, and uses the same approach for computing\nthe complete elliptic integrals as \\texttt{EXOFAST}.  We have made a comparison\nof our implementation of quadratic limb darkening with \\texttt{batman},\nwhich is shown in Figure \\ref{fig:batman_comparison}.  Without computing\nderivatives, our approach (as implemented in \\texttt{Julia}; blue)\ntakes about 60\\% of the time of \\texttt{batman} (orange);\nwith derivatives, the two are comparable in speed. The implementation\nof our algorithm in \\starry (green) is similar in speed to \\texttt{batman}\nwithout derivatives, and about a factor of 2 slower than \\texttt{batman}\nwhen derivatives are computed. Both the \\texttt{Julia} and \\starry\nimplementations have errors close to {\\bf double} precision and are therefore\nmany orders of magnitude more precise than \\batman.\n\nNext, we ran a comparison with the non-linear limb darkening model which\nproves to be a better fit than the quadratic model to both simulated\nand observed stellar atmospheres.  The \\texttt{batman} code carries out\na numerical integration over the surface brightness as a function of\nradius over the stellar disk, which requires additional computational\ntime and limits the precision.  We have carried out a fit to the\nnon-linear limb darkening profile with $c_1=c_2=c_3=c_4=0.2$ with a\npolynomial limb darkening model with $N=15$ (\\S \\ref{sec:nonlinear}).  \nWe then ran a timing comparison between the \\texttt{batman} model and the \npolynomial model, and we find that the polynomial model is about 7 times\nmore accurate and 25 times faster (\\texttt{Julia})\nand 20 times faster (\\starry) to evaluate compared with \\texttt{batman}.\n\n\\subsection{Comparison to \\texttt{PyTransit}} \\label{sec:comparison_pytransit}\n\n\\begin{figure}[t!]\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/compare_to_gimenez.pdf}\n    \\caption{Comparison of the algorithm presented in this work (blue and\n             green points) to that of\n             \\citet{Gimenez2006} for the computation of a transit across a\n             star with polynomial limb darkening, as implemented in the\n             \\texttt{PyTransit} package \\citep{Parviainen2015b}\n             (purple points), as a function\n             of the order of the polynomial. As before, the $y$-axis\n             corresponds to the evaluation time and the size of the points\n             to the log of the error in the computation. For reference, the\n             red points correspond to the evaluation using a naive implementation\n             of the full spherical harmonic formalism of \\citet{starry}, which\n             this paper has improved upon.\n             \\pycodelink{compare_to_gimenez}\n    \\label{fig:gimenez_comparison}}\n    \\end{centering}\n\\end{figure}\n\nAnother popular implementation of transit light curve computation is the\n\\texttt{PyTransit} code \\citep{Parviainen2015b}. We {\\bf have} included points corresponding\nto this code in Figures~\\ref{fig:batman_comparison} and \\ref{fig:batman_nonlinear_comparison},\nand in general find that it is comparable to \\batman in both evaluation time\nand accuracy. However, unlike \\batman, \\texttt{PyTransit} implements the\nalgorithm of \\citet{Gimenez2006} for polynomial limb darkening (Equation~\\ref{eq:gimenez}).\n\nIn Figure~\\ref{fig:gimenez_comparison} we therefore compare our implementation\nto {\\bf the Gim\\'enez algorithm implementation} in \\texttt{PyTransit} as a function \nof the degree of limb darkening.\nWe find our algorithm to be approximately between 5 (for low-order limb darkening)\nand 30 (for high-order limb darkening) times faster, and many orders of magnitude\nmore precise {\\bf for low order limb-darkening, while gradually degrading in precision\nto higher order limb-darkening to become comparable at very high orders ($N=50$)}. \n{\\bf Even when computing derivatives, our \\texttt{Julia} code is still faster by\na about a factor of 2.5 for low-order limb-darkening, $N=0$, increasing in\nspeed relative to the Gim\\'enez algorithm by about an order of magnitude at high-orders,\n$N=50$}.\n\nFor reference, in Figure~\\ref{fig:gimenez_comparison},\nwe also plot the evaluation time when computing the light curve using the\nspherical harmonic formalism of \\cite{starry}. Because the algorithm presented\nin that paper computes surface integrals via recursions in both the\nspherical harmonic degree $l$ and the order $m$ (as it was designed to\nsolve the occultation problem for arbitrary surface features),\nit scales super-quadratically with the degree of limb darkening. That\nalgorithm is therefore orders of magnitude slower\nto evaluate in the case of pure limb darkening ($m=0$ modes only). We have\nmodified the \\starry package to compute light curves\nusing the formalism in this paper in the case of pure limb darkening.\n\n\\section{Discussion}\n\\label{sec:discussion}\n\nWe have presented formulae for the transit (or occultation/eclipse) of a\nlimb-darkened body with a limb darkening profile which is given by a polynomial\nin $\\upmu$.  These formulae have multiple assumptions built in:  both bodies\nare treated as spherical \\citep[but see][]{Seager2002,Hui2002}, so that their projected\nsufaces are assumed to be circular \\citep[but see][]{Barnes2003,Barnes2004,Barnes2009b,\nDobbsDixon2012};  limb darkening is treated as azimuthally-symmetric \\citep[but see][]{Barnes2009a};\nrefraction and any relativistic effects are ignored \\citep[but see][]{Sidis2010};\nand the edges of both bodies are assumed to have a sharp boundary.\nAll of these assumptions are violated in every transit event to some extent,\nbut in the majority of cases these assumptions can yield a sufficiently precise model for\na given signal-to-noise ratio.\n\nGiven these assumptions, generally one next assumes a particular functional\nform for the limb darkening law \\citep{Csizmadia2018}.  The parameterization of\nthe limb darkening model can impact the precision of the computation\nof transit light curves.  A common approach is to derive limb darkening\ncoefficients for a particular limb darkening model from stellar atmosphere models,\nand to either fix these at the tabulated values given an observing band and an\nestimate of stellar parameters \\citep{Claret2011,Howarth2011}, or at least to place\na prior that the limb darkening parameters should nearly match these values.\nThis approach can have several pitfalls:  the limb darkening model may not be\nsufficiently precise,  the stellar atmosphere model may not be accurate, and\nthe stellar parameters may not be precise.\nIn computing limb darkening from stellar atmosphere models,\nthe spherical nature of limb darkening can affect the transit light curve\n\\citep{Neilson2013,Neilson2017}, and thus the limb darkening coefficients must be fit\nwith care \\citep{Claret2018}.  Even more importantly, full three dimensional\nstellar atmosphere models appear to give a more accurate description of\nstellar limb darkening by capturing the structure of the atmosphere under\nthe influence of granulation \\citep{Hayek2012,Magic2015}.  However, any\nphysical model for a stellar atmosphere has limitations in the fidelity at\nwhich it can model actual stellar atmospheres,\nand any modeler can only explore a finite set of parameters (effective temperature,\nmetallicity, surface gravity, and magnetic field strength).\nIn practice, then, it may be most robust simply to let the limb darkening parameters\nbe free parameters, to let the limb darkening model be as flexible as possible,\nand to let the limb darkening model be fit along with the radius ratio and\norbital parameters \\citep{Csizmadia2012,Espinoza2015}.\n\nEven so, this approach still assumes azimuthal symmetry for the star, while\nany model for the surface brightness of a star can only be approximate:\nto some extent most stars are convective, rotationally-oblate, spotted, oscillating, flaring,\netc.  The model we have presented, then, will only resemble any given star to\na precision which is limited by the lack of uniformity of the actual stellar\nsurface.  This begs the question of why a numerically precise model is required\nfor modelling transit light curves.  The answer is computational accuracy\nand stability: this more accurate model can be used over all of parameter space,\nwithout returning spurious results, and the high precision enables computation\nof derivatives which are beneficial when optimizing model parameters, computing\nthe Fisher information matrix, or deriving parameter posteriors with MCMC.\n\nSince we are limited in the knowledge of the properties of any given star,\nthe discrepancies of an azimuthally-symmetric limb-darkened model can be\ntreated as a source of noise.\nThe deviation of the star from the model can be absorbed into noise models that\naccount for outliers, account for correlations in the noise, or actually\ntry to model the deviations of the star from azimuthal symmetry, such as\ninduced by star spots \\citep[e.g.][]{SanchisOjeda2011}.\n\n% In addition to the variability and inhomogeneity of stars, the limb darkening model\n% can only describe the variation of surface brightness with a limited accuracy.\n% Our analytic model can be thought of as a Taylor series with which the\n% limb darkening can be expanded to as high an order as the data require.\n% In fact, for planetary transits in which $r$ is small, an arbitrary limb darkening\n% model could be treated as a Taylor series about the location of the planet,\n% using the analytic formulae to compute an approximate light curve.  This\n% would require varying the polynomial limb darkening coefficients as the\n% planet moved across the disk of the star, which would need to be propagated\n% through the derivatives properly.  Such a model could be a faster, and\n% perhaps, more accurate way to treat arbitrary limb darkening laws, such\n% as ``non-linear\" limb darkening \\citep{Claret2000} or power-law limb darkening\n% \\citep{Maxted2018}.\n\nOne question is what order of the limb darkening model to choose to\nfit the data?  Here we suggest several possibile solutions.  The order of the\nlimb darkening can be varied until the chi-square no longer improves (subject\nto a penalty for the greater freedom in the model, such as Bayesian Information\nCriterion).  A high-order limb darkening model can be chosen, with the\ncoefficients regularized to favor small values;  should the data require\na higher-order model, then the coefficients will increase to accommodate\nthe data.  The parameterization of the limb darkening with terms with\n$\\mathfrak{g}_n ((n+2)\\upmu^n-\\upmu^{n-2})$ for $2 \\le n \\le N$ may be particularly\nconvenient for this model in that these terms do not contribute to the\ntotal flux of the star.  A third possibility is to fit stellar atmosphere\nmodels with the polynomial limb darkening model until a sufficient precision\nis reached given that warranted by the data, and then to place priors\non the limb darkening parameters, informed by the stellar limb darkening\nmodels.  A fourth approach might be to choose a parameterization with\na small number of free parameters, such as the non-linear ``power-2'' law advocated\nby \\citet{Maxted2018}, and fit this parameterized limb darkening model\nwith a high-order polynomial for a given set.  Then, only the non-linear\nparameters need to be varied, while the polynomial coefficients will\nbe a simple function of these non-linear parameters.  In this approach\nit should be straightforward to linearize the polynomial limb darkening\nmodel fitting, which ought to yield good computational efficiency.\nA limitation of our computational approach is that the precision\nbegins to degrade for $N \\approx 25-30$; however, we anticipate that such\na high order will rarely be required.\n\n%Example applications:\n%\\begin{enumerate}\n%\\item optimization with and without analytic derivatives;\n%\\item fitting to stellar limb darkening models;\n%\\item time integrated model with derivatives;\n%\\item HMC.\n%\\end{enumerate}\n\n\\section{Applications}\n\\label{sec:applications}\n\nWe envision that this code will be used for fits to higher precision\ntransit data, such as gathered by the James Webb Space Telescope \\citep[JWST;][]{Beichman2014},\nwhich require an improved model of stellar limb darkening.  Here we discuss\nsome potential avenues for application of this model.\n\nThe derivatives of the time-integrated light curves may be used to revisit the\nFisher information analysis as carried out by \\citet{Price2014}, as originally\ninvestigated without time-integration by \\citet{Carter2008}.  Accounting\nfor correlated noise in this analysis will give more plausible estimates\nfor the impact of stellar variability on the determination of transit\ntransmission spectroscopy and transit-timing variations \\citep{ForemanMackey2017}.\nThis limit will be encountered as more precise measurements are made by gathering\nmore photons during a transit.  For example, for some targets, one can expect to\nobtain $\\sim 10^2$ times as many photons with JWST as collected with Kepler.\nWith such higher precision, as well as the wavelength-dependence afforded\nby several JWST observing modes, one can expect that high fidelity transit\nmodels will be required for making precise measurements of transit parameters.\n\nThe detection of transit-timing variations with low-amplitude sinusoidal\nvariations can make use of the fact that small variations in transit time\ncan be expanded as a Taylor series to linear order in time so that perturbations\nin the transit time are the sum of a periodic component and a constant\ntimes the derivative of the limb-darkened light curve \\citep{Ofir2018}.\nThis approach requires derivatives of the light curve with respect to\ntime, for which the \\citet{MandelAgol2002} computation is too\nimprecise near the points of contact, $b \\approx r$ and $b \\approx 1-r$,\nwithin an impact parameter distance of $10^{-4}$, as shown by \\citet{Ofir2018},\nwho extrapolated over these regions with polynomials.\nHowever, our new precise formulae, with derivatives, will be useful\nfor the perturbative approach to the detection of transit timing\nvariations, avoiding the numerical errors inherent in the \\citet{MandelAgol2002}\nmodel over a narrow range of parameter space.\n\n\\section{Conclusions}\n\\label{sec:conclusions}\n\nWe have presented an analytic model for the transits, occultations, and\neclipses of limb-darkened bodies with a polynomial dependence of the limb darkening\non the $z$ component of the stellar surface (or, alternatively, the\ncosine of the angle from the sub-stellar point, $\\upmu$).  The model is more precise\nand accurate than prior models that we have compared to, especially near\nspecial limits such as the points of contact and the coincidence of the edge\nof the occultor with the center of the source.  The model also compares favorably in\nspeed of evaluation, about a factor of three faster than the code of\nto \\citet{Pal2008}, 5-30 faster than that of Gimenez, a factor of 2-25 faster than \\texttt{batman}\n(depending on the order of the limb darkening), and 35-45\\% faster than \\texttt{EXOFAST}.\n\nWe expect that this code may be used both as a workhorse model for\ngeneral fitting of transit models, as well as a tool for more\nspecialized applications, such as photodynamical modeling of\ninteracting planets \\citep{Carter2012}, triple stars \\citep{Carter2011}, and\ntransiting circumbinary planets \\citep{Doyle2011}.\n\nDuring the preparation of this paper, a related paper appeared on\nthe mutual eclipse of multiple bodies \\citep{Short2018}.  Their\napproach is complementary to ours in that they utilize Green's theorem to\ncarry out a numerical quadrature for mulitiple limb darkening models.\nTheir approach does not yet include the computation of derivatives, but\nit allows for a wider range of limb darkening models than polynomial, it\nallows for computation of the Rossiter-McLaughlin effect, and it\ncarries out the computation for multiple overlapping bodies.\n\nThe code presented in this paper is open source and has two versions: one of which is a part\nof the \\starry package, \\texttt{http://github.com/rodluger/starry/}, written\nin a combination of \\texttt{C++} and \\Python, and a new code written in \\texttt{Julia},\n\\texttt{http://github.com/rodluger/Limbdark.jl/}, as\npart of the development of the equations in this paper.  We have also implemented\nthe flux model in \\texttt{IDL}, without derivatives; this is also available within\nthe GitHub repository. We welcome usage of these\ncodes, and contributions to further develop and enhance their capabilities.\n\nAll figures in this paper were autogenerated on Travis-CI from the latest\nversion of our repository. Clickable icons (\\,\\codeicon\\,) next to each figure link\nto the source code used to produce them, and icons (\\,\\prooficon\\,) next to the main \nequations link to derivations or numerical proofs. We encourage the community\nto adopt similar practices to bolster the accessibility, transparency, and\nreproducibility of research in the field.\n\n\n\\acknowledgements\n\nWe thank Andr\\'as P\\'al for sharing his Fortran code, \\texttt{ntiq-fortran.f}.\nWe thank Andr\\'as P\\'al, Kevin Stevenson, Kai Ueltzh\\\"offer, Mario Damasso,\nMatthew Heising, Robert Morehead, and Laura Kreidberg for pointing out\nerrors or inaccuracies in the \\cite{MandelAgol2002} paper and code, which we have\nhopefully rectified in this paper.\nEA acknowledges NSF grant AST-1615315, NASA grant NNX13AF62G, and from\nthe NASA Astrobiology Institute's Virtual Planetary Laboratory Lead Team,\nfunded through the NASA Astrobiology Institute under solicitation NNH12ZDA002C\nand Cooperative Agreement Number NNA13AA93A.  This research was partially \nconducted during the Exostar19 program at the Kavli Institute for Theoretical \nPhysics at UC Santa Barbara, which was supported in part by the National \nScience Foundation under Grant No.\\ NSF PHY-1748958.\n\n\\bibliography{limbdark}\n\n\\appendix\n\n\\section{Errata for Mandel \\& Agol (2002)}\n\nHere are a list of errata for \\citet{MandelAgol2002}:\n\\begin{enumerate}\n\\item In Equation (7), $\\lambda_3$ and $\\lambda_4$ should have $2k \\rightarrow\n2p$ in arguments of the elliptic integrals.\n\n\\item In Equation (7), $\\lambda_5$ should have $- \\frac{2}{3}\\Theta(p-1/2)$\nat the end.\n\n\\item For Case 11 in Table 1, $\\eta^d$ should be 1/2, not 1, and\n$\\lambda^d$ should be zero, not 1.  This mistake affects the code,\nbut it is never encountered for planets that transit main-sequence\nstars since $p<1$.  This typo was discussed in \\citet{Eastman2013}.\n\n\\item The case $z=1-p$ is missing for $z<p$ (as pointed out by\nPal 2008).\n\n\\item There is a $\\pi$ missing in the denominator of the second term\non the right hand side of Equation (8).\n\\end{enumerate}\n\nWith the exception of 3, none of these errors affected the publicly\navailable code.\n\n\\section{Derivatives of general complete elliptic integral}\n\\label{app:cel_derivatives}\n\nIn this appendix, we give the derivatives of $cel$ with respect to\nthe input parameters.\n\n%\\begin{eqnarray}\n%\\frac{\\partial {\\rm cel}()}{\\partial k_c} &=& \\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial k_c} = \\frac{-k_c}{p-k_c^2}\\left[\\mathrm{cel}(k_c,k_c^2,a,b)-\\mathrm{cel}(k_c,p,a,b)\\right],\\\\\n%\\frac{\\partial {\\rm cel}()}{\\partial p} &=& \\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial p} &= \\frac{\\mathrm{cel}(k_c,p,0,\\lambda) +(b-ap)\\mathrm{cel}(k_c,1,1-p,k_c^2-p)}{2p(1-p)(p-k_c^2)},\\\\\n%\\lambda & =& k_c^2(b+ap-2bp)+p(3bp-ap^2-2b),\\\\\n%\\frac{\\partial {\\rm cel}()}{\\partial a } &=& {\\rm cel}(k_c,p,1,0),\\\\\n%\\frac{\\partial {\\rm cel}()}{\\partial b} &=&{\\rm cel}(k_c,p,0,1).\n%\\end{eqnarray}\n\n%\\begin{eqnarray}\n\\begin{proof}{cel_derivative}\n\\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial k_c} &=& \\frac{-k_c}{p-k_c^2}\\left[\\mathrm{cel}(k_c,k_c^2,a,b)-\\mathrm{cel}(k_c,p,a,b)\\right],\\\\\n\\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial p} &=& \\frac{\\mathrm{cel}(k_c,p,0,\\lambda) +(b-ap)\\mathrm{cel}(k_c,1,1-p,k_c^2-p)}{2p(1-p)(p-k_c^2)},\\\\\n\\lambda &=& k_c^2(b+ap-2bp)+p(3bp-ap^2-2b),\\\\\n\\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial a } &=& \\mathrm{cel}(k_c,p,1,0),\\\\\n\\frac{\\partial \\mathrm{cel}(k_c,p,a,b)}{\\partial b} &=& \\mathrm{cel}(k_c,p,0,1).\n%\\end{eqnarray}\n\\end{proof}\n\n\\section{Listing of symbols used in the paper}\n\nTable \\ref{tab:symbols} gives a list of the notation used throughout\nthe main paper.\n\n{\\bf Table \\ref{tab:precision} lists the IEEE 754 interchange formats\nutilized in three versions of this code (\\texttt{Limbdark.jl} and \\texttt{starry})\nwritten in \\texttt{Julia}, \\texttt{Python}, and \\texttt{C++}.}\n\n\\clearpage\n\n\\begin{center}\n\\renewcommand*{\\arraystretch}{1.08}\n\\begin{longtable}{cll}\n\\caption{Symbols used in this paper} \\label{tab:symbols} \\\\\n%\n\\toprule\n\\multicolumn{1}{c}{\\textbf{Symbol}} &\n\\multicolumn{1}{c}{\\textbf{Definition}} &\n\\multicolumn{1}{c}{\\textbf{Reference}} \\\\\n\\midrule\n\\endfirsthead\n%\n\\multicolumn{3}{c}%\n{{\\bfseries \\tablename\\ \\thetable{} --} continued from previous page} \\\\\n\\toprule\n\\multicolumn{1}{c}{\\textbf{Symbol}} &\n\\multicolumn{1}{c}{\\textbf{Definition}} &\n\\multicolumn{1}{c}{\\textbf{Reference}} \\\\\n\\midrule\n\\endhead\n\\bottomrule\n%\n\\endfoot\n%\n\\bottomrule\n\\endlastfoot\n%\n$a_n$           & Gim\\'enez coefficients                & \\eq{gimenez}\\\\\n$\\mathcal{A}$      & Change of basis matrix:\n                 $\\mathbf{u}$ to Green's\n                 polynomials                            & \\eq{A} \\\\\n$\\mathcal{A}_1$    & Change of basis matrix:\n                 $\\mathbf{u}$ to\n                 polynomials                            & \\eq{A1} \\\\\n$\\mathcal{A}_2$    & Change of basis matrix:\n                polynonials to Green's polynomials      & \\eq{gbasis} \\\\\n$A_{lens}$      & Lens-shaped area of overlap of\n                  two circles                           & \\eq{MAuniform}\\\\\n$A_{kite}$      & Kite-shaped area b/w center\n                  of circles and points of contact\t\t& \\eq{Kite_area}\\\\\n$b$             & Impact parameter in units of occulted\n                 body's radius                          &  \\\\\n$b_c$           & Cutoff for using alternative\n                  expression for $d\\mathcal{P}/db$      & \\S\\ref{sec:analytic_derivatives}\\\\\n$c_1-c_4$       & Non-linear limb darkening\n                  coefficients                          &  \\S\\ref{sec:nonlinear}\\\\\n$\\bvec{D}\\,\\wedge$\n                & Exterior derivative                   & \\eq{DGg} \\\\\n$\\mathrm{cel}(k_c,p,a,b)$\n                & General complete elliptic\n                 integral \\citep{Bulirsch1969}          & \\eq{cel}\\\\\n$E(\\bigdot)$    & Complete elliptic integral of the\n                 second kind                            & \\eq{elliptic} \\\\\n$F$             & Normalized flux seen by observer      & \\eq{occint} \\\\\n$\\overline{F}$  & Time-averaged normalized flux         & \\eq{avg_flux} \\\\\n$_2F_1$         & Generalized Hypergeometric function   & \\eq{Mn_series} \\\\\n$\\gbasis$       & Green's basis                         & \\eq{greensbasis} \\\\\n$\\mathfrak{g}$  & Vector in the basis $\\gbasis$         & \\\\\n$\\bvec{G}_n$    & Anti-exterior derivative of the\n                 $n^\\mathrm{th}$\n                 term in the Green's basis              & \\eq{greens_n} \\\\\n$i$             & Dummy index                           & \\\\\n$I$             & Specific intensity, $I(\\x, \\y)$       & \\\\\n$I_0$           & Intensity normalization constant      & \\eq{normalization} \\\\\n$j$             & Dummy index                           & \\\\\n$k$             & Elliptic parameter                    & \\eq{k2} \\\\\n                & Dummy index                           & \\\\\n$k_c$           & $\\sqrt{1 - k^2}$                      & \\eq{cel} \\\\\n$K(\\bigdot)$    & Complete Elliptic integral of the\n                  first kind                            & \\eq{elliptic} \\\\\n$m_k$           & Elliptic integral parameter           & \\S\\ref{sec:reparam}\\\\\n$n$             & Order of limb darkening/Green's basis\t& \\\\\n$\\mathcal{M}_n(r,b)$\n                & Integral computed recursively         & \\eq{M_of_n}\\\\\n$N$             & Highest order of limb darkening polynomial & \\\\\n$\\mathcal{N}_n(r,b)$\n                & Integral computed recursively         & \\eq{N_of_n}\\\\\n$p$             & Cofficient of $cel$\t\t\t        & \\eq{cel}\\\\\n$\\pbasis$       & Polynomial basis                      & \\eq{polybasis} \\\\\n$\\mathfrak{p}$  & Vector in the basis $\\pbasis$         & \\\\\n$q$             & Term in cel identities                & \\eq{cel_identities}\\\\\n                & Term in cel $\\Lambda$\t\t\t& \\eq{biglam_stable}\\\\\n$\\mathcal{P}$   & Primitive integral along perimiter\n                 of occultor                            & \\eq{primitiveP} \\\\\n$\\mathcal{Q}$   & Primitive integral along perimiter\n                 of occulted body                       & \\eq{primitiveQ} \\\\\n$r$             & Occultor radius in units of occulted\n                 body's radius                          & \\S\\ref{sec:intro} \\\\\n$\\bvec{r}$      & Vector for integration over\n                 boundary of visible disk               & \\eq{greens} \\\\\n$\\mathfrak{s}$  & Occultation light curve solution\n                 vector                                 & \\eq{greens} \\\\\n$t$             & Time variable                         & \\S\\ref{sec:time}\\\\\n$t_0$           & Central time of transit               & \\S\\ref{sec:time}\\\\\n%$u$             & Dummy index                           & \\\\\n$u_1, u_2$      & Quadratic limb darkening coefficients & \\eq{quadraticld} \\\\\n$\\ubasis$       & Limb darkening basis                  & \\eq{ldbasis} \\\\\n$\\bvec{u}$      & Vector of limb darkening coefficients\n                 in the basis $\\ubasis$                 & \\S\\ref{sec:poly_limbdark} \\\\\n$\\bvec{x}$      & Parameters used in time integration   & \\S\\ref{sec:time}\\\\\n$\\x$            & Cartesian coordinate                  & \\eq{xyz} \\\\\n$\\y$            & Cartesian coordinate                  & \\eq{xyz} \\\\\n$\\z$            & Cartesian coordinate,\n                 $z = \\sqrt{1 - \\x^2 - \\y^2}$           & \\eq{xyz} \\\\\n%\n$\\alpha_j$      & Coefficient in series for\n                  $\\mathcal{M}_n$                       & \\eq{Mn_series} \\\\\n$\\gamma_j$      & Coefficient in series for\n                  $\\mathcal{N}_n$                       & \\eq{Nn_series} \\\\\n$\\Gamma$        & Gamma function                        & \\\\\n$\\eta$          & Parameter in quadratic limb\n                  darkening term                        & \\eq{eta}\\\\\n$\\theta$        & Polar angle on star with\n                  respect to observer                   & \\\\\n$\\Theta$        & Heaviside step function               & \\eq{biglam} \\\\\n$\\kappa_0$      & Angular position of occultor/occulted\n                  intersection point                    & \\eq{cosine_formulation} \\\\\n$\\kappa_1$      & Angular position of occultor/occulted\n                  intersection point                    & \\eq{cosine_formulation} \\\\\n$\\lambda$       & Angular position of occultor/occulted\n                  intersection point                    & \\eq{primitiveQdef} \\\\\n                & Term in cel identities                & \\eq{cel_identities} \\\\\n$\\Lambda^e$       & Term in uniform transit expression       & \\eq{MAuniform} \\\\\n$\\Lambda$       & \\citet{MandelAgol2002} function       & \\eq{biglam} \\\\\n$\\upmu$         & Cosine of polar angle on star,\n                  $\\upmu = z$                           & \\eq{quadraticld} \\\\\n$\\Pi(\\bigdot,\\bigdot)$\n                & Complete elliptic integral of the\n                 third kind                             & \\eq{elliptic} \\\\\n$\\phi$          & Angular position of occultor/occulted\n                  intersection point                    & \\eq{primitivePdef} \\\\\n$\\varphi$      & Dummy integration variable             & \\\\\n$\\xi$          & Transformed integration variable       & \\eq{greens_transformed}\\\\\n%\n\\end{longtable}\n\\end{center}\n\n{\\bf \n\\begin{tabular}{lll}\nLanguage & Variable type & IEEE 754 interchange format & precision for 1.0\\\\\nJulia & Float64 & binary64 & $2.0^{-52} = 2.22e-16$\\\\\nJulia & BigFloat & binary256 & $2.0^{-255} = 1.73e-77 \\\\\n\\end{tabular}}\n\\end{document}\n", "meta": {"hexsha": "ac86e9bcac61b95e6a8658b1634df58f350bd031", "size": 130898, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/limbdark.tex", "max_stars_repo_name": "dfm/limbdark", "max_stars_repo_head_hexsha": "364c19e6f16001e417474dcf7b4621af12460207", "max_stars_repo_licenses": ["MIT"], "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/limbdark.tex", "max_issues_repo_name": "dfm/limbdark", "max_issues_repo_head_hexsha": "364c19e6f16001e417474dcf7b4621af12460207", "max_issues_repo_licenses": ["MIT"], "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/limbdark.tex", "max_forks_repo_name": "dfm/limbdark", "max_forks_repo_head_hexsha": "364c19e6f16001e417474dcf7b4621af12460207", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-06-17T08:39:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-23T19:17:21.000Z", "avg_line_length": 49.4514544768, "max_line_length": 211, "alphanum_fraction": 0.6992391022, "num_tokens": 38700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6429906928727571}}
{"text": "\\section{Solving Schrodinger equation}\n\n\\subsection{Operators}\n\nKinetic energy operators (multicolumns):\n\n\\begin{juliacode}\nfunction op_K( pw::PWGrid, psi::Array{Complex128,2} )\n  out = zeros(Complex128,size(psi))\n  Ncol = size(psi,2)\n  Ω = pw.Ω\n  G2 = pw.G2\n  Npoints = pw.Npoints\n  for is = 1:Ncol\n    for ip = 1:Npoints\n      out[ip,is] = psi[ip,is]*G2[ip]\n    end\n  end\n  return 0.5*out\nend\n\\end{juliacode}\n\nApplying potential\n\n\\begin{juliacode}\nfunction op_Vpot( pw::PWGrid, Vpot, psi::Array{Complex128,2} )\n  Ns = pw.Ns\n  Ω = pw.Ω\n  Npoints = prod(Ns)\n  # get values of psi in real space grid via forward transform\n  ctmp = G_to_R( Ns, psi )\n  return R_to_G( Ns, Diagprod(Vpot, ctmp) )\nend\n\\end{juliacode}\n\nFunction {\\tt Diagprod}:\n\n\\begin{juliacode}\nfunction Diagprod( a,B )\n  Ncol    = size(B)[2]\n  Npoints = size(B)[1]\n  out = zeros( Complex128, size(B) )\n  for ic = 1:Ncol\n    for ip = 1:Npoints\n      out[ip,ic] = a[ip]*B[ip,ic]\n    end\n  end\n  return out\nend\n\\end{juliacode}\n\nHamiltonian operator:\n\n\\begin{juliacode}\nfunction op_H( pw, Vpot, psi )\n  return op_K( pw, psi ) + op_Vpot( pw, Vpot, psi )\nend\n\\end{juliacode}\n\n\n\\subsection{Gradient calculation}\n\nGradient of energy with respect to wave function\n\nNot using occupation number\n\n\\begin{juliacode}\nfunction calc_grad( pw::PWGrid, Vpot, psi::Array{Complex128,2} )\n  Npoints = size(psi)[1]\n  Nstates = size(psi)[2]\n  Ω = pw.Ω\n  Ns = pw.Ns\n  #\n  grad = zeros( Complex128, Npoints, Nstates )\n  H_psi = op_H( pw, Vpot, psi )\n  for i = 1:Nstates\n    grad[:,i] = H_psi[:,i]\n    for j = 1:Nstates\n      grad[:,i] = grad[:,i] - dot( psi[:,j], H_psi[:,i] ) * psi[:,j]\n    end\n  end\n  return grad\nend\n\\end{juliacode}\n\n\n\n\\subsection{Calculation of charge density}\n\n\\begin{juliacode}\nfunction calc_rho( pw::PWGrid, psi::Array{Complex128,2} )\n  Ω = pw.Ω\n  Ns = pw.Ns\n  Npoints = pw.Npoints\n  Nstates = size(psi)[2]\n  #\n  ρ = zeros(Complex128,Npoints)\n  # Transform to real space\n  psiR = G_to_R(Ns,psi)\n  # orthonormalization in real space\n  ortho_gram_schmidt!(Nstates,psiR); scale!(sqrt(Npoints/Ω),psiR)\n  for is = 1:Nstates\n    for ip = 1:Npoints\n      ρ[ip] = ρ[ip] + conj(psiR[ip,is])*psiR[ip,is]\n    end\n  end\n  return real(ρ)\nend\n\\end{juliacode}\n\n\n\\subsection{Calculation of total energy}\n\n\n\\begin{juliacode}\nfunction calc_Etot( pw::PWGrid, Vpot, psi::Array{Complex128,2} )\n  Ω = pw.Ω\n  Npoints = pw.Npoints\n  Nstates = size(psi)[2]\n  Kpsi = op_K( pw, psi )\n  Ekin = 0.0\n  for is = 1:Nstates\n    Ekin = Ekin + real( dot( psi[:,is], Kpsi[:,is] ) )\n  end\n  # Calculate in real space\n  rho = calc_rho( pw, psi )\n  Epot = dot( rho, Vpot ) * Ω/Npoints\n  Etot = Ekin + Epot\n  return Etot\nend\n\\end{juliacode}\n\n\n\\subsection{Energy minimization with steepest descent}\n\n\\begin{juliacode}\nfunction Sch_solve_Emin_sd( pw::PWGrid, Vpot, psi::Array{Complex128,2};\n                            NiterMax=1000 )\n  α = 3e-5\n  Etot_old = 0.0\n  Etot = 0.0\n  for iter = 1:NiterMax\n    psi = psi - α*calc_grad( pw, Vpot, psi )\n    psi  = ortho_gram_schmidt(psi)\n    Etot = calc_Etot( pw, Vpot, psi )\n    conv = abs(Etot-Etot_old)\n    if conv < 1e-6\n      break\n    end\n    Etot_old = Etot\n  end\n  return psi, Etot\nend\n\\end{juliacode}\n\n\n\\subsection{Energy minimization with conjugate gradient}\n\n\\begin{juliacode}\nfunction Sch_solve_Emin_cg( pw::PWGrid, Vpot, psi::Array{Complex128,2};\n                            NiterMax=1000 )\n  #\n  Npoints = size(psi)[1]\n  Nstates = size(psi)[2]\n  d = zeros(Complex128, Npoints, Nstates)\n  g_old  = zeros(Complex128, Npoints, Nstates)\n  d_old  = zeros(Complex128, Npoints, Nstates)\n  Kg     = zeros(Complex128, Npoints, Nstates)\n  Kg_old = zeros(Complex128, Npoints, Nstates)\n  #\n  α_t = 1.e-5\n  β = 0.0\n  Etot_old = 0.0\n  Etot = 0.0\n  #\n  for iter = 1:NiterMax\n    g = calc_grad( pw, Vpot,  psi)\n    nrm = 0.0\n    for is = 1:Nstates\n      nrm = nrm + real( dot( g[:,is], g[:,is] ) )\n    end\n    Kg = Kprec(pw,g)\n    if iter != 1\n      β = real( sum( conj(g) .* Kg ) ) / real( sum( conj(g_old) .* Kg_old ) )\n    end\n    d = -Kg + β * d_old\n    psic = ortho_gram_schmidt(psi + α_t*d)\n    gt = calc_grad( pw, Vpot, psic )\n    denum = real(sum(conj(g-gt).*d))\n    if denum != 0.0\n      α = abs(α_t*real(sum(conj(g).*d))/denum)\n    else\n      α = 0.0\n    end\n    # Update wavefunction\n    psi = psi[:,:] + α*d[:,:]\n    psi = ortho_gram_schmidt(psi)\n    Etot = calc_Etot( pw, Vpot, psi )\n    diff = abs(Etot-Etot_old)\n    @printf(\"E step %8d = %18.10f %18.10f %18.10f\\n\", iter, Etot, diff, nrm/Nstates)\n    if diff < 1e-6\n      @printf(\"CONVERGENCE ACHIEVED\\n\")\n      break\n    end\n    g_old = copy(g)\n    d_old = copy(d)\n    Kg_old = copy(Kg)\n    Etot_old = Etot\n  end\n  return psi, Etot\nend\n\\end{juliacode}\n\n\n{\\color{red}\nUsing energy minimization:\n\nIntroduction to minimization\n\nsimple 2D minimization, using steepest-descent and conjugate gradient\nmethod\n\nUsing iterative diagonalization: Davidson and LOBPCG\n\nbackground information about iterative diagonalization\n\nEigenvalue problems\n\n}\n", "meta": {"hexsha": "fef06fe3436805fa185c5999493f77b843219da3", "size": 4962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/Doc/sch_01.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/sch_01.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/sch_01.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": 21.5739130435, "max_line_length": 84, "alphanum_fraction": 0.6340185409, "num_tokens": 1821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6429906881361487}}
{"text": "\\chapter{Magnetostatics}\nWe have been discussing electrostatics, which deals with electric field created by static charges. Now it's time to look into a different phenomenon, the production and properties of magnetic field, whose source is steady current, i.e., charges in motion. An essential difference between the electrostatics and magnetostatics is that electric charges can be isolated, i.e., there exist positive and negative charges which can exist by themselves. Unlike this situation, magnetic charges (which are known as magnetic monopoles) cannot exist in isolation, every north magnetic pole is always associated with a south pole, so that the net magnetic charge is always zero.\\\\\nSources of magnetic field are steady currents. In such a field a moving charge experiences a sidewise  force.  Recall that an electric field exerts a force on a charge, irrespective of whether the charge is  moving or static. Magnetic, field, on the other hand, exerts a force only on charges that are moving.  Under the combined action of electric and magnetic fields, a charge experiences, what is known as Lorentz force,\n\\section{Lorent'z Force Law}\nThe magnetic force on a charge $Q$ moving with a velocity $V$ in a magnetic field $B$ is given by,\n\\begin{equation}\\label{Lorent'z Force Law 1}\n\\vec{F}_{mag}=Q(\\vec{V}\\times \\vec{B})\n\\end{equation}\nAn electric field exerts a force on a charge, irrespective of whether the charge is\nmoving or static. Magnetic, field, on the other hand, exerts a force only on charges that are moving. In the presence at both electric and magnetic field, a charge experiences, what is known as Lorentz force,\nThe net force on $Q$ would be,\n\\begin{equation}\\label{Lorent'z Force Law 2}\n\\vec{F}=Q[\\vec{E}+\\vec{V}\\times \\vec{B}]\n\\end{equation}\n\\subsection{Force on a Conductor in a magnetic field}\nLorentz force law deals with a point charge moving in a magnetic field. Now we are going to find the expression for  force on a conductor in a magnetic field having line charge density $\\lambda$.\\\\\nConsider the figure and a point p on it .Suppose we are measuring the flow of charges in a time intervel $\\Delta t$ through the point p.Let the velocity of electrons be $\\vec{V}$.Therefore the charge flowing through the point in $\\Delta t$ time is $\\lambda V \\Delta t$.Since $\\lambda$ is the line charge density. \\\\\n\\begin{minipage}{.65\\textwidth}\n\t\\begin{align*}\n\t\\text{current } I&=\\frac{Q}{t}\\\\\n\tI&=\\frac{\\lambda \\vec{V} \\Delta t}{\\Delta t}=\\lambda \\vec{V}\n\t\\intertext{The magnetic force on a line segment of length $d l$ and charge $dq$ is given by Lorentz force law}\n\t\\vec{F}&=(\\vec{V} \\times \\vec{B}) d q=(\\vec{V} \\times \\vec{B}) \\lambda d l \\quad \\quad dq=\\lambda dl\\\\\n\t\\text{Total}\\quad \\vec{F}&=\\int(\\vec{V} \\times \\vec{B}) \\lambda d l\\\\\n\t&=\\int(I \\times \\vec{B}) d l=\\int I(\\vec{dl}\\times \\vec{B} ) \\quad \\quad I=\\lambda \\vec{V}\\\\\n\tF_{mag}&=I\\int(\\vec{dl}\\times \\vec{B})\n\t\\end{align*}\n\\end{minipage}\n\\begin{minipage}{.40\\textwidth}\n\t\\includegraphics[height=3cm,width=5cm]{07-crop}\n\\end{minipage}\n\\subsection{Direction of force: Fleming's left hand rule (Motor rule):}\n\\begin{minipage}{0.60\\textwidth}\nWhen a current carrying conductor is placed in an external magnetic field, the conductor experiences a force.THe direction of the force is given be Fleming's left hand rule.\\\\ Stretch thumb, index finger, middle finger in 3 mutually perpendicular direction. If middle finger points in the direction of current and index finger in the direction of field. Then the direction of force is given by thumb.\n\\end{minipage}\\hfil\n\t\\begin{minipage}{0.25\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=3cm]{Flemings left hand rule}\n\t\t\\caption{Flemings left hand rule}\n\t\t\\label{Flemings left hand rule}\n\t\\end{figure}\n\\end{minipage}\n\\subsection{Force on Surface with surfece Current Density K in a magnetic field}\nIf $d I$ is the small current through a ribbon on the surface and $d l_{\\perp}$ is the perpendicular length then \\\\\n\\begin{minipage}{.40\\textwidth}\n\t\\begin{align*}\n\t\\vec{K} \\equiv \\frac{d I}{d l_{\\perp}}\n\t\\end{align*}\n\\end{minipage}\n\\begin{minipage}{.30\\textwidth}\n\t\\includegraphics[width=0.6\\textwidth]{08-crop}\n\\end{minipage}\n\\begin{align*}\n\\intertext{Which is the current per unit width perpendicular to flow}\n\\text{But} \\quad \\vec{K}&=\\sigma V\\\\\n\\text{Where} \\quad \\sigma&= \\text{surface charge density}\\\\\n\\text{so magnetic }&\\text{force on Surface current is}\\\\\n\\vec{F}_{m a g}&=\\int(\\vec{V} \\times \\vec{B}) \\sigma d a=\\int(\\vec{K} \\times \\vec{B}) d a\n\\end{align*}\n\\subsection{Force on a Volume With volume Current Density J in a magnetic field}\nConsider a tube of infinitesmal cross section $da_\\perp$ running parallel to the flow . If the current in this tube is $dI$ the volume current density is,\\\\\n\\begin{minipage}{0.6\\textwidth}\n\\begin{align*}\n\\vec{J} &\\equiv \\frac{d I}{d a_{\\perp}}\\\\\n\\text{$J$ is the current }&\\text{per unit area - perpendicular to flow}\\\\\n\\vec{J}&=\\rho \\vec{V}\\\\\n\\rho&= \\text{volume charge density}\n\\intertext{The magnetic force  on a volume current,}\nF_{mag}&=\\int(\\vec{V} \\times \\vec{B}) \\rho d \\tau=\\int(\\vec{J} \\times \\vec{B}) d \\tau\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{diagram-20220222(7)-crop-20220222162321}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\t\n\\end{minipage}\n\\subsection{Equation of Continuity}\nCurrent is a scalar quantity which is the amount of charge that\ncrosses the boundary of a surface of a volume per unit time, the surface being oriented normal to the\ndirection of flow. In the steady state there is no accumulation of charge inside a volume through whose\nsurface the charges flow in. This results in the “equation of continuity” .\n\\begin{align*}\n\\vec{J}&=\\frac{d I}{d a_{\\perp}}\\\\\n\\text{so }&\\text{current crossing a surface.}\\\\\nI&=\\int \\vec{J} d a_{\\perp}=\\int \\vec{J} \\cdot d a\\\\\n\\text{current }&\\text{through a closed surface $S$}\\\\\nI&=\\oint \\vec{J} \\cdot d a=\\int_{V}({\\nabla} \\cdot {\\vec{J}}) d \\tau\n\\intertext{Because charge is conserved, whatever flows out through the surface must come at the expense of that remaining inside.}\n\\int_{V} \\nabla \\cdot \\vec{J} d \\tau&=\\frac{-d}{d t} \\int_{V} \\rho d \\tau=-\\int \\frac{\\partial  \\rho}{\\partial  t} d \\tau\\\\\n\\nabla\\cdot \\vec{J}&=-\\frac{\\partial  \\rho}{\\partial  t}\\\\\n\\nabla\\cdot \\vec{J}+\\frac{\\partial  \\rho}{\\partial  t}&=0\\Rightarrow \\text{  Continuity equation}\n\\intertext{The principle is a statement of conservation of electric charge.}\n\\end{align*}\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][1.5cm]{4cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering \n\t\t\\textbf{Equation of continuity}\\\\ \\vspace{0.2cm}\n\t\t$\\nabla\\cdot J+\\frac{\\partial  \\rho}{\\partial  t}=0$} \n}\n\\begin{note}\n\tWhen a steady current flows in a wire, its magnitude $I$ must be same all along the line. Otherwise the charge would be piling up some where, it wouldn't be a steady current. That is $\\frac{d \\rho }{d t}=0$ for steady current then.\n\t$$\\nabla \\cdot \\vec{J}=0$$\n\tSteady current produces magnetic field that are constant in time.\n\\end{note}\n\\section{Biot Savart law}\n \\begin{wrapfigure}{r}{0.25\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.15\\textwidth]{diagram-20210417(4)-crop}\n\t\\end{center}\n\t\\caption{Biot Savart law}\n\\end{wrapfigure}\nMagnetic field due to a steady current ${(\\frac{d\\rho}{dt}=0)}$\\ is given by Biot Savart law.\nThe magnetic field at any point $P$ due to the current can be calculated by adding up the magnetic field contributions, $d \\vec{{B}}$, from small segments of the wire $d \\vec{l}$.\n\t\\\\Suppose we have a current carrying conductor having current '$I$' flowing through it. If $dl$ is the small length element on it. Then the magnetic field $\\vec{B}$ at any point at a distance $r$ from $dl$ is given by,\n\t\\begin{center}\n\t\\begin{equation}\\label{key}\n\t\\vec{dB}={\\frac{\\mu_0}{4\\pi}\\frac{Idl\\times{\\hat{r}}}{r^2}}=\\frac{\\mu_0}{4\\pi}\\frac{Idl\\sin\\theta}{r^2}\\qquad \\vert{\\hat{r}\\vert}=1\n\t\\end{equation}\n\t\\end{center}\n\tWhere $\\theta$ \\ is the angle between $I$ and the distance $r$ . So the direction of magnetic field is $\\perp^r$\\ to both $dl$\\ and $dr$. \\\\Then the magnetic field due to whole wire is ,\n\t\\begin{center}\n\t\t\\begin{equation}\\label{key}\n\t\tB=\\frac{\\mu_0}{4\\pi}\\int\\frac{Idl\\times\\hat{r}}{r^3}\n\t\t\\end{equation}\n\t\\end{center}\n Where $\\mu_0$ is the permeability of free space, $ \\mu_0=4\\pi\\times10^{-7}\\frac{N}{A^2}$\\\\\nUnit of\\ $B =N/A.m $\\ or Tesla $T$\n\t\\begin{alignat*}{2}\n\t&\\textbf{For surface current:}\\quad  &&B=\\frac{\\mu_0}{4\\pi}\\int\\frac{k\\times\\hat{r}}{r^2}da\\\\ \n\t&\\textbf{For volume current J:}\\quad  &&B=\\frac{\\mu_0}{4\\pi}\\int\\frac{J\\times\\hat{r}}{r^2}d\\tau \\quad \\text{or}\\quad B=\\frac{\\mu_0}{4\\pi}\\int\\frac{J\\times\\vec{r}}{r^3}d\\tau\\\\\n\t\\end{alignat*}\n\\begin{note}\n\t\\begin{enumerate}\n\t\t\\item Biot Savart law cannot be applied to a moving point charge.  Because a moving point charge can't be considered as steady current.\n\t\t\n\t\t\\item The direction of magnetic field around a current carrying conductor is given by Right hand thumb rule,which states that when you hold the conductor in your right hand pointing thumb in the direction of current then your fingeres curl around the direction of magnetic field.\\\\\n\t\t\n\t\t\n\t\t\\begin{figure}[H]\n\t\t\t\\begin{minipage}{0.45\\textwidth}\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[height=4cm,width=2.2cm]{diagram-20210417(4)-crop}\n\t\t\t\\end{minipage}\n\t\t\t\\begin{minipage}{0.45\\textwidth}\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[height=4cm,width=2.7cm]{diagram-20210417(5)-crop}\n\t\t\t\\end{minipage}\n\t\t\t\\caption{}\n\t\t\t\\label{parellel}\n\t\t\\end{figure}\t \n\t\\end{enumerate}\n\t\n\\end{note}\n\n\\subsection{Applications of Biot-Savart law}\n\\subsubsection{Magnetic field due to a long straight wire.}\nLet us consider a long straight wire carrying a steady current I. We need to find the magnetic field $B$ a distance S from the wire.\n\\begin{figure}[H]\n\\begin{minipage}{0.45\\textwidth}\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{diagram-20210417(6)-crop}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\t\\centering\n\t\\includegraphics[height=4cm,width= 5cm]{diagram-20210417(7)-crop}\n\t\\end{minipage}\n\\caption{Magnetic field due to line element.}\n\\label{Magnetic field due to line element}\n\\end{figure}\nField due to a small length element in figure \\ref{Magnetic field due to line element}\n\\begin{align*}\ndB &=\\frac{\\mu_0}{4\\pi}\\frac{Idl\\sin\\alpha}{r^2}\\qquad\n \\Rightarrow\\alpha=\\theta+90\\\\\ndl\\sin \\alpha &=dl\\cos\\theta\\\\\nl&=S \\tan\\theta\\\\\n\\text{Integrating,}\\qquad dl &=\\frac{S}{\\cos^2\\theta}d\\theta\\\\\n\\text{And}\\quad S&=r\\cos\\theta\\\\\n\\therefore\\frac{1}{r^2}&=\\frac{\\cos^2\\theta}{S^2}\\\\\n\\therefore dB=\\frac{\\mu_0}{4\\pi}\\frac{Idl\\cos\\theta}{r^2}&=\\frac{\\mu_0}{4\\pi}\\frac{ISd\\theta}{\\cos^2\\theta}\\times\\frac{\\cos^2\\theta}{S^2}\\times\\cos\\theta\\\\\n&=\\frac{\\mu_0I}{4\\pi S}cos\\theta d \\theta\n\\intertext{When we consider a wire segment  making an angle $\\theta_1$,and $\\theta_2$ with the point $P$ then $B$ is given by integrating between the limits  $\\theta_1$,and $\\theta_2$}\nB&=\\frac{\\mu_0I}{4\\pi S}\\int\\cos d \\theta_2\\\\\nB&=\\frac{\\mu_0I}{4\\pi S}[\\sin\\theta_2-\\sin\\theta_1]\n\\end{align*}\n\n\\hspace{5.10cm}\\framebox{\n\t\n\t\\parbox[t][2.0cm]{7cm}{\n\t\t\n\t\t\\addvspace{0.2cm} \\centering\n\t\\textbf{\tMagnetic field due to a long straight wire.} \\\\ \\vspace{0.4cm}\n\t\t$B=\\frac{\\mu_0I}{4\\pi s}[\\sin\\theta_2-\\sin\\theta_1]$} \n}\n\\opencutright\n\\renewcommand\\windowpagestuff{\n\t\\centering\\includegraphics[height=3cm,width= 4cm]{12-crop}}\n\\begin{note}\n\t\\vspace{0.5cm}\n\t\\begin{cutout}{3}{\\dimexpr\\linewidth-7cm\\relax}{0pt}{1}\n\t\t{\\textbf{ For an infinite wire:}}\n\t\\begin{align*}\n\t\\theta_{1}&=\\frac{-\\pi}{2}\\quad ; \\quad\n\t\\theta_{2}=\\frac{\\pi}{2}\\\\\\\\\n\tB&=\\frac{\\mu_{0} I}{4 \\pi s}\\left(\\sin \\frac{\\pi}{2}-\\sin \\frac{-\\pi}{2}\\right)\\\\\n\t&=\\frac{\\mu_{0} I}{4 \\pi s}\\times2\n  \\\\&=\\frac{\\mu_{0} I}{2 \\pi s}\n\t\\end{align*}\n\tThus for an infinitely long wire the magnetic field, \n\t\\begin{equation*}\n\tB=\\frac{\\mu_{0} I}{2 \\pi s}\n\t\\end{equation*}\n\t\\end{cutout}\n\\end{note}\n\\subsubsection{Magnetic field due to a circular loop.}\n Let us consider a circular loop of radius $ R  $\\ which carries a steady current I, the magnetic field a distance $ z $ above the center\n\n\\begin{minipage}{0.55\\textwidth}\n\\begin{align*}\n\t\\intertext{Magnetic field at $P$ due to $dl$ is given by,}\n\td \\vec{B}&=\\frac{\\mu_{0}I}{4 \\pi} \\frac{ d \\vec{l} \\times \\vec{a}}{a^{3}}\\hspace{2cm} \\begin{array}{cc}\n\tdl\\perp a\\\\\n\t\\therefore\\sin90=1\n\t\\end{array}\\\\\n\td \\vec{B}&=\\frac{\\mu_{0}I}{4 \\pi} \\frac{ d {l} }{a^{2}}\n\t\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\centering\n\t\\includegraphics[height=3.2cm,width= 6cm]{diagram-20210420-crop}\n\\end{minipage}\\\\\\\\\n$dB$ resolved in to two component $dB \\cos \\theta, dB \\sin \\theta $ due to symmetry the vertical components cancel and the horizontal components combine to give the total magnetic field $B$,\n\t\n\n\\begin{minipage}{0.60\\textwidth}\n\t\\begin{align*}\n\t\tB&=\\int dB \\cos \\theta\\\\\n\tB&=\\frac{\\mu_0I}{4\\pi} \\int \\frac{dl \\cos \\theta}{a^2}\n\t\\intertext{$\\cos \\theta$ \\ and \\  $a^2$ are constants and $\\int dl$ is simply the circumference $2\\pi r$.}\n\t\\therefore B&=\\frac{\\mu_0 I}{4\\pi} \\frac{\\cos \\theta}{a^2}\\times 2\\pi R\\\\\n\t\\therefore B&=\\frac{\\mu_0 I}{4\\pi}\\frac{R^2\\times2\\pi}{(R^2+z^2)^\\frac{3}{2}}\\\\  \\therefore B&=\\frac{\\mu_0 I}{2} \\frac{R^2}{(R^2+z^2)^\\frac{3}{2}}\n\t\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.40\\textwidth}\n\t\t\\vspace{3cm}\n\t\\begin{align*}\n\t\\text{but,}\\quad\n\t\\cos \\theta &=\\frac{R}{a}\\\\\n\t\\cos \\theta &=\\frac{R}{(R^2+z^2)^\\frac{1}{2}}\\\\\n\ta&={(R^2+z^2)^\\frac{1}{2}}\\\\\n\ta^2&={(R^z+z^2)}\n\t\\end{align*}\n\\end{minipage}\n\\begin{corollary}\\hspace{0.5cm}\n\t\\begin{enumerate}\n\t\t\\item At the center of the circle\n\t\t\\begin{align*}\n\t\tB&=\\frac{\\mu_0 I}{2}\\frac{R^2}{(R^2+z^2)^\\frac{3}{2}}\\\\\n\t\t\\text{At center }\\ z&=0\\\\\n\t\tB&=\\frac{\\mu_0 I}{2 R}\n\t\t\\end{align*}\n\t\t\\item When there are n no of turns,\n\t\t\\begin{align*}\n\t\tB&=\\frac{\\mu_0 n I}{2 R} \\ \\ \\ (\\text{At center} ) \n\t\t\\end{align*}\n\t\\end{enumerate}\n\\end{corollary}\n\\subsection{Some important results}\n\\begin{enumerate}\n\t\\item Important Points\n\tWhen two circular coils of radius $r_{1}$ and $r_{2}$, having same material and same number of turns are connected in series, the current through each coil is same, the ratio of the magnetic field induction at their centre is given by\n\t$$\n\t\\frac{B_{1}}{B_{2}}=\\frac{r_{2}}{r_{1}}\n\t$$\n\t\\item If two solenoids having turns $N_{1}$ and $N_{2}$ are connected in series, then current is same in both. Then\n\t$$\n\t\\frac{B_{1}}{B_{2}}=\\frac{N_{1}}{N_{2}}\n\t$$\n\t\\item If a current $i$ flows through a circular path of radius $r$ which subtends an angle $\\alpha$ (in radius) at the centre, as shown in figure, the magnetic field induction at the centre $O$ is given by $B=\\frac{\\mu_{0}i}{2r} \\frac{\\alpha }{2\\pi}$.\n\t\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.15\\textwidth]{field}\n\t\t\\end{center}\n\t\\end{figure}\n\\end{enumerate}\n\\begin{exercise}\n\tFind the magnetic field $B$ at the center of a squar loop of side $a$,if current I is flowing in the anticlockwise direction.which is the result when we consider a finite length.\n\\end{exercise}\n\\opencutright\n\\renewcommand\\windowpagestuff{\n\t\\centering\\includegraphics[width=2cm]{diagram-20210417(9)-crop}}\n\\begin{answer}\n\t\\vspace{1cm}\n\t\\begin{cutout}{3}{\\dimexpr\\linewidth-6cm\\relax}{0pt}{6}\n\t\t\\begin{align*}\n\t\tB\\ \\text{at}\\  P\\ \\text{due to one side,}\\\\\n\t\tB&=\\frac{\\mu_0I}{4\\pi \\frac{a}{2}}[\\sin\\theta_2-\\sin\\theta_1]\\\\\n\t\t\\theta_1&=-45 \\quad \\theta_2=45\\\\\\\\\n\t\tB&=\\frac{\\mu_0I}{4\\pi \\frac{a}{2}}\\times\\frac{2}{\\sqrt{2}}=\\frac{\\mu_0I}{\\pi a}\\times\\frac{1}{\\sqrt{2}}\\\\\n\t\t\\text{So total field at P,}\\\\\n\t\tB&= 4\\times\\frac{\\mu_0I}{\\pi a} \\times \\frac{1}{\\sqrt{2}}=\\frac{2\\sqrt{2}\\mu_0I}{\\pi a}\n\t\t\\end{align*}\n\t\\end{cutout}\n\\end{answer}\n\n\n\\begin{exercise}\n\tFind the field at the center of a regular $n$ sided polygon carrying a steady current $I$. $R$ be the distance from center to any side.\n\\end{exercise}\n\\begin{answer}\n\t for a $n$ sided polygon vertex of each side make an angle $\\frac{\\pi}{n}$ with center $P$ .\\\\\n\t \\begin{figure}[H]\n\t \t\\centering\n\t \t\\includegraphics[height=3cm, width=3.5cm]{diagram-20210420(1)-crop}\n\t \\end{figure}\n \n\t\\begin{minipage}{0.60\\textwidth}\\hfill\n\t\t\\begin{align*}\n\t\t\\therefore B&=n\\times\\frac{\\mu_0 I}{4 \\pi d}(\\sin\\frac{\\pi}{n}-\\sin\\frac{-\\pi}{n})\\\\\n\t\t&=n\\times\\frac{\\mu_0 I}{4 \\pi R \\cos\\frac{\\pi}{n}}\\times2 \\sin\\frac{\\pi}{n}\\\\\n\t\t&=n\\times\\frac{\\mu_0 I}{2 \\pi R}\\tan \\frac{\\pi}{n}\\\\\n\t\t&=\\frac{\\mu_0 I}{2 \\pi R}\\tan \\frac{\\pi}{n}\n\t\t\\end{align*}\n\t\\end{minipage}\n\t\\begin{minipage}{0.40\\textwidth}\n\t\t\\begin{align*}\n\t\t\\sin(-\\theta)=-\\sin \\theta\\\\\n\t\t\\cos\\frac{\\pi}{n}=\\frac{d}{R}\\\\\n\t\t\\therefore d=R\\cos\\frac{\\pi}{n}\n\t\t\\end{align*}\n\t\\end{minipage}\n\n\t\\begin{corollary}\n\t\t\\begin{align*}\n\t\t\t\\intertext{When $n =\\infty$\\  Polygon become circle.}\n\t\t\\therefore \\text{when}\\\tn\\rightarrow\\infty, \\quad\\tan\\frac{\\pi}{n}&=\\frac{\\pi}{n}\\\\\n\t\t\\therefore B&=\\frac{\\mu_0 I}{2 \\pi R}\\frac{\\pi}{n}\\\\&=\\frac{\\mu_0I}{2R} (\\text{When , n=1})\n\t\t\\end{align*}\n\t\\end{corollary}\n\\end{answer}\n\\begin{exercise}\nFind the magnetic field at point $P$ for each of the steady current configuration.\\\\\n\t(\\textbf{a}) \n\t\\begin{minipage}{0.25\\textwidth}\\hfill\n\t\t\\centering\n\t\t\\includegraphics[width=0.75\\textwidth]{diagram-20210420(2)-crop}\n\t\\end{minipage} \\hspace{2cm}\n\t(\\textbf{b})\n\t\t\\begin{minipage}{0.25\\textwidth}\\hfill\n\t\t\t\t\\centering\n\t\t\t\\includegraphics[width=1\\textwidth]{diagram-20210421-crop}\n\t\t\\end{minipage}\n\\end{exercise}\n\\begin{answer}\n\t\\vspace{0.2cm}\n\t(\\textbf{a})\\\\\n\tMagnetic field due to the segment at the end points of the annular region is zero. Because the magnetic field at  a point along the direction of a line segment is zero. Now we have to consider the two circular part.\\\\\n  Field at $P$ due to part with radius $a$,\n \\begin{align*}\n B&=\\frac{1}{4}\\times \\frac{\\mu_0 I}{2a}\\quad \\text{Out to plane of the paper}\\\\\n \\intertext{field at $p$ due to region $b$}\n B&=\\frac{1}{4}\\times \\frac{\\mu_0 I}{2b}\\quad \\text{In to the plane of the paper.}\\\\\n \\therefore \\text{Total}\\quad B\\quad\\text{at}\\quad P &=\\frac{\\mu_0 I}{4\\times2}(\\frac{1}{a}-\\frac{1}{b})\n \\end{align*}\n\t(\\textbf{b})\\\\\n\t\\begin{center}\n\t\t\\begin{minipage}{0.45\\textwidth}\\hfill\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm, width=4.5cm]{diagram-20210421-crop}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}{0.45\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm, width=4.5cm]{diagram-20210420(5)-crop}\n\t\t\\end{minipage}\n\t\\end{center}\n\t\n\tWe can divide the segment in to two part field at $P$ due to circular part is\n\t\\begin{align*}\n B&=\\frac{1}{2}\\times \\frac{\\mu_0 I}{2R}=\\frac{\\mu_0 I}{4 R} \\intertext{Field due to lower segment,}\nB&=\\frac{\\mu_0 I}{4 \\pi R}(\\sin \\theta_2-\\sin \\theta_1)  \\qquad\\begin{array}{l}\n\\text{Here,}\\\\\\theta_1=0 \\\\\n\\theta_2=\\frac{\\pi}{2} \n\\end{array}\\\\\n\\therefore B&=\\frac{\\mu_0 I}{4 \\pi R}\n\\intertext{Field due to the upper segment also equal to,}\nB&=\\frac{\\mu_0}{4 \\pi R}\n\\intertext{Field due to all the three segment are directed in to the plane of thepaper. So}\nB&=\\frac{\\mu_0 I}{4 R}+\\frac{\\mu_0 I}{4 \\pi R}+\\frac{\\mu_0 I}{4 \\pi R}\\\\\n&=\\frac{\\mu_0 I}{4\\pi R}(\\pi+2)\n\\end{align*}\n\\end{answer}\n\\section{ Force Between Two Parallel Current Carrying Conductors}\n\\begin{enumerate}\n\t\\item  The two long parallel conductors carrying currents in the same directions attract each other.And conductors carrying currents in the opposite direction repel each other.\n\t\\item  The force acting per unit length of each conductor will be $F=\\frac{\\mu_{0}}{4 \\pi} \\frac{2 I_{1} I_{2}}{r}$\n\t\\item  The force of attraction or repulsion acting on each conductor of length $l$ due to current in two parallel conductors is\n\t$$\n\tF=\\frac{\\mu_{0}}{4 \\pi} \\frac{2 I_{1} I_{2}}{r} l\n\t$$\n\t\\item The force acting on two parallel current carrying conductors are equal in magnitude and opposite in direction.\n\t\\item If two linear current carrying conductors of unequal length are held parallel to each other,then the force on a long conductor is due to magnetic field interaction due to currents of short and long conductor. If $l, L=$ length of short and long conductor respectively. $I_{1} \\mathrm{I}_{2}=$  current through short and long conductors respectively and r is the seperation between these two parallel conductors ,\\\\\n\tfor a long conductor$$B=\\frac{\\mu_{0}}{4\\pi}\\frac{2I_1I_2}{r}l$$\n\t\\item  when two currents approach a point or they go away from that point, then they experience an altactive force.\n\t\\item when one current out of the two, approaches a point and another one goes away from that point, then they experience a force of repulsion.\n\t\\item If $q_{1}$ and $q_{2}$ are of the same nature and they move in the same direction, then the force acting between them is attractive.\n\t\\item If $q_{1}$ and $q_{2}$ are of the same nature and they move in the opposite directions then the force acting between them is repulsive.\n\\end{enumerate}\n\\begin{exercise}\n\tA square loop is placed near a infinte stright wire as shown in figure.The loop and wire carry a steady current $I_2$ and $I_1$ respectively.Then the net force acting on the square loop?\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{probs-crop}\n\t\\end{figure}\n\\end{exercise}\n\\begin{answer}\nThe force on two sides cancels.\\\\\nAt the bottom,$B=\\frac{\\mu_{0} I}{2\\pi 3a} \\implies F=\\left[ \\frac{\\mu_{0} I_1}{6\\pi a}\\right] \tI_2a=\\frac{\\mu_{0} I_1I_2}{6\\pi}$ \\textbf{Down}\\\\\nAt the top, $B=\\frac{\\mu_{0}I_1}{2\\pi(3a+a)}\\implies F=\\frac{\\mu_{0}I_1I_2a}{8\\pi a}\\implies F=\\frac{\\mu_{0}I_1I_2}{8\\pi}$ \\textbf{up}\\\\\nThus net force=$\\left( \\frac{\\mu_{0}I_1I_2}{6\\pi}-\\frac{\\mu_{0}I_1I_2}{8\\pi}\\right) =\\frac{\\mu_{0}I_1I_2}{24\\pi}$\\textbf{down}\n\\end{answer}\n\\section{Ampere's law}\n \\begin{wrapfigure}{r}{0.35\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.25\\textwidth]{diagram-20210421(1)-crop}\n\t\\end{center}\n\t\\caption{Amperes circuital law}\n\\end{wrapfigure}\nAmpere's circuital law relates the net magnetic field along a closed loop to the electric current passing through the loop.\nConsider the magnetic field produced by a infinite straight conductor having current coming out of the page. From that we can say that the curl of $B$ is not zero, but equal to $\\mu_0J$\n\n\\begin{align*}\n\\therefore \\nabla\\times B&=\\mu_0 \\ J\n\\intertext{Which is called Ampere's law . It can be converted in to integral form by applying stoke's theorem.}\n\\int (\\nabla\\times B) \\cdot d \\tau&=\\mu_0\\int Jd\\tau\\\\\n\\therefore \\oint B \\cdot dl&=\\mu_0 I\n\\end{align*}\n\\begin{note}\n\t\\textbf{1.} When the loop doesn't encloses the carrent carrying wire $d\\phi=0$. Then Ampere's law can't be applied.\\\\\n\\begin{minipage}{0.25\\textwidth}\n\t\n\\end{minipage}\\hspace{10cm}\t\\begin{minipage}{0.25\\textwidth}\n\t\t\\includegraphics[height=4cm, width=4cm]{diagram-20210421(3)-crop}\n\t\\end{minipage}\\\\\\\\\n\\textbf{2.} Suppose if we have a loop containing a no of current carrying wires then.\\\\\\\\\n\t\\begin{minipage}{0.25\\textwidth}\n\\begin{align*}\n\\oint B\\cdot dl=\\mu_0 I\\quad\\text{enclosed}\\\\\nI_{enc}=I_1+I_2+I_3+I_4\n\\end{align*}\n\t\\end{minipage}\\hspace{2cm}\n\\hspace{4cm}\t\\begin{minipage}{0.25\\textwidth}\n\t\t\\includegraphics[height=3.5cm, width=4cm]{diagram-20210421(4)-crop}\n\t\\end{minipage}\\\\\n\\textbf{3.} From Ampere's law and Biot Savart law we will obtain the divergence of $B$ is equal to zero.\n$$\\text{i.e.}\\ \\nabla \\cdot B=0$$\\\\\ni.e. if the magnetic field has started some where it will end some where.\\\\\\\\\n\\textbf{4.} Ampere's law is always true,But can mostly applied only to infinite current carying materials like \nInfinite straight lines,  Infinite planes, Infinite solenoids  ,Toroids\n\\end{note}\n\\subsection{Applications}\n\\subsubsection{Magnetic field of a long straight wire. }\nTo find the field at $P$ at a distance $r$ from the wire, consider an Amperial loop around the conductor having radius equal to $r$.\\\\\n\\begin{minipage}{0.65\\textwidth}\n\\begin{align*}\\\\\n\\intertext{From Ampere's law }\n\\oint B\\cdot dl&=\\mu_0 I\\\\\n\\text{Since}\\ B \\ \\text{and} \\ dl \\text{are parallel} , &B\\text{can be pulled out of the integral so.}\\\\\nB\\oint dl&=\\mu_0 I \\hspace{2cm}  \\oint dl=2\\pi r\\\\\nB&=\\frac{\\mu_0 I}{2\\pi r}\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4cm]{diagram-20210422(1)-crop}\n\t\t\\caption{Long straight wire carrying current I}\n\t\t\\label{Long straight wire}\n\t\\end{figure}\n\\end{minipage}\n\n\nWhich is the same result that we got by using Biot-Savart law. But in this case Ampere's law is simpler.\\\\\n\\subsubsection{Magnetic field of a long Infinite sheet of current. }\n\\begin{wrapfigure}{r}{0.30\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[height=4cm,width=6cm]{diagram-20210422(2)-crop}\n\t\\end{center}\n\t\\caption{Long Infinite sheet of current}\n\\end{wrapfigure}\nLet us find the magnetic field of an infinite uniform surface current $k=k\\hat{x}$ flowing over the $xy$ plane\\\\\nBy Biot-Savart law magnetic surface due to a surface current density $k$ is given by.\n\t\\begin{align*}\n\tB&=\\frac{\\mu_0 I}{4\\pi}\\int\\frac{k\\times \\hat{r}}{r^2}da\\\\\n\tk&=k\\hat{x} \n\t\\end{align*}\nWhen we consider the magnetic field at distance $r$ above and below the surface,$\\hat{r}$\\ is in $\\hat{z}$ direction and $k$ along $\\hat{x}$ direction and from Biot-Savart law $B$ is $\\perp^r$ to both $\\hat{x}$ and $\\hat{z}$ direction. So it should be in $y$ direction.\\\\\nNow consider a rectangular Amperian loop of length $l$ above and below the surface and parallel to $yz$ plane. Applying Ampere's law we find,\n\\begin{align*}\n\\oint B \\cdot dl&=2Bl=\\mu_0 I_{enc} \\qquad\\begin{array}{l}\n\\oint dl=2l \\\\\nI{_{enc}=kl}\n\\end{array}\\\\\n2Bl&=\\mu_0kl\\\\\nB&=\\frac{\\mu_0k}{2}\n\\end{align*}\nBy using right hand thumb rule, magnetic field above the surface is towards left ie$-y$ direction and $B$ below the surface is towards right ie $+y$ direction.\\\\\\\\\n$f(x)= \n\\begin{cases}\n\\frac{+\\mu_0 k}{2}\\hat{y}& \\text{for }\\ z<0\\\\\\\\\n \\frac{-\\mu_0 k}{2}\\hat{y} & \\text{for}\\ z>0\n\\end{cases}$\n\\begin{note}\\\\\n\t$B$ is independent of distance from the plane.\n\\end{note}\n\\subsubsection{Magnetic field of a long  solenoid. }\nA solenoid is essentially a long current loop with closely packed circular turns. The length of the solenoid  is very large compared to  the diameter of the turns. \nLet us find the magnetic field of a very long solenoid, consisting of $n$ closely wound turns per unit length on a cylinder of radius $R$ and carrying a steady current $I$.\n\n\\begin{minipage}{.45\\textwidth}\n\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\\includegraphics[width=0.4\\textwidth]{diagram-20210422(3)-crop}\n\t\\end{center}\n\\label{key}\n\\caption{Long solenoid}\n\t\\end{figure}\n\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.4\\textwidth]{diagram-20210422(4)-crop}\n\t\t\\end{center}\n\t\\label{key}\n\t\\caption{Amperian loop}\n\t\\end{figure}\n\\end{minipage}\n\\\\\\\\Suppose the magnetic field \\ $B$ is positive, then if we change the directions of current $B$ should be negative. Changing the direction of current is equivalent to turning the solenoid upside down. Then radial component won't change.\\\\\nThere will be no circumferential component for \\ $B(\\phi)$ \\ also. Because when we consider an amperial loop around the solenoid, it has magnetic field parallel to the axis. It should be pointed upward inside the solenoid and downward outside. But now we can prove that $B$ outside the solenoid is also zero.\\\\\n(We already know $B_\\phi$ (circumferential component) is zero). For that now conside the loop $1$ of length $L$.\\\\\nApplying Ampere's law to loop$1$\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\n\t\\oint B\\cdot dl&=B_a L-B_b L\\\\\n\t&=\\mu_0 I_{enc} \\hspace{2cm}I_{enc}=0\\\\\n\t&=0\\\\\n\t\\therefore B_a&=B_b\\\\\n\t\\therefore B\\ &\\text{is constant outside}\n\t\\end{align*} \n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=4.5cm]{diagram-20210422(5)-crop}\n\t\t\\caption{Amperian loop}\n\t\t\\label{rc current discharge}\n\t\\end{figure}\t\n\\end{minipage}\\\\\n\\begin{align*}\n\\intertext{But a large distance from solenoid $B$ must be zero. So it should be zero everywhere.}\n\\intertext{\tFor loop $2$ half inside and half outside.}\n\\oint {B} \\cdot d {l}&=B L=\\mu_{0} I_{\\mathrm{enc}}\\\\&=\\mu_{0} n I L\\\\\nB&= \\begin{cases}\n\\mu_0 I \\hat{z}& \\text{inside}\\\\\n0    & \\text{outside}\n\\end{cases}\n\\end{align*}\n\\subsubsection{Magnetic field of Torroid. }\nA torroid is a circular ring around which a long wire is wrapped. Suppose there are $N$ closely spaced wires find the magnetic field around the toroid at a distance $r$ from the center if $I$ is the current flowing through the torroid.\n\\begin{figure}[H]\n\\begin{minipage}{0.45\\textwidth}\n\t\\includegraphics[height=2cm,width=5cm]{diagram-20210422(11)-crop}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\t\t\\includegraphics[height=4cm,width=5.5cm]{diagram-20210422(12)-crop}\n\\end{minipage}\n\\caption{Torroid}\n\\end{figure}\n\\begin{align*}\n\\intertext{Since the field is circumferential, determining its magnitude is ridiculously easy. Just apply Ampère's law to a circle of radius $s$ about the axis of the torroid:}\nB 2 \\pi s&=\\mu_{0} I_{\\text {enc }}\\\\\n\\text{And hence,}\\ {B}(\\mathbf{r})&=\\left\\{\\begin{array}{cl}\n\\frac{\\mu_{0} N I}{2 \\pi s} \\hat{\\boldsymbol{\\phi}}, & \\text {For points inside the coil. } \\\\\n0, & \\text { For points outside the coil, }\n\\end{array}\\right.\n\\intertext{Where $N$ is the total number of turns.}\n\\end{align*}\n\\begin{exercise}\n\t A steady current $I$ flows down a long cylindrical wire of radius $a$ (Fig. 5.40). Find the magnetic field, both inside and outside the wire, if,\n\t\\\\(a) The current is uniformly distributed over the outside surface of the wire.\n\t\\\\(b) The current is distributed in such a way that $J$ is proportional to $s$, the distance from the axis.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\textbf{a)}\\hspace{1cm}\\quad\\oint B \\cdot d l&=B \\times 2 \\pi s=\\mu_{0} I_{\\text {encl }}\\\\\n\tB&=\\left\\{\\begin{array}{ll}0 & \\text { for } s<a \\\\ \\frac{\\mu _0 I}{2 \\pi s} \\phi & \\text { for } s>a\\end{array}\\right.\\\\\n\t\\textbf{b)}\\hspace{2cm}\\quad J&=k s\\\\\n\tI_{\\text {Total }}&=\\int_{0}^{a} J d a=\\int_{0}^{a} k s 2 \\pi s d s=\\frac{2 \\pi k a^{3}}{3}\\\\\n\tk&=\\frac{3 I}{2 \\pi a^{3}}\\\\\n\tI_{\\text {encl }}&=\\int_{0}^{S} k s(2 \\pi s) d s\\\\\n\t&=\\frac{2 \\pi k s^{3}}{3}\\\\\n\t\\text{Substituting value of $k$.}\\\\\n\tI_{\\text{encl}} &=\\frac{I s^{3}}{a^{3}}\\hspace{1.4cm}\\text{ for } s<a\\\\\n\tI_{\\text {encl }}&=I \\hspace{1.8cm}\\text{ for } s>a\\\\\n\t\\therefore \\quad B&=\\left\\{\\begin{array}{l}\\frac{\\mu_{0} I s^{2}}{2 \\pi a^{3}} \\hat{\\phi}\\ \\quad \\text { for } s<a \\\\\\\\ \\frac{\\mu_{0} I}{2\\pi s} \\hat{\\phi}\\qquad \\text { for } s>a\\end{array}\\right.\n\t\\end{align*}\n\\end{answer}\n\\section{Magnetic Vector Potential}\nIn electrostatics, we had seen  a scalar function $\\phi$ called the \"potential\"\nwhose negative gradient is equal to the electric field : \n\\begin{equation*}\n\\vec{E}=-\\nabla \\phi\n\\end{equation*}\n The existence of such a scalar function is a consequence of the conservative nature of the electric force. It also followed that the electric field is irrotational, i.e.\n \\begin{equation*}\n\\nabla \\times \\vec{E}=0\n \\end{equation*}\nFor a magnetic field, Ampere's law gives a non-zero curl,\n\\begin{equation*}\n\\nabla\\times \\vec{B}=\\mu_{0} \\vec{J}\n\\end{equation*}\n\nSince the curl of a gradient is always zero, we cannot express $\\vec{B}$ as a gradient of a scalar function as it would then violate Ampere's law. However, we may introduce a vector function $\\vec{A}(\\vec{r})$ such that,\n\n$$\n\\vec{B}=\\nabla \\times \\vec{A}\n$$\nThis would automatically satisfy $\\nabla \\cdot \\vec{B}=0$ since divergence of a curl is zero.\\ $ \\vec{A} $\\ is known as the vector potential.\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\\vec{B}=\\nabla \\times \\vec{A}\n\t\t\t$} }\n\\end{center}\n\\subsection{Biot-Savart's law for Vector potential.}\nBiot-Savart's law for magnetic field due to a current element $\\vec{d l}$\\ is obtained as,\n\\begin{align*}\nd \\vec{B}&=\\frac{\\mu_{0} I}{4 \\pi} \\frac{\\vec{d} l \\times \\hat{r}}{r^{2}}=-\\frac{\\mu_{0} I}{4 \\pi} \\vec{d} l \\times \\nabla\\left(\\frac{1}{r}\\right)\n\\intertext{It can  be used to obtain an expression for the vector potential. Since the element $\\overrightarrow{d l}$ does not depend on the position vector of the point at which the magnetic field is calculated, we can write}\nd \\vec{B}&=\\frac{\\mu_{0} I}{4 \\pi} \\nabla \\times\\left(\\frac{\\vec{d l}}{r}\\right)\n\\intertext{The change in sign is because}\n\\nabla\\left(\\frac{d l}{r}\\right)&=\\nabla(1 / r) \\times \\vec{d l}\n\\intertext{Thus the contribution to the vector potential from the element $\\overrightarrow{d l}$ is, }\n d \\vec{A}&=\\frac{\\mu_{0} I}{4 \\pi r} \\overrightarrow{d l}\n \\intertext{The expression is to be integrated over the path of the current to get the vector potential for the system}\n \\vec{A}&=\\frac{\\mu_{0} I}{4 \\pi} \\int \\frac{\\vec{d} l}{r}\n\\end{align*}\n\\begin{center}\n\t\\framebox{\n\t\t\n\t\t\\parbox[t][1.0cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t$\\vec{A}=\\frac{\\mu_{0} I}{4 \\pi} \\int \\frac{\\vec{d} l}{r}$} \n\t}\n\\end{center}\n\\begin{exercise}\n\tA current distribution gives rise to the magnetic vector potential\n\t$$\n\t\\vec{A}(x, y, z)=x^{2} y \\hat{i}+y^{2} x \\hat{j}-x y z \\hat{k} \n\t$$\n\tFind the corresponding magnetic field $\\vec{B}$ at $(-1,2,5)$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\vec{B}(x, y, z)&=\\vec{\\nabla} \\times \\vec{A}\\\\&=\\left|\\begin{array}{ccc}\n\t\\hat{i} & \\hat{j} & \\hat{k} \\\\\n\t\\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\\n\tx^{2} y & y^{2} x & -x y z\n\t\\end{array}\\right|\\\\&=-x z \\hat{i}+y z \\hat{j}+\\left(y^{2}-x^{2}\\right) \\hat{k}\\\\\n\t\\vec{B}(-1,2,5)&=5 \\hat{i}+10 \\hat{j}+3 \\hat{k} T\n\t\\end{align*}\n\\end{answer}\n\\subsubsection{Vector potential due to a straight current carying wire.}\nLet us consider a long straight wire $A B$ carrying a steady current $I$. We need to calculate the magnetic vector potential $\\vec{\\mathrm{A}}$ at any point $P .$ We choose cylindrical coordinates $(r, \\theta, z)$ with z-axis along the wire and the foot $O$ of the perpendicular from $P$ on the wire as the origin. Let us consider an element $d \\vec{l}=\\hat{z} d z$ at a distance $z$ from $O$. Now by definition\\\\\n\\begin{minipage}{0.65\\textwidth}\n\\begin{align*}\n\\vec{A}&=\\frac{\\mu_{0}}{4 \\pi} \\int \\frac{I d \\vec{l}}{R}=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi} \\int_{-l_{1}}^{+l_{2}} \\frac{d z}{\\sqrt{r^{2}+z^{2}}}\\\\&=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi}\\left[\\ln \\left(z+\\sqrt{r^{2}+z^{2}}\\right)\\right]_{-l_{1}}^{+l_{2}}\\\\\n&=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi} l n\\left[\\frac{l_{2}+\\sqrt{r^{2}+l_{2}^{2}}}{-l_{1}+\\sqrt{r^{2}+l_{1}^{2}}}\\right]\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=6cm]{vector potential}\n\t\t\\caption{Straight current carying wire.}\n\t\t\\label{Straight current carying wire.}\n\t\\end{figure}\n\\end{minipage}\n\\begin{align*}\n\\intertext{If the wire is of length $2 \\mathrm{~L}$ and the point $\\mathrm{P}$ is just above the centre of the wire then $l_{1}=l_{2}=L$ and we can write,}\n\\vec{A}&=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi} \\ln \\left[\\frac{L+\\sqrt{r^{2}+L^{2}}}{-L+\\sqrt{r^{2}+L^{2}}}\\right]\n\\intertext{Now if $r / L<<1$ then we can approximate,}\n\\vec{A}&=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi} \\ln \\left[\\frac{1+\\left(1+r^{2} / L^{2}\\right)^{1 / 2}}{-1+\\left(1+r^{2} / L^{2}\\right)^{1 / 2}}\\right]\\\\\n&\\approx \\hat{z} \\frac{\\mu_{0} I}{4 \\pi} \\ln \\left[\\frac{2+\\frac{r^{2}}{2 L^{2}}}{\\frac{r^2}{2L^2}}\\right]\\\\\n&=\\hat{z} \\frac{\\mu_{0} I}{4 \\pi} \\ln \\left(\\frac{4 L^{2}}{r^{2}}+1\\right) \\approx \\hat{z} \\frac{\\mu_{0} I}{2 \\pi} \\ln \\left(\\frac{2 L}{r}\\right)\n\\end{align*}\n\n\\subsubsection{Vector potential due to a long solenoid}\nConsider an infinite solenoid with $n$ turns per unit length, radius $a$ and carrying current $I .$ Symmetry of the problem suggests that $\\vec{A}$ should have the direction of the current, i.e. the circumferential direction $(\\hat{\\theta})$. The magnetic field inside is along the axis (z-axis) of the solenoid and is given by,\n\\begin{align*}\n\\vec{B}&=\\mu_{0} n I \\hat{z}\n\\intertext{Now, considering a circular Amperian loop of radius $r(r<a)$ inside the solenoid in $\\mathrm{xy}$ -plane we can\n\twrite.}\n\\oint_{C} \\vec{A} \\cdot d \\vec{l}&=\\int_{S} \\vec{\\nabla} \\times \\vec{A} \\cdot d \\vec{S}=\\int_{S} \\vec{B} \\cdot d \\vec{S} \\\\\nA \\cdot 2 \\pi r&=\\mu_{0} n I \\cdot \\pi r^{2} \\\\\n\\vec{A}&=\\frac{\\mu_{0} n I}{2} r \\hat{\\theta}, \\text { for } r<a\n\\intertext{For a circular Amperian loop of radius $r(r>a)$ outside the solenoid,}\n\\int_{S} \\vec{B} \\cdot d \\vec{S}&=\\mu_{0} n I \\cdot \\pi a^{2}\n\\intertext{Since the field extends only up to $r=a$. Thus,}\nA \\cdot 2 \\pi r&=\\mu_{0} n I \\cdot \\pi a^{2} \\\\\\text { or }\\quad \\vec{A}&=\\frac{\\mu_{0} n I a^{2}}{2 r} \\hat{\\theta} \\text { for } r>a\n\\end{align*}\n\\section{Multipole expansion of a vector potential}\nMultipole expansion is a technique used to find the potential of localized charge distribution in the form of power series in $\\frac{1}{r}$ where r is the distace to the point in question; if r is sufficiently large the series will be dominated by the lowest nonvanishing contributions and the higher term can be ignored.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{diagram-20211216(1)-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\n$$\\frac{1}{r}=\\frac{1}{\\sqrt{r^{2}+\\left(r^{\\prime}\\right)^{2}-2 r r^{\\prime} \\cos \\theta^{\\prime}}}=\\frac{1}{r} \\sum_{n=0}^{\\infty}\\left(\\frac{r^{\\prime}}{r}\\right)^{n} P_{n}\\left(\\cos \\theta^{\\prime}\\right)$$\n Accordingly, the vector potential of a current loop can be written\n $$\n \\mathbf{A}(\\mathbf{r})=\\frac{\\mu_{0} I}{4 \\pi} \\oint \\frac{1}{r} d \\mathbf{l}^{\\prime}=\\frac{\\mu_{0} I}{4 \\pi} \\sum_{n=0}^{\\infty} \\frac{1}{r^{n+1}} \\oint\\left(r^{\\prime}\\right)^{n} P_{n}\\left(\\cos \\theta^{\\prime}\\right) d \\mathbf{l}^{\\prime},\n $$\n or, more explicitly:\n $$\n \\begin{aligned}\n \\mathbf{A}(\\mathbf{r})=& \\frac{\\mu_{0} I}{4 \\pi}\\left[\\frac{1}{r} \\oint d \\mathbf{l}^{\\prime}+\\frac{1}{r^{2}} \\oint r^{\\prime} \\cos \\theta^{\\prime} d \\mathbf{l}^{\\prime}\\right.\\\\\n &\\left.+\\frac{1}{r^{3}} \\oint\\left(r^{\\prime}\\right)^{2}\\left(\\frac{3}{2} \\cos ^{2} \\theta^{\\prime}-\\frac{1}{2}\\right) \\dot{d}^{\\prime}+\\cdots\\right]\n \\end{aligned}\n $$\n First term represents is called monopole term which doesnt exists.$\\left( \\oint dl=0\\right) $\\\\\n Second term represents dipole and third term represents quadrapole term.\\\\\n The main contribution from dipole term can be written as \n$$\\mathbf{A}_{\\mathrm{dip}}(\\mathbf{r})=\\frac{\\mu_{0} I}{4 \\pi r^{2}} \\oint r^{\\prime} \\cos \\theta^{\\prime} d \\mathbf{l}^{\\prime}=\\frac{\\mu_{0} I}{4 \\pi r^{2}} \\oint\\left(\\hat{\\mathbf{r}} \\cdot \\mathbf{r}^{\\prime}\\right) d \\mathbf{l}^{\\prime}$$ \nThe integral can be written as \\\\\n$$\\oint\\left(\\hat{\\mathbf{r}} \\cdot \\mathbf{r}^{\\prime}\\right) d \\mathbf{l}^{\\prime}=-\\hat{\\mathbf{r}} \\times \\int d \\mathbf{a}^{\\prime}$$\nThen \\\\\n$$\\mathbf{A}_{\\mathrm{dip}}(\\mathbf{r})=\\frac{\\mu_{0}}{4 \\pi} \\frac{\\mathbf{m} \\times \\hat{\\mathbf{r}}}{r^{2}}$$\nwhere $\\mathbf{m}$ is the magnetic dipole moment:\n$$\n\\mathbf{m} \\equiv I \\int d \\mathbf{a}=I \\mathbf{a} .\n$$\n\\section{Magnetic Dipole}\nIn electrostatics, when two opposite charge placed a small distance apart, it called an electric dipole. Similarly, when a wire carrying a current forms a small closed loop, then it is called magnetic dipole.\\\\\nThe magnetic field due to a magnetic dipole is given bellow.Where $B_r$ is the magnetic field at the axial point and $B_{\\theta}$ be the magnetic field at point which makes an angle $\\theta$ with the axis.\n$$\\mathbf{B}=\\left\\{\\begin{array}{l}\n\tB_{r}=2|\\boldsymbol{m}| \\frac{\\mu_{0}}{4 \\pi} \\frac{\\cos \\theta}{R^{3}} \\\\\\\\\n\tB_{\\theta}=|\\boldsymbol{m}| \\frac{\\mu_{0}}{4 \\pi} \\frac{\\sin \\theta}{R^{3}}\n\\end{array}\\right.\\hspace{2cm}\\text { Where } \\boldsymbol{m}=i \\mathbf{A} \\text { is the magnetic dipole moment of the loop }$$\nHere $i$ is the current in the loop, $A$ is the loop area, $R$ is the radial distance from the center of the loop. The field is equivalent to that from a tiny bar magnet (a magnetic dipole).\\\\\nWe define \\textbf{the magnetic dipole moment to be a vector pointing out of the plane of the current loop and with a magnitude equal to the product of the current and loop area:}\nThe area vector, and thus the direction of the magnetic dipole moment, is given by a right-hand rule using the direction of the currents.\n\\begin{center}\n\t\\framebox{\n\t\t\n\t\t\\parbox[t][1.0cm]{4cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\tMagnetic dipole moment\\\\\n\t\t\t$m=i A$} \n\t}\n\\end{center}\n\\begin{note}\n\tThe magnetic field of a dipole can be written in coordinate free form\\\\\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][1.5cm]{3.5cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\begin{array}{lll}\n\t\t\t\tB_{dipole}(r)=\\frac{\\mu_{0}}{4 \\pi }\\frac{1}{r^3}\\left[ 3(m\\cdot\\hat{r})\\hat{r}-m\\right]   \n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\\end{note}\n\\subsection{Interaction of Magnetic Dipoles in External Fields }\n\\subsubsection{Torque}\n\\begin{minipage}{0.65\\textwidth}\n\tBy the $\\mathbf{F}=i\\ l \\times \\mathbf{B}_{\\text {ext }}$ force law, we know that a current loop (and thus a magnetic dipole) feels a torque when placed in an external magnetic field:\n\t$$\n\t\\boldsymbol{\\tau}=\\boldsymbol{m} \\times \\mathbf{B}_{\\text {ext }}\n\t$$\n\tThe direction of the torque is to line up the dipole moment with the magnetic field.\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{magnetic dipole1}\n\t\t\\caption{Torque on magnetic dipole}\n\t\t\\label{magnetic dipole1}\n\t\\end{figure}\n\\end{minipage}\n\\subsubsection{Potential Energy}\nThe above equation is analogous to $\\vec{\\tau}=\\overrightarrow{\\mathbf{p}} \\times \\overrightarrow{\\mathbf{E}}$ , the torque exerted on an electric dipole moment $\\overrightarrow{\\mathbf{p}}$ in the presence of an electric field $\\overrightarrow{\\mathbf{E}}$. Recalling that the potential energy for an electric dipole is $U=-\\overrightarrow{\\mathbf{p}} \\cdot \\overrightarrow{\\mathbf{E}}$, a similar form is expected for the magnetic case. The work done by an external agent to rotate the magnetic dipole from an angle $\\theta_{0}$ to $\\theta$ is given by\nLet us calculate the work done by the magnetic field when aligning the dipole. Let $\\theta$ be the angle between the magnetic dipole direction and the external field direction.\\\\\n\\begin{align*}\n\tW_{\\mathrm{ext}} &=\\int_{\\theta_{0}}^{\\theta} \\tau d \\theta^{\\prime}=\\int_{\\theta_{0}}^{\\theta}\\left(\\mu B \\sin \\theta^{\\prime}\\right) d \\theta^{\\prime}=\\mu B\\left(\\cos \\theta_{0}-\\cos \\theta\\right) \\\\\n\t&=\\Delta U=U-U_{0}\n\\end{align*}\nOnce again, $W_{\\text {ext }}=-W$, where $W$ is the work done by the magnetic field. Choosing $U_{0}=0$ at $\\theta_{0}=\\pi / 2$, the dipole in the presence of an external field then has a potential energy of\n$$\nU=-\\mu B \\cos \\theta=-\\overrightarrow{\\boldsymbol{\\mu}} \\cdot \\overrightarrow{\\mathbf{B}}\n$$\nThe configuration is at a stable equilibrium when $\\overrightarrow{\\boldsymbol{\\mu}}$ is aligned parallel to $\\overrightarrow{\\mathbf{B}}$, making $U$ a minimum with $U_{\\min }=-\\mu B$. On the other hand, when $\\overrightarrow{\\boldsymbol{\\mu}}$ and $\\overrightarrow{\\mathbf{B}}$ are anti-parallel, $U_{\\max }=+\\mu \\mathrm{B}$ is a maximum and the system is unstable.\n\\begin{center}\n\t\\framebox{\n\t\t\n\t\t\\parbox[t][3.0cm]{10cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering \n\t\t\t\\begin{alignat*}{2}\n\t\t\t\t&\\text{Magnetic Moment of Current Carrying Wire:}  &&\\overrightarrow{\\boldsymbol{\\mu}}=I \\overrightarrow{\\mathbf{A}} \\\\&\\text{Torque on Magnetic Moment:}\n\t\t\t&&\\overrightarrow{\\mathbf{\\tau}}=\\overrightarrow{\\boldsymbol{\\mu}} \\times \\overrightarrow{\\mathbf{B}}\n\t\t\t\\\\&\\text{Energy of Moment in External Field:}\n\t\t\t&&U=-\\overrightarrow{\\boldsymbol{\\mu}} \\cdot \\overrightarrow{\\mathbf{B}}\n\t\t\t\\end{alignat*}\n\t\t \n\t}}\n\\end{center}\n\\subsection{The interaction energy of two magnetic dipoles}\nThe interaction energy of two magnetic dipoles seperated by a displacement r is given by\\\\\n\\begin{center}\n\t\\framebox{\n\t\t\\parbox[t][1.3cm]{3.5cm}{\n\t\t\t\n\t\t\t\\addvspace{0.2cm} \\centering\n\t\t\t\n\t\t\t\\begin{align*}\n\t\t\t\\begin{array}{lll}\n\t\t\tU=\\frac{\\mu_{0}}{4\\pi}\\frac{1}{r^3}\\left[ m_1 \\cdot m_2-3(m\\cdot \\hat{r})(m_2 \\cdot \\hat{r})\\right]  \n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center} \n\\subsection{Torque On Current Loop}\n\t\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.35\\textwidth]{torque}\n\t\\end{center}\n\\end{figure}\nLet us now consider the case when the magnetic field $B$ is in the plane with the rectangular loop. No force is exerted by the field on the arms of the loop that is parallel to the magnets, but the arms perpendicular to the magnets experience a force given by $F_{1}$\n$$\nF_{1}=I b B\n$$\nThis force is directed into the plane.\nSimilarly, we can write the expression for a force $\\mathrm{F}_{2}$ which is exerted on the arm CD,\n$$\nF_{2}=I b B=F_{1}\n$$\nWe see that the net force on the loop is zero and the torque on the loop is given by,\n$$\n\\begin{gathered}\n\\tau=F_{1} \\frac{a}{2}+F_{2} \\frac{a}{2} \\\\\n\\tau=I b B \\frac{a}{2}+I b B \\frac{a}{2}=I(a b) B=I A B\n\\end{gathered}\n$$\nWhere ab is the area of the rectangle. Here, the torque tends to rotate the loop in the anti-clockwise direction. Let us consider the case when the plane of the loop is not along the magnetic field. Let the angle between the field and the normal to the coil be given by $\\theta$. We can see that the forces on the arms BC and DA will always act opposite to each other and will be equal in magnitude. Since these forces are the equal opposite and collinear at all points, they cancel out each other's effect and this results in zero-force or torque. The forces on the arms $A B$ and $\\mathrm{CD}$ are given by $\\mathrm{F}_{1}$ and $\\mathrm{F}_{2}$. These forces are equal in magnitude and opposite in direction and can be given by,\n$$\nF_{1}=F_{2}=I b B\n$$\nThese forces are not collinear and thus act as a couple exerting a torque on the coil. The magnitude of the torque can be given by,\n$$\n\\begin{gathered}\n\\tau=F_{1} \\frac{a}{2} \\sin \\theta+F_{2} \\frac{a}{2} \\sin \\theta \\\\\n\\tau=I a b B \\sin \\theta \\\\\n\\tau=I A B \\sin \\theta\n\\end{gathered}\n$$\n\\section{Motion of charged particle in Electric and magnetic Field}\n\\subsection{Motion of charged particle in uniform magnetic field}\n\\textbf{(a)}\\quad \\textbf{If the particle enters $\\perp^r$ to the field\\quad(Circular)}\\\\\\\\\nWhen the particle of charge $\\theta$\\ enters $\\perp^r$\\ to the field, if under go circular motion and the centripetal acceleration is provided by magnetic force $qVB$. If it moves in a circular path of radius $R$,\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\n\tQVB&=\\frac{mv^2}{R}\\quad \\Rrightarrow\\quad\\text{ Cyclotron formula.}\\\\\n\tR&=\\frac{mv}{QB},\\quad m \\ \\text{Is the man of the particle}\n\t\\intertext{When $R$ is the cyclotron radius.}\n\t\\text{Momentum}\\ P&=mv=\\frac{m\\times QBR}{m}\\\\\n\t&=QBR\\\\\n\t\\text{Kinetic energy}\\ KE&=\\frac{P^2}{2m}=\\frac{\\theta^2B^2R^2}{2m}\\\\\n\t\\text{Time period }\\ T&=\\frac{2\\pi R}{V}=\\frac{2\\pi m}{\\theta B}\n\t\\end{align*}\n\\end{minipage}\n\t\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4.5cm]{diagram-20210427(4)-crop}\n\t\t\\caption{Circular path of the particle entering perpendicular to the magnetic field}\n\t\t\\label{Cyclotron}\n\t\\end{figure}\t\t\t\t\n\\end{minipage}\n\\textbf{(b)}\\quad \\textbf{The Ratio of Various Quantities}\\\\\n\\begin{enumerate}\n\t\\item $\\frac{r_1}{r_{2}}=\\frac{q_{2}}{q_{1}} \\sqrt{\\frac{m_{1}}{m_{2}}}$, when $E_{K}$ and $B$ are constants.\n\\item $\\frac{r_{1}}{r_{2}}=\\frac{q_{2}}{q_{1}} \\sqrt{\\frac{m_{1} E_{K_{1}}}{m_{2} E_{K_{2}}}}$, when $B$ is constant.\n\\item  $\\frac{p_{1}}{p_{2}}=\\frac{q_{1}}{q_{2}}\\left(\\frac{r_{1}}{r_{2}}\\right)$\n\\item $\\frac{\\omega_{1}}{\\omega_{2}}=\\frac{q_{1} m_{2}}{q_{2} m_{1}}=\\frac{v_{1}}{v_{2}}$\n\\item $\\frac{T_{1}}{T_{2}}=\\frac{q_{2}}{q_{1}} \\times \\frac{m_{1}}{m_{2}}$\\\\\n\\item  $\\frac{E_{K_{l}}}{E_{K_{2}}}=\\frac{q_{1}^{2} r_{1}^{2}}{q_{2}^{2} r_{2}^{2}} \\times \\frac{m_{2}}{m_{1}}$\n\\end{enumerate}\n\\textbf{(c)}\\quad \\textbf{If the particle enters the field with an angle making $\\theta$with it helical motion}\\\\\\\\\nWhen it enters with an angle $\\theta$ with the field $n$ has two component,\\quad $V_\\parallel=V \\cos\\theta$\\quad and \\quad$V_\\perp^r=V\\sin\\theta$\\\\No magnetic force along parallel direction here again\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\\begin{align*}\n\tR&=\\frac{MV_\\perp r}{QB} =\\frac{MV \\sin\\theta}{QB}\\\\\n\tT&=\\frac{2\\pi m}{QB}\\quad \\text{has no change}\n\t\\intertext{Due to parallel component of velocity, particle undergo helical motion. Horizontal distance travelled by the particle during one period of revolution is called Pitch,}\n\tD&=T\\times V cos \\theta\\\\\n\tb&=\\frac{2\\pi m}{QB} V \\cos \\theta \n\t\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=3.5cm]{diagram-20210427(6)-crop}\n\t\t\\caption{Helical path of the particle entering at an angle to the magnetic field}\n\t\t\\label{Helical path of the particle }\n\t\\end{figure}\n\\end{minipage}\n\\subsection{Motion of charged particle in static electric field.}\n\\textbf{(a)}\\quad Charged particle enters in the direction of field (Linear motion)\n\\begin{align*}\n\\intertext{If $q$ charged moves in uniform field then,}\nF&=q E \\hspace{2cm} F=\\frac{md^2r}{dt^2}\\\\\n\\frac{md^2r}{dt^2}&=qE\\\\\n\\frac{dr}{dt}&=\\frac{qEt}{m}+C_0\\\\\n\\text{At} \\quad t=0\\quad V&=V_0,\\quad \\text{and}\\quad r=r_0,\\\\\n\\text{Then}\\quad c_0&=V_0\\\\\n\\frac{d_0}{dt}&=\\frac{qE}{m}t+V_0\\\\\nr&=\\frac{qEt^2}{2m}+V_0t+r_0\n\\end{align*} \n \\begin{minipage}{0.65\\textwidth}\n \t\\begin{align*}\n \t\\intertext{It initial position and velocity are zeros,}\n \t\\text{Then}\\quad V&=\\frac{Q E}{m}t\\\\\n \tr&=\\frac{Q E}{2m}t^2\n \\end{align*} \t\n \t\\end{minipage}\n \\begin{minipage}{0.35\\textwidth}\n \t\\begin{figure}[H]\n \t\t\\includegraphics[height=3cm,width=4cm]{diagram-20210427(11)-crop}\n \t\t\\caption{Linear motion of charged particle in Static electric field.}\n \t\t\\label{Linear motion of charged particle}\n \t\\end{figure}\n \\end{minipage}\n\\begin{align*}\n\\intertext{Energy acquired by the charged particle moving from initial to some final point,}\nw&=\\int f\\cdot dl=m\\int_{V_1}^{V_2}a\\cdot dl\\\\\n&=m\\int_{V_1}^{V_2}\\frac{dV}{dt}\\times Vdt=m\\int_{1}^{2}VdV=\\frac{1}{2}m(V^2_2-V^2_1)\\\\\nw&=\\frac{1}{2}m(V^2_2-V^2_1)\\\\\n\\text{If initial velocity }V_1&=0\\\\\nw&=\\frac{1}{2}mV^2\n\\intertext{If the potential difference between them is $V$ then,}\nw&=QV=\\frac{1}{2}mV^2\\\\\n\\therefore V&=\\sqrt{\\frac{2QV}{m}}\\\\\nK.E&=w=\\frac{1}{2}m\\times\\frac{Q^2 E^2}{m^2}t^2\\\\\n&=QE\\times\\frac{QE}{2m}t^2\\\\\n&=QEr\n\\end{align*}\n\\textbf{(b)}\\quad \\textbf{Charged particle enters in the direction $\\perp^r$ to the electric field (Parabolic motion)}\\\\\n\n \\begin{minipage}{0.55\\textwidth}\nLet us consider a charge particle enters in a electric field region with velocity $V_x$ at\\ $t=0$. The electric field is in $y$ direction and the field region has length $l$. After traversing a distance $l$ it strikes a point $P$ on a screen which is placed at a distance $L$ from the field region. \\\\\nSince electric field is in the $y$ direction , charged particle will experience force.\n\\begin{align*}\nF_y&=QEy\\\\ \n\\intertext{Acceleration}\na_y&=\\frac{QEy}{m}\\\\\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=6cm]{diagram-20210427(5)-crop}\n\t\t\\caption{Parabolic motion of Charged particle entering in   perpendicular direction to the electric field.}\n\t\t\\label{rc current discharge}\n\t\\end{figure}\n\\end{minipage}\\\\\\\\\t\nIn time $t$ , charge particle will traverse a distance $y=\\frac{1}{2}a_yt^2$ in $y$ direction and a distance $x=V_xt$\\  in$x$ direction.\n\\begin{align*}\n\\text{Thus}\\quad y&=\\frac{1}{2}a_yt^2=\\frac{QEy}{2m}(\\frac{x}{V_x})^2 \\quad\\text{represents a parabola}\\\\\ny_1&=\\frac{QEy}{2m}(\\frac{l}{V_x})^2\\text{and}\\quad y_2=L \\tan\\theta\\\\\n\\intertext{Thus distance of point $P$ from the center of the screen is}\ny_1+y_2&=\\frac{QEy}{2m}(\\frac{l}{V_x})^2+L \\tan\\theta\\\\\n\\text{Angle of deviation in the field region}\\\\\n\\tan\\phi&=\\frac{dy}{dx}=\\frac{QEy}{mV_x^2}x\\\\\n\\text{Angle of deviation in the field foce region}\\\\\n\\tan\\theta&=\\frac{QEy}{mV_x^2}l\n\\end{align*}\n\\subsection{Charged particle in uniform electric and magnetic field }\n\\textbf{(a)}\\quad \\textbf{$E$ and $B$ are perpendicular(Cycloid motion).}\\\\\n\\begin{minipage}{0.65\\textwidth}\n\t\tIf $B$ points in $\\hat{x}$ direction $E$ in the $z$ direction. Suppose the particle is at origin initially. So $F_{mg} =0$, due $E$ it moves along $\\hat{z} $ direction, When it starts moving magnetic force develop, it pulls the charge to right, when $V$ increases $F_{mg} $ increases ,it tend to move in a circular path,which results the particle move back towards $Y$ axis at that time it is moving against $\\vec{E}$. Therefore the velocity  $V$ decreases, and $F_{mag} $ also decreases. Then $E$ bring the charge to rest at point $a$. Then  the entire process repeats.\n\\end{minipage}\n\\begin{minipage}{0.35\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210427(8)-crop}\n\t\t\\caption{Cycloid motion of charge}\n\t\t\\label{cycloid }\n\t\\end{figure}\n\\end{minipage}\n\\begin{align*}\n\t\\intertext{We know particle is at rest at origin when time $t=0$ ,Then,} \ny(0)&=z(0)=0\\\\\n\\dot{y}(0)&=\\dot{z}(0)=0\\hspace{1cm}\\text{No motion along $x$ axis}\\\\\nV&=(0,\\dot{y},\\dot{z})\\\\\nV\\times B&=\\left|\\begin{array}{lll}\\hat{x} & \\hat{y}&\\hat{z} \\\\ 0 & \\dot{y}&\\dot{z} \\\\B & 0&0\\end{array}\\right|=B\\dot{z}\\hat{y}-B\\dot{y}\\hat{z}\\\\\n\\text{Total force}\\ F&=Q[E+V\\times B]=Q[E\\hat{z}+B\\dot{z}\\hat{y}-B\\dot{y}\\hat{z}]\\\\\nma&=m[\\dot{y}\\hat{y}+\\dot{z}\\hat{z}]\\\\\nm[\\dot{y}\\hat{y}+\\dot{z}\\hat{z}]&=Q[E\\hat{z}+B\\dot{z}\\hat{y}-B\\dot{y}\\hat{z}]\n\\intertext{Comparing the coefficient $ \\hat{y} $ and $ \\hat{z} $ }\nQB\\dot{z}&=m\\dot{y}\\hspace{2cm}E-QB\\dot{y}=m\\dot{z}\\\\\n\\text{let}\\quad w&=\\frac{QB}{m},\\quad \\text{Cyclotron frequency in absence of $\\vec{E}$}\\\\\n\\text{Then}, \\dot{y}&=w\\dot{z},\\quad \\dot{z}=w\\left( \\frac{E}{B}-\\dot{y}\\right)\\\\ \n\\text{Their Solution,}\\\\\ny(t)&=c_1\\cos wt+c_2\\sin wt+\\left( \\frac{E}{B}\\right) t+c_3\\\\\nz(t)&=c_2\\cos wt-c_1\\sin wt+c_4\n\\intertext{Applying the initial  conditions we will get $ c_1,c_2,c_3.c_4 $}\ny(t)&=\\frac{E}{wB}(wt-\\sin wt)\\\\\nz(t)&=\\frac{E}{wB}(1-\\cos wt)\\\\\n\\text{Now let}\\quad R&=\\frac{E}{wB}\\\\\n\\text{and using }\\sin^2wt+\\cos^2wt&=1\\\\\n\\text{We will get}\\quad (y-Rwt)^2+(z-R)^2&=R^2\n\\end{align*}\nWhich represents the formula of a circle whose center $(0,Rwt,R)$ travels in $y$ direction at speed.\n$$ V=wR=\\frac{E}{B}$$\ncurve generated by this motion is called cycloid.\\\\\\\\\n\\textbf{(b)}\\quad \\textbf{When $E$ and $B$ are parallel}\\\\\\\\\nThe particle will move in helical path of constant radius but varying pitch.\n\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=6cm]{helical}\n\t\t\\caption{Helical path of charged particle in Electric and magnetic field}\n\t\t\\label{Helical path}\n\t\\end{figure}\n\n\t\n\t\n\\begin{exercise}\n\tA neutron, a proton, an electron and an $\\alpha$particle enter a region of constant magnetic field with equal velocities. The magnetic field is inward normal to the plane of paper. Label the tracks of the particle?\\\\\n\t\\begin{minipage}{.45\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.5\\textwidth]{diagram-20210427(9)-crop}\n\t\t\\end{center}\n\t\\end{minipage}\n\\end{exercise}\n\\begin{answer}\n\tSince neutron has no charge it is undeflected by the field. So it is represented by $C$ . So all particle has initial velocity along $C$ and force $( \\theta(V\\times B))$pointed towards left for $+ve$ particles and right for electron. And radius is directly proportional to $m$,so $\\alpha$particle have larger radius. So,\\\\\\\\\n\tA=proton\\quad B)$\\rightarrow$$\\alpha$particle\\quad C)$\\rightarrow$neutron\\quad D)$\\rightarrow$electron.\n\\end{answer}\n\\begin{exercise}\n\tA particle having a charge $a$ and mass $m$ moves along a circle of radius $R$ under the action of magnetic field $B$. When the particle is at a point $P$, a uniform electric field is switched on and it is found that the particle continues on the tangent through $P$ with a uniform velocity. The magnitude of electric field is,?\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\tQ E=\\theta VB\\\\\n\tE=VB\\\\\n\t\\text{Where $V$ is the velocity }\\quad V=\\frac{\\theta BR}{m}\\\\\n\t\\therefore E=\\frac{QB^2R}{m}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tA particle of mass carrying charge q is moving in a circle in a magnetic field.According to Bohr's model, Find?\\\\\n\t(a) The radius of the particle in the nth level.\\\\\n\t(bThe energy of the particle in the nth level\n\\end{exercise}\n\\begin{answer}\n\\begin{align*}\n(a)mv_nr_n=n\\bar{h} \\quad \\quad r_n=\\frac{mv_n}{qB}\\\\\nr_n=\\frac{m}{qB}\\frac{n\\bar{h}}{mv_n}\\\\\nr_n^2=\\frac{n\\bar{h}}{qB}\\\\\nr_n=\\sqrt{\\frac{n\\bar{h}}{qB}}\\\\\n(b) E_n=\\frac{q^2B^2r^2_n}{2m}\\implies \\frac{q^2B^2}{2m}\\times\\frac{n\\bar{h}}{qB}=n\\left( \\frac{qBh}{4\\pi m}\\right)  \n\\end{align*}\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 The magnetic field at a distance $R$ from a long straight wire carrying a steady current $I$ is proportional to\n\t\\exyear{NET 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $I R$\n\t\\task[\\textbf{B.}] $I / R^{2}$\n\t\\task[\\textbf{C.}]$I^{2} / R^{2}$\n\t\\task[\\textbf{D.}]$I / R$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The vector potential $\\vec{A}$ due to a magnetic moment $\\vec{m}$ at a point $\\vec{r}$ is given by $\\vec{A}=\\frac{\\vec{m} \\times \\vec{r}}{r^{3}}$.\n\tIf $\\vec{m}$ is directed along the positive $z$-axis, the $x$ - component of the magnetic field, at the point $\\vec{r}$, is\n\t\\exyear{NET 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{3 m y z}{r^{5}}$\n\t\\task[\\textbf{B.}] $-\\frac{3 m x y}{r^{5}}$\n\t\\task[\\textbf{C.}]$\\frac{3 m x z}{r^{5}}$\n\t\\task[\\textbf{D.}]$\\frac{3 m\\left(z^{2}-x y\\right)}{r^{5}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An infinite solenoid with its axis of symmetry along the $z$-direction carries a steady current $I$.\n\tThe vector potential $\\vec{A}$ at a distance $R$ from the axis\n\t\\exyear{NET 2012}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=3cm]{NET1}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}]is constant inside and varies as $R$ outside the solenoid\n\t\\task[\\textbf{B.}] varies as $R$ inside and is constant outside the solenoid\n\t\\task[\\textbf{C.}]varies as $\\frac{1}{R}$ inside and as $R$ outside the solenoid\n\t\\task[\\textbf{D.}]varies as $R$ inside and as $\\frac{1}{R}$ outside the solenoid\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The force between two long and parallel wires carrying currents $I_{1}$ and $I_{2}$ and separated by a distance $D$ is proportional to\n\t\\exyear{NET 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $I_{1} I_{2} / D$\n\t\\task[\\textbf{B.}]$\\left(I_{1}+I_{2}\\right) / D$\n\t\\task[\\textbf{C.}]$\\left(I_{1} I_{2} / D\\right)^{2}$\n\t\\task[\\textbf{D.}]$I_{1} I_{2} / D^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A time-dependent current $\\vec{I}(t)=K t \\hat{z}$ (where $K$ is a constant) is switched on at $t=0$ in an infinite current-carrying wire. The magnetic vector potential at a perpendicular distance $a$ from the wire is given (for time $t>a / c$ ) by\n\t\\exyear{NET 2014}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\hat{z} \\frac{\\mu_{0} K}{4 \\pi c} \\int_{-\\sqrt{c^{2} t^{2}-a^{2}}}^{\\sqrt{c^{2} t^{2}-a^{2}}} d z \\frac{c t-\\sqrt{a^{2}+z^{2}}}{\\left(a^{2}+z^{2}\\right)^{1 / 2}}$\n\t\\task[\\textbf{B.}] $\\hat{z} \\frac{\\mu_{0} K}{4 \\pi} \\int_{-c t}^{c t} d z \\frac{t}{\\left(a^{2}+z^{2}\\right)^{1 / 2}}$\n\t\\task[\\textbf{C.}] $\\hat{z} \\frac{\\mu_{0} K}{4 \\pi c} \\int_{-c t}^{c t} d z \\frac{c t-\\sqrt{a^{2}+z^{2}}}{\\left(a^{2}+z^{2}\\right)^{1 / 2}}$\n\t\\task[\\textbf{D.}] $\\hat{z} \\frac{\\mu_{0} K}{4 \\pi} \\int_{-\\sqrt{c^{2} t^{2}-a^{2}}}^{\\sqrt{c^{2} t^{2}-a^{2}}} d z \\frac{t}{\\left(a^{2}+z^{2}\\right)^{1 / 2}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A charged particle moves in a helical path under the influence of a constant magnetic field. The initial velocity is such that the component along the magnetic field is twice the component in the plane normal to the magnetic field.\n\tThe ratio $\\ell / R$ of the pitch $\\ell$ to the radius $R$ of the helical path is\n\t\\exyear{NET 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\pi / 2$\n\t\\task[\\textbf{B.}]$4 \\pi$\n\t\\task[\\textbf{C.}]$2 \\pi$\n\t\\task[\\textbf{D.}]$\\pi$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A proton moves with a speed of $300 \\mathrm{~m} / \\mathrm{s}$ in a circular orbit in the $x y$-plan in a magnetic field 1 tesla along the positive $z$-direction. When an electric field of $1 \\mathrm{~V} / \\mathrm{m}$ is applied along the positive $y$-direction, the center of the circular orbit\n\t\\exyear{NET 2014}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] remains stationary\n\t\\task[\\textbf{B.}]moves at $1 \\mathrm{~m} / \\mathrm{s}$ along the negative $x$-direction\n\t\\task[\\textbf{C.}]moves at $1 \\mathrm{~m} / \\mathrm{s}$ along the positive $z$ - direction\n\t\\task[\\textbf{D.}] moves at $1 \\mathrm{~m} / \\mathrm{s}$ along the positive $x$ - direction\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Given a uniform magnetic field $B=B_{0} \\hat{k}$ (where $B_{0}$ is a constant), a possible choice for the magnetic vector potential $A$ is\n\t\\exyear{NET 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $B_{0} y \\hat{i}$\n\t\\task[\\textbf{B.}] $-B_{0} y \\hat{i}$\n\t\\task[\\textbf{C.}] $B_{0}(x \\hat{j}+y \\hat{i})$\n\t\\task[\\textbf{D.}]$B_{0}(x \\hat{i}+y \\hat{j})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A small magnetic needle is kept at $(0,0)$ with its moment along the $x$-axis. Another small magnetic needle is at the point $(1,1)$ and is free to rotate in the $x y$ - plane. In equilibrium the angle $\\theta$ between their magnetic moments is such that\n\t\\exyear{NET 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\tan \\theta=\\frac{1}{3}$\n\t\\task[\\textbf{B.}]$\\tan \\theta=0$\n\t\\task[\\textbf{C.}]$\\tan \\theta=3$\n\t\\task[\\textbf{D.}]$\\tan \\theta=1$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A dipole of moment $\\vec{p}$, oscillating at frequency $\\omega$, radiates spherical waves. The vector potential at large distance is\\\\\n\t$$\\vec{A}(\\vec{r})=\\frac{\\mu_{0}}{4 \\pi} i \\omega \\frac{e^{i k r}}{r} \\vec{p}$$\t\n\t$\\text { To order }\\left(\\frac{1}{r}\\right) \\text { the magnetic field } \\vec{B} \\text { at a point } \\vec{r}=r \\hat{n} \\text { is }$\n\t\\exyear{NET 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{\\mu_{0}}{4 \\pi} \\frac{\\omega^{2}}{C}(\\hat{n} \\cdot \\vec{p}) \\hat{n} \\frac{e^{i k r}}{r}$\n\t\\task[\\textbf{B.}]$-\\frac{\\mu_{0}}{4 \\pi} \\frac{\\omega^{2}}{C}(\\hat{n} \\times \\vec{p}) \\frac{e^{i k r}}{r}$\n\t\\task[\\textbf{C.}]$-\\frac{\\mu_{0}}{4 \\pi} \\omega^{2} k(\\hat{n} \\cdot \\vec{p}) \\vec{p} \\frac{e^{i k r}}{r}$\n\t\\task[\\textbf{D.}]$-\\frac{\\pi_{0}}{4 \\pi} \\frac{\\omega^{2}}{C} \\vec{p} \\frac{e^{i k r}}{r}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A loop of radius $a$, carrying a current $I$, is placed in a uniform magnetic field $B$. If the normal to the loop is denoted by $\\hat{n}$, the force $\\vec{F}$ and the torque $\\vec{T}$ on the loop are\n\t\\exyear{NET 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{F}=0$ and $\\vec{T}=\\pi a^{2} I \\hat{\\mathrm{n}} \\times B$\n\t\\task[\\textbf{B.}]$\\vec{F}=\\frac{\\mu_{0}}{4 \\pi} \\vec{I} \\times \\vec{B}$\n\t\\task[\\textbf{C.}]$\\vec{F}=\\frac{\\mu_{0}}{4 \\pi} \\vec{I} \\times \\vec{B}$ and $\\vec{T}=I \\hat{\\mathrm{n}} \\times \\vec{B}$\n\t\\task[\\textbf{D.}]$\\vec{F}=0$ and $\\vec{T}=\\frac{1}{\\mu_{0} \\varepsilon_{0}} I \\vec{B}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A conducting circular disc of radius $r$ and resistivity $\\rho$ rotates with an angular velocity $\\omega$ in a magnetic field $B$ perpendicular to it. A voltmeter is connected as shown in the figure below. Assuming its internal resistance to be infinite, the reading on the voltmeter\n\t\\exyear{NET 2016}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20211011(46)-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] depends on $\\omega, B, r$ and $\\rho$\n\t\\task[\\textbf{B.}]depends on $\\omega, B$ and $r$ but not on $\\rho$\n\t\\task[\\textbf{C.}]is zero because the flux through the loop is not changing\n\t\\task[\\textbf{D.}]is zero because a current the flows in the direction of $B$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A set of $N$ concentric circular loops of wire, each carrying a steady current $I$ in the same direction, is arranged in a plane. The radius of the first loop is $r_{1}=a$ and the radius of the $n^{\\text {th }}$ loop is given by $r_{n}=n r_{n-1}$. The magnitude $B$ of the magnetic field at the centre of the circles in the limit $N \\rightarrow \\infty$, is\n\t\\exyear{NET 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\mu_{0} I\\left(e^{2}-1\\right) / 4 \\pi a$\n\t\\task[\\textbf{B.}]$\\mu_{0} I(e-1) / \\pi a$\n\t\\task[\\textbf{C.}]$\\mu_{0} I\\left(e^{2}-1\\right) / 8 a$\n\t\\task[\\textbf{D.}]$\\mu_{0} I(e-1) / 2 a$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A constant current $I$ is flowing in a piece of wire that is bent into a loop as shown in the figure.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=7cm]{diagram-20211011(54)-crop}\n\t\\end{figure}\n\t$\\text { The magnitude of the magnetic field at the point } O \\text { is }$\n\t\\exyear{NET 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\mu_{0} I}{4 \\pi \\sqrt{5}} \\ln \\left(\\frac{a}{b}\\right)$\n\t\\task[\\textbf{B.}]$\\frac{\\mu_{0} I}{4 \\pi \\sqrt{5}}\\left(\\frac{1}{a}-\\frac{1}{b}\\right)$\n\t\\task[\\textbf{C.}]$\\frac{\\mu_{0} I}{4 \\pi \\sqrt{5}}\\left(\\frac{1}{a}\\right)$\n\t\\task[\\textbf{D.}]$\\frac{\\mu_{0} I}{4 \\pi \\sqrt{5}}\\left(\\frac{1}{b}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A circular current carrying loop of radius $a$ carries a steady current. A constant electric charge is kept at the centre of the loop. The electric and magnetic fields, $\\vec{E}$ and $\\vec{B}$ respectively, at a distance $d$ vertically above the centre of the loop satisfy\n\t\\exyear{NET 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{E} \\perp \\vec{B}$\n\t\\task[\\textbf{B.}] $\\vec{E}=0$\n\t\\task[\\textbf{C.}]$\\vec{\\nabla}(\\vec{E} \\cdot \\vec{B})=0$\n\t\\task[\\textbf{D.}]$\\vec{\\nabla} \\cdot(\\vec{E} \\times \\vec{B})=0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item \\text { The loop shown in the figure below carries a steady current } I \\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20211011(11)-crop}\n\t\\end{figure}\n\t$\\text { The magnitude of the magnetic field at the point } O \\text { is }$\n\t\\exyear{NET 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\mu_{0} I}{2 a}$\n\t\\task[\\textbf{B.}]$\\frac{\\mu_{0} I}{6 a}$\n\t\\task[\\textbf{C.}]$\\frac{\\mu_{0} I}{4 a}$\n\t\\task[\\textbf{D.}]$\\frac{\\mu_{0} I}{3 a}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Two current-carrying circular loops, each of radius $R$, are placed perpendicular to each other, as shown in the figure.\n\t\n\tThe loop in the $x y$ - plane carries a current $I_{0}$ while that in the $x z$-plane carries a current $2 I_{0}$. The resulting magnetic field $\\vec{B}$ at the origin is\n\t\\exyear{NET 2018 dec}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20211011(12)-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\mu_{0} l_{0}}{2 R}[2 \\hat{j}+\\hat{k}]$ \n\t\\task[\\textbf{B.}]$\\frac{\\mu_{0} l_{0}}{2 R}[2 \\hat{j}-\\hat{k}]$\n\t\\task[\\textbf{C.}]$\\frac{\\mu_{0} l_{0}}{2 R}[-2 \\hat{j}+\\hat{k}]$\n\t\\task[\\textbf{D.}]$\\frac{\\mu_{0} l_{0}}{2 R}[-2 \\hat{j}-\\hat{k}]$\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{c}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{a}\\\\\\hline\n\t\t5&\\textbf{a}&6&\\textbf{b}\\\\\\hline\n\t\t7&\\textbf{d}&8&\\textbf{b}\\\\\\hline\n\t\t9&\\textbf{c}&10&\\textbf{b}\\\\\\hline\n\t\t11&\\textbf{a}&12&\\textbf{b}\\\\\\hline\n\t\t13&\\textbf{d}&14&\\textbf{b}\\\\\\hline\n\t\t15&\\textbf{c}&16&\\textbf{b}\\\\\\hline\n\t\t17&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 2\n\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item Two magnetic dipoles of magnitude $m$ each are placed in a plane as shown in figure The energy of interaction is given by\n\t\\exyear{GATE 2010}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210817(13)-crop}\n\t\t\\caption{}\n\t\t\\label{}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] Zero\n\t\\task[\\textbf{B.}]$\\frac{\\mu_{0} m^{2}}{4 \\pi d^{3}}$\n\t\\task[\\textbf{C.}]$\\frac{3 \\mu_{0} m^{2}}{2 \\pi d^{3}}$\n\t\\task[\\textbf{D.}]$-\\frac{3 \\mu_{0} m^{2}}{8 \\pi d^{3}}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If a force $\\vec{F}$ is derivable from a potential function $V(r)$, where $r$ is the distance from the origin of the coordinate system, it follows that\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\vec{\\nabla} \\times \\vec{F}=0$\n\t\\task[\\textbf{B.}]$\\vec{\\nabla} \\cdot \\vec{F}=0$\n\t\\task[\\textbf{C.}]$\\vec{\\nabla} V=0$\n\t\\task[\\textbf{D.}]$\\nabla^{2} V=0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A uniform surface current is flowing in the positive $y$-direction over an infinite sheet lying in $x-y$ plane. The direction of the magnetic field is\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}]along $\\hat{i}$ for $z>0$ and along $-\\hat{i}$ for $z<0$\n\t\\task[\\textbf{B.}]along $\\hat{k}$ for $z>0$ and along $-\\hat{k}$ for $z<0$\n\t\\task[\\textbf{C.}]along $-\\hat{i}$ for $z>0$ and along $\\hat{i}$ for $z<0$\n\t\\task[\\textbf{D.}]along $-\\hat{k}$ for $z>0$ and along $\\hat{k}$ for $z<0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A magnetic dipole of dipole moment $\\vec{m}$ is placed in a non-uniform magnetic field $\\vec{B} .$ If the position vector of the dipole is $\\vec{r}$, the torque acting on the dipole about the origin is\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{r} \\times(\\vec{m} \\times \\vec{B})$\n\t\\task[\\textbf{B.}]$\\vec{r} \\times \\vec{\\nabla}(\\vec{m} \\cdot \\vec{B})$\n\t\\task[\\textbf{C.}]$\\vec{m} \\times \\vec{B}$\n\t\\task[\\textbf{D.}]$\\vec{m} \\times \\vec{B}+\\vec{r} \\times \\nabla(\\vec{m} \\cdot \\vec{B})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Which of the following expressions for a vector potential $\\vec{A} \\underline{\\text { DOES NOT }}$ represent a uniform magnetic field of magnitude $B_{0}$ along the $z$-direction?\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\vec{A}=\\left(0, B_{0} x, 0\\right)$\n\t\\task[\\textbf{B.}]$\\vec{A}=\\left(-B_{0} y, 0,0\\right)$\n\t\\task[\\textbf{C.}]$\\vec{A}=\\left(\\frac{B_{0} x}{2}, \\frac{B_{0} y}{2}, 0\\right)$\n\t\\task[\\textbf{D.}] $\\vec{A}=\\left(-\\frac{B_{0} y}{2}, \\frac{B_{0} x}{2}, 0\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item In a constant magnetic field of $0.6$ Tesla along the $\\mathrm{z}$ direction, find the value of the path integral $\\oint \\vec{A} \\cdot \\overrightarrow{d l}$ in the units of (Tesla $m^{2}$ ) on a square loop of side length $(1 / \\sqrt{2})$ meters. The normal to the loop makes an angle of $60^{\\circ}$ to the z-axis, as shown in the figure.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210817(19)-crop-crop}\n\t\\end{figure}\t\n\tThe answer should be up to two decimal places.\n\t\\exyear{GATE}\t\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The value of the magnetic field required to maintain non-relativistic protons of energy $1 \\mathrm{MeV}$ in a circular orbit of radius $100 \\mathrm{~mm}$ is Tesla\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item Given that the magnetic flux through the closed loop $P Q R S P$ is $\\phi$. If $\\int_{P}^{R} \\vec{A} \\cdot \\vec{d} l=\\phi_{1}$ along $P Q R$, the value of $\\int^{R} \\vec{A} \\cdot \\vec{d} l$ along $P S R$ is\n\t\\exyear{GATE 2015}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210818(2)-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}](a) $\\phi-\\phi_{1}$\n\t\\task[\\textbf{B.}] $\\phi_{1}-\\phi$\n\t\\task[\\textbf{C.}]$-\\phi_{1}$\n\t\\task[\\textbf{D.}] $\\phi_{1}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Which of the following magnetic vector potentials gives rise to a uniform magnetic field $B_{0} \\hat{k} ?$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $B_{0} z \\hat{k}$\n\t\\task[\\textbf{B.}]$-B_{0} x \\hat{j}$\n\t\\task[\\textbf{C.}]$\\frac{B_{0}}{2}(-y \\hat{i}+x \\hat{j})$\n\t\\task[\\textbf{D.}]$\\frac{B_{0}}{2}(y \\hat{i}+x \\hat{j})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The magnitude of the magnetic dipole moment associated with a square shaped loop carrying a steady current $I$ is $m$. If this loop is changed to a circular shape with the same current $I$ passing through it, the magnetic dipole moment becomes $\\frac{p m}{\\pi} .$ The value of $p$ is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item An infinite solenoid carries a time varying current $I(t)=A t^{2}$, with $A \\neq 0 .$ The axis of the solenoid is along the $\\hat{z}$ direction. $\\hat{r}$ and $\\hat{\\theta}$ are the usual radial and polar directions in cylindrical polar coordinates. $\\vec{B}=B_{r} \\hat{r}+B_{\\theta} \\hat{\\theta}+B_{z} \\hat{z}$ is the magnetic field at a point outside the solenoid. Which one of the following statements is true?\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $B_{r}=0, B_{\\theta}=0, B_{z}=0$\n\t\\task[\\textbf{B.}]$B_{r} \\neq 0, B_{\\theta} \\neq 0, B_{z}=0$\n\t\\task[\\textbf{C.}] $B_{r} \\neq 0, B_{\\theta} \\neq 0, B_{z} \\neq 0$\n\t\\task[\\textbf{D.}] $B_{r}=0, B_{\\theta}=0, B_{z} \\neq 0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An infinitely long straight wire is carrying a steady current $I$. The ratio of magnetic energy density at distance $r_{1}$ to that at $r_{2}\\left(=2 r_{1}\\right)$ from the wire is\n\t\\exyear{GATE 2018}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item A constant and uniform magnetic field $\\vec{B}=B_{0} \\hat{k}$ pervades all space. Which one of the following is the correct choice for the vector potential in Coulomb gauge?\n\t\\exyear{GATE 2018}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $-B_{0}(x+y) \\hat{i}$\n\t\\task[\\textbf{B.}]$B_{0}(x+y) \\hat{j}$\n\t\\task[\\textbf{C.}] $B_{0} x \\hat{j}$\n\t\\task[\\textbf{D.}]$-\\frac{1}{2} B_{0}(x \\hat{i}-y \\hat{j})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item  A solid cylinder of radius $R$ has total charge $Q$ distributed uniformly over its volume. It is rotating about its axis with angular speed $\\omega$. The magnitude of the total magnetic moment of the cylinder is\n\t\\exyear{GATE 2019}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}](a) $Q R^{2} \\omega$\n\t\\task[\\textbf{B.}]$\\frac{1}{2} Q R^{2} \\omega$\n\t\\task[\\textbf{C.}]$\\frac{1}{4} Q R^{2} \\omega$\n\t\\task[\\textbf{D.}]$\\frac{1}{8} Q R^{2} \\omega$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item An infinitely long wire parallel to the $x$-axis is kept at $z=d$ and carries a current $I$ in the positive $x$ direction above a superconductor filling the region $z \\leq 0$ (see figure). The magnetic field $\\vec{B}$ inside the superconductor is zero so that the field just outside the superconductor is parallel to its surface. The magnetic field due to this configuration at a point $(x, y, z>0)$ is\n\t\\exyear{GATE 2019}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=5cm]{diagram-20210818(14)-crop-crop}\n\t\t\\caption{}\n\t\t\\label{}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}]$\\left(\\frac{\\mu_{0} I}{2 \\pi}\\right) \\frac{-(z-d) \\hat{j}+y \\hat{k}}{\\left[y^{2}+(z-d)^{2}\\right]}$\n\t\\task[\\textbf{B.}]$\\left(\\frac{\\mu_{0} I}{2 \\pi}\\right)\\left[\\frac{-(z-d) \\hat{j}+y \\hat{k}}{y^{2}+(z-d)^{2}}+\\frac{(z+d) \\hat{j}-y \\hat{k}}{y^{2}+(z+d)^{2}}\\right]$\n\t\\task[\\textbf{C.}]$\\text { (c) }\\left(\\frac{\\mu_{0} I}{2 \\pi}\\right)\\left[\\frac{-(z-d) \\hat{j}+y \\hat{k}}{y^{2}+(z-d)^{2}}-\\frac{(z+d) \\hat{j}-y \\hat{k}}{y^{2}+(z+d)^{2}}\\right]$\n\t\\task[\\textbf{D.}]$\\text { (d) }\\left(\\frac{\\mu_{0} I}{2 \\pi}\\right)\\left[\\frac{y \\hat{j}+(z-d) \\hat{k}}{y^{2}+(z-d)^{2}}+\\frac{y \\hat{j}-(z+d) \\hat{k}}{y^{2}+(z+d)^{2}}\\right]$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The vector potential inside a long solenoid with $n$ turns per unit length and carrying current $I$, written in cylindrical coordinates is $\\vec{A}(s, \\phi, z)=\\frac{\\mu_{0} n I}{2} s \\hat{\\phi}$. If the term $\\frac{\\mu_{0} n I}{2} s(\\alpha \\cos \\phi \\hat{\\phi}+\\beta \\sin \\phi \\hat{s})$, where $\\alpha \\neq 0, \\beta \\neq 0$ is added to $\\vec{A}(S, \\phi, z)$, the magnetic field remains the same if\n\t\\exyear{GATE 2019}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]$\\alpha=\\beta$\n\t\\task[\\textbf{B.}]$\\alpha=-\\beta$\n\t\\task[\\textbf{C.}]$\\alpha=2 \\beta$\n\t\\task[\\textbf{D.}]$\\alpha=\\frac{\\beta}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A magnetic field $\\vec{B}=B_{0}(\\hat{i}+2 \\hat{j}-4 \\hat{k})$ exists at point. If a test charge moving with a velocity, $\\vec{v}=v_{0}(3 \\hat{i}-\\hat{j}+2 \\hat{k})$ experiences no force at a certain point, the electric field at that point in SI units is\n\t\\exyear{JEST 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{E}=-v_{0} B_{0}(3 \\hat{i}-2 \\hat{j}-4 \\hat{k})$\n\t\\task[\\textbf{B.}]$\\vec{E}=-v_{0} B_{0}(\\hat{i}+\\hat{j}+7 \\hat{k})$\n\t\\task[\\textbf{C.}]$\\vec{E}=v_{0} B_{0}(14 \\hat{j}+7 \\hat{k})$\n\t\\task[\\textbf{D.}]$\\vec{E}=-v_{0} B_{0}(14 \\hat{j}+7 \\hat{k})$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A small magnet is dropped down a long vertical copper tube in a uniform gravitational field. After a long time, the magnet\n\t\\exyear{JEST 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] attains a constant velocity\n\t\\task[\\textbf{B.}] moves with a constant acceleration\n\t\\task[\\textbf{C.}] moves with a constant deceleration\n\t\\task[\\textbf{D.}]executes simple harmonic motion\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A thin uniform ring carrying charge $Q$ and mass $M$ rotates about its axis. What is the gyromagnetic ratio (defined as ratio of magnetic dipole moment to the angular momentum) of this ring?\n\t\\exyear{JEST 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{Q}{2 \\pi M}$\n\t\\task[\\textbf{B.}]$\\frac{Q}{M}$\n\t\\task[\\textbf{C.}]$\\frac{Q}{2 M}$\n\t\\task[\\textbf{D.}]$\\frac{Q}{\\pi M}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The electric and magnetic field caused by an accelerated charged particle are found to scale as $E \\propto r^{-n}$ and $B \\propto r^{-m}$ at large distances. What are the value of $n$ and $m$ ?\n\t\\exyear{JEST 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $n=1, m=2$\n\t\\task[\\textbf{B.}] $n=2, m=1$\n\t\\task[\\textbf{C.}]$n=1, m=1$\n\t\\task[\\textbf{D.}]$n=2, m=2$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A system of two circular co-axial coils carrying equal currents $I$ along same direction having equal radius $R$ and separated by a distance $R$ (as shown in the figure below). The magnitude of magnetic field at the midpoint $P$ is given by\n\t\\exyear{JEST 2014}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{diagram-20210809(7)-crop}\n\t\t\\caption{}\n\t\t\\label{}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}](a) $\\frac{\\mu_{0} I}{2 \\sqrt{2} R}$\n\t\\task[\\textbf{B.}]$\\frac{4 \\mu_{0} I}{5 \\sqrt{5} R}$\n\t\\task[\\textbf{C.}]$\\frac{8 \\mu_{0} I}{5 \\sqrt{5} R}$\n\t\\task[\\textbf{D.}] 0\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A charged particle is released at time $t=0$, from the origin in the presence of uniform static electric and magnetic fields given by $E=E_{0} \\hat{y}$ and $B=B_{0} \\hat{z}$ respectively. Which of the following statements is true for $t>0$ ?\n\t\\exyear{JEST 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] The particle moves along the $x$-axis.\n\t\\task[\\textbf{B.}]The particle moves in a circular orbit.\n\t\\task[\\textbf{C.}]The particle moves in the $(x, y)$ plane.\n\t\\task[\\textbf{D.}] Particle moves in the $(y, z)$ plane\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The strength of magnetic field at the center of a regular hexagon with sides of length $a$ carrying a steady current $I$ is:\n\t\\exyear{JEST 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\mu_{0} I}{\\sqrt{3} \\pi a}$ \n\t\\task[\\textbf{B.}]$\\frac{\\sqrt{6} \\mu_{0} I}{\\pi a}$\n\t\\task[\\textbf{C.}]$\\frac{3 \\mu_{0} I}{\\pi a}$\n\t\\task[\\textbf{D.}]$\\frac{\\sqrt{3} \\mu_{0} I}{\\pi a}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A wire with uniform line charge density $\\lambda$ per unit length carries a current $I$ as shown in the figure. Take the permittivity and permeability of the medium to be $\\varepsilon_{0}=\\mu_{0}=1 . \\mathrm{A}$ particle of charge $q$ is at a distance $r$ and is travelling along a trajectory parallel to the wire. What is the speed of the charge?\n\t\\exyear{JEST 2019}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=6cm]{jest-crop}\n\t\\end{figure}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\lambda}{I}$ \n\t\\task[\\textbf{B.}]$\\frac{\\lambda}{2 I}$\n\t\\task[\\textbf{C.}]$\\frac{\\lambda}{3 I}$\n\t\\task[\\textbf{D.}]$\\frac{4 \\lambda}{I}$\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{d}&2&\\textbf{a}\\\\\\hline\n\t\t3&\\textbf{a}&4&\\textbf{c}\\\\\\hline\n\t\t5&\\textbf{c}&6&\\textbf{0.15}\\\\\\hline\n\t\t7&\\textbf{1.44}&8&\\textbf{b}\\\\\\hline\n\t\t9&\\textbf{c}&10&\\textbf{4}\\\\\\hline\n\t\t11&\\textbf{d}&12&\\textbf{4}\\\\\\hline\n\t\t13&\\textbf{c}&14&\\textbf{c}\\\\\\hline\n\t\t15&\\textbf{b}&16&\\textbf{d}\\\\\\hline\n\t\t17&\\textbf{d}&18&\\textbf{a}\\\\\\hline\n\t\t19&\\textbf{c}&20&\\textbf{c}\\\\\\hline\n\t\t21&\\textbf{c}&22&\\textbf{c}\\\\\\hline\n\t\t23&\\textbf{d}&24&\\textbf{a}\\\\\\hline\n\t\\end{tabular}\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}[ label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item Consider a coil of radius $R$ is placed in $XY$ plane having current $I$ passing through it. Auppose another coil having the same radius $R$ is placed at a distance $2R$ from the first. Find the magnetic field at the mid point between them?\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=4cm,height=2cm]{diagram-20210430-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t&B \\text{at}\\quad\\text{is}=B_1+B_2\\\\\n\t\tB_1&=\\frac{\\mu_{0} I}{2}\\times\\frac{R^2}{(R^2+R^2)^\\frac{3}{2}}\\qquad \\text{here,}\\ z=R\\\\\n\t\t&=\\frac{\\mu_0 I}{2}\\frac{R^2}{2^\\frac{3}{2}\\times R^3}=\\frac{\\mu_0 I}{2\\times2^\\frac{3}{2}\\times R}\\\\\n\t\tB_2 \\text{is also same}\\\\\n\t\t\\therefore B&=2\\times\\frac{\\mu_0 I}{2\\times2^\\frac{2}{3}R}=\\frac{\\mu_0I}{2\\sqrt{2}R}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  A very long solenoid with $n$ turns per unit length carries a current $I$. The magnetic field at a point which is on its axis and its end face?\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=6cm,height=2cm]{diagram-20210430(2)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tFor a solenoid magnetic field at any point $P$ on its axis is given by\n\t\t$$B=\\frac{\\mu_0 nI}{2}(\\cos\\theta_2-\\cos\\theta_1)$$\n\t\t$\\theta_1$ and $\\theta_2$ are the angle made by the end points of the solenoid to $P$.\\\\\n\t\t\\begin{align*}\n\t\t\\therefore\\text{In the case of infinite solenoid,at center}\\\\\n\t\t\\theta_1&=\\pi,\\theta_2=0\\\\\n\t\t\\therefore B&=\\frac{\\mu_0 nI}{2}\\times2=\\mu_0 nI \\quad\\text{at center}\\\\\n\t\t\\text{Here in this question,at one end},\\\\\n\t\t\\theta_1&=\\frac{\\pi}{2},\\quad\\theta_2=0 \\text{(for long solenoid)}\\\\\n\t\tB&=\\frac{\\mu_0 n I}{2}\\times1=\\frac{\\mu_0 n I}{2}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A steady current $I$ flows down a long cylindrical wire of radius $a$ Find the magnetic field, both inside and outside the wire, if\\\\\n\t\\textbf{(a)} The current is uniformly distributed over the outside surface of the wire.\\\\\n\t\\textbf{(b)} The current is distributed in such a way that $J$ is proportional to $s$, the distance from the axis.\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=3.5cm,height=1.5cm]{diagram-20210430(8)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t\\textbf{(a)} Here current is uniform\\\\\n\t\tInside the wire \\quad $B=0$\\quad $s<a$, no current enclosed \\\\\n\t\toutside the wire\\quad $\\oint B\\cdot dl=\\mu_0I$\\\\\n\t\t\\begin{align*}\n\t\tdl&=2\\pi s\\\\\n\t\t\\text{s is the radius of }&\\text{Amperial loop $dl$ around the wire}\\\\\n\t\t\\therefore B\\times2\\pi s&=\\mu_0I\\\\\n\t\tB&=\\frac{\\mu_0I}{2\\pi s}s>a\\\\\n\t\t\\end{align*}\n\t\t\\textbf{(b)}\n\t\t\\begin{align*}\n\t\t\\text{inside the wire}\n\t\tJ&=ks\\\\\n\t\t\\text{First  we have to find }&\\text{  $k$,so}\\hspace{3cm}I=\\text{total current}\\\\\n\t\t\\text{We know}I&=\\int_{0}^{a}J\\cdot da \\hspace{2cm}J=ks \\quad da=2\\pi s ds\\\\\n\t\t\\therefore I&=k2\\pi\\int_{0}^{a}s^2ds\\\\\n\t\tI&=k2\\pi s\\frac{s^3}{3}\\quad\\text{so}\\quad k=\\frac{3I}{2\\pi a^3}\n\t\t\\intertext{Now inside the wire Consider an Amperial loop of radius \\ $s$\\ inside the wire}\n\t\t\\text{So}\\oint B\\cdot dl&=\\mu_0I \\hspace{3cm}J=ks\\\\\n\t\tB\\times2\\pi s&=\\mu_0I\\hspace{3cm}ds=2\\pi sds\\\\\n\t\tI=\\int_{0}^{s}J.ds&=\\int_{0}^{s}ks\\times2\\pi sds\\\\\n\t\t&=k\\int_{0}^{s}s^2 ds\\times2\\pi\\\\\n\t\t&=\\frac{ks^3}{3}\\times2\\pi\\\\\n\t\t\\text{Substituting  value of }k\\\\\n\t\tI&=\\frac{3 I}{2\\pi a^3}\\times\\frac{s^3}{3}\\times2\\pi\\\\\n\t\t&=\\frac{Is^3}{a^3}\\\\\n\t\t\\therefore B\\times2\\pi s&=\\frac{\\mu_0Is^3}{a^3}\\\\\n\t\tB&=\\frac{\\mu_0Is^2}{2\\pi a^3}\\hat{\\phi} \\quad \\text{inside}\\\\\n\t\t\\text{Out side the wire}\\\\\n\t\t\\oint B\\cdot dl&=\\mu_0I\\\\\n\t\tB\\times2\\pi s&=\\mu_0I\\\\\n\t\tB&=\\frac{\\mu_0I}{2\\pi s}\\hat{\\phi}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the magnetic field at the center $O$ for the following figures.\\\\\n\t\\begin{minipage}{0.45\\textwidth}\n\t\t\\begin{figure}[H]\n\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[width=3.5cm,height=3.5cm]{diagram-20210430(1)-crop}\n\t\t\t\\end{center}\n\t\t\t\\caption{(a)}\n\t\t\\end{figure}\n\t\\end{minipage}\n\t\\begin{minipage}{0.45\\textwidth}\n\t\t\\begin{figure}[H]\n\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[width=3.5cm,height=3.5cm]{diagram-20210430(4)-crop}\n\t\t\t\\end{center}\n\t\t\t\\caption{(b)}\n\t\t\\end{figure}\n\t\\end{minipage}\n\t\\begin{answer}\n\t\t\\textbf{(a)}\n\t\t\\begin{align*}\n\t\t\\intertext{Field at $O$ due to $PS$ and $QR$ is zero. Because the point $O$ lies along the axis of the segment.}\n\t\t\\text{Field at $O$ due to $RS$,}\\\\\n\t\tB_1&=\\frac{\\mu_0I}{2b}\\times\\frac{\\phi}{2\\pi}\\\\\n\t\t\\text{Field at $O$ due to $PQ$}\\\\\n\t\tB_2&=\\frac{\\mu_0I}{2a}\\times\\frac{2\\pi-\\phi}{2\\pi}\\\\\n\t\t\\text{So total field at B}\\\\\n\t\tB&=B_1+B_2\\\\\n\t\t&=\\frac{\\mu_0I}{4\\pi}\\left( \\frac{\\phi}{b}+\\frac{2\\pi-\\phi}{a}\\right) \\\\\n\t\t\\end{align*}\n\t\t\\textbf{(b)}\n\t\t\\begin{align*}\n\t\t\\text{Field at $O$ due to arc $pQ$}\\\\\n\t\tB_1&=\\frac{\\mu_0I}{2a}\\times\\frac{3\\frac{\\pi}{2}}{2\\pi}\\\\\n\t\t=&\\frac{\\mu_0I}{2a}\\times\\frac{3}{4}\n\t\t\\intertext{Field at $O$ due to $PT$ \\ and\\ $QR$\\ are zero. Field at $O$ due to $ST$ and $RS$.}\n\t\tB_2=\\ B_3&=\\frac{\\mu_0I}{4\\pi b}(\\sin\\theta_2-\\sin\\theta_1)\\\\\n\t\t&=\\frac{\\mu_0I}{4\\pi b}\\sin45\\hspace{3cm}\\theta_2=45,\\quad \\theta_{1}=0\\\\\n\t\t&=\\frac{\\mu_0I}{4\\pi b}\\times\\frac{1}{\\sqrt{2}}\\\\\n\t\t\\intertext{Total field at \\ $O$,}\n\t\tB&=B_1+B_2+B_3\\\\\n\t\t&=\\frac{\\mu_0I}{2a}\\times\\frac{3}{4}+2\\times\\frac{\\mu_0}{4\\pi b}\\times\\frac{1}{\\sqrt{2}}\\\\\n\t\t&=\\frac{\\mu_0I}{4\\pi}\\left[\\frac{3\\pi}{2a}+\\frac{\\sqrt{2}}{b} \\right] \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Magnetic field at center $O$ due to a regular pentagon if $I$ current flowing through it and $R$ be the distance from each side to $O$.\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=2.5cm,height=2.5cm]{diagram-20210430(5)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tFor an $n$ sided rectangular polygon field at center\\\\\n\t\t$B=\\frac{n\\mu_0I}{2\\pi R}\\tan\\frac{\\pi}{n}$ if $R$ become the distance from each vertex to center\\\\\n\t\tif $R$ is the distance from each side to center  \n\t\t\\begin{align*}\n\t\tB&=\\frac{n\\mu_0I}{2\\pi R}\\sin\\frac{\\pi}{n}\\\\\n\t\t\\text{Here,}\\quad n&=5\\quad \\\\\n\t\t\\text{Then,} B&=\\frac{\\mu_0nI}{2\\pi R}\\sin\\frac{\\pi}{n}\\\\\n\t\t&=\\frac{5\\mu_0 I}{2\\pi R}\\sin\\frac{\\pi}{5}\\\\\n\t\t&=\\frac{5\\mu_0I}{2\\pi R}\\sin 36\t\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Thick slab extending from $z=-a$ and $z=+a$ carries a uniform volume current $J=J(x) $.Find the magnetic field as a function of $Z$ both inside and outside the slab.\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=5cm,height=3cm]{diagram-20210430(6)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tConsider an Amperian loop of length $l$ and height $z$, applying Ampere's law.\\\\\n\t\t\\begin{align*}\n\t\t\\oint B\\cdot dl&=\\mu_0I\\\\\n\t\tB\\times l&=\\mu_0\\cdot lz\\cdot J\\hspace{3cm}I=lz\\cdot \\vec{J}\\\\\n\t\t\\therefore B&=\\mu_0Jz\\hat{y}\\hspace{3cm}(-a<z<a)\\\\\n\t\t\\end{align*}\n\t\tBy using right hand thumb rule we can say that for $z>0$ field is along $-y$ direction and for $z<0$ field is along $+y$ direction\n\t\t\\begin{align*}\n\t\t\\text{So}\\quad B&=-\\mu_0Ja\\hat{y}\\quad\\text{for}\\quad z>+a\\\\\n\t\tB&=+\\mu_0Ja\\hat{y}\\quad\\text{for}\\quad z>-a\n\t\t\\end{align*}\n\t\tBy consideting an Amperian loop of length $l$ and height $a$.\n\t\\end{answer}\n\t\\item A beam of proton with velocity $4\\times10^5 {m}/{Sec}$enters a uniform magnetic field of 0.3Tesla at an angle $60^\\circ$to the magnetic field. Find the radius of the helical path taken by the proton beam. Also find the pitch of the helix.\\\\\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tV&=4\\times10^5 \\frac{m}{Sec}\\hspace{1cm}V_\\perp=V\\sin60\\hspace{1cm}V_\\parallel=V\\cos60\\\\\n\t\t&\\frac{mv_\\perp^2}{R}=qv_\\perp B\\\\\n\t\tR&=\\frac{m v_\\perp}{qB}\\\\\n\t\t&=0.012m \\quad m_p=1.6\\times 10^{-27}kg\\\\\n\t\t\\text{Pitch of helix,}\\\\\n\t\td&=V_\\parallel T=V_\\parallel\\times\\frac{2\\pi m}{qB}=0.044m\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The maximum energy of deuteron coming out of a cyclotron accelerator is $20MeV$. The maximum energy of proton that can be obtained from the accelerator is?\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tKE_{max}&=\\frac{Q^2B^2R^2}{2m}\\\\\n\t\tKE_d&=20 MeV\\\\\n\t\tKE_P&=?\\\\\n\t\t20&=\\frac{1\\times B^2\\times R^2}{2\\times2}\\\\\n\t\tKE_P&=\\frac{1\\times B^2\\times R^2}{2\\times1}\\\\\n\t\tKE_P&=20MeV\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Ab $\\alpha$ particle is accelerated by potencial difference of $10^4V$. Find the change in its direction of motion. If it enters normally in a region of thickness $0.1m$ having transverse magnetic induction of $0.1 $Tesla$(m=6.4\\times10^-27kg)$\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=3.5cm,height=2.5cm]{diagram-20210430(9)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tBefore entering the field, $\\alpha$ particle is accelerated by a potential difference of $10^4V$ then\\begin{align*}\n\t\t\\frac{1}{2}mu^2&=qV\\\\\n\t\tu&=\\sqrt{\\frac{2qV}{m}}\\\\\n\t\tR&=\\frac{mu}{QB}=\\frac{m}{QB}\\sqrt{\\frac{2qV}{m}}\\quad V=pd\\\\\n\t\t&=\\frac{1}{B}\\sqrt{\\frac{2mV}{q}}\n\t\t\\intertext{$ \\theta $ is the angle of deflection,}\n\t\t\\therefore\\sin\\theta&=\\frac{l}{R}\\hspace{3cm}V=10^4\\text{Volt}\\\\\n\t\t\\sin\\theta&=0.1\\times B\\times\\sqrt{\\frac{q}{2mV}}\\\\\n\t\tq&=2\\times1.6\\times10^{-16}=3.2\\times10^{-16}c\\\\\n\t\tm=6.4\\times10^{-27}kg\\\\\n\t\t\\sin\\theta&=0.1\\times0.1\\times\\sqrt{\\frac{3.2\\times10^{-16}}{2\\times6.4\\times10^{-27}\\times10^4}}\\\\\n\t\t&=\\frac{1}{2}\\\\\n\t\t\\therefore\\theta&=30^\\circ\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item There are two similar coils at $P$ and $Q$ having same no of turns located at $(0,4,0)$ and$(0,0,3)$. Area of crone section are in the ratio $4:3$.A $16 A$ current flowing through coil $P$in clockwise direction and a $9\\sqrt{3} A$ current in $Q$ in anticlockwise direction . What will the deflection of a compass needle placed at the origin. Assumes that earth field is negligible and radius of the coil are very small compared to their distance from the origin.\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=5cm,height=4cm]{diagram-20210430(7)-crop}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t$B$ at a distance $x$ from a coil of radius $r$\\\\\n\t\t\\begin{align*}\n\t\tB&=\\frac{\\mu_0I}{2}\\frac{nr^2}{(r^2+x^2)^\\frac{3}{2}}\\\\\n\t\t&=\\frac{\\mu_0 \\ln \\pi r^2}{2\\times\\pi \\times(x^2)^\\frac{3}{2}}\\hspace{2cm}\\quad \\text{When}\\ r<<<x\\\\\n\t\t&=\\frac{\\mu_0In\\times A}{2\\pi x^3}\\\\\n\t\t\\text{Field at 'o' \\ due to $P$},\\\\\n\t\tB_P&=\\frac{\\mu_0\\times16\\times A_P}{2\\pi\\times4^3}\\\\\n\t\t\\text{Field at 'o' \\ due to $Q$},\\\\\n\t\tB_Q&=\\frac{\\mu_0\\times9\\sqrt{3}\\times A_Q}{2\\pi\\times3^3}\\\\\n\t\t\\intertext{From figure resultant of \\ $B_P$\\ and \\ $B_Q$,\\ $B$ makes an angle With \\ $B_Q$\\ with \\ $B_P$}\\\\\n\t\t\\tan\\theta&=\\frac{B_Q}{B_P}\n\t\t=\\frac{\\mu_0\\times9\\sqrt{3} A_Q}{2\\pi\\times3^3}\\times\\frac{2\\pi\\times4^3}{\\mu_0\\times16\\times A_P}\\\\\n\t\t\\tan\\theta&=\\sqrt{3}\\\\\n\t\t\\theta&=60^\\circ\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "4e199f798ecf8026d02bbef370b446e7ff800952", "size": 92606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Electrodynamics- CSIR/chapter/magnetostatics.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/magnetostatics.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/magnetostatics.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.075781664, "max_line_length": 730, "alphanum_fraction": 0.6744379414, "num_tokens": 35008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6429452351295153}}
{"text": "\\section{Covering Spaces}\r\n\\subsection{Definitions and Examples}\r\n\\begin{definition}\r\n    Let $p:\\hat{X}\\to X$ be a map.\r\n    An open subset $U\\subset X$ is evenly covered if there exists a set $\\Delta_U$ with discrete topology and a homeomorphism $\\psi:p^{-1}(U)\\cong\\Delta_U\\times U$ such that the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            p^{-1}(U)\\arrow{r}{\\psi}\\arrow[swap]{d}{p}&\\Delta_U\\times U\\arrow{dl}{(\\delta,u)\\mapsto u}\\\\\r\n            U&\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{definition}\r\nFor $\\delta\\in\\Delta_U$, we write $U_\\delta=\\{\\delta\\}\\times U\\subset\\Delta_U\\times U$.\r\nWe can identify it as a subspace of $p^{-1}(U)$ via $\\psi^{-1}$.\r\nThen, we can canonically identify $\\Delta_U$ with $p^{-1}(\\{x\\})$ for any $x\\in U$.\r\nAlso note that we have\r\n$$p^{-1}(U)\\cong\\Delta_U\\times U\\cong\\coprod_{\\delta\\in\\Delta_U}U$$\r\n\\begin{definition}\r\n    If every point in $X$ has an evenly covered neighbourhood, then $p$ is a covering map and $\\hat{X}$ is a covering space of $X$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Take $X=I, \\Delta_X=\\{1,2,3\\}, \\hat{X}=\\Delta_X\\times X$ and take $p:\\hat{X}\\to X$ to be the projection on second coordinate.\\\\\r\n    But if we take $\\hat{X}=I\\sqcup[0,1/2)$, then the obvious projection is not a covering map as it fails at the inverse of a small neighbourhood of $1/2$.\\\\\r\n    2. Let $\\hat{X}=\\mathbb R$ and $S^1\\subset\\mathbb C$ the unit circle.\r\n    We take $p:t\\mapsto e^{2\\pi it}$.\r\n    This is a covering map.\r\n    Indeed, if $U\\subsetneq S^1$ is a proper open subset and $z_1\\in S^1\\setminus U$, then we can choose a branch of the logarithm well-defined on $S^1\\setminus\\{z_1\\}$.\r\n    Write this choice of branch as $\\log$.\r\n    Now every point $\\hat{z}\\in p^{-1}(U)$ can be uniquely written as $\\hat{z}=k+\\log(z)/(2\\pi i)$ for some integer $k$, which induces the homeomorphism $p^{-1}(U)\\cong\\mathbb Z\\times U$.\r\n    So $p$ is a covering map.\\\\\r\n    3. Let $\\hat{X}=X=S^1\\subset C$ and $p(z)=z^n$ for some $n\\in\\mathbb Z_+$ is a covering map.\r\n    Indeed, choose a local branch for $\\sqrt[n]{\\cdot}$ on a small enough open proper subset $U\\subsetneq S^1$ allows us to write $\\hat{z}\\in p^{-1}(U)$, uniquely, $\\hat{z}=e^{2\\pi ik/n}\\sqrt[n]{z}$ for $k\\in\\mathbb Z/n\\mathbb Z$.\r\n    So $\\Delta_{S^1}=\\mathbb Z/n\\mathbb Z$ works.\\\\\r\n    4. Let $\\hat{X}=S^2$ and $G=\\mathbb Z/2\\mathbb Z$ acting on $S^2$ by the antipodal map $(x,y,z)\\mapsto (-x,-y,-z)$.\r\n    Take $X=\\hat{X}/G$.\r\n    We can identify $X$ with the real projective plane $\\mathbb{RP}^2$.\r\n    The quotient map $p$ is easily a covering map.\r\n    For $x\\in\\hat{X}$, take a small enough neighbourhood $U$ of $x$ such that $(-U)\\cap U=\\varnothing$.\r\n    Let $V=p(U)$, then $p^{-1}(V)=U\\cap(-U)$, so we can just take $\\Delta_U=\\mathbb Z/2\\mathbb Z$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A covering map $p:\\hat{X}\\to X$ is $n$-sheeted (where $n\\in\\mathbb N\\cup\\{\\infty\\}$) if $|p^{-1}(\\{x\\})|=n$ for every $x\\in X$.\r\n    If such an $n$ exists, we call $n$ the degree of $p$.\r\n\\end{definition}\r\n\\subsection{Lifting Properties}\r\nWe want to connect fundamental group and covering spaces.\r\nThis is done by introducing the notion of lifting.\r\n\\begin{definition}\r\n    Let $p:\\hat{X}\\to X$ be a convering map and $f:Y\\to X$ a map.\r\n    A lift of $f$ to $\\hat{X}$ is a map $\\hat{f}:Y\\to\\hat{X}$ such that the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            &\\hat{X}\\arrow{d}{p}\\\\\r\n            Y\\arrow[swap]{r}{f}\\arrow[dashed]{ur}{\\hat{f}}&X\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A space $X$ is locally path connected if for any $x\\in X$ and open set $U\\ni x$, there is a neighbourhood $x\\ni V\\subset U$ that is path-connected.\r\n\\end{definition}\r\n\\begin{lemma}[Uniqueness of Lifting]\\label{lift_unique}\r\n    Let $p:\\hat{X}\\to X$ be a covering map and $\\hat{f}_1,\\hat{f}_2:Y\\to\\hat{X}$ lifts of $f:Y\\to X$.\r\n    If $Y$ is connected and locally path connected, and there is $y_0\\in Y$ such that $\\hat{f}_1(y_0)=\\hat{f}_2(y_0)$, then $\\hat{f}_1=\\hat{f}_2$.\r\n\\end{lemma}\r\nHowever, there exists connected but not locally path-connected space, like the topologist's comb.\r\n\\begin{proof}\r\n    We will show that the following set\r\n    $$S=\\{y\\in Y|\\hat{f}_1(y)=\\hat{f}_2(y)\\}$$\r\n    equals $Y$ by showing it is open and closed.\r\n    The result then follows by the connectedness of $Y$ and the fact that $y_0\\in S$ (so $S$ is nonempty).\\\\\r\n    Let $y_1\\in Y$ be arbitrary and $U$ be an evenly covered open neighbourhood of $f(y_1)$.\r\n    Choose $y\\in V\\subset f^{-1}(U)$ be a path-connected open neighbourhood of $y_1$.\r\n    We shall show that $V\\subset S$ if $y_1\\in S$ and $V\\subset Y\\setminus S$ if $y_1\\notin S$, which implies what we want.\r\n    To see this, choose any $y\\in V$, then there is a path $\\alpha:I\\to V$ such that $\\alpha(0)=y_1$ and $\\alpha(1)=y$.\r\n    Then $\\hat{f}_i\\circ\\alpha$ is a path in $\\hat{X}$ connecting $\\hat{f}_i(y_1)$ and $\\hat{f}_i(y)$.\r\n    But $p\\circ\\hat{f}_i\\circ\\alpha=f\\circ\\alpha$ as $\\hat{f}_i$ are lifts.\r\n    The image of $f\\circ\\alpha$ is contained in $f(V)\\subset U$ by design.\r\n    This tells us $\\hat{f}_i\\circ\\alpha$ is a path in $p^{-1}(U)\\cong\\Delta_U\\times U$.\r\n    But $\\Delta_U$ is discrete, so for each $i$, $\\hat{f}_i(y_1)$ and $\\hat{f}_i(y)$ must in fact lie in the same copy of $U$ as they must be in the same path component.\r\n    We are actually done.\r\n    Indeed, if $y_1\\in S$, then $\\hat{f}_1(y_1)=\\hat{f}_2(y_1)$, so the copies of $U$ those paths $\\hat{f}_i\\circ\\alpha$ lie on are actually the same.\r\n    This forces $\\hat{f}_i(y)$ to be equal since if we denote that particular copy as $U'$ then we have a homeomorphism $p':U'\\to U$ by restricting the covering map which gives\r\n    $$\\hat{f}_1(y)=(p')^{-1}\\circ f(y)=\\hat{f}_2(y)$$\r\n    If $y_1\\notin S$ but $y\\in S$, then by reversing the argument for $y,y_1$ shows $y_1\\in S$ which is false.\r\n    (Alternatively, one can argue by observing that each copy of $U$ contains a unique point of $p^{-1}\\circ f(\\{y_1\\})$).\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $\\gamma:I\\to X$ be a path from $x_0$ and $p:\\hat{X}\\to X$ be a covering map.\r\n    A lift of $\\gamma$ at $\\hat{x}_0\\in\\hat{X}$ is a lift $\\hat{\\gamma}:I\\to\\hat{X}$ of $\\gamma$ such that $\\hat{\\gamma}(0)=\\hat{x}_0$.\r\n\\end{definition}\r\nIn particular, $p(\\hat{x}_0)=x_0$ necessarily.\r\nIn the special case where $\\gamma$ is contained in an evenly covered open set, its lift is just picking one of the copies of the open set containing $\\hat{x}_0$ in the pre-image under the covering map and carve the same path there.\r\nIn fact, we can say more.\r\n\\begin{lemma}[Path-Lifting Lemma]\\label{path_lift}\r\n    Let $p:\\hat{X}\\to X$ be a covering map and $\\gamma:I\\to X$ be a path from $x_0$.\r\n    For any $\\hat{x}_0\\in p^{-1}(x_0)$, there exists a unique lift $\\hat{\\gamma}$ of $\\gamma$ from $\\hat{x}_0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    The uniqueness follows from Lemma \\ref{lift_unique}.\r\n    For existence, we consider\r\n    $$S=\\{t\\in I:\\gamma|_{[0,t]}\\text{ has a lift at $\\hat{x}_0$ to $\\hat{X}$}\\}$$\r\n    and we will show it is open and closed.\r\n    As $0\\in S$, we know $S\\neq\\varnothing$, therefore it shall imply what we want.\\\\\r\n    Let $t_0\\in I$ and $U$ be an evenly covered neighbourhood of $\\gamma(t_0)$ and let $V\\subset\\gamma^{-1}(U)$ be an open interval containing $t_0$.\r\n    Again we will show $t_0\\in S$ implies $V\\subset S$ and $t_0\\notin S$ implies $V\\subset I\\setminus S$ which gives the result.\r\n    Let $t\\in V$ and suppose first that $t_0\\in S$.\r\n    If $t\\le t_0$ then automatically $t\\in S$.\r\n    Otherwise $t>t_0$.\r\n    Denote the lift of $\\gamma|_{[0,t_0]}$ by $\\hat{\\gamma}|_{[0,t_0]}$.\r\n    But then since $U\\supset f(V)$ is evenly covered, we can just pick the copy of $U$ where $\\hat{\\gamma}|_{[0,t_0]}(t_0)$ resides in and continue $\\hat{\\gamma}$ there by following $\\gamma$.\r\n    More precisely, suppose that copy is $U'$ and $p':U'\\to U$ is the homeomoephism by restricting $p$, then\r\n    $$[0,t]\\ni s\\mapsto\\begin{cases}\r\n        \\hat\\gamma(s)\\text{, for $s\\in[0,t_0]$}\\\\\r\n        (p')^{-1}\\circ\\gamma(s)\\text{, for $s\\in[t_0,t]$}\r\n    \\end{cases}$$\r\n    which works as a lift of $\\gamma|_{[0,t]}$.\r\n    So $t\\in S$.\\\\\r\n    If $t_0\\notin S$ and $t\\in V$, then if $t\\in S$ and $t\\ge t_0$ we get an immediate contradiction.\r\n    But if $t<t_0$ and $t\\in S$, we can extend the lift on $[0,t]$ in the way we just described to $t_0$ which shows $t_0\\in S$, another contradiction.\r\n    So we are done.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $p:\\hat{X}\\to X$ is a covering map and $X$ is path-connected, then $p$ is an $n$-sheeted cover for some $n\\in\\mathbb N\\cup\\{\\infty\\}$.\r\n\\end{lemma}\r\nActually we can do something stronger:\r\nWe can prove that if $x,y\\in X$ then there is a bijection between $p^{-1}(\\{x\\})$ and $p^{-1}(\\{y\\})$.\r\nIn fact, this is exactly what we shall prove.\r\n\\footnote{I think this lemma is trivial by considering the set of points $x$ such that $p^{-1}(x)$ has a given (fixed) cardinality which can be easily shown to be both open and closed, but the lecturer prefers to use path-lifting lemma.}\r\n\\begin{proof}\r\n    Let $\\gamma$ be a path in $X$ from $x$ to $y$.\r\n    For any $\\hat{x}\\in p^{-1}(\\{x\\})$, then there is a unique path $\\hat{\\gamma}_{\\hat{x}}$ lifting $\\gamma$ with starting point $\\hat{x}$.\r\n    This gives a map $\\psi:p^{-1}(\\{y\\})\\to p^{-1}(\\{y\\})$ via $\\psi(\\hat{x})=\\hat{\\gamma}_{\\hat{x}}(1)$.\r\n    We shall show that it has an inverse $\\phi$ defined in a similar way but using the path $\\bar\\gamma$ from $y$ to $x$.\r\n    So $\\phi(\\hat{y})=\\widehat{(\\bar\\gamma)}_{\\hat{y}}(1)$.\r\n    We shall show that $\\phi\\circ\\psi=\\operatorname{id}_{p^{-1}(\\{x\\})}$, the other side is completely analogous.\r\n    Indeed,\r\n    $$\\phi\\circ\\psi(\\hat{x})=\\phi(\\hat{\\gamma}_{\\hat{x}}(1))=\\widehat{(\\bar\\gamma)}_{\\hat{\\gamma}_{\\hat{x}}(1)}(1)$$\r\n    But then $\\hat{\\gamma}_{\\hat{x}}\\cdot\\widehat{(\\bar\\gamma)}_{\\hat{\\gamma}_{\\hat{x}}(1)}$ is a lift of $\\gamma\\cdot\\bar\\gamma$, but so is $\\hat{\\gamma}_{\\hat{x}}\\cdot\\overline{(\\hat{\\gamma}_{\\hat{x}})}$ hence by the uniqueness of lifts they have common endpoints.\r\n    In particular, $\\widehat{(\\bar\\gamma)}_{\\hat{\\gamma}_{\\hat{x}}(1)}(1)=\\hat{x}$ as desired.\r\n\\end{proof}\r\nHere comes a lemma that really links together fundamental groups and covering maps\r\n\\begin{lemma}[Homotopy Lifting Lemma]\\label{homotopy_lifting}\r\n    Let $p:\\hat{X}\\to X$ be a covering map and $f_0:Y\\to X$ a map from a locally path-connected space.\r\n    Suppose $F:Y\\times I\\to X$ is a homotopy with $\\forall y\\in Y,F(y,0)=f_0(y)$ and there exists a lifting $\\hat{f}_0:Y\\to\\hat{X}$ of $f_0$.\r\n    Then there exists a unique lifting $\\hat{F}:Y\\times I\\to\\hat{X}$ with $\\hat{F}(y,0)=\\hat{f}_0(y)$ for any $y\\in Y$.\r\n\\end{lemma}\r\n\\begin{remark}\r\n    In the special case where $Y$ is a one-point space we reproduce Lemma \\ref{path_lift}.\r\n\\end{remark}\r\n\\begin{proof}\r\n    For each $y\\in Y$, the homotopu $F$ defines a path $\\gamma_y(t)=F_{y,t}$.\r\n    By Lemma \\ref{path_lift}, each $\\gamma_t$ has a unique lift $\\hat{\\gamma}_t$ from $\\hat{f}_0(y)$.\r\n    So we essentially need $\\hat{F}(y,t)=\\hat{\\gamma}_t(y)$.\r\n    It remains to show that such an $\\hat{F}$ has to be continuous.\r\n    The trick is to construct on open subsets of $Y\\times I$ a differently constructed lift $\\tilde{F}$ which is a priori continuous, and then show that $\\hat{F}$ agrees with $\\tilde{F}$ on these open sets.\r\n    Fix $y_0\\in Y$.\r\n    The goal is to find a neighbourhood $V$ of $y_0$ and a lifting of $F$ on $V\\times I$.\r\n    For any $t\\in I,F(y_0,t)\\in X$ has an evenly covered neighbourhood $U_t\\subset X$.\r\n    Then by continuity and the definition of product topology $F^{-1}(U_t)$ contains an open neighbourhood of $(y_0,t)\\in Y\\times I$ of the form $V_t\\times[(t-\\epsilon_t,t+\\epsilon_t)\\cap I]$ for $\\epsilon_t>0$ and $V_t\\ni y_0$ is open.\r\n    As $Y$ is locally path-connected we might as well assume $V_t$ are path-connected.\r\n    As $\\{y_0\\}\\times I$ is compact, there is a finite set $T\\subset I$ such that $\\{(t_i-\\epsilon_{t_i},t_i+\\epsilon_{t_i}):t_i\\in T\\}$ covers $I$.\r\n    We then take $V=\\bigcap_{t_i\\in T}V_{t_i}$ which is open and path-connected.\r\n    Take $J_i=(t_i-\\epsilon_{t_i},t_i+\\epsilon_{t_i})\\cap I$.\r\n    Then we know that $F(V\\times J_i)$ is contained in an evenly covered open subset $U_i$ of $X$ for each $i$.\r\n    Let $U_i'$ be the unique copy of $U_i$ in $p^{-1}(U_i)$ such that $\\hat{F}(\\{y_0\\}\\times J_i)=\\hat{\\gamma}_{y_0}(J_i)\\subset U_i'$.\r\n    Let $p_i:U_i'\\to U_i$ be the homeomorphism between them.\r\n    Now for $(y,t)\\in V\\times I$, we define $\\tilde{F}(y,t)=p_i^{-1}\\circ F(y,t)$ for $t\\in J_i$.\r\n    It is quite obvious it is well-defined, but let's prove it.\r\n    Suppose $t\\in J_i\\cap J_j$ and let $\\alpha$ be a path in $V$ from $y_0$ to $y$.\r\n    Define $\\alpha_t(s)=F(\\alpha(s),t)$.\r\n    Then $p_i^{-1}\\circ \\alpha_t$ and $p_j^{-1}\\circ\\alpha_t$ are lifts of $\\alpha_t$.\r\n    Furthermore they have the same initial values at $\\hat{F}(y_0,t)$, so they are equal by Lemma \\ref{lift_unique}.\r\n    Consequently $p_i^{-1}\\circ F(y,t)=p_j^{-1}\\circ F(y,t)$ as desired.\r\n    So $\\tilde{F}$ is a well-defined and hence continuous by its definition.\\\\\r\n    As $V$ is path-connected and $\\tilde{F}(\\cdot,0)$ is a lift of $f_0$ that agrees with $\\hat{f}_0$ at $y_0$, we have $\\forall y\\in V,\\hat{F}(y,0)=\\hat{f}_0(y)$ by Lemma \\ref{lift_unique}.\r\n    Also, for each $y\\in V$, $\\hat{F}(y,\\cdot)$ is a lift of $\\gamma_y$ at $\\hat{f}_0(y)$.\r\n    Therefore $\\tilde{F}(y,t)=\\hat{\\gamma}_y(t)$ again by Lemma \\ref{lift_unique}, thus $\\tilde{F}=\\hat{F}$ on $V\\times I$.\r\n    In particular, $\\hat{F}$ is continuous in $V\\times I$, hence it is continuous.\r\n\\end{proof}\r\n\\subsection{Lifting and Fundamental Groups}\r\n\\begin{lemma}\r\n    Let $p:\\hat{X}\\to X$ be a covering map and $F:I\\times I\\to X$ be a homotopy of paths.\r\n    Then any lift $\\hat{F}$ of $F$ is also a homotopy of paths.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    As $F$ is a homotopy of paths, $F(0,\\cdot)$ and $F(1,\\cdot)$ are constant paths in $X$.\r\n    Therefore $\\hat{F}(0,\\cdot)$ and $\\hat{F}(1,\\cdot)$ are lifts those constant paths , hence constant.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $p:\\hat{X}\\to X$ be a covering map with $\\hat{x}\\in \\hat{X}$ and $x=p(\\hat{x})$, then the induced homeomorphism $p_\\ast:\\pi_1(\\hat{X},\\hat{x})\\to\\pi_1(X,x)$ via $[\\hat\\gamma]\\mapsto [p\\circ\\hat\\gamma]$ is injective.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $[\\hat{\\gamma}]\\in\\ker p_\\ast$, then $\\gamma=p\\circ\\hat{\\gamma}\\simeq c_x$.\r\n    If $F$ is a homotopy between $\\gamma$ and $c_x$, we can lift it to a homotopy $\\tilde{F}$ from $\\hat{\\gamma}$ which is a homotopy of paths by the preceding lemma.\r\n    In particular, $\\hat{F}$ is a homotopy between $\\hat\\gamma$ and $c_{\\hat{x}}$, so $[\\hat\\gamma]=[c_{\\hat{x}}]$ is the identity.\r\n    This shows the result.\r\n\\end{proof}\r\n\\begin{remark}\r\n    So we can view $\\pi_1(\\hat{X},\\hat{x})$ as the subgroup $p_\\ast(\\pi(\\hat{X},\\hat{x}))\\le\\pi_1(X,x)$.\r\n    Also note that given $[\\gamma]\\in\\pi_1(X,x)$, we get a map $p^{-1}(\\{x\\})\\to p^{-1}(\\{x\\})$ via $\\hat{x}\\mapsto \\hat{\\gamma}_{\\hat{x}}(1)$ which is necessarily bijective.\r\n    So this defines a right group action of $\\pi_1(X,x)$ on $p^{-1}(\\{x\\})$.\r\n    For $\\hat{x}\\in p^{-1}(\\{x\\})$, this is induced by $\\hat{x}\\cdot\\gamma=\\hat\\gamma_{\\hat{x}}(1)$.\r\n    Easily $(\\hat{x}\\cdot\\gamma)\\cdot\\delta=\\hat{x}\\cdot(\\gamma\\cdot\\delta)$.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $p:\\hat{X}\\to X$ be a covering map and suppose $\\hat{X}$ is path-connected.\r\n    Let $x\\in X$, and let $\\Pi$ denote the set of right cosets of $p_\\ast(\\pi_1(\\hat{X},\\hat{x}))$ in $\\pi_1(X,x)$.\r\n    Then the map $\\Pi\\to p^{-1}(\\{x\\})$ via $p_\\ast(\\pi_1(\\hat{X},\\hat{x}))[\\gamma]\\mapsto \\hat{x}\\cdot\\gamma$ is a bijection.\r\n    Further, this bijection satisfies\r\n    $$p_\\ast(\\pi_1(\\hat{X},\\hat{x}))[\\gamma][\\delta]\\mapsto\\hat{x}\\cdot(\\gamma\\cdot\\delta)$$\r\n    where $\\gamma,\\delta$ are loops based at $x$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $[\\delta]\\in p_\\ast(\\pi_1(\\hat{X},\\hat{x}))$, then $\\hat{x}\\cdot\\delta=\\hat{x}$.\r\n    This obviously implies the map is well-defined.\r\n    To prove this is a bijection, we shall use the Orbit-Stabiliser Theorem.\r\n    Note that the stabliser of $\\hat{x}$ on this right action is the set of loops $[\\gamma]$ at $x$ such that $\\hat\\gamma_{\\hat{x}}(1)=\\hat{x}$ where $\\hat{\\gamma}_{\\hat{x}}$ is the lift of $\\gamma$ from $\\hat{x}$.\r\n    But then $\\hat\\gamma_{\\hat{x}}$ is a loop, so $\\gamma\\in p_\\ast(\\pi_1(\\hat{X},\\hat{x}))$.\r\n    This means that the stabiliser of $\\hat{x}$ is exactly $p_\\ast(\\pi_1(\\hat{X},\\hat{x}))$.\r\n    It remains to show that the action is transitive.\r\n    Let $\\hat{y}\\in p^{-1}(\\{x\\})$, then there is a path $\\hat{\\gamma}$ from $\\hat{x}$ to $\\hat{y}$, so $p\\circ\\hat{\\gamma}$ is a loop based at $x$ and $\\hat{x}\\cdot\\gamma=\\hat{y}$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    So the degree of the covering map $p$ is just the index of $p_\\ast(\\pi_1(\\hat{x},\\hat{x}))$ in $\\pi_1(X,x)$.\r\n\\end{remark}\r\n\\begin{example}\r\n    Consider $\\pi_1(S^1,x)$.\r\n    The covering map $p_1:\\mathbb R\\to S^1$ via $t\\mapsto e^{2\\pi it}$ has infinite degree and $p_2:S^1\\to S^1$ via $z\\mapsto z^n$ has degree $n$ for any $n>1$.\r\n    So what we conclude from the lemma above is that $\\pi_1(S_1,x)$ is an infinite group with subgroups of every finite index.\r\n    A natural guess is then $\\pi_1(S^1,x)\\cong\\mathbb Z$.\r\n    We will prove it later.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $p:\\hat{X}\\to X$ is a covering map and $\\hat{X}$ is simply connected, then $\\hat{X}$ is called a univeral cover of $X$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The map $t\\mapsto e^{2\\pi it}$ makes $\\mathbb R$ a universal cover of $S^1$.\r\n\\end{example}\r\n\\begin{corollary}\r\n    If $p:\\hat{X}\\to X$ is a universal cover, then for any choice of $\\hat{x}\\in p^{-1}(\\{x\\})$ there is a bijection\r\n    $$\\pi_1(X,x)\\to p^{-1}(\\{x\\}),[\\gamma]\\mapsto \\hat{x}\\cdot\\gamma$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from what we have discussed.\r\n\\end{proof}\r\nSo we can get a group structure on $p^{-1}(\\{x\\})$ which is essentially isomorphic to $\\pi_1(X,x)$ and determined by $\\hat{x}\\cdot (\\gamma\\cdot\\delta)=(\\hat{x}\\cdot\\gamma)\\cdot\\delta$.\r\nThis allows us to actually calculate some fundamental groups.\r\n\\begin{example}\r\n    Now we compute the fundamental group of the circle.\r\n    Let $p:\\mathbb R\\to S^1$ be the usual universal cover.\r\n    Hence there is a bijection\r\n    $$\\pi_1(S^1,1)\\to p^{-1}(\\{1\\})=\\mathbb Z\\subset\\mathbb R$$\r\n    Now for $n\\in\\mathbb Z$, take $\\tilde{\\gamma}_n(t)=nt$ to be a path from $0$ to $n$ in $\\mathbb R$ and let $\\gamma_n=p\\circ\\hat{\\gamma}_n$ which has to be a loop based at $1$.\r\n    Clearly $0\\cdot\\gamma_n=\\hat{\\gamma}_n(1)=n$.\r\n    Thus any loop in $S^1$ based at $1$ is homotopic to some $\\gamma_n$.\r\n    So the bijection becomes $[\\gamma_n]\\mapsto n$.\r\n    It remains to show that it is a homomorphism.\r\n    Indeed, for any $m\\in\\mathbb Z$, we know that $m+\\hat{\\gamma}_n$ is a lift of $\\gamma_n$ from $m$ to $m+n$.\r\n    So\r\n    $$(0\\cdot\\gamma_m)\\cdot\\gamma_n=m\\cdot\\gamma_n=m+n=0\\cdot\\gamma_{m+n}$$\r\n    Hence it is indeed a homomorphism, it then follows that it is an isomorphism, which means $\\pi_1(S^1,1)\\cong\\mathbb Z$.\r\n\\end{example}\r\nIn complex analysis, we defined the winding number as, loosely speaking, the number of times a loop wraps around a certain point.\r\nIt then follows that this notion is essentially describing the homotopy class a curve is in when we put the thing in $\\pi_1(S^1,1)$.\r\nThere are more applications of this idea.\r\n\\subsection{Applications of Fundamental Groups}\r\n\\begin{theorem}[No-Retraction Theorem]\\label{no_retraction}\r\n    The identity map of $S^1$ does not extend to a map $r:D^2\\to S^1$ (where we view $S^1$ as $\\partial D^2$).\r\n\\end{theorem}\r\nThat is, $S^1$ is not a retract of $D^2$.\r\nWe have essentially covered the proof in the introduction, where all technical details have just been covered.\r\n\\begin{proof}\r\n    If such an $r$ exists, let $\\iota:S^1\\hookrightarrow D^2$ be the inclusion map, then $r\\circ\\iota=\\operatorname{id}_{S^1}$.\r\n    As $D^2$ is contractible, $\\pi_1(D^2,1)=0$, so there is a factorisation\r\n    $$(\\operatorname{id}_{S^1})_\\ast=(r\\circ\\iota)_\\ast=r_\\ast\\circ\\iota_\\ast:\\pi_1(S^1,1)\\to\\pi_1(D^2,1)\\to\\pi_1(S^1,1)$$\r\n    But the last diagram is just $\\mathbb Z\\to\\{0\\}\\to\\mathbb Z$.\r\n    This means that $(\\operatorname{id}_{S^1})_\\ast$ has to be constant.\r\n    But it isn't.\r\n    Contradiction.\r\n\\end{proof}\r\n\\begin{theorem}[Brouwer's Fixed Point Theorem]\r\n    Any map $f:D^2\\to D^2$ has a fixed point.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose not, then let $g:D^2\\to S^1$ be the map given by projecting $f(x)$ through $x$ onto $S^1$.\r\n    That is, $g(x)$ is the intersection of the line joining $x$ and $f(x)$ and $S^1$ that is closer to $x$.\r\n    Then $g$ is continuous and $g(x)=x$ for any $x\\in S^1$.\r\n    This however means that $g$ restricts to $\\operatorname{id}_{S^1}$, contradicing Theorem \\ref{no_retraction}.\r\n\\end{proof}\r\n\\begin{theorem}[The Fundamental Theorem of Algebra]\r\n    Every nonconstant polynomial $p:\\mathbb C\\to\\mathbb C$ has a zero.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $r:\\mathbb C\\setminus\\{0\\}\\to S^1$ via $r(z)=z/|z|$ which is a retraction.\r\n    For $R\\ge 0$, we define $\\lambda_R:S^1\\to\\mathbb C, \\lambda_R(z)=Rz$.\r\n    If $p$ has no zero, then we can define $f_R:r\\circ p\\circ \\lambda_R:S^1\\to S^1$.\r\n    Easily for any $R_1,R_2\\in\\mathbb R_{\\ge 0}$, $f_{R_1}$ and $f_{R_2}$ are homotopic, hence $(f_{R_1})_\\ast=(f_{R_2})_\\ast$.\r\n    But these induced maps are all homomorphisms $\\mathbb Z\\to\\mathbb Z$.\r\n    Therefore all $(f_R)^\\ast$ is given by multiplication by $d$ for some fixed $d\\in\\mathbb N\\setminus\\{0\\}$.\r\n    But $f_0$ is constant, therefore $d=0$ and $(f_R)_\\ast$ are constantly zero.\r\n    But for very large $R$, the leading term dominates $p$, so it is clear that $(f_R)_\\ast$ is given by multiplication by $\\deg p\\neq 0$, contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A space $X$ is locally simply connected if, for every $x\\in X$ and open neighbourhood $U$ of $x$, there exists a simply connected neighbourhood $x\\in V\\subset U$.\r\n\\end{definition}\r\n\\begin{example}[Non-example]\r\n    Take the Hawaii Earing space\r\n    $$X=\\bigcup_{n=1}^\\infty \\left\\{(x,y)\\in\\mathbb R^2:\\left( x-\\frac{1}{n} \\right)+y^2=\\frac{1}{n^2}\\right\\}$$\r\n    then no open neighbourhood of $(0,0)$ is simply connected.\r\n\\end{example}\r\n\\begin{theorem}[Existence of Universal Cover]\r\n    Let $X$ be a path-connected space such that $X$ is localled simply connected, then there exists a universal cover $p:\\hat{X}\\to X$.\r\n\\end{theorem}\r\n\\begin{proof}[Sketch of proof]\r\n    Fix $x_0\\in X$ and consider the set $\\mathscr X$ of all paths $\\gamma$ from $x_0$.\r\n    Define $\\hat{X}=\\mathscr X/\\simeq$ where $\\simeq$ is the path homotopy equivalence relation.\r\n    The intended map $p:\\hat{X}\\to X$ is gives by $p([\\gamma])=\\gamma(1)$.\r\n    The tricky bit is to find a topology on $\\hat{X}$ making it work, which -- guess what -- is skipped.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $X$ to be the figure eight, then $\\hat{X}$ looks like the Caylay graph of the free group $F_2$.\r\n\\end{example}\r\n\\subsection{The Galois Correspondence}\r\nThe idea is to classify all covering spaces using subgroups of the fundamental group, which is in certain ways analogous to the idea of Galois correspondence in Galois theory.\r\n\\begin{definition}\r\n    Let $X$ be a path-connected space and $p_1:\\hat{X}_1\\to X_1, p_2:\\hat{X}_2\\to X$.\r\n    An isomorphism of covering spaces is a homeomorphism $\\phi:\\hat{X}_1\\to\\hat{X}_2$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            X&\\hat{X}_1\\arrow{dl}{\\phi}\\arrow[swap]{l}{p_1}\\\\\r\n            \\hat{X}_2\\arrow{u}{p_2}&\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{definition}\r\nNote also that $\\phi^{-1}$ is automatically an isomorphism of covering spaces as well\r\nIf $\\hat{X}_i$ are equipped with basepoints $\\hat{x}_i\\in\\hat{X}_i$ and $\\phi(\\hat{x}_1)=\\hat{x}_2$, we say $\\phi$ is based.\r\n\\begin{remark}\r\n    Note that $\\phi$ is a lift of $p_1$ to $\\hat{X}_2$, so by Lemma \\ref{lift_unique}, a based isomorphism is uniquely determined by the basepoints $\\phi(\\hat{x}_1)=\\hat{x}_2$ if $\\hat{X}_1$ is connected and locally path-connected.\r\n\\end{remark}\r\n\\begin{theorem}[Galois Correspondence with Basepoints]\\label{based_galois}\r\n    Let $X$ be a path-connected, locally simply connected space with basepoint $x_0$.\r\n    The map which sends a covering $p:\\hat{X}\\to X$ equipped with a basepoint $\\hat{x}_0\\in p^{-1}(\\{x_0\\})$ to the subgroup $p_\\ast(\\pi_1(\\hat{X},\\hat{x}_0))\\le\\pi_1(X,x_0)$ induces a bijection between the set of based isomorphism classes of path-connected covering spaces with basepoint and the set of subgroups of $\\pi_1(X,x_0)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Not dreadfully hard but omitted.\r\n\\end{proof}\r\n\\begin{example}\r\n    As $\\pi_1(S^1,1)=\\mathbb Z$, each subgroup of $\\mathbb Z$ is of the form $n\\mathbb Z$ for natural number $n$ (including $0$).\r\n    Then the usual $p:\\mathbb R\\to S^1, t\\mapsto e^{2\\pi it}$ corresponds to the subgroup $\\{0\\}$, and the maps $p:S^1\\to S^1, z\\mapsto z^n$ corresponds to the subgroups $n\\mathbb Z$ for $n\\neq 0$.\r\n    Hence, these are the only path-connected covering spaces of $S^1$ up to based isomorphism.\r\n\\end{example}\r\n\\begin{corollary}\r\n    Let $X$ be a path-connected and locally simply connected space, then any two universal covers $p_1:\\hat{X}_1\\to X$ and $p_2:\\hat{X}_2\\to X$ are isomorphic.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{corollary}[Galois Correspondence without Basepoints]\\label{unbased_galois}\r\n    Let $X$ be a path-connected, locally simply connected space with basepoint $x_0$.\r\n    Then the map that sends a covering $p:\\hat{X}\\to X$ equipped with a basepoint $\\hat{x}_0\\in p^{-1}(\\{x_0\\})$ to the subgroup $p_\\ast(\\pi_1(\\hat{X},\\hat{x}))\\le\\pi_1(X,x_0)$ induces a bijection between (unbased) isomorphism classes of path-connected convering spaces of $X$ and conjugacy classes of subgroups of $\\pi_1(X,x_0)$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    This map is surjective due to Theorem \\ref{based_galois}.\r\n    To see it is injective, we need to show that if $(p_1)_\\ast(\\pi_1(\\hat{X}_1,\\hat{x}_1))$ and $(p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2))$ are conjugate subgroups of $\\pi_1(X,x_0)$, then there is an (unbased) isomorphism $\\phi:\\hat{X}_1\\to\\hat{X}_2$ of covering spaces.\\\\\r\n    Suppose\r\n    $$(p_1)_\\ast(\\pi_1(\\hat{X}_1,\\hat{x}_1))=[\\gamma](p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2))[\\bar\\gamma]$$\r\n    for some $[\\gamma]\\in\\pi_1(X,x_0)$.\r\n    Let $\\widehat{\\bar{\\gamma}}$ be the lift of $\\bar\\gamma$ at $\\hat{x}_2$ and $\\hat{x}_2'$ be the other endpoint of $\\widehat{\\bar\\gamma}$.\r\n    By the last part of Lemma \\ref{indep_basepoint},\r\n    \\begin{align*}\r\n        [\\gamma](p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2))[\\bar\\gamma]&=\\bar\\gamma_\\#((p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2)))\\\\\r\n        &=(p_2)_\\ast(\\widehat{\\bar\\gamma}_\\#(\\pi_1(\\hat{X}_2,\\hat{x}_2)))\\\\\r\n        &=(p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2'))\r\n    \\end{align*}\r\n    Therefore $(p_1)_\\ast(\\pi_1(\\hat{X}_1,\\hat{x}_1))=(p_2)_\\ast(\\pi_1(\\hat{X}_2,\\hat{x}_2'))$.\r\n    Theorem \\ref{based_galois} then gives a based isomorphism $(\\hat{X}_1,\\hat{x}_1)\\cong(\\hat{X}_2,\\hat{x}_2')$.\r\n    In particular, $\\hat{X}_1\\cong\\hat{X}_2$ as (unbased) covering spaces.\r\n\\end{proof}", "meta": {"hexsha": "ab8781ce9ef9ea03e86f2683a1e909b2c177076a", "size": 27359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/cover.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": "2/cover.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": "2/cover.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": 71.8083989501, "max_line_length": 333, "alphanum_fraction": 0.6451990204, "num_tokens": 9529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6429452293752298}}
{"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*{3.3.1}\nSales personnel for Skillings Distributors submit weekly reports listing the customer contacts made during the week.\nA sample of 65 weekly reports showed a sample mean of 19.5 customer contacts per week. The sample standard deviation was 5.2.\nProvide 90\\% and 95\\% confidence intervals for the population mean number of weekly customer contacts for the sales personnel.\n\\begin{align*}\n  \\text{Margin} &= 90\\%\\\\\n  s &= 5.2\\\\\n  n &= 65\\\\\n  \\bar{x} &= 19.5\\\\\n  \\text{Error Margin} &= t_{\\alpha/2}(s/ \\sqrt{n})\\\\\n  &=t_{.1/2}(5.2/ \\sqrt{65})\\\\\n  &=t_{.05}(0.644980619863884)\\\\\n  &=1.669(0.644980619863884)\\\\\n  &=1.07648105544093\\\\\n  interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n  &= 19.5 \\pm 1.07648105544093\\\\\n  &= (18.4235189445591, 20.5764810554409)\n\\end{align*}\n\n\\begin{align*}\n  \\text{Margin} &= 95\\%\\\\\n  s &= 5.2\\\\\n  n &= 65\\\\\n  \\bar{x} &= 19.5\\\\\n  \\text{Error Margin} &= t_{\\alpha/2}(s/ \\sqrt{n})\\\\\n  &=t_{.05/2}(5.2/ \\sqrt{65})\\\\\n  &=t_{.025}(0.644980619863884)\\\\\n  &=1.998(0.644980619863884)\\\\\n  &=1.28849691076229\\\\\n  interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n  &= 19.5 \\pm 1.28849691076229\\\\\n  &= (18.2115030892377, 20.7884969107623)\n\\end{align*}\n\n\\section*{3.3.2}\nThe mean number of hours of flying time for pilots at Continental Airlines is 49 hours per month (The Wall Street Journal, February 25, 2003). Assume that this mean was based on actual flying times for a sample of 100 Continental pilots and that the sample standard deviation was 8.5 hours.\n\\begin{enumerate}\n  \\item At 95\\% confidence, what is the margin of error?\n  \\begin{align*}\n    \\text{Margin} &= 95\\%\\\\\n    s &= 8.5\\\\\n    n &= 100\\\\\n    \\bar{x} &= 49\\\\\n    \\text{Error Margin} &= t_{\\alpha/2}(s/ \\sqrt{n})\\\\\n    &=t_{.05/2}(8.5/ \\sqrt{100})\\\\\n    &=t_{.025}(0.85)\\\\\n    &=1.984(0.85)\\\\\n    &=1.68658440884845\n  \\end{align*}\n\n  \\item What is the 95\\% confidence interval estimate of the population mean flying time for the pilots?\n  \\begin{align*}\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 59 \\pm 1.68658440884845\\\\\n    &= (47.3134155911515, 50.6865844088485 )\n  \\end{align*}\n\n  \\item The mean number of hours of flying time for pilots at United Airlines is 36 hours per month. Use your results from part (b) to discuss differences between the flying times for the pilots at the two airlines. (The Wall Street Journal reported United Airlines as having the highest labor cost among all airlines. Does the information in this exercise provide insight as to why United Airlines might expect higher labor costs?)\n  \n  It's probably because United airlines pilots fly a lot less, so the costs may stay relative high when compared to pilots who fly 10 hours more a month\n\\end{enumerate}\n\n\\section*{3.3.3}\nThe average cost per night of a hotel room in New York City is \\$273 (Smart Money, March 2009). Assume this estimate is based on a sample of 45 hotels and that the sample standard deviation is \\$65.\n\\begin{enumerate}\n  \\item With 95\\% confidence, what is the margin of error?\n  \\begin{align*}\n    \\text{Margin} &= 95\\%\\\\\n    s &= 65\\\\\n    n &= 45\\\\\n    \\bar{x} &= 273\\\\\n    \\text{Error Margin} &= t_{\\alpha/2}(s/ \\sqrt{n})\\\\\n    &=t_{.05/2}(65/ \\sqrt{45})\\\\\n    &=t_{.025}(9.689)\\\\\n    &=2.015(9.689)\\\\\n    &=19.5281618831222\n  \\end{align*}\n  \n  \\item What is the 95\\% confidence interval estimate of the population mean?\n  \\begin{align*}\n    interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n    &= 265 \\pm 19.5281618831222\\\\\n    &= (253.471838116878, 292.528161883122)\n  \\end{align*}\n\n  \\item Two years ago the average cost of a hotel room in New York City was \\$229. Discuss the change in cost over the two-year period\n  \n  It seems that the average cost of hotels in New York from two years ago tends to be to the lower estimate of the actual average. Which is normal considering the inflation, which is that costs go up and the money looses value over time.\n\\end{enumerate}\n\n\\section*{3.3.4}\nIs your favorite TV program often interrupted by advertising? CNBC presented statistics on the average number of programming minutes in a half-hour sitcom (CNBC, February 23, 2006). The following data (in minutes) are representative of their findings:\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{c c c c c c}\n    20.02&22.20&21.20&21.06&22.24&20.62\\\\\n    22.37&22.19&22.34&21.66&21.23&23.86\\\\\n    23.82&20.30&21.52&21.52&21.91&23.1\\\\\n    23.36&23.44&&&&\\\\\n  \\end{tabular}\n\\end{table}\nAssume the population is approximately normal. Provide a point estimate and a 95\\% confidence interval for the mean number of programming minutes during a half-hour television sitcom.\n\n\\begin{align*}\n  \\text{Margin} &= 95\\%\\\\\n  s &= 1.11702424230396\\\\\n  n &= 20\\\\\n  \\bar{x} &= 21.998\\\\\n  \\text{Error Margin} &= t_{\\alpha/2}(s/ \\sqrt{n})\\\\\n  &=t_{.05/2}(1.11702424230396/ \\sqrt{20})\\\\\n  &=t_{.025}(0.249774213830685)\\\\\n  &=2.093(0.249774213830685)\\\\\n  &=0.522783437718549\\\\\n  interval &= \\bar{x} \\pm \\text{Error Margin}\\\\\n  &= 21.998 \\pm 0.522783437718549\\\\\n  &= (21.4752165622814, 22.5207834377185)\n\\end{align*}\n\\end{document}", "meta": {"hexsha": "79ada36cbe1ef64a5838f33248429691795fb724", "size": 5507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework3_3.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/Homework3_3.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/Homework3_3.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": 39.618705036, "max_line_length": 432, "alphanum_fraction": 0.6769566007, "num_tokens": 1880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6429452261731039}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Optical flow}\r\nOptical flow is the task of describing how pixels move in an image, thus describing motion of surfaces or objects in an image. Mathematically, you calculate the motion at each pixel position between two frames at times $t$ and $t + \\Delta t$.\r\n\r\n\\subsection{Constraints}\r\nWe usually assume constant brightness between frames\r\n\\begin{equation}\r\n    I(x,y,t) = I(x + \\Delta x, y + \\Delta y, t + \\Delta t)\r\n\\end{equation}\r\nwhere $I(\\cdot)$ is image intensity. We also assume small motion\r\n\\begin{multline}\r\n    I(x + \\Delta x, y + \\Delta y, t + \\Delta t) =\\\\\r\n    I(x,y,z) + \\pd{I}{x}\\Delta x + \\pd{I}{y}\\Delta y + \\pd{I}{t} \\Delta t.\r\n\\end{multline}\r\nThis gives\r\n\\begin{equation}\r\n    \\pd{I}{x} V_x + \\pd{I}{y} V_y + \\pd{I}{t} = 0.\r\n\\end{equation}\r\n\r\nDetermining optical flow can be done in several ways. Sections \\ref{ssec:lucas-kanade} and \\ref{ssec:horn-schunck} describe differential methods.\r\n\r\n\\paragraph{Aperture problem} The aperture problem comes from the fact that what a camera sees is only a small part of the world. Motion inside of this frame may appear different than it really is, if the moving object is not contained in the frame.\r\n\r\n\\subsection{Lucas--Kanade (LK) method}\\label{ssec:lucas-kanade}\r\nLK tracks interest points in a scene from one frame to the next. Can use Harris corner points as the interest points. It assumes constant flow in a neighborhood of the pixel examined, and solves the optical flow equations by least squares. Using a neighborhood reduces ambiguities and improves noise performance. But being purely local, it cannot determine flow in the interior of uniform regions.\r\n\r\n\\subsection{Horn--Schunck (HS) method}\\label{ssec:horn-schunck}\r\nA method to estimate optical flow globally. It introduces a global smoothness constraint to solve the aperture problem. It minimizes distortion in flow globally, and prefers solutions that are smoother.\r\n\r\n\\subsection{Kanade--Lucas-Tomasi (KLT) feature tracker}\\label{ssec:kanade-lucas-tomasi}\r\nKLT is a computationally fast feature extraction method that is useful for tracking in realtime video.\r\n", "meta": {"hexsha": "a09e9d446f212cd66090d43af356f7b9a0b09694", "size": 2138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/optical-flow.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/optical-flow.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/optical-flow.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": 66.8125, "max_line_length": 398, "alphanum_fraction": 0.7464920486, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6429452145456459}}
{"text": "\\documentclass{article}\n\\input{preamble}\n\\begin{document}\n\\section{Noise Calculation}\n\nThe assumption is that the noise of a point source with flux $F$ has a variance \n obtained by quadratically adding the variance of a background $N_0^2$ and a quantity proportional to the Poisson Noise due to the source.\n\\be\nN^2 = N_0^2 + \\alpha F \n\\ee\nGiven a source Flux, the noise has two unknown quantities $\\alpha$ and $N_0$.\nTherefore, it is posible to eliminate one of these variables in terms of \nquantities at a standard SNR. Let us consider this standard SNR to be 5.\nThen, we have \n\\be\n\\frac{F_5^2}{N_0^2 + \\alpha F_5} = 25\n\\ee\nimplying we can eliminate \n\\be\n\\alpha = F_5 \\left( 0.04 - \\left(\\frac{N_0}{F_5}\\right)^2 \\right)\n\\ee\nAt the linear level, the noise in the magnitude $\\sigma_m$ is \n\\beqn\n\\sigma_m^2 &=& \\left(\\frac{2.5}{\\log{(10)}}\\right)^2 (N/F)^2 \\\\\n&\\approx& \\left(\\frac{N_0}{F }\\right)^2 + \\alpha \\left(\\frac{1}{F}\\right) \\\\\n&=& \\left(\\frac{N_0}{F_5}\\right)^2 \\left(F_5/F\\right)^2 + \\left( 0.04 - ({N_0/F_5})^2\\right) (F_5/F) \\\\\n&=& \\gamma x^2 + (0.04 - \\gamma) x\n\\eeqn\nWe could put back the initial missing factor $\\approx 1$ to get \n\\be\n\\sigma_m^2  = \\left(2.5/\\log{(10)}\\right)^2 \\left( \\gamma x^2  + (0.04 - \\gamma ) x \\right)\n\\ee\nwhere \n$\\gamma \\equiv \\left( N_0/ F_5 \\right)^2$ and $x \\equiv F_5/F = 10.0^{0.4(m-m_5)}.$ In terms of $\\gamma$ and $m_5,$ we may write the value of $\\alpha$:\n\\be\n\\alpha = 10.0^{-0.4 m_5} ( 0.04 - \\gamma)\n\\ee\nWe could write the Flux in terms of counts. This would be\n$$\nC_5 = \\frac{\\pi D^2 T_{exp}}{4 g h} F5\n$$\nThen, \n\\be\n\\gamma  = \\left(\\frac{\\pi D^2 T_{exp} N0}{4 g h C_5}\\right)^2\n\\ee\n% \\section{Rewrite}\n% We will consider PSF photometry of a point source as described in the SNR document using the estimator \n% \\be \n% \\hat{S} = \\sum w_i C_i \n% \\ee. Here, the physical signal is the Flux of an astrophysical point source in absolute units in a filter band. This means that number of counts $C$ and the variance of the estimator is \n% \\be\n% N^2 = C/g + N_0^2 \n% \\ee\n% where g is the gain \n\\end{document}\n", "meta": {"hexsha": "85683f8181b762d0710a8adb76350aaf379056fb", "size": 2054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "snsims_previous/docs/NoiseCalculation.tex", "max_stars_repo_name": "rbiswas4/SNsims", "max_stars_repo_head_hexsha": "8df1fec13bcb8b06cbb460663d96625854aa97fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-01T16:17:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-01T16:17:32.000Z", "max_issues_repo_path": "snsims_previous/docs/NoiseCalculation.tex", "max_issues_repo_name": "rbiswas4/SNsims", "max_issues_repo_head_hexsha": "8df1fec13bcb8b06cbb460663d96625854aa97fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 68, "max_issues_repo_issues_event_min_datetime": "2015-04-16T22:54:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-09T23:34:45.000Z", "max_forks_repo_path": "snsims_previous/docs/NoiseCalculation.tex", "max_forks_repo_name": "rbiswas4/SNsims", "max_forks_repo_head_hexsha": "8df1fec13bcb8b06cbb460663d96625854aa97fe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-02-10T19:19:04.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-05T20:45:39.000Z", "avg_line_length": 36.6785714286, "max_line_length": 188, "alphanum_fraction": 0.6684518014, "num_tokens": 764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6429323442085183}}
{"text": "\n\\section{Macaulay Notation}\n\nMacaulay Notation\\footnote{N.b. This should all be familiar to you from your 1st Year Solid Mechanics.} is a method used for the structural analysis of Euler-Bernoulli beams and describes the beam forces, moments and deflection. The method is particularly useful for discontinuous and/or discrete loading scenarios as well as loadings that are uniformly distributed loads (u.d.l.) and/or uniformly varying loads (u.v.l.) over the span of a beam.\n\nThe\\marginnote{Method} method starts with the Euler-Bernoulli beam theory and the relation between the deflection $w$ and bending moment $M$.\n\n\\begin{equation}\n  \\pm EI\\frac{\\text{d}^2 w}{\\text{d}x^2} = M\n\\end{equation}\n\n\\noindent Where $E$ is the elastic modulus and $I$ is the second moment of area.\n\nIn terms of Macaulay Notation, $M$ is expressed in the form:\n\n\\begin{equation}\n  M = M_1(x) + P_1\\langle x-a_1\\rangle^{b_1} + P_2\\langle x-a_2\\rangle^{b_2} + P_3\\langle x-a_3\\rangle^{b_3} + \\ldots\n\\end{equation}\n\n\\noindent Where $M_1$ is the moment at the start of $x$ and $P_i\\langle x-a_i\\rangle^{b_i}$ representing elements along the beam that contribute to the moment. These contribute to the scenario when $x$ becomes greater than $a_i$:\n\n\\begin{equation}\n  \\langle x - a_i\\rangle = \n  \\begin{cases} \n    0 & \\mathrm{if}~ x < a_i \\\\ \n    x - a_i & \\mathrm{if}~ x > a_i \n  \\end{cases}\n\\end{equation}\n\n\\noindent $b_i$ is determined by the type of loading that is being applied. \n\nFor\\marginnote{Shear Force} the shaft design exercise, you will be taking the shear forces and integrating them to get your bending moments for the two axes. For example, the Macaulay Notation for the Free Body Diagrams in \\cref{fig-fbd} are as follows:\n\\begin{equation}\n  S_v = R_{v1}\\langle x-x_1\\rangle^0 + F_{1}\\langle x-x_2\\rangle^0  + F_{2}\\langle x-x_3\\rangle^0 + R_{v2}\\langle x-x_4\\rangle^0\n\\end{equation}\n\\begin{equation}\n  S_h = F_{3}\\langle x-x_0\\rangle^0 + R_{h1}\\langle x-x_2\\rangle^0 + R_{h2}\\langle x-x_4\\rangle^0\n\\end{equation}\n\nFrom\\marginnote{Shear Force Diagram} these equations, the shear force diagrams for the two axes can be generated (\\cref{fig-sfd}).\n\n\\begin{figure*}[th!]\n    \n    \\hfill\n    \\subfloat[Vertical Shear]{\n        \\includestandalone[width=0.45\\textwidth, mode=buildnew]{03_macaulay_notation/vertical_shear}\n    }\n    \\hfill\n    \\subfloat[Horizontal Shear]{\n        \\includestandalone[width=0.45\\textwidth, mode=buildnew]{03_macaulay_notation/horizontal_shear}\n    }\n    \\hfill\n    \n    \\vspace{2em}\n    \\caption{Shear force diagrams}\n    \\label{fig-sfd}\n\\end{figure*}\n\n\nHaving\\marginnote{Bending Moment}  described the shear forces in Macaulay Notation, it is then the case of integrating and determining the constant of integration to arrive at an equation that describes the bending moment at any point through the beam.\n\\begin{equation}\n  M_v = \\int S_v = R_{v1}\\langle x-x_1\\rangle^1 + F_{1}\\langle x-x_2\\rangle^1  + F_{2}\\langle x-x_3\\rangle^1 + R_{v2}\\langle x-x_4\\rangle^1\n\\end{equation}\n\\begin{equation}\n  M_h = \\int S_h = F_{3}\\langle x-x_0\\rangle^1 + R_{h1}\\langle x-x_2\\rangle^1 + R_{h2}\\langle x-x_4\\rangle^1\n\\end{equation}\n\nUsing\\marginnote{Bending Moment Diagram} these equations, one can obtain the bending moment diagrams for the loaded beam (\\cref{fig-bmd}).\n\n\\begin{figure*}[th!]\n\n    \\hfill\n    \\subfloat[Vertical Bending]{\n        \\includestandalone[width=0.45\\textwidth, mode=buildnew]{03_macaulay_notation/vertical_bending}\n    }\n    \\hfill\n    \\subfloat[Horizontal Bending]{\n        \\includestandalone[width=0.45\\textwidth, mode=buildnew]{03_macaulay_notation/horizontal_bending}\n    }\n    \\hfill\n    \n    \\vspace{2em}\n    \\caption{Bending Moment Diagrams}\\label{fig-bmd}\n\\end{figure*}\n", "meta": {"hexsha": "263c31a7553a6656e34c443ff7916fb9b2494e0a", "size": 3712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03_macaulay_notation/section.tex", "max_stars_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_stars_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_stars_repo_licenses": ["MIT"], "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_macaulay_notation/section.tex", "max_issues_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_issues_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_issues_repo_licenses": ["MIT"], "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_macaulay_notation/section.tex", "max_forks_repo_name": "JamesGopsill/ShaftDesignCourseNotes", "max_forks_repo_head_hexsha": "0249e0804538237df58e5a7f99d039b35b30099d", "max_forks_repo_licenses": ["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.6705882353, "max_line_length": 445, "alphanum_fraction": 0.7249461207, "num_tokens": 1192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639065, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6429323221193618}}
{"text": "Software architecture is of central importance in any large software\nproject because it establishes predictable patterns of usage and\ndevelopment~\\cite{Shaw1996}. This section describes the essential\nstructural components of SymPy, provides justifications for the design\ndecisions that have been made, and gives example\nuser-facing code as appropriate.\n\n\\subsection{The Core}\n\\label{sec:core}\nA computer algebra system stores mathematical expressions as data structures.\nFor example, the mathematical expression $x + y$ is represented as a tree with\nthree nodes, $+$, $x$, and $y$, where $x$ and $y$ are ordered children of $+$.\nAs users manipulate mathematical expressions with traditional mathematical\nsyntax, the CAS manipulates the underlying data structures. Symbolic\ncomputations such as integration, simplification, etc.\\ are all functions that\nconsume and produce expression trees.\n\nIn SymPy every symbolic expression is an instance of the class\n\\texttt{Basic},\\footnote{Some internal classes, such as those used in the\n  polynomial submodule, do not follow this rule for efficiency reasons.} the\nsuperclass of all SymPy types providing common methods to all SymPy\ntree-elements, such as traversals. The children of a node in the tree are held\nin the \\texttt{args} attribute. A leaf node in the expression tree\nhas empty \\texttt{args}.\n\nFor example, consider the expression $xy + 2$:\n\\begin{verbatim}\n>>> x, y = symbols('x y')\n>>> expr = x*y + 2\n\\end{verbatim}\nBy order of operations, the parent of the expression tree for \\texttt{expr} is\nan addition. It is of type \\texttt{Add}. The child nodes of \\texttt{expr} are\n\\texttt{2} and \\texttt{x*y}.\n\\begin{verbatim}\n>>> type(expr)\n<class 'sympy.core.add.Add'>\n>>> expr.args\n(2, x*y)\n\\end{verbatim}\n\nDescending further down into the expression tree yields the full expression. For\nexample, the next child node (given by \\texttt{expr.args[0]}) is\n\\texttt{2}. Its class is \\texttt{Integer}, and it has an empty \\texttt{args}\ntuple, indicating that it is a leaf node.\n\\begin{verbatim}\n>>> expr.args[0]\n2\n>>> type(expr.args[0])\n<class 'sympy.core.numbers.Integer'>\n>>> expr.args[0].args\n()\n\\end{verbatim}\nSymbols or symbolic constants, like $e$ or $\\pi$, are other examples of\nleaf nodes.\n\\begin{verbatim}\n>>> exp(1)\nE\n>>> exp(1).args\n()\n>>> x.args\n()\n\\end{verbatim}\n\nA useful way to view an expression tree is using the \\texttt{srepr} function, which\nreturns a string representation of an expression as valid Python code\\footnote{\n\\label{note:dotprint}\nThe \\texttt{dotprint} function from the \\texttt{sympy.printing.dot} submodule\nprints output to dot format, which can be rendered with Graphviz to\nvisualize expression trees graphically.}\nwith all the nested class constructor calls to create the given expression.\n\\begin{verbatim}\n>>> srepr(expr)\n\"Add(Mul(Symbol('x'), Symbol('y')), Integer(2))\"\n\\end{verbatim}\n\nEvery SymPy expression satisfies a key identity invariant:\n\\begin{verbatim}\nexpr.func(*expr.args) == expr\n\\end{verbatim}\nThis means that expressions are\nrebuildable from their \\texttt{args}.\\footnote{\\texttt{expr.func} is used\ninstead of \\texttt{type(expr)} to allow the function of an expression to be\ndistinct from its actual Python class. In most cases the two are the same.}\nNote that in SymPy the \\texttt{==} operator represents exact\nstructural equality, not mathematical equality. This allows testing if any two\nexpressions are equal to one another as expression trees. For example, even\nthough ${(x + 1)}^2$ and $x^2 + 2x + 1$ are equal mathematically, SymPy gives\n\\begin{verbatim}\n>>> (x + 1)**2 == x**2 + 2*x + 1\nFalse\n\\end{verbatim}\nbecause they are different as expression trees (the former is a \\verb|Pow|\nobject and the latter is an \\verb|Add| object).\n\nAnother important property of SymPy expressions is that they are immutable.\nThis simplifies the design of SymPy, and enables expression interning. It also\nenables expressions to be hashed, which allows expressions to be used as keys\nin Python dictionaries, and is used to implement caching in SymPy.\n\nPython allows classes to override mathematical operators. The Python\ninterpreter translates the above \\texttt{x*y + 2} to, roughly,\n\\verb|(x.__mul__(y)).__add__(2)|. Both \\texttt{x} and \\texttt{y}, returned\nfrom the \\texttt{symbols} function, are \\texttt{Symbol} instances. The\n\\texttt{2} in the expression is processed by Python as a literal, and is\nstored as Python's built in \\texttt{int} type. When \\texttt{2} is passed to the\n\\verb|__add__| method of \\texttt{Symbol}, it is converted to the SymPy type\n\\verb|Integer(2)| before being stored in the resulting expression tree. In\nthis way, SymPy expressions can be built in the natural way using Python\noperators and numeric literals.\n\n%% TODO: describe how assumptions are implemented\n\n%%\n%% Extensibility\n\\subsection{Extensibility}\n\nWhile the core of SymPy is relatively small, it has been extended to a wide variety\nof domains by a broad range of contributors.\nThis is due, in part, to the fact that the same language, Python,\nis used both for the internal implementation and the external usage by users.\nAll of the extensibility capabilities available to\nusers are also utilized by SymPy itself. This eases the transition pathway from\nSymPy user to SymPy developer.\n\nThe typical way to create a custom SymPy object is to subclass an existing\nSymPy class, usually \\texttt{Basic}, \\texttt{Expr}, or \\texttt{Function}. As\nit was stated before, all SymPy classes used for expression trees should be\nsubclasses of the base class \\texttt{Basic}. \\texttt{Expr} is the\n\\texttt{Basic} subclass for mathematical objects that can be added and\nmultiplied together. The most commonly seen classes in SymPy are subclasses of\n\\texttt{Expr}, including \\texttt{Add}, \\texttt{Mul}, and \\texttt{Symbol}.\nInstances of \\texttt{Expr} typically represent complex numbers, but may also\ninclude other ``rings'', like matrix expressions. Not all SymPy classes are\nsubclasses of \\texttt{Expr}. For instance, logic expressions, such as\n\\verb|And(x, y)|, are subclasses of \\texttt{Basic} but not of\n\\texttt{Expr}.\\footnote{See section~\\ref{S-suppsec:Logic} of the supplementary\n  material for more information on the\n  \\texttt{sympy.logic} submodule.}\n\nThe \\texttt{Function} class is a subclass of \\texttt{Expr} which makes it\neasier to define mathematical functions called with arguments. This includes\nnamed functions like $\\sin(x)$ and $\\log(x)$ as well as undefined functions\nlike $f(x)$. Subclasses of \\texttt{Function} should define a\nclass method \\texttt{eval}, which returns an evaluated value for the function\napplication (usually an instance of some other class, e.g., a \\texttt{Number}),\nor \\texttt{None} if for the given arguments it should not be\nautomatically evaluated.\n\nMany SymPy functions perform various evaluations down the expression tree.\nClasses define their behavior in such functions by defining a relevant\n\\verb|_eval_|\\texttt{\\textit{*}} method. For instance, an object can indicate\nto the \\texttt{diff} function how to take the derivative of itself by defining\nthe \\verb|_eval_derivative(self, x)| method, which may in turn call\n\\texttt{diff} on its \\texttt{args}. (Subclasses of \\texttt{Function} should\nimplement the \\texttt{fdiff} method instead; it returns the derivative of the function\nwithout considering the chain rule.) The most common\n\\verb|_eval_|\\texttt{\\textit{*}} methods relate to the assumptions:\n\\verb|_eval_is_|\\texttt{\\textit{assumption}} is used to deduce\n\\textit{assumption} on the object.\n\nListing~\\ref{fig:gamma-example} presents an example of this extensibility. It\ngives a stripped down version of the \\texttt{gamma} function $\\Gamma(x)$ from\nSymPy. The methods defined allow it to evaluate itself on positive integer\narguments, define the real assumption, allow it to be rewritten in terms of\nfactorial (with \\verb|gamma(x).rewrite(factorial)|), and allow it to be\ndifferentiated. \\texttt{self.func} is used throughout instead of referencing\n\\texttt{gamma} explicitly so that potential subclasses of \\texttt{gamma} can\nreuse the methods.\n\n\\lstset{\n  basicstyle=\\ttfamily,\n}\n\n\\begin{lstlisting}[caption={A minimal implementation of \\texttt{sympy.gamma}.},label=fig:gamma-example]\nfrom sympy import Function, Integer, factorial, polygamma\n\nclass gamma(Function):\n    @classmethod\n    def eval(cls, arg):\n        if isinstance(arg, Integer) and arg.is_positive:\n            return factorial(arg - 1)\n\n    def _eval_is_real(self):\n        x = self.args[0]\n        # noninteger means real and not integer\n        if x.is_positive or x.is_noninteger:\n            return True\n\n    def _eval_rewrite_as_factorial(self, z):\n        return factorial(z - 1)\n\n    def fdiff(self, argindex=1):\n        from sympy.core.function import ArgumentIndexError\n        if argindex == 1:\n            return self.func(self.args[0])*polygamma(0, self.args[0])\n        else:\n            raise ArgumentIndexError(self, argindex)\n\\end{lstlisting}\nThe gamma function implemented in SymPy has many more capabilities than the\nabove listing, such as evaluation at rational points and series expansion.\n\n\n\\subsection{Performance}\n\\label{sec:performance}\n\nDue to being written in pure Python without the use of extension modules,\nSymPy's performance characteristics are generally poorer than that of\nits commercial competitors. For many applications,\nthe performance of SymPy, as measured by clock cycles, memory usage, and memory\nlayout, is sufficient.\nHowever, the boundaries for when SymPy's pure Python strategy becomes\ninsufficient are when the user requires handling of very long expressions or many\nsmall expressions. Where this boundray lies depends on the system at hand, but tends\nto be within the range of $10^4$--$10^6$ symbols for modern computers.\n\nFor this reason, a new project called SymEngine~\\cite{SymEngine} has been started.\nThe aim of this poject is to develop a library with better performance\ncharacteristics for symbolic manipulation. SymEngine is a pure C++ library,\nwhich allows it fine-grained control over the memory layout of expressions.\nSymEngine has thin wrappers to other languages (Python, Ruby,\nJulia, etc.). Its aim is to be the fastest symbolic manipulation library. Preliminary\nbenchmarks suggest that SymEngine performs as well as its commercial and\nopen source competitors.\n\nThe development version of SymPy has recently started to use SymEngine as an\noptional backend, initially in \\texttt{sympy.\\allowbreak{}physics.\\allowbreak{}mechanics} only.\nFuture work will involve\nallowing more algorithms in SymPy to use SymEngine as a backend.\n", "meta": {"hexsha": "769f1289a974bf4b6563c90674d158053f2b831a", "size": 10562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "architecture.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": "architecture.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": "architecture.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": 46.1222707424, "max_line_length": 103, "alphanum_fraction": 0.7693618633, "num_tokens": 2609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.6428272467371577}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{tikz}\n\\usetikzlibrary{shapes,arrows}\n\\usepackage{amsmath}\n\\usepackage{placeins}\n\\usepackage{amssymb}\n\n\\begin{document}\n\n\\title{SINGULAR VALUE DECOMPOSITION}\n\\date{}\n\\maketitle\n\nSingular Value Decomposition (SVD) is the factorization of any $m\\times n$ matrix $A$ as $A = U \\Sigma V^T$ where $U$ is a $m \\times m$ matrix made up of columns of mutually perpendicular unit vectors, $\\Sigma$ is a diagonal matrix of the same shape as $A$ and $V^T$ is a $n \\times n$ matrix made up of rows of mutually perpendicular unit vectors. \n\n\\section{Example}\n\nLet $A$ be a $2 \\times 3$ matrix as follows,\n\n\\begin{align*}\n\tA = \\begin{pmatrix}\n\t3  & 0 & 0 \\\\\n\t-8 & 0 & 3 \n\t\\end{pmatrix}\n\\end{align*}\n\nTo calculate unit vectors of $U$, eigenvalues and eigenvectors of $AA^T$ are calculated,\n\n\\begin{align*}\n\tAA^T &= \\begin{pmatrix}\n\t3  & 0 & 0 \\\\\n\t-8 & 0 & 3 \n\t\\end{pmatrix} \\begin{pmatrix}\n\t3 & -8 \\\\\n\t0 & 0 \\\\\n\t0 & 3\n\t\\end{pmatrix} \\\\\n\t&= \\begin{pmatrix}\n\t9 & -24 \\\\\n\t-24 & 73\n\t\\end{pmatrix}\n\\end{align*}\n\n$AA^T - \\lambda I$ must be singular if eigenvectors are non-zero. Hence,\n\n\\begin{align*}\n\t\\begin{vmatrix}\n\t9 - \\lambda             & -24          \\\\\n\t-24                     & 73 - \\lambda \n\t\\end{vmatrix}           & = 0          \\\\\n\t(9-\\lambda)(73-\\lambda) & = 576        \n\\end{align*}\n\nThis gives $\\lambda = 81, 1$ and $\\hat{u} = \\begin{pmatrix}\n\\frac{1}{\\sqrt{10}} \\\\\n\\frac{-3}{\\sqrt{10}}\n\\end{pmatrix},\\begin{pmatrix}\n\\frac{3}{\\sqrt{10}} \\\\\n\\frac{1}{\\sqrt{10}}\n\\end{pmatrix}$ respectively. \n\nAt this step, decomposition is as follows:\n\n\\begin{align*}\n\tA = (\\hat{u_1}, \\hat{u_2}) \\begin{pmatrix}\n\t\\sqrt{\\lambda_1} & 0                & 0 \\\\\n\t0                & \\sqrt{\\lambda_2} & 0 \n\t\\end{pmatrix} V^T \\\\\n\tA = \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} & \\frac{3}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}} & \\frac{1}{\\sqrt{10}}\n\t\\end{pmatrix}      \\begin{pmatrix}\n\t9                & 0                & 0 \\\\\n\t0                & 1                & 0 \n\t\\end{pmatrix} V^T \n\\end{align*}\n\nTo continue and calculate $V$, the relation $A\\hat{v_i} = \\sqrt{\\lambda_i}\\hat{u_i}$ is used. It is clear that $V$ is a $3 \\times 3$ matrix.\n\n\\begin{align*}\n\tA\\hat{v_1} &= \\sqrt{\\lambda_1}\\hat{u_1} \\\\\n\t\\begin{pmatrix}\n\t3  & 0 & 0 \\\\\n\t-8 & 0 & 3 \n\t\\end{pmatrix}\\hat{v_1} &= \\sqrt{81}\\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}}\n\t\\end{pmatrix} \\\\\n\t\\hat{v_1} &= \\begin{pmatrix}\n\t\\frac{3}{\\sqrt{10}} \\\\\n\t0 \\\\\n\t\\frac{-1}{\\sqrt{10}} \\\\\n\t\\end{pmatrix}\n\\end{align*}\n\nSimilarly,\n\n\\begin{align*}\n\tA\\hat{v_2} &= \\sqrt{\\lambda_2}\\hat{u_2} \\\\\n\t\\begin{pmatrix}\n\t3  & 0 & 0 \\\\\n\t-8 & 0 & 3 \n\t\\end{pmatrix}\\hat{v_2} &= \\sqrt{1}\\begin{pmatrix}\n\t\\frac{3}{\\sqrt{10}} \\\\\n\t\\frac{1}{\\sqrt{10}}\n\t\\end{pmatrix} \\\\\n\t\\hat{v_2} &= \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} \\\\\n\t0 \\\\\n\t\\frac{3}{\\sqrt{10}} \\\\\n\t\\end{pmatrix}\n\\end{align*}\n\nNotice that $\\hat{v_1}.\\hat{v_2}$ is zero. The choices for $\\hat{v_3}$ which must be perpendicular to both $\\hat{v_1}$ and $\\hat{v_2}$ are $(0, \\pm 1, 0)^T$ and both are admissible in the decomposition as follows,\n\n\\begin{align*}    \n\tA &= \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} & \\frac{3}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}} & \\frac{1}{\\sqrt{10}}\n\t\\end{pmatrix}      \\begin{pmatrix}\n\t9                    & 0                   & 0                    \\\\\n\t0                    & 1                   & 0                    \n\t\\end{pmatrix} \\begin{pmatrix}\n\t\\hat{v_1}            & \\hat{v_2}           & \\hat{v_3}            \n\t\\end{pmatrix}^T \\\\\n\tA &= \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} & \\frac{3}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}} & \\frac{1}{\\sqrt{10}}\n\t\\end{pmatrix}      \\begin{pmatrix}\n\t9                    & 0                   & 0                    \\\\\n\t0                    & 1                   & 0                    \n\t\\end{pmatrix} \\begin{pmatrix}\n\t\\frac{3}{\\sqrt{10}}  & \\frac{1}{\\sqrt{10}} & 0                    \\\\\n\t0                    & 0                   & \\pm 1                \\\\\n\t\\frac{-1}{\\sqrt{10}} & \\frac{3}{\\sqrt{10}} & 0                    \\\\              \n\t\\end{pmatrix}^T \\\\\n\t\\begin{pmatrix}\n\t3                    & 0                   & 0                    \\\\\n\t-8                   & 0                   & 3                    \n\t\\end{pmatrix} &= \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} & \\frac{3}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}} & \\frac{1}{\\sqrt{10}}\n\t\\end{pmatrix}      \\begin{pmatrix}\n\t9                    & 0                   & 0                    \\\\\n\t0                    & 1                   & 0                    \n\t\\end{pmatrix} \\begin{pmatrix}\n\t\\frac{3}{\\sqrt{10}}  & 0                   & \\frac{-1}{\\sqrt{10}} \\\\\n\t\\frac{1}{\\sqrt{10}}  & 0                   & \\frac{3}{\\sqrt{10}}  \\\\              \n\t0                    & \\pm 1               & 0                    \\\\    \n\t\\end{pmatrix}\n\\end{align*}\n\n\\section{Analysis}\n\nSVD can be visualized as follows:\n\n\\begin{align*}\n\tA_{m \\times n} &= \\begin{pmatrix}\n\t| & | & .. & | \\\\\n\t\\hat{u_1} & \\hat{u_2} & .. & \\hat{u_m} \\\\\n\t| & | & .. & | \\\\        \n\t\\end{pmatrix}_{m \\times m} \\begin{pmatrix}\n\t\\sqrt{\\lambda_1} & 0                & .. & 0                & 0 & .. & 0 \\\\\n\t0                & \\sqrt{\\lambda_2} & .. & 0                & 0 & .. & 0 \\\\\n\t0                & 0                & .. & 0                & 0 & .. & 0 \\\\\n\t0                & 0                & .. & \\sqrt{\\lambda_r} & 0 & .. & 0 \\\\ \n\t0                & 0                & .. & 0                & 0 & .. & 0 \\\\ \n\t.                & .                & .. & .                & . & .. & . \\\\\n\t.                & .                & .. & .                & . & .. & . \\\\       \n\t0                & 0                & .. & 0                & 0 & .. & 0 \\\\        \n\t\\end{pmatrix}_{m \\times n} \\begin{pmatrix}\n\t| & | & .. & | \\\\\n\t\\hat{v_1} & \\hat{v_2} & .. & \\hat{v_n} \\\\\n\t| & | & .. & | \\\\        \n\t\\end{pmatrix}_{n \\times n}^T \\\\\n\t&u_i \\perp u_j\\ \\forall\\ i \\neq j \\\\\n\t&v_i \\perp v_j\\ \\forall\\ i \\neq j \\\\\n\t&\\sqrt{\\lambda_1} \\geq \\sqrt{\\lambda_2} \\geq .. \\geq \\sqrt{\\lambda_r} > 0 \\\\ \n\t&r = rank(A)    \n\\end{align*}\n\nThe product of the last two matrices can be simplified as follows,\n\n\\begin{align*}\n\tA_{m \\times n} &= \\begin{pmatrix}\n\t|         & |         & .. & |         \\\\\n\t\\hat{u_1} & \\hat{u_2} & .. & \\hat{u_m} \\\\\n\t|         & |         & .. & |         \\\\        \n\t\\end{pmatrix}_{m \\times m} \\begin{pmatrix}\n\t\\sqrt{\\lambda_1} \\hat{v_1}^T \\\\\n\t\\sqrt{\\lambda_2} \\hat{v_2}^T \\\\    \n\t. \\\\\n\t. \\\\\n\t\\sqrt{\\lambda_r} \\hat{v_r}^T \\\\\n\t0 \\\\\n\t. \\\\\n\t. \\\\\n\t0 \\\\\n\t\\end{pmatrix}_{m \\times n}\n\\end{align*}\n\nleading to the representation of $A$ as a sum of $r$ rank-1 matrices as follows:\n\n\\begin{align*}\n\tA = \\sum_{i=1}^r \\sqrt{\\lambda_i}\\ \\hat{u_i}\\ \\hat{v_i}^T \n\\end{align*}\n\nMultiplying by $\\hat{v_j}$ on both sides,\n\n\\begin{align*}\n\tA\\ \\hat{v_j} = \\sum_{i=1}^r \\sqrt{\\lambda_i}\\ \\hat{u_i}\\ \\hat{v_i}^T\\ \\hat{v_j} \n\\end{align*}\n\nSince all the $\\hat{v_i}$s are mutually perpendicular to each other,\n\n\\begin{align*}\n\tA\\ \\hat{v_j} = \\sqrt{\\lambda_j} \\hat{u_j} \n\\end{align*}\n\nNote the similarity of this equation to the regular eigenvalue equation. The constraint of the same unit vector on both sides of the equation was let go in the return of universal applicability on any matrix whatsoever.\n\n\\section{Application: Matrix Compression}\n\nSubjecting the matrix in example above to the rank-1 breakdown equation,\n\n\\begin{align*}\n\tA &= \\sum_{i=1}^r \\sqrt{\\lambda_i}\\ \\hat{u_i}\\ \\hat{v_i}^T \\\\\n\t\\begin{pmatrix}\n\t3    & 0 & 0    \\\\\n\t-8   & 0 & 3    \n\t\\end{pmatrix} &= \\begin{pmatrix}\n\t2.7  & 0 & -0.9 \\\\\n\t-8.1 & 0 & 2.7  \\\\\n\t\\end{pmatrix} + \\begin{pmatrix}\n\t0.3  & 0 & 0.9  \\\\\n\t0.1  & 0 & 0.3  \n\t\\end{pmatrix}\n\\end{align*}\n\nNote that the first matrix on the right hand side is a resonable approximation of the matrix on the left hand side and the other matrix just represents minor tweaks.\n\n\\begin{align*}\n\t\\begin{pmatrix}\n\t3                   & 0 & 0                    \\\\\n\t-8                  & 0 & 3                    \n\t\\end{pmatrix} &\\approx \\begin{pmatrix}\n\t2.7                 & 0 & -0.9                 \\\\\n\t-8.1                & 0 & 2.7                  \\\\\n\t\\end{pmatrix} \\\\\n\t&\\approx \\sqrt{81} \\begin{pmatrix}\n\t\\frac{1}{\\sqrt{10}} \\\\\n\t\\frac{-3}{\\sqrt{10}}\n\t\\end{pmatrix} \\begin{pmatrix}\n\t\\frac{3}{\\sqrt{10}} & 0 & \\frac{-1}{\\sqrt{10}} \\\\\n\t\\end{pmatrix}\n\\end{align*}\n\nThe left hand side representation requires to store $mn$ entries while the right hand side only requires to store $k(m+n)$ entries. So if $k << m, n$, the right hand side is highly compressed. The right hand side is also a good approximation if k is of the order of the rank of the matrix. So for low-rank highly redundant matrices (example digital images), SVD can serve as a reasonable compression algorithm.\n \n\\section{Appendix} \n \n\\begin{align*}\n\tA    & = U\\Sigma V^T                \\\\\n\tAA^T & = U\\Sigma V^T V \\Sigma^T U^T \\\\\n\\end{align*} \n \nSince $V^TV = I$ and $\\Sigma$ is diagonal.\n\n\\begin{align*}\n\tAA^T & = U \\Sigma^2 U^T                                   \\\\\n\tAA^T & = \\sum_{i = 1}^r \\lambda_i\\ \\hat{u_i}\\ \\hat{u_i}^T \n\\end{align*}\n\nMultiplying both sides by $\\hat{u_j}$ and using the fact that all $u_i$s\nare mutually perpendicular to each other.\n\n\\begin{align*}\n\tAA^T\\ \\hat{u_j} & = \\sum_{i = 1}^r \\lambda_i\\ \\hat{u_i}\\ \\hat{u_i}^T \\ \\hat{u_j} \\\\\n\tAA^T \\hat{u_j}  & = \\lambda_j\\ \\hat{u_j}                                         \n\\end{align*}\n\nIt is clear that $\\hat{u}$s are eigenvectors of $AA^T$. Similarly, it can be seen that $\\hat{v}$s are eigenvectors of $A^TA$. \n\\end{document}\n", "meta": {"hexsha": "e25b225d5c2eb8a4f46f45f2863c4d6d0ae133f2", "size": 9442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Singular Value Decomposition/Singular Value Decomposition.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": "Singular Value Decomposition/Singular Value Decomposition.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": "Singular Value Decomposition/Singular Value Decomposition.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": 33.1298245614, "max_line_length": 410, "alphanum_fraction": 0.4917390383, "num_tokens": 3415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407017, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6428272436418881}}
{"text": "\\section{Problem Definition}\n\\label{section:problems}\n\nThe general problem of \\mcproblem\\ is to select the\nappropriate monitoring operations to reduce\nthe expected uncertainty after they are performed.\nStated formally:\n\n\\begin{problem}[\\mcproblem]\nGiven a transition matrix $P$ and an initial distribution of items $\\initial$,\nselect a set of up to $k$ monitoring operations \nto minimize the expected uncertainty $\\objective$. \n% $E[\\uncertainty]$\n\\end{problem}\n\nWe study variants of the problem --\neach defined for a specific type of monitoring operation.\n For simplicity, we refer to these problems\n with the same name as that of the operation type:\n\\variant{\\parentstransitions},\n\\variant{\\nodeitems},\n\\variant{\\childrentransitions}, \nand \\variant{\\edgetransitions}.\n\nFurthermore, as we saw in Section~\\ref{sec:setting},\nvariants\n\\variant{\\parentstransitions}\\ and\n\\variant{\\nodeitems} are equivalent: for the same set of nodes,\noperations of the first type\nreduce expected uncertainty as much as the second.\nTherefore, in what follows,\nwe treat only the variant of \\variant{\\nodeitems}, as  our claims apply directly to\n\\variant{\\parentstransitions}\\ as well.\n\n\\todo[MM]{One issue we have not addressed is how we go from \n$A_{_\\shortnodeitems}(S)$ to $A_{_\\shortparentstransitions}(S)$.\nDoes it affect our claims?}\n", "meta": {"hexsha": "f10e00dfcc7f5f78ca8b6c49adab83800c5ce5cd", "size": 1319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/SDM-2018/problems.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/problems.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/problems.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": 34.7105263158, "max_line_length": 83, "alphanum_fraction": 0.7778620167, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6427202240100374}}
{"text": "% Copyright 2017-2018 Paul Mitchener, licensed under GNU FDL v1.3\n% main author: \n%   Paul Mitchener\n% contributions by:\n%   Markus Pflaum\n\n\\section{The category of measurable spaces and functions}\\label{sec:category-measurable-spaces-functions}\n\\subsec{Definitions and first examples}\n\\begin{definition}\n  Let $\\Omega$ be a set. By an \\emph{algebra on} $\\Omega$ one understands a collection $\\salgA$ of subsets of $\\Omega$\n  or in other words an element $\\salgA\\in \\power{\\Omega}$ such that\n  \\begin{axiomlist}[A]\n  \\item $\\Omega \\in \\salgA$,\n  \\item for each $A\\in \\salgA$, the complement $\\complement A = \\Omega \\setminus A $ belongs to $\\salgA$,\n  \\item for each finite sequence $(A_k)_{k=1}^n$ of elements of $\\salgA$ the union $A= \\bigcup\\limits_{k=1}^n A_k$\n        belongs to $\\salgA$. \n  \\end{axiomlist}\n  If in addition \n  \\begin{axiomlist}[A]\n  \\setcounter{enumi}{3}\n  \\item for each sequence $(A_k)_{k\\in \\N}$ of elements of $\\salgA$ the union $A= \\bigcup\\limits_{k\\in\\N} A_k$\n        belongs to $\\salgA$,\n  \\end{axiomlist}\n  then the algebra $\\salgA$ is called a \\emph{$\\sigma$-algebra}.\n  A set $\\Omega$ equipped with a $\\sigma$-algebra $\\mathscr A$ is called a \n  \\emph{measurable space}.  The elements of $\\mathscr A$ are termed the \n  \\emph{measurable subsets} of $\\Omega$.\n\\end{definition}\n\n\\begin{proposition}\n  If $\\salgA$ is an algebra on a set $\\Omega$, the empty set and the intersection of finitely many\n  elements of $\\salgA$ lies in $\\salgA$.\n  If $\\salgA$ is a $\\sigma$-algebra on $\\Omega$, then the intersection of countably many\n  measurable sets is also measurable.\n\\end{proposition}\n\\begin{proof}\n  These facts follow immediately from the axioms and the set-theoretic de Morgan's laws. \n\\end{proof}\n\n\\begin{examples}\n\\begin{environmentlist}\n\\item Let $\\Omega$ be any set. Then the power set of $\\Omega$ is a $\\sigma$-algebra.  \n  The set $\\{ \\emptyset , \\Omega \\}$ is also a $\\sigma$-algebra. These are the  largest and smallest\n  $\\sigma$-algebra on $\\Omega$, respectively. \n\\item\n  Let $\\Omega$ be any set.  Let $\\mathscr A$ be the set of all sets $A\\subset \\Omega$ such that $A$ or $\\Omega \\backslash A$ is\n  a countable set.  Then $\\mathscr A$ is a $\\sigma$-algebra.\n\\end{environmentlist}\n\\end{examples}\n\n\\begin{remark}\n  Obviously, the set of algebras on a set $\\Omega$ and the set of $\\sigma$-algebras on $\\Omega$ are both ordered\n  by set-theoretic inclusion. When talking about a ``smaller`` $\\sigma$-algebra or a ``largest'' one we always\n  implicitely mean in regard to set-theoretic inclusion as underlying order relation.\n\\end{remark}\n\nThe following two results are extremely useful when constructing examples.\n\n\\begin{proposition}\n  Let $(\\salgA_i)_{i\\in I}$ a family of algebras on a set $\\Omega$.\n  Then the intersection\n  $\\salgA = \\bigcap\\limits_{i\\in I} \\salgA_i$ is an algebra on $\\Omega$.\n  If each of the $\\salgA_i$ is a $\\sigma$-algebra, then $\\salgA$ is so, too. \n\\end{proposition}\n\\begin{proof}\n  Assume first that each $\\salgA_i$ is an algebra on $\\Omega$. \n  Obviously, $\\Omega \\in \\salgA$ because  $\\Omega \\in \\salgA_i$ for all $i\\in I$.\n  Similarly, if $A  \\in \\salgA$, then $A \\in \\salgA_i$, hence $\\complement A \\in \\salgA_i$\n  for all $i\\in I$. Therefore $\\complement A $ is in the intersection\n  $\\salgA = \\bigcap\\limits_{i\\in I} \\salgA_i$. Now assume that $(A_k)_{k=1}^n$ is a finite\n  sequence of  sets belonging to $\\salgA$. Then $A_k \\in \\salgA_i$  for $k=1,\\ldots,n$ and all\n  $i\\in I$  which entails that $\\bigcup\\limits_{k=1}^n A_k$ is in each of the $\\salgA_i$, hence in the\n  intersection $\\salgA$. The latter argument also works under the condition that each $\\salgA_i$ is a $\\sigma$-algebra\n  to verify that for a sequence $(A_k)_{k\\in\\N}$  in $\\salgA$ the union $\\bigcup\\limits_{k\\in\\N} A_k$\n  is in $\\salgA$. So the proposition is proved. \n\\end{proof}\n\n\n\\begin{corollary}\n  Let $\\mathscr F$ be a collection of subsets of a set $\\Omega$.  Then there is a unique smallest $\\sigma$-algebra,\n  $\\sigma (\\mathscr F)$, on $\\Omega$ containing $\\mathcal F$.  It is called the \\emph{$\\sigma$-algebra} generated by\n  $\\mathscr F$.\n\\end{corollary}\n\n\\begin{proof}\n  Let ${\\mathcal M}$ be the family of all $\\sigma$-algebras which contain $\\mathscr F$.  The set of all subsets of $\\Omega$ is\n  certainly a $\\sigma$-algebra, so ${\\mathcal M} \\neq \\emptyset$.  Let $\\sigma (\\mathscr F)$ be the intersection of all\n  $\\sigma$-algebras in the family ${\\mathcal M}$.  By the preceding proposition $\\sigma (\\mathscr F)$ is a $\\sigma$-algebra.\n  Since every element of ${\\mathcal M}$ contains $\\mathscr F$, the intersection\n  $\\sigma (\\mathscr F) = \\bigcap\\limits_{\\salgA\\in \\mathcal{M}}\\salgA$ contains $\\mathscr F$ as well. By construction,\n  $\\sigma (\\mathscr F)$ is minimal with that property.\n\\end{proof}\n\n\\begin{example}\n  Let $X$ be a topological space.  The $\\sigma$-algebra, $\\mathscr B (X)$, generated by all open subsets of $X$ is called the\n  {\\em Borel $\\sigma$-algebra} on $X$. Its elements are the {\\em Borel measurable sets} or simply the {\\em Borel sets} of $X$.\n  Obviously all open and all closed sets of $X$ are Borel measurable, as are all countable unions of closed sets and countable\n  intersections of open sets.\n\\end{example}\n\n\n\n\\begin{example}\n\\begin{environmentlist}\n\\item All intervals including the half-open intervals $[a,b)$ and $(a,b]$ with $a<b$ are Borel subsets of $\\R$.\n\\item If $X$ is a topological space with the discrete topology, then every subset of $X$ is Borel measurable.\n\\item If $X$ is a topological space carrying the topology $\\{ X ,\\emptyset \\}$, then the $\\sigma$-algebra\n      of Borel sets is the set $\\mathscr B = \\{ X , \\emptyset \\}$.\n\\end{environmentlist}\n\\end{example}\n\n\n\n\\begin{definition}\nLet $\\Omega$ be a measurable space, and $Y$ a topological space.  A map $f\\colon \\Omega \\rightarrow Y$ is termed {\\em measurable} if the set $f^{-1}[U]$ is measurable for every open subset $U\\subseteq Y$.\n\\end{definition}\n\n\\begin{proposition} \\label{ime}\nLet $f\\colon \\Omega \\rightarrow Y$ be a measurable function.  Then the inverse image $f^{-1}[B]$ is measurable whenever $B\\subseteq Y$ is a Borel set.\n\\end{proposition}\n\n\\begin{proof}\nLet $\\mathcal M$ be the collection of all subsets $E\\subseteq Y$  such that the inverse image $f^{-1}[E] \\subseteq \\Omega$ is measurable.  It is easy to check the axioms required to show that $\\mathcal M$ is a $\\sigma$-algebra.\n\nSince the function $f$ is measurable, the $\\sigma$-algebra $\\mathcal M$ contains all open sets of $Y$, and therefore all Borel sets.  Thus, by definition of the $\\sigma$-algebra $\\mathcal M$, the set $f^{-1}[B]$ is measurable whenever $B$ is a Borel set.\n\\end{proof}\n\n\\begin{definition}\nLet $f\\colon X\\rightarrow Y$ be a mapping between topological spaces.  If $f$ is measurable with respect to the $\\sigma$-algebra of all Borel sets in $X$, then we call $f$ a Borel function.\n\\end{definition}\n\nThus a function is a Borel function if the inverse image of any open set is a Borel set.  In particular, any continuous function is a Borel function.\n\n\\begin{proposition} \\label{cm}\nLet $f\\colon \\Omega \\rightarrow X$ be a measurable function, and let $g\\colon X\\rightarrow Y$ be a Borel function.  Then the composite $g\\circ f \\colon \\Omega \\rightarrow Y$ is measurable.\n\\end{proposition}\n\n\\begin{proof}\nLet $U\\subseteq Y$ be an open set.  Then the inverse image $g^{-1}[U]$ is a Borel set, so by proposition \\ref{ime} the inverse image $(g\\circ f)^{-1}[U]$ is measurable.\n\\end{proof}\n\nAs a corollary, the composite of a measurable and a continuous function is measurable.\n\n\\begin{example} \\label{char}\n  Let $X$ be a measure space, and let $E\\subseteq X$ be a measurable set.  Then the function\n  $\\chi_E \\colon X\\rightarrow {\\mathbb C}$ given by the formula\n  $$\\chi_E (x) = \\left\\{ \\begin{array}{ll} 1 & x\\in E \\\\\n  0 & x\\not\\in E \\\\\n  \\end{array} \\right.$$\nis measurable.\n\\end{example}\n\nThe function $\\chi_E$ is called the {\\em characteristic function} of $E$.\n\n\\subsec{Algebras of real and complex valued Borel measurable functions}\n\n\\begin{proposition} \\label{2dm}\nLet $u,v\\colon X\\rightarrow {\\mathbb R}$ be measurable functions, and let $\\Phi \\colon {\\mathbb R}^2 \\rightarrow Y$ be continuous.  Define a function $h\\colon X\\rightarrow Y$ by the formula\n$$h(x) = \\Phi (u(x),v(x))$$\nThen the function $h$ is measurable.\n\\end{proposition}\n\n\\begin{proof}\nDefine $f\\colon X\\rightarrow {\\mathbb R}^2$ by the formula $f(x) = (u(x),v(x))$.  In view of proposition \\ref{cm} it suffices to prove that the function $f$ is measurable.  Observe that:\n$$f^{-1}((a,b)\\times (c,d)) = u^{-1}(a,b)\\cap v^{-1}(c,d)$$\nso the inverse image $f^{-1}((a,b)\\times (c,d))$ is measurable since $u$ and $v$ are measurable functions.\n\nBut every open set $U\\subseteq {\\mathbb R}^2$ is a countable union of rectangles of the form $(a,b)\\times (c,d)$.  The $\\sigma$-algebra axioms thus ensure that the inverse image $f^{-1}[U]$ is measurable whenever $U\\subseteq {\\mathbb R}^2$ is an open set.\n\\end{proof}\n\nThe above proposition and proof still function if the function $\\Phi$ is a Borel function rather than a continuous function.\n\n\\begin{corollary} \\label{comM}\nLet $f\\colon X\\rightarrow {\\mathbb C}$ be a function on a measurable space $X$.  Then the function $f$ is measurable if and only if the functions $\\Re (f)$ and $\\Im (f)$ are measurable.\n\\end{corollary}\n\n\\begin{proof}\nLet $u,v\\colon X\\rightarrow {\\mathbb R}$ be measurable functions.  Define $\\Phi \\colon {\\mathbb R}^2\\rightarrow {\\mathbb C}$ by the formula $\\Phi (x,y) = x+iy$.  Then the function $u+iv$ is measurable by proposition \\ref{2dm}.\n\nThe converse follows immediately from proposition \\ref{cm} since the functions $\\Re$ and $\\Im$ are continuous.\n\\end{proof}\n\n\\begin{corollary} \\label{sum}\nLet $f,g\\colon X\\rightarrow {\\mathbb C}$ be measurable functions.  Then the functions $f+g$ and $fg$ are measurable.\n\\end{corollary}\n\n\\begin{proof}\nIn view of corollary \\ref{comM} it suffices to prove this result for real-valued measurable functions.  If we define continuous functions $\\Phi_1,\\Phi_2 \\colon {\\mathbb R}^2\\rightarrow {\\mathbb R}$ by the formulae $\\Phi_1 (s,t)=s+t$ and $\\Phi_2 (s,t)=st$, then the result follows immediately from proposition \\ref{2dm}\n\\end{proof}\n\n\n\n\\begin{proposition}\nLet $f\\colon X\\rightarrow {\\mathbb C}$ be a measurable function.  Then the function $|f|$ is measurable, and there is a measurable function $\\alpha \\colon X\\rightarrow {\\mathbb C}$ such that $|\\alpha (x)| =1$ for all $x\\in X$, and $f=\\alpha |f|$.\n\\end{proposition}\n\n\\begin{proof}\nLet $E = \\{ x\\in X \\ |\\ f(x)=0 \\}$.  Then the set $E$ is the inverse image of a closed subset, and so measurable.  We can define a continuous function $\\varphi \\colon {\\mathbb C}\\backslash \\{ 0\\} \\rightarrow {\\mathbb C}$ by the formula $\\varphi (z) = z/|z|$.  It follows from example \\ref{char}, corollary \\ref{sum}, and proposition \\ref{cm} that the function $\\alpha \\colon X\\rightarrow {\\mathbb C}$ defined by the formula\n$$\\alpha (x) = \\varphi (f(x) + \\chi_E (x))$$\nis measurable.  The formulae $|\\alpha (x)| =1$ and $f=\\alpha |f|$ are easy to check.\n\\end{proof}\n\n\\subsec{Measurable functions to the extended real line}\n\n\\begin{definition}\nLet $(a_n)$ be a sequence of real numbers.  Then we define\n$${\\lim \\sup}_{n\\rightarrow \\infty} a_n = {\\lim \\sup}_{n\\rightarrow \\infty} \\{ a_n , a_{n+1} , a_{n+2} , \\ldots \\}$$\nand\n$${\\lim \\inf}_{n\\rightarrow \\infty} a_n = {\\lim \\inf}_{n\\rightarrow \\infty} \\{ a_n , a_{n+1} , a_{n+2} , \\ldots \\}$$\n\\end{definition}\n\nWe can pass from results about $\\lim \\sup$ to results about $\\lim \\inf$, or conversely, by the observation\n$${\\lim \\sup}_{n\\rightarrow \\infty} a_n = - {\\lim \\inf}_{n\\rightarrow \\infty} (-a_n)$$\n\nIt will occasionally be convenient to us to allow $\\infty$ and $-\\infty$ as values of limits and functions.  This is a safe enough option provided we do not attempt to do arithmetic with these symbols; for example, expressions such as `$\\infty - \\infty$' are completely meaningless.\n\nHowever, we can form `intervals'\n$$[a,\\infty ] = [a ,\\infty )\\cup \\{ \\infty \\}  \\qquad [\\infty ,b] = (\\infty ,b]\\cup \\{ \\infty \\}$$\nand so on.  These intervals are topological spaces.  We can also allow ourselves the inequality\n$$-\\infty < a < \\infty$$\nfor all $a\\in {\\mathbb R}$.  The standard result about $\\lim \\sup$ and $\\lim \\inf$ can now be expressed quite simply; although a number of special cases need to be examined in the proof.\n\n\\begin{theorem}\nLet $(a_n)$ be a real-valued sequence.  Then the limits\n$${\\lim \\inf}_{n\\rightarrow \\infty} a_n \\in [-\\infty , \\infty ) \\qquad {\\lim \\sup}_{n\\rightarrow \\infty} a_n \\in (-\\infty , \\infty ]$$\nexist and satisfy the inequality\n$${\\lim \\inf}_{n\\rightarrow \\infty} a_n \\leq {\\lim \\sup}_{n\\rightarrow \\infty} a_n$$\n\nFurther, the equality\n$${\\lim \\inf}_{n\\rightarrow \\infty} a_n = a = {\\lim \\sup}_{n\\rightarrow \\infty} a_n$$\nholds precisely when the sequence $(a_n)$ converges to the real number $a$.\n\\textbf{proof to be filled in!}\n\\end{theorem}\n\nNote that the number $a$ in the above result must be finite.\n\n\\begin{proposition}\nLet $\\Omega$ be a measurable space, and let $f\\colon \\Omega \\rightarrow [\\infty , \\infty]$ be any map.  Suppose that the inverse image $f^{-1}((\\alpha , \\infty ])$ is measurable for every point $\\alpha \\in {\\mathbb R}$.  Then the function $f$ is measurable.\n\\end{proposition}\n\n\\begin{proof}\nLet\n$${\\mathcal M} = \\{ E\\subseteq [-\\infty ,\\infty]\\ |\\ f^{-1}[E] \\textrm{ is measurable } \\}$$\n\nBy proposition \\ref{ime} the set $\\mathcal M$ is a $\\sigma$-algebra.  Choose points $\\alpha \\in {\\mathbb R}$ and $\\alpha_n < \\alpha$ such that $\\lim_{n\\rightarrow \\infty} \\alpha_n = \\alpha$.  Since the set $(\\alpha_n , \\infty ]$ is measurable by hypothesis, and\n$$[-\\infty , \\alpha ) = \\bigcup_{n=1}^\\infty [-\\infty , \\alpha_n ] = \\bigcup_{n=1}^\\infty [-\\infty , \\infty ]\\backslash (\\alpha_n , \\infty]$$\nit follows that $[-\\infty , \\alpha )\\in \\Omega$.  Hence\n$$(\\alpha , \\beta ) = [-\\infty , \\beta ) \\cap (\\alpha , \\infty ] \\in \\Omega$$\nfor every point $\\alpha , \\beta \\in {\\mathbb R}$.  Since every open set in $[-\\infty , \\infty ]$ is a countable union of such open intervals, the collection $\\mathcal M$ contains every open set.  Thus the map $f$ is measurable.\n\\end{proof}\n\n\\begin{corollary}\nLet $f_n\\colon X\\rightarrow [-\\infty , \\infty]$ be measurable functions for $n\\in {\\mathbb N}$.  Then the functions\n$$\\sup \\{ f_n \\} \\quad {\\lim \\sup}_{n\\rightarrow \\infty} f_n \\quad \\inf \\{ f_n \\} \\quad {\\lim \\inf}_{n\\rightarrow \\infty} f_n$$\nare measurable.\n\\end{corollary} \n\n\\begin{proof}\nLet $a\\in {\\mathbb R}$.  Observe that the set\n$$(\\sup \\{ f_n \\})^{-1} (a,\\infty ] = \\bigcup_{n=1}^\\infty f_n^{-1}(a,\\infty ]$$\nis measurable.  Hence by the above proposition, the function $\\sup \\{ f_n \\}$ is measurable.  The formula $\\inf \\{ f_n \\} = - \\sup \\{ -f_n \\}$ tells us that the function $\\inf \\{ f_n \\}$ is also measurable.\n\nNow, for each point $x\\in \\Omega$, the sequence of numbers\n$$g_n (x) = \\sup \\{ f_n (x) , f_{n+1} (x) , f_{n+2}(x) , \\ldots \\}$$\nis monotonic increasing.  It follows that\n$${\\lim \\sup }_{n\\rightarrow \\infty} f_n (x) = \\inf \\{ g_n (x) \\}$$\n\nWe know that each function $f_n$ is measurable.  The above argument tells us that each function $g_n$ is measurable, and that the function ${\\lim \\sup}_{n\\rightarrow \\infty}f_n$ is measurable.  A similar argument tells us that the function ${\\lim \\inf}_{n\\rightarrow \\infty}g_n$ is measurable.\n\\end{proof}\n\n\n\\begin{corollary}\nIf $f,g\\colon X\\rightarrow [-\\infty, \\infty ]$ are measurable functions, then so are the functions $\\max \\{ f,g \\}$ and $\\min \\{ f,g \\}$.\n\\textbf{proof to be filled in!}\n\\end{corollary}\n\n\\begin{corollary}\nThe limit of a pointwise-convergent sequence of meaurable functions is measurable.\n\\textbf{proof to be filled in!}\n\\end{corollary}\n", "meta": {"hexsha": "4796a612cfb90dea2c7bb547b3eac0fda316ce29", "size": 15718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/category-measurable-spaces-functions.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/category-measurable-spaces-functions.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/category-measurable-spaces-functions.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": 55.9359430605, "max_line_length": 423, "alphanum_fraction": 0.6897824151, "num_tokens": 5059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6427202194511226}}
{"text": "\\section[Basics in probability theory]{Lecture 3: Basics in probability theory}\n\n\\subsection{Discrete random variables}\n\nHere we will shortly define random variables which is the basis of understanding probability. We will first focus on discrete random variables since we have an intuitive understanding of probability from everyday life situations, e.g. when we toss a coin or role a die. \nA random variable is a variable which is subject to random effects, i.e. other than having a fixed value it can take on different values each associated with a probability. In order to specify a random variable we define a probability space $(\\Omega, E, P)$. $\\Omega$ is called the sampling space i.e. the set of all possible outcomes (states) of a random process. In the case of a single coin toss we can define $\\Omega = \\lbrace H , T\\rbrace$ as the set which respresents Heads and Tails of the toss. $E$ is the set of all possible events where each event is a subsest of $\\Omega$, we write $ E_i \\subseteq \\Omega $. Based on the possible events we define a function $P$ which maps possible events to a probability measure $P: E \\rightarrow [0,1]$. This probability measure represents the likelihood of an event happening in an experiment. We say that for the conjunction of all disjoint subsets of E our probability is normalized, i.e. it sums to one: $(\\forall E_i \\cap E_j = \\emptyset): P(\\cup_i E_i) = 1$. This is equivalent to saying that $P(\\Omega) = 1$. For some examples on how to utilize the probability space see the example box below. \\\\\n\n\\begin{bbbox}{Discrete random variables}\n\t\\begin{small}\n\t\\begin{tabularx}{\\textwidth}{|l|l|l|X|X|} %{| l | l | l | p{5cm} | p{5cm} |}\n\t\\hline\n\tExample & Distribution & $\\Omega$ & $E$ & $P(X=x)$ \\\\ \\hline\n\tCoin Flip & Bernoulli & $\\lbrace H, T \\rbrace$ & $\\lbrace \\rbrace$ , $\\lbrace H \\rbrace$ , $\\lbrace T \\rbrace$ , $\\lbrace H,T \\rbrace$ & $P(X = H) = P(X = T) = 0.5$ \\\\ \\hline\n\tDie Roll & Categorical & $\\lbrace 1,2,3,4,5,6 \\rbrace $ & $\\lbrace \\mbox{\"even number\"} \\rbrace$ , $\\lbrace 5,6 \\rbrace $ & $P(X = x) = \\frac{1}{6}$ ; $P(X = \\{5,6\\}) = P(X = 5) + P(X = 6))$ \\\\ \\hline\n\tSpike count & Poisson & $ \\lbrace 1,2,... \\rbrace $ & $\\lbrace 0 \\rbrace$ , $\\lbrace \\mbox{\"at least one\"} \\rbrace $ & $P(X = 0) = \\mbox{e}^{-\\lambda}$; $P(X > 0) = 1-\\mbox{e}^{-\\lambda}$ \\\\ \\hline\n\t\n\t\\end{tabularx}\n\t\\end{small}\n\\end{bbbox}\n\nIn the case of a discrete random variable $P$ is called a probability mass function (pmf). Since discrete random variables have a countable or finite number of states, or $X: \\Omega \\rightarrow \\mathbb{N}$, the pmf directly assigns a probability to each possible event. We will later see that this is not the case for the $P$ of continuous random variables. In literature there is a redundancy in the notation of the pmf and it is useful to know that some of the expressions used are equivalent:\n\n\\begin{itemize}\n\\item %Rules: \n\\begin{align}\nP(X=x)&=P_X(x)=P(x)\\\\\nP(x)&\\geq 0 \\mbox{ for each } x\\\\\n\\sum_{x \\in \\Omega} P(x)&=1\\\\\nP(A) = P(x \\in A) &=\\sum_{x \\in A} P(X=x)\\\\\n\\end{align}\n\\item We write: $X|q \\sim \\mbox{Binomial}(q)$\n\\end{itemize}\n\n\\subsection{Moments and Expectations}\n\\begin{itemize}\n\\item Expectation (or mean): $E(X)= \\sum_{x} P(X=x) x$ \n\\end{itemize}\n\n\\begin{bbbox}{Expectation of a discrete random variable}\n\tThe expectation of a discrete random variable is the weighted sum over all possible states of the random variable, where the weights are the probabilities of the respective state.\\\\\n\t\n\tExamples: fair coin; fair die; \\\\\n\t\\begin{flalign*}\n\t\t&\\text{Fair coin: } & E(coin) & = P(coin=1)\\times1 + P(coin=0)\\times0 = \\frac{1}{2} \\\\\n\t\t&\\text{Fair die: } & E(die) & = 1\\times\\frac{1}{6} + 2\\times\\frac{1}{6} + \\dots + 6\\times\\frac{1}{6} = 3.5 \\\\\n \t\t&\\text{Poisson with rate } \\lambda \\text{: } & E(X) & = \\sum_{x = 1}^{\\infty} (x) \\frac{1}{\\underbrace{x!}_{(1 \\times 2 \\times \\dots \\times x)}} \\mbox{e}^{-\\lambda} \\lambda^x \\\\\n\t\t& & & = \\sum_{x = 1}^{\\infty} \\frac{1}{(x-1)!} \\mbox{e}^{-\\lambda} \\lambda^{x-1} \\lambda \\\\\n\t\t& & & = \\lambda \\sum_{x = 1}^{\\infty} \\frac{1}{(x-1)!} \\mbox{e}^{-\\lambda} \\lambda^{x-1} \\\\\n\t\t& & & = \\lambda \\underbrace{\\sum_{y = 0}^{\\infty} \\frac{1}{(y)!} \\mbox{e}^{-\\lambda} \\lambda^{y}}_{ = 1} \\;\\; \\vert (y = x+1) \\\\\n\t\t& & & = \\lambda\n\t\\end{flalign*}\n\t\n\\end{bbbox}\n\n\\begin{itemize}\n\\item Expectation of a function:  $E(f(X))= \\sum_{x} P(X=x) f(x)$ \n\\item Moments= expectation of power of $X$: $M_k= E(X^k)$\n\\end{itemize}\n\n\\begin{bbbox}{Example: 2nd order moment}\n\tWe want to calculate the expectation of $Die^2$ for a fair die: \\\\\n\t\\begin{align*}\n\t\tE(Die^2) &= \\sum_{x = 1}^6 P(Die = x) x^2 \\\\\n\t\t\t\t &= \\frac{1}{6} (1 + 2 + 9 + 16 + 25 + 36) \\\\\n\t\t\t\t &= \\frac{1}{6} 89 \\\\\n\t\t\t\t &\\approx 14.66\t\t\t \n\t\\end{align*}\n\\end{bbbox}\n\n\\begin{itemize}\n\\item Variance: Average (squared) fluctuation from the mean\n\\begin{align}\n \\mbox{Var}(X)&= E((X-E(X))^2)\\\\\n &= E(X^2)- E(X)^2\\\\\n &= M_2-M_1^2\n\\end{align}\n\\end{itemize}\n\n\\begin{bbbox}{Variance}\nThe alternative definition of variance based on moments directly emerges from the linearity of the expectation:\n\t\\begin{align*}\n\t\tVar(X) = E((X - E(X))^2) &= E(X^2 - 2 \\times X \\times E(X) + E(X)^2) \\\\\n\t\t\t\t\t\t&= E(X^2) - 2 \\times E(X \\times E(X)) + E(X)^2 \\\\\n\t\t\t\t\t\t&= E(X^2) - 2 \\times E(X) \\times E(X) + E(X)^2 \\\\\n\t\t\t\t\t\t&= E(X^2) - E(X)^2\n\t\\end{align*}\n\\end{bbbox}\n\n\\begin{bbbox}{Why do we use the squared fluctuations from the mean for the mesaure of variance?}\n\t\n\t\\begin{itemize}\n\t\t\\item Average deviations from the mean: \\\\\n\t\t\t  $Var(X) = E(X-E(X)) = E(X) - E(X) = 0$ \\\\\n\t\t\t  As we see this measure is always zero and therefore useless for our purpose.\n\t\t\\item Average abolute deviations from the mean: \n\t\t\t  \\\\$Var(X) = E(|X-E(X)|)$ \\\\\n\t\t\t  However this measure can sometimes be technically difficult and is less used in practice.\n\t\\end{itemize}\n\n\\end{bbbox}\n\n\\begin{itemize}\n\\item Standard devation: Square root of variance.\n\\item Illustration and examples: [on board]\nAside: Difference between expectation/variance of random variable and empirical average/variance.\n\n\\end{itemize}\n\n\\subsection{Probability rules}\nThe course will be focused on Bayesian statistics and in that context we will be constantly using Bayes' rule. In this section we will show that Bayes' rule strictly follows from the definition of conditional probabilities. We have seen that we can measure the probability of an event $A$ with $P(A)$. Further we can measure the probability of two events $A$ and $B$ with P(A,B). We call this the joint probability of the events $A$ and $B$\n\n\\begin{align}\n\tP(B|A) = \\frac{P(A|B) P(B)}{P(A)}\n\\end{align}\n\nwhere $P(B|A)$ is the posterior probability of an event $B$ given we have knowledge about an event $A$. It is straightforward to show from the definition of conditional probabilities that Bayes' rule holds. We define the conditional probability of an event $B$ given knowledge about and event $A$ as\n\n\\begin{align}\n\tP(B|A) = \\frac{P(A,B)}{P(A)}\n\\end{align}\n\nwhere $P(A,B)$ is the  probability of observing events $A$ and $B$, we call this the joint probability of $A$ and $B$. And $P(A)$ is the probability of observing and event $A$. We can  \n\n\\begin{exbox}{It is cold today, will we have rain?}\nWe will consider the example of interactions between rain and temperature in T\\\"ubingen. Lets say we have made $N = 30$ independent measurements of the weather conditions in T\\\"ubingen. We arbitrarily chose to divide our observations based on the temperature and whether it was raining or not. The table below reflects the number of times we made observations under a given condition, e.g. the number of observations when the temperature was below  $10\\,^{\\circ}\\mathrm{C}$ and it was not raining was $N_{(T=0,R=0)} = 10$. \\\\\n\t\\begin{tabular}{ll|c|c|r}\n\t\t\t& & Rain & No Rain \\\\\n\t\t\t& & $R = 1$ & $R = 0$ & $\\sum_R$ \\\\ \\hline\n\t\tTemp $> 20\\,^{\\circ}\\mathrm{C}$: & $T = 2$ & $1$ & $3$ & 4\\\\ \\hline\n\t\t$10\\,^{\\circ}\\mathrm{C} <$ Temp $< 20\\,^{\\circ}\\mathrm{C}$: & $T = 1$ & $4$ & $8$ & 12\\\\ \\hline\n\t\tTemp $< 10\\,^{\\circ}\\mathrm{C}$: & $T = 0$ & $4$ & $10$ & 14\\\\ \\hline\n\t\t\t& $\\sum_T$ & 9 & 21 \\\\\n\t\\end{tabular}\nWe can easily see that the sum over all observations is $N = 30$ again. If we now want to calculate the probability of the temperature being below $10\\,^{\\circ}\\mathrm{C}$ and there being no rain, we can simply do $P(T=0,R=0) = \\frac{N_{(T=0,R=0)}}{N} = \\frac{1}{3}$. We call this the \\textbf{probability} of events $T=0$ and $R=0$. This can be done for all possible events.\\\\\nLets say we know the temerature is between $10$ and $20\\,^{\\circ}\\mathrm{C}$ and we want to know how likely it is to rain. We can utilize the \\textbf{conditional probability} $P(R=1|T=1)$\n\\end{exbox}\n\n\\begin{defbox}{Probability rules}\n\t\\begin{itemize}\n\t\\item {Joint distribution:} $P(X=x, Y=y)$, a list of all probabilities of all possible pairs of observations\n\t\\item {Marginal distribution:} $P(X=x)=\\sum_y P(X=x, Y=y) $\n\t\\item {Conditional distribution:} $P(X=x|Y=y) = \\frac{P(X=x, Y=y)}{P(y=y)}$\n\t\\item $X |Y$ has distribution $P(X|Y)$, where $P(X|Y)$ specifies a 'lookup-table' of all possible $P(X=x| Y=y)$\n\t\\end{itemize}\n\\end{defbox}\n\n\\begin{itemize}\n\\item {Conditional probability:} 'Recalculated probability of event A after someone tells you that event A happened.' \n\\begin{align}\nP(A|B)&= \\frac{P(A \\cap B)}{P(B)}\\\\\nP(A \\cap B)&= P(A|B) P(B)\n\\end{align}\n\\item Examples: Rolls of a die\n [on board]\n\\item Bayes Rule: \n\\begin{align}\nP(B|A) = \\frac{P(A|B) P(B)}{P(A)}\n\\end{align}\n\\end{itemize}\n\n\\begin{itemize} \n\\item Example [on board]     \n\\item {Joint distribution:} $P(X=x, Y=y)$, a list of all probabilities of all possible pairs of observations\n\\item {Marginal distribution:} $P(X=x)=\\sum_y P(X=x, Y=y) $\n\\item {Conditional distribution:} $P(X=x|Y=y) = \\frac{P(X=x, Y=y)}{P(y=y)}$\n\\item $X |Y$ has distribution $P(X|Y)$, where $PX(|Y)$ specifies a 'lookup-table' of all possible $P(X=x| Y=y)$\n\\end{itemize}\nConditioning and marginalization come up in Bayesian inference ALL the time: 'Condition on what you observe. Marginalize out the uncertainty'.\n\n\\subsection{Independence of random variables}\n\n\\begin{itemize}\n \\item Intuitively, two {events are independent} if knowing that the first took places tells us nothing about the probability of the second:  $P(A|B)= P(A)$\n \\item  $P(A) P(B)= P(A \\cap B)$\n \\item  Two {random variables} are independent if the joint p.m.f. is the product of the marginals: $P(X=x,Y=y)=P(X=x) P(Y=y)$. \n \\item If $X$ and $Y$ are independent, we write $X \\perp Y$. Knowing the value of $X$ does not tell us anything about $Y$.\n \\item  If $X$ and $Y$ are independent, $\\mbox{Cov}(X,Y)=0$.\n \\end{itemize}\n Aside: Mutual information is a measure of how 'non-independent' two random variables are.\n\n\n\\subsection{Multivariate Distributions}\n\\subsubsection{Expectation and covariance}\n\\begin{itemize}\n\\item Conditional distributions are just distributions which have a (conditional) mean or variance. \n\\item Note: $E(X|Y)= f(Y)$. 'If I tell you what $Y$ is, what is the average value of $X$?.\n%\\item $E(X,Y)= \\sum_{x,y} P(X=x, Y=y) (x,y)= (E(X), E(Y))$ \n\\item Covariance is the expected value of the product of fluctuations: \n\\begin{align}\n \\mbox{Cov}(X,Y)&= E\\left((X-E(X) )(Y-E(Y) )\\right)\\\\\n &= E(XY)- E(X)E(Y)\\\\\n \\mbox{Var(X)}&= \\mbox{Cov}(X,X)\n\\end{align}\n \\end{itemize}\nAside: One common way to construct bivariate random variables is to have a random variable whos parameter is another random variable. \n\n\\begin{itemize} \n\\item $\\mathbf{X},\\xx$ are vector valued.\n\\item Mean: $E(\\mathbf{X})= \\sum_{\\xx} \\xx P(\\xx)$\n\\item Covariance matrix: \n\\begin{align}\n\\mbox{Cov}(X_i, X_j)&= E(X_iX_j)-E(X_i) E(X_j)\\\\\n\\mbox{Cov}(\\mathbf{X})&= E(\\mathbf{X}\\mathbf{X}^\\top)-E(\\mathbf{X}) \nE(\\mathbf{X})^\\top \n \\end{align}\n\\item Conditional and marginal distributions: Can define and calculate any (multi or single-dimensional) marginals or conditional distributions we need:  $P(X_1)$, $P(X_1, X_2)$, $P(X_1, X_2, X_3 |X_4)$, etc..\n\\end{itemize}\n\n\\begin{bbbox}{Covariance matrix}\n\t\\begin{align*}\n\t\t& & Cov(\\mathbf{X}) &= \n\t\t\\begin{pmatrix}\n   \t\tCov(X_1,X_1) & Cov(X_2,X_1) & \\cdots & Cov(X_n,X_1) \\\\\n   \t\tCov(X_1,X_2) & Cov(X_2,X_2) & \\cdots & Cov(X_n,X_2) \\\\\n   \t\t\\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n   \t\tCov(X_1,X_n) & Cov(X_2,X_n) & \\cdots & Cov(X_n,X_n) \\\\\n  \t\t\\end{pmatrix} \\\\\n\t\t& \\text{Note that: } & Cov(X_i,X_j) &= Cov(X_j,X_i) \\\\\n\t\t& \\text{Therefore: } & Cov(\\mathbf{X}) &=  Cov(\\mathbf{X})^\\top\n\t\\end{align*}\n\t\n\\end{bbbox}\n\n\\subsection{Continuous random variables}\n\\begin{itemize}\n\\item A random variable $X$ is {continuous} if its sample space $X$ is uncountable. \n\\item In this case, $P(X=x)=0$ for each $x$.\n\\item If $p_X(x)$ is a {probability density function} for $X$, then \n\\begin{align}\nP(a < X <b) &=\\int_a^b p(x) dx\\\\\nP(a<X <a+dx) \\approx p(a) \\cdot dx\n\\end{align}\n\\item The {cumulative distribution function} is $F_X(x)=P(X<x)$. We have that $p_X(x)=F'(x)$, and $F(x)=\\int_{-\\infty}^x p(s) ds$.\n\\item\nMore generally: If $A$ is an event, then\n\\begin{align}\nP(A)&=P(X \\in A) =\\int_{x \\in A}  p(x) dx\\\\\nP(\\Omega)&=P(X \\in \\Omega) =\\int_{x \\in \\Omega} p(x) dx=1\n\\end{align}\n\\item Example: Uniform, Exponential, Beta  [on board]\n\\end{itemize}\n\n\\begin{bbbox}{PDFs of the uniform and the exponential distribution}\n\tContinuous uniform distribution: \\\\\n\t\\begin{flalign*}\n\t\tX &\\sim U(0,1) \\\\\n\t\tp(x) &= \n\t\t\t\\begin{cases}\n\t\t    \t1 & \\text{if } x \\epsilon \\left[0,1\\right]; \\\\\n\t\t    \t0 & \\text{else};\n\t\t\t\\end{cases} \\\\\n\t\tP(a \\leq X \\leq b) &= \\int_a^b p(x) dx \\\\\n\t\t\t\t\t\t   &= \\left[ x \\right]_a^b = b-a\\\\\n\t\tP(0 \\leq X \\leq 1) &= 1;\n\t\\end{flalign*} \\\\\n\tExponential Distribution with rate $\\lambda$:\n\t\\begin{flalign*}\n\t\tX &\\sim Exp(\\lambda) \\\\\n\t\tp(x) &= \\lambda \\mbox{e}^{-\\lambda x} \\text{where } x \\epsilon \\left[0,\\infty\\right);\\\\\n\t\tP(a \\leq X \\leq b) &= \\int_a^b \\lambda \\mbox{e}^{-\\lambda x} dx \\\\\n\t\t\t\t\t\t   &= \\left[ - \\mbox{e}^{-\\lambda x} \\right]_a^b\\\\\n\t\t\t\t\t\t   &= \\mbox{e}^{-\\lambda a} - \\mbox{e}^{-\\lambda b} \\\\\n\t\tP(0 \\leq X \\leq \\infty) &= \\mbox{e}^{-\\lambda 0} - \\mbox{e}^{-\\lambda \\infty} = 1\n\t\\end{flalign*} \\\\\n\\end{bbbox}\n\n\n\\subsubsection{Expectations and variance}\n\\begin{itemize}\n\\item Mean: $E(X)= \\int_x x  \\cdot p(x) dx$\\\\\n\\item Variance: $\\mbox{Var}(X)= E(X^2)- E(X)^2$\n\\item Example: Uniform, Exponential [on board]\n\\item If $X$ has pdf $p(x)$, then $X | (X \\in A)$ has pdf \n\\begin{align}\np_{X|A}(x)=\\frac{p(x)}{P(A)}=\\frac{p(x)}{\\int_{x \\in A} p(x) dx}\n\\end{align}\n\\item Only makes sense if $P(A)>0$~!\n\\item Example: Uniform, Exponential [on board]\n\\end{itemize}\n\n\\begin{bbbox}{Moments and Variance of the continuous uniform distribution}\n\tContinuous uniform distribution: \\\\\n\t\\begin{align*}\n\t\tX &\\sim U(0,1) \\\\\n\t\tE(X) &= \\int_0^1 x p(x) dx = \\int_0^1 x dx = &= \\left[ \\frac{1}{2}x^2 \\right]_0^1 = \\frac{1}{2}\\\\\n\t\tE(X^2) &= \\int_0^1 x^2 p(x) dx = \\int_0^1 x^2 dx = &= \\left[ \\frac{1}{3}x^3 \\right]_0^1 = \\frac{1}{3}\\\\\n\t\tVar(X) &= E(X^2) - E(X)^2 = \\frac{1}{3} - \\frac{1}{4} = \\frac{1}{12}\\\\\n\t\\end{align*}\n%\tExponential distribution: \\\\\n%\t\\begin{align*}\n%\t\tE(X) &= \\int_0^\\infty x \\lambda \\mbox{e}^{-\\lambda x} dx \\\\\n%\t\t     &= \\left[ -\\frac{1}{2}x^2 \\mbox{e}^{-\\lambda x} \\right]_0^\\infty \\\\\n%\t\\end{align*}\n\\end{bbbox}\n\n\\subsubsection{Marginalizationa, Conditioning and Independence}\n\\begin{itemize}\n\\item $p_{X,Y}(x,y)$, joint probablity density function of $X$ and $Y$\n\\item $\\int_x \\int_y p(x,y)dx dy=1$\n\\item {Marginal distribution:} $p(x)= \\int_{-\\infty}^\\infty p(x,y) dy$\n\\item {Conditional distribution:} $p(x|y)= \\frac{p(x,y)}{p(y)}$ \n\\item Note: $P(Y=y)=0$! Formally, conditional probability in the continuous case can be derived using infinitesimal events.\n\\item {Independence:} $X$ and $Y$ are independent if $p_{X,Y}(x,y)=p_X(x)p_Y(y)$\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "120169ca8ba11a1a5f9472a39ed751ebb415c303", "size": 15672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture3/lecture3.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/lecture3/lecture3.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/lecture3/lecture3.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.8831168831, "max_line_length": 1150, "alphanum_fraction": 0.6509060745, "num_tokens": 5520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.64272021797907}}
{"text": "\\chapter{ELEC 403 CheatSheet}\n\\begin{multicols}{3}\n\n\\textbf{Algorithm 1.1 General optimization algorithm} \\newline\n\\textbf{Step 1:} \\newline\n(a) Set $k=0$ and initialize $x_0$ \\newline\n(b) Compute $F_0=f(x_0)$ \\newline\n\\textbf{Step 2:} \\newline\n(a) Set $k=k+1$ \\newline\n(b) Compute the changes in $x_k$ given by column vector $\\nabla x_k$ %where\n\\[ \\text{where} \\quad \n\\nabla x_k^T = \\begin{bmatrix}\\nabla x_1 & \\nabla x_2 & \\cdots & \\nabla x_n\\end{bmatrix}\n\\]\nby using an appropriate procedure. \\newline\n(c) Set $x_k=x_{k-1}+\\nabla x_k$ \\newline\n(d) Compute $F_k=f(x_k)$ and $\\nabla F_k=F_{k-1}-F_k$. \\newline\n\\textbf{Step 3:} \\newline\nCheck if convergence has been achieved by using an appropriate criterion, e.g., by checking $\\nabla F_k$ and/or $\\nabla x_k$. If this is the case, continue to\nStep 4; otherwise, go to Step 2. \\newline\n\\textbf{Step 4:} \\newline\n(a) Output $x^* = x_k$ and $F^* = f(x^*)$. \\newline\n(b) Stop\n\\section{Ch.2}\nGradient: $g(x)=\\nabla f(x)=\\begin{bmatrix}\\frac{\\partial f}{\\partial x_1} & \\frac{\\partial f}{\\partial x_2} & \\cdots & \\frac{\\partial f}{\\partial x_n} \\end{bmatrix}^T$ \\newline\nHessian Matrix: $H(x)=\\nabla g(x)=\\nabla \\{ \\nabla^T f(x)\\}$. \\newline\n\\[\nH(x)=\n\\begin{bmatrix}\n\\frac{\\partial^2 f}{\\partial^2 x_1} & \\frac{\\partial^2 f}{\\partial x_1 \\partial x_2} & \\cdots & \\frac{\\partial^2 f}{\\partial x_1 \\partial x_n} \\\\\n\\frac{\\partial^2 f(x)}{\\partial x_2 \\partial x_1} & \\frac{\\partial^2 f(x)}{\\partial x_2^2} & \\cdots & \\frac{\\partial f}{\\partial x_2 \\partial x_n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\frac{\\partial  f}{\\partial x_n \\partial x_1}& \\frac{\\partial f}{\\partial x_n \\partial x_2}& \\cdots & \\frac{\\partial f}{\\partial x_n \\partial x_n}\n\\end{bmatrix}\n\\]\nTaylor Series: (quad approx, linear approx): $\\delta =\\begin{bmatrix} \\delta_1 &\\delta_2 \\end{bmatrix}^T$\n$f(x + \\delta) = f(x) + g(x)^T\\delta + 12\\delta^TH(x)\\delta + o(||\\delta||^2)$ \\newline\nLinear approximation: $f(x + \\delta) \\approx f(x) + g(x)^T\\delta $\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{Images/min.jpg}\n\t\\caption{Minimization points plotted}\n\\end{figure}\n$\\tilde{x}=x+\\delta \\quad \\delta =\\tilde{x}-x$ $\\hat{f}(\\tilde{x})=f(x)+g(x)(\\tilde{x}-x)^T+0.5(\\tilde{x}-x)^T H(x)(\\tilde{x}-x)^T$\nThe gradient $g(x)$ and the Hessian $H(x)$ must satisfy certain conditions at a\nlocal minimizer $x^*$.  \\newline\n1. Conditions which are satisfied at a local minimizer $x^*$.  \\newline\n2. Conditions which guarantee that $x^*$ is a local minimizer. \n\n\\textbf{Definition 2.1} A point $x^* \\in R,$ where R is the feasible region, is said to be a\nweak local minimizer of f(x) if there exists a distance $\\epsilon > 0$ such that\n$f(x) \\geq f(x^*)$ (2.5)\nif\n$x \\in R$ and \n$||x-x^*|| < \\epsilon$ \\newline\n\n\\textbf{Definition 2.2} \nA point $x^* \\in R $ is said to be a weak global minimizer of f(x) if\n$f(x) \\geq f(x^*)$ (2.6)\nfor all $x \\in R.$  \\newline\n\\textbf{Definition 2.3} \n\nIf Eq. (2.5) in Def. 2.1 or Eq. (2.6) in Def. 2.2 is replaced by\n$f(x) > f(x^*)$ (2.7)\n$x^*$ is said to be a strong local (or global) minimizer. d\n\n\\textbf{Definition 2.4} Let $\\delta = \\alpha \\mathbf{d}$ be a change in x where $\\alpha$ is a positive constant and d is a direction vector. If R is the feasible region and a constant $\\hat{\\alpha} > 0$ exists such that\n$x + \\alpha d \\in R$ for all $\\alpha$ in the range $0 \\leq \\alpha \\leq \\hat{\\alpha}$ , then d is said to be a feasible direction at\npoint x. \\newline \n\n\\textbf{Definition 2.5} \\newline\n(a) Let $d$ be an arbitrary direction vector at point $x$. The quadratic form\n$d^TH(x)d$ is said to be \\textit{positive definite, positive semidefinite, negative\n\tsemidefinite, negative definite} if $d^TH(x)d > 0, \\geq 0, \\leq 0, < 0,$ respectively, for all $d \\neq 0$ at $x$. If $d^TH(x)d$ can assume positive as well\nas negative values, it is said to be indefinite. \\newline\n(b) If $d^TH(x)d$ is positive definite, positive semidefinite, etc., then matrix\n$H(x)$ is said to be positive definite, positive semidefinite, etc. \\newline\n\nThe objective function must satisfy two sets of conditions in order to have\na minimum, namely, first- and second-order conditions.  \\newline\n\\textbf{First-order necessary conditions for a minimum} \\newline %Theorem 2.2\n(a) If $f(x) \\in C^1$ and $x^*$ is a local minimizer, then\n$g(x^*)^Td \\geq 0$ for every feasible direction $d$ at $x^*$. \\newline\n(b) If $x^*$ is located in the interior of $\\mathcal{R}$ then\n$g(x^*) = 0$ \\newline \\newline \n\\textbf{Second-order necessary conditions for a minimum} \\newline\n%Theorem 2.2\n(a) If $f(x) \\in C_2$ and $x^*$ is a local minimizer, then for every feasible direction\nd at $x^*$. \\hfill \\break\n\\indent     $(i) \\ g(x^*)Td \\geq 0$ \\newline\n\\indent    $(ii)$ If $g(x^*)^Td = 0$, then $d^TH(x^*)d \\geq 0$ \\newline\n(b) If $x^*$ is a local minimizer in the interior of R, then \\newline\n\\indent $ (i)$ $g(x^*) = 0$ \\newline\n\\indent $ (ii)$ $d^TH(x^*)d \\geq 0$ for all $d \\neq 0$ \n\n\\textbf{Second-order sufficient conditions for a minimum} \\newline %Theorem 2.5\nIf $f(x) \\in C_2$\nand $x^*$ is located in the interior of $\\mathcal{R}$, then the conditions\n(a) $g(x^*) = 0$\n(b) $H(x^*)$ is positive definite\nare sufficient for $x^*$ to be a strong local minimizer. \\newline\n\n\\textbf{Definition 2.6} \\newline\nA point $\\bar{x} \\in \\mathcal{R},$ where $\\mathcal{R}$ is the feasible region, is said to be a saddle point if \\newline\n(a) $g(\\bar{x}) = 0$ \\newline\n(b) point $\\bar{x}$ is neither a maximizer nor a minimizer. \\hfill \\break \\newline\nStationary points can be located and classified as follows: \\newline\n1. Find the points $x_i$ at which $g(x_i) = 0$. \\newline\n2. Obtain the Hessian $H(x_i)$. \\newline\n3. Determine the character of $H(x_i)$ for each point $x_i$. \\newline\nIf $H(x_i)$ is positive (or negative) definite, $x_i$ is a minimizer (or maximizer);\nif $H(x_i)$ is indefinite, $x_i$ is a saddle point. \n\n\\textbf{Techniques to compute Hessian P.D. , N.D. } \\newline\nEigenvalues: det $ (\\lambda I -A) = 0$ Multiplying all eigenvalues is equal to the determinant. \\newline\nThe leading principal minors of a matrix A or its negative $-A$ can be used to\nestablish whether the matrix is positive or negative definite whereas the principal\nminors of A or $-A$ can be used to establish whether the matrix is positive or\nnegative semidefinite. \\newline \n\n\\textbf{Theorem 2.9 Properties of matrices} \\newline \n(a) If \\textbf{H} is positive semidefinite or positive definite, then\ndet $\\mathbf{H} \\geq 0  \\ \\text{or} > 0$ \\newline \n(b) \\textbf{H} is positive definite if and only if all its leading principal minors are\npositive, i.e., det $\\mathbf{H_i} > 0$ for $ i = 1, 2, \\cdots , n.$ \\newline \n(c) \\textbf{H} is positive semidefinite if and only if all its principal minors are nonnegative, i.e., det $(H_i^{(l)}) \\geq 0$ for all possible selections of $\\{l_1, l_2, \\cdots , l_i \\}$\nfor $i = 1, 2, \\cdots, n$. \\newline \n(d) \\textbf{H} is negative definite if and only if all the leading principal minors of\n$-\\mathbf{H}$ are positive, i.e., $det ( -H_i) > 0$ for $i = 1, 2, \\cdots, n$. \\newline \n(e) \\textbf{H} is negative semidefinite if and only if all the principal minors of -$\\mathbf{H}$\nare nonnegative, i.e., det $(-H_i^{(l)}) \\geq 0$ for all possible selections of\n$\\{l_1, l_2, \\cdots , l_i \\}$ for $i = 1, 2, \\cdots , n$. \\newline \n(f) \\textbf{H} is indefinite if neither (c) nor (e) holds. \n\n\\textbf{Definition 2.7} \\newline\nA set $\\mathcal{R}_c\n\\subset E_n $ is said to be convex if for every pair of points $x_1, x_2 \\subset R_c$\nand for every real number $\\alpha$ in the range $0 < \\alpha < 1$, the point\n$x = \\alpha x_1 + (1 - \\alpha)x_2$\nis located in $\\mathcal{R}_c\n$, i.e., $x \\in \\mathcal{R}_c$. \\newline \n\n\\textbf{Definition 2.8} \\newline\n(a) A function $f(x)$ defined over a convex set $\\mathcal{R}_c$  is said to be convex if for\nevery pair of points $x_1, x_2 \\in \\mathcal{R}_c $ and every real number $\\alpha$ in the range $0 < \\alpha < 1$, the inequality\n$f[\\alpha x_1 + (1 - \\alpha)x_2] \\leq \\alpha f(x_1) + (1 - \\alpha)f(x_2)$ \nholds. If $x_1 \\neq x_2$ and\n$f[\\alpha x_1 + (1 - \\alpha)x_2] < \\alpha f(x_1) + (1 - \\alpha)f(x_2)$\nthen f(x) is said to be strictly convex. \\newline\n(b) If $\\phi(x)$ is defined over a convex set $\\mathcal{R}_c$ and f(x) = -$\\phi(x)$ is convex, then $\\phi(x)$ is said to be concave. If f(x) is strictly convex, $\\phi(x)$ is strictly concave. \\newline\n\n\\textbf{Property of convex functions relating to the Hessian} A function $f(x) \\in C^2$is convex over a convex set \n$\\mathcal{R}_c$ if and only if the Hessian H(x) of\nf(x) is positive semidefinite for $x \\in \\mathcal{R}_c.$  \\newline \n\n\\textbf{Theorem 2.15 Relation between local and global minimizers in convex functions} \\newline \nIf $f(x)$ is a convex function defined on a convex set $\\mathcal{R}_c$, then  \\newline \n(a) the set of points $S_c$ where $f(x)$ is minimum is convex;  \\newline \n(b) any local minimizer of $f(x)$ is a global minimizer. \n\n\\section{Ch. 4}\n\\textbf{Dichotomous Search} \\newline\nTwo function evaluations per iteration. \\newline\nA \\textbf{unimodal function} on an interval has exactly\none point where a maximum or minimum\noccurs in the interval. \\newline \nConsider a unimodal function which is known to have a minimum in the interval $[x_L, \\ x_U]$. This interval is said to be the range of uncertainty. \\newline \nIn this method, f(x) is evaluated at two points $x_a =\nx_1 - \\epsilon/2$ and $x_b = x_1 +\\epsilon/2$ where $\\epsilon$ is a small positive number. Then depending\non whether $f(x_a) < f(x_b)$ or $f(x_a) > f(x_b)$, range $x_L$ to $x_1 + \\epsilon/2$ or $x_1 - \\epsilon/2$\nto $x_U$ can be selected and if $f(x_a) = f(x_b)$ either will do fine. If we assume\nthat $x_1 - x_L = x_U - x_1$, i.e., $x_1 = (x_L + x_U)/2$, the region of uncertainty\nis immediately reduced by half. The same procedure can be repeated for the\nreduced range, that is, f(x) can be evaluated at $x_2 - \\epsilon/2$ and $x2 + \\epsilon/2$ where $x_2$ is located at the center of the reduced range, and so on. \\newline \\newline \n%\\begin{Figure}\n%\t\\centering\n%\t\\includegraphics[width=\\linewidth]{disearch}\n%\\end{Figure}\n\\textbf{Algorithm 4.1 Fibonacci} \\newline\nComputing n =$I_n=\\frac{I_1}{F_n}$, function evaluations = n-1 \\newline\n\\textbf{Step 1} \\newline\nInput $x_{L,1}, x_{U,1}$, and n. \\newline\n\\textbf{Step 2} \\newline\nCompute $F_1, F_2, \\cdots, F_n$ using Eq. (4.4). \\newline\n\\textbf{Step 3} \\newline\nAssign $I_1 = x_{U,1} - x_{L,1}$ and compute\n\\begin{align*}\n& I_2 = \\frac{F_{n -1}}{F_n}I_1 (\\text{see Eq. (4.6)})\\\\\n& x_{a,1} = x_{U,1} - I_2, \\quad x_{b,1} = x_{L,1} + I_2\\\\ \n& f_{a,1} = f(x_{a,1}), \\quad f_{b,1} = f(x_{b,1})\n\\end{align*}\nSet k = 1. \\newline\n\\textbf{Step 4} \\newline\nCompute $I_{k+2}$ using Eq. (4.6).\nIf $f_{a,k} \\geq f_{b,k}$, then update Eqs. (4.7) to (4.12) using\n\\begin{align*}\n& x_{L,k+1}=x_{a,k} \\\\\n& x_{U,k+1}=x_{U,k} \\\\\n& x_{a,k+1}=x_{b,k} \\\\\n& x_{b,k+1}=x_{L,k+1}+I_{k+1} \\\\\n& f_{a,k+1}=f_{b,k} \\\\\n& f_{b,k+1}=f(x_{b,k+1})\n\\end{align*}\nusing  Otherwise, if $f_{a,k} < f_{b,k}$, update\ninformation using Eqs. (4.13) to (4.18) using \\newline\n\\begin{align*}\n& x_{L,k+1}=x_{L,k} \\\\\n& x_{U,k+1}=x_{b,k} \\\\\n& x_{a,k+1}=x_{U,k+1}-I_{k+2} \\\\\n& x_{b,k+1}=x_{a,k} \\\\\n& f_{a,k+1}=f(x_{a,k+1}) \\\\\n& f_{b,k+1}=f_{a,k}\n\\end{align*}\n\n\\textbf{Step 5} \\newline\nIf $k = n - 2$ or $x_{a,k+1} > x_{b,k+1}$, output $x^* = x_{a,k+1}$ and $f^* = f(x^*)$,\nand stop. Otherwise, set $k = k + 1$ and repeat from Step 4.\nThe condition $x_{a,k+1} > x_{b,k+1}$ implies that $x_{a,k+1} \\approx x_{b,k+1}$ within the precision of the computer used, as was stated earlier, or that there is an error in the algorithm. It is thus used as an alternative stopping criterion. \\newline\n\n\\textbf{Algorithm 4.2 Golden-section search} \\newline\n(function evaluations = k+1) and Golden Ratio: $K=\\cfrac{1+\\sqrt{5}}{2}$\n$\\Lambda_{GS} = I_n = \\frac{I_1}\n{K_{n-1}}$ \\quad $\\Lambda_{F} = I_n = \\frac{I_1}\n{F_n} \\approx \\frac{\\sqrt{5}}\n{K^{n+1}}I_1$\n$\\frac{I_k}{I_{k+1}}=\\frac{I_{k+1}}{I_{k+2}}\n= \\frac{I_{k+2}}{I_{k+3}}\n= \\cdots = K$ \\newline\n\\textbf{Step 1} \\newline\nInput $x_{L,1}, x_{U,1},$ and $\\epsilon$. \\newline\n\\textbf{Step 2} \\newline\nAssign $I_1 = x_{U,1} - x_{L,1}, K = 1.618034$ and compute\n\\begin{align*}\n&I_2 = I_1/K \\\\\n&x_{a,1} = x_{U,1} - I_2, \\quad x_{b,1} = x_{L,1} + I_2 \\\\\n&f_{a,1} = f(x_{a,1}), \\quad f_{b,1} = f(x_{b,1}) \n\\end{align*}\nSet $k = 1$. \\newline\n\\textbf{Step 3} \\newline\nCompute $I_{k+2} = I_{k+1}/K$ \\newline\nIf $f_{a,k} \\geq f_{b,k}$, then update $x_{L,k+1}, x_{U,k+1}$, $x_{a,k+1}$, $x_{b,k+1}$, $f_{a,k+1}$,\nand $f_{b,k+1}$ as  \n\\begin{align*}\n& x_{L,k+1}=x_{a,k} \\\\\n& x_{U,k+1}=x_{U,k} \\\\\n& x_{a,k+1}=x_{b,k} \\\\\n& x_{b,k+1}=x_{L,k+1}+I_{k+1} \\\\\n& f_{a,k+1}=f_{b,k} \\\\\n& f_{b,k+1}=f(x_{b,k+1})\n\\end{align*}\nOr use using Eqs. (4.7) to (4.12). \nOtherwise if $f_{a,k} < f_{b,k}$, then update $x_{L,k+1}, x_{U,k+1}$, $x_{a,k+1}$, $x_{b,k+1}$, $f_{a,k+1}$, and $f_{b,k+1}$ as\n\\begin{align*}\n& x_{L,k+1}=x_{L,k} \\\\\n& x_{U,k+1}=x_{b,k} \\\\\n& x_{a,k+1}=x_{U,k+1}-I_{k+2} \\\\\n& x_{b,k+1}=x_{a,k} \\\\\n& f_{a,k+1}=f(x_{a,k+1}) \\\\\n& f_{b,k+1}=f_{a,k}\n\\end{align*}\nOtherwise, if $f_{a,k} < f_{b,k}$, update\ninformation using Eqs. (4.13) to (4.18). \\newline\n\\textbf{Step 4} \\newline\nIf $I_k < \\epsilon$ or $x_{a,k+1} > x_{b,k+1}$, then do: \\newline\nIf $f_{a,k+1} > f_{b,k+1}$, compute\n$x^* = 0.5(x_{b,k+1} + x_{U,k+1})$ \\newline\nIf $f_{a,k+1} = f_{b,k+1}$, compute\n$x^* = 0.5(x_{a,k+1} + x_{b,k+1})$ \\newline\nIf $f_{a,k+1} < f_{b,k+1}$, compute\n$x^* = 0.5(x_{L,k+1} + x_{a,k+1})$\nCompute $f^* = f(x^*).$ \\newline\nOutput $x^*$ and $f^*$, and stop. \\newline\n\\textbf{Step 5} \\newline\nSet $k = k + 1$ and repeat from Step 3. \\newline \\newline \n\\textbf{Equations 4.4, 4.6, (4.7-4.12) and (4.13-4.18) } \\newline\n$F_k = F_{k-1} + F_{k-2} \\quad$ for $k \\geq 2$ (4.4) \\newline\n$I_{k+2} = \\frac{F_{n-k-1}}{F_{n-k}}I_{k+1} (4.6)$\n\nIf $f_{a,k} > f_{b,k}$, then $x^*$ is in interval $[x_{a,k}, x_{U,k}]$ and so the new bounds of $x^* \\rightarrow$  %\\newline \n$x_{L,k+1} = x_{a,k} (4.7) \\quad x_{U,k+1} = x_{U,k} (4.8)$ \nSimilarly, the two interior points of the new interval, namely, $x_{a,k+1}$ and $x_{b,k+1}$\nwill be $x_{b,k}$ and $x_{L,k+1} + I_{k+2}$, respectively. We can thus assign\n$x_{a,k+1} = x_{b,k}$ (4.9) $x_{b,k+1} = x_{L,k+1} + I_{k+2}$ (4.10)\nas illustrated in Fig. 4.5. \\newline\nThe value $f_{b,k}$ is retained as the value of f(x) at\n$x_{a,k+1}$, and the value of f(x) at $x_{b,k+1}$ is calculated, i.e.,\n$f_{a,k+1} = f_{b,k}$ (4.11)\n$f_{b,k+1} = f(x_{b,k+1})$ (4.12) \\newline\n%\\begin{Figure}\n%\t\\centering\n%\t\\includegraphics[width=\\linewidth]{fibfirst}\n%\\end{Figure}\nOn the other hand, if $f_{a,k} < f_{b,k}$, then $x^*$ is in interval $[x_{L,k}, x_{b,k}]$. In this\ncase, we assign\n$x_{L,k+1} = x_{L,k}$ (4.13)\n$x_{U,k+1} = x_{b,k}$ (4.14)\n$x_{a,k+1} = x_{U,k+1} - I_{k+2}$ (4.15)\n$x_{b,k+1} = x_{a,k}$ (4.16)\n$f_{b,k+1} = f_{a,k}$ (4.17)\nand calculate\n$f_{a,k+1} = f(x_{a,k+1})$ (4.18) \\newline  \\newline\n%\\begin{Figure}\n%\t\\centering\n%\t\\includegraphics[width=\\linewidth]{fibsecond}\n%\\end{Figure}\n%\\begin{Figure}\n%\t\\centering\n%\t\\includegraphics[width=\\linewidth]{golden}\n%\\end{Figure}\n%\\begin{Figure}\n%\t\\centering\n%\t\\includegraphics[width=\\linewidth]{fib}\n%\\end{Figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Unlikely to be tested %%\n%% INCLUDE FOR FINAL %%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\textbf{Algorithm 4.6 Inexact line search}  \\newline\n\\textbf{Step 1:} \\newline\nInput $x_k$, $d_k$, and compute $g_k$. \\newline\nInitialize algorithm parameters $\\rho, \\sigma, \\tau$, and $\\chi$. \\newline\nSet $\\alpha_L = 0$ and $\\alpha_U = 10^{99}$. \\newline\n\\textbf{Step 2:} \\newline\nCompute $f_L = f(x_k + \\alpha_L dk)$. \\newline\nCompute $f_L^\\prime = g(x_k + \\alpha_L dk)^Tdk$. \\newline\n\\textbf{Step 3:} \\newline\nEstimate $\\alpha_0$. \\newline\n\\textbf{Step 4:} \\newline\nCompute $f_0 = f(x_k + \\alpha_0dk)$. \\newline\n\\textbf{Step 5 (Interpolation)} \\newline\nIf $f_0 > f_L + \\rho(\\alpha_0 - \\alpha_L)f_L^\\prime$ , then do: \\newline\na. If $\\alpha_0 < \\alpha_U$, then set $\\alpha_U = \\alpha_0$.\\newline\nb. Compute $\\breve{\\alpha}_0$ using the interpolation formula Eq. (4.57). %\\newline\n\\[\n\\breve{\\alpha}_0 =\\alpha_L + \\frac{(\\alpha_0-\\alpha_L)^2f_L^\\prime}{2[f_L-f_0+(\\alpha_0-\\alpha_L)f_L^\\prime]}\n\\]\nc. If $\\breve{\\alpha}_0 < \\alpha_L + \\tau(\\alpha_U - \\alpha_L)$ then set $\\breve{\\alpha}_0 = \\alpha_L + \\tau(\\alpha_U - \\alpha_L)$. \\newline\nd. If $\\breve{\\alpha}_0 > \\alpha_U - \\tau(\\alpha_U - \\alpha_L)$ then set $\\breve{\\alpha}_0  = \\alpha_U - \\tau(\\alpha_U - \\alpha_L)$. \\newline\ne. Set $\\alpha_0 = \\breve{\\alpha}_0$ and go to Step 4. \\newline\n\\textbf{Step 6} \\newline\nCompute $f_0^\\prime = g(x_k + \\alpha_0dk)^Tdk$. \\newline\n\\textbf{Step 7 (Extrapolation)} \\newline\nIf $f_0^\\prime < \\alpha f_L^\\prime$ , then do: \\newline\na. Compute $\\nabla \\alpha_0 = (\\alpha_0 - \\alpha_L)f_0^\\prime /(f_L^\\prime - f_0^\\prime)$ (see Eq. (4.58)).\n\\[\n\\breve{\\alpha}_0 = \\alpha_0 + (\\alpha_0 - \\alpha_L)f_0^\\prime\n(f_L^\\prime - f_0^\\prime) \\quad (Eq. (4.58))\n\\]\nb. If $\\nabla \\alpha_0 < \\tau(\\alpha_0 - \\alpha_L)$, then set $\\nabla \\alpha_0 = \\tau(\\alpha_0 - \\alpha_L)$. \\newline\nc. If $\\nabla \\alpha_0 > \\chi(\\alpha_0 - \\alpha_L)$, then set $\\nabla \\alpha_0 = \\chi(\\alpha_0 - \\alpha_L)$. \\newline\nd. Compute $\\breve{\\alpha}_0 = \\alpha_0 + \\nabla \\alpha_0$. \\newline\ne. Set $ \\alpha_L =  \\alpha_0, \\alpha_0 = \\breve{\\alpha}_0, f_L = f_0, f_L^\\prime = f_0^\\prime$, and go to Step 4. \\newline\n\\textbf{Step 8} \\newline\nOutput $\\alpha_0$ and $f_0 = f(x_k + \\alpha_0dk)$, and stop.\n\n\n\\section{Ch. 5}\nStandard form: $f(x)=\\frac{1}{2}x^T H x + x^T g(x) + C$ \\newline \nRate of Convergence $\\beta = (1-r^2)/(1+r^2)$, where r is the smallest eigenvalue divided by the biggest eigenvalue. \\newline\n\\begin{align*}\n& H^{-1}=\\begin{bmatrix}\na & c \\\\\nc & b \n\\end{bmatrix}^{-1}\n=\n\\frac{1}{ab-c^2}\n\\begin{bmatrix}\nb & -c \\\\\n-c & a\n\\end{bmatrix} \\quad ab-c^2 \\neq 0\n\\end{align*}\n$[f(x_k)-f(x^*)]\\leq \\left(\\frac{1-r}{1+r}\\right)^2[f(x_k)-f(x^*)]$ \\newline\n\\textbf{Algorithm 5.1 Steepest-descent algorithm} \\newline\n\\textbf{Step 1}  \\newline\nInput $x_0$ and initialize the tolerance $\\epsilon$. \\newline\nSet $k = 0$. \\newline\n\\textbf{Step 2} \\newline\nCalculate gradient $g_k$ and set $d_k=-g_k$. \\newline\n\\textbf{Step 3} \\newline\nFind $\\alpha_k$, the value of $\\alpha$ that minimizes $f(x_k + \\alpha d_k)$, using a line search (Algorithm Inexact Line Search. 4.6). \\newline\n\\textbf{Step 4} \\newline\nSet $x_{k+1} = x_k + \\alpha_k d_k$ and calculate $f_{k+1} = f(x_{k+1})$. \\newline\n\\textbf{Step 5}  \\newline\nIf $||\\alpha_k d_k|| < \\epsilon$, then do: \\newline\nOutput $x^* = x_{k+1}$ and $f(x^*) = f_{k+1}$, and stop. \\newline\nOtherwise, set $k = k + 1$ and repeat from Step 2. \\newline \n\n\\textbf{Algorithm 5.3 Basic Newton algorithm} \\newline\n\\textbf{Step 1} \\newline\nInput $x_0$ and initialize the tolerance $\\epsilon$ \\newline\nSet $k = 0$. \\newline\n\\textbf{Step 2} \\newline\nCompute $g_k$ and $H_k$. \\newline\nIf $H_k$ is not positive definite, force it to become positive definite. \\newline\n\\textbf{Step 3} \\newline\nCompute $H_k^{-1}$ and $d_k=-H_k^{-1}g_k$ \\newline\n\\textbf{Step 4} \\newline\nFind $\\alpha_k$ , the value of $\\alpha$ that minimizes $f(x+\\alpha d_k)$, using a line search. \\newline\n\\textbf{Step 5} \\newline\nSet $x_{k+1}=x_k+\\alpha_k d_k$ \\newline\nCompute $f_{k+1}=f(x_{k+1})$. \\newline\n\\textbf{Step 6} \\newline\nIf $||\\alpha_k d_k|| < \\epsilon$, then do:  \\newline\nOutput $x^*=x_{k+1}$ and $f(x^*)=f(x_{k+1})$, and stop \\newline\nOtherwise, set $k = k + 1$ and repeat from Step 2. \\newline\n\\textbf{Algorithm 5.5 Gauss --- Newton Algorithm} \\newline\n$f=\\begin{bmatrix}\nf_1(x)  & f_2(x) & \\cdots f_m(x)\n\\end{bmatrix}^T$, J = Jacobian \\newline\n$F(x)=\\sum_{p=1}^{m}f_p(x)^2=f^Tf$ \\newline\n$J=\\begin{bmatrix}\n\\frac{ \\partial f_1}{\\partial  x_1} & \\frac{ \\partial  f_1}{ \\partial  x_2} & \\cdots & \\frac{\\partial  f_1}{\\partial  x_n} \\\\\n\\frac{\\partial  f_2}{\\partial x_1} & \\frac{\\partial  f_2}{\\partial  x_2} & \\cdots & \\frac{\\partial  f_2}{\\partial x_n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\\frac{\\partial f_m}{\\partial  x_1}& \\frac{\\partial f_m}{\\partial  x_2}& \\cdots & \\frac{\\partial f_m}{\\partial x_n}\n\\end{bmatrix}$ \\newline\n\\textbf{Step 1} \\newline\nInput $x_0$ and initialize the tolerance $\\epsilon$.  \\newline\nSet $k = 0$. \\newline\n\\textbf{Step 2} \\newline\nCompute $f_{pk} = f_p(x_k)$ for $p = 1, 2, \\cdots, m$ and $F_k$.\n\\newline\n\\textbf{Step 3}  \\newline\nCompute $J_k, g_k = 2J^T_k f_k$, and $H_k = 2J^T_k J_k$. \\newline\n\\textbf{Step 4}  \\newline\n$d_k=-H_k^{-1}g_k$ \\newline\n\\textbf{Step 5} \\newline\nFind $\\alpha_k$, the value of $\\alpha$ that minimizes $f(x_k + \\alpha d_k)$. \\newline\n\\textbf{Step 6} \\newline\nSet $x_{k+1} = x_k + \\alpha_kd_k$. \\newline\nCompute $f_{p,k+1}$ for $p = 1, 2,\\cdots, m$ and $F_{k+1}$. \\newline\n\\textbf{Step 7} \\newline\nIf $|F_{k+1}-F_k | < \\epsilon$, then do: \\newline\nOutput $x^*= x_{k+1}$, $f_{p,k+1}(x^*)$ for $p = 1, 2,\\cdots, m$, and $F_{k+1}$. \\newline\nStop. \\newline\nOtherwise, set $k = k + 1$ and repeat from Step 3.\n\n\n\\section{Ch. 7}\n\\textbf{Problems with Rank-one Method}\n\\begin{enumerate}\n\t\\item positive definite $S_k$ may not yield positive definite $S_{k+1}$\n\t\\item denominator in correction formula may approach zero \n\\end{enumerate}  \nTHE DFP and BFGS are implementing of the basic algorithms Quasi Newton (7.2) with changes to the updating function. $d_k=-S_kg_k$ and $f(x_k + \\alpha d_k)$  $\\rightarrow$  $\\alpha_k=\\frac{g_k^TS_kg_k} \n{g_k^TS_kHS_kg_k}$ \\newline\nConvergence equation: $\\beta = \\left(\\frac{1-r}{1+r}\\right)^2$ $f(x_{k+1})-f(x^*) \\leq \\left(\\frac{1-r}{1+r}\\right)^2[f(x_k)-f(x^*)]$ \\newline\n\\textbf{BFGS and then DFP properties} \\newline\nFor convex quadratic functions (BFGS)\n\\begin{enumerate}\n\t\\item[---] $Sk+1$ becomes identical to $H^{-1}$ for $k = n-1$.\n\t\\item[---] Directions $\\delta_0,\\delta_1,\\cdots,\\delta_{n-1}$ form a conjugate set. \n\t\\item[---] $S_{k+1}$ is positive definite if $S_k$ is positive definite.\n\t\\item[---] $\\delta^T_k \\gamma_k = \\delta^T_k g_{k+1}-\\delta_T^k g_k > 0$ applies. \\newline\n\\end{enumerate}  \n\\textbf{For DFP (from textbook)} \n\\begin{enumerate}\n\t\\item If $S_k$ is PD, then \n\tthe matrix $S_{k+1}$ generated by DFP is also PD.\n\t\\item Directions $\\delta_0,\\delta_1,\\cdots,\\delta_{n-1}$ form a conjugate set. \\newline\n\\end{enumerate} \n\\textbf{Algorithm 7.2 adjusted for DFP/BFGS} \\newline\n\\textbf{Step 1} \\newline\nInput $x_0$  and initialize the tolerance $\\epsilon$. \\newline\nSet $k = 0$ and $S_0 = I_n$. \\newline\nCompute $g_0$. \\newline\n\\textbf{Step 2} \\newline\nSet $d_k=-S_kg_k$ \\newline\nFind $\\alpha_k$, the value of $\\alpha$ that minimizes $f(x_k+\\alpha d_k)$, using a line search \\newline\nSet $\\delta_k=\\alpha_k d_k$ and $x_{k+1}=x_k+\\delta_k$ \\newline\n\\textbf{Step 3} \\newline\nIf $||\\delta_k|| < \\epsilon$, output $x^* = x_{k+1}$ and $f(x^*) = f(x_{k+1})$, and stop \\\\\n\\textbf{Step 4} \\newline\nCompute $g_{k+1}$ and set $\\gamma_k=g_{k+1}-g_k$ \\newline\nCompute $S_{k+1}$ using appropriate formula.\n\\begin{align*}\n&\\text{Basic/ Rank One:} \\quad S_{k+1}=S_k+\\frac{(\\delta_k-S_k \\gamma_k)(\\delta_k-S_k \\gamma_k)^T}{\\gamma_k^T(\\delta_k-S_k\\gamma_k)}\\\\\n&\\text{DFP:}\\quad S_{k+1}=S_k+\\frac{\\delta_k \\delta_k^T}{\\delta_k^T \\gamma_k}-\\frac{S_k\\gamma_k\\gamma_k^TS_k}{\\gamma_k^TS_k\\gamma_k}\\\\\n&\\text{BFGS:} \\quad S_{k+1}=S_k+\\left(1+\\frac{\\gamma_k^TS_k\\gamma_k}{\\gamma_k^T\\delta_k}\\right)\\frac{\\delta_k\\delta_k^T}{\\gamma_k^T\\delta_k}-\\frac{(\\delta_k\\gamma_k^TS_k+S_k\\gamma_k\\delta_k^T)}{\\gamma_k^T\\delta_k}\n\\end{align*}\nSet $k=k+1$ and repeat from Step 2. \\newline\n\\begin{itemize}\n\t\\item[---] remember that $\\left(1+\\frac{\\gamma_k^TS_k\\gamma_k}{\\gamma_k^T\\delta_k}\\right)$ is a single number\n\t\\item[---] $\\delta_k\\delta_k^T$ is a matrix.\n\t\\item[---] Focus on minimization, $\\max[f(x)] =-\\min[-f(x)]$\n\t\\item[---] Hessian is positive semidefinite for concave functions.\n\\end{itemize}\n\\end{multicols}", "meta": {"hexsha": "54b1285274fd3495980e80dba8b9860663977389", "size": 23718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/ELEC403Cheat.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/ELEC403Cheat.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/ELEC403Cheat.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": 48.7022587269, "max_line_length": 253, "alphanum_fraction": 0.6476515726, "num_tokens": 9420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6427202179647945}}
{"text": "\\section{What is machine learning?} \\label{ch:what_is_ml}\n\n\\subsection{Machine learning in general}\n\nUsually the task of programming is to apply rules to certain problems in order to obtain solutions.\nWith the help of machine learning we want to create a model that uses solutions for certain problems to find out the corresponding rules.\nThe relationship is shown in figure~\\ref{fig:cp_vs_ml}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{images/classical_prog_vs_ml.png}\n    \\caption[ML, a new programming paradigm]{Machine learning, a new programming paradigm \\cite[p.5]{Chollet2017}}\n    \\label{fig:cp_vs_ml}\n\\end{figure}\n\nThe promise of machine learning is that the rules learned can be much more complex than it is possible to program by hand.\nA good example is image recognition (which will be the focus of this project), where the content of images is to be classified.\nThe relations between the pixels have to be found out, which leads to a rather complex model.\nThis cannot be programmed in the traditional way even for the simplest tasks.\n\nThe universal approximation theorem \\cite{Cybenko1989, Hornik1989} states that for any input $x$ there is a function $h$ which approximates the mapping $y$, while the mapping is only the input to the correct output (often labeled by a human).\nThis relationship is described in equation~\\eqref{eq:universal_approx}.\n\n% TODO define sets X and Y of \\theta and x\n\\begin{equation}\n    \\forall \\epsilon > 0 :\n    \\exists h(\\theta, x) : \\forall x \\in I : | h(\\theta, x) - y(x) | < \\epsilon\n    \\label{eq:universal_approx}\n\\end{equation}\n% TODO the text here can be changed with a class of functions (see UAT paper)\n\nThe mathematical description of $h$ is called a model (e.g. $h(x) = \\sum_{i=1}^n{\\lambda (\\theta^T * x)}$).\n$\\lambda \\in \\mathbb{R}$ is a constant and $\\theta$ is a tensor that defines the parameters of $h$, which are made up of so-called weights and biases, which will be explained later.\n\nThe universal approximation theorem makes no statements about the form of $\\theta$; therefore $h$ is called a hypothesis because it states that for a certain composition of $\\theta$ this equation is true.\nThis term is summarized in the equation~\\eqref{eq:hypothesis}.\n\n\\begin{equation}\n    \\forall \\epsilon > 0 : \\exists \\theta \\in X : \\forall x \\in I : |\n    h_\\theta(x) - y(x) | < \\epsilon\n    \\label{eq:hypothesis}\n\\end{equation}\n\nA loss function is used for model valuation; it compares the result of the hypothesis with the data provided.\nProbably the most prominent loss function is the \\name{mean square error}.\nIt takes the sum of the deviation of $n$ examples squared and divides it by $2*n$.\n\n\\begin{equation}\n    L_{mse}(\\theta, x) = \\frac{1}{2 n} \\sum_{i=1}^n (h_\\theta(x) - y(x))^2\n    \\label{eq:mse}\n\\end{equation} \n\nThe task of machine learning is to determine a $\\theta$ for a model that confirms the equations~\\ref{eq:universal_approx} and \\ref{eq:hypothesis}, which is done by iterative updating of $\\theta$. \nBefore training, $\\theta$ is randomly initiated and then iteratively adjusted to make $\\epsilon$ converge toward zero. This minimizes the value of $L$.\n\nIn order for the value of the loss function to gradually decrease, $\\theta$ is adjusted using an optimization function.\nThis is usually done with a gradient descent algorithm or a variant of it.\nThe gradient descent is performed by calculating the gradient of the loss function and subtracting it from the corresponding parameters shown in equation~\\eqref{eq:gradient_descent}.\n\n\\begin{equation}\n    \\theta_{i+1} := \\theta_i - \\eta \\nabla_\\theta L(\\theta, x)\n    \\label{eq:gradient_descent}\n\\end{equation}\n\nWhere $\\eta$ is a constant called the learning rate, which helps the loss function converge to 0 using the gradient descent algorithm.\nIt is one of many hyperparameters that are not automatically adjusted during training, but are determined beforehand.\nOptimal adjustment of hyperparameters is an important task that is difficult to automate and is therefore the focus of much research\\footnote{There are algorithms for adjusting the learning rate, namely \\name{AdaGrad} \\cite{Duchi2010} and derived algorithms and is the main topic of the chapter \\ref{ch:hyper_parameter_tuning}}.\nIf the equation \\eqref{eq:hypothesis} applies to the model in question, it is then sufficiently suitable for the given input.\n\nThese concepts are presented now using a simple example.\n\n\\subsection{Simple linear example} \\label{ch:simple_linear_example}\n\nAs an illustrative example, a model is created that translates Fahrenheit into Celsius\\footnote{Please note that using a learning algorithm here is very inefficient and is in contrast to Maslow's hammer (\\aka{https://en.wikipedia.org/wiki/Law_of_the_instrument}).}.\nThe original equation is given by the linear function $y = mx + b$ as $F = C * 1.8 + 32$, with $F$ as degrees Fahrenheit and $C$ as degrees Celsius.\n\nA model to learn this relationship is defined in the listing~\\ref{lst:c_to_f} \\footnote{Also available at \\aka{https://github.com/klawr/deepmech/tree/master/reports/srp/code/c_to_f.js}} .\n\n% TODO add JavaScript as language\n\\lstinputlisting[label={lst:c_to_f}, caption={Celsius to Fahrenheit}]{code/c_to_f.js}\n\nThe described model is implemented by \\code{w} and the hypothesis function by \\code{h}.\nSince it is known that the relationship is linear, the model represents a one-dimensional polynomial, with the first index being dimensionless (and, as mentioned above, emulating the bias) and the second being used as input x.\nWe will add a dimension later to demonstrate the behavior with polynomials that do not directly represent the target function.\n\n\\code{y} provides the correct, predefined solution.\nPlease note that \\code{y} is only used during training and is omitted if the model parameters are correctly set after training.\n\nIn this example the loss function is described by the \\textit{mean square error } \\footnote{ Abbreviated as \\textit{mse}, which is shown in equation \\eqref{eq:mse}}.\n\nTo minimize the loss function gradient descent described in equation~\\eqref{eq:gradient_descent} is used.\n\nIn listing~\\ref{lst:c_to_f} equation~\\eqref{eq:gradient_descent} is implemented as \\code{sgd} with $\\theta_0 = \\code{b}$ and $\\theta_1= \\code{m}$ as shown in equation~\\eqref{eq:sgd_mse_here}.\n\n\\code{sgd} is short for \\textit{stochastic gradient descent}\\footnote{A distinction is made between batch, mini-batch and stochastic gradient descent; using a complete data set, a defined subset or individual data on the individual iterations of the training process}.\nIt represents the optimization function that updates the parameters of the model by calculating the gradient of loss for each parameter and then updating it.\n\n\\begin{equation}\n    \\begin{split}\n        \\theta_{0} & := \\theta_{0} - \\frac{\\partial L}{\\partial \\theta_{0}} =\n        \\theta_{0} - (h(x) - y(x))  \\\\\n        \\theta_{1} & := \\theta_{1} - \\frac{\\partial L}{\\partial \\theta_{1}} =\n        \\theta_{0} - (h(x) - y(x)) * x\n    \\end{split}\n    \\label{eq:sgd_mse_here}\n\\end{equation}\n\n\\begin{lstlisting}[caption={Output of C to F converter.}]\nloss:  343041.666256673\nloss:  16242.7707476548\nloss:  88.27595280422442\nloss:  10.74432403839251\nloss:  1.1607137779951606\nloss:  0.252186283500194\nloss:  0.00040450626910586374\nloss:  0.00004247033303206121\nloss:  7.158429555712516e-7\nloss:  1.6948019668728757e-10\nweights:  [ 31.99999973758735, 1.8000003977458756 ]\n\\end{lstlisting} \n\nThe expected behavior for the loss function is to decrease with each iteration.\nThis is the case in this example, showing that the deviation of the hypothesis from the actual result decreases.\nAfter 200 iterations, the parameters \\code{m} and \\code{b} of the \\code{model} are displayed and show that they are actually close to the expected result.\nBy increasing the number of iterations, the result can be increased up to the point where they are rounded by the JavaScript compiler to represent exact results (using Node.js\\footnote{As far as can be assumed when calculating exact results using floating point numbers.}).\n\n\\begin{SCfigure}\n    \\centering\n    \\caption[Simplest model]{This example can be visualized as shown here. The bias can be interpreted as additional input, which always has the value 1. The input is multiplied by the parameters marked with the corresponding arrows, which in turn are summed up (resulting in $y = mx + b$).}\n    \\includegraphics[width=0.45\\textwidth]{images/1_simplest_nn.png}\n\\end{SCfigure} \n\nProvided that this hypothesis is initially well suited to the task, it is important to note that by modifying the hypothesis to represent a polynomial of higher degree (e.g. $y = nx^2 + mx + b$) the additional parameters converge towards 0, which effectively gives the same result as before \\footnote{But to achieve similar results, the iteration number must be increased by at least a factor of 20}.\n\nThe experiment can be followed at \\aka{https://github.com/klawr/deepmech/tree/master/reports/srp/code/c_to_f_adv.js}.\n", "meta": {"hexsha": "d57dab2f12dce8078956a33cfeb8c7034e9d88b0", "size": 9026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/srp/sections/what_is_ml.tex", "max_stars_repo_name": "klawr/deepmech", "max_stars_repo_head_hexsha": "61de238f1d4b1b867ec1d5f4e4af2a3b25a5abff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-17T12:27:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T12:27:06.000Z", "max_issues_repo_path": "reports/srp/sections/what_is_ml.tex", "max_issues_repo_name": "klawr/deepmech", "max_issues_repo_head_hexsha": "61de238f1d4b1b867ec1d5f4e4af2a3b25a5abff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-27T13:13:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T13:13:17.000Z", "max_forks_repo_path": "reports/srp/sections/what_is_ml.tex", "max_forks_repo_name": "klawr/deepmech", "max_forks_repo_head_hexsha": "61de238f1d4b1b867ec1d5f4e4af2a3b25a5abff", "max_forks_repo_licenses": ["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.3676470588, "max_line_length": 400, "alphanum_fraction": 0.7633503213, "num_tokens": 2319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6427202164499148}}
{"text": "\\chapter{Lebesgue integration}\nOn any measure space $(\\Omega, \\SA, \\mu)$ we can then,\nfor a function $f \\colon \\Omega \\to [0,\\infty]$\ndefine an integral\n\\[ \\int_\\Omega f \\; d\\mu. \\]\nThis integral may be $+\\infty$ (even if $f$ is finite).\nAs the details of the construction won't matter for us later on,\nwe will state the relevant definitions,\nskip all the proofs,\nand also state all the properties that we actually care about.\nConsequently, this chapter will be quite short.\n\n\\section{The definition}\nThe construction is done in four steps.\n\\begin{definition}\n\tIf $A$ is a measurable set of $\\Omega$,\n\tthen the \\vocab{indicator function}\n\t$\\mathbf{1}_A \\colon \\Omega \\to \\RR$ is defined by\n\t\\[ \\mathbf{1}_A(\\omega) = \\begin{cases}\n\t\t\t1 & \\omega \\in A \\\\\n\t\t\t0 & \\omega \\notin A.\n\t\t\\end{cases} \\]\n\\end{definition}\n\n\\begin{step}\n\t[Indicator functions]\n\tFor an indicator function, we require\n\t\\[ \\int_\\Omega \\mathbf{1}_A \\; d\\mu \\defeq \\mu(A) \\]\n\t(which may be infinite).\n\\end{step}\nWe extend this linearly now for nonnegative functions\nwhich are sums of indicators:\nthese functions are called \\vocab{simple functions}.\n\\begin{step}\n\t[Simple functions]\n\tLet $A_1$, \\dots, $A_n$ be a finite collection of measurable sets.\n\tLet $c_1$, \\dots, $c_n$ be either nonnegative real numbers or $+\\infty$.\n\tThen we define\n\t\\[ \\int_\\Omega \\left( \\sum_{i=1}^n c_i \\mathbf{1}_{A_i} \\right) \\; d\\mu\n\t\t\\defeq \\sum_{i=1}^n c_i \\mu(A_i). \\]\n\tIf $c_i = \\infty$ and $\\mu(A_i) = 0$, we treat $c_i \\mu(A_i) = 0$.\n\\end{step}\nOne can check the resulting sum does not depend\non the representation of the simple function as $\\sum c_i \\mathbf{1}_{A_i}$.\nIn particular, it is compatible with the previous step.\n\nConveniently, this is already enough to define the integral\nfor $f \\colon \\Omega \\to [0, +\\infty]$.\nNote that $[0,+\\infty]$ can be thought of as a topological space\nwhere we add new open sets $(a,+\\infty]$ %chktex 9\nfor each real number $a$ to our usual basis of open intervals.\nThus we can equip it with the Borel sigma-algebra.\\footnote{We\n\t\\emph{could} also try to define a measure on it,\n\tbut we will not: it is a good enough for us\n\tthat it is a measurable space.}\n\\begin{step}\n\t[Nonnegative functions]\n\tFor each measurable function $f \\colon \\Omega \\to [0, +\\infty]$, let\n\t\\[ \\int_\\Omega f \\; d\\mu \\defeq\n\t\t\\sup_{0 \\le s \\le f} \\left( \\int_\\Omega s \\; d\\mu \\right) \\]\n\twhere the supremum is taken over all \\emph{simple} $s$\n\tsuch that $0 \\le s \\le f$.\n\tAs before, this integral may be $+\\infty$.\n\\end{step}\nOne can check this is compatible with the previous definitions.\nAt this point, we introduce an important term.\n\\begin{definition}\n\tA measurable (nonnegative) function $f \\colon \\Omega \\to [0, +\\infty]$\n\tis \\vocab{absolutely integrable}\n\tor just \\vocab{integrable} if $\\int_\\Omega f \\; d\\mu < \\infty$.\n\\end{definition}\nWarning: I find ``integrable'' to be \\emph{really} confusing terminology.\nIndeed, \\emph{every} measurable function from $\\Omega$ to $[0,+\\infty]$\ncan be assigned a Lebesgue integral, it's just that\nthis integral may be $+\\infty$.\nSo the definition is far more stringent than the name suggests.\nEven constant functions can fail to be integrable:\n\\begin{example}\n\t[We really should call it ``finitely integrable'']\n\tThe constant function $1$ is \\emph{not} integrable on $\\RR$,\n\tsince $\\int_\\RR 1 \\; d\\mu = \\mu(\\RR) = +\\infty$.\n\\end{example}\nFor this reason, I will usually prefer the term ``integrable''.\n(If it were up to me, I would call it ``finitely integrable'',\nand usually do so privately.)\n\nFinally, this lets us integrate general functions.\n\\begin{definition}\n\tIn general, a measurable function $f \\colon \\Omega \\to [-\\infty, \\infty]$\n\tis \\vocab{absolutely integrable} or just \\vocab{integrable} if $|f|$ is.\n\\end{definition}\nSince we'll be using the first word, this is easy to remember:\n``absolutely integrable'' requires taking absolute values.\n\n\\begin{step}\n\t[Absolutely integrable functions]\n\tIf $f \\colon \\Omega \\to [-\\infty, \\infty]$ is absolutely integrable,\n\tthen we define\n\t\\begin{align*}\n\t\tf^+(x) &= \\max\\left\\{ f(x), 0 \\right\\} \\\\\n\t\tf^-(x) &= \\min\\left\\{ f(x), 0 \\right\\} \\\\\n\t\\end{align*}\n\tand set\n\t\\[ \\int_\\Omega f \\; d\\mu = \\int_\\Omega |f^+| \\; d\\mu\n\t\t- \\int_\\Omega |f^-| \\; d\\mu \\]\n\twhich in particular is finite.\n\\end{step}\nYou may already start to see that we really like nonnegative functions:\nwith the theory of measures, it is possible to integrate them,\nand it's even okay to throw in $+\\infty$'s everywhere.\nBut once we start dealing with functions that can be either positive or negative,\nwe have to start adding finiteness restrictions ---\nactually essentially what we're doing is splitting\nthe function into its positive and negative part,\nrequiring both are finite, and then integrating.\n\n\nTo finish this section, we state for completeness\nsome results that you probably could have guessed were true.\nFix $\\Omega = (\\Omega, \\SA, \\mu)$, and\nlet $f$ and $g$ be measurable real-valued functions\nsuch that $f(x) = g(x)$ almost everywhere.\n\\begin{itemize}\n\t\\ii (Almost-everywhere preservation)\n\tThe function $f$ is absolutely integrable if and only if $g$ is,\n\tand if so, their Lebesgue integrals match.\n\t\\ii (Additivity)\n\tIf $f$ and $g$ are absolutely integrable then\n\t\\[ \\int_\\Omega f+g \\; d\\mu\n\t\t= \\int_\\Omega f \\; d\\mu\n\t\t+ \\int_\\Omega g \\; d\\mu. \\]\n\tThe ``absolutely integrable'' hypothesis can be dropped\n\tif $f$ and $g$ are nonnegative.\n\t\\ii (Scaling) If $f$ is absolutely integrable and $c \\in \\RR$\n\tthen $cf$ is absolutely integrable and\n\t\\[ \\int_\\Omega cf \\; d\\mu = c \\int_\\Omega f \\; d\\mu. \\]\n\tThe ``absolutely integrable'' hypothesis can be dropped\n\tif $f$ is nonnegative and $c > 0$.\n\t\\ii (Monotoncity)\n\tIf $f$ and $g$ are absolutely integrable and $f \\le g$, then\n\t\\[ \\int_\\Omega f \\; d\\mu \\le \\int_\\Omega g \\; d\\mu. \\]\n\tThe ``absolutely integrable'' hypothesis can be dropped\n\tif $f$ and $g$ are nonnegative.\n\\end{itemize}\nThere are more famous results like monotone/dominated convergence\nthat are also true, but we won't state them here\nas we won't really have a use for them in the context of probability.\n(They appear later on in a bonus chapter.)\n\n\\section{Relation to Riemann integrals (or: actually computing Lebesgue integrals)}\nFor closed intervals, this actually just works out of the box.\n\\begin{theorem}\n\t[Lebesgue integral generalizes Riemann integral]\n\tLet $f \\colon [a,b] \\to \\RR$ be a Riemann integrable function\n\t(where $[a,b]$ is equipped with the Borel measure).\n\tThen $f$ is also Lebesgue integrable and the integrals agree:\n\t\\[ \\int_a^b f(x) \\; dx = \\int_{[a,b]} f \\; d\\mu. \\]\n\\end{theorem}\n\nThus in practice, we do all theory with Lebesgue integrals (they're nicer),\nbut when we actually need to compute $\\int_{[1,4]} x^2 \\; d\\mu$\nwe just revert back to our usual antics with the\nFundamental Theorem of Calculus.\n\\begin{example}\n\t[Integrating $x^2$ over {$[1,4]$}]\n\tReprising our old example:\n\t\\[ \\int_{[1,4]} x^2 \\; d\\mu\n\t\t= \\int_1^4 x^2 \\; dx\n\t\t= \\frac13 \\cdot 4^3 - \\frac13 \\cdot 1^3 = 21.  \\]\n\\end{example}\n\nThis even works for \\emph{improper} integrals,\nif the functions are nonnegative.\nThe statement is a bit cumbersome to write down, but here it is.\n\\begin{theorem}\n\t[Improper integrals are nice Lebesgue ones]\n\tLet $f \\ge 0$ be a \\emph{nonnegative}\n\tcontinuous function defined on $(a,b) \\subseteq \\RR$,\n\tpossibly allowing $a = -\\infty$ or $b = \\infty$.\n\tThen\n\t\\[ \\int_{(a,b)} f \\; d\\mu\n\t\t= \\lim_{\\substack{a' \\to a^+ \\\\ b' \\to b^-}}\n\t\t\\int_{a'}^{b'} f(x) \\; dx \\]\n\twhere we allow both sides to be $+\\infty$\n\tif $f$ is not absolutely integrable.\n\\end{theorem}\nThe right-hand side makes sense since $[a',b'] \\subsetneq (a,b)$\nis a compact interval on which $f$ is continuous.\nThis means that improper Riemann integrals of nonnegative\nfunctions can just be regarded as Lebesgue ones\nover the corresponding open intervals.\n\nIt's probably better to just look at an example though.\n\\begin{example}\n\t[Integrating $1/\\sqrt{x}$ on $(0,1)$]\n\tFor example, you might be familiar with improper integrals like\n\t\\[ \\int_0^1 \\frac{1}{\\sqrt x} \\; dx\n\t\t\\defeq \\lim_{\\eps \\to 0^+}\n\t\t\\int_\\eps^1 \\frac{1}{\\sqrt x} \\; dx\n\t\t= \\lim_{\\eps \\to 0^+} \\left( 2\\sqrt{1} - 2\\sqrt{\\eps} \\right) = 2.\n\t\\]\n\t(Note this appeared before as \\Cref{prob:improper}.)\n\tIn the Riemann integration situation, we needed the limit as $\\eps \\to 0^+$\n\tsince otherwise $\\frac{1}{\\sqrt x}$ is not defined as a function $[0,1] \\to \\RR$.\n\tHowever, it is a \\emph{measurable nonnegative}\n\tfunction $(0,1) \\to [0,+\\infty]$, and hence\n\t\\[ \\int_{(0,1)} \\frac{1}{\\sqrt x} \\; d\\mu = 2. \\]\n\\end{example}\n\nIf $f$ is not nonnegative, then all bets are off.\nIndeed \\Cref{prob:sin_improper} is the famous counterexample.\n\n\\section{\\problemhead}\n\n\\begin{sproblem}\n\t[The indicator of the rationals]\n\t\\label{prob:1QQ}\n\tTake the indicator function\n\t$\\mathbf 1_{\\QQ} \\colon \\RR \\to \\{0,1\\} \\subseteq \\RR$\n\tfor the rational numbers.\n\t\t\\begin{enumerate}[(a)]\n\t   \\ii Prove that $\\mathbf{1}_\\QQ$ is not Riemann integrable.\n\t   \\ii Show that $\\int_\\RR \\mathbf{1}_\\QQ$ exists\n\t   and determine its value --- the one you expect!\n   \\end{enumerate}\n\\end{sproblem}\n\n\\begin{dproblem}\n\t[An improper Riemann integral with sign changes]\n\t\\label{prob:sin_improper}\n\tDefine $f \\colon (1,\\infty) \\to \\RR$ by $f(x) = \\frac{\\sin(x)}{x}$.\n\tShow that $f$ is not absolutely integrable,\n\tbut that the improper Riemann integral\n\t\\[ \\int_1^\\infty f(x) \\; dx \\defeq\n\t\t\\lim_{b \\to \\infty}\n\t\t\\int_a^b f(x) \\; dx \\]\n\tnonetheless exists.\n\\end{dproblem}\n", "meta": {"hexsha": "9129a24aaaa5114af1dc4ec6981d9552f6db2423", "size": 9441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/measure/lebesgue-int.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/measure/lebesgue-int.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/measure/lebesgue-int.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": 39.5020920502, "max_line_length": 83, "alphanum_fraction": 0.6967482258, "num_tokens": 3036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6427202089040678}}
{"text": "\\documentclass[12pt]{article}\n\n% PACKAGES\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{float}\n\\usepackage{graphicx}\n\\usepackage{enumerate}\n%\\usepackage{mathtools}\n\\usepackage{hyperref}\n\n% CUSTOM STYLES\n%\\providecommand{\\e}[1]{\\ensuremath{\\times 10^{#1}}}\n%\\DeclarePairedDelimiter\\abs{\\lvert}{\\rvert}%\n\n\\usepackage{listings}\n\\usepackage{color}\n\n\\definecolor{dkgreen}{rgb}{0,0.6,0}\n\\definecolor{gray}{rgb}{0.5,0.5,0.5}\n\\definecolor{mauve}{rgb}{0.58,0,0.82}\n\n\\lstset{frame=tb,\n  language=Mathematica,\n  aboveskip=3mm,\n  belowskip=3mm,\n  showstringspaces=false,\n  columns=flexible,\n  basicstyle={\\small\\ttfamily},\n  numbers=none,\n  numberstyle=\\tiny\\color{gray},\n  keywordstyle=\\color{blue},\n  commentstyle=\\color{dkgreen},\n  stringstyle=\\color{mauve},\n  breaklines=true,\n  breakatwhitespace=true\n  tabsize=3\n}\n\n\\restylefloat{table}\n\n% METADATA\n\\title{\\textbf{FPGA Implementation of the Fast Fourier Transform}}\n\\date{December 2, 2014}\n\\author{Garrett Massman and Cory Walker}\n\n\\begin{document}\n\n  \\maketitle\n  \\clearpage\n\n  \\section*{Introduction}\n    In this project we implemented a fast Fourier transform algorithm on a Xilinx FPGA using VHDL. The primary motivation of our project was to digitally analyze musical signals, but the use cases for an FFT chip far surpass that specific use case. \\\\\n    \n    As a very general overview, our completed device functions by sampling an analog signal for a set amount of time and storing the data into an input buffer in BRAM. Next, the signal is is processed using an FT controller and a complex ALU and stored in an output buffer. Finally, a microcontroller can then read the output buffer over a standard SPI protocol. From there the processed frequency domain data can be sent to a computer for further processing or any other device.\n\n  \\section*{Theory}\n    To understand the discrete Fourier transform, one must first analyze its analogous continuous    time form.\n    This is written most simply as\n    \\begin{align*}\n    &X(j\\omega) = \\int_{-\\infty}^{\\infty} x(t) e^{-j \\omega t}\\,dt\n    \\end{align*}\n    which defines the transform of a continuous time signal $f(t)$.\n    Without getting into too many details, it defines the signal as a combination of sinusoids,      making it a very useful tool for real world applications.\\\\\n\n    The discrete Fourier transform (DFT) is simply a reduction of the continuous Fourier transform   into a discrete sample space.\n    In other words, if we let $x_n$ represent a sampled version of the continuous time function      $x(t)$ with a total of $N$ samples, we can replace the integral with a summation over the series, as shown below.\n    \\begin{align*}\n        &X_k = \\sum\\limits_{n=0}^{N-1} x_n e^{\\frac{-j2\\pi kn}{N}}\n    \\end{align*}\n    As with the continuous time case, this series gives us a glimpse into the component elements of  our original signal.\n    However, it is rather costly to compute, requiring a time complexity of $O(N^2)$.\n    For each value $X_k$, a series of values from $n = 0$ to $N - 1$ must be generated and summed,   using up valuable computer resources.\n    Thus, calculating the DFT in this way is very inefficient, so we instead turn to the Fast  Fourier transform.\\\\\n\n    In order to perform this operation more quickly, we utilized the Cooley-Tukey FFT algorithm implemented through the Xilinx CoreGen FFT module.\n    One requirement is that our input is strictly a power of 2.\n    That is because the algorithm works by recursively finding the FFT of smaller and smaller sample sizes of $x_n$, which arises from the fact that the transform itself is periodic.\n    The transform function can be broken into the sum of its even and odd components,\n    \\begin{align*}\n        &X_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m}e^{-\\frac{2\\pi i}{N} (2m)k} + \\sum \\limits_{m=0}^{N/ 2-1} x_{2m+1} e^{-\\frac{2\\pi i}{N} (2m+1)k}\n    \\end{align*}\n    This equation can further be simplified by making the substitutions\n    \\begin{align*}\n        &E_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m}e^{-\\frac{2\\pi i}{N} (2m)k}\n        &O_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m+1} e^{-\\frac{2\\pi i}{N/2} mk}\n    \\end{align*}\n    giving us\n    \\begin{align*}\n        &X_k = E_k + e^{-\\frac{2\\pi i}{N} k} O_k\n    \\end{align*}\n    The expression $e^{-\\frac{2\\pi i}{N}k}$ is commonly called the \\textit{twiddle factor}.\n    Furthermore, because of the periodicity of the transform, we can calculate respective even and   odd components simultaneously\n    \\begin{align*}\n        &E_k = E_{k+\\frac{N}{2}}\n        &O_k = O_{k+\\frac{N}{2}}\n    \\end{align*}\n  \n  \\section*{Motivation}\n    The FFT is a very common operation used in many digital signal processing tasks.\n    Digital signal processors are usually very highly tuned to perform a series of dedicated tasks quickly, and have very little flexability in the way of general purpose usage.\n    This is both a blessing and a curse, as they rarely need to be reprogrammed, but are also limited to the range of tasks they can accomplish.\n    High end DSPs utilize parallelism to complete mathematical calculations quickly.\n    Because of their dedicated nature, DSPs also tend to be rather costly, upwards of \\$32 for a SHARC model chip from Analog Electronics.\\\\\n\n    FPGAs are primarily a large collection of configurable logic blocks that can be wired together to run in parallel, so why not try and use one in place of an expensive DSP?\n    By taking the heavy computations off of a typical CPU and putting the burden onto an FPGA, the processor could be freed up to execute any number of instructions until the heavy computations are complete.\n    This hybrid model has actually become quite popular in the past several years, and several products such as some of Intel's Xeon chips have FPGAs integrated onboard.\n    This can offset the costs for companies who formerly may have been inclined to build expensive ASICs and instead shift their focus onto a new platform.\n    A parallel CPU/FPGA integrated system is beyond the scope of this project, but instead a simple model using a Digilent Basys board and an Arduino are built to illustrate the principles.\n\n  \\section*{System Overview}\n    A critical task in building our FFT device was converting an arbitrary waveform into the SPI signal input that the FPGA expected. This requires the use of a fast analog to digital converter. The Xilinx Spartan 3E FPGA does not come with an onboard ADC. Because of this, a large percentage of the work was actually electronics work done outside of the FPGA:\n\n    \\begin{figure}[H]\n      \\centering\n      \\includegraphics[width=100mm]{full_system.JPG}\n      \\caption{Full system including ADC PMOD and audio signal module.}\n      \\label{overflow}\n    \\end{figure}\n    \n    These external components condition the signal and then send the digital signal into the FPGA at the right voltage level. In addition, the FPGA's output buffer must be read out by an Arduino microcrontroller and sent to a computer with the right software to parse and display the output. We call these external components macro-components and we call the FPGA internal blocks micro-components.\n  \n  \\section*{Macro-Component Descriptions}\n    The required components external to the FPGA are as follows:\n    \\subsection*{Audio signal module}\n      \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=60mm]{audio_sig_mod.JPG}\n        \\caption{Audio signal circuit board with audio connector}\n        \\label{overflow}\n      \\end{figure}\n      The audio signal module tailors the input audio signal for conversion with the ADC. Traditional audio signals are centered around 0 V and are in the negative voltage range half the time. This module biases the signal by 2.5 V, allowing for a 5 V variation peak to peak in the audio signal without any clipping. This module also provides filtering capacitors that remove most of the supply rail noise that may be present.\n\n    \\subsection*{ADC PMOD}\n      \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=75mm]{adc_pmod.JPG}\n        \\caption{ADC PMOD circuit board}\n        \\label{overflow}\n      \\end{figure}\n      The ADC PMOD accepts any input analog input and converts it to a SPI bus that the FPGA can read. The analog signal is fed into the onboard ADS7818 chip. Unfortunately, this chip operates at 5 V but the FPGA operates at 3.3 V. Because of this, there is a voltage divider to drop the voltage down to the FPGA. For FPGA output to be read by the ADS7818, we added a Schmitt inverter IC wired as a Schmitt trigger to act as a level converter.\n      \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=100mm]{adc_logic.png}\n        \\caption{ADC interfacing}\n        \\label{overflow}\n      \\end{figure}\n      We started interfacing with the ADS7818 using an Arduino. Once we understood the protocol completely, we moved the interfacing code from the Arduino to the FPGA and started using real signal data.\n\n    \\subsection*{Arduino}\n      The Arduino functions as a means of getting the processed information out of the FPGA's BRAM. The Arduino turned out to be the main bottleneck in terms of framerate to the computer's display. We had to push the SPI and serial write functions outside of recommended bounds to get a fluid framerate on the computer display. The full software is available in the \\texttt{arduino/osc\\_binary\\_spi} directory of the source code repository.\n\n    \\subsection*{Computer software}\n      The computer software for this project is divided into two components. The first component is the Python module that facilitates the reading and decoding of the data from the serial port. It will read out 512 complex numbers and, optionally, compute the magnitude of each of those numbers. The second component is the actual display. It will use the Python module to read the device and it uses Tkinter to display the plot on the screen.\n\n  \\section*{Micro-Component Descriptions}\n    The final block diagram of our device is as follows:\n    \\begin{figure}[H]\n      \\centering\n      \\includegraphics[trim=0 500 0 30,clip,width=140mm]{vhdl_fft.pdf}\n      \\caption{Block diagram of the FFT chip}\n      \\label{overflow}\n    \\end{figure}\n    All of the blocks inside the FPGA device are referred to as micro-components.\n\n    \\begin{itemize}\n      \\item Deterministic ADC: Provides a completely predictable ADC signal to test with and substituted for a real ADC while it was shipping.\n      \\item SPI Mux: A simple multiplexer that selects between the external ADC and the deterministic ADC.\n      \\item SPI Master: An OpenCore that implements an SPI master interface. This handles the control and reading of the SPI bus from either the deterministic ADC or the external ADC.\n      \\item Capture Controller: This block reads samples from the SPI Master and stores the readings as complex numbers in the input buffer. The sample size is 512. It also communicates with the FT controller about when it finishes.\n      \\item FT controller: This block actually executes the fast Fourier transfer algorithm whenever the capture controller indicates that the input buffer is valid.\n      \\item Complex ALU: This block handles complex multiplications for the FT controller.\n      \\item OUTBUF interpreter: This block facilitates the reading of the OUTBUF by feeding words into the SPI slave module.\n      \\item SPI Slave: An OpenCore that implements an SPI slave interface. This handles the control and writing of the SPI bus, and it connects to an external microcontroller.\n    \\end{itemize}\n\n  \\section*{Simulation Results}\n\n  \\section*{Results}\n    He seemed really excited about timing results so we should probably discuss this here.\n\n  \\section*{Roadblocks}\n\n  \\section*{Future Improvements}\n\n  \\section*{Conclusion}\n\n  \\clearpage\n  \\section*{Appendix}\n\n  \\begin{thebibliography}{9}\n    \\bibitem{doin}\n      Doin, Jonny. \\emph{SPI Master/Slave Interface.} OpenCores, 16 May 2011. Web. 13 Sept. 2014. \\textless\\url{http://opencores.org/project,spi_master_slave}\\textgreater.\n    \\bibitem{reynwar}\n      Reynwar, Ben. \\emph{FFT on an FPGA.} FFT on an FPGA. N.p., n.d. Web. 13 Sept. 2014. \\textless\\url{http://www.reynwar.net/ben/docs/fft_dit/index.html}\\textgreater.\n    \\bibitem{roberts}\n      Roberts, Michael J. \\emph{Signals and Systems: Analysis Using Transform Methods and MATLAB.} New York: McGraw Hill, 2012. Print.\n    \\bibitem{satoh}\n      Satoh, Keiichi, Jubee Tada, Kenta Yamaguchi, and Yasutaka Tamura. \\emph{Complex Multiplier Suited for FPGA Structure.} Computers and Communications (2008): 341-44. Web. 13 Sept. 2014.\n    \\bibitem{tukey}\n      Wikipedia contributors. \\emph{Cooley–Tukey FFT algorithm.} Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 27 Jun. 2014. Web. 13 Sep. 2014.\n    \\bibitem{dft}\n      Wikipedia contributors. \\emph{Discrete Fourier transform.} Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 2 Sep. 2014. Web. 13 Sep. 2014.\n  \\end{thebibliography}\n\n\\end{document}\n%  \\subsection*{Overview}\n%    In this project we will implement the Cooley-Tukey Fast Fourier Transform algorithm on a Xilinx FPGA using VHDL.\n%    The primary motivation for this is to digitally analyze musical signals, regardless of the instruments they come from.\n%    Using the Cooley-Tukey algorithm, we can calculate the FFT in $O(nlog_2(n))$ time.\n%    As far as implementation, the project will be split into several main components.\n%    First, we will need to sample our audio for a set amount of time and store the data into a buffer in memory.\n%    Then, the digital signal will need to be processed using a complex ALU.\n%    Finally, the data will need to be sent to an output buffer for application specific usage.\n%    This can be in the form of a 7-segment hex display (for instance if we want to print out the fundamental frequency), or a microcontroller (if we want to plot the entire sampled spectrum by passing it to a more capable platform such as Matlab).\n%\n%  \\subsection*{Theory}\n%    To understand the discrete Fourier Transform, one must first analyze its analogous continuous time form.\n%    This is written most simply as\n%    \\begin{align*}\n%    &X(\\omega) = \\int_{-\\infty}^{\\infty} x(t) e^{-j \\omega t}\\,dt\n%    \\end{align*}\n%    which defines the transform of a continuous time signal $f(t)$.\n%    Without getting into too many details, it defines the signal as a combination of sinusoids, making it a very useful tool for real world applications.\\\\\n%    \n%    The discrete Fourier Transform (DFT) is simply a reduction of the continuous Fourier Transform into a discrete sample space.\n%    In other words, if we let $x_n$ represent a sampled version of the continuous time function $x(t)$ with a total of $N$ samples, we can replace the integral with a summation over the series, as shown below.\n%    \\begin{align*}\n%        &X_k = \\sum\\limits_{n=0}^{N-1} x_n e^{\\frac{-j2\\pi kn}{N}}\n%    \\end{align*}\n%    As with the continuous time case, this series gives us a glimpse into the component elements of our original signal.\n%    However, it is rather costly to compute, requiring a time complexity of $O(N^2)$.\n%    For each value $X_k$, a series of values from $n = 0$ to $N - 1$ must be generated and summed, using up valuable computer resources.\n%    Thus, calculating the DFT in this way is very inefficient, and we must instead turn to the Fast Fourier Transform.\\\\\n%\n%    In order to perform this operation more quickly, we can utilize the Cooley-Tukey FFT algorithm.\n%    However, the one requirement is that our input is strictly a power of 2.\n%    That is because the algorithm works by recursively finding the FFT of smaller and smaller sample sizes of $x_n$, which arises from the fact that the transform itself is periodic.\n%    The transform function can be broken into the sum of its even and odd components,\n%    \\begin{align*} \n%        &X_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m}e^{-\\frac{2\\pi i}{N} (2m)k} + \\sum \\limits_{m=0}^{N/2-1} x_{2m+1} e^{-\\frac{2\\pi i}{N} (2m+1)k}\n%    \\end{align*}\n%    This equation can further be simplified by making the substitutions\n%    \\begin{align*}\n%        &E_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m}e^{-\\frac{2\\pi i}{N} (2m)k}\n%        &O_k = \\sum \\limits_{m=0}^{N/2-1} x_{2m+1} e^{-\\frac{2\\pi i}{N/2} mk}\n%    \\end{align*}\n%    giving us\n%    \\begin{align*}\n%        &X_k = E_k + e^{-\\frac{2\\pi i}{N} k} O_k\n%    \\end{align*}\n%    The expression $e^{-\\frac{2\\pi i}{N}k}$ is commonly called the \\textit{twiddle factor}.\n%    Furthermore, because of the periodicity of the transform, we can calculate respective even and odd components simultaneously\n%    \\begin{align*}\n%        &E_k = E_{k+\\frac{N}{2}}\n%        &O_k = O_{k+\\frac{N}{2}}\n%    \\end{align*}\n%    \n%\n%\n%  \\subsection*{In Mathematica}\n%  We implemented a candidate version of the Cooley-Tukey algorithm in Mathematica. This code shows how it is possible to build a look up table of calculated results against the variables $N$ and $k$ for the calculation $e^{-\\frac{2\\pi i}{N} k}$. This table will not only save us time, but also complexity in the design by allowing us to simply look up this value.\n%  \\begin{lstlisting}\n%myfasterft[x_, capn_, s_, precomputed_] := (\n%   result = {};\n%   If[capn == 1,\n%    result = Append[result, x[[1]]],\n%    result = Join[result, myfasterft[x, capn/2, 2 s, precomputed]];\n%    result = \n%     Join[result, myfasterft[x[[s + 1 ;;]], capn/2, 2 s, precomputed]];\n%    Do[\n%     t = result[[k + 1]];\n%     result[[k + 1]] = \n%      t + precomputed[[Log2[capn]]][[k + 1]]*\n%        result[[k + capn/2 + 1]];\n%     result[[k + capn/2 + 1]] = \n%      t - precomputed[[Log2[capn]]][[k + 1]]*\n%        result[[k + capn/2 + 1]];\n%     , {k, 0, capn/2 - 1}];\n%    ];\n%   result\n%   );\n%\n%precomputedmatrix[datalen_] := (\n%  Table[\n%   Table[\n%    E^(-I*2*\\[Pi]*k/capn),\n%    {k, 0., datalen/2 - 1}\n%    ],\n%   {capn, Table[2^x, {x, 1, Log2[datalen]}]}\n%   ]\n%  )\n%\n%data = Table[N[Sin[30 2 Pi n/200] + (RandomReal[] - 1/2)], {n, 512}];\n%precomputed = precomputedmatrix[Length[data]];\n%ListLinePlot[Abs[myfasterft[data, Length[data], 1, precomputed]], PlotRange -> All]\n%  \\end{lstlisting}\n%  \\subsection*{FPGA considerations}\n%    %Describe how we plan to utilize SPI for communication, what type of logical blocks we will use and how they will work together.\n%    Because we are working with a very specialized type of hardware, we must take into consideration some limiting parameters.\n%    In particular, the Spartan3Es loaded on each BASYS board only have 72K RAM.\n%    This means that if we want a real time FFT, we will need to optimize the space we have available, and only write to it when it is absolutely necessary.\n%    We must also consider the quality of our digital input signal.\n%    There are various ADC PMODs available for the BASYS boards, which range in quality from 4.8 KHz to 1 MHz in speed.\n%    If we are only sampling audio, we probably won't need to gather any frequencies above 1200 Hz, so the lower end model should be fine.\\\\\n%\n%    Once our data has been collected and stored inside the FPGA, it needs to be processed.\n%    This is perhaps the most challenging part of the project, as we need to implement what will be called an FTC (Fourier Transform Controller) as well as a CALU (Complex Arithmetic Logic Unit).\n%    The FTC's primary function will be to keep track of the data as it moves from RAM, into the CALU, and back out into the real world.\n%    This will require some heavily synchronized logic and very tight timing control to be carried out properly.\n%    It will work in sync with the SPI input master to tell the CALU when data is ready to be read, and then clear the input buffer once the CALU has finished.\n%    It will also need to monitor the movement of data from the output buffer into whatever output stream requires it.\n%    The data may be sent directly to a microcontroller or into another component for post processing.\\\\\n%\n%    The CALU will have one primary job, which is to actually perform the FFT.\n%    From its perspective, it will only the addresses of an input buffer and an output buffer, as well as a flag that tells it when to start and stop.\n%    Because all of our calculations are being done inside of an FPGA, the CALU will be most composed of combinational logic at its core.\n%    In theory (i.e., provided enough gates), all that needs to be built is the base case of the FFT, which takes in two numbers and outputs their sum and difference.\n%    \\begin{align*}\n%        &y_0 = x_0 + e^{-\\frac{2\\pi i}{N}k}x_1\n%        &y_1 = x_0 - e^{-\\frac{2\\pi i}{N}k}x_1\n%    \\end{align*}\n%    This portion of the computation is commonly called a \\textit{butterfly}, because the system's diagram looks vaguely like a butterfly.\n%    Each of the twiddle factors included above can be calculated beforehand and stored in a lookup table for quick access before each iteration.\n%    Because we will be performing the same type of computation with them each time, they are essentially constants in our system.\\\\\n%\n%  \\subsection*{Block diagram}\n%    Over the past few weeks we have taken what we know and outlined a basic block diagram of our device:\n%    \\begin{figure}[H]\n%      \\centering\n%      \\includegraphics[trim=0 400 0 400,clip,width=140mm]{vhdl_fft.pdf}\n%      \\caption{Block diagram of the FFT chip}\n%      \\label{overflow}\n%    \\end{figure}\n%    Now that we have divided the device into several logical blocks, we can now split up the work accordingly.\n%  \\subsection*{Roadmap}\n%    In this section, we will describe the steps, in order, that need to be done. Our steps will essentially follow the data pipeline of the module:\n%    \\begin{itemize}\n%      \\item We will begin by implementing a deterministic \"ADC\" module that will emulate the interface of the real ADC but generate a fixed signal every time. We will use this signal in our own calculations so that we can then verify the outputs of the chip at each stage in the data pipeline. When we are ready to convert to real ADC signals, we can simply switch to an external ADC module using an SPI mux. This step has already been completed.\n%      \\item We will then implement the capture controller. This controller will have an SPI master unit that can read from the ADC. It will be also connected to the block RAM to write the input buffer.\n%      \\item Next, we will work on the heart of the chip, the FT controller. This controller will first simply implement the DFT algorithm. It will utilize the complex number ALU to make calculations.\n%      \\item After the FT controller, we will implement an OUTBUF interpreter that is responsible for outputting the results of the FT controller to the rest of the world using SPI.\n%      \\item Once all of this is done, we will finish converting our FT controller from using the simple DFT algorithm to the more complex Cooley-Tukey FFT algorithm.\n%      \\item If we have further time still, we will build interesting demonstrations of this device.\n%    \\end{itemize}\n%  \\subsection*{Resources}\n%    While our aim is to implement the entire Fast Fourier Transform with our own code, there are some blocks of our design that are common practice to reuse. Those blocks are the SPI modules. While SPI is not a complicated communication protocol, it requires a fair amount of time to implement. There is a great resource online called OpenCores. This resource is essentially a collection of open source HDL modules that can be freely used in designs. We will be using the \"SPI Master/Slave Interface\" module a few times in our design to implement SPI.\n%  \\subsection*{Possible extensions}\n%    The Fast Fourier Transform algorithm applied to an arbitrary voltage signal is very useful. Because our final chip will provide such capability, we have the option of using our newly-designed chip with multiple different applications. \\\\\n%  \n%    One of our ideas is to attach a microphone and a preamp and use the frequency-domain signal to determine the musical note being played. We could also build a tuner for a guitar. \\\\\n%    \n%    Additionally, we could connect an audio signal directly from any music player and display a graphic equalizer effect using either a computer or microcontroller that will interface with our chip. \\\\\n%\n%    Finally, provided we are able to tune our chip and ADC to operate fast enough, we might be able to build a radio wave analyzer for very long wavelength signals. This device would almost certainly be too slow for any serious RF work, but it would still be an interesting extension. \\\\\n%\n%    These extensions are not crucial to our design but might serve as a great demonstration when we present the device to the class.\n", "meta": {"hexsha": "8c7bab8f2b9fb396e533b43f30495093ad039d1d", "size": 24695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/final_report/final_report.tex", "max_stars_repo_name": "corywalker/vhdl_fft", "max_stars_repo_head_hexsha": "b7fa75ed1f90a05fcc2521495019c1561df4eaba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-30T03:39:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-30T03:39:35.000Z", "max_issues_repo_path": "docs/final_report/final_report.tex", "max_issues_repo_name": "corywalker/vhdl_fft", "max_issues_repo_head_hexsha": "b7fa75ed1f90a05fcc2521495019c1561df4eaba", "max_issues_repo_licenses": ["MIT"], "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/final_report/final_report.tex", "max_forks_repo_name": "corywalker/vhdl_fft", "max_forks_repo_head_hexsha": "b7fa75ed1f90a05fcc2521495019c1561df4eaba", "max_forks_repo_licenses": ["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.5972222222, "max_line_length": 552, "alphanum_fraction": 0.7276371735, "num_tokens": 6338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6427202043594289}}
{"text": "\\section{Summary and Outlook}\\label{se:Summary}\n\nWe have developed IMEX schemes suitable for a two-moment model of neutrino transport that obey Fermi-Dirac statistics.\nThe scheme employs algebraic closure based on Fermi-Dirac statistics, high-order discontinuous Galerkin methods for spatial discretization, and convex-invariant time integration to maintain realizability of the moments.  \nSince the realizable domain is convex and its convexity can be inherited by a convex combination, a scheme having convex combinations as its stages can preserve the realizable domain.\nThis encouraged us to construct realizability-preserving time integrators, realizability-preserving IMEX schemes, and a method with a realizability-preserving IMEX time integrator and high-order DG method.  \n\nIn the applications that motivate this work, the neutrino distribution function can vary from 0 to 1.  \nHence, we have considered algebraic closures based on Fermi-Dirac statistics for both low and high occupancy.  \nAmong the seven algebraic closures we considered -- Kershaw~\\cite{kershaw_1976}, Wilson~\\cite{wilson_1975,leblancWilson_1970}, Levermore~\\cite{levermore_1984}, Minerbo~\\cite{minerbo_1978}, Janka 1~\\cite{janka_1991}, Janka 2~\\cite{janka_1992}, and Cernohorsky \\& Bludman~\\cite{cernohorskyBludman_1994} -- only the Cernohorsky \\& Bludman closure obeys Fermi-Dirac statistics for all occupancies.  \nAs a result, we employed the Cernohorsky \\& Bludman closure for the neutrino stationary state test in Section~\\ref{se: Neutrino Stationary State Test}.\nWe also ran our code with Minerbo closure, IMEX PC2, IMEX SSP2332 and IMEXRKCB2 schemes, and the results show that only PD-ARS schemes have stability.\nIn addition, closures have impact on the simulation result.\nAs we observed, both using PD-ARS scheme, there are $\\sim30\\%$ difference in the neutrino number densities (and relaxation time) between the results obtained with Minerbo closure and that with CB closure.\nEven though RKCB2 with Minerbo closure luckily survived our test, the results it gave were compromised: they were closer to the results of the PD-ARS scheme with Minerbo closure than to the results of the PD-ARS scheme with CB closure.\nIn what way and to what degree the results are in fact compromised either by the closure or by a particular correction step for unrealizable moments are difficult to determine fully and is left for further study.\n\n\nTwo PD-ARS schemes are proposed.\nThe one with SSPRK2 has second-order accuracy while the other with SSPRK3 has third-order accuracy, and both have the strong-stability preserving property in the streaming limit.  \nTheir accuracy was demonstrated on problems with known smooth solutions in streaming, absorption, and scattering-dominated regimes.\nThe neutrino transport test with emission, absorption, and isoenergetic scattering through a stationary background, was designed to test the convex-invariance of our PD-ARS schemes. \nThe neutrino stationary state test shows that a method combining an algebraic closure based on Fermi-Dirac statistics and convex-invariant time integration is promising for robust CCSN simulation.\n\nIn this work, we adopted Cartesian coordinates, a linear collision term, and a fixed material background.\nMore realistic problems of scientific interest, such as with energy-exchanging scattering and relativistic effects, are left for future research.", "meta": {"hexsha": "ded3061c2c0735cf68ec54c950d98182daba3dae", "size": 3392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/Astronum_2018/sections/Conclusion.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/Astronum_2018/sections/Conclusion.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/Astronum_2018/sections/Conclusion.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": 130.4615384615, "max_line_length": 395, "alphanum_fraction": 0.8186910377, "num_tokens": 764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6427202013011177}}
{"text": " \\chapter{Linear Solver}\n\nIn many applications one of the main problems is to find the solution of a linear system. This system may arise form an optimisation or, like here, a discretised PDE. In this chapter we will go through the two methods which this is done.\n\n\\section{Direct Methods}\n\nSuppose you are given a linear system of the form\n$$Ax = b$$\nwhere $A$ is a real $n\\times n$ non-singular matrix and right hand side vector $b \\in \\mathcal{R}^n$, where the aim is to solve for the vector $x \\in \\mathcal{R}^n$. All direct methods are based on Gaussian elimination.\n\n\\subsection{Software}\n\nUMFPACK \\cite{Davis:2004:CPS:992200.992205,Davis:2004:AUV:992200.992206,Davis:1999:CUM:305658.287640,davis1997unsymmetric}, PASTIX \\cite{henon2002pastix}, SuperLU \\cite{superlu_ug99,li05} and MUMPS \\cite{amestoy2000multifrontal,amestoy2001fully,amestoy2006hybrid}\n\n\n\\section{Iterative Methods}\n\n\n\n", "meta": {"hexsha": "b3d7f96d4116927c047da4eb260a48d98b5e0fce", "size": 893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MHD/THESISnew/LinearSolver/LinearSolver.tex", "max_stars_repo_name": "wathen/PhD", "max_stars_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-10-25T13:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T21:27:30.000Z", "max_issues_repo_path": "MHD/THESISnew/LinearSolver/LinearSolver.tex", "max_issues_repo_name": "wathen/PhD", "max_issues_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MHD/THESISnew/LinearSolver/LinearSolver.tex", "max_forks_repo_name": "wathen/PhD", "max_forks_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-28T16:12:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-13T13:59:44.000Z", "avg_line_length": 44.65, "max_line_length": 263, "alphanum_fraction": 0.7782754759, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6427077937288785}}
{"text": "\\section{Randomized Algorithms}\n\\subsection{Sampling based randomized algorithm (SRA)}\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)]\n\tConsider 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\t\\begin{enumerate}\n\t\t\\item $\\sigma_{min}^2(X U_A) \\geq 1/\\sqrt{2}; $ \\\\\n\t\t\\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\t\\end{enumerate}\n\tfor some $\\epsilon \\in (0,1).$\n\t\n\tThen the solution $\\tilde{x}_{opt}$ to the least squares approximation problem (\\ref{ACT}) satisfies:\n\t\\begin{enumerate}\n\t\t\\item $\\| A \\tilde{x}_{opt} - b\\|_2 \\leq (1+ \\epsilon) \\mathcal{Z} $ , and \\\\\n\t\t\\item $\\| x_{opt} - \\tilde{x}_{opt} \\|_2 \\leq \\frac{1}{\\sigma_{min}(A)} \\sqrt{\\epsilon} \\mathcal{Z}. $\n\t\\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\t\\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],$\n\tand $e_{ir}$ is the standard basis. \\\\\n\t\\item $H \\in \\mathbb{R}^{m \\times m}$ is the Hadamard transform matrix defined recursively by\n\t$$\n\tH_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\t$$\\\\\n\t\\item $D \\in \\mathbb{R}^{m \\times m}$ is the diagonal matrix with\n\t$$\n\tD_{ii} = \\begin{cases} &+1, \\quad \\text{with probability} \\quad 1/2;\\\\ &-1 \\quad \\text{with probability} \\quad 1/2. \\end{cases}\n\t$$\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}\n\tLet $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\t$$\n\t\\| (HDU)_{i} \\|_2^2 \\leq \\frac{2n \\ln(40 m n)}{m}, \\quad \\forall i \\in [m].\n\t$$\n\\end{lemma}\n\n%------------------------------------------------\n\n\n\\begin{theorem}[Convergence and Complexity of SRA]\n\tSuppose $A,b$ and $\\epsilon$ satisfy the input requirement of SRA. Run SRA with\n\t\\begin{equation}\\label{eq22}\n\tr = max \\left( 48^2 n \\ln(40 mn) \\ln(100^2 n \\ln(40 mn)) , 40n \\ln(40 mn) /\\epsilon \\right)\n\t\\approx O(n/\\epsilon).\n\t\\end{equation}\n\tand return $\\tilde{x}_{opt}.$ Then, with probability at least $0.8$, the following claims hold:\n\t\\begin{enumerate}\n\t\t\\item $\\tilde{x}_{opt}$ satisfies $\\| A \\tilde{x}_{opt} - b \\|_2  \\leq (1 + \\epsilon) \\mathcal{Z}; $ \\\\\n\t\t\\item If we assume that $\\| U_A  U_A^T b \\|_2 \\geq \\gamma \\|b\\|_2 $ for some $0< \\gamma \\leq 1$ then\n\t\t$$\n\t\t\\| x_{opt} - \\tilde{x}_{opt}\\|_2 \\leq \\sqrt{\\epsilon} \\left( \\kappa(A) \\sqrt{\\gamma^{-2} -1} \\right) \\| x_{opt}\\|_2.\n\t\t$$\\\\\n\t\t\\item $m(n+1) + 2m(n+1)log_2(r+1) + O(rn^2)$ time suffices to compute the solution $\\tilde{x}_{opt}. $\n\t\\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\t\\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\t\\item $T \\in \\mathbb{R}^{k \\times m}$ is a randomized matrix given by\n\t$$\n\tT_{ij} = \\begin{cases} &+ \\sqrt{1/kq} \\quad \\text{with probability} \\quad q/2, \\\\\n\t&-  \\sqrt{1/kq} \\quad \\text{with probability} \\quad q/2, \\\\\n\t& 0 \\quad \\text{with probability} \\quad 1-q.\n\t\\end{cases}\n\t$$\n\\end{itemize}\n$$\\tilde{x}_{opt} = (THDA)^{\\dagger} THDb. $$\n\n%------------------------------------------------\n\n\\begin{theorem}[Convergence and Complexity of PRA]\n\tSuppose $A,b$ and $\\epsilon$ satisfy the input requirement of FRA. Run FRA with\n\t\\begin{equation}\n\tq \\geq \\frac{C_q n \\ln(40mn)}{m} (2 \\ln(m) + 16n + 16);\n\t\\end{equation}\n\t\\begin{equation}\n\tk \\geq max \\left( C_k (118^2 n + 98^2), \\frac{60n}{\\epsilon} \\right)\n\t\\end{equation}\n\tand return $\\tilde{x}_{opt}.$ Then, with probability at least $0.8$, the following claims hold:\n\t\\begin{enumerate}\n\t\t\\item $\\tilde{x}_{opt}$ satisfies $\\| A \\tilde{x}_{opt} - b \\|_2  \\leq (1 + \\epsilon) \\mathcal{Z}; $ \\\\\n\t\t\\item If we assume that $\\| U_A  U_A^T b \\|_2 \\geq \\gamma \\|b\\|_2 $ for some $0< \\gamma \\leq 1$ then\n\t\t$$\n\t\t\\| x_{opt} - \\tilde{x}_{opt}\\|_2 \\leq \\sqrt{\\epsilon} \\left( \\kappa(A) \\sqrt{\\gamma^{-2} -1} \\right) \\| x_{opt}\\|_2.\n\t\t$$\\\\\n\t\t\\item $m(n+1) + 2m(n+1)log_2(mkq+1) + O(kn^2)$ time suffices to compute the solution $\\tilde{x}_{opt}. $\n\t\\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\t\\begin{enumerate}\n\t\t\\item Compute $E = TA$, where $T$ is the $r \\times m$ SRFT defined as follows, with $m \\geq r \\geq n. $ \\\\\n\t\t\\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\t\t\\item Solve a preconditioned Least Squares Problem\n\t\t$$\n\t\t\\| AP^{-1} y - b\\|\n\t\t$$\n\t\tusing PCG where $P = R \\Pi$ is the preconditioning matrix.\n\t\\end{enumerate}\n\n\n%------------------------------------------------\n\\subsubsection{Complexity for A Fast Randomized Algorithm (FAR)}\n\t\\begin{enumerate}\n\t\t\\item Applying $T$ to every column of $A$ : $O(mnlog(r))$.  \\\\\n\t\t\\item Computing the pivoted QR decomposition of $E$ : $O(n^2r) . $ \\\\\n\t\t\\item Applying $T$ to $b$: O(mlog(r)). Applying $Q^*$ to $Tb$: $O(nr)$.\n\t\t\n\t\tApplying $P^{-1} = \\Pi^{-1} R^{-1}$ to $Q^* Tb$ : $O(n^2). $ \\\\\n\t\t\\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\t\t\\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\t\t\\item Applying $P^{-1}$ to $y$ : $O(n^2). $\n\t\\end{enumerate}\nThus\n{\\color{red}\n\t$$\n\tC_{theoretical} = O((log(r) + \\kappa(AP^{-1}) |log(\\epsilon)|) mn +n^2r).\n\t$$}\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\t\\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\t\\item $F$ is the $m \\times m$ discrete Fourier transform. \\\\\n\t\\item $D = diag(d_1,d_2,\\cdots,d_m)$\n\twhere $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\t\\item $\\Pi$ and $\\tilde{\\Pi}$ are permutation matrices chosen independently and uniformly at random. \\\\\n\t\\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\t\\item\n\t$\\Theta_{m \\times m} = \\begin{bmatrix} cos(\\theta_1)& sin(\\theta_1) & 0& \\cdots &0\\\\\n\t- sin(\\theta_1)  & cos(\\theta_1) & 0 & \\cdots & 0 \\\\\n\t0 & 0 & 1 & \\cdots & 0 \\\\\n\t\\cdots & \\cdots & \\cdots & \\cdots & \\cdots  \\\\\n\t0 & 0 &0 & \\cdots & 1\n\t\\end{bmatrix}\n\t\\cdots\n\t\\begin{bmatrix} 1& \\cdots & 0& 0  &0\\\\\n\t\\cdots  & \\cdots  & \\cdots & \\cdots & \\cdots \\\\\n\t0 & \\cdots & 1 & 0 & 0 \\\\\n\t0 & \\cdots & 0 & cos(\\theta_{m-1})& sin(\\theta_{m-1}) \\\\\n\t0 & \\cdots &0 &  -sin(\\theta_{m-1}) & cos(\\theta_{m-1})\n\t\\end{bmatrix} ,$\n\t\n\t\n\twhere $\\theta_k, \\quad k =1 ,\\cdots m-1$ are i.i.d. real random variables drawn uniformly from $[0,2\\pi]$.\n\tSo is $\\tilde{\\Theta}$, but defined with different $\\tilde{\\theta}_k$.\n\t\n\\end{itemize}\n\n%------------------------------------------------\n\n\\subsubsection{Why SRFT works?}\n\\begin{corollary}\n\tSuppose 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.\n\tThen, 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)]\n\tSuppose 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\t$$\n\tA_{m \\times n} = U_{m \\times n} \\Sigma_{n \\times n} V^*_{n \\times n}.\n\t$$\n\tSuppose in addition that $T$ is an $r \\times m$ matrix such that the $r \\times n$ matrix $TU$ has full rank.\n\tThen\n\t$$\n\tT_{r \\times m} A_{m \\times n} = Q_{r \\times n} P_{n \\times n},\n\t$$\n\twhere $Q$ has orthonormal columns.\n\tAnd\n\t$$\n\t\\kappa(AP^{-1}) = \\kappa(TU).\n\t$$\n\\end{theorem}\n\\small{$r \\geq 4n^2$ guarantees $\\kappa(TU) \\leq 3.$}\n", "meta": {"hexsha": "2bb304e2b36ec375d6789a2d8d2d7cfa33ee6023", "size": 10579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Rand_Algo.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/Rand_Algo.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/Rand_Algo.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.356557377, "max_line_length": 323, "alphanum_fraction": 0.6016636733, "num_tokens": 3799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6425962649680421}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Contents: Math typesetting with LaTeX\n% $Id: math.tex 534 2015-04-09 13:03:16Z oetiker $\n%\n% Changes by Stefan M. Moser: 2008/10/22\n%\n% -Section 2: \"Single Equations\": added comment about preference of\n%  equation* over \\[\n% -Replaced (almost) all examples with \\[ by equation*\n% -New section 4: \"Single Equations that are Too Long: multline\"\n% -New section 5: \"Multiple Equations\"\n% -Section 6: \"Arrays and Matrices\": made a full section and added\n%  some material\n% -Section 9: \"Theorems, Lemmas, ...\": added a subsection about proofs\n%  with new material\n%\n% Other Changes:\n% -in lshort.sty: \n%    *example environment adapted: changed in three places\n%     \\textwidth by \\linewidth. This is necessary for\n%     example-environment within a itemize-list.\n%    *added \\RequirePackage[retainorgcmds]{IEEEtrantools}\n%\n% THINGS TO DO:\n% -adapt typesetting of new sections to rest of lshort, including all\n%  the usual commands used so far. In particular, I guess we have to\n%  get rid of the \\verb-commands everywhere\n% -include index-commands\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n \n\\chapter{Typesetting Mathematical Formulae}\n\n\\begin{intro}\n  Now you are ready! In this chapter, we will attack the main strength\n  of \\TeX{}: mathematical typesetting. But be warned, this chapter\n  only scratches the surface. While the things explained here are\n  sufficient for many people, don't despair if you can't find a\n  solution to your mathematical typesetting needs here. It is highly likely\n  that your problem is addressed in \\AmS-\\LaTeX{}.\n\\end{intro}\n  \n\n\n\\section{The \\texorpdfstring{\\AmS}{AMS}-\\LaTeX{} bundle}\n\nIf you want to typeset (advanced) \\wi{mathematics}, you should\nuse \\AmS-\\LaTeX{}. The \\AmS-\\LaTeX{} bundle is a collection of packages and classes for\nmathematical typesetting. We will mostly deal with the \\pai{amsmath} package\nwhich is a part of the bundle. \\AmS-\\LaTeX{} is produced by The \\emph{\\wi{American Mathematical Society}} \nand it is used extensively for mathematical typesetting. \\LaTeX{} itself does provide\nsome basic features and environments for mathematics, but they are limited (or\nmaybe it's the other way around: \\AmS-\\LaTeX{} is \\emph{unlimited}!) and\nin some cases inconsistent. \n\n\\AmS-\\LaTeX{} is a part of the required distribution and is provided\nwith all recent \\LaTeX{} distributions.\\footnote{If yours is missing it, go to\n  \\CTAN|pkg/amslatex|.} In this chapter, we assume\n  \\pai{amsmath} is loaded in the preamble; \\verb|\\usepackage{amsmath}|.\n\n\\section{Single Equations}\n  \nA mathematical formula can be typeset in-line within a paragraph (\\emph{\\wi{text style}}), or the paragraph can be broken and the formula typeset separately\n(\\emph{\\wi{display style}}). Mathematical \\wi{equation}s \n\\emph{within} a paragraph are entered \\index{$@\\texttt{\\$}} %$\nbetween \\texttt{\\$} and \\texttt{\\$}:\n\\begin{example}\nAdd $a$ squared and $b$ squared\nto get $c$ squared. Or, using \na more mathematical approach:\n$a^2 + b^2 = c^2$\n\\end{example}\n\\begin{example}\n\\TeX{} is pronounced as \n$\\tau\\epsilon\\chi$\\\\[5pt]\n100~m$^{3}$ of water\\\\[5pt]\nThis comes from my $\\heartsuit$\n\\end{example}\n\nIf you want your larger equations to be set apart\nfrom the rest of the paragraph, it is preferable to \\emph{display} them\nrather than to break the paragraph apart.\nTo do this, you enclose them between \\verb|\\begin{|\\ei{equation}\\verb|}| and\n\\verb|\\end{equation}|.\\footnote{This is an \\textsf{amsmath} command. If you don't\nhave access to the package for some obscure reason, you can use \\LaTeX's own\n\\ei{displaymath} environment instead.} You can then \\ci{label} an equation number and refer to\nit somewhere else in the text by using the \\ci{eqref} command. If you want to\nname the equation something specific, you \\ci{tag} it instead.\n\\begin{example}\nAdd $a$ squared and $b$ squared\nto get $c$ squared. Or, using\na more mathematical approach\n \\begin{equation}\n   a^2 + b^2 = c^2\n \\end{equation}\nEinstein says\n \\begin{equation}\n   E = mc^2 \\label{clever}\n \\end{equation}\nHe didn't say\n \\begin{equation}\n  1 + 1 = 3 \\tag{dumb}\n \\end{equation}\nThis is a reference to \n\\eqref{clever}. \n\\end{example}\n\nIf you don't want \\LaTeX{} to number the equations, use the starred\nversion of \\texttt{equation} using an asterisk, \\ei{equation*}, or even easier, enclose the\nequation in \\ci{[} and \\ci{]}:\\footnote{\\index{equation!\\textsf{amsmath}}\n  \\index{equation!\\LaTeX{}}This is again from \\textsf{amsmath}. Standard \\LaTeX{}'s has only the \\texttt{equation} environment without the star.}\n\\begin{example}\nAdd $a$ squared and $b$ squared\nto get $c$ squared. Or, using\na more mathematical approach\n \\begin{equation*}\n   a^2 + b^2 = c^2\n \\end{equation*}\nor you can type less for the\nsame effect:\n \\[ a^2 + b^2 = c^2 \\]\n\\end{example}\nWhile \\ci{[} is short and sweet, it does not allow switching between numbered and not numbered style as easily as\n\\ei{equation} and \\ei{equation*}.\n\nNote the difference in typesetting style between \\wi{text style} and \\wi{display style}\nequations: \n\\begin{example}\nThis is text style: \n$\\lim_{n \\to \\infty} \n \\sum_{k=1}^n \\frac{1}{k^2} \n = \\frac{\\pi^2}{6}$.\nAnd this is display style:\n \\begin{equation}\n  \\lim_{n \\to \\infty} \n  \\sum_{k=1}^n \\frac{1}{k^2} \n  = \\frac{\\pi^2}{6}\n \\end{equation}\n\\end{example}\n\nIn text style, enclose tall or deep math expressions or sub\nexpressions in \\ci{smash}. This makes \\LaTeX{} ignore the height of\nthese expressions. This keeps the line spacing even.\n\n\\begin{example}\nA $d_{e_{e_p}}$ mathematical\nexpression  followed by a\n$h^{i^{g^h}}$ expression. As\nopposed to a smashed \n\\smash{$d_{e_{e_p}}$} expression \nfollowed by a\n\\smash{$h^{i^{g^h}}$} expression.\n\\end{example}\n\n\\subsection{Math Mode}\n\nThere are also differences between \\emph{\\wi{math mode}} and \\emph{text mode}. For\nexample, in \\emph{math mode}: \n\n\\begin{enumerate}\n\n\\item \\index{spacing!math mode} Most spaces and line breaks do not have any significance, as all spaces\nare either derived logically from the mathematical expressions, or\nhave to be specified with special commands such as \\ci{,}, \\ci{quad} or\n\\ci{qquad} (we'll get back to that later, see section~\\ref{sec:math-spacing}).\n \n\\item Empty lines are not allowed. Only one paragraph per formula.\n\n\\item Each letter is considered to be the name of a variable and will be\ntypeset as such. If you want to typeset normal text within a formula\n(normal upright font and normal spacing) then you have to enter the\ntext using the \\verb|\\text{...}| command (see also section \\ref{sec:fontsz} on\npage \\pageref{sec:fontsz}).\n\n\\end{enumerate}\n\\begin{example}\n$\\forall x \\in \\mathbf{R}:\n \\qquad x^{2} \\geq 0$\n\\end{example}\n\\begin{example}\n$x^{2} \\geq 0\\qquad\n \\text{for all }x\\in\\mathbf{R}$\n\\end{example}\n \nMathematicians can be very fussy about which symbols are used:\nit would be conventional here to use the `\\wi{blackboard bold}' font,\n\\index{bold symbols} which is obtained using \\ci{mathbb} from the\npackage \\pai{amssymb}.\\footnote{\\pai{amssymb} is not a part\n  of the \\AmS-\\LaTeX{} bundle, but it is perhaps still a part of your \\LaTeX{}\n  distribution. Check your distribution\n  or go to \\texttt{CTAN:/fonts/amsfonts/latex/} to obtain it.}\n\\ifx\\mathbb\\undefined\\else\nThe last example becomes\n\\begin{example}\n$x^{2} \\geq 0\\qquad\n \\text{for all } x \n \\in \\mathbb{R}$\n\\end{example}\n\\fi\nSee Table~\\ref{mathalpha} on page~\\pageref{mathalpha} and\nTable~\\ref{mathfonts} on page~\\pageref{mathfonts} for more math fonts.\n\n\n\n\\section{Building Blocks of a Mathematical Formula}\n\nIn this section, we describe the most important commands used in mathematical\ntypesetting. Most of the commands in this section will not require\n\\textsf{amsmath} (if they do, it will be stated clearly), but load it anyway.\n\n\n\\textbf{Lowercase \\wi{Greek letters}} are entered as \\verb|\\alpha|,\n \\verb|\\beta|, \\verb|\\gamma|, \\ldots, uppercase letters\nare entered as \\verb|\\Gamma|, \\verb|\\Delta|, \\ldots\\footnote{There is no\n  uppercase Alpha, Beta etc. defined in \\LaTeXe{} because it looks the same as a\n  normal roman A, B\\ldots{}} \n\nTake a look at Table~\\ref{greekletters} on page~\\pageref{greekletters} for a\nlist of Greek letters.\n\\begin{example}\n$\\lambda,\\xi,\\pi,\\theta,\n \\mu,\\Phi,\\Omega,\\Delta$\n\\end{example}\n\n\n\\textbf{Exponents, Superscripts and Subscripts} can be specified using\\index{exponent}\\index{subscript}\\index{superscript}\nthe \\verb|^|\\index{^@\\verb\"|^\"|} and the \\verb|_|\\index{_@\\verb\"|_\"|} characters.\nMost math mode commands act only on the next character, so if you\nwant a command to affect several characters, you have to group them\ntogether using curly braces: \\verb|{...}|.\n\nTable~\\ref{binaryrel} on page \\pageref{binaryrel} lists a lot of binary\nrelations like $\\subseteq$ and $\\perp$.\n\n\\begin{example}\n$p^3_{ij} \\qquad \n m_\\text{Knuth}\\qquad\n\\sum_{k=1}^3 k \\\\[5pt]\n a^x+y \\neq a^{x+y}\\qquad \n e^{x^2} \\neq {e^x}^2$\n\\end{example}\n\n\nThe \\textbf{\\wi{square root}} is entered as \\ci{sqrt}; the\n$n^\\text{th}$ root is generated with \\verb|\\sqrt[|$n$\\verb|]|. The size of\nthe root sign is determined automatically by \\LaTeX. If just the sign\nis needed, use \\verb|\\surd|.\n\nSee various kinds of arrows like $\\hookrightarrow$ and $\\rightleftharpoons$ on\nTable~\\ref{tab:arrows} on page \\pageref{tab:arrows}. \n\\begin{example}\n$\\sqrt{x} \\Leftrightarrow x^{1/2}\n \\quad \\sqrt[3]{2}\n \\quad \\sqrt{x^{2} + \\sqrt{y}}\n \\quad \\surd[x^2 + y^2]$\n\\end{example}\n\n\n\\index{dots!three}\n\\index{vertical!dots}\n\\index{horizontal!dots}\nWhile the \\textbf{\\wi{dot}} sign to indicate\nthe multiplication operation is normally left out, it is sometimes written\nto help the eye in grouping a formula.\nUse \\ci{cdot} to typeset a single centered dot. \\ci{cdots} is\nthree centered \\textbf{\\wi{dots}} while \\ci{ldots} sets the dots low (on the\nbaseline). Besides that, there are \\ci{vdots} for \nvertical and \\ci{ddots} for \\wi{diagonal dots}. There are more examples in \nsection~\\ref{sec:arraymat}.\n\\begin{example}\n$\\Psi = v_1 \\cdot v_2\n \\cdot \\ldots \\qquad \n n! = 1 \\cdot 2 \n \\cdots (n-1) \\cdot n$\n\\end{example}\n\nThe commands \\ci{overline} and \\ci{underline} create\n\\textbf{horizontal lines} directly over or under an expression:\n\\index{horizontal!line} \\index{line!horizontal}\n\\begin{example}\n$0.\\overline{3} = \n \\underline{\\underline{1/3}}$\n\\end{example}\n\nThe commands \\ci{overbrace} and \\ci{underbrace} create\nlong \\textbf{horizontal braces} over or under an expression:\n\\index{horizontal!brace} \\index{brace!horizontal} \n\\begin{example}\n$\\underbrace{\\overbrace{a+b+c}^6 \n \\cdot \\overbrace{d+e+f}^7}\n _\\text{meaning of life} = 42$\n\\end{example}\n\n\\index{mathematical!accents} To add mathematical accents such as \\textbf{small\narrows} or \\textbf{\\wi{tilde}} signs to variables, the commands\ngiven in Table~\\ref{mathacc} on page~\\pageref{mathacc} might be useful.  Wide hats and\ntildes covering several characters are generated with \\ci{widetilde}\nand \\ci{widehat}. Notice the difference between \\ci{hat} and \\ci{widehat} and the placement of\n\\ci{bar} for a variable with subscript. The \\wi{apostrophe} mark\n\\verb|'|\\index{'@\\verb\"|'\"|} gives a \\wi{prime}:\n% a dash is --\n\\begin{example}\n$f(x) = x^2 \\qquad f'(x) \n = 2x \\qquad f''(x) = 2\\\\[5pt]\n \\hat{XY} \\quad \\widehat{XY}\n \\quad \\bar{x_0} \\quad \\bar{x}_0$\n\\end{example}\n\n\n\\textbf{Vectors}\\index{vectors} are often specified by adding small\n\\wi{arrow symbols} on the tops of variables. This is done with the\n\\ci{vec} command. The two commands \\ci{overrightarrow} and\n\\ci{overleftarrow} are useful to denote the vector from $A$ to $B$:\n\\begin{example}\n$\\vec{a} \\qquad\n \\vec{AB} \\qquad\n \\overrightarrow{AB}$\n\\end{example}\n\n\nNames of functions are often typeset in an upright\nfont, and not in italics as variables are, so \\LaTeX{} supplies the\nfollowing commands to typeset the most common function names:\n\\index{mathematical!functions}\n\n\\begin{tabular}{llllll}\n\\ci{arccos} &  \\ci{cos}  &  \\ci{csc} &  \\ci{exp} &  \\ci{ker}    & \\ci{limsup} \\\\\n\\ci{arcsin} &  \\ci{cosh} &  \\ci{deg} &  \\ci{gcd} &  \\ci{lg}     & \\ci{ln}     \\\\\n\\ci{arctan} &  \\ci{cot}  &  \\ci{det} &  \\ci{hom} &  \\ci{lim}    & \\ci{log}    \\\\\n\\ci{arg}    &  \\ci{coth} &  \\ci{dim} &  \\ci{inf} &  \\ci{liminf} & \\ci{max}    \\\\\n\\ci{sinh}   & \\ci{sup}   &  \\ci{tan}  & \\ci{tanh}&  \\ci{min}    & \\ci{Pr}     \\\\\n\\ci{sec}    & \\ci{sin} \\\\\n\\end{tabular}\n\n\\begin{example}\n\\begin{equation*}\n  \\lim_{x \\rightarrow 0}\n  \\frac{\\sin x}{x}=1\n\\end{equation*}\n\\end{example}\n\nFor functions missing from the list, use the \\ci{DeclareMathOperator}\ncommand. There is even a starred version for functions with limits.\nThis command works only in the preamble so the commented lines in the\nexample below must be put into the preamble.\n\n\\begin{example}\n%\\DeclareMathOperator{\\argh}{argh}\n%\\DeclareMathOperator*{\\nut}{Nut}\n\\begin{equation*}\n  3\\argh = 2\\nut_{x=1}    \n\\end{equation*}\n\\end{example}\n\nFor the \\wi{modulo function}, there are two commands: \\ci{bmod} for the\nbinary operator ``$a \\bmod b$'' and \\ci{pmod}\nfor expressions\nsuch as ``$x\\equiv a \\pmod{b}$:''\n\\begin{example}\n$a\\bmod b \\\\\n x\\equiv a \\pmod{b}$\n\\end{example}\n\nA built-up \\textbf{\\wi{fraction}} is typeset with the\n\\ci{frac}\\verb|{...}{...}| command. In in-line equations, the fraction is shrunk to\nfit the line. This style is obtainable in display style with \\ci{tfrac}. The\nreverse, i.e.\\ display style fraction in text, is made with \\ci{dfrac}.\nOften the slashed form $1/2$ is preferable, because it looks better\nfor small amounts of `fraction material:'\n\\begin{example}\nIn display style:\n\\begin{equation*}\n  3/8 \\qquad \\frac{3}{8} \n  \\qquad \\tfrac{3}{8}\n\\end{equation*}\n\\end{example}\n\n\\begin{example}\nIn text style:\n$1\\frac{1}{2}$~hours \\qquad\n$1\\dfrac{1}{2}$~hours\n\\end{example}\n \nHere the \\ci{partial} command for \\wi{partial derivative}s is used:\n\\begin{example}\n\\begin{equation*} \n  \\sqrt{\\frac{x^2}{k+1}}\\qquad\n  x^\\frac{2}{k+1}\\qquad\n  \\frac{\\partial^2f}\n  {\\partial x^2} \n\\end{equation*}\n\\end{example}\n\nTo typeset \\wi{binomial coefficient}s or similar structures, use\nthe command \\ci{binom} from \\pai{amsmath}:\n\\begin{example}\nPascal's rule is\n\\begin{equation*}\n \\binom{n}{k} =\\binom{n-1}{k}\n + \\binom{n-1}{k-1}\n\\end{equation*}\n\\end{example}\n\nFor \\wi{binary relations} it may be useful to stack symbols over each other.\n\\ci{stackrel}\\verb|{#1}{#2}| puts the symbol given\nin \\verb|#1| in superscript-like size over \\verb|#2| which\nis set in its usual position.\n\\begin{example}\n\\begin{equation*}\n f_n(x) \\stackrel{*}{\\approx} 1\n\\end{equation*}\n\\end{example}\n\nThe \\textbf{\\wi{integral operator}} is generated with \\ci{int}, the\n\\textbf{\\wi{sum operator}} with \\ci{sum}, and the \\textbf{\\wi{product operator}}\nwith \\ci{prod}. The upper and lower limits are specified with~\\verb|^|\nand~\\verb|_| like subscripts and superscripts:\n\\begin{example}\n\\begin{equation*}\n\\sum_{i=1}^n \\qquad\n\\int_0^{\\frac{\\pi}{2}} \\qquad\n\\prod_\\epsilon\n\\end{equation*}\n\\end{example}\n\nTo get more control over the placement of indices in complex\nexpressions, \\pai{amsmath} provides the \\ci{substack} command:\n\\begin{example}\n\\begin{equation*}\n\\sum^n_{\\substack{0<i<n \\\\ \n        j\\subseteq i}}\n   P(i,j) = Q(i,j)\n\\end{equation*}\n\\end{example}\n\n\n\n\\LaTeX{} provides all sorts of symbols for \\textbf{\\wi{bracketing}} and other\n\\textbf{\\wi{delimiters}} (e.g.~$[\\;\\langle\\;\\|\\;\\updownarrow$).\nRound and square brackets can be entered with the corresponding keys and\ncurly braces with \\verb|\\{|, but all other delimiters are generated with\nspecial commands (e.g.~\\verb|\\updownarrow|).\n\\begin{example}\n\\begin{equation*}\n{a,b,c} \\neq \\{a,b,c\\}\n\\end{equation*}\n\\end{example}\n\nIf you put \\ci{left} in front of an opening delimiter and\n\\ci{right} in front of a closing delimiter, \\LaTeX{} will automatically\ndetermine the correct size of the delimiter. Note that you must close\nevery \\ci{left} with a corresponding \\ci{right}. If you\ndon't want anything on the right, use the invisible ``\\ci{right.}'':\n\\begin{example}\n\\begin{equation*}\n1 + \\left(\\frac{1}{1-x^{2}}\n    \\right)^3 \\qquad \n\\left. \\ddagger \\frac{~}{~}\\right)\n\\end{equation*}\n\\end{example}\n\nIn some cases it is necessary to specify the correct size of a\nmathematical delimiter\\index{mathematical!delimiter} by hand,\nwhich can be done using the commands \\ci{big}, \\ci{Big}, \\ci{bigg} and\n\\ci{Bigg} as prefixes to most delimiter commands:\n\\begin{example}\n$\\Big((x+1)(x-1)\\Big)^{2}$\\\\\n$\\big( \\Big( \\bigg( \\Bigg( \\quad\n\\big\\} \\Big\\} \\bigg\\} \\Bigg\\} \\quad\n\\big\\| \\Big\\| \\bigg\\| \\Bigg\\| \\quad\n\\big\\Downarrow \\Big\\Downarrow \n\\bigg\\Downarrow \\Bigg\\Downarrow$\n\\end{example}\n For a list of all delimiters available, see Table~\\ref{tab:delimiters} on page\n\\pageref{tab:delimiters}. \n\n\n\\section{Single Equations that are Too Long: multline}\n\\index{long equations}\n\\label{sec:multline}\n\nIf an equation is too long, we have to wrap it somehow. Unfortunately,\nwrapped equations are usually less easy to read than not wrapped\nones. To improve the readability, there are certain rules on how to do\nthe wrapping:\n\\begin{enumerate}\n\\item In general one should always wrap an equation \\textbf{before} an\n  equality sign or an operator.\n\\item A wrap before an equality sign is preferable to a wrap before\n  any operator.\n\\item A wrap before a plus- or minus-operator is preferable to a wrap\n  before a multiplication-operator.\n\\item Any other type of wrap should be avoided if at all possible.\n\\end{enumerate}\nThe easiest way to achieve such a wrapping is the use of the\n\\ei{multline} en\\-vi\\-ron\\-ment:\\footnote{The\n  \\texttt{multline}-environment is from \\texttt{amsmath}.}\n\\begin{example}\n\\begin{multline}\n  a + b + c + d + e + f \n  + g + h + i  \n  \\\\\n  = j + k + l + m + n \n\\end{multline}\n\\end{example}\n\\noindent\nThe difference from the \\ei{equation} environment is that an arbitrary\nline-break (or also multiple line-breaks) can be introduced. This is\ndone by putting a \\verb+\\\\+ on those places where the equation needs\nto be wrapped. Similarly to \\ei{equation*} there also exists a\n\\ei{multline*} version for preventing an equation number.\n\nOften the\n\\ei{IEEEeqnarray} environment (see section~\\ref{sec:IEEEeqnarray})\nwill yield better results.  Consider the following\nsituation:\n\\begin{example}\n\\begin{equation}\n  a = b + c + d + e + f \n  + g + h + i + j \n  + k + l + m + n + o + p  \n  \\label{eq:equation_too_long}\n\\end{equation}\n\\end{example}\n\\noindent\nHere it is actually the RHS that is too long to fit on one line. The\n\\ei{multline} environment creates the following output:\n\\begin{example}\n\\begin{multline}\n  a = b + c + d + e + f \n  + g + h + i + j \\\\\n  + k + l + m + n + o + p\n\\end{multline}\n\\end{example}\n\nThis is better than \\eqref{eq:equation_too_long}, but\nit has the disadvantage that the equality sign loses its natural\ngreater importance with respect to the plus operator in front of\n$k$. The better solution is provided by the\n\\ei{IEEEeqnarray} environment that will be discussed in detail in\nSection~\\ref{sec:IEEEeqnarray}.\n\n\\section{Multiple Equations}\n\\index{equation!multiple}\n\\label{sec:IEEEeqnarray}\n\nIn the most general situation we have a sequence of several\nequalities that do not fit onto one line. Here we need to work with\nvertical alignment in order to keep the array of equations in a nice\nand readable structure.\n\nBefore we offer our suggestions on how to do this, we start with a few\nbad examples that show the biggest drawbacks of some common solutions.\n\n\n\\subsection{Problems with Traditional Commands}\n\\label{sec:problems_traditional}\n\nTo group multiple equations the\n\\ei{align} environment\\footnote{The \\texttt{align}-environment can\n  also be used to group several blocks of equations beside each other.\n  Another excellent use case for the\n  \\ei{IEEEeqnarray} environment. Try an argument like\n  \\texttt{\\{rCl+rCl\\}}.} could be used:\n\\begin{example}\n\\begin{align}\n  a & = b + c \\\\\n  & = d + e\n\\end{align}\n\\end{example}\n\nthis approach fails once a single line is too long:\n\\begin{example}\n\\begin{align}\n  a & = b + c \\\\\n  & = d + e + f + g + h + i \n  + j + k + l \\nonumber \\\\\n  & + m + n + o \\\\\n  & = p + q + r + s\n\\end{align}\n\\end{example}\n\\noindent\nHere $+\\:m$ should be below $d$ and not below the equality sign. Of\ncourse, one could add some space (\\verb+\\hspace{...}+),\nbut this will never yield a precise arrangement (and is bad\nstyle\\ldots).\n\nA better solution is offered by the \\ei{eqnarray} environment:\n\\begin{example}\n\\begin{eqnarray}\n  a & = & b + c \\\\\n  & = & d + e + f + g + h + i \n  + j + k + l \\nonumber \\\\\n  && +\\: m + n + o \\\\\n  & = & p + q + r + s\n\\end{eqnarray}\n\\end{example}\n\nThis is still not optimal. The spaces around the equality signs are too big.\nParticularly, they are \\textbf{not} the same as in the\n\\ei{multline} and \\ei{equation} environments:\n\\begin{example}\n\\begin{eqnarray}\n  a & = & a = a\n\\end{eqnarray}\n\\end{example}\n\n\\noindent \\ldots and the expression sometimes overlaps with the equation number even\n  though there would be enough room on the left:\n\\begin{example}\n\\begin{eqnarray}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h^2 \n  + i^2 + j \n  \\label{eq:faultyeqnarray}\n\\end{eqnarray}\n\\end{example}\n\n\\noindent While the environment offers a command \\ci{lefteqn} that can\n  be used when the LHS is too long:\n\\begin{example}\n\\begin{eqnarray}\n  \\lefteqn{a + b + c + d \n    + e + f + g + h}\\nonumber\\\\\n  & = & i + j + k + l + m \n  \\\\\n  & = & n + o + p + q + r + s\n\\end{eqnarray}\n\\end{example}\n\\noindent This is not optimal either as the RHS is too short and the array is\nnot properly centered:\n\\begin{example}\n\\begin{eqnarray}\n  \\lefteqn{a + b + c + d \n    + e + f + g + h} \n  \\nonumber \\\\\n  & = & i + j \n\\end{eqnarray}\n\\end{example}\n\n\\noindent Having badmouthed the competition sufficiently, I can now steer you gently towards the glorious \\ldots\n\n\\subsection{IEEEeqnarray Environment}\n\\label{sec:IEEEeqnarray_intro}\n\nThe \\ei{IEEEeqnarray} environment is a very powerful command with\nmany options. Here, we will only introduce its basic\nfunctionalities. For more information please refer to the\nmanual.\\footnote{The official manual is called\n  \\CTAN|macros/latex/contrib/IEEEtran/IEEEtran_HOWTO.pdf|. The part about \\texttt{IEEEeqnarray}\n  can be found in Appendix~F.}\n\nFirst of all, in order to be able to use the\n\\ei{IEEEeqnarray} environment one needs to load the\npackage\\footnote{The \\pai{IEEEtrantools} package may not be included in your setup, it can be found on CTAN.}\n\\pai{IEEEtrantools}. Include the following line in the header of\nyour document: \\small\n\\begin{verbatim}\n\\usepackage[retainorgcmds]{IEEEtrantools}\n\\end{verbatim}\n\\normalsize\n\nThe strength of \\ei{IEEEeqnarray} is the ability to specify\nthe number of \\emph{columns} in the equation array. Usually, this\nspecification will be \\verb+{rCl}+, \\emph{i.e.}, three columns, the\nfirst column right-justified, the middle one centered with a little\nmore space around it (therefore we specify capital \\texttt{C} instead of\nlower-case \\texttt{c}) and the third column left-justified:\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h \n  + i + j + k \\nonumber\\\\\n  && \\negmedspace {} + l + m + n + o \n  \\\\\n  & = & p + q + r + s\n\\end{IEEEeqnarray}\n\\end{example}\nAny number of columns can be specified:\n\\verb+{c}+ will give only one column with all entries centered, or\n\\verb+{rCll}+ would add a fourth, left-justified column to use\nfor comments. Moreover, beside \\texttt{l}, \\texttt{c}, \\texttt{r}, \\texttt{L},\n\\texttt{C}, \\texttt{R} for math mode entries there are also \\texttt{s},\n\\texttt{t}, \\texttt{u} for left, centered, and right text mode entries.\nAdditional space can be added with \\texttt{.} and\n\\texttt{/} and \\texttt{?} in increasing order.\\footnote{For more spacing\n  types refer to Section~\\ref{sec:putting-qed-right}.}\nNote the spaces around the equality signs in contrast to the space produced\nby the \\texttt{eqnarray} environment.\n\n\\subsection{Common Usage}\n\\label{sec:common-usage}\n\nIn the following we will describe how we use \\texttt{IEEEeqnarray} to\nsolve the most common problems.\n\nIf a line overlaps with the equation number as in\n  \\eqref{eq:faultyeqnarray}, the command \n\\small\n\\begin{verbatim}\n\\IEEEeqnarraynumspace\n\\end{verbatim} \n\\normalsize\n  can be used: it has to be added in the corresponding line and makes\n  sure that the whole equation array is shifted by the size of the\n  equation numbers (the shift depends on the size of the number!):\n  instead of\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h \n  + i + j + k \n  \\\\\n  & = & l + m + n\n\\end{IEEEeqnarray}\n\\end{example}\n  we get\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h \n  + i + j + k \n  \\IEEEeqnarraynumspace\\\\\n  & = & l + m + n.\n\\end{IEEEeqnarray}\n\\end{example}\n\nIf the LHS is too long, as a replacement for the faulty\n  \\ci{lefteqn} command, \\texttt{IEEEeqnarray} offers the\n  \\ci{IEEEeqnarraymulticol} command which works in all situations:\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  \\IEEEeqnarraymulticol{3}{l}{\n    a + b + c + d + e + f \n    + g + h\n  }\\nonumber\\\\ \\quad\n  & = & i + j \n  \\\\\n  & = & k + l + m\n\\end{IEEEeqnarray}\n\\end{example}\nThe usage is identical to the \\ci{multicolumns} command in the\n\\texttt{tabular}-en\\-vi\\-ron\\-ment. The first argument \\verb+{3}+\nspecifies that three columns shall be combined into one which will be\nleft-justified \\verb+{l}+.\n\nNote that by inserting \\ci{quad} commands one can easily adapt\nthe depth of the equation signs,\\footnote{I think that one quad is the\n  distance that looks good for most cases.} \\emph{e.g.},\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  \\IEEEeqnarraymulticol{3}{l}{\n    a + b + c + d + e + f \n    + g + h\n  }\\nonumber\\\\ \\qquad\\qquad\n  & = & i + j\n  \\\\\n  & = & k + l + m\n\\end{IEEEeqnarray}\n\\end{example}\n\nIf an equation is split into two or more lines, \\LaTeX\\\n  interprets the first $+$ or $-$ as a sign instead of operator.\n  Therefore, it is necessary to add an additional space \\ci{:}\n  between the operator and the term: instead of\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h \n  + i + j + k \\nonumber\\\\\n  && + l + m + n + o \n  \\\\\n  & = & p + q + r + s\n\\end{IEEEeqnarray}\n\\end{example}\n  we should write\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\\\\n  & = & d + e + f + g + h \n  + i + j + k \\nonumber\\\\\n  && \\negmedspace {} + l + m + n + o \n  \\\\\n  & = & p + q + r + s\n\\end{IEEEeqnarray}\n\\end{example}\n\\noindent Note the space difference between $+$ and $l$!\nThe construction \\verb|{} + l| forces the \\verb|+|-sign to be a binary operator rather\nthan just a sign, and the unwanted ensuing space between\n\\verb|{}| and \\verb|+| is compensated by a negative medium space\n\\ci{negmedspace}.\n\nIf a particular line should not have an equation number, the\n  number can be suppressed using \\ci{nonumber} (or\n  \\ci{IEEEnonumber}). If on such a line a label\n  \\verb+\\label{eq:...}+ is defined, then this label is passed on\n  to the next equation number that is not suppressed. Place the labels right before the line-break\n  \\verb+\\\\+ or the next to the equation it belongs to. Apart from\n  improving the readability of the source code this prevents a\n  compilation error when a \\ci{IEEEmulticol} command\n  follows the label-definition.\n  \nThere also exists a *-version where all equation numbers are\n  suppressed. In this case an equation number can be made to appear\n  using the command \\ci{IEEEyesnumber}:\n\\begin{example}\n\\begin{IEEEeqnarray*}{rCl}\n  a & = & b + c \\\\\n  & = & d + e \\IEEEyesnumber\\\\\n  & = & f + g\n\\end{IEEEeqnarray*}\n\\end{example}\n\nSub-numbers are also easily possible using \n  \\ci{IEEEyessubnumber}:\n\\begin{example}\n\\begin{IEEEeqnarray}{rCl}\n  a & = & b + c \n  \\IEEEyessubnumber\\\\\n  & = & d + e \n  \\nonumber\\\\\n  & = & f + g \n  \\IEEEyessubnumber  \n\\end{IEEEeqnarray}\n\\end{example}\n  \n\\section{Arrays and Matrices} \\label{sec:arraymat}\n\nTo typeset \\textbf{arrays}, use the \\ei{array} environment. It works\nin a similar way to the \\texttt{tabular} environment. The \\verb|\\\\| command is\nused to break the lines:\n\\begin{example}\n  \\begin{equation*}\n    \\mathbf{X} = \\left( \n      \\begin{array}{ccc}\n        x_1 & x_2 & \\ldots \\\\\n        x_3 & x_4 & \\ldots \\\\\n        \\vdots & \\vdots & \\ddots\n      \\end{array} \\right)\n  \\end{equation*}\n\\end{example}\n\nThe \\ei{array} environment can also be used to typeset \\wi{piecewise function}s by\nusing a ``\\verb|.|'' as an invisible \\ci{right} delimiter:\n\\begin{example}\n\\begin{equation*}\n  |x| = \\left\\{\n    \\begin{array}{rl}\n      -x & \\text{if } x < 0,\\\\\n      0 & \\text{if } x = 0,\\\\\n      x & \\text{if } x > 0.\n    \\end{array} \\right.\n\\end{equation*}\n\\end{example}\nThe \\ei{cases} environment from \\textsf{amsmath} simplifies\nthe syntax, so it is worth a look:\n\\begin{example}\n  \\begin{equation*}\n    |x| = \n    \\begin{cases}\n      -x & \\text{if } x < 0,\\\\\n      0 & \\text{if } x = 0,\\\\\n      x & \\text{if } x > 0.\n    \\end{cases} \n\\end{equation*}\n\\end{example}\n\n\nMatrices\\index{matrix} can be typeset by \\ei{array}, but\n\\pai{amsmath} provides a better solution using the different \\ei{matrix}\nenvironments. There are six versions with different delimiters: \\ei{matrix}\n(none), \\ei{pmatrix} $($, \\ei{bmatrix} $[$, \\ei{Bmatrix} $\\{$, \\ei{vmatrix} $\\vert$ and\n\\ei{Vmatrix} $\\Vert$. You don't have to specify the number of columns as with\n\\ei{array}. The maximum number is 10, but it is customisable (though it is not\nvery often you need 10 columns!):\n\\begin{example}\n\\begin{equation*}\n  \\begin{matrix} \n    1 & 2 \\\\\n    3 & 4 \n  \\end{matrix} \\qquad\n  \\begin{bmatrix} \n    p_{11} & p_{12} & \\ldots \n    & p_{1n} \\\\\n    p_{21} & p_{22} & \\ldots \n    & p_{2n} \\\\\n    \\vdots & \\vdots & \\ddots \n    & \\vdots \\\\\n    p_{m1} & p_{m2} & \\ldots \n    & p_{mn} \n  \\end{bmatrix}\n\\end{equation*}\n\\end{example}\n\n\n\n\\section{Spacing in Math Mode} \\label{sec:math-spacing}\n\n\\index{math spacing} If the spacing within formulae chosen by \\LaTeX{}\nis not satisfactory, it can be adjusted by inserting special spacing\ncommands: \\ci{,} for $\\frac{3}{18}\\:\\textrm{quad}$\n(\\demowidth{0.166em}), \\ci{:} for $\\frac{4}{18}\\: \\textrm{quad}$\n(\\demowidth{0.222em}) and \\ci{;} for $\\frac{5}{18}\\: \\textrm{quad}$\n(\\demowidth{0.277em}).  The escaped space character \\verb*|\\ |\ngenerates a medium sized space comparable to the interword spacing and\n\\ci{quad} (\\demowidth{1em}) and \\ci{qquad} (\\demowidth{2em}) produce\nlarge spaces. The size of a \\ci{quad} corresponds to the width of the\ncharacter `M' of the current font. \\verb|\\!|\\cih{\"!} produces a\nnegative space of $-\\frac{3}{18}\\:\\textrm{quad}$\n($-$\\demowidth{0.166em}).\n\n\\begin{example}\n\\begin{equation*}\n  \\int_1^2 \\ln x \\mathrm{d}x \n  \\qquad\n  \\int_1^2 \\ln x \\,\\mathrm{d}x\n\\end{equation*}\n\\end{example}\n\nNote that `d' in the differential is conventionally set in roman.\nIn the next example, we define a new command \\ci{ud} (upright d) which produces\n``$\\,\\mathrm{d}$'' (notice the spacing \\demowidth{0.166em} before the\n$\\text{d}$), so we don't have to write it every time. The \\ci{newcommand} is\nplaced in the preamble. %  More on\n% \\ci{newcommand} in section~\\ref{} on page \\pageref{}. To Do: Add label and\n% reference to \"Customising LaTeX\" -> \"New Commands, Environments and Packages\"\n% -> \"New Commands\".\n\\begin{example}\n\\newcommand{\\ud}{\\,\\mathrm{d}}\n\n\\begin{equation*}\n \\int_a^b f(x)\\ud x \n\\end{equation*}\n\\end{example}\n\nIf you want to typeset multiple integrals, you'll discover that the spacing\nbetween the integrals is too wide. You can correct it using \\ci{!}, but\n\\pai{amsmath} provides an easier way for fine-tuning\nthe spacing, namely the \\ci{iint}, \\ci{iiint}, \\ci{iiiint}, and \\ci{idotsint}\ncommands.\n\n\\begin{example}\n\\newcommand{\\ud}{\\,\\mathrm{d}}\n\n\\begin{IEEEeqnarray*}{c}\n  \\int\\int f(x)g(y) \n                  \\ud x \\ud y \\\\\n  \\int\\!\\!\\!\\int \n         f(x)g(y) \\ud x \\ud y \\\\\n  \\iint f(x)g(y)  \\ud x \\ud y \n\\end{IEEEeqnarray*}\n\\end{example}\n\nSee the electronic document \\texttt{testmath.tex} (distributed with\n\\AmS-\\LaTeX) or Chapter 8 of \\companion{} for further details.\n\n\\subsection{Phantoms}\n\nWhen vertically aligning text using \\verb|^| and \\verb|_| \\LaTeX{} is sometimes\njust a little too helpful. Using the \\ci{phantom} command you can\nreserve space for characters that do not show up in the final output.\nThe easiest way to understand this is to look at an example:\n\\begin{example}\n\\begin{equation*}\n{}^{14}_{6}\\text{C}\n\\qquad \\text{versus} \\qquad\n{}^{14}_{\\phantom{1}6}\\text{C}\n\\end{equation*}\n\\end{example}\nIf you want to typeset a lot of isotopes as in the example, the \\pai{mhchem}\npackage is very useful for typesetting isotopes and chemical formulae too.\n\n\n\\section{Fiddling with the Math Fonts}\\label{sec:fontsz}\nDifferent math fonts are listed on Table~\\ref{mathalpha} on page\n\\pageref{mathalpha}.\n\\begin{example}\n $\\Re \\qquad\n  \\mathcal{R} \\qquad\n  \\mathfrak{R} \\qquad\n  \\mathbb{R} \\qquad $  \n\\end{example}\nThe last two require \\pai{amssymb} or \\pai{amsfonts}.\n\nSometimes you need to tell \\LaTeX{} the correct font\nsize. In math mode, this is set with the following four commands:\n\\begin{flushleft}\n\\ci{displaystyle}~($\\displaystyle 123$),\n \\ci{textstyle}~($\\textstyle 123$), \n\\ci{scriptstyle}~($\\scriptstyle 123$) and\n\\ci{scriptscriptstyle}~($\\scriptscriptstyle 123$).\n\\end{flushleft}\n\nIf $\\sum$ is placed in a fraction, it'll be typeset in text style unless you tell\n\\LaTeX{} otherwise:\n\\begin{example}\n\\begin{equation*}\n P = \\frac{\\displaystyle{ \n   \\sum_{i=1}^n (x_i- x)\n   (y_i- y)}} \n   {\\displaystyle{\\left[\n   \\sum_{i=1}^n(x_i-x)^2\n   \\sum_{i=1}^n(y_i- y)^2\n   \\right]^{1/2}}}\n\\end{equation*}    \n\\end{example}\nChanging styles generally affects the way big operators and limits are displayed.\n\n% This is not a math accent, and no maths book would be set this way.\n% mathop gets the spacing right.\n\n\n\\subsection{Bold Symbols}\n\\index{bold symbols}\n\nIt is quite difficult to get bold symbols in \\LaTeX{}; this is\nprobably intentional as amateur typesetters tend to overuse them.  The\nfont change command \\verb|\\mathbf| gives bold letters, but these are\nroman (upright) whereas mathematical symbols are normally italic, and\nfurthermore it doesn't work on lower case Greek letters.\nThere is a \\ci{boldmath} command, but \\emph{this can only be used\noutside math mode}. It works for symbols too, though:\n\\begin{example}\n$\\mu, M \\qquad \n\\mathbf{\\mu}, \\mathbf{M}$\n\\qquad \\boldmath{$\\mu, M$}\n\\end{example}\n\nThe package \\pai{amsbsy} (included by \\pai{amsmath}) as well as the\npackage \\pai{bm} from the \\texttt{tools} bundle make this much easier as they include\na \\ci{boldsymbol} command:\n\n\\begin{example}\n$\\mu, M \\qquad\n\\boldsymbol{\\mu}, \\boldsymbol{M}$\n\\end{example}\n\n\n\\section{Theorems, Lemmas, \\ldots}\n\nWhen writing mathematical documents, you probably need a way to\ntypeset ``Lemmas'', ``Definitions'', ``Axioms'' and similar\nstructures.\n\\begin{lscommand}\n\\ci{newtheorem}\\verb|{|\\emph{name}\\verb|}[|\\emph{counter}\\verb|]{|%\n         \\emph{text}\\verb|}[|\\emph{section}\\verb|]|\n\\end{lscommand}\nThe \\emph{name} argument is a short keyword used to identify the\n``theorem''. With the \\emph{text} argument you define the actual name\nof the ``theorem'', which will be printed in the final document.\n\nThe arguments in square brackets are optional. They are both used to\nspecify the numbering used on the ``theorem''. Use  the \\emph{counter}\nargument to specify the \\emph{name} of a previously declared\n``theorem''. The new ``theorem'' will then be numbered in the same\nsequence.  The \\emph{section} argument allows you to specify the\nsectional unit within which the ``theorem'' should get its numbers.\n\nAfter executing the \\ci{newtheorem} command in the preamble of your\ndocument, you can use the following command within the document.\n\\begin{code}\n\\verb|\\begin{|\\emph{name}\\verb|}[|\\emph{text}\\verb|]|\\\\\nThis is my interesting theorem\\\\\n\\verb|\\end{|\\emph{name}\\verb|}|     \n\\end{code}\n\nThe \\pai{amsthm} package (part of \\AmS-\\LaTeX) provides the \n\\ci{theoremstyle}\\verb|{|\\emph{style}\\verb|}|\ncommand which lets you define what the theorem is all about by picking\nfrom three predefined styles: \\texttt{definition} (fat title, roman body),\n\\texttt{plain} (fat title, italic body) or \\texttt{remark} (italic\ntitle, roman body).\n\nThis should be enough theory. The following examples should\nremove any remaining doubt, and make it clear that the\n\\verb|\\newtheorem| environment is way too complex to understand.\n\n% actually define things\n\\theoremstyle{definition} \\newtheorem{law}{Law}\n\\theoremstyle{plain}      \\newtheorem{jury}[law]{Jury}\n\\theoremstyle{remark}     \\newtheorem*{marg}{Margaret}\n\nFirst define the theorems:\n\n\\begin{verbatim}\n\\theoremstyle{definition} \\newtheorem{law}{Law}\n\\theoremstyle{plain}      \\newtheorem{jury}[law]{Jury}\n\\theoremstyle{remark}     \\newtheorem*{marg}{Margaret}\n\\end{verbatim}\n\n\\begin{example}\n\\begin{law} \\label{law:box}\nDon't hide in the witness box\n\\end{law}\n\\begin{jury}[The Twelve]\nIt could be you! So beware and\nsee law~\\ref{law:box}.\\end{jury}\n\\begin{jury}\nYou will disregard the last\nstatement.\\end{jury}\n\\begin{marg}No, No, No\\end{marg}\n\\begin{marg}Denis!\\end{marg}\n\\end{example}\n\nThe ``Jury'' theorem uses the same counter as the ``Law''\ntheorem, so it gets a number that is in sequence with\nthe other ``Laws''. The argument in square brackets is used to specify \na title or something similar for the theorem.\n\\begin{example}\n\\newtheorem{mur}{Murphy}[section]\n\n\\begin{mur} If there are two or \nmore ways to do something, and \none of those ways can result in\na catastrophe, then someone \nwill do it.\\end{mur}\n\\end{example}\n\nThe ``Murphy'' theorem gets a number that is linked to the number of\nthe current section. You could also use another unit, for example chapter or\nsubsection.\n\nIf you want to customize your theorems down to the last dot, the\n\\pai{ntheorem} package offers a plethora of options.\n\n\n\\subsection{Proofs and End-of-Proof Symbol}\n\\label{sec:putting-qed-right}\n\nThe \\pai{amsthm} package also provides the \\ei{proof} environment.\n\n\\begin{example}\n\\begin{proof}\n Trivial, use\n \\begin{equation*}\n   E=mc^2.\n \\end{equation*}\n\\end{proof}\n\\end{example}\n\nWith the command \\ci{qedhere} you can move the `end of proof' symbol\naround for situations where it would end up alone on a line.\n\n\\begin{example}\n\\begin{proof}\n Trivial, use\n \\begin{equation*}\n   E=mc^2. \\qedhere\n \\end{equation*}\n\\end{proof}\n\\end{example}\n\nUnfortunately, this correction does not work for \\texttt{IEEEeqnarray}:\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with an equation array:\n  \\begin{IEEEeqnarray*}{rCl}\n    a & = & b + c \\\\\n    & = & d + e. \\qedhere\n  \\end{IEEEeqnarray*}  \n\\end{proof}\n\\end{example}\n\\noindent\nThe reason for this is the internal structure of \\texttt{IEEEeqnarray}:\nit always puts two invisible columns at both sides of the array that\nonly contain a stretchable space. By this \\texttt{IEEEeqnarray} ensures\nthat the equation array is horizontally centered. The\n\\ci{qedhere} command should actually be put \\emph{outside} this\nstretchable space, but this does not happen as these columns are\ninvisible to the user.\n\nThere is a very simple remedy. Define the stretching\nexplicitly!\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with an equation array:\n  \\begin{IEEEeqnarray*}{+rCl+x*}\n    a & = & b + c \\\\\n    & = & d + e. & \\qedhere\n  \\end{IEEEeqnarray*}  \n\\end{proof}\n\\end{example}\n\\noindent\nNote that the \\verb=+= in \\verb={+rCl+x*}= denotes stretchable spaces, one\non the left of the equations (which, if not specified, will be done\nautomatically by \\texttt{IEEEeqnarray}!) and one on the right of the\nequations. But now on the right, \\emph{after} the stretching column,\nwe add an empty column \\verb=x=. This column will only be needed on\nthe last line if the \\ci{qedhere} command is put\nthere. Finally, we specify a \\verb=*=. This is a null-space that\nprevents \\texttt{IEEEeqnarray} from adding another unwanted \\verb=+=-space!\n\nIn the case of equation numbering, there is a similar problem. Comparing\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with a numbered equation:\n  \\begin{equation}\n    a = b + c.\n  \\end{equation}\n\\end{proof}\n\\end{example}\n\\noindent\nwith\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with a numbered equation:\n  \\begin{equation}\n    a = b + c. \\qedhere\n  \\end{equation}\n\\end{proof}\n\\end{example}\n\\noindent\nyou notice that in the (correct) second version the $\\Box$ is much\ncloser to the equation than in the first version.\n\nSimilarly, the correct way of putting the QED-symbol at the end of an\nequation array is as follows:\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with an equation array:\n  \\begin{IEEEeqnarray}{+rCl+x*}\n    a & = & b + c \\\\\n    & = & d + e. \\\\\n    &&& \\qedhere\\nonumber\n  \\end{IEEEeqnarray}  \n\\end{proof}\n\\end{example}\n\\noindent\nwhich contrasts with\n\\begin{example}\n\\begin{proof}\n  This is a proof that ends\n  with an equation array:\n  \\begin{IEEEeqnarray}{rCl}\n    a & = & b + c \\\\\n    & = & d + e.\n  \\end{IEEEeqnarray}  \n\\end{proof}\n\\end{example}\n\n\n%\n\n% Local Variables:\n% TeX-master: \"lshort\"\n% mode: latex\n% mode: flyspell\n% End:\n", "meta": {"hexsha": "db051630c1ff3f14abd4e94be8e1deed980a849c", "size": 40906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "synctex test files/less basic/2017/lshort-5.05/src/math.tex", "max_stars_repo_name": "templateK/synctex", "max_stars_repo_head_hexsha": "555467da1535b0b1d7e97532a2c6251d9c2b3957", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 38, "max_stars_repo_stars_event_min_datetime": "2016-12-23T02:21:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T22:07:39.000Z", "max_issues_repo_path": "synctex test files/less basic/2017/lshort-5.05/src/math.tex", "max_issues_repo_name": "templateK/synctex", "max_issues_repo_head_hexsha": "555467da1535b0b1d7e97532a2c6251d9c2b3957", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2016-12-23T13:20:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:31:48.000Z", "max_forks_repo_path": "synctex test files/less basic/2017/lshort-5.05/src/math.tex", "max_forks_repo_name": "templateK/synctex", "max_forks_repo_head_hexsha": "555467da1535b0b1d7e97532a2c6251d9c2b3957", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2017-08-28T20:40:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T21:50:14.000Z", "avg_line_length": 32.4908657665, "max_line_length": 156, "alphanum_fraction": 0.6993595072, "num_tokens": 13041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.6425962638178254}}
{"text": "\\section{The Adjugate Matrix}\r\nGiven a square matrix $A\\in M_n(F)$ with columns $A^{(i)}$.\r\nIf we swap two neighbouring columns (or rows), then $\\det A$ changes sign.\r\n\\begin{remark}\r\n    We can prove properties of determinant using the decomposition of $A$ into elementary matrices.\r\n\\end{remark}\r\nA column expansion is a strategy to compute the determinant of a matrix by using its linkage to some of its submatrices.\r\n\\begin{definition}\r\n    Let $A\\in M_n(F)$ and pick $i,j\\in\\{1,\\ldots,n\\}$.\r\n    We define $A_{\\widehat{ij}}\\in A_{n-1}(F)$ to be the matrix obtained by deleting the $i^{th}$ row and $j^{th}$ column from $A$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take\r\n    $$A=\\begin{pmatrix}\r\n        1&2&-7\\\\\r\n        2&1&0\\\\\r\n        -3&6&1\r\n    \\end{pmatrix}$$\r\n    Then\r\n    $$A_{\\widehat{32}}=\\begin{pmatrix}\r\n        1&-7\\\\\r\n        2&0\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{lemma}[Expansion of Determinant]\r\n    Let $A\\in M_n(F)$.\\\\\r\n    1. We have the expansion along the $j^{th}$ column\r\n    $$\\det A=\\sum_{i=1}^n(-1)^{i+j}a_{ij}\\det A_{\\widehat{ij}}$$\r\n    2. We have the expansion along the $i^{th}$ row\r\n    $$\\det A=\\sum_{j=1}^n(-1)^{i+j}a_{ij}\\det A_{\\widehat{ij}}$$\r\n\\end{lemma}\r\n\\begin{example}\r\n    Take\r\n    $$A=\\begin{pmatrix}\r\n        1&2&-1\\\\\r\n        3&-1&1\\\\\r\n        4&2&-7\r\n    \\end{pmatrix}$$\r\n    So expanding along the second column gives\r\n    $$\\det A=-(2)\\det\\begin{pmatrix}\r\n        3&1\\\\\r\n        4&-7\r\n    \\end{pmatrix}+(-1)\\det\\begin{pmatrix}\r\n        1&-1\\\\\r\n        4&-7\r\n    \\end{pmatrix}-2\\det\\begin{pmatrix}\r\n        1&-1\\\\\r\n        3&1\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{proof}\r\n    Suffices to show the first part.\r\n    Pick $1\\le j\\le n$ and write $A=(a_{ij}),A^{(j)}=\\sum_ia_{ij}e_i$.\r\n    Then\r\n    \\begin{align*}\r\n        \\det A&=\\det\\left( A^{(1)},\\ldots,\\sum_{i=1}^na_{ij}e_i ,\\ldots, A^{(n)}\\right)\\\\\r\n        &=\\sum_{i=1}^na_{ij}\\det(A^{(1)},\\ldots,e_i,\\ldots,A^{(n)})\\\\\r\n        &=\\sum_{i=1}^na_{ij}(-1)^{j-1}\\det(e_i,A^{(1)},\\ldots,A^{(n)})\\\\\r\n        &=\\sum_{i=1}^na_{ij}(-1)^{j-1}(-1)^{i-1}\\det\r\n        \\begin{pmatrix}\r\n            1&\\ast&\\cdots&\\ast\\\\\r\n            0&&&\\\\\r\n            \\vdots&&A_{\\widehat{ij}}&\\\\\r\n            0&&&\r\n        \\end{pmatrix}\\\\\r\n        &=\\sum_{i=1}^n(-1)^{i+j}a_{ij}\\det A_{\\widehat{ij}}\r\n    \\end{align*}\r\n    as desired.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $A\\in M_n(F)$, then the adjugate matrix $\\operatorname{adj}A$ of $A$ is the $n\\times n$ matrix with entries\r\n    $$(\\operatorname{adj}A)_{ji}=(-1)^{i+j}\\det A_{\\widehat{ij}}=\\det(A^{(1)},\\ldots,A^{(j-1)},e_i,A^{(j+1)},\\ldots,A^{(n)})$$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $A\\in M_n(F)$, then $\\operatorname{adj}(A)A=(\\det A)I$ where $I$ is the identity matrix.\r\n\\end{theorem}\r\nIn particular, if $A$ is invertible, then as $\\det A\\neq 0$,\r\n$$A^{-1}=\\frac{1}{\\det A}\\operatorname{adj}A$$\r\n\\begin{proof}\r\n    For any $j$, the preceding lemma translates to\r\n    $$\\det A=\\sum_{i=1}^n(\\operatorname{adj}A)_{ij}a_{ij}=(\\operatorname{adj}(A)A)_{jj}$$\r\n    Now for $j<k$, let $A'$ be the matrix obtained by putting $A^{(k)}$ in the place of $A^{(j)}$, then\r\n    \\begin{align*}\r\n        0&=\\det(A')\\\\\r\n        &=\\det(A^{(1)},\\ldots,A^{(k)},\\ldots,A^{(k)},\\ldots,A^{(n)})\\\\\r\n        &=\\det\\left(A^{(1)},\\ldots,\\sum_{i=1}^na_{ik}e_i,\\ldots,A^{(k)},\\ldots,A^{(n)}\\right)\\\\\r\n        &=\\sum_{i=1}^na_{ik}\\det(A^{(1)},\\ldots,e_i,\\ldots,A^{(k)},\\ldots,A^{(n)})\\\\\r\n        &=\\sum_{i=1}^na_{ik}(\\operatorname{adj}A)_{ji}\\\\\r\n        &=(\\operatorname{adj}(A)A)_{jk}\r\n    \\end{align*}\r\n    which implies the result.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $A\\in M_n(F)$ be invertible, and let $b\\in F^n$, then the unique solution to $Ax=b$ is given by\r\n    $$x_i=\\frac{1}{\\det A}\\det A_{\\hat{i}b}$$\r\n    where $A_{\\hat{i}b}$ is the matrix obtained by replacing the $i^{th}$ column of $A$ by $b$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    As $A$ is invertible, such an $x$ exists and is unique.\r\n    Let $x$ be a solution, then note that\r\n    \\begin{align*}\r\n        \\det(A_{\\hat{i}b})&=\\det(A^{(1)},\\ldots,A^{(i-1)},b,A^{(i+1)},\\ldots,A^{(n)})\\\\\r\n        &=\\det(A^{(1)},\\ldots,A^{(i-1)},Ax,A^{(i+1)},\\ldots,A^{(n)})\\\\\r\n        &=\\det\\left(A^{(1)},\\ldots,A^{(i-1)},\\sum_{j=1}^nx_jA^{(j)},A^{(i+1)},\\ldots,A^{(n)}\\right)\\\\\r\n        &=\\sum_{j=1}^nx_j\\det(A^{(1)},\\ldots,A^{(i-1)},A^{(j)},A^{(i+1)},\\ldots,A^{(n)})\\\\\r\n        &=\\sum_{j=1}^nx_j\\delta_{ij}\\det A\\\\\r\n        &=x_i\\det A\r\n    \\end{align*}\r\n    just as we wanted.\r\n\\end{proof}", "meta": {"hexsha": "995a95eae1e1c156a596321544c7e512b9d4aa36", "size": 4492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/compute.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": "13/compute.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": "13/compute.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": 40.8363636364, "max_line_length": 132, "alphanum_fraction": 0.5333926981, "num_tokens": 1812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6425962633900526}}
{"text": "%%!TEX TS-program = latex\n\\documentclass[11pt]{article} %DIF > \n\\usepackage{etex}\n\\usepackage[utf8]{inputenc}\n\\input ../AuxFiles/PreambleNotes.tex\n\n\n\\begin{document}\n\\onehalfspace\n\n\\vspace*{\\fill}\n\\begingroup\n\\centering\n\n\\Large {\\scshape Introduction to Statistics}\\\\\n\n(Lectures 7-8: Estimation)\n\n\\endgroup\n\\vspace*{\\fill}\n\n\\newpage\n\n\n\\section{Estimation}\n\n{\\scshape Overview:} \\noindent Lectures 7-8 will focus on \\emph{estimation}. As we have mentioned before, a strategy in the estimation problem is an \\emph{estimator}. The loss function used for this problem is the squared distance between the estimated value and the true parameter. This loss gives rise to the popular \\emph{mean squared error} performance criterion. \n\n\n\nWe will analyze two commonly used estimation strategies---Maximum Likelihood (ML) and Posterior Mean estimators---in the context of the homoskedastic Normal regression model with (known variance); i.e., \n\\begin{equation} \\label{equation:Regression-model}\nY \\sim \\mathcal{N}(X \\beta, \\sigma^2 \\mathbb{I}_n ), \n\\end{equation}\n where $Y$ is the $n \\times 1$ vector of outcome variables, $X$ is the $n \\times k$ matrix of non-stochastic regressors, and $\\beta \\in \\mathbb{R}^{k}$ is the parameter of interest. \n \n We will show that if $k \\leq n$ and $X$ has full-column rank, the Maximum Likelihood estimator for the model in (\\ref{equation:Regression-model}) is the OLS estimator\n\\[ \\widehat{\\beta}_{\\textrm{OLS}} \\equiv (X’X)^{-1} X’Y,  \\]\n\n\\noindent (which we introduced in the last problem set). We will show this estimator is ``best'' among all \\emph{unbiased} estimators and we will connect this result to the \\emph{Cram\\'er-Rao} bound for the variance of estimators in parametric models. We will also argue that ``best’’ among the class of unbiased estimators need not imply admissibility with respect to all estimators. In particular, we show that if $k \\geq 3$, the OLS estimator is dominated and we present an ``empirical Bayes’’ estimator that dominates it.   \n\nThe posterior mean estimator for the regression model assuming $\\beta \\sim \\mathcal{N}_{k}(0 , (\\sigma^2/ \\lambda) \\mathbb{I}_k )$ is the popular \\emph{Ridge estimator}\n\\[ \\widehat{\\beta}_{\\textrm{Ridge}} \\equiv (X’X + \\lambda \\mathbb{I}_k)^{-1} X’Y. \\]\nThe Ridge estimator is well-defined regardless of the number of covariates and it is admissible by construction. The Ridge estimator provides a simple example of ``shrinkage’’ or ``regularization’’. A practical concern is that the Ridge estimator is biased, and the bias depends on the choice of the prior hyperparameters and the true parameter at which we evaluate the bias.  \n\nOne result that we will not cover in the notes, but that is important to keep in mind is that despite the inadmissibility of the OLS estimator for the \\emph{full} vector of coefficients $\\beta$, OLS is admissible for the problem in which we are interested in estimating only one regression coefficient but controlling for other variables.   \n\n\n\n\\subsection{Quadratic Loss} \nLet $\\mathcal{A} =\\Theta = \\mathbb{R}^{k}$. The loss function we will work with is the so-called quadratic loss\n\\[ \\mathcal{L}(a, \\beta) = || a- \\beta ||^2 = (a-\\beta)’(a-\\beta) =  \\sum_{j=1}^{k} (a_j  - \\theta_j)^2,  \\]\nwhich measures the squared distance between the estimator $\\widehat{\\beta}$ and the parameter $\\beta$. \nThe risk of any estimator $\\widehat{\\beta}$ (which is a map from data $(Y,X)$ to $\\Theta$) is given by\n\\begin{equation} \\label{equation:MSE}\n\\mathbb{E}_{\\mathbb{P}_{\\beta}}[ \\mathcal{L}(\\widehat{\\beta}, \\beta) ] = \\mathbb{E}_{\\mathbb{P}_{\\beta}}[ (\\widehat{\\beta}- \\beta)’(\\widehat{\\beta}-\\beta) ]. \n\\end{equation}\nEquation (\\ref{equation:MSE}) is referred to as \\emph{the mean-squared estimation error} at $\\beta$. We now present a simple algebraic decomposition of the mean squared error in terms of the ``bias’’ and ``variance’’ of the estimator $\\widehat{\\beta}$. Assuming that $\\overline{\\beta}  \\equiv \\mathbb{E}_{\\beta}[ \\widehat{\\beta} ]$ is finite, we define the \\underline{bias} of $\\widehat{\\beta}$ at $\\beta$ as\n$$ B_\\beta(\\widehat{\\beta}) = \\overline{\\beta} - \\beta.$$\nIf the covariance matrix of $\\widehat{\\beta}$---denoted $\\textrm{V}_{\\beta} (\\widehat{\\beta})$---is also finite, the mean squared-error can be written as\n\\begin{eqnarray*}\n\\mathbb{E}_{\\mathbb{P}_{\\beta}}[ (\\widehat{\\beta}- \\beta)’(\\widehat{\\beta}-\\beta) ] &=& \\mathbb{E}_{\\mathbb{P}_{\\beta}}[ (\\widehat{\\beta}-\\overline{\\beta} +\\overline{\\beta} - \\beta)’(\\widehat{\\beta}-\\overline{\\beta} +\\overline{\\beta} -\\beta) ],  \\\\\n&=& (\\overline{\\beta}-\\beta)’(\\overline{\\beta}-\\beta) +  \\mathbb{E}_{\\mathbb{P}_{\\beta}}[ (\\widehat{\\beta}-\\overline{\\beta} )’(\\widehat{\\beta}-\\overline{\\beta}) ]  \\\\\n&=& ||B_\\beta(\\widehat{\\beta})  ||^2 + \\textrm{tr} \\left( \\textrm{V}_{\\beta} (\\widehat{\\beta}) \\right),\n\\end{eqnarray*}\nwhere $\\textrm{tr}(\\cdot)$ is the trace operator.  The decomposition is fairly straightforward, but it highlights the fact that the bias and variance of the estimator fully determine its risk whenever the loss is quadratic. Also, the correlation between any of the components of $\\widehat{\\beta}$ is not relevant for the risk calculation. \n\n\n\\subsection{Maximum Likelihood Estimation}\n\nAccording to model (\\ref{equation:Regression-model}) the vector of outcome variables is a multivariate normal with parameters $X\\beta$ and $\\sigma^2 \\mathbb{I}_n$ and thus has a p.d.f given by\n\\begin{equation}\\label{equation:Regression-pdf}\nf( Y | \\beta , X ) = \\frac{1}{(2 \\pi \\sigma^2)^{n/2}} \\exp \\left( -\\frac{1}{2 \\sigma^2} (Y - X \\beta)’ (Y-X\\beta) \\right).  \n\\end{equation}\nThis is true, regardless of whether we have very many covariates or not. For a fixed realization of the data, define the likelihood function, L($\\beta$; (Y,X)), as the value attained by the p.d.f. in (\\ref{equation:Regression-pdf}) at different values of the data ($Y, X$); that is \n\\[ L(\\beta, (Y,X)) \\equiv f(Y | \\beta, X ). \\]\nThe maximum likelihood estimator at data $(Y,X)$ is then defined as the value of $\\beta$ that maximizes the likelihood; that is\n\\[ \\widehat{\\beta}_{\\textrm{ML}} \\equiv \\textrm{argmax}_{\\beta \\in \\mathbb{R}^{k}} L(\\beta, (Y,X)).   \\]\n\n\\noindent The likelihood function implied by (\\ref{equation:Regression-pdf}) is decreasing in $(Y-XB)’(Y-XB)$, a term which is usually referred to as the sum of square residuals. Therefore, maximizing the likelihood is equivalent to solving the \\emph{least-squares} problem\n\\[ \\textrm{min}_{\\beta \\in \\mathbb{R}^{k}} (Y-X\\beta)’(Y-X\\beta).   \\]\nThe first-order conditions for the program above, which are necessary and sufficient, yield\n\\[ X’(Y-X\\widehat{\\beta}_{\\textrm{ML}}) = \\textbf{0}_{k \\times 1} \\iff X’Y = (X’X) \\widehat{\\beta}_{\\textrm{ML}}. \\]\n\n\\noindent If $k > n$, there are infinitely many solutions that maximize the likelihood.  If $k \\leq n$, and $X$ has full-column rank there is a unique solution to this problem given by\n\\begin{equation} \\label{equation:OLS}\n\\widehat{\\beta}_{\\textrm{ML}} = \\widehat{\\beta}_{\\textrm{OLS}} = (X’X)^{-1} X’Y.\n\\end{equation}\n\n\\noindent The bias of the maximum likelihood estimator:\n\\begin{equation} \\label{equation:bias}\n\\textrm{B}_{\\beta}(\\widehat{\\beta}_{\\textrm{ML}}) = \\mathbb{E}_{\\mathbb{P}_{\\beta}} [ (X’X)^{-1} X’Y ] - \\beta = \\mathbf{0}_{k \\times 1}.\n\\end{equation}\nfor any $\\beta$. Thus, we say that the ML estimator of $\\beta$ is \\underline{unbiased}.\\footnote{An estimator $\\widehat{\\beta}$ is unbiased if $\\mathbb{E}_{\\beta} [\\widehat{\\beta}] = \\beta$ for all $\\beta \\in \\Theta$.} \n\nThe variance of the ML estimator is \n\\begin{equation} \\label{equation:variance}\n\\mathbb{V}_{\\beta} (\\widehat{\\beta}_{\\textrm{ML}}) = \\mathbb{E}_{\\mathbb{P}_{\\beta}} [ (\\widehat{\\beta}_{\\textrm{ML}}-\\beta) (\\widehat{\\beta}_{\\textrm{ML}} -\\beta )^{\\prime}  ]  = (X’X)^{-1} X’ \\mathbb{E}_{\\mathbb{P}_{\\beta}} [ (Y-X\\beta) (Y-X\\beta)’] X (X’X)^{-1} = \\sigma^2 (X’X)^{-1}.  \n\\end{equation}\nThis means that the mean squared error at $\\beta$---denoted $\\textrm{MSE}(\\beta ; \\widehat{\\beta}_{\\textrm{ML}})$---equals\n\\[ \\sigma^2 \\textrm{tr} \\left ( (X’X)^{-1} \\right). \\] \n\n\\noindent for any $\\beta$. Consequently, an interesting property of the ML/OLS estimator is that its risk function is constant over the parameter space.  \n\n\\noindent \n\n\\subsection{Posterior Mean under a Normal Prior}\nIn this subsection we analyze the Bayes estimator of the parameter $\\beta$. We have already showed that any Bayes rule can be obtained by minimizing posterior loss at each data realization. Let $\\pi$ denote a prior over the parameter $\\beta$. In our set-up the posterior loss of an action $a$ is\n\\[ \\mathbb{E}_{\\pi} [ \\: || a - \\beta ||^2 \\: | \\: (Y,X) \\: ]. \\]\nUsing the same argument that we used to decompose the mean squared-error in terms of bias and variance we can show that\n\\begin{eqnarray*}\n\\mathbb{E}_{\\pi} [ \\: || a - \\beta ||^2 \\: | \\: (Y,X) \\: ] &=& \\mathbb{E}[ \\: || a - \\mathbb{E}_{\\pi} [ \\: \\beta \\: | \\:  (Y,X) \\:  ] + \\mathbb{E}_{\\pi} [ \\beta \\: | \\: (Y,X) ] -  \\beta ||^2 \\: | \\: (Y,X) \\: ],  \\\\\n&=& || a - \\mathbb{E}_{\\pi} [ \\beta \\: | \\: (Y,X) ] ||^2  + \\textrm{tr} \\left( \\mathbb{V}_{\\pi} ( \\beta \\: | \\: (Y,X) ) \\right). \n\\end{eqnarray*}\nThis shows that, regardless of the specific prior we pick, the Bayes estimator is the posterior mean of $\\beta$\n\\[ \\widehat{\\beta}_{\\textrm{Bayes}} =   \\mathbb{E}_{\\pi} [ \\: \\beta \\: | \\: (Y,X) \\: ].  \\]\n\nBefore committing to a specific prior $\\pi$, we will show that under quadratic loss the Bayes estimator is the posterior mean.\\\\  \n\n{\\scshape Posterior Mean under a Normal Prior:}  Consider then the following prior on $\\beta$:\n\n\\begin{equation}\n\\beta  \\sim \\pi (\\beta) \\equiv \\mathcal{N}_{k}( \\beta_0 \\: , \\: \\sigma^2 V^{-1}).\n\\end{equation}\n\n\\noindent The prior assumes that all the coefficients are approximately normal with values close to the vector $\\beta_0$ and covariance matrix given by $\\sigma^2 V^{-1}$. There is typically no magical recipe to select a prior. More often than not, the selection of a prior trades-off interpretation and convenience in its implementation. \n\nWe derive the posterior distribution of $\\beta$. One way of deriving this posterior distribution is by an application of Bayes Theorem\n\\begin{equation*}\n\\pi(\\beta \\: | \\: \\sigma^2, y, X ) = \\frac{f(Y  \\: | \\: \\beta, X) \\pi(\\beta ) }{\\int_{\\Theta} f(Y, \\: | \\: \\beta, X) \\pi (\\beta ) d \\beta}. \n\\end{equation*}\n\n\\noindent The posterior is thus proportional to the likelihood times the prior, both of which are Gaussian. \n\n\\noindent Consequently, $f(Y | X, \\beta, \\sigma^2 )\\:  \\pi(\\beta | \\sigma^2 )$ is, up to a constant that does not depend on $\\beta$, proportional to\n\\begin{equation} \\label{equation:posterior}\n\\exp \\left( -\\frac{1}{2\\sigma^2} (Y-X\\beta)^{\\prime} (Y-X \\beta) \\right)  \\exp \\left(-\\frac{1}{2 \\sigma^2} (\\beta-\\beta_0)^{\\prime} V (\\beta-\\beta_0) \\right). \n\\end{equation}\n\n\\noindent The expression above equals:\n\\[ \\exp \\left( -\\frac{1}{2\\sigma^2} Y^{\\prime} Y \\right) \\exp \\left(  - \\frac{1}{2 \\sigma^2 } \\beta \\left(V + X’X \\right) \\beta + \\frac{1}{\\sigma^2}(Y^{\\prime} X+V\\beta_0) \\beta \\right). \\]\nCompleting the square and ignoring all the terms that do not have $\\beta$ on them, gives the posterior distribution as a constant times the exponential of:\n\\begin{equation*}\n-\\frac{1}{2 \\sigma^2} \\left( \\beta -  \\left( V + X^{\\prime} X \\right)^{-1} (X^{\\prime} y+ V \\beta_0) \\right) \\left(V+ X’X \\right) \\left(\\beta -  ( V^{-1} + X^{\\prime} X )^{-1} (X^{\\prime} Y+ V \\beta_0) \\right). \n\\end{equation*}\nThis implies that:\n\\begin{equation}\n\\beta | Y, X \\sim \\mathcal{N}_{k} \\left(  \\left( V + X’X \\right)^{-1} (X^{\\prime} Y+V\\beta_0) \\: , \\:   \\sigma^2 \\left(V + X^{\\prime} X \\right)^{-1}   \\right).\n\\end{equation}\nThis means that the Bayesian Estimator of $\\beta$ given the Gaussian prior $\\pi(\\beta)$ is:\n\n\\[ \\widehat{\\beta}_{\\textrm{Bayes}} \\equiv \\left( V + X^{\\prime} X \\right)^{-1} \\left( X^{\\prime} Y + V \\beta_0 \\right). \\]\n\n\\noindent The posterior mean estimator is well defined regardless the number of\ncovariates.\\footnote{If $V$ is positive definite, then the matrix $V+ X’X$ is\n  positive definite as well, and thus invertible.} The posterior mean estimator\nfor $V= \\lambda \\mathbb{I}_{k}$ and $\\beta_0 = 0$ is called the Ridge estimator\n\n\\[  \\widehat{\\beta}_{\\textrm{Ridge}} \\equiv (X’X + \\lambda \\mathbb{I}_{k})^{-1} X’Y, \\]\n\n\\noindent which, by construction, is admissible. The Ridge estimator is biased:\n\\begin{eqnarray*}\n\\mathbb{E}_{\\mathbb{P}_{\\beta}} [ \\widehat{\\beta}_{\\textrm{Ridge}} ] - \\beta &=& (X’X + \\lambda \\mathbb{I}_{k})^{-1} X’X\\beta - \\beta,  \\\\\n&=& (X’X + \\lambda \\mathbb{I}_{k})^{-1} (X’X\\beta - (X’X + \\lambda \\mathbb{I}_{k}) \\beta), \\\\\n&=& -\\lambda (X’X + \\lambda \\mathbb{I}_k)^{-1} \\beta.\n\\end{eqnarray*}\n\\noindent and the magnitude of the bias depends on $\\beta$. The variance of the Ridge estimator is\n\\[ \\mathbb{V}_{\\beta} (\\widehat{\\beta}_{\\textrm{Ridge}}) = \\sigma^2( X’X + \\lambda \\mathbb{I}_k)^{-1} X’X ( X’X + \\lambda \\mathbb{I}_k)^{-1}  \\]\n\n\\noindent When $k<n$, the trace of this variance has to be smaller than that of the ML/OLS estimator.\n\n{\\scshape Posterior Mean as a Penalized/Regularized OLS estimator:} \\noindent Equation (\\ref{equation:posterior}) is decreasing as a function of the \\emph{penalized} sum of squared residuals \n\\[ (y-X\\beta)^{\\prime} (y-X \\beta) + (\\beta-\\beta_0)^{\\prime} V (\\beta-\\beta_0). \\]\n\n\n\\noindent Under the Gaussian posterior the posterior mean and posterior mode are the same. Therefore, another way of deriving the posterior mean estimator is by finding a solution to the problem:\n\\[ \\min_{\\beta} (y-X\\beta)^{\\prime} (y-X \\beta) + (\\beta-\\beta_0)^{\\prime} V (\\beta-\\beta_0) \\]\nThe F.O.C are \n\\[ X’(Y-X\\beta) + V(\\beta - \\beta_0) = \\textbf{0}_{n \\times k} \\iff  X’Y + V \\beta_0 = (X’X + V) \\beta. \\]\n\\noindent Solving for $\\beta$ gives the estimator $\\widehat{\\beta}_{\\textrm{Bayes}}$. \n\n\\subsection{Optimality of the OLS estimator among unbiased estimators}\n\nIn this section we will show that the OLS estimator minimizes risk among the class of all unbiased estimators, provided some regularity conditions are met. \n\n\\begin{proposition}(Optimality of OLS) Consider the Normal regression model in (\\ref{equation:Regression-model}). Let $\\widehat{\\beta}$ be an estimator of $\\beta$ for which\n\\[ \\frac{\\partial}{\\partial \\beta} \\int_{\\mathbb{R}^{k}} \\widehat{\\beta} f(Y | \\beta; X ) dY = \\int_{\\mathbb{R}^{k}} \\widehat{\\beta} \\Big ( \\frac{\\partial}{\\partial \\beta} f(Y | \\beta , X) \\Big)’ dY,   \\]\nat any $\\beta$ in the parameter space. If $\\widehat{\\beta}$ is unbiased, then\n\\[ \\mathbb{V}_{\\beta} ( \\widehat{\\beta} ) - \\mathbb{V}_{\\beta} (\\widehat{\\beta}_{\\textrm{OLS}})  \\]\nis positive semi-definite, implying that the mean squared error of $\\widehat{\\beta}$ is larger than that of the OLS everywhere on the parameter space. \n\\end{proposition}\n \n\\begin{proof}\nWe would like show  that for any $c \\in \\mathbb{R}^{k}$, $c \\neq 0$\n\\[ c’ \\left( \\mathbb{V}_{\\beta} ( \\widehat{\\beta} ) - \\mathbb{V}_{\\beta} (\\widehat{\\beta}_{\\textrm{OLS}}) \\right) c \\geq 0. \\]\n\nTo do this, we start by computing the variance of $c’\\widehat{\\beta} - c’ \\widehat{\\beta}_{\\textrm{OLS}}$, \nwhich by definition of variance, has to be nonegative. Since $\\widehat{\\beta}$ and $\\widehat{\\beta}_{\\textrm{OLS}}$ are both unbiased\n\\begin{eqnarray*}\n\\mathbb{V}_{\\beta} \\left( c’\\widehat{\\beta} - c’ \\widehat{\\beta}_{\\textrm{OLS}} \\right)&=&  \\mathbb{V}_{\\beta} (c’\\widehat{\\beta}) + \\mathbb{V}_{\\beta} (c’\\widehat{\\beta}_{\\textrm{OLS}}) - 2 \\textrm{cov}_{\\beta} ( c’\\widehat{\\beta} , c’ \\widehat{\\beta}_{\\textrm{OLS}}  ),  \\\\\n&&  \\textrm{(since $\\textrm{Var}(X-Y) = \\textrm{Var}(X) + \\textrm{Var}(Y)- 2 \\textrm{cov}(X,Y)$)}\\\\\n&=& c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}) c + c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}_{\\textrm{OLS}}) c - 2 \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[  c’ (\\widehat{\\beta}-\\beta) (\\widehat{\\beta}_{\\textrm{OLS}}-\\beta)’ c \\right] \\\\\n&& \\textrm{(using the fact that both estimators are unbiased)}. \\\\\n&=& c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}) c + c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}_{\\textrm{OLS}}) c - 2 c’ \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[  \\widehat{\\beta} (\\widehat{\\beta}_{\\textrm{OLS}}-\\beta)’  \\right] c. \n\\end{eqnarray*}\nWhere the last term is the covariance between $\\widehat{\\beta}$ and the OLS residual. Using the definition of OLS\n\\[ \\widehat{\\beta}_{\\textrm{OLS}}- \\beta = (X’X)^{-1} X’(Y-X\\beta),  \\]\nand using the definition of the the Gaussian p.d.f. $f(Y | \\beta,X)$ we can see verify that\n\\[\\widehat{\\beta}_{\\textrm{OLS}}- \\beta =  \\sigma^2  (X’X)^{-1} \\frac{\\partial}{\\partial \\beta} \\ln f(Y | \\beta, X ).  \\]\nConsequently \n\\begin{eqnarray*}\n\\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[  \\widehat{\\beta} (\\widehat{\\beta}_{\\textrm{OLS}}-\\beta)’  \\right] &=& \\sigma^2 \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[  \\widehat{\\beta} \\left( \\frac{\\partial}{\\partial \\beta} \\ln f(Y | \\beta, X )\\right)’ \\right]  (X’X)^{-1}, \\\\\n&=& \\sigma^2 \\left( \\int_{\\mathbb{R}^{k}} \\widehat{\\beta}  \\left( \\frac{\\partial}{\\partial \\beta} \\ln f(Y | \\beta, X )\\right)’  f(Y | \\beta , X) dY \\right) (X’X)^{-1} \\\\\n&=& \\sigma^2 \\left( \\int_{\\mathbb{R}^{k}} \\widehat{\\beta}  \\left( \\frac{\\partial}{\\partial \\beta} f(Y | \\beta, X )\\right)’ dY \\right) (X’X)^{-1}\\\\\n&& \\textrm{(where we have used the chain rule and $\\partial \\ln x/ \\partial x = 1/x$)}\\\\ \n&=& \\sigma^2 \\frac{\\partial }{\\partial \\beta }\\left( \\int_{\\mathbb{R}^{k}} \\widehat{\\beta}   f(Y | \\beta, X )\\right)  (X’X)^{-1}\\\\\n&& (\\textrm{by assumption}) \\\\ \n&=& \\sigma^2 \\left( \\frac{\\partial }{\\partial \\beta } \\mathbb{E}_{\\mathbb{P}_{\\beta}}[\\widehat{\\beta}]  \\right) (X’X)^{-1}\\\\\n&=& \\sigma^2 (X’X)^{-1}\\\\\n&& \\textrm{(since $\\widehat{\\beta}$ is unbiased).} \\\\\n&=& \\mathbb{V}_{\\beta}(\\widehat{\\beta}_{\\textrm{OLS}}).\n\\end{eqnarray*}\nHence, \n\\[ 0 \\leq \\mathbb{V}_{\\beta} \\left( c’\\widehat{\\beta} - c’ \\widehat{\\beta}_{\\textrm{OLS}} \\right) = c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}) c - c’ \\mathbb{V}_{\\beta}(\\widehat{\\beta}_{\\textrm{OLS}}) c,  \\]\nfor every $\\beta$. The result then follows. \n\\end{proof}\n\n\\subsection{Suboptimality of the OLS estimator}\n\nIf $k \\geq 3$, the OLS estimator is dominated. In this section we present an estimator that dominates OLS.\n\nAssume that $X’X = \\mathbb{I}_n$. Start with a Bayesian estimator for $\\beta$ under the normal prior $\\beta \\sim \\mathcal{N}_{k}(0,  v \\mathbb{I}_k ) = \\mathcal{N}_{k}(0,  \\sigma^2 (v/\\sigma^2) \\mathbb{I}_k ) $. We have shown that such Bayes estimator is\n\\begin{eqnarray*}\n\\widehat{\\beta}_{\\textrm{Bayes}} &=& \\left(  \\mathbb{I}_k + \\frac{\\sigma^2}{v} \\mathbb{I}_k  \\right)^{-1} \\widehat{\\beta} _{\\textrm{OLS}}, \\\\ \n&=& \\left( \\frac{v}{v+\\sigma^2} \\right) \\widehat{\\beta}_{\\textrm{OLS}}, \\\\\n&=& \\left(1 -  \\frac{\\sigma^2}{v+\\sigma^2} \\right) \\widehat{\\beta}_{\\textrm{OLS}}\n\\end{eqnarray*}\nThe hyperparameter $v$ ``shrinks’’ the OLS estimator towards the prior mean. Instead of picking $v$ \\emph{a priori}, it is possible to use data to estimate it. Such an approach is usually called ``empirical Bayes’’. \n\nThe distribution of the data conditional on the parameter is \n\\[ \\widehat{\\beta}_{\\textrm{OLS}} \\sim \\mathcal{N}_{k}(\\beta, \\sigma^2 \\mathbb{I}_k).  \\]\nThis conditional distribution, along with the prior, specify a full joint distribution over $(\\widehat{\\beta}_{\\textrm{OLS}}, \\beta)$. The marginal distribution of the data is \n\\[\\widehat{\\beta}_{\\textrm{OLS}} \\sim \\mathcal{N}_{k}\\left ( 0 , (\\sigma^2  + v)  \\mathbb{I}_k  \\right). \\]\nWe can use this statistical model to estimate the ``shrinkage’’ factor that appears in the Bayes estimator. Note that\n\\[ ||\\widehat{\\beta}_{\\textrm{OLS}} ||^2 \\sim (\\sigma^2 + v) \\chi^2_{k}, \\]\nTherefore, standard results for the mean of the inverse of a chi-square distribution yield\n\\[\\mathbb{E} \\left[ \\frac{k-2 }{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right] = \\frac{1}{v+\\sigma^2}, \\]\nprovided $k \\geq 3$. An unbiased estimator for the ``shrinkage’’ factor that appears in the formula of $\\widehat{\\beta}_{\\textrm{Bayes}}$ is thus:\n\\[\\left(1 -  \\frac{\\sigma^2 (k-2)}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right). \\]\nWe now show that the ``empirical Bayes’’ estimator \n\\[\\widehat{\\beta}_{JS} \\equiv \\left(1 -  \\frac{\\sigma^2 (k-2)}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right) \\widehat{\\beta}_{\\textrm{OLS}}, \\]\ndominates OLS. This estimator was first proposed by Willard James and Charles Stein in 1961. The estimator is typically referred to as the James-Stein estimator. \n\n\\begin{proposition}\nSuppose $X’X = \\mathbb{I}_{k}$ and $\\sigma^2=1$. If $k \\geq 3$, the James-Stein estimator dominates the ML/OLS estimator. \n\\end{proposition}\n\\begin{proof}\n\\[ || \\widehat{\\beta}_{\\textrm{JS}} - \\widehat{\\beta}_{\\textrm{OLS}} ||^2  = || \\widehat{\\beta}_{\\textrm{JS}} - \\beta ||^2 + || \\beta -\\widehat{\\beta}_{\\textrm{OLS}} ||^2 + 2 ( \\widehat{\\beta}_{\\textrm{JS}} - \\beta  )’ (\\beta -\\widehat{\\beta}_{\\textrm{OLS}}) \\]\nimplies\n\\[|| \\widehat{\\beta}_{\\textrm{JS}} - \\beta ||^2 = || \\widehat{\\beta}_{\\textrm{JS}} - \\widehat{\\beta}_{\\textrm{OLS}} ||^2 - || \\beta -\\widehat{\\beta}_{\\textrm{OLS}} ||^2 + 2 ( \\widehat{\\beta}_{\\textrm{JS}} - \\beta  )’ (\\widehat{\\beta}_{\\textrm{OLS}}- \\beta). \\]\nTaking expectation on both sides yields\n\\begin{eqnarray*} \n\\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ || \\widehat{\\beta}_{\\textrm{JS}} - \\beta ||^2 \\right] & = & \\mathbb{E}_{P_{\\beta}} \\left[  || \\widehat{\\beta}_{\\textrm{JS}} - \\widehat{\\beta}_{\\textrm{OLS}}||^2 \\right] \\\\\n&-& \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ || \\widehat{\\beta}_{\\textrm{OLS}}- \\beta ||^2 \\right] \\\\\n&+& 2 \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ (\\widehat{\\beta}_{\\textrm{JS}} -\\beta)’( \\widehat{\\beta}_{\\textrm{OLS}}- \\beta)  \\right].\n\\end{eqnarray*}\nAlgebra shows that \n\\[\\widehat{\\beta}_{JS} - \\widehat{\\beta}_{\\textrm{OLS}} \\equiv \\left(  \\frac{(k-2)}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right) \\widehat{\\beta}_{\\textrm{OLS}}. \\]\nTherefore,\n\\[  \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ ||\\widehat{\\beta}_{JS} -\\beta ||^2 \\right] =  \\mathbb{E}_{\\mathbb{P}_{\\beta}}  \\left[ \\frac{(k-2)^2}{|| \\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right] - k + 2 \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ (\\widehat{\\beta}_{\\textrm{JS}} -\\beta)’( \\widehat{\\beta}_{\\textrm{OLS}}- \\beta)  \\right]. . \\]\nAlso\n\\begin{eqnarray*}\n\\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ (\\widehat{\\beta}_{\\textrm{JS}} - \\beta)’( \\widehat{\\beta}_{\\textrm{OLS}}- \\beta)  \\right] &=& \\sum_{j=1}^{k} \\textrm{Cov}( \\widehat{\\beta}^j_{\\textrm{JS}},\\widehat{\\beta}^j_{OLS} ). \n\\end{eqnarray*}\nand the last term can be shown to equal\n\\begin{eqnarray*}\n\\sum_{j=1}^{k} \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ \\frac{\\partial \\widehat{\\beta}^j_{JS} }{\\partial \\widehat{\\beta}^j_{\\textrm{OLS}}} \\right] &=& K - \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ \\frac{k  (k-2)}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right] + \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ \\frac{2(k-2)}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right]’ \\\\\n&=&  K - \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ \\frac{(k-2)^2}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right] \n\\end{eqnarray*}\nTherefore,\n\\[  \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ ||\\widehat{\\beta}_{JS} -\\beta ||^2 \\right] = k - \\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ \\frac{(k-2)^2}{||\\widehat{\\beta}_{\\textrm{OLS}} ||^2} \\right] \\leq k =\\mathbb{E}_{\\mathbb{P}_{\\beta}} \\left[ ||\\widehat{\\beta}_{OLS} -\\beta ||^2 \\right].    \\]\n\\end{proof}\n\n\\newpage\n\n\n\\bibliographystyle{../AuxFiles/ecta}\n\\bibliography{../AuxFiles/BibMaster}\n\n\\end{document}\n", "meta": {"hexsha": "5c59c0facd3f48cb50388ec3a9d075f732f464ca", "size": 23328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/Lectures/Lectures07-8.tex", "max_stars_repo_name": "snowdj/Courses-IntroEconometrics-Ph.D", "max_stars_repo_head_hexsha": "4529b2ff1f38567c9aef15a52cde9de946413686", "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/Lectures/Lectures07-8.tex", "max_issues_repo_name": "snowdj/Courses-IntroEconometrics-Ph.D", "max_issues_repo_head_hexsha": "4529b2ff1f38567c9aef15a52cde9de946413686", "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/Lectures/Lectures07-8.tex", "max_forks_repo_name": "snowdj/Courses-IntroEconometrics-Ph.D", "max_forks_repo_head_hexsha": "4529b2ff1f38567c9aef15a52cde9de946413686", "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": 80.1649484536, "max_line_length": 528, "alphanum_fraction": 0.6589934842, "num_tokens": 8291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.642596261812063}}
{"text": "\\lab{Application}{Stochastic Cake-Eating Problem}{Stochastic Cake-Eating Problem}\n\\newcommand\\ve{\\varepsilon}\n\n\\objective{In this section we study the stochastic cake-eating problem with both normal and AR(1) shocks.}\n\n\\section*{Infinite Horizon, Stochastic, i.i.d.}\\label{SecRecProbInfinHorStochiid}\n\nIn practice, dynamic programming problems often involve some level of uncertainty.  For example as time progresses prices may change, resources may vary, or preferences themselves may change.  In this lab, we reexamine the cake eating problem, this time allowing for uncertainty.\n\nWe consider again the problem of opimizing a sequence of decisions over an infinite time horizon.  We assume that the individuals preferences fluctuate each period according to some \"shock\" $\\ve$, meaning $\\ve$ is a random variable.  We assume that the $\\ve$ are identically and independently distributed (i.i.d).  In effect, this means the probabilities associated with the $\\ve$ are the same for any time $t$ and do not depend on each other.  We assume for now that the $\\ve$ are distributed normally with mean $\\mu$ and variance $\\sigma^2$.  The Bellman equation can be easily rewritten 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) + \\beta E_{\\ve'}\\left[V\\left(W',\\ve'\\right)\\right] \\quad\\text{where}\\quad \\ve \\sim \\text{N}(\\mu,\\sigma^2)\n\\end{equation*}\nwhere $E$ is the unconditional expectations operator over $\\ve$.  Note that now the value function is a function of two variables.  It represents the value of entering the period with $W$, the amount of cake, and a preference shock of $\\ve$.  For example, in a period where the realization of $\\ve$ is higher, we will get more value from the cake eaten in the current period.  Because we do not know the value of the 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 problem considered in the Value Function Iteration lab.  It is worth noting that in this case, computationally 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 it could take along with the corresponding probabilities that it takes each of those values.  However, $N(\\mu,\\sigma^2)$ is a continuous distribution so we cannot represent every value $\\ve$ could take.  We need a discrete distribution that approximates $N(\\mu,\\sigma^2)$.\n\nTo do this we can think of breaking the distribution $N(\\mu,\\sigma^2)$ up into bins with endpoints $v_1,v_2,\\ldots, v_K$.\n\n\\begin{figure}[h!]\n\\label{stoch1_fig1}\n\\begin{center}\n\\includegraphics[scale = 0.5]{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}$.  In python we can find the area using the function norm.cdf in the stats package.  The cdf function gives the area under the curve from minus infinity to a specified value.  For example, in the following code, eps is the area under the curve from 0 to 1.\n\n\\begin{lstlisting}[style=python]\nfrom scipy import stats as st\n\nmu = 0\nsigma = 1\neps = st.norm.cdf(1,mu,sigma) - st.norm.cdf(0,mu,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$.\n\n\\begin{problem}\nWrite a function called discretenorm that accepts an integer representing the number of discrete points desired, a mean, and a standard deviation and returns a 1 by N vector of values ranging from $\\mu - 3\\sigma$ to $\\mu + 3\\sigma$  and a 1 by N vector of the associated probabilities.  Plot the approximation of $N(0,1)$ using 7 points.\n\\end{problem}\n\nNow that we have a discrete distribution for $\\ve$, we can solve for the value and policy functions determined by \\eqref{stoch_Bellman}.\n\n\\begin{problem}\nComplete the following steps to solve the problem described above.\n\\begin{enumerate}\n   \\item First we establish our approximation of $\\ve$ using the discretenorm function created in Problem 1. Let $\\sigma^2 = 0.25$ and $\\mu=4\\sigma$ (This way the shocks, $\\ve$, are always positive.) Use $K=7$ equally spaced points to approximate $N(\\mu,\\sigma^2)$ so that $\\ve$ is a $K$-length row vector.  Using the function discretenorm from problem 1, generate the probability distribution $\\Gamma$ for $\\ve$. This should be a $K$-length row vector whose entries indicate $P(\\ve = \\ve_k)$\n\n   \\item As in the Value Function Iteration lab, assume that the vector of possible cake sizes is $W$ with $N=100$ equally spaced values between 0 and 1.  Represent the value function as a matrix with each row corresponding to different values of $W'$ and each column corresponding to different values of $\\ve'$. Initialize the value function to an $N$ by $K$ matrix of zeros.  Assume that the period utility function is $u(c)=\\sqrt{c}$, and that the discount factor is $\\beta = 0.9$.\n\n\n   \\item In order to evaluate the value function equation we need to compute $\\ve u(W-W')$ for all values of $\\ve,W,W'$.  Thus $\\ve u(W-W')$ will be represented by a three-dimensional array of size $N\\times N\\times K$.  This can be achieved using the tile function.  For example, if $u(W-W')$ is represented by the $N\\times N$ matrix util\\_grid, and eps is the vector of $\\ve$ values, then we could create the $\\ve u(W-W')$ matrix by the following:\n       \n       \\begin{lstlisting}[style = python]\n       util3 = sp.tile(util_grid[:,:,sp.newaxis],(1,1,K))\n       eps_grid = eps[sp.newaxis,sp.newaxis,:]\n       eps_util = eps_grid*util3\n       \\end{lstlisting}\n         \n       The input (1,1,K) tells sp.tile to repeat util\\_grid K times in the third dimension.  Note we have to put util\\_grid[:,:,sp.newaxis] in order to have a three-dimensional input since util\\_grid is only two dimensional.\n         \n       As in the Value Function Iteration Lab, we replace negative entries in $W-W'$ by 0.\n\n   \\item We also need to compute $E_{\\ve'}\\Bigl[V_k\\left(W',\\ve'\\right)\\Bigr]$.  The expected value is simply\n       \\begin{equation*}\n       E_{\\ve'}\\Bigl[V_k\\left(W',\\ve'\\right)\\Bigr] = \\sum_k \\Gamma(k)V_k(W',\\ve_k')\n       \\end{equation*}  The result is an $N\\times 1$ vector that gives the value for each $W'$.  However we need an $N\\times N\\times K$ array to add to $\\ve u(W-W')$.  Since the expected value does not depend on $W,\\ve$, we tile the vector to create a 3D array that is constant along the $W$ and $\\ve$ dimensions.\n\n   \\item We can now compute the value function contraction\n     \\begin{equation}\\label{EqContractStochiid}\n      V_{k+1}\\left(W,\\ve\\right) \\equiv C\\Bigl(V_k\\left(W,\\ve\\right)\\Bigr) \\equiv \\max_{W'\\in[0,W]}\\: \\ve u\\left(W-W'\\right) + \\beta E_{\\ve'}\\Bigl[V_k\\left(W',\\ve'\\right)\\Bigr].\n      \\end{equation}\n        Before doing so, replace the entries of $\\ve u\\left(W-W'\\right) + \\beta E_{\\ve'}\\Bigl[V_k\\left(W',\\ve'\\right)\\Bigr]$ that corrsepond to $W-W' < 0$ with a large negative number (e.g. $-10^{10}$) so they will not be chosen in the maximization.\n\n   \\item As we iterate on the value function equation, we need a norm\n    \\begin{equation*}\n        \\delta_k = \\norm{V_k\\left(W,\\ve\\right) - V_{k-1}\\left(W,\\ve\\right)}\n    \\end{equation*}\n    that measures the distance between the two value functions to determine convergence.  Compute the norm using the scipy function scipy.linalg.norm.  Iterate on the contraction until $\\delta_k < 10^{-9}$.\n\n   \\item Make a 3-D surface plot of the policy function for the converged problem $W' = \\psi\\left(W,\\ve\\right)$ which gives the value of the cake tomorrow as a function of the cake today  and the taste shock today.  Do the same for the value function.\n\n\\end{enumerate}\n\\end{problem}\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 previous periods.  Often a shock may depend on recent events.  We will assume now that the shocks are persistent, meaning preferences in the current period are more likely to be close to what they were in the previous period.  We can characterize the persistence by what is called an autoregressive process of order one, denoted AR(1).  Such 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 weighted average (weighted by $\\rho$) of some $\\mu$ and the previous realization of the shock, $\\ve$.  As it turns out, we can approximate this process by thinking of it like a Markov Chain. This means we need to determine a discrete set of points representing possible values of $\\ve$ and a Markov transition matrix that gives the probabilities of moving from one value of $\\ve$ to another.  There are methods for determining the discrete approximation of $\\ve$ with a Markov transition matrix.  The methods are beyond the scope of this section, but you can use the file 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 expectations 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) + \\beta E_{\\ve'|\\ve}\\left[V\\left(W',\\ve'\\right)\\right]\n\\end{equation*}\nwhere $\\ve'$ is distributed according to \\eqref{EqAR1shock}. Let $\\Gamma(\\ve'|\\ve)=\\text{Pr}\\left(\\ve_j'|\\ve_i\\right)$ where $\\ve_j'$ is the value of the shock in the next period and $\\ve_i$ is the value of the shock in the current period.  In other words, $\\Gamma(\\ve' | \\ve)$ 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 the probability distributions of the $\\ve$.\n\n\\begin{problem}\n\\begin{enumerate}\n   \\item Use the file tauchenhussey.py to approximate the AR(1) process for $\\ve$ from \\eqref{EqAR1shock} as a Markov chain. The provided Python function tauchenhussey.py will produce a vector of length $M$ for the support of $\\ve$ and an $M\\times M$ transition matrix $\\Gamma(\\ve'|\\ve)=\\text{Pr}\\left(\\ve_j'|\\ve_i\\right)$ where each element in row $i$ and column $j$ represents the probability of the shock $\\ve_j'$ next period given the current shock is $\\ve_i$. As inputs to tauchenhussey.py, let $M=7$, the mean of the process $\\mu=4\\sigma$, $\\rho = 1/2$, $\\sigma=\\sqrt{\\sigma^2}=1/2$, and $basesigma=(0.5+\\frac{\\rho}{4})\\sigma + (0.5 - \\frac{\\rho}{4})*\\frac{\\sigma}{\\sqrt{1-\\rho^2}}$.\n\n  \\item Solving this version of the problem should be very similar to the i.i.d. case completed in problem 2.  The most significant difference is that now we need to compute the conditional expectation\n      \\begin{equation}\n      E_{\\ve'|\\ve}\\left[V\\left(W',\\ve'\\right)\\right].\n      \\end{equation}\n      In this case, the expectation is two-dimensional since it depends on both $W'$ and on $\\ve$.  The expectation can be computed by matrix multiplying $V(W',\\ve')\\Gamma(\\ve' | \\ve)'$ where the last \"$'$\" represents transposing $\\Gamma$.  Again we will need an $N\\times N\\times K$ array, so we tile the result $K$ times representing that the expectation is constant along $W$.\n\n  \\item Solve for the optimal policy by Value Function Iteration.  Plot the value function and policy function surfaces.\n\n\n\\end{enumerate}\n\\end{problem} ", "meta": {"hexsha": "ff61068768753bc1f6fd2a80368a24857617335f", "size": 11805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Dynamic_Programming/Stochastic_Cake_Eating.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/Stochastic_Cake_Eating.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/Stochastic_Cake_Eating.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": 96.762295082, "max_line_length": 738, "alphanum_fraction": 0.7274036425, "num_tokens": 3232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6425962580144247}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{\n  amsmath,\n  amssymb,\n  tikz,\n  microtype,\n  amsthm,\n  thmtools,\n  stmaryrd,\n  hyperref,\n  algorithm2e\n}\n\n\n\\title{Special topics course: Numerical Polynomial Algebra}\n\\author{Anand Deopurkar and Markus Hegland}\n\\date{ANU winter semester 2018}\n\n\\renewcommand{\\algorithmautorefname}{Algorithm}\n\\newcommand{\\C}{\\mathbb C}\n\\newcommand{\\Z}{\\mathbb Z}\n\\newcommand{\\R}{\\mathbb R}\n\\DeclareMathOperator{\\LT}{LT}\n\\DeclareMathOperator{\\wt}{wt}\n\n\\declaretheorem{theorem}\n\\declaretheorem[sibling=theorem, style=theorem]{proposition}\n\\declaretheorem[sibling=theorem, style=definition]{definition}\n\\declaretheorem[sibling=theorem, style=definition]{example}\n\\declaretheorem[sibling=theorem, style=definition]{problem}\n\\declaretheorem[sibling=theorem, style=remark]{remark}\n\n\\begin{document}\n\n\\maketitle\n\n\\part*{Algebraic introduction}\nThis is a quick introduction to the commutative algebra relevant to systems of polynomial equations.\nOur main references are Stetter \\cite{stetter04} and Cox, Little, O'Shea \\cite{cox15}.\n\n\\tableofcontents\n\n\\section{Polynomials and ideals}\n\nLet $k$ be a field.\nDenote by $k[x_1,\\dots,x_s]$ the set of polynomials in variables $x_1, \\dots, x_s$ with coefficients in $k$. \nStetter denotes $k[x_1,\\dots,x_s]$ by $P^s_k$.\nFor numerical analysis, we will take the base-field $k = \\R$, but a lot of the algebraic geometry works best with $k = \\C$.\nThe case of $k = \\Z/p\\Z$ is used frequently for exact symbolic computation.\nWe will try to be base-field agnostic; but for some results, the base-field will play an important role. \n\nLet $f_1, \\dots, f_k$ be elements of $k[x_1,\\dots, x_s]$.\nWe are interested in solving the system of polynomial equations\n\\begin{align}\\label{eqn:system}\n  \\begin{split}\n  f_1(x_1, \\dots, x_s) &= 0,\\\\\n  &\\vdots\\\\\n  f_n(x_1, \\dots, x_s) &= 0.\n\\end{split}\n\\end{align}\nOur experience with systems of linear equation suggests that we should look at not only the $n$ equations listed above, but also their linear combinations.\nThis idea suggests the following.\n\\begin{definition}[Ideal]\n  A subset $I$ of $k[x_1, \\dots, x_s]$ is called an \\emph{ideal} if the following two conditions are satisfied.\n  \\begin{enumerate}\n  \\item If $f, g \\in I$, then $f+g \\in I$.\n  \\item If $f \\in I$ and $c \\in k[x_1, \\dots, x_s]$, then $cf \\in I$.\n  \\end{enumerate}\n\\end{definition}\nThe definition of an ideal should be reminiscent of the definition of a subspace of a vector space.\nThe only difference is that the multipliers in the second condition are not necessarily scalars (elements of $k$) but polynomials.\nBy putting the two conditions together, we see that an ideal is a subset of $k[x_1, \\dots, x_s]$ that is closed under polynomial linear combinations.\nThat is, if $f_1, \\dots, f_n \\in I$ and $c_1, \\dots, c_n \\in k[x_1, \\dots, x_s]$, then $c_1f_1 + \\dots + c_nf_n \\in I$.\n\n\\begin{example}[The unit ideal]\n  The set $I = k[x_1,\\dots,x_s]$ is obviously an ideal; it is called the unit ideal.\n  Observe that it is the only ideal that contains $1$.\n\\end{example}\n\n\\begin{example}[Ideal generated by a set of polynomials]\n  If $f_1, \\dots, f_n$ are elements of $k[x_1, \\dots, x_s]$, then the set consisting of all polynomial linear combinations of $f_1, \\dots, f_s$, namely\n  \\[ I = \\{c_1f_1 + \\dots + c_nf_n \\mid c_1, \\dots, c_n \\in k[x_1,\\dots,x_s]\\}\\]\n  is an ideal.\n  It is the smallest ideal containing $f_1, \\dots, f_n$.\n  We say that $I$ is \\emph{generated by} $f_1, \\dots, f_n$, and write\n  \\[ I = \\langle  f_1, \\dots, f_n \\rangle.\\]\n\\end{example}\n\nA fundamental theorem in commutative algebra is that every ideal has a finite generating set.\n\\begin{theorem}[Hilbert basis theorem]\n  Let $I \\subset k[x_1, \\dots, x_s]$ be an ideal.\n  Then there exists polynomials $f_1, \\dots, f_n$ such that $I = \\langle  f_1, \\dots, f_n \\rangle$.\n\\end{theorem}\nThere are multiple generating sets for a given ideal, just as there are multiple spanning sets for a subspace of a vector space.\nDepending on what we want to do, some generating sets are more useful than others.\nA common theme in the course will be to learn how to construct and use good generating sets.\n\n\\subsection{Zero loci of ideals}\nLet $I \\subset k[x_1, \\dots, x_s]$ be an ideal.\nWe can associate to $I$ a subset $V(I)$ of $k^s$ called the \\emph{zero locus} or the \\emph{vanishing locus} of $I$.\nIt is defined as follows:\n\\[\n  V(I) = \\{x \\in k^s \\mid f(x) = 0 \\text{ for all $f \\in I$}\\}.\n\\]\nObserve that if $I = \\langle  f_1, \\dots, f_n \\rangle$, then $V(I)$ is simply the set of solutions of the system of equations \\eqref{eqn:system}.\nThus, solving \\eqref{eqn:system} is equivalent to finding $V(I)$.\n\nA subset of $k^s$ of the form $V(I)$ for some ideal $I$ is called an \\emph{algebraic set}.\nSome authors also call an algebraic set an \\emph{algebraic variety}, but some other authors reserve the term \\emph{variety} only for special types of algebraic sets (namely, the ``irreducible'' ones).\n\nWe can turn the construction $I \\leadsto V(I)$ around.\nStarting with a subset $Z \\subset k^s$, we can construct an ideal $I(Z) \\subset k[x_1, \\dots, x_s]$ as follows:\n\\[ I(Z) = \\{f \\in k[x_1,\\dots,x_s] \\mid f(x) = 0 \\text{ for all $x \\in Z$}\\}.\\]\nIt is easy to check that $I(Z)$ is an ideal.\nFurthermore, it is easy to verify that $I(Z)$ is a \\emph{radical} ideal.\nThat is, it satisfies the property that if $f^n \\in I(Z)$ for some $n \\geq 1$, then $f \\in I(Z)$.\n(This property is not shared by all ideals.\nFor example, the ideal $\\langle  x^2 \\rangle \\subset k[x]$ is not radical---it contains $x^2$, but not $x$.)\n\n\\begin{example}[Ideal of $3$ points in $k^2$]\n  \\label{ex:3pts}\n  Let $Z = \\{(0,0), (0,1), (1,0)\\}$.\n  Then we have\n  \\[ I(Z) = \\langle x(x-1), xy, y(y-1)) \\rangle.\\]\n\\end{example}\n\\begin{example}[Ideal of the ``twisted cubic'']\n    \\label{ex:twistedcubic}\nLet $Z = \\{(t, t^2, t^3) \\mid t \\in \\C\\} \\subset \\C^3$.\n  Then\n  \\[ I(Z) = \\langle  x^2-y, y^2-xz, x^3-z \\rangle.\\]\n\\end{example}\n\\begin{example}[Ideal of $4$ points in $k^2$]\n  \\label{ex:4pts}\n  Let $Z = \\{(0,0), (1,0), (0,1), (1,1)\\}$.\n  Then\n  \\[ I(Z) = \\langle  x(x-1), y(y-1) \\rangle.\\]\n\\end{example}\n\\begin{remark}\n  The ideal in \\autoref{ex:4pts} is different in a crucial way from the ideals in \\autoref{ex:3pts} and \\autoref{ex:twistedcubic}.\n  It is a \\emph{complete intersection} ideal.\n  A complete intersection ideal is an ideal that is generated by as many polynomials as the codimension of its vanishing set.\n  In \\autoref{ex:4pts}, the codimension of the vanishing set is 2, and indeed, the ideal is generated by 2 polynomials.\n  One can prove that if the base-field is algebraically closed, then an ideal needs at least as many generators as the codimension of its vanishing locus.\n  A complete intersection ideal is one where the bound is achieved.\n\n  A complete intersection ideal is stable under perturbation of its generators.\n  We will not make this precise, but illustrate it in the examples above.\n  If we perturb one (or both) of the generators of the ideal in \\autoref{ex:4pts}, then the perturbed ideal remains the ideal of $4$ points.\n  In contrast, if we perturb the generators of the ideals in \\autoref{ex:3pts} or \\autoref{ex:twistedcubic}, then the ideal changes dramatically in shape.\n  In \\autoref{ex:3pts}, a perturbation of the generators will make the ideal become the unit ideal.\n  In \\autoref{ex:twistedcubic}, a perturbation of the generators will make the ideal become the ideal of a finite set of points.\n  You are encouraged to verify these statements about perturbations either by hand or using a computer algebra system.\n\\end{remark}\n\n\\subsection{The Nullstellensatz}\nThe following important theorem links the constuctions $I \\mapsto V(I)$ and $Z \\mapsto I(Z)$.\n\\begin{theorem}[Nullstellensatz]\n  Suppose $k$ is an algebraically closed field (for example, $k = \\C$).\n  Then we have a one-to-one correspondence\n  \\[\n    \\{\\text{Radical ideals of $k[x_1,\\dots,x_s]$}\\}\n    \\leftrightarrow\n    \\{\\text{Algebraic subsets of $k^s$}\\},\n  \\]\n  where the $\\rightarrow$  direction is given by $I \\mapsto V(I)$ and the $\\leftarrow$ direction is given by $I(Z) \\mapsfrom Z$.\n\\end{theorem}\n\n\\begin{example}[Failure of the Nullstellensatz for non-closed fields]\n  In the Nullstellensatz, it is essential for the base-field to be algebraically closed.\n  To see what can go wrong otherwise, take $k = \\R$ and $I = \\langle  x^2 + 1 \\rangle \\subset k[x]$.\n  Then $I$ is a radical ideal, and we have $V(I) = \\emptyset$.\n  But we also have $V(\\langle  1 \\rangle) = \\emptyset$.\n  So the correspondence is not one-to-one.\n\n  This example shows that when $k$ is ``too small'' (not algebraically closed), then the geometric (right) side may fail to faithfully capture the algebraic (left) side.\n  But this happens only because the points on the right hand side that \\emph{should} be there are not there because the base-field is too small.\n\\end{example}\n\nA consequence of the Nullstellensatz is the following dichotomy for systems of polynomial equations.\n\\begin{theorem}\\label{thm:null}\n  Consider the system of polynomial equations $f_1 = 0, \\dots, f_n = 0$ over an algebraically closed field $k$.\n  Then either there exists a solution or there exist polynomials $c_1, \\dots, c_n$ such that\n  \\[ 1 = c_1 f_1 + \\dots + c_nf_n.\\]\n  Equivalently, given an ideal $I$, either $V(I)$ is non-empty, or $I = \\langle  1 \\rangle$.\n\\end{theorem}\n\\begin{proof}\n  Suppose $V(I)$ is empty.\n  We must prove that $1 \\in I$.\n  If $I$ is radical, then we have\n  \\[ V(I) = V(\\langle 1 \\rangle) = \\emptyset.\\]\n  So by the Nullstellensatz, we have $I = \\langle  1 \\rangle$, and we are done.\n\n  If $I$ is not radical, then we replace it by its radical $\\sqrt I$, defined by\n  \\[ \\sqrt I = \\{f \\mid f^n \\in I \\text{ for some $n \\geq 1$}\\}.\\]\n  It is not too hard to check (do it!) that $\\sqrt I$ is an ideal, is radical, and $V(I) = V(\\sqrt I)$.\n  From the argument above, we get that $\\sqrt I = \\langle  1 \\rangle$, that is $1 \\in \\sqrt I$.\n  But by the definition of $\\sqrt I$, this means that $1^n \\in I$ for some $n \\geq 1$, so $I = \\langle  1 \\rangle$.\n\\end{proof}\n\n\\begin{remark}\n  Over the real numbers, although the Nullstellensatz fails, an analogous theorem called the Positivestellensatz holds.\n  Although it is tempting, we will not discuss this further.\n  This topic belongs to an interesting field of mathematics that lies on the interface of algebraic geometry, combinatorics, applied mathematics, and logic, called \\emph{real algebraic geometry}.\n\\end{remark}\n\n\\section{Ideal membership and the division algorithm}\nLet us return to the system of polynomial equations\n\\begin{align}\\label{eqn:system1}\n  \\begin{split}\n  f_1(x_1, \\dots, x_s) &= 0,\\\\\n  &\\vdots\\\\\n  f_n(x_1, \\dots, x_s) &= 0.\n\\end{split}\n\\end{align}\nAs a first step towards solving this system, we would like to determine whether the system has any solutions at all.\nBy \\autoref{thm:null}, this is equivalent to determining whether $1$ lies in the ideal $\\langle  f_1, \\dots, f_n \\rangle$.\nIn this section, we will consider a general version of this problem.\n\\begin{problem}[Ideal membership]\n  Given polynomials $f_1, \\dots, f_n$ and a polynomial $g$, determine whether $g$ lies in the ideal $\\langle  f_1, \\dots, f_n \\rangle$.\n\\end{problem}\n\n\\subsection{The one-variable case}\nSuppose $s = 1$ and $n = 1$.\nSo, we are given a (non-zero) polynomial $f(x)$ and another polynomial $g(x)$.\nWe want to determine whether $g(x)$ is lies in the ideal $\\langle  f(x) \\rangle$, that is, whether $g(x)$ is a multiple of $f(x)$.\nHere we know what to do: simply run the division algorithm (\\autoref{alg:divalg1}).\n\n\\begin{algorithm}\n  \\While{\n    $\\deg (g) \\geq \\deg(f)$\n  }\n  {\n    Replace $g$ by $g - \\frac{\\LT(f)}{\\LT(g)} f$, where $\\LT$ denotes the leading (highest degree) term.\n  }\n  Return $g$ as the remainder.\n  \\bigskip\n\n  \\caption{The division algorithm for $g(x) \\pmod {f(x)}$}\n  \\label{alg:divalg1}\n\\end{algorithm}\n\nIn the one-variable case, we have the following key fact.\n\\begin{proposition}\n  The polynomial $g(x)$ lies in $\\langle  f(x) \\rangle$ if and only if the remainder obtained in the division algorithm for $g(x) \\pmod {f(x)}$ is zero.\n\\end{proposition}\n\n\\subsection{Term orderings}\nTo extend the division algorithm to handle more than one variable and ideals generated by more than one polynomial, we must first extend the notion of the leading term.\nIt turns out that there are multiple ways to do this.\nIt gives rise to the idea of a term ordering.\n\nLet $T^s$ be the set of monomials in the variables $\\{x_1, \\dots, x_s\\}$.\nWe use multi-indices to denote the elements in $T^s$.\nFor a multi-index $i = (i_1, \\dots, i_s)$, the notation $x^i$ means the monomial $x_1^{i_1} \\cdots x_s^{i_s}$.\n\\begin{definition}[Term ordering]\n  A \\emph{term ordering} is a total ordering $\\prec$ on the elements of $T^s$ satisfying the following two properties:\n  \\begin{enumerate}\n  \\item if $x^i \\prec x^j$ then $x^i \\cdot x^k \\prec x^j \\cdot x^k$ for all multi-indices $k$.\n  \\item $1 \\prec x^i$ for all multi-indices $i$.\n  \\end{enumerate}\n\\end{definition}\n\nFor $s = 1$, there is only one possible term ordering, namely \\[1 \\prec x \\prec x^2 \\prec \\cdots.\\]\nFor $s > 1$, however, there are many possibilities.\n\\begin{example}[Lexicographical ordering $\\prec_{\\rm lex}$]\n  Fix an ordering on the variables, say $x_s \\prec x_{s-1} \\prec \\cdots \\prec x_1$.\n  Extend this ordering to monomials using the lexicographical rule.\n  That is, set $x^i \\prec_{\\rm lex} x^j$ if the first non-zero entry of $j-i$ is positive.\n\\end{example}\n\n\\begin{example}[Graded lexicographical ordering $\\prec_{\\rm grlex}$]\n  Fix an ordering on the variables, say $x_s \\prec x_{s-1} \\prec \\cdots \\prec x_1$.\n  Extend this ordering to monomials by first comparing the total degree and then using the lexicographical rule.\n  That is, set $x^i \\prec_{\\rm grlex} x^j$ if $\\deg(x^i) < \\deg(x^j)$ or if $\\deg(x^i) = \\deg(x^j)$ and $x^i \\prec_{\\rm lex} x^j$.\n\\end{example}\n\n\\begin{example}[Weight ordering]\n  Assign a weight $\\alpha_i \\in \\R_{> 0}$ to each variable $x_i$.\n  Extend the weight assignment to monomials by taking a weighted sum\n  \\[ \\wt(x^i) = \\sum_{\\ell = 1}^s i_\\ell \\alpha_\\ell.\\]\n  Use this to define a term ordering by setting $x^i \\prec_\\alpha x^j$ if $\\wt(x^i) < \\wt(x^j)$.\n\n  We have to take care that there are no ties in the weights of the monomials (or devise a tie-breaker).\n  For generic (almost all) choices of weights, there will be no ties.\n\\end{example}\n\nFix a term ordering $\\prec$.\nUsing $\\prec$, we can define the leading term of a polynomial.\nFor $f \\in k[x_1,\\dots,x_s]$, let $\\LT(f)$, or more precisely $\\LT_\\prec(f)$, be the term of $f$ with the highest monomial (according to $\\prec$).\nFor example, we have\n\\begin{align*}\n  \\LT_{\\prec_{\\rm lex}} (5x^3y^3-3x^4)  &= -3x^4 \\\\\n  \\LT_{\\prec_{\\rm grlex}} (5x^3y^3-3x^4)  &= 5x^3y^3. \n\\end{align*}\nWe can now generalize the division algorithm as follows.\n\n\\begin{algorithm}\n  \\While{\n    there exists an $i$ such that $\\LT(f_i)$ divides $\\LT(g)$.\n  }\n  {\n    Replace $g$ by $g - \\frac{\\LT(f_i)}{\\LT(g)} f_i$.\n  }\n  Return $g$ as the remainder.\n  \\bigskip\n\n  \\caption{The division algorithm for $g \\pmod {f_1, \\dots, f_n}$}\n\\end{algorithm}\n\nIt is easy to see that if the division algorithm for $g \\pmod {f_1, \\dots, f_n}$ returns $0$ as the remainder, then $g$ is in the ideal $\\langle  f_1, \\dots, f_n \\rangle$.\nHowever, the converse is not true, as the next examples show.\nThis severely diminishes the utility of the division algorithm.\n\nThe division algorithm suffers from another drawback.\nNote that there may be choices involved in the running of the algorithm.\nNamely, if there are multiple $i$'s such that $\\LT(f_i)$ divides $\\LT(g)$, then we may choose any one and proceed.\nThe final remainder obtained may change depending on the choices made in the algorithm.\n\nNevertheless, we will see in the next section, that we can overcome both o these drawbacks by making a judicious choice of the generating set for our ideal.\n\n\\begin{example}[Failure of the division algorithm]\n  Let us work with $\\prec_{\\rm grlex}$.\n  Take $f_1  = x^3-2xy$ and $f_2 = x^2y-2y^2+x$; and $g = x^2$.\n  Then the division algorithm stops without any computation, and returns $x^2$ as the remainder.\n  However, the following computation shows that $g$ is actually in the ideal $\\langle  f_1, f_2 \\rangle$:\n  \\[ g = x \\cdot f_2 - f_1.\\]\n\\end{example}\n\n\\begin{example}[Failure of the division algorithm]\n  We can work in any term ordering.\n  Take $f_1 = xy-1$, $f_2 = x^3-y^3$, and $f_3 = x^2+y^2$.\n  Check that $1 \\in \\langle  f_1, f_2, f_3 \\rangle$ (either directly or using that $V(\\langle  f_1, f_2, f_3 \\rangle) = \\emptyset$).\n  However, the division algorithm stops without any computation, and returns $1$ as the remainder.\n\\end{example}\n\n\\subsection{Gr\\\"obner bases}\n\n\\bibliography{ch2}\n\\bibliographystyle{amsalpha}\n\n\\end{document}", "meta": {"hexsha": "562888dabcd31ad9d42f5bb96da511ac9c64fc7d", "size": 16851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/ch2.tex", "max_stars_repo_name": "Chr1sWilliams/NumericalPolyonomialAlgebra", "max_stars_repo_head_hexsha": "a99701bc68ee1db052d5c0b1aabb1588800b6cc3", "max_stars_repo_licenses": ["MIT"], "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/ch2.tex", "max_issues_repo_name": "Chr1sWilliams/NumericalPolyonomialAlgebra", "max_issues_repo_head_hexsha": "a99701bc68ee1db052d5c0b1aabb1588800b6cc3", "max_issues_repo_licenses": ["MIT"], "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/ch2.tex", "max_forks_repo_name": "Chr1sWilliams/NumericalPolyonomialAlgebra", "max_forks_repo_head_hexsha": "a99701bc68ee1db052d5c0b1aabb1588800b6cc3", "max_forks_repo_licenses": ["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.4164222874, "max_line_length": 200, "alphanum_fraction": 0.7050026705, "num_tokens": 5285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6425962562225488}}
{"text": "\\subsection{Boltzmann Machine}\n\n% --- Lucas\n\n\\begin{figure}[htbp]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.5\\textwidth]{inc/boltzmann_machine.png}\n\t\t\\caption{Illustration of a Boltzmann Machine. The blue units represents three hidden units, while the four white units represents four visible units.\\protect\\footnotemark}\n\t\t\\label{fig:boltzmann_machine}\n\t\\end{center}\n\\end{figure}\n\\footnotetext{Original image (Public Domain): \\url{https://en.wikipedia.org/wiki/File:Boltzmannexamplev1.png}}\n\nThe ``Boltzmann Machine'' (BM) is a form of ``parallel constraint satisfaction network'' \\cite{ackley1985learning}. It is capable of learning the underlying constraints of a domain by only being shown examples of it. The BM is composed of units (also known as nodes) forming a complete graph where the connection between two units are symmetric; meaning that the weight on the connection is the same in either direction. No unit has a connection to itself. The units are binary, in the meaning that they can only assume one of two states, on or off. The state of a unit is determined by a probabilistic function based on the states of the units neighbours. A strong connection (high weight value) between two units indicates that if either of these two units are active, the other one should probably be active as well. While a weak connection (low weight value) indicates that these should probably not be active at the same time. This is analogous to Hebbian learning.\n\nThe BM is notably similar to the Hopfield network in that it also defines a global energy state of the system, utilizing the same equation that determines the global energy value. Each global state can be identified by the energy of the system in that state. By forcing the values of the visible units to represent a training set the system attempts to find an energy configuration that is compatible with the given input. The resulting energy state can then be interpreted as to how well the given data fulfils the constraints of the domain. Thus by minimizing the energy the system learns an interpretation of the problem that increasingly satisfies the constraints of the domain.\n\nThe simplest way to minimize the energy into a local minimum of the system is to change each units state into a value that results in a lower energy state. The data needed to determine this change is locally accessible to each unit, and is dependent on the current state of the units neighbours. If the sum of all values for a given units neighbour exceeds the threshold of that unit, the resulting state of the unit should be on. Otherwise it should be off. This is the usual algorithm for binary units.\n\nBecause of this deterministic algorithm it suffers from the usual weaknesses of gradient descent algorithms, namely, it gets stuck in local minima if its initial state is close to one. In order to alleviate the algorithm of this problem, noise is introduced in the training. This allows the network to ``jump'' out of these minima into configurations of higher energy. The algorithm used for noise introduction is a variation of the ``Metropolis algorithm'' \\cite{metropolis1953equation} that was used to study thermodynamic systems. This modified version introduces a concept of temperature to the machine, which then tries to reach ``thermal equilibrium'' during training. Meaning that the machine is allowed to run repeatedly until the global energy of the system converges to a fixed state over a temperature that is initially high and then slowly decreased over the runtime of the system. The probability of finding the system in a global state after it has reached thermal equilibrium follows a Boltzmann distribution. If the temperature feed into the machine is equal to zero the stochastic nature of it is removed, the machine becomes deterministic and can be seen as a regular Hopfield network.\n\n%TODO discuss the usage of Hebbian learning in Boltzmann\n%TODO write more about this temperature thing\n%TODO write more about the probabilistic features of the BM as well as the Boltzmann distribution that gives the system its name.\n\nTraining is conducted in two phases, in the first phase the visible units of the machine are set to the values of the training set. In the next phase the machine is allowed to run freely, independent of the training set. The machine is iteratively switched between these two phases for the duration of the training until it reaches thermal equilibrium. The goal of the training is for the machine to be able to generate the input vector with a high probability of success.\n\n% --- NOTES\n%The difference between the BM and the Hopfield network is mainly that the nodes (or units as they are referred to in the original paper) of the Boltzmann Machine are stochastic by nature.\n%The BM can be used for constraint satisfaction problems that involve a large amount of weak constraints.\n", "meta": {"hexsha": "6628cd0d6a453d6852b8b544ea8669394cc14285", "size": 4876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/2_models_of_associative_memory/2_boltzmann_machine.tex", "max_stars_repo_name": "mewmew/associative_memories", "max_stars_repo_head_hexsha": "d0c50cf3efbcab9369f5a030125752253539d9e0", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-30T12:08:22.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-30T12:08:22.000Z", "max_issues_repo_path": "report/sections/2_models_of_associative_memory/2_boltzmann_machine.tex", "max_issues_repo_name": "mewmew/associative_memory", "max_issues_repo_head_hexsha": "d0c50cf3efbcab9369f5a030125752253539d9e0", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2016-04-04T00:06:16.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-02T13:32:52.000Z", "max_forks_repo_path": "report/sections/2_models_of_associative_memory/2_boltzmann_machine.tex", "max_forks_repo_name": "mewmew/associative_memory", "max_forks_repo_head_hexsha": "d0c50cf3efbcab9369f5a030125752253539d9e0", "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.2903225806, "max_line_length": 1203, "alphanum_fraction": 0.8059885152, "num_tokens": 1000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6425852013287164}}
{"text": "\\input{preamble}\n\n\\begin{document}\n\n\\header{1}{Volumetric Path Tracing}\n\n\\begin{figure}[h]\n    \\includegraphics[width=\\linewidth]{imgs/colored_smoke.png}\n    \\caption{A heterogeneous volume with spectrally varying density over space, rendered with multiple-scattering. Smoke data generated using Wenzel Jakob's \\href{http://www.mitsuba-renderer.org/misc.html}{fsolver}.}\n    \\label{fig:gallery}\n\\end{figure}\n\nIn this homework, we will build a volumetric path tracers that can handle scattering and absorption inside participating media inside lajolla. We will split the development into 6 steps and build 6 volumetric path tracers, each has more features than the previous ones.\\footnote{This approach is inspired by Steve Marschner's \\href{https://www.cs.cornell.edu/courses/cs6630/2015fa/notes/10volpath.pdf}{course note} on volumetric path tracing.} Your $n$-th volumetric path tracer should be able to render all scenes the $(n-1)$-th one can handle. If you want, you can only submit the final volumetric path tracer and let all the rest call the final code. This process is for helping you to slowly and steadily build up your rendering algorithm.\n\nParticipating media are volumes with many infinitesimal particles absorbing and scattering lights. Given a ray inside the volume parametrized by distance $\\mathbf{p}(t)$, the radiance along the ray is modelled by the \\emph{radiative transfer equation}:\n\\begin{equation}\n\\frac{\\mathrm{d}}{\\mathrm{d}t} L(\\mathbf{p}(t), \\omega) = -(\\sigma_a(\\mathbf{p}(t)) + \\sigma_s(\\mathbf{p}(t))) L(\\mathbf{p}(t), \\omega) + \\sigma_a L_e(\\mathbf{p}(t), \\omega) + \\sigma_s(\\mathbf{p}(t)) \\int_{S^2} \\rho(\\mathbf{p}(t), \\omega, \\omega') L(\\mathbf{p}(t), \\omega') \\mathrm{d}\\omega',\n\\label{eq:rte}\n\\end{equation}\nwhere $L$ is the radiance, $\\sigma_a$ is the \\emph{absorption coefficient}, $\\sigma_s$ is the \\emph{scattering coefficient}, $L_e$ is the (volumetric) emission, $\\rho$ is the \\emph{phase function} that is skin to BSDF in surface rendering, and $S^2$ is the spherical domain.\n\nThis looks a bit scary, so let's break it down. From now on we'll drop the arguments for $\\sigma_a$ and $\\sigma_s$, but in general they can still be spatially varying. The radiative transfer equation is made of four components: \\textbf{absorption}, \\textbf{emission}, \\textbf{in-scattering}, and \\textbf{out-scattering}. Absorption and emission handles particles that absorb and emit lights:\n\\begin{equation}\n\\frac{\\mathrm{d}}{\\mathrm{d}t} L_a(\\mathbf{p}(t), \\omega) = -\\sigma_a L_a(\\mathbf{p}(t), \\omega) + \\sigma_a L_e(\\mathbf{p}(t), \\omega).\n\\end{equation}\nNotice how this is just a simple linear ordinary differential equation $x' = ax + b$, where $\\sigma_a$ attenuates lights and $L_e$ is the gain.\n\nThe in-scattering accounts for all the lights bounces between the particles along the ray, just like the surface rendering equation:\n\\begin{equation}\n\\frac{\\mathrm{d}}{\\mathrm{d}t} L_{is}(\\mathbf{p}(t), \\omega) = \\sigma_s \\int_{S^2} \\rho(\\mathbf{p}(t), \\omega, \\omega') L(\\mathbf{p}(t), \\omega') \\mathrm{d}\\omega'.\n\\end{equation}\n\nHowever, the light does not just bounce \\emph{into} the ray, it also bounces \\emph{out}. That's what the out-scattering considers:\n\\begin{equation}\n\\frac{\\mathrm{d}}{\\mathrm{d}t} L_{os}(\\mathbf{p}(t), \\omega) = -\\sigma_s L_{os}(\\mathbf{p}(t)).\n\\end{equation}\n\nCombining all these three components, we get the full radiative transfer equation (Equation~\\ref{eq:rte}). Notice that the full radiative transfer equation is also like a linear ODE: $-(\\sigma_a + \\sigma_s) L$ attenuates light, and $L_e$ and the spherical integral are the gain that makes things brighter. For this reason, we often let $\\sigma_t = \\sigma_a + \\sigma_s$ and call it the \\emph{extinction coefficient}.\n\nWe'll start from a very simplified version of the radiative transfer equation, then slowly handle more complex situations. To make things simpler, we will throughout assume our medium does not emit light itself: it will receive lighting from other surfaces in the scene.\n\nBefore that, let's introduce lajolla's data structures for storing the participating media.\n\n\\section{Lajolla's participating media data structures and interfaces}\n\\begin{figure}\n    \\includegraphics[width=\\linewidth]{imgs/media.pdf}\n    \\caption{Lajolla assumes that media are separated by closed surface boundaries. At the object surface, we store the ID of the interior and exterior media (if either of them is vaccum, set the ID to \\lstinline{-1}). The outmost medium is specified at the camera (and can be accessed through \\lstinline{camera.medium_id}). A surface can be \\emph{index-matching} meaning that light just pass through without changing direction or losing energy. In this case, the \\lstinline{material_id} of the surface is set to \\lstinline{-1}. A surface can also be transmissive. In this case, it is assigned a transmissive material like \\lstinline{roughdielectric}.}\n    \\label{fig:data_structure}\n\\end{figure}\n\n\\paragraph{The Medium struct in lajolla.} Lajolla's medium interface is for querying the media parameters $\\sigma_a$, $\\sigma_s$, phase function $\\rho$, and the \\emph{majorant} which is the upper bound of the extinction coefficient $\\sigma_t = \\sigma_a + \\sigma_s$ -- we will need the majorant in our final renderer. \n\\begin{lstlisting}[language=c++]\nstruct MediumBase {\n    PhaseFunction phase_function;\n};\n\nstruct HomogeneousMedium : public MediumBase {\n    Spectrum sigma_a, sigma_s;\n};\n\nstruct HeterogeneousMedium : public MediumBase {\n    VolumeSpectrum albedo, density;\n};\n\nusing Medium = std::variant<HomogeneousMedium, HeterogeneousMedium>;\n\n/// the maximum of sigma_t = sigma_s + sigma_a over the whole space\nSpectrum get_majorant(const Medium &medium, const Ray &ray);\nSpectrum get_sigma_s(const Medium &medium, const Vector3 &p);\nSpectrum get_sigma_a(const Medium &medium, const Vector3 &p);\n\ninline PhaseFunction get_phase_function(const Medium &medium) {\n    return std::visit([&](const auto &m) { return m.phase_function; }, medium);\n}\n\\end{lstlisting}\nYou will need these functions to obtain the necessary quantities in the homeworks.\n\nA \\lstinline{HomogeneousMedium} should be straightforward: it contains constant $\\sigma_a$ and $\\sigma_s$.\nWe will talk more about \\lstinline{HeterogeneousMedium} and \\lstinline{PhaseFunction} later.\n\nLajolla assumes that the media are separated by surface boundaries (Figure~\\ref{fig:data_structure}). It's up to the upstream user to make sure they are consistent to each other and the surfaces are closed (if they are not, the results are undefined).\\footnote{Modern production volume renderers have paid special attention to make sure the renderers can handle all sorts of inputs, including nested volumes. See \\href{here}{https://graphics.pixar.com/library/ProductionVolumeRendering/index.html} for more information.} \n\nIn the scene file, each objects are marked with corresponding exterior and interior media:\n\\begin{lstlisting}[language=xml]\n    <medium type=\"homogeneous\" id=\"medium\">\n        <rgb name=\"sigmaA\" value=\"0.5 0.5 0.5\"/>\n        <rgb name=\"sigmaS\" value=\"0.0 0.0 0.0\"/>\n        <float name=\"scale\" value=\"3\"/>\n    </medium>\n\n    <shape type=\"sphere\">\n        <!-- ...  -->\n        <ref name=\"exterior\" id=\"medium\"/>\n    </shape>\n\n    <sensor type=\"perspective\">\n        <!-- ... -->\n\n        <ref id=\"medium\"/>\n    </sensor>\n\\end{lstlisting}\n\nThe \\lstinline{Medium}s are stored in \\lstinline{scene.media} which you can access through \\lstinline{scene.media[medium_id]}. The \\lstinline{intersection} routine in lajolla returns a \\lstinline{PathVertex} object which contains relevant information of the intersection:\n\\begin{lstlisting}[language=c++]\nstruct PathVertex {\n    Vector3 position;\n    Vector3 geometry_normal;\n    // ...\n    int shape_id = -1;\n    int primitive_id = -1; // For triangle meshes. This indicates which triangle it hits.\n    int material_id = -1;\n\n    // If the path vertex is inside a medium, these two IDs\n    // are the same.\n    int interior_medium_id = -1;\n    int exterior_medium_id = -1;\n};\n\\end{lstlisting}\n\n\\section{Single absorption-only homogeneous volume}\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{imgs/absorption_medium.pdf}\n\\caption{The setup of our first volumetric renderer.}\n\\label{fig:volpath1_illustration}\n\\end{figure}\n\\begin{figure}\n\\caption{Our first volume rendering.}\n\\label{fig:volpath1}\n\\end{figure}\n\nOur first volume renderer will make four assumptions:\n\\begin{itemize}\n    \\item There is only a single, homogeneous ($\\sigma_a$ and $\\sigma_s$ are constants over space) volume.\n    \\item The volume does not scatter light: $\\sigma_s = 0$.\n    \\item The surfaces in the scene only emit lights (with intensity $L_e$) and do not reflect/transmit lights.\n\\end{itemize}\n\nUnder these assumptions, the radiative transfer equation becomes\n\\begin{equation}\n\\frac{\\mathrm{d}}{\\mathrm{d}t} L_a(\\mathbf{p}(t), \\omega) = -\\sigma_a L_a(\\mathbf{p}(t), \\omega),\n\\end{equation}\nand we know $L_a(\\mathbf{p}(t_{\\text{hit}}), \\omega) = L_e$ where $t_{\\text{hit}}$ is the distance between the origin of the ray and the emissive surface. \n\nThis ordinary differential equation has a simple closed form:\n\\begin{equation}\nL_a(\\mathbf{p}(0), \\omega) = \\exp\\left(-\\sigma_a t_{\\text{hit}} \\right) L_e.\n\\end{equation}\nFigure~\\ref{fig:volpath1_illustration} illustrates the setup. In volume rendering the exponential term\n$\\exp\\left(-\\sigma_a t_{\\text{hit}} \\right)$ is often called the ``transmittance''.\n\nOur rendering algorithm is as follows (in Python-style pseudo code).\n\\begin{lstlisting}[language=python]\ndef L(screen_pos):\n  camera_ray = sample_primary(camera, screen_pos)\n  isect = intersect(scene, camera_ray)\n  if isect:\n    transmittance = exp(-sigma_a * t)\n    Le = 0\n    if is_light(isect):\n      Le = isect.Le\n    return transmittance * Le\n  return 0\n\\end{lstlisting}\n\n\\paragraph{Task (15\\%).} You will implement the algorithm above in the \\lstinline{vol_path_tracing_1} function in \\lstinline{vol_path_tracing.h}. You might want to first look at the surface path tracing code in \\lstinline{path_tracing.h} to understand lajolla's API better. \n\n\\end{document}", "meta": {"hexsha": "9e59faa0182dc26362cb2687a8846e67468bd4d5", "size": 10111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/homework2.tex", "max_stars_repo_name": "ken2576/lajolla_public", "max_stars_repo_head_hexsha": "332df50f5979afb2c9ccf9455d0f5e094a1f5a1d", "max_stars_repo_licenses": ["MIT"], "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/homework2.tex", "max_issues_repo_name": "ken2576/lajolla_public", "max_issues_repo_head_hexsha": "332df50f5979afb2c9ccf9455d0f5e094a1f5a1d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "handouts/homework2.tex", "max_forks_repo_name": "ken2576/lajolla_public", "max_forks_repo_head_hexsha": "332df50f5979afb2c9ccf9455d0f5e094a1f5a1d", "max_forks_repo_licenses": ["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.5449101796, "max_line_length": 743, "alphanum_fraction": 0.7431510236, "num_tokens": 2715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6425851955057205}}
{"text": "\\section{Introduction}\n\nI was lately thinking about fixed points, more or less.\n\nA new version of \n\\href{https://hackage.haskell.org/package/data-fix}{\\texttt{data-fix}}\nwas released recently, and also corresponding version\nof \\href{https://hackage.haskell.org/package/recursion-schemes}{\\texttt{recursion-schemes}}.\n\nAlso I wrote a \\href{https://www.well-typed.com/blog/2020/06/fix-ing-regular-expressions/}{Fix-ing regular expressions} post,\nabout adding fixed points to regular expression.\n\nThis post is another exploration: \\emph{Fixed points of Indexed functors}.\nThis is not novel idea at all,\nbut I'm positively surprised this works out quite nicely in modern GHC Haskell.\nI define a |IxFix| type and illustrate it with three examples.\n\n\\emph{Note:} The\n\\href{https://hackage.haskell.org/package/multirec-0.7.9/docs/Generics-MultiRec-HFix.html}{|HFix| in \\texttt{multirec} package} is the same as |IxFix|\nin this post. I always forget about the existence of \\texttt{multirec}.\n\nIn the following, the \"modern GHC Haskell\" is quite conservative,\nonly eight extensions:\n\n\\begin{code}\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE GADTs #-}\n{-# LANGUAGE PolyKinds #-}\n{-# LANGUAGE RankNTypes #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# LANGUAGE TypeOperators #-}\n\\end{code}\n\nAnd this literate Haskell script is warning free, with \\texttt{-Wall}\n\\begin{code}\n{-# OPTIONS_GHC -Wall #-}\n\\end{code}\n\nOn this trip\n\\begin{code}\nmodule IxFix where\n\\end{code}\n\nwe need a handful of imports\n\n\\begin{code}\n-- Type should be added to Prelude\nimport Data.Kind (Type)\n\n-- Few newtypes\nimport Data.Functor.Identity (Identity (..))\nimport Data.Functor.Compose (Compose (..))\nimport Data.Functor.Const (Const (..))\n\n-- dependently typed programming!\nimport Data.Fin      (Fin)\nimport Data.Type.Nat\nimport Data.Vec.Lazy (Vec (..))\n\n-- magic\nimport Data.Coerce (coerce)\n\\end{code}\n\nBefore we go further, let me remind you about ordinary fixed points,\nas defined in \n\\href{https://hackage.haskell.org/package/data-fix}{\\texttt{data-fix}}\npackage.\n\n\\begin{code}\nnewtype Fix f = Fix { unFix :: f (Fix f) }\n\nfoldFix :: Functor f => (f a -> a) -> Fix f -> a\nfoldFix f = go where go = f . fmap go . unFix\n\\end{code}\n\nUsing |Fix| we can define recursive types using non-recursive \\emph{base functors},\ne.g. for a list we'd have\n\n\\begin{code}\ndata ListF a rec = NilF | ConsF a rec\n\\end{code}\n\nWe then use |foldFix| (or |cata| and other recursion schemes in \\texttt{recursion-schemes}) to \ndecouple \"how we recurse\" and \"what we do at each step\".\nI won't try to convince you why this separation of concerns might be useful.\n\nInstead I continue directly to the topic: define indexed fixed points.\nWhy we need them? Because |Fix| is not powerful enough to allow\nworking with |Vec| or polymorphically recursive types.\n\n\\begin{code}\n-- hello dependently typed world.\ndata Vec (n :: Nat) (a :: Type) where\n    VNil  :: Vec 'Z a\n    (:::) :: a -> Vec n a -> Vec ('S n) a\n\\end{code}\n\n\\section{Fixed points of indexed functors}\n\nBefore talking about fixed points, we need to figure out what\nare indexed functors. Recall a normal functor\nis a thing of kind |Type -> Type|:\n\n\\begin{code}\nclass Functor f where\n    fmap :: (a -> b) -> (f a -> f b)\n\\end{code}\n\nIndexed version is the one with |Type| replaced with |k -> Type|,\nfor some index |k| (it is still a functor, but in different category).\nWe want morphisms to work for all indices,\nand preserve them. Thus we define a commonly used type alias\\footnote{I'm sorry that tilde |~>| and dash |->| arrows look so similar.}\n\\begin{code}\n-- natural, or parametric, transformation\ntype f ~> g = forall (j :: k). f j -> g j\n\\end{code}\nUsing it we can define a |Functor| variant\\footnote{\nNote that |FFunctor| in \\url{https://hackage.haskell.org/package/hkd-0.1/docs/Data-HKD.html} (which is defined with different names in other packages as well)\nis of different kind.\n|IxFunctor| in \\url{https://hackage.haskell.org/package/indexed-0.1.3/docs/Data-Functor-Indexed.html}\nis again different.\nSorry for proliferation of various functors.\nAnd for confusing terminology. \nDominic Orchard et al uses terms graded (|k -> Type|, this post) and parameterised (|k -> k -> Type|, \\texttt{indexed}-package) in \\url{https://arxiv.org/abs/2001.10274v2}.\nThere is no monad-name for \\texttt{hkd}-package variant, as that cannot be made into monad-like thing.\n}:\nit looks almost the same.\n\\begin{code}\nclass IxFunctor (f :: (k -> Type) -> (k -> Type)) where\n    ixmap :: (a ~> b) -> (f a ~> f b)\n\\end{code}\n\nWith |IxFunctor| in our toolbox, we can define an |IxFix|,\nnote how the definition is again almost the same as for unindexed |Fix| and |foldFix|:\n\\begin{code}\nnewtype IxFix f i = IxFix { unIxFix :: f (IxFix f) i }\n\nfoldIxFix :: IxFunctor f => (f g ~> g) -> IxFix f ~> g\nfoldIxFix alg = alg . ixmap (foldIxFix alg) . unIxFix\n\\end{code}\n\nDoes this work?\nI hope that following examples will convince that |IxFix|\nis usable (at least in theory).\n\n\\section{Example: length indexed lists, Vec}\n\nThe go to example of recursion schemes is a folding a list,\nThe go to example of dependent types is length indexed list, often called |Vec|.\nI combine these traditions by defining |Vec| as an indexed fixed point:\n\n\\begin{code}\ndata VecF (a :: Type) rec (n :: Nat) where\n    NilF  ::               VecF a rec 'Z\n    ConsF :: a -> rec n -> VecF a rec ('S n)\n\\end{code}\n\n|VecF| is an |IxFunctor|:\n\n\\begin{code}\ninstance IxFunctor (VecF a) where\n    ixmap _ NilF         = NilF\n    ixmap f (ConsF x xs) = ConsF x (f xs)\n\\end{code}\n\nAnd we can define |Vec| as fixed point of |VecF|, with constructors:\n\n\\begin{code}\ntype Vec' a n = IxFix (VecF a) n\n\nnil :: Vec' a 'Z\nnil = IxFix NilF\n\ncons :: a -> Vec' a n -> Vec' a ('S n)\ncons x xs = IxFix (ConsF x xs)\n\\end{code}\n\nCan we actually use it? Of course!\nLets define concatenation\\footnote{You may wonder why function name is |append|, but operation is concatenation? This is similar to having |plus| for addition.}\n|Vec' a n -> Vec' a m -> Vec' a (Plus n m)|.\nWe cannot use |foldIxFix| directly, as |Plus n m| is not the same\nindex as |n|, so we need to define an auxiliary |newtype|\nto plumb the indices. Another way to think about these kind of |newtype|s,\nis that they work around the lack of type-level anonymous functions in nowadays Haskell.\n\n\\begin{code}\nnewtype Appended m a n =\n    Append { getAppended :: Vec' a m -> Vec' a (Plus n m) }\n\\end{code}\n\n\\begin{code}\nappend :: forall a n m. Vec' a n -> Vec' a m -> Vec' a (Plus n m)\nappend xs ys = getAppended (foldIxFix alg xs) ys where\n    alg :: VecF a (Appended m a) j -> Appended m a j\n    alg NilF          = Append id\n    alg (ConsF x rec) = Append $ \\zs -> cons x (getAppended rec zs)\n\\end{code}\n\nWe can also define a refold function, which doesn't mention\n|IxFix| at all.\n\n\\begin{code}\nixrefold :: IxFunctor f => (f b ~> b) -> (a ~> f a) -> a ~> b\nixrefold f g = f . ixmap (ixrefold f g) . g\n\\end{code}\n\nAnd then, using |ixrefold| we can define concatenation for |Vec| from\n\\href{https://hackage.haskell.org/package/vec}{\\texttt{vec}} package,\nwhich isn't defined using |IxFix|.\nHere we need auxiliary |newtype|s as well.\n\n\\begin{code}\nnewtype Swapped f a b =\n    Swap { getSwapped :: f b a }\nnewtype Appended2 m a n =\n    Append2 { getAppended2  :: Vec m a -> Vec (Plus n m) a }\n\nappend2 :: forall a n m. Vec n a -> Vec m a -> Vec (Plus n m) a\nappend2 xs ys = getAppended2 (ixrefold f g (Swap xs)) ys where\n    -- same as alg in 'append'\n    f :: VecF a (Appended2 m a) j -> Appended2 m a j\n    f NilF          = Append2 id\n    f (ConsF z rec) = Append2 $ \\zs -> z :::  (getAppended2 rec zs)\n\n    -- 'project'\n    g :: Swapped Vec a j -> VecF a (Swapped Vec a) j\n    g (Swap VNil)       = NilF\n    g (Swap (z ::: zs)) = ConsF z (Swap zs)\n\\end{code}\n\nYou may note that one can implement |append| as induction over length,\nthat's how |vec| implements them.\nTheoretically it is not right, and |IxFix| formulation highlights it:\n\n\\begin{code}\nappend3 :: forall a n m. SNatI n\n        => Vec' a n -> Vec' a m -> Vec' a (Plus n m)\nappend3 xs ys = getAppended3 (induction caseZ caseS) xs where\n    caseZ :: Appended3 m a 'Z\n    caseZ = Append3 (\\_ -> ys)\n\n    caseS :: Appended3 m a p -> Appended3 m a ('S p)\n    caseS rec = Append3 $ \\(IxFix (ConsF z zs)) ->\n        cons z (getAppended3 rec zs)\n\n-- Note: this is different than Appended!\nnewtype Appended3 m a n =\n    Append3 { getAppended3 :: Vec' a n -> Vec' a (Plus n m) }\n\\end{code}\n\nHere we \\emph{pattern match} on |IxFix| value.\nIf we want to treat it as least fixed point, the only valid elimination\nis to use |foldIxFix|!\n\nHowever, the induction over length is the right approach if |Vec| is defined\nas a data or type family:\n\n\\begin{code}\ntype family VecFam (a :: Type) (n :: Nat) :: Type where\n    VecFam a 'Z     = ()\n    VecFam a ('S n) = (a, VecFam a n)\n\\end{code}\n\nWhether you want to have data or type-family or GADT depends on the application.\n(Even in Agda or Coq). Family variant doesn't intristically know its length,\nwhich is sometimes a blessing, sometimes a curse.\nFor what it's worth, \\texttt{vec} package provides both variants,\nwith almost the same module interface.\n\n\\section{Example: Polymorphically recursive type}\n\nThe |IxFix| can also be used to define polymorphically recursive types like\n\n\\begin{code}\ndata Nested a = a :<: (Nested [a]) | Epsilon\ninfixr 5 :<:\n\nnested :: Nested Int\nnested = 1 :<: [2,3,4] :<: [[5,6],[7],[8,9]] :<: Epsilon\n\\end{code}\n\nA length function defined over this datatype will be polymorphically recursive,\nas the type of the argument changes from Nested a to Nested [a] in the recursive call:\n\n\\begin{code}\n-- >>> nestedLength nested\n-- 3\nnestedLength :: Nested a -> Int\nnestedLength Epsilon    = 0\nnestedLength (_ :<: xs) = 1 + nestedLength xs\n\\end{code}\n\nWe cannot represent |Nested| as |Fix| of some functor,\nand we can not use \\texttt{recursion-schemes} either.\nHowever, we can redefine |Nested| as indexed fixed point.\n\nAn important observation is that we (often or always?) use polymorphic recursion\nas a solution to the lack indexed types.\nMy favorite example is de Bruijn indices for well-scoped terms.\nCompare\n\\begin{code}\ndata Expr1 a\n    = Var1 a\n    | App1 (Expr1 a) (Expr1 a)\n    | Abs1 (Expr1 (Maybe a))\n\\end{code}\nand\n\\begin{code}\ndata Expr2 a n\n    = Free2 a                -- split free and bound variables\n    | Bound2 (Fin n)\n    | App2 (Expr2 a n) (Expr2 a n)\n    | Abs2 (Expr2 a ('S n))  -- extend bound context by one\n\\end{code}\nWhich one is \\emph{simpler} is a really good discussion,\nbut for another time.\n\nIn |Nested| example the single argument is also used for two\npurposes: the type of an base element (|Int|) and container type\n(starts with |Identity| and increases with extra list layer).\n\nOne approach is just use |Nat| index and have a type family%\n\\footnote{Here one starts to wish that GHC had unsaturated type families, so we wouldn't need to use newtypes...}\n\\begin{code}\ntype family Container (n :: Nat) :: Type -> Type where\n    Container 'Z     = Identity\n    Container ('S n) = Compose [] (Container n)\n\\end{code}\n\nor\n\n\\begin{code}\ndata NestedF a rec f\n    = f a :<<: rec (Compose [] f)\n    | EpsilonF\n\ninstance IxFunctor (NestedF a) where\n    ixmap _ EpsilonF    = EpsilonF\n    ixmap f (x :<<: xs) = x :<<: f xs\n\\end{code}\n\nWe can convert from |Nested a| to |IxFix (NestedF a) Identity| and back.\nWe use |coerce| to help with |newtype| plumbing.\n\n\\begin{code}\nconvert :: Nested a -> IxFix (NestedF a) Identity\nconvert = aux . coerce where\n    aux :: Nested (f a) -> IxFix (NestedF a) f\n    aux Epsilon    = IxFix EpsilonF\n    aux (x :<: xs) = IxFix (x :<<: aux (coerce xs))\n\n-- back left as an exercise\n\\end{code}\n\nAnd then we can write |nestedLength| as a fold.\n\n\\begin{code}\n-- >>> nestedLength2 (convert nested)\n-- 3\nnestedLength2 :: IxFix (NestedF a) f -> Int\nnestedLength2 = getConst . foldIxFix alg where\n    alg :: NestedF a (Const Int) ~> Const Int\n    alg EpsilonF         = Const 0\n    alg (_ :<<: Const n) = Const (n + 1)\n\\end{code}\n\n\\section{Non-example: ListF}\n\nIn the introduction I mentioned an ordinary list, which is a fixed point\n\n\\begin{align*}\n  \\mathsf{List} \\coloneqq \\lambda (A : \\mathsf{Type}).\\; \\mu (r : \\mathsf{Type}).\\; 1 + A \\times r\n\\end{align*}\n\nwhere I use $\\mu (r : X).\\, F\\, r$ notation to represent least fixed points:\n$\\mu (r : X). F\\, r \\cong F\\, (\\mu (r : X). F\\, r)$.\nNote that we first introduce a type parameter $A$ with $\\lambda$, and then make\na fixed point with $\\mu$.\n\nWe can define an ordirinary list using |IxFix|,\nby taking a fixed point of a |Type -> Type| thing,\ni.e. first $\\mu$, and then $\\lambda$.\n\n\\begin{align*}\n  \\mathsf{List}_1 \\coloneqq \\mu (r : \\mathsf{Type} \\to \\mathsf{Type}).\\; \\lambda (A : \\mathsf{Type}).\\; 1 + A \\times r\\,A\n\\end{align*}\n\n\\begin{code}\ndata ListF1 rec a = NilF1 | ConsF1 a (rec a)\ntype List1 = IxFix ListF1\n\nfromList1 :: [a] -> List1 a\nfromList1 []     = IxFix NilF1\nfromList1 (x:xs) = IxFix (ConsF1 x (fromList1 xs))\n\\end{code}\n\nCompare to Agda code:\n\n\\begin{code}\n-- parameter\ndata List (A : Set) : Set where\n    nil  : List A\n    cons : A -> List A -> List A\n\n-- index\ndata List : Set -> Set where\n    nil :  (A : Set) -> List A\n    cons : (A : Set) -> A -> List A -> List A\n\\end{code}\n\nThese types are subtly different.\nSee \\url{https://stackoverflow.com/questions/24600256/difference-between-type-parameters-and-indices}.\n\nThis gives a hint why |Agda| people define |Vec (A : Set) : Nat -> Set|,\ni.e. length as the last parameter: because you have to do that way.\nAnd Haskellers (usually) define as |Vec (n :: Nat) (a :: Type)|,\nbecause then |Vec| can be given |Functor| etc instances.\nIn other words, machinery in both languages forces an order of\nof type arguments.\n\nFinally, we can write parametric version of |List| using\n|IxFix| too. We just use a dummy, boring index.\n\n\\begin{align*}\n  \\mathsf{List}_2 \\coloneqq\n  \\lambda (A : \\mathsf{Type}).\\;\n  \\mu (r : 1 \\to \\mathsf{Type}).\\;\n  \\lambda (x : 1).\\;\n  1 + A \\times r\\,x\n\\end{align*}\n\n\\begin{code}\ndata ListF2 a rec (unused :: ()) = NilF2 | ConsF2 a (rec unused)\ntype List2 a = IxFix (ListF2 a) '()\n\nfromList2 :: [a] -> List2 a\nfromList2 []     = IxFix NilF2\nfromList2 (x:xs) = IxFix (ConsF2 x (fromList2 xs))\n\\end{code}\n\n|IxFix| is more general than |Fix|, but if you don't need\nan extra power, maybe you shouldn't use it.\n\nDo we need something even more powerful than |IxFix|?\nI don't think so. If we need more (dependent) indices, we can pack them all into\na single index by tupling (or $\\sum$-mming) them.\n\n\\section{Conclusion}\n\nWe have seen |IxFix|, fixed point of indexed functor.\nI honestly do not think that you should start looking in your code base whether you can use it.\nI suspect it is more useful as thinking and experimentation tool.\nIt is an interesting gadget.\n", "meta": {"hexsha": "fb510218da4050d2e54396e088736189792770ad", "size": 14789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "posts/2020-08-28-indexed-fixpoint.tex", "max_stars_repo_name": "phadej/gists", "max_stars_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-03-31T19:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-28T16:49:57.000Z", "max_issues_repo_path": "posts/2020-08-28-indexed-fixpoint.tex", "max_issues_repo_name": "phadej/gists", "max_issues_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-19T16:33:09.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T16:33:09.000Z", "max_forks_repo_path": "posts/2020-08-28-indexed-fixpoint.tex", "max_forks_repo_name": "phadej/gists", "max_forks_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-31T07:50:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-19T14:05:45.000Z", "avg_line_length": 32.5032967033, "max_line_length": 172, "alphanum_fraction": 0.6831428765, "num_tokens": 4545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6425851867712261}}
{"text": "\\section{Preliminaries} \n\\label{sec:Prelim} \n\nOur proposal, \\dyntset, relies mainly on three structures, a \\textit{monoid}, a \\textit{set} and a \\textit{finger tree}, which are briefly described in the following subsections. \n\n\\subsection{Monoid}\n\nA \\textit{monoid} is a triple $(S,\\star,e)$, where $S$ is a set, $\\star$ is a binary operation, called $product$ and $e$ is an element of $S$, called $unit$, satisfying the following properties:\n\n\\begin{enumerate}\n\\item $e \\star x = x = x \\star e$, for all $x \\in S$ \n\\item $x \\star (y \\star z) = (x \\star y) \\star z $, for all $x,y,z \\in S$.  \n\\end{enumerate}\n\nThe type class Haskell implementation of a monoid we have:\n%\\begin{verbatim}\n\\begin{lstlisting}[mathescape]\nclass Monoid  a where \n   mempty  :: a\n   mappend :: a $\\to$ a $\\to$ a\n\\end{lstlisting}   \n%\\end{verbatim}\n\nwhere the function \\code{mempty} represents the element $e$ and the function \\code{mappend} represents function $\\star$. Detailed information about monoids within the functional programming can be found in \\cite{Monoids}, and for the Haskell implementation at \\cite{HaskellMonoid}.\n\n\n\\subsection{Set as binary search tree} \n\nA set, as a data structure, is used here for searching purposes, seen as testing membership within a specific set. Also, we look for incorporating elements into a set in order to increase such set for further look ups. This incorporation, comes in two flavours, either as single insertion or as the set-union operation. Finally, the presence of an empty set, a set with no elements at all, is crucial since it is the $unit$ when a set behaves as monoid. Also, an empty set is a starting point when a forest contains no trees.\n\nInternally, a set is implemented as binary search tree, also called BST. A BST is either a \\textit{leaf} (also called a \\code{tip}) or a vertex consisting of a \\textit{value}, a \\textit{left} BST and a \\textit{right} BST. The height of the tree determines the time taken to perform every operation onto it, therefore the shorter the height the better, and this is done throughout a \\textit{balancing scheme}. The study of BSTs is vast and there are several implementation around. In our case, a \\textit{size balanced} and a \\textit{pairing hashed} are used. A detailed comparison and benchmarking is outside the scope of the present work.\n\nThe following is an snippet of \\code{Data.Set} \\footnote{https://hackage.haskell.org/package/containers-0.5.10.2/docs/Data-Set.html}\n%\\begin{verbatim}\n\\begin{lstlisting}\ndata Set a    = Bin Size a (Set a) (Set a)\n              | Tip\n\\end{lstlisting}              \n%\\end{verbatim}\n\nIn Table~\\ref{tab:Setfuncs} we show the set-functions we have incorporated in \\code{dynTsET} from \\code{Data.Set}.\n\\small\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{||l | l | c||} \n \\hline\n Function         & Type                                   & Time complexity            \\\\ \n \\hline\\hline\n \\texttt{empty}   & \\texttt{Set a}                         & $O(1)$                     \\\\ \n \\hline\n \\texttt{insert}  & \\texttt{a $\\to$ Set a $\\to$ Set a}     & $O(\\log n)$                \\\\\n \\hline\n \\texttt{member}  & \\texttt{a $\\to$ Set a $\\to$ Bool}      & $O(\\log n)$                \\\\ \n \\hline\n \\texttt{union}   & \\texttt{Set a $\\to$ Set a $\\to$ Set a} & $O(m(\\log\\frac{n}{m} +1))$ \\\\\n \\hline\n\\end{tabular}\n\\caption{Leijen's implementation of \\code{Data.Set} \\cite{HaskellSet}, based on \\cite{ParallelSets}}\n\\label{tab:Setfuncs} \n\\end{center}\nwhere $n$ and $m$ are the sizes of the largest and smallest sets respectively\n\\end{table}\n\\normalsize\n\nFunctions \\code{empty} and \\code{union} are, in fact, the monoidal functions \\code{mempty} and \\code{mappend} respectively. \n\n\\subsection{Euler-tour tree} \n\\label{sec:ETt}\nDealing with trees of different degree can be complicated. A simple way to handle and represent trees of any degree is by an Euler tour, that is, a sequence as in \\cite{Rand-DynGs-Algos} and \\cite{WerneckR-PhD}. To represent a tree $t$, we replace every edge $\\langle u,v \\rangle$ of $t$ by two arcs $(u,v)$ and $(v,u)$, and add a loop $(v,v)$ to represent each vertex $v$. In this context, a tree $t$ can have at least one, and in general, many Euler tours. The size of an Euler tour \\textit{et} of $t$ is $et(t) = v + 2e $, where $v$ is the number of vertices of $t$ and $e$ its number of edges. We can represent an Euler tour in Haskell simply as a list of pairs, such in \n\n%\\begin{verbatim}\n\\begin{lstlisting}\ndata EulerTour a = [(a,a)] \n\\end{lstlisting}\n%\\end{verbatim}\n\nBy managing the tour with lists, we can perform insertion from the left (head) in $O(1)$ but remaining operations such insertion from the right, access, cutting, appending and inserting might take $O(n)$ per operation.\nOn the other hand, representing tours through finger trees, performance per operation is improved up to $O(\\log n)$ per operation amortised as we explain shortly and in Section~\\ref{sec:TechDes}. \n\nOur representation of $k$-trees through Euler-tour will not close up the tour with the first node as this avoids the uniqueness presence for such a node, as shown in Fig.~\\ref{fig:Euler-tour}.\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.35]{./Images/Euler-tour} \n\\end{center}\n\\caption{The $k$-tree (left) is represented as a sequence of size $v+2e$ (right). Notice we left out the final node-pair to preserve uniqueness}\n\\label{fig:Euler-tour}\n\\end{figure}\n\n\n\\subsection{Finger tree} \n\nWe present Hinze and Paterson's version of finger trees \\madd{(FTs)} \\cite{FTs}. A finger tree is a 2-3-4 tree data structure which is always balanced. The structure is designed to store the elements of a sequence in the terminal nodes or leaves while intermediate nodes are dedicated for monoidal annotations. These annotations help out to achieve a specific task when storing or retrieving values in the leaves or when dealing with the tree itself such concatenation or splitting. One instance is random-access on lists. In order to speed up the time taken by a list for accessing the $n$th element, a finger tree stores the list elements on its leaves and the type \\code{Sum Int} as its monoidal annotation. In this way, we can ask for a specific element provided its index in $O(\\log n)$ rather than $O(n)$ time. This done through monoidal instances for \\code{Sum}. The identity is defined as zero as in \n\\begin{lstlisting}[mathescape]\ninstance Num a $\\Rightarrow$ Monoid (Sum a) where\n        mempty = Sum 0\n\\end{lstlisting}\n\nand the corresponding binary operation on integers which preserves its identity (arithmetic addition),\n\\begin{lstlisting}[mathescape]\ninstance Num a $\\Rightarrow$ Semigroup (Sum a) where\n        (<>) = coerce ((+) :: a $\\to$ a $\\to$ a)\n\\end{lstlisting}\n\n\nThe finger tree data type in Haskell is defined as\n\n\\begin{figure}[H]\n\\begin{lstlisting}\ndata FingerTree v a = Empty\n                    | Single a \n                    | Deep v \n                           Digit a \n                           FingerTree v (Node v a) \n                           Digit a\n\\end{lstlisting}                           \n\\caption{Data type of the finger tree by Hinze and Paterson}\n\\label{fig:FTdatatype}\n\\end{figure}\n\n\\code{Digit} type holds from one up to four elements of type \\code{a}. \\code{Node} type can hold two or three elements of type \\code{a}. The recursive and nested definition of \\code{FingerTree} forces the structure to be balanced by its types, instead of enforcing it by code invariants. In our case, the leaves of a finger tree stores pairs of nodes or vertices representing an Euler tour. To implement \\textit{updates} and \\textit{lookups} efficiently, Hinze and Paterson \\cite{FTs} added a monoidal annotation on the intermediate vertices, the \\code {v} type.\n\nIn Fig.~\\ref{fig:FT-Euler-tour} we can see our example of the Euler-tour sequence in Fig.~\\ref{fig:Euler-tour} managed by the data constructors described above.\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.35]{./Images/FT-Euler-tour} \n\\end{center}\n\\caption{A finger tree (FT) holding the sequence (Euler-tour) that represents the $k$-tree in Fig.\\ref{fig:Euler-tour}}\n\\label{fig:FT-Euler-tour}\n\\end{figure}\n\nSince the backbone of our structure \\dyntset is actually a Hinze's and Paterson finger tree \\cite{FTs}, we show the functions involved in our proposal, those to deal with inserting, cutting, appending and accessing finger trees. There are plenty of additional functions from finger trees we do not cover and that can be reached at \\url{http://hackage.haskell.org/package/fingertree-0.1.4.1/docs/Data-FingerTree.html}.\n\n\\small\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{||l | l | c||} \n \\hline\n Function         & Type                                   & \n      \\begin{tabular}{c} Time complexity \\\\ \n                         (amortised bounds)\n      \\end{tabular} \\\\\n \\hline\\hline\n \\texttt{viewl}   & \n      \\begin{tabular}{l} \\texttt{FingerTree v a}   \\\\ \n                         \\texttt{$\\to$ ViewL (FingerTree v a)  } \n      \\end{tabular}\n                  & $O(1)$ \\\\ \n \\hline\n \\texttt{search}  & \n      \\begin{tabular}{l} \\texttt{(v $\\to$ v $\\to$ Bool)}   \\\\ \n                         \\texttt{$\\to$ FingerTree v a  }   \\\\ \n                         \\texttt{$\\to$ SearchResult v a  } \n      \\end{tabular}\n          & $O(\\log(min(i,n-i)))$  \\\\ \n \\hline\n \\texttt{$\\lhd$} (ins. from left) & \n      \\begin{tabular}{l} \\texttt{a $\\to$ FingerTree v a} \\\\\n                         \\texttt{$\\to$ FingerTree v a} \n      \\end{tabular}\n          & $O(1)$                \\\\\n \\hline\n \\texttt{$\\rhd$} (ins. from right) & \n      \\begin{tabular}{l} \\texttt{FingerTree v a $\\to$ a} \\\\\n                         \\texttt{$\\to$ FingerTree v a} \n      \\end{tabular}\n          & $O(1)$                \\\\\n \\hline\n \\texttt{$\\bowtie$} (concatenation) & \n      \\begin{tabular}{l} \\texttt{FingerTree v a} \\\\\n                         \\texttt{$\\to$ FingerTree v a} \\\\\n                         \\texttt{$\\to$ FingerTree v a} \n      \\end{tabular}\n          & $O(\\log ( min(m,n) ))$         \\\\\n \\hline\n\\end{tabular}\n\\caption{Hinze's and Paterson implementation of \\code{Data.FingerTree} \\cite{FTsURL}, based on \\cite{FTs}}\n\\label{tab:FTfuncs} \n\\end{center}\n\\end{table}\n\\normalsize\n\nwhere $n$ is the size of the largest sequence, $m$ is the size of the smaller sequence (i.e. when concatenating) and $i$ is the index of the element when searching. \n\n\\tcb{SPLIT is not longer used, instead there is SEARCHFT, which aim is the same as SPLIT and hope it will be easier to explain}\n\n\\tcb{Is it the ``best\" part in the document to bring up an explanations or examples or both for amortisation?}", "meta": {"hexsha": "f9b6a5ba93c7390cda6c81895529856fe840b4ab", "size": 10595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pub/Prelim/Prelim.tex", "max_stars_repo_name": "jcsaenzcarrasco/ETdynTs", "max_stars_repo_head_hexsha": "4bf251c1d6a7ac4de916254e7efd2083aa9f9ad8", "max_stars_repo_licenses": ["MIT"], "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/Prelim/Prelim.tex", "max_issues_repo_name": "jcsaenzcarrasco/ETdynTs", "max_issues_repo_head_hexsha": "4bf251c1d6a7ac4de916254e7efd2083aa9f9ad8", "max_issues_repo_licenses": ["MIT"], "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/Prelim/Prelim.tex", "max_forks_repo_name": "jcsaenzcarrasco/ETdynTs", "max_forks_repo_head_hexsha": "4bf251c1d6a7ac4de916254e7efd2083aa9f9ad8", "max_forks_repo_licenses": ["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.3563829787, "max_line_length": 908, "alphanum_fraction": 0.6750353941, "num_tokens": 2958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6425538799346258}}
{"text": "\\chapter{Algorithms for Multi-Dimensional Optimization}\n\\label{sec:algImp}\n\\section{Generalized Pattern Search Methods (Analysis)}\nGeneralized Pattern Search (GPS) algorithms are \nderivative free optimization algorithms for the minimization of\nproblem $\\mathbf P_c$ and $\\mathbf P_{cg}$, defined in~\\eqref{sub:Proc}\nand~\\eqref{sub:Procg}, respectively.\nWe will present the GPS algorithms for the case where \nthe function $f(\\cdot)$ cannot be evaluated exactly,\nbut can be approximated by functions $f^* \\colon \\Re_+^q \\times \\Re^n \\to \\Re$, \nwhere the first argument $\\epsilon \\in \\Re_+^q$ is \nthe precision parameter of PDE, ODE, and algebraic equation solvers.\nObviously, the explanations are similar for problems where\n$f(\\cdot)$ can be evaluated exactly, except that the scheme to\ncontrol $\\epsilon$ is not applicable, and that\nthe approximate functions $f^*(\\epsilon,\\cdot)$ are replaced by $f(\\cdot)$.\\\\\n\nUnder the assumption that the cost function is continuously\ndifferentiable, all the accumulation points constructed by\nthe GPS algorithms are stationary.\\\\\n\nWhat GPS algorithms have in common is that they define the construction\nof a mesh $\\mathbb M_k$ in $\\Re^n$, \nwhich is then explored according to some rules\nthat differ among the various members of the family of GPS algorithms.\nIf no decrease in cost is obtained on mesh points around the current iterate,\nthen the distance between the mesh points is reduced,\nand the process is repeated.\\\\\n\nWe will now explain the framework of GPS algorithms that will be used\nto implement different instances of GPS algorithms in GenOpt.\nThe discussion follows the more detailed description of~\\cite{PolakWetter2003:1}.\\\\\n\\pagebreak\n\n\\subsection{Assumptions}\nWe will assume that $f(\\cdot)$ and its \napproximating functions $\\{ f^*(\\epsilon,\\cdot) \\}_{\\epsilon \\in \\Re_+^q}$ \nhave the following properties.\n\n\\begin{assumption} ~\\\\\n\\\\[-2.5\\baselineskip]\n\\begin{enumerate}\n\\item There exists an error bound function $\\varphi \\colon \\Re_+^q\n  \\to \\Re_+$ such that for any bounded set $\\mathbf S \\subset \\mathbf\n  X$, there exists an $\\epsilon_{\\mathbf S} \\in \\Re_+^q$ and a scalar \n  $K_{\\mathbf S} \\in\n  (0, \\, \\infty)$ such that for all $x \\in \\mathbf S$ and for all\n  $\\epsilon \\in \\Re_+^q$, \nwith $\\epsilon \\le \\epsilon_{\\mathbf S}$,\\footnote{For \n$\\epsilon \\in \\Re_+^q$, by $\\epsilon \\le \n\\epsilon_{\\mathbf S}$, \nwe mean that $0 < \\epsilon^i \\le \\epsilon_{\\mathbf S}^i$, for all \n$i \\in \\{ 1, \\ldots ,q \\}$.}\n  \\begin{equation}\n    | \\, f^*(\\epsilon,x) - f(x) | \\le K_{\\mathbf S} \\, \\varphi(\\epsilon).\n  \\lab{eq:fefPhi}\n  \\end{equation}\nFurthermore, \n\\begin{equation}\n\\lim_{\\| \\epsilon \\| \\to 0} \\varphi(\\epsilon) = 0.\n\\end{equation}\n\\item  The function $f \\colon \\Re^n \\to \\Re$ is once continuously differentiable.\n\\rbox\n\\end{enumerate}\n\\lab{as:FFeps}\n\\end{assumption}\n\n\\begin{remark}~\\\\\n\\\\[-2.5\\baselineskip] {\\em\n\\begin{enumerate}\n\\item\nThe functions $\\{ f^*(\\epsilon,\\cdot) \\}_{\\epsilon \\in \\Re_+^q}$ may be\ndiscontinuous.\n\\item\nSee~\\cite{PolakWetter2003:1} for the situation where $f(\\cdot)$ is\nonly locally Lipschitz continuous.\n\\rbox\n\\end{enumerate}\n}\n\\end{remark}\n\n%--------------------------------------------\nNext, we state an assumption on the level sets of the family of\napproximate functions. To do so, we first define the notion of a level \nset.\n\n\\begin{definition}[Level Set]\nGiven a function $f \\colon \\Re^n \\to \\Re$ and an $\\alpha \\in\n\\Re$, such that $\\alpha > \\inf_{x \\in \\Re^n} f(x)$, we will say that\nthe set $\\mathbf L_\\alpha (f) \\subset \\Re^n$, defined as\n\\begin{equation}\n  \\mathbf L_\\alpha(f) \\triangleq \\{ x \\in \\Re^n \\ | \\  f(x) \\le \\alpha \\}, \n\\end{equation}\n is a {\\em level set} of $f(\\cdot)$, parametrized by $\\alpha$.\n\\rbox\n\\end{definition}\n\n\\begin{assumption}[Compactness of Level Sets]\nLet $\\{ f^*(\\epsilon,\\cdot) \\}_{\\epsilon \\in \\Re_+^q}$ be as in \nAssumption~\\ref{as:FFeps} and let $\\mathbf X \\subset \\Re^n$ be the \nconstraint set. Let $x_0 \\in \\mathbf X$ be the \ninitial iterate and $\\epsilon_0 \\in \\Re_+^q$ be the\ninitial precision setting of the numerical solvers.\nThen, we assume that there exists a\ncompact set $\\mathbf C \\subset \\Re^n$ such that\n\\begin{equation}\n  \\mathbf L_{f^*(\\epsilon_0,x_0)} (f^*(\\epsilon,\\cdot)) \\cap \\mathbf X\n  \\subset \\mathbf C, \\qquad \\forall \\, \\epsilon \\le \\epsilon_0.\n\\end{equation}\n\\rbox\n\\lab{as:LevSetBou}\n\\end{assumption}\n\n% ===============================================\n\\subsection{Characterization of GPS Algorithms}\nThere exist different geometrical explanations for pattern search algorithms, and \na generalization is given in the review~\\cite{KoldaLewisTorczon2003:1}.\nWe will use a simple implementation of the pattern search algorithms\nin~\\cite{PolakWetter2003:1} where we restrict the search directions to\nbe the positive and negative coordinate directions.\nThus, the search directions are the columns of the matrix\n\\begin{equation}\n  D \\triangleq [-e_1, \\, +e_1, \\, \\ldots \\, , -e_n, \\, +e_n] \n  \\in \\mathbb Z^{n \\times 2n},\n\\end{equation}\nwhich suffices for box-constrained problems. Furthermore, we\nconstruct the sequence of mesh size parameters that parametrizes\nthe minimum distance between iterates\nsuch that it satisfies the following assumption.\n\\begin{subequations}\n\\begin{assumption}[$k$-th Mesh Size Parameter]\nLet $r, s_0, k \\in \\mathbb N$, with $r > 1$,\nand $\\{ t_i \\}_{i=0}^{k-1} \\subset \\mathbb N$.\nWe will assume that the sequence of mesh size parameters satisfies\n\\begin{equation}\n\\Delta_k \\triangleq \\frac {1}{r^{s_k}},\n\\label{eq:GPSDelDef}\n\\end{equation}\nwhere for $k > 0$\n\\begin{equation}\ns_k \\triangleq s_0 + \\sum_{i=0}^{k-1} t_i.\n\\label{eq:GPSDelDefSk}\n\\end{equation}\n\\lab{ass:MeshSizePara}\n\\rbox\n\\end{assumption}\n\\end{subequations}\nWith this construction, all iterates lie on a rational mesh of the form\n\\begin{equation}\n  \\mathbb M_k \\triangleq \\{ x_0 + \\Delta_k \\, D \\, m \\ | \\ m \\in \\mathbb N^{2 n} \\}.\n\\lab{eq:Mesh} \n\\end{equation}\n\n\n% -------- Global and Local Search Set ---------\nWe will now characterize the set-valued maps that determine the mesh\npoints for the ``global'' and ``local'' searches.  Note that the images\nof these maps may depend on the entire history of the computation.\n\n\\begin{subequations}\n\\begin{definition}\nLet $\\underline{\\mathbf X}_k \\subset \\Re^n$ and\n$\\underline {\\boldsymbol \\Delta}_k \\subset \\mathbb Q_+$\nbe the sets of all sequences containing $k+1$ elements, \nlet $\\mathbb M_k$ be the current mesh,\nand let $\\epsilon \\in \\Re_+^q$ be the solver tolerance.\n\\begin{enumerate}\n\\item\nWe define the {\\em global search set map} \nto be any set-valued map\n\\begin{equation}\n  \\gamma_k \\colon \\underline{\\mathbf X}_k \\times \\underline\n  {\\boldsymbol \\Delta}_k  \\times \\Re_+^q \\to \n  \\bigl( 2^{\\mathbb M_k} \\cap \\mathbf X \\bigr) \\cup \\emptyset\n\\end{equation}\nwhose image \n$\\gamma_k(\\underline x_k, \\underline \\Delta_k, \\epsilon)$\ncontains only a finite number of mesh points.\n\\item\nWe will call $\\mathcal G_k \\triangleq \n\\gamma_k (\\underline x_k, \\underline \\Delta_k, \\epsilon)$ \nthe {\\em global search set}.\n\\item\nWe define the directions for the local search as\n\\begin{equation}\n D \\triangleq  [-e_1, \\, +e_1, \\, \\ldots \\, , -e_n, \\, +e_n].  \n\\end{equation}\n\\item\nWe will call\n\\begin{equation}\n  \\mathcal L_k \\triangleq \\bigl \\{ x_k + \\Delta_k \\, D \\, e_i \\ | \\ \n  i \\in \\{ 1, \\ldots , \\, 2 \\, n \\} \\bigr \\}\n  \\cap \\mathbf X\n\\lab{eq:defLK}\n\\end{equation}\nthe {\\em local search set}.\n\\rbox\n\\end{enumerate}\n\\lab{def:algFunGamDel}\n\\end{definition}\n\\lab{sub:mapfp}\n\\end{subequations}\n\n\\vspace{-\\baselineskip}\n\\begin{remark}~\\\\\n\\\\[-2.5\\baselineskip] {\\em\n\\begin{enumerate}\n\\item\nThe map $\\gamma_k(\\cdot, \\cdot, \\cdot)$ \ncan be dynamic in the sense that if $\\{ x_{k_i} \\}_{i=0}^I \\triangleq \n\\gamma_k(\\underline x_k, \\underline \\Delta_k, \\epsilon)$, \nthen the rule for selecting\n$x_{k_{\\widehat i}}$, $1 \\le \\widehat i \\le I$, can depend on \n$\\{ x_{k_i} \\}_{i=0}^{\\widehat i - 1}$ and\n$\\{ f^*(\\epsilon, x_{k_i}) \\}_{i=0}^{\\widehat i - 1}$. \nIt is only important that the global search terminates after \na finite number of computations, and that  \n$\\mathcal G_k \\subset (2^{\\mathbb M_k} \\cap \\mathbf X) \\cup \\emptyset$.\n\\item\nAs we shall see, the global search affects only the efficiency of the\nalgorithm but not its convergence properties. Any heuristic procedure\nthat leads to a finite number of function evaluations can be used\nfor $\\gamma_k(\\cdot, \\cdot, \\cdot)$. \n\\item\nThe empty set is included in the range of $\\gamma_k(\\cdot, \\cdot, \\cdot)$ \nto allow omitting the global search.\n\\end{enumerate}\n\\rbox\n}\n\\end{remark}\n\n% ===========================================\n\\subsection{Model Adaptive Precision GPS Algorithm}\nWe will now present our model GPS algorithm\nwith adaptive precision cost function evaluations.\\\\\n\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{algorithm}\n[Model GPS Algorithm]\n~\\\\\n{\\em\n\\begin{tabular}{ll}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n \\textbf{Data}:\n     & Initial iterate $x_0 \\in \\mathbf X$;\\\\ \n     & Mesh size divider $r \\in \\mathbb N$, with $r > 1$;\\\\\n     & Initial mesh size exponent $s_0 \\in \\mathbb N$.\\\\\n \\textbf{Maps}:\n     & Global search set map \n       $\\gamma_k \\colon \\underline{\\mathbf X_k} \n       \\times \\underline\n       {\\boldsymbol \\Delta}_k  \\times \\Re_+^q \\to \\bigl( \n       2^{\\mathbb M_k} \\cap \\mathbf X \\bigr) \\cup \\emptyset$; \\\\ \n     & Function $\\rho \\colon \\Re_+ \\to \\Re_+^q$ (to assign $\\epsilon$),\n       such that the composition \\\\\n     & $\\varphi \\circ \\rho \\colon \\Re_+ \\to \\Re_+$\n       is strictly monotone decreasing and satisfies\\\\\n     & $\\varphi(\\rho(\\Delta))/\\Delta \\to 0$, as $\\Delta \\to 0$.\\\\\n  \\textbf{Step 0}: \n     & Initialize $k=0$, $\\Delta_0 = 1 / r^{s_0}$, and $\\epsilon=\\rho(1)$.\\\\\n  \\textbf{Step 1}:\n     & \\underline{Global Search}\\\\\n     & Construct the global search set\n       $\\mathcal G_k = \\gamma_k(\\underline x_k, \\underline \\Delta_k,\n        \\epsilon)$.\\\\\n     & If $f^*(\\epsilon, x') - f^*(\\epsilon, x_k) < 0$\n       for any $x' \\in \\mathcal G_k$, go to Step 3;\\\\\n       & else, go to Step 2.\\\\\n  \\textbf{Step 2}:\n     & \\underline{Local Search}\\\\\n     & Evaluate $f^*(\\epsilon, \\cdot)$ for any $x' \\in \\mathcal L_k$ until\n       some $x' \\in \\mathcal L_k$\\\\\n     & satisfying \n       $f^*(\\epsilon, x') - f^*(\\epsilon, x_k) < 0$\n       is obtained, \n       or until all points\\\\\n     & in $\\mathcal L_k$ are evaluated.\\\\\n  \\textbf{Step 3}:\n     & \\underline{Parameter Update}\\\\\n     & If there exists an $x' \\in \\mathcal G_k \\cup \\mathcal L_k$\n       satisfying\n       $f^*(\\epsilon, x') - f^*(\\epsilon, x_k) < 0$,\\\\\n     & set  $x_{k+1} = x'$, $s_{k+1}= s_k$, $\\Delta_{k+1} = \\Delta_k$,\n       and do not change $\\epsilon$;\\\\\n     & else, set $x_{k+1} = x_k$, $s_{k+1} = s_k + t_k$, with $t_k \\in\n       \\mathbb N_+$ arbitrary,\\\\\n     & $\\Delta_{k+1} = 1/r^{s_{k+1}}$, \n       $\\epsilon = \\rho(\\Delta_{k+1} / \\Delta_0)$.\\\\\n  \\textbf{Step 4}:\n     & Replace $k$ by $k + 1$, and go to Step 1.\\\\\n    \\hline \\\\\n\\end{tabular}\n}\n~\\\\ \\label{al:GPSImp}\n\\end{algorithm}\n\\end{minipage}\n% ===========================================\n\\newpage\n\\begin{remark}~\\newline \n\\vspace{-1.5\\baselineskip}\n{ \\em \n\\begin{enumerate} \n\\item\nTo ensure that $\\epsilon$ does not depend on the scaling of $\\Delta_0$,\nwe normalized the argument of $\\rho(\\cdot)$.\nIn particular, we want to decouple $\\epsilon$ from\nthe user's choice of the initial mesh parameter.\n\\item\nIn Step 2, once a decrease of the cost function is obtained, one\ncan proceed to Step 3. However, one is allowed to evaluate $f^*(\\epsilon,\\cdot)$\nat more points in $\\mathcal L_k$ in an\nattempt to obtain a bigger reduction in cost.  However,\none is allowed to proceed to Step 3 only after \neither a cost decrease has been found, or after {\\em all} points in \n$\\mathcal L_k$ are tested.\n\\item\nIn Step 3, we are not restricted to accepting the\n$x' \\in \\mathcal G_k \\cup \\mathcal L_k$ that gives lowest cost value.\nBut the mesh size parameter $\\Delta_k$ is reduced {\\em only}\nif there exists no $x' \\in \\mathcal G_k \\cup \\mathcal L_k$ satisfying\n$f^*(\\epsilon, x') - f^*(\\epsilon, x_k) < 0$.\n\\item\nTo simplify the explanations, we do\nnot increase the mesh size parameter if the cost has been reduced.\nHowever, our global search allows searching on a coarser mesh \n$\\widehat {\\mathbb M} \\subset \\mathbb M_k$,\nand hence, our algorithm can easily be extended to include a rule for increasing\n$\\Delta_k$ for a finite number of iterations.\n\\item\nAudet and Dennis~\\cite{AudetDennis2003} update the mesh size parameter \nusing the formula $\\Delta_{k+1} = \\tau^m \\, \\Delta_k$, \nwhere $\\tau \\in \\mathbb Q$, $\\tau > 1$, and $m$ is any\nelement of $\\mathbb Z$. Thus, our update rule for $\\Delta_k$ is a special case of\nAudet's and Dennis' construction since we set $\\tau = 1/r$, with\n$r \\in \\mathbb N_+$, $r \\ge 2$ (so that $\\tau < 1$) and $m \\in \n\\mathbb N$. We prefer our construction because we do not think it negatively affects\nthe computing performance, but it leads to simpler convergence proofs.\n\\rbox\n\\end{enumerate}\n}\n\\end{remark}\n\n% ===========================================\n\\subsection{Convergence Results}\nWe will now present the convergence results for our Model GPS algorithm.\nSee~\\cite{PolakWetter2003:1} for a detailed discussion and convergence proofs.\n\n\\subsubsection{Unconstrained Minimization}\n\nWe will first present the convergence properties of the Model GPS\nAlgorithm~\\ref{al:GPSImp} on unconstrained minimization problems, i.e., for \n$\\mathbf X = \\Re^n$.\\\\\n\nFirst, we will need the notion of a {\\em refining subsequence},\nwhich we define as follows:\n\\begin{definition}[Refining Subsequence]\nConsider a sequence $\\{x_k\\}_{k=0}^\\infty$ constructed by Model GPS\nAlgorithm~\\ref{al:GPSImp}.  We will say that the subsequence $\\{ x_k \\}_{k \\in \n\\mathbf K}$ is the {\\em refining subsequence}, if $\\Delta_{k+1} < \n\\Delta_k$ for all $k \\in \\mathbf K$, and $\\Delta_{k+1} = \\Delta_k$\nfor all $k \\notin \\mathbf K$.\n\\rbox\n\\end{definition}\n\nWe now state that pattern search algorithms with adaptive precision\nfunction evaluations construct sequences with stationary accumulation points.\n\\begin{theorem}[Convergence to a Stationary Point]\nSuppose that Assumptions~\\ref{as:FFeps} and \\ref{as:LevSetBou} are\nsatisfied and that $\\mathbf X = \\Re^n$.\nLet $x^* \\in \\Re^n$ be an accumulation point of the refining \nsubsequence $\\{ x_k \\}_{k \\in \\mathbf K}$, constructed by Model GPS\nAlgorithm~\\ref{al:GPSImp}. Then,\n\\begin{equation}\n  \\nabla f(x^*) = 0.\n\\lab{eq:GradConv}\n\\end{equation}\n\\lab{the:GradConv}\n\\rbox\n\\end{theorem}\n% ===========================================\n\\subsubsection{Box-Constrained Minimization}\nWe now present the convergence results for the box-constrained\nproblem~\\eqref{sub:Proc}.\nSee~\\cite{AudetDennis2003, PolakWetter2003:1, KoldaLewisTorczon2003:1}\nfor the more general case of linearly-constrained problems and for the convergence\nproofs.\\\\\n\nFirst, we introduce the notion of a tangent cone and a normal cone,\nwhich are defined as follows: \n\\begin{definition}[Tangent and Normal Cone] ~\\\\\n\\\\[-2.5\\baselineskip]\n\\begin{enumerate}\n\\item\nLet $\\mathbf X \\subset \\Re^n$. Then, we define the {\\em tangent cone} to\n$\\mathbf X$ at a point $x^* \\in \\mathbf X$ by\n\\begin{subequations}\n  \\begin{equation}\n    \\mathbf T_{\\mathbf X}(x^*) \\triangleq \n    \\overline{ \\{ \\mu \\, (x - x^*) \\ | \\  \\mu \\ge 0, \n      \\, x \\in \\mathbf X \\}}.\n  \\end{equation}\n\\item\nLet $\\mathbf T_{\\mathbf X}(x^*)$ be as above. Then, we define the \n{\\em normal cone} to $\\mathbf X$ at $x^* \\in \\mathbf X$ by\n\\begin{equation}\n      \\mathbf N_{\\mathbf X}(x^*) \\triangleq \\{ v \\in \\Re^n \\ | \\ \n      \\forall \\, t \\in \\mathbf T_{\\mathbf X}(x^*), \\, \\langle v, \\, t\n      \\rangle \\le 0 \\}.\n    \\end{equation}\n\\end{subequations}\n\\rbox\n\\end{enumerate}\n\\end{definition}\n\nWe now state that the accumulation\npoints generated by Model GPS Algorithm~\\ref{al:GPSImp} \nare feasible stationary points of problem~\\eqref{sub:Proc}.\n\\begin{theorem}[Convergence to a Feasible Stationary Point]~\\\\\n\\noindent\nSuppose Assumptions~\\ref{as:FFeps} and \\ref{as:LevSetBou} are\nsatisfied.\nLet $x^* \\in \\mathbf X$ be an accumulation point of a \nrefining subsequence $\\{ x_k \\}_{k \\in \\mathbf K}$ constructed by Model\nGPS Algorithm~\\ref{al:GPSImp} in solving problem~\\eqref{sub:Proc}.\nThen,\n\\begin{subequations}\n \\begin{equation}\n   \\langle \\nabla f(x^*), \\, t \\rangle \\ge 0, \\qquad \\forall \\, t \\in\n   \\mathbf T_{\\mathbf X}(x^*),\n   \\lab{eq:feaPoiConv}\n \\end{equation}\nand\n \\begin{equation}\n   - \\nabla f(x^*) \\in \\mathbf N_{\\mathbf X}(x^*).\n \\end{equation}\n\\end{subequations}\n\\lab{the:feaPoiConv}\n\\end{theorem}\n\n% ===========================================\n\\section{Generalized Pattern Search Methods (Implementations)}\nWe will now present different implementations of the Generalized\nPattern Search (GPS) algorithms.\nThey all use the Model GPS Algorithm~\\ref{al:GPSImp} to solve\nproblem $\\mathbf P_{c}$ defined in~\\eqref{sub:Proc}.\nThe problem $\\mathbf P_{cg}$ defined in~\\eqref{sub:Procg} can be solved\nby using penalty functions as described in Section~\\ref{sec:conDepVarGen}.\\\\\n\nWe will discuss the implementations for the case where\nthe function $f(\\cdot)$ cannot be evaluated exactly,\nbut will be approximated by functions $f^* \\colon \\Re_+^q \\times \\Re^n \n\\to \\Re$, where the first argument $\\epsilon \\in \\Re_+^q$ is \nthe precision parameter of the \nPDE, ODE, and algebraic equation solvers.\nThis includes the case where $\\epsilon$ \nis not varied during the optimization, in which case\nthe explanations are identical, except that the scheme to\ncontrol $\\epsilon$ is not applicable, and that\nthe approximate functions $f^*(\\epsilon,\\cdot)$ are replaced by $f(\\cdot)$.\\\\\n\n\nIf the cost function $f(\\cdot)$ is approximated by\nfunctions $\\{ f^*(\\epsilon,\\cdot)\\}_{\\epsilon \\in \\Re_+^q}$\nwith adaptive precision $\\epsilon$, then\nthe function $\\rho \\colon \\Re_+ \\to \\Re_+^q$ (to assign $\\epsilon$)\ncan be implemented by using GenOpt's pre-processing capability\n(see Section~\\ref{par:posPro}).\\\\\n\n% ===========================================\n\\subsection{Coordinate Search Algorithm}\nWe will now present the implementation of the Coordinate Search \nalgorithm\nwith adaptive precision function evaluations\nusing the Model GPS Algorithm~\\ref{al:GPSImp}.\nTo simplify the implementation, we assign\n$f^*(\\epsilon,x) = \\infty$ for all $x \\not \\in \\mathbf X$ where\n$\\mathbf X$ is defined in~\\eqref{eq:setXPc}.\n\n%-------------------------\n\\subsubsection{Algorithm Parameters}\n\\lab{sec:AlgParCooSea}\nThe search direction matrix is defined as \n\\begin{equation}\n   D \\triangleq [+s^1 \\, e_1, \\, -s^1 \\, e_1, \\ldots , \n\\, +s^n \\, e_n, \\, -s^n \\, e_n]\n\\label{eq:defDMatGPSCooSea}\n\\end{equation}\nwhere $s^i \\in \\Re$, $i \\in \\{1, \\ldots, n \\}$, is a scaling for each parameter\n(specified by GenOpt's parameter \\texttt{Step}).\\\\\n\nThe parameter $r \\in \\Na$, $r>1$, which is used to compute the mesh size parameter\n$\\Delta_k$,\nis defined by the parameter \\texttt{MeshSizeDivider},\nthe initial value for the mesh size exponent $s_0 \\in \\Na$\nis defined by the parameter \\texttt{InitialMeshSizeExponent},\nand the mesh size exponent increment $t_k$ is, for the\niterations that do not reduce the cost,\ndefined by the parameter \\texttt{MeshSizeExponentIncrement}.\n\n%-------------------------\n\\subsubsection{Global Search}\n\\lab{sec:GloSeaCooSea}\n\nIn the Coordinate Search Algorithm, there is no global search.\nThus, $\\mathcal G_k = \\emptyset$ for all $k \\in \\Na$.\n\n%-------------------------\n\\subsubsection{Local Search}\n\\lab{sec:locSeaCooSea}\n\nThe local search set $\\mathcal G_k$ is constructed using the\nset-valued map $E_k \\colon \\Re^n \\times \\mathbb Q_+ \\times \\Re_+^q \\to 2^{\\mathbb M_k}$,\nwhich is defined as follows:\\\\[\\baselineskip]\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{algorithm}\n[Map \n$E_k \\colon \\Re^n \\times \\mathbb Q_+ \\times \\Re_+^q \\rightarrow 2^{\\mathbb M_k}$\nfor ``Coordinate Search'']\n~\\\\\n{\\em\n\\begin{tabular}{ ll }\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n\\textbf{Parameter}:\n    & Search direction matrix $D \n      =  [+s^1 \\, e_1, \\, -s^1 \\, e_1, \\ldots , \n\\, +s^n \\, e_n, \\, -s^n \\, e_n]$.\\\\\n    & Vector $\\mu \\in \\Na^n$.\\\\\n\\textbf{Input}: \n    & Iteration number $k \\in \\Na$.\\\\\n    & Base point $x \\in \\Re^n$.\\\\\n    & Mesh divider $\\Delta_k \\in \\mathbb Q_+$. \\\\\n\\textbf{Output}:\n    & Set of trial points $\\mathcal T$.\\\\\n\\textbf{Step 0}:\n    & Initialize $\\mathcal T = \\emptyset$.\\\\\n    & If $k = 0$, initialize , $\\mu^i=0$ for all $i \\in \\{1, \\ldots, n\\}$.\\\\\n\\textbf{Step 1}:\n    & For $i = 1, \\ldots , n$\\\\\n    & \\hspace{1cm} Set $\\widetilde x = x + \\Delta_k \\, \n      D \\, e_{2 \\, i - 1 + \\mu^i}$ and\n      $\\mathcal T \\leftarrow \\mathcal T \\cup \\{ \\widetilde x \\}$.\\\\\n    & \\hspace{1cm} If $f^*(\\epsilon,\\widetilde x) < f^*(\\epsilon,x)$\\\\\n    & \\hspace{2cm} Set $x = \\widetilde x$.\\\\\n    & \\hspace{1cm} else \\\\\n    & \\hspace{2cm} If $\\mu^i = 0$, set $\\mu^i = 1$, else set $\\mu^i = 0$.\\\\\n    & \\hspace{2cm} Set $\\widetilde x = x + \\Delta_k \\, \n                        D \\, e_{2 \\, i -1 + \\mu_i}$ and\n                   $\\mathcal T \\leftarrow \\mathcal T \\cup \\{\n                   \\widetilde x \\}$.\\\\\n    & \\hspace{2cm} If $f^*(\\epsilon,\\widetilde x) < f^*(\\epsilon,x)$\\\\\n    & \\hspace{3cm} Set $x = \\widetilde x$.\\\\\n    & \\hspace{2cm} else\\\\\n    & \\hspace{3cm} If $\\mu^i = 0$, set $\\mu^i = 1$, else set $\\mu^i = 0$.\\\\\n    & \\hspace{2cm} end if.\\\\\n    & \\hspace{1cm} end if.\\\\  \n    & end for.\\\\\n\\textbf{Step 2}:\n    & Return $\\mathcal T$.\\\\\n    \\hline \\\\\n\\end{tabular}\n}\n\\lab{al:CooSeaLocSea}\n\\end{algorithm}\n\\end{minipage}\nThus, $E_k(x, \\Delta_k, \\epsilon) = \\mathcal T$ for all $k \\in \\Na$.\n\\begin{remark}\n{\\em \nIn Algorithm~\\ref{al:CooSeaLocSea},\nthe vector $\\mu \\in \\Na^n$ contains for\neach coordinate direction an integer $0$ or $1$ that indicates \nwhether a step in the positive or\nin the negative coordinate direction yield a decrease in cost in the previous\niteration. This reduces the number of exploration steps.\n}\n\\rbox\n\\end{remark}\n\n%-------------------------\n\\subsubsection{Parameter Update}\nThe point $x'$ in Step 3 of the GPS Model Algorithm~\\ref{al:GPSImp} \ncorresponds to \n$x' \\triangleq \\arg \\min_{x \\in E_k(x_k, \\Delta_k, \\epsilon)} f^*(\\epsilon,x)$\nin the Coordinate Search algorithm.\n\n%-------------------------\n\\subsubsection{Keywords}\n\\label{sec:GPSCooSeaKeyWor}\nFor the GPS implementation of the Coordinate Search Algorithm, \nthe command file (see page~\\pageref{par:comFil}) must only contain continuous parameters.\\\\\n\nTo invoke the algorithm, \nthe \\texttt{Algorithm} section of the GenOpt command file must have the following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main                      = GPSCoordinateSearch;\n   MeshSizeDivider           = Integer; // 1 <  MeshSizeDivider\n   InitialMeshSizeExponent   = Integer; // 0 <= InitialMeshSizeExponent\n   MeshSizeExponentIncrement = Integer; // 0 <  MeshSizeExponentIncrement\n   NumberOfStepReduction     = Integer; // 0 <  NumberOfStepReduction\n}\n\\end{lstlisting}\nThe entries are defined as follows:\n\\begin{codedescription}\n\\item [Main]\nThe name of the main algorithm.\n\\item [MeshSizeDivider]\nThe value for $r \\in \\Na$, $r>1$, used to compute \n$\\Delta_k \\triangleq  {1} / {r^{s_k}}$ (see equation~\\eqref{eq:GPSDelDef}).\nA common value is $r = 2$.\n\n\\item [InitialMeshSizeExponent]\nThe value for $s_0 \\in \\Na$ in~\\eqref{eq:GPSDelDefSk}.\nA common value is $s_0 = 0$.\n\n\\item [MeshSizeExponentIncrement]\nThe value for $t_i \\in \\Na$ (for the iterations that do not yield\na decrease in cost) in~\\eqref{eq:GPSDelDefSk}.\nA common value is $t_i = 1$.\n\n\\item [NumberOfStepReduction]\nThe maximum number of step reductions before the algorithm stops.\nThus, if we use the notation $m \\triangleq \\text{\\texttt{NumberOfStepReduction}}$, then\nwe have for the last iterations $\\Delta_k = {1} / {r^{s_0 + m\\, t_k}}$.\nA common value is $m = 4$.\n\\end{codedescription}\n\n% ===========================================\n\\subsection{Hooke-Jeeves Algorithm}\n\\lab{sec:GPSHooJeeImp}\nWe will now present the implementation of the Hooke-Jeeves algorithm~\\cite{HookeJee1961}\nwith adaptive precision function evaluations\nusing the Model GPS Algorithm~\\ref{al:GPSImp}.\nThe modifications of Smith~\\cite{Smith1969},\nBell and Pike~\\cite{BellPik1966} and\nDe Vogelaere~\\cite{DeVogelaere1968}\nare implemented in this algorithm.\\\\\n\n \nTo simplify the implementation, we assign\n$f^*(\\epsilon,x) = \\infty$ for all $x \\not \\in \\mathbf X$ where\n$\\mathbf X$ is defined in~\\eqref{eq:setXPc}.\n\n%-------------------------\n\\subsubsection{Algorithm Parameters}\nThe algorithm parameters $D$, $r$, $s_0$, and $t_k$ are defined \nas in the Coordinate Search algorithm \n(see page~\\pageref{sec:AlgParCooSea}).\n\n\n%-------------------------\n\\subsubsection{Map for Exploratory Moves}\nTo facilitate the algorithm explanation, we use\nthe set-valued map \n$E_k \\colon \\Re^n \\times \\mathbb Q_+ \\times \\Re_+^q \\to 2^{\\mathbb M_k}$, \nas defined in Algorithm~\\ref{al:CooSeaLocSea}.\nThe map $E_k(\\cdot,\\cdot,\\cdot)$ defines the\n``exploratory moves'' in~\\cite{HookeJee1961}, and\nwill be used in Section~\\ref{sec:GloSeaSetMapHJ}\nto define the global search set map and,\nunder conditions to be seen in Section~\\ref{sec:locSeaDirMapHJ},\nthe local search direction map as well.\\\\\n%-------------------------\n%-------------------------\n\\subsubsection{Global Search Set Map}\n\\lab{sec:GloSeaSetMapHJ}\n\nThe global search set map\n$\\gamma_k(\\cdot, \\cdot, \\cdot)$ is defined as follows. Because\n$\\gamma_0(\\cdot, \\cdot, \\cdot)$ depends on $x_{-1}$, we need to introduce\n$x_{-1}$, which we define as $x_{-1} \\triangleq x_0$.\\\\\n\n\\noindent\n\\begin{minipage}{\\textwidth}\n\\begin{algorithm}\n[Global Search Set Map $\\gamma_k \\colon \\underline{\\mathbf X}_k \n\\times \\underline {\\boldsymbol \\Delta}_k \\times \\Re_+^q\n\\rightarrow 2^{\\mathbb M_k} $]\n~\\\\\n{\\em\n\\begin{tabular}{ll}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n\\textbf{Map}:\n    & Map for ``exploratory moves'' \n    $E_k \\colon \\Re^n \\times \\mathbb Q_+ \\times \\Re_+^q \\to 2^{\\mathbb M_k}$.\\\\\n\\textbf{Input}: \n    & Previous and current iterate, $x_{k-1} \\in \\Re^n$ \n      and $x_k \\in \\Re^n$.\\\\\n    & Mesh divider $\\Delta_k \\in \\mathbb Q_+$.\\\\\n    & Solver precision $\\epsilon \\in \\Re_+^q$.\\\\\n\\textbf{Output}:\n    & Global search set $\\mathcal G_k$.\\\\\n\\textbf{Step 1}:\n    & Set $x = x_k + (x_k - x_{k-1})$.\\\\\n\\textbf{Step 2}:\n    & Compute $\\mathcal G_k = E_k(x, \\Delta_k, \\epsilon)$.\\\\\n\\textbf{Step 3}:\n    & If $\\bigl(\\min_{x \\in \\mathcal G_k} \n         f^*(\\epsilon,x)\\bigr) > f^*(\\epsilon,x_k)$\\\\\n    & \\hspace{1cm} Set $\\mathcal G_k \\leftarrow \\mathcal G_k \\cup \n                       E_k(x_k, \\Delta_k, \\epsilon)$.\\\\\n    & end if.\\\\\n\\textbf{Step 4}:\n    & Return $\\mathcal G_k$.\\\\\n    \\hline \\\\\n\\end{tabular}\n}\n\\lab{al:HJGloSeaSetMap}\n\\end{algorithm}\n\\end{minipage}\nThus, $\\gamma_k(\\underline x_k, \\underline \\Delta_k, \\epsilon) = \\mathcal G_k$.\\\\\n\n%-------------------------\n\\subsubsection{Local Search Direction Map}\n\\lab{sec:locSeaDirMapHJ}\nIf the global search, as defined by \nAlgorithm~\\ref{al:HJGloSeaSetMap}, has failed in reducing\n$f^*(\\epsilon,\\cdot)$, then Algorithm~\\ref{al:HJGloSeaSetMap} has\nconstructed a set $\\mathcal G_k$ that contains the set \n$\\{ x_k + \\Delta_k \\, D \\, e_i \\ | \\ i = 1, \\ldots , \\, 2 n \\}$.\nThis is because in the evaluation of\n$E_k(x_k, \\Delta_k, \\epsilon)$, defined in Algorithm~\\ref{al:CooSeaLocSea}, all \n``If $f^*(\\epsilon,\\widetilde x) < f^*(\\epsilon,x)$'' statements yield\n{\\tt false}, and, hence, one has constructed \n$\\{ x_k + \\Delta_k \\, D \\, e_i \\ | \\ i = 1, \\ldots , \\, 2 n\n\\} = E_k(x_k, \\Delta_k, \\epsilon)$.\n\nBecause the columns of \n$D$ span $\\Re^n$ positively, it follows that\nthe search on the set  $\\{ x_k + \\Delta_k \\, D \\, e_i \\ | \\ i = 1, \\ldots , \\, 2 n\n\\}$ is a local search. Hence, the constructed set\n\\begin{equation}\n\\mathcal L_k \\triangleq \\{ x_k + \\Delta_k \\, D \\, e_i \\ | \\\ni = 1, \\ldots , \\, 2 n \\} \\subset \\mathcal G_k\n\\lab{eq:LkHJ}\n\\end{equation}\nis a local search set.\nConsequently, $f^*(\\epsilon,\\cdot)$ has already been evaluated\nat all points of $\\mathcal L_k$ (during the construction of $\\mathcal\nG_k$) and, hence, one does not need to evaluate $f^*(\\epsilon,\\cdot)$ \nagain in a local search.\n\n%-------------------------\n\\subsubsection{Parameter Update}\nThe point $x'$ in Step 3 of the GPS Model Algorithm~\\ref{al:GPSImp} \ncorresponds to $x' \\triangleq \\arg \\min_{x \\in \\mathcal G_k} \nf^*(\\epsilon,x)$ in the Hooke-Jeeves algorithm. (Note that \n$\\mathcal L_k \\subset \\mathcal G_k$ if a local search has been done as\nexplained in the above paragraph.)\n\n%-------------------------\n\\subsubsection{Keywords}\nFor the GPS implementation of the Hooke-Jeeves algorithm, the command file (see page~\\pageref{par:comFil}) must only contain continuous parameters.\\\\\n\nTo invoke the algorithm, \nthe \\texttt{Algorithm} section of the GenOpt command file must have the following form:\n\\label{algSec:GPSHookeJeeves}\n\\begin{lstlisting}\nAlgorithm{\n   Main                      = GPSHookeJeeves;\n   MeshSizeDivider           = Integer;   // bigger than 1\n   InitialMeshSizeExponent   = Integer;   // bigger than or equal to 0\n   MeshSizeExponentIncrement = Integer;   // bigger than 0\n   NumberOfStepReduction     = Integer;   // bigger than 0\n}\n\\end{lstlisting}\nThe entries are the same as for the Coordinate Search algorithm, and explained\non page~\\pageref{sec:GPSCooSeaKeyWor}.\n\n\n% ===========================================\n\\subsection{Multi-Start GPS Algorithms}\n\\lab{sec:GPSMulSta}\nAll GPS algorithms can also be run using multiple initial points.\nUsing multiple initial points increases the chance of finding \nthe global minimum if the cost function has several local minima,\nand furthermore, it decreases the risk of not finding a minimum if the\ncost function is not continuously differentiable, which \nis the case if building simulation programs, such as\nEnergyPlus or TRNSYS, are used to compute the cost function\n(see the discussion in Section~\\ref{sec:proAppCosFun}).\\\\\n\nThe values that are specified\nby GenOpt's parameter \\texttt{Ini} in GenOpt's command file\n(see Section~\\ref{par:comFil}) are used to initialize\nthe first initial point.\nThe other initial points are randomly distributed, with\na uniform distribution,\nbetween the lower\nand upper bounds of the feasible domain. \nThey are, however, set to the mesh $\\mathbb M_0$, defined in~\\eqref{eq:Mesh},\nwhich reduces the number of cost function evaluations if\nthe optimization algorithm converges \nfrom different initial points to the same minimizer.\\\\\n\nIn GenOpt's command file, a lower and an upper bound must be specified\nfor each independent variable\nusing the keywords \\texttt{Min} and \\texttt{Max}.\\\\\n\nTo use the \\texttt{GPSCoordinateSearch} algorithm with multiple\nstarting points,\nthe \\texttt{Algorithm} section of the GenOpt command file \nmust have the following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main                      = GPSCoordinateSearch;\n   MultiStart                = Uniform;\n   Seed                      = Integer;\n   NumberOfInitialPoint      = Integer; // bigger than or equal to 1\n   MeshSizeDivider           = Integer; // 1 <  MeshSizeDivider\n   InitialMeshSizeExponent   = Integer; // 0 <= InitialMeshSizeExponent\n   MeshSizeExponentIncrement = Integer; // 0 <  MeshSizeExponentIncrement\n   NumberOfStepReduction     = Integer; // 0 <  NumberOfStepReduction\n}\n\\end{lstlisting}\nThe entries are defined as follows:\n\\begin{codedescription}\n\\item [Main]\nThe name of the main algorithm.\n\\item [MultiStart]\nKeyword to invoke the multi-start algorithm. \nThe only valid value is \\texttt{Uniform}.\n\\item [Seed]\nThis value is used to initialize the random number generator.\n\\item [NumberOfInitialPoint]\nThe number of initial points.\n\\end{codedescription}\nThe other entries are the same as for the Coordinate Search algorithm, \nand are explained on page~\\pageref{sec:GPSCooSeaKeyWor}.\\\\\n\nTo use the \\texttt{GPSHookeJeeves} algorithm with multiple\nstarting points,\nthe \\texttt{Algorithm} section of the GenOpt command file \nmust have the following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main                      = GPSHookeJeeves;\n   MultiStart                = Uniform;\n   Seed                      = Integer;\n   NumberOfInitialPoint      = Integer; // 0 <  NumberOfInitialPoint\n   MeshSizeDivider           = Integer; // 1 <  MeshSizeDivider\n   InitialMeshSizeExponent   = Integer; // 0 <= InitialMeshSizeExponent\n   MeshSizeExponentIncrement = Integer; // 0 <  MeshSizeExponentIncrement\n   NumberOfStepReduction     = Integer; // 0 <  NumberOfStepReduction\n}\n\\end{lstlisting}\nThe entries are the same as for the\nmulti-start Coordinate Search algorithm above.\n\n% ===============================================\n", "meta": {"hexsha": "2dc163d52ecd102da992a5a9848d5b920e1d2cc0", "size": 32573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/algGPS.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/algGPS.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/algGPS.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": 38.0970760234, "max_line_length": 149, "alphanum_fraction": 0.6734718939, "num_tokens": 10249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6425538710905845}}
{"text": "\\section{Mutual information}\nWe now consider the case where we have a set of images. This can be\nR,G,B color band images, observations of the same area but \nat different times, etc.\nWe are interested in having an entropy measurement \nof such data sets, knowing that the correlation between two images \ncan be relatively high. A 3-dimensional wavelet transform is not \nappropriate because the third dimension is generally completely different\nfrom the two first. The standard case is the data set where we have \n2-dimensional spatial information versus a frequency band.\n\n\\subsection{Principal component analysis}\nPrincipal Component Analysis (PCA), also often referred as eigenvector,\nHotelling, \nor Karhunen-Lo\\`eve transform \n\\cite{ima:karhunen47,ima:loeve48,ima:hotelling33},\nallows us to transform  discrete signals into a sequence of uncorrelated \ncoefficients. Considering a population $D(1..M,1..N)$ \nof $M$ signals or images of dimension $N$,\nthe PCA method consists of expressing the dataset $D$ by:\n\\begin{eqnarray}\nD = U \\Lambda^{\\frac{1}{2}} V^t\n\\end{eqnarray}\nand\n\\begin{eqnarray}\nDD^t & = & U \\Lambda U^t \\\\\nD^t D & = & V \\Lambda V^t\n\\end{eqnarray}\nwhere $\\Lambda$ is the diagonal matrix of eigenvalues of the covariance \nmatrix $C = DD^t$, the columns of $U$ are the eigenvectors of $C$, and \nthe columns of $U$ are the eigenvector of $D^t D$. \n\nFor a signal $d(1..N)$ we have,\n\\begin{eqnarray}\nd = \\sum_{i=1}^{M} \\sqrt{\\lambda_i} u_i v_i^t\n\\end{eqnarray}\nwhere $\\lambda_i$ are the eigenvalues of the covariance matrix. The $v_i$\nvectors can also be calculated by \\cite{ima:bijaoui79}:\n\\begin{eqnarray}\n V(i,j) = v_i(j) = \\frac{1}{\\sqrt{\\lambda_i}} \\sum_k D(i,k) u_i(j)\n\\end{eqnarray}\n\nIn practice, we construct the matrix $A$ whose rows are formed \nfrom the eigenvectors\nof $C$ \\cite{ima:gonzalez93}, ordered following the \nmonotonic decreasing order of eigenvalues. A vector $x(1..M)$ can then be\ntransformed by:\n\\begin{eqnarray}\ny = \\Lambda^{-\\frac{1}{2}}A(x-m_x)\n\\end{eqnarray}\nwhere $m_x$ is the mean value of $x$.\nBecause the rows of $A$ are orthonormal vectors, $A^{-1} = A^t$, and\nany vector $x$ can be recovered from its corresponding $y$ by:\n\\begin{eqnarray}\nx = \\Lambda^{\\frac{1}{2}}A^t y + m_x\n\\end{eqnarray}\n\nThe $\\Lambda$ matrix multiplication can be seen as a normalization.\nBuilding $A$ from the correlation matrix instead of the covariance matrix\nleads to another kind of normalization, \nand the $\\Lambda$ matrix can be suppressed \n($y = A(x-m_x)$ and $x = A^t y + m_x$). Then the norm of $y$ will be equal to the\nnorm of $x$.  \n\n\\subsection{The WT-PCA transform}\n\nWe consider now that we have $M$ observations of the same view, but\nat different wavelengths (or at different epochs, etc.), and denote \nas $D_k$ one \nobservation, and $W(k, 1..P)$ its wavelet transform, $P$ being the\nnumber of scales (or bands) of the wavelet transform. Then for a given\nfrequency band $j$, we can compare the information content for all observations.\nAs a strong correlation may exist between the same frequency band of two \ndifferent observations, we can appy a principal component analysis for\nthe specific scale $j$, and repeat the same information for all $j$. Then,\nfor each scale $j$, we build a correlation matrix $C_j$ (and also $A_j$), \nand the wavelet coefficients are transformed into their principal \ncomponents. As the obtained coefficients are obtained by applying\nsuccessively a wavelet transform and a principal component analysis,\nwe will term these two transformations a WT-PCA transform,\nand the values obtained will be called WT-PCA coefficients.\n\nThe advantages of the WT-PCA transform are:\n\\begin{itemize}\n\\item We have separated the information not only spatially as if we had\nused only a wavelet transform, but also on the wavelength axis as if\nhad used directly a PCA on the images.\n\\item We keep the possibility open to estimate the noise level of the  \nWT-PCA coefficients in  the same rigorous way as for a simple wavelet \ntransform.\n\\item We have an exact reconstruction.\n\\end{itemize}\n \n\\subsection{Entropy from the WT-PCA transform}\n\nThe entropy relative to a set of observations $D(1..M)$ can be written by:\n\\begin{eqnarray}\nH(D) = \\sum_{j=1}^{l} \\sum_{e=1}^{M}  \\sum_{k=1}^{N_j} h(c_{j,k,e})\n\\end{eqnarray}\nwhere $l$ is the number of scales used in the wavelet transform\ndecomposition, $M$ the number of observations, $k$ a pixel position,\n $c$ a WT-PCA coefficients, and $e$ denotes the eigenvector number.\n\nThe last scale of the wavelet transform is not used, as previously, so\nthis entropy measurement is background independent, which is really\nimportant because the background can vary from one wavelength to another.\n\n\n", "meta": {"hexsha": "44fe8b4ecd584c0e06786ce36db7c260f7ad1b47", "size": 4673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/infomut.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/infomut.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/infomut.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.871559633, "max_line_length": 81, "alphanum_fraction": 0.7504814894, "num_tokens": 1290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6423471146444206}}
{"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 4.} Static games with complete information III: Nash equilibria}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\vspace{-1cm}\n\n\\subsection*{Exercise 1: 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 2: 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\\subsection*{Exercise 3: Cournot Duopoly}\n\nThe Cournot duopoly game is defined by:\n\n\\begin{itemize}\n    \\item Players: \\(N = \\{\\text{Firm } 1, \\text{Firm } 2\\}\\)\n    \\item Actions: Amount of good produced, \\(x^{(i)} \\in [0, \\infty)\\) for \\(i \\in \\{1, 2\\}\\)\n    \\item Payoffs: \\(\\pi^{(i)}(x^{(1)}, x^{(2)}) = [a - b (x^{(1)} + x^{(2)})] x^{(i)} - c x^{(i)}\\)\n\\end{itemize}\n\n\\textbf{Show that there is a Nash equilibrium in pure strategies. For simplicity\nassume \\(a=10, b=1, c=1\\)}.\n\n[Hint: For each \\(x^{(i)}\\) computer BR\\((x^{(-i)})\\). Then solve simultaneously:\n\\begin{align*}\n    x^{(1)}= \\text{BR}(x^{(2)}) \\\\\n    x^{(2)}= \\text{BR}(x^{(1)})\n\\end{align*}\n]\n\n\\subsection*{Exercise 4: Matching Pennies}\n\n\\textbf{Compute the Nash equilibria for the following two games, and interpret the result.}\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & \\text{Left} & \\text{Right} \\\\\n        \\begin{block}{c(cc)}\n            \\text{Top} &    (0.8, 0.4) & (0.4, 0.8) \\\\\n            \\text{Bottom} & (0.4, 0.8) & (0.8, 0.4) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n    %\n    \\begin{blockarray}{ccc}\n        & \\text{Left} & \\text{Right} \\\\\n        \\begin{block}{c(cc)}\n            \\text{Top} &    (3.2, 0.4) & (0.4, 0.8) \\\\\n            \\text{Bottom} & (0.4, 0.8) & (0.8, 0.4) \\\\\n        \\end{block}\n    \\end{blockarray}\n    \\end{equation*}\n\n\\subsection*{Bonus Exercise 1: Verifying NE in games with finitely many players \\& actions}\n\nShow that to verify whether a strategy profile \\(\\hat{\\sigma} =\n(\\hat{\\sigma}^{(1)}, \\dots, \\hat{\\sigma}^{(n)})\\) is a Nash equilibrium, it is\nsufficient to check all deviations towards pure strategies.\n\n\\textbf{Specifically show that \\(\\hat{\\sigma}\\) is a Nash equilibrium if and only if for\nall players \\(i\\) the following two conditions hold:}\n\n\\begin{enumerate}[(i)]\n    \\item All actions that player \\(i\\) uses give the same payoff: if\n    \\(\\sigma^{(i)}_j > 0\\) and \\(\\sigma^{(i)}_k > 0\\) then\n    \\(\\pi^{(i)}(s^{(i)}_j, \\hat{\\sigma}^{(-i)}) = \\pi^{(i)}(s^{(i)}_k,\n    \\hat{\\sigma}^{(-i)})\\).\n    \\item Actions that are not played are not profitable: if \\(\\sigma^{(i)}_j =\n    0\\) then \\(\\pi^{(i)}(s^{(i)}_j, \\hat{\\sigma}^{(-i)}) \\leq\n    \\pi^{(i)}(\\hat{\\sigma}^{(i)}, \\hat{\\sigma}^{(-i)})\\).\n\\end{enumerate}\n\n[Hint: One way to prove the above is once again by contradiction.]\n\n\\subsection*{Bonus Exercise 2: Finding games with a non-generic number of equilibria}\n\n\\textbf{Find an example of a symmetric 2 player game, with 2 actions per player, with:}\n\n\\begin{itemize}\n    \\item Exactly 2 Nash equilibria\n    \\item infinitely many Nash equilibria\n\\end{itemize}\n\n[Note: These should include all Nash equilibria. Not just pure Nash equilibria.]\n\n\\end{document}\n\n", "meta": {"hexsha": "59a7f151a40f11903025a3e9aaf0c0e1e91dabe4", "size": 5063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w4.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/w4.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/w4.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": 35.1597222222, "max_line_length": 100, "alphanum_fraction": 0.6152478768, "num_tokens": 1724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.9184802479302793, "lm_q1q2_score": 0.6422513740203923}}
{"text": "%\n% Chapter 4\n%\n\\chapter {Shor's Semiprime Integer Factorization Algorithm}\n\nShor's algorithm is a polynomial-time quantum algorithm for semiprime integer factorization. In comparison, the time complexity of the most efficient known classical factoring algorithm is superpolynomial.\n\nWe chose Shor's algorithm because it is one of the most significant quantum algorithms, and because the number of qubits and the number of quantum operations required are proportional to the input size. The number of operations is particullarly relevant since it makes the errors introduced by the physical gates an important consideration.\n\n\\section{Algorithm}\n\nThe problem that Shor's algorithm solves is the following: given a semiprime integer \\textit{N}, find its two prime factor \\textit{p} and \\textit{q}.\n\nShor's algorithm combines both classical and quantum computations, and the procedure to perform it is the following:\n\\begin{enumerate}\n    \\item Pick a random integer $1 < a < N$.\n    \\item Check whether $a$ is a factor by determining whether $a$ and $N$ are comprime. If they are, we can compute the factors. Otherwise continue with the rest of the algorithm.\n    \\item Use a period-finding quantum subroutine to find the period $r$ of the function $f(x)=a^{x} \\ mod \\ N$.\n    \\item If $r$ is odd, then go back to step 1. If $r$ is even, go to the next step.\n    \\item If $a^{\\frac{r}{2}} \\equiv -1  \\ mod \\ N$, then go back to step 1.\n    \\item Either $a^{\\frac{r}{2}} - 1$ or $a^{\\frac{r}{2}} + 1$ shares a factor with $N$.\n\\end{enumerate}\n\n\\section{Q\\# Implementation}\n\nIn order to take advantage of the tools built around Q\\#, we use a modified implementation of Shor's algorithm found in Microsoft's quantum samples GitHub repository.\n\n\\todo{Add reference to Microsoft's quantum samples repository.}\n\n\\todo{Breakdown the implementation into different sections and describe each one (similar to what is done in the \"Learn Quantum Computing with Python and Q\\#\" book).}\n\nThe following Q\\# code presents a top-level implementation of Shor's algorithm.\n\n\\begin{lstlisting}[language=C]\n@EntryPoint()\noperation FactorSemiprimeInteger(N : Int) : (Int, Int) {\n\n    // Check the most trivial case where N is pair.\n    if (N % 2 == 0) {\n        return (2, N / 2);\n    }\n\n    mutable factors = (1, 1);\n    mutable foundFactors = false;\n    repeat {\n\n        // Start by guessing a coprime to N.\n        let coprimeGuess = DrawRandomInt(1, N - 1);\n\n        // If the guess number is a coprime, use a quantum algorithm for period finding.\n        // Otherwise, the GCD between N and the coprime guess number is one of the factors.\n        if (IsCoprimeI(N, coprimeGuess)) {\n            let period = EstimatePeriod(N, coprimeGuess);\n            set (foundFactors, factors) = CalculateFactorsFromPeriod(N, coprimeGuess, period);\n        } else {\n            let gcd = GreatestCommonDivisorI(N, coprimeGuess);\n            set (foundFactors, factors) = (true, (gcd, N / gcd));\n        }\n    }\n    until foundFactors\n\n    return factors;\n}\n\\end{lstlisting}\n\n\\section{Quantum Subroutine}\n\n\\todo{Show the circuit representation of the quantum subroutine.}\n\nThe following Q\\# code implements the period finding quantum subroutine:\n\n\\begin{lstlisting}[language=C]\n    @EntryPoint()\n    operation EstimatePeriodInstance(N : Int, a : Int) : (Bool, Int) {\n    \n        // Prepare eigenstate register.\n        let bitSize = BitSizeI(N);\n        use eigenstateRegister = Qubit[bitSize];\n        let eigenstateRegisterLE = LittleEndian(eigenstateRegister);\n        ApplyXorInPlace(1, eigenstateRegisterLE);\n    \n        // Prepare phase register.\n        let bitsPrecision =  2 * bitSize + 1;\n        use phaseRegister = Qubit[bitsPrecision];\n        let phaseRegisterLE = LittleEndian(phaseRegister);\n    \n        // Prepare oracle for quantum phase estimation.\n        let oracle = DiscreteOracle(ApplyOrderFindingOracle(N, a, _, _));\n    \n        // Execute quantum phase estimation.\n        QuantumPhaseEstimation(oracle, eigenstateRegisterLE!, LittleEndianAsBigEndian(phaseRegisterLE));\n    \n        let phaseEstimate = MeasureInteger(phaseRegisterLE);\n    \n        // Reset qubit registers \n        ResetAll(eigenstateRegister);\n    \n        // Return period calculation based on estimated phase.\n        return CalculatePeriodFromPhaseEstimate(N, bitsPrecision, phaseEstimate);\n    }\n\\end{lstlisting}\n", "meta": {"hexsha": "d641a4922a6ff28439cf78faab7ec05552abbfad", "size": 4384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter04.tex", "max_stars_repo_name": "cesarzc/qc-resources-estimation", "max_stars_repo_head_hexsha": "2909d8d51c51e69183622e039af6eaa1ed74d1c0", "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/chapter04.tex", "max_issues_repo_name": "cesarzc/qc-resources-estimation", "max_issues_repo_head_hexsha": "2909d8d51c51e69183622e039af6eaa1ed74d1c0", "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/chapter04.tex", "max_forks_repo_name": "cesarzc/qc-resources-estimation", "max_forks_repo_head_hexsha": "2909d8d51c51e69183622e039af6eaa1ed74d1c0", "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.9803921569, "max_line_length": 340, "alphanum_fraction": 0.7009580292, "num_tokens": 1066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6421531335506958}}
{"text": "\n\n\\section{Preliminaries and exploratory data analysis}\n\nConsider some data from Manly (you will need to get the file from the portal), OR try this with an example from Johnson and Wichern.   A link to their data is given in the portal.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> econ.df <- read.csv(\"econ.csv\", row.names = 1)\n> econ <- econ.df[, -10]\n> econ.cor <- cor(econ)\n> econ.ev <- eigen(econ.cor)\n\\end{Sinput}\n\\end{Schunk}\n\n\\section{PRINCIPAL COMPONENT EXTRACTION}\n\nExtracts loadings, uniqueness and residuals for 4 factors based on principal component extraction.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> loadings4 <- matrix(0, 9, 4)\n> for (i in 1:4) {\n+     loadings4[, i] <- sqrt(econ.ev$values[i]) * econ.ev$vectors[, \n+         i]\n+ }\n> LLt <- loadings4 %*% t(loadings4)\n> unique <- diag(econ.cor - LLt)\n> error <- econ.cor - (LLt + unique)\n\\end{Sinput}\n\\end{Schunk}\n\n\\begin{itemize}\n  \\item Now consider how to amend this code to give you a two or three factor solution.\n\\end{itemize}\n    \n    \n\\subsection{RESULTS FROM PRINCIPAL COMPONENT EXTRACTION}\n\nThe following labels the loadings for ease of use\n\n\\begin{Schunk}\n\\begin{Sinput}\n> row.names(loadings4) <- row.names(econ.cor)\n\\end{Sinput}\n\\end{Schunk}\nThe following gives us the values\n\n\\begin{Schunk}\n\\begin{Sinput}\n> loadings4\n> unique\n> error\n\\end{Sinput}\n\\end{Schunk}\n\nThe following extracts the eigenvalues, and then calculates the proportion and cumulative proportion of variance explained by each component (for 9 variables)\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> econ.ev$values\n> econ.ev$values/0.09\n> cumsum(econ.ev$values/0.09)\n\\end{Sinput}\n\\end{Schunk}\n\nThe following calculates the communalities\n\n\\begin{Schunk}\n\\begin{Sinput}\n> apply(loadings4^2, 1, sum)\n\\end{Sinput}\n\\end{Schunk}\n\nThe following carries out a rotation (you should also consider promax rotation)\n\n\\begin{Schunk}\n\\begin{Sinput}\n> varimax(loadings4)\n\\end{Sinput}\n\\end{Schunk}\n\n\\section{PRINCIPAL FACTORING WITH ITERATION}\n\nThis is rather crude code, but it lets you see what's going on (i.e. try this once and then forget it)\n\nFirstly, an initial estimate of the uniquenesses (can you explain what's going on here?)\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> r2s <- vector(\"numeric\", 9)\n> for (i in 1:9) {\n+     y <- econ[, i]\n+     x <- econ[, -i]\n+     mod <- lm(y ~ as.matrix(x))\n+     r2s[i] <- summary(mod)$r.squared\n+ }\n> unique <- diag(1 - r2s)\n> diag(unique)\n\\end{Sinput}\n\\end{Schunk}\n\n\nThe following step requires to be repeated until the values of the uniquenesses and the loadings converge (10 - 20 runs will do for now).   Type this code in a text editor and paste it all in as one (when you have it working).\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> new <- econ.cor - unique\n> new.ev <- eigen(new)\n> loadings4pf <- matrix(0, 9, 4)\n> for (i in 1:4) {\n+     loadings4pf[, i] <- sqrt(new.ev$values[i]) * new.ev$vectors[, \n+         i]\n+ }\n> LLt <- loadings4pf %*% t(loadings4pf)\n> unique.f <- econ.cor - LLt\n> diag(unique) <- diag(unique.f)\n> diag(unique)\n> loadings4pf\n\\end{Sinput}\n\\end{Schunk}\n\nRepeat that until you get convergence in the loadings estimates.   If\nyou get convergence in the loadings estimates (one of the pitfalls of\nthis technique)\n\n\n\\section{MAXIMUM LIKELIHOOD SOLUTION}\n\nFor our purposes, we will trust R to do the optimisation.  In other\nwords, to carry out the analysis we need one line of code!!!!!!!!!!!!)\n\n\\begin{Schunk}\n\\begin{Sinput}\n> econ.fact <- factanal(econ, factors = 4, rotation = \"none\")\n> econ.fact\n\\end{Sinput}\n\\end{Schunk}\n\nExtract the loadings, calculate the uniquenesses, calculate the residuals\n\n\\begin{Schunk}\n\\begin{Sinput}\n> loadml <- loadings(econ.fact)\n> loadml\n> class(loadml) <- \"matrix\"\n> uniqueml <- econ.fact$uniquenesses\n> resid <- econ.cor - (loadml %*% t(loadml) + diag(uniqueml))\n> resid\n\\end{Sinput}\n\\end{Schunk}\n\nCalculate the communalities\n\n\\begin{Schunk}\n\\begin{Sinput}\n> apply(loadml^2, 1, sum)\n\\end{Sinput}\n\\end{Schunk}\n\n\\section{PLOTTING THE ROTATIONS}\n\nIn case it helps, you could try plotting the rotations (the code here\nillustrates the pcfa method), with numbers\nfor the unrotated loadings and letters for the rotated loadings.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> plot(loadings4[, c(1:2)], pch = as.character(c(1:9)), xlab = expression(paste(gamma, \n+     \"1\")), ylab = expression(paste(gamma, \"2\")), main = \"First and second loadings\", \n+     xlim = c(-1, 1), ylim = c(-1, 1))\n> points(varimax(loadings4)$loadings[, c(1:2)], pch = letters[c(1:9)], \n+     col = \"red\")\n> abline(h = 0)\n> abline(v = 0)\n\\end{Sinput}\n\\end{Schunk}\n\\includegraphics{week11fa-plotloadings}\n\n\n\\begin{itemize}\n\\item Do this for maximum likelihood method\n\\end{itemize}\n\n\n\\begin{itemize}\n  \\item How do you interpret the loadings??????\n    \\end{itemize}\n\n\n\n\n\\section{Summary}\n\n\\fbox{\\parbox[c]{0.9\\textwidth}{\\color{blue}\nWe have left factor analysis until last - you should be very clear that despite some superficial similarities it is a very different technique to p.c.a.   By the end of this week we should:\n\n\\begin{itemize}\n\\item Understand the role of factor analysis as a means of explaining the relationships between variables in a given dataset\n\\item Be able to interpret the results (loadings) of a particular factor analysis, aided or not by rotations\n\\item To explain the difference between p.c.a. based and maximum likelihood based methods of factor analysis\n  \\item To interpret the ``signficance'' of solutions of different size, and to justify the use of a particular size solution in all cases\n \\end{itemize}\n\n\n\n}}\n\n\n\n\n", "meta": {"hexsha": "b9385022f8b65654641d6184e02979d22f995691", "size": 5491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "newworksheet/week11fa.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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": "newworksheet/week11fa.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "newworksheet/week11fa.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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": 25.5395348837, "max_line_length": 226, "alphanum_fraction": 0.7066108177, "num_tokens": 1648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6421531176217297}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 2.13 Inverse Error Function and Inverse \\hbox{Complementary Error Function}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nGiven $x$, this pair of subprograms computes the value $t$ such that%\n\\begin{equation*}\nx=\\text{erf}(t)=\\frac 2{\\sqrt{\\pi }}\\int_0^te^{-s^2}ds\n\\end{equation*}\nfor the Inverse Error Function, or%\n\\begin{equation*}\nx=\\text{erfc}(t)=\\frac 2{\\sqrt{\\pi }}\\int_t^\\infty e^{-s^2}ds\n\\end{equation*}\nfor the Inverse Complementary Error Function.\n\nProcedures in Chapter~15.2 may be used to calculate the inverse of\nthe Gaussian or normal probability integral.\n\nReference \\cite{ams55:erf} provides further discussion of the properties\nof the error function.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf X, SERFI, SERFCI, T}\n\\end{description}\n\nAssign a value to X and use one of the following function references.\n\nTo compute the Inverse Error Function:\n$$\n\\fbox{{\\bf T = SERFI(X)}}\n$$\nTo compute the Inverse Complementary Error Function:\n$$\n\\fbox{{\\bf T = SERFCI(X)}}\n$$\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[X]  \\ [in] Argument of function. Require $-1<\\text{X}<1$ for SERFI, $0<%\n\\text{X}<2$ for SERFCI.\n\\end{description}\n\n\\subsubsection{Modification for Double Precision}\n\nFor double precision usage change the REAL type statement to DOUBLE\nPRECISION and change the function names to DERFI and DERFCI respectively.\n\n\\subsection{Examples and Remarks}\n\nSee DRDERFI and ODDERFI for an example of the usage of these subprograms.\n\n$|\\frac{\\text{d}}{\\text{dx}}\\text{erf}^{-1}(x)|$ and\n$|\\frac{\\text{d}}{\\text{dx}}\\text{erfc}^{-1}(x)|$ are $\\frac{\\sqrt{\\pi}}2\ne^{x^2}$.  Therefore, the relative accuracy to be expected in evaluating\nthese functions decreases rapidly as $x$ increases.  For example, when using\nIEEE single-precision arithmetic, one should expect no more than one digit of\nthe result to be correct when $x > \\approx 3.6$\n\n\\subsection{Functional Description}\n\nThe computer approximations for these functions were developed by A.\nStrecok, \\cite{Strecok:1968:OCI}, using Chebyshev polynomial expansions.\n\nThese subprograms were tested on the IBM PC/AT, which uses IEEE\narithmetic with precision, $\\rho \\approx 1.19 \\times 10^{-7}$ in single precision and\n$\\rho \\approx 2.22 \\times 10^{-16}$ in double precision.  We checked how well the\nError Function subprograms (SERF and SERFC or DERF and DERFC) and the\npresent subprograms are inverses. Two sets of relative error tests were\nperformed:\n\\begin{gather*}\n\\varepsilon _1 = |\\erf(\\erfi(x))/x - 1|\\ /\\ \\rho,\\ \\ \\text{and}\\\\\n\\varepsilon _2 = |\\erfi(\\erf(x))/x - 1|\\ /\\ \\rho\n\\end{gather*}\n\nand similarly for the complementary functions. The latter test does not\nmeasure relative error precisely for the complementary functions, and was\nnot carried out in the range 1.0E$-$35 $\\leq x \\leq $ 1.0E$-$5 (1.0E$-$300 $%\n\\leq x \\leq $ 1.0E$-$5 in double precision). The results are summarized below.\n\n\\begin{tabular}{llll}\n & \\bf Argument & \\bf Max. & \\bf Max.\\\\\n\\bf Function & \\bf \\ \\,Interval & \\bf \\ \\ \\ $\\varepsilon _1$ &\n\\bf \\ \\ \\ $\\varepsilon _2$\\\\\nSERFI & [0.1E$-$2, 0.8] & 0.956 & 0.993\\\\\n & [0.8, 0.9975] & 0.625 & 1.66\\\\\n & [.9975, .99999] & 0.0 & 1.50\\\\\nSERFCI & [1.0E$-$35, 1.0E$-$5] & 113\\\\\n & [1.E$-$5, 2.5E$-$3] & 16.3 & 1.91E+4\\\\\n & [2.5E$-$3, 0.2] & 14.2 & 86.7\\\\\n & [0.2, 0.999] & 2.14 & 1.92\\\\\nDERFI & [0.1E$-$2, 0.8] & 0.896 & 0.973\\\\\n &[0.8, 0.9975] & 0.625 & 1.59\\\\\n &[.9975, .99999] & 0.0 & 1.50\\\\\nDERFCI & [1.0E$-$300, 1.0E$-$5] & 964\\\\\n & [1.E$-$5, 2.5E$-$3] & 13.6 & 1.90E+4\\\\\n &[2.5E$-$3, 0.2] & 8.29 & 64.6\\\\\n &[0.2, 0.999] & 1.69 & 1.60\n\\end{tabular}\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nThese subprograms issue an error message and terminate execution if\n\n\\hspace{.4in}(a) \\ \\ X $\\leq -1$ or X $\\geq 1$ for SERFI, or\n\n\\hspace{.4in}(b) \\ \\ X $\\leq 0$ or X $\\geq 2$ for SERFCI.\n\nThe error message is issued by way of the error message processor at level 0,\nand the returned function value is 0.0.  If it is desired, in the event an error\noccurs, to issue the error message and then terminate program execution\n\n\\hspace{.4in}CALL ERMSET (2)\n\nbefore invoking SERFI or SERFCI.\n\nSee Chapter~19.2 for further description of the error message processor.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nSubprograms designed and developed by W. V. Snyder, JPL, 1986.\n\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDERFCI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERFI, DERM1, DERV1, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\DERFI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERFI, DERM1, DERV1, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\SERFCI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERFI, SERM1, SERV1\\rule[-5pt]{0pt}{8pt}}\\\\SERFI & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERFI, SERM1, SERV1}\\\\\\end{tabular}\n\n\\begcode\n\n\\bigskip\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDERFI}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{derfi}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDERFI}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{derfi}}\n\n\\end{document}\n", "meta": {"hexsha": "21397b171eb7b06c5e40cfa45abd8a306ec1bdc5", "size": 5541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch02-13.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/ch02-13.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/ch02-13.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": 34.4161490683, "max_line_length": 123, "alphanum_fraction": 0.7016783974, "num_tokens": 1982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6420822448221035}}
{"text": "\n\\section{The \\minmaxelement algorithm}\n\\Label{sec:minmaxelement}\n\nThe \\minmaxelement algorithm in the\n\\cxx Standard Library \\cite[\\S 28.7.8]{cxx-17-draft} searches\n\\emph{both} the minimum \\emph{and} the maximum in a sequence.\nThe signature of our version of \\minelement reads:\n\n\\begin{lstlisting}[style = acsl-block]\n\n        size_type_pair minmax_element(const value_type* a, size_type n);\n\\end{lstlisting}\n\nNote that \\minmaxelement returns a \\emph{pair} of indices (see \\S\\ref{sec:makepair}).\nThis pair contains the \\emph{first} position where the minimum occurs in\nthe sequence \\inl{a[0..n-1]} and the \\emph{last} position where maximum occurs.\n\nThe properties of the index for the minimum value are the same as the properties\nof \\specref{minelement}.\nHowever, the properties of the index that marks the maximum\nelement, are slightly different from the properties of \\specref{maxelement}.\nThe \\maxelement algorithm returns the position of the \\emph{first} occurrence of\nthe maximum element if it occurs multiple times in the sequence. The\n\\minmaxelement algorithm returns the position of the last occurrence of the\nmaximum element.\n\n%\\clearpage\n\n\\subsection{Formal specification of \\minmaxelement}\n\nThe following listing shows the acsl specification of \\specref{minmaxelement}.\nNote that we use the predicates \\logicref{StrictLowerBound} and\n\\logicref{StrictUpperBound} in order to express that the algorithm returns\nthe positions of both the \\emph{first minimum} and the \\emph{last maximum}.\nWe also use the predicates \\logicref{MinElement} and \\logicref{MaxElement}.\nThus reflects of course the use of this predicates for the algorithms\n\\specref{minelement} and \\specref{maxelement}.\n\n\\input{Listings/minmax_element.h.tex}\n\n\nThe specification is similar to the specifications of \\minelement and\n\\maxelement. The only difference lies in the postcondition \\inl{last}. Here the\npostcondition states that after the position of the maximum element there is no\nvalue greater or equal the maximum element. This differs from the specification\nof \\maxelement, where the first occurrence of the maximum value has to be\nreturned.\n\n%\\clearpage\n\n\\subsection{Implementation of \\minmaxelement}\n\nThe implementation of \\implref{minmaxelement} uses the auxiliary\nfunction \\specref{makepair} to construct a pair of indices.\nWe will focus on the loop invariant \\inl{last}, because it is the\nonly loop invariant that differs from the implementations of \\implref{minelement} and\n\\implref{maxelement}.\n\n\\input{Listings/minmax_element.c.tex}\n\nAs already mentioned we had to alter the range for the predicate\n\\logicref{StrictUpperBound} to fit into the property of returning\nthe last maximum position that occurred.\n\n", "meta": {"hexsha": "23f9c6d418e25da9134cec6e231d92b1c16903a5", "size": 2698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/maxmin/minmax_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/minmax_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/minmax_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": 40.8787878788, "max_line_length": 85, "alphanum_fraction": 0.7987398073, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721305, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6420822360421787}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{Prove that for a finite topological spaces, discrete is equivalent to Hausdorf}\n\nAssume a finite topological space X is discrete. Then given two points $x_1$ and $x_2$ there are the open sets $\\{x_1\\}$ and $\\{x_2\\}$ that are non-intersecting, thus X is Hausdorf. Note the assumption that the space was finite was not needed.\n\nAssume a finite topological space X is Hausdorf. Pick an arbitrary point $x$. For every $x_i \\in X$ where $1 \\le i \\le n=|X|$, there exists an open set containing $x$ that does not contain $x_i$, call it $U_i$. Take $U=\\bigcap_{i=0}^n U_i$. $U = \\{x\\}$ since it is in every set $U_i$ but every other point in $X$ is not in at least one $U_i$. $U$ is open, since it is the finite intersection of open sets.\n\nSince $x$ was chosen arbitrarily, the singleton set around every point is open. Thus since the union of open sets is open, any subset of $X$ is open, thus $X$ is discrete.\n\n\\end{document}\n", "meta": {"hexsha": "c385f1c2eb0a3ccc880be3572cfbc74472a3f52d", "size": 1012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/8_C_star_Algebras/extra.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/8_C_star_Algebras/extra.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/8_C_star_Algebras/extra.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": 63.25, "max_line_length": 405, "alphanum_fraction": 0.7302371542, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6420822306885893}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 5.3 Eigenvalues of an Unsymmetric Matrix\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nCompute all eigenvalues of a real N $\\times $ N unsymmetric matrix $A$. Some or all\nof the eigenvalues may be complex.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf A}(LDA, $\\geq $ N) \\ [LDA$\\geq $N]{\\bf , VR}($\\geq $ N)%\n{\\bf , VI}($\\geq $N)\n\n\\item[INTEGER]  \\ {\\bf LDA, N, IFLAG}($\\geq $ N)\n\\end{description}\n\nAssign values to A(,), LDA, and N.\n$$\n\\fbox{{\\bf CALL SEVUN(A, LDA, N, VR, VI, IFLAG)}}\n$$\nResults are returned in VR(), VI(), IFLAG(1). The contents of A(,) will be\nmodified.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A(,), LDA, N]  \\ A(,) is [inout], LDA and N are [in]. On entry A(,) must\ncontain the N $\\times $ N matrix $A$ whose eigenvalues are to be computed. The\ninteger LDA is the dimension of the first subscript of the array A(,).\nRequire LDA $\\geq $ N. On return the contents of A(,) will be modified.\n\n\\item[VR(), VI()]  \\ [out] The subroutine will store the $J^{th}$ eigenvalue\nin VR($J$) and VI($J$), $J =1$, ..., N. The real part is stored in\nVR($J$), and\nthe imaginary part in VI($J$). If the $J^{th}$ eigenvalue is real VI($J$) will\nbe zero. The eigenvalues will be sorted so that VR(1) $\\leq $ VR(2) $\\leq $\n... $\\leq $ VR(N), and if VR($J$) = VR($J$+1) for some $J$ then $|$VI$(J)|\n\\leq |$VI$(J+1)|.$\n\nComplex eigenvalues will occur in conjugate pairs. Such pairs will be stored\nin adjacent locations with the eigenvalue having positive imaginary part\npreceding its conjugate partner.\n\n\\item[IFLAG()]  \\ [out, scratch] The N-array IFLAG() will be used as INTEGER\nworking space. In addition, the first location, IFLAG(1), will be used to\npass information back to the user as follows:\n\n\\begin{itemize}\n\\item[= 1]  If successful and all eigenvalues are real.\n\n\\item[= 2]  If successful and some eigenvalues are complex.\n\\end{itemize}\n\nSee Section E for use of IFLAG(1) in error conditions.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SEVUN to DEVUN, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\n{\\bf Example~1:} Define\n\\begin{equation*}\nA=\\left[\n\\begin{array}{rrr}\n-954 & -464 & -2088 \\\\\n792 & 387 & 1728 \\\\\n264 & 128 & 579\n\\end{array}\n\\right] .\n\\end{equation*}\nThe eigenvalues of $A$ are $\\lambda _1 = 3$, $\\lambda _2 = 3$, $\\lambda _3\n= 6$.  This example was constructed by using the matrix called $A^{-1}$ in\nExample~3.1, page~29, of \\cite{Gregory:1969:ACM} as the matrix of\neigenvectors.  It illustrates the case of a double eigenvalue having a\nfull set of eigenvectors.\n\n{\\bf Example~2:} Define\n\\begin{equation*}\nB=\\left[\n\\begin{array}{ccc}\n4 & 1 & 1 \\\\\n2 & 4 & 1 \\\\\n0 & 1 & 4\n\\end{array}\n\\right] .\n\\end{equation*}\nThis is Example~5.2 of page~82 of~\\cite{Gregory:1969:ACM}.  The\neigenvalues are $\\lambda _1 = 3 $, $\\lambda _2 = 3$, and $\\lambda _3 = 6$.\nThe matrix is defective in that there is only a one-dimensional space of\neigenvectors associated with the eigenvalue~3.\n\n{\\bf Example 3:} Define\n\\begin{equation*}\nC=\\left[\n\\begin{array}{rrr}\n8 & -1 & -5 \\\\\n-4 & 4 & -2 \\\\\n18 & -5 & -7\n\\end{array}\n\\right] .\n\\end{equation*}\nThis is Example~5.4 of page~84 of \\cite{Gregory:1969:ACM}.  The\neigenvalues are $\\lambda _1 = 1 $, $\\lambda _2 = 2 + 4i$, and $\\lambda _3\n= 2 - 4i.$\n\nThe demonstration program DRSEVUN below applies SEVUN to compute eigenvalues\nfor the above three matrices. Results are in the file ODSEVUN.\n\n\\subsection{Functional Description}\n\nGiven an N $\\times $ N real unsymmetric matrix $A$ there exists an N $\\times $ N\nnonsingular matrix $C$ such that the matrix\n\\begin{equation*}\nU=C^{-1}AC\n\\end{equation*}\nis N $\\times $ N upper triangular. The matrices $C$ and $U$ may be complex. The\ndiagonal elements of $U$ are called the eigenvalues of $A$. This set of N\nnumbers is uniquely determined by $A$ although $C$ and $U$ are not unique.\nNote that $\\lambda $ is an eigenvalue of $A$ if and only if $A - \\lambda I$\nis singular.\n\nThis subroutine SEVUN was developed using the subroutines BALANC, ELMHES,\nand HQR from the EISPACK package of eigenvalue-eigenvector subroutines,\n\\cite{Smith:1974:MER}. The Fortran subroutines in EISPACK\nare based directly on the earlier set of Algol procedures described in\n\\cite{Wilkinson:1971:HAC}.\n\nSubroutine SEVUN first calls SEVBH which consists of the two EISPACK\nsubroutines, BALANC and ELMHES.\n\nBALANC applies similarity permutations to isolate eigenvalues available by\ninspection, if any. It then applies diagonal similarity scaling to balance\nthe size of the matrix elements%\n\\begin{equation*}\nB=D^{-1}P^TAPD.\n\\end{equation*}\nELMHES reduces $B$ to upper Hessenberg form using stabilized elementary\ntransformations%\n\\begin{equation*}\nH=G^{-1}BG.\n\\end{equation*}\nThe remainder of SEVUN consists of a minor modification of HQR\nwhich applies the QR algorithm to $H$. This is an iterative process that\nreduces $H$ to a real nearly-upper-triangular matrix $R$%\n\\begin{equation*}\nR=Q^THQ.\n\\end{equation*}\nThe matrix $R$ has a mixture of single elements and $2 \\times 2$ blocks on its\ndiagonal and is otherwise upper triangular.\n\nThe eigenvalues of $A$ are the single diagonal elements of $R$ along with the\neigenvalues of the $2 \\times 2$ blocks on the diagonal of $R$. These latter\neigenvalues are computed by direct formulas.\n\nSEVUN reorders the eigenvalues to achieve the ordering described\npreviously in Section~B.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIf N $\\leq 0$ or if there is convergence failure in the QR algorithm the\nerror processing subroutine ERMSG of Chapter 19.2 will be called with an\nerror level 0 to print an error message. Upon return, IFLAG(1) = 3~or~4 to\nindicate N $\\leq  0$ or convergence failure, respectively.\n\nIn these error conditions all computed eigenvalues should be regarded as\ninvalid.\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} \\\\\nDEVUN & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DEVBH, DEVUN, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\\nSEVUN & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SEVBH, SEVUN}\\\\\n\\end{tabular}\n\nThe EISPACK package of Fortran subroutines was acquired at JPL from Argonne\nNational Laboratories where it was developed with financial support from the\nAEC and the NSF. The subroutine SEVUN was written by F. T. Krogh, JPL,\nOctober~1991.\n\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSEVUN}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sevun}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSEVUN}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sevun}}\n\\end{document}\n", "meta": {"hexsha": "5fa4a799b8f9499a875ad6f44e1c7513ff93ffde", "size": 7077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch05-03.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/ch05-03.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/ch05-03.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": 33.3820754717, "max_line_length": 98, "alphanum_fraction": 0.725024728, "num_tokens": 2250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.6420822208685436}}
{"text": "% This is a model template for the solutions in computational science. You can find a very useful documentation for LaTeX in Finnish at ftp://ftp.funet.fi/pub/TeX/CTAN/info/lshort/finnish/ or in English at ftp://ftp.funet.fi/pub/TeX/CTAN/info/lshort/english/. The section List of mathematical symbols in Chapter 3 is especially useful for the typesetting of mathematical formulas.\n\n% Compile the document to PDF by command 'pdflatex model.tex' in the terminal. The command must be run twice for the references in the text to be correct.\n\n\\documentclass[a4paper,11pt]{article}\n\\usepackage[utf8]{inputenc}\n% This includes letters such as � and �\n\\usepackage[T1]{fontenc}\n% Use here 'Finnish' for Finnish hyphenation. You may have to compile the code twice after the change. \n\\usepackage[english]{babel}\n\\usepackage{graphicx}\n% Some math stuff\n\\usepackage{amsmath,amsfonts,amssymb,amsbsy,commath,booktabs,hyperref}  \n% This is just to include the urls\n\\usepackage{hyperref,subcaption}\n\\usepackage[margin=2cm]{geometry}\n\n\\setlength{\\parindent}{0mm}\n\\setlength{\\parskip}{1.0\\baselineskip}\n\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{pdfpages}\n\n\\definecolor{dkgreen}{rgb}{0,0.6,0}\n\\definecolor{gray}{rgb}{0.5,0.5,0.5}\n\\definecolor{mauve}{rgb}{0.58,0,0.82}\n\n\\lstset{frame=tb,\n\tlanguage=Python,\n\taboveskip=3mm,\n\tbelowskip=3mm,\n\tshowstringspaces=false,\n\tcolumns=flexible,\n\tbasicstyle={\\tiny\\ttfamily},\n\tnumbers=none,\n\tnumberstyle=\\tiny\\color{gray},\n\tkeywordstyle=\\color{blue},\n\tcommentstyle=\\color{dkgreen},\n\tstringstyle=\\color{mauve},\n\tbreaklines=true,\n\tbreakatwhitespace=true,\n\ttabsize=4\n}\n\n\\begin{document}\n\n\\title{Becs-114.1100 Computational Science -- exercise round 8} % Replace the exercise round number\n\\author{Kunal Ghosh, 546247} % Replace with your name and student number\n\\maketitle\n\\section{Solution to Question 3}\n\\subsection{Using Box-Muller algorithm}\\label{prob3a}\nIn this exercise we use the Box-Muller algorithm to generate two gaussing distributed random variables. We generate $10^5$ random number pairs and plot them separately in two histograms shown below.\\\\\nHere we have used the standard python random number generator which uses \\textbf{Mersenel Primes} to generate a random number in the range of [0,1]\n\\begin{figure}[ht]\n    \\begin{subfigure}{.5 \\textwidth}\n\t\\centering\n    \\includegraphics[scale=0.40]{figure3_y1s.png}\n    \\caption{$Y_1$ as per $\\sqrt(-2\\log(x1))*\\cos(2*\\pi*x2)$}\n\t\\label{fig:Y1}\n\\end{subfigure}\n    \\begin{subfigure}{.5 \\textwidth}\n\t\\centering\n    \\includegraphics[scale=0.40]{figure3_y2s.png}\n    \\caption{$Y_1$ as per $\\sqrt(-2\\log(x1))*\\cos(2*\\pi*x2)$}\n\t\\label{fig:Y1}\n\\end{subfigure}\n    \\caption{This plot shows Y1 and Y2, two random variables generated from two uniformly distributed random variables(x1 and x2) and transformed as showing under the respective graphs.}\n\\end{figure}\n\nThese are two zero mean and unit variance gaussian distributed random numbers.\n\nThe corresponding python code can be found at \\ref{code:problem3a}\n\\section{Solution 4a}\\label{prob4a}\n\nIn this section we compare the 1st, 2nd and 3rd moments of two random number generators. LCG(128, 0, 509) and Mersene Twister. We compare these to the true moments defined by:\n\\begin{equation}\n    \\langle x^{k} \\rangle = \\frac{1}{(k+1)}\n\\end{equation}\nIn the above equation k is the moment. i.e. k = 1 gives us the 1st moment, k = 2 gives us the second moment and so on.\nWe calculate the moments for different random number generators by generating a sequence of $N$ random numbers from the generator and using the formula below. \n\\begin{equation}\n    \\langle x^k \\rangle = \\frac{1}{N}\\sum_{i=1}^{N}x_{i}^{k}\n\\end{equation}\n\nIn this experiment we are trying to see whether the the two random number generators are truly uniform. If they are then their moments must be close to the true moments of the uniform distribution.\n\n\\begin{table}[ht]\n\\centering\n\\label{1moment}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n\\textbf{N} & \\textbf{LCG(128,0,509)}&\\textbf{Mersene Twister}&\\textbf{True Moment} \\\\ \\hline\n10 & 0.0264746457362 & 0.518080782167 & 0.5 \\\\\n100 & 0.00240679565587 & 0.474926738729 & 0.5 \\\\\n1000 & 0.000238511281212 & 0.494459184012 & 0.5 \\\\\n10000 & 2.38296599591e-05 & 0.493928278685 & 0.5 \\\\\n100000 & 2.38275152683e-06 & 0.500197518937 & 0.5 \\\\\n1000000 & 2.38273008204e-07 & 0.499728476939 & 0.5 \\\\\n10000000 & 2.38272793759e-08 & 0.500054377307 & 0.5 \\\\\n\\hline\n\\end{tabular}\n\\caption{Values for the 1st Moment}\n\\end{table}\n\n\\begin{table}[ht]\n\\centering\n\\label{1moment}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n\\textbf{N} & \\textbf{LCG(128,0,509)}&\\textbf{Mersene Twister}&\\textbf{True Moment} \\\\ \\hline\n10 & 0.00377304392308 & 0.310275753489 & 0.333333333333 \\\\\n100 & 0.000343003993013 & 0.311212396032 & 0.333333333333 \\\\\n1000 & 3.3991386695e-05 & 0.328312667816 & 0.333333333333 \\\\\n10000 & 3.39607913874e-06 & 0.326612059681 & 0.333333333333 \\\\\n100000 & 3.39577348856e-07 & 0.333317261858 & 0.333333333333 \\\\\n1000000 & 3.39574292657e-08 & 0.333169017655 & 0.333333333333 \\\\\n10000000 & 3.3957398704e-09 & 0.3333760948 & 0.333333333333 \\\\\n\\hline\n\\end{tabular}\n\\caption{Values for the 2nd Moment}\n\\end{table}\n\n\\begin{table}[ht]\n\\centering\n\\label{1moment}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n\\textbf{N} & \\textbf{LCG(128,0,509)}&\\textbf{Mersene Twister}&\\textbf{True Moment} \\\\ \\hline\n10 & 0.000640566707312 & 0.199266027703 & 0.25 \\\\\n100 & 5.82333370283e-05 & 0.228229711742 & 0.25 \\\\\n1000 & 5.77087123704e-06 & 0.246069547559 & 0.25 \\\\\n10000 & 5.7656769335e-07 & 0.243561537242 & 0.25 \\\\\n100000 & 5.76515801739e-08 & 0.249764456768 & 0.25 \\\\\n1000000 & 5.76510613091e-09 & 0.249906635608 & 0.25 \\\\\n10000000 & 5.76510094232e-10 & 0.250034371239 & 0.25 \\\\\n\\hline\n\\end{tabular}\n\\caption{Values for the 3rd Moment}\n\\end{table}\nWe can see that in all the 3 cases above, the LCG deviates from each of the moments quite a bit as we take more samples from the random number generator. However, the Mersent Twister stays quite close to the true moment even when we take a lot of samples from the generator which means that the random number it generates are close to uniformly distributed.\n% \\begin{figure}[ht]\n% \t\\center\n%     \\includegraphics[scale=0.75]{matlabS_dash.png}\n%     \\caption{Plot showing the first derivative of the natural cubic interpoland S'(X) as calculated using Matlab. Values of $S'(X_i)$ for $X_i$ in the range of (min(knot values), max(knot values)) are shown as red circles.} \n% \t\\label{fig:sdash_matlab}\n% \\end{figure}\n% The corresponding plots created by matlab are much more smoother because matlab implements an additional constraint that the third derivatives of the piecewise polynomials are also equal at the second and the last knots. This are apparently called the \"Not-A-Knot\" end conditions. This is only done when the length of \\textbf{t} and \\textbf{y} are same.\n% \n% Natural splines are a good choice only when the functions have 0 second derivative at the end points. I read it up from here. \\url{http://www.mathworks.com/matlabcentral/newsreader/view_thread/172988} would really appreciate some more information about why using the Not-A-Knot condition is better. \n% \\\\\n% The corresponding matlab code can be found at \\ref{code:problem2b}\n\nThe corresponding python code can be found at \\ref{code:problem4a}\n\n\\section{Solution 4b}\\label{prob4b}\nIn this solution we are trying to validate the central limit theorem. \\textit{An average of measured quantities, taken from the same distribution (which can be any distribution), will asymptotically follow the normal distribution.}\nHere we draw random numbers from the uniform distribution and since the generator generates values close to the uniform distribution the mean of the values as we draw more samples tends to the normal distribution.\n\\begin{figure}[ht]\n    \\begin{subfigure}{.5 \\textwidth}\n\t\\centering\n    \\includegraphics[scale=0.45]{fig4b.png}\n    \\caption{N = 100, m = 10000}\n\t\\label{fig:clt_10000}\n    \\end{subfigure}\n    \\begin{subfigure}{.5 \\textwidth}\n\t\\centering\n    \\includegraphics[scale=0.45]{fig4b_100000.png}\n    \\caption{N = 100, m = 100000}\n\t\\label{fig:clt_100000}\n    \\end{subfigure}\n    \\caption{Figure validating the central limit theorem in the figure to the left we have plotted 10000 means of $\\langle x^2 \\rangle$100 random numbers and can see that the figure is almost like the normal distribution. This is confirmed as the number of means are increased to 100,000 of 100 random numbers and the graph looks very much like the normal distribution. Bins = 100 interval = [0.2,0.5] this interval is chosen because the mean of the values is around 0.33333}\n\\end{figure}\n\n\nThe corresponding python code can be found at \\ref{code:problem4b}\n\\clearpage\n\\section{Appendix A}\\label{code:problem3a}\nPython source code for \\ref{prob3a}.\n{\\footnotesize\n\\begin{lstlisting}\nfrom __future__ import division\nimport random\nimport math\nimport pylab as pl\n\npi    = math.pi\nlog   = math.log\ncos   = math.cos\nsin   = math.sin\nsqrt  = math.sqrt\nfloor = math.floor\n\ndef get_gauss_random():\n    x1 = random.random()\n    x2 = random.random()\n\n    y1 = sqrt(-2*log(x1))*cos(2*pi*x2)\n    y2 = sqrt(-2*log(x1))*sin(2*pi*x2)\n\n    # We don't multiply by sigma\n    # implying the value is unit variance\n\n    # Since are random numbers are uniform\n    # between 0 and 1, we have zero mean.\n\n    # Hence our distributionis zero mean and \n    # unit variance.\n    return y1,y2\n\n\ndef get_bin(yi, ymin, ymax, Nbin):\n    val = ((yi - ymin) / (ymax - ymin)) * Nbin\n    return floor(val)\n\nif __name__ == '__main__':\n    seed = 7777\n    random.seed(seed)\n    Nbin = 100\n    bins = [0] * Nbin\n    ymin, ymax = -5, 5\n    binVals = []\n    ybins = []\n    for _ in xrange(100000):\n        y = get_gauss_random()\n        ybins.append(y)\n        #binVals.append(get_bin(yi, ymin, ymax, Nbin))\n        # binNum = get_bin(yi, ymin, ymax, Nbin)\n        # bins[binNum]+=1\n    y1s,y2s = zip(*ybins)\n    pl.figure()\n    pl.grid()\n    pl.hist(y1s,bins=Nbin,range=(ymin,ymax))\n    #pl.hist(binVals, bins=Nbin)\n    pl.xlabel(\"Bins\")\n    pl.title(\"Y1s\")\n    pl.savefig(\"figure3_y1s.png\")\n    pl.figure()\n    pl.grid()\n    pl.hist(y2s,bins=Nbin,range=(ymin,ymax))\n    #pl.hist(binVals, bins=Nbin)\n    pl.xlabel(\"Bins\")\n    pl.title(\"Y2s\")\n    pl.savefig(\"figure3_y2s.png\")\n    pl.show()\n\\end{lstlisting}\n}\n\\clearpage\n\\section{Appendix B}\\label{code:problem4a}\nPython source code \\ref{prob4a}.\n{\\footnotesize\n\\begin{lstlisting}\n\nfrom __future__ import division\nimport random\nimport math\nimport pylab as pl\n\npi    = math.pi\nlog   = math.log\ncos   = math.cos\nsin   = math.sin\nsqrt  = math.sqrt\nfloor = math.floor\n\ndef lcg(x):\n    # Implementing lcg(a,b,m)\n    # a = 128 b = 0 m = 509\n    a = 128\n    b = 0\n    m = 509\n    randVal = (a*x + b)%m\n    return randVal / m # scale the rand num to be in 0,1 range\n\ndef get_moment(rand_nums, m):\n    return sum([x**m for x in rand_nums])/len(rand_nums)\n\nif __name__ == '__main__':\n    seed = 7777\n    random.seed(seed)\n    randLcg = lcg(seed)   \n    lcgs = [randLcg]\n    srgl = []\n    N = 10**7\n    moment = [[],[],[]]\n    for _ in xrange(N):\n        randLcg = lcg(randLcg)\n        lcgs.append(randLcg)\n        srgl.append(random.random())\n    for m in [1,2,3]:\n        trueMoment = 1/(m+1)\n        print \"M = {}\".format(m)\n        for N in [10, 100, 1000, 10000, 100000, 1000000, 10000000]:\n            lcgMoment = get_moment(lcgs[1:N], m)\n            srglMoment = get_moment(srgl[1:N], m)\n            moment[m-1].append((lcgMoment, srglMoment, trueMoment))\n            print(\"{} & {} & {} & {} \\\\\\\\\".format(N,lcgMoment,srglMoment,trueMoment))\n\n \n\\end{lstlisting}\n}\n\\section{Appendix C}\\label{code:problem4b}\nPython source code for \\ref{prob4b}.\n{\\footnotesize\n\\begin{lstlisting}\nfrom __future__ import division\nimport random\nimport math\nimport pylab as pl\n\npi    = math.pi\nlog   = math.log\ncos   = math.cos\nsin   = math.sin\nsqrt  = math.sqrt\nfloor = math.floor\n\ndef get_moment(rand_nums, m):\n    return sum([x**m for x in rand_nums])/len(rand_nums)\n\nif __name__ == '__main__':\n    seed = 7777\n    random.seed(seed)\n    N = 100\n    m = 10000\n    means = []\n    for _ in xrange(m):\n        temp = 0\n        for _ in xrange(N):\n            temp += random.random() ** 2\n        means.append(temp/N)\n    pl.hist(means, bins=100, range=(0.2,0.5))\n    pl.savefig(\"fig4b.png\")\n    pl.show()\n\\end{lstlisting}\n}\n\\end{document}\n\n   \n\n", "meta": {"hexsha": "bf2b17f9c4d11506ff53c42f00b4066942046d5f", "size": 12332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercise8/report.tex", "max_stars_repo_name": "kunalghosh/BECS-114.1100-Computational-Science", "max_stars_repo_head_hexsha": "ca91ac59cb5276d213c1aec50ae7786efe72ae43", "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": "exercise8/report.tex", "max_issues_repo_name": "kunalghosh/BECS-114.1100-Computational-Science", "max_issues_repo_head_hexsha": "ca91ac59cb5276d213c1aec50ae7786efe72ae43", "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": "exercise8/report.tex", "max_forks_repo_name": "kunalghosh/BECS-114.1100-Computational-Science", "max_forks_repo_head_hexsha": "ca91ac59cb5276d213c1aec50ae7786efe72ae43", "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": 36.1642228739, "max_line_length": 475, "alphanum_fraction": 0.706373662, "num_tokens": 3960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.6420482546497808}}
{"text": "\\documentclass[11pt]{article}\n\n\n\\usepackage[margin=1in]{geometry}\n\n\\usepackage{mathpazo}\n\n\\usepackage{amsmath}\n\n\\newcommand{\\numpy}{{\\sffamily NumPy}}\n\n\\usepackage[defaultsans]{cantarell} %% Use option ``defaultsans'' to use cantarell as sans serif only\n\\usepackage[T1]{fontenc}\n\n% this needs to be done before the fncychap style, since that will \n% redo the chapter stuff\n\\usepackage{sectsty}\n\\allsectionsfont{\\sffamily}\n\n\\usepackage{graphicx}\n\n% prefer PDF to PNG\n\\DeclareGraphicsExtensions{% \n  .pdf}\n\n\n\\begin{document}\n\n\\begin{center}\n{\\bfseries \\sffamily \\LARGE Making Sense of Power Spectra} \\\\\nMichael Zingale\n\\end{center}\n\nWe are interested in computing the numerical power spectrum of a\ndiscretely-sampled three-dimensional dataset.  These notes serve\nto verify the procedure by starting with a real-space\nfunction with a known analytic power spectrum and computing the\npower spectrum of this test function.\n\nConsider a function that is a superposition of sines with different\nwavelengths.  The power will be encoded in the amplitude of the sines.\nNow imagine this function discretely sampled at $N$ points.  For a domain of\nlength $L$ the highest possible wavenumber is:\n\\begin{equation}\nk_\\mathrm{max} = \\frac{1}{\\Delta x}\n\\end{equation}\nwith $\\Delta x = L/N$.  However, for real-valued data, Nyquist sampling\nmeans that $k_\\mathrm{max}/2$ is the meaningful maximum.\nThe lowest wavenumber is:\n\\begin{equation}\nk_\\mathrm{min} = \\frac{1}{L}\n\\end{equation}\nFigure~\\ref{fig:wavenumbers} shows two different sine modes.\n\n\\suppressfloats\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.75\\linewidth]{wavenumber}\n\\caption{\\label{fig:wavenumbers} The $k = 1/L$ (top) and $k = 4/L$ (bottom)\nmodes.}\n\\end{figure}\n\n\nThe definition of the Fourier transform is:\n\\begin{equation}\n\\mathcal{F}(k) = \\int_{-\\infty}^{\\infty} f(x) e^{-2\\pi i x k} dx\n\\end{equation}\nwith the inverse transform as\n\\begin{equation}\nf(x) = \\int_{-\\infty}^{\\infty} \\mathcal{F}(x) e^{2\\pi i x k} dk\n\\end{equation}\nHowever, we need to work with discretely-sampled data, so we will need\nthe {\\em discrete Fourier transform}, which is efficiently implemented by\nthe FFT algorithm.\n\n\\section*{\\numpy\\ details}\n\nThe \\numpy\\ FFTs have the discrete form:\n\\begin{equation}\n\\mathcal{F}_k = \\sum_{m=0}^{N-1} f_m \\exp \\left \\{ -2\\pi i \\frac{mk}{N} \\right \\}\n\\end{equation}\nand the inverse is\n\\begin{equation}\nf_m = \\frac{1}{N} \\sum_{k=0}^{N-1} \\mathcal{F}_k \\exp \\left \\{ 2\\pi i \\frac{mk}{N} \\right \\}\n\\end{equation}\nWe see from the inverse that if we want to know the amplitude of a single\nmode at a given spatial location (denoted by index $m$), that $\\mathcal{F}/N$\nis the normalized amplitude, i.e., we can think of this expansion as:\n\\begin{equation}\nf_m = \\sum_{k=0}^{N-1} \\left (\\frac{\\mathcal{F}_k}{N} \\right )\n    \\exp \\left \\{ 2\\pi i \\frac{mk}{N} \\right \\}\n\\end{equation}\n\n\nThe {\\tt rfftfreq()} function returns the wavenumbers as\n\\begin{equation}\nk = \\left \\{ 0, \\frac{1}{N}, \\frac{2}{N}, \\ldots, \\frac{N-2}{2N}, \\frac{1}{2} \\right \\}\n\\end{equation}\n(for even $n$, and in the mode where we do not specify the sample spacing).\nWe convert these into a physical quantity (with units of cm$^{-1}$) by\nmultiplying by $1/\\Delta x$, giving the set:\n\\begin{equation}\nk = \\left \\{ 0, \\frac{1}{L}, \\frac{2}{L}, \\ldots, \\frac{1}{2\\Delta x} \\right \\}\n\\end{equation}\n\n\\numpy\\ does not have a real-valued FFT function for 3-d data, so we\nneed to use the {\\tt fftn} function.  Because $N$ real numbers results\nin $2N$ complex numbers, only 1/2 of the transformed data (in each\ndimension) will be unique.  In 3-d this means we consider only an\noctant of data.  In practice, this means keeping the positive\nfrequencies and dropping the negative ones (this is what the {\\tt\n  rfftfreq} function does for us).\n\n\n\n\n\\section*{Power}\n\nFor a continuous function, $f(x)$, the ``energy'' is defined as\n\\begin{equation}\nE = \\int_{-\\infty}^\\infty |f(x)|^2 dx\n\\end{equation}\nUsing Parseval's theorem, we have\n\\begin{equation}\nE = \\int_{-\\infty}^\\infty |\\mathcal{F}(k)|^2 dk\n\\end{equation}\n%\nSo when we compute the power spectrum, we will be looking at\n$|\\mathcal{F}(k)|^2$. \\\\\n\n\\noindent [see ``spectral density'' Wikipedia] \\\\\n\nThe discrete version of Parseval's theorem in 1-d is\n\\begin{equation}\n\\sum_{n=0}^{N-1} | f(n) |^2 = \\frac{1}{N} \\sum_{k=0}^{N-1} | \\mathcal{F}(k) |^2\n\\end{equation}\n\n\n\\section*{One-dimensional Example}\n\nThe idea of the power spectrum is very straightforward in 1-d.  To illustrate\nthis we will create a function in real space that we expect to have a\npower spectrum scaling as:\n\\begin{equation}\nP \\sim k^{-\\eta}\n\\end{equation}\nThis is accomplished by setting the amplitude of each mode to yield\nthis power.  Our function is:\n\\begin{equation}\nf(x) = \\sum_{m=1}^{N_\\mathrm{modes}} a_m \\sin \\left ( \\frac{2\\pi m x}{L}\\right )\n\\end{equation}\nwhere $L$ is the width of the physical domain, and \n\\begin{equation}\na_m = \\left (A_0 k^{-\\eta} \\right )^{1/2}\n\\end{equation}\nThis function is shown in Figure~\\ref{fig:phi1d}.\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.5\\linewidth]{phi_1d}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\caption{\\label{fig:phi1d} The real-space, one-dimensional function $f(x)$,\nfor the case $N_\\mathrm{modes} = 16$, with $A_0 = 1000$ and $\\eta = -4$.\\newline}\n\\end{minipage}\n\\end{figure}\n\nWe then transform this function, denoting the transform as $\\mathcal{F}(k)$.  Plotting\n$|\\mathcal{F}(k)|^2$ vs.\\ $k$ gives the power spectrum.  Figure~\\ref{fig:ps1d} shows\nthe result, together with the expected power-law scaling, $P$, shown as the \ndashed line.\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.5\\linewidth]{ps1d}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\caption{\\label{fig:ps1d} The power spectrum of $f(x)$, compared to the\nexpected result (dashed line).\\newline}\n\\end{minipage}\n\\end{figure}\n\n\n\nSee {\\tt ps1d.py} for the implementation of this test.\n\n\n\n\\section*{Three-dimensional Case}\n\nIn 3-d, things are more complex---traditionally we express the power\nspectrum by integrating over spherical shells with a radius $k$.  The\npower spectrum is defined as\n\\begin{equation}\nE(k) = \\frac{1}{\\Omega} \\int_{S(k)} \\mathcal{F}(k) \\mathcal{F}^\\star(k) dS\n\\end{equation}\nwhere $\\Omega$ is the volume in physical space, and the integral is done\nover the surface $S(k)$, defined by $|\\vec{k}| = k$.  We can\nwrite $dS = 4\\pi k^2 dk$ and integrate along radial $|\\vec{k}|$.\n\nIn discrete form, we bin the $k$ in our transformed space into a\nnumber of uniformly spaced bins, $\\kappa_l$, where the index\n$l$ denote the bin boundaries, with $\\kappa_0$ the leftmost bin boundary.\nWe also denote the bin centers as $\\bar{\\kappa}_l$ such that\n\\begin{equation}\n\\bar{\\kappa}_l = \\frac{1}{2} ( \\kappa_l + \\kappa_{l+1} )\n\\end{equation}\nOur power spectrum becomes\n\\begin{equation}\nE(\\bar{\\kappa}_l) = \\sum_{\\kappa_{l} \\le |\\vec{k}| < \\kappa_{l+1}}\n   \\mathcal{F}(k) \\mathcal{F}^\\star(k)\n\\end{equation}\nwhere the sum is over all the zones in the $k_x \\times k_y \\times k_z$\ncube whose wavenumber magnitude, $k$, falls into our bin,\n$[\\kappa_l,\\kappa_{l+1})$.  As we go to higher wavenumbers, the number\n  of zones will increase as $k^2$---this captures the $dS$ scaling in\n  the continuous-form of the power spectrum.\n\n\nAgain, to test the algorithm, we define a test function and set the power at\ndifferent wavenumbers {\\em in physical space}, and then do the transform\nand power spectrum to see if we get the expected result.  We will design\nour function to have the same scaling as the 1-d case, $P \\sim k^{-\\eta}$.\nOur test function\nis:\n\\begin{equation}\nf(x,y,z) = \\sum_{m=1}^{N_\\mathrm{modes}} \n              \\sum_{n=1}^{N_\\mathrm{modes}} \n              \\sum_{p=1}^{N_\\mathrm{modes}} \n     a_{m,n,p} \\sin \\left ( \\frac{2\\pi m x}{L_x} + \n                            \\frac{2\\pi n y}{L_y} + \n                            \\frac{2\\pi p z}{L_z} \\right )\n\\end{equation}\nwhere we can identify the wavenumbers in each direction as\n\\begin{equation}\nk_m = \\frac{m}{L_x} \\, ; \\quad \nk_n = \\frac{n}{L_y} \\, ; \\quad \nk_p = \\frac{p}{L_z} \\,\n\\end{equation}\nThis is equivalent to defining a vector wavenumber\n\\begin{equation}\n\\vec{k} = k_m \\hat{x} + k_n \\hat{y} + k_p \\hat{z}\n\\end{equation}\nand expressing a single component as\n\\begin{equation}\nf_{m,n,p} = a_{m,n,p} \\sin(2\\pi \\vec{k}\\cdot \\vec{x})\n\\end{equation}\n\n\n\nWe can set the amplitude of component based on our desired\npower-law scaling.  Defining $k = |k|$, and $A_0$ as a\nreference amplitude of the power, we take\n\\begin{equation}\na_{m,n,p}^2 = \\frac{A_0 k^{-\\eta}}{W(k)} \\frac{1}{\\Delta S}\n\\end{equation}\nwhere $W(k)$ is the weight that accounts for the fact that multiple\ncombinations of $m, n, p$ can result in the same $k$.  Using Iverson bracket\nnotation, defined as\n\\begin{equation}\n[P] = \\begin{cases}\n  1 & \\text{if P is true} \\\\\n  0 & \\text{otherwise}\n      \\end{cases}\n\\end{equation}\nwe find $W(k)$ as\n\\begin{equation}\nW(k) = \\sum_{m=1}^{N_\\mathrm{modes}}\n       \\sum_{n=1}^{N_\\mathrm{modes}} \n       \\sum_{p=1}^{N_\\mathrm{modes}} [ k_m^2 + k_n^2 + k_p^2 = k^2 ]\n\\end{equation}\n\nThe $\\Delta S$ in the weighting reflects the fact that the power \nin mode $k$ resides in a spherical shell---we need to divide this\narea out so when we integrate over $dS$, we get the correct power\nin the shell.  For $|k| \\gg \\Delta \\kappa$, we can take $\\Delta S \\sim\n4\\pi k^2$.  But we can do better by recognizing that eventually we\nwill bin the data up into the bins given by $\\{\\kappa_l\\}$.  If we\ndenote the bin $\\xi$ such that $\\kappa_\\xi \\le k < \\kappa_{\\xi+1}$,\nthen we can take\n\\begin{equation}\n\\Delta S = 4 \\pi \\bar{\\kappa}_\\xi^2\n\\end{equation}\n\nThis normalization should give an amplitude in the power spectrum at the lowest\n$k$ that agrees with the corresponding amplitude in real-space for that same $k$.  \nFigure~\\ref{fig:phireal} shows the function in three orthogonal slice planes\nthrough the center of the domain.\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=\\linewidth]{phi}\n\\caption{\\label{fig:phireal} $f(x,y,z)$ shown in three orthogonal slice\nplanes through the center of the domain.}\n\\end{figure}\n\nSince the power spectrum integrated over shells, we don't include the $4\\pi$\nin the real space amplitude when comparing our power spectrum to the $P \\sim k^{-\\eta}$\nexpected result.  Figure~\\ref{fig:ps} shows the power spectrum of our function.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=0.5\\linewidth]{ps}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\caption{\\label{fig:ps} The power spectrum of our function $f(x,y,z)$ compared to\nthe expected result (dashed line).\\newline}\n\\end{minipage}\n\\end{figure}\n\n\nAs a final check on the overall normalization, we can use Parseval's theorem\nto see if we have the correct amount of energy in the spectrum.  In 3-d,\nParseval's theorem says:\n\\begin{equation}\nE = \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} |f(x,y,z)|^2 dx dy dz = \n  \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty}  |\\mathcal{F}(k_x,k_y,k_z)|^2 dk_x dk_y dk_z\n\\end{equation}\nor in discrete form:\n\\begin{equation}\n\\sum_{j=0}^{N_x} \\sum_{k=0}^{N_y} \\sum_{l=0}^{N_z}\n   | f(x_j, y_k, z_l) |^2 = \\frac{1}{N_x N_y N_z} \n \\sum_{k_x=0}^{N_x-1} \\sum_{k_y=0}^{N_y-1} \\sum_{k_z=0}^{N_z-1} \n   | \\mathcal{F}(k_x, k_y, k_z) |^2\n\\end{equation}\nWe can express the integral over $d^3k$ in terms of the spherical $|k|$ as\n\\begin{equation}\nE = 4\\pi \\int_{-\\infty}^{\\infty} |\\mathcal{F}(k)|^2 k^2 dk = \\int_{-\\infty}^{\\infty} E(k) dk\n\\end{equation}\nwhere we substitute in the power spectrum, $E(k)$.  This means that if we integrate up our\npower spectrum, we should get the same energy as the integral\nof $|f(x,y,z)|^2$ over physical space.  We need to keep track of the normalizations---in\ncreating the power spectrum, we used $\\mathcal{F}/N^3$, so our discrete sum over the energy\nspectrum will have a $N^{-6}$ normalization, while the discrete form of Parseval's theorem\nhas an $N^{-3}$ normalization.\n\n\n\\end{document}\n", "meta": {"hexsha": "c8795dc1b9ed9a5e9ae0d5212fa8afdb69017aa2", "size": 11914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "overview.tex", "max_stars_repo_name": "zingale/powerspectrum_test", "max_stars_repo_head_hexsha": "140f4a70b43edf3fb68fc8ab1d56818f7a6c7a3b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-03-17T14:53:13.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-02T21:54:17.000Z", "max_issues_repo_path": "overview.tex", "max_issues_repo_name": "zingale/powerspectrum_test", "max_issues_repo_head_hexsha": "140f4a70b43edf3fb68fc8ab1d56818f7a6c7a3b", "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": "overview.tex", "max_forks_repo_name": "zingale/powerspectrum_test", "max_forks_repo_head_hexsha": "140f4a70b43edf3fb68fc8ab1d56818f7a6c7a3b", "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.353115727, "max_line_length": 118, "alphanum_fraction": 0.6978344804, "num_tokens": 3975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6420482499243692}}
{"text": "\\section{Orthogonal projections and Fourier series}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute the orthogonal projection of a vector onto a subspace.\n  \\item Find the least squares approximation of a function by a\n    polynomial of a given degree. \n  \\item Calculate the generalized Fourier series of a vector.\n  \\item Use Fourier series to approximate a function by polynomials or\n    trigonometric functions.\n  \\end{enumerate}\n\\end{outcome}\n\nWe now reconsider a problem that we briefly encountered, only in the\ncontext of $\\R^3$, in Section~\\ref{sec:planes}: how to find the\nshortest distance between a point and a subspace. The method we used\nin Section~\\ref{sec:planes} (see\nExample~\\ref{exa:shortest-distance-plane}) relies on the existence of\nnormal vectors and does not generalize beyond $\\R^3$. The following\nproposition gives a much better method for solving this problem,\nprovided that we have an orthogonal basis of the subspace.\n\n\\begin{proposition}{Orthogonal projection onto a subspace}{projection-subspace}\n  Let $V$ be an inner product space, and let $W$ be a subspace of\\/\n  $V$. Assume $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is an orthogonal\n  basis of\\/ $W$, and $\\vect{v}\\in V$ is any vector. Then the\n  following vector $\\vect{v}'$ is the element of $W$ that is closest\n  to $\\vect{v}$, i.e., such that $\\norm{\\vect{v}-\\vect{v}'}$ is as\n  small as possible.\n  \\begin{equation*}\n    \\vect{v}' =\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n    + \\ldots\n    + \\frac{\\iprod{\\vect{u}_k,\\vect{v}}}{\\iprod{\\vect{u}_k,\\vect{u}_k}}\\,\\vect{u}_k.\n  \\end{equation*}\n  Moreover, the vector $\\vect{v}-\\vect{v}'$ is orthogonal to $W$.\n  \\begin{center}\n    \\begin{tikzpicture}[x={(1cm,-0.1cm)},y={(0.4cm,0.5cm)},z={(0cm,1cm)}]\n      \\filldraw[draw=red!80,fill=red!10](-4,-4,0) -- (4,-4,0) -- (4,4,0) -- (-4,4,0) -- cycle;\n      \\path[red] (4.5,0,0) node[right] {$W$};\n      \\draw[thin,red!50] (-2,-4,0) -- (-2,4,0);\n      \\draw[thin,red!50] (0,-4,0) -- (0,4,0);\n      \\draw[thin,red!50] (2,-4,0) -- (2,4,0);\n      \\draw[thin,red!50] (-4,-2,0) -- (4,-2,0);\n      \\draw[thin,red!50] (-4,0,0) -- (4,0,0);\n      \\draw[thin,red!50] (-4,2,0) -- (4,2,0);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[below, pos=0.45]{$\\vect{u}_1$} (2,0,0);\n      \\draw[->,thick,blue!80!black](0,0,0) -- node[left, pos=0.55]{$\\vect{u}_2$} (0,2,0);\n      \\draw[->,thick,green!50!black](0,0,0) -- node[above, pos=0.7] {$\\vect{v}$} (3,2.5,2);\n      \\draw[->,thick,green!50!black](0,0,0) -- node[above, pos=0.7] {$\\vect{v}'$} (3,2.5,0);\n      \\draw[dashed](3,2.5,0) -- (3,2.5,2);\n      \\fill (0,0,0) circle [radius=2.2pt] node [left=3pt] {$\\vect{0}$};\n      \\fill (3,2.5,2) circle [radius=2.2pt];\n      \\fill (3,2.5,0) circle [radius=2.2pt];\n    \\end{tikzpicture}\n  \\end{center}\n  The vector $\\vect{v}'$ is called the \\textbf{orthogonal projection\n    of $\\vect{v}$ onto $W$}%\n  \\index{orthogonal projection!onto subspace}%\n  \\index{projection!onto subspace}. We also say that $\\vect{v}'$ is\n  the \\textbf{best approximation}%\n  \\index{approximation} of $\\vect{v}$ in $W$.\n\\end{proposition}\n\n\\begin{proof}\n  In case $\\vect{v}\\in W$, then by\n  Proposition~\\ref{prop:fourier-coefficients}, we have\n  \\begin{equation*}\n    \\vect{v} =\n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n    + \\ldots\n    + \\frac{\\iprod{\\vect{u}_k,\\vect{v}}}{\\iprod{\\vect{u}_k,\\vect{u}_k}}\\,\\vect{u}_k,\n  \\end{equation*}\n  and therefore $\\vect{v}'=\\vect{v}$. In that case\n  $\\norm{\\vect{v}-\\vect{v}'}=0$, which is clearly as small as\n  possible, and $\\vect{v}-\\vect{v}'=\\vect{0}$ is orthogonal to $W$, so\n  we are done.\n\n  Now assume that $\\vect{v}\\not\\in W$. Let\n  $W'=\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k,\\vect{v}}$. Apply the\n  Gram-Schmidt procedure to the $k+1$ vectors\n  $\\vect{u}_1,\\ldots,\\vect{u}_k,\\vect{v}$ to obtain an orthogonal\n  basis of $W'$. Since the first $k$ vectors are already orthogonal,\n  the Gram-Schmidt procedure does not change them, and we therefore\n  obtain an orthogonal basis of $W'$ of the form\n  $\\vect{u}_1,\\ldots,\\vect{u}_k,\\vect{u}_{k+1}$. Since $\\vect{v}\\in\n  W'$, we can write $\\vect{v}$ as a linear combination of these basis\n  vectors, i.e., $\\vect{v}=a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k +\n  a_{k+1}\\vect{u}_{k+1}$. Moreover, by\n  Proposition~\\ref{prop:fourier-coefficients}, we know that each $a_j$\n  is the corresponding Fourier coefficient of $\\vect{v}$, i.e., $a_j =\n  \\frac{\\iprod{\\vect{u}_j,\\vect{v}}}{\\iprod{\\vect{u}_j,\\vect{u}_j}}$.\n\n  Now consider any $\\vect{w}\\in W$. Since\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is a basis of $W$, we can write\n  $\\vect{w} = x_1\\vect{u}_1 + \\ldots + x_k\\vect{u}_k$. Using\n  Proposition~\\ref{prop:norm-orthogonal}, we have\n  \\begin{eqnarray*}\n    \\norm{\\vect{v}-\\vect{w}}^2\n    &=& \\norm{(a_1-x_1)\\vect{u}_1 + \\ldots + (a_k-x_k)\\vect{u}_k + a_{k+1}\\vect{u}_{k+1}}^2 \\\\\n    &=& (a_1-x_1)^2\\norm{\\vect{u}_1}^2 ~+~ \\ldots ~+~ (a_k-x_k)^2\\norm{\\vect{u}_k}^2 ~+~ a_{k+1}^2\\norm{\\vect{u}_{k+1}}^2.\n  \\end{eqnarray*}\n  Here, $a_1,\\ldots,a_{k+1}$ are the fixed coordinates of $\\vect{v}$,\n  and $x_1,\\ldots,x_k$ depend on $\\vect{w}$.  Therefore,\n  $\\norm{\\vect{v}-\\vect{w}}$ takes its smallest value when $x_j=a_j$,\n  for $j=1,\\ldots,k$. So the minimum value of\n  $\\norm{\\vect{v}-\\vect{w}}$ occurs when\n  \\begin{equation*}\n    \\vect{w}\n    ~~=~~ a_1\\vect{u}_1 + \\ldots + a_k\\vect{u}_k \n    ~~=~~ \n    \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n    + \\ldots\n    + \\frac{\\iprod{\\vect{u}_k,\\vect{v}}}{\\iprod{\\vect{u}_k,\\vect{u}_k}}\\,\\vect{u}_k\n    ~~=~~ \\vect{v}'.\n  \\end{equation*}\n  This is what had to be shown. Finally, to show that\n  $\\vect{v}-\\vect{v}'$ is orthogonal to $W$, note that\n  $\\vect{v}-\\vect{v}' = a_{k+1}\\vect{u}_{k+1}$, which is orthogonal to\n  each $\\vect{u}_1,\\ldots,\\vect{u}_k$, and therefore to $W$.\n\\end{proof}\n\n\\begin{example}{Orthogonal projection onto a subspace}{projection-subspace}\n  Consider $\\R^4$ with the usual dot product. Let\n  $W=\\sspan\\set{\\vect{u}_1,\\vect{u}_2}$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\\\ 0 \\end{mymatrix}, \\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 1 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Note that $\\vect{u}_1$ and $\\vect{u}_2$ are orthogonal. Let\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  Find the best approximation of $\\vect{v}$ in $W$.\n\\end{example}\n\n\\begin{solution}\n  We calculate $\\iprod{\\vect{u}_1,\\vect{v}}=9$,\n  $\\iprod{\\vect{u}_1,\\vect{u}_1}=6$, $\\iprod{\\vect{u}_2,\\vect{v}}=12$,\n  and $\\iprod{\\vect{u}_2,\\vect{u}_2}=12$. Therefore, by\n    Proposition~\\ref{prop:projection-subspace}, the desired vector is\n  \\begin{equation*}\n    \\vect{v}'\n    ~=~ \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n    + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n    ~=~ \\frac{9}{6} \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + \\frac{12}{12} \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 1 \\\\ 3 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 1/2 \\\\ 1/2 \\\\ 4 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nNote how straightforward the calculations in this example are. All we\nhad to do is calculate a few inner products. It is not even necessary\nto solve a system of equations. Such is the power of orthogonal bases.\n\nThe next example shows that we can use exactly the same method to find\napproximations%\n\\index{approximation!of functions} of functions.\n\n\\begin{example}{Approximating a function by a polynomial}{projection-subspace-polynomial}\n  Let $V=C[-1,1]$ be the vector space of continuous functions, with the\n  inner product given by\n  \\begin{equation*}\n    \\iprod{f,g} = \\int_{-1}^{1} f(x)g(x)\\,dx.\n  \\end{equation*}\n  Consider the function $f\\in V$ given by\n  \\begin{equation*}\n    f(x)\n    ~=~ 1-\\abs{x}\n    ~=~ \\begin{cases}\n      1+x & \\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 2. Graph both $f$ and the approximating polynomial.\n\\end{example}\n\n\\begin{solution}\n  Let $W=\\sspan\\set{1,x,x^2}$ be the subspace of $V$ consisting of\n  polynomials of degree at most 2. What we are looking for is an\n  element $g\\in W$ such that $\\norm{f-g}$ is as small as possible.  We\n  can solve this problem using\n  Proposition~\\ref{prop:projection-subspace}.\n\n  First we need an orthogonal basis for $W$. We found such an\n  orthogonal basis in Example~\\ref{exa:legendre-polynomials}, namely\n  the Legendre polynomials $p_0(x) = 1$, $p_1(x) = x$, and\n  $p_2(x) = x^2-\\frac{1}{3}$.  By\n  Proposition~\\ref{prop:projection-subspace}, the desired\n  approximation $g\\in W$ is given by:\n  \\begin{equation*}\n    g\n    ~=~\n    \\frac{\\iprod{p_0,f}}{\\iprod{p_0,p_0}}\\,p_0\n    + \\frac{\\iprod{p_1,f}}{\\iprod{p_1,p_1}}\\,p_1\n    + \\frac{\\iprod{p_2,f}}{\\iprod{p_2,p_2}}\\,p_2.\n  \\end{equation*}\n  We already computed the inner products $\\iprod{p_0,p_0}=2$,\n  $\\iprod{p_1,p_1}=\\frac{2}{3}$, and $\\iprod{p_2,p_2}=\\frac{8}{45}$ in\n  Example~\\ref{exa:legendre-polynomials}. We calculate the remaining\n  inner products:\n  \\begin{eqnarray*}\n    \\iprod{p_0,f}\n    &=& \\int_{-1}^{1} 1\\cdot f(x)\\,dx\n        ~=~ \\int_{-1}^{0} 1\\cdot (1+x)\\,dx\n        +   \\int_{0}^{1} 1\\cdot (1-x)\\,dx\n        ~=~ \\frac{1}{2} + \\frac{1}{2}\n        ~=~ 1, \\\\\n    \\iprod{p_1,f}\n    &=& \\int_{-1}^{1} x\\cdot f(x)\\,\\,dx\n        ~=~ \\int_{-1}^{0} x\\cdot (1+x)\\,\\,dx\n        +   \\int_{0}^{1} x\\cdot (1-x)\\,\\,dx\n        ~=~ -\\frac{1}{6} + \\frac{1}{6}\n        ~=~ 0, \\\\\n    \\iprod{p_2,f}\n    &=& \\int_{-1}^{1} (x^2-\\frac{1}{3})\\cdot f(x)\\,dx \\\\\n    &=& \\int_{-1}^{0} (x^2-\\frac{1}{3})\\cdot (1+x)\\,dx\n        +   \\int_{0}^{1} (x^2-\\frac{1}{3})\\cdot (1-x)\\,dx\n        ~=~ - \\frac{1}{12} - \\frac{1}{12}\n        ~=~ -\\frac{1}{6}.\n  \\end{eqnarray*}\n  Therefore,\n  \\begin{eqnarray*}\n    g\n    &=&\n    \\frac{\\iprod{p_0,f}}{\\iprod{p_0,p_0}}\\,p_0\n        + \\frac{\\iprod{p_1,f}}{\\iprod{p_1,p_1}}\\,p_1\n        + \\frac{\\iprod{p_2,f}}{\\iprod{p_2,p_2}}\\,p_2\n    \\\\\n    &=& \\frac{1}{2}\\,p_0\n        + \\frac{0}{2/3}\\,p_1\n        - \\frac{1/6}{8/45}\\,p_2\n    \\\\\n    &=& \\frac{1}{2}\n        - \\frac{15}{16}(x^2-\\frac{1}{3})\n    \\\\\n    &=& \\frac{13}{16} - \\frac{15}{16}x^2.\n  \\end{eqnarray*}\n  The following graph shows the function $f(x)$ as well as the\n  polynomial $g(x)$:\n  \\begin{center}\n    \\begin{tikzpicture}[domain=-1:1, scale=3, samples=25]\n      \\def\\fA#1{1}\n      \\def\\fC#1{(abs((#1)^2)-1/3)}\n      \\draw[thick,color=fourier0] (-1,0) -- (0,1) -- (1,0);\n      \\draw[thick,color=fourier2] plot (\\x,{0.5*\\fA{\\x} - 0.9375*\\fC{\\x}});\n      \\path[color=fourier2t] (0.6,0.6) node[right]{$g(x)= \\frac{13}{16} - \\frac{15}{16}x^2$};\n      \\path[color=fourier0t] (0.2,0.9) node[right]{$f(x) = 1-\\abs{x}$};\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{solution}\n\nWhen approximating a function $f$ by a polynomial, as in the last\nexample, there is no need to stop with polynomials of degree 2. We can\nalso ask what is the best approximation%\n\\index{approximation!of functions} of $f$ by a polynomial of\ndegree 3, of degree 4, of degree 5, and so on. By increasing the\ndegree of the polynomials, we get better and better approximations to\n$f$. This leads us to the concept of a generalized Fourier series.\n\n\\begin{definition}{Generalized Fourier series}{generalized-fourier-series}\n  Let $V$ be an inner product space and let\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\ldots}$ be an infinite\n  orthogonal set of vectors.  Let $\\vect{v}\\in V$. The\n  \\textbf{generalized Fourier series}%\n  \\index{generalized Fourier series}%\n  \\index{Fourier series!generalized}%\n  \\index{series!Fourier series} of $\\vect{v}$ (with respect to\n  $\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\ldots$) consists of the following\n  sequence of vectors:\n  \\begin{eqnarray*}\n    \\vect{v}_1\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1, \\\\\n    \\vect{v}_2\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n        + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2, \\\\\n    \\vect{v}_3\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n        + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n        + \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\iprod{\\vect{u}_3,\\vect{u}_3}}\\,\\vect{u}_3, \\\\\n    \\vect{v}_4\n    &=& \\frac{\\iprod{\\vect{u}_1,\\vect{v}}}{\\iprod{\\vect{u}_1,\\vect{u}_1}}\\,\\vect{u}_1\n        + \\frac{\\iprod{\\vect{u}_2,\\vect{v}}}{\\iprod{\\vect{u}_2,\\vect{u}_2}}\\,\\vect{u}_2\n        + \\frac{\\iprod{\\vect{u}_3,\\vect{v}}}{\\iprod{\\vect{u}_3,\\vect{u}_3}}\\,\\vect{u}_3\n        + \\frac{\\iprod{\\vect{u}_4,\\vect{v}}}{\\iprod{\\vect{u}_4,\\vect{u}_4}}\\,\\vect{u}_4, \\\\\n    &\\vdots        &\n  \\end{eqnarray*}\n  The vectors $\\vect{v}_i$ are also called \\textbf{generalized Fourier\n    approximations}%\n  \\index{Fourier approximation}%\n  \\index{approximation!Fourier} of $\\vect{v}$.\n\\end{definition}\n\nBy Proposition~\\ref{prop:projection-subspace}, we know that each\n$\\vect{v}_i$ is the best approximation of $\\vect{v}$ in the subspace\n$\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_i}$. In particular,\n$\\norm{\\vect{v}-\\vect{v}_{i+1}} \\leq \\norm{\\vect{v}-\\vect{v}_i}$, so\neach $\\vect{v}_i$ is potentially a better approximation of $\\vect{v}$\nthan the previous one. In a course on analysis%\n\\footnote{``Algebra'' is the name for those subjects where all sums\n  are finite. This includes, for example, linear algebra and abstract\n  algebra. ``Analysis'' is the name for those subjects where sums are\n  potentially infinite (and may or may not converge). This includes,\n  for example, calculus, complex analysis, and functional analysis.},\nyou will learn that in many situations, the sequence\n$\\vect{v}_1,\\vect{v}_2,\\vect{v}_3,\\ldots$ can be shown to converge to\n$\\vect{v}$.\n\n\\begin{example}{Generalized Fourier series}{generalized-fourier-series}\n  Proceeding as in Example~\\ref{exa:projection-subspace-polynomial},\n  find the generalized Fourier approximations of $f(x)=1-\\abs{x}$ up\n  to degree 8.\n\\end{example}\n\n\\begin{solution}\n  We use the Legendre polynomials $p_0,\\ldots,p_8$ from\n  Section~\\ref{sec:gram-schmidt} and calculate the relevant inner\n  products, each of which requires solving an integral. As these\n  integrals get a bit complicated, it is best to use a computer\n  algebra system to compute them.\n  \\begin{equation*}\n    \\def\\arraystretch{1.4}\n    \\begin{array}{rcl}\n      \\iprod{p_0,f} &=& 1, \\\\\n      \\iprod{p_1,f} &=& 0, \\\\\n      \\iprod{p_2,f} &=& -\\frac{1}{6}, \\\\\n      \\iprod{p_3,f} &=& 0, \\\\\n      \\iprod{p_4,f} &=& \\frac{1}{105}, \\\\\n      \\iprod{p_5,f} &=& 0, \\\\\n      \\iprod{p_6,f} &=& -\\frac{1}{924}, \\\\\n      \\iprod{p_7,f} &=& 0, \\\\\n      \\iprod{p_8,f} &=& \\frac{1}{6435}, \\\\\n    \\end{array}\n    \\quad\n    \\begin{array}{rcl}\n      \\iprod{p_0,p_0} &=& 2, \\\\\n      \\iprod{p_1,p_1} &=& \\frac{2}{3}, \\\\\n      \\iprod{p_2,p_2} &=& \\frac{8}{45}, \\\\\n      \\iprod{p_3,p_3} &=& \\frac{8}{175}, \\\\\n      \\iprod{p_4,p_4} &=& \\frac{128}{11025}, \\\\\n      \\iprod{p_5,p_5} &=& \\frac{128}{43659}, \\\\\n      \\iprod{p_6,p_6} &=& \\frac{512}{693693}, \\\\\n      \\iprod{p_7,p_7} &=& \\frac{512}{2760615}, \\\\\n      \\iprod{p_8,p_8} &=& \\frac{32768}{703956825}. \\\\\n    \\end{array}\n  \\end{equation*}\n  We therefore have the following approximations:\n  \\begin{eqnarray*}\n    f_0 &=& f_1 ~~=~~\n            \\frac{1}{2}\\,p_0,\n    \\\\\n    f_2 &=& f_3 ~~=~~\n            \\frac{1}{2}\\,p_0\n            - \\frac{15}{16}\\,p_2,\n    \\\\\n    f_4 &=& f_5 ~~=~~\n            \\frac{1}{2}\\,p_0\n            - \\frac{15}{16}\\,p_2\n            + \\frac{105}{128}\\,p_4,\n    \\\\\n    f_6 &=& f_7 ~~=~~\n            \\frac{1}{2}\\,p_0\n            - \\frac{15}{16}\\,p_2\n            + \\frac{105}{128}\\,p_4\n            - \\frac{3003}{2048}\\,p_6,\n    \\\\\n    f_8 &=& f_9 ~~=~~\n            \\frac{1}{2}\\,p_0\n            - \\frac{15}{16}\\,p_2\n            + \\frac{105}{128}\\,p_4\n            - \\frac{3003}{2048}\\,p_6\n            + \\frac{109395}{32768}\\,p_8.\n  \\end{eqnarray*}\n  The following graph shows the function $f$ as well as its\n  approximations $f_0$, $f_2$, $f_4$, $f_6$, and $f_8$. It can be seen\n  that each successive approximation is closer to the function $f$\n  than the previous one.\n  \\begin{center}\n    \\begin{tikzpicture}[domain=-1:1, scale=4, 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,0) -- (0,1) -- (1,0);\n      \\path[color=fourier0t] (0,1) node[right=2ex] {$f$};\n      \\draw[thick,color=fourier1] plot (\\x,0.5*\\fA{\\x}) (1,0.5) node[right=1ex,color=fourier1t] {$f_0$};\n      \\draw[thick,color=fourier2] plot (\\x,{0.5*\\fA{\\x} - 0.9375*\\fC{\\x}}) (1,-0.18) node[right=1ex,color=fourier2t] {$f_2$};\n      \\draw[thick,color=fourier4,samples=50] plot (\\x,{0.5*\\fA{\\x} - 0.9375*\\fC{\\x} + 0.8203125*\\fE{\\x}}) (1,0.18) node[right=1ex,color=fourier4t] {$f_4$};\n      \\draw[thick,color=fourier5,samples=50] plot (\\x,{0.5*\\fA{\\x} - 0.9375*\\fC{\\x} + 0.8203125*\\fE{\\x} -1.46630859375*\\fG{\\x}}) (1,-0.06) node[right=1ex,color=fourier5t] {$f_6$};\n      \\draw[thick,color=fourier6,samples=75] plot (\\x,{0.5*\\fA{\\x} - 0.9375*\\fC{\\x} + 0.8203125*\\fE{\\x} -1.46630859375*\\fG{\\x}+3.338470458984375*\\fI{\\x}}) (1,0.06) node[right=1ex,color=fourier6t] {$f_8$};\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{solution}\n\n\\begin{example}{Generalized Fourier series}{generalized-fourier-series2}\n  The following graph shows the generalized Fourier approximations of\n  the function\n  \\begin{equation*}\n    f(x) ~=~ \\begin{cases}\n      0 & \\mbox{if $x<0$,} \\\\\n      1 & \\mbox{if $x\\geq 0$}\n    \\end{cases}\n  \\end{equation*}\n  by polynomials up to degree 7. (Note: the function $f$ is not\n  continuous, so not technically an element of $C[-1,1]$, but we\n  ignore this here. Instead of the vector space of continuous\n  functions, we can work in the vector space of piecewise continuous\n  functions).\n\\end{example}\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=-1:1, scale=4, 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,0) -- (0,0) -- (0,1) -- (1,1);\n    \\path[color=fourier0t] (0.1,1) node[above] {$f$};\n    \\draw[thick,color=fourier1] plot (\\x,0.5*\\fA{\\x}) (1,0.5) node[right=1ex,color=fourier1t] {$f_0$};\n    \\draw[thick,color=fourier2]     plot (\\x,{0.5*\\fA{\\x} + 0.75*\\fB{\\x}}) (1,1.24) node[right=1ex,color=fourier2t] {$f_1$};\n    \\draw[thick,color=fourier4,samples=50]   plot (\\x,{0.5*\\fA{\\x} + 0.75*\\fB{\\x} - 1.09375*\\fD{\\x}}) (1,0.82) node[right=1ex,color=fourier4t] {$f_3$};\n    \\draw[thick,color=fourier5,samples=50]       plot (\\x,{0.5*\\fA{\\x} + 0.75*\\fB{\\x} - 1.09375*\\fD{\\x} + 2.70703125*\\fF{\\x}}) (1,1.10) node[right=1ex,color=fourier5t] {$f_5$};\n    \\draw[thick,color=fourier6,samples=75]      plot (\\x,{0.5*\\fA{\\x} + 0.75*\\fB{\\x} - 1.09375*\\fD{\\x} + 2.70703125*\\fF{\\x} - 7.855224609375*\\fH{\\x}}) (1,0.96) node[right=1ex,color=fourier6t] {$f_7$};\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\nComparing the last two examples, we see that the function in\nExample~\\ref{exa:generalized-fourier-series2} is much harder to\napproximate well by polynomials. This is due to the discontinuity in\nthe latter function. Nevertheless, the sequence of approximations\neventually converges to $f$.\n\n\\begin{example}{Generalized Fourier series}{generalized-fourier-series3}\n  The following graph shows the generalized Fourier approximations of\n  the function\n  \\begin{equation*}\n    f(x) ~=~ \\begin{cases}\n      0 & \\mbox{if $x<-\\frac{1}{2}$,} \\\\\n      x+\\frac{1}{2} & \\mbox{if $-\\frac{1}{2}\\leq x<\\frac{1}{2}$,} \\\\\n      1 & \\mbox{if $x\\geq \\frac{1}{2}$} \\\\\n    \\end{cases}\n  \\end{equation*}\n  by polynomials up to degree 7.\n\\end{example}\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=-1:1, scale=4, 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,0) -- (-0.5,0) -- (0.5,1) -- (1,1);\n    \\path[color=fourier0t] (0.5,1) node[above] {$f$};\n    \\draw[thick,color=fourier1] plot (\\x,0.5*\\fA{\\x}) (1,0.5) node[right=1ex,color=fourier1t] {$f_0$};\n    \\draw[thick,color=fourier3]     plot (\\x,{0.5*\\fA{\\x} + 0.6875*\\fB{\\x}}) (1,1.2) node[right=1ex,color=fourier3t] {$f_1$};\n    \\draw[thick,color=fourier4,samples=50]   plot (\\x,{0.5*\\fA{\\x} + 0.6875*\\fB{\\x} - 0.615234375*\\fD{\\x}}) (1,0.9) node[right=1ex,color=fourier4t] {$f_3$};\n    \\draw[thick,color=fourier5]       plot (\\x,{0.5*\\fA{\\x} + 0.6875*\\fB{\\x} - 0.615234375*\\fD{\\x} + 0.38067626953125*\\fF{\\x}}) (1,1.0) node[right=1ex,color=fourier5t] {$f_5$};\n    \\draw[thick,color=fourier6,samples=50]      plot (\\x,{0.5*\\fA{\\x} + 0.6875*\\fB{\\x} - 0.615234375*\\fD{\\x} + 0.38067626953125*\\fF{\\x} + 1.0494089126587303*\\fH{\\x}}) (1,1.1) node[right=1ex,color=fourier6t] {$f_7$};\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\nSo far, we have worked with Legendre polynomials, but there are of\ncourse other examples of orthogonal sets of functions. An important\nsuch set is given by sine and cosine waves. We will see that every\nperiodic function can be decomposed into sine and cosine waves of\nvarying frequencies. This was Fourier's original discovery, and the\ncorresponding series are just known as \\textbf{Fourier series}%\n\\index{Fourier series}%\n\\index{series!Fourier series} (i.e., not ``generalized'').\n\n\\begin{example}{Fourier series}{fourier-series}\n  Consider the inner product space $C[0,2\\pi]$. Recall from\n  Example~\\ref{exa:orthogonal-set-sin-cos} that the following\n  functions form an orthogonal set:\n  \\begin{eqnarray*}\n    \\vect{u}_0 &=& 1 \\\\\n    \\vect{u}_1 &=& \\sin x \\\\\n    \\vect{u}_2 &=& \\cos x \\\\\n    \\vect{u}_3 &=& \\sin 2x \\\\\n    \\vect{u}_4 &=& \\cos 2x \\\\\n    \\vect{u}_5 &=& \\sin 3x \\\\\n    \\vect{u}_6 &=& \\cos 3x \\\\\n    &\\vdots&\n  \\end{eqnarray*}\n  Consider the function $f(x) = x - \\pi$, where $x\\in[0,2\\pi]$. Find\n  its Fourier series.\n\\end{example}\n\n\\begin{solution}\n  Following Definition~\\ref{def:generalized-fourier-series}, we must\n  calculate a number of inner products. We have\n  $\\iprod{\\vect{u}_0,\\vect{u}_0}=2\\pi$. Also, for all $i\\geq 1$, we\n  have $\\iprod{\\vect{u}_i,\\vect{u}_i}=\\pi$. We note the following\n  antiderivatives, for $k\\geq 1$:\n  \\begin{equation*}\n    \\int x\\sin kx\\,dx ~=~ -\\frac{x}{k}\\cos kx + \\frac{1}{k^2}\\sin kx, \\qquad\n    \\int x\\cos kx\\,dx ~=~ \\frac{x}{k}\\sin kx + \\frac{1}{k^2}\\cos kx.\n  \\end{equation*}\n  Using these formulas, we can compute the following inner products\n  quite easily:\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u}_0, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\n        ~~=~~ 0, \\\\\n    \\iprod{\\vect{u}_1, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\sin x\n        \\,~~=~~ -2\\pi, \\\\\n    \\iprod{\\vect{u}_2, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\cos x\n        ~~=~~ 0, \\\\\n    \\iprod{\\vect{u}_3, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\sin 2x\n        \\,~~=~~ -\\frac{2\\pi}{2}, \\\\\n    \\iprod{\\vect{u}_4, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\cos 2x\n        ~~=~~ 0, \\\\\n    \\iprod{\\vect{u}_5, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\sin 3x\n        \\,~~=~~ -\\frac{2\\pi}{3}, \\\\\n    \\iprod{\\vect{u}_6, f}\n    &=& \\int_{0}^{2\\pi} (x-\\pi)\\cos 3x\n        ~~=~~ 0,\n  \\end{eqnarray*}\n  and so on. We therefore find the following Fourier series:\n  \\begin{eqnarray*}\n    f_1 &=& -2 \\sin x, \\\\\n    f_3 &=& -2 \\sin x - \\frac{2}{2}\\sin 2x, \\\\\n    f_5 &=& -2 \\sin x - \\frac{2}{2}\\sin 2x - \\frac{2}{3}\\sin 3x, \\\\\n    f_7 &=& -2 \\sin x - \\frac{2}{2}\\sin 2x - \\frac{2}{3}\\sin 3x - \\frac{2}{4}\\sin 4x, \\\\\n    f_9 &=& -2 \\sin x - \\frac{2}{2}\\sin 2x - \\frac{2}{3}\\sin 3x - \\frac{2}{4}\\sin 4x - \\frac{2}{5}\\sin 5x,\n  \\end{eqnarray*}\n  and so on.\n\\end{solution}\n\nThe following graph illustrates the successive approximations of this\nFourier series.\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.8, samples=100]\n    \\def\\fA#1{1}\n    \\def\\fB#1{(sin((#1)/pi*180))}\n    \\def\\fC#1{(cos((#1)/pi*180))}\n    \\def\\fD#1{(sin(2*(#1)/pi*180))}\n    \\def\\fE#1{(cos(2*(#1)/pi*180))}\n    \\def\\fF#1{(sin(3*(#1)/pi*180))}\n    \\def\\fG#1{(cos(3*(#1)/pi*180))}\n    \\def\\fH#1{(sin(4*(#1)/pi*180))}\n    \\def\\fI#1{(cos(4*(#1)/pi*180))}\n    \\draw[thick,color=fourier0] (0,0) -- (0,-pi) -- (2*pi,pi) -- (2*pi,-pi) -- (4*pi,pi) -- (4*pi,-pi) -- (6*pi, pi) -- (6*pi, 0) (2*pi, pi) node[right,color=fourier0t] {$f$};\n    \\draw[thick,color=fourier1]                 plot (\\x,{((-2)*\\fB{\\x})}) (pi,0) +(0.6*pi,0.6*pi) node[left=4ex,color=fourier1t] {$f_1$};\n    \\draw[thick,color=fourier4,samples=200] plot (\\x,{((-2)*\\fB{\\x})+((-1)*\\fD{\\x})}) (pi,0) +(0.75*pi,0.75*pi) node[left=4ex,color=fourier4t] {$f_3$};\n    \\draw[thick,color=fourier5,samples=200]       plot (\\x,{((-2)*\\fB{\\x})+((-1)*\\fD{\\x})+((-2/3)*\\fF{\\x})}) (pi,0) +(0.9*pi,0.9*pi) node[left=4ex,color=fourier5t] {$f_5$};\n    \\draw[thick,color=fourier6,samples=300]      plot (\\x,{((-2)*\\fB{\\x})+((-1)*\\fD{\\x})+((-2/3)*\\fF{\\x})+((-1/2)*\\fH{\\x})}) (pi,0) +(1.05*pi,1.05*pi) node[left=4ex,color=fourier6t] {$f_7$};\n    \\draw[->] (-0.8,0) -- (6*pi+0.8,0) node[right] {$x$};\n    \\draw[->] (0,-3.5) -- (0,3.5);\n    \\draw (pi,0) -- (pi,-0.05) node[below] {$\\pi$};\n    \\draw (2*pi,0) -- (2*pi,-0.05) node[below] {$2\\pi$};\n    \\draw (3*pi,0) -- (3*pi,-0.05) node[below] {$3\\pi$};\n    \\draw (4*pi,0) -- (4*pi,-0.05) node[below] {$4\\pi$};\n    \\draw (5*pi,0) -- (5*pi,-0.05) node[below] {$5\\pi$};\n    \\draw (6*pi,0) -- (6*pi,-0.05) node[below] {$6\\pi$};\n  \\end{tikzpicture}\n\\end{center}\nNote that, although the function $f$ is defined on the interval\n$[0,2\\pi]$, we have extended it periodically for $[2\\pi,4\\pi]$,\n$[4\\pi,6\\pi]$, and so on. This makes sense because all of the\northogonal functions $1$, $\\sin x$, $\\cos x$, $\\sin 2x$, and so on,\nhave period $2\\pi$.\n\nWe can also illustrate the same information differently, by showing\nthe individual sine waves making up the wave form of the function\n$f(x)$. In the context of audio signals, these sine waves are also\ncalled the \\textbf{harmonics}%\n\\index{harmonic} of the signal.\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.3, samples=100]\n    \\def\\fA#1{1}\n    \\def\\fB#1{(sin((#1)/pi*180))}\n    \\def\\fC#1{(cos((#1)/pi*180))}\n    \\def\\fD#1{(sin(2*(#1)/pi*180))}\n    \\def\\fE#1{(cos(2*(#1)/pi*180))}\n    \\def\\fF#1{(sin(3*(#1)/pi*180))}\n    \\def\\fG#1{(cos(3*(#1)/pi*180))}\n    \\def\\fH#1{(sin(4*(#1)/pi*180))}\n    \\def\\fI#1{(cos(4*(#1)/pi*180))}\n    \\begin{scope}[yshift=-12cm,xshift=-29cm]\n      \\draw[thick,color=fourier0] (0,0) -- (0,-pi) -- (2*pi,pi) -- (2*pi,-pi) --\n      (4*pi,pi) -- (4*pi,-pi) -- (6*pi, pi) -- (6*pi, 0);\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0) node[right]{$~~=~~\\left\\{\\rule{0mm}{3cm}\\right.$};\n    \\end{scope}\n    \\begin{scope}[yshift=-4cm]\n      \\draw[thick,color=fourier1]   plot (\\x,{((-2)*\\fB{\\x})}) node[right=2ex,color=fourier1t] {$-\\frac{2}{1}\\sin(x)$};\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-8cm]\n      \\draw[thick,color=fourier4] plot (\\x,{((-1)*\\fD{\\x})}) node[right=2ex,color=fourier4t] {$-\\frac{2}{2}\\sin(2x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-12cm]\n      \\draw[thick,color=fourier5,samples=200]     plot (\\x,{((-2/3)*\\fF{\\x})}) node[right=2ex,color=fourier5t] {$-\\frac{2}{3}\\sin(3x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-16cm]\n      \\draw[thick,color=fourier6,samples=200]    plot (\\x,{((-1/2)*\\fH{\\x})}) node[right=2ex,color=fourier6t] {$-\\frac{2}{4}\\sin(4x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-20cm]\n      \\path (-1.5,0) node[left]{$+$} node[right]{$\\cdots$};\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{center}\n\n\\begin{example}{Fourier series}{fourier-series2}\n  The following graph shows the first few Fourier approximations of the function\n  \\begin{equation*}\n    f(x) ~=~ \\begin{cases}\n      x - \\frac{\\pi}{2} & \\mbox{if $0\\leq x<\\pi$,} \\\\\n      \\frac{3\\pi}{2} - x & \\mbox{if $\\pi\\leq x\\leq 2\\pi$.}\n    \\end{cases}\n  \\end{equation*}\n\\end{example}\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.8, samples=100]\n    \\def\\fC#1{(cos((#1)/pi*180))}\n    \\def\\fG#1{(cos(3*(#1)/pi*180))}\n    \\def\\fK#1{(cos(5*(#1)/pi*180))}\n    \\def\\fO#1{(cos(7*(#1)/pi*180))}\n    \\draw[thick,color=fourier0] (0,-pi/2) -- (pi,pi/2) -- (2*pi,-pi/2) -- (3*pi,pi/2) -- (4*pi,-pi/2) -- (5*pi,pi/2) -- (6*pi, -pi/2) (pi,pi/2) node [above,color=fourier0t] {$f$};\n    \\draw[thick,color=fourier1]   plot (\\x,{((-1.2732395447351623)*\\fC{\\x})}) (0.6*pi,-pi/2+0.6*pi) node[left=2ex,color=fourier1t] {$f_2$};\n    \\draw[thick,color=fourier4,samples=200] plot (\\x,{((-1.2732395447351623)*\\fC{\\x})+((-0.14147106052612904)*\\fG{\\x})}) (0.75*pi,-pi/2+0.75*pi) node[left=2ex,color=fourier4t] {$f_4$};\n    \\draw[thick,color=fourier5,samples=200]     plot (\\x,{((-1.2732395447351623)*\\fC{\\x})+((-0.14147106052612904)*\\fG{\\x})+((-0.05092958178940641)*\\fK{\\x})}) (0.9*pi,-pi/2+0.9*pi) node[left=2ex,color=fourier5t] {$f_6$};\n    \\draw[thick,color=fourier6,samples=200]    plot (\\x,{((-1.2732395447351623)*\\fC{\\x})+((-0.14147106052612904)*\\fG{\\x})+((-0.05092958178940641)*\\fK{\\x})+((-0.025984480504798825)*\\fO{\\x})}) (1.05*pi,-pi/2+1.05*pi) node[left=2ex,color=fourier6t] {$f_8$};\n    \\draw[->] (-0.8,0) -- (6*pi+0.8,0) node[right] {$x$};\n    \\draw[->] (0,-2) -- (0,2);\n    \\draw (pi,0) -- (pi,-0.05) node[below] {$\\pi$};\n    \\draw (2*pi,0) -- (2*pi,-0.05) node[below] {$2\\pi$};\n    \\draw (3*pi,0) -- (3*pi,-0.05) node[below] {$3\\pi$};\n    \\draw (4*pi,0) -- (4*pi,-0.05) node[below] {$4\\pi$};\n    \\draw (5*pi,0) -- (5*pi,-0.05) node[below] {$5\\pi$};\n    \\draw (6*pi,0) -- (6*pi,-0.05) node[below] {$6\\pi$};\n  \\end{tikzpicture}\n\\end{center}\n\n\\noindent Note how rapidly this Fourier series converges to $f$. The\nfollowing image shows the function $f$ (extended periodically outside\nthe interval $[0,2\\pi]$) as a sum of its harmonics. Compared to\nExample~\\ref{exa:fourier-series}, we see that the higher harmonics\nhave much smaller amplitudes, which explains the rapid convergence.\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.3, samples=100]\n    \\def\\fC#1{(cos((#1)/pi*180))}\n    \\def\\fG#1{(cos(3*(#1)/pi*180))}\n    \\def\\fK#1{(cos(5*(#1)/pi*180))}\n    \\def\\fO#1{(cos(7*(#1)/pi*180))}\n    \\begin{scope}[yshift=-12cm,xshift=-29cm]\n      \\draw[thick,color=fourier0] (0,-pi/2) -- (pi,pi/2) -- (2*pi,-pi/2) -- (3*pi,pi/2) --\n      (4*pi,-pi/2) -- (5*pi,pi/2) -- (6*pi, -pi/2);\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0) node[right]{$~~=~~\\left\\{\\rule{0mm}{3cm}\\right.$};\n    \\end{scope}\n    \\begin{scope}[yshift=-4cm]\n      \\draw[thick,color=fourier1]   plot (\\x,{((-1.2732395447351623)*\\fC{\\x})}) (6*pi,0) node[right=2ex,color=fourier1t] {$-\\frac{4}{\\pi}cos(x)$};\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-8cm]\n      \\draw[thick,color=fourier4] plot (\\x,{((-0.14147106052612904)*\\fG{\\x})}) (6*pi,0) node[right=2ex,color=fourier4t] {$-\\frac{4}{9\\pi}\\cos(3x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-12cm]\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n      \\draw[thick,color=fourier5]     plot (\\x,{((-0.05092958178940641)*\\fK{\\x})}) (6*pi,0) node[right=2ex,color=fourier5t] {$-\\frac{4}{25\\pi}\\cos(5x)$};\n    \\end{scope}\n    \\begin{scope}[yshift=-16cm]\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n      \\draw[thick,color=fourier6]    plot (\\x,{((-0.025984480504798825)*\\fO{\\x})}) (6*pi,0) node[right=2ex,color=fourier6t] {$-\\frac{4}{49\\pi}\\cos(7x)$};\n    \\end{scope}\n    \\begin{scope}[yshift=-20cm]\n      \\path (-1.5,0) node[left]{$+$} node[right]{$\\cdots$};\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{center}\n\n\\begin{example}{Fourier series}{fourier-series3}\n  The following graph shows the first few Fourier approximations of the function\n  \\begin{equation*}\n    f(x) ~=~ \\begin{cases}\n      1 & \\mbox{if $0\\leq x<\\pi$,} \\\\\n      -1 & \\mbox{if $\\pi\\leq x\\leq 2\\pi$.}\n    \\end{cases}\n  \\end{equation*}\n\\end{example}\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.8, samples=100]\n    \\def\\fB#1{(sin((#1)/pi*180))}\n    \\def\\fF#1{(sin(3*(#1)/pi*180))}\n    \\def\\fJ#1{(sin(5*(#1)/pi*180))}\n    \\def\\fN#1{(sin(7*(#1)/pi*180))}\n    \\draw[thick,color=fourier0] (0,0) -- (0,1) -- (pi,1) -- (pi,-1) --\n    (2*pi,-1) -- (2*pi,1) --\n    (3*pi,1) -- (3*pi,-1) --\n    (4*pi,-1) -- (4*pi,1) --\n    (5*pi,1) -- (5*pi,-1) --\n    (6*pi,-1) -- (6*pi,0) (pi, 1) node[right,color=fourier0t] {$f$};\n    \\draw[thick,color=fourier1]   plot (\\x,{((1.2732395447351623)*\\fB{\\x})}) (0.4*pi, 1.2) node[above,color=fourier1t] {$f_1$};\n    \\draw[thick,color=fourier4,samples=200] plot (\\x,{((1.2732395447351623)*\\fB{\\x})+((0.4244131815783881)*\\fF{\\x})}) (0.6*pi, 1.2) node[above,color=fourier4t] {$f_3$};\n    \\draw[thick,color=fourier5,samples=200]     plot (\\x,{((1.2732395447351623)*\\fB{\\x})+((0.4244131815783881)*\\fF{\\x})+((0.25464790894703326)*\\fJ{\\x})}) (0.8*pi, 1.2) node[above,color=fourier5t] {$f_5$};\n    \\draw[thick,color=fourier6,samples=300]    plot (\\x,{((1.2732395447351623)*\\fB{\\x})+((0.4244131815783881)*\\fF{\\x})+((0.25464790894703326)*\\fJ{\\x})+((0.18189136353359486)*\\fN{\\x})}) (1.0*pi, 1.2) node[above,color=fourier6t] {$f_7$};\n    \\draw[->] (-0.8,0) -- (6*pi+0.8,0) node[right] {$x$};\n    \\draw[->] (0,-2) -- (0,2);\n    \\draw (pi,0) -- (pi,-0.05) node[below] {$\\pi$};\n    \\draw (2*pi,0) -- (2*pi,-0.05) node[below] {$2\\pi$};\n    \\draw (3*pi,0) -- (3*pi,-0.05) node[below] {$3\\pi$};\n    \\draw (4*pi,0) -- (4*pi,-0.05) node[below] {$4\\pi$};\n    \\draw (5*pi,0) -- (5*pi,-0.05) node[below] {$5\\pi$};\n    \\draw (6*pi,0) -- (6*pi,-0.05) node[below] {$6\\pi$};\n  \\end{tikzpicture}\n\\end{center}\n\n\\noindent Once again, here is an image showing the function $f$ as a\nsum of its harmonics:\n\n\\begin{center}\n  \\begin{tikzpicture}[domain=0:6*pi, scale=0.3, samples=100]\n    \\def\\fB#1{(sin((#1)/pi*180))}\n    \\def\\fF#1{(sin(3*(#1)/pi*180))}\n    \\def\\fJ#1{(sin(5*(#1)/pi*180))}\n    \\def\\fN#1{(sin(7*(#1)/pi*180))}\n    \\begin{scope}[yshift=-12cm,xshift=-29cm]\n      \\draw[thick,color=fourier0] (0,0) -- (0,1) -- (pi,1) -- (pi,-1) --\n      (2*pi,-1) -- (2*pi,1) --\n      (3*pi,1) -- (3*pi,-1) --\n      (4*pi,-1) -- (4*pi,1) --\n      (5*pi,1) -- (5*pi,-1) --\n      (6*pi,-1) -- (6*pi,0);\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0)\n      node[right]{$~~=~~\\left\\{\\rule{0mm}{3cm}\\right.$};\n    \\end{scope}\n    \\begin{scope}[yshift=-4cm]\n      \\draw[thick,color=fourier1]   plot (\\x,{((1.2732395447351623)*\\fB{\\x})}) node[right=2ex,color=fourier1t] {$\\frac{4}{\\pi}\\sin(x)$};\n      \\draw[->] (-1.5,0) -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-8cm]\n      \\draw[thick,color=fourier4] plot (\\x,{((0.4244131815783881)*\\fF{\\x})}) node[right=2ex,color=fourier4t] {$\\frac{4}{3\\pi}\\sin(3x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-12cm]\n      \\draw[thick,color=fourier5,samples=150]     plot (\\x,{((0.25464790894703326)*\\fJ{\\x})}) node[right=2ex,color=fourier5t] {$\\frac{4}{5\\pi}\\sin(5x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-16cm]\n      \\draw[thick,color=fourier6,samples=200]    plot (\\x,{((0.18189136353359486)*\\fN{\\x})}) node[right=2ex,color=fourier6t] {$\\frac{4}{7\\pi}\\sin(7x)$};\n      \\draw[->] (-1.5,0) node[left]{$+$} -- (6*pi+1.5,0);\n    \\end{scope}\n    \\begin{scope}[yshift=-20cm]\n      \\path (-1.5,0) node[left]{$+$} node[right]{$\\cdots$};\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{center}\n\n\\noindent\nWatch the video at \\url{http://y2u.be/3IAMpH4xF9Q} for a demonstration\nof what the functions from\nExamples~\\ref{exa:fourier-series}--\\ref{exa:fourier-series3}, and\ntheir harmonics, sound like as audio signals.\n", "meta": {"hexsha": "0ae6f361f108715e31d7733464efb18f32d4997a", "size": 37750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/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/content/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/content/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": 47.0698254364, "max_line_length": 254, "alphanum_fraction": 0.5751523179, "num_tokens": 16160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.6419679277353068}}
{"text": "%---------------------------Condition-----------------------------\n\\section{Condition}\n\n\\[\nq = \\frac{1}{2} \\max \\left\\{  \\frac {\\normvec{L_0}^2 + \\normvec{L_3}^2 } { \\alpha_0 },\n                        \\frac {\\normvec{L_1}^2 + \\normvec{L_0}^2 } { \\alpha_1 },\n                        \\frac {\\normvec{L_2}^2 + \\normvec{L_1}^2 } { \\alpha_2 },\n                        \\frac {\\normvec{L_3}^2 + \\normvec{L_2}^2 } { \\alpha_3 } \n                \\right\\}\n\\]\n\nNote that if $\\alpha_i< DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\quadmetrictable{condition}%\n{$1$}%                                      Dimension\n{$[1,4]$}%                                  Acceptable range\n{$[1,DBL\\_MAX]$}%                           Normal range\n{$[1,DBL\\_MAX]$}%                           Full range\n{$1$}%                                      Unit square\n{\\cite{knu:00}}%                            Citation\n{v\\_quad\\_condition}%                       Verdict function name\n\n", "meta": {"hexsha": "0f10b3d1ff3a896a1be57f4d2a13b8f627b8fd5a", "size": 941, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadCondition.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/QuadCondition.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/QuadCondition.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": 40.9130434783, "max_line_length": 86, "alphanum_fraction": 0.38575983, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6419679257536588}}
{"text": "\\documentclass[letterpaper]{jpconf}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx,wrapfig}\n\\usepackage{hyperref}\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{\\deriv}[2]{\\frac{d #1}{d #2}}\n\\newcommand{\\pderiv}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\vect}[1]{\\boldsymbol{#1}}\n\\newcommand{\\f}[2]{\\frac{#1}{#2}}\n\\newcommand{\\dx}{\\Delta x}\n\\newcommand{\\pd}[2]{\\partial_{#2}{#1}}\n\\newcommand{\\bx}{\\vect{x}}\n\\newcommand{\\bK}{\\vect{K}}\n\\newcommand{\\cT}{\\mathcal{T}}\n\\newcommand{\\xL}{x_{\\textnormal{\\tiny\\textsc{L}}}}\n\\newcommand{\\xH}{x_{\\textnormal{\\tiny\\textsc{H}}}}\n\\newcommand{\\xMin}{x_{\\textnormal{\\tiny m}}}\n\\newcommand{\\xMax}{x_{\\textnormal{\\tiny M}}}\n\\newcommand{\\trans}{\\textnormal{\\tiny\\textsc{T}}}\n\\newcommand{\\leftState}{\\textnormal{\\tiny\\textsc{L}}}\n\\newcommand{\\rightState}{\\textnormal{\\tiny\\textsc{R}}}\n\\newcommand{\\TCI}{\\textnormal{\\tiny\\textsc{TCI}}}\n\\newcommand{\\shock}{\\textnormal{\\tiny\\textsc{Sh}}}\n\\newcommand{\\Pos}{\\textnormal{\\tiny\\textsc{Pos}}}\n\\newcommand{\\TVD}{\\textnormal{\\tiny\\textsc{Tvd}}}\n\\newcommand{\\thornado}{\\texttt{thornado}}\n\\newcommand{\\chimera}{{\\sc Chimera}}\n\n\\newcommand{\\ee}[1]{{\\color{red} EE:~#1}}\n\n\\begin{document}\n\\title{\\thornado-hydro: towards discontinuous Galerkin methods for supernova hydrodynamics\\footnote{This manuscript has been authored by UT-Battelle, LLC under Contract No. DE-AC05-00OR22725 with the U.S. Department of Energy. The United States Government retains and the publisher, by accepting the article for publication, acknowledges that the United States Government retains a non-exclusive, paid-up, irrevocable, world-wide license to publish or reproduce the published form of this manuscript, or allow others to do so, for United States Government purposes. The Department of Energy will provide public access to these results of federally sponsored research in accordance with the DOE Public Access Plan (http://energy.gov/downloads/doe-public-access-plan).}}\n\n\\author{Eirik Endeve$^{1,2,6}$, Jesse Buffaloe$^{2}$, Samuel J Dunham$^{3}$, \\\\ Nick Roberts$^{2}$, Kristopher Andrew$^{4,1}$, Brandon Barker$^{2}$, \\\\ David Pochik$^{2}$, Juliana Pulsinelli$^{5,7}$ and Anthony Mezzacappa$^{2,6}$}\n\\address{$^{1}$Computer Science and Mathematics Division, Oak Ridge National Laboratory, TN 37831}\n\\address{$^{2}$Department of Physics and Astronomy, University of Tennessee Knoxville, TN 37996}\n\\address{$^{3}$Department of Astronomy, Vanderbilt University, TN 37212}\n\\address{$^{4}$Department of Physics and Astronomy, University of Kentucky, Lexington, KY 40506}\n\\address{$^{5}$Princeton University, NJ 08544}\n\\address{$^{6}$Joint Institute for Computational Sciences, Oak Ridge National Laboratory, TN 37831}\n\\address{$^{7}$Physics Division, Oak Ridge National Laboratory, TN 37831}\n\\ead{endevee@ornl.gov}\n\n\\begin{abstract}\nThe {\\bf t}oolkit for {\\bf h}igh-{\\bf or}der {\\bf n}eutrino-r{\\bf ad}iation hydr{\\bf o}dynamics (\\thornado) is being developed for simulations of core-collapse supernovae (CCSNe) and related problems.  \nCurrent capabilities in \\thornado\\ include solvers for the Euler equations --- in non-relativistic and special relativistic limits --- and the two-moment model of neutrino transport.  \nThe spatial discretization in \\thornado\\ is based on the discontinuous Galerkin (DG) method, which is receiving increased attention from the computational astrophysics community.  \nIn this paper, we provide an overview of the numerical methods for the Euler equations in \\thornado, and present some encouraging preliminary numerical results from a set of basic tests in one and two spatial dimensions.  \n\\end{abstract}\n\n\\section{Introduction}\n\nAlong with solvers for neutrino transport and gravity, the hydrodynamics solver constitutes a major component of core-collapse supernova (CCSN) simulations.  \nThe dynamics of the bounce shock and associated fluid instabilities, which drive turbulent flows and help shape the explosion, must be faithfully captured (see, e.g., \\cite{muller_2016}, for a recent review).  \nEssentially, the stellar interior is modeled as a perfect fluid (thermal conduction and viscosity are not explicitly included) using the Euler equations, but the models are extended to accommodate a nuclear equation of state.  \n\nThe discontinuous Galerkin (DG) method \\cite{cockburnShu_2001,hesthavenWarburton_2008} appears as an appealing choice to model fluid flows in CCSNe.  \nDG methods combine elements of spectral and finite volume methods, and achieve high-order accuracy on a compact stencil.  \nData is only communicated with nearest neighbors, regardless of the formal order of accuracy, which leads to a high computation to communication ratio, and favorable parallel scalability on heterogeneous architectures has been demonstrated \\cite{klockner_etal_2009}.  \nThey can be used in combination with $hp$-adaptivity \\cite{remacle_etal_2003}, where, in addition to grid refinement with AMR, the local polynomial degree can be chosen differently, and independently, in different cells.  \nDG methods can easily be applied to problems involving curvilinear coordinates, which is beneficial in numerical relativity \\cite{teukolsky_2016}.  \nCurrently, most hydrodynamics solvers in CCSN codes are based on finite volume methods.  \nExploring the utility and performance of DG methods to model CCSNe seems like a worthy exercise by itself.  \n\nThe {\\bf t}oolkit for {\\bf h}igh-{\\bf or}der {\\bf n}eutrino-r{\\bf ad}iation hydr{\\bf o}dynamics (\\thornado) is being developed to simulate neutrino-radiation hydrodynamics in CCSNe and related applications in nuclear astrophysics.  \nThe spatial discretization of solvers for hyperbolic partial differential equations in \\thornado\\ is based on the DG method, while we foresee using a combination of spectral and continuous finite element methods for solving elliptic equations; e.g., for Newtonian gravity or relativistic gravity employing the conformal flatness approximation \\cite{wilson_etal_1996}.  \nWith these approaches, we employ high-order discretization techniques based on a common mathematical framework in all the major model components.  \nWhether the high-order approach will improve accuracy and efficiency of CCSN models remains to be demonstrated.  \nHowever, in this paper, we provide an initial description and encouraging demonstration of the DG method implemented in \\thornado\\ to solve the Euler equations.  \nWe focus on basic tests in one and two spatial dimensions and focus, to some extent, on the implementation of limiters in \\thornado.  \nWe note that others (e.g., \\cite{radiceRezzolla_2011,schaal_etal_2015,zanotti_etal_2015,dumbser_etal_2018}) have also investigated the DG method in the context of astrophysical applications and reported encouraging results.  \nThe DG limiting techniques implemented in \\thornado\\ are similar to those used by \\cite{schaal_etal_2015}, but is supplemented with a troubled-cell indicator \\cite{fuShu_2017} to prevent excessive limiting (e.g., around smooth extrema), and differs from more recent approaches in the literature (e.g., \\cite{huerta_etal_2012,dumbser_etal_2014,zanotti_etal_2015,sonntagMunz_2017}), which combine the sub-cell resolution of the DG method with high-order finite-volume techniques to improve the performance of the DG limiting procedure.  \nWhile the results with current limiters are encouraging, these latter methods appear as attractive options for future implementation in \\thornado.  \n\n\\section{The discontinuous Galerkin method}\n\nExcellent books and review articles on the DG method are available (see, e.g., \\cite{cockburnShu_1998,cockburnShu_2001,hesthavenWarburton_2008,shu_2016} and references therein), and we will not go into too much detail here.  \nHowever, we review some key concepts to introduce notation, and emphasize specific choices for our implementation in \\thornado.  \nTo this end, we consider a system of conservation laws with sources of the form\n\\begin{equation}\n  \\pd{}{t}\\big(\\,\\sqrt{\\gamma}\\,\\vect{U}\\,\\big)\n  +\\sum_{i=1}^{d}\\pd{}{i}\\Big(\\,\\sqrt{\\gamma}\\,\\vect{F}^{i}(\\vect{U})\\,\\Big)\n  =\\sqrt{\\gamma}\\,\\vect{S}(\\vect{U}),\n  \\label{eq:extendedEulerCompact}\n\\end{equation}\nwhere $\\vect{U}$ is the evolved state vector, $\\vect{F}^{i}$ are the fluxes, and $\\vect{S}$ is the source vector.  \nWe use a formulation of the equations sufficiently general to accommodate curvilinear spatial coordinates encoded in the metric $\\gamma_{ij}$, giving the squared line element $ds^{2}=\\gamma_{ij}dx^{i}dx^{j}$, whose determinant is $\\gamma$.  \nHenceforth, we will assume that the spatial metric is time-independent.  \nTo solve Eq.~\\eqref{eq:extendedEulerCompact}, the computational domain $D\\subset\\mathbb{R}^{d}$ is divided into a disjoint union $\\cT$ of open elements $\\bK$, so that $D = \\cup_{\\bK \\in \\cT}\\bK$.  \nWe require that each element is a box in the logical coordinates; i.e.,\n\\begin{equation}\n  \\bK=\\{\\,\\vect{x} : x^{i} \\in K^{i} := (\\xL^{i},\\xH^{i}),\\,i=1,\\ldots,d\\,\\}, \n\\end{equation}\nwith the surface elements denoted $\\partial\\bK^{i}=\\times_{j\\ne i}K^{j}$.  \nWe let $V_{\\bK}$ denote the proper element volume\n\\begin{equation}\n  V_{\\bK} = \\int_{\\bK}dV, \\quad\\text{where}\\quad dV = \\sqrt{\\gamma}\\,\\prod_{i=1}^{d}dx^{i}.  \n\\end{equation}\nWe also define as a set $\\bx=\\{\\tilde{\\bx}^{i},x^{i}\\}$ and $\\dx^{i}=\\xH^{i}-\\xL^{i}$.  \n\nWe let the approximation space for the DG method, $\\mathbb{V}^{k}$, be constructed from the tensor product of one-dimensional polynomials of maximal degree $k$.  \nNote that functions in $\\mathbb{V}^{k}$ can be discontinuous across element interfaces.  \nThe semi-discrete DG problem is to find $\\vect{U}_{h}\\in\\mathbb{V}^{k}$, which approximates $\\vect{U}$ in Eq.~\\eqref{eq:extendedEulerCompact}, such that for all $v\\in\\mathbb{V}^{k}$ and all $\\bK\\in\\mathcal{T}$\n\\begin{align}\n  &\\partial_{t}\\int_{\\bK}\\vect{U}_{h}\\,v\\,dV\n  +\\sum_{i=1}^{d}\\int_{\\partial\\bK^{i}}\\big(\\,\\sqrt{\\gamma}\\,\\widehat{\\vect{F}}^{i}(\\vect{U}_{h})\\,v\\big|_{\\xH^{i}}-\\sqrt{\\gamma}\\,\\widehat{\\vect{F}}^{i}(\\vect{U}_{h})\\,v\\big|_{\\xL^{i}}\\,\\big)\\,d\\tilde{\\bx}^{i} \\nonumber \\\\\n  &\\hspace{24pt}\n  -\\sum_{i=1}^{d}\\int_{\\bK}\\vect{F}^{i}(\\vect{U}_{h})\\,\\pd{v}{i}\\,dV\n  =\\int_{\\bK}\\vect{S}(\\vect{U}_{h})\\,v\\,dV.  \n  \\label{eq:semidiscreteDG}\n\\end{align}\nIn Eq.~\\eqref{eq:semidiscreteDG}, $\\widehat{\\vect{F}}^{i}(\\vect{U}_{h})$ is a numerical flux approximating the flux on the $i$th surface of $\\bK$.  \nThe numerical flux function $\\vect{f}^{i}$ is evaluated using values from both sides of an element interface; i.e.,\n\\begin{equation}\n  \\widehat{\\vect{F}}^{i}(\\vect{U}_{h})=\\vect{f}^{i}(\\vect{U}_{h}(x^{i,-},\\tilde{\\bx}^{i}),\\vect{U}_{h}(x^{i,+},\\tilde{\\bx}^{i})),\n\\end{equation}\nwhere superscripts $-/+$, e.g. in the arguments of $\\vect{U}_{h}$, indicate that the function is evaluated to the immediate left/right of $x^{i}$.  \nWe use the Harten-Lax-van Leer (HLL) flux \\cite{harten_etal_1983} or the HLLC flux \\cite{toro_etal_1994,mignoneBodo_2005} for all the numerical experiments presented in Section~\\ref{sec:numerical}.  \n\nWe provide further details on the DG method to arrive at the equations that are actually evolved in \\thornado.  \nWe start by introducing some notation, defining the polynomial expansion for $\\vect{U}_{h}$ and the quadrature rules used to evaluate the integrals in Eq.~\\eqref{eq:semidiscreteDG}.  \nThen we provide explicit expressions for each of the terms in Eq.~\\eqref{eq:semidiscreteDG}.  \nFor simplicity we consider one spatial dimension ($d=1$) and drop indices denoting the spatial dimension.  \nIn each element $K$, we use a nodal representation of the conserved variables $\\vect{U}$; i.e.,\n\\begin{equation}\n  \\vect{U}(x,t)\\approx\n  \\vect{U}_{h}(x,t)=\\sum_{i=1}^{N}\\vect{U}_{i}(t)\\,\\ell_{i}(x),\n  \\quad\\text{where}\\quad\n  \\ell_{i}(\\eta)=\n  \\prod_{\\substack{j=1\\\\j\\ne i}}^{N}\\f{\\eta-\\eta_{j}}{\\eta_{i}-\\eta_{j}}\n  \\label{eq:conservedNodalExpansion}\n\\end{equation}\nare Lagrange polynomials defined on the reference element $I = \\{ \\eta : \\eta \\in (-0.5,0.5) \\}$, and constructed to interpolate the node set $S_{N}=\\{\\eta_{i}\\}_{i=1}^{N}\\subset I$.  \nThe spatial coordinate $x$ and the reference coordinate $\\eta$ are related by the mapping $x(\\eta)=\\xL+(0.5+\\eta)\\,\\dx$.  \nThen, for any $\\eta_{j}\\in S_{N}$, $\\ell_{i}(\\eta_{j})=\\delta_{ij}$, so that $\\vect{U}_{h}(x(\\eta_{j}),t)=\\vect{U}_{j}(t)$.  \nWe introduce numerical quadratures to evaluate the integrals in Eq.~\\eqref{eq:semidiscreteDG}.  \nFirst we define the $M$-point quadrature $Q_{M}:C^{0}(I)\\to\\mathbb{R}$ with abscissas $\\hat{S}_{M}=\\{\\eta_{q}\\}_{q=1}^{M}$ and weights $\\{w_{q}\\}_{q=1}^{M}$, normalized such that $\\sum_{q=1}^{M}w_{q}=1$.  \nThe $M$-point Legendre-Gauss quadrature, which we use, integrates polynomials of degree $\\le 2M-1$ exactly.  \nThen, if $P_{h}(x)$ is such a polynomial, we have\n\\begin{equation}\n  \\f{1}{\\dx}\\int_{K}P_{h}(x)\\,dx=\\int_{I}P_{h}(\\eta)\\,d\\eta=Q_{M}\\big[P_{h}\\big]\\equiv\\sum_{q=1}^{M}w_{q}\\,P_{h}(\\eta_{q}).  \n\\end{equation}\n\nNote that the interpolation points $S_{N}$ and the quadrature points $\\hat{S}_{M}$ generally do not coincide.  \nHowever, for the sake of computational efficiency we let $M=N$ and $S_{N}=\\hat{S}_{N}$, which is a spectral-type nodal collocation DG approximation \\cite{bassi_etal_2013}.  \nInserting Eq.~\\eqref{eq:conservedNodalExpansion} into Eq.~\\eqref{eq:semidiscreteDG}, letting $v(x)=\\ell_{k}(x)$, and using the quadratures defined above, we obtain\n\\begin{align}\n  \\pd{}{t}\\int_{K}\\vect{U}_{h}\\,v\\,dV\n  &\\approx w_{k}\\,\\sqrt{\\gamma}_{k}\\,\\pd{}{t}\\vect{U}_{k}\\,\\dx\n  \\label{eq:timeDerivativeTerm}\n\\end{align}\nfor the time derivative term.  \nFor a general metric, the integral in Eq.~\\eqref{eq:timeDerivativeTerm} is approximate since we use the Legendre-Gauss quadrature rule with the nodal points given by the expansion in Eq.~\\eqref{eq:conservedNodalExpansion}.  \nHowever, since $\\ell_{i}(\\eta_{k})=\\delta_{ik}$, this leads to a diagonal mass matrix, and simplifies the implementation.  \nSimilarly, we obtain\n\\begin{align}\n  \\int_{K}\\vect{S}(\\vect{U}_{h})\\,v\\,dV\n  &\\approx w_{k}\\,\\sqrt{\\gamma}_{k}\\,\\vect{S}(\\vect{U}_{k})\\,\\dx.\n  \\label{eq:sourceTerm}\n\\end{align}\nfor the source term.  \nFinally, the volume term (last term on the left-hand side of Eq.~\\eqref{eq:semidiscreteDG}) becomes\n\\begin{equation}\n  \\int_{K}\\vect{F}(\\vect{U}_{h})\\,\\pderiv{v}{x}\\,dV\n  \\approx \\sum_{q=1}^{N}w_{q}\\,\\sqrt{\\gamma}_{q}\\,\\vect{F}(\\vect{U}_{q})\\,\\pderiv{\\ell_{k}}{\\eta}(\\eta_{q}).\n  \\label{eq:volumeTerm}\n\\end{equation}\nUsing Eqs.~\\eqref{eq:timeDerivativeTerm}-\\eqref{eq:volumeTerm} in Eq.~\\eqref{eq:semidiscreteDG} results in the semi-discrete form\n\\begin{align}\n  \\deriv{\\vect{U}_{k}}{t}\n  =-\\f{1}{w_{k}\\sqrt{\\gamma}_{k}\\dx}\n  \\Big\\{\n  \\Big[\\,\n    \\sqrt{\\gamma}\\widehat{\\vect{F}}\\ell_{k}\\big|_{\\xH}\n    -\\sqrt{\\gamma}\\widehat{\\vect{F}}\\ell_{k}\\big|_{\\xL}\n  \\,\\Big]\n  -\\sum_{q=1}^{N}w_{q}\\,\\sqrt{\\gamma}_{q}\\,\\vect{F}(\\vect{U}_{q})\\,\\pderiv{\\ell_{k}}{\\eta}(\\eta_{q})\n  \\Big\\} + \\vect{S}(\\vect{U}_{k}).\n  \\label{eq:semidiscreteDiscretized}\n\\end{align}\nEq.~\\eqref{eq:semidiscreteDiscretized} comprises a system of ordinary differential equations (ODEs), which are integrated in time with an ODE solver.  \nIn Section~\\ref{sec:numerical} we use the optimal third-order strong stability-preserving Runge-Kutta (SSP-RK3) method from \\cite{shuOsher_1988}.  \nWe assume that the source term $\\vect{S}(\\vect{U}_{k})$ is non-stiff so that the equations can be integrated efficiently with explicit methods.  \nIn future applications of the DG method to model CCSNe we plan to use a combination of implicit and explicit methods (e.g., IMEX methods \\cite{ascher_etal_1997}) to stably integrate stiff sources due to neutrino-matter interactions.  \n\nLimiting of the polynomial representation $\\vect{U}_{h}$, to reduce oscillations and prevent unphysical states, is a critical step in the DG algorithm.  \nWe use the TVD-type slope limiter based on limiting characteristic variables, discussed in \\cite{cockburnShu_1998}.  \nTo prevent excessive limiting (e.g., at smooth extrema), we use the troubled-cell indicator (TCI) of \\cite{fuShu_2017}:\n\\begin{equation}\n  I_{\\bK}(G) = \\f{\\sum_{j}|G_{\\bK}-G_{\\bK}^{(j)}|}{\\max_{j}|G_{\\bK^{(j)}}^{(j)}|},\n  \\label{eq:indicator}\n\\end{equation}\nwhere $G\\in\\vect{G}\\subseteq\\vect{U}$.  \n(Here, $\\vect{G}$ consists of the first and last element of $\\vect{U}$.)  \nIn Eq.~\\eqref{eq:indicator}, the sum in the numerator and the $\\max$ in the denominator extend over the neighboring elements sharing a face with the target element $\\bK$.  \n$G_{\\bK}$ is the cell average in $\\bK$, $G_{\\bK}^{(j)}$ is the cell average computed by extrapolating the polynomial representation from the neighbor element $\\bK^{(j)}$ into $\\bK$, and $G_{\\bK^{(j)}}^{(j)}$ is the cell average native to $\\bK^{(j)}$.  \nAn element is flagged for limiting if $I_{\\bK}(G)>C_{\\TCI}$ for any $G\\in\\vect{G}$.  \nTo prevent negative mass density and pressure (and superluminal velocity for the relativistic Euler equations), we follow the approaches in \\cite{zhangShu_2010,wuTang_2015,qin_etal_2016}.  \n\nTo summarize the full RK-DG algorithm we let $\\bar{\\vect{U}}$ denote the global solution vector containing all the unknowns in $D$ and $\\bar{\\vect{F}}$ denote the corresponding DG discretization from the right-hand side of Eq.~\\eqref{eq:semidiscreteDiscretized}, so that the global ODE system can be written as the $d_{t}\\bar{\\vect{U}}=\\bar{\\vect{F}}(\\bar{\\vect{U}})$.  \nThe TVD limiter and the `positivity' limiter preventing unphysical states are denoted by $\\Lambda^{\\TVD}\\{\\}$ and $ \\Lambda^{\\Pos}\\{\\}$, respectively (e.g., application of the TVD limiter is $\\bar{\\vect{U}} := \\Lambda^{\\TVD}\\{\\bar{\\vect{U}}\\}$).  \nThe general $s$-stage Runge-Kutta time stepping algorithm, which includes application of limiters, can then be written as \\cite{cockburnShu_2001}:\n\\begin{itemize}\n  \\item[1.] Set $\\bar{\\vect{U}}^{(0)} = \\bar{\\vect{U}}^{n}$,\n  \\item[2.] For $i=1,\\ldots,s$ compute:\n  \\begin{equation}\n    \\bar{\\vect{U}}^{(i)} \n    = \\Lambda^{\\Pos}\\Big\\{\\,\\Lambda^{\\TVD}\\Big\\{\\,\\sum_{j=0}^{i-1}\\Big(\\,\\alpha_{ij}\\,\\bar{\\vect{U}}^{(j)}+\\beta_{ij}\\,\\Delta t\\,\\bar{\\vect{F}}\\big(\\bar{\\vect{U}}^{(j)}\\big)\\,\\Big)\\,\\Big\\}\\,\\Big\\},\n    \\label{eq:rkStages}\n  \\end{equation}\n  \\item[3.] Set $\\bar{\\vect{U}}^{n+1}=\\bar{\\vect{U}}^{(s)}$.  \n\\end{itemize}\nThe coefficients $\\alpha_{ij}$ and $\\beta_{ij}$ for SSP-RK3 are given in Table~2.1 in \\cite{cockburnShu_2001}.  \nIn Eq.~\\eqref{eq:rkStages}, for each stage, the TVD limiter is applied first (for elements where $I_{\\bK}>C_{\\TCI}$), followed by the positivity limiter.  \nThe algorithm is subject to two time step restrictions, the stability condition $\\Delta t_{\\TVD}$ and the positivity condition $\\Delta t_{\\Pos}$, and we take $\\Delta t=\\min_{D}(\\Delta t_{\\TVD},\\Delta t_{\\Pos})$.  \nLet $(h/|\\lambda|)=\\min_{i\\in\\{1,\\ldots,d\\}}(\\Delta x^{i}/|\\lambda^{i}|)$, where $|\\lambda^{i}|$ is the largest absolute eigenvalue of the flux Jacobian.  \nThen, assuming Cartesian coordinates (e.g., \\cite{cockburnShu_2001,zhangShu_2010}):\n\\begin{equation}\n  \\Delta t_{\\TVD} \\le \\f{1}{d}\\,\\f{(h/|\\lambda|)}{(2k+1)} \\quad\\text{and}\\quad\n  \\Delta t_{\\Pos} \\le \\f{\\hat{w}_{1}(h/|\\lambda|)}{d},\n  \\label{eq:timestepRestrictions}\n\\end{equation}\nwhere $\\hat{w}_{1}$ is the first quadrature weight of the Gauss-Lobatto quadrature that integrates the cell average of $\\vect{U}_{h}$ exactly.  \nFor $d=k=2$, the effective Courant-Friedrichs-Lewy (CFL) factor is $0.1$ for $\\Delta t_{\\TVD}$, while it is $1/12$ for $\\Delta t_{\\Pos}$.  \nThe positivity limiter checks for unphysical states in all the quadrature points involved in the DG discretization.  \nIf any point in an element is flagged as unphysical, the polynomial representation $\\vect{U}_{h}$ is damped towards its cell average $\\vect{U}_{\\bK}$, which is guaranteed to be physical by the $\\Delta t_{\\Pos}$ restriction.  \nNote that $\\Delta t_{\\Pos}$ is a sufficient condition.  \nIn practice, the time step can often be set larger than $\\Delta t_{\\Pos}$.  \n\n\\section{Preliminary numerical results}\n\\label{sec:numerical}\n\nIn this section we show preliminary numerical results obtained with the DG method implemented in \\thornado\\ to solve the non-relativistic and special relativistic Euler equations.  \nWe use the ideal gas equation of state where the pressure $p$ is related to the internal energy density $e$ by $p=(\\Gamma-1)e$, and where $\\Gamma$ is the (constant) adiabatic index.  \nLet the $d$-dimensional computational domain be $D=\\times_{i=1}^{d}[\\xMin^{i},\\xMax^{i}]$, where $\\xMin^{i}$ and $\\xMax^{i}$ denote the coordinates of the inner and outer boundary in the $i$th coordinate direction, respectively.  \nTo limit the scope of this initial study, we use polynomials of degree $k=2$ (except in Section~\\ref{sec:isentropicVortex}, where we also use $k=1$ and $k=3$) combined with SSP-RK3 time stepping, and, unless stated otherwise, run all the tests with a CFL factor of $C=0.1$.  \nWe use the HLL Riemann solver when solving the non-relativistic Euler equations and the HLLC Riemann solver when solving the special relativistic Euler equations.  \nThe purpose of the tests is to gauge the performance of the DG implementation on a set of benchmarks as an initial measure of its suitability for future CCSN simulations.  \n\n\\subsection{Non-relativistic (NR) hydrodynamics}\n\nFor the NR Euler equations, the state, flux, and source vectors in Eq.~\\eqref{eq:extendedEulerCompact} are\n\\begin{equation}\n  \\vect{U}=\\big(\\rho,\\rho u_{j},E\\big)^{\\trans},~\n  \\vect{F}^{i}=\\big(\\rho u^{i},\\Pi^{i}_{~j},(E+p)u^{i}\\big)^{\\trans},~\n  \\text{and}~\n  \\vect{S}=\\big(0,\\f{1}{2}\\Pi^{ik}\\pd{\\gamma_{ik}}{j}-\\rho\\pd{\\Phi}{j},-\\rho u^{i}\\pd{\\Phi}{i}\\big)^{\\trans},\n\\end{equation}\nwhere $\\rho$ and $u^{i}$ are the mass density and components of the fluid three-velocity, respectively.  \nThe stress tensor is $\\Pi^{i}_{~j}=\\rho u^{i} u_{j}+p\\delta^{i}_{~j}$, and $E=e+\\f{1}{2}\\rho u_{i} u^{i}$ is the fluid (internal plus kinetic) energy density.  \nThe sources are due to curvilinear coordinates and Newtonian gravity.  \n\n\\subsubsection{Sod shock tube}\n\nThe first test is the classic Riemann problem due to Sod \\cite{sod_1978}, computed using Cartesian coordinates.  \nThe one-dimensional computational domain is $D=[0,1]$, and a discontinuity is initially located at $x^{1}=0.5$, separating the left and right states\n\\begin{equation*}\n  \\vect{U}_{\\leftState}=(1.0,\\vect{0.0},2.5)^{\\trans}\\quad\\text{and}\\quad\n  \\vect{U}_{\\rightState}=(0.125,\\vect{0.0},0.25)^{\\trans},\n\\end{equation*}\nwhere the adiabatic index is $\\Gamma=1.4$.  \nThe test is run with $100$ elements until $t=0.2$, using $C_{\\TCI}=0.03$.  \nResults are plotted in the left panels of Figure~\\ref{fig:SodSedov}.  \nThe DG method captures the main features of the solution well without introducing noticeable oscillations near the discontinuities (upper left panel).  \nIn the lower left panel we plot locations in the $xt$-plane of elements flagged for limiting.  \nLimiting is mainly triggered by the contact discontinuity and the shock.  \n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Sod_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Sedov_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Sod_TCI_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Sedov_TCI_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:SodSedov}{\\it Upper left panel:} numerical solution of Sod's problem using $100$ elements (plusses) compared with the exact solution (solid lines; from \\cite{toro_1999}).  {\\it Upper right panel:} numerical solution of the Sedov-Taylor blast wave using $256$ elements (plusses) against the exact solution (solid lines; from \\cite{kammTimmes_2007}).  In the lower panels we plot locations in the $xt$-plane of elements flagged for limiting ($I_{\\bK}>C_{\\TCI}$) by the Sod (left) and Sedov (right) problems.}\n\\end{figure}\n\n\\subsubsection{Sedov-Taylor blast wave}\n\nThis test, detailed in \\cite{sedov_1959} (see also {\\S}99 in \\cite{landauLifshitz_1979}), is computed in spherical polar coordinates with the assumption of spherical symmetry.\\footnote{In this paper, all tests in spherical polar coordinates are computed with the assumption of spherical symmetry.}\nThe computational domain is $D=[0,1.2]$, and the initial condition consists of a fluid at rest with density $\\rho=1$.  \nThe adiabatic index is $\\Gamma=1.4$, and an amount of thermal energy equal to $1$ is released in the innermost element.  \nWe use $256$ elements and run until $t=1$, using $C_{\\TCI}=0.03$.  \nAgain, the DG method captures the characteristic of the exact solution (cf. upper right panel of Figure~\\ref{fig:SodSedov}).  \nThe maximum density in the shock is somewhat lower for the numerical solution than the exact value (about $5$ versus $6$).  \nIn the lower right panel we map locations of elements flagged for limiting in the $xt$-plane.  \nThe troubled-cell indicator tracks the shock well (the analytic shock trajectory is given by the dashed cyan line), but also flags elements at smaller radii with low density.  \n\n\\subsubsection{Shu-Osher shock tube}\n\nThis test from \\cite{shuOsher_1989} is suitable for measuring the amount of dissipation in a numerical scheme.  \nThe one-dimensional computational domain is $D=[-5,5]$, and a discontinuity is placed at $x^{1}=-4$, separating the states\n\\begin{equation*}\n  \\vect{U}_{\\leftState}=\\big( 3.857143, 10.14185, 0.0, 0.0, 39.16667 \\big)^{\\trans}\\quad\\text{and}\\quad\n  \\vect{U}_{\\rightState}=\\big( 1+0.2\\times\\sin(5 x^{1}), \\vect{0.0}, 2.5 \\big)^{\\trans},\n\\end{equation*}\nwhere the adiabatic index is $\\Gamma=1.4$.  \nThe density variations ahead of the Mach=3 shock are compressed through the shock and result in higher-frequency variations downstream, which can be difficult to capture with an excessively dissipative scheme.  \n\nWe run this test to $t=1.8$ using $200$ elements.  \nIn the two upper panels of Figure~\\ref{fig:ShuOsher} we plot the density for various values of the troubled-cell indicator threshold $C_{\\TCI}$; $0.0$ (full limiting, green), $0.03$ (magenta), $0.3$ (red), and $3.0$ (blue).  \nLarger $C_{\\TCI}$ implies less limiting.  \nThe results are compared with a reference solution computed with $2048$ elements.  \nWith full limiting, the scheme is unable to capture the density variations behind the shock (cf. upper right panel in Figure~\\ref{fig:ShuOsher}).  \nThis is expected since the TVD-type limiter clips extrema.  \nThe results improve when the troubled-cell indicator is used.  \nWhen $C_{\\TCI}=0.03$, the variations are better resolved, but the amplitudes are much reduced relative to the reference solution.  \nWith $C_{\\TCI}=3.0$, the variations are well resolved and the amplitudes are comparable to the reference.  \n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/ShuOsher_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/ShuOsher_Inset_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{12pc}\n    \\includegraphics[width=12pc]{./Figures/ShuOsher_TCI_0015_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{12pc}\n    \\includegraphics[width=12pc]{./Figures/ShuOsher_TCI_0150_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}\n  \\begin{minipage}{12pc}\n    \\includegraphics[width=12pc]{./Figures/ShuOsher_TCI_1500_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:ShuOsher}Results for the Shu-Osher shock tube problem computed with $200$ elements.  The upper panels show the mass density at $t=1.8$ for various values of the troubled-cell indicator threshold $C_{\\TCI}$, compared with a high-resolution (2048 elements) reference solution.  In the lower panels we show elements flagged for limiting in the $xt$-plane for various values of $C_{\\TCI}$.}\n\\end{figure}\nIn the lower panels of Figure~\\ref{fig:ShuOsher} we plot locations in the $xt$-plane of elements flagged for limiting by the troubled-cell indicator: $C_{\\TCI}=0.03$ (left), $C_{\\TCI}=0.3$ (middle), and $C_{\\TCI}=3.0$ (right).  \nWith $C_{\\TCI}=0.03$, limiting is triggered in a wide region around the shock and around the peaks of the three leftmost density variations in the upper left panel in Figure~\\ref{fig:ShuOsher}.  \nWith $C_{\\TCI}=3.0$, limiting is only triggered in the shock.  \n\n\\subsubsection{Isentropic vortex}\n\\label{sec:isentropicVortex}\n\nThis test from \\cite{shu_1997} is included to verify the accuracy of the DG method implemented in \\thornado.  \nThe periodic computational domain is given by $D=[-5,5]\\times[-5,5]$.  \nThe initial density and pressure are given by $\\rho_{0}=\\big(\\,1-\\f{(\\Gamma-1)\\,\\beta^{2}}{(8\\pi\\Gamma)}\\exp\\big(1-r^{2}\\big)\\,\\big)^{1/(\\Gamma-1)}$ and $P_{0}=\\rho^{\\Gamma}$, where $r=\\sqrt{(x^{1})^{2}+(x^{2})^{2}}$, while the velocity components are $v_{0}^{1}=1-\\f{x^{2}\\beta}{2\\pi}\\,\\exp\\big((1-r^{2})/2\\big)$ and $v_{0}^{2}=1+\\f{x^{1}\\beta}{2\\pi}\\,\\exp\\big((1-r^{2})/2\\big)$.  \nThe strength of the vortex is set to $\\beta=5$, and we use $\\Gamma=1.4$.  \nWe evolve this test until $t=t_{f}=10$, when the vortex has returned to its initial position.  \n\n\\begin{wrapfigure}{L}{2.825in}\n  \\includegraphics[width=18pc]{./Figures/IsentropicVortex_Astronum_2018}\n  \\caption{\\label{fig:IsentropicVortex}Convergence results for the Isentropic Vortex:  $L^{\\infty}$ error norm versus number of elements in the $x^{1}$-dimension.}\n\\end{wrapfigure}\n\nIn Figure~\\ref{fig:IsentropicVortex} we plot the density error measured in the infinity norm $L^{\\infty}=\\max_{D}|\\rho(\\vect{x},t_{f})-\\rho_{0}(\\vect{x})|$ versus number of cells the $x^{1}$-dimension for various configurations.  \nWe ran with spatial resolutions of $25\\times25$, $50\\times50$, $100\\times100$, and $200\\times200$.  \nIn the first set of runs, we ran without any limiting and varied the polynomial degree $k$: $k=1$ (solid red), $k=2$ (solid black), and $k=3$ (solid green).  \nWe observe the expected order of accuracy for $k=1$ and $k=2$ (second- and third-order accuracy, respectively; cf. dotted reference lines).  \nFor $k=3$, the order of accuracy is close to fourth-order for the lower resolutions, but tends to third-order as the resolution increases, presumably due to the use of third-order time stepping.  \n(Note that we ran the $k=3$ case with a CFL factor of $1/14$; cf. Eq.~\\eqref{eq:timestepRestrictions}.)\nIn the second set of runs, we kept $k=2$ and ran with limiting turned on.  \nWe ran one set with $C_{\\TCI}=0.03$ (dashed magenta) and one set with $C_{\\TCI}=0.1$ (dashed cyan).  \nWhen $C_{\\TCI}=0.03$, the limiter is activated for the lowest resolution run and significantly reduces the accuracy of the method.  \nFor all the other runs, the limiter is not activated, and the results are identical to the runs with the limiter turned off.  \n\n\\subsubsection{Kelvin-Helmholtz (KH) instability}\nThis hydrodynamic instability is of significant astrophysical relevance --- including during the explosion phase of CCSNe --- and may occur in the interface separating fluids in relative motion.  \nWe compute this problem on the unit square $D=[0,1]\\times[0,1]$, imposing periodic boundary conditions, and with initial conditions and single-mode perturbations taken from \\cite{mcnally_etal_2012}.  \nWe use $256^{2}$ elements and evolve until $t=3.0$, well into the nonlinear regime.  \nResults are displayed in Figure~\\ref{fig:KelvinHelmholtz}.  \nWe have computed two models, one with $C_{\\TCI}=0.06$ (left panels) and one without limiting ($C_{\\TCI}\\to\\infty$; right panels).  \n\n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_15_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_15_noLim_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_24_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_24_noLim_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_30_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_30_noLim_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:KelvinHelmholtz}Mass density from the KH instability at various times, computed with $256^{2}$ elements: $t=1.5$ (top panels), $t=2.4$ (middle panels), and $t=3.0$ (bottom panels).  Results for $C_{\\TCI}=0.06$ and $C_{\\TCI}\\to\\infty$ (no limiting) are shown in the left and right panels, respectively.}\n\\end{figure}\n\nEarly on ($t=1.5$), the results from the two runs are practically indistinguishable, show no sign of developing secondary billows, and agree visually with results presented in \\cite{mcnally_etal_2012}.  \nWhen $t=2.4$, the run with $C_{\\TCI}=0.06$ has started to develop secondary billows within the coiled-up interface separating dense (white) and less dense (black) fluids, while the model with no limiting has not.  \nSee Figure~\\ref{fig:KelvinHelmholtz_TCI} for the spatial distribution of elements flagged for limiting at $t=2.4$.  \nWhen $t=3.0$, these secondary instabilities appear to have largely destroyed the coil structure for the model with limiting, while the coils remain intact in the model without limiting (although secondary billows have started to form in this model at this time).  \nAs discussed in more detail by \\cite{mcnally_etal_2012}, the development of the secondary billows may be an artifact of numerical perturbations and diffusion, which is delayed when the resolution is increased.  \nOur results are consistent with this in the sense that the less diffusive model develops secondary billows later.  \n\n\\begin{wrapfigure}{R}{2.825in}\n  \\centering\n  \\includegraphics[width=18pc]{./Figures/KelvinHelmholtz_TCI_24_Astronum_2018}\n  \\caption{\\label{fig:KelvinHelmholtz_TCI}Distribution of elements flagged for limiting in the KH test at $t=2.4$.}\n\\end{wrapfigure}\n\n\\subsubsection{Liska-Wendroff implosion}\n\nThis test from \\cite{liskaWendroff_2003} is computed on a 2D domain $D=[0,0.3]\\times[0,0.3]$ with reflecting boundary conditions using $256^{2}$ elements.  \nBelow the line $x^{2}=0.15-x^{1}$, we initially set $\\vect{U}=\\big(0.125,\\vect{0.0},0.35\\big)^{\\trans}$, while $\\vect{U}=\\big(1.0,\\vect{0.0},2.5\\big)^{\\trans}$ elsewhere.  \n\n\\begin{figure}[b]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Implosion_01_HighTCI_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Implosion_02_HighTCI_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:Implosion}Plots for the Liska-Wendroff implosion problem at $t=0.045$ (left) and $t=2.5$ (right), intended to match Figures~4.10 and 4.11 in \\cite{liskaWendroff_2003}.  The color map shows the pressure distribution, black contours show the mass density, while arrows indicate the velocity.}\n\\end{figure}\n\nResults for $t=0.045$ and $t=2.5$, with $C_{\\TCI}=0.6$, are displayed in Figure~\\ref{fig:Implosion} (left and right panels, respectively), which agree qualitatively with \\cite{liskaWendroff_2003}, who compared the results of eight different schemes for this problem.  \nWhen $t=0.045$, a shock wave propagates towards the origin of $D$, while a contact discontinuity is trailing the shock (cf. density contours), and a rarefaction wave is spreading in the opposite directions.  \nWhen $t=2.5$, a complex flow pattern with multiple shocks has emerged due to multiple reflections off the boundaries.  \nThe initial symmetry about the $x^{1}=x^{2}$ diagonal is maintained, and the results from \\thornado\\ agree qualitatively with the unsplit schemes in \\cite{liskaWendroff_2003}.  \nIn the right panel of Figure~\\ref{fig:Implosion}, the chatacteristic ``jet'' has formed and propagates along the diagonal, similar to that displayed by CLAW and WENO in \\cite{liskaWendroff_2003}.  \n\n\\subsubsection{Liska-Wendroff explosion}\n\nThis test, also from \\cite{liskaWendroff_2003}, is computed on the domain $D=[0,1.5]\\times[0,1.5]$ with reflecting inner boundaries and outflow outer boundaries using $256^{2}$ elements.  \nInside the radius $r=\\sqrt{(x^{1})^{2}+(x^{2})^{2}}=0.4$, we initially set $\\vect{U}=\\big(1.0,\\vect{0.0},2.5\\big)^{\\trans}$, while $\\vect{U}=\\big(0.125,\\vect{0.0},0.25\\big)^{\\trans}$ elsewhere.  \nWe did not apply any smoothing to the initial discontinuity.  \n\nResults for $t=3.2$, obtained with $C_{\\TCI}=0.1$, are displayed in Figure~\\ref{fig:Explosion}, which agree qualitatively with results in \\cite{liskaWendroff_2003}.  \nInitially, this test is similar to the Sod shock tube in cylindrical geometry: a shock and a contact discontinuity propagate in the positive radial direction, while a rarefaction wave propagates toward the origin.  \nLater, the initial shock leaves the computational domain, while an instability (resembling Richtmeyr-Meshkov) develops in the contact discontinuity.  \nA second shock emerges from the origin of the computational domain and runs through the contact discontinuity, which has developed a complex structure (see density contours in Figure~\\ref{fig:Explosion}).  \nThe second shock is located around $r=1.2$ at $t=3.2$.  \nIn the right panel we plot the distribution of elements flagged for limiting by the troubled-cell indicator at $t=3.2$.  \nLimiting is mainly focused on elements around the shock and the contact discontinuity.  \n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Explosion_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/Explosion_TCI_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:Explosion}Plots for the Liska-Wendroff Explosion problem at $t=3.2$.  In the left panel, intended to match panels in Figure~4.12 in \\cite{liskaWendroff_2003}, the color map shows the pressure distribution, black contours show the mass density, while arrows indicate the velocity.  In the right panel we plot the distribution of elements flagged for limiting $t=3.2$.}\n\\end{figure}\n\n\\subsubsection{Standing accretion shock (SAS)}\n\nThis test is of immediate relevance to simulation of CCSNe.  \nThe initial conditions, described in detail in \\cite{blondin_etal_2003}, have been used by many to study the standing accretion shock instability (SASI) and CCSN explosion dynamics.  \nWe follow closely the description in \\cite{blondin_etal_2003} to initialize this test.  \nWe use spherical polar coordinates, let $D=[0.2,2.0]$, and $\\Gamma=4/3$.  \nThe gravitational potential is given by the point-mass formula with $GM=0.5$.  \nA stationary shock is placed at a radius $R_{\\shock}=1$.  \nAhead of the shock, the flow is essentially in free-fall towards the shock with a constant Mach number of $100$.  \nThe mass accretion rate is held fixed at the outer boundary to $\\dot{M}=4\\pi$.  \nBelow the shock, $r\\in[0.2,1]$, the settling solution is obtained by solving Bernoulli's equation.  \nMatter flows through the inner boundary, and the density and pressure in boundary elements are set by extrapolating from $D$ assuming $\\rho\\propto r^{-3}$ and $E\\propto r^{-4}$, while the momentum components are held fixed to their initial values.  \n\n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/SAS_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/SAS_TCI_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{36pc}\n    \\includegraphics[width=36pc]{./Figures/SAS_Perturbed_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:SAS}Results from the SAS test using $256$ elements.  In the upper left panel we plot the mass density (blue) and velocity (red) versus radius for the initial condition (dashed lines) and for $t=100$ (solid lines) from an unperturbed run.  In the upper right panel we show elements flagged for limiting in the $rt$-plane.  In the bottom panel we show results from a perturbed model, where we plot the relative deviation of the pressure below the shock; cf. Eq.~\\eqref{eq:pressureDeviation}.}\n\\end{figure}\n\nWe use $256$ elements and run the tests until $t=100$ ($>5$ dynamical times \\cite{blondin_etal_2003}).  \nResults are shown in Figure~\\ref{fig:SAS}.  \nIn the first test we show results from an unperturbed run to gauge the ability of the DG method to maintain the initial state.  \nIn the upper left panel we compare the initial state (dashed lines) with the solution at $t=100$.  \nExcept for a slight shift ($\\sim1\\%$) in the position of the shock, the initial and final states are indistinguishable on the plot.  \nAlso, there are no oscillations visible in the numerical results.  \nIn the upper right panel we show elements flagged for limiting in the $rt$-plane (we set $C_{\\TCI}=0.03$ in this run), which illustrates how limiting is confined to the shock.  \nIn the second test we placed a shell with thickness $0.2$ and density three times higher than the ambient density ahead of the shock to induce a strong radial perturbation (similar to \\cite{blondin_etal_2003}; see their Figure~4).  \nThe initial condition is stable against radial perturbations.  \nIn the lower panel in Figure~\\ref{fig:SAS} we plot the pressure deviation below the shock, defined as\n\\begin{equation}\n  \\delta p = (p-\\bar{p})/\\bar{p},\n  \\quad\\text{where}\\quad\n  \\bar{p}=p_{0}(r_{0}/r)^{4},\n  \\label{eq:pressureDeviation}\n\\end{equation}\nand $p_{0}$ and $r_{0}$ are the pressure and radius at the inner boundary.  \nAs the shell falls through the shock, the strong perturbation results in an interesting pattern of waves propagating inside the shocked cavity, and oscillations of the shock position.  \nThe configuration eventually settles down to a configuration that is close to the initial condition (although the position of the shock is slightly larger than that of the initial state.)  \n\n\\subsubsection{Yahil-Lattimer collapse}\n\nThe final test of the NR hydrodynamics in \\thornado\\ involves self-gravity and is due to \\cite{yahilLattimer_1982,yahil_1983}.  \nIt models the self-similar collapse of a polytropic star; i.e., $p=\\kappa\\rho^{\\Gamma}$, where $\\kappa$ is the polytropic constant.  \nThis test is also of immediate relevance to CCSN simulations.  \nIn \\cite{yahilLattimer_1982,yahil_1983}, self-similar solutions to the gravitational collapse problem were constructed for $6/5\\le\\Gamma<4/3$.   \nThe solutions smoothly connect an homologously collapsing subsonic inner core (velocity proportional to radius) to a supersonically collapsing outer core in near free-fall ($u\\propto r^{-1/2}$).  \n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/YahilLattimerCollapse_MassDensity_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/YahilLattimerCollapse_Velocity_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:YahilLattimer}Results from the Yahil-Lattimer collapse test using $256$ elements.  Results obtained with \\thornado\\ (dashed black) are compared with the reference solution from Yahil \\cite{yahil_1983} (solid red).  The mass density (left panel) and velocity (right panel) are plotted versus radius.  We compare the solutions at select central densities during collapse, approximately $[10^{10},10^{11},10^{12},10^{13},10^{14}]$~g~cm$^{-3}$, which correspond to $(-t)=[51.0,15.0,5.0,1.5,0.5]$~ms.  }\n\\end{figure}\nWith two dimensional parameters in the model (the gravitational constant $G$ and the polytropic constant $\\kappa$), the dimensionless similarity variable is\n\\begin{equation}\n  X = \\kappa^{-1/2} \\, G^{(\\Gamma-1)/2} \\, r \\, (-t)^{\\Gamma-2},\n\\end{equation}\nwhere the origin of time is the moment of infinite central density.  \nAll the hydrodynamic variables can be expressed as a function of $X$, and the time-dependent Euler equations can be recast as a system of ODEs (see \\cite{yahil_1983} for details).  \nTo construct a reference to compare with our numerical results we have solved the ODEs given in \\cite{yahil_1983} to obtain these self-similar solutions.  \n\nWe show results for a model with $\\Gamma=1.30$.  \nWe use spherical polar coordinates, and let $D=[0,1\\times10^{5}]$~km, which is covered with $256$ elements.  \nThe Newtonian gravitational potential is obtained by solving Poisson's equation using a third-order accurate continuous finite element method (e.g., \\cite{brennerScott_2008}).  \nWe use a geometric grid to resolve the mass distribution as the star collapses and the central density increases from about $10^{9}$~g~cm$^{-3}$ to about $10^{14}$~g~cm$^{-3}$.  \nThe size of the innermost element is set to $1$~km while the size of the last element is about $3\\times10^{3}$~km.  \nWe specify the polytropic constant by setting a reference pressure $p=6\\times10^{27}$~erg~cm$^{-3}$ for $\\rho=7\\times10^{9}$~g~cm$^{-3}$ (reasonable values for a massive star in the pre-collapse stage).  \nWe also set the collapse time to $(-t)=150$~ms.  \nResults comparing the mass density and velocity of Yahil's reference solution to those obtained with \\thornado\\ using $C_{\\TCI}=0.03$ are plotted in Figure~\\ref{fig:YahilLattimer}.  \nThe agreement of the mass density and velocity profiles is excellent throughout collapse.  \n\n\\subsection{Special relativistic (SR) hydrodynamics}\n\nHere we show results from solving the SR Euler equations in Cartesian coordinates with \\thornado.\nIn this case the state, flux, and source vectors in Eq.~\\eqref{eq:extendedEulerCompact} are\n\\begin{equation}\n  \\vect{U}=\\big(\\rho W, \\rho h W^{2} u_{j},\\tau\\big)^{\\trans},~\n  \\vect{F}^{i}=\\big(\\rho W u^{i},\\Pi^{i}_{~j},\\rho(hW-1)W u^{i}\\big)^{\\trans},~\n  \\text{and}~\\vect{S}=0,\n\\end{equation}\nwhere $W$ is the Lorentz factor, $h=1+(e+p)/\\rho$ is the specific enthalpy, $\\tau=\\rho W(hW-1)-p$, and $\\Pi^{i}_{~j}=\\rho h W^{2} u^{i} u_{j}+p\\delta^{i}_{~j}$.  \nTo recover primitive from conserved variables we have implemented the procedure for analytic equations of state detailed in Appendix~D in \\cite{rezzollaZanotti_2013}.  \nWe solve two Riemann problems and compare the numerical results with exact solutions obtained with the solver from \\cite{martiMuller_2003}.  \nLet the primitive state vector be $\\vect{V}=\\big(\\rho,\\vect{u},p\\big)^{\\trans}$.  \nIn the first problem (Riemann problem~1), taken from \\cite{mignoneBodo_2005}, we use $\\Gamma=4/3$ and\n\\begin{equation*}\n  \\vect{V}_{\\leftState}=\\big(1.0,0.9,0.0,0.0,1.0\\big)^{\\trans}\\quad\\text{and}\\quad\n  \\vect{V}_{\\rightState}=\\big(1.0,0.0,0.0,0.0,10.0\\big)^{\\trans},\n\\end{equation*}\nwhile in the second problem (Riemann problem~2), also from \\cite{mignoneBodo_2005}, we use $\\Gamma=5/3$, and let\n\\begin{equation*}\n  \\vect{V}_{\\leftState}=\\big(1.0,\\vect{0.0},10^{3}\\big)^{\\trans}\\quad\\text{and}\\quad\n  \\vect{V}_{\\rightState}=\\big(1.0,\\vect{0.0},10^{-2}\\big)^{\\trans}.  \n\\end{equation*}\nIn both problems, the computational domain is $D=[0,1]$, the discontinuity is initially located at $x^{1}=0.5$, and the solutions are integrated to $t=0.4$.  \nResults are plotted in Figure~\\ref{fig:RelativisticHydro}.  \n\n\\begin{figure}[h]\n  \\centering\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/MB2005_01_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/MB2005_04_Astronum_2018}\n  \\end{minipage} \\\\\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/MB2005_01_TCI_Astronum_2018}\n  \\end{minipage}\\hspace{0.5pc}%\n  \\begin{minipage}{18pc}\n    \\includegraphics[width=18pc]{./Figures/MB2005_04_TCI_Astronum_2018}\n  \\end{minipage}\n  \\caption{\\label{fig:RelativisticHydro}Results from solving the SR Euler equations with \\thornado.  Riemann problem~1 (left panels) was solved using $100$ elements, while Riemann problem~2 (right panels) was solved using $400$ elements.  The numerical and exact solutions are plotted with plusses and solid lines, respectively.  In the lower panels we plot $xt$-plane locations of elements flagged for limiting}\n\\end{figure}\n\nAgain, the main features of the exact solution are captured with the DG method implemented in \\thornado.  \nFor Riemann problem~1, we observe some oscillations in the density profile between the leftmost shock and the contact discontinuity located around $x^{1}=0.6$.  \nFor Riemann problem~2, the maximum density in the thin density shell between the shock and the contact discontinuity is significantly lower for the numerical solution than the exact solution.  \nThis is due to a combination of limited spatial resolution and the action of the slope limiter.  \nWe used $C_{\\TCI}=0.03$ in both tests in this section, and we plot locations in the $xt$-plane of elements flagged for limiting in Figure~\\ref{fig:RelativisticHydro}.  \nThe troubled-cell indicator tracks the discontinuities well for both Riemann problems.  \nWe have found the agreement with the exact solution to improve for larger values of $C_{\\TCI}$, but at the expense of somewhat more oscillatory results.  \n\n\\section{Summary and outlook}\n\nWe have presented preliminary algorithm details and numerical results for solvers of the non-relativistic and special relativistic Euler equations of gas dynamics as implemented in the {\\bf t}oolkit for {\\bf h}igh-{\\bf or}der {\\bf n}eutrino-r{\\bf ad}iation hydr{\\bf o}dynamics (\\thornado).  \nThe spatial discretization is based on the DG method and the ODEs resulting from this discretization are integrated in time using SSP-RK methods.  \nWe employ a spectral-type nodal collocation DG approximation based on Legendre-Gauss points for interpolation and numerical quadrature evaluation \\cite{bassi_etal_2013}.  \nThis choice simplifies expressions for the semi-discretized equations, especially when applied to problems involving curvilinear coordinates encoded in a metric (e.g., in numerical relativity).  \nResults from a suite of tests in one and two spatial dimensions --- including problems with strong shocks --- demonstrate reliable performance of the implementation.  \nThe accuracy of \\thornado\\ on three shock tests (Sod shock tube \\cite{sod_1978}, Sedov-Taylor blast wave \\cite{sedov_1959}, and Shu-Osher shock tube \\cite{shuOsher_1989}) is qualitatively similar to that of the well-established CCSN simulation code \\chimera\\ \\cite{bruenn_etal_2018}, which is based on the PPM finite volume method \\cite{colellaWoodward_1984}.  \nTwo tests in spherical symmetry (standing accretion shock \\cite{blondin_etal_2003} and Yahil-Lattimer collapse \\cite{yahilLattimer_1982,yahil_1983}) demonstrate the DG method's ability to handle conditions relevant to CCSN simulations.  \nWe will present a more in-depth analysis of the performance of \\thornado\\ on these (and related) problems in a future study.  \n\nThe performance of the DG algorithm is sensitive to limiting of the polynomial representation.  \nThe combination of a TVD-type limiter (e.g., \\cite{cockburnShu_1998}) and the troubled-cell indicator of \\cite{fuShu_2017} seems to give satisfactory results for a range of problems.  \nHowever, in our experience, the optimal value for the indicator threshold $C_{\\TCI}$ seems to vary with the specific problem, and further investigation is needed to determine if there exists an optimal value suitable for CCSN simulations.  \nAlong these lines of investigation, it would also be interesting to explore and compare the use of the {\\it a posteriori} subcell limiting approach in \\cite{dumbser_etal_2014,fambri_etal_2018} with our current approach.  \n\nOngoing and planned near-future work within \\thornado\\ include coupling to solvers for two-moment neutrino transport, extensions to accommodate nuclear equations of state, general relativity within the conformal flatness approximation, and deployment within an adaptive mesh refinement framework.  \nWe hope to report on progress in these directions in the near future.  \n\n\\ack Eirik Endeve, Anthony Mezzacappa, Nick Roberts, and Samuel J. Dunham acknowledge support from the NSF Gravitational Physics Program (NSF-GP 1505933 and 1806692).\n\n\\section*{References}\n\\begin{thebibliography}{36}\n  \\bibitem{ascher_etal_1997} Ascher U M, Ruuth S J and Spiteri R J 1997 {\\it Applied Numerical Mathematics} {\\bf 23} 151\n  \\bibitem{bassi_etal_2013} Bassi F, Franchina N, Ghidoni A and Rebay S 2013 {\\it Int. J. Numer. Meth. Fluids} {\\bf 71} 1322\n  \\bibitem{blondin_etal_2003} Blondin J M, Mezzacappa A and DeMarino C 2003 {\\it ApJ} {\\bf 584} 980\n  \\bibitem{brennerScott_2008} Brenner S C and Scott L R 2008 {\\it The Mathematical Theory of Finite Element Methods} Springer\n  \\bibitem{bruenn_etal_2018} Bruenn S W {\\it et al} {\\it Preprint} arXiv:1809.05608\n  \\bibitem{cockburnShu_1998} Cockburn B and Shu C-W 1998 {\\it JCP} {\\bf 141} 199\n  \\bibitem{cockburnShu_2001} Cockburn B and Shu C-W 2001 {\\it Journal of Scientific Computing} {\\bf 16} 173\n  \\bibitem{colellaWoodward_1984} Colella P and Woodward P 1984 {\\it JCP} {\\bf 54} 174\n  \\bibitem{dumbser_etal_2014} Dumbser M, Zanotti O, Loub{\\`e}re R and Diot S 2014 {\\it JCP} {\\bf 278} 47\n  \\bibitem{dumbser_etal_2018} Dumbser M, Guercilena F, K{\\\"o}ppel S, Rezzolla L and Zanotti O 2018 {\\it Phys. Rev. D} {\\bf 97} 084053\n  \\bibitem{fambri_etal_2018} Fambri F, Dumbser M, K{\\\"o}ppel S, Rezzolla L and Zanotti O 2018 {\\it MNRAS} {\\bf 477} 4543\n  \\bibitem{fuShu_2017} Fu G and Shu C-W 2017 {\\it JCP} {\\bf 347} 305\n  \\bibitem{harten_etal_1983} Harten A, Lax P D and Van Leer B 1983 {\\it SIAM~Review} {\\bf 25} 35\n  \\bibitem{hesthavenWarburton_2008} Hesthaven J S and Warburton T 2008 {\\it Nodal discontinuous Galerkin methods: Algorithms, analysis and applications} Springer\n  \\bibitem{huerta_etal_2012} Huerta A, Casoni E and Peraire J 2012 {\\it Int. J. Numer. Meth. Fluids} {\\bf 69} 1614\n  \\bibitem{kammTimmes_2007} Kamm J R and Timmes F X 2007 {\\it LANL Report, No. LA-UR-07-2849}\n  \\bibitem{klockner_etal_2009} Kl{\\\"o}ckner A, Warburton T, Bridge J and Hesthaven J S 2009 {\\it JCP} {\\bf 228} 7863\n  \\bibitem{landauLifshitz_1979} Landau L D and Lifshitz E M 1979 {\\it Fluid Mechanics} Pergamon\n  \\bibitem{liskaWendroff_2003} Liska R and Wendroff B 2003 {\\it SIAM J. Sci. Comput.} {\\bf 25} 3\n  \\bibitem{martiMuller_2003} Mart{\\'i} J M and M{\\\"u}ller E 2003 {\\it Living Rev. Relativ.} {\\bf 6} 7\n  \\bibitem{mcnally_etal_2012} McNally C, Lyra W and Passy J-C 2012 {\\it ApJS} {\\bf 201} 18\n  \\bibitem{mignoneBodo_2005} Mignone A and Bodo G 2005 {\\it MNRAS} {\\bf 364} 126\n  \\bibitem{muller_2016} M{\\\"u}ller B 2016 {\\it PASA} {\\bf 33} 1\n  \\bibitem{qin_etal_2016} Qin T, Shu C-W and Yang Y 2016 {\\it JCP} {\\bf 315} 323\n  \\bibitem{radiceRezzolla_2011} Radice D and Rezzolla L 2011 {\\it Phys. Rev. D} {\\bf 84} 024010\n  \\bibitem{remacle_etal_2003} Remacle J-F, Flaherty J E and Shephard M S 2003 {\\it SIAM~Review} {\\bf 45} 53\n  \\bibitem{rezzollaZanotti_2013} Rezzolla L and Zanotti O 2013 {\\it Relativistic Hydrodynamics} Oxford\n  \\bibitem{schaal_etal_2015} Schaal K, Bauer A, Chandrashekar P R{\\\"u}diger P, Klingenberg C and Springel V 2015 {\\it MNRAS} {\\bf 453} 4278\n  \\bibitem{sedov_1959} Sedov L I 1959 {\\it Similarity and Dimensional Methods in Mechanics} Academic Press\n  \\bibitem{shuOsher_1988} Shu C-W and Osher S 1988 {\\it JCP} {\\bf 77} 439\n  \\bibitem{shuOsher_1989} Shu C-W and Osher S 1989 {\\it JCP} {\\bf 83} 32\n  \\bibitem{shu_1997} Shu C-W 1997 {\\it NASA/CR-97-206253 ICASE Report No. 97-65}\n  \\bibitem{shu_2016} Shu C-W 2016 {\\it JCP} {\\bf 316} 598\n  \\bibitem{sod_1978} Sod G A 1978 {\\it JCP} {\\bf 27} 1\n  \\bibitem{sonntagMunz_2017} Sonntag M and Munz C-D 2017 {\\it Journal of Scientific Computing} {\\bf 70} 1262\n  \\bibitem{teukolsky_2016} Teukolsky S A 2016 {\\it JCP} {\\bf 312} 333\n  \\bibitem{toro_etal_1994} Toro E F, Spruce M and Speares W 1994 {\\it Shock Waves} {\\bf 4} 25\n  \\bibitem{toro_1999} Toro E F 1999 {\\it NUMERICA: A Library of Source Codes for Teaching, Research and Applications}\n  \\bibitem{wilson_etal_1996} Wilson J R, Mathews G J and Marronetti P 1996 {\\it Phys. Rev. D} {\\bf 54} 1317\n  \\bibitem{wuTang_2015} Wu K and Tang H 2015 {\\it JCP} {\\bf 298} 539\n  \\bibitem{yahilLattimer_1982} Yahil A and Lattimer J M 1982 {\\it Supernovae: A Survey of Current Research} Reidel\n  \\bibitem{yahil_1983} Yahil A 1983 {\\it ApJ} {\\bf 265} 1047\n  \\bibitem{zanotti_etal_2015} Zanotti O, Fambri F and Dumser M 2015 {\\it MNRAS} {\\bf 452} 3010\n  \\bibitem{zhangShu_2010} Zhang X and Shu C-W 2010 {\\it JCP} {\\bf 229} 8918\n\\end{thebibliography}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "127bde6f15600c1682ac88d848ef65a207465036", "size": 57108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/Astronum_2018/ms_endeve.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/Euler/Astronum_2018/ms_endeve.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/Euler/Astronum_2018/ms_endeve.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": 84.8558692422, "max_line_length": 768, "alphanum_fraction": 0.7385305036, "num_tokens": 17799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6419271292817372}}
{"text": "\\section{Introduction}\n\\label{sec:Introduction}\n\n\n\\subsection{Model formulation}\n\\label{subsec:Model formulation}\n\nLet us consider a two-stage stochastic program as follows. Let $\\Omega$ represent the set of scenarios, and $p(\\omega)$ be the probability distribution function for the random parameters $\\omega$ with support $\\Omega$. Let $x \\in \\mathbb{R}^{n_1}$ be the first-stage (i.e., here-and-now) decision variables, and let $y(\\omega) \\in \\mathbb{R}^{n_2}$ be the second-stage (i.e., recourse or wait-and-see) decision variables representing recourse decisions corresponding to scenario $\\omega$. Moreover, let the first $i$ variables of $x$ be integer valued. A two-stage stochastic programming formulation is given by\n\\begin{subequations} \\label{eqn:master problem}\n\\begin{align}\n  \\min \\quad & c^T x + \\cQ(x) \\\\\n  \\text{s.t.} \\quad\n  & b^L \\leq A x \\leq b^U \\\\\n  & x \\in \\Z^{i}_{+} \\times \\R^{n_1 - i}_{+},\n\\end{align}\n\\end{subequations}\nwith the second stage recourse function $\\cQ(x)\\coloneqq \\E \\lmp Q(x, \\omega) \\rmp$,\n\\begin{subequations} \\label{eqn:subproblem}\n\\begin{align}\n  Q(x, \\omega):= \\min \\quad & q(\\omega)^T y(\\omega)) \\\\\n  \\text{s.t.} \\quad\n  & h^L(\\omega) \\leq W(\\omega) y(\\omega) \\leq h^U(\\omega) \\quad \\forall \\omega \\in \\Omega - T(\\omega) x\\\\\n  & y(\\omega)  \\in \\R^{n_2}_{+},\n\\end{align}\n\\end{subequations}\nwhere $A \\in \\R^{m_1 \\times n_1}, b \\in \\R^{m_1}, c \\in \\R^{n_1}$ and $T(\\omega) \\in \\R^{m_2 \\times n_1}$, $W(\\omega) \\in \\R^{m_2 \\times n_2}$, $h^L(\\omega), h^U(\\omega) \\in \\R^{m_2}$, $q(\\omega) \\in \\R^{n_2}$ for each $\\omega \\in \\Omega$.\nA reformulation of problem (\\ref{eqn:model formulation}) is the extensive form deterministic equivalent model (DE)\n\\begin{subequations} \\label{eqn:model formulation}\n\\begin{align}\n  \\min \\quad & c^T x + \\int_{\\omega \\in \\Omega} p(\\omega) q(\\omega)^T y(\\omega) d\\omega \\\\\n  \\text{s.t.} \\quad\n  & b^L \\leq A x \\leq b^U \\\\\n  & h^L(\\omega) \\leq T(\\omega) x + W(\\omega) y(\\omega) \\geq h^U(\\omega) \\quad \\forall \\omega \\in \\Omega \\\\\n  & x \\in \\Z^{i}_{+} \\times \\R^{n_1 - i}_{+}, y(\\omega) \\in \\R^{n_2}_{+}.\n\\end{align}\n\\end{subequations}\n In the stochastic programming literature, $T(\\omega)$ is called a technology matrix and $W(\\omega)$ is called a recourse matrix.\n\n\\subsubsection{Deterministic equivalent format}\n\\label{subsubsec: Deterministic equivalent format}\n\nWhen $\\Omega$ represents a finite set of scenarios, the expectation in (\\ref{eqn:master problem}) can be replaced by a probability-weighted sum.  The DE reformulation is the most straight forward approach to solve a two-stage stochastic mixed integer program. Let $S$ be the number of scenarios in $\\Omega$, and $x \\in \\Z^{i}_{+} \\times \\R^{n_1 - i}_{+}, y_1,\\ldots ,y_S \\in \\R^{n_2}_{+}$. The DE formulation of problem (\\ref{eqn:model formulation}) is presented in the following form:\n\\begin{align}\n\\begin{array}{rllllllllll}\n    {\\min}      & c_f  &+         & c^T x  & +& p(1) q_1^T y_1       & \\ldots & + &p(S) q_S^T y_S & & \\\\\n                    &   &   &     &             &        &  &  &  &  \\\\\n    \\text{s.t.} &  b^L &\\leq& Ax  &                      &        &                  & &             &\\leq  & b^U, \\\\\n                &  h^L_1 &\\leq& T_1 x & + &W_1 y_1     &      &     &     & \\leq & h^U_1, \\\\\n                &          & \\vdots&                 &    &         &       \\ddots   &        &              & \\vdots &        \\\\\n                &  h^L_S & \\leq &T_S  &     &             &        &  +& W_S y_S    &\\leq  & h^U_S,\n\\end{array}\n\\end{align}\nwith the bounds\n\\begin{align}\n\\begin{array}{lllll}\n                 x^L           & \\leq   & x    & \\leq   & x^U,     \\\\\n                 y^L_1         & \\leq   & y_1  & \\leq   & y^U_1,   \\\\\n                               & \\vdots &      & \\vdots &          \\\\\n                 y^L_S         & \\leq   & y_S  & \\leq   & y^U_S.\n\\end{array}\n\\end{align}\n\n\\subsubsection{C API}\n\\label{subsubsec:C API}\n\n\\IOP~provides a C API which gives programmatic access to the solver functionality. An online iOptimize C-API user manual can be found in the following website:\n\\[\n    %\\mbox{TODO.}\n    \\mbox{\\tt http://www.voptimize.org}.\n\\]\n\n\\subsubsection{SMPS Format}\n\\label{subsubsec:SMPS Format}\n\n\\IOP~also supports a subset of SMPS~\\cite{Birge.Louveaux1997IntroductionToStochastic}, which is an early format for stochastic programming problems. In this format three separate data files are provided:\n\n\\begin{itemize}\n  \\item Core file: a generic presentation of the variables and constraints in MPS (MPSX) layout. Data values need not feature any particular scenario, but every random data element must be represented.\n  \\item Time file: specifying the subdivisions of the core file that belong to each stage.\n  \\item Stoch file: specifying every scenario, the values of random data, and probabilities. However, we note that at this stage, only discrete forms of random distributions are implemented in \\IOP.\n\\end{itemize}\n\n\\subsection{External Solvers}\n\\label{subsec:External Solvers}\nThe current version of \\IOP~uses \\Cplex~\\cite{IBMILogCplex} as an external solver. The following versions of \\Cplex~are supported:\n\\begin{itemize}\n  \\item 12.5.0.0, 12.5.1.0\n  \\item 12.6.0.0, 12.6.1.0, 12.6.2.0, 12.6.3.0\n\\end{itemize}\nA trail or academic version of \\Cplex~can be downloaded from the following website:\n\\[\n    \\mbox{\\tt http://goo.gl/gh1SoG}.\n\\]\n\n\\subsection{\\IOP-\\SOS \\ Installation}\n\\label{subsec:Installation}\n\\IOP~supports Linux 64-bit compatible operating system (GLIBC version at least 2.14). After downloading the package, installation requires simply moving the package to the preferred directory. Contents of the package are\n\\begin{itemize}\n  \\item ./bin: a folder containing the iOptimize dynamic library.\n  \\item ./include: a folder containing the iOptimize header files.\n  \\item ./examples: a folder containing examples of using the iOptimize package.\n\\end{itemize}\n\nA gcc makefile is included in the folder examples. To compile the code, use command\n\\[\n    {\\tt make~all}.\n\\]\n\nOnce completed, two executable files, namely {\\tt IopTssLpEx1} and {\\tt IopTssLpEx2} shall be generated. To run the examples, use command\n\\[\n    {\\tt ./IopTssLpEx1} \\mbox{~~or~~} {\\tt ./IopTssLpEx2}.\n\\]\n\n{\\bf A path to the dynamic library of the external solver \\Cplex~must be specified before running the code}. The path is specified in the parameter file {\\tt TssLp.par} located in folder ./example by modifying the following two parameters:\n\\begin{itemize}\n  \\item {\\tt IOP\\_SPA\\_SOS\\_EXTSOL\\_DLL\\_PATH}: A path to the directory where the \\Cplex~dynamic library is currently located. For example, {\\tt\"/PATH/TO/ibm/ILOG/}{\\tt CPLEX\\_Studio1261/}{\\tt cplex/bin/x86-64\\_linux/\"}.\n  \\item {\\tt IOP\\_SPA\\_SOS\\_EXTSOL\\_DLL\\_NAME}: A filename of the \\Cplex~dynamic library. For example, {\\tt \"libcplex1261.so\"}.\n\\end{itemize}\nThe editor such as {\\tt vim} may be used to edit the parameter file {\\tt TssLp.par}.\n\n", "meta": {"hexsha": "dbe4b39d0ae6f427299bbff6f7d42256c439a842", "size": 6897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ConeOpt_Intro.tex", "max_stars_repo_name": "jupiters1117/ConeOpt", "max_stars_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_stars_repo_licenses": ["MIT"], "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/ConeOpt_Intro.tex", "max_issues_repo_name": "jupiters1117/ConeOpt", "max_issues_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_issues_repo_licenses": ["MIT"], "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/ConeOpt_Intro.tex", "max_forks_repo_name": "jupiters1117/ConeOpt", "max_forks_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_forks_repo_licenses": ["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.0, "max_line_length": 611, "alphanum_fraction": 0.6486878353, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6419093651281262}}
{"text": "\\chapter{Spaces}\n\\label{chp:manifold}\n\nA space is a set of points.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Space_(mathematics)}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Topological_space\\#Definition}}\n\n\\enquote{Space} is another word for \\enquote{set}.\n\n\\enquote{Point} is another word for \\enquote{element}.\n\nBecause spaces are sets,\nwe can use set operations such as intersection and union.\nFor example, if \\(A_1\\) is the set of all points on the line \\(L_1\\),\nand \\(A_2\\) is the set of all points on the line \\(L_2\\),\nthen the set intersection \\(A_1 \\cap A_2\\)\nis the set of all points where \\(L_1\\) and \\(L_2\\) intersect.\nA point in \\(A_1 \\cap A_2\\) must be both on \\(L_1\\) and \\(L_2\\) simultaneously.\nIf those lines are parallel (and don't coincide),\nthen \\(A_1 \\cap A_2\\) is empty,\nbecause those lines don't intersect.\n\nThe dimension of a space is a natural number.\n\nA point is an example of a zero-dimensional space.\n\nA line is an example of a one-dimensional space.\n\nA sheet is an example of a two-dimensional space.\n\nA cube is an example of a three-dimensional space.\n", "meta": {"hexsha": "ee49bc7e6644e95c7841312de66559d62996c982", "size": 1089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/space.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/space.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/space.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.03125, "max_line_length": 79, "alphanum_fraction": 0.7318640955, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6419093499977385}}
{"text": "\\chapter{Special relativity}\nThe study of high energy physics involves particles travelling at speeds close to $c$ and often with energies much greater than their mass. Therefore, much of the notation and calculations used stem from a proper treatment of special relativity (SR).\n\n\\section{4-vectors}\nSR places space and time on an equal footing and they adopt the same units in the system of natural units. We combine the information in time and space as components in a 4-vector, for example,\n\\begin{align*}\nx^\\mu = \\mqty(t \\\\ \\vec{r}), \\quad p^\\mu = \\mqty(E \\\\ \\vec{p}).\n\\end{align*}\nNote that in contravariant form (with the index up), 4-vectors are written as column vectors.\n\nThe metric tensor is a symmetric matrix that tells us how to link space and time. In the case of special relativity, it is simply a diagonal matrix\\footnote{The $(+,-,-,-)$ signature is most often used in high energy physics since most 4-vector quantities we deal with will be timelike. By contrast, general relativity usually uses the $(-,+,+,+)$ signature. Using either signature is valid, but it is important to not confuse them.},\n\\begin{equation}\ng_{\\mu\\nu} = \\mqty(\\dmat{1,-1,-1,-1}) = g^{\\mu\\nu}.\n\\end{equation}\nThe metric tensor may be used to perform index gymnastics to raise or lower an index. For example, we can find the covariant forms of the above 4-vectors,\n\\begin{align*}\nx_{\\mu} = g_{\\mu\\nu}x^\\nu = (t,\\, -\\vec{r}), \\quad p_{\\mu} = g_{\\mu\\nu}p^\\nu = (E,\\, -\\vec{p}).\n\\end{align*}\n\nThe scalar product of two 4-vectors is given by\n\\begin{equation}\na_{\\mu} b^{\\mu} = g_{\\mu\\nu}a^{\\nu}b^{\\mu} = b_{\\mu} a^{\\mu}.\n\\end{equation}\n\nNote the scalar product is invariant to which vector is covariant. Often, when only dealing with scalar products, we use the notation of a capital letter with no index for a 4-vector: $X$, $P$, $A$, etc. Then a scalar product may be written, for instance, as $XX = X^2$.\n\nFinally, introduce the 4-vector derivative in covariant form,\n\\begin{equation}\n\\partial_\\mu = \\left( \\pdv{t},\\, \\vec{\\nabla} \\right).\n\\end{equation}\nthen its square length is\n\\begin{equation}\n\\partial^2 = \\partial_\\mu \\partial^\\nu = \\left(\\pdv{t}\\right)^2 - \\nabla^2.\\label{eq:nablaSquared}\n\\end{equation}\n\n\\section{Lorentz transformation}\nThe Lorentz transformation is given by $x^\\mu \\rightarrow (x^\\prime)^\\mu$ where\n\\begin{equation}\n\\mqty(t^\\prime \\\\ x^\\prime \\\\ y^\\prime \\\\ z^\\prime) = \\mqty(\\dmat{\\gamma&{-\\beta\\gamma}\\\\{-\\beta\\gamma}&\\gamma, 1, 1}) \\mqty(t\\\\ x\\\\ y\\\\ z)\n\\end{equation}\nfor a 4-vector boosted by speed $\\beta$ along the $x$-axis. For completeness, we define $\\gamma$ here,\n\\begin{equation}\n\\gamma = \\frac{1}{\\sqrt{1-\\beta^2}}.\n\\end{equation}\n\nThe scalar product $a_\\mu b^\\mu$, and in fact any fully-contracted quantity, is invariant under Lorentz transformations, since they do not depend on the coordinates.\n\n\\section{The light cone}\nConsider two events with 4-coordinates $X$ and $Y$. The square of their spacetime separation is given by\n\\begin{equation}\ns^2 = (X-Y)^2 = (t_x - t_y)^2 - (\\vec{x} - \\vec{y})^2.\n\\end{equation}\nAlong the surface of the light cone, $s=0$. This condition gives\n\\begin{equation}\nt_x - t_y = \\abs{\\vec{x} - \\vec{y}}\n\\end{equation}\ni.e.~if a flash of light is emitted at $X$, it reaches $\\vec{y}$ at $t_y$. If $s^2 > 0$, then $t_x - t_y > \\abs{\\vec{x} - \\vec{y}}$ and a light pulse emitted at $X$ reaches $\\vec{y}$ before $t_y$. Therefore, the events are causally connected and their separation is said to be timelike. For $s^2<0$, the events are have spacelike separation and are causally disjoint.\n\n\\section{Relativistic kinematics}\nIn particle physics, there are two processes we could consider. Firstly, the decay of one particle into daughter particles,\n\\begin{equation}\nA \\to B + C + \\ldots\n\\end{equation}\nwhere the simplest case is that of two-body decay, \\HepProcess{A\\to B+C}. Here the centre of mass (CM) energy is simply the mass of the parent particle, $m_A$. Secondly, a scattering process,\n\\begin{equation}\nA + B \\to C + D + \\ldots\n\\end{equation}\nwhere the CM energy is given by $E_{CM}^2 = (P_A + P_B)^2 = (P_C + P_D + \\ldots) ^2$ (recall that $P_i$ is a 4-momentum).\n\n\\subsection{Fixed target particle production}\nConsider the process\n\\begin{equation}\nA + B \\to C\n\\end{equation}\nwhere the target $B$ is at rest in the laboratory frame. Therefore, $P_B = (m_B, \\vec{0})$.\n\nThe centre of mass energy is given by\n\\begin{align}\nE_{CM}^2 &= (P_A + P_B)^2 \\\\\n&= E_A^2 + 2E_A m_B + m_B^2 - \\abs{\\vec{p_A}}^2\n\\end{align}\nUse that $E_A^2 - \\abs{\\vec{p_A}}^2 = m_A^2$,\n\\begin{equation}\nE_{CM}^2 = m_A^2 + m_B^2 + 2E_A m_V\n\\end{equation}\nA typical beam has energy much greater than either of the masses involved, so we may write\n\\begin{equation}\n\\boxed{\nE_{CM} \\approx \\sqrt{2 E_A m_B}\n}\n\\end{equation}\n\nAt the production threshold, $E_{CM} = E_C$. This means that for a proton target ($m_B \\sim \\SI{1}{\\giga\\electronvolt}$), the incident particle energy required to produce a Higgs boson ($m_C \\sim \\SI{100}{\\giga\\electronvolt}$) is about \\SI{5}{\\tera\\electronvolt}. For a hadronic beam about one tenth of the beam energy goes into collisions so this would require a \\SI{50}{\\tera\\electronvolt} beam. In fact, fixed-target collisions rarely even produce \\Pbottom quarks. This means fixed-target experiemnts are not suitable for modern high-energy discoveries with present accelerator technology, and we must instead look towards beam-beam colliders.\n\n\\subsection{Beam-beam collisions}\nIn this type of collider, two beams are collided with opposite momenta:\n\\begin{align*}\nP_A = \\mqty(E_A \\\\ \\vec{p}), \\quad P_B = \\mqty(E_B \\\\ -\\vec{p})\n\\end{align*}\nso the CM frame is the laboratory frame:\n\\begin{equation}\nP_{CM} = P_A + P_B = \\mqty(E_{CM} \\\\ \\vec{0}) = \\mqty(E_A + E_B \\\\ \\vec{0}).\n\\end{equation}\nWe want to find the required energy for one of the beams, $E_A$, as a function of $E_{CM}$. Start by considering the product\n\\begin{align}\nP_A P_{CM} &= \\left( E_A,\\, \\vec{p} \\right) \\mqty(E_{CM} \\\\ \\vec{0}) = E_A E_{CM} \\\\\n\\text{also,}\\quad P_A P_{CM} &= P_A (P_A + P_B) = P_A^2 + P_A P_B \\label{eq:P_AP_CM}\n\\end{align}\nso, using $P_A^2 = m_A^2$, we have\n\\begin{equation}\nE_A E_{CM} = m_A^2 + P_A P_B. \\label{eq:E_AE_CM}\n\\end{equation}\nTo determine $P_A P_B$ consider\n\\begin{align}\nE_{CM}^2 &= P_{CM}^2 \\\\\n&= (P_A + P_B)^2 \\\\\n&= m_A^2 + m_B^2 + 2P_A P_B.\n\\end{align}\nSubstituting this into \\eqref{eq:E_AE_CM},\n\\begin{align}\nE_A E_{CM} &= m_A^2 + \\frac{1}{2}(E_{CM}^2 - m_A^2 - m_B^2) \\nonumber \\\\\n&= \\frac{E_{CM}^2 + m_A^2 - m_B^2}{2}\n\\end{align}\ntherefore,\n\\begin{equation}\\boxed{\nE_A = \\frac{E_{CM}^2 + m_A^2 - m_B^2}{2E_{CM}}.\n}\n\\end{equation}\n\nIn the case where $m_A = m_B$ this becomes $E_A = E_{CM}/2$.\n\n\\section{Mandelstam variables}\n\\begin{figure}[ht]\n\\centering\n\\include{figures/process}\n\\caption{Some process \\HepProcess{A + B \\to C + D}.\\label{fig:process}}\n\\end{figure}\nConsider some process \\HepProcess{A + B \\to C + D}. The three Mandelstam variables, $s$, $t$, and $u$ are combinations of the incoming and outgoing 4-momenta. For different diagrams, they are the momentum of the propagator:\n\\include{figures/channelTable}\n\nThe sum of $s$, $t$, and $u$ gives the sum of the squares of the mass of the four particles,\n\\begin{align}\ns +t + u &= (P_A + P_B)^2 + (P_A - P_C)^2 + (P_A - P_D)^2 \\\\\n&= 3P_A^2 + P_B^2 + P_C^2 + P_D^2 + 2P_A(P_B - P_C - P_D)\n\\end{align}\nBy conservation of 4-momentum, we have $P_A + P_B$ = $P_C + P_D$, therefore $P_B - P_C - P_D = -P_A$, so\n\\begin{align}\ns + t + u &= 3P_A^2 + P_B^2 + P_D^2 + 2P_A(-P_A) \\\\\n&= P_A^2 + P_B^2 + P_C^2 + P_D^2 \\\\\n&= m_A^2 + m_B^2 + m_C^2 + m_D^2. \\label{eq:madelstamSum}\n\\end{align}\n", "meta": {"hexsha": "1fdb490ac2c1a69cb0b4497d1c5a545b9d77a15f", "size": 7605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/5_Special_Relativity.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/5_Special_Relativity.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/5_Special_Relativity.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": 50.0328947368, "max_line_length": 646, "alphanum_fraction": 0.691913215, "num_tokens": 2588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7025300511670689, "lm_q1q2_score": 0.6418852114413178}}
{"text": "\\chapter{Lifting Machines}\n\\label{chap:lifting}\n\nWe observe that whenever we want to combine machines, the number of tapes and alphabets of all sub-machines have to agree.  For example, we have the\nfollowing typing rule for the sequential composition of labelled Turing machines:\n\\[\n  \\inferrule{M_1 : \\TM_\\Sigma^n(L_1) \\and M_2 : \\TM_\\Sigma^n(L_2)}{M_1 \\Seq M_2 : \\TM_\\Sigma^n(L_2)}\n\\]\nAssume that we have a one-tape machine $M_{aux} : \\TM_\\Sigma^1$ that moves the head to the right of the tape.  If we need a two-tape machine $M$ that\nmoves both tapes to the right, we would like to use sequential composition and move one tape after the other tape to the right.  But according to the\ntyping rule above, we would need two auxiliary two-tape machines $M_1$ and $M_2$, where $M_1$ moves the first tape to the right and $M_2$ the second.\n\nThere are multiple ways to solve this problem.  Maybe the most obvious solution is to define a class of $n$-tape machines $M_i : \\TM_\\Sigma^n$\nparametrised over the number of tapes and the tape-index $i$ of the tape to move.  The machine $M_i$ moves the $i$th tape to the right.  All other\ntapes are ``inactive'' and remain unchanged.  This approach of parametrising machines over the tape-indices of ``active'' tapes, however, becomes\nunhandy for machines with a lot of active tapes.\n\nWe choose another approach, because it is in general easier to define and verify machines with a fixed number of tapes.  We lift the one-tape machine\n$M_{aux}$ to $n$ different $n$-tape machines, for every $n\\ge1$.  Asperti and Ricciotti~\\cite{asperti2015} implement such an operator that translates\na one-tape machine into $n$-tape machines.  We implement a generalised operator that takes an $m$-tape machine and a mapping from $\\Fin_m$ to\n$\\Fin_n$, and yields an $n$-tape machine, for~$m \\le n$.\n\nThe second part of this problem is how to combine machines with different alphabets.  For example, if we have a machine $\\MS{Add}$ that adds\n(encodings of) natural numbers, we could want to build a machine $\\MS{Sum}$ that computes the sum of a list of numbers.  Consider an alphabet\n$\\Sigma_\\Nat$ where we could encode natural numbers on and an alphabet $\\Sigma_{\\List(\\Nat)}$ to encode lists of natural numbers.  If the alphabet\n$\\Sigma_\\Nat$ is included in $\\Sigma_{\\List(\\Nat)}$, we would like to lift $\\MS{Add}$ to the alphabet $\\Sigma_{\\List(\\Nat)}$, to define $\\MS{Sum}$.\n\nAsperti and Ricciotti~\\cite{asperti2015} avoid the problem of agreement of alphabets.  They consider a fixed alphabet to encode all needed data on and\nimplement a universal Turing machine.  However, this approach does not scale when we need to encode many different data types.  Whenever the alphabet\nhas to be changed, they also must change the definitions of all auxiliary machines.  That is why we introduce another operator that lifts a machine to\na bigger alphabet.\n\nBoth lifting operators are easy to define and verify using the lemmas of the previous chapter (see Section~\\ref{sec:match-proofs}).\n\n\n\\section{Tape-Lift}\n\\label{sec:n-Lift}\n\\setCoqFilename{ProgrammingTuringMachines.TM.Lifting.LiftTapes}%\n\nThe tape-lift takes a machine $M:\\TM_\\Sigma^m(L)$ and a duplicate-free vector $I: \\Fin_n^m$, and yields a machine\n$\\LiftTapes{M}{I} : \\TM_\\Sigma^n(L)$.  The tape of $\\LiftTapes{M}{I}$ with the index $i = I[j]$ (with $i:\\Fin_n$, $j:\\Fin_m$) behaves exactly as the\ntape $j$ of $M$.  All other tapes of $\\LiftTapes{M}{I}$ that are not in~$I$ are inactive and do not change.\n\n\nThe transition function of $\\LiftTapes{M}{I}$ gets the $n$ read symbols and selects the $m$ relevant symbols.  Then it applies the transition function\n$\\delta_M$ with the selected symbols and the current state $q$.  $\\delta_M$ yields an $m$-vector $act:\\Act^m$ and the continuation state $q'$.  It\nfills ``nop''-actions into $act$, to get an action vector $act':\\Act^n$.\n\n\\begin{definition}[Vector selecting][select]\n  \\label{def:select}\n  Let $X:\\Type$, $m,n:\\Nat$, $I : \\Fin_n^m$, and $V : X^m$.  Then $select~I~V : X^n$ is defined by\n  $select~I~V := \\map{\\bigl(\\lambda (j:\\Fin_m).~V[j] \\bigr)}{I}$\n\\end{definition}\n\\begin{lemma}[Correctness of $select$][select_nth]\n  By definition, for $j:\\Fin_m$, we have\n  \\[\n    (select~I~V)[j]=V\\bigl[I[j]\\bigr]\n  \\]\n\\end{lemma}\n\n\\begin{definition}[Vector filling][fill]\n  Let $X:\\Type$, $m,n:\\Nat$, $I:\\Fin_n^m$, $init:X^n$, and $V:X^m$.  Then $fill~I~init~V : X^n$ is defined per recursion:\n  \\begin{alignat*}{3}\n    & fill~(\\nil      )&& ~init~V &~:=~& init \\\\\n    & fill~(i \\cons I')&& ~init~V &~:=~& replace~(fill~I'~(\\tl V))~i~(\\hd V)\n  \\end{alignat*}\n  Where $replace : X^n \\to \\Fin_n \\to X \\to X^n$ replaces the $i$th element of a vector.\n\\end{definition}\n\\begin{lemma}[Correctness of $fill$]\n  If $I$ is duplicate-free, then:\n  \\begin{enumerate}\n  \\coqitem[fill_correct_nth] \\label{lem:fill_correct_nth}\n    If $I[j]=i$, then $(fill~I~init~V)[i] = V[j]$.\n  \\coqitem[fill_not_index] \\label{lem:fill_not_index}\n    If $i \\notin I$, then $(fill~I~init~V)[i] = init[i]$.\n  \\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n  By induction on $I : \\Fin_n^m$.\n\\end{proof}\n\n\\begin{definition}[$\\LiftTapes{M}{I}$][LiftTapes]\n  \\label{def:LiftTapes}\n  Let $M:\\TM_\\Sigma^m(L)$ and $I : \\Fin_n^m$.  We define $\\LiftTapes{M}{I} : \\TM_\\Sigma^n(L)$.  All components are the same as in $M$, except:\n  \\begin{alignat*}{2}\n    &\\delta(q,s) &~:=~& \\Let{(q', act) := \\delta_M(q, select~I~s)}{\\\\%\n    &            &~  ~& (q', fill~I~(\\None,N)^n~act)}\n  \\end{alignat*}\n\\end{definition}\n\n\\begin{lemma}[Correctness of $\\LiftTapes{M}{I}$][LiftTapes_Realise]\n  \\label{lem:LiftTapes_Realise}\n  Let $M : \\TM_\\Sigma^m(L)$ and $I : \\Fin_n^m$ duplicate-free.  If $M \\Realise R$, then $\\LiftTapes{M}{I} \\Realise \\LiftTapes{R}{I}$ with\n  \\[\n    \\LiftTapes{R}{I} := \\lambda t~(l,t').~ R~(select~I~t)~(l, select~I~t') \\land \\forall i:\\Fin_n.~i \\notin I \\rightarrow t'[i]=t[i]\n  \\]\n\\end{lemma}\n\n\\begin{lemma}[Running time of $\\LiftTapes{M}{I}$][LiftTapes_Terminates]\n  \\label{lem:LiftTapes_TerminatesIn}\n  Let $M : \\TM_\\Sigma^m(L)$ and $I : \\Fin_n^m$ duplicate-free. If $M \\TerminatesIn T$, then $\\LiftTapes{M}{R} \\TerminatesIn \\LiftTapes{T}{I}$ with\n  $ \\LiftTapes{T}{I} := \\lambda t~k.~ T~(select~I~t)~k.  $\n\\end{lemma}\n\nThe proofs are similar to the former proofs, i.e.\\ using Lemma~\\ref{lem:loop_lift} and Lemma~\\ref{lem:loop_unlift} with the following configuration\nlifting function:\n\\[\n  selectConf(q,t) := (q, select~I~t)\n\\]\n\nHowever, for the second part of the correctness, i.e.\\ tapes that are not in $I$ do not change, we need another lemma about $\\Loop$:\n\n\\begin{lemma}[Mapping loops][loop_map]\n  \\label{lem:loop_map}\n  Let $A:\\Type$, $f : A \\to A$, $h:A \\to \\Bool$.  Let $B:\\Type$ and $g : A \\to B$.  If $g(f~a)=g(a)$ for all $a:A$, then\n  \\begin{alignat*}{1}\n    & \\forall (k:\\Nat)~(a_1~a_2 : A). \\\\\n    & \\quad \\Loop~f~h~k~a_1 = \\Some{a_2} \\rightarrow \\\\\n    & \\quad g(a_1) = g(a_2)\n  \\end{alignat*}\n\\end{lemma}\n\\begin{proof}\n  By induction on $k:\\Nat$.\n\\end{proof}\n\nWe apply this lemma in the proof of Lemma~\\ref{lem:LiftTapes_Realise} with $g := \\lambda ((q,t):\\Conf).~t[i]$.\n\n\n\n\\section{Alphabet-Lift}\n\\label{sec:sigma-Lift}\n\\setCoqFilename{ProgrammingTuringMachines.TM.Lifting.LiftAlphabet}%\n\nLet $M : \\TM_\\Sigma^n(L)$ be a machine over the alphabet $\\Sigma$, and $f : \\Sigma \\hookrightarrow \\Tau$ a retraction on another alphabet $\\Tau$.\nNote that then $\\Tau$ has at least as many symbols as $\\Sigma$.  We need a default symbol $def:\\Sigma$.  In contrast to the default label we needed in\nthe definition of $\\While$, the choice of $def$ is semantically \\textit{relevant}.  This means that $def$ should be a symbol that $M$ does not expect\nto read.  The alphabet-lift $\\LiftAlphabet{M}{(f,def)} : \\TM_\\Tau^n(L)$ is a machine over the bigger alphabet $\\Tau$.\n\nThe transition function of the lifted machine $\\LiftAlphabet{M}{(f,def)}$ reads the $n$ optional symbols $s : \\Option(\\Tau)^n$ and tries to translate\nthem to $s': \\Option(\\Sigma)^n$ using the partial inversion function $f^{-1} : \\Tau \\to \\Option(\\Sigma)$.  If the symbol $\\tau:\\Tau$ has no\ncorresponding symbol in $\\Sigma$, it must be translated to $def$.  The transition function $\\delta_M$ of $M$ yields the successor state $q'$ and a\nvector of actions $act: (\\Option(\\Sigma) \\times \\MS{Move})^n$, which is translated using $f:\\Sigma\\to\\Tau$ to\n$act' : (\\Option(\\Tau) \\times \\MS{Move})^n$.\n\n\\begin{definition}[$\\LiftAlphabet{M}{(f,def)}$][LiftAlphabet]\n  \\label{def:LiftAlphabet}\n  Let $f : \\Sigma \\hookrightarrow \\Tau$, $def:\\Sigma$, and $M : \\TM_\\Sigma^n(L)$.  We define the machine %\n  $\\LiftAlphabet{M}{(f,def)} : \\TM_\\Tau^n(L)$ with the same components as $M$, except:\n  \\begin{alignat*}{2}\n    & \\delta(q,s)    &~:=~& \\Let{(q', act) := \\delta_M(q, \\map{(mapOpt~(surject~f~def))}{s})}{\\\\%\n    &                &~  ~& (q', \\map{(mapAct~f)}{act})} \\\\\n  \\end{alignat*}\n  With $surject~f~def : \\Tau \\to \\Sigma$:\n  \\[\n    \\coqlink[surjectTape]{surject}~f~def~\\tau :=\n    \\begin{cases}\n      \\sigma & f^{-1}(\\tau) = \\Some{\\sigma} \\\\\n      def & f^{-1}(\\tau) = \\None\n    \\end{cases}\n  \\]\n  and with the canonical functions $mapOpt: \\forall (X~Y:\\Type).~ (X \\to Y) \\to \\Option(X) \\to \\Option(Y)$ and\n  $mapAct : \\forall (\\Sigma~\\Tau:\\Type).~(\\Sigma\\to\\Tau) \\to \\Act_\\Sigma \\to \\Act_\\Tau$.\n\\end{definition}\n\n\\setCoqFilename{ProgrammingTuringMachines.TM.TM}%\nFor the correctness and running time lemmas, we also need the canonical function\n\\[\n  \\coqlink[mapTape]{mapTape}:\\forall (\\Tau~\\Sigma:\\Type).~(\\Tau\\to\\Sigma)\\to\\Tape_\\Tau\\to\\Tape_\\Sigma\n\\]\nthat maps every symbol on a tape.  We write $\\coqlink[mapTapes]{mapTapes}$ for the respective tape-vector function.\n\\setCoqFilename{ProgrammingTuringMachines.TM.Lifting.LiftAlphabet}%\n\n\\begin{lemma}[Correctness of $\\LiftAlphabet{M}{(f,def)}$][LiftAlphabet_Realise]\n  \\label{lem:LiftAlphabet_Realise}\n  If $M \\Realise R$, then $\\LiftAlphabet{M}{(f,def)} \\Realise \\LiftAlphabet{R}{(f,def)}$ with\n  \\small\n  \\[\n    \\LiftAlphabet{R}{(f,def)} := \\lambda t~(l, t').~R~(mapTapes~(surject~f~def)~t)~(l, mapTapes~(surject~f~def)~t')\n  \\]\n\\end{lemma}\n\n\\begin{lemma}[Running time of $\\LiftAlphabet{M}{(f,def)}$][LiftAlphabet_TerminatesIn]\n  \\label{lem:LiftAlphabet_TerminatesIn}\n  If $M \\TerminatesIn T$, then $\\LiftAlphabet{M}{(f,def)} \\TerminatesIn \\LiftAlphabet{T}{(f,def)}$ with\n  \\[\n    \\LiftAlphabet{T}{(f,def)} := \\lambda t~k.~T~(mapTapes~(surject~f~def)~t)~k\n  \\]\n\\end{lemma}\n\nThe proofs are analogous to the former proofs.  The configuration lifting is:\n\\[\n  \\coqlink[surjectConf]{surjectConf} (q,t) := (q, mapTapes~(surject~f~def)~t)\n\\]\n\n\n\n%%% Local Variables:\n%%% TeX-master: \"thesis\"\n%%% End:", "meta": {"hexsha": "eab3f1612f2126aae50387d48ffa22059f1f3e10", "size": 10609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/thesis/Lifting.tex", "max_stars_repo_name": "mwuttke97/CoqTM", "max_stars_repo_head_hexsha": "f4d2aab2008e2158e2c7ca88ebb53b42808a0778", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-08-30T14:58:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-27T15:44:28.000Z", "max_issues_repo_path": "tex/thesis/Lifting.tex", "max_issues_repo_name": "mwuttke97/CoqTM", "max_issues_repo_head_hexsha": "f4d2aab2008e2158e2c7ca88ebb53b42808a0778", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-10T09:16:49.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-10T09:16:49.000Z", "max_forks_repo_path": "tex/thesis/Lifting.tex", "max_forks_repo_name": "mwuttke97/CoqTM", "max_forks_repo_head_hexsha": "f4d2aab2008e2158e2c7ca88ebb53b42808a0778", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-04-09T19:01:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T15:39:53.000Z", "avg_line_length": 53.3115577889, "max_line_length": 150, "alphanum_fraction": 0.6795173909, "num_tokens": 3627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6418628470118574}}
{"text": "\\SecDef{intro}{Introduction}\n\nS-Boxes are used to provide non-linearity in SPN-based block ciphers. They provide basic resistance against linear and differential cryptanalysis, and the rest of the structure ensures that many S-Boxes are activated in a linear or differential trail. The resistance of an S-Box can be quantified. The lower are the \\emph{linearity} and the \\emph{differential uniformity} of an S-Box, the more resistant it is. Everything else being equal, a stronger S-Box allows to use less rounds in the block cipher using it for the same security level.\n\nThe differential uniformity is always even and at least equal to 2. When this bound is achieved, the S-Box is called \\emph{Almost Perfect Non-linear (APN)}. The finite field cube function is APN in all field dimensions~\\cite{Nyb94}. However, it is a permutation only in odd dimensions. This is a problem, since in most cases (e.g. an SPN block cipher) the S-Boxes are required to be bijective. For efficiency reasons, even-dimensional S-Boxes are preferable, especially powers of 2. And this is exactly the case, where the existence of APN functions is not established: bijective S-Boxes in even dimensions with differential uniformity 2, i.e. APN permutations of $\\field{n}$ for $n$ even. For $n = 4$ there exist no APN permutations of $\\field{n}$. For $n = 6$ this question was a long standing problem until Dillon~\\etal{} presented a 6-bit APN permutation~\\cite{DillonAPN,DillonPres} in 2009. Since then, no answers were obtained for even $n \\ge 8$, despite many attempts~\\cite{SubspaceProperty,Uniform4}. This remains a big open problem in the field of Boolean functions.\n\nThe 6-bit APN permutation is found by a computer search, by transforming the 6-bit APN function, called the Kim mapping $\\kim\\colon \\fielde{6} \\to \\fielde{6}$:\n$$\n\\kim(x) \\eqdef \\VV x^{24} + x^{10} + x^3,\n$$\nwhere $v$ is a primitive element of $\\fielde{6}$. Even though the Kim mapping is a trinomial function, the resulting APN permutation is an object without clear structure. For example, its polynomial form contains 52 monomials.\n\nUsing the methods of S-Box reverse-engineering described in previous chapters (developed in~\\cite{OurKuz1}), I and my coauthors managed to find a simple algebraic structure of the Dillon's APN permutation. We call this structure a ``Butterfly'' because of its graphical representation the way it changes by particular transformations. The decomposition is established in Theorem~\\Ref{thm:main}, restated here:\n\n\\textbf{Main theorem (A Family of 6-bit APN Permutations)}.\nThe 6-bit permutation described by Dillon \\etal{} in~\\cite{DillonAPN} is affine equivalent to any involution built using the structure described in \\FigRef{intro-decomp}, where $\\fmult$ denotes multiplication in the finite field $\\fielde{3}$, $\\alpha \\neq 0$ is such that $\\tr(\\alpha) = 0$ and $\\mathcal{A}$ denotes any 3-bit APN permutation.\n\\FigTex{intro-decomp.tex}\n\n\\subsection{Notations}\nFor any $f\\colon \\field{n} \\to \\field{n}$ let $\\parf{f}\\colon \\field{2n} \\to \\field{2n}$ be the parallel application of $f$ given by\n$$\n\\parf{f}(x,y) = (f(x), f(y)).\n$$\nFor any $a,b \\in \\field{n}$ let $\\xorf{f}\\colon \\field{2n} \\to \\field{2n}$ be parallel xor with constants $a,b$:\n$$\n\\xorf{f}(x,y) = (x \\oplus a, y \\oplus b).\n$$\nThe finite field trace function is denoted by $\\Tr\\colon \\fielde{n} \\to \\field{}$, it is given by\n$$\n\\Tr(x) \\eqdef \\sum_{e=0}^{n-1} x^e.\n$$\n\n\\subsection{Outline}\n\\SecRef{decomposition} explains the decomposition process of the APN permutation. In~\\SecRef{properties} I describe new properties of the APN permutation that follow from the discovered structure. \\SecRef{components} studies the flexibility of the structure, i.e. how can we modify the structure while preserving the APN property?\nIn \\SecRef{relations} I show new relations between the APN permutation, the Kim mapping, monomial functions and 3-round Feistel Network structure. Finally, I briefly conclude the chapter in \\SecRef{conclusions}.\n", "meta": {"hexsha": "5f27b501a2cd339abd324c5ef3c26d9f80ac42f4", "size": 3984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strAPN/0intro.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/9strAPN/0intro.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/9strAPN/0intro.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": 110.6666666667, "max_line_length": 1075, "alphanum_fraction": 0.7597891566, "num_tokens": 1078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357632379241, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6417576478890329}}
{"text": "\\section{Reachable nonterminals}\n\n$A$ is reachable iif $S \\Rightarrow^* \\alpha A \\beta$\n\nFor finding the reachable nonterminals build the \\textbf{produce} graph and visit it from the axiom.\n\n\\section{Defined nonterminals}\n$A$ is defined iff $L_A(G) \\ne \\emptyset$.\n\nFor finding the defined nonterminals apply the following relations:\n\\begin{align*}\n    D &:= \\{ A | (A \\rarr u) \\in P, u \\in \\Sigma^*\\} \\\\\n    D &:= D \\cup \\{ A | (A \\rarr B_1\\ldots B_n) \\in P, \\land \\forall B_i: B_i \\in (D \\cup \\Sigma) \\}\n\\end{align*}\n\n\\section{Circular Derivations}\n\nDerivations like $A \\Rightarrow^+ A$, are not essential and introduce ambiguity.\n\n\\section{Clean Grammars}\nA grammar $G$ is clean iif every nonterminal is \\textbf{reachable} and every nonterminal is \\textbf{defined}.\n", "meta": {"hexsha": "c949618df4a2d49298bd3a3209ddd479c193a195", "size": 769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grammars/erroneous-grammars.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": "grammars/erroneous-grammars.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": "grammars/erroneous-grammars.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": 34.9545454545, "max_line_length": 109, "alphanum_fraction": 0.7035110533, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6417576354071945}}
{"text": "% chapters/searching.tex\n\n\\chapter{Searching}\t\\label{chapter:searching}\n\n% deterministic search\nAlgorithm \\ref{alg:deterministic-search} (see Problem $5-2$ of \\cite{CLRS09})\nsearches for a value $x$ in an unsorted array $A$ consisting of $n$ elements \nby checking $A[1], A[2], \\cdots, A[n]$ in order until either it finds $A[i] = x$\nor it reaches the end of the array.\n\n\\input{algs/searching/deterministic-search}\n\n% binary stride\n\\begin{figure}\n  \\centering\n  \\includegraphics[width = 0.70\\textwidth]{figs/binary-stride}\n  \\caption{Binary stride.}\n  \\label{fig:binary-stride}\n\\end{figure}\n\n\\input{algs/searching/binary-search-iterative}\n\\input{algs/searching/binary-search-recursive}\n", "meta": {"hexsha": "477201f5528956479e5032e20c7566013a1b70fa", "size": 685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/searching.tex", "max_stars_repo_name": "hengxin/algorithms-pseudocode", "max_stars_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-11-06T08:52:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-27T13:01:13.000Z", "max_issues_repo_path": "chapters/searching.tex", "max_issues_repo_name": "hengxin/algorithms-pseudocode", "max_issues_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_issues_repo_licenses": ["MIT"], "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/searching.tex", "max_forks_repo_name": "hengxin/algorithms-pseudocode", "max_forks_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_forks_repo_licenses": ["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.7826086957, "max_line_length": 80, "alphanum_fraction": 0.7445255474, "num_tokens": 211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6416997625202546}}
{"text": "\\label{App:appendixB}\n\\begin{quotation}\n\t\"The simplest quantum mechanical system, and the system which we will be most concerned with, is the \\emph{qubit}. A qubit has a two-dimensional state space. [...] \n\tThe way a qubit differs from a bit is that superpositions of these two states, of the form $a\\ket{0} + b\\ket{1}$, can also exist, in which it is not possible to say that the qubit is definitely in the state $\\ket0$, or definitely in the state $\\ket1$.\"\n\t\\cite{NC10}\n\\end{quotation}\n\n%\\large{\\textbf{The three postulates}}\\cite{NC10}\n\\subsection{The three postulates}\\footcite{NC10}\n\t\\begin{quote}\n\t\t\\textbf{Postulate 1}: Associated to any isolated physical system is a complex vector space with inner product (that is, a Hilbert space) known as the \\emph{state space} of the system. \n\t\tThe system is completely described by its \\emph{state vector}, which is a unit vector in the system's state space. \n\t\\end{quote}\n\t\n\t\\begin{quote}\n\t\t\\textbf{Postulate 2}: The evolution of a \\emph{closed} quantum system is described by a \\emph{unitary transformation}. That is, the state $\\ket{\\psi}$ of the system at time $t_1$ is related to the state $\\ket{\\psi'}$ of the system at time $t_2$ by a unitary operator $U$ which depends only on times $t_1$ and $t_2$,\n\t\t$$ \\ket{\\psi'} = U\\ket{\\psi} $$\n\t\\end{quote}\n\t\n\t\\begin{quote}\n\t\t\\textbf{Postulate 3}: Quantum measurements are described by a collection $\\{M_m\\}$ of \\emph{measurements operators}. \n\t\tThese are operators acting on the state space of the system being measured. \n\t\tThe index $m$ refers to the measurement outcomes that may occur in the experiment. If the state of the quantum system is $\\ket{\\psi}$ immediately before the measurement then the probability that result $m$ occur is given by \n\t\t$$ p(m) = \\bra{\\psi}M_m^{\\dagger}M_m\\ket{\\psi} \\: ,$$\n\t\tand the state of the system after the measurement is \n\t\t$$ \\frac{M_m\\ket{\\psi}}{\\sqrt{\\bra{\\psi}M_m^{\\dagger}M_m\\ket{\\psi}}} \\: . $$\n\t\tThe measurement operators satisfy the \\emph{completeness equation},\n\t\t$$\\sum_m  M_m^{\\dagger}M_m = I \\: .$$\n\t\tThe completeness equation expresses the fact that probabilities sum to one:\n\t\t$$ 1 = \\sum_m p(m) = \\sum_m  \\bra{\\psi}M_m^{\\dagger}M_m\\ket{\\psi} \\: .$$ \n\t\\end{quote}\n\t\n\tFor our purposes it is enough for us to only consider the quantum system called \\emph{qubit} and its rules of computation following from the tensor product algebra. \n\n\\section{Dirac's bra-ket notation}\n\t%\t\\begin{figure}[h!]\n%\t\t\\centering\n%\t\t\\includegraphics[scale=0.2]{images/sketch1.png} \n%\t\t\\caption{how a physical state is represented}\n%\t\\end{figure}\n\tEvery pure quantum state can be represented as vector in a vector space with inner product, i.e. a \\emph{Hilbert space}. \n\t A complex Hilbert space $\\H$ of dimension $n$ is isomorphic to $ \\mathbb{C}^n $ with the standard inner product. \n\t In $\\mathbb{C}^n $ one can choose a basis and then represent vectors with coordinates with respect to this basis.\n\tThe bra-ket notation is a handy notation introduced by physicist Paul Dirac to deal with such vector representation of quantum states. \n\tFirst of all we note that a state $\\varphi '\\in\\H$ corresponds via the isomorphism to $ \\varphi  \\in \\mathbb{C}^n $. It can be represented as a vector with respect of some basis as follows\n\t$$\\ket{\\varphi} = \\begin{pmatrix} \\varphi_1 \\\\ \\varphi_2 \\\\ \\vdots \\end{pmatrix}\t  \\text{  is a coloumn \"ket\" vector over } \\H $$\n\t$$\\bra{\\varphi}  = \\begin{pmatrix} \\varphi_1 & \\varphi_2 & \\hdots \\end{pmatrix} \\text{  is a row \"bra\" vector over } \\H $$\n\tTo be representative of a quantum state the vector has to have unitary length, $\\|\\varphi\\|= 1$.\n\tFurthermore the conjugate transpose of a \\emph{bra} vector is the corresponding \\emph{ket} vector, and vice versa.\n\t$$ \\bra{\\varphi}^{\\dagger} = \\ket{\\varphi} \\text{,    } \\ket{\\varphi}^{\\dagger} = \\bra{\\varphi}$$\n\tMore specifically, for a complex vector space as $\\H$, the components of $\\bra{\\varphi}$ are each the complex conjugate of the components of $\\ket{\\varphi}$.\n\tIt is worth noting that in quantum information we will consider only vectors of finite dimensions, and more often than not, the standard basis for qubits represented by\n\t$$\\ket0 =  \\begin{pmatrix} 1 \\\\ 0 \\end{pmatrix}\n\t\\text{ and }\n\t\\ket1 =  \\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}$$\n\twhich are recognizable as the equivalent of $\\vec{e_1}$ and $\\vec{e_2}$ in $\\mathbb{C}^2$.\n\t\n\tTo summarize then, $\\ket{\\varphi}$ represents a column vector on a complex vector space with inner product equivalent to $\\mathbb{C}^n$ in some basis, and $\\bra{\\varphi}$ is its complex conjugate.\n\t\n\t\n\tSo if we define the matrix\\footnote{The fact that the result of  $ \\ketbra{w}{v} $ is indeed a matrix can be seen more directly if we remember that this is nothing less than a column-row vectors multiplication.} $A =  \\ketbra{w}{v} $ we observe that\n\t$$ \\ket{w}\\braket{v}{v'} = \\braket{v}{v'}\\ket{w} $$\t\n\twhich is a convenient way of visualizing the action of matrix $A$. In particular if we divide it like $(\\ketbra{w}{v}) (\\ket{v'}) $ it is easy to interpret it as \\textit{matrix $A$ acting on vector $\\ket{v'}$}. The other equivalent form $(\\braket{v}{v'})(\\ket{w})$ can also be seen as multiplying vector $\\ket{w}$ by a value $\\braket{v}{v'}$.\n\t%this part may be too similar to book, page 67...\n\t\n\tThe intuition of this is that $\\ketbra{w}{v}$ can indeed be defined as a (linear) operator from the vector space of $\\ket{v}$ to the vector space of $\\ket{w}$. \n\n\\section{Measurements on a  basis} \\label{measurements}\n\n\tTo get any information out of a state one has to \\textit{measure} it. \n\tMeasurement is, mathematically, a projection onto some chosen computational basis. \n\tThe result for each base vector projection is then interpreted as a \\emph{probability}. \n\tThe state then changes after measurement, meaning for example that it will not retain its value as superposition any more.\\\\\n\n\tIf Alice has the state $\\ket{\\psi_i}$ out of $i=1..n$ and all states are orthonormal, then Bob can --- measuring with the same basis --- find out what the choice of $i$ was.\n\tIf the states are not orthonormal there is no quantum measurement capable of distinguishing the states. \n\tIf the states $\\ket{\\psi_1}$ and $\\ket{\\psi_2}$ are not orthogonal, then $\\ket{\\psi_2}$ has a component orthogonal to $\\ket{\\psi_1}$, and also a component parallel to it.\n\tThis will lead to a non-zero probability of measuring a value on $\\ket{\\psi_1}$ for the state $\\ket{\\psi_2}$.\n\n\t\\begin{xmpl}\\cite{NC10}\n\t\t\\begin{equation*} \n\t\t\tZ = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix} \\quad P_{+1} = \\proj{0} , \\; P_{-1} = \\proj{1}\n\t\t\\end{equation*}\n\t\tMeasurement on qubit $ \\ket{\\psi} = \\frac{\\ket0 + \\ket1}{\\sqrt{2}} $ has probability $p_{+1} = \\bra{\\psi}P_{+1}\\ket{\\psi} = \\bk{\\psi}{0}\\bk{0}{\\psi} = \\frac{1}{2}$ and similarly $p_{-1} = \\frac{1}{2}$\n\t\t\t\n\t\\end{xmpl}\n    \n\t\\subsubsection*{Linear operators}\n\tA linear operator between two vector spaces is defined as \n\t$$ \\mathbf{A}: V\\longrightarrow W \\text{  ,  }\\ket{v_i}\\mapsto A\\ket{v_i}$$\n\t$$ \\text{ linear in all inputs, i.e.  }  A\\left( \\sum_i a_i\\ket{v_i}\\right) = \\sum_i a_i A\\ket{v_i} \\text{  for all } i $$ \n\tLooking back at the definition of the matrix $ A = \\ketbra{w}{v}$ we can now refer to it as a linear operator from now on.\n\tSome well-known linear operators acting on single qubits that we will use later on are the \\textit{Pauli Matrices}\n\t$$ I = \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\t \\quad   X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$$\n\t$$ Y= \\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}\t \\quad   Z = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}$$\n\t\n\tIn particular it is safe to say that, unless stated otherwise, the operators that will be presented all have a set of properties and are called Hermitian operators, or \\emph{self-adjoint operators}.\n\t$$ A = A^{\\dagger} \\quad \\Longrightarrow (A\\ket{v})^{\\dagger} = \\bra{v}A^{\\dagger} $$ \n\tOperators have also to be positive, this means that it holds, for every $\\ket{v}$, $\\bra{v}A\\ket{v}$ is real non-negative. \n \n\\section{Mixed states}\n\tAll pure states in QM are normalized vectors in $\\H$.\n\t$$ \\ket{\\psi} \\text{ is a state vector } \\Rightarrow \\ket{\\psi}\\in\\H \\text{ and }  \\vert\\bk{\\psi}{\\psi}\\vert = 1$$\n\tThis is instrumental in seeing them as probability vectors. \n\tEvery linear operator has then to be unitary to maintain this property.\n\tA statistical mixture of states corresponds to a \\emph{density matrix}, which is itself a new state. \n\tIt is important to note that a mixture of probability of states is not the same thing as superposition of states. In the latter we don't have a measure of uncertainty of the state, meaning also that in theory we are always able to find a measurement basis that will always output the same result for that state. \n\tIn the former, however, this is not possible because of the intrinsic uncertainty of the state.\n\tDensity matrices have then the properties:\n\t$$ M = \\rho = \\sum_i p_i \\ketbra{\\psi_i}{\\psi_i} = \\sum_i p_i P_{\\ket{\\psi_i}} \\text{  , where state }\\ket{\\psi_i}\\text{ has probability } p_i $$ \n\t$\\rho$ is a positive, trace-1 operator meaning that $\\Tr(\\rho) = 1$ and all eigenvalues of $\\rho$ are positive. \n\tMoreover $\\rho$ is a linear combination of projectors $\\proj{\\psi_i}$ which makes $\\rho\\in\\mathbb{P}(\\H)$ a projector itself on the the Hilbert space.\n\n%\\section{Quantum entanglement}\n%\n%\t\\begin{quotation}\n%\t\tThere exist vectors in $V\\otimes W$ that can not be represented by a single tensor product:\n%\t\tGiven $v_1,v_2\\in V \\; w_1,w_2\\in W$ linear independent:\n%    \\begin{equation*}\n%\t\tv_1\\otimes w_1 + v_2\\otimes w_2 = v_1w_1 + v_2w_2 \\in V\\otimes W\n%    \\end{equation*}\n%    is \\emph{not} separable.\n%\t\tthis may be strange because on physical level tensor product is combination(merging) of quantum systems\n%\t\t\\end{quotation}\\cite{Han13}", "meta": {"hexsha": "bd5d12d704c67d92b6719d6569adb3275f7b9e59", "size": 9779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writings/chapters/appendixB.tex", "max_stars_repo_name": "CrashingBrain/BSc_Project", "max_stars_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_stars_repo_licenses": ["FSFAP"], "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/chapters/appendixB.tex", "max_issues_repo_name": "CrashingBrain/BSc_Project", "max_issues_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_issues_repo_licenses": ["FSFAP"], "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/chapters/appendixB.tex", "max_forks_repo_name": "CrashingBrain/BSc_Project", "max_forks_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.8629032258, "max_line_length": 343, "alphanum_fraction": 0.7049800593, "num_tokens": 3024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6416997542074672}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nNature laughs at the difficulties of integration.\n\\byline{Pierre-Simon Laplace} % what's the original source for this quotation?\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  What does it mean to say that $\\Omega \\subset \\C$ is connected?  Is path-connected?  \n  \\end{problem}\n  \\begin{solution}\n  $\\Omega\\subset \\C$ is said to be connected if, for any two disjoint open sets $U,V\\in \\C$ containing $\\Omega$ in their union, either $U\\cap \\Omega$ or $V\\cap \\Omega$ is empty.\n  \\end{solution}\n  \\begin{problem}\n    What is a piecewise-smooth \\textbf{curve}?  When are two curves ``the same''?  \n    \\end{problem}\n    \\begin{solution}\n    A smooth curve is a smooth function $f$ from an interval $[t_0, t_1]: t_0, t_1\\in\\R$ to the complex numbers $\\gamma(t)\\in \\C$ such that $\\gamma'(t)\\neq 0$ at any point $t$.A piecewise smooth curve is the function defined on the interval $[t_0, t_n]$ by $n$ smooth curves $$\\gamma_i:[t_{i-1}, t_i]\\mapsto \\C$$ satisfying $\\gamma_{i-1}(t_{i}) = \\gamma_{i}(t_{i})$ for $i\\in [1, n]$.\n\n    Two curves $\\gamma_a:[a_0, a_1] \\mapsto \\C, \\gamma_b:[b_0, b_1]\\mapsto \\C$ are said to be the same if there is a differentiable function $f: [a_0, a_1] \\mapsto [b_0, b_1]$ such that $\\forall t\\in [a_0, a_1], \\gamma_a(t) = \\gamma_b(f(t))$.\n    \\end{solution}\n    \\begin{problem}\n        Define $\\int_\\gamma f(z) \\, dz$ and define $\\int_\\gamma f(z) \\, dx$ and define $\\int_\\gamma f(z) \\, dy$.\n        \\end{problem}\n        \\begin{solution}\n        First, some notation for $\\gamma$. Define $\\gamma:[a,b]\\to \\{x + iy:x, y \\in \\R\\}$. Then\n        \\begin{align*}\n        \\int_\\gamma f(z) \\, dz &:= \\int_{a}^b \\gamma'(t)f(\\gamma(t)) \\, dt\\quad \\color{purple}\\text{ complex derivative }\\\\\n        \\int_\\gamma f(z) \\, dx &:= \\int_{a}^b \\gamma_x(t)f(\\gamma(t)) \\, dt\\quad\\color{purple}\\text{ first coordinate derivative }\\\\\n        \\int_\\gamma f(z) \\, dy &:= i\\int_{a}^b \\gamma_y(t)f(\\gamma(t)) \\,dt\\quad \\color{purple}\\text{ second coordinate derivative }\n        \\end{align*}\n        \\end{solution}\n        \\begin{problem}\n          Define $\\int_\\gamma f(z) \\, d\\conj{z}$.\n          \\end{problem}\n          \\begin{solution}\n          \\begin{align*}\n          \\int_\\gamma f(z) \\, \\conj{dz} &:= \\conj{\\int_{a}^b \\gamma'(t)\\conj{f(\\gamma(t))} \\, dt}\\\\\n          \\end{align*}\n\n          \\end{solution}\n          \\begin{problem}\n            Define $\\int_\\gamma f(z) \\, \\abs{dz}$.\n            \\end{problem}\n            \\begin{solution}\n            \\begin{align*}\n            \\int_\\gamma f(z) \\, \\abs{dz} &:= \\int_{a}^b \\abs{\\gamma'(t)}f(\\gamma(t)) \\,dt \\\\\n            \\end{align*}\n            \\end{solution}\n\n            \\begin{problem}\n              What does it mean to say that a $1$-form is \\textbf{exact}?\n              \\end{problem}\n              \\begin{solution}\n              $f(z)\\,dz$ is \\textbf{exact} if there it has a \\textbf{primitive} - a complex differentiable function $F(z)$ such that $\\frac{d}{dz} F(z) = f(z)$.\n              \\end{solution}\n              \\begin{problem}\n                What are the \\textbf{poles} and \\textbf{zeros} of a rational\n                  function $p(z)/q(z)$?\n                  \\end{problem}\n                  \\begin{solution}\n                  Assuming that $p(z)$ and $q(z)$ share no zeros as part of the definition of a rational function:\n                  The \\textbf{poles} of $p(z)/q(z)$ are the points at which $q(z)=0$. The $\\textbf{zeros}$ are the points at which $p(z)=0$.\n                  \\end{solution}\n\n                  \\section{Numericals}\n\n                  \\begin{problem}\n                  Consider a piecewise smooth curve $\\gamma$ tracing the boundary of the square\n                    $$S = \\{ z = x+iy\\in \\C : \\abs{x} \\mbox{ and } \\abs{y} \\leq 1 \\}.$$\n                      Compute $\\displaystyle\\int_\\gamma \\frac{1}{z} \\, dz$ by hand.\n                      \\end{problem}\n                      \\begin{solution}\n                      Going counter-clockwise, we recognize $\\gamma = \\gamma_1 + \\gamma_2 + \\gamma_3 + \\gamma_4$ with $\\gamma_i$ defined on the interval $[-1, 1]$ satisfying\n                      \\begin{align*}\n                      \\gamma_1 = 1 + it &\\qquad \\gamma_3 = -1 - it \\\\\n                      \\gamma_2 = -t + i  &\\qquad \\gamma_4 = t - i\n                      \\end{align*}\n                      Now we can compute the integral:\n                      \\begin{align*}\n                      \\int_{\\gamma} \\frac{1}{z} \\, dz \n                      &= \\int_{-1}^1 \\frac{\\gamma_1'}{1 + it} \\, dt +\n                      \\int_{-1}^1 \\frac{\\gamma_2'}{-t + i} \\, dt +\n                      \\int_{-1}^1 \\frac{\\gamma_3'}{-1 - it} \\, dt +\n                      \\int_{-1}^1 \\frac{\\gamma_4'}{t - i} \\, dt\\\\\n                      &= \\int_{-1}^1 \\frac{i}{1 + it} \\, dt +\n                      \\int_{-1}^1 \\frac{-1}{-t + i} \\, dt +\n                      \\int_{-1}^1 \\frac{-i}{-1 - it} \\, dt +\n                      \\int_{-1}^1 \\frac{1}{t - i} \\, dt\\\\\n                      &= \\int_{-1}^1 \\frac{4}{t - i} \\, dt\\\\\n                      &= 4\\Log(t - i)|_{t=-1}^1\\color{purple}\\text{ Log is analytic in an open set containing [-1, 1]} \\\\\n                      &= 4(\\Log(1 - i)  - \\Log(-1 - i))\\\\\n                      &= 4((\\sqrt{2} + i7\\pi/4) - (\\sqrt{2} + i5\\pi/4))\\\\\n                      &= 4(i\\pi/2) = 2\\pi i\n                      \\end{align*}\n\n                      \\end{solution}\n                      \\begin{problem}\\label{integral-powers-of-z}Consider the curve $\\gamma : [0,2\\pi] \\to \\C$ given by $\\gamma(\\theta) = e^{i\\theta}$.  For an integer $n \\in \\Z$, compute $\\displaystyle\\int_\\gamma z^n \\, dz$ and $\\displaystyle\\int_\\gamma \\conj{z}^n \\, dz$.\n                      \\end{problem}\n                      \\begin{solution}\n                      \\begin{align*}\n                      \\int_\\gamma z^ndz &= \\int_{0}^{2\\pi} \\gamma'(\\theta) e^{i\\theta n} d\\theta\\\\\n                      &= i\\int_{0}^{2\\pi}e^{i(1+n)\\theta} d\\theta\\\\\n                      &= \\begin{cases}i\\int_{0}^{2\\pi} e^{i(1+n)\\theta} d\\theta & n \\neq -1\\\\\n                      i\\int_{0}^{2\\pi} 1 d\\theta & n = -1 \\end{cases}\\\\\n                      &= \\begin{cases} 0 & n \\neq -1\\\\\n                      2\\pi i & n = -1 \\end{cases}\n                      \\end{align*}\n                      For the second integral,\n                      \\begin{align*}\n                      \\int_\\gamma \\conj{z}^ndz &= \\int_{0}^{2\\pi} \\gamma'(\\theta) e^{-i\\theta n} d\\theta\\\\\n                      &= i\\int_{0}^{2\\pi}e^{i(1-n)\\theta} d\\theta\\\\\n                      &= \\begin{cases}i\\int_{0}^{2\\pi} e^{i(1-n)\\theta} d\\theta & n \\neq 1\\\\\n                      i\\int_{0}^{2\\pi} 1 d\\theta & n = 1 \\end{cases}\\\\\n                      &= \\begin{cases} 0 & n \\neq 1\\\\\n                      2\\pi i & n = 1 \\end{cases}\n                      \\end{align*}\n                      \\end{solution}\n\n                      \\begin{problem}\\label{one-over-z-around-circle}Let $\\gamma:[a, b]\\mapsto \\C$ be a (positively oriented) parametrization of a circle\n                        in the plane, and suppose the image of $\\gamma$ does not include the\n                          origin.  Compute $\\displaystyle\\int_\\gamma \\frac{1}{z} \\, dz$.\n                          \\end{problem}\n                          \\begin{solution}\n                          Since $\\gamma$ is a positively oriented parameterization of a circle, we can find a differentiable map $f:[a,b]\\mapsto [0, 2\\pi]$ such that $r(e^{if(t)} + z)= \\gamma(t)$, where $r\\in\\R$ is the radius of and $rz$ is the center of the circle parameterized by $\\gamma$.\n                          \\begin{align*}\n                          \\int_\\gamma \\frac{1}{z} \\, dz &= \\int_a^{b} \\frac{\\frac{d}{dt}\\gamma(t)}{\\gamma(t)}dt\\\\\n                          &= \\int_a^{b} \\frac{\\frac{d}{dt}(re^{if(t)}+ rz)}{re^{if(t)} + rz}dt\\\\\n                          &= \\int_a^{b} \\frac{if'(t)e^{if(t)}}{e^{if(t)} + z}dt\\\\\n                          &= \\int_0^{2\\pi} \\frac{ie^{iu}}{e^{iu} +  z}du \\quad \\color{purple} u=f(t), du = f'(t) dt\\\\\n                          &= \\log(e^{ui} + z)\\big|_{u=0}^{2\\pi}\n                          \\end{align*}\n                          Though we may be a bit suspcious about which log we are using. However, since the interior of $\\gamma$ does not contain the origin, we can choose a branch of the log such that the angle which has a discontinuity is disjoint from the set of $\\theta$ that satisfy $re^{i\\theta}= e^{ui} +z$ for some $r, u$. Then the value of the above integral is 0 since $e^0 = e^{2\\pi i}$.\n\n                          On the other hand, if the image does include the origin, we can imagine that the argument of the parameter passed to log will continuously increase by $2\\pi$, so if we switch branches of the log at the place that the derivative is continuous, the difference between the start and end point will be exactly $2\\pi i$.\n\n                          \\end{solution}\n                          \\begin{problem}\\label{lacunary-series}What is radius $R$ of convergence of\n                            $\\displaystyle\\sum_{n=1} x^{(n!)}$?  (This is a \\textbf{lacunary\n                                series} with large gaps between nonzero terms.)\n                                \\end{problem}\n                                \\begin{solution}\n                                We use the following fact: the radius of convergence of a power series $R$ satisfies\n                                \\[\\frac{1}{R} = \\limsup_{k\\to \\infty} \\sqrt[k]{|x_k|}\\]\n                                So we need to compute \n                                \\[\\limsup_{n\\to \\infty} \\sqrt[n!]{1} = 1\\]\n                                Therefore, the radius of convergence is 1.\n                                \\end{solution}\n\n                                \\section{Exploration}\n\n                                \\begin{problem}For the series in \\ref{lacunary-series}, find a dense\n                                  subset of the circle $\\{ z \\in \\C : \\abs{z} = 1 \\}$ where the series\n                                    diverges.\n                                    \\end{problem}\n                                    \\begin{solution}\n                                    Let $z=e^{2i\\pi \\theta}$ with $\\theta$ some rational number $n/m$, this is a dense subset of the circle. Note that for $x>=m$, \n                                    \\[z^x = (e^{2i\\pi n/m})^{x!} = z^x = e^{(2i\\pi n)*(x!/m)} = 1\\],\n                                    so we are taking a sum of a 1 infinitely many times, which does not seem like a good sign for convergence.\n                                    \\end{solution} \n\n                                    \\begin{problem}\n                                      For which $z \\in \\C$ with $|z|=1$ does the series\n                                        $\\displaystyle\\sum_{n=0}^{\\infty} \\frac{z^n}{n}$ converge?  Diverge?\n                                        \\end{problem}\n                                        \\begin{solution}\n                                        If $z=1$ then it's the harmonic series so it diverges. Otherwise it goes in a big spiral that obviously converges. But how to prove... Let's check by letting $z=e^{i\\theta}, \\theta\\neq 0$ and using the integral test (checking if the integral from some lower bound to infinity is finite). It suffices to show that the real and imaginary part converge. For the imaginary part:\n                                        \\begin{align*}\n                                        \\int_{\\pi/\\theta}^\\infty \\frac{\\sin(x\\theta)}{x} dx &=\n                                        \\sum_{k=1}^\\infty (\\int_{(2k + 1)\\pi /\\theta}^{(2k+2)\\pi/\\theta} \\frac{\\sin(x\\theta)}{x} dx +\n                                        \\int_{2k\\pi/\\theta}^{(2k + 1)\\pi/\\theta} \\frac{\\sin(x\\theta)}{x} dx)\n                                        \\end{align*}\n                                        Setting $u=x\\theta, du = \\theta dx$:\n                                        \\begin{align*}\n                                        \\int_{\\pi/\\theta}^\\infty \\frac{\\sin(x\\theta)}{x} dx &= \\sum_{k=1}^\\infty (\\int_{(2k + 1)\\pi}^{(2k+2)\\pi} \\frac{\\sin(u)}{u} du +\n                                        \\int_{2k\\pi}^{(2k + 1)\\pi} \\frac{\\sin(u)}{u} du)\\\\\n                                        &= \\sum_{k=1}^\\infty \\int_{(2k + 1)\\pi}^{(2k+2)\\pi} \\sin(u)(\\frac{1}{u} - \\frac{1}{u-\\pi}) du  \\color{purple} \\text{ note it's negative}\\\\\n                                        &\\geq -\\sum_{k=1}^\\infty \\int_{(2k + 1)\\pi}^{(2k+2)\\pi} (\\frac{1}{(2k+2)\\pi} - \\frac{1}{2k\\pi}) du \\\\\n                                        &= \\sum_{k=1}^\\infty \\frac{1}{(2k+2)} - \\frac{1}{2k} du = -\\frac{1}{2}\n                                        \\end{align*}\n                                        This integral is finite so the imaginary part of the series converges. An analogous argument with cosine shows that the real part of the series converges, so the series must converge in the complex plane.\n                                        \\end{solution}\n\n\n                                        \\begin{problem}\n                                        Suppose $f : \\C \\to \\C$ is a rational function which\n                                          sends the unit circle to the real line, i.e., for $z \\in \\C$ with\n                                            $|z| = 1$ we have $f(z) \\in \\R$.  Inspired\n                                              by \\ref{schwarz-reflection-principle}, compute\n                                                $\\overline{f(1/\\conj{z})}$ and then discuss the relationship between\n                                                  the poles and zeros of $f$.\n                                                  \\end{problem}\n                                                  \\begin{solution}\n                                                  If $|z|=1$, then $f(z)=\\conj{f(z)}$ and $1/\\conj{z} = z$. Thus\n                                                  $\\conj{f(1/\\conj{z})} = f(z)$ on the unit circle. Since these are rational functions that agree on an infinite set of points, they must be equal everywhere.\n\n                                                  Thus for any zero or pole $z_0$ of $f$, there is another zero or pole respectively at $\\frac{1}{\\conj{z_0}}= \\frac{z_0}{|z_0|}.$\n                                                  \\end{solution}\n                                                  \\begin{problem}\n                                                  In lecture, we briefly saw an example (the\n                                                    \\textbf{topologist's sine curve}) of a subset of $\\mathbb{C}$ which\n                                                      is connected but not path-connected.  For open subsets of\n                                                        $\\mathbb{C}$, what is the relationship between connectedness and\n                                                          path-connectedness?\n                                                          \\end{problem}\n                                                          \\begin{solution}\n                                                          If a open subset of $\\C$ is path-connected, it's also connected: For contradiction, suppose there was a disconnection formed from disjoint open sets $U$, $V$. Choosing points $P_U \\in U, P_V \\in V$, there is a path $f:[0, 1]\\mapsto \\C$ from $P_U$ to $P_V$. Let $s = \\sup x\\in [0,1]: f(x) \\in U$. s is not 1 since $f$ is continuous and there is a ball around $f(1)$ contained in $V$. Hence by the defintion of sup, we can find an infinite sequence $u_i \\in [0, 1]$ with $f(u_i) \\in U$ that converges to $s$ and any sequence of points $v_i \\in [0, 1]$ with $v_i < s$ converging to $s$ has $f(v_i) \\in V$, so $f(s)$ is a boundary point of both $U$ and $V$ contained in either $U$ or $V$, a contradiction.\n\n                                                          Next we show that if a open subset of $S\\in \\C$ is connected, it's also path-connected. For each point $p \\in S$, define $P$ to be the set of points that we can reach from $p$. $P$ is open since if we can reach any point by a path, we can also reach any point from $p$, then we can also reach any point in the (convex) open ball surrounding that point.\n\n                                                          Now consider the complement $S/P$. This set is also open - supposing that we can't reach a point $s\\in S/P$, then we can't reach any point in the open ball surrounding that point. So $P=(S/P)\\cup S$ is a union of two disjoint open sets. As $P$ is connected, this implies that one of the $S/P$ and $S$ is empty, and as $s\\in S$, this implies $S/P = \\empty$ and $S=P$. Recalling the definition of $P$, we can reach any point in $S$ by a path starting at $p$, so we can reach any point from any other point by going first to $p$ and then to the second point.\n                                                          \\end{solution}\n                                                          \\begin{problem}\\label{argument-principle-numerical}Consider $\\gamma : [0,2\\pi] \\to \\C$ given by $\\gamma(\\theta) = e^{i\\theta}$.  For an integer $n \\in \\Z$ and $f(z) = z^n$, compute\n                                                            \\[\n                                                                \\frac{1}{2\\pi i} \\displaystyle\\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz\n                                                                  \\]\n                                                                    in two different ways.  First, evaluate $f'(z)/f(z)$ and invoke\n                                                                      \\ref{integral-powers-of-z}.  Second, describe a curve $\\gamma_n$ and\n                                                                        interpret $\\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz$ as\n                                                                          $\\int_{\\gamma_n} dz/z$ for that different curve $\\gamma_n$.  (This\n                                                                            is our first glimpse of the \\textbf{argument principle}.)\n                                                                            \\end{problem}\n                                                                            \\begin{solution}\n                                                                            \\[\\frac{f'(z)}{f(z)} = \\frac{nz^{n-1}}{z^n} = \\frac{n}{z}\\]\n                                                                            Then using \\ref{integral-powers-of-z}, the integral's value is $n$.\n\n                                                                            Next, consider going along the curve $\\gamma_n = f\\circ \\gamma$, it's the path that $f(z)$ traces out as we go along the curve. Algebraically, let $u = f(z)$ so $du = f'(z) dz.$\n                                                                            Then\n                                                                            \\[\n                                                                            \\int_{\\gamma} \\frac{f'(z)}{f(z)}dz =  \\int_{\\gamma_n} \\frac{1}{u} du = \\int \\frac{\\gamma_n'(t)}{\\gamma_n(t)}dt = \\int_0^{2\\pi} \\frac{ine^{int}}{e^{int}}dt = 2in\\pi\n                                                                            \\]\n                                                                            Dividing out by $2in\\pi$, the value of the integral we were given is $n$. \n                                                                            \\end{solution}\n\n                                                                            \\begin{problem}\\label{one-over-z-w-around-circle}\n                                                                              Consider the curve $\\gamma : [0,2\\pi] \\to \\C$ given by $\\gamma(\\theta) = e^{i\\theta}$.  For $w \\in \\C$ with $|w| \\neq 1$, compute\n                                                                                \\[\n                                                                                    \\frac{1}{2\\pi i} \\displaystyle\\int_\\gamma \\frac{1}{z-w} \\, dz\n                                                                                      \\]\n                                                                                        perhaps by invoking \\ref{one-over-z-around-circle}.\n                                                                                        \\end{problem}\n                                                                                        \\begin{solution}\n                                                                                        Let $v = z - w,$ so $dv = dz$. Defining the function $\\gamma_2(t) := \\gamma(t) - w$, we see that \n                                                                                        \\[\\int_\\gamma \\frac{1}{z-w}dz =  \\int_{\\gamma_2} \\frac{1}{v}dv\\]\n                                                                                        This is exactly the integral of a circle, and \\ref{one-over-z-around-circle} shows that if the circle doesn't include the origin, then the integral is 0 and otherwise, (the specific proof I did shows), it is $\\frac{1}{2\\pi i}$. Thus\n                                                                                        \\[\n                                                                                        \\frac{1}{2\\pi i} \\displaystyle\\int_\\gamma \\frac{1}{z-w} \\, dz = \\begin{cases}1 & |w| < 1\\\\ 0 & |w| > 1\\end{cases}.\n                                                                                        \\]\n                                                                                        \\end{solution}\n\n                                                                                        \\begin{problem}\n                                                                                          Yet again consider the curve $\\gamma : [0,2\\pi] \\to \\C$ given by $\\gamma(\\theta) = e^{i\\theta}$.  For distinct $w_1, w_2 \\in \\C$ with $\\abs{w_1} \\neq 1$ and $\\abs{w_2} \\neq 1$, let $f(z) = (z - w_1) (z - w_2)$ and compute\n                                                                                            \\[\n                                                                                                \\frac{1}{2\\pi i} \\displaystyle\\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz.\n                                                                                                  \\]\n                                                                                                  \\end{problem}\n                                                                                                  \\begin{solution}\n                                                                                                  Let $\\gamma' = f\\circ \\gamma = (e^{i\\theta} - w_1)(e^{i\\theta} - w_2)$, and make the subsitution $w=f(z)$ so $dw = f'(z)dz$.\n                                                                                                  Then\n                                                                                                  \\begin{align*}\n                                                                                                  \\frac{1}{2\\pi i} \\int_\\gamma \\frac{f'(z)}{f(z)} \\, dz\n                                                                                                  &= \\frac{1}{2\\pi i} \\int_{\\gamma_1}\\frac{1}{w} \\, dw\\\\\n                                                                                                  &= \\frac{1}{2\\pi i} \\int_0^{2\\pi} \\frac{\\gamma_1'(t)}{\\gamma_1(t)} \\, dt\\\\\n                                                                                                  &= \\frac{1}{2\\pi i} \\int_0^{2\\pi} \\frac{ie^{i\\theta} - w_1}{e^{i\\theta}} + \\frac{ie^{i\\theta}}{e^{i\\theta} - w_1} \\, dt\\\\\n                                                                                                  &= \\frac{1}{2\\pi i} (\\int_0^{2\\pi} \\frac{ie^{i\\theta}}{e^{i\\theta} - w_1} dt + \\int_0^{2\\pi} \\frac{ie^{i\\theta}}{e^{i\\theta} - w_1}dt )\\\\\n                                                                                                  &= \\frac{1}{2\\pi i} (\\int_{\\gamma} \\frac{1}{z - w_1} dt + \\int_{\\gamma} \\frac{1}{z - w_1}dt )\n                                                                                                  \\end{align*}\n                                                                                                  Invoking \\ref{one-over-z-w-around-circle}, this is\n                                                                                                  \\[\\left(\\begin{cases}1 & |w_1| < 1\\\\ 0 & |w_1| > 1\\end{cases} \\right) +\n                                                                                                  \\left(\\begin{cases}1 & |w_2| < 1\\\\ 0 & |w_2| > 1\\end{cases}\\right)\\]\n                                                                                                  \\end{solution}\n\n                                                                                                  \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                  \\begin{problem}\n                                                                                                    If $e^z = e^w$, then $z = w$.\n                                                                                                    \\end{problem}\n                                                                                                    \\begin{solution}\n                                                                                                    False, $e^0 = e^{2\\pi i}= 1$. However, since $e^{x + iy} = e^x(\\cos(y) + i\\sin(y))$, $\\exists \\, k \\, s.t. \\, (e^z = e^w \\implies z = w + 2\\pi ik)$\n                                                                                                    \\end{solution}\n                                                                                                    \\begin{problem}\n                                                                                                      If $f \\, dz$ is exact, then $\\displaystyle\\int_\\gamma f \\, dz = 0$.\n                                                                                                      \\end{problem}\n                                                                                                      \\begin{solution}\n                                                                                                      Additionally we require that $\\gamma$ is a closed curve starting and ending at the same point $p$. In this case, letting $F$ be the antiderivative of $f$,\n                                                                                                      \\begin{align*}\n                                                                                                      \\int_\\gamma f \\, dz \n                                                                                                      &= \\int \\gamma'(t)f(\\gamma(t)) \\, dt \\\\\n                                                                                                      &= \\int_\\gamma \\frac{d}{dt}(F\\circ\\gamma)(t) \\, dt\\\\\n                                                                                                      &= (F\\circ\\gamma)(\\gamma(p) - \\gamma(p)) = 0\n                                                                                                      \\end{align*}\n                                                                                                      \\end{solution}\n\n                                                                                                      \\begin{problem}% orientation issues\n                                                                                                        Suppose $\\gamma : [0,1] \\to \\C$ is a smooth curve, and $p : [0,1] \\to [0,1]$ is a smooth bijection.\n                                                                                                          Then\n                                                                                                            \\[\n                                                                                                                \\int_\\gamma f(z) \\, dz = \\int_{\\gamma \\circ p} f(z) \\, dz.\n                                                                                                                  \\]\n                                                                                                                  \\end{problem}\n                                                                                                                  \\begin{solution}\n                                                                                                                  If $p(0)=1$, then we will switch the direction of the curve which will make the answer negative. \n\n                                                                                                                  Otherwise, we can prove it as follows.\n                                                                                                                  \\begin{align*}\n                                                                                                                  \\int_{\\gamma \\circ p} f(z) \\, dz &= \\int_0^1 (\\frac{d}{dt}(\\gamma\\circ p) \\times (f \\circ \\gamma \\circ p))t \\,dt\\\\\n                                                                                                                  &= \\int_{0}^1 \\gamma'(p(t))p'(t) (f \\circ \\gamma \\circ p)t\\, dt \\\\\n                                                                                                                  &= \\int_{0}^1 \\gamma'(u) (f \\circ \\gamma)u\\, du \\quad \\color{purple} u=p(t), du = p'(t)dt\\\\\n                                                                                                                  &= \\int_{\\gamma} f(z) \\, dz\n                                                                                                                  \\end{align*}\n                                                                                                                  \\end{solution}\n\n\n\n                                                                                                                    \\begin{problem}\\label{identity-theorem}If $f \\in \\C[z]$ is a polynomial with infinitely many zeros, then\n                                                                                                                        $f \\equiv 0$.\n                                                                                                                          \\end{problem}\n                                                                                                                           \\begin{solution}\n                                                                                                                            By the fundamental theorem of arithmetic, $f$ splits completely in $\\C$ as $\\prod_{i=0}^n (z - r_i)$ where $r_i$ is a root. At any number that's not a root, this product is clearly nonzero unless it is the empty product, so we must have that $f\\equiv 0$.\n                                                                                                                             \\end{solution} \n                                                                                                                             \\end{document}\n\n", "meta": {"hexsha": "50c1c4aade17a405ef6761d2665c4a85baadb669", "size": 31676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol3.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/sol3.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/sol3.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": 95.6978851964, "max_line_length": 759, "alphanum_fraction": 0.3548112135, "num_tokens": 6892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126791, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6416997514750897}}
{"text": "\\documentclass{notes}\n\n  \\title{Collatz Turing Machine}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \n\n  \n\\section*{Language}\n  \\begin{align*}\n    A &= \\{ 0, 1 \\} \\\\\n    T &= A \\ \\cup \\ \\{ , \\} \\ \\cup \\  \\{ \\blm,  X \\} \\\\\n    L &= \\{1, 10, 11, 100, 101, 110, 111, 1000, 1001, \\ldots \\} \\\\\n    f(s) &= 1s,s \\\\\n  \\end{align*}\n\n\\section*{Duplicate and append 1}\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Append a comma. \\\\\n    \\( q_1 \\) & Move left to start. \\\\\n    \\( q_2 \\) & Check if 0 or 1, mark X. \\\\\n    \\( q_3 \\) & Move right to end, append 0. \\\\\n    \\( q_4 \\) & Move right to end, append 1. \\\\\n    \\( q_5 \\) & Move left to X, overwrite 0, back to \\(q_2\\). \\\\\n    \\( q_6 \\) & Move left to X, overwrite 1, back to \\(q_2\\). \\\\\n    \\( q_7 \\) & Move to start, prepend 1. \\\\\n    \\( q_8 \\) & Back to start, end. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % Right to Write a comma at end on input.\n      \\(q_0\\) & \\bl &   , & L & \\(q_1\\) \\\\\n      \\(q_0\\) &   0 &   0 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Left to start.\n      \\(q_1\\) & \\bl & \\bl & R & \\(q_2\\) \\\\\n      \\(q_1\\) &   0 &   0 & L & \\(q_1\\) \\\\\n      \\(q_1\\) &   1 &   1 & L & \\(q_1\\) \\\\\n      \\(q_1\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_1\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Overwrite first symbol with X.\n      \\(q_2\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_2\\) &   0 &   X & R & \\(q_3\\) \\\\\n      \\(q_2\\) &   1 &   X & R & \\(q_4\\) \\\\\n      \\(q_2\\) &   , &   , & R & \\(q_7\\) \\\\\n      \\(q_2\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Left to write a 0 at the end.\n      \\(q_3\\) & \\bl &   0 & L & \\(q_5\\) \\\\\n      \\(q_3\\) &   0 &   0 & R & \\(q_3\\) \\\\\n      \\(q_3\\) &   1 &   1 & R & \\(q_3\\) \\\\\n      \\(q_3\\) &   , &   , & R & \\(q_3\\) \\\\\n      \\(q_3\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Left to write a 1 at the end.\n      \\(q_4\\) & \\bl &   1 & L & \\(q_6\\) \\\\\n      \\(q_4\\) &   0 &   0 & R & \\(q_4\\) \\\\\n      \\(q_4\\) &   1 &   1 & R & \\(q_4\\) \\\\\n      \\(q_4\\) &   , &   , & R & \\(q_4\\) \\\\\n      \\(q_4\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Left to the X, overwrite with 0\n      \\(q_5\\) & \\bl & \\bl & L & \\(q_f\\) \\\\\n      \\(q_5\\) &   0 &   0 & L & \\(q_5\\) \\\\\n      \\(q_5\\) &   1 &   1 & L & \\(q_5\\) \\\\\n      \\(q_5\\) &   , &   , & L & \\(q_5\\) \\\\\n      \\(q_5\\) &   X &   0 & R & \\(q_2\\) \\\\\n      \\midrule\n      % Left to the X, overwrite with 1\n      \\(q_6\\) & \\bl & \\bl & L & \\(q_f\\) \\\\\n      \\(q_6\\) &   0 &   0 & L & \\(q_6\\) \\\\\n      \\(q_6\\) &   1 &   1 & L & \\(q_6\\) \\\\\n      \\(q_6\\) &   , &   , & L & \\(q_6\\) \\\\\n      \\(q_6\\) &   X &   1 & R & \\(q_2\\) \\\\\n      \\midrule\n      % Left to start, prepend 1.\n      \\(q_7\\) & \\bl &   1 & L & \\(q_8\\) \\\\\n      \\(q_7\\) &   0 &   0 & L & \\(q_7\\) \\\\\n      \\(q_7\\) &   1 &   1 & L & \\(q_7\\) \\\\\n      \\(q_7\\) &   , &   , & L & \\(q_7\\) \\\\\n      \\(q_7\\) &   X &   X & L & \\(q_7\\) \\\\\n      \\midrule\n      % Back to start, accept.\n      \\(q_8\\) & \\bl & \\bl & R & \\(q_a\\) \\\\\n      \\(q_8\\) &   0 &   0 & R & \\(q_f\\) \\\\\n      \\(q_8\\) &   1 &   1 & R & \\(q_f\\) \\\\\n      \\(q_8\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_8\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n    \n\\section*{Add}\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Right to comma. \\\\\n    \\( q_1 \\) & Decrease by 1, go to final states if no 1. \\\\\n    \\( q_2 \\) & Left to start. \\\\\n    \\( q_3 \\) & Increase by 1, use X as comma if overflow. \\\\\n    \\( q_4 \\) & Delete to comma/X, replace X with 1. \\\\\n    \\( q_5 \\) & Left to start. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % Right to comma/X.\n      \\(q_0\\) & \\bl & \\bl & L & \\(q_f\\) \\\\\n      \\(q_0\\) &   0 &   0 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_1\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_1\\) \\\\\n      \\midrule\n      % Decrease by 1, go to final states if no 1.\n      \\(q_1\\) & \\bl & \\bl & L & \\(q_4\\) \\\\\n      \\(q_1\\) &   0 &   1 & R & \\(q_1\\) \\\\\n      \\(q_1\\) &   1 &   0 & L & \\(q_2\\) \\\\\n      \\(q_1\\) &   , &   , & L & \\(q_f\\) \\\\\n      \\(q_1\\) &   X &   X & L & \\(q_f\\) \\\\\n      % Left to start.\n      \\(q_2\\) & \\bl & \\bl & R & \\(q_3\\) \\\\\n      \\(q_2\\) &   0 &   0 & L & \\(q_2\\) \\\\\n      \\(q_2\\) &   1 &   1 & L & \\(q_2\\) \\\\\n      \\(q_2\\) &   , &   , & L & \\(q_2\\) \\\\\n      \\(q_2\\) &   X &   X & L & \\(q_2\\) \\\\\n      \\midrule\n      % Increase by 1 - use X in place of comma if overflow.\n      \\(q_3\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_3\\) &   0 &   1 & R & \\(q_0\\) \\\\\n      \\(q_3\\) &   1 &   0 & R & \\(q_2\\) \\\\\n      \\(q_3\\) &   , &   X & L & \\(q_0\\) \\\\\n      \\(q_3\\) &   X &   X & L & \\(q_f\\) \\\\\n      \\midrule\n      % Delete to and including comma/X - replace X with 1.\n      \\(q_4\\) & \\bl & \\bl & L & \\(q_f\\) \\\\\n      \\(q_4\\) &   0 & \\bl & L & \\(q_4\\) \\\\\n      \\(q_4\\) &   1 &   1 & L & \\(q_f\\) \\\\\n      \\(q_4\\) &   , & \\bl & L & \\(q_5\\) \\\\\n      \\(q_4\\) &   X &   1 & L & \\(q_5\\) \\\\\n      \\midrule\n      % Left to start.\n      \\(q_5\\) & \\bl & \\bl & R & \\(q_a\\) \\\\\n      \\(q_5\\) &   0 &   0 & L & \\(q_5\\) \\\\\n      \\(q_5\\) &   1 &   1 & L & \\(q_5\\) \\\\\n      \\(q_5\\) &   , &   , & L & \\(q_f\\) \\\\\n      \\(q_5\\) &   X &   X & L & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n\n  \\section*{Divide by two}\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Delete 0, move right. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % Delete 0, move right.\n      \\(q_0\\) & \\bl & \\bl & L & \\(q_f\\) \\\\\n      \\(q_0\\) &   0 & \\bl & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n \n  \\section*{Remove leading zeros}\n  Fails on string meaning zero.\n\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Move right to end. \\\\\n    \\( q_1 \\) & Delete zeros. \\\\\n    \\( q_2 \\) & Left to end. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % Right to end.\n      \\(q_0\\) & \\bl & \\bl & L & \\(q_1\\) \\\\\n      \\(q_0\\) &   0 &   0 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_0\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Delete zeros.\n      \\(q_1\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_1\\) &   0 & \\bl & L & \\(q_0\\) \\\\\n      \\(q_1\\) &   1 &   1 & L & \\(q_2\\) \\\\\n      \\(q_1\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_1\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Left to start.\n      \\(q_2\\) & \\bl & \\bl & R & \\(q_a\\) \\\\\n      \\(q_2\\) &   0 &   0 & R & \\(q_2\\) \\\\\n      \\(q_2\\) &   1 &   1 & R & \\(q_2\\) \\\\\n      \\(q_2\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_2\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n\n  \\section*{Check if 1}\n\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Check if first bit 1. \\\\\n    \\( q_1 \\) & Check if second bit blank. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % First bit 1.\n      \\(q_0\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   0 &   0 & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_1\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\midrule\n      % Check if blank.\n      \\(q_1\\) & \\bl & \\bl & L & \\(q_a\\) \\\\\n      \\(q_1\\) &   0 &   0 & L & \\(q_f\\) \\\\\n      \\(q_1\\) &   1 &   1 & L & \\(q_f\\) \\\\\n      \\(q_1\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_1\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n\n  \\section*{Check if even}\n\n  \\begin{tabular}{rl}\n    \\textbf{State} & \\textbf{Description} \\\\\n    \\midrule\n    \\( q_0 \\) & Check if first bit 0. \\\\\n  \\end{tabular}\n\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      % Check 0.\n      \\(q_0\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   0 &   0 & R & \\(q_a\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   , &   , & R & \\(q_f\\) \\\\\n      \\(q_0\\) &   X &   X & R & \\(q_f\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n\n\n  %\\bibliography{bibliography}\n\\end{document}", "meta": {"hexsha": "22ea6504a8602548a403b4113d67dcb6f129fb6c", "size": 9028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "colltaz.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": "colltaz.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": "colltaz.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": 31.6771929825, "max_line_length": 66, "alphanum_fraction": 0.3689632255, "num_tokens": 3911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6416997507630817}}
{"text": "\\section{Termination}\\label{sec:termination}\n\nProgram divergence is, more often than not,\na bug rather than a feature. \n%\nTo account for the common cases, \nby default, \\toolname proves termination of each recursive function.\n%\nFortunately, refinements make this onerous task quite straightforward. \nWe need simply associate a \\emph{well-founded termination metric} % $\\mu$\non the function's parameters, and then use refinement typing to check \nthat the metric strictly decreases at each recursive call. In practice,\ndue to a careful choice of defaults, this amounts to about a line \nof termination-related hints per hundred lines of source. \n%\nIn Chapter~\\ref{chapter:refinedhaskell}\nwe prove soundness of our refinement type based termination checker \nand also we explain how soundness of \\toolname crucially depends on \nthe termination checker. \n%\nHere, we provide an overview on how one can use \\toolname \nto prove termination.\n\n\\mypara{Simple Metrics}\nAs a starting example, consider the @fac@ function\n%\n\\begin{code}\n  fac :: n:Nat -> Nat / [n]\n  fac 0 = 1 \n  fac n = n * fac (n-1)\n\\end{code}\n%\nThe termination metric is simply the parameter @n@; \nas @n@ is non-negative and decreases at the recursive \ncall, \\toolname verifies that @fac@ will terminate.\n%\nWe specify the termination metric in the type signature \nwith the @/[n]@.\n\nTermination checking is performed at the same \ntime as regular type checking, as it can be \nreduced to refinement type checking with a \nspecial terminating fixpoint combinator~\\ref{chapter:refinedhaskell}.\nThus, if \\toolname fails to prove that a given \ntermination metric is well-formed and decreasing, \nit will report a @Termination Check@ @Error@. \n%% \\RJ{Seems untrue -- I just get a plain old liquid type error?\n%% NV: IF you provide termination metrics, you DO get termination check error}.\nAt this point, the user can either debug \nthe specification, or mark the function \nas non-terminating.\n\n\n%%\\mypara{Refinements Enable Termination} \n%%Consider Euclid's GCD:\n%%%\n%%\\begin{code}\n%%  gcd :: a:Nat -> {v:Nat | v < a} -> Nat \n%%  gcd a 0 = a\n%%  gcd a b = gcd b (a `mod` b)\n%%\\end{code}\n%%%\n%%Here, the termination metric is the first parameter @a@.\n%%To prove that @a@ is decreasing requires\n%%the fact that the second parameter is smaller than the first \n%%and that @mod@ returns results smaller than its second \n%%parameter. Both facts are easily expressed as refinements, \n%%but elude non-extensible checkers~\\cite{Giesl11}.\n%%\n%%\\mypara{Explicit Termination Metrics}\n%%The termination metric can be some parameter \\emph{other} than the first \n%%argument.\n%%For example, consider: % As an example, consider the tail-recursive factorial:\n%%%\n%%\\begin{code}\n%%  tfac     :: Nat -> n:Nat -> Nat / [n] \n%%  tfac x 0 = if n == 0 then x\n%%                       else tfac (n*x) (n-1)\n%%\\end{code}\n%%%\n%%%\n%%It can be checked that @n@, \\ie, the second argument is decreasing at each recursive call.\n%%\n\\mypara{Termination Expressions} \nSometimes, no single parameter decreases across recursive calls,\nbut there is some \\emph{expression} that forms the decreasing \nmetric.\n%\nFor example recall @range lo hi@ (from \\S~\\ref{sec:tool:verification}) \nwhich returns the list of @Int@s from @lo@ to @hi@:\n%\n\\begin{code}\n  range lo hi \n    | lo < hi   = lo : range (lo+1) hi\n    | otherwise = [] \n\\end{code}\n%\nHere, neither parameter is decreasing (indeed, the first \none is increasing) but @hi-lo@ decreases across each call. \nTo account for such cases, we can specify as the termination\nmetric a (refinement logic) expression over the function\nparameters. Thus, to prove termination, we could type @range@ as:\n\\begin{code}\n  lo:Int -> hi:Int -> [(Btwn lo hi)] / [hi-lo]\n\\end{code}\n\n\\mypara{Lexicographic Termination}\nThe Ackermann function\n%\n\\begin{code}\n  ack m n \n    | m == 0    = n + 1\n    | n == 0    = ack (m-1) 1 \n    | otherwise = ack (m-1) (ack m (n-1))\n\\end{code}\n%\nis curious as there exists no simple, natural-valued, \ntermination metric that decreases at each recursive call.\n%\nHowever @ack@ terminates because at each call \\emph{either}\n@m@ decreases \\emph{or} @m@ remains the same and @n@ decreases. \n%\nIn other words, the pair @(m,n)@ strictly decreases according to a\n\\emph{lexicographic} ordering. \n%\nThus \\toolname supports termination metrics that are a \n\\emph{sequence of} termination expressions. For example, \nwe can type @ack@ as:\n%\n\\begin{code}\n  ack :: m:Nat -> n:Nat -> Nat / [m, n]\n\\end{code}\n%\nAt each recursive call \\toolname uses a lexicographic \nordering to check that the sequence of termination \nexpressions is decreasing (and well-founded in each component).\n\n\\mypara{Mutual Recursion}\n%\nThe lexicographic mechanism lets us check termination of\nmutually recursive functions, \\eg @isEven@ and @isOdd@\n%\n\\begin{code}\n  isEven 0 = True\n  isEven n = isOdd $ n-1\n  \n  isOdd n  = not $ isEven n \n\\end{code}\n%\nEach call terminates as either @isEven@ calls @isOdd@ with a \ndecreasing parameter, \\emph{or} @isOdd@ calls @isEven@ with \nthe same parameter, expecting the latter to do the decreasing.\n%\nFor termination, we type:\n%\n\\begin{code}\n  isEven :: n:Nat -> Bool / [n, 0]\n  isOdd  :: n:Nat -> Bool / [n, 1]\n\\end{code}\n%\nTo check termination, \\toolname verifies that at each recursive \ncall the metric of the caller is less than the metric of the \ncallee.\n%\nWhen @isEven@ calls @isOdd@, it proves that the caller's \nmetric, namely @[n,0]@ is greater than the callee's @[n-1,1]@.\nWhen \\hbox{@isOdd@} calls @isEven@, it proves that the \ncaller's metric @[n,1]@ is greater than the callee's @[n,0]@,\nthereby proving the mutual recursion always terminates.\n\n\\mypara{Recursion over Data Types}\nThe above strategies generalize easily to functions that recurse\nover (finite) data structures like arrays, lists, and trees.\nIn these cases, we simply use \\emph{measures} to project the \nstructure onto @Nat@, thereby reducing the verification to \nthe previously seen cases. \nFor example, we can prove that @map@ \n%\n\\begin{code}\n  map f (x:xs) = f x : map f xs\n  map f []     = []\n\\end{code}\n%\nterminates, by typing @map@ as \n%\n\\begin{code}\n  (a -> b) -> xs:[a] -> [b] / [len xs]\n\\end{code}\n%\n\\ie, by using the measure @len xs@, from \\S~\\ref{sec:tool:measures}, \nas the metric.\n\n%%% %\n%%% \\begin{code}\n%%%   data L [sz] a = N | C a (L a)\n%%% \\end{code}\n%%% %\n%%% we can define a \\emph{measure}\n%%% %\n%%% \\begin{code}\n%%%   measure sz  :: L a -> Nat\n%%%   sz (C x xs) = 1 + (sz xs)\n%%%   sz N        = 0\n%%% \\end{code}\n%%% %\n%%% We prove that @map@ terminates using the type:\n%%% %\n%%% \\begin{code}\n%%%   map :: (a -> b) -> xs:L a -> L b / [sz xs]\n%%%   map f (C x xs) = C (f x) (map f xs)\n%%%   map f N        = N\n%%% \\end{code}\n%%% %\n%%% That is, by simply using @(sz xs)@  as the \n%%% decreasing metric.\n\n\\mypara{Generalized Metrics Over Datatypes}\nIn many functions there is no single argument \nwhose measure provably decreases. Consider\n%\n\\begin{code}\n  merge (x:xs) (y:ys)\n    | x < y     = x : merge xs (y:ys)\n    | otherwise = y : merge (x:xs) ys\n\\end{code}\n%\nfrom the homonymous sorting routine. Here, neither\nparameter decreases, but the \\emph{sum} of their \nsizes does. To prove termination, we can type @merge@ as:\n%\n\\begin{code}\n  xs:[a] -> ys:[a] -> [a] / [len xs + len ys]\n\\end{code}\n\n%%%% \\begin{figure*}[!t]\n%%%% \t\\begin{code}\n%%%% \ttype OL  a   =  [a]<{\\fld v -> (v >= fld)}>\n%%%% \n%%%% \tqsort :: (Ord a) => xs:[a] -> OL a / [(len xs), 0]\n%%%% \tqsort []         = []\n%%%% \tqsort (x:xs)     = qpart x xs [] []\n%%%% \n%%%% \tqpart :: (Ord a) => x:a -> q:[a] -> r: [{v:a|v<x}] -> p: [{v:a|v>=x}] -> OL a \n%%%% \t       / [((len q) + (len r) + (len p)), ((len q) + 1)]\n%%%% \tqpart x []     rlt rge             = app x (qsort rlt) (x:qsort rge)\n%%%% \tqpart x (y:ys) rlt rge | x > y     = qpart x ys (y:rlt) rge\n%%%% \t                       | otherwise = qpart x ys rlt (y:rge)\n%%%% \n%%%% \tapp k []     ys = ys\n%%%% \tapp k (x:xs) ys = x : (app k xs ys)\n%%%% \t\\end{code}\n%%%% \\caption{Mutual-recursive qsort}\n%%%% \\label{fig:code:qsort}\n%%%% \\end{figure*}\n\n\n\\mypara{Putting it all Together}\nThe above techniques can be combined to prove \ntermination of the mutually recursive quick-sort (from~\\citep{XiTerminationLICS01})% \\RJ{from where?}\n%\n\\begin{code}\n  qsort (x:xs)   = qpart x xs [] []\n  qsort []       = []\n\n  qpart x (y:ys) l r \n    | x > y      = qpart x ys (y:l) r \n    | otherwise  = qpart x ys l (y:r)\n  qpart x [] l r = app x (qsort l) (qsort r) \n\n  app k []     z = k : z\n  app k (x:xs) z = x : app k xs z\n\\end{code}\n%\n@qsort (x:xs)@ calls @qpart x xs@ to partition @xs@ \ninto two lists @l@ and @r@ that have elements less \nand greater or equal than the pivot @x@, respectively.\n%\nWhen @qpart@ finishes partitioning it mutually recursively\ncalls @qsort@ to sort the two list and appends the results \nwith @app@. \n%\n\\toolname proves sortedness as well~\\cite{vazou13} but let us \nfocus here on termination. To this end, we type the functions\nas:\n%\n\\begin{code}\n  qsort :: xs:_ -> _ \n        / [len xs, 0]\n    \n  qpart :: _ -> ys:_ -> l:_ -> r:_ -> _ \n        / [len ys + len l + len r, 1 + len ys]\n\\end{code}\n%\nAs before, \\toolname checks that at each recursive call \nthe caller's metric is less than the callee's. \n%\nWhen @qsort@ calls @qpart@ the length of the unsorted \nlist @len (x:xs)@ exceeds the \\hbox{@len xs + len [] + len []@}.\n%\nWhen @qpart@ recursively calls itself the first component\nof the metric is the same, but the length of the unpartitioned \nlist decreases, \\ie @1 + len y:ys@ exceeds \\hbox{@1 + len ys@}.\n%\nFinally, when @qpart@ calls @qsort@ we have \\hbox{@len ys + len l + len r@}\nexceeds both @len l@ and @len r@, thereby ensuring termination.\n\n\n%%% Before we dive into proving termination, note that the \n%%% type alias @OL a@ uses Abstract Refinements~\\citep{vazou13} to describe \n%%% Ordered Lists. \n%%% Thus, when \\toolname decides that the @qsort@ is SAFE, \n%%% it proves both termination and sortedness.\n%%%%Note that classical appending @rlt ++ rge@ of the two sorted lists will lose \n%%%%the crucial for sorting information that every element of @rlt@ is less than each element of @rge@.\n%%%%%\n%%%%Thus we defined a new version of list appending @app@ that uses the pivot element @k@\n%%%%as a ghost-parameter.\n%%%%%\n%%%%Good news is that \\toolname will automatically infer the appropriate type of @app@!\n\n%% Let \\mus{xs} and \\mup{q}{r}{p} be the (well-founded) termination pairs\n%% for @qsort xs@ and @qpart x q r p@ respectively, as annotated in the type signatures.\n%% %\n%%%$\\mu_s(x:xs) = (1 + len xs, 0) > (len xs + 0 + 0, len xs + 1) = \\mu_p(xs, [], [])$\n%%%$\\mu_p(y:ys, rlt, rge) = ((1 + (len ys)) + (len rlt) + (len rge), (1 + len ys) + 1) > \n%%%(len ys + (1 + (len rlt)) + (len rge), ((len ys) + 1)) = \\mu_p(ys, y:rlt, rge) $\n%%%$\\mu_p([], rlt, rge) = (0 + len rlt + len rge, 1) > (len rlt, 0) = \\mu_s(rlt)$ \n\n%% Existing techniques~\\citep{CookPR11} could be used to \n%% come up with termination metrics.\n%% We leave embedding these techniques into \\toolname as a future work, and instead\n%% we use some defaults to automate termination proving \n%% on functions with trivial metrics.\n\n\\mypara{Automation: Default Size Measures}\n%\nThe @qsort@ example illustrates that while \\toolname is \nvery expressive, devising appropriate termination metrics \ncan be tricky.\n%\nFortunately, such patterns are very uncommon, and the vast\nmajority of cases in real world programs are just structural \nrecursion on a datatype.\n%\n\\toolname automates termination proofs for this common case,\nby allowing users to specify a \\emph{default size measure} \nfor each data type, \\eg @len@ for @[a]@.\n%\nNow, if no explicit termination metric is given, by default \n\\toolname assumes that the \\emph{first} argument whose type\nhas an associated size measure decreases.\n%\nThus, in the above, we need not specify metrics for @fac@ \nor @map@ as the size measure is automatically \nused to prove termination. \n%\nThis heuristic suffices to \\emph{automatically}\nprove 67\\% of recursive functions terminating.\n\n\\mypara{Disabling Termination Checking}\nIn \\texttt{Haskell}'s lazy setting not all functions are terminating.\n% \n\\toolname provides two mechanisms the disable termination proving.\n%\nA user can disable checking a single function by marking \nthat function as lazy. For example, specifying @lazy repeat@ \ntells the tool to not prove @repeat@ terminates.\n%\nOptionally, a user can disable termination checking for a whole\nmodule by using the command line argument \\cmdnotermination\nfor the entire file.\n", "meta": {"hexsha": "cba9faec28313cbdd4e365080733928ad90df6a6", "size": 12480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/realworldhaskell/termination.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/realworldhaskell/termination.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/realworldhaskell/termination.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": 33.5483870968, "max_line_length": 103, "alphanum_fraction": 0.6717948718, "num_tokens": 3707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7826624840223698, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.6416997480307042}}
{"text": "\\section{Image Processing}\n\n\\begin{definition}[Aliasing]\n    Images are constructed and then reconstructed one or more times - \n    each of these reconstructions are referred to as aliases.\n\\end{definition}\n\n\\begin{definition}[Anisotropy]\\label{anisotropy}\n    Directionally dependent. Opposite of~\\nameref{isotropy}.\n    Example is to apply a filter to a set of images - consider\n    what would happen if one image was tilted.\n\\end{definition}\n\n\\begin{definition}[Anisotropic diffusion]\n    also called Perona-Malik diffusion, is a technique aiming at reducing image\n    noise without removing significant parts of the image content, typically\n    edges, lines or other details that are important for the interpretation of\n    the image.\n\n\\end{definition}\n\n\\begin{definition}[Aperture]\n    A hole which light goes through.\n\\end{definition}\n\n\\begin{definition}[Convolution]\\label{convolution}\n    In image-processing, this can in general be thought of as applying a mask\n    that takes the local neighbourhood for a pixel x and calculates its\n    gradient.\n\n    Noteworthingly, convolution as an operation to an image is in general\n    $O(n^{2})$.\n\\end{definition}\n\n\\begin{definition}[Curve representation]\n    How to represent a curve: computational cost is crucial.\n\n    \\begin{description}\n        \\item[Explicit] $y = f(x)$ - only lines but really easy to genereate.\n        \\item[Implicit] $f(x,y) = 0$. \\dots imagine a circle: to know if a point\n            is on the line, we can use pythagoras's $x^{2} + y^{2} - r^{2} = 0$. Costs a lot.\n        \\item[Parametric] $(x,y) = ( f(u), g(u))$. Oh yeah..\n    \\end{description}\n    \n\\end{definition}\n\n\\begin{definition}[Dilation (of functions)]\n    To skew a function, e.g.\\ for $f(x) = x$, you skew to $\\hat{f}(x) = x + 2$.\n\\end{definition}\n\n\\begin{definition}[Dirichet boundary condtions]\n    In image processing, you can say that this boundary condition is to assume\n    for a set of differential equations, the unknowns at the borders are \n    0: $u(0) = u(1) = 0$.\n\n\\end{definition}\n\n\\begin{definition}[extrapolation]\n    The process of estimating, beyond the original observation range, the value\n    of a variable on the basis of its relationship with another variable.\n\n    Creating a tangent line at the end of the known data and extending it\n    beyond that limit.\n\n\\end{definition}\n\n\\begin{definition}[Filter]\n    Applying a mask or operation to an image to extract or distort values.\n\n    \\begin{description}\n        \\item[High-pass] takes only the high frequency into play, lower values\n            are not affected that strongly (if at all)\n        \\item[Low-pass] \\dots\n    \\end{description}\n\\end{definition}\n\n\\begin{definition}[Gaussian blur]\n    Use a gaussian function on an image to reduce image noise and detail\n\\end{definition}\n\n\\begin{definition}[Gaussian filter]\n    Gaussian filters have the properties of having no overshoot to a step\n    function input while minimizing the rise and fall time.\n\n\\end{definition}\n\n\\begin{definition}[Gaussian pyramid]\n    A stack of images, where for each iteration, you take neighboring pixels\n    and make them into one. That is, you reduce the intensity in the picture.\n    This compresses the image. \n\n    It is a pyramid because for each iteration you take neighboring pixels\n    from the previous pyramid to generate the current.\n\\end{definition}\n\n\n\\begin{definition}[Gradient flow]\n    $$\n        V = \\nabla{f} = \\left(\\\n        \\frac{\\partial{f}}{\\partial{x_{1}}},\n        \\frac{\\partial{f}}{\\partial{x_{2}}},\n        \\dots,\n        \\frac{\\partial{f}}{\\partial{x_{n}}}\n    \\right)\n    $$\n\n    Note that for an oridnary image, the gradient at a given position is \n    given by:\n    $$\n    \\nabla{f} = \n    \\frac{\\partial{f}}{\\partial{x}}\\hat{x} +\n    \\frac{\\partial{f}}{\\partial{y}}\\hat{y}\n    $$\n    Where the first (x) term is the gradient in direction x, and y is the\n    gradient in direction y.\n\n    One can also calculate the direction of the gradient using\n    $\\theta = a\\tan^{2}{\\frac{\\partial{f}}{\\partial{y}}, \\frac{\\partial{f}}{\\partial{x}}}$\n\\end{definition}\n\n\\begin{definition}[Grating]\n    A collection of identical pararell objects, placed next to each other with\n    equal spacing.\n    \\end{definition}\n\\begin{definition}[Grayscale]\n    an image in which the value of each pixel is a single sample, that is, it\n    carries only intensity information\n\n    Grayscale images are distinct from one-bit bi-tonal black-and-white images,\n    which in the context of computer imaging are images with only the two\n    colors, black, and white (also called bilevel or binary images). Grayscale\n    images have many shades of gray in between.\n\n    Grayscale images are often the result of measuring the intensity of light\n    at each pixel in a single band of the electromagnetic spectrum \n\n\\end{definition}\n\n\\begin{definition}[Image gradient]\n    Gradual blend of color\n\\end{definition}\n\n\\begin{definition}[Image noise]\n    Unwanted signal, electrical signals not wanted in an image\n\\end{definition}\n\n\\begin{definition}[Image masking]\n    Apply an image over another. This can be used for e.g.\\ putting a square image\n    with only contents in the middle over another.\n\\end{definition}\n\n\\begin{definition}[Interpolation]\n    A way to estimate (pixel) values when resizing to a larger image.\n\n    An example from calculus is: given temps at noon and midnight, estimate\n    the temp at 5 PM as the mean of noon and midnight.\n\n    Interpolation can also (in signal processing) be referred to as \n    \\textbf{upsampling}.\n\n    Interpolation can be \\textit{linear}(1D), \\textit{bilinear}(2D) and so on\\dots\n\n\\end{definition}\n\n\\begin{definition}[Isotropy]\\label{isotropy}\n    Directionally independent. Opposite of~\\nameref{anisotropy}.\n\\end{definition}\n\n\\begin{definition}[Laplacian]\n    Highlight regions of rapid intensity change and is therefore often used for\n    edge detection.\n\n    Often applied to an image that has first been smoothed with something\n    approxiating in order to reduce its sensitivity to noise.\n\n\\end{definition}\n\n\\begin{definition}[Spatial frequency]\n    The number of changes in color values that occur per space.\n\n    Images with high spatial frequency are detailed, images with low spatial \n    frequency will appear blurred.\n\n    I.e.\\ sharp transitions from low/high to high/low intensities are said\n    to have a large spatial frequency,\n\n\\end{definition}\n\n\n\\begin{definition}[SRGB]\n    sRGB is a standard RGB color space created cooperatively by HP and\n    Microsoft in 1996 for use on monitors, printers and the Internet.\n\n\\end{definition}\n\n\n\\begin{definition}[Poisson image editing]\n    Blend two images together and make them seem alike.\n\\end{definition}\n\n\\begin{definition}[Raster order]\n    Begin at top left, proceed to right, then at leftmost pixel in next line.\n\\end{definition}\n\n\\begin{definition}[Raster image]\n    An image with pixels.\n\\end{definition}\n\n\\begin{definition}[Ringing]\n    The size of the oscillations after a peak frequency. E.g.\\ if you have a \n    sudden overshoot (bright color) the amplitude of the next wave is\n    the ringing. (???)\n\\end{definition}\n\n\\begin{definition}[Scalar field]\\label{scalarfield}\n    Associate a value to every point in a space. E.g.\\ for an image, you\n    could assign each pixel a color value.\n\\end{definition}\n\n\\begin{definition}[Seperable filter]\n    A filter that can be written as the product of two or more small filters.\n    This is usually done to reduce the computational costs.\n    E.g.~\\nameref{convolution} is usually faster in 1d than iterating $nD$, for\n    $n \\ge 2$.\n\\end{definition}\n\n\\begin{definition}[Spline]\n    A line that goes through a series of points.\n\n    The section between the lines is interpolated. This can be done linearly,\n    quadratic, \\dots so on.\n\\end{definition}\n\n\\begin{definition}[Stencil]\n    A figure that connects dots on a grid. Usually a cross-like figure \n    (one center dots, and one edge out in 4 directions from the center to\n    other dots).\n\\end{definition}\n", "meta": {"hexsha": "2235e6d74ad42788c3a16a9435726bcb0db71bcb", "size": 8017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/image.tex", "max_stars_repo_name": "andsild/NotusVitae", "max_stars_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": "src/def/image.tex", "max_issues_repo_name": "andsild/NotusVitae", "max_issues_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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/def/image.tex", "max_forks_repo_name": "andsild/NotusVitae", "max_forks_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": 33.5439330544, "max_line_length": 93, "alphanum_fraction": 0.7169764251, "num_tokens": 2000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6416997466066878}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{wrapfig}\n\\usepackage{float}\n\\usepackage{graphicx}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{comment}\n\\usepackage{amsmath,amsthm,amssymb}\n% \\usepackage[vlined,linesnumbered,ruled,resetcount]{algorithm2e}\n\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\\DeclareMathOperator*{\\val}{val}\n\\DeclareMathOperator*{\\best}{best}\n\\DeclareMathOperator*{\\worst}{worst}\n\n\\usepackage{algorithm}\n% \\usepackage{algorithmicx}\n\\usepackage[noend]{algpseudocode}\n\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Rgz}{\\mathbb{R}_{\\ge 0}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\n\\newcommand{\\Es}[2]{\\mathbb{E}_{#1}\\left[{#2}\\right]}\n\\newcommand{\\E}[1]{\\mathbb{E}\\left[{#1}\\right]}\n\\newcommand{\\ip}[2]{\\left\\langle{#1} , {#2}\\right\\rangle}\n\n\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{lemma}[definition]{Lemma}\n\\newtheorem{corollary}[definition]{Corollary}\n\\newtheorem{theorem}[definition]{Theorem}\n\\newtheorem{claim}[definition]{Claim}\n\n\\begin{document}\n\n% \\renewcommand{\\qedsymbol}{\\filledbox}\n \n\\title{Mechanism Design Notes}\n\\author{Clay Thomas\\\\\nclaytont@princeton.edu}\n\\maketitle\n\n\\clearpage\n\\section{Regret Minimization and Correlated Equilibrium Concepts}\n\nConsider the following online learning problem:\nThere is a set of actions $A$, $|A| = n$. For each time step $t=1,\\ldots,T$,\nthe decision maker picks a distribution on actions $p^t$.\nAfterwards, a cost vector $c^t : A\\to [0,1]$ is selected\n(in any way - even by an adversary who can see $p^t$ before it picks $c^t$)\nand the decision maker ``incurs cost'' $\\Es{a\\sim p^t}{c^t(a)} = \\ip{p^t}{c^t}$.\nAdditionally, the decision maker learns the vector $c^t$.\nThe goal is to minimize the sum of the costs $\\Es{a\\sim p^t}{c^t(a)}$.\n\n\\[ \\sum_{t=1}^T \\min_a c^t(a) \\]\nCan we hope to achieve something approximating this?\nNot quite: an adversary who can first look at $p^t$ can, for example,\nmake all costs very high, except the one with smallest probability in $p^t$.\nA more realistic goal is to compare our cost to the following:\n\\[ \\min_a \\sum_{t=1}^T c^t(a) \\]\nIntuitively, ``the cost of the best action which, in hindsight, we could've\nalways taken''.\n\nThis leads us to define the \\emph{regret} of our learning algorithm as\n\\[ \\Es{a^t\\sim p^t, t=1,\\ldots,T}{\\sum_{t=1}^T c^t(a)} - \\min_a \\sum_{t=1}^T c^t(a) \n  = {\\sum_{t=1}^T \\ip{p^t}{c^t}} - \\min_a \\sum_{t=1}^T c^t(a) \n\\]\n\nIt turns out there is a simple algorithm that achieves low regret.\n\\begin{algorithm}\n  \\begin{algorithmic}[0]\n  \\State \\textbf{Parameters:} $\\epsilon > 0$, $T$\n  \\State Initialize $w^1(a) = 1$ for each $a\\in A$\n  \\For {$t=1,\\ldots,T$}\n    \\State Choose action $a\\in A$ according to distribution $p^t$ proportional to $w^t$\n    \\State \\qquad i.e. let $p^t(a) = w^t(a) / \\Phi^t$ where\n      $\\Phi^t = \\sum_{a\\in A} w^t(a)$\n    \\State Observe costs $c^t$ and update weights as follows for each $a\\in A$:\n    \\State \\qquad $w^{t+1}(a) = w^t(a) (1 - \\epsilon)^{c^t(a)}$.\n  \\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{theorem}\n  Let $OPT = \\min_a \\sum_{t=1}^T c^t(a)$.\n  If we set $\\epsilon = \\sqrt{\\log n/T}$, then after $T$ rounds the total realized\n  cost of the multiplicative weights algorithm is $OPT + O(\\sqrt{T\\log n})$.\n\\end{theorem}\n\\begin{proof}\n  The proof follows two observations.\n  First, if the decision maker makes a bad move\n  (i.e. the weight of costly moves is high) then lots of total weight is lost.\n  Second, the best action in hindsight contributes has weight\n  $(1-\\epsilon)^{OPT}$ at time $T$.\n  Intuitively, this says that the only way for the decision maker to have many \n  bad moves is if every action was very bad.\n\n  For the formal proof, start by bounding $\\Phi^{t+1}$ in terms of $\\Phi^t$.\n  In what follows, almost all of the inequalities are standard approximations,\n  which can be proved using Taylor series or other estimations.\n  This is somewhat interesting, and basically just happens because $\\epsilon$ is\n  so small we can go back and forth between exponentiation and addition really\n  easily. In a sense, this was exactly the property we needed for our\n  multiplicative weights to produce a low additive cost measure.\n  Denote by $\\ell^t = \\Es{a\\sim p^t}{c^t(a)}$ be the realized cost at time $t$.\n  \\begin{align*}\n    \\Phi^{t+1}\n      & = \\sum_a w^t(a)(1 - \\epsilon)^{c^t(a)} \\\\\n      & \\le \\sum_a w^t(a)(1 - \\epsilon c^t(a)) \\\\\n      & = \\sum_a w^t(a) - \\Phi^t \\epsilon \\sum_a \\frac{w^t(a)}{\\Phi^t} c^t(a) \\\\\n      & = \\Phi^t \\left( 1 -\\epsilon \\sum_a p^t(a) c^t(a) \\right) \\\\\n      & = \\Phi^t \\left( 1 -\\epsilon \\ell^t \\right) \\\\\n  \\end{align*}\n  Now we can relate $\\Phi^T$ to the total loss $L = \\sum_{t=1}^T \\ell^t$:\n  \\begin{align*}\n    \\Phi^T\n      & = \\Phi^0 \\prod_{t=1}^T \\left( 1 -\\epsilon \\ell^t \\right) \\\\\n      & \\le n \\prod_{t=1}^T \\exp\\left(-\\epsilon \\ell^t \\right) \\\\\n      & = n \\exp\\left(-\\epsilon \\sum_{t=1}^T \\ell^t \\right) \\\\\n      & = n \\exp\\left(-\\epsilon L\\right) \\\\\n  \\end{align*}\n\n  On the other hand, for any action $a\\in A$ we have\n  \\[ (1-\\epsilon)^{OPT} \\le w^T(a) < \\Phi^T \\le n\\exp(-\\epsilon L) \\]\n  \\[ OPT(-\\epsilon - \\epsilon^2/2) \\le OPT\\log(1 - \\epsilon) \n    \\le \\log n - \\epsilon L \\]\n  \\begin{align*} \n    L & \\le OPT + ({\\epsilon}/{2}) OPT + \\frac{\\log n}{\\epsilon} \\\\\n      & \\le OPT + (\\sqrt{\\log n/T}/{2}) T + \\frac{\\log n}{\\sqrt{\\log n/T}} \\\\\n      & = OPT + \\frac{3}{2} \\sqrt{T\\log n}\n  \\end{align*}\n\n\\end{proof}\n\nFollowing experts online sounds great and all, but how is this actually useful\nfor proving theorems? Often time we are interested in the \\emph{time averaged}\ncost incurred, typically because that allows us to combine all of the\ndistributions $p^t$ into a distribution which is ``close to optimal'' in some\nsense. The following restatement tells you ``how long you need to go'' to get\nadditive error $\\epsilon$.\n\n\\begin{corollary}\n  For any $\\epsilon > 0$, if we run for $T = O(\\log n / \\epsilon^2)$ steps,\n  multiplicative weights will have average regret $\\epsilon$.\n\\end{corollary}\n\n\n\n\n\n\n\n\n  \\subsection{Swap regret}\n\n  The first idea is to run several independent instances of low regret\n  algorithm. We'll kind of see that each instance will correspond to a different\n  action. However, perhaps the best way to see why this definition works comes\n  out in the analysis: we need to align the sum of the costs incurred to the\n  individual instances with the swap regret.\n\n  Here's a description of the algorithm:\n  Run independent instances of the multiplicative weights algorithm (or any\n  low-regret online learning algorithm) $M_j$ for $j=1,\\ldots,n = |A|$.\n  At each time $t$, the algorithm:\n  \\begin{itemize}\n    \\item asks each learner for a distribution $q_j^t$ over actions\n    \\item calculates $p^t = P(q_1^t,\\ldots,q_n^t)$ using some subroutine $P$,\n      and acts according to $p^t$\n    \\item observes ``real'' cost $c^t$, but tells each learner $M_j$ that the\n      cost incurred to $M_j$ is $p^t(j)c^t$\n  \\end{itemize}\n\n  Individually, it is a bit difficult to interpret what each $M_j$ is trying to\n  minimize: it's like $M_j$ gets punished, but only if the action he is\n  associated with is likely played. Collectively, all the $M_j$s are trying to\n  minimize $\\sum_j p^t(j) c^t = c^t$, so at least that aligns with what we want.\n\n  More formally, the algorithm looks like this:\n  \\begin{algorithm}\n    \\begin{algorithmic}[0]\n    \\State \\textbf{Parameters:} $\\epsilon > 0$, $T$\n    \\State Initialize $w^1_j(a) = 1$ for each $a\\in A$ and $j=1,\\ldots,n$\n    \\For {$t=1,\\ldots,T$}\n      \\For {$j=1,\\ldots,n$}\n        \\State Define a distribution $q_j^t$ proportional to $w_j^t$\n      \\EndFor\n      \\State Let $p^t = P(q^t_1,\\ldots,q^t_n)$, and \n        draw an action according to $p^t$\n      % \\State Define $p^t$ as follows: $p^t$ is any stationary distribution of\n      %   the Mark chain whose states \n      % \\State \\qquad are actions $j\\in A$ and whose transition\n      %   probabilities from $j$ to each $i\\in A$ are $q_j^t(i)$\n      \\State Observe costs $c^t$\n      \\For {$j=1,\\ldots,n$}\n        \\State Update weights $w^{t+1}_j(a) = w^t_j(a) (1 - \\epsilon)^{p^t(j) c^t(a)}$\n      \\EndFor\n    \\EndFor\n  \\end{algorithmic}\n  \\end{algorithm}\n\n  Let's dive into the analysis, during which we'll finally specify $P$:\n\n", "meta": {"hexsha": "09387c44f0d2454f8dd58a47d182c49cb3e96085", "size": 8257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Regret.tex", "max_stars_repo_name": "ClathomasPrime/CompetitiveStableMatching", "max_stars_repo_head_hexsha": "8a0b1edadbffb8ea7dde8fac8d7696f91747668f", "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": "Tex/Regret.tex", "max_issues_repo_name": "ClathomasPrime/CompetitiveStableMatching", "max_issues_repo_head_hexsha": "8a0b1edadbffb8ea7dde8fac8d7696f91747668f", "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/Regret.tex", "max_forks_repo_name": "ClathomasPrime/CompetitiveStableMatching", "max_forks_repo_head_hexsha": "8a0b1edadbffb8ea7dde8fac8d7696f91747668f", "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.8888888889, "max_line_length": 87, "alphanum_fraction": 0.6659803803, "num_tokens": 2751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933227109649, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.641699732117137}}
{"text": "\\hypertarget{convex-hull}{%\n\\section{Convex Hull}\\label{convex-hull}}\n\n\\hypertarget{introduction}{%\n\\subsection{Introduction}\\label{introduction}}\n\nGiven a set of points P, the Convex Hull of P, denoted conv(P) is the\nsmallest closed simple polygon which contains all the points in P. It\ncan be visualized as a tightly snapped rubber band over the given set of\npoints.\n\nWe would like to compute the convex hull of given set of points by using\na divide and conquer technique. Later, we will also show that the\ncomputational complexity of our algorithm is also O(n log n). Note that\nwe cannot do better than is for computing convex hull\n\n\\hypertarget{how-to-run}{%\n\\subsection{How to Run}\\label{how-to-run}}\n\nThe src folder contains the source code for the convex hull program.\n\\texttt{g++} from the GNU compiler suite is required to compile the\nprogram to a executable.\n\nSteps to Compile:\n\n\\begin{enumerate}\n\\def\\labelenumi{\\arabic{enumi})}\n\\tightlist\n\\item\n  \\texttt{cd} into the src directory\n\\item\n  Run \\texttt{g++\\ main.cpp} which generates an executable called\n  \\texttt{a.out} in the same directory\n\\item\n  Run the executable using \\texttt{./a.out} (on linux)\n\n  \\begin{enumerate}\n  \\def\\labelenumii{\\arabic{enumii})}\n  \\tightlist\n  \\item\n    The executable takes a dataset from command line argument. For\n    example, to use an existing dataset, run\n    \\texttt{./a.out\\ ../datasets/edge.txt}\n  \\item\n    If no command-line argument is given, it takes input from the shell\n    directly (stdin)\n  \\end{enumerate}\n\\end{enumerate}\n\n\\hypertarget{input}{%\n\\subsection{Input}\\label{input}}\n\nThe required file format for the algorithm to work correctly is:\n\n\\begin{itemize}\n\\tightlist\n\\item\n  First line must contain the no of Points to be taken as input by the\n  program.\n\\item\n  Each of next line must contain 2 integers, space seperated denoting\n  the (x, y) coordinates of each point.\n\\item\n  Each coordinate must be of integer type in the range -10\\^{}6 to\n  10\\^{}6.\n\\item\n  No of coordinates must be less than 1 Billion.\n\\item\n  \\textbf{Note}: while using floating point datasets, the output\n  coordinates might slightly differ as given coordinates are stored as\n  floats.\n\\end{itemize}\n\n\\hypertarget{output}{%\n\\subsection{Output}\\label{output}}\n\nEach line of output contains the coordinates of points present on the\nconvex hull in clockwise order.\\\\\nThe last two lines of output show the time taken to take input in\nmicroseconds and the time taken by the algorithm to compute convex hull\n(also in microseconds).\n\nExample output:\n\n\\includegraphics[width=8cm,height=8cm]{img/CH10.png}\\\\\n\n\\hypertarget{documentation-and-report}{%\n\\subsection{Documentation and Report}\\label{documentation-and-report}}\n\nDocumentation of this algorithm, functions and classes can be found in\nthe \\texttt{docs} folder in the current directory. Open the\n\\href{../ConvexHull/docs/html/index.html}{index.html} file from the docs\ndirectory with your preferred browser to go through the documentation\n\n\\hypertarget{performance-analysis}{%\n\\subsection{Performance Analysis}\\label{performance-analysis}}\n\nAnalysis is performed with a system running:\n\n\\begin{itemize}\n\\tightlist\n\\item\n  OS: Arch Linux (64Bit) running Linux Kernel version 5.7.2\n\\item\n  Processor: Intel Core i7 7700HQ\n\\item\n  RAM: 8GB\n\\item\n  Compiler: GNU G++ (GCC) 10.1.0\n\\end{itemize}\n\n\\textbf{The following observations are recorded:}\n\n\\begin{longtable}[]{@{}lcccc@{}}\n\\toprule\nFilename & Input Dimentions & Output Diemntions & File read time &\nAlgorithm runtime\\tabularnewline\n\\midrule\n\\endhead\nedge.txt & 5 & 4 & 451 microsec & 8 microsec\\tabularnewline\nsmall.txt & 7 & 7 & 495 microsec & 16 microsec\\tabularnewline\ntest.txt & 34 & 7 & 328 microsec & 56 microsec\\tabularnewline\nradial.txt & 3100 & 9 & 1348 microsec & 6.15 millisec\\tabularnewline\n\\bottomrule\n\\end{longtable}\n\nRandomly generated points (using python):\n\n\\begin{longtable}[]{@{}lcccc@{}}\n\\toprule\nFilename & Input Dimentions & Output Diemntions & File read time &\nAlgorithm runtime\\tabularnewline\n\\midrule\n\\endhead\n10.txt & 10 & 5 & 314 microsec & 16 microsec\\tabularnewline\n20.txt & 20 & 7 & 495 microsec & 31 microsec\\tabularnewline\n50.txt & 50 & 9 & 427 microsec & 108 microsec\\tabularnewline\n100.txt & 100 & 13 & 348 microsec & 165 microsec\\tabularnewline\n500.txt & 500 & 13 & 572 microsec & 935 microsec\\tabularnewline\n1000.txt & 1000 (1K) & 18 & 510 microsec & 2.1 millisec\\tabularnewline\n3000.txt & 3000 (3K) & 24 & 2.49 millisec & 5.5 millisec\\tabularnewline\n5000.txt & 5000 (5K) & 22 & 2.12 millisec & 8.0 millisec\\tabularnewline\n10000.txt & 10000 (10K) & 23 & 3.26 millisec & 17.6\nmillisec\\tabularnewline\n50000.txt & 50000 (50K) & 28 & 17.4 millisec & 80.5\nmillisec\\tabularnewline\n100000.txt & 100000 (1L) & 31 & 39.3 millisec & 164.1\nmillisec\\tabularnewline\n250000.txt & 250000 (2.5L) & 31 & 78.1 millisec & 448.3\nmillisec\\tabularnewline\n\\bottomrule\n\\end{longtable}\n\nUsing real world datasets:\n\n\\begin{longtable}[]{@{}lcccc@{}}\n\\toprule\nFilename & Input Points & Output Diemntions & File read time & Algorithm\nruntime\\tabularnewline\n\\midrule\n\\endhead\nsubway-entrance-ny.txt & 1929 & 16 & 2.85 millisec & 3.81\nmillisec\\tabularnewline\nparking\\_meter.txt & 15191 & 16 & 14.15 millisec & 27.04\nmillisec\\tabularnewline\n\\bottomrule\n\\end{longtable}\n\nSources of datasets:\n\n\\begin{itemize}\n\\tightlist\n\\item\n  \\href{https://data.world/city-of-ny/5jsj-cq4s}{Parking meter dataset}\n\\item\n  \\href{https://data.world/new-york-city/subway-entrances}{New York\n  Subway Entrance dataset}\n\\end{itemize}\n\nIt is highly difficult to calculate the time taken exactly up to the\nmicrosecond, hence the value might vary on different executions. Also,\nplease note that the time calculated here may vary based on the system\nload and other background applications.\n\n\\hypertarget{algorithm-approach}{%\n\\subsection{Algorithm Approach}\\label{algorithm-approach}}\n\nFor more detailed information regarding the algorithm, refer to David\nMount Lecture notes from the course\n\\href{https://www.cs.umd.edu/class/spring2020/cmsc754/lectures.html}{CMSC\n754 - Computational Geometry}\n\nGiven set of points P, we would like to first order them according to\nthe increasing x coordinate. For the sake of simplicity, let us assume\nthat no two points will have same x or y coordinate and no 3 points are\nco-linear.\n\nFirst, we will recursively compute the upper hull and then similarly\ncompute the lower hull of the given set of points. Finally, we will join\nthe upper hull with the lower hull to complete the convex hull and\nreturn/print the clockwise ordering of the points present on the convex\nhull\n\n\\textbf{Upper Hull Computation}\n\nWe divide the input set of points into 2 equal halves and recursively\ncompute the upper hull for both the half. Then, we compute the upper\ntangent to both the hulls by traversing from the right on left hull and\ntraversing from left on the right hull. We perform orientation tests to\ndetermine when the orientation changes on each hull respectively and\nmove upwards a point. We perform this operations until we reach the\nupper part of both hulls.\n\nAll the traversed points on both hulls except the one which lead to\ntangent are deleted (because all of them lie under tangent, hence lie\ninside the polygon) and the resulting points of both hulls are catenated\nto get the upper hull.\n\n\\hypertarget{results}{%\n\\subsection{Results}\\label{results}}\n\nThe following is the computed convex hull of the\n\\href{./datasets/parking_meter.txt}{parking\\_meter.txt} dataset:\n\n\\includegraphics[width=8cm,height=8cm]{img/CHparkingmeter.png}\\\\\n\nThe red boundary in the above image represents the convex hull given as\nthe output by the program. The blue points are the inputs given to the\nprogram.\n\nBy analysis of the above divide and conquer algorithm, It can be\nconcluded that the algorithm runs in O(n log n) time complexity. From\nthe above results of testing of various datasets, we can see that the\ntime increase is proportional to the no of points.\n\n\\includegraphics[width=8cm,height=8cm]{img/CHradial.png}\\\\\n\nThe dataset \\href{./datasets/radial.txt}{radial.txt} is a hand-crafted\ndataset (3K points) which has high concentration of points\n(\\textasciitilde2.1K) in the center, whereas other randomly generated\ndatasets (for example: \\href{./datasets/3000.txt}{3000.txt})have a\nuniform distribution of points (the python random number generator uses\nan underlying uniform distribution). From this we can assume that\nindependant of positioning of points, our algorithm takes approximately\nthe same time to compute the convex hull.\n\n\\hypertarget{conclusion}{%\n\\subsection{Conclusion}\\label{conclusion}}\n\nFor the last dataset which contains 2.5L points, its worth noting that\nthe algorithm runs in just under 500ms which might appear to be fast.\nBut for applications like graphics, rendering and animations, this poses\na huge overhead in terms of repeated computation of convex hull for\nvarious objects.\n\nOne observation we can make here is that the number of points which are\npresent on the convex hull is usually relatively lower most of the\ntimes. So, using an output sensitive algorithms (Ex: Jarvis's march)\nmight help us if our application has fewer vertices on the convex hull.\n\nIt's worth noting that convex hull computation cannot be done under O(n\nlog n) which has been proved. Therefore, we can only hope to reduce the\nconstants of complexity. In our algorithm, we repeatedly recurse, hence\nmake many function calls which is computationally expensive. Hence by\nusing algorithms like Chan's or Grahm's, we can do better\n", "meta": {"hexsha": "32f6d0c21f36780824ea113c9608277dd0088057", "size": 9525, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/ConvexHull.tex", "max_stars_repo_name": "RikilG/Geometry-Algorithms", "max_stars_repo_head_hexsha": "7bdf25e425b93dc6955331a48980a4b4d8051a6d", "max_stars_repo_licenses": ["MIT"], "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/ConvexHull.tex", "max_issues_repo_name": "RikilG/Geometry-Algorithms", "max_issues_repo_head_hexsha": "7bdf25e425b93dc6955331a48980a4b4d8051a6d", "max_issues_repo_licenses": ["MIT"], "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/ConvexHull.tex", "max_forks_repo_name": "RikilG/Geometry-Algorithms", "max_forks_repo_head_hexsha": "7bdf25e425b93dc6955331a48980a4b4d8051a6d", "max_forks_repo_licenses": ["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.8082706767, "max_line_length": 73, "alphanum_fraction": 0.7717585302, "num_tokens": 2598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.6416771741144867}}
{"text": "\\subsection{Input Circuit}\nIn Europe the mains voltage in houses is 230 volts, all of the input circuit before the transformer needs to be designed to that voltages. \nAs this part of the input circuit we want to besure that the noise on mains volts do not propegate to our output volts, \nwe are going to use a main emi filter to filter out some of the noise on the mains system. \nThis will also double as filter for any noise we are going to send out to the mains voltage. \n\nAs a means for input protection we are also going to use fuse (see formula \\ref{eq:transfer-transformer} on page \\pageref{eq:transfer-transformer}).\n\n\\subsubsection{Transformer}\nThe transfer formula for the transformer \n\\begin{align}\\label{eq:transfer-transformer}\nm &= \\frac{I_s}{I_p} = \\frac{V_p}{V_s}\n\\end{align}\nFor the input supply I am going to use a transformer 2x18V at 1.5A, that I already have. And I am going to connect the 18V's in series to get 36V at 1.5A. But for finding the transfer value we can use formula \\ref{eq:transfer-transformer}.\n\\begin{align}   \nm = \\frac{V_p}{V_s} = \\frac{230V}{18V} = 12.78 \\nonumber\n\\end{align}\n To find out which size of fuse that we are going to be using, we need to find out how much current that are going to be used on the main side of the transformer.\nWe are going rearrange in formula \\ref{eq:transfer-transformer} as we know what $I_s$ is and we have calculated $m$.\n\\begin{align}\nm = \\frac{I_s}{I_p} \\nonumber \\\\\n\\Rightarrow \\nonumber \\\\\nI_p \\cdot m = I_p \\cdot \\frac{I_s}{I_p} = I_s \\nonumber \\\\\n\\Rightarrow \\nonumber \\\\\n\\frac{ I_p \\cdot m}{m} = \\frac{I_s}{m} \\nonumber \\\\\n\\Rightarrow \\nonumber \\\\\nI_p = \\frac{I_s}{m} \\label{eq:found-Ip}\n\\end{align}\nNow we can calculate $I_p$ with $I_s$ and $m$ from \\ref{eq:found-Ip}.\n\\begin{align}\nI_p = \\frac{I_s}{m} = \\frac{1.5A}{12.78} = 0.117A = \\underline{\\underline{117mA}} \\nonumber \n\\end{align}\nSo the primary side of the transformer needs a fuse of 117mA, \nbut as I can not find that size, the one that is going to be used is a 125mA.\nOn the secondary side, I am going to use a 1,5A fuse.\n\n\\subsubsection{DC voltage}\nNow we should calculate if we want to use 2x18V or put them in serial and get 36V. \nOne thing to keep in mind, is that when using a bridge rectifier the input frequency is doubled.\n\\paragraph{36 \\vac}\nThe 36 volt ac are going to be converted to dc, via fullwave diode bridge. \nSinces the ac voltage specified on the transformer is RMS voltage, and not the peak voltage. \nWe can calculate what the dc voltage will become assuming no losses.\n\\begin{align} \\label{eq:calc_vdc}\n\\text{V}_{ \\text{DC} } &= \\frac{ 2 \\cdot \\text{V}_{ \\text{max} } }{ \\pi } \\\\\n         &= 0.637 \\cdot \\text{V}_{ \\text{max} } \\\\\n         &= 0.9 \\cdot \\text{V}_{ \\text{RMS} } \\\\\n         &= 0.9 \\cdot 36 \\text{V}_{\\text{AC}}\\nonumber \\\\\n         &= 32.4 \\text{V}_{ \\text{DC} } \\nonumber\n\\end{align}\nBut since we are going to use a bridge rectifier there is two times diode voltage drop that gives total drop of \\(1.4V\\). \nWhich meaning that we are properly only going to see around \\( 31V \\) if measure at the diode bridge output. \n\\paragraph{18 \\vac}\n\\begin{align} \\label{eq:calc_18vdc}\n    \\text{V}_{ \\text{DC} }  &= \\frac{ 2 \\cdot \\text{V}_{ \\text{max} } }{ \\pi } \\\\\n             &= 0.637 \\cdot \\text{V}_{ \\text{max} } \\\\\n             &= 0.9 \\cdot \\text{V}_{ \\text{RMS} } \\\\\n             &= 0.9 \\cdot 18 \\text{V}_{ \\text{AC} } \\nonumber \\\\\n             &= 16.2 \\text{V}_{ \\text{DC} } \\nonumber\n\\end{align}\nAnd again we need to take into account the diode drop, which gives 14.8V after the diode bridge.\n\n\\subsection{Ripple voltage}\nThe diode bridge does not create a dc voltage, but rather flips over the negativ half of the sinus wave to the positive. So there is a need for smoothering out the sinus wave to get a dc voltage. \nWe need to figure out how much ripple voltage, that we can get away with at this point. We are going to use formula \\ref{eq:calc_vripple} to calculate our $V_{ripple}$.\n\\begin{align}\\label{eq:calc_vripple}\n\\text{V}_{ \\text{PP}_{\\text{ripple} }} &= \\frac{ \\text{I}_{ \\text{load} } }{ 2 \\cdot f \\cdot C } [V]\n\\end{align}\nIf we choose a big capacitor, then the time for it going to be discharge from fully charged is going to be long. As long there is voltage on the capacitor the rest of the circuit is working. At table \\ref{tab:choose-c} I have made some calculation of a couple of capacitor that I can buy.\n\\begin{table}[ht]\n\\centering\n\\caption{Choosing smooting capacitor} \\label{tab:choose-c}\n\\begin{tabular}{|c|r|r|r|r|} \n\\hline\nC & $V_{ripple}$ \\@ 1.5A & $V_{ripple}$ \\@ 1A & $V_{ripple}$ \\@ 500mA & $V_{ripple}$ \\@ 10mA \\\\ \\hline \\hline\n 47 uF  &  3.525 mV &  2.350 mV &  1.175 mV & 0.024 mV \\\\ \\hline\n100 uF  &  7.500 mV &  5.000 mV &  2.500 mV & 0.050 mV \\\\ \\hline\n120 uF  &  9.000 mV &  6.000 mV &  3.000 mV & 0.060 mV \\\\ \\hline\n150 uF  & 11.250 mV\t&  7.500 mV &  3.750 mV & 0.075 mV \\\\ \\hline\n180 uF  & 13.500 mV &  9.000 mV &  4.500 mV & 0.090 mV \\\\ \\hline\n220 uF  & 16.500 mV & 11.000 mV &  5.500 mV & 0.110 mV \\\\ \\hline\n270 uF  & 20.250 mV & 13.500 mV &  6.750 mV & 0.135 mV \\\\ \\hline\n330 uF  & 24.750 mV & 16.500 mV &  8.250 mV & 0.165 mV \\\\ \\hline\n390 uF  & 29.250 mV & 19.500 mV &  9.750 mV & 0.195 mV \\\\ \\hline\n470 uF  & 35.250 mV & 23.500 mV & 11.750 mV\t& 0.235 mV \\\\ \\hline\n560 uF  & 42.000 mV & 28.000 mV\t& 14.000 mV & 0.280 mV \\\\ \\hline\n680 uF  & 51.000 mV & 34.000 mV & 17.000 mV & 0.340 mV \\\\ \\hline\n820 uF  & 61.500 mV & 41.000 mV & 20.500 mV & 0.410 mV \\\\ \\hline\n\\end{tabular}\n\\end{table}", "meta": {"hexsha": "8d595ea3c1f2e31bccd47c45433c8fb91db15e20", "size": 5511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/inputcircuit.tex", "max_stars_repo_name": "mtkaalund/psu", "max_stars_repo_head_hexsha": "98bf7e367becc1e3480d916a514af6f1dee106ca", "max_stars_repo_licenses": ["MIT"], "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/inputcircuit.tex", "max_issues_repo_name": "mtkaalund/psu", "max_issues_repo_head_hexsha": "98bf7e367becc1e3480d916a514af6f1dee106ca", "max_issues_repo_licenses": ["MIT"], "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/inputcircuit.tex", "max_forks_repo_name": "mtkaalund/psu", "max_forks_repo_head_hexsha": "98bf7e367becc1e3480d916a514af6f1dee106ca", "max_forks_repo_licenses": ["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.2333333333, "max_line_length": 288, "alphanum_fraction": 0.6741063328, "num_tokens": 1962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6416559817783778}}
{"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{ISE 538 Homework 1}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle\n\n\n\n\n\\section*{Problem 1.31}\nLet $D_i$ represent the score on $i^{th}$ dice.\nThen the possible configurations for getting a sum 7 are: $(D_1, D_2): (1,6), (2,5), (3,4), (4,3), (5,2), (6,1) $\n\nThus $P(D_1=6|D_1+D_2=7) = \\frac{1}{6}$\n\\section*{Problem 1.32}\n\nLet \n\\begin{align*}\nI_i &= \\begin{cases}\n1 & i^{th}\\text{ person gets his hat back}\\\\\n0 & \\text{otherwise}\n\\end{cases}\\\\\nP(\\text{no person gets his hat back}) &= 1 - P(I_1 \\cup I_2 \\dots \\cup I_n)\\\\\nP(I_i=1) &= \\frac{1}{n}\\\\\nP(I_i=1, I_j=1) &= \\frac{1}{n}\\frac{1}{n-1} = \\frac{1}{n(n-1)} = \\frac{(n-2)!}{n!}\\\\\nP(I_i=1, I_j=1) &= \\frac{1}{n}\\frac{1}{n-1}\\frac{1}{n-2} = \\frac{(n-3)!}{n!}\\\\\nP(I_1 \\cup I_2 \\dots \\cup I_n) &= \\sum_{i=1}^{n}P(I_i) - \\sum_{i<j}P(I_iI_j) + \\sum_{i<j<k}P(I_iI_jI_k) - \\dots - (-1)^n P(I_1I_2\\dots I_n)\\\\\n\\end{align*}\n\nThe number of terms of type $P(I_iI_j) $ for $i<j$ are $n\\choose{2}$, similarly of type $P(I_iI_jI_k)$ for $i<j<k$ are $n\\choose{3}$ and so on\n\nThus,\n\n\\begin{align*}\nP(I_1 \\cup I_2 \\dots \\cup I_n) &= n \\times \\frac{1}{n} - {n\\choose{2}} \\times \\frac{(n-2)!}{n!} + {n\\choose{3}} \\times \\frac{(n-3)!}{n!} - \\dots - (-1)^n {n\\choose{n}} \\times \\frac{1}{n!}\\\\\n&= 1 - \\frac{1}{2!} + \\frac{1}{3!} - \\dots - (-1)^n \\frac{1}{n!}\\\\\nP(\\text{no person gets his hat back}) &= 1 - (1 - \\frac{1}{2!} + \\frac{1}{3!} - \\dots - (-1)^n \\frac{1}{n!})\\\\\n&= \\frac{1}{2!} - \\frac{1}{3!} + \\dots + (-1)^n \\frac{1}{n!}\\\\\n\\end{align*}\n\n\\section*{Problem 1.34}\nAssuming that the red and black are equiprobable, choosing a red or black is equally rewarding.\n$P(11 \\text{consecutive black}) = (\\frac{1}{2})^{11}$\n$P(11^{th} \\text{red} , \\text{ last 10 black}) = \\frac{1}{2}\\frac{1}{2}^{10}$. The probability of observing $10$ blacks continuously is very low, having observed this it is actually likely that the system is biased towards black hits and hence the bet should probably be on a black rather than a red.\n\n\\section*{Problem 1.35}\n\\textbf{(a)} H,H,H,H: $(\\frac{1}{2})^4$\n\n\\textbf{(b)} T,H,H,H: $(\\frac{1}{2})^4$\n\n\\textbf{(c)} T,H,H,H occurs before H,H,H,H: The only possible way for $H,H,H,H$ to occur first is that first four flips are heads. And hence the required probability is $1-\\frac{1}{2}^4 = \\frac{15}{16}$\n\n\\section*{Problem 1.36}\nBox1 : $1B, 1W$\n\nBox2: $2B, 1W$\n\n$P(B) = \\frac{1}{2} \\times \\frac{1}{2} + \\frac{1}{2} \\times \\frac{2}{3} = \\frac{7}{12}$\n\n\\section*{Problem 1.37}\n\n$P(Box_1|W) = \\frac{P(W,Box1)}{P(W)} = \\frac{P(W|Box1)P(Box1)}{P(W)} = \\frac{\\frac{1}{2}\\frac{1}{2}}{1-\\frac{7}{12}} = \\frac{3}{5}$\n\n\\section*{Problem 1.44}\n$P(tails|W) = \\frac{P(tails)P(W|tails)}{P(W)}$\n\n$P(W) = P(W|heads)P(heads) + P(W|tails)P(tails) = \\frac{5}{12}\\frac{1}{2} + \\frac{3}{15}\\frac{1}{2} = \\frac{37}{120}$\n\nThus, $P(tails|W) = \\frac{\\frac{1}{2}\\frac{3}{15}}{\\frac{37}{120}} = \\frac{12}{37}$\n\n\\section*{Problem 1.45}\n$P(B1|R2) = \\frac{P(R2|B1)P(B1)}{P(R2)}$\n\\begin{align*}\nP(B1) &= \\frac{b}{b+r}\\\\\nP(R2) &= P(R2|B1)P(B1) + P(R2|R1)P(R1)\\\\\n&= \\frac{r}{r+b+c}\\frac{b}{b+r}+ \\frac{r+c}{r+b+c}\\frac{r}{b+r}\\\\\n&= \\frac{br+r^2+rc}{(b+r)(b+r+c)}\\\\\nP(B1|R2) &= \\frac{\\frac{r}{r+b+c}\\frac{b}{b+r}}{\\frac{br+r^2+rc}{(b+r)(b+r+c)}}\\\\\n&= \\frac{br}{br+r^2+rc}\\\\\n&= \\frac{b}{b+r+c}\n\\end{align*}\n\n\\section*{Problem 1.46}\nLet's assume WLOG, that the jailer tells $C$ will be set free.\nThen $P(\\text{C free} | \\text{A dies}) = \\frac{1}{2}$ because is A is to die the jailer could have also named $B$ with equal probability.\n\\begin{align*}\nP(\\text{A dies} | \\text{C free}) &= \\frac{P(\\text{C free}| \\text{A dies})P(\\text{A dies})}{P(\\text{C free})}\\\\\n&= \\frac{P(\\text{C free}| \\text{A dies})P(\\text{A dies})}{P(\\text{C free} | \\text{A dies}) P(\\text{A dies}) + P(\\text{C free} | \\text{B dies}) P(\\text{B dies}) + P(\\text{C free} | \\text{C dies}) P(\\text{C dies}) }\\\\\n&= \\frac{\\frac{1}{2} \\frac{1}{3}}{1\\frac{1}{3} + 1\\frac{1}{3} + 0}\\\\\n&= \\frac{1}{3}\n\\end{align*}\n\nSo the jailer is wrong. The probability of $A$ being executed remains the same.\n\n\\section*{Problem 1.47}\n\\begin{align*}\n0 \\leq P(A|B) \\leq 1\\\\\nP(\\Omega | B) = \\frac{P(\\Omega \\cap B)}{P(B)} = \\frac{P(B)}{P(B)} = 1\\\\\n\\end{align*}\n\nFor the third property, let's consider disjoint events $A$ and $C$\nthen \n\\begin{align*}\nP(A \\cup C | B) & = \\frac{P((A \\cup C)B)}{P(B)}\\\\ \n&= \\frac{P(AB \\cup CB)}{P(B)}\\\\\n&= \\frac{P(AB)+P(CB)}{P(B)}\\\\\n&= P(A|B)+P(C|B)\n\\end{align*}\n\nNow,\n\\begin{align*}\nP(A|BC)P(C|B) + P(A|BC^c)P(C^c|B)\n&= \\frac{P(ABC)}{P(BC)}\\frac{P(BC)}{P(B)} + \\frac{P(ABC^c)}{P(BC^c)}\\frac{P(BC^c)}{P(B)}\\\\\n&= \\frac{P(ABC)}{P(B)} + \\frac{P(ABC^c)}{P(B)}\\\\\n&= P(AC|B) + P(AC^c|B)\\\\\n&= P(AC \\cup AC^c|B)\\\\\n&= P(A|B)\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "a2823b25b176c9745e1efc746370cf6ca7b0d17c", "size": 4899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Fall/ISE-538/HW/hw1/hw1.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_Fall/ISE-538/HW/hw1/hw1.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_Fall/ISE-538/HW/hw1/hw1.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": 37.6846153846, "max_line_length": 300, "alphanum_fraction": 0.5819555011, "num_tokens": 2228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6416559760404239}}
{"text": "\\documentclass{article}\n\n%% Language and font encodings\n%\\usepackage[english]{babel}\n%\\usepackage[utf8x]{inputenc}\n%\\usepackage[T1]{fontenc}\n\n%% Sets page size and margins\n\\usepackage[margin=1in]{geometry}\n\n%% Useful packages\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n%\\usepackage{mathrsfs}\n\\usepackage{amsfonts,amssymb}\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\\usepackage{parskip}\n\\setlength{\\parindent}{0pt}\n\n\\title{Homework 2}\n\\author{Group L\\\\\nYang Li, Jimmy Jusuf, Zhirong Zhang, Tiangang Zhang}\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Problem 1}\n\\begin{eqnarray*}\nL(x,y,\\lambda)=(x-a)^2+(y-b)^2-\\lambda_1 x+\\lambda_2 (x-1)-\\lambda_3 y +\\lambda_4 (y-1)\n\\end{eqnarray*}\nThen local minimizer should subject to\n\n\\begin{equation}  \n\\left\\{  \n             \\begin{array}{ll}\n             2(x^*-a)-\\lambda_1^*+\\lambda_2^*=0\\\\  \n             2(y^*-a)-\\lambda_3^*+\\lambda_4^*=0\\\\\n             \\lambda_1^* x^*=0\\\\\n             \\lambda_2^*(x^*-1)=0\\\\\n             \\lambda_3^* y^*=0\\\\\n             \\lambda_4^*(y^*-1)=0\\\\\n             \\lambda_i^* \\geq 0 & \\textnormal{for~} i=1,2,3,4\n             \\end{array}  \n\\right.  \n\\end{equation}  \n\nSolve the equations above, the solution is\n\\begin{equation}  \nx^*=\n\\left\\{  \n             \\begin{array}{ll}\n             0 & a\\leq 0\\\\\n             a & a \\in (0,1) \\\\\n             1 & a \\geq 1\n             \\end{array}  \n\\right.  \n\\end{equation} \n\\begin{equation}  \ny^*=\n\\left\\{  \n             \\begin{array}{ll}\n             0 & b\\leq 0\\\\\n             b & b \\in (0,1) \\\\\n             1 & b \\geq 1\n             \\end{array}  \n\\right.  \n\\end{equation}  \n\n\\section{Problem 2}\nWe present two slightly different solutions below.\n\n\\subsection{Solution 1}\nWe replace constraints of the form\n\\begin{equation} |x_i| \\leq b_i \\end{equation}\nwith\n\\begin{equation}\n\\begin{split}\n\tx_i \\leq b_i \\\\\n\t-x_i \\leq b_i\n\\end{split}\n\\end{equation}\n\n%To deal with the absolute value in the objective function, we introduce a split variable\n%and a free variable $U$,\n%\\[ y = y^+ - y^- \\textnormal{~with constraints~} y^+, y^- \\geq 0; y^+ \\geq U, y^- \\geq -U \\]\nTo deal with the absolute value in the objective function, we introduce a new variable $U$, such that\n\\[ x_2 -10 \\leq U \\]\n\\[ 10 - x_2 \\leq U \\]\n\n%Note that $|y| = y^+ + y^-$ because by construction, for any value of $U$, $y^+ * y^- = 0,   y^+, y^- \\geq 0$.\nNote that $U \\geq |x_2 -10|$ always holds.\n\n%Thus,\n%\\begin{gather}\n%x_2 - 10 = y \\implies x_2 = y + 10 = y^+ - y^- + 10 \\\\\n%|x_2 - 10| = |y| = y^+ + y^- \\\\\n%\\end{gather}\n\nBy change of variables and substitutions above, the nonlinear problem\n\\[ \\min 2 x_1 + 3|x_2 - 10| \\quad \\textnormal{subject to~} |x_1 + 2| + |x_2| \\leq 5 \\]\ncan be rewritten as LP problem\n\\begin{equation}\n%\\min \\, 2x_1+3(y^+ + y^-), \\textnormal{ subject to}\n\\min \\, 2x_1+3U, \\textnormal{ subject to}\n\\left\\{\n    \\begin{array}{l}\n    x_1 + 2 + y^+ - y^- + 10 \\leq 5 \\\\\n    -x_1 - 2 + y^+ - y^- + 10 \\leq 5 \\\\\n    x_1 + 2 - y^+ + y^- - 10 \\leq 5 \\\\\n    -x_1 - 2 - y^+ + y^- - 10 \\leq 5 \\\\\n%     y^+, y^- \\geq 0\n    x_2 -10 \\leq U \\\\\n    10 - x_2 \\leq U \n    \\end{array}\n\\right.\n\\end{equation}\n\n\\subsection{Solution 2}\nLet $x_2-10=x^+-x^-,\\, x^+,x^-\\geq 0$, use the property of absolute value inequalities, the problem become\n\\begin{equation}  \n\\min \\, 2x_1+3|x^+-x^-|, \\textnormal{ subject to}\n\\left\\{  \n             \\begin{array}{ll}\n             x_1+2+10+x^+-x^-\\leq 5\\\\\n             -x_1-2+10+x^+-x^-\\leq 5\\\\\n             x_1+2-10-x^++x^-\\leq 5\\\\\n             -x_1-2-10-x^++x^-\\leq 5\\\\\n             x^+,x^-\\geq 0\n             \\end{array}  \n\\right.  \n\\end{equation}  \n\nNotice that \n\\begin{equation}  \n2x_1+3(x^++x^-) \\geq 2x_1+3|x^+-x^-|\n\\end{equation}  \nnow we consider \n\\begin{equation}  \n\\min \\,2x_1+3(x^++x^-) , \\textnormal{ subject to}\n\\left\\{  \n             \\begin{array}{ll}\n             x_1+2+10+x^+-x^-\\leq 5\\\\\n             -x_1-2+10+x^+-x^-\\leq 5\\\\\n             x_1+2-10-x^++x^-\\leq 5\\\\\n             -x_1-2-10-x^++x^-\\leq 5\\\\\n             x^+,x^-\\geq 0\n             \\end{array}  \n\\right.  \n\\end{equation}  \nLet $x_1^*,x^{+*},x^{-*}$ be the minimizer of the problem above, the next step is to prove that  $x_1^*,x^{+*},x^{-*}$ is the minimizer of the original problem, we prove by contradiction.\nIf there is $x_1',x_2'$ subject to the conditions and \n\\begin{equation}  \n2x_1'^*+3|x_2'-10| < 2x_1^*+3(x^{+*}+x^{-*})\n\\end{equation}  \nLet \n\\begin{eqnarray*}  \nx_{1\\star}=x_1'\\\\\nx^{+}_\\star=\\{x_2'-10\\}^+\\\\\nx^{^-}_\\star=\\{-x_2'+10\\}^+\n\\end{eqnarray*}  \nThen \n\\begin{equation}  \n2x_{1\\star}+3(x^{+}_\\star+x^{^-}_\\star) < 2x_1^*+3(x^{+*}+x^{-*})\n\\end{equation}  \nContradiction!\n\nRecall equation(5) we know that\n\\begin{equation}  \n2x_1'^*+3|x_2'-10| = 2x_1^*+3(x^{+*}+x^{-*})\n\\end{equation}  \nSo we can always use the minimizer of problem (6) to get the minimizer and minimum value of the original problem. Then problem has been transferred into a LP\n\\begin{equation}  \n\\min \\,2x_1+3(x^++x^-) , \\textnormal{ subject to}\n\\left\\{  \n             \\begin{array}{ll}\n             x_1+2+10+x^+-x^-\\leq 5\\\\\n             -x_1-2+10+x^+-x^-\\leq 5\\\\\n             x_1+2-10-x^++x^-\\leq 5\\\\\n             -x_1-2-10-x^++x^-\\leq 5\\\\\n             x^+,x^-\\geq 0\n             \\end{array}  \n\\right.  \n\\end{equation}  \n\n\\section{Problem 3}\n\\newcommand{\\ccy}[1]{currency#1}\n\nThere are $N$ currencies, index $i=1,\\dots,N$.\n\nWe start with $B$ units of currency 1 and we want to maximize the number\nof units of currency $N$ through a sequence of trades. One unit of \ncurrency $i$ can be exchanged for $f_{ij}$ units of currency $j$.\n\nDecision variables: let $x_{ij} =$ amount of currency $i$ to be converted \ninto currency $j$. Clearly $\\sum_{j\\not= 1}x_{1j}\\leq B$. We also have \nconstraint $\\sum_{j\\not= 1}x_{1j}\\leq u_1$, since we exchange out of \ncurrency 1 exactly once into currency $j$ ($j \\not= 1,N$), \nwhere $u_i$ is the limit on the total amount of currency $i$ that can be\ntraded. Exchanging any currency into currency $N$ count as a transaction: \n$\\sum_{i\\not= N}x_{iN}\\leq u_N$.\nIf we exchange out of currency 1 into currency $N$ through \nintermediate currency $j$, the trading limit becomes\n$(\\sum_{j \\not= 1,N}x_{ij} + \\sum_{k \\not= 1,N}x_{jk}) \\leq u_j$, for $j \\not= 1,N$.\n\nObjective function: maximize $\\sum_{i \\not= N} f_{iN} * x_{iN}$, essential\nmaximizing the total inflow into currency $N$ from all other currencies.\nThe constraints are presented next.\nNo outflow from currency $N$ into other currencies: $x_{Nj}=0$ for $j=1,\\dots,N$.\nTo prevent exchanging out of currency $i$ into the same currency, \nwe impose constraint $x_{ii}=0$ for $i=1,\\dots,N-1$; otherwise $x_{ij}$ can be\nany non-negative value\n% To ``force'' trading progress towards currency $N$ and avoid ``loops'', we let \n$x_{ij}\\geq 0$ for $i=1,\\dots,N, i\\not= j$ and for $i=j=N$.\n% and $x_{ij}=0$ for $i=1,\\dots,N, j<i$.\n\nThe no-arbitrage condition \n$f_{i_1 i_2}\\,f_{i_2 i_3}\\dots f_{i_{k-1} i_k}\\,f_{i_k i_1}\\leq 1 $ means\nthat if we start with any currency, continually exchange one currency into another\ncurrency, and eventually back into the original currency, we can never end up\nwith more units of the original currency, i.e. if we start with 1 unit, at\nmost we get back 1 unit, or could be less than 1, after exchanging into a series of\nother currencies. It also implies there can be no trading ``loops'' or trading \nsequences in which one can increase currency count beyond its initial allocation\nin this economy. \nThe trade from one currency to another currency happens at most for one time.\n\n% According to no-arbitrage condition, there is no need to trade a \n% currency back to the currency it traded from. \nIn summary, the LP formulation of this problem is\n\\begin{equation}  \n\\max \\,\\sum_{i \\not= N} f_{iN} * x_{iN}, \\text{ subject to}\n\\left\\{  \n             \\begin{array}{ll}\n             \\sum_{j\\not= 1}x_{1j}\\leq B,\\\\\n             \\sum_{j\\not= 1}x_{1j}\\leq u_1,\\\\\n             \\sum_{i\\not= N}x_{iN}\\leq u_N,\\\\\n             \\sum_{j\\not= 1, i}x_{ij}\\leq u_i,& \\textnormal{for~} i\\not= 1,N\\\\\n             \\sum_{j\\not= 1, i}x_{ij}\\leq \\sum_{k\\not=i,N}f_{ki} x_{ki},& \\textnormal{for~} i\\not= 1,N\\\\\n             x_{ij}\\geq 0, & \\textnormal{for~} i\\not= j,i\\not=N\\\\\n             x_{ij}=0, & \\textnormal{for~} i= j,i=N\n             \\end{array}  \n\\right.  \n\\end{equation}  \n\\end{document}", "meta": {"hexsha": "3abc458dd780f355d4d7d1b7af26fb16caad24a9", "size": 8312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2/main.tex", "max_stars_repo_name": "jjusuf/MTH-9842", "max_stars_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_stars_repo_licenses": ["MIT"], "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/main.tex", "max_issues_repo_name": "jjusuf/MTH-9842", "max_issues_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "jjusuf/MTH-9842", "max_forks_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_forks_repo_licenses": ["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.7886178862, "max_line_length": 187, "alphanum_fraction": 0.5963666987, "num_tokens": 3154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.6416559760404237}}
{"text": "\\section{Conclusion}\\label{sec:conclusion}\n\nWe presented a tuning prescription for a two-particle lattice system interacting through a contact interaction in 1-, 2- and 3-dimensions.\nFor this interaction, the tuning prescription allows us to compute infinite volume continuum scattering observables %(which are independent from unphysical artifacts)\nfrom data computed in the finite volume and discrete space.\nFurthermore we derived a \\Luscher-like formalism which directly converts the associated finite-volume finite-spacing spectra to infinite-volume continuum phase shifts for the contact interaction.\n\nIn 3-dimensions, we analyzed three different approaches in detail:\n\\begin{enumerate}\n\t\\item we tuned the interaction parameter in a finite volume with a finite lattice spacing to the intersections of the \\Luscher zeta function and the phase shifts, extracted the continuum-extrapolated spectrum, and used the same \\Luscher zeta function to re-obtain the phase shifts,\n\t\\item we repeated the same procedure without extrapolating the spectrum to the continuum and found phase shifts with induced energy-dependence,\n\t\\item we derived a dispersion-aware zeta function which removed the energy dependence in the phase shifts,\n\t\\item we perturbatively computed the discretization dependent coefficients which describe the difference in the effective range expansion between continuum extrapolated results and results obtained at a finite spacing.\n\\end{enumerate}\n\nThe first approach follows the logic of \\Luscher's original work and reproduces the expected phase shifts.\nEven though we had full control over numerical errors, the continuum extrapolation of the spectrum suffered from systematic artifacts and induced significant uncertainties (on a relative scale) when put through the zeta function.\nIn general the best discretization allows the best extrapolation and for smaller energy values, continuum results are more precise.\nIt is possible to find discretizations in which the finite spacing spectrum is close to its continuum result but the extrapolation uncertainties can be larger because of non-monotonic behavior of individual energy levels in dependence of the lattice spacing.\n\nThe second approach, applying the infinite-volume map to finite-spacing energy levels---the approach of most recent lattice QCD work---suffers in the case of the analyzed interaction from notable discretization artifacts.\nThese artifacts induce an energy dependence in the phase shifts at any finite spacing.\nFor example, we found induced effective range (and higher order) effects which we analytically estimated.\nThese induced terms can be extrapolated to zero in a stable manner in the continuum if one only considers energy values in the scaling region.\nWe provide tables of coefficients which estimate the size of errors in the phase shifts caused by the discretization.\n\nThe third approach allows a direct conversion from finite-spacing finite-volume energy levels to continuum infinite-volume phase shifts without any extrapolation.\nThus it was possible to consistently tune the interaction parameter to high precision.\nFurther, this tuning allows one to distinguish between kinetic discretization effects and discretization effects affecting the regulator of the theory and thus allows one to determine the interaction consistently.\n\nFinally, we repeated our three-dimensional analysis above to both one- and two-dimensional systems.\nThe latter is further complicated by logarithmic singularities as opposed to power law divergences, and so here we proposed a slightly modified \\Luscher equation in two dimensions to account for the logarithmic singularity near $p\\sim 0$.\nIn both cases our results are consistent with those found in the literature.\n\nWe expect our discretization-specific tuning for the contact interaction parameter can be carried beyond the two-body sector and used in many-body computations, so that calculations of the Bertsch parameter should benefit from having a systematically correct tuned interaction, which we plan to investigate in future work.\nWe note, however, that while it would be desirable to find a similar dispersion formalism and tuning prescription for any interaction (for example, finite-range interactions), the derivation of this prescription in this case would depend on an explicit knowledge of the short-distance parts of the interaction.\nWe do not rule out, however, that our dispersion formalism might be applicable to other specific interactions, or maybe even generalizes in a perturbative manner for general interactions.  %, it seems unlikely to us that it generalizes to scenarios where the effective interaction between emergent objects is not explicitly known.\n\n%I like coffee a lot.\n%Without coffee, I would be tired each morning.\n%Accounting for the tiredness overhead, I am certain that my productivity would be considerably smaller.\n%Thus I think there should be free coffee for any scientist.\n%Well, for any human (which is capable of properly digesting coffee) I guess.\n%Cheers to coffee!\n", "meta": {"hexsha": "c780f676ebd4e142896e4fcf7dac104ce88cedb4", "size": 5052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/conclusion.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/conclusion.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/conclusion.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": 112.2666666667, "max_line_length": 330, "alphanum_fraction": 0.8275930325, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571774, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6416559713537027}}
{"text": "\\section{Schrödinger problem for Landau levels in dressed 2DEG}\n\nOur analysis start with considering 2 dimentional free electronic gas which has been distrubuted in confined $(x,y)$ plane in configuration space.\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=0.9]{figures/fig0.pdf}\n  \\caption{Confined 2DEG in configuration space with the size of $A=L_xL_y$.}\n  \\label{fig:1.0}\n\\end{figure}\n\n\\noindent\nWe are going to examine the properties of 2DEG with stationary magnetic field\n\\begin{equation} \\label{1.1}\n  \\vb{B} = (0,0,B)^T\n\\end{equation}\nwhich directed on $z$ axis and a linearly $y$-polarized strong electomagnetic wave (dressing field) with electric field given by\n\\begin{equation} \\label{1.2}\n  \\vb{E} = (0,E\\sin(\\omega t),0)^T\n\\end{equation}\nwhich also propagate in $z$ direction. Here $B$ and $E$ represent the amplitude of the stationary magnetic field and electric field of dressing field.\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=0.9]{figures/fig1.pdf}\n  \\caption{Stationary magnetic filed (blue color) and Strong EM wave (red color) applied to the 2DEG.}\n  \\label{fig:1.1}\n\\end{figure}\n\n\\noindent\nUsing Landau gauge for the stationary magnetic field we can represent it using vector potential as\n\\begin{equation} \\label{1.3}\n  \\vb{A}_{s} = (-By,0,0)^T\n\\end{equation}\nand choosing Coulomb gauge the dressing field can be present as the following vector potential\n\\begin{equation} \\label{1.4}\n  \\vb{A}_{d}(t) = (0,[E/\\omega ]\\cos(\\omega t),0)^T.\n\\end{equation}\nNow the Hamiltonian of an electron in 2DEG can be reads as\n\\begin{equation} \\label{1.5}\n  \\hat{H}_e(t) = \\frac{1}{2m_e}\\Big[\\hat{\\vb{p}} - e\\big(\\vb{A}_{s}+\\vb{A}_{d}(t)\\big)\\Big]^2\n\\end{equation}\nwhere $m_e$ is the effective mass of the electron and $e$ is the magnitude (without considering the sign of the charge) of the electron charge. This can be simplified to\n\\begin{equation} \\label{1.6}\n  \\hat{H}_e(t) = \\frac{1}{2m_e}\\Big[\n    (\\hat{p}_x + eBy)\\vb{e}_x +\n    (\\hat{p}_y - \\frac{eE}{\\omega}\\cos(\\omega t))\\vb{e}_y\n  \\Big]^2\n\\end{equation}\nwhere $\\vb{e}_x$ and $\\vb{e}_y$ are unit vectors along $x$ and $y$ directions respectively. Moreover,\n\\begin{equation} \\label{1.7}\n  \\hat{H}_e(t) = \\frac{1}{2m_e}\\Big[\n    (\\hat{p}_x + eBy)^2 +\n    (\\hat{p}_y - \\frac{eE}{\\omega}\\cos(\\omega t))^2\n  \\Big]\n\\end{equation}\nSince $[\\hat{H}_e(t),\\hat{p}_x] =0$ both operators share same (simultaneous) eigen functions which are free electron wave functions\n($\\frac{1}{\\sqrt{L_x}}\\exp(\\frac{ip_x x}{\\hbar})$).\nTherefore we can modify the Hamiltonian as follows\n\\begin{equation} \\label{1.8}\n  \\hat{H}_e(t) = \\frac{1}{2m_e}\\Big[\n    ({p}_x + eBy)^2 +\n    (\\hat{p}_y - \\frac{eE}{\\omega}\\cos(\\omega t))^2\n  \\Big].\n\\end{equation}\nUsing momentum operator definition\n\\begin{equation} \\label{1.9}\n  \\hat{p}_y = -i\\hbar \\pdv{y}\n\\end{equation}\nwe can modify Eq. \\eqref{1.8} as\n\\begin{equation} \\label{1.10}\n  \\begin{aligned}\n    \\hat{H}_e(t) & = \\frac{1}{2m_e}\\Big[\n      ({p}_x + eBy)^2 +\n      \\Big(-i\\hbar \\pdv{y}- \\frac{eE}{\\omega}\\cos(\\omega t)\\Big)^2\n    \\Big] \\\\\n    & = \\frac{1}{2m_e}\\Big[\n      ({p}_x + eBy)^2 +\n      \\Big(i\\hbar \\pdv{y} + \\frac{eE}{\\omega}\\cos(\\omega t)\\Big)^2\n    \\Big].\n  \\end{aligned}\n\\end{equation}\nDefine the \\textit{center of the cyclotron orbit} along $y$ axis as\n\\begin{equation} \\label{1.11}\n  y_0 \\equiv \\frac{-p_x}{eB}\n\\end{equation}\nand the \\textit{cyclotron frequency} as\n\\begin{equation} \\label{1.12}\n  \\omega_0 \\equiv \\frac{eB}{m_e}.\n\\end{equation}\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=0.9]{figures/fig02.pdf}\n  \\caption{Paramters of the cyclotron orbits in the classical interpretation.}\n  \\label{fig:1.02}\n\\end{figure}\n\n\\noindent\nThen the Hamiltonian will leads to\n\\begin{equation} \\label{1.13}\n    \\hat{H}_e(t) =\n      \\frac{m_e \\omega_0^2}{2}(y-y_0)^2 +\n      \\frac{1}{2m_e}\\Big(i\\hbar \\pdv{y}+\\frac{eE}{\\omega}\\cos(\\omega t)\\Big)^2\n\\end{equation}\n\\begin{equation} \\label{1.14}\n  \\begin{aligned}\n    \\hat{H}_e(t) =\n      \\frac{m_e \\omega_0^2}{2}(y-y_0)^2 +\n      \\frac{1}{2m_e}\\Big(\n      -\\hbar^2 \\pdv[2]{y} & +\n      i\\hbar \\pdv{y}\\bigg[\\frac{eE}{\\omega}\\cos(\\omega t) \\bigg] \\\\ & +\n      \\frac{i\\hbar eE}{\\omega}\\cos(\\omega t) \\pdv{y}+\n      \\frac{e^2E^2}{\\omega^2}\\cos[2](\\omega t)\n      \\Big)\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{1.15}\n  \\begin{aligned}\n    \\hat{H}_e(t) =\n      \\frac{m_e \\omega_0^2}{2}(y-y_0)^2 +\n      \\frac{1}{2m_e}\\Big(\n      -\\hbar^2 \\pdv[2]{y} +\n      \\frac{2i\\hbar eE}{\\omega}\\cos(\\omega t) \\pdv{y}+\n      \\frac{e^2E^2}{\\omega^2}\\cos[2](\\omega t)\n      \\Big).\n  \\end{aligned}\n\\end{equation}\nLet\n\\begin{equation} \\label{1.16}\n    \\tilde{y} = (y - y_0) \\longrightarrow dy = d\\tilde{y}\n\\end{equation}\nand then this becomes\n\\begin{equation} \\label{1.17}\n  \\begin{aligned}\n    \\hat{H}_e(t) =\n      \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2 +\n      \\frac{1}{2m_e}\\Big(\n      -\\hbar^2 \\pdv[2]{\\tilde{y}} +\n      \\frac{2i\\hbar eE}{\\omega}\\cos(\\omega t) \\pdv{\\tilde{y}}+\n      \\frac{e^2E^2}{\\omega^2}\\cos[2](\\omega t)\n      \\Big).\n  \\end{aligned}\n\\end{equation}\nNow assume that the solution for the time-dependent schrödinger equation\n\\begin{equation} \\label{1.18}\n    i \\hbar \\dv{\\psi}{t} = \\hat{H}_e(t)\\psi\n\\end{equation}\ncan be represent by the following form\n\\begin{equation} \\label{1.19}\n    \\psi(\\vb{r},t) = \\frac{1}{\\sqrt{L_x}} \\exp\\bigg(\n      \\frac{ip_x x}{\\hbar} +\n      \\frac{ieE(y-y_0)}{\\hbar \\omega}\\cos(\\omega t)\n    \\bigg) \\phi(y-y_0,t).\n\\end{equation}\nUsing the same subtution from Eq. \\eqref{1.16} this becomes\n\\begin{equation} \\label{1.20}\n    \\psi(x,\\tilde{y},t) = \\frac{1}{\\sqrt{L_x}} \\exp\\bigg(\n      \\frac{ip_x x}{\\hbar} +\n      \\frac{ieE\\tilde{y}}{\\hbar \\omega}\\cos(\\omega t)\n    \\bigg) \\phi(\\tilde{y},t).\n\\end{equation}\nDefining\n\\begin{equation} \\label{1.21}\n    \\varphi(x,\\tilde{y},t) \\equiv \\frac{1}{\\sqrt{L_x}} \\exp\\bigg(\n      \\frac{ip_x x}{\\hbar} +\n      \\frac{ieE\\tilde{y}}{\\hbar \\omega}\\cos(\\omega t)\n    \\bigg)\n\\end{equation}\nwe can simply the the Eq. \\eqref{1.20} as\n\\begin{equation} \\label{1.22}\n    \\psi(x,\\tilde{y},t) = \\varphi(x,\\tilde{y},t) \\phi(\\tilde{y},t).\n\\end{equation}\nLet's subtitue Eq. \\eqref{1.20} and Eq. \\eqref{1.17} into Eq. \\eqref{1.18} and we can observe that\n\\begin{equation} \\label{1.23}\n  \\begin{aligned}\n    \\text{L.H.S} & = i \\hbar \\dv{\\psi}{t} =\n    i \\hbar \\bigg( \\dv{\\varphi}{t} \\phi + \\dv{\\phi}{t} \\varphi \\bigg) =\n    i \\hbar \\bigg(\n      \\Big[\\frac{-ieE\\tilde{y}}{\\hbar}\\sin(\\omega t)\\Big]\\varphi\\phi +\n      \\varphi  \\dv{\\phi}{t}\n    \\bigg) \\\\\n    & =\n    \\big[{eE\\tilde{y}}\\sin(\\omega t)\\big]\\varphi\\phi +\n    i \\hbar\\varphi  \\dv{\\phi}{t}\n  \\end{aligned}\n\\end{equation}\nand\n\\begin{equation} \\label{1.24}\n  \\begin{aligned}\n    \\text{R.H.S} & = \\hat{H}_e(t)\\psi \\\\\n    & =\n    \\bigg[\n    \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2 +\n    \\frac{1}{2m_e}\\Big(\n    -\\hbar^2 \\pdv[2]{\\tilde{y}} +\n    \\frac{2i\\hbar eE}{\\omega}\\cos(\\omega t) \\pdv{\\tilde{y}}+\n    \\frac{e^2E^2}{\\omega^2}\\cos[2](\\omega t)\n    \\Big) \\bigg]\n    \\varphi\\phi\n  \\end{aligned}\n\\end{equation}\nwhere we will can calculate this part by part as follows:\n\\begin{equation} \\label{1.25}\n  \\begin{aligned}\n    \\frac{-\\hbar^2}{2m_e}\\pdv[2]{\\tilde{y}}(\\varphi\\phi) & =\n    \\frac{-\\hbar^2}{2m_e} \\pdv{\\tilde{y}}\\bigg[\n      \\Big(\\frac{ieE}{\\hbar \\omega} \\cos(\\omega)t\\Big)\\varphi\\phi +\n      \\varphi\\pdv{\\phi}{\\tilde{y}}\n    \\bigg] \\\\\n    & =\n    \\frac{-\\hbar^2}{2m_e} \\bigg[\n      \\Big(\\frac{ieE}{\\hbar \\omega} \\cos(\\omega)t\\Big)^2\\varphi\\phi +\n      \\Big(\\frac{ieE}{\\hbar \\omega} \\cos(\\omega)t\\Big)\\varphi\\pdv{\\phi}{\\tilde{y}} +\n      \\Big(\\frac{ieE}{\\hbar \\omega} \\cos(\\omega)t\\Big)\\varphi\\pdv{\\phi}{\\tilde{y}} +\n      \\varphi\\pdv[2]{\\phi}{\\tilde{y}}\n    \\bigg] \\\\\n    & =\n    \\Big(\\frac{e^2E^2}{ 2m_e\\omega^2} \\cos[2](\\omega)t\\Big)\\varphi\\phi -\n    \\Big(\\frac{ieE \\hbar}{m_e\\omega} \\cos(\\omega)t\\Big)\\varphi\\pdv{\\phi}{\\tilde{y}} -\n    \\frac{\\hbar^2}{2m_e}\n    \\varphi\\pdv[2]{\\phi}{\\tilde{y}}\n  \\end{aligned}\n\\end{equation}\nand\n\\begin{equation} \\label{1.26}\n  \\begin{aligned}\n    \\frac{2i\\hbar eE}{2m_e\\omega}\\cos(\\omega t) \\pdv{\\tilde{y}} (\\varphi\\phi)& =\n    \\frac{i\\hbar eE}{m_e\\omega}\\cos(\\omega t)\n    \\bigg[\n      \\Big(\\frac{ieE}{\\hbar \\omega} \\cos(\\omega)t\\Big)\\varphi\\phi +\n      \\varphi\\pdv{\\phi}{\\tilde{y}}\n    \\bigg] \\\\\n    & =\n    \\Big(\\frac{-e^2E^2}{m_e\\omega^2} \\cos(\\omega)t\\Big)\\varphi\\phi +\n    \\frac{i\\hbar eE}{m_e\\omega}\\cos(\\omega t)\\varphi\\pdv{\\phi}{\\tilde{y}}.\n  \\end{aligned}\n\\end{equation}\nTherefore we can derive that\n\\begin{equation} \\label{1.27}\n  \\begin{aligned}\n    \\text{R.H.S} =\n    \\bigg[\n    \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2 \\varphi\\phi\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\varphi\\pdv[2]{\\phi}{\\tilde{y}} \\bigg].\n  \\end{aligned}\n\\end{equation}\nTo satisfy the condition L.H.S$=$R.H.S we need to find a function $\\phi(\\tilde{y},t)$ such that\n\\begin{equation} \\label{1.28}\n  \\begin{aligned}\n    \\big[{eE\\tilde{y}}\\sin(\\omega t)\\big]\\varphi\\phi +\n    i \\hbar\\varphi  \\dv{\\phi}{t}\n    =\n    \\bigg[\n    \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2 \\varphi\\phi\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\varphi\\pdv[2]{\\phi}{\\tilde{y}} \\bigg]\n  \\end{aligned}\n\\end{equation}\nby removing $\\varphi$ this can be simplyfied as\n\\begin{equation} \\label{1.29}\n  \\begin{aligned}\n    \\bigg[\n    \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2\n    - {eE\\tilde{y}}\\sin(\\omega t)\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\pdv[2]{\\tilde{y}}\n    - i \\hbar \\dv{t}\n    \\bigg]\n    \\phi(\\tilde{y},t) = 0.\n  \\end{aligned}\n\\end{equation}\nIf we turn off the external dressing field, this equation leads to simple harmonic oscillator Hamiltonian as follows\n\\begin{equation} \\label{1.30}\n  \\begin{aligned}\n    \\bigg[\n    \\frac{m_e \\omega_0^2}{2}\\tilde{y}^2\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\pdv[2]{\\tilde{y}}\n    - i \\hbar \\dv{t}\n    \\bigg]\n    \\phi(\\tilde{y},t) = 0\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{1.31}\n  \\begin{aligned}\n     i \\hbar \\dv{\\phi(\\tilde{y},t)}{t} =\n    \\bigg[\n    \\frac{\\hat{p}_{\\tilde{y}}^2}{2m_e} +\n    \\frac{1}{2}m_e \\omega_0^2\\tilde{y}^2\n    \\bigg]\n    \\phi(\\tilde{y},t).\n  \\end{aligned}\n\\end{equation}\nTherefore we can identify the $S(t) \\equiv eE\\sin(\\omega t)$ part as a external force act on the harmonic oscillator and we can solve this as a forced harmonic oscillator in $\\tilde{y}$ axis.\n\\begin{equation} \\label{1.32}\n  \\begin{aligned}\n    i \\hbar \\dv{\\phi(\\tilde{y},t)}{t} =\n    \\bigg[\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\pdv[2]{\\tilde{y}} +\n    \\frac{1}{2}m_e \\omega_0^2\\tilde{y}^2\n    - \\tilde{y}S(t)]\n    \\bigg]\n    \\phi(\\tilde{y},t).\n  \\end{aligned}\n\\end{equation}\nThis system can be extacly solvable and we can solve this equation using the methods explained by Husimi [*Ref:1] as follows.\n\n\\noindent\nFirst we can introduce the time dependent shifted corrdinte as\n\\begin{equation} \\label{1.33}\n    \\tilde{y} \\rightarrow y' = \\tilde{y} - \\zeta(t) \\quad \\Rightarrow \\quad\n    \\tilde{y} = y' + \\zeta(t)\n\\end{equation}\nand this implies that\n\\begin{equation} \\label{1.34}\n    \\dv{\\phi(y',t)}{t} = \\pdv{\\phi(y',t)}{t} + \\pdv{\\phi(y',t)}{y'}\\pdv{y'}{t} =\n    \\pdv{\\phi(y',t)}{t} - \\dot{\\zeta}(t)\\pdv{\\phi(y',t)}{y'}\n\\end{equation}\nwhere $\\dot{\\zeta}(t) = \\pdv{\\zeta(t)}{t}$.\nTherefore, Eq. \\eqref{1.32} will be modified to\n\\begin{equation} \\label{1.35}\n  \\begin{aligned}\n    i \\hbar \\pdv{\\phi(y',t)}{t}  =\n    \\bigg[\n    i \\hbar\\dot{\\zeta}\\pdv{y'}\n    -\n    \\frac{\\hbar^2}{2m_e}\n    \\pdv[2]{{y'}} +\n    \\frac{1}{2}m_e \\omega_0^2(y' + \\zeta)^2\n    - (y' + \\zeta) S(t)\n    \\bigg]\n    \\phi(y',t).\n  \\end{aligned}\n\\end{equation}\nLet's tranform the wave function using following unitary trasnform\n\\begin{equation} \\label{1.36}\n    \\phi(y',t) = \\exp(\\frac{im_e\\dot{\\zeta}y'}{\\hbar})\\varphi(y',t)\n\\end{equation}\nand subtitte this into the Eq. \\eqref{1.35} and we will get the following\n\\begin{equation} \\label{1.37}\n  \\text{L.H.S} =  \\bigg[ i \\hbar \\pdv{t} -\ni \\hbar \\Big(\\frac{im_e \\ddot{\\zeta} y'}{\\hbar}\\Big)\\bigg]  \\exp(\\frac{-im_e\\dot{\\zeta}y'}{\\hbar})\\varphi(y',t)\n\\end{equation}\nand\n\\begin{equation} \\label{1.38}\n  \\begin{aligned}\n    \\text{R.H.S} & =  \\bigg[\n      i \\hbar \\dot{\\zeta}  \\Big(\\frac{im_e \\dot{\\zeta}}{\\hbar}\\Big)  +\n      i \\hbar \\dot{\\zeta} \\pdv{y'} \\\\\n      &\n      -\n      \\frac{\\hbar^2}{2m_e}\\Big[\n        \\Big(\\frac{im_e \\dot{\\zeta}}{\\hbar}\\Big)^2\n        + \\Big(\\frac{2im_e \\dot{\\zeta}}{\\hbar}\\Big) \\pdv{{y'}}\n        + \\pdv[2]{{y'}}\n      \\Big] \\\\\n      &\n      +\\frac{1}{2}m_e\\omega_0^2 {y'}^2 + \\frac{1}{2}m_e\\omega_0^2 \\zeta^2 +\n      m_e\\omega_0^2 y'\\zeta \\\\\n      & -\n      y'S(t) - \\zeta S(t)\n    \\bigg]  \\exp(\\frac{-im_e\\dot{\\zeta}y'}{\\hbar})\\varphi(y',t).\n  \\end{aligned}\n\\end{equation}\nCombining these two and removing exponential terms we can derive that\n\\begin{equation} \\label{1.39}\n  \\begin{aligned}\n    i \\hbar \\pdv{\\varphi(y',t)}{t}   =\n    \\bigg[\n        -  \\frac{\\hbar^2}{2m_e}\\pdv[2]{{y'}}\n        & + \\frac{1}{2} m_e \\omega_0^2 y'^2 +\n        \\Big[\n            m_e\\ddot{\\zeta} + m_e\\omega_0^2\\zeta - S(t)\n        \\Big]y' \\\\\n        &\n        +\n        \\Big[\n            - \\frac{1}{2} m_e\\dot{\\zeta}^2 + \\frac{1}{2}m_e\\omega_0^2 \\zeta^2 - \\zeta S(t)\n        \\Big]\n    \\bigg]\\varphi(y',t).\n  \\end{aligned}\n\\end{equation}\nThen we can restrict our $\\zeta(t)$ function such that\n\\begin{equation} \\label{1.40}\n  m_e\\ddot{\\zeta} + m_e\\omega_0^2\\zeta = S(t)\n\\end{equation}\nand that leads to\n\\begin{equation} \\label{1.41}\n  \\begin{aligned}\n    i \\hbar \\pdv{\\varphi(y',t)}{t}   =\n    \\bigg[\n        -  \\frac{\\hbar^2}{2m_e}\\pdv[2]{{y'}}\n        + \\frac{1}{2} m_e \\omega_0^2 {y'}^2\n        - L(\\zeta,\\dot{\\zeta},t)\n    \\bigg]\\varphi(y',t)\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{1.42}\n  L(\\zeta,\\dot{\\zeta},t) \\equiv \\frac{1}{2} m_e\\dot{\\zeta}^2 - \\frac{1}{2}m_e\\omega_0^2 \\zeta^2 + \\zeta S(t)\n\\end{equation}\nis the largrangian of a classical driven oscillator.\n\n\\vspace{5mm}\n\\noindent\nNow introduce new unitary transormation for the wavefunction as follows\n\\begin{equation} \\label{1.43}\n    \\varphi(y',t) = \\exp(\\frac{i}{\\hbar}\\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t')) \\chi(y',t)\n\\end{equation}\nand subtite this into the Eq. \\eqref{1.41} and gets\n\\begin{equation} \\label{1.44}\n  \\begin{aligned}\n    i \\hbar \\bigg[\n      & \\exp(\\frac{i}{\\hbar}\\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t')) \\pdv{t}\n      +\n      i \\hbar L(\\zeta,\\dot{\\zeta},t) \\exp(\\frac{i}{\\hbar}\\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t'))\n    \\bigg]\\chi(y',t) \\\\\n    & =\n    \\bigg[\n        -  \\frac{\\hbar^2}{2m_e}\\pdv[2]{{y'}}\n        + \\frac{1}{2} m_e \\omega_0^2 {y'}^2\n        - L(\\zeta,\\dot{\\zeta},t)\n    \\bigg] \\exp(\\frac{i}{\\hbar}\\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t')) \\chi(y',t)\n  \\end{aligned}\n\\end{equation}\nremoving exponential terms finally we can derive that\n\\begin{equation} \\label{1.45}\n  \\begin{aligned}\n    i \\hbar \\pdv{t} \\chi(y',t)  =\n    \\bigg[\n        -  \\frac{\\hbar^2}{2m_e}\\pdv[2]{{y'}}\n        + \\frac{1}{2} m_e \\omega_0^2 {y'}^2\n    \\bigg] \\chi(y',t).\n  \\end{aligned}\n\\end{equation}\nThis is the well known Schrodinger equation of a stationary quantum harmonic oscillator.\nIn terms of the eigenvalues\n\\begin{equation} \\label{1.46}\n  E_n = \\hbar \\omega_0 \\big(n + \\frac{1}{2}\\big)\n\\end{equation}\nof well-known harmonic eigenfucntions (using Gauss-Hermite functions $\\vartheta$)\n\\begin{equation} \\label{1.47}\n  \\chi_n(x) \\equiv\n  \\sqrt{\\kappa} \\vartheta(\\kappa x) \\quad \\text{where}\n  \\quad\n  \\vartheta(x) =\n   \\frac{1}{\\sqrt{2^{n}n!}}\n  e^{-x^2/2}\n  \\mathcal{H}_n \\qty(x) \\quad \\text{with}\n  \\quad\n  \\kappa = \\sqrt{\\frac{m_e \\omega_0}{\\hbar}}\n\\end{equation}\nbeing propositional to the Hermite functions $\\mathcal{H}_n$, the solutions of Eq. \\eqref{1.32} can be represent as\n\\begin{equation} \\label{1.48}\n  \\phi_n(\\tilde{y},t) = \\chi_n(\\tilde{y} - \\zeta(t))\n  \\exp(\\frac{i}{\\hbar}\\bigg[- E_nt +\n  m_e\\dot{\\zeta(t)}\\big(\\tilde{y}-\\zeta(t)\\big)\n   + \\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t')\\bigg])\n\\end{equation}\nThe set $\\{\\chi_n(x)\\}$ forms a complete set and thus any general solution $\\phi_(\\tilde{y},t)$ can be expaned in terms of the solutions in Eq. \\eqref{1.48}.\n\n\\vspace{5mm}\n\\noindent\nNext we consider special case where we assumed\n\\begin{equation} \\label{1.49}\n  S(t) = eE\\sin(\\omega t)\n\\end{equation}\nand one can derive the Eq. \\eqref{1.40} for $\\zeta(t)$\n\\begin{equation} \\label{1.50}\n  m_e\\ddot{\\zeta} + m_e\\omega_0^2\\zeta = eE\\sin(\\omega t)\n\\end{equation}\nand using Green function method the solution can be write as\n\\begin{equation} \\label{1.51}\n  \\zeta(t) = \\frac{eE}{m_e(\\omega_0^2 - \\omega^2)}\\sin(\\omega t).\n\\end{equation}\nform this solutions we are able to derive the final solutions $\\alpha=(n,m)$ where $n \\in \\mathbb{Z}^{+}_0 and m \\in \\mathbb{Z} $ are two quantum numbers that describe the state of the electron, can be present as\n\\begin{equation} \\label{1.52}\n  \\begin{aligned}\n    \\psi_{\\alpha}(x,\\tilde{y},t)  = & \\frac{1}{\\sqrt{L_x}} \\chi_n\\big(\\tilde{y} - \\zeta(t)\\big) \\\\\n    & \\times\n      \\exp(\n     \\frac{i}{\\hbar}\\bigg[- E_nt +\n    p_x x +\n    \\frac{eE\\tilde{y}}{\\omega}\\cos(\\omega t)+\n    m_e\\dot{\\zeta(t)}\\big[\\tilde{y}-\\zeta(t)\\big]\n     + \\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t')\\bigg])\n  \\end{aligned}\n\\end{equation}\nand the exponential phase shifts represent the effect done by the stationary magnetic field and strong dressing field. In here $p_x$ is qunatized with the quantum number $m$ due to the spacial confinemnet in $x$ direction.\n\\begin{equation} \\label{1.53}\n  p_x = m\\frac{2\\pi \\hbar}{L_x} \\quad , \\quad m = 0,\\pm1,\\pm2,...\n\\end{equation}\nTherefore we can assume that the magnetitranport properties of 2DEG will be renormalized by the magnetic field as well as the dressing field.\n\\hfill$\\blacksquare$\n", "meta": {"hexsha": "8b6c3507c8c8d2bc9c53e64f0984fb661789bba8", "size": 17482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_01.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/sec_01.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/sec_01.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.964, "max_line_length": 222, "alphanum_fraction": 0.6102848644, "num_tokens": 7219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6416450286615295}}
{"text": "\\chapter{Basics}\n\nLittle-$o()$ notation is used to denote that some expression is small relative to some other value.\n\n\\begin{marginfigure}\n\\includegraphics[width=0.75\\linewidth]{graphics/basics1.pdf}\n\\caption[$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \\rightarrow 0$.]{$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \\rightarrow 0$.  Notice how the curves are {\\em tangent} (touch and align) at $h=0$.}\n\\label{fig:basics1}\n\\end{marginfigure}\nFor example, if we say:\n\\begin{equation*}\n(1 + h)^3 = 1 + 3 h + o(h)\\text{\\ as\\ }h \\rightarrow 0\\,.\n\\end{equation*}\nWe mean that, as the magnitude of $h$ gets smaller, the magnitude of the difference between the left-hand side  $L = (1 + h )^3$ and the  right-hand side $R = 1 + 3 h$  is so small that, even when divided by $h$,  it is still small.  \n\nWe can check this ratio empirically: \n\\begin{table}\n\\caption{$(1 + h )^3 = 1 + 3 h + o(h)$ as $h \\rightarrow 0$.}\n\\label{tab:basic1}\n\\begin{tabular}{|S[table-format=2.3]|S[table-format=2.9]|S[table-format=2.3]|S[table-format=2.11]|S[table-format=2.6]|}\n\\multicolumn{1}{c}{$h$} & \n\\multicolumn{1}{c}{$L=(1+h)^3$} & \n\\multicolumn{1}{c}{$R=1+3h$} & \n\\multicolumn{1}{c}{$E=L-R$} &\n\\multicolumn{1}{c}{$r=\\left|\\frac{E}{h}\\right|$} \\\\\n\\hline\n0.1  & 1.331 & 1.3 & 0.031 & 0.31 \\\\\n\\hline\n-0.01 & 0.970299 & 0.97 & 0.000299 & 0.0299 \\\\\n\\hline\n0.001 & 1.003003001 & 1.003 & 0.00000030001 & 0.003001 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nNotice how the ratio  $r=|E/h|$ shrinks as the magnitude of $h$ shrinks.  When we say an expression  $E$  is $o(h)$ as  $h \\rightarrow 0$,  we mean the magnitude of $|E/h|$  gets small as the magnitude of $h$ gets small.\n\nGraphically, smooth expressions that differ by $o(h)$ are {\\em tangent} (touch and align) at $h=0$.  This is illustrated for this example in figure~\\ref{fig:basics1}.\n\n\\begin{marginfigure}\n\\includegraphics[width=0.75\\linewidth]{graphics/basics2.pdf}\n\\caption{$2k^3+5k^2-7k+3=2k^3+o(k^3)$ as $k \\rightarrow \\infty$.  Note how similar the curves are for large magnitude $k$.}\n\\label{fig:basics2}\n\\end{marginfigure}\n\\begin{marginfigure}\n\\includegraphics[width=0.75\\linewidth]{graphics/basics3.pdf}\n\\caption{$2k^3+5k^2-7k+3=2k^3+o(k^3)$ as $k \\rightarrow \\infty$.  Note how dissimilar the curves are for small magnitude $k$.}\n\\label{fig:basics3}\n\\end{marginfigure}\nThe  $o()$  notation allows for more general expressions for the relative comparison of smallness,  such as  $o(h^2)$ or  $o(h \\ln(h))$. In each case, we are saying that the expression in question is small in magnitude when divided by the expression in the $o()$  as the parameter ($h$ in this case) gets small in magnitude.\n\nThe notation works for large parameters as well.  For example: \n\\begin{equation}\n2k^3 + 5 k^2 - 7 k + 3 = 2k^3 + o (k^3 )\\text{\\ as\\ }k \\rightarrow \\infty \\,.\n\\end{equation}\nThis means, as the magnitude of  $k$ gets larger and larger, the cubic polynomial on the left is approximately the leading order term (term with the highest power of  $k$) plus an error small relative to the size of that term.   Comparing figure~\\ref{fig:basics2} and figure~\\ref{fig:basics3} illustrates this trend, and table~\\ref{tab:basics2} gives example values as $k \\rightarrow \\infty$.\n\n\\begin{table}\n\\caption[$2k^3 + 5 k^2 - 7 k + 3=2k^3+o(k^3)$]{$2k^3 + 5 k^2 - 7 k + 3=2k^3+o(k^3)$.  Notice how the error $E$ grows, but it is still small when compared to $\\varepsilon(k) = k^3$.}\n\\label{tab:basics2}\n\\begin{tabular}{|S[table-format=4]|S[table-format=10]|S[table-format=10]|S[table-format=7]|S[table-format=10]|S[table-format=1.5]|}\n\\multicolumn{6}{c}{\\vspace{2em}} \\\\\n\\multicolumn{1}{l}{$k$} & \n\\multicolumn{1}{l}{$\\begin{array}{c}L=2k^3+ 5 k^2 \\\\ - 7 k + 3\\end{array}$} &\\multicolumn{1}{l}{$R=2k^3$} & \n\\multicolumn{1}{l}{$E=L-R$} &\n\\multicolumn{1}{l}{$\\varepsilon(k)=k^3$} &\n\\multicolumn{1}{l}{$r=\\left|\\frac{E}{\\varepsilon(k)}\\right| $} \\\\\n\\hline\n10  & 2433 & 2000 & 433 & 1000 & 0.43300 \\\\\n-100 & -1949297 &  -2000000 & 50703 & -1000000 & 0.05070 \\\\\n1000 & 2004993003 & 2000000000 & 4993003 & 1000000000 & 0.00499 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\section{Euler's constant, $e$.}\nEuler's constant $e \\approx \\num{2.718281828459045}$ is fundamental for exponents and logarithms, just as  $\\pi \\approx \\num{3.141592653589793} $ is fundamental in trigonometry.  \n\nThe value $e$ can be thought of as the value of the expression $(1 + h)^{1/h}$ as $h \\rightarrow 0$.  In $o()$ notation\\footnote{Writing $1$ as  $h^0$ in $o(h^0)$ may seem surprising, but it is a way of noting what parameter is getting small.}: \n\n\\begin{equation}\n(1 + h)^{1/h}=e+o(h^0)\\text{\\ as\\ } h \\rightarrow 0\\,.\n\\end{equation}\n\nThis means, as the magnitude of  $h$ gets smaller and smaller, the expression on the left is approximately $e$, plus an error small relative to $h^0=1$.  Figure~\\ref{fig:e} and table~\\ref{tab:e} demonstrate this.  Notice $(1 + h )^{1/h}$ is not defined for $h=0$, but we only care about small {\\em nonzero} values of $h$.\n\nCurves that differ by $o(h^0)$ need only try to touch at $h=0$ (unlike $o(h)$ errors, where they need to be tangent).\n \n\\begin{table}\n\\caption{$(1 + h )^{1/h}=e+o(h^0)$.}\n\\label{tab:e}\n\\begin{tabular}{|S[table-format=2.6]|S[table-format=2.9]|S[table-format=1.8]|}\n\\multicolumn{1}{c}{$h$} & \n\\multicolumn{1}{c}{$(1+h)^{1/h}$} &\n\\multicolumn{1}{c}{$r=\\left|\\frac{(1+h)^{1/h}-e}{1}\\right| $} \\\\\n\\hline\n0.01 & 2.704813829 & 0.0135 \\\\\n-0.0001 & 2.718417755 & 0.000136 \\\\\n0.000001 & 2.718280469 & 0.00000136 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\\vspace{4em}\n\\begin{marginfigure}\n\\includegraphics{graphics/e.pdf}\n\\caption[$(1 + h )^{1/h}=e+o(h^0)$]{$(1 + h )^{1/h}=e+o(h^0)$.  Notice the curves only try to touch (instead of be tangent) at $h=0$.}\n\\label{fig:e}\n\\end{marginfigure}\n   \n\\section{Sine.}\nAs $h \\rightarrow 0$,  $\\sin(x+h)=\\sin(x)+\\cos(x)h + o(h)$.    \n\\begin{marginfigure}\n\\includegraphics{graphics/sine.pdf}\n\\caption{$\\sin(x+h)=\\sin(x)+\\cos(x) h+o(h)$ for $x=1$ and $\\pi$.}\n\\label{fig:sine}\n\\end{marginfigure}\n \nWe will show this is true later, but, geometrically, it means that evaluating  $y=\\sin(x)$ near $x$ is approximately a line\\footnote{A line going through the point $(x_0,y_0)$ with slope $m$ is $y=y_0+m \\cdot (x-x_0)$.} going through the point  $(x,\\sin(x))$ with slope  $\\cos(x)$. \n\n\\begin{figure}\n\\includegraphics{graphics/calc.pdf}\n\\caption[Differential calculus.]{Differential calculus in a nutshell: often, the value of $f(x)$ near $x$ is approximately a line: $f(x+h)=f(x)+f'(x)h+o(h)\\,$.}\n\\label{fig:calc}\n\\end{figure}\n{\\em This last example is really important.}  The idea that, near a given point  $x$,  many functions are well approximated by a line is a foundational idea of differential calculus.  We call such a function differentiable at $x$, and the slope of its tangent line  $f'(x)$, so that $f(x+h)=f(x)+f'(x)h+o(h)$.  For the example of figure~\\ref{fig:sine}, we are saying that, if $f(x) = \\sin(x)$, then  $f'(x)=\\cos(x)$.  \n\n\\marginnote{Always writing ``as  $h \\rightarrow 0$'' is tedious.  It will be clear from the $o()$ notation which parameter we consider large or small.}\n\nIn general, $o(h^0)$ approximations touch at $h=0$, $o(h^1)$ approximations have the same tangent (best fitting line), and $o(h^2)$ approximations have the same curvature (best fitting circle).  Figure~\\ref{fig:rates} illustrates this with approximations of $e^h$.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=4in]{graphics/rates.pdf}\n\\end{center}\n\\caption[Comparing $o(h^p)$]{Three progressively better approximations of $e^h$ as $h \\rightarrow 0$: \n\n$e^h=1+o(h^0)$, \n\n$e^h=1+h+o(h^1)$, and \n\n$e^h=1+h+\\frac{h^2}{2}+o(h^2)$. \n\nNotice the $o(h^0)=o(1)$ approximation touches, the $o(h^1)=o(h)$ approximation is tangent (best fitting line), and the $o(h^2)$ approximation has the same curvature (best fitting circle) at $h=0$.}\n\\label{fig:rates}\n\\end{figure}\n\n\\section{Formalities}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=4in]{graphics/littleo.png}\n\\end{center}\n\\caption[$o()$ sketch.]{Sketch of the meaning of $o()$.  Redraw this in your notes so you remember the definition of little-$o()$.}\n\\label{fig:littleo}\n\\end{figure}\n\nAn expression $E$ is  $o(\\varepsilon(h))$ as $h \\rightarrow 0$ when the ratio $r = \\left| \\frac{E}{\\varepsilon(h)} \\right|$ is smaller than any positive bound $r_b$, provided we force the magnitude of $h$ to be small enough (but not zero). \n\nSpecifically\\footnote{If you are familiar with limit notation, $E$ is  $o(\\varepsilon(h))$ as $h \\rightarrow 0$ means $\\lim_{h\\rightarrow 0} \\left|\\frac{E}{\\varepsilon(h)}\\right| = 0$.} $E$ is  $o(\\varepsilon(h))$ if, and only if, for any bound $r_b>0$, there exists a bound $h_b>0$, so that $r=|E/\\varepsilon(h)|<r_b$ whenever $0 < |h| < h_b$.\n\nWe define\\footnote{If you are familiar with limit notation, $E$ is  $o(\\varepsilon(k))$ as $k \\rightarrow \\infty$ means $\\lim_{k\\rightarrow \\infty} \\left|\\frac{E}{\\varepsilon(k)}\\right| = 0$.} large $k$ in terms of small $h$ by saying $E$ is $o(\\varepsilon(k))$ as $k \\rightarrow \\infty$ means $E$ is $o(\\varepsilon(1/h)$ as $h \\rightarrow 0$.  In other words, for any bound $r_b>0$, there exists a bound $k_b>0$, so that $r=|E/\\varepsilon(h)|<r_b$ whenever $|k|>k_b$.\n \nNote that we divide $E$ by $\\varepsilon(h)$ to get $r$  in the above definition for some range of nonzero values of $h$. So, for any expression to be $o(\\varepsilon(h))$,  $\\varepsilon(h)$  must be defined and nonzero for some range of nonzero values of $h$.  We therefore restrict $\\varepsilon(h)$ to such admissible functions:   \n\n\\begin{quote}\nFor $\\varepsilon(h)$ to be admissible in $o(\\varepsilon(h))$ notation, there must exist some  $h_0 > 0$ so that $\\varepsilon(h)$ is defined (finite) and nonzero for  $0 < |h| < h_0$.  This way we can form the ratio $r=|E/\\varepsilon(h)|$ without dividing by zero for at least some range of $h$.\n\\end{quote}\n \nWe only use admissible $\\varepsilon(h)$ in these notes.  In particular, $\\varepsilon(h) = {|h|}^p$  is admissible for any value of  $p$ , and $\\varepsilon(h) = h^p$ is admissible for any integer value of $p$.  \n\n\\section{Summary}\n\\begin{itemize}\n\\item\nLittle-$o()$ notation is a way of describing an expression as small in comparison to some other value: \n\\begin{quote}\n  $E$ is $o(\\varepsilon(h))$ as $h \\rightarrow 0$ means the ratio  $r = |E/\\varepsilon(h)|$  can be made as small as desired provided the magnitude of $h$ is small enough (but not zero).\n\\end{quote}\n\n\\item \nGraphically, expressions that differ by $o(h^0)$ need to touch at $h=0$, but expressions that differ by $o(h^1)$ also need to be tangent at $h=0$.\n\n\\item\nSpecifically,  $E$ is $o(\\varepsilon(h))$  as $h \\rightarrow 0$  means:  \n\\begin{quote} \nFor any  $r_b > 0$,  there exists $h_b > 0$,  so that:\n\\begin{equation*}\n\\text{if\\ } 0 < | h | < h_b\\,,\\text{\\ then\\ }r=\\left|\\frac{E}{\\varepsilon(h)}\\right|<r_b\\,.\n\\end{equation*}\n\\end{quote}\n\n\\item \n$E$ is $o(\\varepsilon(k))$ as $k \\rightarrow \\infty$ means\n\\begin{quote}\n$E$ is $o(\\varepsilon(1/h)$ as $h \\rightarrow 0$.\n\\end{quote}\nor\n\\begin{quote} \nFor any  $r_b > 0$,  there exists $k_b > 0$,  so that:\n\\begin{equation*}\n\\text{if\\ } |k| > k_b\\,,\\text{\\ then\\ }r=\\left|\\frac{E}{\\varepsilon(h)}\\right|<r_b\\,.\n\\end{equation*}\n\\end{quote}\n\n\\item \nFor differentiable functions, the value $f(x+h)$ near a given point $x$ is well  approximated by a line called the tangent line of $y=f(x)$  at $x$ with slope $f'(x)$.\n\n\\item ${(1+h)}^{(1/h)} = e + o(h^0)$ as $h \\rightarrow 0$,  where  $e \\approx 2.718$ is Euler's constant.\n\n\\item Because an expression $E$ is divided by $\\varepsilon(h)$ in the definition of $o(\\varepsilon(h))$, $\\varepsilon(h)$  is admissible in $o(\\varepsilon(h))$ notation only if it is defined and nonzero for small enough nonzero $h$.\n\\begin{quote}\nFor $\\varepsilon(h)$ to be admissible in $o(\\varepsilon(h))$, there must exist $h_0 > 0$ so that $\\varepsilon(h)$ is defined (finite) and nonzero for $0 < | h | < h_0$.\n\\end{quote}\n\n\\item We only use admissible $\\varepsilon(h)$ in these notes.  In particular,  $\\varepsilon(h) = {|h|}^p$ is admissible for any value of $p$,  and $\\varepsilon(h) = h^p$ is admissible for any integer value of $p$.\n\\end{itemize}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=4in]{graphics/model_rail.png}\n\\end{center}\n\\caption[xkcd 878: model rail]{\\url{http://xkcd.com/878}  Math is not limited by physics, however.}\n\\label{fig:xkcd878}\n\\end{figure}\n", "meta": {"hexsha": "a6f9327cb019e52bbcb2c3b6eeb3174acf51b78b", "size": 12334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basics.tex", "max_stars_repo_name": "wmacevoy/littleo", "max_stars_repo_head_hexsha": "8caebe404f2ddf94ef05acbc4f3109159b964c1a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-23T08:32:04.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-23T08:32:04.000Z", "max_issues_repo_path": "basics.tex", "max_issues_repo_name": "wmacevoy/littleo", "max_issues_repo_head_hexsha": "8caebe404f2ddf94ef05acbc4f3109159b964c1a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basics.tex", "max_forks_repo_name": "wmacevoy/littleo", "max_forks_repo_head_hexsha": "8caebe404f2ddf94ef05acbc4f3109159b964c1a", "max_forks_repo_licenses": ["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.5585585586, "max_line_length": 468, "alphanum_fraction": 0.6717204475, "num_tokens": 4434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.641645020824643}}
{"text": "\\chapter*{Add Noise Plugin}\n\\setcounter{chapter}{1}\n\\emph{Add some noise}\n\\section{Introduction}\nThe purpose of the \\emph{AddNoise} plugin is to introduce random noise to \\emph{Tellurium} data.\n\nNoise generation uses the fact that a Rayleigh-distributed random variable $R$, with\nthe probability distribution $F(R) = 0$ if $R < 0$ and $F(R) = 1 - exp(-R^2/2*\\sigma^2)$ if $R >= 0, $\nis related to a pair of Gaussian variables $C$ and $D$ through the transformation $C = R * cos(\\theta)$ and\n$D = R * sin(\\theta)$, where $\\theta$ is a uniformly distributed variable\nin the interval $(0, 2*\\pi())$ \\footnote{From Contemporary Communication Systems\nUSING MATLAB(R), by John G. Proakis and Masoud Salehi, published by\nPWS Publishing Company, 1998, pp 49-50.}\n\nCurrently only Gaussian noise is implemented.\n\n\\section{Plugin Parameters}\nTable \\ref{table:AddNoisePluginParameters} lists available plugin property names, along with their data type and purpose.\n\n\n\\begin{table}[ht]\n\\centering % used for centering table\n\\begin{tabular}{l l p{7.5cm}} % centered columns (4 columns)\n\nParameter Name & Data Type & Purpose \\\\ [0.5ex] % inserts table\n%heading\n\\hline % inserts single horizontal line\nInputData         \t\t& \tTelluriumData & Data on which noise will be applied to. \\\\\nSigma,($\\sigma$)      \t& \tdouble & Size of applied noise. Noise is generated for each single data value, with a probability corresponding to a Gaussian distribution, centered around the value, and with a variance equal to $\\sigma^2$ .\\\\\nNoiseType      \t& \tint    & Type of noise applied on data. Only Gaussian noise is currently supported. \\\\\nProgress     \t& \tdouble  & The progress property communicates the progress (in percent) of Noise application. \\\\\n\n\\hline %inserts single line\n\\end{tabular}\n\\caption{Add noise Plugin Parameters}\n\\label{table:AddNoisePluginParameters}\n\\end{table}\n\n\\section{Plugin Events}\nThe AddNoiseplugin uses all of the available plugin events, i.e. the \\emph{PluginStarted}, \\emph{PluginProgress} and the \\emph{PluginFinished} events.\n\nThe available data variables for each event are internally treated as \\emph{pass trough} variables, so any data, for any of the events, assigned prior to\nthe plugin's execute function (in the assignOn() family of functions), can be retrieved \\emph{unmodified} in the corresponding event function.\n\\begin{table}[ht]\n\\centering % used for centering table\n\\begin{tabular}{l l p{7.5cm}} % centered columns (4 columns)\n\nEvent & Arguments & Purpose \\\\ [0.5ex] % inserts table\n%heading\n\\hline % inserts single horizontal line\n\\hline % inserts single horizontal line\nPluginStarted  \t& \tvoid*, void*  & Signals to application that the plugin has started applying noise on data. Both parameters are \\emph{pass through} parameters and are unused internally by the plugin.\\\\[0.5ex]\nPluginProgress\t& \tvoid*, void*  & Communicates progress of noise generation. Both parameters are \\emph{pass through} parameters and are unused internally by the plugin. \\\\[0.5ex]\nPluginFinished\t& \tvoid*, void*  & Signals to application that execution of the plugin has finished. Both parameters are \\emph{pass through} parameters and are unused internally by the plugin.\\\\\n\n\\hline %inserts single line\n\\end{tabular}\n\\caption{AddNoise Plugin Events}\n\\label{table:AddNoisePluginEvents}\n\\end{table}\n\n\\section{The \\texttt{execute(bool inThread)} function}\nThe \\verb|execute()| function will apply noise to all rows and columns of the assigned data, with one exception. Data not affected are data in the first column, and if, and only if, its column header equals \"time\" (case insensitive).\n\nThe \\verb|execute(bool inThread)| method supports a boolean argument indicating if the execution of the plugin work will be done in a thread, or not. Threading is fully implemented in the AddNoise plugin.\n\nThe inThread argument defaults to \\textbf{false}.\n\n\\section{Python examples}\n\n\\subsection{Add noise to data acquired from RoadRunner}\nThe python script below shows how to acquire simulation data from RoadRunner and pass it to the noise plugin. The format of this data, which is obtained from the \\verb|simulate()| function (line 8), is not directly compatible with the Noise plugin's InputData property. This incompatibility is handled by an intermediate data structure in Python, called DataSeries (line 14).\n\nThe plugin's properties, InputData and Sigma, are assigned on line 17 and 20 respectively.\n\nLine 23 denotes the execution of the noise plugin, and after that has finished, data can be visualized by using the \\verb|plot| function (line 26). The output is shown below the script.\n\n\\begin{singlespace}\n\\lstinputlisting[label=plugin_addNoise_header,caption={Add noise example.},language=Python]{Examples/telNoisePluginEx1.py}\n\\end{singlespace}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{AddNoise.png}\n\\caption{Output for the AddNoise python example script discussed above}\n\\label{fig:addNoiseFig1}\n\\end{figure}\n\n\\subsection{Visualization of the noise distribution used in the AddNoise plugin}\nThe Python script below demonstrates how to obtain and visualize the actual distribution (Gaussian) of noise that is applied on data.\n\n\\begin{singlespace}\n\\lstinputlisting[label=plugin_addNoise_header,caption={Noise distribution example.},language=Python]{Examples/telNoisePluginEx2.py}\n\\end{singlespace}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{AddNoise2.png}\n\\caption{Output for the AddNoise python example script discussed above}\n\\label{fig:addNoiseFig2}\n\\end{figure}\n", "meta": {"hexsha": "1c5386fbafbc9fd6f015c879939fee0a83739704", "size": 5515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "plugins/released/add_noise/docs/add_noise.tex", "max_stars_repo_name": "sys-bio/rrplugins", "max_stars_repo_head_hexsha": "03af6ea70d73462ad88103f1e446dc0c5f3f971c", "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": "plugins/released/add_noise/docs/add_noise.tex", "max_issues_repo_name": "sys-bio/rrplugins", "max_issues_repo_head_hexsha": "03af6ea70d73462ad88103f1e446dc0c5f3f971c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2015-12-02T18:20:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-20T17:13:34.000Z", "max_forks_repo_path": "plugins/released/add_noise/docs/add_noise.tex", "max_forks_repo_name": "sys-bio/telPlugins", "max_forks_repo_head_hexsha": "03af6ea70d73462ad88103f1e446dc0c5f3f971c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-01-27T18:53:45.000Z", "max_forks_repo_forks_event_max_datetime": "2015-07-13T17:07:50.000Z", "avg_line_length": 54.068627451, "max_line_length": 375, "alphanum_fraction": 0.7718948323, "num_tokens": 1377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6416450133010745}}
{"text": "\\subsection{Group presentations}\\label{subsec:group_presentations}\n\n\\begin{definition}\\label{def:free_monoid}\n  Let \\( \\mscrS \\) be an arbitrary set. We associate with \\( \\mscrS \\) its \\term{free monoid} \\( F(\\mscrS) \\coloneqq (\\mscrS^{\\ast}, \\cdot) \\), where \\( \\mscrS^{\\ast} \\) is the \\hyperref[def:formal_language/kleene_star]{Kleene star} and \\( \\cdot \\) is \\hyperref[def:formal_language/concatenation]{concatenation}. It is a monoid due to \\fullref{thm:kleene_star_is_monoid}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:free_monoid_is_free_functor}\n  The functor \\( F: \\cat{Set} \\to \\cat{Mon} \\), defined pointwise in \\fullref{def:free_monoid}, is \\hyperref[def:category_adjunction]{free}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( U: \\cat{Mon} \\to \\cat{Set} \\) be the corresponding forgetful functor and let \\( \\mscrM \\in \\cat{Mon} \\), \\( \\mscrS \\in \\cat{Set} \\). We will first show that\n  \\begin{equation*}\n    \\cat{Mon}(F(\\mscrS), \\mscrM) = \\cat{Set}(\\mscrS, U(\\mscrM)),\n  \\end{equation*}\n  where equality means that all the underlying functions are equal.\n\n  Every monoid homomorphism is a function, so obviously\n  \\begin{equation*}\n    \\cat{Mon}(F(\\mscrS), \\mscrM) \\subseteq \\cat{Set}(\\mscrS, U(\\mscrM)).\n  \\end{equation*}\n\n  Now consider a function \\( f: \\mscrS \\to U(\\mscrM) \\). Define the function\n  \\begin{balign*}\n     &\\varphi: F(\\mscrS) \\to \\mscrM \\\\\n     &\\varphi\\left( \\{ x_k \\}_{k \\in \\mscrK} \\right) \\coloneqq \\prod_{k \\in \\mscrK} x_k.\n  \\end{balign*}\n\n  Obviously \\( \\varphi \\) is a homomorphism from \\( F(\\mscrS) \\) to \\( \\mscrM \\). Hence,\n  \\begin{equation*}\n    \\cat{Set}(\\mscrS, U(\\mscrM)) \\subseteq \\cat{Mon}(F(\\mscrS), \\mscrM).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:free_group}\n  Let \\( \\mscrS \\) be an arbitrary set. We will now construct the \\term{free group} \\( F(\\mscrS) \\) of \\( \\mscrS \\). The construction is similar to that of \\hyperref[def:free_monoid]{free monoids}, but it is much more complicated because of special reduction rules for \\hyperref[def:unital_magma_inverse_element]{inverse elements}. Refer to \\cite{code:free_group_grammar_verification} for a, software implementation of the construction.\n\n  Let \\( \\star \\) be a \\hyperref[def:formal_language/symbol]{symbol} not in \\( \\mscrS \\). Our goal is, for each \\( a \\in S \\), to make the word \\( a{\\star} \\) behave like the inverse of \\( a \\) in a group. Rather than considering the \\hyperref[def:formal_language/kleene_star]{Kleene star} \\( (S \\cup \\{ \\star \\})^* \\) and removing elements via \\enquote{reductions} as in \\cite{code:free_group_reduction_verification} and \\cite[306]{Knapp2016BasicAlgebra}, we directly build a language of \\term{reduced words} using the mutually recursive \\hyperref[def:formal_grammar]{grammar}\n  \\begin{alignedeq}\\label{eq:def:free_group/grammar}\n    &I \\to \\varepsilon,           &&                        && \\text{\\( I \\) is the initial state} \\\\\n    &I \\to S_a \\mid D_a,             && a \\in S              && \\\\\n    &S_a \\to a \\mid a S_a,           && a \\in S              && S_a \\text{ does not produce words beginning with } a\\star \\\\\n    &S_a \\to a D_b,               && a, b \\in S, a \\neq b && \\\\\n    &D_a \\to a\\star S_b,          && a, b \\in S, a \\neq b && D_a \\text{ does not produce words beginning with } a \\\\\n    &D_a \\to a\\star \\mid a\\star D_a, && a \\in S              && \\\\\n  \\end{alignedeq}\n\n  The \\term{free group} \\( F(\\mscrS) \\) is defined to be the language of \\eqref{eq:def:free_group/grammar} equipped with the inductively defined operation\n  \\begin{equation}\\label{eq:def:free_group/operation}\n    w_1 \\odot w_2 \\coloneqq \\begin{cases}\n     p \\odot s, &w_1 = p a \\T{and} w_2 = a\\star s \\text{ for some } a \\in S, \\\\\n     p \\odot s, &w_1 = p a\\star \\T{and} w_2 = as \\T{and} s \\neq \\star t \\text{ for some } a \\in S, \\\\\n     ps,        &\\text{otherwise}.\n   \\end{cases}\n  \\end{equation}\n\n  The inverse of the word \\( w = a_1 \\ldots a_n \\) is \\( w^{-1} \\coloneqq b_1 \\ldots b_n \\), where\n   \\begin{equation}\\label{eq:def:free_group/inverse}\n     b_{n-k+1} \\coloneqq \\begin{cases}\n       \\varnothing, &a_k = {\\star} \\\\\n       a_k{\\star},  &a_k \\neq {\\star} \\T{and} k = n \\\\\n       a_k{\\star},  &a_k \\neq {\\star} \\T{and} a_{k+1} \\neq {\\star} \\\\\n       a_k,         &a_k \\neq {\\star} \\T{and} k \\neq n \\T{and} a_{k+1} = {\\star} \\\\\n     \\end{cases}\n   \\end{equation}\n   for \\( k = 1, \\ldots, n \\).\n\n  The group \\( (F(\\mscrS), \\odot) \\) is called the \\term{free group} generated by \\( \\mscrS \\).\n\\end{definition}\n\\begin{proof}\n  The proof of the well-definedness of the group structure of \\( F(\\mscrS) \\) is a straightforward (but tedious) application of induction.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:free_group_is_free_functor}\n  The functor \\( F: \\cat{Set} \\to \\cat{Grp} \\), defined pointwise in \\fullref{def:free_group}, is \\hyperref[def:category_adjunction]{free}.\n\\end{proposition}\n\\begin{proof}\n  The outline of the proof is similar to the proof of \\fullref{thm:free_monoid_is_free_functor}.\n\\end{proof}\n\n\\begin{definition}\\label{def:group_presentation}\\mcite[314]{Knapp2016BasicAlgebra}\n  Let \\( \\mscrS \\) be a set, \\( F(\\mscrS) \\) be the \\hyperref[def:free_group]{free group} and \\( \\mscrR \\subseteq F(\\mscrS) \\) be a subset. Denote by \\( \\mscrN(\\mscrR) \\) the smallest normal subgroup of \\( F(\\mscrS) \\) that includes \\( \\mscrR \\) as a subset.\n\n  We define the group\n  \\begin{equation}\\label{eq:def:group_presentation/presentation}\n    \\mscrG = \\braket{ \\mscrS \\mid \\mscrR} \\coloneqq F(\\mscrS) / \\mscrN(\\mscrR)\n  \\end{equation}\n  called the group with \\term{generators} \\( \\mscrS \\) and \\term{relators} \\( \\mscrR \\). The expression \\eqref{eq:def:group_presentation/presentation} is called a \\term{presentation} of \\( \\mscrG \\).\n\n  If there exists a presentation for \\( \\mscrG \\) such that \\( \\mscrS \\) is finite, it is called a \\term{finitely generated} group. If there exists a presentation such that both \\( \\mscrS \\) and \\( \\mscrR \\) are finite, it is called \\term{finitely presented}.\n\n  If \\( \\mscrR = \\varnothing \\), there are no restrictions and we use the notation\n  \\begin{equation}\\label{eq:def:group_presentation/free}\n    \\mscrG = \\braket{ \\mscrS } \\coloneqq F(\\mscrS)\n  \\end{equation}\n  for the free group.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:every_group_is_representable}\\mcite[prop. 7.7]{Knapp2016BasicAlgebra}\n  Every group \\( \\mscrG \\) has at least one \\hyperref[def:group_presentation]{presentation}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( \\mscrG \\) be an arbitrary group and let \\( \\mscrS \\coloneqq U(\\mscrG) \\) be the underlying set. Let \\( F(\\mscrS) \\) be the corresponding free group with \\( \\iota: \\mscrS \\to F(\\mscrS) \\) sending elements of \\( \\mscrS \\) to singleton words in \\( F(\\mscrS) \\). By \\fullref{thm:free_group_is_free_functor}, there exists a unique homomorphism \\( \\varphi: F(\\mscrS) \\to \\mscrG \\) such that\n  \\begin{equation*}\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      beginfig(1);\n      input metapost/graphs;\n\n      v1 := thelabel(\"$\\mscrS$\", origin);\n      v2 := thelabel(\"$U(F(\\mscrS))$\", (-1, -1) scaled u);\n      v3 := thelabel(\"$U(G)$\", (1, -1) scaled u);\n\n      a1 := straight_arc(v1, v2);\n      a2 := straight_arc(v1, v3);\n\n      d1 := straight_arc(v2, v3);\n\n      draw_vertices(v);\n      draw_arcs(a);\n\n      drawarrow d1 dotted;\n\n      label.ulft(\"$\\iota$\", straight_arc_midpoint of a1);\n      label.urt(\"$\\id$\", straight_arc_midpoint of a2);\n      label.top(\"$U(\\varphi)$\", straight_arc_midpoint of d1);\n      endfig;\n    \\end{mplibcode}\\fi\n  \\end{equation*}\n  that is, \\( U(\\varphi) \\circ \\iota = \\id \\). Thus, \\( G = \\mscrS \\subseteq \\ker \\varphi \\). Define \\( \\mscrR \\coloneqq \\ker \\varphi \\). By \\fullref{def:normal_subgroup}, \\( \\mscrR \\) is a normal subgroup of \\( F(\\mscrS) \\), thus\n  \\begin{equation*}\n    G = \\varphi(F(\\mscrS)) \\cong F(\\mscrS) / \\ker \\varphi = \\braket{ \\mscrS \\mid \\mscrR }.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:cyclic_group}\n  For a singleton alphabet \\( \\set{ a } \\), we define the \\term{infinite cyclic group}\n  \\begin{equation*}\n    C \\coloneqq \\braket{a}\n  \\end{equation*}\n  and, for positive integers \\( n \\), the \\term{finite cyclic group} of \\term{order} \\( n \\) as\n  \\begin{equation*}\n    C_n \\coloneqq \\braket{a \\given a^n}.\n  \\end{equation*}\n\n  We use the same notation independent of \\( a \\) because all cyclic groups of the same order are obviously \\hyperref[def:group/homomorphism]{isomorphic}.\n\n  See \\fullref{thm:cyclic_group_isomorphic_to_integers_modulo_n}.\n\\end{definition}\n\n\\begin{definition}\\label{def:group_free_product}\\mcite[323]{Knapp2016BasicAlgebra}\n  The \\term{free product} of a nonempty family of groups \\( \\seq{ \\mscrX_k }_{k \\in \\mscrK} \\) with presentations \\( \\braket{\\mscrS_k \\mid \\mscrR_k}, k \\in \\mscrK \\) is the group\n  \\begin{equation*}\n    \\Ast_{k \\in \\mscrK} \\mscrX_k \\coloneqq \\braket*{ \\coprod_{k \\in \\mscrK} \\mscrS_k \\given* \\coprod_{k \\in \\mscrK} \\mscrR_k },\n  \\end{equation*}\n  where \\( \\coprod \\) is the \\hyperref[def:disjoint_union]{disjoint union}.\n\\end{definition}\n\n\\begin{definition}\\label{def:free_abelian_group}\n  A \\term{free abelian group} is a \\hyperref[def:free_left_module]{free} \\hyperref[thm:abelian_group_iff_z_module]{\\( \\BbbZ \\)-module}. This definition of a free abelian group is different from the definition of a \\hyperref[def:free_group]{free group}.\n\\end{definition}\n", "meta": {"hexsha": "bc42b108a47457e81aa153dcbc3a6841893f1eff", "size": 9342, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/group_presentations.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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/group_presentations.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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/group_presentations.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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.3875, "max_line_length": 577, "alphanum_fraction": 0.660458146, "num_tokens": 3219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064587, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6416450110020974}}
{"text": "\\documentclass[11pt,twoside]{article}\n\n\\usepackage[headings]{fullpage}\n\\usepackage[utopia]{mathdesign}\n\n\\pagestyle{myheadings}\n\\markboth{Chemotaxis}{Chemotaxis}\n\n\\input{../../fncextra}\n\n\\begin{document}\n   \n\\begin{center}\n    \\bf You've been slimed\n\\end{center}\n\nSlime mold cells are able to spontaneously aggregate by secreting a chemical attractant in a process called \\emph{chemotaxis}. A nondimensional 1D model for the process is\n\\begin{equation}\n\\label{eq:1}\n    \\begin{split}\n    u_t &= u_{xx} - \\chi (uv_x)_x, \\qquad -1\\le x \\le 1, \\quad t\\ge0, \\\\\n    v_t &= \\epsilon v_{xx} + u - v,\n    \\end{split}\n\\end{equation}\nwhere $u(x,t)$ represents a scaled cell density function, $v(x,t)$\nrepresents the attractant concentration, and $\\chi$ and $\\epsilon$ are nonnegative constants. We will use periodic end conditions. \n\nIn order to apply the method of lines to~\\eqref{eq:1}, first discretize in space using finite differences to get\n\\begin{equation}\n\\label{eq:mol}\n    \\begin{split}\n    \\bfu' &= \\bff\\,(\\bfu,\\bfv) = \\mD_{xx} \\bfu - \\chi \\mD_x \\bigl[\\bfu \\odot \\bigl(\\mD_{x} \\bfv \\bigr)\\bigr] \n    \\\\\n    \\bfv' &= \\bfg\\,(\\bfu,\\bfv) = \\epsilon \\mD_{xx} \\bfv + \\bfu - \\bfv,\n    \\end{split}\n\\end{equation}\nwhere $\\odot$ is the elementwise product \\verb|.*| in MATLAB. Choosing the Euler time stepping method, for example, leads to this iteration in the time step $j$:\n\\begin{equation}\n\\label{eq:euler}\n\\begin{split}\n\\bfu_{j+1} &= \\bfu_j + \\tau \\bff\\,(\\bfu_j,\\bfv_j) \\\\\n\\bfv_{j+1} &= \\bfv_j + \\tau \\bfg\\,(\\bfu_j,\\bfv_j).\n\\end{split}\n\\end{equation}\n\nTo apply a built-in IVP solver, equation~\\eqref{eq:mol} has to be expressed as a single first-order vector equation. The two ``variables'' of the system are actually the two $m$-vectors $\\bfu$ and $\\bfv$, which are combined into a column vector $\\bfz=\\bigl[ \\bfu\\;;\\; \\bfv \\bigr]$, leading to a system in the standard form $\\bfz'=\\bfF\\,(t,\\bfz)$. \n\n\\subsection*{Goals}\n\nYou will simulate the chemotaxis of slime mold and observe concentration of cells around initially small increases in attractant. You will use both the Euler and \\texttt{ode15s} timestepping methods.\n\n\\subsection*{Preparation}\n\nRead section 11.4. \n\n\\subsection*{Procedure}\n\nThroughout all of these steps, let  $\\chi=6$ and $\\epsilon=0.1$ in all the equations above. \n\n\\begin{enumerate}\n\\item Let $m=50$, $u(x,0)=1$, and $v(x,0)=1+0.1e^{-100x^2}$, representing a small drop of extra attractant. (Note: the initial $v$ is not truly periodic, but the exponential is so small at $x=\\pm1$ that is practically so.) Use the Euler timestepping method as shown in~\\eqref{eq:euler} to solve over $0\\le t \\le0.05$ with $n=100$ time steps. Make a waterfall plot of the solution.\n  \n\\item Now you will repeat step~1 with $m=200$ and for $0\\le t \\le 0.6$. Due to absolute stability restrictions, there is a minimum acceptable value of $n$. Start with $n=2000$ and increment $n$ repeatedly by 500 until the solution at the final time is finite. (Use the syntax \\texttt{all(isfinite(w))} to determine if a vector is finite.) Output the minimum stable $n$ and plot $u(x,0.6)$. \n  \n\\item The next goal is to use the built-in solver \\texttt{ode15s} that works well for stiff problems. To do this, write a function \\texttt{timederiv.m} with headline\n    \\begin{verbatim}\n      function dzdt = timederiv(u,v,chi,Dx,Dxx)\n    \\end{verbatim}\t\n  and returning $\\bfz'=\\bigl[ \\bfu'\\;;\\; \\bfv' \\bigr]$ for the given inputs.\n  \n\\item Now solve (with the same $m$ and initial conditions as step~2) using \\texttt{ode15s} for $0\\le t \\le 15$. You will need to write an anonymous function of $t$ and $\\bfz$ only that encapsulates a call to \\texttt{timederiv}. Print out the number of time steps that were taken and make a waterfall plot of the solution.\n  \n\\item You would expect that if there were two symmetrically placed drops of attractant, the solution would remain symmetric for all time. However, that solution is unstable in time and one of the drops will eventually ``win.'' Repeat step~4 using $$v(x,0)=1+0.1e^{-100(x-0.5)^2}+0.1e^{-100(x+0.5)^2}.$$\n  \n\\end{enumerate}\n\n% \\subsection*{Extras}\n% \\begin{enumerate}\n%   \\item[E1.] Observe that\n%   $$\\frac{d}{dt} \\int_{-1}^{1} u\\, dx = \\int_{-1}^{1} u_t \\,dx = \\int_{-1}^{1} \\bigl[u_x - \\chi(uv_x)\\bigr]_x \\,dx = 0,$$\n%   due to the periodicity in $x$. Thus the total ``mass'' $M(t)=\\int u\\,dx$ is conserved in the exact solution. Use the trapezoidal quadrature formula to make a plot of $M(t)$ for the numerical solution of step~5 and check the conservation property. Make sure you apply the formula correctly over the entire interval and account for the periodicity of $u$.\n% \\end{enumerate}\n\n\n\n\\end{document}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n\n\n", "meta": {"hexsha": "8d3fe806176f8eee9aa2bf1e83118058aa0dcddc", "size": 4722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter11/Chemotaxis/Chemotaxis.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/chapter11/Chemotaxis/Chemotaxis.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/chapter11/Chemotaxis/Chemotaxis.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": 50.2340425532, "max_line_length": 390, "alphanum_fraction": 0.6994917408, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6415123588777435}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Feedback linearisation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Input-output linearisation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{align}\n\t\\dot{x} &= f(x) + g(x)u \\label{eq:siso-x} \\\\\n\ty       &= h(x)         \\label{eq:siso-y}\n\\end{align}\n\n\\paragraph{Definition 13.2 (relative degree)}\nThe relative degree $\\rho$ of \\eqref{eq:siso-x}--\\eqref{eq:siso-y} is equal to the number of times $y$ must be differentiated until $u$ appears.\n\n\\paragraph{Theorem 13.1}\nThe system \\eqref{eq:siso-x} can be input-output linearised if the relative degree is well defined in the region of interest $\\mathbb{D}_0$.\n\n\\paragraph{Minimum phase}\nThe system \\eqref{eq:siso-x}--\\eqref{eq:siso-y} is \\emph{minimum phase} if, for the zero-dynamics $\\dot{\\eta} = f_0(\\eta,0)$, $\\eta = 0$ is AS.\n\n\\paragraph{Method}\nThe system is given by \\eqref{eq:siso-x}--\\eqref{eq:siso-y}. First determine relative degree $\\rho$. Define\n\\begin{equation}\n\t\\xi =\n\t\\begin{bmatrix}\n\t\t\\xi_1 \\\\ \\vdots \\\\ \\xi_\\rho\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t\ty \\\\ \\vdots \\\\ y^{(\\rho-1)}\n\t\\end{bmatrix}\n\\end{equation}\nso that\n\\begin{equation}\n\t\\dot{\\xi} =\n\t\\begin{bmatrix}\n\t\t\\dot{\\xi}_1 \\\\ \\vdots \\\\ \\dot{\\xi}_\\rho\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t\t\\xi_2 \\\\ \\vdots \\\\ L_f^\\rho h + L_g L_f^{\\rho-1} h \\cdot u\n\t\\end{bmatrix}\n\t.\n\\end{equation}\nThen choose $n-\\rho$ coordinates\n\\begin{equation}\n\t\\eta =\n\t\\begin{bmatrix}\n\t\t\\eta_1 \\\\ \\vdots \\\\ \\eta_{n-\\rho}\n\t\\end{bmatrix}\n\\end{equation}\nwith the coordinate transformation\n\\begin{equation}\n\tz = T(x) =\n\t\\begin{bmatrix}\n\t\t\\eta_1 \\\\ \\vdots \\\\ \\eta_{n-\\rho} \\\\ \\xi_1 \\\\ \\vdots \\\\ \\xi_\\rho\n\t\\end{bmatrix}\n\\end{equation}\nand choose $\\eta$ such that\n\\begin{itemize}\n\t\\item $T$ is a diffeomorphism,\n\t\\item $L_g \\eta_i = 0$,\n\t\\item $\\eta_i(0) = 0$.\n\\end{itemize}\nWe have then that\n\\begin{equation}\n\t\\dot{\\eta}_j = \\pd{\\eta_j}{x} \\dot{x} = L_f \\eta_j + \\underbrace{L_g \\eta_j}_{= 0} \\cdot u = f_{0_j} (\\eta_i, \\xi_i)\n\\end{equation}\nand we can write the system on normal form\n\\begin{equation}\n\t\\begin{bmatrix}\n\t\t\\dot{\\eta}_1        \\\\\n\t\t\\vdots              \\\\\n\t\t\\dot{\\eta}_{n-\\rho} \\\\\n\t\t\\dot{\\xi}_1         \\\\\n\t\t\\vdots              \\\\\n\t\t\\dot{\\xi}_\\rho\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t\tf_{0_1}(\\eta_i, \\xi_i)        \\\\\n\t\t\\vdots                        \\\\\n\t\tf_{0_{n-\\rho}}(\\eta_i, \\xi_i) \\\\\n\t\t\\xi_2                         \\\\\n\t\t\\vdots                        \\\\\n\t\tL_f^\\rho h + L_g L_f^{\\rho-1} h \\cdot u\n\t\\end{bmatrix}\n\t.\n\\end{equation}\nThen choose $u$ to cancel the nonlinearities:\n\\begin{equation}\n\tu = \\frac{1}{L_g L_f^{\\rho-1} h} (-L_f^\\rho h + v)\n\\end{equation}\nThis leads to\n\\begin{gather}\n\t\\dot{\\eta} = f_0(\\eta,\\xi) \\\\\n\t\\dot{\\xi} = \n\t\\begin{bmatrix}\n\t\t\\xi_2 \\\\ \\vdots \\\\ v\n\t\\end{bmatrix}\n\\end{gather}\nThen analyse the zero-dynamics---the internal dynamics when the output is kept zero by the input:\n\\begin{equation}\n\t\\dot{\\eta} = f_0(\\eta,0)\n\\end{equation}", "meta": {"hexsha": "9a8999cf611ae1faf3a1ee9eaae2f6322af1f82f", "size": 2891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-feedback-lin.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-feedback-lin.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-feedback-lin.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": 27.5333333333, "max_line_length": 144, "alphanum_fraction": 0.6015219647, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.641512355169013}}
{"text": "\n\\subsection{The Lorentz group}\n\nThe Lorentz group is the \\(O(1,3)\\) group.\n\\subsubsection{Symmetries of the Lorentz group}\n\nWe can do the usual \\(3\\) rotations, however there are additional \\(3\\) symmetries, making the Lorzentz group \\(6\\)-dimensional.\n\nThese are the Lorentz boosts.\n\nA symmetry has:\n\n\\(t'^2 - x'2 - y'^2 - z'^2 = t^2 - x^2 - y^2 - z^2\\)\n\nWe consider the case where we just boost on \\(x\\), so \\(y = y'\\) and \\(z = z'\\).\n\n\\(t'^2 - x'2 = t^2 - x^2\\)\n\nOr with \\(c\\):\n\n\\(c^2t'^2 - x'2 = ct^2 - x^2\\)\n\n\n\\subsubsection{New}\n\\(s^2 = t^2 - x^2 - y^z - z^2\\)\n\n\\(s'^2 = t'^2 - x'^2 - y'^2 - z'^2\\)\n\n\\(ds^2 = s'^2 - s^2\\)\n\n\\(ds^2 = (t'^2 - x'^2 - y'^2 - z'^2) - (t^2 - x^2 - y^z - z^2)\\)\n\n\\(ds^2 = (t'^2 - t^2) - (x'^2 - x^2) - (y'^2 - y^2) - (z'^2 - z^2)\\)\n\n\\(ds^2 = dt^2 - dx^2 - dy^2 - dz^2\\)\n\n\nboost:\n\\(s^2 = c^2t^2 - x^2 - y^z - z^2\\)\n\nwe want new t and x where distance is same\n\\(c^2t'^2 - x'^2 - y^z - z^2 = c^2t^2 - x^2 - y^z -z^2\\)\n\\(c^2t'^2 - x'^2 = c^2t^2 - x^2\\)\n\nWe know that both transformations are linear [WHY??], therefore\n\\(x' = Ax + Bt\\)\n\\(t' = Cx+Dt\\)\n\nwe transform to \\(x' = 0\\). so\n\\(Ax + Bt = 0\\)\n\nWe define\n\\(v = \\dfrac{x}{t}\\)\n\nSo:\n\\(x = vt\\)\n\nWe can plug these in:\n\\(Avt + Bt = 0\\)\n\\(Av + B = 0\\)\n\\(\\dfrac{A}{B} = -v\\)\n\n", "meta": {"hexsha": "fee0a2bd8b94b0874a2338d42191e667106e2406", "size": 1253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-07-lorentz.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/02-07-lorentz.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/02-07-lorentz.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.8888888889, "max_line_length": 128, "alphanum_fraction": 0.4996009577, "num_tokens": 586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6414869185262314}}
{"text": "\\lab{The Arnoldi Iteration}{The Arnoldi Iteration}\n\\objective{The Arnoldi Iteration is an efficient method for finding the eigenvalues of extremely large matrices.\nInstead of using standard methods, the iteration uses Krylov subspaces to approximate how a linear operator acts on vectors.\nWith this approach, the Arnoldi Iteration facilitates the computation of eigenvalues for enormous matrices without needing to physically create the matrix in memory.\nWe will explore this subject by implementing the Arnoldi iteration algorithm, using our implementation for eigenvalue computation, and then graphically representing the accuracy of our approximated eigenvalues.}\n\n\\section*{Krylov Subspaces} % =================================================\n\nOne of the biggest difficulties in numerical linear algebra is the amount of memory needed to store a large matrix and the amount of time needed to read its entries.\nMethods using Krylov subspaces avoid this difficulty by studying how a matrix acts on vectors, making it unnecessary in many cases to create the matrix itself.\n\nThe \\emph{Arnoldi Iteration} is an algorithm for finding an orthonormal basis of a Krylov subspace.\nOne of its strengths is that it can run on any linear operator without knowing the operator's underlying matrix representation.\nThe outputs of the Arnoldi algorithm can then be used to approximate the eigenvalues of the matrix of the linear operator.\n\nThe order-$n$ Krylov subspace of $A$ generated by $\\x$ is\n\\[\n\\mathcal{K}_n(A, \\x) =\\text{span} \\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}.\n\\]\nIf the vectors $\\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}$ are linearly independent, then they form a basis for $\\mathcal{K}_n(A,\\x)$.\nHowever, $A^n x$ frequently converges to a dominant eigenvector of $A$ as $n$ gets large, which fills the basis with many almost parallel vectors.\nThis yields a basis prone to ill-conditioned computations and numerical instability.\n\n\\section*{The Arnoldi Iteration Algorithm} % ==================================\n\nThe Arnoldi iteration focuses on efficiently creating an orthonormal basis for $\\mathcal{K}_n(A,\\x)$ by integrating the creation of $\\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}$ with the modified Gram-Schmidt algorithm.\nThis process yields an orthonormal basis for $\\mathcal{K}_n(A,\\x)$ that can be used for further computations.\n%A brief walkthrough of this method and a psuedo code representation of it are contained below.\n\n\\begin{comment}\nBefore discussing the specific uses of the Krylov subspace in linear systems and eigenvalue problems, let us address a very practical concern: how can we best compute a basis for the Krylov subspace?\nThe obvious answer is simply to calculate the vectors $x, ax, a^2x, \\ldots, a^{n-1} x$, which we can accomplish using only matrix-vector multiplication.\nStraightforward though this may be, there is a major problem: $a^n x$ tends to converge to a dominant eigenvector of $a$ as $n$ gets large, and consequently these vectors become nearly parallel.\nThus, the basis $\\{x, ax, a^2x, \\ldots, a^{n-1} x\\}$ is far from orthogonal, and matrix computations associated with this basis will likely be ill-conditioned and prone to numerical instability.\nTo redress this problem, we may think to apply the Gram-Schmidt orthogonalization process to the basis, obtaining an orthonormal basis for the krylov subspace that enjoys much better numerical properties.\nThis turns out to be a useful thought, and is the basis for the Arnoldi iteration.\n\nYou may recall from lab \\ref{lab:qrdecomp} that the modified Gram-Schmidt algorithm allows us to find an increasing number of orthogonal vectors but does not require that we run the algorithm to its completion to find a full basis.\nOur goal is to find an orthonormal set of vectors $q_1,\\ldots,q_n$ having the same span as $x, ax, a^2x, \\ldots, a^{n-1} x$.\nWe start things off by setting\n\\[\nq_1 = \\frac{x}{\\|x\\|_2}.\n\\]\nnow, assuming we have obtained $q_1,\\ldots,q_n$, we obtain $q_{n+1}$ by projecting $a q_n$ onto the previous vectors, subtracting out these projections, and then normalizing.\nTo make this more precise, let $h_{i,n} = \\langle q_i, a q_n\\rangle$ for $i = 1,\\ldots, n$. subtract out these projections by calculating\n\\[\np_{n+1} = a^n x - \\sum_{i=1}^n h_{i,n}q_i.\n\\]\ndefine $h_{n+1,n} = \\|p_{n+1}\\|_2$, and normalize $p_{n+1}$ by calculating\n\\[\nq_{n+1} = \\frac{p_{n+1}}{h_{n+1,n}},\n\\]\nour next basis vector.\nThis procedure is outlined (in slightly more python-friendly notation) in algorithm \\ref{alg:arnoldi_iteration}.\n\nPerhaps you noticed a slight discrepancy between the Arnoldi iteration as described above, and the usual Gram-Schmidt procedure.\nSpecifically, you might have expected to compute $q_{n+1}$ by projecting $a^n x$, rather than $a q_n$, onto the previous vectors.\nThankfully, it is straightforward to show that our algorithm produces a valid orthonormal basis for the Krylov subspace, despite this difference, and because of this detail, we do not need to compute and store the original Krylov basis $x, ax, \\ldots, a^{n-1}x$.\nAdditionally, each iteration only requires one matrix-vector calculation, and the individual entries in $a$ are never referenced or modified.\nThus, even if the matrix $a$ is very large in theory, as long as we have a reasonably efficient subroutine to calculate $ax$ for any vector $x$, the Arnoldi iteration is computationally tractable.\n\nThis algorithm produces an orthonormal basis $q_1,\\ldots,q_n$ for the order-$n$ Krylov subspace generated by $a$ and $x$, as well as a collection of numbers $h_{i,j}$.\nIf we define a matrix $h_n$ whose $i,j$'th entry is $h_{i,j}$ for $i \\leq j+1$ and is $0$ otherwise, we now have an upper Hessenberg matrix.\nRecall that an upper Hessenberg matrix has the property that all entries below the first subdiagonal are equal to zero.\nAny square matrix is unitarily similar to an upper Hessenberg matrix.\nDealing with a Hessenberg matrix is often more convenient than dealing with a general matrix, especially when it comes to finding eigenvalues or solving systems of equations, since efficient algorithms designed for these types of matrices exist.\nIt turns out that there is a Hessenberg factorization of $a$, given by\n\\[\na  = qhq^*,\n\\]\nWhere $q$ is a unitary matrix and $h$ is upper Hessenberg such that the first $n$ columns of $q$ are $q_1,\\ldots,q_n$, and the upper left $n \\times n$ submatrix of $h$ is equal to $h_n$.\nHence, the Arnoldi iteration provides a connection between the Krylov subspace and the Hessenberg factorization of a matrix.\nEach step in the Arnoldi iteration can be thought of as computing another step in the Hessenberg reduction of $a$.\nEach $h_n$ is really just the $n \\times n + 1$ upper-left block of $h$.\nSolving eigenvalue problems or systems of equations for a general square matrix can thus be reduced, via Arnoldi iteration, to solving these problems for a Hessenberg matrix, a much easier task.\n\nAt this point, we can view the Arnoldi iteration as a means to compute an orthonormal basis for a Krylov subspace, or alternatively, to compute a partial Hessenberg factorization of a matrix.\nBut in lab \\ref{lab:canonical_transformations}, we discussed how orthogonal transformations can be used to transform a matrix to upper Hessenberg form.\nWe were able to find the eigenvalues of such upper Hessenberg matrices in lab \\ref{lab:eigsolve}.\nSo what have we really gained by this new approach?\nThese previous approaches were based on matrix-matrix multiplication and required us to manipulate individual entries of the matrix.\nThe Arnoldi iteration avoids this and relies only on our ability to calculate matrix-vector multiplication.\nFurther, our present approach will allow us to compute only a partial Hessenberg factorization.\nThis is advantageous when, as is often the case, the behavior and properties of a matrix can be well-approximated by only a small portion of its Hessenberg form.\n\\end{comment}\n\nThe algorithm begins by initializing a matrix $H$ which will be an upper Hessenberg matrix and a matrix $Q$ which will be filled with the basis vectors of our Krylov subspace.\nIt also requires an initial vector $\\b \\neq 0$ which is normalized to get $\\q_1 = \\b/\\norm{\\b}$.\nThis represents the basis for the initial Krylov subspace, $\\mathcal{K}_1(A,\\b)$.\n\nFor the $k$th iteration, compute the next basis vector $\\q_{k+1}$ by using the modified Gram-Schmidt process to make $A\\q_k$ orthonormal to $\\q_k$.\nThis entails making each column of $Q$ orthogonal to $\\q_k$ before proceeding to the next iteration.\nThe vectors $\\{\\q_i\\}_{i=1}^k$ are then a basis for $\\mathcal{K}_k(A,\\b)$.\nIf $\\norm{\\q_{k+1}}$ is below a certain tolerance, stop and return $H$ and $Q$.\nOtherwise, normalize the new basis vector new $\\q_{k+1}$ and continue to the next iteration.\n% This process continues until we have an orthonormal basis of an order $k+1$ Krylov subspace.\n\n%This algorithm is described in algorithm \\ref{alg:arnoldi_iteration} for an order $k+1$ Krylov subspace, where $k$ is the number of times we multiply by $A$.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Arnoldi}{$\\b$, $A$, $k$, \\li{tol}}\n\t\\State $Q \\gets \\allocate{\\size{\\b}}{k+1}$\t\t\t\\Comment{Some initialization steps}\n\t\\State $H \\gets \\zeros{ k+1}{ k}$\n\t\\State $Q_{:,0} \\gets \\b/\\norm{\\b}_2$\n\t\\For{$j=0\\ldots k-1$}\t\t\t\t\t\t\t\\Comment{Perform the actual iteration.}\n\t\t\\State $Q_{:,j+1} \\gets A(Q_{:,j})$\n\t\t\\For{$i=0\\ldots j$}\t\t\t\t\t\\Comment{Modified Gram-Schmidt.}\n\t\t\t\\State $H_{i,j} \\gets Q_{:,i}\\hrm Q_{:,j+1}$\n\t\t\t\\State $Q_{:,j+1} \\gets Q_{:,j+1} - H_{i,j} Q_{:,i}$\n\t\t\\EndFor\n\t\t\\State $H_{j+1,j} \\gets \\norm{Q_{:,j+1}}_2$\t\t\t\\Comment{Set subdiagonal element of $H$.}\n            \\If{$|H_{j+1,j}|<$ \\li{tol}}\t\t\t\t\t\\Comment{Stop if $\\norm{Q_{:,j+1}}_2$ is small enough.}\n\t\t\t\\State \\pseudoli{return} $H_{:j+1,:j+1}$, $Q_{:,:j+1}$\n\t\t\\EndIf\n\t\t\\State $Q_{:,j+1} \\gets Q_{:,j+1}/H_{j+1,j}$\t\t\t\t\\Comment{Normalize $\\q_{j+1}$.}\n\t\\EndFor\n\t\\State \\pseudoli{return} $H_{:-1, :}$, $Q$\t\t\t\\Comment{Return $H_k$ and $Q$.}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Arnoldi iteration.\nThis algorithm accepts a square matrix $A$ and a starting vector $\\b$.\nIt iterates $k$ times or until the norm of the next vector in the iteration is less than \\li{tol}.\nThe algorithm returns an upper Hessenberg $H$ and an orthonormal $Q$ such that $H = Q^{\\mathsf{H}}AQ$.}\n\\label{alg:arnoldi_iteration}\n\\end{algorithm}\n\n\\begin{warn}\nIf the starting vector $\\x$ is an eigenvector of $A$ with corresponding eigenvalue $\\lambda$, then by definition $\\mathcal{K}_k(A, \\x)=\\text{span}\\{\\x, \\lambda \\x, \\lambda^2\\x, \\ldots, \\lambda^k \\x\\}$, which is equal to the span of $\\x$.\nSo, when $\\x$ is normalized with $\\q_1 = \\x/\\|\\x\\|$, $\\q_2 = A\\q_1 = \\lambda \\q_1$.\n\nThe vector $\\q_2$ is supposed to be the next vector in the orthonormal basis for $\\mathcal{K}_k(A, \\x)$, but it is not linearly independent of $\\q_1$.\nIn fact, $\\q_1$ already spans $\\mathcal{K}_k(A, \\x)$.\nHence, the Gram-Schmidt process fails and results in a \\li{ZeroDivisionError} or an extremely early termination of the algorithm.\nA similar phenomenon may occur if the starting vector $\\x$ is contained in a proper invariant subspace of $A$.\n\\end{warn}\n\n\\section*{Arnoldi Iteration on Linear Operators} % ============================\n\nA major strength of the Arnoldi iteration is that it can run on a linear operator, even without knowing the matrix representation of the operator.\nIf $L$ is some linear function, then we can modify the pseudocode above by replacing $AQ_{:,j}$ with $A_{mul}(Q_{:,j})$.\nThis makes it possible to find the eigenvalues of an arbitrary linear transformation.\n\n\\begin{problem}\\label{prob:arnoldi}\nWrite a function that accepts a starting vector $\\b$ for the Arnoldi Iteration, a function handle $L$ that describes a linear operator, the number of times $n$ to perform the iteration, and a tolerance \\li{tol} that defaults to $10^{-8}$.\nUse Algorithm \\ref{alg:arnoldi_iteration} to implement the Arnoldi Iteration with these parameters.\nReturn the upper Hessenberg matrix $H$ and the orthonormal matrix $Q$ from the iteration.\n\nConsider the following implementation details.\n\\begin{enumerate}\n\\item Since $H$ and $Q$ will eventually hold complex numbers, initialize them as complex arrays (e.g., \\li{A = np.empty((3,3), dtype=np.complex128)}).\n\\item This function can be tested on a matrix A by passing in \\li{A.dot} for a linear operator.\n\\item Remember to use complex inner products. Here is an example of how to evaluate $A^HA$:\n\\begin{lstlisting}\nb = A.conj() @ B\n\\end{lstlisting}\n\\end{enumerate}\nTest your function by comparing the resulting $H$ with $Q\\hrm A Q$.\n\\end{problem}\n\n\\section*{Finding Eigenvalues Using the Arnoldi Iteration} % ==================\n\nLet $A$ be an $n \\times n$ matrix.\nLet $Q_k$ be the matrix whose columns $\\q_1, \\ldots, \\q_k$ are the orthonormal basis for $\\mathcal{K}_m(A, \\x)$ generated by the Arnoldi algorithm, and let $H_k$ be the $k\\times k$ upper Hessenburg matrix defined at the $k$th stage of the algorithm.\nThen these matrices satisfy\n\\begin{equation}\\label{eq:arnoldi-hqa}\nH_k = Q_k^{\\mathsf H} A Q_k.\n\\end{equation}\nIf $k<n$, then $H_k$ is a low-rank approximation to $A$  and the eigenvalues of $H_k$ may be used as approximations for the eigenvalues of $A$.\nThe eigenvalues of $H_k$ are called \\emph{Ritz Values}, and we will later show that they converge quickly to the largest eigenvalues of $A$.\n\n\\begin{problem}\\label{prob:ritz}\nWrite a function that accepts a function handle $L$ that describes a linear operator, the dimension of the space \\li{dim} that the linear operator works on, the number of times $k$ to perform the Arnoldi Iteration, and the number of Ritz values $n$ to return.\nUse the previous implementation of the Arnoldi Iteration and an eigenvalue function such as \\li{scipy.linalg.eigs()} to compute the largest Ritz values of the given operator.\nReturn the \\li{n} largest Ritz values.\n\\end{problem}\n\nOne application of the Arnoldi iteration is to find the eigenvalues of linear operators that are too large to store in memory.\nFor example, if an operator acts on a vector $\\x \\in \\mathbb{C}^{2^{20}}$, then its matrix representation contains $2^{40}$ complex values.\nStoring such a matrix would require 64 terabytes of memory!\n\nAn example of such an operator is the Fast Fourier Transform, cited by SIAM as one of the top algorithms of the century \\cite{cipra2000}.\nThe Fast Fourier Transform is used very commonly in signal processing.\n\n\\begin{problem}\n\\label{prob:fourier_eigs}\nThe four largest eigenvalues of the Fast Fourier Transform are known to be $\\{ -\\sqrt{n}, \\sqrt{n}, -i\\sqrt{n}, i\\sqrt{n} \\}$ where $n$ is the dimension of the space on which the transform acts.\n\nUse your function from Problem \\ref{prob:ritz} to approximate the eigenvalues of the Fast Fourier Transform.\nSet $k = 10$ and \\li{dim} = $2^{20}$.\nFor the argument $L$, use the \\li{scipy.fftpack.fft()}.\n\\end{problem}\n\nThe Arnoldi iteration for finding eigenvalues is implemented in a Fortran library called ARPACK.\nScipy interfaces with the Arnoldi iteration in this library via the function \\li{scipy.sparse.linalg.eigs()}.\nThis function has many more options than the implementation we wrote in Problem \\ref{prob:ritz}.\nIn this example, the keyword argument \\li{k=5} specifies that we want five Ritz values.\nNote that even though this function comes from the \\li{sparse} library in Scipy, we can still call it on regular Numpy arrays.\n\n\\begin{lstlisting}\n>>> from scipy.sparse import linalg as spla\n>>> B = np.random.random((100,100))\n>>> spla.eigs(B, k=5, return_eigenvectors=false)\narray([ -1.15577072-2.59438308j,  -2.63675878-1.09571889j,\n        -2.63675878+1.09571889j,  -3.00915592+0.j        ,  50.14472893+0.j ])\n\\end{lstlisting}\n\n\\subsection*{Convergence} % ---------------------------------------------------\nAs more iterations of the Arnoldi method are performed, our approximations are of higher rank.\nConsequently, the Ritz values become more accurate approximations to the eigenvalues of the linear operator.\n\nThis technique converges quickly to eigenvalues whose magnitude is distinctly larger than the rest.\nFor example, matrices with random entries tend to have one eigenvalue of distinctly greatest magnitude.\nConvergence of the Ritz values for such a matrix is plotted in Figure \\ref{fig:arnoldi_random_val_conv}.\n\nHowever, Ritz values converge more slowly for matrices with random eigenvalues.\nFigure \\ref{fig:arnoldi_random_eig_conv} plots convergence of the Ritz values for a matrix with eigenvalues uniformly distributed in $[0,1)$.\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rand_vals_conv.pdf}\n    \\caption{}\n    \\label{fig:arnoldi_random_val_conv}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rand_eigs_conv.pdf}\n    \\caption{}\n    \\label{fig:arnoldi_random_eig_conv}\n\\end{subfigure}\n\\caption{These plots show the relative error of the ritz values as approximations to the eigenvalues of a matrix.\nThe figure on the left plots the largest 15 Ritz values for a $500\\times 500$ matrix with random entries and demonstrates that the largest eigenvalue (the blue line) converges after 20 iterations.\nThe figure at right plots the largest 15 Ritz values for a $500\\times 500$ matrix with uniformly distributed eigenvalues in $[0,1)$ and demonstrates that all the eigenvalues take from 150 to 250 iterations to converge.}\n\\end{figure}\n\n% todo: this problem may be too difficult but we have added a great deal of supplementary code to make it more doable.\n\\begin{problem}\nWrite a function that accepts a linear operator $A$, the number of Ritz values to plot $n$, and the the number of times to perform the Arnoldi iteration \\li{iters}.\nUse these parameters to create a plot of the absolute error between the largest Ritz values of $A$ and the largest eigenvalues of $A$.\n\\begin{enumerate}\n    \\item Find $n$ eigenvalues of $A$ of largest magnitude. Store these in order.\n    \\item Create an empty array to store the relative errors for every $k=0,1,\\ldots,$ \\li{iters}.\n    \\begin{enumerate}\n    \t\\item Use your Ritz function to find the $n$ largest Ritz values of the operator. Note that for small $k$, the matrix $H_k$ may not have this many eigenvalues. Due to this, the graphs of some eigenvalues have to begin after a few iterations.\n        \\item Store the absolute error between the eigenvalues of A and the Ritz values of H. Make sure that the errors are stored in the correct order.\n    \\end{enumerate}\n    %\\item Use array broadcasting to compute the absolute error.\n    \\item Iteratively plot the errors for each eigenvalue with the range of the iterations.\n\\end{enumerate}\nHints:\nIf $\\tilde{\\x}$ is an an approximation to $\\x$, then the \\emph{absolute error} in the approximation is $\\|\\x - \\tilde{\\x}\\|$.\n\nSort your eigenvalues from greatest to least.\nAn example of how to do this is included:\n\\begin{lstlisting}\n# Evaluate the eigenvalues\neigvalues = la.eig(A)[0]\n# Sort them from greatest to least (use np.abs to account for complex parts)\neigvalues = eigvalues[np.sort(np.<<abs>>(eigvalues))[::-1]]\n\\end{lstlisting}\nIn addition, remember that certain eigenvalues of $H$ will not appear until we are computing enough iterations in the Arnoldi algorithm.\nAs a result, we will have to begin the graphs of several eigenvalues after we are computing sufficient iterations of the algorithm.\n%To be able to keep our graph readable, use masking such as the following to remove any extreme errors that arise in the first iterations.\n%\\begin{lstlisting}\n%errors[errors > 10] = 10.\n%\\end{lstlisting}\n\nRun your function on these examples.\nThe plots should be fairly similar to Figures \\ref{fig:arnoldi_random_eig_conv} and \\ref{fig:arnoldi_random_val_conv}.\n\n\\begin{lstlisting}\n>>> A = np.random.rand(300, 300)\n>>> plot_ritz(a, 10, 175)\n\n>>> # A matrix with uniformly distributed eigenvalues\n>>> d = np.diag(np.random.rand(300))\n>>> B = A @ d @ la.inv(A)\n>>> plot_ritz(B, 10, 175)\n\\end{lstlisting}\n% These may take some time to run.\n\\end{problem}\n\n% once the eigenvalue lab has been rewritten, have them use their own solver to find the eigenvalues of the $h_k$.\n\n% this problem is very ill-conditioned.\n\\begin{comment}\n\\begin{problem}\nfinding the roots of a polynomial can be represented as an eigenvalue problem.\nfinding the roots of a monic polynomial (a polynomial with leading coefficient 1) $p = c_0 + c_1 x + \\dots + c_{n-1} x^{n-1} + x^n$ is equivalent to finding the eigenvalues of the matrix\n\\[c = \\begin{bmatrix}\n0 & 0 & \\dots & 0 & -c_0 \\\\\n1 & 0 & \\dots & 0 & -c_1 \\\\\n0 & 1 & \\dots & 0 & -c_2 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n0 & 0 & \\dots & 1 & -c_{n-1} \\end{bmatrix}\\]\nthis matrix is called the companion matrix of the polynomial $p$.\nas it happens, every matrix is similar to the companion matrix of its characteristic polynomial, but we won't use that fact here.\n\nThe following is a function that, given an array containing the coefficients $c_0, c_1, \\dots, c_{n-1}$ for a monic polynomial $p$, performs matrix multiplication by the corresponding companion matrix.\n\n\\begin{lstlisting}\ndef companion_multiply(c, u):\n    v = np.empty_like(u)\n    v[0] = - c[0] * u[-1]\n    v[1:] = u[:-1] - c[1:] * u[-1]\n    return v\n\\end{lstlisting}\n\nUse the Arnoldi iteration to estimate the five zeros of largest norm of a degree $1000$ monic polynomial with randomly chosen coefficients (the leading coefficient still needs to be 1).\nRun $50$ steps of the Arnoldi iteration.\nCompare your results with the roots of the polynomial computed using NumPy's \\li{poly1d} class.\nThis computation can be done like this (where \\li{c} is the array of random coefficients for the polynomial)\n\n\\begin{lstlisting}\np = np.poly1d([1] + list(c[::-1]))\nroots = p.roots\n# Now sort by absolute value from largest to smallest\nroots = roots[np.<<abs>>(roots).argsort()][::-1]\n\\end{lstlisting}\n\nHow close are the first few zeros of largest norm?\n\\end{problem}\n\\end{comment}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{The Lanczos Iteration} % -----------------------------------------\n\nThe Lanczos iteration is a version of the Arnoldi iteration that is optimized to operate on symmetric matrices.\nIf A is symmetric, then \\eqref{eq:arnoldi-hqa} shows that $H_k$ is symmetric and hence tridiagonal.\nThis leads to two simplifications of the Arnoldi algorithm.\n\nFirst, we have $0=H_{k, n}=\\langle \\q_k, A\\q_n \\rangle$ for $k \\leq n-2$; i.e., $A\\q_n$ is orthogonal to $\\q_1, \\ldots, \\q_{n-2}$.\nThus, if the goal is only to compute $H_k$ (say to find the Ritz values), then we only need to store the two most recently computed columns of $Q$.\nSecond, the data of $H_k$ can also be stored in two vectors, one containing the main diagonal and one containing the first subdiagonal of $H_k$\n(by symmetry, the first superdiagonal equals the first subdiagonal of $H_k$).\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Lanczos}{$\\b, A, k, tol$}\n\t\\State $\\q_0 \\gets \\zeros{\\size{\\b}}$\t\t\t\t\t\t\t\t\\Comment{Some initialization}\n\t\\State $\\q_1 \\gets \\b/\\norm{\\b}_2$\n\t\\State $\\x \\gets \\allocate{k}$\n\t\\State $\\y \\gets \\allocate{k}$\n\t\\For{$i=0\\ldots k-1$}\t\t\t\t\t\t\t\t\t\\Comment{Perform the iteration.}\n\t\t\\State $\\z \\gets A\\q_1$\t\t\t\t\t\\Comment{$\\z$ is a temporary vector to store $\\q_{i+1}$.}\n\t\t\\State $\\x[i] \\gets \\q_1\\trp \\z$\t\t\t\t\\Comment{$\\q_1$ is used to store the previous $\\q_i$.}\n\t\t\\State $\\z \\gets \\z - \\x[i] \\q_1 + \\y[i-1] \\q_0$\t\t\t\t\\Comment{$\\q_0$ is used to store $\\q_{i-1}$.}\n\t\t\\State $\\y[i] = \\norm{\\z}_2$\t\t\t\t\t\t\\Comment{Initialize $\\y[i]$.}\n\t\t\\If{$\\y[i]<tol$}\t\t\t\t\t\t\t\t\\Comment{Stop if $\\norm{ \\q_{i+1}}_2$ is too small.}\n\t\t\t\\State \\pseudoli{return} $\\x[: i+1]$, $\\y[: i]$\n\t\t\\EndIf\n\t\t\\State $\\z = \\z/ \\y[i]$\n\t\t\\State $\\q_0, \\q_1 = \\q_1, \\z$\t\t\t\t\t\t\\Comment{Store new $\\q_{i+1}$ and $\\q_i$ on top of $\\q_1$ and $\\q_0$.}\n\t\\EndFor\n\t\\State \\pseudoli{return} $\\x$, $\\y[: -1]$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Lanczos Iteration. This algorithm operates on a vector $\\b$ of length $n$ and an $n \\times n$ symmetric matrix $A$. It iterates $k$ times or until the norm of the next vector in the iteration is less than $tol$. It returns two vectors $\\x$ and $\\y$ that respectively contain the main diagonal and first subdiagonal of the current Hessenberg approximation.}\n\\label{alg:lanczos_iteration}\n\\end{algorithm}\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:lanczos}\nImplement Algorithm \\ref{alg:lanczos_iteration} by completing the following function.\nWrite it so that it can operate on complex arrays.\n\\begin{lstlisting}\ndef lanczos(b, L, k, tol=1E-8):\n    '''Perform `k' steps of the Lanczos iteration on the symmetric linear\n    operator defined by `L', starting with the vector 'b'.\n\n    INPUTS:\n    b    - A NumPy array. The starting vector for the Lanczos iteration.\n    L - A function handle. Should describe a symmetric linear operator.\n    k    - Number of times to perform the Lanczos iteration.\n    tol  - Stop iterating if the next vector in the Lanczos iteration has\n          norm less than `tol'. Defaults to 1E-8.\n\n    RETURN:\n    Return (alpha, beta) where alpha and beta are the main diagonal and\n    first subdiagonal of the tridiagonal matrix computed by the Lanczos\n    iteration.\n    '''\n\\end{lstlisting}\n\\end{problem}\n\\end{comment}\n\nAs it is described in Algorithm \\ref{alg:lanczos_iteration}, the Lanczos iteration is not stable.\nRoundoff error may cause the $\\q_i$ to be far from orthogonal.\nIn fact, it is possible for the $\\q_i$ to be so adulterated by roundoff error that they are no longer linearly independent.\n% If needed we could make a separate lab on the Lanczos iteration and the Implicitly Restarted Lanczos Method.\n% There isn't time or space here for it though.\n\n\\begin{comment}\n\\begin{problem}\nThe following code performs multiplication by a tridiagonal symmetric matrix.\n\n\\begin{lstlisting}\ndef tri_mul(a, b, u):\n   ''' Return Au where A is the tridiagonal symmetric matrix with main\n   diagonal a and subdiagonal b.\n   '''\n    v = a * u\n    v[:-1] += b * u[1:]\n    v[1:] += b * u[:-1]\n    return v\n\\end{lstlisting}\n\nLet $A$ be a $1000\\times 1000$ symmetric tridiagonal matrix with random values in its nonzero diagonals.\nUse the function \\li{lanczos()} from Problem \\ref{prob:lanczos} with 100 iterations to estimate the 5 eigenvalues of $A$ of largest norm.\nCompare these to the 5 largest true eigenvalues of $A$\n\nIf you do this problem for different vectors $a$ and $b$, you may notice that occasionally the largest Ritz value is repeated.\nThis happens because the vectors used in the Lanczos iteration may not be orthogonal.\nThese erroneous eigenvalues are called ``ghost eigenvalues.''\n%They generally converge to actual eigenvalues of the matrix and can make the multiplicity of an eigenvalue look higher than it really is.\n\\end{problem}\n\\end{comment}\n\nThere are modified versions of the Lanczos iteration that are numerically stable.\nOne of these, the Implicitly Restarted Lanczos Method, is found in SciPy as \\li{scipy.sparse.linalg.eigsh()}.\n", "meta": {"hexsha": "5e48644bc57f63fe79694b23ef32df770591a513", "size": 27085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume1/Arnoldi/Arnoldi.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/Arnoldi/Arnoldi.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/Arnoldi/Arnoldi.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": 63.4309133489, "max_line_length": 369, "alphanum_fraction": 0.7336902344, "num_tokens": 7468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.6414286411264932}}
{"text": "\\section{Factorization in Integral Domains}\r\nIn this section, $R$ will always denote an integral domain.\r\n\\subsection{Prime and Irreducible Elements}\r\n\\begin{definition}\r\n    $a\\in R$ is said to divide $b\\in R$, written as $a|b$, if $\\exists c\\in R,b=ac$.\r\n    Or equivalently, $(b)\\subset (a)$.\\\\\r\n    $a,b\\in R$ are associates if $a=bc$ for some unit $c\\in R$.\r\n    Equivalently, $(a)=(b)$.\\\\\r\n    $r\\in R$ is irreducible if it is nonzero and not a unit, also $ab=r$ implies at least one of $a,b$ is a unit.\r\n    It is prime if it is nonzero and not a unit, and $r|ab\\implies r|a\\lor r|b$.\r\n\\end{definition}\r\nNote that these properties depend on the underlying ring $R$.\r\nFor example, $2$ is irreducible and prime in $\\mathbb Z$ but not in $\\mathbb Q$.\r\nAlso $2X$ is irreducible in $\\mathbb Q[X]$ but not in $\\mathbb Z[X]$.\r\n\\begin{lemma}\r\n    For a $r\\in R$, $(r)$ is prime iff $r=0$ or $r$ is prime.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $(r)$ is prime and $r\\neq 0$, then since $(r)$ is proper $r$ is not a unit, and if $r|ab$, then $ab\\in (r)$, so $a\\in (r)$ or $b\\in (r)$, so $r|a$ or $r|b$, so $r$ is prime.\\\\\r\n    Conversely, $(0)$ is prime and for $r$ a prime, $ab\\in (r)\\implies r|ab\\implies r|a\\lor r|b\\implies a\\in (r)\\lor b\\in (r)$, so $(r)$ is a prime ideal.\r\n\\end{proof}\r\nOne find that an integer is maximal iff it is prime.\r\nWe want to generalize this to some other integral domains.\r\n\\begin{lemma}\r\n    A prime element is irreducible.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $r\\in R$ is prime, then it is nonzero and not a unit.\r\n    If $r=ab$, then $r|a$ or $r|b$.\r\n    WLOG $r|a$, then $a=rc$ for some $c\\in R$, then $r=rcb\\implies r(cb-1)=0$, but $r\\neq 0$, so $cb=1$, hence $b$ is unit.\r\n    Therefore $r$ is irreducible.\r\n\\end{proof}\r\nThe converse, sadly, does not hold in general.\r\n\\begin{example}[Non-example]\r\n    Let $R=\\mathbb Z[\\sqrt{-5}]$, which is the subring of the field $\\mathbb C$, hence is an integral domain.\r\n    Define the norm $N:R\\to\\mathbb Z_{\\ge 0}$ by $a+b\\sqrt{-5}\\mapsto a^2+5b^2$, which one can verify is multiplicative and $N(r)=1\\implies r=\\pm 1$.\r\n    Now the only units in $R$ are $\\pm 1$.\r\n    Indeed if $rs=1$, then $1=N(rs)=N(r)N(s)$, so $N(r)=N(s)=1$, so $r,s\\in\\{\\pm 1\\}$.\\\\\r\n    We claim that $2$ is irreducible in $R$.\r\n    Suppose $2=rs$, then $N(r)N(s)=N(rs)=4$, but one can show that there is no element with norm $2$, so one of $N(r),N(s)$ must be $1$, which means that it is a unit.\r\n    Similarly, $3,1+\\sqrt{-5},1-\\sqrt{-5}$ are all irreducible using exactly the same way.\r\n    However, $(1+\\sqrt{-5})(1-\\sqrt{-5})=6=2\\cdot 3$, but neither $1+\\sqrt{-5}$ nor $1-\\sqrt{-5}$ is divisible by $2$ (by either taking norms or finding out directly), therefore $2$ is not prime.\r\n\\end{example}\r\nAlso, in this particular ring $R$, unique Factorization fails as we can factorize $6$ into two different products of irreducibles which cannot be saved by multiplying a unit.\r\n\\subsection{Principal Ideal Domains}\r\n\\begin{definition}\r\n    An integral domain $R$ is a principal ideal domain (PID) if every ideal of $R$ is principal.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\mathbb Z$ is a PID.\r\n\\end{example}\r\nWe will later show that $\\mathbb Z[i]$ and $\\mathbb F[X]$ for a field $\\mathbb F$ are also PIDs.\r\n\\begin{lemma}\r\n    Let $0\\neq r\\in R$, if $(r)$ is maximal, then $r$ is irreducible.\r\n    If $R$ is a PID, then the converse holds.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We have $(r)\\neq 0,R$ by assumption, so $r$ is neither $0$ or a unit.\r\n    If $r=ab$ for some $a,b\\in R$, then $(r)\\subset (a)\\subset R$.\r\n    Hence $(a)=R$ so $a$ is a unit, or $(r)=(a)$, therefore $r=au$ for a unit $u$.\r\n    So $au=ab\\implies b=u$ is a unit.\r\n    Hence $r$ is irreducible.\r\n    Conversely, given that $R$ is a PID, suppose $r$ is irreducible, then if $(r)\\subset J\\subset R$ for some ideal $J=(a)$ for some $a\\in R$.\r\n    Then $r=ab$ for some $b\\in R$, but $r$ is irreducible, so either $b$ is a unit whence $(r)=(a)=J$, or $a$ is a unit whence $J=R$, therefore $(r)$ is maximal.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $R$ be a PID, every irreducible element is prime.\r\n\\end{proposition}\r\n\\begin{proof}[First proof]\r\n    Start with an irreducible $p\\in R$.\r\n    So $p$ is nonzero and not a unit.\r\n    Suppose $p|ab$ and $p\\nmid a$.\r\n    Consider the ideal $(a,p)=(d)$ for some $d\\in R$ since $R$ is a PID.\r\n    Then $p=cd$ for some $c\\in R$, so either $c$ or $d$ is a unit.\\\\\r\n    If $c$ is a unit, then $(p)=(d)=(a,p)$, therefore $p|a$ contradiction.\r\n    If $d$ is a unit, then $(a,p)=(d)=R$, so there is some $r,s$ such that $ar+ps=1$, hence $rab+sbp=b$, so $p|b$.\r\n\\end{proof}\r\n\\begin{proof}[Second proof]\r\n    Given $p\\in R$ irreducible, then $(p)$ is maximal, so $R/(p)$ is a field, which is an integral domain, hence $(p)$ is a prime ideal, which means that $p$ is prime.\r\n\\end{proof}\r\n\\begin{definition}\r\n    An integral domain $R$ is called an Euclidean domain (ED) if there is a function $\\phi:R\\setminus\\{0\\}\\to\\mathbb Z_{\\ge 0}$ (the Euclidean function) such that for any $a,b\\in R$:\\\\\r\n    1. If $a,b\\neq 0$ and $a|b$, then $\\phi(b)\\ge \\phi(a)$.\\\\\r\n    2. If $b\\neq 0$, then $\\exists q,r>0,a=qb+r$ such that either $r=0$ or $\\phi(r)<\\phi(b)$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    If $R$ is an Euclidean domain, then it is a PID.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $\\phi$ be the Euclidean function and $0\\neq I\\lhd R$ an ideal.\r\n    Choose $b\\in I$ such that it is nonzero and $\\phi(b)$ is minimal.\r\n    We shall show that $I=(b)$.\r\n    Note that we immediately have $(b)\\subset I$.\r\n    For the other way, choose $0\\neq a\\in I$, we write $a=qb+r$ with $q,r\\in R$ and either $r=0$ or $\\phi(r)<\\phi(b)$.\r\n    If $r=0$ then $a\\in (b)$.\r\n    Otherwise, note that $r=a-qb\\in I$, but $\\phi(r)<\\phi(b)$, contradicting the minimality of $b$.\r\n    So we must have $a\\in (b)$, hence $I=(b)$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Note that we did not use the first criterion to define the Euclidean function in the above proof.\r\n    The reason for us to include that in the definition of a ED is that it allows us to describe the units in $R$ in the way that $\\phi(a)=\\phi(1)$ iff $a$ is unit.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. $\\mathbb Z$ is a ED since we can take $\\phi(n)=|n|$.\\\\\r\n    2. For a field $\\mathbb F$, $\\mathbb F[X]$ is a ED by taking $\\phi(P)=\\deg P$ since we can do division with remainder in the polynomial ring of a field.\\\\\r\n    3. Consider the Gaussian integer $R=\\mathbb Z[i]\\le C$ by taking $\\phi(a+ib)=a^2+b^2$, so $\\phi$ is multiplicative therefore we get the first criterion.\r\n    For the second, let $z_1,z_2\\in R$.\r\n    Consider $z_1/z_2\\in\\mathbb C$, which has distance strictly less than $1$ from the nearest Gaussian integer, so $z_1/z_2=q+\\epsilon$ where $q\\in R$ and $|\\epsilon|<1$, so $z_1=qz_2+r$ where $r=\\epsilon z_2=z_1-qz_2\\in R$ and $\\phi(r)=|\\epsilon z_2|^2=|\\epsilon|^2\\phi(z_2)<\\phi(z_2)$.\r\n\\end{example}\r\nThe above examples are all also PIDs by the preceding proposition.\r\n\\begin{example}\r\n    1. Let $A$ be an $n\\times n$ matrix in the field $\\mathbb F$, and let $I$ be the set of all $f\\in \\mathbb F[X]$ such that $f(A)=0$.\r\n    Now $I$ is trivially an ideal.\r\n    But this ideal is principal since $\\mathbb F[X]$ is a ED hence PID.\r\n    Suppose $I=(f)$, then for any $g\\in\\mathbb F[X]$ such that $g(A)=0$, we have $f|g$.\r\n    So $f$ is the minimal polynomial of $A$.\\\\\r\n    2. Consider $\\mathbb F_2=\\mathbb Z/2\\mathbb Z$ and let $f(X)=X^3+X+1\\in\\mathbb F_2[X]$.\r\n    We want to show that $f$ is irreducible.\r\n    Suppose $f(X)=g(X)h(X)$ with $\\deg g,\\deg h>0$.\r\n    So one of $\\deg g$ and $\\deg f$ must be $1$ since $f$ has degree $3$, so $f$ has a root, but it does not, contradiction.\\\\\r\n    But $\\mathbb F_2[X]$ is a ED hence PID, therefore $(f)$ is maximal, so we get to construct a field $\\mathbb F_2[X]/(X^3+X+1)$.\r\n    The quotient looks like $\\{aX^2+bX+c+(X^3+X+1):a,b,c\\in\\mathbb F_2\\}$, but $a,b,c$ uniquely determines the ideal, so this is a field of order $8$.\\\\\r\n    3. (non-example) The ring $\\mathbb Z[X]$ is not a PID.\r\n    Indeed, consider the ideal $I=(2,X)$, then $I=\\{2f_1(X)+Xf_2(X):f_1,f_2\\in\\mathbb Z[X]\\}=\\{f(X)\\in\\mathbb Z[X]:f(0)\\text{ is even}\\}$.\r\n    Suppose $I$ is generated by some polynomial $f\\in\\mathbb Z[X]$, so $2=fg$ for some $g\\in\\mathbb Z[X]$.\r\n    But degrees add when polynomials multiply, hence $f,g$ has to be constant.\r\n    Therefore $I$ can only be $\\mathbb Z[X]$ or $2\\mathbb Z[X]$, but both are impossible since $1\\notin I$ (so $I$ is not the entire ring) and $X\\in I$ (but $X\\notin 2\\mathbb Z[X]$).\r\n\\end{example}\r\n\\subsection{Unique Factorization Domains}\r\n\\begin{definition}\r\n    An integral domain $R$ is called a unique factorization domain (UFD) if\\\\\r\n    1. Every nonzero and nonunit $r\\in R$ is a product of irreducibles.\\\\\r\n    2. If $p_1\\cdots p_m=q_1\\cdots q_n$ where $p_i,q_i$ are irreducibles, then $m=n$ and $\\exists\\sigma\\in S_n$ such that $p_i$ is an associate with $q_{\\sigma(i)}$.\r\n\\end{definition}\r\n\\begin{proposition}\\label{irred_prime_uniq}\r\n    Let $R$ be an integral domain having the first property stated above, then $R$ is a UFD iff every irreducible is prime.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $R$ is a UFD and $r\\in R$ is irreducible and $p|ab$, then $pc=ab$ for some $c\\in R$.\r\n    By the first condition, we can write $a,b,c$ as products of irreducibles, so an associate of $p$ must appear in the factorization of $a$ or $b$ by the second condition, so $p|a$ or $p|b$, hence $p$ is prime.\\\\\r\n    Suppose every irreducible is prime.\r\n    If $p_1\\cdots p_m=q_1\\cdots q_n$.\r\n    Now since $p_1$ is prime, then $p_1|q_i$ for some $i$.\r\n    But $q_i,p_1$ are both irreducible, so they are associates.\r\n    By reordering, we can write $i=1$, and by cancellation law, $p_2\\cdots p_m=q_2\\cdots q_n$.\r\n    The proof is finished by descent (or equivalently, induction).\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $R$ be a PID and there is a nested sequence of ideals $I_1\\subset I_2\\subset\\cdots$, then there exists some $N\\in\\mathbb N$ such that $I_n=I_N$ for every $n\\ge N$.\r\n\\end{lemma}\r\n\\begin{remark}\r\n    This condition is one of the formulations of the definition of a Noetherian ring.\r\n\\end{remark}\r\n\\begin{proof}\r\n    Consider the union $I=I_1\\cup I_2\\cup\\cdots$.\r\n    $I$ is obviously an ideal, so $I=(a)$ for some $a\\in R$.\r\n    But $a\\in I_N$ for some $N\\in\\mathbb N$, so for any $n\\ge N$, we have $(a)\\subset I_n\\subset I=(a)$, hence $I_n=(a)=I_N$.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Every PID is a UFD.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $R$ be a PID.\r\n    By Proposition \\ref{irred_prime_uniq}, since every irreducible in a PID is prime, it suffices to show the first condition of a UFD.\r\n    Let $x\\in R$ be nonzero and nonunit.\r\n    Suppose $x$ cannot be written as a product of irreducibles, so in particular $x$ is not irreducible.\r\n    Therefore we can write $x=x_1y_1$ for nonunit $x_1,y_1$.\r\n    But not both of $x_1,y_1$ can be written as a product of irreducibles.\r\n    WLOG $x_1$ is not a product of irreducibles, also we have $(x)\\subsetneq (x_1)$ since $y_1$ is not a unit.\r\n    Continue the process over and again gives a sequence of strictly nested ideals $(x)\\subsetneq (x_1)\\subsetneq\\cdots$, but this is a sequence of nested ideals that does not terminate, hence contradiction to the preceding lemma.\r\n\\end{proof}\r\n\\begin{example}\r\n    We know that ED implies PID implies UFD implies integral, so we have the following table of examples:\r\n    \\begin{center}\r\n        \\begin{tabular}{c|c|c|c|c|l}\r\n            &ED&PID&UFD&Integral&\\\\\r\n            $\\mathbb Z/4\\mathbb Z$&&&&No&\\\\\r\n            $\\mathbb Z[\\sqrt{5}]$&&&No&Yes&See later.\\\\\r\n            $\\mathbb Z[X]$&&No&Yes&&See later.\\\\\r\n            $\\mathbb Z\\left[\\frac{1+\\sqrt{-19}}{2}\\right]$&No&Yes&&&See in Number Fields.\\\\\r\n            $\\mathbb Z[i]$&Yes&&&&\r\n        \\end{tabular}\r\n    \\end{center}\r\n\\end{example}\r\n\\subsection{Greatest Common Factors and Least Common Multiples}\r\n\\begin{definition}\r\n    Let $R$ be a integral domain.\r\n    We say $d$ is a greatest common divisor of $a_1,\\ldots,a_n\\in R$ if $d|a_i$ for each $i$ and if $\\forall i,d'|a_i$, then $d'|d$.\r\n    We say $m$ is a least common multiple of $a_1,\\ldots,a_n\\in R$ if $a_i|d$ for each $i$ and if $\\forall i,a_i|d'$, then $d|d'$.\r\n\\end{definition}\r\nBoth GCDs and LCMs, when they exists, they are unique up to associates.\r\n\\begin{proposition}\r\n    In a UFD, both LCMs and GCDs exist.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}", "meta": {"hexsha": "0c62b8c89a422423eda6fd2cccfb37cfded23db3", "size": 12484, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/ufd.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": "10/ufd.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": "10/ufd.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": 63.3705583756, "max_line_length": 289, "alphanum_fraction": 0.6413008651, "num_tokens": 4287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.9005297941266013, "lm_q1q2_score": 0.6413863022430384}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Problem 2}\n\nConsider an infinite slab of material described by diffusion coefficient $D$ and macroscopic cross section $\\Sigma_a$. \nThe material extends infinitely in two dimensions, but has vacuum boundaries at $x=\\pm a$.\nInside the slab is a uniformly distributed source with strength $s'''$ [neutrons per volume]. \nFind the flux in this geometry. \n(You may use the substitution $L = \\sqrt{\\frac{D}{\\Sigma_a}}$.)\n\n", "meta": {"hexsha": "a35041dd7dfc3e578e7c620353e230080001f4ba", "size": 506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc10/disc10_exercise02.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/disc10/disc10_exercise02.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/disc10/disc10_exercise02.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": 50.6, "max_line_length": 119, "alphanum_fraction": 0.6501976285, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6413700930993228}}
{"text": "Disagreements between the obtained and the \\emph{aRTist} simulated projections can be found by subtracting one projection from the other. Any values too big in magnitude can be considered as a defect. However, in the previous chapters, it was found that x-ray photons behave randomly and differences in the comparison can be due to chance. Thus, the comparisons should be done in the face of uncertainty.\n\nA pixel by pixel hypothesis test was proposed to do defect detection. To illustrate this method of inference, the projections from the dataset \\texttt{AbsFilter} at \\ang{120} was used. To recap, 20 replicate projections of a test sample, with purposefully manufactured voids, were obtained. \\emph{aRTist} was used to create a simulation of that projection but as if the voids were not there. Thus, the method should pick these voids up.\n\nBeforehand, linear shading correction was applied to the projections. The \\emph{aRTist} projections were shading corrected using the simulated greyscale projections. The 20 replicate projections were split into two. 19 randomly selected projections were used for the variance-mean model to fit onto. The remaining projection was compared with the \\emph{aRTist} projection. This remaining projection and the \\emph{aRTist} projections are shown in Figures \\ref{fig:inference_inferenceIntro_inference_scan} and \\ref{fig:inference_inferenceIntro_inference_artist} respectively.\n\nA gamma GLM, with a basic linear relationship, was used for the variance-mean model, as described in Chapter \\ref{chapter4}. The variance was predicted using the grey value in the \\emph{aRTist} simulation as the predictor variable.\n\nThe test statistic, for the pixel located at $(x,y)$, is\n\\begin{equation}\n  Z_{x,y} =\n  \\dfrac{\n    \\text{projection}_{x,y} - \\emph{aRTist}_{x,y}\n  }\n  {\n    \\sqrt{\\widehat{y}\\left[\\emph{aRTist}_{x,y}\\right]}\n  }\n\\end{equation}\nwhere $\\widehat{y}\\left[\\emph{aRTist}_{x,y}\\right]$ is the predicted grey value variance. The test statistic was calculated for each pixel in the ROI, that is, pixels which represent the test sample. The ROI was created by manually segmenting the test sample from the projection.\n\nIt is important to identify which quantities are random and which are not. For high photon rates, it was shown in the previous chapters that the grey values in the projection can be modelled using a Normal distribution. Thus, $\\text{projection}_{x,y}$ is a random quantity. The simulation $\\emph{aRTist}_{x,y}$ is not random because this was obtained through computer software. Given the 19 selected projections used for training the variance-mean model, the variance prediction $\\widehat{y}\\left[\\emph{aRTist}_{x,y}\\right]$ is not random because the variance-mean model was fitted before encountering the remaining projection to be compared with \\emph{aRTist}. The variance-mean model can be made random if a different set of 19 projections was used to train the model each time this inference was conducted, but this shall not be considered here.\n\nIf there are no significant differences between the obtained and \\emph{aRTist} projections, then the randomness of the test statistics can be approximately quantified as\n\\begin{equation}\nZ_{x,y}\\sim \\normal(0,1) \\ .\n\\end{equation}\nAs with usual statistical convention, an upper case $Z$ denotes a random variable. A lower case $z$ denotes a realisation or an observation of that random variable.\n\nFor each pixel, a test statistic was calculated, which forms a $z$ image. A test statistic too large in magnitude, relative to the anticipated variance, will classify that pixel as a positive result. In two-tailed hypothesis testing \\citep{pearson1900on, neyman1933on, fisher1970statistical}, $p$-values can be used to represent the test statistics in a different way\n\\begin{equation}\n  p_{x,y} = 2(1-\\Phi(|z_{x,y}|))\n\\end{equation}\nwhich can takes values $0\\leqslant p_{x,y} \\leqslant 1$. A $p$-value too small is considered a positive result. The $p$-values are shown in Figure \\ref{fig:inference_inferenceIntro_inference_pvalue}.\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_scan.eps}\n      \\caption{Obtained projection (\\SI{}{\\adu})}\n      \\label{fig:inference_inferenceIntro_inference_scan}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_artist.eps}\n      \\caption{\\emph{aRTist} projection (\\SI{}{\\adu})}\n      \\label{fig:inference_inferenceIntro_inference_artist}\n    \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_logp.eps}\n      \\caption{$-\\log p\\text{-values}$}\n      \\label{fig:inference_inferenceIntro_inference_pvalue}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_positivePixels.eps}\n      \\caption{Positive pixels overlaid on a)}\n      \\label{fig:inference_inferenceIntro_inference_positivePixels}\n    \\end{subfigure}\n  }\n  \\caption{The obtained projection of the test sample (a), from the \\texttt{AbsFilter} at \\ang{120} dataset, was compared to the \\emph{aRTist} projection (b) to detect purposefully manufactured voids. The $p$-values (c) obtained were used for hypotheses testing. Pixels detected as positive are shown in red in d) using the \\cite{benjamini1995controlling} procedure at the 5\\% false discovery rate level.}\n  \\label{fig:inference_inferenceIntro_inference}\n\\end{figure}\n\nThe resulting $p$-values are concerning. This is because the $p$-values are not very smooth on the surfaces of the sample. It should be expected that small $p$-values are in areas of the defects. Pixels were tested positive or considered to be evidence of a defect, when $|z_{x,y}|>\\inputNumber{../figures/inference/inferenceIntro_critical.txt}$ to 2 decimal places. This value was chosen by controlling the false discovery rate at 5\\% using the \\cite{benjamini1995controlling} (BH) procedure. The positive pixels are shown in Figure \\ref{fig:inference_inferenceIntro_inference_positivePixels}.\n\nThis proposed method for defect detection failed because too many false positives were detected. These false positives appeared to have some structure, for example, clustering in the corners or on surfaces. Also, false negatives were detected because not all of the defects were detected.\n\nModel misspecification appeared to be the main source of error. The test statistics and $p$-values were inspected in Figure \\ref{fig:inference_inferenceIntro_histogram}. It can be seen that the test statistics were not compatible with the standard Normal distribution. Also, the majority of the $p$-values did not look uniformly distributed. This seems to suggest that the assumption of $Z_{x,y}\\sim \\normal(0,1)$ is incorrect.\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_histogram.eps}\n    \\caption{Histogram}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/inferenceIntro_pValue.eps}\n    \\caption{$p$-values}\n    \\label{fig:inference_inferenceIntro_pvalue}\n  \\end{subfigure}\n}\n  \\caption{a) The histogram of the test statistics, from the \\texttt{AbsFilter} projection at \\ang{120}, is compared with the standard Normal distribution. The standard Normal distribution is known as the null distribution in this scenario. b) The $p$-values are ordered and plotted. The critical region corresponds to controlling the false discovery rate at the 5\\% level using the \\cite{benjamini1995controlling} procedure. The dotted line shows the result if the $p$-values were uniformly distributed.}\n  \\label{fig:inference_inferenceIntro_histogram}\n\\end{figure}\n\nThis chapter recaps hypothesis testing, for a single test and then for multiple tests, treating each pixel as a test. Assumptions used in the hypotheses testing can be relaxed by using the empirical null \\citep{efron2004large}, which is reviewed here. The empirical null is then extended to an image filter, called the empirical null filter. This filter adjusts each test statistic according to its neighbours, ironing out false positive results. Simulations and results are shown towards the end of the chapter.\n\n\\section{Literature Review}\n\nConsider a test statistic $Z$ from a pixel. If there are no defects, then the statistic is null and has the null distribution $Z|H_0\\sim\\normal(0,1)$. This can be described by specifying the random variable as $Z\\sim\\normal(\\mu,1)$ and the null hypothesis as $H_0:\\mu=0$. A hypothesis test can judge how much $Z$ deviates from 0 by defining the alternative hypothesis $H_1:\\mu\\neq 0$. A statistic which does not has the null distribution is known as non-null.\n\nIn two-tailed hypothesis testing \\citep{pearson1900on, neyman1933on, fisher1970statistical}, the $p$-value can be compared with the user-defined size of the test $\\alpha$, also known as the significance level in this specific example. A positive result is declared when $p<\\alpha$, else it is a negative result. Correct and incorrect testing of the statistics can occur. For example, testing a null statistic as positive is known as a false positive. It can be shown that $\\alpha$ controls the false positive rate. $\\alpha=5.0\\%$ is a typical choice \\citep{wasserstein2019moving} and is used throughout this thesis.\n\nMultiple hypotheses testing occurs when there are more than one hypotheses to test. For example, $N$ pixels can be tested where the test statistics are $Z_1, Z_2, \\dotsc, Z_N$ and $Z_i\\sim\\normal(\\mu_i,1)$ for $i=1,2,\\dotsc,N$. The null hypotheses are $H_{0,i}:\\mu_i=0$ and are tested against the alternative $H_{1,i}:\\mu_i\\neq 0$ for $i=1,2,\\dotsc,N$. Let the corresponding $p$-values be $p_1, p_2, \\dotsc, p_N$.\n\nThe uncorrected test classify any $p_i<\\alpha$ as positive. This is flawed because the possibility of obtaining at least one false positive increases as the number of tests increases \\citep{shaffer1995multiple}. This method does control the per-comparison error rate (PCER) \\citep{benjamini1995controlling}. PCER is the proportion of false positives out of all tests. The notation for the number of true/false positive/negatives obtained are defined in Table \\ref{table:inference_randomvariables}. Using the notation, the PCER is defined as\n\\begin{equation}\n  \\text{PCER}=\n  \\dfrac{1}{N}\n  \\expectation[V]\n  \\ .\n\\end{equation}\nIt can be seen that if the uncorrected test controls the false positive rate such that $\\expectation[V]/N_0 = \\alpha$, then it controls the PCER such that\n\\begin{equation}\n  \\text{PCER}\\leqslant\\alpha \\ .\n\\end{equation}\n\n\\begin{table}\n  \\centering\n  \\begin{tabular}{l|cc|c}\n    &Negative&Positive&Total\\\\\\hline\n    Null & $U$ & $V$ & $N_0$\\\\\n    Non-null & $T$ & $S$ & $N-N_0$\\\\\\hline\n    &$N-R$&$R$&$N$\n  \\end{tabular}\n  \\caption{Random variable definitions for the number of true/false positives/negatives made in multiple hypotheses testing}\n  \\label{table:inference_randomvariables}\n\\end{table}\n\nThe Bonferroni correction \\citep{shaffer1995multiple, bland1995multiple, perneger1998what} controls the family-wise error rate (FWER) \\citep{shaffer1995multiple} where\n\\begin{equation}\n  \\text{FWER} = \\prob(V\\geqslant1) \\ .\n  \\label{eq:inference_fwer}\n\\end{equation}\nThis is done by adjusting the size of the test to be $\\alpha/N$. By using the adjusted size, then $\\text{FWER}=1-\\left[(1-\\alpha/N)^N\\right]$. Using the approximation $(1-\\alpha/N)^N\\approx 1-\\alpha$ then $\\text{FWER}\\approx \\alpha$. This shows that the Bonferroni correction controls the family-wise error rate such that\n\\begin{equation}\n  \\text{FWER} \\leqslant \\alpha \\ .\n\\end{equation}\nIn practice, the Bonferroni correction is not very powerful \\citep{perneger1998what}, meaning it gives too many false negatives. This is because the correction traded too many false positives for false negatives.\n\nThe \\cite{benjamini1995controlling} (BH) procedure controls the false discovery rate (FDR) \\citep{benjamini2010discovering} rather than the PCER or FWER. The FDR is the proportion of false positives out of all positive results, that is\n\\begin{equation}\n  \\text{FDR} = \\expectation\\left[\\dfrac{V}{R}\\right]\n  \\ .\n\\end{equation}\nIt is defined that $V/R=0$ when $R=0$.\n\nThe BH procedure adjusts the size of the test between the Bonferroni correction and the uncorrected test. It adapts to the data and chooses different sizes for different data. The procedure is as follows, the $p$-values are ordered such that $p_{(1)}\\leqslant p_{(2)}\\leqslant \\dotsc \\leqslant p_{(N)}$. Suppose a size $\\alpha$ is provided beforehand. The size is adjusted to\n\\begin{equation}\n  \\alpha_{\\text{BH}} = \\frac{\\alpha k}{N}\n\\end{equation}\nwhere\n\\begin{equation}\n  k\\text{ is the largest }i\\text{ for which }p_{(i)}\\leqslant\\frac{i}{N}\\alpha\n  \\ .\n\\end{equation}\nThis test the statistics with $p$-values $p_{(1)},p_{(2)},\\dotsc,p_{(k)}$ as positive. For the case where $p_{(1)}>\\alpha/N$ then $k=1$ so that the Bonferroni correction is used when there are no positive results, this is only for illustration purposes. For example in Figure \\ref{fig:inference_inferenceIntro_pvalue}, the $p$-values were plotted against their order so that the critical boundary was shown by a linear curve with gradient $\\alpha/N$.\n\nThe BH procedure comes from the fact that if all the statistics are null and independent, then the $p$-values are uniformly distributed \\citep{simes1986improved}. However, it can be shown that the BH procedure works for many scenarios of dependencies \\citep{benjamini2001control}. It can be shown that the BH procedure controls the FDR such that\n\\begin{equation}\n  \\text{FDR}\\leqslant\\alpha\n\\end{equation}\n\\citep{benjamini1995controlling}.\n\nIn summary, the uncorrected, Bonferroni and BH correction controls for different error rates according to the threshold $\\alpha$, summarised in Table \\ref{table:inference_corrections}.\n\n\\begin{table}\n    \\centering\n    \\begin{tabular}{l|l}\n        Correction&Controls for\\\\\\hline\n        No correction&$\\text{PCER}\\leqslant\\alpha$\\\\\n        Bonferroni&$\\text{FWER}\\leqslant\\alpha$\\\\\n        BH&$\\text{FDR}\\leqslant\\alpha$\n    \\end{tabular}\n    \\caption{Different types of corrections for multiple hypotheses testing are listed here, along with what they control for.}\n    \\label{table:inference_corrections}\n\\end{table}\n\nConsider a small example where a $\\SI{200}{\\pixel}\\times\\SI{200}{\\pixel}$ section of the $z$ image was investigated, as shown Figure \\ref{fig:inference_inferenceSubsample1_histogram}. The distribution of the test statistics appeared Normal but not centred at zero. By using the BH procedure to obtain a critical region of $|Z|>\\input{../figures/inference/inferenceSubsample1_criticalBoundary.txt}$ to 2 decimal places, almost half of the pixels were tested positive at the 5\\% FDR level. It is questionable whether such many positive results are sensible, in particular, in an area where defects were not expected.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample1_zImage.eps}\n      \\caption{Test statistics}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample1_histogram.eps}\n      \\caption{Histogram}\n    \\end{subfigure}\n    }\n    \\caption{The resulting test statistics for the \\texttt{AbsFilter} projection at \\ang{120} are shown in a). A $\\SI{200}{\\pixel}\\times\\SI{200}{\\pixel}$ sub-image was taken shown by the dashed lines. A histogram of the test statistics in the sub-image is shown in b). The critical region corresponds to the 5\\% FDR level.}\n    \\label{fig:inference_inferenceSubsample1_histogram}\n\\end{figure}\n\nThis problem commonly occurs in large scale multiple hypotheses testing \\citep{efron2004large} such as in microarrays \\citep{hedenfalk2001gene, efron2002empirical, efron2003robbins}. It appeared that the null distribution was misspecified as $Z_i|H_{0,i}\\sim\\normal(0,1)$ when in reality they are distributed as $Z_i|H_{0,i}\\sim\\normal(\\mu_0,\\sigma_0^2)$, where $\\mu_0$ and $\\sigma_0$ are the null mean and null standard deviation respectively.\n\nIn practice, $\\mu_0$ and $\\sigma_0$ are unknown. The empirical null \\citep{efron2004large} replaces the parameters of the null distribution with its estimate. Suppose $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$ are the estimated null mean and null standard deviation respectively. The statistics are specified by $Z_i\\sim\\normal(\\mu_i, \\widehat{\\sigma}_0^2)$ so that the following null hypotheses $H_{0,i}:\\mu_i=\\widehat{\\mu}_0$ are tested against $H_{1,i}:\\mu_i\\neq\\widehat{\\mu}_0$ for $i=1,2,\\dotsc,N$.\n\nIn \\cite{efron2004large}, a few assumptions were made in order to obtain the estimators $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$. Let the test statistic $Z$ have the p.d.f.\n\\begin{equation}\n  p_Z(z) =\n  \\pi_0 p_{Z|H_0}(z) + \\pi_1 p_{Z|H_1}(z)\n\\end{equation}\nwhere $0\\leqslant\\pi_0\\leqslant 1$ and  $\\pi_1 = 1-\\pi_0$. In addition, the null distribution is\n\\begin{equation}\n  p_{Z|H_0}(z) =\n  \\dfrac{1}{\\sqrt{2\\pi}\\sigma_0}\n  \\exp\\left[\n    -\\dfrac{1}{2}\n    \\left(\n      \\dfrac{z-{\\mu}_0}{\\sigma_0}\n    \\right)^2\n  \\right]\n\\end{equation}\nas it was assumed to be Normal. The non-null distribution $p_{Z|H_1}(z)$ does not need to be specified. Assume that the majority of the data are null and non-null test statistics are rare, say $\\pi_0>0.9$ \\citep{efron2004large}, then around the mode, the probability density function would be dominated by the null distribution. This implies that\n\\begin{equation}\n  p_{Z}(z) \\approx \\pi_0 p_{Z|H_0}(z)\n\\end{equation}\nfor values of $z$ around the mode. Finding the mode for $p_{Z}(z)$ and $p_{Z|H_0}(z)$ should yield the same solution. This justify the use of the mode for the empirical null mean \\citep{efron2004large}\n\\begin{equation}\n  \\widehat{\\mu}_0 = \\argmax\\widehat{p}_Z(z)\n\\end{equation}\nwhere $\\widehat{p}_Z(z)$ is the density estimation of $p_Z(z)$, for example it could be a smoothing spline fitted onto the histogram \\citep{efron2004large}.\n\nThe null standard deviation is estimated from the log density \\citep{efron2004large}. For values of $z$ at and around the mode\n\\begin{equation}\n  \\ln p_{Z}(z) =\n  \\ln\\left[\n    \\dfrac{\\pi_0}{\\sqrt{2\\pi}{\\sigma}_0}\n  \\right]\n  -\\dfrac{1}{2}\n  \\left(\n    \\dfrac{z-{\\mu}_0}{{\\sigma}_0}\n  \\right)^2\n  \\ .\n\\end{equation}\nTaking derivatives\n\\begin{align}\n  \\dfrac{\\partial}{\\partial z} \\ln p_{Z}(z) &=\n  -\\left(\n    \\dfrac{\n      z-{\\mu}_0\n    }\n    {\n      {\\sigma}_0^2\n    }\n  \\right)\n  \\\\\n  \\dfrac{\\partial^2}{\\partial z^2} \\ln p_{Z}(z) &=\n  -\\dfrac{\n    1\n  }\n  {\n    {\\sigma}_0^2\n  }\n\\end{align}\nwhich motivates the estimator \\citep{efron2004large}\n\\begin{equation}\n  \\widehat{\\sigma}_0 = \\left[\n    \\left.\n      -\\dfrac{\\partial^2}{\\partial z^2}\\ln\\widehat{p}(z)\n    \\right|_{z=\\widehat{\\mu}_0}\n  \\right]^{-1/2}\n  \\ .\n  \\label{eq:inference_nullStdEstimator}\n\\end{equation}\nThe evaluation of $z=\\widehat{\\mu}_0$ is used because at the mode, it was assumed that the null test statistics would dominate and non-null test statistics would not contribute much to the density estimate.\n\nThis method does not need estimations of $\\pi_0$ which makes it quite convenient. Estimations of $\\pi_0$ are discussed in literature such as \\cite{benjamini2000adaptive, pounds2003estimating, storey2003statistical, pounds2004improving, langaas2005estimating, durnez2014posthoc}. \\cite{efron2004large} motivated the use of the empirical null by investigating various types of false discovery rates \\citep{storey2002direct, storey2003positive, efron2002empirical, efron2007size} which will not be discussed here.\n\nThe empirical null is used widely, including in neuroimaging \\citep{schwartzman2008false, schwartzman2009empirical} and has been extended to include non-Normal null distributions \\citep{schwartzman2008false, schwartzman2008empirical}. There exist various methods for the empirical null, for example, \\cite{schwartzman2008empirical} used Poisson regression on the histogram counts in regions where the null statistics dominate. The empirical characteristic function was used in \\cite{jin2007estimating}.\n\n\\section{Empirical Null}\n\nReturning to the sub-image example in Figure \\ref{fig:inference_inferenceSubsample1_histogram}. The histogram was smoothed using a kernel density estimate \\citep{parzen1962on, friedman2001elements} as shown in Figure \\ref{fig:inference_inferenceSubsample1_densityEstimate}. The kernel density estimate \\citep{parzen1962on} is\n\\begin{equation}\n  \\widehat{p}_Z(z)=\n  \\frac{1}{nh}\n  \\sum_{i=1}^n\\phi\\left(\n    \\dfrac{z_i-z}{h}\n  \\right)\n  \\label{eq:inference_kernel_density_estimate}\n\\end{equation}\nwhere $h$ is the bandwidth, $\\phi(x)$ is the standard Normal density and $n=N$ is number of terms in the summation. The bandwidth was chosen such that\n\\begin{equation}\n  h = (0.9n^{-1/5}\\ + 0.16) \\times \\text{min}\\left(s_z,\\text{IQR}_z/1.34\\right)\n  \\label{eq:inference_ourruleofthumb}\n\\end{equation}\nwhere $s_z$ and $\\text{IQR}_z$ are the sample standard deviation and sample interquartile range. This bandwidth is justified later on in this section.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\subSize]{../figures/inference/inferenceSubsample1_densityEstimate.eps}\n  \\caption{The density of the test statistics, from Figure \\ref{fig:inference_inferenceSubsample1_histogram}, was estimated using a kernel density estimate. The dot-dashed line shows the empirical null distribution multiplied by some constant, this is to illustrate that the two densities have the same curvature at the mode.}\n  \\label{fig:inference_inferenceSubsample1_densityEstimate}\n\\end{figure}\n\nThe null mean was estimated by numerically finding the mode of the density estimate. The null standard deviation was estimated using Equation \\eqref{eq:inference_nullStdEstimator}. This resulted in the empirical null density to have the same curvature as the density estimate at the mode, this is illustrated in Figure \\ref{fig:inference_inferenceSubsample1_densityEstimate}. In this particular example, it was found that $\\widehat{\\mu}_0=\\input{../figures/inference/inferenceSubsample1_nullMean.txt}$ and $\\widehat{\\sigma}_0=\\input{../figures/inference/inferenceSubsample1_nullStd.txt}$ to 2 decimal places.\n\nThe use of the kernel density estimate has its advantages. The only tuning parameter is the bandwidth $h$ and the density estimate is simple enough to do calculus on it. Speed may be an issue as an evaluation of the density estimate requires the sum over the $n$ test statistics.\n\nThe test statistics were normalised to $T_1,T_2,\\dotsc,T_N$ by using\n\\begin{equation}\n  T_i = \\dfrac{\n    Z_i - \\widehat{\\mu}_0\n  }\n  {\n    \\widehat{\\sigma}_0\n  }\n  \\label{eq:inference_empiricalNullNormalise}\n\\end{equation}\nfor $i=1,2,\\dotsc,N$. The normalised $p$-values were obtained by using\n\\begin{equation}\n  p_i = 2(1-\\Phi(|t_i|))\n\\end{equation}\nand were used in the BH procedure. The critical region was found to be $|t|\\geqslant\\inputNumber{../figures/inference/inferenceSubsample1_nullNormalisedCritical.txt}$ at the 5\\% FDR level. In terms of the original units, the critical region was $z \\leqslant \\inputNumber{../figures/inference/inferenceSubsample1_nullCritical1.txt}$ and $\\inputNumber{../figures/inference/inferenceSubsample1_nullCritical2.txt}\\leqslant z$, all to 2 decimal places. The critical region and the normalised $p$-values are shown in Figure \\ref{fig:inference_inferenceSubsample1_nullResults}.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample1_nullHistogram.eps}\n        \\caption{Histogram}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample1_nullPValues.eps}\n        \\caption{$p$-values}\n    \\end{subfigure}\n    }\n    \\caption{Histogram and $p$-values of the test statistics from the sub-image in Figure \\ref{fig:inference_inferenceSubsample1_histogram}. The critical regions were adjusted using the empirical null and correspond to the 5\\% FDR level.}\n    \\label{fig:inference_inferenceSubsample1_nullResults}\n\\end{figure}\n\nNo positive results were found and the $p$-values were sensible as they resemble the uniform distribution. This demonstrated that the empirical null adjusted the parameters of the null distribution to fit onto the majority of the data to make a sensible inference.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample2_zImage.eps}\n        \\caption{Test statistics}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample2_subimagePositive.eps}\n        \\caption{Sub-image}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample2_nullHistogram.eps}\n        \\caption{Histogram}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsample2_nullPValues.eps}\n        \\caption{$p$-values}\n    \\end{subfigure}\n    }\n    \\caption{The resulting test statistics for the \\texttt{AbsFilter} projection at \\ang{120} are shown in a). A $\\SI{200}{\\pixel}\\times\\SI{200}{\\pixel}$ sub-image was taken shown by the dashed lines. Positive pixels are shown in red in b). The histogram of the test statistics in the sub-image are shown in c) along with the critical region. The $p$-values are shown in d). The critical regions were adjusted using the empirical null and correspond to the 5\\% FDR level.}\n    \\label{fig:inference_inferenceSubsample2}\n\\end{figure}\n\nAnother example is shown in Figure \\ref{fig:inference_inferenceSubsample2} where a $\\SI{200}{\\pixel}\\times\\SI{200}{\\pixel}$ sub-image containing a defect was used. It can be seen that the null distribution was not centred at zero which can be taken into account by using the empirical null. The estimation of the empirical null parameters was robust as it depends on the density estimate at the mode only, it should not be affected by non-null test statistics.\n\nThe BH procedure was conducted using the normalised $p$-values. $\\inputNumber{../figures/inference/inferenceSubsample2_nPositive.txt}$ pixels were tested positive at the 5\\% FDR level. The majority of the positive pixels were found to be clustered together which highlighted the defect. The entire area of the defects was not tested positive but a good portion of them are. This should be enough to raise suspicion in that particular area. Only a few pixels were falsely tested as positive, however, they are typically isolated single pixels. Isolated positive pixels should be discarded as they are more than likely to be tested positive by random chance.\n\nThis section describes the empirical null implementation in detail, in particular, the numerical and computational aspects. The empirical properties of the sampling distribution of the null parameter estimators were studied.\n\n\\subsection{Mode Finding}\n\nThe mode was found by solving $\\widehat{\\mu}_0 = \\argmax\\widehat{p}_Z(z)$ numerically. This was done by using the Newton-Raphson method to solve\n\\begin{equation}\n  \\dfrac{\n    \\partial\n  }\n  {\n    \\partial z\n  }\n  \\ln\\widehat{p}_Z(z)\n  = 0\n\\end{equation}\nfor $z$ which finds stationary points. The method is an iterative algorithm and requires an initial value $z^{(0)}$. The iterative step is\n\\begin{equation}\n  z^{(r+1)} =\n  z^{(r)}\n  -\\dfrac{\n    \\left.\n      \\dfrac{\n        \\partial\n      }\n      {\n        \\partial z\n      }\n      \\ln\\widehat{p}_Z(z)\n    \\right|_{z = z^{(r)}}\n  }\n  {\n    \\left.\n      \\dfrac{\n        \\partial^2\n      }\n      {\n        \\partial z^2\n      }\n      \\ln\\widehat{p}_Z(z)\n    \\right|_{z = z^{(r)}}\n  }\n\\end{equation}\nfor $r=0,1,2,3,\\dotsc$ until some convergence condition is met. The derivatives for the log density were obtained via the following. Recall the kernel density estimate in Equation \\eqref{eq:inference_kernel_density_estimate}, the log density is\n\\begin{equation}\n  \\ln\\widehat{p}_Z(z)=\n  \\ln\\left(\n    \\dfrac{1}{nh}\n  \\right)\n  +\n  \\ln\\left[\n    \\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i - z\n      }\n      {\n        h\n      }\n    \\right)\n  \\right]\n  \\ .\n\\end{equation}\nTaking the first-order derivative\n\\begin{equation*}\n  \\dfrac{\n    \\partial\n  }\n  {\n    \\partial z\n  }\n  \\ln\\widehat{p}_Z(z)\n  =\n  \\dfrac{\n    1\n  }\n  {\n    \\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i - z\n      }\n      {\n        h\n      }\n    \\right)\n  }\n  \\times\n  \\sum_{i=1}^n\n  \\phi'\\left(\n    \\dfrac{\n      z_i - z\n    }\n    {\n      h\n    }\n  \\right)\n  \\left(\n    -\\dfrac{\n      1\n    }\n    {\n      h\n    }\n  \\right)\n  \\ .\n\\end{equation*}\nUsing the fact that $\\phi(z)=(2\\pi)^{-1/2}\\exp(-z^2/2)$, then $\\phi'(z)=-z\\phi(z)$. This is used to simplify the equation to be\n\\begin{equation}\n  \\dfrac{\n    \\partial\n  }\n  {\n    \\partial z\n  }\n  \\ln\\widehat{p}_Z(z)\n  =\n  \\dfrac{\n    \\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i - z\n      }\n      {\n        h\n      }\n    \\right)\n    \\left(\n      \\dfrac{\n        z_i - z\n      }\n      {\n        h\n      }\n    \\right)\n  }\n  {\n    h\n    \\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i - z\n      }\n      {\n        h\n      }\n    \\right)\n  }\n  \\ .\n\\end{equation}\nTaking the derivative again\n\\begin{multline*}\n  \\dfrac{\n    \\partial^2\n  }\n  {\n    \\partial z^2\n  }\n  \\ln\\widehat{p}_Z(z)\n  =\n  \\left[\n    h\\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i-z\n      }\n      {\n        h\n      }\n    \\right)\n  \\right]^{-2}\n  \\times\n  \\left\\{\n    h\\left[\n      \\sum_{i=1}^n\n      \\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]\n  \\right.\n  \\\\\n  \\left.\n    \\times\n    \\sum_{i=1}^n\\left[\n      \\phi'\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        -\\dfrac{\n          1\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      +\\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        -\\dfrac{\n          1\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]\n  \\right.\n  \\\\\n  \\left.\n    -\n    \\left[\n      \\sum_{i=1}^n\n      \\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]\n    \\left[\n      h\\sum_{i=1}^n\n      \\phi'\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        -\\dfrac{\n          1\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]\n  \\right\\}\n  \\ .\n\\end{multline*}\nUsing the fact that $\\phi'(z)=-z\\phi(z)$, then it is simplified to\n\\begin{multline}\n  \\dfrac{\n    \\partial^2\n  }\n  {\n    \\partial z^2\n  }\n  \\ln\\widehat{p}_Z(z)\n  =\n  \\left[\n    h\\sum_{i=1}^n\n    \\phi\\left(\n      \\dfrac{\n        z_i-z\n      }\n      {\n        h\n      }\n    \\right)\n  \\right]^{-2}\n  \\times\n  \\left\\{\n    \\left[\n      \\sum_{i=1}^n\n      \\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]\n  \\right.\n  \\\\\n  \\left.\n    \\times\n    \\left[\n      \\sum_{i=1}^n\n      \\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n      \\left(\n        \\left(\n          \\dfrac{\n            z_i-z\n          }\n          {\n            h\n          }\n        \\right)^2\n        -1\n      \\right)\n    \\right]\n    -\n    \\left[\n      \\sum_{i=1}^n\n      \\phi\\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n    \\right.\n  \\right.\n  \\\\\n  \\left.\n    \\left.\n      \\left(\n        \\dfrac{\n          z_i-z\n        }\n        {\n          h\n        }\n      \\right)\n    \\right]^2\n  \\right\\}\n  \\ .\n\\end{multline}\n\nThe convergence criteria were met when either 10 update steps were taken or when\n\\begin{equation}\n  \\log\\left[\\left|\n    \\left.\n    \\dfrac{\n      \\partial\n    }\n    {\n      \\partial z\n    }\n  \\ln\\widehat{p}_Z(z)\n  \\right|_{z=z^{(r)}}\n  \\right|\\right]\n  <-5\n\\end{equation}\nat the current step. This was chosen arbitrary to speed up the algorithm without losing too much accuracy. At the end of the algorithm, for a successful convergence it was required, in addition, that\n\\begin{equation}\n  \\left.\n    \\dfrac{\n      \\partial^2\n    }\n    {\n      \\partial z^2\n    }\n    \\ln\\widehat{p}_Z(z)\n  \\right|_{z=z^{(r)}}\n  < 0 \\ .\n\\end{equation}\nFollowing a successful convergence, the estimator $\\widehat{\\sigma}_0$ was calculated straight away.\n\nThe algorithm does depend on the initial value so using different initial values were used. Further initial values were generated by sampling from $\\normal(z^{(0)}, s_z^2)$. This was done multiple times until three valid solutions were obtained. The best solution, the one with the largest $\\ln\\widehat{p}_Z\\left(\\widehat{\\mu}_0\\right)$, out of all the different initial values was used as the final answer. The Newton-Raphson method may converge to a local maximum.\n\nIt can be noted that this mode finding method can be applied to other distributions in general.\n\n\\subsection{Bandwidth Tuning}\n\nThe bandwidth $h$ controls how smooth the kernel density estimator is, higher values produce smoother curves \\citep{friedman2001elements}. Cross-validation methods to select $h$ do exist \\citep{bowman1984alternative, sheather2004density} but they can be computationally expensive. Rules of thumb \\citep{silverman1986density, sheather2004density} can be used instead and are usually of the form\n\\begin{equation}\n  h = bn^{-1/5}\\times\\text{min}\\left(s_z,\\text{IQR}_z/1.34\\right)\n\\end{equation}\nwhere $b=0.9$ \\citep{silverman1986density}. This rule of thumb was developed with consideration of bimodal Normal distributions \\citep{silverman1986density}. Other options include $b=1.06$ and $b=1.144$ to produce smoother curves \\citep{silverman1986density, sheather2004density}.\n\nThe kernel density estimator was only used to obtain values of $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$. Thus, a good bandwidth, in the context of the empirical null, is one which has good properties of $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$ rather than the density estimate. Exact properties of these estimators based on the kernel density estimators can be rather complicated. For example, numerous approximations were needed to show that $\\widehat{\\sigma}_0^2$ is an unbiased estimator of $\\sigma_0^2$ to the first-order and higher-order terms are functions of $(\\widehat{\\mu}_0 - \\mu_0)^2$ and $h$. This is shown in Appendix \\ref{chapter:appendix_expectationNullStdEstimator}.\n\nAn experiment was conducted to investigate how the estimators, $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$, varied with $h$ and $n$. This was done on a simulated dataset of $n$ standard Normal random variables. For a given $h$ and $n$, 100 values of $\\widehat{\\mu}_0$ and $\\widehat{\\sigma}_0$ were obtained by repeating the simulation of the dataset. The median squared error was obtained by taking the median over all the squared errors from the 100 estimates. 300 values of $n$ from 10 to $10^6$ and 30 values of $h$ from 0.09 to 1.5 were investigated. Figure \\ref{fig:inference_BandwidthSelection_error} shows the resulting median squared errors with the rules of thumb.\n\n$\\widehat{\\mu}_0$ has a low median squared error for large bandwidths. For low $n$, large bandwidths are particularly useful because smoother curves prevent any false bimodal features appearing, making it easier to find the mode.\n\nA smooth valley can be seen for the median squared error for $\\widehat{\\sigma}_0$. It appeared for a given $n$, there exist a bandwidth which minimises the median squared error. The rules of thumb did not optimise for $\\widehat{\\sigma}_0$ and undershot it. Figure \\ref{fig:inference_BandwidthSelection_error3} shows the median of the estimates of $\\sigma_0$. The true value in this simulation is $\\sigma_0=1$ which is represented as a horizontal plane. Bandwidths too small underestimated $\\sigma_0$, bandwidths too big overestimated $\\sigma_0$.\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection_error1.eps}\n      \\caption{$\\mu_0$}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection_error2.eps}\n      \\caption{$\\sigma_0$}\n  \\end{subfigure}\n  \\caption{The median squared error of the estimates of the empirical null parameters over 100 repeats of $n$ simulated standard Normal data. Lines represent the rule of thumb for various values of $b$.}\n  \\label{fig:inference_BandwidthSelection_error}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection_error3.eps}\n        \\caption{Heatmap}\n    \\end{subfigure}\n    \\caption{Median value of $\\widehat{\\sigma}_0$ over 100 repeats of $n$ simulated standard Normal data. The true value is $\\sigma_0=1$ which is represented by a horizontal plane.}\n    \\label{fig:inference_BandwidthSelection_error3}\n\\end{figure}\n\nOverestimates and underestimates are both dangerous and it can affect the false positive and false negative rate. This is because $\\widehat{\\sigma}_0$ was used to rescale the test statistics accordingly. Recall that the normalised test statistics are $t_i = \\dfrac{z_i - \\widehat{\\mu}_0}{\\widehat{\\sigma}_0}$. Low values of $\\widehat{\\sigma}_0$ produce large values, in magnitude, of $t_i$, potentially testing more of these test statistics as positive. High values of $\\widehat{\\sigma}_0$ do the opposite. A large number of positives can lead to more false positives and vice versa.\n\nThe optimal bandwidth for a given $n$ was found numerically. Figure \\ref{fig:inference_BandwidthSelection2_plot} shows the log squared error against the bandwidth for various $h$ given $n$. A smoothing spline \\citep{friedman2001elements} was fitted and this was optimised to find the bandwidth which minimises the log squared error for a given $n$. \\emph{MATLAB}'s \\texttt{fit(x,y,'smoothingspline')} function was used to fit the smoothing spline which has inbuilt cross validation procedures. The optimisation was done using \\emph{MATLAB}'s gradient free \\texttt{fminsearch} function, using $h=0.9n^{-1/5}$ as the initial value.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot1.eps}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot51.eps}\n    \\end{subfigure}\n    }\n    \\medskip\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot100.eps}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot150.eps}\n    \\end{subfigure}\n    }\n    \\medskip\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot199.eps}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/BandwidthSelection2_plot249.eps}\n    \\end{subfigure}\n    }\n    \\caption{A smoothing spline was fitted on the log squared error, for estimating $\\sigma_0$ on $n$ simulated standard Normal random variables, versus bandwidth. The experiment was repeated by simulating the standard Normal random variables again. The boxplots represent the 100 repeats. The red dashed line shows the bandwidth which minimised the fitted spline.}\n    \\label{fig:inference_BandwidthSelection2_plot}\n\\end{figure}\n\nA relationship between the optimal bandwidth and $n$ was attempted to be found. It was assumed such a relationship has the linear form\n\\begin{equation}\n  h_{\\text{optimal}} = b n^{-1/5} + a\n\\end{equation}\nwhere $b$ and $a$ are parameters to be fitted. This was chosen to establish a simple relationship with the rules of thumb. Figure \\ref{fig:inference_BandwidthSelection2_ruleOfThumb} show the fitting of an identity link gamma GLM in order to estimate $b$ and $a$. The estimated parameters are shown in Table \\ref{table:inference_BandwidthSelection2_ruleOfThumb}.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\mainSize]{../figures/inference/BandwidthSelection2_ruleOfThumb.eps}\n  \\caption{An identity link gamma GLM was fitted onto the relationship between the optimal bandwidth and $n^{-1/5}$ from the experiment. The dashed lines show the 68\\% prediction interval.}\n  \\label{fig:inference_BandwidthSelection2_ruleOfThumb}\n\\end{figure}\n\n\\begin{table}\n  \\centering\n  \\begin{tabular}{l|c}\n           &Estimate \\\\ \\hline\n  Intercept&\\input{../figures/inference/BandwidthSelection2_coeff1.txt}\\\\\n  Gradient &\\input{../figures/inference/BandwidthSelection2_coeff2.txt}\n  \\end{tabular}\n  \\caption{The estimated and standard error of the gradient and intercept from the linear relationship in Figure \\ref{fig:inference_BandwidthSelection2_ruleOfThumb}.}\n  \\label{table:inference_BandwidthSelection2_ruleOfThumb}\n\\end{table}\n\nThe rules of thumb can be improved if a small bias is added to it. This is because an intercept was found when fitting a linear relationship between the optimal bandwidth and $n^{-1/5}$. Adding this bias should improve the performance of the estimator $\\widehat{\\sigma}_0$. The gradient is similar to the rules of thumb in the literature \\citep{sheather2004density}.\n\nThe GLM fit in Figure \\ref{fig:inference_BandwidthSelection2_ruleOfThumb} appeared to underfit, which suggest there may be a more complicated relationship between the optimal bandwidth and $n$, for example, a quadratic term can be added to the GLM fit. The method used in fitting the smoothing spline could contribute to the underfitting. For example, if the smoothing spline was not smooth enough so that multiple local minima appeared, it would add variance to the optimal bandwidth if the optimisation algorithm converges to a local minimum. A basic linear relationship was chosen to avoid overfitting and to keep the rule of thumb simple. It would also choose a large bandwidth for small $n$ which would improve the performance $\\widehat{\\mu}_0$ by working on a smoother density estimate for the price of a less optimal $\\widehat{\\sigma}_0$.\n\nIn conclusion, a small bias added to the rule of thumb improved the performance of the estimator $\\widehat{\\sigma}_0$. \\cite{silverman1986density} pointed out that a smaller bandwidth should be used when, in particular, the distribution is bimodal. This is why \\cite{silverman1986density} suggested the use of $b=0.9$. Following from this, it was chosen that the intercept was added to Silverman's rule of thumb for the use in the empirical null $h = \\left(0.9n^{-1/5}+ 0.16\\right) \\times\\text{min}\\left(s_z,\\text{IQR}_z/1.34\\right)$.\n\n\\afterpage{\\clearpage}\n\\subsection{Comparison with Other Robust Estimators}\n\nThe empirical null mean is effectively the mode and the empirical null standard deviation is a measure of dispersion. It was investigated how they compare with various estimates of central tendency and dispersion for varying sample sizes $n$. The empirical sampling distribution of these estimators was observed to look for properties such as bias, variance and robustness.\n\nThe central tendency estimates looked at were the median, the mean and Tukey's biweighted mean \\citep{beaton1974fitting}. In summary, the biweighted mean weighs each data point using a smooth function of its residual and ignores any data points with residuals greater than a certain value. \\emph{MATLAB}'s \\texttt{robustfit} function was used for the biweighted mean and selects any tuning parameters.\n\nThe dispersion estimates looked at were the interquartile range (IQR) $\\div 1.349$, the standard deviation and the median absolute deviation around the mode (MADA-mode) $\\times 1.483$. The normalisation constants were used so that MADA-mode and IQR can be compared directly to the standard deviation. MADA-mode was considered to investigate how estimators, which depends on the mode, perform.\n\nIn the next section, these estimators are used on a circular kernel with radius $r$ containing $\\pi r^2$ pixels. To make results comparable, the sample size $n$ may be represented using $r=\\sqrt{n/\\pi}$.\n\nA sample of standard Normal random variables was simulated to obtain estimates of central tendency and dispersion. This was repeated 100 times to obtain a sampling distribution. The results are shown in Figures \\ref{fig:inference_NullIidMean} and \\ref{fig:inference_NullIidStd}. The mode and empirical null standard deviation both suffered from high variance, much higher than typical robust estimators.\n\nThe empirical null standard deviation had some positive bias and it was found that this bias was quite sensitive to the bandwidth. Further fine-tuning on the bandwidth would be required for the empirical null standard deviation to be unbiased. For example, it appeared there was a consistent positive bias for all $r$ investigated, perhaps suggesting the bandwidth parameter $a$ should be decreased ever so slightly. The source of bias could come from the fact that the bandwidth was tuned to minimise the log squared error rather than the squared bias.\n\nIt is interesting to compare the empirical null standard deviation with MADA-mode, in Figure \\ref{fig:inference_NullIidStd}, because they both depend on the mode. The mode suffered from high variance which may affect dispersion estimators using the mode. The figure shows that MADA-mode had less variance than the empirical null standard deviation. This suggests that using the curvature of the density estimate at the mode was the main source of variance for the empirical null standard deviation.\n\nTo test for robustness, a sample of mixture of Gaussian random variables were simulated with the following distribution: $\\normal(0,1)$ with probability $90\\%$, $\\normal(3,1)$ with probability $10\\%$. The $\\normal(3,1)$ component acts as non-null statistics and robust estimators should be unaffected by it. The results are shown in Figures \\ref{fig:inference_NullIidMixtureMean} and \\ref{fig:inference_NullIidMixtureStd}. The empirical null estimators are robust to the non-null component but still suffers from high variance. The rest of the estimators were affected by the non-null statistics, making them unsuitable to estimate parameters of the null parameters.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullMean1.eps}\n        \\caption{Mode}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullMean2.eps}\n        \\caption{Bisquare weighted mean}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullMean4.eps}\n        \\caption{Median}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullMean3.eps}\n        \\caption{Mean}\n      \\end{subfigure}\n    }\n  \\caption{Different types of central tendency estimators were used on $\\pi r^2$ standard Normal random variables. The boxplots represent the sampling distributions over 100 estimates. The dashed lines show the 95\\% confidence interval for the sample mean.}\n  \\label{fig:inference_NullIidMean}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullStd1.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullStd2.eps}\n        \\caption{MADA-mode}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullStd4.eps}\n        \\caption{IQR}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIid_nullStd3.eps}\n        \\caption{Standard deviation}\n      \\end{subfigure}\n    }\n  \\caption{Different types of statistical dispersion estimators were used on $\\pi r^2$ standard Normal random variables. The boxplots represent the sampling distributions over 100 estimates. The dashed lines show the 95\\% confidence interval for the sample variance.}\n  \\label{fig:inference_NullIidStd}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullMean1.eps}\n        \\caption{Mode}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullMean2.eps}\n        \\caption{Bisquared weighted mean}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullMean4.eps}\n        \\caption{Median}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullMean3.eps}\n        \\caption{Mean}\n      \\end{subfigure}\n    }\n  \\caption{Different types of central tendency estimators were used on $\\pi r^2$ mixture of Gaussian random variables. The random variable has distribution $\\normal(0,1)$ with probability $0.9$ and $\\normal(3,1)$ with probability $0.1$. The boxplots represent the sampling distributions over 100 estimates. The dashed lines show the 95\\% confidence interval for the sample mean.}\n  \\label{fig:inference_NullIidMixtureMean}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullStd1.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullStd2.eps}\n        \\caption{MADA-mode}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullStd4.eps}\n        \\caption{IQR}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/NullIidMixture_nullStd3.eps}\n        \\caption{Standard deviation}\n      \\end{subfigure}\n    }\n  \\caption{Different types of statistical dispersion estimators were used on $\\pi r^2$ mixture of Gaussian random variables. The random variable has distribution $\\normal(0,1)$ with probability $0.9$ and $\\normal(3,1)$ with probability $0.1$. The boxplots represent the sampling distributions over 100 estimates. The dashed lines show the 95\\% confidence interval for the sample variance.}\n  \\label{fig:inference_NullIidMixtureStd}\n\\end{figure}\n\n\\afterpage{\\clearpage}\n\\section{Empirical Null Filter}\n\nReturning to the example at the start of the chapter, the empirical null could be used on the histogram shown in Figure \\ref{fig:inference_inferenceIntro_histogram}. The resulting empirical null distribution is shown in Figure \\ref{fig:inference_inferenceSubsampleAll}. The critical boundary, adjusted using the empirical null, which corresponds to the 5\\% FDR level was found to be $z\\leqslant\\inputNumber{../figures/inference/inferenceSubsampleAll_nullCritical1.txt}$ and $\\inputNumber{../figures/inference/inferenceSubsampleAll_nullCritical2.txt}\\geqslant z$ to 2 decimal places. This would test all pixels as negative which is incorrect.\n\nThe problem was that the empirical distribution of all of the test statistics looked like it did not come from a Normal distribution. It appeared that the test statistics varied spatially, suggesting that the empirical null varied spatially as well. To account for the spatial variability of the null parameters, one possible extension to the empirical null is to spilt the $z$ image into a grid and conduct inference in each section separately. There are problems with this though. The first problem is that how the grid is overlaid can be arbitrary, for example, the grid can be translated to produce different sections. Secondly, it is not clear how to combine the results from each section together \\citep{efron2008simultaneous}.\n\nThe empirical null filter extends the empirical null to images. The parameters of the null distribution varies spatially, slowly and smoothly. Let the test statistic of the pixel at position $(x,y)$ be\n\\begin{equation}\nZ_{x,y}\\sim\\normal(\\mu_{0,x,y},\\widehat{\\sigma}_{0,x,y}^2)\n\\end{equation}\nfor $x=1,2,\\dotsc,W$ and $y=1,2,\\dotsc,H$. $\\mu_{0,x,y}$ and $\\sigma_{0,x,y}$ are the null mean and null standard deviation at position $(x,y)$ respectively. Define the null hypotheses to be\n\\begin{equation}\n  H_{0,x,y}:\\mu_{0,x,y}=\\widehat{\\mu}_{0,x,y}\n\\end{equation}\nwhich are tested against\n\\begin{equation}\n  H_{1,x,y}:\\mu_{0,x,y}\\neq\\widehat{\\mu}_{0,x,y} \\ .\n\\end{equation}\n The empirical null filter aims to estimate the parameters $\\mu_{0,x,y}$ and $\\sigma_{0,x,y}$ for all $x$ and $y$.\n\n \\begin{figure}[t]\n  \\centering\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsampleAll_subimagePositive.eps}\n    \\caption{Test statistics}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/inferenceSubsampleAll_densityEstimate.eps}\n    \\caption{Distribution of test statistics}\n  \\end{subfigure}\n  \\caption{The resulting test statistics for the \\texttt{AbsFilter} projection at \\ang{120} are shown in a). The density estimate of the statistics is shown in b). The empirical null distribution multiplied by some constant is also plotted in b); this is to illustrate the curvature is the same as the density estimate at the mode.}\n  \\label{fig:inference_inferenceSubsampleAll}\n\\end{figure}\n\nThe empirical null filter uses the empirical null on neighbouring pixels to estimate the null parameters. To estimate $\\mu_{0,x,y}$ and $\\sigma_{0,x,y}$, a circular kernel $C_r(x,y)$ of radius $r$ was centred at $(x,y)$. All the pixels captured by the circular kernel and the ROI were used for the empirical null to obtain $\\widehat{\\mu}_{0,x,y}$ and $\\widehat{\\sigma}_{0,x,y}$, in other words\n\\begin{equation}\n  \\widehat{\\mu}_{0,x,y} = \\argmax\\widehat{p}_{Z_{x,y}}(z)\n\\end{equation}\n\\begin{equation}\n  \\widehat{\\sigma}_{0,x,y} = \\left[\n    \\left.\n      -\\dfrac{\\partial^2}{\\partial z^2}\\ln\\widehat{p}_{Z_{x,y}}(z)\n    \\right|_{z=\\widehat{\\mu}_{0,x,y}}\n  \\right]^{-1/2}\n\\end{equation}\nwhere\n\\begin{equation}\n\\widehat{p}_{Z_{x,y}}(z) =\n\\frac{1}{nh}\n  \\sum_{i,j\\in K_{x,y}}\\phi\\left(\n    \\dfrac{z_{i,j}-z}{h}\n  \\right) \\ ,\n\\end{equation}\n$K_{x,y} = C_r(x,y) \\cap \\text{ROI}$ and $n=\\left|K_{x,y}\\right|$, not to be confused with $N$. A bandwidth of $h = (0.9n^{-1/5}\\ + 0.16) \\times \\text{min}\\left(s_{x,y},\\text{IQR}_{x,y}/1.34\\right)$ was used where $s_{x,y}$ and $\\text{IQR}_{x,y}$ are the sample standard deviation and sample interquartile range of the test statistics in $K_{x,y}$.\n\nAfter obtaining the estimates of the empirical null parameters, the test statistics were normalised using\n\\begin{equation}\n  T_{x,y} =\n  \\dfrac{\n    Z_{x,y}-\\widehat{\\mu}_{0,x,y}\n  }\n  {\n    \\widehat{\\sigma}_{0,x,y}\n  }\n\\end{equation}\nand only the normalised test statistics were used in hypotheses testing. It should be noted that because the kernels can overlap, correlation between $T_{x,y}$ for different $(x,y)$ is introduced.\n\nThe parameter of choice is the kernel radius $r$. A radius too small will treat defects as the null and will not detect them, too big can also cause problems as well. The empirical null filter assumes that the null parameters vary smoothly and slowly so that the null test statistics captured by the kernel is somewhat Normal. If the radius is too big, the kernel will capture distanced test statistics with very different null distributions. If all of these test statistics are pulled together into a histogram, the null distribution may not look Normal at all which can cause problems when fitting a Normal null distribution. Furthermore, if $r\\rightarrow \\infty$, then this is just using the empirical null on all pixels.\n\nThe radius controls the proportion of pixels which are null captured by the kernel, denoted as $\\pi_0$. It should be selected so that $\\pi_0$ is of sensible value, for example, $>90\\%$. In practice, the defects are unknown so various kernel radiuses should be tried out. The kernel radius should be much larger than the size of the defect.\n\nThere exist similar filters, for example the local normalisation filter \\citep{sage2003teaching, sage2018local} uses a Gaussian filter to obtain $\\widehat{\\mu}_{0,x,y}$. $\\widehat{\\sigma}_{0,x,y}^2$ was obtained by applying another Gaussian filter on the $\\left(z_{x,y}-\\widehat{\\mu}_{0,x,y}\\right)^2$ image. The purpose of this filter was to normalise images with uneven illumination. The disadvantage of using this filter, for estimating the null parameters, is that it uses a Gaussian filter. This is a type of weighted mean which is not robust to non-null statistics. Also, the two Gaussian filters can have different radiuses, it is not clear how to set them.\n\n\\subsection{Design and Implementation}\n\nThe empirical null filter was implemented using open-source software called \\emph{ImageJ} \\citep{abramoff2004image, schneider2012nih, perez2013image} by modifying the existing class \\texttt{RankFilters}, available on \\emph{GitHub} \\citep{imagej2018rank}. This class implemented filters, such as the mean filter and median filter, using a circular kernel, making this a suitable framework for the empirical null filter. Figure \\ref{fig:inference_fijiGui} shows the graphical user interface of the empirical null filter in \\emph{Fiji} \\citep{schindelin2012fiji}, a distribution of \\emph{ImageJ}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth]{../figures/inference/fiji/gui.png}\n    \\caption{The graphical user interface of the empirical null filter in \\emph{Fiji}. The user can adjust the kernel radius as well as other advanced options relating to the Newton-Raphson method and the kernel density estimate. By-products such as the empirical null parameters can be shown after the filtering as well.}\n    \\label{fig:inference_fijiGui}\n\\end{figure}\n\nAs a test, the empirical null filter with $r=\\SI{5}{\\pixel}$ was used on a \\emph{ImageJ} sample image \\texttt{bridge.gif}, as shown in Figure \\ref{fig:inference_fijiBridgeFilter}. It is meaningless to use the empirical null filter on an arbitrary image, however, it did verify that the filter coped with it with some computational considerations. The empirical null images $\\widehat{\\mu}_{0,x,y}$ and $\\widehat{\\sigma}_{0,x,y}$ could be of interest, in particular, the empirical null mean image could be interpreted as the result of a mode filter \\citep{griffin2000mean}. Figure \\ref{fig:inference_fijiMean} compares the empirical null mean with other averaging filters. The empirical null mean has an impasto effect and preserved edges which are similar to the result in \\cite{griffin2000mean}. Dispersion filters such as the standard deviation filter can be used to detect edges. Figure \\ref{fig:inference_fijiStd} compares the standard deviation filter with the empirical null standard deviation. The resulting images were similar but it was notable that the edges in the empirical null standard deviation were sharper, suggesting that the empirical null standard deviation is a more robust measure of dispersion compared to the standard deviation.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/bridge.png}\n        \\caption{Before filtering}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/bridgeFilter.png}\n        \\caption{After filtering}\n    \\end{subfigure}\n    }\n    \\caption{The empirical null filter, with kernel radius $r=\\SI{5}{\\pixel}$, was used on the sample image \\texttt{bridge.gif}.}\n    \\label{fig:inference_fijiBridgeFilter}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/bridge.png}\n        \\caption{No filter}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/mean.png}\n        \\caption{Mean filter}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/median.png}\n        \\caption{Median filter}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/nullMean.png}\n        \\caption{Empirical null mean}\n    \\end{subfigure}\n    }\n    \\caption{Various averaging filters, with kernel radius $r=\\SI{5}{\\pixel}$, were used on the sample image \\texttt{bridge.gif}.}\n    \\label{fig:inference_fijiMean}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/std.png}\n        \\caption{Standard deviation filter}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/fiji/nullStd.png}\n        \\caption{Empirical null standard deviation}\n    \\end{subfigure}\n    }\n    \\caption{Various dispersion filters, with kernel radius $r=\\SI{5}{\\pixel}$, were used on the sample image \\texttt{bridge.gif}.}\n    \\label{fig:inference_fijiStd}\n\\end{figure}\n\nWhen using the empirical null filter in \\emph{ImageJ} or \\emph{Fiji}, the user is presented with a menu, as shown in Figure \\ref{fig:inference_fijiGui}. The user can input the kernel radius, the filter then modifies the currently selected image $z_{x,y}$ to $t_{x,y}$ for all $x$ and $y$ using a circular kernel with the specified radius. The menu also has options for by-product images to be shown: the empirical null mean $\\widehat{\\mu}_{0,x,y}$, the empirical null standard deviation $\\widehat{\\sigma}_{0,x,y}$, the standard deviation filter, quartile filters. Advanced options are available to the user, for example, the number of initial values set the number of valid solutions to be found when using the Newton-Raphson method to find the mode of the density estimate. The user can also set the maximum number of steps and tolerance for the Newton-Raphson method. The bandwidth parameters for the kernel density estimate can also be adjusted here.\n\nLine filtering was done from left to right. At the start on the far left, an initial value of the median over the pixels in the kernel was used. Also, various initial values were randomly tried out until a requested number of valid solutions were found. For the following pixel to the right, the empirical null mean of the neighbouring left pixel was used as the initial value. This was chosen as it was assumed the empirical null mean would vary slowly and smoothly spatially. The implementation uses multiple threads, each thread filters a row in parallel.\n\nWhen the kernel captures pixels outside the boundary of the image or ROI, \\texttt{RankFilters} uses nearest pixel padding which fills in pixels outside the ROI with values to the nearest pixels. Figure \\ref{fig:inference_padding_nearest} shows an example of nearest pixel padding on the top left corner of a rectangle ROI. This is not suitable for the empirical null filter as this will cause bias in the density estimation. The empirical null filter uses \\texttt{NaN} padding which fills pixels outside the ROI with \\texttt{NaN}. This indicates that these pixels are outside the ROI and are ignored. The number of non-\\texttt{NaN} captured by the kernel was kept track for calculations such as the bandwidth.\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{\\subSize}\n      \\begin{tabular}{lllllll}\n         $\\ddots$ & $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\udots$ \\\\\n         $\\dotsc$ & $z_{1,1}$ & $z_{1,1}$ & $z_{1,1}$ & $z_{1,2}$ & $\\dotsc$ \\\\\n         $\\dotsc$ & $z_{1,1}$ & $z_{1,1}$ & $z_{1,1}$ & $z_{1,2}$ & $\\dotsc$ \\\\ \\cline{4-6}\n         $\\dotsc$ & $z_{1,1}$ & \\multicolumn{1}{l|}{$z_{1,1}$} & $z_{1,1}$ & $z_{1,2}$ & $\\dotsc$ \\\\\n         $\\dotsc$ & $z_{2,1}$ & \\multicolumn{1}{l|}{$z_{2,1}$}  & $z_{2,1}$ & $z_{2,2}$ & $\\dotsc$ \\\\\n         $\\udots$ & $\\vdots$ & \\multicolumn{1}{l|}{$\\vdots$}  & $\\vdots$ & $\\vdots$ & $\\ddots$\n    \\end{tabular}\n    \\caption{Nearest pixel padding}\n    \\label{fig:inference_padding_nearest}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\begin{tabular}{lllllll}\n         $\\ddots$ & $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\udots$ \\\\\n         $\\dotsc$ & \\texttt{NaN} & \\texttt{NaN} & \\texttt{NaN} & \\texttt{NaN} & $\\dotsc$ \\\\\n         $\\dotsc$ & \\texttt{NaN} & \\texttt{NaN} & \\texttt{NaN} & \\texttt{NaN} & $\\dotsc$ \\\\ \\cline{4-6}\n         $\\dotsc$ & \\texttt{NaN} & \\multicolumn{1}{l|}{\\texttt{NaN}} & $z_{1,1}$ & $z_{1,2}$ & $\\dotsc$ \\\\\n         $\\dotsc$ & \\texttt{NaN} & \\multicolumn{1}{l|}{\\texttt{NaN}}  & $z_{2,1}$ & $z_{2,2}$ & $\\dotsc$ \\\\\n         $\\udots$ & $\\vdots$ & \\multicolumn{1}{l|}{$\\vdots$}  & $\\vdots$ & $\\vdots$ & $\\ddots$\n    \\end{tabular}\n    \\caption{\\texttt{NaN} padding}\n    \\label{fig:inference_padding_nan}\n  \\end{subfigure}\n  \\caption{When a kernel contains pixels outside the ROI, as shown by the solid line, the pixels can either be extrapolated using the nearest pixel or completely ignored by filling in the missing pixels with \\texttt{NaN}.}\n  \\label{fig:inference_padding}\n\\end{figure}\n\nWhen filtering arbitrary images such as \\texttt{bridge.gif}, a few computational considerations were needed. \\texttt{bridge.gif} is an 8-bit image so values were represented as integers. This opened up opportunities for the interquartile range and the standard deviation to be zero. This caused problems as this would set the bandwidth to zero. When the standard deviation is zero, it was set to $0.289$ which corresponds to the standard deviation of a uniform random variable. When the inter-quartile range is zero, the inter-quartile range was set to the standard deviation $\\times 1.34$.\n\nWhen the number of initial values is too few, poor solutions to $\\widehat{\\mu}_0$ are possible which then can propagate to the pixel to the right and used as its initial value. Poor initial values could cause the Newton-Raphson method to never converge. If the Newton-Raphson method failed to converge too many times, the median, over pixels in the kernel, is used as the new initial value. Should it fail too, the program gives up and puts a $\\texttt{NaN}$ in that pixel.\n\n\\subsection{Filtering an Image with No Defects}\n\nAn experiment was conducted to demonstrate the effects of the empirical null filter on a simulated $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$ Gaussian image, where all the pixels have value distributed as standard Normal. The purpose is to simulate test statistics which are null and few positive results, subject to the FDR, should be detected. The test statistics after filtering should preserve its original distribution, or at least close to it. The statistical moments before and after filtering should be the same and were investigated. Because the empirical null mean and empirical null standard deviation are random variables, the filtered pixels will never be Normal and any normality tests would be too strict for this experiment.\n\nContamination is defined as some smooth and slowly varying function added and/or multiplied to an image. Conducting hypotheses testing on a contaminated Gaussian image may cause errors if the null distributions were incorrectly specified as standard Normal. In this experiment, the contamination was a gradient such that the pixel at position $(x,y)$ has a value distributed as $Z_{x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_{0,x,y}^2)$ where\n\\begin{equation}\n  \\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0) \\ ,\n\\end{equation}\n$(x_0,y_0)$ is the centre of the image and $\\sigma_{0,x,y}=2$ for all $(x,y)$.\n\nA caveat is that some bias to the null standard deviation estimation would be introduced because of the contamination. This is because sources of variance captured by the kernel are from $\\sigma_{0,x,y}$ and also from the variability of $\\mu_{0,x,y}$. This can be shown with an example. Let $Z_{x,y}$ be the value of the pixels captured by the circular kernel, centred at the origin, for integer values of $(x,y)$ such that $x^2+y^2\\leqslant r^2$. Suppose that $Z_{x,y}\\sim\\normal(ax+by,\\sigma^2)$. The quantities of interest are the expectation and variance of all the values contained in the kernel because this is the quantity the estimators are estimating.\n\nThe calculations of the expectation and variance of $Z_{x,y}$ can be approximated by treating $x$ and $y$ as uniformly distributed within a circle centred at the origin with radius $r$. The expectation is\n\\begin{equation}\n\\expectation[Z_{X,Y}] = \\expectation\\expectation[Z_{X,Y}|X,Y]=0 \\ .\n\\end{equation}\n\nThe variance is given as $\\variance[Z_{X,Y}] = \\expectation\\variance[Z_{X,Y}|X,Y] + \\variance\\expectation[Z_{X,Y}|X,Y]$. From the distribution of $Z_{X,Y}$, $\\expectation\\variance[Z_{X,Y}|X,Y] = \\sigma^2$ and $\\variance\\expectation[Z_{X,Y}|X,Y]=\\variance[aX+bY]$. This is worked out to be\n\\begin{align}\n\\variance[aX+bY] &= \\dfrac{1}{\\pi r^2}\\int_{\\rho=0}^{\\rho=r}\\int_{\\theta=0}^{\\theta=2\\pi}\n\\rho^3(a\\cos\\theta + b\\sin\\theta)^2 \\diff \\theta \\diff \\rho\n\\nonumber\\\\\n& = \\dfrac{1}{4}(a^2+b^2)r^2\n\\end{align}\nthus\n\\begin{equation}\n\\variance[Z_{X,Y}] = \\dfrac{1}{4}(a^2+b^2)r^2 + \\sigma^2 \\ .\n\\end{equation}\nThis shows that when estimating the null variance on a contaminated Gaussian image, there may be a $(a^2+b^2)r^2/4$ bias. If the contamination is slowly varying, that is $a$ and $b$ are small, then the bias should be small.\n\n\\begin{figure}[p]\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullGaussianScript_beforeFilter.eps}\n    \\caption{Unfiltered}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullGaussianScript_afterFilter.eps}\n    \\caption{Filtered}\n    \\label{fig:inference_allNullGaussianScript_afterFilter}\n  \\end{subfigure}\n  }\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullGaussianScript_nullMean.eps}\n    \\caption{Empirical null mean}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullGaussianScript_nullStd.eps}\n    \\caption{Empirical null std}\n  \\end{subfigure}\n  }\n  \\caption{A $\\SI{256}{\\pixel}\\times \\SI{256}{\\pixel}$ Gaussian image before and after filtering with kernel radius \\SI{20}{\\pixel}. Also shown are the empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_allNullGaussianScript}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullPlaneScript_beforeFilter.eps}\n    \\caption{Unfiltered}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullPlaneScript_afterFilter.eps}\n    \\caption{Filtered}\n    \\label{fig:inference_allNullPlaneScript_afterFilter}\n  \\end{subfigure}\n  }\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullPlaneScript_nullMean.eps}\n    \\caption{Empirical null mean}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullPlaneScript_nullStd.eps}\n    \\caption{Empirical null std}\n  \\end{subfigure}\n  }\n  \\caption{A $\\SI{256}{\\pixel}\\times \\SI{256}{\\pixel}$ contaminated Gaussian image before and after filtering with kernel radius \\SI{20}{\\pixel}. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. Also shown are the empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_allNullPlaneScript}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullGaussianScript_pValue.eps}\n    \\caption{No contamination}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/allNullPlaneScript_pValue.eps}\n    \\caption{With contamination}\n  \\end{subfigure}\n  \\caption{$p$-values from a filtered $\\SI{256}{\\pixel}\\times \\SI{256}{\\pixel}$ Gaussian image with kernel radius \\SI{20}{\\pixel}. In b), the Gaussian image was contaminated before filtering. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The $p$-values were obtained from the images in Figures \\ref{fig:inference_allNullGaussianScript_afterFilter} and \\ref{fig:inference_allNullPlaneScript_afterFilter}. The critical region corresponds to the 5\\% FDR level. The dotted lines shows the $p$-values if they were uniformly distributed.}\n  \\label{fig:inference_allNull_pValues}\n\\end{figure}\n\nAn example of a Gaussian image with/without contamination before/after filtering are shown in Figures \\ref{fig:inference_allNullGaussianScript} and \\ref{fig:inference_allNullPlaneScript}. In the contaminated example, the filter managed to estimate the null mean, picking up the gradient. This enabled the filtered image to look flat and removed the contamination. The $p$-values after filtering are shown in Figure \\ref{fig:inference_allNull_pValues}. A quick inspection suggests that the filtered pixels appeared reasonably Normal for this particular example.\n\nFor a given kernel radius $r$, 100 different Gaussian images were filtered to investigate the within image mean, standard deviation and kurtosis of the filtered statistics. Various other filters for normalisation were used as well such as the MADA-mode null filter, median IQR null filter and the mean variance null filter. They use different estimators to estimate the null parameters as their name suggests, Table \\ref{table:inference_nullFilters} clarifies them.\n\n\\begin{table}\n  \\centering\n  \\begin{tabular}{l|l|l}\n    Filters&Null mean&Null standard deviation\\\\\\hline\n    MADA-mode null&Mode&MADA-mode $\\times1.483$\\\\\n    Median IQR null&Median&IQR $\\div1.349$\\\\\n    Mean variance null&Mean&Standard deviation\n  \\end{tabular}\n  \\caption{Various filters using different estimators to estimate the null parameters are described here.}\n  \\label{table:inference_nullFilters}\n\\end{table}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianEmpirical_mean.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMadMode_mean.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMedianIqr_mean.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMeanVar_mean.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample mean of a filtered Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$.  The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullGaussian_mean}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianEmpirical_variance.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMadMode_variance.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMedianIqr_variance.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMeanVar_variance.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample standard deviation of a filtered Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$. The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullGaussian_var}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianEmpirical_kurtosis.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMadMode_kurtosis.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMedianIqr_kurtosis.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullGaussianMeanVar_kurtosis.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample kurtosis of a filtered Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$. The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullGaussian_kurtosis}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneEmpirical_mean.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMadMode_mean.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMedianIqr_mean.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMeanVar_mean.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample mean of a filtered contaminated Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullPlane_mean}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneEmpirical_variance.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMadMode_variance.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMedianIqr_variance.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMeanVar_variance.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample standard deviation of a filtered contaminated Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullPlane_var}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneEmpirical_kurtosis.eps}\n    \\caption{Empirical null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMadMode_kurtosis.eps}\n    \\caption{MADA-mode null filter}\n  \\end{subfigure}\n  }\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMedianIqr_kurtosis.eps}\n    \\caption{Median IQR null filter}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n    \\includegraphics[width=\\textwidth]{../figures/inference/AllNullPlaneMeanVar_kurtosis.eps}\n    \\caption{Mean var null filter}\n  \\end{subfigure}\n  }\n  \\caption{The within image sample kurtosis of a filtered contaminated Gaussian image of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The boxplots summarise the 100 repeated simulations of the image. The dashed lines show the 95\\% confidence interval using standard tests and assuming independence.}\n  \\label{fig:inference_AllNullPlane_kurtosis}\n\\end{figure}\n\nThe results for the filtered images are shown in Figures \\ref{fig:inference_AllNullGaussian_mean}, \\ref{fig:inference_AllNullGaussian_var} and \\ref{fig:inference_AllNullGaussian_kurtosis}. For the filtered contaminated images, they are in Figures \\ref{fig:inference_AllNullPlane_mean}, \\ref{fig:inference_AllNullPlane_var} and \\ref{fig:inference_AllNullPlane_kurtosis}. The filtered test statistic means did agree with zero as expected, showing that the filters centred the statistics when normalising. When using the empirical null filter, there was some negative bias with the standard deviation of the filtered test statistics. The negative bias comes from a positive bias when estimating the null standard deviation.\n\nWhen filtering the contaminated image, all estimators suffered from negative bias in the standard deviation of the filtered statistics, in particular when the kernel radius increased. This is shown in Figure \\ref{fig:inference_AllNullPlane_var}. As discussed before, the kernel captured the variation due to the contamination and this added bias to the estimation of the null standard deviation.\n\nThe kurtosis in Figures \\ref{fig:inference_AllNullGaussian_kurtosis} and \\ref{fig:inference_AllNullPlane_kurtosis} showed that the empirical null filter caused the filtered statistics to have heavy tails, in particular, for small kernel radiuses. This could cause problems in hypotheses testing because heavy tails could be misinterpreted as a contribution from non-null statistics. The source of the kurtosis inflation is from the estimation of the null standard deviation. This can be seen by comparing the empirical null filter with the MADA-mode null filter because the only difference between the two filters is in the estimation of the null standard deviation.\n\n\\afterpage{\\clearpage}\n\\subsection{Detection of Simulated Defects}\n\nThe empirical null filter was tested to see if it can assist in detecting simulated defects from an image with/without contamination. A defect assigns pixels to have a value not distributed under the null distribution, but instead, under an alternative, or non-null, distribution. For example, suppose $Z_{x,y}|H_{0,x,y}\\sim\\normal(0,1)$, then a defect assign certain pixels to have a value distributed as $Z_{x,y}|H_{1,x,y}\\sim\\normal(\\mu_{1},1)$ where $\\mu_1\\neq0$.\n\nTo recap, contamination is the result of a linear transform of the test statistics $Z_{x,y}$. For example, in this experiment, the image was multiplied by 2 and a gradient was added to it. The resulting null and alternative distributions are\n\\begin{align}\n  Z_{x,y}|H_{0,x,y}&\\sim\\normal(\\mu_{0,x,y},2^2)\n  \\\\\n  Z_{x,y}|H_{1,x,y}&\\sim\\normal(2\\mu_1+\\mu_{0,x,y},2^2)\n\\end{align}\nrespectively where $\\mu_{0,x,y}=0.01(x-x_0)+0.01(y-y_0)$ and $(x_0,y_0)$ is the centre of the image. This was used in this experiment to simulate a contaminated image with defects.\n\nThe empirical null filter aims to estimate the null distribution parameters from $Z_{x,y}$ to normalise it to form $T_{x,y}$. By normalising it, $T_{x,y}|H_{0,x,y}$ should be approximately standard Normal and hypotheses testing can be used to detect defects.\n\nVarious defects were investigated. Speckle defect with density $\\pi_1$ assign all test statistics to be non-null with probability $\\pi_1$ and are null otherwise. This was chosen because the proportion of null statistics captured by the kernel should be the same for all kernel radiuses. A line defect assigns columns of pixels to be non-null, a kernel would only capture a section of the defect. A square defect was also investigated and a kernel can capture the entire defect only if its radius is large enough.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_imageClean.eps}\n        \\caption{Uncontaminated}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_imageContaminated.eps}\n        \\caption{Contaminated}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_EmpiricalNullFilterimageFiltered.eps}\n        \\caption{Filtered}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_EmpiricalNullFilternullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{A $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$ Gaussian image with speckle defect is shown in a). The image was contaminated in b) and then filtered with kernel radius \\SI{20}{\\pixel} in c). Non-null pixels have the distribution $\\normal(3,1)$. The speckle defect has density $\\pi_1 = 0.1$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. In a), c) and d), highlighted in red are pixels tested as positive at the 5\\% FDR level.}\n  \\label{fig:inference_defectDustExample}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_imageClean.eps}\n        \\caption{Uncontaminated}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_imageContaminated.eps}\n        \\caption{Contaminated}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_EmpiricalNullFilterimageFiltered.eps}\n        \\caption{Filtered}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_EmpiricalNullFilternullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{A $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$ Gaussian image with a line defect is shown in a). The image was contaminated in b) and then filtered with kernel radius \\SI{20}{\\pixel} in c). Non-null pixels have the distribution $\\normal(3,1)$. The line defect is \\SI{5}{\\pixel} thick. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. In a), c) and d), highlighted in red are pixels tested as positive at the 5\\% FDR level.}\n  \\label{fig:inference_defectLineExample}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_imageClean.eps}\n        \\caption{Uncontaminated}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_imageContaminated.eps}\n        \\caption{Contaminated}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_EmpiricalNullFilterimageFiltered.eps}\n        \\caption{Filtered}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_EmpiricalNullFilternullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n    }\n  \\caption{A $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$ Gaussian image with a square defect is shown in a). The image was contaminated in b) and then filtered with kernel radius \\SI{20}{\\pixel} in c). Non-null pixels have the distribution $\\normal(3,1)$. The square defect is $\\SI{30}{\\pixel}\\times \\SI{30}{\\pixel}$ in size. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. In a) and c), highlighted in red are pixels tested as positive at the 5\\% FDR level.}\n  \\label{fig:inference_defectSquareExample}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_imageClean.eps}\n        \\caption{Uncontaminated}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_imageContaminated.eps}\n        \\caption{Contaminated}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_EmpiricalNullFilterimageFiltered.eps}\n        \\caption{Filtered}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_EmpiricalNullFilternullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n    }\n  \\caption{A $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$ Gaussian image with a square defect is shown in a). The image was contaminated in b) and then filtered with kernel radius \\SI{40}{\\pixel} in c). Non-null pixels have the distribution $\\normal(3,1)$. The square defect is $\\SI{30}{\\pixel}\\times \\SI{30}{\\pixel}$ in size. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. In a) and c), highlighted in red are pixels tested as positive at the 5\\% FDR level.}\n  \\label{fig:inference_defectSquare2Example}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_EmpiricalNullFilterpValueFiltered.eps}\n        \\caption{Speckle defect, $r=\\SI{20}{\\pixel}$}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_EmpiricalNullFilterpValueFiltered.eps}\n        \\caption{Line defect, $r=\\SI{20}{\\pixel}$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_EmpiricalNullFilterpValueFiltered}\n        \\caption{Square defect, $r=\\SI{20}{\\pixel}$}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_EmpiricalNullFilterpValueFiltered}\n        \\caption{Square defect, $r=\\SI{40}{\\pixel}$}\n      \\end{subfigure}\n    }\n  \\caption{A $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$ contamined defected Gaussian image was filtered using the empirical null filter with kernel radius $r$. Shown are the $p$-values converted from the filtered images. Non-null pixels have the distribution $\\normal(3,1)$. The speckle defect has density $\\pi_1=0.1$. The line defect is \\SI{5}{\\pixel} thick. The square defect is $\\SI{30}{\\pixel}\\times \\SI{30}{\\pixel}$ in size. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The critical region corresponds to the 5\\% FDR level. The dotted lines shows the $p$-values if they were uniformly distributed.}\n  \\label{fig:inference_defectExamplePValue}\n\\end{figure}\n\nAn example of a speckle defected image is shown in Figure \\ref{fig:inference_defectDustExample}, the figure also shows the image contaminated and then filtered. Without filtering, the top-left and bottom-right of the contaminated image have large, in magnitude, test statistics. In these areas, a lot of pixels would be tested as falsely positive. By using the empirical null filter, the resulting filtered image reassemble the uncontaminated image and appropriate inference can be done on the filtered image. However, some statistical power was lost when conducting hypotheses testing on the filtered image because, in areas of high empirical null standard deviation, the normalised statistics became too small which then decreased the detection power. This cannot be avoided as areas of high empirical null standard deviation was due to the randomness in sampling. Similar comments can be made for the line defect as shown in Figure \\ref{fig:inference_defectLineExample}.\n\nThe square defected images, including the contaminated ones, are shown in Figures \\ref{fig:inference_defectSquareExample} and \\ref{fig:inference_defectSquare2Example}. Figure \\ref{fig:inference_defectSquareExample} filtered the contaminated image using a kernel radius of $r=\\SI{20}{\\pixel}$, while Figure \\ref{fig:inference_defectSquare2Example} used a kernel radius of $r=\\SI{40}{\\pixel}$. With $r=\\SI{20}{\\pixel}$, the kernel is smaller than the square defect, therefore, the defect was treated as the null. This is evident because the empirical null mean captured the defect. This resulted in difficulty detecting the defect. With $r=\\SI{40}{\\pixel}$, the kernel is bigger than the defect and treated the defect as non-null. In this scenario, the empirical null filter recovered the gradient in the empirical null which was then used for normalisation.\n\nThe empirical null mean in Figure \\ref{fig:inference_defectSquareExample} demonstrated the multi-thread nature of the implementation of the empirical null filter. It can be seen that there were horizontal streaks where the defect is. This is the result of each thread filtering a row and jumping from one mode, the null, to the other, the non-null, at different times. The horizontal streaks can be removed by using more initial values so that the Newton-Raphson method can pinpoint which mode is greater. However, this would be at a computational cost.\n\nFigure \\ref{fig:inference_defectExamplePValue} shows the $p$-values after filtering a contaminated defected image. The FDR can be estimated in these figures by dividing the number of null statistics in the critical region by the number of statistics in the critical region. With a sensible kernel radius, some of the defects can be detected. False negatives are common but this is inevitable to control for the FDR. The figure shows that using a kernel radius of $r=\\SI{20}{\\pixel}$, for the square defect, failed to capture the defect. This, again, emphasise the importance of a good kernel radius.\n\nThe receiver operating characteristic (ROC) curves \\citep{green1966signal, metz1978basic, hanley1982meaning, friedman2001elements, cook2007use} are shown in Figure \\ref{fig:inference_defectSimulationRoc} for the various defects and filters. The ROC curve is a parametric plot, plotting the true positive rate (sensitivity) against the false positive rate ($1-\\text{specificity}$) for varying thresholds. The area under the ROC curve (AUC) is a commonly used statistic to quantify the performance of the test \\citep{friedman2001elements}. Interpretations of the area do exist \\citep{metz1978basic,hanley1982meaning} and discussed thoroughly in \\cite{cook2007use}.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleDust_roc.eps}\n        \\caption{Speckle defect, $r=\\SI{20}{\\pixel}$}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleLine_roc.eps}\n        \\caption{Line defect, $r=\\SI{20}{\\pixel}$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare20_roc.eps}\n        \\caption{Square defect, $r=\\SI{20}{\\pixel}$}\n        \\label{fig:inference_defectSimulationRoc_square20}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectExampleSquare40_roc.eps}\n        \\caption{Square defect, $r=\\SI{40}{\\pixel}$}\n      \\end{subfigure}\n    }\n  \\caption{ROC curves for various defected $\\SI{256}{\\pixel}\\times \\SI{256}{\\pixel}$ Gaussian images. The upper/lower dot-dashed lines show the resulting ROC curve when testing on an image without/with contamination respectively. The different curves are the resulting ROC curves after filtering a contaminated image. The speckle defect has density $\\pi_1=0.1$. The line defect is \\SI{5}{\\pixel} thick. The square defect is $\\SI{30}{\\pixel}\\times \\SI{30}{\\pixel}$ in size. Defected pixels have the distribution $\\normal(3,1)$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$.}\n  \\label{fig:inference_defectSimulationRoc}\n\\end{figure}\n\nIn terms of the AUC, the empirical null filter improved the performance of hypotheses testing compared with using the unfiltered contaminated image. The performance before contamination cannot be recovered but it was an improvement. For kernel radiuses too small, such as Figure \\ref{fig:inference_defectSimulationRoc_square20}, the empirical null filter deteriorated the performance and it would be better off using the contaminated image.\n\n\\subsection{Speckle Defect Experiment}\n\nThe ROC curves consider all thresholds or specificities used in the hypotheses testing. In the previous experiment, it was found that the variance of the test statistics was different before and after filtering. As a result, for a given threshold, such as the 5\\% FDR level, the specificity may change ever so slightly after filtering.\n\nAn experiment was conducted to investigate how filtering affects hypotheses testing. A $\\SI{256}{\\pixel}\\times \\SI{256}{\\pixel}$ Gaussian image with speckle defect, with density $\\pi_1=0.1$, and various values of $\\mu_1$ were investigated. The AUC, type 1 error, type 2 error and FDR were measured when testing on an image with a defect before and after contamination and then after filtering with the contamination. The AUC was obtained by integrating the ROC curve. A kernel radius of $r=\\SI{20}{\\pixel}$ was used and was repeated 100 times by simulating another image.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectAltDustEmpirical_roc.eps}\n        \\caption{AUC}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectAltDustEmpirical_type1.eps}\n        \\caption{Type 1 error}\n        \\label{fig:inference_DefectSimulationDust_type1}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectAltDustEmpirical_type2.eps}\n        \\caption{Type 2 error}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectAltDustEmpirical_fdr.eps}\n        \\caption{FDR}\n        \\label{fig:inference_DefectSimulationDust_fdr}\n      \\end{subfigure}\n    }\n  \\caption{AUC and various errors obtained when conducting hypotheses testing on an empirical null filtered contaminated speckle defected Gaussian image of size $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$. In a), the upper/lower dot-dashed lines shows the resulting mean AUC when testing on a defected image before/after contamination respectively. In b), c) and d), the dashed lines show the 95\\% empirical confidence interval of the resulting error when testing the defected image before contamination. The filter used a kernel radius of \\SI{20}{\\pixel}. Defected pixels have the distribution $\\normal(\\mu_1,1)$ where $\\mu_1$ was varied in this experiment. The speckle defect has density $\\pi_1 = 0.1$. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The test was done at the 5\\% FDR level. The boxplots summarise the 100 repeated simulations of the image.}\n  \\label{fig:inference_DefectSimulationDust}\n\\end{figure}\n\nThe results are shown in Figure \\ref{fig:inference_DefectSimulationDust}. The AUC quantified showed that using the filter improved the performance of the test from the contamination. The type 1 error, or specificity, did decrease after filtering. However, the results illustrated that the FDR is controlled quite well at around 5\\% after filtering. This meant that in this particular example, FDR control is consistent after filtering. At situations with low detection power, the FDR can fluctuate between 0 and 1 and can take only so many values. For example, if 3 positive pixels were detected, then the FDR can only take values of multiples of $1/3$ between and including 0 and 1.\n\n\\subsection{Optimal Kernel Radius Experiment}\n\nThere is the question of what kernel radius to choose for a given defect. Literature, such as \\cite{efron2004large} and \\cite{schwartzman2008empirical}, suggest that, as a rule of thumb, the proportion of non-null statistics should not be larger than $\\pi_1=0.1$ to satisfy some assumptions made for the empirical null. Given the size of the defect, one could work out the minimum kernel radius by setting a threshold for the maximum proportion of the area of the kernel which contains a defect to 10\\%. In other words, for a kernel with radius $r$\n\\begin{equation}\n0.1 > \\dfrac{\\text{maximum area of defect captured by the kernel}}{\\text{area of kernel}} \\ .\n\\end{equation}\nFor a $d \\times d$ square defect, this is $r > d \\sqrt{10/\\pi}$.\nIn the example of $d=\\SI{30}{\\pixel}$, this is about $r>\\SI{54}{\\pixel}$. For the line defect with thickness $\\SI{5}{\\pixel}$, the radius is about $r>\\SI{32}{\\pixel}$. These are rules of thumb because the kernel is not perfectly circular when used on a grid of pixels. It should be pointed out that the implementation can accept non-integer radiuses if desired.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusLine_roc.eps}\n        \\caption{AUC}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusLine_type1.eps}\n        \\caption{Type 1 error}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusLine_type2.eps}\n        \\caption{Type 2 error}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusLine_fdr.eps}\n        \\caption{FDR}\n      \\end{subfigure}\n    }\n  \\caption{AUC and various errors obtained when conducting hypotheses testing on a filtered contaminated line defected Gaussian image, of size $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$, using various kernel radiuses. The dashed lines show the resulting 95\\% empirical confidence interval when the hypotheses testing was done on the uncontaminated defected image. Defected pixels have the distribution $\\normal(3,1)$. The line defect is \\SI{5}{\\pixel} thick. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The test was done at the 5\\% FDR level. The boxplots summarise the 100 repeated simulations of the image.}\n  \\label{fig:inference_Experiment_DefectRadiusLine}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusSquare_roc.eps}\n        \\caption{AUC}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusSquare_type1.eps}\n        \\caption{Type 1 error}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusSquare_type2.eps}\n        \\caption{Type 2 error}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectRadiusSquare_fdr.eps}\n        \\caption{FDR}\n      \\end{subfigure}\n    }\n  \\caption{AUC and various errors obtained when conducting hypotheses testing on a filtered contaminated square defected Gaussian image, of size $\\SI{256}{\\pixel} \\times \\SI{256}{\\pixel}$, using various kernel radiuses. The dashed lines show the resulting 95\\% empirical confidence interval when the hypotheses testing was done on the uncontaminated defected image. Defected pixels have the distribution $\\normal(3,1)$. The square defect is $\\SI{30}{\\pixel}\\times \\SI{30}{\\pixel}$ pixels in size. The contamination was such that the null distribution is $Z_{x,y}|H_{0,x,y}\\sim\\normal(\\mu_{0,x,y},\\sigma_0^2)$ where $\\mu_{0,x,y} = 0.01 (x-x_0) + 0.01 (y-y_0)$ and $\\sigma_0=2$. The test was done at the 5\\% FDR level. The boxplots summarise the 100 repeated simulations of the image.}\n  \\label{fig:inference_Experiment_DefectRadiusSquare}\n\\end{figure}\n\nAn experiment was conducted where a contaminated defected Gaussian image, of size $\\SI{256}{\\pixel}\\times\\SI{256}{\\pixel}$, was filtered using various kernel radiuses for a fixed alternative distribution $\\normal(3,1)$. Hypotheses testing was done on the uncontaminated defected and filtered contaminated defected images. The AUC and various errors were recorded. This was repeated 100 times by simulating the image again. The AUC was obtained by integrating the ROC curve. The results of the uncontaminated defected image were all pooled together to obtain the empirical distribution of the AUC and errors without contamination. Results for the line and square defect are shown in Figures \\ref{fig:inference_Experiment_DefectRadiusLine} and \\ref{fig:inference_Experiment_DefectRadiusSquare} respectively.\n\nThe results showed that the AUC increased with kernel radius. This highlighted that a kernel with a good radius can perform almost as though there was no contamination. It also appeared that the optimal AUC was achieved when using the kernel radius from the rule of thumb, making these results consistent with the literature.\n\nFor large enough kernel radius, the FDR was controlled at around 5\\%. It appeared that a large kernel radius helped preserve FDR control after filtering in these examples. It was observed that there exist a kernel radius which minimised the type 2 error. So a large kernel radius is required for FDR control but too large can lose statistical power. It was noticed that filtering using large kernel radiuses is computationally slower.\n\n\\afterpage{\\clearpage}\n\\subsection{Application to Real Projections}\n\nThe empirical null filter was applied to the \\texttt{AbsFilter} projection at \\ang{120}. Figures \\ref{fig:inference_AbsFilterDeg120_inference_radius1} and \\ref{fig:inference_AbsFilterDeg120_inference_radius4} shows the resulting inference when using a kernel radius of $r=\\addNumber{../figures/inference/DefectDetectAbsFilterDeg120_radius1.txt}\\,\\SI{}{\\pixel}$ and $r=\\addNumber{../figures/inference/DefectDetectAbsFilterDeg120_radius4.txt}\\,\\SI{}{\\pixel}$ respectively. With a small radius, the empirical null treated the voids as the null which is shown by the empirical null mean capturing the features of the voids. When a large enough radius was used, the larger voids were highlighted by the hypotheses test and the empirical null mean became smoother. This is evidence that this method ironed out false positives observed at the start of the chapter.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius1_sig.eps}\n        \\caption{Obtained projection (\\SI{}{\\adu})}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius1_logp.eps}\n        \\caption{$-\\log p$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius1_nullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius1_nullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{Resulting inference when using the empirical null filter on the \\texttt{AbsFilter} projection at \\ang{120}. A kernel radius of $r=\\addNumber{../figures/inference/DefectDetectAbsFilterDeg120_radius1.txt}\\,\\SI{}{\\pixel}$ was used. a) Highlighted in red are positive pixels at the 5\\% FDR level. b) $p$-values on the log scale. c) and d) Empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_AbsFilterDeg120_inference_radius1}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius4_sig.eps}\n        \\caption{{Obtained projection (\\SI{}{\\adu})}}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius4_logp.eps}\n        \\caption{$-\\log p$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius4_nullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectAbsFilterDeg120_radius4_nullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{Resulting inference when using the empirical null filter on the \\texttt{AbsFilter} projection at \\ang{120}. A kernel radius of $r=\\addNumber{../figures/inference/DefectDetectAbsFilterDeg120_radius4.txt}\\,\\SI{}{\\pixel}$ was used. a) Highlighted in red are positive pixels at the 5\\% FDR level. b) $p$-values on the log scale. c) and d) Empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_AbsFilterDeg120_inference_radius4}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/cornerSelect.eps}\n      \\caption{$z$ image with section highlighted}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/inference/cornerSelectHist.eps}\n      \\caption{Histogram of $z$ in the kernel}\n    \\end{subfigure}\n  }\n  \\caption{A section of the bottom right of an unfiltered $z$ image is shown in a). The $z$ statistics in it are shown as a histogram in b) and indicates a bimodal distribution.}\n  \\label{fig:inference_cornerSelect}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\subSize]{../figures/inference/segment.eps}\n  \\caption{The $z$ image was segmented further into 7 segments shown by the dotted red lines.}\n  \\label{fig:inference_segmentFurther}\n\\end{figure}\n\nFalse positives were detected on the bottom right of the test sample. When placing the kernel on the bottom right corner, the null distribution is bimodal because each face has a different distribution. Figure \\ref{fig:inference_cornerSelect} illustrates this. The geometry of the faces and the kernel used was such that it resulted in one of the faces to be treated as non-null and then tested positive, falsely so.\n\nThe false positives were tackled by manually segmenting the image further as shown in Figure \\ref{fig:inference_segmentFurther}. It was segmented using the edges of the $z$ image. The empirical null filter was then used on each segment, or ROI, independently, ignoring any pixels outside the ROI the filter is working on. The resulting filtered segments were stitched together to form the resulting filtered image. By using this method, the resulting inference is shown in Figure \\ref{fig:inference_subroiAbsFilterDeg120_inference_radius4}. It can be seen that the empirical null mean did change face to face, resulting in a clear boundary set by the edges. Most of the false positives around the corners and edges have been eliminated.\n\nThe same procedure was done on the projection at \\ang{30}, as shown in Figure \\ref{fig:inference_subroiAbsFilterDeg30_inference_radius1}, with similar results.\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg120_radius4_sig.eps}\n        \\caption{{Obtained projection (\\SI{}{\\adu})}}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg120_radius4_logp.eps}\n        \\caption{$-\\log p$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg120_radius4_nullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg120_radius4_nullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{Resulting inference when using the empirical null filter on the \\texttt{AbsFilter} projection at \\ang{120} and on each segment independently. A kernel radius of $r=\\addNumber{../figures/inference/DefectDetectSubRoiAbsFilterDeg120_radius4.txt}\\,\\SI{}{\\pixel}$ was used. a) Highlighted in red are positive pixels at the 5\\% FDR level. The test statistics from all segments were combined in the BH procedure. b) $p$-values on the log scale. c) and d) Empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_subroiAbsFilterDeg120_inference_radius4}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n    \\centerline{\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg30_radius1_sig.eps}\n        \\caption{{Obtained projection (\\SI{}{\\adu})}}\n      \\end{subfigure}\n      \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg30_radius1_logp.eps}\n        \\caption{$-\\log p$}\n      \\end{subfigure}\n    }\n    \\centerline{\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg30_radius1_nullMean.eps}\n        \\caption{Empirical null mean}\n      \\end{subfigure}\n      \\begin{subfigure}{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/inference/DefectDetectSubRoiAbsFilterDeg30_radius1_nullStd.eps}\n        \\caption{Empirical null std}\n      \\end{subfigure}\n    }\n  \\caption{Resulting inference when using the empirical null filter on the \\texttt{AbsFilter} projection at \\ang{30} and on each segment independently. A kernel radius of $r=\\addNumber{../figures/inference/DefectDetectSubRoiAbsFilterDeg30_radius1.txt}\\,\\SI{}{\\pixel}$ was used. a) Highlighted in red are positive pixels at the 5\\% FDR level. The test statistics from all segments were combined in the BH procedure. b) $p$-values on the log scale. c) and d) Empirical null mean and empirical null standard deviation.}\n  \\label{fig:inference_subroiAbsFilterDeg30_inference_radius1}\n\\end{figure}\n\n\\section{Conclusion}\n\nThe empirical null filter demonstrated that it can adjust the null hypotheses according to the data to make a sensible inference. In the simulations, it was found that the FDR level is preserved after filtering. Also, the empirical null filter outperformed other methods based on quantiles, as suggested by \\cite{efron2004large}. A sensible kernel radius is required to avoid treating defects as the null.\n\nIn the experiment, the larger voids of diameter \\SI{2.4}{\\milli\\metre} were detected in the test sample. False positives do occur but this is unavoidable because tests were done at the 5\\% FDR level. Typically in the experiments, false positives were isolated single pixels and probably occurred due to random chance. Clusters of positive pixels should raise suspicion so it would be a good idea to borrow strength from neighbouring pixels. For example, one could create a binary image, assigning a Boolean value whether that pixel was tested positive or not. A binary image filter, such as erode followed by a dilate, can be used to remove isolated positive pixels to emphasise the cluster of positive pixels.\n\nThe assessment of the inference could be improved if the location of the defects were known in the projections. This would allow identifying which positives are true and false positives so that the analysis can be quantified using a ROC curve.\n\nFor good results, the faces of the test sample were segmented. This was necessary because the empirical null filter assumes that the null parameters varied spatially smoothly and slowly. Manual segmentation was easy to do because a cuboid has 6 faces. However, segmentation of faces cannot be generalised well to AM samples with complicated geometry and curved surfaces. Automatic segmentation may be possible with geometrical information from the CAD model.\n\nThe main issue with implementing this method onto the production line was how slow the filter was. The main bottleneck is the evaluation of the density estimate. Each step in the Newton-Raphson required the evaluation of $\\pi r^2$ data points. As a result, increasing the kernel radius slows down the filter. There may be faster methods for density estimation such as fitting a smoothing spline on the histogram \\citep{efron2004large}, however, that would require tuning the histogram bins as well as the tuning parameters for the spline. On the other hand, the method in \\cite{schwartzman2008empirical}, which uses the histogram count, found that the estimation of the null parameters was insensitive to the histogram binning.\n\nThere are a few strategies to accelerate the filter. The empirical null filter may be accelerated using GPUs \\citep{yang2008parallel, hwu2011gpu, eklund2013medical}, however, efforts to implement the filter in \\emph{CUDA} and \\emph{C++} is fruitless if there may exist a faster method. Instead, accuracy may be sacrificed for speed by only estimating the null parameters for several regularly spaced pixels, the remaining pixels are interpolated. This requires the null parameters to be slowly varying, otherwise, the interpolation may underfit. This may cause problems because of the face to face transition observed in the experiments. It was found that if a bad solution was found for a point, then that solution would spread its bad solution to neighbouring pixels due to the interpolation.\n\nEstimation of the null parameters is essentially robust statistics, estimating the parameters of the null distribution without being affected by non-null statistics. Potential faster methods compared to the empirical null could exist in the literature for robust statistics such as \\cite{hampel1986robust, rousseeuw1987robust, maronna2006robust, huber2009robust, jewson2018principles}. The use of density estimation for robust estimation is also featured when using loss functions derived from the Hellinger-divergence \\citep{beran1977minimum, jewson2018principles} or the beta-divergence \\citep{basu1998robust, jewson2018principles} which bears similarities to the empirical null. However, numerical methods are still required to find the mode. Exact estimation of the mode using Bayesian methods is impossible \\citep{heinrich2013the} which suggest avoiding the use of numerical methods can be difficult.\n\nThe EM algorithm \\citep{dempster1977maximum} could be used to fit a mixture of Gaussians to identify the null distribution and estimate its parameters. However, the power of hypothesis testing and the empirical null comes from the fact that the alternative distribution does not need to be specified.\n", "meta": {"hexsha": "a7c4cb38fec176fa1a89a5ca0c1a11a996e43491", "size": 123639, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/thesis/chapters/5_inference.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/5_inference.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/5_inference.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": 65.3828662084, "max_line_length": 1251, "alphanum_fraction": 0.7384805765, "num_tokens": 33238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6413016920764267}}
{"text": "\\subsection{Functors}\\label{subsec:functors}\n\n\\begin{definition}\\label{def:functor}\\mcite[def. 1.2.1 \\\\ def. 1.2.10]{Leinster2016Basic}\n  Fix some \\hyperref[def:category]{categories} \\( \\cat{C} \\) and \\( \\cat{D} \\). A \\term{functor} \\( F: \\cat{C} \\to \\cat{D} \\) is a \\hyperref[eq:def:category_of_small_quivers/homomorphism]{quiver homomorphism} between the underlying quivers that is compatible with composition and identities.\n\n  Explicitly, a functor is a family of functions\n  \\begin{equation}\\label{eq:def:functor_as_family_of_function}\n    \\begin{aligned}\n      F_{\\obj}:       &\\obj(\\cat{C}) \\to \\obj(\\cat{D}) \\\\\n      F_{\\hom(A, B)}: &\\cat{C}(A, B) \\to \\cat{D}(F_{\\obj}(A), F_{\\obj}(B)),\n    \\end{aligned}\n  \\end{equation}\n  where \\( F_{\\hom(A, B)} \\) is a distinct function for every pair of objects \\( A \\) and \\( B \\).\n\n  In practice, we usually define the functor as the set\n  \\begin{equation}\\label{eq:def:functor_as_single_function}\n    F \\coloneqq F_{\\obj} \\cup \\bigcup\\set{ F_{\\hom(A, B)} \\given A, B \\in \\obj(\\cat{C}) }\n  \\end{equation}\n\n  Since the domains of all constituent functions are disjoint, \\( F \\) is again a total single-valued function. This allows us to justify the notation \\( F(A) \\) for objects and \\( F(f) \\) for morphisms.\n\n  \\begin{thmenum}[resume=def:functor]\n    \\thmitem{def:functor/domain_and_codomain} We say that the category \\( \\cat{C} \\) is the \\term{domain} and \\( \\cat{D} \\) --- the \\term{codomain} of the functor \\( F \\). These are technically not the domain and codomain of \\( F \\) when regarded as a function, however it is consistent with \\fullref{def:category_of_small_categories}.\n\n    \\thmitem{def:functor/endofunctor} Similarly to \\fullref{def:multi_valued_function/endofunction} for functions, if the domain \\( \\cat{C} \\) and codomain \\( \\cat{D} \\) of a functor coincide, we say that it is an \\term{endofunctor}.\n  \\end{thmenum}\n\n  The definition of a functor additionally requires the following compatibility conditions to hold:\n  \\begin{thmenum}[series=def:functor]\n    \\thmitem[def:functor/CF1]{CF1} Functors must preserve identities, meaning that for any object \\( A \\in \\cat{C} \\) the following equality must hold:\n    \\begin{equation}\\label{eq:def:functor/CF1}\\tag{\\logic{CF1}}\n      F(\\id_A) = \\id_{F(A)}.\n    \\end{equation}\n\n    \\thmitem[def:functor/CF2]{CF2} Functors must preserve composition, meaning that for any pair of morphism \\( f: A \\to B \\) and \\( g: B \\to C \\) in \\( \\cat{C} \\),\n    \\begin{equation}\\label{eq:def:functor/CF2}\\tag{\\logic{CF2}}\n      F(g \\bincirc f) = F(g) \\bincirc F(f).\n    \\end{equation}\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  The definition \\eqref{eq:def:functor_as_family_of_function} ensures that the quiver homomorphism conditions \\eqref{eq:def:category_of_small_quivers/homomorphism/head} and \\eqref{eq:def:category_of_small_quivers/homomorphism/tail} hold.\n\n  Indeed, for any morphism \\( f: A \\to B \\) in \\( \\cat{C} \\) we have\n  \\begin{equation*}\n    F(\\dom(f)) = F(A) = \\dom(F(f)),\n  \\end{equation*}\n  which implies \\eqref{eq:def:category_of_small_quivers/homomorphism/head}. We also have\n  \\begin{equation*}\n    F(\\co\\dom(f)) = F(B) = \\co\\dom(F(f)),\n  \\end{equation*}\n  which implies \\eqref{eq:def:category_of_small_quivers/homomorphism/tail}.\n\\end{defproof}\n\n\\begin{remark}\\label{rem:functor_size}\n  It is possible that \\( \\cat{C} \\) is \\( \\mscrU \\)-small in the sense of \\fullref{def:category_size}, but the \\hyperref[def:functor]{functor} \\( F \\), as the set \\eqref{eq:def:functor_as_single_function}, is not \\( \\mscrU \\)-small in the sense of \\fullref{def:large_and_small_sets}. Without using universes, we cannot prove the existence of any functor from the category of smalls sets to itself, for example.\n\\end{remark}\n\n\\begin{example}\\label{ex:unary_functors_in_set}\n  In \\fullref{def:basic_set_operations}, we defined some operations on the category \\hyperref[def:category_of_small_sets]{\\( \\cat{Set} \\)} of small sets.\n\n  \\begin{thmenum}\n    \\thmitem{ex:unary_functors_in_set/power} The \\hyperref[def:basic_set_operations/power_set]{power set} \\( \\pow: \\cat{Set} \\to \\cat{Set} \\) is a canonical example of an \\hyperref[def:functor/endofunctor]{endofunctor}. Explicitly:\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\pow: \\cat{Set} \\to \\cat{Set}, \\\\\n        &\\pow(A) \\coloneqq \\set{ S \\given S \\subseteq A }, \\\\\n        &\\pow(f: A \\to B) \\coloneqq (S \\mapsto f[S]). \\\\\n      \\end{aligned}\n    \\end{equation*}\n\n    We must verify that it is indeed a functor. \\ref{def:functor/CF2} is satisfied because\n    \\begin{equation*}\n      \\pow(g) \\bincirc \\pow(f) = (S \\mapsto g[f[S]]) = \\pow(g \\bincirc f).\n    \\end{equation*}\n\n    The condition \\ref{def:functor/CF2} is also obviously satisfied.\n\n    The nuance here is that we send every function \\( f: A \\to B \\) to its \\hyperref[def:multi_valued_function/set_value]{set value} \\( f[S] \\) of some subset \\( S \\) of \\( A \\).\n\n    \\thmitem{ex:unary_functors_in_set/union} The \\hyperref[def:basic_set_operations/union]{union} \\( \\bigcup \\) and \\hyperref[def:basic_set_operations/intersection]{intersection} \\( \\bigcap \\) may seem to be good examples of endofunctors in \\( \\cat{Set} \\). Unfortunately, there is no natural way to extend a morphism (function) \\( f: A \\to B \\) to a morphism from \\( \\bigcup A \\) to \\( \\bigcup B \\) or \\( \\bigcap A \\) to \\( \\bigcap B \\).\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:subcategory}\\mcite[def. 1.2.18]{Leinster2016Basic}\n  We call the category \\( \\cat{D} \\) a \\term{subcategory} of \\( \\cat{C} \\) if the following hold:\n  \\begin{itemize}\n    \\item The underlying quiver \\( U(\\cat{D}) \\) is a \\hyperref[def:quiver/submodel]{subquiver} of \\( U(\\cat{C}) \\). That is, every object in \\( \\cat{D} \\) is an object in \\( \\cat{C} \\) and every morphism in \\( \\cat{D} \\) is a morphism in \\( \\cat{C} \\).\n    \\item Composition and identity in \\( \\cat{D} \\) are \\hyperref[def:multi_valued_function/restriction]{restrictions} of composition and identity in \\( \\cat{C} \\).\n  \\end{itemize}\n\n  \\begin{thmenum}\n    \\thmitem{def:subcategory/inclusion} For every subcategory there exists an \\term{inclusion functor} \\( \\Iota: \\cat{D} \\to \\cat{C} \\), which sends every object and morphism of \\( \\cat{D} \\) to itself in \\( \\cat{C} \\).\n\n    \\thmitem{def:subcategory/full} We say that \\( \\cat{D} \\) is a \\term{full subcategory} if the underlying quiver \\( U(\\cat{C}) \\) is a \\hyperref[def:quiver/submodel]{full subquiver}. That is, in case \\( \\cat{D}(A, B) = \\cat{C}(A, B) \\) for every pair of objects \\( A \\) and \\( B \\) of \\( \\cat{D} \\).\n\n    By \\fullref{thm:def:functor_invertibility/properties/full_subcategory}, this is equivalent to the inclusion functor being \\hyperref[def:functor_invertibility/full]{full}.\n\n    \\thmitem{def:subcategory/induced} Every \\hyperref[rem:family_of_sets]{family} \\( \\mscrD \\) of objects in \\( \\cat{C} \\) induces a full subcategory \\( \\cat{D} \\) of \\( \\cat{C} \\), whose objects are those of \\( \\mscrD \\) and whose morphisms are restricted to those whose domain and codomain are both in \\( \\mscrD \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:contravariant_functor}\\mcite[def. 1.2.10]{Leinster2016Basic}\n  We can invert the order of composition in \\ref{def:functor/CF2} in the definition of a functor given in \\fullref{def:functor}.\n  \\begin{thmenum}\n    \\thmitem[rem:contravariant_functor/CF2]{CF2\\Textprime} We can replace \\ref{def:functor/CF2} with\n    \\begin{equation}\\label{eq:rem:contravariant_functor/CF2}\\tag{\\logic{CF2\\Textprime}}\n      F(g \\bincirc f) = F(f) \\bincirc F(g).\n    \\end{equation}\n  \\end{thmenum}\n\n  This also requires some other straightforward modifications to the definition of a functor.\n\n  A functor that satisfies \\ref{rem:contravariant_functor/CF2} rather than \\ref{def:functor/CF2} is called \\term{contravariant}. In this context, a functor satisfying \\ref{def:functor/CF2} is called \\term{covariant}.\n\n  Fortunately, a contravariant functor from \\( \\cat{C}^{\\opcat} \\) to \\( \\cat{D} \\) is identical to a covariant functor from \\( \\cat{C} \\) to \\( \\cat{D} \\). Therefore, there is no formal difference between the two concepts.\n\n  The usage of the terms are entirely dictated by context. Unless necessary, we will avoid speaking about contravariant functors to avoid confusion. Some examples where this terminology may be useful are \\fullref{def:dual_functor}, \\fullref{def:hom_functor/unary} and \\fullref{ex:dual_space_contravariant_functor}.\n\\end{remark}\n\n\\begin{example}\\label{ex:dual_space_contravariant_functor}\n  We can try to na\\\"ively define a functor that assigns to a \\hyperref[def:vector_space]{vector space} its \\hyperref[def:dual_vector_space]{algebraic dual}:\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: \\cat{Vect_\\BbbK} \\to \\cat{Vect_\\BbbK}, \\\\\n      &F(V) \\coloneqq V^*, \\\\\n      &F(f: V \\to W) \\coloneqq (\\varphi: W \\to \\BbbK \\mapsto \\varphi \\bincirc f).\n    \\end{aligned}\n  \\end{equation*}\n\n  Unfortunately, \\( F(f) \\) is supposed to be a morphism from \\( V^* \\) to \\( W^* \\), but is actually a morphism from \\( W^* \\) to \\( V^* \\). This makes \\( F \\) a \\hyperref[rem:contravariant_functor]{contravariant functor} or, equivalently, a functor from \\( \\cat{Vect_\\BbbK}^{\\opcat} \\) to \\( \\cat{Vect_\\BbbK} \\).\n\\end{example}\n\n\\begin{definition}\\label{def:discrete_category}\n  A \\term{discrete category} is a category with no morphisms except for the identities. Clearly to any set there corresponds exactly one discrete category and vice versa.\n\\end{definition}\n\n\\begin{example}\\label{ex:discrete_category_adjunction}\n  Denote by\n  \\begin{equation*}\n    U: \\cat{Cat} \\to \\cat{Set}\n  \\end{equation*}\n  the forgetful functor that for any small category \\( \\cat{C} \\) gives us its set of objects \\( \\obj(\\cat{C}) \\). There is also a functor\n  \\begin{equation*}\n    D: \\cat{Set} \\to \\cat{Cat}\n  \\end{equation*}\n  that for any small set \\( A \\) gives us the \\hyperref[def:discrete_category]{discrete category} whose set of objects is \\( A \\).\n\n  This is actually an \\hyperref[def:category_adjunction]{adjunction} --- see \\fullref{ex:def:category_adjunction/set_cat}.\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:functor/properties}\n  \\hyperref[def:functor]{Functors} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:functor/properties/half_inverses} Functors preserve inverses. For every functor \\( F: \\cat{C} \\to \\cat{D} \\) and every morphism \\( f: A \\to B \\) in \\( \\cat{C} \\) with a right inverse \\( g: B \\to A \\), \\( F(f) \\) is a right inverse of \\( F(g) \\). Similarly, if \\( g \\) is a left inverse of \\( f \\), then \\( F(g) \\) is a left inverse of \\( F(f) \\).\n\n    \\thmitem{thm:def:functor/properties/inverses} For every functor \\( F: \\cat{C} \\to \\cat{D} \\) and every isomorphism \\( f: A \\to B \\) in \\( \\cat{C} \\),\n    \\begin{equation}\\label{eq:thm:def:functor/properties/inverses}\n      [F(f)]^{-1} = F(f^{-1}).\n    \\end{equation}\n\n    \\thmitem{thm:def:functor/properties/isomorphisms} Functors preserve \\hyperref[def:morphism_invertibility/isomorphism]{isomorphisms}. That is, for every functor \\( F: \\cat{C} \\to \\cat{D} \\), if \\( f: A \\to B \\) is an isomorphism in \\( \\cat{C} \\), \\( F(f) \\) is an isomorphism in \\( \\cat{D} \\).\n\n    Consequently, for every pair of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), from \\( A \\cong B \\) it follows that \\( F(A) \\cong F(B) \\).\n\n    The converse sometimes also holds --- see \\fullref{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:functor/properties/half_inverses} Let \\( f: A \\to B \\) be a right inverse of \\( g: B \\to A \\) in \\( \\cat{C} \\). Then\n  \\begin{equation*}\n    F(g) \\bincirc F(f)\n    \\reloset {\\eqref{eq:def:functor/CF2}} =\n    F(g \\bincirc f)\n    =\n    F(\\id_A)\n    \\reloset {\\eqref{eq:def:functor/CF1}} =\n    \\id_{F(A)}.\n  \\end{equation*}\n\n  Thus, \\( F(f) \\) is a right inverse of \\( F(g) \\). Since \\( g \\) is a left inverse of \\( f \\), automatically \\( F(g) \\) is a left inverse of \\( F(f) \\).\n\n  \\SubProofOf{thm:def:functor/properties/inverses} If \\( f^{-1} \\) is a left inverse of \\( f \\), by \\fullref{thm:def:functor/properties/half_inverses} we have that \\( F(f^{-1}) \\) is a left inverse of \\( F(f) \\). But \\( F(f^{-1}) \\) is also a right inverse, and again by \\fullref{thm:def:functor/properties/half_inverses} \\( F(g) \\) is a right inverse of \\( F(f^{-1}) \\).\n\n  Therefore, \\( F(f^{-1}) \\) is a two-sided inverse of \\( F(f) \\). By \\fullref{thm:def:morphism_invertibility/properties/at_most_one_inverse}, it is the only two-sided inverse, hence\n  \\begin{equation*}\n    [F(f)]^{-1} = F(f^{-1}).\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:functor/properties/isomorphisms} Follows from \\fullref{thm:def:functor/properties/inverses}.\n\\end{proof}\n\n\\begin{definition}\\label{def:category_of_small_categories}\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:category]{categories} by \\( \\ucat{Cat} \\) or, if the universe is clear from the context, simply by \\( \\cat{Cat} \\). 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{Cat}) \\) is the set of all \\( \\mscrU \\)-small categories.\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{Cat}(A, B) \\) from \\( A \\) to \\( B \\) is the set of all \\hyperref[def:functor]{functors} from \\( A \\) to \\( B \\).\n\n    \\item The \\hyperref[def:category/composition]{composition of morphisms} is the \\hyperref[def:multi_valued_function/composition]{function composition} of the functors regarded as the functions \\eqref{eq:def:functor_as_single_function}. That is, the composition of \\( F: \\cat{C} \\to \\cat{D} \\) and \\( G: \\cat{D} \\to \\cat{E} \\) is the functor\n    \\begin{equation}\\label{eq:def:category_of_small_categories/composition}\n      \\begin{aligned}\n        &[G \\bincirc F]: \\cat{C} \\to \\cat{E}, \\\\\n        &[G \\bincirc F](A) \\coloneqq G(F(A)), \\\\\n        &[G \\bincirc F](f) \\coloneqq G(F(f)).\n      \\end{aligned}\n    \\end{equation}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the category \\( \\cat{C} \\) is the \\term{identity functor}\n    \\begin{equation}\\label{eq:def:category_of_small_categories/identity}\n      \\begin{aligned}\n        &\\id_{\\cat{C}}: \\cat{C} \\to \\cat{C}, \\\\\n        &\\id_{\\cat{C}}(A) \\coloneqq A, \\\\\n        &\\id_{\\cat{C}}(f) \\coloneqq f.\n      \\end{aligned}\n    \\end{equation}\n  \\end{itemize}\n\\end{definition}\n\\begin{defproof}\n  To see that \\( \\ucat{Cat} \\) is indeed a category, we verify the conditions \\ref{def:category/C1} and \\ref{def:category/C2}.\n\n  \\SubProofOf{def:category/C1} For every two \\( \\mscrU \\)-small categories \\( \\cat{C} \\) and \\( \\cat{D} \\) and every functor \\( F: \\cat{C} \\to \\cat{D} \\), for every object \\( A \\in \\cat{C} \\) we have\n  \\begin{equation*}\n    [\\id_{\\cat{D}} \\bincirc F](A)\n    =\n    \\id_{\\cat{D}}(F(A))\n    =\n    F(A)\n    =\n    F(\\id_{\\cat{C}}(A))\n    =\n    [F \\bincirc \\id_{\\cat{C}}](A)\n  \\end{equation*}\n  and analogously for morphisms.\n\n  Therefore, \\( \\id_{\\cat{C}} \\) and \\( \\id_{\\cat{D}} \\) satisfy \\eqref{eq:def:category/C1}.\n\n  \\SubProofOf{def:category/C2} Associativity of functor composition is inherited from the associativity of function composition.\n\\end{defproof}\n\n\\begin{definition}\\label{def:universal_categories}\n  For any \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\), the \\hyperref[def:category_of_small_categories]{category of \\( \\mscrU \\)-small categories} \\( \\ucat{Cat} \\) has an initial and a terminal object.\n\n  Similarly to how we use the \\hyperref[def:ordinal]{ordinals} \\( 0 \\) and \\( 1 \\) to denote the initial and terminal object in the category of sets (see \\fullref{ex:def:universal_objects/set}), we denote the initial category by \\( \\cat{0} \\) and the final category by \\( \\cat{1} \\). Note that the final category is only unique up to an isomorphism. They are identical, however, for all universes \\( \\mscrU \\).\n\n  These categories are precisely the \\hyperref[def:discrete_category]{discrete categories} induced by the ordinals \\( 0 \\) and \\( 1 \\) as described in \\fullref{thm:order_category_isomorphism}.\n\\end{definition}\n\n\\begin{definition}\\label{def:dual_functor}\\mcite{nLab:opposite_category}\n  The \\term{opposite} or \\term{dual} functor of \\( F: \\cat{C} \\to \\cat{D} \\) is the functor\n  \\begin{equation*}\n    \\begin{aligned}\n      &F^{\\opcat}: \\cat{C}^{\\opcat} \\to \\cat{D}^{\\opcat} \\\\\n      &F^{\\opcat}(A) \\coloneqq A \\\\\n      &F^{\\opcat}(f^{\\opcat}: B \\to A) \\coloneqq [F(f: A \\to B)]^{\\opcat}.\n    \\end{aligned}\n  \\end{equation*}\n\n  For the composition of functors, we then have\n  \\begin{equation}\\label{eq:def:dual_functor/composition}\n    [G \\bincirc F]^{\\opcat} = G^{\\opcat} \\bincirc F^{\\opcat}.\n  \\end{equation}\n\n  This is somewhat in contrast to the general practice of inverting morphisms when taking duals. Thus, we define, for any \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\), the \\term{oppositization functor}\n  \\begin{equation*}\n    (\\anon*)^{\\opcat}: \\ucat{Cat}^{\\opcat} \\to \\ucat{Cat}.\n  \\end{equation*}\n\n  As an \\hyperref[def:multi_valued_function/endofunction]{endofunction} on \\( \\obj(\\ucat{Cat}) \\), the oppositization functor is clearly an \\hyperref[def:set_with_involution]{involution}.\n\n  Dual functors also arise naturally in \\fullref{thm:dual_functor_category}.\n\\end{definition}\n\n\\begin{definition}\\label{def:functor_image}\n  The \\term{image} of a functor \\( F: \\cat{C} \\to \\cat{D} \\) is the \\hyperref[def:quiver]{quiver} whose vertex set is\n  \\begin{equation*}\n    V \\coloneqq \\set{ F(A) \\given A \\in \\cat{C} }\n  \\end{equation*}\n  and whose arc set is\n  \\begin{equation*}\n    A \\coloneqq \\set{ F(f) \\given A, B \\in \\cat{C} \\T{and} f \\in \\cat{C}(A, B) }.\n  \\end{equation*}\n\n  This quiver has no categorical structure --- it is merely a directed multigraph. As shown in \\fullref{ex:functor_image_not_a_category}, imposing a categorical structure na\\\"ively may fail.\n\\end{definition}\n\n\\begin{example}\\label{ex:functor_image_not_a_category}\\mcite{MathSE:image_of_functor_is_not_a_category}\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=1]{output/ex__functor_image_not_a_category.pdf}\n    \\hfill\n    \\hfill\n    \\caption{A functor whose image is not a category.}\\label{fig:ex:functor_image_not_a_category}\n  \\end{figure}\n\n  Consider the functor \\( F: \\cat{C} \\to \\cat{D} \\) from \\cref{fig:ex:functor_image_not_a_category}.\n\n  \\begin{itemize}\n    \\item The solid arrows are the morphisms in \\( \\cat{C} \\) and their images in \\( F(\\cat{C}) \\).\n    \\item The dashed arrows denote the action of the functor \\( F \\).\n    \\item The dotted arrow exists in \\( \\cat{D} \\) as the composition of the other two arrows, however it is missing in the image \\( F(\\cat{C}) \\). Thus, composition is not fully defined in \\( F(\\cat{C}) \\), and \\( F(\\cat{C}) \\) fails to be a category.\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:categorical_diagram}\n  Fix a category \\( \\cat{I} \\), called an \\term{index category}. A \\term{diagram} in \\( \\cat{C} \\) of shape \\( \\cat{I} \\) is simply a functor \\( D: \\cat{I} \\to \\cat{C} \\), whose domain is \\( \\cat{I} \\). We sometimes identify a diagram functor with its image \\( D(\\cat{I}) \\).\n\n  It is often convenient to draw graphically the \\hyperref[def:quiver_geometric_realization]{geometric realizations} of the \\hyperref[def:quiver]{quiver} \\( D(\\cat{I}) \\). An established convention is to allow multiple vertices representing the same object, which can be achieved formally by actually adjoining new vertices to the quiver and labeling them as in \\fullref{def:weighted_set}. Other established conventions for drawing diagrams include not drawing identity morphisms and adding various visual aids. In this regard, categorical diagrams correspond to the everyday sense of the word \\enquote{diagram}.\n\n  We say that the diagram \\( D \\) over \\( \\cat{C} \\) \\term{commutes} if, whenever \\( p = (f_1, \\ldots, f_n) \\) and \\( q = (g_1, \\ldots, g_m) \\) are two \\hyperref[def:quiver_path/directed]{directed paths} in \\( D(\\cat{I}) \\) with identical endpoints and either \\( n > 1 \\) or \\( m > 1 \\), then\n  \\begin{equation*}\n    f_n \\bincirc f_{n-1} \\bincirc \\cdots \\bincirc f_2 \\bincirc f_1\n    =\n    g_m \\bincirc g_{m-1} \\bincirc \\cdots \\bincirc g_2 \\bincirc g_1.\n  \\end{equation*}\n\n  We do not really care about how the objects and morphisms in \\( \\cat{I} \\) are labeled, hence we often use placeholder dots like in \\eqref{eq:ex:quivers_as_functors/index/dots}.\n\n  The requirement that the one of the paths is nontrivial, however, is crucial in \\fullref{def:equalizers}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:inverting_isomorphisms_may_preserve_commutativity}\n  Inverting isomorphisms in a \\hyperref[def:categorical_diagram]{commutative diagram} may or may not preserve commutativity.\n\n  If \\( p = (f_1, \\ldots, f_n) \\) and \\( q = (g_1, \\ldots, g_m) \\) are two paths in a commutative diagram, and if \\( f_1 \\) is invertible, then obviously\n  \\begin{equation*}\n    f_n \\bincirc \\cdots \\bincirc f_1 = g_m \\bincirc \\cdots \\bincirc g_1\n  \\end{equation*}\n  if and only if\n  \\begin{equation*}\n    f_n \\bincirc \\cdots \\bincirc f_2 = g_m \\bincirc \\cdots \\bincirc g_1 \\bincirc f_1\n  \\end{equation*}\n  and similarly if \\( f_n \\) is invertible.\n\n  On the other hand, consider \\hyperref[def:ordinal]{ordinals} in \\( \\cat{Set} \\). Denote by \\( \\iota \\) the inclusion maps and by \\( f: \\omega^2 \\to \\omega \\) the bijective map from \\fullref{thm:omega_equinumerous_with_omega_squared}. Then the following diagram commutes:\n  \\begin{equation}\\label{eq:rem:inverting_isomorphisms_may_preserve_commutativity/ordinals_commuting}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/rem__inverting_isomorphisms_may_preserve_commutativity.pdf}\n    \\end{aligned}\n  \\end{equation}\n  but the following does not:\n  \\begin{equation}\\label{eq:rem:inverting_isomorphisms_may_preserve_commutativity/ordinals_not_commuting}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/rem__inverting_isomorphisms_may_preserve_commutativity.pdf}\n    \\end{aligned}\n  \\end{equation}\n\\end{remark}\n\n\\begin{definition}\\label{def:functor_invertibility}\n  In connection with \\fullref{def:morphism_invertibility} and \\fullref{def:function_invertibility}, we introduce the following terminology:\n  \\begin{thmenum}\n    \\thmitem{def:functor_invertibility/injective_on_objects} The \\hyperref[def:functor]{functor} \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{injective on objects} if the \\hyperref[def:multi_valued_function/restriction]{restriction}\n    \\begin{equation*}\n      F\\restr_{\\obj(C)}: \\obj(C) \\to \\obj(D)\n    \\end{equation*}\n    is \\hyperref[def:function_invertibility/injective]{injective}.\n\n    That is, for every pair of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), from \\( F(A) = F(B) \\) it follows that \\( A = B \\).\n\n    If, instead, from \\( F(A) \\cong F(B) \\) it follows that \\( A \\cong B \\), we say that \\( F \\) if \\term{essentially injective on objects}.\n\n    \\thmitem{def:functor_invertibility/injective_on_morphisms} The \\hyperref[def:functor]{functor} \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{injective on morphisms} if its restriction to the set\n    \\begin{equation*}\n      \\bigcup\\set{ \\cat{C}(A, B) \\given A, B \\in \\obj(\\cat{C}) }\n    \\end{equation*}\n    of all morphisms is injective.\n\n    That is, for every pair of morphisms \\( f \\) and \\( g \\) in \\( \\cat{C} \\), from \\( F(f) = F(g) \\) it follows that \\( f = g \\). Note that if the morphisms are not parallel, we assume that they are not equal.\n\n    \\thmitem{def:functor_invertibility/faithful}\\mcite[def. 1.2.16]{Leinster2016Basic} The functor \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{faithful} if it is \\hyperref[def:function_invertibility/injective]{injective} on \\( \\hom \\)-sets, i.e. for all pairs of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), the restriction of \\( F \\) to \\( \\cat{C}(A, B) \\) is an injective function.\n\n    That is, for every pair of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\) and every pair of morphisms \\( f \\) and \\( g \\) in \\( \\cat{C}(A, B) \\), from \\( F(f) = F(g) \\) it follows that \\( f = g \\).\n\n    See \\fullref{thm:def:functor_invertibility/properties/injective} for how faithful functors relate to functors injective on objects or on morphisms.\n\n    \\thmitem{def:functor_invertibility/surjective_on_objects}\\mcite[def. 1.3.17]{Leinster2016Basic} The functor \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{surjective on objects} if the restriction\n    \\begin{equation*}\n      F\\restr_{\\obj(C)}: \\obj(C) \\to \\obj(D)\n    \\end{equation*}\n    is \\hyperref[def:function_invertibility/surjective]{surjective}.\n\n    That is, for every object \\( B \\) in \\( \\cat{D} \\), there exists at least one object \\( A \\) in \\( \\cat{C} \\) such that \\( F(A) = B \\).\n\n    If, instead, there exists at least one object \\( A \\in \\cat{C} \\) such that \\( F(A) \\cong B \\), we say that \\( F \\) is \\term{essentially surjective on objects}.\n\n    \\thmitem{def:functor_invertibility/surjective_on_morphisms} Similarly, \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{surjective on morphisms} if its restriction to the set of all morphisms is surjective.\n\n    That is, for every morphism \\( g \\) in \\( \\cat{D} \\), there exists at least one morphism \\( f \\) in \\( \\cat{C} \\) such that \\( F(f) = g \\).\n\n    \\thmitem{def:functor_invertibility/full}\\mcite[def. 1.2.16]{Leinster2016Basic} The functor \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{full} if it is surjective on \\( \\hom \\)-sets, i.e. for all pairs of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), the restriction of \\( F \\) to \\( \\cat{C}(A, B) \\) is a surjective function.\n\n    That is, for every pair of objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\) and every morphism \\( g: F(A) \\to F(B) \\) in \\( \\cat{D} \\), there exists at least one morphism in \\( f: A \\to B \\) in \\( \\cat{C} \\) such that \\( F(f) = g \\).\n\n    \\thmitem{def:functor_invertibility/fully_faithful} Finally, \\( F: \\cat{C} \\to \\cat{D} \\) is \\term{fully faithful} if it is both full and faithful.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:functor_invertibility/properties}\n  \\hyperref[def:functor]{Functors} have the following basic properties regarding their \\hyperref[def:functor_invertibility]{invertibility}:\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:functor_invertibility/properties/injective} A functor is \\hyperref[def:functor_invertibility/injective_on_morphisms]{injective on morphisms} if and only if it is both \\hyperref[def:functor_invertibility/injective_on_objects]{injective on objects} and \\hyperref[def:functor_invertibility/faithful]{faithful}.\n\n    \\thmitem{thm:def:functor_invertibility/properties/surjective} A functor is \\hyperref[def:functor_invertibility/surjective_on_morphisms]{surjective on morphisms} if and only if it is both \\hyperref[def:functor_invertibility/surjective_on_objects]{surjective on objects} and \\hyperref[def:functor_invertibility/full]{full}.\n\n    \\thmitem{thm:def:functor_invertibility/properties/full_subcategory} A \\hyperref[def:subcategory]{subcategory} \\( \\cat{D} \\) of \\( \\cat{C} \\) is full in the sense of \\fullref{def:subcategory} if and only if the \\hyperref[def:subcategory]{inclusion functor} \\( \\Iota: \\cat{D} \\to \\cat{C} \\) is full in the sense of \\fullref{def:functor_invertibility/full}.\n\n    \\thmitem{thm:def:functor_invertibility/properties/faithful_reflects_composition} \\hyperref[def:functor_invertibility/faithful]{Faithful} functors reflect composition. That is, for every functor \\( F: \\cat{C} \\to \\cat{D} \\), if the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/image}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__def__functor_invertibility__properties.pdf}\n      \\end{aligned}\n    \\end{equation}\n    then the following diagram are identities:\n    \\begin{equation}\\label{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/source}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/thm__def__functor_invertibility__properties.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    \\thmitem{thm:def:functor_invertibility/properties/faithful_reflects_cancellative} A \\hyperref[def:functor_invertibility/faithful]{faithful} functor reflects monomorphisms and epimorphisms. For every functor \\( F: \\cat{C} \\to \\cat{D} \\) and morphism \\( f: A \\to B \\) in \\( \\cat{C} \\), if \\( F(f) \\) is a monomorphism (resp. epimorphism), so is \\( f \\).\n\n    \\thmitem{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} A \\hyperref[def:functor_invertibility/fully_faithful]{fully faithful} functor reflects identities. For every functor \\( F: \\cat{C} \\to \\cat{D} \\) and endomorphism \\( f: A \\to A \\) in \\( \\cat{C} \\), if \\( F(f) = \\id_{F(A)} \\), then \\( f = \\id_A \\).\n\n    \\thmitem{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms} A \\hyperref[def:functor_invertibility/fully_faithful]{fully faithful} functor reflects split monomorphisms and split epimorphisms, and hence also isomorphisms.\n\n    That is, for every functor \\( F: \\cat{C} \\to \\cat{D} \\) and morphism \\( f: A \\to B \\) in \\( \\cat{C} \\), if \\( F(f) \\) is a split monomorphism (resp. split epimorphism or isomorphism), so is \\( f \\).\n\n    \\thmitem{thm:def:functor_invertibility/properties/isomorphism} A functor between \\( \\mscrU \\)-small categories that is both injective and surjective on morphisms is itself an isomorphism in \\( \\ucat{Cat} \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:functor_invertibility/properties/injective}\n  \\SufficiencySubProof* Let \\( F: \\cat{C} \\to \\cat{D} \\) be injective on morphisms. It is trivially faithful since faithfulness is a more restrictive condition.\n\n  To see that \\( F \\) is injective on objects, let \\( A, B \\in \\cat{C} \\) and suppose that \\( F(A) = F(B) \\). Then \\( \\id_{F(A)} = \\id_{F(B)} \\) and\n  \\begin{equation*}\n    F(\\id_A)\n    \\reloset {\\eqref{eq:def:functor/CF2}} =\n    \\id_{F(A)}\n    =\n    \\id_{F(B)}\n    \\reloset {\\eqref{eq:def:functor/CF2}} =\n    F(\\id_B).\n  \\end{equation*}\n\n  Since \\( F \\) is injective on morphisms, it follows that \\( \\id_A = \\id_B \\), hence \\( A = B \\). Thus, \\( F \\) is injective on objects.\n\n  \\NecessitySubProof* Let \\( F: \\cat{C} \\to \\cat{D} \\) be faithful and injective on objects. Let \\( f: A \\to B \\) and \\( g: C \\to D \\) be morphisms in \\( \\cat{C} \\) such that \\( F(f) = F(g) \\).\n\n  Then both \\( F(f) \\) and \\( F(g) \\) have the same domain \\( F(A) = F(C) \\) and codomain \\( F(B) = F(D) \\). Hence, since \\( F \\) is injective on objects, we have \\( A = C \\) and \\( B = D \\).\n\n  Thus, \\( f \\) and \\( g \\) are both morphisms from \\( A \\) to \\( B \\). Since \\( F \\) is also faithful, from \\( F(f) = F(g) \\) it follows that \\( f = g \\).\n\n  Therefore, \\( F \\) is injective on morphisms.\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/surjective}\n  \\SufficiencySubProof* Let \\( F: \\cat{C} \\to \\cat{D} \\) be surjective on morphisms. It is trivially full since fullness is a more restrictive condition.\n\n  To see that \\( F \\) is surjective on objects, let \\( C \\in \\cat{D} \\). Then there exists some morphism \\( f: A \\to B \\) in \\( \\cat{C} \\) such that \\( F(f) = \\id_Z \\). We thus necessarily have \\( F(A) = C \\) and \\( F(B) = C \\).\n\n  \\NecessitySubProof* Let \\( F: \\cat{C} \\to \\cat{D} \\) be full and injective on objects. Let \\( g: C \\to D \\) be a morphism in \\( \\cat{D} \\).\n\n  Since \\( F \\) is surjective on objects, there exists preimages \\( A \\) of \\( C \\) and \\( B \\) of \\( D \\) under \\( F \\). Thus, \\( g \\in \\cat{D}(F(A), F(B)) \\).\n\n  Since \\( F \\) is also full, there exists some morphism \\( f: A \\to B \\) such that \\( F(f) = g \\).\n\n  Therefore, \\( F \\) is surjective on morphisms.\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/full_subcategory} Trivial.\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/faithful_reflects_composition} Suppose that \\eqref{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/image} commutes. Then, since \\( F \\) is faithful and thus injective on the morphism set \\( \\cat{C}(A, C) \\), the equality \\( F(g \\bincirc f) = F(g) \\bincirc F(f) = F(h) \\) implies that \\( g \\bincirc f = h \\). Hence, \\eqref{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/source} also commutes.\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/faithful_reflects_cancellative} Let \\( F(g) \\) be a monomorphism and let \\( f_1, f_2: A \\to B \\) be parallel morphisms such that\n  \\begin{equation*}\n    g \\bincirc f_1 = g \\bincirc f_2.\n  \\end{equation*}\n\n  Then, since \\( F(g) \\) is a monomorphism, we have that \\( F(f_1) = F(f_2) \\). Since \\( F \\) is faithful, the restriction \\( F\\restr_{C(A, B)} \\) is injective, and \\( f_1 = f_2 \\).\n\n  The proof when \\( F(g) \\) is an epimorphism is analogous.\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} If \\( F: \\cat{C} \\to \\cat{D} \\) is fully faithful, for every object \\( A \\) in \\( \\cat{C} \\), the identity morphism \\( \\id_{F(A)} \\) has a unique preimage under \\( F \\). By \\ref{def:functor/CF1}, this preimage can only be \\( \\id_A \\).\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms} Let \\( q \\) be a left inverse of \\( F(f) \\). Since \\( F \\) is fully faithful, there exists a unique morphism \\( g: B \\to A \\) such that \\( F(g) = q \\).\n\n  Since\n  \\begin{equation*}\n    F(g) \\bincirc F(f) = \\id_{F(A)},\n  \\end{equation*}\n  by \\fullref{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} we have\n  \\begin{equation*}\n    g \\bincirc f = \\id_A.\n  \\end{equation*}\n\n  Therefore, \\( g \\) is a left inverse of \\( F(f) \\).\n\n  The proof for right inverses follows from \\fullref{thm:def:morphism_invertibility/properties/inverse_interchanges}.\n\n  From \\fullref{thm:def:morphism_invertibility/properties/left_and_right} it follows that if \\( F(f) \\) is an isomorphism, so is \\( f \\).\n\n  \\SubProofOf{thm:def:functor_invertibility/properties/isomorphism} If \\( F \\) is both injective and surjective on morphisms, it is also injective and surjective on objects and hence, as a function, is bijective. Therefore, it is both left and right invertible as a consequence of \\fullref{thm:function_invertibility_categorical/fully_invertible}.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:functor_invertibility}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{ex:def:functor_invertibility/power} The power set functor described in \\fullref{ex:unary_functors_in_set} is clearly \\hyperref[def:functor_invertibility/injective_on_morphisms]{injective on morphisms}, hence by \\fullref{thm:def:functor_invertibility/properties/injective}, it is also \\hyperref[def:functor_invertibility/injective_on_objects]{injective on objects} and \\hyperref[def:functor_invertibility/faithful]{faithful}.\n\n    It is not full, nor surjective on objects.\n\n    \\thmitem{ex:def:functor_invertibility/cat_to_set} The forgetful functor \\( D: \\ucat{Cat} \\to \\ucat{Set} \\) discussed in \\fullref{def:discrete_category} is \\hyperref[def:functor_invertibility/surjective_on_morphisms]{surjective on morphisms}, hence by \\fullref{thm:def:functor_invertibility/properties/surjective}, it is also \\hyperref[def:functor_invertibility/surjective_on_objects]{surjective on objects} and \\hyperref[def:functor_invertibility/full]{full}.\n\n    It is not faithful, nor injective on objects.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:commutative_diagrams_preserved_and_reflected}\n  Functors preserve commutative diagrams and faithful functors also reflect commutative diagrams.\n\n  More precisely, let \\( \\cat{C} \\) be an arbitrary category, let \\( D \\) be a diagram in \\( \\cat{C} \\), and let \\( p = (f_1, \\ldots, f_n) \\) and \\( q = (g_1, \\ldots, g_m) \\) be two \\hyperref[def:quiver_path/directed]{directed paths} with the same endpoints in \\( D \\).\n\n  For any functor \\( F: \\cat{C} \\to \\cat{D} \\), if\n  \\begin{equation}\\label{eq:thm:commutative_diagrams_preserved_and_reflected/source}\n    f_n \\bincirc \\cdots \\bincirc \\bincirc f_1 = g_m \\bincirc \\cdots \\bincirc \\bincirc g_1,\n  \\end{equation}\n  then\n  \\begin{equation}\\label{eq:thm:commutative_diagrams_preserved_and_reflected/image}\n    F(f_n) \\bincirc \\cdots \\bincirc \\bincirc F(f_1) = F(g_m) \\bincirc \\cdots \\bincirc \\bincirc F(g_1),\n  \\end{equation}\n\n  Conversely, if \\( F \\) is faithful, then \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} implies \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source}.\n\\end{proposition}\n\\begin{proof}\n  Functors preserve composition by \\ref{eq:def:functor/CF2}, hence \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} follows from \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source} directly.\n\n  Now suppose that \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} holds for a faithful functor \\( F \\). \\ref{eq:def:functor/CF2} allows us to reduce \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} to\n  \\begin{equation*}\n    F(f_n \\bincirc \\cdots \\bincirc \\bincirc f_1) = F(g_m \\bincirc \\cdots \\bincirc \\bincirc g_1).\n  \\end{equation*}\n\n  Then, by injectivity of \\( F \\) on the morphism set \\( \\cat{C}(\\dom(f_1), \\co\\dom(f_1)) \\), \\eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source} holds.\n\\end{proof}\n\n\\begin{definition}\\label{def:natural_transformation}\\mcite[def. 1.3.1]{Leinster2016Basic}\n  Let \\( F \\) and \\( G \\) be parallel \\hyperref[def:functor]{functors} from the category \\( \\cat{C} \\) to \\( \\cat{D} \\).\n\n  A \\term{natural transformation} \\( \\alpha \\) from \\( F \\) to \\( G \\) is an \\hyperref[def:cartesian_product/indexed_family]{indexed family} of\n  \\begin{equation}\\label{eq:def:natural_transformation/family}\n    \\seq{ \\alpha_A: F(A) \\to G(A) }_{A \\in \\cat{C}}\n  \\end{equation}\n  of morphisms in \\( \\cat{D} \\) such that, for every morphism \\( f: A \\to B \\) in \\( \\cat{C} \\), the following \\hyperref[def:categorical_diagram]{diagram commutes}:\n  \\begin{equation}\\label{eq:def:natural_transformation/diagram}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/def__natural_transformation.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  The morphisms \\( \\alpha_A \\) are called the components of \\( \\alpha \\). We denote natural transformations by \\( \\alpha: F \\Rightarrow G \\) and, when used in diagrams, by\n  \\begin{equation}\\label{eq:def:natural_transformation/notation}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/def__natural_transformation.pdf}\n    \\end{aligned}\n  \\end{equation}\n\\end{definition}\n\n\\begin{example}\\label{ex:quivers_as_functors}\\mcite[exmpl. 1.3.46]{Perrone2019}\n  In \\fullref{def:quiver}, we have defined a quiver as a set \\( V \\) of vertices, a set \\( A \\) of arcs and two functions --- the head \\( h: A \\to V \\)and tail \\( t: A \\to V \\) of an arc.\n\n  Now consider the following \\hyperref[def:categorical_diagram]{index category} \\( \\cat{I}: \\)\n  \\begin{equation}\\label{eq:ex:quivers_as_functors/index/dots}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/ex__quivers_as_functors.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  For the sake of readability, we will give the following explicit labels in this category:\n  \\begin{equation}\\label{eq:ex:quivers_as_functors/index/annotated}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/ex__quivers_as_functors.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  A quiver can then be defined as a functor \\( Q: \\cat{I} \\to \\ucat{Set} \\) to the category \\hyperref[def:category_of_small_sets]{\\( \\ucat{Set} \\)} of \\( \\mscrU \\)-small sets (for a \\hyperref[def:category_size]{fixed Grothendieck universe} \\( \\mscrU \\)).\n\n  A \\hyperref[def:natural_transformation]{natural transformation} from the quiver \\( Q: \\cat{I} \\to \\ucat{Set} \\) to \\( R: \\cat{I} \\to \\ucat{Set} \\) is then a pair of functions \\( f_V: Q(V) \\to R(V) \\) and \\( f_A: Q(A) \\to R(A) \\) such that the following \\hyperref[def:categorical_diagram]{diagrams commute}:\n  \\begin{equation}\\label{eq:ex:quivers_as_functors/index/diagram}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/ex__quivers_as_functors.pdf}\n      \\quad\\quad\\quad\\quad\n      \\includegraphics[page=4]{output/ex__quivers_as_functors.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  See \\fullref{ex:isomorphism_of_quiver_categories} for how these functors related to quivers as defined in \\fullref{def:quiver}.\n\\end{example}\n\n\\begin{remark}\\label{rem:natural_transformations_into_set}\n  Let \\( \\cat{C} \\) be an arbitrary \\( \\mscrU \\)-small category. A \\hyperref[def:natural_transformation]{natural transformation} \\( \\alpha \\) from \\( F: \\cat{C} \\to \\ucat{Set} \\) to \\( G: \\cat{C} \\to \\ucat{Set} \\) is then a family of functions\n  \\begin{equation*}\n    \\seq{ \\alpha_A: F(A) \\to G(A) }_{A \\in \\cat{C}}.\n  \\end{equation*}\n\n  Suppose that for every two objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), the functions \\( \\alpha_A \\) and \\( \\alpha_B \\) agree on \\( F(A) \\cap F(B) \\). This is automatically satisfied in \\( F(A) \\) and \\( F(B) \\) are disjoint whenever \\( A \\neq B \\).\n\n  We can then take the set-theoretic union of \\( \\alpha \\) to obtain the function\n  \\begin{equation*}\n    \\bigcup_{A \\in \\cat{C}} \\alpha_A: \\bigcup\\set{ F(A) \\given A \\in \\cat{C} } \\to \\bigcup\\set{ G(A) \\given A \\in \\cat{C} }.\n  \\end{equation*}\n\n  Both the domain and codomain are sets as a consequence of \\ref{def:grothendieck_universe/union}, therefore the function is well-defined in the universe \\( \\mscrU \\). Denote it on \\( \\Alpha \\) for brevity.\n\n  An advantage of this is that we can define a natural transformation to be a function on a general enough set and then prove that its restrictions satisfy \\eqref{eq:def:natural_transformation/diagram}.\n\n  For example, consider the power set functor \\( \\pow: \\ucat{Set} \\to \\ucat{Set} \\) discussed in \\fullref{ex:unary_functors_in_set}. The \\hyperref[def:multi_valued_function/identity]{identity function} \\( \\id_\\mscrU \\) is then a natural transformation from the identity functor \\( \\id_{\\ucat{Set}} \\) to \\( \\pow \\).\n\n  Another natural transformation between the same functors is the singleton set operation \\( \\Sigma \\) on sets defined as \\( A \\mapsto \\set{ A } \\). Note that, in this context, \\( \\Sigma \\) operates not on the sets \\( \\id_{\\ucat{Set}}(A) \\) and \\( \\pow(A) \\), but on their members. The diagram \\eqref{eq:def:natural_transformation/diagram} becomes\n  \\begin{equation}\\label{eq:rem:natural_transformations_into_set}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/rem__natural_transformations_into_set.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  This diagram commutes because, for every function \\( f: A \\to B \\) and every \\( x \\in A \\), we have\n  \\begin{equation*}\n    f[\\set{ x }] = \\set{ f(x) }.\n  \\end{equation*}\n\\end{remark}\n\n\\begin{definition}\\label{def:functor_category}\n  Let \\( \\cat{C} \\) and \\( \\cat{D} \\) be arbitrary \\hyperref[def:category]{categories}. The \\term{functor category} \\( [\\cat{C}, \\cat{D}] \\), also denoted as \\( \\cat{D}^{\\cat{C}} \\), is defined as follows:\n\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj([\\cat{C}, \\cat{D}]) \\) is the set of all functors from \\( \\cat{C} \\) to \\( \\cat{D} \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( [\\cat{C}, \\cat{D}](F, G) \\) from \\( F \\) to \\( G \\) is the set of all \\hyperref[def:natural_transformation]{natural transformations} from \\( F \\) to \\( G \\).\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms} \\( \\alpha: F \\Rightarrow G \\) and \\( \\beta: G \\Rightarrow H \\) is the natural transformation \\( \\beta \\bincirc \\alpha: F \\Rightarrow H \\) defined in terms of componentwise morphism composition, i.e.\n    \\begin{equation}\\label{eq:def:functor_category/composition}\n      (\\beta \\bincirc \\alpha)_A \\coloneqq \\beta_A \\bincirc \\alpha_A.\n    \\end{equation}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the functor \\( F: \\cat{C} \\to \\cat{D} \\) is the \\term{identity natural transformation} \\( \\id_F: F \\Rightarrow F \\) with components\n    \\begin{equation}\\label{eq:def:functor_category/identity}\n      (\\id_F)_A \\coloneqq \\underbrace{\\id_{F(A)}}_{F(\\id_A)}\n    \\end{equation}\n  \\end{itemize}\n\\end{definition}\n\\begin{defproof}\n  Just to verify that the composition \\( \\beta \\bincirc \\alpha \\) defined in \\eqref{eq:def:functor_category/composition} is indeed a natural transformation from \\( F \\) to \\( H \\), note that the following diagram trivially commutes:\n  \\begin{equation}\\label{def:functor_category/composition}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/def__functor_category.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Now, to see that \\( [\\cat{C}, \\cat{D}] \\) is indeed a category, we verify the conditions \\ref{def:category/C1} and \\ref{def:category/C2}, which are in turn inherited from the same conditions on the categories \\( \\cat{C} \\) and \\( \\cat{D} \\).\n\n  \\SubProofOf{def:category/C1} For every two functors \\( F, G: \\cat{C} \\to \\cat{D} \\) and natural transformation \\( \\alpha: F \\Rightarrow G \\), for every object \\( A \\in \\cat{C} \\) we have\n  \\begin{equation*}\n    \\id_{G(A)} \\bincirc \\alpha_A\n    \\reloset{\\eqref{def:category/C1}} =\n    \\alpha_A\n    \\reloset{\\eqref{def:category/C1}} =\n    \\alpha_A \\bincirc \\id_{F(A)}\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    \\id_G \\bincirc \\alpha = \\alpha = \\alpha \\bincirc \\id_F\n  \\end{equation*}\n  and, after generalizing, we obtain that \\eqref{eq:def:category/C1} holds in \\( [\\cat{C}, \\cat{D}] \\).\n\n  \\SubProofOf{def:category/C2} For any quadruple \\( F \\), \\( G \\), \\( H \\) and \\( T \\) of functors from \\( \\cat{C} \\) to \\( \\cat{D} \\) and every combination of natural transformations \\( \\alpha: F \\Rightarrow G \\), \\( \\beta: G \\Rightarrow H \\) and \\( \\gamma: H \\Rightarrow T \\), for every object \\( A \\in \\cat{C} \\) we have\n  \\begin{equation*}\n    (\\gamma_A \\bincirc \\beta_A) \\bincirc \\alpha_A\n    \\reloset{\\eqref{def:category/C2}} =\n    \\gamma_A \\bincirc (\\beta_A \\bincirc \\alpha_A).\n  \\end{equation*}\n\n  Therefore, after generalizing, we obtain that \\eqref{eq:def:category/C2} holds in \\( [\\cat{C}, \\cat{D}] \\).\n\\end{defproof}\n\n\\begin{remark}\\label{rem:functor_category_size}\n  If \\( \\cat{C} \\) and \\( \\cat{D} \\) are \\( \\mscrU \\)-large categories in the sense of \\fullref{def:category_size}, we cannot construct the \\hyperref[def:functor_category]{functor category} \\( [\\cat{C}, \\cat{D}] \\). This is the main motivation for the \\hyperref[def:axiom_of_universes]{axiom of universes}, which is discussed in \\fullref{def:large_and_small_sets} and, in relation to category theory, in \\fullref{def:category_size}.\n\\end{remark}\n\n\\begin{example}\\label{ex:isomorphism_of_quiver_categories}\n  In \\fullref{ex:quivers_as_functors}, we defined \\hyperref[def:quiver]{quivers} as functors from a certain index category \\( \\cat{I} \\) to \\( \\ucat{Set} \\) (for a \\hyperref[def:category_size]{fixed Grothendieck universe} \\( \\mscrU \\)).\n\n  There is then an obvious correspondence between quivers as objects of \\hyperref[def:category_of_small_quivers]{\\( \\ucat{Quiv} \\)}, defined in \\fullref{def:quiver}, and quivers as objects in the \\hyperref[def:functor_category]{functor category} \\( [\\cat{I}, \\ucat{Set}] \\), defined in \\fullref{ex:quivers_as_functors}. Indeed, given any functor \\( Q: \\cat{I} \\to \\ucat{Set} \\), the quadruple\n  \\begin{equation*}\n    \\parens[\\Big]{ Q(V), Q(A), Q(h), Q(t) }\n  \\end{equation*}\n  is a quiver in the sense of \\fullref{def:quiver}.\n\n  No object in \\( \\ucat{Quiv} \\) is formally equal to any object in \\( [\\cat{I}, \\ucat{Set}] \\) in the sense of \\hyperref[def:zfc]{\\logic{ZFC}}. They are, however, equivalent, as shown above, and this can be formalized by stating that the two categories are isomorphic, in the sense of \\fullref{def:morphism_invertibility/isomorphism}, as objects of the category \\( \\ucat[\\mscrV]{Cat} \\), where \\( \\mscrV \\) is a Grothendieck universe that strictly contains \\( \\mscrU \\). We have already defined this isomorphism explicitly.\n\n  This is an example of \\term{isomorphism of categories}. In practice, if two categories are not so obviously identical, we are usually better served by \\term{equivalences of categories} defined in \\fullref{def:category_equivalence}.\n\\end{example}\n\n\\begin{definition}\\label{def:dual_natural_transformation}\\mcite{nLab:opposite_category}\n  The \\term{opposite} or \\term{dual} natural transformation of \\( \\alpha: F \\Rightarrow G \\), where \\( F \\) and \\( G \\) are functors from \\( \\cat{C} \\) to \\( \\cat{D} \\), is the natural transformation \\( \\alpha^{\\opcat}: G^{\\opcat} \\Rightarrow F^{\\opcat} \\), in which we take the opposite of each component in \\( \\alpha \\).\n\n  Dual natural transformation arise naturally in \\fullref{thm:dual_functor_category}.\n\\end{definition}\n\\begin{defproof}\n  The naturality diagram \\eqref{eq:def:natural_transformation/diagram} commutes for \\( \\alpha^{\\opcat} \\) because all morphisms are simply reversed.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:dual_functor_category}\n  For the \\hyperref[def:dual_category]{dual} of the \\hyperref[def:functor_category]{functor category} \\( [\\cat{C}, \\cat{D}] \\) we have\n  \\begin{equation*}\n    [\\cat{C}, \\cat{D}]^{\\opcat} = [\\cat{C}^{\\opcat}, \\cat{D}^{\\opcat}].\n  \\end{equation*}\n\n  This is part of the duality principles listed in \\fullref{thm:categorical_principle_of_duality}.\n\\end{proposition}\n\\begin{proof}\n  In \\fullref{def:dual_functor}, we have defined the opposite functor \\( F^{\\opcat}: \\cat{C}^{\\opcat} \\to \\cat{D}^{\\opcat} \\) of \\( F: \\cat{C} \\to \\cat{D} \\) in a way that allows us to regard it as an object of \\( [\\cat{C}^{\\opcat}, \\cat{D}^{\\opcat}] \\).\n\n  In \\fullref{def:dual_natural_transformation}, we have defined the opposite natural transformation \\( \\alpha^{\\opcat}: G^{\\opcat} \\to F^{\\opcat} \\) of \\( \\alpha: F \\Rightarrow G \\) in a way that allows us to regard it as a morphism of \\( [\\cat{C}^{\\opcat}, \\cat{D}^{\\opcat}] \\).\n\n  Furthermore, \\( \\alpha^{\\opcat}: G^{\\opcat} \\to F^{\\opcat} \\) reverses the direction of its morphisms, and hence it is the dual to \\( \\alpha \\) in the category \\( [\\cat{C}, \\cat{D}]^{\\opcat} \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:diagonal_functor}\\mcite[143]{Leinster2016Basic}\n  Given an \\term{index category} \\( \\cat{I} \\) and an arbitrary category \\( \\cat{C} \\), for any object \\( A \\) in \\( \\cat{C} \\), we can define the \\term{constant functor}\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Delta_A^{\\cat{I}}: \\cat{I} \\to \\cat{C}, \\\\\n      &\\Delta_A^{\\cat{I}}(X) \\coloneqq X, \\\\\n      &\\Delta_A^{\\cat{I}}(g: X \\to Y) \\coloneqq \\id_A.\n    \\end{aligned}\n  \\end{equation*}\n\n  Given two objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\), a natural transformation \\( \\alpha: \\Delta_A^{\\cat{I}} \\Rightarrow \\Delta_B^{\\cat{I}} \\) is an \\hyperref[def:cartesian_product/indexed_family]{indexed family} that gives the same morphism for every object of the index category \\( \\cat{I} \\).\n\n  Indeed, the diagram \\eqref{eq:def:natural_transformation/diagram} in this case becomes\n  \\begin{equation}\\label{eq:def:diagonal_functor/nat}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/def__diagonal_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  This diagram implies that \\( \\alpha_A = \\alpha_B \\) for any two objects \\( A \\) and \\( B \\) in \\( \\cat{I} \\). Therefore, all components of \\( \\alpha \\) are equal to some morphism in \\( \\cat{C}(A, B) \\).\n\n  We can now define the \\( \\cat{I} \\)-shaped \\term{diagonal functor} on \\( \\cat{C} \\)\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Delta^{\\cat{I}}: \\cat{C} \\to [\\cat{I}, \\cat{C}], \\\\\n      &\\Delta^{\\cat{I}}(A) \\coloneqq \\Delta_A^{\\cat{I}}, \\\\\n      &\\Delta^{\\cat{I}}(f: A \\to B) \\coloneqq \\seq{ f: A \\to B }_{k \\in \\cat{I}}.\n    \\end{aligned}\n  \\end{equation*}\n\n  It is called a diagonal functor because, if \\( \\cat{I} \\) is a discrete category of two objects, then \\( \\Delta_{\\cat{I}} \\) gives the diagonal of the \\hyperref[def:product_category]{product category} \\( \\cat{C}^2 \\) by providing, for each object \\( A \\) of \\( \\cat{C} \\), the ordered pair \\( (A, A) \\) (and similarly for morphisms).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:natural_isomorphism}\\mcite{math3ma:natural_transformations}\n  Let \\( F \\) and \\( G \\) be parallel \\hyperref[def:functor]{functors} from the category \\( \\cat{C} \\) to \\( \\cat{D} \\). The family \\eqref{eq:def:natural_transformation/family} is an isomorphism in the corresponding \\hyperref[def:functor_category]{functor category} \\( [\\cat{C}, \\cat{D}] \\) if and only if all of its components are isomorphisms and, for any morphism \\( f: A \\to B \\) in \\( \\cat{C} \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:natural_isomorphism/diagram}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__natural_isomorphism.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  We say that \\( \\alpha \\) is a \\term{natural isomorphism}.\n\\end{proposition}\n\\begin{proof}\n  If all components of \\( \\alpha \\) are isomorphisms, the condition\n  \\begin{equation*}\n    \\alpha_B \\bincirc F(f) = G(f) \\bincirc \\alpha_A\n  \\end{equation*}\n  is equivalent to\n  \\begin{equation*}\n    F(f) = \\alpha_B^{-1} \\bincirc G(f) \\bincirc \\alpha_A.\n  \\end{equation*}\n\n  We must now show that, if \\( \\alpha \\) is an isomorphism in \\( [\\cat{C}, \\cat{D}] \\), all of its components are isomorphisms.\n\n  If \\( \\alpha: F \\Rightarrow G \\) is an isomorphism in \\( [\\cat{C}, \\cat{D}] \\). Then there exists some natural transformation \\( \\beta: G \\Rightarrow F \\) such that\n  \\begin{equation*}\n    \\beta \\bincirc \\alpha = \\id_F \\quad\\T{and}\\quad \\alpha \\bincirc \\beta = \\id_G.\n  \\end{equation*}\n\n  For every object \\( A \\) in \\( \\cat{C} \\), the morphism \\( \\alpha_A: F(A) \\to G(A) \\) composed with \\( \\beta_A: G(A) \\to F(A) \\) is\n  \\begin{equation*}\n    \\beta_A \\bincirc \\alpha_A = \\id_{F(A)}.\n  \\end{equation*}\n\n  Therefore, \\( \\alpha_A \\) is left-invertible. Analogously,\n  \\begin{equation*}\n    \\alpha_A \\bincirc \\beta_A = \\id_{F(A)}\n  \\end{equation*}\n  and hence \\( \\alpha_A \\) is right-invertible.\n\n  Therefore, for every object \\( A \\) in \\( \\cat{C} \\), the morphism \\( \\alpha_A \\) is fully invertible, i.e. an isomorphism.\n\\end{proof}\n\n\\begin{definition}\\label{def:product_category}\\mcite[const. 1.1.11]{Leinster2016Basic}\n  We define the \\term{product category} \\( \\cat{C} \\times \\cat{D} \\) of \\( \\cat{C} \\) and \\( \\cat{D} \\) as follows:\n\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} is the \\hyperref[def:cartesian_product]{Cartesian product}\n    \\begin{equation}\\label{eq:def:product_category/objects}\n      \\obj(\\cat{C} \\times \\cat{D}) \\coloneqq \\obj(\\cat{C}) \\times \\obj(\\cat{D}).\n    \\end{equation}\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} from the pair of objects \\( (A, X) \\) to \\( (B, Y) \\) is the product\n    \\begin{equation}\\label{eq:def:product_category/morphisms}\n      (\\cat{C} \\times \\cat{D})\\parens[\\Big]{ (A, X), (B, Y) } \\coloneqq \\cat{C}(A, B) \\times \\cat{D}(X, Y).\n    \\end{equation}\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms}\n    \\begin{align*}\n      (f, r)&: (A, X) \\to (B, Y) \\\\\n      (g, s)&: (B, Y) \\to (C, Z)\n    \\end{align*}\n    is the pairwise composition\n    \\begin{equation}\\label{eq:def:product_category/composition}\n      (g, s) \\bincirc (f, r) \\coloneqq \\underbrace{(g \\bincirc f, s \\bincirc r)}_{(A, X) \\to (C, Z)}.\n    \\end{equation}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} of the pair \\( (A, X) \\) is simply the pair of identity morphisms \\( (\\id_A, \\id_X) \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{definition}\\label{def:hom_functor}\n  Let \\( \\cat{C} \\) be a \\hyperref[def:category_size]{locally \\( \\mscrU \\)-small} category. We can regard the morphism sets \\( \\cat{C}(A, B) \\) as a functor parameterized by objects of \\( \\cat{C} \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:hom_functor/binary} For any pair of morphisms \\( f: B \\to A \\) and \\( g: X \\to Y \\) in \\( \\cat{C} \\), define the operator\n    \\begin{equation}\\label{eq:def:hom_functor/t}\n      \\begin{aligned}\n        &T_{f,g}: \\cat{C}(A, X) \\to \\cat{C}(B, Y) \\\\\n        &T_{f,g}(s) \\mapsto g \\bincirc s \\bincirc f.\n      \\end{aligned}\n    \\end{equation}\n\n    The action of \\( T_{f,g} \\) can be expressed graphically as\n    \\begin{equation}\\label{eq:def:hom_functor/t_diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__hom_functor.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    We can now define the following \\term{binary hom-functor}:\n    \\begin{equation}\\label{eq:def:hom_functor/binary}\n      \\begin{aligned}\n        &\\cat{C}(\\anon*, \\anon*): \\cat{C}^{\\opcat} \\times \\cat{C} \\to \\ucat{Set} \\\\\n        &\\cat{C}(A, X) \\coloneqq \\set{ s: A \\to X } \\\\\n        &\\cat{C}(f, g) \\coloneqq T_{f,g}\n      \\end{aligned}\n    \\end{equation}\n\n    \\thmitem{def:hom_functor/unary} Fixing the first argument \\( A \\) in \\eqref{eq:def:hom_functor/binary}, we instead obtain a covariant unary hom-functor:\n    \\begin{equation}\\label{eq:def:hom_functor/unary/covariant}\n      \\cat{C}(A, \\anon*): \\cat{C} \\to \\ucat{Set}\n    \\end{equation}\n\n    Analogously, fixing the second argument \\( X \\), we obtain a \\hyperref[def:hom_functor/unary]{contravariant} unary hom-functor:\n    \\begin{equation}\\label{eq:def:hom_functor/unary/contravariant}\n      \\cat{C}(\\anon*, X): \\cat{C}^{\\opcat} \\to \\ucat{Set}\n    \\end{equation}\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  It is sufficient to verify that \\eqref{eq:def:hom_functor/binary} defines a functor. \\ref{def:functor/CF2} can be seen to hold by inspecting the diagram:\n  \\begin{equation}\\label{eq:def:hom_functor/inv_composition}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/def__hom_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  The other functor condition \\ref{def:functor/CF1} is straightforward to prove.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:currying_is_natural_isomorphism}\n  \\hyperref[def:function/currying]{Function currying} is a natural isomorphism between the functors\n  \\begin{align*}\n    &\\cat{Set}(A \\times B, C)\n    &\\cat{Set}(A, \\cat{Set}(B, C))\n  \\end{align*}\n\n  More concretely, consider the following functors, which are loosely based in \\fullref{def:hom_functor}:\n  \\begin{equation*}\n    \\begin{aligned}\n      &V: \\cat{Set}^3 \\to \\cat{Set} \\\\\n      &V(A, B, C) \\coloneqq \\cat{Set}(A \\times B, C) \\\\\n      \\Big[& V(f: X \\to A, g: Y \\to B, h: C \\to Z) \\Big](s: A \\times B \\to C) \\coloneqq \\smash{ \\overbrace{ (x, y) \\mapsto h\\parens[\\Bigg]{ s\\parens[\\Big]{ \\underbrace{ f(x), g(y) }_{A \\times B} } } }^{X \\times Y \\to Z} } \\\\\n    \\end{aligned}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{aligned}\n      &W: \\cat{Set}^3 \\to \\cat{Set} \\\\\n      &W(A, B, C) \\coloneqq \\cat{Set}(A, \\cat{Set}(B, C)) \\\\\n      \\Big[& W(f: X \\to A, g: Y \\to B, h: C \\to Z) \\Big](t: A \\to \\cat{Set}(B, C)) \\coloneqq \\smash{ \\underbrace{ x \\mapsto \\overbrace{y \\mapsto h\\parens[\\Bigg]{ \\overbrace{t(f(x))}^{B \\to C}\\parens[\\Big]{ g(y) } } }^{Y \\to Z} }_{X \\to \\cat{Set}(Y, Z)} } \\\\\n    \\end{aligned}\n  \\end{equation*}\n\n  Then the family of functions\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\alpha: V \\Rightarrow W \\\\\n      &\\alpha_{A,B,C}(s: A \\times B \\to C) \\coloneqq a \\mapsto b \\mapsto s(a, b)\n    \\end{aligned}\n  \\end{equation*}\n  is a \\hyperref[thm:natural_isomorphism]{natural isomorphism}.\n\\end{proposition}\n\\begin{proof}\n  The function \\( \\varphi \\) is clearly invertible. Fix a triple of functions \\( f: X \\to A \\), \\( g: Y \\to B \\) and \\( h: C \\to Z \\). For every \\( s: A \\times B \\to C \\) we have\n  \\begin{align*}\n    [W(f, g, h)](\\alpha_{A,B,C}(s))\n    &=\n    x \\mapsto y \\mapsto \\parens[\\Big]{ h\\parens[\\Big]{ [a \\mapsto b \\mapsto s(a, b)](f(x))(g(y)) } }\n    = \\\\ &=\n    x \\mapsto y \\mapsto h\\parens[\\Big]{ s(f(x), g(y)) }\n    = \\\\ &=\n    \\alpha_{X,Y,Z}(V(f, g, h)),\n  \\end{align*}\n  which proves that the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:currying_is_natural_isomorphism/diagram}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__currying_is_natural_isomorphism.pdf}\n    \\end{aligned}\n  \\end{equation}\n\\end{proof}\n", "meta": {"hexsha": "123c186ade3b4ded007339ad444fa45febebd78c", "size": 60210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/functors.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/functors.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/functors.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": 64.5337620579, "max_line_length": 612, "alphanum_fraction": 0.6822620827, "num_tokens": 20098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650248, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6413016852796846}}
{"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*{Allan Overlapping Deviation}\n\n\\begin{par}\nExample for algorithm OADEV.\n\\end{par} \\vspace{1em}\n\\begin{par}\nOADEV is an algorithm to compute the overlapping Allan deviation for a set of time-domain frequency data.\n\\end{par} \\vspace{1em}\n\\begin{par}\nSee also W. J. Riley, \"The Calculation of Time Domain Frequency Stability\". Implementation: M. A. Hopcroft, \\verb\"mhopeng@gmail.com\", Matlab Central.'\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}\nA random numbers with normal probability distribution function will be generated into input data \\lstinline{DI.y.v}. Next a drift will be added.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI = [];\nDI.y.v = 1.5 + 3.*randn(1, 1e3);\nDI.y.v = DI.y.v + [1:1:1e3]./100;\n\\end{lstlisting}\n\\begin{par}\nLets suppose a sampling frequency is 1 Hz. The algorithm will generate all possible tau values automatically.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.fs.v = 1;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{OADEV} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDO = qwtb('OADEV', 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}\nLog log figure is the best to see allan deviation results:\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nfigure; hold on\nloglog(DO.tau.v, DO.oadev.v, '-b')\nloglog(DO.tau.v, DO.oadev.v + DO.oadev.u, '-k')\nloglog(DO.tau.v, DO.oadev.v - DO.oadev.u, '-k')\nxlabel('\\tau (sec)');\nylabel('\\sigma_y(\\tau)');\ntitle(['period = ' num2str(DI.fs.v)]);\ngrid('on'); hold off\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{algs_examples_published/OADEV_alg_example_01.pdf}\n\\end{center}\n\n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "161292e88230875a4c4c876718ed73284af6a9e8", "size": 2368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_OADEV.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_OADEV.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_OADEV.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.9263157895, "max_line_length": 150, "alphanum_fraction": 0.714527027, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6413016836667522}}
{"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{float}\n\\usepackage{subcaption}\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 } \\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}{#4}{#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{Project 2: Hedcut}{Fall 2019}{William Austin}{CS 633 Computational Geometry}\n\n\\section{Summary of the hedcut method}\n\nThe hedcut method that is implemented in this project is closely related to the idea of stippling, which uses a combination of dots to represent an image. Originally, this style of drawing was used in newspapers because they are typically black-and-white, can be easily printed on a page, and retained the important details of the image throughout this process. However, these works are also produced manually by a skilled artist and take several hours to complete. Therefore, this project explores how this style of art can be generated in an automated way, based off of an input image.\n\nThe provided functionality uses the concepts described in the paper ``Weighted Voronoi Stippling'', which is based on the concept of centroidal Voronoi diagrams. In order for a Voronoi diagram to be centroidal, the generating points must also be the centroid, which can be interpreted as the center of mass. For images, we can calculate the intensity at each pixel: ((R + G + B) / 3), and interpret it as a density function. Then, for each Voronoi cell, we can compute the centroid, based on the ``weight'' and location of each pixel in the cell.\n\nThe implementation is an iterative algorithm that starts off with random samples from the image. Then, we repeatedly:\n\\begin{enumerate}\n\t\\item Compute the Voronoi diagram for the given point locations, and\n\t\\item For each cell, find the centroid, and use it as the generating point for the next iteration.\n\\end{enumerate}\n\nWe must introduce some stopping criteria so that the algorithm eventually halts. In our case, we can specify an upper limit to the number of iterations performed or the distance the centroid moves in a step (total or average.) \n\n\\section{Improvement of hedcuter method}\n\nI've made several improvements to the provided functionality, listed below. In each section, I will give some examples, and intuition for the new features. A quick summary of the changes is given here, in the expanded options list for the hedcuter application:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.3]{HeducterCommandOptions}\n\t\\caption{Hedcuter Application Command Options}\n\\end{figure}\n\n\n\\subsection{Creating Voronoi Diagrams using OpenGL}\n\nThe first large improvement to the application was to use OpenGL to compute the Voronoi diagrams at each step in the algorithm. The idea is to construct a scene with a cone centered on the X-Y plane at each generating point. By fixing the camera to look at the all of the cones in the direction of the Z-axis, using a 2-D projection, the resulting scene is the Voronoi diagram.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.35]{VoronoiDiagram}\n\t\\caption{Voronoi Diagram, as computed by OpenGL}\n\t\\label{fig:voronoiDiagram}\n\\end{figure} \n\nOne of the problems that arises during the implementation of this feature is trying to map the regions in the rendered diagram back to the point that generated them. We do this by converting the index of the generating point $[0 \\dots n - 1]$ into the RGB color-space by transforming the index into a point in the range $[0 \\dots 256^3]$, and then representing it as $256^2 \\cdot R + 256 \\cdot G + B$. This tells Open GL what colors to use for the cones, and then we do the reverse transform to map the Voronoi regions of a certain color back to the correct generating point.\n\nSome other challenges that arise include:\n\\begin{itemize}\n\t\\item Model space in OpenGL is represented in X-Y coordinates, so (0, 0) is in the bottom-left of the screen, whereas OpenCV uses row-column format, with the pixel at (0, 0) in the upper-left of the screen. Therefore, when converting between the representations, we must flip the image, and reverse the coordinate order.\n\t\\item OpenGL initialization requires another library to control the window system, such as GLUT. Offline rendering does not seem to be especially well supported.\n\t\\item Internally, the OpenCV library uses a BGR representation for colors instead of the more traditional RGB. Therefore, we need to take care to convert correctly and make sure that the code is accessing the correct channel for the data structure.\n\\end{itemize} \n\nMost of my code for this feature is in the \\verb|vorgpu.hpp| and \\verb|vorgpu.cpp| files. A few changes to other files were required to integrated the command line option and call the correct functionality. This is in the \\verb|wcvt.cpp| file, in the \\verb|compute_weighted_cvt()| function. The functionality is enabled by specifying the \\verb|-useOpenGL| flag, with no options.\n\nI was able to get good stippling results using the OpenGL option. The example below shows the original input on the left, and the generated hedcut with 4000 disks.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t \t\\includegraphics[width=\\linewidth]{Snorlax}\n\t \t\\caption{Original Image, Snorlax}\n\t \t\\label{fig:snorlax}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Snorlax-OpenGL-4000}\n\t\t\\caption{Hedcut Image using OpenGL with 4000 Disks, Snorlax}\n\t\t\\label{fig:snorlaxOpenGL}\n\t\\end{subfigure}\n\t\\caption{OpenGL Example with Snorlax}\n\t\\label{fig:snorlaxExample}\n\\end{figure}\n\nDespite the complete implementation and reasonable output, I did not notice a large speedup when using the OpenGL functionality instead of the built-in method. In most cases, the total time taken is comparable. For example, the output below shows that OpenGL based method was slightly slower for 750 disks.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.35]{OpenGL-Performance}\n\t\\caption{Relative OpenGL Performance}\n\t\\label{fig:OpenGLPerformance}\n\\end{figure} \n\n\\subsection{Colored Disks, Grayscale Disks, and Background Color}\n\nFor the next feature to be added into the Hedcuter code, I added a few different ways to specify color in the output image. This includes:\n\n\\begin{itemize}\n\t\\item Use the \\verb|-diskColor R G B| option to specify a constant disk color. The default is black.\n\t\\item Use the \\verb|-bgColor R G B| option to specify a background color for the output. The default is no background (transparent).\n\t\\item Use the \\verb|-useGrayscaleColor| flag to create an image with disks based on the average grayscale intensity for each Voronoi cell to be represented.\n\t\\item Use the \\verb|-useAvgDiskColor| flag to create an image with disks based on the average color for each Voronoi cell to be represented.\n\\end{itemize} \n\nSome sample results are shown below.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Mount-Rushmore}\n\t\t\\caption{Original Image, Mount Rushmore}\n\t\t\\label{fig:mountRushmore}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Mount-Rushmore-Red-15000}\n\t\t\\caption{Red Hedcut Image with 15000 Disks}\n\t\t\\label{fig:mountRusmoreRed}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Mount-Rushmore-Blue-15000}\n\t\t\\caption{Blue Hedcut Image with 15000 Disks}\n\t\t\\label{fig:mountRusmoreBlue}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Mount-Rushmore-Inverted-15000}\n\t\t\\caption{Inverted Hedcut Image with 15000 Disks}\n\t\t\\label{fig:mountRusmoreInverted}\n\t\\end{subfigure}\n\t\\caption{Color Example with Mount Rushmore}\n\t\\label{fig:mountRushmoreEx}\n\\end{figure}\n\nA more dynamic coloring approach can be seen by using the grayscale color and average color options. This is accomplished by simply averaging all of the cell colors together to choose an approximation of the input color when we create the disks for the hedcut.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.52\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Jordan-Pond}\n\t\t\\caption{Original Image, Jordan Pond}\n\t\t\\label{fig:jordanPond}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Jordan-Pond-Grayscale-10000}\n\t\t\\caption{Jordan Pond, Grayscale, 10000 Disks}\n\t\t\\label{fig:jordanPondGray}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Jordan-Pond-Color-10000}\n\t\t\\caption{Jordan Pond, Colored, 10000 Disks}\n\t\t\\label{fig:jordanPondColor}\n\t\\end{subfigure}\n\t\\caption{Colore Example with Jordan Pond}\n\t\\label{fig:jordanPondExample}\n\\end{figure}\n\n\n\\subsection{Disk Sizing based on Cell Area and Intensity, with Regularization}\n\nI have also implemented dynamic disk sizing to produced different visual effects in the final hedcut image. The first way of doing this is to scale the size of each disk by the size of the containing Voronoi cell. This is done by specifying \\verb|-areaScaling scaleFactor|. In the example with Roger Federer, you can see that the disks on the handle of the racket and his grip are much larger than the rest of the disks in the second example, but much smaller in second example because we specified a negative value to invert the relationship.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.52\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Roger-Federer}\n\t\t\\caption{Original Image, Roger Federer}\n\t\t\\label{fig:rf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Roger-Federer-AreaScale-12000}\n\t\t\\caption{Roger Federer, Area scaled, 12000 Disks}\n\t\t\\label{fig:rf2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Roger-Federer-ReverseAreaScaling-12000}\n\t\t\\caption{Roger Federer, Reverse area scaled, 12000 Disks}\n\t\t\\label{fig:rf3}\n\t\\end{subfigure}\n\t\\caption{Area Scaling Example with Roger Federer}\n\t\\label{fig:rf4}\n\\end{figure}\n\nWe can perform the same scaling operation, but use the average intensity of the cell as the input, instead of the cell area. This is shown below when we specify the \\verb|-areaScaling scaleFactor| option. As expected, in the first image, the darker areas produce larger disks, and the lighter areas produce smaller disks. The relationship is reversed for the second example when we pass a negative argument.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.52\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Emilee-And-Lola}\n\t\t\\caption{Original Image, Girl and Dog}\n\t\t\\label{fig:gff}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Emilee-And-Lola-IntensityScaled2-10000}\n\t\t\\caption{Intensity scaled, 10000 Disks}\n\t\t\\label{fig:rff2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Emilee-And-Lola-IntensityScaled-10000}\n\t\t\\caption{Reverse Intensity scaled, 10000 Disks}\n\t\t\\label{fig:rff3}\n\t\\end{subfigure}\n\t\\caption{Intensity Scaling Example with Girl and Dog}\n\t\\label{fig:rff4}\n\\end{figure}\n\nWe can also apply a regularization process to artificially introduce some variation into the stippling. For example, in the area scaling example, most of the cells are about the same size with a few outliers. In the regularization process, we push the distribution of disk sizes to be more uniform, based on a regularization factor from 0 to 1. The images below show an image of train with negative area scaling and regularization values of 0, 0.3 and 0.8. This effect is enabled by using the \\verb|-regularize factor| command. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Train-Canada}\n\t\t\\caption{Original Image, Train}\n\t\t\\label{fig:train}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Train-Canada-8000-1}\n\t\t\\caption{Reverse area scaling, R = 0}\n\t\t\\label{fig:train1}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Train-Canada-8000-2}\n\t\t\\caption{Reverse area scaling, R = 0.3}\n\t\t\\label{fig:train2}\n\t\\end{subfigure}\n\t\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Train-Canada-8000-3}\n\t\t\\caption{Reverse area scaling, R = 0.8}\n\t\t\\label{fig:train3}\n\t\\end{subfigure}\n\t\\caption{Regularization Example with Train}\n\t\\label{fig:mountRusddhmoreEx}\n\\end{figure}\n\n\\subsection{More Dynamic Initial Sampling}\n\nWe have also  implemented a tweak to allow greater control over the sampling process. This is enabled with the \\verb|-samplingWeight weight| command option. The effect of this is that we are more selective when keeping or throwing away points during the initial sampling. A larger value means that lighter pixels are less likely to get chosen and darker pixels are more likely to be included. In the example below, we see the results for a sampling weight of 0 (uniform distribution), and a sampling weight of 3. Note that we have implemented this as a linear cutoff and large values may lead to an infinite loop because not enough points are eligible for inclusion, so care must be taken.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.52\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Chessboard}\n\t\t\\caption{Original Image, Chessboard}\n\t\t\\label{fig:gfff}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Chessboard-Points-1}\n\t\t\\caption{Uniform sample points, 6000 Disks}\n\t\t\\label{fig:rfff2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Chessboard-6000-1}\n\t\t\\caption{Stippled Chessboard 1, 600 Disks}\n\t\t\\label{fig:rfff3}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Chessboard-Points-2}\n\t\t\\caption{Weighted sample points, 6000 Disks}\n\t\t\\label{fig:rffdf2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Chessboard-6000-2}\n\t\t\\caption{Stippled Chessboard 2, 600 Disks}\n\t\t\\label{fig:rfffd3}\n\t\\end{subfigure}\n\t\\caption{Initial Sampling Example with Chessboard}\n\t\\label{fig:rfff4}\n\\end{figure}\n\n\\subsection{Edge Detection}\n\nThe last feature that we have included in the application is the ability to incorporate information about edges in the input image into the stipple pattern. This enabled by using the \\verb|-detectEdges alpha| option. If this is specified, we use OpenCV to detect edges in the input image, using the Sobel operator. Then, we create a linear combination of this output with the grayscale input image, to be used when computing the cell centroids at each step. This helps drag cell centers toward edges in the input image, creating a more well-defined output hedcut, as shown below.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Portrait}\n\t\t\\caption{Original Image, Portrait}\n\t\t\\label{fig:trafin}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Portrait-Sobel}\n\t\t\\caption{Portrait after Sobel Operator (k=3)}\n\t\t\\label{fig:trxain1}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Portrait-7000-1}\n\t\t\\caption{Portrait Stippling Default}\n\t\t\\label{fig:traixn2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.48\\linewidth}\n\t\t\\includegraphics[width=\\linewidth]{Portrait-7000-2}\n\t\t\\caption{Portrait Stippling with Edge Detection}\n\t\t\\label{fig:traxin3}\n\t\\end{subfigure}\n\t\\caption{Edge Detection Example with Portrait}\n\t\\label{fig:mountRusdxdhmoreEx}\n\\end{figure}\n\n\\section{Conclusion}\n\nThis project was a good example of how computer vision and computation geometry algorithms can be applied to interesting real world problems. All of the code that I implemented is completed, and the submitted application runs without any errors. However, there are several things that could be improved or expanded upon. Some examples are:\n\n\\begin{itemize}\n\t\\item When using the OpenGL Voronoi diagram option, cells seem to converge somewhat more slowly than using the original method. All of my code is a drop-in replacement for the \\verb|vor()| method, so I was a bit confused by this because the \\verb|move_sites()| code is exactly the same, regardless of whether the option is on or not.\n\t\\item There are several cases in the code where I have commented out print statements, or dead code. Throughout the course of this project, I spent considerable time experimenting with different ways of doing things and did not have time to clean up everything.\n\t\\item An idea for improvement is to support alpha channels for the disk and background coloring functionality.\n\t\\item Another improvement would be to have support for color scaling, so that stipples could be different shades of the same color (variable intensity). This would look like a grayscale image, but with a different hue.\n\t\\item There are also performance improvements that could be made. For example, I did not implement Fortune's algorithm. In addition, my focus for this project was to enhance the visual aspects of the produced hedcut images, so it is likely that portions of my code could be implemented more cleanly and efficiently.\n\\end{itemize}\n\n\\bibliographystyle{plain}\n\\bibliography{report}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "5a64ec2c32406d2b53e6c2dcf4fb39dfde582e17", "size": 18380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/report.tex", "max_stars_repo_name": "william-r-austin/hedcut", "max_stars_repo_head_hexsha": "58c6e452439a4abaf2bf09e09393e9a267fe2fe4", "max_stars_repo_licenses": ["MIT"], "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/report.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": "report/report.tex", "max_forks_repo_name": "william-r-austin/hedcut", "max_forks_repo_head_hexsha": "58c6e452439a4abaf2bf09e09393e9a267fe2fe4", "max_forks_repo_licenses": ["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.3407821229, "max_line_length": 689, "alphanum_fraction": 0.7722524483, "num_tokens": 5035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6413016802683813}}
{"text": "\\chapter{补充内容}\n\\section{$L^{p}$ Spaces for $0<p<1$}\n下面内容来自Matt Rosenzweig:\n\\subsection{Complete Quasi-Normed Space}\n\\begin{lemma}\nIf $p \\in(0,1)$ and $a, b \\geq 0$, then\n\\[\n    (a+b)^{p} \\leq a^{p}+b^{p}\n\\]\nwith equality if and only if either a or $b$ is zero.\n\\end{lemma}\n\\begin{proof}\n    Define a function $f(t):=(1+t)^{p}-1-t^{p}$ for $t \\geq 0 .$ Then $f^{\\prime}(t)=p(1+t)^{p-1}-p t^{p-1}<0$ for all $t \\in(0, \\infty)$. Since $f(0)=0$, it follows that $f(t)<0$ on $\\left(0, \\infty\\right.$. If $a, b \\neq 0$, then substituting $t=\\frac{a}{b}$\n    \\[\n        \\left(1+\\frac{a}{b}\\right)^{p}-1-\\left(\\frac{a}{b}\\right)^{p}<0 \\Longleftrightarrow\\left(\\frac{a+b}{b}\\right)^{p}-1-\\left(\\frac{a}{b}\\right)^{p}<0 \\Longleftrightarrow(a+b)^{p}-\\left(a^{p}+b^{p}\\right)<0\n    \\]\n    The equality criterion is obvious from the fact that $f$ is strictly decreasing on $(0, \\infty)$.\n    Recall that a pair $(X,\\|\\cdot\\|)$, consiting of a (real or complex) vector space $X$ and a function $\\|\\cdot\\|: X \\rightarrow \\mathbb{R}^{\\geq 0}$ satisfying $\\|\\lambda x\\|=|\\lambda|\\|x\\|$, is a quasinormed space, if there exists $K \\geq 1$ such that\n    \\[\n        \\|x+y\\| \\leq K(\\|x\\|+\\|y\\|) \\quad \\forall x, y \\in X \\qedhere\n    \\]\n\\end{proof}\n\n\\begin{proposition}\n    For $0<p<\\infty,\\left(L^{p}(X, \\mu),\\|\\cdot\\|_{L^{p}}\\right)$ is a complete quasinormed space.\n\\end{proposition}\n\\begin{proof}\n    We can define a distance function on $L^{p}(X, \\mu)$ by\n    \\[\n        d(f, g):=\\|f-g\\|_{L^{p}}^{p}=\\int_{X}|f-g|^{p} d \\mu\n    \\]\n    The only metric axiom which isn't obvious is the triangle inequality. Applying the preceding lemma, for all $f, g, h \\in L^{p}(X, \\mu)$\n    \\[\n        d(f, g)+d(g, h)=\\int_{X}\\left(|f-g|^{p}+|g-h|^{p}\\right) d \\mu \\geq \\int_{X}(|f-g|+|g-h|)^{p} d \\mu \\geq \\int_{X}|f-h|^{p} d \\mu=d(f, h)\n    \\]\n    Since $\\left\\|f_{n}-f_{m}\\right\\|_{L^{p}} \\rightarrow 0, n, m \\rightarrow \\infty \\Longleftrightarrow d\\left(f_{n}, f_{m}\\right) \\rightarrow 0, n, m \\rightarrow \\infty$ by the continuity of the maps $x \\mapsto x^{p}$ and $x \\mapsto x^{\\frac{1}{p}}$, to show that $d$ is a complete metric, it suffices to show that given a sequence $\\left(f_{n}\\right)_{n=1}^{\\infty}$\n    \\[\n        \\left\\|f_{n}-f_{m}\\right\\|_{L^{p}}^{p} \\rightarrow 0, n, m \\rightarrow \\infty \\Rightarrow \\exists f \\in L^{p},\\left\\|f_{n}-f\\right\\|_{L^{p}}^{p} \\rightarrow 0, n \\rightarrow \\infty\n    \\]\n    Let $\\left(f_{n}\\right)_{n=1}^{\\infty}$ be such a sequence. Then we can construct a subsequence $\\left(f_{n_{k}}\\right)_{k \\in \\mathbb{N}}$ such that $\\left\\|f_{n_{k}}-f_{n_{k+1}}\\right\\|_{L^{p}}^{p} \\leq \\frac{1}{2^{k}}$. Define\n    \\[\n        f=f_{n_{1}}+\\sum_{k=1}^{\\infty}\\left(f_{n_{k+1}}-f_{n_{k}}\\right)\n    \\]\n    Since\n    \\[\n        \\left\\|\\sum_{k=1}^{N}\\left(f_{n_{k+1}}-f_{n_{k}}\\right)\\right\\|_{L^{p}}^{p} \\leq \\sum_{k=1}^{N}\\left\\|f_{n_{k+1}}-f_{n_{k}}\\right\\|_{L^{p}}^{p} \\leq \\sum_{k=1}^{N} \\frac{1}{2^{k}} \\leq 1 \\forall N \\in \\mathbb{N}\n    \\]\n    it follows from the monotone convergence theorem, $\\left|f_{n_{1}}\\right|+\\sum_{k=1}^{\\infty}\\left|f_{n_{k+1}}-f_{n_{k}}\\right| \\in L^{p}(X, \\mu) .$ Hence, by the Lebesgue dominated convergence theorem, $f \\in L^{p}(X, \\mu)$.\n    \\[\n    f_{1}+\\sum_{k=1}^{N}\\left(f_{n_{k+1}}-f_{n_{k}}\\right)=f_{n_{N+1}} \\Rightarrow \\lim _{k \\rightarrow \\infty} f_{n_{k}}=f\n    \\]\n    Hence, $\\left(f_{n}\\right)_{n=1}^{\\infty}$ is Cauchy with a convergent subsequence and therefore $\\left\\|f_{n}-f\\right\\|_{L^{p}}^{p} \\rightarrow 0$, as $n \\rightarrow \\infty$\n\\end{proof}\n\\subsection{Inequalities}\n\\begin{proposition}[Reverse Hölder's]\n    Let $q \\in(0,1) .$ For $r<0$ and $g>0 \\mu-a . e .$, define $\\|g\\|_{L^{r}}:=\\left\\|g^{-1}\\right\\|_{L^{|r|}}^{-1}$. Then for $f \\geq 0$ and $g>0 \\mu-$ a.e., we have that\n    \\[\n        \\|f g\\|_{L^{1}} \\geq\\|f\\|_{L^{q}}\\|g\\|_{L^{q^{\\prime}}}\n    \\]\n    where $\\frac{1}{q}+\\frac{1}{q^{\\prime}}=1$\n\\end{proposition}\n\\begin{proof}\n    If $f g \\notin L^{1}(X, \\mu)$ (i.e. $\\|f g\\|_{L^{1}}=\\infty$ ) or $g^{-1} \\notin L^{q^{\\prime}}(X, \\mu)$, then the inequality is trivial. So assume otherwise. Since $q \\in(0,1)$ and $1=\\frac{1}{q}+\\frac{1}{q^{\\prime}}$, we have that $q^{\\prime}<0$ and\n    \\[\n        \\frac{1}{q}=\\frac{1}{1}+\\frac{1}{\\left|q^{\\prime}\\right|}\n    \\]\n    By Hölder's inequality applied to $f g$ and $g^{-1} \\in L^{\\left|q^{\\prime}\\right|}$,\n    \\[\n        \\|f\\|_{L^{q}}=\\left\\|f g g^{-1}\\right\\|_{L^{q}} \\leq\\|f g\\|_{L^{1}}\\left\\|g^{-1}\\right\\|_{L^{\\prime q^{\\prime}} \\mid} \\Rightarrow\\|f\\|_{L^{q}}\\|g\\|_{L^{q^{\\prime}}}=\\|f\\|_{L^{q}}\\left\\|g^{-1}\\right\\|_{L^{\\left|q^{\\prime}\\right|}} \\leq\\|f g\\|_{L^{1}}\\qedhere\n    \\]\n\\end{proof}\n\n\\begin{proposition}[Reverse Minkowski's]\n    Let $f_{1}, \\cdots, f_{N} \\in L^{p}(X, \\mu)$, where $0<p<1$ Then\n    \\[\n        \\sum_{j=1}^{N}\\left\\|f_{j}\\right\\|_{L^{p}} \\leq\\left\\|\\sum_{j=1}^{N}\\left|f_{j}\\right|\\right\\|_{L^{p}}\n    \\]\n\\end{proposition}\n\\begin{proof}\n    By induction it suffices to consider the case $N=2 .$ If $\\left\\|\\left|f_{1}\\right|+\\left|f_{2}\\right|\\right\\|_{L^{p}}=\\infty$, then the stated inequality is trivially true, so assume otherwise. Furthermore, if either $f_{1}$ or $f_{2}$ are zero $\\mu-. a . e$, then the inequality is also trivial, so assume otherwise. By the reverse Hölder's inequality,\n    \\[\n        \\begin{aligned}\n        \\left\\|\\left|f_{1}\\right|+\\left|f_{2}\\right|\\right\\|_{L^{p}}^{p}=\\int_{X}\\left\\|f_{1}|+| f_{2}\\right\\|^{p} d x &=\\int_{X}\\left|f_{1}\\right|\\left\\|f_{1}|+| f_{2}\\right\\|^{p-1} d x+\\int_{X}\\left|f_{2}\\right|\\left\\|f_{1}|+| f_{2}\\right\\|^{p-1} d x \\\\\n        & \\geq\\left\\|f_{1}\\right\\|_{L^{p}}\\left\\|\\left(\\left|f_{1}\\right|+\\left|f_{2}\\right|\\right)^{p-1}\\right\\|_{L^{\\frac{p}{p-1}}}+\\left\\|f_{2}\\right\\|_{L^{p}}\\left\\|\\left(\\left|f_{1}\\right|+\\left|f_{2}\\right|\\right)^{p-1}\\right\\|_{L^{\\frac{p}{p-1}}} \\\\\n        &=\\left(\\left\\|f_{1}\\right\\|_{L^{p}}+\\left\\|f_{2}\\right\\|_{L^{p}}\\right)\\left\\|\\left|f_{1}\\right|+\\left|f_{2}\\right|\\right\\|_{L^{p}}^{p-1}\n        \\end{aligned}\n    \\]\n    Dividing both sides by $\\left\\|f_{1}+f_{2}\\right\\|_{L^{p}}^{p-1}$ yields the stated inequality. \n\\end{proof}\nThe preceding proposition shows that $\\left(L^{p}(X, \\mu),\\|\\cdot\\|_{L^{p}}\\right)$ is not a normed space when $0<p<\\infty$.\n\n\\begin{lemma}\n    Suppose $1 \\leq \\theta<\\infty$. Then for $a_{1}, \\cdots, a_{N} \\in \\mathbb{R}^{\\geq 0}$,\n    \\[\n        \\left(\\sum_{j=1}^{N} a_{j}\\right)^{\\theta} \\leq N^{\\theta-1} \\sum_{j=1}^{N} a_{j}^{\\theta}\n    \\]\n\\end{lemma}\n\\begin{proof}\n    Since $\\theta \\geq 1$, the function $f(x)=x^{\\theta}$ is convex. Hence,\n    \\[\n        \\left(\\sum_{j=1}^{N} a_{j}\\right)^{\\theta}=f\\left(\\frac{\\sum_{j=1}^{N} N a_{j}}{N}\\right) \\leq \\frac{1}{N} \\sum_{j=1}^{N} f\\left(N a_{j}\\right)=N^{\\theta-1} \\sum_{j=1}^{N} a_{j}^{\\theta} \\qedhere\n    \\]\n\\end{proof}\n\n\\begin{proposition}\n    For $0<p<1$,\n    \\[\n        \\left\\|\\sum_{j=1}^{N} f_{j}\\right\\|_{L^{p}} \\leq N^{\\frac{1-p}{p}} \\sum_{j=1}^{N}\\left\\|f_{j}\\right\\|_{L^{p}}\n    \\]\n    Furthermore, $N^{\\frac{1-p}{p}}$ is the best possible constant.\n\\end{proposition}\n\\begin{proof}\n    If $\\left\\|f_{j}\\right\\|_{L^{p}}=\\infty$ for some $j$, then the inequality trivially holds, so assume otherwise. Since $\\frac{1}{p}>1$, by the preceding lemma,\n    \\[\n        \\left\\|\\sum_{j=1}^{N} f_{j}\\right\\|_{L^{p}}=\\left(\\int_{X}\\left|\\sum_{j=1}^{N} f_{j}\\right|^{p} d x\\right)^{\\frac{1}{p}} \\leq\\left(\\sum_{j=1}^{N} \\int_{X}\\left|f_{j}\\right|^{p} d x\\right)^{\\frac{1}{p}} \\leq N^{\\frac{1}{p}-1} \\sum_{j=1}^{N}\\left(\\int_{X}\\left|f_{j}\\right|^{p} d x\\right)^{\\frac{1}{p}}=N^{\\frac{1-p}{p}} \\sum_{j=1}^{N}\\left\\|f_{j}\\right\\|_{L^{p}}\n    \\]\n    To see that $N^{\\frac{1-p}{p}}$ is the best possible constant, let $E$ be a measurable set such that $\\mu(E)=\\alpha<\\infty$, and set $E_{j}:=E$ and $f_{j}:=\\mathbf{1}_{E}$ for $1 \\leq j \\leq N$. Then\n    \\[\n        \\left\\|\\sum_{j=1}^{N} f_{j}\\right\\|_{L^{p}}=\\left(\\sum_{j=1}^{N} \\mu\\left(E_{j}\\right)\\right)^{\\frac{1}{p}}=(N \\alpha)^{\\frac{1}{p}}=N^{\\frac{1-p}{p}}\\left(N \\alpha^{\\frac{1}{p}}\\right)=N^{\\frac{1-p}{p}} \\sum_{j=1}^{N} \\mu\\left(E_{j}\\right)^{\\frac{1}{p}}=N^{\\frac{1-p}{p}} \\sum_{j=1}^{N}\\left\\|f_{j}\\right\\|_{L^{p}}\n    \\]\n\\end{proof}\n\\subsection{Day's theorem}\n\\begin{lemma}\n    Let $(X, \\mathcal{A}, \\mu)$ be a measure space with the property that given any $f \\in L^{p}(X, \\mu)$ for $p \\in(0,1)$, the functional\n    \\[\n        \\mathcal{A} \\rightarrow \\mathbb{R}, E \\mapsto \\int_{E}|f|^{p} d \\mu\n    \\]\n    assumes all values between 0 and $\\|f\\|_{L^{p}}^{p}$. Then $L^{p}(X, \\mu)$, with $0<p<1$, contains no convex open sets, other than $\\emptyset$ and $L^{p}(X, \\mu)$\n\\end{lemma}\n\n\\begin{proof}\n    Let $\\Omega$ be a nonempty convex open neighborhood of the origin in $L^{p}(X)$ and $f \\in L^{p}(X)$ be arbitrary. Since $\\Omega$ is open, there exists a ball $B_{\\delta}$ about the origin contained in $\\Omega .$ Choose $n \\in \\mathbb{Z}^{\\geq 1}$ such that $\\frac{\\|f\\|_{L^{p}}^{p}}{n^{1-p}} \\leq \\delta$ (i.e. $\\left.n f \\in B_{n \\delta}\\right)$. Note that we can choose such a $n$ precisely because $p \\in(0,1)$. Using the intermediate value hypothesis for the measure space, there exists a measurable set $E_{1}$ such that\n    \\[\n        \\int_{E_{1}}|f|^{p} d \\mu=\\frac{1}{n} \\int_{X}|f|^{p} d \\mu=\\frac{\\|f\\|_{L^{p}}^{p}}{n}\n    \\]\n    Repeating the argument for $f_{1}=f \\mathbf{1}_{E_{1}^{c}}$ and apply induction, we obtain a partition $\\left\\{E_{1}, \\cdots, E_{n}\\right\\}$ of $X$ into disjoint measurable subsets such that $\\int_{E_{j}}|f|^{p}=\\frac{\\|f\\|_{L^{p}}^{p}}{n} \\forall j=1, \\cdots, n .$ Define $h_{j}:=n f \\mathbf{1}_{E_{j}} .$ Then by our choice of $n$,\n    \\[\n        \\int_{X}\\left|h_{j}\\right|^{p} d \\mu=\\int_{E_{j}} n^{p}|f|^{p} d \\mu=\\frac{1}{n^{1-p}} \\int_{X}|f|^{p} d \\mu \\leq \\delta\n    \\]\n    Hence, $h_{j} \\in B_{\\delta} \\subset \\Omega \\forall j=1, \\cdots, n$. By convexity,\n    \\[\n        f=\\frac{h_{1}+\\cdots+h_{n}}{n} \\in \\Omega\n    \\]\n    Since $f \\in L^{p}(X, \\mu)$ was arbitrary, we obtain that $\\Omega=L^{p}(X, \\mu)$\n\\end{proof}\n\\begin{corollary}\n    With $(X, \\mathcal{A}, \\mu)$ as above, the natural topology for $L^{p}(X, \\mu)$, with $0<p<1$, is not locally convex.\n\\end{corollary}\n\nThe following result, originally proven by M.M. Day, shows that the Hahn-Banach theorem fails for $L^{p}(X, \\mu)$, when $0<p<1$. Specifically, the Hahn-Banach theorem may fail when we only assume the underlying space is quasi-normed.\n\n\\begin{theorem}[M.M. Day]\n    Let $p \\in(0,1)$ and let $T: L^{p}(X, \\mu) \\rightarrow Y$ be a continuous linear mapping of $L^{p}(X, \\mu)$ into a locally convex $T_{0}$ space $Y$ (i.e. singletons are closed). Then $T$ is the zero map. In particular, $L^{p}(X, \\mu)^{*}=\\{0\\}$\n\\end{theorem}\n\n\\begin{proof}\n    Let $T$ be such a map, and let $\\mathcal{B}$ be a convex local base for $Y$ at the origin. Let $W \\in \\mathcal{B}$. Then $T^{-1}(W)$ is a nonempty open convex subset of $L^{p}(X, \\mu)$, hence by the preceding lemma, $T^{-1}(W)=L^{p}(X, \\mu)$. Hence, $T\\left(L^{p}(X, \\mu)\\right) \\subset W$ for all $W \\in \\mathcal{B} .$ I claim that $\\bigcap_{W \\in \\mathcal{B}} W=\\{0\\} .$ Assume the contrary, and let $x \\neq 0$ be in the intersection. Since singletons are closed in $Y, Y \\backslash\\{x\\}$ is an open neighborhood of $0 .$ Hence, $\\bigcap_{W \\in \\mathcal{B}} W \\subset(Y \\backslash\\{x\\})$, which is a contradiction. We conclude that $T\\left(L^{p}(X, \\mu)\\right)=\\{0\\} \\Longleftrightarrow T=0$.\n\\end{proof}\n\\subsection{Non-Normability}\nOne might ask if $L^{p}(X, \\mu), 0<p<1$, is normable for an arbitrary measure space $(X, \\mathcal{A}, \\mu)$. The following example shows that it is not, even for a nice measure space.\n\n\\begin{proposition}\n    Let $\\left(f_{n}\\right)_{n=1}^{\\infty}$ be a sequence in $L^{p}([0,1], \\mathcal{L}, \\lambda)$, where $\\mathcal{L}$ is the Lebesgue $\\sigma$-algebra and $\\lambda$ is the Lebesgue measure on $[0,1] .$ Then there does not exist a norm $\\|\\cdot\\|$ on $L^{p}([0,1])$ such that for any sequence $\\left(f_{n}\\right)_{n \\in \\mathbb{N}} \\subset L^{p}([0,1]), f_{n} \\rightarrow 0$ in $L^{p} \\Rightarrow\\left\\|f_{n}\\right\\| \\rightarrow 0, n \\rightarrow \\infty$\n\\end{proposition}\n\n\\begin{proof}\n    Suppose such a norm $\\|\\cdot\\|$ exists. I claim that there exists a positive constant $C<\\infty$ such that $\\|f\\| \\leq$ $C\\|f\\|_{L^{p}} \\forall f \\in L^{p}([0,1]) .$ Indeed, the map $L^{p}([0,1]) \\rightarrow \\mathbb{R}, f \\mapsto\\|f\\|$ is evidently continuous. Hence, there exists $\\delta>0$ such that $\\|f\\|_{L^{p}}<\\delta \\Rightarrow\\|f\\| \\leq 1$. Then $\\forall f \\in L^{p}([0,1]), \\frac{\\alpha \\delta f}{\\|f\\|_{L^{p}}} \\in B_{\\delta}$, where $0<|\\alpha|<1 .$ Hence,\n    \\[\n        \\left\\|\\frac{\\alpha \\delta f}{\\|f\\|_{L^{p}}}\\right\\| \\leq 1 \\Rightarrow\\|f\\| \\leq \\frac{1}{\\alpha \\delta}\\|f\\|_{L^{p}}\n    \\]\n    Letting $\\alpha \\rightarrow 1$, we see that the inequality holds for $C=\\frac{1}{\\delta} .$ Choose $C=\\inf \\left\\{K:\\|f\\| \\leq K\\|f\\|_{L^{p}} \\forall f \\in L^{p}([0,1])\\right\\}$ (Note that we do not exclude the possibility that $C=0$ ). By the intermediate value theorem, there exists $c \\in(0,1)$ such that\n    \\[\n        \\int_{0}^{c}|f|^{p} d \\lambda=\\int_{c}^{1}|f|^{p} d \\lambda=\\frac{1}{2} \\int_{0}^{1}|f|^{p} d \\lambda\n    \\]\n    Set $g=f \\chi_{[0, c]}$ and $h=f \\chi_{(c, 1]} .$ Then $f=g+h$ and $\\|g\\|_{L^{p}}=\\|h\\|_{L^{p}}=2^{-\\frac{1}{p}}\\|f\\|_{L^{p}} .$ By the triangle inequality,\n    \\[\n        \\|f\\| \\leq\\|g\\|+\\|h\\| \\leq C\\left(\\|g\\|_{L^{p}}+\\|h\\|_{L^{p}}\\right)=\\frac{C}{2^{\\frac{1}{p}-1}}\\|f\\|_{L^{p}}\n    \\]\n    Since $p \\in(0,1), \\frac{C}{2^{\\frac{1}{p}-1}} \\leq C \\Rightarrow C=0 \\Rightarrow\\|f\\|=0 ,\\forall f \\in L^{p}(X, \\mu)$, which contradicts that $\\|\\cdot\\|$ is a norm.\n\\end{proof}\n\n\\begin{remark}\n    In fact, the non-normability of $L^{p}([0,1])$, when $0<p<1$, follows from M.M. Day's thoerem. If $L^{p}([0,1])$ were normable, then the Hahn-Banach theorem would hold, contradicting that $L^{p}([0,1])^{*}=\\{0\\}$. So we have the more general assertion that given any measure space $(X, \\mathcal{A}, \\mu)$ which satisfies the hypotheses of Day's theorem, $L^{p}(X, \\mu)$ is non-normable.\n\\end{remark}", "meta": {"hexsha": "bc4ade2ce43c4ad756ad05488882eed8fec91290", "size": 14038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "back/Appendix_complement.tex", "max_stars_repo_name": "xkwxdyy/Function_Analysis_notes", "max_stars_repo_head_hexsha": "08dc86defb36de79751419ad2dd6417fd4645c84", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "back/Appendix_complement.tex", "max_issues_repo_name": "xkwxdyy/Function_Analysis_notes", "max_issues_repo_head_hexsha": "08dc86defb36de79751419ad2dd6417fd4645c84", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "back/Appendix_complement.tex", "max_forks_repo_name": "xkwxdyy/Function_Analysis_notes", "max_forks_repo_head_hexsha": "08dc86defb36de79751419ad2dd6417fd4645c84", "max_forks_repo_licenses": ["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.2934782609, "max_line_length": 698, "alphanum_fraction": 0.575580567, "num_tokens": 5874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6413016726651729}}
{"text": "\\documentclass{article}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\n\\newcommand{\\ket}[1]{\\ensuremath{\\left\\vert #1 \\right \\rangle}}\n\\newcommand{\\weight}[1]{\\ensuremath{\\mathrm{w}\\left(#1\\right)}}\n\n\\begin{document}\n\n\\section*{Change in mutation operator}\n\nLet $\\Sigma=\\{0,1\\}$. Consider an $n$ length string $\\mathbf{x} \\in\n\\Sigma^n$. A flip in positions $\\mathbf{a} \\in \\Sigma^n$ is defined\nusing the operator \n\n\\[\nU_{\\mathbf{a}} \\ket{\\mathbf{x}} = \\ket{\\mathbf{x} + \\mathbf{a}}\n\\]\n\nIn the quantum setting there is a possibility of applying the phase\nflip as well which is defined using the operator $V_\\mathbf{b}$ as\n\n\\[\nV_\\mathbf{b} \\ket{\\mathbf{x}} =\n(-1)^{\\mathbf{b}^{\\mathrm{T}}\\mathbf{x}} \\ket{\\mathbf{x}}.\n\\]\n\nIn general for $\\mathbf{a}$ and $\\mathbf{b}$ in $\\Sigma^n$, let\n$W_{\\mathbf{a},\\mathbf{b}}$ denote the operator\n$U_\\mathbf{a}V_\\mathbf{b}$, then candidate solutions $\\ket{x}$ can be\nmutated by applying any of the operators $W_{\\mathbf{a},\\mathbf{b}}$.\n\nThe parameter of interest here is the joint weight defined as\n\n\\[\n\\weight{\\mathbf{a},\\mathbf{b}} = \\# \\{ i | (a_i,b_i) \\neq (0,0) \\}.\n\\]\n\nLocal search and EA on an average make only one mutation per\nstep. This can be modeled by making transformation\n$W_{\\mathbf{a},\\mathbf{b}}$ where the average joint weight\n$\\weight{\\mathbf{a},\\mathbf{b}}$.\n\n\\end{document}\n", "meta": {"hexsha": "106e7955042dd11fbec4aea76599d72d00a80aad", "size": 1327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "contents/research/publication/Journal/2014-01-01-Evolutionary-Algorithms-For-Quantum-Computers/ideas.tex", "max_stars_repo_name": "piyush-kurur-pages/website", "max_stars_repo_head_hexsha": "246dfa730328b45b65840ebed3293e96c497aa86", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-16T09:55:17.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-16T09:55:17.000Z", "max_issues_repo_path": "contents/research/publication/Journal/2014-01-01-Evolutionary-Algorithms-For-Quantum-Computers/ideas.tex", "max_issues_repo_name": "piyush-kurur-pages/website", "max_issues_repo_head_hexsha": "246dfa730328b45b65840ebed3293e96c497aa86", "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": "contents/research/publication/Journal/2014-01-01-Evolutionary-Algorithms-For-Quantum-Computers/ideas.tex", "max_forks_repo_name": "piyush-kurur-pages/website", "max_forks_repo_head_hexsha": "246dfa730328b45b65840ebed3293e96c497aa86", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-10T22:18:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T22:18:56.000Z", "avg_line_length": 29.4888888889, "max_line_length": 69, "alphanum_fraction": 0.6797287114, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6413016666748967}}
{"text": "\\documentclass[a4paper,10pt]{report}\n\\usepackage[utf8]{inputenc}\n\\usepackage{tikz}\n\\usepackage[fleqn]{amsmath}\n\n\\begin{document}\nJust a short explanation how the calculations for the graver sharpening jig works. \nNormally, there are three 5 parameters that define the form of the base plate:\n\n\n\\begin{tabular}{ll}\n $\\alpha$ & Angle of the cutting face \\\\\n $\\beta$ & Angle of the v-shape \\\\\n $\\theta$ & Angle of the heel \\\\\n $d$ & Elevation of the sharpening stone over the plane the jig is running on \\\\\n $s$ & Stick out, the length the graver is protruding from the front face of the jig\n\\end{tabular} \n\n\n\\vspace{2em}\nIn order to print a jig with a given width $b$, three main dimensions are calculated:\n\\vspace{1em}\n\n\\begin{minipage}{0.45\\textwidth}\n \\begin{tikzpicture}[scale=2]\n\\draw[thick] (0,0) -- (0,2)-- (2,2) -- (2,0) -- (1,-1) -- (0,0);\n\\draw [fill] (1,1) circle [radius=0.1];\n\n\\draw[teal, dashed] (0,1.8) -- (2,1.8);\n\\node[teal] at (0.3,1.7) {b};\n\n\\draw[teal, dashed] (1,2) -- (1,1);\n\\node[teal] at (1.2,1.5) {h1};\n\n\\draw[teal, dashed] (1,1) -- (1,-1);\n\\node[teal] at (1.2,0) {h2};\n\n\\draw[teal] (2.2,1) -- (2.4,1);\n\\draw[teal] (2.2,0) -- (2.4,0);\n\\draw[teal, dashed] (2.3,1) -- (2.3,0);\n\\node[teal] at (2.44,0.5) {h3};\n\\end{tikzpicture}\n\\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n \\begin{tabular}{lp{5cm}}\n  $h1$ & Distance between the axis of the graver and the edge of the jig (for face sharpening) \\\\\n  $h2$ & Distance between the axis of the graver and the tip of the jig (for the heels) \\\\\n  $h3$ & Height from graver axis to the lower corners (for the heels) \\\\\n \\end{tabular}\n\\end{minipage}\n\nWith some base geometry the dimensions can be found to be:\n$$\n    h_1 = \\frac{s \\cdot \\sin \\alpha  + d}{\\cos \\alpha}\n$$\n$$\n    h_2 = \\frac{s \\cdot \\sin \\theta  + d}{\\cos \\theta \\cdot \\sin \\frac{\\beta}{2}}\n$$\n$$\n    h_3 = h_2 - \\frac{b}{2 \\tan \\frac{\\beta}{2}}\n$$\n\n\\section*{Example (distances in mm, angles in °):}\n\\begin{minipage}{0.65\\textwidth}\ngiven: \\\\\n$b=50, d=20, s=30$ \\\\ $\\alpha=45, \\beta=105, \\theta=8 $\n$$\n    h_1 = \\frac{30 \\cdot \\sin 45  + 20}{\\cos 45} \\approx \\frac{41.2}{0.71} \\approx 49.5\n$$\n$$\n    h_2 = \\frac{30 \\cdot \\sin 8  + 20}{\\cos 8 \\cdot \\sin 52.5} \\approx \\frac{24.2}{0.8} \\approx 30.8\n$$\n$$\n    h_3 = 30.8 - \\frac{25}{\\tan 52.5} \\approx 11.6\n$$\n\n\\end{minipage}\n\\begin{minipage}{0.25\\textwidth}\n\\begin{tikzpicture}[scale=0.05]\n\\draw[thick] (0,0) -- (0,49.5) -- (50,49.5) -- (50,0) -- (50,-11.6) -- (25,-30.8) -- (0,-11.6) -- (0,0) ;\n\\draw [fill] (25,0) circle [radius=1.15];\n\\end{tikzpicture}\n\\end{minipage}\n\n\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "12ecfd5cf7545a4c6645c8e52758e2329eb32224", "size": 2573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "v-shaped/calculations.tex", "max_stars_repo_name": "olivermanz/graver-sharpening-jig", "max_stars_repo_head_hexsha": "7c50bbb0ce9c7f446a2ca6a84145b03212c710e7", "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": "v-shaped/calculations.tex", "max_issues_repo_name": "olivermanz/graver-sharpening-jig", "max_issues_repo_head_hexsha": "7c50bbb0ce9c7f446a2ca6a84145b03212c710e7", "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": "v-shaped/calculations.tex", "max_forks_repo_name": "olivermanz/graver-sharpening-jig", "max_forks_repo_head_hexsha": "7c50bbb0ce9c7f446a2ca6a84145b03212c710e7", "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": 27.3723404255, "max_line_length": 105, "alphanum_fraction": 0.6187329965, "num_tokens": 1055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6411986550696426}}
{"text": "\\documentclass[8pt]{article}\n\n\\usepackage{geometry}\n\\geometry{landscape,margin=.2in}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[hidelinks]{hyperref}\n% \\hypersetup{\n%     colorlinks=false,\n%     linkcolor=white,\n%     filecolor=magenta,      \n%     urlcolor=white,\n% }\n\n\\bibliographystyle{abbrv}\n\\usepackage{multicol}\n\\usepackage{parskip}\n\n\\DeclareMathOperator*{\\argmin}{argmin}\n\n% ------------------------------------------------------------------------\n\\begin{document}\n\n% ------------------------------------------------------------------------\n% Overall intro\n\\section*{The math of reinforcement learning}\nAll the math for learning and choosing, in a common place and notation.\n\n% ------------------------------------------------------------------------\n% Start the sheet...\n\\begin{multicols}{4}\n\nThe aim of all reinforcement learning it to maximize reward recieved. Call this $\\rho$.\n\n\\subsection*{Some formality} \nIn all reinforcement leaning problems there is a set of $\\textbf{S}$ states, $\\textbf{A}$ actions, and $\\textbf{R}$ rewards. \n\nA model always start of in some state $s_0 \\in \\textbf{S}$. Using policy $\\pi$ it takes action $a \\in \\textbf{A}$. Each action leads to a new state $s' \\in \\textbf{S}$, and sometimes a reward $r \\in \\textbf{R}$. Eventually, a terminal state is found. \n\nWe don't know to find $\\rho$ so it is estimated incrementally by an \\emph{expected value} $V$. Said another way, $V \\approx \\rho$. \n\nAs we will see there are many ways to define $V$. Many of the proofs in reinforcement learning want to show that for some way of calculating $V$, $V \\rightarrow \\rho$ as $t \\rightarrow \\infty$.\n\nHere the expected value at $s$ is $V$. The expected value at $s'$ is $V'$. \n\nThe intial value $V_0$ is arbitrary, but is important by Bellman's optimality principle \\footnote{\\url{https://en.wikipedia.org/wiki/Bellman_equation}}.\n\nThe size of each set is denoted by $k = |\\textbf{A}|$, $m = |\\textbf{S}|$, and $o = |\\textbf{R}|$.\n\n\\subsection*{A recursive notion of time}\nTo keep the notation simple, we don't mantion time explicitly. Learning happens recursively, with changes denoted by the `$\\leftarrow$'.  \n\nFor example, $V \\leftarrow V + r$ is equivilant to $V(t+\\delta t) = V(t) + r(t)$.\n\n\\subsection*{Other simplifications}\n\nCommonly $V$ is denoted as function of $s$, $a$, and $t$. That is as $V(s,a,t)$, or even as $V(s,a, s', a', t)$.\n\nTo keep the notation compact--at the cost of precision--this kind of thing is left implicit. Only when really needed is the complete notation used. \n\n\n% ------------------------------------------------------------------------\n% Begin denoting all the models\n% \\vfill\\null\n% \\columnbreak\n\\section*{The models}\n\\subsection*{The minimal}\n\nThe simplest possible reinforcement learning is:\n\n\\begin{eqnarray}\n    V \\leftarrow V + r \\\\\n    \\pi \\leftarrow \\frac{V}{\\sum_\\textbf{A}{V}} \n\\end{eqnarray}\n\nWhere the intial value is free $V_0 = \\mathbb{R}$, and $\\sum_\\textbf{A}{V}$ is the sum of the values for all actions $A$. The difference in size between $V$ and $r$ determines the learning rate. \n\nWhich is equivilant to:\n\n\\begin{eqnarray}\n    V \\leftarrow V + \\alpha r \n\\end{eqnarray}\n\nWhere the learning rate is explicit as, $(0 < \\alpha \\leq 1)$ and $V_0 = 0$.\n\n\\subsubsection*{Other policies}\n\nDifferent policies can be calculated with the same values. The linear version above is not common. Two common alternatives are softmax,\n\n\\begin{eqnarray}\n    \\pi \\leftarrow \\frac{e^{V}}{\\sum_\\textbf{A}{e^{V}}} \n\\end{eqnarray}\n\nand $\\epsilon$-greedy\n\n\\begin{eqnarray}\n    TODO\n\\end{eqnarray}\n\n\\textbf{Note:} these, or any other policy, can be mixed and matched arbitrarily with any learning rule.  \n\n\n\\subsection*{The minimal, discounted}\nThe effect of recent values can be modulated with:\n\n\\begin{eqnarray}\n    V \\leftarrow \\gamma V + \\alpha r \n\\end{eqnarray}\n\nWhere $(0 < \\gamma \\leq 1)$, $(0 < \\alpha \\leq 1)$, and $V_0 = 0$. \n\nOnce the ratio $\\alpha/\\gamma > 0.5$ current rewards begin to matter more than past values.\n\nThis general method for controlling recent values carries on to more complex models, and longer time horizons. Use it as needed.\n\n\\subsection*{The discount}\nOften values or summed rewards will be discounted as time passes. A common form is:\n\n\\begin{eqnarray}\n    \\gamma \\leftarrow \\gamma ^ t\n\\end{eqnarray}\n\nWhere $0 < \\gamma \\leq 1$ and $t \\in \\mathbb{N}_1$ is an integer code for the elapsed discrete time.\n\nAnother form is exponential decay \\cite{Francois-Lavet2015}:\n\\begin{eqnarray}\n    \\gamma \\leftarrow \\gamma - \\gamma \\tau\n\\end{eqnarray}\n\nWhere $\\tau \\in \\mathbb{R}_+$. Typically $\\tau \\approx 0.02$.\n\n\\textbf{Note}: anywhere $\\gamma$ is used here assume a discounted form can--and often is--substituted in.\n\n\n% \\vfill\\null\n% \\columnbreak\n\\subsection*{The temporal difference}\nIf the reward is delayed, the minimal model can't give credit to past states. \n\nOne solution is to take the difference between the current $V$ next, $V'$, as in the \\emph{SARSA} rule:\n\n\\begin{eqnarray}\n    V \\leftarrow V + \\alpha (r  + \\gamma V' - V) \n\\end{eqnarray}\n\nWhere $(0 < \\gamma \\leq 1)$, $(0 < \\alpha \\leq 1)$, and $V_0 = 0$. Unlike the minimal model here $\\gamma$ wieghs the influence of the future, not the past.\n\n\n\\subsection*{The maximum difference}\n\\emph{Q learning} takes the difference between the current value $V$ and the maximum value, $\\argmin_A \\textbf{V}$.\n\n\\begin{eqnarray}\n    V \\leftarrow V + \\alpha (r + \\gamma \\argmin_A \\textbf{V} - V) \n\\end{eqnarray}\n\nWhere $(0 < \\gamma \\leq 1)$, $(0 < \\alpha \\leq 1)$, and $V_0 = 0$.\n\n\\textbf{Note:} as policies are define by their target action $a$, \\emph{Q learning} is often called an \\emph{off-policy} learning rule, while the temporal difference is \\emph{on-policy}.\n\n\\subsection*{The average difference}\n\\emph{Avantage learning} works with relative changes in value, comparing $V$ to its average $\\bar{V}$.\n\\begin{eqnarray}\n    V \\leftarrow V + \\alpha (r + \\gamma \\bar{V} - V) \\\\\n    \\bar{V} = \\frac{1}{k} \\sum_\\textbf{A}{V} \n\\end{eqnarray}\n\nIn practice $\\bar{V}$ is approximated online, often with a discounting scheme.\n\n\\textbf{Note}: advantages play an important role in policy gradients.\n\n\\subsection*{The regretable difference}\n\nTODO....\n\n\n\\vfill\\null\n\\columnbreak\n\\subsection*{The policy gradient}\nPolicy gradients learn to map states to directly to actions. They are most useful when problems are continious in action spaace and time, or when promises of local optima are needed.  \n\nPolicy gradients tend however to be sample inefficient, and by definition they are also \\emph{on policy} methods, which can also slow learning down.\n\nA policy is the probability of taking an action $a$, given a state $s$ and some generic parameters $\\theta$.\n\n\\begin{eqnarray}\n\\pi = P(a, s, \\theta)\n\\end{eqnarray}\n\nTo learn a good policy $\\pi$, the parameter gradient should follow the reward gradient. \n\n\\begin{eqnarray}\n\\theta \\leftarrow \\theta + \\alpha \\frac{\\partial \\rho}{\\partial \\theta}\n\\end{eqnarray}\n\nAs with other reinforcement leaning methods, finding a suitable way to estimate $\\rho$ becomes a major concern, and our problem becomes:\n\n\\begin{eqnarray}\n\\theta \\leftarrow \\theta + \\alpha \\frac{\\partial V}{\\partial \\theta}\n\\label{eq:grad}\n\\end{eqnarray}\n\n\\subsection*{The average (again)}\nIn a gradient setting \\emph{avantage learning} increases in $V$ are by definition better than average, $\\bar{V}$.\n\n\\begin{eqnarray}\n    V \\leftarrow V + \\alpha (r + \\gamma \\bar{V} - V) \\\\\n    \\bar{V} = \\frac{1}{k} \\sum_\\textbf{A}{V} \n\\end{eqnarray}\n\n Gradients driven by advatage updates ensure learning is always better than average \\cite{Sutton}. By eq. \\ref{eq:grad}, purturbations to $\\theta \\leftarrow \\theta + \\delta \\theta$ which increase $V$ must, by definition, be better than average. \n\n\\subsection*{The generalized advantage}\nDiscounting values can introduce a bias to the final estimate. The generalized advantage scheme takes this into account \\cite{Schulman2015a}. \n\n\\subsection*{Actor-critic}\nValue learning and policy can be joined into a single \\emph{actor-critic architecture}.\n\nTODO\\ldots\n\n\n% ------------------------------------------------------------------------\n\\vfill\\null\n\\columnbreak\n\\section*{The planning models}\nPlanning means the learner has, or creates, an \\emph{explicit map} of the state-space. This map can come from outside the system, from some useful oracle, or can be learned.\n\n\\subsection*{The DYNA}\n\n\\subsection*{The prioritized sweep}\n\n\\subsection*{The successor}\n\n\\end{multicols}\n\n\\newpage\n\\bibliography{library}\n\\end{document}", "meta": {"hexsha": "5d23ac3a0adf35fa8831137ed919b3b63b82079c", "size": 8569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/rl.tex", "max_stars_repo_name": "CoAxLab/azad", "max_stars_repo_head_hexsha": "d1498069dd8856e93ae077b34dd7c9f1c7ce80e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-09-11T21:06:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T17:36:52.000Z", "max_issues_repo_path": "notes/rl.tex", "max_issues_repo_name": "CoAxLab/azad", "max_issues_repo_head_hexsha": "d1498069dd8856e93ae077b34dd7c9f1c7ce80e6", "max_issues_repo_licenses": ["MIT"], "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/rl.tex", "max_forks_repo_name": "CoAxLab/azad", "max_forks_repo_head_hexsha": "d1498069dd8856e93ae077b34dd7c9f1c7ce80e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-09-12T00:40:52.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-29T15:45:54.000Z", "avg_line_length": 35.5560165975, "max_line_length": 251, "alphanum_fraction": 0.6879449177, "num_tokens": 2416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6411986521493419}}
{"text": "\\newpage \\subsection{Recurrent Sequences}\t\n\t\n\t\n\t\\begin{myitemize}\n\t\t\\item \\href{https://ufile.io/ywbniil2}{WOOT 2010-11 Recursion}\n\t\\end{myitemize}\n\t\n\t\n\t\\begin{BoxedTheorem}{Sum of Geometric Sequences}{}\\label{theorem:Sum of Geometric Sequences}\n\t\tEvery recurrent sequence can be written as a sum of some geometric sequences. Given a recurrent sequence, \n\t\t\\[x_n = a_1x_{n-1} + a_2x_{n-2}\t+\\dots + a_kx_{n-k}\\]\n\t\tThen $ x_n $ can be written as \n\t\t\\[x_n = c_1r_1^n + c_2r_2^n +\\dots + c_lr_l^n\\]\n\t\tFor all $ c_i $ if $ r_i $ are the roots of the \\emph{characteristic polynomial} of the recursion. Which is:\n\t\t\\[\\tcboxmath[colback=white, colframe=white]{x^k - a_1x^{k-1} - a_2x^{k-2} \\dots - a_k = 0}\\]\n\t\tIf there are double roots, say $ r_1 = r_2 = r_3 $, then we instead have,\n\t\t\\[x_n = \\tcboxmath[colback=white, colframe=white]{c_1r_1^n + c_2n\\ r_2^n + c_3n^2\\ r^n} \\dots + c_lr_l^n\\]\n\t\t \n\t\tReversely, we can say that a sequence defined by a sum of geometric recurrent series is a recursion. \n\t\\end{BoxedTheorem}\n\n\t\\lem{}{Let $ F_n $ be the $ n $th Fibonacci number. Then the following holds:\n\t\t\\[F_{n}^2 + F_{n+1}^2 = F_{2n+1}\\]}\n\t\n\t\\proof{Expanding the general form of the terms, and showing that $ a_n = F_{n}^2 + F_{n+1}^2 - F_{2n+1} $ is a recursion by \\autoref{theorem:Sum of Geometric Sequences}.}\n\t\n\t\\begin{BoxedTheorem}[title=Repertoire Method]{}{}\n\t\tGiven a recurrent function defined by \n\t\t\\[f(n) = A(n)\\a + B(n)\\beta + C(n)\\gamma\\]\n\t\tWe plug in different values for $ f(n) $, for example, $ f(n) = 1, n, 2n $ etc. for which the values are known from the recursion, and then solve for $ A, B, C $.\n\t\\end{BoxedTheorem}", "meta": {"hexsha": "9fcfb585b78efaac5045f8344312e901f8ff958c", "size": 1629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec8_1_Recursion.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_1_Recursion.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_1_Recursion.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": 52.5483870968, "max_line_length": 171, "alphanum_fraction": 0.671577655, "num_tokens": 617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.641123259060993}}
{"text": "\\chapter{Generative Convolutional Neural Networks}\n\nIn this chapter we develop the idea of a generative convolutional neural\nnetwork.  Doing so will allow us to use a natural generative pre-training\nalgorithm so that we do not need the same quantity of labeled data\nthat deep neural networks normally require.\n\n\\section{Fixed-length speech samples}\n\nWe begin our discussion with fixed-length vectors of speech signals\n$\\mathbf{X}\\in\\mathbb{R}^{N\\times D}$ which denotes $N$ vectors\nof dimension $D$.  We use Numpy-style slicing syntax so that\n$\\mathbf{X}(n_1:n_2,d_1:d_2)\\in \\mathbb{R}^{(n_2-n_1)\\times(d_2-d_1)}$\nrefers to the matrix\n\\begin{equation}\n\\begin{bmatrix}\n  \\mathbf{X}(n_1,d_1) & \\mathbf{X}(n_1,d_1+1) & \\cdots & \\mathbf{X}(n_1,d_2-1)\\\\\n  \\mathbf{X}(n_1+1,d_1) & \\mathbf{X}(n_1+1,d_1+1) & \\cdots & \\mathbf{X}(n_1+1,d_2-1)\\\\\n  \\vdots & \\vdots & \\ddots & \\vdots \\\\\n  \\mathbf{X}(n_2-1,d_1) & \\mathbf{X}(n_2-1,d_1+1) & \\cdots & \\mathbf{X}(n_2-1,d_2-1)\n\\end{bmatrix}\n\\end{equation}\nand we denote the index set for a vector of length $D$ as $[D]=\\{0,1,\\ldots,D-1\\}$. We will consider a sequence of models for these data.  Initially we will begin with \na mixture model and progressively we will develop towards the convolutional neural network model.\n\n\\subsection{Circulant Gaussian Models}\n\nWe may model these vectors using circulant Gaussians $\\mathcal{N}_D(\\mathbf{0},\\mathbf{\\Sigma})$ where\n$\\tilde{\\boldsymbol{\\Sigma}}\\in\\Circ_D$ where $\\Circ_D$ is the set of circulant matrices over $\\mathbb{R}^{D\\times D}$.\nSince $\\boldsymbol{\\Sigma}$ is circulant we may write it as $F_D^*\\diag(\\tilde{\\boldsymbol{\\sigma}})F_D$ for some \nreal vector $\\tilde{\\boldsymbol{\\sigma}}\\in\\mathbb{R}^D$. Since $\\boldsymbol{\\Sigma}$ is a real symmetric\n positive definite circulant matrix we may write it as $\\boldsymbol{\\Sigma}=\\Circ(\\boldsymbol{\\sigma})$\nwhere $\\boldsymbol{\\sigma}$ is the first column of $\\boldsymbol{\\Sigma}$.  Due to the symmetry and circularity of\n$\\boldsymbol{\\Sigma}$ this means that $\\boldsymbol{\\sigma}$ is symmetric so that for $1 < d < D$ we have\n$\\boldsymbol{\\sigma}(d)=\\boldsymbol{\\sigma}(D-d)$ and the same holds for $\\tilde{\\boldsymbol{\\sigma}}=\\mathbf{F}\\boldsymbol{\\sigma}$.\n\nThe circulant model is given by a single vector specifying the spectral distribution\n", "meta": {"hexsha": "433340d435e6ea60e8c988ef3807c614e59c07df", "size": 2284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch5_generative_cnn.tex", "max_stars_repo_name": "markstoehr/researchnotes", "max_stars_repo_head_hexsha": "07197f3234a8993d8d4c416fb2878aab0618344d", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-06-06T09:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2015-06-06T09:37:00.000Z", "max_issues_repo_path": "chapters/ch5_generative_cnn.tex", "max_issues_repo_name": "markstoehr/researchnotes", "max_issues_repo_head_hexsha": "07197f3234a8993d8d4c416fb2878aab0618344d", "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/ch5_generative_cnn.tex", "max_forks_repo_name": "markstoehr/researchnotes", "max_forks_repo_head_hexsha": "07197f3234a8993d8d4c416fb2878aab0618344d", "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.1052631579, "max_line_length": 168, "alphanum_fraction": 0.7272329247, "num_tokens": 747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6411232546902635}}
{"text": "\\documentclass[11pt,twoside,a4paper]{article}\n\\usepackage{amsmath}\n\\usepackage{commath}\n\\usepackage{graphicx}\n\\usepackage{tikz}\n\\usetikzlibrary{bayesnet}\n\n\\begin{document}\n\\section{Uivariate Gaussian distribution}\n  Let $\\{x_i\\}= \\{x_1, x_2, \\cdots,x_n\\}$ denote $n$ random variates drawn from\n  a univariate Normal distribution parametrised by the unknown variance $\\omega$\n  and known mean $\\mu = 0$. Let us assume that the a Gaussian noise with known\n  variannce $\\zeta$ has been added to the variates yeilding new variates\n  $\\{y_i\\}= \\{y_1, y_2, \\cdots,y_n\\}$. Using statistical notations we can write\n  \\begin{align}\n    \\label{eqn_posteriors_signal_and_noise}\n    \\Pr \\left(\\{x_i\\} | \\omega \\right) &= \\prod_{i=1}^n\n      \\frac{1}{\\sqrt{2 \\pi \\omega}} \\exp \\left(-\\frac{x_i^2}{2 \\omega} \\right)\\\\\n    \\Pr \\left(\\{x_i\\} | \\{y_i\\}, \\zeta \\right) &= \\prod_{i=1}^n\n      \\frac{1}{\\sqrt{2 \\pi \\zeta}} \\exp\n      \\left(-\\frac{\\left(y_i - x_i \\right)^2}{2 \\zeta} \\right)\n  \\end{align}\n  Using Bayes theorem the inference about the variance $\\omega$ can be written\n  as\n  \\begin{align}\n    \\label{eqn_posterior_omega_given_noisy_random_variates}\n    \\Pr \\left(\\omega | \\{y_i\\} \\right) \\propto\n      \\Pr \\left(\\{y_i\\} | \\omega \\right) \\Pr(\\omega).\n  \\end{align}\n  Assuming a prior distribution $\\Pr(\\omega) = 1$, we can transfom the problem\n  to the computation of the conditional distribution which is given by\n  \\begin{align}\n    \\Pr \\left(\\{y_i\\} | \\omega \\right) &= \\prod_{i=1}^n\n      \\frac{1}{\\sqrt{2 \\pi (\\zeta + \\omega)}} \\exp\n      \\left(-\\frac{y_i^2}{2(\\zeta + \\omega)} \\right), \\nonumber \\\\\n    &= (2 \\pi)^{-\\frac{n}{2}} \\left(\\zeta + \\omega \\right)^{-\\frac{n}{2}}\n      \\exp \\left(-\\frac{\\sum_{i=1}^n y_i^2}{2 (\\zeta + \\omega)} \\right) .\n  \\end{align}\n  This equation represents an inverse-Gamma distribution:\n  \\begin{align}\n    f(x | \\alpha, \\beta) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} x^{\\alpha - 1}\n        \\exp \\left(-\\frac{\\beta}{x} \\right).\n  \\end{align}\n  The statistical properties of inverse-Gamma distribution is well known and\n  are shown in the table below.\n  \\begin{table}\n    \\caption{Statistical properties of inverse-Gamma distribution}\n    \\label{tab_statistical_properties_of_inverse_gamma}\n    \\begin{center}\n      \\begin{tabular}{|c|c|c|}\n        \\hline\n        mode & mean $(\\alpha > 1)$ & variance $(\\alpha > 2)$ \\\\\n        \\hline\n        $\\frac{\\beta}{\\alpha + 1}$ & $\\frac{\\beta}{\\alpha - 1}$ &\n          $\\frac{\\beta^2}{(\\alpha - 1)^2 (\\alpha - 2)}$ \\\\\n        \\hline\n      \\end{tabular}\n    \\end{center}\n  \\end{table}\n  We can find the values of $n$ for which the variance of the distribution is\n  defined as shown below:\n  \\begin{align}\n    \\alpha > 2 \\\\\n    \\frac{n}{2} + 1 > 2 \\\\\n    \\frac{n}{2} > 1 \\\\\n    \\boxed{n > 2}\n  \\end{align}\n  This implies that we need at least 2 samples to determine the variance of the\n  estimated and at least one sample to determine the mean.\n\n  The logarithm of the posterior distribution can be written as\n  \\begin{align}\n    \\psi &= \\log \\left(\\Pr \\left(\\{y_i\\} | \\omega \\right) \\right) \\\\\n    &= -\\frac{n}{2}\\log(2 \\pi) - \\frac{n}{2}\\log(\\zeta + \\omega)\n      -\\frac{1}{2} \\frac{\\sum_{i=1}^n y_i^2}{(\\zeta + \\omega)}.\n  \\end{align}\n  The gradient of the log-posterior with respect to $\\omega$ is given by\n  \\begin{align}\n    \\frac{\\partial \\psi}{\\partial \\omega} = -\\frac{n}{2 (\\zeta + \\omega)}\n      - \\frac{\\sum_{i=1}^n y_i^2}{2 (\\zeta + \\omega)^2}.\n  \\end{align}\n  The mode of the distribution can be found by setting gradients equal to zero\n  and solving the resulting equation:\n  \\begin{align}\n    \\frac{n}{2 (\\zeta + \\omega)}\n      + \\frac{\\sum_{i=1}^n y_i^2}{2 (\\zeta + \\omega)^2} = 0, \\\\\n    \\frac{n}{2} + \\frac{\\sum_{i=1}^n y_i^2}{2 (\\zeta + \\omega)} = 0 \\\\\n    n + \\frac{\\sum_{i=1}^n y_i^2}{(\\zeta + \\omega)} = 0 \\\\\n    n (\\zeta + \\omega) + \\sum_{i=1}^n y_i^2 = 0\n    %\\zeta + \\omega + \\frac{\\sum_{i=1}^n y_i^2}{n} = 0 \\\\\n    %\\omega = \\frac{\\sum_{i=1}^n y_i^2}{n} - \\zeta \\\\\n    %\\omega = \\bar{y} - \\zeta\n  \\end{align}\n  Thus mode of the distribution is given by\n  \\begin{align}\n    \\boxed{\\bar{\\omega} = \\bar{y} - \\zeta.}\n  \\end{align}\n  As we can see, the mode may have chance of being negative or zero which\n  corresponds to non-physical variance. Hence we cannot treat this as point\n  estimate of the distribution. The question then is what suffices as a\n  ``good'' point estimate?\n\n  From a Bayesian prespective, we haven't really assed the situaton carefully.\n  By choosing uniform prior for $\\omega$ we have allowed non-positive values\n  for the variance. However, a sensible prior for the variance should disregard\n  any values less than or equal to zero. According to Jeffery's a reasonable\n  prior distribution for a variable taking only positive values should be\n  a uniform prior on the logarithm of the variable. Let $\\eta = \\log(\\omega)$\n  and hence we can write,\n  \\begin{align}\n    \\Pr(\\eta) = 1.\n  \\end{align}\n  The rule of chang of variables says that\n  \\begin{align}\n    \\Pr(\\omega) \\dif \\omega = \\Pr(\\eta) \\dif \\eta.\n  \\end{align}\n  Therefore the Jeffreys prior on $\\omega$ can be derived as\n  \\begin{align}\n    \\Pr(\\omega) &= \\Pr(\\eta) \\frac {\\dif \\eta}{\\dif \\omega}, \\\\\n    &= \\frac{1}{\\omega}.\n  \\end{align}\n\n  Applying the Jeffreys prior, the logarithm of the posterior distribution\n  becomes\n  \\begin{align}\n    \\psi  = - \\frac{n}{2} \\log (2 \\pi) - \\frac{n}{2} \\log (\\zeta + \\omega)\n      - \\frac{1}{2} \\frac{\\sum_{i=1}^n y_i^2}{(\\zeta + \\omega)} - \\log(\\omega).\n  \\end{align}\n  We compare the two posterior distributions in\n  Figure~\\ref{fig_log_post_uniform_jeffreys}\n  \\begin{figure}\n    \\includegraphics[scale=0.8]{images/log_post_uniform_jeffreys.pdf}\n    \\caption{Comparing the log-posterior distributions of $\\omega$ with uniform and Jeffreys prior.}\n    \\label{fig_log_post_uniform_jeffreys}\n  \\end{figure}\n  As we can see the resultng posterior distribution has spike near zero. Can\n  there be a probabilisitc explanation for this characterstic? Since we are\n  estimating the variance in the presence of noice, we have have to think in\n  terms of a hierarchical way.\n\n\\subsection{Hierarchical modelling}\n  In hierarchical model, one considers a prior of the form\n  \\begin{align}\n    \\Pr(\\zeta + \\omega) = \\frac{1}{\\zeta + \\omega}.\n  \\end{align}\n  The logaritm of the posterior now has the form\n  \\begin{align}\n    \\psi  = - \\frac{n}{2} \\log (2 \\pi) - \\frac{n}{2} \\log (\\zeta + \\omega)\n      - \\frac{1}{2} \\frac{\\sum_{i=1}^n y_i^2}{(\\zeta + \\omega)}\n      - \\log(\\zeta + \\omega).\n  \\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "5d86cdba1134ef5a4feb14af7c0ebb3b4f96b03f", "size": 6532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/univariate_gaussian/univariate_gaussian_estimation.tex", "max_stars_repo_name": "tbs1980/research-covariance-matrix-estimation", "max_stars_repo_head_hexsha": "33d73b2fc3f31dbfa5dc62eb94229b733be6ac98", "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": "notes/univariate_gaussian/univariate_gaussian_estimation.tex", "max_issues_repo_name": "tbs1980/research-covariance-matrix-estimation", "max_issues_repo_head_hexsha": "33d73b2fc3f31dbfa5dc62eb94229b733be6ac98", "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": "notes/univariate_gaussian/univariate_gaussian_estimation.tex", "max_forks_repo_name": "tbs1980/research-covariance-matrix-estimation", "max_forks_repo_head_hexsha": "33d73b2fc3f31dbfa5dc62eb94229b733be6ac98", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-14T15:06:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T15:06:48.000Z", "avg_line_length": 42.4155844156, "max_line_length": 100, "alphanum_fraction": 0.640385793, "num_tokens": 2210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6411232438983857}}
{"text": "\\chapter{Equation Conventions}\n\\label{ch:conventions}\n\n\\textit{In this manual we will} be adhering to the following conventions\n\n\\section{List of Symbols}\n\n\\begin{itemize}\n\t\\item {\\boldmath{$i$}} Receiver identification or {\\boldmath{$r$}}\n\t\\item {\\boldmath{$j$}} Satellite identification or {\\boldmath{$s$}}\n\t\\item {\\boldmath{$k$}} Epoch number or {\\boldmath{$t$}}\n\t\\item {\\boldmath{$q$}} GNSS type (GPS,GALILEO,GLONASS,QZSS)\n\t\\item {\\boldmath{$c$}} Speed of light [m/s]\n\t\\item {\\boldmath{$x$}} Vector of parameters to be estimated\n\t\\item {\\boldmath{$y$}} Vector of observations\n\t\\item {\\boldmath{$v$}} Vector of residuals\n\t\\item {\\boldmath{$H$}} Design matrix\n\t\\item {\\boldmath{$\\sigma$}} Standard deviation of observable\n\t\\item {\\boldmath{$\\Delta$}} Increment to a priori values [m]\n\t\\item {\\boldmath{$\\lambda$}} Wavelength or {\\boldmath{$\\lambda_1,\\lambda_2,\\lambda_5$}}\n\t\\item {\\boldmath{$f_1,f_2,f_5$}} frequency\n\t\\item {\\boldmath{$\\alpha$}} Ambguity or {\\boldmath{$N$}} Real valued ambguity and {\\boldmath{$\\bar{N}$}} Integer part of real valued ambguity\n\t\\item {\\boldmath{$\\alpha$}} level of significance\n\t\n\t\\item {\\boldmath{$\\beta$}} Biases\n\t\\item {\\boldmath{$\\zeta$}} Clock offsets\n\t\\item {\\boldmath{$\\delta t$}} Clock error [s]\n\t\\item {\\boldmath{$\\kappa$}} Correction - relativity\n\t\\item {\\boldmath{$\\iota$}} Ionosphere or  {\\boldmath{$I$}}\n\t\\item {\\boldmath{$\\tau$}} Troposphere or {\\boldmath{$T,T_h,T_w$}}\n\t\\item {\\boldmath{$M$}} elevation dependent mapping function for the troposphere wet delay\n\t\\item {\\boldmath{$\\xi$}} Phase wind-up error\n\t\\item {\\boldmath{$\\epsilon$}} Error in observations and unmodelled effects [m]\n\t\\item {\\boldmath{$\\phi_i^j$}} Carrier phase observable (times c) [m]\n\t\\item {\\boldmath{$P_i^j$}} Pseudo range observable [m]\n\t\t\n\\end{itemize}\n\nLets try this for example:\nFor an undifference, uncombined float solution, the linearized observation equations for pseudorange and phase observations from satellite $s$ to receiver $r$ can be described as:\n\n\\begin{math}\n\\Delta P_{r,f}^{q,s} = u_r^{q,s} . \\Delta x + c . (\\delta t_r^q - \\delta t^{q,s}) + M_r^{q,s} . T_r + \\gamma_f^q . I_{r,1}^{q,s} + d_{r,f}^q - d_f^{q,s} + \\epsilon_{P,f}^q\n\\end{math}\\\\\n\\begin{math}\n\\Delta\\phi_{r,f}^{q,s} = u_r^{q,s} . \\Delta x + c . (\\delta t_r^q - \\delta t^{q,s}) + M_r^{q,s} . T_r - \\gamma_f^q . I_{r,1}^{q,s} + \\lambda_f^q . N_{r,f}^{q,s} + b_{r,f}^q - b_f^{q,s} + \\epsilon_{L,f}^q \n\\end{math}\n\nwhere$\\Delta P_{r,f}^{q,s}$ and $\\Delta\\phi_{r,f}^{q,s}$ are the respective pseudorange and phase measurements on the frequency $f$(f=1,2), from which the computed values are removed;\n$u_r^{q,s}$ is the receiver-to-satellite unit vector;\n$\\Delta x$ is the vector of the receiver position corrections to its preliminary position; \n$\\delta t_r^q$ and $\\delta t^{q,s}$ are the receiver and satellite clock errors respectively;\n$c$ is the speed of light in a vaccum\n$M_r^{q,s}$ is the elevation dependent mapping function for the troposphere wet delay from the corresponding zenith one $T_r$;\n$I_{r,1}^{q,s}$ is the ionosphere delay along the line-of-sight from a receiver to a satellite at the first frequency and $\\gamma_f^q = (\\lambda_f^q / \\lambda_1^q)^2$;\n$\\lambda_f^q$ is the wavelength for the frequency $f$ of a GNSS $q$;\n$N_{r,f}^{q,s}$is the phase ambguity \n$d_{r,f}^q$ and $b_{r,f}^q$ are the receiver hardware delays of code and phase observations respectively;\n$d_f^{q,s}$ and $b_f^{q,s}$ are the satellite hardware delays of code and phase observations, respectively;\n$\\epsilon_{P,f}$ and $\\epsilon_{L,f}$ are the code and phase measurement noises respectively. \n\n", "meta": {"hexsha": "f08b412183042d054097a0f7db29cbad3362f7f0", "size": 3590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manual/conventions.tex", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "docs/manual/conventions.tex", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "docs/manual/conventions.tex", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 57.9032258065, "max_line_length": 204, "alphanum_fraction": 0.6896935933, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6411232408361885}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{momftfr}\n\\section*{\\hspace*{-1.6cm} momftfr}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nFrequency moments (order 1 and 2) of a time-frequency representation.\n\\end{minipage}\n\\vspace*{.35cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tm,T2] = momftfr(tfr)\n[tm,T2] = momftfr(tfr,tmin)\n[tm,T2] = momftfr(tfr,tmin,tmax)\n[tm,T2] = momftfr(tfr,tmin,tmax,time)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.35cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty momftfr} computes the frequeny moments of order 1 and 2 of a\n        time-frequency representation\\,:\n\\[t_m(f) = \\frac{1}{E}\\ \\int_{-\\infty}^{+\\infty} t\\ \\mbox{tfr}(t,f)\\ dt\\ \\\n;\\ \\ T^2(f) = \\frac{1}{E}\\ \\int_{-\\infty}^{+\\infty} t^2\\ \\mbox{tfr}(t,f)\\\ndt - t_m(f)^2.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c} Name &\nDescription & Default value\\\\ \\hline {\\ty tfr} & time-frequency\nrepresentation (size {\\ty (N,M)}). \\\\ {\\ty tmin} & smallest column\nelement of {\\ty tfr} taken into account & {\\ty 1} \\\\ {\\ty tmax} & highest\ncolumn element of {\\ty tfr} taken into account & {\\ty M}\\\\ {\\ty time} &\ntrue time instants & {\\ty (1:M)}\\\\ \\hline {\\ty tm} & averaged time (first order\nmoment)\\\\ {\\ty T2} & squared time duration (second order moment)\\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Example}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n         sig=fmlin(200,0.1,0.4); [tfr,t,f]=tfrwv(sig); \n         [tm,T2]=momftfr(tfr); \n         subplot(211); plot(f,tm); subplot(212); plot(f,T2); \n\\end{verbatim}\nThe first order moment represents an estimation of the group delay, and the\nsecond order moment the variance of this estimator. We can see that the\nestimation is better around the time center position than at the edges of\nthe observation interval.\n\\end{minipage}\n\\vspace*{.35cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nmomttfr, margtfr.\n\\end{verbatim}\n\\end{minipage}\n\n", "meta": {"hexsha": "16ba30fe1e0bec9a8db9b667dac08c5bcf112d82", "size": 2294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/momftfr.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/momftfr.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/momftfr.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 29.7922077922, "max_line_length": 79, "alphanum_fraction": 0.6591107236, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289535, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6411232377739916}}
{"text": "\\section{The \\variant{\\childrentransitions} problem}\n\\label{sec:simplenodes}\n\nIn this section, we provide the formal problem definition of the \n{\\variant{\\childrentransitions}}\nand describe a greedy polynomial-time algorithm for solving it.\n\n\\begin{problem}[{\\variant{\\nodeitems}}]\n\\label{problem:simplenodes-variant}\nGiven $G=(V,E)$, transition matrix $\\transition$, \ninitial distribution of items to nodes\n$\\initial$ and integer $k$, find\n$S\\subseteq V$ such that $|S|=k$ such that \n$\\objective_{_\\shortchildrentransitions}\\left(S\\right)$ is minimized.\n\\label{problem:simple-nodes-variant}\n\\end{problem}\n\nAs we can see from the definition of \n$\\objective_\\shortchildrentransitions\\left(S\\right)$ \nin \\eqref{eq:shortchildrentransitions},\nthe contribution of each node $u\\in {V-S}$\nto the objective function is equal to\n\\begin{equation}\n\\label{eq:parent-contribution}\n\\objective_{_\\shortchildrentransitions}(\\{u\\}) = \n\t\\initial(u)\\sum_{v\\in V}\\transition(u,v)\\left(1-\\transition(u,v)\\right)\n\\end{equation}\nand independent of any other node in $V-S$.\nIt directly follows, then, that Problem~\\ref{problem:simplenodes-variant}\nis solved by a simple greedy algorithm\nthat places in $S$ the {\\bf top k} nodes $u$ in terms\nof contribution $\\objective_{_\\shortchildrentransitions}(u)$.\n", "meta": {"hexsha": "aabf17376e19d15e4dcfbf77afe5e7b3a04174e9", "size": 1279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/SDM-2018/simplenodes.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/simplenodes.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/simplenodes.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": 38.7575757576, "max_line_length": 73, "alphanum_fraction": 0.7630961689, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6411232377739914}}
{"text": "\\chapter{Graphical Models}\n\\label{chap:Graphical Models}\n\n\\section{Introduction}\n\n\\section{Directed Graph}\n\n\\section{Undirected Graph}\n\n\\section{Inference in Graphical Models}\n\\subsection{Factor graphs}\nThe joint distribution over a set of variables in the form of a product of factors\n\\begin{align}\np(\\vec{x}) = \\prod_s f_s(\\vec{x}_s)\n\\end{align}\nwhere $\\vec{x}_s$ denotes a set of the variables.We shall denote individual variable by $x_i$,which can comprise groups of variables(such as vectors and matrices).Each factor $f_s$ is a function of a corresponding set of variable $\\vec{x}_s$.\nDirected graphs have factors $f_s(\\vec{x}_s)$ as local conditional distributions.Undirected graphs' factors are potential function over the maximal cliques.\n\n\\subsection{The Sum-product algorithm}\n\\textbf{sum-product} algorithm solves the problem of evaluating the \\textbf{local marginals} over nodes or subsets of nodes.And \\textbf{max-sum} algorithm find the \\textbf{most probable state},evaluating the maximal joint distribution.\n\nThe marginal is obtained by\n\\begin{align}\np(x) = \\sum_{\\vec{x}\\backslash x}{p(\\vec{x})}\n\\end{align}\nwhere $\\backslash x$ denotes the set of variables in $\\vec{x}$ omitting $x$.\n\nJoin distribution \n\\begin{align}\np(\\vec{x}) =\\prod_{s\\in \\text{ne}(x)}{F_s(x,\\vec{X}_s)}\n\\end{align}\n\nThen interchanging the sums and products,we obtain\n\\begin{align}\n\\text{objective} &= p(x)=\\sum_{\\vec{x}\\backslash x}{p(\\vec{x})} \\\\\n&= \\prod_{s\\in\\text{ne}(x)}{\\left[\\sum_{X_s}F_s(x,X_s)\\right]} \\\\\n&= \\prod_{s\\in\\text{ne}(x)}\\mu_{f_s\\rightarrow x}(x)\n\\end{align}\nView \\textbf{messages} from the factor nodes $f_s$ to the variable node $x$ as\n\\begin{align}\n\\mu_{f_s\\rightarrow x}(x) &\\equiv \\sum_{X_s}F_s(x,X_s) \\\\\nF_s(x,X_s) &= f_s(x,x_1,\\ldots,x_M)G_1(x_1,X_{s1})\\ldots G_M(x_M,X_{sM})\n\\end{align}\n\nRecursive inference in the sub-graph and interchanging sums and products leads to \n\\begin{align}\n\\mu_{f_s\\rightarrow x}(x) &= \\sum_{x_1}\\ldots\\sum_{x_M} f_s(x,x_1,\\ldots,x_M)\\prod_{m\\in \\text{ne}(f_s)\\backslash x} \\mu_{x_m\\rightarrow f_s}(x_m) \n\\end{align}\nwhere $\\text{ne}(x)$ denotes the set of neighbor variables.\nAnd define \\textbf{messages} from variable nodes to factor nodes\n\\begin{align}\n\\mu_{x_m\\rightarrow f_s}(x_m) &\\equiv \\sum_{X_{sm}}G_m(x_m,X_{sm})\n\\end{align}\n\nAgain,making use of (sub)-graph factorization,we have\n\\begin{align}\n\\mu_{x_m\\rightarrow f_s}(x_m) &= \\prod_{l\\in \\text{ne}(x_m)\\backslash f_s}\\left[\\sum_{X_{ml}}F_l(x_m,X_{ml}) \\right] \\\\\n&=\\prod_{l\\in \\text{ne}(x_m)\\backslash f_s}\\mu_{f_l\\rightarrow x_m}(x_m)\n\\end{align}\n\n\n\\subsection{Max-sum algorithm}\nThe \\textbf{sum-product} algorithm allows us to take a joint distribution $p(\\vec(x))$ expressed as a factor graph and efficiently find marginal component variables.\\textbf{Max-sum} find a setting of variables that has the largest probability,which is an application of \\textbf{dynamic programming}.\nMaximize the joint distribution\n\\begin{align}\n\\vec{x}^{max} = \\arg\\max_{\\vec{x}}p(\\vec{x})\n\\end{align}\nJoint distribution\n\\begin{align}\np(\\vec{x}) &= \\prod_{s\\in \\text{ne}(x)}F_s(x,X_s)\n\\end{align}\nMaking use of \\textbf{distributive law} for multiplication with max operator,similarly to add operator\n\\begin{align}\n\\text{objective} &= \\max\\ln p(\\vec{x}) =\\max\\sum\\ln F_s(x,X_s) \\\\\n&=\\sum\\max\\ln F_s(x,X_s)\n\\end{align}\nMaking use of recursion,factorize $F_s(x,X_s)$ with sub-graph,we can obtain\n\\begin{align}\n\\mu_{f\\rightarrow x} &= \\max_{x_1,\\ldots,x_M}\\left[\\ln f(x,x_1,\\ldots,x_M) + \\sum_{m\\in \\text{ne}(f_s)\\backslash x} {\\mu_{x_m\\rightarrow f}(x_m)} \\right] \\\\\n\\mu_{x\\rightarrow f}(x) &= \\sum_{l\\in \\text{ne}(x)\\backslash f}{\\mu_{f_l\\rightarrow x}}(x).\n\\end{align}\nwhere $\\mu_{f\\rightarrow x} \\equiv \\max\\ln F_s(x,X_s)$\n\n\n\n\n\n\n\n", "meta": {"hexsha": "212b488b78d51c509412732068a3b2891e744659", "size": 3718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Graphical Models.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/Graphical Models.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/Graphical Models.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": 41.3111111111, "max_line_length": 299, "alphanum_fraction": 0.7227003765, "num_tokens": 1219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6411232377739914}}
{"text": "\\section{FourierTransform: Fast Fourier Transforms}\n[Warren Smith prepared the analysis and modules.]\n\nThis is an {\\em in place} FFT routine with array length:  $N = 2^n$.\n\\begin{equation}\n a_{output,k} = \\sum_{m=0}^{N-1} a_{input,m} \n        e^{(2 \\pi i \\mbox{direction} m k/N)}\n\\end{equation}\n\nwhere direction $= \\pm 1$.\nYou have to do any scaling (by $1/N$ or $1/\\sqrt{N}$) or zeroing of a[] by\nyourself. \n\nUses $2N \\ln N + 2 N + O(\\ln N)$ [real] multiplications, \nand $ 3N \\ln N + 2 N + O(\\ln N)$ [real] additions.\n(And hopefully the compiler optimizes the subscripting in the inner loop so\nthat only $2 N \\ln N$ total subscripting ops are needed.)\n\nThe test routine shown yields\nerror after 1 forward and one backward use\nat least 3 decimal places better than\nslow FT has after only one use!\n\nThe basic FFT idea (for N a power of 2) is from J.Cooley \\& J.Tukey:\nAn algorithm for the Machine Calculation of Complex Fourier Series,\nMOC 19 (1965) 297-301. (Knuth, Henrici, and Dahlquist/Bjorck also discuss\nthe FFT.) The basic idea is that to calculate the DFT\n\\begin{eqnarray}\n    A[k]  & = & \\sum_{j=0}^{N-1}a_j*W^{kj}  \\, \\mbox{for k=0..N-1}\\\\\n    N & = & \\mbox{a power of 2,}\\, N>1\\\\\n    W & = & \\mbox{a principal Nth root of unity}\\\\\n   \\mbox{e.g., } W & = & e^{2 i \\pi/N}\n\\end{eqnarray}\nWe may write\n\\begin{eqnarray}\n    A_k & = & g_k + h_k * W^k \\, \\mbox{ where}\\\\\n    g_k & = & \\sum_{0<=2j<N} a_{2j}   * (W^2)^{k j}\\\\\n    h_k & = & \\sum_{0<=2j<N} a_{2j+1} * (W^2)^{k j}\n\\end{eqnarray}\nare FFTs of half the size (on the even and odd indexed a[]'s, respectively)\nnote that $g_k$ and $h_k$ are periodic in k with period $N/2$, \nsince $W^{N/2} = -1$,\nso that if $T(N)=\\mbox{time to calculate FFT of size N}$, then \n$T(N)=2T(N/2)+O(N)$ and so $T(N)=O(N \\ln N)$. The inverse transform is:\n\\begin{equation}\n    a_k  =  \\mbox{Ninverse}  \\sum_{j=0}^{N-1} a_j \n              \\mbox{Winverse}^{k j} \\mbox{  for k=0..N-1}\n\\end{equation}\nalso an FFT and is calculable by the same method. (Ninverse*N=1. Winverse*W=1.)\nCooley-Tukey also works for general highly composite N.\nA short and elegant implementation is:\n[Warren E.Ferguson: A simple derivation of glassman's general N FFT,\nComputers \\& Math. with Applics. 8 (1982) 401-411].\n\nFor an efficient implementation of the FFT, further refinements are desired.\nThese include: \n\\begin{enumerate}\n\\item Removal of the recursion by \"reverse binary permuting\" the\noriginal data; \n\\item \"In place\" implementation with no extra storage requirement;\n\\item Calculation of the $W^k$'s (k=0,1..) by efficient and stable recurrences\n(thus avoiding the need for transcendental functions); \n\\item Possibly use \"fast complex multiplication\"; \n\\item In specific but common applications,\nsome further savings may be possible. Thus when doing a fast convolution\nof two arrays of N reals using an FFT, the two FFTs may be \naccomplished by ONE N point complex FFT, \nfollowed by linear time uncombining/termwise\nmultiplication step, followed by a N/2 point reverse FFT. \nThe reverse binary\npermuting stages may be avoided completely. \n\\end{enumerate}\n\nThe basic symmetry here is that\nthe FFT of a real array is \"conjugate even\", e.g.\n\\begin{equation}\n    A_k = \\mbox{CompConjugate}(A_{N-k}) \\mbox{ if a[0..n-1] is real}\n\\end{equation}\n\nR.C.Singleton [e.g. see his algorithm for fast circular convolutions,\nCACM 12,3 (March 1969) 179; his FFT2 algorithm, CACM 11 (Nov 1968) 773-779;\nand his article CACM 10 (Oct 1967) 647-654] has suggested a second \ndifference\nmethod [which keeps the real and imaginary parts of exp(ick) uncoupled] \nfor evaluating exp(ick):    \n\\begin{eqnarray}\n    e^{ic(k+1)} & = & e^{ick} + I_{k+1}\\\\\n    I_{k+1} & = & -4 \\sin^2(c/2) e^{ikc} + I_k\\\\   \n    I_0 & = & 2 i \\sin(c/2) e^{-ic/2}\n\\end{eqnarray}\nwhich is both faster and experimentally far more stable (typically\nyielding 500 times smaller error for 128 point transform+inverse transform)\nthan the straightforward \"multiply by exp(ic)\" method. (It's more stable\nbecause of the small multiplier $-4 \\sin^2(c/2)$, as opposed to 1.)\n\nHowever a better idea which I recently thought of is to use this recurrence:\n\\begin{equation}\n    e^{ic(k+1)} = e^{ic(k-1)} + 2 i \\sin(c) e^{ick}\n\\end{equation}\nwhich requires only 2*,2+ per complex exponential (Singleton is 2*,4+;\nnaive method is 4*,2+ and isn't stable) and is also stable since it involves\nthe small multiplier $2 i \\sin(c)$. (In fact, this method runs faster than\nSingleton, is easier to program, and even yielded slightly better accuracy\nin the test program below, too!) Therefore this modification of Singleton\nis the method I've used.\n\nIncidentally, Press et al. in their NR book use the Singleton algorithm\nbut neglect to credit Singleton!\n\nBy a trivial modification of my code, one could generate the sines and\ncosines by repeated application of the bisection identities:\n\\begin{eqnarray}\n    \\cos(t/2) & = & \\sqrt{0.5 (1.0 + \\cos(t))}\\\\\n    \\sin(t/2) & = & 0.5 \\sin(t)/\\cos(t/2)\n\\end{eqnarray}\nstarting from the values with $t=\\pi$ and $t=\\pi/2$ as special cases, thus\navoiding trig subroutine calls entirely. \nOK, I've now done this; now using precomputed table.\n\nThe time savings introduced by either of these is small, however.\nFinally, \"radix 8\" transforms are experimentally the most efficient,\ntypically 20\\% faster than \"radix 2\" routines like this one, although far\nmore complicated; and anyway I suspect the advantage is $<20\\%$ \nin the modern cache-memory system world, since I suspect the radix 2 algorithm\nhas better cache locality. However, that has not been tested.\n\nAlso you could take advantage of 1's and 0's to save a little time at\nthe expense of considerably more space.\n\nAnother idea which I have chosen not to implement is the fact that two\ncomplex numbers may be multiplied in 3 real multiplications:\nThus  $E+iF = (a+bi)*(c+di)$  may be accomplished via the instructions\n\\begin{eqnarray}\n  bpa & = & b+a; \\\\\n  bma & = & b-a; \\\\\n  E & = & a*(c+d);\\\\ \n  F & = & bma*c+E; \\\\\n  E & -= & bpa*d;\n\\end{eqnarray}\nand if bpa and bma are precomputed, this is a 3*,3+ method for a complex\nmultiplication. This idea may be used to reduce (?) the box score from\nthe present  $2N \\ln N+2N+O(\\ln N)$ mults, \n$3N \\ln N+2N+O(\\ln N)$ adds  to\n$1.5N \\ln N+2N+O(\\ln N)$ mults  and  $3.5N \\ln N+4N+O(\\ln N)$ adds. \nIf a floating point\nmultiplication is M times slower than a floating point addition,\nthis idea pays iff $ln N>4/(M-1)$. On PDP-11/44 C, however, rough timing\nhas shown that $M=1.08$ (but with considerable standard deviation.\nIt does\nabout $5*10^4$ additions/sec.) so this idea is not worth it unless N is\nenormous.\n\nSome similar, but worse, ideas have been suggested by Buneman:\n\\begin{verbatim}\n If c=cos(m),s=sin(m), then precompute  \n    t1 = (1-c)/s = s/(1+c)= tan(m/2)  and\n    t2 = (1+s)/c = c/(1-s). \n\\end{verbatim}\nThen $X+iY = (a+bi)*(c+is)$ may be found in 3*,3+ by:\n\\begin{verbatim}\n  if(|t1|<|t2|) then\n     X = a-t1*b; Y = b+s*X; X -= t1*Y;\n  else\n     X = b+t2*a; Y = c*X-a; X -= t2*Y;\n\\end{verbatim}\ntans may be updated by  \n$\\tan(x+y)-\\tan(x-y) = 2*\\tan(y)/(1-(\\tan(x)*\\tan(y))^2)$,\nbut the extra overhead seems not to be worth it].\n\nThere is also a symmetric 3*,5+ (4+ with precomputation) formula for  \n$E+iF = (a+bi)*(c+di)$:\n\\begin{eqnarray}\n  E & = & a*c-b*d\\\\\n  F & = & (a+b)*(c+d)-a*c-b*d\n\\end{eqnarray}\n\nOther FFT algorithms: Winograd has shown how to design FFTs with N prime\n(as opposed to the Cooley-Tukey approach which works for N highly composite)\nthat run in $O(N \\ln N)$ time and even with only O(N) multiplications;\nthe latter figure is optimal. [S.Winograd: Math. of Comput. 32 (1978) 175-179;\nAdvs in Math 32 (1979) 83-117].\n\nWinograd's approach is based on a theorem that allows him (by a permutation\nof the original and transformed variables) to express FFTs for N prime\nin terms of a circular convolution of N-1 elements, plus some additions.\nHe then shows how circular convolutions of k elements (for certain small k)\nmay be computed in a small number of arithmetic operations, (for k=2..6,\nthe number of multiplications Winograd uses is 2,4,5,10,8; for k prime,\nWinograd shows that a (2k-2)* scheme for CC(k) always exists) and further, how\nCC(n1) and CC(n2) algorithms may be composed to make a CC(n1*n2) algorithm, IF\nn1 and n2 are relatively prime, that uses mult(n1)*mult(n2) multiplications.\nAlso, he shows how FFT(n1*n2) may be computed via FFT(n1) and FFT(n2)\nin mult(n1)*mult(n2) multiplications, IF n1,n2 relatively prime, and\nalso gives methods for FFT(prime power). He gives two appendices\ncontaining optimized CC(2..6) and FFT(2..9) algorithms. Winograd's methods\ndon't appear suitable for general N, but if N is specified in advance, they\nmake it possible to do considerable fine tuning at the expense of\nlarge algorithm complexity.\n\nMeanwhile, Nussbaumer [H.J.Nussbaumer: Fast Polynomial Transform algorithms\nfor digital convolutions, IEEE Transactions on Audio, Speech, Signal Processing\n28,2 (April 1980) 205-215 (this article has many references to other FFT\nschemes); see also Knuth 2: 503, 652-653] has found another way to do circular\nconvolutions of arrays of (N=a power of 2) reals without any NTTs, FFTs, trig,\nor complex numbers. His approach is based on viewing circular convolutions\nas polynomial multiplications modulo certain simple polynomials, factoring the\nmodular polynomials, divide and conquer, chinese remainder thm.\nHis approach uses roughly NlgN *,\n$N \\ln N \\ln \\ln N$ +, is fairly complicated to program, and requires extra space.\n\n[Nussbaumer \\& Quandalle: IBM JResDev 22 (1978) 134-144] show how some\nparticularly efficient CC and FFT schemes for N in the range 10-3000\nmay be constructed; their approach is based on some novel ways to combine\nefficient small CC schemes that is rather like the NTT (Number theoretic\ntransform) only in rings of polynomials rather than in the integers.\n\nHowever even the best known arithmetic op count methods only improve on my\nmethod by perhaps 30\\%, and at the cost of considerable complexity.\nC.H.Papadimitriou [Optimality of the FFT, JACM 26 (1979) 95-102 and its refs]\nhas shown that in some models of computation $O(N\\ln N)$ is\noptimal for the FFT, while Patterson et al have shown a lower\nbound of $O(N\\ln N/\\ln \\ln N)$ for integer multiplication on multitape\nTuring machines, see Knuth 2.\n\nFFTs in a finite field (if the ring ZmodK, called \"number theoretic\ntransforms\") are discussed in Aho,Hopcoft,Ullman: The Design and Analysis\nof Computer algorithms, Addison-Wesley 1974. They recommend using W=2,\nN=a power of 2, do all arithmetic in the ring of integers \nmodulo $2^{N/2}+1$\n(in which W is an Nth root of unity, and in which the convolution theorem\n\\begin{equation}\n    C_i=A_iB_i  \\Longleftrightarrow   \n         c_i = \\sum_{j=0}{N-1} a_i*b_{i-j \\bmod N}\n\\end{equation}\n[Which makes possible the calculation of discrete convolutions in $N\\ln N$ time]\nstill holds). [See also R.Agrawal\\&C.Burrus: NTTs to implement fast digital\nconvolutions, ProcIEEE 63 (1975) 550; articles by H.Nussbaumer on \"Fermatrix\"\nand \"Mersenne\" transforms, IBMJR\\&D 21 (1976) 282 and 498.]\n\nThese FFFFTs are of use in applications where it is desirable\nto completely eliminate roundoff error and floating point operations,\ne.g. all-integer convolutions. However, as you can see, NTTs have severe\nword length and transform length limitations; the need for high precision\nmodular arithmetic can be a major stumbling block. On the other hand,\nmultiplications by W=2 are easy, while modular arithmetic modulo a\nFermatrix number is not that hard. Thus using N=16, modulo 65537 arithmetic,\nW=2 [left shift and modulo], Winverse=32769 [right shift; modular\naddition correction if inexact], and all numbers in 0..89 allows\ncomputation of CC(16) in 16*, many bit shifts and additions.\n\nRabiner,Schafer,Rader: The Chirp-Z transform and its Applications,\nBSTJ 48,3 (1969) 1249-1292 show how DFTs (for any N) may be calculated in\n$N\\ln N$ time by using fast convolutions; the method also works for an extension\nof FFTs (to W=any complex number, not just the principal Nth root of unity):\n\\begin{equation}\n    A_k  =  \\sum_{j=0}^{N-1}a_j*W^{k*j}  \\mbox{ for k=0..N-1}\n\\end{equation}\nmay be calculated in $N\\ln N$ time by a fast convolution by the \"Chirp-Z\ntransform\" identity\n\\begin{equation}\n    A_k  = W^{k*k/2} \\sum_{j=0}^{N-1} W^{-((j-k)^2)/2} W^{j*j/2}b_j\n\\end{equation}\n\nAho,Stieglitz,Ullman: Evaluating Polynomials at fixed sets of points,\nSIAMJComp 4,4 (Dec 1975) 533-539, demonstrate that a polynomial and all its\nderivatives at one point (or equivalently, an origin shift of an Nth\ndegree polynomial) may be calculated in $N\\ln N$ time by a fast convolution\nvia the (binomial theorem) identity\n\\begin{eqnarray}\n    \\sum_{j=0}^{N-1} c_j*(x+q)^j  & = & \\sum_{r=0}^{N-1} x^r * d_r/r!\n  \\mbox {  where}\\\\\n    d_r & = & \\sum_{j=r}^{N-1} c_j*j! * q^{j-r}/(j-r)!\n\\end{eqnarray}\n\nSome other applications of FFTs are:\n\nFast multiplication and division of N digit integers may be done in\n(roughly) $N\\ln N$ time by using fast convolutions followed by a carry step.\n(See Aho-Hopcoft-Ullman: Design and Analysis of Computer algorithms, for\nfurther discussion.)\n\nBase conversion of an N digit number may be done in $N(\\ln N)^2$ time by\ndivide and conquer (convert the left and right half of the number recursively,\nthen do a fast multiplication and addition to combine them).\n\nFast polynomial multiplication and division by fast convolutions in $N\\ln N$\ntime are also discussed in AHU. (This may also be done for Chebyshev\nseries...) Given the N roots of a polynomial, you can find its\ncoefficients (as Chebyshev or as regular) in $N(\\ln N)^2$ time by fast\npolynomial multiplications on a binary tree. On the other hand,\nyou can perform a \"root squaring\" transformation on a polynomial\nin (Chebyshev or power form)\n\\begin{equation}\n   P(y) = -P(x)*P(-x)  \\mbox{ where }y = x^2\n\\end{equation}\nin $N\\ln N$ time by a fast multiplication, or alternatively can implement\na Henrici-Gargantini or Korsak-Pease (or other) simultaneous all root iteration\nstep, in $N(\\ln N)^2$ time by a fast multipoint evaluator, see below.\n\nAll shifted correlations of vectors (and/or autocorrelations) may be\ncalculated in $N\\ln N$ time by fast convolutions; this has application in\nsignal processing, 1D pattern recognition, Electrical engineering.\n\nFast polynomial multiplication/division/remaindering and a divide and\nconquering of the Lagrange interpolation formula may be used to do fast\nNth degree polynomial interpolation and N-point evaluation, as was\nshown by Borodin\\&Moenck [JCompSystSci 1974]. I have extended B\\&M's\nresults to Chebyshev polynomials and less successfully to other\npolynomials.\n\nFast algorithms exist for power-series to continued fraction interconversion;\nthese may also be generalized to Chebyshev series.\n\nFast polynomial evaluation/interpolation at special point sets\n(e.g. $Z^k$ for some Z) may be accomplished in $N\\ln N$ time by the Chirp-Z and\nFF transforms; this also carries over to Chebyshev. Thus fast Taylor\nand Chebyshev series calculations.\n\nFast composition of Taylor series -\n$O((N\\ln N)^{3/2})$ is also possible, as was discovered by Brent\\&Kung,\nvia a \"block Horner\" approach. This may also be extended to Chebyshev.\n\nFast Elliptic linear PDE solvers (by finite differneces or spectrally):\nthere are many schemes based on FFTs that run in $N\\ln N$ time, N=size of\noutput.\n\nA complete list of FFT applications is far too huge to discuss here...\n\n", "meta": {"hexsha": "717bef647b432b4a8c42724eb2f9fa4b50c03eca", "size": 15440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/fft.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/fft.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/fft.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": 46.9300911854, "max_line_length": 82, "alphanum_fraction": 0.7267487047, "num_tokens": 4726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6411071608251628}}
{"text": "\\section{Modelization of a DC-DC converter}\nIn the system we want to simulate, as in many real-life systems, is present a DC-DC converter, which will have its non-idealities too, resulting in energy losses.\n\nThis means, while in an ideal DC-DC converter the input and output power will be equal ($P_{in}=P_{out}$), in a real one the output power will be scaled by a factor $\\eta$, and thus it will be $\\eta P_{in}=P_{out}$. $\\eta$ will be called \\emph{efficiency} of the DC-DC converter. in order to simulate the blocks into SimuLink, we wanted to find a good expression approximating the power loss due to the non-unary efficiency ($P_{loss}$). The chosen analytical expression to fit on the $P_{loss}$ data has been a quadratic one:\n$$\nP_{loss}=c_1I_{out}^2+c_2I_{out}+c_3\n$$\n\nAs in the previous part, the first work has consisted in extrapolating data from a graph present into the datasheet of the converter (\\emph{LTC3789}), in order to obtain a current-efficiency curve. It has been important to notice that the data were in logarithmic scale on the X axis, and so have had to be interpolated as exponents and transformed into linear values post-audit.\n\nAfter extracting data from the graph and linearly interpolating it, in order to fit the analytical onto the $P_{loss}$ data it has been needed to use the relationship (which is valid by definition of $\\eta$) between $\\eta$ and $P_{loss}$:\n\\begin{gather*}\n\\eta=\\frac{P_{out}}{P_{in}} \\\\\n\\Downarrow \\\\\n\\eta=\\frac{P_{out}}{P_{out}+P_{loss}}\n\\end{gather*}\n\nInstead of reverting this equation and doing a two-step process to fit the curve, again the \\emph{fmins} has been used to evaluate fitting between the available $\\eta$ data and the new $P_{loss}$ data. The handle passed to \\emph{fmins} calls a function which evaluates the expected $\\eta$ vector starting from a sample $P_{loss}$ vector, compares it with the actual $\\eta$ vector and returns the squared difference (i.e. the error) between the two. Minimizing this cost function is equivalent to fitting the $P_{loss}$ curve to the desired one.\n\nAgain, the result has been satisfactory enough.\n\n\\begin{center}\n\\begin{tabular}{|c| c|}\n\n    \\hline\n    Parameter name & Parameter value \\\\\n    \\hline\n    $c_{1}$ & 0.0309 \\\\\n    $c_{2}$ & 0.1166 \\\\\n    $c_{3}$ & 0.4535 \\\\\n    \\hline\n\\end{tabular}\n\n\\begin{figure}[h]\n  \\centering\n\\includegraphics[width=2.5in]{fitted_eta}\n\\caption{Current-Efficiency curve as computed after fitting $P_{loss}$}\n\\end{figure}\n\\begin{figure}[h]\n  \\centering\n\\includegraphics[width=2.5in]{ploss}\n\\caption{Obtained Current-Power loss curve for the converter}\n\\end{figure}\n\n\\end{center}\n", "meta": {"hexsha": "71be8174e7bc07cf85877f0fbf365ad77399952a", "size": 2623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/ass3.tex", "max_stars_repo_name": "conte91/ENOPT_Lab4", "max_stars_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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/ass3.tex", "max_issues_repo_name": "conte91/ENOPT_Lab4", "max_issues_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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/ass3.tex", "max_forks_repo_name": "conte91/ENOPT_Lab4", "max_forks_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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.0217391304, "max_line_length": 544, "alphanum_fraction": 0.7392298894, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6410827158558332}}
{"text": "% $Id$\n%\n% Author: David Fournier\n% Copyright (c) 2008 Regents of the University of California\n%\n\n\\section{The necessity for adjoint code}\n\nWhen you write code for variable objects in \\ADM, all the\nderivatives are calculated for you in a transparent manner. \nTo accomplish this, \\ADM\\ must save certain information for\nlater use. We shall refer to this as derivative information.\nEach arithmetic operation generates about 32~bytes of\nderivative information.  If you have some simple function that\nhas 20 arithmetic operations, it will therefore\ngenerate 640 bytes of derivative information every time\nit is called. The purpose of writing adjoint code is to\nreduce the amount of derivative information that must\nbe calculated. For a function that is called many times,\nthis can greatly reduce the amount of derivative information that\nmust be stored.\n\nIn this chapter, we investigate how to write and debug\nadjoint code. To begin, we investigate how to write adjoint code for a\nsimple function that takes 1--4 independent variables and returns 1~dependent variable. \nThe adjoint code for such functions is\nsimpler to write than that for a general function---such as the\nsingular value decomposition of a matrix, which we will consider later.\n\n\n\\section{Writing adjoint code: a simple case}\n\nConsider a simple function $f$ which takes 1~independent variable $x$\nand returns a dependent variable $y$, i.e.,\n$$y=f(x)$$\nwhere $f(x)=\\exp(-x^2/2)$. The code for this example can be written like\n\\begin{lstlisting}\n  dvariable errf(const prevariable& x)\n  {\n    return exp(-0.5*square(x));\n  }\n\\end{lstlisting}\nThere are three arithmetic operations here: square, multiplication, and exponentiation,\nso 96 bytes of derivative information will be generated. (Actually, the \\texttt{return} operation\nalso generates 32 bytes of derivative information, but we will ignore that for now.)\nA less efficient way to write the code (but more useful for \nshowing adjoint code for this simple example) would be:\n\\begin{lstlisting}\n  dvariable errf(const prevariable& x)\n  {\n    dvariable y;\n    y=exp(-0.5*square(x));\n    return y;\n  }\n\\end{lstlisting}\nHere is the same code with the derivative calculated by the one line of adjoint\ncode \\texttt{double dfx=-value(x)*value(y);}:\n\\begin{lstlisting}\n  dvariable errf(const prevariable& x)\n  {\n    dvariable y;\n    value(y)=exp(-0.5*square(value(x)));\n    double dfx=-value(x)*value(y);\n    AD_SET_DERIVATIVES1(y,x,dfx);  // 1 dependent variable \n    return y;\n  }\n\\end{lstlisting}\nSo what is going on here? Consider the line\n\\begin{lstlisting}\n  value(y)=exp(-0.5*square(value(x))); \n\\end{lstlisting}\nThe \\texttt{value} function returns a constant type, that is, a double, \nthat has the same value as the corresponding \\texttt{dvariable} or prevariable.\nIn fact, it is the {\\it same} object.  That is, it shares the same address,\nbut the type has been changed to double. So, the above line of\ncode assigns the value \\texttt{exp(-0.5*square(value(x)))} to \\texttt{y},\nbut without generating any derivative code. Similarly, since\nthe calculations are made on \\texttt{value(x)}, these calculations\nwill not generate any derivative code. So, it is the responsibility of the\nprogrammer to calculate the derivative code and store it where it\ncan be used later. The line\n\\begin{lstlisting}\n  double dfx=-value(x)*value(y);\n\\end{lstlisting}\ncalculates the derivative $f^\\prime(x)$\nof $y$ with respect to $x$ and stores it with the line of code\n\\begin{lstlisting}\n  AD_SET_DERIVATIVES1(y,x,dfx);\n\\end{lstlisting}\nThis code will only generate 32 bytes of derivative information.\n\n\n\\section{Debugging adjoint code: a simple case}\n\nThe simplest way to debug the adjoint code is to put your new\nfunction into an \\ADM\\ template file and use the \\texttt{-dd 1}\ncommand line option to call the derivative checker.\n\\XX{\\fontindexentry{tt}{-dd}}{command line argument}\n\\XX{command line arguments}{\\fontindexentry{tt}{-dd}}\n\\begin{lstlisting}\nDATA_SECTION\nPARAMETER_SECTION\n  init_number x\n !! x=2;\n  objective_function_value f;\nPROCEDURE_SECTION\n  f=square(errf(x));\n  \nGLOBALS_SECTION\n  #include <admodel.h>\n  dvariable errf(const prevariable& x)\n  {\n    dvariable y;\n    value(y)=exp(-0.5*square(value(x)));\n    double dfx=-value(x)*value(y);\n    AD_SET_DERIVATIVES1(y,x,dfx);  // 1 dependent variable \n    return y;\n  }\n\\end{lstlisting}\n\n\n\\section{Adjoint code for more than\\br one independent variable}\n\nThe following code shows how to write the adjoint code for a function with two\nindependent variables:\n\\begin{lstlisting}\nDATA_SECTION\n  vector lengths(1,10)\n  vector ages(1,10)\n  !! lengths.fill_seqadd(1,1);\n  !! ages.fill_seqadd(1,1);\n  !! lengths=sqrt(lengths);\n\nPARAMETER_SECTION\n  init_bounded_number linf(0,10) \n  init_bounded_number rho(0,1) \n  objective_function_value f;\nPROCEDURE_SECTION\n  for (int i=1;i<=10;i++)\n    f+=square(lengths(i)-vb_growth(linf,rho,ages(i)));\n  \nGLOBALS_SECTION\n  #include <admodel.h>\n\n  dvariable vb_growth(const prevariable& linf, const prevariable& rho, \n    double t)\n  {\n    double clinf=value(linf);\n    double crho=value(rho);\n    dvariable len;\n    value(len)=clinf*(1-pow(crho,t));\n    double dflinf=1-pow(crho,t);\n    double dfrho=-clinf*t*pow(crho,t-1);\n    AD_SET_DERIVATIVES2(len,rho,dfrho,linf,dflinf);  // 2 dependent variable \n    return len;\n  }\n\\end{lstlisting}\nThis approach to writing adjoint code has been implemented for functions of\nup to four independent variables.\n\\begin{lstlisting}\nDATA_SECTION\n  vector lengths(1,10)\n  vector ages(1,10)\n  !! lengths.fill_seqadd(1,1);\n  !! ages.fill_seqadd(1,1);\n  !! lengths=sqrt(lengths);\n\nPARAMETER_SECTION\n  init_bounded_number linf(0,10) \n  init_bounded_number rho(0,1) \n  init_number t0 \n  init_bounded_number gamma(.1,1.9) \n  objective_function_value f;\nPROCEDURE_SECTION\n  for (int i=1;i<=10;i++)\n    f+=square(lengths(i)-vb_growth(linf,rho,t0,gamma,ages(i)));\n  \nGLOBALS_SECTION\n  #include <admodel.h>\n\n  dvariable vb_growth(const prevariable& linf, const prevariable& rho, \n    const prevariable& t0, const prevariable gamma,double t)\n  {\n    double clinf=value(linf);\n    double ct0=value(t0);\n    double crho=value(rho);\n    double cgamma=value(gamma);\n    dvariable len;\n    value(len)=pow(clinf*(1-pow(crho,t-ct0)),cgamma);\n    double tmp=cgamma*pow(clinf*(1-pow(crho,t-ct0)),cgamma-1);\n    double dflinf=tmp*(1-pow(crho,t-ct0));\n    double dft0=tmp*(clinf*log(crho)*pow(crho,t-ct0));\n    double dfrho=-tmp*clinf*(t-ct0)*pow(crho,t-ct0-1);\n    double dfgamma=value(len)*log(clinf*(1-pow(crho,t-ct0)));\n    AD_SET_DERIVATIVES4(len,t0,dft0,rho,dfrho,linf,dflinf,gamma,dfgamma); \n       // 4 dependent variable \n    return len;\n  }\n\\end{lstlisting}\n\n\n\\section{Structured calculation of derivatives in adjoint code}\n\nUntil now, we have deliberately calculated the derivatives with respect to the independent\nvariables in an {\\it ad-hoc} fashion. While this approach works for simple functions,\nit rapidly becomes untenable when the function is more complicated. In the following example,\nwe have calculated the derivatives in a more structured fashion. Notice that to calculate the\nderivatives, every line of code in the function is repeated in the opposite\norder (commented out, of course) and the corresponding derivatives are calculated.\n\\begin{lstlisting}\nDATA_SECTION\n  vector lengths(1,10)\n  vector ages(1,10)\n  !! lengths.fill_seqadd(1,1);\n  !! ages.fill_seqadd(1,1);\n  !! lengths=sqrt(lengths);\n\nPARAMETER_SECTION\n  init_bounded_number linf(0,10) \n  init_bounded_number rho(0,1) \n  init_number t0 \n  init_bounded_number gamma(.1,1.9) \n  objective_function_value f;\nPROCEDURE_SECTION\n  for (int i=1;i<=10;i++)\n    f+=square(lengths(i)-vb_growth(linf,rho,t0,gamma,ages(i)));\n  \nGLOBALS_SECTION\n  #include <admodel.h>\n\n  dvariable vb_growth(const prevariable& linf, const prevariable& rho, \n    const prevariable& t0, const prevariable gamma,double t)\n  {\n    double clinf=value(linf);\n    double ct0=value(t0);\n    double crho=value(rho);\n    double cgamma=value(gamma);\n    dvariable len;\n    double u1=pow(crho,t-ct0);\n    double u2=clinf*(1-u1); \n    value(len)=pow(u2,cgamma);\n    double dflen=1.0;\n    //value(len)=pow(u2,cgamma);\n    double dfu2=dflen*cgamma*pow(u2,cgamma-1.0);\n    double dfgamma=dflen*value(len)*log(u2);\n    //double u2=clinf*(1-u1); \n    double dflinf=dfu2*(1-u1);\n    double dfu1=-dfu2*clinf;\n    //double u1=pow(crho,t-ct0);\n    double dfrho=dfu1*(t-ct0)*pow(crho,t-ct0-1.0);\n    double dft0=-dfu1*u1*log(crho);\n\n    AD_SET_DERIVATIVES4(len,t0,dft0,rho,dfrho,linf,dflinf,gamma,dfgamma);  \n      // 4 dependent variable \n    return len;\n  }\n\\end{lstlisting}\n\n\n\\section{General adjoint code}\n\nSo far, the adjoint code has been for a simple function which has from~1 to~4\nindependent variables and returns 1~dependent variable. \nNow we consider the general case where the function can take\nany number of dependent variables and return any number of \ndependent variables, and these variables can be in the form of numbers, \nvectors, or matrices.\n\\begin{lstlisting}\n dvar_vector  operator * (_CONST dvar_matrix& m,_CONST dvar_vector& x )\n {\n   if (x.indexmin() != m.colmin() || x.indexmax() != m.colmax())\n   {\n     cerr << \" Incompatible array bounds in dvar_vector  operator * \"\n            << \"(_CONST dvar_matrix& m,_CONST dvar_vector& x)\\n\";\n     ad_exit(21);\n   }\n\n   dvar_vector tmp(m.rowmin(),m.rowmax());\n   double sum;\n\n   for (int i=m.rowmin(); i<=m.rowmax(); i++)\n   {\n     sum=0.0;\n     for (int j=x.indexmin(); j<=x.indexmax(); j++)\n     {\n       sum+=(m.elem(i)).elem_value(j)*x.elem_value(j);\n     }\n     tmp.elem_value(i)=sum;\n   }\n  save_identifier_string(\"PLACE4\");\n  x.save_dvar_vector_value();\n  x.save_dvar_vector_position();\n  save_identifier_string(\"PLACE3\");\n  m.save_dvar_matrix_value();\n  m.save_dvar_matrix_position();\n  save_identifier_string(\"PLACE2\");\n  tmp.save_dvar_vector_position();\n  save_identifier_string(\"PLACE1\");\n  \n  ADJOINT_CODE(dmdv_prod);\n   return(tmp);\n }\n\\end{lstlisting}\nTo calculate the adjoint code, it will be necessary to have the\nvalues of the matrix \\texttt{m} and the vector \\texttt{x}.\nThis is accomplished with the instructions\n\\begin{lstlisting}\n  x.save_dvar_vector_value();\n  m.save_dvar_matrix_value();\n\\end{lstlisting}\nAlso, to calculate the derivatives, it will be necessary to know where the\nderivatives with respect to the independent and dependent variables are \nlocated. This information is saved with the instructions\n\\begin{lstlisting}\n  x.save_dvar_vector_position();\n  m.save_dvar_matrix_position();\n  tmp.save_dvar_vector_position();\n\\end{lstlisting}\nFinally, we need to save the name of the routine that calculates\nthe adjoint code, so that it can be called at the appropriate time. To write the\ncode for the adjoint calculations, keep in mind that everything must be recovered\nfrom the stack in the reverse order from which it was put on the stack.\nThis process can be a bit confusing and if you don't do it properly, the \nstack will become corrupted and nothing will work.  To help diagnose\nproblems, function \\texttt{save\\_identifier\\_string} can be\nused to put a string on the stack. This string value can be checked in the\nadjoint code with the \\texttt{verify\\_identifier\\_string} function. At least two of\nthese functions should be left in any adjoint code, so that stack\nintegrity can be monitored if problems show up later. For optimized code,\nthey are not used, and so contribute almost nothing to the overhead.\n\nThe adjoint code begins by reading the information that was saved on the stack.\nAn object of type \\texttt{dvar\\_vector\\_position} contains both the size and\naddress information associated with a \\texttt{dvar\\_vector}---which are needed to\nrecover or store derivative values, or to build a \\texttt{dvector} with the\nsame shape as the {\\t dvar\\_vector}.\nThe function \\texttt{restore\\_dvar\\_vector\\_der\\-ivatives} gets the values of the\nderivatives with respect to the dependent variables, so they can be used in the\nadjoint code. The functions\n\\begin{lstlisting}\n   dfx.save_dvector_derivatives(x_pos);\n   dfm.save_dmatrix_derivatives(m_pos);\n\\end{lstlisting}\nuse the position information to save the derivatives with respect to the\nindependent variables in the appropriate places.\n\\begin{lstlisting}\nvoid dmdv_prod(void)\n{\n  verify_identifier_string(\"PLACE1\");\n  dvar_vector_position tmp_pos=restore_dvar_vector_position();\n  verify_identifier_string(\"PLACE2\");\n  dvar_matrix_position m_pos=restore_dvar_matrix_position();\n  dmatrix m=restore_dvar_matrix_value(m_pos);\n  verify_identifier_string(\"PLACE3\");\n  dvar_vector_position x_pos=restore_dvar_vector_position();\n  dvector x=restore_dvar_vector_value(x_pos);\n  verify_identifier_string(\"PLACE4\");\n  dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);\n  \n  dmatrix dfm(m_pos);\n  dvector dfx(x_pos.indexmin(),x_pos.indexmax());\n  dfm.initialize();\n  dfx.initialize();\n  \n   double dfsum;\n   for (int i=m.rowmax(); i>=m.rowmin(); i--)\n   {\n     // tmp.elem_value(i)=sum;\n     dfsum=dftmp.elem(i);\n     for (int j=x.indexmax(); j>=x.indexmin(); j--)\n     {\n       //sum+=(m.elem(i)).elem_value(j)*x.elem_value(j);\n       dfm.elem(i,j)+=dfsum*x.elem(j);\n       dfx.elem(j)+=dfsum*m.elem(i,j);\n     }\n     //sum=0.0;\n     dfsum=0.0;\n   }\n   dfx.save_dvector_derivatives(x_pos);\n   dfm.save_dmatrix_derivatives(m_pos);\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "89acabdc64f5fc3f25d3b3f0c7c815cfa48f1ec3", "size": 13338, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manuals/admb/adjoint.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/adjoint.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/adjoint.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": 34.8250652742, "max_line_length": 97, "alphanum_fraction": 0.7358674464, "num_tokens": 3675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6410827103103446}}
{"text": "\\section{Extension to Higher Dimensions}\\label{sec:mud-higher-dimensions}\nWe now show that when the dimension of $\\pspace$ is higher, the benefit from maximizing the dimension of the QoI map is even more considerable than what we observed in the two-dimensional cases, as long as we aggregate data into components of the QoI map in a purposeful manner.\nIn the first example, we demonstrate the impact of increasing the volume of the parameter space while fixing all other attributes of the inverse problem.\nIn the second example, we illustrate how we could utilize the solution to the SIP for the two-dimensional case from \\ref{subsec:pde-example} to improve the MUD estimate in five dimensions.\n\n\\subsection{A SIP with a Naive Initial Density}\nConsider a naive implementation in five dimensions, where the same prior knowledge on the bounds of $g$ inform the choice of a parameter space.\nSuppose $\\pspace$ is given by $[-4, 0]^5$, induced by five regularly-spaced knot points in the interior of $x_2 \\in (0,1)$ for which a uniform density is assumed in each component.\nIn Figure~\\ref{fig:pde-highd-initial-5d}, we show what one-thousand such initial functions look like, and note that many of them appear to exhibit fluctuating behavior which may require a finer mesh than the one being used to solve the problem ($36\\times36$), in order to reduce numerical errors.\nThis choice of initial density induces a lot of ``conceptual'' noise into the SIP, since ``common sense'' from a modeler's perspective could rule out functions which zig-zag excessively.\n\n\\begin{figure}\n\\centering\n  \\includegraphics[width=0.475\\linewidth]{figures/pde-highd/pde-highd_init_D5.png}\n\\caption{\nOne thousand initial parameter samples (our model evaluation ``bugdet'') were used to estimate $g$, constructed by taking independent uniform samples from $[-4, 0]$ for each direction are shown in purple.\n}\n\\label{fig:pde-highd-initial-5d}\n\\end{figure}\n\nWe solve the SIP for both scalar-- and vector--valued QoI maps.\nThe latter is constructed with horizontal bands\\---which correspond to the partitioning of $\\Omega$ into components of the QoI map\\---shown in the left of Figure \\ref{fig:pde-highd-5d-example}.\nWe refer to this map as $\\qoi_\\text{5D}$, and $\\qoi_\\text{1D}$ will again represent the scalar--valued map.\nIn the right half of Figure~\\ref{fig:pde-highd-5d-example}, the MUD solutions for $\\qoi_\\text{5D}$ and $\\qoi_\\text{1D}$ are shown in parameter space for a representative SIP.\nThe scalar-valued MUD misidentifies the location of $g$'s minimum value, but the vector-valued QoI is able to resolve the general qualitative behavior.\n\n\\begin{figure}\n\\centering\n  \\includegraphics[width=0.45\\linewidth]{figures/pde-highd/pde-highd_sensors_D5}\n  \\includegraphics[width=0.45\\linewidth]{figures/pde-highd/pde-highd_comp_exmud_D5_m100}\n\\caption{\n(Left): Layout for 5-D vector--valued map and comparison of the two MUD solutions in parameter space.\n(Right): Example MUD solutions for $\\qoi_\\text{5D}$ and $\\qoi_\\text{1D}$.\n}\n\\label{fig:pde-highd-5d-example}\n\\end{figure}\n\nIn Figure~\\ref{fig:pde-highd-5d-mud} we plot the results from twenty repeated trials (perturbations of noise) when using all $100$ measurements.\nWe observe, as before, the same difference in going from scalar-- to vector--valued solutions that we saw in two dimensions in Fig.~\\ref{fig:pde-MUD}.\nIn the left half of Figure~\\ref{fig:pde-highd-5d-mud}, the scalar-valued QoI is unable to differentiate between resolving residual discrepancies in different locations in $\\Omega$.\nBy contrast, the vector-valued QoI shown to the right is constructed with respect to the flow of information in the system, and so many more of the twenty trials land closer to the true minimum value of $g$.\nThe solutions for the vector-valued approach instead explore the available knots (at $x_2=1/6$ and $1/3$), nearest the actual minimum value of $2/7$ instead, a much more valuable area of $\\Lambda$ to explore.\n\n\\begin{figure}\n\\centering\n  \\includegraphics[width=0.45\\linewidth]{figures/pde-highd/pde-highd_pair_D5-1_m100}\n  \\includegraphics[width=0.45\\linewidth]{figures/pde-highd/pde-highd_pair_D5-5_m100}\n\\caption{ SIP solutions using $\\qoi_\\text{5D}$ and $\\qoi_\\text{1D}$ for twenty realizations of noise polluting the hundred measurements used to construct the map.\n(Left): Scalar-valued solutions.\n(Right): Vector-valued solutions.\n}\n\\label{fig:pde-highd-5d-mud}\n\\end{figure}\n\n\nRecall from \\ref{subsec:pde-example} that we previously solved a two-dimensional version of this problem.\nWe leverage the effort involved in solving this first problem in order to better refine the approximation of $g$ in \\ref{sec:mud-pde-sequence} below.\nBy using the former SIP solution results to define a much smaller region of $\\pspace$ to explore, the results from the second SIP can improve considerably.\n", "meta": {"hexsha": "6165612bb2ddafcf890fdc86e4dcdfd88f304a80", "size": 4832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "extensions/mud_pde_5d.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": "extensions/mud_pde_5d.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": "extensions/mud_pde_5d.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": 81.8983050847, "max_line_length": 296, "alphanum_fraction": 0.7800082781, "num_tokens": 1247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.803173791645582, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6410826968627072}}
{"text": "\\section{Definition of a battery model}\n\nIn order to define a good model for Li-Po battery, comprehending also a good approximation of all its non-idealities, a two-branches model has been used.\nIn the first part, current SoC is computed, by taking as a reference electrical model a current generator and a capacitor. The discharge current $I_{b}$ charges the capacitor, of capacity $C_{m}$ (representing the total capacity of the battery), producing an output voltage $V_{SOC}$ which represents the SoC. \n\n\nThe output equation of the circuit is thus $V_{SOC} = V_{SOC}(0)+\\int\\!\\frac{I_{b}}{C_{m}}dt$, which is equivalent to the SoC expression for the battery.\n\nThe second part of the model is composed by a voltage generator and a series resistance, as in a usual models of voltage sources. The big difference from standard models is that both the voltage and the series resistance of the battery depend on the current state of charge, and are thus functions of $V_{SOC}$.\n\nThe output of this second circuit is the true battery voltage as seen by the load.\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=3in]{circuit}\n  \\caption{Equivalent circuit of the Li-Po battery}\n\\end{figure}\n\nWhile the first part of the circuit is well-defined by the initial and total capacity of the battery, in the second part the two functions $V(SoC)$ and $R(SoC)$ has to be extracted from available battery data. In this case, the available source of information contained into the battery's datasheet has been the graph showing output voltage ($V_{B}$) as a function of both discharge capacity - which is, after fixing a maximum capacity value, easily convertible to SoC - and load current. The latter dependance is due to the series resistance of the battery.\n\nPoints from these curves have been extracted using a figure digitizer tool into MatLab and have been converted to different Soc-voltage tables. In order to find a good value for R two curves have been necessary (as R affects only the $V_{B}$-$I_{load}$ relationship). To minimize sampling errors, the highest and lowest currents' curves have been digitalized. Finally, the saved data have been interpolated in a linear fashion to obtain a continous sequence of equally-spaced points on the graph.\n\nFrom these data, $V(Soc)$ and $R(Soc)$ values can be easily obtained by solving the second circuit. Although at this point a model of the two circuits has been made, having the values stored as a lookup table is not the best choice, both because of the space occupation which would not scale for bigger graphs, and because of the missing smoothness of the obtained relationship, which is typical of a real-life system. In order to obtain a smoother and simpler relationship, the data have been fitted using MatLab $fmins$ function, in order to have an analytical representation for them:\n\\begin{align*}\nV(SoC)&=b_1e^{(b_2SoC)}+b_3SoC^4+b_4SoC^3+b_5SoC^2+b_6SoC+b_7 \\\\\nR(SoC)&=b_8e^{(b_9SoC)}+b_{10}\n\\end{align*}\n\nThe curve fitting produced a satisfactory result:\n\n\\begin{center}\n\\begin{tabular}{|c| c|}\n\n    \\hline\n    Parameter name & Parameter value \\\\\n    \\hline\n    $b_{1}$ & 1.3518 \\\\\n    $b_{2}$ & -0.7752 \\\\\n    $b_{3}$ & 0.4669 \\\\\n    $b_{4}$ & -1.0723 \\\\\n    $b_{5}$ & 0.8729 \\\\\n    $b_{6}$ & -0.0031 \\\\\n    $b_{7}$ & 2.8434 \\\\\n    $b_{8}$ & 0.0000 \\\\\n    $b_{9}$ & 9.7875 \\\\\n    $b_{1}$ & 0.1909 \\\\\n    \\hline\n\\end{tabular}\n\n\n\\begin{figure}[h]\n  \\centering\n\\includegraphics[width=3in]{fitted_r_curve}\n\\caption{$SoC-R$ curve after fitting}\n\\end{figure}\n\n\n\\begin{figure}[h]\n  \\centering\n\\includegraphics[width=4in]{fitted_vsoc_curve} \n\\caption{$SoC-V$ curve after fitting}\n\\end{figure}\n\n\\end{center}\n\n\n", "meta": {"hexsha": "4bcebf77084738d7de42809ee5ad9cab85e9498e", "size": 3664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/ass1.tex", "max_stars_repo_name": "conte91/ENOPT_Lab4", "max_stars_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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/ass1.tex", "max_issues_repo_name": "conte91/ENOPT_Lab4", "max_issues_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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/ass1.tex", "max_forks_repo_name": "conte91/ENOPT_Lab4", "max_forks_repo_head_hexsha": "2bd11699bc9274c9f0fe3c36b1f39b66f0a9fd2c", "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": 54.6865671642, "max_line_length": 587, "alphanum_fraction": 0.7399017467, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.6410826967674265}}
{"text": "\\chapter{R Background}\nThis chapter describes the R programming techniques that we will need in order\nto do Bayesian statistics both within R and also by using JAGS.\n\n\\section{Vectors}\nWe will use vectors frequently throughout the course. A vector can be thought\nof as a list of numbers. In R, you can create a vector using the function\n{\\tt c}, which stands for ``concatenate''.\n\\begin{verbatim}\nmy_vector = c(12.4, -6.2, 4.04)\n\\end{verbatim}\nYou can then examine the contents of the vector by typing its name.\n\\begin{verbatim}\n> my_vector\n[1] 12.40 -6.20  4.04\n\\end{verbatim}\nThere are various helpful things you can do with vectors. You can get the length\nof a vector (the number of elements in it) like so:\n\\begin{verbatim}\n> length(my_vector)\n[1] 3\n\\end{verbatim}\nYou can do arithmetic\nwith vectors too, if they're the same length. For example:\n\\begin{verbatim}\n> c(1,2,3)*c(2,5,3)\n[1]  2 10 9\n\\end{verbatim}\nIf you wanted, you could assign the output to a new variable:\n\\begin{verbatim}\n> x = c(1,2,3)\n> y = c(2,5,3)\n> z = x*y\n> z\n[1]  2 10 9\n\\end{verbatim}\nIt is important to understand how to access subsets (or ``slices'') of vectors\nbased on which elements satisfy a certain condition. Here is an example:\n\\begin{verbatim}\n> x = c(1, 2, 3, 0, 10)\n> test = x > 3\n> test\n[1] FALSE FALSE FALSE FALSE  TRUE\n> y = x[x <= 2]\n> y\n[1] 1 2 0\n> z = sum(x[x <= 2])\n> z\n[1] 3\n\\end{verbatim}\nThis kind of thing will be used frequently in the computational parts of the\ncourse.\n\n\n\n\n\\section{Lists}\nLists are a bit like vectors, in that they can contain a lot of information in\na single variable. But instead of just being numbers, lists can contain all\nsorts of things. For example, suppose I want a variable/object in an R program\nto represent a person. A person can have a name and an age. Here is how to make\na list:\n\\begin{verbatim}\na_person = list(name=\"Nicole\", age=21)\n\\end{verbatim}\nIf you needed to extract certain elements from a list, you can do it using the\n\\$ operator in R. For example suppose I wanted to extract the {\\tt name} variable\nfrom within {\\tt a\\_person}. I could do this:\n\\begin{verbatim}\n> a_person$name\n[1] \"Nicole\"\n\\end{verbatim}\nand voila. When we use JAGS, a data set will be represented using a list.\nSo will our JAGS output.\n\nIf you have ever learned C, C++, or Matlab, a list in R is basically the same thing as\na ``struct'' in these languages.\nIf you have learned C++, Java, or Python, a list is\nlike a ``class'' but with just variables and no functions.\nIn Python, ``dictionaries''\nare also very similar to R lists.\n\n\\section{Functions}\nIn this course you'll need to be able to read and understand simple R\nfunctions, and perhaps write a few. A function is like a machine that takes\nan input, does something, and returns an output. You have probably used many\nbuilt-in R functions already, like {\\tt sum()}.\n\n\\begin{verbatim}\n# Defining a function called my_function\nmy_function = function(x)\n{\n  # Do some stuff\n  result = 3*x + 0.5\n  return(result)\n}\n\\end{verbatim}\n\n\n\\section{For Loops}\nFor loops are mostly used to repeat an action many times. Here is an example.\n\\begin{verbatim}\nN = 100\nfor(i in 1:N)\n{\n  print(i)\n}\n\\end{verbatim}\n\n\\section{Useful Probability Distributions}\nSince R is a statistics program, it knows about a lot of probability\ndistributions already. So, if I wanted to use the probability density function\nof a normal distribution, instead of having to code something like this:\n\\begin{verbatim}\nf = exp(-0.5*((x - mu)/sigma)**2)/(sigma*sqrt(2*pi))\n\\end{verbatim}\nI can just use the built-in function {\\tt dnorm}.\n\\begin{verbatim}\nf = dnorm(x, mean=mu, sd=sigma)\n\\end{verbatim}\nMuch easier! If, instead of wanting to evaluate the PDF, I wanted to generate\nrandom samples from a normal distribution, I could use {\\tt rnorm}.\n\\begin{verbatim}\n# Generate 1000 samples\nsamples = rnorm(1000, mean=50., sd=10.)\n\\end{verbatim}\n\n", "meta": {"hexsha": "6377a09edc15d2c6cdde573778aa6f97fa524e62", "size": 3876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "r_background.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": "r_background.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": "r_background.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": 30.28125, "max_line_length": 86, "alphanum_fraction": 0.7293601651, "num_tokens": 1114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6410826911742974}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{epstopdf}\n\\usepackage{inputenc}\n\\usepackage{geometry} \n\\usepackage{cancel}\n\\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}\n\n\\begin{document}\n\t\n\t\\title{MITx 15.455x Mathematical Methods for Quantitative Finance\n\t \\\\\n\t\\begin{large} \n\t\tRecitation 3\n\t\\end{large} }\n\n\t\n\t\\maketitle\n\t\n\t\\section*{Module 3: Forecasting}\n\t\n\nLet's talk about forecasting.\nWe saw in lecture that forecasting\nis an application of conditional probability to time series\nmodels.\nSo we think of the time series as generating the data.\nAnd we ask at a given point in time,\ngiven all the observations that exist up\nthrough that point in time, what can we say about the future?\nWe might want to know what happens one time step ahead,\ntwo time steps ahead, or in limit\nas the number of times that goes to infinity,\nbut the key thing is the break between past and future.\nSo we take the present time to be just after we've\nmade our final observation.\nAnd we're first forecast period is one step ahead.\nAnd, as I said, the key tool is in addition to\nour previous ones with expectations,\nlinearity, algebraic substitution, recursion.\nWe had a new one, which is conditional probability.\nIn this setting, conditional probability simply\nmeans that for any variable that was\na random variable in the past that has been realized,\nit's no longer a random variable.\nNow it's a scalar.\nNow it's a number.\nSo those things that show up in the recursion\nthat we previously thought of as random variables,\nin this setting, when we take conditional expectations\nof our defining equations or equations of evolution,\nthen they take a different character,\nbecause they're already known.\nThey're no longer random variables.\nSo we looked at an example in lecture.\nLet's just do a couple of examples together.\nIt's the same structure.\nThey're just one or two things it might be worth\npaying attention to as you look at the blind forecast\nof your own.\nSome of the things that might have look special for the case\nof the AR1 are quite general.\nSo let's take a look at a model.\n\n\\subsection*{ARMA(1,1)}\n\nLet's look at, say, an ARMA(1,1)  which is this form:\n\n$$ x_t = c_o + c_1 x_{t-1} \\sigma z_t + \\phi_1 z_{t-1} $$\n\nSo I'm going to keep the notation $\\sigma z_t$ for our shock for innovation in the period.\nYou could give it another name for its coefficient.\nRemember that $\\sigma$, in this case,\nis not the standard deviation of $x$.\nIt's just a scaling parameter for the random shock $z$.\n\nSo the first thing we'd like to do\nis compute the mean value for $x$ and simplify our expression.\nSo we use our usual trick.\n$\\mu$ is the name will give the expectation of $x_t$.\nAnd then we take expectations on the right hand side\nand apply linearity.\nSo we have this is going to be:\n\n\n$$ \\mu = E[x_t] = c_0 + c_1 E[x_{t-1}] + 0 + 0 $$\n\n$$ \\mu = \\frac{c_0}{1-c_1} $$\n\n\nAnd you should recognize that expression from our AR 1 model.\nIt's exactly the same expression.\nAnd therefore, we can substitute and rewrite our equation\nas a bunch of things that are grouped together in such a way\nthat they all have 0 mean.\nThat is to say, if I substitute for $c_0$\nand say it's equal to $\\mu (1 - c_1)$,\nthen I can write this as:\n\n$$ x_t = \\mu (1 - c1) + c_1 x_{t-1} + \\sigma z_t + \\phi_1 z_{t-1} $$\n$$ x_t - \\mu =   c_1 (x_{t-1} - \\mu)+ \\sigma z_t + \\phi_1 z_{t-1} $$\n\n\nNow the next thing we want to do is put things\nin forecasting form.\nSo what I'm going to do is I'm going to shift $t$ to $t+1$.\nEverywhere where I see a $t$, I'm going to write $t+1$.\nAnd that puts the future values on the left\nand the present and past values or the known\nvalues on the right hand side.\nSo for one-time step ahead, this makes exactly the split\nthat we want to have:\n\n$$ x_{t+1}  =  \\mu + c_1 (x_{t} - \\mu)+ \\sigma z_{t+1} + \\phi_1 z_{t} $$\n\n\nSo what's our forecast?\nSo our definition for our forecast\nis going to be the conditional probability.\nSo our first forecast is going to be:\n\n$$f_{t,1} = E[x_{t+1}|x_t, z_t, \\dots] $$\n\nThat is the forecast made at time t for one-time step\nahead in the future.\nAnd there are different notations for this.\nSo what you really should rely on is not the notation,\nbut reduce everything to expectations.\nSo this is the expectation of $t+1$ given everything\nup through that point, which includes $x_t$, $z_t$,\nand any previous failures, but those\ndon't show up in this equation on the right-hand side.\nSo let's compute the expectation.\nAnd what we noticed is that the only random variable\non the right hand side is $z_{t+1}$.\nThat's the only thing that's random.\nSo $x_t$ is known.\nThis $z_t$ is known.\nThere's only one random variable, i.e. $z_{t+1}$ .\nAnd we take expectations, the expectation of $z_{t+1}$\nis going to vanish.\nSo what do we get?\nWe're going to get that the forecast is equal to:\n\n$$f_{t,1} =\\mu + c_1 (x_{t} - \\mu) + \\phi_1 z_{t}  $$\n\nSo we just do the calculation.\nIt's exactly the same as the expression\nabove, except for this $\\sigma z_{t+1}$, this random term\nthat dropped out, because it has zero expectation.\nSo let's take a look at the forecast error.\nSo the first forecast error for one-time step\nahead is going to be:\n\n$$e_{t+1} = x_{t+1} - f_{t,1} $$\n\nThat is the forecast error as defined\nas the difference between what we predicted\nand what actually happened.\nWhat we'd like to do and the way in which\nwe have this definition for the forecast being optimal\nis we're going to minimize the mean squared forecast error.\nThat is going to minimize $e^2$\nin expectation of all possible things that would happen.\nNow we could use other kinds of loss functions.\nThose will depend on the settings,\ndepending on the economic values.\nSo it's just a question of doing and minimization,\nbut in this case, we have this basic result\nthat this will be our expectation,\nbut let's compute the forecast error.\nSo the idea is that what we really want, in general, if you\nwant to drive this and check, what we really want\nis we want a predictor for $f$, that some function of all\nthe previous observations, in this case, just $x_t$ and $z_t$,\nwe'd like to be a linear function.\nAnd when we find the linear function that\nminimizes the mean squared error,\nwe find that it's this conditional expectation.\nSo let's compute this quantity.\nAnd we'll see that there's a really nice structure that\nshows up.\n$x_{t+1} - f_{t,1}$, you\nnotice that most of the terms are common.\n\nAnd therefore, the mean squared forecast error\nis:\n$$E[e_{t+1}^2] = E[ x_{t+1} - f_{t,1} ] = E[(\\sigma z_{t+1})^2] =\\sigma^2$$\n\n\nNow what about looking at multiple forecasts?\nSo we'd like to go for future horizons.\nOne-step was easy.\nSo the general rule is that when we\nwant to do it two-step ahead forecast,\nwe're going to shift everything.\nWe're going to add one more.\nSo we write an expression for $x_{t+2}$.\n\nSo here's the general procedure.\nKeep doing the recursion.\nKeep substituting in back until all of the $X$'s on the right\nhand side of the equation have a time index of $t$ or earlier.\nThe $z$'s can be later.\nThat's OK, because we're going to take their expectations,\nand they're going to vanish.\nSo we might have some possibly unknown $z$'s.\nBut the basic idea is once we go beyond one-time step,\nhow do you know what to do?\nIt's easy.\nYou're doing $x_t+h$ for horizon $h$\non the left hand side.\nAnd on the right hand side, you do probably $h$ or $h-1$\nrecursive substitutions of the defining equation\nuntil we can express $x_t$ plus $h$ in terms of $x$, $x_{t-1}$\nminus 1, and so on.\nThose are all known quantities.\nThen we take conditional expectations.\nWe have our forecast.\nWe compute the forecast errors.\nWe take expectations of their squares.\nThat's easy as well, because it's just the same quantities.\nNow we have the known and the unknown ones\nclearly delineated.\nAnd we get our results for our mean squared forecast error.\nAnd there are two really important properties\nto keep in mind for our solution.\nOne of them is the forecast error has zero expectation.\nAnd the forecast error is orthogonal\nto the other variables, to the other  to the other predictor variables.\n\n\\subsection*{ARMA(2,2)}\n\nSo let's take a look for another example\nLet's take a look at an ARMA(2,2), shall we?\nSo now when you're given numbers for the forecasts\nor particular horizons, you can either plug them in right away\nor you can leave the parameters general.\nThat generally makes it easier to check your math\nand find any sign errors that might be there,\nbut either way, whether you substitute indefinite numbers\nfor the parameters before or after shouldn't\nmake any difference.\nWhen you're doing forecast, you do want to pay attention though\nto the initial conditions if you have to bootstrap your process,\nbecause if you're asked for a forecast one or three\nor seven steps ahead, you'll need enough data to get\nthe process started before you can generate the recursion.\nThe recursive techniques that we have\nthat I'm writing down here for the forecast\nare technically appropriate for the case, where we go\ninfinitely far into the past.\nEven if the series did exist an infinitely long time,\nwe wouldn't have an infinite amount of data.\nSo we do need to make sure we have the initial conditions set\nto get numerical answers, but the basic rules are compute\nconditional expectations after writing our defining\nequations with variable to be forecast on the left hand side\nand only known observations on the right hand side.\n\n\nSo let's do this for ARMA(2,2).\nit's little bit more complicated at least initially.\nSo it looks like:\n\n$$x_t = c_0+c_1 x_{t-1} + c_2 x_{t-2} + \\sigma z_t + \\phi_1 z_{t-1} + \\phi_2 z_{t-2} $$\n\nAnd you can see how it would go for a general ARMA(p,q).\nI'm going to write it in concrete form\nso we don't have summations running around.\nAnd when we shift, it gets a little messy\nkeeping track of the indices, but you can do it.\nAnd you can take a look at the literature as well for that.\nSo what's our expectation in this case?\n\n$$ \\mu = E[x_t] =  c_0+c_1 \\mu + c_2 x_{t-2} + \\mu  $$\n$$ \\mu = \\frac{c_0}{1-c_1 - c_2}    $$\n\n\nAnd you can guess how this generalizes\nfor the general ARMA(p,q) model, we\nget the generalization of this expression.\nAnd then we can write our equation\nas:\n\n$$ x_t - \\mu = c_1(x_{t-1}-\\mu) + c_2(x_{t-2}-\\mu) + \\sigma z_t + \\phi_1 z_{t-1} + \\phi_2 z_{t-2} $$\n\nLet's do some forecasting, shall we?\n\nYou should notice that each of the terms that I've\nwritten down is a way that it has 0 mean.\nThat just makes it a bit easier to see what's going on,\nto see what the dynamics are, and to do some calculations.\nYou can also, if you want to clean it up,\nyou can find a new variable $y$ to be $x_t - \\mu$ and shift things\nback.\nSo you can do any rescaling things you like.\nThe end results are going to be the same if they're just\nredefinitions of the parameters and rescalings\nof the variables.\n\nSo let's take a look for time $t+1$:\n\n$$ x_{t+1} - \\mu = c_1(x_{t}-\\mu) + c_2(x_{t-1}-\\mu) + \\sigma z_{t+1} + \\phi_1 z_{t} + \\phi_2 z_{t-1} $$\n\n\nSo that one is pretty easy.\nIt looks like the expression that we just\ndid before for the ARMA(1,1).\nThat is everything on the right hand side has an index of \nall of the $x$'s are taken at time $t$ or $t-1$.\nAnd the $z$'s are mostly in the past.\nWe have these two with coefficients\nof $\\phi$'s both in the past.\nAnd this is the only one that's still a random variable,\nbut at time 2, things change.\nSo let's look one more time step ahead.\nLet's contrast a little bit.\nSo if we write this as:\n\n$$ x_{t+2} - \\mu = c_1(x_{t+1}-\\mu) + c_2(x_{t}-\\mu) + \\sigma z_{t+2} + \\phi_1 z_{t+1} + \\phi_2 z_{t} $$\n\n\nSo all I've done is I shifted $t$ to $t+1$ again.\n\n\nSo I have two of the terms on the right hand side\ninvolve the present or the past.\nAnd that's OK.\nThose are known quantities, but I have these other expressions.\nSo I can't just directly compute the expectation\non the left hand side.\nNow I could take the previous work I did before\nand substitute that would be fine.\nBut if I want to see the general approach for doing it\nat a particular time step, what I'm going to say\nis that the expressions  $\\sigma z_{t+2}$ and $\\phi_1 z_{t+1}$ , I can leave alone,\nbecause those are both fine.\nThese just involves $z$'s.\nAnd I know their expectations, but I\ndon't want the recursive structure for $x_t+1$, because remember this is saying that the value two\ndays from now depends on the value tomorrow, which\nI haven't yet observed.\nSo the value today, the value yesterday, those are all known,\nbut rather than expressing it this way,\nI'd like to do my recursions, get it out.\nAnd then I can take clean ordinary simple expectations\nand get an answer.\nSo let's do that.\nAnd we just need to substitute one more time and put that in.\nSo which term are we going to substitute--\nwe're going to substitute in?\nWe'll have :\n\n$$ x_{t+2} = \\mu + c_1\\Big[  c_1(x_{t}-\\mu) + c_2(x_{t-1}-\\mu) + \\sigma z_{t+1} + \\phi_1 z_{t} + \\phi_2 z_{t-1} \\Big] + c_2(x_{t}-\\mu) + \\sigma z_{t+2} + \\phi_1 z_{t+1} + \\phi_2 z_{t} $$\n\n\nSo what have we got?\nSo I now have an expression for $x_{t+2}$, where on the right hand side,\neverything depends on known quantities.\nSo we put it in.\nWe turn the crank.\nWe compute the expectation two-time steps ahead.\nThat will give us our forecast today for two-time steps ahead.\nWhen tomorrow is realized, that forecast\nfor what will then be one more day ahead is going to change.\nAnd how will it change?\nIt will be updated by the new observation.\nSo if today is Monday and I'd like\nto know about Wednesday's weather,\nI would make a forecast today.\nTomorrow I'll have a new forecast for Wednesday.\nAnd that will change.\nIt will change by my knowledge of what happened on Tuesday.\nBut from a mathematical point of view,\nwe separated things into the form that we want.\nWe can first take the expectation\nwith the appropriate conditions.\nAnd second, we can compute forecast error in advance.\nAnd we can compute the mean squared forecast\ntwo steps ahead.\nAnd so that's looking ahead for what\nour expected forecast error.\nThe reason that that's important is\nthat we want to think not only about distributions.\nWhat's the exact value?\nBecause that exact value probably won't be realized.\nIt gives us characteristics of the full distribution\nof the actual outcome.\nAnd it lets us have a sense as to how we\nshould evaluate our forecasts.\nSo that's an expectation.\nOnce Wednesday is realized, then we'd like to go back.\nAnd then our Xt plus 2 will be a known quantity.\nWe can compare it with our forecast.\nAnd, of course, this will differ by some amount,\nbut if we'd like to improve our forecasting techniques,\nour forecasting methodology, and our forecasting quality,\nwhat we do is we look over time.\nWe take a large collection of forecasts and outcomes.\nAnd we study the statistics of the forecast errors.\nSo we use forecast errors both in expectation going forward\nand to assess forecast quality and look\nfor improvements going backward once we've\ncollected the relevant data.\n\t\n\\end{document}", "meta": {"hexsha": "73f666bf7defec4ae7b836f5de740c3278afc793", "size": 14996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.455x/recitation_03.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.455x/recitation_03.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.455x/recitation_03.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": 36.6650366748, "max_line_length": 186, "alphanum_fraction": 0.7444651907, "num_tokens": 4083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.641050423726081}}
{"text": "\\chapter{Combinatorial}\n\n\\section{Permutations}\n\t\\subsection{Factorial}\n\t\t\\import{factorial.tex}\n\t\t\\kactlimport{IntPerm.h}\n\n\t\\subsection{Cycles}\n\t\tLet $g_S(n)$ be the number of $n$-permutations whose cycle lengths all belong to the set $S$. Then\n\t\t$$\\sum_{n=0} ^\\infty g_S(n) \\frac{x^n}{n!} = \\exp\\left(\\sum_{n\\in S} \\frac{x^n} {n} \\right)$$\n\n\t\\subsection{Derangements}\n\t\tPermutations of a set such that none of the elements appear in their original position.\n\t\t\\[ \\mkern-2mu D(n) = (n-1)(D(n-1)+D(n-2)) = n D(n-1)+(-1)^n = \\left\\lfloor\\frac{n!}{e}\\right\\rceil \\]\n\n\t\\subsection{Burnside's lemma}\n\t\tGiven a group $G$ of symmetries and a set $X$, the number of elements of $X$ \\emph{up to symmetry} equals\n\t\t \\[ {\\frac {1}{|G|}}\\sum _{{g\\in G}}|X^{g}|, \\]\n\t\t where $X^{g}$ are the elements fixed by $g$ ($g.x = x$).\n\n\t\t If $f(n)$ counts ``configurations'' (of some sort) of length $n$, we can ignore rotational symmetry using $G = \\mathbb Z_n$ to get\n\t\t \\[ g(n) = \\frac 1 n \\sum_{k=0}^{n-1}{f(\\text{gcd}(n, k))} = \\frac 1 n \\sum_{k|n}{f(k)\\phi(n/k)}. \\]\n\n\\section{Partitions and subsets}\n\t\\subsection{Partition function}\n\t\tNumber of ways of writing $n$ as a sum of positive integers, disregarding the order of the summands.\n\t\t\\[ p(0) = 1,\\ p(n) = \\sum_{k \\in \\mathbb Z \\setminus \\{0\\}}{(-1)^{k+1} p(n - k(3k-1) / 2)} \\]\n\t\t\\[ p(n) \\sim 0.145 / n \\cdot \\exp(2.56 \\sqrt{n}) \\]\n\n\t\t\\begin{center}\n\t\t\\begin{tabular}{c|c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c}\n\t\t\t$n$    & 0 & 1 & 2 & 3 & 4 & 5 & 6  & 7  & 8  & 9  & 20  & 50  & 100 \\\\ \\hline\n\t\t\t$p(n)$ & 1 & 1 & 2 & 3 & 5 & 7 & 11 & 15 & 22 & 30 & 627 & $\\mathtt{\\sim}$2e5 & $\\mathtt{\\sim}$2e8 \\\\\n\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\\subsection{Lucas' Theorem}\n\t\tLet $n,m$ be non-negative integers and $p$ a prime. Write $n=n_kp^k+...+n_1p+n_0$ and $m=m_kp^k+...+m_1p+m_0$. Then $\\binom{n}{m} \\equiv \\prod_{i=0}^k\\binom{n_i}{m_i} \\pmod{p}$.\n\n\t\\subsection{Binomials}\n\t\t\\kactlimport{multinomial.h}\n\n\\section{General purpose numbers}\n\t\\subsection{Bernoulli numbers}\n\t\tEGF of Bernoulli numbers is $B(t)=\\frac{t}{e^t-1}$ (FFT-able).\n\t\t$B[0,\\ldots] = [1, -\\frac{1}{2}, \\frac{1}{6}, 0, -\\frac{1}{30}, 0, \\frac{1}{42}, \\ldots]$\n\n\t\tSums of powers:\n\t\t\\small\n\t\t\\[ \\sum_{i=1}^n n^m = \\frac{1}{m+1} \\sum_{k=0}^m \\binom{m+1}{k} B_k \\cdot (n+1)^{m+1-k} \\]\n\t\t\\normalsize\n\n\t\tEuler-Maclaurin formula for infinite sums:\n\t\t\\small\n\t\t\\[ \\sum_{i=m}^{\\infty} f(i) = \\int_m^\\infty f(x) dx - \\sum_{k=1}^\\infty \\frac{B_k}{k!}f^{(k-1)}(m) \\]\n\t\t\\[ \\approx \\int_{m}^\\infty f(x)dx + \\frac{f(m)}{2} - \\frac{f'(m)}{12} + \\frac{f'''(m)}{720} + O(f^{(5)}(m)) \\]\n\t\t\\normalsize\n\n\t\\subsection{Stirling numbers of the first kind}\n\t\tNumber of permutations on $n$ items with $k$ cycles.\n\t\t\\begin{align*}\n\t\t\t&c(n,k) = c(n-1,k-1) + (n-1) c(n-1,k),\\ c(0,0) = 1 \\\\\n\t\t\t&\\textstyle \\sum_{k=0}^n c(n,k)x^k = x(x+1) \\dots (x+n-1)\n\t\t\\end{align*}\n\t\t$c(8,k) = 8, 0, 5040, 13068, 13132, 6769, 1960, 322, 28, 1$ \\\\\n\t\t$c(n,2) = 0, 0, 1, 3, 11, 50, 274, 1764, 13068, 109584, \\dots$\n\n\t\\subsection{Eulerian numbers}\n\t\tNumber of permutations $\\pi \\in S_n$ in which exactly $k$ elements are greater than the previous element. $k$ $j$:s s.t. $\\pi(j)>\\pi(j+1)$, $k+1$ $j$:s s.t. $\\pi(j)\\geq j$, $k$ $j$:s s.t. $\\pi(j)>j$.\n\t\t$$E(n,k) = (n-k)E(n-1,k-1) + (k+1)E(n-1,k)$$\n\t\t$$E(n,0) = E(n,n-1) = 1$$\n\t\t$$E(n,k) = \\sum_{j=0}^k(-1)^j\\binom{n+1}{j}(k+1-j)^n$$\n\n\t\\subsection{Stirling numbers of the second kind}\n\t\tPartitions of $n$ distinct elements into exactly $k$ groups.\n\t\t$$S(n,k) = S(n-1,k-1) + k S(n-1,k)$$\n\t\t$$S(n,1) = S(n,n) = 1$$\n\t\t$$S(n,k) = \\frac{1}{k!}\\sum_{j=0}^k (-1)^{k-j}\\binom{k}{j}j^n$$\n\n\t\\subsection{Bell numbers}\n\t\tTotal number of partitions of $n$ distinct elements. $B(n) =$\n\t\t$1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, \\dots$. For $p$ prime,\n\t\t\\[ B(p^m+n)\\equiv mB(n)+B(n+1) \\pmod{p} \\]\n\n\t\\subsection{Labeled unrooted trees}\n\t\t\\# on $n$ vertices: $n^{n-2}$ \\\\\n\t\t\\# on $k$ existing trees of size $n_i$: $n_1n_2\\cdots n_k n^{k-2}$ \\\\\n\t\t\\# with degrees $d_i$: $(n-2)! / ((d_1-1)! \\cdots (d_n-1)!)$\n\n\t\\subsection{Catalan numbers}\n\t\t\\[ C_n=\\frac{1}{n+1}\\binom{2n}{n}= \\binom{2n}{n}-\\binom{2n}{n+1} = \\frac{(2n)!}{(n+1)!n!} \\]\n\t\t\\[ C_0=1,\\ C_{n+1} = \\frac{2(2n+1)}{n+2}C_n,\\ C_{n+1}=\\sum C_iC_{n-i} \\]\n\t\t${C_n = 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, \\dots}$\n\t\t\\begin{itemize}[noitemsep]\n\t\t\t\\item sub-diagonal monotone paths in an $n\\times n$ grid.\n\t\t\t\\item strings with $n$ pairs of parenthesis, correctly nested.\n\t\t\t\\item binary trees with with $n+1$ leaves (0 or 2 children).\n\t\t\t\\item ordered trees with $n+1$ vertices.\n\t\t\t\\item ways a convex polygon with $n+2$ sides can be cut into triangles by connecting vertices with straight lines.\n\t\t\t\\item permutations of $[n]$ with no 3-term increasing subseq.\n\t\t\\end{itemize}\n", "meta": {"hexsha": "686a1194d9f96f8b047769dafbd6c362ddecfe7f", "size": 4761, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/combinatorial/chapter.tex", "max_stars_repo_name": "sarafanshul/KACTL", "max_stars_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2021-01-25T12:07:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T17:20:31.000Z", "max_issues_repo_path": "content/combinatorial/chapter.tex", "max_issues_repo_name": "sarafanshul/KACTL", "max_issues_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_issues_repo_licenses": ["MIT"], "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/combinatorial/chapter.tex", "max_forks_repo_name": "sarafanshul/KACTL", "max_forks_repo_head_hexsha": "fa14ed34e93cd32d8625ed3729ba2eee55838340", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-28T11:13:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:56:20.000Z", "avg_line_length": 46.6764705882, "max_line_length": 201, "alphanum_fraction": 0.5782398656, "num_tokens": 2185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566559, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6410504085850299}}
{"text": "%% theorem/proof/lemma/corollary/example blocks\n\\section{Prime Numbers}\n\\subsection{Definition}\n\\begin{frame}{What Are Prime Numbers?}\n  \\begin{definition}\n    A \\alert{prime number} is a number that has exactly two divisors.\n  \\end{definition}\n  \\begin{example}\n    \\begin{itemize}\n      \\item 2 is prime (two divisors: 1 and 2).\n      \\item 3 is prime (two divisors: 1 and 3).\n      \\item 4 is not prime (\\alert{three} divisors: 1, 2, and 4).\n    \\end{itemize}\n  \\end{example}\n\\end{frame}\n\n\\lipsum[1]\n\n", "meta": {"hexsha": "b407407db8fead1f69dff91f3d6b8530129841a4", "size": 504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "beamer-lecture-notes/example1.tex", "max_stars_repo_name": "edgemaster/latex-experiments", "max_stars_repo_head_hexsha": "4b3b3d0f64fad84e23242780c2a0778d1927a7d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "beamer-lecture-notes/example1.tex", "max_issues_repo_name": "edgemaster/latex-experiments", "max_issues_repo_head_hexsha": "4b3b3d0f64fad84e23242780c2a0778d1927a7d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-02-17T15:45:36.000Z", "max_issues_repo_issues_event_max_datetime": "2015-02-17T15:46:39.000Z", "max_forks_repo_path": "beamer-lecture-notes/example1.tex", "max_forks_repo_name": "edgemaster/beamer-lecture-notes", "max_forks_repo_head_hexsha": "4b3b3d0f64fad84e23242780c2a0778d1927a7d8", "max_forks_repo_licenses": ["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.5263157895, "max_line_length": 69, "alphanum_fraction": 0.6746031746, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.64100778269002}}
{"text": "\\documentclass[main]{subfiles}\n\\begin{document}\n\\section{Poisson Regression}\n\\label{sec:poisson_regression}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{}\n\nTransform the poisson distribution function\n\\begin{align*}\n\tp(y;\\lambda)\n\t\t&=\n\t\t\te^{-\\lambda}\n\t\t\t\\frac {(\\lambda)^y} {y!} \t\t\t\\\\\n\t\t&=\n\t\t\t\\frac {1} {y!}\n\t\t\t\\exp (\n\t\t\t\ty \\log \\lambda - \\lambda\n\t\t\t)\n\\end{align*}\n\nCompare it to the general equation that defines the exponential family\n\\begin{center}\n\\begin{math}\n\tp(y;\\lambda) =\n\t\tb(y) \\exp ( \\eta \\, y - a(\\eta) )\n\\end{math}\n\\end{center}\n\nWe get\n\\begin{align*}\n\ta(\\eta) \t&=\n\t\t\t\\lambda = e^{\\eta} \t\t\t\t\t\\\\\n\tb(y)\t\t&=\n\t\t\t\\frac {1} {y!}\t\t\t\t\t\t\\\\\n\t\\eta \t\t&=\n\t\t\t\\log \\lambda\t\t\t\t\t\t\\\\\n\tT(y)\t\t&=\n\t\t\ty\n\\end{align*}\n\n\\subsection{}\n\nThe mean value of a random variable that abides by the Poisson distribution is\n$\\lambda$. Thus the \\textbf{canonical response function} is\n\\begin{center}\n\\begin{math}\n\tg(\\eta) = E[y;\\lambda] = \\lambda = e^{\\eta}\n\\end{math}\n\\end{center}\n\n\\subsection{}\nskipped\n\n\\subsection{}\nGiven $T(y) = y$, the general equation of exponential distributions is\nsimplified to\n\\begin{align*}\n\tp(y|\\eta) =\n\t\tb(y) \\exp ( \\eta \\, y - a(\\eta) )\n\\end{align*}\n\nWith the course assumption $\\eta = \\v{\\theta}\\cdot\\v{x}$, the log-likelihood\nfunction can be written as\n\\begin{align*}\n\tl(\\theta)\n\t\t&=\n\t\t\t\\log p(y^{(i)}|x^{(i)};\\theta) \t\t\\\\\n\t\t&=\n\t\t\t\\log b(y) +\n\t\t\t(\\v{\\theta}\\cdot\\v{x}^{(i)}) y - a(\\v{\\theta}\\cdot\\v{x}^{(i)})\n\\end{align*}\n\nGiven a data point $(x^{(i)}, y^{(i)})$, the gradient of the log-likelihood with\nrespect to $\\theta$ is\n\\begin{align*}\n\t\\pd{l(\\theta)}{\\theta_j}\n\t\t=\n\t\t\tx^{(i)}_j (\n\t\t\t\ty - a^{\\p}(\\eta)\n\t\t\t)\n\\end{align*}\n\nBy observation, it concludes this proof if\n\\begin{align*}\n\ta^{\\p}(\\eta) = g(\\eta)\n\\end{align*}\n\nIt can be proved. First let's define a function of $\\eta$\n\\begin{align*}\n\tI(\\eta)\n\t\t&=\n\t\t\t\\int\n\t\t\tp(y;\\eta)\n\t\t\tdy \t\t\t\t\t\t\t\t\t\\\\\n\t\t&=\n\t\t\t\\int\n\t\t\tb(y) \\exp ( \\eta \\, y - a(\\eta) )\n\t\t\tdy\n\\end{align*}\n\n$I(\\eta)$ is just the sum of the probabilities of all possible states, which\nmust be one, i.e.\n\\begin{center}\n\\begin{math}\n\tI(\\eta) = 1\n\\end{math}\n\\end{center}\n\nTake the derivative with respect to $\\eta$\n\\begin{align*}\n\tI^{\\p}(\\eta)\n\t\t&=\n\t\t\t\\int\n\t\t\t\\pd {} {\\eta}\n\t\t\tb(y) \\exp ( \\eta \\, y - a(\\eta) )\n\t\t\tdy \t\t\t\t\t\t\t\t\t\\\\\n\t\t&=\n\t\t\t\\int\n\t\t\ty \\, b(y) \\exp ( \\eta \\, y - a(\\eta) )\n\t\t\tdy \t\t\t\t\t\t\t\t\t\\\\\n\t\t&-\n\t\t\ta^{\\p}(\\eta)\n\t\t\t\\int\n\t\t\tb(y) \\exp ( \\eta \\, y - a(\\eta) )\n\t\t\tdy \t\t\t\t\t\t\t\t\t\\\\\n\t\t&=\n\t\t\tE[y]\n\t\t\t- a^{\\p}(\\eta) I(\\eta)\t\t\t\t\\\\\n\t\t&=\n\t\t\tg(\\eta)\n\t\t\t- a^{\\p}(\\eta) \t\t\t\t\t\t\\\\\n\t\t&=\n\t\t\t0\n\\end{align*}\n\nThe last step used the fact that the derivative of a constant number is zero.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\end{document}\n", "meta": {"hexsha": "c7c8b128ed55485fe745c00a059c8d8e7b9e3db3", "size": 2739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignments/1/prob2.tex", "max_stars_repo_name": "qzmfranklin/cs299", "max_stars_repo_head_hexsha": "95dff2eaa41c80559b38870b18683fee678e0544", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-03-20T00:40:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-20T00:40:43.000Z", "max_issues_repo_path": "assignments/1/prob2.tex", "max_issues_repo_name": "qzmfranklin/cs299", "max_issues_repo_head_hexsha": "95dff2eaa41c80559b38870b18683fee678e0544", "max_issues_repo_licenses": ["MIT"], "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/1/prob2.tex", "max_forks_repo_name": "qzmfranklin/cs299", "max_forks_repo_head_hexsha": "95dff2eaa41c80559b38870b18683fee678e0544", "max_forks_repo_licenses": ["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.2887323944, "max_line_length": 80, "alphanum_fraction": 0.5213581599, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6410077788816405}}
{"text": "\\documentclass[english]{../thermomemo/thermomemo}\n% NOTE: You must pass either norsk or english as an option!\n\\usepackage[utf8]{inputenc}\n\n\\title{Introduction to thermodynamics}\n\\author{Morten Hammer, Geir Skaugen and Eskil Aursand}\n\n\\usepackage[normalem]{ulem}\n\n\\usepackage{hyperref}\n\\usepackage{color}\n\\usepackage{amsfonts}\n\n\\definecolor{midnightblue}{RGB}{35,35,132}\n\\definecolor{urlblue}{RGB}{70,130,180}\n\n\\definecolor{shadecolor}{gray}{0.9}\n\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=midnightblue,\n    urlcolor=urlblue,\n    citecolor=midnightblue,\n    linktoc=page\n}\n\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\\usepackage{framed}\n\\usepackage{siunitx,mhchem,todonotes}\n\\newcommand{\\pone}[3]{\\frac{\\partial #1}{\\partial #2}\\bigg|_{#3}}% partial\n                                % derivative with information of\n                                % constant variables\n\\newcommand*{\\vektor}[1]{\\boldsymbol{#1}}%\n\\newcommand{\\dd}[1]{\\mathrm{d}{#1}}\n\n\\DeclareMathOperator*{\\argmin}{arg\\,min }\n\n\n\n\\usepackage[activate={true,nocompatibility},final,kerning=true,tracking=true,spacing=true,stretch=10,shrink=10]{microtype}\n\\microtypecontext{spacing=nonfrench}\n\\SetExtraKerning[unit=space]\n    {encoding={*}, family={bch}, series={*}, size={footnotesize,small,normalsize}}\n    {\\textendash={400,400}, % en-dash, add more space around it\n     \"28={ ,150}, % left bracket, add space from right\n     \"29={150, }, % right bracket, add space from left\n     \\textquotedblleft={ ,150}, % left quotation mark, space from right\n     \\textquotedblright={150, }} % right quotation mark, space from left\n\\SetTracking{encoding={*}, shape=sc}{0}\n\n\\begin{document}\n\\frontmatter\n\n\\tableofcontents\n\n\\section{Introduction}\nThis document is ment as an introduction to thermodynamics for users\nand programmers in thermopack.\n\nIn addition to this memo, there exsist two memos written to document\nthermopack. These can be generated running pdflatex in the thermopack\ndocumentation folder ./doc/memo/.\n\nOtherwise the thermodynamics book by Callen \\cite{callen85} and by\nMichelsen \\cite{michelsen07} is recommended. Much of the work done on\nflash algorithms are based on the work by Michelsen\n\\cite{michelsen82a,michelsen82b,michelsen99}.\n\n\\section{Thermodynamic potentials}\n\\subsection{Internal energy}\nAs a starting point, one assumes a fundamental equation for the internal energy ($U$), with the extensive variables entropy ($S$), volume ($V$) \nand molar numbers ($\\vektor{n})$ as independent variables:\n\\begin{equation}\n  U = U(S,V,\\vektor{n})\n  \\label{}\n\\end{equation}\nUnder the assumption that $U$ is a \\textit{first order homogeneous function} of the extensive variables, one may use \n\\textit{Euler's theroem of homogeneous functions} to show that:\n\\begin{align}\n  U(S,V,\\vektor{n}) &= S \\pone{U}{S}{V,\\vektor{n}}\n  +V \\pone{U}{V}{S,\\vektor{n}}\n  +\\sum_i n_i \\pone{U}{n_i}{S,V,n_j} \\nonumber \\\\\n  &= ST - VP + \\sum_i n_i \\mu_i\n  \\label{eq:U_euler}\n\\end{align}\nusing the definitions \n\\begin{equation}\n  T \\equiv \\pone{U}{S}{V,\\vektor{n}}, \\quad P \\equiv \\pone{U}{V}{S,\\vektor{n}}, \\quad \\mu_i \\equiv \\pone{U}{n_i}{S,V,n_j}.\n  \\label{}\n\\end{equation}\nThe differential of $U$ given its homogeneous property \\eqref{eq:U_euler} is \n\\begin{equation}\n  \\dd{U} = S\\dd{T} + T\\dd{S} - V\\dd{P} - P\\dd{V} + \\sum_i n_i \\dd{\\mu_i} + \\sum_i \\mu_i \\dd{n_i},\n  \\label{}\n\\end{equation}\nwhile generally the total (exact) differential of \\eqref{eq:U_euler}, given its independent variables, is\n\\begin{equation}\n  \\dd{U} = T\\dd{S} - P\\dd{V} + \\sum_i \\mu_i \\dd{n_i},\n  \\label{eq:U_totaldiff}\n\\end{equation}\nwhich combine into the \\textit{Gibbs-Duhem} relation for the intensive properties:\n\\begin{equation}\n  S\\dd{T} - V\\dd{P} + \\sum_i n_i \\dd{\\mu_i} = 0.\n  \\label{eq:gibbsduhem}\n\\end{equation}\n\n\\subsection{Helmholtz energy}\nThe Helmholtz energy is defined as\n\\begin{equation}\n  A(T,V,\\vektor{n}) \\equiv U - TS,\n  \\label{eq:helmholtz_def}\n\\end{equation}\nand by using \\eqref{eq:U_totaldiff}, one may show that\n\\begin{align}\n  \\dd{A} = -S\\dd{T} - P\\dd{V} + \\sum_i \\mu_i \\dd{n_i},\n  \\label{}\n\\end{align}\nand one may then see that\n\\begin{equation}\n  S = -\\pone{A}{T}{V,\\vektor{n}}, \\quad P = -\\pone{A}{V}{T,\\vektor{n}}, \\quad \\mu_i = \\pone{A}{n_i}{T,V,n_j}.\n  \\label{eq:A_differentials}\n\\end{equation}\n\n\n\\subsection{Gibbs energy}\nThe Gibbs energy is defined as \n\\begin{equation}\n  G(T,P,\\vektor{n}) \\equiv U + PV - TS,\n  \\label{eq:gibbs_def}\n\\end{equation}\nand by using \\eqref{eq:U_totaldiff}, one may show that\n\\begin{align}\n  \\dd{G} = -S\\dd{T} + V\\dd{P} + \\sum_i \\mu_i \\dd{n_i}.\n  \\label{eq:dG}\n\\end{align}\nand one may then see that\n\\begin{equation}\n  S = -\\pone{G}{T}{P,\\vektor{n}}, \\quad V = \\pone{G}{P}{T,\\vektor{n}}, \\quad \\mu_i = \\pone{G}{n_i}{T,P,n_j}.\n  \\label{}\n\\end{equation}\n\nCombining \\eqref{eq:gibbsduhem} with \\eqref{eq:dG} leads to  \n\\begin{align}\n  \\dd{G} = \\sum_i \\mu_i \\dd{n_i} + \\sum_i n_i \\dd{\\mu_i},\n  \\label{}\n\\end{align}\nwhich can be recognized as a total differential for the alternative expression for G:\n\\begin{equation}\n  G = \\sum_i \\mu_i n_i.\n  \\label{eq:G_alt}\n\\end{equation}\n\n\n\\subsection{Enthalpy}\nThe Enthalpy is defined as \n\\begin{equation}\n  H(S,P,\\vektor{n}) \\equiv U + PV,\n  \\label{}\n\\end{equation}\nand by using \\eqref{eq:U_totaldiff}, one may show that\n\\begin{align}\n  \\dd{H} = T\\dd{S} + V\\dd{P} + \\sum_i \\mu_i \\dd{n_i}.\n  \\label{eq:dH}\n\\end{align}\nand one may then see that\n\\begin{equation}\n  T = \\pone{H}{S}{P,\\vektor{n}}, \\quad V = \\pone{H}{P}{S,\\vektor{n}}, \\quad \\mu_i = \\pone{H}{n_i}{S,P,n_j}.\n  \\label{}\n\\end{equation}\n\n\\section{Equilibrium in multi-phase systems with given (T,P)}\n\\subsection{Systems with given (T,P)}\n\\label{sec:eq_givenTP}\nTo characterize the equilibrium state, let us image that a small perturbation from equilibrium happens, and then focus on \nthe spontaneous process ($\\delta$) leading back to the equilibrium state. \nFor an isolated system, the second law of thermodynamics states that all spontaneous changes towards the equilibrium \nstate involve an increase in entropy:\n\\begin{equation}\n  \\delta S_\\text{tot} \\geq 0\n  \\label{eq:secondlaw}\n\\end{equation}\nwhere $\\delta$ indicates that it is not a change between different equilibrium states, as $\\mathrm{d}$ is used to indicate. \nWe are however not interested in an isolated system, but rather a system with given temperature and pressure. This may be though of as a sub-system of a total \nsystem, the latter satisfying \\eqref{eq:secondlaw}. The other part of the total system is the \\textit{reservoir}, which holds the given temperature and \npressure, and is large enough to force our system to keep the same values. Energy and volume (but not particles) \nmay be freely exchanged between the system (no subscript) and \nthe reservour (subscript r), in order to find the equilibrium of the total system. As entropy is an extensive quantity, the total entropy (which must increase) is \na sum of the entropy of the system and en entropy of the reservoir:\n\\begin{align}\n  \\delta S  + \\delta S_\\text{r} = \\delta S_\\text{tot} \\geq 0.\n  \\label{eq:secondlaw_composite}\n\\end{align}\nDefining $\\delta Q$ as the heat transferred into the system, the change of entropy in the reservoir is given by\n\\begin{align}\n  \\delta S_\\text{r} = - \\frac{\\delta Q}{T} = - \\left( \\frac{1}{T}\\delta U + \\frac{P}{T} \\delta V \\right),\n  \\label{}\n\\end{align}\nby using the first and second laws of thermodynamics. The implication of \\eqref{eq:secondlaw_composite} is then that\n\\begin{align}\n  T \\delta S \\geq \\delta U +  P \\delta V.\n  \\label{eq:TdS}\n\\end{align}\nThe change in Gibbs energy at constant temperature and pressure is \n\\begin{align}\n  \\delta G &= \\delta \\left( U + PV - TS \\right) \\nonumber\\\\ \n  &= \\delta U + P \\delta V + V \\delta P - T \\delta S - S \\delta T \\nonumber\\\\\n  &= \\delta U + P \\delta V - T \\delta S,\n  \\label{}\n\\end{align}\nwhich combined with \\eqref{eq:TdS} shows that\n\\begin{equation}\n  \\delta G \\leq 0.\n  \\label{}\n\\end{equation}\nIn words, this shows that a process which increases the entropy of the total system must decrease the Gibbs energy of a sub-system, given that the rest of the \ntotal system behaves like a $T,P$ reservoir. Given that this process characterizes returns from perturbations around the equilibrium state, the \nconclusion must be:\n\\begin{framed}\n  \\noindent\n  For a closed system of given temperature and pressure, the equilibrium condition is that its Gibbs energy ($G$) is at a minimum. \n\\end{framed}\n\n\\subsection{Multi-phase systems}\n\\label{sec:eq_multiphase}\nSo far the internal workings of the system have been ignored. Now we want to take into account that the system may consist of multiple phases, \nwhich essentially are sub-systems which are free to exchange energy, volume and particles.\nAs shown in Sec.~\\ref{sec:eq_givenTP}, the condition for equilibrium is that the Gibbs energy for the entire system is at an extremum with respect to perturbation. \nLet us assume that the perturbation is sufficiently small that the chemical potentials to not change, \\textit{i.e.} $\\delta \\mu_i \\approx 0$. This may also be seen as \nassuming that the perturbation is so small that $\\delta G \\approx \\dd{G}$, where the latter is given by \\eqref{eq:dG}.\nFor constant $T$ and $P$ this means that \n\\begin{align}\n  \\delta G = \\sum_j \\delta G_j = \\sum_j \\sum_i \\mu_i^{(j)} \\delta n_i^{(j)} = 0,\n  \\label{eq:dG_multiphase}\n\\end{align}\nwhere $j$ indicates the phase, and $i$ indicates the component. The conservation of matter, given no chemical reactions, \ngives that any change in the mole number of a component in an arbitrary phase $\\alpha$, must come from a net opposite change in the same \ncomponent in the other phases:\n\\begin{equation}\n  \\delta n_i^{(\\alpha)}  = - \\sum_{j\\neq \\alpha} \\delta n_i^{(j)}.\n  \\label{eq:matter_cons}\n\\end{equation}\nCombining \\eqref{eq:dG_multiphase} and \\eqref{eq:matter_cons} leads to \n\\begin{equation}\n  \\sum_{j\\neq \\alpha} \\sum_i \\left( \\mu_i^{(j)} - \\mu_i^{(\\alpha)} \\right) \\delta n_i^{(j)} = 0.\n  \\label{}\n\\end{equation}\nGiven that the above must be true for any variation of the independent mole numbers, this means that \n\\begin{equation}\n  \\mu_i^{(\\alpha)} = \\mu_i^{(j)} \\quad \\forall \\quad  i,j\n  \\label{}\n\\end{equation}\nwhich in words is stated as:\n\\begin{framed}\n  \\noindent\n  For a multi-phase system of given temperature and pressure, the equilibrium condition is that for each component, the chemical potential \n  is equal in all phases.\n\\end{framed}\n\nAdditionally, there is a stability criterion for each phase, stated as:\n\\begin{framed}\n  \\noindent\n  For a multi-phase system of given temperature and pressure, the condition for phase stability is that the change in total Gibbs energy associated with \n  the formation of a new infinitesimal phase within an existing phase is non-negative, for \\textit{any} composition of the new phase. \n  This is called the \\textit{tangent plane condition}.\n\\end{framed}\nThe change in Gibbs energy with the formation of a new phase of $\\delta n$ moles and composition $w_i$, from an existing phase of composition $z_i$, is\n\\begin{align}\n  \\delta G \n  &= \\sum_i \\mu_i(\\vektor{z})\\left( - w_i \\delta n \\right) + \\sum_i \\mu_i(\\vektor{w})\\left( + w_i \\delta n \\right) \\nonumber\\\\\n  &= \\delta n \\sum_i w_i \\left( \\mu_i(\\vektor{w}) - \\mu_i(\\vektor{z}) \\right), \n  \\label{}\n\\end{align}\nwhich must be non-negative for any composition $\\vektor{w}$, for the existing phase composition $\\vektor{z}$:\n\\begin{align}\n  \\sum_i w_i \\left( \\mu_i(\\vektor{w}) - \\mu_i(\\vektor{z}) \\right) \\geq 0.\n  \\label{eq:tangentplane}\n\\end{align}\nWhen checking the stability of equilibrium phases, the chemical potential of each component is equal between the phases, and thus the left hand side of \n\\eqref{eq:tangentplane} is identical for each phase.\n\n\n\n\\section{Equilibrium in terms of an equation of state}\n\\subsection{The equation of state}\nAn \\textit{equation of state} is often given as an explicit pressure equation, such as \n\\begin{equation}\n  P = P (T,V,\\vektor{n}).\n  \\label{}\n\\end{equation}\nHowever, many equations of state is expressed as a Helmholtz energy\nfunction, \n\\begin{equation}\n  A = A(T,V,\\vektor{n}).\n  \\label{}\n\\end{equation}\nwhich is useful because all thermodynamical properties\nmay be derived by differentiating it.\n\nThe Helmholtz function of new multi--parameter GERG equations of state\n\\cite{kunz07,span96} and the older cubic equations of state is represented as a sum of \nan ideal contribution, and a departure (residual) contribution:\n\\begin{equation}\n\\label{eq:helmholtz}\nA(T,V,\\vektor{n}) = A^{\\text{ig}}(T,V,\\vektor{n}) + A^{\\text{r}}(T,V,\\vektor{n})\n\\end{equation}\n\nOften a reduced (dimensionless) form of the residual Helmholtz energy is used,\n\\begin{equation}\n\\label{eq:reduced_helmholtz}\nF(T,V,\\vektor{n}) = a \\equiv  \\frac{A^\\text{r}(T,V,\\vektor{n})}{nRT}\n\\end{equation}\n\n\\subsection{The residual Helmholtz energy}\n\nThe relationship between pressure and the Helmholtz energy two forms is:\n\\begin{equation}\n  P(T,V,\\vektor{n}) = -\\pone{A}{V}{T,\\vektor{n}} \n  = \\frac{nRT}{V} - \\pone{A^{\\text{r}}(T,V,\\vektor{n})}{V}{T,\\vektor{n}}.\n  \\label{}\n\\end{equation}\nAn expression for $A^\\text{r}$ may be found by integrating to the limit of infinite volume at constant temperature and mole numbers:\n\\begin{equation}\n  A^\\text{r}(T,V,\\vektor{n}) \n  = A^\\text{r}(T,\\infty,\\vektor{n}) + \\int_\\infty^V \\left[ P^\\text{ig}(T,V^\\prime,\\vektor{n}) - P(T,V^\\prime,\\vektor{n}) \\right]\\dd{V^\\prime},\n  \\label{}\n\\end{equation}\nwhich when using that real fluids behave as an ideal gas in the limit of zero pressure ($V \\to \\infty$) leads to the expression:\n\\begin{framed}\n\\begin{align}\n  A^\\text{r}(T,V,\\vektor{n}) \n  = \\int^\\infty_V \\left[ P(T,V^\\prime,\\vektor{n}) - \\frac{nRT}{V^\\prime} \\right]\\dd{V^\\prime}\n  \\label{eq:helmholtz_int}\n\\end{align}\n\\end{framed}\n\nBe aware that residual quantities will depend on which set of variables they are represented with. As an example, let's show \nhow this works out for the residual Helmholtz energy:\nFrom the state $(T,V,P,\\vektor{n})$ by definition being a real state, we know that \n\\begin{equation}\n  A(T,V,\\vektor{n}) = A(T,P,\\vektor{n}).\n  \\label{eq:Aequal}\n\\end{equation}\nWhile the value of $A$ is independent of representation, the distribution of it between the ideal \ncontribution and the residual is not. This is so because  \nthe state $(T,V,P,\\vektor{n})$ is not in \ngeneral a valid state of an ideal gas, so \ngenerally we have that\n\\begin{equation}\n  A^\\text{ig}(T,V,\\vektor{n}) \\neq A^\\text{ig}(T,P,\\vektor{n}).\n  \\label{}\n\\end{equation}\n\nUsing an arbitrary valid ideal gas state at temperature $T$, $(T,V_0,P_0,\\vektor{n})$, we \nhave by definition of this state that \n\\begin{equation}\n  A^\\text{ig}(T,P_0,\\vektor{n}) = A^\\text{ig}(T,V_0,\\vektor{n})\n  \\label{eq:Aequal_ideal}\n\\end{equation}\n\nCombining \\eqref{eq:helmholtz}, \\eqref{eq:Aequal}, \\eqref{eq:Aequal_ideal} and the ideal gas law  \nleads to the following calculation \nfor the difference in residuals between variable representations:\n\\begin{align}\n  A^\\text{r}(T,V,\\vektor{n}) - A^\\text{r}(T,P,\\vektor{n}) \n  &= A^\\text{ig}(T,P,\\vektor{n}) - A^\\text{ig}(T,V,\\vektor{n})\n  \\nonumber \\\\\n  &=\\left[A^\\text{ig}(T,P,\\vektor{n}) - A^\\text{ig}(T,P_0,\\vektor{n})\\right]\n  -\n  \\left[A^\\text{ig}(T,V,\\vektor{n}) - A^\\text{ig}(T,V_0,\\vektor{n})\\right]\n  \\nonumber\\\\\n  &=\\int_{P_0}^P \n  \\pone{A^\\text{ig}}{P}{T,\\vektor{n}}\n  \\dd{P}\n  -\n  \\int_{V_0}^V \n  \\pone{A^\\text{ig}}{V}{T,\\vektor{n}}\n  \\dd{V}\n  \\nonumber\\\\\n  &= nRT \\ln\\left( \\frac{PV}{P_0 V_0} \\right) \n  = nRT \\ln\\left( \\frac{PV}{nRT} \\right) \n  = nRT \\ln\\left( Z \\right),\n  \\label{}\n\\end{align}\nwhere $Z$ is the compressibility factor, defined by\n\\begin{equation}\n  Z \\equiv \\frac{PV}{nRT} = 1 - \\frac{V}{nRT} \\pone{A^\\text{r}(T,V,\\vektor{n})}{V}{T,\\vektor{n}} .\n  \\label{eq:Z_def}\n\\end{equation}\n\nThus we have the following expression for the residual Helmholtz free energy expressed through the \nvariables $(T,P,\\vektor{n})$:\n\\begin{equation}\n\\label{eq:helmholtz_int_TPN}\nA^{\\text{r}}(T,P,\\vektor{n})  = \\int_V^\\infty \\left(P(T,V^\\prime,\\vektor{n}) - \\frac{nRT}{V^\\prime}\\right) \\dd{V^\\prime} \n-nRT \\ln\\left( Z \\right)\n\\end{equation}\n\n\n\n\n\\subsection{Fugacity}\nFor a pure ideal gas, the change in chemical potential corresponding to a change in pressure, at constant temperature, is give by \n\\begin{equation}\n  \\frac{P}{P_0} = \\exp\\left( \\frac{\\mu^\\text{ig}(T,P) - \\mu^\\text{ig}(T,P_0) }{RT} \\right).\n  \\label{}\n\\end{equation}\nReal fluids do not obey this relation, but one may define an ``effective pressure'' called \n\\textit{fugacity} ($f$) such that the following relation holds:\n\\begin{equation}\n  \\frac{f(T,P)}{P_0} = \\exp\\left( \\frac{\\mu(T,P) - \\mu^\\text{ig}(T,P_0) }{RT} \\right).\n  \\label{}\n\\end{equation}\nThe reference pressure is arbitrary, so one may set $P_0=P$ to make an expression only in terms of the deviation from ideal gas:\n\\begin{equation}\n  \\frac{f(T,P)}{P} = \\exp\\left( \\frac{\\mu(T,P) - \\mu^\\text{ig}(T,P) }{RT} \\right),\n  \\label{}\n\\end{equation}\nwhich shows that for ideal gases, $f(T,P)=P$.\n\n\n\n\\subsubsection{Ideal gas mixtures}\nAn ideal gas mixture is defined as a mixture which has the following expression for the Helmholtz free energy:\n\\begin{equation}\n  A^\\text{ig}(T,V,\\vektor{n}) \\equiv \\sum_i n_i \\left( \n  \\mu_i^\\text{ig}(T,P_0) + RT\\ln \\frac{n_i RT}{P_0 V} - RT\n  \\right)\n  \\label{eq:def_idealmix}\n\\end{equation}\nwhere $n_i$ is the mole number of component $i$, and\n$\\mu^\\text{ig}_i(T,P)$ is the chemical potential of component $i$ in its pure form \nat the given temperature and pressure. This definition is consistent with the ideal gas law for the mixture as a whole, \n$PV=nRT$, where $n=\\sum n_i$.\nFrom \\eqref{eq:def_idealmix} one may find the Gibbs free energy of the \nideal gas mixture as\n\\begin{align}\n  G^\\text{ig}(T,P,\\vektor{n}) \n  &= A^\\text{ig}(T,V,\\vektor{n}) + \\left( PV \\right)^\\text{ig} = A^\\text{ig}(T,V,\\vektor{n}) + nRT \\nonumber\\\\\n  &= \\sum_i n_i \\left( \n  \\mu_i^\\text{ig}(T,P_0) + RT\\ln \\frac{x_i P}{P_0}\n  \\right)\n  \\label{eq:G_idealmix}\n\\end{align}\nwhere $x_i \\equiv n_i/n$ is the \\textit{mole fraction} of component $i$.\n\nFrom \\eqref{eq:def_idealmix} and \\eqref{eq:G_idealmix} \none may find the chemical potential, in terms of $V$ or $P$, of component $i$ in the ideal mixture as\n\\begin{align}\n  \\mu_i^\\text{ig}(T,V,\\vektor{n}) &\\equiv \\pone{A^\\text{ig}}{n_i}{T,V} = \\mu_i^\\text{ig}(T,P_0) + RT\\ln \\frac{n_i RT}{P_0 V} \\nonumber \\\\\n  \\mu_i^\\text{ig}(T,P,\\vektor{n}) &\\equiv \\pone{G^\\text{ig}}{n_i}{T,P} = \\mu_i^\\text{ig}(T,P_0) + RT\\ln \\frac{x_i P}{P_0},\n  \\label{eq:mu_ig}\n\\end{align}\nwhich are equal if the state $(T,V,P,\\vektor{n})$ is a valid ideal gas state ($PV=nRT$), as expected. Combining the two \nequations in \\eqref{eq:mu_ig}, while setting $P_0=P$, leads the the following useful expression:\n\\begin{equation}\n  \\mu_i^\\text{ig}(T,V,\\vektor{n}) - \\mu_i^\\text{ig}(T,P,\\vektor{n})\n  =-RT\\ln \\left( Z \\right)\n  \\label{eq:mu_ig_PVdiff}\n\\end{equation}\nwhere if $(T,V,P,\\vektor{n})$ is a valid state for an ideal gas, \n$Z=1$, and the right hand side reduces to zero as expected.\n\nThe last equation in \\eqref{eq:mu_ig} may be rearranged to form the inspiration for the definition of \nreal mixture fugacity in the next section:\n\\begin{equation}\n  \\frac{P_i}{P_0} = \\exp\\left( \\frac{\\mu^\\text{ig}_i(T,P,\\vektor{n}) - \\mu^\\text{ig}_i(T,P_0)}{RT} \\right)\n  \\label{eq:p_mu_ideal}\n\\end{equation}\nwhere $P_i=x_iP$ is the \\textit{partial pressure} of component $i$. For $P_0 = P$ this reduces to \n\\begin{equation}\n  \\mu^\\text{ig}_i(T,P,\\vektor{n}) - \\mu^\\text{ig}_i(T,P) = RT\\ln x_i\n  \\label{eq:mu_and_xi_idealmix}\n\\end{equation}\n\n\\subsubsection{Real mixtures}\n\\label{sec:realmixtures}\nSimilar to the case of pure components, one may define an ``effective partial pressure'' of a component in a mixture, the \ncomponent fugacity ($f_i$), such that the following relation similar to \\eqref{eq:p_mu_ideal} holds:\n\\begin{equation}\n  \\frac{f_i(T,P,\\vektor{n})}{P_0} \\equiv \\exp\\left( \\frac{\\mu_i(T,P,\\vektor{n}) - \\mu_i^\\text{ig}(T,P_0)}{RT} \\right),\n  \\label{eq:fug_def_mix}\n\\end{equation}\nwhere one may again set $P_0=P$ to state it in terms of deviations from a pure ideal gas:\n\\begin{equation}\n  \\frac{f_i(T,P,\\vektor{n})}{P} \\equiv \\exp\\left( \\frac{\\mu_i(T,P,\\vektor{n}) - \\mu_i^\\text{ig}(T,P)}{RT} \\right),\n  \\label{eq:fug_def_mix_P0eqP}\n\\end{equation}\n\nThe chemical potential of a component in a real mixture may be decomposed into an ideal gas part and a residual part:\n\\begin{align}\n  \\mu_i(T,V,\\vektor{n}) &= \\mu_i^\\text{ig}(T,V,\\vektor{n}) + \\mu_i^\\text{r}(T,V,\\vektor{n}) \\nonumber\\\\\n  \\mu_i(T,P,\\vektor{n}) &= \\mu_i^\\text{ig}(T,P,\\vektor{n}) + \\mu_i^\\text{r}(T,P,\\vektor{n})\n  \\label{}\n\\end{align}\nwhich may be combined with \\eqref{eq:mu_ig_PVdiff} to show that \n\\begin{equation}\n  \\mu_i^\\text{r}(T,V,\\vektor{n}) - \\mu_i^\\text{r}(T,P,\\vektor{n})\n  =RT\\ln \\left( Z \\right)\n  \\label{eq:mu_r_PVdiff}\n\\end{equation}\n\nCombining \\eqref{eq:fug_def_mix_P0eqP} and \\eqref{eq:mu_and_xi_idealmix}, one finds that\n\\begin{equation}\n  \\frac{f_i(T,P,\\vektor{n})}{x_i P} \\equiv\n  \\exp\\left( \\frac{\\mu_i(T,P,\\vektor{n}) - \\mu_i^\\text{ig}(T,P,\\vektor{n})}{RT} \n  \\right)\n  \\label{eq:fugcoeff_vs_mu}\n\\end{equation}\n\nThe \\textit{fugacity coefficient} may now be defined, calculated using \\eqref{eq:fugcoeff_vs_mu} \nand \\eqref{eq:mu_r_PVdiff} as follows:\n\\begin{align}\n  \\phi_i(T,P,\\vektor{n}) \\equiv \\frac{f_i(T,P,\\vektor{n})}{x_i P} &= \n  \\exp\\left( \\frac{\\mu_i(T,P,\\vektor{n}) - \\mu_i^\\text{ig}(T,P,\\vektor{n})}{RT}\\right)\n  \\nonumber\\\\\n  &= \\exp\\left( \\frac{\\mu_i^\\text{r}(T,P,\\vektor{n})}{RT} \\right)\n  \\nonumber\\\\\n  &= \\exp\\left( \\frac{\\mu_i^\\text{r}(T,V,\\vektor{n})}{RT} - \\ln\\left( Z \\right) \\right)\n  \\nonumber\\\\\n  &= \\exp\\left( \\frac{1}{RT}\\pone{A^\\text{r}(T,V,\\vektor{n})}{n_i}{T,V,n_j} - \\ln\\left( Z \\right) \\right)\n  \\label{eq:fugcoeff}\n\\end{align}\nwhere $A^\\text{r}(T,V,\\vektor{n})$ may be found from \\eqref{eq:helmholtz_int}.\n\nAs shown in Sec.~\\ref{sec:eq_multiphase}, the condition of phase equilibrium is that for each component, \nthe chemical potential must be equal in all phases. Using \\eqref{eq:fug_def_mix_P0eqP}, and the fact that \n$\\mu_i^\\text{ig}(T,P)$ is independent of phase, the condition may be restated in the more useful form:\n\\begin{framed}\n  \\noindent\n  For a multi-phase system of given temperature and pressure, the equilibrium condition is that for each component $i$, the quantity \n  $x_i \\phi_i$ is equal in all phases. The fugacity coefficient may be calculated from the equation of state through \n  \\eqref{eq:fugcoeff} and \\eqref{eq:Z_def}.\n\\end{framed}\n\n\\section{TP Flash}\n\n\\subsection{General equations of phase equilibrium and stability}\nAs shown in Sec.~\\ref{sec:eq_multiphase} and~\\ref{sec:realmixtures}, the criterion for equilibrium in a multi-phase system at given temperature \nand pressure is that for each component, the fugacity is equal in all phases.\n\\begin{equation}\n  f_i^{(\\alpha)} = f_i^{(j)} \\quad \\forall \\quad i,j,\\alpha\n  \\label{}\n\\end{equation}\n\nAdditionally, there is a phase stability criterion, stated as the \\textit{tangent plane condition} in Sec.~\\ref{sec:eq_multiphase}.\nLet us define a \\textit{tangent plane distance function} for the composition $\\vektor{z}$, a function of a trial composition $\\vektor{w}$:\n\\begin{equation}\n  \\mathit{TPD}_z(\\vektor{w}) \\equiv \\sum_{i} w_i \\left( \\mu_i(\\vektor{w}) - \\mu_i(\\vektor{z}) \\right).\n  \\label{}\n\\end{equation}\nIt is often conventient to use a \n\\textit{reduced tangent plane distance function}\n\\begin{align}\n  \\mathit{tpd}_z(\\vektor{w}) &\\equiv \\frac{\\mathit{TPD}(\\vektor{w})}{RT} \n  \\nonumber\\\\\n  &= \\sum_{i} w_i \\left[ \\ln w_i + \\ln \\phi_i(\\vektor{w}) - \\ln z_i - \\ln \\phi_i(\\vektor{z}) \\right]\n  \\nonumber\\\\\n  &= \\sum_{i} w_i \\left[ \\ln w_i + \\ln \\phi_i(\\vektor{w}) - d_i(\\vektor{z}) \\right],\n  \\label{}\n\\end{align}\nwhere $d_i \\equiv \\ln z_i + \\ln \\phi_i(\\vektor{z}) $\n\nThe phase stability criterion is then\n\\begin{equation}\n  \\mathit{tpd}_z(\\vektor{w}) \\geq 0 \\quad \\text{for any valid composition $\\vektor{w}$}\n  \\label{}\n\\end{equation}\nand this may be shown to be both a necessary and sufficient condition for phase stability \\cite{michelsen07}. \nIn practice, ensuring that $\\mathit{tpd}_z(\\vektor{w})$ is non-negative everywhere in compositional space is done by finding its \nminima, and then checking if it is negative at these locations. Finding the minima of $\\mathit{tpd}_z(\\vektor{w})$, subject to the constraint of \n$\\sum w_i = 1$, may be solved using the \\textit{method of Lagrange multipliers}.\n\nModified (unconstrained) formulation:\n\\begin{align}\n  \\mathit{tm}_z(\\vektor{W}) &= 1 + \\sum_{i} W_i \\left[ \\ln W_i + \\ln \\phi_i(\\vektor{W}) - d_i(\\vektor{z}) -1\\right]\n  \\nonumber\\\\\n  &= \\left( 1 - W_T + W_T \\ln W_T \\right) + W_T \\mathit{tpd}_z(\\vektor{w})\n  \\label{eq:tm}\n\\end{align}\nwhere $W_i = w_i W_T$ ($W_T \\equiv \\sum W_i $) are mole numbers, not composition, and are thus not constrained to sum to one.\nAt stationary points of $\\mathit{tm}_z(\\vektor{W})$ with respect to $W_i$:\n\\begin{equation}\n  \\ln W_i^\\text{SP} + \\ln \\phi_i(\\vektor{W}^\\text{SP}) - d_i(\\vektor{z}) = 0 \\quad \\forall \\quad i\n  \\label{eq:tm_stationary}\n\\end{equation}\n\\begin{equation}\n  \\mathit{tm}_z(\\vektor{W}^\\text{SP}) = 1 - W_T^\\text{SP} \n  \\label{}\n\\end{equation}\n\nIt may be shown~\\cite[Ch.~9]{michelsen07} that the stationary points of\n$\\mathit{tm}_z(\\vektor{W})$ are also valid stationary points for the\nconstrained function $\\mathit{tpd}_z(\\vektor{w})$, and\n$\\mathit{tpd}_z(\\vektor{w}^\\text{SP})$ is positive at these minima if and only\nif $W_T^\\text{SP} \\leq 1$, \\textit{i.e.} if\n$\\mathit{tm}_z(\\vektor{W}^\\text{SP}) \\geq 0$. The procedure to check stability\ncan then be formulated as:\n\\begin{framed}\n\\begin{enumerate}\n  \\item Find the stationary points of $\\mathit{tm}_z(\\vektor{W})$ with respect to $\\vektor{W}$, \\textit{i.e} solutions of \\eqref{eq:tm_stationary}.\n  \\item Check if $W_T^\\text{SP} \\leq 1$ at all the stationary points found. If not, the mixture $\\vektor{z}$ is unstable.\n\\end{enumerate}\n\\end{framed}\nEq.~\\eqref{eq:tm_stationary} may be solved by \\textit{successive substitution}\nor \\textit{Newton's method}. As discussed by Michelsen \\cite{michelsen07},\nsuccessive substitution will converge in most case but may suffer from a low\nrate of convergence, giving merit to the use of Newton's method. \n\nA composition $\\vektor{z}$ is metastable as long as the Hessian matrix \n$H(\\vektor{z})$ \nof $\\mathit{tm}_z(\\vektor{W})$ is positive definite. \nIf not, the state is \\textit{intrinsically unstable}. \nThe limit between the two cases is the \n\\textit{stability limit / spinodal line}.\n\nHow to uncover all negative minima of $\\mathit{tm}_z(\\vektor{W})$ (if any)?\nThis cannot be done with total certainty, but one may use some clever initial\nestimates to perform a finite set of searches which are likely to uncover\nthem. \n\n\\subsection{Tangent plane stability analysis}\n\nTangent plane stability analysis serves two purposes:\n\\begin{itemize}\n  \\item Verifies that a single phase state is stable.\n  \\item If the single phase state is not stable, gives an improved K-factor guess.\n\\end{itemize}\nAs shown, a phase of composition $\\vektor{z}$ is stable at the specified temperature and pressure \\textit{if and only if}\n$tpd_z(\\vektor{w}) \\geq 0$ for any trial phase composition $\\vektor{w}$. This could checked by inspecting the minima of \n$\\mathit{tm}_z(\\vektor{W})$ \\eqref{eq:tm} and checking the criterion\n$W_T^\\text{SP} \\leq 1$. \n\nThe original composition is \\textit{intrinsically unstable} if the Hessian \n\\begin{equation}\n  H_{ij} \\equiv \\frac{\\partial^2 \\mathit{tm}_z}{\\partial W_i \\partial W_j} \n  = \\frac{\\delta_{ij}}{W_i} + \\frac{\\partial \\ln \\phi_i}{\\partial W_j}\n  \\label{}\n\\end{equation}\nhas any negative eigenvalues at the trivial stationary point at $\\vektor{W}=\\vektor{z}$. If it has no negative eigenvalues at \nthis point, the mixture is either stable ($\\mathit{tm}_z(\\vektor{W}) > 0$ at all its minima) or \n\\textit{metastable} ($\\mathit{tm}_z(\\vektor{W}) < 0$ at some minimum where $\\vektor{W}\\neq \\vektor{z}$).\n\nBy using \\eqref{eq:tm_stationary}, minima of $\\mathit{tm}_z(\\vektor{W})$ may be found by successive substitution:\n\\begin{equation}\n  \\ln W_i^{k+1} = d_i(\\vektor{z}) - \\ln \\phi_i \\left( \\vektor{W}^k \\right),\n  \\label{}\n\\end{equation}\nwhich may be shown to only converge to minima, not other stationary points. Slow convergence may be remedied by higher order \nmethods.\nOutcomes of stability analysis:\n\\begin{itemize}\n  \\item A composition $\\vektor{W}$ where $\\mathit{tm}_z(\\vektor{W}) < 0$ is found. Continue the flash calculation with $\\vektor{w}$ \n    as a new phase.\n  \\item All attempts converge to either the trivial solution of a positive minimum. The composition $\\vektor{z}$ is thus stable.\n\\end{itemize}\n\n\\subsection{Mixture reduced molar Gibbs energy}\nBy combining \\eqref{eq:G_alt}, \\eqref{eq:fugcoeff_vs_mu} and \\eqref{eq:mu_and_xi_idealmix}, one may show that \nthe Gibbs energy of a multi-phase mixture is given by \n\\begin{align}\n  G &= \\sum_j \\sum_i n_i^{(j)} \\mu_i^{(j)} \\nonumber\\\\\n  &= \\sum_j\\sum_i n_i^{(j)} \\left[ \\mu_i^\\text{ig}(T,P,\\vektor{n}) + RT\\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right] \\nonumber\\\\\n  &= \\sum_j\\sum_i n_i^{(j)} \\left[ \\mu_i^\\text{ig}(T,P) + RT\\ln x_i^{(j)} + RT\\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right] \\nonumber\\\\\n  &= \\sum_j\\sum_i n_i^{(j)} \\mu_i^\\text{ig}(T,P) +  \\sum_j \\sum_i n_i^{(j)} \\left[ RT\\ln x_i^{(j)} + RT\\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right] \\nonumber\\\\\n  &= \\sum_i \\left( \\sum_j n_i^{(j)} \\right) \\mu_i^\\text{ig}(T,P) +  \n      \\sum_j \\sum_i n_i^{(j)} \\left[ RT\\ln x_i^{(j)} + RT\\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right] \\nonumber\\\\\n  &= \\sum_i  n_i^{(\\text{tot})}  \\mu_i^\\text{ig}(T,P) +  \n      \\sum_j \\sum_i n_i^{(j)} \\left[ RT\\ln x_i^{(j)} + RT\\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right] \n  \\label{eq:G_mix}\n\\end{align}\n\nWhen wanting to compare the total Gibbs energy of different phase configurations possible from the same overall composition, \nthe first term in \\eqref{eq:G_mix} will cancel due to being identical in all configurations. It is thus not necessary to consider \nit further for these purposes. Denoting this term by $G_0 \\equiv \\sum_i  n_i^{(\\text{tot})}  \\mu_i^\\text{ig}(T,P)$, one may \ndefine a reduced molar Gibbs energy useful for comparing different phase configurations from the same feed by \n\\begin{align}\n  g &\\equiv \\frac{G - G_0 }{nRT} \\nonumber\\\\\n    &= \\sum_i \\sum_j \\beta_j  x_i^{(j)} \\left[ \\ln x_i^{(j)} + \\ln \\phi_i^{(j)}(T,P,\\vektor{n})\\right],\n  \\label{eq:g_func}\n\\end{align}\nwhere $\\beta_j$ is the fraction of moles in phase $j$.\n\n\n\\subsection{Two-phase flash}\nConsider a mixture of $C$ components, of overall composition $\\vektor{z}$, and define the liquid and vapor compositions as \n$\\vektor{x}$ and $\\vektor{y}$, respectively. When indices are used instead of vectors, the index $i$ indicates the component.\nIt is assumed that we have a thermodynamic model for the mixture, capable of calculating the fugacity of any component, given a set of   \ntemperature, pressure and composition.\n\nThe equilibrium condition is \n\\begin{equation}\n  f_i^l = f_i^v \\quad \\forall \\quad i\n  \\label{eq:eq_twophase}\n\\end{equation}\n\nDefine $\\beta$ as the overall mole fraction of the vapor phase, giving the material balance:\n\\begin{equation}\n  \\beta y_i + (1-\\beta)x_i = z_i \\quad \\forall \\quad i\n  \\label{eq:materialbalance}\n\\end{equation}\n\nThe mole fractions must sum to unity, a condition which may be transformed to the convenient form:\n\\begin{equation}\n  \\sum_{i=1}^C \\left( x_i - y_i \\right) = 0.\n  \\label{eq:mole_frac_sum}\n\\end{equation}\nThe above equations yield $2C + 1$ relations, while the number of variables ($\\vektor{x}$, $\\vektor{y}$, $T$, $P$, $\\beta$) are $2C + 3$. \nThis shows that two additional pieces of information are needed, such as specifying $(T,P)$.\n\n\n\\textit{Equilibrium factors}:\n\\begin{equation}\n  K_i \\equiv \\frac{y_i}{x_i}\n  \\label{eq:K_factors}\n\\end{equation}\n\n\nCombining \\eqref{eq:K_factors} and \\eqref{eq:materialbalance}\n\\begin{equation}\n  x_i = \\frac{z_i}{1 - \\beta + \\beta K_i}, \\quad\\quad y_i = K_i x_i = \\frac{K_i z_i}{1 - \\beta + \\beta K_i} \n  \\label{eq:xy_and_Kbeta}\n\\end{equation}\n\nAt equilibrium, where \\eqref{eq:eq_twophase} is satisfied, we have that \n\\begin{equation}\n  K_i \\equiv \\frac{y_i}{x_i} = \\frac{\\phi_i^l}{\\phi_i^v}\n  \\label{eq:K_eq}\n\\end{equation}\n\nCombining \\eqref{eq:mole_frac_sum} with \\eqref{eq:xy_and_Kbeta} leads to the \\textit{Rachford-Rice} equation:\n\\begin{equation}\n  g(\\beta) \\equiv \\sum_{i=1}^C \\left( x_i - y_i \\right) = \\sum_{i=1}^C \\frac{z_i \\left( K_i -1 \\right)}{1 -\\beta + \\beta K_i} = 0\n  \\label{eq:rachford_rice}\n\\end{equation}\n\\begin{framed}\nTwo-phase TP flash by successive substitution:  \n\\begin{enumerate}\n  \\item Use current (or initial) $\\vektor{K}$ in the Rachford-Rice equation \\eqref{eq:rachford_rice}.\n  \\item Solve the Rachford-Rice equation for a value of $\\beta$ \\textit{e.g.} by Newton's method.\n  \\item Find compositions $x_i$ and $y_i$ corresponding to the above values of $K_i$ and $\\beta$, through \\eqref{eq:xy_and_Kbeta}.\n  \\item Find fugacity coefficients from the equation of state given the above compositions, using \\textit{e.g.} \\eqref{eq:fugcoeff}.\n  \\item Find a new equilibrium factor $\\vektor{K}$ using the above fugacity coefficients and the equilibrium assunption \\eqref{eq:K_eq}.\n  \\item Go to 1 if $\\vektor{K}$ has not converged yet.\n\\end{enumerate}\n\\end{framed}\nEqual fugacities may also be satisfied at ``false solutions'', which are critical points of the Gibbs energy, but not minima.\nFortunately, it may be shown that successive substitution can only converge to minima of the Gibbs energy~\\cite{michelsen07}.\nConvergence will be slow at high pressures or close to the mixture critical point.\n\nInitial values for $\\vektor{K}$:\nWilson's approximation:\n\\begin{equation}\n  \\ln K_i = \\ln \\left( \\frac{P_{c_i}}{P} \\right) + 5.373(1+\\gamma_i) \\left( 1-\\frac{T_{c_i}}{T} \\right),\n  \\label{eq:wilson_K}\n\\end{equation}\nwhere $P_{c_i}$, $T_{c_i}$ and $\\gamma_{i}$ is the critical temperature, critical pressure and acentric factor, respectively, \nof component $i$.\n\nSingle phase solution?\\\\\nConvergence at $\\beta <0$ or $\\beta>0$, or convergence to the trivial solution $\\vektor{x} = \\vektor{y}$.\\\\\n\nFlash strategy:\n\\begin{enumerate}\n  \\item Find Wilson K-factors \\eqref{eq:wilson_K} to use as initial estimates.\n  \\item Do three steps of successive substitution. Check for conditions:\n    \\begin{itemize}\n      \\item Total Gibbs energy of the resulting liquid-vapor system is lower than in the feed (assuming single phase). This verifies the presence of \n              multiple phases. Continue iteration, perhaps with higher order methods.\n      \\item If not the above, check  if $\\mathit{tpd}_z(\\vektor{x})$ or $\\mathit{tpd}_z(\\vektor{y})$ is negative. If the former, set \n        $K_i = \\phi_i^x / \\phi_i^z$. If the latter, set $K_i = \\phi_i^z / \\phi_i^y$. Continue iteration.\n    \\end{itemize}\n  \\item If neither of the above conditions were met after three iterations, do tangent plane stability analysis.\n\\end{enumerate}\nIf at any time $\\beta$ exceeds its bounds, it is very likely that the specification corresponds to a single phase state. \nTo be certain, perform tangent plane stability analysis.\n\n\nInitializing $\\vektor{W}$ for tangent plane analysis: \nInvestigate both ``liquid-like'' and ``vapor-like'' trial compositions, through \nWilson K-factors \\eqref{eq:wilson_K}. If the feed itself may with confidence be said to be ``liquid-like'' or ``vapor-like'', \none may to save time only investigate the trial composition of the opposite kind.\n\n\n\n\\subsubsection{Solution by minimization}\nWhen formulating an equilibrium calculation as a minimization problem, it \nmay be useful to use \\textit{molar amounts} as the independent variables, \ndefined by \n\\begin{align}\n  v_i &\\equiv \\beta y_i\\nonumber\\\\\n  l_i &\\equiv (1-\\beta) x_i,\n  \\label{}\n\\end{align}\nsuch that\n\\begin{equation}\n  v_i + l_i = z_i,\n  \\label{}\n\\end{equation}\nwhere $\\vektor{z}$ is now molar amounts, but numerically identical to the feed composition.\n\n\\begin{equation}\n  y_i = \\frac{v_i}{\\sum v_i}, \\quad x_i = \\frac{l_i}{\\sum l_i}\n  \\label{}\n\\end{equation}\n\n\\begin{equation}\n  \\beta_L \\equiv 1-\\beta\n  \\label{}\n\\end{equation}\n\n\\begin{equation}\n  \\beta = \\sum v_i\n  \\label{}\n\\end{equation}\n\n\\begin{equation}\n  \\beta_L = \\sum l_i\n  \\label{}\n\\end{equation}\n\nThe minimization problem to be solved is then \n\\begin{equation}\n  \\vektor{v} = \\underset{\\vektor{v} \\in \\mathbb{R}^C}{\\argmin}\\left\\{g(\\vektor{v},\\vektor{l}(\\vektor{v}))\\right\\}, \\quad\\text{with } \n  \\vektor{l} = \\vektor{z}-\\vektor{v}\n  \\label{}\n\\end{equation}\n\\textit{e.g.}\\ by Newton's method of optimization (ref appendix).\n\n\nBy using \\eqref{eq:g_func} for the case of two-phase systems:\n\\begin{equation}\n  g = \\sum_i \\left( v_i \\left[ \\ln y_i + \\ln \\phi_i^v \\right] + l_i \\left[ \\ln x_i + \\ln \\phi_i^l \\right] \\right)\n  \\label{eq:g_twophase}\n\\end{equation}\n\n\\begin{align}\n  \\frac{\\partial g}{\\partial v_j}\n  =& \\ln y_j - \\ln x_j + \\ln \\phi_j^v - \\ln \\phi_j^l \\nonumber\\\\\n  &+ 1 - \\underbrace{\\sum_i y_i}_{=1} + \\underbrace{\\sum_i v_i \\frac{\\partial \\ln \\phi_i^v}{\\partial v_j}}_{=0}\\nonumber\\\\\n  &- 1 + \\underbrace{\\sum_i x_i}_{=1} - \\underbrace{\\sum_i l_i \\frac{\\partial \\ln \\phi_i^l}{\\partial l_j}}_{=0} \\nonumber\\\\\n  =& \\ln y_j - \\ln x_j + \\underbrace{\\ln \\phi_j^v - \\ln \\phi_j^l}_{\\text{From EoS}},\n  \\label{}\n\\end{align}\nwhere the sums involving derivatives are zero due to \\textit{Euler's theroem} for homogeneous functions, as explained in\n1.8 of~\\cite{michelsen07}.\n\n\\begin{align}\n  \\frac{\\partial^2 g}{\\partial v_i \\partial v_j} \n  &= \\frac{\\partial \\ln \\phi_j^v}{\\partial v_i} - \\frac{\\partial \\ln \\phi_j^l}{\\partial v_i}  \n  - \\left( \\frac{\\beta + \\beta_L}{\\beta \\beta_L} \\right)\n  + \\delta_{i,j} \\left( \\frac{z_i}{x_i y_i \\beta \\beta_L} \\right) \\nonumber\\\\\n  &= \n  \\frac{1}{\\beta \\beta_L} \\left[\n  \\beta_L \\underbrace{\\left( \\sum_i v_i\\right)  \\frac{\\partial \\ln \\phi_j^v}{\\partial v_i} }_\\text{From EoS}\n  +  \\beta \\underbrace{\\left( \\sum_i l_i\\right)  \\frac{\\partial \\ln \\phi_j^l}{\\partial l_i}}_\\text{From EoS}\n  - 1\n  + \\delta_{i,j} \\left( \\frac{z_i}{x_i y_i} \\right) \n  \\right]\\nonumber\\\\\n  \\label{}\n\\end{align}\n\nThe function $g$ in \\eqref{eq:g_twophase} should at the located minimum be smaller than the smallest possible value \nfor the a single phase of feed composition:\n\\begin{equation}\n  g_\\text{feed} = \\min\\left\\{ \\sum_i  z_i \\left[ \\ln z_i + \\ln \\phi_i(\\vektor{z}) \\right]   \\right\\},\n  \\label{}\n\\end{equation}\nwhich is either a liquid or a vapor state, depending on which has the lowest Gibbs energy.\n\n\n\\section{Cubic equations of state}\nThe general cubic equation of state has the form\n\\begin{equation}\nP = \\frac{RT}{v -b}- \\frac{\\alpha a}{(v-m_1 b)(v-m_2 b)},\n\\label{eq:gencubic}\n\\end{equation}\nwhere $m_1$ and $m_2$ are dimensionless constants defining the SRK, PR and Van der\nWaals equation of state, $v=V/n~(\\SI{}{\\meter^3\\per\\mol})$ is the specific volume. The\nparameters $a~(\\SI{}{\\meter^3\\joule\\per \\mol^2})$ and $b~(\\SI{}{\\meter^3\\per\\mol})$ typically \ndepend on the composition and the dimensionless quantity \n$\\alpha$ is a function of temperature. \n\n\n\n\\begin{shaded}\n  \\noindent\n\\textit{Exercise: Find the reduced residual Helmholtz energy function for a general\ncubic equation of state \\eqref{eq:gencubic}.}\n\n\\noindent\n\\textit{Solution}:\n\\begin{equation}\n  A^\\text{r}(T,V,N) = n \\left[ RT\\ln \\left( \\frac{v}{v-b} \\right) + \n  \\frac{\\alpha a}{\\left( m_1-m_2 \\right)b} \\ln\\left( \\frac{v-m_1 b}{v-m_2 b} \\right) \\right]\n  \\label{}\n\\end{equation}\n\n\\end{shaded}\n\n\\subsection{Mixing rules}\nMixing rules are various ways of letting $a$ and $b$ in \\eqref{eq:gencubic} \ndepend on composition. \n\n\\subsubsection{Classic mixing rule}\nParameters: $a_{ii}$, $k_{ij}$ and $b_i$.\n\\begin{equation}\n  a = \\sum_i x_i \\sum_j x_j a_{ij}\n  \\label{}\n\\end{equation}\n\n\\begin{equation}\n  a_{ij} = a_{ji} = \\sqrt{a_{ii} a_{jj}} \\left( 1-k_{ij} \\right)\n  \\label{}\n\\end{equation}\n\n\\begin{equation}\n  b = \\sum_i x_i b_i\n  \\label{}\n\\end{equation}\n\n\n\\subsubsection{Huron-Vidal mixing rule}\n\n\n\n\\section{Explicit Helmholtz equations of state}\nBased on an explicit expression for the reduced dimensionless Helmholtz energy \\eqref{eq:reduced_helmholtz}. This includes \nequations such as GERG2004/2008 and the Span-Wagner equation of state for \\ce{CO2}.\n\n\\begin{equation}\n  a(\\delta,\\tau,\\vektor{x}) = a^\\text{ig}(\\rho,T,\\vektor{x}) + a^\\text{r}(\\delta,\\tau,\\vektor{x}),\n  \\label{}\n\\end{equation}\nwhere $\\delta$ is the \\textit{reduced mixture density} and $\\tau$ is the \\textit{reduced mixture temperature}, which are both generally \ndependent on the composition:\n\\begin{equation}\n  \\delta = \\frac{\\rho}{\\rho_r(\\vektor{x})}, \\quad \\quad \\tau = \\frac{T}{T_r(\\vektor{x})}.\n  \\label{}\n\\end{equation}\n\n\n\\section{Ideal gas Helmholtz energy}\nThe equation of state does not provide the energies.\nIn order to find the total Helmholtz energy, and not just the residual, \nthe ideal gas contribution $A^\\text{ig}$ must be found.\n\nAn ideal gas is defined by two equations. One the equation of state\n\\begin{equation}\n  P^\\text{ig} = \\frac{nRT}{V}\n  \\label{eq:idealgaslaw}\n\\end{equation}\nand the second is the equation for the internal energy\n\\begin{equation}\n  U^\\text{ig}(T,n) = n c_v(T) T\n  \\label{eq:U_ideal}\n\\end{equation}\nwhich simply states that the internal energy depends on the temperature and the number of particles only. The function $c_v$\nis the \\textit{heat capacity at constant volume}: \n\\begin{equation}\n  C_v = n c_v \\equiv \\pone{Q}{T}{V} = \\pone{U}{T}{V}.\n  \\label{}\n\\end{equation}\nAdditionally there is the \\textit{heat capacity at constant pressure}:\n\\begin{equation}\n  C_p = n c_p \\equiv \\pone{Q}{T}{P} = \\pone{H}{T}{P},\n  \\label{}\n\\end{equation}\nwhere it was used that $\\dd{H} = \\delta Q + V\\dd{P}$.\nFor an ideal gas, the enthalpy is \n\\begin{align}\n  H^\\text{ig}(T,n) &\\equiv U^\\text{ig} + p^\\text{ig}V \n  \\nonumber\\\\\n  &= U^\\text{ig}(T,n) + nRT\n  \\nonumber\\\\\n  &= n\\left( c_v + R \\right)T\n  \\label{}\n\\end{align}\nwhich shows that for an ideal gas\n\\begin{equation}\n  c_p = c_v + R.\n  \\label{}\n\\end{equation}\n\nChange in ideal gas enthalpy at a constant number of particles:\n\\begin{align}\n  H^\\text{ig}(T,n) - H^\\text{ig}_0 &= \\int_{T_0}^T \\pone{H}{T}{P} \\dd{T}\n  \\nonumber\\\\\n   &= n \\int_{T_0}^T c_p \\dd{T}\n  \\label{}\n\\end{align}\n\nChange in ideal gas entropy at a constant number of particles:\n\\begin{align}\n  S^\\text{ig}(T,V,n) - S^\\text{ig}_0 \n  &= \\int_{T_0}^T \\pone{S}{T}{V} \\dd{T} + \\int_{V_0}^V \\pone{S}{V}{T} \\dd{V}\n    \\nonumber\\\\\n    &=\\int_{T_0}^T \\frac{n c_v(T)}{T} \\dd{T}\n    + \\int_{V_0}^V \\pone{P}{T}{V} \\dd{V}\n    \\nonumber\\\\\n    &=n\\int_{T_0}^T \\frac{c_p(T) - R}{T} \\dd{T}\n    + nR\\int_{V_0}^V \\frac{1}{V} \\dd{V}\n    \\nonumber\\\\\n    &=n\\int_{T_0}^T \\frac{c_p(T) - R}{T} \\dd{T}\n    + nR\\ln \\left( \\frac{V}{V_0} \\right),\n  \\label{}\n\\end{align}\nusing \n\\begin{equation}\n  \\pone{S}{T}{V} = \\pone{S}{U}{V} \\pone{U}{T}{V} = \\frac{1}{T} \\pone{U}{T}{V} = \\frac{n c_v}{T} \n  \\label{}\n\\end{equation}\nand the \\textit{Maxwell relation}\n\\begin{equation}\n\\label{eq:dsrel}\n\\pone{S}{V}{T,\\vektor{n}} = \\pone{P}{T}{V,\\vektor{n}}.\n\\end{equation}\n\nThe total Helmholtz energy is not provided through the cubic equation of state, only the residual part.\nThe ideal gas part is usually specified as \nalgebraic temperature functions for the heat capacity at constant pressure, $c_p(T)$, provided\nfor each component in the mixture. The total Helmholtz energy may be written as \n\\begin{align}\n  A &\\equiv U - TS \\nonumber\\\\\n  &=U-TS+PV-PV \\nonumber\\\\\n  &= H - TS - PV,\n  \\label{}\n\\end{align}\nwhich means that the Helmholtz energy of a pure ideal gas may be expressed as:\n\\begin{align}\n  A^\\text{ig}_i(T,V,n_i) &= H^\\text{ig} - TS^\\text{ig} - nRT\n  \\nonumber\\\\\n  &= \\Delta H_i^\\text{ig} + H_{0,i}^\\text{ig} \n  - T\\left(  \\Delta S_i^\\text{ig} + S_{0,i}^\\text{ig}  \\right)  - n_i RT\n  \\nonumber\\\\\n  &=  n_i \\int_{T_0}^T c_{p,i}^\\text{ig}(T) \\dd{T} + H_{0,i}^\\text{ig}\n  -  n_i T \\left[ \\int_{T_0}^T \\frac{c_{p,i}^\\text{ig}(T) - R}{T} \\dd{T} \n    + R \\ln \\left( \\frac{V}{V_0} \\right) \\right]\n     - T S_{0,i}^\\text{ig} - nRT.\n  \\label{}\n\\end{align}\n\nMixing carries with it another entropy contribution, even in the case of ideal mixtures, \\textit{i.e.} with no interactions. The entropy change \nfrom ideal mixing at constant pressure and temperature is:\n\\begin{align}\n  \\Delta S^\\text{ig}_\\text{mix} &= -nR \\sum_i x_i \\ln x_i \n  \\nonumber\\\\\n  &= -R \\sum_i n_i \\ln \\left( \\frac{n_i}{n} \\right),\n  \\label{}\n\\end{align}\nwhich means that the total Helmholtz energy of an ideal mixture is given by:\n\\begin{align}\n  A^\\text{ig}(T,V,\\vektor{n}) &=  \\sum_i A_i^\\text{ig}(T,V,n_i) - T \\Delta S^\\text{ig}_\\text{mix}\n  \\label{}\n\\end{align}\nIn terms of the reduced Helmholtz energy, this becomes:\n\\begin{align}\n  a^\\text{ig}(T,V,\\vektor{x}) &=  \\sum_i x_i a_i^\\text{ig}(T,V) + \\sum_i x_i \\ln x_i, \n  \\label{}\n\\end{align}\nwhere \n\\begin{equation}\n  a_i^\\text{ig}(T,V) \\equiv \\frac{A^\\text{ig}_i(T,V,n_i)}{n_i RT}.\n  \\label{}\n\\end{equation}\n\n\n\\appendix\n\n\\section{Newton's method for root finding}\n\\section{Newton's method for optimization (Modified Newton)}\n\\section{Accelerated direct substitution (Dominant Eigenvalue Method)}\n\n\n\\begin{thebibliography}{9}\n\n\\bibitem{callen85}\n  Herbert B. Callen,\n  \\emph{Thermodynamics and an Introduction to Thermostatistics}.\n  second edition,\n  John Wiley \\& Sons Inc,\n  1985.\n\n\\bibitem{kunz07}\n  O. Kunz, R. Klimeck, W. Wagner, M. Jaeschke,\n  \\emph{The GERG-2004: Wide-Range Equation of State for Natural Gases and Other Mixtures}.\n  GERG TM15 Report (http://www.gerg.eu/publications/tm.htm),\n  2007.\n\n\\bibitem{michelsen82a}\n  Michael L. Michelsen,\n  \\emph{The isothermal flash problem. Part I. stability}.\n  Fluid Phase Equilibria,\n  9(1)\n  pp. 1-19,\n  1982.\n\n\\bibitem{michelsen82b}\n  Michael L. Michelsen,\n  \\emph{The isothermal flash problem. Part II. phase-split calculation}.\n  Fluid Phase Equilibria,\n  9(1)\n  pp. 21-40,\n  1982.\n\n\\bibitem{michelsen99}\n  Michael L. Michelsen and J{\\o}rgen M. Mollerup,\n  \\emph{State function based flash specifications}.\n  Fluid Phase Equilibria,\n  158-160\n  pp. 617-626,\n  1999.\n\n\\bibitem{michelsen07}\n  Michael L. Michelsen and J{\\o}rgen M. Mollerup,\n  \\emph{Thermodynamic models: Fundamentals \\& computational aspects}.\n  second edition\n  Tie-Line Publication,\n  2007.\n\n\\bibitem{span96}\n  Roland Span and Wolfgang Wagner,\n  \\emph{A New Equation of State for Carbon Dioxide Covering the Fluid Region\n  from the Triple-Point Temperature to 1100 {K} at Pressures up to 800 {MPa}}.\n  J. Phys. Chem. Ref. Data,\n  25(6)\n  pp. 1509-1596\n  1996.\n\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "212fbe7b0120962041c93777eff424de8c96e835", "size": 46443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/memo/intro/intro.tex", "max_stars_repo_name": "SINTEF/Thermopack", "max_stars_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-10-14T07:51:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T04:59:23.000Z", "max_issues_repo_path": "doc/memo/intro/intro.tex", "max_issues_repo_name": "SINTEF/Thermopack", "max_issues_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-10-26T11:43:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:06:30.000Z", "max_forks_repo_path": "doc/memo/intro/intro.tex", "max_forks_repo_name": "SINTEF/Thermopack", "max_forks_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-10-27T13:04:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T04:59:24.000Z", "avg_line_length": 40.9911738747, "max_line_length": 167, "alphanum_fraction": 0.6945072454, "num_tokens": 15755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581049086031, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6410077788816405}}
{"text": "\\documentclass[../main.tex]{}\n\\begin{document}\n\n\\subsection{Clarke Wright Saving Algorithm}\nThe Clarke and Wright algorithm \\cite{clarke_wright} is one of the earliest, and most popular heuristic algorithm for the VRP due to its speed, simplicity, and ease of adjustment to handle various constraints in real-life applications. Clarke Wright saving algorithm works equally well for both directed and undirected problems. The algorithm is built on a basic simple idea: maximize saving cost within a route, hence minimize total cost. Consider a depot D and n demand points. Suppose that initially the solution to the VRP consists of using n vehides and dispatching one vehicle to each one of the n demand points. The total cost of this solution is:\n\\[ C = 2\\sum\\limits_{i=1}^n d(D, i)\\]\nwhere d(i, j) is a function calculate distance between point i and , j, and C is total cost. To get a better solution, we now can combine 2 customers served by single vehicle on a single trip, the total distance we can save after combined is:\n\\begin{eqnarray}\ns(i, j) & = & 2d(D, i) + 2d(D, j) \\nonumber \\\\\n&& -\\: [d(D, i) + d(D, j) + d(i, j)] \\nonumber \\\\\n& = & d(D, i) + d(D, j) - d(i, j)\n\\end{eqnarray}•\n\\begin{algorithm}\n\\caption{Clarke Wright saving alorithm}\\label{alg:clarke_wright}\n\\textbf{Step 1: Savings computation}\n\\flushleft\n\\begin{itemize}\n\\item Compute $s_{ij} \\forall(i, j) \\subset E$.\n\\item Sort $s_{ij}$\n\\end{itemize}\n\\textbf{Step 2:  Route Extension}\n\\flushleft\n\\begin{itemize}\n\\item for each route $(0, i, ..., j, 0)$\n\\item Determine the first saving ${s_{ki}}$ or ${s_{jl}}$ that can feasibly be used to merge the current route with another route ending with ${(k,0)}$ or starting with ${(0,l)}$.\n\\item Implement the merge and repeat this operation to the current route.\n\\item If not feasible merge exists, consider the next route and reapply the same operations.\n\\item Stop when not route merge is feasible.\n\\end{itemize}\n\\end{algorithm}\n\n\\subsection{Ruin and Recreate Algorithms}\n\nRuin and recreate framework is introduced in \\cite{ref:rr_break}. By performing ruin and recreation on current solutions frequently enough, the better solutions will be obtained. A set of random vehicle routes are created and their total vehicle distance is calculated. The Ruin and Recreate approach is applied frequently to obtain another set of vehicle routes that have the least of total vehicle distance.\n\nThis approach starts with creating a set of initial vehicle routes: a random customer is selected, and combined with the depot location to create a base vector. The base vector starts to rotate clockwise with the depot location at the center and customers on the way are added to the route. If the route is over the vehicle capacity, a new route is created, and so on. Total vehicle distance is calculated for the initial routes.\nNext, some customers from each initial route are removed by different ruin strategies and then added back to the same route in different order or different route using greedy insertion recreation strategy by trying all possible locations to pick the least total vehicle distance.\n There are three ruin strategies are used to remove customers from existing solution: random ruin, sequential ruin, and least customer ruin. Random strategy removes customers randomly from all customers of all routes, which creates the effect of diversifying the removing process. Sequential strategy removes customers sequentially in a selected route. The least customer strategy removes all customers in the route that has the least customers.\nGreedy insertion strategy is used for the recreation of the solution by adding the removed customers back. This approach is to insert each removed customer to the cheapest possible route.\n\n\\begin{algorithm}\n\\caption{Ruin and recreate framework}\\label{alg:RR}\n\\flushleft\n\\begin{itemize}\n\\item create intial solution\n\\item do {\n\\flushleft\n\\begin{itemize}\n\\item choose ruin and recreate strategy\n\\item ruin current solution\n\\item recreate ruined solution\n\\item if new solution better than current solution\n\\item then accept new solution\n\\item else accept new solution with probaility $e^{\\frac{\\Delta C}{T}}$\n\\end{itemize}\n\\item } while stop condition is not meet\n\\item return best solution\n\\end{itemize}\n\\end{algorithm}\n\n\\end{document}\n", "meta": {"hexsha": "48778449eeff0464a5d6c7657ddd8dc6dd80174e", "size": 4290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/methods.tex", "max_stars_repo_name": "dinhvan5481/ee382v-adv-algorithms-vehicle-routing-problem", "max_stars_repo_head_hexsha": "2aff876c4f6440fe4fb8551f1647ab14085dfa92", "max_stars_repo_licenses": ["MIT"], "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/methods.tex", "max_issues_repo_name": "dinhvan5481/ee382v-adv-algorithms-vehicle-routing-problem", "max_issues_repo_head_hexsha": "2aff876c4f6440fe4fb8551f1647ab14085dfa92", "max_issues_repo_licenses": ["MIT"], "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/methods.tex", "max_forks_repo_name": "dinhvan5481/ee382v-adv-algorithms-vehicle-routing-problem", "max_forks_repo_head_hexsha": "2aff876c4f6440fe4fb8551f1647ab14085dfa92", "max_forks_repo_licenses": ["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.1935483871, "max_line_length": 654, "alphanum_fraction": 0.7771561772, "num_tokens": 1015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6410077733119761}}
{"text": "%intro\n\n\\section{Introduction}\nWe are presenting a brief summory of basic concepts of modern algebraic geometry. In particular, we will discuss standard constructions and expand our learnings to a more abstract scheme theoretic approach.\n\\subsection{Requirements}\nThe reader only needs a minimum understanding in linear and abstract algebra. However, although some definitions will be missed we try to include as many as possible.\\\\\n\\subsection{Basics}\n\\indent We denote by $R$ an arbitrary ring with one (unital), unless mentioned otherwise, always commutative. A field is denoted by $k$ and its algebraic closure with $\\overline{k}$, special fields and rings are denoted following \\cite{Bour}. The polynomial ring for a given ring $R$ is denoted by $R[X] = R[X_1\\ldots X_n]$ and the affine module $\\mathbb{A}^n_R = (R^n, P(R^n), \\phi)$.\n\\subsubsection{Zero sets and the Zariski topology}\nGiven a field $k$ and its polynomial ring $k[X] = k[X_1\\ldots X_n]$ and a nonempty set of polynomials $F \\subset R[X]$, the zero set of $F$, $Z(F)$, is defined:\n$$\\left\\{x \\in \\kaffn : f(x) = 0 \\ \\forall f \\in F\\right\\}.$$\nWe may rewrite:\n$$\\begin{array}{rcl}\nZ(F) &=& \\{x : f(x) = 0 \\forall f \\in F\\}\\\\&&\\\\\n&=& \\bigcap_{f \\in F} \\{x : f(x) = 0\\}.\\\\\n\\end{array}$$\nIn other words, $Z(F)$ is simply the intersection of common zeros of  each polynomial in $F$. Therefore, we could have simply defined zero sets for polynomials and then show that zero sets of $F$ are the intersections of the zeros of its elements.\\\\\n\\indent We remark that $Z(F)$ may be empty if no common zero is present (e.g. $f = X, g = X - 1 \\in k[X]$). The zero set of the constant polynomial $1 \\in k[X]$ is therefore empty and the zero set of $0 \\in k[X]$ is the whole affine space.\\\\\n\\paragraph{Zeros and their topology}\nBy the above definition, we get that the set of all zeros is closed under arbitrary intersection. Furthermore, the empty set and the whole affine space are present in $\\cldk := \\{X \\subset \\kaffn : X \\ \\mathrm{zero~set}\\}$. Now, let us check for two polynomials $f, g \\in k[X]$:\n$$\\begin{array}{rcl}\nZ(f) \\cup Z(g) &=& \\{x : f(x) = 0\\} \\cup \\{x : g(x) = 0\\}\\\\&&\\\\\n&=& \\{x : f(x) = 0 \\vee g(x) = 0\\}\\\\&&\\\\\n&=& \\{x : f(x) \\cdot g(x) = 0\\}\\\\&&\\\\\n&=& Z(f g)\\\\\n\\end{array}$$\nThis shows $\\cldk$ is closed under finite union and making it a closed topology (i.e. generated by closed sets) over $\\kaffn$.\\\\\n\\paragraph{Principal open sets and their topology}\n\\indent Now, for a given $f \\in k[X]$ we call the set\n$$D(f) := \\{x \\in \\kaffn : f(x) \\neq 0\\}$$\na principal open set of $\\kaffn$. It is obviously the complement of a zero set. Now, for any nonempty set $F$ of polynomials we define the open set\n$$D(F) := \\bigcup_{f \\in F} D(f).$$\nAgain, we remark that $D(F)$ may be empty or the full affine space:\n$$D(F) = \\kaffn \\Leftrightarrow F \\subset k^\\times,\\ D(F) = \\emptyset \\Leftrightarrow F = \\{0\\}.$$\nAs above, we need to check for closeness under intersection. However, as we defined our subset system via the complements of a topology generated by closed sets we get a topology generated by open sets. Therefore:\n$$\\opnk := \\left\\{U \\subset \\kaffn : U^c := \\kaffn\\backslash U \\in \\cldk\\right\\}$$\nis an open topology on $\\kaffn$.\n\\begin{defi}\nThe topology $\\tau \\subset \\mathcal{P}(\\kaffn)$ generated by both $\\cldk$ and $\\opnk$ is called the Zariski topology on $\\kaffn$.\n\\end{defi}\n\\subsubsection{Affine schemes and the Zariski topology}\nGiven a unital commutative $k$ algebra $R$ and the class of all $R$-submodules of $R$, $\\mathrm{Mod}_R(R)$, (i.e. its ideals)\n$$\\specr := \\{\\prm \\in \\mathrm{Mod}_R(R) : \\prm \\ \\mathrm{prime}\\},$$\nthe set of all prime ideals, is called the spectrum of $R$.\n\\paragraph{Pairing of points and ideals}\nGiven a $P = (P_1,\\ldots,P_n) \\in \\kaffn$, the ideal\n$$\\mxx_P = \\left<X_1 - P_1,\\ldots,X_n - P_n\\right>$$\nis maximal in every polynomial ring $k[X]$ over some field $k$. As every maximal ideal in a unital ring is prime we get a unique subset of $\\specr$:\n$$\\max (R) = \\{\\mxx \\in \\specr : \\mxx \\ \\mathrm{maximal}\\},$$\ni.e. the set of maximal ideals in $R$.\n\\begin{prop}\nLet $k = \\overline{k}$ be a field and $R = k[X]$. The pairing\n$$\\kaffn \\longrightarrow \\max(R),\\ P \\longmapsto \\mxx_P$$\nis a bijection.\n\\end{prop}\n\\bmk This proposition is a rephrasing of Hilberts Nullstellensatz. Thus, the interested reader will find a proof in the standard literature as \\cite{Hart}. In analogy to the Zariski topology on $\\kaffn$ we define for some family of polynomials $F$:\n$$V(F) = \\{\\prm \\in \\speck : f \\in \\prm,\\ \\forall f \\in F\\} = \\bigcap_{f \\in F} \\{\\prm : f \\in \\prm\\}.$$\nAccordingly, we call for some polynomial $f \\in k[X]$ the set $U(f) = \\{\\prm : f \\notin \\prm\\} = V(f)^c$ a prinicipal open set in $\\speck$. Again, we get for some family $F$ of polynomials:\n$$\n\\begin{array}{rclcl}\nU(F) &:=& V(F)^c &=& \\speck \\backslash V(F)\\\\&&&&\\\\ &=& \\speck \\backslash \\left(\\bigcap_{f \\in F} V(f)\\right) &=& \\bigcup_{f \\in F} \\left(\\speck \\backslash V(f)\\right)\\\\&&&&\\\\ &=& \\bigcup_{f \\in F} V(f)^c &=& \\bigcup_{f \\in F} U(f).\\\\\n\\end{array}\n$$\nWith this equivalences in place, we get the following proposition\n\\begin{prop}\nThe sets $\\kaffn$ and $\\X := \\speck$ are isomorphic in the category of topological spaces with corresponding topologies $\\cldk$ and $\\opnk$, as well as\n$$\\mathcal{F}(\\X) = \\{V(F) : F \\subset k[X]\\}\\ \\mathrm{and}\\ \\mathcal{O}(\\X) = \\{V(F)^c : F \\subset k[X]\\},$$\nrespectively. Again, $V(F)^c := \\speck \\backslash V(F)$.\n\\end{prop}\n\\bws We simply use our bijective pairing above:\n$$\\kaffn \\ni P = (P_1,\\ldots,P_n) \\longmapsto \\mxx_P = \\left<X_1 - P_1,\\ldots,X_n - P_n\\right> \\in X.$$\nFurthermore, we expand\n$$\\begin{array}{rclcl}\n\\cldk \\ni Z(F) &=& \\bigcap_{f \\in F} Z(f) \\longmapsto V(F) &=& \\bigcap_{f \\in F} V(f) \\in \\mathcal{F}(\\X)\\\\&&&&\\\\\n\\opnk \\ni D(F) &=& \\bigcup_{f \\in F} D(f) \\longmapsto U(F) &=& \\bigcup_{f \\in F} U(f) \\in \\mathcal{O}(\\X)\\\\\n\\end{array}$$", "meta": {"hexsha": "6d293c61f0e35a7923c30f7ae11c60d7f03eca0e", "size": 5894, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg_geo/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": "alg_geo/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": "alg_geo/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": 77.5526315789, "max_line_length": 385, "alphanum_fraction": 0.6669494401, "num_tokens": 2025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6410077733119761}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath, amssymb, graphicx, float, dsfont}\n\n%opening\n\\title{Notes for \"Statistics Informed Decisions using Data\"}\n\\author{Delbert Yip}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n\tThese notes covers several chapters from \"Statistics Informed Decisions using Data,\" focusing on practical applications. \n\\end{abstract}\n\n\\section{Probability Distributions}\n\\textbf{Poisson distribution}\nA random variable $X$, the number of successes in a fixed interval, follows a Poisson process if:\n\\begin{itemize}\n\t\\item The probability of 2 or more successes in a sufficiently small subinterval, is 0.\n\t\\item The probability of success is the same for any two intervals of equal length. \n\t\\item The number of successes in any interval is independent of the number of successes in any other intervals, as long as said intervals do not overlap. \n\\end{itemize}\n\nA Poisson process is described by:\n\\begin{equation}\nP(x) = \\frac{(\\lambda t)^x}{x!} \\exp(-\\lambda t), \\quad x=0,1,...n\n\\end{equation}\n\nWhere $\\lambda$ is the average number of occurrences of the event in an interval of length 1. \n\n\\section{Inference}\n\\subsection{Hypothesis Tests}\nWe try to find support for the \\textbf{alternative hypothesis}, $H_1$. The \\textbf{null hypothesis}, $H_0$, is assumed true until refuted by evidence, and assumes no change/difference/etc. Three ways to set up null and alternative hypotheses:\n\\begin{enumerate}\n\t\\item Two-tailed test: equal versus not equal\n\t\\begin{align*}\n\t\tH_0 &= x \\\\\n\t\tH_1 &\\neq x\n\t\\end{align*}\n\t\n\t\\item Left-tailed test: equal versus less than \n\t\\begin{align*}\n\tH_0 &= x \\\\\n\tH_1 &< x\n\t\\end{align*}\n\t\n\t\\item Right-tailed test: equal versus greater than \n\t\\begin{align*}\n\tH_0 &= x \\\\\n\tH_1 &> x\n\t\\end{align*}\n\\end{enumerate}\n\n$H_0$ is always a statement of equality. Left- and right-tailed tests are a.k.a one-tailed tests. There are two types of errors in hypothesis testing: Type I (false negative, $H_0$ is rejected when $H_0$ is actually true) and Type II (false positive, $H_0$ is not rejected while $H_1$ is true.) Importantly, the \\textbf{level of significance, $\\alpha$} is the \\textit{probability of making a Type I error/false negative}.The  choice of $\\alpha$ depends on the consequences of making a Type I error, or false negative. On the other hand, $\\beta$ is the probability of making a Type II error/false positive. There is an inverse relation between $\\alpha$ and $\\beta$: when $\\alpha$ is small, $\\beta$ is large. \n\n\\end{document}\n", "meta": {"hexsha": "85226ae667745ce0c9759114cc38b79717240efa", "size": 2486, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_posts/SIDUD_notes.tex", "max_stars_repo_name": "haganenoneko/website.github.io", "max_stars_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_posts/SIDUD_notes.tex", "max_issues_repo_name": "haganenoneko/website.github.io", "max_issues_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_posts/SIDUD_notes.tex", "max_forks_repo_name": "haganenoneko/website.github.io", "max_forks_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_forks_repo_licenses": ["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.8620689655, "max_line_length": 707, "alphanum_fraction": 0.7437650845, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.6410077674565017}}
{"text": "\\documentclass[english]{../spicker}\r\n\r\n\\usepackage{amsmath}\r\n\r\n\\usepackage{graphicx}\r\n\\usepackage{tabularx, multirow}\r\n\r\n\\usepackage[style=numeric, backend=bibtex]{biblatex}\r\n\\addbibresource{or.bib}\r\n\r\n\\title{Operations Research}\r\n\\author{Patrick Gustav Blaneck}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\\tableofcontents\r\n\\newpage\r\n\r\n%\\setcounter{section}{1}\r\n\r\n\\section{Linear Programming}\r\n\r\n\\begin{defi}{Linear Programming}\r\n    \\emph{Linear Programming} is the problem of optimizing (maximizing or minimizing) a \\emph{linear objective function} subject to a set of \\emph{linear functional constraints}.\r\n\r\n    \\textbf{Given:} $A \\in \\R^{m\\times n}, b \\in \\R^m, c\\in R^n$\r\n\r\n    \\textbf{Find:} $x^* \\in \\R^n$ where $x^* = \\arg\\max\\{c^Tx \\mid Ax \\leq b\\}$\r\n\\end{defi}\r\n\r\n\\begin{bonus}{Linear Programming Solvers}\r\n    Software that solves linear programs - \\emph{linear programming solvers} - also generate lots of important auxiliary information (as well as the optimum):\r\n    \\begin{itemize}\r\n        \\item sensitivity analysis\r\n        \\item shadow prices\r\n        \\item alternative optima\r\n        \\item \\ldots\r\n    \\end{itemize}\r\n\\end{bonus}\r\n\r\n\\begin{theo}{Ellipsoid Method}\r\n    A LP of dimension $n$ can be solved in $\\bigo(L^2 \\cdot n^6)$ time \\cite{khachiyan1979}, where $L =$ \\# bits in the input.\r\n\\end{theo}\r\n\r\n\\begin{theo}{Interior Point Method}\r\n    A LP of dimension $n$ can be solved in a \\emph{numerically stable} way in $\\bigo(L^2 \\cdot n^{3.5})$ time \\cite{karmarkar1984}.\r\n\\end{theo}\r\n\r\n\\begin{defi}{Integer Linear Programs (ILP)}\r\n    \\textbf{Given:} $A \\in \\R^{m\\times n}, b \\in \\R^m, c\\in R^n$\r\n\r\n    \\textbf{Find:} $\\underline{x^*\\in\\Z^n}$ where $x^* = \\arg\\max\\{c^Tx \\mid Ax \\leq b\\}$\r\n\\end{defi}\r\n\r\n\\begin{example}{Integer Linear Program for \\textsc{Vertex Cover}}\r\n    \\fbox{\r\n        \\parbox{0.95\\textwidth}{\r\n            \\underline{\\textsc{Vertex Cover}}\r\n\r\n\r\n            \\textbf{Given:} Graph $G = (V, E)$\\\\\r\n            \\textbf{Find:} \\textsc{Vertex Cover}, i.e. $V' \\subseteq V$ such that every edge has at least one endpoint in $V'$.\r\n        }\r\n    }\r\n\r\n    \\textbf{Integer Linear Program:}\r\n\r\n    For $v\\in V$, let $x_v \\in \\{0, 1\\}$.\r\n\r\n    Goal: minimize $\\sum_{v\\in V}x_v$.\r\n\r\n    Constraints: for every edge $uv \\in E$, we require $x_u + x_v \\geq 1$.\r\n\\end{example}\r\n\r\n\\printbibliography\r\n\\end{document}\r\n", "meta": {"hexsha": "8e368e85df3e369f0c458843f7e6b7fea9bd148b", "size": 2339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "or/or.tex", "max_stars_repo_name": "pblan/matse-spicker", "max_stars_repo_head_hexsha": "50109dee722338bb79c70d922cc1adc04c35132d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-06-29T08:48:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T08:55:59.000Z", "max_issues_repo_path": "or/or.tex", "max_issues_repo_name": "pblan/matse-spicker", "max_issues_repo_head_hexsha": "50109dee722338bb79c70d922cc1adc04c35132d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-12-13T08:32:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:35:50.000Z", "max_forks_repo_path": "or/or.tex", "max_forks_repo_name": "pblan/matse-spicker", "max_forks_repo_head_hexsha": "50109dee722338bb79c70d922cc1adc04c35132d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-03-14T21:11:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T22:20:59.000Z", "avg_line_length": 30.3766233766, "max_line_length": 179, "alphanum_fraction": 0.6387345019, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6408934849135525}}
{"text": "\\section{Skipping}\n\\label{sec:skipping}\n\nHere we envisage how to copy a stack while ignoring a given\nitem. [\\emph{The progression is very slow on purpose.}]\n\n\\paragraph{First occurrence}\n\\label{def:linear_search}\n\\index{stack!skipping an item!first occurrence}\n\nLet us suppose that \\(\\fun{sfst}(s,x)\\)\\index{sfst@\\fun{sfst/2}|(}\n(\\emph{skip the first occurrence}) evaluates in a stack identical\nto~\\(s\\) but without the first occurrence of~\\(x\\), starting from the\ntop. In particular, if~\\(x\\) is absent in~\\(s\\), then the value of the\ncall is identical to~\\(s\\). This is our\n\\emph{specification}.\\index{specification} For instance, we expect the\nfollowing evaluations:\\label{sfst_ex}\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,3) & \\twoheadrightarrow & \\el;\\\\\n\\fun{sfst}(\\el,\\el) & \\twoheadrightarrow & \\el;\\\\\n\\fun{sfst}([3,\\el],[5,2]) & \\twoheadrightarrow & [3,\\el];\\\\\n\\fun{sfst}([\\el,[1,2],4,\\el,4],4) & \\twoheadrightarrow &\n  [\\el,[1,2],\\el,4];\\\\\n\\fun{sfst}([4,[1,2],\\el,\\el,4],\\el)\n & \\twoheadrightarrow & [4,[1,2],\\el,4].\n\\end{array}\n\\end{equation*}\n\n\\paragraph{First attempt}\n\nLet us try a direct approach. In particular, at this point, it is\nimportant \\emph{not} to seek a definition in tail form. Tail form must\nbe considered as an optimisation and early optimisation is opening\nPandora's jar. The first idea that may come to mind is to define an\nauxiliary function \\fun{mem/2} such that the call \\(\\fun{mem}(s,x)\\)\nchecks whether a given item \\(x\\)~is in a given stack~\\(s\\), because\nthat notion of membership is implicit in the wording of the\nspecification. But two problems then arise. Firstly, what would be the\nresult of such a function? Secondly, what would be the additional cost\nfor using it? For the sake of the argument, let us follow this track\nand find out how where it leads. A stack can either be empty or not,\nso let us make two rules:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nNote that we introduced a variable~\\(y\\), distinct from\nvariable~\\(x\\). \\emph{Two different variables may or may not denote\n  the same value, but two occurrences of the same variable always\n  denote the same value.} Had we written instead\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{mem}(\\cons{\\underline{x}}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\none case would be missing, namely when the top of the stack is not the\nitem sought for, for instance, \\(\\fun{mem}(3,[4])\\) would fail due to\na match failure. Now, what is the first right\\hyp{}hand side? The\nfirst pattern matches only if the stack is empty. In particular, this\nmeans that the item is not in the stack, since, by definition, an\nempty stack is a stack containing no item. How do we express that?\nSince the original problem is silent on the matter, it is said to be\n\\emph{underspecified}.\\index{underspecification} We may think that\nzero would be a token of choice to denote the absence of the item in\nthe stack:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & 0;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nBut this would be a mistake because there is no natural and necessary\nrelationship between the concept of emptiness and the number\nzero. Zero is best understood algebraically as the number noted~\\(0\\)\nsuch that \\(0 + n = n + 0 = n\\), for any number~\\(n\\). Then, let us\ntry the empty stack:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\el;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nThe next step is to find a way to actually compare the value of~\\(x\\)\nto the value of~\\(y\\). We can use the rule above about variables: two\noccurrences of the same variable mean that they hold the same\nvalue. Therefore\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\el;\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nwas not so bad, after all? Indeed, but we know now that a case is\nmissing, so let us add it at the end, where \\(x \\neq y\\):\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\el;\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\rightarrow & \\fbcode{CCCCC};\\\\\n\\underline{\\fun{mem}(\\cons{y}{s},x)} & \\rightarrow & \\fbcode{CCCCC}.\n\\end{array}\n\\end{equation*}\nNow, what is the second right\\hyp{}hand side? It is evaluated if the\nitem we were looking for is present at the top of the stack. How do we\nexpress that? We may think of ending with the item itself, the\nrationale being that if the result is the empty stack, then the item\nis not in the input stack, otherwise the result is the item itself:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\el;\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\rightarrow & x;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nThe last right\\hyp{}hand side is easier to guess since it deals with\nthe case where the top of the stack (\\(y\\)) is not the item we seek\n(\\(x\\)), so a recursive call which ignores~\\(y\\) should come to mind:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x) & \\rightarrow & \\el;\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\rightarrow & x;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\rightarrow & \\fun{mem}(s,x).\n\\end{array}\n\\end{equation*}\n\nSome tests would increase the confidence that this definition is\ncorrect\\index{soundness} and complete\\index{completeness} with respect\nto the specification. Let us label the rules first:\n\\begin{equation*}\n\\begin{array}{r@{\\;}c@{\\;}l}\n\\fun{mem}(\\el,x)         & \\smashedrightarrow{\\zeta}  & \\el;\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\smashedrightarrow{\\eta}   & x;\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\smashedrightarrow{\\theta} &\n\\fun{mem}(s,x).\n\\end{array}\n\\end{equation*}\nThen we could try the following cases:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l@{\\;}l@{\\;}l}\n\\fun{mem}(\\el,3) & \\smashedrightarrow{\\zeta} & \\el,\\\\\n\\fun{mem}([1],3) & \\smashedrightarrow{\\theta} & \\fun{mem}(\\el,3)\n& \\smashedrightarrow{\\zeta} & \\el,\\\\\n\\fun{mem}([1,3,2],3) & \\smashedrightarrow{\\theta} & \\fun{mem}([3,2],3)\n& \\smashedrightarrow{\\eta} & 3.\n\\end{array}\n\\end{equation*}\nThe code seems to work: item~\\(x\\) is in stack~\\(s\\) if the result\nis~\\(x\\), otherwise it is~\\(\\el\\). However, this function is not\ncorrect.\\index{soundness} The hidden and flawed assumption is ``items\ncan not be stacks'', in spite of the counter\\hyp{}examples given at\nthe beginning for illustrating the expected behaviour of\n\\fun{sfst/2}. In particular, an item can be the empty stack and this\nsituation leads to an ambiguity with our definition of \\fun{mem/2}:\n\\begin{equation*}\n  \\fun{mem}(\\el,\\el) \\smashedrightarrow{\\zeta} \\el \\xleftarrow{\\smash{\\eta}} \\fun{mem}([\\el],\\el).\n\\end{equation*}\nIt is impossible to discriminate the two cases, the first one meaning\nabsence of the item and the second presence, because they both end\nwith the empty stack. In fact, we should have distinguished two data\nconstructors to denote the outcomes ``the item was found'' and ``the\nitem was not found''. For example,\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mem}(\\el,x)         & \\smashedrightarrow{\\zeta}  & \\fun{false}();\\\\\n\\fun{mem}(\\cons{x}{s},x) & \\smashedrightarrow{\\eta}   & \\fun{true}();\\\\\n\\fun{mem}(\\cons{y}{s},x) & \\smashedrightarrow{\\theta} & \\fun{mem}(s,x).\n\\end{array}\n\\end{equation*}\nBut, for now, let us backtrack and ask ourselves again whether using\n\\fun{mem/2} is really a good idea.\n\n\\paragraph{Better approach}\n\nLet us suppose that the input stack contains the item at the\nbottom. Using \\fun{mem/2} to find it leads to a complete traversal of\nthe input stack. Then another traversal from the beginning (the top of\nthe stack) is needed to copy the stack without its last item, so, in\ntotal, two complete traversals are performed.\n\nA better idea consists in \\emph{interleaving} these two passes into\none because the problem stems from the fact that \\fun{mem/2} forgets\nabout the items which are not the item of interest, thus, when it is\nfound or known to be absent, there is no way to build a copy to make\nthe result. By interleaving, we mean that during the traversal, the\nconcepts of membership and of copying are combined, instead of being\nused sequentially as two function calls. A similar situation was\nencountered in the design of a function reversing a stack:\n\\fun{rev\\(_0\\)/1}, which calls \\fun{cat/2}, is much slower than\n\\fun{rev/1}, which uses an auxiliary stack.\n\nHere, our algorithm consists in memorising all visited items and, if\nthe item is not found, the resulting stack is rebuilt from them; if\nfound, the result is built from them \\emph{and} the remaining,\nunvisited, items. There are usually two ways to keep visited items:\neither in an accumulative parameter, called \\emph{accumulator}, or in\nthe context of recursive calls. At this point, it is important to\nrecall a cardinal guideline: Do not try first to design a definition\nin tail form, but opt instead for a direct approach. In some simple\ncases, a direct approach may actually be in tail form, but the point\nis methodological: a priori ignore all concerns about tail\nforms. Accordingly, let us use the context of a recursive call to\nrecord the visited items. A stack being either empty or not, it is\nnatural to start with\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nThen, just as we tried with \\fun{mem/2}, we must distinguish the\ncase when \\(x\\)~is the same as~\\(y\\):\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\underline{\\fun{sfst}(\\cons{x}{s},x)} & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\nThis method is a \\emph{linear search}\\index{linear search}: the items\nin the stack are compared one by one to~\\(x\\), starting from the top,\nuntil the bottom or an item equal to~\\(x\\) is reached. Since we know\nthat the last rule deals with the case when \\(x \\neq y\\), we must\nmemorise~\\(y\\) and go on comparing~\\(x\\) with the other items in~\\(s\\)\n(if any). This is where the recursive call with a context, discussed\nabove, is set as \\(\\cons{y}{\\text{\\textvisiblespace}}\\):\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{sfst}(\\cons{x}{s},x) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\cons{y}{\\fun{sfst}(s,x)}.\n\\end{array}\n\\end{equation*}\nVery importantly, let us remark that the position of~\\(y\\) in the\nresult is the same as in the input (the top). The second rule\ncorresponds to the case where the item we are looking for,\nnamely~\\(x\\), is found to be the top of the current stack, which is a\nsubstack of the original input. A stack made of successive items from\nthe beginning of a given stack is called a \\emph{prefix} of the\nlatter. When a stack is a substack of another, that is, it is made of\nsuccessive items including the last, it is called a \\emph{suffix}. We\nknow that the~\\(x\\) in \\(\\cons{x}{s}\\) is the first occurrence\nof~\\(x\\) in the original stack (the one in the first call), because we\nwouldn't be dealing with this case \\emph{again}: the specification\nstates that this first occurrence must be absent from the resulting\nstack; since it is now at the top of a suffix, we just need to end\nwith~\\(s\\), \\emph{which we do not visit}:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x)         & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{sfst}(\\cons{x}{s},x) & \\rightarrow & \\underline{s}\\,;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\cons{y}{\\fun{sfst}(s,x)}\\,.\n\\end{array}\n\\end{equation*}\nThe first rule handles the case where we traversed the whole original\nstack (up to \\(\\el\\)) without finding~\\(x\\). Thus the result is simply\nthe empty stack because the empty stack without~\\(x\\) is the empty\nstack:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x)         & \\rightarrow & \\el;\\\\\n\\fun{sfst}(\\cons{x}{s},x) & \\rightarrow & s;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\cons{y}{\\fun{sfst}(s,x)}.\n\\end{array}\n\\end{equation*}\n\nLet us run some tests now and, in order avoid mistakes, it is handy to\nlabel the rules with some Greek letters:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el,x)          & \\smashedrightarrow{\\theta} & \\el;\\\\\n\\fun{sfst}(\\cons{x}{s},x)  & \\smashedrightarrow{\\iota}  & s;\\\\\n\\fun{sfst}(\\cons{y}{s},x)  & \\smashedrightarrow{\\kappa} &\n\\cons{y}{\\fun{sfst}(s,x)}.\n\\end{array}\n\\end{equation*}\nThe item is absent in~\\(\\theta\\), the item is found in~\\(\\iota\\) and\nthe search continues with~\\(\\kappa\\). Note that equality is implicitly\nmeant in non\\hyp{}linear rules like~\\(\\iota\\); in other words, the\ncost of such equality test is~\\(0\\) in our model. Also remark how\nimportant is for rule~\\(\\iota\\) to be written before~\\(\\kappa\\),\notherwise \\(\\iota\\)~would be useless (so\\hyp{}called \\emph{dead\n  code}\\index{functional language!dead code}). Here is an\nexample\\index{stack!skipping an item!example} of a successful search:\n\\begin{equation*}\n\\fun{sfst}([3,0,1,2],1) \\xrightarrow{\\smash{\\kappa}}\n\\cons{3}{\\fun{sfst}([0,1,2],1)} \\xrightarrow{\\smash{\\kappa}}\n\\cons{3,0}{\\fun{sfst}([1,2],1)} \\xrightarrow{\\smash{\\iota}} [3,0,2].\n\\end{equation*}\nNow an example of an unsuccessful\\index{stack!skipping an\n  item!example} search:\n\\begin{equation*}\n\\fun{sfst}([3,0],4) \\xrightarrow{\\smash{\\kappa}}\n\\cons{3}{\\fun{sfst}([0],4)} \\xrightarrow{\\smash{\\kappa}}\n\\cons{3,0}{\\fun{sfst}(\\el,4)} \\xrightarrow{\\smash{\\theta}}\n[3,0].\n\\end{equation*}\nMore complicated examples, given \\vpageref{sfst_ex}, yield\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}([4,[1,2],\\el,\\el,4],\\el)\n& \\smashedrightarrow{\\kappa} &\n  [4|\\fun{sfst}([[1,2],\\el,\\el,4],\\el)]\\\\\n& \\smashedrightarrow{\\kappa} &\n  [4|[[1,2]|\\fun{sfst}([\\el,\\el,4],\\el)]]\\\\\n& = & [4,[1,2]|\\fun{sfst}([\\el,\\el,4],\\el)]\\\\\n& \\smashedrightarrow{\\iota} & [4,[1,2]|[\\el,4]]\\\\\n& = & [4,[1,2],\\el,4].\n\\end{array}\n\\end{equation*}\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}([3,\\el],[5,2])\n& \\smashedrightarrow{\\kappa} & [3|\\fun{sfst}([\\el],[5,2])]\\\\\n& \\smashedrightarrow{\\kappa} & [3|[\\el|\\fun{sfst}(\\el,[5,2])]]\\\\\n& = & [3,\\el|\\fun{sfst}(\\el,[5,2])]\\\\\n& \\smashedrightarrow{\\theta} & [3,\\el|\\el]\\\\\n& = & [3,\\el].\n\\end{array}\n\\end{equation*}\nOnce we are convinced that our definition is correct\\index{soundness}\nand complete with respect to the specification, there is a little\nextra worth testing: we can check \\emph{what happens for inputs which\n  are not expected by the specification.} Our specification says at\none point that the second argument of \\fun{sfst/2} is a stack. What\nhappens if we supply an integer instead? For example, we have\n\\(\\fun{sfst}(3,\\el) \\nrightarrow\\). We have a match failure, that is,\nthe rewrites are stuck, so that our definition is not\n\\emph{robust},\\index{robustness} in other words, it fails abruptly on\nunspecified inputs.\n\nWhen programming in the small, as we do here, robustness is usually\nnot a concern because we want to focus on learning a language by\nexpressing simple algorithms, but when developing large applications,\nwe must take care of making the code robust by catching and signalling\nerrors. Notice that a program can be complete\\index{completeness} but\nnot robust,\\index{robustness} because completeness is relative to\nwhat is specified behaviour (all valid inputs must be accepted and not\nlead to an error), whereas robustness is relative to what is left\nunspecified.\n\nThese considerations are germane to discussing the merits and\nweaknesses of scripting languages, whose semantics try hard to ignore\nerrors by defaulting on special values (like the empty string) to keep\nrunning. In the setting of our abstract functional language, we can\nuse a data constructor, that is, a function without evaluation rules,\nlike \\(\\fun{error}()\\), to signal an error or notify some piece of\ninformation about the arguments. For instance, here is the definition\nof a function which distinguishes between stacks and non\\hyp{}stack\narguments:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{is\\_a\\_stack}(\\el) & \\rightarrow & \\fun{yes}();\\\\\n\\fun{is\\_a\\_stack}(\\cons{x}{s}) & \\rightarrow & \\fun{yes}();\\\\\n\\fun{is\\_a\\_stack}(s) & \\rightarrow & \\fun{no}().\n\\end{array}\n\\end{equation*}\nData constructors come handy in signalling errors because they are\nlike unique identifiers, therefore they cannot be confused with any\nother kind of data the function computes and so can be detected easily\nby the caller. Consider this robust\\index{robustness} version of\n\\fun{sfst/2} which discriminates errors:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}(\\el, x) & \\rightarrow & \\el;\\\\\n\\fun{sfst}(\\cons{x}{s},x) & \\rightarrow & s;\\\\\n\\fun{sfst}(\\cons{y}{s},x) & \\rightarrow & \\cons{y}{\\fun{sfst}(s,x)};\\\\\n\\fun{sfst}(s,x) & \\rightarrow & \\underline{\\fun{error}()}.\n\\end{array}\n\\end{equation*}\nThen a function calling \\fun{sfst/2} can make the difference between a\nnormal rewrite and an error by using a data constructor in a pattern:\n\\begin{equation*}\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{caller}(s,x) & \\rightarrow & \\fun{check}(\\fun{sfst}(s,x)).\\\\\n\\fun{check}(\\fun{error}()) & \\rightarrow & \\fbcode{CCCCC}\\,;\\\\\n\\fun{check}(r) & \\rightarrow & \\fbcode{CCCCC}\\,.\n\\end{array}\n\\end{equation*}\n%%% END\n\n\\paragraph{Cost}\n\nIn general, the cost\n\\(\\C{\\fun{sfst}}{n}\\)\\index{sfst@$\\C{\\fun{sfst}}{n}$|(} of\n\\(\\fun{sfst}(s,x)\\), where \\(n\\)~is the length of~\\(s\\), depends\non~\\(x\\) being present in~\\(s\\) or not. In the latter case, the trace\nis \\(\\kappa^n\\theta\\), so \\(\\C{\\fun{sfst}}{n} = \\len{\\kappa^n\\theta} =\nn + 1\\). If the former, the cost depends on the position of~\\(x\\)\nin~\\(s\\). Let us set that the top of~\\(s\\) is at position~\\(0\\) and\n\\(x\\)~occurs at position~\\(j\\). We then have \\(\\C{\\fun{sfst}}{n,j} =\n\\len{\\kappa^j\\iota} = j + 1\\)\\index{sfst@$\\C{\\fun{sfst}}{n}$|)}. If we\ndecide that position~\\(n\\) (or greater) means absence, we can actually\nretain the last formula for both cases.\n\nThe minimum cost \\(\\B{\\fun{sfst}}{n}\\)\\index{sfst@$\\B{\\fun{sfst}}{n}$}\nis then the minimum\\index{stack!skipping an item!minimum cost} value\nof \\(\\C{\\fun{sfst}}{n,j}\\), for \\(j\\)~ranging from \\(0\\)~to~\\(n\\),\ntherefore \\(\\B{\\fun{sfst}}{n} = \\C{\\fun{sfst}}{n,0} = 1\\), that is,\nwhen the item occurs at the top, and, dually, the maximum\ncost\\index{stack!skipping an item!maximum cost}\nis\\index{sfst@$\\W{\\fun{sfst}}{n}$} \\(\\W{\\fun{sfst}}{n} =\n\\C{\\fun{sfst}}{n,n} = n + 1\\), that is, when the item is absent. The\naverage cost\n\\(\\M{\\fun{sfst}}{n}\\)\\index{sfst@$\\M{\\fun{sfst}}{n}$}\\index{stack!skipping\n  an item!average cost} of a successful search assumes that \\(j\\)~can\ntake all the positions in the stack:\n\\begin{equation*}\n  \\M{\\fun{sfst}}{n} = \\frac{1}{n}\\sum_{j=0}^{n-1}\\C{\\fun{sfst}}{n,j} =\n  \\frac{1}{n}\\sum_{j=0}^{n-1}(j+1) = \\frac{1}{n}\\sum_{j=0}^{n}j\n  = \\frac{n+1}{2} \\sim \\frac{n}{2},\n\\end{equation*}\nby equation~\\eqref{eq:sum_k} \\vpageref{eq:sum_k}.\n\nNotice that rule~\\(\\kappa\\) implies the creation of a\n(\\texttt{|})\\hyp{}node, which we call\n\\emph{cons\\hyp{}node}\\index{cons-node}, as shown in\n\\fig~\\vref{fig:sfst_dag}.\n\\begin{figure}\n\\centering\n\\includegraphics[bb=71 664 345 721]{sfst_dag}\n\\caption{Directed acyclic graphs for \\fun{sfst/2}\n\\label{fig:sfst_dag}}\n\\end{figure}\nHence, whilst the contents of the new stack is shared with the\noriginal stack, \\(j\\)~nodes are newly allocated if~\\(x\\) occurs at\nposition~\\(j\\) in~\\(s\\). The worst case happens when \\(x\\)~is absent\nso the memory\\index{stack!skipping an item!memory} needed amounts to\n\\(n\\)~nodes, all of which being useless because in this case\n\\(\\fun{sfst}(s,x) \\equiv s\\). If we want to avoid this situation,\nanother definition of \\fun{sfst/2} has to be devised, one that\ndiscards all constructed nodes and allows us to reference the input\nwhen~\\(x\\) is missing.\n\nThe crux of the matter is embodied in the construct\n\\(\\cons{y}{\\texttt{\\textvisiblespace}}\\) of rule~\\(\\kappa\\), called\nthe \\emph{context}\\index{functional language!context of a call} of the\ncall \\(\\fun{sfst}(s,x)\\)\\index{sfst@\\fun{sfst/2}|)}, which we want\nif~\\(x\\) is present, but not otherwise. To resolve this conflicting\nrequirement, we opt for removing the context and store the information\nit contains (\\(y\\)) into an accumulator\\index{functional\n  language!accumulator}, in a new rule~\\(\\xi\\) derived\nfrom~\\(\\kappa\\). We use the accumulator in a new rule~\\(\\nu\\) derived\nfrom~\\(\\iota\\). The new \\fun{sfst/2} is called\n\\fun{sfst\\(_0\\)/2}\\index{sfst0@\\fun{sfst\\(_0\\)/2}} and is shown in\n\\fig~\\ref{fig:sfst0}.\\index{sfst@\\fun{sfst/4}}\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n\\fun{rcat}(\\el,t)              & \\xrightarrow{\\smash{\\zeta}} & t; &\n\\fun{sfst}(\\el,x,t,u)          & \\xrightarrow{\\smash{\\mu}} & u;\\\\\n\\fun{rcat}(\\cons{x}{s},t)      & \\xrightarrow{\\smash{\\eta}}\n                               & \\fun{rcat}(s,\\cons{x}{t}). &\n\\fun{sfst}(\\cons{x}{s},x,t,u)  & \\xrightarrow{\\smash{\\nu}}\n                               & \\fun{rcat}(t,s);\\\\\n\\fun{sfst}_0(s,x)              & \\xrightarrow{\\smash{\\lambda}}\n                               & \\fun{sfst}(s,x,\\el,s). &\n\\fun{sfst}(\\cons{y}{s},x,t,u)  & \\xrightarrow{\\smash{\\xi}}\n                               & \\fun{sfst}(s,x,\\cons{y}{t},u).\n\\end{array}}\n\\end{equation*}\n\\caption{Skipping the first occurrence with maximum sharing\n\\label{fig:sfst0}}\n\\end{figure}\nOf course, whilst in~\\(\\iota\\) we just referenced~\\(s\\), the\nconstruction corresponding to the now missing context of~\\(\\kappa\\)\nmust be performed by~\\(\\nu\\). Also, we must add another argument which\nrefers to the original stack, so we can use it in a new rule~\\(\\mu\\),\nthe pendant of~\\(\\theta\\). Note the shapes of the right\\hyp{}hand\nsides: they are either a value~(\\(\\zeta\\) and~\\(\\mu\\)) or a function\ncall whose arguments contain values. In other words, no function call\nhas a context.\n\nThis syntactic property of a definition is named \\emph{tail\n  form}\\index{functional language!tail form}. Intuitively, the\npractical consequence of such a form is that terminating calls unfold\nuntil a value is reached and nothing else is left to be done:\n\\emph{the value of the last call is the value of the first call}. This\nkind of definition enables the sharing in rule~\\clause{\\mu}, where\n\\(u\\) (the reference to the original stack) becomes the value, instead\nof \\(\\fun{rev}(t)\\).\n\nImplementations of functional language often use this property to\noptimise the evaluation, as we shall see in the last part of this\nbook. The downside of \\fun{sfst\\(_0\\)/2} with respect to \\fun{sfst/2}\nis the additional cost incurred by having to reverse~\\(t\\) in\nrule~\\clause{\\nu}, that is, the call \\(\\fun{rcat}(t,s)\\). More\nprecisely, there are two complementary cases: either \\(x\\)~is missing\nin~\\(s\\) or \\(x\\)~occurs in~\\(s\\). Let us assume that \\(s\\)~contains\n\\(n\\)~items and \\(x\\)~is absent in~\\(s\\). The evaluation trace\n\\index{functional language!evaluation!trace} of the call\n\\(\\fun{sfst}_0(s,x)\\) is \\(\\lambda\\xi^n\\mu\\), so\n\\begin{equation*}\n  \\C{\\fun{sfst}_0}{n}\n= \\len{\\lambda\\xi^n\\mu} = \\len{\\lambda} + n \\len{\\xi} + \\len{\\mu} = n\n+ 2.\n\\end{equation*}\nLet us now assume that \\(x\\)~occurs at position \\(k\\) in~\\(s\\),\nwith the first item having position~\\(0\\). The evaluation trace is\nthen \\(\\lambda \\xi^{k}\\nu\\eta^k\\zeta\\), hence\n\\begin{equation*}\n  \\C{\\fun{sfst}_0}{n,k} = \\len{\\lambda \\xi^{k}\\nu\\eta^k\\zeta} = 2k + 3.\n\\end{equation*}\nClearly now,\n\\begin{align*}\n\\B{\\fun{sfst}_0}{0} & = 2,\\\\\n\\B{\\fun{sfst}_0}{n} & = \\min_{0 \\leqslant k < n}\\{\\C{\\fun{sfst}_0}{n}, \\C{\\fun{sfst}_0}{n,k}\\}\n                    = \\min_{0 \\leqslant k < n}\\{n+2,2k+3\\} = 3,\\\\\n\\W{\\fun{sfst}_0}{n} & = \\max_{0 \\leqslant k < n}\\{n+2,2k+3\\} = 2n+1,\n\\end{align*}\nwhere the minimum cost occurs when the item is the top of the stack;\nthe maximum cost happens when the sought item is last in the stack (at\nthe bottom).\n\nSince calling \\fun{rcat/2}\\index{rcat@\\fun{rcat/2}} to reverse the\nvisited items is the source of the extra cost, we might try to\nmaintain the order of these items in \\fig~\\vref{fig:sfst1}\\index{sfst1@\\fun{sfst\\(_1\\)/1}}\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{sfst}_1(s,x)               & \\rightarrow\n                                & \\fun{sfst}_2(s,x,\\el,s).\\\\\n\\fun{sfst}_2(\\el,x,t,u)         & \\rightarrow & u;\\\\\n\\fun{sfst}_2(\\cons{x}{s},x,t,u) & \\rightarrow & \\fun{cat}(t,s);\\\\\n\\fun{sfst}_2(\\cons{y}{s},x,t,u) & \\rightarrow\n                                & \\fun{sfst}_2(s,x,\\fun{cat}(t,[y]),u).\n\\end{array}}\n\\end{equation*}\n\\caption{Skipping the first occurrence (bad design)\n\\label{fig:sfst1}}\n\\end{figure}\nbut using stack catenation instead of pushing. The problem is that the\nlast rule of \\fun{sfst\\(_2\\)/4}\\index{sfst@\\fun{sfst\\(_2\\)/4}}\n\\index{cat@\\fun{cat/2}} yields\n\\(\\fun{cat}(\\dots\\fun{cat}(\\fun{cat}(\\el,[x_1]),[x_2])\\dots)\\), whose\ncost we know to be quadratic \\index{cost!quadratic $\\sim$} as in the\nrewrite~\\eqref{eq:rev0}\n\\vpageref{eq:rev0}\\index{rev0@\\fun{rev\\(_0\\)/1}}, from which we can\nquickly conclude that \\(\\W{\\fun{sfst}_1}{n} \\sim \\tfrac{1}{2}n^2\\).\n\n\\paragraph{Last occurrence}\n\\index{stack!skipping an item!last occurrence}\n\nLet us suppose that \\(\\fun{slst}(s,x)\\)\\index{slst@\\fun{slst/2}}\n(\\emph{skip the last occurrence}) evaluates in a stack identical\nto~\\(s\\) but without the last occurrence of~\\(x\\). In particular,\nif~\\(x\\) is absent in~\\(s\\), then the value of the call is identical\nto~\\(s\\). The first design that may come to mind is to see this\nproblem as the dual problem of ignoring the first occurrence:\n\\begin{equation}\n\\fun{slst}_0(s,x) \\xrightarrow{\\smash{\\pi}}\n                  \\fun{rev}(\\fun{sfst}(\\fun{rev}(s),x)).\n\\label{eq:slst0}\n\\end{equation}\nIf~\\(x\\) is missing in~\\(s\\), we\nhave\\index{slst0@$\\C{\\fun{slst}_0}{n}$}\\index{rev@$\\C{\\fun{rev}}{n}$}\n\\(\\C{\\fun{slst}_0}{n} = 1 + \\C{\\fun{rev}}{n} + \\W{\\fun{sfst}}{n} +\n\\C{\\fun{rev}}{n} = 3n+6\\). If~\\(x\\) occurs in~\\(s\\) at position~\\(k\\),\n\\(\\C{\\fun{slst}_0}{n,k} = 1 + \\C{\\fun{rev}}{n} +\n\\C{\\fun{sfst}}{n,n-k-1} + \\C{\\fun{rev}}{n-1} = 3n - k +\n4\\). Therefore, we can derive the minimum and\nmaximum\\index{stack!skipping an item!minimum\n  cost}\\index{stack!skipping an item!maximum cost} costs:\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\B{\\fun{slst}_0}{n} = \\min_{k < n}\\{3n+6,3n-k+4\\} = 2n + 5,\n\\end{equation*}\nwhen\\index{slst@$\\B{\\fun{slst}_0}{n}$} \\(x\\)~is last in~\\(s\\), and\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\W{\\fun{slst}_0}{n} = \\max_{k < n}\\{3n+6,3n-k+4\\} = 3n+6,\n\\end{equation*}\nwhen\\index{slst@$\\W{\\fun{slst}_0}{n}$} \\(x\\)~is missing in~\\(s\\).  The\nmean cost\\index{stack!skipping an item!average\n  cost}\\index{slst@$\\M{\\fun{slst}_0}{n}$} when \\(x\\)~is present is\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\M{\\fun{slst}_0}{n} = \\frac{1}{n}\\sum_{k=0}^{n-1}\\C{\\fun{slst}_0}{n,k}\n                    = \\frac{1}{n}\\sum_{k=0}^{n-1}(3n - k + 4)\n                    = \\frac{5n+9}{2} \\sim \\frac{5}{2}n.\n\\end{equation*}\nWhen \\(x\\)~is present, the worst case is when it is the top of the\nstack: \\(\\W{\\fun{slst}_0}{n} = \\max_{k<n}\\{3n - k + 4\\} = 3 n+ 4\n\\leqslant 3n + 6\\).\n\nIn any case, the maximum cost is asymptotically equivalent to~\\(3n\\),\nthat is, three complete traversals of~\\(s\\) are performed, whilst the\nabsence of~\\(x\\) could be detected with one. Dually, the minimum cost\nis asymptotically equivalent to~\\(2n\\), accounting for two full\ntraversals, whilst \\(x\\)~being the last item could be assessed with\none. All this suggests that a better design is worth thinking about.\n\nConsider \\fig~\\ref{fig:slst},\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{slst}(\\el,x)           & \\xrightarrow{\\smash{\\rho}} & \\el;\n& \\fun{slst}(\\el,x,t)         & \\xrightarrow{\\smash{\\upsilon}} & t;\\\\\n  \\fun{slst}(\\cons{x}{s},x)   & \\xrightarrow{\\smash{\\sigma}} &\n                                           \\fun{slst}(s,x,s);\n& \\fun{slst}(\\cons{x}{s},x,t) & \\xrightarrow{\\smash{\\phi}} &\n                                           \\cons{x}{\\fun{slst}(t,x)};\\\\\n  \\fun{slst}(\\cons{y}{s},x)   & \\xrightarrow{\\smash{\\tau}} &\n                                           \\cons{y}{\\fun{slst}(s,x)}.\n& \\fun{slst}(\\cons{y}{s},x,t) & \\xrightarrow{\\smash{\\chi}} &\n                                           \\fun{slst}(s,x,t).\n\\end{array}}\n\\end{equation*}\n\\caption{Skipping the last occurrence with \\fun{slst/2}\n\\label{fig:slst}\\index{stack!skipping an item!last occurrence}}\n\\end{figure}\nwhere, with a linear search\\index{linear search} (rules\n\\(\\rho\\)~and~\\(\\tau\\)), we find the first occurrence of~\\(x\\)\n(rule~\\(\\sigma\\)), but, in order to check whether it is also the last,\nanother linear search has to be run~(\\(\\chi\\)). If it is successful\n(\\(\\phi\\)), we retain the occurrence find earlier (\\(x\\)) and resume\nanother search; if it is unsuccessful~(\\(\\upsilon\\)), the~\\(x\\) found\nearlier was indeed the last occurrence.  Notice how we have two\nmutually recursive functions, \\fun{slst/2}\\index{slst@\\fun{slst/2}}\nand~\\fun{slst/3}\\index{slst@\\fun{slst/3}}. The definition of the\nlatter features a third parameter, \\(t\\), which is a copy of the\nstack~\\(s\\) when an occurrence of~\\(x\\) was found\nby~\\fun{slst/2}\\index{slst@\\fun{slst/2}} (\\(\\sigma\\)). This copy is\nused to resume~(\\(\\phi\\)) the search from where the previous\noccurrence was found. This is necessary as \\(y\\) in rule~\\(\\chi\\) must\nbe discarded because we do not know at that point whether the\nprevious~\\(x\\) was the last. Consider \\fig~\\vref{fig:slst_27071}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{slst}([2,7,0,7,1],7)\n& \\xrightarrow{\\smash{\\tau}}\n& \\cons{2}{\\fun{slst}([7,0,7,1],7)}\\\\\n& \\xrightarrow{\\smash{\\sigma}}\n& \\cons{2}{\\fun{slst}([0,7,1],7,[0,7,1])}\\\\\n& \\xrightarrow{\\smash{\\chi}}\n& \\cons{2}{\\fun{slst}([7,1],7,[0,7,1])}\\\\\n& \\xrightarrow{\\smash{\\phi}}\n& \\cons{2,7}{\\fun{slst}([0,7,1],7)}\\\\\n& \\xrightarrow{\\smash{\\tau}}\n& \\cons{2,7,0}{\\fun{slst}([7,1],7)}\\\\\n& \\xrightarrow{\\smash{\\sigma}}\n& \\cons{2,7,0}{\\fun{slst}([1],7,[1])}\\\\\n& \\xrightarrow{\\smash{\\chi}}\n& \\cons{2,7,0}{\\fun{slst}(\\el,7,[1])}\\\\\n& \\xrightarrow{\\smash{\\upsilon}}\n& \\cons{2,7,0}{[1]} = [2,7,0,1].\n\\end{array}}\n\\end{equation*}\n\\caption{\\(\\fun{slst}([2,7,0,7,1],7) \\twoheadrightarrow\n  [2,7,0,1]\\)\\label{fig:slst_27071}\\index{stack!skipping an item!example}}\n\\end{figure}\nIf the item is missing, the linear search fails as usual with a cost\nof \\(\\len{\\tau^n\\rho} = n + 1\\). Otherwise, let us name \\( 0 \\leqslant\nx_1 < x_2 < \\dots < x_p < n\\) the positions of the \\(p\\)~occurrences\nof~\\(x\\) in~\\(s\\). The evaluation trace\\index{functional\n  language!evaluation!trace} is\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\tau^{x_1}\n\\cdot\n\\prod_{k=2}^{p}(\\sigma\\chi^{x_k-x_{k-1}-1})(\\phi\\tau^{x_k-x_{k-1}-1})\n\\cdot\n(\\sigma\\chi^{n-x_p-1}\\upsilon),\n\\end{equation*}\nwhose length is \\(x_1 + 2\\sum_{k=2}^{p}(x_k-x_{k-1}) + (n - x_p + 1) =\nn + x_p - x_1 + 1\\). In other words, if the position of the first\noccurrence is noted~\\(f\\) and the position of the last is~\\(l\\), we\nfind that\\index{slst@$\\C{\\fun{slst}}{n}$}\n\\begin{equation*}\n\\C{\\fun{slst}}{n,f,l} = n + l - f + 1.\n\\end{equation*}\nWe deduce that the minimum cost\\index{stack!skipping an item!minimum\n  cost} happens when \\(l-f+1 = p\\), that is, when all the occurrences\nare consecutive, so \\(\\B{\\fun{slst}}{n,p} = n +\np\\)\\index{slst@$\\B{\\fun{slst}}{n}$}. The maximum\ncost\\index{stack!skipping an item!maximum cost} occurs when~\\({f=0}\\)\nand~\\({l=n-1}\\), that is, when there is at least two occurrences\nof~\\(x\\), one at the top and one at the bottom: \\(\\W{\\fun{slst}}{n} =\n2n\\)\\index{slst@$\\W{\\fun{slst}}{n}$}. We can check that when the stack\nis entirely made of~\\(x\\), minimum and maximum costs concur\nin~\\(2n\\). The average cost\\index{stack!skipping an item!average cost}\n\\index{slst@$\\M{\\fun{slst}}{n}$} when \\(x\\)~is present requires\ndetermining the cost for every possible pair \\((f,l)\\), with \\(0\n\\leqslant f \\leqslant l < n\\):\n\\begin{align*}\n\\M{\\fun{slst}}{n}\n  &= \\frac{2}{n(n+1)} \\sum_{f=0}^{n-1}\\sum_{l=f}^{n-1}{\\C{\\fun{slst}}{n,f,l}}\n   = \\frac{2}{n(n+1)} \\sum_{f=0}^{n-1}\\sum_{l=f}^{n-1}{(n+l-f+1)}\\\\\n  &= \\frac{2}{n(n+1)} \\sum_{f=0}^{n-1}\\bigg(\\!\\!(n-f+1)(n-f)\n     + \\!\\!\\sum_{l=0}^{n-f-1}\\!\\!(l+f)\\!\\!\\bigg)\\\\\n  &= \\frac{1}{n(n+1)}\\sum_{f=0}^{n-1}(3n + 1 - f)(n-f)\\\\\n  &= \\frac{n(3n+1)}{n+1} - \\frac{4n+1}{n(n+1)}\\sum_{f=0}^{n-1}f\n     + \\frac{1}{n(n+1)}\\sum_{f=0}^{n-1}f^2\n  = \\frac{4}{3}{n} + \\frac{2}{3} \\sim \\frac{4}{3}n,\n\\end{align*}\nwhere \\(\\sum_{f=0}^{n-1}{f} = n(n-1)/2\\) is equation~\\eqref{eq:sum_k},\n\\vpageref{eq:sum_k}, and the sum of the successive squares is obtained\nas follows. We use the \\emph{telescoping} or \\emph{difference} method\non the series \\((k^3)_{k>0}\\). We start with the equality \\((k+1)^3 =\nk^3 + 3k^2 + 3k + 1\\), hence \\((k+1)^3 - k^3 = 3k^2 + 3k + 1\\). Then\nwe can sum these differences, whose terms cancel out, leaving the\nfirst and the last:\n\\begin{align}\n  && (1+1)^3 - \\boxed{1^3} &= 3 \\cdot 1^2 + 3 \\cdot 1 + 1\\notag\\\\\n+ && (2+1)^3 - 2^3         &= 3 \\cdot 2^2 + 3 \\cdot 2 + 1\\notag\\\\\n+ &&&\\;\\;\\vdots\\notag\\\\\n+ && \\boxed{(n+1)^3} - n^3 &= 3n^2 + 3n + 1\\notag\n\\intertext{\\rule{\\linewidth}{0.4pt}}\n\\Rightarrow\n  &&\\boxed{(n+1)^3} - \\boxed{1^3}\n  &= 3 \\sum_{k=1}^{n}{k^2} + 3 \\sum_{k=1}^{n}{k} + n\\notag\\\\\n  && n^3 + 3n^2 + 3n\n  &= 3 \\sum_{k=1}^{n}{k^2} + 3 \\cdot \\frac{n(n+1)}{2} + n\\notag\\\\\n\\Leftrightarrow && \\sum_{k=1}^{n}{k^2} &= \\frac{n(n+1)(2n+1)}{6}.\n\\label{eq:sum_of_squares}\n\\end{align}\n\n\\paragraph{Exercises}\n\\begin{enumerate}\n\n  \\item Prove that \\(\\fun{sfst/2} = \\fun{sfst\\(_0\\)/2}\\).\n    \\index{sfst@\\fun{sfst/2}}\\index{sfst0@\\fun{sfst\\(_0\\)/2}}\n\n  \\item Show that \\(\\B{\\fun{sfst}_0}{n} = 3\\), \\(\\W{\\fun{sfst}_0}{n} =\n    2n+1\\) and \\(\\M{\\fun{sfst}_0}{n} = n+2\\) (successful\n    search).\n\n  \\item Prove \\fun{slst/2} = \\fun{slst\\(_0\\)/2}.\n\n  \\item Show that, in a worst case to be identified,\n    \\(\\fun{slst}_0(s,x)\\) creates \\(3n\\)~useless nodes if~\\(s\\)\n    contains \\(n\\)~items. Compare the memory usage of\n    \\fun{slst\\(_0\\)/2}\\index{slst@\\fun{slst\\(_0\\)/2}} with that of\n    \\fun{slst/2}\\index{slst@\\fun{slst/2}}.\n\n\\end{enumerate}\n", "meta": {"hexsha": "b1cf4e5309fe31d5b5afc6285e5476824e879b12", "size": 34421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "skipping.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": "skipping.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": "skipping.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": 46.0173796791, "max_line_length": 98, "alphanum_fraction": 0.657912321, "num_tokens": 12378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6408934773194396}}
{"text": "\\def\\mA{\\ensuremath{{\\bf A}}}\n\\def\\mB{\\ensuremath{{\\bf B}}}\n\\def\\mC{\\ensuremath{{\\bf C}}}\n\\def\\mD{\\ensuremath{{\\bf D}}}\n\\def\\mu{\\ensuremath{{\\bf u}}}\n\\def\\mx{\\ensuremath{{\\bf x}}}\n\\def\\my{\\ensuremath{{\\bf y}}}\n\n\\documentclass[12pt]{article}\n\\usepackage{siunitx}\n\\begin{document}\n\\title{Drive kinematics and simulation}\n\\author{sss}\n\\maketitle\n\nA useful reference: http://fbsbook.org.\n\n\\section{Motor constants}\n\nA DC motor typically consists of a permanent magnet rotating relative\nto a conducting coil.  As the magnet rotates, it induces an EMF in the\ncoil.  This `back-EMF' is proportional to the angular velocity:\n\\begin{equation}\n  E = K_e \\omega .\n\\end{equation}\n\nA DC motor can be modeled as a resistance $R$ in series with the back EMF.\nTherefore, given the applied voltage $V$ and current $I$:\n\\begin{equation}\n  V = IR + E = IR + K_e \\omega.\n\\end{equation}\n\nIn other words, when a voltage is applied to the motor, it increases in speed\nuntil the back-EMF (plus resistive losses) balance the applied voltage.\n\nIf the current with no load is $I_0$, then the maximum speed of the motor\nis\n\\begin{equation}\n  \\omega_{\\max} = {V-I_0R \\over K_e}.\n\\end{equation}\n\nAlso note that when the motor is stalled, $E=0$, so the resistance\ncan be found using the current drawn at the stall:\n\\begin{equation}\n  R = V / I_{\\mathrm{stall}}.\n\\end{equation}\n\nIt is common to write $K_V = 1/K_e$.  Then the motor speed for a given applied\nvoltage is\n\\begin{equation}\n  \\omega = K_V (V-IR).\n\\end{equation}\nIn practice, the $IR$ term is usually small compared to $V$ and can be\nneglected, giving\n\\begin{equation}\n  \\omega = K_V V.\n\\end{equation}\n$K_V$ is sometimes called the motor velocity constant, and has SI units\nof $1/Vs$ (though it is sometimes given as $\\textrm{RPM}/V$).\n\nThe torque of the motor is related to the current via the motor\ntorque constant $K_T$:\n\\begin{equation}\n  \\tau = K_T I.\n\\end{equation}\nThis constant can be calculated from the torque required to stall the motor\nand the current draw at the stall:\n\\begin{equation}\n  K_T = \\tau_{\\textrm{stall}} / I_{\\textrm{stall}}.\n\\end{equation}\n\n$K_T$ and $K_V$ are not independent; they are inversely related.\nThe electrical power input to the motor is\n\\begin{equation}\n  P_{\\textrm{in}} = VI = (IR + K_e\\omega)I = I^2R + IK_e\\omega\n\\end{equation}\nwhile the mechanical power out is\n\\begin{equation}\n  P_{\\textrm{out}} = \\tau\\omega = IK_T\\omega,\n\\end{equation}\nwhile losses are\n\\begin{equation}\n  P_{\\textrm{loss}} = I^2R.\n\\end{equation}.\nBut\n\\begin{equation}\n  P_{\\textrm{in}} = P_{\\textrm{out}} + P_{\\textrm{loss}},\n\\end{equation}\nwhich implies that\n\\begin{equation}\n  K_T = K_e = 1/K_V.\n\\end{equation}\n\nTo take a specific example, the Falcon 500  motor operates at $\\SI{12}{\\V}$,\nwith $I_0 = \\SI{1.5}{\\A}$, $I_{\\textrm{stall}} = \\SI{257}{\\A}$,\n$\\tau_{\\textrm{stall}} = \\SI{4.69}{\\N\\m}$,\nand $\\omega_{\\max} = \\SI{6380}{RPM} = \\SI{668}{/\\s}$.\nThis then gives $R=V/I_{\\textrm{stall}}=\\SI{0.047}{\\ohm}$,\n$K_V = \\omega_{\\max} / (V-I_0R) = \\SI{60.0}{/\\V\\s}$ and\n$K_T = \\tau_{\\textrm{stall}} / I_{\\textrm{stall}} = \\SI{0.018}{\\N\\m/\\A}$.\nAnd $1/60 = 0.017$, so these are nearly inverse of each other.\n(Note that since power is voltage times current,\n$\\textrm{VA} = \\textrm{Nm}/\\textrm{s}$ or $\\textrm{Vs} = \\textrm{NM}/\\textrm{A}$.)\n\n\n\\section{A unicycle}\n\nLet's now apply this to a putative vehicle with a single wheel,\nconstrained to move in one dimension.  In addition to\n$R$, $K_V$, and $K_T$ of the motor, let $m$ be the mass,\n$r_w$ be the wheel radius, and $g$ be the gear ratio between\nthe motor and the wheel.\n\nLet $v$ be the (one-dimensional) velocity and $V$ be the voltage\napplied to the motor.  Then we want to write:\n\\begin{equation}\n  m \\dot v = c_1 v + c_2 V.\n\\end{equation}\n(Using the notation $\\dot v = dv/dt$.)\nSo the right-hand side represents the force acting on the vehicle.\n\nConsider the $c_2$ term first.  If the motor voltage is $V$, then the\ncurrent is $I = V/R$, the motor torque is $\\tau_m = IK_T = K_T V/R$,\nthe wheel torque is $\\tau_w = gK_T V/R$, and the force on the vehicle\nis $F = \\tau_w / r_w$, which implies\n\\begin{equation}\n  c_2 = {g K_T \\over R r_w}.\n\\end{equation}\n\nNow, consider the case where the voltage on the motor is zero.\nA rotating motor generates an EMF, so if the voltage is zero, then\nsomething must be absorbing the power produced by the motor; hence,\nthe motor will act as a brake.  We can thus write\n\\begin{equation}\n  m \\dot v = - { g K_T \\over R r_w } E,\n\\end{equation}\nwhere $E$ is the back-EMF.  But $E = K_e\\omega_m = g \\omega_w / K_V =\ng v / r_w K_V$.  Putting this together, we get\n\\begin{equation}\n  c_1 = - { g^2 K_T \\over K_V R r_w^2}.\n\\end{equation}\n\nTo specify the state of the vehicle, we also need its position $s$.\nThe equation for this is trivial:\n\\begin{equation}\n  \\dot s = v.\n\\end{equation}\n\n\\section{State space representation}\n\nThe dynamical variables describing the state of a system make up the\n\\emph{state space}.  These variables contain sufficient information\nto find the future state of the system.\n\nFormally, we write the state variables as an $n$-element vector $\\mx$.\nThe system can also have control inputs, which we represent\nas a $p$-element vector $\\mu$.  We can also make measurements\non the system, which we represent as an $q$-element vector $\\my$.\nThe system can then be described by\n\\begin{eqnarray}\n  {\\bf\\dot x} &=& f(\\mx, \\mu)\\\\\n  \\my &=& h(\\mx, \\mu)\n\\end{eqnarray}\n\nIf $f$ and $h$ are time-invariant and linear, then we can write this as\n\\begin{eqnarray}\n  {\\bf\\dot x} &=& \\mA\\mx + \\mB\\mu \\\\\n  \\my &=& \\mC\\mx + \\mD\\mu.\n\\end{eqnarray}\nThe matrix $\\mA$ is called the `system' or `dynamics' or `state' matrix;\n$\\mB$ is called the `input' or `control' matrix;\n$\\mC$ is called the `output' or `sensor' matrix; and\n$\\mD$ is called the `feedthrough' or `feedforward' or `direct' matrix.\n\n\n\\section{Differential drive}\n\nHere, the system consists of two identical motors with wheels separated\nby distance $2r_b$, and the system can move in two dimensions.\nThe mass is again $m$, and the moment of inertia is $I$.\n\nThe state variables here are the $x$ and $y$ positions, $s_x$ and $s_y$,\nthe heading $\\theta$, the positions of the two wheels\n$d_L$ and $d_R$, and their velocities $\\dot d_L$, $\\dot d_R$.\nWe can write this as a vector:\n$\\mx = [s_x, s_y, \\theta, \\dot d_L, \\dot d_R, d_L, d_R]^T$.\nThe control inputs are the motor voltages: $\\mu = [V_L, V_R]^T$.\n\nUsing the results from the previous section, the forces on the\nvehicle produced by the left and right motors are\n\\begin{equation}\n  F_L = c_1 \\dot d_L + c_2 V_L.\n\\end{equation}\nand similarly for the other motor.  Given $F_L$ and $F_R$,\nthe total force is $F_{\\textrm{tot}} = F_L + F_R$ and the torque is\n$\\tau = (F_L -F_R) r_b$.  Therefore, the acceleration for one\nof the wheels is\n\\begin{eqnarray}\n  \\ddot d_L &=& {1\\over m}F_{\\textrm{tot}} + {r_b\\over I}\\tau\\\\\n            &=& {1\\over m}(F_L + F_R) + {r_b^2\\over I}(F_L - F_R)\\\\\n            &=& \\left({1\\over m} + {r_b^2\\over I}\\right) c_1 \\dot d_L +\n                \\left({1\\over m} - {r_b^2\\over I}\\right) c_1 \\dot d_R +\\\\\n            & & \\left({1\\over m} + {r_b^2\\over I}\\right) c_2 V_L +\n                \\left({1\\over m} - {r_b^2\\over I}\\right) c_2 V_R \\nonumber\\\\\n            &=& c_3 c_1 \\dot d_L + c_4 c_1 \\dot d_R + c_3 c_2 V_L + c_4 c_2 V_R ,\n\\end{eqnarray}\nwhere\n\\begin{eqnarray}\n  c_3 &=& \\left({1\\over m} + {r_b^2\\over I}\\right) \\\\\n  c_4 &=& \\left({1\\over m} - {r_b^2\\over I}\\right).\n\\end{eqnarray}\nSimilarly,\n\\begin{equation}\n  \\ddot d_R = c_4 c_1 \\dot d_L + c_3 c_1 \\dot d_R + c_4 c_2 V_L + c_3 c_2 V_R.\n\\end{equation}\n\nIn addition, if we call the forward velocity\n$v = {1\\over 2}(\\dot d_L + \\dot d_R)$, then\n\\begin{eqnarray}\n  \\dot s_x &=& v \\cos \\theta \\\\\n  \\dot s_y &=& v \\sin \\theta \\\\\n  \\dot \\theta &=& (\\dot d_R - \\dot d_L) / 2r_b.\n\\end{eqnarray}\n\nFor the subset of state variables\n$\\mx = [\\dot d_L, \\dot d_R, d_L, d_R]^T$, with $\\mu = [V_L, V_R]^T$,\nthe dynamics can then be written in the notation of the previous\nsection as\n\\begin{equation}\n  \\dot\\mx = \\mA\\mx + \\mB \\mu\n\\end{equation}\nwith\n\\begin{equation}\n  \\mA = \\left[ \\begin{array}{cccc}\n  c_1c_3 & c_1c_4 & 0 & 0 \\\\\n  c_1c_4 & c_1c_3 & 0 & 0 \\\\\n  1 & 0 & 0 & 0 \\\\\n  0 & 1 & 0 & 0 \\\\\n\\end{array} \\right]\n\\end{equation}\nand\n\\begin{equation}\n  \\mB = \\left[ \\begin{array}{cc}\n  c_2c_3 & c_2c_4 \\\\\n  c_2c_4 & c_2c_3 \\\\\n  0 & 0 \\\\\n  0 & 0 \\\\\n\\end{array} \\right].\n\\end{equation}\n\n\n\\section{Runge-Kutta integration}\n\nGiven\n\\begin{equation}\n  {dy \\over dt} = f'(y, t)\n\\end{equation}\nwith an initial value of $y$ at some $t$, one can use Euler's method\nto integrate this in steps of $t$ of size $h$:\n\\begin{equation}\n  y_{n+1} = y_n + hf'(y_n, t_n).\n\\end{equation}\n\nIn practice, however, this is not a good method to use.\nThe error per step is $O(h^2)$, as can be seen from a series expansion:\n\\begin{equation}\n  y(t_n+h) = y(t_n) + {dy\\over dt}(t_n) h + O(h^2).\n\\end{equation}\nSo over the $\\sim 1/h$ steps needed to cover a fixed-size interval,\nthe error is $O(h)$.  This is not very accurate.\n\nWe can do better by first taking a trial step to the midpoint\nof the interval and then using the derivatives calculated there\nfor entire step.  That is,\n\\begin{eqnarray}\n  k_1 &=& h f'(t_n, y_n) \\\\\n  k_2 &=& h f'(t_n + {h\\over2}, y_n + {k_1\\over2}) \\\\\n  y_{n+1} &=& y_n + k_2.\n\\end{eqnarray}\nThis ends up canceling some the first order error terms, giving\na step error of $O(h^3)$.\n\nOne can go further in canceling error terms.  Fourth-order Runge-Kutta\nis defined by \n\\begin{eqnarray}\n  k_1 &=& h f'(t_n, y_n) \\\\\n  k_2 &=& h f'(t_n + {h\\over2}, y_n + {k_1\\over2}) \\\\\n  k_3 &=& h f'(t_n + {h\\over2}, y_n + {k_2\\over2}) \\\\\n  k_4 &=& h f'(t_n + h, y_n + k_3) \\\\\n  y_{n+1} &=& y_n + {k_1\\over6} + {k_2\\over3} + {k_3\\over3} + {k_4\\over6}\n\\end{eqnarray}\nand has a step error of $O(h^5)$.  One can extend this further,\nbut that is usually not found to be worthwhile.\n\n\\end{document}\n", "meta": {"hexsha": "ca8b614d7cd294f78ea8546a98b56b63fe99aa50", "size": 9886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mechanum-note/mechanum.tex", "max_stars_repo_name": "FRC-Team-496/FRC2022", "max_stars_repo_head_hexsha": "37bda9cbc0c82fd1ad059ca84184b05dd7b23a5a", "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": "mechanum-note/mechanum.tex", "max_issues_repo_name": "FRC-Team-496/FRC2022", "max_issues_repo_head_hexsha": "37bda9cbc0c82fd1ad059ca84184b05dd7b23a5a", "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": "mechanum-note/mechanum.tex", "max_forks_repo_name": "FRC-Team-496/FRC2022", "max_forks_repo_head_hexsha": "37bda9cbc0c82fd1ad059ca84184b05dd7b23a5a", "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.3986486486, "max_line_length": 82, "alphanum_fraction": 0.6670038438, "num_tokens": 3580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749421, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6408829256187889}}
{"text": "\\documentclass[12pt,onecolumn,a4paper]{report}\n\n\\usepackage{mathtools}\n\\usepackage[top=60pt,bottom=60pt,left=50pt, right=50pt]{geometry}\n\\usepackage{graphicx}\n\\usepackage{wrapfig}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{listings}\n\n\\graphicspath{{../plots/}}\n\\renewcommand*\\thesection{\\arabic{section}}\n\n\\newfont{\\pica}{cmpica scaled 800}\n\n\\begin{document}\n\\title{COMP3032 Assignment: Image Contour Extraction}\n\\author{ \\textbf{ Dionisio Perez-Mavrogenis}\\\\\n\t\tSchool of Electronics and Computer Science \\\\\n\t\tFaculty of Physical and Applied Sciences \\\\\n\t\tUniversity of Southampton}\n\\maketitle\n\n\\tableofcontents\n\\pagebreak\n\n\\section{Introduction}\n\\subsection{Equations used}\n\nThe equations used for extracting the optimal contour from the provided image were the following :\n\\begin{equation}\nE(v) = \\sum^{N-2}_{i=1} E_i (v_{i-1},v_i,v_{i+1})\n\\end{equation}\n\n\\begin{equation}\nE_i (v_{i-1},v_i,v_{i+1}) = \\lambda \\frac{|v_{i+1} - 2v_i + v_{i+1}|^2}{|v_{i+1} - v_{i-1}|^2} + (1-\\lambda)I(v_i)\n\\end{equation}\n\n\\begin{equation}\nS_i(v_{i+1},v_i) = \\min_{v_{i-1}}[S_{i-1}(v_i,v_{i-1}) + E_i (v_{i-1},v_i,v_{i+1})]\n\\end{equation}\n\n\\begin{equation}\nE(v_i) = \\lambda |v_i - v_{i-1}| + (1-\\lambda)I(v_i)\n\\end{equation}\n\n\\begin{equation}\nS_i(v_i) = \\min_{v_{i-1}}[S_{i-1}(v_{i-1})+E_i(v_{i-1},v_i)]\n\\end{equation}\n\nwhere $\\lambda \\in [0,1]$ is the regularization parameter and $S_0(v_1,v_0) = 0$.\n\\section{Approach}\nThe coursework was coded in Matlab. Although the approach I have chosen is not exactly the same as the one in the specification(with differences highlighted as encountered), my implementation works fairly well.\nThe image used was the file \"tongue.png\" provided with the specification, but the images displayed in the report are zoomed-in in the area enclosed be the contours because it is easier to spot details.\n\\subsection{Constructing the search space}\nThe construction of the search space is done by the function {\\pica get\\_search\\_space}. Given a number $M$, the search space created will have $M*N$ points, where $M$ includes both points on the starting contours(only $M-2$ points are created). \n\nThe search space is constructed in the following manner : \nfor each point in the first contour, calculate the $x$ and $y$ difference with the corresponding point in the second contour ($ xdif_i = abs[v_{i,1}(x) - v_{i,2}(x)]/(M-1),ydif_i = abs[v_{i,1}(y) - v_{i,2}(y)]/(M-1) $) and then to get each new point $v'(i)$ between points $v_{i,1},v_{i,2}$ do :\n\n\\begin{displaymath}\nv'_i = [xdif_i*(J-1)+v_{i,1}(x),ydif_i*(J-1)+v_{i,1}(y)], \\forall J \\in [1,M]\n\\end{displaymath}\n\nwhere $v_{i,1}$ is point $i$ in contour $1$ and $dif_i$ is the absolute difference between points $(v_{i,1},v_{i,2})$(with $x$ and $y$ denoting the corresponding coordinate).I add $dif*(J-1)$ to $v_{i,1}$ because contour one is assumed to be \"bellow\" contour two, that is, it has $x_1 \\leq x_2$ and $y_1 \\leq y_2$.\nThe {\\pica get\\_search\\_space} function is given as inputs an M, the vector of contour1, the vector of contour2 and the matrix of intensities of the image and returns the intensity matrix for the search space points and matrices $X$ and $Y$, which contain the corresponding $x$ and $y$ coordinates of the search space points.\nBecause the results of calculating the search space point coordinates might not always yield an integer, Matlab's inbuilt function {\\pica round} function was used.\n\nThe code for {\\pica get\\_search\\_space} is given in Appendix A 0.1, Listing A.2, and samples of the generated search space are shown in Appendix B 0.3, Figure B.1 . \n\n\\subsection{Construction of Energy and Position matrices}\n\nThe function {\\pica get\\_matrices} is responsible for calculating the energy and position matrices. It is supplied with arguments : $\\lambda$ (the regularization parameter), the intensity matrix calculated by {\\pica get\\_search\\_space}, and the $X$ and $Y$ matrices(also calculated by {\\pica get\\_search\\_space}), and returns the energy matrix (an $M\\times N\\times M$ matrix) and a vector describing which points belong to the optimal contour (the backtracking is also done in this function), which then is handled by the plotting functions who locate the actual points on the image later on.\n\nFor a given point $v_i$ , the entry in the energy matrix is calculated according to equation(3), with resulting value being inserted in $en(y,x,z)$ and $z$ being equal to the $y$ index of $v_{i+1}$. The energy up to point $v_i$ is taken to be the energy between points $v_{i-1}$ and $v_i$, as this is assumed to be the optimal between these two and thus the optimal between the triplet.\n\nSimultaneously, the position matrix is being built. At each position, $posm(y,x,z)= z' $, where $z'$ is the $y$-index of the optimal $v_{i-1}$ point and $z$ represents the $y$-index of the $v_{i+1}$ point for which this calculation is taking place.\n\nThe first and last columns of the position and energy matrices present a special case, since we need points $v_0$ and $v_{N+1}$ to calculate results for points in columns 1 and N, and such points do not exist. Therefore, column 1 is initialized to 0,  and the energy for points in column N is calculated by equations (4) and (5).\n\nBacktracking involved searching through the N-1 column of the energy matrix for the row that contained the minimum value , record the position of the row($y$-index) and the position of the minimum value in the row($z$-index). The rest of the procedure involves setting $y=z$ and reading $posm(y,x,z)$ into  $z$, then repeating the process for every $x \\in [2,N-1]$.\n\nThe code for this section is given in Appendix A, Listing A.3. The plotting functions are called in the invoking script, which is given in Appendix A, Listing A.1.\n\n\\section{Evaluation of the algorithm}\nThe evaluation following is not general and refers only to my implementation. Also, timings were performed using Matlab's {\\pica tic toc} function, on machines in the Zepler labs.\n\n\\subsection{Robustness}\n\\paragraph{Robustness to different initialisations }\n\n\n\\begin{figure}[Ht]\n        \\centering\n        \\begin{subfigure}[b]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcap-100-0.05000}.png}\n                \\caption{Initialized to 0.}\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]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcapnz-100-0.05000}.png}\n                \\caption{Initialized to intensity.}\n        \\end{subfigure}\n        \\caption{Optimal contour for different initialization of the energy matrix(M=100,$\\lambda=0.05$.)}\n\\end{figure}\n\nTwo different initialization methods were tried to test the algorithms robustness. The first method set the energies of the first column to zero, as the coursework suggested, whereas the second set each point's energy to be equal to its intensity.\n\nFigure 1 displays the resulting optimal contour for different initializations. The algorithm is robust enough so that the only difference is not on the actual contour being traced, but on the black space to the left of the tongue. Once the algorithm finds the optimal contour, the two contours are effectively identical.\n\n\n\n\\paragraph{Robustness for varying values of $\\lambda$}\nWith an initial value of $\\lambda=0.5$ the results were not satisfactory,as the result of tracing deviated a lot from the desired result, whereas when varying $\\lambda$ it was found that acceptable results are obtained when $\\lambda < 0.2$, and improved as $\\lambda$ got smaller. \n\n\\begin{figure}[Ht]\n        \\centering\n        \\begin{subfigure}[b]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcap-100-0.05000}.png}\n                \\caption{$\\lambda=0.05$}\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]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcap-100-0.50000}.png}\n                \\caption{$\\lambda=0.5$}\n        \\end{subfigure}\n        \\caption{Optimal contour for different values of $\\lambda$(M=100)}\n\\end{figure}\n\nFigure 2 shows a comparison for different $\\lambda$ values and Appendix B 0.4 shows resulting traces for for different values of $\\lambda$\n\n\n\\subsection{Performance}\n\n\\begin{figure}[Htb]\n\\includegraphics[scale=0.5]{3D/cw_3d_benchmark.png}\n\\centering\n\\caption{Benchmark of 3D matrix implementation for various values of M.}\n\\end{figure}\n\nThis algorithm performs for $N-1$ columns(where $N$ is the number of points in the initial contours), for $M$ points, $M\\times M$ operations and thus a good approximation for the running time would be $N\\times M^3$, and one hypothesis suggests that the algorithms has $O(M^3)$ running time, since N could be considered a constant. My implementation uses four {\\pica for}-loops to perform the calculations and all calculations have been moved to the outermost loop possible .\n\nFigure 3 is plot of the value of $M$ and the corresponding running times. The shape of the curve suggests an exponential function for the total running time. It has been observed that changing the value of $\\lambda$ has no impact on the running time for any given $M$.\n\n\\subsection{Application to other images}\n\n\\begin{figure}[Ht]\n        \\centering\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{curve.png}\n                \\caption{The random curve}\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]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{curvez-150-0.05000}.png}\n                \\caption{The traced contour.}\n        \\end{subfigure}\n        \\caption{Application to a random curve(M=150)}\n\\end{figure}\nThe algorithm was applied to the image of a curve that I created, and the results are shown in Figure 4.\nThe result shown in Figure 4(b) is for M=150,$\\lambda$=0.05 and a zero initialization of the energy matrix's first column. \nThere is a small part in the beginning of the curve that is not tracked (missing points from the initial contours), and the two initial points of the optimal contour that are completely off the curve, as well as the last point of the tracing. These might be attributed to the initialization of the energy matrix's first column and different calculation for the last column's energy. However, when the algorithm \"finds\" the black curve it tracks the curve correctly, confirming that the initial and last points pose a special case and could perhaps be ignored, or be dealt with in a different fashion.\n\n\\subsection{Comparison with a different algorithm}\n\n\\begin{figure}[Ht]\n\\includegraphics[scale=0.5]{2D/cw_2d_benchmark.png}\n\\centering\n\\caption{Benchmark of 2D matrix implementation for various values of M.}\n\\end{figure}\n\n\\begin{figure}[Ht]\n        \\centering\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcap-100-0.05000}.png}\n                \\caption{3D matrix, M=100,$\\lambda=0.05$}\n        \\end{subfigure}%\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{2D/{2d-clcap-100-0.05000}.png}\n                \\caption{2D matrix, M=100,$\\lambda=0.05$}\n        \\end{subfigure}\n        \n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{clcap-300-0.05000}.png}\n                \\caption{3D matrix, M=300,$\\lambda=0.05$.}\n        \\end{subfigure}\n        \n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{2D/{2d-clcap-300-0.05000}.png}\n                \\caption{2D matrix, M=300,$\\lambda=0.05$.}\n        \\end{subfigure}\n        \\caption{Comparison of the two algorithms}\n\\end{figure}\n\n\n\\begin{figure}[Ht]\n\\includegraphics[scale=1]{2D/{2d-curve-150-0.00500}.png}\n\\centering\n\\caption{Tracing of curve by 2D algorithm ($M=150,\\lambda=0.005$), with portions of the contour being completely straight, illustrating this algorithm's linear sense of continuity.}\n\\end{figure}\n\n\nA second algorithm was implemented in order to extract the contour of the tongue. This is the algorithm presented in the \"Dynamic Programming\" lecture, and uses Equations (4) and (5) to extract the optimal contour. The algorithm performs a total of $N\\times M\\times M$ operations; a benchmark of this algorithm's performance is given in Figure 5, and its time complexity could be characterized as $O(M^2)$, if we treat $N$ as a constant term.\n\nFigure 6 shows a comparison of the contours extracted from the two algorithms. Both algorithms extracted the optimal contour fairly well, the 2D implementation being simpler and faster to implement and seems to extract a smoother contour. However, the 2D algorithm has got a sense of continuity that approximates a straight line because it only considers two points, something that is illustrated in Figure 7.\n\nCode for this algorithm is given in Appendix A.2.\n\n\\section{Conclusion}\nThis implementation of the algorithm might not be the optimal, as I am not as proficient in Matlab, however it illustrates that the algorithm works and allows comparison with other algorithms.\nAlso, even though the background of the image containing the tongue is the original one, the algorithms run on the negated version of that image (so that the contour we extract has the minimum energy) and the result is plotted on the original image.\n\n%\n\n%\t\tAPPENDICES \n\n%\n\n\n\\pagebreak\n\\appendix\n\\chapter{Code listings}\n\\subsection{Code for the 3D matrix algorithm}\n\n\\lstset{ %\n  language=Matlab,                % the language of the code\n  numbers=left, \n  caption={Code used to initialize, run and plot the results for the 3D algorithm.},\n}\n\\lstinputlisting{../start_coursework_3D.m}\n\n\\lstset{ %\n  language=Matlab,                % the language of the code\n  numbers=left, \n  caption={Function generating the search space for the 3D algorithm.},\n}\n\\lstinputlisting{../get_search_space.m}\n\n\\lstset{\n  language=Matlab,\n  numbers=left, \n  caption={Function generating the position and energy matrices and doing the backtracking.},\n}\n\\lstinputlisting{../get_matrices_3D.m}\n\n\\lstset{\n  language=Matlab,\n  numbers=left, \n  caption={Function that gets the optimal points returned from {\\pica get\\_matrices} and retrieves their (x,y) coordinates, and adds them to an $N\\times 2$ vector for the plotting functions.},\n}\n\\lstinputlisting{../get_optimals_3D.m}\n\n\\subsection{Energy extraction function of 2D matrix.}\nSince the search space extraction and plotting functions are identical to the 3D implementation, only the energy calculation and back-tracking code for the 2D implementations is shown.\n\\lstset{\n  language=Matlab,\n  numbers=left, \n  caption={Function that generates the position and energy matrices for the 2D implementation of the algorithm.},\n}\n\\lstinputlisting{../2D_implementation/fill_energy_matrix.m}\n\n\\lstset{\n  language=Matlab,\n  numbers=left, \n  caption={Function that does the calculation for the transition between points $v_{i-1},v_i$.},\n}\n\\lstinputlisting{../2D_implementation/point_energy.m}\n\n\\chapter{Some of the images generated}\n\n\\subsection{Images of the search space generated}\nThese are two sample images generated by the {\\pica get\\_search\\_space} function. The search points are not plotted together with the optimal contour because the resulting image would get too cluttered to draw any results.\n\\begin{figure}[ht]\n        \\centering\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{sspace-50}.png}\n                \\caption{Search space generated for M=50}\n        \\end{subfigure}%\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{sspace-50}.png}\n                \\caption{Search space generated for M=100}\n        \\end{subfigure}\n        \\caption{Plotting of two sample search spaces.}\n\\end{figure}\n\n\\subsection{Traced contours for different values of $\\lambda$}\n\\begin{figure}[H]\n\\centering\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{100-0.05000}.png}\n                \\caption{$\\lambda=0.05$}\n        \\end{subfigure}%\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{100-0.15000}.png}\n                \\caption{$\\lambda=0.15$}\n        \\end{subfigure}\n        \\begin{subfigure}[b]{0.5\\textwidth}\n\t        \t\\centering\n    \t\t    \\includegraphics[width=\\textwidth]{3D/{100-0.30000}.png}\n\t        \t\\caption{$\\lambda=0.3$}\n        \\end{subfigure}\n        \\begin{subfigure}[b]{0.5\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{3D/{100-0.50000}.png}\n                \\caption{$\\lambda=0.5$}\n        \\end{subfigure}\n        \\caption{Plotting of two sample search spaces, with M=100.}\n\\end{figure}\n\nThese tracings are generated by the 3D energy matrix algorithm and have $M=100$.\n\\end{document}", "meta": {"hexsha": "080042005c5d666adfcfadc45f298e2d5d18c397", "size": 17565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "year_4/intelligent_algorithms/report/intalgreport.tex", "max_stars_repo_name": "dperezmavro/courseworks_uni", "max_stars_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_stars_repo_licenses": ["MIT"], "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_4/intelligent_algorithms/report/intalgreport.tex", "max_issues_repo_name": "dperezmavro/courseworks_uni", "max_issues_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_issues_repo_licenses": ["MIT"], "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_4/intelligent_algorithms/report/intalgreport.tex", "max_forks_repo_name": "dperezmavro/courseworks_uni", "max_forks_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_forks_repo_licenses": ["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.7155963303, "max_line_length": 600, "alphanum_fraction": 0.7070310276, "num_tokens": 4699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.6408829105266425}}
{"text": "\\subsection{What is Pressure?}\nWhile the Zeroth law of thermodynamics allows for the notion of \"temperature\" to be well defined, it isn't a particularly useful definition. While it can tell us that, macroscopically, \"temperature is what you read from a thermometer\", it is of interest to see how the phenomenon of temperature arises microscopically. For this, we will first introduce the notion of pressure\\footnote{{\\tt https://www.youtube.com/watch?v=a01QQZyl-\\_I}}.\n\nWe will here define the pressure $P$ as:\n\n\\begin{equation}\n    P = \\frac{F}{A}\n\\end{equation}\n\nWhere $F$ is the force exerted over a certain area $A$. A good way to think about this might be if I have a gas of pressure $P$ contained in a box, that would tell you that if one of the walls of the box has area $A$, there is a perpendicular force of $PA$ being applied.\\\\\n\nJust how does this help us define temperature? In order for us to connect the pieces, it will be helpful to figure out how the pressure of a gas arises from the microscopic properties of the gas. For this, let us consider a very simple scenario of a single molecule of gas bouncing back and forth in a 1-dimensional tube. This might seem like a strange place to start, but we will shortly see that this simple start leads to valuable information about more complicated scenarios! Note that the below derivation is mainly for your own understanding, and is not especially crucial for your success in Thermodynamics.\n\n\\begin{center}\n    \\begin{tikzpicture}[scale=4]\n    \\draw[draw=black] (0,0) rectangle(2,0.25);\n    \\filldraw (1,0.125) circle (0.75pt);\n    \\draw[red, ->, thick] (1.025,0.125) -- (1.5,0.125);\n    \\node[below] at (1,0.125) {$m$};\n    \\node[below] at (1.25,0.125) {$v$};\n    \\draw[<->] (0,-0.05) -- (2,-0.05);\n    \\draw[<->] (2.05,0) -- (2.05,0.25);\n    \\node[below] at (1,-0.05) {$L$};\n    \\node[right] at (2.05,0.125) {$A$};\n    \\end{tikzpicture}\n\\end{center}\n\nPictured above is our scenario; we have a single molecule of gas of mass $m$ and speed $v$ moving back and forth in a tube of length $L$, as it bounces off the ends of the tube that have area $A$. We assume that the molecule collides elastically off the walls, and hence it goes back and forth with velocities $\\vec{v}$ and $-\\vec{v}$. From our knowledge of kinematics, we obtain that the time it takes for the particle to go back and forth once is:\n\\begin{align*}\n    \\Delta t = \\frac{2L}{v}\n\\end{align*}\nNow, we want to figure out the average pressure that this particle applies on the wall; to obtain this, we, we return to how we have defined pressure above:\n\\begin{align*}\n    P_{av} = \\frac{F_{av}}{A}\n\\end{align*}\n$A$ is just a constant here, so we then just need to figure out $F_{av}$! For this, we think back to the kinematics unit and the definition of force as the time derivative of momentum\\footnote{Of course you know by know that force and momentum are vector and not scalar quantities, but since our problem is one dimensional, we can just consider the scalar version of the equation here!}:\n\\begin{align*}\n    F = \\frac{dp}{dt} = \\frac{d(mv)}{dt}\n\\end{align*}\nSince we are just concerned with the average force, we can just consider the change in momentum $\\Delta p$ of the particle from hitting one of the ends over one cycle over the time it takes for one cycle (which is just $\\Delta t$, above!). We consider that when the molecule hits the end of the tube with speed $v$, it reflects back elastically and starts going in the other direction with the same speed $v$, so its change in velocity is therefore $-2\\Delta v$, and therefore the change in momentum is:\n\\[ \\Delta p_{molecule} = -2m\\Delta v\\]\nAnd therefore the average force applied to the wall is:\n\\[ F_{av} = \\frac{-\\Delta p_{molecule}}{\\Delta t} = \\frac{2mv}{\\frac{2L}{v}} = \\frac{mv^2}{L} \\]\nThen, getting the average pressure (from the one molecule) is simple, using the definition of pressure:\n\\[P_{av} = \\frac{\\frac{mv^2}{L}}{A} = \\frac{mv^2}{V} \\]\nWhere I have used the fact that the volume of the tube is given by $V = AL$. Now, in a real gas, we obviously don't just have one molecule, but a bunch of different molecules, all with different speeds! If we want the total pressure from a whole bunch of (say, $N$) molecules, we can just add up the average pressure of $N$ molecules:\n\\[P_{total} = \\sum_{i=1}^N \\frac{mv_i^2}{V}\\]\nAs a reminder, the greek sigma $\\Sigma$ above is telling us to take the \"sum of N\" things (in this case, molecules). It's clear that the volume can be taken out of the summation (because the volume of the tube is the same no matter which molecule we look at), and if we further assume that all of the masses of the molecules are the same (which is perfectly reasonable if we have a gas made of one element), then we obtain:\n\\[P_{total} = \\frac{m}{V} \\sum_{i=1}^N v_i^2 \\]\nNow I'm going to do a bit of a hack; I'm going to multiply this expression by $1 = \\frac{N}{N}$:\n\\[P_{total} = N\\frac{m}{V} \\left(\\frac{1}{N}\\sum_{i=1}^N v_i^2 \\right)\\]\nYou might recognize from your physics labs that the quantity in brackets is just the \\textit{average} of the squared velocities of all the molecules\\footnote{To be clear, this is not the square of the averages!}; let us denote this by $v^2_{av}$. Now, let us multiply both sides by the volume $V$ of the box:\n\\[PV = Nmv^2_{av} \\]\nNow, if we multiply both sides by a half, we get something that looks familiar on the right hand side:\n\\[\\frac{1}{2}PV = N\\frac{1}{2}mv^2_{av} \\]\nYou can see that we have exactly the average kinetic energy of our molecules (times the number of molecules in our system)! Now, at the beginning I said we were considering a one-dimensional system; but the direction we could have been talking about could have been the x direction, the y direction, or the z direction, and we would have got the same result! Therefore, we have that:\n\\[N\\frac{1}{2}mv^2_{xav} = N\\frac{1}{2}mv^2_{yav} = N\\frac{1}{2}mv^2_{zav} = \\frac{1}{2}PV \\]\nTherefore, for an ideal gas in three dimensions, all we have to do is add the three terms (the three kinetic energy contributions from each of the directions) together:\n\\begin{equation}\n    \\label{eqn:(2)}\n    \\frac{3}{2}PV = N\\epsilon_{kavg}\n\\end{equation}\nWhere $\\epsilon_{kavg}$ is the average kinetic energy of the molecules in three dimensions, defined as:\n\\begin{equation}\n    \\epsilon_{kavg} = \\frac{1}{2}mv^2_{xav} + \\frac{1}{2}mv^2_{yav} + \\frac{1}{2}mv^2_{zav} = \\frac{1}{2}m\\vec{v}_{av} \\cdot \\vec{v}_{av}\n\\end{equation}\nNow at this point, you might be holding your head in your hands because I spent three pages on a derivation\\footnote{I sincerely apologize for your suffering.} and it seems like we're no closer to defining temperature than when we started. However, in the next section we will introduce the ideal gas law, and combining that with equation \\ref{eqn:(2)} we just derived, we will see that we obtain exactly what we want to find. ", "meta": {"hexsha": "556b3124dad5f59276d8a7765918d571cb0c66dd", "size": 6887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Temperature/pressure.tex", "max_stars_repo_name": "RioWeil/SCIE001-thermo-notes", "max_stars_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Temperature/pressure.tex", "max_issues_repo_name": "RioWeil/SCIE001-thermo-notes", "max_issues_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Temperature/pressure.tex", "max_forks_repo_name": "RioWeil/SCIE001-thermo-notes", "max_forks_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-30T05:36:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-30T05:36:50.000Z", "avg_line_length": 102.7910447761, "max_line_length": 614, "alphanum_fraction": 0.7229562945, "num_tokens": 1971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6408828974103131}}
{"text": "\\section{\\module{cmath} ---\n         Mathematical functions for complex numbers}\n\n\\declaremodule{builtin}{cmath}\n\\modulesynopsis{Mathematical functions for complex numbers.}\n\nThis module is always available.  It provides access to mathematical\nfunctions for complex numbers.  The functions are:\n\n\\begin{funcdesc}{acos}{x}\nReturn the arc cosine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{acosh}{x}\nReturn the hyperbolic arc cosine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{asin}{x}\nReturn the arc sine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{asinh}{x}\nReturn the hyperbolic arc sine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{atan}{x}\nReturn the arc tangent of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{atanh}{x}\nReturn the hyperbolic arc tangent of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{cos}{x}\nReturn the cosine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{cosh}{x}\nReturn the hyperbolic cosine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{exp}{x}\nReturn the exponential value \\code{e**\\var{x}}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{log}{x}\nReturn the natural logarithm of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{log10}{x}\nReturn the base-10 logarithm of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{sin}{x}\nReturn the sine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{sinh}{x}\nReturn the hyperbolic sine of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{sqrt}{x}\nReturn the square root of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{tan}{x}\nReturn the tangent of \\var{x}.\n\\end{funcdesc}\n\n\\begin{funcdesc}{tanh}{x}\nReturn the hyperbolic tangent of \\var{x}.\n\\end{funcdesc}\n\nThe module also defines two mathematical constants:\n\n\\begin{datadesc}{pi}\nThe mathematical constant \\emph{pi}, as a real.\n\\end{datadesc}\n\n\\begin{datadesc}{e}\nThe mathematical constant \\emph{e}, as a real.\n\\end{datadesc}\n\nNote that the selection of functions is similar, but not identical, to\nthat in module \\refmodule{math}\\refbimodindex{math}.  The reason for having\ntwo modules is that some users aren't interested in complex numbers,\nand perhaps don't even know what they are.  They would rather have\n\\code{math.sqrt(-1)} raise an exception than return a complex number.\nAlso note that the functions defined in \\module{cmath} always return a\ncomplex number, even if the answer can be expressed as a real number\n(in which case the complex number has an imaginary part of zero).\n", "meta": {"hexsha": "3a11870d5e25efe588e376ead6e955095440ee7b", "size": 2358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Doc/lib/libcmath.tex", "max_stars_repo_name": "marcosptf/cpython-2.0.1", "max_stars_repo_head_hexsha": "73c739a764e8b1dc84640e73b880bc66e1916bca", "max_stars_repo_licenses": ["PSF-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-03-26T21:53:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T21:47:20.000Z", "max_issues_repo_path": "Doc/lib/libcmath.tex", "max_issues_repo_name": "marcosptf/cpython-2.0.1", "max_issues_repo_head_hexsha": "73c739a764e8b1dc84640e73b880bc66e1916bca", "max_issues_repo_licenses": ["PSF-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-11-18T15:48:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-03T21:20:50.000Z", "max_forks_repo_path": "Doc/lib/libcmath.tex", "max_forks_repo_name": "marcosptf/cpython-2.0.1", "max_forks_repo_head_hexsha": "73c739a764e8b1dc84640e73b880bc66e1916bca", "max_forks_repo_licenses": ["PSF-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-07-16T08:14:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T01:55:17.000Z", "avg_line_length": 25.6304347826, "max_line_length": 75, "alphanum_fraction": 0.7408821035, "num_tokens": 681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619393159451, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6408541552274378}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\\usepackage{float}\n\\usepackage{ulem}\n\\usepackage{bm}\n\\usepackage{anysize}\n\\usepackage{pythonhighlight}\n\n\\marginsize{2cm}{2cm}{0.9cm}{1.8cm}\n\n\\title{EECE 5639 Computer Vision\\\\ [2ex] \\begin{large} Homework \\#4 \\end{large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\pagestyle{empty}\n%%---------------------------------------------------------------\n%% Question 1\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) Since $Z=0$, it is a similarity transformation:\n\\begin{equation*}\n\\left[ \\begin{array}{c}\nu\\\\\nv\\\\\n1\n\\end{array} \\right] \\sim \\left[ \\begin{array}{ccc}\nfcos\\theta & -fsin\\theta & ft_x\\\\\nfsin\\theta & fcos\\theta & ft_y\\\\\n0 & 0 & t_z\n\\end{array} \\right]\\left[ \\begin{array}{c}\nX\\\\\nY\\\\\n1\n\\end{array} \\right]\n\\end{equation*}\n(b) It has 4 degree of freedom.\\\\\n(c) 4 points are needed since it is a 2D to 2D transformation.\\\\\n(d) Yes, more correspondences will be helpful for a more robust solution:\n\\begin{itemize}\n    \\item 4 correspondences may be collinear\n    \\item points may be inaccurate because of noise\n\\end{itemize}\n(e) Cross ratio of collinear points.\\\\\n(f) Parallellism.\\\\\n(g) The building plane is parallel to the image plane if and only if:\n\\begin{itemize}\n    \\item lines of building parallel to $X$ axes are also parallel to each other on the image\n    \\item lines of building parallel to $Y$ axes are also parallel to each other on the image\n\\end{itemize}\n\n%%---------------------------------------------------------------\n%% Question 2\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) SSD\n\\begin{equation*}\nSSD = \\left[ \\begin{array}{cccccccc}\n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times \\\\\n\\times &  24 & 28 & 24 & 12 & 8 & 8 & \\times \\\\\n\\times &  16 & 12 & 16 & 8 & 12 & 8 & \\times \\\\\n\\times &  8 & 8 & 12 & 8 & 16 & 8 & \\times \\\\\n\\times &  10 & 7 & 9 & 12 & 28 & 20 & \\times \\\\\n\\times &  9 & 12 & 9 & 12 & 24 & 20 & \\times \\\\\n\\times &  0 & 7 & 7 & 8 & 12 & 8 & \\times \\\\\n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times \n\\end{array} \\right]\n\\end{equation*}\n(b) Cross-Correlation\n\\begin{equation*}\nC_fg = \\left[ \\begin{array}{cccccccc}\n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times \\\\\n\\times &  4 & 4 & 2 & 0 & 0 & 0 & \\times \\\\\n\\times &  10 & 14 & 8 & 2 & 0 & 2 & \\times \\\\\n\\times &  4 & 4 & 0 & 0 & 0 & 4 & \\times \\\\\n\\times &  4 & 5 & 2 & 0 & 4 & 10 & \\times \\\\\n\\times &  3 & 1 & 0 & 0 & 4 & 8 & \\times \\\\\n\\times &  8 & 4 & 1 & 2 & 8 & 12 & \\times \\\\ \n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times\n\\end{array} \\right]\n\\end{equation*}\n(c) Normalized Cross-Correlation\n\\begin{equation*}\nN_fg = \\left[ \\begin{array}{cccccccc}\n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times \\\\\n\\times &  0.0208 & 0.0179 & 0.0125 & 0 & 0 & 0 & \\times \\\\\n\\times &  0.0446&  0.0547 & 0.0417 & 0.0625&  0 & 0.0625& \\times \\\\\n\\times &  0.0625  &0.0625 & 0 & 0 & 0 & 0.0625 &\\times \\\\\n\\times &  0.05 & 0.0694 & 0.05 & 0 & 0.0179 & 0.0391& \\times \\\\\n\\times &  0.0536 & 0.0208 & 0 & 0 & 0.0208 & 0.0357& \\times \\\\\n\\times &  0.125 & 0.0714 & 0.125 & 0.0625&  0.05 & 0.0625 &\\times \\\\\n\\times & \\times& \\times& \\times& \\times &\\times &\\times & \\times \n\\end{array} \\right]\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "1b295b9f83ff8446a78c0e8071dd5baf5b2733d9", "size": 3385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5639-Computer-Vision/Homework-4/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": "EECE5639-Computer-Vision/Homework-4/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": "EECE5639-Computer-Vision/Homework-4/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.5148514851, "max_line_length": 93, "alphanum_fraction": 0.5675036928, "num_tokens": 1293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6408541494230007}}
{"text": "% !TEX root = index.tex\n\n\\section{The Cocomplex World of Cochain Complexes}\n\\epigraph{The introduction of the digit 0 or the group concept was general nonsense too, and mathematics was more or less stagnating for thousands of years because nobody was around to take such childish steps.}{Grothendieck}\n\\begin{align*}\n \\xymatrix@R-2pc{\n \\U \\ar@{~>}[r] & \\L^\\bullet(\\U)\\\\\n \\mbox{Good cover of } X & \\mbox{Cech Complex of } \\U }\n\\end{align*}\nTo be able to use algebraic techniques, we need a way to convert topological information into algebraic information. We'll do this using locally constant functions and of course, linear algebra. All our vector spaces will be over the base field $ \\F = \\{0, 1\\}$ i.e. all the scalars are either 0 or 1. This is mainly because $-1 = 1$ in $ \\F$\nand hence we do not have to worry about signs.\\\\\n\n\\noindent \\textbf{Notation:} $V = \\F \\langle v_1, \\dots, v_n \\rangle = \\F \\langle \\mathcal{B} \\rangle$ stands for ``$V$ is a vector space over $\\F$ with basis $ \\mathcal{B} = \\{ v_1, \\dots, v_n\\}$''.\n  \\begin{ques}\n      Show that the elements of $ \\F \\langle \\mathcal{B} \\rangle$ can be identified with subsets of $\\mathcal{B}$ and hence as a set $V$ has size $2^{\\lvert\\mathcal{B}\\rvert}$, where $\\lvert \\mathcal{B} \\rvert$ denotes the size of $\\mathcal{B}$.\n  \\end{ques}\n\n\\subsection{Locally Constant Functions}\n\\begin{definition}\n\tFor a topological space $X$, define the vector space of \\textbf{locally constant functions}, denoted $\\L(X)$, to be the space of continuous maps from $X$ to $\\F$.\n\t\\begin{align*}\n\t\t\\L(X) := \\{ \\: f: X \\rightarrow \\F \\: \\mbox{ continuous } \\}\n\t\\end{align*}\n  Here we are thinking of $\\F$ as a topological space with 2 points.\n\\end{definition}\n\\begin{ques}\n  Show that $\\L(X)$ is naturally a vector space over $\\F$.\n\\end{ques}\n\\begin{ques}\n  Show that if $X$ is connected then every continuous function $f: X \\rightarrow \\F$ is a constant function and hence $\\L(X) \\cong \\F$ as a vector space.\n\\end{ques}\n\\begin{ques}\n\tWhat is $\\L(\\phi)$ where $\\phi$ is the empty set (which is a legit topological space)?\n\\end{ques}\n\\noindent Let $X^1, X^2, \\dots, X^k$ be the connected components of $X$. Define $k$ functions $\\delta^1, \\delta^2, \\dots, \\delta^k : X \\rightarrow \\F$ as\n\\begin{align*}\n  \\delta^i(x) = \\begin{cases}\n    1 & \\mbox{ if $x \\in X^i$} \\\\\n    0 & \\mbox{ otherwise}\n\\end{cases}\n\\end{align*}\nfor $1 \\le i \\le k$.\\\\\n\\begin{ques}\n\tShow that\n\t\\begin{align*}\n\t\t\\L(X) = \\F \\langle \\delta^1, \\delta^2, \\dots, \\delta^k \\rangle\n\t\\end{align*}\n\tand hence $\\dim \\L(X) = k = \\pi_0(X)$.\n\\end{ques}\n\\begin{ques}*\n  Show that the above statement is false if $X$ has infinitely many connected components, for example, if $X$ is the set of integers.\n\\end{ques}\n\\begin{definition}\n\tWith the notation as above, we call $\\delta^1, \\delta^2, \\dots, \\delta^k$ the \\textbf{canonical basis} for $\\L(X)$.\n\\end{definition}\n\nThe following exercise is extremely important, make sure you understand it well.\n\\begin{ques} \\label{q:restrictions}\n  For an inclusion of topological spaces $X \\subseteq Y$,\n\t\\begin{enumerate}\n\t\t\\item We can restrict a function $f: Y \\rightarrow \\F$ to the subspace $X$ and get a function $f|_{X} : X \\rightarrow \\F$. Show that this induces a linear transformation\n    \\begin{align*}\n\t\t\t\\res_{Y \\rightarrow X}: \\L(Y) \\rightarrow \\L(X)\n\t\t\\end{align*}\n    \\item Explicitly compute the matrix for $\\res_{Y \\rightarrow X}$ in the canonical bases when $Y = \\R$ and $X = \\{ -1, 1\\}$.\n    \\item Explicitly compute the matrix for $\\res_{Y \\rightarrow X}$ in the canonical bases when $Y = \\R^2 $ minus the $y$-axis and $X = \\{ (-1,0), (1,0), (2,0)\\}$.\n    \\item* More generally, show that if $X^i$ and $Y^j$ are the connected components of $X$ and $Y$ respectively, for $1 \\le i \\le k$ and $1 \\le j \\le l$, then in the canonical basis $\\res_{Y \\rightarrow X}$ is a $k \\times l$ matrix whose entry in the $i^{th}$ row and $j^{th}$ column is given by\n    \\begin{align*}\n      [\\res_{Y \\rightarrow X}]_{i,j} &= \\begin{cases}\n        1 & \\mbox{ if } X^i \\subseteq Y^j \\\\\n        0 & \\mbox{ if } X^i \\not \\subseteq Y^j\n    \\end{cases}\n    \\end{align*}\n\t\t% \\item Show that $\\res_{U \\rightarrow U}$ is the identity transformation.\n\t\t% \\item Show that $\\res_{V \\rightarrow U} \\circ \\res_{W \\rightarrow V} = \\res_{W \\rightarrow U}$.\n    \\end{enumerate}\n\\end{ques}\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Cochain Complexes}\nThe various vector spaces $\\L(U_I)$ naturally assemble themselves into a cochain complex, we'll get to that in the next section. First we need to understand what cochain complexes are.\n\\begin{definition}\n  A \\textbf{cochain complex} $ \\V^\\bullet$ consists of the following data:\n  \\begin{align*}\n    &\\xymatrix{0 \\ar[r] & \\V^0 \\ar[r] & \\cdots \\ar[r] & \\V^{i-1} \\ar^-{d^{i-1}}[r] & \\V^{i} \\ar^{d^{i}}[r]& \\V^{i+1} \\ar[r] & \\cdots \\ar[r] & \\V^n \\ar[r] &0}\n  \\end{align*}\n  \\begin{enumerate}\n    \\item A vector space $ \\V^i$ for each $ i \\in \\Z$, with $ \\V^i \\neq 0$  only if $ 0 \\le i \\le n$ for some positive integer $ n$.\n    \\item For each $ i \\in \\Z$ a linear transformation $ d^i: \\V^i \\rightarrow \\V^{i+1}$ that satisfies\n    \\begin{align*}\n      d^{i} \\circ d^{i-1} = 0\n      &&\n      \\xymatrix{\n      \\V^{i-1} \\ar@/_1pc/_{d^{i} \\circ d^{i-1} = 0}[rrrr] \\ar^{d^{i-1}}[rr] && \\V^i \\ar^{d^{i}}[rr] && \\V^{i+1}\n      }\n    \\end{align*}\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{ques}\n  Show that $ \\im d^{i-1} \\subseteq \\ker d^{i}$.\n\\end{ques}\n\n\\begin{definition}\n  The $ i^{th}$ \\textbf{cohomology} of $ \\V^\\bullet$ is the quotient vector space\n    \\begin{align*}\n      H^i(\\V) := \\ker d^{i} / \\im d^{i-1}\n    \\end{align*}\n\\end{definition}\n\\begin{remark}\n  This is well-defined because of the previous exercise. We'll only be interested in the dimensions\n  \\begin{align*}\n    \\dim H^i(\\V) = \\dim \\ker d^{i} - \\dim \\im d^{i-1}\n  \\end{align*}\n\\end{remark}\n\\noindent \\textbf{Convention:} Even though in a cochain complex there is a vector space $ \\V^i$ for all integers $ i$ it is a common convention to explicitly define $ \\V^i$ only where it is non-zero, it is understood that the rest of the $ \\V^i$ are all 0. The first non-zero vector space in the cochain complex is understood to be $ \\V^0$ unless otherwise specified.\n\\begin{ques}\n  A vector space $A$ can be thought of as a cochain complex as\n  \\begin{align*}\n    \\xymatrix{ \\V^\\bullet= 0 \\ar[r] & A \\ar[r] & 0}\n  \\end{align*}\n  What are the cohomologies $ H^i(\\V)$, for $ i \\in \\Z$?\n\\end{ques}\n\n\\begin{ques}\n  A linear transformation $ f:A \\rightarrow B$ can be thought of as a cochain complex as\n  \\begin{align*}\n    \\xymatrix{ \\V^\\bullet= 0 \\ar[r] & A \\ar^f[r] & B \\ar[r] & 0}\n  \\end{align*}\n  What are the cohomologies $ H^i(\\V)$, for $ i \\in \\Z$?\n\\end{ques}\nFor the following exercises it'll be useful to invoke the {\\bf Rank-Nullity / Dimension Theorem}.\n\\begin{ques} Verify that the following are cochain complexes and compute their cohomologies.\n  \\begin{enumerate}\n    \\item $ \\xymatrix{0 \\ar[r] & \\F \\ar^{0}[r] & \\F \\ar^{0}[r] & \\F \\ar[r] & 0 }  $\n    \\item $ \\xymatrix{0 \\ar[r] & \\F \\ar^{1}[r] & \\F \\ar^{0}[r] & \\F \\ar[r] & 0 }  $\n    \\item $ \\xymatrix{0 \\ar[r] & \\F \\ar^{0}[r] & \\F \\ar^{1}[r] & \\F \\ar[r] & 0 }  $\n    \\item $ \\xymatrix{0 \\ar[r] & \\F \\ar^{\\begin{bmatrix}1 \\\\ 1 \\end{bmatrix}}[rr]  && \\F^2  \\ar^{\\begin{bmatrix}1 & 1 \\end{bmatrix}}[rr] && \\F \\ar[r] & 0 }  $\n  \\end{enumerate}\n\\end{ques}\n\n\\begin{ques} Compute the cohomologies of the following cochain complexes.\n  \\begin{enumerate}\n    \\item $ \\xymatrix{0 \\ar[r] & \\F^2 \\ar^{\\begin{bmatrix}1 & 1 \\\\ 1 & 1 \\\\ 1 & 1 \\end{bmatrix}}[rr] && \\F^3 \\ar[r] & 0 } \\qquad $ (this is computing $\\check H^* (S^1 \\vee S^1)$).\n    \\item $ \\xymatrix{0 \\ar[r] & \\F^3 \\ar^{\\begin{bmatrix}1 & 1 & 0\\\\ 1 & 0 & 1 \\\\ 0 & 1 & 1 \\end{bmatrix}}[rr] && \\F^3 \\ar^{\\begin{bmatrix}1 & 1 & 1\\\\ 1 & 1 & 1 \\end{bmatrix}}[rr] && \\F^2 \\ar[r] & 0 } \\qquad $ (this is computing $\\check H^* (S^2)$).\n  \\end{enumerate}\n\\end{ques}\n\n\\begin{ques}\n  Given $\\xymatrix{ \\V^\\bullet= 0 \\ar[r] & A \\ar^f[r] & B \\ar^g[r] &  C \\ar[r] & 0}$\n  \\begin{enumerate}\n    \\item Under what conditions on $ f,g$ is $ \\V^\\bullet$ a cochain complex.\n    \\item Under what conditions on $ f,g$ is $ H^i(\\V) = 0$ for all $ i$. In this case, we say that $ \\V^\\bullet$ is a \\textbf{short exact sequence}.\n  \\end{enumerate}\n\\end{ques}\n\n\\begin{definition}\n  More generally, a cochain complex $ \\V^\\bullet$ is said to be \\textbf{exact} (or \\textbf{long exact}) if $H^i(\\V) = 0$ for all $ i$.\n\\end{definition}\n\\newpage\n\n\\subsection*{Optional Problems}\n\\begin{definition}\n  Define the \\textbf{Euler characteristic} of a cochain complex to be\n  \\begin{align*}\n    \\chi(\\V)\n    &= \\sum_{i \\in \\Z} (-1)^i \\dim H^i(\\V) \\\\\n    &= \\dim H^0(\\V) - \\dim H^1(\\V) +  \\dim H^2(\\V) \\pm \\cdots + (-1)^n \\dim  H^n(\\V)\n  \\end{align*}\n\\end{definition}\n% \\begin{ques} $ $\n%   \\begin{enumerate}\n%     \\item Show that if $ \\V^\\bullet$ is exact then $ \\chi(\\V) = 0$.\n%     \\item Find an example of a cochain complex $ \\V^\\bullet$ which is not exact but for which $ \\chi(\\V) = 0$.\n%   \\end{enumerate}\n% \\end{ques}\n\n\\begin{ques}$ $\n  \\begin{enumerate}\n    \\item Express the Euler characteristic in terms of the $ \\dim \\ker(d^i)$ and $ \\dim \\im(d^i)$ for $i \\in \\Z$.\n    \\item Show that\n      \\begin{align*}\n        \\chi(V) = \\sum_{i \\in \\Z} (-1)^i \\dim \\V^i\n      \\end{align*}\n  \\end{enumerate}\n  \\end{ques}\n  \\noindent Thus the Euler characteristic can be computed using the dimensions of the vector spaces of the original cochain complex, but it is really an invariant of the underlying cohomology!!! \\\\\\\\\n\\begin{ques}*\n  The direct sum of cochain complexes $(\\V_1 \\oplus \\V_2)^\\bullet$ is defined as\n  \\begin{align*}\n    (\\V_1 \\oplus \\V_2)^i := \\V_1^i \\oplus \\V_2^i\n  \\end{align*}\n  and the differential is defined as\n  \\begin{align*}\n    d^i := d_1^i \\oplus d_2^i\n  \\end{align*}\n  % \\begin{align*}\n  %   &\\xymatrix{ \\cdots \\ar[r] & \\V_1^{i-1} \\oplus \\V_2^{i-1} \\ar^-{d_1^{i-1} \\oplus d_2^{i-1}}[rr] && \\V_1^{i} \\oplus \\V_2^{i} \\ar^{d_1^{i} \\oplus d_2^{i}}[rr]&& \\V_1^{i+1} \\oplus \\V_2^{i+1} \\ar[r] & \\cdots}\n  % \\end{align*}\n  Find $H^*(\\V_1 \\oplus \\V_2)$ in terms of $H^*(\\V_1)$ and $H^*(\\V_2)$.\n\\end{ques}\n\n\\begin{ques}***\n  The tensor product $(\\V_1 \\otimes \\V_2)^\\bullet$ of two cochain complexes $\\V_1^\\bullet$, $\\V_2^\\bullet$ is defined as\n  \\begin{align*}\n    (\\V_1 \\otimes \\V_2)^k := \\bigoplus \\limits_{i + j = k} \\V_1^i \\otimes \\V_2^j\n  \\end{align*}\n  and the differential is defined as\n  \\begin{align*}\n    d^k := \\bigoplus \\limits_{i + j = k} d_1^i \\otimes d_2^j\n  \\end{align*}\n  Find $H^*(\\V_1 \\otimes \\V_2)$ in terms of $H^*(\\V_1)$ and $H^*(\\V_2)$.\n\\end{ques}\n\\newpage\n\\begin{ques}***\n  A \\textbf{morphism of cochain complexes} $\\phi: \\V_1^\\bullet \\rightarrow \\V_2^\\bullet$ is a collection of maps $ \\phi: \\V_1^i \\rightarrow \\V_2^i$ for each $ i \\in \\Z$ such that the following diagram commutes\n  \\begin{align*}\n    \\xymatrix{\n    \\V_2^i \\ar^-{d}[r]  & \\V_2^{i+1}  \\\\\n    \\V_1^i \\ar^-{d}[r] \\ar_{\\phi}[u] & \\V_1^{i+1} \\ar^{\\phi}[u]\n    }\n  \\end{align*}\n  \\begin{enumerate}\n    \\item Show that a morphism $\\phi: \\V_1^\\bullet \\rightarrow \\V_2^\\bullet$ between cochain complexes naturally induces a map between cohomologies $\\phi^*: H^i(\\V_1) \\rightarrow H^i(\\V_2)$, for all $ i \\in Z$.\n    \\item Given two morphisms $\\phi_1: \\V_1^\\bullet \\rightarrow \\V_2^\\bullet$ and $\\phi_2: \\V_2^\\bullet \\rightarrow \\V_3^\\bullet$, show that their composition $\\phi_2 \\circ \\phi_1: \\V_1^\\bullet \\rightarrow \\V_3^\\bullet$ is also a morphism of cochain complexes. Further show that $ (\\phi_2 \\circ \\phi_1)^* = \\phi_2^* \\circ \\phi_1^*$.\n  \\end{enumerate}\n\\end{ques}\n\n\\begin{ques}**\n  A cochain complex of cochain complexes (i.e. each $\\V^i$ is itself a cochain complex and the differentials $d^i$ are morphisms of cochain complexes) is called a \\textbf{double complex}. Unravel this description of a double complex and describe it more explicitly as a grid of vector spaces.\n\\end{ques}\n\n\\iffalse\n\\begin{ques}[Snake Lemma]**\n  Show that a morphism $ \\phi$ between short exact sequences\n    \\begin{align}\n      \\label{eq:double_complex}\n      \\xymatrix{\n         0 \\ar[r] & \\V_1^0 \\ar^{\\phi^0}[d] \\ar[r] & \\V_1^1 \\ar^{\\phi^1}[d] \\ar[r] & \\ar^{\\phi^2}[d] \\V_1^2 \\ar[r] & 0 \\\\\n         0 \\ar[r] & \\V_2^0 \\ar[r] & \\V_2^1 \\ar[r] &  \\V_2^2 \\ar[r] & 0\n      }\n    \\end{align}\n    induces a natural exact sequence (not a full cochain complex)\n    \\begin{align}\n      \\label{eq:snake_lemma}\n      \\xymatrix{\\ker \\phi^0 \\ar[r] & \\ker \\phi^1 \\ar[r] & \\ker \\phi^2 \\ar[r] & \\coker \\phi^0 \\ar[r] &\\coker \\phi^1 \\ar[r] &\\coker \\phi^2 }\n    \\end{align}\n    (Recall the cokernel of a map $ f:A \\rightarrow B$ is $ B/(\\im f)$.) This sequence does not naturally extend to a full cochain complex.\n\\end{ques}\n\\begin{remark}\n  Note that \\eqref{eq:double_complex} is a double complex which gives rise to the exact sequence \\eqref{eq:snake_lemma}. Larger double complexes give rise to more complicated structures called \\textbf{spectral sequences}.\n\\end{remark}\n\\fi\n", "meta": {"hexsha": "72ec000d89102c75f863b0371a2cd07998378b7c", "size": 12946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.tex", "max_stars_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_stars_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_issues_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_forks_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_forks_repo_licenses": ["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.7923076923, "max_line_length": 367, "alphanum_fraction": 0.6295380813, "num_tokens": 4809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6408541476215096}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#9 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\textbf{Disclaimer.} This is the reasoning I used to solve the problem; it\nmay be wrong though. This is intended just as food for thought.\n\n\\section{Parameters Of Neural Network}\n\nGiven a neural network with 10 input units (including the constant $x_0^{(0)}$\nunit), one output unit, and 36 hidden units (including the necessary number of\nconstant units for a fully-connected network), this question asks what is the\nminimum possible number of weights that such a network can have.\n\n\\subsection{Finding The Minimum}\n\nThe network must be fully connected, and each hidden layer must include a\nconstant (bias) unit. Since the constant units don't get any input from the\nprevious layer, one way to minimize the number of required weights is by\nmaximizing the number of constant units in the network.\n\nThis can be done by creating a network with 18 hidden layers, with 2 units each.\nThe number of weights in this network is given by:\n\n\\begin{equation*}\n(1 \\cdot 10) + (1 \\cdot 2 \\cdot 17) + (2) = 46\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "583f67a882d0610d450af1fd7ab15cf12187ca17", "size": 1202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-06/math/q09.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-06/math/q09.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-06/math/q09.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": 31.6315789474, "max_line_length": 80, "alphanum_fraction": 0.768718802, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6408541342111439}}
{"text": "% conclusions and future work\n\\section{Discussions and Conclusions}\n\\label{sec:conclusions}\n\nWe presented an effective approach to mine approximate frequent subgraph\npatterns from a single large graph database in the presence of\na label cost matrix.\n\nThere are two main parameters in our method: $K$, the number of random\nwalks, and $\\alpha$ the cost threshold. The value of $K$ is directly\nproportional to the number of maximal approximate patterns we desire,\nand is relatively easy to set.\nOn the other hand, choosing an appropriate value of\n$\\alpha$ is very important as it affects the quality of\npatterns mined. Depending on the application domain\nand the purpose of the graph mining, let $t$ be the number of\nvertices in the pattern for which we allow label mismatches\nin the subgraph isomorphism. One reasonable value of\n$\\alpha$ is $t \\times IMQ$ where $IMQ$ is the inter-quartile mean\ni.e., the mean of the entries between the first quartile ( $25^{th}$\npercentile) and the third quartile ( $75^{th}$ percentile)\nof the entries in the cost matrix arranged in sorted order. \n$t$ can be chosen by first\nenumerating maximal patterns with $\\alpha = 0$ and computing the \naverage size $m$ of the maximal patterns mined from the graph.\nThe value of $t$ then is a fraction of the average size $m$.\nCare has to be taken not to choose a very large $\\alpha$ as it leads to\npatterns of poor quality and also increases the run time of the\nalgorithm significantly as can be seen in Table \\ref{tab:scop_alpha}.\n\nIn terms of future work, we plan to increase the efficiency of our\nmethod by exploiting parallelism. Obviously different walks can be\ncarried out in parallel. However, more interesting is the\nparallelization of the approximate isomorphism generation and\nlabel-based pruning steps, including verification. We also\nwant to explore the idea of label based pruning for more\ngeneral definitions of approximate isomorphism including \nedge mismatches.\n\n", "meta": {"hexsha": "ad6ae761e7e329a376fdbb54baef8ca87998e1e6", "size": 1952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "finalversion/sigkdd13/conclusions.tex", "max_stars_repo_name": "PranayAnchuri/approx-graph-mining-with-label-costs", "max_stars_repo_head_hexsha": "4bb1d78b52175add3955de47281c3ee0073c7943", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "finalversion/sigkdd13/conclusions.tex", "max_issues_repo_name": "PranayAnchuri/approx-graph-mining-with-label-costs", "max_issues_repo_head_hexsha": "4bb1d78b52175add3955de47281c3ee0073c7943", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "finalversion/sigkdd13/conclusions.tex", "max_forks_repo_name": "PranayAnchuri/approx-graph-mining-with-label-costs", "max_forks_repo_head_hexsha": "4bb1d78b52175add3955de47281c3ee0073c7943", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-08T11:17:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-08T11:17:33.000Z", "avg_line_length": 48.8, "max_line_length": 72, "alphanum_fraction": 0.7899590164, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6408541317592973}}
{"text": "\\onecolumn\r\n\\chapter{Measurement Models}\r\n\r\n\r\n\\begin{equation}\r\n    \\mathcal{R}_1^{(j)} = \\rho^{(m,j)}_1(t_i) +c\\left(b_r^{(m)}(t_i) - b_t^{(j)}(t_t)\\right) + \\Delta \\rho^{(j)}_{iono}(t_i) + \\Delta \\rho^{(j)}_{tropo}(t_i) + \\sigma_{SA}^{(j)} + \\sigma_n^{(j)} + b_m\r\n\\end{equation}\r\n\r\n\\begin{tabbing}\r\n12345678912345 \\= Reynolds number based on length $s$ \\kill\r\n$\\mathcal{R}_1^{(j)}$         \\>  One-way pseudorange measurement from transmitting \\\\\r\n$$                            \\> antenna $k$ on satellite $j$ to receiving antenna $m$ on satellite $n$. \\\\\r\n$\\rho^{(m,j)}_1(t_i)$         \\>  Geometric distance between transmitting and receiveing antenntas.\\\\\r\n$b_r^{(m)}(t_i)$               \\> Clock bias for receiver \\\\\r\n$b_t^{(j)}(t_t)$                   \\>  Clock bias for transmitter\\\\\r\n$\\Delta \\rho^{(j)}_{iono}(t_i)$    \\> Correction for ionspheric delay \\\\\r\n$ \\Delta \\rho^{(j)}_{tropo}(t_i) $ \\> Correction for  Tropospheric delay\\\\\r\n$\\sigma_{SA}^{(j)}$                \\> Error due to selective availability \\\\\r\n$\\sigma_n^{(j)}$                   \\> Measurement noise \\\\\r\n$b_m$                              \\> Measurement bias \\\\\r\n$t_t$                              \\> Trasmission time \\\\\r\n$t_r$                              \\> Receive time\r\n\\end{tabbing}\r\n\r\n\r\nThe transmission time $t_t$ and the geometric range are determined\r\niteratively by using fixed point iteration on the following equation\r\n%\r\n\\begin{equation}\r\n   t_t = t_i - \\frac{\\rho^{(m,j)}_1(t_i) + \\Delta \\rho^{(j)}_{iono}(t_i) + \\Delta \\rho^{(j)}_{tropo}(t_i)}{c}\r\n\\end{equation}\r\n\r\n\\section{Range}\r\n\r\nGMAT supports two primary models for spacecraft range: geometric and\r\nradiometric. In both cases the range is a measure of the distance\r\nbetween an observer and a vehicle.\r\n The geometric range is calculated using vector geometry and ignores signal propagation\r\n  times and error sources.  Most, if not all, ground trackers provide the user with\r\n  the round trip signal propagation time.  The radiometric range model uses the best\r\n   estimate spacecraft state to determine an expected value for the round trip signal\r\n   propagation time from observer to spacecraft and back to the observer.  Hence,\r\n   the raw radiometric value is a measure of round trip range.\r\n\r\nThe general form of the measurement model used by GMAT is\r\n%\r\n\\begin{equation}\r\n   \\mathcal{O}_c = \\mathbf{f}_k\\left(\\mathbf{r}_v(t + \\delta t), \\dot{\\mathbf{r}}_v(t + \\delta t),\r\n   \\mathbf{r}_o, \\dot{\\mathbf{r}}_o\\right) + b + \\delta_a + \\delta_r\r\n\\end{equation}\r\n%\r\n%\r\n\\begin{tabbing}[htbp!]\r\n12345678 \\= dummy line \\kill\r\n$\\mathbf{f}_k$ \\> The kinematic model specific to a measurement type\\\\\r\n$\\mathbf{r}_v$ \\> Vehicle position\\\\\r\n$\\dot{\\mathbf{r}}_v$ \\> Vehicle velocity\\\\\r\n$\\mathbf{r}_o$ \\> Observer position\\\\\r\n$\\dot{\\mathbf{r}}_o$    \\> Observer velocity\\\\\r\n$t$    \\> Measurement time tag\\\\\r\n$b$    \\> Measurement bias\\\\\r\n$\\delta a$    \\> Atmospheric correction\\\\\r\n$\\delta r$     \\> Relativistic correction\\\\\r\n\\end{tabbing}\r\n\r\nThe kinematic model for geometric range is simply\r\n%\r\n\\begin{equation}\r\n    \\rho_c = \\| \\mathbf{r}_v(t) - \\mathbf{r}_g(t)\\|\r\n\\end{equation}\r\n%\r\n\r\nThe kinematic model for radiometric two way range is\r\n%\r\n\\begin{equation}\r\n     \\rho_c= \\frac{1}{2}\\left(\\| \\mathbf{r}_v(t_{v}) -  \\mathbf{r}_g(t_{gt})  \\| +\r\n      \\| \\mathbf{r}_v(t_{v}) -  \\mathbf{r}_g(t_{gt})  \\|\\right) \\label{Eq:ExpectedTwoWayRange}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{tabbing}[htbp!]\r\n12345678 \\= dummy line \\kill\r\n$t_{gt}$ \\> Time the uplink signal is transmitted from ground station\\\\\r\n$t_{vr}$ \\> Time the uplink signal is received at vehicle\\\\\r\n$t_{vt}$ \\> Time the downlink signal is transmitted from vehicle\\\\\r\n$t_{gr}$ \\> Time the downlink signal is received at ground station\\\\\r\n$t_u$    \\> Uplink propagation time, ( $t_{vr}$ - $t_{gt}$ )\\\\\r\n$t_d$    \\> Downlink propagation time, ( $t_{vt}$ - $t_{gr}$ )\\\\\r\n$\\rho_u$    \\> Uplink distance\\\\\r\n$\\rho_d$    \\> Downlink distance\\\\\r\n$d_T$     \\> Distance traveled by vehicle during transponder delay\\\\\r\n$\\mathbf{r}_v(t)$ \\> Position of vehicle at time $t$\\\\\r\n$\\mathbf{r}_t(t)$ \\> Position of transmitter at time $t$\\\\\r\n$\\mathbf{r}_r(t)$ \\> Position of receiver at time $t$\\\\\r\n$t$           \\>  time of geometric range measurement \\\\\r\n$\\delta T$  \\>  Vehicle's transponder delay time\\\\\r\n$\\delta t_a$  \\>  Atmospheric delays\\\\\r\n$\\delta t_r$  \\>  Relativistic effects\\\\\r\n\\end{tabbing}\r\n%\r\n\r\nThe radiometric model is derived from the measurement geometry shown\r\nin Fig.~\\ref{Fig:RangeMeasurement}. We see that the total signal\r\npropagation time is the sum of three times, the uplink\r\n signal propagation time, $t_u$, the transponder delay time, $\\delta T$, and\r\n the downlink propagation time, $t_d$.  Hence, the observed value for signal propagation time, $t_o$, is\r\n%\r\n\\begin{equation}\r\n     \\Delta t_o = t_{gr} - t_{gt} = t_u + \\delta T + t_d\r\n\\end{equation}\r\n%\r\n\\begin{figure}[htbp!]\r\n    \\begin{center}\r\n    \\begin{picture}(270,215)\r\n    \\special{psfile= RangeMeasurement.eps\r\n    hscale= 75 vscale= 75 hoffset = -85 voffset = -270}\r\n        \\makebox(175,295){ $\\mathbf{r}_v(t_{vr})$}\r\n        \\makebox(-25,290){ $\\mathbf{r}_v(t_{vt})$}\r\n        \\makebox(85,290){ $\\rho_d$}\r\n        \\makebox(-100,90){ $\\mathbf{r}_g(t_{gr})$}\r\n        \\makebox(-460,90){ $\\mathbf{r}_g(t_{gt})$}\r\n        \\makebox(-485,290){ $\\rho_u$}\r\n        \\makebox(-305,390){ $d_T$}\r\n    \\end{picture}\r\n    \\end{center}\r\n    \\vspace{0.2 in}\r\n    \\label{Fig:RangeMeasurement}\r\n    \\caption{ Geometry of Radiometric Range Measurement}\r\n\\end{figure}\r\n%\r\nThe elapsed time is converted to a measure of the average range\r\nusing\r\n%\r\n\\begin{equation}\r\n     \\rho_o = \\frac{c}{2}\\Delta t_o\r\n\\end{equation}\r\n%\r\nThe computed elapsed time is rigorously expressed as\r\n%\r\n\\begin{equation}\r\n    \\Delta t_c = \\frac{1}{c}\\| \\mathbf{r}_v(t_{vr}) -  \\mathbf{r}_g(t_{gt})  \\| +\r\n    \\frac{1}{c}\\| \\mathbf{r}_v(t_{vt}) -  \\mathbf{r}_g(t_{gr})  \\| + \\delta T\r\n\\end{equation}\r\n%\r\nAssuming that the transponder delay is modelled as a measurement\r\nbias we can write $ t_{vr} = t_{vt} = t_v$ and convert the computed\r\nround trip time to average range:\r\n%\r\n\\begin{equation}\r\n     \\rho_c= \\frac{1}{2}\\left(\\| \\mathbf{r}_v(t_v) -  \\mathbf{r}_g(t_{gt})  \\| +\r\n      \\| \\mathbf{r}_v(t_v) -  \\mathbf{r}_g(t_{gr})  \\|\\right) \\label{Eq:MeasuredTwoWayRange}\r\n\\end{equation}\r\n%\r\nTo solve Eq.~\\ref{Eq:MeasuredTwoWayRange}, we must know  $t_{v}$.\r\nFor applications\r\n that do not require high accuracy we can approximate $t_v$ as we describe below.\r\n  For higher fidelity applications we must solve for the uplink and downlink\r\n  propagation times using two iterative processes.  The downlink signal propagation\r\n  time is calculated using the following fixed point iteration on the following equation:\r\n%\r\n\\begin{equation}\r\n     \\delta t_d^{i+1} = \\frac{1}{c}\\| \\mathbf{r}_v( t - t_d^{i}) - \\mathbf{r}_g(t)   \\|\r\n\\end{equation}\r\n%\r\nThe uplink propagation time is calculated using fixed point\r\niteration on\r\n%\r\n\\begin{equation}\r\n     \\delta t_u^{i+1} = \\frac{1}{c}\\| \\mathbf{r}_v( t - t_d) - \\mathbf{r}_g(t - t_d - t_u^{i} )   \\|\r\n\\end{equation}\r\n%\r\n\r\n\\begin{eqnarray}\r\n     \\frac{\\partial \\rho_c (t)}{\\partial \\mathbf{r}_v(t_v)} &=& \\frac{1}{2\\rho_u\\rho_d}\r\n     \\left( \\rho_d(\\mathbf{r}_v^T(t_v) - \\mathbf{r}_T^T(t_{gt}) + \\rho_u(\\mathbf{r}_v^T(t_v) - \\mathbf{r}_R^T(t_{gr}  ) \\right)\\\\\r\n     %\r\n     \\frac{\\partial \\rho_c (t)}{\\partial \\dot{\\mathbf{r}}_v(t_v)} &=& \\mathbf{0}_{1x3}\r\n\\end{eqnarray}\r\n", "meta": {"hexsha": "c412cd421e70f9d1593c4afe44dbc75fbe4848ad", "size": 7438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/MeasurementModels.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/MeasurementModels.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/MeasurementModels.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": 41.3222222222, "max_line_length": 201, "alphanum_fraction": 0.628260285, "num_tokens": 2425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.6926419894793246, "lm_q1q2_score": 0.6408531210621525}}
{"text": "\\chapter{Beginning Combinatorics}\n\nDiscrete probabilities problems often include some counting. For\nexample, we figured out that there were 36 different ways the two dice\ncould come up, but all of them summed to some number 2 through 12. How\nmany different ways could 3 8-sided dice come up? We would need to\ncount them, right? As the numbers get big we will need some tricks so\nwe don't need to write them all down and count them one-by-one.\n\nThe branch of mathematics that focuses on tricks for counting is\ncalled \\textit{combinatorics}.\\index{combinatorics}\n\nHow can be sure that there were 36 different configurations for the\ntwo 6-sided dice? The first die could have come up as any one of six\nnumbers. For each of those, the second could have come up with any one\nof six numbers.  Thus, the number of possibilities is $ 6 \\times 6 =\n36.$\n\nHow many different configurations for 3 8-sided dice?  $8 \\times 8\n\\times 8 = 8^3 = 512$.\n\nWhat about 7 dice, each with 20 sides? $20^7=1,280,000,000$\nconfigurations.  See, aren't you glad we don't need to write them all\ndown?\n\nNow, let's say that six people (Anne, Brock, Carl, Dev, Edgar, and Fred) are\ngoing to run a race. You have to make a plaque that says who won first\nplace, who won second place, and who won third. If you want to get all\nthe possible plaques created beforehand, and just pull the right one\nout as soon as the race ends, how many plaques would you need to get\nengraved?\n\nIn this case, once someone has been given first place, they can't win\nsecond or third place.  Thus, any of the 6 people can come in first,\nbut once you have engraved that person's name on the plaque, there are\nonly 5 people whose name can appear in second place.  Once you have\nengraved that name, there are only 4 people whose name can appear in\nthird place.  Thus, you would get $6 \\times 5 \\times 4 = 120$ plaques\nengraved.\n\nWhat if the plaque includes all 6 places?  Then you would need $6 \\times 5\n\\times 4 \\times 3 \\times 2 \\times 1 = 720$ plaques engraved.  We use\nthis process often enough that we gave it a name.  We say ``I need 6\nfactorial plaques engraved.''  When we write a factorial, we use an\nexclamation point:\\index{factorial}\n\n$$6! = 6 \\times 5 \\times 4 \\times 3 \\times 2 \\times 1 = 720$$\n\nThe rule, then, is $n$ items can be ordered in $n!$ ways. We use the\nword ``permutation'' to mean a particular ordering.  Thus\nmathematicians actually say ``If you have a list of $n$ items then I\ncan generate $n!$ different permutations of those items''.\n\nIn Python, there is a \\pyfunction{factorial} function in the math library:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n> \\textbf{python3} \n>>> \\textbf{import math}\n>>> \\textbf{math.factorial(6)}\n720\n\\end{Verbatim}\n\nHandy, right? Now you don't need to write loop to calculate factorials.\n\nRemember when we only wanted the first three names on the plaque? We can do that problem using factorials:\n\n$$6 \\times 5 \\times 4 = \\frac{6 \\times 5 \\times 4 \\times 3 \\times 2 \\times 1}{3 \\times 2 \\times 1} = \\frac{6!}{3!}$$\n\nThis formulation makes it easy to figure out on any calculator with a ``!'' button.\n\nThe rule on this is to fill $m$ positions from $n$ items, it can be done this many ways:\n\n$$\\frac{n!}{(n-m)!}$$\n\n\\subsection{Choose}\n\nLet's say that there are 12 kids in a classroom, and you need a team\nof 4 to wipe down the desks.  How many different possible teams are\nthere? You know that if you were giving out four different positions\n(Like the race gave out 1st, 2nd, and 3rd), the answer would be $12\n\\times 11 \\times 10 \\time 9$ or $12! / (12 - 4)!$.\n\nHowever, once we pick the 4 people, we don't care what order they are\nin, right?  In this problem, the team ``Anne, Brad, Carl, and Don'' is\nthe same as the team ``Carl, Don, Brad, and Anne''.\n\nThus, the quantity $12! / (12 - 4)!$ is many times too large because\nit counts each permutation separately.  To get the right number, we\njust divide this by the number of possible permuations for a group of\nfour people: $4!$\n\nThat gets us our answer: How many different teams of four can be chosen from 12 people?\n\n$$\\frac{12!}{(12-4)! 4!}= 495$$\n\nIn combinatorics, we use this quantity a lot, so we have given it a name: \\textit{choose}\\index{choose function}\n\nWe have also given it a notation.  ``12 choose 4'' is written like this:\n\n$${12 \\choose 4}$$\n\nPython has the \\pyfunction{math.comb} function:\n\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n> \\textbf{python3}\n>>> \\textbf{import math}\n>>> \\textbf{comb(12, 4)}\n495  \n\\end{Verbatim}\n\n", "meta": {"hexsha": "0ed5c6802021cc469ac9f715a56ca4941eb11f52", "size": 4487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/DiscreteProbability/combinatorics-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/combinatorics-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/combinatorics-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.7909090909, "max_line_length": 116, "alphanum_fraction": 0.7298863383, "num_tokens": 1308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8918110454379297, "lm_q1q2_score": 0.6408504164844492}}
{"text": "\\documentclass{article}\n\\input{commonheader}\n\\usepackage{comment}\n\\usepackage{enumitem}\n\\usepackage{algpseudocode}\n\n\\title{CS 5050: Homework 1}             \n\\author{Andrew Pound}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\nI worked on this assignement with Chad Cummings.\n\\section{}\n\\begin{enumerate}[label=(\\alph*)]\n\\item  Suppose we are comparing implementations of insertion sort and \nmerge sort on the same machine. For inputs of size n, insertion sort\nruns in $8n^2$ steps, while merge sort runs in $64n \\log n$ steps. For\nwhich values of $n$ does insertion sort beats merge sort? {\\bf (5\n  points)} \n\\item[]\nThere are a few different ways to do this. The first way that we\nattacked it was that we solved the inequality equation to easiest way\nto solve this is to tabulate the answers for each side of the equatoin\nand find the point that they cross.  (This would actually get a bit\nlong for this particular problem).  So instead a plot of the two\nfunctions can be used to see where it crosses.\n\nEquations:\n\\begin{equation}\\label{eq:1a}\n  \\begin{split}\n    8n^2 &\\le 64n\\log n\\\\\n    \\frac{1}{8} &\\le  \\frac{1}{n}\\log n\\\\\n    2^{\\frac{1}{8}} &\\le n^{\\frac{1}{n}}\n  \\end{split}\n\\end{equation}\n\nPlotting both sides of this, produces the graph below.\n\\begin{figure}[h!t]\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{prob1a}\n  \\caption{Plot of the inequality in equation \\ref{eq:1a}.}\n  \\label{fig:prob1a}\n\\end{figure}\n\nFrom this we can see that the cross over point is around 43.\nTabulating the values of $n^{1/n}$ in Table \\ref{tab:1a}, the\nneighborhood of 43 and \n\\begin{table}[h!t]\n  \\centering\n  \\caption{Tabulation of values around $n=43$.}\n  \\label{tab:1a}\n  \\begin{tabular}{cc}\n    $n$ & $n^{1/n}$ \\\\\n    \\input{prob1a.tex}\n  \\end{tabular}\n\\end{table}\ncomparing them with the value of $2^{1/8} = 1.0905$, we can see that\nany number greater than 43 satisfies the inequality.  \n\n\n\\item  What is the smallest value of n such that an algorithm whose\nrunning time is $100n^2$ runs faster than an algorithm whose running\ntime is $2^n$ on the same machine? {\\bf (5 points) }\n\\item[] This can be solved in much the same manner as the previous\n  problem. First, Let's examine the inequality.\n  \\begin{equation}\\label{eq:1b}\n    \\begin{split}\n      100 n^2 & \\le 2^n\\\\\n      \\log_2(100n^2) & \\le log_2(2^n) = n\\\\\n      \\frac{2}{n} \\log(10n) &\\le 1\\\\\n      \\frac{1}{n} \\log(10n) &\\le \\frac1 2\\\\\n      \\log\\left(n^{\\frac{1}{n}}\\right) &\\le \\frac{1}{2}\\\\\n      \\left(10n\\right)^{\\frac{1}{n}} &\\le \\sqrt{2}\n    \\end{split}\n  \\end{equation}\n\\end{enumerate} \n\nThe plot of this function is seen in Figure \\ref{fig:1b}, and the\ntabulation around the cross over is in Table \\ref{tab:1b}.  This time\nwe ar comparing with the value $\\sqrt{2} = 1.4142$, and we can see\nthat the cross over happens at $n=15$.\n\\begin{figure}[h!t]\n  \\centering\n  \\includegraphics[width=.7\\linewidth]{prob1b}\n  \\caption{Plot of the inequality in equation \\ref{eq:1b}.}\n  \\label{fig:1b}\n\\end{figure}\n\n\\begin{table}[h!t]\n  \\centering\n  \\caption{Tabulation of values around $n=15$.}\n  \\label{tab:1b}\n  \\begin{tabular}[h]{cc}\n    $n$ & $(10n)^{1/n}$ \\\\\n    \\input{prob1b.tex}\n  \\end{tabular}\n\\end{table}\n\n\\vspace{3em}\n\\section{}\nWe have discussed the insertion sort algorithm in class and we showed\nthat in the worst case the algorithm runs in $\\Theta(n^2)$ time. You\nmay wonder whether the algorithm can run asymptotically faster for\ncertain ``average'' cases. In this exercise, we will examine the running\ntime of the insertion sort algorithm on some average cases. Let $A$ be \nthe input array of n elements.\n\nNote: For each of the questions, please give your answers in the\nbig-Theta notation and also briefly explain how you obtain your answer.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Consider the case where the first $n/2$ elements of $A$ have\nalready been sorted \\emph{increasingly} and the last $n/2$ elements\nhave been sorted \\emph{decreasingly}. For example, $A = \\{1, 3, 5, 7,\n8, 6, 4, 2\\}$. Suppose we want to sort all elements of $A$ in\nincreasing order by using the insertion sort algorithm. What would be\nthe running time of the algorithm? What if the first $n/2$ elements of\n$A$ have already been sorted decreasingly and the last $n/2$ elements\nhave been sorted increasingly? For example, $A = \\{8, 6, 4, 2, 1, 3,\n5, 7\\}$. What would be the running time in this case? {\\bf (10 points)}\n\n\\item[] The insertion sort algorithm that we discussed in class is\n  given as\n  \\begin{algorithmic}\n    \\For{$i=2\\dots n$}\n    \\State $x\\gets A[i]$\n    \\State $j \\gets i-1$\n    \\While{$A[j-1] < x \\And j \\ge 1$}\n    \\State $A[j+1]\\gets A[j]$\n    \\State $j \\gets j-1$\n    \\EndWhile\n    \\State $A[j+1]\\gets x$\n    \\EndFor\n  \\end{algorithmic}\nThe outer for loop consists of $4c$ operations, and the inner loop\n(when run) consists of $2c$ operations.\nNow suppose that  the elements of our array are ordered in such a  way\nthat the first half of the array are already in ascending order, and\nthe second half is the worst case (descending order) and need to be\nmerged into the first half.  If that is the case, then the first half\nof the algorithm is a best case scenario, and only uses\n$4c\\frac{n}{2}$ operations.  The second half, though will utilize the\ninner for-loop to move some of the elements in the first half of the\narray in order to insert in the correct place. \nBy considering the first elements in the second half, we can determine\na relation between the number of times in the inner loop and the\niteration index.  If the array is in the form specified, then the\nfirst element of the second half will not require any moving to place\nit.  The second will require 2 moves (the first element of the 2nd\nhalf and the last element of the first half).  The third element in\nthe 2nd half will require 4 moves.  We see that for $i > \\frac{n}{2}$,\nthe number of times in the inner loop will be $2(i-\\frac{n}{2})$.\nThus, we can stick this into an expression for the total number of\noperations\n\\begin{equation}\n  \\underbrace{4cn}_{\\text{outer loop}} + \\underbrace{\\sum_{i =\n    \\frac{n}{2}}^n2\\left(i-\\frac{n}{2}\\right)\\left(2c\\right).\n}_{\\text{inner loop}} \n\\end{equation}\nNow expanding this, we get a total of \n\\begin{equation}\n\\begin{split}\n  (4cn) + 4c\\sum_{i=0}^{n/2}i &= 4cn +\n  4c\\frac{\\frac{n}{2}\\left(\\frac{n}{2} + 1\\right)}{2}\\\\\n  &= 4cn + 2c\\left(\\frac{1}{4}n^2 + \\frac{1}{2}n\\right)\\\\\n  &= 4cn + \\frac{1}{2}n^2c + cn\\\\\n  &= \\frac{1}{2}cn^2 + 5cn\\\\\n  &= O(n^2)\n\\end{split}\n\\end{equation}\n\n%The second ordering \n\n\n\n\\item Consider the case where the elements of $A$ with odd indices have\nalready been sorted increasingly and elements with even indices have\nbeen sorted decreasingly (we assume the index of $A$ starts from\n1). For example, $A = \\{1, 8, 2, 7, 3, 6, 4, 5\\}$. Suppose we want to\nsort all elements of $A$ in increasing order by using the insertion\nsort algorithm. What would be the running time of the algorithm?\n\nWhat if the elements of $A$ with odd indices have already been sorted\n\\emph{decreasingly} and elements with even indices have been sorted \n\\emph{increasingly}. For example, $A = \\{8, 1, 7, 2, 6, 3, 5,\n4\\}$. What would be the running time in this case?  {\\bf (10 points)}\n\n\\item[] \nOk, we'll begin by looking at how the algorithm works on the example\nsequence.  The results of the steps of the algorithm are shown below.\nThe bolded numbers identify values that needed to be moved (i.e. the\nvalues for which the inner loop was used). The first line is the\noriginal sequence.\n\\begin{equation}\n  \\begin{matrix}\n    1 & 8 & 2 & 7& 3  &6 & 4 & 5\\\\\n    1 &&&&&&&\\\\\n    1 & 8 &&&&&&\\\\\n    1 & 2 & {\\bf 8}&&&&&\\\\ \n    1 & 2 & 7 & {\\bf 8}&&&&\\\\\n    1 & 2 & 3 & {\\bf 7}&{\\bf 8}  &&&\\\\\n    1 & 2 & 3 & 6& {\\bf 7}&{\\bf 8}  &&\\\\\n    1 & 2 & 3 & 4& {\\bf 6}& {\\bf 7}&{\\bf 8}  &\\\\\n    1 & 2 & 3 & 4& 5  &{\\bf 6} & {\\bf 7}&{\\bf 8} \\\\\n  \\end{matrix}\n\\end{equation}\nFrom this we can see that for each pair of iterations, the number of\nmoves ends up being predictable.  In order to count the time, we then\nstart with the equation\n\\begin{equation}\n  \\underbrace{4cn}_{\\text{outer loop}} + \\underbrace{2 \\sum_{i=1}^{n/2}\n    (i-1)(2c)}_{\\text{inner loop}}.\n\\end{equation}\nThe outer loop has $4c$ operations and happens for each element in the\narray, thus we get $4cn$.   Each pair of iterations is hitting the\ninner loop for the same number of times, namely $i-1$, for the $i$th\npair. The inner loop consists of $2c$ operations, thus we get the\nsummation over all the pairs, and multiply by 2 to get the full effect\nof the inner loop.  This is\n\\begin{equation}\n  \\begin{split}\n    2 \\sum_{i=1}^{n/2}\n    (i-1)(2c) &= 4c \\sum_{i=1}^{n/2}(i - 1)\\\\\n    &= 4c \\sum_{i=1}^{n/2}i  - 4c\\frac{n}{2}\\\\\n    &= 4c \\frac{\\frac{n}{2}\\left(\\frac{n}{2} + 1\\right)}{2} -\n    4c\\frac{n}{2}\\\\ \n    &= 2c\\left(\\frac{n^2}{4} + \\frac{n}{2} - n\\right)\\\\\n    &= 2c\\left(\\frac{1}{4}n^2 - \\frac{1}{2}n\\right)\n  \\end{split}\n\\end{equation}\nThe entire operations count together then would be\n\\begin{equation}\n  \\begin{split}\n    4cn + 2c\\left(\\frac{1}{4}n^2 - \\frac{1}{2}n\\right)&= \n    4cn + \\frac{1}{2}cn^2 - cn\\\\\n    &= \\frac{1}{2}cn^2 + 3cn\\\\\n    &= O(n^2)\n  \\end{split}\n\\end{equation}\nNow for the other example, let's see what it looks like:\n\\begin{equation}\n  \\begin{matrix}\n    8& 1& 7& 2& 6& 3& 5 &4 \\\\\n    8 &&&&&&&\\\\\n    1 & {\\bf 8} &&&&&&\\\\\n    1 & 7 & {\\bf 8}&&&&&\\\\ \n    1 & 2 & {\\bf 7} & {\\bf 8}&&&&\\\\\n    1 & 2 & 6 & {\\bf 7}&{\\bf 8}  &&&\\\\\n    1 & 2 & 3 & {\\bf 6}& {\\bf 7}&{\\bf 8}  &&\\\\\n    1 & 2 & 3 & 5& {\\bf 6}& {\\bf 7}&{\\bf 8}  &\\\\\n    1 & 2 & 3 & 4& {\\bf 5}  &{\\bf 6} & {\\bf 7}&{\\bf 8} \\\\\n  \\end{matrix}\n\\end{equation}\nEssentially, the idea is the same, in that the iterations can be split\ninto pairs such that a pair will use the inner loop (to move larger\nnumbers) the same number of times.  Thus the analysis is (almost)\nexactly the same: $ O(n^2)$.\n\n\n\\end{enumerate}\n\n\n\\section{}\nFor each of the following pairs of functions, indicate whether it is\none of the three cases: $f (n) = O(g(n))$, $f (n) = \\Omega(g(n))$, or\n\n$f (n) = \\Theta(g(n))$. (30 points)\n\\begin{enumerate}[label=(\\alph*)]\n\\item $f (n) = 100n + \\log n$ and $g(n) = 6n + \\log^2 n$.\n\\item[] $f(n) = \\Omega(g(n))$.  My reasoning is this:\n  \\begin{equation}\n    \\begin{split}\n      f(n) &\\: ?\\: g(n)\\\\\n      100n + \\log n &\\: ? \\: 6n+]log^2 n\\\\\n      94n &\\: ?\\: \\log^2 n - \\log n \n    \\end{split}\n  \\end{equation}\nNow, $\\log^2 n - \\log n < \\log^2 n$, and comparing this as above, we\nsee that \n\\begin{equation}\n  \\begin{split}\n    94n > \\log^2 n > \\log^2 n -\\log n.\n  \\end{split}\n\\end{equation}\nThus, we can say that $f(n) = \\Omega(g(n))$.\n\\item $f (n) = 20 \\log n + 4$ and $g(n) = \\log n^2 - 100$.\n\\item[] $f(n) = \\Theta(g(n))$.  Playing with the equations a bit, we\n  can see\n  \\begin{equation}\n    \\begin{split}\n      f(n) & \\: ? \\: g(n)\\\\\n      20\\log n + 4 &\\: ? \\: \\log n^2 - 100\\\\\n      20 \\log n + 4 &\\: ? \\: 2\\log n - 100.\n    \\end{split}\n  \\end{equation}\nNow, if we choose $c_1 = 20$ and $c_2 = 10$, then we get an asymptotic\nupper and lower bound, respectively, by forming the equations $c_i\ng(n)$.  Thus, we know that $f(n) = \\Theta(g(n))$.\n\\item $f (n) =\\frac{n^2}{\\log n}$ and $g(n) = n \\log^2 n$.\n\\item[] $f(n) = \\Omega(g(n))$. Let's play with the equations:\n  \\begin{equation}\n    \\begin{split}\n      \\frac{n^2}{\\log n} &\\: ? \\: n \\log^2 n\\\\\n      n &\\: ? \\: \\log^3 n.\n    \\end{split}\n  \\end{equation}\nThen using a nifty formula:\n  \\begin{equation}\n    \\log^k n = O(n^d) \\quad \\forall\\: k>0, \\: d > 0,\n  \\end{equation}\nwe can see that $d = 1$, and $k = 3$, and thus, $g(n) = O(f(n))$. \nOr in other words, $f(n) = \\Omega(g(n))$.\n\\item $f (n) =\\sqrt{n}$ and $g(n) = \\log^5 n$.\n\\item[] $f(n) = \\Omega(f(n))$. Using the same nifty equation from\n  above, we can see that $g(n) = O(f(n))$, as $k = 5$, and $d = 1/2$.\n  Thus flipping this around, we see that $f(n) = \\Omega(f(n))$.\n\\item $f (n) = n2^n$ and $g(n) = 3^n$ .\n\\item[] $f(n) = O(g(n))$.  We will make use of our other nifty\n  formula \n  \\begin{equation}\n    n^d = o(e^n), \\quad \\forall\\: e > 1.\n  \\end{equation}\nFirst, let's play a bit with our equation\n\\begin{equation}\n\\begin{split}\n  n2^n &\\: ?\\: 3^n\\\\\n  n &\\: ? \\:  \\left(\\frac{3}{2}\\right)^n.\n\\end{split}\n\\end{equation}\nThis helps us to see that when $d = 1$ and $ e = 3/2$, then \nwe know that $f(n) = o(g(n))$ and therfore, $f(n) = O(g(n))$.\n\\item $f (n) = 4n \\log n$ and $g(n) = n \\log_3 n$.\n\\item[] $f(n) = \\Theta(g(n))$. Playing with the equation, we get\n  \\begin{equation}\n    \\begin{split}\n    4n \\log n &\\: ? \\: n \\log_3 n\\\\\n    4 \\log n &\\: ? \\: \\frac{\\log n}{\\log 3}\\\\\n    4 \\log n &\\: ? \\: \\frac{1}{\\log 3} \\log n\\\\\n    4 &\\: ? \\: \\frac{1}{\\log 3}\n    \\end{split}\n  \\end{equation}\nNow we see that $f(n) = \\Theta(g(n))$.\n\\end{enumerate}\n\n\nNote: For each question, you only need to give your answer and the\nproof is not required. \n\n\n\\section{}\nThe \\emph{knapsack problem} is defined as follows: Given as input a\nknapsack of size $K$ and $n$ items whose sizes are $k_1 , k_2 ,\n\\dots , kn$ , where $K$ and $k_1 , k_2 , \\dots , k_n$ are all real\nnumbers, find a full ``packing'' of the knapsack (i.e., choose a\nsubset of the n items such that the total sum of the sizes of the\nitems in the chosen subset is exactly $K$). \n\nIt is well known that the knapsack problem is NP-complete, which\nimplies that it is very likely that efficient algorithms (i.e., those\nwith a polynomial running time) for this problem do not exist. Thus,\npeople tend to look for good {\\bf approximation algorithms} for\nsolving this problem. In this exercise, we relax the constraint of the\nknapsack problem as follows. We still seek a packing of the knapsack,\nbut we need not look for a ``full'' packing of the knapsack; instead,\nwe look for a packing of the knapsack (i.e., a subset of the n input\nitems) such that the total sum of the sizes of the items in the chosen\nsubset is at least $K/2$ (but no more than $K$). This is called a\n\\emph{factor of 2 approximation solution} for the knapsack problem. To \nsimplify the problem, we assume that a factor of 2 approximation\nsolution for the knapsack problem always exists, i.e, there always\nexists a subset of items whose total size is at least $K/2$ and at\nmost $K$. \n\nDesign a polynomial time algorithm for computing a factor of 2\napproximation solution for this problem, and analyze the running time\nof your algorithm (in the big-O notation). If your algorithm runs in\n$O(n)$ time and is correct, then you get {\\bf 5 extra points}. {\\bf(20\n  points)} \n\nNote: You are required to clearly describe the main idea of your\nalgorithm. Although the pseudo-code is not required, you may also give\nthe pseudo-code if you feel it is helpful for you to describe your\nalgorithm. (The reason I want to see the algorithm description instead\nof only the code or pseudo-code is that it would be difficult to\nunderstand another person's code without any explanation.) You also\nneed to briefly explain why your algorithm works, i.e., why your\nalgorithm can produce a factor of 2 approximation solution. Finally,\nplease analyze the running time of your algorithm. \n\n\\paragraph{My algorithm}\n\n\n\n\n\nIn order to find a factor of 2 approximation, we will make use of the\nassumptions that there definitely exists such an approximation, and\nthat all of the $k_i$ sizes are positive.\n\nThe algorithm is as follows:\n\nIterate through the list by pairs, finding the largest of each pair\nand moving it to the lower position in the pair.\nThen iterate and add the largest of each pair (unless it is too large\n(i.e. makes the knapsack over full).\nThen, if at the end of this loop, that knapsack is not at least 1/2\nfull, then iterate through the smaller of the pairs, adding them,\nunless they overfill the knapsack.\n\nBecause there exists a factor of 2 approximation, this algorithm will\nterminate when either the solution is found or the entire list is\nadded during the 3rd loop, which will then constitute a solution\n(because one has to exist).\n\nPseudocode for the algorithm can be laid out as \n{\\singlespacing\n\\begin{algorithmic}\n  \\State $cap \\gets$ Knapsack size/capacity\n  \\For{$i = 1,3,\\dots,n$} \n  \\If{$k[i] \\le k[i+1]$}\n  \\State Swap($k[i],k[i+1]$)\n  \\EndIf\n  \\EndFor\n  \\State $Sz = 0$\n  \\State // Let's fill in the larger sizes first\n  \\For{$i = 1,3,\\dots,n$}\n  \\If{ $Sz + k[i] \\le cap$}\n  \\State $Sz \\gets Sz + k[i]$\n  \\EndIf\n  \\If{ $Sz \\ge \\frac{cap}{2}$}\n  \\State return\n  \\EndIf\n  \\EndFor\n  \\State // Now, start filling in the smaller sizes\n  \\For{$i = 2,4,\\dots,n$}\n  \\If{ $Sz + k[i] \\le cap$}\n  \\State $Sz \\gets Sz + k[i]$\n  \\EndIf\n  \\If{ $Sz \\ge \\frac{cap}{2}$}\n  \\State return\n  \\EndIf\n  \\EndFor\n\\end{algorithmic}\n}\nThe runtime for this algorithm is $O(\\frac{3}{2}n)$, because at the\nmost it will utilize all three for-loops which are each over only half\nthe length of the array.\n\\end{document}", "meta": {"hexsha": "f22ddaec7d15c0ee7fef2750b0afb15c4e2f7d01", "size": 16768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw/hw1/hw1.tex", "max_stars_repo_name": "aepound/advAlgo", "max_stars_repo_head_hexsha": "03d612282a86a8957df6b9197af036c6fc548b0b", "max_stars_repo_licenses": ["MIT"], "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/hw1/hw1.tex", "max_issues_repo_name": "aepound/advAlgo", "max_issues_repo_head_hexsha": "03d612282a86a8957df6b9197af036c6fc548b0b", "max_issues_repo_licenses": ["MIT"], "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/hw1/hw1.tex", "max_forks_repo_name": "aepound/advAlgo", "max_forks_repo_head_hexsha": "03d612282a86a8957df6b9197af036c6fc548b0b", "max_forks_repo_licenses": ["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.2622222222, "max_line_length": 72, "alphanum_fraction": 0.6572638359, "num_tokens": 5775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8918110353738529, "lm_q1q2_score": 0.6408504092524601}}
{"text": "%As explained in Section \\ref{sec:background}, comparing elements over $\\mathbb{F}_{p^d}$ boils down to their comparison over $\\mathbb{F}_p$. \nIn this section, we study the structure of basic comparison circuits over $\\mathbb{F}_p$ used in Section~\\ref{sec:background} to compare integers, namely $\\LT_{\\S}$ and $\\EQ_{\\S}$ for some $\\S \\subseteq [0, p-1]$. \n\n%Let $\\S$ be a subset of $[0,p-1]$ such that $\\S$ can be embedded canonically embedded into $\\F_p$.\nFor any choice of $\\S$, the corresponding equality function over $\\F_p$ is equal to\n\\begin{align*}\n  \\EQ_{\\S}(x,y) = 1 - (x-y)^{p-1}.\n\\end{align*}\nUnfortunately, $\\LT_{\\S}$ is not that simple and universal and we have to rely on Lagrange interpolation (Lemma~\\ref{lem:interpolation}) to compute it. \nYet, there are two different ways to evaluate it.\nThe first method (as done in \\cite{TLWRK20}) uses $\\S = [0,p-1]$ and directly interpolates $\\LT_{\\F_p}(x,y)$ as a bivariate polynomial over $\\F_{p}$.\nThe second approach (as done in \\cite{NGEG17} and \\cite{PoPETS:SFR20}) has $\\S = [0, (p-1)/2]$ and interpolates a univariate polynomial of $\\LT_{\\S}(z, 0)$ with $z = x - y$.\n%In this case, $x,y$ must belong to the set $[0, (p-1)/2]$. \n%However, these works evaluated $\\LT_{\\F_p}$ without exploiting its structure. \nIn this section, we show how to exploit the structure of these polynomials to speed-up their evaluation.\n\n\\subsection{Bivariate interpolation of $\\LT_\\S$.}\n\n  Let $\\S = [0,p-1]$.\n  The less-than function can be interpolated using Lemma~\\ref{lem:interpolation} and the following truth table.\n  \\begin{table}[h]\n    \\centering\n    \\begin{tabular}{c|ccccc}\n        $<$ & 0 & 1 & 2 & $\\cdots$ & $p-1$ \\\\\n        \\hline\n        0 & 0 & 1 & 1 & $\\cdots$ & 1 \\\\\n        1 & 0 & 0 & 1 & $\\cdots$ & 1 \\\\\n        2 & 0 & 0 & 0 & $\\cdots$ & 1 \\\\\n        $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\vdots$ & $\\ddots$ & $\\vdots$ \\\\\n        $p-1$ & 0 & 0 & 0 & $\\cdots$ & 0 \\\\\n    \\end{tabular}\n  \\end{table}\n    \n  In particular, the interpolation polynomial of $\\LT_\\S$ over $\\F_p$ is equal to\n  \\begin{align*}%\\label{eq:less_than_function}\n    P_{\\LT_\\S}(X,Y) &= \\sum_{a = 0}^{p-2} \\EQ_\\S(X,a)\\sum_{b = a+1}^{p-1} \\EQ_\\S(Y,b) \\nonumber\\\\\n    = \\sum_{a = 0}^{p-2}& \\left(1-\\left(X - a\\right)^{p-1}\\right) \\sum_{b = a+1}^{p-1} \\left(1-\\left(Y - b\\right)^{p-1}\\right).\n  \\end{align*}\n  Surprisingly, the total degree of $P_{\\LT_\\S}(X,Y)$ is only $p$ and its coefficients can be described by the following theorem.\n  \\begin{theorem} \\label{thm:less_than_total_degree}\n    Let $p>2$ be a prime number and $\\S = [0,p-1]$, then the interpolation polynomial of $\\LT_\\S$ over $\\F_p$ has the following form\n    \\begin{align*}\n      P_{\\LT_\\S}(X,Y) = Y^{p-1} - \\frac{p-1}{2} (XY)^{\\frac{p-1}{2}} + \\sum_{\\substack{i,j>0, \\\\ i \\ne j, \\\\ i+j \\le p}} a_{ij} X^i Y^j \n    \\end{align*}\n    where $a_{ij} = \\sum_{a=0}^{p-2} \\sum_{b=a+1}^{p-1} a^{p-1-i} b^{p-1-j} \\in \\F_p$.\n    The total degree of $P_{\\LT_\\S}(X,Y)$ is $p$.\n  \\end{theorem}\n  \\begin{proof}\n    See Appendix \\ref{app:proof_thm_less_than_total_degree}.\n  \\end{proof}\n  From the definition of $\\LT_\\S$, one can easily prove the following facts about $P_{\\LT_\\S}$:\n  \\begin{itemize}[label=--]\n    \\item $P_{\\LT_\\S} (X, 0) = 0$, thus $Y$ divides $P_{\\LT_\\S} (X, Y)$;\n    \\item $P_{\\LT_\\S} (X, X) = P_{\\LT_\\S} (Y,Y) = 0$, thus $(X - Y)$ divides $P_{\\LT_\\S} (X, Y)$;\n    \\item $P_{\\LT_\\S} (p-1, Y)=0$ thus $X + 1$ divides $P_{\\LT_\\S} (X, Y)$.\n  \\end{itemize}\n  Hence, there exists a bivariate polynomial $f(X,Y)$ of total degree $p - 3$ over $\\F_p$ such that:\n  \\begin{equation}\n    \\label{eq:decomposition-LT}\n    P_{\\LT_\\S} (X, Y) = Y(X - Y)(X + 1)f(X, Y).\n  \\end{equation}\n  The following theorem describes the structure of $f(X,Y)$.\n  \\begin{theorem}\\label{thm:decomposition-f}\n    Let $p$ be an odd prime and $\\S = [0,p-1]$.\n    Let $P_{\\LT_\\S} (X, Y)$ be the interpolation polynomial of $\\LT_\\S$ over $\\F_p$ and $P_{\\LT_\\S} (X, Y) = Y(X - Y)(X + 1)f(X, Y)$.\n    Then, for any $z \\in \\F_p$ we have\n    \\begin{equation}\n      \\label{eq:3}\n       f(z,z) = f(z,0) = f(p-1,z).\n    \\end{equation}\n    As a consequence, \n    %there exists a bivariate polynomials $f_1(X,Y)$ of total degree $p-5$ over $\\F_p$ such that:\n    %\\begin{align}\n    %  \\label{eq:dec-f}\n    %  f(X,Y) &= f(X,0) + Y(X-Y)f_1(X,Y) \\nonumber \\\\\n    %  &= f_0(X) + Y(X-Y)f_1(X,Y).\n    %\\end{align}   \n    %This decomposition can be applied recursively to $f_1(X,Y)$, so that \n    there exists $(p-1)/2$ polynomials $f_i(X)$ over $\\F_p$, $0\\leq i \\leq (p-3)/2$, such that:\n    \\begin{align}\\label{eq:decomposition-f-final}\n      f(X,Y) = \\sum_{i=0}^{(p-3)/2} f_i(X)Z^i,\n    \\end{align}\n    with $Z=Y(X-Y)$ and $\\deg (f_{i}(X)) = p-3 - 2i$.\n\n    % or equivalently a bivariate polynomials $f'_1$ of total degree $p-5$ over $\\F_p$ such that:\n    % \\begin{equation}\n    %   \\label{eq:dec-f'}\n    %   f(x,y) = f(p-1,y) + (x+1)(x-y)f'_1(x,y)\n    % \\end{equation}    \n  \\end{theorem}  \n\n  Since our proof of Theorem~\\ref{thm:decomposition-f} is quite long and with no real interest for the purpose of this work, we defer it to an extended version of this paper. \n  In our experiments, we used the decompositions~(\\ref{eq:decomposition-f-final}) of $f(X,Y)$ only for small $p$ (between $3$ and $7$), which you can find in Appendix~\\ref{app:decomposition-f}.\\newline\n  \n%   In order to show Eq. (\\ref{eq:3}) we will need the following lemma:\n\n%   \\begin{lemma}\\label{lem:structure-f}\n%     Let $p>3$ be an odd prime, $i\\in[0,p-2]$ and $f$ be the polynomial defined in Eq. (\\ref{eq:decomposition-LT}), then for any $z\\in[0,p-1]$ we have:\n\n%     $$ f(i,z) = f(p-1-z,p-1-i) = -\\displaystyle\\sum_{k=i+1}^{p-1}\\frac{1-(z-k)^{p-1}}{(i+1)z(z-i)} \\bmod p.$$\n%   \\end{lemma}\n\n%   \\begin{proof}\n%     We know that for any $z\\in[0,p-1]$ we have:\n%     $$\\LT_\\S(i,z) = \\left\\{\n%       \\begin{array}{l}\n%         0 ~\\text{ if }~ 0\\leq z\\leq i \\\\\n%         1 ~\\text{ otherwise}~\n%       \\end{array}\n%     \\right.$$\n%     Note that since $i<p-1$, $\\LT_\\S(i,\\cdot)$ is not the zero function. It can be interpolated by the univariate polynomial:\n%     $$P_{\\LT_\\S}(i,z) = \\displaystyle\\sum_{k=i+1}^{p-1}\\left[1-(z-k)^{p-1}\\right] \\bmod p. $$\n    \n%     Similarly:\n%     \\begin{align*}\n%       P_{\\LT_\\S}(x,p-1-i) &= \\displaystyle\\sum_{k=0}^{p-2}\\left[1-(x-k)^{p-1}\\right]\\displaystyle\\sum_{l=k+1}^{p-1}\\left[1-(p-1-i-l)^{p-1}\\right] \\\\\n%                           &= \\displaystyle\\sum_{k=0}^{p-2-i}\\left[1-(x-k)^{p-1}\\right]  \\bmod p\n%     \\end{align*}\n%     So:\n%     \\begin{align*}\n%       P_{\\LT_\\S}(p-1-z,p-1-i) &= \\displaystyle\\sum_{k=0}^{p-2-i}\\left[1-(p-1-z-k)^{p-1}\\right]  \\bmod p \\\\\n%                               &= \\displaystyle\\sum_{k=i+1}^{p-1}\\left[1-(k-z)^{p-1}\\right]  \\bmod p \\\\\n%                               &= \\displaystyle\\sum_{k=i+1}^{p-1}\\left[1-(z-k)^{p-1}\\right]  \\bmod p \\\\\n%                               &=  P_{\\LT_\\S}(i,z) \\bmod p.\n%     \\end{align*}\n%     Now let $A$ be the bivariate polynomial defined over $\\F_p$ by:\n%     $$A(x,y) = y(x-y)(x+1).$$\n%     We have:\n%     \\begin{align*}\n%       A(p-1-z,p-1-i) &= -(i+1)(-z+i)(-z) \\bmod p \\\\\n%                      &= -(i+1)z(z-i) \\bmod p\\\\\n%                      &= A(i,z) \\bmod p.\n%     \\end{align*}\n%     Again, note that since $i < p-1$, $A(i,z)\\neq 0 \\bmod p$.\n    \n%     Starting from Eq. (\\ref{eq:decomposition-LT}) we can write:\n%     \\begin{align*}\n%       P_i(z) =& A(i,z)f(i,z) = A(p-1-z,p-1-i)f(p-1-z,p-1-i) \\bmod p \\\\\n%       \\Leftrightarrow & A(i,z)f(i,z) - A(p-1-z,p-1-i)f(p-1-z,p-1-i) = 0 \\bmod p \\\\\n%       \\Leftrightarrow & A(i,z)(f(i,z) - f(p-1-z,p-1-i)) = 0 \\bmod p\n%     \\end{align*}\n%     Given that $A(i,z)\\neq 0 \\bmod p$ and that $\\F_p[z]$ is an integral domain we obtain what we want:\n\n%     $$ f(i,z) = f(p-1-z,p-1-i) \\bmod p. $$\n\n%     The last equality is obtained by dividing $P_{LT_\\S}(i,z)$ with $A(i,z)\\neq 0 \\bmod p$.\n%   \\end{proof}\n%   Now we can start the proof of Theorem \\ref{thm:decomposition-f}.\n%   \\begin{proof}[Theorem \\ref{thm:decomposition-f}]\n%     Equation (\\ref{eq:3}) says that the first column, the last line and the descending diagonal of the table of values of $f$ are equals (cf. Table \\ref{tab:values-f}).\n%     \\begin{table}[h]\n%       \\centering\n%       \\begin{tabular}{m{1.5em}|m{1em}m{1em}m{1em}m{1em}m{1em}m{1em}c}\n%         \\backslashbox{$x$}{$y$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\\\\n%         \\hline\n%         0 & \\bf{0} & 6 & 5 & 3 & 3 & 5 & 6 \\\\\n%         1 & \\bf{4} & \\bf{4} & 5 & 4 & 2 & 4 & 5 \\\\\n%         2 & \\bf{2} & 0 & \\bf{2} & 3 & 2 & 3 & 2 \\\\\n%         3 & \\bf{2} & 0 & 0 & \\bf{2} & 3 & 4 & 3 \\\\\n%         4 & \\bf{2} & 0 & 0 & 0 & \\bf{2} & 5 & 5 \\\\\n%         5 & \\bf{4} & 0 & 0 & 0 & 0 & \\bf{4} & 6 \\\\\n%         6 & \\bf{0} & \\bf{4} & \\bf{2} & \\bf{2} & \\bf{2} & \\bf{4} & \\bf{0} \\\\\n%       \\end{tabular}\n%       \\vspace{1em}\\caption{Values $f(x,y)$ for $x,y\\in\\F_7$.}\n%       \\label{tab:values-f}\n%     \\end{table}\n    \n%     Lemma \\ref{lem:structure-f} says that for any $0\\leq i< p-1$ the $i$-th row (starting from $y=0$) and the $p-1-i$-th column (starting from $x=p-1$) of the table are equals. Another consequence of Lemma \\ref{lem:structure-f} is that the values on any descending diagonal of the table form a palindrome (i.e. the values in the table are symmetric around the axis $x = p-1-y$). This is true in particular for the main descending diagonal $(x=y)$.\n\n%     Now let us show that for any $0\\leq i < p-1$ we have $f(i,0) = f(i,i)$. The case $i=0$ is trivial, for $i>0$ we know from Lemma \\ref{lem:structure-f} that:\n%     $$ f(i,z) = -\\displaystyle\\sum_{k=i+1}^{p-1}\\frac{1-(z-k)^{p-1}}{(i+1)z(z-i)} \\bmod p, $$\n%     which can be rewritten modulo $p$ as:\n%     \\begin{align*}\n%       f(i,z) & = -\\frac{p-1-i - \\displaystyle\\sum_{k=i+1}^{p-1}(z-k)^{p-1}}{(i+1)z(z-i)} = -\\frac{p-1-i - \\displaystyle\\sum_{k=i+1}^{p-1}\\displaystyle\\sum_{j=0}^{p-1}z^j k^{p-1-j}}{(i+1)z(z-i)} \\\\\n%              & = -\\frac{p-1-i - \\displaystyle\\sum_{j=0}^{p-1}\\left(\\displaystyle\\sum_{k=i+1}^{p-1} k^{p-1-j}\\right)z^j}{(i+1)z(z-i)}  = \\frac{\\displaystyle\\sum_{j=1}^{p-1}\\left(\\displaystyle\\sum_{k=i+1}^{p-1} k^{p-1-j}\\right)z^{j-1}}{(i+1)(z-i)}.\n%     \\end{align*}\n%     Similarly:\n%     \\begin{align*}\n%       f(i,z) & = -\\frac{p-1-i - \\displaystyle\\sum_{k=1}^{p-1-i}(z-i-k)^{p-1}}{(i+1)z(z-i)} = -\\frac{p-1-i - \\displaystyle\\sum_{k=1}^{p-1-i}\\displaystyle\\sum_{j=0}^{p-1}(z-i)^j k^{p-1-j}}{(i+1)z(z-i)} \\\\\n%              & = -\\frac{p-1-i - \\displaystyle\\sum_{j=0}^{p-1}\\left(\\displaystyle\\sum_{k=1}^{p-1-i} k^{p-1-j}\\right)(z-i)^j}{(i+1)z(z-i)}  = \\frac{\\displaystyle\\sum_{j=1}^{p-1}\\left(\\displaystyle\\sum_{k=1}^{p-1-i} k^{p-1-j}\\right)(z-i)^{j-1}}{(i+1)z}\n%     \\end{align*}\n\n%     So for any $0 < i < p-1$, from the first expression we obtain:\n%     $$f(i,0) = -\\frac{\\sum_{k=i+1}^{p-1} k^{p-2}}{i(i+1)},$$\n%     from the second expression we get:\n%     \\begin{align*}\n%       f(i,i) &= \\frac{\\sum_{k=1}^{p-1-i} k^{p-2}}{i(i+1)} = \\frac{\\sum_{k'=i+1}^{p-1} (p-k')^{p-2}}{i(i+1)} = \\frac{\\sum_{k'=i+1}^{p-1} (-k')^{p-2}}{i(i+1)} \\bmod p \\\\\n%       &= -\\frac{\\sum_{k'=i+1}^{p-1} (k')^{p-2}}{i(i+1)} = f(i,0).\n%     \\end{align*}\n\n%     At this point we have shown that for $0\\leq i<p-1$ we have $f(i,0) = f(i,i)$. \n%     This means that the first column and the descending diagonal are equals up to the last line. \n%     Since the values of the descending diagonal form a palindrome, the same applies to the values of the first column and thus of the last line. More precisely, for any $0\\leq i < p-1$ we have:\n%     $$f(i,0) = f(i,i) = f(p-1-i, p-1-i) = f(p-1-i, 0) = f(p-1, i)$$\n\n%     At this point the last thing we have to prove to get Eq. (\\ref{eq:3}) is that $f(0,0) = f(p-1,0) = f(p-1,p-1) \\bmod p$. Lemma \\ref{lem:structure-f} already gives us $f(0,0) = f(p-1,p-1)$, so we just have to prove the last one.\n\n%     We have:\n%     $$ P_{\\LT_\\S}(0,z)  = -\\sum_{j=1}^{p-1}\\left(\\sum_{k=1}^{p-1}k^{p-1-j}\\right)z^j  = z^{p-1} \\bmod p \\text{ (cf. Lemma \\ref{lem:sum_poly}).} $$\n\n%     Moreover, let $A(x,y) = y(x-y)(x+1)$, we have $A(0,z) = -z^2$. So from Eq.~(\\ref{eq:decomposition-LT}) we obtain $f(0,z) = -z^{p-3}$ and so $f(0,0) = f(p-1,p-1) = -1 \\bmod p$ if $p = 3$ and $0$ otherwise.\n\n%     To conclude we have to show that $f(p-1,0) = -1 \\bmod p$ if $p=3$ and $0$ otherwise. \n%     Since both $A$ and $\\LT_\\S$ vanish on the first column of the table ($y=0$) and the last line ($x=p-1$) we cannot use their values on these lines to derive the value of $f(p-1,0)$. So this time we will estimate $\\LT_\\S$ and $A$ on the ascending diagonal. Since $A(p-1-z,z) = z^2(1+2z) \\bmod p$ if we want to prove that $f(p-1,0) = 0 \\bmod p$ (resp. $1$ if $p=3$) we have to show that the coefficients of degree $0$, $1$ and $2$ of $P_{\\LT_\\S}(p-1-z,z)$ are equals to $0$, (resp $0, 1$ are equals to $0$ and the coefficient of degree $2$ is equal to $-1$).\n\n%     By definition, $\\LT_\\S(p-1,0) = P_{LT_\\S}(p-1,0) = 0 \\bmod p$, so the coefficient of degree $0$ is equal to $0$. Now let us have a look at the formal derivative of $P_{\\LT_\\S}(p-1-z,z)$. We have: \n%     $$ P_{LT_\\S}(p-1-z,z) = \\sum_{k=0}^{p-2}\\underbrace{[1-(1+z+k)^{p-1}]}_{=g_k(z)}\\underbrace{\\sum_{l=k+1}^{p-1}[1-(z-l)^{p-1}]}_{=h_k(z)} \\bmod p $$\n \n%   For $0\\leq k \\leq p-2$, we have $g_k(0) = 1-(1+k)^{p-1} = 0 \\bmod p$, and also $h_k(0) = \\sum_{l=k+1}^{p-1}[1-l^{p-1}] = 0 \\bmod p$ since $0<l\\leq p-1$. \n\n% Therefore $P'_{LT_\\S}(p-1,0) = \\sum_{k=0}^{p-2}\\left(g_k'(0)h_k(0) + g_k(0)h'_k(0) \\right) = 0 \\bmod p$ therefore the coefficient of degree $1$ is also equal to $0$. \n\n% Now let us consider the formal derivative at the second order of $P_{\\LT_\\S}(p-1-z)$:\n% $$P''_{\\LT_\\S}(p-1-z,z) = \\sum_{k=0}^{p-2}\\left(g_k''(z)h_k(z) + 2g_k'(z)h'_k(z) + g_k(z)h''_k(z) \\right).$$\n% Thus in $z=0$ we obtain: \n% \\begin{align*}\n%   P''_{\\LT_\\S}(p-1,0) & = 2\\sum_{k=0}^{p-2}g_k'(0)h'_k(0) = -2\\sum_{k=0}^{p-2}(1+k)^{p-2}\\sum_{l=k+1}^{p-1}l^{p-2} \\\\\n%                       &= -2\\left(\\sum_{k=1}^{(p-1)/2}k^{p-2}\\sum_{l=k}^{p-1}l^{p-2} + \\sum_{k=(p+1)/2}^{p-1}k^{p-2}\\sum_{l=k}^{p-1}l^{p-2}\\right) \\\\\n%                       & = -2\\left(\\sum_{k=1}^{(p-1)/2}k^{p-2}\\sum_{l=k}^{p-1}l^{p-2} + \\sum_{k=1}^{(p-1)/2}(-k)^{p-2}\\sum_{l=p-k}^{p-1}l^{p-2}\\right) \\\\\n%                       & = -2\\sum_{k=1}^{(p-1)/2}k^{p-2}\\left(\\sum_{l=k}^{p-1}l^{p-2} -  \\sum_{l=p-k}^{p-1}l^{p-2}\\right) \\\\\n%                       & = -2\\sum_{k=1}^{(p-1)/2}k^{p-2}\\sum_{l=k}^{p-1-k}l^{p-2} = -2\\sum_{k=1}^{(p-1)/2}k^{2p-4} \\\\\n%                       & = -2\\sum_{k=1}^{(p-1)/2}k^{p-3} = -\\sum_{k=1}^{(p-1)/2}k^{p-3} - \\sum_{k=1}^{(p-1)/2}(-k)^{p-3} \\\\\n%                       & = -\\sum_{k=1}^{p-1}k^{p-3}  \\bmod p\\\\\n%                       & = 1 ~\\text{ if } p = 3 ~\\text{ and }~ 0 ~\\text{ otherwise.}\n% \\end{align*}\n% The coefficient of degree 2 is equal to $P''_{\\LT_\\S}(p-1,0)/2 = -1 \\bmod 3$.\n% Thus overall $f(p-1,0) = f(p-1,p-1) = f(0,0)$ and we have proved Eq. (\\ref{eq:3}). The rest of the theorem is straightforward:\n% \\begin{itemize}\n% \\item $y$ and $(x-y)$ divide $f(x,y)-f(x,0) = f(x,y)-f(x,x) \\bmod p$ which implies (\\ref{eq:dec-f}). \n% \\item $x+1$ and $(x-y)$ divide $f(x,y)-f(p-1,y) = f(x,y)-f(y,y) \\bmod p$ which implies (\\ref{eq:dec-f'}).\n% \\end{itemize}\n% Note that when $p=3$ $f(x,y) = 1 \\bmod p.$\n% \\end{proof}\n\n\\textbf{Complexity analysis.}\nIn \\cite{TLWRK20}, the authors proposed to evaluate $P_{\\LT_S}(X,Y)$ by evaluating each monomials separately before summing them up. \nGiven $x,y \\in \\F_p$, they precompute the powers of $x$ and $y$ up to $p-1$ for a total of $2p-4$ non-scalar multiplications. \nThen, another $p-1$ non-scalar multiplications are needed to evaluate each monomial $((\\sum_i c_i X^i)Y^j)_{j}$ where $c_i$'s are scalars in $\\F_p$, before summing them together to get the final result. \nOverall their evaluation of $P_{\\LT_\\S}(X,Y)$ requires $3p-5$ non-scalar multiplications.\n\nFollowing this idea and using the decomposition of $f(X,Y)$ given in Eq. (\\ref{eq:decomposition-f-final}) one needs:\n\\begin{itemize}\n\\item $2$ multiplications to compute $(X+1)Z$ if $p\\geq 3$ or $1$ multiplication when $p=2$;\n\\end{itemize}\nand then for $p\\geq 5$:\n\\begin{itemize}\n\\item $p-4$ multiplications to compute the $X^i$'s for $2\\leq i \\leq p-3$ required to compute the terms $f_i(X)$;\n\\item $(p-5)/2$ multiplications to compute the $Z^i$ for $2\\leq i \\leq (p-3)/2$;\n\\item $(p-5)/2$ multiplications to compute the products $f_i(X)\\cdot Z^i$;\n\\item $1$ final multiplication $(X+1)Z\\cdot f(X,Y)$.\n\\end{itemize}\nOverall, at most $2p-6$ non-scalar multiplications are needed to homomorphically evaluate $P_{\\LT_\\S}(X,Y)$ for \\mbox{$p \\geq 5$}. \nThis number can be slightly reduced by optimizing the way of computing $f_i$'s. \nFor instance, it can be done with only $6$ multiplications for $p=7$, (see Appendix \\ref{app:decomposition-f}), which is smaller than $2p-6=8$.\n\nOverall, for $p\\geq 5$, our method saves $p+1$ multiplications over the method of Tan et al.~\\cite{TLWRK20}. \nHowever, the complexity of the bivariate circuit remains linear in $p$ which is unpractical for performing homomorphic comparisons using large digits (i.e. a large $p$).\n  \n\\subsection{Univariate interpolation of $\\LT_\\S$}\nUnlike bivariate polynomials, it is possible to evaluate univariate polynomials of degree $p-1$ in $\\mathcal{O}(\\sqrt{p})$ non-scalar multiplications using the Paterson-Stockmeyer algorithm~\\cite{SIAM:PS73}. The Paterson-Stockmeyer algorithm has been used in various works related to homomorphic encryption in order to speed-up polynomial evaluation. As a recent example, it was applied by Shaul et al \\cite{PoPETS:SFR20} in the context of top-$k$ selection, which uses small-number comparison as a subroutine. However, in our case the study of the structure of $\\LT_\\S$ as a univariate polynomial will allow us to speed-up its evaluation for large $p$ beyond what could be achieved using only the Paterson-Stockmeyer algorithm.\n\nTo evaluate $\\LT_S$ as a univariate polynomial, we compute the difference $x-y$ of the two input values and check its sign.\nTo compute the sign function using finite field arithmetic, we need to split finite field elements into two classes:  negative ($\\F_p^-$) and non-negative ($\\F_p^+$).\nIn addition, for any $x, y \\in \\S$ the following property should hold:\n\\begin{align*}\n  x - y \\in \n  \\begin{cases}\n    \\F_p^+ \\text{ if } \\LT_\\S(x,y) = 0, \\\\\n    \\F_p^- \\text{ if } \\LT_\\S(x,y) = 1.\n  \\end{cases}\n\\end{align*}   \nIt is easy to see that these constraints are satisfied by $\\S = [0, (p-1)/2]$.\nLet us split $\\F_p$ into $\\F_p^+ = [0, (p-1)/2]$ and $\\F_p^- = [-(p-1)/2, -1]$.\nNotice that for any $x, y \\in \\S$, their difference $x - y$ belongs to $\\F_p^-$ if and only if $x < y$.\n\nLet $\\chi_{\\F_p^-}(z)$ be a function that outputs $1$ if $z$ is negative and $0$ otherwise.\nAccording to Lemma~\\ref{lem:interpolation}, $\\chi_{\\F_p^-}(z)$ is equal to\n\\begin{align*}\n  \\chi_{\\F_p^-}(z) = \\sum_{a=-\\frac{p-1}{2}}^{-1} 1 - (z - a)^{p-1}.\n\\end{align*}\n  Combining the above facts, the $\\LT_\\S$ function can be interpolated by the following polynomial over $\\F_p$\n  \\begin{align*}\n    Q_{\\LT_\\S}(X,Y) = \\sum_{a=-\\frac{p-1}{2}}^{-1} 1 - (X - Y - a)^{p-1}\\,.\n  \\end{align*}\n  The following theorem describes all the coefficients of this interpolation polynomial.\n  \\begin{theorem}\\label{th:univariate}\n    For an odd prime $p$ and $\\S = [0, (p-1)/2]$, the $\\LT_\\S$ function can be interpolated by the following polynomial over $\\F_p$\n    \\begin{align}\\label{eq:univariate_circuit}\n      Q_{\\LT_\\S}(X,Y) = \\frac{p+1}{2} (X-Y)^{p-1} + \\sum_{i=1, \\text{odd}}^{p-2} c_i (X-Y)^i.\n    \\end{align}\n    where $c_i = \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-1-i}$.\n  \\end{theorem}\n  \\begin{proof}\n    See Appendix \\ref{app:proof-lem-univariate}\n  \\end{proof}\n  \\begin{remark}\\label{rem:sign_function}\n    The polynomial $Q_{\\LT_\\S}(X,Y)$ yields the interpolation polynomial of the sign function $\\sign_{\\S'}$ defined on $\\S' = [-(p-1)/2, (p-1)/2]$ as $\\sign_{\\S'}(x) = 1$ if $x < 0$ and $\\sign_{\\S'}(x) = 1$ if $x \\ge 0$.\n    In particular, we have \n    \\begin{align}\\label{eq:sign_interpolation}\n      Q_{\\sign_{\\S'}}(X) = Q_{\\LT_\\S}(X,0)\\,.\n    \\end{align} \n  \\end{remark}\n  \\textbf{Complexity analysis.} The above theorem implies that the less-than function can be expressed by a univariate polynomial of degree $p-1$.\n  In general, such polynomials are evaluated in $p-1$ multiplications according to Horner's method.\n  \n  To reduce the number of non-scalar multiplications, we can resort to the Paterson-Stockmeyer algorithm~\\cite{SIAM:PS73} that requires $\\sqrt{2(p-1)} + \\log_2 (p-1) + \\mathcal{O}(1)$ such multiplications.\n  However, we can improve this complexity by exploiting the fact that the polynomial in~(\\ref{eq:univariate_circuit}) has only one coefficient with an even index, the leading one.\n  Thus, if $Z=X-Y$, we can rewrite~(\\ref{eq:univariate_circuit}) as follows\n  \\begin{align*}\n    \\alpha_{p-1} Z^{p-1} + Z \\sum_{i=0, \\text{even}}^{p-3} \\alpha_{i+1} Z^i =  \\alpha_{p-1} Z^{p-1} + Z g(Z^2)\n  \\end{align*}\n  where $\\alpha_i = \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-1-i}$ and $g(X)$ is a polynomial of degree $(p-3)/2$.\n  To evaluate $g(X)$, the Paterson-Stockmeyer algorithm requires $\\sqrt{p-3} + \\log_2 \\left(\\frac{p-3}{2}\\right) + \\mathcal{O}(1)$ non-scalar multiplications.\n  Furthermore, the preprocessing phase of this algorithm computes the powers $Z^2, Z^4, \\dots, Z^{2k}$ and $Z^{4k}, Z^{8k}, \\dots, Z^{2^r k}$ with $2k(2^r-1) = p-3$.\n  We can use these powers to compute the leading term in $r$ non-scalar multiplications, namely\n  \\begin{align*}\n    Z^2 Z^{2k} Z^{4k} \\cdots Z^{2^r k} = Z^{2 + 2k(2^r-1)} = Z^{2 + p - 3} = Z^{p-1}.\n  \\end{align*}\n  Since the optimal $k$ is about $\\sqrt{(p-3)/2}$, we obtain that $r$ must be about $\\log_2 \\sqrt{p-3}$.\n  Hence, the total non-scalar complexity of evaluating~(\\ref{eq:univariate_circuit}) is equal to\n  \\begin{align*}\n    \\sqrt{p-3} + \\frac{3 \\log_2 \\left(p-3\\right)}{2} + \\mathcal{O}(1).\n  \\end{align*}\n  \n  \\begin{remark}\n    A careful reader can notice that the leading term of~(\\ref{eq:univariate_circuit}) is equal to $(X-Y)^{p-1}$, which is the heaviest part of the equality circuit $\\EQ_\\S(X,Y)$.\n    Thus, we can get $\\EQ_\\S(X,Y)$ almost for free (at the cost of one homomorphic subtraction) after evaluating $\\LT_\\S(X,Y)$, which saves $\\mathcal{O}(\\log (p-1))$ non-scalar multiplications.\n\n    This feature of the univariate circuit allows to compute all the equality operations while comparing large integers using the less-than function $\\LT$ from~(\\ref{eq:general_lex_order}).\n    This saves $\\mathcal{O}((d'-1)(k-1) \\log (p-1))$ homomorphic multiplications, thus leading to a better running time than for the bivariate circuit.\n\n    The downside of the univariate circuit is that only $(1/2)^d$ of the plaintext space is used to encode input integers in comparison to the bivariate method.\n  \\end{remark}\n\n\\subsection{Min/max function}\n\n  Given the less-than function $\\LT$ defined on some set, one can compute the minimum of two elements $x, y$ of this set in the following generic way\n  \\begin{align}\\label{eq:generic_minimum}\n    \\min(x,y) &= x \\cdot \\LT(x,y) + y \\cdot (1 - \\LT(x,y)) \\nonumber\\\\\n    &= y + (x-y) \\cdot \\LT(x,y)\\,.\n  \\end{align}\n  Notice that the input difference $x - y$ naturally emerges in this expression, thus hinting that the univariate circuit from~(\\ref{eq:univariate_circuit}) might be useful here.\n  Indeed, by replacing $X - Y$ with a variable $Z$ we obtain the univariate polynomial representation of the minimum function on the set $\\S=[0,(p-1)/2]$ \n  \\begin{align*}\n    Q_{\\min_\\S}(X,Y) &= Y + Z \\cdot Q_{\\LT_S}(X,Y) \\\\\n    & = Y + \\frac{p+1}{2} Z + \\sum_{i=1}^{\\frac{p-1}{2}} Z^{2i} \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-2i} \\\\\n    & = \\frac{p+1}{2} (X+Y) + \\sum_{i=1}^{\\frac{p-1}{2}} Z^{2i} \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-2i} \\\\\n    & = \\frac{p+1}{2} (X+Y) + g(Z^2)\\,,\n  \\end{align*}\n  where $g(X)$ is a polynomial of degree $(p-1)/2$. \n  As a result, $\\min_S(x,y)$ can be computed with $\\mathcal{O}(\\sqrt{p-1})$ non-scalar multiplications via the Paterson-Stockmeyer algorithm.\n\n  Following the above reasoning, the maximum function can be computed with the following polynomial\n  \\begin{align*}\n    Q_{\\max_\\S}(X,Y) &= \\frac{p+1}{2} (X+Y) - \\sum_{i=1}^{\\frac{p-1}{2}} Z^{2i} \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-2i}.\n  \\end{align*}\n  \\begin{remark}\n    Maximum and minimum functions are basic building blocks in the design of neural networks.\n    For example, one of the most popular activation functions in neural networks is the rectifier, or ReLU, which is equal to $\\max(x,0)$.\n    By analogy with~(\\ref{eq:generic_minimum}), we have $\\max(x,0) = x \\cdot (1 - \\sign_{\\S'}(x))$ where $\\S' = [-(p-1)/2,(p-1)/2]$ (see Remark~\\ref{rem:sign_function}).\n    Thus, Eq.~(\\ref{eq:sign_interpolation}) yields the following interpolation polynomial of the ReLU function on $\\S'$\n    %The above polynomial of $\\max_\\S$ yields the following simple polynomial for the ReLU function defined on $\\S=[0,(p-1)/2]$\n    \\begin{align*}\n      Q_{\\ReLU_{\\S'}}(X) &= X \\cdot (1 - Q_{\\sign_{\\S'}}(X))\\\\\n      &= \\frac{p+1}{2} X - \\sum_{i=1}^{\\frac{p-1}{2}} X^{2i} \\sum_{a=1}^{\\frac{p-1}{2}} a^{p-2i}.\n    \\end{align*}\n  \\end{remark}\n\n  \\subsection{Impact on the overall complexity}\n  In this section, we summarize the complexities of our method as compared to the work of Tan et al. for the evaluation of the less-than function using the lexicographical order method described in Section \\ref{sec:background}.\n\n  For fixed $p$ and $d$, Tan et al.~\\cite[Section 4.4]{TLWRK20} determined that the depth of the circuit evaluating the less-than function of two $b$-bits integers is equal to\n  \\begin{equation}\n    \\label{eq:circuit-depth}\n    \\lfloor \\log_2 d \\rfloor + \\lfloor \\log_2 (p-1) \\rfloor + \\lfloor \\log_2 (\\log_p 2^b)/d) \\rfloor + 4.\n  \\end{equation}\n  Note that our algorithms do not decrease the depth of the circuit. \n  Similarly, Tan et al. showed that the number of homomorphic multiplications required to evaluate the less-than function of two $b$-bit integers with the bivariate interpolation is\n  $$ d\\cdot\\left(T+ \\lceil\\log_2(p-1)\\rceil + \\lceil \\log_2 d \\rceil \\right) + \\lfloor\\log_2(\\log_p 2^b)/d)\\rfloor+2. $$\n  where $T$ is the number of homomorphic multiplications required to evaluate the comparison circuit over $\\mathbb{F}_p$.\n  In the work of Tan et al. $T = 3p-5$, while in our case it is $T = 2p-6$.\n\n  The univariate method saves even more multiplications since one can extract $1 - \\EQ_\\S(x,y)$ while computing $\\LT_\\S(x,y)$. \n  Hence, we obtain $\\EQ_\\S(x,y)$ almost for free when evaluating the lexicographical order (Remark 2). Thus, in this case the comparison of two $b$-bits integers requires\n  $$ d\\cdot\\left(T + \\lceil \\log_2 d \\rceil \\right) + \\lfloor\\log_2(\\log_p 2^b)/d)\\rfloor+2. $$\n  with $T\\approx \\sqrt{2p-4}+3(\\log_2(2p-4))/2$ by using the Paterson-Stockmeyer algorithm.\n  \n% \\subsection{Lexicographic order}\\label{subsec:lexicographic_order}\n%   Let $\\vx=(x_0,x_1,\\ldots,x_{\\ell-1})$ and $\\vy=(y_0,y_1,\\ldots,y_{\\ell-1}) \\in \\F_\\fieldcard^\\ell$ for the lexicographical order $<$ defined by the choice of $\\S$:\n%   \\begin{align*}\n%     \\vx < \\vy \\Leftrightarrow \\exists i\\in[0,\\ell-1] \\text{ such that } x_i < y_i \\text{ and } \\forall j > i ~~ x_j = y_j\\,.\n%   \\end{align*}\n%   This order induces a function $\\LT_{\\F_\\fieldcard}(\\vx, \\vy)$ that returns $1$ if $\\vx < \\vy$ and $0$ otherwise. \n%   As done in~\\cite{TLWRK20}, we can employ $\\EQ_{\\F_\\fieldcard}$ and $\\LT_{\\F_\\fieldcard}$ to compute $\\LT_{\\F_\\fieldcard}(\\vx, \\vy)$ as follows\n%   \\begin{align*}\n%     \\LT_{\\F_\\fieldcard}(\\vx, \\vy) = \\sum_{i=0}^{\\ell-2} \\LT_{\\F_\\fieldcard}(x_{i}, y_{i}) \\prod_{j=i+1}^{\\ell-1} \\EQ_{\\F_\\fieldcard}(x_{j}, y_{j}) + \\LT_{\\F_\\fieldcard}(x_{\\ell-1}, y_{\\ell-1}).\n%   \\end{align*}\n%   Notice that the multiplicative depth of this function solely depends on the products of the equality functions.\n%   In fact, these products compare subvectors $\\vx_i = (x_i, x_{i+1},\\dots,x_{\\ell-1})$ and $\\vy_i = (y_i, y_{i+1},\\dots,y_{\\ell-1})$ for $i \\in [1,\\ell-1]$.\n%   Thus, we can rewrite $\\LT_{\\F_\\fieldcard}$ as\n%   \\begin{align}\\label{eq:general_lex_order}\n%     \\LT_{\\F_\\fieldcard}(\\vx, \\vy) = \\sum_{i=0}^{\\ell-2} \\LT_{\\F_\\fieldcard}(x_{i}, y_{i}) \\EQ_{\\F_\\fieldcard}(\\vx_{i+1}, \\vy_{i+1}) + \\LT_{\\F_\\fieldcard}(x_{\\ell-1}, y_{\\ell-1})\n%   \\end{align}\n%   with the equality function $\\EQ_{\\F_\\fieldcard}(\\vx_{i+1}, \\vy_{i+1})$ that returns $1$ if $\\vx_{i+1} = \\vy_{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%   \\begin{algorithm}[t]\n%     \\KwIn{\n%     $\\ct_\\vx$ -- a ciphertext encrypting $\\vx \\in \\F^\\ell_\\fieldcard$,\n%     $\\ct_\\vy$ -- a ciphertext encrypting $\\vy \\in \\F^\\ell_\\fieldcard$.\n%     }\n%     \\KwOut{$\\ct$ -- a ciphertext containing the output of $\\EQ_{\\F_\\fieldcard, e}(\\vx_{i+1},\\vy_{i+1})$ in the $i$th SIMD slot}\n%     $\\ct_1 \\leftarrow \\Shift(\\ct_\\vx, 1)$ // removes the value $x_0$ and shifts $\\vx$ to the left\\\\\n%     $\\ct_2 \\leftarrow \\Shift(\\ct_\\vy, 1)$ // removes the value $y_0$ and shifts $\\vy$ to the left\\\\\n%     $\\ct \\leftarrow \\Sub(\\ct_1, \\ct_2)$ // $(x_i - y_i), i \\in [1,\\ell-1]$\\\\\n%     $r_0,r_1,\\dots,r_{\\ell-1} \\leftarrow \\udist(\\F_{\\fieldcard^e})$ //\\todo{define uniform distribution}\\\\ \n%     $\\pt_r \\leftarrow \\pt(r_0,r_1,\\dots,r_{\\ell-1})$\\\\\n%     $\\ct \\leftarrow \\ct \\cdot \\pt_r$ // $r_i(x_i - y_i), i \\in [1,\\ell-1]$\\\\\n%     $k \\leftarrow 1$// $\\sum_{j=i}^{\\ell-1} r_i(x_i - y_i), i \\in [1,\\ell-1]$\\\\\n%     \\While{$k < \\ell-1$}{\n%       $\\ct_{tmp} \\leftarrow \\Shift(\\ct, k)$\\\\\n%       $\\ct \\leftarrow \\ct + \\ct_{tmp}$\\\\\n%       $k \\leftarrow 2k$\\\\\n%     }\n%     $\\ct \\leftarrow \\Power(\\ct, \\fieldcard^e-1)$ //$\\princhar_{\\fieldcard^e}\\left(\\sum_{j=i}^{\\ell-1} r_i(x_i - y_i)\\right), i \\in [1,\\ell-1]$ \\\\\n%     $\\ct \\leftarrow 1 - \\ct$\\\\\n%     \\textbf{Return} $\\ct$.\n%     \\caption{Homomorphic circuit computing $\\EQ_{\\F_\\fieldcard, e}(\\vx_{i+1},\\vy_{i+1})$ in parallel.}\\label{alg:vector_equalities_circuit}\n%   \\end{algorithm}\n  \n%   Let us go back to the lexicographic order in equation~(\\ref{eq:general_lex_order}).\n%   Assume that we have a ciphertext $\\ct_{\\LT}$ containing $\\LT_{\\F_\\fieldcard}(x_i, y_i)$ in the $i$th slot (\\todo{elaborate on that}) and the output $\\ct_{\\EQ}$ of Algorithm~\\ref{alg:vector_equalities_circuit}.\n%   We set the $\\ell-1$ slot of $\\ct_{\\EQ}$ to $1$ and multiply it by $\\ct_{\\LT}$.\n%   The resulting ciphertext contains all the products $\\LT_{\\F_\\fieldcard}(x_{i}, y_{i}) \\EQ_{\\F_\\fieldcard}(\\vx_{i+1}, \\vy_{i+1})$ for any $i \\in [0,\\ell-2]$ and $\\LT_{\\F_\\fieldcard}(x_{\\ell-1}, y_{\\ell-1})$, which can be summed in the same way as in the while circuit of Algorithm~\\ref{alg:vector_equalities_circuit}.\n%   As a result, we obtain a ciphertext with the output of $\\LT_{\\F_\\fieldcard}(\\vx, \\vy)$ in the first SIMD slot.\n\n%   \\subsubsection{Comparing large integers.}\n%   Since any integer $z$ can be represented in base $\\fieldcard$ as $z = \\sum_{i=0}^{\\ell-1} z_i q^i$, we can encode $z$ into SIMD slots as a vector $(z_0,z_1,\\dots,z_{\\ell-1}) \\in \\F_{\\fieldcard}^\\ell$.\n%   As shown above, we can compare such vectors using the lexicographic order function in~(\\ref{eq:general_lex_order}) and thus compare integers larger than $\\fieldcard$.\n\n%   \\todo{Incorporate the following into the complexity analysis.} \n%   We can obtain ciphertexts encrypting $(x,x,\\ldots, x)$ and $(y,y,\\ldots, y)$ with $2\\log_2(q-1)\\texttt{Rot}$ and $2\\log_2(q-1)\\texttt{Add}$. \n\n%   From there we can obtain encryptions of $(x,x-1,\\ldots, x-q-2)$ and $(y-1,y-2,\\ldots, y-q-1)$ with $2\\texttt{Add}$. We can apply $f$ to these vectors in parallel with a depth of $\\log (p-1) + \\log d$ for a cost of $2(\\log (p-1) + wt(p-1) + d - 2) \\texttt{Mult}$. This can be minimized by choosing $p = 2^d + 1$ for some $d$.\n\n%   With $2$ more $\\texttt{Sub}$ we obtain encryptions of $(1-f(x), 1-f(x-1), \\ldots, 1-f(x-q-2))$ and $(1-f(y-1), 1-f(y-2), \\ldots, 1-f(y-q-1))$. From there we can get an encryption of the different partial sums in $\\log_2(q-1)\\texttt{Rot}$, $\\log_2(q-1)\\texttt{Select}$ and $\\log_2(q-1)\\texttt{Add}$. The algorithm works as follow:\n\n%   \\begin{center}\n%     \\begin{tikzpicture}[scale=0.8]\n%       \\newcommand\\y{-4};\n      \n%       \\draw (0,2) -- (16,2);\n%       \\draw (0,0) -- (16,0);    \n%       \\foreach \\x in {0,...,8}{\n%         \\draw (2*\\x,0) -- (2*\\x,2);\n%       }\n%       \\foreach \\x in {0,...,7}{\n%         \\node at (2*\\x+1,1) {$x_\\x$};\n%       }\n\n%       \\draw (0,2+\\y) -- (16,2+\\y);\n%       \\draw (0,\\y) -- (16,\\y);    \n%       \\foreach \\x in {0,...,8}{\n%         \\draw (2*\\x,0+\\y) -- (2*\\x,2+\\y);\n%       }\n\n%       \\node at (1,1+\\y) {$x_0 + x_1$};\n%       \\node at (3,1+\\y) {$x_1 + x_2$};\n%       \\node at (5,1+\\y) {$x_2 + x_3$};\n%       \\node at (7,1+\\y) {$x_3 + x_4$};\n%       \\node at (9,1+\\y) {$x_4 + x_5$};\n%       \\node at (11,1+\\y) {$x_5 + x_6$};\n%       \\node at (13,1+\\y) {$x_6 + x_7$};\n%       \\node at (15,1+\\y) {$x_7$};\n\n%       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n      \n%       \\draw (0,2+2*\\y) -- (16,2+2*\\y);\n%       \\draw (0,0+2*\\y) -- (16,0+2*\\y);    \n%       \\foreach \\x in {0,...,8}{\n%         \\draw (2*\\x,0+2*\\y) -- (2*\\x,2+2*\\y);\n%       }\n\n%       \\node at (1,1+2*\\y) {$\\begin{array}{c}\n%           x_0 + x_1  \\\\\n%           + x_2 + x_3\n%         \\end{array}$};\n%       \\node at (3,1+2*\\y) {$\\begin{array}{c}\n%           x_1 + x_2  \\\\\n%           + x_3 + x_4\n%         \\end{array}$};\n%       \\node at (5,1+2*\\y) {$\\begin{array}{c}\n%           x_2 + x_3  \\\\\n%           + x_4 + x_5\n%         \\end{array}$};\n%       \\node at (7,1+2*\\y) {$\\begin{array}{c}\n%           x_3 + x_4  \\\\\n%           + x_5 + x_6\n%         \\end{array}$};\n%       \\node at (9,1+2*\\y) {$\\begin{array}{c}\n%           x_4 + x_5  \\\\\n%           +x_6 + x_7\n%         \\end{array}$};\n%       \\node at (11,1+2*\\y) {$\\begin{array}{c}\n%           x_5 + x_6  \\\\\n%           + x_7\n%         \\end{array}$};\n%       \\node at (13,1+2*\\y) {$x_6 + x_7$};\n%       \\node at (15,1+2*\\y) {$x_7$};\n\n%       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n      \n%       \\draw (0,2+3*\\y) -- (16,2+3*\\y);\n%       \\draw (0,0+3*\\y) -- (16,0+3*\\y);    \n%       \\foreach \\x in {0,...,8}{\n%         \\draw (2*\\x,0+3*\\y) -- (2*\\x,2+3*\\y);\n%       }\n\n%       \\node at (1,1+3*\\y) {$\\begin{array}{c}\n%           x_0 + x_1  \\\\\n%                               + x_2 + x_3 \\\\\n%                               + x_4 + x_5 \\\\\n%                               + x_6 + x_7\n%         \\end{array}$};\n%       \\node at (3,1+3*\\y) {$\\begin{array}{c}\n%           x_1 + x_2  \\\\\n%                               + x_3 + x_4 \\\\\n%                               + x_5 + x_6 \\\\\n%                               + x_7 \\\\\n%         \\end{array}$};\n%       \\node at (5,1+3*\\y) {$\\begin{array}{c}\n%           x_2 + x_3  \\\\\n%                               + x_4 + x_5 \\\\\n%                               + x_6 + x_7\n%         \\end{array}$};\n%       \\node at (7,1+3*\\y) {$\\begin{array}{c}\n%           x_3 + x_4  \\\\\n%                               + x_5 + x_6 \\\\\n%                               +x_7\n%         \\end{array}$};\n%       \\node at (9,1+3*\\y) {$\\begin{array}{c}\n%           x_4 + x_5  \\\\\n%           +x_6 + x_7\n%         \\end{array}$};\n%       \\node at (11,1+3*\\y) {$\\begin{array}{c}\n%           x_5 + x_6  \\\\\n%           + x_7\n%         \\end{array}$};\n%       \\node at (13,1+3*\\y) {$x_6 + x_7$};\n%       \\node at (15,1+3*\\y) {$x_7$};\n\n%       \\foreach \\x in {2,...,8}\n%       \\draw[->,thick = 2pt] (2*\\x-0.1-1,2) to[bend right] (2*\\x-3+0.1,2);\n\n%       \\foreach \\x in {3,...,8}\n%       \\draw[->,thick = 2pt] (2*\\x-0.1-1,2+\\y) to[bend right] (2*\\x-5+0.1,2+\\y);\n\n%       \\foreach \\x in {5,...,8}\n%       \\draw[->,thick = 2pt] (2*\\x-0.1-1,2+2*\\y) to[bend right] (2*\\x-9+0.1,2+2*\\y);\n\n%   \\end{tikzpicture}\n%   \\end{center}\n\n%   From there we just have to compute the scalar product of the two vectors with $1\\texttt{Mult} + \\log_2(q-1)\\texttt{Rot} + \\log_2(q-1)\\texttt{Add}$. \\newline\n\n%   So overall we can compute $<$ over $\\mathbb{F}_q$ for $q = p^d$ in:\n\n%   \\begin{itemize}\n%   \\item $4\\log_2 (q-1) \\texttt{Rot}$\n%   \\item $(4\\log_2 (q-1) + 4) \\texttt{Add}$\n%   \\item $(2(\\log (p-1) + wt(p-1) + d - 2) + 1) \\texttt{Mult}$\n%   \\item $(\\log_2 (q-1) + 1) \\texttt{Select}$\n%   \\end{itemize}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main_pets\"\n%%% End:\n", "meta": {"hexsha": "77738a01193a1051d7997add7856fb6d35b61c3a", "size": 36900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/comparison-circuit.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/comparison-circuit.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/comparison-circuit.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": 63.0769230769, "max_line_length": 728, "alphanum_fraction": 0.5776151762, "num_tokens": 14408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.810478926981208, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.6407081704211174}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{setspace}\n\n\\usepackage{amsmath, amsfonts, amssymb, graphicx, color, fancyhdr, mathrsfs, tikz-cd, mdframed, enumitem, framed, adjustbox, bbm, upgreek, xcolor, hyperref}\n\\usepackage[framed,thmmarks]{ntheorem}\n\\usepackage[style=alphabetic]{biblatex}\n%Set the bibliography file\n\\bibliography{sources}\n\n%Replacement for the old geometry package\n\\usepackage{fullpage}\n\n%Input my definitions\n\\input{./mydefs.tex}\n\n%Shade definitions\n\\theoremindent0cm\n\\theoremheaderfont{\\normalfont\\bfseries} \n\\def\\theoremframecommand{\\colorbox[rgb]{0.9,1,.8}}\n\\newshadedtheorem{defn}[thm]{Definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%% Customize Below %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%header stuff\n\\setlength{\\headsep}{24pt}  % space between header and text\n\\pagestyle{fancy}     % set pagestyle for document\n\\lhead{Notes on the Grassmannian} % put text in header (left side)\n\\rhead{Nico Courts} % put text in header (right side)\n\\cfoot{\\itshape p. \\thepage}\n\\setlength{\\headheight}{15pt}\n\\allowdisplaybreaks\n\n% Document-Specific Macros\n\\DeclareMathOperator{\\Gr}{Gr}\n\\DeclareMathOperator{\\Flag}{Flag}\n\\DeclareMathOperator{\\GL}{GL}\n\\newcommand{\\Alg}{\\mathbf{Alg}}\n\\newcommand{\\CRing}{\\mathbf{CRing}}\n\\DeclareMathOperator{\\inv}{inv}\n\\newcommand{\\detq}{\\operatorname{det}_q}\n\\let\\k\\relax\n\\newcommand{\\k}{\\mathbbm{k}}\n\n\\begin{document}\n%make the title page\n\\title{Notes on the Grassmannian \\vspace{-1ex}}\n\\author{Nico Courts}\n\\date{Summer 2019}\n\\maketitle\n\n\\begin{abstract}\n\tThese notes are my summary of the realization of the Grassmanian $\\Gr(n,k)$ as a quotient of \n\tthe Lie group $\\GL(n,\\k)$. In particular the focus will be on $\\k=\\bbR$ or $\\bbC$. I also talk about quantum \n\tdeformations of $\\GL(n,\\k)$ and $\\Gr(n,k)$.\n\\end{abstract}\n\n\\section*{Vista: Where We're Headed}\nThe idea that $\\GL_n$ acts on vector subspaces of a Euclidean space should be unsurprising and natural, but \nthe upshot to considering this viewpoint is that is allows us to consider this object from the perspective of smooth \nmanifold theory. This gives us some great machinery to grasp onto to prove some nice properties \nabout $\\Gr(n,k)$.\n\nEventually I will lead us slightly astray by investigating a ``quantum analog'' of $\\Gr(n,k)$. This $q$-deformation\nis related closely to the kinds of structures I have been thinking about recently: specifically quantum groups. One can think of \nthese as ``deformations'' of groups in some controlled way.\n\n\\section{The Grassmannian as a Lie group quotient}\nIn the following, let $\\k=\\bbR$ or $\\bbC$ and let $V=\\k^n$. For a great introduction to this theory see \\cite{LeeISM},\n(specifically chapters 1, 7, and 21), which serves as the primary source for this section.\n\\subsection{Smooth Manifolds}\nRecall that a smooth manifold is a topological manifold equipped with a \\textbf{smooth structure}: that is, an atlas comprised \nof smoothly-compatable charts (ones where the transition functions are smooth as maps of Euclidean spaces).\n\\subsection{The general linear Lie group} \nLet $G=\\GL(V)$, initially considered just as a group. In fact, one can apply to $G$ a smooth structure very naturally\nby recognizing $\\GL(V)\\subseteq M_{n\\times n}(\\k)$, the latter of which is identified with the Euclidean space $\\k^{n^2}$,\nwhose smooth structure is the obvious one (the identity map).\n\nThat $G$ itself is a smooth manifold comes from the fact that $\\GL(V)=\\det^{-1}(\\k\\setminus\\{0\\})$, which is \nitself an open set as the inverse image of an open set under a continuous map. So then $G$ is a (codimension zero) open (smooth) submanifold\nof $M_{n\\times n}(k)$ whose smooth structure is inherited from the ambient space.\n\nIn fact, the algebraic and geometric structure of $G$ come together in a very nice way to define what is called \na \\textbf{Lie group:}\n\\begin{defn}\n\tLet $G$ be a smooth manifold. Then a \\textbf{Lie group} is $G$ along with a group structure given by maps $m:G\\times G\\to G$ and $i:G\\to G$\n\t(representing multiplication and inverse maps) such that $m$ and $i$ are smooth maps (smooth in charts).\n\\end{defn}\n\n\\begin{prop}\n\t$G$ is a Lie group.\n\\end{prop}\n\\begin{prf}\n\tSince we have already defined the smooth and group structures on $G$, it suffices to show that \n\t$m$ and $i$ (matrix multiplication and the inverse map) are smooth maps.\n\n\tMultiplication is smooth since if we consider the $i^{th}$ component function of $m$, where $i=an+b$ for $1\\le a,b\\le n$, we get (for $\\mathbf x$ and $\\mathbf y$ in $\\k^{n^2}$)\n\t\\[m_i(\\mathbf x,\\mathbf y)=\\sum_{k=1}^{n}\\mathbf x_{an+k}\\mathbf y_{kn+b}\\]\n\twhich is a polynomial in the $x_i$ and $y_i$ and is thus (clearly) smooth.\n\n\tThat the inverse map is also smooth follows via similar reasoning: since $\\det$ is smooth (again a polynomial in the entries),\n\tcomputing the adjugate matrix is a smooth operation and so via Cramer's rule (since $\\det A\\ne 0$)\n\t\\[i(A)=\\frac{1}{\\det A}\\operatorname{adj}A\\]\n\tis also a smooth operation.\n\\end{prf}\n\n\\subsection{The action on \\texorpdfstring{$\\Gr(n,k)$}{Gr(n,k)}}\nThe first thing to notice is that there is a natural action \nof $G$ on the set of $k$-dimensional subspaces of $V$ in the following way: let $A\\in\\GL(V)$ and let $W\\le V$ be a $k$-dimensional \nsubspace. Then $A(W)$ is also $k$-dimensional since $A$ is invertible\\footnote{If you are not convinced, remember that $A$ being invertible means all minors are nonsingular,\nso by extending a basis for $W$ to $V$ and looking at $A$ in this basis, the top-left $k\\times k$ matrix defines an isomorphism \nof $W$ onto some other subspace of $V$.}.\n\\begin{prop}\n\tThe action defined above gives a group action of $\\GL(V)$ on $\\Gr(n,k)$.\n\\end{prop}\n\\begin{prf}\n\tThis is clear since the identity matrix $I_n$ fixes subspaces and since matrix multiplication is associative.\n\\end{prf}\n\n\\subsection{Defining a smooth structure on the Grassmanian}\nAs we are working in the context of smooth manifolds, we need to make some sense of how this action fits into the theory of smooth group actions.\nNormally,\n\\begin{defn}\n\tIf $G$ is a Lie group and $M$ is a smooth manifold, we say $G$ acts smoothly on $M$ if $G$ acts on $M$ as a set and the map \n\t\\[\\rho:G\\times M\\to M\\]\n\tgiven by \n\t\\[\\rho(g,m)=g.m\\]\n\tis a smooth map.\n\\end{defn}\nIn this case, we don't have a smooth structure (yet!) on $\\Gr(n,k)$, so we will define one:\n\n\\subsubsection{Stabilizers}\nOur first step is to show that the stabilizer of an arbitrary $W\\in\\Gr(n,k)$, denoted $G_W$, is a closed Lie subgroup (that is a Lie group and closed smooth submanifold). \nTo this end:\n\\begin{thm}[Closed Subgroup Theorem]\\label{thm-closed-subgroup}\n\tSuppose $G$ is a Lie group and $H\\subseteq G$ is a subgroup that is also a closed subset of $G$. Then $H$ is an embedded \n\tLie subgroup.\n\\end{thm}\n\\begin{rmk}\n\tThe proof of this theorem is two pages of Lie theory and is a little involved for this talk. Jack does \n\ta great job (as always) in his proof (cf. \\cite[Thm. 20.12]{LeeISM})\n\\end{rmk}\n\n\\noindent Using this theorem we start by proving something about a particular subset:\n\\begin{prop}\\label{prop-GW}\n\tFix some basis $\\calB$ for $V$. Let $W\\le V$ be the subspace of $\\k^n$ by setting the last $(n-k)$ coordinates in this basis to zero (which is isomorphic to $\\k^k$). Then \n\tthe stabilizer $G_W$ of $W$ is \n\t\\[G_W=\\left\\{\\begin{pmatrix}\n\t\tA & B\\\\ 0 & D\n\t\\end{pmatrix}:A\\in\\GL_k(\\k),\\ D\\in\\GL_{n-k}(\\k),\\ B\\in M_{k\\times n-k}(\\k)\\right\\}\\]\n\tand this set is a closed Lie subgroup of $\\GL(V)$.\n\\end{prop}\n\\begin{prf}\n\tWe begin by noticing that $G_W$ as above is precisely the stabilizer of $W$. But because we picked \n\t$W$ in the way we did, we know immediately that $\\calA\\in\\GL(V)$ fixes $W$ if the $i^{th}$ coordinate\n\tof $\\calA(\\mathbf x)$ is zero for all $\\mathbf x=(x_1,\\dots,x_k,0,\\dots,0)$. Since that $x_i$ are arbitrary,\n\twe get that $\\calA$ is block upper triangular as above. That $A$ and $D$ are invertible comes from the fact that \n\t\\[\\det\\calA=\\det A\\det D\\ne 0.\\]\n\tTherefore the stabilizer of $W$ is contained in $G_W$. The reverse inclusion is clear.\n\n\tThat $G_W$ is a subgroup of $\\GL(V)$ then follows from group theory. In light of thm.~\\ref{thm-closed-subgroup},\n\tproving that $G_W$ is a Lie subgroup amounts to showing that $G_W$ forms a closed subset of $\\GL(V)$. But this is clear because \n\tthis is inverse image of all of $\\GL_k(\\k)$ under $F:\\GL(V)\\to\\GL_k(\\k)$ that maps a matrix to the $k\\times k$ minor in the upper left corner.\n\n\tEquivalently, $G_W$ is defined by the closed condition $\\calA_{ij}=0$ if $i\\ge k_1$ and $j\\le k$. That every such matrix has the form of $G_W$ is \n\tclear as argued above.\n\n\tThus $G_W$ is closed, so is a closed Lie subgroup of $G$.\n\\end{prf}\n\nSo we have shown that a particular stabilizer $G_{\\k^k}$ is a closed Lie subgroup, but in fact this holds for \\textit{any $W\\in\\Gr(n,k)$:}\n\\begin{cor}\n\tFor any $W\\in\\Gr(n,k)$, $G_W$ is a closed Lie subgroup of $G$.\n\\end{cor}\n\\begin{prf}\n\tSimply choose a new basis for $V$ such that all vectors in $W$ are of the form \n\t\\[(v_1,\\dots,v_k,0,\\dots,0)\\]\n\tand apply prop.~\\ref{prop-GW}.\n\\end{prf}\n\n\\subsubsection{The Quotient Manifold Theorem}\nRecall from point-set topology that a proper map is one that pulls back compact sets to compact sets.\n\\begin{defn}\n\tAn action of a Lie group $G$ on a smooth manifold $M$ is \\textbf{proper} if the map \n\t\\[G\\times M\\to M\\times M\\qquad \\text{via}\\qquad (g,p)\\mapsto(g.p,p)\\]\n\tis a proper map.\n\\end{defn}\n\\begin{rmk}\n\tJack (\\cite[Ex. 21.3]{LeeISM}) says that this is a \\textit{strictly weaker} condition than saying\n\t$(g,p)\\mapsto g.p$ is proper.\n\\end{rmk}\n\\begin{thm}[Quotient Manifold Theorem]\\label{thm-QMT}\n\tLet $G$ be a Lie group acting \\textit{smoothly, freely, and properly} on a smooth manifold $M$. Then \n\tthe orbit space $M/G$ is a topological manifold of dimension $\\dim M-\\dim G$ and has a unique smooth structure \n\tmaking the quotient map $\\pi:M\\to M/G$ a smooth submersion.\n\\end{thm}\n\\begin{prf}\n\tAs before, see Jack's proof \\cite[thm. 21.10]{LeeISM}.\n\\end{prf}\n\\begin{rmk}\n\tIn case this wasn't obvious, this is a rather high-powered result and is the primary facilitator of what follows.\n\\end{rmk}\n\n\\subsubsection{Homogeneous Spaces}\n\\begin{defn}\n\tA smooth manifold $M$ endowed with a \\textit{transitive, smooth} action by a Lie group $G$ is called\n\ta \\textbf{homogeneous space.}\n\\end{defn}\nThen we use the quotient manifold theorem to construct a homogeneous space for ourselves (following part of the proof of \\cite[thm. 21.17]{LeeISM}):\n\\begin{prop}\n\tLet $W$ be an arbitrary element in $\\Gr(n,k)$. Then if $G=\\GL(V)$, $G/G_W$ is a homogeneous space given by the action\n\t\\[g\\cdot (g'G_W)=(gg')G_W\\]\n\\end{prop}\n\\begin{prf}\n\tConsider the action of $G_W$ on $G$ by left multiplication. This action is free since if $hg=g$, we get $h=e$. The action is a restriction of \n\t$G$ on itself by left multiplication, which is smooth by virtue of being a Lie group, so the action is smooth.\n\n\tTo see the action is proper, we use the fact (proved in \\cite[prop. 21.5(a,b)]{LeeISM}) that the action is proper if and only if $(h_i)$ is a sequence in $G_W$ and \n\t$(g_i)$ are a sequence in $G$, if both $(h_i)$ and $(h_ig_i)$ converge then the $(g_i)$ converge.\n\n\tLet $(g_i)$ be a convergent sequence in $G$ and $(h_i)$ a sequence in $G_W$ such that $(h_ig_i)$ converges. Then by the continuity of \n\tthe $G$ action on itself, $h_i=(h_ig_i)g_i^{-1}$ converges to a point in $G$. Since $G_W$ is closed in $G$, this limit converges in $G_W$.\n\n\tThus we can apply thm~\\ref{thm-QMT} to say that $G/G_W$ has a unique smooth manifold structure making the quotient map $\\pi:G\\to G/G_W$ a smooth submersion. The action \n\t\\[g\\cdot g'G_W=(gg')G_W\\]\n\tis transitive and smooth, giving us our homogeneous space.\n\\end{prf}\n\\subsubsection{Bringing it home}\nNow that we have that $G/G_W$ is a smooth manifold, consider the map\n\\[F:G/G_W\\to \\Gr(n,k)\\]\nbe defined by \n\\[F(A\\cdot G_W)=A(W).\\]\n\n\\begin{lem}\n\t$F$ defined as above is a $G$-equivariant bijection.\n\\end{lem}\n\\begin{prf}\n\tThis is a well-defined map since if $gG_W=g'G_W$, we get that $g=g'h$ for some $h\\in G_W$, thus\n\t\\[F(gG_W)=g\\cdot W=g'hW=g'W=F(g'G_W).\\]\n\n\tThen that this map is surjective follows since the action of $G$ on $\\Gr(n,k)$ has a single orbit. That \n\tthe map is injective follows since if the images of the same, this means precisely that $gW=g'W$, so $g^{-1}g'\\in G_W$,\n\tproving $gG_W=g'G_W$.\n\n\t$G$-equivariance is a simple consequence of the fact \n\t\\[g\\cdot F(g'G_W)=g\\cdot (g'W)=(gg')W=F(gg'G_W)=F(g(g'G_W)).\\]\n\\end{prf}\n\n\\noindent Now we can give $\\Gr(n,k)$ a smooth structure such that $F$ is a diffeomorphism\\footnote{Open sets are precisely the images of open sets of $G/G_V$ and the smooth \nstructure is the one pulled back through $F$.}. Notice now that the action of $G$ on $\\Gr(n,k)$ is smooth since we can write \n\\[g\\cdot V=F(g\\cdot F^{-1}(V))\\]\nsince $F$ and the action of $G$ on $G/G_W$ is smooth.\n\nWe still need to establish that such a smooth structure is, in some sense, \\textit{the} structure that makes \nthe action provided into a smooth action. This will be the smooth structure we give the Grassmannian.\n\nWe need one more theorem from smooth manifolds to finish this off:\n\\begin{thm}[Equivariant Rank Theorem]\n\tLet $M$ and $N$ be smooth manifolds and $G$ be a Lie group. If $F:M\\to N$ is a smooth, bijective, $G$-equivariant map with respect to \n\ta smooth, transitive action of $G$ on $M$ and any smooth action of $G$ on $N$, then $F$ is a diffeomorphism.\n\\end{thm}\n\\begin{prf}\n\tSee \\cite[thm 7.25]{LeeISM}.\n\\end{prf}\n\\begin{lem}\n\tThere is only one smooth structure on $X=\\Gr(n,k)$ such that the action of $G$ on $X$ is smooth.\n\\end{lem}\n\\begin{prf}\n\tLet $\\tilde X$ be $X$ with any other smooth structure. Then if $G$ acts smoothly on $\\tilde X$, the (smooth) action $\\theta^{(W)}:G\\to \\tilde X$ given by $\\theta^{(W)}(g)=g\\cdot W$ \n\tdescends to the quotient to give us a smooth map $\\calF:G/G_W\\to \\tilde X$, which as before can be shown to be a $G$-equivariant bijection.\n\n\tBut then by the equivariant rank theorem since the action of $G$ on $G/G_W$ is smooth and transitive, and the action of $G$ on $\\tilde X$ is smooth,\n\tthe map $\\calF$ is a diffeomorphism. But then in particular since $F$ gave us a diffeomorphism from $G/G_W$ to $X$, \n\twe have a diffeomorphism $X\\cong \\tilde X$, so the smooth structure on $X$ is unique.\n\\end{prf}\n\\subsection{Denouement: \\texorpdfstring{$\\Gr(n,k)$}{Gr(n,k)} is compact.}\nI found a neat proof of this online \\href{https://math.stackexchange.com/questions/148088/compactness-of-the-grassmannian}{here}.\n\\begin{prop}\n\t$\\Gr(n,k)$ is compact.\n\\end{prop}\n\\begin{prf}\n\tLet $S=\\{v\\in V=\\k^n: \\|v\\|=1\\}$. Notice that $S\\cong \\bbS^{n-1}$, the $n-1$ sphere in $\\k^n$, which is compact. Then $S^d=S\\times \\cdots\\times S$ is compact as well.\n\n\tConsidering $S^d$ as some choice of $d$ unit vectors in $\\k^n$, we can consider the map \n\t\\[S^d\\to\\k^{\\binom{d}{2}}\\qquad\\text{via}\\qquad (v_1\\dots,v_d)\\mapsto (v_1\\cdot v_2,v_1\\cdot v_3,\\dots,v_1\\cdot v_n,v_2\\cdot v_3,\\dots,v_{n-1}\\cdot v_n)\\]\n\tand notice that pulling back $\\mathbf 0$ in this map gets us a (closed whence) compact subspace $C$ of $S^d$ corresponding to the \n\tsets of $d$ orthonormal vectors in $\\k^n$.\n\n\tFinally define the equivalence relation on $C$ where $c_1\\sim c_2$ if $\\operatorname{span} c_1=\\operatorname{span} c_2$. Then the quotient \n\t$C/\\sim$ is precisely $\\Gr(n,k)$ which, as a quotient of a compact space, is compact.\n\\end{prf}\n\n\\section{Aside: Quantized Grassmanians}\nIn this section I will take a little time to develop some of the things I have been learning about quickly,\nspecifically developing non-commutative algebraic geometry by relying on intuitions from traditional algebraic geometry \nwhile ``deforming'' things in a controlled way so that we can use our intuition to develop analogous ideas.\n\n\\subsection{Algebra vs. Geometry}\nThe discussion that follows is a relatively constructive method for $q$-deforming the Grassmannian and studying the action it \ninherits from $\\GL_q(n)$. It gives a good flavor for the field, but is very strongly rooted in algebra.\n\nThat is, the methods we describe take the coordinate ring of the Grassmannian and deform it purely in the realm of algebra, with the understanding \nthat there is some parallel geometric structure that is being analogously twisted.\n\nLate in my research, I found a paper by Aaron Lauve \\cite{lauve} takes the results of Taft and Towber and reimagines them in a context that \npreserves a certain level of geometry. I haven't had time to read it in its entirety but it may be a good place to look for those interested in the geometry.\n\n\\subsection{Hopf Algebras}\nThe leading idea here is that Hopf algebras lie at the heart of a lot of modern algebra---especially representation theory. Sometimes you are working with \na Hopf algebra without knowing it!\n\nLet's begin with a definition:\n\\begin{defn}\n\tA \\textbf{Hopf algebra} is a $k$-vector space $A$ equipped with maps \n\t\\begin{gather*}\n\t\t\\mu:A\\otimes A\\to A\\\\\n\t\t\\eta:k\\to A\\\\\n\t\t\\Delta:A\\to A\\otimes A\\\\\n\t\t\\varepsilon:A\\to k\\\\\n\t\tS:A\\to A\n\t\\end{gather*}\n\tsuch that $\\mu$ and $\\eta$ form an associative algebra structure on $A$, $\\Delta$ and $\\varepsilon$ form a coassociative coalgebra structure on $A$,\n\t$\\mu$ is a coalgebra morphism, $\\Delta$ is an algebra morphism (so far we have defined a bialgebra) and furthermore $S:A\\to A$ is an antihomomorphism:\n\t\\[S(ab)=S(b)S(a)\\]\n\tand such that all the maps satisfy the following:\n\t\\[\\mu\\circ S\\otimes\\id\\circ \\Delta(a)=S(a_1)a_2=a_2S(a_2)=\\mu\\circ \\id\\otimes S\\circ\\Delta(x)=\\eta\\circ\\varepsilon(x)\\]\n\\end{defn}\n\\begin{rmk}\n\tWe used Sweedler notation above to simplify things although it looks deceptively simple to the uninitiated.\n\\end{rmk}\n\\begin{rmk}\n\tIn shorter terms, \n\\end{rmk}\n\n\\subsubsection{Examples of Hopf algebras}\nThese algebras pop up relatively frequently! For instance, the tensor, symmetric, and exterior algebras on a vector space are all \nreadily made into Hopf algebras.\n\nI am a representation theorist, so my primary examples tend to revolve around \nthe group algebra $k[G]$ of a group. It is a Hopf algebra where you define the Hopf algebra structure by making all \nelements of $G$ grouplike\\footnote{$\\Delta(x)=x\\otimes x$, $\\varepsilon(x)=1$ and $S(x)=x^{-1}$} and extending $k$-linearly.\n\nYou can also dualize things somewhat and consider the algebra of regular functions on $G$, denoted $kG$ or $k(G)$. When $G$ is finite,\nthese are isomorphic but when $G$ is infinite these can be quite different. In either of these contexts one can interchange ``group''\nwith ``group scheme'' or ``algebraic group''. A quite nice treatment of the affine case (that is when the Hopf algebra is finite dimensional over a field)\ncan be found in \\cite{waterhouse}. If you are interested in a highly representation-theoretic treatment of algebraic groups, you can can check out \\cite{jantzen-algebraic}\nor \\cite{Milne}.\n\nFinally the last way these arise in nature is in the universal enveloping algebra $\\calU(\\frakg)$ of a Lie algebra $\\frakg$. One can find the theory here developed in Jantzen's \nother book \\cite{jantzen-quantum}.\n\n\\subsection{Quantum deformations of Hopf algebras}\nIn all of the above examples, the Hopf algebra is either commutative or cocommutative and in fact you get some nice equivalences of categories \nbetween, for instance, group schemes over a field $k$ and commutative Hopf algebras over $k$. The ``quantum perspective'' is the tendency to \nask the question: \\textit{what about the non-commutative, non-cocommutative Hopf algebras?}\n\nIn some way, the study of quantum groups is the attempt to consider the Hopf algebras that fall in the gaps between the more ``natural'' ones.\n\n\\subsection{The idea}\nThe primary source for this section is Taft and Towber's \\textit{Quantum deformation of flag schemes and Grassmann schemes} \\cite{quantum-flag}.\nOur tact here is to build up an algebra (thought of as the ring of functions on the flag or Grassmannian scheme) and through deformation of this algebra,\n$q$-deform the space.\n\n\\begin{rmk}\n\tGenerally when working with vector spaces one can more-or-less forget about which basis is chosen when working in coordinates. Unfortunately here\n\tthe commutativity (or lack thereof) of a quantum deformation is highly dependent on the choice of \\textit{ordering} of any basis. Thus we will be considering commutative rings $\\k$ and \n\t$\\k$-algebras freely generated by some fixed \\textbf{ordered} basis $\\calB=\\{v_1,\\dots,v_n\\}$. \n\n\tIn what follows I will suppress the basis $\\calB$ (e.g. write $\\Flag^n(\\calB)$ as $\\Flag^n$) but remember that it is vital to the construction.\n\\end{rmk}\n\n\\subsection{The affine flag scheme \\texorpdfstring{$\\Flag^n(\\calB)$}{Flag-n(B)}}\n\\begin{rmk}\n\tI will admit that here is the most difficult part for me: defining these objects\\footnote{As well as seeing why these objects are what their names imply they should be} requires some geometry \n\tthat is beyond my understanding at the moment. I will do my best, but the geometers among you may notice some \n\tholes in my justification. Corrections are warmly welcomed.\n\\end{rmk}\nThe idea here is to define the scheme $\\Flag^n:=\\Flag^n(\\calB):\\CRing\\to\\Set$ which assigns to any commutative ring $\\k$ the (commutative, associative, unital) $\\k$-algebra\n$\\Flag^n(\\k)$ generated over $\\k$ by the elements of $\\Lambda^\\ast(\\calB)$\n\\[v_{i_1}\\wedge\\cdots\\wedge v_{i_r}\\qquad (1\\le r\\le n,\\ \\forall j,\\  1\\le i_j\\le n)\\]\nsubject to the relations: $v_{i_1}\\wedge\\cdots\\wedge v_{i_s}=0$ if two $i_k$ coincide and if $\\sigma\\in\\frakS_n$,\n\\[v_{i_{\\sigma 1}}\\wedge\\cdots\\wedge v_{i_{\\sigma s}}=(\\operatorname{sgn}\\sigma)\\  v_{i_1}\\wedge\\cdots\\wedge v_{i_s}\\]\ntogether with the relation \n\\[\\sum_{1\\le \\lambda_1\\le\\cdots\\le\\lambda_r\\le t+r}(-1)^{\\sum \\lambda_i}\\bigwedge_{k\\ne \\lambda_i \\forall i}v_{k}\\times_{\\Lambda^+(\\calB)}(v_{\\lambda_1}\\wedge\\cdots\\wedge v_{\\lambda_r}\\wedge v_{j_1}\\wedge\\cdots\\wedge v_{j_{s-r}})=0\\]\nfor all $1\\le r\\le s\\le t\\le n$ and all choices of $i_1,\\dots,i_{t+r}$ and $j_1,\\dots,j_{s-r}$.\n\n\\subsubsection{The grading}\nThis algebra admits a $P(n)$ grading where $P(n)$ is the semigroup (here no inverses) of nonincreasing sequences of positive integers\n\\[(\\alpha_1,\\dots,\\alpha_k)\\]\nwith $n\\ge \\alpha_1\\ge\\cdots\\ge \\alpha_1\\ge 1$ where multiplication is defined by (disjoint) union and sorting the multiset. The $P(n)$ grading determines the ``\\textbf{shape}'' of a monomial in \n$\\Flag^n(\\k)$ in the following way: we can write each monomial $\\omega\\in\\Flag^n(\\k)$ as $\\omega_1\\cdots\\omega_r$ where $\\omega_i\\in\\Lambda^{\\alpha_i}(\\calB)$\nand such that $n\\ge\\alpha_1\\ge\\cdots\\ge\\alpha_r\\ge 1$. For notation, if $\\alpha=(\\alpha_1,\\dots,\\alpha_r)$, write \n\\[\\Flag^\\alpha(\\k)=\\Lambda^\\alpha(\\calB,\\k)=\\Lambda^\\alpha(\\calB)\\]\nto be the $\\k$-span of all products of shape $\\alpha$.\n\nThis gives us a graded algebra structure (called the \\textbf{shape algebra})\n\\[\\Lambda^+(\\calB)=\\bigoplus_{\\alpha\\in P(n)}\\Lambda^\\alpha(\\calB)\\]\nof $\\Flag^n(\\k)$.\n\nThe upshot here is that each $\\Lambda^\\alpha$ inherits a natural $\\GL(n,\\k)$ action by acting on each $v_i$ independently.\n\nThen defining a deformation of this algebra amounts to deforming $\\GL(n,\\k)$.\n\n\\subsection{The affine Grassmann scheme \\texorpdfstring{$\\Gr^{t,n}(\\calB)$}{Gr(t,n)(B)}}\nWe define the \\textbf{affine Grassmann scheme} $\\Gr^{t,n}:=\\Gr^{t,n}(\\calB)$ to be a closed subscheme of $\\Flag^n$ such that \n$\\Gr^{t,n}(\\k)$ is the $\\k$-subalgebra of $\\Flag^n(\\k)$ generated by the $t$-fold wedges in $\\calB$. Notice this also inherits a grading, \nbut this time we can view it as a $\\bbZ$-grading since all monomials in $\\Gr^{t,n}(\\k)$ are of shape $(t,t,\\dots,t)$.\n\n\\subsection{Quantized \\texorpdfstring{$\\GL(n)$}{GL(n)}}\nLet $q$ be an indeterminate (often thought of as an element in the base ring [e.g an odd root of unity] and always as a \\textit{deformation parameter})\nand let $\\k_q:=\\k[q,q^{-1}]$, the Laurent polynomials in $q$. To proceed we need the \\textit{(strict) inversion statistic} seen in the combinatorics of $\\frakS_n$.\n\\begin{defn}\n\tIf $\\sigma\\in\\frakS_n$, let \n\t\\[\\inv\\sigma=\\#\\{(i,j)|1\\le i\\le j\\le n,\\ \\sigma(i)>\\sigma(j)\\}\\]\n\\end{defn}\n\nThen we can go on to define $M_q(n,\\k)$ to be the $\\k_q$-algebra generated by $n^2$ elements $X_i^j$ for $1\\le i,j\\le n$\nsubject to the $q$-commutativity relations\n\\begin{equation} \n\\begin{gathered}\n\tX_{k}^jX_i^j=qX_i^jX_{k}^j,\\qquad \\text{if } i<k\\\\\n\tX_i^kX_i^j=qX_i^jX_i^k,\\qquad\\text{if } j<k\\\\\n\tX_k^lX_i^j=X_i^jX_k^l+(q-q^{-1})X_i^lX_k^j,\\qquad\\text{if } i<k \\text{ and } j<l\\\\\n\tX_k^lX_i^j=X_i^jX_k^l\\qquad\\text{otherwise.}\n\\end{gathered} \\label{eqn:qcomm}\n\\end{equation}\n\nWe define the \\textbf{$q$-determinant} $\\det_q$ to be (thinking of $\\mathbf X=(X_i^j)$ as a matrix)\n\\[\\detq(\\mathbf X)=\\detq=\\sum_{\\sigma\\in\\frakS_n}(-q)^{-\\inv\\sigma} X_1^{\\sigma 1}\\cdots X_n^{\\sigma n}\\]\nand can therefore define the $q$-analog of $\\GL(n,\\k)$ (written $\\GL_q(n,\\k)$) to be the $\\k_q$-algebra generated by \nthe $X_i^j$ and an indeterminate $D$ satisfying the relations in (1) above as well as \n\\[D\\cdot\\detq =\\detq\\cdot D=1\\in\\k\\]\nas well as $DX_i^j=X_i^jD$ for all $i$ and $j$.\n\nThe coalgebra structure given by $\\Delta(X_i^j)=\\sum_k X_i^k\\otimes X_k^j$, $\\Delta(D)=D\\otimes D$,\n$\\varepsilon(X_i^j)=\\delta_i^j$ and $\\varepsilon(D)=1$.\n\nThe antipode $S$ is given as \n\\[S(X_i^j)=(-q)^{j-i}\\ |X^{1\\cdots\\hat i\\cdots n}_{1\\cdots\\hat j\\cdots n}|_q\\ D\\]\nwhere in general $|X^{i_1\\cdots i_s}_{j_1\\cdots j_s}|_q$ denotes the $q$ determinant of the $s\\times s$ matrix formed by the rows $j$ and the columns $i$ of $\\mathbf X$ in that order.\nFinally $S(D)=\\detq$. This gives us a Hopf algebra structure on $\\GL_q(n,\\k)$ and thus realizes $\\GL_q(n)$ as a quantum group.\n\nNotice that we can give $\\k$ a $\\k_q$-module structure by the evaluation map $ev:\\k_q\\to\\k$ sending $q$ to 1. Under this structure,\nwe get \n\\[\\GL_q(n,\\k)\\otimes_{\\k_q}\\k\\cong \\k[\\GL(n,\\k)]\\]\nso indeed this quantization collapses to the regular $\\k$ functions on $\\GL(n)$, indicating we have found the (perhaps \\textit{a}) ``correct'' object.\n\n\\subsection{The quantized Grassmannian}\nThen we can define $\\Gr_q^{t,n}$ to be the $\\k_q$ algebra generated by the $t$-fold wedges (notice that we are losing the intuition of the wedge product now so this is just a notational designation)\nin $\\Lambda_q^+(\\calB)$,\nthe quantized shape algebra where we replace the usual relations with\n\\[v_{i_{\\sigma 1}}\\wedge\\cdots\\wedge v_{i_{\\sigma s}}=(-q)^{\\inv\\sigma}\\  v_{i_1}\\wedge\\cdots\\wedge v_{i_s}\\]\nas well as the quantum Young symmetry relation\n\\[\\sum_{1\\le \\lambda_1\\le\\cdots\\le\\lambda_r\\le t+r}(-q)^{-\\inv(i_1,\\dots,i_{\\hat\\lambda_i}\\cdots i_{t+r},i_{\\lambda_1},\\dots,i_{\\lambda_r})}\\bigwedge_{k\\ne \\lambda_i \\forall i}v_{k}\\times_{\\Lambda_q^+(\\calB)}(v_{\\lambda_1}\\wedge\\cdots\\wedge v_{\\lambda_r}\\wedge v_{j_1}\\wedge\\cdots\\wedge v_{j_{s-r}})=0\\]\nalong with a (rather nasty) $q$-commutativity relation (i.e. $\\Lambda_q^+$ is no longer commutative)\n\\begin{align*}\n\t&(v_{j_1}\\wedge\\cdots\\wedge v_{j_r})\\cdot (v_{i_1}\\wedge\\cdots\\wedge v_{i_r})=\\\\\n\t&\\sum_{1\\le \\lambda_1\\le\\cdots\\le\\lambda_r\\le s}(-q)^{\\inv(\\lambda_1,\\dots,\\lambda_r,1,\\dots,\\hat\\lambda_i,\\dots,s)}(v_{j_1}\\wedge\\cdots\\wedge v_{j_r}\\wedge v_{i_1}\\wedge\\cdots\\wedge\\hat v_{i_{\\lambda_i}}\\wedge\\cdots v_{i_s})(v_{\\lambda_1}\\wedge\\cdots\\wedge v_{\\lambda_r})\n\\end{align*}\n\nThe punchline (after many pages of theorems and lemmas) is that $\\Gr_q^{t,n}(\\k)$ inherits a natural $\\GL_q(n)$-module structure as well as a $\\GL_q(n)$-comodule structure \nfrom the structure map \n\\[\\rho:\\Lambda_q^t(\\calB)\\to \\GL_q(n,\\k)\\otimes \\Lambda_q^t(\\calB)\\]\nwhere \n\\[\\rho(v_{\\lambda_1}\\wedge\\cdots\\wedge v_{\\lambda_t})=\\sum_{1\\le \\mu_1\\le\\cdots\\le \\mu_t\\le n}|X^{\\mu_1,\\dots,\\mu_t}_{\\lambda_1,\\dots,\\lambda_t}|_q\\otimes(v_{\\mu_1}\\wedge\\cdots\\wedge v_{\\mu_t})\\]\n\nFurthermore, this comodule structure is the unique comodule structure extending the natural comodule structure of $\\GL_q(n)$ on itself (cf. the ``normal representation'').\n\nFinally the good stuff: let $L_q^t(\\calB)$ denote the (unital) $\\k_q$ subalgebra of $M_q(n,\\k)$ generated \nby the quantum minors $|X^{1,\\dots,t}_{\\lambda_1,\\dots,\\lambda_t}|_q$ for $1\\le \\lambda_i\\le n$. There is an isomorphism of $\\GL_q(n,\\k)$-comodule algebras \nbetween $\\Lambda^t_q(\\calB)$ and $L^t_q(\\calB)$ by sending every such element to $v_{\\lambda_1}\\wedge\\cdots\\wedge v_{\\lambda_t}$. So this gives us an easy generating set \nfor the quantum Grassmannian over $\\k_q$.\n\nOf course it is also shown that the map $ev:\\k_q\\to \\k$ sending $q$ to 1 induces an isomorphism \n\\[\\Lambda_q^t(\\calB)\\otimes_{\\k_q}\\k\\cong \\Lambda^t(\\calB)\\cong \\k[\\Gr^{t,n}]\\]\nand since we used the same map $ev$, we get that this isomorphism is compatible with the $\\GL_q(n,\\k)$ action.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%  Bibliography %%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\medskip\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "29020dc2374a0a7b65ff14dc2aaee81a8485ab50", "size": 28975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grassmanian.tex", "max_stars_repo_name": "NicoCourts/Grassmannian-Notes", "max_stars_repo_head_hexsha": "f81a6a55b444539fa9f6b616659dff95b483c06e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Grassmanian.tex", "max_issues_repo_name": "NicoCourts/Grassmannian-Notes", "max_issues_repo_head_hexsha": "f81a6a55b444539fa9f6b616659dff95b483c06e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Grassmanian.tex", "max_forks_repo_name": "NicoCourts/Grassmannian-Notes", "max_forks_repo_head_hexsha": "f81a6a55b444539fa9f6b616659dff95b483c06e", "max_forks_repo_licenses": ["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.6193415638, "max_line_length": 303, "alphanum_fraction": 0.712096635, "num_tokens": 9279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6407081539459379}}
{"text": "\\clearpage\n\\subsection{C++ Expression} % (fold)\n\\label{sub:program-creation-c_expression}\n\nAn \\nameref{sub:expression} in C++ is a mathematical calculation or a \\nameref{sub:program-creation-c_literal} value. Each expression will have a \\nameref{sub:type}, and can contain a number of mathematic operators. Table \\ref{tbl:program-creation-c 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{\\% * /}      &   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 \\% 3}    \\\\\n    \\texttt{+ -}      &   Addition and subtraction    & \\texttt{10 + 3 - 4}   \\\\\n    \\hline\n  \\end{tabular}\n  \\end{minipage}\n  \\caption{C++ Operators and Example Expressions}\n  \\label{tbl:program-creation-c 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{int}  \\\\\n    \\texttt{ 2.1 }      & 2.1   & \\texttt{float}    \\\\\n    \\texttt{ \"Hello World\" }      &   \"Hello World\"    & \\texttt{string}\\footnote{This is technically a \\texttt{char*} which denotes a reference to a \\textit{string} of characters.}   \\\\\n    \\texttt{ \"Fred\" }      &   \"Fred\"    & \\texttt{string}   \\\\\n    \\texttt{ 3 * 2 } & 6 & \\texttt{int} \\\\\n    \\texttt{ 1 + 3 * 2 }  & 7 & \\texttt{int} \\\\\n    \\texttt{ (1 + 3) * 2} & 8 & \\texttt{int} \\\\\n    \\texttt{ 7 - 3 + 1 }  & 5 & \\texttt{int} \\\\\n    \\texttt{ 3 / 2 } & 1\\footnote{C does integer division for int values, rounding the value down.} & \\texttt{int} \\\\\n    \\texttt{ 3.0 / 2.0} & 1.5 & \\texttt{float} \\\\\n    \\texttt{ 3 \\% 2} & 1 & \\texttt{int} \\\\\n    \\texttt{ 11 \\% 3} & 2 & \\texttt{int} \\\\\n    \\texttt{ 3 / 2.0 } & 1.5\\footnote{If either, or both, values are real (floating point) numbers the result is also a real number.} & \\texttt{float} \\\\\n    \\texttt{ 1 + (3 / 2.0) + 6 * 2 - 8} & 6.5 & \\texttt{float} \\\\\n    \\hline\n  \\end{tabular}\n\\end{minipage}\n  \\caption{Example C++ Expressions and their values}\n  \\label{tbl:program-creation-c example expresions}\n\\end{table}\n\n\\mynote{\n\\begin{itemize}\n  \\item Table \\ref{tbl:program-creation-c 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 groupings.\n\\end{itemize}\n}\n\n\n% subsection c_expression (end)", "meta": {"hexsha": "f116070132e1df5e910d2f85355d6e887f9830a5", "size": 3113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/program-creation/c/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/c/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/c/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": 51.0327868852, "max_line_length": 546, "alphanum_fraction": 0.6418246065, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047048, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6407081503271101}}
{"text": "\\section{Information Theory}\n\n% ======================================\n% SINGLE VARIATE MEASURES\n% ======================================\n\\subsection{Single Variable}\n\\newcommand{\\entropy}[1]{\\text{H}\\left(#1\\right)}\n\\newcommand{\\info}[1]{\\text{I}\\left(#1\\right)}\n\\newcommand{\\totalcorr}[1]{\\text{TC}\\left(#1\\right)}\n\n\n\n\n\\begin{table}[h]\n    \\centering\n    \\caption{List of symbols and their meaning for single variable measures.}\n    \\begin{tabular}{m{7em}m{20em}}\n        \\toprule\n        \\textbf{Symbol}             & \\textbf{Name} \\\\\n        \\midrule\n        $\\info{\\mathbf{X}}$         & Self-Information\\\\\n        $\\entropy{\\mathbf{X}}$      & Entropy \\\\\n        $\\totalcorr{\\mathbf{X}}$    & Total Correlation \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\label{tab:info_theory}\n\\end{table}\n\n\n% ======================================\n% MULTI VARIATE MEASURES\n% ======================================\n\\subsection{Multiple Variables}\n\n\n\\newcommand{\\jointentropy}[2]{\\text{H}\\left(#1,#2\\right)}\n\\newcommand{\\mutualinfo}[2]{\\text{I}\\left(#1,#2\\right)}\n\\newcommand{\\kld}[2]{\\text{D}_{\\text{KL}}\\left[#1||#2\\right]}\n\n\n\\begin{table}[h]\n    \\centering\n    \\caption{List of symbols and their meaning for multiple variable measures.}\n    \\begin{tabular}{m{7em}m{20em}}\n        \\toprule\n        \\textbf{Symbol} & \\textbf{Meaning} \\\\\n        \\midrule\n        $\\jointentropy{\\mathbf{X}}{\\mathbf{Y}}$ & Joint Entropy \\\\\n        $\\mutualinfo{\\mathbf{X}}{\\mathbf{Y}}$   & Mutual Information \\\\\n        $\\kld{\\mathbf{X}}{\\mathbf{Y}}$          & Kullback-Leibler Divergence \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\label{tab:info_theory}\n\\end{table}", "meta": {"hexsha": "e74da7c66970c457f643fd754f2142344da17224", "size": 1643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/info_theory.tex", "max_stars_repo_name": "IPL-UV/latex_math", "max_stars_repo_head_hexsha": "c8c37e2364b4499e36590ecd3d89b3e0cb47b1bf", "max_stars_repo_licenses": ["MIT"], "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/info_theory.tex", "max_issues_repo_name": "IPL-UV/latex_math", "max_issues_repo_head_hexsha": "c8c37e2364b4499e36590ecd3d89b3e0cb47b1bf", "max_issues_repo_licenses": ["MIT"], "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/info_theory.tex", "max_forks_repo_name": "IPL-UV/latex_math", "max_forks_repo_head_hexsha": "c8c37e2364b4499e36590ecd3d89b3e0cb47b1bf", "max_forks_repo_licenses": ["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.4259259259, "max_line_length": 80, "alphanum_fraction": 0.5483870968, "num_tokens": 500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6407081479463312}}
{"text": "% --------------------------- %\n% SimpleTreeTest Start\n% --------------------------- %\n\\section{\\textbf{SimpleTreeTest}}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Particular Case}\n\\par\nThe problem we want to solve now is how we can implement a bounded priority\nqueue that can be accessed concurrently by multiple threads.\n\\par\nRemember that priority queue is said to be \\textit{bounded} when the range of\nthe priorities are taken from the range $0,...,m-1$.\n\\par\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Solution}\n\\par\nOne possible solution to this problem is given by the \\textit{Tree-Based Bounded\nPriority Queue} data structure. This structure is essentially a binary tree where\nthe leaf nodes have a bin holding items of priority $i$. Internal nodes maintain\na shared counter that indicates the number of elements stored to the left of\na given node.\n\\par\nThe interesting methods in this data structure are the \\textit{add()} and\n\\textit{removeMin()}, so let us talk about them.\n\\par\nThe \\textit{add()} method first takes the bin associated with the given\npriority. It puts the item into that bin and then starts increasing the counter\nof the parent nodes all the way to the root. Note that it only increases the\ncounter if the current node happens to be a left child of the parent.\n\\par\n\\hfill\n\\begin{lstlisting}[style=numbers]\n  /**\n   *  add item to priority queue\n   * @param item new item\n   * @param priority item''s priority\n   */\n  public void add(T item, int priority) {\n    TreeNode node = leaves.get(priority);\n    node.bin.put(item);\n    while(node != root) {\n      TreeNode parent = node.parent;\n      if (node == parent.left) { // increment if ascending from left\n        parent.counter.getAndIncrement();\n      }\n      node = parent;\n    }\n  }\n\\end{lstlisting}\n\\hfill\n\\par\nThe \\textit{removeMin()} method has to retrieve the item with the lowest\npriority. In order to do that, the method starts from the root and traverses the\ntree. If the current counter of the inner node is $0$, then it knows that the\nmin must be on the left. Otherwise, it goes through the right child. \n\\par\n\\hfill\n\\begin{lstlisting}[style=numbers]\n  public T removeMin() {\n    TreeNode node = root;\n    while(!node.isLeaf()) {\n      if (node.counter.getAndDecrement() > 0 ) {\n        node = node.left;\n      } else {\n        node = node.right;\n      }\n    }\n    return node.bin.get(); // if null pqueue is empty\n  }\n\\end{lstlisting}\n\\hfill\n\\par\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Experiment Description}\n\\par\nThree test cases were provided to exercise this code:\n\\begin{itemize}\n\\item testAdd. This test adds elements with random priority to the priority\nqueue one by one. At the end, it extracts each element and it must be the case\nthat the previously removed element had a lower priority than the current\nelement. \n\\item testParallelAdd. This test spawns 8 threads. Each of the test adds 8\nelements to the queue concurrently. At the end, it performs the same checking as\nin the previous test case. Notice that each thread is in charge of adding\nelements from a fixed range in ascending order.\n\\item testParallelBoth. Does the same as the previous test case but also removes\nelements in parallel. Each remover thread will perform the same checking. Since\nadders add elements in ascending order, it is guaranteed that any removal from\nany thread will retrieve an element with a lower priority than the next one.\n\\end{itemize}\n\\par\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Sample Results}\n\\par\nHere is the result of the execution of the test cases:\n\\par\n\\hfill\n\\begin{verbatim}\n[oraadm@gdlaa008 ch15]$ junit priority.SimpleTreeTest\n.sequential test\nOK.\n.testParallelBoth\nOK.\n.testParallelAdd\nOK.\n\nTime: 0.01\n\nOK (3 tests)\n\\end{verbatim}\n\\hfill\n\\par\nThe tests passed every time\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% --------------------------- %\n% SimpleTreeTest End\n% --------------------------- %\n", "meta": {"hexsha": "3524bc1ab205bd5b9877ff79bf3f392ea5fd7f0a", "size": 3917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "zava/Multiprocessor/SimpleTreeTest.tex", "max_stars_repo_name": "rzavalet/multiprocessor", "max_stars_repo_head_hexsha": "f27d4dd6f44172bb6c910552e50107838d653f2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "zava/Multiprocessor/SimpleTreeTest.tex", "max_issues_repo_name": "rzavalet/multiprocessor", "max_issues_repo_head_hexsha": "f27d4dd6f44172bb6c910552e50107838d653f2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "zava/Multiprocessor/SimpleTreeTest.tex", "max_forks_repo_name": "rzavalet/multiprocessor", "max_forks_repo_head_hexsha": "f27d4dd6f44172bb6c910552e50107838d653f2f", "max_forks_repo_licenses": ["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.1949152542, "max_line_length": 81, "alphanum_fraction": 0.6867500638, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.640679216503287}}
{"text": "\\section{Hydrodynamic Equations in Comoving Coordinates}\n\n\\subsection{Conservative Form}\n\nWe solve the equations of gas dynamics in a coordinate system that is comoving \nwith the expanding universe,  with expansion factor, $a,$ related to the redshift, $z$, by $a = 1 / (1 + z).$\nThe continuity equation is written,\n\\begin{equation}\n\\label{eq:dens}\n\\frac{\\partial \\rho_b}{\\partial t} = - \\frac{1}{a} \\nabla \\cdot (\\rho_b \\Ub) \\enskip , \\\\\n\\end{equation}\nwhere $\\rho_b$ is the comoving baryonic density, related to the proper density by $\\rho_b = a^3 \\rho_{proper},$ \nand $\\Ub$ is the proper peculiar baryonic velocity.\n\nThe momentum evolution equation can be expressed as\n\\begin{eqnarray}\n\\frac{\\partial (\\rho_b \\Ub)}{\\partial t} &=&  \\frac{1}{a} \\left(\n- \\nabla \\cdot (\\rho_b \\Ub \\Ub) \n- \\nabla p \n+ \\rho_b \\gb \n+ {\\bf S}_{\\rho \\Ub}\n- \\dot{a} \\rho_b \\Ub \\right) \\enskip , \n\\end{eqnarray}\nor equivalently,\n\\begin{eqnarray}\n\\label{eq:momt}\n\\frac{\\partial (a \\rho_b \\Ub)}{\\partial t} &=& \n-             \\nabla \\cdot (\\rho_b \\Ub \\Ub) \n-             \\nabla p \n+             \\rho_b \\gb \n+             {\\bf S}_{\\rho \\Ub} \\enskip , \n\\end{eqnarray}\nwhere the pressure, $p$, that appears in the \nevolution equations is related to the proper pressure, $p_{proper},$ by  $p = a^3 p_{proper}.$ \nHere $\\gb = - \\nabla \\phi$ is the gravitational acceleration vector, and \n${\\bf S}_{\\rho \\Ub}$ represents any external forcing terms.\n\nThe energy equation can be written,\n\\begin{eqnarray}\n\\frac{\\partial (\\rho_b E)}{\\partial t} &=& \\frac{1}{a} \\left[\n- \\nabla \\cdot (\\rho_b \\Ub E + p \\Ub)\n+ ( \\rho_b \\Ub \\cdot \\gb +  S_{\\rho E} ) \n- \\dot{a} ( 3 (\\gamma - 1) \\rho_b e + \\rho_b ( \\Ub \\cdot \\Ub) ) \\right] \\enskip . \n\\end{eqnarray}\nor equivalently,\n\\begin{eqnarray}\n\\label{eq:energy}\n\\frac{\\partial (a^2 \\rho_b E)}{\\partial t} &=& a \\left[\n- \\nabla \\cdot (\\rho_b \\Ub E + p \\Ub)\n+  \\rho_b \\Ub \\cdot \\gb \n+  S_{\\rho E}  \n+  \\dot{a} ( \\; ( 2 - 3 (\\gamma - 1) ) \\; \\rho_b e ) \\right] \\enskip . \n\\end{eqnarray}\nHere $E = e + \\Ub \\cdot \\Ub / 2$ is the total energy per unit mass, \nwhere $e$ is the specific internal energy.  \n$S_{\\rho E} = S_{\\rho e} + \\Ub \\cdot {\\bf S}_{\\rho \\Ub}$\nwhere $S_{\\rho e} = \\Lambda^H - \\Lambda^C$ represents the heating and cooling terms, respectively.\nWe can write the evolution equation for internal energy as\n\\begin{eqnarray}\n\\frac{\\partial (\\rho_b e)}{\\partial t} &=& \\frac{1}{a} \\left[\n- \\nabla \\cdot (\\rho_b \\Ub e)\n- p \\nabla \\cdot \\Ub\n- \\dot{a} ( 3 (\\gamma - 1) \\rho_b e )\n+ S_{\\rho e}  \\right] \\enskip . \n\\end{eqnarray}\nor equivalently,\n\\begin{eqnarray}\n\\frac{\\partial (a^2 \\rho_b e)}{\\partial t} &=&  a \\left[\n- \\nabla \\cdot (\\rho_b \\Ub e)\n- p \\nabla \\cdot \\Ub\n+ S_{\\rho e} \n+ \\dot{a} ( \\; ( 2 - 3 (\\gamma - 1) ) \\; \\rho_b e ) \\right] \\enskip . \n\\end{eqnarray}\n\nNote that for a gamma-law gas with $\\gamma = 5/3,$ we can write\n\\begin{eqnarray}\n\\frac{\\partial (a^2 \\rho_b E)}{\\partial t} &=&  a \\left[\n -\\nabla \\cdot (\\rho_b \\Ub E + p \\Ub)\n+  \\rho_b \\Ub \\cdot \\gb \n+  S_{\\rho e}  \\right]  \\enskip . \n\\end{eqnarray}\nand\n\\begin{eqnarray}\n\\frac{\\partial (a^2 \\rho_b e)}{\\partial t} &=& a \\left[ \n- \\nabla \\cdot (\\rho_b \\Ub e)\n-  p \\nabla \\cdot \\Ub\n+  S_{\\rho e}  \\right]  \\enskip . \n\\end{eqnarray}\n\n\\subsection{Tracing}\n\nIn order to compute the fluxes on faces, we trace $\\rho, \\Ub, \\rho e$ and $p$ to the faces.\n\n\\noindent Thus we must convert the momentum evolution equation into a velocity evolution equation:\n\\begin{eqnarray}\n\\frac{\\partial\\Ub}{\\partial t} &=&  \\frac{1}{\\rho_b} \\left(\n\\frac{\\partial (\\rho_b \\Ub)}{\\partial t}  - \\Ub \\frac{\\partial \\rho_b}{\\partial t}  \\right) \\\\\n&=&  \\frac{1}{a \\rho_b} \\left(\n- \\nabla \\cdot (\\rho_b \\Ub \\Ub)\n- \\nabla p\n+ \\rho_b \\gb\n+ S_{\\rho \\Ub}\n- \\dot{a} \\rho_b \\Ub \\right) \n+ \\frac{1}{a}  \\Ub \\; \\nabla \\cdot (\\rho_b \\Ub) \\\\\n&=&  \\frac{1}{a} \\left(\n- \\Ub \\cdot \\nabla \\Ub\n- \\frac{1}{\\rho_b} \\nabla p\n+ \\gb\n+ \\frac{1}{\\rho_b} {\\bf S}_{\\rho \\Ub}\n- \\dot{a} \\Ub \\right) \\enskip .\n\\end{eqnarray}\n\n\\section{Subgrid Scale Model in Comoving Coordinates}\n\nThe fundamental modification to the standard compressible equations is the addition\nof a SGS turbulence energy variable, $K$ and associated source terms in the equations\nfor the evolution of velocity, total energy, and $K$ \\cite{schumann:1975,sagaut,schmidt:2006}.\nThe set of conservation equations in comoving coordinates~(\\ref{eq:dens})--(\\ref{eq:energy}) then becomes\n\\cite{maier:2009}:\n\\begin{align}\n\\frac{\\partial \\rho_b}{\\partial t} =& - \\frac{1}{a} \\nabla \\cdot (\\rho_b \\Ub) \\enskip , \\\\\n\\label{eq:momt_les}\n\\frac{\\partial (a \\rho_b \\Ub)}{\\partial t} =& \n-             \\nabla \\cdot (\\rho_b \\Ub \\Ub) \n-             \\nabla p\n+             \\nabla \\cdot \\boldsymbol{\\tau}\n+             \\rho_b \\gb  \\enskip , \\\\\n\\label{eq:energy_les}\n\\frac{\\partial (a^2 \\rho_b E)}{\\partial t} =& - a \\nabla \\cdot (\\rho_b \\Ub E + p \\Ub)\n+  a \\rho_b \\Ub \\cdot \\gb \n+ a \\nabla \\cdot (\\Ub\\cdot\\boldsymbol{\\tau}) - a^2(\\Sigma - \\rho_b \\varepsilon) \\enskip \\\\\n\\nonumber\n&+ a \\dot{a} \\left( ( 2 - 3 (\\gamma - 1) ) \\rho_b e \\right) \n+ a^2 ( \\Lambda^H  - \\Lambda^C )  \\enskip , \\\\\n\\label{eq:k_les}\n\\frac{\\partial (a^2\\rho_b K)}{\\partial t} =&\n- a\\nabla \\cdot \\left(\\rho_b \\Ub K\\right) \n+ a\\nabla \\cdot \\left(\\rho_b \\kappa_{\\rm sgs}\\nabla K\\right)  \n+ a^2(\\Sigma - \\rho_b \\varepsilon)\\enskip .\n\\end{align}\nThe interaction between resolved and unresolved turbulent eddies is described by\nthe SGS turbulence stress tensor $\\boldsymbol{\\tau}$. Since inertial-range dynamics of \nturbulence is scale-invariant, we conjecture that $\\boldsymbol{\\tau}$ in comoving coordinates \nhas the same form as for non-expanding fluids. For compressible turbulence, \nthe following closure is proposed in \\cite{schmidt:2011}:\n\\begin{equation}\n \\label{eq:tau_nonlin}\n  \\tau_{ij}= 2C_{1}\\Delta\\rho_b(2 K_{\\mathrm{sgs}})^{1/2}S_{\\! ij}^{\\ast}\n  -4C_{2}\\rho_bK\\frac{U_{i,k}U_{j,k}}{|\\nabla\\Ub|^{2}}\n  -\\frac{2}{3}(1-C_{2})\\rho_bK\\delta_{ij}.\n\\end{equation}\nwhere $|\\nabla\\Ub|:=(2U_{i,k}U_{i,k})^{1/2}$ is the norm of the resolved velocity derivative,\n\\begin{equation}\nS_{ij}^{\\ast} = S_{ij} - \\frac{1}{3}\\delta_{ij}d =\n\\frac{1}{2} (U_{i,j} + U_{j,i}) - \\frac{1}{3}\\delta_{ij}U_{k,k}\n\\end{equation}\nis the trace-free rate-of strain, and $\\Delta=(\\vartriangle\\!x\\,\\vartriangle\\!y\\,\\vartriangle\\!z)^{1/3}$\nis the grid scale in comoving coordinates. The production and dissipation terms in equation~(\\ref{eq:k_les}) \nare defined as follows:\n\\begin{eqnarray}\n\\Sigma             &=& \\frac{1}{a}\\tau_{ij} S_{ij}, \\\\\n\\varepsilon &=& \\frac{C_\\varepsilon K^{3/2}}{a\\Delta},\n\\end{eqnarray}\nand $\\kappa_{\\rm sgs} = C_{\\kappa}\\Delta K^{1/2}$ is the SGS diffusivity.\nHere we assume that the Reynolds number of turbulence is high such that the damping of turbulent eddies by the microscopic\nviscosity of the fluid occurs entirely on the subgrid scales. Because of the numerical viscosity of PPM,\nhowever, part of the numerically resolved kinetic energy will be dissipated directly into internal energy.\n", "meta": {"hexsha": "b323be93aec8ad8109e7b8fe209bd7d5ae67278a", "size": 6935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "UsersGuide/ComovingHydro/Equations.tex", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "UsersGuide/ComovingHydro/Equations.tex", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "UsersGuide/ComovingHydro/Equations.tex", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 41.2797619048, "max_line_length": 122, "alphanum_fraction": 0.6454217736, "num_tokens": 2555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.640593713764708}}
{"text": "\\graphicspath{{Pics/}}\n\n\\newpage\\subsection{Projective Constructions}\n\n\\begin{minipage}{.6\\linewidth}\n    \\begin{construction}[Second Intersection of Line with Conic]\n        Given four points $ A, B, C, D $, no three collinear, and a point $ P\n        $ on a line $ l $ passing through at most one of the four points,\n        construct the point $ P'\\in l $ such that $ A, B, C, D, P, P' $ line\n        on the same conic.\n\n        \\solu{\n            Let $ AP\\cap BC = X,\\ l\\cap CD = Y,\\ XY\\cap AD=Z $. Then by\n            Pascal's Hexagrummum Mysticum Theorem, we have, $\\ \\  P' = BZ\\cap\n            l $\n        }\n    \\end{construction}\n\\end{minipage}\\hfill%\n\\begin{minipage}{.35\\linewidth}\n    \\figdf{}{constructing_second_intersection_with_conic}{}\n\\end{minipage}\n\n\\begin{minipage}{.6\\linewidth}\n    \\begin{construction}[Conic touching conic]\n        Given a conic $ \\mathcal{C} $, and two points $ A, B $ on it, and $ C\n        $ inside of it. Construct the conic $ \\mathcal{H} $ that is tangent to\n        $ \\mathcal{C} $ at $ A, B $ and passes through $ C $.\n    \\end{construction}\n    \\solu{\n        Draw the two tangest at $ A,B $ which meet at $ X $. Take an arbitrary\n        line passing through $ X $ that intersects $ AC, BC $ at $ Y, Z $.\n        Take $ D=BY\\cap AZ $. Then $ D $ lies on $ \\mathcal{H} $ by Pascal.\n        Construct another point $ E $ similarly and draw the conic.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.35\\linewidth}\n    \\figdf{.9}{conic_touching_conic}{}\n\\end{minipage}\n\n\\begin{construction}[Inconic of a quadrilateral]\n    Given a convex quadrilateral $ ABCD $. $ P=AC\\cap BD $, $ S\\in AD, T\\in BC\n    $ such that $ S, P, T $ are collinear. Construct the conic that touches $\n    AB, CD $, and also touches $ AD, BC $ at $ S, T $ respectively.\n\\end{construction}\n\n\\solu{[the\\textunderscore Construction] \n    Draw the polar line $ l $ of $ P $ wrt to the quadrilateral. Let $\n    Z=BC\\cap l $. Let $ ZS\\cap AB = U $, $ ZT\\cap CD = V $. Then $ SSUUTTVV $\n    is our desired conic.\n}\t\n\n\\begin{minipage}{.5\\linewidth}\n    \\proof{\n        If $ U, V\\in CD, AB $ such that $ UV $ passes through $ P $, and if\n        the conic passing through $ U, V $ and tangent to $ AD, BC $ at $ S, T\n        $ intersects $ CD $ at $ U' $ again, then $ SV, U'T, DB $ are\n        concurrent. So to show our construction works, we just need to prove\n        that $ U, V, P $ are collinear.\\\\\n\n        Since Pascal's theorem works on $ SVBTUD $, we know $ S, V, B, T, U, D $\n        lie on a conic $ \\mathcal{H} $ and $ l $ is the pole of $ P $ wrt $\n        \\mathcal{H} $. Now, applying Pascal's theorem on $ TDVUBS $, and quadrilateral\n        theorem on $ BTUD $ and $ BVSD $, we have, $ ST\\cap UV\\in AC $, which is $ P\n        $. So we are done.\n    }\t\n\\end{minipage}\\hfill%\n\\begin{minipage}{.45\\linewidth}\n    \\figdf{}{conic_touching_quad}{}\n\\end{minipage}\n\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\begin{construction}[\\href{http://www.geometry.ru/persons/beluhov/selected.pdf}{Sharygin\n        Olympiad 2010}]\n        A conic $ \\mathcal{C} $ passing through the vertices of $ \\triangle\n        ABC $ is drawn, and three points $ A', B', C' $ on its sides $ BC, CA,\n        AB $ are chosen. Then the original triangle is erased. Prove that the\n        original triangle can be constructed iff $ AA', BB', CC' $ are\n        concurrent.\t\t\n    \\end{construction}\n\n    \\solu{[the\\textunderscore Construction] \n        Draw $ B'C' $. It intersects the circle at $ X_1, X_2 $. Draw the\n        conic $ \\mathcal{H} $ that is tangent to $ \\mathcal{C} $ at $ X_1, X_2\n        $ and passes through $ A' $. Then $ BC $ is tangent to $ \\mathcal{H} $\n        at $ A' $.\n    }\n\n\\end{minipage}\\hfill%\n\\begin{minipage}{.45\\linewidth}\n    \\figdf{1}{reconstruct_ABC}{}\n\\end{minipage}\n\n\n\n\n\\proof{\n    The only if part is easy to prove. Becase if $ AA', BB', CC' $ aren't\n    concurrent, then we can get multiple triangles $ ABC $. So suppose that\n    they are concurrent. \\\\\n\n    Now we define some intersetion points.\n    \\begin{center}\n        \\begin{tabular}{ccccc}\n            $W_1$\t&= &$BB'$\t&$\\cap$ &$\\mathcal{C}$\\\\\n            $S$\t&=\t&$X_1X_1$\t&$\\cap$ &$AW_1$\\\\\n            $T$\t&=\t&$X_1B$\t&$\\cap$ &$AX_2$\\\\\n            $U$\t&=\t&$X_1X_1$\t&$\\cap$ &$BC$\\\\\n            $V$\t&=\t&$X_2X_2$\t&$\\cap$ &$BC$\\\\\n            $R$\t&=\t&$X_2X_2$\t&$\\cap$ &$AW_1$\\\\\n            $Y_1$\t&=\t&$A'B'$\t&$\\cap$ &$SR$\n        \\end{tabular}\n    \\end{center}\n\n    $T, S, B'$ are collinear by Pascal's theorem on $ BX_1X_1X_2AW_1 $. $ T,\n    B', V $ are similarly collinear for $ AX_2X_2X_1BC $. And similarly $ R,\n    B', U $ are collinear.\\\\\n\n    We will prove that $ \\mathcal{H} $ is an inconic of $ SRVU $ that goes\n    through $ A', X_1, X_2 $. \\\\\n\n    For a point $ X $ on $ UV $, define $ f:UV\\to UV $ such that $ f(X) $ is\n    the second intersection of the conic $ X_1X_1X_2X_2X $ ($ X_1X_1 = SU,\n    X_2X_2=RV  $) with $ UV $. \n    $ f $ is an involution by \\autoref{theorem:Three Conic Law}. \\\\\n\n    Suppose $A_1$ is the intersection with the inconic of $ SRUV $ through $\n    X_1, X_2 $ and $ UV $. Let $ A_2 = X_1X_2\\cap UV $. Then $ f(A_1) =A_1,\n    f(A_2)=A_2, f(B)=C $. \\\\\n\n    Which means, $A(B, C; A_1, A_2) = -1$. Which means $ A_1=A' $. So, $\n    X_1X_2A'X_2X_2 $ is an inconic of $ SRVU $, just as we wanted.\t\n\n    \\figdf{.8}{reconstruct_ABC_1}{}\n}\n\n\\newpage\n\\begin{construction}[Focus and Directrix of a Parabola]\n    First draw two parallel segments on the parabola, join their midpoints to\n    get the line parallel to the axis. Then draw the main axis and find out\n    the tip of the parabola. Then draw $f(x) = \\frac{x}{2}$ line through $P$.\n    And find the foot of the intersection of it with the parabola. It is the\n    focus.\n    \\figdf{.5}{parabola_foci_construction}{}\n\\end{construction}\n", "meta": {"hexsha": "2f1bfb8dcdc5d6550feb922d14c95df9b1bfac68", "size": 5796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geo/sec8_5_projective_construction.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": "geo/sec8_5_projective_construction.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": "geo/sec8_5_projective_construction.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": 39.4285714286, "max_line_length": 92, "alphanum_fraction": 0.5916149068, "num_tokens": 1995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.640483532882625}}
{"text": "\\section{Sparse Coding}\n\n\\subsection*{Orthogonal Basis}\nFor $\\mathbf{x}$ and o.n.b. $\\mathbf{U}$ compute $\\mathbf{z} = \\mathbf{U}^\\top \\mathbf{x} $. Approx $ \\mathbf{\\hat{x}} = \\mathbf{U\\hat{z}}$, $\\hat{z}_i = z_i$ if $ \\lvert z_i \\rvert > \\epsilon$ else 0.\nReconstruction Error $\\|\\mathbf{x}-\\mathbf{\\hat{x}}\\|^2 = \\sum_{d\\notin\\sigma}\\langle\\mathbf{x},\\mathbf{u}_d\\rangle ^2$.\nChoice of base depends on signal. Fourier for global, wavelet for local support. PCA basis optimal for given $\\Sigma$. (Haar Wavelet) include the scaling function in the family.\nChange of base complexity = $O(D^2)$ but fast transforms = $O(DlogD)$\n\\subsection*{Overcomplete Basis}\n$\\mathbf{U} \\in \\mathbb{R}^{D \\times  L}$ for \\# atoms $ = L > D = \\mathsf{dim}\\text{(data)}$. Decoding involved $\\rightarrow$ add constraint $\\mathbf{z}^\\star \\in \\argmin_\\mathbf{z} \\lVert \\mathbf{z} \\rVert_0$ s.t. $\\mathbf{x} = \\mathbf{Uz}$. NP-hard $\\rightarrow$ approximate with 1-norm (convex) or with MP.\n\n\\textbf{Coherence}\n\\begin{inparaitem}[\\color{red}\\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}$ orthogonal matrix\n\t\\item $m([\\mathbf{B}, \\mathbf{u}]) \\geq \\frac{1}{\\sqrt{D}}$ if atom $\\mathbf{u}$ is added to orthogonal basis $\\mathbf{B}$ (o.n.b. = orthonormal base)\n\\end{inparaitem}\n\\textbf{Matching Pursuit (MP)}\napproximation of $\\mathbf{x}$ onto $\\mathbf{U}$, using $K$ entries.\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 smallest angle $i^\\star = \\argmax_i |\\langle \\mathbf{u}_i, \\mathbf{r} \\rangle|$\n\t\\item update coefficients: $z_{i^\\star} \\leftarrow z_{i^\\star} + \\langle \\mathbf{u}_{i^\\star}, \\mathbf{r} \\rangle$\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\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$ with $y_i = \\langle \\mathbf{w}_i, \\mathbf{x}\\rangle $: $M$ lin. combinations 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$ 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": "cbd6efe7c337dc31facdd9c38913661dce54b270", "size": 4179, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SparseCoding.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": "SparseCoding.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": "SparseCoding.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": 87.0625, "max_line_length": 486, "alphanum_fraction": 0.6489590811, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6404835064509062}}
{"text": "\n\\subsection{Independent Contour Method}\n\\begin{frame}{Definition}\n\t\\begin{block}{Formula}\n\t\tFor a closed mechanism, the number of independent contours $N$ is calculated as follows:\n\t\t\\[N=c-n\\]\n\t\twhere\\\\\n\t\t$c$ is the number of joints\\\\\n\t\t$n$ is the number of links, excluding ground\n\t\\end{block}\n\tThe number of independent contours depends on the number of joint connections to ground. Its graphical representation can be referred to as \\textit{connectivity table}, \\textit{structural diagram} or \\textit{\\textbf{contour diagram}}.\n\\end{frame}\n\\begin{frame}{Velocity Analysis}\n\t\\begin{block}{Formulas}\n\t\tFor a closed kinematic chain:\n\t\t\\begin{itemize}\n\t\t\t\\item $\\displaystyle\\sum_{i}\\vb{\\omega}{i-1,i}=\\vb{0}{}$\n\t\t\t\\item $\\displaystyle\\sum_{i}\\vb{r}{A_i}\\times\\vb{\\omega}{i-1,i} + \\sum_{i}\\vb{v}{A_{i-1,i}}=\\vb{0}{}$\n\t\t\\end{itemize}\n\t\twhere:\\\\\n\t\t$\\vb{\\omega}{i-1,i}$ is the angular velocity of link $i$ relative to link $i-1$\\\\\n\t\t$\\vb{r}{A_i}$ is the position vector of joint $A_i$\\\\\n\t\t$\\vb{v}{A_{i-1,i}}$ is the velocity vector of joint $A_i$ on link $i$ relative to joint $A_i$ on link $A_{i-1}$\\\\\n\t\\end{block}\n\\end{frame}\n\\begin{frame}{Acceleration Analysis}\n\\begin{block}{Formulas}\n\tFor a closed kinematic chain:\n\t\\begin{itemize}\n\t\t\\item $\\displaystyle\\sum_{i}\\vb{\\alpha}{i-1,i}+\\sum_{i}\\vb{\\omega}{i}\\times\\vb{\\omega}{i-1,i}=\\vb{0}{}$\n\t\t\\item $\\displaystyle\\sum_{i}\\vb{r}{A_i}\\times(\\vb{\\alpha}{i-1,i}+\\vb{\\omega}{i}\\times\\vb{\\omega}{i-1,i}) +  \\sum_{i}\\vb{a}{A_{i-1,i}} + 2 \\sum_i\\vb{\\omega}{i-1}\\times \\vb{v}{A_{i-1,i}}+ \\sum_{i}\\vb{\\omega}{i}\\times(\\vb{\\omega}{i}\\times \\vb{r}{A_{i+1}A_i})=\\vb{0}{}$\n\t\\end{itemize}\n\twhere:\\\\\n\t$\\vb{\\omega}{i}$, $\\vb{\\omega}{i-1}$ are the angular velocities of link $i$ and $i-1$ relative to ground\\\\\n\t$\\vb{\\alpha}{i-1,i}$ is the angular acceleration of joint $A_i$ relative to joint $A_{i-1}$\\\\\n\t$\\vb{a}{A_{i-1,i}}$ is the acceleration vector of joint $A_i$ on link $i$ relative to joint $A_i$ on link $A_{i-1}$\\\\\n\\end{block}\n\\end{frame}\n\\begin{frame}\n\tIn planar motions, the above equations for acceleration analysis can be reduced to:\n\t\\begin{itemize}\n\t\t\\item$\\displaystyle\\sum_{i}\\vb{\\alpha}{i-1,i}=\\vb{0}{}$\n\t\t\\item $\\displaystyle\\sum_{i}\\vb{r}{A_i}\\times\\vb{\\alpha}{i-1,i} +  \\sum_{i}\\vb{a}{A_{i-1,i}} + 2 \\sum_i\\vb{\\omega}{i-1}\\times \\vb{v}{A_{i-1,i}}- \\sum_{i}\\vb{\\omega}{i}^2\\vb{r}{A_{i+1}A_i})=\\vb{0}{}$\n\t\\end{itemize}\\vskip3mm\n\tIn general, the steps of this method are:\n\t\\begin{enumerate}\n\t\t\\item Perform position analysis.\n\t\t\\item Draw the contour diagram of the mechanism.\n\t\t\\item Use the formulas above to obtain the results.\n\t\t\\item Calculate $\\vb{\\omega}{i}$ and $\\vb{a}{i}$ with respect to ground.\n\t\t\\item Compute relevant velocities and accelerations.\n\t\\end{enumerate}\n\\end{frame}\n", "meta": {"hexsha": "d009e51927ebcad1edc44b5cb385b4eb88b262da", "size": 2739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Independent_contour_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/velocity_acceleration_analysis_pdf/Sections/Introduction/Independent_contour_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/velocity_acceleration_analysis_pdf/Sections/Introduction/Independent_contour_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": 50.7222222222, "max_line_length": 267, "alphanum_fraction": 0.6666666667, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6404835064509061}}
{"text": "\n\\documentclass{article}\n\n\\newcommand{\\steem}{\\texttt{STEEM}}\n\\newcommand{\\mytoken}{\\texttt{MYTOKEN}}\n\n\\begin{document}\n\n\\section{Automated Market Makers for SMTs}\n\n\\section{Setup}\n\n\\subsection{Basic definitions}\n\nIn this article, we'll let $s$ represent a quantity of STEEM, let $t$\nrepresent a quantity of some token (SMT), and let $p$ represent a price,\nsuch that $pt$ is STEEM-valued (i.e. if MYTOKEN is trading at\n$p = 0.05$ STEEM / MYTOKEN then $t = 120$ MYTOKEN has a value of\n$pt = (0.05\\ \\mbox{STEEM / MYTOKEN}) \\cdot (120\\ \\mbox{MYTOKEN}) = 6\\ \\mbox{STEEM}$.\n\nSuppose we have a market maker (or any economic agent) with a two-asset\n``portfolio'' (inventory) of $s$ STEEM and $t$ tokens.  If the price of\ntokens is $t$, then we may measure of the value of this portfolio, in\nunits of STEEM, as $v(p, s, t) = s + pt$.\n\nOne common portfolio management policy is to require that STEEM\nshould be some constant fraction $r$ of the portfolio, i.e.\n$s = r v(p, s, t)$ where $0 < r < 1$.  We call this policy the\n\\textit{constant portfolio ratio} or CPR policy, and the equation\n$s = r v(p, s, t)$ is the \\textit{CPR invariant}.\n\nA different portfolio management policy, discussed by the Bancor\nwhitepaper, is called CRR or \\textit{constant reserve ratio}.  To discuss CRR,\nlet us notate the total number of tokens in existence as $T$.  The\n\\textit{CRR invariant} is then defined as $s = r v(p, 0, T-t)$.\n\n\\subsection{Note on conventions}\n\nWe must discuss where our convention varies from the Bancor whitepaper.\nAt some times, when some user Alice interacts with the market maker,\nAlice will remove some tokens from her balance to get STEEM from\nthe market maker's balance.  On the other hand, Bob may add some tokens\nto his balance in exchange for sending STEEM to the market maker's balance.\n\nBancor takes the convention that in this example, the market maker \\textit{destroys}\ntokens in its interaction with Alice, and \\textit{creates} tokens in its interaction\nwith Bob.  The Bancor convention suggests the market maker is not\nan ordinary actor, but needs system-level ``special powers'' -- specifically,\nthe privilege to operate the token printing press -- in order to function.\n\nIn this paper, we adopt the convention that the tokens sent by Alice to the\nmarket maker are not destroyed, but are instead added to the inventory (balance)\nof the market maker.  Likewise, the tokens sent to Bob by the market maker\nare not created out of thin air; they already exist and are merely\ntransferred from the inventory of the market maker to Bob.  Thus, we show\nthat the market maker is essentially an ordinary economic agent acting according\nto a deterministic algorithm -- it doesn't actually need ``special powers''!\n\n\\section{Finite trades}\n\n\\subsection{Basic definitions}\n\nA \\textit{trade} is a change in the market maker's balance from\n$(s, t) \\to (s+\\Delta s, t+\\Delta t)$.  The \\textit{price} at which the\ntrade occurs is defined as $p = {- \\Delta s \\over \\Delta t}$.  We restrict\nourselves to \\textit{well-formed trades} where either $\\Delta s = \\Delta t = 0$,\nor $\\Delta s$ and $\\Delta t$ are both nonzero and have opposite sign.\n\nTheorem:  A trade at price $p$ conserves value at price $p$.  More rigorously,\nif $\\Delta s, \\Delta t$ represent a trade at price $p$, then\n$v(p, s, t) = v(p, s + \\Delta s, t + \\Delta t)$.\n\nLet us more rigorously define the market maker's \\textit{state} as a tuple\n$M = (s, t, T, r)$.  Given some price $p$, we may define the\n\\textit{restoring trade} at $p$ (also called a \\textit{relaxing trade} or\na \\textit{relaxation}) to be a trade which occurs at price $p$ and results in a\nstate that satisfies the CRR invariant.\n\n\\subsection{Computing the restoring trade}\n\nThe restoring trade consists of functions $\\Delta s(M, p)$ and $\\Delta t(M, p)$.\nWe may actually compute these functions from the definition of price and the\nCRR invariant:\n\n\\begin{eqnarray*}\n\\Delta s & = & -p \\Delta t \\\\\ns + \\Delta s & = & r v(p, 0, T-(t+\\Delta t)) \\\\\n\\Rightarrow s - p \\Delta t & = & r v(p, 0, T-t-\\Delta t) \\\\\n   & = & r p(T-t-\\Delta t) \\\\\n   & = & rpT - rpt - rp \\Delta t \\\\\n\\Rightarrow r p \\Delta t - p \\Delta t & = & r p (T-t) - s \\\\\n\\Rightarrow \\Delta t & = & {r p (T - t) - s \\over rp - p } \\\\\n                     & = & \\left( {1 \\over 1-r} \\right) \\left( {s \\over p} - r (T-t) \\right) \\\\\n\\Rightarrow \\Delta s & = & - p \\Delta t \\\\\n   & = & \\left( {1 \\over 1-r} \\right) \\left( r p (T - t) - s \\right)\n\\end{eqnarray*}\n\n\\subsection{Computing the equilibrium price}\n\nGiven a state $M$, there exists some price $p_{eq}(M)$ for which the restoring\ntrade is zero; call this price the \\textit{equilibrium price}.  We may compute\nthe equilibrium price by setting $\\Delta s = 0$:\n\n\\begin{eqnarray*}\n\\Delta s & = & 0 \\\\\n& = & \\left( {1 \\over 1-r} \\right) \\left( r p_{eq} (T - t) - s \\right) \\\\\n\\Rightarrow r p_{eq} (T - t) - s & = & 0 \\\\\n\\Rightarrow r p_{eq} (T - t) & = & s \\\\\n\\Rightarrow p_{eq} & = & {s \\over r (T-t)}\n\\end{eqnarray*}\n\nTheorem:  Relaxation is idempotent.  That is, after relaxing at price $p$,\nthe equilibrium price of the resulting state is $p$, and a second relaxation\nat price $p$ will be a zero trade.\n\n\\subsection{Example}\n\nExample:  Suppose $M = (1200, 3600, 12000, 0.25)$ and $p = 0.5$.  Then of the\n$T = 12000$ TOKEN in existence, $t = 3600$ TOKEN is held by the MM, so\n$T-t = 12000 - 3600 = 8400$ TOKEN are ``circulating'' (i.e. exist in balances\noutside the MM).  These circulating tokens are worth $p(T-t) = 4200$ STEEM\ntotal, so they ``should be'' backed by a target reserve level of\n$rp(T-t) = 4200 * 0.25 = 1050$ STEEM.\n\nIn this example, there is ``too much'' STEEM in the reserve, so relaxation\nwill buy tokens in the market.  This sale will cause two effects:   It will\ndecrease the reserve STEEM, and also decrease circulating tokens.  The decrease\nin circulating tokens, in turn, causes the target reserve level to decline.  For\nevery 1 STEEM used to buy tokens, the target reserve level declines by $r$ STEEM;\nsince $r < 1$ eventually the declining reserve will ``catch up'' to its more slowly\ndeclining target level.\n\nThe above algebra shows that we will catch up at\n$\\Delta s = \\left( {1 \\over 1-r} \\right) \\left( r p (T - t) - s \\right)$ and\n$\\Delta t = \\left( {1 \\over 1-r} \\right) \\left( {s \\over p} - r (T - t) \\right)$.\nRunning the calculations with the numbers defined in this example gives\n$\\Delta s = -200$ STEEM and $\\Delta t = 400$ TOKEN.\n\nLet's check that these computed values $\\Delta s = -200, \\Delta t = 400$\n(a) represent a trade with price $0.5$, and (b) that the CRR invariant holds\nfor the new state $M_{new} = (s+\\Delta s, t+\\Delta t, T, r)$.  Calculating\n$p = {- \\Delta s \\over \\Delta t}$ we indeed get $p = 0.5$.  After this trade executes,\nthe market maker has $s_{new} = s + \\Delta s = 1200 - 200 = 1000$ STEEM, and\n$t_{new} = t + \\Delta t = 3600 + 400 = 4000$ tokens.\n\nTo check condition (b), that the CRR invariant holds, we effectively repeat the\nanalysis in the initial paragraph of this example with the new numbers.  We know\n$M_{new} = (1000, 4000, 12000, 0.25)$ and $p = 0.5$.  Then of the $T = 12000$\nTOKEN in existence, $t_{new} = 4000$ TOKEN is now held by the MM, so\n$T-t_{new} = 12000 - 4000 = 8000$ TOKEN are now circulating.  These circulating\ntokens are worth $p(T-t_{new}) = 4000$ STEEM total, so they ``should be'' backed\nby a target reserve level of $rp(T-t) = 4000 * 0.25 = 1000$ STEEM.  Since the\ntarget reserve level indeed exactly matches the actual reserve level of\n$s_{new} = 1000$ STEEM, we conclude that the CRR invariant is satisfied after\nthis relaxing trade.\n\n\\section{Infinitesimal trades}\n\nThis section is fairly technical; the reader will need a good grasp of\ncalculus and differential equations to follow the results.\n\n\\subsection{Setting up the problem}\n\nSuppose we satisfy the invariant condition at some price\n$p = p_eq$; by the CRR invariant $s = r v( p, 0, T-t) = r p (T-t)$.\nSuppose the price then increases to $p + \\Delta p$ and a relaxing trade\n$\\Delta s, \\Delta t$ occurs at this new price.\n\nIn this section we consider the limiting situation where $\\Delta p$ is\ninfintesimally small, so we will use Leibniz notation ($dp$ for a small change\nin $p$, $ds$ for a small change in $s$, $dt$ for a small change in $t$).\n\n\\subsection{Solving the DE's}\n\nBy applying the substitution $p \\gets p + dp$ to the expression for $\\Delta s$\ncomputed in the previous section, we obtain an expression which simplifies\nto a separable DE which can be solved:\n\n\\begin{eqnarray*}\nds & = & {1 \\over 1-r} \\left( r (p + dp) (T - t) - s \\right) \\\\\n   & = & {1 \\over 1-r} \\left( r p (T - t) + r dp (T - t) - r p (T - t) \\right) \\\\\n   & = & {1 \\over 1-r} r (T - t) dp \\\\\n   & = & {1 \\over 1-r} \\left( {s \\over p} \\right) dp \\\\\n\\Rightarrow {1 \\over p} dp & = & (1-r) \\left( {1 \\over s} ds \\right) \\\\\n\\Rightarrow \\int {1 \\over p} dp & = & (1-r) \\int {1 \\over s} ds \\\\\n\\Rightarrow \\ln(p) & = & (1-r) \\ln(s) + C_0 \\\\\n\\Rightarrow p & = & k_0 s^{1-r}\n\\end{eqnarray*}\n\nSimilarly for $t$, we can start from $dt = -ds / p$ and again obtain and solve\na separable DE:\n\n\\begin{eqnarray*}\ndt & = & -ds / p \\\\\n   & = & -{r \\over 1-r} (T - t) dp / p \\\\\n\\Rightarrow {1 \\over T-t} dt & = & -{r \\over 1-r} \\left( {1 \\over p} \\right) dp \\\\\n\\Rightarrow {1 \\over p} dp & = & {1-r \\over r} \\left( {1 \\over t-T} \\right) dt \\\\\n\\Rightarrow \\int {1 \\over p} dp & = & {1-r \\over r} \\int {1 \\over t-T} dt \\\\\n\\Rightarrow \\ln(p) & = & {1-r \\over r} \\ln | t-T | + C_1 \\\\\n\\Rightarrow p & = & k_1 (T-t)^{1-r \\over r}\n\\end{eqnarray*}\n\n\\section{Qualitative discussion}\n\nIn a CRR market maker, where does the ``backing'' for newly emitted tokens come from?\n\nOne option is to lower the reserve ratio $r$.  This option results in no immediate market\nactivity, but will weaken the response of the market maker to any future price changes.\nThis is called the ``pay later'' option.\n\nAnother option is to change the dynamical system's initial conditions, i.e. edit the\nconstants of integration.  This option will cause the equilibrium price $p_{eq}$ to drop,\nmeaning the market maker will more aggressively sell tokens to replenish the reserve.\nIf order books are deep compared to the amount of emission, and there are adequate buyers\nfor the tokens, then the sales will be able to replenish the reserve and keep the equilibrium\nprice near its old value; the deep order books provide resistance to the price change being\ndriven by the market maker.  If order books are thin compared to the amount of emission,\nand there are few/no buyers for the tokens, then the equilibrium price will fall, breaking\nthrough the thin orders and lowering the market price.  Even though few/no many tokens were\nsold, so even though the \\textit{absolute} amount of STEEM in the reserve is still\nnearly/exactly the same as before, the reserve's value \\textit{relative} to the now-lower\nmarket cap of the token has increased to the reserve ratio.  This option is the ``pay now''\noption.\n\n\n\n\n\\section{FAQ}\n\nFAQ\n\nQ:  Where are the pretty pictures and graphs?\n\nA:  They're being worked on right now, and will exist in a future version of this paper.\n\nQ:  What is the relevance of constant portfolio ratio policy?\n\nA:  It may become a supported market maker policy in the future.\n\nQ:  Can the reserve ratio go over 100 percent?\n\nA:  No.\n\nQ:  Can the reserve ratio be exactly 100 percent?\n\nA:  Not with the system described in this paper.  It might be possible to code as a special case.\n\nQ:  In a CRR market maker, where does the ``backing'' for newly emitted tokens come from?\n\nA:  As blockchain designers, we have two options for sourcing the ``backing''.  One option\nis to lower the reserve ratio $r$.  This option results in no immediate market\nactivity, but will weaken the response of the market maker to any future price changes.\nThis is called the ``pay later'' option.\n\nAnother option is to change the dynamical system's initial conditions, i.e. edit the\nconstants of integration.  This option will cause the equilibrium price $p_{eq}$ to drop,\nmeaning the market maker will more aggressively sell tokens to replenish the reserve.\nIf order books are deep compared to the amount of emission, and there are adequate buyers\nfor the tokens, then the sales will be able to replenish the reserve to its target level while\nkeeping the equilibrium price near its old value.  The deep order books provide resistance to\nthe price change being driven by the market maker.\n\nIf order books are thin compared to the amount of emission, and there are few/no buyers for the\ntokens, then the equilibrium price will fall, breaking through the thin orders and lowering\nthe market price.  Even though few/no many tokens were sold, so even though the\n\\textit{absolute} amount of STEEM in the reserve is still nearly/exactly the same as before,\nthe reserve's value \\textit{relative} to the now-lower market cap of the token has increased\nto the reserve ratio.  This option is the ``pay now'' option.\n\nQ:  Where's the ``don't pay'' option?\n\nA:  You have to come up with some answer to where the ``backing'' for newly emitted\ntokens will come from.  Unless there's no emission.  Or unless there's no ``backing'' for\nany tokens.  So the ``don't pay'' option would be to have an SMT with either no\nemission, or no market maker.\n\nQ:  Don't fractional exponents require floating point to implement?\n\nA:  Only if you need fairly high precision (we don't), don't care about bit-for-bit\nreproducibility across compilers, OS's, CPU's, etc (we do), and need to do massive\nnumbers of calculations quickly (we don't).  A fast, approximate, all-integer\nimplementation is possible.\n\nQ:  Does this market maker interact with the order book through the existing limit order\nsystem, or is it a separate set of operations?\n\nA:  In theory, it could be implemented either way.  However, the likely outcome is that the market maker will be implemented outside of order-book markets to allow its code to be modularized.  In practice, if implemented as a completely separate subsystem, people will run arbitrage bots which will trade away any price differences\nbetween the reserve system and the existing market system.\n\nQ:  Where do the market maker's initial token balances come from?\n\nA:  ICO units can specify the market maker as a destination.  An ICO creator\nmay direct a percentage of ICO's STEEM contributions to the MM by specifying\nthe market maker similarly to specifying a founder.  Or may use the soft cap\nsystem to specify all STEEM above a pre-determined amount goes to the ICO.  Likewise,\na fixed or percentage amount of tokens can be added in the ICO to increase the MM's\ntoken balance.\n\nQ:  Can someone send STEEM or tokens to the market maker?\n\nA:  Yes.\n\nQ:  What are the side effects of sending STEEM or tokens to the market maker?\n\nA:  The constants of integration are re-initialized, meaning the equilibrium price will\nchange.  The market maker will become more aggressive about selling the asset.\n\nQ:  Can't this cause manipulation or appropriating the market maker's inventory\nto private profit?\n\nA:  Sending assets to the market maker does cause it to engage in trading activity\nwhich affects the price.  However, dumping an identical amount on the market will\nresult in a larger amount of trading activity and a larger effect on the price.  If\nEve is willing to spend her tokens/STEEM to manipulate prices, she would prefer\nthe strategy of simply dumping tokens/STEEM on the market, as that strategy is more\ncost-effective for her.\n\nQ:  Does the market maker's activity generate profits (losses)?\n\nA:  It depends on how you measure ``profits.'' If you measure the value of STEEM\nand tokens in some external third currency such as US dollars or bitcoins, the\nmarket maker's inventory, valued in that currency, can definitely increase or\ndecrease.  If people voluntarily send STEEM or tokens to the market maker,\nsuch activity definitely increases the value of the market maker regardless of\nyour measurement.\n\nAnother way to define profits is by the constants of integration.  If both\nof the constants of integration increase, or one increases while the other\nremains the same, a tiny increase occurs with each trade when the market\nmaker is in ``taker'' mode.\n\nQ:  What is ``taker'' mode?  How can a market maker be set to operate\nin ``taker'' mode?\n\nA:  When orders execute, the order used to set the price is called the maker;\nthe maker's counterparty is the taker.  In the STEEM on-chain market (and on\nalmost all trading platforms) the older order is always the maker.\n\nWhen the market maker is in taker mode, its actions are always considered to be\ntaker orders, which execute at the price specified by the user acting as its\ncounterparty -- this price is always at least a little bit more favorable than\nthe market maker is willing to accept.  When the market maker is not in taker\nmode, its actions are always considered to be maker orders, which don't\ngenerate changes in the constants of integration.\n\nTaker mode is a runtime parameter that can be set by the SMT's control account.\n\nQ:  Who benefits from the profits of a market maker in taker mode?\n\nA:  Maybe nobody, or maybe everybody.  It's decentralized.\n\nQ:  OK, if my SMT reaches a steady price, the STEEM in the reserve is basically\nlocked up forever.  That seems not cool.  How do I set it up so that this STEEM\ncan be unlocked for the benefits of my SMT users?\n\nA:  Set the DRR (decaying reserve ratio) setup parameter.  If you set DRR, then the\nreserve ratio will slowly drop over time to a pre-set value, using its excess STEEM\nreserves to buy excess tokens.  Setting DRR is an excellent, fair, decentralized\nway to return excess capitalization to contributors in a more-popular-than-anticipated\nICO that raises more than the sponsor can effectively spend.\n\nQ:  If the reserve ratio can change over time due to pay-later emissions or DRR,\nit's not really a constant reserve ratio, is it?\n\nA:  No, they're not.  The reserve ratio's called ``constant'' because it's constant\nover the short-term, in normal conditions, or in the conditions in Bancor which is\nwhere it was named.  But the name could be regarded as slightly misleading.\n\nQ:  If the constants of integration can change over time, they're not really\nconstants either, are they?\n\nA:  No, they're not.  They're called constants of integration because that's their\nmathematical role in the calculation that introduces them.  Maybe they'll be\ndifferently named in a future version of this paper.\n\nQ:  Can I specify a contribution to a DRR to be a pay-later contribution, that\n\\textit{increases} its reserve ratio, the increase to be eventually negated over\ntime by future decay?  Why would I want to?\n\nA:  Yes.  This is effectively contributing to the market maker,\nsubject to the condition that it's not allowed to immediately dump a portion\nof the contribution.  It's useful if you want to make a large contribution\nto a market maker without causing it to create a disturbance by immediately\ndumping a significant fraction of your contribution onto the market.\n\nQ:  Can I specify a DRR with emission to use pay-later for emissions when the\nRR is decaying?\n\nA:  Yes.\n\nQ:  Is the market maker specified here equivalent to a Bancor token changer?\n\nA:  No.  A Bancor token changer has multiple reserve ratios that must sum to\none hundred percent, and involves a third token that effectively represents\nequity in the token changer.  This paper's market maker has none of these\nfeatures.\n\nQ:  I want to have an initial ``price discovery'' period where people trade\nwithout action from the market maker, then have tokens and STEEM from\nthe ICO gradually flow in over time to the market maker so it has a delayed,\nslow start from zero to full power.  Can I do it?\n\nA:  This is called ``gradual seeding'' and it may be supported.\n\nQ:  What about numerical stability?\n\nA:  A market maker will be restricted to only operate when its\nbalances exceed a certain minimum for both assets.  Also, reserve\nratios will be restricted to a certain range, all the mechanisms\nthat can set / increase / decrease a reserve ratio will be restricted\nto not allow it to move outside the range.  Tentative numerical\nexperiments suggests these limits should be about 10,000 satoshis\nof both assets, 5 percent and 50 percent, respectively.  These\nvalues are subject to change based on future experimentation,\nworst-case analysis, and testing.\n\n\\end{document}\n", "meta": {"hexsha": "ae020c84588eafccf22ae102b3ea9ad7c1f9b482", "size": 20376, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "smt-manual/market-maker.tex", "max_stars_repo_name": "blocktradesdevs/smt-whitepaper", "max_stars_repo_head_hexsha": "cc10fc34e20b31ccbacdda436ddd2ee004896488", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": 35, "max_stars_repo_stars_event_min_datetime": "2017-09-28T19:01:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T08:07:17.000Z", "max_issues_repo_path": "smt-manual/market-maker.tex", "max_issues_repo_name": "blocktradesdevs/smt-whitepaper", "max_issues_repo_head_hexsha": "cc10fc34e20b31ccbacdda436ddd2ee004896488", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": 36, "max_issues_repo_issues_event_min_datetime": "2017-09-29T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-20T18:22:39.000Z", "max_forks_repo_path": "smt-manual/market-maker.tex", "max_forks_repo_name": "blocktradesdevs/smt-whitepaper", "max_forks_repo_head_hexsha": "cc10fc34e20b31ccbacdda436ddd2ee004896488", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2017-10-16T23:44:24.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-15T14:56:19.000Z", "avg_line_length": 48.7464114833, "max_line_length": 331, "alphanum_fraction": 0.7311542992, "num_tokens": 5499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6404627525086258}}
{"text": "% Preamble.\n\\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{siunitx}\n%\\usepackage{subfiles}  % Include for subfiles.\n%\\usepackage{tikz}  % Include for handmade figures.\n\\usepackage{graphicx}  % Include for external figures.\n\n%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{1}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-08-28}\n\n\\title{\\vspace{-2\\baselineskip}PHYS 225 - Written Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\n\\section*{1.}\n\\textit{Consider the vectors $\\vec{A} = -2\\hat{\\imath} - 2\\hat{\\jmath}$ and\n$\\vec{B} = \\hat{\\imath} + 3\\hat{\\jmath}$.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Find the unit vectors\n\t$\\hat{A} = \\frac{\\vec{A}}{\\|\\vec{A}\\|}$ and\n\t$\\hat{B} = \\frac{\\vec{B}}{\\|\\vec{B}\\|}$.}\n\t\\begin{gather*}\n\t\t\\hat{A}\n\t\t= \\frac{\\vec{A}}{\\|\\vec{A}\\|}\n\t\t= \\frac{-2\\hat{\\imath} - 2\\hat{\\jmath}}{2\\sqrt{2}}\n\t\t= \\boxed{\n\t\t\t-\\frac{1}{\\sqrt{2}} \\hat{\\imath}\n\t\t\t- \\frac{1}{\\sqrt{2}} \\hat{\\jmath}\n\t\t}, \\\\\n\t\t\\hat{B}\n\t\t= \\frac{\\vec{B}}{\\|\\vec{B}\\|}\n\t\t= \\frac{\\hat{\\imath} + 3\\hat{\\jmath}}{\\sqrt{10}}\n\t\t= \\boxed{\n\t\t\t\\frac{1}{\\sqrt{10}} \\hat{\\imath}\n\t\t\t+ \\frac{3}{\\sqrt{10}} \\hat{\\jmath}\n\t\t}.\n\t\\end{gather*}\n\t\\item \\textit{Express the vector $\\vec{C} = 5\\hat{\\imath} - 3\\hat{\\jmath}$\n\tin terms of $\\hat{A}$ and $\\hat{B}$.}\n\t\\begin{gather*}\n\t\t\\vec{C} = \\hat{A}x + \\hat{B}y, \\\\\n\t\t\\begin{pmatrix} 5 \\\\ -3 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{10}} \\\\\n\t\t\t-\\frac{1}{\\sqrt{2}} & \\frac{3}{\\sqrt{10}}\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix} x \\\\ y \\end{pmatrix}.\n\t\\end{gather*}\n\tSolving for $x$ and $y$,\n\t\\begin{equation*}\n\t\t\\begin{pmatrix} x \\\\ y \\end{pmatrix}\n\t\t= \\begin{pmatrix} -9\\sqrt{2} \\\\ -4\\sqrt{10} \\end{pmatrix}.\n\t\\end{equation*}.\n\tThus,\n\t\\begin{equation*}\n\t\t\\vec{C} = \\boxed{\n\t\t\t-9\\sqrt{2}\\hat{A} - 4\\sqrt{10}\\hat{B}\n\t\t}.\n\t\\end{equation*}\n\\end{enumerate}\n\n\\section*{2.}\n\\textit{A particle moves in one dimension with a velocity\n$v(t) = v_0 + v_1 t^3$, where $v_0 = 2.00\\si{\\frac{m}{s}}$ and\n$v_1 = 1.00\\si{\\frac{m}{s^4}}$.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Assuming that at $t_0 = 0$, the particle is at position\n\t$x_0 = 4.00\\si{m}$ measured from the origin, derive a formula for the\n\tparticle's position as a function of time.}\n\t\\begin{gather*}\n\t\tv(t) = v_1 t^3 + v_0, \\\\\n\t\tx(t)\n\t\t= \\int v(t) dt\n\t\t= \\boxed{\n\t\t\t\\frac{v_1}{4}t^4 + v_0 t + x_0\n\t\t}.\n\t\\end{gather*}\n\t\\item \\textit{Obtain a formula for the acceleration of the particle.}\n\t\\begin{equation*}\n\t\ta(t)\n\t\t= \\frac{d}{dt} v(t)\n\t\t= \\boxed{\n\t\t\t3v_1 t^2\n\t\t}.\n\t\\end{equation*}\n\t\\item \\textit{Make quantitative plots of the particle's position,\n\tvelocity, and acceleration as a function of time during the interval\n\t$t_0 = 0$ and $t_1 = 1.00\\si{s}$.}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.6\\textwidth]{fig.pdf}\n\t\\end{center}\n\t\\newpage\n\t\\item \\textit{What is the particle's average velocity and acceleration in\n\tthe time interval $t_0 = 0$ to $t_1 = 1.00\\si{s}$?} \\\\[\\baselineskip]\n\tFor the interval $[0, 1.00\\si{s}]$, let $v_{avg}$ and $a_{avg}$ be the\n\tparticle's average velocity and average acceleration over the interval\n\trespectively.\n\t\\begin{gather*}\n\t\tv_{avg}\n\t\t= \\frac{x(1.00\\si{s}) - x(0)}{1.00\\si{s} - 0}\n\t\t= \\frac{6.25\\si{m} - 4.00\\si{m}}{1.00\\si{s} - 0}\n\t\t= \\boxed{2.25\\si{\\frac{m}{s}}}, \\\\\n\t\ta_{avg}\n\t\t= \\frac{v(1.00\\si{s}) - v(0)}{1.00\\si{s} - 0}\n\t\t= \\frac{3.00\\si{\\frac{m}{s}} - 2.00\\si{\\frac{m}{s}}}{1.00\\si{s} - 0}\n\t\t= \\boxed{1.00\\si{\\frac{m}{s^2}}}.\n\t\\end{gather*}\n\t\\item \\textit{What is the particle's position at the end of this time\n\tinterval (at $t_1 = 1.00\\si{s}$)?}\n\t\\begin{align*}\n\t\tx(1.00\\si{s})\n\t\t&= \\frac{v_1}{4}(1.00\\si{s})^4 + v_0 (1.00\\si{s}) + x_0 \\\\\n\t\t&= {\n\t\t\t\\frac{1.00\\si{\\frac{m}{s^4}}}{4}(1.00\\si{s})^4\n\t\t\t+ 2.00\\si{\\frac{m}{s}} (1.00\\si{s})\n\t\t\t+ 4.00\\si{m}\n\t\t} \\\\\n\t\t&= \\boxed{6.25\\si{m}}\n\t\t.\n\t\\end{align*}\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "e81f8d8f17e78ae2c70317e25d992ae365c9071a", "size": 4079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20203-phys-151-50380/hw01/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-20203-phys-151-50380/hw01/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-20203-phys-151-50380/hw01/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": 28.7253521127, "max_line_length": 75, "alphanum_fraction": 0.6038244668, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799253, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.6404627349729926}}
{"text": "\\section{Dijkstra's Algorithm as Framework}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Dijkstra's algorithm}\n  \\[\n\t\\dist(v) = \\min_{u \\in N(v)} \\set{\\dist(u) + l(u,v)}\n  \\]\n  \n  \\begin{columns}\n\t\\column{0.35\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\ForAll{$v \\in V$}\n\t\t  \\State $\\dist[v] \\gets \\infty$\n\t\t\\EndFor\n\n\t\t\\State $\\dist[s] \\gets 0$\n\t\t\\Statex\n\t\t\\State $Q \\gets \\text{MinPQ}(V)$\n\t  \\end{algorithmic}\n\t\\column{0.60\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\While{$Q \\neq \\emptyset$}\n\t\t  \\State $u \\gets \\text{deleteMin}(Q)$\n\t\t  \\ForAll{$(u,v) \\in E \\land v \\in Q$}\n\t\t\t\\If{$\\dist[v] > \\dist[u] + l(u,v)$}\n\t\t\t  \\State $\\dist[v] \\gets \\dist[u] + l(u,v)$\n\t\t\t  \\State $\\text{decreaseKey(Q, v)}$\n\t\t\t\\EndIf\n\t\t  \\EndFor\n\t\t\\EndWhile\n\t  \\end{algorithmic}\n  \\end{columns}\n\n  \\vspace{0.50cm}\n  \\[\n\tO(n + (n+m) \\log n) \\implies O((n + m) \\log n) \\implies O(m \\log n)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Dijkstra's algorithm}\n  \\begin{columns}\n\t\\column{0.45\\textwidth}\n\t  Prim's algorithm for MST:\n\t  \\begin{algorithmic}\n\t\t\\If{$\\text{cost}[u] > w(u,v)$}\n\t\t  \\State $\\text{cost}[u] \\gets w(u,v)$\n\t\t\\EndIf\n\t  \\end{algorithmic}\n\t\\column{0.45\\textwidth}\n\t  BFS:\n\t  \\begin{algorithmic}\n\t\t\\State $Q \\gets \\text{FIFO-Q}(s)$\n\t\t\\Statex\n\t\t\\If{$\\dist[v] = \\infty$}\n\t\t  \\State $\\dist[v] \\gets \\dist[u] + 1$\n\t\t\\EndIf\n\t  \\end{algorithmic}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Unique shortest paths}\n  \\begin{exampleblock}{Unique shortest paths (Problem 6.18)}\n\t  Undirected graph $G = (V, E), w(e) > 0, s \\in V$:\n\t  \\[\n\t\t\\text{usp}[v] = T \\iff \\exists! s \\leadsto^{\\SP} v \n\t  \\]\n  \\end{exampleblock}\n\n  \\begin{columns}[t]\n\t\\column{0.30\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\ForAll{$v \\in V$}\n\t\t  \\State $\\text{usp}[v] \\gets F$\n\t\t\\EndFor\n\t\t\\State $\\text{usp}[s] \\gets T$\n\t  \\end{algorithmic}\n\t\\column{0.60\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\If{$\\dist[v] > \\dist[u] + l(u,v)$}\n\t\t  \\State $\\dist[v] \\gets \\dist[u] + l(u,v)$\n\t\t  \\State $\\text{usp}[v] \\gets \\text{usp}[u]$\n\t\t\\ElsIf{$\\dist[v] = \\dist[u] + l(u,v)$}\n\t\t  \\State $\\text{usp}[v] \\gets F$\n\t\t\\EndIf\n\t  \\end{algorithmic}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Number of shortest paths}\n  \\begin{exampleblock}{Number of shortest paths (Problem 6.31, 5.26)}\n\t\\[\n\t  \\# s \\leadsto^{\\SP} v\n\t\\]\n\n\t\\[\n\t  O(n + m) \\text{\\emph{ if }} w(e) = 1\n\t\\]\n  \\end{exampleblock}\n\n  \\[\n\t\\text{Num}[s] = 1 \\text{\\emph{ vs. }} \\text{Num}[s] = 0\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Min-max path problem}\n  \\begin{exampleblock}{Min-max path problem (Problem 6.23)}\n\t\\begin{itemize}\n\t  \\item $G = (V, E)$: network of highways\n\t  \\item $l_e$: road length; $L$: tank capacity\n\t  \\item (1) Given $L$, $\\exists? s \\leadsto t$.\n\t  \\item (2) Given $G$, compute $\\min L$.\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\[\n\tL[v] = \\min_{u \\in N(v)} \\max \\set{L[u], l(u,v)}\n  \\]\n\n  \\begin{columns}\n\t\\column{0.35\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\ForAll{$v \\in V$}\n\t\t  \\State $L[v] \\gets \\infty$\n\t\t\\EndFor\n\t\t\\State $L[s] \\gets 0$\n\t  \\end{algorithmic}\n\t\\column{0.65\\textwidth}\n\t  \\begin{algorithmic}\n\t\t\\If{$L[v] > \\max(L[u], l(u,v))$}\n\t\t  \\State $L[v] \\gets \\max(L[u], l(u,v))$\n\t\t\\EndIf\n\t  \\end{algorithmic}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Min-max path problem}\n  \\begin{exampleblock}{Min-max path problem (Problem 6.23)}\n\t\\begin{itemize}\n\t  \\item $G = (V, E)$: network of highways\n\t  \\item $l_e$: road length; $L$: tank capacity\n\t  \\item (1) Given $L$, $\\exists? s \\leadsto t$.\n\t  \\item (2) Given $G$, compute $\\min L$.\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\vspace{0.50cm}\n  \\centerline{$O(\\log m)$ binary searches for $\\min L$}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Max-min path problem}\n  \\begin{exampleblock}{Max-min path problem (Problem 6.26)}\n\t\\begin{itemize}\n\t  \\item $G = (V, E)$: network of oil pipelines\n\t  \\item $c(u,v)$: capacity of $(u,v)$\n\t  \\item (1) Given $s$, compute $\\text{cap}(s, v)$.\n\t  \\item (2) Compute all-pair $\\text{cap}(u,v)$.\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\[\n\t\\text{cap}[v] = \\max_{u \\in N(v)} \\min (\\text{cap}[u], c(u,v))\n  \\]\n\n  \\[\n\tQ \\gets \\text{MaxPQ}(V)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "21ac29efa5b7d75e95a5ad4e98ca91897931bfe5", "size": 4133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/alg-tutorial-paths-20170605/sections/dijkstra-framework.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/alg-tutorial-paths-20170605/sections/dijkstra-framework.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/alg-tutorial-paths-20170605/sections/dijkstra-framework.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": 24.4556213018, "max_line_length": 69, "alphanum_fraction": 0.5584321316, "num_tokens": 1641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6404072371187239}}
{"text": "%!TEX root = ../CombinatoricsNotes.tex\n\n\\section{Convexity}\nWe will consider finite collections of points in Euclidean space, $\\R^d$. Let's recall some definitions.\n\\begin{itemize}[]\n\\item[Linear space:] $L\\subset \\R^d$ is a \\defn{linear space}[linear!space] if it is closed under addition and multiplication by scalars.\n\\item[Linear dependence:] We say $v_1,v_2,\\dotsc,v_n$ are \\defn{linearly dependent}[linear!dependence] if there exist $\\alpha_1,\\alpha_2,\\dotsc,\\alpha_n\\in \\R$ not all zero such that\n\\[\n\\alpha_1 v_1 + \\alpha_2v_2 + \\dotsc + \\alpha_n v_n = 0.\n\\]\n\\item[Linear hull:] The \\defn{linear hull}[linear!hull] $\\braket{S}$ of $S\\subset \\R^d$ is the smallest linear subspace containing $S$, i.e. $\\braket{S}=\\bigcap_{L\\supset S} L$ where the intersection is taken over linear subspaces $L$. Equivalently,\n\\begin{align*}\t\n\\braket{S} = \\{ \\alpha_1 v_1 + \\alpha_2 v_2 + \\dotsc + \\alpha_n v_n: \\forall n,\\, v_1,\\dotsc,v_n\\in S,\\, \\alpha_1,\\dotsc,\\alpha_n\\in \\R \\}.\n\\end{align*}\nNote that we may take $n = d$.\n% , because any $d+1$ vectors in $S\\subset \\R^d$ will be linearly dependent.}\n\n\\item[Affine subspace:] An \\defn{affine subspace}[affine!subspace] is a subset of $\\R^d$ of the form $v+ L$ where $L$ is a linear subspace and $v\\in \\R^d$.\n\n\\item[Affine hull:] The \\defn{affine hull}[affine!hull] $\\aff(S)$ of $S\\subset \\R^d$ is the intersection of all affine subspaces containing $S$. Equivalently,\n\\[\n\\aff(S) = \\{\\alpha_1 v_1 + \\alpha_2 v_2 + \\dotsb + \\alpha_n v_n : \\sum_i \\alpha_i= 1,\\, v_1,\\dotsc,v_n\\in S\\}.\n\\]\nNote: if $w\\in v+L$, then $w-v\\in L$, so $w+L = v+L$. \n\n\\item[Affine dependence:]A set of vectors $\\{v_1,\\dotsc,v_n\\}$ are \\defn{affinely dependent}[affine!dependence] if \n\\[\n\\alpha_1 v_1 + \\dotsb + \\alpha_n v_n = 0\n\\]\nfor some $\\sum_{i=1}^n\\alpha_i=0$ with some $\\alpha_i \\neq 0$. This is equivalent to one of the vectors belongs to the affine hull of the other vectors.\n\\begin{remark}\nThe maximum number of affinely independent vectors in $\\R^d$ is $d+1$. Why? Any $d+2$ vectors in $\\R^d$ are affinely dependent. Suppose we have $v_1,\\dotsc,v_{d+2}$. Then WLOG $v_1,\\dotsc,v_d$ form a basis of $\\R^d$. Then $\\alpha_1 v_1 + \\dotsb + \\alpha_d v_d = v_{d+1}$ for some choice of $\\alpha_i$'s. Likewise, $\\beta_1 v_1  +\\dotsb + \\beta_d v_d = v_{d+2}$. Let $\\alpha = \\sum_i \\alpha_i$ and $\\beta = \\sum_i \\beta_i$. So\n\\begin{align*}\t\n\\alpha_1 v_1 + \\dotsb + \\alpha_d v_d - v_{d+1} &= 0\\\\\n\\beta_1 v_1 + \\dotsb + \\beta_d v_d - v_{d+2} &= 0.\n\\end{align*}If $\\alpha=1$ or $\\beta=1$, then we are done. Otherwise,\n\\begin{align*}\t\n(\\beta-1)(\\alpha_1 v_1 + \\dotsb + \\alpha_d v_d - v_{d+1}) - (\\alpha-1)(\\beta_1 v_1 + \\dotsb + \\beta_d v_d - v_{d+2} ) &= 0\n\\end{align*}\nwhich demonstrates affine dependence, as the sum of coefficients is $(\\beta-1)(\\alpha-1) - (\\alpha-1)(\\beta-1)=0$.\n\\end{remark}\n\n\n\\item[Convex:] A set $C\\subset \\R^d$ is \\defn{convex} if for any two points $v_1,v_2\\in C$, the interval joining these two points lies in $C$. That is, if $v_1,v_2\\in C$, then $\\{\\alpha v_1 + (1- \\alpha)v_2: 0\\leq \\alpha \\leq 1\\} \\subset C$.\n\\item[Convex hull:]  For $X\\subset \\R^d$, the \\defn{convex hull}[convex!hull] $\\conv(X)$ is the intersection of all convex sets containing $X$. Then\n\\[\n\\conv(X) = \\{\\alpha_1 v_1 + \\dotsc + \\alpha_n v_n:n\\in \\N,\\, v_1,\\dotsc,v_n\\in X, \\sum_i \\alpha_i =1, \\alpha_i\\geq 0 \\}\n\\]\nNote that $\\alpha_1 v_1 + \\dotsc + \\alpha_n v_n$ where $\\alpha_i\\geq 0$ and $\\sum_i \\alpha_i=1$ is called a \\defn{convex combination}[convex!combination] of $v_1,\\dotsc,v_n$.\n\nTo prove this formula,  we note by induction on $n$ we see that any convex combination of $n$ vectors in $X$ is in $\\conv(X)$: wlog $\\alpha_n\\neq 0$, $\\alpha_n\\neq 1$. Then \n\\[\n\\alpha_1 v_1 + \\dotsc + \\alpha_n v_n = (1- \\alpha_n) \\underbrace{\\left[ \\frac{\\alpha_1}{1- \\alpha_n}v_1 + \\dotsc + \\frac{\\alpha_{n-1}}{1 - \\alpha_n} v_{n-1} \\right]}_{\\in \\conv(X)} + \\alpha_n \\underbrace{ v_n.}_{\\in \\conv(X)}\n\\]\nSo this set of convex combinations is a subset of $\\conv(X)$. But since the set of convex combinations is itself convex, as it is easy to check, we have equality.\n\n\\item[Convex dependence:]We say $X\\subset \\R^d$  is \\defn{convex dependent}[convex!dependence] if for some $x\\in X$ we have $x\\in \\conv(X\\setminus \\{x\\})$. \\marginnote{That is, one vector in $X$ is a convex combination of some of the others.}\n\nWe say $X$ is \\defn{convex independent}[convex!independence] if it is not convex dependent.\n\n\\begin{remark}\nNo point on the boundary of a circle is a convex combination of the other points, so there is no bound on the size of convex independent sets.\n\\end{remark}\n\n\\end{itemize}\n\n\n\\begin{theorem}[\\cite{Radon1921}] \nLet $A\\subset \\R^d$ be finite, with $|A| \\geq d+2$. Then there exist disjoint $A_1,A_2\\subset A$ such that $\\conv(A_1)\\cap \\conv(A_2)\\neq 0$.\n\n\\end{theorem}\n\\begin{remark}\nLet's first consider the case $d=2$, $|A| =4$. If three points do not fall on a line (a degenerate case), then there are two cases: \n\\begin{figure}\n\\hfill\n\\begin{tikzpicture}[scale=1.5]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (1.5,0);\n\\coordinate (c) at (.75,1);\n\n\\coordinate (d) at (0.5,.3);\n% \\draw[green] (a) -- (d) --;\n% \\draw[blue] (b) -- (c);\n\\filldraw[LightBlue] (a) -- (b) -- (c) -- cycle;\n\\filldraw[black] (a) circle (1pt);\n\\filldraw[black] (b) circle (1pt);\n\\filldraw[black] (c) circle (1pt);\n\\filldraw[black] (d) circle (1pt);\n\n\\end{tikzpicture}\n\\hfill\n\\begin{tikzpicture}[scale=1.5]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (0,1);\n\\coordinate (c) at (1.25,0);\n\\coordinate (d) at (1.25,1);\n\\draw[green] (a) -- (d);\n\\draw[blue] (b) -- (c);\n\n\\filldraw[black] (a) circle (1pt);\n\\filldraw[black] (b) circle (1pt);\n\\filldraw[black] (c) circle (1pt);\n\\filldraw[black] (d) circle (1pt);\n\n% \\node at (a) {\\textbullet};\n\n\\end{tikzpicture}\n\\hfill\n\\caption{Four points in $\\R^2$, when no three form a line. Either one is in the convex hull of the other three (left), or we may divide into pairs so that the convex hulls intersect (right).}\\label{fig:Radon_example_d2}\n\\end{figure}\nIn either case, we may verify Radon's theorem.\n% \\missingfigure{BLue Triangle with dot in middle}\n\\end{remark}\n\n\\begin{proof}\t\nWLOG, we may take $|A|=d+2$; any surplus points we could put in $A_1,A_2$, or neither, without changing the result. Set $A=  \\{v_1,v_2,\\dotsc,v_{d+2}\\}$. Since $v_1,v_2,\\dotsc,v_{d+2}$ are affinely dependent\\sidenote{since there are more than $d+1$ of them}, there exist $\\alpha_1,\\dotsc,\\alpha_{d+2}$ with $\\sum_i \\alpha_i=0$ not all zero such that\n\\[\n\\alpha_1v_1 + \\dotsb + \\alpha_{d+2} v_{d+2} = 0.\n\\]\nLet $A_1 = \\{v_i : \\alpha_i > 0\\}$ and $A_2 = \\{ v_i: \\alpha_i < 0\\}$. WLOG, $\\alpha_1,\\dotsc,\\alpha_k > 0$ and $\\alpha_{k+2},\\dotsc,\\alpha_{d+2} < 0$. Let $s = \\alpha_1 + \\dotsb + \\alpha_k = - \\alpha_{k+1} - \\dotsb - \\alpha_{d+2}$.\nThen\n\\begin{align*}\t\n\\left( \\frac{\\alpha_1}{s} \\right) v_1 + \\dotsb + \\left( \\frac{\\alpha_k}{s} \\right) v_{k+1} = \\left( - \\frac{\\alpha_{k+1}}{s} \\right)v_{k+1} + \\dotsb + \\left( - \\frac{\\alpha_{d+2}}{s} \\right)v_{d+2}.\n\\end{align*}\nBut as shown by the LHS, this quantity lies in $\\conv(A_1)$, and as shown by the RHS, the quantity lies in $\\conv(A_2)$.\n\\end{proof}\n\n\\begin{theorem}[\\cite{Caratheodory1911}]\nEvery point in $\\conv(X)$ for $X\\subset \\R^d$ is a convex combination of at most $d+1$ points in $X$.\n\\end{theorem}\n\\begin{proof}\t\nLet $x\\in \\conv(X)$ be written $x = \\alpha_1 v_1 + \\dotsb + \\alpha_n v_n$ for $v_1,\\dotsc,v_n\\in X$ and $\\sum_i \\alpha_i=0$ with $\\alpha_i\\geq 0$ not all zero. Suppose is $n$ is chosen minimally such that a convex combination exists. Suppose $n\\geq d+2$ for the sake of contradiction. Then by Radon's theorem, wlog\n\\[\n\\conv(\\{v_1,\\dotsc,v_k\\})\\cap \\conv(\\{v_{k+1},\\dotsc, v_n \\}).\n\\]\nSo, for some $\\beta_1,\\dotsc,\\beta_n\\geq 0$,\n\\[\n\\beta_1 v_1 + \\dotsb \\beta_k v_k = \\beta_{k+1} v_{k+1} + \\dotsb + \\beta_n v_n\n\\]\nwith $\\sum_{i=1}^k \\beta_i = \\sum_{i=k+1}^n \\beta_i = 1$. Then\n\\vspace{-\\baselineskip}\n\\begin{fullwidth}\n\\begin{align}\t\nx &= (\\alpha_1 + \\epsilon \\beta_1) v_1 + \\dotsb + (\\alpha_k + \\epsilon \\beta_k)v_k + (\\alpha_{k+1} - \\epsilon \\beta_{k+1})v_{k+1}+ \\dotsb +  (\\alpha_n - \\epsilon \\beta_n)v_n \\tag{$\\star$} \\label{eq:Cara_proof}\n\\end{align}\n\\end{fullwidth}\nhas the sum of coefficients one for every $\\epsilon$. If $\\epsilon>0$ is minimally such that $\\alpha_i - \\epsilon \\beta_i=0$ for some $i$, then the expression \\eqref{eq:Cara_proof} is a convex combination of $\\{v_1,\\dotsc,v_n\\}\\setminus \\{v_i\\}$, giving a contradiction.\n\\end{proof}\n\\begin{theorem}[\\cite{Helly1923}]\nLet $C_1,C_2\\dotsc,C_n$ be a collection of convex sets in $\\R^d$. If $\\bigcap_{i\\in I} C_i \\neq \\emptyset$ for every $I\\subset [n]$ with $|I| = d+1$, then $\\bigcap_{i=1}^n C_i \\neq \\emptyset$.\n\\end{theorem}\n\\begin{remark}\nFor $\\R^1$, if we consider \\marginnote{Convex sets in $\\R^1$ may be open or closed intervals or rays, but we will take closed intervals for simplicity.}$C_i = [a_i,b_i]$, then if each $C_i\\cap C_j\\neq \\emptyset$, then we need $a_i \\leq b_j$ for each $i,j$. Then $[\\max_i a_i, \\min_i b_i] \\subset C_k$ for all $k$.\n\\end{remark}\n\\begin{proof}[Proof by induction on $n$.] \nLet us postpone the base case, $n=d+2$.\nFor the induction step, let $C_1' = C_1 \\cap C_n$, \\ldots, $C_{n-1}' = C_{n-1} \\cap C_n$. Then by the base case, any $(d+1)$ sets in $\\{C_1',\\dotsc,C_{n-1}'\\}$ have a non-empty intersection. Therefore they all intersect by the induction hypothesis, hence\n\\[\n\\bigcap_{i=1}^n C_i = \\bigcap_{i=1}^{n-1}C_i' \\neq \\emptyset.\n\\]\nSo let us show the base case. Let $v_i \\in \\bigcap_{j\\neq i} C_j$; by the assumption. Let $A = \\{v_1,\\dotsc,v_{d+2}\\}$. Then by Radon's theorem, there exist disjoint $A_1,A_2\\subset A$ such that $\\conv(A_1)\\cap \\conv(A_2)\\neq \\emptyset$. Consider $v\\in \\conv(A_1)\\cap \\conv(A_2)$. We will show that $v\\in C_i$ for every $i$.\n\nSuppose wlog that $v_i \\in A_2$. Then $A_1 \\subset C_i$. Since $C_i$ is convex, then $\\conv(A_1) \\subset C_i$. So $v\\in C_i$, as desired. See \\cref{fig:Helly_proof} for an example of this process in $\\R^2$. \\qedhere\n% \\missingfigure{Draw four disks in $\\R^2$, $C_1,\\dotsc,C_4$. Draw the $v_i$ in all the intersections but $v_i$. Connect $v_1,v_3$ in red $v_2,v_4$ in blue. Then let $v$ be the intersection. $v$ is in all four; it is in $C_1$ because it's in the interval between $v_2,v_4 \\in C_1$. Etc.}\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[circ/.style={circle,minimum size=\\circdiam cm,draw,opacity=.7}]\n\n\n\\def\\circposrad{1}\n\\def\\circdiam{3}\n\n\\node[circ,label={right:$C_1$}] at (0:\\circposrad cm) {};\n\\node[circ,label={above:$C_2$}] at (90:\\circposrad cm) {};\n\\node[circ,label={left:$C_3$}] at (180:\\circposrad cm) {};\n\\node[circ,label={below:$C_4$}] at (270:\\circposrad cm) {};\n\n\\coordinate (v3) at (0:.7cm);\n\\coordinate (v4) at (90:.7cm);\n\\coordinate (v1) at (180:.7cm);\n\\coordinate (v2) at (270:.7cm);\n\n\\draw[red] (-.7,0) -- (.7,0);\n\\draw[blue] (v2) -- (v4);\n\n\\filldraw[black] (v1) circle (1.65pt) node[label=$v_1$]{};\n\\filldraw[black] (v2) circle (1.65pt) node[label=right:$v_2$]{};\n\\filldraw[black] (v3) circle (1.65pt) node[label=$v_3$]{};\n\\filldraw[black] (v4) circle (1.65pt) node[label=above:$v_4$]{};\n\n\\draw (0,0) circle (1.75pt);% node[label={[label distance=.02cm]north east:$v$}]{};\n\\end{tikzpicture}\n\\end{center}\n\\caption{Helly's theorem in $\\R^2$. Given four convex sets $C_1,\\dots,C_4$ such that every triple has a non-empty intersection $v_i \\in \\bigcap_{j\\neq i} C_j$, we can use Radon's theorem to divide $\\{v_1,v_2,v_3,v_4\\}$ into two disjoint sets with non-empty convex hull. Here, $A_1 = \\{v_1,v_3\\}$ and $A_2 = \\{v_2,v_4\\}$. The point in the intersection $\\conv(A_1)\\cap \\conv(A_2)$ is labelled here with an open circle.} \\label{fig:Helly_proof}\n\\end{figure}\n\\end{proof}\n\n\\begin{remark}\nHelly's theorem may not apply to infinite collections of sets; consider $\\{[n,+\\infty):n\\in \\N\\}$.\n\\end{remark}\n\nFor any set of $n$ points on the line, we can find a point such that there are at least $n/2$ points above it and below it. This is the median. How do we find an analog for $\\R^d$? We'd like to find a point that in any direction away from this point, there are still many points in our set.\n\n\nLet us generalize to $\\R^d$: Given $X\\subset \\R^d$, $|X|=n$, the \\defn{centerpoint} of $x$ is a point $m\\in \\R^d$ such that for every closed halfspace $H\\subset \\R^d$ such that $m\\in H$, then $H$ contains at least $\\frac{n}{d+1}$ points in $X$.\n\n\\begin{theorem}\nFor every finite set $X\\subset \\R^d$, there exists a centerpoint.\n\\end{theorem}\n\\begin{proof}\t\nNote the following are all equivalent:\n\\begin{itemize}\n\\item $m$ is a centerpoint\n\t\\item  For every closed halfspace $H\\subset \\R^d$, if $m\\in H$ then $|H\\cap X| \\geq \\frac{n}{d+1}$.\n\t\\item For every closed halfspace $H\\subset \\R^d$, if  $|X\\cap H| < \\frac{n}{d+1}$, then $m\\not \\in H$.\n\t\\item For every closed halfspace $H\\subset \\R^d$, if $|X\\cap H^c| > n - \\frac{n}{d+1} = \\frac{dn}{d+1}$, then $m\\in H^c$.\n\t\\item For every open halfspace $H\\subset \\R^d$, if $|X\\cap H| >  \\frac{dn}{d+1}$, then $m\\in H$.\n\\end{itemize}\n% Alternatively, every open half space which does not contain $m$ must contain at most $$\nConsider the family \n\\begin{align*}\t\n\\H = \\{H: H \\text{ is an open halfspace of }\\R^d, |H\\cap X| >  \\frac{dn}{d+1}\\}.\n\\end{align*}\nWe will show for some $m \\in \\R^d$, we have $m\\in H$ for every $H\\in \\H$, proving that $m$ is a centerpoint. \nFirst, if $H_1,H_2,\\dotsc,H_{d+1}\\in \\H$, then\n\\begin{align*}\t\nH_1\\cap H_2\\cap \\dotsm \\cap H_{d+1}\\neq \\emptyset.\n\\end{align*}\nOtherwise, every point of $X$ belongs to $\\leq d$ out of $d+1$ of these half spaces, and thus\n\\begin{align*}\t\ndn = \\sum_{i=1}^{d+1} \\frac{dn}{d+1} < \\sum_{i=1}^{d+1} |H_i \\cap X| \\leq d n\n\\end{align*}\nwhich is a contradiction.\n\nWe would like to now apply Helly's theorem, but we have an infinite collection $\\H$ instead of a finite one.\n\nLet us instead set $\\H' = \\{ \\conv(Y): Y\\subset X, |Y| > \\frac{dn}{d+1}\\}$. By the previous argument and Helly's theorem, there exists $m\\in \\R^d$ such that $m\\in C$ for every $C\\in \\H'$. But this suffices. For any $H\\in \\H$  there is $Y\\subset X$ with $|Y| > \\frac{dn}{d+1}$ and $Y\\subset H$. Then $\\conv(Y) \\subset H$ since $H$ is convex. But since $m\\in \\conv(Y)$, we have $m\\in H$, as desired.%if $m\\not \\in H$, then $m\\not \\in \\conv(Y)$ which is a contradiction.\n% If $m\\not \\in H$, then we want that $H$ contains\n\\end{proof}\n\n\n\n\\begin{theorem}[Birch]\nLet $X\\subset \\R^2$ be a collection of $3n$ points. Then $X$ can be partitioned into $n$ triples such that the corresponding triangles all share a point in common.\n\\end{theorem}\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{scope}[scale=.6]\n\\coordinate (v1) at (0:3cm);\n\\coordinate (v9) at (20:2cm);\n\\coordinate (v6) at (130:1cm);\n\\coordinate (v3) at (240:2.3cm);\n\\coordinate (v5) at (160:3.3cm);\n\\coordinate (v4) at (290:.3cm);\n\\coordinate (v7) at (80:1.3cm);\n\\coordinate (v2) at (340:1.23cm);\n\\coordinate (v8) at (45:3cm);\n\\foreach \\n in {1,2,3,4,5,6,7,8,9}\n{\n\t\\filldraw (v\\n) circle (1.65pt);\n}\n\\end{scope}\n\\node at (3cm,0){$\\leadsto$};\n\\begin{scope}[scale=.6, xshift=10cm]\n\\coordinate (v1) at (0:3cm);\n\\coordinate (v9) at (20:2cm);\n\\coordinate (v6) at (130:1cm);\n\\coordinate (v3) at (240:2.3cm);\n\\coordinate (v5) at (160:3.3cm);\n\\coordinate (v4) at (290:.3cm);\n\\coordinate (v7) at (80:1.3cm);\n\\coordinate (v2) at (340:1.23cm);\n\\coordinate (v8) at (45:3cm);\n\\foreach \\n in {1,2,3,4,5,6,7,8,9}\n{\n\t\\filldraw (v\\n) circle (1.65pt);\n}\n\n\\filldraw[blue,opacity=.4] (v7) -- (v4) -- (v1) -- cycle;\n\n\\filldraw[green,opacity=.4] (v2) -- (v5) -- (v8) -- cycle;\n\n\\filldraw[red,opacity=.4] (v3) -- (v6) -- (v9) -- cycle;\n\\end{scope}\n\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{An example of Birch's theorem with nine points. On the left, the nine points are depicted; on the right, intersecting triangles chosen.}\\label{fig:birch_ex}\n\\end{figure}\n% \\missingfigure{Draw 9 points and three triangles in different colors so that there is a common area. Label a point of intersection.}\n\\begin{remark}\nSee \\cref{fig:birch_ex} for an example.\n\\end{remark}\\begin{proof}\n% \\missingfigure{Draw rays from centerpoint to each vertex}\n\nLet $m$ be a centerpoint of $X$. Label the points of $X$ by $x_1$, $x_2$, \\ldots, $x_{3n}$ so that the rays $mx_1$, $mx_2$, \\ldots, $mx_{3n}$ are arranged around $m$ in clockwise order, as shown in \\cref{fig:birch_proof1}.\n\\begin{figure}[ht]\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{scope}[scale=1]\n\\coordinate (m) at (.7cm,.3cm);\n\\coordinate (v1) at (0:3cm);\n\\coordinate (v9) at (20:2cm);\n\\coordinate (v6) at (130:1cm);\n\\coordinate (v3) at (240:2.3cm);\n\\coordinate (v5) at (160:3.3cm);\n\\coordinate (v4) at (290:.3cm);\n\\coordinate (v7) at (80:1.3cm);\n\\coordinate (v2) at (340:1.23cm);\n\\coordinate (v8) at (45:3cm);\n\\foreach \\n in {6,7}\n{\n\t\\filldraw (v\\n) circle (1.65pt) node[above]{$x_\\n$};\n}\n\\foreach \\n in {4,5}\n{\n\t\\filldraw (v\\n) circle (1.65pt) node[left]{$x_\\n$};\n}\n\\foreach \\n in {1,8,9}\n{\n\t\\filldraw (v\\n) circle (1.65pt) node[right]{$x_\\n$};\n}\n\\foreach \\n in {2,3}\n{\n\t\\filldraw (v\\n) circle (1.65pt) node[below]{$x_\\n$};\n}\n\n% \\filldraw[blue,opacity=.4] (v5) -- (v4) -- (v1) -- cycle;\n\n% \\filldraw[green,opacity=.4] (v3) -- (v9) -- (v8) -- cycle;\n\n% \\filldraw[red,opacity=.4] (v6) -- (v7) -- (v2) -- cycle;\n\n\t\\foreach \\n in {1,2,...,9}\n{\n\t\\draw[opacity=.7] (m) -- (v\\n);\n}\n\t\\filldraw[red] (m) circle (1.75pt) node[black,right]{$m$};\n\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\n\\caption{Nine points $\\{x_1,\\dotsc,x_9\\}$ in $\\R^2$ and their centerpoint $m$, in red. Continuing the example from \\cref{fig:birch_ex}, the points are labelled clockwise in order from the centerpoint. }\\label{fig:birch_proof1}\n\\end{figure}\nLet $X_i = \\{ x_i, x_{i+n}, x_{i+2n}\\}$ for $i=1,\\dotsc, n$. Then $m\\in \\conv(X_i)$ for each $i$.\n\nAssume $m\\not \\in \\conv(X_i)$. Then\\sidenote{We are appealing to a separating hyperplane theorem, such as \\cite[Theorem 1.24]{matouvsek2002lectures}, although the result seems clear geometrically in this case.} some closed halfplane containing $m$ separates $m$ from the three points of $X_i$; see \\cref{fig:birch_proof2}. But then the $2n$ rays between $x_i$ and $x_{i+2n}$ fall in the other half of the halfplane, so there are at least $2n+1$ points in $X$ on the other side, contradicting that $m$ is a centerpoint. \\qedhere\n\\begin{marginfigure}\n\\begin{center}\n\\begin{tikzpicture}\n\\coordinate (v3) at (240:2.3cm);\n\\coordinate (v2) at (100:1.5cm);\n\\coordinate (v1) at (130:2cm);\n\\coordinate (m) at (.7cm,.3cm);\n\\foreach \\n in {1,2,3}\n{\n\t\\draw[opacity=.7] (m) -- (v\\n);\n}\n\t\\filldraw (v3) circle (1.65pt) node[left]{$x_i$};\n\t\\filldraw (v2) circle (1.65pt) node[above]{$x_{i+2n}$};\n\t\\filldraw (v1) circle (1.65pt) node[above]{$x_{i+n}$};\n\n\n\\filldraw[blue,opacity=.4] (v1) -- (v2) -- (v3) -- cycle;\n\t\\filldraw[red] (m) circle (1.75pt) node[black,right]{$m$};\n\n\\end{tikzpicture}\n\n\\end{center}\n\\caption{The case where the centerpoint $m$, in red, is not in the convex hull of $X_i$, shown in blue. Then the $2n$ points $\\{x_i,x_{i+1},\\dotsc,x_{i+2n}$ all lie between $x_i$ and $x_{i+2n}$ (angularly) and may be separated from $m$ by a closed hyperplane, contradicting the definition of centerpoint.} \\label{fig:birch_proof2}\n\\end{marginfigure}\n% \\missingfigure{$m$, then line, and three points $x_i$, $x_{i+n}$, $x_{i+2n}$. Draw outline convex hull in red  around those three. They are all on the other side of a halfplane from $m$.}\n\n\\end{proof}\n\n\\begin{theorem}[Colorful Carath\\'eodory theorem, \\cite{barany1982generalization}]\nLet $S_1,S_2,\\dotsc,S_{d+1}\\subset \\R^d$ and suppose that $x\\in \\bigcap_{i=1}^{d+1} \\conv(S_i)$. Then there exist $x_1\\in S_1$, $x_2\\in S_2$, \\ldots, $x_{d+1}\\in S_{d+1}$ such that $x\\in \\conv(\\{x_1,x_2,\\dotsc,x_{d+1}\\})$.\n\\end{theorem}\n\\begin{remark}\nThe different sets correspond to different colors. Then $x$ belongs to a convex combination of points each a different color. Taking each set $S_i \\equiv X$, we recover Carath\\'eodory's theorem.\n\\end{remark}\n\\begin{proof}\t\nWe will say $C$ is a \\defn{colorful simplex} if $C = \\conv(\\{ x_1,x_2,\\dotsc,x_{d+1} \\})$ for $x_i\\in S_i$ for $i\\in[d+1]$. Suppose that no colorful simplex contains $x$.\n\nChoose a colorful simplex $C$ such that $\\dist(C,x) = \\min_{c\\in C} \\|c-x\\|$ is minimal.\\marginnote{$\\|c-x\\| = \\dist(c,x)$ is the 2-norm (Euclidean norm).}\n\nLet $z\\in C$ be the closest point to $x$: $\\dist(z,x) = \\dist(C,x)$.\n\n\nLet $H$ be a hyperplane orthogonal to $zx$ through $z$. Let $H^+$ and $H^-$ be closed halfspaces with respect to $H$ such that $x\\in H^-$.\n\n\\begin{claim}\n$C\\subset H^+$.\n\\end{claim}\n\\begin{subproof}\t\nSuppose not: $z' \\in C\\cap (H^- \\setminus H^+)$\\marginnote{So $z'\\not \\in H^+$}. Then angle $z' z x$ is acute and points on $zz'$ near $z$ are closer to $x$ than $z$, a contradiction.\n\\end{subproof}\n\n\\begin{claim}\n$z\\in \\conv(\\{x_1,\\dotsc,x_{d+1}\\}\\cap H)$.\n\\end{claim}\n\\begin{subproof}\t\n$z = \\sum_{i=1}^{d+1} \\lambda_i x_i$ with $\\lambda_i\\geq 0$, $\\sum_i \\lambda_i =1$, since $z\\in C$. Let $f: \\R^d \\to \\R$ linear such that if $f(p)> 0$ for $p\\in H^+\\setminus H$, and $f(p) = 0$ for $p\\in H$. \n\nThen $0 = f(z) = \\sum_{x_i \\in H^+ \\setminus H} \\lambda_i \\underbrace{f(x_i)}_{>0} + \\sum_{x_i \\in H} \\lambda_i \\underbrace{f(x_i)}_{=0}$. So we must have $\\lambda_i=0$ when $x_i \\in H^+ \\setminus H$.\n\\end{subproof}\n\nBy Caratheordy theorem applied to $z$ and $\\{x_i,\\dotsc,x_{d+1}\\}\\cap H$, there exists $j$ such that \\begin{align*}\t\nz\\in \\conv((\\{x_1,x_2,\\dotsc,x_{d+1}\\}\\setminus \\{j\\})\\cap H).\n\\end{align*}\nWe know $x\\in \\conv(S_j)$, so there exists $x'_j \\in S_j \\cap (H^-\\setminus H^+)$. Let $C' = \\conv( \\{x_1,\\dotsc,x_{j-1},x_j',x_{j+1},\\dotsc,x_{d+1}\\})$.\n\n\\begin{claim}\nThen $\\dist(C',x) < \\dist(C,x)$.\n\\end{claim}\n\\begin{subproof}\t\nWe know $z\\in C'$. Then, as before, points on $x_j' z\\subset C'$ are closer to $x$ than $z$. \n\\end{subproof}\nThis last claim yields a contradiction to minimality of $C$.\n\nNote: we assumed the $S_i$ were finite when assuming there exists a minimal colorful simplex $C$. But in fact, we only need to consider $\\conv(S_i)$, which only depends on $d+1$ points, by (the original) Carath\\'eodory points. Thus, we could take $|S_i|=d+1$ for each $i$.\n\\end{proof}\n\\begin{remark}\nThis proof yields an algorithm to improve our convex set one point at a time to the optimal one. Yet, it is unknown if this algorithm or any other can find the optimal $\\conv(\\{x_1,\\dotsc,x_{d+1}\\})$ in polynomial time.\n\\end{remark}\n\n\\begin{theorem}[\\cite{Tverberg1966}]\nLet $A\\subset \\R^d$ with $|A| \\geq (r-1)(d+1)+1$. Then there exist $A_1,A_2,\\dotsc,A_r\\subset A$ pairwise disjoint such that $\\bigcap_{i=1}^r \\conv(A_i)\\neq \\emptyset$.\n\\end{theorem}\n\\begin{remark}\nRadon's theorem is the case $r=2$. If $d=1$, then we have $2r-1$ points in $\\R$ which we wish to write as $r$ groups with intersecting convex hulls.\n\nFor $d=2$, $3r-2$ points in $\\R^2$ can be partitioned into $r$ groups with intersecting convex hulls. This in fact implies Birch's theorem.\n\\end{remark}\n\nIf $u\\in \\R^n$ and $v\\in \\R^m$, then $u\\otimes v \\in \\R^{nm}$. Suppose $u = (u_1,\\dotsc,u_n)$ and $v = (v_1,\\dotsc,v_m)$; i.e., we have chosen bases for $\\R^n$ and $\\R^m$. Then $u\\otimes v $ can be thought of as a $m\\times n$ matrix with components $(u\\otimes v)_{ij} = u_i v_j$.\n\\begin{align*}\t\nu = \\begin{pmatrix}\nu_1\\\\ u_2\\\\ u_3\n\\end{pmatrix}, \\qquad v = \\begin{pmatrix}\nv_1 \\\\ v_2 \\\\ v_3\n\\end{pmatrix}, \\qquad u\\otimes v = \\begin{pmatrix}\nu_1 v_1 & u_1 v_2 & u_1 v_3\\\\\nu_2 v_1 & u_2 v_2 & u_2 v_3 \\\\\nu_3 v_1 & u_3 v_2 & u_3 v_3\n\\end{pmatrix}.\n\\end{align*}\n\n\\begin{proposition}\n~\\begin{enumerate}\n\\item $(\\alpha_1 u_1 + \\alpha_2 u_2) \\otimes v = \\alpha_1 (u_1\\otimes v) + \\alpha_2 (u_2\\otimes v)$\n\\item  Suppose $v_1,\\dotsc,v_k$ are linearly independent and $u_1\\otimes v_1 + u_2\\otimes v_2 + \\dotsm + u_k \\otimes v_k = 0$. Then $u_1 = u_2 = \\dotsm = u_k = 0$.\n\\end{enumerate}\n\\end{proposition}\nWe will leave the proof of the proposition as an exercise, and proceed to the proof of Tverberg's theorem.\n\\lect{3}{23}\n% \\marginnote{Lecture X: March 23, 2016.}\n\n\\begin{proof}[Proof (\\cite{sarkaria1992tverberg}).]\nLet $m = (r-1)(d+1)+1$.\n\n\\begin{enumerate}\n\t\\item Instead of the orginal setting, consider $A = \\{v_1,v_2,\\dotsc,v_m\\} \\subset \\R^{d+1}$ such that the vectors of $A$ lie in an affine hyperplane not passing through the origin. I.e., there exists $f: \\R^{d+1}\\to \\R$ linear such that $f(v_i) = 1$ for every $i$. \n\t\\item Let $w_1,w_2,\\dotsc,w_r$ be vectors in $\\R^{r-1}$ such that $w_1+w_2+\\dotsc+w_r=0$ and this is essentially the only relation between these vectors. For instance, we could choose $w_i = (\\underbrace{0,\\dotsc,0}_{i-1},1,0,\\dotsc,0)$ for $i=1,\\dotsc,r-1$ and $w_r = (-1,-1,\\dotsc,-1)$.\n\t\\item Consider $\\{v_i \\otimes w_j: 1\\leq i \\leq m, 1\\leq j \\leq r\\}\\subset \\R^{d+1}\\otimes \\R^{r-1}\\cong \\R^{m-1}$. For each $i$, we may think of $S_i:=\\{v_i\\otimes w_j:1\\leq j\\leq r\\}$ as a copy of the $w_j$ embedded in a hyperplane. Note $0\\in \\conv(S_i)$ for each $i$, since\n\t\\begin{align*}\t\n\t0 &= \\frac{1}{r}v_i \\otimes (w_1+w_2+\\dotsm+ w_r) = \\frac{1}{r} v_i \\otimes w_1 + \\frac{1}{r}v_i\\otimes w_2  +\\dotsm + \\frac{1}{r}v_i\\otimes w_r.\n\t\\end{align*}\n\t\\item Apply the Colorful Carath\\'eodory theorem to $S_1,\\dotsc,S_m$ and the point $0$. We get that for $1\\leq i\\leq m$ there exist $j_i$ and $\\lambda_i\\geq 0$ such that\n\t\\begin{align}\t\n\t\\sum_{i=1}^m \\lambda_i (v_i\\otimes w_{j_i})=0 \\label{eq:Tv_conv_comb}\n\t\\end{align}\n\twith $\\sum_i \\lambda_i=1$.\n\n\tLet $A_j = \\{ v_i : j_i = j \\}$ for $j=1,\\dotsc,r$. Let us rewrite \\cref{eq:Tv_conv_comb} as follows.\n\t\\begin{align*}\t\n\t\\sum_{j=1}^r \\left( \\sum_{v_i \\in A_j} \\lambda_i v_i \\right)\\otimes w_j = 0.\n\t\\end{align*}\n\tLet us write $u_j =  \\sum_{v_i \\in A_j} \\lambda_i v_i$. Then we have\n\t\\begin{align*}\t\n\tu_1\\otimes w_1 + u_2\\otimes w_2 + \\dotsm + u_r\\otimes w_r &= 0\\\\\n\t(u_1- u_r)\\otimes w_1 + (u_2-u_r)\\otimes w_2 + \\dotsm + (u_{r-1} - u_r)\\otimes w_{r-1} &= 0\n\t\\end{align*}\n\tusing $w_r = -w_1 - w_2 - \\dotsm - w_{r-1}$. But since $\\{w_1,\\dotsc,w_{r-1}\\}$ are linearly independent, we must have $u_1-u_r = u_2 - u_r = \\dotsm = u_{r-1}- u_r = 0$. That is, \n\t\\[\n\tu_1 = u_2 = \\dotsm = u_r.\n\t\\]\n\tSubstituting the definition of $u_j$,\n\t\\begin{align}\t\n\t\\sum_{v_i \\in A_1} \\lambda_i v_i = \\sum_{v_i\\in A_2} \\lambda_i v_i = \\dotsm = \\sum_{v_i\\in A_r}\\lambda_i v_i. \\label{eq:Tv_lambda_vs_equal}\n\t\\end{align}\n\tSuppose the sum of coefficients $\\lambda_i$ in each expression is the same and is equal to $s$.\\marginnote{In fact, $s= \\frac{1}{r}$.} Then\n\t\\begin{align*}\t\n\t\\sum_{v_i \\in A_1} \\frac{\\lambda_i}{s}v_i = \\dotsm = \\sum_{v_i\\in A_r} \\frac{\\lambda_i}{s}v_i = p\n\t\\end{align*}\n\tand hence $p\\in \\conv(A_k)$.\n\n\tBut if we apply $f$ to \\cref{eq:Tv_lambda_vs_equal}, by linearity we obtain\n\t\\begin{align*}\t\n\t\\sum_{v_i \\in A_1} \\lambda_i f(v_i) = \\sum_{v_i\\in A_2} \\lambda_i f(v_i) = \\dotsm = \\sum_{v_i\\in A_r}\\lambda_i f(v_i). \n\t\\end{align*}\n\tSince $f(v_i)=1$ for all $i$, we find $\\sum_{v_i\\in A_j} \\lambda_i \\equiv s$. \\qedhere\n\\end{enumerate}\n\\end{proof}\n\\flavor{A magical proof. 30 years after the original.}\n\n\\begin{remark}\nIn Helly's theorem, we consider $C_1,\\dotsc,C_n\\subset \\R^d$ convex such that every $(d+1)$-tuple of $C$'s has non-empty intersection. Then we obtain that there is a common point in all of the sets. Suppose instead $\\sim \\frac{1}{2}$ of the $(d+1)$-tuples have a non-empty intersection. What can we say about large intersections?\n\\end{remark}\n\\begin{theorem}[Fractional Helly's theorem]\nFor every $d\\in \\N$ and $0< \\alpha \\leq 1$ there exists a $\\beta = \\beta(\\alpha,d)$ such that the following holds. Let $C_1, C_2,\\dotsc,C_n\\subset \\R^d$ be convex and suppose $\\bigcap_{i\\in I} C_i\\neq \\emptyset$ for at least $\\alpha {n\\choose d+1}$ sets $I\\subset[n]$ with $|I| = d+1$. Then there exists $X \\subset [n]$ with $|X|\\geq \\beta n$ such that $\\bigcap_{i\\in X} C_i \\neq \\emptyset$.\n\n\\end{theorem}\n\\begin{proof}\t\nWe need to assume that $C_1,C_2,\\dotsc,C_n$ are compact; we may do this as follows. For each set $I$ as in the statment, select $p_I \\in \\bigcap_{i\\in I} C_i$. Then replace $C_i$ by $\\conv(\\{p_I:  I \\text{ s.t. } I\\ni i\\})$.\n\nLet $F_I = \\bigcap_{i\\in I} C_i$. Let $<$ be a linear lexicographic order on $\\R^d$. Let $p_I= \\min (F_I)$ in this order, if $F_I\\neq \\emptyset$. Since $F_I$ is compact, $p_I$ exists and is unique.\n\n\\begin{claim}\nFor every $I\\subset[n]$ with $|I|=d+1$, s.t. $F_I\\neq \\emptyset$, there exists $J\\subset I$, $|J| = d$ such that $p_I = p_J$.\n\\end{claim}\n\\begin{remark}\nFor any $J\\subset I$,  we have $p_J \\leq P_I$.\n\\end{remark}\n\\begin{subproof}[Proof of claim.]\nLet $C =  \\{q \\in \\R^d: q< p_I\\}$. Then $C$ is convex. Then $C\\cap \\left( \\bigcap_{i\\in I} C_i \\right) = C\\cap F_I = \\emptyset$. Since this $(d+2)$-tuple intersection is empty, then by the contrapositive of Helly's theorem, not all $(d+1)$-tuples can have empty intersection. But since $F_I\\neq \\emptyset$, the $(d+1)$-tuple with empty intersection must include $C$. So there exists $J\\subset I$ with $|J| = d$ such that\n\\begin{align*}\t\nC \\cap \\left( \\bigcap_{i\\in J}C_i \\right) = \\emptyset.\n\\end{align*}\nThen $p\\geq p_I$ for every $p\\in F_J$.\n\\end{subproof}\n\nNow for every $I\\subset[n]$ with $|I| = d+1$, $F_I\\neq \\emptyset$, select $J\\subset I$ with $|J| = d$ such that $P_J = P_I$. Then there are $\\alpha{n \\choose d+1}$ sets $I$ which we consider, and  ${n\\choose d}$ sets $J$ of size $d$. So some set $J_0$ is associated with at least $\\frac{\\alpha {n\\choose d+1}}{{n\\choose d}}$ sets $I$. Such sets are of the form $J_0 \\cup \\{ i\\}$ for some $i$, and $p_{J_0} \\in C_i$ for such $i$. So $p_{J_0}$ belongs to  at least \n\\begin{align*}\t\n\\frac{\\alpha{ n\\choose d+1}}{{n\\choose d}} + d = \\frac{\\alpha(n-d)}{d+1}+d \\geq \\frac{\\alpha}{d+1}n\n\\end{align*}\nsets $C_i$ (counting the $d$ sets in $J_0$).\nTherefore, we may take $\\beta = \\frac{\\alpha}{d+1}$.\n\\end{proof}\n\\begin{remark}\nThis constant is not optimal; for instance, when $\\alpha=1$, we would like $\\beta=1$ to recover Helly's theorem. The optimal constant is known, however.\n\\end{remark}\n\n\nFor every $k$, we'd like to prove existence (and estimate the value) of the number $g(k)$ such that in every set of $g(k)$ points in $\\R^2$, with no three lying on a line\\sidenote[][-1cm]{``in general position''} there exist $k$ points which are convexly independent\\sidenote[][-1cm]{``in convex position,'' or are the verticies of a convex polygon}.\n\nLet us consider small $k$. Then $g(1)=1$, $g(2)=2$, $g(3)=3$. But $g(4) > 4$, as shown in \\cref{fig:g4}.\n\\begin{marginfigure}[-1cm]\n\\begin{center}\n\\begin{tikzpicture}[scale=1.5]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (1.5,0);\n\\coordinate (c) at (.75,1);\n\n\\coordinate (d) at (0.5,.3);\n% \\draw[green] (a) -- (d) --;\n% \\draw[blue] (b) -- (c);\n\\filldraw[LightBlue] (a) -- (b) -- (c) -- cycle;\n\\filldraw[black] (a) circle (1pt);\n\\filldraw[black] (b) circle (1pt);\n\\filldraw[black] (c) circle (1pt);\n\\filldraw[black] (d) circle (1pt);\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{An illustration of the fact that $g(4) > 4$. We have four points with no three lying on a line such that not all four are convexly independent: one point is in the convex hull of the other three.} \\label{fig:g4}\n\\end{marginfigure}\n\n\\begin{lemma} \\label{lem:g4_is_5}\n$g(4)=5$.\n\\end{lemma}\n\\begin{proof}\t\nLet $X\\subset \\R^2$ be a set of five points in general position. Consider $\\conv(X)$: this is a polygon with 3, 4, or 5 vertices. If there are 4 or 5 vertices we are done, so, assume $\\conv(X)$ is a triangle with vertices $\\{a,b,c\\}$. Let $\\{d,e\\}$ be the remaining two points of $X$, as shown in \\cref{fig:lem89convX}.\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[scale=3]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (1.5,0);\n\\coordinate (c) at (.75,1);\n\n\\coordinate (e) at (0.9,.2);\n\\coordinate (d) at (0.7,.4);\n\n% \\draw[green] (a) -- (d) --;\n% \\draw[blue] (b) -- (c);\n\\filldraw[LightBlue] (a) -- (b) -- (c) -- cycle;\n\t\\filldraw[black] (a) circle (1pt) node[label=left:$a$]{};\n\\filldraw[black] (b) circle (1pt)node[label=right:$b$]{};\n\\filldraw[black] (c) circle (1pt)node[label=above:$c$]{};\n\\filldraw[black] (d) circle (1pt)node[label=below:$d$]{};\n\\filldraw[black] (e) circle (1pt)node[label=below:$e$]{};\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{We assume $\\conv(X) = \\conv(\\{a,b,c\\})$; then $\\{d,e\\}:= X\\setminus \\{a,b,c\\}$ lie inside the triangle formed by $\\{a,b,c\\}$.} \\label{fig:lem89convX}\n\\end{figure}\n\nNow assume the line $de$ intersects $ab$ and $ac$, as shown in \\cref{fig:lem89de_line}.\n\\begin{marginfigure}\n\\begin{center}\n\\usetkzobj{all}\n\\begin{tikzpicture}[scale=1.5]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (1.5,0);\n\\coordinate (c) at (.75,1);\n\n\\coordinate (e) at (0.9,.2);\n\\coordinate (d) at (0.6,.4);\n\n% \\draw[green] (a) -- (d) --;\n% \\draw[blue] (b) -- (c);\n\\filldraw[LightBlue] (a) -- (b) -- (c) -- cycle;\n\t\\filldraw[black] (a) circle (1pt) node[label=left:$a$]{};\n\\filldraw[black] (b) circle (1pt)node[label=right:$b$]{};\n\\filldraw[black] (c) circle (1pt)node[label=above:$c$]{};\n\\filldraw[black] (d) circle (1pt)node[label=below:$d$]{};\n\\filldraw[black] (e) circle (1pt)node[label=below:$e$]{};\n\n\n\n  % \\tkzDefLine[through d](d,e)\n  \\tkzDrawLine[add = 2 and 2](d,e)\n\\end{tikzpicture}\n\\end{center}\n\\caption{We assume the line passing through $d$ and $e$ intersects the sides $ac$ and $ab$ of the triangle. Since no three points in $X$ are colinear, the line passing through $d$ and $e$ must intersect two of the sides of the triangle, so we can always relabel the verticies so that this is the case.} \\label{fig:lem89de_line}\n\\end{marginfigure} Then $bcde$ form a convex quadrangle. We may see this by taking the convex hull of any three of $\\{b,c,d,e\\}$ to form a triangle $T$, and calling the omitted point $z$. Then there are two boundary line segments of the quadrilateral $bcde$ which end in $z$, but each of these line segments only intersects $T$ at the opposite end from $z$. If $z\\in T$, then the whole line between $z$ and those endpoints would have to be included in $T$. Thus, $z\\not \\in T$, and we truly have a convex quadrilateteral $bcde$. This is illustrated in \\cref{fig:lem89T}.\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[scale=3]\n\\coordinate (a) at (0,0);\n\\coordinate (b) at (1.5,0);\n\\coordinate (c) at (.75,1);\n\n\\coordinate (e) at (0.9,.2);\n\\coordinate (d) at (0.7,.4);\n\n% \\draw[green] (a) -- (d) --;\n% \\draw[blue] (b) -- (c);\n\\filldraw[LightBlue] (a) -- (b) -- (c) -- cycle;\n\t\\filldraw[black] (a) circle (1pt) node[label=left:$a$]{};\n\\filldraw[black] (b) circle (1pt)node[label=right:$b$]{};\n\\filldraw[black] (c) circle (1pt)node[label=above:$c$]{};\n\\filldraw[black] (d) circle (1pt)node[label=below:$d$]{};\n\\filldraw[black] (e) circle (1pt)node[label=below:$e$]{};\n\n\\filldraw[pattern=north west lines] (c) -- (d) -- (b) -- cycle;\n\n\\draw[dashed] (d)--(e);\n\\draw[dashed] (e)--(b);\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{We will take $T= \\conv(\\{c,d,b\\})$, the crosshatched region. Then the two dashed lines only intersect $T$ at the verticies $d,b$. We see if $e$ were moved up into $T$, then the line passing through $d$ and $e$ would no longer intersect the segment $ab$.} \\label{fig:lem89T}\n\\end{figure}\n\\end{proof}\n\\begin{theorem}[\\cite{erdosszekeres1935combinatorial}]\n$g(k)$ exists for all $k$.\n\\end{theorem}\n\\begin{proof}\t\nLet $n=g(k)$ be such that in every coloring of $[n]^{(4)}$ in colors red and blue, one can find either a set of $5$ with all quadruples in red, or a set of size $k$ with all quadruples blue. This exists by the Hypergraph Ramsey theorem\\sidenote{For all positive integers $r,k_1$, and $k_2$ there exists a positive integer $n= R^{(r)}(k_1,k_2)$ so that the following holds. If elements of $[n]^{(r)}$ are colored in colors red and blue then there is a set $Z\\subset [n]$ such that either $|Z| = k_1$ and all elements of $Z^{(r)}$ are red, or $|Z| = k_2$ and all elements of $Z^{(r)}$ are blue.}.\n\nColor quadruples of points in red color if it is not in convex position, and otherwise in blue. By  \\cref{lem:g4_is_5}, there exists a set of $k$ points such that every four of them are in convex position.\n\nThen these $k$ points are in convex position by Carath\\'eodory's theorem.\n\\end{proof}\n\\begin{remark}\nWe may obtain much better bounds by longer proofs.\n\\end{remark}\n\n", "meta": {"hexsha": "0dcbc27fcdd0fa7717a3ddc02d831d7f9ef22a0f", "size": 36085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch8_convexity.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/ch8_convexity.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/ch8_convexity.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": 53.618127786, "max_line_length": 594, "alphanum_fraction": 0.6613551337, "num_tokens": 13875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6403352265131278}}
{"text": "% !TEX root = Main.tex\n\\section{Non-Negative Matrix Factorization}\n$\\mathbf{X} \\in \\mathbb{Z}^{N \\times M}_{\\geq 0}$, NMF: $\\mathbf{X} \\approx \\mathbf{U^\\top V}, x_{ij}=\\sum_z{u_{zi}v_{zj}}=\\langle\\mathbf{u}_i \\mathbf{v}_j\\rangle$\nDecompose object into features: topics, face parts, etc.. $\\mathbf{u}$ weights on parts, $\\mathbf{v}$ parts (bases). More interpretable (PCA: holistic repre.).\n\n\\subsection*{EM for MLE for pLSA (NO global opt guarantee)}\n\\textbf{Context Model:} $p(w | d) = \\sum_{z=1}^K p(w | z) p(z | d)$\\\\\n\\textbf{Conditional independence assumption ($*$):}\\\\\n$p(w|d) = \\sum_z p(w,z|d) = \\sum_z p(w|d,z)p(z|d) \\stackrel{*}{=} \\sum_z p(w|z)p(z|d)$\\\\\n\\textbf{Symmetric parameterization:}\\\\\n$p(w, d) = \\sum_z p(z)p(w | z) p(d | z)$ \\\\\nLog-Likelihood: $L(\\mathbf{U}, \\mathbf{V}) = \\sum_{i,j} x_{i,j}\\log p(w_j|d_i) \\\\\n= \\sum_{(i,j) \\in X} \\log \\sum_{z=1}^K p(w_j|z)p(z|d_i)$ \\\\ \n$ p(w_j|z) = v_{zj}$, $p(z|d_i) = u_{zi}$, $\\sum_j^N v_{zj} = \\sum_z^K u_{zi} = 1$\\\\\nE-Step (optimal q: posterior of z over $(d_i, w_j)$):\\\\\n$q_{zij} = \\frac{p(w_j|z)p(z|d_i)}{\\sum_{k=1}^K p(w_j|k)p(k|d_i)} := \\frac{v_{zj}u_{zi}}{\\sum_{k=1}^K v_{kj}u_{ki}}$, $\\sum_z q_{zij}=1$\\\\\nM-Steps:\\\\\n$p(z|d_i) = \\frac{\\sum_j x_{ij}q_{zij}}{\\sum_j x_{ij}}, p(w_j|z) = \\frac{\\sum_i x_{ij}q_{zij}}{\\sum_{i,l}x_{il}q_{zil}}$\\\\\n\n\\subsection*{Latent Dirichlet Allocation}\nTo sample a new document, we need to extend $X$ and $U^T$ with a new row, s.t. $X=U^T V$. (While pLSA fixes both dimensions)\\\\\nFor each $d_i$ sample topic weights $\\mathbf{u}_i$\\textasciitilde Dirichlet($\\alpha$): $p(u_i|\\alpha) = \\prod_{z=1}^K u_{zi}^{\\alpha_k-1}$, then topic $z^t$\\textasciitilde Multi($u_i$), word $w^t$\\textasciitilde Multi($v_{z^t}$)\\\\\nMultinom. obsv. model on wc vec: $p(\\mathbf{x}|V,u) = \\frac{l!}{\\prod_j \\mathbf{x}_j!}\\prod_j \\pi_j^{\\mathbf{x}_j}$ \nwhere $\\pi_j=\\sum_z v_{zj} u_z$, $l=\\sum_j x_j$ \\\\\nBayesian averaging over $\\mathbf{u}$: $p(\\mathbf{x}|\\mathbf{V},\\alpha)=\\int p(\\mathbf{x}|\\mathbf{V},\\mathbf{u})p(\\mathbf{u}|\\alpha)d\\mathbf{u}$\n\n\\subsection*{NMF Algorithm for quadratic cost function}\n\n$\\min_{\\mathbf{U}, \\mathbf{V}} J(\\mathbf{U}, \\mathbf{V}) = \\frac{1}{2} \\|\\mathbf{X} - \\mathbf{U}^\\top\\mathbf{V}\\|_F^2$ (non-negativity)\ns.t. $\\forall i,j,z:u_{zi},v_{zj} \\geq 0 $ \\\\\nComparison with pLSA:\\\\\n1. sampling model: Gaussian vs multinomial\n2. objective: quadratic vs KL divergence\n3. constraints: not normalized \\\\\nAlternating least squares:\\\\\n1. init: $\\mathbf{U}, \\mathbf{V} = rand()$\\\\ 2. repeat 3\\textasciitilde4 for $\\mathit{maxIters}$:\\\\\n3. upd. $(\\mathbf{VV}^\\top)\\mathbf{U} = \\mathbf{VX}^\\top$, proj. $u_{zi} = \\max \\{ 0, u_{zi} \\}$\\\\\n4. update $(\\mathbf{UU}^\\top)\\mathbf{V} = \\mathbf{UX}$, proj. $v_{zj} = \\max \\{ 0, v_{zj} \\}$\n", "meta": {"hexsha": "083833fa0e797ee3270f8390a9dc09da5cb627ef", "size": 2722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NMF.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": "NMF.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": "NMF.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": 69.7948717949, "max_line_length": 230, "alphanum_fraction": 0.6223365173, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7217431943271998, "lm_q1q2_score": 0.6403338774911501}}
{"text": "\\section{Homology Calculations and Applications}\r\n\\begin{example}\r\n    If $S^n\\simeq S^m$, then $m=n$.\r\n    This follows immediately from our calculation of the homology groups of simplices which are the triangulations of the spheres.\r\n\\end{example}\r\n\\begin{theorem}\r\n    If $\\mathbb R^n\\cong\\mathbb R^m$, then $m=n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose we are given a homeomorphism $\\phi:\\mathbb R^m\\to\\mathbb R^n$, then by a translation we can assume WLOG that $\\phi(0)=0$.\r\n    Then we can restrict $\\phi$ so that $\\mathbb R^n\\setminus\\{0\\}$ and $\\mathbb R^m\\setminus\\{0\\}$, which are homotopic to $S^{n-1}$ and $S^{m-1}$ respectively, consequently $S^{n-1}\\simeq S^{m-1}$, so $n=m$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Any map $\\phi:D^n\\to D^n$ has a fixed point.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Repeat the argument as in the $D^2$ case and finish the argument by homology.\r\n\\end{proof}\r\n\\subsection{Mayer-Vietoris Theorem}\r\nThe Mayor-Vietoris theorem is an analog of Seifert-van Kampen theorem as in both deals with the algebraic invariants of spaces that are constructed by gluing.\r\n\\begin{definition}\r\n    A sequence of homomorphisms of abelian groups\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\cdots\\arrow{r}&A_{i+1}\\arrow{r}{f_i}&A_i\\arrow{r}{f_{i-1}}&A_{i-1}\\arrow{r}&\\cdots\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact at $A_i$ if $\\operatorname{Im}f_i=\\ker f_{i-1}$.\r\n    We say the sequence is exact if it is exact at every $A_i$.\r\n\\end{definition}\r\nConsequenly, any exact sequence is a chain complex with all homology groups trivial.\r\n\\begin{definition}\r\n    A short exact sequence is an exact sequence in the form\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&A\\arrow{r}&B\\arrow{r}&C\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n\\end{definition}\r\nSo necessarily $A\\to B$ is injective, $B\\to C$ is surjective and $C\\cong B/A$.\r\nAn exact sequence that is not short is of course called a long exact sequence.\\\\\r\nSuppose $K$ is a simplicial complex with $K=L\\cup M$ where $L,M$ are subcomplexes of $K$.\r\nThen $N=L\\cap M$ is also a subcomplex.\r\nWe usually write $K=L\\cup_NM$.\r\nAnalogous to what we did in Seifert-van Kampen theorem, we want to relate the homology groups of $L,M,N$ to the homology group of $K$.\r\nOf course we immediately get the natual inclusion maps\r\n$$i:N\\to L,j:N\\to M,l:L\\to K,m:M\\to K$$\r\n\\begin{theorem}[Mayer-Vietoris]\\label{mayer-vietoris}\r\n    There exists a map (known as the connecting homomorphism) $\\delta_\\ast:H_n(K)\\to H_{n-1}(N)$ for each $n$ such that the sequence\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\cdots\\arrow{r}{\\delta_\\ast}&H_n(N)\\arrow{r}{i_\\ast\\oplus j_\\ast}&H_n(L)\\oplus H_n(M)\\arrow{r}{l_\\ast-m_\\ast}&H_n(K)\\arrow[swap,overlay,out=0,in=180]{dll}{\\delta_\\ast}&\\\\\r\n            &H_{n-1}(N)\\arrow[swap]{r}{i_\\ast\\oplus j_\\ast}&H_{n-1}(L)\\oplus H_{n-1}(M)\\arrow[swap]{r}{l_\\ast-m_\\ast}&H_{n-1}(K)\\arrow[swap]{r}{\\delta_\\ast}&\\cdots\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact.\r\n\\end{theorem}\r\nWe will prove this after further development on homological algebra.\r\n\\begin{definition}\r\n    We say a sequence of chain complexes\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\cdots\\arrow{r}&A_\\bullet\\arrow{r}{f_\\bullet}&B_\\bullet\\arrow{r}{g_\\bullet}&C_\\bullet\\arrow{r}&\\cdots\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact at $B_\\bullet$ if\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\cdots\\arrow{r}&A_n\\arrow{r}{f_n}&B_n\\arrow{r}{g_n}&C_n\\arrow{r}&\\cdots\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact for every $n$.\r\n\\end{definition}\r\nSo we can analogously define (short) exact sequences of chain complexes.\r\n\\begin{lemma}[Snake Lemma]\r\n    Let\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&A_\\bullet\\arrow{r}{f_\\bullet}&B_\\bullet\\arrow{r}{g_\\bullet}&C_\\bullet\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    be a short exact sequence of chain complexes.\r\n    Then for any $n$ there is a homomorphism $\\delta_\\ast:H_{n+1}(C_\\bullet)\\to H_n(A_\\bullet)$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\cdots\\arrow{r}{\\delta_\\ast}&H_{n+1}(A_\\bullet)\\arrow{r}{f_\\ast}&H_{n+1}(B_\\bullet)\\arrow{r}{g_\\ast}&H_{n+1}(C_\\bullet)\\arrow[swap,overlay,out=0,in=180]{dll}{\\delta_\\ast}&\\\\\r\n            &H_n(A_\\bullet)\\arrow[swap]{r}{f_\\ast}&H_n(B_\\bullet)\\arrow[swap]{r}{g_\\ast}&H_n(C_\\bullet)\\arrow[swap]{r}{\\delta_\\ast}&\\cdots\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We already have this huge commutative diagram with exact rows\r\n    \\[\r\n        \\begin{tikzcd}\r\n            &\\vdots\\arrow{d}&\\vdots\\arrow{d}&\\vdots\\arrow{d}&\\\\\r\n            0\\arrow{r}&A_{n+1}\\arrow{r}{f_{n+1}}\\arrow{d}{\\partial_{n+1}}&B_{n+1}\\arrow{r}{f_{n+1}}\\arrow{d}{\\partial_{n+1}}&C_{n+1}\\arrow{r}\\arrow{d}{\\partial_{n+1}}&0\\\\\r\n            0\\arrow{r}&A_n\\arrow{r}{f_n}\\arrow{d}{\\partial_n}&B_n\\arrow{r}{f_n}\\arrow{d}{\\partial_n}&C_n\\arrow{r}\\arrow{d}{\\partial_n}&0\\\\\r\n            0\\arrow{r}&A_{n-1}\\arrow{r}{f_{n-1}}\\arrow{d}&B_{n-1}\\arrow{r}{g_{n-1}}\\arrow{d}&C_{n-1}\\arrow{r}\\arrow{d}&0\\\\\r\n            &\\vdots&\\vdots&\\vdots&\r\n        \\end{tikzcd}\r\n    \\]\r\n    We now construct $\\delta_\\ast:H_{n+1}(C_\\bullet)\\to H_n(A_\\bullet)$.\r\n    Take $[x]\\in H_{n+1}(C_\\bullet)$ for $x\\in Z_{n+1}(C_\\bullet)$.\r\n    As $g_{n+1}$ is surjective, there is $x\\in B_{n+1}$ such that $g_{n+1}(y)=x$.\r\n    Now $g_n\\circ\\partial_{n+1}(y)=\\partial_{n+1}\\circ g_{n+1}(y)=\\partial_{n+1}(x)=0$.\r\n    So by exactness, there exists $z\\in A_n$ such that $f_n(z)=\\partial_{n+1}(y)$.\r\n    Note that $f_{n-1}\\circ\\partial_n(z)=\\partial_n\\circ f_n(z)=\\partial_n\\circ\\partial_{n+1}(y)=0$, so $\\partial_n(z)=0$ since $f_{n-1}$ is injective.\r\n    This means that $z\\in Z_n(A_\\bullet)$, so we define $\\delta_\\ast([x])=[z]$.\r\n    To see it is well-defined, we have two issues to deal with:\\\\\r\n    First, if we replace $x$ by $x+\\partial_{n+2}(x')$ and $g_{n+2}(y')=x'$ , then replace $y$ with $y+\\partial_{n+2}(y')$.\r\n    Then $g_{n+1}(y+\\partial_{n+2}(y'))=g_{n+1}(y)+\\partial_{n+2}\\circ g_{n+2}(y')=x+\\partial_{n+2}(x')$.\r\n    But $\\partial_{n+1}(y+\\partial_{n+2}(y'))=\\partial_{n+1}(y)$, so $z$ does not change.\\\\\r\n    Secondly, if we have made up our mind on $x$ and $y,y'$ are chosen with $g_{n+1}(y')=g_{n+1}(y)=x$, then $g_{n+1}(y'-y)=0$, therefore by exactness there is some $z'$ such that $f_{n+1}(z')=y'-y$, thus $y'=y+f_{n+1}(z')$.\r\n    So $\\partial_{n+1}(y')=\\partial_{n+1}(y)+\\partial_{n+1}\\circ f_{n+1}(z')=\\partial_{n+1}(y)+f_n\\circ\\partial_{n+1}(z')$, which means $f_n(z+\\partial_{n+1}(z'))=\\partial_{n+1}(y)+f_n\\circ\\partial_{n+1}(z')=\\partial_{n+1}(y')$.\r\n    This is saying that replacing $y$ by $y'$ modifies $z$ by adding $\\partial_{n+1}(z')$.\r\n    But $[z]=[z+\\partial_{n+1}(z')]$, so $\\delta_\\ast$ is well-defined.\\\\\r\n    The proof of the sequence being exact is tedious routine work.\\\\\r\n    At $H_n(B_\\bullet)$, if $[a]\\in H_n(A_\\bullet)$, then by definition $g_\\ast\\circ f_\\ast([a])=[g_n\\circ f_n(a)]=0$ by the exactness of our original short exact sequence.\r\n    So $\\operatorname{Im}f_\\ast\\subset \\ker g_\\ast$.\r\n    Now if $g_\\ast([b])=0$, then $[g_n(b)]=g_\\ast([b])=0$, thus there is some $c\\in C_{n+1}$ with $g_n(b)=\\partial_{n+1}(c)$.\r\n    But then choosing $b'\\in B_{n+1}$ with $g_{n+1}(b')=c$ by exactness gives $g_n(b-\\partial_{n+1}(b'))=0$, hence $b-\\partial_{n+1}(b')\\in\\ker g_n=\\operatorname{Im}f_n$, so there is some $a\\in A_n$ such that $f_n(a)=b-\\partial_{n+1}(b')$.\r\n    In particular, $f_\\ast([a])=[f_n(a)]=[b-\\partial_{n+1}(b')]=[b]$, therefore $\\operatorname{Im}f_\\ast\\supset\\ker g_\\ast$.\r\n    Combining these gives $\\operatorname{Im}f_\\ast=\\ker g_\\ast$ which implies the exactness at $H_n(B_\\bullet)$.\\\\\r\n    At $H_n(A_\\bullet)$, suppose $[z]=\\delta_\\ast([x])$, then $f_\\ast([z])=[f_n(z)]=[\\partial_{n+1}(y)]=0$ where $y$ is as in the construction of $\\delta_\\ast$, so $\\operatorname{Im}\\delta_\\ast\\subset\\ker f_\\ast$.\r\n    Suppose now that $f_\\ast([z])=0$, then $f_n(z)=\\partial_{n+1}(y)$ for some $y\\in B_{n+1}$.\r\n    Take $x=g_{n+1}(y)$, then $\\partial_{n+1}(x)=\\partial_{n+1}\\circ g_{n+1}(y)=g_n\\circ\\partial_{n+1}(y)=g_n\\circ f_n(z)=0$, so $x$ is a cycle, so $[x]$ is a homology class.\r\n    But $\\delta_\\ast([x])=[z]$ by construction, hence $\\operatorname{Im}\\delta_\\ast\\supset\\ker f_\\ast$, therefore $\\operatorname{Im}\\delta_\\ast=\\ker f_\\ast$ which gives the exactness at $H_n(A_\\bullet)$.\\\\\r\n    At $H_n(C_\\bullet)$, if $[x]\\in\\operatorname{Im}g_\\ast$, then (ater replacing $x$ with another representative if necessary) WLOG there exists a cycle $y\\in B_n$ such that $g_n(y)=x$.\r\n    But then immediately $\\delta_\\ast([x])=0$, so $\\operatorname{Im}g_\\ast\\subset\\ker\\delta_\\ast$.\r\n    Conversely, suppose $\\delta_\\ast([x])=0$, then let $y,z$ be the corresponding element in the construction of $\\delta_\\ast$.\r\n    By hypothesis there exists $a\\in A_n$ such that $\\partial_n(a)=z$.\r\n    Then $\\partial_n\\circ f_n(a)=f_{n-1}\\circ\\partial_n(a)=f_{n-1}(z)=\\partial_n(y)$.\r\n    Thus $\\partial_n(y-f_n(a))=0$, so $y-f_n(a)$ is a cycle.\r\n    Also $g_n(y-f_n(a))=x$, so $[x]=g_\\ast([y-f_n(a)])$.\r\n    Consequently $\\operatorname{Im}g_\\ast\\supset\\ker\\delta_\\ast$, so $\\operatorname{Im}g_\\ast=\\ker\\delta_\\ast$.\r\n    This finished the proof.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{mayer-vietoris}]\r\n    Easy to check that $C_\\bullet\\oplus D_\\bullet$ is a chain complex with all data obtained from direct sums of data of $C_\\bullet,D_\\bullet$.\r\n    Also $H_n(C_\\bullet\\oplus D_\\bullet)=H_n(C_\\bullet)\\oplus H_n(D_\\bullet)$.\r\n    It then suffices to check that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&C_\\bullet(N)\\arrow{r}{i_\\bullet\\oplus j_\\bullet}&C_\\bullet(L)\\oplus C_\\bullet(M)\\arrow{r}{l_\\bullet-m_\\bullet}&C_\\bullet(K)\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    is exact.\r\n    The proof is then done by snake lemma.\\\\\r\n    Note that $C_\\bullet(N)$ naturally embeds into $C_\\bullet (L)$ and $C_\\bullet(M)$ via $i_\\bullet\\oplus j_\\bullet$, so in particular $i_\\bullet\\oplus j_\\bullet$ is a injective.\r\n    Also since $K=L\\cup M$, for any $c\\in C_n(K)$ we can write $c=c_L+c_M$ where $c_L$ is a linear combination of simplices in $L$ and $c_M$ is that in $M$.\r\n    Let $b_L,b_M$ be the respective copies of $c_L,c_M$ in $C_n(L),C_n(M)$ respectively, then $l_\\bullet(b_L)=c_L,m_\\bullet(b_M)=c_M$, and hence $c=(l_\\bullet-m_\\bullet)(b_L,-b_M)$, so $l_\\bullet-m_\\bullet$ is surjective.\\\\\r\n    It remains to show the exactness in the middle.\r\n    For $(b_L,b_M)\\in C_n(L)\\oplus C_n(M)$, note that $l_\\bullet(b_L)-m_\\bullet(b_M)=0$ iff every simplex which occurs in $b_L$ also occurs in $b_M$ with the same coefficient.\r\n    This is just saying that $b_L,b_M$ are linear combinations of simplices in $L\\cap M=N$.\r\n    Therefore $\\operatorname{Im}(i_\\bullet\\oplus j_\\bullet)=\\ker (l_\\bullet-m_\\bullet)$, hence the sequence is indeed exact.\r\n\\end{proof}\r\n\\begin{lemma}[Five Lemma]\r\n    Given a commutative diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            A\\arrow{r}\\arrow{d}{\\alpha}&B\\arrow{r}\\arrow{d}{\\beta}&C\\arrow{r}\\arrow{d}{\\gamma}&D\\arrow{r}\\arrow{d}{\\delta}&E\\arrow{d}{\\epsilon}\\\\\r\n            A'\\arrow{r}&B'\\arrow{r}&C'\\arrow{r}&D'\\arrow{r}&E'\r\n        \\end{tikzcd}\r\n    \\]\r\n    If the rows are exact and $\\alpha,\\beta,\\delta,\\epsilon$ are isomorphisms, then $\\gamma$ is also an isomorphism.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\nWe can now prove Proposition \\ref{barycentric_iso_homol}.\r\nRecall that we want to show that $s_\\ast:H_n(K')\\to H_n(K)$ is an isomorphism where $s:K'\\to K$ is a simplicial approximation to the identity map on $|K|=|K'|$ which sends each $\\hat\\sigma$ to a vertex of $\\sigma$.\r\n\\begin{proof}[Proof of Proposition \\ref{barycentric_iso_homol}]\r\n    Induction on the number of simplices of $K$.\r\n    If $K$ has only one simplex, then it is just a vertex, so the proposition is trivial.\r\n    For the induction step, let $\\sigma\\in K$ be of maximal dimension, then $L=K\\setminus \\{\\sigma\\}$ is also a simplicial complex.\r\n    Let $M$ be the simplicial complex consists of $\\sigma$ and its faces.\r\n    Then $N=M\\cap L$ is just the proper faces of $\\sigma$.\r\n    By construction of $s$ we can restrict $s$ to $L',M',N'$ to get the maps\r\n    $$s_\\ast:H_n(L')\\to H_n(L),s_\\ast:H_n(M')\\to H_n(M),s_\\ast:H_n(N')\\to H_n(N)$$\r\n    By the induction hypothesis, these are all isomorphisms.\r\n    Then by Mayer-Vietoris, we have the diagram\r\n    \\[\r\n        \\begin{tikzcd}[column sep=0.34em]\r\n            H_n(N')\\arrow{r}\\arrow{d}{s_\\ast}&H_n(L')\\oplus H_n(M')\\arrow{r}\\arrow{d}{s_\\ast\\oplus s_\\ast}&H_n(K')\\arrow{r}\\arrow{d}{s_\\ast}&H_{n-1}(N')\\arrow{r}\\arrow{d}{s_\\ast}&H_{n-1}(L')\\oplus H_{n-1}(M')\\arrow{d}{s_\\ast\\oplus s_\\ast}\\\\\r\n            H_n(N)\\arrow{r}&H_n(L)\\oplus H_n(M)\\arrow{r}&H_n(K)\\arrow{r}&H_{n-1}(N)\\arrow{r}&H_{n-1}(L)\\oplus H_{n-1}(M)\r\n        \\end{tikzcd}\r\n    \\]\r\n    with exact rows.\r\n    Easy to check that it commutes.\r\n    Also, by the induction hypothesis, all vertical arrows except $s_\\ast:H_n(K')\\to H_n(K)$ are isomorphisms.\r\n    Hence $s_\\ast:H_n(K')\\to H_n(K)$ is an isomorphism by five lemma.\r\n\\end{proof}\r\n\\subsection{Homology of Compact Surfaces}\r\nRecall that we constructed the oriented surfaces of genus $g$ as $\\Sigma_g=\\Gamma_{2g}\\cup_{\\rho_g}D^2$ where $\\Gamma_{2g}$ is a bouquet of $2g$ copies of $S^1$ with generators $\\alpha_1,\\ldots,\\alpha_g,\\beta_1,\\ldots,\\beta_g$ and $\\rho_g=\\alpha_1\\beta_1\\alpha_1^{-1}\\beta_1^{-1}\\cdots \\alpha_g\\beta_g\\alpha_g^{-1}\\beta_g^{-1}$.\r\n\\begin{example}\r\n    $\\Gamma_r$ can be triangulated in the obvious way by taking it as $r$ hollow triangles joined by a common vertex.\r\n    We know that $H_n(\\Gamma_1)$ is $\\mathbb Z$ when $n=0,1$ and $0$ otherwise.\r\n    We claim that\r\n    $$H_i(\\Gamma_r)=\\begin{cases}\r\n        \\mathbb Z\\text{, if $i=0$}\\\\\r\n        \\mathbb Z^r\\text{, if $i=1$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    which we shall show inductively.\r\n    The cases except for $i=1$ are all trivial, so it suffices to show that.\r\n    Suppose we have shown the case for $r-1$, then take $K=\\Gamma_r$, $L$ be a natural copy of $\\Gamma_{r-1}$ in $\\Gamma_r$ and $M$ be the remaining triangle.\r\n    Then $N=L\\cap M=\\{\\ast\\}$ and hence Mayer-Vietoris gives the exact sequence\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&H_1(N)\\arrow{r}&H_1(\\Gamma_{r-1})\\oplus H_1(S^1)\\arrow{r}& H_1(\\Gamma_r)\\arrow[overlay, out=0, in=180]{dll}&\\\\\r\n            &H_0(N)\\arrow{r}&H_0(\\Gamma_{r-1})\\oplus H_0(S^1)\\arrow{r}& H_0(\\Gamma_r)\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    which, after putting in everything we already know,\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&0\\arrow{r}&\\mathbb Z^{r-1}\\oplus \\mathbb Z\\arrow{r}& H_1(\\Gamma_r)\\arrow[overlay, out=0, in=180]{dll}&\\\\\r\n            &\\mathbb Z\\arrow{r}&\\mathbb Z\\oplus \\mathbb Z\\arrow{r}& \\mathbb Z\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    By exactness of the bottom row, the map $\\mathbb Z\\to\\mathbb Z\\oplus\\mathbb Z$ is injective (alternatively this can also be easily seen from the definition of that map), hence the connecting homomophism is the zero map.\r\n    Therefore the top row reduces to the exact sequence\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&\\mathbb Z^{r-1}\\oplus \\mathbb Z\\arrow{r}& H_1(\\Gamma_r)\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    which precisely means that $H_1(\\Gamma_r)\\cong\\mathbb Z^{r-1}\\oplus \\mathbb Z\\cong\\mathbb Z^r$.\r\n\\end{example}\r\nWorth noting that $H_1(\\Gamma_r)$ is the free abelian group on $r$ letters while $\\pi_1(\\Gamma_r)$ is the free group on $r$ letters.\r\nAlso, if $\\alpha_1,\\ldots,\\alpha_r$ are the generating paths of the circles, then $H_1(\\Gamma_r)$ is generated by $\\alpha_1,\\ldots,\\alpha_r$.\r\n\\begin{remark}\r\n    Like in the preceding exacmple, whenever $N$ is connected, the map $H_0(N)\\to H_0(L)\\oplus H_0(M)$ is injective, and hence $H_1(L)\\oplus H_1(M)\\to H_1(K)$ is surjective.\r\n\\end{remark}\r\nNow we want to attach our $2$-cell to get $\\Sigma_g$.\r\nWe'll do this in two steps.\\\\\r\nFirst, we attach a cylinder $S^1\\times I$ via the same $\\rho_g$ but on $S^1\\times\\{0\\}$.\r\nWrite $\\Sigma_g^\\star=\\Gamma_{2g}\\cup_{\\rho_g} (S^1\\times I)$\r\nBy shrinking $I$ to a point we can obtain the deformation retraction of $\\Sigma_g^\\star$ onto $\\Gamma_{2g}$, therefore they have the same homology groups.\\\\\r\nNow $\\Sigma_g=\\Sigma_g^\\star\\cup_\\alpha D^2$ where $\\alpha:\\partial D^2\\to S^1\\times \\{1\\}$ is the natural identity.\r\nWe can choose triangulations of $\\Sigma_g^\\star$ and $D^2$ so that they are compatible under this gluing (so we are essentially removing a $D^2$ from $\\Sigma_g$ to get $\\Sigma_g^\\star$).\r\n\\footnote{There are of course some technical details regarding why we can do this, but we are not going into this part of details here. It is not too hard though.}\r\nLet $L$ be the triangulation of $\\Sigma_g^\\star$ and $M$ be the triangulation of $D^2$ such that this holds.\r\nThen $N=L\\cap M$ is a triangulation of $S^1\\times\\{1\\}\\cong S^1$.\r\nMajer-Vietoris then gives the exact sequence\r\n\\[\r\n    \\begin{tikzcd}\r\n        &H_2(L)\\oplus H_2(M)\\arrow{r}&H_2(\\Sigma_g)\\arrow[overlay, out=0,in=180]{dll}&\\\\\r\n        H_1(N)\\arrow[swap]{r}{i_\\ast}&H_1(L)\\oplus H_1(M)\\arrow{r}&H_1(\\Sigma_g)\\arrow{r}&0\r\n    \\end{tikzcd}\r\n\\]\r\nNote that the zero at the end is due to the preceding remark.\r\nAgain putting everything we already know into it gives\r\n\\[\r\n    \\begin{tikzcd}\r\n        0\\arrow{r}&H_2(\\Sigma_g)\\arrow{r}&\\mathbb Z\\arrow{r}{i_\\ast}&\\mathbb Z^{2g}\\arrow{r}&H_1(\\Sigma_g)\\arrow{r}&0\r\n    \\end{tikzcd}\r\n\\]\r\nThe exactness means that $H_2(\\Sigma_g)\\cong\\ker i_\\ast$ and $H_1(\\Sigma_g)\\cong\\operatorname{coker}i_\\ast=\\mathbb Z^{2g}/\\operatorname{Im}i_\\ast$.\r\nSo we just need to understand $i_\\ast:\\mathbb Z\\to\\mathbb Z^{2g}$, or in other words $i_\\ast:H_1(S^1)\\to H_1(\\Sigma_g^\\star)$.\r\nNote that the generator of $H_1(S^1)$ is the cycle runs through it (which is basically the one corresponding to the generator of $\\pi_1(S^1)$).\r\nThe deformation retract of $\\Sigma_g^\\star$ to $\\Gamma_{2g}$ identifies $S^1$ with the image of the cycle under $\\rho_g$.\r\nTherefore $(\\rho_g)_\\ast$ maps the cycle to $[\\alpha_1]+[\\beta_1]-[\\alpha_1]-[\\beta_1]+\\cdots+[\\alpha_g]+[\\beta_g]-[\\alpha_g]-[\\beta_g]=0$.\r\nTherefore $i_\\ast=0$ and hence $H_2(\\Sigma_g)\\cong\\mathbb Z$ and $H_1(\\Sigma_g)\\cong\\mathbb Z^{2g}$.\r\nTo conclude,\r\n$$H_n(\\Sigma_g)\\cong\\begin{cases}\r\n    \\mathbb Z\\text{, if $n=0,2$}\\\\\r\n    \\mathbb Z^{2g}\\text{, if $n=1$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nwhich in particular allows us to know $g$ given the homology group of some $\\Sigma_g$.\\\\\r\nWe also have the non-orientable surfaces $S_g$ which is given by $\\Gamma_{g+1}\\cup_\\alpha D^2$ where $\\alpha=\\alpha_0^2\\alpha_1^2\\cdots\\alpha_g^2$ where $\\alpha_i$ is the generator of the $i^{th}$ circle in the bouquet.\r\nRepeating the same process gives the exact sequence\r\n\\[\r\n    \\begin{tikzcd}[row sep=tiny]\r\n        0\\arrow{r}&H_2(\\Sigma_g)\\arrow{r}&H_1(S^1)\\arrow{r}{i_\\ast}&H_1(\\Gamma_{g+1})\\arrow{r}&H_1(\\Sigma_g)\\arrow{r}&0\\\\\r\n        &&\\mathbb Z\\arrow[equal]{u}&\\mathbb Z^{g+1}\\arrow[equal]{u}&\r\n    \\end{tikzcd}\r\n\\]\r\nSo again $H_2(S_g)\\cong\\ker i_\\ast$ and $H_1(S_g)\\cong\\operatorname{coker}i_\\ast$.\r\nNote that $i_\\ast$ maps the generator of $H_1(S^1)$ to the nonzero element $2[\\alpha_0]+\\cdots+2[\\alpha_g]$.\r\nHence $\\ker i_\\ast=0$ and $\\operatorname{coker}i_\\ast\\cong\\mathbb Z^{g+1}/(2,\\ldots,2)\\mathbb Z\\cong\\mathbb Z^g\\oplus\\mathbb Z/2\\mathbb Z$.\r\nIn conclusion\r\n$$H_n(S_g)\\cong\\begin{cases}\r\n    \\mathbb Z\\text{, if $n=0$}\\\\\r\n    \\mathbb Z^g\\oplus\\mathbb Z/2\\mathbb Z\\text{, if $n=1$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nIn particular we can tell apart $S_g$ and $\\Sigma_g$ as well.", "meta": {"hexsha": "2c4c7cd452ddbec522b1dd36a0782d7e9403c43b", "size": 19542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/homol.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": "6/homol.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": "6/homol.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": 67.3862068966, "max_line_length": 329, "alphanum_fraction": 0.6425135605, "num_tokens": 7124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.6402676394095056}}
{"text": "\\section{Diatomic gas}\nThe heat capacity is\n\\begin{align}\n    c_v &= (6N + N)\\frac{1}{2}k_B = \\frac{7}{2}k_B N\n\\end{align}\nHarmonic oscillator.\nFor $k_B T \\gg \\hbar\\omega$, $\\bar{E} = k_B T$.\n\nBack to solids.\nDebye model.\n\\begin{itemize}\n    \\item Normal modes have $\\omega_k=v k$ for all 3 modes.\n        2 transverse and 1 longitudinal.\n    \\item Brilluoin zone is a sphere\n        \\begin{align}\n            3N = 3V \\int^{k_D} \\frac{d^3 k}{(2\\pi)^3}\n            =\n            \\frac{V}{2\\pi^2} k_D^3\n        \\end{align}\n        i.e. number of normal modes $3N$ equals number of fourier modes.\n\\end{itemize}\nWe used that\n\\begin{align}\n    \\sum_{\\vec{k}} f(\\vec{k}) \\approx\n    V \\int \\frac{d^3k}{(2\\pi)^3} f(k)\n\\end{align}\nIf you don't know this,\nwe'll discuss it in detail soon.\n\nThe partition function is\n\\begin{align}\n    Z &= \\Tr e^{-\\beta H}\\\\\n    &=\n    \\prod_{k,\\alpha}\\sum_{n_k=0}^{\\infty} e^{-\\beta\\hbar\\omega\\left( n_k +\n    \\frac{1}{2}\n    \\right)}\n\\end{align}\nwhere each term is partition function for one oscillator for one oscillator of\nfrequency $\\omega_k$.\nHere $\\alpha = 1,2,3$\nare the polarizations.\nSo\n\\begin{align}\n    Z &=\n    \\prod_{k,\\alpha}\n    \\frac{e^{-\\beta\\hbar\\omega/2}}{1 - e^{-\\beta\\hbar\\omega_k}}\n\\end{align}\nThe free energy is\n\\begin{align}\n    F &= -k_B T\\ln Z\\\\\n    &=\n    k_B T\n    \\sum_{\\vec{k},\\alpha}\n    \\left[\n    \\ln\\left( 1 - e^{-\\beta\\hbar\\omega_k} \\right)\n    +\n    \\underbrace{\\frac{\\beta\\hbar\\omega_k}{2}}_{\\textrm{negelect zero-point}}\n    \\right]\\\\\n    &\\approx\n    3 k_B T V \\int^{k_D} \\frac{d^3k}{{(2\\pi)}^3}\n    \\ln\\left( 1 - e^{-\\beta\\hbar vk} \\right)\n\\end{align}\nWe neglect the zero-point energy because it's independent of $T$.\nThe factor of 3 comes from the 3 polarizations.\n\nThe entropy is then\n\\begin{align}\n    S &= \\left.\\frac{-\\partial F}{\\partial T}\\right|_{V}\\\\\n    &=\n    -3k_B V \\int^{k_D} d^3k\\, \\ln(\\cdots)\n    +\n    \\frac{3k_B T}{k_B T^2} V\n    \\int^{k_D} d^3k\n    \\frac{\\hbar v k e^{-\\beta\\hbar v k}}{1 - e^{-\\beta\\hbar v k}}\n\\end{align}\n\nAnd finally the energy is\n\\begin{align}\n    E &= F + TS\\\\\n    &=\n    3V \\int^{k_D} \\frac{d^3k}{(2\\pi)^3}\n    \\frac{\\hbar vk}{e^{\\beta\\hbar vk} - 1}.\n\\end{align}\nThen the heat capacity is\n\\begin{align}\n    C_v &=\n    \\left.\\frac{1}{N} \\frac{\\partial E}{\\partial T}\\right|_{V,N}\\\\\n    &=\n    \\frac{1}{N} V\n    \\frac{\\partial}{\\partial T}\n    \\int_{0}^{k_D} \\frac{d^3k}{(2\\pi)^3}\n    \\frac{3\\hbar\\omega_k}{e^{\\beta\\hbar\\omega_k} - 1}\\\\\n    &=\n    \\frac{3V}{N} \\frac{1}{k_B T^2}\n    \\int_{0}^{k_D} \\frac{d^3k}{(2\\pi)^3}\n    \\frac{(\\hbar\\omega_k)^2}{e^{\\beta\\hbar\\omega_k} - 1}\n    e^{\\beta\\hbar\\omega_k}\\\\\n    &=\n    \\frac{3V}{N} \\frac{1}{2\\pi^2}\n    \\frac{(\\hbar v)^2}{k_B T^2}\n    \\left( \\frac{k_B T}{\\hbar v} \\right)^5\n    \\int_{0}^{\\beta\\hbar vk} dx\\,\n    \\frac{x^4}{\\left( e^x - 1 \\right)^2} e^x\n\\end{align}\nwhich for $k_B T \\ll \\hbar v k_D$\ngives\n\\begin{align}\n    C_V &\\approx\n    3 \\frac{V}{N}\n    \\left( \\frac{k_B T^}{\\hbar v} \\right)^3\n    \\frac{1}{2\\pi^2}\n    \\int_{0}^{\\infty} dx\\,\n    \\underbrace{\\frac{x^4 e^{x}}{\\left( e^x - 1 \\right)^2}}_{4\\pi^4/15}\\\\\n    &=\n    \\frac{V}{N}\n    k_B\n    \\frac{2\\pi^2}{5}\n    \\left( \\frac{k_B T}{\\hbar v} \\right)^3\\\\\n    &\\sim T^3\n\\end{align}\nwhich is the $C_v \\sim T^3$ law for low temperatures.\n", "meta": {"hexsha": "c9fa4a30a108bd0fd556dccb9ecf7367bb3dd266", "size": 3249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/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": "phys612/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": "phys612/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": 26.631147541, "max_line_length": 78, "alphanum_fraction": 0.5641735919, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6402676354464254}}
{"text": "\\section{Introduction}\n\\label{sec:intro}\n\nWe consider a rectangular area of dimension $W \\times L$ subdivided into countries of dimension $w \\times l$ each. We consider a cartesian reference system with $x$ pointing to the East and $y$ to the North as shown in figure~\\ref{fig:area_subdivision}. The areas are indexed in left-to-right and bottom-up order.\nFor simplicity, we assume that these dimensions are given as integers, that $l$ divides $L$ and $w$ divides $W$ (the input will be checked).\nWe use MPI as the implementation technology, so we decide to assign each country to a separate MPI process to improve the regularity of the program, while still not preventing multiple processes to be assigned to the same node.\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}[c]{0.7\\textwidth}\n    \\begin{tikzpicture}\n        % grid\n        \\draw[xstep=2, ystep=1] (0,0) grid (8,4);\n        % axes\n        \\draw[->] (0,0) -- (8.25,0) node[right] {$x$};\n        \\draw[->] (0,0) -- (0,4.25) node[above] {$y$};\n        \\node[below left] at (0,0) {$0$};\n        % country dimensions\n        \\draw[<->] (0,-.25) -- node[below] {$w$} (2,-.25);\n        \\draw[<->] (-.25,0) -- node[left] {$l$} (-.25, 1);\n        % world dimensions\n        \\draw[<->] (0,-.75) -- node[below] {$W$} (8,-.75);\n        \\draw[<->] (-.75,0) -- node[left] {$L$} (-.75, 4);\n        % country indices\n        \\matrix[matrix of nodes, inner sep=0, anchor=south west,\n        nodes={minimum width=2cm, minimum height=1cm, inner sep=0, align=center}]{\n            12 & 13 & 14 & 15 \\\\\n                8 &  9 & 10 & 11 \\\\\n                4 &  5 &  6 &  7 \\\\\n                0 &  1 &  2 &  3 \\\\\n        };\n    \\end{tikzpicture}\n    \\end{subfigure}\n    \\begin{subfigure}[c]{0.29\\textwidth}\n    \\begin{tikzpicture}\n        \\draw[step=2] (-.25,-.25) grid (2.25,2.25);\n        \\node           at (1,1) {$c$}; % center\n        \\node[above]    at (1,2) {$c + \\left\\lfloor \\frac{W}{w} \\right\\rfloor$}; % north\n        \\node[right]    at (2,1) {$c + 1$}; % east\n        \\node[below]    at (1,0) {$c - \\left\\lfloor \\frac{W}{w} \\right\\rfloor$}; % south\n        \\node[left]     at (0,1) {$c - 1$}; % west\n    \\end{tikzpicture}\n    \\end{subfigure}\n    \\caption{World subdivision into countries.}\n    \\label{fig:area_subdivision}\n\\end{figure}\n\n\\noindent\nOur program then considers a population $N$ and an initial number of infected individuals $I$ which are uniformly distributed among the countries.\n\n\\paragraph{Motion}\nThe individuals will follow a linear motion with velocity $v$ (given in \\si{m/s}), whose direction is randomly generated for each individual at the beginning of the simulation, and is kept also when moving from one country to another. When an individual is detected reaching (or surpassing) the world boundary it “bounces” onto it: the components of its speed perpendicular to the boundary will be inverted, as in figure~\\ref{fig:boundary_bounce}.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[\n        dot/.style={circle,fill,inner sep=1.25pt},\n        >=stealth\n    ]\n        \\node[dot, label=below:$p_s$] (p1) at (210:2) {};\n        \\node[dot,                  ] (p2) at (30:0) {};\n        \\node[dot,                  ] (p3) at (30:1) {};\n        \\node[dot, label=below:$p_d$] (p4) at (-30:1) {};\n        \\draw[-] (p1) -- (p2);\n        \\draw[->, dashed] (p2) -- (p3);\n        \\draw[->] (p2) -- (p4);\n        \\draw[-, very thick] (-2.5,0) -- (2.5,0);\n        \\draw[draw=none, pattern=north east lines] (-2.5,0) rectangle (2.5,.1);\n    \\end{tikzpicture}\n    \\caption{An individual bouncing on the world boundary}\n    \\label{fig:boundary_bounce}\n\\end{figure}\n\n\\paragraph{Infection and recovery}\nIf a susceptible individual $i$ spends at least $t_{infection} = \\SI{10}{min}$ continuously at a distance $d_{ij}\\leq d$ from an infected person $j$, it gets \\emph{infected} too.\nAfter being infected for $t_{recovery} = \\SI{10}{day}$ a person will become \\emph{immune}, so it can't be infected or infect others. It will become susceptible again after further $t_{immunity} = \\SI{90}{days}$.\n\nWe only consider individuals in the same country when computing infections, in order to reduce the communication between processes. This means that if two individuals are closer than $d$ but in different countries, they won't be able to infect each other. This approximation should be acceptable in a realistic scenario where there are physical borders between countries and where $d$ is much smaller than the size of a country. However, the accumulated exposure time of an individual is not reset when passing the border.\n\n\\paragraph{Simulation step}\nThe position and status of each individual is computed with a granularity of $t_{step}$ seconds, with no interpolation in between.\nWe compute periodic logs of the status of the population as soon as the end of each day has been surpassed, therefore we assume that $t_{step} \\ll \\SI{1}{day}$. Also, in a realistic scenario we should have $t_{step} \\cdot v \\ll w,l$ so that an individual cannot span a whole country in few steps. However, we only enforce $t_{step} \\cdot v \\le w,l$, so that each country only needs to send individuals out to its neighbors.\nThe simulation ends when\n\\begin{enumerate*}[label=(\\roman*)]\n    \\item $t \\geq t_{target}$, or\n    \\item there are no infected people left\n\\end{enumerate*}.", "meta": {"hexsha": "379cbd1091efbf7decd68e3505b9a5f22ae1c33a", "size": 5336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections_report/introduction.tex", "max_stars_repo_name": "fuljo/my-population-infection", "max_stars_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_stars_repo_licenses": ["MIT"], "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_report/introduction.tex", "max_issues_repo_name": "fuljo/my-population-infection", "max_issues_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_issues_repo_licenses": ["MIT"], "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_report/introduction.tex", "max_forks_repo_name": "fuljo/my-population-infection", "max_forks_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_forks_repo_licenses": ["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.0465116279, "max_line_length": 522, "alphanum_fraction": 0.6435532234, "num_tokens": 1587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6402676305456955}}
{"text": "\\documentclass[12pt, leqno]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n%american mathematical society - AMS \n\n\\usepackage{enumerate}\n\n\\usepackage{wrapfig}\n\\usepackage{subfig}\n\n\\oddsidemargin = 0in\n\\textwidth=6.5in\n\n\\numberwithin{equation}{section} \n\n\\numberwithin{figure}{section}\n\n\\begin{document}\n\n%\\baselineskip=20pt \n\nHello world! This is the beginning of \\LaTeX! \\\\\n\nWe can start a new paragraph at any time by leaving a blank line. \nNot that there are many special characters in \\LaTeX or just \\TeX. \nIn particular \\&, \\%, \\#, \\_, \\{, \\}, carets and tildes.  and  \\textbackslash\nare all special characters -- if \\LaTeX sees any of these without a preceding backslash, \nit thinks they are commands. \\\\\n\nA macro is just a markup command. \n\n\\section*{Typesetting Mathematics!}\n\nDonnie Knuth is the creator of \\TeX. To typeset mathematics and it is very good at it. \nWe could type a vector as: \n\n$ (v_1, v_2, v_3)^T $.\n\nWe can create display math in a number of ways. \n\n$$ %display math mode.\nf(x) = x^n + 500x^n-1 + \\cdots + 501x\n$$ \nWe can type many things in \\TeX that were not possible in HTML, for example \n\n\\begin{equation}\ny = x \n\\end{equation}  \n  \n\\begin{displaymath}\ng(x) = \\int_0^\\infty G(t,x) \\, dx  % \\, adds just a little bit of extra space -- only in math mode. \n\\end{displaymath}  \n\nWe can now do more complicated constructions. For example, we say that $\\lambda$ is an eigenvalue of a matrix $A$ corresponding to a vector $\\vec{u}$ or \\(u\\) if $Au = \\lambda u $ For example \n\n%put some bullshit right here. \n%Remember that you CANNOT HAVE BLANK SPACE AT END OF EQUATION!!!\n\nso $-1$ is an eigenvalue corresponding to eigenvector $[1,0]^T$\n\n\\LaTeX\\ can do more sophisticated mathematical typesetting. We can make piecewise defined functions as follows: \n\n\\[\nf(x) = \\begin{cases}\nx^2 & x\\ge 0 \\\\ \n0 & \\text{otherwise}. \n\\end{cases}\n\\]  \n\nHere is an example involving some Greek letters and special functions: \n$$  \n\\Lambda_N = \n\\sum_{n=0}^{N}\\left(\\frac{1}{\\cos\\lambda^n}\\right).\n$$  \n\nWe could write the key part of the proof that the harmonic series diverges as \n\n% &= means align on this thing\n\n\\begin{align}\n\\sum_{i=1}^{2^N-1}\n\\frac{1}{i} &= 1 + \\frac{1}{2} + \\frac{1}{3} + \\cdots + \\frac{1}{2^N-1}\\\\\n&> \\frac{1}{2} + \\frac{1}{4} + \\frac{1}{4} + \n\\overbrace{\\frac{1}{8} + \\cdots + \\frac{1}{8}}^{\\text{4 times}} +\n\\cdots + \\frac{1}{2^N-1} \\quad \\text{for} N > 3\n\\end{align}\n\n\n\\section*{Counting} \n%\\label{sec:math}\n%\\nonumber will give the equation no number. \nAs we saw in Section %\\ref{sec:math} \n\\LaTeX counts many things, such as chapters, sections and other document body parts, equations, \ncitations, theorems and so on. We can manipulate those counters by using the setcounter and addtocounter macros. \n\nTo make our own counter, we just use the \\texttt{setcounter} macro: \n\\newcounter{numberthes}\n\\setcounter{numberthes}{42}\nfor instance, the number of times the word \"the\" has occurred so far is \n\\arabic{numberthes} but now, the number of times ``the\" has occurred. is \n\\addtocounter{numberthes}{2}\n\\arabic{numberthes}  \n% these are back quotes by unix geeks `````````\n\n% there are two environments 'align' starts a bunch of stuff(math mode, number equations, align equal signs) \n% there is 'aligned' that does NOT start math mode. It only starts in math mode. \n%ampersands are for alignment \n\n\\subsection*{Theorems \\& Stuff}\n\\label{subsec:theorems}\nIn this subsection, numbered, \\ref{subsec:theorems}, we will discuss the numbering scheme for theorems, definitions corollaries, and such. \n\n\\newtheorem{theorem}{Theorem}[section] %the counter is at the end. \n\\newtheorem{definition}[theorem]{Definition}\n\n\\newtheorem{lemma}[theorem]{Lemma} %counter in the middle uses an exsisting counter\n\n\n\\begin{definition}\nThe definition is where we put the meanings of the terms we use in our theorems. \n\\end{definition}\n\nFirst, we prove a technical result. \n\\begin{lemma}\nhere is where we prove some little technical result taht we will use in the proof of the theorem.\n\\end{lemma}\n\n\\begin{theorem}\nTheorems are where we prove things about the terms we defined in the definitions. \n\\end{theorem}\n\n\\section*{Lists}\nThere are three kinds of lists in every markup language: \nordered lists, unordered lists, and description lists. \n\n\\begin{enumerate}[A)]\n\\item The first item \n\\item The second item \n\\item The ultimate item \n\\end{enumerate}\n\nHere is an unordered list. \n%\\noindent \n\\begin{itemize}\n\\item one \n\\item two \n\\item three\n\\end{itemize}\n\nHere is a description list. \n\\begin{description}\n\\item[The first definition -] the first def. \n\\item[second -] the second. etc etc \n\\end{description}\n\n\n\\section*{Page layout and spacing}\nPage layout in \\TeX\\ is not as transparent as it is in writing in WYSiWYG word processor \ninstead of setting margins, as we woul in a WYSiWYG program, \\LaTeX\\ knows only where the \nupper left corner of hte text area is relative to the page, and how wide \nand tall the text area is. \nFor this purpose it sets many variables that control the positions and sizes of the text area. \nWe can change the values of these variables. \n\nThere are two ways to change the values of these variables: We can do it directly (set the variable equal to exactly what we want.); or we can use the \\texttt{newdimension} command. \nHere is a list(possibly incomplete) of the variables of what we can change and control. \n\n\\begin{description}\n\\item[oddsidemargin-]This is distance of the text area from the left edge of the page on \\textbf{odd} numbered pages. \nThis is useful when you are writing a book! In the article documentclass, this controls both odd and even numbered pages. Note that the distance we specify here is relative to default 1 inch margin. Not that the documentclass also imposes a separate default. \n\\item[evensidemargin-]this is the distance of the text area from the left edge of the page on even-numbered pages This only applies in some documentclasse, such as in book. \n\\item[topmargin-] This is the top of the page. \n\\item[textwidth-]the width of the text area. \n\\item[textheight-] the height of the text area. \n\\item[headheight-] The height of the header. \n\\item[headsep-]The height of the separation of the header from the text area. \n\\item[footskip-] The distance from th text area to the footer. \n\\item[baselineskip-] The distance from the bottom of on line to the next. \n\\item[baselinestrech] This is actually not a dimension; it is a macro that controls how much the space between\nline is stretched. For example, to get double-spaced text you could type\\\\\n%\\texttt{\\textbackslash renewcommand\\{\\textbackslash baselinestretch\\{2\\}\\}}\n\\item[parskip-] The extra distance to place between paragraphs. \n\\item[parindent-] the amount o indentation at the beginning of every paragraph. Except the first paragraph in article class. \n\n\\subsection{Spacing}\n\nBefore we can really discuss spacing, we have to talk about horizontal and vertical mode. \\LaTeX\\ \ntakes characters not separated by spaces and pastes them together into a word. \nIt takes other white space and replaces it by so-called \\textit{glue}.\nThis is illustrated below: \n%\\begin{description}\n\n%\\begin{center}\n%\\fboxsep=0pt\n%\\framebox(stuff){M}\n%\\end{center}\n\nAll of this word and line formation takes place in horizontal mode. \nPutting lines one after another requires going into vertical mode -- where \\LaTeX\\ figures out how to fit the various lines on the page. \n\nwe can make horizontal spaces \\hspace{10pt} any time we are in horizontal mode. \n\\vspace{0.5in} \\\\\nSpace can be either positive or negative. Note that \\LaTeX cannot put in vertical space except when it is in vertical mode. \n\n%\\end{description}\n\nthere are some special spacing commands that allow us to put in a lot of glue at once. \nIn particular in horizontal mode, the \\texttt{hfil} and \\texttt{hfill} commands put in as much space as we need. \nFor example, look below. \n\\begin{center}\nLeft \\hfill Right \\\\\nLeft \\hfil Right \\\\\nLeft \\hfill middle \\hfill right\n\\end{center}\n\nLikewise, there are commands called \\texttt{vfil} and \\texttt{vfill} that give as much vertical space as we need. \nThere are a couple of similar macros that put dots or rules in place of these spaces. These are called \\texttt{dotfill} and \\texttt{hrulefill}, respectively. \n\\begin{center}\nChapter 12 \\dotfill 121 \n\\end{center}\n\nAnother aspect of spacing is the boxes \\TeX\\ constantly uses form lines and so on. \nFor example, we already saw that we could put a box around any text using \\texttt{framebox} \\framebox{framebox}. \nWe can make a a plain box any time using \\makebox[3in]{makebox} \n\n\n\\parbox{2in}{To get a paragraph of a certain size, use \\texttt{parbox}. Not that the width of this is an obligatory argument.}\n\n\n\n\\end{description}\n\n\n\\section{Graphics}\n\nBefore we start, we should probably mention one or two ways of storing graphics that are not traditional \nimage formats. In particular, the EPS(Encapsulated PostScript) format is often used for storing images used in \\TeX. \nThis is an old-fashioned way to do \n \nto incorporate images into your document, you must first load the \\texttt{graphicx}, After that we can use the famous \\texttt{includegraphics} command to put in your image: viz\\\\\n\\begin{figure}[ht] % 'h' means put it here and 'ht' means that put it at top the and here. 'ht!' put it here now! \n\\centering\n%\\includegraphics[width=0.5\\textwidth]{/path/to/picture.jpg}\n%\\caption{Who brought the cat?!}\n\\end{figure}\n\nNote that from now on we will never refer to figures using any formulations such as ``in the figure below''. Instead, we always give the figure a name (number), and then refer to it using that. \n\nthere are many more packages to allow us to place our figures cleverly, attractively, etc., but we must load each \none separately. Note that some of the these packages are not compatible with features of other packages -- never load packages you do not need. For example, if we want to place a figure to one side of the page with text flowing around it, we use the \\texttt{wrapfig} package. \n\n%\\begin{wrapfigure}{l}{2.54in}\n%\\includegraphics[width=2.5in]{/path/to/filname/cat.jpg}\n%caption{Tijgertje's like to sleep}\n%\\label{fig:hanger}\n%\\end{wrapfigure}\n\nNote that if we want to have figure numbers in the form section.figure, we can again use the \\texttt{numberwithin} macro. We can also refer to %\\ref{fig:hanger} \nusing a \\texttt{ref} command. Also note that the figure number is not incremented until we use the \\texttt{caption}\nmacro -- do not use your \\texttt{label} macro until after that happens. \n\nAnother common requirement is to have two figures side by side. We could actually do that in an ordinary \\texttt{figure} environment, but we would not get captions on each individual figure. Figure environment isn't about figures, but about floating elements. If we want captions then we must load another package: the \\texttt{subfig} package. \n%\\begin{figure}[ht!]\n%\\begin{subfloat}[How it is not done.]\n%{\n%\\includegraphics[.45\\textwidth]{/path/to/the/image/cat.jpg}\n%\\label{fig:done}\n%}\n%\\end{subfloat}\n%\\end{figure}\n%\n%\\begin{figure}\n%\\begin{subfloat}[How it is done.]\n%{\n%\\includegraphics[.45\\textwidth]{/path/to/the/image/cat.jpg}\n%}\n%\\end{subfloat}\n%\\end{figure}\n\nNow we can refer to Figure \\ref{fig:done} using the \\texttt{label-ref} system as usual. \n\n\\section*{Tables}\n\nThere is another environment that works exactly like the \\texttt{figure} environment, except that the object in it that the objects in it that have captions are labeled  ``Table''. That environment is, not surprisingly, called the \\texttt{table} environment. In order to make an actual table we must invoke the \\texttt{tabular} environment. \nTable \\ref{tab:pets} shows an example of some of the simplest features of the \\texttt{tabular} environment. \n\n\\begin{table}[ht!] %difference between a table and a figure? Nothing other than the name. \n\\caption{A summary of pets}\n\\label{tab:pets}\n\\begin{tabular}{| l | c | p{2in} |}\nAnimal & Sociability & something and feeding \\\\ \n\\hline\nDog & high & blah blah bblah \\\\\n\\hline\nCat & low & blah blah blah \\\\ \n\\cline{2-3}\npolitician & \\multicolumn{2}{c|}{Avoid this pet at all costs} \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nNote that the wrapfig package supplies a \\texttt{wraptable} environment that lets tables float to one side or the other. \n\n\\section{References}\n\nWe often (always) need to make references to other sources in our documents. One way of handling those is to use \nthe \\texttt{thebibliography} environment. The key macros associated with this are called \\texttt{bibitem} \nand \\texttt{cite} command to actually refer to it. For example, this document contains some bogus references to Donald Knuth's work \\cite{ref:knuth79}.\n\nNote that most scholars create a database of references for the work they cite often. For this they use software called Bib\\TeX. We will say no more about this.  \n\n\\begin{thebibliography}{XX}\n\n\\bibitem{ref:knuth79} %when we refer to it by name we use this name. \nDonald Knuth, \\textbf{The \\TeX book} Addison Wesley, New York, 1979. \n\n\\bibitem{ref:lamport69}\nLeslie Lamport, \\textbf{The \\LaTeX\\ Book}, Addison Wesley, New York, 1969. \n\\end{thebibliography}\n\n\\section{Programming}\n\n\\newcommand{\\wsu}{Washington State University}\n\nWe can let \\TeX\\ do a lot of our work for us. For example, if there is some text that appears very often in our \npaper, we can define our own macro to make that text. \nWe can use \\texttt{newcommand} to create a new command that\nwill save us a bunch of time. \n\n\\newcommand{\\tc}[1]{\\textbackslash\\texttt{#1}}\n\nSometimes we need to define commands that operate on some argument. For example we have needed to typeset the \\TeX\\ commands we were talking about, but we were too lazy to type all the stuff every time. Above we defined a \\TeX\\ command called \\tc{tc} that does all that for us. This way we can talk about any command we like, such as \\tc{numberwithin}, and get the output while only having to type the argument. Here is another. \n\n\\newcommand{\\ltx}[2]{L\\raisebox{#1}{a}\\raisebox{#2}{}$\\chi$} \n\nThis one makes a \\LaTeX\\ command that raises the a as much as we want: viz. \\ltx{2pt}{-2pt}.\n\nThere is also a \\tc{newenvironment} command that defines an environment that way we want it. \n\n\\section{Odds 'n ends}\n\n\\begin{enumerate}\n\\item We have seen that tilde is a special character. It is actually a non-breaking space. The hyphenation program is not allowed to hyphenate there. \n\\item If you need to give \\TeX\\ a hint about where a convenient place to hyphenate is, you cna use the \\textbackslash- command. \n\\item The \\texttt{verbatim} environment allows us to typeset text obeying all spaces, line breaks and so on. This is used particularly in typesetting computer code. \n\\end{enumerate}\n\n\\begin{verbatim}\nfunction f(x)\nf = 5 \nreturn f\n\\end{verbatim}\n\n\n\\end{document}", "meta": {"hexsha": "9ac17928a1abeadb33b2019bfc8918d44ed14681", "size": 14786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math300/sept21.tex", "max_stars_repo_name": "johnnydevriese/wsu_courses", "max_stars_repo_head_hexsha": "b55efd501c2d8f0651891f422a486e32533f5aa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math300/sept21.tex", "max_issues_repo_name": "johnnydevriese/wsu_courses", "max_issues_repo_head_hexsha": "b55efd501c2d8f0651891f422a486e32533f5aa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math300/sept21.tex", "max_forks_repo_name": "johnnydevriese/wsu_courses", "max_forks_repo_head_hexsha": "b55efd501c2d8f0651891f422a486e32533f5aa0", "max_forks_repo_licenses": ["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.5337078652, "max_line_length": 429, "alphanum_fraction": 0.7473961856, "num_tokens": 4062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.6402676301623184}}
{"text": "%---------------------------Aspect Ratio----------------------------------\n\\section{Aspect Ratio\\label{s:tet-aspect-ratio}}\n\nThe aspect ratio of a tetrahedron $K$ is: \n\\[\n\\frac{L_{\\max}}{2\\sqrt{6}r}.\n\\]\n\n\\tetmetrictable{aspect ratio}%\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{frey:00}}%        Citation\n{v\\_tet\\_aspect\\_ratio}%                            Verdict function name\n", "meta": {"hexsha": "44602b32e6c714d3a25fcf21a1ed54db38b04b55", "size": 530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectRatio.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/TetAspectRatio.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/TetAspectRatio.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": 31.1764705882, "max_line_length": 74, "alphanum_fraction": 0.479245283, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6402676199774812}}
{"text": "\\section{Generalization of Wright-Fisher model dynamics to non-fixed population size where the population size fluctuates randomly}\n\\subsection{Motivation}\nTodo: Describe motivation - maybe add few sentences to motivate the research\n\\subsection{Results}\nLet me introduce the specific model with three main assumptions:\n\\begin{enumerate}\n\\item\nnon-fixed population size,\n\\item\nnon-overlapping generations,\n\\item\nrandom selection.\n\\end{enumerate}\nThe model is inspired directly by Wright-Fisher model without a fixed population size assumption, hence it can be considered as a generalization of the latter. Random selection feature corresponds to random mating assumption in Wright-Fisher model and means that in order to form a new generation each individual copies the state of a randomly selected parent, so no a priori defined fitness plays role except for the obvious rule that the rich gets richer.\nIt is difficult to observe non-overlapping generations in the nature, however this assumption plays a crucial role in the model so cannot be relaxed. One can think of a model without this limitation but deriving analytics results will be more challenging in such a setup. On the other hand the model should be not more difficult than it has to be and it might be that after appropriate scaling this feature has none or little effect on the quantitative output however may influence the qualitative outcome.\nFurther necessary assumptions are:\n\\begin{enumerate}\n\\item\nStart with fixed number of $n_0$ individuals - each possess a different opinion\n\\item\nExpected population of each generation stays positive i.e. \n\\begin{equation}\n\\mathbb{E}(\\sum_{i=1}X_t(i))>0\n\\end{equation}\n\\item \nPopulation of each generation is independent:\n\\begin{equation}\nn_t\\equiv\\sum_{i=1}X_t(i)\n\\end{equation}\n\\end{enumerate}\n\nIn terms of graph theory language we start with a fixed setup - initial generation $0$ consists of $n_0$ nodes. Each node $x_i$ has a different colour $i$. Every successive generation $t$ consists of $n_t$ nodes. Each node inherits a colour of its parent - a uniformly selected node from the generation $t-1$. \nNow one initial node $i$ (from generation $0$) is selected and a following martingale is considered \n\\begin{equation}\n\\{Y_t(i)=\\frac{X_t(i)}{n_t}\\}_{t\\geq0}\n\\end{equation}\nwhere $X_t(i)$ is a number of offsprings of node $i$ in generation $t$. For a given fixed $T>0$ we consider a following stopping time:\n\\begin{equation}\n\\tau=\\begin{cases} t_0 &\\qquad \\mbox{ if } X_{t_0}(i)=0 \\mbox{ for some time } t_0 \\leq T \\mbox{ (process dies until T) }\\\\ T &\\qquad \\mbox{ if } X_{T}(i)>0\\end{cases}\n\\end{equation}\nNext by applying Optional Stopping Theorem for martingale we have:\n\\begin{equation}\n\\mathbb{E}(Y_{\\tau}(i))=\\frac{1}{n_0}=\\mbox{Pr}\\{Y_T(i)>0\\}\\cdot\\mathbb{E}(Y_{T}(i) | X_{T}(i)>0)\n\\end{equation}\n$Pr\\{Y_T(i)>0\\}$ is a probability that the process will not die until time $T$. Hence, the number of colours at time $T$ is given by the formula:\n\\begin{equation}\n\\mathbb{E}(\\mbox{\\# colours at time } T)=\\frac{1}{\\mathbb{E}(Y_T(i) | X_T(i) >0)}\n\\end{equation}\n\nIn order to go further let’s switch a perspective.\nThe model can be alternatively viewed as a (possibly infinite) series of urns (non-overlapping generations) where the content of each urn (population of the generation) depends only on the content of the previous urn and the capacity of the current urn. Zeroth urn is filled with $n_0$ different balls. Then the process of populating the $t$-th urn is constrained with $n_t$ drawings with replacement from the previous $t-1$-th urn filled with $n_{t-1}$ labelled balls where each ball has exactly single label and some labels could be sticked to many balls. Thus multiplicity of labels/colours/languages can be approximated using mixed Poisson distribution in the following way:\n\nMultiplicity of colours to observe in first generation $X_1$ is a discrete random variable which can be approximated by poisson distribution with $\\lambda_1=\\frac{n_1}{n_0}$, so $Pr\\{X_1(i)=0\\}=\\exp(-\\lambda_1)$ meaning that expected number of $\\exp(-\\frac{n_1}{n_0})$ colours will disappear from the system at the first time step.\nIn general multiplicity of colurs in the first urn is fully described by the Poisson distribution:\n\\begin{equation}\nP(X_1(i)=k)=\\mbox{exp}(-\\lambda_1)\\frac{\\lambda_1^k}{k!}\n\\end{equation}\nLet’s proceed to the content of the next urn. We start from stating an exact formula for conditional probability of $X_2(i)$ under condition that we know the value of $X_1(i)$ (i.e. multiplicity of $i$-th colour in the first urn is known apriori):\n\\begin{equation}\nP\\left(X_2(i)=l|X_1(i)=k\\right)=\\mbox{exp}\\left(-k\\lambda_2\\right)\\frac{\\left(k\\lambda_2\\right)^l}{l!}\n\\end{equation}\nwhere $\\lambda_i\\equiv\\frac{n_i}{n_{i-1}}$ is a factor which corresponds to scaling of the population in the $i$-th step. The above formula is well defined only for $X_1(i)>0$. Let’s further assume that $P(X_t(i)=0|X_{t-1}(i)=0)\\equiv1$ (so if a colour/a label is lost at some point, then it cannot be pushed back in the system in the future). Now we can calculate unconditional probability of $X_2(i)$ using the law of total probability:\n\\begin{equation*}\n\\begin{split}\nP\\left(X_2(i)=l\\right) & =\\sum_{k}P\\left(X_2(i)=l|X_1(i)=k\\right)P\\left(X_1(i)=k\\right) \\\\ & =\\sum_{k=1}\\mbox{exp}\\left(-k\\lambda_2\\right)\\frac{\\left(k\\lambda_2\\right)^l}{l!}\\mbox{exp}\\left(-\\lambda_1\\right)\\frac{\\left(\\lambda_1\\right)^k}{k!} + \\delta_{l0}\\cdot\\mbox{exp}\\left(-\\lambda_1\\right)\n\\end{split}\n\\end{equation*}\n\nThis can be simplified by observing a fact that under the sum we have a sum of probability mass function of another Poisson distribution (except for mass of point $0$ and normalization factor). The computation is lengthy but straightforward and will be given in details only for $X_2(i)$ as further time steps involves the same method:\n\\begin{equation*}\n\\begin{split}\nP\\left(X_2(i)=0\\right) & =\\sum_{k}P\\left(X_2(i)=0|X_1(i)=k\\right)P\\left(X_1(i)=k\\right) \\\\ & =\\sum_{k=1}\\mbox{exp}\\left(-k\\lambda_2\\right)\\mbox{exp}\\left(-\\lambda_1\\right)\\frac{\\left(\\lambda_1\\right)^k}{k!} + \\mbox{exp}\\left(-\\lambda_1\\right) \\\\ &\n=\\mbox{exp}\\left(-\\lambda_1\\right)\\left(\\sum_{k=1}\\frac{\\left(\\lambda_1\\mbox{exp}\\left(-\\lambda_2\\right)\\right)^k}{k!} + 1 \\right) \\\\ &\n=\\mbox{exp}\\left(-\\lambda_1\\right)\\left(\\left(1-\\mbox{exp}\n\\left(-\\lambda_1\\mbox{exp}\\left(-\\lambda_2\\right)\\right)\\right)\\mbox{exp}\\left(\\lambda_1\n\\mbox{exp}\\left(-\\lambda_2\\right)\\right)+1\\right)\n\\end{split}\n\\end{equation*}\n\nFinally, the calculation above gives the elegant exact formula for probability of extinction until $t=2$:\n\\begin{equation}\nP(X_2(i)=0)=\\mbox{exp}\\left(-\\lambda_1\\left(1-\\mbox{exp}\\left(-\\lambda_2\\right)\\right)\\right)\n\\end{equation}\nTODO: Now the missing part - please compute explicit the value of $P(X_2(i)=l>0)$.\nWithout that computation, all remaining results are not valid.\nPlease check \\url{https://en.wikipedia.org/wiki/Poisson_distribution#Higher_moments} for further reference.\n\n\nIn fact the following exact formula is valid for any $t>1$:\n\\begin{equation}\nP(X_t(i)=0)=\\mbox{exp}\\left(- \\lambda_1 \\left(\\cdots\\left(1-\\mbox{exp}\\left(- \\lambda_{t-1}\\left(1 - \\mbox{exp}\\left(-\\lambda_{n_t}\\right)\\right)\\right)\\right)\\cdots\\right)\\right)\n\\end{equation}\n\nProof of this formula is based on induction and very useful property explained above on the recurrent use of sum of probability mass function except mass point $0$ - that for any $a$, $b$ and $\\left(x_k\\right)_{k\\in \\mathbb{N}}$ being a collection of positive iterators, we have: \n\\begin{equation}\n\\sum_{x_k=1}\\exp(a)^{x_k}\\frac{(x_{k-1}b)^{x_k}}{x_k!}=\n\\exp(x_{k-1}b\\exp(a))-1\n\\end{equation}\n\n\\begin{equation*}\n\\begin{split}\nP\\left(X_{t}(i)=0\\right) & =\\sum_{x_{t-1}}P\\left(X_{t}(i)=0|X_{t-1}(i)=x_{t-1}\\right)P\\left(X_{t-1}(i)=x_{t-1}\\right) \\\\ & \n=\\sum_{x_{t-1}}P\\left(X_{t}(i)=0|X_{t-1}(i)=x_{t-1}\\right)\\cdots \\sum_{x_{1}}P\\left(X_{2}(i)=x_{2}|X_{1}(i)=x_{1}\\right)P\\left(X_{1}(i)=x_1\\right)\n\\end{split}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{split}\n& P\\left(X_{t}(i)=0\\right) \\\\ & = \\sum_{x_{t-1}=1} \\exp(-\\lambda_{t})^{x_{t-1}}\n\\sum_{x_{t-2}=1} \\exp(- \\lambda_{t-1})^{x_{t-2}}\\frac{\\left(x_{t-2}\\lambda_{t-1}\\right)^{x_{t-1}}}{x_{t-1}!} \\cdots \\sum_{x_{1}=1} \\exp( - \\lambda_1)\\frac{\\lambda_1^{x_1}}{x_1!} + P\\left(X_{t-1}(i)=0\\right)\n\\end{split}\n\\end{equation*}\n\n", "meta": {"hexsha": "3e274441d954c26b28188cf669f6cf99ce88ed78", "size": 8325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/Analytic_WFExtended.tex", "max_stars_repo_name": "eMaerthin/agent-based-models-for-language-evolution-phd-thesis", "max_stars_repo_head_hexsha": "d61ad554f7a3bf5093aeffb5d83d56a8055ad9b8", "max_stars_repo_licenses": ["MIT"], "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/Analytic_WFExtended.tex", "max_issues_repo_name": "eMaerthin/agent-based-models-for-language-evolution-phd-thesis", "max_issues_repo_head_hexsha": "d61ad554f7a3bf5093aeffb5d83d56a8055ad9b8", "max_issues_repo_licenses": ["MIT"], "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/Analytic_WFExtended.tex", "max_forks_repo_name": "eMaerthin/agent-based-models-for-language-evolution-phd-thesis", "max_forks_repo_head_hexsha": "d61ad554f7a3bf5093aeffb5d83d56a8055ad9b8", "max_forks_repo_licenses": ["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.0263157895, "max_line_length": 678, "alphanum_fraction": 0.732972973, "num_tokens": 2668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6402676177188048}}
{"text": "\\chapter{Deep Learning and Large Scale Computing}\n\\section{Deep Learning and Large Scale Computing}\n\t\\subsection{What is a learning algorithm?}\n\t\t\n\t\tA \\textbf{machine learning algorithm} is an algorithm that is able to learn form data. But\twhat do we mean by learning? Mitchell (1997) provides the definition \"A computer program is said to learn from experience $E$\twith respect to some class of tasks\t$T$\tand performance measure\t$P$, if its performance at tasks in\t$T$, as measured by $P$, improves with experience $E$.\"Learning is not the task, but the means of attaining the ability to perform the task. The result of the learning is a model that is used to perform tasks.\n\t\t\n\t\tThe machine learning algorithm grew out of work in \\textbf{Artificial Intelligence (AI)} and take advantage of new capability of computing resources. \\textbf{Deep learning} is a subset of machine learning.\n\n\t\\subsection{Types of learning algorithm}\n\t\t\n\t\t Machine learning algorithms can be broadly categorized as \\textbf{unsupervised} or \\textbf{supervised} or \\textbf{Reinforcement learning algorithms\n\t\t }\tby what kind of experience they are allowed to have during the learning process.\n\t\\begin{itemize}\t\t\n\t\t\\item Unsupervised learning algorithms learn from a dataset containing many features, then learn useful properties of the structure of this dataset. E.g. K-means clustering\t\n\t\t\\item Supervised learning algorithms learn from a dataset containing features, but each example is also associated with a label or target. E.g. classification , regression method to predict housing price\t\n\t\t\\item Reinforcement learning algorithms interact with an environment, so there is feedback loop between the learning system and its experience. But it's out of the scope of this note.\t\t\n\t\\end{itemize}\t\n\tHere we offer a simple example to illustrate the difference between the supervised and unsupervised learning algorithm.\n\t\n\t Suppose we have a set of points in $\\mathbb{R}^2: \\{(x_1,y_1),(x_2,y_2),\\dots,(x_n,y_n)\\}$.\n\t \\begin{itemize}\n\t \t\\item Ther's no more information about the points except their coordinates. We want to split them into several subsets (which is 'clustering') based on their coordinates. That's an unsupervised algorithm.\n\t \t\\item The points are painted red or blue. We want to learn from the data about the reason why the point is red or blue. If given a new point, we can label it as red or blue according the points before. That's an example of classification, which is one kind of supervised learning algorithm.\n\t \\end{itemize}\n\t\\section{Maximum Likelihood Estimation}\n\tAs the process of machine learning is to estimate a set of parameters $\\theta$ based on observations of examples X, \\textbf{maximum likelihood} is often considered the preferred estimator to use for machine learning.\n\t\n\t\\begin{itemize}\n\t\t\\item Consider a set of $m$ examples $\\mathbb X=\\{\\bm x^{(1)},...,\\bm x^{(m)}\\}$ drawn independently from the true but unknown data generating distribution $p_{data}(\\bm x)$.\n\t\t\\item Let $p_{model}(\\bm x;\\bm \\theta)$ be a parametric family of probability distributions over the same space indexed by $\\bm \\theta$.\n\t\t\\item The maximum likelihood estimator for $\\bm \\theta$ is then defined as\n\t\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\\bm \\theta_{ML} &= \\arg \\max_{\\bm \\theta}p_{model}(\\mathbb X;\\bm \\theta) \\\\\n\t\t&=\\arg \\max_{\\bm \\theta}\\prod_{\\bm x \\in \\mathbb X} p_{model}(\\bm x;\\bm \\theta)\\\\\n\t\t&=\\arg \\max_{\\bm \\theta}\\sum_{\\bm x \\in \\mathbb X} \\log p_{model}(\\bm x;\\bm \\theta)\\\\\n\t\t\\end{split}\n\t\t\\end{equation*}\n\t\\end{itemize}\n\n\t\\section{Input data}\n\tPreviously observed data in the experience can be split to three categories:\n\t\\begin{itemize}\n\t\t\\item Training data: used to train the model\n\t\t\\item Validation data: used to adjust the model\n\t\t\\item Test data: used to evaluate the generalization of the model\n\t\\end{itemize}\n\tTraining data and validation data are usually split from a large observed data set. The ratio between training data and validation data is commonly 4:1 or 9:1.\n\t\\subsection{Capacity and Performance}\t\n\n\tThe capacity of the learning algorithms can be underfitting, appropriate capacity and overfitting. Underfitting occurs when the model is not able to obtain a sufficiently low error value on the training set. Overfitting occurs when the gap between the training error and test error is too large.\n\t\n\tThe factors determining the performance of the machine learning algorithms are:\n\t\\begin{itemize}\n\t\t\\item Test error (final error of the generated model) The error is calculated by a cost function based on the test data set\n\t\t\\item The gap between training and validation error\n\t\\end{itemize}\n\tThe central challenge in machine learning is that we must perform well on new, previously unseen inputs, not just those on which our model was trained. So Machine learning algorithms indirectly minimize the test error. Regularization is the modification of machine learning algorithms to reduce validation error but not the training error in order to avoid overfitting.\n\t\n\\section{Neural Network}\nAccording to Maureen Caudill{\\color{red} LZ:???} neural network is a computing system made up of a number of simple, highly interconnected processing elements, which process information by their dynamic state response to external inputs.\n\n\n{\\bf Activation function}. In a neural network, an activation function of a node determines the output of that node for a given input. Inspired by biological neurons, an activation function basically works as a switch that can set the neuron on \"ON\" or \"OFF\".\n\nThe sigmoid function is a common choice for activation function. It is defined by\n\\begin{equation}\n\\sigma(t) = \\frac{1}{1+e^{-t}}.\n\\end{equation}\nThe sigmoid function is monotonically increasing over $\\mathbb{R}$ and is infinitely-differentiable. It has limit 0 and 1 as $t$ approaches $-\\infty$ and $+\\infty$, respectively.\n%The graph of $\\sigma(t)$ is shown in Figure \\ref{fsig}.\n\nA useful property of $\\sigma(t)$ is that its derivative can be expressed by the function itself.\n{\\color{red} LZ:Add graph of sigmoid}\n\\begin{lemma}\n\\label{lsig}\n$\\sigma'(t) = \\sigma(t)(1-\\sigma(t))$.\n\\end{lemma}\n\n\nBesides the sigmoid function, commonly used activation functions are:\n\n\\begin{enumerate}\n\\item\nBinary step function: $f(t) = \\mathbbm{1}_{t\\ge 0}$.\n\\item\nHyperbolic tangent function: $f(t) = \\tanh(t)=\\frac{2}{1+e^{2t}}-1$.\n\\item\nArctan function: $f(t) = \\tan^{-1}(t)$.\n\\item\nRectified linear unit (ReLU) $f(t) = \\max\\{0, t\\}$.\n\\end{enumerate}\n\nA \\textit{neural network} is a network model with non-linear unites on its hidden layers.\n\n\n\n\n{\\bf Hyper-parameters.} Most machine learning algorithms involve hyper-parameters which are variables set before actually optimizing the model's parameters. For a neural network, hyper-parameters include the depth of the network $d$, the width of each layer $n$, the regularization parameter $\\lambda$, the learning rate for gradient descent $r$, and the initial values for weight matrices $(\\bm{W_1}(0),...,\\bm{W_d}(0))$ and biases $(\\bm{b_1}(0),...,\\bm{b_d}(0))$. {\\color{red} LZ:???}There is no theorem stating how to choose the best hyper-parameters, we now choose them merely by experience and luck.\n\n\\section{Back Propagation}\n\n{\\bf Training a neural network model}. Suppose we have $m$ labeled training examples\n$$\\{(\\bm{x^1, y^1}),...,(\\bm{x^m, y^m})\\}.$$ Let $\\sigma_k$, $\\bm{W_k}$, $\\bm{b_k}$, be the activation function, weight matrix, bias vector, resp. for the $k_{th}$ hidden layer, $k=1,2,...,d-1$. Let $\\sigma_d$, $\\bm{W_d}$ and $\\bm{b_d}$ be the activation function, weight matrix and bias vector for the output layer. \n\nThe neural network model can be defined recursively as follows:\n\\begin{equation}\n\\label{enn}\n\\aligned\n\\bm{z_1}=&\\bm{W_1^Tx}+\\bm{b_1}\\\\\n\\bm{a_1}=&\\sigma_1(\\bm{z_1})\\\\\n\\bm{z_k}=&\\bm{W_k^T}\\bm{a_{k-1}}+\\bm{b_k}\\\\\n\\bm{a_k}=&\\sigma_k(\\bm{z_k}), k=2,...,d.\n\\endaligned\n\\end{equation}\nHere we use the convention $\\sigma(x_1,...,x_n) = (\\sigma(x_1),...,\\sigma(x_n))$ and call $\\bm{z_k}$ weighted input and $\\bm{a_k}$ weighted output hence $\\bm{a_d}(\\bm{x})$ is the output from the neural network given $\\bm{x}$ as the input data.\n\n{\\bf Cost function}.\nThe error of a neural network with respect to a sample $(\\bm{x^j, y^j})$ is defined by cost (loss) function. One way is to use the quadratic loss function\n\\begin{equation}\nL(\\bm{x^j, y^j}) =\\|\\bm{y^j} - \\bm{a_d}(\\bm{x^j})\\|^2+\\lambda \\sum_{i=1}^d ||\\bm{W_i}||_F^2,\n\\end{equation}\nwhere the second term is the regularization term to avoid overfitting and $\\lambda$ is the regularization parameter.{\\color{red} LZ: remove regularization?}\n\nAn alternative way is to use the cross-entropy loss function\n\\begin{equation}\nL(\\bm{x^j, y^j}) = -[\\bm{y^j} \\ln (\\bm{a_d}(\\bm{x^j}))+(1-\\bm{y^j}) \\ln (1-\\bm{a_d}(\\bm{x^j}))]+\\lambda \\sum_{i=1}^d ||\\bm{W_i}||_F^2,\n\\end{equation}\n{\\color{red} LZ: remove regularization?}\n\nThe goal of training a neural network model is to find parameters $(\\bm{W_1},...,\\bm{W_d},\\bm{b_1},..,\\bm{b_d})$ such that the total loss\n\\begin{equation}\n\\label{etotalloss}\nL_{total} = \\frac{1}{m} \\sum_{j=1}^m L(\\bm{x^j, y^j})\n\\end{equation}\nis as small as possible.\n\n{\\bf Back propagation}.\nThe parameters are adjusted using the following process called \\textit{back-propagation} w.r.t. $L_{total}$.\n\nThere is an intuition to introduce the error $\\delta_l^j$.\nSuppose there is a very small change $\\Delta z_l^j$ added to the weighted input to the $j_{th}$ neuron in the $l_{th}$ layer, after the forward propagation, the final cost function changes by $\\frac{\\partial}{\\partial \\bm{z_l^j}}L_{total} \\Delta z_l^j$. If the partial derivative $\\frac{\\partial}{\\partial \\bm{z_l^j}}L_{total}$ is large, we can choose $\\Delta z_l^j$ with the different sign to decrease the cost function. Otherwise if the partial derivative is near zero, it's difficult to change the cost function. Therefore we use $\\delta_l^j = \\frac{\\partial}{\\partial \\bm{z_l^j}}L_{total}$ to denote the error of the $j_{th}$ neuron in the $l_{th}$ layer.\nFirst  we compute the error in the last layer.\n{\\color{red}LZ: bold sigma}\n\n\\begin{equation}\n\\aligned\n\\bm{\\delta_d^j} =& \\frac{\\partial}{\\partial z_d^j}L_{total}\\\\\n=& \\sum_{k} \\frac{\\partial L_{total}}{\\partial a_k^j}\\frac{\\partial a_k^j}{\\partial z_d^j}\\\\\n=& \\frac{\\partial L_{total}}{\\partial a_d^j} \\sigma'(z_d^j),\\\\\n\\bm{\\delta_d} =& \\nabla_{a_d} L_{total}\\odot \\sigma'(z_d).\n\\endaligned\n\\end{equation}\nHere $\\odot$ is the Hadamard product meaning component-wise multiplication of two vectors. In the third equality results from that $a_d^k$ relies only on the weighted input $z_d^k$.\n\nThen we compute the error in the $l_{th}$ layer, $l=1,2,...,d-1$.\n\\begin{equation}\n\\aligned\n\\delta_l^j =& \\frac{\\partial}{\\partial {z_l^j}}L_{total}\\\\\n=& \\sum_{k} \\frac{\\partial L_{total}}{\\partial z_{l+1}^k}\\frac{\\partial z_{l+1}^k}{\\partial z_l^j}\\\\\n=& \\sum_{k} \\frac{\\partial z_{l+1}^k}{\\partial z_l^j} \\bm\\delta_{l+1}^k\\\\\n=& \\sum_{k} W_{l+1}^{kj} \\delta_{l+1}^k \\sigma'(z_l^j),\\\\\n\\bm{\\delta_l} =& ((W_{l+1})^T \\bm\\delta_{l+1} \\odot \\sigma'(z_l).\n\\endaligned\n\\end{equation}\n\n\nThe computation of $\\bm{\\delta^k}$ depends on the knowledge of $\\bm{\\delta^{k+1}}$, and here comes the name back-propagation. The gradient of the loss function with respect to each parameter can be computed as follows: for each $k=1,...,d$ we have\n\\begin{equation}\n\\label{ebpparam}\n\\aligned\n\\frac{\\partial}{\\partial W_l^{jk}}L_{total}\n=& \\sum_{i} \\frac{\\partial L_{total}}{\\partial z_l^i}\\frac{\\partial z_l^i}{\\partial W_l^{jk}}\\\\\n=& \\frac{\\partial L_{total}}{\\partial z_l^j}\\frac{\\partial z_l^j}{\\partial W_l^{jk}}\\\\\n=& \\delta_l^j a_{l-1}^k,\\\\\n\\frac{\\partial}{\\partial b_l^{j}}L_{total}\n=& \\sum_{i} \\frac{\\partial L_{total}}{\\partial z_l^i}\\frac{\\partial z_l^i}{\\partial b_l^{j}}\\\\\n=& \\frac{\\partial L_{total}}{\\partial z_l^j}\\frac{\\partial z_l^j}{\\partial b_l^{j}}\\\\\n=& \\delta_l^j.\n\\endaligned\n\\end{equation}\n{\\color{red}LZ: matrix form:\n\\begin{align*}\n    \\frac{\\partial L_{total}}{\\partial \\bm W_l} =& \\bm{\\delta_l}\\bm a_{l-1}\\\\\n    \\frac{\\partial L_{total}}{\\partial \\bm b_l} =& \\bm{\\delta_l}\n\\end{align*}}\n\nWith the gradients computed, we use the following update rule to adjust the parameters:\n\\begin{equation}\n\\label{ebpup}\n\\aligned\nW_l^{jk} =& W_l^{jk} - r\\frac{\\partial L_{total}}{\\partial W_l^{jk}}\\\\\nb_l^{j} =& b_l^{j} - r\\frac{\\partial L_{total}}{\\partial b_l^{j}},\n\\endaligned\n\\end{equation}\nwhere r is the learning rate, for $l=1,...,d$. The learning rate r and the regularization parameter $\\lambda$ are hyper parameters, we still don't know why and how to choose them.{\\color{red}LZ: $\\lambda$? overstatement?} Therefore we normally choose them by experience and manually parameter tuning to decide the optimal hyper parameters.\n\n\n", "meta": {"hexsha": "b6dca246759211380b069469e293901097b4e2d7", "size": 12688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DeepLearningandLargeScaleComputingJiLiu.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/DeepLearningandLargeScaleComputingJiLiu.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/DeepLearningandLargeScaleComputingJiLiu.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": 63.7587939698, "max_line_length": 659, "alphanum_fraction": 0.7239123581, "num_tokens": 3735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835493924954, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6402257372615309}}
{"text": "\\subsection{Rings}\\label{subsec:rings}\n\n\\begin{definition}\\label{def:ring}\n  A \\term{ring} is a \\hyperref[def:semiring]{semiring} with additive inverses. More precisely, this means that the additive monoid is a group.\n\n  As for semirings, rings can also be nonunital, with \\hyperref[def:semiring_ideal]{ring ideals} being the main example.\n\n  Rings have the following metamathematical properties:\n  \\begin{thmenum}\n    \\thmitem{def:ring/theory} We can construct a \\hyperref[def:first_order_theory]{first-order theory} for rings by adding a unary functional symbol \\( - \\) and the involution axiom \\eqref{eq:def:group/theory/inverse_axiom} to the \\hyperref[def:semiring/theory]{theory of semirings}.\n\n    \\thmitem{def:ring/homomorphism} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} between the rings \\( R \\) and \\( T \\) is a \\hyperref[def:semiring/homomorphism]{semiring homomorphism} \\( \\varphi: R \\to T \\) that additionally preserves additive inverses.\n\n    As shown in \\fullref{thm:group_homomorphism_single_condition}, this condition is not only redundant, but the structure of a ring rather than semiring also automatically implies that \\( \\varphi(0_R) = 0_S \\).\n\n    \\thmitem{def:ring/submodel} The set \\( A \\subseteq R \\) is a \\hyperref[thm:substructure_is_model]{submodel} of \\( R \\) if it is both a \\hyperref[def:semiring]{sub-semiring} of \\( R \\) and an additive submonoid of \\( R \\).\n\n    As a consequence of \\fullref{thm:positive_formulas_preserved_under_homomorphism}, the image of a ring homomorphism is a subring of its range.\n\n    \\thmitem{def:ring/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} ring is the \\hyperref[def:pointed_set/trivial]{trivial pointed set} \\( \\set{ 0 } \\).\n\n    \\thmitem{def:ring/commutative} If multiplication is commutative, we call the ring itself \\term{commutative}. Unless multiplication corresponds to function composition, most rings we will encounter will be commutative.\n\n    \\thmitem{def:ring/category} The corresponding \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} \\( \\ucat{Ring} \\) is \\hyperref[def:concrete_category]{concrete} over \\hyperref[def:monoid]{\\( \\ucat{SRing} \\)}. We denote the category of commutative rings by \\( \\cat{CRing} \\).\n\n    Unlike the category \\hyperref[def:group/category]{\\( \\cat{Grp} \\)} of groups, \\( \\cat{Ring} \\) is not as well-behaved. Nevertheless, kernels and quotients of rings are commonly established concepts.\n\n    The category of unital rings does not have a zero object, but the category of nonunital rings does, and we will sometimes consider nonunital ring homomorphisms between unital rings. That is, ring homomorphisms that may not preserve the multiplicative identity.\n\n    \\thmitem{def:ring/kernel} The \\term{kernel} of a ring homomorphism \\( \\varphi: R \\to T \\) is simply its \\hyperref[def:zero_locus]{zero locus} \\( \\varphi^{-1}(0_S) \\). This is precisely the kernel of the additive group in the sense of \\fullref{def:group/kernel}, and the \\hyperref[def:zero_morphisms/cokernel]{categorical kernel} in the category of nonunital rings.\n\n    Furthermore, \\( \\ker \\varphi \\) is an ideal of \\( R \\) because, if \\( x \\in \\ker \\varphi \\),\n    \\begin{equation*}\n      \\varphi(xy)\n      =\n      \\varphi(x) \\varphi(y)\n      =\n      0_S \\varphi(y)\n      =\n      0_S,\n    \\end{equation*}\n    and thus \\( xy \\in \\ker \\varphi \\).\n\n    Despite being categorical kernels only in the category of nonunital rings, the kernel is defined and used mainly for unital ring homomorphism.\n\n    \\thmitem{def:ring/quotient} The \\hyperref[def:zero_morphisms/cokernel]{categorical cokernel} of homomorphism \\( \\varphi: R \\to T \\) in the category of nonunital rings is, similarly to the case for groups in \\fullref{def:group/quotient}, a partition of \\( T \\) induced by the image of \\( \\varphi \\).\n\n    This is not merely the cokernel \\( T / \\img \\varphi \\) of the additive group, however. Multiplication induces an additional restriction on congruences: \\( x \\cong x' \\) and \\( y \\cong y' \\) together imply \\( x y \\cong x' y' \\). Hence, \\( [x][y] = [xy] \\).  Denote the coset \\( [0_S] \\) by \\( I \\). We have \\( I[x] = [0x] = I \\), therefore the cokernel inherits absorption from \\( T \\).\n\n    Additive subgroups of \\( T \\) that absorb multiplication are precisely the \\hyperref[def:semiring_ideal]{two-sided ideals} of \\( T \\). Hence, \\( I \\) is the ideal generated by \\( \\img \\varphi \\). From the general case for groups it follows that quotient ring cosets have the form \\( x + I \\).\n\n    Finally, given an ideal \\( I \\) of an arbitrary ring \\( R \\), we can define the \\term{quotient ring} \\( R / I \\) as the cokernel of the inclusion \\( \\iota: I \\to R \\). That is, \\( R / I \\) consists of the cosets \\( x + I \\) for \\( x \\in R \\). In practice, quotients are conveniently characterized by \\fullref{thm:quotient_algebra_universal_property}.\n\n    Somewhat similarly to \\fullref{thm:def:group/kernel_cokernel_compatibility} for groups, the kernel \\( \\ker \\pi \\) of the canonical projection \\( \\pi(x) \\coloneqq x + I \\) is the ideal \\( I \\) itself.\n\n    Despite being \\hyperref[def:zero_morphisms/cokernel]{categorical cokernel} only in the category of nonunital rings, the quotient \\( R / I \\) is defined and used mainly for unital rings.\n\n    Fortunately, for unital ring \\( R \\), the quotient \\( R / I \\) is also unital. The projection morphism is an epimorphism by \\fullref{thm:equalizer_invertibility}, and hence \\( R / I \\) is a \\hyperref[def:subobject_and_quotient]{categorical quotient object}.\n\n    \\thmitem{def:ring/simple} Analogously to \\hyperref[def:group/simple]{simple groups}, if the only proper \\hyperref[def:semiring_ideal]{ideal} of \\( R \\) is the \\hyperref[def:ring/trivial]{trivial ideal} \\( \\set{ 0_R } \\), we say that \\( R \\) is a \\term{simple ring}.\n\n    The trivial ring itself is not simple, because it has no proper ideals.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:quotient_equality_via_difference}\n  Given an \\hyperref[def:semiring_ideal]{ideal} \\( I \\) in a \\hyperref[def:ring]{ring} \\( R \\), we have \\( x + I = y + I \\) if and only if \\( x - y \\in I \\).\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ring_of_integers_modulo}\n  For a positive integer \\( n > 1 \\), we extend the group \\hyperref[thm:group_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n \\) with the operation\n  \\begin{equation*}\n    x \\odot y \\coloneqq \\rem(xy, n).\n  \\end{equation*}\n\n  Then \\( \\BbbZ_n \\) is a \\hyperref[def:ring/commutative]{commutative ring} called the \\term{ring of integers modulo} \\( n \\).\n\\end{proposition}\n\\begin{proof}\n  Note that\n  \\begin{balign*}\n    &\\phantom{{}\\cong{}} \\rem(x, n) \\rem(y, n)\n    &\\cong \\pmod n \\\\ &\\cong\n    (x - n \\quot(x, n)) (y - n \\quot(y, n))\n    &\\cong \\pmod n \\\\ &\\cong\n    xy - n \\quot(x, n) - n \\quot(y, n) + n^2 \\quot(x, n) \\quot(y, n)\n    &\\cong \\pmod n \\\\ &\\cong\n    xy.\n  \\end{balign*}\n\n  The proof that multiplication in \\( \\BbbZ_n \\) is associative, unital and commutative becomes trivial.\n\n  We will prove that multiplication distributes over addition. Fix \\( x, y, z \\in \\BbbZ_n \\). We have\n  \\begin{balign*}\n    (x \\oplus y) \\odot z\n     & =\n    \\rem((x \\oplus y) z, n)\n    =    \\\\ &=\n    \\rem(\\rem(x + y, n) z, n)\n    =    \\\\ &=\n    \\rem((x + y - n \\quot(x + y, n)) z, n)\n    =    \\\\ &=\n    \\rem((x + y)z, n).\n  \\end{balign*}\n  and\n  \\begin{balign*}\n    (x \\odot z) \\oplus (y \\odot z)\n     & =\n    \\rem([(x \\odot z) + (y \\odot z)], n)\n    =    \\\\ &=\n    \\rem([xz - n \\quot(xz, n) + yz - n \\quot(yz, n)], n)\n    =    \\\\ &=\n    \\rem(xz + yz, n)\n    =    \\\\ &=\n    \\rem((x + y)z, n).\n  \\end{balign*}\n\n  Hence,\n  \\begin{equation*}\n    (x \\oplus y) \\odot z = (x \\odot z) \\oplus (y \\odot z).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ring_characteristic_homomorphism}\n  Similarly to how \\( \\BbbN \\) is an \\hyperref[def:universal_objects/initial]{initial object} in the category \\hyperref[def:semiring/category]{\\( \\cat{SRing} \\)} of semirings, \\( \\BbbZ \\) is an initial object in the category \\hyperref[def:ring/category]{\\( \\cat{Ring} \\)} of rings.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:semiring_characteristic_homomorphism} with the addition of \\( (-n)x = -nx \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:ring_characteristic}\\mimprovised\n  We define the \\term{characteristic} \\( \\op{char}(R) \\) of a ring \\( R \\) via the following equivalent definitions:\n  \\begin{thmenum}\n    \\thmitem{def:ring_characteristic/embedding} \\( \\op{char}(R) \\) is the unique nonnegative integer \\( n \\) for which \\( \\BbbZ_n \\) can be embedded into \\( R \\). That is,\n    \\begin{equation*}\n      \\BbbZ_n \\cong \\BbbZ / \\ker \\iota,\n    \\end{equation*}\n    where \\( \\iota \\) is the homomorphism from the integers defined via \\eqref{eq:thm:ring_characteristic_homomorphism}.\n\n    We use here that \\( \\BbbZ_0 \\) is the \\hyperref[def:ring/trivial]{trivial ring}.\n\n    \\thmitem{def:ring_characteristic/direct} \\( \\op{char}(R) \\) is the \\hyperref[def:group_order]{order} of the additive group of \\( R \\) and, if it exists, and \\( 0 \\) otherwise.\n\n    That is, \\( \\op{char}(R) \\) is the smallest positive integer \\( n \\) such that \\( n \\cdot 1_R = 0_R \\) and \\( \\op{char}(R) = 0 \\) if \\( 0_R \\) cannot be obtained in this way.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  \\EquivalenceSubProof{def:ring_characteristic/homomorphism}{def:ring_characteristic/direct} Let \\( n \\) be such that\n  \\begin{equation*}\n    n \\BbbZ = \\ker\\iota.\n  \\end{equation*}\n\n  In particular, \\( \\iota(0) = \\iota(n) \\).\n\n  If \\( n = 0 \\), \\( \\ker\\iota \\) is a trivial group and \\( \\iota \\) is an embedding. Then there cannot exist a positive integer \\( n \\) such that\n  \\begin{equation*}\n    n \\cdot 1_R = 0_R.\n  \\end{equation*}\n\n  Otherwise, \\( n \\) is the smallest positive integer such that\n  \\begin{equation*}\n    n \\cdot 1_R = 0 \\cdot 1_R = 0_R.\n  \\end{equation*}\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:ring_embedding_preserves_characterstic}\n  If \\( \\varphi: R \\to S \\) is a \\hyperref[def:ring/homomorphism]{ring embedding}, then \\( S \\) inherits its \\hyperref[def:semiring_characteristic]{characteristics} from \\( R \\).\n\\end{proposition}\n\\begin{proof}\n  First suppose that \\( R \\) has positive characteristic \\( n \\). Then \\( n \\cdot 1_R = 0_R \\), which implies \\( n \\cdot \\varphi(1_R) = \\varphi(0_R) \\), hence \\( \\op{char}(T) \\leq n \\). But \\( \\varphi \\) is an embedding, hence if \\( k \\cdot 1_R \\neq 0_R \\), then\n  \\begin{equation*}\n    k \\cdot \\varphi(1_R) \\neq \\varphi(0_R).\n  \\end{equation*}\n\n  This implies that \\( \\op{char}(S) \\geq \\op{char}(R) \\), which in turn shows that \\( \\op{char}(S) = \\op{char}(R) \\).\n\n  If \\( R \\) has characteristic zero, then \\( \\iota: \\BbbN \\to R \\) is an embedding and thus \\( \\varphi \\bincirc \\iota: \\BbbN \\to S \\) is also an embedding. It is unique as shown in \\fullref{thm:ring_characteristic_homomorphism}. Therefore, \\( S \\) also has characteristic zero.\n\\end{proof}\n\n\\begin{example}\\label{ex:def:ring_characteristic}\n  The following are examples of \\hyperref[def:ring_characteristic]{ring characteristics}:\n  \\begin{thmenum}\n    \\thmitem{ex:def:ring_characteristic/natural_numbers} The \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) have characteristic \\( \\op{char}(\\BbbZ) = 0 \\) because \\( \\iota \\) is an isomorphism. Consequently, by \\fullref{thm:ring_embedding_preserves_characterstic}, any superring of \\( \\BbbZ \\) has characteristic zero, most notably the fields \\( \\BbbQ \\), \\( \\BbbR \\) and \\( \\BbbC \\).\n\n    \\thmitem{ex:def:ring_characteristic/integers_modulo} The ring \\hyperref[thm:ring_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n \\) has characteristic \\( \\op{char}(\\BbbZ_n) = n \\) because of \\fullref{thm:integers_modulo_isomorphic_to_quotient_group}.\n\n    \\thmitem{ex:def:ring_characteristic/polynomial_ring} An \\hyperref[def:algebra_over_semiring]{algebra} \\( M \\) over a nontrivial commutative unital ring \\( R \\) has the same characteristic as \\( R \\) because of the canonical embedding of \\( R \\) in \\( M \\). In particular, the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( R[X] \\) has the same characteristic as their ring.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:grothendieck_semiring_completion}\\mcite[80]{OpenLogicFull}\n  The \\hyperref[def:monoid_grothendieck_completion]{Grothendieck completion} \\( \\overline{R} \\) of the additive monoid of a \\hyperref[def:semiring]{semiring} \\( R \\) becomes a \\hyperref[def:ring]{ring} with the operation\n  \\begin{equation*}\n    [(a, b)] \\odot [(c, d)] \\coloneqq [(ac + bd, ad + bc)].\n  \\end{equation*}\n\n  This definition is motivated in the proof of \\fullref{thm:grothendieck_semiring_completion_universal_property}.\n\\end{proposition}\n\\begin{proof}\n  Multiplication on \\( R \\) does not depend on the representative of the equivalence class. Indeed, let \\( (a, b) \\sim (a', b') \\) and \\( (c, d) \\sim (c', d') \\). Then there exist \\( u \\) and \\( v \\) such that\n  \\begin{align*}\n    a + b' + u &= a' + b + u, \\\\\n    c + d' + v &= c' + d + v.\n  \\end{align*}\n\n  Then\n  \\begin{align*}\n    &\\phantom{{}={}}\n    \\hi{ac} + b'c + uc + a'd + \\hi{bd} + ud + a'c + \\hi{a'd'} + a'v + \\hi{b'c'} + b'd + b'v\n    = \\\\ &=\n    (a + b' + u)c + (a' + b + u)d + a'(c + d' + v) + b'(c' + d + v)\n    = \\\\ &=\n    (a' + b + u)c + (a + b' + u)d + a'(c' + d + v) + b'(c + d' + v)\n    = \\\\ &=\n    a'c + \\hi{bc} + uc + \\hi{ad} + b'd + ud + \\hi{a'c'} + a'd + a'v + b'c + \\hi{b'd'} + b'v.\n  \\end{align*}\n\n  Therefore,\n  \\begin{equation*}\n    (a \\cdot c + b \\cdot d, a \\cdot d + b \\cdot c) \\sim (a' \\cdot c' + b' \\cdot d', a' \\cdot d' + b' \\cdot c').\n  \\end{equation*}\n\n  Associativity and distributivity in \\( \\overline{R} \\) are inherited from \\( R \\).\n\\end{proof}\n\n\\begin{theorem}[Grothendieck semiring completion universal property]\\label{thm:grothendieck_semiring_completion_universal_property}\n  The \\hyperref[thm:grothendieck_semiring_completion]{Grothendieck completion} \\( \\overline{R} \\) of a semiring \\( R \\) satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every ring \\( T \\) and every semiring homomorphism \\( \\varphi: R \\to T \\), there exists a unique ring homomorphism \\( \\widetilde{\\varphi}: \\overline{R} \\to T \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:grothendieck_semiring_completion_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__semiring_grothendieck_completion_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  Via \\fullref{rem:universal_mapping_property}, \\( \\overline{\\anon} \\) becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{CRing} \\to \\cat{CSRing}.\n  \\end{equation*}\n\n  Compare this result to \\fullref{thm:grothendieck_monoid_completion_universal_property}.\n\\end{theorem}\n\\begin{proof}\n  \\Fullref{thm:grothendieck_monoid_completion_universal_property} suggests the definition\n  \\begin{equation*}\n    \\overline{\\varphi}([(a, b)]) \\coloneqq \\varphi(a) - \\varphi(b).\n  \\end{equation*}\n\n  We must only show that \\( \\overline{\\varphi} \\) is a ring homomorphism. Clearly\n  \\begin{equation*}\n    \\overline{\\varphi}([(1, 0)]) = \\varphi(1) - \\varphi(0),\n  \\end{equation*}\n  which implies that \\( \\varphi \\) preserves multiplicative identities. Also,\n  \\begin{balign*}\n    \\overline{\\varphi}\\parens[\\Big]{ [(a, b)] \\odot [(c, d)] }\n    &=\n    \\overline{\\varphi}\\parens[\\Big]{ [(a \\cdot b + c \\cdot d, a \\cdot d + b \\cdot c)] }\n    = \\\\ &=\n    \\varphi(a \\cdot b + c \\cdot d) - \\varphi(a \\cdot d + b \\cdot c)\n    = \\\\ &=\n    \\varphi(c) \\parens[\\Big]{ \\varphi(d) - \\varphi(b) } - \\varphi(a) \\parens[\\Big]{ \\varphi(d) - \\varphi(b) }\n    = \\\\ &=\n    \\parens[\\Big]{ \\varphi(c) - \\varphi(a) } \\parens[\\Big]{ \\varphi(d) - \\varphi(b) }\n    = \\\\ &=\n    \\overline{\\varphi}\\parens[\\Big]{ [(a, c)] } \\overline{\\varphi}\\parens[\\Big]{ [(b, d)] }.\n  \\end{balign*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:grothendieck_semiring_completion}\n  The \\hyperref[thm:grothendieck_semiring_completion]{Grothendieck completion} \\( \\overline{R} \\) of a semiring \\( R \\) satisfies the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:grothendieck_semiring_completion/commutative} If \\( R \\) is commutative, so is \\( \\overline{R} \\).\n    \\thmitem{thm:def:grothendieck_semiring_completion/entire} If \\( R \\) is \\hyperref[def:divisibility/zero]{entire}, so is \\( \\overline{R} \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:grothendieck_semiring_completion/commutative} This is clear from the definition of multiplication.\n  \\SubProofOf{thm:def:grothendieck_semiring_completion/entire} Suppose that\n  \\begin{equation*}\n    \\underbrace{[(a, b)] \\cdot [(c, d)]}_{[(ac + bd, ad + bc)]} = [(0, 0)]\n  \\end{equation*}\n\n  Then there exists an element \\( u \\) in \\( R \\) such that\n  \\begin{equation*}\n    (ac + bd) + 0 + u = 0 + (ad + bc) + u.\n  \\end{equation*}\n\n  Suppose that \\( d = c + e \\). Then\n  \\begin{equation*}\n    ac + b(c + e) = a(c + e) + bc\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    (ac + bc) + be = (ac + bc) + ae.\n  \\end{equation*}\n\n  Cancelling \\( e \\), we obtain that \\( a = b \\). But \\( [(a, b)] = [(0, 0)] \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:ring_commutator}\n  Let \\( R \\) be an arbitrary ring. We define the \\term{commutator} of the elements \\( x \\) and \\( y \\) as\n  \\begin{equation*}\n    [x, y] \\coloneqq xy - yx.\n  \\end{equation*}\n\n  The \\term{commutator ideal} \\( [R, R] \\) of \\( R \\) is the two-sided ideal \\hyperref[def:generated_ring_ideal]{generated} by all the commutators in \\( G \\).\n\\end{definition}\n\n\\begin{theorem}[Ring abelianization universal property]\\label{thm:ring_abelianization_universal_property}\\mcite[prop. 7.4]{Knapp2016BasicAlgebra}\n  The quotient \\( R / [R, R] \\) of a ring \\( R \\) by its commutator ideal \\( [R, R] \\) is a commutative ring, which we call the \\term{abelianization} of \\( R \\), and satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every commutative ring \\( T \\) and every ring homomorphism \\( \\varphi: R \\to T \\), \\( \\varphi \\) \\hyperref[def:factors_through]{uniquely factors through} \\( R / [R, R] \\). That is, there exists a unique ring homomorphism \\( \\widetilde{\\varphi}: R / [R, R] \\to T \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:ring_abelianization_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__ring_abelianization_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  Via \\fullref{rem:universal_mapping_property}, the abelianization functor becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{CRing} \\to \\cat{Ring}.\n  \\end{equation*}\n\n  Compare this result to \\fullref{thm:group_abelianization_universal_property}.\n\\end{theorem}\n\\begin{proof}\n  This is a refinement of \\fullref{thm:group_abelianization_universal_property}, and we only need to show that \\( R / [R, R] \\) is a commutative ring. For \\( x \\) and \\( y \\) in \\( R \\), since \\( yx - xy \\in I \\), we have\n  \\begin{equation*}\n    (x + I) (y + I)\n    =\n    (xy + I)\n    =\n    (xy + yx - xy + I)\n    =\n    (yx + I)\n    =\n    (y + I) (x + I).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:multiplicative_set_in_semiring}\\mcite[428]{Knapp2016BasicAlgebra}\n  We call the subset of the semiring \\( R \\) a \\term{multiplicative set} if it contains \\( 1_R \\) and, furthermore, it is closed under multiplication.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:complement_of_prime_ideal}\n  The \\hyperref[def:semiring_ideal]{ideal} \\( P \\) in the \\hyperref[def:semiring/commutative]{commutative semiring} \\( R \\) is \\hyperref[def:semiring_ideal/prime]{prime} if and only if \\( R \\setminus P \\) is a \\hyperref[def:multiplicative_set_in_semiring]{multiplicative set}.\n\n  Not all multiplicative sets are obtained as complements of prime ideals --- see \\fullref{ex:def:ring_localization/powers_of_two}.\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:def:semiring_ideal/ideal_containing_unit}, \\( P \\) is a proper ideal if and only if \\( 1_R \\in R \\setminus P \\).\n\n  By \\fullref{thm:def:semiring_ideal/prime_pointwise}, \\( P \\) is prime if and only if \\( x, y \\in R \\setminus P \\) implies \\( xy \\in R \\setminus P \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:ring_localization}\\mcite[428]{Knapp2016BasicAlgebra}\n  Let \\( R \\) be a \\hyperref[def:ring/commutative]{commutative ring} and let \\( S \\subseteq R \\) be a \\hyperref[def:multiplicative_set_in_semiring]{multiplicative set}.\n\n  Define the equivalence relation \\( (r, s) \\sim (r', s') \\) on \\( R \\times S \\) to hold if and only if there exists some \\( u \\in S \\) such that \\( u r s' = u r' s \\).\n\n  Consider the set\n  \\begin{equation*}\n    S^{-1} R \\coloneqq R \\times S / \\sim,\n  \\end{equation*}\n  whose cosets we will denote by \\( \\ifrac r s \\) rather than \\( [(r, s)] \\).\n\n  Define on \\( S^{-1} R \\) the operations\n  \\begin{align*}\n    \\frac a b + \\frac c d     &\\coloneqq \\frac {a d + b c} {b d}, \\\\\n    \\frac a b \\cdot \\frac c d &\\coloneqq \\frac {a c} {b d},\n  \\end{align*}\n  and the canonical inclusion\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\iota: R \\to S^{-1} R \\\\\n      &\\iota(r) \\coloneqq \\frac r {1_R}.\n    \\end{aligned}\n  \\end{equation*}\n\n  This ring is called the \\term{localization} of \\( R \\) with respect to \\( A \\); we denote it by \\( S^{-1} R \\). In case \\( S \\) is the \\hyperref[thm:boolean_algebra_of_subsets/complement]{complement} of a \\hyperref[def:semiring_ideal/prime]{prime ideal}, we may denote the localization by \\( R_P \\) (or \\( R_p \\) if \\( P = \\braket{ p } \\)).\n\n  The image under \\( \\iota \\) of every element \\( s \\) of \\( S \\) is invertible in \\( S^{-1} R \\), and we call the inverse \\( \\ifrac {1_R} s \\) the \\term{reciprocal} of \\( s \\).\n\n  This construction is very similar to the \\hyperref[def:monoid_grothendieck_completion]{Grothendieck completion} of a monoid or semiring, although with notable differences --- the set \\( S \\) may be a strict subset of \\( R \\), and addition in the Grothendieck completion corresponds to multiplication in the localization, while addition in the completion has no analogy.\n\\end{definition}\n\\begin{defproof}\n  The proof that \\( {\\sim} \\) is an equivalence relation is the same as in \\fullref{def:monoid_grothendieck_completion}. The result is then a ring if the operations are well-defined.\n\n  We will show that both operations are well-defined. Let \\( u ab' = u a'b \\), meaning that \\( (a, b) \\sim (a', b') \\) and hence \\( \\ifrac a b = \\ifrac {a'} {b'} \\), and let \\( v cd' = v c'd \\).\n\n  For addition, we have\n  \\begin{align*}\n    u v (ad + bc) b' d'\n    &=\n    v dd' (u ab') + u bb' (v cd')\n    = \\\\ &=\n    v dd' (u a'b) + u bb' (v c'd)\n    = \\\\ &=\n    u v (a'd' + b'c') b d,\n  \\end{align*}\n  hence \\( (ad + bc, bd) \\sim (a'd' + b'c', b'd') \\).\n\n  The proof for correctness of multiplication is the same as the proof of correctness of addition in \\fullref{def:monoid_grothendieck_completion}.\n\\end{defproof}\n\n\\begin{theorem}[Ring localization universal property]\\label{thm:ring_localization_universal_property}\\mcite[431]{Knapp2016BasicAlgebra}\n  The \\hyperref[def:ring_localization]{localization} of \\( R \\) by \\( S \\) satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every commutative ring \\( T \\) and every ring homomorphism \\( \\varphi: R \\to T \\) such that \\( \\varphi(s) \\) is invertible in \\( T \\) for every \\( s \\in S \\), \\( \\varphi \\) \\hyperref[def:factors_through]{uniquely factors through} \\( S^{-1} R \\). That is, there exists a unique ring homomorphism \\( \\widetilde{\\varphi}: S^{-1} R \\to T \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:ring_localization_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__ring_localization_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\\end{theorem}\n\\begin{proof}\n  The condition suggests the definition\n  \\begin{equation*}\n    \\widetilde{\\varphi}\\parens*{ \\frac r s } \\coloneqq \\varphi(r) \\varphi(s)^{-1}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:def:ring_localization}\n  We list several examples of \\hyperref[def:ring/commutative]{commutative ring} \\hyperref[def:ring_localization]{localization}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:ring_localization/zero} If \\( S \\) contains \\( 0_R \\), then \\( S^{-1} R \\) is the trivial ring.\n\n    \\thmitem{ex:def:ring_localization/powers_of_two} The localization \\( S^{-1} \\BbbZ \\) by the set \\( S \\coloneqq \\set{ 2^n \\given n \\geq 0 } \\) is (a ring isomorphic to) the rational numbers with denominators that are powers of two. This is an example of a multiplicative set that is not the complement of a prime ideal.\n\n    This ring is isomorphic to the ring \\( \\BbbZ[\\ifrac 1 2] \\) obtained by \\hyperref[thm:adjoining_elements_to_semiring]{adjoining} the rational number \\( \\ifrac 1 2 \\) to \\( \\BbbZ \\).\n\n    \\thmitem{ex:def:ring_localization/prime_number} Let \\( p \\) be a \\hyperref[def:prime_number]{prime number}. The localization \\( S^{-1} \\BbbZ \\) by \\( S \\coloneqq \\BbbZ \\setminus \\braket{ p } \\) is (a ring isomorphic to) the rational numbers with denominators coprime to \\( p \\).\n\n    For \\( p = 2 \\), this localization consists of rational numbers whose denominator is an odd number.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:ring_localization}\n  \\hyperref[def:ring_localization]{Ring localization} has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:ring_localization/image_of_ideal}\\mcite[432]{Knapp2016BasicAlgebra} Localization preserves \\hyperref[def:semiring_ideal]{ideals}. More precisely, given a commutative ring \\( R \\), a multiplicative set \\( S \\) and an ideal \\( I \\), the set\n    \\begin{equation*}\n      S^{-1} I \\coloneqq \\set*{ \\frac r s \\given* r \\in I \\T{and} s \\in S }\n    \\end{equation*}\n    is an ideal of the localization \\( S^{-1} R \\).\n\n    \\thmitem{thm:def:ring_localization/prime_ideals}\\mcite[exer. 4.3]{КоцевСидеров2016} The map \\( I \\mapsto S^{-1} I \\) is a \\hyperref[def:partially_ordered_set/homomorphism]{strict order isomorphism} between the set of \\hyperref[def:ring/submodel]{prime ideals} of \\( R \\) not intersecting \\( S \\) and the set of all prime ideals of \\( S^{-1} R \\).\n\n    \\thmitem{thm:def:ring_localization/by_prime_ideal}\\mcite[exer. 4.2a)]{КоцевСидеров2016} The localization \\( R_P \\) by a \\hyperref[def:semiring_ideal/prime]{prime ideal} \\( P \\) has a unique maximal ideal \\( S^{-1} P \\) (here \\( S \\coloneqq R \\setminus P \\)).\n\n    \\thmitem{thm:def:ring_localization/injective_inclusion} The canonical inclusion \\( \\iota: R \\to S^{-1} R \\) is injective if and only if \\( S \\) contains no zero divisors.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:ring_localization/image_of_ideal} Trivial since \\( S \\) is closed under multiplication.\n\n  \\SubProofOf{thm:def:ring_localization/prime_ideals} Let \\( P \\) be a prime ideal in \\( R \\) disjoint from \\( S \\). By \\fullref{thm:def:ring_localization/image_of_ideal}, \\( S^{-1} P \\) is an ideal of \\( S^{-1} R \\). If the product \\( \\ifrac {ac} {bd} \\) belong to \\( S^{-1} P \\), then \\( ac \\in P \\) and \\( bd \\in S \\). Since \\( P \\) is prime, \\( a \\in P \\) or \\( c \\in P \\). If \\( a \\in P \\), then \\( ba \\in P \\) and \\( \\ifrac a d = \\ifrac {ba} {bd} \\in S^{-1} P \\); if \\( c \\in P \\), we proceed analogously. Thus, \\( S^{-1} P \\) is a prime ideal, i.e. the image under \\( I \\mapsto S^{-1} I \\) of a prime ideal is a prime ideal.\n\n  \\SubProofOf[def:function_invertibility/injective/equality]{injectivity} Let \\( S^{-1} P = S^{-1} Q \\) for prime ideals \\( P \\) and \\( Q \\) disjoint from \\( S \\). Suppose that \\( P \\setminus Q \\) contains at least one element, say \\( p \\). Then \\( \\iota(p) = \\ifrac p 1 \\) belongs to both \\( S^{-1} P \\) and \\( S^{-1} Q \\); hence, \\( Q \\) contains an element \\( q \\) such that, for some \\( s \\in S \\) and \\( u \\in S \\),\n  \\begin{equation*}\n    p \\cdot s \\cdot u = 1 \\cdot q \\cdot u.\n  \\end{equation*}\n\n  Since \\( Q \\) is an ideal, \\( qu \\in Q \\), and hence \\( psu \\in Q \\). But neither \\( p \\), \\( s \\) nor \\( u \\) belong to \\( Q \\), which contradicts the assumption that \\( Q \\) is prime. Therefore, \\( P \\setminus Q \\) is empty. Generalizing, we obtain that \\( I \\mapsto S^{-1} I \\) is injective on prime ideals.\n\n  \\SubProofOf[def:function_invertibility/surjective/existence]{surjectivity} Fix a prime ideal \\( T \\) in \\( S^{-1} R \\) and let \\( P \\) be the set of numerators in \\( T \\), i.e. if \\( \\ifrac p s \\in T \\), then \\( p \\in P \\). We will show that \\( P \\) is a prime ideal; clearly \\( T = S^{-1} P \\).\n\n  Clearly \\( 0_R \\in P \\). Let \\( a, c \\in P \\). Then there exist \\( b, d \\in S \\) such that \\( \\ifrac a b \\) and \\( \\ifrac c d \\) belong to \\( T \\). But \\( T \\) is closed under multiplication with members of \\( R \\), hence \\( \\ifrac a {1_R} = b (\\ifrac a b) \\) and \\( \\ifrac c {1_R} = d (\\ifrac c d) \\) also belong to \\( T \\). Then their sum \\( \\ifrac {(a + c)} 1 \\) belongs to \\( T \\), and hence also to \\( P \\). Thus, \\( P \\) is closed under addition. We analogously obtain that it is closed under multiplication.\n\n  We have shown that \\( P \\) is an ideal in \\( R \\). We must show that it is a prime ideal. Let \\( ac \\in P \\). Then\n  \\begin{equation*}\n    \\frac a b \\cdot \\frac c d \\in T\n  \\end{equation*}\n  for some \\( b, d \\in S \\). Hence, \\( \\ifrac a b \\) or \\( \\ifrac c d \\) belongs to \\( T \\), implying that \\( a \\in P \\) or \\( c \\in P \\).\n\n  \\SubProofOf[def:partially_ordered_set/homomorphism]{monotonicity} Follows from \\fullref{thm:order_embedding_is_strict}.\n\n  \\SubProofOf{thm:def:ring_localization/by_prime_ideal} In the localization \\( R_P \\) be a prime ideal, all members of \\( P \\) become invertible. Hence, a maximal ideal cannot contain members of \\( P \\). By \\fullref{thm:def:ring_localization/image_of_ideal}, \\( S^{-1} P \\) is an ideal, therefore it must be the largest proper ideal.\n\n  \\SubProofOf{thm:def:ring_localization/injective_inclusion} Let \\( sr = 0 \\) for \\( s \\in S \\). Then \\( \\iota(s) = \\ifrac s {1_R} \\) is invertible in \\( S^{-1} R \\) and hence\n  \\begin{equation*}\n    \\frac {0_R} {1_R}\n    =\n    \\frac {sr} {1_R}\n    =\n    \\frac {1_R} s \\cdot \\frac {sr} {1_R}\n    =\n    \\frac r {1_R}.\n  \\end{equation*}\n\n  Hence, \\( \\iota(r) = \\iota(0_R) \\).\n\n  It follows that \\( \\iota \\) is injective if and only if \\( S \\) contains no zero divisors.\n\\end{proof}\n\n\\begin{definition}\\label{def:division_ring}\\mcite[144]{Knapp2016BasicAlgebra}\n  If every nonzero element of a ring is \\hyperref[def:divisibility/unit]{invertible}, we call it a \\term{division ring}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:division_ring_is_entire}\n  A nontrivial \\hyperref[def:division_ring]{division ring} is \\hyperref[def:entire_semiring]{entire}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( xy = 0 \\). If \\( x \\) is nonzero, multiplying both sides by \\( x^{-1} \\), we obtain \\( y = 0 \\). Analogously, \\( y \\neq 0 \\) implies that \\( x = 0 \\). In all cases, either \\( x \\) or \\( y \\) is necessarily zero.\n\n  Therefore, the ring has no nontrivial zero divisors.\n\\end{proof}\n\n\\begin{definition}\\label{def:field}\n  We will call the \\hyperref[def:ring/trivial]{nontrivial} \\hyperref[def:ring]{ring} \\( \\BbbK \\) a \\term{field} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:field/simple} \\( \\BbbK \\) is \\hyperref[def:ring/commutative]{commutative} and \\hyperref[def:ring/simple]{simple}.\n    \\thmitem{def:field/division_ring} \\( \\BbbK \\) is a \\hyperref[def:ring/commutative]{commutative} \\hyperref[def:division_ring]{division ring}.\n  \\end{thmenum}\n\n  Fields have the following metamathematical properties:\n  \\begin{thmenum}\n    \\thmitem{def:field/theory} We can construct a \\hyperref[def:first_order_theory]{first-order theory} for fields by adding to the \\hyperref[def:semiring/theory]{theory of rings} the axioms \\( \\neg (0 \\doteq 1) \\) and\n    \\begin{equation}\\label{eq:def:field/theory/invertibility}\n      (\\xi \\doteq 0) \\vee \\qexists \\eta (\\xi \\cdot \\eta \\doteq 1).\n    \\end{equation}\n\n    These axioms are not \\hyperref[def:positive_formula]{positive formulas}, hence fields automatically get worse metamathematical properties than rings, for example.\n\n    \\thmitem{def:field/homomorphism}\\mcite[453]{Knapp2016BasicAlgebra} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} between fields is simply a \\hyperref[def:ring/homomorphism]{unital ring homomorphism}.\n\n    \\thmitem{def:field/submodel} If for two fields \\( \\Bbbk \\) and \\( \\BbbK \\) are have \\( \\Bbbk \\subseteq \\BbbK \\), we say that \\( \\BbbK \\) is a \\term{field extension} of \\( \\Bbbk \\) and that \\( \\Bbbk \\) is a \\term{subfield} of \\( \\BbbK \\). In particular, if \\( \\BbbK = \\Bbbk \\), we say that the extension is trivial.\n\n    \\thmitem{def:field/category} The category of \\hyperref[def:large_and_small_sets]{\\( \\mscrU \\)-small} fields \\( \\ucat{Field} \\) is a full subcategory of \\hyperref[def:ring/category]{\\( \\ucat{CRing} \\)} with objects restricted to fields.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  The equivalence of definitions follows from \\fullref{thm:def:semiring_ideal/units}.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:field_of_fractions}\n  Let \\( D \\) be an \\hyperref[def:integral_domain]{integral domain}. The \\hyperref[def:ring_localization]{localization} of \\( D \\) at the zero ideal \\( \\set{ 0_R } \\) is a \\hyperref[def:field]{field}, which we call the \\term{field of fractions} of \\( D \\).\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:def:ring_localization/prime_ideal}, the localization by the prime ideal \\( \\set{ 0_R } \\) has  whose only maximal ideal is \\( S^{-1} \\set{ 0_R } \\). Since \\( 0_R \\) is absorbing, \\( S^{-1} \\set{ 0_R } \\) is again the zero ideal.  Therefore, it is the only proper ideal of the localization \\( S^{-1} D \\), and hence the localization is a \\hyperref[def:ring/simple]{simple ring}.\n\n  Since \\( D \\) is an integral domain, by \\fullref{thm:def:ring_localization/injective_inclusion}, \\( S^{-1} D \\) is a superring of \\( D \\). It is therefore a nontrivial commutative simple ring, and thus it satisfies \\fullref{def:field/simple}.\n\\end{proof}\n\n\\begin{theorem}[Field of fractions universal property]\\label{thm:field_of_fractions_universal_property}\n  The \\hyperref[def:field_of_fractions]{field of fractions} \\( \\BbbK \\) of the integral domain \\( D \\) satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every field \\( \\BbbL \\) and every ring homomorphism \\( \\varphi: D \\to \\BbbL \\), \\( \\varphi \\) \\hyperref[def:factors_through]{uniquely factors through} \\( \\BbbK \\). That is, there exists a unique field homomorphism \\( \\widetilde{\\varphi}: \\BbbK \\to \\BbbL \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:field_of_fractions_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__field_of_fractions_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\\end{theorem}\n\\begin{proof}\n  This is simply a special case of \\fullref{thm:ring_localization_universal_property}.\n\\end{proof}\n\n\\begin{definition}\\label{def:rational_function_field}\n  The field of \\term{rational algebraic functions} \\( D(\\mscrX) \\) for the set of indeterminates \\( \\mscrX \\) over the \\hyperref[def:integral_domain]{integral domain} \\( D \\) is the \\hyperref[thm:field_of_fractions]{field of fractions} of the \\hyperref[def:polynomial_algebra]{polynomial ring} \\( D[\\mscrX] \\).\n\n  Despite the name, elements of the field of fractions are not actually functions, but merely formal expressions. In particular, an analog of \\fullref{thm:polynomial_algebra_universal_property} does not really make sense.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:adjoining_elements_to_field}\n  Let \\( \\Bbbk \\subseteq \\BbbK \\) be \\hyperref[def:field]{fields} and let \\( A \\) be an arbitrary subset of \\( \\BbbK \\).\n\n  Let \\( \\Bbbk[A] \\) be the ring obtained by adjoining the elements of \\( A \\) to \\( \\Bbbk \\) as described in \\fullref{thm:adjoining_elements_to_semiring}. The \\hyperref[def:field_of_fractions]{field of fractions} of \\( \\Bbbk[A] \\) is the smallest field extension of \\( \\Bbbk \\) containing \\( A \\).\n\n  We denote this extension by \\( \\Bbbk(A) \\). It should not be confused with the image of the evaluation homomorphism on the \\hyperref[def:rational_function_field]{field of rational functions}; the rational functions do not actually have an evaluation homomorphism.\n\\end{proposition}\n\\begin{proof}\n  It follows from \\fullref{thm:adjoining_elements_to_semiring} that \\( \\Bbbk[A] \\) is the smallest superring of \\( \\Bbbk \\) containing \\( A \\). By \\fullref{thm:field_of_fractions_universal_property}, \\( \\Bbbk(A) \\) is the smallest field containing \\( \\Bbbk[A] \\).\n\\end{proof}\n", "meta": {"hexsha": "c7aa70bfecb68a9d9e11f95187d299ca523cac65", "size": 37240, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/rings.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/rings.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/rings.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": 63.8765008576, "max_line_length": 631, "alphanum_fraction": 0.6757518797, "num_tokens": 12200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6402257341225217}}
{"text": "\\documentclass[a4paper]{article}\n\n\\def\\npart{IB}\n\n\\def\\ntitle{Optimisation}\n\\def\\nlecturer{M.\\ Tehranchi}\n\n\\def\\nterm{Easter}\n\\def\\nyear{2017}\n\n\\input{header}\n\n\\begin{document}\n\n\\input{titlepage}\n\n\\tableofcontents\n\n\\section{Introduction}\n\nThe typical problem is of the form\n\n\\begin{center}\n  minimise $f(x)$ subject to $g(x) = b,\\: x \\in X$,\n\\end{center}\n\nwhere\n\n\\begin{itemize}\n\\item $f : \\mathbb{R}^n → \\mathbb{R}$ is the \\emph{objective function},\n\\item $X \\subseteq \\mathbb{R}^n$ defines a \\emph{regional constraint},\n\\item $g: \\mathbb{R}^n → \\mathbb{R}^m$ defines $m$ \\emph{functional constraints},\n\\item $b \\in \\mathbb{R}^m$ is the \\emph{right-hand side}.\n\\end{itemize}\n\nWe will also use the terminology\n\n\\begin{itemize}\n\\item a \\emph{feasible solution} is any $x \\in X$ s.t. $g(x) = b$,\n\\item an \\emph{optimal solution} is a feasible solution $x^*$ s.t. $f(x^*) ≤ f(x)$ for all feasible $x$.\n\n\\end{itemize}\n\nA problem with inequality constraints can be put into equality form by introducing \\emph{slack variables}:\n\n\\begin{center}\n  minimise $f(x)$ subject to $g(x) ≤ b,\\: x \\in X$\n\n  minmise $f(x)$ subject to $g(x) + z = b,\\: x \\in X$.\n\\end{center}\n\n\\section{Lagrangian Methods}\n\nConsider the problem\n\n\\begin{center}\n  minimise $f(x)$ subject to $g(x) = b,\\: x \\in X$.\n\\end{center}\n\nIntroduce a new function $L : \\mathbb{R}^n × \\mathbb{R}^m → \\mathbb{R},\\: L(x, \\lambda) = f(x) + \\lambda^T (b - g(x))$, the \\emph{Lagrangian} of the problem. The components $\\lambda_i$ is called the \\emph{Lagrangian multiplier} for the $i$-th functional constraint.\n\n\\subsection{Lagrangian Sufficiency}\n\n\\begin{theorem}[Lagrangian Sufficiency Theorem]\n  Let $x^*$ be feasible. Suppose there exists $\\lambda^* \\in \\mathbb{R}^m$ s.t.\n  \\[\n    L(x^*, \\lambda^*) ≤ L(x, \\lambda^*) \\: \\text{for all } x \\in X\n  \\]\n\n  then $x^*$ is optimal.\n\n\\end{theorem}\n\n\\begin{proof}\n  For any feasible $x$ and any $\\lambda$ we have\n  \\[\n    L(x, \\lambda) = f(x) + \\lambda^T (b - g(x)) = f(x)\n  \\]\n\n  so\n  \\begin{align*}\n    f(x^*) &= L(x^*, \\lambda^*) \\\\\n           &≤ L(x, \\lambda^*) \\: \\text{for all} x \\in X \\: \\text{by assumption } \\\\\n           &= f(x) \\: \\text{for all feasible } x \\in X\n  \\end{align*}\n\\end{proof}\n\n\\subsection{Steps}\n\nConsider the problem to\n\n\\begin{center}\n  minimise $f(x)$ subject to $g(x) = b,\\: x \\in X$\n\\end{center}\n\n\\begin{itemize}\n\\item[Step 1] $\\Lambda := \\{\\displaystyle \\lambda \\in \\mathbb{R}^n: \\inf_{x \\in X} L(x, \\lambda) > -∞\\}$\n\\item[Step 2] For each $\\lambda \\in \\Lambda$ find the optimal solution to the unconstrained problem\n\n\\begin{center}\n  minimise $L(x, \\lambda)$ subject to $x \\in X$\n\\end{center}\n\nLet $x(\\lambda)$ be the minimiser\n\\item[Step 3] Find a $\\lambda^* \\in \\Lambda$ s.t. $x^* = x(\\lambda^*)$ is feasible for the original problem, i.e. $g(x^*) = b$.\n\\end{itemize}\n\nNote that $x^*$ is optimal by Lagrangian sufficiency theorem.\n\n\\subsection{Complementary Slackness}\n\nGiven an inequality constraint, we introduce the equivalent equality constraint problem with slack variables. The Lagrangian is now\n\\[\n  L(x, z, \\lambda) = f(x) + \\lambda^T (b - g(x)) - \\lambda^T z\n\\]\n\nNote that for the infimum to exist, $\\lambda ≤ 0$. The inequality constraint $g(x) ≤ b $ for the variable $x$ introduces a \\emph{sign constraint} $\\lambda ≤ 0$ for the Lagrange multiplier $\\lambda$.\n\nIn addition, for $\\lambda ≤ 0$ we have $\\displaystyle \\inf_{z ≥ 0} (-\\lambda^T z) = 0$. Thus for each $\\lambda \\in \\Lambda$, the optimal $z = z(\\lambda)$ satisfis the \\emph{compementary slacknes} condition $\\lambda^T z = 0$. Hence $\\lambda_i z_i = 0$ for all $i$.\n\n\\subsection{Lagrangian Necessity}\n\nNote that for any Lagrange multiplier $\\lambda$ we have\n\n\\begin{align*}\n  \\inf_{x \\in X,\\: g(x) = b} f(x) &= \\inf_{x \\in X,\\: g(x) = b} (f(x) + \\lambda^T (b - g(x))) \\\\\n                                &= \\inf_{x \\in X,\\: g(x) = b} L(x, \\lambda) \\\\\n                                &≥ \\inf_{x \\in X} L(x, \\lambda)\n\\end{align*}\n\nsince $\\{x \\in X: g(x) = b\\} ⊆ X$. We say the Lagrangian method works if there exists a Lagrange multiplier $\\lambda^*$ s.t. there is an equality. To characterise when the Lagrangian method works, we need to define some terms.\n\n\\begin{definition}\n  $\\psi: \\mathbb{R}^m → \\mathbb{R}$ has a \\emph{supporting hyperplane} at a point $b \\in \\mathbb{R}^m$ if there exist a $\\lambda$ s.t.\n  \\[\n    \\psi(c) ≥ \\psi(b) + \\lambda^T (c-b)\n  \\]\n  for all $c \\in \\mathbb{R}^m$.\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{value function} $φ$ on $\\mathbb{R}^n$ is defined by $\\displaystyle\\phi(c) = \\inf_{x \\in X,\\: g(x) = c} f(x)$.\n\\end{definition}\n\n\\begin{theorem}[Lagrangian Necessity Theorem]\n  The Lagrangian method works for the problem iff the value function has a supporting hyperplane at $b$.\n\\end{theorem}\n\n\\begin{proof}\n  The Lagrangian method works iff there exists a $\\lambda$ s.t.\n  \\[\n   \\phi(b) = \\inf_{x \\in X} (f(x) + \\lambda^T (b - g(x)))\n  \\]\n\n  The value function has a supporting hyperplane at $b$ iff there exists a $\\lambda$ s.t.\n  \\[\n   \\phi(b) = \\inf_{c \\in \\mathbb{R}^m} (\\phi(c) + \\lambda^T (b - c))\n  \\]\n\n  Thus the equivalence of the two hypotheses is proven by noting the equality\n  \\begin{align*}\n    \\inf_{x \\in X} (f(x) + \\lambda^T (b - g(x))) &= \\inf_{c \\in \\mathbb{R}^m} \\underbrace{\\inf_{x \\in X,\\: g(x) = c} (f(x)}_{\\phi(c)} + \\lambda^T \\underbrace{(c - g(x))}_{= 0} + \\lambda^T (b - c)) \\\\\n                                         &= \\inf_{c \\in \\mathbb{R}^m} (\\phi(c) + \\lambda^T (b - c))\n  \\end{align*}\n\\end{proof}\n\nTo check whether a function has a supporting hyperplane, we have to define a few terms.\n\n\\begin{definition}\n  A subset $C \\subseteq \\mathbb{R}^n$ is \\emph{convex} if\n  \\[\n    x, y \\in C \\: \\text{implies } \\theta x + (1 - \\theta)y \\in C \\: \\text{for all } 0 \\subseteq \\theta \\subseteq 1.\n  \\]\n\\end{definition}\n\n\\begin{definition}\n  A function $\\psi: \\mathbb{R}^m \\rightarrow \\mathbb{R}^m$ is \\emph{convex} if\n  \\[\n    \\psi(\\theta x + (1 - \\theta) y \\leq \\theta\\psi(x) + (1-\\theta) \\psi(y) \\: \\text{for all } x, y \\in \\mathbb{R}^m \\: \\text{and } 0 \\leq \\theta \\leq 1.\n  \\]\n\\end{definition}\n\n\\begin{corollary}\n  A fucntion $\\psi : \\mathbb{R}^m \\rightarrow \\mathbb{R}$ is convex iff the set\n  \\[\n    C := \\{(x, y) : \\psi(x) \\leq y \\} \\subseteq \\mathbb{R}^{m + 1}\n  \\]\n  is convex\\footnote{The set $C$ defined above is call the \\emph{epigraph} of $\\psi$.}.\n\\end{corollary}\n\n\\begin{theorem}[Non-examinable]\n  A function is convex iff it has a supporting hyperplane at each point.\n\\end{theorem}\n\n\\begin{proposition}\n  If\n  \\begin{enumerate}\n  \\item the set $X$ is convex,\n  \\item the objective function $f$ is convex, and\n  \\item the functional constraint is\n    \\begin{itemize}\n    \\item either $g(x) = b$ and $g$ is linear, or\n    \\item $g(x) \\leq b$ and $g$ is convex.\n    \\end{itemize}\n  \\end{enumerate}\n\n  then $\\psi$ is convex.\n\\end{proposition}\n\n\\section{Dual Problem}\n\nConsider the \\emph{primal} problem\n\n\\begin{center}\n  $P:$ minimise $f(x)$ subject to $g(x) = b,\\: x \\in X$.\n\\end{center}\n\nAs before, introduce the Lagrangian $L$ and the set of Lagrange multipliers $\\Lambda$. Now define the \\emph{dual objective function} $h: \\Lambda \\rightarrow \\mathbb{R}$ by\n\\[\n  h(\\lambda) = \\inf_{x \\in X} L(x, \\lambda).\n\\]\n\nThe \\emph{dual} problem is defined to be\n\n\\begin{center}\n  $D:$ maximise $h(\\lambda)$ subject to $\\lambda \\in \\Lambda$.\n\\end{center}\n\nThe set $\\Lambda$ is the set of \\emph{feasible solutions to the dual problem}.\n\n\\begin{theorem}[Weak Duality]\n  Let $x$ be feasible for $P$ and let $\\lambda$ be feasible for $D$. Then\n  \\[\n    h(\\lambda) \\leq f(x)\n  \\]\n\n  and in particular\n  \\[\n    \\sup_{\\lambda \\in \\Lambda} \\leq \\inf_{x \\in X,\\: g(x) = b} f(x).\n  \\]\n\\end{theorem}\n\n\\begin{proof}\n  Let $x$ and $f$ be feasible for their respective problems, then\n  \\begin{align*}\n    h(\\lambda) &= \\inf\\{L(x', \\lambda): x' \\in X \\} \\\\\n               &\\leq L(x, \\lambda) \\: \\text{for all } x \\in X \\\\\n               &= f(x) \\: \\text{for all feasible } x\n  \\end{align*}\n\\end{proof}\n\nThe difference\n\\[\n  \\inf_{x \\in X,\\: g(x) = b} f(x) - \\sup_{\\lambda \\in \\Lambda} h(\\lambda)\n\\]\n\nis called the \\emph{duality gap}. Weak duality says that the duality gap is non-negative while in the case where the conditions of Lagrangian necessity are met, the duality gap is zero. This is called strong duality.\n\n\\begin{eg}[Linear Programming]\n  Consider the primal problem\n  \\begin{center}\n    $P:$ maximise $c^T x$ subject to $Ax \\leq b,\\: x \\geq 0$\n  \\end{center}\n  where $A$ is a $m \\times n$ matrix, $b \\in \\mathbb{R}^m$, and $c \\in \\mathbb{R}^n$.\n\n  The dual problem is found as follows:\n  \\begin{enumerate}\n  \\item Introduce slack variables\n    \\begin{center}\n      $P:$ maximise $c^T x$ subject to $Ax + z = b, \\: x \\geq 0, \\: z \\geq 0$\n    \\end{center}\n  \\item The Lagrangian is\n    \\[\n      L(x, z, \\lambda) = b^T \\lambda + (c - A^T \\lambda)^T x - \\lambda ^T z.\n    \\]\n  \\item The set of feasible solutions to the dual problem is\n    \\begin{align*}\n      \\Lambda &= \\{\\lambda \\in \\mathbb{R}^m: \\sup_{x \\geq 0,\\: z \\geq 0} L(x, z, \\lambda) < \\infty \\} \\\\\n              &= \\{\\lambda \\in \\mathbb{R}^m: A^T \\lambda \\geq c,\\: \\lambda \\geq 0\\}.\n    \\end{align*}\n  \\item The dual objective funtion\n    \\[\n      \\sup_{x \\geq 0, z \\geq 0} L(x, z, \\lambda) = b^T \\lambda \\: \\text{for } \\lambda \\in \\Lambda.\n    \\]\n\n    The dual problem is then\n\n    \\begin{center}\n      $D:$ minimise $b^T \\lambda$ subject to $A^T \\lambda \\geq c,\\: \\lambda \\geq 0$.\n    \\end{center}\n  \\end{enumerate}\n\\end{eg}\n\nWe can verify that the dual of the dual is the original problem.\n\n\\begin{theorem}[Fundamental Theorem of Linear Programming]\n  Consider the problem\n  \n  \\begin{center}\n    $P:$ maximise $c^T x$ subject to $Ax \\leq b,\\: x \\geq 0$.\n  \\end{center}\n  \n  A vector $x^* \\in \\mathbb{R}^n$ is optimal for $P$ iff there exists a vector $\\lambda^* \\in \\mathbb{R}^m$ s.t.\n\n  \\begin{itemize}\n  \\item $A x^* \\leq b,\\: x^* \\geq 0$ \\: (primal feasibility)\n  \\item $A^T \\lambda^* \\geq c,\\: \\lambda^* \\geq 0$ \\: (dual feasibility)\n  \\item $(\\lambda^*)^T (b - A x^*) = 0 = (x^*)^T (c - A^T \\lambda ^*)$ \\: (complementary slackness)\n  \\end{itemize}\n\\end{theorem}\n\nIn this case, the value of the primal problem $c^T x^* = b^T \\lambda^*$ equals the value of the dual problem.\n\n\\subsection{Extreme Points and Basic Feasible Solutions}\n\nSuppose $\\psi$ is a convex function, then give $x, y \\in X$ and $0 \\leq \\theta \\leq 1$,\n\n\\begin{align*}\n  \\psi(\\theta x + (1 - \\theta) y) & \\leq \\theta \\psi(x) + (1 - \\theta)\\psi(y) \\\\\n                                  &\\leq \\max\\{\\psi(x), \\psi(y)\\}\n\\end{align*}\n\nThat is to say the maximimum of $\\psi$ on any segment occurs at one of the end points. Thus to find the maximum of $\\psi$ over $X$ we over have to consider points of $X$ that do not lie on a line segment contained in $X$.\n\n\\begin{definition}\n  Let $C \\subseteq \\mathbb{R}^n$ be a convex set. A point $x \\in C$ is an \\emph{extreme point} if\n\n  \\[\n    x = \\theta y + (1 - \\theta) z\n  \\]\n  for $y, z \\in X$ and $0 \\leq \\theta \\leq 1$ imples $x = y = z$.\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{standard form} of a linear programme is\n\n  \\begin{center}\n    maximise $c^T x$ subject to $Ax = b,\\: x\\geq 0$\n  \\end{center}\n  where $c \\in \\mathbb{R}^n,\\: b \\in \\mathbb{R}^m$ and $A$ is a $m \\times n$ matrix. The set $C := \\{x \\in \\mathbb{R}^n: Ax = b\\}$ is the set of feasible solutions to the problem.\n\\end{definition}\n\n\\begin{proposition}\n  The set $C$ is convex.\n\\end{proposition}\n\n\\begin{proof}\n  Suppose $x, y \\in C$. Then $Ax = b,\\: x \\geq 0$, and $Ay = b,\\: y \\geq 0$. Fix $\\theta \\in [0, 1]$ and let $z = \\theta x + (1 - \\theta)y$. Then\n\n  \\begin{align*}\n    Az &= \\theta Ax + (1 - \\theta) Ay = b \\\\\n    z_i &= \\theta x_i + (1 - \\theta) y_i \\geq 0 \\: \\text{for all } i\n  \\end{align*}\n\n  Hence $z \\in C$.\n\\end{proof}\n\nA solution $x \\in \\mathbb{R}^n$ of the equation $Ax = b$ is called \\emph{basic} if at least $n - m$ entries of $x$ are zero. If $x$ is a basic solution and $x \\geq 0$ then $x$ is called a \\emph{basic feasible solution}, abbreviated \\emph{b.f.s}.\n\n\\begin{theorem}\n  Let $x$ be a point in $C$ with the property that have at least $m+1$ indices $i$ s.t. $x_i>0$. Then $x$ is not a extreme point of $C$.\n\\end{theorem}\n\n\\begin{proof}\n  \\texttt{to be filled in}\n\\end{proof}\n\n\\begin{theorem}\n  Suppose that every set of $m$ columns of $A$ is linearly independent. Let $x$ be a point in $C$ with the property that at most $m$ indices $i$ are s.t. $z_i>0$. Then $x$ is an extreme point of $C$.\n\\end{theorem}\n\n\\begin{proof}\n  \\texttt{to be filled in}\n\\end{proof}\n\n\\subsection{Simplex Algorithm}\n\nWe assume $A$ is a $m\\times n$ matrix and $n > m$ and that every set of $m$ columns of $A$ is linearly independent. From discussion above it suffices to consider the extreme points of $C$. Fix $B \\subset \\{1, \\ldots ,n\\}$ with $|B|=m$, and let $N=\\{1,\\ldots, n\\} \\setminus B$. If $B=\\{i_1,\\ldots,i_m\\}$, let $A_B=(A_{i_1}\\:\\ldots\\:A_{i_m})$ bethe $m\\times m$ matrix formed by takning the colums of $A$ indexed by $i \\in B$. By assumption $A_B$ is invertible. Define $x_B$ and $c_B$ similarly. Similar for the set $N$.\n\nUsing this notation, the equation is\n\\[\n  A_B x_B + A_N x_N = b\n\\]\n\nSetting $x_N=0$ yields $x_B=A_B^{-1}b$ so by rearranging the coordinates we may write the basic point as $x=\\binom{x_B}{x_N}\\binom{A_B^{-1}b}{0}$. To check this $x$ is feasible, we need $A_B^{-1}b \\geq 0$. If it is, compute the objective function $c^Tx=c_B^Tx_B$.\n\nTo check the optimality, we use the fundamental theorem. For the b.f.s. $x=\\binom{A_B^{-1}b}{0}$, we associate to it a Lagrange multiplier $\\lambda$ by complementary slackness\n\n\\begin{align*}\n  0 &= (c - A^T\\lambda)^Tx \\\\\n    &= (c_B - A_B^T\\lambda)^Tx_B\n\\end{align*}\n\nAssuming \\emph{non-degeneracy}, we take $\\lambda=(A_B^T)^{-1}c_B$. By construction $x$ satisfies primal feasibility and $\\lambda$ satisfies complementary slackness. Thus $x$ is optimal iff $\\lambda$ satisfies dual feasibility. Thus if $A^T\\lambda\\geq c$ then we know we have found an optimal solution.\n\n\\section{Two-person Zero-sum Game}\n\nSuppose Player I and Player II are competing. I has $m$ choices of strategies, labelled $i \\in \\{1,\\ldots,m\\}$ while II has $n$, labelled $j \\in \\{1,\\ldots,n\\}$. Zero-sum means that if I chooses strategy $i$ and II chooses strategy $j$ then\n\n\\begin{itemize}\n\\item I is paid $a_{i,j}$\n\\item II is paid $-a_{i,j}$\n\\end{itemize}\n\nSo the net payment is zero. The matrix $A=(a_{i,j})_{i,j}$ is called the \\emph{payoff} matrix of the game\n\\end{document}\n", "meta": {"hexsha": "960cd5ad3f1ba3ec1770fac6e34c50cfb0be547d", "size": 14449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "IB/optimisation.tex", "max_stars_repo_name": "geniusKuang/tripos", "max_stars_repo_head_hexsha": "127e9fccea5732677ef237213d73a98fdb8d0ca0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2018-01-15T05:02:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T15:48:31.000Z", "max_issues_repo_path": "IB/optimisation.tex", "max_issues_repo_name": "b-mehta/tripos", "max_issues_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-11T20:43:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T21:29:15.000Z", "max_forks_repo_path": "IB/optimisation.tex", "max_forks_repo_name": "b-mehta/tripos", "max_forks_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2017-11-08T16:16:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T17:20:19.000Z", "avg_line_length": 35.5012285012, "max_line_length": 517, "alphanum_fraction": 0.6264101322, "num_tokens": 5173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6402257218158316}}
{"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\n\\begin{document}\n\n\\section{Vectors}\n\\subsection{Rules}\n\\begin{enumerate}\n\\item\nThe angle between vectors $\\mathbf{a}$ and $\\mathbf{b}$ is the angle one should rotate vector $\\mathbf{a}$ to align it with $\\mathbf{b}$.\nThen:\n\\begin{enumerate}\n\\item \t\n$\\angle (\\mathbf{a},\\mathbf{b}) = - \\angle (\\mathbf{b},\\mathbf{a})$\n\\item \n$\\angle (\\mathbf{a},\\mathbf{b}) + \\angle (\\mathbf{b},\\mathbf{c}) = \\angle (\\mathbf{a},\\mathbf{c})$\n\\item\n$\\angle (\\mathbf{a},\\mathbf{b}) = \\angle (\\mathbf{-a},\\mathbf{b}) - 180 ^\\circ$\n\\end{enumerate}\n\n\\item \nThe dot product (also inner product or scalar product) of vectors $\\mathbf{a}$ and $\\mathbf{b}$ is: \\\\\n$$\\mathbf{a} \\cdot \\mathbf{b} \\equiv (\\mathbf{a},\\mathbf{b}) = \\abs{\\mathbf{a}} \\abs{\\mathbf{b}} \\cos \\angle (\\mathbf{a},\\mathbf{b}) $$\nThen:\n\\begin{enumerate}\n\\item \n$\\mathbf{a} \\cdot \\mathbf{b} = \\mathbf{b} \\cdot \\mathbf{a}$\n\\item \n$\\abs{\\mathbf{a} \\cdot \\mathbf{b}} \\leq  \\abs{\\mathbf{a}} \\abs{\\mathbf{b}} $ \n\\item\n$(\\lambda \\mathbf{a} + \\mu \\mathbf{b}) \\cdot \\mathbf{c} = \\lambda \\mathbf{a} \\cdot \\mathbf{c} + \\mu \\mathbf{b} \\cdot \\mathbf{c}$\n\\item \nIf $\\abs{\\mathbf{a}},\\abs{\\mathbf{b}} \\ne 0$,then $\\mathbf{a} \\cdot \\mathbf{b}=0$ if and only if when $\\mathbf{a} \\perp \\mathbf{b}$.\n\\end{enumerate}\n\\item \nThe cross product (also vector product) of vectors $\\mathbf{a}$ and $\\mathbf{b}$ has direction for which $\\mathbf{c} \\perp \\mathbf{a}$ and $\\mathbf{c} \\perp \\mathbf{b}$ and magnitude of: \\\\\n$$\\abs{\\mathbf{a} \\cross \\mathbf{b}} = \\abs{\\mathbf{a}} \\abs{\\mathbf{b}} \\sin \\angle (\\mathbf{a},\\mathbf{b})$$ \\\\\nAlternatively:\n$$ \\mathbf{a} \\cross \\mathbf{b} = \\det\n\\left(\n\\begin{matrix}\n\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\na_1 & a_2 & a_3 \\\\\nb_1 & b_2 & b_3 \n\\end{matrix}\n\\right)\n$$\nwhere $\\mathbf{i},\\mathbf{j},\\mathbf{k}$ are unit vectors. Then:\n\\begin{enumerate}\n\\item \n$\\mathbf{a} \\cross \\mathbf{b} = - \\mathbf{b} \\cross \\mathbf{a} $\n\\item \n$(\\lambda \\mathbf{a} + \\mu \\mathbf{b}) \\times \\mathbf{c} = \\lambda \\mathbf{a} \\times \\mathbf{c} + \\mu \\mathbf{b} \\times \\mathbf{c}$\n\n\\item \nIf $\\abs{\\mathbf{a}},\\abs{\\mathbf{b}} \\ne 0$,then $\\mathbf{a} \\cross \\mathbf{b}=0$ if and only if when $\\mathbf{a} \\parallel \\mathbf{b}$.\n\\end{enumerate}\n\\end{enumerate}\n\n\\newpage\n\\subsection{Problems}\n\\begin{enumerate}\n\\item\nProve that $\\abs{\\mathbf{a} + \\mathbf{b}}^2 + \\abs{\\mathbf{a} - \\mathbf{b}}^2 = 2(\\abs{\\mathbf{a}}^2 + \\abs{\\mathbf{b}}^2)$.\n\n\\item\nProve that if $(\\mathbf{a}+\\mathbf{b}) \\perp (\\mathbf{a}-\\mathbf{b})$, then $\\abs{\\mathbf{a}} = \\abs{\\mathbf{b}}$.\n\n\\item \nLet $\\overrightarrow{OA} + \\overrightarrow{OB} + \\overrightarrow{OC} = 0$ and $\\abs{OA}=\\abs{OB}=\\abs{OC}$. Prove that $ABC$ is an equilateral triangle\n\n\\item %Prasolov 13.1\nProve that it is possible to make another triangle $KLM$ from the medians $AA_1$,$BB_1$,$CC_1$ of a triangle $ABC$. Similarly, triangle $XYZ$ is formed from the medians of $KLM$. Prove that $\\triangle ABC \\sim \\triangle XYZ$ and find their similarity coefficient. \n\n\\item %Prasolov 13.4\nFrom a point inside a convex $n$-gon, the rays are drawn perpendicular to the sides and intersecting the sides (or their continuations). On these rays the vectors $\\mathbf{a_1}, \\dots , \\mathbf{a_n}$ whose lengths are equal to the lengths of the corresponding sides are drawn. Prove that\n$\\mathbf{a_1} + \\dots + \\mathbf{a_n} = 0$.\n\n\n\\item % Prasolov 13.7\nConsider n pairwise non-codirected vectors ($n \\geq 3$) whose sum is equal to zero. Prove that there exists a convex $n$-gon such that the set of vectors formed by its sides coincides with the given set of vectors.\n\n\\item % Napoleonic triangles\n(\\emph{Napoleon's theorem})Three equilateral triangles $ABD$, $BCE$, $CAF$ are constructed outside the triangle $ABC$. Prove that the centres of the constructed triangles form an equilateral triangle. \n\n\\item %Prasolov 13.12\n\\begin{enumerate}\n\\item Let A, B, C and D be arbitrary points on a plane. Prove that\n$$ \\overrightarrow{AB} \\cdot \\overrightarrow{CD} +\n\\overrightarrow{BC} \\cdot \\overrightarrow{AD} +\n\\overrightarrow{CA} \\cdot \\overrightarrow{BD} = 0\n $$\n\\item Prove that the heights of a triangle intersect at one point.\t\n\\end{enumerate}\n\n\\item %Prasolov 13.13\nLet $O$ be the centre of the circumcircle of triangle $ABC$ and let point $H$\nsatisfy $\\overrightarrow{OH} = \\overrightarrow{OA} + \\overrightarrow{OB} + \\overrightarrow{OC}$. Prove that $H$ is the intersection point of heights of triangle.\n\n\\item %Prasolov 13.19\nGiven points $A$, $B$, $C$ and $D$. Prove that $AB^2 + BC^2 + CD^2 + DA^2 \\geq AC^2 + BD^2$,\nwhere the equality is attained only if $ABCD$ is a parallelogram.\n\n\\item % Prasolov13.22.\nPoints $A_1,\\dots, A_n$ lie on a circle with center $O$ and $\\overrightarrow{OA_1} +\\dots+ \\overrightarrow{OA_n}=0$. Prove\nthat for any point $X$ we have $XA_1 + \\dots + XA_n \\geq nR$, where $R$ is the radius of the circle.\n\n\n\n\\item \nProve Ceva's theorem: $X$, $Y$ and $Z$ are points on the sides $BC$, $CA$ and $AB$ of a triangle $ABC$ respectively. Then, lines $AX$, $BY$,$CZ$ intersect at a single point if and only if\n$$\\frac{\\overrightarrow{BX}}{\\overrightarrow{XC}} \\cdot \\frac{\\overrightarrow{CY}}{\\overrightarrow{YA}} \\cdot \\frac{\\overrightarrow{AZ}}{\\overrightarrow{ZB}} = 1$$\n\n\\item \nProve Menelaus's theorem: $X$, $Y$ and $Z$ are points on the sides (or their elongations) $BC$, $CA$ and $AB$ of a triangle $ABC$ respectively. Then, $X$,$Y$ and $Z$ lie on the same line if and only if\n$$\\frac{\\overrightarrow{BX}}{\\overrightarrow{XC}} \\cdot \\frac{\\overrightarrow{CY}}{\\overrightarrow{YA}} \\cdot \\frac{\\overrightarrow{AZ}}{\\overrightarrow{ZB}} = -1$$\n\n\n\\item % IMO-2013-4\nLet $ABC$ be an acute-angled triangle with orthocentre $H$, and let $W$ be a point on the side $BC$, lying strictly between $B$ and $C$. The points $M$ and $N$ are the feet of the altitudes from $B$ and $C$, respectively. Denote by $\\omega_1$ the circumcircle of $BWN$, and let $X$ be the point on $\\omega_1$ such that $WX$ is a diameter of $\\omega_1$. Analogously, denote by $\\omega_2$ the circumcircle of $CWM$, and let $Y$ be the point on $\\omega_2$ such that $WY$ is a diameter of $\\omega_2$. Prove that $X$, $Y$ and $H$ are collinear.\n\n\\item \nIs it possible to construct a triangle for which both coordinates of each vertex are integers?\n\n\\item %http://www.math.olympiaadid.ut.ee/eng/archive/prob1314.pdf p12\nThe angles of a triangle are $22.5^\\circ$, $45^\\circ$ and $112.5^\\circ$. Prove that inside this triangle there exists a point that is located on the median through one vertex, the angle bisector through another vertex and the altitude through the third vertex.\n\n\n\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "65a738756f5c793fe7b6aef686f33876d1e89546", "size": 6830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "08_vectors.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": "08_vectors.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": "08_vectors.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": 48.4397163121, "max_line_length": 539, "alphanum_fraction": 0.6872620791, "num_tokens": 2408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152325073083131, "lm_q2_score": 0.7853085834000791, "lm_q1q2_score": 0.640209085455986}}
{"text": "% !TeX root = ../libro.tex\n% !TeX encoding = utf8\n%\n%*******************************************************\n% Summary\n%*******************************************************\n\n\\selectlanguage{english}\n\\chapter*{Summary}\\label{ch:summary}\n%\\addcontentsline{toc}{chapter}{Summar}\n\nNowadays experimental research in Neural Networks is more advanced than theoretical\nresults. \nFrom this we aim to establish a solid mathematical theory so as to optimize the current neural network models. \n\n\nAs a result of our study, we have proposed a novel neural \nnetwork model, and adapted and optimized\nevaluation and learning methods to it. \nMoreover, we have discovered some theorems that prove the \nequivalence among some activation functions, and hence we propose a new\n algorithm to initialize the weights of neural networks. Thanks to the\nfirst result, we obtain a criterion to choose the most \nsuitable activation function to maintain accuracy and reduce computational costs.\n Thanks to the second one, we might accelerate \nlearning convergence methods.\n\nIn addition, the models, methods and algorithms have been \nimplemented in Julia, resulting in the \\textit{OptimizedNeuralNetwork.jl} library. \n\nAll the theory development, designs, decisions and results are \nwritten in this memory, which has the following structure: \n\\begin{itemize}\n \\item \\textbf{Chapter \\ref{ch00:methodology}: Description of the methodology followed.} We have organized our project according to an agile philosophy  based on personas methodology, user stories, milestones and tests. This method has conducted and linked mathematical and technical results and implementations, giving them coherence and validation methods. \n\n \\item \\textbf{Chapter \\ref{chapter:Introduction-neuronal-networks}: Description of the learning problem.} We defined the characteristic and type of machine learning problems. We will focus on supervised learning ones. \n\n \\item \\textbf{Chapter \\ref{ch03:teoria-aproximar}:  Approximation theory.} In order to establish a solid theory, we will start our work trying to solve machine learning problems by traditional approximation methods.  The main result we prove is the Stone Weierstrass's theorem. As a conclusion of this chapter we will achieve knowledge of the virtues and faults of traditional methods and understanding the necessity of new methods and structures such as neural networks. \n\n \\item \\textbf{Chapter \\ref{chapter4:redes-neuronales-aproximador-universal}: Neural networks are universal approximators.}  In this chapter we introduce our neural \n network model and compare it with the conventional ones. In order to show it is well \n defined, we will prove the universal convergence of our model to any measurable \n function. In addition, we will give some results about how our model solves \n classification and regression problems as its number of neurons rises. Finally, we \n will argue if all of those math results can actually solve real life problems. The \n idea behind the debate is the computability representation of real numbers. \n\n \\item \\textbf{Chapter  \\ref{chapter:construir-redes-neuronales}: The design and implementation of neural networks.} We will carefully  describe the design and \n implementation of our model of neural network. Thanks to that we will obtain some \n mathematical results about bias and classification function. This will be useful to \n compare our model with the conventional ones and justify \nour selection. Moreover, we will explain, justify and design  learning and evaluation \nmethods to our model. These methods are optimized versions of Forward Propagation and \nBackpropagation. \n\n\\item \\textbf{Chapter \\ref{funciones-activacion-democraticas-mas-demoscraticas}: Democratization of activation functions.} \nWe will explain in this chapter if there are better activation functions. In this \ndirection we will prove two original results which show that there are families of \nactivation functions that under the same conditions will solve problems with the same \naccuracy. As a result, if we compare the computational cost of the members of those \nfamilies and choose the faster one, we will obtain a method to optimize evaluation and \nlearning of neural networks without loss of accuracy. We have used the Wilcoxon \nsigned-rank test as a statistical hypothesis test so as to give a rigorous study of \nour criteria. \n\n\\item \\textbf{Chapter \\ref{section:inicializar_pesos}: Weight initializing algorithm.} \nSince Backpropagation and other iterative  methods are sensitive to the initial \nvalue of a neural network, we will show an original method to initialize its weights \nfrom training data. This process not only will produce a better initial step but also \nhas lower computational cost than Backpropagation.  To test the potential of this \nmethod we will use the Wilcoxon signed-rank test again and also, from the experiment's \nrequirements we will design and create our OptimizedNeuralNetwork.jl library. In this chapter we \nwill also explain every decision done during the design and implementation of the \nlibrary in order to be as efficient as possible.\t\n\n\\item \\textbf{Chapter \\ref{ch08:genetic-selection}: Use of genetic algorithm in the selection of activation function.} \nIn this chapter we will explain a future work. Given a fixed number of neurons, the \nselection of its activation function may be crucial to reduce the train and test \nerror.  However, adding more free params to the search space increases its complexity \nand at same time the cost of finding a solution.  Nevertheless, the result obtained in \nchapter \\ref{funciones-activacion-democraticas-mas-demoscraticas} and a property of our neural model will reduce the space complexity.\n\n\\item \\textbf{Chapter \\ref{ch09:conclusion}: Conclusions.}\n\\end{itemize} \n\n\\paragraph{KEYWORDS:}\n\\begin{itemize*}[label=,itemsep=1em,itemjoin=\\hspace{1em}]\n  \\item neural networks\n  \\item optimization\n  \\item activation functions\n  \\item weights initializing\n  \\item machine learning library\n\\end{itemize*}\n\n% Al finalizar el resumen en inglés, volvemos a seleccionar el idioma español para el documento\n\\selectlanguage{spanish}\n\\endinput\n", "meta": {"hexsha": "295f70313e2b47525ca92eebdb4280575e4a6e93", "size": 6148, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Memoria/preliminares/summary.tex", "max_stars_repo_name": "BlancaCC/TFG-Estudio-de-las-redes-neuronales", "max_stars_repo_head_hexsha": "e16d039ba972c6f2fb4eeed899b3abfa6e121d07", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2022-01-09T18:56:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T17:05:44.000Z", "max_issues_repo_path": "Memoria/preliminares/summary.tex", "max_issues_repo_name": "BlancaCC/TFG-Estudio-de-las-redes-neuronales", "max_issues_repo_head_hexsha": "e16d039ba972c6f2fb4eeed899b3abfa6e121d07", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 73, "max_issues_repo_issues_event_min_datetime": "2021-11-27T06:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T17:38:01.000Z", "max_forks_repo_path": "Memoria/preliminares/summary.tex", "max_forks_repo_name": "BlancaCC/TFG-Estudio-de-las-redes-neuronales", "max_forks_repo_head_hexsha": "e16d039ba972c6f2fb4eeed899b3abfa6e121d07", "max_forks_repo_licenses": ["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.7346938776, "max_line_length": 473, "alphanum_fraction": 0.7895250488, "num_tokens": 1308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410783, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6402090769281766}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\\DeclareMathOperator{\\Res}{Res}\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\n\\begin{problem}\\label{terminology-infinite-product}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\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\n\\begin{problem}\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\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\n\n\\begin{problem}\\label{modularity}For $a > 0$ define\n  $\\vartheta(a) = \\sum_{n=-\\infty}^\\infty e^{-a \\pi z^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\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} &=\n3.544907701811032\\textbf{10533931955126186}\\ldots \\\\\n  2\\sqrt{\\pi} &=\n3.544907701811032\\textbf{05459633496668229}\\ldots\n\\end{align*}\nIs my computer broken?  (For more, see \\texttt{https://arxiv.org/abs/1809.10907}.)\n\\end{problem}\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\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\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\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\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\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\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\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\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\n\\end{document}\n", "meta": {"hexsha": "1e38fd4df53f9670bf2dfbcd392c133f4a2c1e17", "size": 4884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set10.tex", "max_stars_repo_name": "kisonecat/math5522h", "max_stars_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-13T03:38:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T03:38:29.000Z", "max_issues_repo_path": "problem-sets/set10.tex", "max_issues_repo_name": "kisonecat/math5522h", "max_issues_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "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/set10.tex", "max_forks_repo_name": "kisonecat/math5522h", "max_forks_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-11T18:43:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-11T18:43:51.000Z", "avg_line_length": 34.1538461538, "max_line_length": 233, "alphanum_fraction": 0.6457821458, "num_tokens": 1822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8152324871074607, "lm_q1q2_score": 0.6402090675439575}}
{"text": "\\input{Setup.tex}\n\\begin{document}\n\n\\mainmatter\n\n\\section{Hebbian Learning}\n\\vspace{1mm}\n\\begin{quote}\n\\textsl{When an axon of cell A is near enough to excite a cell B and repeatedly or persistently takes part in firing it, some growth process or metabolic change takes places in one or both cells such that A's efficiency, as one of the cells firing B, is increased.}\\cite{Hebb1949}\n\\end{quote}\n\n\\section{Spike Timing Dependant Plasticity}\nWrite about STDP, see the 'Postulates.pdf'. \\\\\n\nWith spike timing dependant plasticity we want to study how two neurons change their synaptic strength based on the time delay between spikes. When $\\theta(t)_j > \\pi$ we say that the neuron $\\theta_j$ spikes at time $t$. \nLet us say that $\\theta_i$ spikes at time $t_i$ and $\\theta_j$ spikes at $t_j$. Taking the time difference $\\Delta t_{ij}$ as $t_j - t_i$, we can say that when $\\Delta t_{ij} > 0$ the spikes are correlated (there exists a temporally causal relation), and we can model an increase in synaptic strength of the connection $K_{ij}$ from $\\theta_i$ to $\\theta_j$. In the same fashion we can decrease $K_{ji}$ when $\\Delta t_{ij} < 0$ as there is no causal relation. \\\\\nThe functions $W(t)$ that relate $\\Delta t_{ij}$ to $\\Delta K_{ij}$ are called \\textsl{learning windows},  as they define a range in which $K_{ij}$ is able to adapt. When signals between neurons show a very large time difference (negative or positive) we do not expect them to be correlated. Because the learning windows are generally not symmetrical we can also expect an asymmetrical adjacency matrix.\\\\\nAnother characteristic is the integral over the learning window. A window with a negative integral directs synaptic strengths mostly towards inhibitory behaviour, and vice versa with a positive integral. An integral of zero would mean that both inhibitory and excitatory synapses are stimulated equally.\\\\\n\nNow that we have a feeling of how \\STDP works, we need to formulate the behaviour exactly. One by one, we will denote our ideas into mathematics.\n\n\n\\subsection{Biphasic learning windows}\n\n\\subsubsection{Kempter1999}\nFollowing the notation in \\cite{Kempter1999}, we will denote the spike train coming from each neuron $\\theta_i$ as $S_i^{\\rm out}(t) = \\sum_{n} \\delta (t-t_{i}^{n})$, where $t_{i}^{n}$ is the time that $\\theta_i$ has fired. Similarly, we will denote the spike train coming into each neuron $\\theta_i$ as $S_i^{\\rm in}(t) = \\sum_{f} \\delta (t-t_{i}^{f})$. Now we can say that the synaptic strengths are adjusted as:\n\\begin{align}\n\\Delta K_{ij} &= \\int_{t}^{t+\\mathcal{T}} w^{\\rm{out}} S_i^{\\rm out}(\\tau) + w^{\\rm{in}} S_{j}^{\\rm {in}}(\\tau) \\mathrm{d}\\tau\n+ \\iint_{t}^{t+\\mathcal{T}} W( \\tau^\\prime - \\tau) S_{i}^{\\rm out}(\\tau) S_{j}^{\\rm in}( \\tau^\\prime) \\mathrm{d} \\tau \\mathrm{d} \\tau^\\prime\n\\label{eq:KempterSTDPFormulation1} \\\\\n&= \\sum_{t_i^{n}\\in \\mathcal{T}} w^{\\mathrm{out}} + \\sum_{t_{j}^{f} \\in \\mathcal{T}} w^{\\mathrm{in}} + \\sum_{t_{j}^{f}, t_i^{n} \\in \\mathcal{T}} W (t_{j}^{f}-t_i^{n} ) \\label{eq:KempterSTDPFormulation2}\n\\end{align}\nwhere \\cite{Kempter1999} proposes the following learning window:\n\\begin{align}\nW(t)_K = \\alpha\n\\begin{cases}\n\\left[A_{p}\\left(1-\\frac{t}{\\tilde{\\tau}_{p}}\\right)+A_{n}\\left(1-\\frac{t}{\\tilde{\\tau}_{n}}\\right)\\right] \\cdot \\exp \\left( \\frac{t}{\\tau_{\\rm syn}} \\right) & \\text{for } t \\leq 0 \\\\\nA_{p} \\cdot \\exp \\left(-\\frac{t}{\\tau_{p}}\\right) + A_{n} \\cdot \\exp \\left(-\\frac{t}{\\tau_{n}} \\right) & \\text{for } t > 0\n\\end{cases} \\label{eq:learningwindowKempter1999}\n\\end{align}\nHere $t$ is the delay between presynaptic spike arrival and postsynaptic firing, $\\alpha$ is a small learning parameter and all $\\tau$ are time constants. Numerical values are usually  $\\alpha = 0.05$, $\\tau_{\\rm syn} = 5$ ms, $\\tau_{p} = 1$ ms, $\\tau_{n} = 20$ ms and $A_p = 1$ and $A_{n} = -1$. $\\tilde{\\tau}_{p} \\equiv \\tau_{\\rm syn} \\tau_{p} / (\\tau_{\\rm syn} + \\tau_{p})$ and $\\tilde{\\tau}_{n} \\equiv \\tau_{\\rm syn} \\tau_{n} / (\\tau_{\\rm syn} + \\tau_{n})$. \\\\\n$\\int W(s)_K \\mathrm{d}s = 2.56 \\times 10^{-4}$.\n\n\n\\subsubsection{Song 2000}\nThe first formulation of \\STDP as a mathematical model was in \\cite{Song2000}. It is postulated without being concerned about the biological aspect too much. The synaptic strengths are simply updated as:\n\\begin{align}\n\\Delta K_{ij} &= K_{ij} \\sum_{t_{j}^{f}, t_i^{n} \\in \\mathcal{T}} W (t_{j}^{f}-t_i^{n} ) \\label{eq:SongSTDPFormulation}\n\\end{align}\nThe learning window is defined as a discontinuous function:\n\\begin{align}\nW(t)_S =\n\\begin{cases}\nA_{p} \\cdot \\exp \\left(\\frac{-t}{\\tau_p}\\right) & \\text{for } s > 0 \\\\\nA_{n} \\cdot \\exp \\left(\\frac{t}{\\tau_n}\\right)  & \\text{for } s \\leq 0\n\\end{cases} \\label{eq:learningwindowKempter1999}\n\\end{align}\nwhere we will use $A_p = 0.005$, $A_n = -0.00525$ and $\\tau_p = \\tau_n = 20$ ms. $\\int W(s)_S \\mathrm{d}s = -3.70 \\times 10^{-4}$ so we expect the weights to be suppressed towards a negative value.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/LearningWindowsBiphasic.png}\n\\caption{Two different biphasic learning windows. We can see how in $W(t)_s$ a larger weight is put on the anti-Hebbian learning.}\n\\label{fig:LearningWindowsBiphasic}\n\\end{figure}\n\n\n\\subsection{Triphasic Learning windows}\nBased off of neuronal actiity in the hippocmpus, biologically inspired triphasic windows have been developed. The papers describing the learning process are not specifying exactly how the weights are updated, as we have seen before there are a few options. We assume the change is simply:\n\\begin{align}\n\\Delta K_{ij} =  \\sum_{t_{j}^{f}, t_i^{n} \\in \\mathcal{T}} W (t_{j}^{f}-t_i^{n} ) \\label{eq:WaddingtonSTDPFormulation}\n\\end{align}\nas there is no mention of other parameters.\n\n\\subsubsection{Chrol-Cannon 2012}\n\\begin{align}\nW(t)_C = A_{p} \\cdot \\exp \\left(\\frac{-\\left(t - 15 \\right)^{2}}{ \\tau_{p}}\\right) - A_{n} \\cdot \\exp \\left(\\frac{-\\left(t - 20\\right)^{2}}{ \\tau_{n}}\\right)  \\label{eq:learningwindowChrolCannon2012}\n\\end{align}\nwhere $A_{p}=0.23$, $A_{n}=0.15$, $\\tau_{p}=200$ and $\\tau_n = 2000$. $\\int W(s)_C \\mathrm{d}s = -60.0 \\times 10^{-4}$.\n\n\\subsubsection{Waddington 2014}\nThe learning window is then defined as:\n\\begin{align}\nW(t)_W =  A \\left[1-\\frac{\\left(t-\\alpha\\right)^{2}}{\\alpha^{2}}\\right] \\cdot \\exp \\left(\\frac{-\\left|t - \\alpha\\right|}{\\alpha}\\right) \\label{eq:learningwindowWaddington2014}\n\\end{align}\nWe will use $A = 0.1$ and $\\alpha = 4.0$ ms . $\\int W(s)_W \\mathrm{d}s = -8.0 \\times 10^{-4}$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/LearningWindowsTriphasic.png}\n\\caption{The mean degree $\\kmean$ evolves over time as a function of the spiking behaviour, just like we expect.}\n\\label{fig:LearningWindowsTriphasic}\n\\end{figure}\n\n\n\\subsection{Interpretation}\nThe learning windows generally have $W(t^{\\ast}) = 0$ for $t^{\\ast} > 0$. This means that no learning will take place when the delay between neuron spikes is exactly $t^{\\ast} > 0$. The triphasic windows show two of those points.\n\n\\subsection{Results}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth, trim={60 0 60 0}]{../Figures/LearningWithoutScaling.png}\n\\caption{Two different triphasic learning windows. We can see how in $W(t)_C$  a much higher penalty is given to signals that arrive too early or too late. The moments at which signals should peak also differ by about 10 ms.}\n\\label{fig:LearningWithoutScaling}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.2\\textheight]{../Figures/STDPbeforeIP.png}\n\\caption{Results from \\STDP.}\n\\label{fig:STDPbeforeIP}\n\\end{figure}\n\n\n\n\\subsection{Synaptic scaling}\nThere is no upper or lower bound on the synapse strength. Also generally, connection strengths are nonzero. This means that the notion of a \\textsl{network} is lost.\\\\\nOne technique we can apply to keep the strengths within a definitive range is to scale homeostatically - a method where increases in synaptic strength will balance out any decreases by scaling:\n\\begin{align}\nK_{ij}^s = K_{ij} \\frac{\\frac{1}{N} \\sum_{i,j} K_{ij}}{\\sum_{i} K_{ij}}\n\\end{align}\nIn this way, the out-degrees will remain constant. Using this approach, something has to remain constant, whether that is $\\kmean$, or $\\kmean^2$ or any other property of the adjacency matrix.\n\n\n\\subsection{Intrinsic plasticity}\nInstead of scaling the weights to preserve a certain quantity in the network, we can allow the neurons to adjust the sensitivity to incoming signals. So when some synaptic strengths are increased, we can reduce the excitability. In \\cite{Song2017} such a method is introduced in detail. We can simply update $\\eta_{i} \\rightarrow \\eta_{i} + \\eta_{\\max } \\cdot \\phi_{i}$ where \n\\begin{align}\n\\phi_{i} (t) =\\left\\{\\begin{array}{l}-\\alpha \\cdot \\exp \\left(\\frac{T_{\\min }-t}{T_{\\rm min }}\\right) \\text { if } t<T_{ \\rm min } \\\\ \\alpha \\cdot \\exp \\left(\\frac{t-T_{\\rm max }}{T_{\\max }}\\right) \\text { if } t >T_{\\rm max } \\\\ 0, \\text { otherwise }\\end{array}\\right.\n\\end{align}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{../Figures/IPlearningFunction.png}\n\\caption{The learning behaviour for the intrinsic plastiity.}\n\\label{fig:IPlearningFunction}\n\\end{figure}\n\n\n\n\\subsection{Custom learning windows}\nSome of the behaviour we want to observe is currently not accounted for: synaptic strengths are unbounded and are generally nonzero. How can we model the behaviour where synaptic strengths can also settle on being zero? Perhaps a better idea than updating the synaptic strength by adding a new value, we can scale it.\n\\begin{itemize}\n\\item When $\\Delta t_{ij}$ is very large (both positive and negative) we expect no change in the synaptic strength: $W(-\\infty) = W(-\\infty) = 0$. \n\\item We expect a specific positive time delay to yield the most amount of synaptic strengthening: $\\Delta t_{\\rm best} = \\underset{x}{\\arg \\max}  W(t)$\n\\item We expect small connections that have been reducing in size to quickly become zero, \n\\item A better scaling system would be that not the out- or in-degree is constant, but \n\\end{itemize}\n\n\n\n\\bibliographystyle{utphys}\n\\small{\\bibliography{references}}\n\n\\label{LastPage}~\n\n\\end{document}\n", "meta": {"hexsha": "fd802d84ab9a056eaea51d3ee67cc908fc004106", "size": 10173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Notes/SynapticPlasticity.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/Notes/SynapticPlasticity.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/Notes/SynapticPlasticity.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": 64.7961783439, "max_line_length": 464, "alphanum_fraction": 0.7169959697, "num_tokens": 3181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.6402090663522412}}
{"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{Recurrences}\nIf $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. \\]\nNon-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\\\\\ncos(v+w)&{}=\\cos v\\cos w-\\sin v\\sin w\\\\\n\\end{align*}\n\\begin{align*}\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\\[ (V+W)\\tan(v-w)/2{}=(V-W)\\tan(v+w)/2 \\]\nwhere $V, W$ are lengths of sides opposite angles $v, w$.\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: $p=\\dfrac{a+b+c}{2}$\\\\\nArea: $A=\\sqrt{p(p-a)(p-b)(p-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{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}\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(2n+1)(n+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\n\\section{Series} \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", "meta": {"hexsha": "aa265d9d452e414c5e96b170e3077005e7515898", "size": 3324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/math/chapter.tex", "max_stars_repo_name": "moskupols/teambook", "max_stars_repo_head_hexsha": "343fd426960e6e7d6e1a62fa3724470d58f4494f", "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": "content/math/chapter.tex", "max_issues_repo_name": "moskupols/teambook", "max_issues_repo_head_hexsha": "343fd426960e6e7d6e1a62fa3724470d58f4494f", "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": "content/math/chapter.tex", "max_forks_repo_name": "moskupols/teambook", "max_forks_repo_head_hexsha": "343fd426960e6e7d6e1a62fa3724470d58f4494f", "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.1688311688, "max_line_length": 157, "alphanum_fraction": 0.5716004813, "num_tokens": 1597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6402090640186456}}
{"text": "\\section{Measurement Model}\n\nThe measurement model serves the goal of allowing us to retrieve the equivalent measurement values for a given state. This is necessary for calculating the Innovation, and thus the Kalman Gain, which allows us to update the state in the best way possible by taking both the predictions and the measurements into account. This use implies the necessity of being able to retrieve the measurements from the state, which is why we include the wheel velocities $v_l$ and $v_r$ in the state despite not actually using these values for navigation; without including them directly, it is hard to recover them from the remaining state variables.\n\nThe desired behavior is\n\\begin{equation}\n    \\boldsymbol{z}_{\\textrm{equiv}} = \\boldsymbol{H} \\cdot \\boldsymbol{\\hat{x}}_{n,n-1}\n\\end{equation}\n\nIn words, we multiply $\\boldsymbol{H}$ by the prediction for the current state made in the previous timestep to recover an equivalent measurement. Since our measurement vector is simply a subset of the state, our measurement model is\n\\begin{equation}\n    \\boldsymbol{H} = \n    \\begin{pmatrix}\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\n    \\end{pmatrix}\n\\end{equation}\n\nWe can then calculate our innovation,\n\\begin{equation}\n    \\boldsymbol{y}_{n} = \\boldsymbol{z}_{n} - \\boldsymbol{z}_{\\textrm{equiv}}\n\\end{equation}", "meta": {"hexsha": "8c4b4144a8e2930c03e066b0f8ff121db9b3c687", "size": 1505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/IGVC EKF Derivation/sections/measurementmodel.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/measurementmodel.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/measurementmodel.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": 57.8846153846, "max_line_length": 636, "alphanum_fraction": 0.6916943522, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.7154239836484144, "lm_q1q2_score": 0.6401538363368621}}
{"text": "The previous chapter on finite state machines provided an introduction into high-level robot behavior specification. Another important topic along this thread is \\textit{sequential decision making}\\cite{Bertsekas2019}, where the robot must make a series of decisions to accomplish an objective in an optimal way. \nThis chapter provides an introduction to fundamental topics in decision making, including for problems where there is some uncertainty (e.g. uncertainty about the robot's state or about the environment).\n\n\\notessection{Sequential Decision Making}\nIn addition to the motion planning and control problems discussed in earlier chapters (which focus on low-level tasks), there exist a broad range of situations where higher-level autonomous decision making is required. For example when deciding whether it is time for a self-driving car to cross an intersection, or whether a robot should first complete task A or task B.\nTwo of the fundamental challenges associated with robotic decision making are that \\textit{sequences} of decisions must be made (which requires reasoning about future actions and observations) and that uncertainty may exist in the operating environment. This chapter presents a modeling framework for addressing decision making problems and will also introduce \\textit{dynamic programming}, a fundamental approach for solving these problems .\n\n\n\\subsection{Deterministic Decision Making Problem}\nThe standard mathematical formulation for decision making problems includes several components: a model of the robot's behavior, a set of admissible controls, and a cost function. This set of components is quite similar to the components used in trajectory optimization problems discussed in previous chapters, however decision making problems are generally represented in \\textit{discrete-time} rather than in \\textit{continuous-time}\\footnote{There is a continuous-time formulation, known as the Hamilton–Jacobi–Bellman formulation.}.\n\nIn the deterministic decision making problem, the model of the robot is expressed in \\textit{discrete-time} as:\n\\begin{equation} \\label{eq:detmodel}\n\\x_{k+1}= f_k(\\x_k, \\bu_k), \\quad k = 0, \\dots, N-1,\n\\end{equation}\nwhere $\\x$ is the robot's state, $\\bu$ is the control, $f_k$ defines how the robot's state changes at time step $k$, and $N$ is an integer that defines a finite planning horizon for the decision making problem. There are generally no restrictions on how the functions $f_k$ are defined, they could come from a physics-based dynamics/kinematics model or even a higher-level state transition model similar to the finite state machine from the previous chapter.\n\nIt is also generally assumed that only some control actions are admissible at a given state, which denoted by the set $\\mathcal{U}(\\x_k)$. For example a car may only have an option to turn left or right when it is at an intersection.\nTherefore the control constraints for the robot at time step $k$ are given by:\n\\begin{equation} \\label{eq:SDMPconstraints}\n\\bu_k \\in \\mathcal{U}(\\x_k).\n\\end{equation}\nAgain, there are generally no restrictions on how the set of admissible control is defined. For example $\\mathcal{U}(\\x_k)$ could be a finite set of actions, it could be a convex region of allowable inputs, etc.\n\nThe cost function is assumed to be \\textit{additive}, and is defined as:\n\\begin{equation} \\label{eq:detcost}\nJ(\\x_0, \\bu_0, \\dots, \\bu_{N-1}) = g_N(\\x_N) + \\sum_{k=0}^{N-1} g_k(\\x_k, \\bu_k),\n\\end{equation}\nwhere $g_N$ is a terminal state cost function and $g_k$ for $k=0,\\dots,N-1$ are stage cost functions. These individual cost functions are also not restricted to a particular form (e.g. convex, differentiable, etc.).\n\n\\begin{definition}[Deterministic Decision Making Problem]\nThe deterministic decision making problem can be expressed for the system model \\eqref{eq:detmodel}, control constraints \\eqref{eq:SDMPconstraints}, and cost function \\eqref{eq:detcost} as:\n\\begin{equation} \\label{eq:dproblem}\nJ^*(\\x_0) = \\underset{\\bu_k \\in \\mathcal{U}(\\x_k), \\:\\:k=0,\\dots,N-1}{\\min} J(\\x_0, \\bu_0, \\dots, \\bu_{N-1}).\n\\end{equation}\n\\end{definition}\n\nNotice that this problem is used to compute an \\textit{open-loop} control sequence $\\{\\bu_0, \\dots, \\bu_{N-1}\\}$ given an initial condition $\\x_0$, which is similar to the trajectory optimization problems seen in earlier chapters. \nHowever, this problem is generally quite hard to solve since there is no guarantee that the model \\eqref{eq:detmodel} and cost function \\eqref{eq:detcost} have any particular structure that can be leveraged to make the optimization problem amenable to numerical optimization algorithms. While it is theoretically possible to solve the problem through a brute force search over all possible combinations of sequences $\\{\\bu_0, \\dots, \\bu_{N-1}\\}$, this leads to a combinatorial explosion of options and is therefore not possible in practical settings (except of course for very small problems).\n\n\\subsubsection{Principle of Optimality (Deterministic)}\nFortunately, there is in fact an underlying structure to the deterministic decision making problem that can be leveraged to make the problem easier to solve. This structure is commonly referred to as the \\textit{principle of optimality}.\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{tex/figs/ch20_figs/princopt1.png}\n    \\caption{Starting from point $a$, let the red path $a-b-e$ be the optimal path from $a$ to $e$, with a total cost of $J^*_{ae} = J_{ab}+J_{be}$. The principle of optimality in this case says that the path $b-e$ must therefore be the optimal path when starting from point $b$. This can be proven by contradiction, since if the path $b-c-e$ had a lower cost than path $b-e$ (i.e. $J_{bce} < J_{be}$), then the original path $a-b-e$ cannot be optimal!}\n    \\label{fig:princopt1}\n\\end{figure}\n\nThe principle of optimality for deterministic systems is that for a sequence of optimal decisions, the \\textit{tail} of the optimal sequence is also optimal for a \\textit{tail subproblem}. For a concrete example see Figure \\ref{fig:princopt1}. This can greatly simplify the overall problem, since you can ``reuse'' optimal paths for different scenarios. More formally, the principle of optimality is given by the following theorem:\n\\begin{theorem}[Principle of Optimality (Deterministic)]\nLet $\\{\\bu_0^*, \\bu_1^* \\dots, \\bu_{N-1}^*\\}$ be an optimal control sequence to the deterministic decision making problem \\eqref{eq:dproblem} with a given initial condition $\\x^*_0$, such that the resulting optimal state sequence is $\\{\\x_0^*, \\x_1^* \\dots, \\x_{N}^*\\}$. Then, the tail sequence $\\{\\bu_k^*, \\dots, \\bu_{N-1}^*\\}$ is an optimal control sequence when starting from $\\x^*_k$ and minimizing the cost from time $k$ to time $N$\n\\begin{equation*}\nJ_{\\text{tail}}(\\x_k, \\bu_k, \\dots, \\bu_{N-1}) = g_N(\\x_N) + \\sum_{m=k}^{N-1} g_m(\\x_m, \\bu_m).\n\\end{equation*}\n\\end{theorem}\n\nTo see how the principle of optimality can be applied to simplify the decision making problem, consider the scenario in Figure \\ref{fig:princopt2}. In this case it is desired to find an optimal path from point $b$ to point $f$, and it is assumed that optimal paths from $c$, $d$, and $e$ to $f$ are already known. A brute force search over all possible paths in this problem would require nine paths to be evaluated:\n\\begin{equation*}\n\\begin{split}\n\\{b-c-f, \\quad b-c-d-f, \\quad b-c-d-e-f, \\quad b-d-c-f, \\quad b-d-f, \\\\\n\\quad b-d-e-f, \\quad b-e-d-c-f, \\quad b-e-d-f, \\quad b-e-f \\}.\n\\end{split}\n\\end{equation*}\nHowever, by leveraging the principle of optimality the number of candidate paths is reduced to three:\n\\begin{equation*}\nb-c-f, \\quad b-d-f, \\quad b-e-f.\n\\end{equation*}\nIn other words, the principle of optimality allows the search to be performed over \\textit{immediate} decisions by also concatenating the optimal tail decisions! This procedure is generally implemented backward in time, for example in Figure \\ref{fig:princopt2} the point $f$ (the goal) is first evaluated, then the points $c$, $d$, and $e$, and then finally the point $b$.\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.65\\textwidth]{tex/figs/ch20_figs/princopt2.png}\n    \\caption{Suppose the optimal paths from points $c$, $d$ and $e$ to $f$ are known (shown in red). By using the principle of optimality, an optimal path from point $b$ to $f$ can be found by \\textit{only} searching over paths from $b$ to $c$, $d$, and $e$, and determining the lowest cost from the candidates $\\{J_{bc} + J^*_{cf}, J_{bd} + J^*_{df}, J_{be} + J^*_{ef}\\}$. In other words, the \\textit{optimal tails} can be leveraged to reduce the total number of paths that need to be considered when finding an optimal path from $b$ to $f$!}\n    \\label{fig:princopt2}\n\\end{figure}\n\n\\subsubsection{Dynamic Programming (Deterministic)}\nThe dynamic programming (DP) algorithm \\textit{globally} solves the deterministic decision making problem \\eqref{eq:dproblem} by leveraging the principle of optimality\\footnote[][4\\baselineskip]{Note that the principle of optimality is a fundamental property that is actually utilized in almost all decision making algorithms, including reinforcement learning.}. The dynamic programming algorithm is given in Algorithm \\ref{alg:dDP}, where it can be seen that a backward-in-time recursion is used and at each step a \\textit{local} optimization is performed (this local optimization is referred to as the \\textit{Bellman} equation), leveraging the optimal \\textit{tail} costs from the previous iteration.\n\\begin{algorithm}[ht]\n $J^*_N(\\x_N) = g_n(\\x_N),$ for all $\\x_N$\\\\\n \\For{$k=N-1$ \\KwTo $0$}{\n  $J^*_k(\\x_k) = \\underset{\\bu_k \\in \\mathcal{U}(\\x_k)}{\\min}g_k(\\x_k,\\bu_k) + J^*_{k+1}(f_k(\\x_k, \\bu_k)),$ for all $\\x_k$\\\\\n }\n \\Return $J^*_0(\\cdot),\\dots,J^*_N(\\cdot)$\n \\caption{Dynamic Programming (Deterministic)}\n \\label{alg:dDP}\n\\end{algorithm}\nThe output of the dynamic programming algorithm is a set of costs $J^*_k(\\x_k)$ for each time step $k = 0, \\dots,N$ and states $\\x_k$, which provide the optimal \\textit{tail} cost for the \\textit{tail} subproblem. \n\nGiven an initial condition $\\x_0$, the optimal control sequence $\\{\\bu^*_0,\\dots,\\bu^*_{N-1}\\}$ that solves the deterministic decision making problem can be computed with a ``forward pass'', where:\n\\begin{equation*}\n\\bu_0^* = \\underset{\\bu_0 \\in \\mathcal{U}(\\x_0)}{\\arg \\min}\\:\\:g_0(\\x_0,\\bu_0) + J^*_{1}(f_0(\\x_0, \\bu_0)).\n\\end{equation*}\nThe next state is then computed as $\\x^*_1 = f_0(\\x_0, \\bu^*_0)$, and the process is repeated:\n\\begin{equation*}\n\\bu_1^* = \\underset{\\bu_1 \\in \\mathcal{U}(\\x^*_1)}{\\arg \\min}\\:\\:g_1(\\x^*_1,\\bu_1) + J^*_{2}(f_1(\\x^*_1, \\bu_1)),\n\\end{equation*}\nuntil the full trajectory and optimal control is specified.\n\nNote that in practice the DP algorithm is not practical for continuously values states $\\x$, since an infinite number of states would have to be iterated over. Therefore one possible modification to handle continuously valued states is to \\textit{quantize} the state space into a finite set of states (other approaches, such as interpolation, are also possible). Also, it is interesting to note that the addition of control constraints can actually simplify the procedure, since it restricts the number of possible options that need to be considered!\n\n\\begin{example}[Deterministic Dynamic Programming] \\label{ex:detDP}\n\\theoremstyle{definition}\nConsider the environment shown in Figure \\ref{fig:detDPprob}, where the goal is to start at point $a$ and reach point $h$ while incurring the smallest cost. In this problem the state is represented as the current location (i.e. $a$, $b$, etc.), and the control constraints are encoded by the arrows indicating possible directions of travel (e.g. at point $c$ it is possible to either go right or up, but not down or left). The cost of traversing between two points is also denoted in Figure \\ref{fig:detDPprob}.\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{tex/figs/ch20_figs/dpexample.png}\n    \\caption{A deterministic decision making problem where the goal is to move from point $a$ to point $h$ while incurring the minimal amount of cost. The red path indicates the optimal path. This problem is solved by dynamic programming in Example \\ref{ex:detDP}.}\n    \\label{fig:detDPprob}\n\\end{figure}\n\nTo implement the DP algorithm, the final point $h$ is chosen as $\\x_N$, and the DP recursion begins with:\n\\begin{equation*}\n    J^*_N(h) = 0,\n\\end{equation*}\nsince there is no cost to stay at point $h$.\nMoving backward in time, it can be seen that the possible states $\\x_{N-1}$ that can transition to $\\x_N = h$ are the points $h$, $e$, and $g$ (assuming it is possible to stay at $h$ with no cost). Therefore in the first step of the DP recursion:\n\\begin{equation*}\n\\begin{split}\nJ^*_{N-1}(h) &= 0 + J^*_N(h) = 0, \\quad u^*_{N-1}(h) = \\text{stay}. \\\\\nJ^*_{N-1}(e) &= 8 + J^*_N(h) = 8, \\quad u^*_{N-1}(e) = \\text{right}, \\\\\nJ^*_{N-1}(g) &= 2 + J^*_N(h) = 2, \\quad u^*_{N-1}(g) = \\text{up}, \\\\\n\\end{split}\n\\end{equation*}\nNote that $J^*_k(h) = 0$ for all $k \\leq N$, and therefore it will not be explicitly included in the following steps. In the next step:\n\\begin{equation*}\n\\begin{split}\nJ^*_{N-2}(e) &= 8 + J^*_{N-1}(h) = 8, \\quad u^*_{N-2}(e) = \\text{right}, \\\\\nJ^*_{N-2}(g) &= 2, \\quad u^*_{N-2}(g) = \\text{up}, \\\\\nJ^*_{N-2}(d) &= 3 + J^*_{N-1}(e) = 11, \\quad u^*_{N-2}(d) = \\text{right}, \\\\\nJ^*_{N-2}(f) &= 3 + J^*_{N-1}(g) = 5, \\quad u^*_{N-2}(f) = \\text{right}, \\\\\n\\end{split}\n\\end{equation*}\nAt this point, these optimal tail costs can be considered to be the optimal costs associated with control actions that lead from $e$, $g$, $d$, or $f$ to the end point $h$ in \\textit{two} steps! Continuing on:\n\\begin{equation*}\n\\begin{split}\nJ^*_{N-3}(e) &= \\min \\{8 + J^*_{N-2}(h), \\:2 + J^*_{N-2}(f)\\} = 7, \\quad u^*_{N-3}(e) = \\text{down}, \\\\\nJ^*_{N-3}(g) &= 2, \\quad u^*_{N-3}(g) = \\text{up},  \\\\\nJ^*_{N-3}(d) &= 3 + J^*_{N-2}(e) = 11, \\quad u^*_{N-3}(d) = \\text{right}, \\\\\nJ^*_{N-3}(f) & = 5, \\quad u^*_{N-3}(f) = \\text{right}, \\\\\nJ^*_{N-3}(a) &= 8 + J^*_{N-2}(d) = 19, \\quad u^*_{N-3}(a) = \\text{right}, \\\\\nJ^*_{N-3}(c) &= \\min \\{5 + J^*_{N-2}(d), \\:3 + J^*_{N-2}(f)\\} = 8, \\quad u^*_{N-3}(c) = \\text{right}. \\\\\n\\end{split}\n\\end{equation*}\nInterestingly, it can be seen that it is now possible to accomplish the objective (i.e. go from point $a$ to $h$) in 3 time steps (i.e. on path $a-d-e-f$) and incur an optimal cost of 19. However it turns out that an even lower cost is achievable if the number of time steps is increased further! Continuing the DP recursion:\n\\begin{equation*}\n\\begin{split}\nJ^*_{N-4}(e) & = 7, \\quad u^*_{N-4}(e) = \\text{down}, \\\\\nJ^*_{N-4}(g) &= 2, \\quad u^*_{N-4}(g) = \\text{up}, \\\\\nJ^*_{N-4}(d) &= 3 + J^*_{N-3}(e) = 10, \\quad u^*_{N-4}(d) = \\text{right}, \\\\\nJ^*_{N-4}(f) &= 5,  \\quad u^*_{N-4}(f) = \\text{right},\\\\\nJ^*_{N-4}(a) &= 8 + J^*_{N-3}(d) = 19, \\quad u^*_{N-4}(a) = \\text{right} \\\\\nJ^*_{N-4}(c) &= \\min \\{5 + J^*_{N-3}(d), \\:3 + J^*_{N-3}(f)\\} = 8, \\quad u^*_{N-4}(c) = \\text{right}, \\\\\nJ^*_{N-4}(b) &= 9 + J^*_{N-3}(c) = 17, \\quad u^*_{N-4}(b) = \\text{right},\\\\\n\\end{split}\n\\end{equation*}\nand finally with one more iteration:\n\\begin{equation*}\n\\begin{split}\nJ^*_{N-5}(e) & = 7, \\quad u^*_{N-5}(e) = \\text{down}, \\\\\nJ^*_{N-5}(g) &= 2, \\quad u^*_{N-5}(g) = \\text{up}, \\\\\nJ^*_{N-5}(d) &= 10, \\quad u^*_{N-5}(d) = \\text{right}, \\\\\nJ^*_{N-5}(f) &= 5, \\quad u^*_{N-5}(f) = \\text{right}, \\\\\nJ^*_{N-5}(a) &= \\min \\{8 + J^*_{N-4}(d), \\:5 + J^*_{N-4}(b)\\} = 18, \\quad u^*_{N-5}(a) = \\text{right} \\\\\nJ^*_{N-5}(c) &= \\min \\{5 + J^*_{N-4}(d), \\:3 + J^*_{N-4}(f)\\} = 8, \\quad u^*_{N-5}(c) = \\text{right}, \\\\\nJ^*_{N-5}(b) &= 9 + J^*_{N-4}(c) = 17, \\quad u^*_{N-5}(b) = \\text{right}. \\\\\n\\end{split}\n\\end{equation*}\nAdditional iterations are not included in this example because the costs and optimal decisions will no longer change with longer horizons (see for yourself!). Therefore it can be seen that with a sufficiently long horizon ($N \\geq 5$), the optimal path from $a$ to $h$ is $a-d-e-f-g-h$ and incurs a cost of $18$. Not this process has actually given a lot more information than what was original asked for. In particular, given \\textit{any} starting point and \\textit{any} horizon it is straightforward to generate an optimal control sequence! For example, if you wanted to start at point $c$ and get to $h$ in $N=3$ steps you could immediately see that the optimal path is $c-f-g-h$ and the optimal cost is $8$.\n\\end{example}\n\n\n\\subsection{Stochastic Decision Making Problem}\nIn the stochastic decision making problem it is assumed that there is some \\textit{uncertainty} in the robot's behavior or in the environment. This uncertainty is captured in the stochastic discrete-time robot model:\n\\begin{equation} \\label{eq:smodel}\n\\x_{k+1}= f_k(\\x_k, \\bu_k, \\w_k), \\quad k = 0, \\dots, N-1,\n\\end{equation}\nwhere $\\w_k$ represents a stochastic disturbance term. Additionally, it is assumed that this disturbance has a known conditional probability distribution $P_k(\\w_k \\mid \\x_k, \\bu_k)$. Note that it is assumed that the disturbance is only dependent on the current state $\\x_k$ and control $\\bu_k$, and not states from earlier in the robot's history. \nThis is another example of the Markov assumption, which was similarly used to develop the algorithms for localization and filtering in previous chapters.\n\nAnother main difference between the stochastic decision making problem and the deterministic problem is that a control \\textit{policy} is computed in the stochastic case. A control policy, usually denoted $\\bu = \\pi(\\x)$, is a function that maps the state $\\x$ to a control $\\bu$, and therefore defines a closed-loop controller (whereas in the deterministic setting an open-loop sequence was computed). Generally speaking, the search for control \\textit{policies} makes the problem more difficult to solve, but is typically required in stochastic settings because uncertainty would lead to undesirable behavior under open-loop control plans. Specifically, in the stochastic decision making problem the policies $\\pi = \\{\\pi_0, \\dots, \\pi_{N-1}\\}$ are computed, which define the controls by $\\bu_k = \\pi_k(\\x_k)$.\n\nOf course the cost function is also modified to handle the uncertainty. In particular, a \\textit{risk-neutral} formulation is used (i.e. minimize the cost \\textit{on average}), where the cost is defined by the \\textit{expected} value:\n\\begin{equation} \\label{eq:scost}\nJ_\\pi(\\x_0) = E_{\\w} \\big[g_N(\\x_N) + \\sum_{k=0}^{N-1} g_k(\\x_k, \\pi(\\x_k), \\w_k)\\big],\n\\end{equation}\nwhere the expectation is over the stochastic variables $\\w$. The stochastic decision making problem can now be stated as:\n\\begin{definition}[Stochastic Decision Making Problem]\nThe stochastic decision making problem can be expressed for the system model \\eqref{eq:smodel}, control constraints \\eqref{eq:SDMPconstraints}, and cost function \\eqref{eq:scost} as:\n\\begin{equation} \\label{eq:sproblem}\nJ^*(\\x_0) = \\underset{\\pi}{\\min} \\:\\:J_{\\pi}(\\x_0).\n\\end{equation}\n\\end{definition}\n\n\n\\subsubsection{Principle of Optimality (Stochastic)}\nThe principle of optimality can again be applied in the stochastic setting, and the intuition is identical to the deterministic case (however the proof is slightly different because the reasoning is in terms of probability distributions). The principle of optimality in the stochastic setting is stated formally as:\n\\begin{theorem}[Principle of Optimality (Stochastic)]\nLet $\\pi^* = \\{\\pi_0^*, \\pi_1^* \\dots, \\pi_{N-1}^*\\}$ be an optimal policy for the stochastic decision making problem \\eqref{eq:sproblem}, and assume the state $\\x_k$ is reachable. Then, the tail policy sequence $\\{\\pi_k^*, \\dots, \\pi_{N-1}^*\\}$ is an optimal policy sequence when starting from $\\x_k$ to minimize the cost from time $k$ to time $N$.\n\\end{theorem}\nAgain, by leveraging the principle of optimality the decision making problem can be simplified to making immediate decisions by concatenating optimal tail policies.\n\n\\subsubsection{Dynamic Programming (Stochastic)}\nThe dynamic programming algorithm for the stochastic setting is also quite similar to DP for deterministic problems, and is given in Algorithm \\ref{alg:sDP}.\n\\begin{algorithm}[ht]\n $J_N(\\x_N) = g_n(\\x_N),$ for all $\\x_N$\\\\\n \\For{$k=N-1$ \\KwTo $0$}{\n  $J_k(\\x_k) = \\underset{\\bu_k \\in \\mathcal{U}(\\x_k)}{\\min}E_{\\w_k}\\big[g_k(\\x_k,\\bu_k,\\w_k) + J_{k+1}(f_k(\\x_k, \\bu_k, \\w_k))\\big],$ for all $\\x_k$\\\\\n }\n \\Return $J_0(\\cdot),\\dots,J_N(\\cdot)$\n \\caption{Dynamic Programming (Stochastic)}\n \\label{alg:sDP}\n\\end{algorithm}\nOnce Algorithm \\ref{alg:sDP} is run, the optimal policy is defined by:\n\\begin{equation*}\n\\pi^*_k(\\x_k) = \\underset{\\bu_k \\in \\mathcal{U}(\\x_k)}{\\arg \\min}E_{\\w_k}\\big[g_k(\\x_k,\\bu_k,\\w_k) + J_{k+1}(f_k(\\x_k, \\bu_k, \\w_k))\\big].\n\\end{equation*}\n\n\\begin{example}[Stochastic Dynamic Programming] \\label{ex:stoDP}\n\\theoremstyle{definition}\nConsider an inventory control problem, where the available stock of a particular item is the state $x_k \\in \\mathbb{N}$, the ability to add to the inventory is the control $u_k \\in \\mathbb{N}$, and the demand for the item is a stochastic variable $w_k \\in \\mathbb{N}$. The dynamics of the available stock is modeled as:\n\\begin{equation*}\nx_{k+1} = \\max \\{0, x_k + u_k - w_k\\},\n\\end{equation*}\nwhich models the fact that demand reduces available stock but can also never be negative. Additionally, consider the control constraints:\n\\begin{equation*}\nx_k + u_k \\leq 2,\n\\end{equation*}\nwhich limits the amount of additional inventory that can be added based on the current available stock to ensure that $x_k \\leq 2$.\nThe demand $w_k$ is assumed to be modeled probabilistically with a distribution:\n\\begin{equation*}\np(w_k=0) = 0.1, \\quad p(w_k = 1) = 0.7, \\quad p(w_k = 2) = 0.2.\n\\end{equation*}\nFinally, the cost is given for a horizon of $N=3$ as:\n\\begin{equation*}\nE\\big[\\sum_{k=0}^2 u_k + (x_k + u_k - w_k)^2 \\big],\n\\end{equation*}\nwhich penalizes ordering new stock at each time step and also having available stock at the next time step (i.e. having to store stock).\n\nThe dynamic programming algorithm can then be applied, starting with the end costs:\n\\begin{equation*}\nJ_3(x_3) = 0,\n\\end{equation*}\nand then recursively computing:\n\\begin{equation*}\n\\begin{split}\nJ_2(0) &= \\underset{u_2 \\in \\{0,1,2\\}}{\\min} E\\big[u_2 + (u_2 - w_2)^2  \\big] = \\underset{u_2 \\in \\{0,1,2\\}}{\\min} u_2 + 0.1u_2^2 + 0.7(u_2-1)^2 + 0.2(u_2 - 2)^2 = 1.3, \\\\\nJ_2(1) &= \\underset{u_2 \\in \\{0,1\\}}{\\min} E\\big[u_2 + (1 + u_2 - w_2)^2  \\big] = 0.3,\\\\\nJ_2(2) &= E\\big[(2 - w_2)^2  \\big] = 1.1, \\\\\n\\end{split}\n\\end{equation*}\nwhere the last cost is easily evaluated since the constraint makes $u_2 = 0$ the only feasible choice.\nThe optimal stage policies associated with this step are:\n\\begin{equation*}\n\\begin{split}\n\\pi^*_2(0) &= 1, \\\\ \n\\pi^*_2(1) &= 0, \\\\ \n\\pi^*_2(2) &= 0. \\\\ \n\\end{split}\n\\end{equation*}\nIn the next step:\n\\begin{equation*}\n\\begin{split}\nJ_1(0) &= \\underset{u_1 \\in \\{0,1,2\\}}{\\min} E\\big[u_1 + (u_1 - w_1)^2 + J_2(\\max\\{0, u_1 - w_1\\}) \\big] = 2.5, \\\\\nJ_1(1) &= \\underset{u_1 \\in \\{0,1,\\}}{\\min} E\\big[u_1 + (1 + u_1 - w_1)^2 + J_2(\\max\\{0, 1 + u_1 - w_1\\})  \\big] = 1.5,\\\\\nJ_1(2) &= E\\big[(2 - w_1)^2  + J_2(\\max\\{0, 2 - w_1\\}) \\big] = 1.68,\\\\\n\\end{split}\n\\end{equation*}\nwith optimal stage policies:\n\\begin{equation*}\n\\begin{split}\n\\pi^*_1(0) &= 1, \\\\ \n\\pi^*_1(1) &= 0, \\\\ \n\\pi^*_1(2) &= 0. \\\\ \n\\end{split}\n\\end{equation*}\nFinally, in the last step:\n\\begin{equation*}\n\\begin{split}\nJ_0(0) &= \\underset{u_0 \\in \\{0,1,2\\}}{\\min} E\\big[u_0 + (u_0 - w_0)^2 + J_1(\\max\\{0, u_0 - w_0\\}) \\big] = 3.7, \\\\\nJ_0(1) &= \\underset{u_0 \\in \\{0,1,\\}}{\\min} E\\big[u_0 + (1 + u_0 - w_0)^2 + J_1(\\max\\{0, 1 + u_0 - w_0\\})  \\big] = 2.7,\\\\\nJ_0(2) &= E\\big[(2 - w_0)^2  + J_1(\\max\\{0, 2 - w_0\\}) \\big] = 2.818,\\\\\n\\end{split}\n\\end{equation*}\nwith optimal stage policies:\n\\begin{equation*}\n\\begin{split}\n\\pi^*_0(0) &= 1, \\\\ \n\\pi^*_0(1) &= 0, \\\\ \n\\pi^*_0(2) &= 0. \\\\ \n\\end{split}\n\\end{equation*}\nInterestingly, the best scenario occurs with an initial stock of one, rather than have no stock or too much stock. Also, the policy ends up being the same at all time steps: if you have no stock you add one item, otherwise you do nothing.\n\\end{example}\n\n\\subsection{Challenges and Extensions of Dynamic Programming}\nDynamic programming is a powerful algorithm, but suffers from several practical considerations: the ``curse of dimensionality'', the ``curse of modeling'', and the ``curse of time''. The curse of dimensionality arises because of a exponential growth of the computational and storage requirements based on the dimension of the state. For example if the state has dimension one (i.e. $\\x \\in \\R$) and can take on 100 different values, then at each step of the algorithm the Bellman equation must be solved 100 times. While this may be possible from a practical perspective, if $\\x \\in \\R^3$ this would lead to $100^3$ solves of the Bellman equation! Additionally, extensions to the problems presented in this chapter where the full state is not \\textit{known} (e.g. because you can only measure some parts of the state), the problem also become intractable. The curse of modeling results from the complexity of modeling stochastic systems. In particular, it can be very hard to obtain expressions for transition probabilities for real world systems! Lastly, the curse of time is that the data of the problem may not be known ahead of time (such that the DP algorithm can be run offline). Therefore it may be required to solve the DP algorithm online when the data becomes available, or when the data changes and the problem needs to be resolved.\n\n\\subsubsection{Reinforcement Learning}\nThe practical challenges related to dynamic programming motivated the development of \\textit{suboptimal} dynamic programming approaches, which more commonly are referred to as \\textit{reinforcement learning} approaches. The goal of these approaches is to make \\textit{approximations} to the original problem that make it more practical for specific settings, such as with high-dimensional states, when the model is not known, and more. Broadly speaking, there are two main categories of approximations. The first category includes approximations in the value space (i.e. where the optimal cost function is approximated). The second category includes approximations in the policy space (i.e. where the policy is approximated by a neural network whose weights are optimized over).\n\n\n", "meta": {"hexsha": "967c44e31db20dfe67e618115a310fa104c83348", "size": 26421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch20.tex", "max_stars_repo_name": "StanfordASL/Principles-of-Robot-Autonomy", "max_stars_repo_head_hexsha": "852ce0fd1361d95576f72558d2c29d8610ced652", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-03-23T16:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T14:15:38.000Z", "max_issues_repo_path": "tex/source/ch20.tex", "max_issues_repo_name": "StanfordASL/Principles-of-Robot-Autonomy", "max_issues_repo_head_hexsha": "852ce0fd1361d95576f72558d2c29d8610ced652", "max_issues_repo_licenses": ["MIT"], "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/source/ch20.tex", "max_forks_repo_name": "StanfordASL/Principles-of-Robot-Autonomy", "max_forks_repo_head_hexsha": "852ce0fd1361d95576f72558d2c29d8610ced652", "max_forks_repo_licenses": ["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.198019802, "max_line_length": 1343, "alphanum_fraction": 0.7146209455, "num_tokens": 8186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6401435843321877}}
{"text": "\\chapter{Characters}\nCharacters are basically the best thing ever.\nTo every representation $V$ of $A$ we will attach a\nso-called character $\\chi_V : A \\to k$.\nIt will turn out that the characters of irreps of $V$\nwill determine the representation $V$ completely.\nThus an irrep is just specified by a set of $\\dim A$ numbers.\n\n\\section{Definitions}\n\\begin{definition}\n\tLet $V = (V, \\rho)$ be a finite-dimensional representation of $A$.\n\tThe \\vocab{character} $\\chi_V : A \\to k$ attached to\n\t$A$ is defined $\\chi_V = \\Tr \\circ \\rho$, i.e.\\\n\t\\[ \\chi_V(a) \\defeq \\Tr\\left( \\rho(a) : V \\to V \\right). \\]\n\\end{definition}\nSince $\\Tr$ and $\\rho$ are additive, this is a $k$-linear map\n(but it is not multiplicative).\nNote also that $\\chi_{V \\oplus W} = \\chi_V + \\chi_W$\nfor any representations $V$ and $W$.\n\nWe are especially interested in the case $A = k[G]$, of course.\nAs usual, we just have to specify $\\chi_V(g)$ for each\n$g \\in S_3$ to get the whole map $k[G] \\to k$.\nThus we often think of $\\chi_V$ as a function $G \\to k$,\ncalled a character of the group $G$.\nHere is the case $G = S_3$:\n\\begin{example}\n\t[Character table of $S_3$]\n\tLet's consider the three irreps of $G = S_3$ from before.\n\tFor $\\CC_{\\text{triv}}$ all traces are $1$;\n\tfor $\\CC_{\\text{sign}}$ the traces are $\\pm 1$ depending on sign\n\t(obviously, for one-dimensional maps $k \\to k$ the trace ``is''\n\tjust the map itself).\n\tFor $\\refl_0$ we take a basis $(1,0,-1)$ and $(0,1,-1)$, say,\n\tand compute the traces directly in this basis.\n\t\\[\n\t\t\\begin{array}{|r|rrrrrr|}\n\t\t\t\\hline\n\t\t\t\\chi_V(g) & \\id & (1\\;2) & (2\\;3) & (3\\;1) \n\t\t\t\t& (1\\;2\\;3) & (3\\;2\\;1)  \\\\ \\hline\n\t\t\t\\Ctriv & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n\t\t\t\\CC_{\\mathrm{sign}} & 1 & -1 & -1 & -1 & 1 & 1 \\\\\n\t\t\t\\refl_0 & 2 & 0 & 0 & 0 & -1 & -1 \\\\ \\hline\n\t\t\\end{array}\n\t\\]\n\\end{example}\nThe above table is called the \\vocab{character table} of the group $G$.\nThe table above has certain mysterious properties,\nwhich we will prove as the chapter progresses.\n\\begin{enumerate}[(I)]\n\t\\ii The value of $\\chi_V(g)$ only depends on the conjugacy class of $g$.\n\t\\ii The number of rows equals the number of conjugacy classes.\n\t\\ii The sum of the squares of any row is $6$ again!\n\t\\ii The ``dot product'' of any two rows is zero.\n\\end{enumerate}\n\n\\begin{abuse}\n\tThe name ``character'' for $\\chi_V : G \\to k$ is a bit of a misnomer.\n\tThis $\\chi_V$ is not multiplicative in any way,\n\tas the above example shows: one can almost think of it as\n\tan element of $k^{\\oplus |G|}$.\n\\end{abuse}\n\n\\begin{ques}\n\tShow that $\\chi_V(1_A) = \\dim V$,\n\tso one can read the dimensions of the representations\n\tfrom the leftmost column of a character table.\n\\end{ques}\n\n\\section{The dual space modulo the commutator}\nFor any algebra, we first observe that since $\\Tr(TS) = \\Tr(ST)$,\nwe have for any $V$ that\n\\[ \\chi_V(ab) = \\chi_V(ba). \\]\nThis explains observation (I) from earlier:\n\\begin{ques}\n\tDeduce that if $g$ and $h$ are in the same conjugacy class of a \n\tgroup $G$, and $V$ is a representation of $\\CC[G]$,\n\tthen $\\chi(g) = \\chi(h)$.\n\\end{ques}\nNow, given our algebra $A$ we define the \\vocab{commutator} $[A,A]$\nto be the (two-sided) ideal\\footnote{%\n\tThis means the ideal consists of sums elements of the form\n\t$a(xy-yx)b$ for $a,b \\in A$.\n}\ngenerated by elements of the form $xy-yx$.\nThus $[A,A]$ is contained in the kernel of each $\\chi_V$.\n\\begin{definition}\n\tThe space $A / [A,A]$ is called the \\vocab{abelianization} of $A$;\n\tfor brevity we denote it as $A\\ab$.\n\tWe think of this as ``$A$ modulo the relation $ab=ba$ for each $a,b \\in A$.''\n\\end{definition}\nSo we can think of each character $\\chi_V$ as an element of $(A\\ab)^\\vee$.\n\n\\begin{example}\n\t[Examples of abelianizations]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $A$ is commutative, then $[A,A] = \\{0\\}$\n\t\tand $A\\ab = A$.\n\t\t\\ii If $A = \\Mat_k(d)$, then $[A,A]$ consists exactly\n\t\tof the $d \\times d$ matrices of trace zero.\n\t\t(Proof: harmless exercise.)\n\t\tConsequently, $A\\ab$ is one-dimensional.\n\t\t\\ii Suppose $A = k[G]$.  We claim that $\\dim A\\ab$ is equal to the\n\t\tnumber of conjugacy classes of $A$.\n\t\tIndeed, an element of $A$ can be thought of as just \n\t\tan arbitrary function $\\xi : G \\to k$.\n\t\tSo an element of $A\\ab$ is a function $\\xi: G \\to k$ such that\n\t\t$\\xi(gh) = \\xi(hg)$ for every $g,h \\in G$.\n\t\tThis is equivalent to functions from conjugacy classes of $G$ to $k$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{theorem}\n\t[Character of representations of algebras]\n\tLet $A$ be an algebra over an algebraically closed field. Then\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Characters of pairwise non-isomorphic irreps are\n\t\tlinearly independent as elements of $A\\ab$.\n\t\t\\ii If $A$ is finite-dimensional and semisimple,\n\t\tthen the characters attached to irreps\n\t\tform a basis of $A\\ab$.\n\t\\end{enumerate}\n\tIn particular, in (b) the number of irreps of $A$ equals $\\dim A\\ab$.\n\\end{theorem}\n\\begin{proof}\n\tPart (a) is more or less obvious by the density theorem.\n\tSuppose there is a linear dependence, so that for every $a$ we have\n\t\\[ c_1 \\chi_{V_1}(a) + c_2 \\chi_{V_2}(a) + \\dots + c_r \\chi_{V_r} (a) = 0\\]\n\tfor some integer $r$.\n\t\\begin{ques}\n\t\tDeduce that $c_1 = \\dots = c_r = 0$ from the density theorem.\n\t\\end{ques}\n\tFor part (b), assume there are $r$ irreps\n\twe may assume that \\[ A = \\bigoplus_{i=1}^r \\Mat(V_i) \\]\n\twhere $V_1$, \\dots, $V_r$ are the irreps of $A$.\n\tSince we have already showed the characters are linearly independent\n\twe need only show that $\\dim ( A / [A,A] ) = r$,\n\twhich follows from the observation earlier that each $\\Mat(V_i)$\n\thas a one-dimensional abelianization.\n\\end{proof}\nSince $G$ has $\\dim \\CC[G]\\ab$ conjugacy classes,\nthis completes the proof of (II).\n\n\\section{Orthogonality of characters}\nNow we specialize to the case of finite groups $G$, represented over $\\CC$.\n\\begin{definition}\n\tLet $\\Classes(G)$ denote the set conjugacy classes of $G$.\n\\end{definition}\nIf $G$ has $r$ conjugacy classes, then it has $r$ irreps.\nEach (finite-dimensional) representation $V$, irreducible or not, gives a\ncharacter $\\chi_V$.\n\\begin{abuse}\n\tFrom now on, we will often regard $\\chi_V$ as a function $G \\to \\CC$\n\tor as a function $\\Classes(G) \\to \\CC$.\n\tSo for example, we will write both $\\chi_V(g)$ (for $g \\in G$)\n\tand $\\chi_V(C)$ (for a conjugacy class $C$);\n\tthe latter just means $\\chi_V(g_C)$ for any representative $g_C \\in C$.\n\\end{abuse}\n\\begin{definition}\n\tLet $\\FunCl(G)$ denote the set of functions $\\Classes(G) \\to \\CC$\n\tviewed as a vector space over $\\CC$.\n\tWe endow it with the inner form\n\t\\[\n\t\t\\left< f_1, f_2 \\right> = \n\t\t\\frac{1}{|G|}\n\t\t\\sum_{g \\in G} f_1(g) \\ol{f_2(g)}.\n\t\\]\n\\end{definition}\nThis is the same ``dot product'' that we mentioned at the beginning,\nwhen we looked at the character table of $S_3$.\nWe now aim to prove the following orthogonality theorem,\nwhich will imply (III) and (IV) from earlier.\n\\begin{theorem}[Orthogonality]\n\tFor any finite-dimensional complex representations $V$ and $W$\n\tof $G$ we have\n\t\\[ \\left< \\chi_V, \\chi_W \\right> = \\dim \\Homrep(W, V). \\]\n\tIn particular, if $V$ and $W$ are irreps then\n\t\\[ \\left< \\chi_V, \\chi_W \\right> \n\t\t=\n\t\t\\begin{cases}\n\t\t\t1 & V  \\cong W \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\\end{theorem}\n\\begin{corollary}[Irreps give an orthonormal basis]\n\tThe characters associated to irreps\n\tform an \\emph{orthonormal} basis of $\\FunCl(G)$.\n\\end{corollary}\n\nIn order to prove this theorem, we have to define\nthe dual representation and the tensor representation,\nwhich give a natural way to deal with the quantity $\\chi_V(g)\\ol{\\chi_W(g)}$.\n\\begin{definition}\n\tLet $V = (V, \\rho)$ be a representation of $G$.\n\tThe \\vocab{dual representation} $V^\\vee$ is the representation on $V^\\vee$\n\twith the action of $G$ given as follows: for each $\\xi \\in V^\\vee$,\n\tthe action of $g$ gives a $g \\cdot \\xi \\in V^\\vee$ specified by\n\t\\[ v \\xmapsto{g \\cdot \\xi} \\xi\\left( \\rho(g\\inv)(v) \\right). \\]\n\\end{definition}\n\\begin{definition}\n\tLet $V = (V, \\rho_V)$ and $W = (W, \\rho_W)$\n\tbe \\emph{group} representations of $G$.\n\tThe \\vocab{tensor product} of $V$ and $W$ is the group representation\n\ton $V \\otimes W$ with the action of $G$ given on pure tensors by\n\t\\[\n\t\tg \\cdot (v \\otimes w)\n\t\t= \n\t\t(\\rho_V(g)(v)) \\otimes (\\rho_W(g)(w)) \\]\n\twhich extends linearly to define the action of $G$ on all of $V \\otimes W$.\n\\end{definition}\n\\begin{remark}\n\tWarning: the definition for tensors does \\emph{not} extend to algebras.\n\tWe might hope that $a \\cdot (v \\otimes w) = (a \\cdot v) \\otimes (a \\cdot w)$\n\twould work, but this is not even linear in $a \\in A$\n\t(what happens if we take $a=2$, for example?).\n\\end{remark}\n\n\\begin{theorem}\n\t[Character traces]\n\tIf $V$ and $W$ are finite-dimensional representations of $G$,\n\tthen for any $g \\in G$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\chi_{V \\oplus W}(g) = \\chi_V(g) + \\chi_W(g)$.\n\t\t\\ii $\\chi_{V \\otimes W}(g) = \\chi_V(g) \\cdot \\chi_W(g)$.\n\t\t\\ii $\\chi_{V^\\vee}(g) = \\ol{\\chi_V(g)}$.\n\t\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n\tParts (a) and (b) follow from the identities\n\t$\\Tr(S \\oplus T) = \\Tr(S) + \\Tr(T)$\n\tand $\\Tr(S \\otimes T) = \\Tr(S) \\Tr(T)$.\n\tHowever, part (c) is trickier.\n\tAs $(\\rho(g))^{|G|} = \\rho(g^{|G|}) = \\rho(1_G) = \\id_V$\n\tby Lagrange's theorem, we can diagonalize $\\rho(g)$,\n\tsay with eigenvalues $\\lambda_1$, \\dots, $\\lambda_n$\n\twhich are $|G|$th roots of unity,\n\tcorresponding to eigenvectors $e_1$, \\dots, $e_n$.\n\tThen we see that in the basis $e_1^\\vee$, \\dots, $e_n^\\vee$,\n\tthe action of $g$ on $V^\\vee$ has eigenvalues\n\t$\\lambda_1\\inv$, $\\lambda_2\\inv$, \\dots, $\\lambda_n\\inv$.\n\tSo\n\t\\[\n\t\t\\chi_V(g) = \\sum_{i=1}^n \\lambda_i \\quad\\text{and}\\quad\n\t\t\\chi_{V^\\vee}(g) = \\sum_{i=1}^n \\lambda_i\\inv = \\sum_{i=1}^n \\ol{\\lambda_i}\n\t\\]\n\twhere the last step follows from the identity $|z|=1 \\iff z\\inv = \\ol z$.\n\\end{proof}\n\\begin{remark}\n\t[Warning]\n\tThe identities (b) and (c) do not extend linearly to $\\CC[G]$,\n\ti.e.\\ it is not true for example that $\\chi_V(a) = \\ol{\\chi_V(a)}$\n\tif we think of $\\chi_V$ as a map $\\CC[G] \\to \\CC$.\n\\end{remark}\n\\begin{proof}\n\t[Proof of orthogonality relation]\n\tThe key point is that we can now reduce\n\tthe sums of products to just a single character by\n\t\\[ \\chi_V(g) \\ol{\\chi_W(g)} = \\chi_{V \\otimes W^\\vee} (g). \\]\n\tSo we can rewrite the sum in question as just\n\t\\[\n\t\t\\left< \\chi_V, \\chi_W \\right>\n\t\t= \\frac{1}{|G|} \\sum_{g \\in G} \\chi_{V \\otimes W^\\vee} (g)\n\t\t= \\chi_{V \\otimes W^\\vee}\n\t\t\\left( \\frac{1}{|G|} \\sum_{g \\in G} g \\right).\n\t\\]\n\tLet $P : V \\otimes W^\\vee \\to V \\otimes W^\\vee$ be the\n\taction of $\\frac{1}{|G|} \\sum_{g \\in G} g$,\n\tso we wish to find $\\Tr P$.\n\t\\begin{exercise}\n\t\tShow that $P$ is idempotent.\n\t\t(Compute $P \\circ P$ directly.)\n\t\\end{exercise}\n\tHence $V \\otimes W^\\vee = \\ker P \\oplus \\img P$ (by \\Cref{prob:idempotent})\n\tand $\\img P$ is the subspace of elements which are fixed under $G$.\n\tFrom this we deduce that\n\t\\[ \\Tr P = \\dim \\img P =\n\t\t\\dim \\left\\{ x \\in V \\otimes W^\\vee\n\t\t\\mid g \\cdot x = x \\; \\forall g \\in G  \\right\\}.\n\t\t\\]\n\tNow, consider the natural isomorphism $V \\otimes W^\\vee \\to \\Hom(W, V)$.\n\t\\begin{exercise}\n\t\tLet $g \\in G$.\n\t\tShow that under this isomorphism, $T \\in \\Hom(W, V)$\n\t\tsatisfies $g \\cdot T = T$ if and only if\n\t\t$T(g \\cdot w) = g \\cdot T(w)$ for each $w \\in W$.\n\t\t(This is just unwinding three or four definitions.)\n\t\\end{exercise}\n\tConsequently, $\\chi_{V \\otimes W^\\vee}(P) = \\Tr P = \\dim \\Homrep(W,V)$\n\tas desired.\n\\end{proof}\n\nThe orthogonality relation gives us a fast and mechanical way to check\nwhether a finite-dimensional representation $V$ is irreducible.\nNamely, compute the traces $\\chi_V(g)$ for each $g \\in G$,\nand then check whether $\\left< \\chi_V, \\chi_V \\right> = 1$.\nSo, for example, we could have seen the three representations of\n$S_3$ that we found were irreps directly from the character table.\nThus, we can now efficiently verify any time we have\na complete set of irreps.\n\n\\section{Examples of character tables}\n\\begin{example}\n\t[Dihedral group on $10$ elements]\n\tLet $D_{10} = \\left< r,s \\mid r^5 = s^2 = 1, rs = sr\\inv \\right>$.\n\tLet $\\omega = \\exp(\\frac{2\\pi i}{5})$.\n\tWe write four representations of $D_{10}$:\n\t\\begin{itemize}\n\t\t\\ii $\\Ctriv$, all elements of $D_{10}$ act as the identity.\n\t\t\\ii $\\Csign$, $r$ acts as the identity while $s$ acts by negation.\n\t\t\\ii $V_1$, which is two-dimensional and given by\n\t\t$r \\mapsto \\begin{bmatrix} \\omega & 0 \\\\ 0 & \\omega^4 \\end{bmatrix}$\n\t\tand $s \\mapsto \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$.\n\t\t\\ii $V_2$, which is two-dimensional and given by\n\t\t$r \\mapsto \\begin{bmatrix} \\omega^2 & 0 \\\\ 0 & \\omega^3 \\end{bmatrix}$\n\t\tand $s \\mapsto \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}$.\n\t\\end{itemize}\n\tWe claim that these four representations are irreducible\n\tand pairwise non-isomorphic.\n\tWe do so by writing the character table:\n\t\\[\n\t\t\\begin{array}{|c|rccr|}\n\t\t\t\\hline\n\t\t\tD_{10} & 1 & r, r^4 & r^2, r^3 & sr^k \\\\ \\hline\n\t\t\t\\Ctriv & 1 & 1 & 1 & 1 \\\\\n\t\t\t\\Csign & 1 & 1 & 1 & -1 \\\\\n\t\t\tV_1 & 2 & \\omega+\\omega^4 & \\omega^2+\\omega^3 & 0 \\\\\n\t\t\tV_2 & 2 & \\omega^2+\\omega^3 & \\omega+\\omega^4 & 0 \\\\ \\hline\n\t\t\\end{array}\n\t\\]\n\tThen a direct computation shows the orthogonality relations,\n\thence we indeed have an orthonormal basis.\n\tFor example, $\\left< \\Ctriv, \\Csign \\right> = 1 + 2 \\cdot 1 + 2 \\cdot 1 + 5 \\cdot (-1) = 0$.\n\\end{example}\n\n\\begin{example}\n\t[Character table of $S_4$]\n\tWe now have enough machinery to to compute the character\n\ttable of $S_4$, which has five conjugacy classes\n\t(corresponding to cycle types $\\id$, $2$, $3$, $4$ and $2+2$).\n\tFirst of all, we note that it has two one-dimensional representations,\n\t$\\Ctriv$ and $\\Csign$, and these are the only ones\n\t(because there are only two homomorphisms $S_4 \\to \\CC^\\times$).\n\tSo thus far we have the table\n\t\\[\n\t\t\\begin{array}{|c|rrrrr|}\n\t\t\t\\hline\n\t\t\tS_4 & 1 & (\\bullet\\;\\bullet) & (\\bullet\\;\\bullet\\;\\bullet)\n\t\t\t\t& (\\bullet\\;\\bullet\\;\\bullet\\;\\bullet)\n\t\t\t\t& (\\bullet\\;\\bullet)(\\bullet\\;\\bullet)\n\t\t\t\t\\\\ \\hline\n\t\t\t\\Ctriv & 1 & 1 & 1 & 1 & 1 \\\\\n\t\t\t\\Csign & 1 & -1 & 1 & -1 & 1 \\\\ \n\t\t\t\\vdots & \\multicolumn{5}{|c|}{\\vdots}\n\t\t\\end{array}\n\t\\]\n\tNote the columns represent $1+6+8+6+3=24$ elements.\n\n\tNow, the remaining three representations have dimensions\n\t$d_1$, $d_2$, $d_3$ with\n\t\\[ d_1^2 + d_2^2 + d_3^2 = 4! - 2 = 22 \\]\n\twhich has only $(d_1, d_2, d_3) = (2,3,3)$ and permutations.\n\tNow, we can take the $\\refl_0$ representation\n\t\\[ \\left\\{ (w,x,y,z) \\mid w+x+y+z=0 \\right\\} \\]\n\twith basis $(1,0,0,-1)$, $(0,1,0,-1)$ and $(0,0,1,-1)$.\n\tThis can be geometrically checked to be irreducible,\n\tbut we can also do this numerically by computing the\n\tcharacter directly (this is tedious):\n\tit comes out to have $3$, $1$, $0$, $-1$, $-1$\n\twhich indeed gives norm\n\t\\[\n\t\t\\left< \\chi_{\\refl_0}, \\chi_{\\refl_0} \\right>\n\t\t=\n\t\t\\frac{1}{4!}\n\t\t\\left( \n\t\t\t\\underbrace{3^2}_{\\id}\n\t\t\t+ \\underbrace{6\\cdot(1)^2}_{(\\bullet\\;\\bullet)}\n\t\t\t+ \\underbrace{8\\cdot(0)^2}_{(\\bullet\\;\\bullet\\;\\bullet)}\n\t\t\t+ \\underbrace{6\\cdot(-1)^2}_{(\\bullet\\;\\bullet\\;\\bullet\\;\\bullet)}\n\t\t\t+ \\underbrace{3\\cdot(-1)^2}_{(\\bullet\\;\\bullet)(\\bullet\\;\\bullet)}\n\t\t\\right)\n\t\t= 1.\n\t\\]\n\tNote that we can also tensor this with the sign representation,\n\tto get another irreducible representation\n\t(since $\\Csign$ has all traces $\\pm 1$, the norm doesn't change).\n\tFinally, we recover the final row using orthogonality\n\t(which we name $\\CC^2$, for lack of a better name);\n\thence the completed table is as follows.\n\t\\[\n\t\t\\begin{array}{|c|rrrrr|}\n\t\t\t\\hline\n\t\t\tS_4 & 1 & (\\bullet\\;\\bullet) & (\\bullet\\;\\bullet\\;\\bullet)\n\t\t\t\t& (\\bullet\\;\\bullet\\;\\bullet\\;\\bullet)\n\t\t\t\t& (\\bullet\\;\\bullet)(\\bullet\\;\\bullet)\n\t\t\t\t\\\\ \\hline\n\t\t\t\\Ctriv & 1 & 1 & 1 & 1 & 1 \\\\\n\t\t\t\\Csign & 1 & -1 & 1 & -1 & 1 \\\\ \n\t\t\t\\CC^2 & 2 & 0 & -1 & 0 & 2 \\\\ \n\t\t\t\\refl_0 & 3 & 1 & 0 & -1 & -1 \\\\\n\t\t\t\\refl_0 \\otimes \\Csign & 3 & -1 & 0 & 1 & -1 \\\\\\hline\n\t\t\\end{array}\n\t\\]\n\\end{example}\n\n\\section\\problemhead\n\n\\begin{dproblem}\n\t[Reading decompositions from characters]\n\tLet $W$ be a complex representation of a finite group $G$.\n\tLet $V_1$, \\dots, $V_r$ be the complex irreps of $G$\n\tand set $n_i = \\left< \\chi_W, \\chi_{V_i} \\right>$.\n\tProve that each $n_i$ is a non-negative integer and\n\t\\[ W = \\bigoplus_{i=1}^r V_i^{\\oplus n_i}. \\]\n\t\\begin{hint}\n\t\tObvious.\n\t\tLet $W = \\bigoplus V_i^{m_i}$ (possible since $\\CC[G]$ semisimple)\n\t\tthus $\\chi_W = \\sum_i m_i \\chi_{V_i}$.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\tConsider complex representations of $G = S_4$.\n\tThe representation $\\refl_0 \\otimes \\refl_0$\n\tis $9$-dimensional, so it is clearly reducible.\n\tCompute its decomposition in terms of the five\n\tirreducible representations.\n\t\\begin{hint}\n\t\tUse the previous problem, with $\\chi_W = \\chi_{\\refl_0}^2$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\t$\\Csign \\oplus \\CC^2 \\oplus \\refl_0 \\oplus (\\refl_0\\otimes\\Csign)$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Tensoring by one-dimensional irreps]\n\tLet $V$ and $W$ be irreps of $G$, with $\\dim W = 1$.\n\tShow that $V \\otimes W$ is irreducible.\n\t\\begin{hint}\n\t\tCharacters. Note that $|\\chi_W| = 1$ everywhere.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFirst, observe that $|\\chi_W(g)|=1$ for all $g \\in G$.\n\t\t\\begin{align*}\n\t\t\t\\left< \\chi_{V \\otimes W}, \\chi_{V \\otimes W} \\right>\n\t\t\t&= \\left< \\chi_V \\chi_W, \\chi_V \\chi_W \\right> \\\\\n\t\t\t&= \\frac{1}{|G|} \\sum_{g \\in G} \n\t\t\t\\left\\lvert \\chi_V(g) \\right\\rvert^2\n\t\t\t\\left\\lvert \\chi_W(g) \\right\\rvert^2 \\\\\n\t\t\t&= \\frac{1}{|G|} \\sum_{g \\in G} \n\t\t\t\\left\\lvert \\chi_V(g) \\right\\rvert^2 \\\\\n\t\t\t&= \\left< \\chi_V, \\chi_V \\right> = 1.\n\t\t\\end{align*}\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Quaternions]\n\tCompute the character table of the quaternion group $Q_8$.\n\t\\begin{hint}\n\t\tThere are five conjugacy classes, $1$, $-1$\n\t\tand $\\pm i$, $\\pm j$, $\\pm k$.\n\t\tGiven four of the representations, orthogonality\n\t\tcan give you the fifth one.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe table is given by\n\t\t\\[\n\t\t\t\\begin{array}{|c|rrrrr|}\n\t\t\t\t\\hline\n\t\t\t\tQ_8 & 1 & -1 & \\pm i & \\pm j & \\pm k \\\\ \\hline\n\t\t\t\t\\Ctriv & 1 & 1 & 1 & 1 & 1 \\\\\n\t\t\t\t\\CC_i & 1 & 1 & 1 & -1 & -1 \\\\\n\t\t\t\t\\CC_j & 1 & 1 & -1 & 1 & -1 \\\\\n\t\t\t\t\\CC_k & 1 & 1 & -1 & -1 & 1 \\\\\n\t\t\t\t\\CC^2 & 2 & -2 & 0 & 0 & 0 \\\\\\hline\n\t\t\t\\end{array}\n\t\t\\]\n\t\tThe one-dimensional representations (first four rows)\n\t\tfollows by considering the homomorphism $Q_8 \\to \\CC^\\times$.\n\t\tThe last row is two-dimensional and can be recovered\n\t\tby using the orthogonality formula.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{sproblem}\n\t[Second orthogonality formula]\n\t\\label{prob:second_orthog}\n\t\\gim\n\tLet $g$ and $h$ be elements of a finite group $G$,\n\tand let $V_1$, \\dots, $V_r$ be the irreps of $G$.\n\tProve that\n\t\\[\n\t\t\\sum_{i = 1}^r \\chi_{V_i}(g) \\ol{\\chi_{V_i}(h)}\n\t\t=\n\t\t\\begin{cases}\n\t\t\t|C_G(g)| & \\text{if $g$ and $h$ are conjugates} \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\tHere, $C_G(g) = \\left\\{ x \\in G : xg = gx \\right\\}$\n\tis the centralizer of $g$.\n\t\\begin{hint}\n\t\tWrite as \n\t\t\\[ \\sum_{i=1}^r \\chi_{V_i \\otimes V_i^\\vee} (gh\\inv)\n\t\t\t= \\chi_{\\bigoplus_i V_i \\otimes V_i^\\vee}(gh\\inv)\n\t\t\t= \\chi_{\\CC[G]}(gh\\inv).\n\t\t\\]\n\t\tNow look at the usual basis for $\\CC[G]$.\n\t\\end{hint}\n\\end{sproblem}\n", "meta": {"hexsha": "c3a4e316c46fec9601bda061fee2efc2b9703081", "size": 18897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/rep-theory/characters.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/characters.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/characters.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.7645914397, "max_line_length": 93, "alphanum_fraction": 0.6415304017, "num_tokens": 7009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.6401435662795332}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage{amsmath}\n\n\\title{Some Informal Notes for Radiative Transfer Code}\n\\author{Mark Baum}\n\n\\begin{document}\n\n\\small\n\n\\maketitle\n\n\\section*{Pressure Coordinates}\n\nGet pressure coordinates by using the hydrostatic relation,\n\\begin{equation}\n\t\\frac{dP}{dz} = -\\rho g \\, ,\n\\end{equation}\nto replace $dz$ wherever it appears,\n\\begin{equation}\n\tdz = -\\frac{dP}{\\rho g} \\, .\n\\end{equation}\nConsider optical depth\n\\begin{equation}\n\t\\tau\t = \\int \\sigma N dz \\, ,\n\\end{equation}\nwhere $\\sigma$ is the absorption cross-section (m$^2$/molecule) and $N$ is the number density of the absorber (molecules/m$^3$). Switching to pressure coordinates yields\n\\begin{equation}\n\t\\tau\t = \\int \\sigma N \\frac{1}{\\rho g} dP \\, .\n\t\\label{tau}\n\\end{equation}\nThen the ideal gas law can be used to substitute for both $N$ and $\\rho$.\n\\begin{align}\n\tN &= \\frac{P}{k_B T} \\\\[1ex]\n\t\\rho &= \\frac{P \\mu}{k_B T N_A}\n\\end{align}\nwhere $\\mu$ is the molar mass in kg/mole and $N_A$ is Avogadro's number. Because we have $N/\\rho$ above in equation (\\ref{tau}) for optical depth, lots of things cancel.\n\\begin{equation}\n\t\\frac{N}{\\rho} = \\frac{P}{k_B T} \\frac{k_B T N_A}{P \\mu} = \\frac{N_A}{\\mu}\n\\end{equation}\nPutting this into equation (\\ref{tau}),\n\\begin{equation}\n\t\\tau = \\int \\sigma \\frac{N_A}{\\mu g} dP \\, .\n\\end{equation}\nThe negative sign in the original $dz=-dP/\\rho g$ has been dropped for convenience. Obviously, the optical depth must be positive, so the coordinate switch probably brings in another negative sign, perhaps when integral limits are switched because low pressure is high altitude and vice versa.\n\nThe same steps apply to the closely related Schwarzschild equation,\n\\begin{equation}\n\tdI = \\sigma N [B_{\\nu}(T) - I] dz \\, ,\n\\end{equation}\nexpressed here in differential form. We have the same $N dz$ factor that, through the hydrostatic relation and ideal gas law, gets replaced by $N_A/\\mu g$.\n\\begin{equation}\n\tdI = \\sigma\t\\frac{N_A}{\\mu g} [B_{\\nu}(T) - I] dP \\, .\n\\end{equation}\nImportant to remember that the molar mass here has units of kg/mole.\n\n\\section*{log Pressure Coordinates}\n\nSometimes there is a case for very high resolution in the upper atmosphere, per unit mass. To get that, log pressure coordinates can be used, which is essentially the same as using altitude directly but lets you keep the equations in terms of $P$. The same steps from above are applied, with one more. Simply use\n\\begin{equation}\n\t\\frac{1}{P} dP = d\\ln P\n\\end{equation}\nor, rearranged\n\\begin{equation}\n\tdP = P d\\ln P \\, .\n\\end{equation}\nPutting this into the optical depth and Schwarzschild equations,\n\\begin{align}\n\t\\tau\t &= \\int \\sigma N \\frac{1}{\\rho g} P d\\ln P \\\\[1em]\n\tdI &= \\sigma\t\\frac{N_A}{\\mu g} [B_{\\nu}(T) - I] P d\\ln P \\, .\n\\end{align}\nIt's the same as pressure coordinates, but multiplied by $P$. Then, of course, these equations must be integrated with the appropriate limits, $\\ln(P_{\\textrm{s}})$ and $\\ln(P_{\\textrm{toa}})$. Its important to consistently use the natural log, not log$_{10}$.\n\n\\section*{Integrating Multiple Streams}\n\nIn the absence of scattering, the total flux up or down in the atmosphere must account for irradiance at all angles in the hemisphere pointing up/down.\n\\begin{equation}\n\tF = \\int_0^{2\\pi} \\int_0^{\\pi/2} I(\\theta\t,\\phi) \\cos(\\theta) \\sin(\\theta) d\\theta d\\phi \\, ,\n\\end{equation}\nwhere $\\theta$ is the azimuthal angle (zero is straight up/down), $\\phi$ is the ``latitude\" angle going around the whole hemisphere. The cosine factor accounts for the angle of $I$ with respect to the horizontal planar surface that the flux is passing through. The sine factor simply comes out of the spherical integration, accounting for area attenuation near the very top of the hemisphere.\n\nAssuming streams are identical with respect to the latitude angle $\\phi$, that dimension is trivial to integrate.\n\\begin{equation}\n\tF = 2\\pi\t \\int_0^{\\pi/2} I(\\theta) \\cos(\\theta) \\sin(\\theta) d\\theta\n\\end{equation}\nThe azimuthal dimension generally must be integrated numerically. $I$ should be quite smooth with respect to $\\theta$, so gaussian integration is a good way to do it. The flux is then\n\\begin{equation}\n\tF = 2\\pi \\sum_{i=0}^N I(\\theta_i) w_i \\cos(\\theta_i) \\sin(\\theta_i)\n\\end{equation}\nwhere $\\theta_i$ are the gaussian quadrature nodes mapped to $[0,\\pi/2]$ and $w_i$ are the appropriately scaled weights. For a given number of streams $N$, one can precompute the factors $2\\pi w_i \\cos(\\theta_i) \\sin(\\theta_i)$.\n\n\\end{document}", "meta": {"hexsha": "60f9a48701c44ee61f7405931b84e78498624815", "size": 4484, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/notes.tex", "max_stars_repo_name": "markmbaum/ClearSky.jl", "max_stars_repo_head_hexsha": "84e8aec24a648dd7ebbef4c8d1f743bb2669a47d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-31T18:12:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T18:12:56.000Z", "max_issues_repo_path": "notes/notes.tex", "max_issues_repo_name": "wordsworthgroup/ClearSky.jl", "max_issues_repo_head_hexsha": "84e8aec24a648dd7ebbef4c8d1f743bb2669a47d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-23T20:42:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-23T20:42:44.000Z", "max_forks_repo_path": "notes/notes.tex", "max_forks_repo_name": "wordsworthgroup/ClearSky.jl", "max_forks_repo_head_hexsha": "84e8aec24a648dd7ebbef4c8d1f743bb2669a47d", "max_forks_repo_licenses": ["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.7391304348, "max_line_length": 392, "alphanum_fraction": 0.721677074, "num_tokens": 1352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6401435633790977}}
{"text": "\\section{Jinchao's inputs}\n\n\\subsection{Classification versus regression}\nClassification is a special form of regression.   Basically, it tries to find the (continuous) boundary of domains (that contain different clusters of data)\n\n\\subsection{Overfitting}\n\nIt seems to be related to the Runge phenomenon in polynomial interpolation for non-analytic function.  It would be interesting to study, theoretically, whether deep neural network also has Runge phenomenon.  \n\n\\subsection{CNN versus multigrid}\n$$\nAu=f\n$$\n\n\\paragraph{Multigrid}\n\nWe know $f$, then try to find $u$.\n\nWe have multilevel\n\nWe also use average, namely convolution, which is smoother:\n\n\\begin{itemize}\n\\item filter out the high frequencies\n\\end{itemize}\n\n\\paragraph{CNN}\nWe know $u$, then try to find $f$.  In order to find $f$, we have to find $A$ first. \n\nWe use ``finite difference'', namely convolution, which is ``rougher''.\n\\begin{itemize}\n\\item filter out the low frequencies\n\\end{itemize}\n\n\n\\subsection{Role of probability theory and tool}\n\nThe role of probability is important for sure, but it is not essential .... \n\nIn the idealistic situation, namely all the data are good, no noise etc, we can approach deep learning problem without relying on probability theory and tools.\n\nTo understand the essence of deep learning, can we first skip probability tool?\n\nIf we skip probability, how much do we miss?   We would not miss very much for the understanding how and why DNN works. \n\n\\begin{itemize}\n\\item High school probability is enough.\n\\end{itemize}\n\n", "meta": {"hexsha": "878f86a3271dc21f2be3fde53fe9ae2a6b7b5a55", "size": 1531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/jinchao.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/jinchao.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/jinchao.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": 30.62, "max_line_length": 208, "alphanum_fraction": 0.7668190725, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.640143554027749}}
{"text": "\\documentclass{notes}\n\n  \\title{Computability}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \n\n  \n\n    \\section*{Natural numbers}\n    \\begin{align*}\n      \\mathbb{N}    &= \\{ 1, 2, 3, 4, \\ldots \\} \\\\\n      \\mathbb{N}_0  &= \\{ 0, 1, 2, 3, \\ldots \\} \\\\\n      2\\mathbb{N}_0 &= \\{ 0, 2, 4, 6, \\ldots \\} \\\\\n      3\\mathbb{N}_0 &= \\{ 0, 3, 6, 9, \\ldots \\} \\\\\n      \\mathbb{Z}    &= \\{ \\ldots, -2, -1, 0, 1, 2, \\ldots \\} \\\\\n    \\end{align*}\n    \n    \\section*{Real numbers}\n    \n    \\begin{center}\n    \\begin{tikzpicture}\n        % https://tex.stackexchange.com/a/148253\n        \\draw[latex-latex] (-1.5,0) -- (3.5,0) ; %edit here for the axis\n        \n        \\draw[shift={(0,0)},color=black]    (0pt,3pt) -- (0pt,-3pt);\n        \\draw[shift={(1,0)},color=black]    (0pt,3pt) -- (0pt,-3pt);\n        \\draw[shift={(1.41,0)},color=black] (0pt,3pt) -- (0pt,-3pt);\n        \\draw[shift={(3.12,0)},color=black] (0pt,3pt) -- (0pt,-3pt);\n        \n        \\draw[shift={(0,0)},color=black]    (0pt,-3pt) -- (0pt,0pt) node[above] {$0$};\n        \\draw[shift={(1,0)},color=black]    (0pt,-3pt) -- (0pt,0pt) node[above] {$1$};\n        \\draw[shift={(1.41,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] {$\\sqrt{2}$};\n        \\draw[shift={(3.14,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] {$\\pi$};\n        %\\draw[very thick] (,0) -- (1.92,0);\n    \\end{tikzpicture}\n    \\end{center}\n\n    \\noindent Real numbers are difficult to define:\n    \\begin{enumerate}\n        \\item Draw an infinite\n        straight line.\n        \\item Mark two distinct points.\n        \\item Call the left-most 0, the right-most 1.\n        \\item One unit is the length between 0 and 1.\n        \\item Mark any point on the line and measure its length $x$ in units from 0.\n    \\end{enumerate}\n    Then $x$ is a real number.\n    The set $\\mathbb{R}$ is the set of all such $x$'s.\n  \n    \\section*{Bijections}\n    \n    \\[ f: \\mathbb{N}_0 \\rightarrow 2\\mathbb{N}_0 : n \\rightarrow 2n  \\]\n    \n    \\begin{align*}\n        f(0) &= 0 \\\\\n        f(1) &= 2 \\\\\n        f(2) &= 4 \\\\\n        f(3) &= 6 \\\\\n        \\vdots \\\\\n    \\end{align*}\n    \n    \\noindent\n    Every element of $\\mathbb{N}_0$ is mapped to a different element of $2\\mathbb{N}_0$.\n    For instance, $1$ is the only number mapped to $2$.\n    \n    Also, every element of $2 \\mathbb{N}_0$ is mapped to from some element of $\\mathbb{N}_0$.\n    There's no element of $2 \\mathbb{N}_0$ that isn't the image of some element of $\\mathbb{N}_0$.\n    \n    There are lots of functions like $f$ to and from each of the sets $\\mathbb{N}, \\mathbb{N}_0, \\mathbb{Z}$ and so on, but there is none to $\\mathbb{R}$.\n    \n    \\section*{Diagonilsation}\n    \n    Suppose there was a map $f: \\mathbb{N}_0 \\rightarrow \\mathbb{R}$.\n    List out each element $n$ of $\\mathbb{N}_0$ with $f(n)$ beside it with all of the decimal places displayed.\n    For example, suppose the first few are as follows.\n    \n    \\begin{alignat*}{2}\n        0 & \\quad \\rightarrow \\quad &   0&.16346234234234 \\ldots \\\\\n        1 & \\quad \\rightarrow \\quad &  10&.56775344747474 \\ldots \\\\\n        2 & \\quad \\rightarrow \\quad & 214&.99999999999999 \\ldots \\\\\n        3 & \\quad \\rightarrow \\quad &  -1&.33333333333333 \\ldots \\\\\n        4 & \\quad \\rightarrow \\quad &   0&.00000000000000 \\ldots \\\\\n          & \\quad \\;\\; \\vdots    \\quad &    &                   \\\\\n    \\end{alignat*}\n\n    While the list contains all of the natural numbers $\\mathbb{N}_0$, we can show that it can't possibly contain all of the real numbers $\\mathbb{R}$.\n    We'll use Cantor's diagonal argument to construct a real number not in the list.\n    \n    Start by constructing a new number $0.$ and add decimal places as follows.\n    Take the digit in the first decimal place of the first real number in the list.\n    The first real number is $0.1634\\ldots$ so the first decimal place contains a $1$.\n    Add $1$ to this number, giving $2$, and use this as the digit in the first decimal place of our new number: $0.2$.\n    \n    Next add 1 to the digit in the second decimal place of the second real number.\n    That gives 6, so the digit in the second decimal place of our new number is $6$, giving $0.26$ so far.\n    Keep going down the list, adding one to each successive decimal place in each successive number.\n    Any time you encounter $9$, adding $1$ would give $10$, so replace the $9$ with $0$ instead.\n    That happens for the third real number in the list, so our new number becomes $0.260$ at that point.\n    \n    The new number differs from the first real number in the list in the first decimal place, the second real number in the second decimal place and so on.\n    Therefore, the new number is not in the list --- so the list can't contain all real numbers.\n    We have to conclude that the real numbers were not and can not be paired up with the natural numbers.\n    \n    \\section*{Computable numbers}\n    Cantor's argument has profound implications for what a computer can do.\n    Each file on a computer is stored in binary -- a string over the alphabet $\\{ 0, 1 \\}$.\n    The possible files are then $\\{ 0 , 1 \\}^* = \\{ \\epsilon, 0, 1, 00, 01, 10, 11, 000, \\ldots \\}$.\n    We can pair $\\mathbb{N}_0$ up with $\\{ 0 , 1 \\}^*$ using that listing: $0 \\rightarrow \\epsilon$, $1 \\rightarrow 0$, $2 \\rightarrow 1$, $3 \\rightarrow 00$, and so on.\n    \n    Executables are just files.\n    Consider an executable that prints a real number to the screen.\n    For instance, we could write a program to print $0.0000\\ldots$ to the screen where it just keeps printing $0$'s.\n    It's printing the real number $0$.\n    For any given real number, is there a program to print it out?\n    There must be real numbers for which no such program exists -- because there are less possible programs than real numbers.\n    \n    Computers can't even print all numbers out.\n    \n\n  \\bibliography{bibliography}\n\\end{document}\n", "meta": {"hexsha": "8adff9b7d259311a46d87b3b418b9ba780152eb7", "size": 5879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "computability.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": "computability.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": "computability.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": 46.6587301587, "max_line_length": 169, "alphanum_fraction": 0.612178942, "num_tokens": 1897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8175744761936438, "lm_q1q2_score": 0.6398848745556435}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amsmath}\n\\usepackage{xcolor}\n\\usepackage{titlesec}\n\\usepackage{listings}\n\\usepackage{syntax}\n\\usepackage{pythonhighlighting}\n\\usepackage{fancyvrb}\n\n\\usepackage{graphicx}\n\n\\graphicspath{ {./assets/} }\n\n\\usepackage[margin=1.4in]{geometry}\n\n\\title{Homework \\#3 | Fall 2021} \n\\author{Jared Dyreson\\\\ \n        California State University, Fullerton}\n\n\\DeclareRobustCommand{\\bowtie}{%\n  \\mathrel\\triangleright\\joinrel\\mathrel\\triangleleft}\n\n\n\\usepackage [english]{babel}\n\\usepackage [autostyle, english = american]{csquotes}\n\\MakeOuterQuote{\"}\n\n\\titlespacing*{\\section}\n{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}\n\\titlespacing*{\\subsection}\n{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}\n\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks,\n    citecolor=black,\n    filecolor=black,\n    linkcolor=black,\n    urlcolor=black\n}\n\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\n\\newpage\n\n\n\\section{Questions}\n\n\\subsection{Offline Ski Rental}\n\n\\subsubsection{Problem Description}\n\n\\begin{table}[!h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\textbf{input} & a daily ski rental price $r > 0$, purchase price $p > 0$, and number of days $d > 0$ \\\\ \\hline\n\\textbf{output} & \\begin{tabular}[c]{@{}l@{}}True if it is cheaper to rent skis for d days at r dollars per day, or False if it is\\\\ cheaper to buy skis for p dollars\\end{tabular} \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\subsubsection{Pseudocode}\n\n\\begin{verbatim}\nfunction ski(int rate, int purchasePrice, int days):\n    rental_total = rate * days\n    return rental_total < purchasePrice\n\\end{verbatim}\n\n\\subsubsection{Time Complexity}\n\nThis function is quite simple, as we are given all the information up front.\nEach operation we have will complete in a time complexity of $O(1)$.\nTherefore, the best/worst case of this is $O(1)$.\n\n\\subsubsection{Implementation}\n\n\\begin{python}\n\ndef solution(rental_price: int,\n             purchase_price: int, days: int) -> bool:\n\n    return (rental_price * days) < purchase_price\n\\end{python}\n\n\\newpage\n\n\\subsection{List Reversal}\n\n\\subsubsection{Problem Description}\n\n\\begin{table}[!h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\textbf{input} & a list L of n elements \\\\ \\hline\n\\textbf{output} & a list containing the elements of L but in reversed order \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\subsubsection{Pseudocode}\n\n\\begin{verbatim}\nfunction reverse(container):\n    last_index = container.length # O(1)\n    for element in container: # O(n)\n        swap(element, container[last_index]) # O(1)\n        last_index = last_index - 1 # O(1)\n    return container # O(1)\n\\end{verbatim}\n\n\\subsubsection{Time Complexity}\n\nThis function will modify the container in place and does not create a copy.\nOther variants can leave the original container intact and return a reversed copy.\nThe benefit of this would be data integrity, however, that is at the expense of having to have duplicate data.\nWe need to iterate over the entire container of \"n\" elements and we assume the swap function is of constant time.\nTherefore, time complexity of this function is linear, or $O(n)$.\n\\subsubsection{Implementation}\n\n\\begin{python}\ndef solution(container: list) -> list:\n    end = len(container) - 1\n    for x, _ in enumerate(container):\n        if x < end:\n            container[x], container[end] = container[end], container[x]\n            end -= 1\n    return container\n\\end{python}\n\n\\newpage\n\n\\subsection{Pythagorean Triple}\n\n\\subsubsection{Problem Description}\n\\begin{table}[!h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\textbf{input} & two positive integers; $a$ and $b$ with $a < b$ \\\\ \\hline\n\\textbf{output} & \\begin{tabular}[c]{@{}l@{}}a Pythagorean triple (x, y, z), such that $x$, $y$, and $z$ are positive integers,\\\\ $a \\le x \\le y \\le z \\le b$ and $x^{2} + y^{2} = z^{2}$, or None if no such triples exist\\end{tabular}\\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\subsubsection{Pseudocode}\n\n\\begin{verbatim}\nfunction validator(tuple[int, int, int] triplet):\n    x, y, z = triplet # O(3), assignment and unpacking for three elements\n    return z == square_root(x ** 2 + y ** 2) and x <= y <= z\n    # O(n) <- for the squaring of x and y. This is building off the previous\n    # assumption made in Project 2 for the Fibonacci sequence\n\nfunction pythagorean_triples(int a /* lower bound */, int b /* upper bound */):\n    candidates = [] # O(1)\n    for x in range(a, b + 1): # get range of values, bounded by a and b # O(n)\n        candidates.append(x) # O(1)\n    # create all permutations\n    # description does not specifically instruct to create an algorithm\n    # to create these permutations, therefore we use the best case\n    # of O(n^r), where r represents the length of the tuple -> O(n^3)\n    permutations = generate_permutations(iterable=candidates, r=3) # O(n^3)\n    # this is the function signature of itertools.combinations\n    valid_triplets = [] # O(1)\n\n    # this for loop block runs in O(n^2)\n    for permuation in permutations: # O(n)\n        if(validator(permuation)): # O(n)\n            valid_triplets.append(permutation) # O(1)\n    return valid_triplets # O(1)\n\\end{verbatim}\n\n\\subsubsection{Time Complexity}\n\nThe main portion of this algorithm comes solely from creating all possible combinations the range presents.\nHere, we are tasked with creating triplets, given a range of numbers $a$ and $b$.\nThe creation of all possible combinations will take $O(n^{r})$, where $r$ is the length of the container you're producing.\nTherefore in our case it is $O(n^{3})$ and more information regarding this can be found in \\href{https://stackoverflow.com/a/20765011}{\\underline{this StackOverflow comment thread}}.\nAll of these triplets need to then be processed by our validator function, which was defined in the problem description.\nThese validations will occur in $O(n)$ time, because we are assuming raising a number to a given power will take that time complexity.\nIt is disputed in implementations in Python, either $O(1)$ or $O(n)$ and since a previous homework assignment uses the latter, we will go with this assumption.\nOverall, the time complexity will be of $O(n^{3})$, as it the leading term in the polynomial $O(n^{3}) + O(n^{2})$.\n\n\n\\newpage\n\n\\subsubsection{Implementation}\n\n\\begin{python}\nimport itertools\nimport math\n\ndef validator(container: tuple[int, int, int]) -> bool:\n    x, y, z = container  # raise ValueError if container len != 3\n    # x ^ 2 + y ^ 2 = z ^ 2\n    # where x, y and z are perfect squares\n    return z == math.sqrt(x ** 2 + y ** 2) and x <= y <= z\n\ndef solution(integers: tuple[int, int]) -> list[tuple[int, int, int]]:\n    a, b = integers  # a is lower bound and b is upper bound\n    if not(isinstance(a, int)\n           and isinstance(b, int)\n           and a < b):\n        raise ValueError(\n            f'[ERROR] Expected integers for `a` ({a}) and `b` ({b}), where a < b')\n    candidates = [_ for _ in range(a, b+1)]\n    \"\"\"\n    Given a = 1 and b = 4\n    - (1, 2, 3)\n    - (2, 3, 4)\n    are all valid combinations\n    \"\"\"\n\n    return [candidate for candidate in\n            itertools.combinations(candidates, 3) if validator(candidate)]\n\\end{python}\n\n\n\\newpage\n\n\\subsection{Missing Integer}\n\n\\subsubsection{Problem Description}\n\n\\begin{table}[!h]\n\\begin{tabular}{|l|l|}\n\\hline\n\\textbf{input} & \\begin{tabular}[c]{@{}l@{}}an array $A$ of size $N-1$ that contains all integers in the range of $1$ to $N$,\\\\ except one missing integer. This list contains no duplicates.\\end{tabular} \\\\ \\hline\n\\textbf{output} & the missing number from the list \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\subsubsection{Pseudocode}\n\n\\begin{verbatim}\nfunction missing_element(container: list[int]):\n    N = len(container) + 1\n    intended_sum = N * (N + 1) / 2 # Gaussian Sum\n    return intended_sum - sum(container) \n    # the missing element is the difference between each container\n\\end{verbatim}\n\n\n\\subsubsection{Time Complexity}\n\nThis function is quite efficient in finding the missing integer, as it only needs to loop through the container once.\nAlso, the algorithm does not require the list to be in sorted order and can be extended to tuples, sets and other Python data containers.\nFirst, we need to compute the Gaussian Sum of the container as if it was intact.\nThe formula for this is:\n$$\\frac{N \\times (N + 1)}{2}$$\nand assumes the sequence is monotonically increasing, and contains all integers from $1$ to $N$ inclusive.\nHere, we have access to a key characteristic of the container without having to reconstruct it.\nThen, we translate the current container in terms of an integer and we apply the sum function $O(n)$.\nSubtracting the difference between the two will give you the missing integer.\nThis will  run in $O(n)$ time, as the only linear aspect is to find the sum of the current container.\n\\subsubsection{Implementation}\n\n\\begin{python}\ndef missing_integer(container: typing.List[int], dialation: int = 1) -> int:\n    \"\"\"\n    Find the missing integer in a monotonically increasing sequence\n    \"\"\"\n\n    intended_sum = gaussian_sum(len(container) + 1)\n\n    return intended_sum - sum(container)\n\n\ndef gaussian_sum(N: int, dialation: int = 1) -> int:\n    \"\"\"\n    This is the sum of a contiguous sequence of integers\n    Dialation is applied when a constant is applied to all elements in the sequence\n    \"\"\"\n\n    return int(N * (N + 1) / 2) * dialation\n\\end{python}\n\n\n\\newpage\n\n\\section{Extra Credit}\n\n\\subsection{Street Map}\n\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=10cm]{StreetMap}\n\\caption{Street View of Troy High School backroads}\n\\end{figure}\n\nEach node can contain the following information, and applying this to node \\#1 we get:\n\n\\begin{itemize}\n\\item Lateral intersection | Dorthy Lane (East/West)\n\\item Medial intersection | Acacia Avenue (South/North)\n\\item Longitude | SomeValue\n\\item Latitude | SomeValue\n\\item Dead end | False\n\\end{itemize}\n\nEach edge on the graph represents the street connecting each intersection and each edge is bidirectional (forgot to make it so in the diagram).\n\n\\newpage\n\n\\subsection{Course Requirements}\n\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=10cm]{CourseRequirements}\n\\caption{Example set of courses to be taken}\n\\end{figure}\n\nEach class should be taken in sequential order and must have it's prerequisites met before.\nThis is called a topological graph and is applied in different areas such as package managers and neuroscience.\nAs shown here in this example, some sections or \"forests\" can exist independently of one another.\nThese do not have interlaced dependencies and can be completed in their own continuum.\nOthers are connected on a basis where the course  must be taken in conjunction with the another class.\nThis can be seen in CS 121 and Math 150A, however this can also be applied to lab courses and their associated lecture (PHYS 225 and PHYS 225L).\n\n\\newpage\n\n\\subsection{Social Media Network}\n\n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=13cm]{SocialMediaNetwork}\n\\caption{Example Social Media Network}\n\\end{figure}\n\nGiven the list of people and their associated friends, we can construct a graph showing their relationships.\n\\begin{itemize}\n\\item Sussy $\\rightarrow$ Alex, Jo, Albert\n\\item Alex $\\rightarrow$ Jacob, Sussy, Jon\n\\item Bobby $\\rightarrow$ Nick, Nicole, Sheldon\n\\end{itemize}\n\nSingly directed edges can be read as \"Person 1 is following Person 2 but Person 2 is not following Person 1\".\nBidirectional edges are when both parties are following each other.\nEach \"forest\" is a collection of  nodes where they are all connected in some fashion.\nThe separation occurs when there are not mutual connections between every element in the network\n\n\\end{document}\n", "meta": {"hexsha": "a7630f19393efe88168ce2f7dfae053e462c6566", "size": 11591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/Homework_3.tex", "max_stars_repo_name": "JaredsAlgorithms/Assignments", "max_stars_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_stars_repo_licenses": ["MIT"], "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/Homework_3.tex", "max_issues_repo_name": "JaredsAlgorithms/Assignments", "max_issues_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_issues_repo_licenses": ["MIT"], "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/Homework_3.tex", "max_forks_repo_name": "JaredsAlgorithms/Assignments", "max_forks_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_forks_repo_licenses": ["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.6947674419, "max_line_length": 241, "alphanum_fraction": 0.7186610301, "num_tokens": 3110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6398110412720355}}
{"text": "\\documentclass[]{article}\n\n% Define page\n\\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}\n\n% Include packages for text modification\n\\usepackage{amsmath,amsfonts,amssymb}\n\\usepackage{bm}\n\n% Include packages for citing\n\\usepackage[noadjust]{cite}\n\n% Include packages for graphics\n\\usepackage{graphicx,psfrag}\n\\usepackage{subfigure}\n\n% Include packages for tables\n\\usepackage{array,multirow}\n\\usepackage{ctable}\n\n% Define new commands\n\\newcommand{\\etal}{\\emph{et al.}}\n\\newcommand{\\vT}{\\bm{T}}\n\\newcommand{\\vmu}{\\bm{\\mu}}\n\\newcommand{\\vTmu}{\\bm{T_{\\mu}}}\n\\newcommand{\\vTx}[1][]{\\bm{T}_{#1}(\\bm{x})}\n\\newcommand{\\vTy}[1][]{\\bm{T}_{#1}(\\bm{y})}\n\\newcommand{\\vx}[1][]{\\bm{x}_{#1}}\n\\newcommand{\\vxt}[1][]{\\bm{\\widetilde x}_{#1}}\n\\newcommand{\\vy}[1][]{\\bm{y}_{#1}}\n\\newcommand{\\D}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\Dd}[3]{\\frac{\\partial^2 #1}{\\partial #2 \\partial #3}}\n\\newcommand{\\elastix}{\\texttt{elastix}}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n\\title{Spatial derivatives and penalty terms in ITK and \\elastix}\n\n\\author{Marius Staring and Stefan Klein}\n\\date{}\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% main text\n\n\\section{Introduction}\n\nImage registration is the process of aligning images, and can be\ndefined as an optimisation problem:\n\\begin{align}\n\\hat \\vmu &= \\arg \\min_{\\vmu} \\mathcal{C}(I_F, I_M;\n\\vmu),\\label{eq:reg}\n\\end{align}\nwith $I_F$ and $I_M$ the $d$-dimensional fixed and moving image,\nrespectively, and $\\vmu$ the vector of parameters of size $N$ that\nmodel the transformation $\\vT$. The cost function $\\mathcal{C}$\nconsists of a similarity measure $\\mathcal{S}(I_F, I_M; \\vmu)$ that\ndefines the quality of alignment. Examples are the mean square\ndifference, normalised correlation, and mutual information measure.\nIn order to regularise the transformation $\\vT_{\\vmu}$ often a\npenalty term $\\mathcal{P}(\\vmu)$ is added to the cost function, so\nit becomes:\n\\begin{align}\n\\mathcal{C} &= \\alpha_1 \\mathcal{S} + \\alpha_2 \\mathcal{P},\n\\end{align}\nwhere $\\alpha_1, \\alpha_2$ user-defined constants that weigh\nsimilarity against regularity.\n\nPenalty term are often based on the first or second order spatial\nderivatives of the transformation. For example the bending energy of\nthe transformation, which is arguably the most common penalty term,\nis defined in 2D as:\n\\begin{align}\n\\mathcal{P}_{\\mathrm{BE}}(\\vmu) &= \\frac{1}{P} \\sum_{\\vxt[i]}\n\\left\\| \\frac{\\partial^2 \\vT}{\\partial \\vx \\partial \\vx^T}(\\vxt[i])\n\\right\\|_F^2 \\\\\n&= \\frac{1}{P} \\sum_{\\vxt[i]} \\sum_{j = 1}^2 \\left( \\frac{\\partial^2\nT_j}{\\partial x_1^2}(\\vxt[i]) \\right)^2  + 2 \\left( \\frac{\\partial^2\nT_j}{\\partial x_1 \\partial x_2}(\\vxt[i]) \\right)^2 + \\left(\n\\frac{\\partial^2 T_j}{\\partial x_2^2}(\\vxt[i]) \\right)^2,\n\\end{align}\nwhere $P$ is the number of points $\\vxt[i]$, and the tilde denotes\nthe difference between a variable and a given point over which a\nterm is evaluated.\n\nThe optimisation problem (\\ref{eq:reg}) is frequently solved using\nan iterative gradient descent routine:\n\\begin{align}\n\\vmu_{k+1} &= \\vmu_k - a_k \\frac{\\partial \\mathcal{C}}{\\partial\n\\vmu} = \\vmu_k - a_k \\left( \\alpha_1 \\frac{\\partial\n\\mathcal{S}}{\\partial \\vmu} + \\alpha_2 \\frac{\\partial\n\\mathcal{P}}{\\partial \\vmu} \\right),\\label{eq:opt}\n\\end{align}\nwith $a_k$ a user-defined declining function that defines the step\nsize.\n\nThe derivative of the similarity measure usually involves\ncomputation of the spatial derivative of the moving image:\n$\\D{I_M}{\\vx}$, and the derivative of the transformation to its\nparameters: $\\D{\\vT}{\\vmu}$. In the ITK the last derivative is\nimplemented using $\\texttt{transform->GetJacobian()}$, i.e. the\nderivative to the transformation parameters $\\vmu$ is referred to as\n`Jacobian'.\n\nPenalty terms usually consist of the first and second order\n\\emph{spatial} derivatives of the transformation, i.e.\n$\\D{\\vT}{\\vx}$ and $\\Dd{\\vT}{\\vx}{\\vx^T}$. We will refer to these\nderivatives as the `SpatialJacobian' and the `SpatialHessian' to\nclearly distinguish between these derivatives and the `Jacobian'. In\norder to apply the gradient descent optimisation routine\n(\\ref{eq:opt}), we additionally need the derivatives $\\D{}{\\vmu}\n\\D{\\vT}{\\vx}$ and $\\D{}{\\vmu} \\Dd{\\vT}{\\vx}{\\vx^T}$. These we call\nthe `JacobianOfSpatialJacobian' and `JacobianOfSpatialHessian',\nrespectively. See Table \\ref{tab:notation} for details.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{llll}\n\\toprule \\toprule\nName & definition & matrix size & written out in 2D \\\\\n\\midrule Transformation & $\\vT = \\vT_{\\vmu}(\\widetilde \\vx)$ & $d\n\\times 1$ & $\\begin{bmatrix} T_1(\\vx) \\\\ T_2(\\vx) \\end{bmatrix}$ \\\\[3ex]\nJacobian & $\\frac{\\partial \\vT_{\\vmu}}{\\partial \\vmu}(\\widetilde\n\\vx)$ & $d \\times N$ & $\\begin{bmatrix}\n  \\frac{\\partial T_1}{\\partial \\mu_1}(\\widetilde \\vx) & \\cdots & \\frac{\\partial T_1}{\\partial \\mu_N}(\\widetilde \\vx) \\\\\n  \\frac{\\partial T_2}{\\partial \\mu_1}(\\widetilde \\vx) & \\cdots & \\frac{\\partial T_2}{\\partial \\mu_N}(\\widetilde \\vx) \\\\\n\\end{bmatrix}$ \\\\[3ex]\nSpatialJacobian & $\\frac{\\partial \\vT_{\\vmu}}{\\partial\n\\vx}(\\widetilde \\vx)$ & $d \\times d$ & $\\begin{bmatrix}\n  \\frac{\\partial T_1}{\\partial x_1}(\\widetilde \\vx) \\frac{\\partial T_1}{\\partial x_2}(\\widetilde \\vx) \\\\\n  \\frac{\\partial T_2}{\\partial x_1}(\\widetilde \\vx) \\frac{\\partial T_2}{\\partial x_2}(\\widetilde \\vx) \\\\\n\\end{bmatrix}$ \\\\[3ex]\nJacobianOfSpatialJacobian & $\\frac{\\partial}{\\partial \\vmu}\n\\frac{\\partial \\vT_{\\vmu}}{\\partial \\vx}(\\widetilde \\vx)$ & $d\n\\times d \\times N$ & $\\begin{bmatrix}\n  \\frac{\\partial}{\\partial \\mu_1} \\frac{\\partial \\vT_{\\vmu}}{\\partial\n\\vx}(\\widetilde \\vx) & \\cdots & \\frac{\\partial}{\\partial \\mu_N}\n\\frac{\\partial \\vT_{\\vmu}}{\\partial \\vx}(\\widetilde \\vx)\n\\end{bmatrix}$ \\\\[3ex]\nSpatialHessian & $\\frac{\\partial^2 \\vT_{\\vmu}}{\\partial \\vx\n\\partial \\vx^T}$ & $d \\times d \\times d$ & $\\left\\{ \\begin{bmatrix}\n  \\frac{\\partial^2 T_1}{\\partial x_1 \\partial x_1}(\\widetilde \\vx) \\frac{\\partial^2 T_1}{\\partial x_2 \\partial x_1}(\\widetilde \\vx) \\\\\n  \\frac{\\partial^2 T_1}{\\partial x_2 \\partial x_1}(\\widetilde \\vx) \\frac{\\partial^2 T_1}{\\partial x_2 \\partial x_2}(\\widetilde \\vx) \\\\\n\\end{bmatrix}, \\begin{bmatrix}\n  \\frac{\\partial^2 T_2}{\\partial x_1 \\partial x_1}(\\widetilde \\vx) \\frac{\\partial^2 T_2}{\\partial x_2 \\partial x_1}(\\widetilde \\vx) \\\\\n  \\frac{\\partial^2 T_2}{\\partial x_2 \\partial x_1}(\\widetilde \\vx) \\frac{\\partial^2 T_2}{\\partial x_2 \\partial x_2}(\\widetilde \\vx) \\\\\n\\end{bmatrix} \\right\\}$ \\\\[3ex]\nJacobianOfSpatialHessian & $\\frac{\\partial}{\\partial \\vmu}\n\\frac{\\partial^2 \\vT_{\\vmu}}{\\partial \\vx \\partial \\vx^T}$ & $d\n\\times d \\times d \\times N$ & $\\begin{bmatrix}\n  \\frac{\\partial}{\\partial \\mu_1} \\frac{\\partial^2 \\vT_{\\vmu}}{\\partial \\vx\n\\partial \\vx^T} & \\cdots & \\frac{\\partial}{\\partial \\mu_N} \\frac{\\partial^2 \\vT_{\\vmu}}{\\partial \\vx\n\\partial \\vx^T}\n\\end{bmatrix}$ \\\\\n\\bottomrule \\bottomrule\n\\end{tabular}\n\\caption{Naming conventions and definitions for the transformation\nand its derivatives used in this paper.}\\label{tab:notation}\n\\end{table}\n\n\\section{Support for penalty terms in the ITK}\n\nThe derivative of the penalty term is not supported in the ITK. We\npropose to add the following functions in the\n\\texttt{itk::Transform} class:\n\\begin{quote}\n\\begin{verbatim}\nvirtual void GetSpatialJacobian(\n  const InputPointType &,\n  SpatialJacobianType & ) const;\n\nvirtual void GetSpatialHessian(\n  const InputPointType &,\n  SpatialHessianType & ) const;\n\nvirtual void GetJacobianOfSpatialJacobian(\n  const InputPointType &,\n  JacobianOfSpatialJacobianType &,\n  NonZeroJacobianIndicesType & ) const;\n\nvirtual void GetJacobianOfSpatialHessian(\n  const InputPointType &,\n  JacobianOfSpatialHessianType &,\n  NonZeroJacobianIndicesType & ) const;\n\\end{verbatim}\n\\end{quote}\nand additionally a function to implement a sparse version of the\nJacobian:\n\\begin{quote}\n\\begin{verbatim}\nvirtual void GetJacobian(\n    const InputPointType &,\n    JacobianType &,\n    NonZeroJacobianIndicesType & ) const;\n\\end{verbatim}\n\\end{quote}\n\nThe ITK structures that were used to store the data are given in\nTable \\ref{tab:datastructures}. The Jacobian is of size $d \\times\nN$, and since the number of transformation parameters is flexible\nfor some transformations, the data structure used for storing the\nJacobian is an \\texttt{itk::Array2D} object, which inherits from the\n\\texttt{vnl\\_matrix}. This was already chosen previously in the ITK.\nThe SpatialJacobian is of fixed size $d \\times d$, and therefore we\nchoose to use the \\texttt{itk::Matrix} to store the SpatialJacobian,\nwhich inherits from the \\texttt{vnl\\_matrix\\_fixed}. For derivatives\nto $\\vmu$ we choose to use the \\texttt{std::vector}. The\nSpatialHessian gives us some problems, since we really need a 3D\nmatrix, but currently no such thing exists in the ITK. Therefore, we\nopt for an \\texttt{itk::FixedArray} of \\texttt{itk::Matrix}.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{ll}\n\\toprule \\toprule\nName & ITK structure \\\\\n\\midrule Transformation &  \\\\\nJacobian & \\texttt{Array2D = vnl\\_matrix} \\\\\nSpatialJacobian & \\texttt{Matrix = vnl\\_matrix\\_fixed} \\\\\nJacobianOfSpatialJacobian & \\texttt{std::vector< Matrix >} \\\\\nSpatialHessian & \\texttt{FixedArray< Matrix >}\\footnotemark \\\\\nJacobianOfSpatialHessian & \\texttt{std::vector< FixedArray< Matrix > >} \\\\\nNonZeroJacobianIndices & \\texttt{std::vector< unsigned long >} \\\\\n\\bottomrule \\bottomrule\n\\end{tabular}\n\\caption{The ITK structures that store the\ndata.}\\label{tab:datastructures}\n\\end{table}\n\\footnotetext{by lack of a good 3D matrix structure}\n\nFrom the function definitions above, notice that we chose to pass\nthe variables by reference, and as function arguments. The\n\\texttt{GetJacobian} in the \\texttt{itk::Transform} is defined as:\n\\begin{quote}\n\\begin{verbatim}\nvirtual const JacobianType & GetJacobian( const InputPointType & ) const;\n\\end{verbatim}\n\\end{quote}\nwhich returns a reference to the member variable\n\\texttt{m\\_Jacobian}. It is possible, however, that this member is\nonly valid for the input point, namely for transformations with a\nderivative dependent of the spatial position. Therefore, we think\nthat it should not be possible to access this parameter at a later\ntime, when the input point has possibly changed.\n\nAlso notice the \\texttt{NonZeroJacobianIndicesType} in the function\ndefinitions. These are meant for the support of sparse Jacobians,\nJacobianOfSpatialJacobians, etc.\n\n\\section{Affine transformation}\n\nFor the affine transformation, the derivatives evaluate to the\nfollowing in 2D:\n\\begin{align}\n\\vTmu(\\vxt) &= A \\vx + \\bm{t} = \\begin{bmatrix} a_{11} & a_{12}\n\\\\ a_{21} & a_{22} \\end{bmatrix} \\begin{bmatrix} \\widetilde x_1 \\\\\n\\widetilde x_2 \\end{bmatrix} + \\begin{bmatrix} t_1 \\\\ t_2\n\\end{bmatrix} = \\begin{bmatrix} \\mu_0 & \\mu_1\n\\\\ \\mu_2 & \\mu_3 \\end{bmatrix} \\begin{bmatrix} \\widetilde x_1 \\\\\n\\widetilde x_2 \\end{bmatrix} + \\begin{bmatrix} \\mu_4 \\\\ \\mu_5\n\\end{bmatrix}, \\\\\n\\D{\\vT}{\\vmu}(\\vxt) &= \\begin{bmatrix} \\widetilde x_1 & \\widetilde\nx_2 & 0 & 0 & 1 & 0 \\\\ 0 & 0 & \\widetilde x_1 & \\widetilde x_2 & 0 &\n1 \\end{bmatrix}, \\\\\n\\D{\\vT}{\\vx}(\\vxt) &= \\begin{bmatrix} \\mu_0 & \\mu_1 \\\\ \\mu_2 & \\mu_3 \\end{bmatrix}, \\\\\n\\Dd{\\vT}{\\vx}{\\vx^T}(\\vxt) &= O_{d \\times d \\times d}, \\\\\n\\D{}{\\vmu} \\D{\\vT}{\\vx}(\\vxt) &= \\left\\{ \\begin{bmatrix} 1 & 0 \\\\\n0 & 0 \\end{bmatrix}, \\begin{bmatrix} 0 & 1 \\\\ 0 & 0\n\\end{bmatrix}, \\begin{bmatrix} 0 & 0 \\\\ 1 & 0\n\\end{bmatrix}, \\begin{bmatrix} 0 & 0 \\\\ 0 & 1\n\\end{bmatrix} \\right\\}, \\\\\n\\D{}{\\vmu} \\Dd{\\vT}{\\vx}{\\vx^T}(\\vxt) &= O_{d \\times d \\times d\n\\times N},\n\\end{align}\nwhere $O_s$ is a zero matrix of size $s$.\n\n%centre of rotation!!!\n\nThe \\texttt{GetJacobianOfSpatialJacobian()} returns\n\\texttt{nonZeroJacobianIndices} = $[ 0, 1, 2, 3 ]$.\n\n%For the SpatialHessian and the JacobianOfSpatialHessian we choose to\n%not return matrices filled with zeros, but instead zero sized\n%matrices. The implementation of the penalty term is assumed to check\n%for the size. In case of an affine transform the size is zero, and\n%the penalty term can simply return zero. This is a performance\n%benefit compared to walking over the zero matrix, and adding and\n%multiplying everything, which in the end also gives zero.\n\nThese derivatives are implemented in the\n\\texttt{itk::AdvancedMatrixOffsetTransformBase} class.\n\n\\section{B-spline transformation}\n\nA transformation parameterised by third order B-splines can be\nwritten in 2D as follows:\n\\begin{align}\n\\vTmu(\\vxt) &= \\begin{bmatrix} T_1(\\vxt;\\vmu) \\\\ T_2(\\vxt;\\vmu)\n\\end{bmatrix} = \\begin{bmatrix} \\widetilde{x}_1 \\\\ \\widetilde{x}_2 \\end{bmatrix}\n + \\begin{bmatrix} \\sum_{i} \\mu_i \\beta^3 \\left(\n\\frac{ \\widetilde{x}_1 - x_{1}^i}{\\sigma_1} \\right)\n\\beta^3 \\left( \\frac{\\widetilde{x}_2 - x_{2}^i}{\\sigma_2}\\right) \\\\\n \\sum_{i} \\mu_{i+16} \\beta^3 \\left( \\frac{ \\widetilde{x}_1 - x_{1}^i}\n {\\sigma_1} \\right) \\beta^3 \\left( \\frac{\\widetilde{x}_2 - x_{2}^i}{\\sigma_2} \\right)\n\\end{bmatrix},\n\\end{align}\nwith $\\vx^i$ the control points within the support of the B-spline\nbasis functions $\\beta^3(\\cdot)$, and $\\sigma$ the B-spline grid\nspacing. Here, we labelled the $x$-direction of the control points\nwith $\\mu_0, \\ldots, \\mu_{15}$ and the $y$-direction with $\\mu_{16},\n\\ldots, \\mu_{31}$. (Since the support of a cubic B-spline is $4^d =\n16$.)\n\nFor short notation, define:\n\\begin{align}\nb_{33}^{i} &= \\beta^3\\left( (\\widetilde{x}_1 - x_{1}^i) / \\sigma_1\n\\right) \\cdot \\beta^3 \\left( (\\widetilde{x}_2 - x_{2}^i) / \\sigma_2\n\\right), \\\\\nb_{23}^{i} &= \\left[ \\beta^2 \\left( (\\widetilde{x}_1 -\nx_{1}^i)/\\sigma_1 + \\tfrac{1}{2} \\right) - \\beta^2 \\left(\n(\\widetilde{x}_1 - x_{1}^i)/\\sigma_1 - \\tfrac{1}{2} \\right) \\right]\n\\cdot \\beta^3 \\left( (\\widetilde{x}_2 - x_{2}^i)/\\sigma_2 \\right) /\n\\sigma_1, \\\\\nb_{32}^{i} &= \\beta^3 \\left( (\\widetilde{x}_1 - x_{1}^i)/\\sigma_1\n\\right) \\cdot \\left[ \\beta^2 \\left( (\\widetilde{x}_2 -\nx_{2}^i)/\\sigma_2 + \\tfrac{1}{2} \\right) - \\beta^2 \\left( (\n\\widetilde{x}_2 - x_{2}^i)/\\sigma_2 - \\tfrac{1}{2} \\right) \\right] /\n\\sigma_2, \\\\\n\\begin{split}\nb_{22}^{i} &= \\left[ \\beta^2 \\left( ( \\widetilde{x}_1 -\nx_{1}^i)/\\sigma_1 + \\tfrac{1}{2} \\right) - \\beta^2 \\left( (\n\\widetilde{x}_1 - x_{1}^i)/\\sigma_1 - \\tfrac{1}{2} \\right) \\right] \\\\\n& \\qquad \\qquad \\cdot \\left[ \\beta^2 \\left( ( \\widetilde{x}_2 -\nx_{2}^i)/\\sigma_2 + \\tfrac{1}{2} \\right) - \\beta^2 \\left( (\n\\widetilde{x}_2 - x_{2}^i)/\\sigma_2 - \\tfrac{1}{2} \\right) \\right] /\n(\\sigma_1 \\sigma_2),\n\\end{split} \\\\\nb_{13}^{i} &= \\left[ \\beta^1 \\left( (\\widetilde{x}_1 -\nx_{1}^i)/\\sigma_1 + 1 \\right) - 2 \\beta^1 \\left( ( \\widetilde{x}_1 -\nx_{1}^i)/\\sigma_1 \\right) + \\beta^1 \\left( (\\widetilde{x}_1 -\nx_{1}^i)/\\sigma_1 - 1 \\right) \\right] \\cdot \\beta^3 \\left(\n(\\widetilde{x}_2 - x_{2}^i)/\\sigma_2 \\right) / \\sigma_1^2, \\\\\nb_{31}^{i} &= \\beta^3 \\left( (\\widetilde{x}_1 - x_{1}^i)/\\sigma_1\n\\right) \\cdot \\left[ \\beta^1 \\left( (\\widetilde{x}_2 -\nx_{2}^i)/\\sigma_2 + 1 \\right) - 2 \\beta^1 \\left( ( \\widetilde{x}_2 -\nx_{2}^i)/\\sigma_2 \\right) + \\beta^1 \\left( (\\widetilde{x}_2 -\nx_{2}^i)/\\sigma_2 - 1 \\right) \\right] / \\sigma_2^2.\n\\end{align}\nFrom these equations we derive:\n\\begin{align}\n\\D{\\vT}{\\vmu}(\\vxt) &= \\begin{bmatrix} b_{33}^{0} & \\cdots &\nb_{33}^{15} & 0 & \\cdots & 0 \\\\ 0 & \\cdots & 0 & b_{33}^{0} &\n\\cdots & b_{33}^{15} \\end{bmatrix}, \\\\\n\\D{\\vT}{\\vx}(\\vxt) &= \\begin{bmatrix} 1 + \\sum_i \\mu_i b_{23}^i &\n\\sum_i \\mu_i b_{32}^i \\\\ \\sum_i \\mu_{i+16} b_{23}^{i} & 1 + \\sum_i\n\\mu_{i+16} b_{32}^{i} \\end{bmatrix}, \\\\\n\\Dd{\\vT}{\\vx}{\\vx^T}(\\vxt) &= \\left\\{ \\begin{bmatrix} \\sum_i \\mu_i\nb_{13}^i & \\sum_i \\mu_i b_{22}^i \\\\ \\sum_i \\mu_{i} b_{22}^{i} &\n\\sum_i \\mu_{i} b_{31}^{i} \\end{bmatrix}, \\begin{bmatrix} \\sum_i\n\\mu_{i+16} b_{13}^{i} & \\sum_i \\mu_{i+16} b_{22}^{i} \\\\ \\sum_i\n\\mu_{i+16} b_{22}^{i} & \\sum_i \\mu_{i+16} b_{31}^{i}\n\\end{bmatrix} \\right\\} \\\\\n\\D{}{\\vmu} \\D{\\vT}{\\vx}(\\vxt) &= \\left\\{ \\begin{bmatrix} b_{23}^{0}\n& b_{32}^{0} \\\\ 0 & 0 \\end{bmatrix}, \\cdots, \\begin{bmatrix}\nb_{23}^{15} & b_{32}^{15} \\\\ 0 & 0 \\end{bmatrix}, \\begin{bmatrix} 0\n& 0 \\\\ b_{23}^{0} & b_{32}^{0} \\end{bmatrix}, \\cdots,\n\\begin{bmatrix} 0 & 0 \\\\ b_{23}^{15} & b_{32}^{15} \\end{bmatrix} \\right\\}\n\\\\\n\\D{}{\\vmu} \\Dd{\\vT}{\\vx}{\\vx^T}(\\vxt) &= \\left\\{ \\left\\{\n\\begin{bmatrix} b_{13}^0 & b_{22}^0 \\\\ b_{22}^0 & b_{31}^0 \\end{bmatrix},\nO_{d \\times d} \\right\\}, \\cdots, \\left\\{ \\begin{bmatrix} b_{13}^{15}\n& b_{22}^{15} \\\\ b_{22}^{15} & b_{31}^{15} \\end{bmatrix}, O_{d\n\\times d} \\right\\}, \\right. \\\\\n& \\qquad \\left. \\left\\{ O_{d \\times d},\n\\begin{bmatrix} b_{13}^{0} & b_{22}^{0} \\\\ b_{22}^{0} &\nb_{31}^{0} \\end{bmatrix} \\right\\}, \\cdots, \\left\\{ O_{d \\times d},\n\\begin{bmatrix} b_{13}^{15} & b_{22}^{15} \\\\ b_{22}^{15} &\nb_{31}^{15} \\end{bmatrix} \\right\\} \\right\\}.\n\\end{align}\n\nThese derivatives are implemented in the\n\\texttt{itk::AdvancedBSplineDeformableTransform} class.\n\n\\section{Combining transformations}\n\n\\texttt{elastix} supports combining multiple transformations by\naddition or composition. Adding transformations is done via:\n\\begin{align}\n\\vTx &= \\vTx[0] + \\vTx[1] - \\vx,\n\\end{align}\nwhere $\\vTx[0]$ is the initial transformation and $\\vTx[1]$ the\ncurrent transformation. Only the current transformation is optimised\nduring the registration (as a choice). Composition of\ntransformations is defined via:\n\\begin{align}\n\\vTx &= \\vT_1(\\vTx[0]).\n\\end{align}\n\nFor these combined transformations we need to derive the relations\nfor the derivatives. Define $\\bm{y} = \\vT_0(\\vxt)$.\n\n\\begin{align}\n\\intertext{Jacobian:}\n\\D{\\vTmu}{\\vmu}(\\vxt) &= \\D{}{\\vmu} \\left( \\vT_0(\\vxt) + \\vT_1(\\vxt)\n- \\vxt \\right) = \\D{}{\\vmu} \\vT_1(\\vxt), \\\\\n\\D{\\vTmu}{\\vmu}(\\vxt) &= \\D{}{\\vmu} \\left( \\vT_1(\\vT_0(\\vxt))\n\\right) = \\D{}{\\vmu} \\vT_1(\\bm{y}).\n\\intertext{SpatialJacobian:}\n\\D{\\vTmu}{\\vx}(\\vxt) &= \\D{}{\\vx} \\left( \\vT_0(\\vxt) + \\vT_1(\\vxt) -\n\\vxt \\right) = \\D{}{\\vx} \\vT_0(\\vxt) + \\D{}{\\vx} \\vT_1(\\vxt) - \\bm{I}, \\\\\n%\\D{\\vTmu}{\\vx}(\\vxt) &= \\D{}{\\vx} \\vT_1(\\vT_0(\\vxt)) = \\D{}{\\vx}\n%\\vT_1(\\bm{y}) \\cdot \\D{}{\\vx} \\vT_0(\\vxt). \\\\\n\\D{T_{\\vmu,k}}{x_i}(\\vxt) &= \\left( \\D{T_{1,k}}{\\vx}(\\vy) \\right)^T\n\\D{\\vT_0}{x_i}(\\vxt) =  \\left(\\D{\\vT_0}{x_i}(\\vxt) \\right)^T\n\\D{T_{1,k}}{\\vx}(\\vy)\n\\intertext{JacobianOfSpatialJacobian:}\n\\D{}{\\vmu} \\D{\\vTmu}{\\vx}(\\vxt) &= \\D{}{\\vmu} \\D{}{\\vx} \\left(\n\\vT_0(\\vxt) + \\vT_1(\\vxt) - \\vxt \\right) = \\D{}{\\vmu} \\D{}{\\vx}\n\\vT_1(\\vxt), \\\\\n\\D{}{\\vmu} \\D{\\vTmu}{\\vx}(\\vxt) &= \\D{}{\\vmu} \\D{}{\\vx} \\left(\n\\vT_1(\\vT_0(\\vxt)) \\right) = \\D{}{\\vmu} \\D{}{\\vx} \\vT_1(\\bm{y}) \\cdot\n\\D{}{\\vx} \\vT_0(\\vxt).\n\\intertext{SpatialHessian:}\n\\Dd{\\vTmu}{x_i}{x_j} &= \\Dd{}{x_i}{x_j} \\left( \\vT_0(\\vxt) +\n\\vT_1(\\vxt) \\right) = \\Dd{}{x_i}{x_j} \\vT_0(\\vxt) +\n\\Dd{}{x_i}{x_j} \\vT_1(\\vxt), \\\\\n%\\Dd{\\vTmu}{x_i}{x_j} &= \\Dd{}{x_i}{x_j} \\left( \\vT_1(\\vT_0(\\vxt))\n%\\right) = \\D{}{x_i} \\vT_0(\\vxt) \\Dd{}{x_i}{x_j} \\vT_1(\\bm{y})\n%\\D{}{x_j} \\vT_0(\\vxt) + \\Dd{}{x_i}{x_j} \\vT_0(\\vxt) \\D{}{x_j}\n%\\vT_1(\\bm{y}). \\\\\n\\Dd{T_{\\vmu,k}}{x_i}{x_j}(\\vxt) &= \\left( \\D{T_{1,k}}{\\vx}(\\vy)\n\\right)^T \\Dd{\\vT_0}{x_i}{x_j}(\\vxt) + \\left(\\D{\\vT_0}{x_i}(\\vxt)\n\\right)^T \\Dd{T_{1,k}}{\\vx}{\\vx^T}(\\bm{y}) \\D{\\vT_0}{x_j}(\\vxt)\n\\intertext{JacobianOfSpatialHessian:}\n\\D{}{\\vmu} \\Dd{\\vTmu}{x_i}{x_j} &= \\D{}{\\vmu} \\Dd{}{x_i}{x_j} \\left(\n\\vT_0(\\vxt) + \\vT_1(\\vxt) - \\vxt \\right) = \\D{}{\\vmu}\n\\Dd{}{x_i}{x_j} \\vT_1(\\vxt), \\\\\n%\\D{}{\\vmu} \\Dd{\\vTmu}{\\vx}{\\vx^T} &= \\D{}{\\vmu} \\Dd{}{x_i}{x_j}\n%\\left( \\vT_1(\\vT_0(\\vxt)) \\right) \\\\\n% &= \\D{}{x_i} \\vT_0(\\vxt) \\D{}{\\vmu} \\Dd{}{x_i}{x_j} \\vT_1(\\bm{y})\n%\\D{}{x_j} \\vT_0(\\vxt) + \\Dd{}{x_i}{x_j} \\vT_0(\\vxt) \\D{}{\\vmu}\n%\\D{}{x_j} \\vT_1(\\bm{y}). \\\\\n\\D{}{\\vmu} \\Dd{T_{mu,k}}{x_i}{x_j}(\\vxt) &=\n\\Dd{T_{1,k}}{\\vmu}{\\vx^T}(\\vy) \\Dd{\\vT_0}{x_i}{x_j}(\\vxt) +\n\\left(\\D{\\vT_0}{x_i}(\\vxt) \\right)^T \\left(\\D{}{\\vmu}\n\\Dd{T_{1,k}}{\\vx}{\\vx^T}(\\bm{y})\\right) \\D{\\vT_0}{x_j}(\\vxt)\n\\end{align}\n\nThese derivatives are implemented in the\n\\texttt{itk::AdvancedCombinationTransform} class.\n\n\\section{Bending energy penalty term}\n\nThe bending energy was defined as:\n\\begin{align}\n\\mathcal{P}_{\\mathrm{BE}}(\\vmu) &= \\frac{1}{P} \\sum_{\\vxt[i]}\n\\sum_{k,l,m = 1}^2 \\left( \\Dd{T_k}{x_l}{x_m}(\\vxt[i]) \\right)^2.\n\\end{align}\n\nWe constructed an \\texttt{itk::TransformBendingEnergyPenaltyTerm}\nwhich inherits from the \\texttt{itk::ImageToImage\\-Metric}. The\n\\texttt{GetValue()}-method is implemented like:\n\\begin{quote}\n\\begin{verbatim}\nSpatialHessianType spatialHessian;\nfor all samples\n  this->GetTransform()->GetSpatialHessian( sample, spatialHessian );\n  for all k, l, m\n    measure += spatialHessian[ k ][ l ][ m ]^2;\n  end\nend\nmeasure /= this->m_NumberOfPixelsCounted;\n\\end{verbatim}\n\\end{quote}\n\nFor the \\texttt{GetValueAndDerivative()} we have:\n\\begin{align}\n\\D{}{\\vmu} \\mathcal{P}_{\\mathrm{BE}}(\\vmu) &=  \\frac{1}{P}\n\\sum_{\\vxt[i]} \\sum_{k,l,m = 1}^2 2 \\Dd{T_k}{x_l}{x_m} (\\vxt[i])\n\\D{}{\\vmu} \\Dd{T_k}{x_l}{x_m}(\\vxt[i]),\n\\end{align}\nwhich is implemented like:\n\\begin{quote}\n\\begin{verbatim}\nSpatialHessianType spatialHessian;\nJacobianOfSpatialHessianType jacobianOfSpatialHessian;\nfor all samples\n  this->GetTransform()->GetSpatialHessian( sample, spatialHessian );\n  this->GetTransform()->GetJacobianOfSpatialHessian( sample,\n    jacobianOfSpatialHessian, nonZeroJacobianIndices );\n  for all nonZeroJacobianIndices, k, l, m\n    derivative[ nonZeroJacobianIndices[ mu ] ] += 2.0\n      * spatialHessian[ k ][ i ][ j ]\n      * jacobianOfSpatialHessian[ mu ][ k ][ i ][ j ];\n  end\nend\nderivative /= this->m_NumberOfPixelsCounted;\n\\end{verbatim}\n\\end{quote}\n\nThis penalty term is implemented in the\n\\texttt{itk::TransformBendingEnergyPenaltyTerm} class.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Discussion and Conclusion}\n\nThis document describes the use and implementation of spatial\nderivatives of coordinate transformations. These spatial derivatives\nwere exploited by the bending energy penalty term. Their usage is,\nhowever, not limited to that penalty term, and many more penalty\nterms can be implemented using the new functionality.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%\\bibliographystyle{plainnat}\n%\\bibliography{mi}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\end{document}\n", "meta": {"hexsha": "7ffe4429590f87bcd0e1ef2f6385905bd691d6b4", "size": 22075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dox/misc/penalty.tex", "max_stars_repo_name": "eliseemond/elastix", "max_stars_repo_head_hexsha": "0e8572f4a315e0a8f08b07d5947b4f3ac160b575", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 318, "max_stars_repo_stars_event_min_datetime": "2017-05-22T11:39:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T04:40:13.000Z", "max_issues_repo_path": "dox/misc/penalty.tex", "max_issues_repo_name": "eliseemond/elastix", "max_issues_repo_head_hexsha": "0e8572f4a315e0a8f08b07d5947b4f3ac160b575", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 358, "max_issues_repo_issues_event_min_datetime": "2017-05-22T11:36:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-18T15:49:10.000Z", "max_forks_repo_path": "dox/misc/penalty.tex", "max_forks_repo_name": "eliseemond/elastix", "max_forks_repo_head_hexsha": "0e8572f4a315e0a8f08b07d5947b4f3ac160b575", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2017-05-22T11:38:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T20:27:51.000Z", "avg_line_length": 42.0476190476, "max_line_length": 134, "alphanum_fraction": 0.6573046433, "num_tokens": 8387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6398110401833503}}
{"text": "\\chapter{Multi-Rotor Development}\n\\label{chap:MR}\n\\section{Range \\& Endurance}\nFor a multirotor, range can be estimated by how far it can be controlled by the controller before losing its connection. The range of a multirotor is dependent on certain factors like weight, motor power, weather conditions, etc. Based on the application requirement, they can be customized for longer ranges and better performances. In this project, the forward flight momentum theory was used to estimate the range and endurance of the aircraft for a given set of forward speeds. A velocity range of 0-20 m/s was chosen to perform this calculation and the estimated values of range, endurance, and forward speeds of the multi-rotor drone were calculated using the following steps as follows: \\\\\\\n\n\\subsection{Forward Flight Momentum Theory}\n\nThe forward flight expression can be written as:\n\n\\begin{equation}\n\t\\label{eq:range_multirotor}\n\tv = \\frac{T}{2} \n\\end{equation}\n\nAt a given forward speed, V we can then solve for $ α_D $, v, T, $ P_{ind} $, $ P_{tot} $ as follows: \\\\\\\n\n\\begin{enumerate}\n\t\\item Calculate the quadrotor drag $ D = \\frac{\\rho C_D V^2}{2} $ at $ α_D = 0 $ Assume $ α_D $ does not affect the drag, otherwise need to iterate to find solution\n\t\\item Solve $ α_D = tan^-1(\\frac{D}{W}) $\n\t\\item Square both sides of \\ref{eq:range_multirotor} replace $ T_2 $ by $ W_2 $ + $ D_2 $ and re-arrange to get, $ v_4 + (2 V sin(α_D)) v_3 + V 2 v_2 −(W2 + D2)/(2 ρ A)2 = 0 $\n\t\\item Positive real root of equation gives v, then $ P_{ind} = T_v; P_{tot} = T (v + V sin(α_D)) $\n\t\\item Notice that this total power does not include profile drag, swirl, or additional\n\tlosses due to non-uniform induced velocity.\n\t\\item Solve for a range of speeds and plot results versus V\n\t\t\n\\end{enumerate}\n\nThe maximum range of the quadcopter is calculated using the formula: \\\\\n\nMax. Range = $ (\\frac{E_b * m_e * esc_e }{Minimum Total Power/Velocity}) $ \\\\\n\nWhere, $ E_b $  = Energy of the battery;  $ M_e $ = Motor efficiency;  $ Esc_e $ = ESC efficiency \\\\\n\nThe maximum endurance of the quadcopter is calculated using the formula: \\\\\n\nMax. Endurance = $ (E_b * m_e * esc_e) / (Minimum Total Power) $ \\\\\nWhere, $ E_b $ = Energy of the battery; $ M_e $ = Motor efficiency; $ Esc_e $ = ESC efficiency \\\\\n\nBased on the above-mentioned procedures, the results of the multi-rotor drone (quadcopter) are as follows: \\\\\n\\begin{itemize}\n\t\\item Max. Range = 34 kms\n\t\\item Max. Endurance = 68.1 minutes\n\t\\item Forward Speed for range = 9.5 m/s\n\t\\item Forward Speed for endurance = 7 m/s\n\\end{itemize}\n\n\\section{Quadrotor Dynamics Model}\n\nThe development of dynamics model of quadrotor was done by using the following state space matrices given for each control channel.\n\n\\textbf{Given State-Space Matrices} : \\\\\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{Images/ss_1}\n\t\\includegraphics[width=0.8\\textwidth]{Images/ss_2}\n\t\\caption{State-Space Matrices}\n\t\\label{fig:ss}\n\\end{figure}\n\nThe output from position controller was fed into the dynamics model. The dynamics model consists of each control channel mentioned above put in a separate state-space block in Simulink. For roll control the input was the desired roll angle and the output from the state-space block was the actual roll angle. This actual roll angle was then fed into the roll to v control channel as input, to get the actual velocity v about y-axis.\n\nFor pitch control the input was desired pitch angle and the output was the actual pitch angle. This actual pitch angle was then fed into the pitch to u control channel which gives the actual velocity about x-axis. \n\nYaw control channel used desired yaw rate, also called as desired heading rate, for input while the output of this control channel is actual yaw angle. The last control channel used for the dynamic model of this quadrotor is altitude control, for this the input was desired vertical velocity w while the output was orientation along z- axis, which is also called altitude. \n\nThe Simulink design of Dynamic Model is shown in the figure below:\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{Images/position_control}\n\t\\caption{Simulink Design Dynamic Model}\n\t\\label{fig:pc}\n\\end{figure}\n\n\\section{Development of Position/Orientation control system:}\n\nPosition/Orientation Control System contains two types of state input, one is the target x, y, and z coordinate input and the other is actual x, y and z coordinates of the quadrotor. A reference yaw command is also given into the position controller to ensure that the quadrotor maintains the commanded yaw while operating for the target position.\n\nThe target x coordinate is given into a summation block while the actual x orientation of the quadrotor is given to the summation block as feedback. This command is fed into the PD controller, which gives corresponding derivative $\\dot{x}$ (i.e., speed along x axis). This derived velocity u is given to the summation block whereas the actual velocity $ u_a $ is given as feedback in the same block. A PD controller is used again which finally gives the derivative $\\ddot{x}$ . \n\nSimilarly, target y position and actual y position of the quadrotor is also given into the summation block and then into the PD controller. The output from this PD controller is further given into a summation block where the actual velocity v is given as feedback. This output is then given into the PD controller to get acceleration along y-axis. \n\nActual heading angle psi, along with $\\ddot{x}$ and $\\ddot{y}$ is used to calculate the desired pitch angle and desired roll angle. The following equations [reference no?] are used for this: \\\\\n\n\\left[\\begin{array}{c}\n\t\\phi_{d} \\\\\n\t\\theta_{d}\n\\end{array}\\right]=\\left[\\begin{array}{cc}\n\t-\\sin \\psi & -\\cos \\psi \\\\\n\t\\cos \\psi & -\\sin \\psi\n\\end{array}\\right]^{-1} \\frac{m}{U_{1}}\\left[\\begin{array}{l}\n\t\\ddot{x}_{d} \\\\\n\t\\ddot{y}_{d}\n\\end{array}\\right] \\\\\n\n\nSince the derivation of these equations in (reference no) uses small angle approximation, we must ensure that the desired angles $\\theta_{d}$ and $\\phi_{d}$ are within the limit of –20° and 20°. Therefore, a saturation block is placed at the output of MATLAB function block.   \n\nWe also need the desired vertical velocity w and the desired heading rate $\\dot{psi$ to be given into the dynamics model of the quadrotor. For this, desired z coordinate and actual z coordinate are given into a summation block and PD controller is used to obtain the desired w velocity. Similarly, actual yaw angle and desired yaw angle along with PD controller are used to obtain heading rate $\\dot{psi}$. \n\t\n\\section{Development of Position Estimation:}\n\nFor estimating the position of the quadrotor, the output states from the dynamic model i.e., psi, psi, theta, h, u and v, are used. The dynamic model provides information about the actual value of states of the quadrotor. To acquire data regarding the actual x and y coordinated of the quadrotor we integrate the u and v velocities, respectively. The Simulink model of position estimation subsystem is shown in \\ref{fig:pe}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{Images/pe}\n\t\\caption{Position Estimation}\n\t\\label{fig:pe}\n\\end{figure}\n \n \\section{Development of linear simulation model:}\n \n For the development of the linear simulation model, a reference subsystem was created which was used for giving the desired coordinate information to the position controller. The desired pitch and roll angles $ \\theta_{d} $ and $\\phi_{d}$ along with the heading rate $\\dot{psi}$ and desired vertical velocity wd goes into a summation block followed by a PID controller. To this summation block feedback is given of actual orientation of the respective states. \n \n Further, these values are given into the dynamics model subsystem which is also explained in the previous section. The actual values obtained from the dynamic model are used in the position estimation subsystem to get information about Euler angles, position, and velocities of the quadrotor. \n \n The reference position subsystem developed in for this project is an If-Else condition block which is used with Action block to activate a particular command for an If-Else condition. The reference command subsystem is shown in the \\ref{fig:rp}.\n \\begin{figure}\n \t\\centering\n \t\\includegraphics[width=0.8\\textwidth]{Images/rp}\n \t\\caption{Reference Position}\n \t\\label{fig:rp}\n \\end{figure}\n\nThe complete linear simulation system that was developed in Simulink is shown in the \\ref{fig:cm} \n\nPID Tuning methods used for this project were Inbuilt PID tuners provided by Simulink. For tuning PD controllers, the following steps were taken:\n\\begin{enumerate}\n\t\\item Proportional gain Kp was increased until steady oscillations were obtained\n\t\\item Derivate gain Kd was increased until the oscillations were critically damped\n\\end{enumerate} \\\\\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=1.1\\textwidth]{Images/multirotor}\n\t\\caption{Complete Multirotor Dynamic System}\n\t\\label{fig:cm}\n\\end{figure}\n\nTotal simulation time was taken to be 1500 seconds for the following four maneuvers: \\\\\n\\begin{enumerate}\n\t\\item Take off and hover at 2 meters above origin\n\t\\item Fly to the first target (x = 5 m, y = 6 m, h = 4 m) and hover\n\t\\item Fly to the second target (x = -5 m, y = -6 m, h = 4 m) and hover\n\t\\item Return to 2 meters above origin and land\n\\end{enumerate}\n\n\\section{Result}\n\nThe quadcopter was successfully able to complete all the given maneuvers for this project. The simulation result, which shows the trajectory of x, y and z coordinates of the quadcopter for 1500 seconds is shown in . \n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=1.1\\textwidth]{Images/multirotor_sol}\n\t\\caption{Quadrotor Simulation Solution}\n\t\\label{fig:m_sol}\n\\end{figure}\\\\\n\nIn the figure the quadcopter is initially at x=0, y=0 and z=0 position, in the first 300 seconds it takes off and hover at x=0 y=0 and z=2 m. Next, the quadcopter reaches to x=5, y=6 and z=4.For the third maneuver it goes from its current position to the target position, x=-5, y=-6 and z=4 and then for the last maneuver is goes from current position to target position of x=0, y=0 and z= 2 and then back to the origin. ", "meta": {"hexsha": "5cc7a67803516e08e31f944315d987a141ca61d7", "size": 10220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/report/Chapters/Multirotor.tex", "max_stars_repo_name": "Rutvikrj26/AER1216", "max_stars_repo_head_hexsha": "c809846ba49d086415827829ec57ef42ae37ba9c", "max_stars_repo_licenses": ["MIT"], "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/Chapters/Multirotor.tex", "max_issues_repo_name": "Rutvikrj26/AER1216", "max_issues_repo_head_hexsha": "c809846ba49d086415827829ec57ef42ae37ba9c", "max_issues_repo_licenses": ["MIT"], "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/Chapters/Multirotor.tex", "max_forks_repo_name": "Rutvikrj26/AER1216", "max_forks_repo_head_hexsha": "c809846ba49d086415827829ec57ef42ae37ba9c", "max_forks_repo_licenses": ["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.2767295597, "max_line_length": 697, "alphanum_fraction": 0.7610567515, "num_tokens": 2607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6395109809782137}}
{"text": "\\chapter{Multi-scale Analysis}\n\\section{Introduction}\n\nIn this chapter, the tools for multi-scale and multi-resoltuion\nprocessing (analysis, synthesis and fusion) will be presented. Most of\nthe algorithms are based on pyramidal approaches. These approaches\nwere first used for image compression and they are based on the fact\nthat, once an image has been low-pass filtered it does not have\ndetails beyond the cut-off frequency of the low-pass\nfilter any more. Therefore, the image can be subsampled -- decimated -- without\nany loss of information.\n\nA pyramidal decomposition is thus performed applying the following 3\nsteps in an iterative way:\n\\begin{enumerate}\n  \\item Low pas filter the image $I_{n}$ in order to produce $F(I_n)$;\n  \\item Compute the difference $D_n = I_n - F(I_n)$ which corresponds\n  to the details at level $n$;\n  \\item Subsample $F_(I_n)$ in order to obtain $I_{n+1}$.\n\\end{enumerate}\n\nThe result is a series of decrasing resolution images $I_k$ and a\nseries of decreasing resolution details $D_k$.\n\n\n\n\\section{Morphological Pyramid}\\label{secMorphoPyr}\n\nIf the smoothing filter used in the pyramidal analysis is a\nmorphological filter, one cannot safely subsample the filtered image\nwithout loss of information. However, by keeping the details possibly\nlost in the down-sampling operation, such a decomposition can be used.\n\nThe Morphological Pyramid is an approach to such a\ndecomposition. Its computation process is an iterative analysis\ninvolving smoothing by the morphological filter, computing the\ndetails lost in the smoothing, down-sampling the current image, and\ncomputing the details lost in the down-sampling.\n\n\\input{MorphologicalPyramidAnalysisFilterExample.tex}\n\n\\input{MorphologicalPyramidSynthesisFilterExample.tex}\n\n\n\\subsection{Morphological Pyramid Exploitation}\nOne of the possible uses of the morphological pyramid is the\nsegmentation of objects -- regions -- of a particular scale.\n\n\\input{MorphologicalPyramidSegmenterExample.tex}\n\nThis same approach can be applied to all the levels of the\nmorphological pyramid analysis.\n\n\\input{MorphologicalPyramidSegmentationExample.tex}\n", "meta": {"hexsha": "39d1531f81ad8c8d05b1eb5c480d0b5cb34a1bdf", "size": 2123, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/SoftwareGuide/Latex/MultiScaleAnalysis.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": "2018-03-30T18:05:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-28T01:03:49.000Z", "max_issues_repo_path": "Documentation/SoftwareGuide/Latex/MultiScaleAnalysis.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/MultiScaleAnalysis.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": "2015-10-08T12:04:06.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-19T08:00:47.000Z", "avg_line_length": 38.6, "max_line_length": 79, "alphanum_fraction": 0.8035798398, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6395092448598105}}
{"text": "%\\pagestyle{plain}\n\n\\chapter{Event Detection}\nIn this chapter, we will introduce the mechanism of event detection in this project. \nWe first apply some noise reduction or audio enhancement technique on the training data for our events. \nThen we extract MFCC features from the training clips. \nAfter getting features, a Gaussian Mixture Model is built on those features. \n\n\\section{Audio Enhancement}\nBecause the audios downloaded from SSEs are uploaded by other users. \nThose clips are recorded by various types of devices and in different environments. \nHence we need to apply a noise reduction step to enhance the audio clips. \n\nAmong algorithms for speech enhancement, spectral subtraction was one of the first algorithms proposed. \nAlthough it was originally proposed for speech enhancement, we use it in our project for noise is pretty much the same in speech or in more general audios. \nThe basic principles is that we assume the clean signal add some additive noise becomes the audio we get. \nThen if we subtract the noise spectrum from the audio, we may get signal close to the original clean one. \n\nMathematically speaking, assume the input signal is $ y(t) = x(t) + n(t)$, where the signal $x(t)$ is the signal of interest and $n(t)$ is the additive noise. \nThe audio enhancement process takes on the following steps:\n\\begin{enumerate}\n\\item The input signal $y(t)$ is resampled to 16kHz and multiple channels are averaged to one channel. \n\\item Using short time Fourier transform (STFT), we obtain $Y_i(k) = X_i(k) + N_i(k)$, where $i$ is the frame indices and $k$ is the frequency bin indices of the spectrum. \n\\item The Minimum Statistics (MS) estimator \\cite{martin2001noise} is used to the noise power spectral density from $y(t)$. \n\\item Spectral subtraction is used to remove the estimated noice spectrum from the input spectrum $Y_i(k)$. \nThen we could get an estimated clean signal spectrum: $\\hat{X_i}(k)$. \n\\item Applying inverse short time Fourier transform (ISTFT) on $\\hat{X_i}(k)$ to get the estimated clean signal $\\hat{x}(t)$. \n\\end{enumerate}\n\nA speech processing toolbox for Matlab called VoiceBox is used for spectral subtraction\\footnote{\\url{http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html}}.\n% noise subtraction example here \n\n\\section{Feature Extraction}\nSince the audio data is downloaded from a sound website where clips are crowdsourced, the clips are in various format. \nWe converted all audio clips to WAV format and averaged the channels into one if it has multiple channels. \nMoreover, clips are all downsampled to 16khz sample rate for feature extraction. \n\nFor the audio data, mel-frequency cepstrum coefficients (MFCCs) features are a widely-used feature. \nIt was brought up by Davis and Mermelstein in the 1980s. \nMFCC features extract the spectral envelope from spectrums of audio frames.\nBasically, the process of extracting MFCCs start by applying Fast Fourier transform (FFT) on framed audio. \nFFT transform audio data from Amplitude-Time domain (frame) into Amplitude-Frequency domain (spectrum).  \nAs each audio frame is transformed into a spectrum, the spectral envelope is extracted by Inverse FFT (IFFT).\n\nActually, one more filtering is performed before applying IFFT on spectrums. \nBecause MFCC features are based on human perceptual experiment, and human's ear is like a natural filter, where low-frequency area has more filter and high-frequency area has less. So a nonlinear function is applied to original spectrum to transform the frequency axis into the mel scale. \nA popular formula to convert $f$ herts into $m$ mel is:  \n\\begin{equation}\n\tm = 2595 \\times \\log_{10}(1+\\frac{1}{700})\n\\end{equation} \n\n% melscale.eps on 5566\n\\begin{figure}[htb]\n\\centering\n\\input{figure/eventdetect/melscale}\n\\caption{Mel scale versus hertz scale}\n\\label{fig:melscale}\n\\end{figure}\n\nFigure \\ref{fig:melscale} shows the non-linear transformation of hertz scale to mel scale. \nWe could see that the slope of the curve are decreasing as the pitch goes up in hertz scale. \nBecause of this feature of suppressing the higher frequency bands, MFCC enables a focus of the more useful range of bands in lower scale \\cite{davis1980comparison}.\n\n% Paraphrase !!!\n\n\\section{Model Selection}\nFrom the previous feature extraction process, we could a matrix representation for an audio clip. \nThe column number stands for the dimension of the features and each row corresponds to one observation. \nFrom these data, we need to build a model that can capture the overall feature distribution and also are convenient to use for testing data.\n\nFor this goal, Gaussian Mixture Model (GMM) is used. \nFirst, a multivariate gaussian distribution has the following probability density:\n\n% multivariate gaussian \n\\begin{equation}\n \\mathcal{N}(\\mathbf{x}| \\mathbf{\\mu}, \\Sigma) = \n\\frac{1}{\\sqrt{(2\\pi)^D|\\Sigma|}}e^{-\\frac{1}{2}(\\mathbf{x}-\\mathbf{\\mu})^T \\Sigma^{-1} (\\mathbf{x}-\\mathbf{\\mu})}\n\\end{equation}\n\nIn this equation, $\\mathbf{\\mu}$ and $\\mathbf{\\Sigma}$ are all vectors in $D$ dimensions, for discribing high dimensional data. \nA gaussian mixture model (or density) is a weighted sum of N gaussian densities. \nTypically, these gaussian densities have the same dimension, say $D$, and each gaussian are called a component.  \nPut many gaussian distributions together, we could get the density function for GMM: \n\n% GMM density function\n\\begin{equation}\nP(\\mathbf{x}|\\mathbf{\\pi},\\mathbf{\\mu},\\Sigma) = \\sum_{k = 1}^{M} \\pi_k\n\\mathcal{N}(\\mathbf{x}|\\mathbf{\\mu}_k, \\Sigma_k),\n\\end{equation} \n\nThe intuition of using GMM to model the audio events is that the individual component densities of a multi-model density may model some underlysing set of acoustic classes \\cite{reynolds1995robust}. \nLike in speech, a words may consist of some vowels and consonants. \nAn audio event is naturally more complicated than speech, and may therefore contain more characteristics. \nTherefore, we use different gaussian densities with different $\\mathbf{\\mu}$ and $\\mathbf\\sigma$, where the $\\mathbf\\mu$ may capture the overall value for one class and the $\\mathbf\\sigma$ shows the variation of that class.  \nWhen these densities are added together, forming a GMM, they can have a good depiction of some unusual distributions. \n\n%Before training GMMs for event training data, we first apply K-means algorithm on the data. \n%K-means is also an unsupervised clustering method. \n%It uses a Expectation-Maximization step to update the cluster centroid. \n%Because K-means has a faster speed for iterating than GMMs, so we first run K-means and use its centroid result as initials for further iterating of GMMs. \n%This part use the gaussian toolbox provided by Matlab\\footnote{\\url{http://cn.mathworks.com/help/stats/gmdistribution-class.html}} . \n\n\n\\section{Training Data Selection}\nAs previously mentioned, many of the clips in those Sound Search Engines are crowdsourced. \nHence, the quality of those clips are not guaranteed to be suitable as our event training data.    \nWe need to select out those data which are similar, and discard those outliers. \nBecause outliers are very likely to be a noise, thus adding no knowledge for our event models, perhaps even bring bad effects. \n\nTherefore, in our project, we added a step for comparing the similarity of the audio clips, and cluster similar clips together, while leaving others clips out. \nYet signal data of the audio clips are in different volume, and different duration, it is hard to directly compare their similarity. \nSo we resort to the distance between their corresponding GMMs. \nBecause the trained GMM are in the same dimension for different audio clips, and GMM represent the overall features, it is reasonable to cluster similar GMMs together. \n\nIn order to measure the distance between GMMs, we use Kullback-Leibler (KL) divergence. \nKL divergence is a measure of the difference between two probability distributions. \nMore precisely, KL divergence of $Q$ from $P$, denoted by $KL(P||Q)$, is a measure of the information loss when we use $Q$ to approximate $P$.\n\nFor continuous random variables $\\mathbf{x}$ and two distributions $P$ and $Q$, the KL divergence of $Q$ from $P$ is defined as:\n\\begin{equation}\nKL(P||Q) = \\int_{-\\infty}^{+\\infty}\\ln(\\frac{p(\\mathbf{x})}{q(\\mathbf{x})})p(\\mathbf{x})\\mathrm{d}x,\n\\label{eq:kl}\n\\end{equation}\nwhere $p(\\mathbf{x})$ and $q(\\mathbf{x})$ are the density functions of $P$ and $Q$.\nThe divergence satisifies three properties: \n\\begin{enumerate}\n\\item{Self similarity: $KL(P||P) = 0$}. \n\\item{Self identification: $KL(P||Q) = 0$, only if $P = Q$}. \n\\item{Non-Negativity: $KL(P||Q) >= 0$ for any $P, Q$}. \n\\end{enumerate}\n\nBecause of these properties, KL divergence is used in many aspects of speech recognition \\cite{olsen2003efficient}. \nBut we need to take notice that KL divergence is not a distance because it is not symmetric: $KL(P||Q) \\neq KL(Q||P)$. \nFor two gaussian distributions, the KL divergence has a closed formed expression. \nBut for two gaussian mixture models, there is no such closed form expression. \nTo tackle this issue, we use an approximation method to the KL divergence proposed in \\cite{hershey2007approximating}\nIt uses ``variational approximation'' for calculating KL divergence. \nWe use the \\textit{gaussmixk} function in VoiceBox toolbox for implementing the approximated KL divergence\\footnote{\\url{http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/doc/voicebox/gaussmixk.html}}. \n\n\\section{Summary}\nThe method we propose for audible event detection are introduced in this chapter. \nWe first apply a noise reduction technique on the downloaded audio clips. \nThis audio enhancement process uses Minimum Statistics estimator to estimate the noise power spectral density. \nThen this estimated noise are subtracted from the input signal to get a more cleaned signal for event models trainging. \nFeature extraction are also reviewed in this chapter.  \nThe features we use in this task are MFCC features. \nThey are notable for good capture of audio features because of the non-linear mel scale could suppress higher frequency bands and put more focus on the lower part. \nFrom the extracted features, we build Gaussian Mixture Models (GMMs) on them. \nThe reason that GMMs are chosen against other models is that they comprised of multiple gaussian distributions, which are called components. \nThese components could be used to model the underlying sound generating process and help us model more complicated sound events. \nIn the end, we touch on the problem of removing some low-quality sound clips. \nThis removal process is carried out by clustering audio clips. \nWe use an approximation for Kullback-Leibler (KL) divergence to represent the distance between different GMMs, and thus, can also be viewed as the distance between audio clips. \nClip features which have similar GMMs are clustered together, and we stop the clustering process when the divergence is large enough. \nThrough this way, we could remove some noisy clips for their feature data is too far away from others. \n", "meta": {"hexsha": "79aa086d23b3ffaeace12fc7a3478b45dd38dd2c", "size": 11031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/eventdetect.tex", "max_stars_repo_name": "findslowly/thesis", "max_stars_repo_head_hexsha": "177115f287b00d81434a13b00dd449ed9944607d", "max_stars_repo_licenses": ["MIT"], "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/eventdetect.tex", "max_issues_repo_name": "findslowly/thesis", "max_issues_repo_head_hexsha": "177115f287b00d81434a13b00dd449ed9944607d", "max_issues_repo_licenses": ["MIT"], "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/eventdetect.tex", "max_forks_repo_name": "findslowly/thesis", "max_forks_repo_head_hexsha": "177115f287b00d81434a13b00dd449ed9944607d", "max_forks_repo_licenses": ["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.7115384615, "max_line_length": 289, "alphanum_fraction": 0.7769921131, "num_tokens": 2641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6394989421454439}}
{"text": "\n\\subsection{Testing for stationarity with Dickey-Fuller (DF) and Augmented Dicky-Fuller (ADF)}\n\n\\subsubsection{Stationarity}\n\n\\subsubsection{Unit roots}\n\n\n\\subsubsection{Integration order}\n\n\\subsubsection{Dickey-Fuller}\n\nThe Dickey-Fuller test tests if there is a unit root.\n\nThe AR(\\(1\\)) model is:\n\n\\(y_t=\\alpha + \\beta y_{t-1}+\\epsilon_t\\)\n\nWe can rewrite this as:\n\n\\(\\Delta y_t=\\alpha + (\\beta -1)y_{t-1}+\\epsilon_t\\)\n\nWe test if \\(\\beta -1)=0\\).\n\nIf the coefficient on the last term is \\(1\\) we have a random walk, and the process is non-stationary.\n\nIf the last term is \\(<1\\) then we have a stationary process.\n\n\\subsubsection{Variation: Removing the drift}\n\nIf our model has no intercept it is:\n\n\\(y_t=\\beta y_{t-1}+\\epsilon_t\\)\n\n\\(\\Delta y_t=(\\beta -1)y_{t-1}+\\epsilon_t\\)\n\n\\subsubsection{Variation: Adding a deterministic trend}\n\nIf our model has a time trend it is:\n\n\\(y_t=\\alpha \\beta y_{t-1}+\\gamma t + \\epsilon_t\\)\n\n\\(\\Delta y_t=\\alpha + (\\beta -1)y_{t-1}+\\gamma t+\\epsilon_t\\)\n\n\\subsubsection{Augmented Dickey-Fuller}\n\nWe include more lagged variables.\n\n\\(y_t=\\alpha + \\beta t + \\sum_i^p \\theta_i y_{t-i}+\\epsilon_t\\)\n\nIf no unit root, can do normal OLS?\n\n\n", "meta": {"hexsha": "ac5592671f367548fce0c888eb00a428efa2a197", "size": 1173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticWold/01-02-stationarity.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/01-02-stationarity.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/02-02-stationarity.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.7222222222, "max_line_length": 102, "alphanum_fraction": 0.7007672634, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6392157007544894}}
{"text": "% !TEX root =  manual.tex\n\\section{PCA Analysis}\\label{sec:pca}\n\nThe emulator is dependent on the principal component analysis (PCA). PCA also provides insight of its own. The principal components show which linear combinations of observables are likely to be well constrained, and which combinations are uninteresting. Further, one can also estimate which parameters are driving specific principal components, at least within a linear picture.\n\nPCA is performed by the following command,\n\n\\commandline{madai\\_pca\\_decompose stat1}\n\nWhen running, \\path{madai_pca_decompose} will read the parameters file \\path{stat1/settings.dat}. The PCA analysis uses the following parameters:\n\n\\begin{quote}\n{\\tt MODEL\\_OUTPUT\\_DIR \"./model\\_output\"}\\\\\n{\\tt EXPERIMENTAL\\_RESULTS\\_FILE \"./experimental\\_results.dat\"}\\\\\n$\\vdots$\n\\end{quote}\nThe PCA analysis uses the experimental information only in calculating the error for comparing a model value to the experimental value, each of which has its own error.\n\n\\path{madai_pca_decompose} produces a file \\path{stat1/PCADecomposition.dat}. This file holds the eigenvalues of $\\Xi$ (the strength of the principal components) and the eigenvectors of $\\Xi$ (which define the rotation of $\\tilde{y}$ into the principal components, $z$. If $M$ experimental values are written down, the PCA analysis will determine and record the information recorded to rotate the vector $y_1\\cdots y_M$ to $z_1\\cdots z_M$. The emulator will in turn use only those components $z_1\\cdots z_{M_Z}$ that correspond to the largest eigenvalues, $\\lambda_i$, of the matrix $\\Xi$. The number of components retained, $M_Z$, can be chosen during the emulator tuning or initialization.\n\nThe \\path{madai_pca_decompose} file has the following format:\n\\begin{quote}\n{\\tt OUTPUT\\_MEANS}\\\\\n$M~~\\leftarrow$ Number of observables.\\\\\n$y_1$~~~$\\leftarrow$ Means for observables averaged over the $N$ model runs.\\\\\n$y_2$~~~$\\swarrow$\\\\\n$\\vdots$\\\\\n$y_M$\\\\\n{\\tt OUTPUT\\_UNCERTAINTY\\_SCALES}\\\\\n$M~~\\leftarrow$ Number of observables.\\\\\n$\\sigma_1$~~~$\\leftarrow$ Uncertainties that incorporate both experimental and model uncertainties.\\\\\n$\\sigma_2$~~~$\\leftarrow$ If different model runs have different $\\sigma_i$, model error is averaged over runs.\\\\\n$\\sigma_3$~~~$\\swarrow$\\\\\n$\\vdots$\\\\\n$\\sigma_M$\\\\\n{\\tt OUTPUT\\_PCA\\_EIGENVALUES}\\\\\n$M$~~$\\leftarrow$ Number of observables\\\\\n$\\lambda^{(M)}$~$\\leftarrow$ Smallest eigenvalue of $\\Xi_{ab}$ in Eq. \\eqref{eq:Xidef}\\\\\n$\\lambda^{(M-1)}$~$\\swarrow$\\\\\n$\\vdots$\\\\\n$\\lambda^{(1)}$~~~~$\\leftarrow$ Largest eigenvalue\\\\\n{\\tt OUTPUT\\_PCA\\_EIGENVECTORS}\\\\\n$M~~~~M$\\\\\n\\vspace*{-10pt}\n\\[\n\\hspace*{-130pt}\n\\begin{array}{cccc}\n~~~~\\xi_1^{\\rm(M)}&\\xi_1^{\\rm(M-1)}&\\cdots&\\xi_1^{(1)}\\\\\n~~~~\\xi_2^{\\rm(M)}&\\xi_2^{\\rm(M-1)}&\\cdots&\\xi_2^{(1)}\\\\\n~~~~\\vdots&\\vdots&\\ddots&\\vdots\\\\\n~~~~\\xi_M^{\\rm(M)}&\\xi_M^{\\rm(2)}&\\cdots&\\xi_M^{(1)}\\\\\n\\end{array} ~~~\\leftarrow{\\rm These~are~the~normalized~eigenvectors}\n\\]\n{\\tt END\\_OF\\_FILE}\n\\end{quote}\n\nBefore building an emulator, the experimental observables and the corresponding model values are rotated into a new basis. The rotation can be stated as,\n\\[\nz_a=U_{ab}y_b,~~y_a=U^{-1}_{ab}z_b.\n\\]\nAs described in Eq. (\\ref{eq:pcarotation}), the rotation matrix is comprised of eigenvectors of the matrix $\\Xi_{ab}=\\langle \\tilde{y}_a\\tilde{y}_b\\rangle$, where $\\tilde{y}_a\\equiv (y_a-\\langle y_a\\rangle)/\\sigma_a$, with $\\langle y_a\\rangle$ denoting $y_a({\\bf x})$ averaged over model values calculated from the parameters taken from the prior distribution.\n", "meta": {"hexsha": "9f71a84aaa1dd74c6ba3cf02f19edf2450de1201", "size": 3515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/manual/pca.tex", "max_stars_repo_name": "scottedwardpratt/MADAI", "max_stars_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-04-02T17:37:35.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-28T20:14:23.000Z", "max_issues_repo_path": "doc/manual/pca.tex", "max_issues_repo_name": "scottedwardpratt/MADAI", "max_issues_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "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/manual/pca.tex", "max_forks_repo_name": "scottedwardpratt/MADAI", "max_forks_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-08-20T14:07:41.000Z", "max_forks_repo_forks_event_max_datetime": "2017-03-28T20:15:23.000Z", "avg_line_length": 56.6935483871, "max_line_length": 691, "alphanum_fraction": 0.7305832148, "num_tokens": 1068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6392156911042582}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Author: David Oniani\n%\n%  _         _____   __  __\n% | |    __ |_   _|__\\ \\/ /\n% | |   / _` || |/ _ \\\\  /\n% | |__| (_| || |  __//  \\\n% |_____\\__,_||_|\\___/_/\\_\\\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Document Definition\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\documentclass{article}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Packages and Related Settings\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Global, document-wide settings\n\\usepackage[english]{babel}\n\\usepackage[margin=1in]{geometry}\n\\usepackage[utf8]{inputenc}\n\n% Other packages\n\\usepackage{caption}\n\\usepackage{hyperref}\n\\usepackage{mathtools}\n\\usepackage{minted}\n\\usepackage{sectsty}\n\\usepackage{xcolor}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Setup\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Black-blue color\n\\colorlet{bb}{black!50!blue}\n\n% Orange color\n\\definecolor{orange}{HTML}{f0360e}\n\n% PDF information and nice-looking urls\n\\hypersetup{%\n    pdfauthor={David Oniani},\n    pdftitle={Bresenham's Circle Drawing Algorithm},\n    pdfsubject={bresenham, circle, geometry},\n    pdfkeywords={bresenham, circle, geometry},\n    pdflang={English},\n    colorlinks=true,\n    linkcolor={bb},\n    citecolor={bb},\n    urlcolor={bb}\n}\n\n% Change section color\n\\sectionfont{\\color{orange}}\n\n% Remove indentations from paragraphs\n\\setlength{\\parindent}{0pt}\n\n% Setting style for the minted package\n\\setminted{\n    fontsize=\\small,\n    frame=lines,\n    linenos,\n}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Author(s), Title, and Date\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Author(s)\n\\author{David Oniani\\\\\n        \\href{mailto:onianidavid@gmail.com}{onianidavid@gmail.com}}\n\n% Title\n\\title{\\textcolor{orange}{\\textit{Bresenham's Circle Drawing Algorithm}}}\n\n% Date\n\\date{\\today}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Beginning of Document\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Derivation\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Derivation}\n\nLet the radius of the circle centered at \\((0, 0)\\) be given and equal \\(r\\). Any point \\((x, y)\\)\non the circle satisfies the following:\n\\begin{equation}\n    x^2 + y^2 = r^2\n\\end{equation}\n\nConsider the upper half of the first quadrant. The next point could then be placed either to the\neast \\((x + 1, y)\\) or southeast \\((x + 1, y - 1)\\). The errors for both scenarios are:\n\\begin{align}\n    &e(x + 1, y) = {(x + 1)}^2 + y^2 - r^2\\\\\n    &e(x + 1, y - 1) = {(x + 1)}^2 + {(y - 1)}^2 - r^2\n\\end{align}\n\nThe decision parameter \\(d\\) representing the total error is defined as follows:\n\\begin{equation}\n    d = e(x + 1, y) + e(x + 1, y - 1)\n      = 2{(x + 1)}^2 + y^2 + {(y - 1)}^2 - 2r^2\n\\end{equation}\n\nSince the \\(x\\) coordinate always increases, the next point is some \\((x + 1, y_n)\\) and we get:\n\\begin{equation}\n    d_n = e(x + 2, y_n) + e(x + 2, y_n - 1)\n        = 2{(x + 2)}^2 + {y_n}^2 + {(y_n - 1)}^2 - 2r^2\n\\end{equation}\n\nThe difference is equal to the following:\n\\begin{equation}\n    d_n - d = 2(2x + 3) + \\big({y_n}^2 - y^2\\big) + \\big({(y_n - 1)}^2 - {(y - 1)}^2\\big)\n\\end{equation}\n\nFinally, we have:\n\\begin{align}\n    &d_n - d = 2(2x + 3) &&\\implies d_n\n             = d + 4x + 6 &&\\text{ if } d \\leq 0\\ (y_n = y)\\\\\n    &d_n - d = 2(2x + 3) - 4y + 4 &&\\implies d_n\n             = d + 4(x - y) + 10 &&\\text{ if } d > 0\\ (y_n = y - 1)\\\\\n    &d_0 = 2{(0 + 1)}^2 + r^2 + {(r - 1)}^2 - 2r^2 &&\\implies d_0\n         = 3 - 2r &&\\text{ at initial point } (0, r)\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Implementation\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\clearpage\n\\section{Implementation}\n\n\\begin{itemize}\n    \\item Time Complexity: \\(O(r)\\) where \\(r\\) is the radius of the circle\n    \\item Space Complexity: \\(O(1)\\)\n\\end{itemize}\n\n\\begin{figure}[H]\n    \\inputminted{python}{bresenham.py}\n    \\caption*{A Python Implementation of Bresenham's Circle Drawing Algorithm}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% End of Document\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\end{document}\n", "meta": {"hexsha": "4cfd4d3ef0170b8f5f941ac066658fc7271f53e0", "size": 5200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bresenham.tex", "max_stars_repo_name": "oniani/bresenham", "max_stars_repo_head_hexsha": "a01bd090a578372dbfacbcce9b730b446a5c4cb6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bresenham.tex", "max_issues_repo_name": "oniani/bresenham", "max_issues_repo_head_hexsha": "a01bd090a578372dbfacbcce9b730b446a5c4cb6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bresenham.tex", "max_forks_repo_name": "oniani/bresenham", "max_forks_repo_head_hexsha": "a01bd090a578372dbfacbcce9b730b446a5c4cb6", "max_forks_repo_licenses": ["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.298136646, "max_line_length": 100, "alphanum_fraction": 0.3996153846, "num_tokens": 1292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754471, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.6391890223048489}}
{"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 XIV 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{Multiple Integrals $-$ 15.1}\n\nIn calculus I, integrals were defined as the area, $A$, under a curve, where:\n\n$$A=\\lim_{x\\to\\infty}\\sum_{i=1}^n f(x_i^*) \\Delta x$$\n\nThis formula was simplified to what is known as the integral:\n\n$$\\int_a^b f(x)\\,dx$$\n\nThe volume of a multivariable function, then, is given by:\n\n$$V \\approx \\sum_{i=1}^m \\sum_{j=1}^n f(x_{ij}^*, y_{ij}^*) \\Delta A$$\n$$V=\\lim_{m,n\\to\\infty}\\sum_{i=1}^m \\sum_{j=1}^n f(x_{ij}^*, y_{ij}^*) \\Delta A $$\n$$V=\\iint_R f(x,y)\\,dA$$\n\n\\subsection{Double Integral Properties}\n\nDouble integrals have many of the same properties as single integrals:\n\n$$1. \\iint_R [f(x,y)+g(x,y)]\\,dA=\\iint_R f(x,y)\\,dA + \\iint_R g(x,y)\\,dA$$\n\nIf $c$ is a constant:\n\n$$\\iint_R cf(x,y)\\,dA=c\\iint_R f(x,y)\\,dA$$\n\nIf $f(x,y)\\geq g(x,y)$ for all $(x,y)$, then:\n\n$$\\iint_R f(x,y)\\,dA \\geq \\iint_R g(x,y)\\,dA$$\n\nIf $g(x)$ is a function of $x$ and $h(y)$ is a function of $y$:\n\n$$\\iint_R g(x)h(y) dA=\\int_a^b g(x)\\,dx\\int_c^d h(y)\\,dy$$\n\n\\subsection{Iterated Integrals}\n\nThe double integral, $\\iint_R f(x,y)\\,dA$, may be broken up in order to be calculated with ease:\n\n$$\\iint_R f(x,y) dA=\\int_a^b \\int_c^d f(x,y)\\,dy\\,dx$$\n\nThis may be solved using the method of partial integrals, where, much like partial derivatives, only one of the variables is treated as a variable at once. As a result of this, just like with partial derivatives, the order that the operation is done in yields the same result no matter what:\n\n$$\\int_a^b \\int_c^d f(x,y)\\,dy\\,dx=\\int_c^d\\int_a^b f(x,y)\\,dx\\,dy$$\n\n\\subsection{Fubini's Theorem}\n\nIf $f(x,y)$ is continuous on $R=\\{(x,y)|a\\leq x\\leq b, c\\leq y\\leq d\\}$\n\n$$\\iint_R f(x,y) dA=\\int_a^b \\int_c^d f(x,y)\\,dy\\,dx=\\int_c^d\\int_a^b f(x,y)\\,dx\\,dy$$\n\n\\end{document}\n", "meta": {"hexsha": "d1642c8201421e0e3019963029b2f5fceda95353", "size": 3157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture14.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/Lecture14.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/Lecture14.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": 29.7830188679, "max_line_length": 291, "alphanum_fraction": 0.5929680076, "num_tokens": 1073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.6391890165889557}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 2.2 Covariant derivative of $v_{ab}$}\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   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   # template for covariant derivative of a vector\n\n   derivU := \\nabla_{a}{A?^{b}} -> \\partial_{a}{A?^{b}} + \\Gamma^{b}_{c a} A?^{c}.\n   derivD := \\nabla_{a}{A?_{b}} -> \\partial_{a}{A?_{b}} - \\Gamma^{c}_{b a} A?_{c}.\n\n   vab := v_{a b} -> A_{a} B_{b}.\n   iab := A_{a} B_{b} -> v_{a b}.\n\n   pab := \\partial_{a}{A_{b}} B_{c} -> \\partial_{a}{A_{b} B_{c}} - A_{b} \\partial_{a}{B_{c}}.\n\n   # create an object\n\n   Dvab := \\nabla_{a}{v_{b c}}.     # cdb (ex-0202.101,Dvab)\n\n   # apply the rule, then simplify\n\n   substitute     (Dvab,vab)        # cdb (ex-0202.102,Dvab)\n   product_rule   (Dvab)            # cdb (ex-0202.103,Dvab)\n   substitute     (Dvab,derivD)     # cdb (ex-0202.104,Dvab)\n   substitute     (Dvab,derivU)     # cdb (ex-0202.105,Dvab)\n   distribute     (Dvab)            # cdb (ex-0202.106,Dvab)\n   substitute     (Dvab,pab)        # cdb (ex-0202.107,Dvab)\n   canonicalise   (Dvab)            # cdb (ex-0202.108,Dvab)\n   substitute     (Dvab,iab)        # cdb (ex-0202.109,Dvab)\n   sort_product   (Dvab)            # cdb (ex-0202.110,Dvab)\n\\end{cadabra}\n\n\\begin{align}\n   \\cdb{ex-0202.101} &= \\Cdb{ex-0202.102}\\\\\n                     &= \\Cdb{ex-0202.103}\\\\\n                     &= \\Cdb{ex-0202.104}\\\\\n                     &= \\Cdb{ex-0202.105}\\\\\n                     &= \\Cdb{ex-0202.106}\\\\\n                     &= \\Cdb{ex-0202.107}\\\\\n                     &= \\Cdb{ex-0202.108}\\\\\n                     &= \\Cdb{ex-0202.109}\\\\\n                     &= \\Cdb{ex-0202.110}\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "45938b399f6a94007664b248efaa214756e6fe5a", "size": 1931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0202.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-0202.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-0202.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": 33.8771929825, "max_line_length": 94, "alphanum_fraction": 0.4899016054, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6391890142858403}}
{"text": "\\section{Lines}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the vector, parametric, and symmetric equations of a line.\n  \\item Determine whether a point is on a given line.\n  \\item Determine whether two lines intersect.\n  \\item Find the angle between two lines.\n  \\item Find the projection of a point onto a line.\n  \\end{enumerate}\n\\end{outcome}\n\nWe can use the concept of vectors and points to find equations for\nlines in $\\R^n$. Consider a straight line $L$ that passes through a\npoint $P$ in the direction given by a non-zero vector $\\vect{d}$.\n\\begin{center}\n  \\begin{tikzpicture}[rotate=10]\n    % Note: I deliberately made the red a bit lighter and the blue a bit\n    % darker, so that it will also look okay in black-and-white.\n    \\draw[red!80](-4,0) -- node [above=3pt, pos=0.875] {$L$} (9,0);\n    \\draw[->,thick,blue!80!black](0,0) -- node[above left] {$\\vect{d}$} (2,0);\n    \\fill (0,0) circle [radius=2.2pt] node [above=3pt] {$P$};\n    \\fill (5,0) circle [radius=2.2pt] node [above=3pt] {$Q$};\n  \\end{tikzpicture}\n\\end{center}\nThe line $L$ is infinitely long in both directions, although the\npicture only shows a finite part of it. To find an equation for this\nline, first suppose that $Q$ is an arbitrary point on $L$. Then the\nvector $\\longvect{PQ}$ is parallel to $\\vect{d}$. In other words,\nthere exists some real number $t$ such that\n\\begin{equation*}\n  \\longvect{PQ} = t\\,\\vect{d}.\n\\end{equation*}\nIf $\\vect{p}$ is the position vector of $P$ and $\\vect{q}$ is the\nposition vector of $Q$, we can write\n\\begin{equation*}\n  \\longvect{PQ} = \\vect{q}-\\vect{p}.\n\\end{equation*}\nPutting together the last two equations, we get $\\vect{q}-\\vect{p} =\nt\\,\\vect{d}$, which we can write as\n\\begin{equation*}\n  \\vect{q} = \\vect{p} + t\\,\\vect{d}.\n\\end{equation*}\nThis is called the \\textbf{vector equation}%\n\\index{vector equation!of a line}%\n\\index{line!vector equation} of the line $L$. The vector $\\vect{d}$ is\ncalled the \\textbf{direction vector}%\n\\index{direction vector}%\n\\index{vector!direction vector}, and $t$ is called a\n\\textbf{parameter}%\n\\index{parameter}. The parameter $t$ can be any real number; each time\nwe plug in a different number for $t$, we get a different point $Q$ on\nthe line. The following picture shows the effect of the parameter:\n\\begin{center}\n  \\begin{tikzpicture}[rotate=10]\n    % Note: I deliberately made the red a bit lighter and the blue a bit\n    % darker, so that it will also look okay in black-and-white.\n    \\draw[red!80](-4,0) -- node [above=3pt, pos=0.92] {$L$} (10,0);\n    \\draw[->,thick,blue!80!black](0,0) -- node[above=3pt] {$\\vect{d}$} (2,0);\n    \\draw[->,thick,blue!80!black](3,-2) -- node[below=3pt] {$\\vect{p}$} (0,0);\n    \\fill (0,0) circle [radius=2.2pt] node [above=3pt] {$P$};\n    \\fill (-2,0) circle [radius=2.2pt] node [below=9pt] {$t=-1$};\n    \\fill (0,0) circle [radius=2.2pt] node [below=10pt] {$t=0$};\n    \\fill (2,0) circle [radius=2.2pt] node [below=10pt] {$t=1$};\n    \\fill (4,0) circle [radius=2.2pt] node [below=10pt] {$t=2$};\n    \\fill (6,0) circle [radius=2.2pt] node [below=10pt] {$t=3$};\n    \\fill (8,0) circle [radius=2.2pt] node [below=10pt] {$t=3$};\n    \\fill (3,-2) circle [radius=2.2pt] node [right=3pt] {$0$};\n  \\end{tikzpicture}\n\\end{center}\nThe following definition summarizes the above.\n\n\\begin{definition}{Vector equation of a line}{vector-equation-of-line}\n  Let $\\vect{p}$ be a vector and $\\vect{d}$ a non-zero vector. Then\n  \\begin{equation*}\n    \\vect{q} = \\vect{p} + t\\,\\vect{d}\n  \\end{equation*}\n  is the \\textbf{vector equation}%\n  \\index{vector equation!of a line}%\n  \\index{line!vector equation} of a straight line $L$. Specifically,\n  as the parameter $t$ ranges over the real numbers, $\\vect{q}$ ranges\n  over the position vectors of all the points $Q$ on the line $L$.\n  The vector $\\vect{d}$ is called the \\textbf{direction vector}%\n  \\index{direction vector}%\n  \\index{vector!direction vector} of the line.\n\\end{definition}\n\n\\begin{example}{A line from a point and a direction vector}{line-point-and-direction-vector}\n  Find a vector equation for the line which contains the point\n  $P = (2,0,3)$ and has direction vector\n  $\\vect{d} = \\mat{1,2,1}^T$.\n\\end{example}\n\n\\begin{solution}\n  The position vector of the point $P$ is\n  $\\vect{p}=\\mat{2,0,3}^T$. The equation of the line is\n  $\\vect{q}= \\vect{p} + t\\,\\vect{d}$, which we can write as\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{A line from two points}{line-from-two-points}\n  Find a vector equation for the line through the points\n  $P = (1,2,0,1)$ and $R = (2,-4,6,3)$.\n\\end{example}\n\n\\begin{solution}\n  We can use $P$ as the base point; its position vector is\n  $\\vect{p}=\\mat{1,2,0,1}^T$. We can use\n  $\\vect{d}=\\longvect{PR}=\\mat{1,-6,6,2}$ as the direction vector. Then\n  a vector equation of the line is\n  $\\vect{q} = \\vect{p} + t\\,\\vect{d}$,\n  which we can also write as\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 0 \\\\ 1\\end{mymatrix}\n    + t \\begin{mymatrix}{r} 1 \\\\ -6 \\\\ 6 \\\\ 2\\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWhen we write a vector equation in the form\n\\begin{equation*}\n  \\begin{mymatrix}{c} x_1 \\\\ x_2 \\\\ \\vdots \\\\ x_n \\end{mymatrix}\n  = \\begin{mymatrix}{c} p_1 \\\\ p_2 \\\\ \\vdots \\\\ p_n \\end{mymatrix}\n  + t \\begin{mymatrix}{r} d_1 \\\\ d_2 \\\\ \\vdots \\\\ d_n \\end{mymatrix},\n\\end{equation*}\nit is also called the \\textbf{component form}%\n\\index{vector equation!of a line!component form}%\n\\index{component form!line}%\n\\index{line!component form} of the vector equation.\n\nNotice that the vector equation of a line is not unique. In fact,\nthere are infinitely many vector equations for the same line. For\nexample, we can replace the parameter $t$ with another parameter, say\n$3s$ or $1-r$.\n\n\\begin{example}{Change of parameter}{change-of-parameter}\n  Consider the vector equation from\n  Example~\\ref{exa:line-point-and-direction-vector},\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Find two other equations for the same line, by changing the\n  parameter%\n  \\index{line!change of parameter}%\n  \\index{change of parameters!line} to $3s$ and to $1-r$.\n\\end{example}\n\n\\begin{solution}\n  If we let $t=3s$, we get\n  \\begin{equation*}\n    \\begin{array}{rcl}\n      \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n      &=& \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n      + 3s \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\\\\\\\\[-1ex]\n      &=& \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n      + s \\begin{mymatrix}{c} 3 \\\\ 6 \\\\ 3 \\end{mymatrix}.\n    \\end{array}\n  \\end{equation*}\n  If we let $t=1-r$, we get\n  \\begin{equation*}\n    \\begin{array}{rcl}\n      \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n      &=& \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n      + (1-r) \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\\\\\\\\[-1ex]\n      &=& \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 3 \\end{mymatrix}\n      + \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\n      - r \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\\\\\\\\[-1ex]\n      &=& \\begin{mymatrix}{c} 3 \\\\ 2 \\\\ 4 \\end{mymatrix}\n      + r \\begin{mymatrix}{c} -1 \\\\ -2 \\\\ -1 \\end{mymatrix}.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\n\\begin{definition}{Parametric equations of a line}{parametric-equations}\n  A line with vector equation\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x_1 \\\\ x_2 \\\\ \\vdots \\\\ x_n \\end{mymatrix}\n    = \\begin{mymatrix}{c} p_1 \\\\ p_2 \\\\ \\vdots \\\\ p_n \\end{mymatrix}\n    + t \\begin{mymatrix}{r} d_1 \\\\ d_2 \\\\ \\vdots \\\\ d_n \\end{mymatrix}\n  \\end{equation*}\n  can also be written as a set of $n$ scalar equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c}\n      x_1 &=& p_1 + t\\,d_1, \\\\\n      x_2 &=& p_2 + t\\,d_2, \\\\\n          &\\vdots&             \\\\\n      x_n &=& p_n + t\\,d_n,\n    \\end{array}\n  \\end{equation*}\n  When written in this form, they are called the \\textbf{parametric\n    equations}%\n  \\index{parametric equations!of a line}%\n  \\index{line!parametric equations} of the line.\n\\end{definition}\n\n\\begin{example}{Parametric equations}{parametric-equation}\n  Find parametric equations for the line through the points\n  $P = (1,2,0,1)$ and $R = (2,-4,6,3)$.\n\\end{example}\n\n\\begin{solution}\n  This is a same line as in Example~\\ref{exa:line-from-two-points}. We\n  can easily convert the vector equation\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 0 \\\\ 1\\end{mymatrix}\n    + t \\begin{mymatrix}{r} 1 \\\\ -6 \\\\ 6 \\\\ 2\\end{mymatrix}\n  \\end{equation*}\n  to a set of parametric equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}l}\n      x &=& 1 + t, \\\\\n      y &=& 2 - 6t, \\\\\n      z &=& 6t, \\\\\n      w &=& 1 + 2t.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Determine whether a point is on a line}{point-on-line}\n  Determine whether the point $P=(5,8,4)$ is on the line $L$ given by\n  the vector equation\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 2 \\\\ 3 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The point $P$ is on the line $L$ if and only if there exists some\n  $t\\in\\R$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 1 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 2 \\\\ 3 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 5 \\\\ 8 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  Subtracting $\\mat{1,2,1}^T$ from both sides of the equation, this is\n  equivalent to\n  \\begin{equation*}\n    t \\begin{mymatrix}{c} 2 \\\\ 3 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 4 \\\\ 6 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  We can write this as a set of parametric equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}l}\n      2t &=& 4, \\\\\n      3t &=& 6, \\\\\n      t &=& 3.\n    \\end{array}\n  \\end{equation*}\n  This is a system of three linear equations in one variable, and we\n  quickly see that it is inconsistent. Therefore, the point $P$ does\n  not lie on the line $L$.\n\\end{solution}\n\n\\begin{example}{Determine whether two lines intersect}{lines-intersect}\n  Determine whether the lines\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 3 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ 5 \\end{mymatrix}\n    + s \\begin{mymatrix}{c} 2 \\\\ 1 \\\\ -2 \\end{mymatrix}\n  \\end{equation*}\n  intersect. If yes, find the point of intersection.%\n  \\index{intersection!of two lines}\n\\end{example}\n\n\\begin{solution}\n  The two lines intersect if and only if there exist $t,s\\in\\R$ such\n  that\n  \\begin{equation*}\n    \\begin{mymatrix}{c} 3 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ 5 \\end{mymatrix}\n    + s \\begin{mymatrix}{c} 2 \\\\ 1 \\\\ -2 \\end{mymatrix}.\n  \\end{equation*}\n  Bringing $s$ to the left-hand side, and subtracting $\\mat{3,1,0}^T$\n  from both sides of the equation, this is equivalent to\n  \\begin{equation*}\n    t \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    - s \\begin{mymatrix}{c} 2 \\\\ 1 \\\\ -2 \\end{mymatrix}\n    = \\begin{mymatrix}{c} -2 \\\\ -2 \\\\ 5 \\end{mymatrix}.\n  \\end{equation*}\n  If we write this vector equation as a set of three parametric\n  equations, it is a system of 3 linear equations in 2 variables. The\n  augmented matrix of the system is\n  \\begin{equation*}\n    \\begin{mymatrix}{cc|c}\n      2 & -2 & -2 \\\\\n      0 & -1 & -2 \\\\\n      1 & 2 & 5   \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  This system has {\\rref}\n  \\begin{equation*}\n    \\begin{mymatrix}{cc|c}\n      1 & 0 & 1 \\\\\n      0 & 1 & 2 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  and has the unique solution $t=1$ and $s=2$. Therefore, the lines\n  intersect. (Other possible cases are: If the system is inconsistent,\n  the lines do not intersect. If the system has more than one\n  solution, the lines are identical). We find the point of\n  intersection by plugging the parameter $t=1$ into the equation of\n  the first line (or equivalently, but plugging $s=2$ into the\n  equation of the second line - doing it both ways is a good way to\n  double-check your answer). Therefore, the point of intersection is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} 3 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 5 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nThere is one other form for a line which is useful, which is the\n\\textbf{symmetric form}.  Consider the line given by\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}l}\n    x &=& 1 + 2t, \\\\\n    y &=& 1 - t, \\\\\n    z &=& 3 + 2t. \\\\\n  \\end{array}\n\\end{equation*}\nWe can solve each equation for $t$:\n\\begin{equation*}\n  \\begin{array}{c@{~}c@{~}l}\n    t &=& \\frac{x-1}{2}, \\\\\\\\[-2ex]\n    t &=& \\frac{y-1}{-1}, \\\\\\\\[-2ex]\n    t &=& \\frac{z-3}{2}.\n  \\end{array}\n\\end{equation*}\nFinally, we can eliminate $t$ from the equations by setting all three\nequations equal to one another:\n\\begin{equation*}\n  \\frac{x-1}{2} = \\frac{y-1}{-1} = \\frac{z-3}{2}.\n\\end{equation*}\nThe latter is really a system of 2 equations in 3 variables.  This is\nthe \\textbf{symmetric form}%\n\\index{line!symmetric form equation}%\n\\index{symmetric form} of the equation of the line.  In the following\nexample, we look at how to convert the equation of a line from\nsymmetric form to parametric form.\n\n\\begin{example}{Change symmetric form to parametric form}{symmetric-to-parametric}\n  Consider the line whose equations are given in \\textbf{symmetric form} as\n  \\begin{equation*}\n    \\frac{x-2}{3}=\\frac{y-1}{2}=\\frac{z+3}{1}.\n  \\end{equation*}\n  Find parametric and vector equations for this line.\n\\end{example}\n\n\\begin{solution}\n  We set all three quantities equal to $t$:\n  \\begin{equation*}\n    t=\\frac{x-2}{3}, \\quad\n    t=\\frac{y-1}{2}, \\quad\n    t=\\frac{z+3}{1}.\n  \\end{equation*}\n  Solving these equations for $x,y,z$ yields\n  \\begin{equation*}\n    \\begin{array}{c}\n      x = 2 + 3t, \\\\\n      y = 1 + 2t, \\\\\n      z = -3 + t.\n    \\end{array}\n  \\end{equation*}\n  These are the parametric equations for the line. The vector equation\n  is\n  \\begin{equation*}\n    \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\n    \\begin{mymatrix}{r}\n      2 \\\\\n      1 \\\\\n      -3\n    \\end{mymatrix}\n    +\n    t\n    \\begin{mymatrix}{r}\n      3 \\\\\n      2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWe can use the dot product to find the angle between two intersecting\nlines. This is simply the smallest angle between (any of) their\ndirection vectors. The only subtlety here is that if $\\vect{u}$ is a\ndirection vector for a line, then so is $-\\vect{u}$, and thus we will\nfind pairs of complementary angles. We will take the smaller of the\ntwo angles.\n\\begin{center} \\begin{tikzpicture}\n    \\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (-25:8mm)\n    arc (-25:25:8mm) -- cycle;\n    \\filldraw[fill=yellow!20,draw=yellow!50!black] (0,0) -- (25:8mm)\n    arc (25:155:8mm) -- cycle;\n    \\node at (0:5mm) {$\\theta$};\n    \\node at (90:4.2mm) {$\\pi-\\theta$};\n    \\draw[red!80](25:-2.5) -- (25:2.5);\n    \\draw[red!80](-25:-2.5) -- (-25:2.5);\n    \\draw[->,thick,red!80!black](0,0) -- node[above,pos=0.6]{$\\vect{v}$} (25:2);\n    \\draw[->,thick,blue!80!black](0,0) -- node[below,pos=0.3]{$\\vect{u}$} (-25:1.5);\n    \\draw[->,thick,blue!80!black](0,0) -- node[below,pos=0.6]{$-\\vect{u}$} (155:1.5);\n  \\end{tikzpicture}\n\\end{center}\n\n\\begin{example}{Find the angle between two lines}{angle-between-two-lines}\n  Find the angle between the two lines%\n  \\index{line!angle between}%\n  \\index{angle!between two lines}\n  \\begin{equation*}\n    L_1:  \\;\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 2 \\end{mymatrix}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    L_2: \\;\n    \\begin{mymatrix}{r} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{r} 0 \\\\ 3 \\\\ 2 \\end{mymatrix}\n    + s \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The direction vectors are\n  \\begin{equation*}\n    \\vect{u}=\\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}=\\begin{mymatrix}{r} 2 \\\\ 1 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  The answer is given by\n  \\begin{equation*}\n    \\cos\\theta =\n    \\frac{\\vect{u}\\dotprod\\vect{v}}{\\norm{\\vect{u}}\\norm{\\vect{v}}} = -\\frac{1}{2},\n  \\end{equation*}\n  which gives $\\theta=\\frac{2\\pi}{3}$.  Now the angles between any two\n  direction vectors for these lines will either be $\\frac{2 \\pi}{3}$ or\n  its complement $\\phi = \\pi - \\frac{2 \\pi}{3} = \\frac{\\pi}{3}$. We\n  choose the smaller angle, and therefore conclude that the angle\n  between the two lines is $\\frac{\\pi}{3}$.\n\\end{solution}\n\nFinally, we will show how to use projections to find the shortest\ndistance from a point to a line.\n\n\\begin{example}{Shortest distance from a point to a line}{shortest-point-line}\n  Let $L$ be the line which goes through the point $P = (0,4,-2)$ with\n  direction vector\n  $\\vect{d} = \\begin{mysmallmatrix}{r} 2 \\\\ 1 \\\\\n    2 \\end{mysmallmatrix}$, and let $Q=(1,3,5)$. Find the shortest\n  distance%\n  \\index{distance!point to line} from $Q$ to the line $L$, and find\n  the point $R$ on $L$ that is closest to $Q$.%\n  \\index{projection!point to line}\n  \\begin{center}\n    \\begin{tikzpicture}[rotate=-20]\n      \\draw[red!80](-1.5,0) -- node[above, pos=0.9]{$L$} (4.5,0);\n      \\draw[->,thick,blue!80!black](0,0) -- node[above right, pos=0.4]{$\\vect{d}$} (2,0);\n      \\draw[dashed] (3,1.5) -- (3,0);\n      \\draw[fill](0,0) circle [radius=2.25pt] node[below=1ex]{$P$};\n      \\draw[fill](3,1.5) circle [radius=2.25pt] node[right=0.5ex]{$Q$};\n      \\draw[fill](3,0) circle [radius=2.25pt] node[below=1ex]{$R$};\n    \\end{tikzpicture}\n  \\end{center}\n\\end{example}\n\n\\begin{solution}\n  In order to determine the shortest distance from $Q$ to $L$, we will\n  first find the vector $\\longvect{PQ}$ and then find the projection\n  of this vector onto $L$.  The vector $\\longvect{PQ}$ is given by\n  \\begin{equation*}\n    \\longvect{PQ}=\n    \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 5 \\end{mymatrix}\n    - \\begin{mymatrix}{r} 0 \\\\ 4 \\\\ -2 \\end{mymatrix}\n    = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 7 \\end{mymatrix}.\n  \\end{equation*}\n  Then, if $R$ is the point on $L$ closest to $Q$, it follows that\n  \\begin{equation*}\n    \\longvect{PR}\n    ~=~ \\proj_{\\vect{d}}\\longvect{PQ} \\\\\n    ~=~ \\frac{\\vect{d}\\dotprod\\longvect{PQ}}{\\norm{\\vect{d}}^2}\\,\\vect{d} \\\\\n    ~=~ \\frac{15}{9} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix} \\\\\n    ~=~ \\frac{5}{3} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Now, the distance from $Q$ to $L$ is given by\n  \\begin{equation*}\n    \\norm{\\longvect{RQ}} = \\norm{\\longvect{PQ} - \\longvect{PR}}\n    = \\sqrt{26}.\n  \\end{equation*}\n  The point $R$ is found by adding the vector $\\longvect{PR}$ to the\n  position vector $\\longvect{0P}$ for $P$ as follows\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 0 \\\\ 4 \\\\ -2 \\end{mymatrix}\n    + \\frac{5}{3} \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 2 \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c}\n      10/3 \\\\\n      17/3 \\\\\n      4/3\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, $R = (\\frac{10}{3}, \\frac{17}{3}, \\frac{4}{3})$.\n\\end{solution}\n", "meta": {"hexsha": "c44e2429111efa5d459612521819e650a0e75e34", "size": 19655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/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/content/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/content/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": 37.653256705, "max_line_length": 92, "alphanum_fraction": 0.62284406, "num_tokens": 7385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.6391224560369261}}
{"text": "\\chapter{Probability Models}\nWrite something here.\n\\newpage\n\\section{Multivariable Gaussian Distributions}\n\\subsection{Product of Experts}\n\\[ p(x) = \\frac{1}{Z}\\prod_{m=1}^M p_m(x) \\]\nIs (informally) equivalent to the intersection of Gaussian distributions.\n\\begin{remark}\n    Product of Experts is beyond the scope of this course.\n\\end{remark}\n\\subsection{Mixture of Experts}\nWeighted sum of multiple distributions.\n\\[ p(x) = \\sum_{m=1}^M c_m p_m(x) \\]\n\\begin{remark}\n    Weighted sum of Gaussians is not necessarily a Gaussian. So mixture of Gaussians can be used to ``fit'' different distributions.\n\\end{remark}\n\n\\section{Gaussian Mixture Model}\n\\subsection{Sampling from a GMM}\n\\begin{enumerate}\n    \\item Sample $c_m$ from $c_1,c_2,\\dots,c_M$\n    \\item Sample data from $\\mathcal{N}(x|\\mu_m,\\Sigma_m)$\n\\end{enumerate}\n\n\\section{Some Information Theory}\n\\textbf{Information} contains \\textbf{uncertainty}. The more uncertain something is, the more information is needed to eliminate its uncertainty.\n\n\\begin{definition}\n    The information in discrete variable is\n    \\[ I(x) = -\\log_2 P(x) \\]\n\\end{definition}\n\\begin{definition}[Entropy]\n    The \n    \\[ H = \\mathbb{E}[-\\log_2 P(x)] = -\\sum_{x\\in X}P(x)\\log_2 P(x) \\]\n    \\[ H = \\mathbb{E}[I(x) = -\\int_{-\\infty}^{\\infty}p(x)\\ln(p(x))\\mathrm{d}x] \\]\n\\end{definition}\n\\begin{remark}\n    \\begin{itemize}\n        \\item Entropy is a function of distribution $p(x)$.\n        \\item Is the expectation of information of random variables.\n    \\end{itemize}\n\\end{remark}\n\n\\subsection{Entropy of common distriutions}\n\n\\subsection{Conditional Entropy}\n\\begin{definition}\n    \\[ H[y|x] = \\sum_{x'}P(x)H(y|x=x') = -\\sum_{x}P(x)\\sum_yP(y|x)\\ln P(TooFast) \\]\n\\end{definition}", "meta": {"hexsha": "962e7b233250b16a7173293473e56294e8bf6327", "size": 1715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Speech Recognition/Probability.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/Probability.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/Probability.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": 35.0, "max_line_length": 145, "alphanum_fraction": 0.6979591837, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6391224500097433}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{fullpage}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{Numerical Methods for Solving Navier-Stokes Equations}\n\\author{Nikolas Tselepidis}\n\\date{}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Finite Pr Equations}\n\n\\paragraph{Conservation of momentum (dimensionless)}\n\n\\begin{equation}\n\\frac{1}{Pr} \\left( \\frac{\\partial \\vec{v}}{\\partial t} + \\vec{v} \\cdot \\nabla \\vec{v} \\right) =\n    - \\nabla P + \\nabla^2 \\vec{v} + Ra T \\hat{y}\n\\end{equation}\n\nTaking the curl of equation (1), and substituting the vorticity $\\vec{\\omega} = \\nabla \\times \\vec{v}$, it follows that:\n\n\\begin{equation}\n    \\frac{1}{Pr} \\left( \\frac{\\partial \\omega}{\\partial t} + v_x \\frac{\\partial \\omega}{\\partial x} + v_y \\frac{\\partial \\omega}{\\partial y} \\right) =\n     \\nabla^2 \\omega - Ra \\frac{\\partial T}{\\partial x}\n\\end{equation}\n\nIn 2D only one component of vorticity is needed, i.e. the one perpedicular to the 2D plane:  $\\nabla^2 \\psi = \\omega_z$.\n\n\\paragraph{Conservation of mass (continuity)}\n\\begin{equation}\n    \\frac{\\partial T}{\\partial t} + \\vec{v} \\cdot \\nabla T = \\kappa \\nabla^2 T\n\\end{equation}\n\n\\paragraph{Conservation of energy}\n\\begin{equation}\n    \\nabla \\cdot \\vec{v} = 0\n\\end{equation}\n\n\n\\section{Solve}\n\n\\begin{equation}\n    \\nabla^2 \\psi = \\omega\n\\end{equation}\n\n\\begin{equation}\n    \\left( v_x, v_y \\right) = \\left( \\frac{\\partial \\psi}{\\partial y}, -\\frac{\\partial \\psi}{\\partial x} \\right)\n\\end{equation}\n\n\\begin{equation}\n    \\frac{\\partial T}{\\partial t} = -v_x \\frac{\\partial T}{\\partial x} -v_y \\frac{\\partial T}{\\partial y} + \\kappa \\nabla^2 T\n\\end{equation}\n\n\\begin{equation}\n    \\frac{\\partial \\omega}{\\partial t} = -v_x \\frac{\\partial \\omega}{\\partial x} -v_y \\frac{\\partial \\omega}{\\partial y} + Pr \\nabla^2 \\omega - Ra Pr \\frac{\\partial T}{\\partial x}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "09dd9c39af7c7379d5311eb7f72db1963b939324", "size": 1862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doc.tex", "max_stars_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_stars_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-21T15:16:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-21T15:16:04.000Z", "max_issues_repo_path": "doc/doc.tex", "max_issues_repo_name": "ntselepidis/FDM-Navier-Stokes", "max_issues_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_issues_repo_licenses": ["MIT"], "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": "ntselepidis/FDM-Navier-Stokes", "max_forks_repo_head_hexsha": "fbb9a1741b1d8e3e550db0c2e756d25780c48ed6", "max_forks_repo_licenses": ["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.09375, "max_line_length": 179, "alphanum_fraction": 0.6761546724, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6391224423458924}}
{"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-11.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 11 The RNC connection.}\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#}::Indices(position=independent).\n\n   D{#}::PartialDerivative.\n   \\nabla{#}::Derivative.\n\n   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n   g^{a b}::Weight(label=gnum,value=1).\n\n   \\delta{#}::KroneckerDelta.\n\n   R_{a b c d}::RiemannTensor.\n   R_{a b c d}::Depends(\\nabla{#}).\n\n   x^{a}::Depends(D{#}).\n   x^{a}::Weight(label=xnum,value=1).\n\n   Dx := D_{a}{x^{b}} -> \\delta^{b}_{a}.   # cdb (ex-11.000,Dx)\n\n   gab := g_{a b} -> 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-11.001,gab)\n\n   iab := g^{a b} -> 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-11.002,iab)\n\n   distribute (gab)\n   distribute (iab)\n\n   ChrSym := \\Gamma^{a}_{b c} -> 1/2 g^{a d} (  D_{b}{g_{d c}}\n                                              + D_{c}{g_{b d}}\n                                              - D_{d}{g_{b c}} ).   # cdb (ex-11.003,ChrSym)\n\n   Gamma := \\Gamma^{a}_{b c}.              # cdb (ex-11.100,Gamma)\n\n   substitute     (Gamma,ChrSym)           # cdb (ex-11.101,Gamma)\n   substitute     (Gamma,gab)              # cdb (ex-11.102,Gamma)\n   substitute     (Gamma,iab)              # cdb (ex-11.103,Gamma)\n   distribute     (Gamma)                  # cdb (ex-11.104,Gamma)\n   unwrap         (Gamma)                  # cdb (ex-11.105,Gamma)\n   product_rule   (Gamma)                  # cdb (ex-11.106,Gamma)\n   distribute     (Gamma)                  # cdb (ex-11.107,Gamma)\n   substitute     (Gamma,Dx)               # cdb (ex-11.108,Gamma)\n   eliminate_kronecker (Gamma)             # cdb (ex-11.109,Gamma)\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(\"xnum = \" + str(i))\n          distribute  (foo)\n          keep_weight (foo, bah)\n          ans = ans + foo\n\n       return ans\n\n   checkpoint.append (Gamma)\n\n   # sort_product   (Gamma)  # 52.3 sec, 49 Mbyte\n   # rename_dummies (Gamma)  # 58.6 sec, 51 Mbyte\n   # canonicalise   (Gamma)  # killed after 20 mins and over 500 Mbyte\n\n   Gamma = truncate (Gamma,3)   # cdb (ex-11.110,Gamma)  # allow up to 3rd order in x^a\n\n   sort_product   (Gamma)\n   rename_dummies (Gamma)\n   canonicalise   (Gamma)\n\n   checkpoint.append (Gamma)\n\n   # ==========================================================================\n   # the remaining code is just for pretty printing\n\n   def product_sort (obj):\n       substitute (obj,$ g^{a b}                   -> A001^{a b}                $)\n       substitute (obj,$ x^{a}                     -> A002^{a}                  $)\n       substitute (obj,$ z^{a}                     -> A003^{a}                  $)\n       substitute (obj,$ R_{a b c d}               -> A004_{a b c d}            $)\n       substitute (obj,$ \\nabla_{e}{R_{a b c d}}   -> A005_{a b c d e}          $)\n       substitute (obj,$ \\nabla_{e f}{R_{a b c d}} -> A006_{a b c d e f}        $)\n       sort_sum       (obj)\n       sort_product   (obj)\n       rename_dummies (obj)\n       substitute (obj,$ A001^{a b}                -> g^{a b}                   $)\n       substitute (obj,$ A002^{a}                  -> x^{a}                     $)\n       substitute (obj,$ A003^{a}                  -> z^{a}                     $)\n       substitute (obj,$ A004_{a b c d}            -> R_{a b c d}               $)\n       substitute (obj,$ A005_{a b c d e}          -> \\nabla_{e}{R_{a b c d}}   $)\n       substitute (obj,$ A006_{a b c d e f}        -> \\nabla_{e f}{R_{a b c d}} $)\n\n   def get_xterm (obj,n):\n\n       foo := @(obj).\n       bah  = Ex(\"xnum = \" + str(n))\n       distribute  (foo)\n       keep_weight (foo, bah)\n\n       return foo\n\n   def get_gterm (obj,n):\n\n       foo := @(obj).\n       bah  = Ex(\"gnum = \" + 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      product_sort   (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_xterm (Gamma, 1)                          # cdb (ex-11.200,gam1)\n   gam2  = get_xterm (Gamma, 2)                          # cdb (ex-11.201,gam2)\n   gam3  = get_xterm (Gamma, 3)                          # cdb (ex-11.202,gam3)\n\n   gam31 = get_gterm (gam3,  1)                          # cdb (ex-11.210,gam31)\n   gam32 = get_gterm (gam3,  2)                          # cdb (ex-11.211,gam31)\n\n   gam1  = reformat (gam1,   3)                          # cdb (ex-11.220,gam1)\n   gam2  = reformat (gam2,  12)                          # cdb (ex-11.221,gam2)\n\n   gam31 = reformat (gam31, 40)                          # cdb (ex-11.222,gam31)\n   gam32 = reformat (gam32, 45)                          # cdb (ex-11.223,gam32)\n\n   Gamma  := @(gam1) + @(gam2) + @(gam31) + @(gam32).    # cdb (ex-11.230,Gamma)\n   Scaled := 360 @(Gamma).                               # cdb (ex-11.231,Scaled)\n\n   checkpoint.append (Gamma)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{\\cdb{ex-11.100}(x) = \\Cdb*[\\hskip 3.0cm]{ex-11.230}}\n\\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{360 \\cdb{ex-11.100}(x) = \\Cdb*[\\hskip 3.0cm]{ex-11.231}}\n\\end{dgroup*}\n\n\\clearpage\n\n% ============================================================================================\n% export to json format\n\n% --------------------------------------------------------------------------------------------\n\\subsection*{Save $\\Gamma^{a}{}_{bc}$ for later use in Example 12.}\n\n\\begin{cadabra}\n   jsonfile = 'example-11.json'\n   cdblib.create (jsonfile)\n   cdblib.put ('Gamma',Gamma,jsonfile)\n\\end{cadabra}\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": "6e2da1dc9f7b5e4b8fdbdf98f6a1b7b598baebef", "size": 7066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-11.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-11.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-11.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": 33.9711538462, "max_line_length": 112, "alphanum_fraction": 0.4363147467, "num_tokens": 2249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.6391224372815785}}
{"text": "\n\n\n\nThe chapter presents two ways of doing hypothesis tests on whole\nmodels: (1) permutation tests where the connection is severed between\nthe explanatory and response variables, (2) tests such as \\ANOVA\\\nwhere the sampling distribution is calculated from first principles.\nIn practice, first-principle tests are used most of the time.\nStill, the permutation test is useful for developing intuition about\nhypothesis testing --- our main purpose here --- \nand for those not-so-rare occasions where the assumptions\nbehind the first-principle tests are dubious.\n\n\\subsection{The Permutation Test}\n\nThe idea of a permutation test is to enforce the null hypothesis that\nthere is no connection between the response variables and the\nexplanatory variables.  An effective way to do this is to randomize\nthe response variable in a way that is consistent with sampling\nvariability.  When constructing confidence intervals, the\n\\function{resampling} function was used.  Re-sampling will typically\nrepeat some cases and omit others.  Here, the \\function{shuffle}\nfunction will be used instead, to scramble the order of one or more\nvariables while leaving the others in their original state.\n\n\nTo illustrate, consider a model for exploring whether \\VN{sex} and\n\\VN{mother}'s height are related to the height of the child: \\datasetGalton\n\\begin{Schunk}\n\\begin{Sinput}\n> galton = fetchData(\"galton.csv\")\n> mod = lm(height ~ sex + mother, data=galton)\n> coefficients(mod)\n\\end{Sinput}\n\\begin{Soutput}\n(Intercept)        sexM      mother \n     41.450       5.177       0.353 \n\\end{Soutput}\n\\end{Schunk}\nThe coefficients indicate that typical males are taller than typical \nfemales by about 5 inches and that for each inch taller the mother is,\na child will typically be taller by 0.35 inches.  \nA reasonable test statistic to summarize the whole model is $R^2$:\n\\begin{Schunk}\n\\begin{Sinput}\n> rsquared(mod)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 0.562\n\\end{Soutput}\n\\end{Schunk}\n\nFor confidence intervals, re-sampling was applied to the entire data\nframe.  This selects random cases, but each selected case is an\nauthentic one that matches exactly the original values for that case.\nThe point of re-sampling is to get an idea of the variability\nintroduced by random sampling of authentic cases.\n\\begin{Schunk}\n\\begin{Sinput}\n> do(5) * lm(height ~ sex + mother, data=resample(galton))\n\\end{Sinput}\n\\begin{Soutput}\n  Intercept sexM mother sigma r-squared\n1      42.3 5.37  0.337  2.29     0.593\n2      42.1 4.93  0.344  2.34     0.550\n3      43.5 5.23  0.321  2.36     0.568\n4      37.9 5.26  0.409  2.34     0.579\n5      39.9 5.14  0.378  2.29     0.570\n\\end{Soutput}\n\\end{Schunk}\nThe \\indicatorVar{sex}{M} coefficients are tightly grouped near 5\ninches, the \\VN{mother} coefficients are around 0.3 to 0.4.\n\n\\index{P}{resample@\\texttt{resample}*}\n\\index{P}{shuffle@\\texttt{shuffle}*}\n\\index{P}{Hypothesis Testing!resample@\\texttt{resample}*}\n\\index{P}{Hypothesis Testing!shuffle@\\texttt{shuffle}*}\n\n\\index{P}{Resampling!resample@\\texttt{resample}*}\n\\index{P}{Resampling!shuffle@\\texttt{shuffle}*}\n\\index{C}{permutation test!computing}\n\nIn order to carry out a permutation test, do not randomize the\nwhole data frame.  Instead, shuffle just the response variable:\n\\begin{Schunk}\n\\begin{Sinput}\n> do(5) * lm(shuffle(height) ~ sex + mother, data=galton)\n\\end{Sinput}\n\\begin{Soutput}\n  Intercept     sexM  mother sigma r-squared\n1      63.7 -0.30663  0.0507  3.58   0.00300\n2      72.3  0.00676 -0.0859  3.58   0.00306\n3      70.8  0.00563 -0.0629  3.58   0.00164\n4      70.2  0.02282 -0.0533  3.58   0.00119\n5      68.3 -0.55719 -0.0192  3.58   0.00613\n\\end{Soutput}\n\\end{Schunk}\nNow the \\indicatorVar{sex}{M} and \\VN{mother} \ncoefficients are close to zero, as would be expected when\nthere is no relationship between the response variable and the\nexplanatory variables.\n\nIn constructing the sampling distribution under the null hypothesis,\nyou should do hundreds of trials of fitting the model to the scrambled\ndata, calculating the test statistic ($R^2$ here) for each trial.  Note that each\ntrial itself involves all of the cases in your sample, but those cases\nhave been changed so that the shuffled variable almost certainly\ntakes on a different value in every case than in the original data.\n\\begin{Schunk}\n\\begin{Sinput}\n> nulltrials = do(500) *  rsquared(\n     lm(shuffle(height) ~ sex + mother, data=galton))\n\\end{Sinput}\n\\end{Schunk}\nNotice that the \\function{rsquared} operator has been used to calculate\nthe test statistic $R^2$ from the model.  The output of \\function{do}\nis a data frame: \n\\begin{Schunk}\n\\begin{Sinput}\n> nulltrials\n\\end{Sinput}\n\\end{Schunk}\n\\begin{Schunk}\n\\begin{Soutput}\n       var\n1 0.000920\n2 0.001854\n3 0.000533\n... for 500 cases altogether ...\n\\end{Soutput}\n\\end{Schunk}\nNaturally, all of the $R^2$ values for the trials are close to zero.\nAfter all,  there is no\nrelation between the response variable (after randomization with\n\\function{shuffle}) and the explanatory variables.\n\nThe p-value can be calculated directly from the trials, by comparison\nto the observed value in the actual data: $R^2$ was 0.5618. \n\\begin{Schunk}\n\\begin{Sinput}\n> count(var > 0.5618, nulltrials)\n\\end{Sinput}\n\\begin{Soutput}\ncount.FALSE \n        500 \n\\end{Soutput}\n\\end{Schunk}\nNone of the 500 trials were greater than the value of the test statistic, 0.5618.\nIt wouldn't be fair to claim that $p=0$, since we only did 500 trials,\nbut it is reasonable to say that the permutation test shows the \np-value is $p \\leq 1/500$.\n\n\n\\subsection{First-Principle Tests}\n\n\\index{C}{regression report!hypothesis testing}\n\\index{C}{hypothesis testing!in regression report}\nOn modern computers, the permutation test is entirely practical.  But\na few decades ago, it was not.  Great creativity was applied to\nfinding test statistics where the sampling distribution could be\nestimated without extensive calculation.  One of these is the F\nstatistic.  This is still very useful today and is a standard part of\nthe regression report in many statistical packages.  \n\n\\index{P}{summary@\\texttt{summary}!for linear models}\n\\index{P}{Hypothesis Testing!summary@\\texttt{summary}!for linear models}\n\nHere is the regression report from the\n\\model{\\VN{height}}{\\VN{sex}+\\VN{mother}}:\n\\begin{Schunk}\n\\begin{Sinput}\n> mod = lm( height ~ sex + mother, data=galton)\n> summary(mod)\n\\end{Sinput}\n\\begin{Soutput}\n...\n            Estimate Std. Error t value Pr(>|t|)    \n(Intercept)  41.4495     2.2095    18.8   <2e-16 ***\nsexM          5.1767     0.1587    32.6   <2e-16 ***\nmother        0.3531     0.0344    10.3   <2e-16 ***\n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\nResidual standard error: 2.37 on 895 degrees of freedom\nMultiple R-squared: 0.562,\tAdjusted R-squared: 0.561 \nF-statistic:  574 on 2 and 895 DF,  p-value: <2e-16 \n\\end{Soutput}\n\\end{Schunk}\nThe last line of the report\nshows an F statistic of 574 based on an $R^2$ of 0.562 and\ntranslates this to a p-value that is practically zero: \\code{<2e-16}.\n\nBy way of showing that the regression report is rooted in the same\napproach shown in the chapter, you can confirm the calculations.\nThere are $m=3$ coefficients and $n=898$ cases,\nproducing $n-m=895$ degrees of freedom in the denominator and $m-1=2$\ndegrees of freedom in the numerator. The calculation of the F\nstatistic from $R^2$ and the degrees of freedom follows the formula\ngiven in the chapter.  \n$$ F = \\frac{R^2}{m-1} \\Biggm/ \\frac{1-R^2}{n-m} $$\nPlugging the values into the formula\n\\begin{Schunk}\n\\begin{Sinput}\n> (0.562/2) / ((1-.562)/895)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 574\n\\end{Soutput}\n\\end{Schunk}\nF is the test statistic.  To convert it to a p-value, you need to\ncalculate how extreme the value of F$=574.2$ is with reference to the\nF distribution with 895 and 2 degrees of freedom.\n\\begin{Schunk}\n\\begin{Sinput}\n> 1 - pf( 574.2, 2, 895)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 0\n\\end{Soutput}\n\\end{Schunk}\n\\index{P}{pf@\\texttt{pf}}\n\\index{P}{Hypothesis Testing!pf@\\texttt{pf}}\n\\index{C}{p value!from F statistic}\nThe calculation of p-values from F always follows this form.  In the\ncontext of the F distribution, ``extreme'' always means ``bigger\nthan.''  So, calculate the area under the F distribution to the right\nof the observed value.\n\n", "meta": {"hexsha": "b1e87f1529f03561582a5b03a3bd8375456808f6", "size": 8258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComputationalTechnique-Orig/WholeModels/computer-wholemodels.tex", "max_stars_repo_name": "dtkaplan/SM3", "max_stars_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-01T01:28:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T01:28:07.000Z", "max_issues_repo_path": "ComputationalTechnique-Orig/WholeModels/computer-wholemodels.tex", "max_issues_repo_name": "BriannaBarry/SM3", "max_issues_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "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": "ComputationalTechnique-Orig/WholeModels/computer-wholemodels.tex", "max_forks_repo_name": "BriannaBarry/SM3", "max_forks_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-02-14T05:22:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T12:42:15.000Z", "avg_line_length": 35.9043478261, "max_line_length": 81, "alphanum_fraction": 0.7308064907, "num_tokens": 2538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519378, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6391017786768378}}
{"text": "\\documentclass{article}\n\\input{../../FrequentlyUsed/latex/mypackages}\n\\input{../../FrequentlyUsed/latex/mydefs}\n\n\\usepackage[makeroom]{cancel}\n\n\\title{Math for Taehoon}\n\\author{Sunghee Yun}\n\n\\begin{document}\n\\maketitle\n\n\\tableofcontents\n\n\\newpage\n\n\\section{27-SEP-2019}\n\\begin{itemize}\n\\item What is the smallest possible value of $n$ that makes $7! \\times n$ a perfect square?\n\n{\\bf Answer}: $35$\n\n\\begin{proof}\nSince\n\\begin{equation}\n7! = 2 \\times 3 \\times (2 \\times 2 ) \\times 5 \\times (2\\times 3) \\times 7\n= 2^4 \\times 3^2 \\times 5 \\times 7\n= (2^2 \\times 3)^2 \\times 5 \\times 7,\n\\end{equation}\nwe need at least one $5$ and one $7$ to make $7!\\times n$ a perfect square.\nTherefore the smallest possible value of $n$ that makes $7! \\times n$ a perfect square\nis $5\\times 7 = 35$.\nNote that $7! \\times 35 = (2^2 \\times 3 \\times 5 \\times 7)^2$.\n\n\\end{proof}\n\n\\item If there are 18 dragons with either $2$ or $3$ heads,\nand the total number of heads is $42$,\nhow many $2$-headed dragons are there? \n\n{\\bf Answer}: $12$\n\n\\begin{proof}\nLet $x$ be the number of $2$-headed dragons\nand\n$y$ be the number of $3$-headed dragons.\nSince there are $18$ dragons, we have the following equation:\n\\begin{equation}\n\\label{eq:dfihj}\nx + y = 18\n\\end{equation}\nAlso, the total number of heads is $42$, thus we have\n\\begin{equation}\n2 \\times x + 3 \\times y = 42\n\\end{equation}\n\nNow if we multiply $3$ to both the left-hand-side (LHS) and right-hand-side (RHS) of (\\ref{eq:dfihj}),\nwe obtain the following two equations:\n\\begin{eqnarray}\n3\\times x + 3\\times y &=& 3\\times(x+y) = 3\\times 18\n\\label{eq:oges}\n\\\\\n2 \\times x + 3 \\times y &=& 42\n\\label{eq:uydh}\n\\end{eqnarray}\n\nNow we subtract (\\ref{eq:uydh}) from (\\ref{eq:oges}), we get\n\\begin{equation}\nx = (3\\times x + 3\\times y) - (2 \\times x + 3 \\times) = 3 \\times 18 - 42 = 54 - 42 = 12.\n\\end{equation}\nSince we initially assumed that $x$ is the number of $2$-headed dragons,\nthe answer is $12$.\n\\end{proof}\n\n\n\\item Brenda and Sally run in opposite directions on a circular track,\nstarting at diametrically opposite points.\nThey first meet after Brenda has run $100$ meters.\nThey next meet after Sally has run $150$ meters past their first meeting point.\nEach girl runs at a constant speed.\nWhat is the length of the track in meters?\n\n{\\bf Answer}: $350$ meters.\n\n\\begin{proof}\n\\figurename~\\ref{fig:race} shows the track Brenda and Sally run.\n$X$ refers to the distance that Sally runs until she meets Brenda\nand $Y$ refers to the distance that Brenda runs past the first meeting point until she meets Sally again.\nNow since they run at constant speed,\nthe ratio of $100$ to $X$ and that of $Y$ to $150$ are the same,\n\\ie,\n\\begin{equation}\n\\label{eq:bysio}\n100 : X = Y : 150\n\\Leftrightarrow\n\\frac{100}{X} = \\frac{Y}{150}\n\\Leftrightarrow\nX \\times Y = 100 \\times 150.\n\\end{equation}\nNow we know that the sum of the distance that Brenda runs and the distance that Sally runs until they first meet\nis half the circumference of the track.\nWe also know that the sum of the distance that Brenda runs and the distance that Sally runs\nuntil they meets second time is the circumference of the track.\nIf we express this as an equation, we have\n\\begin{equation}\nY + 150 = 2 \\times (X + 100).\n\\end{equation}\nNow if we multiply $2$ to both side of this equation and use (\\ref{eq:bysio}),\nwe have\n\\begin{eqnarray*}\n&& X \\times Y + 150 \\times X = 2 \\times (X \\times X + 100 \\times X)\n\\\\\n&\\Leftrightarrow&\n100 \\times 150 + 150 \\times X = 2 \\times (X \\times X + 100 \\times X)\n\\\\\n&\\Leftrightarrow&\nX\\times X + 25 \\times X - 100 \\times 75 = 0\n\\\\\n&\\Leftrightarrow&\n(X - 75) \\times (X + 100) = 0.\n\\end{eqnarray*}\nTherefore $X=75$ and the circumference (or the length) of the track\nis $2\\times (X+100) = 350$.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=.5\\linewidth]{figures/sally_and_brenda}\n\\caption{Race of Brenda and Sally. B and S stand for Brenda and Sally respectively.}\n\\label{fig:race}\n\\end{center}\n\\end{figure}\n\n\\end{proof}\n\n\\end{itemize}\n\n\n\n\\section{02-NOV-2019}\n\n\\begin{enumerate}\n\n\\item In this addition problme, \\ldots\\\\\n\n\\begin{tabular}{cccc}\n&$T$\t&$W$\t&$O$\n\\\\\n+\t&$T$\t&$W$\t&$O$\n\\\\\n\\hline\n$F$\t&$O$\t&$U$\t&$R$\n\\end{tabular}\n\n\\begin{solution}\n\nSince $O$ is an even number, the previous addition, \\ie, $W+W$ should not generate overflow.\nTherefore, $W$ should be less than $5$.\nThen $O=4$ and $F=1$ since $7+7=14$.\nSince $O=4$, $R=8$.\nNow the above equation becomes\\\\\n\n\\begin{tabular}{cccc}\n&$7$\t&$W$\t&$4$\n\\\\\n+\t&$7$\t&$W$\t&$4$\n\\\\\n\\hline\n$1$\t&$4$\t&$U$\t&$8$\n\\end{tabular}\n\n\\ \\\\\n\n\n\nNow since $O=4$ and $F=1$, the only possible values for $W$ are $2$ and $3$.\nBut if $W=2$, then $U=4$ and $U=O$. Therefore $W=3$.\nIn summary,\\\\\n\n\\begin{tabular}{cccc}\n&$7$\t&$3$\t&$4$\n\\\\\n+\t&$7$\t&$3$\t&$4$\n\\\\\n\\hline\n$1$\t&$4$\t&$6$\t&$8$\n\\end{tabular}\n\n\\end{solution}\n\n\\item Mr. Harman needs ...\n\n\\begin{description}\n\\item[Answer:] $(122+125+127)/2 = 187$.\n\\end{description}\n\n\\begin{solution}\nLet $X$, $Y$, and $Z$ be the weights of the three boxes. Then we have\n\\begin{eqnarray*}\nX + Y &=& 122\n\\\\\nY + Z &=& 125\n\\\\\nX + Z &=& 127\n\\end{eqnarray*}\n\nSince the sum of all three quantities in left-hand-side (LHS)\nis the same as the sum of all three quantities in right-hand-side (RHS),\nwe have\n\\begin{equation}\n2 \\times ( X + Y + Z ) = 122+125+127,\n\\end{equation}\nthus\n\\begin{equation}\nX + Y + Z = (122+125+127)/2 = 187.\n\\end{equation}\n\n\\end{solution}\n\n\n\\item The students in Mrs. Reed's English class are reading \\ldots\n\n\\begin{description}\n\\item[Answer:] $760 \\times \\frac{1.5}{1 + 1.5} = 760 \\times \\frac{3}{5}= 456.$\n\\end{description}\n\n\\begin{solution}\nNote that Chandra's reading speed is $1.5$ times bigger than that of Bob.\nIf we let $x$ be the number of pages that Bob should read,\nthen $1.5 \\times x$ is the number of pages that Chandra should read.\nThus we have $x + 1.5 \\times x = 2.5 \\times x = 760$ and\n\\begin{equation}\nx = \\frac{760}{2.5} = 760 \\times \\frac{2}{5}.\n\\end{equation}\nThus the number of pages Chandra should read is\n\\begin{equation}\nx \\times 1.5 = 760 \\times \\frac{\\cancel{2}}{5} \\times \\frac{3}{\\cancel{2}}\n= 152 \\times 3 = 456.\n\\end{equation}\n\\end{solution}\n\n\n\\item Landy drove \\ldots\\\\\n\n\\begin{description}\n\\item[Answer:]\n\\begin{equation}\n\\frac{10+20+30}{10/30 + 20/20 + 30/10} = 13.8 \\mbox{ miles/hour}\n\\end{equation}\n\\end{description}\n\n\n\\item The Incredible \\ldots\\\\\n\n\\begin{description}\n\\item[Answer:] The $11$th jump!\n\\end{description}\n\n\\begin{solution}\n\\begin{eqnarray*}\n1\\mbox{st jump} &=& 1\n\\\\\n2\\mbox{nd jump} &=& 2\n\\\\\n3\\mbox{rd jump} &=& 4\n\\\\\n4\\mbox{th jump} &=& 8\n\\\\\n5\\mbox{th jump} &=& 16\n\\\\\n6\\mbox{th jump} &=& 32\n\\\\\n7\\mbox{th jump} &=& 64\n\\\\\n8\\mbox{th jump} &=& 128\n\\\\\n9\\mbox{th jump} &=& 256\n\\\\\n10\\mbox{th jump} &=& 512\n\\\\\n11\\mbox{th jump} &=& 1024\n\\end{eqnarray*}\n\\end{solution}\n\n\n\\item The Amaco \\ldots\\\\\n\n\\begin{description}\n\\item[Answer:] $15 - 11 = 4$\n\\end{description}\n\n\\begin{solution}\nLet $X$ and $Y$ be the number of seventh graders and that of sixth graders\nrespectively who bought pencils.\nLet $P$ be the price of one pencil in cents.\nThen we have\n\\begin{eqnarray*}\nX \\times P &=& 143 = 11 \\times 13\n\\\\\nY \\times P &=& 195 = 15 \\times 13\n\\end{eqnarray*}\nThus $P$ is a common divisor of $143$ and $195$.\nThus $P$ is $1$ or $13$. However, if $P=1$, then $Y=195$. But $Y\\leq 30$, hence $P=13$.\nTherefore, $X=11$ and $Y=15$.\nThus $Y-X = 4$.\n\\end{solution}\n\n\\end{enumerate}\n\n\\begin{description}\n\n\\item[Q1] $88+86+91+92+87+90+89+93+92+88$?\n\n\\begin{description}\n\\item[Answer:] \n\\begin{eqnarray*}\n\\lefteqn{\n88+86+91+92+87+90+89+93+92+88}\n\\\\\n&=&\n(90 - 2)\n+ (90 - 4)\n+ (90 + 1)\n+ (90 + 2)\n+ (90 - 3)\n\\\\\n&&\n+ (90 + 0)\n+ (90 - 1)\n+ (90 + 3)\n+ (90 + 2)\n+ (90 - 2)\n\\\\\n&=&\n90 \\times 10\n+(- 2 - 4 + 1 + 2 - 3 + 0 - 1 + 3 + 2 - 2)\n\\\\\n&=&\n90 \\times 10 - 4 = 896.\n\\end{eqnarray*}\n\\end{description}\n\n\n\\item[Q2]\n\\begin{description}\n\\item[Answer:] $90$ inches.\n\\end{description}\n\n\n\\item[Q3]\n\\begin{description}\n\\item[Answer:] $4$.\n\\end{description}\n\n\n\\item[Q4]\n\\begin{description}\n\\item[Answer:] $3 \\times 8 \\times 2 = 48$.\n\\end{description}\n\n\n\\item[Q5]\n\\begin{description}\n\\item[Answer:] $1249$\n\\end{description}\n\n\n\\item[Q6]\n\\begin{description}\n\\item[Answer:] $56.25$\n\\begin{equation}\nx \\times \\frac{4}{5} \\times \\frac{4}{5} = 36\n\\Rightarrow x = 36 \\times \\frac{5}{4} \\times \\frac{5}{4} = 56.25\n\\end{equation}\n\\end{description}\n\n\n\\item[Q7]\n\\begin{description}\n\\item[Answer:] $2 \\times 2 / 2 = 2$\n\\end{description}\n\n\n\\item[Q8]\n\\begin{description}\n\\item[Answer:] Captain Hook found $30$ diamonds.\n\\begin{eqnarray*}\nH + P &=& 80\n\\\\\nP + S &=& 70\n\\\\\nH + S &=& 50\n\\end{eqnarray*}\nthus\n\\[\n2 \\times H = (H+P) + (H+S) - (P+S) = 80+50-70 = 60\n\\Rightarrow H = 30.\n\\]\n\\end{description}\n\n\n\\item[Q9]\n\\begin{description}\n\\item[Answer:] $15 + 10 \\times 2 = 35$.\n\\end{description}\n\n\n\\item[Q10]\n\\begin{description}\n\\item[Answer:] $25$ hours.\n\nSince the 1st pipe can fill the swimming pool $1.5$ times faster than the 2nd pipe,\nusing both pipes will be $2.5$ $(=1 + 1.5)$ times fater than using the 2nd pipe alone.\nThus using only 2nd pipe will be $2.5$ slower than using both pipes, hence it'd take $10 \\times 2.5 = 25$ hours to fill the swimming pool.\n\\end{description}\n\n\n\\item[Q11]\n\\begin{description}\n\\item[Answer:] $12 \\times 12 - 4 \\times 4 - 4 \\times (4\\times 4)/2 = 96$.\n\\end{description}\n\n\n\\item[Q12]\n\\begin{description}\n\\item[Answer:] $(30+90+50)/(1+2+1) = 42.5$ miles/hour.\n\\end{description}\n\n\n\\item[Q13]\n\\begin{description}\n\\item[Answer:] $4$ months\n\\[\n1\\ \\cancel{2}\\ \\cancel{3}\\ \\cancel{4}\\ 5\\ \\cancel{6}\\ 7\\ \\cancel{8}\\ \\cancel{9}\\ \\cancel{10}\\ 11\\ \\cancel{12}\n\\]\n\\end{description}\n\n\n\\item[Q17]\n\\begin{description}\n\\item[Answer:] $12$ kilograms\n\n\nAssume that $x$ kilograms of raisins and $y$ kilograms of nuts were used for making the snakcs.\nThen\n\\begin{eqnarray*}\nx + y &=& 20\n\\\\\n3.5 \\times x + 4.75 \\times y &=& 20 \\times 4\n\\end{eqnarray*}\n\nIf we multiply $4.75$ to both sides of the first equation,\nwe have\n\\begin{eqnarray*}\n4.75 \\times x + 4.75 \\times y &=& 20 \\times 4.75\n\\\\\n3.5 \\times x + 4.75 \\times y &=& 20 \\times 4\n\\end{eqnarray*}\n\nIf we subtract the second equation from the first one,\nwe have\n\\begin{eqnarray*}\n&&(4.75 - 3.5) \\times x = 20 \\times (4.75 - 4)\n\\\\\n&\\Leftrightarrow&\n1.25 \\times x = 20 \\times 0.75\n\\\\\n&\\Leftrightarrow&\nx = 20 \\times 0.75 / 1.25 = 20 \\times \\frac{3}{5} = 12\n\\end{eqnarray*}\n\n\n\n\n\n\n\\end{description}\n\n\n\\end{description}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "05a5d74b4b48071c3a6294f0e880e10814b4c00b", "size": 10300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem_sovling/math4taehoon_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/math4taehoon_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/math4taehoon_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": 21.2371134021, "max_line_length": 138, "alphanum_fraction": 0.6548543689, "num_tokens": 3945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6391017767071818}}
{"text": "\\documentclass[paper.tex]{subfiles}\n\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{tabularx}\n\\usepackage{multicol}\n\\usepackage{algpseudocode}\n\\usepackage{algorithm}\n\n% Add vertical spacing to tables\n\\renewcommand{\\arraystretch}{1.4}\n\n% Begin Document\n\\begin{document}\n\n\\section{Brute Force Approach}\n\nCalculating the Minimum Domating Set of a graph is a difficult problem.\nThe size and complexity of a graph quickly grows with the number of nodes, $n$, and the number of edges, $e$, that make up the graph.\nAs such, the only known way to guarantee finding the minimum dominating set is through a brute force approach.\n\nThis entails checking every possible combination of nodes in the graph.\nFor each combination, the algorithm would check if it dominates every node in the graph, and if it is then checks if it's smaller than the currently known smallest dominating set.\nAfter all combinations are checked, the smallest known set is then guaranteed to be the Minimum Dominating Set.\n\nTo put this concept into pseudocode:\n\n\\begin{algorithm}[H]\n\n    \\caption{Minimum Dominating Set brute force algorithm}\n\n    \\begin{algorithmic}[1]\n        \\Procedure{Minimum Dominating Set}{}\n            \\State $i \\gets 1$\n            \\While{$i < 2^n$}\n                \\State{Convert $i$ into a binary array, $binArray$}\n                \\State{Create an array of $0s$ for the dominated nodes, $domArray$}\n                \\For{each $1 \\in binArray$}\n                    \\State{Get the node at that index from the graph}\n                    \\For{each neighbor of the node}\n                        \\State{Set it to dominated in $domArray$}\n                    \\EndFor\n                \\EndFor\n                \\If{all nodes dominated}\n                    \\If{Current Solution Size $<$ Best Solution Size}\n                        \\State{$bestSolution \\gets i$}\n                    \\EndIf\n                \\EndIf\n                \\State{Increment $i$}\n            \\EndWhile\n        \\EndProcedure\n\n    \\end{algorithmic}\n\n\\end{algorithm}\n\nAs this is a brute force algorithm, the amount of iterations needed is strictly dependent on the size of the graph.\nWe can represent each solution as a set of bits, such that any index with a $1$ indicates that node is a part of the dominating set.\nThe number of possible solutions is therefore $2^n$, resulting in a runtime complexity of $O(2^n)$.\nThe amount of iterations quickly scales up, crossing the one billion mark for a graph of size 30.\nThis indicates that any sufficiently large graphs are essentially outside the limits of brute force computing.\nWe later cover experimental data that shows this.\n\n\\end{document}", "meta": {"hexsha": "2bf7f849f70badaa331df25d1ff79028248c5718", "size": 2662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/Minimum Dominating Set/docs/tex/bruteforce.tex", "max_stars_repo_name": "Bkrenz/calu-csc360", "max_stars_repo_head_hexsha": "8600fb644e145cca27e10b084e9ddf62fbc84f4e", "max_stars_repo_licenses": ["MIT"], "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/Minimum Dominating Set/docs/tex/bruteforce.tex", "max_issues_repo_name": "Bkrenz/calu-csc360", "max_issues_repo_head_hexsha": "8600fb644e145cca27e10b084e9ddf62fbc84f4e", "max_issues_repo_licenses": ["MIT"], "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/Minimum Dominating Set/docs/tex/bruteforce.tex", "max_forks_repo_name": "Bkrenz/calu-csc360", "max_forks_repo_head_hexsha": "8600fb644e145cca27e10b084e9ddf62fbc84f4e", "max_forks_repo_licenses": ["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.9538461538, "max_line_length": 179, "alphanum_fraction": 0.681066867, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839874, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6391017692102879}}
{"text": "\\documentclass[hidelinks, 11pt, openleft]{scrartcl}\n\n\\input{config/bendell-notes-config}\n\n\\title{Midterm Vocabularly List}\n\\author{Cody Mazza-Anthony \\\\ 260405012}\n\\date{March 2014}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Vocabularly from Chapters 1-3}\n\\subsection*{Dot Product in $\\mathbb{R}^2$ (1.4 pg. 4)}\n\n\\begin{itemize}\n    \\item The $u \\cdot v$ is obtained by multiplying corresponding components and adding the resulting products. The vectors $u$ and $v$ are said to be \\textit{orthogonal} (or \\textit{perpendicular}) if their dot product is zero --that is, if $u \\cdot v = 0$.\n    \\item The \\textit{dot product} or \\textit{inner product} of $u$ and $v$ is defined by:\n    \\begin{center}\n        $ u \\cdot v = a_{1}b_{1} + a_{2}b_{2} + \\dots + a_{n}b_{n}$\n    \\end{center}\n\\end{itemize}\n\n\\subsection*{Norm (Length) of a Vector (1.4 pg. 5)}\n\n\\begin{itemize}\n    \\item The \\textit{norm} and \\textit{length} of a vector $u$ in $\\mathbb{R}^n$, denoted by $\\|u\\|$, is defined to be the nonnegative square root of $u \\cdot u$. \n    \\item If $u = (a_{1}, \\dots, a_{n})$, then\n        \\begin{center}\n            $\\|u\\| = \\sqrt{u \\cdot u} = \\sqrt{a_1^2 + \\dots + a_n^2}$ \n        \\end{center}\n    \\item $\\|u\\|$ is the square root of the sum of squares of each of its components of $u$. Thus, $\\|u\\| \\ge 0$, and $\\|u\\|=0$ if and only if $u=0$.\n    \\item A vector $u$ is called a unit vector if $\\|u\\|=1$ or, equivalently, if $u \\cdot u = 1$. For any nonzero vector $v$ in $\\mathbb{R}^n$, the vector\n        \\begin{center}\n            $\\hat{v} = \\frac{v}{\\|v\\|}$\n        \\end{center}\n        is the unique unit vector in the same direction as $v$. The process of finding $\\hat{v}$ from $v$ is called \\textit{normalizing} $v$.\n\\end{itemize}\n\n\\subsection*{Distance and Angle Between Vectors (1.4 pg. 6)}\n\\begin{itemize}\n    \\item The \\textit{distance} between vectors $u=(a_{1}, \\dots. a_{n})$ and $v=(b_{1}, \\dots , b_{n})$ in $\\mathbb{R}^n$ is defined by:\n        \\begin{center}\n            $d(u,v) = \\|u-v\\| = \\sqrt{(a_1-b_1)^2 + \\dots + (a_n-b_n)^2}$ \n        \\end{center}\n    \\item The angle $\\theta$ between nonzero vectors $u,v$ in $\\mathbb{R}^n$ is defined by\n        \\begin{center}\n            ${cos\\theta} = {u \\cdot v \\over \\|u\\|\\|v\\| }$\n        \\end{center}\n\\end{itemize}\n\n\\subsection*{Complex Numbers (1.7 pg. 11)}\n\\begin{itemize}\n    \\item Formally, a complex number is an ordered pair (a,b) of real numbers.\n    \\item The complex number (0,1) is denoted by $i$. Important Property: $i^2 = -1$\n    \\item A complex number can be written $z=(a,b)= a + bi$\n\\end{itemize}\n\n\\subsection*{Complex Conjugation (1.7 pg. 12)}\n\\begin{itemize}\n    \\item Consider the complex number $z=a+bi$. The \\textit{conjugate} of $z$ is denoted and defined by: $\\overline{z} = \\overline{a+bi} = a-bi$.\n\\end{itemize}\n\n\\subsection*{Absolute Value of a Complex Number (1.7 pg. 12)}\n\\begin{itemize}\n    \\item The \\textit{absolute value} of $z$, denoted by $|z|$, is defined to be the nonnegative square root of $z\\overline{z}$. Namely, $|z|= \\sqrt{z\\overline{z}}= \\sqrt{a^2+b^2}$\n\\end{itemize}\n\n\\subsection*{Dot Product in $C^n$ (1.8 pg. 13)}\n\\begin{itemize}\n    \\item The dot or inner product of $u$ and $v$ is denoted by\n    \\begin{align*}\n        u \\cdot v = u_1\\overline{v_1} + \\cdots + u_n\\overline{v_n}\n    \\end{align*}\n\\end{itemize}\n\n\\subsection*{Matrix Multiplication (2.5 pg. 31)}\n\n    \\begin{align*}\n        c_{ij} &= a_{i1}b_{1j} + \\cdots + a_{ip}b_{pj} \\\\\n        &= \\sum_{k=1}^{p} a_{ik}b_{kj}\n    \\end{align*}\n\n\\subsection*{Polynomials in Matrices ()}\n\\vspace{10 cm}\n\n\\subsection*{Invertible Matrices (2.9 pg. 34)}\n\\begin{itemize}\n    \\item A square matrix $A$ is said to be \\textit{invertible} or \\textit{nonsingular} if there exists a matrix $B$ such that: \n    \\begin{align*}\n        AB=BA=I\n    \\end{align*}\n    where $I$ is the identity matrix. Such a matrix $B$ is unique. That is, if $AB_1=B_1A = I$ and $AB_2=B_2A=I$, then\n    \\begin{align*}\n        B_1=B_1I=B_1(AB_2) = (B_1A)B_2=IB_2=B_2\n    \\end{align*}\n    \\item We call such a matrix B the inverse of A and dneote it by $A^-1$. Observe that the above relatin is symmetric; that is, if $B$ is the inverse $A$, then $A$ is the inverse of $B$.\n\\end{itemize}\n\n\\subsection*{Equivalent Systems of Linear Equations (3.3 pg. 60)}\n\\begin{itemize}\n    \\item Two systems of linear equations have the same solutoins if and only if each equation in each system is alinear combination of the equations in the other system.\n    \\item Two systems of linear equations are said to be equivalent if they have the same solutions. \n\\end{itemize}\n\n\\subsection*{Augmented Matrix of a Linear System (3.2 pg. 59)}\n\\begin{itemize}\n    \\item Is the matrix of coefficients plus the last column which is made up of constants, sometimes written $M=[A,B]$.\n\\end{itemize}\n\n\\subsection*{Coefficient Matrix of a Linear System (3.3 pg. 59)}\n\\begin{itemize}\n    \\item Is the matrix of coefficients which is associated with a general system of $m$ equations and $n$ unknowns.\n\\end{itemize}\n\n\\subsection*{Matrix Equation of a system of linear Equations (3.2 pg. 58)}\n\\begin{itemize}\n    \\item Is a list of linear equations with the same unknowns -- that is, a system of $m$ linear equations and $n$ unknowns.\n    \\item The coefficients, constants, and equations can be represented in a matrix as the two above definitions state(augmented or coefficient matrices).\n\\end{itemize}\n\n\\subsection*{Elementary Row Operations(ERO) (3.3 pg. 61) }\n\\begin{itemize}\n    \\item The following operations on a system of linear equations:\n        \\begin{enumerate}\n            \\item Interchange two of the equations.\n            \\item Replace an equation by a nonzero multiple of itself.\n            \\item Replace an equation by the sum of a multiple of another equation and itself.\n        \\end{enumerate}\n\\end{itemize}\n\n\\subsection*{Elementary Matrices (3.12 pg. 84)}\n\\begin{itemize}\n    \\item Let $e$ denote an elementary row operation and let $e(A)$ denote the results of applying the operation $e$ to a matrix $A$. Now let $E$ be the matrix obtained by applying $e$ to the identity matrix $I$; that is,\n    \\begin{align*}\n        E=e(I)\n    \\end{align*}\n    \\item Then $E$ is called the \\textit{elementary matrix} corresponding to the elementary row operation $e$. Note that $E$ is always a square matrix\n\\end{itemize}\n\n\\subsection*{Row Equivalence (3.7 pg. 72)}\n\\begin{itemize}\n    \\item A matrix $A$ is said to be \\textit{row equivalent} to a matrix $B$, written $A~B$\n    \\item If $B$ can be obtained from $A$ by a sequence of elementary row operations. In the case that $B$ is also an echelon matrix, $B$ is called an \\textit{echelon form} of $A$.\n\\end{itemize}\n\n\\subsection*{Echelon Form (3.7 pg. 70)}\n\\begin{itemize}\n    \\item A matrix $A$ is called an \\textit{echelon matrix}, or is said to be in \\textit{echelon form},if the following two conditions hold (where a leading nonzero element of a row A is the first nonzero element in the row):\n    \\begin{enumerate}\n        \\item All zero rows, if any, are at the bottom of the matrix\n        \\item Each leading nonzero entry in a row is to the right of the leading nonzero entry in the preceding row. \n    \\end{enumerate}\n\\end{itemize}\n\n\\subsection*{Row Canonical Form (3.7 pg. 71)}\n\\begin{itemize}\n    \\item A matrix $A$ is said to be in \\textit{row canonical form} if it is an echelon matrix -- that is, if it satisfies the above properties (1) and (2), and if it satisfies the following additional two properties \n    \\item The major difference between an echelon matrix and a matrix in row canonical form is that in an echelon matrix there must be zeros below the pivots, but in a matrix in row canonical form, each pivot must also equal 1 and there must also be zeros above the pivots. \n    \\item The zero matrix of any size and the identity matrix $I$ of any size are important special examples of matrices in row canonical form. \n\\end{itemize}\n\n\\subsection*{Free Variables and Pivot Variables (3.5 pg. 65)}\n\\begin{itemize}\n    \\item The leading unknowns in a system are called \\textit{pivot} variables, and the other unknowns are called \\textit{free variables}.\n\\end{itemize}\n\n\\subsection*{Gaussian Elimination (3.8 pg. 73)}\n\\begin{itemize}\n    \\item Algorithms to convert matrices to echelon form and row canonical form by using elementary row operations, are simply restatements of the Gaussian elimination as applied to matrices rather than linear equations.\n\\end{itemize}\n\n\\subsection*{Homogeneous Systems of Linear Equations associated to a Matrix (3.11 pg. 81)}\n\\begin{itemize}\n    \\item A system of linear equations is said to be \\textit{homogeneous} if all the constant terms are zero. Thus, a homogeneous system has the form $AX=0$\n    \\item Such a system has the zero vector as a solution. We are usually interested in whether or not the system has a nonzero solution.\n    \\item Here $r$ denotes the number of equations in echelon form and $n$ denotes the number of unknowns. Thus, the echelon system has $n-r$ free variables.\n    \\begin{enumerate}\n    \\item $r=n$. The system has only the zero solution. \n    \\item $r < n$. The system has a nonzero solution. \n    \\end{enumerate}\n\\end{itemize}\n\n\n\\section{Vocabularly from Chapter 4}\n\n    \\subsection*{Vector Space (4.2 pg. 112)}\n    \\begin{itemize}\n        \\item Let $V$ be a nonempty set with two operations:\n        \\begin{enumerate}\n            \\item Vector Addition: This assigns to any $u, v \\in V$ a sum $u+v$ in $V$.\n            \\item Scalar Multiplication: This assigns to any $u \\in V, k \\in K$ a product $ku \\in V$.\n        \\end{enumerate}\n        \\item There are additional axioms that need to hold located on pg. 113 of the textbook. They can be summarized by saying $V$ is a \\textit{commutative group} under addition. Also, \\textit{subtraction} in $V$ is defined by $u-v = u + (-v)$, where $-v$ is a unique negative of $v$.\n    \\end{itemize}\n    \n    \\subsection*{Subspace (4.5 pg. 117)}\n    \\begin{itemize}\n        \\item Let $V$ be a vector space over field $K$ and let $W$ be a subset of $V$. Then $W$ is a \\textit{subspace} of $V$ if $W$ is itself a vector space over $K$ with respect to the operations of vector addition and scalar multiplication on $V$.\n        \\item The way you would show that any set $W$ is a vector space is to show that $W$ satisfies the eight axioms of a vector space. However, if $W$ is a subset of a vector space $V$, then some of the axioms automatically hold in $W$, because they already hold in $V$. \n        \\item To identify a vector space suppose $W$ is a subset of a vector space $V$. Then $W$ is a subspace of $V$ if the following two conditions hold:\n            \\begin{enumerate}\n                \\item The zero vector 0 belongs to $W$\n                \\item For ever $u, v \\in W, k \\in K$: (i) The sume $u+v \\in W$ (ii) The multiple $ku \\in W$.\n            \\end{enumerate}\n    \\end{itemize}\n    \n    \\subsection*{Linear Combination (4.4 pg. 115)}\n    \\begin{itemize}\n    \\item A vector $v$ in $V$ is a linear combination of vectors $u_{1}, u_{2}, \\dots , u_{m}$ in V if there exists scalars $a_{1}, a_{2}, \\dots , a_{m}$ in K such that\n        \\begin{center}\n            $v = a_{1}u_{1} + a_{2}u_{2} + \\dots + a_{m}u_{m}$\n        \\end{center}\n    \\item Alternatively, $v$ is a linear combination of $u_{1}, u_{2}, \\dots , u_{m}$ if there is a solution to the vector equation\n        \\begin{center}\n            $v = x_{1}u_{1} + x_{2}u_{2} + \\dots + x_{m}u_{m}$\n        \\end{center}\n    where $x_{1},x_{2}, \\dots , x_{m}$ are unknown scalars.\n        \\item A system can have a unique solution, many solutions, or no solution. No solution means that the system cannot be written as a linear combination.\n    \\end{itemize}\n    \n    \\subsection*{Spanning Set (4.4 pg. 116)}\n        \\begin{itemize}\n            \\item Let $V$ be a vector space over $K$. Vectors $u_{1}, u_{2}, \\dots , u_{m}$ in $V$ are said to span V or to form a spanning set of $V$ if every $v$ in $V$ is a linear combination of the vectors $u_{1}, u_{2}, \\dots , u_{m}$ - that is, if there exists scalars $a_{1}, a_{2}, \\dots , a_{m}$ in $K$ such that \n            \\begin{center}\n                $v = a_{1}u_{1} + a_{2}u_{2} + \\dots + a_{m}u_{m}$\n            \\end{center}\n        \\end{itemize}\n\n    \\subsection*{Span of a Set of Vectors ()}\n    \\vspace{10 cm}\n    \n    \\subsection*{Row Space of a Matrix ()}\n    \\vspace{10 cm}\n    \n    \\subsection*{Column Space of a Matrix ()}\n    \\vspace{10 cm}\n\n    \\subsection*{Linear Dependence (4.7 pg. 121)}\n        \\begin{itemize}\n            \\item We say that vectors $v_1, \\cdots ,v_m$ in $V$ are \\textit{linearly depedent} if there exists scalars $a_1, \\cdots, a_m$ in $K$, not all of them 0, such that\n                \\begin{align*}\n                    a_1v_1 + \\cdots + a_mv_m = 0\n                \\end{align*}\n            \\item Otherwise, we say that the vectors are \\textit{linearly independent}.\n        \\end{itemize}\n    \n    \\subsection*{Linear Independence (4.7 pg. 121}\n        \\begin{itemize}\n            \\item Consider the vector equation\n            \\begin{align*}\n                x_1v_1 + \\cdots + x_mv_m = 0\n            \\end{align*}\n            \\item where the x's are unknown scalars in $K$. This equation always has the \\textit{zero solution} $x_1=0, \\cdots,x_m=0$. Suppose this is the only solution; that is, suppose we can show:\n            \\begin{align*}\n                x_1v_1 + \\cdots + x_mv_m = 0\n            \\end{align*}\n            implies\n            \\begin{align*}\n                x_1=0, \\cdots ,x_m=0\n            \\end{align*}\n            \\item Then the vectors $v_1, \\cdots ,v_m$ are \\textit{linearly independent}\n        \\end{itemize}\n    \n    \\subsection*{Basis (4.8 pg. 124)}\n        \\begin{itemize}\n            \\item Definition 1: A set $S = \\{u_1, \\cdots, u_n\\}$ of vectors is a \\textit{basis} of $V$ if it has the following two properties: (1) S is linearly independent (2) $S$ spans $V$.\n            \\item Definition 2: A set $S = \\{u_1, \\cdots, u_n\\}$ of vectors is a \\textit{basis} of $V$ if every $v \\in V$ can be written uniquely as a linear combination of the basis vectors. \n        \\end{itemize}\n        \n    \\subsection*{Dimension ()}\n    \\vspace{10 cm}\n    \n    \\subsection*{Rank of Matrix (4.9 pg. 126)}\n    \\begin{itemize}\n        \\item The \\textit{rank} of a matrix $A$, written rank(A), is equal to the maximum number of linearly independent rows of $A$ or, equivalently, the dimension of the row space of $A$.\n        \\item The rank can be equal to the number of pivots in echelon form.\n        \\item The rank can correspond to the nonzero rows in echelon form, which form a basis for the row space of the original vector.\n    \\end{itemize}\n    \n    \\subsection*{Sum of two Subspaces (4.10 pg. 129)}\n    \\begin{itemize}\n        \\item Suppose $U$ and $W$ are subspaces of $V$. Then one can shows that $U+W$ is a subspace of $V$. Recall that $U \\cap W$ is also a subspace of $V$. \n        \\item Suppose $U$ and $W$ are finite-dimensional subspaces of a vector space $V$. Then $U+W$ has finite dimension and\n            \\begin{align*}\n                dim(U+W) = dimU + dimW - dim(U \\cap W)\n            \\end{align*}\n    \\end{itemize}\n    \n    \\subsection*{Direct Sum (4.10 pg. 129)}\n    \\begin{itemize}\n        \\item The vector space $V$ is said to be the \\textit{direct sum} of its subspaces $U$ and $W$, denoted by\n        \\begin{align*}\n            V=U \\oplus W\n        \\end{align*}\n        \\item if every $v in V$ can be written in one and only one way as $v=u+w$ where $u \\in U$ and $w \\in W$.\n    \\end{itemize}\n    \n    \\subsection*{Coordinates (4.11 pg. 130)}\n    \\begin{itemize}\n        \\item Let $V$ be an n-dimensional vector space over $K$ with basis $S=\\{u_1, \\cdots , u_n\\}$. Then any vector $v \\in V$ can be expressed uniquely as a linear combination of the basis vectors ini $S$, say\n        \\begin{align*}\n            v = a_1u_1 + \\cdots + a_nu_n\n        \\end{align*}\n        \\item Then $n$ scalars $a_1, \\cdots , a_n$ are called the \\textit{coordinates} of $v$ relative to the basis $S$, and they form a vector $[a_1, \\cdots , a_n]$ in $K^n$ called the \\textit{coordinate vector} of $v$ relative to $S$. \n        \\item We denote this vector by $[v]_S$, or simple $[v]$, when $S$ is understood. Thus,\n        \\begin{align*}\n            [v]_S = [a_1, \\cdots , a_n]\n        \\end{align*}\n    \\end{itemize}\n    \n    \\subsection*{Isomorphism of vector spaces (4.11 pg. 130)}\n    \\vspace{10 cm}\n    \n    \n\\section{Vocabularly from Chapters 5 and 6}\n\n\\subsection*{Function/Mapping (5.2 pg. 164)}\n\\begin{itemize}\n    \\item Let $A$ and $B$ be arbitrary sets. Suppose to each element in $a \\in A$ there is assigned a unique element of B; called the \\textit{image} of $a$. \n    \\item The collection of $f$ of such assignments is called a \\textit{mapping} from $A$ to $B$, and is denoted by\n        \\begin{center}\n            $f: A \\to B$\n        \\end{center}\n    \\item The set $A$ is called the \\textit{domain} of the mapping, and $B$ is called the \\textit{target set}.\n    \\item One may also view a mapping $f: A \\to B$ as a computer that, for each input value $a \\in A$, produces a unique output $f(a) \\in B$.\n\\end{itemize}\n\n\\subsection*{Range/Image (5.2 pg. 164)}\n\\begin{itemize}\n    \\item Is a subset of the \\textit{target set} that the function actually maps to. \n    \\item Sometimes the \"barred\" arrow $\\mapsto$ is used to denote the range of an arbitrary element $x \\in A$ under a mapping $f: A \\to B$ by writing $x \\mapsto f(x)$.\n\\end{itemize}\n\n\n\\subsection*{One-to-One Mapping (5.2 pg. 166)}\n\\begin{itemize}\n    \\item A mapping $f: A \\to B$ is said to be \\textit{one-to-one} (or 1-1 or injective) if different elements of A have distinct images; that is,\n        \\begin{center}\n            If $f(a) = f(a')$, then $a=a'$\n        \\end{center}\n\\end{itemize}\n\n\\subsection*{Onto Mapping (5.2 pg. 166)}\n\\begin{itemize}\n    \\item A mapping $f: A \\to B$ is said to be \\textit{onto} (or $f$ maps $A$ onto $B$ or \\textit{surjective}) if ever $b \\in B$ is the range of at least one $a \\in A$.\n\\end{itemize}\n\n\\subsection*{Linear Transformation (5.3 pg. 167)}\n\\begin{itemize}\n    \\item Let $V$ and $U$ be vector spaces over the same field $K$. A mapping $F: V \\to U$ is called a \\textit{linear mapping} or \\textit{linear transformation} if it satisfies the following two conditions:\n        \\begin{enumerate}\n            \\item For any vectors $v, w \\in V, F(v+w) = F(v) + F(w)$.\n            \\item For any scalar $k$ and vector $v \\in V, F(kv) = kF(v)$.\n        \\end{enumerate}\n    \\item Basically, $F: V \\to U$ is linear if it \"preserves\" the two basic operations of a vector space, that of vector addition and that of scalar multiplication.\n\\end{itemize}\n\n\\subsection*{Kernal (5.4 pg. 169)}\n\n\\begin{itemize}\n    \\item Let $F: V \\to U$ be a linear transformation/mapping. The \\textit{kernel} of $F$, written Ker F, is the set of elements in $V$ that map into the zero vector 0 in $U$; that is,\n    \\begin{center}\n        Ker $F = \\{v \\in V: F(v) = 0\\}$\n    \\end{center}\n\\end{itemize}\n\n\\subsection*{Image (5.4 pg. 169)}\n\n\\begin{itemize}\n    \\item The \\textit{image} of $F$, written Im $F$, is the set of image points in $U$; that is,\n    \\begin{center}\n        Im $F = \\{u \\in U: there exists v \\in V for which F(v) = u\\}$\n    \\end{center}\n\\end{itemize}\n\n\\subsection*{Rank (5.4 pg. 171)}\n\\begin{itemize}\n    \\item Let $F: V \\to U$ be a linear mapping. The \\textit{rank} of $F$ is defined to be the dimension of its image.\n    \\begin{center}\n        rank(F) = dim(Im F)\n    \\end{center}\n\\end{itemize}\n\n\\subsection*{Nullity (5.4 pg. 171)}\n\\begin{itemize}\n    \\item The \\textit{nullity} of $F$ is defined to be the dimension of its kernel\n    \\begin{center}\n        nullity(F) = dim(Ker F)\n    \\end{center}\n\\end{itemize}\n\n\\subsection*{Linear Transformation associated to a Matrix (Matrix Mapping) () }\n\\vspace{10 cm}\n\n\\subsection*{Singular Linear Transformation (5.5 pg. 172)}\n\\begin{itemize}\n    \\item Let $F: V \\to U$ be a linear mapping. Recall that $F(0) = 0$. $F$ is said to be $singular$ if the image of some nonzero vector $v$ is 0 -- that is, if there exists $v \\ne 0$ such that $F(v) = 0$.\n\\end{itemize}\n\n\\subsection*{Matrix Representation of Linear Transformation ()}\n\\vspace{10 cm}\n\n\n\\end{document}\n", "meta": {"hexsha": "e3c0f052f74caef65a179775790a28a581147fa7", "size": 20243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vocab.tex", "max_stars_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_stars_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-03T23:09:18.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-03T23:09:18.000Z", "max_issues_repo_path": "Vocab.tex", "max_issues_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_issues_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Vocab.tex", "max_forks_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_forks_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_forks_repo_licenses": ["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.8596059113, "max_line_length": 322, "alphanum_fraction": 0.6437780961, "num_tokens": 6387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8006920020959545, "lm_q1q2_score": 0.6391017691148559}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\setcounter{section}{-1}\n\n\\begin{document}\n\n\\title{Logic and Set Theory}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Miscellaneous}\n\nSome introductory speech\n\n\\newpage\n\n\\section{Propositional logic}\nLet $P$ denote a set of \\emph{primitive proposition}, unless otherwise stated, $P=\\{p_1,p_2,...\\}$.\n\n\\begin{defi}\nThe \\emph{language} or \\emph{set of propositions} $L=L(P)$ is defined inductively by:\\\\\n(1) $p \\in L$ $\\forall p \\in P$;\\\\\n(2) $\\perp \\in L$, where $\\perp$ is read as 'false';\\\\\n(3) If $p,q \\in L$, then $(p \\implies q) \\in L$. For example, $(p_1 \\implies L)$, $((p_1 \\implies p_2) \\implies (p_1 \\implies p_3))$.\n\\end{defi}\n\nNote that at this point, each proposition is only a finite string of symbols from the alphabet $(,),\\implies,\\perp,p_1,p_2,...$ and do not really mean anything (until we define so).\\\\\nBy \\emph{inductively define}, we mean more precisely that we set $L_1 = P \\cup \\{\\perp\\}$, and $L_{n+1} = L_n \\cup \\{(p \\implies q):p,q \\in L_n\\}$, and then put $L = L_1 \\cup L_2 \\cup ...$.\n\nEach proposition is built up \\emph{uniquely} from 1) and 2) using 3). For example, $((p_1 \\implies p_2) \\implies (p_1 \\implies p_3))$ came from $(p_1 \\implies p_2)$ and $(p_1 \\implies p_3)$. We often omit outer brackets or use different brackets for clarity.\n\nNow we can define some useful things:\\\\\n$\\bullet$ $\\neg p$ (not $p$), as an abbreviation for $p \\implies \\perp$;\\\\\n$\\bullet$ $p \\vee q$ ($p$ or $q$), as an abbreviation for $(\\neg p) \\implies q$;\\\\\n$\\bullet$ $p \\wedge q$ ($p$ and $q$), as an abbreviation for $\\neg (p \\implies (\\neg q))$.\n\nThese definitions 'make sense' in the way that we expect them to.\n\n\\begin{defi}\nA \\emph{valuation} is a function $v:L \\to \\{0,1\\}$ s.t.\\\\\n(1) $v(\\perp) = 0$;\n(2) \n\\begin{equation*}\n\\begin{aligned}\nv(p \\implies q) = \\left\\{ \\begin{array}{ll}\n0 & v(p) =1, v(q) = 0\\\\\n1 & else\n\\end{array}\n\\right. \\forall p,q \\in L\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{rem}\nOn $\\{0,1\\}$, we could define a constant $\\perp$ by $\\perp = 0$, and an operation $\\implies$ by $a \\implies b = 0$ if $a=1, b=0$ and $1$ otherwise. Then a valuation is a function $L \\to \\{0,1\\}$ that preserves the structure ($\\perp$ and $\\implies$), i.e. a homomorphism.\n\\end{rem}\n\n\\begin{prop}\n(1) If $v,v'$ are valuations with $v(p) = v'(p)$ $\\forall p \\in P$, then $v=v'$ (on $L$).\\\\\n(2) For any $w:P \\to \\{0,1\\}$, there exists a valuation $v$ with $v(p) = w(p)$ $\\forall p \\in P$.\\\\\nIn short, a valuation is defined by its value on $p$, and any values will do.\n\\begin{proof}\n(1) We have $v(p)=v'(p)$ $\\forall p \\in L_1$. However, if $v(p) = v'(p)$ and $v(q) = v'(q)$ then $v(p \\implies q) = v'(p \\implies q)$, so $v=v'$ on $L_2$. Continue inductively we have $v=v'$ on $L_n \\forall n$.\\\\\n(2) Set $v(p) = w(p)$ $\\forall p \\in P$ and $v(\\perp) = 0$: this defines $v$ on $L_1$. Having defined $v$ on $L_n$, use the rules for valuation to inductively define $v$ on $L_{n+1}$ so we can extend $v$ to $L$.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi}\nWe say $p$ is a \\emph{tautology}, written $\\vDash p$, if $v(p) = 1$ $\\forall$ valuations $v$. Some examples:\\\\\n(1) $p \\implies (q \\implies p)$: a true statement is implies by anything. We can verify this by:\n\\begin{equation*}\n\\begin{aligned}\n\\begin{matrix}\nv(p) & v(q) & v(q \\implies p) & v(p \\implies (q \\implies p))\\\\\n1 & 1 & 1 & 1\\\\\n1 & 0 & 1 & 1\\\\\n0 & 1 & 0 & 1\\\\\n0 & 0 & 1 & 1\n\\end{matrix}\n\\end{aligned}\n\\end{equation*}\n\nSo we see that this is indeed a tautology;\\\\\n(2) $(\\neg\\neg p) \\implies p$, i.e. $((p \\implies \\perp) \\implies \\perp) \\implies p$, called the \"law of excluded middle\";\n\n(3) $[p \\implies (q \\implies r)] \\implies [(p \\implies q) \\implies (p \\implies r)]$.\\\\\nIndeed, if not then we have some $v$ with $v(p\\implies(q \\implies r)) = 1$, $v(\\implies (p \\implies q) \\implies (p \\implies r)) = 0$. So $v(p\\implies q) = 1$, $v(p \\implies r) =0$. This happens when $v(p) = 1$, $v(r) = 0$, so also $v(q) = 1$. But then $v(q \\implies r)=0$, so $v(p \\implies (q \\implies r)) = 0$.\n\\end{defi}\n\n\\begin{defi}\nFor $S \\subset L$, $t \\in L$, say $S$ \\emph{entails} or \\emph{semantically implies} $t$, written $S \\vDash t$ if $v(s) = 1 \\forall s \\in S \\implies v(t) = 1$, for each valuation $v$.\\\\\n(\"Whenever all of $S$ is true, $t$ is true as well.\")\n\nFor example, $\\{p \\implies q, q \\implies r\\} \\vDash (p \\implies r)$. To prove this, suppose not: so we have $v$ with $v(p\\implies q) = v(q\\implies r) = 1$ but $v(p\\implies r) = 0$. So $v(p) = 1$, $v(r) = 0$, so $v(q) = 0$, but then $v(p \\implies q)$ = 0.\n\nIf $v(t) = 1$ we say $t$ is true in $v$ or that $v$ is a model of $t$.\n\nFor $S \\subset L$, $v$ is a model of $S$ if $v(s) = 1$ $\\forall s \\in S$. So $S \\vDash t$ says that every model of $S$ is a model of $t$. For example, in fact $\\vDash t$ is the same as $\\phi \\vDash t$.\n\\end{defi}\n\n\\newpage\n\n\\section{Syntactic implication}\n\nFor a notion of 'proof', we will need axioms and deduction rules. As axioms, we'll take:\\\\\n1. $p \\implies (q \\implies p)$ $\\forall p,q \\in L$;\\\\\n2. $[p\\implies (q \\implies r)] \\implies [(p \\implies q) \\implies (p \\implies r)]$ $\\forall p,q,r \\in L$;\\\\\n3. $(\\neg\\neg p) \\implies p$ $\\forall p \\in L$.\n\nNote: these are all tautologies. Sometimes we say they are 3 axiom-schemes, as all of these are infinite sets of axioms.\n\nAs deduction rules, we'll take just \\emph{modus ponens}: from $p$, and $p\\implies q$, we can deduce $q$.\n\nFor $S \\subset L$, $t \\in L$, a \\emph{proof} of $t$ from $S$ cosists of a finite sequence $t_1,...,t_n$ of propositions, with $t_n = t$, s.t. $\\forall i$ the proposition $t_i$ is an axiom, or a member of $S$, or there exists $j,k < i$ with $t_j=(t_k \\implies t_i)$.\n\nWe say $S$ is the \\emph{hypotheses} or \\emph{premises} and $t$ is the \\emph{conclusion}.\n\nIf there exists a proof of $t$ from $S$, we say $S$ \\emph{proves} or \\emph{syntactically implies} $t$, written $S \\vdash t$.\n\nIf $\\phi \\vdash t$, we say $t$ is a \\emph{theorem}, written $\\vdash t$.\n\n\\begin{eg}\n$\\{p \\implies q, q \\implies r\\} \\vdash p \\implies r$.\\\\\nwe deduce by the following:\\\\\n(1) $[p \\implies (q \\implies r)] \\implies [(p \\implies q) \\implies (p \\implies r)]$; (axiom 2)\\\\\n(2) $q \\implies r$; (hypothesis)\\\\\n(3) $(q \\implies r) \\implies (p \\implies (q \\implies r))$; (axiom 1)\\\\\n(4) $p \\implies (q \\implies r)$; (mp on 2,3)\\\\\n(5) $(p \\implies q) \\implies (p \\implies r)$ (mp on 1,4);\\\\\n(6) $p \\implies q$; (hypothesis)\\\\\n(7) $p \\implies r$. (mp on 5,6)\n\\end{eg}\n\n\\begin{eg}\nLet's now try to prove $\\vdash p \\implies p$. Axiom 1 and 3 probably don't help so look at axiom 2; if we make $(p \\implies q)$ and $p\\implies (q \\implies r)$ something that's a theorem, and make $p \\implies r$ to be $p \\implies p$ then we are done. So we need to take $p=p,q=(p \\implies p), r=p$. Now:\\\\\n(1) $[p \\implies ((p \\implies p) \\implies p)] \\implies [( p \\implies (p \\implies p)) \\implies (p \\implies p)]$; (axiom 2)\\\\\n(2) $p \\implies ((p \\implies p) \\implies p)$; (axiom 1)\\\\\n(3) $(p \\implies (p \\implies p)) \\implies (p \\implies p)$; (mp on 1,2)\\\\\n(4) $p \\implies (p \\implies p)$; (axiom 1)\\\\\n(5) $p \\implies p$. (mp on 3,4)\n\\end{eg}\n\nProofs are made easier by:\n\\begin{prop} (2, deduction theorem)\\\\\nLet $S \\subset L$, $p,q \\in L$. Then $S \\vdash (p \\implies q)$ if and only if $(S \\cup \\{p\\}) \\vdash q$.\n\\begin{proof}\nForward: given a proof of $p \\implies q$ from $S$, add the lines $p$ (hypothesis), $q$ (mp) to optaion a proof of $q$ from $S\\cup\\{p\\}$.\\\\\nBackward: if we have proof $t_1,...,t_n=q$ of $q$ from $S \\cup \\{p\\}$. We'll show that $S \\vdash (p \\implies t_i) \\forall i$, so $p \\implies t_n=q$.\\\\\nIf $t_i$ is an axiom, then we have $\\vdash t_i \\implies (p \\implies t_i)$, so $\\vdash p \\implies t_i$;\\\\\nIf $t_i \\in S$, write down $t_i$, $t_i \\implies (p \\implies t_i)$, $p \\implies t_i$ we get a proof of $p \\implies t_i$ from $S$;\\\\\nIf $t_i = p$: we know $\\vdash (p \\implies p)$, so done;\\\\\nIf $t_i$ obtained by mp: in that case we have some earlier lines $t_j$ and $t_j \\implies t_i$. By induction, we may assume $S \\vdash (p \\implies t_j)$ and $S \\vdash (p \\implies (t_j \\implies t_i))$. Now we can write down $[p \\implies (t_j \\implies t_i)] \\implies [(p \\implies t_j) \\implies (t_i)]$ by axiom 2, $p \\implies (t_j \\implies t_i)$, $p \\implies t_j) \\implies (p \\implies t_i)$ (mp), $p \\implies t_j$, $p \\implies t_i$ (mp) to obtain $S \\vdash (p \\implies t_i)$.\n\nThese are all of the cases. So $S \\vdash (p \\implies q)$.\n\\end{proof}\nThis is why we chose axiom 2 as we did -- to make this proof work.\n\\end{prop}\n\n\\begin{eg}\nTo show $\\{p \\implies q, q \\implies r\\} \\vdash (p \\implies r)$, it's enough to show that $\\{p \\implies q, q \\implies r, p\\} \\vdash r$, which is trivial by mp.\n\\end{eg}\n\nNow, how are $\\vdash$ and $\\vDash$ related? We are going to prove the \\emph{completeness theorem}: $S \\vdash t \\iff S \\vDash t$.\n\nThis ensures that our proofs are sound, in the sense that everything it can prove is not absurd ($S \\vdash t$ then $S \\vDash t$), and are adequate, i.e. our axioms are powerful enough to define every semantic consequence of $S$, which is not obvious ($S \\vDash t$ then $S \\vdash t$).\n\n\\begin{prop} (3)\\\\\nLet $S \\subset L$, $t \\in L$. Then $S \\vdash t \\implies S \\vDash t$.\n\\begin{proof}\nGiven a valuation $v$ with $v(s) =1$ $\\forall s \\in S$, we want $v(t) = 1$.\\\\\nWe have $v(p) = 1$ $\\forall p$ axiom as our axioms are all tautologies (proven earier); $v(p)=1$ $\\forall p \\in S$ by definition of $v$; also if $v(p) = 1$ and $v(p \\implies q) = 1$, then also $v(q) = 1$ (by definition of $\\implies$). So $v(p) = 1$ for each line $p$ of our proof of $t$ from $S$.\n\\end{proof}\n\\end{prop}\n\nWe say $S \\subset L$ consistent if $S \\not\\vdash \\perp$. One special case of adequacy is: $S \\vDash \\perp \\implies S \\vdash \\perp$, i.e. if $S$ has no model then $S$ inconsistent, i.e. if $S$ is consistent then $S$ has a model. This implies adequacy: given $S \\vDash t$, we have $S \\cup \\{\\neg t\\} \\vDash \\perp$, so by our special case we have $S \\cup \\{\\neg t\\} \\vdash \\perp$, i.e. $S \\vdash ((\\neg t) \\implies t)$ by deduction theorem, so $S \\vdash \\neg\\neg t$. But $S \\vdash ((\\neg\\neg t) \\implies t)$ by axiom 3, so $S \\vdash t$ (mp).\n\n\\begin{thm} (4)\\\\\nLet $S \\subset L$ be consistent, then $S$ has a model.\\\\\nThe idea is that we would like to define valuation $v$ by $v(p) = 1 \\iff p \\in S$, or more sensibly, $v(p)=1 \\iff S \\vdash p$.\\\\\nBut maybe $S \\not \\vdash p_3, S \\not\\vdash \\neg p_3$, but a valuation maps half of $L$ to 1, so we want to 'grow' $S$ to contain one of $p$ or $\\neg p$ for each $p \\in L$, while keeping consistency.\n\\begin{proof}\nClaim: for any consistent $S \\subset L$, $p \\in L$, $S \\cup \\{p\\}$ or $S \\cup \\{\\neg p\\}$ consistent.\n\\emph{Proof of claim.} If not, then $S \\cup \\{p\\} \\vdash \\perp$ and $S \\cup \\{\\neg p\\} \\vdash \\perp$, then $S \\vdash (p \\implies \\perp)$ (deduction theorem), i.e. $S \\vdash \\not p$, so $S \\vdash \\perp$ contradiction.\n\nNow $L$ is countable as each $L_n$ is countable, so we can list $L$ as $t_1,t_2,...$. Put $S_0 = S$; set $S_1 = s_0 \\cup \\{t_1\\}$ or $s_0 \\cup (\\neg t_1\\}$ so that $S_1$ is consistent. Then set $S_2 = S_1 \\cup \\{t_2\\}$ or $S_1 \\cup \\{\\neg t_2\\}$ so that $S_2$ is consistent, and continue likewise. Set $\\bar{S} = S_0 \\cup S_1 \\cup S_2 \\cup ...$ Then $\\bar{S} \\supset S$, and $\\bar{S}$ is consistent (as each $S_n$ is, and each proof is finite). $\\forall p \\in L$, we have either $p \\in S$ or $(\\neg p) \\in S$. Also, $\\bar{S}$ is \\emph{deductively closed}, meaning that is $\\bar{S} \\vdash p$ then $p \\in \\bar{S}$: if $p \\not\\in \\bar{S}$ then $(\\neg p) \\in \\bar{S}$, so $\\bar{S} \\vdash p$, $\\bar{S} \\vdash (\\not p)$ so $\\bar{S} \\vdash \\perp$ contradiction.\\\\\nDefine $v:L \\to \\{0,1\\}$ by $p \\to 1$ if $p \\in \\bar{S}$, $0$ otherwise. Then $v$ is a valuation: $v(\\perp) = 0$ as $\\perp \\not\\in \\bar{S}$; for $v(p \\implies q)$:\\\\\nIf $v(p) = 1$, $v(q) = 0$: We have $p \\in \\bar{S}$, $q \\not\\in \\bar{S}$, and want $v(p \\implies q) = 0$, i.e. $(p \\implies q \\not\\in \\bar{S}$. But if $9p \\implies q) \\in \\bar{S}$ then $\\bar{S} \\vdash q$ contradiction;\\\\\nIf $v(q) = 1$: have $q \\in \\bar{S}$, and want $v(p \\implies q) =1$, i.e. $(p \\implies q) \\int \\bar{S}$. But $\\vdash q \\implies (p \\implies q)$ so $\\bar{S} \\vdash (p \\implies q)$;\\\\\nIf $v(p) = 0$: have $p \\not\\in \\bar{S}$, i.e. $(\\neg p) \\in \\bar{S}$ and want $(p \\implies q) \\in \\bar{S}$. So we need $(p \\implies \\perp) \\vdash (p \\implies q)$, i.e. $p \\implies \\perp,p \\vdash q$ (deduction theorem). Thus it's enough to show that $\\perp \\vdash q$. But $(\\neg\\neg q) \\implies q$, and $\\vdash (\\perp \\implies (\\neg\\neg q))$ (axiom 3 and 1 -- to see the second one, write $\\neg$ explicitly using $\\implies$ and $\\perp$), so $\\vdash(\\perp \\implies q)$, i.e. $\\perp\\vdash q$.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\nSometimes this is called 'completeness theorem'. The proof used $P$ being countable to get $L$ countable; in fact, result still holds if $P$ is uncountable (see chapter 3).\n\\end{rem}\n\nBy remark before theorem 4, we have\n\\begin{coro} (5, adequacy)\\\\\nLet $S \\subset L$, $t \\in L$. Then if $S \\vDash t$ then $S \\vdash t$.\n\\end{coro}\n\nAnd hence,\n\\begin{thm} (6, completeness theorem)\\\\\nLet $S \\subset L$, $t \\in L$. Then $S \\vdash t \\iff S \\vDash t$.\n\\end{thm}\n\nSome consequences:\n\\begin{coro} (7, compactness theorem)\\\\\nLet $S \\subset L$, $t \\in L$ with $S \\vDash t$. Then $\\exists$ finite $S' \\subset S$ with $S' \\vDash t$.\\\\\nThis is trivial if we replace $\\vDash$ by $\\vdash$ (as proofs are finite).\n\\end{coro}\n\nSpecial case for $t=\\perp$: If $S$ has no model then some finite $S' \\subset S$ has no model. Equivalently,\n\\begin{coro} (7', compactness theorem, equivalent form)\\\\\nLet $S \\subset L$. If every finite subset of $S$ has a model then $S$ has a model.\\\\\nThis \\emph{isi} equivalent to corollary 7 because $S \\vDash t$ $\\iff S \\cup \\{\\neg t\\}$ has no model and $S' \\vDash t \\iff S' \\cup (\\neg t)$ has no model.\n\\end{coro}\n\n\\begin{coro} (8, decidability theorem)\\\\\nThere is an algorithm to determine (in finite time) whether or not, for a given finite $S \\subset L$ and $t \\in L$, we have $S \\vdash t$.\\\\\nThis is highly non-obviuos; however it's trivial to decide if $S \\vDash t$ just by drawing a truth table, and $\\vDash \\iff \\vdash$.\n\\end{coro}\n\n\\newpage\n\n\\section{Well-Orderings and Ordinals}\n\n\\begin{defi}\nA \\emph{total order} or \\emph{linear order} on a set $X$ is a relation $<$ on $X$, such that\\\\\n(1) Irreflexive: Not $x<x$ $\\forall x \\in X$;\\\\\n(2) Transitive: $x<y,y<z\\implies x<z$ $\\forall x,y,z \\in X$;\\\\\n(3) Trichotomous: $x<y$ or $x=y$ or $y<x$ $\\forall x,y \\in X$.\\\\\nNote: two of (iii) cannot hold: if $x<y$, $y<x$ then $x<x$ by transitivity.\\\\\nWrite $x \\leq y$ if $x<y$ or $x=y$, and $y>x$ if $x<y$.\n\nWe can also define total order in terms of $\\leq$:\\\\\n(1) Reflexive: $x \\leq x$ $\\forall x \\in X$;\\\\\n(2) Transitive: $x\\leq y, y \\leq z \\implies x \\in z$ $\\forall x,y,z \\in X$;\\\\\n(3) Antisymmetric: $x \\leq y,y \\leq x \\implies x=y$ $\\forall x,y \\in X$;\\\\\n(4) 'Tri'chotomous (although it's only two): $x\\leq y$ or $y \\leq x$ $\\forall x,y \\in X$.\n\\end{defi}\n\n\\begin{eg}\n$\\N,\\Q,\\R$ with the usual orders are all total orders.\\\\\n$\\N^+$ the relation 'divides' is not a total order: for example we don't have any of $2|3,3|2$ or $2=3$.\\\\\n$\\mathcal{P}(S)$ for some $S$ (with $|S|\\geq 2$ to be rigorous), with $x \\leq y$ if $x\\subseteq y$ is not a total order for the same reason.\n\\end{eg}\n\nA total order is a \\emph{well-ordering} if every (non-empty) subset has a least element, i.e. $\\forall S \\subset X, S \\neq \\phi \\implies \\exists x \\in S, x \\leq y \\forall y \\in S$.\n\n\\begin{eg}\n1.$\\N$ with the usual $<$ is a well ordering.\\\\\n2.$\\Z,\\Q,\\R$ with the usual $<$ are not well orderings.\\\\\n3.$\\Q^+ \\cup \\{0\\}$ with the usual $<$ is not a well ordering (e.g. $(0,\\infty) \\subset \\Q^+\\cup \\{0\\}$).\\\\\n4.The set $\\{1-\\frac{1}{n} : n=2,3,...\\}$ as a subset of $\\R$ with the usual ordering is a well ordering.\n5.The set $\\{1-\\frac{1}{n} : n=2,3,...\\} \\cup \\{1\\}$ as a subset of $\\R$ with the usual ordering is a well ordering.\n6.The set $\\{1-\\frac{1}{n} : n=2,3,...\\} \\cup \\{2-\\frac{1}{n} : n=2,3,...\\}$ (same assumption) is a well ordering.\n\\end{eg}\n\n\\begin{rem}\n$X$ is well-ordered iff there is no $x_1>x_2>x_3>...$ in $X$.\\\\\nClearly if there is such a sequence then $S=\\{x_1,x_2,...\\}$ has no least element. Conversely, if $S \\subset X$ has no least element, then for each element $x \\in S$ there exists a $x' \\in S$ with $x' < x$, so we can just pick $x,x',...$ inductively.\n\\end{rem}\n\n\\begin{defi}\nWe say total orders $X,Y$ are \\emph{isomorphic} if there exists a bijection $f:X \\to Y$ that is order-preserving, i.e. $x<y \\iff f(x) <f(y)$.\\\\\nFor example, 1 and 4 above are isomorphic; 5 and 6 are isomorphic; 4 and 5 are not isomorphic (one has a greatest element, and the other doesn't).\n\\end{defi}\n\nHere comes the first reason why well orderings are useful:\n\\begin{prop} (1, Proof by induction)\\\\\nLet $X$ be well-ordered, and let $S \\subset X$ be s.t. if $y \\in S$ $\\forall y < x$ then $x \\in S$ (each $x \\in X$). Then $S=X$.\\\\\nEquivalently, if $p(x)$ is a property s.t. $\\forall x$: if $p(y) \\forall y < x$ then $p(x)$, then $p(x) \\forall x$.\\\\\n(I think we must assert $S$ to be non-empty here, but the lecturer didn't agree with me; need to check later.)\n\\begin{proof}\nIf $S \\neq X$ then let $x$ be the least element of $X \\setminus S$. Then $x \\not\\in S$. But $y \\in S$ $\\forall y<x$, contradiction.\n\\end{proof}\n\\end{prop}\n\nA typical use:\n\n\\begin{prop}\nLet $X,Y$ be isomorphic well-orderings. Then there is a \\emph{unique} isomorphism from $X$ to $Y$.\n\\begin{proof}\nLet $f,g$ be isomorphisms. We'll show $f(x) = g(x)$ $\\forall x$ by induction. Thus we may assume $f(y) = g(y)$ $\\forall y < x$, and want $f(x) = g(x)$. Let $a$ be the least element of $Y\\setminus \\{f(y):y<x\\}$. Then we must have $f(x) = a$: if $f(x) > a$, then some $x'>x$ has $f(x') = a$ by surjectivity, contradiction. The same shows $g(x) = $least element of $Y\\setminus \\{g(y):y<x\\}$, but this is the same as $a$. So $f(x) = g(x)$.\n\\end{proof}\n\\end{prop}\n\n\\begin{rem}\nThis is false for total orders in general. One example is, consider from $\\Z \\to \\Z$, we could either take identity, or $x \\to x-5$; or from $\\R$ to $\\R$ we could take identity or $x \\to x-5$ or $x\\to x^3$...\n\\end{rem}\n\n\\begin{defi}\nIn a total order $X$, an \\emph{initial segment} $I$ is a subset of $X$ such that $x \\in I, y < x \\implies y \\in I$.\n\\end{defi}\n\n\\begin{eg}\nFor any $x \\in X$, set $I(x) = \\{y\\in X : y < x\\}$. Then this is an initial segment.\\\\\nObviously, not every initial segment is of this form: for example, in $\\R$ we can take $\\{x:x \\leq 3\\}$; or in $\\Q$, take $\\{x:x^2 < 2\\} \\cup \\{x<0\\}$ (this cannot be written as above form as $\\sqrt{2} \\not\\in \\Q$.\\\\\nNote: in a well-ordering, every proper initial segment \\emph{is} of the above form: let $x$ be the least elemnt of $X \\setminus I$. Then $y<x \\implies y \\in I$. Conversely, if $y \\in I$, then we must have $y < x$: otherwise $x \\in I$, contradiction.\n\\end{eg}\n\nOur aim is to show that every subset of a well-ordered $X$ is isomorphic to an initial segment.\\\\\nNote: this is very false for total orders: e.g. $\\{1,5,9\\} \\subset \\Z$, or $\\Q \\subset \\R$. If we have $S \\subset X$, Wwe would like to define $f:S \\to X$ that sends the smallest of $S$ to the smallest of $X$, then remove them from both sets and send the smallest of the remaining to the smallest of the remaining, etc... But to do this we need a theorem.\n\n\\begin{thm} (3, definition by recursion)\\\\\nLet $X$ be well-ordered, $Y$ be a set, and $G:\\mathcal{P}(X\\times Y) \\to Y$. Then $\\exists f : X \\to Y$ s.t. $f(x) = G(f|_{I_x})$ for all $x \\in X$. Moreover, such $f$ is unique.\\\\\nHere we define the restriction as: for $f:A \\to B$, and $C \\subset A$, the restriction of $f$ to $C$ is $f|_C = \\{(x,f(x)) : x \\in C\\}$. (I think the lecturer is regarding a function as subset of a cartesian product)\\\\\nIn defining $f(x)$, make use of $f|_{I_x}$, i.e. the values of $f(y), y<x$.\\\\\n\\begin{proof}\nExistence: define '$h$ is an attempt' to mean: $h:I \\to Y$, some initial segment $I$ of $X$, and $\\forall x \\in I$ we have $h(x) = G(h|_{I_X})$. Note that is $h,h'$ are attempts, both defined at $x$, then $h(x) = h'(x)$ by induction on $x$. Since if $h(y) = h'(y) \\forall y < x $ then $h(x) = h'(x)$.\\\\\nAlso, $\\forall x \\in X$ there exists an attempt defined at $x$ by induction on $x$: we want attempt definde at $x$, given $\\forall y < x$ there exists attempt defined at $y$. For each $y<x$, we have unique attempt $h_y$ defined on $\\{z:z\\leq y\\}$ (unique by what we just showed).\\\\\nLet $h = \\cup_{y < x} h_y$: an attempt defined on $I_x$. This is single-valued by uniqueness, so is indeed a function.\\\\\nSo $h'=h \\cup \\{(x,G(h))\\}$ is an attempt defined at $x$.\\\\\nNow set $f(x) = y$ if $\\exists$ attempt $h$, defined at $x$, with $h(x) = y$ (single-valued).\\\\\nUniqueness: if $f,f'$ suitable then $f(x) = f'(x) \\forall x \\in X$ (induction on $X$) -- since if $f(y) = f'(y) \\forall y < x$ then $f(x) = f'(x)$.\n\\end{proof}\n\\end{thm}\n\nA typical application:\n\n\\begin{prop} (4, subset collapse)\\\\\nLet $X$ be well-ordered, $Y \\subset X$. Then $Y$ is isomorphic to an initial segment of $X$. Moreover, such initial segment is unique.\\\\\n\\begin{proof}\nTo have $f$ an isomorphism from $y$ to an initial segment of $X$, we need precisely that $\\forall x \\in Y: f(x) = \\min X \\setminus \\{f(y):y<x\\}$. So done (existence and uniqueness) by theorem 3.\\\\\nNote that $X \\setminus \\{f(y):y<x\\} \\neq \\phi$, e.g. because $f(y) \\leq y$ $\\forall y$ (induction), so $x \\not\\in \\{f(y):y<x\\}$.\n\\end{proof}\n\\end{prop}\n\nIn particular, a well-ordered $X$ cannot be isomorphic to a proper initial segment of $X$ -- by uniqueness in subset collapse, as $X$ is isomorphic to $X$.\n\nHow do different well-orderings relate to each other?\n\nWe say $X \\leq Y$ if $X$ is isomorphic to an initial segment of $Y$. For example, $\\N \\leq \\{1-\\frac{1}{n}:n=2,3,...\\}\\cup\\{1\\}$.\n\n\\begin{thm} (5)\\\\\nLet $X,Y$ be well-orderings. Then $X\\leq Y$ or $Y \\leq X$.\n\\begin{proof}\nSuppose $Y \\not\\leq X$. To obtain $f:X \\to Y$ that is an isomorphism with an initial segment of $Y$, need $\\forall x \\in X: f(x) = \\min Y \\setminus \\{f(y):y<x\\}$. So we are done by theorem 3.\\\\\nNote that we cannot have $\\{f(y):y<x\\} = X$, as then $Y$ is isomorphic to $I_x$.\n\\end{proof}\n\\end{thm}\n\n\\begin{prop} (6)\\\\\nLet $X,Y$ be well-orderings with $X \\leq Y$ and $Y \\leq X$. Then $X$ and $Y$ are isomorphic.\n\\begin{proof}\nWe have isomorphism $f$ from $X$ to an isomorphism of $Y$, and $g$ the other way round. Then $g \\circ f: X \\to X$ is an isomorphism from $X$ to an initial segment of $X$ (i.s. of i.s. is i.s.), but that is impossible unless the initial segment is $X$ itself. So $g\\circ f$ is identity (by uniqueness in subset collapse). Similarly, $f \\circ g$ is identity on $Y$.\n\\end{proof}\n\\end{prop}\n\nNew well-orderings from old:\n\nWrite $X<Y$ if $X \\leq Y$ but $X$ not isomorphic to $Y$. Equivalently, $X < Y$ iff $X$ is isomorphic to a proper initial segment of $Y$. For example, if $X = \\N$, $Y = \\{1-\\frac{1}{n}\\} \\cup \\{1\\}$ then $X < Y$.\n\nMake a bigger one: given well-ordered $X$, choose $x \\not\\in X$, and set $x>y$ for all $y \\in X$. This is a well-ordering on $X \\cup \\{x\\}$: written $X^+$. Clearly $X < X^+$.\n\nPut some together:\\\\\nLet $(X,<_X)$ and $(Y,<_Y)$ be well-orderings. Say $Y$ extends $X$ if $X \\subset Y$, and $<_X$, $<_Y$ agree on $X$, and $X$ an initial segment of $(Y,<_Y)$.\\\\\nWell-orderings $(X_i: i \\in I)$ are nested if $\\forall i,j \\in I:$ $X_i$ extends $X_j$ or $X_j$ extends $X_i$.\n\n\\begin{prop} (7)\\\\\nLet $(X_i:i \\in I)$ be a nested family of well-orderings. Then there exist well-ordering $X$ with $X \\geq X_i$ $\\forall i$.\n\\begin{proof}\nLet $X = \\cup_{i \\in I} X_i$, with $x<y$ if $\\exists i$ with $x,y \\in X_i$ and $x <_i y$, Then $<$ is a well-defined total order on $X$. given $S \\subset X$, $S \\neq \\phi$, choose $i$ with $S\\cap X_i \\neq \\phi$. Then $S \\cap X_i$ has a minimal element (as $X_i$ is well-ordered), which must also be a minimal element of $S$ (as $X_i$ an i.s. of $X$). Also, $X \\geq X_i \\forall i$.\n\\end{proof}\n\\end{prop}\n\n\\newpage\n\n\\section{Ordinals}\n\nAre the well-orderings themselves well-ordered?\n\nAn ordinal is a well-ordered set, with two sell-ordered sets regarded as the same if they are isomorphic. (Just as a rational is an expression $\\frac{M}{N}$, with $\\frac{M}{N}$, $\\frac{M'}{N'}$ regarded as the same if $MN' = M'N$. But, unlike for $\\Q$, we cannot formalise by equivalence classes -- see later).\n\nIf $X$ is a well-ordering corresponding to ordinal $X$, say $X$ has order-type $\\alpha$.\n\n\\begin{eg}\nFor each $k \\in \\N$, write $k$ for the order-type of the (unique) well-ordering of a set of size $k$, and write $\\omega$ for order-type of $\\N$. So, in $\\R$, $\\{1,3,7\\}$ has order-type 3. $\\{1-\\frac{1}{n}:n=2,3,...\\}$ has order-type $\\omega$. For $X$ of o-t $\\alpha$ and $Y$ of o-t $\\beta$, write $\\alpha \\leq \\beta$ if $X \\leq Y$ (this is independent of choice of $X$,$Y$).\\\\\nSimilarly for $\\alpha<\\beta$ etc.\n\\end{eg}\n\nWe know: $\\forall \\alpha,\\beta$, $\\alpha\\leq \\beta$ or $\\beta\\leq\\alpha$, and if $\\alpha\\leq \\beta$, $\\beta\\leq\\alpha$ then $\\alpha=\\beta$.\n\n\\begin{thm}\nLet $\\alpha$ be an ordinal. Then the ordinals $<\\alpha$ form a well-ordered set of order-type $\\alpha$. e.g. the ordinals $<\\omega$ are $0,1,2,3,...$.\n\\begin{proof}\nLet $X$ have o-t $\\alpha$. the well-orderings $<X$ are precisely (up to isomorphism) the proper initial segments of $X$, i.e. the $I_{x},x \\in X$.\\\\\nBut these are isomorphic to $X$ itself, via $x \\to I_x$.\n\\end{proof}\n\\end{thm}\n\nWe often write $I_\\alpha$ to be the set of ordinals less than $\\alpha$.\n\n\\begin{prop} (9)\\\\\nLet $S$ be a non-empty set of ordinals. Then $S$ has a least element.\n\\begin{proof}\nChoose $\\alpha \\in S$. If $\\alpha$ minimal in $S$ then done. If not, then $S \\cap I_\\alpha \\neq \\phi$, so have a minimal element of $S\\cap I_\\alpha$, which is therefore minimal in $S$.\n\\end{proof}\n\\end{prop}\n\n\\begin{thm} (10, Burali-Forti paradox):\\\\\nThe ordinals do not form a set.\n\\begin{proof}\nSuppose not, let $X$ be set of all ordinals. Then $X$ is a well-orderings, say order-type $\\alpha$. So $X$ is isomorphic to $I_\\alpha$. But $I_\\alpha$ is a proper i.s. of $X$.\n\\end{proof}\n\\end{thm}\n\nGiven $\\alpha$, we have $\\alpha^+ > \\alpha$. Also, if $\\{\\alpha_i:i \\in I\\}$ is a set of ordinals, then there exists $\\alpha$ with $\\alpha \\geq \\alpha_i \\forall i$ (by applying prop 7 to the nested family of $I_{\\alpha_i};i \\in I$).\n\nIn fact, there is therefore a least upper bound for $\\{\\alpha_i: i \\in I\\}$ by applying prop 9 to the set $\\{\\beta \\leq \\alpha: \\beta$ an upper bound for the $\\alpha_i\\}$. This is written $\\sup\\{\\alpha_i:i \\in I\\}$, e.g. $\\sup\\{2,4,6,8,...\\} = \\omega$.\n\nSome ordinals: $0,1,2,...,\\omega,\\omega+1$(officially $\\omega^+$),$\\omega+2$,...,\\\\\n$\\omega+\\omega =\\omega2 = \\sup\\{\\omega+1,\\omega+2,...,\\}$, $\\omega^2+1,\\omega^2+2,...$,\\\\\n$\\omega3,...,\\omega4,...,...,\\omega\\omega = \\omega^2 = \\sup\\{\\omega,\\omega2,\\omega3,...\\}$,\\\\\n$\\omega^2+1,...,\\omega^2+\\omega,\\omega^2+\\omega+1,...\\omega^2+\\omega2,...,\\omega^2+\\omega^2=\\omega^2 2,...,\\omega^2 3,..., \\omega^2 4,..., \\omega^2 5,..., \\omega^2 \\omega = \\omega^3, ...\\omega^3 2,...,\\omega^4,...,\\omega^\\omega = \\sup\\{\\omega,\\omega^2,\\omega^3,...\\}$,\\\\\n$\\omega^\\omega+1,...,\\omega^\\omega 2,...,\\omega^\\omega \\omega = \\omega^{\\omega+1}$,\\\\\n$\\omega^{\\omega+2},...,\\omega^{\\omega+3},...,\\omega^{\\omega^2},...,\\omega^{\\omega^3},...,\\omega^{\\omega^\\omega}$,...\\\\\nAnd as expected we have $\\omega^{\\omega^{\\omega^{\\omega^{...}}}} = \\sup\\{\\omega,\\omega^2,\\omega^3,...\\} := \\varepsilon_0$, and then $\\varepsilon_0+1,...$, and then the whole thing again until $\\varepsilon_1 = \\varepsilon_0^{\\varepsilon_0^{...}}$.\n\nHowever, although this thing looks quite magnificent, they are all just countable (as we have just done it). Is there an uncoutnable ordinal? In other words, is there an uncountable well-ordered set?\n\n\\begin{thm} (11)\\\\\nThere is an uncountable ordinal.\n\\begin{proof}\n\\[IDEA: take sup of all countable ordinals. However, this might not be a set.\\]\\\\\nLet $R=\\{A \\in \\mathcal{P}(\\N \\times \\N)\\}$ s.t. $A$ is a well-ordering of a subset of $\\N$. Let $S$ be image of $R$ under 'order-type', i.e. $S$ is the set of all order-types of well-orderings of some subset of $\\N$. Then $S$ is the set of all countable ordinals. Let $\\omega_1$ be $\\sup S$. Then $\\omega_1$ is uncountable: otherwise, then $\\omega_1 \\in S$, so $\\omega_1$ would be the greatest member of $S$. But then $\\omega_1+1$ is also in $S$.\n\\end{proof}\n\\end{thm}\n\nNote that, by contradiction, $\\omega_1$ is the \\emph{least} uncountable ordinal. $\\omega_1$ has some strange properties, e.g.\\\\\n1. $\\omega_1$ is uncountable, but for any $\\alpha < \\omega_1$, we have $\\{\\beta:\\beta < \\alpha\\}$ countable.\\\\\n2. If $\\alpha_1,\\alpha_2,... < \\omega_1$ is any sequence, then it is bounded in $\\omega_1$: $\\sup\\{\\alpha_1,...,\\alpha_2\\}$ is countable, so is less than $\\omega_1$.\n\nSimilarly we have\n\n\\begin{thm} (11', Hartogs' lemma)\\\\\nFor any set $X$, there is an ordinal that  does not inject into $X$.\\\\\nTo see that, just replace $\\mathcal{P}(\\N\\times\\N)$ by $\\mathcal{P}(X \\times X)$ in the previous proof.\\\\\n\\end{thm}\n\nWrite $\\gamma(X)$ for the least such ordinal -- e.g. $\\gamma(\\omega) = \\omega_1$.\n\n\\newpage\n\n\\subsection{Successors and limits}\nGiven ordinal $\\alpha$, does $\\alpha$ (any set of order-type $\\alpha$, e.g. $I_\\alpha$) have a greatest element?\\\\\nIf yes: say $\\beta$ is that greatest element. Then $\\gamma<\\beta$ or $\\gamma =\\beta$ $\\implies$ $\\gamma<\\alpha$, and $\\gamma<\\alpha \\implies \\gamma < \\beta$ or $\\gamma = \\beta$ (as we can't have $\\gamma > \\beta$). In other words, $\\alpha = \\beta^+$. In that case, we call $\\alpha$ a \\emph{successor};\\\\\nIf not: then $\\forall \\beta < \\alpha$, $\\exists \\gamma < \\alpha$ s.t. $\\gamma > \\beta$. So $\\alpha = \\sup\\{\\beta:\\beta < \\alpha\\}$. (this is false in general, e.g. $\\omega+5$). We call $\\alpha$ a \\emph{limit}.\n\nFor example, $5$ is a successor, $\\omega+5$ is a successor, $\\omega$ is a limit, $\\omega+\\omega$ is a limit. ($0$ is a limit as well).\n\nFor ordinals $\\alpha,\\beta$, define $\\alpha+\\beta$ by recursion on $\\beta$ ($\\alpha$ fixed) by: $\\alpha+0=\\alpha$, $\\alpha+\\beta^+ = (\\alpha+\\beta)^+$, $\\alpha+\\lambda = \\sup \\{\\alpha+\\gamma: \\gamma < \\lambda\\}$ for $\\lambda$ a non-zero limit.\n\nFor example, $\\omega+1 = (\\omega+0)^+ = \\omega^+$, $\\omega+2 = \\omega^{++}$, $1+\\omega = \\sup \\{1+\\gamma:\\gamma < \\omega\\} =\\omega$ -- so addition is not commutative.\n\nOfficially, by 'recursion on the ordinals', we mean: define $\\alpha+\\gamma$ on $\\{\\gamma:\\gamma \\leq \\beta\\}$ (a set) recursively, plus uniqueness. Similarly for induction: if know $p(\\beta) \\forall \\beta < \\alpha \\implies p(\\alpha)$ (for each $\\alpha$), then must have $p(\\alpha) \\forall \\alpha$. If not, say $p(\\alpha)$ false: then look at $\\{\\beta \\leq \\alpha : p(\\beta)$ false $\\}$.\n\nNote that $\\beta \\leq \\gamma \\implies \\alpha + \\beta \\leq \\alpha +\\gamma$ (induction on $\\gamma$). Also, $\\beta <\\gamma \\implies \\alpha+\\beta<\\alpha+\\gamma$. Indeed, $\\gamma \\geq \\beta^+$, so $\\alpha+\\gamma\\geq \\alpha+\\beta^+ = (\\alpha+\\beta)^+ > \\alpha+\\beta$. However, $1<2$, but $1+\\omega = 2+\\omega$.\n\n\\begin{prop} (12)\\\\\n$\\alpha+(\\beta+\\gamma) = (\\alpha+\\beta)+\\gamma \\forall \\alpha,\\beta,\\gamma$ ordinals.\n\\begin{proof}\nInduction on $\\gamma$:\\\\\n$0$: $\\alpha+(\\beta+0) = \\alpha+\\beta = (\\alpha+\\beta)+0$.\\\\\nSuccessors: $(\\alpha+\\beta)+\\gamma^+ = ((\\alpha+\\beta)+\\gamma)^+ = (\\alpha+(\\beta+\\gamma))^+ = \\alpha+(\\beta+\\gamma)^+ = \\alpha+(\\beta+\\gamma^+)$.\\\\\n$\\lambda$ a non-zero limit: $(\\alpha+\\beta)+\\lambda = \\sup\\{(\\alpha+\\beta)+\\gamma: \\gamma<\\lambda\\} = \\sup\\{\\alpha+(\\beta+\\gamma):\\gamma<\\lambda\\}$.\n\nClaim: $\\beta+\\lambda$ is a limit.\\\\\nProof of claim: We have $\\beta + \\gamma = \\sup\\{\\beta+\\gamma:\\gamma<\\lambda\\}$. But $\\gamma<\\lambda \\implies \\exists \\gamma' <\\lambda$ with $\\gamma <\\gamma'$ $\\implies $ $\\beta+\\gamma < \\beta+\\gamma'$. So $\\{\\beta+\\gamma : \\gamma<\\lambda\\}$ does not have a greatest element.\n\nBack to the main proof, now $\\alpha+(\\beta+\\gamma) = \\sup\\{\\alpha+\\delta:\\delta<\\beta+\\lambda\\}$. So want $\\sup\\{\\alpha+(\\beta+\\gamma):\\gamma<\\lambda\\{ = \\sup\\{\\alpha+\\delta:\\delta <\\beta+\\lambda\\}$. \\\\\n$\\leq$: $\\gamma < \\lambda \\implies \\beta+\\gamma<\\beta+\\lambda$, so LHS $\\subset$ RHS;\\\\\n$\\geq$: $\\delta < \\beta+\\lambda \\implies \\delta<\\beta+\\gamma$, some $\\gamma<\\lambda$ (definition of $\\beta+\\lambda$). So $\\alpha+\\delta \\leq \\alpha+(\\beta+\\gamma)$.\n\\end{proof}\n\\end{prop}\n\nAlternative viewpoint:\\\\\nAbove is the 'inductive' definition of $+$. Thereis also a synthetic definition: $\\alpha+\\beta$ is the order-type of $\\alpha \\sqcup \\beta$ ($\\alpha$ disjoint union $\\beta$), with all of $\\alpha$ coming before all of $\\beta$.\n\nClearly we have $\\alpha+(\\beta+\\gamma) = (\\alpha+\\beta)+\\gamma$ with this definition (same order-type). We need:\n\n\\begin{prop} (13)\\\\\nThe synthetic and inductive definition of $+$ coincide.\n\\begin{proof}\nWrite $\\alpha+\\beta$ for inductive, $\\alpha +' \\beta$ for synthetic. Do induction on $\\beta$ ($\\alpha$ fixed).\\\\\n$0$: $\\alpha+0=\\alpha=\\alpha+'0$:\\\\\nSuccessors: $\\alpha+'\\beta^+ = (\\alpha+'\\beta)^+ = (\\alpha+\\beta)^+=\\alpha+\\beta^+$;\\\\\n$\\lambda$ a non-zero limit: $\\alpha+'\\gamma$ = order-type of $\\alpha \\sqcup \\lambda$ = $\\sup$ of order-type of $\\alpha\\sqcup \\gamma$, $\\gamma <\\lambda$ (nest union, so order-type of union = $\\sup$ -- this was proved before) = $\\sup(\\alpha+'\\gamma:\\gamma<\\lambda) = \\sup(\\alpha+\\gamma:\\gamma<\\lambda) = \\alpha+\\lambda$.\n\\end{proof}\n\\end{prop}\n\nNormally we prefer to use synthetic than inductive, \\emph{if} we do have a synthetic definition available.\n\nOrdinal multiplication:\\\\\nDefine $\\alpha \\beta$ recursively by:\\\\\n$\\alpha 0 = 0$, $\\alpha(\\beta^+) = \\alpha\\beta + \\alpha$, $\\alpha\\lambda = \\sup\\{\\alpha\\gamma:\\gamma <\\lambda \\}$ for $\\lambda$ a non-zero limit. e.g:\\\\\n$\\omega 1 = \\omega 0 + \\omega = 0 + \\omega = \\omega$;\\\\\n$\\omega 2 = \\omega 1 + \\omega = \\omega+\\omega$;\\\\\n$\\omega\\omega = \\sup\\{0,\\omega,\\omega+\\omega,\\omega+\\omega+\\omega,...\\}$ (as in our big picture)\\\\\n$2\\omega = \\sup\\{2 \\gamma:\\gamma < \\omega\\} = \\omega$, so multiplication is not commutative.\n\nSimilarly, this also has a synthetic definition: $\\alpha\\beta$ is the order-type of $\\alpha\\times\\beta$, with $(x,y) < (z,t)$ if either $y<t$ or $y=t$ and $x<z$. We can check that these coincide on the previous examples. Also we can see $\\alpha(\\beta\\gamma) = (\\alpha\\beta)\\gamma$ etc.\n\nWe can define ordinal exponentiation, powers, etc. Similarly. For example, let's define exponentiation:\\\\\n$\\alpha^0 = 1$, $\\alpha^{\\beta^+} = \\alpha^\\beta \\cdot \\alpha$, $\\alpha^\\lambda = \\sup\\{\\alpha^\\gamma:\\gamma<\\lambda\\}$ for $\\lambda$ a non-zero limit.\n\nNote that $\\omega^1 = \\omega$, $\\omega^2 = \\omega \\cdot \\omega$, and $2^\\omega = \\sup\\{2^\\gamma: \\gamma<\\omega\\} = \\omega$ (and is countable). This is different to what we expect from cardinality, but the notation in cardinality and here is different.\n\n\\newpage\n\n\\section{Posets and Zorn's lemma}\nA \\emph{Partially ordered} set or {poset} is a pair $(X,\\leq)$ where $X$ is a set and $\\leq$ is a relation on $X$ that is reflexive,transitive and antisymmetric. Write $x<y$ if $x\\leq y ,x \\neq y$. In terms of $<$, a poset is irreflexive and transitive.\n\nFor example, any total order is a partial order; $\\N^+$ with divides; for any set $S$, $\\mathcal{P}(S)$, wiith $x \\leq y$ if $x \\subset y$; for any $X \\subset \\mathcal{P}(S)$, with same relation of $x \\leq y$ if $x \\subset y$ (e.g. all subspaces of a given vector space).\n\nIn general, a hasse diagram for a poset $X$ consists of a drawing of the posets of $X$, with an upward line from $x$ to $y$ if $y$ \\emph{covers} x, i.e. $y>x$, but no $z$ that $y>z>x$.\n\nHasse diagrams can be useful to visualize a poset (e.g. $\\N$, usual order), or useless (e.g. $\\Q$, usual order).\n\nIn a poset $X$, a \\emph{chain} is a set $S \\subset X$ that is totally ordered ($\\forall x,y\\in S: x \\leq y$ or $y \\leq x$). \n\nNote: chains can be uncountable, e.g. in $(\\R,\\leq)$ take $\\R$.\n\nWe say $S \\subset X$ is an antichain if no two elmeent are related.\n\nFor $S \\subset X$, an \\emph{upper bound} for $S$ is an $x \\in X$ s.t. $x \\geq y$ $\\forall y \\in S$.\n\nSay $X$ is a \\emph{least upper bound}, or \\emph{supremum} for $S$, if $x$ is an upper bound for $S$, and $x \\leq y$ for every upper bound $y$ of $S$.\n\nWrite $x = \\sup S$ or $x = \\vee S$.\n\ne.g. In $\\R$, $\\{x:x^2<2\\}$ has 7 as least upper bound, and $\\sup = \\sqrt{2}$ (so $\\sup S$ need not be in $S$). In $\\R$, $\\Z$ has no upper bound. In $\\Q$, $\\{x:x^2 < 2\\}$ has 7 as an upper bound, but no least upper bound.\n\nWe say a poset is \\emph{complete} if every subset has a sup.\n\ne.g. $(\\R,\\leq)$ is not complete: $\\Z$ has no sup (so different to notion of 'completeness' from analysis);\\\\\n$[0,1]$ is complete; $(0,1)$ is not complete: itself has no sup;\\\\\n$\\P(S)$ is always complete: $\\{A_i: i \\in I\\}$ has sup $\\cup_{i \\in I} A_i$.\n\nA function $f:X \\to X$, where $X$ is any poset, is order-preserving if $f(x) \\leq f(y)$ $\\forall x \\leq y$.\n\ne.g. on $\\N$ : $f(x) = x+1$; on $[0,1]: f(x) = \\frac{1+x}{2}$ (halve the distance to 1); on $\\P(S)$: $f(A) = A \\cup \\{i\\}$ for some fixed $i \\in S$.\n\nnot every order-preserving $f$ has a fixed point ($f(x) = x$), e.g. $f(x) = x+1$ on $\\N$.\n\n\\begin{thm} (1, Knaster-Tarski fixed point theorem):\\\\\nLet $X$ be a complete poset. Then every order-preserving function $f:X \\to X$ has a fixed point.\n\\begin{proof}\nLet $E = \\{x \\in X: x \\leq f(x)\\}$, and put $s = \\sup E$. To show $f(s) = s$, we'll show that $s \\leq f(s)$ and $s \\geq f(s)$.\\\\\n$s \\leq f(S)$: Enough to show $f(s)$ is an upper bound for $E$ (as $s$ the \\emph{least} upper bound). But $x \\in E$ $\\implies x \\leq s$ $\\implies f(x) \\leq f(s) \\implies x \\leq f(x) \\leq f(s)$.\\\\\n$s \\geq f(s)$: Enough to show $f(s) \\in E$ (as $s$ an upper bound). We know $s \\leq f(s)$, and want $f(s) \\leq f(f(s))$. But that's true because $f$ is order preserving.\n\\end{proof}\n\\end{thm}\n\nNote: in any complete poset $X$, we have a greatest element ($x s.t. x \\geq y \\forall y$), namely $\\sup X$. A typical application of knaster-tarski:\n\n\\begin{thm} (2, schr$\\ddot{o}$der-bernstein theorem)\\\\\nLet $a,B$ be sets s.t. there exists injection $f:A \\to B$ and an injection $g:B \\to A$. Then there exists an bijection from $A$ to $B$.\n\\begin{proof}\nSeek partition $A = P \\sqcup Q,B = R \\sqcup S$ s.t. $f(P) = R$ and $g(S) = Q$. Then we are done: set $h$ to be $f$ on $P$, $y^{-1}$ on $Q$, then $h:A \\to B$ is a bijection.\\\\\ni.e. we seek $P \\subset A$ s.t. $A \\setminus g(B\\setminus f(P)) = P$. Define $\\theta: \\mathcal{P}(A) \\to \\mathcal{P}(A)$ via $P \\to A \\setminus g(B\\setminus f(P))$. Then since $\\mathcal{P}(A)$ is complete, $\\theta$ order-preserving, there is a fixed point by K-T theorem.\n\\end{proof}\n\\end{thm}\n\n\\subsection{Zorn's Lemma}\nAn element $x$ in poset $X$ is \\emph{Maximal} if no $y \\in X$ has $y >x$.\n\nPosets need not have a maximal element, for example $\\Z,\\Q,\\R$.\n\n\\begin{thm} (3, Zorn's lemma)\\\\\nLet $X$ be a non-empty poset in which every chain has an u.b.. Then $X$ has a maximal element.\n\\begin{proof}\nSuppose not. Then for each $x \\in X$ there is some $x' \\in X$ with $x' > x$. Also, for any chain $C$ we have an upper bound $u(C)$. Pick $x \\in X$. Define $x_\\alpha \\in X$, each $\\alpha < \\gamma(x)$ ($\\gamma(x)$ is the u.b.?) recursively by: $x_0 = x$, $x_{\\alpha+1} = x'_\\alpha$, $x_\\lambda = u(\\{x_\\alpha: \\alpha < \\lambda\\})$ for $\\lambda$ a non-zero limit (this is a chain by induction). Then $\\alpha \\to x_\\alpha$ is an injection from $\\gamma(X) to X$.\n\\end{proof}\n\\end{thm}\n\nA typical application of Zorn: does every vecotr space have a basis? Recall that a basis is a LI spanning set.\n\ne.g. $V=$ space of all real polynomials. We can take $1,x,x^2,...$\\\\\nLet $V$ now be all real sequences. But $l_1 = (1,0,0,0,...)$, $l_2 = (0,1,0,0,...)$, then $l_1,l_2$ LI but not spanning! (recall span must be a finite linear combination!) It's easy to check that there is no countable basis. Also, it turns out that there is no \\emph{explicit} basis.\\\\\n$\\R$ as a vector space over $\\Q$. Basis is called a Hamel basis.\n\n\\begin{thm} (4)\nEvery vector space $V$ has a basis.\n\\begin{proof}\nLet $X = \\{A\\subset V: A$ is LI$\\}$, ordered by $\\subset$. We seek a maximal element $M$ of $X$ (then we are done: if $M$ does not span then choose $x \\not\\in \\bra M\\ket$, and now $M \\cup \\{x\\}$ is LI, contradiction.\\\\\nWe have $X\\neq\\phi$, as $\\phi \\in X$.\\\\\nGiven a chain $\\{A_i: i \\in I\\}$ in $X$, put $A = \\cup_{i \\in I} A_i$, then $A > A_i$ $\\forall i$, so just need $A \\in X$, i.e. $A$ LI. Suppose $A$ is not LI, hten $\\sum_{i=1}^n \\lambda_i x_i = 0$ for some $x_1,...,x_n \\in A$, and $\\lambda_i$ scalars not all zero. We have $x_i \\in A_{i_1},...,x_n \\in A_{i_n}$ for some $i_1,...,i_n \\in I$. But $A_{i_1},...,A_{i_n} \\in A_{i_k}$, some $k$ (as they are nested), contradicting $A_{i_k}$ being LI.\n\\end{proof}\n\\end{thm}\n\nNote: the only actualy maths (i.e. linear alebra) in the proof was the 'then done' part.\n\nAnother application: completeness theorem when proposition language uncountable.\n\n\\begin{thm} (5)\\\\\nLet $S \\subset L(P)$, where $P$ is any set. Then $S$ consistent implies that $S$ has a model.\n\\begin{proof}\nWe seek a maximal consistent $\\bar{S} \\supset S$. Then done: for each $t \\in L(p)$ we have $\\bar{S} \\cup \\{t\\}$ or $\\bar{S} \\cup \\{\\neg t\\}$ consistent (see chapter 1), hence $t \\in \\bar{S}$ or $\\neg t \\in \\bar{S}$ by maximality of $\\bar{S}$.  Now define $v(t) = 1$ if $t \\in \\bar{S}$, $0$ otherwise (as in chapter 1). Let $X$ be the set of all consistent subsets of $L(P)$, ordered by $\\subset$. Then $X \\neq \\phi$, as $S \\in X$. Given a non-empty chain $(T_i:i \\in I)$ in $X$, put $T = \\cup_{i \\in I} T_i$. Then $T \\supset T_i$ for each $i$, so we just need $T \\in X$. We have $S \\subset T$ as $T \\neq \\phi$. Also $T$ is consistent: if $T \\vdash \\perp$, then $\\{t_1,...,t_n\\} \\vdash \\perp$ for some $t_1,...,t_n \\in T$. We have $t_1 \\in T_{i_1},...,t_n \\in T_{i_n}$ for some $i_1,...,i_n \\in I$. But $T_{i_1},...,T_{i_n} \\subset T_{i_k}$ for some $k$ (nested), contradicting $T_{i_k}$ being consistent.\n\\end{proof}\n\\end{thm}\n\nOne more:\n\n\\begin{thm} (6, well-ordering principle)\\\\\nEvery set $S$ can be well-ordered.\\\\\nNote that this is very surprising for e.g $S=\\R$.\n\\begin{proof}\nLet $X = \\{(A,R):A \\subset S$ and $R$ is a well-ordering of $A\\}$. We order this by: $(A,R) \\leq (A',R')$ if $(A',R')$ extends $(A,R)$. Then $X \\neq \\phi$, as $(\\phi,\\phi) \\in X$. Given a chain $((A_i,R_i) : i \\in I)$, we have $(\\cup_{i \\in I} A_i, \\cup_{i \\in I} R_i) \\in X$, and extends each $(A_i,R_i)$ from chapter 2. So by Zorn's lemma, $X$ has a maximal element $(A,R)$. We must have $A = S$: otherwise choose $x \\in S\\setminus A$ and take 'successor': well-order $A\\cup\\{x\\}$ by putting $x > a$ $\\forall a \\in A$, contradicting maximality of $(A,R)$.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\nProof of zorn was easy, but we used a lot of machinery there (ordinals, recursion, hartog's lemma).\n\\end{rem}\n\n\\subsection{Zorn's lemma and the axiom of choice}\nIn proof of Zorn's kemma, we chose, for each $x \\in X$, and $x' \\supset x$, i.e. we made infinitely many arbitrary choices, even by time we get to $x_\\omega$. We did the same in part IA, to prove that a countable union of countable sets is countable. This is appealing to the axiom of choice, saying that we may choose an element of each set in a family of non-empty sets.\n\nMore precisely, the axiom of choice states that, if $(A_i : i \\in I)$ is a family of sets, we have a choice function, meaning a function $f:I \\to \\cup_{i \\in I} A_i$ s.t. $f(i) \\in A_i$ $\\forall i$. This is of a different characterto the other set-building rules in that the object whose existence is asserted is not uniquely specified by its properties (unlike ,e.g., $A \\cup B$).\\\\\nSo often one points out when one has used axiom of choice.\n\nNote that AC is trivial $|I| = 1$ ($A \\neq \\phi$ means $\\exists x \\in A$). Similarly for $I$ finite by induction. However, there is no derivation of AC from the other set-building rules for general $I$.\n\nAlso, we cannot prove ZL without AC because we can deduce AC from ZL:\\\\\nGiven family $(A_i:i \\in I)$ of non-empty sets, a partial choice function is an $f:J \\to \\cup_{i \\in I} A_i$ for some $J \\subset I$, s.t. $f(j) \\in A_j \\forall j \\in J$. Put $(J,f) \\leq (J',f')$ if $J \\subset J'$ and $f'|J = f$. This poset is not empty. Also, given a chain we have an upper bound being the union of them. So by ZL, there is a maximal of such. We must have $J=I$ in that case, as if not we can choose (???) $i \\in I \\setminus J$, $x \\in A_i$ and put $J' = J \\cup \\{i\\}$, $f' = f \\cup \\{(i,x)\\}$. Contradiction.\n\nConclusion: ZL $\\iff$ AC (in presence of the other set-building rules).\n\nAlso, we had $ZL \\implies WO$, and $WO \\implies AC$ trivially (well order $\\cup i \\in I A_i$ and let $f(i)$ be the least element of $A_i$). So we get $ZL \\iff AC \\iff WO$.\n\n\\subsection{The Bourbaki-Witt theorem}\nPoset $X$ is \\emph{chain-complete} if $X \\neq \\phi$ and every non-empty chain has a sup.\\\\\nFor example, any complete poset is chain-complete; any finite poset is chain-complete; and $\\{A \\subset V: A$ is LI$\\}$, for a vector space $V$ is also.\n\nWe say $f:X \\to X$ is \\emph{inflationary} if $f(x) \\geq x$ $\\forall x$.\n\n\\begin{thm} (Bourbaki-Witt)\\\\\n$X$ chain-complete, $f:X \\to X$ inflationary. Then $f$ has a fixed point.\\\\\nNote that BW follows instantly from ZL: take maximal $x$, and now $f(x) \\geq x$ $\\implies f(x) = x$.\\\\\nHowever, we can prove BW without AC: we pick some $x_0 \\in X$, then let $x_1 = f(x_0)$, $x_2 = f(x_1)$, ..., and let $x_\\omega$ be the sup of them.\n\nIn chapter 2, we did not use AC, except in remark that well-ordering $\\iff$ no decreasing sequence, and that $\\omega_1$ is not a countable sup.\n\\end{thm}\n\nIn fact, it's easy to deduce ZL from BW (using AC). So we can view BW as the choice-free version of ZL.\n\n\\newpage\n\\section{Predicate Logic}\nRecall that a group is a set equipped with functions:\\\\\n$M:A^2 \\to A$ ('arity' (slots) 2) and inverse $iA \\to A$ ('arity' 1), and a constant $e \\in A$ (kind of 'arity' 0), s.t.\n\\begin{equation*}\n\\begin{aligned}\n& (\\forall x,y,z \\in A) (M(x,M(y,z)) = M(M(x,y),z)),\\\\\n(\\forall x \\in A) (M(x,e) = x \\wedge M(e,x) = x),\\\\\n(\\forall x \\in A) (M(x,i(x)) = e \\wedge M(i(x),x) = e)\n\\end{aligned}\n\\end{equation*}\n\nAnd a poset is a set $A$ equipped with a predicate (relation) $\\leq$ (arity 2) $\\subset A^2$ s.t\\\\\n\\begin{equation*}\n\\begin{aligned}\n(\\forall x \\in A) (x \\leq x),\\\\\n(\\forall x,y,z \\in A) ((x \\leq y) \\wedge (y \\leq z) \\implies x \\leq z),\\\\\n(\\forall x,y \\in A) ((x \\leq y \\wedge y \\leq x) \\implies x = y)\n\\end{aligned}\n\\end{equation*}\n\nWe try to establish these correspondence between propositional logic and predicate logic:\nLanguage $\\to$ e.g. language of groups (thinks like the definitions above);\\\\\nValuation $\\to$ structure (set equipped with functions and relations of given arities);\\\\\nModel of $S$ (valuation making each $s \\in S$ true) $\\to$ model of $S$ (structure in which each $s \\in S$ holds);\\\\\n$S \\vDash t$ $\\to $ same (e.g. In language of groups, should have the above 3 definitions $\\vDash M(e,e) = e$ etc);\\\\\n$S \\vdash t$ $\\to $ same (but a bit more complicated).\n\nLet $\\Omega$ (function symbols) and $\\Pi$(relation symbols) be disjoint sets, and $\\alpha$ (arity) : $\\Omega \\cup \\Pi \\to \\N$. The \\emph{language} $L=L(\\Omega,\\Pi,\\alpha)$ is the set of \\emph{formulae}, defined by:\\\\\n$\\bullet$ variables: $x_1,x_2,x_3,...$ (can use $x,y$, etc);\\\\\n$\\bullet$ terms: defined inductively by:\\\\\n(i) each variable is a term;\\\\\n(ii) If $f \\in \\Omega$, $\\alpha(f) = n$, and $t_1,...,t_n$ are terms, then $ft_1...t_n$ is a term (and as always, we can add brackets, commas, etc).\nFor example, in the language of groups: $\\Omega = \\{m,i,e\\}$ of arities $2,1,0$, $\\Pi = \\phi$. Some terms: $x_1,m(x_1,x_2),e,m(e,e),m(x_1,i(x_1))$, etc.\\\\\n$\\bullet$ Atomic formulae, consists of:\\\\\n(i) $\\perp$;\\\\\n(ii) $(s=t)$, any terms $s,t$;\\\\\n(iii) $\\phi(t_1,...,t_n)$, any $\\phi \\in \\Pi$, $\\alpha(\\phi) = n$, and terms $t_1,...,t_n$.\\\\\nAgain use the language of groups as example: $m(x,y) = m(y,x)$, $m(x,i(x)) = e$;\\\\\nIn language of posets: $\\Omega = \\phi$, $\\Pi = \\{\\leq\\}$ of arity 2. We could take $x=y,x\\leq y,x \\leq x$.\\\\\n$\\bullet$ Formulae: defined inductively by:\\\\\n(i) Each atomic formula is a formula;\\\\\n(ii) If $p,q$ are formulae, then so is $(p \\implies q)$;\\\\\n(iii) If $p$ is a formulae, $x$ is a variable, then $(\\forall x) p$ is a formula.\\\\\ne.g. in language of groupsL $(\\forall x)(m(x,x) = e)$, $(\\forall x)((m(x,x) = e) \\implies (\\exists y)(m(y,y) = x))$ (note that we have not talked about $\\exists$ yet; we'll do that later).\\\\\nIn language of posets: $(\\forall x)(x \\leq x)$.\\\\\n\nNotes:\\\\\n1. A formula is just a string of symbols.\\\\\n2. We can now write $\\neg p$ for $p \\implies \\perp$, and similarly for $p \\wedge q$, $p \\vee q$ etc, and $(\\exists x) p$ for $\\neg(\\forall x)(\\neg p)$.\n\nA term is \\emph{closed} if it contains no variables. For example, $e,m(e,e),m(e,m(e,e))$. However, $m(x,i(x))$ is \\emph{not} closed.\\\\\nAn occurrence of variable $x$ in formular $p$ is \\emph{bound} if it is inside the brackets of '$\\forall x$' quantifier. Otherwise, it is \\emph{free}.\\\\\nFor example, in $m(x,x) = e \\implies (\\exists y) (m(y,y) = x)$, each $x$ is free and each $y$ is bound.\\\\\nNote that in some cases we can make a variable both free and bound: $(m(x,x) = e) \\implies (\\forall x)(\\forall y) (m(x,y) = m(y,x))$. We see that $x$ in LHS is free, but in RHS is bound (although it's not a very helpful expression).\n\nA \\emph{sentence} is a formula without free variables: e.g., $(\\forall x) (m(x,e) = x)$. For formula $p$, variable $x$, term $t$, the \\emph{substitution} $p[t/x]$ is obtained by replacing each free occurence of $x$ with $t$.\\\\\nFor example, if $p$ is $(\\exists y) (m(y,y) = x)$, then $p[e/x]$ is $(\\exists y) (m(y,y) = e)$.\n\n\\emph{Semantic entailment}:\nAn \\emph{$L$-structure} consists of a non-empty (see later wfor why) set $A$ equipped with, for each $f \\in \\Omega$ with $\\alpha(f) = m$, a function $f_A:A^m \\to A$, and for each $\\phi \\in \\Pi$, with $\\alpha(\\phi) = n$, a relation $\\phi_A \\subset A^n$.\n\nFor example, let $L$ be the language of groups: an $L$-structure is a set $A$ with functions $m_A:A^2 \\to A$, $i_A: A \\to A$, $e_A$ an element of $A$ (need not be a group! These have no 'meaning' yet).\\\\\nAnother example: $L$ be the language of posets: an $L$-structure is a set $A$ with a relation $\\leq_A \\subset A^2$.\n\nWe want to define the \\emph{interpretation} $p_A \\in \\{0,1\\}$ of a sentence $p$ in structure $A$, e.g. $(\\forall x)(m(x,x) = e)$ shold be 'true in $A$' if $\\forall a \\in A: m_A(a,a) = e_A$.\\\\\nSo: 'insert $\\in A$ subsubscript $A$ and say it aloud'.\n\n\\emph{Formal bit}:\nFor $L$-structure $A$, define \\emph{interpretation} of a closed term $t$ to be $t_A \\in A$, defined inductively by:\\\\\n$(ft_1...t_n)_A = f_A({t_1}_A,...,{t_n}_A)$ for any $f \\in \\Omega$, $\\alpha(f) = n$, closed terms $t_1,...,t_n$.\\\\\ne.g. $m(e,i(e))_A =m_A (e_A, i_A (e_A))$ (and $e_A$ already defined).\\\\\n\nAtomic formulae: define $p_A \\in \\{9,1\\}$ for $p$ atomic by:\\\\\n(i) $\\perp_A = 0$;\\\\\n(ii) \n\\begin{equation*}\n\\begin{aligned}\n(s=t)_A = \\left\\{\\begin{array}{ll}\n1 & s_A = t_A\\\\\n0 & else\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nfor $s,t$ closed terms;\\\\\n(iii) \n\\begin{equation*}\n\\begin{aligned}\n\\phi(t_1...t_n)_A = \\left\\{\\begin{array}{ll}\n1 & ({t_1}_A,...,{t_n}_A) \\in \\phi_A\\\\\n0 & else\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nfor $\\phi \\in \\Pi$, $\\alpha(\\phi) = n$, closed terms $t_1,...,t_n$.\n\nSentences: $p_A$ defined inductively by:\\\\\n(i)\n\\begin{equation*}\n\\begin{aligned}\n(p \\implies q)_A =\\left\\{\\begin{array}{ll}\n0 & p_A=1,q_A=0\\\\\n1 & else\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\n(ii)\n\\begin{equation*}\n\\begin{aligned}\n((\\forall i)_p)_A =\\left\\{\\begin{array}{ll}\n1 & p[\\bar{a}/x]_A = 1 \\text{ for all } a \\in A\\\\\n0 & else\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nwhere, for any $a \\in A$, add constant symbol $\\bar{a}$ to $L$, obtaining $L'$, and make $A$ an $L'$-structure by setting $\\bar{a}_A = a$.\n\nIf $p$ has free variables, we can define $p_A \\subset A^{\\text{number of free variables of } p}$.\\\\\ne.g. if $p$ is $(\\exists y)(m(y,y) = x)$, then $p_A = \\{a \\in A: \\exists b \\in A$ with $m_A(b,b) = a\\}$.\n\nIf $p_A = 1$, say $p$ \\emph{true} in $A$, or $p$ holds in $A$, or $A$ is a \\emph{model} of $p$. For $T$ a theoy (set of sentences), say $T$ semantically entails $p$, written $T \\vDash p$, if every model of $T$ is a model of $p$.\n\n$p$ is a \\emph{tautology} if $\\phi \\vDash p$ (or just $\\vDash p$), i.e. $p$ holds in every $L$-structure. For example, $\\vDash (\\forall x)(x=x)$.\n\nExamples: theory of groups: $\\Omega = (m,i,e)$, $\\Pi = \\phi$. Let\n\\begin{equation*}\n\\begin{aligned}\nT = \\{(\\forall x)(\\forall y)(\\forall z)(m(x,m(y,z)) = m(m(x,y),z),(\\forall x)(m(x,e) = x \\wedge m(e,x) = x),(\\forall x)(m(x,i(x)) = e \\wedge m(i(x),x) = e)\\}\n\\end{aligned}\n\\end{equation*}\nThen an $L$-structure is a model of $T$ $\\iff$ it is a group.\n\nSay $T$ 'axiomatises' the class of groups or 'axiomatises the theory of groups'.\n\nSometimes call the elements of $T$ the 'axioms' of $T$.\n\nTheory of fields: $\\Omega = \\{+,\\times,-,0,1\\}$. $T$ is: abelian group under $(+,-,0)$; $X$ is commutative, associative, distributive under $+$; $(\\forall x)(1x=x)$, $\\neg(1=0)$, $(\\forall x)((\\neg(x=0)) \\implies (\\exists y) (xy = 1))$. Then $T$ axiomatises the class of fields. E.g., $T\\vDash$ inverses are unique: $(\\forall x) ((\\neg(x \\neq 0)) \\implies ((\\forall y)(\\forall x)((yx = 1 \\wedge zx=1) \\implies y=z))$.\n\nTheory of posets: $\\Omega = \\phi, \\Pi = \\{\\leq\\}$.\n\n$T$ is: $(\\forall x)(x \\leq x)$, $(\\forall x)(\\forall y)(\\forall z)((x \\leq y \\wedge y \\leq z) \\implies x \\leq z)$, $(\\forall x)(\\forall y)((x \\leq y \\wedge y \\leq x) \\implies x=y)$.\n\nTheory of graphs: $\\Omega = \\phi$, $\\Pi =\\{a\\}$ ('is adjacent to').\n\n$T$ is $(\\forall x)(\\neg a(x,x))$, $(\\forall x)(\\forall y)(a(x,y) \\implies a(y,x))$.\n\nProofs:\n\nLogical axioms:\\\\\n(1) $p \\implies (q \\implies p)$ (any formulae $p,q$);\\\\\n(2) $p \\implies (q \\implies r)) \\implies ((p \\implies q) \\implies (p \\implies r))$ (any formulae $p,q,r$);\\\\\n(3) $(\\neg\\neg p) \\implies p$ (any formula $p$);\\\\\n(4) $(\\forall x) (x=x)$; (any variable $x$);\\\\\n(5) $(\\forall x)(\\forall y)(x=y) \\implies (p\\implies p[y/x]))$ (any variables $x,y$, formula $p$ where $y$ is a bound);\\\\\n(6) $((\\forall x) p) \\implies p [t/x]$ (any variable $x$, term $t$, formula $p$ with no variable in $t$ occuring bound in $p$)\\\\\n(7) $((\\forall x)(p \\implies q)) \\implies (p \\implies (\\forall x) q)$ (any variable $x$, formulae $p,q$ with $x$ not occurring free in $p$).\n\nAs rules of deduction, we take:\\\\\n\\emph{Modus Ponens}: From $p,p \\implies q$ can deduce $q$;\\\\\n\\emph{Generalisation}: From $p$ can deduce $(\\forall x)p$, if $x$ does not occur free in any premise used to prove $p$.\n\nFor $S \\subset L$, $p \\in L$, a proof of $p$ from $S$ is a finite sequence of formulae, ending with $p$, s.t. each line is a logical axiom, or a member of $S$, or follows from earlier lines by MP or GEN. Write $S\\vdash p$ ('$S$ proves $P$') if there exists a proof of $p$ from $S$.\n\nExample: $\\{x=y,x=z\\} \\vdash\\{y=z\\}$ (use axiom 5, with $p$ being $'x=z')$.\n\n1. $(\\forall x)(\\forall y) (x=y \\implies (x=z \\implies y=z))$ (axiom 5);\\\\\n2. $(\\forall x)(\\forall y)(x=y \\implies (x=z \\implies y=z)) \\implies (\\forall y)(x=y \\implies (x=z \\implies y=z))$ (axiom 6, $t='x'$);\\\\\n3. $(\\forall y)(x=y \\implies (x=z \\implies y=z))$ (MP on 1,2);\\\\\n4. $(\\forall y) (x=y \\implies (x=z \\implies y=z)) \\implies (x=y \\implies (x=z \\implies y=z))$ (axiom 6);\\\\\n5. $x=y \\implies (x=z \\implies y=z)$ (MP on 3,4);\\\\\n6. $x=y$ (hypothesis)\\\\\n7. $x=y \\implies y=z$ (mp on 5,6)\\\\\n8. $x \\implies z$ (hypothesis)\\\\\n9. $y=z$ (mp on 7,8).\n\nAim: $T \\vdash p$ $\\iff$ $T \\vDash p$.\n\ne.g. if $p$ holds in every group then $p$ can be proved from the three group axioms (completely obvious).\n\n\\begin{prop} (1, deduction theorem)\\\\\nLet $S \\subset L$, $p,q \\in L$. Then $S \\vdash (p\\implies q) \\iff S \\cup \\{p\\} \\vdash q$.\n\\begin{proof}\nForward: as for propositional logic, from $p \\implies q$ write down $p$ and apply MP to obtain $S \\cup \\{p\\} \\vdash q$;\\\\\nBackward: as for propositional logic: the only new case is 'generalisation'. So in proof of $q$ from $S \\cup \\{p\\}$ we have something like $r$ then $(\\forall x) r$ (Gen), and have a proof of $p \\implies r$ from $S$ (induction), and we want $S \\vdash p \\implies (\\forall x) r$. In proof of $r$ from $S \\cup \\{p\\}$, no premise had $x$ free. So in proof of $p \\implies r$ from $S$, no premise had $x$ free. Hence $S \\vdash (\\forall x)(p \\implies r$ (gen).\\\\\n$\\bullet$ If $x$ does not occur free in $p$: we have $S \\vdash p \\implies (\\forall x) r$ by axiom 6 and MP;\\\\\n$\\bullet$ If $x$ does occur free in $p$: proof of $r$ from $S \\cup \\{p\\}$ cannot have used $p$. So in fact $S \\vdash (\\forall x) r$ whence $S \\vdash (p \\implies (\\forall x) r)$ by axiom 1.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop} (2, soundness)\\\\\nLet $S$ be a set of sentences, $p$ a sentence. Then if $S \\vdash p$ then $S \\vDash p$.\n\\begin{proof}\nWe have proof of $p$ from $S$, and a model $A$ of $S$, and we want $p_x = 1$. This is an induction down the lines of the proof.\n\\end{proof}\n\\end{prop}\n\nFor adequacy, we want if $S \\vDash p$, i.e. that if $S \\cup \\{\\neg p\\} \\vDash \\perp$, then $S \\cup \\{\\neg p\\} \\vdash \\perp$.\n\n\\begin{thm} (3, model existence lemma, or completeness theorem)\\\\\nLet $S \\subset L$ be a set of setences. Then $S$ consistent implies that $S$ have a model.\\\\\nIdeas:\\\\\n$\\bullet$ 1. Build model out of language: let $A$ be the set of closed terms of $L$, with operation line $(1+1) +_A (1+1) = (1+1) +(1+1)$;\\\\\n$\\bullet$ 2. Say for $S$ be the theory of fields: $(1+1)+1 \\neq 1+(1+1)$, but $S \\vdash (1+1)+1 = 1+(1+1)$. So quotient out by $s \\sim t$ if $S \\vdash s = t$;\\\\\n$\\bullet$ 3. Suppose $s$ is the fields of characteristic $2$ or $3$, i.e. field axioms, and the statement $1+1=0 \\vee 1+1+1=0$. Then $S \\not\\vdash 1+1=0$. So $[1+1] \\neq [0]$, where $[\\cdot]$ denotes the equivalent class unrder $\\sim$. Also, $S \\not\\vdash 1+1+1=0$, so $[1+1+1] \\neq [0]$.\n\nSo our structure does not satisfy $1+1=0 \\vee 1+1+1 = 0$. Then we need to extend $S$ to maximal consistent.\n\n$\\bullet$ 4. If $S$ is 'fields with a sqaure root of $2$': field axioms + $(\\exists x) (xx=1+1)$. Maybe no closed term $t$ has $[tt] = [1+1]$. So $s$ lacks 'witnesses'.\\\\\nSolution: for each $(\\exists x|p$ in $S$, add new constant $c$ to language, and add $p[c/x]$ to $S$. (e.g. $cc=1+1$).\\\\\nNow no longer maximal consistent, so go back to step 3.\\\\\nProblem: this might not terminate.\n\\begin{proof}\nWe have consistent $S$ in language $L_0 = L(\\Omega,\\Pi)$. Extend to maximal consistent $S_1$ (zorn), so for each sentence $p \\in L$, we have $p \\in S_1$, or $(\\neg p) \\in S_1$. Thus $S_1$ is complete (for every $p$, $S_1 \\vdash p$ or $S_1 \\vdash (\\neg p)$). Add witnesses: for each $(\\exists x) p$ in $S_1$, add new constant $c$ and axiom $p[c/x]$. We obtain $T_1$ in language $L_1 = L(\\Omega \\cup C_1,\\Pi)$ that has \\emph{witnesses} for $S_1$ (if $(\\exists x) p \\in S$, then some closed term $t$ has $p[t/x] \\in T_1$). It's easy to check $T_1$ consistent. Now extend $T_1$ to maximal consistent $S_2$ (in $L$). Add witnesses, obtaining $T_2$ in language $L_2 =L(\\Omega \\cup C_1 \\cup C_2, \\Pi)$.\\\\\nContinue inductively.\\\\\nPut $\\bar{S} = S_1 \\cup S_2 \\cup ...$. In language $\\bar{L} = L(\\Omega \\cup C_1\\cup C_2 \\cup ...)$.\\\\\n$\\bullet$ $\\bar{S}$ is consistent: If $\\bar{S} \\vdash \\perp$, then some $S_n \\vdash \\perp$ (as proofs are finite), contradiction;\\\\\n$\\bullet$ $\\bar{S}$ is complete: given sentence $p \\in \\bar{L}$, we have $p \\in L_n$ for some $n$ (as $p$ mentions only finitely many constants), so $S_{n+1} \\vdash p$ or $S_{n+1} \\vdash (\\neg p)$ (choice of $S_{n+1}$).\\\\\n$\\bullet$ $\\bar{S}$ has witnesses (for itself): given $(\\exists x)p \\in \\bar{S}$, we have $(\\exists x)p \\in S_n$ for some $n$. So $p[t/x] \\in T_n$ for some closed term $t$ (choice of $T_n$), whence $p[t/x] \\in \\bar{S}$.\n\\end{proof}\n\\end{thm}\n\nOn set of closed terms of $\\bar{L}$, define $s \\sim t$ if $\\bar{S} \\vdash (s=t)$.\n\nThis is clearly an equivalent relationship. let $A$ be the set of equivalent clases. Make $A$ into an $\\bar{L}$-structure by setting $f_A([t_1],...,[t_2]) = [ft_1...t_n]$ (each $f \\in \\bar{\\Omega},\\alpha(f) = n$, closed terms $t_1...t_n$), $\\varphi_A = \\{([t_1],...,[t_n]): \\bar{S} \\vdash \\phi(t_1,...,t_n)\\}$ (each $\\phi \\in \\Pi$, $\\alpha(\\phi) = n$, closed terms $t_1...t_n$).\n\nClaim: $\\phi_A = 1 \\iff \\bar{S} \\vdash p$ for each setnence $p \\in \\bar{L}$. (Then done: $A$ is a model of $\\bar{S}$, so $A$ is a model of $S$.\n\\begin{proof}\nAn easy induction:\\\\\n\\emph{Atomic sentences}:\\\\\n$\\perp$: $\\perp_A = 0$ and $\\bar{S} \\not\\vdash \\perp$.\\\\\n$s=t$: \n\\begin{equation*}\n\\begin{aligned}\n\\bar{S} \\vdash (s=t) &\\iff [s] = [t]\\\\\n&\\iff s_A = t_A\\\\\n&\\iff (s=t)_A = 1\n\\end{aligned}\n\\end{equation*}\n$\\phi(t_1...t_n)$: same.\n\n\\emph{Induction step}:\\\\\n$p \\implies q$: \n\\begin{equation*}\n\\begin{aligned}\n\\bar{S} \\vdash (p \\implies q) &\\iff \\bar{S} \\vdash (\\neg p)\\text{ or } \\bar{S} \\vdash q\\\\\n&\\iff p_A = 0\\text{ or } q_A = 1 (induction)\\\\\n&\\iff (p \\implies q)_A =1 \n\\end{aligned}\n\\end{equation*}\nwhere the second step is because, say if the forward direction doesn't hold, then $\\bar{S} \\vdash p$, $\\bar{S} \\vdash (\\neg q)$ (since $\\bar{S}$ is complete), but then $\\bar{S} \\vdash \\neg(p \\implies q)$, contradiction).\n\n$(\\exists x) p$:\n\\begin{equation*}\n\\begin{aligned}\n\\bar{S} \\vdash (\\exists x) p &\\iff \\bar{S} \\vdash p[t/x]\\\\\n&\\iff p[t/x]_A = 1\\\\\n&\\iff ((\\exists x)p)_A = 1\n\\end{aligned}\n\\end{equation*}\nfor some closed term $t$. The last line is because $A$ is the set of equivalent classes of closed terms.\n\\end{proof}\n\nBy remark before theorem 3 we have\n\n\\begin{coro} (4,adequacy)\\\\\nIf $S \\vDash p$, then $S \\vdash o$.\n\\end{coro}\n\nHence:\n\\begin{thm} (5, G$\\ddot{o}$del's completeness theorem for first-order logic)\\\\\nLet $S$ be a set of sentences and $p$ a sentence (in language $L$). Then $S \\vDash p \\iff S \\vdash p$.\\\\\nThe proof is just soundness + adequacy.\n\\end{thm}\n\nNote:\\\\\n$\\bullet$ If $L$ is countable (i.e .$\\Omega,\\Pi$ countable), then we don't need Zorn's lemma;\\\\\n$\\bullet$ 'First-order' means variables range over elements of our structure (not, e.g., subsets).\n\n\\begin{thm} (6, compactness)\\\\\nLet $S \\subset L$ be a set of sentences. Then if every finite subset of $S$ has a model, then $S$ has a model.\n\\begin{proof}\nThis is trivial if we replace $\\vDash$ with $\\vdash$ (as proofs are finite).\n\\end{proof}\n\\end{thm}\n\nNote: we have no decidability theorem -- how to check if $S \\vDash t$?\n\nSome consequences of completeness/compactness:\\\\\nCan we axiomatise the class of finite groups? In other words, we want some sentences $S$ (in language of groups) s.t. a structure is a model for $S$ $\\iff$ it is a finite group.\n\nHowever, this is not possible.\n\n\\begin{coro} (7)\\\\\nthe class of finite groups cannot be axiomatised (in language of groups).\n\\begin{proof}\nSuppose $S$ axiomatises finite groups. We add to $S$ the sentences:\n\\begin{equation*}\n\\begin{aligned}\n(\\exists x_1) (\\exists x_2) (\\neg (x_1 =x_2))\\\\\n(\\exists x_1) (\\exists x_2) (\\exists x_3) (\\neg (x_1 = x_2) \\wedge \\neg(x_1 = x_3) \\wedge \\neg(x_2 = x_3))\\\\\n...\n\\end{aligned}\n\\end{equation*}\nwhich stands for $|G| \\geq 2$, $|G| \\geq 3$, etc.\\\\\nThen ever finite subset has a model (e.g. $\\Z_n$, $n$ large). However, the set itself has no model -- contradicting compactness.\n\\end{proof}\n\\end{coro}\n\nSimilarly,\n\\begin{coro} (7')\\\\\nLet $S$ be a theory in a language $L$. Then if $S$ has arbitrarily large finite models, then it has an infinite model.\n\\begin{proof}\nAdd sentences as in corollary 7, and apply compactness theorem.\n\\end{proof}\n\\end{coro}\n\nSo we know \\emph{finiteness is not a first-order property}.\n\n\\begin{coro} (8, upward L$\\ddot{o}$wenheim-Skolem theorem)\\\\\nIf a theory $S$ has an infinite model, then it has an uncoutnable model.\n\\begin{proof}\nAdd uncoutnably many consttants $\\{c_i:i \\in I\\}$ to the language, and add to $S$ the set of sentences $c_i \\neq c_j$ (for each distinct $i,j \\in I$). Then any finite subset has a model. So the whole set has a model by compactness.\n\\end{proof}\n\\end{coro}\n\nSimilarly, we could find a model into which $P(P(R))$ injects (choose $I = P(P(R))$). E.g., there exists an infinite field ($\\Q$), so there exists field as big as $P(P(R))$.\n\n\\begin{coro} (9, downward L$\\ddot{o}$wenheim-Skolem theorem):\\\\\nLet $S$ be a theory in countable language $L$. If $S$ has a model, then it has a countable model.\n\\begin{proof}\nThe model constructed in theorem 3 is countable.\n\\end{proof}\n\\end{coro}\n\n\\subsection{Peano Arithmetic}\nWe try to make the usual axioms for $\\N$ into a first-order theory.\\\\\n$L : \\Omega = \\{0,s,+,\\times\\}$, $\\Pi = \\phi$, axioms:\\\\\n1. $(\\forall x) (\\neg s(x) = 0)$;\\\\\n2. $(\\forall x)(\\forall y) (s(x) = s(y) \\implies x=y)$;\\\\\n3. $(\\forall y_1)...(\\forall y_n) [(p[0/x] \\cap (\\forall x) (p \\implies p[s(x)/x])) \\implies (\\forall x) p]$.\\\\\n($y_i$ in 3 are parameters).\\\\\n4. $(\\forall x) (x+0=x)$;\\\\\n5. $(\\forall x)(\\forall y) (x+s(y) = s(x+y))$;\\\\\n6. $(\\forall x) (x+0=0)$;\\\\\n7. $(\\forall x)(\\forall y) (x\\times(y) = (x+y)+x)$.\n\nThese axioms are called Peano Arithmetic or Formal Number Theory.\n\nNote on axiom 3: first guess shold have been \n\\begin{equation*}\n\\begin{aligned}\n(p[0/x] \\cap (\\forall x|(p \\implies p[s(x)/x])) \\implies (\\forall x) p\n\\end{aligned}\n\\end{equation*}\nBut then missing properties like $x \\geq y$ ($y$ chosen earlier).\n\nThen PA has an infinite model, so by upward L-S, PA has an uncountable model that is not isomorphic to $\\N$ trivially. Doesn't this contradict the fact that the usual axioms characterise $\\N$ uniquely?\n\nAnswer: axiom 3 is only 'first-order induction' -- even in $\\N$ itself, it refers to only countably many subsets (as opposed to true induction).\n\nA subset $S \\subset \\N$ is called \\emph{definable} if there exists $p \\in L$, free variable $x$, s.t. $\\forall m \\in \\N$ we have: $m \\in S \\iff p[m/x]$ holds in $\\N$ (where by $m$ we mean $1+1+...+1$ ($m$ times)).\n\ne.g. set of squares: $p(x)$ is $(\\exists y) (yy=x)$;\\\\\nset of primes: $p(x)$ is: $\\neg(x=0) \\cap \\neg(x=1) \\neg (\\forall y) (y |x) \\implies ((y=1) \\vee (y=x))$, where $y|x$ is a short hand for $(\\exists z) (yz = x)$, and by $1$ we mean $s(0)$.\\\\\nPowers of $2$: $p(x)$ is $(\\forall y) ((y|x \\wedge y\\ prime) \\implies (y=2))$.\n\nExercise: powers of 4; challenge: powers of 6.\n\nIs PA complete? in other words, for each sentence $p$, PA $\\vdash p$ or PA $\\vdash \\neg p$?\n\n\\begin{thm} (G$\\ddot{o}$del's incompleteness theorem)\\\\\nPA is not complete.\\\\\nTake $p$ with PA $\\not\\vdash p$, $PA \\not\\vdash \\neg p$. We have $p$ holding in $\\N$ or $(\\neg p)$ holding in $\\N$. Conclution: $\\exists$ sentence $p$ s.t. $p$ is true in $\\N$, but $PA \\not\\vdash p$.\n\\end{thm}\n\nThis does not contradict completeness; it shows that if $p$ true in all models of PA, then PA $\\vdash p$.\n\n\\newpage\n\\section{Set Theory}\nAim: what does 'the universe of sets' look like?\n\nKey starting point: view set theory as 'just another finite-order theory'.\n\n\\subsection{Zermelo-Fraenkel set theory}\nWe have $L$: $\\Omega = \\phi$, $\\Pi = \\{\\varepsilon\\}$, $\\alpha(\\epsilon) = 2$.\n\nWe'll have the ZF axioms: 2 to get started, 4 to build things, and 3 you might not think of at first.\n\nThen a 'universe of sets' will mean a model ($V,\\epsilon$) of the ZF axioms.\n\n1. \\emph{Axiom of extension}:\\\\\nIf two sets have the same mebmers, then they are equal:\\\\\n$(\\forall x)(\\forall y) ((\\forall z) (z \\in x \\iff z \\in y) \\implies (x=y))$.\n\nNote: converse is an instance of a logical axiom.\n\n2. \\emph{Axiom of separtion}:\\\\\nWe can form a subset of a set, or precisely, given set $x$ and property $p(z)$, we can form the set of all $z \\in x$ such that $p(z)$ holds:\\\\\n$(\\forall t_1) ... (\\forall t_n) (\\forall x)(\\exists y) (\\forall z) (z \\in y \\iff (z \\in x \\wedge p))$\\\\\nThis is actually an axiom scheme: for each formula $p$ and free variables $t_i$.\n\nNote: we do want parameters, e.g. to have $\\{z \\in x: t \\in z\\}$, $t$ chosen earlier.\n\n3. \\emph{Axiom of empty-set}:\\\\\nThere is a set with no members.\\\\\n$(\\exists x) (\\forall y) (\\neg y \\in x)$.\n\nWe write $\\phi$ for the unique (by extension axiom) such set $x$. This is just an abbreviation: so $p(\\phi)$ means $(\\exists x) ((\\forall y) (\\neg y \\in x) \\wedge p(x))$.\n\nSimilarly, write $\\{z \\in x: p (z)\\}$ for the set guaranteed by separation.\n\n4. \\emph{Axiom of pair-set}:\\\\\nWe can form $\\{x,y\\}$.\\\\\n$(\\forall x)(\\forall y)(\\exists z) (\\forall t) (t \\in z \\iff t = x \\vee t = y)$.\n\nWe write $\\{x,y\\}$ for this set, and $\\{x\\}$ for $\\{x,x\\}$.\\\\\nWe can now define the 'ordered pair' $(x,y)$ to be $\\{\\{x\\},\\{x,y\\}\\}$.\\\\\nIt's easy to check that $(x,y) = (t,u) \\implies x=t \\wedge y=u$ (follows from axiom so far).\\\\\nSay $x$ is an ordered pair if $(\\exists y) (\\exists z) (x=(y,z))$, and we say $f$ is a function to mean $(\\forall x) (x \\in f \\implies x$ is an ordered pair) $\\wedge (\\forall x)(\\forall y)(\\forall z)((x,y) \\in f \\wedge (x,z) \\in f \\implies y=z)$.\n\nCan now define the domain of a function as follows: write $x = Dom f$ if $(f$ is a function) $\\wedge (\\forall z)(z \\in x \\iff (\\exists t)((z,t) \\in f)))$.\n\nAnd write $f:x \\to y$ for $(f$ is a function) $\\wedge (x=Dom f|\\wedge (\\forall z)((\\exists t)((t,z) \\in f) \\implies z \\in y))$.\n\n5. \\emph{Axiom of union}:\\\\\nWe can form unions.\\\\\n$(\\forall x)(\\exists y)(\\forall z)(z \\in y \\iff (\\exists t) (z \\in t \\wedge t \\in x))$.\n\n6. \\emph{Axiom of power-set}:\\\\\nWe can form power-sets.\\\\\n$(\\forall x)(\\exists y) (\\forall z) (z \\in y \\iff z \\subset x)$.\\\\\nHere by $z \\subset x$ we mean $(\\forall t)(t \\in z \\implies t \\in x)$.\n\nNotes:\\\\\n1. write $\\cup x$ and $\\mathcal{P}(x)$ for these two sets. We can write $x \\cup y$, etc.\\\\\n2. No extra axiom needed for interseionts: we can form $\\cap x$ ($x \\neq \\phi$) as a subset of $y$ any $y \\in x$. So ok by separation.\\\\\n3. We can now form $x \\times y$ as a suitable subset of $\\mathcal{P}\\mathcal{P}(x\\cup y)$ -- since if $t \\in x,u \\in y$, then $(t,u) = \\{\\{t\\},\\{t,u\\}\\}\\in\\mathcal{P}\\mathcal{P}(x \\cup y)$. And then we can form the set of all functions from $x$ to $y$, as a subset of $\\mathcal{P}(x \\times y)$.\n\nThe next three are more subtle:\n\n7. \\emph{Axiom of infinity}:\\\\\nSo far, $V$ (the branch symbol) must be inifinite. For example, write $x^+ = x \\cup \\{x\\}$, then easy to check that $\\phi,\\phi^+,\\phi^{++},...$ are all distinct. We often write $0$ for $\\phi$, $1$ for $\\phi^+$,$2$ for $\\phi^{++}$, etc. So $1 = \\{0\\}, 2 = \\{0,1\\},3=\\{0,1,2\\}$,etc. But does the structure $(V,\\epsilon)$ have an infinite set -- e.g. $x$ with $\\phi \\in x,\\phi^+ \\in x$, ...?\n\nWe say $x$ is a successor set if $(\\phi \\in x) \\wedge (\\forall y) (y \\in x \\implies y^+ \\in x)$.\n\nNow let's state the axiom:\\\\\nThere is an infintie set/there is a successor set.\\\\\n$(\\exists x) (x$ is a successor set$)$.\n\nNote that any intersection of successor sets is a successor set, so there exists a least one, called $\\omega$. This will be our version, in $V$, of the natural numbers.\n\nThus $(\\forall x)(x \\in \\omega \\iff (\\forall y)(y$ a successor set $\\implies x \\in y))$.\n\nNote that if $x \\subset \\omega$ is a successor set then $x=\\omega$ by definition:\\\\\n$(\\forall x)(x \\subset \\omega \\wedge \\phi \\in x \\wedge (\\forall y)(y \\in x \\implies y^+ \\in x)) \\implies x=\\omega)$. This is induction: genuine induction, over all $x \\subset \\omega$ (as opposed to in PA).\n\nAlso, it's easy to check $(\\forall x \\in \\omega) (\\neg x^+ = \\phi)$, and $(\\forall x \\in \\omega)(\\forall y \\in \\omega)(x^+ = y^+ \\implies x=y)$.\n\nThus: $\\omega$ satisfies (in $V$) all the usual axioms for the natural numbers.\n\nSay $x$ is finite if $(\\exists y) (y \\in \\omega \\wedge x$ bijects with $y$).\n\nAnd then $x$ is countable if $x$ is finite or $x$ bijects with $y$.\n\n8. \\emph{Axiom of Foundation}:\\\\\n\"Sets are build up from simpler sets\". We want to disallow $x \\in x$: note that $\\{x\\}$ has no $\\varepsilon$-minimal member; and also disallow $x \\in y \\in x$: note $\\{x,y\\}$ has no $\\varepsilon$-minimal element, etc. And we also want to disallow the infinite sequence $x_1 \\in x_0$, $x_2 \\in x_1$, $x_3 \\in x_2$,..., in which case $\\{x_0,x_1,...\\}$ has no $\\varepsilon$-minimal element.\n\nThe axiom: every (non-empty) set has an $\\varepsilon$-minimal element.\\\\\n$(\\forall x) (x \\neq \\phi \\implies (\\exists y) (y \\in x \\wedge (\\forall z) (z \\in x \\implies z \\not\\in y))$.\n\nBonus lecture on next Wednesday 1pm (proof of incompleteness theorem, consistency of ZF)\n\n9. \\emph{Axiom of Replacement}:\\\\\nWe often say \"for each $i \\in I$ have $A_i$ -- take $\\{A_i: i \\in I\\}$. However, how do we know they form a set? Alternatively, how do we know that $i \\to A_i$ is a function?\\\\\nWe want to say \"the image of a set under something that looks like a function is a set\".\n\nA digression on classes:\\\\\nIdea: $x \\to \\{x\\}$ (for all $x$). This looks like a function, but it isn't: e.g. every function has a domain as functions are sets of ordered pairs, and the domain is just the left element of all those pairs. However, the 'domain' of $x \\to \\{x\\}$ is not a set (the universal 'set').\n\nFor an $L$-structure $V$, a collection $C$ of elements of $V$ is called a \\emph{class} if there is a formula $p$, free variables $x$ (and maybe more) s.t. $x \\in C$ $\\iff p(x)$ holds in $V$. E.g. $V$ is a class: take $p(x)$ to be $x=x$.\n\nFor any $t$, $\\{x: t \\in x\\}$ is a class: take $p(x)$ to be $t \\in x$.\\\\\nNote that every set $y$ is a class: take $p(x)$ to be $x \\in y$.\n\nIf $C$ is not a set (in $V$), i.e. $\\not (\\exists y)(\\forall x)(x \\in y \\iff p(x))$, say $C$ is a proper class. E.g., $V$ is a proper class, as is $\\{x:x$ infinite$\\}$, where by infinite we mean not finite.\n\nSimilarly, a function-class is a collection $F$ of ordered pairs from $V$, s.t. for some formula $p$, free variables $x,y$ (and maybe more), have $(x,y) \\in F \\iff p(x,y)$, and if $(x,y) \\in F, (x,z) \\in F$, then $y=z$.\\\\\nFor example, $x \\to \\{X\\}$ is a function class: take $p(x,y)$ to be $y=\\{x\\}$.\n\n---End of digression---\n\nLet's now state the axiom of replacement: \"the image of a set under a function-class is a set.\\\\\n$(\\forall t_1) ... (\\forall t_n) ([(\\forall x)(\\forall y)(\\forall z) ((p \\wedge p[z/y] ) \\implies y=z)] \\implies [(\\forall x)(\\exists y) (\\forall z) (z \\in y \\iff (\\exists t) (t \\in x \\wedge p[t/x,z/y])])$\\\\\nFor each formula $p$, free variables $x,y,t_1,...,t_n$, i.e., the image of $x$ under $p$ is a set.\n\nEg. for any set $x$, we can form $\\{\\{t\\}:t \\in x\\}$ using function class $t \\to \\{t\\}$.\n\nThis is a 'bad' example, as it didn't need replacement -- see later for 'good' examples.\n\nThose are the ZF axioms.\n\nNote:\\\\\n1: Sometimes separation is called 'comprehension', and sometimes fundation is called 'regularity'.\\\\\n2. ZF axioms do not include AC: ZF + AC is called ZFC, where axiom of choice is: \"every family of (non-empty) sets has a choice function\" -- $ (\\forall f) (f$ is a function $\\wedge (\\forall x) (x \\in Dom f \\implies f(x) \\neq \\phi)) \\implies (\\exists y) (y$ is a function $ \\wedge Dom y = Dom f \\wedge (\\forall x)(x \\in Dom f \\implies g(x) \\in f(x))))$.\n\nGoal: what does a model $(V,\\epsilon)$ of ZF look like?\n\nRemark: we haven't proved ZF consistent (i.e. $\\exists$ model of ZF). Sadly, ZF $\\not\\vdash$ \"ZF has a model\", i.e. it cannot be proved in ordinary maths (ZF or ZFC).\n\nSay $x$ is transitive if every member of $x$ is itself a member of $x$: $(\\forall y)((\\exists z)(y \\in z \\wedge z \\in x) \\implies (y \\in x)$, i.e. $\\cup x \\subset x$.\n\nE.g. $2=\\{\\phi,\\{\\phi\\}\\}$ is transitive; $\\omega$ is transitive as $n=\\{0,1,...,n-1\\}$ $\\forall n \\in \\omega$.\n\nLemma 1: every set $x$ is contained in a transitive set.\n\nRemarks: 1. Officially, let $(V,\\epsilon)$ be a model of ZF. Then in $V$, ... holds, or equivalently, $ZF \\vdash ...$.\\\\\n2. Any $\\cap$ of transitive sets is transitive, so we'll then know that there exists a least transitive set containing $x$, called the transitive closure of $x$, written $TC(x)$.\n\\begin{proof}\nWe'll take $x \\cup (\\cup x) \\cup(\\cup\\cup x) \\cup)\\cup\\cup\\cup x) \\cup ...$ which is a set by union axiom, which is a set by replacement (a good example of replacement): $0 \\to x, 1 \\to \\cup x$, etc. But why is this a function class?\\\\\nTo show that, define $f$ is a an attempt to mean (recall we've done similar things before in chapter 2) $(f$ is a function $) \\cap (Dom f \\in \\omega) \\cap (Dom f \\neq \\phi) \\cap (f (0) = x) \\cap (\\forall n) (n \\in Dom f \\cap n \\neq 0 \\implies f(n) = \\cup f(n-1))$. Then $(\\forall n\\in\\omega) (\\forall f) (\\forall f') ((f,f'$ attempts $\\wedge n \\in Dom f') \\implies f(n) = f'(n))$ (by $\\omega$-induction). And $(\\forall n \\in \\omega) (\\exists f) (f$ an attempt $\\cap n \\in Dom f)$ (again, by $\\omega$-induction). So take $p(y,z)$ to be $(\\exists f) (f$ an attempt $\\cap$ $y \\in Dom f \\cap f(y) = z)$.\n\\end{proof}\n\nWe want foundation to be saying 'sets are built out of simpler sets'. If so, we would want: suppose $p(y) \\forall y \\in x$ implies $p(x)$, then $p(x) \\forall x$.\n\n\\begin{thm} (2, principle of $\\epsilon$-induction): let $p$ be a formula with free variables $t_1,...,t_n,x$. Then $(\\forall t_1)...(\\forall t_n) ((\\forall x) ((\\forall y)(y \\in x \\implies p(y) \\implies p(x)) \\implies (\\forall x) p(x))$. Note that formally, $p(y)$ should be $p[y/x]$, and $p(x)$ should just be $p$.\n\\begin{proof}\nGiven $t_1,...,t_n$, have $p(y) \\forall y \\in x \\implies p(x)$, and suppose $(\\forall x) p(x)$ not true. So $(\\exists x) (\\neg p(x))$. We want ot say 'choose $\\epsilon$-minimal member of $\\{x: \\neg p(x))$, then contradiction'; however, this might not be a set -- e.g. if $p(x)$ is $x \\neq x$.\n\nLet $t = TC(\\{x\\})$. So $x \\in t$, and $\\neg p(x)$. Let $u =\\{y \\in t: \\neg p(y))$, and let $y$ be an $epsilon$-minimal element of $u$. Then $\\neg p(y)$. But $(\\forall z \\in y) p(z)$ (as $z \\in y \\implies z \\in t$ and $y$ is $\\epsilon$-minimal in $u$).\n\\end{proof}\n\\end{thm}\n\nRemarks: 1. we used existence of transitive closures (i.e. lemma 1).\\\\\n2. In fact, $\\epsilon$-induction equivalent to foundatoin: as can deduce foundation from $\\epsilon$-induction (in the presence of the other ZF axioms): say $x$ is regular if $(\\forall y) (x \\in y \\implies y$ has an $\\epsilon$-minimal element$)$. Foundation says every set is regular. To prove this by $\\epsilon$ induction, given $y$ regular $\\forall y \\in x$, we want to prove $x$ is regular. For $x \\in z$, if $x$ minimal then done. Otherwise, some $y \\in x$ has $y \\in z$. But $y$ is regular. So $z$ has a minimal element.\n\nHow about recursion? we want '$f(x)$ defined in terms of the $f(y)$, $y \\in x$'.\n\n\\begin{thm} (3, $\\epsilon$-recursion theorem)\\\\\nLet $G$ be a function-class ($(x,y) \\in G \\iff p(x,y)$ for some formula $p$), everywhere defined. Then there is a function-class $F$ ($(x,y) \\in F \\iff q(x,y)$, for some formula $q$) s.t. $(\\forall x) (F(x) = G(F|x))$. Moreover, $F$ is unique.\\\\\nNote: $F|x = \\{(z,f(z)): z \\in x\\}$ is a set, by replacement.\n\\begin{proof}\nSay $f$ is an attempt if: $(f$ is a function $) \\wedge (Dom f$ transitive $) \\wedge (\\forall x) (x \\in Dom f \\implies f(x) = G(f|x))$ ($f|x$ is defined, as $Dom f$ is transitive).\\\\\nThen $(\\forall x) (f,f'$ attempts defined at $x \\implies f(x) = f'(x))$ by $\\epsilon$-induction.\\\\\nSince, if $f,f'$ agree at all $y \\in x$, then they agree at $x$.\\\\\nAlso, $(\\forall x) (\\exists$ attempt $f$ defined at $x)$ by $\\epsilon$-induction.\\\\\nIndeed, suppose $|forall y \\in x$ $\\exists$ attempt defined at $y$. So $\\forall y \\in x$ $\\exists$ unique attempt $f_y$ defined on $TC(\\{y\\})$. Put $f = \\cup_{y \\in x} f_y$, and now put $f' = f \\cup \\{(x,G(f|x)\\}$. So done: take $q(x,y)$ to be $(\\exists f) (f$ an attempt $\\wedge x \\in Dom f \\wedge f(x) = y)$.\n\\end{proof}\n\\end{thm}\n\nNote: $\\epsilon$-induction and $\\epsilon$-recursion proofs look very similar to induction and recursion from chapter 2.\n\nWhat properties of the 'relation-class' $\\epsilon$ (i.e. the formula $p(x,y) = x\\epsilon y$) have we used?\n\n1. $p$ is well-founded: every non-empty set has a $p$-minimal element;\\\\\n2. $p$ is local: $(y:p(y,x))$ is a set, for each $x$.\n\nSo in fact we have $p$-induction and $p$-recursion for any $p(x,y)$ that is well-founde and local.\n\nFor a relation $r$ on a set $a$, trivially $r$ is local (as $a$ is a set). So to have $r$-induction and $r$-recursion, just need $r$ to be well-founded.\n\nThus induction and recursion from chapter 2 are special cases of this.\n\nCan we 'model' a relation by $\\varepsilon$?\n\nE.g. let $a = \\{a_1,a_2,a_3\\}$ and $r=\\{(a_1,a_2),(a_2,a_3)\\}$.\n\nPut $b = \\{b_1,b_2,b_3\\}$, where $b_1 = \\phi$, $b_2 = \\{\\phi\\}$, $b_3 = \\{\\{\\phi\\}\\}$. Then $a_i r a_j \\iff b_i r b_j \\forall i,j$. Moreover, $b$ transitive.\n\nSay relation $r$ on set $a$ is extensional if $(\\forall x,y \\in a) ((\\forall z \\in a)(zrx \\iff zry) \\implies x=y)$, e.g. above relation on above $a$, or relation $\\epsilon$ on any transitive set.\n\nAnalogue of subset collapse is:\n\n\\begin{thm} (4, Mostowski's collapse theorem):\\\\\nLet $r$ be a relation on a set $a$ that is well-founded and extensional. Then $\\exists$ transitive $b$ and bijection $f:a \\to b$ s.t. $(\\forall x,y \\in a)(x \\vee y \\iff f(x) \\in f(y))$. Moreover, $b$ and $f$ are unique.\n\\begin{proof}\nDefine $f(x)=\\{f(y):yrx\\}$ a definition by $r$-recursion on the set $a$. ($f$ is a function, not just a function-class, as it is an image of the set $a$).\n\nLet $b = \\{f(x):x \\in a\\}$ (a set, by replacement).\n\nThen $b$ transitive (definition of $f$), and $f$ surjective (definition of $b$). We need $f$ injective, then also have $xry \\iff f(x) \\in f(y)$.\n\nWe'll show that $(\\forall y) (f(y) = f(x) \\implies y=x)$ holds $\\forall x \\in a$, by $r$-induction on $x$.\n\nSo given $y$ with $f(y) =f(x)$, we want $y=x$, and may assume that $(\\forall t)(\\forall n) ((t,n \\in a \\wedge trx \\wedge f(y)=f(t) ) \\implies n=t)$.\n\nFrom $f(y)=f(x)$, we have $\\{f(n):nry\\} = \\{f(t):trx\\}$, whence $\\{n:nry\\} = \\{t:trx\\}$.\n\nThus $x=y$ as $r$ extensional.\n\nExistence: if $f,f'$ suitable then $(\\forall x \\in a) (f(x) = f''(x))$ by $r$-induction.\n\\end{proof}\n\\end{thm}\n\nAn ordimal or Von Neumann ordinal is a transitive set that is well-orderd by $\\epsilon$. (or 'totally ordered, thanks to foundation)\n\ne.g. $\\phi,\\{\\phi\\}$, any $n \\in \\omega$ (as $n=\\{0,1,2,...,\\{n-1\\}$), $\\omega$ itself.\n\nSo mostowski tells us: any well-ordered $X$ is order-isomorphic to a unique ordinal $\\alpha$. Say $X$ has order-type $\\alpha$. (this was owed from chapter 2).\n\nRemark (irrelevant): we know that for any ordinal $\\alpha$, have $\\{\\beta:\\beta<\\alpha\\}$ is a well-ordered set of order-type $\\alpha$.\n\nHence, by definition of $f$ in theorem 4, we have: $\\alpha<\\beta \\iff \\alpha \\in \\beta$.\n\nSo $\\alpha = \\{\\beta:\\beta<\\alpha\\}$.\n\nSo e.g. $\\alpha^+ = \\alpha \\cup \\{\\alpha\\}$, and $\\sup\\{\\alpha_i:i \\in I\\} = \\cup\\{\\alpha_i:i\\in I\\}$.\n\nPicture of the universe:\n\n\"start with $\\phi$, and take $\\P$ (power sets) many times. Define sets $V_\\alpha$ for each ordinal $\\alpha$ be recursion: $V_0 = \\phi$, $V_{\\alpha+1} = \\P(V_\\alpha)$, $V_\\lambda = \\cup_{\\alpha < \\lambda} V_\\alpha$ for $\\lambda$ a non-zero limit. We want every set $x$ to belong to some $V_\\alpha$.\n\n\\begin{lemma} (5)\\\\\nEach $V_\\alpha$ is transitive.\n\\begin{proof}\nInduction on $\\alpha$: 0 is trivial.\\\\\nSuccessors: given $x \\in y \\in V_{\\alpha+1}$, we have $y \\in \\P(V_\\alpha)$, so $x \\in V_\\alpha$. So $x \\subset V_\\alpha$ (as $V_\\alpha$ transitive), i.e. $x \\in \\P(V_\\alpha) = V_{\\alpha+1}$.\\\\\nLimits: any union of transitive sets is transitive.\n\\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (6)\\\\\nWe have $V_\\alpha \\subset V_\\beta$ whenever $\\alpha \\leq \\beta$.\n\\begin{proof}\nInduction on $\\beta$ ($\\alpha$ fixed):\\\\\n$\\beta=\\alpha$ is trivial.\\\\\nSuccessors ($\\beta$): given $V_\\alpha \\subset V_\\beta$, we want $V_\\alpha \\subset \\P(V_\\beta)$. But $V_\\beta \\subset \\P(V_\\beta)$, $x \\in V_\\beta \\implies x \\subset V_\\beta$ as that is transitive.\\\\\nLimits are trivial as well as it is the union of all $V_\\alpha$ below.\n\\end{proof}\n\\end{lemma}\n\n\\begin{thm} (7)\\\\\n$(\\forall x) (\\exists \\alpha) (x \\in V_\\alpha)$.\\\\\nSlogan: $V = \\cup_{\\alpha \\in ON} V_\\alpha$, where $ON$ is the class of ordinals. However that's not allowed, as we cannot take union over a class.\\\\\nNotes: 1. $x \\subset V_\\alpha \\iff x \\in V_{\\alpha+1}$.\\\\\n2. If $x \\subset V_\\alpha$, then there exists least such $\\alpha$ -- called the rank of $x$. For example, $rank(\\phi) = 0$, $rank(\\{\\phi\\}) = 1$, $rank(\\omega) = \\omega$, and $rank(\\alpha) = \\alpha$ for all ordinals $\\alpha$ (by induction).\n\\begin{proof}\nWe'll show $(\\forall x) (\\exists \\alpha) (x \\subset V_\\alpha)$ by $\\epsilon$-induction. Given $x$, have $y \\subset V_\\alpha$ for some $\\alpha$ (for each $y \\in x)$, so $y \\subset V_{rank(y)}$, i.e. $y \\in V_{rank(y)+1}$ for each $y \\in x$.\\\\\nLet $\\alpha =\\sup \\{ rank(y) + 1: y \\in x\\}$. Then $x \\subset V_\\alpha$.\n\\end{proof}\n\\end{thm}\n\n\\begin{rem}\n1. The $V_\\alpha$ are called the Von-Neumann Hierarchy.\\\\\n2. Proof gives: $rank(x) = \\sup\\{rank(y)+1: y \\in x\\}$ (this is the right way to think about rank). For example, what's the rank of $\\{6\\}$? For each ordinal the rank is itself, so $rank(6) = 6$. So $rank\\{6\\} =\\sup\\{rank(6)+1\\} = 7$.\\\\\n3. (useless comment) Most of maths takes place in $V_{\\omega+10}$, apart from order-types, etc. i.e. in this course.\n\\end{rem}\n\n\\section{Cardinals}\nLet's look at 'sizes' of sets. Work in ZFC.\n\nWe want to define $Card(x)$ so that $Card(x) = Card(y) \\iff x \\leftrightarrow y$, which is a short hand for 'there is a bijection from $x$ to $y$'.\n\n(Note: We cannot take $Card(x) = \\{y:y \\leftrightarrow x\\}$, as this may not be a set.)\n\nWe do know $x \\leftrightarrow \\alpha$ for some ordinal $\\alpha$, so can define $Card(x)$ to be the least such $\\alpha$. Thus $Card(x) = Card(y) \\iff x \\leftrightarrow y$. \n\n(In just ZF, use Scott trick: define the essential rank of $x$ to be $essrank(x)=$least rank of any $y \\leftrightarrow x$, and then define $Card(x) = \\{y \\subset V_{essrank(x)}:y \\leftrightarrow x\\}$)\n\nSay $m$ is a cardinal or a cardinality if $m=Card(x)$ for some $x$.\n\nFor cardinals $m,n$, say $m \\leq n$ if $M$ injects into $N$ for some $M,N$ with $Card(M) = m$, $Card(N) = n$ (does not depend on choice of $M$ and $N$).\n\nWrite $m<n$ if $m \\leq n$ and $m \\neq n$. For example, $Card(\\omega) \\leq Card(\\P(\\omega))$.\n\nNote that if $m \\leq n$, $n \\leq m$, then $m=n$ (Schr$\\ddot{o}$der-Bernstein). So $\\leq$ is a partial order, and even a total order (by well-ordering). However, in just ZF, this need not be a total ordering.\n\n\\iffalse\n\\begin{equation*}\n\\begin{aligned}\n\n\\end{aligned}\n\\end{equation*}\n\\fi\n\n\n\\end{document}\n", "meta": {"hexsha": "8ced9094d3b7cb6d8b7acfdc9a9607e40b0dfb7b", "size": 86416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/LST.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/LST.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/LST.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": 64.6342557966, "max_line_length": 904, "alphanum_fraction": 0.6306008147, "num_tokens": 31826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.6390875105772319}}
{"text": "\\section{Camera Calibration and 3d Reconstruction}\n\nThe functions in this section use the so-called pinhole camera model. That\nis, a scene view is formed by projecting 3D points into the image plane\nusing a perspective transformation.\n\n\\[\ns \\; m' = A [R|t] M'\n\\]\n\nor\n\n\\[\ns \\vecthree{u}{v}{1} = \\vecthreethree\n{f_x}{0}{c_x}\n{0}{f_y}{c_y}\n{0}{0}{1}\n\\begin{bmatrix}\n r_{11} & r_{12} & r_{13} & t_1 \\\\\n r_{21} & r_{22} & r_{23} & t_2 \\\\\n r_{31} & r_{32} & r_{33} & t_3\n\\end{bmatrix}\n\\begin{bmatrix}X\\\\Y\\\\Z\\\\1 \\end{bmatrix}\n\\]\n\nWhere $(X, Y, Z)$ are the coordinates of a 3D point in the world\ncoordinate space, $(u, v)$ are the coordinates of the projection point\nin pixels. $A$ is called a camera matrix, or a matrix of\nintrinsic parameters. $(cx, cy)$ is a principal point (that is\nusually at the image center), and $fx, fy$ are the focal lengths\nexpressed in pixel-related units. Thus, if an image from camera is\nscaled by some factor, all of these parameters should\nbe scaled (multiplied/divided, respectively) by the same factor. The\nmatrix of intrinsic parameters does not depend on the scene viewed and,\nonce estimated, can be re-used (as long as the focal length is fixed (in\ncase of zoom lens)). The joint rotation-translation matrix $[R|t]$\nis called a matrix of extrinsic parameters. It is used to describe the\ncamera motion around a static scene, or vice versa, rigid motion of an\nobject in front of still camera. That is, $[R|t]$ translates\ncoordinates of a point $(X, Y, Z)$ to some coordinate system,\nfixed with respect to the camera. The transformation above is equivalent\nto the following (when $z \\ne 0$):\n\n\\[\n\\begin{array}{l}\n\\vecthree{x}{y}{z} = R \\vecthree{X}{Y}{Z} + t\\\\\nx' = x/z\\\\\ny' = y/z\\\\\nu = f_x*x' + c_x\\\\\nv = f_y*y' + c_y\n\\end{array}\n\\]\n\nReal lenses usually have some distortion, mostly\nradial distortion and slight tangential distortion. So, the above model\nis extended as:\n\n\\[\n\\begin{array}{l}\n\\vecthree{x}{y}{z} = R \\vecthree{X}{Y}{Z} + t\\\\\nx' = x/z\\\\\ny' = y/z\\\\\nx'' = x' \\frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2 p_1 x' y' + p_2(r^2 + 2 x'^2) \\\\\ny'' = y' \\frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' \\\\\n\\text{where} \\quad r^2 = x'^2 + y'^2 \\\\\nu = f_x*x'' + c_x\\\\\nv = f_y*y'' + c_y\n\\end{array}\n\\]\n\n$k_1$, $k_2$, $k_3$, $k_4$, $k_5$, $k_6$ are radial distortion coefficients, $p_1$, $p_2$ are tangential distortion coefficients.\nHigher-order coefficients are not considered in OpenCV. In the functions below the coefficients are passed or returned as\n\\[ (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) \\] vector. That is, if the vector contains 4 elements, it means that $k_3=0$.\nThe distortion coefficients do not depend on the scene viewed, thus they also belong to the intrinsic camera parameters.\n\\emph{And they remain the same regardless of the captured image resolution.}\nThat is, if, for example, a camera has been calibrated on images of $320\n\\times 240$ resolution, absolutely the same distortion coefficients can\nbe used for images of $640 \\times 480$ resolution from the same camera (while $f_x$,\n$f_y$, $c_x$ and $c_y$ need to be scaled appropriately).\n\nThe functions below use the above model to\n\n\\begin{itemize}\n \\item Project 3D points to the image plane given intrinsic and extrinsic parameters\n \\item Compute extrinsic parameters given intrinsic parameters, a few 3D points and their projections.\n \\item Estimate intrinsic and extrinsic camera parameters from several views of a known calibration pattern (i.e. every view is described by several 3D-2D point correspondences).\n \\item Estimate the relative position and orientation of the stereo camera \"heads\" and compute the \\emph{rectification} transformation that makes the camera optical axes parallel.\n\\end{itemize}\n\n\\ifC\n\n\\cvCPyFunc{CalcImageHomography}\nCalculates the homography matrix for an oblong planar object (e.g. arm).\n\n\\cvdefC{\nvoid cvCalcImageHomography( \\par float* line,\\par CvPoint3D32f* center,\\par float* intrinsic,\\par float* homography );\n}\n\\cvdefPy{CalcImageHomography(line,center)-> (intrinsic,homography)}\n\n\\begin{description}\n\\cvarg{line}{the main object axis direction (vector (dx,dy,dz))}\n\\cvarg{center}{object center ((cx,cy,cz))}\n\\cvarg{intrinsic}{intrinsic camera parameters (3x3 matrix)}\n\\cvarg{homography}{output homography matrix (3x3)}\n\\end{description}\n\nThe function calculates the homography\nmatrix for the initial image transformation from image plane to the\nplane, defined by a 3D oblong object line (See \\_\\_Figure 6-10\\_\\_\nin the OpenCV Guide 3D Reconstruction Chapter).\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{CalibrateCamera2}\n\\else\n\\cvCppFunc{calibrateCamera}\n\\fi\nFinds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.\n\n\\cvdefC{double cvCalibrateCamera2( \\par const CvMat* objectPoints,\\par const CvMat* imagePoints,\\par const CvMat* pointCounts,\\par CvSize imageSize,\\par CvMat* cameraMatrix,\\par CvMat* distCoeffs,\\par CvMat* rvecs=NULL,\\par CvMat* tvecs=NULL,\\par int flags=0 );}\n\\cvdefPy{CalibrateCamera2(objectPoints,imagePoints,pointCounts,imageSize,cameraMatrix,distCoeffs,rvecs,tvecs,flags=0)-> None}\n\\cvdefCpp{double calibrateCamera( const vector<vector<Point3f> >\\& objectPoints,\\par\n                      const vector<vector<Point2f> >\\& imagePoints,\\par\n                      Size imageSize,\\par\n                      Mat\\& cameraMatrix, Mat\\& distCoeffs,\\par\n                      vector<Mat>\\& rvecs, vector<Mat>\\& tvecs,\\par\n                      int flags=0 );}\n\\begin{description}\n\\ifCPy\n\\cvarg{objectPoints}{The joint matrix of object points - calibration pattern features in the model coordinate space. It is floating-point 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel array, where N is the total number of points in all views.}\n\\cvarg{imagePoints}{The joint matrix of object points projections in the camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}\n\\cvarg{pointCounts}{Integer 1xM or Mx1 vector (where M is the number of calibration pattern views) containing the number of points in each particular view. The sum of vector elements must match the size of \\texttt{objectPoints} and \\texttt{imagePoints} (=N).}\n\\fi\n\\ifCpp\n\\cvarg{objectPoints}{The vector of vectors of points on the calibration pattern in its coordinate system, one vector per view. If the same calibration pattern is shown in each view and it's fully visible then all the vectors will be the same, although it is possible to use partially occluded patterns, or even different patterns in different views - then the vectors will be different. The points are 3D, but since they are in the pattern coordinate system, then if the rig is planar, it may have sense to put the model to the XY coordinate plane, so that Z-coordinate of each input object point is 0}\n\\cvarg{imagePoints}{The vector of vectors of the object point projections on the calibration pattern views, one vector per a view. The projections must be in the same order as the corresponding object points.}\n\\fi\n\\cvarg{imageSize}{Size of the image, used only to initialize the intrinsic camera matrix}\n\\cvarg{cameraMatrix}{The output 3x3 floating-point camera matrix $A = \\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$.\\newline\nIf \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS} and/or \\texttt{CV\\_CALIB\\_FIX\\_ASPECT\\_RATIO} are specified, some or all of \\texttt{fx, fy, cx, cy} must be initialized before calling the function}\n\\cvarg{distCoeffs}{The output vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements}\n\\cvarg{rvecs}{The output \\cvCPy{3x\\emph{M} or \\emph{M}x3 1-channel, or 1x\\emph{M} or \\emph{M}x1 3-channel array}\\cvCpp{vector} of rotation vectors (see \\cvCross{Rodrigues2}{Rodrigues}), estimated for each pattern view. That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, i.e. real position of the calibration pattern in the k-th pattern view (k=0..\\emph{M}-1)}\n\\cvarg{tvecs}{The output \\cvCPy{3x\\emph{M} or \\emph{M}x3 1-channel, or 1x\\emph{M} or \\emph{M}x1 3-channel array}\\cvCpp{vector} of translation vectors, estimated for each pattern view.}\n\\cvarg{flags}{Different flags, may be 0 or combination of the following values:\n\\begin{description}\n\\cvarg{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS}{\\texttt{cameraMatrix} contains the valid initial values of \\texttt{fx, fy, cx, cy} that are optimized further. Otherwise, \\texttt{(cx, cy)} is initially set to the image center (\\texttt{imageSize} is used here), and focal distances are computed in some least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to estimate the extrinsic parameters. Use \\cvCross{FindExtrinsicCameraParams2}{solvePnP} instead.}\n\\cvarg{CV\\_CALIB\\_FIX\\_PRINCIPAL\\_POINT}{The principal point is not changed during the global optimization, it stays at the center or at the other location specified when \\newline \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS} is set too.}\n\\cvarg{CV\\_CALIB\\_FIX\\_ASPECT\\_RATIO}{The functions considers only \\texttt{fy} as a free parameter, the ratio \\texttt{fx/fy} stays the same as in the input \\texttt{cameraMatrix}. \\newline When \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS} is not set, the actual input values of \\texttt{fx} and \\texttt{fy} are ignored, only their ratio is computed and used further.}\n\\cvarg{CV\\_CALIB\\_ZERO\\_TANGENT\\_DIST}{Tangential distortion coefficients $(p_1, p_2)$ will be set to zeros and stay zero.}}\n\\cvarg{CV\\_CALIB\\_FIX\\_K1,...,CV\\_CALIB\\_FIX\\_K6}{Do not change the corresponding radial distortion coefficient during the optimization. If \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS} is set, the coefficient from the supplied \\texttt{distCoeffs} matrix is used, otherwise it is set to 0.}\n\\cvarg{CV\\_CALIB\\_RATIONAL\\_MODEL}{Enable coefficients k4, k5 and k6. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function will compute \\cvCpp{and return} only 5 distortion coefficients.}\n\\end{description}\n\\end{description}\n\nThe function estimates the intrinsic camera\nparameters and extrinsic parameters for each of the views. The\ncoordinates of 3D object points and their correspondent 2D projections\nin each view must be specified. That may be achieved by using an\nobject with known geometry and easily detectable feature points.\nSuch an object is called a calibration rig or calibration pattern,\nand OpenCV has built-in support for a chessboard as a calibration\nrig (see \\cvCross{FindChessboardCorners}{findChessboardCorners}). Currently, initialization\nof intrinsic parameters (when \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS}\nis not set) is only implemented for planar calibration patterns\n(where z-coordinates of the object points must be all 0's). 3D\ncalibration rigs can also be used as long as initial \\texttt{cameraMatrix}\nis provided.\n\nThe algorithm does the following:\n\\begin{enumerate}\n    \\item First, it computes the initial intrinsic parameters (the option only available for planar calibration patterns) or reads them from the input parameters. The distortion coefficients are all set to zeros initially (unless some of \\texttt{CV\\_CALIB\\_FIX\\_K?} are specified).\n    \\item The initial camera pose is estimated as if the intrinsic parameters have been already known. This is done using \\cvCross{FindExtrinsicCameraParams2}{solvePnP}\n    \\item After that the global Levenberg-Marquardt optimization algorithm is run to minimize the reprojection error, i.e. the total sum of squared distances between the observed feature points \\texttt{imagePoints} and the projected (using the current estimates for camera parameters and the poses) object points \\texttt{objectPoints}; see \\cvCross{ProjectPoints2}{projectPoints}.\n\\end{enumerate}\n\n\\ifPy\n\\else\nThe function returns the final re-projection error.\n\\fi\n\nNote: if you're using a non-square (=non-NxN) grid and\n\\cvCppCross{findChessboardCorners} for calibration, and \\texttt{calibrateCamera} returns\nbad values (i.e. zero distortion coefficients, an image center very far from\n$(w/2-0.5,h/2-0.5)$, and / or large differences between $f_x$ and $f_y$ (ratios of\n10:1 or more)), then you've probably used \\texttt{patternSize=cvSize(rows,cols)},\nbut should use \\texttt{patternSize=cvSize(cols,rows)} in \\cvCross{FindChessboardCorners}{findChessboardCorners}.\n\nSee also: \\cvCross{FindChessboardCorners}{findChessboardCorners}, \\cvCross{FindExtrinsicCameraParams2}{solvePnP}, \\cvCppCross{initCameraMatrix2D}, \\cvCross{StereoCalibrate}{stereoCalibrate}, \\cvCross{Undistort2}{undistort}\n\n\\ifCpp\n\n\\cvCppFunc{calibrationMatrixValues}\nComputes some useful camera characteristics from the camera matrix\n\n\\cvdefCpp{void calibrationMatrixValues( const Mat\\& cameraMatrix,\\par\n                              Size imageSize,\\par\n                              double apertureWidth,\\par\n                              double apertureHeight,\\par\n                              double\\& fovx,\\par\n                              double\\& fovy,\\par\n                              double\\& focalLength,\\par\n                              Point2d\\& principalPoint,\\par\n                              double\\& aspectRatio );}\n\\begin{description}\n\\cvarg{cameraMatrix}{The input camera matrix that can be estimated by \\cvCppCross{calibrateCamera} or \\cvCppCross{stereoCalibrate}}\n\\cvarg{imageSize}{The input image size in pixels}\n\\cvarg{apertureWidth}{Physical width of the sensor}\n\\cvarg{apertureHeight}{Physical height of the sensor}\n\\cvarg{fovx}{The output field of view in degrees along the horizontal sensor axis}\n\\cvarg{fovy}{The output field of view in degrees along the vertical sensor axis}\n\\cvarg{focalLength}{The focal length of the lens in mm}\n\\cvarg{principalPoint}{The principal point in pixels}\n\\cvarg{aspectRatio}{$f_y/f_x$}\n\\end{description}\n\nThe function computes various useful camera characteristics from the previously estimated camera matrix.\n\n\\cvCppFunc{composeRT}\nCombines two rotation-and-shift transformations\n\n\\cvdefCpp{void composeRT( const Mat\\& rvec1, const Mat\\& tvec1,\\par\n                const Mat\\& rvec2, const Mat\\& tvec2,\\par\n                Mat\\& rvec3, Mat\\& tvec3 );\\newline\nvoid composeRT( const Mat\\& rvec1, const Mat\\& tvec1,\\par\n                const Mat\\& rvec2, const Mat\\& tvec2,\\par\n                Mat\\& rvec3, Mat\\& tvec3,\\par\n                Mat\\& dr3dr1, Mat\\& dr3dt1,\\par\n                Mat\\& dr3dr2, Mat\\& dr3dt2,\\par\n                Mat\\& dt3dr1, Mat\\& dt3dt1,\\par\n                Mat\\& dt3dr2, Mat\\& dt3dt2 );}\n\\begin{description}\n\\cvarg{rvec1}{The first rotation vector}\n\\cvarg{tvec1}{The first translation vector}\n\\cvarg{rvec2}{The second rotation vector}\n\\cvarg{tvec2}{The second translation vector}\n\\cvarg{rvec3}{The output rotation vector of the superposition}\n\\cvarg{tvec3}{The output translation vector of the superposition}\n\\cvarg{d??d??}{The optional output derivatives of \\texttt{rvec3} or \\texttt{tvec3} w.r.t. \\texttt{rvec?} or \\texttt{tvec?}}\n\\end{description}\n\nThe functions compute:\n\n\\[ \\begin{array}{l}\n\\texttt{rvec3} = \\mathrm{rodrigues}^{-1}\\left(\\mathrm{rodrigues}(\\texttt{rvec2}) \\cdot\n\\mathrm{rodrigues}(\\texttt{rvec1})\\right) \\\\\n\\texttt{tvec3} = \\mathrm{rodrigues}(\\texttt{rvec2}) \\cdot \\texttt{tvec1} + \\texttt{tvec2}\n\\end{array}, \\]\n\nwhere $\\mathrm{rodrigues}$ denotes a rotation vector to rotation matrix transformation, and $\\mathrm{rodrigues}^{-1}$ denotes the inverse transformation, see \\cvCppCross{Rodrigues}.\n\nAlso, the functions can compute the derivatives of the output vectors w.r.t the input vectors (see \\cvCppCross{matMulDeriv}).\nThe functions are used inside \\cvCppCross{stereoCalibrate} but can also be used in your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a function that contains matrix multiplication.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{ComputeCorrespondEpilines}\n\\else\n\\cvCppFunc{computeCorrespondEpilines}\n\\fi\nFor points in one image of a stereo pair, computes the corresponding epilines in the other image.\n\n\\cvdefC{void cvComputeCorrespondEpilines( \\par const CvMat* points,\\par int whichImage,\\par const CvMat* F, \\par CvMat* lines);}\n\\cvdefPy{ComputeCorrespondEpilines(points, whichImage, F, lines) -> None}\n\\cvdefCpp{void computeCorrespondEpilines( const Mat\\& points,\\par\n                                int whichImage, const Mat\\& F,\\par\n                                vector<Vec3f>\\& lines );}\n\\begin{description}\n\\cvCPy{\\cvarg{points}{The input points. \\texttt{2xN, Nx2, 3xN} or \\texttt{Nx3} array (where \\texttt{N} number of points). Multi-channel \\texttt{1xN} or \\texttt{Nx1} array is also acceptable}}\n\\cvCpp{\\cvarg{points}{The input points. $N \\times 1$ or $1 \\times N$ matrix of type \\texttt{CV\\_32FC2} or \\texttt{vector<Point2f>}}}\n\\cvarg{whichImage}{Index of the image (1 or 2) that contains the \\texttt{points}}\n\\cvarg{F}{The fundamental matrix that can be estimated using \\cvCross{FindFundamentalMat}{findFundamentalMat}\nor \\cvCross{StereoRectify}{stereoRectify}.}\n\\cvarg{lines}{\\cvCPy{The output epilines, a \\texttt{3xN} or \\texttt{Nx3} array.}\\cvCpp{The output vector of the corresponding to the points epipolar lines in the other image.} Each line $ax + by + c=0$ is encoded by 3 numbers $(a, b, c)$}\n\\end{description}\n\nFor every point in one of the two images of a stereo-pair the function finds the equation of the\ncorresponding epipolar line in the other image.\n\nFrom the fundamental matrix definition (see \\cvCross{FindFundamentalMat}{findFundamentalMat}),\nline $l^{(2)}_i$ in the second image for the point $p^{(1)}_i$ in the first image (i.e. when \\texttt{whichImage=1}) is computed as:\n\n\\[ l^{(2)}_i = F p^{(1)}_i \\]\n\nand, vice versa, when \\texttt{whichImage=2}, $l^{(1)}_i$ is computed from $p^{(2)}_i$ as:\n\n\\[ l^{(1)}_i = F^T p^{(2)}_i \\]\n\nLine coefficients are defined up to a scale. They are normalized, such that $a_i^2+b_i^2=1$.\n\n\\ifCPy\n\\cvCPyFunc{ConvertPointsHomogeneous}\n\\else\n\\cvCppFunc{convertPointsHomogeneous}\n\\fi\nConvert points to/from homogeneous coordinates.\n\n\\cvdefC{void cvConvertPointsHomogeneous( \\par const CvMat* src,\\par CvMat* dst );}\n\n\\cvdefPy{ConvertPointsHomogeneous( src, dst ) -> None}\n\n\\cvdefCpp{void convertPointsHomogeneous( const Mat\\& src, vector<Point3f>\\& dst );\\newline\nvoid convertPointsHomogeneous( const Mat\\& src, vector<Point2f>\\& dst );}\n\n\\begin{description}\n\\ifC\n\\cvarg{src}{The input point array, \\texttt{2xN, Nx2, 3xN, Nx3, 4xN or Nx4 (where \\texttt{N} is the number of points)}. Multi-channel \\texttt{1xN} or \\texttt{Nx1} array is also acceptable}\n\\cvarg{dst}{The output point array, must contain the same number of points as the input; The dimensionality must be the same, 1 less or 1 more than the input, and also within 2 to 4}\n\\else\n\\cvarg{src}{The input array or vector of 2D, 3D or 4D points}\n\\cvarg{dst}{The output vector of 2D or 2D points}\n\\fi\n\\end{description}\n\nThe \\cvC{function converts}\\cvCpp{functions convert} 2D or 3D points from/to homogeneous coordinates, or simply \\cvC{copies or transposes}\\cvCpp{copy or transpose} the array. If the input array dimensionality is larger than the output, each coordinate is divided by the last coordinate:\n\n\\[\n\\begin{array}{l}\n(x,y[,z],w) -> (x',y'[,z'])\\\\\n\\text{where} \\\\\nx' = x/w \\\\\ny' = y/w \\\\\nz' = z/w \\quad \\text{(if output is 3D)}\n\\end{array}\n\\]\n\nIf the output array dimensionality is larger, an extra 1 is appended to each point.  Otherwise, the input array is simply copied (with optional transposition) to the output.\n\n\\cvC{\\textbf{Note} because the function accepts a large variety of array layouts, it may report an error when input/output array dimensionality is ambiguous. It is always safe to use the function with number of points $\\texttt{N} \\ge 5$, or to use multi-channel \\texttt{Nx1} or \\texttt{1xN} arrays.}\n\n\\ifCPy\n\n\\cvCPyFunc{CreatePOSITObject}\nInitializes a structure containing object information.\n\n\\cvdefC{\nCvPOSITObject* cvCreatePOSITObject( \\par CvPoint3D32f* points,\\par int point\\_count );\n}\\cvdefPy{CreatePOSITObject(points)-> POSITObject}\n\n\\begin{description}\n\\ifC\n\\cvarg{points}{Pointer to the points of the 3D object model}\n\\cvarg{point\\_count}{Number of object points}\n\\else\n\\cvarg{points}{List of 3D points}\n\\fi\n\\end{description}\n\nThe function allocates memory for the object structure and computes the object inverse matrix.\n\nThe preprocessed object data is stored in the structure \\cvCPyCross{CvPOSITObject}, internal for OpenCV, which means that the user cannot directly access the structure data. The user may only create this structure and pass its pointer to the function.\n\nAn object is defined as a set of points given in a coordinate system. The function \\cvCPyCross{POSIT} computes a vector that begins at a camera-related coordinate system center and ends at the \\texttt{points[0]} of the object.\n\nOnce the work with a given object is finished, the function \\cvCPyCross{ReleasePOSITObject} must be called to free memory.\n\n\\cvCPyFunc{CreateStereoBMState}\nCreates block matching stereo correspondence structure.\n\n\\cvdefC{\n\nCvStereoBMState* cvCreateStereoBMState( int preset=CV\\_STEREO\\_BM\\_BASIC,\n                                        int numberOfDisparities=0 );\n\n}\n\\cvdefPy{CreateStereoBMState(preset=CV\\_STEREO\\_BM\\_BASIC,numberOfDisparities=0)-> StereoBMState}\n\n\\begin{description}\n\\cvarg{preset}{ID of one of the pre-defined parameter sets. Any of the parameters can be overridden after creating the structure.  Values are\n\\begin{description}\n\\cvarg{CV\\_STEREO\\_BM\\_BASIC}{Parameters suitable for general cameras}\n\\cvarg{CV\\_STEREO\\_BM\\_FISH\\_EYE}{Parameters suitable for wide-angle cameras}\n\\cvarg{CV\\_STEREO\\_BM\\_NARROW}{Parameters suitable for narrow-angle cameras}\n\\end{description}\n}\n\\cvarg{numberOfDisparities}{The number of disparities. If the parameter is 0, it is taken from the preset, otherwise the supplied value overrides the one from preset.}\n\\end{description}\n\nThe function creates the stereo correspondence structure and initializes\nit. It is possible to override any of the parameters at any time between\nthe calls to \\cvCPyCross{FindStereoCorrespondenceBM}.\n\n\\cvCPyFunc{CreateStereoGCState}\nCreates the state of graph cut-based stereo correspondence algorithm.\n\n\\cvdefC{\n\nCvStereoGCState* cvCreateStereoGCState( int numberOfDisparities,\n                                        int maxIters );\n\n}\n\\cvdefPy{CreateStereoGCState(numberOfDisparities,maxIters)-> StereoGCState}\n\n\\begin{description}\n\\cvarg{numberOfDisparities}{The number of disparities. The disparity search range will be $\\texttt{state->minDisparity} \\le disparity < \\texttt{state->minDisparity} + \\texttt{state->numberOfDisparities}$}\n\\cvarg{maxIters}{Maximum number of iterations. On each iteration all possible (or reasonable) alpha-expansions are tried. The algorithm may terminate earlier if it could not find an alpha-expansion that decreases the overall cost function value. See \\cite{Kolmogorov03}  for details. }\n\\end{description}\n\nThe function creates the stereo correspondence structure and initializes it. It is possible to override any of the parameters at any time between the calls to \\cvCPyCross{FindStereoCorrespondenceGC}.\n\n\\cvclass{CvStereoBMState}\nThe structure for block matching stereo correspondence algorithm.\n\n\\ifC\n\\begin{lstlisting}\ntypedef struct CvStereoBMState\n{\n    //pre filters (normalize input images):\n    int       preFilterType; // 0 for now\n    int       preFilterSize; // ~5x5..21x21\n    int       preFilterCap;  // up to ~31\n    //correspondence using Sum of Absolute Difference (SAD):\n    int       SADWindowSize; // Could be 5x5..21x21\n    int       minDisparity;  // minimum disparity (=0)\n    int       numberOfDisparities; // maximum disparity - minimum disparity\n    //post filters (knock out bad matches):\n    int       textureThreshold; // areas with no texture are ignored\n    int       uniquenessRatio;// invalidate disparity at pixels where there are other close matches\n                              // with different disparity\n    int       speckleWindowSize; // the maximum area of speckles to remove\n                                 // (set to 0 to disable speckle filtering)\n    int       speckleRange; // acceptable range of disparity variation in each connected component\n    \n    int trySmallerWindows; // not used \n    CvRect roi1, roi2; // clipping ROIs\n    \n    int disp12MaxDiff; // maximum allowed disparity difference in the left-right check \n    \n    // internal data\n    ...\n}\nCvStereoBMState;\n\\end{lstlisting}\n\\fi\n\\begin{description}\n\\cvarg{preFilterType}{type of the prefilter, \\texttt{CV\\_STEREO\\_BM\\_NORMALIZED\\_RESPONSE} or the default and the recommended \\texttt{CV\\_STEREO\\_BM\\_XSOBEL}, int}\n\\cvarg{preFilterSize}{~5x5..21x21, int}\n\\cvarg{preFilterCap}{up to ~31, int}\n\\cvarg{SADWindowSize}{Could be 5x5..21x21 or higher, but with 21x21 or smaller windows the processing speed is much higher, int}\n\\cvarg{minDisparity}{minimum disparity (=0), int}\n\\cvarg{numberOfDisparities}{maximum disparity - minimum disparity, int}\n\\cvarg{textureThreshold}{the textureness threshold. That is, if the sum of absolute values of x-derivatives computed over \\texttt{SADWindowSize} by \\texttt{SADWindowSize} pixel neighborhood is smaller than the parameter, no disparity is computed at the pixel, int}\n\\cvarg{uniquenessRatio}{the minimum margin in percents between the best (minimum) cost function value and the second best value to accept the computed disparity, int}\n\\cvarg{speckleWindowSize}{the maximum area of speckles to remove (set to 0 to disable speckle filtering), int}\n\\cvarg{speckleRange}{acceptable range of disparity variation in each connected component, int}\n\\cvarg{trySmallerWindows}{not used currently (0), int}\n\\cvarg{roi1, roi2}{These are the clipping ROIs for the left and the right images. The function \\cvCPyCross{StereoRectify} returns the largest rectangles in the left and right images where after the rectification all the pixels are valid. If you copy those rectangles to the \\texttt{CvStereoBMState} structure, the stereo correspondence function will automatically clear out the pixels outside of the \"valid\" disparity rectangle computed by \\cvCPyCross{GetValidDisparityROI}. Thus you will get more \"invalid disparity\" pixels than usual, but the remaining pixels are more probable to be valid.}\n\\cvarg{disp12MaxDiff}{The maximum allowed difference between the explicitly computed left-to-right disparity map and the implicitly (by \\cvCPyCross{ValidateDisparity}) computed right-to-left disparity. If for some pixel the difference is larger than the specified threshold, the disparity at the pixel is invalidated. By default this parameter is set to (-1), which means that the left-right check is not performed.}\n\\end{description}\n\n\nThe block matching stereo correspondence algorithm, by Kurt Konolige, is very fast single-pass stereo matching algorithm that uses sliding sums of absolute differences between pixels in the left image and the pixels in the right image, shifted by some varying amount of pixels (from \\texttt{minDisparity} to \\texttt{minDisparity+numberOfDisparities}). On a pair of images WxH the algorithm computes disparity in \\texttt{O(W*H*numberOfDisparities)} time. In order to improve quality and readability of the disparity map, the algorithm includes pre-filtering and post-filtering procedures.\n\nNote that the algorithm searches for the corresponding blocks in x direction only. It means that the supplied stereo pair should be rectified. Vertical stereo layout is not directly supported, but in such a case the images could be transposed by user.\n\n\\cvclass{CvStereoGCState}\nThe structure for graph cuts-based stereo correspondence algorithm\n\n\\ifC\n\\begin{lstlisting}\ntypedef struct CvStereoGCState\n{\n    int Ithreshold; // threshold for piece-wise linear data cost function (5 by default)\n    int interactionRadius; // radius for smoothness cost function (1 by default; means Potts model)\n    float K, lambda, lambda1, lambda2; // parameters for the cost function\n                                       // (usually computed adaptively from the input data)\n    int occlusionCost; // 10000 by default\n    int minDisparity; // 0 by default; see CvStereoBMState\n    int numberOfDisparities; // defined by user; see CvStereoBMState\n    int maxIters; // number of iterations; defined by user.\n\n    // internal buffers\n    CvMat* left;\n    CvMat* right;\n    CvMat* dispLeft;\n    CvMat* dispRight;\n    CvMat* ptrLeft;\n    CvMat* ptrRight;\n    CvMat* vtxBuf;\n    CvMat* edgeBuf;\n}\nCvStereoGCState;\n\\end{lstlisting}\n\\else\n\\begin{description}\n\\cvarg{Ithreshold}{threshold for piece-wise linear data cost function (5 by default)}\n\\cvarg{interactionRadius}{radius for smoothness cost function (1 by default; means Potts model)}\n\\cvarg{K, lambda, lambda1, lambda2}{parameters for the cost function (usually computed adaptively from the input data)}\n\\cvarg{occlusionCost}{10000 by default}\n\\cvarg{minDisparity}{0 by default; see \\cross{CvStereoBMState}}\n\\cvarg{numberOfDisparities}{defined by user; see \\cross{CvStereoBMState}}\n\\cvarg{maxIters}{number of iterations; defined by user.}\n\\end{description}\n\\fi\n\nThe graph cuts stereo correspondence algorithm, described in \\cite{Kolmogorov03} (as \\textbf{KZ1}), is non-realtime stereo correspondence algorithm that usually gives very accurate depth map with well-defined object boundaries. The algorithm represents stereo problem as a sequence of binary optimization problems, each of those is solved using maximum graph flow algorithm. The state structure above should not be allocated and initialized manually; instead, use \\cvCPyCross{CreateStereoGCState} and then override necessary parameters if needed.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{DecomposeProjectionMatrix}\n\\else\n\\cvCppFunc{decomposeProjectionMatrix}\n\\fi\nDecomposes the projection matrix into a rotation matrix and a camera matrix.\n\n\\cvdefC{\nvoid cvDecomposeProjectionMatrix( \\par const CvMat *projMatrix,\\par CvMat *cameraMatrix,\\par CvMat *rotMatrix,\\par CvMat *transVect,\\par CvMat *rotMatrX=NULL,\\par CvMat *rotMatrY=NULL,\\par CvMat *rotMatrZ=NULL,\\par CvPoint3D64f *eulerAngles=NULL);\n}\n\n\\cvdefPy{DecomposeProjectionMatrix(projMatrix, cameraMatrix, rotMatrix, transVect, rotMatrX = None, rotMatrY = None, rotMatrZ = None) -> eulerAngles}\n\n\\cvdefCpp{void decomposeProjectionMatrix( const Mat\\& projMatrix,\\par\n                                Mat\\& cameraMatrix,\\par\n                                Mat\\& rotMatrix, Mat\\& transVect );\\newline\nvoid decomposeProjectionMatrix( const Mat\\& projMatrix, \\par\n                                Mat\\& cameraMatrix,\\par\n                                Mat\\& rotMatrix, Mat\\& transVect,\\par\n                                Mat\\& rotMatrixX, Mat\\& rotMatrixY,\\par\n                                Mat\\& rotMatrixZ, Vec3d\\& eulerAngles );}\n\\begin{description}\n\\cvarg{projMatrix}{The 3x4 input projection matrix P}\n\\cvarg{cameraMatrix}{The output 3x3 camera matrix K}\n\\cvarg{rotMatrix}{The output 3x3 external rotation matrix R}\n\\cvarg{transVect}{The output 4x1 translation vector T}\n\\cvarg{rotMatrX}{Optional 3x3 rotation matrix around x-axis}\n\\cvarg{rotMatrY}{Optional 3x3 rotation matrix around y-axis}\n\\cvarg{rotMatrZ}{Optional 3x3 rotation matrix around z-axis}\n\\cvarg{eulerAngles}{Optional 3 points containing the three Euler angles of rotation}\n\\end{description}\n\nThe function computes a decomposition of a projection matrix into a calibration and a rotation matrix and the position of the camera.\n\nIt optionally returns three rotation matrices, one for each axis, and the three Euler angles that could be used in OpenGL.\n\nThe function is based on \\cvCross{RQDecomp3x3}{RQDecomp3x3}.\n\n\\ifCPy\n\\cvCPyFunc{DrawChessboardCorners}\n\\else\n\\cvCppFunc{drawChessboardCorners}\n\\fi\nRenders the detected chessboard corners.\n\n\\cvdefC{\nvoid cvDrawChessboardCorners( \\par CvArr* image,\\par CvSize patternSize,\\par CvPoint2D32f* corners,\\par int count,\\par int patternWasFound );\n}\\cvdefPy{DrawChessboardCorners(image,patternSize,corners,patternWasFound)-> None}\n\\cvdefCpp{void drawChessboardCorners( Mat\\& image, Size patternSize,\\par\n                            const Mat\\& corners,\\par\n                            bool patternWasFound );}\n\\begin{description}\n\\cvarg{image}{The destination image; it must be an 8-bit color image}\n\\cvarg{patternSize}{The number of inner corners per chessboard row and column. (patternSize = cv::Size(points\\_per\\_row,points\\_per\\_column) = cv::Size(rows,columns) )}\n\\cvarg{corners}{The array of corners detected, this should be the output from findChessboardCorners wrapped in a cv::Mat().}\n\\cvC{\\cvarg{count}{The number of corners}}\n\\cvarg{patternWasFound}{Indicates whether the complete board was found \\cvCPy{$(\\ne 0)$} or not \\cvCPy{$(=0)$}. One may just pass the return value \\cvCPyCross{FindChessboardCorners}{findChessboardCorners} here}\n\\end{description}\n\nThe function draws the individual chessboard corners detected as red circles if the board was not found or as colored corners connected with lines if the board was found.\n\n\\ifCPy\n\\cvCPyFunc{FindChessboardCorners}\n\\else\n\\cvCppFunc{findChessboardCorners}\n\\fi\nFinds the positions of the internal corners of the chessboard.\n\n\\cvdefC{int cvFindChessboardCorners( \\par const void* image,\\par CvSize patternSize,\\par CvPoint2D32f* corners,\\par int* cornerCount=NULL,\\par int flags=CV\\_CALIB\\_CB\\_ADAPTIVE\\_THRESH );}\n\\cvdefPy{FindChessboardCorners(image, patternSize, flags=CV\\_CALIB\\_CB\\_ADAPTIVE\\_THRESH) -> corners}\n\\cvdefCpp{bool findChessboardCorners( const Mat\\& image, Size patternSize,\\par\n                            vector<Point2f>\\& corners,\\par\n                            int flags=CV\\_CALIB\\_CB\\_ADAPTIVE\\_THRESH+\\par\n                                 CV\\_CALIB\\_CB\\_NORMALIZE\\_IMAGE );}\n\\begin{description}\n\\cvarg{image}{Source chessboard view; it must be an 8-bit grayscale or color image}\n\\cvarg{patternSize}{The number of inner corners per chessboard row and column\n( patternSize = cvSize(points\\_per\\_row,points\\_per\\_colum) = cvSize(columns,rows) )}\n\\cvarg{corners}{The output array of corners detected}\n\\cvC{\\cvarg{cornerCount}{The output corner counter. If it is not NULL, it stores the number of corners found}}\n\\cvarg{flags}{Various operation flags, can be 0 or a combination of the following values:\n\\begin{description}\n \\cvarg{CV\\_CALIB\\_CB\\_ADAPTIVE\\_THRESH}{use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).}\n \\cvarg{CV\\_CALIB\\_CB\\_NORMALIZE\\_IMAGE}{normalize the image gamma with \\cvCross{EqualizeHist}{equalizeHist} before applying fixed or adaptive thresholding.}\n \\cvarg{CV\\_CALIB\\_CB\\_FILTER\\_QUADS}{use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads that are extracted at the contour retrieval stage.}\n \\cvarg{CALIB\\_CB\\_FAST\\_CHECK}{Runs a fast check on the image that looks for chessboard corners, and shortcuts the call if none are found. This can drastically speed up the call in the degenerate condition when\n no chessboard is observed.}\n\\end{description}}\n\\end{description}\n\nThe function attempts to determine\nwhether the input image is a view of the chessboard pattern and\nlocate the internal chessboard corners. The function returns a non-zero\nvalue if all of the corners have been found and they have been placed\nin a certain order (row by row, left to right in every row),\notherwise, if the function fails to find all the corners or reorder\nthem, it returns 0. For example, a regular chessboard has 8 x 8\nsquares and 7 x 7 internal corners, that is, points, where the black\nsquares touch each other. The coordinates detected are approximate,\nand to determine their position more accurately, the user may use\nthe function \\cvCross{FindCornerSubPix}{cornerSubPix}.\n\nSample usage of detecting and drawing chessboard corners:\n\\begin{lstlisting}\nSize patternsize(8,6); //interior number of corners\nMat gray = ....; //source image\nvector<Point2f> corners; //this will be filled by the detected corners\n\n//CALIB_CB_FAST_CHECK saves a lot of time on images \n//that don't contain any chessboard corners\nbool patternfound = findChessboardCorners(gray, patternsize, corners, \n\tCALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE \n\t+ CALIB_CB_FAST_CHECK);\n\nif(patternfound)\n  cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), \n    TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));\n    \ndrawChessboardCorners(img, patternsize, Mat(corners), patternfound);\n\\end{lstlisting}\n\n\\textbf{Note:} the function requires some white space (like a square-thick border, the wider the better) around the board to make the detection more robust in various environment (otherwise if there is no border and the background is dark, the outer black squares could not be segmented properly and so the square grouping and ordering algorithm will fail).\n\n\\ifCPy\n\\cvCPyFunc{FindExtrinsicCameraParams2}\n\\else\n\\cvCppFunc{solvePnP}\n\\fi\nFinds the object pose from the 3D-2D point correspondences\n\n\\cvdefC{void cvFindExtrinsicCameraParams2( \\par const CvMat* objectPoints,\\par const CvMat* imagePoints,\\par const CvMat* cameraMatrix,\\par const CvMat* distCoeffs,\\par CvMat* rvec,\\par CvMat* tvec, \\par int useExtrinsicGuess=0);}\n\\cvdefPy{FindExtrinsicCameraParams2(objectPoints,imagePoints,cameraMatrix,distCoeffs,rvec,tvec,useExtrinsicGuess=0)-> None}\n\\cvdefCpp{void solvePnP( const Mat\\& objectPoints,\\par\n               const Mat\\& imagePoints,\\par\n               const Mat\\& cameraMatrix,\\par\n               const Mat\\& distCoeffs,\\par\n               Mat\\& rvec, Mat\\& tvec,\\par\n               bool useExtrinsicGuess=false );}\n\\begin{description}\n\\cvarg{objectPoints}{The array of object points in the object coordinate space, 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel, where N is the number of points. \\cvCpp{Can also pass \\texttt{vector<Point3f>} here.}}\n\\cvarg{imagePoints}{The array of corresponding image points, 2xN or Nx2 1-channel or 1xN or Nx1 2-channel, where N is the number of points. \\cvCpp{Can also pass \\texttt{vector<Point2f>} here.}}\n\\cvarg{cameraMatrix}{The input camera matrix $A = \\vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{rvec}{The output rotation vector (see \\cvCross{Rodrigues2}{Rodrigues}) that (together with \\texttt{tvec}) brings points from the model coordinate system to the camera coordinate system}\n\\cvarg{tvec}{The output translation vector}\n\\cvarg{useExtrinsicGuess}{If true (1), the function will use the provided \\texttt{rvec} and \\texttt{tvec} as the initial approximations of the rotation and translation vectors, respectively, and will further optimize them.}\n\\end{description}\n\nThe function estimates the object pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients. This function finds such a pose that minimizes reprojection error, i.e. the sum of squared distances between the observed projections \\texttt{imagePoints} and the projected (using \\cvCross{ProjectPoints2}{projectPoints}) \\texttt{objectPoints}.\n\n\n\\ifCPy\nThe function's counterpart in the C++ API is \\hyperref[cppfunc.solvePnP]{cv::solvePnP}\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{FindFundamentalMat}\n\\else\n\\cvCppFunc{findFundamentalMat}\n\\fi\n\nCalculates the fundamental matrix from the corresponding points in two images.\n\n\\cvdefC{\nint cvFindFundamentalMat( \\par const CvMat* points1,\\par const CvMat* points2,\\par CvMat* fundamentalMatrix,\\par int    method=CV\\_FM\\_RANSAC,\\par double param1=1.,\\par double param2=0.99,\\par CvMat* status=NULL);\n}\n\\cvdefPy{FindFundamentalMat(points1, points2, fundamentalMatrix, method=CV\\_FM\\_RANSAC, param1=1., param2=0.99, status = None) -> None}\n\\cvdefCpp{Mat findFundamentalMat( const Mat\\& points1, const Mat\\& points2,\\par\n                        vector<uchar>\\& status, int method=FM\\_RANSAC,\\par\n                        double param1=3., double param2=0.99 );\\newline\nMat findFundamentalMat( const Mat\\& points1, const Mat\\& points2,\\par\n                        int method=FM\\_RANSAC,\\par\n                        double param1=3., double param2=0.99 );}\n\\begin{description}\n\\cvarg{points1}{Array of \\texttt{N} points from the first image.\\cvCPy{It can be \\texttt{2xN, Nx2, 3xN} or \\texttt{Nx3} 1-channel array or  \\texttt{1xN} or \\texttt{Nx1} 2- or 3-channel array}. The point coordinates should be floating-point (single or double precision)}\n\\cvarg{points2}{Array of the second image points of the same size and format as \\texttt{points1}}\n\\cvCPy{\\cvarg{fundamentalMatrix}{The output fundamental matrix or matrices. The size should be 3x3 or 9x3 (7-point method may return up to 3 matrices)}}\n\\cvarg{method}{Method for computing the fundamental matrix\n\\begin{description}\n  \\cvarg{CV\\_FM\\_7POINT}{for a 7-point algorithm. $N = 7$}\n  \\cvarg{CV\\_FM\\_8POINT}{for an 8-point algorithm. $N \\ge 8$}\n  \\cvarg{CV\\_FM\\_RANSAC}{for the RANSAC algorithm. $N \\ge 8$}\n  \\cvarg{CV\\_FM\\_LMEDS}{for the LMedS algorithm. $N \\ge 8$}\n\\end{description}}\n\\cvarg{param1}{The parameter is used for RANSAC. It is the maximum distance from point to epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution and the image noise}\n\\cvarg{param2}{The parameter is used for RANSAC or LMedS methods only. It specifies the desirable level of confidence (probability) that the estimated matrix is correct}\n\\cvarg{status}{The \\cvCPy{optional} output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in RANSAC and LMedS methods. For other methods it is set to all 1's}\n\\end{description}\n\nThe epipolar geometry is described by the following equation:\n\n\\[ [p_2; 1]^T F [p_1; 1] = 0 \\]\n\nwhere $F$ is fundamental matrix, $p_1$ and $p_2$ are corresponding points in the first and the second images, respectively.\n\nThe function calculates the fundamental matrix using one of four methods listed above and returns \\cvCpp{the found fundamental matrix}\\cvCPy{the number of fundamental matrices found (1 or 3) and 0, if no matrix is found}. Normally just 1 matrix is found, but in the case of 7-point algorithm the function may return up to 3 solutions ($9 \\times 3$ matrix that stores all 3 matrices sequentially).\n\nThe calculated fundamental matrix may be passed further to\n\\cvCross{ComputeCorrespondEpilines}{computeCorrespondEpilines} that finds the epipolar lines\ncorresponding to the specified points. It can also be passed to \\cvCross{StereoRectifyUncalibrated}{stereoRectifyUncalibrated} to compute the rectification transformation.\n\n\\ifC\n% Example. Estimation of fundamental matrix using RANSAC algorithm\n\\begin{lstlisting}\nint point_count = 100;\nCvMat* points1;\nCvMat* points2;\nCvMat* status;\nCvMat* fundamental_matrix;\n\npoints1 = cvCreateMat(1,point_count,CV_32FC2);\npoints2 = cvCreateMat(1,point_count,CV_32FC2);\nstatus = cvCreateMat(1,point_count,CV_8UC1);\n\n/* Fill the points here ... */\nfor( i = 0; i < point_count; i++ )\n{\n    points1->data.fl[i*2] = <x,,1,i,,>;\n    points1->data.fl[i*2+1] = <y,,1,i,,>;\n    points2->data.fl[i*2] = <x,,2,i,,>;\n    points2->data.fl[i*2+1] = <y,,2,i,,>;\n}\n\nfundamental_matrix = cvCreateMat(3,3,CV_32FC1);\nint fm_count = cvFindFundamentalMat( points1,points2,fundamental_matrix,\n                                     CV_FM_RANSAC,1.0,0.99,status );\n\\end{lstlisting}\n\\fi\n\\ifCpp\n\\begin{lstlisting}\n// Example. Estimation of fundamental matrix using RANSAC algorithm\nint point_count = 100;\nvector<Point2f> points1(point_count);\nvector<Point2f> points2(point_count);\n\n// initialize the points here ... */\nfor( int i = 0; i < point_count; i++ )\n{\n    points1[i] = ...;\n    points2[i] = ...;\n}\n\nMat fundamental_matrix =\n findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);\n\\end{lstlisting}\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{FindHomography}\n\\else\n\\cvCppFunc{findHomography}\n\\fi\nFinds the perspective transformation between two planes.\n\n\\cvdefC{void cvFindHomography( \\par const CvMat* srcPoints,\\par const CvMat* dstPoints,\\par CvMat* H \\par\nint method=0, \\par double ransacReprojThreshold=3, \\par CvMat* status=NULL);}\n\\cvdefPy{FindHomography(srcPoints,dstPoints,H,method,ransacReprojThreshold=3.0, status=None)-> None}\n\\cvdefCpp{Mat findHomography( const Mat\\& srcPoints, const Mat\\& dstPoints,\\par\n                    Mat\\& status, int method=0,\\par\n                    double ransacReprojThreshold=3 );\\newline\nMat findHomography( const Mat\\& srcPoints, const Mat\\& dstPoints,\\par\n                    vector<uchar>\\& status, int method=0,\\par\n                    double ransacReprojThreshold=3 );\\newline\nMat findHomography( const Mat\\& srcPoints, const Mat\\& dstPoints,\\par\n                    int method=0, double ransacReprojThreshold=3 );}\n\\begin{description}\n\n\\cvCPy{\\cvarg{srcPoints}{Coordinates of the points in the original plane, 2xN, Nx2, 3xN or Nx3 1-channel array (the latter two are for representation in homogeneous coordinates), where N is the number of points. 1xN or Nx1 2- or 3-channel array can also be passed.}\n\\cvarg{dstPoints}{Point coordinates in the destination plane, 2xN, Nx2, 3xN or Nx3 1-channel, or 1xN or Nx1 2- or 3-channel array.}}\n\\cvCpp{\\cvarg{srcPoints}{Coordinates of the points in the original plane, a matrix of type \\texttt{CV\\_32FC2} or a \\texttt{vector<Point2f>}.}\n\\cvarg{dstPoints}{Coordinates of the points in the target plane, a matrix of type \\texttt{CV\\_32FC2} or a \\texttt{vector<Point2f>}.}}\n\n\\cvCPy{\\cvarg{H}{The output 3x3 homography matrix}}\n\\cvarg{method}{ The method used to computed homography matrix; one of the following:\n\\begin{description}\n\\cvarg{0}{a regular method using all the points}\n\\cvarg{CV\\_RANSAC}{RANSAC-based robust method}\n\\cvarg{CV\\_LMEDS}{Least-Median robust method}\n\\end{description}}\n\\cvarg{ransacReprojThreshold}{The maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). That is, if\n\\[\\|\\texttt{dstPoints}_i - \\texttt{convertPointsHomogeneous}(\\texttt{H} \\texttt{srcPoints}_i)\\| > \\texttt{ransacReprojThreshold}\\]\nthen the point $i$ is considered an outlier. If \\texttt{srcPoints} and \\texttt{dstPoints} are measured in pixels, it usually makes sense to set this parameter somewhere in the range 1 to 10.}\n\\cvarg{status}{The optional output mask set by a robust method (\\texttt{CV\\_RANSAC} or \\texttt{CV\\_LMEDS}). \\emph{Note that the input mask values are ignored.}}\n\\end{description}\n\nThe \\cvCPy{function finds}\\cvCpp{functions find and return} the perspective transformation $H$ between the source and the destination planes:\n\n\\[\ns_i \\vecthree{x'_i}{y'_i}{1} \\sim H \\vecthree{x_i}{y_i}{1}\n\\]\n\nSo that the back-projection error\n\n\\[\n\\sum_i\n\\left( x'_i-\\frac{h_{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \\right)^2+\n\\left( y'_i-\\frac{h_{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \\right)^2\n\\]\n\nis minimized. If the parameter \\texttt{method} is set to the default value 0, the function\nuses all the point pairs to compute the initial homography estimate with a simple least-squares scheme.\n\nHowever, if not all of the point pairs ($srcPoints_i$,\n$dstPoints_i$) fit the rigid perspective transformation (i.e. there\nare some outliers), this initial estimate will be poor.\nIn this case one can use one of the 2 robust methods. Both methods,\n\\texttt{RANSAC} and \\texttt{LMeDS}, try many different random subsets\nof the corresponding point pairs (of 4 pairs each), estimate\nthe homography matrix using this subset and a simple least-square\nalgorithm and then compute the quality/goodness of the computed homography\n(which is the number of inliers for RANSAC or the median re-projection\nerror for LMeDs). The best subset is then used to produce the initial\nestimate of the homography matrix and the mask of inliers/outliers.\n\nRegardless of the method, robust or not, the computed homography\nmatrix is refined further (using inliers only in the case of a robust\nmethod) with the Levenberg-Marquardt method in order to reduce the\nre-projection error even more.\n\nThe method \\texttt{RANSAC} can handle practically any ratio of outliers,\nbut it needs the threshold to distinguish inliers from outliers.\nThe method \\texttt{LMeDS} does not need any threshold, but it works\ncorrectly only when there are more than 50\\% of inliers. Finally,\nif you are sure in the computed features, where can be only some\nsmall noise present, but no outliers, the default method could be the best\nchoice.\n\nThe function is used to find initial intrinsic and extrinsic matrices.\nHomography matrix is determined up to a scale, thus it is normalized so that\n$h_{33}=1$.\n\nSee also: \\cvCross{GetAffineTransform}{getAffineTransform}, \\cvCross{GetPerspectiveTransform}{getPerspectiveTransform}, \\cvCross{EstimateRigidMotion}{estimateRigidMotion}, \\cvCross{WarpPerspective}{warpPerspective}, \\cvCross{PerspectiveTransform}{perspectiveTransform}\n\n\\ifCPy\n\n\\cvCPyFunc{FindStereoCorrespondenceBM}\nComputes the disparity map using block matching algorithm.\n\n\\cvdefC{\n\nvoid cvFindStereoCorrespondenceBM( \\par const CvArr* left, \\par const CvArr* right,\n                                   \\par CvArr* disparity, \\par CvStereoBMState* state );\n\n}\\cvdefPy{FindStereoCorrespondenceBM(left,right,disparity,state)-> None}\n\n\\begin{description}\n\\cvarg{left}{The left single-channel, 8-bit image.}\n\\cvarg{right}{The right image of the same size and the same type.}\n\\cvarg{disparity}{The output single-channel 16-bit signed, or 32-bit floating-point disparity map of the same size as input images. In the first case the computed disparities are represented as fixed-point numbers with 4 fractional bits (i.e. the computed disparity values are multiplied by 16 and rounded to integers).}\n\\cvarg{state}{Stereo correspondence structure.}\n\\end{description}\n\nThe function cvFindStereoCorrespondenceBM computes disparity map for the input rectified stereo pair. Invalid pixels (for which disparity can not be computed) are set to \\texttt{state->minDisparity - 1} (or to \\texttt{(state->minDisparity-1)*16} in the case of 16-bit fixed-point disparity map)\n\n\\cvCPyFunc{FindStereoCorrespondenceGC}\nComputes the disparity map using graph cut-based algorithm.\n\n\\cvdefC{\n\nvoid cvFindStereoCorrespondenceGC( \\par const CvArr* left, \\par const CvArr* right,\n                                   \\par CvArr* dispLeft, \\par CvArr* dispRight,\n                                   \\par CvStereoGCState* state,\n                                   \\par int useDisparityGuess = CV\\_DEFAULT(0) );\n\n}\n\\cvdefPy{FindStereoCorrespondenceGC( left, right, dispLeft, dispRight, state, useDisparityGuess=(0))-> None}\n\n\\begin{description}\n\\cvarg{left}{The left single-channel, 8-bit image.}\n\\cvarg{right}{The right image of the same size and the same type.}\n\\cvarg{dispLeft}{The optional output single-channel 16-bit signed left disparity map of the same size as input images.}\n\\cvarg{dispRight}{The optional output single-channel 16-bit signed right disparity map of the same size as input images.}\n\\cvarg{state}{Stereo correspondence structure.}\n\\cvarg{useDisparityGuess}{If the parameter is not zero, the algorithm will start with pre-defined disparity maps. Both dispLeft and dispRight should be valid disparity maps. Otherwise, the function starts with blank disparity maps (all pixels are marked as occlusions).}\n\\end{description}\n\nThe function computes disparity maps for the input rectified stereo pair. Note that the left disparity image will contain values in the following range: \n\n\\[\n-\\texttt{state->numberOfDisparities}-\\texttt{state->minDisparity}\n< dispLeft(x,y) \\le -\\texttt{state->minDisparity},\n\\]\n\nor\n\\[\ndispLeft(x,y) == \\texttt{CV\\_STEREO\\_GC\\_OCCLUSION}\n\\]\n\nand for the right disparity image the following will be true: \n\n\\[\n\\texttt{state->minDisparity} \\le dispRight(x,y) \n< \\texttt{state->minDisparity} + \\texttt{state->numberOfDisparities}\n\\]\n\nor\n\n\\[\ndispRight(x,y) == \\texttt{CV\\_STEREO\\_GC\\_OCCLUSION}\n\\]\n\nthat is, the range for the left disparity image will be inversed,\nand the pixels for which no good match has been found, will be marked\nas occlusions.\n\nHere is how the function can be used:\n\n\\ifC\n\\begin{lstlisting}\n// image_left and image_right are the input 8-bit single-channel images\n// from the left and the right cameras, respectively\nCvSize size = cvGetSize(image_left);\nCvMat* disparity_left = cvCreateMat( size.height, size.width, CV_16S );\nCvMat* disparity_right = cvCreateMat( size.height, size.width, CV_16S );\nCvStereoGCState* state = cvCreateStereoGCState( 16, 2 );\ncvFindStereoCorrespondenceGC( image_left, image_right,\n    disparity_left, disparity_right, state, 0 );\ncvReleaseStereoGCState( &state );\n// now process the computed disparity images as you want ...\n\\end{lstlisting}\n\nand this is the output left disparity image computed from the well-known\nTsukuba stereo pair and multiplied by -16 (because the values in the\nleft disparity images are usually negative):\n\n\\begin{lstlisting}\nCvMat* disparity_left_visual = cvCreateMat( size.height, size.width, CV_8U );\ncvConvertScale( disparity_left, disparity_left_visual, -16 );\ncvSave( \"disparity.pgm\", disparity_left_visual );\n\\end{lstlisting}\n\n\\includegraphics{pics/disparity.png}\n\n\\else\n\n\\lstinputlisting{python_fragments/findstereocorrespondence.py}\n\nand this is the output left disparity image computed from the well-known\nTsukuba stereo pair and multiplied by -16 (because the values in the\nleft disparity images are usually negative):\n\n\\includegraphics{pics/disparity.png}\n\n\\fi\n\n\\fi\n\n\\ifCpp\n\\cvCppFunc{getDefaultNewCameraMatrix}\nReturns the default new camera matrix\n\n\\cvdefCpp{Mat getDefaultNewCameraMatrix(\\par\n                               const Mat\\& cameraMatrix,\\par\n                               Size imgSize=Size(),\\par\n                               bool centerPrincipalPoint=false );}\n\\begin{description}\n\\cvarg{cameraMatrix}{The input camera matrix}\n\\cvarg{imageSize}{The camera view image size in pixels}\n\\cvarg{centerPrincipalPoint}{Indicates whether in the new camera matrix the principal point should be at the image center or not}\n\\end{description}\n\nThe function returns the camera matrix that is either an exact copy of the input \\texttt{cameraMatrix} (when \\texttt{centerPrinicipalPoint=false}), or the modified one (when \\texttt{centerPrincipalPoint}=true).\n\nIn the latter case the new camera matrix will be:\n\n\\[\\begin{bmatrix}\nf_x && 0 && (\\texttt{imgSize.width}-1)*0.5 \\\\\n0 && f_y && (\\texttt{imgSize.height}-1)*0.5 \\\\\n0 && 0 && 1\n\\end{bmatrix},\\]\n\nwhere $f_x$ and $f_y$ are $(0,0)$ and $(1,1)$ elements of \\texttt{cameraMatrix}, respectively.\n\nBy default, the undistortion functions in OpenCV (see \\texttt{initUndistortRectifyMap}, \\texttt{undistort}) do not move the principal point. However, when you work with stereo, it's important to move the principal points in both views to the same y-coordinate (which is required by most of stereo correspondence algorithms), and maybe to the same x-coordinate too. So you can form the new camera matrix for each view, where the principal points will be at the center.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{GetOptimalNewCameraMatrix}\n\\else\n\\cvCppFunc{getOptimalNewCameraMatrix}\n\\fi\nReturns the new camera matrix based on the free scaling parameter\n\n\\cvdefC{void cvGetOptimalNewCameraMatrix(\n    \\par const CvMat* cameraMatrix, const CvMat* distCoeffs,\n    \\par CvSize imageSize, double alpha,\n    \\par CvMat* newCameraMatrix,\n    \\par CvSize newImageSize=cvSize(0,0),\n    \\par CvRect* validPixROI=0 );}\n\\cvdefPy{GetOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, alpha, newCameraMatrix, newImageSize=(0,0), validPixROI=0) -> None}\n\\cvdefCpp{Mat getOptimalNewCameraMatrix(\n    \\par const Mat\\& cameraMatrix, const Mat\\& distCoeffs,\n    \\par Size imageSize, double alpha, Size newImageSize=Size(),\n    \\par Rect* validPixROI=0);}\n    \n\\begin{description}\n\\cvarg{cameraMatrix}{The input camera matrix}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{imageSize}{The original image size}\n\\cvarg{alpha}{The free scaling parameter between 0 (when all the pixels in the undistorted image will be valid) and 1 (when all the source image pixels will be retained in the undistorted image); see \\cvCross{StereoRectify}{stereoRectify}}\n\\cvarg{newCameraMatrix}{The output new camera matrix.}\n\\cvarg{newImageSize}{The image size after rectification. By default it will be set to \\texttt{imageSize}.}\n\\cvarg{validPixROI}{The optional output rectangle that will outline all-good-pixels region in the undistorted image. See \\texttt{roi1, roi2} description in \\cvCross{StereoRectify}{stereoRectify}}\n\\end{description}\n\nThe function computes \\cvCpp{and returns} the optimal new camera matrix based on the free scaling parameter. By varying  this parameter the user may retrieve only sensible pixels \\texttt{alpha=0}, keep all the original image pixels if there is valuable information in the corners \\texttt{alpha=1}, or get something in between. When \\texttt{alpha>0}, the undistortion result will likely have some black pixels corresponding to \"virtual\" pixels outside of the captured distorted image. The original camera matrix, distortion coefficients, the computed new camera matrix and the \\texttt{newImageSize} should be passed to \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} to produce the maps for \\cvCross{Remap}{remap}.\n\n\\ifCPy\n\\cvCPyFunc{InitIntrinsicParams2D}\n\\else\n\\cvCppFunc{initCameraMatrix2D}\n\\fi\n\nFinds the initial camera matrix from the 3D-2D point correspondences\n\n\\cvdefC{void cvInitIntrinsicParams2D(\\par const CvMat* objectPoints,\n                                     \\par const CvMat* imagePoints,\n                                     \\par const CvMat* npoints, CvSize imageSize,\n                                     \\par CvMat* cameraMatrix,\n                                     \\par double aspectRatio=1.);}                                     \n\\cvdefPy{InitIntrinsicParams2D(objectPoints, imagePoints, npoints, imageSize, cameraMatrix, aspectRatio=1.) -> None}\n\\cvdefCpp{Mat initCameraMatrix2D( const vector<vector<Point3f> >\\& objectPoints,\\par\n                        const vector<vector<Point2f> >\\& imagePoints,\\par\n                        Size imageSize, double aspectRatio=1.);}\n\\begin{description}\n\\ifCPy\n\\cvarg{objectPoints}{The joint array of object points; see \\cvCross{CalibrateCamera2}{calibrateCamera}}\n\\cvarg{imagePoints}{The joint array of object point projections; see \\cvCross{CalibrateCamera2}{calibrateCamera}}\n\\cvarg{npoints}{The array of point counts; see \\cvCross{CalibrateCamera2}{calibrateCamera}}\n\\fi    \n\\ifCpp\n\\cvarg{objectPoints}{The vector of vectors of the object points. See \\cvCppCross{calibrateCamera}}\n\\cvarg{imagePoints}{The vector of vectors of the corresponding image points. See \\cvCppCross{calibrateCamera}}\n\\fi\n\\cvarg{imageSize}{The image size in pixels; used to initialize the principal point}\n\\cvCPy{\\cvarg{cameraMatrix}{The output camera matrix $\\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}}\n\\cvarg{aspectRatio}{If it is zero or negative, both $f_x$ and $f_y$ are estimated independently. Otherwise $f_x = f_y * \\texttt{aspectRatio}$}\n\\end{description}\n\nThe function estimates and returns the initial camera matrix for camera calibration process.\nCurrently, the function only supports planar calibration patterns, i.e. patterns where each object point has z-coordinate =0.\n\n\\ifCPy\n\\cvCPyFunc{InitUndistortMap}\nComputes an undistortion map.\n\n\\cvdefC{void cvInitUndistortMap( \\par const CvMat* cameraMatrix,\\par const CvMat* distCoeffs,\\par CvArr* map1,\\par CvArr* map2 );}\n\\cvdefPy{InitUndistortMap(cameraMatrix,distCoeffs,map1,map2)-> None}\n\n\\begin{description}\n\\cvarg{cameraMatrix}{The input camera matrix $A = \\vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{map1}{The first output map \\cvCPy{of type \\texttt{CV\\_32FC1} or \\texttt{CV\\_16SC2} - the second variant is more efficient}}\n\\cvarg{map2}{The second output map \\cvCPy{of type \\texttt{CV\\_32FC1} or \\texttt{CV\\_16UC1} - the second variant is more efficient}}\n\\end{description}\n\nThe function is a simplified variant of \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} where the rectification transformation \\texttt{R} is identity matrix and \\texttt{newCameraMatrix=cameraMatrix}.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{InitUndistortRectifyMap}\n\\else\n\\cvCppFunc{initUndistortRectifyMap}\n\\fi\nComputes the undistortion and rectification transformation map.\n\n\\cvdefC{void cvInitUndistortRectifyMap( \\par const CvMat* cameraMatrix,\n                                \\par const CvMat* distCoeffs,\n                                \\par const CvMat* R,\n                                \\par const CvMat* newCameraMatrix,\n                                \\par CvArr* map1, \\par CvArr* map2 );}\n\\cvdefPy{InitUndistortRectifyMap(cameraMatrix,distCoeffs,R,newCameraMatrix,map1,map2)-> None}\n\\cvdefCpp{void initUndistortRectifyMap( const Mat\\& cameraMatrix,\\par\n                           const Mat\\& distCoeffs, const Mat\\& R,\\par\n                           const Mat\\& newCameraMatrix,\\par\n                           Size size, int m1type,\\par\n                           Mat\\& map1, Mat\\& map2 );}\n\\begin{description}\n\\cvarg{cameraMatrix}{The input camera matrix $A=\\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{R}{The optional rectification transformation in object space (3x3 matrix). \\texttt{R1} or \\texttt{R2}, computed by \\cvCross{StereoRectify}{stereoRectify} can be passed here. If the matrix is \\cvCPy{NULL}\\cvCpp{empty}, the identity transformation is assumed}\n\\cvarg{newCameraMatrix}{The new camera matrix $A'=\\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}$}\n\\cvCpp{\\cvarg{size}{The undistorted image size}\n\\cvarg{m1type}{The type of the first output map, can be \\texttt{CV\\_32FC1} or \\texttt{CV\\_16SC2}. See \\cvCppCross{convertMaps}}}\n\\cvarg{map1}{The first output map \\cvCPy{of type \\texttt{CV\\_32FC1} or \\texttt{CV\\_16SC2} - the second variant is more efficient}}\n\\cvarg{map2}{The second output map \\cvCPy{of type \\texttt{CV\\_32FC1} or \\texttt{CV\\_16UC1} - the second variant is more efficient}}\n\\end{description}\n\nThe function computes the joint undistortion+rectification transformation and represents the result in the form of maps for \\cvCross{Remap}{remap}. The undistorted image will look like the original, as if it was captured with a camera with camera matrix \\texttt{=newCameraMatrix} and zero distortion. In the case of monocular camera \\texttt{newCameraMatrix} is usually equal to \\texttt{cameraMatrix}, or it can be computed by \\cvCross{GetOptimalNewCameraMatrix}{getOptimalNewCameraMatrix} for a better control over scaling. In the case of stereo camera \\texttt{newCameraMatrix} is normally set to \\texttt{P1} or \\texttt{P2} computed by \\cvCross{StereoRectify}{stereoRectify}.\n\nAlso, this new camera will be oriented differently in the coordinate space, according to \\texttt{R}. That, for example, helps to align two heads of a stereo camera so that the epipolar lines on both images become horizontal and have the same y- coordinate (in the case of horizontally aligned stereo camera).\n\nThe function actually builds the maps for the inverse mapping algorithm that is used by \\cvCross{Remap}{remap}. That is, for each pixel $(u, v)$ in the destination (corrected and rectified) image the function computes the corresponding coordinates in the source image (i.e. in the original image from camera). The process is the following:\n\n\\[\n\\begin{array}{l}\nx \\leftarrow (u - {c'}_x)/{f'}_x \\\\\ny \\leftarrow (v - {c'}_y)/{f'}_y \\\\\n{[X\\,Y\\,W]}^T \\leftarrow R^{-1}*[x\\,y\\,1]^T \\\\\nx' \\leftarrow X/W \\\\\ny' \\leftarrow Y/W \\\\\nx\" \\leftarrow x' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 x' y' + p_2(r^2 + 2 x'^2) \\\\\ny\" \\leftarrow y' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' \\\\\nmap_x(u,v) \\leftarrow x\" f_x + c_x \\\\\nmap_y(u,v) \\leftarrow y\" f_y + c_y\n\\end{array}\n\\]\nwhere $(k_1, k_2, p_1, p_2[, k_3])$ are the distortion coefficients. \n \nIn the case of a stereo camera this function is called twice, once for each camera head, after \\cvCross{StereoRectify}{stereoRectify}, which in its turn is called after \\cvCross{StereoCalibrate}{stereoCalibrate}. But if the stereo camera was not calibrated, it is still possible to compute the rectification transformations directly from the fundamental matrix using \\cvCross{StereoRectifyUncalibrated}{stereoRectifyUncalibrated}. For each camera the function computes homography \\texttt{H} as the rectification transformation in pixel domain, not a rotation matrix \\texttt{R} in 3D space. The \\texttt{R} can be computed from \\texttt{H} as \n\n\\[ \\texttt{R} = \\texttt{cameraMatrix}^{-1} \\cdot \\texttt{H} \\cdot \\texttt{cameraMatrix} \\]\n\nwhere the \\texttt{cameraMatrix} can be chosen arbitrarily.\n\n\\ifCpp\n\n\\cvCppFunc{matMulDeriv}\nComputes partial derivatives of the matrix product w.r.t each multiplied matrix\n\n\\cvdefCpp{void matMulDeriv( const Mat\\& A, const Mat\\& B, Mat\\& dABdA, Mat\\& dABdB );}\n\\begin{description}\n\\cvarg{A}{The first multiplied matrix}\n\\cvarg{B}{The second multiplied matrix}\n\\cvarg{dABdA}{The first output derivative matrix \\texttt{d(A*B)/dA} of size $\\texttt{A.rows*B.cols} \\times {A.rows*A.cols}$}\n\\cvarg{dABdA}{The second output derivative matrix \\texttt{d(A*B)/dB} of size $\\texttt{A.rows*B.cols} \\times {B.rows*B.cols}$}\n\\end{description}\n\nThe function computes the partial derivatives of the elements of the matrix product $A*B$ w.r.t. the elements of each of the two input matrices. The function is used to compute Jacobian matrices in \\cvCppCross{stereoCalibrate}, but can also be used in any other similar optimization function.\n\n\\fi\n\n\\ifCPy\n\n\\cvCPyFunc{POSIT}\nImplements the POSIT algorithm.\n\n\\cvdefC{\nvoid cvPOSIT( \\par CvPOSITObject* posit\\_object,\\par CvPoint2D32f* imagePoints,\\par double focal\\_length,\\par CvTermCriteria criteria,\\par CvMatr32f rotationMatrix,\\par CvVect32f translation\\_vector );\n}\n\\cvdefPy{POSIT(posit\\_object,imagePoints,focal\\_length,criteria)-> (rotationMatrix,translation\\_vector)}\n\n\\begin{description}\n\\cvarg{posit\\_object}{Pointer to the object structure}\n\\cvarg{imagePoints}{Pointer to the object points projections on the 2D image plane}\n\\cvarg{focal\\_length}{Focal length of the camera used}\n\\cvarg{criteria}{Termination criteria of the iterative POSIT algorithm}\n\\cvarg{rotationMatrix}{Matrix of rotations}\n\\cvarg{translation\\_vector}{Translation vector}\n\\end{description}\n\nThe function implements the POSIT algorithm. Image coordinates are given in a camera-related coordinate system. The focal length may be retrieved using the camera calibration functions. At every iteration of the algorithm a new perspective projection of the estimated pose is computed.\n\nDifference norm between two projections is the maximal distance between corresponding points. The parameter \\texttt{criteria.epsilon} serves to stop the algorithm if the difference is small.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{ProjectPoints2}\n\\else\n\\cvCppFunc{projectPoints}\n\\fi\nProject 3D points on to an image plane.\n\n\\cvdefC{void cvProjectPoints2( \\par const CvMat* objectPoints,\\par const CvMat* rvec,\\par const CvMat* tvec,\\par const CvMat* cameraMatrix,\\par const CvMat* distCoeffs,\\par CvMat* imagePoints,\\par CvMat* dpdrot=NULL,\\par CvMat* dpdt=NULL,\\par CvMat* dpdf=NULL,\\par CvMat* dpdc=NULL,\\par CvMat* dpddist=NULL );}\n\n\\cvdefPy{ProjectPoints2(objectPoints,rvec,tvec,cameraMatrix,distCoeffs, imagePoints,dpdrot=NULL,dpdt=NULL,dpdf=NULL,dpdc=NULL,dpddist=NULL)-> None}\n\n\n\\cvdefCpp{void projectPoints( const Mat\\& objectPoints,\\par\n                    const Mat\\& rvec, const Mat\\& tvec,\\par\n                    const Mat\\& cameraMatrix,\\par\n                    const Mat\\& distCoeffs,\\par\n                    vector<Point2f>\\& imagePoints );\\newline\nvoid projectPoints( const Mat\\& objectPoints,\\par\n                    const Mat\\& rvec, const Mat\\& tvec,\\par\n                    const Mat\\& cameraMatrix,\\par\n                    const Mat\\& distCoeffs,\\par\n                    vector<Point2f>\\& imagePoints,\\par\n                    Mat\\& dpdrot, Mat\\& dpdt, Mat\\& dpdf,\\par\n                    Mat\\& dpdc, Mat\\& dpddist,\\par\n                    double aspectRatio=0 );}\n\n\\begin{description}\n\\cvarg{objectPoints}{The array of object points, 3xN or Nx3 1-channel or 1xN or Nx1 3-channel \\cvCpp{(or \\texttt{vector<Point3f>})}, where N is the number of points in the view}\n\\cvarg{rvec}{The rotation vector, see \\cvCross{Rodrigues2}{Rodrigues}}\n\\cvarg{tvec}{The translation vector}\n\\cvarg{cameraMatrix}{The camera matrix $A = \\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1} $}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{imagePoints}{The output array of image points, 2xN or Nx2 1-channel or 1xN or Nx1 2-channel \\cvCpp{(or \\texttt{vector<Point2f>})}}\n\\cvarg{dpdrot}{Optional 2Nx3 matrix of derivatives of image points with respect to components of the rotation vector}\n\\cvarg{dpdt}{Optional 2Nx3 matrix of derivatives of image points with respect to components of the translation vector}\n\\cvarg{dpdf}{Optional 2Nx2 matrix of derivatives of image points with respect to $f_x$ and $f_y$}\n\\cvarg{dpdc}{Optional 2Nx2 matrix of derivatives of image points with respect to $c_x$ and $c_y$}\n\\cvarg{dpddist}{Optional 2Nx4 matrix of derivatives of image points with respect to distortion coefficients}\n\\end{description}\n\nThe function computes projections of 3D\npoints to the image plane given intrinsic and extrinsic camera\nparameters. Optionally, the function computes jacobians - matrices\nof partial derivatives of image points coordinates (as functions of all the\ninput parameters) with respect to the particular parameters, intrinsic and/or\nextrinsic. The jacobians are used during the global optimization\nin \\cvCross{CalibrateCamera2}{calibrateCamera},\n\\cvCross{FindExtrinsicCameraParams2}{solvePnP} and \\cvCross{StereoCalibrate}{stereoCalibrate}. The\nfunction itself can also used to compute re-projection error given the\ncurrent intrinsic and extrinsic parameters.\n\nNote, that by setting \\texttt{rvec=tvec=(0,0,0)}, or by setting \\texttt{cameraMatrix} to 3x3 identity matrix, or by passing zero distortion coefficients, you can get various useful partial cases of the function, i.e. you can compute the distorted coordinates for a sparse set of points, or apply a perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup etc.\n\n\n\\ifCPy\n\\cvCPyFunc{ReprojectImageTo3D}\n\\else\n\\cvCppFunc{reprojectImageTo3D}\n\\fi\nReprojects disparity image to 3D space.\n\n\\cvdefC{void cvReprojectImageTo3D( const CvArr* disparity,\\par\n                                   CvArr* \\_3dImage, const CvMat* Q,\\par\n                                   int handleMissingValues=0);}\n\n\\cvdefPy{ReprojectImageTo3D(disparity, \\_3dImage, Q, handleMissingValues=0) -> None}\n\n\\cvdefCpp{void reprojectImageTo3D( const Mat\\& disparity,\\par\n                         Mat\\& \\_3dImage, const Mat\\& Q,\\par\n                         bool handleMissingValues=false );}\n\\begin{description}\n\\cvarg{disparity}{The input single-channel 16-bit signed or 32-bit floating-point disparity image}\n\\cvarg{\\_3dImage}{The output 3-channel floating-point image of the same size as \\texttt{disparity}.\n Each element of \\texttt{\\_3dImage(x,y)} will contain the 3D coordinates of the point \\texttt{(x,y)}, computed from the disparity map.}\n\\cvarg{Q}{The $4 \\times 4$ perspective transformation matrix that can be obtained with \\cvCross{StereoRectify}{stereoRectify}}\n\\cvarg{handleMissingValues}{If true, when the pixels with the minimal disparity (that corresponds to the outliers; see \\cvCross{FindStereoCorrespondenceBM}{StereoBM}) will be transformed to 3D points with some very large Z value (currently set to 10000)}\n\\end{description}\n \nThe function transforms 1-channel disparity map to 3-channel image representing a 3D surface. That is, for each pixel \\texttt{(x,y)} and the corresponding disparity \\texttt{d=disparity(x,y)} it computes: \n\n\\[\\begin{array}{l}\n[X\\; Y\\; Z\\; W]^T = \\texttt{Q}*[x\\; y\\; \\texttt{disparity}(x,y)\\; 1]^T \\\\\n\\texttt{\\_3dImage}(x,y) = (X/W,\\; Y/W,\\; Z/W)\n\\end{array}\\]\n\nThe matrix \\texttt{Q} can be arbitrary $4 \\times 4$ matrix, e.g. the one computed by \\cvCross{StereoRectify}{stereoRectify}. To reproject a sparse set of points {(x,y,d),...} to 3D space, use \\cvCross{PerspectiveTransform}{perspectiveTransform}.\n\n\\ifCPy\n\\cvCPyFunc{RQDecomp3x3}\n\\else\n\\cvCppFunc{RQDecomp3x3}\n\\fi\nComputes the 'RQ' decomposition of 3x3 matrices.\n\n\\cvdefC{\nvoid cvRQDecomp3x3( \\par const CvMat *M,\\par CvMat *R,\\par CvMat *Q,\\par CvMat *Qx=NULL,\\par CvMat *Qy=NULL,\\par CvMat *Qz=NULL,\\par CvPoint3D64f *eulerAngles=NULL);\n}\n\\cvdefPy{RQDecomp3x3(M, R, Q, Qx = None, Qy = None, Qz = None) -> eulerAngles}\n\\cvdefCpp{void RQDecomp3x3( const Mat\\& M, Mat\\& R, Mat\\& Q );\\newline\nVec3d RQDecomp3x3( const Mat\\& M, Mat\\& R, Mat\\& Q,\\par\n                   Mat\\& Qx, Mat\\& Qy, Mat\\& Qz );}\n\n\\begin{description}\n\\cvarg{M}{The 3x3 input matrix}\n\\cvarg{R}{The output 3x3 upper-triangular matrix}\n\\cvarg{Q}{The output 3x3 orthogonal matrix}\n\\cvarg{Qx}{Optional 3x3 rotation matrix around x-axis}\n\\cvarg{Qy}{Optional 3x3 rotation matrix around y-axis}\n\\cvarg{Qz}{Optional 3x3 rotation matrix around z-axis}\n\\cvCPy{\\cvarg{eulerAngles}{Optional three Euler angles of rotation}}\n\\end{description}\n\nThe function computes a RQ decomposition using the given rotations. This function is used in \\cvCross{DecomposeProjectionMatrix}{decomposeProjectionMatrix} to decompose the left 3x3 submatrix of a projection matrix into a camera and a rotation matrix.\n\nIt optionally returns three rotation matrices, one for each axis, and the three Euler angles \\cvCpp{(as the return value)} that could be used in OpenGL.\n\n\\ifC\n\n\\cvCPyFunc{ReleasePOSITObject}\nDeallocates a 3D object structure.\n\n\\cvdefC{\nvoid cvReleasePOSITObject( \\par CvPOSITObject** posit\\_object );\n}\n\n\\begin{description}\n\\cvarg{posit\\_object}{Double pointer to \\texttt{CvPOSIT} structure}\n\\end{description}\n\nThe function releases memory previously allocated by the function \\cvCPyCross{CreatePOSITObject}.\n\n\\fi\n\n\\ifC\n\n\\cvCPyFunc{ReleaseStereoBMState}\nReleases block matching stereo correspondence structure.\n\n\\cvdefC{void cvReleaseStereoBMState( CvStereoBMState** state );}\n\\cvdefPy{ReleaseStereoBMState(state)-> None}\n\n\\begin{description}\n\\cvarg{state}{Double pointer to the released structure.}\n\\end{description}\n\nThe function releases the stereo correspondence structure and all the associated internal buffers. \n\n\\cvCPyFunc{ReleaseStereoGCState}\nReleases the state structure of the graph cut-based stereo correspondence algorithm.\n\n\\cvdefC{void cvReleaseStereoGCState( CvStereoGCState** state );}\n\\cvdefPy{ReleaseStereoGCState(state)-> None}\n\n\\begin{description}\n\\cvarg{state}{Double pointer to the released structure.}\n\\end{description}\n\nThe function releases the stereo correspondence structure and all the associated internal buffers. \n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{Rodrigues2}\n\\else\n\\cvCppFunc{Rodrigues}\n\\fi\nConverts a rotation matrix to a rotation vector or vice versa.\n\n\\cvdefC{int cvRodrigues2( \\par const CvMat* src,\\par CvMat* dst,\\par CvMat* jacobian=0 );}\n\\cvdefPy{Rodrigues2(src,dst,jacobian=0)-> None}\n\n\\cvdefCpp{void Rodrigues(const Mat\\& src, Mat\\& dst);\\newline\nvoid Rodrigues(const Mat\\& src, Mat\\& dst, Mat\\& jacobian);}\n\n\\begin{description}\n\\cvarg{src}{The input rotation vector (3x1 or 1x3) or rotation matrix (3x3)}\n\\cvarg{dst}{The output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively}\n\\cvarg{jacobian}{Optional output Jacobian matrix, 3x9 or 9x3 - partial derivatives of the output array components with respect to the input array components}\n\\end{description}\n\n\\[\n\\begin{array}{l}\n\\theta \\leftarrow norm(r)\\\\\nr \\leftarrow r/\\theta\\\\\nR = \\cos{\\theta} I + (1-\\cos{\\theta}) r r^T + \\sin{\\theta}\n\\vecthreethree\n{0}{-r_z}{r_y}\n{r_z}{0}{-r_x}\n{-r_y}{r_x}{0}\n\\end{array}\n\\]\n\nInverse transformation can also be done easily, since\n\n\\[\n\\sin(\\theta)\n\\vecthreethree\n{0}{-r_z}{r_y}\n{r_z}{0}{-r_x}\n{-r_y}{r_x}{0}\n=\n\\frac{R - R^T}{2}\n\\]\n\nA rotation vector is a convenient and most-compact representation of a rotation matrix\n(since any rotation matrix has just 3 degrees of freedom). The representation is\nused in the global 3D geometry optimization procedures like \\cvCross{CalibrateCamera2}{calibrateCamera},\n\\cvCross{StereoCalibrate}{stereoCalibrate} or \\cvCross{FindExtrinsicCameraParams2}{solvePnP}.\n\n\n\\ifCpp\n\n\\cvclass{StereoBM}\nThe class for computing stereo correspondence using block matching algorithm.\n\n\\begin{lstlisting}\n// Block matching stereo correspondence algorithm\\par\nclass StereoBM\n{\n    enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,\n        BASIC_PRESET=CV_STEREO_BM_BASIC,\n        FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,\n        NARROW_PRESET=CV_STEREO_BM_NARROW };\n\n    StereoBM();\n    // the preset is one of ..._PRESET above.\n    // ndisparities is the size of disparity range,\n    // in which the optimal disparity at each pixel is searched for.\n    // SADWindowSize is the size of averaging window used to match pixel blocks\n    //    (larger values mean better robustness to noise, but yield blurry disparity maps)\n    StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);\n    // separate initialization function\n    void init(int preset, int ndisparities=0, int SADWindowSize=21);\n    // computes the disparity for the two rectified 8-bit single-channel images.\n    // the disparity will be 16-bit signed (fixed-point) or 32-bit floating-point image of the same size as left.\n    void operator()( const Mat& left, const Mat& right, Mat& disparity, int disptype=CV_16S );\n\n    Ptr<CvStereoBMState> state;\n};\n\\end{lstlisting}\n\nThe class is a C++ wrapper for \\hyperref[CvStereoBMState]{cvStereoBMState} and the associated functions. In particular, \\texttt{StereoBM::operator ()} is the wrapper for \\cvCPyCross{FindStereoCorrespondceBM}. See the respective descriptions.\n\n\n\\cvclass{StereoSGBM}\nThe class for computing stereo correspondence using semi-global block matching algorithm.\n\n\\begin{lstlisting}\nclass StereoSGBM\n{\n    StereoSGBM();\n    StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,\n               int P1=0, int P2=0, int disp12MaxDiff=0,\n               int preFilterCap=0, int uniquenessRatio=0,\n               int speckleWindowSize=0, int speckleRange=0,\n               bool fullDP=false);\n    virtual ~StereoSGBM();\n    \n    virtual void operator()(const Mat& left, const Mat& right, Mat& disp);\n    \n    int minDisparity;\n    int numberOfDisparities;\n    int SADWindowSize;\n    int preFilterCap;\n    int uniquenessRatio;\n    int P1, P2;\n    int speckleWindowSize;\n    int speckleRange;\n    int disp12MaxDiff;\n    bool fullDP;\n    \n    ...\n};\n\\end{lstlisting}\n\nThe class implements modified H. Hirschmuller algorithm \\cite{HH08}. The main differences between the implemented algorithm and the original one are:\n\n\\begin{itemize}\n    \\item by default the algorithm is single-pass, i.e. instead of 8 directions we only consider 5. Set \\texttt{fullDP=true} to run the full variant of the algorithm (which could consume \\emph{a lot} of memory)\n    \\item the algorithm matches blocks, not individual pixels (though, by setting \\texttt{SADWindowSize=1} the blocks are reduced to single pixels)\n    \\item mutual information cost function is not implemented. Instead, we use a simpler Birchfield-Tomasi sub-pixel metric from \\cite{BT96}, though the color images are supported as well.\n    \\item we include some pre- and post- processing steps from K. Konolige algorithm \\cvCPyCross{FindStereoCorrespondceBM}, such as pre-filtering (\\texttt{CV\\_STEREO\\_BM\\_XSOBEL} type) and post-filtering (uniqueness check, quadratic interpolation and speckle filtering)\n\\end{itemize}\n\n\\cvCppFunc{StereoSGBM::StereoSGBM}\nStereoSGBM constructors\n\n\\cvdefCpp{\nStereoSGBM::StereoSGBM();\\newline\nStereoSGBM::StereoSGBM(\n            \\par int minDisparity, int numDisparities, int SADWindowSize,\n           \\par int P1=0, int P2=0, int disp12MaxDiff=0,\n           \\par int preFilterCap=0, int uniquenessRatio=0,\n           \\par int speckleWindowSize=0, int speckleRange=0,\n           \\par bool fullDP=false);\n}\n\\begin{description}\n\\cvarg{minDisparity}{The minimum possible disparity value. Normally it is 0, but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly}\n\\cvarg{numDisparities}{This is maximum disparity minus minimum disparity. Always greater than 0. In the current implementation this parameter must be divisible by 16.}\n\\cvarg{SADWindowSize}{The matched block size. Must be an odd number \\texttt{>=1}. Normally, it should be somewhere in \\texttt{3..11} range}.\n\\cvarg{P1, P2}{Parameters that control disparity smoothness. The larger the values, the smoother the disparity. \\texttt{P1} is the penalty on the disparity change by plus or minus 1 between neighbor pixels. \\texttt{P2} is the penalty on the disparity change by more than 1 between neighbor pixels. The algorithm requires \\texttt{P2 > P1}. See \\texttt{stereo\\_match.cpp} sample where some reasonably good \\texttt{P1} and \\texttt{P2} values are shown (like \\texttt{8*number\\_of\\_image\\_channels*SADWindowSize*SADWindowSize} and \\texttt{32*number\\_of\\_image\\_channels*SADWindowSize*SADWindowSize}, respectively).}\n\\cvarg{disp12MaxDiff}{Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to non-positive value to disable the check.}\n\\cvarg{preFilterCap}{Truncation value for the prefiltered image pixels. The algorithm first computes x-derivative at each pixel and clips its value by \\texttt{[-preFilterCap, preFilterCap]} interval. The result values are passed to the Birchfield-Tomasi pixel cost function.}\n\\cvarg{uniquenessRatio}{The margin in percents by which the best (minimum) computed cost function value should \"win\" the second best value to consider the found match correct. Normally, some value within 5-15 range is good enough}\n\\cvarg{speckleWindowSize}{Maximum size of smooth disparity regions to consider them noise speckles and invdalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in 50-200 range.}\n\\cvarg{speckleRange}{Maximum disparity variation within each connected component. If you do speckle filtering, set it to some positive value, multiple of 16. Normally, 16 or 32 is good enough.}\n\\cvarg{fullDP}{Set it to \\texttt{true} to run full-scale 2-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default this is \\texttt{false}}\n\\end{description}\n\nThe first constructor initializes \\texttt{StereoSGBM} with all the default parameters (so actually one will only have to set \\texttt{StereoSGBM::numberOfDisparities} at minimum). The second constructor allows you to set each parameter to a custom value.\n\n\\cvCppFunc{StereoSGBM::operator ()}\nComputes disparity using SGBM algorithm for a rectified stereo pair\n\n\\cvdefCpp{\nvoid SGBM::operator()(const Mat\\& left, const Mat\\& right, Mat\\& disp);\n}\n\\begin{description}\n\\cvarg{left}{The left image, 8-bit single-channel or 3-channel.}\n\\cvarg{right}{The right image of the same size and the same type as the left one.}\n\\cvarg{disp}{The output disparity map. It will be 16-bit signed single-channel image of the same size as the input images. It will contain scaled by 16 disparity values, so that to get the floating-point disparity map, you will need to divide each \\texttt{disp} element by 16.}\n\\end{description}\n\nThe method executes SGBM algorithm on a rectified stereo pair. See \\texttt{stereo\\_match.cpp} OpenCV sample on how to prepare the images and call the method. Note that the method is not constant, thus you should not use the same \\texttt{StereoSGBM} instance from within different threads simultaneously.\n\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{StereoCalibrate}\n\\else\n\\cvCppFunc{stereoCalibrate}\n\\fi\nCalibrates stereo camera.\n\n\\cvdefC{double cvStereoCalibrate( \\par const CvMat* objectPoints, \\par const CvMat* imagePoints1,\n                        \\par const CvMat* imagePoints2, \\par const CvMat* pointCounts,\n                        \\par CvMat* cameraMatrix1, \\par CvMat* distCoeffs1,\n                        \\par CvMat* cameraMatrix2, \\par CvMat* distCoeffs2,\n                       \\par CvSize imageSize, \\par CvMat* R, \\par CvMat* T,\n                        \\par CvMat* E=0, \\par CvMat* F=0,\n                        \\par CvTermCriteria term\\_crit=cvTermCriteria(\n                               \\par CV\\_TERMCRIT\\_ITER+CV\\_TERMCRIT\\_EPS,30,1e-6),\n                        \\par int flags=CV\\_CALIB\\_FIX\\_INTRINSIC );}\n\n\\cvdefPy{StereoCalibrate( objectPoints, imagePoints1, imagePoints2, pointCounts, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E=NULL, F=NULL, term\\_crit=(CV\\_TERMCRIT\\_ITER+CV\\_TERMCRIT\\_EPS,30,1e-6), flags=CV\\_CALIB\\_FIX\\_INTRINSIC)-> None}\n\n\\cvdefCpp{double stereoCalibrate( const vector<vector<Point3f> >\\& objectPoints,\\par\n                      const vector<vector<Point2f> >\\& imagePoints1,\\par\n                      const vector<vector<Point2f> >\\& imagePoints2,\\par\n                      Mat\\& cameraMatrix1, Mat\\& distCoeffs1,\\par\n                      Mat\\& cameraMatrix2, Mat\\& distCoeffs2,\\par\n                      Size imageSize, Mat\\& R, Mat\\& T,\\par\n                      Mat\\& E, Mat\\& F,\\par\n                      TermCriteria term\\_crit = TermCriteria(TermCriteria::COUNT+\\par\n                         TermCriteria::EPS, 30, 1e-6),\\par\n                      int flags=CALIB\\_FIX\\_INTRINSIC );}\n\n\\begin{description}\n\\ifCPy\n    \\cvarg{objectPoints}{The joint matrix of object points - calibration pattern features in the model coordinate space. It is floating-point 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel array, where N is the total number of points in all views.}\n    \\cvarg{imagePoints1}{The joint matrix of object points projections in the first camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}\n    \\cvarg{imagePoints2}{The joint matrix of object points projections in the second camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}\n    \\cvarg{pointCounts}{Integer 1xM or Mx1 vector (where M is the number of calibration pattern views) containing the number of points in each particular view. The sum of vector elements must match the size of \\texttt{objectPoints} and \\texttt{imagePoints*} (=N).}\n\\fi\n\\ifCpp\n    \\cvarg{objectPoints}{The vector of vectors of points on the calibration pattern in its coordinate system, one vector per view. If the same calibration pattern is shown in each view and it's fully visible then all the vectors will be the same, although it is possible to use partially occluded patterns, or even different patterns in different views - then the vectors will be different. The points are 3D, but since they are in the pattern coordinate system, then if the rig is planar, it may have sense to put the model to the XY coordinate plane, so that Z-coordinate of each input object point is 0}\n    \\cvarg{imagePoints1}{The vector of vectors of the object point projections on the calibration pattern views from the 1st camera, one vector per a view. The projections must be in the same order as the corresponding object points.}\n    \\cvarg{imagePoints2}{The vector of vectors of the object point projections on the calibration pattern views from the 2nd camera, one vector per a view. The projections must be in the same order as the corresponding object points.}\n\\fi\n    \\cvarg{cameraMatrix1}{The input/output first camera matrix: $ \\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$, $j = 0,\\, 1$. If any of \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS}, \\newline \\texttt{CV\\_CALIB\\_FIX\\_ASPECT\\_RATIO}, \\texttt{CV\\_CALIB\\_FIX\\_INTRINSIC} or \\texttt{CV\\_CALIB\\_FIX\\_FOCAL\\_LENGTH} are specified, some or all of the matrices' components must be initialized; see the flags description}\n    \\cvarg{distCoeffs}{The input/output vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. \\cvCpp{On output vector length depends on the flags.}}\n    \\cvarg{cameraMatrix2}{The input/output second camera matrix, as cameraMatrix1.}\n    \\cvarg{distCoeffs2}{The input/output lens distortion coefficients for the second camera, as \\texttt{distCoeffs1}.}\n\\cvarg{imageSize}{Size of the image, used only to initialize intrinsic camera matrix.} \n\\cvarg{R}{The output rotation matrix between the 1st and the 2nd cameras' coordinate systems.}\n\\cvarg{T}{The output translation vector between the cameras' coordinate systems.}\n\\cvarg{E}{The \\cvCPy{optional} output essential matrix.}\n\\cvarg{F}{The \\cvCPy{optional} output fundamental matrix.}\n\\cvarg{term\\_crit}{The termination criteria for the iterative optimization algorithm.}\n\\cvarg{flags}{Different flags, may be 0 or combination of the following values:\n\\begin{description}\n\\cvarg{CV\\_CALIB\\_FIX\\_INTRINSIC}{If it is set, \\texttt{cameraMatrix?}, as well as \\texttt{distCoeffs?} are fixed, so that only \\texttt{R, T, E} and \\texttt{F} are estimated.}\n\\cvarg{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS}{The flag allows the function to optimize some or all of the intrinsic parameters, depending on the other flags, but the initial values are provided by the user.}\n\\cvarg{CV\\_CALIB\\_FIX\\_PRINCIPAL\\_POINT}{The principal points are fixed during the optimization.}\n\\cvarg{CV\\_CALIB\\_FIX\\_FOCAL\\_LENGTH}{$f^{(j)}_x$ and $f^{(j)}_y$ are fixed.}\n\\cvarg{CV\\_CALIB\\_FIX\\_ASPECT\\_RATIO}{$f^{(j)}_y$ is optimized, but the ratio $f^{(j)}_x/f^{(j)}_y$ is fixed.}\n\\cvarg{CV\\_CALIB\\_SAME\\_FOCAL\\_LENGTH}{Enforces $f^{(0)}_x=f^{(1)}_x$ and $f^{(0)}_y=f^{(1)}_y$} \\cvarg{CV\\_CALIB\\_ZERO\\_TANGENT\\_DIST}{Tangential distortion coefficients for each camera are set to zeros and fixed there.}\n\\cvarg{CV\\_CALIB\\_FIX\\_K1,...,CV\\_CALIB\\_FIX\\_K6}{Do not change the corresponding radial distortion coefficient during the optimization. If \\texttt{CV\\_CALIB\\_USE\\_INTRINSIC\\_GUESS} is set, the coefficient from the supplied \\texttt{distCoeffs} matrix is used, otherwise it is set to 0.}\n\\cvarg{CV\\_CALIB\\_RATIONAL\\_MODEL}{Enable coefficients k4, k5 and k6. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function will compute \\cvCpp{and return} only 5 distortion coefficients.}\n\\end{description}}\n\\end{description}\n\nThe function estimates transformation between the 2 cameras making a stereo pair. If we have a stereo camera, where the relative position and orientation of the 2 cameras is fixed, and if we computed poses of an object relative to the fist camera and to the second camera, (R1, T1) and (R2, T2), respectively (that can be done with \\cvCross{FindExtrinsicCameraParams2}{solvePnP}), obviously, those poses will relate to each other, i.e. given ($R_1$, $T_1$) it should be possible to compute ($R_2$, $T_2$) - we only need to know the position and orientation of the 2nd camera relative to the 1st camera. That's what the described function does. It computes ($R$, $T$) such that:\n\n\\[\nR_2=R*R_1\nT_2=R*T_1 + T,\n\\]\n\nOptionally, it computes the essential matrix E:\n\n\\[\nE=\n\\vecthreethree\n{0}{-T_2}{T_1}\n{T_2}{0}{-T_0}\n{-T_1}{T_0}{0}\n*R\n\\]\n\nwhere $T_i$ are components of the translation vector $T$: $T=[T_0, T_1, T_2]^T$. And also the function can compute the fundamental matrix F:\n\n\\[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\\]\n\nBesides the stereo-related information, the function can also perform full calibration of each of the 2 cameras. However, because of the high dimensionality of the parameter space and noise in the input data the function can diverge from the correct solution. Thus, if intrinsic parameters can be estimated with high accuracy for each of the cameras individually (e.g. using \\cvCross{CalibrateCamera2}{calibrateCamera}), it is recommended to do so and then pass \\texttt{CV\\_CALIB\\_FIX\\_INTRINSIC} flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, e.g. pass \\texttt{CV\\_CALIB\\_SAME\\_FOCAL\\_LENGTH} and \\texttt{CV\\_CALIB\\_ZERO\\_TANGENT\\_DIST} flags, which are usually reasonable assumptions.\n\nSimilarly to \\cvCross{CalibrateCamera2}{calibrateCamera}, the function minimizes the total re-projection error for all the points in all the available views from both cameras.\n\\ifPy\n\\else\nThe function returns the final value of the re-projection error.\n\\fi\n\n\\ifCPy\n\\cvCPyFunc{StereoRectify}\n\\else\n\\cvCppFunc{stereoRectify}\n\\fi\nComputes rectification transforms for each head of a calibrated stereo camera.\n\n\\cvdefC{void cvStereoRectify( \\par const CvMat* cameraMatrix1, const CvMat* cameraMatrix2,\n                      \\par const CvMat* distCoeffs1, const CvMat* distCoeffs2,\n                      \\par CvSize imageSize, const CvMat* R, const CvMat* T,\n                      \\par CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,\n                      \\par CvMat* Q=0, int flags=CV\\_CALIB\\_ZERO\\_DISPARITY,\n                      \\par double alpha=-1, CvSize newImageSize=cvSize(0,0),\n                      \\par CvRect* roi1=0, CvRect* roi2=0);}\n\\cvdefPy{StereoRectify( cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2, imageSize, R, T, R1, R2, P1, P2, Q=NULL, flags=CV\\_CALIB\\_ZERO\\_DISPARITY, alpha=-1, newImageSize=(0,0))-> (roi1, roi2)}\n\n\\cvdefCpp{void stereoRectify( const Mat\\& cameraMatrix1, const Mat\\& distCoeffs1,\\par\n                    const Mat\\& cameraMatrix2, const Mat\\& distCoeffs2,\\par\n                    Size imageSize, const Mat\\& R, const Mat\\& T,\\par\n                    Mat\\& R1, Mat\\& R2, Mat\\& P1, Mat\\& P2, Mat\\& Q,\\par\n                    int flags=CALIB\\_ZERO\\_DISPARITY );\\newline\nvoid stereoRectify( const Mat\\& cameraMatrix1, const Mat\\& distCoeffs1,\\par\n                    const Mat\\& cameraMatrix2, const Mat\\& distCoeffs2,\\par\n                    Size imageSize, const Mat\\& R, const Mat\\& T,\\par\n                    Mat\\& R1, Mat\\& R2, Mat\\& P1, Mat\\& P2, Mat\\& Q,\\par\n                    double alpha, Size newImageSize=Size(),\\par\n                    Rect* roi1=0, Rect* roi2=0,\\par\n                    int flags=CALIB\\_ZERO\\_DISPARITY );}\n\\begin{description}\n\\cvarg{cameraMatrix1, cameraMatrix2}{The camera matrices $\\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$.}\n\\cvarg{distCoeffs1, distCoeffs2}\\cvarg{distCoeffs}{The input vectors of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements each. If the vectors are NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{imageSize}{Size of the image used for stereo calibration.}\n\\cvarg{R}{The rotation matrix between the 1st and the 2nd cameras' coordinate systems.}\n\\cvarg{T}{The translation vector between the cameras' coordinate systems.}\n\\cvarg{R1, R2}{The output $3 \\times 3$ rectification transforms (rotation matrices) for the first and the second cameras, respectively.}\n\\cvarg{P1, P2}{The output $3 \\times 4$ projection matrices in the new (rectified) coordinate systems.}\n\\cvarg{Q}{The output $4 \\times 4$ disparity-to-depth mapping matrix, see \\cvCppCross{reprojectImageTo3D}.}\n\\cvarg{flags}{The operation flags; may be 0 or \\texttt{CV\\_CALIB\\_ZERO\\_DISPARITY}. If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function may still shift the images in horizontal or vertical direction (depending on the orientation of epipolar lines) in order to maximize the useful image area.}\n\\cvarg{alpha}{The free scaling parameter. If it is -1\\cvCpp{ or absent}, the functions performs some default scaling. Otherwise the parameter should be between 0 and 1. \\texttt{alpha=0} means that the rectified images will be zoomed and shifted so that only valid pixels are visible (i.e. there will be no black areas after rectification). \\texttt{alpha=1} means that the rectified image will be decimated and shifted so that all the pixels from the original images from the cameras are retained in the rectified images, i.e. no source image pixels are lost. Obviously, any intermediate value yields some intermediate result between those two extreme cases.}\n\\cvarg{newImageSize}{The new image resolution after rectification. The same size should be passed to \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap}, see the \\texttt{stereo\\_calib.cpp} sample in OpenCV samples directory. By default, i.e. when (0,0) is passed, it is set to the original \\texttt{imageSize}. Setting it to larger value can help you to preserve details in the original image, especially when there is big radial distortion.}\n\\cvarg{roi1, roi2}{The optional output rectangles inside the rectified images where all the pixels are valid. If \\texttt{alpha=0}, the ROIs will cover the whole images, otherwise they likely be smaller, see the picture below}\n\\end{description}\n\nThe function computes the rotation matrices for each camera that (virtually) make both camera image planes the same plane. Consequently, that makes all the epipolar lines parallel and thus simplifies the dense stereo correspondence problem. On input the function takes the matrices computed by \\cvCppCross{stereoCalibrate} and on output it gives 2 rotation matrices and also 2 projection matrices in the new coordinates. The 2 cases are distinguished by the function are: \n\n\\begin{enumerate}\n\\item Horizontal stereo, when 1st and 2nd camera views are shifted relative to each other mainly along the x axis (with possible small vertical shift). Then in the rectified images the corresponding epipolar lines in left and right cameras will be horizontal and have the same y-coordinate. P1 and P2 will look as: \n\n\\[\\texttt{P1}=\n\\begin{bmatrix}\nf & 0 & cx_1 & 0\\\\\n0 & f & cy & 0\\\\\n0 & 0 & 1 & 0\n\\end{bmatrix}\n\\]\n\\[\\texttt{P2}=\n\\begin{bmatrix}\nf & 0 & cx_2 & T_x*f\\\\\n0 & f & cy & 0\\\\\n0 & 0 & 1 & 0\n\\end{bmatrix}\n,\n\\]\n\nwhere $T_x$ is horizontal shift between the cameras and $cx_1=cx_2$ if \\texttt{CV\\_CALIB\\_ZERO\\_DISPARITY} is set.\n\\item Vertical stereo, when 1st and 2nd camera views are shifted relative to each other mainly in vertical direction (and probably a bit in the horizontal direction too). Then the epipolar lines in the rectified images will be vertical and have the same x coordinate. P2 and P2 will look as:\n\n\\[\n\\texttt{P1}=\n\\begin{bmatrix}\nf & 0 & cx & 0\\\\\n0 & f & cy_1 & 0\\\\\n0 & 0 & 1 & 0\n\\end{bmatrix}\n\\]\n\\[\n\\texttt{P2}=\n\\begin{bmatrix}\nf & 0 & cx & 0\\\\\n0 & f & cy_2 & T_y*f\\\\\n0 & 0 & 1 & 0\n\\end{bmatrix}\n,\n\\]\n\nwhere $T_y$ is vertical shift between the cameras and $cy_1=cy_2$ if \\texttt{CALIB\\_ZERO\\_DISPARITY} is set.\n\\end{enumerate} \n\nAs you can see, the first 3 columns of \\texttt{P1} and \\texttt{P2} will effectively be the new \"rectified\" camera matrices. \nThe matrices, together with \\texttt{R1} and \\texttt{R2}, can then be passed to \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} to initialize the rectification map for each camera.\n\nBelow is the screenshot from \\texttt{stereo\\_calib.cpp} sample. Some red horizontal lines, as you can see, pass through the corresponding image regions, i.e. the images are well rectified (which is what most stereo correspondence algorithms rely on). The green rectangles are \\texttt{roi1} and \\texttt{roi2} - indeed, their interior are all valid pixels.\n\n\\includegraphics[width=0.8\\textwidth]{pics/stereo_undistort.jpg}\n\n\\ifCPy\n\\cvCPyFunc{StereoRectifyUncalibrated}\n\\else\n\\cvCppFunc{stereoRectifyUncalibrated}\n\\fi\nComputes rectification transform for uncalibrated stereo camera.\n\n\\cvdefC{void cvStereoRectifyUncalibrated( \\par const CvMat* points1, \\par const CvMat* points2,\n                                  \\par const CvMat* F, \\par CvSize imageSize,\n                                  \\par CvMat* H1, \\par CvMat* H2,\n                                  \\par double threshold=5 );}\n\\cvdefPy{StereoRectifyUncalibrated(points1,points2,F,imageSize,H1,H2,threshold=5)-> None}\n\\cvdefCpp{bool stereoRectifyUncalibrated( const Mat\\& points1,\\par\n                                const Mat\\& points2,\\par\n                                const Mat\\& F, Size imgSize,\\par\n                                Mat\\& H1, Mat\\& H2,\\par\n                                double threshold=5 );}\n\\begin{description}\n\\cvarg{points1, points2}{The 2 arrays of corresponding 2D points. The same formats as in \\cvCross{FindFundamentalMat}{findFundamentalMat} are supported}\n\\cvarg{F}{The input fundamental matrix. It can be computed from the same set of point pairs using \\cvCross{FindFundamentalMat}{findFundamentalMat}.}\n\\cvarg{imageSize}{Size of the image.}\n\\cvarg{H1, H2}{The output rectification homography matrices for the first and for the second images.}\n\\cvarg{threshold}{The optional threshold used to filter out the outliers. If the parameter is greater than zero, then all the point pairs that do not comply the epipolar geometry well enough (that is, the points for which $|\\texttt{points2[i]}^T*\\texttt{F}*\\texttt{points1[i]}|>\\texttt{threshold}$) are rejected prior to computing the homographies.\nOtherwise all the points are considered inliers.}\n\\end{description}\n\nThe function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in space, hence the suffix \"Uncalibrated\". Another related difference from \\cvCross{StereoRectify}{stereoRectify} is that the function outputs not the rectification transformations in the object (3D) space, but the planar perspective transformations, encoded by the homography matrices \\texttt{H1} and \\texttt{H2}. The function implements the algorithm \\cite{Hartley99}. \n\nNote that while the algorithm does not need to know the intrinsic parameters of the cameras, it heavily depends on the epipolar geometry. Therefore, if the camera lenses have significant distortion, it would better be corrected before computing the fundamental matrix and calling this function. For example, distortion coefficients can be estimated for each head of stereo camera separately by using \\cvCross{CalibrateCamera2}{calibrateCamera} and then the images can be corrected using \\cvCross{Undistort2}{undistort}, or just the point coordinates can be corrected with \\cvCross{UndistortPoints}{undistortPoints}.\n\n\n\\ifCPy\n\\cvCPyFunc{Undistort2}\n\\else\n\\cvCppFunc{undistort}\n\\fi\nTransforms an image to compensate for lens distortion.\n\n\\cvdefC{void cvUndistort2( \\par const CvArr* src,\\par CvArr* dst,\\par const CvMat* cameraMatrix,\n    \\par const CvMat* distCoeffs, \\par const CvMat* newCameraMatrix=0 );}\n\\cvdefPy{Undistort2(src,dst,cameraMatrix,distCoeffs)-> None}\n\n\\cvdefCpp{void undistort( const Mat\\& src, Mat\\& dst, const Mat\\& cameraMatrix,\\par\n                const Mat\\& distCoeffs, const Mat\\& newCameraMatrix=Mat() );}\n\\begin{description}\n\\cvarg{src}{The input (distorted) image}\n\\cvarg{dst}{The output (corrected) image; will have the same size and the same type as \\texttt{src}}\n\\cvarg{cameraMatrix}{The input camera matrix $A = \\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} $}\n\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvCpp{\\cvarg{newCameraMatrix}{Camera matrix of the distorted image. By default it is the same as \\texttt{cameraMatrix}, but you may additionally scale and shift the result by using some different matrix}}\n\\end{description}\n\nThe function transforms the image to compensate radial and tangential lens distortion.\n\nThe function is simply a combination of \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} (with unity \\texttt{R}) and \\cvCross{Remap}{remap} (with bilinear interpolation). See the former function for details of the transformation being performed.\n\nThose pixels in the destination image, for which there is no correspondent pixels in the source image, are filled with 0's (black color).\n\nThe particular subset of the source image that will be visible in the corrected image can be regulated by \\texttt{newCameraMatrix}. You can use \\cvCross{GetOptimalNewCameraMatrix}{getOptimalNewCameraMatrix} to compute the appropriate \\texttt{newCameraMatrix}, depending on your requirements.\n\nThe camera matrix and the distortion parameters can be determined using\n\\cvCross{CalibrateCamera2}{calibrateCamera}. If the resolution of images is different from the used at the calibration stage, $f_x, f_y, c_x$ and $c_y$ need to be scaled accordingly, while the distortion coefficients remain the same.\n\n\n\\ifCPy\n\\cvCPyFunc{UndistortPoints}\n\\else\n\\cvCppFunc{undistortPoints}\n\\fi\nComputes the ideal point coordinates from the observed point coordinates.\n\n\\cvdefC{void cvUndistortPoints( \\par const CvMat* src, \\par CvMat* dst,\n                        \\par const CvMat* cameraMatrix,\n                        \\par const CvMat* distCoeffs,\n                        \\par const CvMat* R=NULL,\n                        \\par const CvMat* P=NULL);}\n\\cvdefPy{UndistortPoints(src,dst,cameraMatrix,distCoeffs,R=NULL,P=NULL)-> None}\n\n\\cvdefCpp{void undistortPoints( const Mat\\& src, vector<Point2f>\\& dst,\\par\n                      const Mat\\& cameraMatrix, const Mat\\& distCoeffs,\\par\n                      const Mat\\& R=Mat(), const Mat\\& P=Mat());\\newline\nvoid undistortPoints( const Mat\\& src, Mat\\& dst,\\par\n                      const Mat\\& cameraMatrix, const Mat\\& distCoeffs,\\par\n                      const Mat\\& R=Mat(), const Mat\\& P=Mat());}\n\n\\begin{description}\n\n\\cvarg{src}{The observed point coordinates, 1xN or Nx1 2-channel (CV\\_32FC2 or CV\\_64FC2).} \n\\cvarg{dst}{The output ideal point coordinates, after undistortion and reverse perspective transformation\\cvCPy{, same format as \\texttt{src}}.}\n\\cvarg{cameraMatrix}{The camera matrix $\\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}\n\\cvarg{distCoeffs}\\cvarg{distCoeffs}{The input vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])$ of 4, 5 or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.}\n\\cvarg{R}{The rectification transformation in object space (3x3 matrix). \\texttt{R1} or \\texttt{R2}, computed by \\cvCppCross{StereoRectify} can be passed here. If the matrix is empty, the identity transformation is used}\n\\cvarg{P}{The new camera matrix (3x3) or the new projection matrix (3x4). \\texttt{P1} or \\texttt{P2}, computed by \\cvCppCross{StereoRectify} can be passed here. If the matrix is empty, the identity new camera matrix is used}\n\\end{description}\n\nThe function is similar to \\cvCross{Undistort2}{undistort} and \\cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap}, but it operates on a sparse set of points instead of a raster image. Also the function does some kind of reverse transformation to \\cvCross{ProjectPoints2}{projectPoints} (in the case of 3D object it will not reconstruct its 3D coordinates, of course; but for a planar object it will, up to a translation vector, if the proper \\texttt{R} is specified).\n\n\\begin{lstlisting}\n// (u,v) is the input point, (u', v') is the output point\n// camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1]\n// P=[fx' 0 cx' tx; 0 fy' cy' ty; 0 0 1 tz]\nx\" = (u - cx)/fx\ny\" = (v - cy)/fy\n(x',y') = undistort(x\",y\",dist_coeffs)\n[X,Y,W]T = R*[x' y' 1]T\nx = X/W, y = Y/W\nu' = x*fx' + cx'\nv' = y*fy' + cy',\n\\end{lstlisting}\n\nwhere undistort() is approximate iterative algorithm that estimates the normalized original point coordinates out of the normalized distorted point coordinates (\"normalized\" means that the coordinates do not depend on the camera matrix).\n\nThe function can be used both for a stereo camera head or for monocular camera (when R is \\cvC{NULL}\\cvPy{None}\\cvCpp{empty}).\n", "meta": {"hexsha": "96edb875968f27cea20e696243761f356f6a5ff0", "size": 109140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "to/lang/OpenCV-2.2.0/doc/calib3d.tex", "max_stars_repo_name": "eirTony/INDI1", "max_stars_repo_head_hexsha": "42642d8c632da53f60f2610b056547137793021b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "to/lang/OpenCV-2.2.0/doc/calib3d.tex", "max_issues_repo_name": "eirTony/INDI1", "max_issues_repo_head_hexsha": "42642d8c632da53f60f2610b056547137793021b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2016-11-24T10:46:39.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-10T07:24:15.000Z", "max_forks_repo_path": "to/lang/OpenCV-2.2.0/doc/calib3d.tex", "max_forks_repo_name": "eirTony/INDI1", "max_forks_repo_head_hexsha": "42642d8c632da53f60f2610b056547137793021b", "max_forks_repo_licenses": ["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.9720670391, "max_line_length": 806, "alphanum_fraction": 0.7446948873, "num_tokens": 30498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6390874885308283}}
{"text": "% -*- root: 00-main.tex -*-\n\n\\renewcommand{\\theequation}{A.\\arabic{equation}}\n\\renewcommand{\\thesubsection}{Appendix \\arabic{subsection}}\n\n\\section*{Appendix}\n\n\\subsection{Simplifying the regularization term}\\label{app:reg_term}\nThe exponentials of the Thikonov regularization prior \\eqref{eq:regseg-thikonov} have the general form\n  $\\vec{v}^T \\mathbf{M} \\vec{v}$.\nIf $\\mathbf{M}$ is a $n \\times n$ diagonal matrix such that $\\mathbf{M} = \\vec{m} \\, \\mathbf{I}_n$,\n  then:\n\n\\begin{equation*}\n\\vec{v}^T \\mathbf{M} \\vec{v} = \\vec{m} \\cdot (\\vec{v}^T \\mathbf{I}_n \\vec{v}) = \\vec{m} \\cdot \\vec{v}^{\\circ2},\n\\end{equation*}\n  where we have introduced the Hadamard power notation\\footnote{The Hadamard power of a matrix or a vector\n  is the power of its elements $\\mathbf{M}^{\\circ p} = ({m_{ij}}^{p})$}.\n\nIn general, the anisotropy of the distortion field is aligned with the \n  voxel coordinate system, so\n  $\\mathbf{A}$ and $\\mathbf{B}$ of \\eqref{eq:regseg-energy} can be simplified to diagonal matrices\n  to regularize the registration process, such that\n  $\\mathbf{A}= \\, \\boldsymbol{\\alpha}\\,\\vec{I}_n$ and\n  $\\mathbf{B}= \\, \\boldsymbol{\\beta}\\,\\vec{I}_n$.\nBy substituting into equation \\eqref{eq:regseg-energy}, we obtain:\n\n  \\begin{align}\n  E(\\vec{u}) &= \\const + \\, \\underset{l}{\\sum} \\int_{\\Omega_l} \\mdist{f'}{l} \\,d\\vec{r} \\,\n  \\ifthenelse{\\boolean{review}}{+}{+ \\notag\\\\ &+}\n  \\int_{\\Omega} \\frac12 \\left[ \\boldsymbol{\\alpha} \\cdot \\vec{u}^{\\circ2} + \\boldsymbol{\\beta} \\cdot (\\nabla \\vec{u})^{\\circ2} \\right] \\,d\\vec{r}.\n  \\label{eq:regseg-app_energy}\n  \\end{align}\n\n\\subsection{Application of the shape-gradients}\\label{app:shape_gradients}\nThe computation of gradients at the locations of the active contours in the\n  instant $t$ is based on the work of \\cite{herbulot_segmentation_2006}.\nLet $F(\\vec{r})$ be an ``arbitrary'' function over the image domain\n  $\\Omega = \\Omega_l \\cup \\Omega_m$ split in two regions $l$ and\n  $m$, and $\\Gamma_{l,m}$ a closed boundary between them.\nWe now derive the domain integral w.r.t. $t$:\n\n  \\begin{equation}\n  \\frac{\\partial}{\\partial t} \\int_\\Omega F(\\vec{r}) d\\vec{r} =\n  \\int_\\Omega \\frac{\\partial}{\\partial t}F(\\vec{r}) d\\vec{r}\n  - \\int_{\\Gamma_{l,m}} F(\\vec{r}) \\left\\langle \\frac{\\partial \\Gamma_{l,m} }{\\partial t},\n  N_{\\Gamma_{l,m}}\\right\\rangle d\\vec{r},\n  \\end{equation}\n%\n  where $\\left\\langle\\frac{\\partial\\Gamma_{l,m}}{\\partial t}, N_{\\Gamma_{l,m}}\\right\\rangle$ is\n  the projection of the boundary movement on the unit inward normal $N_{\\Gamma_{l,m}}$.\nAssuming that the region descriptors $\\{\\boldsymbol{\\mu}_l, \\boldsymbol{\\Sigma}_l\\}$ vary slowly enough, we can consider\n  that $\\frac{\\partial}{\\partial t} F(\\vec{r}) = 0$ and thus:\n\n  \\begin{equation}\n  \\frac{\\partial}{\\partial t} \\int_\\Omega F(\\vec{r}) d\\vec{r} =\n  - \\int_{\\Gamma_{l,m}} F(\\vec{r}) \\left\\langle \\frac{\\partial \\Gamma_{l,m} }{\\partial t},\n  N_{\\Gamma_{l,m}}\\right\\rangle d\\vec{r}.\n  \\label{eq:regseg-shape_gradients}\n  \\end{equation}\n\nThe equation \\eqref{eq:regseg-shape_gradients} is discretized as follows.\nFirst, the surface between limiting regions $l$ and $m$ ($\\Gamma_{l,m}$) is explicitly represented by\n  a discrete set of vertices $\\vec{v}_i$, with $i \\in \\{0, \\ldots, N_p -1 \\}$.\nConsequently, the inwards normal of the surface $N_{\\Gamma_{l,m}}$ is represented by the discrete\n  set of normals $\\hat{\\vec{n}}_i$ at each vertex of the mesh.\nThe resulting summation is, therefore, discrete and the integral operator is replaced by the sum:\n\n  \\begin{align}\n  \\frac{\\partial}{\\partial t} \\int_\\Omega F(\\vec{r}) d\\vec{r} &=\n  \\underbracket{\\cancel{\\int_\\Omega \\frac{\\partial}{\\partial t}F(\\vec{r}) d\\vec{r} }}_{\\text{Functional's evolution}}\n  - \\underbracket{\\int_{\\Gamma_{l,m}} F(\\vec{r}) \\left\\langle \\frac{\\partial \\Gamma_{l,m}}{\\partial t},\n  N_{\\Gamma_{l,m}}\\right\\rangle d\\vec{r}}_{\\text{Shape's evolution}} \\notag \\\\\n  & = - \\underset{p}{\\sum} \\frac{1}{A_p} \\underset{i}{\\sum} \\, a_i \\, F(\\vec{v}_i) \\left\\langle \\underbracket{\\frac{\\partial \\vec{v}_i}{\\partial t}}_{\\text{speed of }\\vec{v}_i},\n  \\hat{\\vec{n}}_{i}\\right\\rangle.\n  \\label{eq:regseg-shape_gradient_orig}\n  \\end{align}\nwhere $a_i$ is the area corresponding to vertex $\\vec{v}_i$, and $A_p = \\sum_i a_i$ is the total area of the surface $p$.\nIn the following, we will refer as $w_{p,i} = a_i / A_p $ to the area contribution of $\\vec{v}_i$ to the\n  total area of the surface it belongs to.\nFor simplicity, the sum over $p$ can be also removed, as the vertices belong to only one of the total $P$ contours.\n\nThen, the speed of $\\vec{v}_i$ is discretized using the artificial time-step parameter $\\delta$, as the displacement\n  $\\frac{\\partial \\vec{v}_i}{\\partial t} = \\vec{v}_i(\\delta = t+1) - \\vec{v}_i(\\delta = t)$:\n\n  \\begin{equation}\n  \\frac{\\partial}{\\partial t} \\int_\\Omega F(\\vec{r}) \\, d\\vec{r} =\n  - \\underset{i}{\\sum} w_{p,i} F(\\vec{v}_i) \\frac{\\partial \\vec{v}_i}{\\partial t} \\cdot \\hat{\\vec{n}}_i.\n  \\label{eq:regseg-shape_gradient_disc1}\n  \\end{equation}\n\nSince the energy functional is defined over competing regions, the displacement of $\\vec{v}_i$ will cause\n  an energy exchange between the limiting regions, and therefore $F(\\vec{r})$ must be split in\n  two terms, $F_{in}(\\vec{r})$ corresponding to the interior region and $F_{out}(\\vec{r})$ to the exterior:\n\n  \\begin{equation}\n  \\frac{\\partial}{\\partial t} \\int_\\Omega F(\\vec{r}) \\, d\\vec{r} =\n  - \\underset{i}{\\sum} \\, \\frac{\\partial \\vec{v}_i}{\\partial t} \\cdot\n  \\underbracket{w_{p,i} \\, \\Big[ F_{out}(\\vec{v}_i) - F_{in}(\\vec{v}_i) \\Big] \\hat{\\vec{n}}_i}_{\\bar{s}_i \\text{ in Figure 1}}.\n  \\label{eq:regseg-shape_gradient_disc2}\n  \\end{equation}\n\nThen, we identify the shape gradient contribution $\\vec{g}_k$ on the coefficients $\\vec{u}_k$ of the B-spline grid \n\\revcomment[R\\#1-C4]{to obtain the definition of $\\vec{g}_k$ given in \\eqref{eq:regseg-final_gradient}}:\n\n  \\begin{equation}\n  \\label{eq:regseg-gradient_wshape}\n  \\begin{split}\n  \\vec{g}_k &= - \\underset{i}{\\sum} \\left\\langle \\frac{\\partial \\vec{v}_i'}{\\partial \\vec{u}_k}, \\bar{s}_i'\\right\\rangle \\\\\n  \\text{with }\n  \\bar{s}_i' &= w_i \\left[ \\mdist{f_i'}{out} - \\mdist{f_i'}{in} \\right] \\, \\hat{\\vec{n}}_i, \\\\\n  \\text{and }\n  \\frac{\\partial \\vec{v}_i'}{\\partial \\vec{u}_k} &=\n  \\frac{\\partial}{\\partial \\vec{u}_k} \\left\\{ \\vec{v}_i + \\sum_k \\psi_k(\\vec{v}_i) \\vec{u}_k \\right\\} = \\psi_k(\\vec{v}_i)\\, \\hat{\\vec{e}},\n  \\end{split}\n  \\end{equation}%\n\\revcomment[R\\#1-C4]{where $\\psi_k$ and $\\vec{u}_k$ define our B-spline deformation model (\\autoref{eq:regseg-nodes_tfm})} and\n  $\\hat{\\vec{e}}$ is the coordinates system's unit vector.\n\n\n", "meta": {"hexsha": "e1eaf3d012332a0099a9629083dd2a45e3f90a6f", "size": 6589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2015-NeuroImage/08-appendix-00-shapepriors.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-00-shapepriors.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-00-shapepriors.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": 54.4545454545, "max_line_length": 177, "alphanum_fraction": 0.6709667628, "num_tokens": 2356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6390603445092725}}
{"text": "\\section{Features}\n\\label{sec:Features}\nEach sample is split into windowed and overlapping blocks. Different features are calculated on each block. The blocks have a length of 20~ms, 50~\\% overlap and are Hann windowed.\\\\\nFeatures used are the RMS, peak, crest factor, spectral centroid, logarithmic spectral centroid, spectral variance, spectral skewness, spectral flatness, spectral brightness and mean spectral absolute slope. They are described in detail as follows.\\\\\nFor every feature, the block is given as $x$, $x[k]$ is a frame within the block, $K$ is the number of frames within one block. The FFT of the block is $X$, $X[n]$ is an FFT bin, $2 N$ is the FFT-Length. The features are calculated as follows:\n\\begin{description}\n    \\item[RMS:]\n        The RMS is a measure for the energy of the block.\n        \\[\n            \\mathrm{RMS} = \\sqrt{\\frac{1}{K}\\sum_{k=0}^{K-1}{x[k]^2}}\n        \\]\n    \\item[Peak:]\n        The peak is simply the maximum of all absolute values within the block.\n        \\[\n            \\mathrm{PK} = \\max{|x[k]|}\n        \\]\n    \\item[Crest Factor:]\n        The ratio of the peak to the RMS value is the crest factor.\n        \\[\n            \\mathrm{CF} = \\frac{\\mathrm{PK}}{\\mathrm{RMS}}\n        \\]\n    \\item[Spectral Centroid:]\n        The spectral centroid is the normalized frequency weighted mean of the absolute spectrum. The frequency is normalized to the sampling frequency.\n        \\[\n            \\mathrm{SC} = \\sum_{n=0}^{N}{|X[n]| \\cdot \\frac{n}{2N}}\n        \\]\n\n    \\item[Logarithmic Spectral Centroid:]\n        To account for human frequency perception, the spectral centroid is calculated relative to a logarithmic frequency axis as well.\n        \\[\n            \\mathrm{LSC} = \\sum_{n=0}^{N}{|X[n]| \\cdot \\log{\\frac{n}{2 N}+1}}\n        \\]\n    \\item[Spectral Variance:]\n        The spectral variance gives a value of the change of the absolute spectrum over all frequencies.\n        \\[\n            \\mathrm{SV} = \\sum_{n=0}^{\\frac{K}{2}}{(|X[n]|-\\overline{|X[n]|})^2}\n        \\]\n        with the spectral mean\n        \\[\n            \\overline{|X[n]|} = \\frac{1}{N+1}\\sum_{n=0}^{N}{|X[n]|}.\n        \\]\n    \\item[Spectral Skewness:]\n    \t\tThe skewness of the absolute spectrum shows how much its distribution leans towards high or low frequencies.\n        \\[\n            \\mathrm{SS} = \\sum_{n=0}^{\\frac{K}{2}}{(|X[n]|-\\overline{|X[n]|})^3}.\n        \\]\n    \\item[Spectral Flatness:]\n        Given the spectral mean $\\overline{|X[n]|}$ and the geometric spectral mean\n        \\[\n            \\overline{|X[n]|}_\\mathrm{geom} = \\sqrt[N+1]{\\prod_{n=0}^{N}{|X[n]|}},\n        \\]\n        the spectral flatness is calculated as the ratio of them.\n        \\[\n        \t\t\\frac{\\overline{|X[n]|}_\\mathrm{geom}}{\\overline{|X[n]|}}\n        \\]\n    \\item[Spectral Brightness:]\n        The spectral brightness is the ratio of high to the low frequency energy. To get the energy of low and high frequency, the weighted sum of the absolute spectrum is taken. The weighting of the high frequency bins is given as\n        \\begin{eqnarray*}\n            w_\\mathrm{high} &=& 0.5 - \\frac{\\cos(\\omega)}{2}\\\\\n            w_\\mathrm{low} &=& \\frac{\\cos(\\omega)}{2} + 0.5\n        \\end{eqnarray*}\n        with $\\omega$ as $N$ logarithmic ordered values in the range $[0;~\\pi]$. The point of intersection between the low and high frequency weighting was set to approximately 2~kHz.\n        \\[\n            \\mathrm{SB} = \\frac{\\sum_{n=0}^{\\frac{K}{2}}{|X[n]|\\cdot w_\\mathrm{high}}}{\\sum_{n=0}^{\\frac{K}{2}}{|X[n]|\\cdot w_\\mathrm{low} }}\n        \\]\n    \\item[Mean Absolute Spectral Slope:]\n        The mean of the absolute spectral slope gives the amount of change in the spectrum over the frequency. It is calculated by\n        \\[\n            \\mathrm{MASS} = \\frac{1}{N}\\sum_{n=1}^{N}{||X[n]|-|X[n-1]||}\n        \\]\n\\end{description}\nThe features of all blocks of all samples are saved within a Pandas DataFrame\\footnote{http://pandas.pydata.org/}. This makes them easily searchable and saveable.", "meta": {"hexsha": "724c6fe5392389fdd683e6ee8a4daffd6fe81ece", "size": 4004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Features.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/Features.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/Features.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": 55.6111111111, "max_line_length": 250, "alphanum_fraction": 0.6136363636, "num_tokens": 1130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6390603393057274}}
{"text": "%-------------------------------------------------------------------------------\n\\section{Working Example}\n%-------------------------------------------------------------------------------\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{0.48\\columnwidth}\n    \\includegraphics[width=\\linewidth]{figs/sosp-working_ex3}\n    \\caption{\\label{fig:working_ex1}Proximal cost function at $\\bar{x} = 7$.}\n  \\end{subfigure}\n  \\hspace{0.1cm}\n  \\begin{subfigure}[b]{0.48\\columnwidth}\n    \\includegraphics[width=\\linewidth]{figs/sosp-working_ex2}\n    \\caption{\\label{fig:working_ex2}Evaluated Proximal Gradient for $\\bar{x} = 7$.}\n  \\end{subfigure}\n  \\vspace{-15pt}\n  \\caption{\\label{fig:working_ex}Example of Proximal Gradient Evaluation.}\n  \\vspace{-15pt}\n\\end{figure}\n\nTo give a better intuition for how proximal gradients work in practice, we provide a working example. Consider the function $f(x) =   x \\texttt{\\&} 4$ shown in figure \\ref{fig:ex_funcs}, and suppose we are evaluating it with $\\bar{x} = 7$. This type of bitwise operation is common in programs that parse a file for input, since they frequently need to check if flag bits are set in a header or section header of the file. However, discrete functions like bitwise operations are nondifferentiable so we instead evaluate the proximal gradient.\n\nTo evaluate the proximal gradient on $f\\left(x\\right)$, the sampling region must first be defined. \\tc{x \\& 4} has a Lipschitz Constant of $K=4$ (any bitwise operation with a constant has a Lipschitz Constant with the value of the most significant bit in the constant), so assuming a proximal scaling factor of $\\lambda = 1$, the sampling distance bound is $2K = 8$. Therefore, a total of 16 samples must be taken, for $x = [-1, 15]$, and the cost function of the proximal operator, $f(x) + ||x - \\bar{x}||_2^2$ evaluated for each possible $x$. Figure \\ref{fig:working_ex1} shows the value of the cost function near $x = 7$, there is a clear minimum at $x=8$, where $f\\left(8\\right) + ||8-7||_2^2 = 1$, so the proximal operator evaluates to $x=8$. The proximal gradient is then $prox_{\\nabla f}\\left(7\\right) = \\frac{f\\left(7\\right) - f\\left(8\\right)}{7 - 8} = -4$.\n\n\n", "meta": {"hexsha": "c2d3a4bed242e89643e7fb1b58439980af53215e", "size": 2172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "submissions/sosp2019/sections/working_example.tex", "max_stars_repo_name": "sillywalk/grazz", "max_stars_repo_head_hexsha": "a0adb1a90d41ff9006d8c1476546263f728b3c83", "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": "submissions/sosp2019/sections/working_example.tex", "max_issues_repo_name": "sillywalk/grazz", "max_issues_repo_head_hexsha": "a0adb1a90d41ff9006d8c1476546263f728b3c83", "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": "submissions/sosp2019/sections/working_example.tex", "max_forks_repo_name": "sillywalk/grazz", "max_forks_repo_head_hexsha": "a0adb1a90d41ff9006d8c1476546263f728b3c83", "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.5384615385, "max_line_length": 865, "alphanum_fraction": 0.6731123389, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.6390517405784424}}
{"text": "\\section{Euclidean Structure}\n\n\\subsection{Exercise 1}\nApplying Cauchy-Schwarz gives that $(x, y) \\leq \\norm{x}\\norm{y} = \\norm{x}$, which yields\nthe desired result.\n\n\\subsection{Exercise 2}\nBoth of these just follow from the fact that a linear space with Euclidean structure is\nisomorphic to $R^k$, which has the desired properties. The following feel like cop-out\nsolutions, but I feel they're fair given this isn't supposed to be a real analysis text.\n\n(i) Let $x_k = \\sum_i a_i^{(k)} x^{(i)}$ and $x_j = \\sum_i a_i^{(j)} x^{(i)}$. Then we have that\n$\\norm{x_k - x_j} \\to 0 \\implies \\abs{a_i^{(k)} - a_i^{(j)}} \\to 0$. Since $\\mathbb{R}$ is\ncomplete, $a_i^{(n)} \\to a_i$ for some $a_i \\in \\mathbb{R}$. Thus $x_k \\to x = \\sum a_i x^{(i)}$.\n\n(ii) Same logic as (i): the individual $a_i^{(n)}$ have convergent subsequences.\n\n\\subsection{Exercise 3}\nWe also need to assume $X$ is finite dimensional (I think).\n\n(i) Since $X$ is finite dimensional, we have that $x = \\sum a_i e^{(i)}$ for some basis $e^{(i)}$. Let\n$v$ be the vector whose components are $v_i = \\norm{Ae^{(i)}}$. Then\n\\begin{align*}\n        \\norm{Ax} &= \\norm{\\sum a_i Ae^{(i)}} \\\\\n                  &= \\norm{(x, v)} \\\\\n                  &\\leq \\norm{x} \\norm{v}\n\\end{align*}\nSince $\\norm{v}$ is a constant, $\\norm{Ax}$ is bounded on the unit sphere.\n\n(ii) We have that $\\norm{A} = \\max_x \\frac{\\norm{Ax}}{\\norm{x}} = \\max_x \\norm{Ax}$.\n The result then follows from $(Ax, y) \\leq \\norm{Ax}$.\n\n(iii) Let $v$ be as in (i). Then $\\norm{Ax_i - Ax_j} \\leq \\norm{A} \\norm{x_i - x_j}$. Since\n$\\norm{A} \\leq \\norm{v}$ from (i), we are done (we can make $ \\norm{x_i - x_j}$ as small\nas we'd like).\n\n\\subsection{Exercise 4}\nFollows immediately from $(Ax, y) = (x, A^{*}y)$ and Exercise 3 (ii).\n\n\\subsection{Exercise 5}\nLet $x = y_1 + y_1^{\\perp}$ and $z = y_2 + y_2^{\\perp}$. Then\n\\begin{align*}\n        (P_Y x, z) &= (y_1, y_2 + y_2^{\\perp}) \\\\\n                   &= (y_1, y_2) + 0 \\\\\n                   &= (y_1, y_2) + (y_1^{\\perp}, y_2) \\\\\n                   &= (x, P_Y z)\n\\end{align*}\n\n\\subsection{Exercise 6}\nReflection across $x_3 = 0$ sends $(x_1, x_2, x_3) \\to (x_1, x_2, -x_3)$. Hence it can be represented as\n\\begin{align*}\n       A =\n       \\begin{pmatrix}\n               1 & 0 & 0 \\\\\n               0 & 1 & 0 \\\\\n               0 & 0 & -1\n       \\end{pmatrix}\n\\end{align*}\nWhich has determinant -1 (product of diagonal terms).\n\n\\subsection{Exercise 7}\n(a) If $A$ is orthogonal, then $A^{*}A = I$. Since $A^{*} = A^{\\top}$ in this case, we immediately get\nthat the column vectors of $A$ are pairwise orthogonal unit vectors. Similarly, a matrix $A$ with\npairwise orthogonal unit vectors satisfies $A^{*} A = I$, implying that it is orthogonal.\n\n(b) $A^{*} A = I \\implies A^{*} = A^{-1} \\implies A A^{*} = I$ so $A$ orthogonal implies $A^{*}$ orthogonal.\nThe result then follows from plugging $A^{*}$ into (a).\n\n\\subsection{Exercise 8}\nThe proof is almost identical to the non-complex case.\n\\begin{align*}\n        (x + ty, x + ty) &= (x, x) + (ty, x) + (x, ty) + \\norm{t}^2 (y, y) \\\\\n                         &= (x, x) + t(y, x) + \\bar{t}(x, y) + \\norm{t}^2 (y, y)\n\\end{align*}\nPlugging in $t = \\frac{(x, y)}{(y, y)}$ and using the fact that $(x + ty, x + ty) \\geq 0$ for all\ncomplex $t$ gives the desired inequality.\n\n\\subsection{Exercise 9}\n\\subsubsection{Theorem 4}\nThe proof of Theorem 4 is the same, except we use $y = \\sum \\bar{b_k} x^{(k)}$ instead.\n\n\\subsubsection{Theorem 5}\nNo changes need to be made to the proof of Theorem 5.\n\n\\subsubsection{Theorem 6}\nAgain, no changes need to be made.\n\n\\subsubsection{Theorem 7}\nNo changes need to be made here either, since $(y, y^{\\perp}) = 0 \\implies \\overline{(y, y^{\\perp})} = 0$.\n\n\\subsection{Exercise 10}\n\\subsubsection{Theorem 8}\nParts (i)-(iii) remain the same. For part (iv), we see that \n\\begin{align*}\n        (Ax, y) = (x, A^{*}y) = \\overline{(A^{*}y, x)} = \\overline{(y, A^{**}x)} = (A^{**}x, y)\n\\end{align*}\n\n\\subsubsection{Theorem 9}\n(i) $\\norm{kA} = \\max_x \\frac{\\sqrt{(kAx, kAx)}}{\\norm{x}} = \\sqrt{k\\bar{k}} \\norm{A} = \\norm{k} \\norm{A}$.\n\n(ii) Applying triangle inequality to the definition of norm gives the result.\n\n(iii) Comes immediately from $\\norm{A(Bx)} \\leq \\norm{A} \\norm{Bx}$.\n\n\\subsection{Exercise 11}\nFollows from $\\norm{M(x) - M(y)} = (\\bar{x} - \\bar{y}) (x - y) = \\norm{x - y}$.\n\n\\subsection{Exercise 12}\nSame idea as proof of Theorem 10.\n\n\\subsection{Exercise 13}\nAs in Exercise 7, $M^{*} M = I \\implies M^{*} = M^{-1} \\implies M M^{*} = I$. Similarly,\n$M^{*} = M^{-1} \\implies (M^{*})^{-1} M^{-1} = I$.\n\n\\subsection{Exercise 14}\nAssociativity follows from associativity of composition. From Exercise 13, if $M$ is unitary, so is $M^{-1}$.\nFinally, $I$ is also unitary, so the unitary maps are a group with unit $I$.\n\n\\subsection{Exercise 15}\nAgain, same idea as in Theorem 10: $\\det M^{*} \\det M = 1$.\n\n\\subsection{Exercise 16}\n\\begin{align*}\n        (Mf, Mg) = \\int_{-1}^{1} m^2(s) f(s) \\bar{g}(s) = \\int_{-1}^{1} f(s) \\bar{g}(s)\n\\end{align*}\n\n", "meta": {"hexsha": "97abaf00b66e8c2024b26ab8c723f8f50bd7f033", "size": 4992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": 39.3070866142, "max_line_length": 109, "alphanum_fraction": 0.5971554487, "num_tokens": 1825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6390517387757118}}
{"text": "\n\n\\subsection{Looking from a \\emph{modular} perspective}\n\nGiven a Riordan array $\\mathcal{M}$, we are interested to look at it\ndoing a transformation of the matrix $\\lbrace m_{nk}\\rbrace_{n,k\\in\\mathbb{N}}$,\nbuilding a new one defined by $\\lbrace m_{nk}\\mod\\,p\\rbrace_{n,k\\in\\mathbb{N}}$,\nwhere $p\\in\\mathbb{N}$ is a module, usually a \\emph{prime} number.\n\nThis transformation allows us to represent any array $\\mathcal{M}$ pictorially,\nassociating a colour to each \\emph{remainder class} of $\\equiv_{p}$ relation:\ninspecting the produced coloured triangle it is possible to recognize some\npatterns in the colouring and we will see that for same classes of Riordan\narrays, these colourings are pretty interesting, while for other classes they\nseems to be quite random.\n\nWe will attempt to formally prove what can be see in the pictures, in\nparticular we will discuss the Pascal array $\\mathcal{P}$ and the Catalan array\n$\\mathcal{C}$.  We believe that this kind of study is important in order to\nunderstand and to make conjectures about the combinatorial structure underlying\nthose arrays and, why not, any array $\\mathcal{M}$ in general.\n\n\\input{Chapters/back-to-the-basics/main-idea-modular-characterization/assembling-include-figures}\n\nIn \\autoref{fig:main:idea:modular:characterization} is shown this kind of study,\nand it will be addressed in \\autoref{ch:modular:characterization}.\n\n\\subsection{Looking for characterizations, again}\n\nAltough pretty interesting and fairly general characterizations exists for\na coefficient $m_{nk}$ in a Riordan array $\\mathcal{M}$, we would like to\nrework some of them, looking from different points of view.\n\nIn particular we provide a new characterization, called $h$-\\emph{characterization},\nwhich allows us to rewrite a Riordan array $\\mathcal{M}=(d(t),h(t))$ only\nusing function $h$, namely $\\mathcal{M}_{h(t)}(\\alpha(h(t)),h(t))$, for some\nfunction $\\alpha$ in the ``variable'' $h(t)$. If the given array $\\mathcal{M}$\nis in the \\emph{Renewal} subgroup, then the $h$-characterization shows the $A$-sequence's\n\\ac{gf} in the first component of array $\\mathcal{M}_{h(t)}$, automagically.\n\nMoreover, we provide another derivation of a concept similar to $A$-matrix characterization,\nfound by reasoning from a \\emph{column}'s \\ac{gf} point of view, instead of\nfocusing on the combination for a generic element $m_{n+1,k+1}$. This study will be\naddressed in \\autoref{ch:h:characterization}.\n\n\\subsection{Python implementation}\n\nIn order to support the present work, we have coded a bunch of classes in the\n\\emph{Python} programming language, that implement a subset of \\emph{Riordan\ngroup} theory. We rest on \\emph{Sage} \\cite{sage} mathematical framework in\norder to do hard math computation and our implementation aims to be truly\nobject oriented and very minimal, in order to be extended easily. \n\nNonetheless, it is possible to play with Riordan arrays, inverting them, doing\nraw matrix expansions and building a modular representation producing\n\\LaTeX\\,ready code.  All pictures in this document are generated by compilation\nof \\emph{TikZ} statements, produced by our implementation.\n\n", "meta": {"hexsha": "c9d6f613959e1be4e3f0ec861cff40b69f838dc2", "size": 3130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classicthesis/Chapters/introduction/targets.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/introduction/targets.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/introduction/targets.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": 53.0508474576, "max_line_length": 97, "alphanum_fraction": 0.7734824281, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.803173791645582, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6390517350271122}}
{"text": "\\chapter{Game Theory}\n\\label{chap:game-theory}\n\nAs a warm-up, we include the following result.\n\n\\begin{lemma}\n\tFor every game $G$, there exists at least one individually rational strategy profile.\n\tIn other words, $\\mathcal{S}_1(G) \\ne \\emptyset$.\n\\end{lemma}\n\n\\begin{proof}\n\tFor every player $i \\in P$ we denote $m_i \\in S_i$ the strategy that lower-bounds utility of player $i$:\n\t\\[\n\t\tm_i = \\text{arg} \\max_{t_i \\in S_i} \\min_{\\vect_{-i} \\in S_{-i}} u_i(t_i, \\vect_{-i}).\n\t\\]\n\tWe claim that the strategy profile $\\mm = (m_1, \\dots, m_n) \\in S$ is individually rational.\n\tIf $\\mm$ was not individually rational, there would have to be some player $j \\in P$ and a strategy $s_j^* \\in S_j$ that would ensure a better worst-case payoff: $\\min_{\\vecs_{-j} \\in S_{-j}}u_j(s_j^*, \\vecs_{-j}) > u_j(\\mm)$ which would contradict the choice of~$m_j$.\n\\end{proof}\n\nThe main goal of this work is to create a gaming platform of human vs. computer, which trains the human to play towards a PTE.\nThis \\enquote{training} should be conducted by the human playing many games and trying to figure out how to maximize their payoffs.\nThe primary means of affecting this process is through choosing an appropriate strategy chosen by the computer in each play.\nHow precisely this response should be chosen is not clear and needs to be determined by experiments.\n\nThis chapter introduces three new equilibria which might be useful for the cause described in the previous paragraph: the perfectly transparent best response equilibrium and the perfectly transparent optimal profile equilibrium.\nThen, we discuss some relations between these two equilibria and between the other equilibria introduced in \\autoref{chap:background}.\n\nWe start by defining the most natural way to translate the preemption process for determining a PTE to a notion of best response.\n\n\\begin{definition}[Perfectly transparent best response]\n\tIn a game (possibly with ties) $G = (P, S, \\uu)$ we say a strategy $s_i^* \\in S_i$ is a perfectly transparent best response to a strategy profile $\\vecs_{-i} \\in S_{-i}$ of the opponent players if it is the Nashian best response to $\\vecs_{-i}$ across all profiles that survive the maximum possible number of preemption rounds.\n\tThe weak/strict notion is inherited from the Nashian best response.\n\tFormally $s_i^*$ is a (\\textit{weak}) perfectly transparent best response if either $(s_i^*, \\vecs_{-i})$ is a PTE or $\\exists k \\in \\N: (s_i^*, \\vecs_{-i}) \\in \\mathcal{S}_k(G), (s_i, \\vecs_{-i}) \\notin \\mathcal{S}_{k+1}(G) \\forall s_i \\in S_i$, and\n\t\\[\n\t\t\\forall (s_i', \\vecs_{-i}) \\in \\mathcal{S}_k(G): u_i(s_i^*, \\vecs_{-i}) \\ge u_i(s_i', \\vecs_{-i}).\n\t\\]\n\tIt is a \\textit{strict} perfectly transparent best response if either $(s_i^*, \\vecs_{-i})$ is a PTE or $\\exists k \\in \\N: (s_i^*, \\vecs_{-i}) \\in \\mathcal{S}_k(G), (s_i, \\vecs_{-i}) \\notin \\mathcal{S}_{k+1}(G) \\forall s_i \\in S_i$, and\n\t\\[\n\t\t\\forall (s_i', \\vecs_{-i}) \\in \\mathcal{S}_k(G): s_i' \\ne s_i^* \\implies u_i(s_i^*, \\vecs_{-i}) > u_i(s_i', \\vecs_{-i}).\n\t\\]\n\\end{definition}\n\nA best response naturally induces an equilibrium.\n\n\\begin{definition}[Perfectly transparent best response equilibrium]\n\tWe say a strategy profile $\\vecs = (s_1, \\dots, s_n) \\in S$ is a (\\textit{weak}) perfectly transparent best response equilibrium (PTBRE) if $s_i$ is a (weak) perfectly transparent best response to $\\vecs_{-i}$ for all players $i \\in P$.\n\t\n\tSimilarly, $\\vecs$ is a \\textit{strict} PTBRE if $s_i$ is a strict perfectly transparent best response to $\\vecs_{-i}$ for all players $i \\in P$.\n\\end{definition}\n\nIt is easy to see that for any game, if a strategy profile is a PTE, then it is also a PTBRE.\nOur initial hope was that the other direction also holds, so PTE and PTBRE are equivalent.\nUnfortunately, this is not true, as we can see in the following sections.\n\nNext, we can consider the following situation: we are playing a game of 2 players, and we know that our opponent's strategy will always be a perfectly transparent best response to our strategy.\nIn this case, what strategy should we choose to maximize our payoff?\nThis is captured in the following definition.\n\n\\begin{definition}[Perfectly transparent $i$-best profile]\n\tFor a game $G = (P, S, \\uu)$ of two players with $P = \\{i, j\\}$\n\twe say a strategy profile $\\vecs = (s_1, s_2) \\in S$ is a (\\textit{weak}) perfectly transparent $i$-best profile if\n\t$j$'s strategy $s_j$ is a (weak) perfectly transparent best response to $s_i$, and\n\t\\[\n\t\t\\forall s_i' \\in S_i: u_i(\\vecs) \\ge u_i\\left(s_i', b(s_i')\\right),\n\t\\]\n\twhere $b(s_i')$ is some weak perfectly transparent best response of player $j$ to $s_i'$ (note that there may be multiple best responses to $s_i'$ but they must all have the same utility for player $i$).\n\n\tIt is a \\textit{strict} perfectly transparent $i$-best profile if $s_j$ is a strict perfectly transparent best response to $s_i$ and\n\t\\[\n\t\t\\forall s_i' \\in S_i: s_i' \\ne s_i \\implies u_i(\\vecs) > u_i\\left(s_i', b(s_i')\\right).\n\t\\]\n\tNote that we still consider $b(s_i')$ to be a weak best response even in the strict definition.\n\tThis is to ensure that every strict best profile is also a weak best profile.\n\\end{definition}\n\nAgain, this notion naturally induces an equilibrium.\n\n\\begin{definition}[Perfectly transparent best profile equilibrium]\n\tFor a game of two players, we say that a strategy profile $\\vecs \\in S$ is a (\\textit{weak}) perfectly transparent best profile equilibrium (PTBPE) if $\\vecs$ is a (weak) perfectly transparent $i$-best profile for both players $i \\in P$.\n\n\tSimilarly, $\\vecs$ is a \\textit{strict} PTBPE if it is a strict perfectly transparent $i$-best profile for both $i \\in P$.\n\\end{definition}\n\nAnother situation that we consider is the following: we are playing a game of two players, and the strategy that we are going to choose is a perfectly transparent best response to the opponent's strategy.\nWhat is the best payoff that we can get---that is, what payoff would we get if the opponent knew we would choose a perfectly transparent best response and were optimizing for \\textit{our} payoff instead of theirs?\nThis is captured by the following definition.\n\n\\begin{definition}[Perfectly transparent $i$-optimal profile]\n\tFor a given game $G = (P, S, \\uu)$ and player $i \\in P$ we say a strategy profile $\\vecs = (s_1, \\dots, s_n) \\in S$ is a (\\textit{weak}) perfectly transparent $i$-optimal profile if\n\t$s_i$ is a (weak) perfectly transparent best response to $\\vecs_{-i}$ and\n\t\\[\n\t\t\\forall \\vecs'_{-i} \\in S_{-i}: u_i(\\vecs) \\ge u_i\\left(b(\\vecs'_{-i}), \\vecs'_{-i}\\right),\n\t\\]\n\twhere $b(\\vecs'_{-i})$ is some weak perfectly transparent best response to $\\vecs'_{-i}$ (note that there may be multiple best responses to $\\vecs'_{-i}$ but they must all have the same utility for player $i$).\n\n\tIt is a \\textit{strict} perfectly transparent $i$-optimal profile if $s_i$ is a strict perfectly transparent best response to $\\vecs_{-i}$ and\n\t\\[\n\t\t\\forall \\vecs_{-i}' \\in S_{-i}: \\vecs_{-i}' \\ne s_{-i} \\implies u_i(\\vecs) > u_i\\left(b(\\vecs_{-i}'), \\vecs_{-i}'\\right).\n\t\\]\n\tNote that even in the strict definition, we still consider $b(\\vecs_{-1})$ to be a weak best response.\n\tThis is to ensure that every strict optimal profile is also a weak optimal profile.\n\\end{definition}\n\nThis definition also induces an equilibrium.\n\n\\begin{definition}[Perfectly transparent optimal profile equilibrium]\n\tWe say that a strategy profile $\\vecs \\in S$ is a (\\textit{weak}) perfectly transparent optimal profile equilibrium (PTOPE) if $\\vecs$ is a (weak) perfectly transparent $i$-optimal profile for all $i \\in P$.\n\n\tSimilarly, $\\vecs$ is a \\textit{strict} PTOPE if it is a strict perfectly transparent $i$-optimal profile for all $i \\in P$.\n\\end{definition}\n\nWhile the other equilibria model selfish behavior, PTOPE models altruistic behavior.\nIt can be seen as the non-Nashian counterpart to the Berge equilibrium \\cite{berge1957theorie}.\n\nRecall that for any game $G = (P, S, \\uu)$, a strategy profile $\\vecs \\in S$ is individually rational if and only if it survives the first preemption round: $\\vecs \\in \\mathcal{S}_1(G)$.\nThis means that every PTE must be individually rational.\nIf we think of these equilibria as sets of strategy profiles in any possible game, we can express this as PTE $\\subset$ IR.\nIt is not hard to see that the inclusion is indeed strict as there are games in which $\\mathcal{S}_2 \\subsetneq \\mathcal{S}_1$, so not all individually rational profiles are PTEs.\n\nIn the rest of this chapter, we present several such inclusion results that help to understand the relations between individual rationality, perfectly transparent best response equilibria, perfectly transparent equilibria, perfectly transparent optimal profile equilibria, and minimax rationalizability.\n\nThese results were obtained by first computing equilibria for all games in large datasets \\cite{bigDataset}, and analyzing the results using Apache Spark.\nMost of the counterexamples found in the Appendix come from these datasets.\nMoreover, not finding counterexamples for certain inclusions initiated many hypotheses that we proved at a later point.`'\nAn overview of all inclusions that we prove or disprove can be found in \\autoref{sec:inclusions-overview} of the Appendix.\n\n\\section{Games with Ties}\n\\label{sec:games-with-ties}\n\nWe start by presenting results about the most general setup: games with ties.\nAll the proofs presented in this section naturally hold also for the more specific cases (symmetric games, games without ties).\nThe results are summarized by a Venn diagram in \\autoref{fig:venn-with-ties}.\n\nWe consider the most interesting result of this section to be that both PTBPE and PTOPE are subsets of PTE.\nThis means that both selfishness and altruism can achieve a perfectly transparent equilibrium under the non-Nashian assumptions.\n\n\\begin{figure}[b]\n\t\\centering\n\t\\begin{tikzpicture}[line width=0.25pt]\n\t\t\\draw (0,0) ellipse (1 and 0.5);\n\t\t\\draw (-0.2,0.2) ellipse (1.5 and 1.1);\n\t\t\\draw (1.75,0) ellipse (1 and 0.5);\n\t\t\\draw (2,0.2) ellipse (1.5 and 1.1);\n\t\t\\draw (0.9,0.3) ellipse (2 and 2.5);\n\t\t\\draw (0.3,0.4) ellipse (3.3 and 3.3);\n\t\t\\draw (1.7,-0.2) ellipse (3.5 and 2.5);\n\t\t\\draw[rounded corners=2ex] (-3.2,4) rectangle (5.5,-3.2);\n\t\t\\draw (4.1,-0.3) ellipse (3.7 and 3);\n\t\t\\node at (-0.25,0) {sPTOPE};\n\t\t\\node at (-0.3,0.8) {PTOPE};\n\t\t\\node at (1.95,0) {sPTBPE};\n\t\t\\node at (1.85,0.8) {PTBPE};\n\t\t\\node at (0.4,1.6) {sPTBRE};\n\t\t\\node at (-1.5,2.0) {PTBRE};\n\t\t\\node at (4.3,0) {PTE};\n\t\t\\node at (-2.5,3) {IR};\n\t\t\\node at (6.5,0) {MR};\n\t\\end{tikzpicture}\n\t\\caption{A Venn diagram depicting the inclusion of different equilibria in games with ties.}\n\t\\label{fig:venn-with-ties}\n\\end{figure}\n\n\\begin{observation}\n\t\\label{th:strict-sub-weak}\n\tWe can see from our definition of PTOPE, PTBPE, and PTBRE that any strategy profile satisfying the strict definition of each equilibrium also satisfies the weak definition of the respective equilibrium.\n\tThus, we have sPTOPE $\\subset$ PTOPE, sPTBPE $\\subset$ PTBPE, and sPTBRE $\\subset$ PTBRE.\n\\end{observation}\n\n\\begin{observation}\n\t\\label{th:ptope-subset-ptbre}\n\tFor any game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTOPE, then it is a PTBRE.\n\tSimilarly, if $\\vecs$ is a strict PTOPE, then it is a strict PTBRE.\n\tThus, we have PTOPE $\\subset$ PTBRE, and sPTOPE $\\subset$ sPTBRE.\n\\end{observation}\n\n\\begin{proof}\n\tIf $\\vecs$ is a PTOPE, it is by definition a perfectly transparent $i$-optimal profile for every player $i \\in P$.\n\tIf $\\vecs$ is a perfectly transparent $i$-optimal profile, then, again by definition, $s_i$ is a perfectly transparent best response to $\\vecs_{-i}$.\n\tThis being true for all $i \\in P$ is precisely the definition of a PTBRE.\n\tThe same argument holds for strict equilibria.\n\\end{proof}\n\n\\begin{lemma}\n\t\\label{th:ptope-subset-pte}\n\tIf a game $G = (P, S, \\uu)$ has a PTOPE $\\vecs \\in S$, then $\\vecs$ is also a PTE, i.e., we have the inclusion PTOPE $\\subset$ PTE.\n\\end{lemma}\n\n\\begin{proof}\n\tFor the sake of deriving a contradiction, suppose that there is a game $G = (P, S, \\uu)$ with a strategy profile $\\vecs = (s_1, \\dots, s_n) \\in S$ such that $\\vecs$ is a PTOPE but not a PTE and let $k$ be the last preemption round in which $\\vecs$ is not eliminated (i.e., $\\vecs \\in \\mathcal{S}_k(G)$ but $\\vecs \\notin \\mathcal{S}_{k+1}(G)$).\n\tBecause $\\vecs$ is eliminated in the $(k+1)$\\textsuperscript{st} round, there must be some player $i \\in P$ with a strategy $s_i^* \\ne s_i$ which causes the elimination:\n\t\\[\n\t\t\\forall \\vecs_{-i}' \\in S_{-i}: (s_i^*, \\vecs_{-i}') \\in \\mathcal{S}_k(G) \\implies u_i(s_i^*, \\vecs_{-i}') > u_i(\\vecs).\n\t\\]\n\tLet $\\vecs_{-i}^* \\in S_{-i}$ be the opponents' profile that minimizes $u_i(s_i^*, \\vecs_{-i}^*)$, subject to $(s_i^*, \\vecs_{-i}^*)\\in \\mathcal{S}_k(G)$ (there must be at least one such profile to cause $\\vecs \\notin \\mathcal{S}_{k+1}(G)$).\n\tLet $b \\in S_i$ be the perfectly transparent best response to $\\vecs_{-i}^*$.\n\tBy the choice of $\\vecs_{-i}^*$, we must have $u_i(b, \\vecs_{-i}^*) \\ge u_i(s_i^*, \\vecs_{-i}^*) > u_i(\\vecs)$.\n\tThis means that $\\vecs$ is not a perfectly transparent $i$-optimal profile, contradicting $\\vecs$ being a PTOPE.\n\\end{proof}\n\n\\begin{lemma}\n\t\\label{th:ptbpe-subset-pte}\n\tIf a game $G = (P, S, \\uu)$ of two players has a PTBPE $\\vecs \\in S$, then $\\vecs$ is a PTE; we have PTBPE $\\subset$ PTE.\n\\end{lemma}\n\n\\begin{proof}\n\tThe proof is very similar to the proof of \\autoref{th:ptope-subset-pte}.\n\tWe suppose for the sake of contradiction that there is a game $G = (P, S, \\uu)$ with $P = \\{1, 2\\}$, and a strategy profile $\\vecs = (s_1, s_2) \\in S$ such that $\\vecs$ is a PTBPE but not a PTE and let $k$ be the last preemption round in which $\\vecs$ is not eliminated (i.e., $\\vecs \\in \\mathcal{S}_k(G)$ but $\\vecs \\notin \\mathcal{S}_{k+1}(G)$).\n\tBecause $\\vecs$ is eliminated in the $(k+1)$\\textsuperscript{st} round, there must be some player $i \\in P$ with a strategy $s_i^* \\ne s_i$ which causes the elimination:\n\t\\[\n\t\t\\forall s_j' \\in S_j: (s_i^*, s_j') \\in \\mathcal{S}_k(G) \\implies u_i(s_i^*, s_j') > u_i(\\vecs),\n\t\\]\n\twhere $j = 3 - i$ is the opponent of $i$ and there is at least one $s_j' \\in S_j$ which satisfies $(s_i^*, s_j') \\in \\mathcal{S}_k(G)$.\n\tLet $b \\in S_j$ be the perfectly transparent best response of player $j$ to $s_i^*$.\n\tWe must have $(s_i^*, b) \\in \\mathcal{S}_k$ and so $u_i(s_i^*, b) > u_i(\\vecs)$.\n\tThis means that $\\vecs$ is not a perfectly transparent $i$-best profile, contradicting $\\vecs$ being a PTBPE.\n\\end{proof}\n\n\\begin{lemma}\n\t\\label{th:ptbpe-subset-ptbre}\n\tIf a game $G = (P, S, \\uu)$ of two players has a PTBPE $\\vecs \\in S$, then $\\vecs$ is a PTBRE.\n\tSimilarly, if $\\vecs$ is a strict PTBPE, then it is a strict PTBRE.\n\tWe have PTBPE $\\subset$ PTBRE, and sPTBPE $\\subset$ sPTBRE.\n\\end{lemma}\n\n\\begin{proof}\n\tSuppose that a game $G = (P, S, \\uu)$ with $P = \\{i, j\\}$ has a PTBPE $\\vecs = (s_i, s_j) \\in S$.\n\tBy definition, this means that $\\vecs$ is a perfectly transparent $i$-best profile, hence $s_j$ is a perfectly transparent best response to $s_i$.\n\tMoreover, $\\vecs$ is a perfectly transparent $j$-best profile, hence $s_i$ is a perfectly transparent best response to $s_j$.\n\tThis implies that $\\vecs$ is a PTBRE.\n\tThe same argument holds for strict equilibria.\n\\end{proof}\n\n\\begin{observation}\n\t\\label{th:pte-subset-ir}\n\tIn any game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTE, then it is individually rational.\n\tWe have PTE $\\subset$ IR.\n\\end{observation}\n\n\\begin{proof}\n\tBy definition, a profile is IR if it survives the first preemption round, i.e., $\\vecs \\in \\mathcal{S}_1$.\n\tIf $\\vecs$ is a PTE, it survives all preemption rounds.\n\tThus, it must satisfy $\\vecs \\in \\mathcal{S}_1$.\n\\end{proof}\n\n\\begin{lemma}\n\t\\label{th:ptbre-subset-ir}\n\tFor any game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTBRE, then it is individually rational.\n\tThus, we have PTBRE $\\subset$ IR.\n\\end{lemma}\n\n\\begin{proof}\n\tLet us suppose that there is a game $G = (P, S, \\uu)$ and a strategy profile $\\vecs = (s_1, \\dots, s_n) \\in S$ such that $\\vecs$ is a PTBRE but not individually rational.\n\tThis is equivalent to $s_i$ being a perfectly transparent best response to $\\vecs_{-i}$ for all $i \\in P$, and $\\vecs \\notin \\mathcal{S}_1(G)$.\n\tNote that we must also have $(s_i', \\vecs_{-i}) \\notin \\mathcal{S}_1(G)\\ \\forall s_i' \\in S_i,\\ \\forall i \\in P$ because otherwise $s_i$ would not be a perfectly transparent best response to $\\vecs_{-i}$ for some player $i$.\n\tThis means the perfectly transparent best response of every player $i \\in P$ to $\\vecs_{-i}$ is simply a Nashian best response (since all considered strategy profiles are eliminated in the same preemption round).\n\tThus, $\\vecs$ is a Nash equilibrium, which is always individually rational.\n\\end{proof}\n\n\\begin{lemma}\n\t\\label{th:ptbpe-subset-mr}\n\tIn any game $G = (P, S, \\uu)$ of two players with $P = \\{i, j\\}$, if a strategy profile $\\vecs \\in S$ is a PTBPE, then it is minimax rationalizable.\n\tWe have PTBPE $\\subset$ MR.\n\\end{lemma}\n\n\\begin{proof}\n\tSuppose for the sake of contradiction that there is a strategy profile $\\vecs \\in S$, which is a PTBPE but not MR.\n\tThis means there is some $k \\in \\N$ such that $\\vecs \\in \\mathcal{R}_k$ and $\\vecs \\notin \\mathcal{R}_{k+1}$.\n\tSuppose WLOG that player $i$ caused the elimination of $\\vecs$ in the $k+1$\\textsuperscript{st} round.\n\tThis means, player $i$ has some strategy $s_i' \\in S_i'$ such that\n\t\\[\n\t\t\\forall (s_i', s_j') \\in \\mathcal{R}_k: u_i(s_i', s_j') > u_i(\\vecs),\n\t\\]\n\tand there is at least one $s_j' \\in S_j$ such that $(s_i', s_j') \\in \\mathcal{R}_k$.\n\tNow, we can observe that $(s_i', s_j) \\in \\mathcal{R}_k$; otherwise either the whole row or column corresponding to $(s_i', s_j)$ would have to be eliminated in some previous round but we know that $\\vecs \\in \\mathcal{R}_k$ and $(s_i', s_j') \\in \\mathcal{R}_k$ for some $s_j' \\in S_j$.\n\tSince $u_i(s_i', s_j) > u_i(\\vecs)$, it cannot be that $s_i$ is a perfectly transparent best response to $s_j$. Hence, $\\vecs$ cannot be a perfectly transparent $j$-best profile, a contradiction.\n\\end{proof}\n\nAll the described inclusions are strict.\nIn \\autoref{tab:overview-nosym-dup} an overview of all inclusions can be found.\nFor each pair of equilibria $A, B$, it refers to either a proof or a counterexample of the claim \\enquote{$A \\subseteq B$} (note that $A \\subseteq B \\land B \\not\\subseteq A$ implies strict inclusion: $A \\subset B$).\n\nMinimax rationalizability intersects with all the other equilibria, as shown in \\autoref{tab:PTOPE-eq-minimax}.\n\n\n\\section{Symmetric Games with Ties}\nEvery proof from the previous section holds even for symmetric games with ties.\nHowever, some counterexamples that we gave are non-symmetric.\nIn particular, for the following claims we do not have any counterexamples that would prove them:\n\\begin{enumerate}\n\t\\item sPTOPE $\\not\\subseteq$ MR. For non-symmetric games proved by \\autoref{tab:PTOPE-ne-minimax}.\n\t\\item PTOPE $\\not\\subseteq$ MR. For non-symmetric games holds transitively because sPTOPE~$\\subset$~PTOPE (\\autoref{th:strict-sub-weak}), and sPTOPE~$\\not\\subseteq$~MR (point 1).\n\t\\item PTE $\\not\\subseteq$ MR. For non-symmetric games holds because PTOPE $\\subset$ PTE (\\autoref{th:ptope-subset-pte}), and PTOPE $\\not\\subset$ MR (point 2).\n\\end{enumerate}\nSince we have not found any counterexamples in our datasets, we believe the opposite statements to be true.\n\n\\begin{conjecture}\n\tFor any game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTOPE, then it is minimax rationalizable.\n\tWe have PTOPE $\\subset$ MR.\n\\end{conjecture}\n\n\\begin{conjecture}\n\tFor any game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTE, then it is minimax rationalizable.\n\tWe have PTE $\\subset$ MR.\n\\end{conjecture}\n\nDue to limited time constraints, we have not been able to prove these conjectures.\n\nAll other inclusions are the same as in \\autoref{sec:games-with-ties}.\nAn overview of all inclusion proofs and counterexamples can be found in \\autoref{tab:overview-sym-dup}.\n\n\\section{Games without Ties}\nWe can observe that in games without ties, similar to Nash equilibria, weak and strict equilibria are also equivalent in the case of PTBRE and PTOPE.\nThus, in this section, we do not distinguish between them.\nMoreover, all the \\enquote{is subset of} relations are inherited from \\autoref{sec:games-with-ties}.\nThe only difference is that PTE is not intersecting with PTBRE anymore (the example in \\autoref{tab:ties-pte-not-sub-ptbre} indeed has ties).\nAll inclusions for games without ties are depicted by a Venn diagram in \\autoref{fig:venn-general-without-ties}.\n\n\\begin{observation}\n\t\\label{th:pte-subset-ptbre}\n\tIf a strategy profile is a PTE, then it must be a PTBRE because there is only one strategy profile to choose from in the last preemption round.\n\tWe have PTE $\\subset$ PTBRE.\n\\end{observation}\n\n\\begin{figure}[t]\n\t\\centering\n\t\\begin{tikzpicture}[line width=0.25pt]\n\t\t\\draw (-0.9,0) ellipse (1.1 and 1.1);\n\t\t\\draw (0.9,0) ellipse (1.1 and 1.1);\n\t\t\\draw (0,0) circle (2.2);\n\t\t\\draw (0,0) circle (3.3);\n\t\t\\draw[rounded corners=2ex] (-3.5,3.5) rectangle (3.5,-3.5);\n\t\t\\draw (2.8,0) ellipse (3 and 2.8);\n\t\t\\node at (-1,0) {PTOPE};\n\t\t\\node at (1,0) {PTBPE};\n\t\t\\node at (-0.5,1.45) {PTE};\n\t\t\\node at (-1.3,2.45) {PTBRE};\n\t\t\\node at (-2.5,3.0) {IR};\n\t\t\\node at (4.3,0) {MR};\n\t\\end{tikzpicture}\n\t\\caption{A Venn diagram depicting the inclusion of different equilibria in games without ties.}\n\t\\label{fig:venn-general-without-ties}\n\\end{figure}\n\nAn overview of all inclusion proofs and counterexamples can be found in \\autoref{tab:overview-nosym-nodup}.\n\n\\section{Symmetric Games without Ties}\nIn this section, we restrict ourselves to symmetric games without ties.\nAll the \\enquote{subset} relations from the previous section still hold since symmetric games are a special case of general games.\nMoreover, none of the equilibria collapses (i.e., they are still strict subsets, even when restricted to symmetric games); this because all the provided counterexamples are symmetric games.\nThe only new relation that emerges is between minimax rationalizability and~PTE.\nAll the inclusions are depicted in \\autoref{fig:venn-sym-without-ties}.\nFurthermore, we present some other interesting observations about symmetric games.\n\n\\begin{figure}[t]\n\t\\centering\n\t\\begin{tikzpicture}[line width=0.25pt]\n\t\t\\draw (-0.9,0) ellipse (1.1 and 1.1);\n\t\t\\draw (0.9,0) ellipse (1.1 and 1.1);\n\t\t\\draw (0,0) circle (2.2);\n\t\t\\draw (0,0) circle (3.3);\n\t\t\\draw[rounded corners=2ex] (-3.5,3.5) rectangle (3.5,-3.5);\n\t\t\\draw (2.8,0) ellipse (5 and 3.2);\n\t\t\\node at (-1,0) {PTOPE};\n\t\t\\node at (1,0) {PTBPE};\n\t\t\\node at (-0,1.35) {PTE};\n\t\t\\node at (-1.3,2.45) {PTBRE};\n\t\t\\node at (-2.5,3.0) {IR};\n\t\t\\node at (5,0) {MR};\n\t\\end{tikzpicture}\n\t\\caption{A Venn diagram depicting the inclusion of equilibria in symmetric games without ties.}\n\t\\label{fig:venn-sym-without-ties}\n\\end{figure}\n\n\\begin{observation}\n\t In a symmetric game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTE, then it lies on the diagonal, i.e., we have $\\vecs = (a, a, \\dots, a)$ for some strategy $a$.\n\\end{observation}\n\n\\begin{proof}\n\tIf there was a PTE somewhere else than on the diagonal, we would necessarily have multiple PTEs by symmetry, contradicting the uniqueness of PTE.\n\\end{proof}\n\n\\begin{corollary}\n\tIf a symmetric game $G = (P, S, \\uu)$ has a PTE $\\vecs \\in S$ and $\\vecs$ is the perfectly transparent $i$-optimal profile for some player $i \\in P$, then $\\vecs$ is a PTOPE. \n\\end{corollary}\n\n\\begin{proof}\n\tSince $\\vecs$ is on the diagonal and it is the perfectly transparent $i$-optimal profile for some $i \\in P$, by symmetry, it must actually be the perfectly transparent $j$-optimal profile for all $j \\in P$, which is the definition of PTOPE.\n\\end{proof}\n\n\\begin{lemma}[Fourny \\cite{Fourny20}]\n\t\\label{th:pte-sym-subset-mr}\n\tIn a symmetric game $G = (P, S, \\uu)$, if a strategy profile $\\vecs \\in S$ is a PTE, then it is minimax rationalizable.\n\tThus, we have PTE\\textsuperscript{sym} $\\subset$ MR\\textsuperscript{sym}.\n\\end{lemma}\n\n\\begin{proof}\n\tSuppose, for the sake of deriving a contradiction, that there is a game $G = (P, S, \\uu)$ and a strategy profile $\\vecs \\in S$ that is a PTE but not minimax rationalizable.\n\tBy definition, this means that there is some player $i \\in P$ such that $(s_i, \\vecs_{-i}')$ is not minimax rationalizable for any $\\vecs' \\in S$.\n\tBy symmetry, if this statement holds for one player, then it must hold for all players.\n\tLet $s_j$ be the strategy that minimax-dominates $s_i$ (i.e. causes that $s_i$ is not minimax rationalizable).\n\tWe denote $\\vecs^* = (s_j, s_j, \\dots, s_j)$.\n\tIn the round where strategy $s_i$ is eliminated, strategy profile $\\vecs^*$ must survive---otherwise, strategy $s_j$ would be eliminated as well, but we supposed that $s_j$ is the strategy that caused the elimination of $s_i$.\n\tMoreover, we must have $u_i(\\vecs^*) > u_i(\\vecs)\\ \\forall i \\in P$ because $s_j$ minimax-dominates $s_i$.\n\tThis means $\\vecs$ is not Pareto-optimal which contradicts $\\vecs$ being a PTE.\n\\end{proof}\n\nAn overview of all inclusion proofs and counterexamples can be found in \\autoref{tab:overview-sym-nodup}.\n", "meta": {"hexsha": "b1337f5f4bed1c7584fb113881362f5da54e945a", "size": 25188, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapters/game-theory.tex", "max_stars_repo_name": "KuceraMartin/perfect-prediction-game", "max_stars_repo_head_hexsha": "61296cdae8fd33f902d73a819d39535c7945501a", "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/chapters/game-theory.tex", "max_issues_repo_name": "KuceraMartin/perfect-prediction-game", "max_issues_repo_head_hexsha": "61296cdae8fd33f902d73a819d39535c7945501a", "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/chapters/game-theory.tex", "max_forks_repo_name": "KuceraMartin/perfect-prediction-game", "max_forks_repo_head_hexsha": "61296cdae8fd33f902d73a819d39535c7945501a", "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": 61.7352941176, "max_line_length": 348, "alphanum_fraction": 0.7134746705, "num_tokens": 7907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.80563219364797, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6389516911874429}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{color}\n\\usepackage{geometry}\n \\geometry{\n a4paper,\n total={210mm,297mm},\n left=20mm,\n right=20mm,\n top=20mm,\n bottom=20mm,\n}\n\\usepackage[parfill]{parskip}\n\\usepackage[colorlinks=true]{hyperref}\n\\hypersetup{urlcolor=blue, citecolor=red}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{definition}{Definition}\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{rem}[theorem]{Remark}\n\\newtheorem{pro}[theorem]{Proposition}\n\\newtheorem{con}[theorem]{Conjecture}\n\n\\renewcommand{\\vec}[1]{\\ensuremath{\\overrightarrow{#1}}}\n\n\\begin{document}\n\\begin{center}\n{\\huge \\bf Idealized 2 links} \\\\\n\\end{center}\n\\vspace{1ex}\n\\begin{flushright}\nFerenc A. Bartha\\\\\nfab2@rice.edu\n\\end{flushright}\n\n\\subsection*{Generalized Coordinates}\nWe use the following coordinates and notation:\n\\begin{itemize}\n \\item The middle mass point is given in polar coordinates w.r. to the origin and the fixed $x$-, $y$-axes.\n \\begin{itemize}\n  \\item the connection to the origin (fixed) is a weightless rod,\n  \\item the weight of the mass point is $m_1$,\n  \\item radius$\\, = d_1$, constant,\n  \\item angle from $x$-axis to the direction $\\vec{e_{r_1}} = \\theta_1$.\n \\end{itemize}\n \\item The upper mass point is given in polar coordinates w.r. to middle point\n \\begin{itemize}\n  \\item the connection to the middle point is a weightless rod,\n  \\item the weight of the mass point is $m_2$,\n  \\item radius$\\, = d_2$, constant,\n  \\item angle from the direction $\\vec{e_{r_1}}$ to the direction $\\vec{e_{r_2}} = \\theta_2$.\n \\end{itemize}\n \\item Consequently, we describe our system by $\\theta_1$ and $\\theta_2$ and their derivatives.\n\\end{itemize}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[scale=0.8]{01_Idealized_2links.png}\n    \\caption{The coordinates}\n\\end{figure}\n\nNote that none of these coordinate systems (describing the middle or the upper point) is an inertial coordinate system. Both are rotating (thus accelerating) compared to the one fixed in the origin with axis $x$ and $y$.\n\n\\newpage\n\n\\subsection*{The Lagrangian}\nWe assume that no external forces act on the system, so we have conservation of energy, that is in our case conservation of kinetic energy.\nThe Lagrangian is\n$$\\mathcal{L}(\\theta_1, \\dot \\theta_1, \\theta_2, \\dot \\theta_2) = \\frac{1}{2} m_1 |\\vec{v_1}|^2 + \\frac{1}{2} m_2 |\\vec{v_2}|^2.$$\n\\vspace{1ex}\n\\noindent\nWe have\n\\begin{itemize}\\itemsep 0.7ex\n \\item conservation of energy: $\\mathcal{L} = $ constant,\n \\item the position vector of the middle mass from the origin is $d_1 \\vec{e_{r_1}}$,\n \\item the velocity vector is the derivative $\\vec{v_1} = \\dot{d_1} \\vec{e_{r_1}} + d_1 \\dot{\\vec{e_{r_1}}} = d_1 \\dot{\\theta_1} \\vec{e_{\\theta_1}}$\\\\\n as $\\dot d_1 = 0$ and $\\dot{\\vec{e_{r_1}}} = \\dot{\\theta_1} \\vec{e_{\\theta_1}}$ (see {\\bf Appendix}),\n \\item thus, the speed$^2$ is $|\\vec{v_1}|^2 = (d_1 \\dot{\\theta_1})^2$,\n \\item the position vector of the upper mass from the origin is $d_1 \\vec{e_{r_1}} + d_2 \\vec{e_{r_2}}$,\n \\item the velocity vector is $\\vec{v_2} = \\vec{v_1} + \\dot{d_2} \\vec{e_{r_2}} + d_2 \\dot{\\vec{e_{r_2}}} = d_1 \\dot{\\theta_1} \\vec{e_{\\theta_1}} + d_2 (\\dot{\\theta_1} + \\dot{\\theta_2}) \\vec{e_{\\theta_2}}$\\\\\n as $\\dot d_2 = 0$ and $\\dot{\\vec{e_{r_2}}} = (\\dot{\\theta_1} + \\dot{\\theta_2}) \\vec{e_{\\theta_2}}$  (see {\\bf Appendix}),\n \\item thus, the speed$^2$ is $|\\vec{v_2}|^2 = (d_1 \\dot{\\theta_1})^2 + (d_2 (\\dot{\\theta_1} + \\dot{\\theta_2}))^2 + 2 d_1 d_2 \\dot{\\theta_1} (\\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{cos}(\\mathrm{angle}(\\vec{e_{\\theta_1}}, \\vec{e_{\\theta_2}}))$\\\\\n that is $|\\vec{v_2}|^2 = (d_1 \\dot{\\theta_1})^2 + (d_2 (\\dot{\\theta_1} + \\dot{\\theta_2}))^2 + 2 d_1 d_2 \\dot{\\theta_1} (\\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{cos}\\theta_2$.\n\\end{itemize}\n\n\\vspace{1ex}\nThus, \n\\begin{equation*}\n\\begin{split}\n\\mathcal{L}(\\theta_1, \\dot \\theta_1, \\theta_2, \\dot \\theta_2) = &\\,\\frac{1}{2} (m_1 + m_2) d_1^2 \\dot{\\theta_1}^2 \n             + \\frac{1}{2} m_2 d_2^2 (\\dot{\\theta_1} + \\dot{\\theta_2})^2\n             + m_2 d_1 d_2 \\dot{\\theta_1} (\\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{cos}\\theta_2.\n\\end{split}\n\\end{equation*}\n\n\\subsection*{Equations of Motion}\nThe equations of motion are derived by taking\\\\ {\\it(Lagrange equations of the $2nd$ kind a.k.a Euler--Lagrange equations)}\n$$d/dt [ \\partial\\mathcal{L}/\\partial \\dot q_j ] = \\partial\\mathcal{L}/\\partial q_j$$\nfor all generalized coordinates $q_j \\in \\{\\theta_1, \\theta_2 \\}$.\n\nThis gives us\n$$\\frac{d}{dt}\\left[(m_1 + m_2) d_1^2 \\dot{\\theta_1} \n             + m_2 d_2^2 (\\dot{\\theta_1} + \\dot{\\theta_2})\n             + m_2 d_1 d_2 (2 \\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{cos}\\theta_2\\right] = 0 \\quad \\text{ for } q_j = \\theta_1$$\nand\n\\begin{equation*}\n \\frac{d}{dt}\\left[m_2 d_2^2 (\\dot{\\theta_1} + \\dot{\\theta_2})\n             + m_2 d_1 d_2 \\dot{\\theta_1} \\mathrm{cos}\\theta_2 \\right] = \n  - m_2 d_1 d_2 \\dot{\\theta_1} (\\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{sin}(\\theta_2) \\quad \\text{ for } q_j = \\theta_2.\n\\end{equation*}\n\nWriting in the time derivatives we get\n\\begin{equation*}\n\\begin{split}\n  (m_1 + m_2) d_1^2 \\ddot{\\theta_1} \n + m_2 d_2^2 (\\ddot{\\theta_1} + \\ddot{\\theta_2})\n + m_2 d_1 d_2 [(2 \\ddot{\\theta_1} + \\ddot{\\theta_2}) \\mathrm{cos}\\theta_2 - (2 \\dot{\\theta_1} + \\dot{\\theta_2})\\dot{\\theta_2} \\mathrm{sin}\\theta_2] = 0\n\\end{split}\n\\end{equation*}\nthat results in \n\\begin{equation}\\label{eq-theta1}\n\\begin{split}\n \\left( m_2 d_2^2 + m_2 d_1 d_2 \\mathrm{cos}\\theta_2 \\right) \\ddot{\\theta_2} = \n &- \\left( (m_1 + m_2) d_1^2 + m_2 d_2^2 + 2 m_2 d_1 d_2 \\mathrm{cos}\\theta_2 \\right) \\ddot{\\theta_1}\\\\ \n &+ m_2 d_1 d_2 (2 \\dot{\\theta_1} + \\dot{\\theta_2}) \\dot{\\theta_2} \\mathrm{sin}\\theta_2 \n \\qquad \\qquad \\qquad \\text{ for } q_j = \\theta_1\n\\end{split}\n\\end{equation}\nand\n\\begin{equation*}\n m_2 d_2^2 (\\ddot{\\theta_1} + \\ddot{\\theta_2})\n + m_2 d_1 d_2 [\\ddot{\\theta_1} \\mathrm{cos}\\theta_2 - \\dot{\\theta_1} \\dot{\\theta_2} \\mathrm{sin}\\theta_2] =\n- m_2 d_1 d_2 \\dot{\\theta_1} (\\dot{\\theta_1} + \\dot{\\theta_2}) \\mathrm{sin}(\\theta_2)\n\\end{equation*}\nthat is transformed to\n$$m_2 d_2^2 \\ddot{\\theta_2} =\n- m_2 d_2^2 \\ddot{\\theta_1} - m_2 d_1 d_2 \\ddot{\\theta_1} \\mathrm{cos}\\theta_2 \n- m_2 d_1 d_2 \\dot{\\theta_1}^2 \\mathrm{sin}(\\theta_2)\n$$\nand simplified to \n\\begin{equation}\\label{eq-theta2}\n \\ddot{\\theta_2} = - \\left( \\left[ 1 + \\frac{d_1}{d_2} \\mathrm{cos}\\theta_2 \\right] \\ddot{\\theta_1} + \n \\frac{d_1}{d_2} \\dot{\\theta_1}^2 \\mathrm{sin}(\\theta_2) \\right)\n  \\qquad \\qquad \\qquad \\qquad \\text{ for } q_j = \\theta_2\n\\end{equation}\n\n\\subsection*{Further Transformation of the Equations of Motion}\nWe want to solve the equations \\eqref{eq-theta1} and \\eqref{eq-theta2} for \n$\\ddot{\\theta_1}$ and $\\ddot{\\theta_1}$  \n(some tools can model them as they readily are, but we need now a more standard form).\n\nSubstituting \\eqref{eq-theta2} into \\eqref{eq-theta1} yields\n\\begin{equation*}\n\\begin{split}\n - \\left( m_2 d_2^2 + m_2 d_1 d_2 \\mathrm{cos}\\theta_2 \\right) &\\left( \\left[ 1 + \\frac{d_1}{d_2} \\mathrm{cos}\\theta_2 \\right] \\ddot{\\theta_1} + \\frac{d_1}{d_2} \\dot{\\theta_1}^2 \\mathrm{sin}(\\theta_2) \\right) = \\\\\n  &- \\left( (m_1 + m_2) d_1^2 + m_2 d_2^2 + 2 m_2 d_1 d_2 \\mathrm{cos}\\theta_2 \\right) \\ddot{\\theta_1}\\\\ \n &+ m_2 d_1 d_2 (2 \\dot{\\theta_1} + \\dot{\\theta_2}) \\dot{\\theta_2} \\mathrm{sin}\\theta_2 \n\\end{split}\n\\end{equation*}\nthat is transformed to\n\\begin{equation*}\n\\begin{split}\n \\big( m_1 d_1^2 + m_2 d_1^2 -& m_2 d_1^2 \\mathrm{cos}^2\\theta_2 \\big) \\ddot{\\theta_1} =\\\\\n & m_2 d_1 d_2 (2 \\dot{\\theta_1} + \\dot{\\theta_2}) \\dot{\\theta_2} \\mathrm{sin}\\theta_2 \n + \\left( m_2 d_2^2 + m_2 d_1 d_2 \\mathrm{cos}\\theta_2 \\right) \\frac{d_1}{d_2} \\dot{\\theta_1}^2 \\mathrm{sin}(\\theta_2)\n\\end{split}\n\\end{equation*}\nand simplified to\n\\begin{equation}\\label{eq-theta1b}\n \\left( \\tfrac{m_1}{m_2} + \\mathrm{sin}^2\\theta_2 \\right) \\ddot{\\theta_1} =\n  \\tfrac{d_2}{d_1} (2 \\dot{\\theta_1} + \\dot{\\theta_2}) \\dot{\\theta_2} \\mathrm{sin}\\theta_2 \n + \\left( \\tfrac{d_2}{d_1} + \\mathrm{cos}\\theta_2 \\right) \\dot{\\theta_1}^2 \\mathrm{sin}(\\theta_2)\n\\end{equation}\n\nSubstitute $\\ddot{\\theta_1}$ from \\eqref{eq-theta1b} into \\eqref{eq-theta2} and we reach the desired form.\n\n\\subsection*{Deriving the Initial Conditions}\nOur experiment is the following. The initial alignment is $\\theta_1(0) = \\frac{\\pi}{2}$ and $\\theta_2(0) = 0$. A momentary impulse gives velocity to the middle point and does not affect the upper point.\n\\begin{itemize}\n \\item $\\vec{v_1}_{, init} = \\vec{v_1}(0) = d_1 \\dot{\\theta_1}(0) \\vec{e_{\\theta_1}}(0)$ \\\\\n \\hspace*{0.5cm} $\\Rightarrow$ we obtain the initial value $\\dot{\\theta_1}(0)$.\n \n \\item The upper point is not affected that is $\\vec{0} = \\vec{v_2}(0) = d_1 \\dot{\\theta_1}(0) \\vec{e_{\\theta_1}}(0) + d_2 (\\dot{\\theta_1}(0) + \\dot{\\theta_2}(0)) \\vec{e_{\\theta_2}}(0)$\\\\\n \\hspace*{0.5cm} $\\Rightarrow$ we obtain the initial value $\\dot{\\theta_2}(0) = - \\frac{d_1}{d_2} \\dot{\\theta_1}(0) - \\dot{\\theta_1}(0)$\\\\\n \\hspace*{1.1cm} as $\\vec{e_{\\theta_1}}(0) = \\vec{e_{\\theta_2}}(0)$ due to the initial alignment.\n\\end{itemize}\n\nRecall that $\\dot\\theta_2$ is a relative coordinate with respect to the middle point that is in motion at time $0$. \nThus, as the upper point is not in motion viewing from the fixed coordinate system centered at the origin, it is moving \nwhen viewed from the middle point, therefore, it has nonzero {\\bf relative} velocity $d_2 (\\dot{\\theta_1}(0) + \\dot{\\theta_2}(0)) \\vec{e_{\\theta_2}}(0) = - d_1 \\dot{\\theta_1}(0) \\vec{e_{\\theta_2}}(0) = - d_1 \\dot{\\theta_1}(0) \\vec{e_{\\theta_1}}(0) = - \\vec{v_1}(0)$.\n\n\\newpage\n\\subsection*{Appendix}\nThe derivation for $\\dot{\\vec{e_{r_1}}}(t) = \\dot{\\theta_1}(t) \\vec{e_{\\theta_1}}(t)$ is pretty straightforward. Centered at the origin, \n$\\vec{e_{r_1}}(t)$ and $\\vec{e_{\\theta_1}}(t)$ form a coordinate system that rotates with speed $\\dot{\\theta_1}(t)$ around the origin \n(thus, rotates with respect to the inertial coordinate system). This rotation is actually around the $z$-axis (lifting it into 3D).\n\nGiven a position vector $\\vec{p}_{relative}(t)$ of a moving point in this rotating coordinate system, its velocity (within this rotating system) is $\\dot{\\vec{p}}_{relative}(t)$. Looking from the origin in the inertial coordinate system, the effect of the rotation needs to be taken into account:\n$$\\dot{\\vec{p}}_{global}(t) = \\dot{\\vec{p}}_{relative}(t) + \\dot\\theta_1(t) \\vec{k} \\times \\vec{p}_{global}(t).$$\nHere $\\vec{k}$ is the axis of rotation, the direction of the $z$-axis.\n\nApplying this for $\\vec{p}_{global}(t) = \\vec{e_{r_1}}(t)$, we get \n$$\\dot{\\vec{e_{r_1}}}(t) = \\dot{(1,0)} + \\dot\\theta_1(t) \\vec{k} \\times \\vec{e_{r_1}}(t) = \\dot\\theta_1(t) \\vec{k} \\times \\vec{e_{r_1}}(t).$$\nNow as $\\vec{e_{\\theta_1}}(t) = \\vec{k} \\times \\vec{e_{r_1}}(t)$ by definition, we have shown the sought relation.\n\n\\vspace{1cm}\nSimilar argument works for $\\dot{\\vec{e_{r_2}}}(t) = (\\dot{\\theta_1}(t) + \\dot{\\theta_2}(t)) \\vec{e_{\\theta_2}}(t)$ as well. \nTranslate $\\dot{\\vec{e_{r_2}}}(t)$ to the origin and observe that it actually rotates with speed \n$(\\dot{\\theta_1}(t) + \\dot{\\theta_2}(t))$ around the $z$-axis.\n\n\\subsection*{Further reading}\n\\begin{itemize}\n \\item \\href{http://en.wikipedia.org/wiki/Lagrangian_mechanics#Euler.E2.80.93Lagrange_equations}{Wikipedia - Lagrangian Mechanics}\n \\item \\href{http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-07-dynamics-fall-2009/lecture-notes/MIT16_07F09_Lec08.pdf}{MIT OpenCourseware - Dynamics - Relative Motion using Rotating Axis}\n \\item \\href{http://en.wikibooks.org/wiki/Kinematics/2D_Coordinate_Systems}{Wikibooks - 2D Coordinate Systems}\n \\item \\href{http://en.wikipedia.org/wiki/Double_pendulum}{Wikipedia - Double Pendulum}\n\\end{itemize}\n\\end{document}\n\n", "meta": {"hexsha": "239d4b9a756cfa0ad3db35921028336905505c7f", "size": 11704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/03_Projects/06_Ferenc_Bartha/01_Idealized_2links.tex", "max_stars_repo_name": "janduracz/acumen-dev", "max_stars_repo_head_hexsha": "8fdb5c72d4f3617c709bf354b83347faf7a57b60", "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": "examples/03_Projects/06_Ferenc_Bartha/01_Idealized_2links.tex", "max_issues_repo_name": "janduracz/acumen-dev", "max_issues_repo_head_hexsha": "8fdb5c72d4f3617c709bf354b83347faf7a57b60", "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": "examples/03_Projects/06_Ferenc_Bartha/01_Idealized_2links.tex", "max_forks_repo_name": "janduracz/acumen-dev", "max_forks_repo_head_hexsha": "8fdb5c72d4f3617c709bf354b83347faf7a57b60", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-30T08:20:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-13T12:10:32.000Z", "avg_line_length": 52.7207207207, "max_line_length": 296, "alphanum_fraction": 0.6756664388, "num_tokens": 4627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645723, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6389516877247711}}
{"text": "% LaTeX file for a 1 page document\n\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{physymb}\n\\usepackage{braket}\n\\title{EP 307 Assignment 2}\n\n\\author{Manish Goregaokar\\\\120260006}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1}\n\n\\begin{align*}\n\\Braket{e_1|e_1}=\\Braket{e_2|e_2} &= 2\\\\\n \\Braket{e_3|e_3} &=4\\\\\n \\Braket{e_1|e_2} &=i\\sqrt{2}\\\\\n \\Braket{e_1|e_3} &=1+i\\\\\n \\Braket{e_2|e_3} &=2\n\\end{align*}\n\nFirst, we normalize the states to get:\n\n\\begin{align*}\n\\Braket{a_1|a_1}=\\Braket{a_2|a_2} &= 1\\\\\n \\Braket{e_3|a_3} &=1\\\\\n \\Braket{a_1|a_2} &=i\\frac1{\\sqrt{2}}\\\\\n \\Braket{a_1|a_3} &=\\frac{1+i}{2\\sqrt{2}}\\\\\n \\Braket{a_2|a_3} &=\\frac1{\\sqrt{2}}\n\\end{align*}\n\n\\newcommand{\\proj}[1]{\\hat{p}_{a_{#1}}}\nTaking $\\proj i = \\Ket{a_i}\\Bra{a_i}$ to be the projection operator with respect to $a_i$, by Gram-Schmidt orthogonalization procedure,\n\n\\begin{align*}\n&\\Ket{\\phi_1}=\\Ket{a_1}\\\\\n&\\Ket{\\phi_2}=\\Ket{a_2}-\\proj1\\Ket{a_2}\\\\\n&\\Ket{\\phi_3}=\\Ket{a_3}-\\proj1\\Ket{a_3}-\\proj2\\Ket{a_3}\\\\\n\\end{align*}\n\\renewcommand{\\proj}[2]{\\Ket{a_{#1}}\\Braket{a_{#1}|#2}}\nThus\n\\begin{align*}\n&\\Ket{\\phi_1}=\\Ket{a_1}\\\\\n&\\Ket{\\phi_2}=\\Ket{a_2}-\\proj1{a_2}\\\\\n&\\Ket{\\phi_3}=\\Ket{a_3}-\\proj1{a_3}-\\proj2{a_3}\\\\\n\\end{align*}\nand\n\\begin{align*}\n&\\Ket{\\phi_1}=\\Ket{a_1}\\\\\n&\\Ket{\\phi_2}=\\Ket{a_2}+\\frac{1}{\\sqrt{2}i}\\Ket{a_1}\\\\\n&\\Ket{\\phi_3}=\\Ket{a_3}-\\frac{1+i}{2\\sqrt{2}}\\Ket{a_1}-\\frac{1}{\\sqrt{2}}\\Ket{a_2}\\\\\n\\end{align*}\n\nWe can calculate \\begin{align*}&\\Braket{\\phi_1|\\phi_1}=1\\\\\n&\\Braket{\\phi_2|\\phi_2}=1-\\frac{1}{2}=\\frac12\\\\ &\\Braket{\\phi_3|\\phi_3}=1+\\frac{(1-i)(1+i)}{8}+\\frac12=\\frac74\n\\end{align*}\nand from here we get an orthonormal basis\n\n\\begin{align*}\n&\\Ket{\\psi_1}=\\Ket{a_1}\\\\\n&\\Ket{\\psi_2}=\\sqrt{2}\\left(\\Ket{a_2}+\\frac{1}{\\sqrt{2}i}\\Ket{a_1}\\right)\\\\\n&\\Ket{\\psi_3}=\\frac{2}{\\sqrt{7}}\\left(\\Ket{a_3}-\\frac{1+i}{2\\sqrt{2}}\\Ket{a_1}-\\frac{1}{\\sqrt{2}}\\Ket{a_2}\\right)\\\\\n\\end{align*}\n\nRewriting in terms of the original vectors\n\n\\begin{align*}\n&\\Ket{\\psi_1}=\\frac{1}{\\sqrt{2}}\\Ket{e_1}\\\\\n&\\Ket{\\psi_2}=\\Ket{e_2}+\\frac{1}{\\sqrt{2}i}\\Ket{e_1}\\\\\n&\\Ket{\\psi_3}=\\frac{4}{\\sqrt{7}}\\left(\\Ket{e_3}-\\frac{1+i}{2\\sqrt{2}}\\Ket{e_1}-\\frac{1}{\\sqrt{2}}\\Ket{e_2}\\right)\\\\\n\\end{align*}\n\n$\\Ket{\\psi_1},\\Ket{\\psi_2},\\Ket{\\psi_3}$ are our orthonormal basis vectors.\n\n\\section*{Problem 2}\nFirst, we normalize them by taking integrals in $[-1,1]$, and get $c_0=\\frac1{\\sqrt{2}},c_1=\\sqrt{\\frac32},c_2=\\sqrt{\\frac52}$\n\nApplying the orthogonalization process,\n\n\\begin{align*}\n\\Ket{\\phi_1}&=\\Ket{\\psi_1}\\\\\n\\Ket{\\phi_2}&=\\Ket{\\psi_2}-\\Ket{\\psi_1}\\Braket{\\psi_1|\\psi_2}\\\\\n\\Ket{\\phi_3}&=\\Ket{\\psi_3}-\\Ket{\\psi_1}\\Braket{\\psi_1|\\psi_3}-\\Ket{\\psi_2}\\Braket{\\psi_2|\\psi_3}\n\\end{align*}\n\ncalculating the inner products, we get\n\n\\begin{align*}\n\\Ket{\\phi_1}&=\\Ket{\\psi_1}\\\\\n\\Ket{\\phi_2}&=\\Ket{\\psi_2}-0\\Ket{\\psi_1}\\\\\n\\Ket{\\phi_3}&=\\Ket{\\psi_3}-\\frac{\\sqrt5}{2}\\frac23\\Ket{\\psi_1}-0\\Ket{\\psi_2}\n\\end{align*}\n\nwhich evaluates to\n\n\\begin{align*}\n\\phi_1&=\\frac1{\\sqrt{2}}\\\\\n\\phi_2&=\\sqrt{\\frac32}x\\\\\n\\phi_3&=\\sqrt{\\frac52}\\left(x^2-\\frac13\\right)\n\\end{align*}\n\\section*{Problem 3}\n\n$$\\hat Bg(x)=g(-x)$$\nThe operator is linear, since $\\hat B(\\alpha f(x)+\\beta g(x))=\\alpha f(-x)+\\beta g(-x)=\\alpha \\hat Bf(x)+\\beta\\hat B g(x)$\n\nIt also is Hermitian, as \\begin{align*}\\Bra{f}(\\hat B\\Ket{g})&=\\int_{-\\infty}^\\infty \\bar{f}(x)\\hat B g(x) dx\\\\\n&= \\int_{-\\infty}^\\infty \\bar{f}(x) g(-x) dx\\\\\n&= \\int_{-\\infty}^\\infty \\bar{f}(-x)g(x)dx\\\\\n&= \\int_{-\\infty}^\\infty \\bar{f}(-x)g(x)dx\\\\\n&=\\int_{-\\infty}^\\infty \\overline{\\hat B f(x)}g(x)\\\\\n&=\\Braket{\\overline{\\hat B} f|g}\\\\\n\\therefore \\Braket{f|\\hat B g}&=\\Braket{\\overline{\\hat B} f|g}\n\\end{align*}\n\nTo find eigenvalues, $\\hat B g(x)=b g(x)=g(-x)$\n\nSince $b g(x)=g(-x)$ and $b g(-x)=g(x)$, $b=\\pm 1$ (neglecting the trivial $b=0$ solution).\n\nThus, we have eigenvectors:\n\\begin{align*}\n&\\sum_n a_n x^{2n} & \\text{(even function)}\\qquad &\\text{for eigenvalue $b=1$}\\\\\n&\\sum_n b_n x^{2n+1}& \\text{(odd function)}\\qquad &\\text{for eigenvalue $b=-1$}\n\\end{align*} \nTo calculate the commutator,\n\\begin{align*}\n [B,\\hat{x}^n]f&=\\hat B \\hat x^n f(x)-\\hat xn \\hat B f(x)\\\\\n &=\\hat B x^n f(x) - \\hat x^n f(-x)\\\\\n &= (-x)^{n}f(-x)-x^n f(-x)\\\\\n &= f(-x)((-x)^{n}-x^n)\n\\end{align*}\n\nFor this to be zero for all states $f$, $n$ must be even. Thus the commutator is zero only for even $n$\n\\section*{Problem 4}\n\n$$\\hat \\Omega = \\Ket{\\psi}\\Bra{\\phi}$$\n\nFor it to be Hermitian, $\\hat \\Omega^\\dagger =\\Omega$. Applying it to the state $\\Ket{\\Psi}=\\Ket{\\psi}+\\Ket{\\phi}$,\n\n\\begin{align*}\n\\Ket{\\psi}\\Braket{\\phi|\\Psi}&=\\Ket{\\phi}\\Braket{\\psi|\\Psi}\\\\\n\\Ket{\\psi}\\Braket{\\phi|\\psi}+\\Ket{\\phi}\\Braket{\\psi|\\psi} &= \\Ket{\\psi}\\Braket{\\phi|\\phi}+\\Ket{\\phi}\\Braket{\\psi|\\phi}\\\\\n\\left(\\Braket{\\phi|\\psi}-\\Braket{\\phi|\\phi}\\right)\\Ket{\\psi} &= \\left(\\Braket{\\psi|\\phi}-\\Braket{\\psi|\\psi}\\right)\\Ket{\\phi}\n\\end{align*}\n\nFor this to hold, either $\\Ket{\\psi}=c\\ket{\\phi}$ or  $\\left(\\Braket{\\phi|\\psi}-\\Braket{\\phi|\\phi}\\right)=0=\\left(\\Braket{\\psi|\\phi}-\\Braket{\\psi|\\psi}\\right)$\n\nIn the latter case, we get $\\Braket{\\psi|\\psi}=\\Braket{\\phi|\\psi}=\\Braket{\\phi|\\phi}$, which can only happen if the two states are equivalent.\n\nThus condition for the operator to be hermitian is that $\\Ket{\\psi}=c\\Ket{\\phi}$.\n\nFor it to be a projection operator, $c=\\frac1{\\Braket{\\phi|\\phi}}$\n\n\\section{Problem 5}\n\n$$\\hat B \\psi(x)=\\int_{-\\infty}^x x' \\psi(x')dx'$$\n\nThe eigenvalue problem $\\hat B \\psi =\\lambda\\psi$ thus becomes $\\int_{-\\infty}^x x' \\psi(x')dx' = \\lambda \\psi(x)$.\n\nDifferentiating with respect to $x$, this is \\begin{align*}\nx\\psi(x)&=\\lambda\\psi'(x)\\\\\n\\implies \\frac{\\psi'(x)}{\\psi(x)}&=\\frac{x}{\\lambda}\\\\\n\\implies \\int_{\\psi(0)}^\\psi\\frac{\\psi'(x)}{\\psi(x)}&=\\int_0^x\\frac{x}{\\lambda}\\\\\n\\implies \\log\\frac{\\psi(x)}{\\psi(0)} &= \\frac1{\\lambda} \\frac{x^2}2\\\\\n\\implies \\psi(x)=\\psi(0)e^{\\frac{x^2}{2\\lambda}}\n\\end{align*}\n\nThis is an acceptable (square-integrable) wavefunction only when $\\lambda$ is negative.\n\\end{document}\n\n\\documentclass[12pt]{}", "meta": {"hexsha": "29a3381369139d3bd8bb7b7b491bbab7aeacfb4c", "size": 5962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 2/assign2.tex", "max_stars_repo_name": "CourseResources/CourseResources", "max_stars_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-28T05:59:31.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-28T05:59:31.000Z", "max_issues_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 2/assign2.tex", "max_issues_repo_name": "CourseResources/CourseResources", "max_issues_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 2/assign2.tex", "max_forks_repo_name": "CourseResources/CourseResources", "max_forks_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_forks_repo_licenses": ["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.4624277457, "max_line_length": 159, "alphanum_fraction": 0.6278094599, "num_tokens": 2733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6389516855163802}}
{"text": "\r\n\\input{SingleAssignmentSetup.tex}\r\n\\input{../WeekTitles.tex}\r\n\\begin{document}\r\n\r\n\r\n\\begin{center}\r\n\\subsection*{MNTC P01 - Week \\#3 - \\WeekTitleThree}\r\n\\end{center}\r\n\r\n\\subsection*{Taylor Polynomials}\r\n\r\nFor reference, the general formula for the Taylor polynomial centered at x = a is:\r\n\\[P(x) = f(a) + \\frac{f'(a)}{1!} (x-a) + \\frac{f''(a)}{2!} (x-a)^2 + ... + \\frac{f^n(a)}{n!} (x-a)^n\\]\r\nwhere $n!$ means ``n factorial'', or $n \\times (n-1) \\times (n-2) \\times ... 2 \\times 1$.  E.g. $4! = 4 \\cdot 3 \\cdot 2 \\cdot 1 = 24$.\r\n\r\n\\begin{enumerate}[1.]\r\n\\begin{multicols}{2}\r\n\r\n\\item\r\n\\begin{Question}\r\n Suppose \\(g\\) is a function which has continuous derivatives, and that\r\n\\(g(5)=-3, g'(5)=-2\\), \\(g''(5)=1\\),\r\n\\(g'''(5)=-5\\).\r\n\\begin{enumerate}[(a)]\r\n\\item What is the Taylor polynomial of degree 2 for \\(g\\) near \r\n\\(5\\)?\r\n\\item What is the Taylor polynomial of degree 3 for \\(g\\) near \r\n\\(5\\)? \\\\\r\n\\item Use the two polynomials that you found in parts (a) and (b) to\r\napproximate \\(g(5.1)\\).\r\n\\end{enumerate}\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nWe have\r\n\\[g(x) = g(5) + g'(5)(x-5) + \\frac{g''(5)}{2!}(x-5)^2\r\n+\\frac{g'''(5)}{3!}(x-5)^3+\\cdots\\]\r\nSubstituting gives\r\n\\[g(x) = -3  - 2(x-5) + \\frac{1}{2!}(x-5)^2\r\n  +\\frac{-5}{3!}(x-5)^3+\\cdots\\]\r\n  \\begin{enumerate}[(a)]\r\n\\item \r\nThe degree 2 Taylor polynomial, \\(P_2 (x)\\), is obtained by truncating\r\nafter the \\((x-5)^2\\) term:\r\n\\[P_2(x) = -3+\\left(-2\\right)\\!\\left(x-5\\right)+\\frac{1}{2!}\\cdot 1\\!\\left(x-5\\right)^{2}.\\]\r\n\\par \r\n\\item \r\nThe degree 3 Taylor polynomial, \\(P_3 (x)\\), is obtained by truncating\r\nafter the\r\n\\((x-5)^3\\) term:\r\n\\[P_3 (x) = -3+\\left(-2\\right)\\!\\left(x-5\\right)+\\frac{1}{2!}\\cdot 1\\!\\left(x-5\\right)^{2}+\\frac{1}{3!}\\!\\left(-5\\right)\\!\\left(x-5\\right)^{3}\\]\r\n\\par \r\n\\item \r\nSubstitute \\(x=5.1\\) into the Taylor polynomial of degree 2:\r\n\\[P_2(5.1) = -3+\\left(-2\\right)\\!\\left(5.1-5\\right)+\\frac{1}{2!}\\cdot 1\\!\\left(5.1-5\\right)^{2} = -3.195.\\]\r\nFrom the Taylor polynomial of degree 3, we obtain\r\n\\begin{align*}\r\nP_3(5.1) =&  -3+\\left(-2\\right)\\!\\left(5.1-5\\right)+\\frac{1}{2!}\\cdot 1\\!\\left(5.1-5\\right)^{2}+ \\\\\r\n& \\frac{1}{3!}\\!\\left(-5\\right)\\!\\left(5.1-5\\right)^{3} \\\\\r\n =& -3.19583.\r\n\\end{align*}\r\n  \\end{enumerate}\r\n\\par\\end{Solution}\r\n\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n  Find the Taylor polynomial of degree \\(n = 4\\) for \\(x\\) near the\r\n  point \\(a = \\frac{\\pi }{4}\\) for the function\r\n  \\(\\cos\\!\\left(4x\\right)\\).\\\\\r\n  Use MATLAB to graph both the function and the Taylor polynomial on a\r\n  reasonable interval around $x=\\pi/4$.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nLet \\(f(x)= \\cos\\!\\left(4x\\right)\\). Then \\(f(\\frac{\\pi }{4}) = -1\\), and\r\n\\par\\smallskip\\begin{center}\\begin{tabular}{|c|c|} \\hline\r\n\\(f'(x) = -4\\sin\\!\\left(4x\\right)\\) &\\(f'(\\frac{\\pi }{4}) = 0\\) \\\\ \\hline \r\n\\(f''(x) = -16\\cos\\!\\left(4x\\right)\\) &\\(f'''(\\frac{\\pi }{4}) = 16\\) \\\\ \\hline \r\n\\(f'''(x) = 64\\sin\\!\\left(4x\\right)\\) &\\(f'''(\\frac{\\pi }{4}) = 0\\) \\\\ \\hline \r\n\\(f''''(x) = 256\\cos\\!\\left(4x\\right)\\) &\\(f''''(\\frac{\\pi }{4}) = -256\\) \\\\ \\hline \r\n\\end {tabular}\\end{center}\\par\\smallskip\r\nSo,\r\n\\(P_4(x) = -1+\\frac{16}{2}\\!\\left(x-\\frac{\\pi }{4}\\right)^{2}+\\frac{-256}{24}\\!\\left(x-\\frac{\\pi }{4}\\right)^{4}\\).\r\n\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig1.m}{W03TaylorTrig1.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n  Find the fifth order Taylor polynomial for\r\n  \\(\\sin\\!\\left(x\\right)\\) near $x = \\pi/4$. \\\\\r\n  Use MATLAB to graph both the function and the Taylor polynomial on\r\n  a reasonable interval around $x = \\pi/4$.\r\n  \\end{Question}\r\n\r\n\\begin{Solution}\r\nThe fifth order Taylor polynomial is based on the first five derivatives of $\\sin(x)$.\r\n\\begin{align*}\r\nf(x) &= \\sin(x) &  f(\\pi/4) = \\frac{1}{\\sqrt{2}} \\approx 0.7071\\\\\r\nf'(x) &= \\cos(x) &  f'(\\pi/4) = \\frac{1}{\\sqrt{2}} \\approx 0.7071\\\\\r\nf''(x) &= -\\sin(x) & f''(\\pi/4) \\approx -0.7071\\\\\r\nf'''(x) &= - \\cos(x)& f'''(\\pi/4) \\approx -0.7071\\\\\r\nf^{(4)}(x) &= \\sin(x)& f^{(4)}(\\pi/4)\\approx  0.7071\\\\\r\nf^{(5)}(x) &= \\cos(x)& f^{(5)}(\\pi/4) \\approx 0.7071\\\\\r\n\\end{align*}\r\nUsing the Taylor polynomial formula, \r\n\\begin{align*}\r\nP_5(x) = &\r\n\\frac{1}{\\sqrt{2}} + \r\n\\frac{1}{\\sqrt{2}} (x-\\pi/4)  - \r\n\\frac{1}{2}\\frac{1}{\\sqrt{2}} (x-\\pi/4)^2  \\\\\r\n& - \r\n\\frac{1}{3!}\\frac{1}{\\sqrt{2}} (x-\\pi/4)^3  + \r\n\\frac{1}{4!}\\frac{1}{\\sqrt{2}} (x-\\pi/4)^4 \\\\\r\n& + \r\n\\frac{1}{5!}\\frac{1}{\\sqrt{2}} (x-\\pi/4)^5   \r\n\\end{align*}\r\n\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig2.m}{W03TaylorTrig2.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Find the Taylor polynomial of degree 3 around the point \\(x = -4\\) of\r\n\\(f(x) = \\sqrt{5+x}\\). \\\\\r\n  Use MATLAB to graph both the function and the Taylor polynomial on\r\n  a reasonable interval around the reference point.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nLet \\(f(x) = \\sqrt{5+x} = (5 +x)^{1/2}\\).\r\n\\par \r\nThen\r\n\\[f'(x) = \\frac{1}{2\\sqrt{5 + x}},\\]\r\n\\[f''(x) = -\\frac{1}{4(5 + x)^{3/2}},\\]\r\nand\r\n\\[f'''(x) = \\frac{3}{8(5 + x)^{5/2}}.\\]\r\nThe Taylor polynomial of degree three about \\(x =-4\\) is thus\r\n\\begin{align*}\r\nP_3(x) & = \\sqrt{5  - 4} + \\frac{1}{2\\sqrt{5 - 4}} (x  + 4 ) + (\\frac{1}{2!})\\,\\left(-\\frac{1}{4(5 - 4)^{3/2}}\\right)\r\n    (x  + 4)^2 + \\\\\r\n&(\\frac{1}{3!})\\left(\\frac{3}{8(5 - 4)^{5/2}}\\right) (x  + 4)^3. \\\\\r\n& = 1 + \\frac{1}{2} (x+4) + \\frac{1}{2!} \\frac{-1}{4} (x+4)^2\r\n+ \\frac{1}{3!} \\frac{3}{8} (x+4)^3\r\n\\end{align*}\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRoot1.m}{W03TaylorRoot1.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \r\n  Calculate the Taylor polynomials \\(P_2(x)\\) and \\(P_3(x)\\) centered\r\n  at \\(x = 1\\) for \\(f(x) = \\ln\\!\\left(x+1\\right)\\). \\\\\r\n  Use MATLAB to graph the function and both the Taylor polynomials on\r\n  a reasonable interval around the reference point.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nRecall the general formula for the Taylor polynomial centered at \\(x\\) = a:\r\n\\[P(x) = f(a) + \\frac{f'(a)}{1!} (x-a) + \\frac{f''(a)}{2!} (x-a)^2 + ... + \\frac{f^n(a)}{n!} (x-a)^n\\]\r\n\\[f(x) = \\ln\\!\\left(x+1\\right)\\]\r\n\\[f'(x) = \\frac{1}{x+1}\\]\r\n\\[f''(x) = \\frac{-1}{\\left(x+1\\right)^{2}}\\]\r\n\\[f'''(x) = \\frac{2}{\\left(x+1\\right)^{3}}\\]\r\nSo, \\(f(x) = \\ln\\!\\left(x+1\\right)\\) and \r\n\\(P_2(x) = A + B(x-1) + C(x-1)^2\\)  \\\\\r\nwhere  \\\\\r\n\\(A=f(1)=\\ln (2)=0.693147\\)  \\\\\r\n\\(B=f'(1)=\\frac{1}{(2)}=0.5\\)  \\\\\r\n\\(C=\\frac{f''(1)}{2!}=-\\frac{1}{(8)}=-0.125\\)  \\\\\r\nThus, \r\n\\[P_2(x) = \\ln (2) + \\frac{1}{(2)} (x - 1)  - \\frac{1}{(8)} (x - 1)^2\\] \\\\\r\nor,\r\n\\[P_2(x) = 0.693147+0.5\\!\\left(x-1\\right)-0.125\\!\\left(x-1\\right)^{2}\\] \\\\\r\nSimilarly,  \\\\\r\n\\(P_3(x) = D + E(x-1) + F(x-1)^2 + G(x-1)^3\\)  \\\\\r\nwhere  \\\\\r\n\\(D=f(1)=\\ln (2)=0.693147\\)  \\\\\r\n\\(E=f'(1)=\\frac{1}{(2)}=0.5\\)  \\\\\r\n\\(F=\\frac{f''(1)}{2!}=-\\frac{1}{(8)}=-0.125\\)  \\\\\r\n\\(G=\\frac{f'''(1)}{3!}=\\frac{1}{(24)}=0.0416667\\)  \\\\\r\nThus, \r\n\\[P_3(x) = \\ln (2) + \\frac{1}{(2)} (x - 1)  - \\frac{1}{(8)} (x - 1)^2 + \\frac{1}{(24)}  (x - 1)^3\\] \\\\\r\nor,\r\n\\[P_3(x) = P_2(x)  + 0.0417 (x-1)^3\\] \r\n\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorLn1.m}{W03TaylorLn1.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \r\n  Calculate the Taylor polynomials \\(P_2(x)\\) and \\(P_3(x)\\) centered\r\n  at \\(x = \\frac{\\pi }{6}\\) for \\(f(x) = \\sin\\!\\left(x\\right)\\). \\\\\r\nUse MATLAB to graph the function and both the Taylor polynomials on a\r\nreasonable interval around the reference point.\r\n\\end{Question}\r\n\\begin{Solution}\r\nThe 2nd and 3rd order Taylor polynomials are based on the first three derivatives of $\\sin(x)$.\r\n\\begin{align*}\r\nf(x) &= \\sin(x) &  f(\\pi/6) = \\frac{1}{2} \\\\\r\nf'(x) &= \\cos(x) &  f'(\\pi/6) = \\frac{\\sqrt{3}}{2} \\approx 0.866\\\\\r\nf''(x) &= -\\sin(x) & f''(\\pi/6) = \\frac{-1}{2} \\\\ \r\nf'''(x) &= - \\cos(x)& f'''(\\pi/6) = \\frac{-\\sqrt{3}}{2} \\approx -0.866\\\\\r\n\\end{align*}\r\nUsing the Taylor polynomial formula, \r\n\\begin{align*}\r\nP_2(x) = &\r\n\\frac{1}{2} + \r\n\\frac{\\sqrt{3}}{2} (x-\\pi/6)  - \r\n\\frac{1}{2!}\\frac{1}{2} (x-\\pi/6)^2  \r\n\\end{align*}\r\nand $P_3$ will be the same, just with the cubic term added at the end.\r\n\\begin{align*}\r\nP_3(x) = &\r\n\\frac{1}{2} + \r\n\\frac{\\sqrt{3}}{2} (x-\\pi/6)  - \r\n\\frac{1}{2!}\\frac{1}{2} (x-\\pi/6)^2   - \r\n\\frac{1}{3!}\\frac{\\sqrt{3}}{2} (x-\\pi/6)^3  \r\n\\end{align*}\r\n\r\n\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig3.m}{W03TaylorTrig3.m}\r\n \r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \r\n  Calculate the Taylor polynomials \\(P_2(x)\\) and \\(P_3(x)\\) centered\r\n  at \\(x = 7\\) for \\(f(x) = \\frac{1}{1+x}\\).  \\\\\r\n  Use MATLAB to graph both the function and the Taylor polynomial on a\r\n  reasonable interval around the reference point.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\n\\[f(x) = \\frac{1}{1+x}\\]\r\n\\[f'(x) = \\frac{-1}{(1+x)^2}\\]\r\n\\[f''(x) = \\frac{2}{(1+x)^3}\\]\r\n\\[f'''(x) = \\frac{-6}{(1+x)^4}\\]\r\nand \r\n\\(P_2(x) = A + B(x-7) + C(x-7)^2\\)  \\\\\r\nwhere  \\\\\r\n\\(A=f(7)=\\frac{1}{(8)}=0.125\\)  \\\\\r\n\\(B=f'(7)=-\\frac{1}{(64)}\\approx-0.0156\\)  \\\\\r\n\\(C=\\frac{f''(7)}{2!}=\\frac{1}{(512)}=0.00195\\)  \\\\\r\nThus, \r\n\\[P_2(x) = \\frac{1}{(8)}  - \\frac{1}{(64)} (x - 7) + \\frac{1}{(512)} (x - 7)^2\\] \\\\\r\nor,\r\n\\[P_2(x) = 0.125-0.0156\\!\\left(x-7\\right)+0.00195\\!\\left(x-7\\right)^{2}\\] \\\\\r\nSimilarly,  \\\\\r\n\\(P_3(x) = D + E(x-7) + F(x-7)^2 + G(x-7)^3\\)  \\\\\r\nwhere  \\\\\r\n\\(D=f(7)=\\frac{1}{(8)}=0.125\\)  \\\\\r\n\\(E=f'(7)=-\\frac{1}{(64)}=-0.0156\\)  \\\\\r\n\\(F=\\frac{f''(7)}{2!}=\\frac{1}{(512)}=0.00195\\)  \\\\\r\n\\(G=\\frac{f'''(7)}{3!}=-\\frac{1}{(4096)}=-0.000244\\)  \\\\\r\nThus, \r\n\\[P_3(x) = \\frac{1}{(8)}  - \\frac{1}{(64)} (x - 7) + \\frac{1}{(512)} (x - 7)^2  - \\frac{1}{(4096)}  (x - 7)^3\\] \\\\\r\nor,\r\n\\[P_3(x) = P_2(x)  - 0.000244 (x-7)^3\\] \\\\\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRecip1.m}{W03TaylorRecip1.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n  Calculate the Taylor polynomials \\(P_2(x)\\) and \\(P_3(x)\\) centered\r\n  at \\(x = 2\\) for \\(f(x) = e^{-x}+e^{-2x}\\). \\\\\r\n  Use MATLAB to graph the function and both the Taylor polynomials on a\r\n  reasonable interval around the reference point.\r\n\\end{Question}\r\n\\begin{Solution}\r\n \r\n\\[f(x) = e^{-x}+e^{-2x}\\]\r\n\\[f'(x) = -e^{-x}-2e^{-2x}\\]\r\n\\[f''(x) = e^{-x}+4e^{-2x}\\]\r\n\\[f'''(x) = -e^{-x}-8e^{-2x}\\]\r\nand \r\n\\(P_2(x) = A + B(x-2) + C(x-2)^2\\)  \\\\\r\nwhere  \\\\\r\n\\(A=f(2)=e^{-2}+e^{-4}\\)  \\\\\r\n\\(B=f'(2)=-\\left(e^{-2}+2e^{-4}\\right)\\)  \\\\\r\n\\(C=\\frac{f''(2)}{2!}=\\frac{e^{-2}+4e^{-4}}{2}\\)  \\\\\r\nThus, \r\n\\[P_2(x) = (e^{-2}+e^{-4})-\\left(e^{-2}+2e^{-4}\\right)\\!\\left(x-2\\right)+\\frac{e^{-2}+4e^{-4}}{2}\\!\\left(x-2\\right)^{2}\\] \\\\\r\nSimilarly,  \\\\\r\n\\(P_3(x) = D + E(x-2) + F(x-2)^2 + G(x-2)^3\\)  \\\\\r\nwhere  \\\\\r\n\\(D=f(2)=e^{-2}+e^{-4}\\)  \\\\\r\n\\(E=f'(2)=-\\left(e^{-2}+2e^{-4}\\right)\\)  \\\\\r\n\\(F=\\frac{f''(2)}{2!}=\\frac{e^{-2}+4e^{-4}}{2}\\)  \\\\\r\n\\(G=\\frac{f'''(2)}{3!}=-\\frac{e^{-2}+8e^{-4}}{6}\\)  \\\\\r\nThus, \\(P_3(x) =\\)\r\n\\[\\begin{array}{lcl} \r\n& = & e^{-2}+e^{-4}-\\left(e^{-2}+2e^{-4}\\right)\\!\\left(x-2\\right)+\\frac{e^{-2}+4e^{-4}}{2}\\!\\left(x-2\\right)^{2}  \\cr\\cr \r\n& & - {\\frac{e^{-2}+8e^{-4}}{6}} (x-2)^3 \r\n\\end{array}\\] \r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorExp1.m}{W03TaylorExp1.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \r\n  Calculate the Taylor polynomials \\(P_2(x)\\) and \\(P_3(x)\\) centered\r\n  at \\(x = \\frac{\\pi }{4}\\) for \\(f(x) = \\tan\\!\\left(x\\right)\\).\r\n\r\n  Use MATLAB to graph the function and both the Taylor polynomials on\r\n  a reasonable interval around the reference point.\r\n\\end{Question}\r\n\\begin{Solution}\r\n \r\n\\[f(x) = \\tan\\!\\left(x\\right)\\]\r\n\\[\\frac{d}{dx}\\tan\\!\\left(x\\right) = \\frac{1}{\\cos^{2}\\!\\left(x\\right)}\\]\r\n\\[\\frac{d^2}{dx^2}\\tan\\!\\left(x\\right) = \\frac{2\\sin\\!\\left(x\\right)}{\\cos^{3}\\!\\left(x\\right)}\\]\r\n\\[\\frac{d^3}{dx^3}\\tan\\!\\left(x\\right) = \\frac{2\\!\\left(2\\sin^{2}\\!\\left(x\\right)+1\\right)}{\\cos^{4}\\!\\left(x\\right)}\\]\r\nSo, in this case, \r\n\\[P_2(x) = 1+2\\!\\left(x-\\frac{\\pi }{4}\\right)+2\\!\\left(x-\\frac{\\pi }{4}\\right)^{2}\\]\r\nand\r\n\\[P_3(x) = 1+2\\!\\left(x-\\frac{\\pi }{4}\\right)+2\\!\\left(x-\\frac{\\pi }{4}\\right)^{2} + \\frac{8}{3} (x-\\frac{\\pi }{4})^3\\]\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorTrig4.m}{W03TaylorTrig4.m}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n  Find the second-degree Taylor polynomial \\(P_2(x)\\) for the function\r\n  \\(f(x) = \\sqrt{15+x^2}\\) at the number \\(x=1\\).\r\n\r\n  Use MATLAB to graph both the function and the Taylor polynomial on a\r\n  reasonable interval around $x = \\pi/4$.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n$P_2(x)= 4+(1/4)*(x-1)+(15/(2(16)4))(x-1)^2$\r\n\r\nMATLAB graphing: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03TaylorRoot2.m}{W03TaylorRoot2.m}\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Find the second-degree Taylor polynomial for\r\n\\(f(x)=2 x^2 - 3 x + 8\\) about\r\n\\(x=0\\).\r\nWhat do you notice about your polynomial?\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nWe note that \\(f(0) = 8\\);\r\n\\(f'(x) = 4 x - 3\\), so that \\(f'(0) = -3\\); and\r\n\\(f''(x) = 4\\), so that \\(f''(0) = 4\\).\r\n\\par \r\nThus\r\n\\[P_2(x) = 8 - 3 x + {4\\over 2!} x^2\r\n          = 8 - 3 x + 2 x^2.\\]\r\nWe notice that \\(f(x) = P_2(x)\\) in this case, which makes\r\nsense because \\(f(x)\\) is a polynomial.\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Suppose that \\(P_2(x)=a+bx+cx^2\\) is the\r\nsecond degree Taylor polynomial for the function \\(f\\) about \\(x=0\\).\r\nWhat can you say about the signs of\r\n\\(a\\), \\(b\\), \\(c\\) if \\(f\\) has the graph given below? \\\\\r\nNote that the central lines are the $x$ and $y$ axes.\r\n\\begin{center} \r\n\\includegraphics[width=0.25\\linewidth]{graphics/Week03_TaylorPolynomials/aableson-2281-setUnit_06_TaylorPolynomialsprob16image1}\r\n\\end{center} \r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nSince \\(P_2(x)\\) is the second degree Taylor polynomial for \\(f(x)\\)\r\nabout \\(x=0\\), \\(P_2(0)=f(0)\\), which says \\(a=f(0)\\).  Since\r\n\\(\\frac{d}{dx}P_2(x) \\big|_{x=0} = f'(0)\\),\r\n\\(b=f'(0)\\); and since\r\n\\(\\frac{d^2}{dx^2} P_2(x) \\big|_{x=0} = f''(0)\\),\r\n\\(2c=f''(0)\\).  In other words, \\(a\\) is the \\(y\\)-intercept of\r\n\\(f(x)\\), \\(b\\) is the slope of the tangent line to \\(f(x)\\) at\r\n\\(x=0\\) and \\(c\\) tells us the concavity of \\(f(x)\\) near \\(x=0\\).\r\n\\par \r\nThus\r\n\\(a < 0\\); \\(b > 0\\); and \\(c > 0\\)\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n The function \\(f(x)\\) is approximated near \\(x=0\\) by the second\r\ndegree Taylor polynomial \\(P_2(x) = 3x-3+8x^{2}\\).\r\n\\par \r\nGive values the values of $f(0)$, $f'(0)$, and $f''(0)$.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nUsing the fact that\r\n\\[f(x)\\approx\r\nP_2(x)=f(0)+f'(0)x+\\frac{f''(0)}{2!}x^2\\]\r\nand identifying coefficients with those given for \\(P_2(x)\\), we obtain:\r\n\\par \r\n\\(f(0)=\\) the constant term, which equals \\(-3\\), so \\(f(0)=-3\\).\r\n\\(f'(0)=\\) the coefficient of \\(x\\), which equals \\(3\\), so\r\n\\(f'(0)=3\\).\r\n\\(\\frac{f''(0)}{2!}=\\) the coefficient of \\(x^2\\), which equals \\(8\\),\r\nso \\(f''(0)=16\\).\r\n\\par\\end{Solution}\r\n\\end{multicols} \r\n\r\n\\hrulefill\r\n\r\n\\subsection*{Optimization Introduction}\r\n\\begin{multicols}{2}\r\n\r\n\\item\r\n\\begin{Question}\r\nLet \\(f(x)=x^{2}-10x+13\\), and consider the interval \\([0, 10]\\). \r\n\\begin{enumerate}[(a)]\r\n\\item  Find the critical point \\(c\\) of \\(f(x)\\) and compute \\(f(c)\\).\r\n\\item  Compute the value of \\(f(x)\\) at the endpoints of the interval \\([0,10]\\).\r\n\\item  Determine the global min and max of \\(f(x)\\) on \\([0,10]\\).\r\n\\item  Find the global min and max of \\(f(x)\\) on \\([0,1]\\). (Note: not the same interval as before)\r\n\\end{enumerate}\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n  \\item The critical point of \\(f(x)\\) is the solution to \\(f'(x)=0\\). The\r\n  derivative is\\(f'(x)=2x-10\\). Setting this equal to zero and solving\r\n  for \\(x\\) gives \\(x=5\\). Evaluating \\(f(5)\\) yields $-12$.\r\n\\item Evaluating \\(f(0)\\) and \\(f(10)\\), we find that each is equal to 13.\r\n\\item The global min and max values must occur at critical points or\r\n  at the endpoints of the interval. Since the value at the critical\r\n  point is smaller than the value at the endpoints, the value of\r\n  \\(f(5)\\) is a minimum, and the value of \\(f(0)\\) (or \\(f(10)\\) since\r\n  they are equal) is a maximum.\r\n\\item Since there are no critical points in the interval \\([0,1]\\), so\r\n  the global min and max values lie at the endpoints of the\r\n  interval. Computation yields \\(f(0)=13\\),\\(f(1)=4\\), so the minimum\r\n  is 4 and the maximum is 13.\r\n  \\end{enumerate}\r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\nFind the maximum and minimum values of the function \\(\\ds f(x)=\\frac{\\ln\\!\\left(x\\right)}{x}\\) on the interval [1,3]. \r\n\\end{Question}\r\n\\begin{Solution}\r\n  First we check for critical points. The critical point of \\(f(x)\\)\r\n  is the solution to \\(f'(x)=0\\). \\\\\r\n  The derivative\r\n  is\\(\\ds f'(x)=x^{-2}-\\frac{\\ln\\!\\left(x\\right)}{x^{2}}\\). \\\\\r\n  Setting this\r\n  equal to zero and solving for \\(x\\) gives \\(x=e^1=e\\).\\\\\r\n  Evaluating \\(f(e)\\) yields the value \r\n  \\(\\frac{1}{e}=0.3679\\). \\\\\r\n  The values of the function at the endpoints of the interval are\r\n  \\(f(1)=0\\), \\(f(3)=0.3662\\), so the minimum value is 0, and the\r\n  maximum value is \\(\\frac{1}{e}=0.3679\\).\r\n\\par \r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n  Find the minimum and maximum values of \\(y = \\sqrt{10}\\theta-\\sqrt{5}\\sec\\theta\\) on the interval \\([ 0, \\frac {\\pi}{3}]\\).\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\n\\par \r\nLet \\(f(\\theta) = \\sqrt{10} \\theta - \\sqrt{5}\\sec \\theta\\).  \\leavevmode\\\\\\relax \r\nOn the interval \\([ 0, \\frac {\\pi}{3}]\\) , \\(f'(\\theta)= \\sqrt{10} - \\sqrt{5}\\sec \\theta \\tan \\theta = 0\\)  at  \\(\\theta = \\frac{\\pi}{4}\\).  \\\\\r\n(This can be found either by inspiration, guessing that the answer is a `nice' angle like $\\pi/3$, $\\pi/4$ or $\\pi/6$, or more mechanically by writing the whole equation in terms of $\\sin(\\theta)$, using $\\cos^2(\\theta) = 1 - \\sin^2(\\theta)$ and then solving a quadratic equation.) \\\\\r\nThe minimum value of  \\(f\\) on this interval is at \\leavevmode\\\\\\relax \r\n the endpoint \\(\\theta=0\\), where \\(f(0) = -2.2361\\), \\leavevmode\\\\\\relax \r\nwhereas the maximum value over this interval is \\leavevmode\\\\\\relax \r\n\\(f(\\frac{\\pi}{4})=\\sqrt{10}(\\frac{\\pi}{4} - 1) = -0.6786\\). \\leavevmode\\\\\\relax \r\nAt the second endpoint \\(\\theta=\\frac{\\pi}{3}\\), \\leavevmode\\\\\\relax \r\n \\(f(\\frac{\\pi}{3})= \\sqrt{10} \\frac{\\pi}{3} - 2 \\sqrt{5}= -1.1606\\). \r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n \r\n\\par \r\nFind the maximum and minimum values of the function \\(\\ds f(x)=x-\\frac{125x}{x+5}\\) on the interval [0,21]. \r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nFirst we check for critical points. The critical point of \\(f(x)\\) is\r\nthe solution to \\(f'(x)=0\\). \\\\\r\nThe derivative\r\nis\\(f'(x)=1-\\frac{625}{\\left(x+5\\right)^{2}}\\). \\\\\r\nSetting this equal to\r\nzero and solving for \\(x\\) gives \\(x=-5\\pm 25\\), and of these two\r\ncritical points only -5+25=20 lies in our interval.\\\\\r\n Evaluating\r\n\\(f(-5+25)=f(20)\\) yields the value -80.\\\\\r\n The values of the\r\nfunction at the endpoints of the interval are \\(f(0)=0\\),\r\n\\(f(21)=-79.9615\\), so the minimum value is -80, and the maximum value\r\nis 0.\r\n\\par \r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n The function \\(f(x) = -2 x^3 + 21 x^2 - 36 x + 10\\)\r\nhas one local minimum and one local maximum. Find their $(x,y)$ locations.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  To identify any local extrema, we start by identifying critical\r\n  points.  We note that $f(x)$ is a polynomial, so its derivative is\r\n  defined everywhere, so only points where $f'(x) = 0$ will be\r\n  critical points.\r\n  \\begin{align*}\r\n    f'(x) & = -6x^2 + 42 x - 36 \\\\\r\n\\mbox{ Setting $f'(x) = 0$, }~~~~~~~ 0 & = -6 x^2 + 42 x - 36 \\\\\r\n\\mbox{ Factoring, }~~~~~~~ 0 & = -6 (x^2 - 7 x + 6) \\\\\r\n0 & = -6 (x-1)(x-6) \r\n  \\end{align*}\r\n  The two critical points are at $x=1$ and $x=6$.  Subbing those $x$\r\n  values back into the original function $f(x)$ gives us the points\r\n  (1, -7) and $(6, 118)$.\r\n\r\nUsing test points and the first derivative test, or taking another derivative and using the second derivative test, you can find that:  \\\\\r\nthere is a local minimum at (1,-7), and \\\\\r\nthere is a local maximum at (6, 118).\r\n\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n A University of Rochester student decided to depart from Earth after his\r\ngraduation to find work on Mars.  Before building a shuttle, he conducted careful\r\ncalculations.  A model for the velocity of the shuttle, from liftoff at t = 0\r\ns until the solid rocket boosters were jettisoned at t =   80 s, is given by\r\n\\[v(t) = 0.001094333 t^3- 0.08215 t^2 + 28.6 t - 4.3\\] (in feet per\r\nsecond).  Using this model, estimate the global\r\nmaximum value and global minimum value of the {\\bf acceleration } of\r\nthe shuttle between liftoff and the jettisoning of the boosters.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n\r\nFor simplicity of presentation, let $c_3 =  0.001094333$ and $c_2 = 0.08215$, so\r\n$$v(t) = c_3 t^3 - c_2 t^2 + 28.6 t - 4.3$$\r\nDifferentiating once gives the acceleration\r\n$$a(t) = 3c_3 t^2 - 2c_2 t + 28.6 $$\r\nTo find the critical points of the acceleration, we need to know when its rate of change is\r\nzero: \r\n$$a'(t) = 6 c_3 t - 2c_2 $$\r\nThis will have a zero value when \r\n\\begin{align*}\r\n  0 & = 6 c_3 t - 2c_2 \\\\\r\n  t & = \\frac{2c_2}{6 c_3} = \\frac{1}{3} \\frac{0.08215}{0.001094333} \\approx 25.022\r\n\\end{align*}\r\nThus $t \\approx 25.022$ is the only critical point.  \r\n\r\nWe compute the acceleration at the end points of the interval ($t=0$\r\nand 80), and at the critical point: \\\\\r\n$a(0)  = 28.6 \\mbox{ ft/s}^2$ \\\\\r\n$a(25.022)  = 26.5444 \\mbox{ ft/s}^2$ \\\\\r\n$a(80)  = 36.4672 \\mbox{ ft/s}^2$ \\\\\r\n\r\nThe global maximum acceleration is $36.4672$ ft/s$^2$ and occurs at\r\n$t=80$, while the global minimum acceleration is 26.5444 ft/s$^2$,\r\nand it occurs at $t=25.022$ s.\r\n\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n Use the given graph of the function on the interval \\((0,8]\\) to answer the following questions.\r\n\\par \r\n\\begin{center}\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week03_OptimizationIntro/crit_point_graph}\r\n\\end{center} \\par \r\n\\begin{enumerate}[(a)]\r\n\\item Where does the function \\(f\\) have a local maximum?\r\n\\item Where does the function \\(f\\) have a local minimum?\r\n\\item What is the global maximum of \\(f\\)?\r\n\\item What is the global minimum of \\(f\\)?\r\n\\end{enumerate}\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n\\item $x=$3.  ($x=8$ is an end-point, and so is {\\bf not} considered a local max or min using our definitions.)\r\n\\item $x=$2, 5 \r\n\\item none:  at the left end, the interval is open, so the maximum is never reached.\r\n\\item The global minimum of the function occurs at $x=5$, and the value there is $f(5) = 0$.\r\n  \\end{enumerate}\r\n\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n \\par \r\nFind the global maximum and minimum values of the following function on the given interval. \r\n\\par \r\n\\(f(t)= 4 t \\sqrt{4-t^2}, \\ [-1,2]\\)\r\n\\par\\end{Question}\r\n\\begin{Solution}  \r\nThe global maximum occurs at $x= 1.4142$ and $y = 8$. \r\n\r\nThe global minimum occurs at $x=-1$, and $y = -6.9282$\r\n\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n \\par \r\n An object with weight W is dragged along a horizontal plane by a\r\n force acting along a rope attached to the object. If the rope makes\r\n an angle \\(\\theta\\) with the plane, then the magnitude of the force\r\n is\r\n\\par \r\n$$F = \\dfrac {\\mu W} {\\mu \\sin ( \\theta ) + \\cos ( \\theta ) }$$\r\n\\par \r\nwhere \\(\\mu\\) is a positive constant called the coefficient of\r\nfriction and where \\(0 \\leq \\theta \\leq \\pi/2\\). Find the value for\r\n\\(\\tan \\theta\\) which minimizes the force. Your answer may depend on W\r\nand \\(\\mu\\).\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\nTo minimize $F$, we differentiate with respect to $\\theta$:\r\n\\begin{align*}\r\n &&   F(\\theta) & = \\mu W (\\mu \\sin(\\theta) + \\cos(\\theta))^{-1} \\\\\r\n\\mbox{ so } &&  F'(\\theta) & = - \\frac{\\mu W}{(\\mu \\sin(\\theta) + \\cos(\\theta))^2}(\\mu \\cos(\\theta) - \\sin(\\theta)) \\\\\r\n\\end{align*}\r\nSetting the derivative equal to zero to identify critical points, \r\n\\begin{align*}\r\n0 & = - \\frac{\\mu W}{(\\mu \\sin(\\theta) + \\cos(\\theta))^2}(\\mu \\cos(\\theta) - \\sin(\\theta)) \\\\\r\n\\mbox{ requires } 0 & = (\\mu \\cos(\\theta) - \\sin(\\theta)) \\\\\r\n\\sin(\\theta) & = \\mu \\cos(\\theta) \\\\\r\n\\frac{\\sin(\\theta)}{\\cos(\\theta)} & = \\mu \\\\\r\n\\tan(\\theta) & = \\mu \\\\\r\n\\end{align*}\r\nThe question asked for the value of $\\tan(\\theta)$, so we have that now as $\\mu$.\r\n\r\nThe greater the coefficient of friction, $\\mu$, the more of our force\r\nshould be directed upwards rather than forwards, to help minimize the\r\nfriction effect.\r\n\r\n\\end{Solution}\r\n\r\n\\item\r\n\\begin{Question}\r\n Find the exact global maximum and minimum values of the\r\nfunction \\(f(t) = \\frac{3 t}{8 + t^2}\\) if its domain is all real\r\nnumbers.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nDifferentiating using the quotient rule gives\r\n\\[f'(t)=\\frac{3(8 + t^2) - 3 t(2 8 t)}{(8+t^2)^2} = \r\n    \\frac{3(8 - t^2)}{(8+t^2)^2}.\\]\r\nThe critical points are the solutions to\r\n\\(\\frac{3(8 - t^2)}{(8+t^2)^2} = 0\\), which are \r\n\\(t = \\pm\\sqrt{8}\\).\r\n\\par \r\nSince \\(f'(t)>0\\) for \\(-\\sqrt{8}<t<\\sqrt{8}\\) \r\nand \\(f'(t)<0\\) otherwise, there is a local\r\nminimum at \\(t=-\\sqrt{8}\\) and a local maximum at \\(t=\\sqrt{8}\\). \r\n\\par \r\nAs \\(t\\to\\pm\\infty\\), we have \\(f(t)\\to0\\).  Thus, the local\r\nmaximum at \\(t=\\sqrt{8}\\) is a global maximum of \r\n\\(f(\\sqrt{8}) = {3\\sqrt{8}\\over 8 + 8}\\), \r\nand the local minimum at\r\n\\(t=-\\sqrt{8}\\) is a global minimum of \r\n\\(f(-\\sqrt{8}) = {-3\\sqrt{8}\\over 2(8)}\\).\r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n A ball is thrown up on the surface of a moon.  Its height\r\nabove the lunar surface (in feet) after \\(t\\) seconds is given by the formula\r\n\\[h=217 t-\\frac{7}{4}t^2.\\]\r\n\\begin{enumerate}[(a)]\r\n\\item Find the time that the ball reaches its maximum height.\r\n\\item Find the maximal height attained by the ball. \r\n\\end{enumerate}\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n\\item When the ball reaches its maximum, the velocity will be zero, so we can solve\r\nfor when velocity = $h'(t)$ = 0.\r\n\r\n\\begin{align*}\r\n&& h'(t) & = 217 - \\frac{7}{2} t \\\\\r\n\\mbox{ setting h'=0, } && 0 & = 217 - \\frac{7}{2} t \\\\\r\n&& t & = \\frac{2}{7} 217 = 62 \\mbox{ s}\r\n\\end{align*}\r\n\\item At the time of zero velocity, the height will be $h(62) = 6727$ m.\r\n  \\end{enumerate}\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n In a certain chemical reaction, substance \\(A\\) combines with substance \r\n\\(B\\) to form substance \\(Y\\).  At the start of the reaction, the\r\nquantity of \\(A\\) present is \\(a\\) grams, and the quantity of \r\n\\(B\\) present is \\(b\\) grams.  Assume \\(a<b\\) and \\(y\\le a\\).\r\nAt time \\(t\\)\r\nseconds after the start of the reaction, the quantity of \\(Y\\)\r\npresent is \\(y\\) grams.  For certain types of reactions, the rate of\r\nthe reaction, in grams/sec, is given by \r\n\\[\\hbox{Rate}=k(a-y)(b-y),\\]\r\nwhere \\(k\\) is a positive constant.\r\n\\begin{enumerate}[(a)]\r\n\\item Sketch a graph of the rate against \\(y\\).\r\n\\item For what values of \\(y\\) is the rate non-negative?\r\n\\item Use your graph to find the value of \\(y\\) at which the rate of the \r\nreaction is fastest.\r\n\\end{enumerate}\r\n\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n\r\n  \\begin{enumerate}\r\n\\item~ \\\\ \\includegraphics[width=0.75\\linewidth]{graphics/Week03_OptimizationIntro/parabola_ab}\r\n\\par \r\n \r\n\\item If we expect the rate to be non-negative, we must have \\(0\\le y\\le a\\)\r\nor \\(b \\le y\\).  Since we assume \\(a<b\\), we restrict \\(y\\) to \r\n\\(0\\le y\\le a\\).\r\n\r\nIn fact, the expression for the rate is non-negative for \\(y\\) greater\r\nthan $a$ but these values of \\(y\\) are not meaningful for the\r\nreaction.  See the figure above (which shows the rate with \\(k=1\\)).\r\n\\par \r\n\\item From the graph, we see that the maximum rate occurs when \\(y=0\\); that\r\nis, at the start of the reaction.\r\n  \\end{enumerate}\r\n\\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n  At what value(s) of \\(x\\) on the curve \\(y = 1 + 250 x^3 - 3 x^5\\)\r\n  does the tangent line have the largest slope?\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\nThe slope of the tangent line is given by $y' = 750 x^2 -15 x^4$.\r\n\r\nConsider this to be a new function, $g(x)$, that we want to maximize (to get the {\\em largest} slope).  To maximize $g(x)$, we differentiate to find critical points:\r\n\\begin{align*}\r\n  g(x) & = 750 x^2 -15 x^4 \\\\\r\n\\mbox{ so } g'(x) & = 1500 x - 60 x^3 \\\\\r\n\\mbox{ set $g'$ = 0: } 0 & = 1500 x - 60 x^3 \\\\ \r\n0 &= 60x (25 - x^2) \\\\\r\n0 &= 60x (5 - x)(5+x) \\\\\r\nx & = 0, 5, -5\r\n\\end{align*}\r\nThese are the critical points of the slope function.  To determine\r\nwhich is a max, and which is a min, we can use either the first or second derivative tests.\r\nLet's use the 2nd here because differentiation of $g'$ will be easy:\r\n$g''(x) = 1500  - 180 x^2$ \\\\\r\n$g''(-5) = -3000 < 0$: concave down; $x=-5$ is a local max. \\\\\r\n$g''(0) = 1500 > 0$: concave up; $x=0$ is a local min. \\\\\r\n$g''(5) = -3000 < 0$: concave down; $x=5$ is a local max. \\\\\r\n\r\nThe values of $g(-5) = 9375$ and $g(5) = 9375$ are the slopes of the\r\noriginal function at $x=-5$ and $x=5$.  They are equal, so they are\r\nboth the common global maximum slope of $9375$.\r\n\\end{Solution}\r\n\r\n\\end{multicols}\r\n\\hrulefill\r\n\r\n\\begin{multicols}{2}\r\n\r\n\\subsection*{Optimization With MATLAB}\r\n\r\nFor Questions \\ref{qoptmatlab1}-\\ref{qoptmatlab2}, use MATLAB to:\r\n\\begin{itemize}\r\n\\item generate a graph of the given function on the domain shown, and\r\n\\item use the \\texttt{fminbnd} function to find the global maximum and\r\n  global minimum of the function on that interval.\r\n\\end{itemize}\r\n\r\n% ******************************\r\n\\item \\label{qoptmatlab1}\r\n\\begin{Question}\r\n$f(x)= 7 e^{7 x^3 -  7 x} , \\mbox{ on }  -1 \\leq x \\leq 0$\r\n\\end{Question}\r\n\\begin{Solution}\r\n\r\nAll the examples will be solved with the same basic architecture. \r\n\r\nIn the MATLAB plots, \r\n\\begin{itemize}\r\n\\item the global {\\bf min} will be shown as a {\\bf red} dot, and\r\n\\item the global {\\bf max} will be shown as a {\\bf green} dot.\r\n\\end{itemize}\r\n\r\nIf there is anything special that is required in the solving, it will\r\nbe mentioned in text, as well as a commetn in the MATLAB code.\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptExp1.m}{W03OptExp1.m}\r\n\r\n\\lstinputlisting{MATLAB/W03OptExp1.m}\r\n\r\nFinal answer:\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n   -0.0001    7.0032\r\n\r\nGlobal max (x, y) \r\n   -0.5774  103.5662\r\n\\end{verbatim}\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n$f(x)= 7 x - 21 \\ln (x),\\mbox{ on } \\ [1,4]$\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n\r\n  For all the following problems, we will just provide a link to the\r\n  solution MATLAB file, and the final answer, rather than including it\r\n  in the PDF.\r\n\r\n  Looking at the graph, this function has a clear global max at the\r\n  left boundary of the interval, and a global min at the critical\r\n  point at $x=1$.\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptLn1.m}{W03OptLn1.m}\r\n\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n    3.0000   -2.0709\r\n\r\nGlobal max (x, y) \r\n    1.0000    6.9994\r\n\\end{verbatim}\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \\par \r\n$f(x)= 4 e^{-x} - 4 e^{-2 x}, \\mbox{ on }\\ [0,1]$\r\n\\end{Question}\r\n\\begin{Solution}\r\n  Looking at the graph, this function has a clear global max at the\r\n  left boundary of the interval, and a global min at the critical\r\n  point at $x\\approx 0.6931$ (exact value is $x = \\ln(2)$).\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptExp2.m}{W03OptExp2.m}\r\n\r\nNotice that MATLAB doesn't return {\\em exactly} $x=0$ for the global\r\nminimum, but just the very small\r\n$x = 0.0661\\times 10^{-3} = 0.0000661$.  This kind of slight deviation\r\nfrom the exact value is common with numerical methods.\r\n\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n   1.0e-03 *\r\n\r\n    0.0661    0.2644\r\n\r\nGlobal max (x, y) \r\n    0.6931    1.0000\r\n\\end{verbatim}\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n$f(x)= 7 x - 14 \\cos (x), \\mbox{ on }  [-\\pi,\\pi]$\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  Looking at the graph, this function has \r\n  \\begin{itemize}\r\n  \\item a clear global max at the\r\n  right boundary of the interval, and \r\n\\item a global min at the critical point at $x\\approx -0.5236$.\r\n  \\end{itemize}\r\n\r\n  There is a local max around $x=-2.8$ that isn't found by\r\n  \\texttt{fminbnd} when the interval is $[-\\pi, pi]$.\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptTrig1.m}{W03OptTrig1.m}\r\n\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n   -0.5236  -15.7895\r\n\r\nGlobal max (x, y) \r\n    3.1415   35.9907\r\n\\end{verbatim}\r\n\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n \\par \r\n$f(x)= ( 3 \\cos x ) / (20 + 10 \\sin x ), \\ 0 \\leq x \\leq 2 \\pi$\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n\r\n  This example requires some care, as the default search with\r\n  \\texttt{fminbnd} does {\\bf not} find the correct global maximum.\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptTrig2.m}{W03OptTrig2.m}\r\n\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n    3.6652   -0.1732\r\n\r\nEndpoint (x, y) \r\n    0.0001    0.1500\r\n\r\nGlobal max (x, y) \r\n    5.7596    0.1732\r\n\\end{verbatim}\r\n\\end{Solution}\r\n% ******************************\r\n\\item\\label{qoptmatlab2}\r\n\\begin{Question}\r\n \\par \r\n \\(f(t)=\\frac{10}{t}+4, 0 < t \\leq 1\\)  \\\\\r\n Note the open end due to the $0 < t$ instead of $0 \\le t$.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n\r\n  {\\bf Variables}: note that you can choose to change the $x$\r\n  variables in your script to \\texttt{t}, or just note that the\r\n  function $\\ds f(x) = \\frac{10}{x} + 4$ has all the same properties\r\n  as $\\ds f(t) = \\frac{10}{t} + 4$.\r\n\r\n  {\\bf Open Interval: }Even though we are working on an open interval,\r\n  we can still try to use \\texttt{fminbnd}.  We just need to be\r\n  careful when running it, and interpreting its results.\r\n\r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W03OptRecip1.m}{W03OptRecip1.m}\r\n\r\n  If you run your \\texttt{fminbnd} with $t=0$ as a boundary, you will get an error:\r\n\\begin{verbatim}\r\nError using fminbnd (line 219)\r\nUser supplied objective function must return a scalar value.\r\n\\end{verbatim}\r\n  This points to the fact that $f(0)$ is actually undefined (dividing\r\n  by zero).  As a result, the best you can do is try to use a small\r\n  but non-zero left limit, but then check your results against the\r\n  graph to be sure.\r\n\r\n\\begin{verbatim}\r\nGlobal min (x, y) \r\n    0.9999   14.0005\r\n\r\nGlobal max (x, y) \r\n   1.0e+04 *\r\n\r\n    0.0000    6.0209\r\n\\end{verbatim}\r\n  {\\bf However}, the global max is actually incorrect.  This function won't have a global max, \r\n  because there is a vertical asymptote at $t=0$, so there is no single highest point for this function.\r\n\r\n\\end{Solution}\r\n\r\n\\end{multicols}\r\n\\hrulefill\r\n\\subsection*{Optimization Word Problems}\r\n\r\n\\begin{multicols}{2}\r\n\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Some airlines have restrictions on the size of items of luggage that\r\npassengers are allowed to take with them.  Suppose that one has a rule\r\nthat the sum of the length, width and height of any piece of luggage\r\nmust be less than or equal to 192 cm.  A passenger wants to take a\r\nbox of the maximum allowable volume.    \r\n\\begin{enumerate}[(a)]\r\n\\item If the length and width are to\r\nbe equal, what should the dimensions be?\r\n\\item In this case, what is the volume? \r\n\\item If the length is be twice the width, what should the dimensions be? \r\n\\item In this case, what is the volume? \r\n\\end{enumerate}\r\nInclude units in all your answers.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\n  Let the length, width and height of the box be \\(L\\), \\(w\\) and\r\n  \\(h\\), respectively.  Then the volume of the box is \\(V = Lwh\\).\r\n  The sum \\(L + w + h = 192\\), and, for the first part, we know that\r\n  \\(L = w\\).  Thus \\(2w + h = 192\\), so \\(h = 192 - 2w\\), and the\r\n  volume equation becomes \\(V = Lwh = w\\cdot w\\cdot(192 - 2w) =\r\n  192\\cdot w^2 - 2w^3\\).  Since we need $h \\ge 0$ and $h = 192 - 2w$,\r\n  the domain for \\(w\\) is \\(0\\le w\\le 96\\).\r\n\\par \r\nCritical points are where \r\n\\(\\frac{dV}{dw} = 2\\cdot 192\\cdot w - 6\\cdot w^2 = 0\\), so \r\n\\(w = 0\\) or \\(w = 64\\).  The global maximum must occur either at\r\nthis point or at the end points.  \\(V(64) > 0\\) while \r\n\\(V(0) = V(96) = 0\\), so the global maximum is at \\(L=w=64\\), \r\nin which case \\(h=64\\) as well.  The volume is then \r\n\\(V = 64^3 = 262144 {\\rm cm}^3\\).\r\n\\par \r\nIf \\(L = 2w\\), \\(2w + w + h = 192\\), so \r\n\\(V = (2w)(w)(192 - 3w) = 384 w^2 - 6 w^3\\).  Proceeding as\r\nbefore, we find \\(w = \\frac{128}{3}\\), \\(L = \\frac{256}{3}\\) and \\(h = 64\\), so that \r\n\\(V = \\frac{2097152}{9}\\).\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n A wire 3 meters long is cut into two pieces.  One piece is bent\r\ninto a square for a frame for a stained glass ornament, while the\r\nother piece is bent into a circle for a TV antenna.  \r\n\\begin{enumerate}[(a)]\r\n\\item To reduce storage\r\nspace, where should the wire be cut to {\\bf minimize} the total area of both\r\nfigures? \r\n\\item Where should the wire be cut to {\\bf maximize} the total area?  \r\n\\end{enumerate}\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n  \\item Note that we are interested in {\\it the total area enclosed by\r\nthe two figures} .  Our first task is therefore to find an\r\nequation for this area, which will be the sum of the areas of the two\r\nfigures.\r\n\\par \r\nSuppose we cut \\(x\\) meters of wire to make the circular antenna.\r\nThen there are \\(3 - x\\) meters left for the square.  To find the\r\narea of the circle we need its radius.  The circumference of a circle\r\nof radius \\(r\\) is \\(C = 2\\pi r\\), so the radius of the circle is\r\ngiven by \\(2\\pi r = x\\), and so \\(r = \\frac{x}{2\\pi}\\).  The area\r\nof the circular antenna is therefore \r\n\\(A_c = \\pi r^2 = \\frac{1}{4\\pi} x^2\\).\r\n\\par \r\nThen the perimeter of a square with side length \\(s\\) is \r\n\\(P = 4 s = 3 - x\\), so the side length is \r\n\\(s = \\frac{1}{4}(3 - x)\\).  Then the area of a square is \r\n\\(A_s =  s^2\\), so the area of the square is \r\n\\(A_s =  (\\frac{1}{16})(3 - x)^2\\).\r\n\\par \r\nThe total area is therefore\r\n\\[A = \\frac{1}{4\\pi} x^2 +  (\\frac{1}{16})(3 - x)^2\r\n  = \\frac{1}{4\\pi} x^2 + \\frac{1}{ (16)}(9 - 6 x + x^2).\\]\r\nThe domain for \\(x\\) is \\(0\\le x\\le 3\\).  \r\n\\par  \r\nThe maximum and minimum of \\(A\\) will occur at critical or end\r\npoints.  Critical points are where \\(dA/dx = 0\\), or, where\r\n\\[\\frac{1}{2\\pi} x + \\frac{1}{ (16)}(2x - 6) = 0.\\]\r\nCollecting all terms in \\(x\\) we have\r\n\\[\\left( \\frac{1}{2\\pi} + \\frac{2 }{ (16)}\\right) x = \r\n  \\frac{6 }{16},\\]\r\nso, after simplifying, \r\n\\[x = \\frac{3 \\pi}{4 + \\pi}.\\]\r\n\\par \r\nTo determine if this is a local maximum or minimum, we use the second\r\nderivative test.  \r\n\\[A'' = \\left( \\frac{1}{2\\pi} + \\frac{2 }{ (16)}\\right) > 0,\\]\r\nso the function is concave up everywhere and this is a local minimum.\r\nAlso, because this is the {\\em only} critical point, this is also a {\\em global}\r\nminimum for the area.\r\n\r\nThus to minimize area we use \\(\\frac{3 \\pi}{4 + \\pi}\\) meters of wire\r\nfor the circle and \\(3 - \\frac{3 \\pi}{4 + \\pi}\\) meters for the\r\nsquare.\r\n\\item To {\\em maximize} the area, we can't use our critical point,\r\n  which was a minimum; instead we must use the endpoints.  The areas\r\n  at the endpoints are\r\n\\[A(0) = \\frac{9}{16} \\approx 0.56\\qquad{\\rm and}\\qquad\r\n   A(3) = \\frac{9}{4\\pi} \\approx 0.72,\\]\r\nthe larger of which is \\(A(3)\\), so the maximum area occurs when\r\nall of the wire is used for the circle and none for the square.\r\n  \\end{enumerate}\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n A printed poster is to have a total area of 799 square inches with top and\r\nbottom margins of 6 inches and side margins of 4 inches. What should be the\r\ndimensions of the poster so that the printed area be as large as possible?\r\nLet \\(x\\) denote the width of the poster and let \\(y\\)\r\ndenote the length. \r\n\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week03_OptimizationWordProblems/Poster}\r\n\r\n\\begin{enumerate}[(a)]\r\n\\item Write the function of $x$ and $y$ that you need to maximize.\r\n\\item Express that function in terms of $x$ alone. \r\n\\item Find the critical points of the function. \r\n\\item Use the second derivative test to verify that \\(f(x)\\) has a maximum at this critical point \r\n\\item Find the optimal dimensions of the poster, and the resulting area.  Include units.\r\n\\end{enumerate}\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n\r\n\\item $\\mbox{Area} = A = (x-2\\cdot 4 )(y - 2\\cdot 6)= (x - 8)(y - 12)$\r\n\\item By using the requirement that $799 = x y$, we get  $A = (x - 8)(799/x - 12)$\r\n\\item Differentiating and setting the derivative equal to zero, we obtain $x = 23.08$.\r\n\\item The second derivative of $A$ will be negative at $x = 23.08$, so\r\n  $A$ is concave down there, indicating $x=23.08$ is a local maximum for the printed area.\r\n\\item The dimensions of the poster with the largest printed area will be\r\n$23.08 \\times 34.62$, with a net printed area of 341.09 cm.\r\n  \\end{enumerate}\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n A box with an open top has vertical sides, a square bottom, and a volume of\r\n32 cubic meters. If the box has the least possible surface area, find its\r\ndimensions.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\nThis is the same question studied in the course videos.  Let the dimensions\r\nof the box be $w$ and $h$; the bottom is square so $w$ can represent the length of both \r\nsides of the bottom.  These combine to produce\r\n$$A = w^2 + 2(wh) + 2(wh), ~~~~ V = w^2h = 32$$\r\nSolving for $h$ in the $V$ equation, $\\ds h = 32/w^2$, we can write\r\n$A$ as just a function of $w$:\r\n\\begin{align*}\r\nA & = w^2 + 4w(32/w^2) \\\\\r\nA & = w^2 + 128/w \\\\\r\n\\end{align*}\r\nDifferentiating and setting $A' = 0$, you will find $w = 4$, and consequently $h = 32/w^2 = 2$.\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Find the dimensions of the rectangle of largest area that can be\r\ninscribed in an equilateral triangle with sides of length 2 if \r\none side of the rectangle lies on the base of the triangle.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\nThe optimal rectangle will be 1 unit on the base, and have height $\\ds \\frac{\\sqrt{3}}{2}$.\r\n\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n Find the minimum distance from the parabola \r\n \\[x - y^2 = 0\\]  to the point {(0,3)}.\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n\r\n\r\nThe point of closest approach will occur at $y=1$, and that will give a distance\r\nof $\\sqrt{ 1^2 + (3-1)^2} = \\sqrt{5}$.\r\n\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\n  I have enough pure silver to coat \\(2\\) square meters of surface\r\n  area.  I plan to coat a sphere and a cube.\r\n  \\begin{enumerate}[(a)]\r\n  \\item Allowing for the possibility of all the silver going onto one\r\n    of the solids, what dimensions should they be if the total volume\r\n    of the silvered solids is to be a maximum? \r\n  \\item Now allowing for the possibility of all the silver going onto\r\n    one of the solids, what dimensions should they be if the total\r\n    volume of the silvered solids is to be a minimum? \r\n  \\end{enumerate}\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\n  Let \\(s\\) be the length of the cube, \\(A\\) the total area, and \\(V\\)\r\n  the total volume.  Then\r\n\\[A=4\\pi r^2+6s^2\\]\r\nand\r\n\\[V= \\frac{4}{3}\\pi r^3 + s^3.\\]\r\nObviously, the volume is maximized if we put all of our stock in the\r\nsphere.  In that case, \r\n\\[r = \\sqrt{\\frac{A}{4\\pi}} \\approx 0.3989\\hbox{~meters}\\]\r\n(and \\(s=0\\) meters).\r\nTo minimize the volume we eliminate one of the variables and find a\r\nstationary point as usual.\r\nSolving the area equation for \\(s\\) gives\r\n\\[s= \\sqrt{\\frac{A-4\\pi r^2}{6}}.\\] Substituting this value in the\r\nvolume equation gives\r\n\\[V= \\frac{4}{3}\\pi r^3 + \\left(\\frac{A-4 \\pi\r\nr^2}{6}\\right)^{\\frac{3}{2}}.\\]\r\nDifferentiating with respect to \\(r\\) and setting to zero gives:\r\n\\[V'=4\\pi r^2 - \\frac{3}{2}\\times\\frac{8\\pi r}{6} \\left(\\frac{A-4 \\pi\r\nr^2}{6}\\right)^{\\frac{1}{2}} = 0.\\]\r\nThis simplifies to\r\n\\[2r = \\sqrt{\\frac{A-4 \\pi\r\nr^2}{6}}.\\]\r\nSquaring gives\r\n\\[4r^2 = \\frac{A-4 \\pi\r\nr^2}{6}\\]\r\nwhich gives\r\n\\[r = \\sqrt{\\frac{A}{24+4\\pi}} \\approx  0.2339\\hbox{~meters.}\\]\r\nThe corresponding value of \\(s\\) is\r\n\\[s = 2r = \\sqrt{\\frac{A}{6+\\pi}} \\approx  0.4677\\hbox{~meters.}\\]\r\n\\par\\end{Solution}\r\n% ******************************\r\n\\item\r\n\\begin{Question}\r\nSuppose that 241 ft of fencing are used to enclose a corral in the shape of a rectangle with a semicircle whose diameter is a side of the rectangle as the following figure:\\leavevmode\\\\\\relax \r\n\\includegraphics[width=0.3\\linewidth]{graphics/Week03_OptimizationWordProblems/WindowShape}\r\n\r\nFind the dimensions of the corral with maximum area. \r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\n\\par \r\nFrom the picture, we see that \\(x\\) is the width of the corral, and therefore the diameter of the semicircle, \\leavevmode\\\\\\relax  and that \\(y\\) is the height of the rectangular section. Thus the perimeter of the corral can be expressed \\leavevmode\\\\\\relax \r\nby the equation \\(2y+ x+ \\frac{\\pi}{2}x= 2y + (1+ \\frac{\\pi}{2})x= 241\\) ft or equivalently, \\leavevmode\\\\\\relax \r\n\\(y=\\frac{1}{2}(241 - (1+ \\frac{\\pi}{2})x)\\). Since \\(x\\) and \\(y\\) must both be non-negative, it follows that \\(x\\) must \\leavevmode\\\\\\relax \r\nbe restricted to the interval \\([0, \\frac{241}{1+ \\pi/2}]\\). The area of the corral is the sum of the area of the \\leavevmode\\\\\\relax \r\nrectangle and semicircle, \\(A= xy + \\frac{\\pi}{8}x^2\\). Making the substitution for \\(y\\) from the \\leavevmode\\\\\\relax \r\nconstraint equation, \\par \r\n\\(A(x)=\\frac{1}{2}x(241 - (1+ \\frac{\\pi}{2})x) + \\frac{\\pi}{8}x^2 = 120.5 x - \\frac{1}{2}(1+ \\frac{\\pi}{2})x^2 + \\frac{\\pi}{8}x^2\\). \\leavevmode\\\\\\relax \r\nNow, \\(A'(x) = 120.5 - (1 + \\frac{\\pi}{2})x + \\frac{\\pi}{4}x = 0\\) implies \\(x= \\frac{120.5}{(1+ \\frac{\\pi}{4})} \\approx 67.4919\\).  \\leavevmode\\\\\\relax \r\nWith \\(A(0)=0\\), \\par \r\n\\(A(\\frac{120.5}{(1+ \\frac{\\pi}{4})}) \\approx 4066.39 \\qquad\\) and \\(\\qquad A(\\frac{241}{1+ \\frac{\\pi}{2}}) \\approx 3451.11\\), \\leavevmode\\\\\\relax \r\nit follows that the corral of maximum area has dimensions \\par \r\n\\(x= \\frac{120.5}{1+ \\frac{\\pi}{4}} \\qquad\\) and \\\\\r\n\\(\\qquad y= \\frac{1}{2}(241 - (1+ \\frac{\\pi}{2}) \\frac{120.5}{1+ \\frac{\\pi}{4}}) \\approx 33.746\\).\r\n\\par\\end{Solution}\r\n% \\item\r\n% \\begin{Question}\r\n \r\n% \\par \r\n% Find the maximum area of a triangle formed in the first quadrant by the \\(x\\)-axis, \\(y\\)-axis and a tangent line to the graph of \\(f=(x + 2)^{-2}\\).\r\n% \\par  \\end{Question}\r\n% \\begin{Solution}\r\n \r\n% Let \\(P\\left(t,\\frac{1}{(t+2)^2}\\right)\\) be a point on the graph of the curve \\(y=\\frac{1}{(x+2)^2}\\) in the first quadrant. The tangent line to the curve at \\(P\\) is\r\n% \\[L(x)=\\frac{1}{(t+2)^2}-\\frac{2(x-t)}{(t+2)^3},\\]\r\n% which has \\(x\\)-intercept \\(a=\\frac{3t+2}{2}\\) and \\(y\\)-intercept \\(b=\\frac{3t+2}{(t+2)^3}\\). The area of the triangle in question is\r\n% \\[A(t) = \\frac{1}{2}ab = \\frac{(3t+2)^2}{4(t+2)^3}.\\]\r\n% Solve\r\n% \\[A'(t) = \\frac{(3t+2)(3\\cdot 2-3t)}{4(t+2)^4} = 0\\]\r\n% for \\(0 \\le t\\) to obtain \\(t = 2\\).  Because \\(A(0) = \\frac{1}{4 \\cdot 2}\\), \\(A(2) = \\frac{1}{2 \\cdot 2}\\) and \\(A(t) \\to 0\\) as \\(t \\to \\infty\\), it follows that the maximum area is \\(A(2) = 0.25\\).\r\n% \\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n \r\n\\par \r\nA box is constructed out of two different types of metal. The metal for\r\nthe top and bottom, which are both square, costs \\$4 per square foot\r\nand the metal for the sides costs \\$6 per square foot. Find the\r\ndimensions that minimize cost if the box has a volume of 35 cubic\r\nfeet.\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nLet \\(x>0\\) be the length of a side of the square base and \\(z>0\\) the height of the box. With volume \\(x^{2} z=35\\), we have \\(z=35/x^{2}\\) and cost\r\n\\[C(x)=4\\cdot 2\\cdot x^{2}+6\\cdot 4\\cdot xz=8x^{2}+840\\frac{1}{x}.\\]\r\nSolve \\(C'(x)=8\\cdot 2x-840x^{-2}=0\\) to obtain \\(x= \\left(\\frac{35 \\cdot 6}{4} \\right)^{1/3}\\). \r\nSince \\(C(x) \\to \\infty\\) as \\(x \\to 0+\\) and as \\(x \\to \\infty\\), the minimum cost is \r\n\\(C\\left( (\\frac{35 \\cdot 6}{4})^{1/3} \\right)\r\n\\approx \\$ 336.499\\) \r\nwhen \r\n\\(x\\approx 3.74444\\textrm{ ft}\\) \r\nand \r\n\\(z\\approx 2.49629\\textrm{ ft}\\).\r\n\\par\\end{Solution}\r\n%\\item\r\n%\\begin{Question}\r\n% A manufacturer has been selling 1550 television sets a week at \\$540\r\n% each.  A market survey indicates that for each \\$23 rebate offered to\r\n% a buyer, the number of sets sold will increase by 230 per week.  \r\n% \\begin{enumerate}[(a)]\r\n% \\item Find the price, $p(x)$, as a function of $x$, where \\(x\\) is\r\n%   the number of the television sets sold per week.\r\n% \\item How large rebate should the company offer to a buyer, in order\r\n%   to maximize its revenue?\r\n% \\item If the weekly cost function is \\(139500 + 180 x\\), how should\r\n%   it set the size of the rebate to maximize its profit?\r\n% \\end{enumerate}\r\n%\\par\\end{Question}\r\n%\\begin{Solution}\r\n% \\begin{enumerate}[(a)]\r\n%\\item $p(x) = (1550-x)/10 +540$.\r\n%\\item Revenue = price $\\times$ demand = $(540 - 23\\cdot x) (1550-x)/10 +540$.\r\n%Finding the critical point of the revenue function, you will find $x = 192.5$.\r\n%\\item Build profit as revenue - cost. Compute the critical points, and\r\n% you will find $x= 102.5$ produces a maximum profit.\r\n% \\end{enumerate}\r\n%\r\n%\\end{Solution}\r\n% \\item\r\n% \\begin{Question}\r\n%   A baseball team plays in he stadium that holds 72000\r\n%   spectators. With the ticket price at 12 the average attendence has\r\n%   been 30000. When the price dropped to 11, the averege attendence\r\n%   rose to 36000.  \\leavevmode\\\\\\relax \r\n%   \\begin{enumerate}[(a)]\r\n%   \\item Find the demand function \\(p(x)\\), where \\(x\\) is the number\r\n%     of the spectators. (assume \\(p(x)\\) is linear.)\r\n%   \\item How should be set a ticket price to maximize revenue?\r\n%   \\end{enumerate}\r\n% \\par\\end{Question}\r\n% \\begin{Solution}\r\n%  {\r\n% \\vspace{-\\parskip}\\begin{itemize}\r\n% \\item $(30000-x)*1/(6*1000) +12$\r\n% \\item 8.5 \r\n% \\end{itemize}}\\par\r\n%\\end{Solution}\r\n%\\item\r\n%\\begin{Question}\r\n% For the cost function \\(C(x) = 40000+800 x + x^2\\) find: \r\n% \\begin{enumerate}[(a)]\r\n%\\item The cost at the production level 1650.\r\n%\\item The average cost at the production level 1650.\r\n%\\item The marginal cost at the production level 1650 (this is the in.\r\n%\\item The production level that will minimize the average cost.\r\n%\\item The minimal average cost.  \r\n% \\end{enumerate}\r\n%\\par\\end{Question}\r\n%\\begin{Solution}\r\n%  \\begin{enumerate}[(a)]\r\n%\\item 4082500 \r\n%\\item 2474.24242424242 \r\n%\\item 4100 \r\n%\\item 200 \r\n%\\item 1200 \r\n%  \\end{enumerate}\r\n%\r\n%\\end{Solution}\r\n% \\item\r\n% \\begin{Question}\r\n%   A rectangle is inscribed with its base on the \\(x\\) axis and its\r\n%   upper corners on the parabola \\(y= 12 - x^2\\).  What are the\r\n%   dimensions of such a rectangle with the greatest possible area?\r\n% \\par  \\end{Question}\r\n% \\begin{Solution}\r\n \r\n% To solve this problem, we need to find an expression for the area of the \r\n% rectangle in terms of one of its dimensions, and then use derivatives to\r\n% maximize this area.  First, however, we can simply things quite a bit by \r\n% noting that the parabola given by \\(y = 12 - x^2\\) is symmetric about \r\n% the \\(y\\)-axis.  Therefore, the inscribed rectangle will also be symmetric \r\n% about the \\(y\\)-axis.  So it is enough to find the dimensions of half of this \r\n% rectangle and double the x value.\r\n% \\par \r\n% Our rectangle will therefore have the bottom left corner \\((0,0)\\) and the top\r\n% right corner \\((x,12-x^2)\\) where \\(x\\) is the width of the rectangle, \r\n% and \\(12 - x^2\\) is its height.  Thus, the area of the rectangle is\r\n% given by \\(f(x) = x(12-x^2) = {12}x-x^3\\) where \\(x\\) is the width \r\n% of the rectangle.  We now find the derivative of this and solve for zero \r\n% to find critical points.\r\n% \\par \r\n% The derivative is \\(f'(x) = 12 - 3x^2\\).  Setting this equal to 0 and \r\n% recalling that we are talking about widths, so that all \\(x\\) values \r\n% should be positive, we get:\r\n% \\par \r\n% \\[\\begin{aligned}\r\n%     f'(x) & = 0 \\\\\r\n%     12 - 3x^2 & = 0 \\\\\r\n%     3x^2 & = 12 \\\\\r\n%      x^2 & = \\frac{12}{3} = 4 \\\\\r\n%      x & = \\sqrt{4} = 2\r\n%   \\end{aligned}\\]\r\n% \\par \r\n% It is easy to check that the second derivative of \\(f(x)\\) is negative everywhere, \r\n% so this is a maximum of \\(f(x)\\).  Therefore, this is the width of the rectangle with the\r\n% maximum area. Actually, it is the width of half of that rectangle, since we were\r\n% ignoring the half on the left side of the y-axis. So the width of the whole rectangle is \\(2\\cdot 2 =  4\\).  The height is given by \r\n% plugging \\(x=2\\) into the formula for the parabola, giving\r\n% \\(12 - (2)^2  = 12 - 4 = 8 \\).\r\n% \\par\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n Centerville is the headquarters of Greedy Cablevision Inc. The\r\ncable company is about to expand service to two nearby towns,\r\nSpringfield and Shelbyville.  There needs to be cable connecting\r\nCenterville to both towns.  The idea is to save on the cost of\r\ncable by arranging the cable in a Y-shaped configuration.\r\nCenterville is located at\r\n\\((8,0)\\) in the \\(xy\\)-plane, Springfield is at \\((0,5)\\), and\r\nShelbyville is at \\((0,- 5)\\). The cable runs from Centerville\r\nto some point \\((x,0)\\) on the \\(x\\)-axis where it splits into two branches going to\r\nSpringfield and Shelbyville. Find the location \\((x,0)\\)\r\nthat will minimize the amount of cable between the 3 towns and\r\ncompute the amount of cable needed. Justify your answer.\r\n\\par \r\n\\begin{enumerate}[(a)]\r\n\\item What function of $x$ needs to be minimized to solve this problem?\r\n\\item Find the critical points of $f(x)$.\r\n\\item Use the second derivative test to verify that \\(f(x)\\) has a minimum at this critical point.\r\n\\item Compute the minimum amount of wire needed.\r\n\\end{enumerate}\r\n\\par\\end{Question}\r\n\\begin{Solution}\r\n  \\begin{enumerate}[(a)]\r\n\\item Draw a sketch.   \\\\\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week03_OptimizationWordProblems/Cablevision}\r\n\r\nWith $x$ being the horizontal component of the diagonal lines, the\r\ntotal length of the cable will be $L(x) = 2 \\sqrt{x^2+5^2}+(8 -x)$.\r\n\\item Taking the derivative and finding critical points of $L(x)$ yields $x = 2.89$.\r\n\\item The second derivative of $L(x)$ will be positive at $x = 2.89$, indicating that\r\nthe critical point is a local minimum for the length of cable. \r\n\\item $L(2.89) = 2 \\sqrt{(2.89)^2 + 25} + (8-2.89) = 16.66$ units of cable.\r\n  \\end{enumerate}\r\n\r\n\\end{Solution}\r\n\\item\r\n\\begin{Question}\r\n  A cylinder is inscribed in a right circular cone of height 4 m and\r\n  radius (at the base) equal to 3.5 m.  What are the dimensions of\r\n  such a cylinder which has maximum volume?\r\n\\par  \\end{Question}\r\n\\begin{Solution}\r\n \r\nAs we are attempting to maximize the volume of the inscribed cylinder,\r\nwe must first come up with a formula for the volume of this cylinder.\r\nLet \\(x\\) be the radius of the cylinder, \\(v(x)\\) the volume.  We \r\nknow from basic geometry that the formula for volume is give by \r\n\\(\\pi x^2h\\) where \\(x\\) is the radius and \\(h\\) is the height\r\nof the cylinder.  So in order to come up with a formula for volume\r\nin terms of \\(x\\) only, we need to relate \\(x\\) to \\(h\\).\r\n\\par \r\nThis is where the information about the cone comes in handy.  The cone is \r\na right circular cone.  Thus, inscribing the cylinder will fill up\r\nsome of the base of the cone, and just touch the slanted side, leaving\r\na similar right circular cone at the top.  This new cone will have a\r\nradius of \\(x\\) and a height of \\(4 - h\\) where \\(x\\) and \\(h\\) are as in the formula for the volume of our cylinder.  As this cone is\r\nsimilar to the original, we can use ratios to get:\r\n\\par \r\n\\[\\frac{x}{3.5}=\\frac{4 - h}{4}\\]\r\n\\par \r\nSimplifying this, we get \\(h = 4 - \\frac{4}{3.5}x\\).  \r\nTherefore, our formula for volume in terms of \\(x\\) becomes \\(v(x) = \\pi \r\nx^2(4 - \\frac{4}{3.5}x) = (4\\pi)x^2 - \r\n(\\frac{4}{3.5}\\pi)x^3\\)\r\n\\par \r\nNow, we want to maximize this.  So we will first take the derivative.  \r\nUsing the rules for differentiation of polynomials, the derivative is \\(v'(x) = 2(4\\pi)x - 3(\\frac{4}{3.5}\\pi)x^2\\).  Solving\r\nfor zero, we get, as we don't want \\(x = 0\\), the following.\r\n\\par \r\n\\[\\begin{aligned}\r\n      v'(x)  & = 0 \\\\\r\n      2(4\\pi)x - 3(\\frac{4}{3.5}\\pi)x^2 & = 0 \\\\\r\n      \\pi x(2(4) - 3\\frac{4}{3.5}x) & = 0 \\\\\r\n      2(4) - 3\\frac{4}{3.5}x & = 0 \\\\\r\n      3\\frac{4}{3.5}x & = 2(4) \\\\\r\n      x & = \\frac{2}{3}(3.5) = 2.333 \\mbox{ m}\\\\\r\n    \\end{aligned}\\]\r\nThen, using the formula for height we came up with before, the height\r\ncan be determined by:\r\n\\[h = 4 - \\frac{4}{3.5}(2.333) = 1.333\\mbox{ m}\\]\r\n\\par\\end{Solution}\r\n% \\item\r\n% \\begin{Question}\r\n%  A small island is 3 miles from the nearest point P on the straight\r\n% shoreline of a large lake.  If a woman on the island can row a boat\r\n% 2 miles per hour and can walk 3 miles per hour, where should\r\n% the boat be landed in order to arrive at a town 8 miles down the\r\n% shore from P in the least time?  Let \\(x\\) be the distance (in miles) between\r\n% point P and where the boat lands on the lakeshore.\r\n% \\begin{enumerate}[(a)]\r\n% \\item Enter a function \\(T(x)\\) that describes the total amount of\r\n% time the trip takes as a function of the distance \\(x\\).\r\n% \\item What is the distance \\(x = c\\) that minimizes the travel time?\r\n% \\item What is the least travel time?  \r\n% \\end{enumerate}\r\n% \\end{Question}\r\n% \\begin{Solution}\r\n% See the similar example in the course notes.\r\n% \\begin{enumerate}[(a)]\r\n% \\item \\begin{align*}\r\n% T(x)&  = \r\n% \\frac{\\mbox{water dist}}{\\mbox{water speed}} + \r\n% \\frac{\\mbox{land dist}}{\\mbox{land speed}} \\\\\r\n% & = \\frac{\\sqrt{9+x^2}}{2}+\\frac{(8-x)}{3}\r\n% \\end{align*}\r\n% \\item The minimum of $T(x)$ will occur when $x = 2.68$ miles.\r\n% \\item For that landing point, the travel time will be $T(2.68) = 3.78$\r\n%   hours or about 3 hours and 45 minutes.\r\n% \\end{enumerate}\r\n%\r\n%\\end{Solution}\r\n\r\n\r\n\\end{multicols}\r\n\r\n\\end{enumerate}\r\n\\end{document}\r\n", "meta": {"hexsha": "1b39bd73e5352df1e62b73dc8586427eae8d3fe3", "size": 58400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PracticeProblems/Week03.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/Week03.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/Week03.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": 39.4861392833, "max_line_length": 285, "alphanum_fraction": 0.6128424658, "num_tokens": 20765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6389516835465168}}
{"text": "\\chapter{Interpolation of the data}\n\\label{Sec:interpolate}\nThe data in \\xendl\\ representing the probability density\n$\\pi(E', \\mu \\mid E ) = \\pi_r(E', \\mu \\mid E )$ in the integrals (\\ref{Inum}) and~(\\ref{Ien})\nare given in various forms.  In the case of tabulated data, intermediate\nvalues must be obtained via some sort of interpolation.  Interpolation\nwith respect to one independent variable is described first, followed by a discussion of\nthe 2-dimensional case.  In \\xendl\\ full 3-dimensional interpolation\nof $\\pi(E', \\mu \\mid E )$ data is reduced to a sequence of 2-dimensional\ninterpolations.\n\n\\section{Interpolation methods for a single variable}\\label{Sec:1d-interp}\nFor the sake of having a specific application,\nthe discussion here is given in terms of tables of data $\\{E_i, f(E_i)\\}$,\nwith values $E_i$ of the energy of the outgoing particle as independent variable.\nThese ideas are applicable to one dimension for any tabular data.\nThe types of interpolation method used in \\xendl\\ \nfor such tables are: histogram, linear-linear, \nlog-linear, linear-log, and log-log.  The algorithms for interpolation\nof $F(E)$ on an interval $E_0 < E < E_1$ with given $f(E_0)$ and~$f(E_1)$\nare as follows.  In these definitions it is assumed that the argument of a\nlogarithm is positive.\n\n\\subsection{Histograms}\nFor histogram interpolation set\n$$\n  f(E) = f(E_0) \\quad \\text{for $E_0 \\le E < E_1$}.\n$$\n\n\\subsection{Linear-linear}\n For linear-linear interpolation set\n\\begin{equation}\n   \\alpha = \\frac{E - E_0}{E_1 - E_0}\n \\label{def-alpha}\n\\end{equation}\nand take\n$$\n  f(E) = (1 - \\alpha)f(E_0) + \\alpha f(E_1)\n   \\quad \\text{for $E_0 \\le E \\le E_1$}.\n$$\n\n\\subsection{Log-linear}\nFor log-linear interpolation take $\\alpha$ as in Eq.~(\\ref{def-alpha}),\nand set\n$$\n \\log f(E) = (1 - \\alpha)\\log f(E_0) + \\alpha \\log f(E_1)\n   \\quad \\text{for $E_0 \\le E \\le E_1$}.\n$$\nThis relation may also be written as\n\\begin{equation}\n  f(E) = f(E_0)^{1 - \\alpha} f(E_1)^\\alpha.\n \\label{loglin-interp}\n\\end{equation}\n\n\\subsection{Linear-log}\n For linear-log interpolation set\n\\begin{equation}\n   \\alpha' = \\frac{\\log(E / E_0)}{\\log( E_1 / E_0 )}\n \\label{def-alpha-prime}\n\\end{equation}\nand take\n$$\n  f(E) = (1 - \\alpha')f(E_0) + \\alpha' f(E_1)\n   \\quad \\text{for $E_0 \\le E \\le E_1$}.\n$$\n\n\\subsection{Log-log}\nFor log-log interpolation take $\\alpha'$ as in Eq.~(\\ref{def-alpha-prime}),\nand set\n$$\n \\log f(E) = (1 - \\alpha')\\log f(E_0) + \\alpha' \\log f(E_1)\n   \\quad \\text{for $E_0 \\le E \\le E_1$}.\n$$\nThis is equivalent to\n\\begin{equation}\n  f(E) = f(E_0)^{1 - \\alpha'} f(E_1)^{\\alpha'}.\n \\label{loglog-interp}\n\\end{equation}\n\n\\textbf{Remark.}\nWith log-linear interpolation written in the form of Eq.~(\\ref{loglin-interp})\nand log-log interpolation written as Eq.~(\\ref{loglog-interp}), it is permitted\nthat $f(E_0) = 0$ or $f(E_1) = 0$.  These cases all lead to the result that\n$f(E) = 0$ for $E_0 < E < E_1$, however.\n\n\\section{Interpolation methods for probability densities}\\label{Sec:2d-interp}\nIn order to explain the methods for interpolation of probability densities, it suffices to\nconsider a table of values $\\pi( E' \\mid E )$\n\\begin{equation}\n  \\{ E'_{j,k}, \\pi(E'_{j,k} \\mid E_k )\\} \\quad \\text{for $j = 0$, 1, $\\ldots\\,$, $J_k$}\n  \\label{EPtable}\n\\end{equation}\ngiven at values of the incident energy~$E_k$, for\n$k = 0$,~1, $\\ldots\\,$,~$K$.\nIn Eq.~(\\ref{EPtable}) it is required that the outgoing energies\nbe ordered\n\\begin{equation}\n  E'_{0,k} < E'_{1,k} \\le E'_{2,k} \\le \\cdots \\le E'_{J_k-1,k} < E'_{J_k,k}.\n  \\label{Eout-order}\n\\end{equation}\n\nThe condition Eq.~(\\ref{Eout-order}) permits the data of\nEq.~(\\ref{EPtable}) to have equal consecutive intermediate\noutgoing energies $E'_{j-1,k} = E'_{j,k}$, so that the probability\ndensity~$\\pi(E' \\mid E_k)$ may have a jump discontinuity there.\nJump discontinuities are not allowed at the end points $E' = E'_{0,k}$\nand~$E' = E'_{J_k,k}$.  In Eq.~(\\ref{EPtable}) the possibility \nof three or more consecutive equal outgoing energies may be ruled out,\nbecause all but the first and last would be redundant. \nThe convention adopted here is that the value of $\\pi(E' \\mid E_k)$\nat a discontinuity is the second data value\n$$\n \\pi(E' \\mid E_k) = \\pi(E'_{j,k} \\mid E_k) \\quad\n  \\text{if $E' = E'_{j-1,k} = E'_{j,k}$.}\n$$\n\nFor fixed incident energy $E_k$, the rules for interpolation of \n$\\pi(E' \\mid E_k )$ in outgoing energy~$E'$ are as given\nin Section~\\ref{Sec:1d-interp}.  The following types\nof interpolation with respect to $E$ are discussed in subsequent subsections:\n\\begin{enumerate}\n \\item direct interpolation.\n \\item unit-base interpolation,\n \\item interpolation using cumulative points.\n\\end{enumerate}\n\nThe method referred to here as ``interpolation by cumulative points''\nis closely related to ``interpolation by corresponding energies'' as described\nin the \\ENDF\\ manual~\\cite{ENDFB}.  \nFor a more-detailed discussion of 2-dimensional interpolation methods,\nsee the reference~\\cite{interpolation}.\n\nFor a discussion of interpolation of data Eq.~(\\ref{EPtable}), it suffices\nto consider interpolation between incident energies $E_0$ and~$E_1$.\nThus, it is desired to interpolate to incident energy~$E$ with\n$E_0 < E < E_1$ the data\n\\begin{equation}\n\\begin{split}\n  \\{ E'_{j,0}, \\pi(E'_{j,0} \\mid E_0 )\\} &\\quad \\text{for $j = 0$, 1, $\\ldots\\,$, $J_0$}, \\\\\n  \\{ E'_{j,1}, \\pi(E'_{j,1} \\mid E_1 )\\} &\\quad \\text{for $j = 0$, 1, $\\ldots\\,$, $J_1$}.\n  \\label{EPtables}\n\\end{split}\n\\end{equation}\nThe ideas presented apply equally well to interpolation of data\nin Eq.~(\\ref{EPtable}) between any consecutive pair of\nincident energies $E_{k-1} < E_k$.\n\nThe methods of 2-dimensional interpolation are described in turn.\nFor each of these methods the interpolated probability density $\\pi(E' \\mid E)$\nfor $E_0 < E < E_1$ has the proper norm\n\\begin{equation}\n  \\int\n  \\pi(E' \\mid E) \\ dE' = 1\n  \\label{piNorm}\n\\end{equation}\nwhen the interpolation rule with respect to incident energy~$E$ for the\ndata Eq.~\\eqref{EPtables} is linear-linear, histogram, or linear-log.\nThe norm condition Eq.~\\eqref{piNorm} is not usually satisfied when\nlog-linear or log-log interpolation is used for the incident energy.\n\n\\subsection{Direct interpolation}\\label{Sec:direct-interp}\nIt is common to do direct interpolation for interpolating tables of angular probability\ndensity~$\\pi( \\mu \\mid E)$ with respect to incident energy~$E$, because the\nrange of direction cosines is usually $-1 \\le \\mu \\le 1$.  For example, in order\nto determine the value of $\\pi( \\mu \\mid E)$ for $E_0 < E < E_1$ from data\nEq.~(\\ref{EPtables}), one first interpolates in $\\mu$\nat fixed incident energies to obtain $\\pi( \\mu \\mid E_0)$ and~$\\pi( \\mu \\mid E_1)$.\nOne then obtains the value of $\\pi( \\mu \\mid E)$ by interpolating between\n$\\pi( \\mu \\mid E_0)$ and~$\\pi( \\mu \\mid E_1)$.\n\nThe trouble with the application of direct interpolation to tables of \nenergy distributions\n is that the range of outgoing energy~$E'$\nusually depends on the incident energy~$E$.\nThus, for the data in Eq.~(\\ref{EPtables}), the ranges of outgoing energies\nare given by\n\\begin{equation}\n\\begin{split}\n  \\Eminzero' =  E'_{0,0} \\quad \\text{and} \\quad\n           \\Emaxzero' = E'_{J_0,0} \\quad \\text{for $E = E_0$}, \\\\\n  \\Eminone' =  E'_{0,1} \\quad \\text{and} \\quad\n           \\Emaxone' = E'_{J_1,1} \\quad \\text{for $E = E_1$}.\n  \\label{Eout-ranges}\n\\end{split}\n\\end{equation}\n\n\\textbf{Remark.}\nIn the definition of the range of outgoing energies Eq.~(\\ref{Eout-ranges}),\nit is natural to expect that the data in Eq.~(\\ref{EPtables}) are such that\nfor each incident energy $E_k$ with $k = 0,$~1, $\\ldots\\,$,~$K$, the probability\ndensity $\\pi(E' \\mid E_k )$ is not equal to zero on the entire lowest outgoing\nenergy range $E'_{0,k} < E' < E'_{1,k}$ or highest outgoing energy range\n$E'_{J_k - 1,k} < E' < E'_{J_k,k}$.  That is, \nEq.~(\\ref{Eout-ranges}) ought to give the\nactual range of outgoing energies.\nSome nuclear data libraries, e.~g.,\n\\ENDFdata~\\cite{ENDFdata}, have\ndata of the form Eq.~(\\ref{EPtable}) which imply that\n$\\pi(E' \\mid E_k ) = 0$ on the lowest or highest outgoing energy ranges.\nThe sample input data given in\nSection~\\ref{Sec:isotropic-table-lab} illustrates the problem.\n\nIt is convenient to describe the process of direct interpolation using\nnotation of set theory, with the sets\n\\begin{equation}\n\\begin{split}\n  \\calA_0 = \\{ E': \\Eminzero' \\le E' \\le\n           \\Emaxzero' \\}, \\\\\n  \\calA_1 = \\{ E':   \\Eminone' \\le E' \\le\n           \\Emaxone' \\}.\n  \\label{def-calA01}\n\\end{split}\n\\end{equation}\nThe union of these two sets is denoted by\n\\begin{equation}\n   \\calA_X = \\calA_0 \\cup \\calA_1,\n \\label{def-calA-X}\n\\end{equation}\nand the intersection is denoted by\n\\begin{equation}\n   \\calA_T = \\calA_0 \\cap \\calA_1,\n \\label{def-calA-T}\n\\end{equation}\n\nThere are two obvious interpretations of direct interpolation of\nthe data in Eq.~(\\ref{EPtables}) when the outgoing energy ranges\ndiffer, $\\calA_0 \\ne \\calA_1$.  One may do \\textit{direct interpolation\nwith extrapolation} or \\textit{direct interpolation\nwith truncation}.   Linear-linear versions of these methods are\ndescribed here. \n\nFor direct interpolation with extrapolation the probability densities\n$\\pi(E' \\mid E_0 )$ and $\\pi(E' \\mid E_1 )$ constructed from the\ntables in Eq.~(\\ref{EPtables})  are extrapolated to\n\\begin{equation}\n  \\pi_X(E' \\mid E_0 ) = \\begin{cases}\n    \\pi(E' \\mid E_0 ) &\\quad \\text{for $E'$ in $\\calA_0$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_X \\setminus \\calA_0$,}\n  \\end{cases}\n  \\label{def-pi-X0}\n\\end{equation}\nand\n\\begin{equation}\n  \\pi_X(E' \\mid E_1 ) = \\begin{cases}\n    \\pi(E' \\mid E_1 ) &\\quad \\text{for $E'$ in $\\calA_1$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_X \\setminus \\calA_1$.}\n  \\end{cases}\n  \\label{def-pi-X1}\n\\end{equation}\nFor direct interpolation\nto incident energy $E$ with $E_0 < E < E_1$,\nthe proportionality factor $q$ is  defined as\n\\begin{equation}\n  q = \\frac{ E - E_0}{ E_1 - E_0 }.\n  \\label{def-q}\n\\end{equation}\nIn linear-linear direct interpolation with extrapolation,\nthe interpolant is taken to be\n\\begin{equation}\n  \\pi_X(E' \\mid E ) = ( 1 - q )\\, \\pi_X(E' \\mid E_0 ) + q\\, \\pi_X(E' \\mid E_1 )\n  \\label{def-pi-X}\n\\end{equation}\nfor $E'$ in the set~$\\calA_X$.\n\nThe method of direct interpolation with truncation differs from\nthat using extrapolation, in that this method uses the truncated\nprobability densities\n\\begin{equation}\n \\begin{split}\n   \\pi_T(E' \\mid E_0 )& = C_0 \\pi(E' \\mid E_0 ), \\\\\n   \\pi_T(E' \\mid E_1 )& = C_1 \\pi(E' \\mid E_1 )\n  \\end{split}\n \\label{def-pi-T01}\n\\end{equation}\nfor outgoing energy $E'$ in the set~$\\calA_T$.  Here, $C_0$ \nand~$C_1$ are normalization constants such that\n$$\n   \\int_{\\calA_T} dE' \\, \\pi_T(E' \\mid E_0 ) = 1\n   \\quad \\text{and} \\quad\n   \\int_{\\calA_T} dE' \\, \\pi_T(E' \\mid E_1 ) = 1.\n$$\nFor linear-linear direct interpolation with truncation of the data in Eq.~(\\ref{EPtables})\nto incident energy $E$ with $E_0 < E < E_1$, the factor~$q$\nis chosen as in Eq.~(\\ref{def-q}), and the interpolant is\n$$\n  \\pi_T(E' \\mid E ) = ( 1 - q )\\, \\pi_T(E' \\mid E_0 ) + q\\, \\pi_T(E' \\mid E_1 )\n$$\nfor $E'$ in the set~$\\calA_T$.\n\n\\textbf{Remarks.}\nThe \\ENDFdata\\ data~\\cite{ENDFdata} contains many instances in which\nlinear-linear direct interpolation is specified, but the \\ENDF\\ manual~\\cite{ENDFB}\nsays nothing about how to deal with differences in range of outgoing\nenergies.  Both versions can be expected to produce violation of\nenergy conservation.  The {\\gettransfer} code\ncurrently uses direct interpolation with extrapolation.\n\n\\subsection{Unit-base interpolation}\\label{Sec:unitBase}\nOnly the linear-linear version of unit-base interpolation is discussed here.\nThe first step in unit-base interpolation is the construction of the\nrange of energies of the outgoing particle.  \nThe minimum and maximum\noutgoing energies for the data in Eq.~(\\ref{EPtables})\nare given by Eq.~(\\ref{Eout-ranges}).\nFor incident energy~$E$ with $E_0 < E < E_1$, the factor~$q$\nis taken as in Eq.~(\\ref{def-q}), and\n the minimum and maximum outgoing energies\nare given by\n\\begin{equation}\n \\begin{split}\n   \\Emin'& = ( 1 - q )\\Eminzero' + q \\Eminone', \\\\\n   \\Emax' & = ( 1 - q )\\Emaxzero' + q \\Emaxone'.\n  \\label{EoutRange}\n \\end{split}\n\\end{equation}\n\nThe interpolated probability density $\\pi(E' \\mid E)$ must\nsatisfy the normalization condition\n\\begin{equation}\n  \\int_{\\Emin'}^{\\Emax'} dE' \\, \\pi(E' \\mid E) = 1.\n \\label{probabilityNorm}\n\\end{equation}\nOne way to ensure this is to first map the outgoing energy ranges\nEq.~(\\ref{Eout-ranges}) to unit base $0 \\le \\Ehat' \\le 1$\nand to scale the probability densities Eq.~(\\ref{EPtables})\naccordingly.  Thus, for the data in Eq.~(\\ref{EPtables}) at\nincident energy~$E_0$, set\n\\begin{equation}\n  \\Ehat' = \\frac{ E' - \\Eminzero'}{ \\Emaxzero' - \\Eminzero'}\n  \\label{unit-base-map}\n\\end{equation}\nand scale the probability density\n\\begin{equation}\n  \\pihat(\\Ehat' \\mid E_0) = ( \\Emaxzero' - \\Eminzero' )\\pi(E' \\mid E_0).\n  \\label{unitbaseMap}\n\\end{equation}\nFor incident energy $E_1$, the outgoing energy is scaled\nas\n\\begin{equation}\n    \\Ehat' = \\frac{ E' - \\Eminone'}{ \\Emaxone' - \\Eminone'},\n  \\label{unit-base-map1}\n\\end{equation}\nand the probability density\nis scaled to define the unit-base probability\ndensity \n\\begin{equation}\n  \\pihat(\\Ehat' \\mid E_1) = ( \\Emaxone' - \\Eminone' )\\pi(E' \\mid E_1)\n  \\label{unitbaseMap1}\n\\end{equation}\nfor $0 \\le \\Ehat' \\le 1$.\n\nIf linear-linear interpolation with respect to incident energy is\ndesired, the proportionality factor $q$ defined in\nEq.~(\\ref{def-q}) is used to linearly interpolate between\n$\\pihat(\\Ehat' \\mid E_0)$ and $\\pihat(\\Ehat' \\mid E_1)$\nby setting\n\\begin{equation}\n  \\pihat(\\Ehat' \\mid E) = (1 - q)\\,\\pihat(\\Ehat' \\mid E_0) +\n   q \\,\\pihat(\\Ehat' \\mid E_1)\n \\label{unitbaseInterp}\n\\end{equation}\nfor $0 \\le \\Ehat' \\le 1$. \n\nFinally, in order to define the interpolated probability\ndensity $\\pi(E' \\mid E)$, invert the mappings Eq.~(\\ref{unit-base-map})\nand~Eq.~(\\ref{unitbaseMap}).  Specifically, with $\\Emin'$ and\n$\\Emax'$ as in Eq.~(\\ref{EoutRange}), set\n\\begin{equation}\n   E' = \\Emin' + ( \\Emax' - \\Emin')\\Ehat'\n \\label{range-inv}\n\\end{equation}\nand take\n\\begin{equation}\n  \\pi(E' \\mid E) = \\frac{\\pihat(\\Ehat' \\mid E)}{ \\Emax' - \\Emin' }.\n \\label{unitbaseInvert}\n\\end{equation}\n\nUnit-base interpolation is ordinarily not used with tables of\nangular probability densities~$\\pi( \\mu \\mid E)$, because the\nrange of direction cosines is usually~$-1 \\le \\mu \\le 1$.  One\nmay want to use it for a table with forward emission given in\nthe laboratory frame, however.\n\n\\subsection{Interpolation by cumulative points}\\label{Sec:cumProb}\nThe method of interpolation by cumulative points that is\nused in the code \\gettransfer\\ is proposed in~\\cite{interpolation},\nand it is a modification of interpolation by corresponding energies as described\nin the \\ENDF\\ manual~\\cite{ENDFB}.  \nInterpolation by corresponding energies requires the selection of\n$N$ equiprobable energy bins, so the result depends on the value of~$N$.\nIt is shown in~\\cite{interpolation} that for data Eq.~(\\ref{EPtable}) which are\nhistograms with respect to outgoing energy $E'$, interpolation by cumulative \npoints is equivalent to interpolation by corresponding energies with~$N = \\infty$.\nThe \\gettransfer\\ code therefore uses interpolation by cumulative points\nwhenever the data specify interpolation by corresponding energies.\n\nOne objection to unit-base interpolation is that the mapping\n(\\ref{unitbaseMap}) depends only\non the range of outgoing energies.\nOne can often get a better approximation to the physics if the\ninterpolation method incorporates\nknowledge of the local behavior of each $\\pi( E' \\mid E_k)$\nin Eq.~(\\ref{EPtable}).\nOne method of doing so is based on the cumulative\nprobability function\n\\begin{equation}\n  \\Pi( E' \\mid E_k) = \\int_{E'_{k,\\text{min}}}^{E'} dx\\, \\pi( x \\mid E_k)\n  \\label{cumProb}\n\\end{equation}\nfor $k = 0$,~1, $\\ldots\\,$,~$K$.\n\n\n\n\nBecause the data $\\pi( E' \\mid E_k)$ consist of probability densities,\nit follows that $\\pi( E' \\mid E_k) \\ge 0$.  Hence, $\\pi( E' \\mid E_k)$ \ns a non-decreasing function of~$E'$.  There are\nenergy distributions in the data library\n\\xendl~\\cite{GND} for which $\\pi( E' \\mid E_k ) = 0$\non an interval $E_{j - 1,k}' < E' < E_{j,k}$ for $k = 0$~or~1\nand for some values of $j = 1$, 2, $\\ldots\\,$, $J_k$.\nThe corresponding cumulative probability is constant\non such intervals.  The method of cumulative points\ndepends on solutions of the equation\n$$\n  \\Pi(E' \\mid E_k ) = Y\n$$\nfor given value of  $0 \\le Y \\le 1$.  Denote the\nlargest solution by\n$$\n  S = \\max \\left \\{ E': \\Pi(E' \\mid E_k ) = Y \\right \\}\n$$\nand the smallest solution by\n$$\n  T = \\min \\left \\{ E': \\Pi(E' \\mid E_k ) = Y \\right \\}.\n$$\nIf $\\pi( E' \\mid E_k ) = 0$ only at discrete\npoints, then $\\Pi(E' \\mid E_k )$ is strictly increasing\nand $S = T$.\n\nThe cumulative points method is defined as\nfollows.\n\\begin{enumerate}\n\\item For probability density data Eqs.~\\eqref{EPtables}\nat incident energy~$E_k$ with $k = 0$ and~1, compute the cumulative\nprobabilities $\\Pi( E' \\mid E_k )$ in Eqs.~\\eqref{cumProb}\nat the data points~$E_{j,k}'$ for $j = 0$, 1, $\\ldots\\,$, $J_k$.  \nDenote the result as\n\\begin{equation}\n  y_{j,k} = \\Pi( E_{j,k}' \\mid E_k ).\n \\label{def-phijk}\n\\end{equation}\n\\item Form the union of these two sets\n\\begin{equation}\n   \\{Y_\\ell\\} = \\{y_{j,0}\\} \\cup \\{y_{j,1}\\},\n \\label{def-Phi-cup}\n\\end{equation}\nremove duplicates, and arrange the remaining values\nin increasing order,\n\\begin{equation}\n  0 = Y_0 < Y_1 < \\cdots < Y_L = 1.\n \\label{Phi-ordered}\n\\end{equation}\n\\item For $k = 0$ and~1 and for each $Y = Y_\\ell$ with\n$\\ell = 1$, 2, $\\ldots\\,$, $L$,\ncompute the outgoing energies\n$S_{\\ell,k}'$ and~$T_{\\ell,k}'$ by solving the equations\n\\begin{equation}\n \\begin{split}\n     S_{\\ell,k}' &= \\max \\left \\{ E': \\Pi(E' \\mid E_k ) = Y_{\\ell-1} \\right \\}, \\\\\n      T_{\\ell,k}' &= \\min \\left \\{ E': \\Pi(E' \\mid E_k ) = Y_\\ell \\right \\}.\n \\end{split}\n  \\label{T-cum-prob-inv}\n\\end{equation}\n\\item For $k = 0$ and~1 form the intervals $\\calB_\\ell(E_k)$\n\\begin{equation}\n \\begin{split}\n   \\calB_\\ell(E_k) &= \\{E' : S_{\\ell,k}' \\le E' < T_{\\ell,k}' \\} \n     \\quad \\text{for $\\ell = 1$,~2, $\\ldots\\,$,~$L-1$,} \\\\\n   \\calB_L(E_k) &= \\{E' : S_{L,k}' \\le E' \\le T_{L,k}' \\}.\n \\end{split}\n  \\label{def-B-ell}\n\\end{equation}\nThe reason for omitting right-hand endpoints of\nintervals $\\calB_\\ell(E_k)$ for $\\ell < L$ in Eqs.~\\eqref{def-B-ell}\nis that they may be points of discontinuity\nof the original energy distributions in Eq.~\\eqref{EPtables}.\n\\item For incident energy $E$ with $E_0 < E < E_1$ do unit-base\ninterpolation of $\\pi( E' \\mid E_0 )$ on $\\calB_\\ell(E_0)$ with\n$\\pi( E' \\mid E_1 )$ on $\\calB_\\ell(E_1)$\nfor $\\ell = 1$,~2, $\\ldots\\,$,~$L$. The interpolation with\nrespect to~$E$ may be histogram, linear-linear, or linear-log.\nThe linear-linear version is as follows.  \nFor $k = 0$ and~1 use\n\\begin{equation}\n  \\Ehat' = \\frac{ E' -  S_{\\ell,k}'}{  T_{\\ell,k}' -  S_{\\ell,k}'}\n  \\label{unit-base-map-cum}\n\\end{equation}\nto map the interval $\\calB_\\ell(E_k)$\nto $0 \\le \\Ehat' < 1$ for $\\ell = 1$,~2, $\\ldots\\,$,~$L-1$ and to\n$0 \\le \\Ehat' \\le 1$ for $\\ell = L$.  Scale the probability density\naccordingly,\n\\begin{equation}\n  \\pihat(\\Ehat' \\mid E_k) = (T_{\\ell,k}' -S_{\\ell,k}' )\\pi(E' \\mid E_0).\n  \\label{unit-base-scale}\n\\end{equation}\nDefine the proportionality factor\n\\begin{equation}\n  \\alpha = \\frac{ E - E_0 }{ E_1 - E_0 }\n  \\label{def-alpha-cum}\n\\end{equation}\nand interpolate to obtain\n\\begin{equation}\n  \\pihat(\\Ehat' \\mid E) = (1 - \\alpha)\\pihat(\\Ehat' \\mid E_0) +\n   \\alpha \\pihat(\\Ehat' \\mid E_1)\n \\label{unitbaseInterpCum}\n\\end{equation}\nfor $0 \\le \\Ehat' < 1$ and $\\ell < L$ and for $0 \\le \\Ehat' \\le 1$ and $\\ell = L$.\nFor $\\ell = 1$,~2, $\\ldots\\,$,~$L$\ninterpolate the end points of the intervals $\\calB_\\ell(E_k)$ to\nobtain\n\\begin{equation}\n \\begin{split}\n  S_{\\ell,\\alpha}' &= (1 - \\alpha)S_{\\ell,0}' + \\alpha S_{\\ell,1}', \\\\\n  T_{\\ell,\\alpha}' &= (1 - \\alpha)T_{\\ell,0}' + \\alpha T_{\\ell,1}'.\n \\end{split}\n  \\label{energy-range}\n\\end{equation}\nAt incident energy~$E$ \nthe range of outgoing energies~$E'$ as taken as\n\\begin{equation}\n \\begin{split}\n   \\calB_\\ell(E) &= \\{E' : S_{\\ell,\\alpha}' \\le E' < T_{\\ell,\\alpha}' \\}\n     \\quad \\text{for $\\ell = 1$,~2, $\\ldots\\,$,~$L-1$,} \\\\\n   \\calB_L(E) &= \\{E' : S_{L,\\alpha}' \\le E' \\le T_{L,\\alpha}' \\}.\n \\end{split}\n  \\label{def-B-ell-alpha}\n\\end{equation}\nFinally, the interpolated probability\ndensity $\\pi( E' \\mid E )$ is obtained by inversion of the mapping\nEq.~\\eqref{unit-base-scale}, giving\n\\begin{equation}\n  \\pi(E' \\mid E) = \\frac{\\pihat(\\Ehat' \\mid E)}{  T_{\\ell,\\alpha}' -  S_{\\ell,\\alpha}'}\n \\label{map-inv}\n\\end{equation}\nfor $E'$ in $\\calB_\\ell(E)$.\nSet $\\pi(E' \\mid E) = 0$ for all outgoing energies~$E'$ which \nare not in any of the sets $\\calB_\\ell(E)$ for \n$\\ell = 1$,~2, $\\ldots\\,$,~$L$.\n\\end{enumerate}\n\nFor tables of angular probability densities~$\\pi( \\mu \\mid E)$, direct interpolation\nis often used for interpolating with respect to incident energy~$E$,\nbecause the direction cosines usually range over $-1 \\le \\mu \\le 1$.\nFor angular distributions with strong local features, interpolation by cumulative points \nmay be preferable.\n\n\n\\subsubsection{Practical considerations: intervals of zero length} \n\\label{Sec:cum-points-trivial}\nExperience with interpolation\nby cumulative points as described above shows that it must be\nmodified to deal with the inaccuracy of\ncomputer arithmetic.  In particular, it may happen that \nfor $k=0$ or~1 and for some $\\ell = \\widehat \\ell$\nthe values of $S'_{ \\ell,k}$ and~$T'_{ \\ell,k}$\nas obtained from Eq.~(\\ref{T-cum-prob-inv}) are computed to be equal.\nThe mapping Eq.~(\\ref{unit-base-map-cum}) to unit base is then undefined.\n\nThis phenomenon may be understood in terms of the computer's\nmachine epsilon, which is the smallest number $\\epsilon_{\\text{mach}}$\nsuch that $1 + \\epsilon_{\\text{mach}} > 1$ in the computer's arithmetic.\nIn double precision arithmetic a common value is\n$$\n  \\epsilon_{\\text{mach}}  = 2^{-52} \\approx 2.22 \\times 10^{-16}.\n$$\nIn particular, if the exact values of $S_{\\widehat \\ell,k}' $ and $T_{\\widehat \\ell,k}' $\nare such that $S_{\\widehat \\ell,k}' > 0$ and\n$$\n  T_{\\widehat \\ell,k}'  - S_{\\widehat \\ell,k}'  < \\epsilon_{\\text{mach}} S_{\\widehat \\ell,k}',\n$$\nthen the computer will say that $S_{\\widehat \\ell,k}' = T_{\\widehat \\ell,k}'$.\n\nConsider first the case that the probability density $\\pi(E' \\mid E_k )$ is\ngiven as a histogram.  Then in exact arithmetic the cumulative points algorithm \nensures the existence of $S_{\\widehat \\ell,k}' $ and $T_{\\widehat \\ell,k}' $\nsuch that\n\\begin{equation}\n  \\Pi(S_{\\widehat \\ell,k}' \\mid E_k ) = Y_{\\widehat \\ell-1}\n  \\quad \\text{and} \\quad\n  \\Pi(T_{\\widehat \\ell,k}' \\mid E_k ) = Y_{\\widehat \\ell}.\n \\label{get-S-T}\n\\end{equation}\nFurthermore, it is assured that $S_{\\widehat \\ell,k}'  < T_{\\widehat \\ell,k}' $\nand that\n$$\n  \\pi(E' \\mid E_k ) = \\pi_{\\widehat \\ell,k}\n  \\quad \\text{for} \\quad\n  S_{\\widehat \\ell,k}' \\le E' < T_{\\widehat \\ell,k}',\n$$\nwhere $\\pi_{\\widehat \\ell,k}$  is a positive constant.  Thus, if it happens\nthat\n\\begin{equation}\n  Y_{\\widehat \\ell} - Y_{\\widehat \\ell-1} <\n  \\epsilon_{\\text{mach}}  \\pi_{\\widehat \\ell,k} S_{\\widehat \\ell,k}' ,\n \\label{bad-cum-prob}\n\\end{equation}\nthe computer will conclude that $S_{\\widehat \\ell,k}' = T_{\\widehat \\ell,k}'$.\nBecause of the factor $\\pi_{\\widehat \\ell,k}$ appearing on the right-hand\nside of Eq.~{\\ref{bad-cum-prob}), this phenomenon is usually associated\nwith narrow resonances in the data.  The size of $ \\pi_{\\widehat \\ell,k}$ depends\non the units used for energy, but the product $ \\pi_{\\widehat \\ell,k} S_{\\widehat \\ell,k}' $\nis dimensionless, and it is typically large at a resonance.  For example, \nfor $S_{\\widehat \\ell,k}'  = 1\\,\\text{MeV}$ the value $ \\pi_{\\widehat \\ell,k} \n= 1.0 \\times 10^8\\,\\text{MeV}^{-1}$ is reasonable, and Eq.~(\\ref{bad-cum-prob})\ncould easily be satisfied.\n\nThe situation for a piecewise linear probability density $\\pi(E' \\mid E_k )$ is\na little different.  For one thing, the value $ \\pi_{\\widehat \\ell,k}$ in\nEq.~(\\ref{bad-cum-prob}) is replaced by the average\n$$\n  \\frac{1}{2} \\left(\n    \\pi( S_{\\widehat \\ell,k}' \\mid E_k ) +  \\pi( T_{\\widehat \\ell,k}' \\mid E_k ) \n  \\right).\n$$\nAnother difference from the histogram case is that the determination of\n$S_{\\widehat \\ell,k}' $ and $T_{\\widehat \\ell,k}' $ in Eq.~(\\ref{get-S-T}) \nrequire the solution of quadratic equations, with additional inaccuracy\nintroduced by the computer arithmetic.\n\nThis raises the question of what to do when the solution of\nEq.~(\\ref{T-cum-prob-inv}) gives values of $S_{ \\widehat \\ell,k}'$ and \n$T_{\\widehat \\ell,k}'$\nwhich are nearly equal for some $\\widehat \\ell$ and~$k$.\nThe first requirement is a definition of equality for computer arithmetic.\nIn the \\gettransfer\\ code $S'_{ \\widehat \\ell,k}$ and~$T'_{ \\widehat \\ell,k}$\nare considered to be essentially equal if\n\\begin{equation}\n  \\left| \n    S'_{ \\widehat \\ell,k} - T'_{ \\widehat \\ell,k}\n  \\right| <\n  \\frac{ \\delta_r} {2} \\left(\n    S'_{ \\widehat \\ell,k} + T'_{ \\widehat \\ell,k}\n  \\right),\n \\label{bad-unit-base}\n\\end{equation}\nwhere $\\delta_r$ is the parameter \\texttt{tight\\_tol}\ndescribed in Section~\\ref{Sec:floatingPoint}.  \n\n The decision on what to do in \\gettransfer\\ about such near equality of\n$S'_{ \\widehat \\ell,k}$ and~$T'_{ \\widehat \\ell,k}$  is based on the size of\n$Y_{\\widehat \\ell} - Y_{\\widehat \\ell-1}$.  Let $\\delta_c$\nbe the parameter \\texttt{cum\\_prob\\_skip} described in\nSection~\\ref{Sec:cum-prob-skip}. \nIf Eq~(\\ref{bad-unit-base})\nis satisfied and\n\\begin{equation}\n  Y_{\\widehat \\ell} - Y_{\\widehat \\ell-1} < \\delta_c,\n \\label{drop-B-ell}\n\\end{equation}\nthen the sets $\\calB_{\\widehat \\ell}(E_k)$ with $k = 0$,~1\nin Eq.~(\\ref{def-B-ell}) are omitted from the computation of the\ntransfer matrix.  This omission introduces an error of at most one part\nin~$1/\\delta_c$ in the transfer matrix.\n\nOn the other hand, if Eq~(\\ref{bad-unit-base})\nis satisfied and Eq~(\\ref{drop-B-ell}) is violated for some\n$\\widehat \\ell$ and~$k$, then in \\gettransfer\\ the interval\n$\\calB_{\\widehat \\ell}(E_k)$ is reduced to the point\n\\begin{equation}\n   \\calB_{\\widehat \\ell}(E_k) = \\{E' : E' = \\widetilde S_{\\widehat \\ell,k}' \\} \n  \\label{def-B-ell-point}\n\\end{equation}\nwith\n\\begin{equation}\n    \\widetilde S_{\\widehat \\ell,k}' =\n     \\frac{ 1} {2} \\left(\n    S'_{ \\widehat \\ell,k} + T'_{ \\widehat \\ell,k}\n  \\right),\n  \\label{def-S-ell-point}\n\\end{equation}\nand $\\pi( E' \\mid E_k )$ on $\\calB_{\\widehat \\ell}(E_k)$ is taken\nto be a delta function\n\\begin{equation}\n  \\pi( E' \\mid E_k ) = \\left(\n    Y_{\\widehat \\ell} - Y_{\\widehat \\ell - 1}\n   \\right)\n  \\delta( E' - \\widetilde S_{\\widehat \\ell,k}'  ).\n \\label{delta-data}\n\\end{equation}\nNote that in exact arithmetic the intervals $\\calB_{\\ell}( E_k )$ defined\nin Eq.~(\\ref{def-B-ell}) are disjoint.  For the construction here,\nhowever, there is no guarantee that the point $\\calB_{\\widehat \\ell}(E_k)$\nobtained from Eqs.~(\\ref{def-B-ell-point}) and~(\\ref{def-S-ell-point})\nis not contained in $\\calB_{\\widehat \\ell - 1}( E_k )$ or~$\\calB_{\\widehat \\ell + 1}( E_k )$.\n\nIf it happens that the delta function Eq.~(\\ref{delta-data}) is used\nfor both $k = 0$ and $k = 1$, then for incident energy~$E$ with\n$E_0 < E < E_1$, the set  $\\calB_{\\widehat \\ell}(E)$ in\nEq.~(\\ref{def-B-ell-alpha}) is defined as the single point\n$$\n  \\widetilde S_{\\widehat \\ell, \\alpha}' = ( 1 - \\alpha ) \\widetilde S_{\\widehat \\ell, 0}' +\n  \\alpha \\widetilde S_{\\widehat \\ell,1}'\n$$\nwith $\\alpha$ given by Eq.~(\\ref{def-alpha-cum}).  The\nprobability density on $\\calB_{\\widehat \\ell}(E)$ is taken to be\nthe delta function\n$$\n   \\pi( E' \\mid E ) = \\left(\n    Y_{\\widehat \\ell} - Y_{\\widehat \\ell - 1}\n   \\right)\n  \\delta( E' - \\widetilde S_{\\widehat \\ell, \\alpha}'  ).\n$$\n\nIt remains to consider the case when Eq~(\\ref{bad-unit-base})\nis satisfied and Eq~(\\ref{drop-B-ell}) is false for only one value\nof~$k$, say $k = 0$.  In that case the set $ \\calB_{\\widehat \\ell}(E_0)$\nreduces to a point as in Eqs.~(\\ref{def-B-ell-point}) and~(\\ref{def-S-ell-point}), and\n$\\pi( E' \\mid E_0 )$ on  $ \\calB_{\\widehat \\ell}(E_0)$ is defined to be as\nin Eq.~(\\ref{delta-data}) with $k = 0$.  For the mapping of this\n$\\pi( E' \\mid E_0 )$ on  $ \\calB_{\\widehat \\ell}(E_0)$ to unit base,\nEq.~(\\ref{unit-base-scale}) is replaced by in \\gettransfer\\ by\n$$\n  \\pihat(\\Ehat' \\mid E_0) = Y_{\\widehat \\ell} - Y_{\\widehat \\ell - 1}\n  \\quad \\text{for} \\quad\n  0 \\le \\Ehat'  \\le 1.\n$$\nAt incident energy~$E$ with $E_0 < E < E_1$ the interpolation\nEq.~(\\ref{unitbaseInterpCum}) is performed using $\\alpha$\ndefined by Eq.~(\\ref{def-B-ell-alpha}).  For inversion of the\nunit base map at incident energy~$E$, the range of outgoing\nenergies Eq.~(\\ref{energy-range}) is replaced by\n\\begin{equation*}\n \\begin{split}\n  S_{\\ell,\\alpha}' &= (1 - \\alpha) \\widetilde S_{\\widehat \\ell, 0}'  + \\alpha S_{\\ell,1}', \\\\\n  T_{\\ell,\\alpha}' &= (1 - \\alpha) \\widetilde S_{\\widehat \\ell, 0}'  + \\alpha T_{\\ell,1}'.\n \\end{split}\n  %\\label\n\\end{equation*}\nThe probability density $\\pi( E' \\mid E )$ for $S_{\\ell,\\alpha}' \\le E' <\nT_{\\ell,\\alpha}'$ is then calculated using the scaling Eq.~(\\ref{map-inv}).\n\n\n\\section{Unscaled interpolation of Kalbach-Mann data}\\label{Sec:Kalbach-r-interp}\nThe above discussion pertains to the interpolation of tables of probability densities,\nfor which maintenance of the norm condition Eq.~(\\ref{probabilityNorm})\nis essential.  The parameter~$r(\\Ecm', E)$ in Eq.~(\\ref{Kalbach-eta}) for the\nKalbach-Mann model of double-differential data is given as tables\ndepending on the energy $E$ of the incident particle and the energy $\\Ecm'$ of\nthe outgoing particle in the center-of-mass frame, and it has the different\nconstraint,\n\\begin{equation}\n  0 \\le r \\le 1.\n \\label{Kalbach-r-constraint}\n\\end{equation}\n\nAgain, it suffices to describe interpolation between Kalbach-Mann $r$\ndata between tables at incident energies $E_0$ and~$E_1$ with\n$E_0 < E_1$.  As in Eq.~(\\ref{def-calA01}),\nconsider the sets $\\calA_0$ of outgoing energies\nat $E = E_0$ and $\\calA_1$ at $E = E_1$.  For unscaled direct interpolation\nwith extrapolation, take $\\calA_X = \\calA_0 \\cup \\calA_1$ as in\nEq.~(\\ref{def-calA-X}), so that the extrapolated $r$ parameter is\n\\begin{equation*}\n  r_X(E', E_0 ) = \\begin{cases}\n    r(E', E_0 ) &\\quad \\text{for $E'$ in $\\calA_0$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_X \\setminus \\calA_0$,}\n  \\end{cases}\n%  \\label{def-r-X0}\n\\end{equation*}\nand\n\\begin{equation*}\n  r_X(E', E_1 ) = \\begin{cases}\n    r(E', E_1 ) &\\quad \\text{for $E'$ in $\\calA_1$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_X \\setminus \\calA_1$.}\n  \\end{cases}\n%  \\label{def-r-X1}\n\\end{equation*}\nThen for $E_0 < E < E_1$, for $q$ as in Eq.~(\\ref{def-q}) and for\n$E'$ in the set~$\\calA_X$, the linear-linear form of unscaled direct interpolation\nwith extrapolation becomes as in Eq.~(\\ref{def-pi-X}),\n\\begin{equation}\n  r_X(E', E ) = ( 1 - q )\\, r_X(E', E_0 ) + q\\, r_X(E', E_1 ).\n  \\label{r-direct-extrapolation}\n\\end{equation}\nThe extrapolation version of direct interpolation of the Kallbach-Mann\n$r$ parameter as in Eq.~(\\ref{r-direct-extrapolation}) is implemented in\nthe \\gettransfer\\ code.\n\nFor unscaled direct interpolation of the Kalbach-Mann $r$ parameter with\ntruncation, the outgoing energy $E'$ is restricted to the common \ndomain $\\calA_T = \\calA_0 \\cap \\calA_1$, and there is no change\nof scale analogous to that used for probability densities in\nEq.~(\\ref{def-pi-T01}).  Thus, the truncated Kalbach-Mann $r$ parameters\nfor incident energies $E_0$ and~$E_1$ are\n\\begin{equation*}\n  r_T(E', E_0 ) = \\begin{cases}\n    r(E', E_0 ) &\\quad \\text{for $E'$ in $\\calA_T$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_0 \\setminus \\calA_T$,}\n  \\end{cases}\n%  \\label{def-r-T0}\n\\end{equation*}\nand\n\\begin{equation*}\n  r_X(E', E_1 ) = \\begin{cases}\n    r(E', E_1 ) &\\quad \\text{for $E'$ in $\\calA_T$,} \\\\\n    0 &\\quad \\text{for $E'$ in $\\calA_1 \\setminus \\calA_T$.}\n  \\end{cases}\n%  \\label{def-r-T1}\n\\end{equation*}\nThe linear-linear version of unscaled direct\ninterpolation with truncation is\n\\begin{equation}\n  r_T(E', E ) = ( 1 - q )\\, r_T(E', E_0 ) + q\\, r_T(E', E_1 )\n  \\label{r-direct-truncation}\n\\end{equation}\nwith $E'$ restricted to~$\\calA_T$.\nThe \\gettransfer\\ code does not currently implement unscaled direct\ninterpolation with truncation of the Kalbach-Mann $r$ parameter\ngiven in Eq.~(\\ref{r-direct-truncation}).\n\nThere is also an unscaled version of unit-base interpolation with\nEqs.~(\\ref{unitbaseMap}) and~(\\ref{unitbaseMap1}) replaced by\n\\begin{equation*}\n \\begin{split}\n  \\widehat r(\\Ehat', E_0) &= r(E', E_0), \\\\\n  \\widehat r(\\Ehat', E_1) &= r(E', E_1), \\\\\n \\end{split}\n\\end{equation*}\nfor $0 \\le \\Ehat' \\le 1$ with $\\Ehat'$ as in Eq.~(\\ref{unit-base-map-cum})\nfor $E = E_0$ and as in Eq.~(\\ref{unit-base-map1})\nfor $E = E_1$.  For linear-linear unscaled unit-base interpolation\nto incident energy $E$ with $E_0 < E < E_1$, interpolate the\nminimal and maximal outgoing energies as in Eq.~(\\ref{EoutRange}),\ninterpolate $\\widehat r$ using\n$$\n    \\widehat r(E', E ) = ( 1 - q )\\, \\widehat r(E', E_0 ) + q\\, \\widehat r(E', E_1 ),\n$$\nand invert the unit-base map using Eq.~(\\ref{range-inv})\nand \n$$\n  r(E', E) = \\widehat r(\\Ehat', E)\n$$\nfor $\\Emin' \\le E' \\le \\Emax'$.\n\nWhen the energy probability density $\\pi_E( E' \\mid E )$ in Eq.~(\\ref{Kalbach-prob})\nis interpolated using the method of cumulative points, the interpolated values of\n$r(E', E)$ in Eq.~(\\ref{Kalbach-eta}) are obtained using the method of\nunscaled cumulative points defined as follows.  Because the data for\n $r( E' , E )$ and  $\\pi_E( E' \\mid E )$ are given at the same energy points\n $E$ and~$E'$, it is natural to use for $r( E' , E_0 )$ and $r( E' , E_1 )$ the\n intervals  $\\calB_{ \\ell}(E_k )$, k = 0,~1, constructed for $\\pi_E( E' \\mid E_k )$\nin Eq.~(\\ref{def-B-ell}).  The \\gettransfer\\ code uses unscaled unit-base interpolation \nbetween $r( E', E_0)$ on $\\calB_{\\ell}(E_0 )$ and  $r( E', E_0)$ on $\\calB_{ \\ell}(E_1 )$\nin sequence for $\\ell = 1,$ 2, $\\ldots\\,$, $L$. This method is applicable\neven when a set $\\calB_{ \\ell}(E_k )$ reduces to a point as discussed in\nSection~\\ref{Sec:cum-points-trivial}, as here is no problem of possible division by zero.\n\n\n", "meta": {"hexsha": "adf3d1e208a9194100a66aaab8ea693cec6f537b", "size": 34259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Merced/Doc/interpolate.tex", "max_stars_repo_name": "brown170/fudge", "max_stars_repo_head_hexsha": "4f818b0e0b0de52bc127dd77285b20ce3568c97a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-08-29T23:46:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T10:16:25.000Z", "max_issues_repo_path": "Merced/Doc/interpolate.tex", "max_issues_repo_name": "brown170/fudge", "max_issues_repo_head_hexsha": "4f818b0e0b0de52bc127dd77285b20ce3568c97a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-04T16:14:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-01T01:54:34.000Z", "max_forks_repo_path": "Merced/Doc/interpolate.tex", "max_forks_repo_name": "brown170/fudge", "max_forks_repo_head_hexsha": "4f818b0e0b0de52bc127dd77285b20ce3568c97a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-03-03T22:41:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T22:54:43.000Z", "avg_line_length": 39.8360465116, "max_line_length": 94, "alphanum_fraction": 0.6746840246, "num_tokens": 11922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.638951668264664}}
{"text": "\\documentclass{amsart}\n\\usepackage{style/preamble}\n\\usepackage{parskip}\n\\begin{document}\n  \\section{Complex analysis theorems}\n  Let $U$ be an open subset of $\\bbc$.\n  Let $f: U \\rightarrow \\bbc$ be a continuous function.\n\n  $f$ is called (once) \\emph{complex differentiable} at $a \\in U$ if the limit\n  \\begin{align*}\n    f'(z) := \\lim_{h \\rightarrow 0} \\dfrac{f(z + h) - f(z)}{h}\n  \\end{align*}\n  exists for all $z$ in some neighborhood of $a$.\n\n  \\begin{theorem}[Taylor series]\n    If $f$ is once differentiable at $a$, then $f$ is infinitely differentiable at $a$ and $f$ has a Taylor series converging to it in a neighborhood of $a$.\n    \\begin{align*}\n      f(z) = f(a) + f'(a){(z-a)} +  f''(a)\\dfrac{(z-a)^2}{2!} + \\dots +  f^{(n)}(a)\\dfrac{(z-a)^n}{n!} + \\dots\n    \\end{align*}\n  \\end{theorem}\n\n  \\begin{theorem}[Open mapping theorem]\n    If $f$ is complex differentiable then for any open set $V \\subseteq U$, the set $f(V)$ is an open subset of $\\bbc$.\n  \\end{theorem}\n\n  \\begin{theorem}[Isolated zeroes]\n    If $f$ is complex differentiable then the set of zeroes of $f$ are isolated i.e. if $f(a) = 0$ for some $a \\in U$ then there exists a neighborhood $V$ of $a$ such that $a$ is the only zero of $f$ in $V$.\n  \\end{theorem}\n\n\\vspace{1cm}\n\n  A complex differentiable function $g: \\bbc \\rightarrow \\bbc$ is called an \\emph{entire} function.\n  \\begin{theorem}[Liouville's theorem]\n    Let $g$ be an entire function.\n    If there exists a real number $M$ such that $|g(z)| < M$ for all $z \\in \\bbc$ then $g(z)$ is a constant function.\n  \\end{theorem}\n\n  \\begin{theorem}[Little Picard's theorem]\n    Let $g$ be an entire function.\n    If $g$ is not a constant function then the image of $g$ is either the whole complex plane or the plane minus a single point.\n  \\end{theorem}\n\\end{document}\n", "meta": {"hexsha": "e71423eb74d08e0c89d8f652d8b21c9593029261", "size": 1801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComplexAnalysisTheorems.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": "ComplexAnalysisTheorems.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": "ComplexAnalysisTheorems.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": 41.8837209302, "max_line_length": 207, "alphanum_fraction": 0.6563020544, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397349, "lm_q2_score": 0.8080672135527631, "lm_q1q2_score": 0.638801639812054}}
{"text": "\\chapter{Governing Equations}\n\\label{cha:governing:equations}\n\nWe present here a brief derivation of the equations for both quasi-static\nand dynamic computations. Since the general equations are the same\n(except for the absence of inertial terms in the quasi-static case),\nwe first derive these equations. We then present solution methods\nfor each specific case. In all of our derivations, we use the notation\ndescribed in Table \\vref{tab:notation} for both index\nand vector notation. When using index notation, we use the common\nconvention that repeated indices indicate summation over the range\nof the index.\n\n\\begin{table}[htbp]\n  \\caption{Mathematical notation}\n  \\label{tab:notation}\n  \\begin{tabular}{ccp{3in}}\n    \\multicolumn{2}{c}{{\\bf Symbol}} & {\\bf Description} \\\\\n    {\\bf Index notation} & {\\bf Vector Notation} & \\\\\n    \\hline \n    $a_{i}$ & \\raisebox{12pt}{}$\\overrightarrow{a}$ & Vector field a \\\\\n    $a_{ij}$ & $\\underline{a}$ & Second order tensor field a \\\\\n    $u_{i}$ & $\\overrightarrow{u}$ & Displacement vector field \\\\\n    $d_{i}$ & $\\vec{{d}}$ & Fault slip vector field \\\\\n    $f_{i}$ & $\\overrightarrow{f}$ & Body force vector field \\\\\n    $T_{i}$ & $\\overrightarrow{T}$ & Traction vector field \\\\\n    $\\sigma_{ij}$ & $\\underline{\\sigma}$ & Stress tensor field \\\\\n    $n_{i}$ & $\\overrightarrow{n}$ & Normal vector field \\\\\n    $\\rho$ & $\\rho$ & Mass density scalar field \\\\\n    \\hline \n  \\end{tabular}\n\\end{table}\n\n\n\\section{Derivation of Elasticity Equation}\n\n\\subsection{Index Notation}\n\nConsider volume $V$ bounded by surface $S$. Applying a Lagrangian\ndescription of the conservation of momentum gives\n\\begin{equation}\n\\label{eqn:momentum:index}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial u_{i}}{\\partial t}\\, dV=\\int_{V}f_{i}\\, dV+\\int_{S}T_{i}\\, dS.\n\\end{equation}\nThe traction vector field is related to the stress tensor through\n\\begin{equation}\nT_{i}=\\sigma_{ij}n_{j},\n\\end{equation}\nwhere $n_{j}$ is the vector normal to $S$. Substituting into equation\n\\vref{eqn:momentum:index} yields\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial u_{i}}{\\partial t}\\, dV=\\int_{V}f_{i}\\, dV+\\int_{S}\\sigma_{ij}n_{j}\\, dS.\n\\end{equation}\nApplying the divergence theorem,\n\\begin{equation}\n\\int_{V}a_{i,j}\\: dV=\\int_{S}a_{j}n_{j}\\: dS,\n\\end{equation}\nto the surface integral results in\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial u_{i}}{\\partial t}\\, dV=\\int_{V}f_{i}\\, dV+\\int_{V}\\sigma_{ij,j}\\, dV,\n\\end{equation}\nwhich we can rewrite as\n\\begin{equation}\n\\int_{V}\\left(\\rho\\frac{\\partial^{2}u_{i}}{\\partial t^{2}}-f_{i}-\\sigma_{ij,j}\\right)\\, dV=0.\n\\end{equation}\nBecause the volume $V$ is arbitrary, the integrand must be zero at\nevery location in the volume, so that we end up with\n\\begin{gather}\n\\rho\\frac{\\partial^{2}u_{i}}{\\partial t^{2}}-f_{i}-\\sigma_{ij,j}=0\\text{ in }V,\\\\\n\\sigma_{ij}n_{j}=T_{i}\\text{ on }S_{T}\\text{,}\\\\\nu_{i}=u_{i}^{o}\\text{ on }S_{u}\\text{, and}\\\\\nR_{ki}(u_{i}^{+}-u_{i}^{-})=d_{k}\\text{ on }S_{f}.\n\\end{gather}\nWe specify tractions, $T_{i}$, on surface $S_{f}$, displacements,\n$u_{i}^{o}$, on surface $S_{u}$, and slip, $d_{k}$, on fault surface\n$S_{f}$ (we will consider the case of fault constitutive models in\nSection \\vref{sec:fault}). The rotation matrix $R_{ki}$ transforms\nvectors from the global coordinate system to the fault coordinate\nsystem. Note that since both $T_{i}$ and $u_{i}$ are vector quantities,\nthere can be some spatial overlap of the surfaces $S_{T}$ and $S_{u}$;\nhowever, the same degree of freedom cannot simultaneously have both\ntypes of boundary conditions.\n\n\n\\subsection{Vector Notation}\n\nConsider volume $V$ bounded by surface $S$. Applying a Lagrangian\ndescription of the conservation of momentum gives\n\\begin{equation}\n\\label{eqn:momentum:vec}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial\\vec{u}}{\\partial t}\\, dV=\\int_{V}\\overrightarrow{f}\\, dV+\\int_{S}\\overrightarrow{T}\\, dS.\n\\end{equation}\nThe traction vector field is related to the stress tensor through\n\\begin{equation}\n\\overrightarrow{T}=\\underline{\\sigma}\\cdot\\overrightarrow{n},\n\\end{equation}\nwhere $\\overrightarrow{n}$ is the vector normal to $S$. Substituting\ninto equation \\vref{eqn:momentum:vec} yields\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial\\overrightarrow{u}}{\\partial t}\\, dV=\\int_{V}\\overrightarrow{f}\\, dV+\\int_{S}\\underline{\\sigma}\\cdot\\overrightarrow{n}\\, dS.\n\\end{equation}\nApplying the divergence theorem,\n\\begin{equation}\n\\int_{V}\\nabla\\cdot\\overrightarrow{a}\\: dV=\\int_{S}\\overrightarrow{a}\\cdot\\overrightarrow{n}\\: dS,\n\\end{equation}\nto the surface integral results in\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\int_{V}\\rho\\frac{\\partial\\overrightarrow{u}}{\\partial t}\\, dV=\\int_{V}\\overrightarrow{f}\\, dV+\\int_{V}\\nabla\\cdot\\underline{\\sigma}\\, dV,\n\\end{equation}\nwhich we can rewrite as\n\\begin{equation}\n\\int_{V}\\left(\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}-\\overrightarrow{f}-\\nabla\\cdot\\overrightarrow{\\sigma}\\right)\\, dV=\\vec{0}.\n\\end{equation}\nBecause the volume $V$ is arbitrary, the integrand must be the zero\nvector at every location in the volume, so that we end up with\n\\begin{gather}\n\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}-\\overrightarrow{f}-\\nabla\\cdot\\overrightarrow{\\sigma}=\\vec{0}\\text{ in }V,\\\\\n\\underline{\\sigma}\\cdot\\overrightarrow{n}=\\overrightarrow{T}\\text{ on }S_{T}\\text{,}\\\\\n\\overrightarrow{u}=\\overrightarrow{u^{o}}\\text{ on }S_{u},\\text{ and}\\\\\n\\underbar{R}\\cdot(\\vec{u^{+}}-\\vec{u^{-}})=\\vec{d}\\text{ on }S_{f}.\n\\end{gather}\nWe specify tractions, $\\vec{T}$, on surface $S_{f}$, displacements,\n$\\overrightarrow{u^{o}}$, on surface $S_{u}$, and slip, $\\vec{d}$,\non fault surface $S_{f}$ (we will consider the case of fault constitutive\nmodels in Section \\vref{sec:fault}). The rotation matrix $\\underline{R}$\ntransforms vectors from the global coordinate system to the fault\ncoordinate system. Note that since both $\\overrightarrow{T}$ and\n$\\overrightarrow{u}$ are vector quantities, there can be some spatial\noverlap of the surfaces $S_{T}$ and $S_{u}$; however, the same degree\nof freedom cannot simultaneously have both types of boundary conditions.\n\n\\section{Finite-Element Formulation of Elasticity Equation}\n\nWe formulate a set of algebraic equations using Galerkin's method.\nWe consider (1) a trial solution, $\\vec{u}$, that is a piecewise\ndifferentiable vector field and satisfies the Dirichlet boundary conditions\non $S_{u}$, and (2) a weighting function, $\\vec{\\phi}$, that is\na piecewise differentiable vector field and is zero on $S_{u}$.\n\n\\subsection{Index Notation}\n\nWe start with the wave equation (strong form),\n\\begin{gather}\n\\sigma_{ij,j}+f_{i}=\\rho\\ddot{u_{i}}\\text{ in }V,\\\\\n\\sigma_{ij}n_{j}=T_{i}\\text{ on }S_{T},\\\\\nu_{i}=u_{i}^{o}\\text{ on }S_{u},\\\\\nR_{ki}(u_{i}^{+}-u_{i}^{-})=d_{k}\\text{ on }S_{f},\\text{ and}\\\\\n\\sigma_{ij}=\\sigma_{ji}\\text{ (symmetric).}\n\\end{gather}\nWe construct the weak form by computing the dot product of the wave\nequation and weighting function and setting the integral over the\ndomain to zero:\n\\begin{gather}\n\\int_{V}\\left(\\sigma_{ij,j}+f_{i}-\\rho\\ddot{u}_{i}\\right)\\phi_{i}\\, dV=0\\text{, or }\\\\\n\\int_{V}\\sigma_{ij,j}\\phi_{i}\\: dV+\\int_{V}f_{i}\\phi_{i}\\: dV-\\int_{V}\\rho\\ddot{u}_{i}\\phi_{i}\\: dV=0.\n\\end{gather}\n Consider the divergence theorem applied to the dot product of the\nstress tensor and the weighting function, $\\sigma_{ij}\\phi_{i}$,\n\\begin{equation}\n\\int_{V}(\\sigma_{ij}\\phi_{i})_{,j}\\, dV=\\int_{S}(\\sigma_{ij}\\phi_{i})n_{i}\\, dS.\n\\end{equation}\nExpanding the left-hand side yields\n\\begin{gather}\n\\int_{V}\\sigma_{ij,j}\\phi_{i}\\: dV+\\int_{V}\\sigma_{ij}\\phi_{i,j}\\: dV=\\int_{S}\\sigma_{ij}\\phi_{i}n_{i}\\: dS,\\text{ or}\\\\\n\\int_{V}\\sigma_{ij,j}\\phi_{i}\\: dV=-\\int_{V}\\sigma_{ij}\\phi_{i,j}\\, dV+\\int_{S}\\sigma_{ij}\\phi_{i}n_{i}\\, dS.\n\\end{gather}\nSubstituting into the weak form gives\n\\begin{equation}\n-\\int_{V}\\sigma_{ij}\\phi_{i,j}\\, dV+\\int_{S}\\sigma_{ij}\\phi_{i}n_{i}\\, dS+\\int_{V}f_{i}\\phi_{i}\\, dV-\\int_{V}\\rho\\ddot{u}_{i}\\phi_{i}\\, dV=0.\n\\end{equation}\nTurning our attention to the second term, we separate the integration\nover $S$ into integration over $S_{T}$ and $S_{u}$ (we will consider\ntractions over the fault surface, $S_{f}$, associated with the fault\nconstitutive model in Section \\vref{sec:fault}),\n\\begin{equation}\n-\\int_{V}\\sigma_{ij}\\phi_{i,j}\\, dV+\\int_{S_{T}}\\sigma_{ij}\\phi_{i}n_{i}\\, dS+\\int_{S_{u}}\\sigma_{ij}\\phi_{i}n_{i}\\, dS+\\int_{V}f_{i}\\phi_{i}\\, dV-\\int_{V}\\rho\\ddot{u}_{i}\\phi_{i}\\, dV=0,\n\\end{equation}\nand recognize that\n\\begin{gather}\n\\sigma_{ij}n_{i}=T_{i}\\text{ on }S_{T}\\text{ and}\\\\\n\\phi_{i}=0\\text{ on }S_{u},\n\\end{gather}\nso that the equation reduces to\n\\begin{equation}\n\\label{eq:elasticity:integral}\n-\\int_{V}\\sigma_{ij}\\phi_{i,j}\\: dV+\\int_{S_{T}}T_{i}\\phi_{i}\\, dS+\\int_{V}f_{i}\\phi_{i}\\, dV-\\int_{V}\\rho\\ddot{u}_{i}\\phi_{i}\\, dV=0.\n\\end{equation}\nWe express the trial solution and weighting function as linear combinations\nof basis functions,\n\\begin{gather}\nu_{i}=\\sum_{m}a_{i}^{m}N^{m},\\\\\n\\phi_{i}=\\sum_{n}c_{i}^{n}N^{n}.\n\\end{gather}\nNote that because the trial solution satisfies the Dirichlet boundary\ncondition, the number of basis functions for $u$ is generally greater\nthan the number of basis functions for $\\phi$, i.e., $m>n$. Substituting\nin the expressions for the trial solution and weighting function yields\n\\begin{gather}\n-\\int_{V}\\sigma_{ij}\\sum_{n}c_{i}^{n}N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}\\sum_{n}c_{i}^{n}N^{n}\\, dS+\\int_{V}f_{i}\\sum_{n}c_{i}^{n}N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\ddot{a}_{i}^{m}N^{m}\\sum_{n}c_{i}^{n}N^{n}\\ dV=0,\\text{ or}\\\\\n\\sum_{n}c_{i}^{n}(-\\int_{V}\\sigma_{ij}N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}N^{n}\\, dS+\\int_{V}f_{i}N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\ddot{a}_{i}^{m}N^{m}N^{n}\\ dV)=0.\n\\end{gather}\n Because the weighting function is arbitrary, this equation must hold\nfor all $c_{i}^{n}$, so that the quantity in parenthesis is zero\nfor each $c_{i}^{n}$\n\\begin{equation}\n\\label{eq:elasticity:integral:discretized}\n-\\int_{V}\\sigma_{ij}N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}N^{n}\\, dS+\\int_{V}f_{i}N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\ddot{a}_{i}^{m}N^{m}N^{n}\\ dV=\\vec{0}.\n\\end{equation}\nWe want to solve this equation for the unknown coefficients $a_{i}^{m}$\nsubject to\n\\begin{gather}\nu_{i}=u_{i}^{o}\\text{ on }S_{u},\\text{ and}\\\\\nR_{ki}(u_{i}^{+}-u_{i}^{-})=d_{k}\\text{ on }S_{f},\n\\end{gather}\n\n\n\\subsection{Vector Notation}\n\nWe start with the wave equation (strong form),\n\\begin{gather}\n\\nabla\\cdot\\underline{\\sigma}+\\overrightarrow{f}=\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\text{ in }V,\\\\\n\\underline{\\sigma}\\cdot\\overrightarrow{n}=\\overrightarrow{T}\\text{ on }S_{T},\\\\\n\\overrightarrow{u}=\\overrightarrow{u^{o}}\\text{ on }S_{u},\\\\\n\\underbar{R}\\cdot(\\overrightarrow{u^{+}}-\\overrightarrow{u^{-}})=\\vec{d}\\text{ on }S_{f}\\\\\n\\underline{\\sigma}=\\underline{\\sigma}^{T}\\text{ (symmetric).}\n\\end{gather}\nWe construct the weak form by multiplying the wave equation by a weighting\nfunction and setting the integral over the domain to zero. The weighting\nfunction is a piecewise differential vector field, $\\overrightarrow{\\phi}$,\nwhere $\\overrightarrow{\\phi}=0$ on $S_{u}.$ Hence our weak form\nis\n\\begin{gather}\n\\int_{V}\\left(\\nabla\\cdot\\underline{\\sigma}+\\overrightarrow{f}-\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\right)\\cdot\\overrightarrow{\\phi}\\, dV=0\\text{, or }\\\\\n\\int_{V}(\\nabla\\cdot\\underline{\\sigma})\\cdot\\overrightarrow{\\phi}\\: dV+\\int_{V}\\overrightarrow{f}\\cdot\\overrightarrow{\\phi}\\: dV-\\int_{V}\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\: dV=0.\n\\end{gather}\n Consider the divergence theorem applied to the dot product of the\nstress tensor and the trial function, $\\underline{\\sigma}\\cdot\\overrightarrow{\\phi}$,\n\\begin{equation}\n\\int_{V}\\nabla\\cdot(\\underline{\\sigma}\\cdot\\overrightarrow{\\phi})\\, dV=\\int_{S}(\\underline{\\sigma}\\cdot\\overrightarrow{\\phi})\\cdot\\overrightarrow{n}\\, dS.\n\\end{equation}\nExpanding the left-hand side yields\n\\begin{equation}\n\\int_{V}(\\nabla\\cdot\\underline{\\sigma})\\cdot\\overrightarrow{\\phi}\\: dV+\\int_{V}\\underline{\\sigma}:\\nabla\\overrightarrow{\\phi}\\: dV=\\int_{S}(\\underline{\\sigma}\\cdot\\overrightarrow{\\phi})\\cdot\\overrightarrow{n}\\: dS,\\text{ or}\n\\end{equation}\n\\begin{equation}\n\\int_{V}(\\nabla\\cdot\\underline{\\sigma})\\cdot\\overrightarrow{\\phi}\\: dV=-\\int_{V}\\underline{\\sigma}:\\nabla\\overrightarrow{\\phi}\\, dV+\\int_{S}\\underline{\\sigma}\\cdot\\overrightarrow{n}\\cdot\\overrightarrow{\\phi}\\, dS.\n\\end{equation}\nSubstituting into the weak form gives\n\\begin{equation}\n-\\int_{V}\\underline{\\sigma}:\\nabla\\overrightarrow{\\phi}\\, dV+\\int_{S}\\underline{\\sigma}\\cdot\\overrightarrow{n}\\cdot\\overrightarrow{\\phi}\\, dS+\\int_{V}\\overrightarrow{f}\\cdot\\overrightarrow{\\phi}\\, dV-\\int_{V}\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\, dV=0.\n\\end{equation}\nWe separate the integration over $S$ into integration over $S_{T}$\nand $S_{u}$,\n\\begin{multline}\n-\\int_{V}\\underline{\\sigma}:\\nabla\\overrightarrow{\\phi}\\, dV+\\int_{S_{T}}\\underline{\\sigma}\\cdot\\overrightarrow{n}\\cdot\\overrightarrow{\\phi}\\, dS+\\int_{S_{u}}\\underline{\\sigma}\\cdot\\overrightarrow{n}\\cdot\\overrightarrow{\\phi}\\, dS+\\int_{V}\\overrightarrow{f}\\cdot\\overrightarrow{\\phi}\\, dV-\\int_{V}\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\, dV=0,\n\\end{multline}\nand recognize that\n\\begin{gather}\n\\underline{\\sigma}\\cdot\\overrightarrow{n}=\\overrightarrow{T}\\text{ on }S_{T}\\text{ and}\\\\\n\\overrightarrow{\\phi}=0\\text{ on }S_{u},\n\\end{gather}\nso that the equation reduces to\n\\begin{equation}\n-\\int_{V}\\underline{\\sigma}:\\nabla\\overrightarrow{\\phi}\\: dV+\\int_{S_{T}}\\overrightarrow{T}\\cdot\\overrightarrow{\\phi}\\, dS+\\int_{V}\\overrightarrow{f}\\cdot\\overrightarrow{\\phi}\\, dV-\\int_{V}\\rho\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\, dV=0.\n\\end{equation}\nWe express the trial solution and weighting function as linear combinations\nof basis functions,\n\\begin{gather}\n\\vec{u}=\\sum_{m}\\overrightarrow{a^{m}}N^{m},\\\\\n\\vec{\\phi}=\\sum_{n}\\overrightarrow{c^{n}}N^{n}.\n\\end{gather}\nNote that because the weighting function is zero on $S_{u}$, the\nnumber of basis functions for $\\vec{u}$ is generally greater than\nthe number of basis functions for $\\vec{\\phi}$, i.e., $m>n$. Substituting\nin the expressions for the trial solution and weighting function yields\n\\begin{multline}\n-\\int_{V}\\underline{\\sigma}:\\sum_{n}\\overrightarrow{c^{n}}\\nabla N_{,}^{n}\\, dV+\\int_{S_{T}}\\vec{T}\\cdot\\sum_{n}\\overrightarrow{c^{n}}N^{n}\\, dS+\\int_{V}\\vec{f}\\cdot\\sum_{n}\\overrightarrow{c^{n}}N^{n}\\, dV\\\\\n-\\int_{V}\\rho\\sum_{m}\\frac{\\partial^{2}\\overrightarrow{a^{m}}}{\\partial t^{2}}N^{m}\\cdot\\sum_{n}\\overrightarrow{c^{n}}N^{n}\\ dV=0.\n\\end{multline}\n Because the weighting function is arbitrary, this equation must hold\nfor all $\\overrightarrow{c^{n}}$, so that\n\\begin{equation}\n-\\int_{V}\\underline{\\sigma}:\\nabla N^{n}\\, dV+\\int_{S_{T}}\\vec{T}N^{n}\\, dS+\\int_{V}\\vec{f}N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\frac{\\partial^{2}\\overrightarrow{a^{m}}}{\\partial t^{2}}N^{m}N^{n}\\, dV=\\vec{0}.\n\\end{equation}\nWe want to solve this equation for the unknown coefficients $\\overrightarrow{a^{m}}$\nsubject to\n\\begin{gather}\n\\vec{u}=u^{o}\\overrightarrow{}\\text{ on }S_{u},\\text{ and}\\\\\n\\underline{R}(\\overrightarrow{u^{+}}-\\overrightarrow{u^{-}})=\\vec{d}\\text{ on }S_{f},\n\\end{gather}\n\n\\section{Solution Method for Quasi-Static Problems}\n\nFor brevity we outline the solution method for quasi-static problems\nusing only index notation. In quasi-static problems we neglect the\ninertial terms, so equation \\eqref{eq:elasticity:integral:discretized}\nreduces to\n\\begin{equation}\n-\\int_{V}\\sigma_{ij}N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}N^{n}\\, dS+\\int_{V}f_{i}N^{n}\\, dV=\\vec{0}.\n\\end{equation}\nAs a result, time-dependence only enters through the constitutive\nrelationships and the loading conditions. We consider the deformation\nat time $t+\\Delta t$,\n\\begin{equation}\n\\label{eq:elasticity:integral:quasistatic}\n-\\int_{V}\\sigma_{ij}(t+\\Delta t)N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}(t+\\Delta t)N^{n}\\, dS+\\int_{V}f_{i}(t+\\Delta t)N^{n}\\, dV=\\vec{0}.\n\\end{equation}\nWe solve this equation through formulation of a linear algebraic system\nof equations ($Au=b$), involving the residual ($r=b-Au$) and Jacobian\n($A$). The residual is simply\n\\begin{equation}\nr_{i}^{n}=-\\int_{V}\\sigma_{ij}(t+\\Delta t)N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}(t+\\Delta t)N^{n}\\, dS+\\int_{V}f_{i}(t+\\Delta t)N^{n}\\, dV.\n\\end{equation}\nWe employ numerical quadrature in the finite-element discretization\nand replace the integrals with sums over the cells and quadrature\npoints,\n\\begin{multline}\nr_{i}^{n}=-\\sum_{\\text{vol cells}}\\sum_{\\text{quad pts}}\\sigma_{ij}(x_{q},t+\\Delta t)N_{,j}^{n}(x_{q})\\: w_{q}|J_{cell}(x_{q})|+\\sum_{\\text{vol cells}}\\sum_{\\text{quad pt}s}f_{i}(x_{q},t+\\Delta t)N^{n}(x_{q})\\, w_{q}|J_{cell}(x_{q})|\\\\\n+\\sum_{\\text{tract cells}}\\sum_{\\text{quad pts}}T_{i}(x_{q},t+\\Delta t)N^{n}(x_{q})\\, w_{q}|J_{cell}(x_{q})|,\n\\end{multline}\nwhere $r_{i}^{n}$ is an $nd$ vector ($d$ is the dimension of the\nvector space) and $i$ is a vector space component, $x_{q}$ are the\ncoordinates of the quadrature points, $w_{q}$ are the weights of\nthe quadrature points, and $|J_{cell}(x_{q})|$ is the determinant\nof the Jacobian matrix evaluated at the quadrature points associated\nwith mapping the reference cell to the actual cell. The quadrature\nscheme for the integral over the tractions is one dimension lower\nthan the one used in integrating the terms for the volume cells.\n\nIn order to find the Jacobian of the system, we let\n\\begin{equation}\n\\sigma_{ij}(t+\\Delta t)=\\sigma_{ij}(t)+d\\sigma_{ij}(t).\n\\end{equation}\nIsolating the term associated with the increment in stresses yields\n\n\\begin{equation}\n\\int_{V}d\\sigma_{ij}(t)N_{j}^{n}\\ dV=-\\int_{V}\\sigma_{ij}(t)N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}(t+\\Delta t)N^{n}\\, dS+\\int_{V}f_{i}(t+\\Delta t)N^{n}\\, dV\n\\end{equation}\nWe associate the term on the left-hand-side with the action of the\nsystem Jacobian on the increment of the displacement field. We approximate\nthe increment in stresses using linear elasticity and infinitesimal\nstrains,\n\n\\begin{gather}\nd\\sigma_{ij}(t)=C_{ijkl}(t)d\\varepsilon_{kl}(t)\\\\\nd\\sigma_{ij}(t)=\\frac{1}{2}C_{ijkl}(t)(du_{k.l}(t)+du_{l,k}(t))\\\\\nd\\sigma_{ij}(t)=\\frac{1}{2}C_{ijkl}(t)(\\sum_{m}da_{k,l}^{m}(t)N^{m}+\\sum_{m}da_{l,k}^{m}(t)N^{m})\n\\end{gather}\nNow, $d\\sigma_{ij}\\phi_{i,j}$ is a scalar, so it is symmetric,\n\\begin{equation}\nd\\sigma_{ij}\\phi_{i,j}=d\\sigma_{ji}\\phi_{j,i},\n\\end{equation}\nand we know that $d\\sigma_{ij}$ is symmetric, so\n\\begin{equation}\nd\\sigma_{ij}\\phi_{i,j}=d\\sigma_{ij}\\phi_{j,i},\n\\end{equation}\nwhich means\n\\begin{equation}\n\\phi_{i,j}=\\phi_{j,i},\n\\end{equation}\nwhich we can write as\n\\begin{equation}\n\\phi_{i,j}=\\frac{1}{2}(\\phi_{i,j}+\\phi_{j,i}).\n\\end{equation}\nIn terms of the basis functions, we have\n\n\\begin{equation}\n\\sum_{n}c_{i}^{n}N_{,j}^{n}=\\frac{1}{2}(\\sum_{n}c_{i}^{n}N_{,j}^{n}+\\sum_{n}c_{j}^{n}N_{,i}^{n}).\n\\end{equation}\nCombining these expressions for the increment in stresses and making\nuse of the symmetry of the weighting functions, we find the system\nJacobian is\n\n\\begin{equation}\nA_{ij}^{nm}=\\int_{V}\\frac{1}{4}C_{ijkl}(N_{,l}^{m}+N_{,k}^{m})(N_{,j}^{n}+N_{,i}^{n})\\ dV.\n\\end{equation}\nWe employ numerical quadrature in the finite-element discretization\nand replace the integral with a sum over the cells and quadrature\npoints,\n\\begin{equation}\nA_{ij}^{nm}=\\sum_{\\text{vol cells}}\\sum_{\\text{quad pts}}\\frac{1}{4}C_{ijkl}(N_{,l}^{m}(x_{q})+N_{,k}^{m}(x_{q}))(N_{,j}^{n}(x_{q})+N_{,i}^{n}(x_{q}))w_{q}|J_{cell}(x_{q}).\n\\end{equation}\n\n\\section{Solution Method for Dynamic Problems}\n\nFor brevity we outline the solution method for dynamic problems using\nonly index notation. Time-dependence enters through the constitutive\nrelationships, loading conditions, and the inertial terms. We consider\nthe deformation at time $t$,\n\\begin{equation}\n\\label{eq:elasticity:integral:dynamic:t}\n-\\int_{V}\\sigma_{ij}(t)N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}(t)N^{n}\\, dS+\\int_{V}f_{i}(t)N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\ddot{a}_{i}^{m}(t)N^{m}N^{n}\\ dV=\\vec{0}.\n\\end{equation}\nWe solve this equation through formulation of a linear algebraic system\nof equations ($Au=b$), involving the residual ($r=b-Au$) and Jacobian\n($A$). The residual is simply\n\\begin{equation}\nr_{i}^{n}=-\\int_{V}\\sigma_{ij}(t)N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}(t)N^{n}\\, dS+\\int_{V}f_{i}(t)N^{n}\\, dV-\\int_{V}\\rho\\sum_{m}\\ddot{a}_{i}^{m}(t)N^{m}N^{n}\\ dV.\n\\end{equation}\nWe employ numerical quadrature in the finite-element discretization\nand replace the integrals with sums over the cells and quadrature\npoints,\n\\begin{multline}\nr_{i}^{n}=-\\sum_{\\text{vol cells}}\\sum_{\\text{quad pts}}\\sigma_{ij}(x_{q},t)N^{n}(x_{q})\\: w_{q}|J_{cell}(x_{q})|+\\sum_{\\text{vol cells}}\\sum_{\\text{quad pt}s}f_{i}(x_{q},t)N^{n}(x_{q})\\, w_{q}|J_{cell}(x_{q})|\\\\\n+\\sum_{\\text{tract cells}}\\sum_{\\text{quad pts}}T_{i}(x_{q},t)N^{n}(x_{q})\\, w_{q}|J_{cell}(x_{q})|-\\sum_{\\text{vol cells}}\\sum_{\\text{quad pts}}\\rho\\sum_{m}\\ddot{a}_{i}^{m}(t)N^{m}N^{n}\\ w_{q|J_{cell}(x_{q})},\n\\end{multline}\nwhere $x_{q}$ are the coordinates of the quadrature points, $w_{q}$\nare the weights of the quadrature points, and $|J_{cell}(x_{q})|$\nis the determinant of the Jacobian matrix evaluated at the quadrature\npoints associated with mapping the reference cell to the actual cell.\nThe quadrature scheme for the integral over the tractions is one dimension\nlower than the one used in integrating the terms for the volume cells. \n\nWe find the system Jacobian matrix by making use of the temporal discretization\nand isolating the term for the increment in the displacement field\nat time $t$. Using the central difference method to approximate the\nacceleration (and velocity),\n\\begin{gather}\n\\ddot{u}_{i}(t)=\\frac{1}{\\Delta t^{2}}\\left(u_{i}(t+\\Delta t)-2u_{i}(t)+u_{i}(t-\\Delta t)\\right)\\\\\n\\dot{u}_{i}(t)=\\frac{1}{2\\Delta t}\\left(u_{i}(t+\\Delta t)-u_{i}(t-\\Delta t)\\right)\n\\end{gather}\nand writing the displacement at time $t+\\Delta t$ in terms of the\ndisplacement at $t$ (for consistency with the displacement increment\nquasi-static formulation),\n\\begin{gather}\nu_{i}(t+\\Delta t)=u_{i}(t)+du_{i}(t),\\\\\n\\ddot{u}_{i}(t)=\\frac{1}{\\Delta t^{2}}\\left(du_{i}(t)-u_{i}(t)+u_{i}(t-\\Delta t)\\right),\\\\\n\\dot{u}_{i}(t)=\\frac{1}{2\\Delta t}\\left(du_{i}(t)+u_{i}(t)-u_{i}(t-\\Delta t)\\right).\n\\end{gather}\nSubstituting into equation \\eqref{eq:elasticity:integral:dynamic:t}\nyields\n\\begin{multline}\n\\frac{1}{\\Delta t^{2}}\\int_{V}\\rho\\sum_{m}da_{i}^{m}(t)N^{m}N^{n}\\ dV=-\\int_{V}\\sigma_{ij}N_{,j}^{n}\\: dV+\\int_{S_{T}}T_{i}N^{n}\\, dS+\\int_{V}f_{i}N^{n}\\, dV\\\\\n-\\frac{1}{\\Delta t^{2}}\\int_{V}\\rho\\sum_{m}(a_{i}^{m}(t)-a_{i}^{m}(t-\\Delta t))N^{m}N^{n}\\ dV.\n\\end{multline}\nThus, the Jacobian for the system is\n\\begin{equation}\nA_{ij}^{nm}=\\delta_{ij}\\frac{1}{\\Delta t^{2}}\\int_{V}\\rho N^{m}N^{n}\\ dV,\n\\end{equation}\nand using numerical quadrature in the finite-element discretization\nto replace the integrals with sums over the cells and quadrature points,\n\n\\begin{equation}\nA_{ij}^{nm}=\\delta_{ij}\\frac{1}{\\Delta t^{2}}\\sum_{\\text{vol cells}}\\sum_{\\text{quad pts}}\\rho(x_{q})N^{m}(x_{q})N^{n}(x_{q}),\n\\end{equation}\nwhere $A_{ij}^{mn}$ is a $nd$ by $md$ matrix ($d$ is the dimension\nof the vector space), $m$ and $n$ refer to the basis functions and\n$i$ and $j$ are vector space components. We consider the contributions\nassociated with the fault in section \\vref{sec:fault} and with absorbing\nboundaries is section \\vref{sec:absorbing:boundaries}.\n\n\n\\section{Small (Finite) Strain Formulation}\n\\label{sec:small:strain:formulation}\n\nIn some crustal deformation problems sufficient deformation may occur\nthat the assumptions associated with infinitesimal strains no longer\nhold. This is often the case for problems when one wants to include\nthe effects of gravitational body forces on vertical deformation.\nIn such cases we want to account for both rigid body motion and small\nstrains. We use a total Lagrangian formulation (quantities are associated\nwith the undeformed configuration) based on the one presented by Bathe\n\\cite{Bathe:1995}.\n\nStarting from the governing equation, written for the deformed configuration\n(denoted by the subscript $t$), we have\n\\begin{equation}\n\\label{eq:governing:equation:deformed}\n\\int(\\nabla_{t}\\cdot\\underline{\\sigma})\\cdot\\vec{\\phi}\\: dV_{t}+\\int_{Vt}\\overrightarrow{f_{t}}\\cdot\\overrightarrow{\\phi}\\, dV_{t}-\\int_{Vt}\\rho_{t}\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\, dV_{t}=0.\n\\end{equation}\nFor the total Lagrangian formulation we want to transform these integrals\nover the deformed configuration to integrals over the undeformed configuration.\nWe require that the deformed and undeformed configurations use the\nsame coordinate system (origin and orientation). Conservation of mass\nrequires that $\\rho\\, dV_{t}=\\rho_{0}\\, dV_{0}$. We define the body\nforce as a force per unit volume that does not depend on the configuration,\nwhich leads to $\\vec{f}_{t}\\, dV_{t}=\\vec{f}_{0}\\, dV_{0}$.\n\nThe Green-Lagrange strain provides a measure of the strain relative\nto the original, undeformed configuration.\n\\begin{gather}\n\\underline{\\epsilon}=\\frac{1}{2}(\\nabla u_{i,j}+(\\nabla u)^{T}+u_{k,i}u_{k,j}),\\text{ or}\\\\\n\\underline{\\epsilon}=\\underline{X}_{0}^{T}\\underline{\\, X}_{0}-\\underline{I},\\text{ where}\\\\\n\\underline{X_{0}}=\\frac{\\partial}{\\partial x_{j}}(\\vec{x}(0)+\\vec{u}(t)),\n\\end{gather}\nand $\\underline{X}$ is the deformation gradient tensor. The second\nPiola-Kirchhoff stress tensor, $\\underline{S}$, is the work conjugate\nof the Green-Lagrange strain tensor. As a result, they are related\nthrough the elasticity constants,\n\n\\begin{equation}\n\\underline{S}=\\underline{C\\,}\\underline{\\varepsilon},\n\\end{equation}\nin the same manner as the Cauchy stress is related to the infinitesimal\nstrain. The Cauchy stress is related to the second Piola-Kirchoff\nstress through the deformation gradient tensor,\n\\begin{equation}\n\\underline{\\sigma}=\\frac{1}{|\\underline{X}_{0}|}\\underline{\\, X}_{0}\\,\\underline{S\\,}\\underline{X}_{0}^{T},\n\\end{equation}\n where $\\mathit{det}(\\underline{X}_{0})=|\\underline{X}_{0}|$. Additionally,\nthe first Piola-Kirhoff stress is define to be \n\\begin{equation}\n\\underline{P}=\\underline{S\\,}\\underline{X}_{0}^{T}.\n\\end{equation}\n\n\nApplying the divergence theorem, making use of the fact that $dV_{t}=|\\underline{X}_{0}|\\, dV_{0}$,\nand recognizing that the gradient in the deformed configuration is\nrelated to the gradient in the undeformed configuration through the\ndeformation gradient tensor, we can show that\n\\begin{equation}\n\\int_{V_{t}}\\nabla_{t}\\cdot\\underline{\\sigma}\\cdot\\vec{\\phi}\\: dV_{t}=-\\int_{V_{0}}\\underline{P}:\\nabla\\overrightarrow{\\phi}\\, dV_{0}+\\int_{S_{0}}\\overrightarrow{T_{0}}\\cdot\\overrightarrow{\\phi}\\, dS_{0},\n\\end{equation}\nwhere we assume the the tractions on the boundary do not depend on\nthe configuration. That is, the normal and share traction components\nare defined in terms of the undeformed configuration. Incorporating\nthe other relationships between the underformed and deformed configurations\nallows us to rewrite Equation \\vref{eq:governing:equation:deformed}\nin the undeformed configuration,\n\\begin{equation}\n-\\int_{V_{0}}\\underline{P}:\\nabla\\overrightarrow{\\phi}\\, dV_{0}+\\int_{S_{0}}\\overrightarrow{T_{0}}\\cdot\\overrightarrow{\\phi}\\, dS_{0}+\\int_{V_{0}}\\overrightarrow{f_{0}}\\cdot\\overrightarrow{\\phi}\\, dV_{0}-\\int_{V_{0}}\\rho_{0}\\frac{\\partial^{2}\\overrightarrow{u}}{\\partial t^{2}}\\cdot\\overrightarrow{\\phi}\\, dV_{0}=0.\n\\end{equation}\n\n\n\\subsection{Quasi-static Problems}\n\nThe system Jacobian for quasi-static problems includes terms associated\nwith elasticity. For the small strain formulation, we write the elasticity\nterm at time $t+\\Delta t$ and consider the first terms of the Taylor\nseries expansion,\n\\begin{equation}\n\\int_{v}S_{ij}(t+\\Delta t)\\delta\\varepsilon_{ij}(t+\\Delta t)\\: dV=\\int_{V}(S_{ij}(t)\\delta\\varepsilon_{ij}(t)+dS_{ij}(t)\\delta\\varepsilon_{ij}(t)+S_{ij}(t)d\\delta\\varepsilon_{ij}(t))\\: dV.\n\\end{equation}\nWe approximate the increment in the stress tensor using the elastic\nconstants,\n\\begin{equation}\ndS_{ij}=C_{ijkl}d\\varepsilon_{kl},\n\\end{equation}\nand the increment in the ``virtual'' strain via\n\\begin{equation}\nd\\delta\\varepsilon_{ij}=\\frac{1}{2}(du_{k,i}\\delta u_{k,j}+du_{k,j}\\delta u_{k,i}).\n\\end{equation}\nWe associate the system Jacobian with the terms involving the increment\nin displacements. After substituting in the expressions for the increment\nin the stresses and the increment in the ``virtual'' strains, we\nhave\n\\begin{equation}\nA_{ij}^{nm}=\\int_{V}\\frac{1}{4}C_{ijkl}(N_{,k}^{m}+(\\sum_{r}a_{p}^{r}N_{,l}^{r})N_{,k}^{m})(N_{,i}^{n}+(\\sum_{r}a_{p}^{r}N_{,j}^{r})N_{,i}^{n})+\\frac{1}{2}S_{kl}N_{,l}^{m}N_{,l}^{n}\\delta_{ij}\\: dV.\n\\end{equation}\nThe small strain formulation produces additional terms associated\nwith the elastic constants and a new term associated with the stress\ntensor.\n\n\n\\subsection{Dynamic Problems}\n\nThe system Jacobian matrix in dynamic problems does not include any\nterms associated with elasticity, so the system Jacobian matrix in\nthe small strain formulation matches the one used in the infinitesimal\nstrain formulation.\n", "meta": {"hexsha": "c07e1a2eef5b7b33fa68e3cbfa99047eda1dcfe2", "size": 29173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/userguide/governingeqns/governingeqns.tex", "max_stars_repo_name": "joegeisz/pylith", "max_stars_repo_head_hexsha": "f74060b7b19d7e90abf8597bbe9250c96593c0ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-20T17:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-20T17:18:28.000Z", "max_issues_repo_path": "doc/userguide/governingeqns/governingeqns.tex", "max_issues_repo_name": "joegeisz/pylith", "max_issues_repo_head_hexsha": "f74060b7b19d7e90abf8597bbe9250c96593c0ad", "max_issues_repo_licenses": ["MIT"], "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/userguide/governingeqns/governingeqns.tex", "max_forks_repo_name": "joegeisz/pylith", "max_forks_repo_head_hexsha": "f74060b7b19d7e90abf8597bbe9250c96593c0ad", "max_forks_repo_licenses": ["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.0017825312, "max_line_length": 388, "alphanum_fraction": 0.7055153738, "num_tokens": 10156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6388016338303001}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[margin=0.5in]{geometry}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\setlength{\\parindent}{0em}\n\n\\title{\\textbf{COMP90056 Assignment A}}\n\\author{Tingsheng (Tinson) Lai (731319)}\n\\date{\\today}\n\n\\begin{document}\n    \\maketitle\n    \\section{Part 1}\n    Let $S$ denotes the union, i.e. $$S = S_1 \\cup S_2$$\n    From the inequality, we can claim that the inequality inherently holds for $\\forall x \\in S \\backslash S_2$ and $\\forall x \\in S \\backslash S_1$. So the only task is to prove that the inequality holds for the third circumstance where $$\\forall x \\in S_1 \\cap S_2$$\n    Use $\\hat{S}$ as the intersection $$\\hat{S} = S_1 \\cap S_2$$\n    First prove the $RHS$ where $\\forall x \\in \\hat{Z}$ $\\hat{c} \\left( x \\right) \\leq f_{x}$. As $x \\in S_1 \\wedge x \\in S_2$, we know that $\\hat{c}_1 \\left( x \\right) \\leq f_{1,x}$ and $\\hat{c}_2 \\left( x \\right) \\leq f_{2,x}$. So $$\\hat{c} \\left( x \\right) = \\hat{c}_1 \\left( x \\right) + \\hat{c}_2 \\left( x \\right) \\leq f_{1,x} + f_{2,x} = f_{x}$$\n    Even if the subtraction to shrink the size happens, the $RHS$ still holds as $\\forall i \\in \\mathbb{U}$, $f_{i}$ will not be changed throughout the whole process. For the $LHS$, using the same trick we can get $$f_{1,x} - \\frac{m_1 - \\tau_1}{k_1} + f_{2,x} - \\frac{m_2 - \\tau_2}{k_2} = f_x - \\frac{m - \\tau}{x}$$ So $$\\hat{c} \\left( x \\right) \\geq f_x - \\frac{m - r}{k} = LHS$$ Subtracting $a$ from each $x \\in S$ will decrease the value of $\\tau$ by at least $k \\cdot a$. Denoting $\\Delta \\hat{c}_x$ = -a as the change in the counter and $\\Delta \\tau$ as the change in $\\tau \\leq -a \\cdot k$. It is clear that $f_x$ and $m$ and $k$ are fixed, so $\\Delta LHS \\leq -a$. So the decrease in the $LHS$ are even greater than $\\hat{c} \\left( x \\right)$, so the inequality still holds.\n\\end{document}\n", "meta": {"hexsha": "e5a9e20646c5a3abfd1c1854d05a1abb33e490e3", "size": 1852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment/B/part1.tex", "max_stars_repo_name": "laitingsheng/2019S2-COMP90056", "max_stars_repo_head_hexsha": "adc65917942ce0057cd51602f700c8a7e09cfaea", "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": "Assignment/B/part1.tex", "max_issues_repo_name": "laitingsheng/2019S2-COMP90056", "max_issues_repo_head_hexsha": "adc65917942ce0057cd51602f700c8a7e09cfaea", "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": "Assignment/B/part1.tex", "max_forks_repo_name": "laitingsheng/2019S2-COMP90056", "max_forks_repo_head_hexsha": "adc65917942ce0057cd51602f700c8a7e09cfaea", "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": 84.1818181818, "max_line_length": 782, "alphanum_fraction": 0.6517278618, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8080672204860317, "lm_q1q2_score": 0.6388016293416686}}
{"text": "\\section*{Ex.34.5-6}\n\\subsection*{Hamiltonian path NP complete}\n\nTo show that HAM--PATH is NP complete we show\n\\begin{enumerate}[]\n\t\\item HAM--PATH is NP\n\t\\item HAM--CYCLE $\\leq_P$ HAM--PATH\n\\end{enumerate}\nThat HAM--PATH is NP, is shown in EX.34.2-6.\n\nTo see that HAM--CYCLE $\\leq_P$ HAM--PATH:\n\nGiven a graph $G$ where there is an instance of HAM--CYCLE, pick a node $u$ and create a new graph $G'$ where $u$ is replaced with two new nodes $u'$ and $u''$. All the edges that goes in to $u$ are also going into $u''$ and all of the outgoing edges from $u$ are also outgoing edges from $u'$. No edges are going from $u'$ to $u''$.\n\\\\\nThen it holds that\n\\\\\n$G$ has HAM--CYCLE $\\Leftrightarrow$ $G'$ has HAM--PATH\n\nBefore we prove it, note that a HAM--PATH must start in $u'$ and end in $u''$\n\nWe show $\\Rightarrow$:\n\nAssume $G$ has a HAM-CYCLE, then the same nodes creates a HAM--CYCLE in $G'$ if we split $u$ into $u'$ and $u''$.\n\nWe show $\\Leftarrow$:\n\nAssume $G'$ has HAM-PATH, then combining $u'$ and $u''$ into $u$ will create a HAM-CYCLE in $G$.\n\n\nThis show item 2. Hence we have shown that HAM-PATH is NP complete.\n", "meta": {"hexsha": "c7ecd97e02d27ccd8acfdece4a5e07e7d8fcb11b", "size": 1121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.5-6.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.5-6.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.5-6.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": 36.1612903226, "max_line_length": 333, "alphanum_fraction": 0.6743978591, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6388016183797507}}
{"text": "\\paragraph{Def} $x_i \\in [l_i, u_i]$, $a_i^\\le \\le x_i \\le a_i^\\ge$, $a_i^\\cdot = \\sum_j w_j x_j + v$\n\\paragraph{Complexity} Affine: $\\mathcal{O}(\\left(\\text{\\#layers} \\right) \\left(\\text{max \\#neurons}\\right)^2)$, ReLU: $\\mathcal{O}(1)$\n\\paragraph{ReLU}\n\\begin{tabular}[t]{c|c|c|c|c}\n    Condition & $a_j^\\le$ & $a_j^\\ge$ & $l_j$ & $u_j$ \\\\\\midrule\n    $u_i \\le 0$ & 0 & 0 & 0 & 0 \\\\\n    $l_i \\ge 0$ & $x_i$ & $x_i$ & $l_i$ & $u_i$ \\\\\n    $l_i < 0 < u_i$ & $\\lambda x_i$ & $u_i \\dfrac{x_i-l_i}{u_i-l_i}$ & $\\lambda l_i$ & $u_i$ \n\\end{tabular}\nFor any $\\lambda \\in [0,1]$\n\\paragraph{Area heuristic} Choose $\\lambda=0$ if $u\\le-l$, else $\\lambda=1$\n\n\\paragraph{Backsub} After affine layer, repeatedly backsubstitute (for $l$, choose $a^\\le$ for $w \\ge 0$, $a^\\ge$ otherwise)\n\\paragraph{Verification} Backsubstitute $x_\\text{label} - x_i$ to find lower bound, verifies iff $> 0$", "meta": {"hexsha": "c7b811ec710b1e9550f5a76b966c4cf04f342c7d", "size": 876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "deeppoly.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": "deeppoly.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": "deeppoly.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": 62.5714285714, "max_line_length": 135, "alphanum_fraction": 0.6050228311, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6387815587852551}}
{"text": "In Chapter~\\ref{chapter:bdp}, we assumed that an event organizer is only allowed to inspect a group of columns (as a batch) by polling all invitees at once.\nIn this chapter, we relax this restriction, and assume that the organizer can inspect each entry of a random matrix at unit cost (by querying a certain invitee about a certain date/time option). \nConsequently, \\Time and \\Inconvenience are always equal in this setting, and the goal is to find an optimal inspection sequence which is a permutation of entries of a given random matrix.\nAs in \\BDP, we would like to optimize the expected cost, which is the expected number of inspections until a feasible column is found or all columns are deemed infeasible -- we call this problem the Probabilistic Matrix Inspection Problem (\\PMIP). \n\n\nThe main difference between the Batched Doodle Problem (\\BDP) and the Probabilistic Matrix Inspection Problem (\\PMIP) lies in the solution domain (a unit operation on a group of columns versus entries) and the cost model (a function of Time and Inconvenience versus the number of inspections). \nThe Batched Doodle generalizes Doodle by allowing columns-by-columns inspections, and we further generalize it by allowing entry-by-entry inspections. \n\n%TODO: To re-write intro?\n\n\\section{Notation and Definitions} \\label{PMIP:sec:notation}\n\n  We use the same definition of feasibility as in previous chapter, which is copied below. \n\n \\begin{definition}[Feasibility]\n Let $A$ be a matrix whose entries are from $\\{0,1\\}$, and refer to the entry of $A$ at row $r$ and column $c$ as $a_{r,c}$.\n We say that a column $c$ of $A$ is {\\em feasible} if it consists only of 1's (otherwise it is {\\em infeasible}). \n We say that $A$ is {\\em feasible} if it contains at least one feasible column (otherwise it is {\\em infeasible}).\n \\end{definition}\n\n In the Probabilistic Matrix Inspection Problem, we do not know of the values of the entries of $A$, as they are Bernoulli random variables, but we know of probability distribution of each entry.\n An input to the problem is this probability distribution. \n \\begin{definition}[Input instance]\n An input instance of the Probabilistic Matrix Inspection problem is a pair of matrices $(A, P_A)$ of size $n$ by $m$\n where $A$ is a matrix of Bernoulli random variables \n and $P_A$ is the probability matrix associated with it.\n We denote an entry of $A$ as $a_{r,c}$ and of $P_A$ as $p_{r,c}$.\n Each entry $a_{r,c}$ of $A$ is a Bernoulli random variable, and $p_{r,c}$ is the probability of success for $a_{r,c}$ (i.e., $p_{r,c} = \\mathbf{P}[a_{r,c} = 1]$).\n We define $s_c = \\prod_{r=1}^{n} p_{r,c}$ to denote the probability that column $c$ is feasible (probability of success for column $c$).\n \\end{definition}\n Throughout this work we will assume that the set of random variables $\\{a_{r,c}\\}$ are mutually independent. This assumption is crucial to our technical results because it allows to compute (in polynomial time) the probability of a specific realization of $A$ conditioning on the event in which some entries of $A$ have already been realized. \n Without this assumption, it is unclear how one can compute such probabilities without having an access to the joint probability distribution over all realizations of $A$ (whose size is exponential in the size of $A$).\n\n We define an ``inspection'' as an operation that can be performed on $A$. \n One can inspect an arbitrary entry $a_{r,c}$ of $A$ at unit cost, so as to know of the realization of the random variable. In group scheduling, an inspection corresponds to querying an agent about her availability for a certain outcome. \n The objective of the problem is to determine whether $A$ is feasible or not, with minimum (expected) number of inspections possible. The expectation is with respect to the probability distribution specified by $P_A$.\n\n Because we are interested in determining feasibility of $A$ with minimum number of inspections, there are certain ``unnecessary inspections'' that an optimal strategy must avoid.\n For instance, if a certain entry $a_{r,c}$ is found to be unsuccessful (i.e., $a_{r,c} = 0$ is realized), then there is no need to inspect any other entry from the same column because the column is already known to be infeasible. Similarly, if a certain column is found to be feasible (which implies $A$ is feasible) or if all columns are found to be infeasible (which implies $A$ is infeasible), then there is no need to inspect any other entries of the matrix. Lastly, if $p_{r,c} = 0$ or $p_{r,c} = 1$, then there is no need to inspect the entry $a_{r,c}$ because we already know its realization with probability $1$.\n Therefore, without loss of generality, we will assume that $p_{r,c} \\in (0,1)$ (i.e., $p_{r,c}\\neq 0,1$) in this work. \n\n Let us define what constitutes a solution to the problem. \n \\begin{definition}[Inspection policy]\n \tGiven an input instance $(A,P_{A})$, a solution is any permutation of the entries of $A$, and we call it an ``inspection policy'' (or simply, a ``policy'').\n \\end{definition}\n The interpretation of a permutation is as follows. The entries of $A$ will be inspected in order specified by the permutation. After each inspection, if $A$ is found to be feasible or infeasible, the inspection process ends. Otherwise, it continues inspecting the entries as specified, but it will not make any unnecessary inspections as mentioned earlier. \n\n If $\\pi$ is a permutation of the entries of $A$, we write $C(\\pi)$ to denote the number of inspections performed by $\\pi$. $C(\\pi)$ is a random variable whose probability distribution is determined by $P_A$. We are interested in finding an optimal policy which minimizes the expected number of inspections, $\\mathbf{E}[C(\\pi)]$.\n Note that there are $(nm)!$ permutations of the entries of $A$, and therefore exhaustive search for an optimal permutation will not produce an efficient algorithm. \n\n \\subsection{Example} \\label{sec:example}\n\n Consider a 2-by-2 matrix $A$ of Bernoulli random variables whose probability of success is given by $P_A$ as follows. In group scheduling, this corresponds to two agents and a set of two date/time options being considered.\n \\begin{equation*}\n A = \n \t\\begin{bmatrix}\n \t\ta_{1,1}  & a_{1, 2} \\\\\n \t\ta_{2,1}  & a_{2, 2}\n \t\\end{bmatrix},\n P_A = \n \t\\begin{bmatrix}\n \t\t0.6  & 0.7  \\\\\n \t\t0.9  & 0.8 \n \t\\end{bmatrix}\n \\end{equation*}\n Let us consider an inspection policy $\\pi$ which inspects the entries of $A$ column-by-column while inspecting them from top to bottom within a column:\n \\begin{equation*}\n \t\\pi = \n \t\\begin{pmatrix} \n \t1 & 2 & 3 & 4  \\\\\n \ta_{1,1} & a_{2,1} & a_{1,2} & a_{2,2} \n \t\\end{pmatrix}.\n \\end{equation*}\t\n Suppose that the realization of $A$ happens to be the identity matrix of size $2$ (i.e., $a_{1,1} = a_{2,2} = 1$ and $a_{2,1} = a_{1,2} = 0$). If we use $\\pi$, it will first inspect $a_{1,1}$ and learn its realization. Since $a_{1,1} = 1$, it will inspect $a_{2,1}$ next only to find that column $1$ is infeasible after all. It will then inspect $a_{1,2}$ and learn that column $2$ is also infeasible, which implies that $A$ is infeasible. At this point, the inspection process terminates without inspecting $a_{2,2}$.\n This specific realization of $A$ happens with probability $p_{1,1}(1 - p_{2,1})(1-p_{1,2})p_{2,2}$, and yields $C(\\pi) = 3$ because 3 inspections would occur. \n If the realization of $A$ happens to be the null matrix (i.e., all entries are $0$'s), then $\\pi$ would only inspect $a_{1,1}$ and $a_{1,2}$ but skip $a_{2,1}$ and $a_{2,2}$.  In this manner one can consider all $2^{2\\cdot 2} = 16$ possible realizations of $A$, and compute $\\mathbf{E}[C(\\pi)]$ in this example. \n\n Another way to compute $\\mathbf{E}[C(\\pi)]$ is by de-coupling $C(\\pi)$ into two random variables $N(\\pi, c)$ with $c\\in\\{1,2\\}$ where $N(\\pi,c)$ denotes the number of inspections (on column $c$) performed by $\\pi$ conditioning on the event that (at least one element of) column $c$ is inspected.\n We can efficiently compute these: $\\mathbf{E}[N(\\pi, c)] = 1 \\cdot \\mathbf{P}[a_{1,c} = 0] + 2 \\cdot \\mathbf{P}[a_{1,c} = 1]$ for $c\\in \\{1, 2\\}$.\n To express $\\mathbf{E}[C(\\pi)]$ in $N(\\pi,c)$'s, we need to take conditional probability into account, as column 2 is inspected only if column 1 is infeasible: \n $\\mathbf{E}[C(\\pi)] = \\mathbf{E}[N(\\pi,1)] + \\mathbf{E}[N(\\pi,2)] (1-s_1) = 2.382$. Recall that $s_c$ is the probability of success for column $c$.\n\n\n\\section{Technical Results and Algorithm} \\label{PMIP:sec:results}\n\n\n We first consider two special cases (1-row or 1-column matrices) of the Probabilistic Matrix Inspection problem, which admit intuitive, greedy algorithms. We then discuss a couple of interesting properties of an optimal inspection policy, which leads to our main result and algorithm.\n\n \\subsection{1-Row Matrix and 1-Column Matrix}\n Let us first consider the case where an input matrix $A$ has only one row (i.e., $n = 1$).\n In this case it is natural to inspect entries with largest probability first because we can stop as soon as we find an entry whose value is $1$ -- which makes its column and $A$ feasible. This intuition is exactly what an optimal policy should do in the single row case.\n\n \\begin{lemma}[1-Row Matrix]\\label{lemma:single_row_opt}\n When $n = 1$, an inspection policy $\\pi$ is optimal if and only if it inspects the entries in non-increasing order of their associated probabilities.\n \\end{lemma}\n \\begin{proof}\n \tWithout loss of generality let us assume that a policy $\\pi$ inspects the entries in increasing order of their column index; that is, $\\pi(i) = a_{1,i}$. \n \tRecall that $C(\\pi)$ is a random variable that denotes the number of inspections $\\pi$ incurs. \n \tWe can express the expectation of $C(\\pi)$ in terms of $p_{1,c}$'s as follows:\n \t\\small\n \t\\begin{equation} \\label{eqn:exp_cost_pi_1row}\n \t\t\\mathbf{E}\\left[C(\\pi)\\right] = \n \t\tm \\left(\\prod_{k=1}^{m-1}(1 - p_{1,k})\\right) + \n \t\t\\sum_{j=1}^{m-1} j \\left(p_j \\prod_{k=1}^{j-1} (1-p_{1,k}) \\right).\n \t\\end{equation}\n \t\\normalsize\n\t\n \tSuppose that there exists some $c^*$ such that $p_{1,c^*} < p_{1,c^*+1}$ (if no such $c^*$ exists, then $\\pi$ is an inspection policy that inspects the entries in non-increasing order of probabilities).\n \tLet $\\pi'$ be the same policy as $\\pi$ except we swap the order of $a_{1,c^*}$ and $a_{1,c^*+1}$. \n \tThat is, $\\pi'$ is defined as follows.\n \t\\begin{equation*}\n \t\t\\pi'(j) = \n \t\t\\begin{cases}\n \t\t\t\\pi'(j) = \\pi(c^*+1)&  \\mbox{if~} j = c^* \\\\\n \t\t\t\\pi'(j) = \\pi(c^*)  &  \\mbox{if~} j = c^*+1 \\\\\n \t\t\t\\pi'(j) = \\pi(j)  &  \\mbox{if~} j \\neq c^* \\land j \\neq c^*+1\n \t\t\\end{cases}\n \t\\end{equation*}\t\n \tAfter expressing $\\mathbf{E}[C(\\pi)]$ and $\\mathbf{E}[C(\\pi')]$ as in Equation~\\ref{eqn:exp_cost_pi_1row}, one can re-arrange the terms to obtain the following:\n \t\\begin{equation} \\label{eqn:proof_pi_1row}\n \t\\mathbf{E}\\left[C(\\pi)\\right] - \\mathbf{E}\\left[C(\\pi')\\right] = \n \t\\left(\\prod_{j=1}^{c^*-1} (1-p_{1,j})\\right) (p_{1,c^*+1} - p_{1,c^*}).\n \t\\end{equation}\n \tThis quantity is positive if $p_{1,c^*+1} > p_{1,c^*}$ (recall that $p_{1,j} \\in (0,1)$ for all $j$ as mentioned in Section~\\ref{PMIP:sec:notation}). \n\t\n \tThis proves the lemma because any policy that inspects an entry with smaller probability before another entry with higher probability is suboptimal, and therefore an optimal policy must inspect entries in non-increasing order of their associated probabilities. \n \\end{proof}\n Although the proof of Lemma~\\ref{lemma:single_row_opt} is simple, it confirms correctness of our intuition. Equation~\\ref{eqn:proof_pi_1row} illustrates this intuition; conditioning on the event that the first $c^*-1$ inspections fail (whose probability is the product term in Equation~\\ref{eqn:proof_pi_1row}), the difference $\\mathbf{E}[C(\\pi)] - \\mathbf{E}[C(\\pi')]$ depends on the difference in the probabilities of success between the next-entry-to-be-inspected by $\\pi$ and $\\pi'$.\n\n We can also consider the case where an input matrix $A$ has only one column.\n Intuitively, if we wish to minimize the expected number of inspections, we must inspect entries with smallest probability first because we can stop as soon as we determine that $A$ is infeasible.\n Lemma~\\ref{lemma:single_column_opt} formally states this intuition about optimal policy, and we omit a proof of it as it can be easily done by following the proof of Lemma~\\ref{lemma:single_row_opt}.\n \\begin{lemma}[1-Column Matrix] \\label{lemma:single_column_opt}\n When $m = 1$, an inspection policy $\\pi$ is optimal if and only if it inspects the entries in non-decreasing order of their associated probabilities.\n \\end{lemma}\n\n\n \\subsection{Inspection of Entire Column}\n Another interesting property of an optimal inspection policy is that once it inspects the first entry of a column, then it must commit to it and continue inspecting the remaining entries of the column until feasibility of the column is determined. Otherwise, if the policy switches to another column too soon, then it is not optimal. \n \\begin{theorem}[Optimality of inspecting entire column] \\label{theorem:col_by_col_opt}\n Consider any inspection policy $\\pi$.\n Without loss of generality, let us assume that for each column $c$, $\\pi$ inspects $a_{n,c}$ the last among $n$ entries of the column. \n Let $b_c$ be the index of $\\pi$ such that $\\pi(b_c) = a_{n,c}$. \n Without loss of generality, assume $b_1 < b_2 < \\cdots < b_m$ (we can do this by re-labeling the columns of $A$). \n If there is some column $c^*$ such that $b_{c^*} > n\\cdot c^*$, then $\\pi$ is not optimal.\n \\end{theorem}\n \\begin{proof}\n First, note that $b_c \\geq n\\cdot c$ for all $c$ because we assumed $b_1 < b_2 < \\cdots < b_m$, and therefore the entries of previous columns must appear before the last entry of each column.\n\n Let $\\pi$ be an inspection policy being considered in the theorem for which there exists some $c$ with $b_{c} > n \\cdot c$.\n Let us construct a different inspection policy $\\pi'$.\n First, $\\pi'$ inspects all entries of column $1$ in the same order $\\pi$ does. \n Then, $\\pi'$ inspects all entries of column $2$ in the same order $\\pi$ does, and so on. \n In particular, $\\pi'$ inspects all entries of a column before inspecting another column, while preserving the original ordering of the entries within each column that is given by $\\pi$. \n We will show that $\\mathbf{E}[C(\\pi')] < \\mathbf{E}[C(\\pi)]$.\n\n Let us define a set of new random variables which can be used to express $C(\\cdot)$, as we did in Section~\\ref{sec:example} when analyzing an example.\n Recall that $s_c = \\prod_{r=1}^{n} a_{r,c}$ is the probability of success for column $c$.\n Let $N(\\pi, c)$ ($N(\\pi', c)$, respectively) be a random variable that denotes the number of entries of column $c$ that is inspected by $\\pi$ (by $\\pi'$, respectively), conditioning on the event that column $c$ is inspected (i.e., when the previous $c-1$ columns are infeasible).\n We can then express $\\mathbf{E}[C(\\pi)]$ and $\\mathbf{E}[C(\\pi')]$ as follows:\n \\begin{equation} \\label{eqn:exp_c_pi_decoupled}\n \t\\mathbf{E}[C(\\pi)] = \\sum_{c=1}^{m} \\mathbf{E}[N(\\pi, c)]\\left( \\prod_{k=1}^{c-1} (1 - s_c) \\right)\n \\end{equation}\n and\n \\begin{equation} \\label{eqn:exp_c_pi2_decoupled}\n \t\\mathbf{E}[C(\\pi')] = \\sum_{c=1}^{m} \\mathbf{E}[N(\\pi', c)]\\left( \\prod_{k=1}^{c-1} (1 - s_c) \\right).\n \\end{equation}\n\n\n To prove the theorem we will first show that for any realization of $A$, $N(\\pi, c) \\geq N(\\pi', c)$ holds for all $c$; this immediately implies $\\mathbf{E}[C(\\pi)] \\geq \\mathbf{E}[C(\\pi')]$.\n We will then show that there exists at least one realization of $A$ such that for some column $c'$ the strict inequality $N(\\pi, c') > N(\\pi', c')$ holds. These two statements together imply that $\\mathbf{E}[C(\\pi)] > \\mathbf{E}[C(\\pi')]$.\n\n\n Consider any realization of $A$ with the condition that the first $m-1$ columns are infeasible (recall that $m$ is the number of columns of $A$).\n Then $N(\\pi, c) = N(\\pi', c)$ for all $c$ regardless of feasibility of column $m$.\n To see why, both $\\pi$ and $\\pi'$ would inspect the same set of entries in each of the first $m-1$ columns in the same order until the column is determined to be infeasible, and therefore $N(\\pi, c) = N(\\pi', c)$ if $c<m$.\n If column $m$ is feasible, then both $\\pi$ and $\\pi'$ would inspect all $n$ entries of it, and thus we have $N(\\pi, m) = N(\\pi', m) = n$. Otherwise, if column $m$ is also infeasible (in which case $A$ is infeasible), then $\\pi$ and $\\pi'$ would inspect the same set of entries of column $m$ in the same order until the first infeasible entry of the column is found. Therefore if the first $m-1$ columns are infeasible we have $N(\\pi, c) \\geq N(\\pi', c)$ for all $c$.\n\n Now consider any realization of $A$ with the condition that at least one of the first $m-1$ columns is feasible. Let $c'$ be the smallest index of feasible columns of $A$.\n Because the columns from $1$ to $c'-1$ are infeasible, $N(\\pi, c) = N(\\pi', c)$ for all $c < c'$ for the same reason we stated earlier for the other case. \n Since $c'$ is feasible, $N(\\pi, c') = N(\\pi', c') = n$ as both policies would inspect all $n$ entries of $c'$. By our construction of $\\pi'$ it is clear that $N(\\pi', c) = 0$ for all $c > c'$; therefore we have $N(\\pi, c) \\geq N(\\pi', c)$ for all $c>c'$. In summary $N(\\pi, c) \\geq N(\\pi', c)$ holds for all $c$ in this case as well. \n\n So far we proved the first claim we stated earlier: for all realizations of $A$, we have $N(\\pi, c) \\geq N(\\pi', c)$ for all $c$.\n Let us now prove the second claim. Let $c^*$ be the smallest index $c$ of columns such that $b_c > nc$ (note that $c^* < m$ because $b_m = nm$ by definition). \n Consider any realization of $A$ with the condition that the first $c^*-1$ columns are infeasible and column $c^*$ is feasible (feasibility of other columns do not matter). \n Using the same arguments we used earlier, we can show that $N(\\pi, c) = N(\\pi', c)$ for all $c < c^*$, that $N(\\pi, c^*) = N(\\pi', c^*) = n$, and that $N(\\pi', c) = 0$ for all $c> c^*$. \n However, because $b_{c^*} > n \\cdot c^*$, there is at least one entry $a_{r',c'}$ with $c' > c^*$ which  appears before $b_{n, c^*}$ in $\\pi$ (otherwise, if no such entry exists, then $b_{c^*}$ would be equal to $n \\cdot c^*$). This implies that there exists some $c'$ with $c' > c^*$ such that $N(\\pi, c') > 0$. \n This proves the second claim that for some realization of $A$, there is some column $c'$ for which $N(\\pi, c') >  N(\\pi', c')$, and together with the first claim we proved earlier, this implies that $\\mathbf{E}[C(\\pi)] > \\mathbf{E}[C(\\pi')]$. \n\n This proves the theorem: Any policy that does not inspect all entries of a column consecutively is suboptimal.\n \\end{proof}\n By Theorem~\\ref{theorem:col_by_col_opt}, when seeking an optimal policy, it is sufficient to consider the set of policies that inspect an entire column before committing to another column. Lemma~\\ref{lemma:single_column_opt} hints that one should inspect the entries of each column in increasing order of probabilities, and this is what we prove next.\n\n\n \\subsection{Optimal Ordering within Column} \n\n Lemma~\\ref{lemma:single_column_opt} states that\n an optimal policy must inspect the entries in increasing order of their probability of success, if $A$ is a 1-column matrix.\n This argument can be generalized to the case where there is more than one column: If an optimal policy is to inspect an entry of some column $c$, it must inspect the entry with smallest probability of success first. \n \\begin{theorem}[Optimal ordering within column] \\label{theorem:within_column_opt}\n \tConsider any inspection policy $\\pi$.\n \tIf there exist two entries $a_{r_1,c}$ and $a_{r_2,c}$ from the same column such that $a_{r_1,c}$ appears before $a_{r_2,c}$ in $\\pi$ and $p_{r_1,c} > p_{r_2,c}$, then $\\pi$ is not optimal. \n \tIn other words, when restricted to each column, an optimal policy must inspect the entries of the column in non-decreasing order of probabilities.\n \\end{theorem}\n \\begin{proof}\n \tLet $\\pi$ be an inspection policy being considered in the theorem.\n \tBecause of Theorem~\\ref{theorem:col_by_col_opt} we can assume, without loss of generality, that $\\pi$ inspects all entries of column 1, followed by column 2, and so on.\n \tFurther let us assume that $\\pi$ inspects the entries of each column in increasing order of their row index (we can do so by re-labeling the indices of entries). Precisely, $\\pi(r + n (c-1)) = a_{r,c}$ defines $\\pi$. Let $p_{r,c^*}$ and $p_{r+1,c^*}$ be the entries with $p_{r,c^*} > p_{r+1, c^*}$.\n \tLet us consider a different inspection policy $\\pi'$ that is the same as $\\pi$ except that $\\pi'$ inspects $p_{r+1,c^*}$ before $p_{r,c^*}$, by swapping the ordering of them.\n \t\\begin{equation*}\n \t\t\\pi'(j) = \n \t\t\\begin{cases}\n \t\t\t\\pi'(j) = a_{r+1,c^*}  &  \\mbox{if~} \\pi(j) = a_{r,c^*} \\\\\n \t\t\t\\pi'(j) = a_{r,c^*}    &  \\mbox{if~} \\pi(j) = a_{r+1,c^*} \\\\\n \t\t\t\\pi'(j) = \\pi(j)     &  \\mbox{otherwise} \n \t\t\\end{cases}\n \t\\end{equation*}\t\n\t\n \tWe claim that $\\mathbf{E}[C(\\pi')] < \\mathbf{E}[C(\\pi)]$, which implies that $\\pi$ is not optimal.\n\t\n \tLet us define new random variables $N(\\pi, c)$ and $N(\\pi', c)$ as we did in our proof of Theorem~\\ref{theorem:col_by_col_opt} (i.e., the number of inspections performed by the respective policy on column $c$, conditioning on the event that the column is inspected).\n \tThen we can express $\\mathbf{E}[C(\\pi)]$ and $\\mathbf{E}[C(\\pi')]$ in terms of the new random variables and $s_c$'s as we did in Equations~\\ref{eqn:exp_c_pi_decoupled} and \\ref{eqn:exp_c_pi2_decoupled}.\n\t\n \tObserve that $N(\\pi, c) = N(\\pi', c)$ for any realization of $A$ if $c \\neq c^*$.\n \tTo see this, first note that column $c$ would not be inspected by $\\pi$ or by $\\pi'$ if any of the previous columns (that is, columns $1$ through $c-1$) is found to be feasible, in which case $N(\\pi, c) = N(\\pi', c) = 0$. Otherwise, if column $c$ is inspected, both policies would inspect the entries of $c$ in the very same order, so $N(\\pi, c) = N(\\pi', c)$ must hold. Therefore we conclude that $\\mathbf{E}[N(\\pi, c)] = \\mathbf{E}[N(\\pi', c)]$ when $c \\neq c^*$. \n\t\n \tWe will now show that $\\mathbf{E}[N(\\pi, c^*)] > \\mathbf{E}[N(\\pi', c^*)]$ holds. \n \tThis immediately implies $\\mathbf{E}[C(\\pi)] > \\mathbf{E}[C(\\pi')]$ due to Equations~\\ref{eqn:exp_c_pi_decoupled} and \\ref{eqn:exp_c_pi2_decoupled}.\n \tLet us express $\\mathbf{E}[N(\\pi, c^*)]$ in terms of $p_{r,c^*}$'s.\n \t\\begin{equation*}\n \t\t\\mathbf{E}[N(\\pi, c^*)] = n\\left( \\prod_{k=1}^{n-1} p_{k,c^*}\\right) + \n \t\t\\sum_{j=1}^{n-1} j (1-p_{j,c^*}) \\left( \\prod_{k=1}^{j-1} p_{k,c^*} \\right)\n \t\\end{equation*}\n \tNote that the event $N(\\pi, c^*) = j$ occurs if the first $j-1$ entries are feasible while the $j$-th entry is not feasible when $j < n$, and $N(\\pi, c^*) = n$ occurs if the first $n-1$ entries are feasible (but the $n$-th entry's feasibility does not matter).\n\t\n \tWe can express $\\mathbf{E}[N(\\pi', c^*)]$ in a similar manner, and simplify  $\\mathbf{E}[N(\\pi, c^*)] - \\mathbf{E}[N(\\pi', c^*)]$ as follows:\n \t\\small\n \t\\begin{equation*}\n \t\t\\mathbf{E}[N(\\pi, c^*)] - \\mathbf{E}[N(\\pi', c^*)] = \n \t\tr \\left( \\prod_{k=1}^{r-1} p_{k,c^*} \\right) (p_{r,c^*} - p_{r+1,c^*}).\n \t\\end{equation*}\n \t\\normalsize\n \tThe quantity above is positive if $p_{r,c^*} > p_{r+1,c^*}$, which is the assumption we began with.\n \tThis proves the theorem.\n \\end{proof}\n\n\n Theorems~\\ref{theorem:col_by_col_opt} and \\ref{theorem:within_column_opt} together tell us that \n in order to find an optimal policy we only need to decide the ordering of the columns. \n There are still $m!$ orderings of columns, and an exhaustive search algorithm would not be efficient.\n As we were able to generalize Lemma~\\ref{lemma:single_column_opt} to Theorem~\\ref{theorem:within_column_opt} by generalizing the optimal solution for 1-column case, it would be natural to consider generalizing Lemma~\\ref{lemma:single_row_opt} in a similar manner.\n\n This idea leads to the following greedy algorithm: First we sort columns by their probability of success ($s_c = \\prod_{r=1}^{n} p_{r,c}$) in decreasing order, and inspect the entries of each column in increasing order of their associated probabilities. However, as the following example shows, this algorithm is suboptimal. \n \\begin{equation*}\n A = \n \t\\begin{bmatrix}\n \t\ta_{1,1}  & a_{1, 2} \\\\\n \t\ta_{2,1}  & a_{2, 2}\n \t\\end{bmatrix},\n \tP_A =\n \t\\begin{bmatrix}\n \t\t0.4459  & 0.2262 \\\\\n \t\t0.4459  & 0.8114\n \t\\end{bmatrix}\n \\end{equation*}\n Here we have $s_1 ~= 0.199$ and $s_2 ~= 0.184$, and the greedy algorithm would produce $\\pi = \\begin{pmatrix} a_{1,1} & a_{2,1} & a_{1,2} & a_{2,2} \\end{pmatrix}$. Its expected cost, $\\mathbf{E}[C(\\pi)]$, is $2.428$, but if we inspect the second column first, then the expected cost is $2.407$ which is optimal in this example.\n One can consider another greedy algorithm which inspects the columns in increasing order of their expected number of inspections (within column), but this algorithm turns out to be suboptimal as well. \n\n\n \\subsection{Main Result and Algorithm}\n Let us present the main result that leads to an efficient algorithm for finding an optimal inspection policy. \n\n \\begin{theorem} \\label{thm:main_result}\n \tLet $s_c$ be the probability of success for column $c$ as before. \n \tLet $\\mu_c$ be the expected number of inspections that column $c$ incurs if its entries are inspected in increasing order of their probability of success, conditioning on the event that column $c$ is inspected and infeasible.\n \tAn optimal policy must be a column-by-column policy (due to Theorem~\\ref{theorem:col_by_col_opt}), must inspect the entries of each column in non-decreasing order of probabilities (due to Theorem~\\ref{theorem:within_column_opt}), and must inspect the columns in non-decreasing order of $\\mu_c(1 - s_c)/s_c$.\n \\end{theorem}\n \\begin{proof}\n \tConsider a column-by-column inspection policy $\\pi$ which inspects the column 1 through $m$ in increasing order of their index (we can assume this without loss of generality by re-labeling columns).\n\t\n \tAs before, let $N(\\pi,c)$ be a random variable that denotes the number of inspections performed by $\\pi$ on column $c$, conditioning on the event that column $c$ is inspected.\n \tThen we can express $\\mathbf{E}[N(\\pi, c)]$ in terms of $s_c$ and $\\mu_c$ as follows.\n \t\\begin{equation}\\label{eqn:exp_cost_column_by_condition}\n \t\t\\mathbf{E}[N(\\pi, c)] = s_c \\cdot n  + (1-s_c) \\cdot \\mu_c\n \t\\end{equation}\n \tThis equation holds because if the column is feasible (with probability $s_c$), it would require $n$ inspections, but if it is not (with probability $1-s_c$), it would require $\\mu_c$ inspections in expectation. The equation above simply considers these two events, and calculates the expected value of $N(\\pi, c)$. \n\t\n \tSuppose that there is some column $c^*$ such that $\\mu_{c^*}(1 - s_{c^*}) / s_{c^*} > \\mu_{c^*+1} (1 - s_{c^*+1}) / s_{c^*+1}$. Because $\\pi$ inspects column $c^*$ before column $c^*+1$, it would not be inspecting the columns in increasing order of $\\mu_c(1-s_c)/s_c$.\n \tConsider a different inspection policy $\\pi'$ which inspects the columns in the same order as $\\pi$ except that $\\pi'$ inspects column $c^*+1$ before $c^*$ by swapping the inspection ordering of the two.\n \tWe can relate $N(\\pi, \\cdot)$ to $N(\\pi', \\cdot)$ as follows.\n \t\\begin{equation*}\n \t\tN(\\pi', c) = \n \t\t\\begin{cases}\n \t\t\tN(\\pi, c^*+1) & \\mbox{if~} c = c^* \\\\\n \t\t\tN(\\pi, c^*)   & \\mbox{if~} c = c^* + 1 \\\\\n \t\t\tN(\\pi, c)     & \\mbox{otherwise}\n \t\t\\end{cases}\n \t\\end{equation*}\n\t\n \tAs we did in proofs of Theorems~\\ref{theorem:col_by_col_opt} and \\ref{theorem:within_column_opt}, we can use Equations~\\ref{eqn:exp_c_pi_decoupled} and \\ref{eqn:exp_c_pi2_decoupled}, and simplify $\\mathbf{E}[C(\\pi)] - \\mathbf{E}[C(\\pi')]$ as follows.\n\t\\small\n \t\\begin{equation} \\label{eqn:main_result_diff}\n \t\t\\begin{aligned}\n \t\t\\mathbf{E}[C(\\pi)] - \\mathbf{E}[C(\\pi')] ={} & \\left(\\frac{\\mathbf{E}[N(\\pi, c^*)]}{s_{c^*}}  - \\frac{\\mathbf{E}[N(\\pi, c^*+1)]}{s_{c^*+1}} \\right) \\\\\n \t\t& \\cdot \\left( \\prod_{j=1}^{c^*-1} (1 - s_j)\\right) s_{c^*} s_{c^*+1}\n \t\t \\end{aligned}\n \t\\end{equation}\t\n\t\\normalsize\n \tThe quantity in Equation~\\ref{eqn:main_result_diff} is positive if the difference of the weighted expected values (in the first parentheses) are positive. Using Equation~\\ref{eqn:exp_cost_column_by_condition} we obtain the following inequality.\n \t\\begin{equation*}\n \t\t\\begin{aligned}\n \t\t\t{} &\n \t\t\\frac{\\mathbf{E}[N(\\pi, c^*)]}{s_{c^*}}  > \\frac{\\mathbf{E}[N(\\pi, c^*+1)]}{s_{c^*+1}} \\\\\n \t\t\\Leftrightarrow &\n \t\t\\mu_{c^*} (1 - s_{c^*}) / s_{c^*} > \\mu_{c^*+1}(1 - s_{c^*+1}) / s_{c^*+1} \n \t\t\\end{aligned}\n \t\\end{equation*}\n \tBy definition of $c^*$, the second inequality above holds, which implies $\\mathbf{E}[C(\\pi)] > \\mathbf{E}[C(\\pi')]$.\n \tTherefore, an optimal inspection policy must inspect the columns in non-decreasing order of $\\mu_c(1 - s_c)/s_c$. \n \\end{proof}\n Because there is a unique ordering of columns if we sort them by $\\mu_c(1-s_c)/s_c$ (up to ties), Theorem~\\ref{thm:main_result} leads to the following algorithm: We inspect the columns in increasing order of $\\mu_c(1-s_c)/s_c$, and in each column, we inspect the entries of it in increasing order of probabilities. \n This algorithm can easily be implemented to run in polynomial time. \n\n\n\\section{Discussion and Future Work} \\label{PMIP:sec:discussion}\nIn this work we defined the Probabilistic Matrix Inspection problem motivated by group scheduling and Doodle. \nWe first considered two special cases, and discovered interesting properties of an optimal inspection policy which agree with our intuition. We then generalized our findings to design an efficient algorithm to solve the general case, and along the way we showed that two natural greedy algorithms fail to find an optimal solution. While we believe that our technical results make a great starting point for studying and optimizing a group scheduling process, there remain several open problems and future work to be done.\n\nAs we discussed in previous chapter, our model and algorithm rely on the assumption that probability estimates on availability of agents are available. We suggested several ideas motivated by previous work in the literature, but it will be important to deploy such ideas into a system, and integrate it with our algorithm. From a theoretical perspective, there remain several open problems. While we assumed that an inspection can be performed on a single entry at unit cost, one can generalize the cost model by allowing an inspection of any subset of entries whose cost depends on, for example, the number of entries being inspected. In the context of group scheduling, an inspection on many entries means querying multiple agents at the same time for one or many outcomes (but an inspection is not limited to the entries from the same column or row). This generalization is particularly useful when scheduling takes place in a hierarchical setting such as corporates. For instance the event organizer may feel that the cost of querying a supervisor is significantly different from that of querying a colleague.\n\nLastly, although we focused on relating our model to group scheduling, the Probabilistic Matrix Inspection problem has other applications. Finding the right childcare facility, for example, involves extensive inquiries as parents wish to gather more information about how they would handle certain situations, what benefits and environments they provide, and so on. Through advertisements or brochures parents may even be able to gauge the likelihood of a certain facility satisfying their needs. Yet they still need to inquire facilities for precise information, which can be modeled by our probabilistic matrix model where columns correspond to facilities and rows correspond to the needs of parents. \n\n", "meta": {"hexsha": "0ab6225f9d066722cf859f4ffddd7b3917bede38", "size": 31727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prior to 2016-09-18/30Matrix.tex", "max_stars_repo_name": "ltdtl/thesis", "max_stars_repo_head_hexsha": "b1585aa3e57e06b4368fb51540bbbf1c64c491df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-09-18T17:20:45.000Z", "max_stars_repo_stars_event_max_datetime": "2016-09-18T17:20:45.000Z", "max_issues_repo_path": "prior to 2016-09-18/30Matrix.tex", "max_issues_repo_name": "ltdtl/thesis", "max_issues_repo_head_hexsha": "b1585aa3e57e06b4368fb51540bbbf1c64c491df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-01-29T07:21:01.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-29T07:21:01.000Z", "max_forks_repo_path": "prior to 2016-09-18/30Matrix.tex", "max_forks_repo_name": "ltdtl/thesis", "max_forks_repo_head_hexsha": "b1585aa3e57e06b4368fb51540bbbf1c64c491df", "max_forks_repo_licenses": ["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.9910179641, "max_line_length": 1113, "alphanum_fraction": 0.7077883191, "num_tokens": 9474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6387441920906125}}
{"text": "%---------------------------Shape & Size-----------------------------\n\\section{Shape and Size\\label{s:tri-shape-and-size}}\n\nLet $R$ be the relative size squared as defined in \\S\\ref{s:tri-rel-size-squared}\nand $S$ be the shape as defined in \\S\\ref{s:tri-shape}.\nThen the ``shape and size'' metric is \n\\[\n  q = RS\n\\]\n\n\\trimetrictable{shape and size}%\n{$1$}%                                                Dimension\n{$[0.25,1]$}%                                         Acceptable range\n{$[0,1]$}%                                            Normal range\n{$[0,1]$}%                                            Full range\n{Dependent on $\\overline{A}$}%                        Unit equilateral triangle value\n{\\cite{knu:03}}%                                      Reference(s)                   \n{v\\_tri\\_shape\\_and\\_size}%                            Verdict function name\n\n", "meta": {"hexsha": "aabb1beb2e50054cc9cd8932ceac9cb60cf5bff4", "size": 867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriShapeAndSize.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/TriShapeAndSize.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/TriShapeAndSize.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.35, "max_line_length": 85, "alphanum_fraction": 0.4186851211, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6386570788740827}}
{"text": "\\newpage\n\\part{Introduction}\n%\\section{Introduction}\n\n\\section{Terminologies \\& Intros }\n\n\\subsection{Categories of Business Analytics}\n\\begin{itemize}\n\t\\item descriptive analytics\n\t\t\\begin{itemize}\n\t\t\t\\item data engineering(organizing data, queries) \\& statistics (mean, trend, standard deviation, test hypotheses)\n\t\t\\end{itemize}\n\t\n\t \\item predictive analytics\n\t \t\\begin{itemize}\n\t \t\t\\item machine learning \\& econometrics\n\t \t\t\\item learn the pattern of data\n\t \t\\end{itemize}\n \t\n \t\\item prescriptive analytics\n \t\\begin{itemize}\n \t\t\\item algorithm \\& optimization models\n \t\\end{itemize}\n\t\n\\end{itemize}\n\n\\subsection{From Data to Information}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{datatoinfo.png}\n\\end{figure}\n\n\\subsection{Types of Analytic Exercises}\n\\begin{itemize}\n\t\\item Numeric Prediction\n\t\\begin{itemize}\n\t\t\\item \\textbf{supervised} learning\n\t\t\\item input: a collection of data input + \\textbf{known} output\n\t\t\n\t\t\t  job: create a function  $f(\\text{input}_{0}) = \\text{output}_0$\n\t\t\t  \n\t\t\t  output: \\textbf{prediction} values to a \\textbf{new} collection of data: $f(\\text{input}_1) = ?$ \n\t\t\\item example: linear regression\n\t\\end{itemize}\n\n\t\\item Classification\n\t\\begin{itemize}\n\t\t\\item \\textbf{supervised} learning\n\t\t\\item input: a collection of data input + \\textbf{known} label\n\t\t\t\n\t\t\t  job: create a classifier $f(\\text{input}_0) = \\text{label}_0$\n\t\t\t  \n\t\t\t  output: \\textbf{prediction} label to a \\textbf{new} collection of data: $f(\\text{input}_1) = ?$\n\t\\end{itemize}\n\n\t\\item Clustering\n\t\\begin{itemize}\n\t\t\\item \\textbf{unsupervised} learning\n\t\t\\item input: a collection of data input\n\t\t\t  \n\t\t\t  job: identify \"natural\" grouping in data\n\t\t\t  \n\t\t\t  output: clustered data\n\t\\end{itemize}\n\n\t\\item Association Rule Analysis\n\t\\begin{itemize}\n\t\t\\item \\textbf{unsupervised} learning\n\t\t\\item input: a collection of data list\n\t\t\t  \n\t\t\t  job: identify \\textbf{relationships} in data from \\textbf{co-occuring items}\n\t\t\\item grocery store purchases analysis\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Machine Learning Terminology in categorizing analytic exercises}\n\\begin{itemize}\n\t\\item \\textbf{supervised learning}\n\t\\begin{itemize}\n\t\t\\item a training set is given\n\t\t\\item find relationship between input \\& target attributes\t\t\n\t\t\\item examples: numeric prediction, classification\n\t\\end{itemize}\n\n\t\\item \\textbf{unsupervised learning}\n\t\\begin{itemize}\n\t\t\\item only input data available, no training set\n\t\t\\item find regularities, irregularities, relationships, similarities among data points\n\t\t\\item examples: clustering, association rule analysis\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Model}\nexamples: \n\\begin{itemize}\n\t\\item linear model\n\t\\item decision tree\n\t\\item neural network\n\\end{itemize}\n\n\\section{Statistics Recap}\n\\subsection{Categories}\n\\begin{itemize}\n\t\\item \\hl{descriptive statistics}: \\textbf{summary} of data\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item examples: mean, standard deviation\n\t\\end{itemize}\n\t\n\t\\item \\hl{inferential statistics}: model \\textbf{patterns} of data, accounting for \\textbf{randomness} and drawing \\textbf{inferences about a larger population}\n\t\\begin{itemize}\n\t\t\\item estimation\n\t\t\\item hypothesis testing\n\t\t\\item forecasting\n\t\t\\item correlation\n\t\t\\item regression\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n\\subsection{Random Variables}\n$X$ is a \\textbf{random variable} if:\n\\begin{itemize}\n\t\\item it represents a \\textbf{random draw} from a population\n\t\\item it's associated with a \\textbf{probability distribution}\n\t\\item either \\textbf{discrete} or \\textbf{continuous}\n\t\\item example: a random variable that follows a \\textbf{normal distribution} $N(\\mu, \\sigma^2)$ has a probability density function of \n\t$$f(x) = \\frac{1}{\\sigma \\sqrt{2\\pi}}e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}$$\n\\end{itemize}\n\n\\subsection{Normal Distribution \\& Standard Normal Distribution}\nA random variable $X$ follows a normal distribution $N(\\mu, \\sigma^2)$\n\nTo \\textbf{''standardize''} a random variable $x$ to \\textbf{standard normal distribution }\n$N(0,1)$: $$Z = \\frac{X - \\mu}{\\sigma}$$\n\n\\subsection{Probability density function \\& Cumulative density function}\n\\textbf{Probability density function (pdf): f(x)} $$f(x) = P(X = x)$$\n\n\\textbf{Cumulative distribution fuction (cdf): F(x)} $$F(x) = P(X \\leq x)$$ $$P(X \\geq x) = 1 - F(x)$$  $$P(x_1 \\leq X \\leq x_2) = F(x_2) - F(x_1)$$\n\n\\subsection{Statistical Estimation}\n\\textbf{Statistical estimation}: \n\nThe parameters of a population are \\textbf{unknown}. However, we can \\textbf{estimate} the parameters by \\textbf{drawing a random sample} out of the population, analyzing this random sample and getting the statistics. The statistics should infer the parameters.\n\\\\ \\ \\\\\nRequirements of random sampling: \n\\begin{itemize}\n\t\\item each variable $X$ from the population is a random variable. \n\t\\item each combination of $n$ sample points has an \\textbf{equal} chance of being selected.  \n\t\n\\end{itemize}\n\t$\\longrightarrow$ a random sample is a set of \\textbf{independent, identically distributed (i.i.d)} random variables.\n\\\\ \\ \\\\\n\\textbf{Categories:}\n\\begin{itemize}\n\t\\item Point Estimate\n\t\\begin{itemize}\n\t\t\\item sample mean\n\t\t\\item sample proportion\n\t\\end{itemize}\n\n\t\\item Interval Estimate\n\t\\begin{itemize}\n\t\t\\item \\textbf{confidence interval} for sample mean\n\t\t\\item \\textbf{confidence interval} for sample proportion\n\t\\end{itemize}\n\\end{itemize}\nPoint estimate is always within the interval estimate.\n\n\\subsubsection{Point Estimate: Population Mean and Its Estimation}\n\\begin{itemize}\n\t\\item \\textbf{Expected Value of X and the Population Mean}\n\t\n\tThe expected value of a probability \\textbf{weighted average} of $X$, $E(X)$, is the mean/expected value of the probability distribution of $X$. \n\t\n\t$f(x_i)$ is the (discrete) probability that $X = x_i$.\n\t$$\\mu_x = E(X) = \\Sigma_{i=1}^{n} x_i f(x_i)$$ or $$\\mu_x = E(X) = \\int_{-\\infty}^{+\\infty} xf(x) dx$$ \n\t\n\tIf this random sample is a set of i.i.d random variables, the \\textbf{expected value of X} is the \\textbf{population mean}(unknown).\n\t\n\t\\item \\textbf{Estimation of the Population Mean by Sample Mean}\n\t\n\t\\textbf{Sample Mean $\\bar{X}$:} the \\textbf{random variable} for the arithmetic mean of the sample. $\\bar{x}$ is the mean of a \\textbf{particular realization} of a sample.\n\t\n\t \n\t$$\\bar{X} = \\frac{\\Sigma X_i}{n} $$\n\t\n\tThis is a random variable, because a lot of samples are drawn repeatedly, the arithmetic mean of the sample has also a probability distribution. \\textbf{The mean(center) of this distribution should estimate the mean of the whole population. }\n\t\n\t\n\t\n\t\\item Requirements for an estimator: \\textbf{unbiased}\n\t\n\tExample: $$E(\\bar{X}) = \\mu_x$$\n\t\n\t\\item \\textbf{Standard Error of the Sample Mean}: \n\t\n\t\\begin{itemize}\n\t\t\\item  \\hl{\\textbf{standard error of the sample mean $SE_{\\bar{X}}$}} : an estimate of how far the \\textbf{sample mean} is likely to be \\textbf{from the population mean}. \n\t\t\n\t\tWhen $n \\rightarrow \\infty$,  $SE_{\\bar{X}}  \\rightarrow \\sigma_{\\bar{X}}$ (\\hl{\\textbf{true standard deviation of sample mean}}).\n\t\t\n\t\t$$SE_{\\bar{X}} = \\frac{s}{\\sqrt{n}}$$\n\t\t$$\\sigma_{\\bar{X}} = SD(\\bar{X}) = \\sqrt{Var(\\bar{X})} = \\frac{\\sigma}{\\sqrt{n}}$$\n\t\t\n\t\t\\item\\hl{\\textbf{sample standard deviation $s$}} : the degree to which \\textbf{individuals within the sample} differ from the \\textbf{sample mean}\n\t\t\n\t\t$$s = \\sqrt{\\frac{1}{n-1} \\Sigma_{i=1}^{n} (X_i - \\bar{X})^2}$$\n\t\\end{itemize}\n\t\n\t\\item \\textbf{Law of Large Numbers}\n\t\n\tIf $n \\rightarrow \\infty, \\bar{X}_n \\rightarrow \\mu$. \n\t\n\tIf the size of the random sample is large enough, then the arithmetic mean converge to the real population mean.  \n\t$$\\lim\\limits_{n\\rightarrow \\infty} P(|\\bar{X}_n - \\mu| > \\epsilon) = 0$$\n\t\n\t\\item \\textbf{Central Limit Theorem}\n\t\n\tIf \\textbf{$n \\rightarrow \\infty$}, the \\textbf{average $\\bar{X}$} of any population of \\textbf{i.i.d.} random variables $X_i$ with the population mean $\\mu_X$ and population variance $\\sigma^2$ \\textbf{follows asymptotically a normal distribution} $\\bar{X} \\sim N(\\mu_X, \\frac{\\sigma^2}{n})$. \n\t$$\\bar{X} = \\frac{X_1 + X_2 + \\dots + X_n}{n}$$\n\tThe \\textbf{standardize average} $Z \\sim N(0,1)$: $$Z = \\frac{\\bar{X} - \\mu_X}{\\frac{\\sigma}{\\sqrt{n}}}$$\n\\end{itemize}\n\n\\subsubsection{Interval Estimate: }\n\\begin{itemize}\n\t\\item \\textbf{Confidence Interval of Sample Mean:}\n\t\\begin{itemize}\n\t\t\\item Assumption: samples drawn from a population that follows a normal distribution $N(\\mu_X, \\sigma^2)$. \n\t\t\n\t\teg: The sample mean $\\bar{X}$ follows asymptotically a normal distribution $N(\\mu_X, \\frac{\\sigma^2}{n})$\n\t\t\\item a level of confidence($1 - \\alpha$) is given.\n\t\t\\item \\textbf{two-sided} $\\rightarrow z_{(1 - \\frac{\\alpha}{2})} $  / $z_{(1 + \\frac{\\alpha}{2})}$\n\t\t\\item z value: \\textbf{standardized}. \\textbf{Find z value from cdf-table given an $\\alpha$}.\n\t\t\\item if population standard deviation $\\sigma$ is given, \n\t\t$$CI = \\left[ \\bar{X} - z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} , \\bar{X} + z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} \\right] $$\n\t\t$$Pr(\\bar{X} - z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} < \\mu_X < \\bar{X} + z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{\\sigma}{\\sqrt{n}} ) = 1 - \\alpha$$\n\t\t\n\t\t\\item if population standard deviation $\\sigma$ is unknown, \n\t\t\\begin{itemize}\n\t\t\t\\item n is \\textbf{small}: use \\textbf{sample standard deviation $s$} and \\textbf{t-distribution}\n\t\t\t$$CI = \\left[ \\bar{X} - t_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} , \\bar{X} + t_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} \\right] $$\n\t\t\t\\item n is \\textbf{large}: use \\textbf{sample standard deviation $s$} and \\textbf{normal distribution}\n\t\t\t$$CI = \\left[ \\bar{X} - z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} , \\bar{X} + z_{(1 - \\frac{\\alpha}{2})}\\cdot \\frac{s}{\\sqrt{n}} \\right] $$\n\t\t\\end{itemize}\n\t\tIf $n \\rightarrow \\infty$, the T-Distribution converges to a Normal Distribution.\n\t\t\n\t\\end{itemize}\n\n\t\\item Effects on Confidence Intervals:\n\t\\begin{itemize}\n\t\t\\item \\textbf{sample size} n: n $\\uparrow$, interval size $\\downarrow$ \n\t\t\n\t\t(the larger the size, more precise is the estimation)\n\t\t\\item \\textbf{confidence level} ($1 - \\alpha$): confidence level $\\uparrow$, interval size $\\uparrow$ \n\t\t\n\t\t(given the same sample size, the higher the confidence level, the more values need to be included.)\n\t\t\\item \\textbf{population standard deviation} $\\sigma$: $\\sigma \\uparrow$, interval size $\\uparrow$ \n\t\t\n\t\t(the more spreaded the population, the more values need to be included to achieve same confidence level.)\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{Statistical Tests}\n\\subsubsection{Process} \n\\begin{itemize}\n\t\\item number of samples\n\t\\begin{itemize}\n\t\t\\item 1 sample:\n\t\t\\begin{itemize}\n\t\t\t\\item $\\sigma$ known: \\textbf{Z-Test}\n\t\t\t\\item $\\sigma$ unknown: \\textbf{T-Test}\n\t\t\\end{itemize}\n\t\t\\item 2 samples:\n\t\t\\begin{itemize}\n\t\t\t\\item dependent:\\textbf{ Paired T-Test} \n\t\t\t\\item independent: \\textbf{Welch-Test}\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\\item Formulate \\textbf{null and alternative hypothesis} ($H_0$ and $H_1$), $H_1$ is the hypothesis we want to test.\n\t\\item Choose an \\textbf{$\\alpha$ level}. (type I error: probability of falsely rejecting $H_0$)\n\t\\item Find corresponding \\textbf{distribution}, calculate \\textbf{test statistic}, \n\t\\item Find the \\textbf{critical value} in the table and corresponding \\textbf{p-value}\n\t\\item Conclusion: \n\t\\begin{itemize}\n\t\t\\item $p \\leq \\alpha$, reject $H_0$\n\t\t\\item $p > \\alpha$, reject $H_1$ \n\t\\end{itemize}\n\tInterpretation of p-value: the probability of having the other mean $\\bar{x}$, given that $H_0$ is true.\n\\end{itemize}\n\n\\subsubsection{Two-sided or One-sided Test}\nThree possible alternative hypotheses $H_1$:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{H1.png}\n\\end{figure}\nCritical Value:\n\\begin{itemize}\n\t\\item two-sided test: $z_{\\frac{\\alpha}{2}}, z_{1-\\frac{\\alpha}{2}}$ / $t_{\\frac{\\alpha}{2}}, t_{1-\\frac{\\alpha}{2}}$\n\t\\item one-sided test: $z_{1-\\alpha}$ / $t_{1-\\alpha}$\n\\end{itemize}\n\n\n\n\\subsubsection{Z-Test}\n\\begin{itemize}\n\t\\item Requirements: \\textbf{1 sample, $\\mu$, $\\sigma$ known} (population mean and population standard deviation)  \n\t\\item Distribution: \\textbf{standardized normal distribution}\n\t\\item test statistic: \\large{$$ z = \\frac{\\bar{X} - \\mu_0}{\\frac{\\sigma}{\\sqrt{n}}}$$}\n\t\\item critical value: $z^c_{1-\\frac{\\alpha}{2}}$ / $z^c_{1-\\alpha}$\n\t\\item $H_0$ Rejection region/ $H_1$ Acceptance region :\n\t\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$H_1$ \t\t\t\t& Rejection Region\t\t\t\t\t& test variant \\\\ \\hline\n\t\t\t\t$\\mu\\mu \\neq \\mu_0$\t& $|z| \\geq z^c_{1-\\frac{\\alpha}{2}}$\t& two-sided                 \\\\ \\hline\n\t\t\t\t$\\mu\\mu > \\mu_0$\t& $ z \\geq z^c_{1-\\alpha}$\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\t$\\mu\\mu < \\mu_0$\t& $ z \\leq -z^c_{1-\\alpha} $\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table} \t\n\\end{itemize}\n\n\\subsubsection{Single Sample T-test}\n\\begin{itemize}\n\t\\item Requirements: \\textbf{1 sample, $\\sigma$ unknown}\n\t\\item Distribution: Student \\textbf{t-Distribution}\n\t\\item Degree of Freedom($df$): determines how spread the distribution is. \n\t\\large{$$df = n - 1$$}\n\t\\item test statistic: \n\t\n\t$s$ is the standard error(empirical)\n\t\\large{$$t(df) = \\frac{\\bar{X} - \\mu_0}{\\frac{s}{\\sqrt{n}}}$$}\n\t\\item critical value: $t^c_{1-\\frac{\\alpha}{2}, df}$ / $t^c_{1-\\alpha, df}$\n\t\\item $H_0$ Rejection region/ $H_1$ Acceptance region :\n\t\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$H_1$ \t\t\t\t& Rejection Region\t\t\t\t\t& test variant \\\\ \\hline\n\t\t\t\t$\\mu\\mu \\neq \\mu_0$\t& $|t| \\geq t^c_{1-\\frac{\\alpha}{2}, df}$\t& two-sided                 \\\\ \\hline\n\t\t\t\t$\\mu\\mu > \\mu_0$\t& $ t \\geq t^c_{1-\\alpha, df}$\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\t$\\mu\\mu < \\mu_0$\t& $ t \\leq -t^c_{1-\\alpha,df} $\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table} \t\t\n\\end{itemize}\n\n\\subsubsection{Paired Sample T-test}\n\\begin{itemize}\n\t\\item Requirements: \\textbf{2 samples, $\\sigma$ unknown, dependent}\n\t\n\teg: means obtained in 2 conditions(time,places,etc.) by a single group of participants\n\t\\item Distribution: \\textbf{T-Distribution}\n\t\\item Test of relationship between 2 linked samples (eg: Difference)\n\t\\item Degree of Freedom($df$): $$df = n -1 $$\n\t\\item Example null hypothesis: $ H_0: \\mu_d = \\mu_1 - \\mu_2 = \\Delta_0$\n\t\\item test statistic: \n\t\\large{$$t = \\frac{\\bar{d} - \\Delta_0}{\\frac{s}{\\sqrt{n}}}$$}\n\t\\item critical value: $t^c_{1-\\frac{\\alpha}{2}, df}$ / $t^c_{1-\\alpha, df}$\n\t\\item $H_0$ Rejection Region/ $H_1$ Acceptance Region:\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$H_1$ \t\t\t\t& Rejection Region\t\t\t\t\t& test variant \\\\ \\hline\n\t\t\t\t$\\mu_d \\neq \\Delta_0$\t& $|t| \\geq t^c_{1-\\frac{\\alpha}{2}, df}$\t& two-sided                 \\\\ \\hline\n\t\t\t\t$\\mu_d > \\Delta_0$\t& $ t \\geq t^c_{1-\\alpha, df}$\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\t$\\mu_d < \\Delta_0$\t& $ t \\leq -t^c_{1-\\alpha,df} $\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table} \t\n\\end{itemize}\n\n\\subsubsection{Independent T-Test/ Welch-Test}\n\\begin{itemize}\n\t\\item Requirements: \\textbf{2 samples, $\\sigma$ unknown, independent}\n\t\n\teg: credit card debt difference between urban and rural households/ shopping expenses between male and female\n\t\\item Distribution: \\textbf{T-Distribution}\n\t\\item Test of relationship between 2 independent samples (doesn't need to be same size)\n\t\\item Degree of Freedom($df$): round to \\textbf{nearest integer} number\n\t\\large{$$df = \\dfrac{(\\frac{s_1^2}{n_1} + \\frac{s_2^2}{n_2})^2}{\\frac{(\\frac{s_1^2}{n_1})^2}{n_1 -1} + \\frac{(\\frac{s_2^2}{n_2})^2}{n_2 -1}}$$} \n\t\\item test statistic:\n\t\\large{$$t = \\frac{(\\bar{x}_1 - \\bar{x}_2) - \\mu_0}{s_{\\bar{x}_1 -\\bar{x}_2}}$$}\n\t\\large{$$s_{\\bar{x}_1 -\\bar{x}_2} = \\sqrt{\\frac{s_1^2}{n_1} + \\frac{s_2^2}{n_2}}$$}\n\t\\item $H_0$ Rejection Region/ $H_1$ Acceptance Region:\n\t\\begin{table}[H]\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$H_1$ \t\t\t\t& Rejection Region\t\t\t\t\t& test variant \\\\ \\hline\n\t\t\t\t$\\mu_d \\neq \\Delta_0$\t& $|t| \\geq t^c_{1-\\frac{\\alpha}{2}, df}$\t& two-sided                 \\\\ \\hline\n\t\t\t\t$\\mu_d > \\Delta_0$\t& $ t \\geq t^c_{1-\\alpha, df}$\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\t$\\mu_d < \\Delta_0$\t& $ t \\leq -t^c_{1-\\alpha,df} $\t\t\t& one-sided                  \\\\ \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\t\\end{table} \n\t\\item Confidence Interval of both samples: if both confidence intervals overlap each other $\\rightarrow$ \\textbf{cannot reject} $H_0$\n\\end{itemize}\n\\subsubsection{Using Confidence Intervals in Significance Tests}\nFind confidence intervals for $\\mu_x$, which -- under $H_0$ -- contains the true value $\\mu_x$ with a probability of at least $1 - \\alpha$: \n\\begin{itemize}\n\t\\item $\\sigma$ known: \\textbf{Normal Distribution}\n\t$$CI = [\\bar{x} - z^c_{(1-\\frac{\\alpha}{2})} \\cdot \\frac{\\sigma}{\\sqrt{n}}, \\bar{x} + z^c_{(1-\\frac{\\alpha}{2})} \\cdot \\frac{\\sigma}{\\sqrt{n}}]$$\n\t\\item $\\sigma$ unknown: \\textbf{t-Distribution}\n\t$$CI = [\\bar{x} - t^c_{(1-\\frac{\\alpha}{2}, n-1)} \\cdot \\frac{s}{\\sqrt{n}}, \\bar{x} + t^c_{(1-\\frac{\\alpha}{2}, n-1)} \\cdot \\frac{s}{\\sqrt{n}}]$$\n\\end{itemize}\t\nConclusion:\n\\begin{itemize}\n\t\\item Accept $H_0$: if $\\mu_0$ lies \\textbf{within} the confidence interval\n\t\\item Rejection $H_0$: if $\\mu_0$ lies \\textbf{outside} the confidence interval\n\\end{itemize}\n\n\\subsubsection{Other Tests}\n\\begin{itemize}\n\t\\item Parametric Tests: eg: T-tests,  F-test(comparing variance of 2 samples)\n\t\\item Non-parametric Tests: eg: Wilcoxon signed-rank test(2 paired i.i.d. samples), Mann-Whitney-U test(2 independent i.i.d. samples)\n\t\\item Test of Probability Distribution: Kolmogorov-Smirnov test, Chi-square test\n\\end{itemize}\n\n\\section{Description of a Dataset}\n\\begin{itemize}\n\t\\item \\textbf{Dependent} and \\textbf{independent} variables\n\t\\item Scales of measurement of the variables \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.8\\textwidth]{scale_measurement.jpg}\n\t\\end{figure}\n\t\\begin{itemize}\n\t\t\\item \\textbf{Nominal}: \\textbf{categorical} variable scale. A scale used for labeling variables into distinct classifications, \\textbf{doesn't involve quantitative value or order. }\n\t\t\\begin{itemize}\n\t\t\t\\item eg: Gender, City, Nationality, Jobs\n\t\t\\end{itemize}\n\t\t\\item \\textbf{Ordinal}: scale to depict \\textbf{order} of the variables for non-mathematical ideas. It maintains a \\textbf{descriptional} quality and the \\textbf{difference between variables can't be calculated}. \n\t\t\\begin{itemize}\n\t\t\t\\item eg: Frequency(high, medium, low), Happiness, Satisfaction, Pain level, Cloth size (S, M, L), rank of Unis\n\t\t\\end{itemize}\n\t\t\\item \\textbf{Interval}: numeric scale where \\textbf{order} of the variables as well as the \\textbf{difference between variables are known}. There exists \\textbf{no true 0}. Variables can be added and subtracted, but \\textbf{not multiplied or divided}. \n\t\t\\begin{itemize}\n\t\t\t\\item eg: GPA, GRE, Celsius, Fahrenheit (20$^\\circ$C is 10$^\\circ$C higher than 10$^\\circ$C, it doesn't mean 2 times warmer.)\n\t\t\\end{itemize}\n\t\t\\item \\textbf{Ratio}: numeric scale that's ordered, difference between variables known, and there \\textbf{exists true 0}. Variables can be added, subtracted, multiplied and divided.\n\t\t\\begin{itemize}\n\t\t\t\\item eg: weight, height, time, Kelvin temperature, money\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\\item \\textbf{Cross-sectional, time series, panel data} (see 7.1.5)\n\\end{itemize}\n\n\n%\\section{Summary of Possible Exam Questions}\n%\\begin{itemize}\n%\t\\item Calculation of arithmetic weighted mean of sample $\\bar{X}$, variance $\\sigma^2$ of the sample, standard deviation $\\sigma$ of the sample.\n%\t\\item Calculation of variance/standard deviation of the sample mean $\\sigma_{\\bar{X}}^2$/$\\sigma_{\\bar{X}}$\n%\t\\item Standardization of a normal distribution \n%\t\\item Calculation of probability, find values from pdf or cdf table \n%\t\\item independent, identically distributed sample points (i.i.d.)\n%\t\\item Performance of Significance Test according to requirements\n%\t\\item p-value: Interpretation when to reject $H_0$ ($p < \\alpha$)\n%\t\\item description of dataset\n%\\end{itemize}\n", "meta": {"hexsha": "15d2c9f88ca33b8619bdc2d76fe6b5ca39ca654b", "size": 20086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/introduction.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/introduction.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/introduction.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.8272921109, "max_line_length": 295, "alphanum_fraction": 0.6787314547, "num_tokens": 6677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.6386146224854996}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Partial Fractions}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to partial fractions and integration.\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. Do not forget absolute value signs inside logarithms when they are needed.\n\n\\begin{exercise}%[APEX0604PF07]\n\\[ \\frac{7x+7}{x^2+3x-10} = \\frac{\\answer{3}}{x-2} + \\frac{\\answer{4}}{x+5} \\]\n\\[ \\int \\frac{7x+7}{x^2+3x-10}\\ dx = \\answer{3 \\ln |x-2|+4 \\ln |x+5|}+C\\]\n(Do not include any constant terms in your antiderivative.)\n%%\n%%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0604PF08]\n\\[ \\int \\frac{7x-2}{x^2+x}\\ dx = \\answer{9 \\ln |x+1|-2 \\ln |x|}+C\\]\n(Do not include any constant terms in your antiderivative.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0604PF11]\n\\[ \\frac{x+7}{(x+5)^2} = \\frac{\\answer{1}}{x+5} + \\frac{\\answer{2}}{(x+5)^2} \\]\n\\[ \\int \\frac{x+7}{(x+5)^2}\\ dx = \\answer{\\ln |x+5|-\\frac{2}{x+5}}+C\\]\n(Do not include any constant terms in your antiderivative.)\n%\n%\n\\end{exercise}\n\n\n\\begin{exercise}%[APEX0604PF13]\n\\[ \\int \\frac{9x^2+11x+7}{x(x+1)^2}\\ dx = \\answer{\\frac{5}{x+1}+7 \\ln |x|+2 \\ln |x+1|}+C\\]\n(Do not include any constant terms in your answer.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0604PF16]\n\\[ \\int \\frac{x^2+x+1}{x^2+x-2}\\ dx = \\answer{x+\\ln |x-1|-\\ln |x+2|}+C \\]\n(Do not include any constant terms in your answer.)\n\\begin{hint}\nDon't forget polynomial long division; it is needed in this case because the degree of the numerator is at least as large as the degree of the denominator.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0604PF20]\n\\[ \\int \\frac{x^2+x+5}{x^2+4x+10}\\ dx = \\answer{-\\frac{3}{2} \\ln \\left|x^2+4 x+10\\right|+x+\\frac{\\arctan \\left(\\frac{x+2}{\\sqrt{6}}\\right)}{\\sqrt{6}}}+C \\]\n(Do not include any constant terms in your answer.)\n\\begin{hint}\n\\[ \\frac{x^2+x+5}{x^2+4x+10} = \\answer{1} + \\frac{\\answer{-3} x + \\answer{-5}}{x^{2} + 4 x + 10}  \\]\nSince the derivative of the denominator is $2x + 4$, we should rewrite the numerator of the big fraction to have $x+2$'s if possible:\n\\[  \\frac{x^2+x+5}{x^2+4x+10} = \\answer{1} + \\frac{\\answer{-3}(x+2) + \\answer{1}}{x^2 + 4x + 10}. \\]\nFor expressions like\n\\[ \\int \\frac{x+2}{x^2 +4x+10} dx \\]\nwe should do a substitution. For terms like\n\\[ \\int \\frac{1}{x^2 + 4x + 10} dx \\]\nwe should first complete the square: $x^2 + 4x + 10 =  (x + 2)^2 + 6$ and then make the substitution $x + 2 = u \\sqrt{6}$.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0604PF23]\n\\[ \\int \\frac{2x^2+x+1}{(x+1)(x^2+9)}\\ dx = \\answer{\\frac{9}{10} \\ln \\left|x^2+9\\right|+\\frac{1}{5} \\ln |x+1|-\\frac{4}{15} \\arctan \\left(\\frac{x}{3}\\right)} +C\\]\n(Do not include any constant terms in your answer.)\n%\n%\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[PartialFracHeav001v2]\n\nCompute the integral\n\\[\\int_{3}^{4}\\frac{2x-3}{x^2-3x+2}~dx.\\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\ln 2\\)}\n\\choice[correct]{\\(\\displaystyle \\ln 3\\)}\n\\choice{\\(\\displaystyle \\ln 4\\)}\n\\choice{\\(\\displaystyle \\ln 5\\)}\n\\choice{\\(\\displaystyle \\ln 6\\)}\n\\choice{\\(\\displaystyle \\ln 7\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst factor the denominator of the integrand: \\(x^2-3x+2 = (x-1)(x-2)\\). Since the roots are distinct, it is possible to use the Heaviside cover-up method.  \\begin{hint} The partial fractions expansion will take the form \\[\\frac{A}{x-1} + \\frac{B}{x-2}, \\] where the coefficient \\(A\\) can be computed by cancelling the factor of \\(x-1\\) in the denominator and evaluating the result at \\(x = 1\\), i.e., \\[A = \\frac{2(1)-3}{(1)-2} = 1. \\] Similarly, \\[B = \\frac{2(2)-3}{(2)-1} = 1,\\] which gives that \\[\\frac{2x-3}{(x-1)(x-2)} = \\frac{1}{x-1} + \\frac{1}{x-2}. \\] \\begin{hint} Therefore\n\\[ \\begin{aligned} \n\\int_{3}^{4}\\frac{2x-3}{x^2-3x+2}~dx & = \\int_{3}^{4}\\left(\\frac{1}{x-1} + \\frac{1}{x-2}\\right)~dx \\\\\n & = \\left(\\ln |4-1| + \\ln |4-2| \\right) - \\left(\\ln |3-1| + \\ln |3-2| \\right)\\\\\n & = \\ln 3 + \\ln 2 + \\ln \\frac{1}{2} + 0 = \\ln 3.\\end{aligned}\\] \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2019WrittenByClass01]\nCompute the volume of the solid of revolution obtained by revolving around the $y$-axis the region below the graph\n\\[ y = \\frac{1}{(x-1)^2}, \\]\nabove $y=0$, and between $x=2$ and $x=3$.\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\pi\\)}\n\\choice{\\(\\displaystyle \\pi ( \\ln 2 + 3)\\)}\n\\choice[correct]{\\(\\displaystyle \\pi (2 \\ln 2 + 1)\\)}\n\\choice{\\(\\displaystyle \\pi (2 \\ln 3 + 1)\\)}\n\\choice{\\(\\displaystyle \\pi (3 \\ln 2 + 1)\\)}\n\\choice{\\(\\displaystyle \\pi (3 \\ln 3 + 1)\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nChoosing $x$ as the variable of integration, slices will be parallel to the $y$-axis, indicating that the shell method should be used. The radius of a shell is $x$ (because the axis lies to the left of the region) and the height will be $(x-1)^{-2}$, so \n\\[ V = \\int_2^3 \\frac{2 \\pi x}{(x-1)^2} dx = 2 \\pi \\int_2^3 \\frac{x}{(x-1)^2} dx. \\] \\begin{hint}\nThe integral can be computed by partial fractions; the expansion has the form\n\\[ \\frac{x}{(x-1)^2} = \\frac{A}{x-1} + \\frac{B}{(x-1)^2}. \\]\nThe coefficients $A$ and $B$ can be found by usual methods (but note that the Heaviside cover up method will \\textit{not} work in this case), but it is also possible to find them directly by carefully rewriting the numerator of the fraction in terms of $x-1$:\n\\[ \\frac{x}{(x-1)^2} = \\frac{(x-1) + 1}{(x-1)^2} = \\frac{(x-1)}{(x-1)^2} + \\frac{1}{(x-1)^2} = \\frac{1}{x-1} + \\frac{1}{(x-1)^2}. \\]\nTherefore\n\\[ \\begin{aligned} V & = 2 \\pi \\int_2^3 \\left[ \\frac{1}{x-1} + \\frac{1}{(x-1)^2} \\right] dx = 2 \\pi \\left. \\left[ \\ln |x-1| - \\frac{1}{x-1} \\right] \\right|_{2}^3 \\\\\n& = 2 \\pi \\left( \\ln 2 - \\frac{1}{2} \\right) - 2 \\pi \\left( 0 - 1 \\right) = \\pi(2 \\ln 2 + 1). \\end{aligned}\\] \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.04]\n\nCompute the constants \\(A\\) and \\(B\\) in the partial fractions expansion indicated below. \\offline{To receive full credit, it is not necessary to compute \\(C, D,\\) or \\(E\\).}\n\\[ \\frac{x^4 + 16}{x^4 - 16} =A +  \\frac{B}{x-2} + \\frac{C}{x+2} + \\frac{Dx + E}{x^2 + 4} \\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(A=-1, B=1\\)}\n\\choice{\\(A = 0, B = 1\\)}\n\\choice[correct]{\\(A = 1, B = 1\\)} \n\\choice{\\(A=-1, B=-1\\)}\n\\choice{\\(A = 0, B = -1\\)}\n\\choice{\\(A = 1, B = -1\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nYou'll need to do polynomial long division first. To compute $B$, you can use Heaviside cover-up.\n\\begin{hint}\n\\[  \\frac{x^4 + 16}{x^4 - 16} = 1 + \\frac{1}{x-2} - \\frac{1}{x+2} - \\frac{4}{x^2+4} \\]\n\\end{hint}\n\\end{feedback}\n\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.04]\n\nEvaluate \\(\\displaystyle \\int_1^2 \\frac{x^2+x+1}{x^2+x} dx\\).\n\\begin{multiplechoice}\n\\choice{\\(0\\)}\n\\choice{\\(1\\)}\n\\choice[correct]{\\(\\displaystyle 1 + \\ln \\left(\\frac{4}{3}\\right)\\)}\n\\choice{\\(2\\)}\n\\choice{\\(\\displaystyle 2 + \\ln \\left(\\frac{8}{3}\\right)\\)}\n\\choice{none of these}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "cd22679067f189c06c76d3b25006023eabc08b19", "size": 7360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "techniques/12partialfractionspractice.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/12partialfractionspractice.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/12partialfractionspractice.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": 42.0571428571, "max_line_length": 584, "alphanum_fraction": 0.6315217391, "num_tokens": 2862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6386145200198188}}
{"text": "\\subsection{Modules}\\label{subsec:modules}\n\n\\begin{definition}\\label{def:left_module}\n  Let \\( R \\) be a \\hyperref[def:semiring/dioid]{dioid} and \\( M \\) be an abelian group. Analogously to \\fullref{def:left_monoid_action}, we say that \\( M \\) is a left \\( R \\)-\\term{module} if it has some additional structure, which can be defined equivalently as\n  \\begin{thmenum}\n    \\thmitem{def:left_module/homomorphism} a dioid homomorphism from \\( R \\) to the endomorphism \\hyperref[def:endomorphism_dioid]{ring} \\( \\End(M) \\)\n\n    \\thmitem{def:left_module/multiplication}\\cite[374]{Knapp2016BasicAlgebra} an \\hyperref[def:magma/associative]{associative} and \\hyperref[def:unital_magma]{unital} \\hyperref[def:left_monoid_action/operation]{operation} \\( \\cdot: R \\times M \\to M \\), written using juxtaposition.\n\n    We require that \\( \\cdot \\) is associative, distributive over \\( + \\), and compatible with the identity in \\( R \\). Explicitly, the following are satisfied for \\( x, y \\in M \\) and \\( s, t \\in R \\):\n    \\begin{thmenum}\n      \\thmitem{def:left_module/associativity}(associativity) \\( s \\cdot (t \\cdot x) = (s t) \\cdot x \\).\n      \\thmitem{def:left_module/scalar_distributivity}(scalar distributivity) \\( (s + t) \\cdot x = s \\cdot x + t \\cdot x \\).\n      \\thmitem{def:left_module/vector_distributivity}(vector distributivity) \\( t \\cdot (x + y) = t \\cdot x + t \\cdot y \\).\n      \\thmitem{def:left_module/identity}(identity) \\( 1_R \\cdot x = x \\).\n    \\end{thmenum}\n  \\end{thmenum}\n\n  In analogy with \\hyperref[def:vector_space]{vector spaces}, we call elements of \\( R \\) scalars and elements of \\( M \\) vectors. See \\fullref{def:vector_space}.\n\n  We denote the category of modules over \\( R \\) by \\( \\cat{Mod}_R \\).\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:left_module/homomorphism}{def:left_module/multiplication} Let \\( \\tau: R \\to \\End(M) \\) be a ring homomorphism. Define the operation\n  \\begin{balign*}\n     & \\cdot: R \\times M \\to M           \\\\\n     & \\cdot(r, m) \\coloneqq \\tau(r)(m).\n  \\end{balign*}\n\n  Let \\( x, y \\in M \\) and \\( s, t \\in R \\). From the fact that \\( \\tau \\) is a ring homomorphism, we have\n  \\SubProofOf{def:left_module/associativity}\n  \\begin{equation*}\n    s \\cdot (t \\cdot x)\n    =\n    \\tau(s)(\\tau(t)(x))\n    =\n    (\\tau(s) \\circ \\tau(t))(x)\n    =\n    \\tau(st)(x).\n  \\end{equation*}\n\n  \\SubProofOf{def:left_module/scalar_distributivity}\n  \\begin{equation*}\n    (s + t) \\cdot x\n    =\n    \\tau(s + t)(x)\n    =\n    \\tau(s)(x) + \\tau(t)(x)\n    =\n    s \\cdot x + t \\cdot x.\n  \\end{equation*}\n\n  \\SubProofOf{def:left_module/vector_distributivity}\n  \\begin{equation*}\n    t \\cdot (x + y)\n    =\n    \\tau(t)(x + y).\n  \\end{equation*}\n\n  Now since \\( \\tau(t) \\) is a group endomorphism, we have \\( \\tau(t)(x + y) = \\tau(t)(x) + \\tau(t)(y) \\). Thus,\n  \\begin{equation*}\n    t \\cdot (x + y)\n    =\n    t \\cdot x + t \\cdot y.\n  \\end{equation*}\n\n  \\SubProofOf{def:left_module/identity}\n  \\begin{equation*}\n    1_R \\cdot x\n    =\n    \\tau(1_R)(x)\n    =\n    \\id(x)\n    =\n    x.\n  \\end{equation*}\n\n  \\ImplicationSubProof{def:left_module/multiplication}{def:left_module/homomorphism} Let \\( \\cdot: R \\times M \\to M \\) be a left scalar multiplication operation. We define\n  \\begin{balign*}\n     & \\tau: R \\to \\End(M)                      \\\\\n     & \\tau(t) \\coloneqq (x \\mapsto t \\cdot x).\n  \\end{balign*}\n\n  This function is well-defined since for each \\( t \\in R \\), the function \\( \\tau(t) \\) is an abelian group homomorphism (due to \\fullref{def:left_module/associativity}).\n\n  \\( \\tau \\) is a ring homomorphism because\n  \\begin{itemize}\n    \\item it preserves addition:\n          \\begin{equation*}\n            \\tau(s + t)\n            =\n            (x \\mapsto (s + t) \\cdot x)\n            =\n            (x \\mapsto s \\cdot x + t \\cdot x)\n            =\n            \\tau(s) + \\tau(t).\n          \\end{equation*}\n\n    \\item it preserves multiplication:\n          \\begin{equation*}\n            \\tau(st)\n            =\n            (x \\mapsto (st) \\cdot x)\n            =\n            (x \\mapsto (s \\cdot (t \\cdot x)))\n            =\n            \\tau(s) \\circ \\tau(t).\n          \\end{equation*}\n\n    \\item it preserves identities:\n          \\begin{equation*}\n            \\tau(1_R)\n            =\n            \\id,\n          \\end{equation*}\n          which is the multiplicative unit in \\( \\End(M) \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\\label{def:right_module}\n  We say that \\( \\tau: R \\to \\End(A) \\) is a \\term{right \\( R \\)-module} if the same function is a \\hyperref[def:left_module]{left module} on the opposite \\hyperref[def:opposite_ring]{ring} \\( R^{-1} \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:bimodule}\n  An abelian group \\( M \\) that is both a left \\( L \\)-module and right \\( R \\)-module is called an \\( L, R \\)-\\term{bimodule} if \\( l \\in L, r \\in R \\) and \\( x \\in M \\) implies\n  \\begin{equation*}\n    (lx)r = l(xr).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:left_module/properties}\n  Any left \\( R \\)-module \\( M \\) has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:left_module/properties/ring_zero_is_absorbing} Multiplication by \\( 0_R \\) is \\term{absorbing}, that is, \\( 0_R x = 0_M \\) for any \\( x \\in M \\).\n\n    \\thmitem{thm:def:left_module/properties/module_zero_is_absorbing} Multiplication by \\( 0_M \\) is absorbing, that is, \\( t 0_M = 0_M \\) for any \\( t \\in R \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:left_module/properties/ring_zero_is_absorbing} For any \\( x \\in M \\) we have that \\( 0_R x = (0_R + 0_R)x = 0_R x + 0_R x \\), thus \\( 0_R x \\) is an additive identity and \\( 0_R x = 0_M \\).\n\n  \\SubProofOf{thm:def:left_module/properties/module_zero_is_absorbing} For any \\( t \\in R \\) we have that \\( t 0_M = t (0_M + 0_M) = t 0_M + t 0_M \\), thus \\( t 0_M \\) is an additive identity and \\( t 0_M = 0_M \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:module/ideal_of_ring}\n  Every unital ring \\( R \\) is a module over itself. Every ideal \\( I \\subseteq R \\) is an \\( R \\)-module since it is closed under multiplication with \\enquote{scalars} from \\( R \\).\n\\end{example}\n\n\\begin{definition}\\label{def:left_module_kernel}\n  The \\term{kernel} \\( \\ker(f) \\) of a left \\( R \\)-module homomorphism \\( f: M \\to N \\) is the \\hyperref[def:zero_locus]{zero locus} of \\( f \\), that is, \\hyperref[thm:def:function/properties/preimage]{preimage} \\( f^{-1}(0_N) \\).\n\n  It is an instance of \\fullref{def:zero_morphisms/kernel}.\n\\end{definition}\n\n\\begin{definition}\\label{def:quotient_left_module}\n  Let \\( M \\) be a left module and \\( N \\) be a submodule of \\( M \\). Define the \\term{quotient module}\n  \\begin{equation*}\n    M / N \\coloneqq \\{ x + N \\colon x \\in M \\}\n  \\end{equation*}\n  with the operations\n  \\begin{balign*}\n    x + N \\oplus y + N \\coloneqq x + y + N.\n    t \\odot x + N \\coloneqq tx + N.\n  \\end{balign*}\n\n  Define the canonical projection homomorphism\n  \\begin{balign*}\n     & \\pi: G \\to G / N        \\\\\n     & \\pi(x) \\coloneqq x + N.\n  \\end{balign*}\n\n  The kernel of \\( \\pi \\) is precisely \\( N \\).\n\\end{definition}\n\\begin{proof}\n  The proof of correctness is similar to \\fullref{def:quotient_group}.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:homomorphism_theorem_for_left_modules}\n  Fix a ring \\( R \\). Let \\( \\varphi: M \\to K \\) be a homomorphism of left \\( R \\)-modules. We have the isomorphism\n  \\begin{equation*}\n    M / \\ker \\varphi \\cong \\img \\varphi.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  Analogous to \\fullref{thm:homomorphism_theorem_for_groups}.\n\\end{proof}\n\n\\begin{definition}\\label{def:linear_operator}\n  Let \\( M \\) and \\( N \\) be two left \\( R \\)-modules. We say that the function \\( f: M \\to N \\) is \\term{linear} or a \\term{linear operator} if it satisfies the conditions\n  \\begin{thmenum}\n    \\thmitem{def:linear_operator/additivity}(additivity) \\( f(x + y) = f(x) + f(y) \\) for any \\( x, y \\in M \\).\n    \\thmitem{def:linear_operator/homogeneity}(homogeneity) \\( f(tx) = t f(x) \\) for any \\( t \\in R \\) and \\( x \\in M \\) (see \\fullref{def:homogenous_function}).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:map_is_linear_iff_homomorphism}\n  A function \\( f: M \\to N \\) between left \\( R \\)-modules is \\hyperref[def:linear_operator]{linear} if and only if it is a module homomorphism in the sense of \\fullref{def:first_order_homomorphism}.\n\\end{proposition}\n\\begin{proof}\n  Since \\( (M, +) \\) and \\( (N, +) \\) are groups, it follows from \\fullref{thm:group_homomorphism_single_condition} that \\fullref{def:linear_operator/additivity} is equivalent to the requirement that \\( f \\) is a homomorphism between \\( (M, +) \\) and \\( (N, +) \\).\n\n  Now fix \\( t \\in R \\). For \\( f \\) to be a homomorphism, it must satisfy\n  \\begin{equation*}\n    f(\\cdot_M^{(t)}(x)) = \\cdot_t^{(N)}(f(x)),\n  \\end{equation*}\n  which is just a more formal way to write \\fullref{def:linear_operator/homogeneity}.\n\\end{proof}\n\n\\begin{definition}\\label{def:affine_operator}\n  Let \\( M \\) and \\( N \\) be two left \\( R \\)-modules. We say that the function \\( f: M \\to N \\) is \\term{affine} if it is a translation of a \\hyperref[def:linear_operator]{linear function}, that is, if there exists a linear function \\( l: M \\to N \\) and a constant \\( a \\in N \\) such that \\( f(x) = l(x) + a \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:multilinear_function}\n  Generalizing \\fullref{def:linear_operator}, if \\( M_1, \\ldots, M_k \\) and \\( N \\) are \\( R \\)-modules, we say that the function\n  \\begin{equation*}\n    f: M_1 \\times \\ldots \\times M_k \\to N\n  \\end{equation*}\n  is \\term{multilinear} or \\term{\\( k \\)-linear} (\\term{bilinear} for \\( k = 2 \\), \\term{trilinear} for \\( k = 3 \\)) if it is linear in each component, that is, for each component \\( i = 1, \\ldots, k \\), and for each tuple not containing elements from \\( M_i \\),\n  \\begin{equation*}\n    (u_1, \\ldots, u_{i-1}, u_{i+1}, \\ldots, u_k) \\in M_1 \\times \\ldots \\times M_{i-1} \\times M_{i+1} \\times \\ldots \\times M_k \\to N\n  \\end{equation*}\n  the following function is linear:\n  \\begin{balign*}\n     & f_i: M_i \\to N                                                         \\\\\n     & f_i(u_i) \\coloneqq f(u_1, \\ldots, u_{i-1}, u_i, u_{i+1}, \\ldots, u_k).\n  \\end{balign*}\n\\end{definition}\n\n\\begin{definition}\\label{def:abelian_group_z_module}\\mcite[375]{Knapp2016BasicAlgebra}\n  Let \\( G \\) be an abelian group. Associate with \\( G \\) the \\( \\BbbZ \\)-module \\( M \\) with scalar multiplication\n  \\begin{balign*}\n    nu \\coloneqq \\begin{cases}\n      0,              & n = 0  \\\\\n      u + \\ldots + u, & n > 0  \\\\\n      -((-n)u),       & n < 0.\n    \\end{cases}\n  \\end{balign*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:abelian_group_iff_z_module}\\mcite[375]{Knapp2016BasicAlgebra}\n  Every abelian group is isomorphic to exactly one \\( \\BbbZ \\)-module.\n\\end{proposition}\n\\begin{proof}\n  We already saw in \\fullref{def:abelian_group_z_module} how every abelian group can be regarded as a \\( \\BbbZ \\)-module. Every \\( \\BbbZ \\)-module can then be identified with its additive group.\n\n  Scalar multiplication ensures that there is exactly one way to define a \\( \\BbbZ \\)-module structure on an abelian group since \\( na = (n-1)a + a \\) and \\( 0a = 0 \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:left_module_direct_product}\n  Let \\( \\{ X_k \\}_{k \\in \\mscrK} \\) be a nonempty family of left \\( R \\)-modules.\n\n  Analogously to \\fullref{def:group_direct_product}, we define their \\term{direct product} as the module \\( \\prod_{k \\in \\mscrK} X_k \\), the operations defined componentwise as\n  \\begin{balign*}\n     & \\{ x_k \\}_{k \\in \\mscrK} + \\{ y_k \\}_{k \\in \\mscrK}\n    \\coloneqq\n    \\{ x_k + y_k \\}_{k \\in \\mscrK},                     \\\\\n     & t \\{ x_k \\}_{k \\in \\mscrK}\n    \\coloneqq\n    t \\{ t x_k \\}_{k \\in \\mscrK}.\n  \\end{balign*}\n\n  We define their \\term{direct sum} as the submodule of \\( \\prod_{k \\in \\mscrK} X_k \\) (see \\fullref{def:left_module_direct_product}) where only finitely many components of any module element are different from zero.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:module_categorical_limits}\n  We are interested in \\hyperref[def:category_of_cones/limit]{categorical limits} and \\hyperref[def:category_of_cones/colimit]{colimits} in the category \\( \\cat{Mod}_R \\) of left-modules over \\( R \\). Fix an indexed family  \\( \\{ X_k \\}_{k \\in \\mscrK} \\) of \\( R \\)-modules.\n  \\begin{thmenum}\n    \\thmitem{thm:module_categorical_limits/product} Their \\hyperref[def:discrete_category_limits]{categorical product} is their direct \\hyperref[def:left_module_direct_product]{product} \\( \\prod_{k \\in \\mscrK} X_k \\), the projection morphisms being inherited from \\fullref{thm:discrete_category_limits_in_set}.\n\n    \\thmitem{thm:module_categorical_limits/coproduct} Their \\hyperref[def:discrete_category_limits]{categorical coproduct} is the \\hyperref[def:group_direct_product]{direct sum} \\( \\oplus_{k \\in \\mscrK} X_k \\), the embedding morphisms being inherited from \\fullref{thm:abelian_group_categorical_limits/coproduct}.\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{definition}\\label{def:linear_combination}\n  Let \\( M \\) be a left \\( R \\)-module. Like \\hyperref[def:polynomial]{polynomials}, we define linear combinations to be tuples \\( (t_1, t_2, \\ldots, t_n) \\) of scalars from \\( R \\). Unlike with polynomials, we are not interested in defining operations on them, but rather defining the function\n  \\begin{equation}\\label{def:linear_combination/function}\n    (x_1, \\ldots, x_n) \\mapsto \\sum_{k=1}^n t_k x_k.\n  \\end{equation}\n\n  The scalars \\( t_1, \\ldots, t_n \\) are called the \\term{coefficients} of the linear combination. A linear combination is said to be \\term{trivial} if all coefficients are equal to \\( 0_R \\).\n\n  For convenience, given set of vectors \\( x_1, \\ldots, x_n \\in M \\), we also call the sum \\( \\sum_{k=1}^n t_k x_k \\) a linear combination.\n\n  In the special case where \\( R \\) is a superring of \\( \\BbbR \\), we define the following special types of linear combinations:\n  \\begin{thmenum}\n    \\thmitem{def:linear_combination/affine} an \\term{affine combination} if \\( \\sum_{k=1}^n t_k = 1 \\).\n    \\thmitem{def:linear_combination/conic} a \\term{conic combination} if all of the coefficients are nonnegative real numbers.\n    \\thmitem{def:linear_combination/convex} a \\term{convex combination} if it is both affine and conic.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:left_module_linear_dependence}\n  Let \\( M \\) be a left \\( R \\)-module and let \\( A \\subseteq M \\). We say that the set \\( A \\) is \\term{linearly independent} if for any linear \\hyperref[def:linear_combination/function]{combination}, the equality\n  \\begin{equation*}\n    \\sum_{i=1}^n t_i x_k = 0_M\n  \\end{equation*}\n  for \\( x_1, \\ldots, x_n \\in A \\) implies that the combination is trivial.\n\n  We say that the vectors \\( x_1, \\ldots, x_n \\) are linearly independent if the corresponding set \\( \\{ x_1, \\ldots, x_n \\} \\) is linearly independent.\n\n  We say that \\( A \\) is \\term{linearly dependent} if it is not linearly independent.\n\\end{definition}\n\n\\begin{definition}\\label{def:left_module_hamel_basis}\n  A subset \\( B \\) of the left \\( R \\)-module \\( M \\) is called a \\term{Hamel basis} or simply \\term{basis} of \\( M \\) if \\( B \\) is a \\hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{minimal} (with respect to set inclusion) linearly independent subset of \\( M \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:free_left_module}\\mcite[377]{Knapp2016BasicAlgebra}\n  We say that the left \\( R \\)-module \\( M \\) is a \\term{free left module} if it has a \\hyperref[def:left_module_hamel_basis]{basis}.\n\n  Let \\( S \\) be any set. If we regard \\( R \\) as a left module over itself, then the \\hyperref[thm:module_categorical_limits/coproduct]{direct sum}\n  \\begin{equation*}\n    F(S) \\coloneqq \\oplus_{s \\in S} R\n  \\end{equation*}\n  with injections \\( \\{ \\iota_s \\}_{s \\in S} \\) is called the free left module \\term{generated by \\( S \\)}. Define the function\n  \\begin{balign*}\n     & \\varphi: S \\to F(S)                \\\\\n     & \\varphi(s) \\coloneqq \\iota_s(1_R).\n  \\end{balign*}\n\n  The image \\( \\varphi(S) \\) is then a basis of \\( F(S) \\).\n\n  The cardinality of the basis of a free left module \\( M \\) is called the \\term{rank} \\( \\rank M \\) of \\( M \\). \\Fullref{thm:left_module_basis_cardinality} tells us that this rank is unique for commutative unital rings. If the rank of a module is finite, we say that the module is \\term{finitely generated}.\n\n  We also denote \\( F(S) = \\braket S \\), especially in finitely generated modules.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:free_module_is_free_functor}\n  The functor \\( F: \\cat{Set} \\to \\cat{Mod}_R \\), defined pointwise in \\fullref{def:free_left_module}, is \\hyperref[def:category_adjunction]{free}.\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:left_module_basis_decomposition}\n  Let \\( B \\) be a basis of the free left \\( R \\)-module \\( M \\). Then each element \\( u \\) of \\( M \\) can be uniquely (up to a permutation) represented as a linear \\hyperref[def:linear_combination]{combination} of elements of \\( B \\).\n\\end{proposition}\n\\begin{proof}\n  Let\n  \\begin{equation*}\n    u = \\sum_{i=1}^n t_i v_i\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    u = \\sum_{j=1}^m s_i w_i\n  \\end{equation*}\n  be two representations of \\( u \\) as a linear combination over \\( B \\).\n\n  Define the function\n  \\begin{balign*}\n     & t: M \\to R                                \\\\\n     & t(v) \\coloneqq \\begin{cases}\n      t_i, & v = v_i,                          \\\\\n      0,   & v \\not\\in \\{ v_1, \\ldots, v_n \\}.\n    \\end{cases}\n  \\end{balign*}\n  and analogously for \\( s: M \\to R \\). Define the set\n  \\begin{equation*}\n    B' \\coloneqq \\{ v_1, \\ldots, v_n, w_1, \\ldots, w_m \\}.\n  \\end{equation*}\n\n  Thus,\n  \\begin{equation*}\n    u = \\sum_{b \\in B'} t(b) b = \\sum_{b \\in B'} s(b) b\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    0 = u - u = \\sum_{b \\in B'} (t(b) - s(b)) b.\n  \\end{equation*}\n\n  The set \\( B' \\) is linearly independent as a subset of the basis \\( B \\), hence only a trivial linear combination can be the zero vector. This gives us\n  \\begin{equation*}\n    t(b) = s(b), b \\in B'.\n  \\end{equation*}\n\n  In particular, the two decompositions of \\( u \\) along \\( B \\) are identical up to a permutation.\n\\end{proof}\n\n\\begin{definition}\\label{def:left_module_basis_projection}\n  Let \\( M \\) be a left \\( R \\)-module and let \\( B \\) be a basis of \\( M \\). For each \\( b \\in B \\), we define the \\text{coordinate projection functional} \\( \\pi_b: M \\to R \\) that gives us the unique coefficient in the basis decomposition. Thus, for every \\( x \\in M \\) we have\n  \\begin{equation*}\n    x = \\sum_{b \\in B} \\pi_b(x) b.\n  \\end{equation*}\n\n  The sum is well-defined since only finitely many terms are nonzero.\n\n  When the basis \\( B \\) is finite and ordered:\n  \\begin{equation*}\n    B = \\{ b_1, \\ldots, b_n \\},\n  \\end{equation*}\n  we also write\n  \\begin{equation*}\n    x = \\sum_{i=1}^n x_k b_i.\n  \\end{equation*}\n\\end{definition}\n\\begin{proof}\n  By \\fullref{thm:left_module_basis_decomposition}, this decomposition is unique given a basis \\( B \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:left_module_basis_projections_are_linear}\n  The basis projection \\hyperref[def:left_module_basis_projection]{maps} are linear.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{def:linear_operator/homogeneity} Let \\( t \\in R \\) and \\( x \\in M \\). We have the unique decompositions\n  \\begin{balign*}\n    x  & = \\sum_{b \\in B} \\pi_b(x) b,  \\\\\n    tx & = \\sum_{b \\in B} \\pi_b(tx) b.\n  \\end{balign*}\n\n  Since both decompositions have only finitely many terms, their difference also has only finitely many nonzero terms. Thus,\n  \\begin{equation*}\n    0\n    =\n    tx - tx\n    =\n    t \\left( \\sum_{b \\in B} \\pi_b(x) b \\right) - \\sum_{b \\in B} \\pi_b(tx) b\n    =\n    \\sum_{b \\in B} (t \\pi_b(x) - \\pi_b(tx)) b.\n  \\end{equation*}\n\n  Since the vectors in \\( B \\) are linearly independent, no nontrivial linear combination can equal the zero vector. Thus, for all \\( b \\in B \\),\n  \\begin{equation*}\n    t \\pi_b(x) = \\pi_b(tx).\n  \\end{equation*}\n\n  \\SubProofOf{def:linear_operator/additivity} Analogous.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:linear_map_iff_function_on_basis}\n  Let \\( M \\) and \\( N \\) be left \\( R \\)-modules and let \\( B \\) be a basis of \\( M \\). Then there exists a bijection between the \\hyperref[def:function]{functions} from \\( B \\) to \\( N \\) and the module \\hyperref[def:linear_operator]{homomorphisms} from \\( M \\) to \\( N \\), such that each linear map is an \\hyperref[def:multi_valued_function/restriction]{extension} of the corresponding function.\n\\end{theorem}\n\\begin{proof}\n  Let \\( \\varphi: M \\to N \\) be a homomorphism. Define the function\n  \\begin{balign*}\n     & f: B \\to N                 \\\\\n     & f(b) \\coloneqq \\varphi(b).\n  \\end{balign*}\n\n  Now define the linear map\n  \\begin{balign*}\n     & \\hat \\varphi: M \\to N                                   \\\\\n     & \\hat \\varphi(x) \\coloneqq \\sum_{b \\in B} \\pi_b(x) f(b).\n  \\end{balign*}\n\n  Since the projections \\( \\pi_b(x) \\) are linear functions by \\fullref{thm:left_module_basis_projections_are_linear} and since we only use the value of \\( f \\) on fixed vectors, it follows that \\( \\hat \\varphi \\) is also linear.\n\n  It remains to show that \\( \\varphi = \\hat \\varphi \\). For each \\( x \\in M \\), by linearity of \\( \\varphi \\) we have\n  \\begin{equation*}\n    \\hat \\varphi(x)\n    =\n    \\sum_{b \\in B} \\pi_b(x) f(b)\n    =\n    \\sum_{b \\in B} \\pi_b(x) \\varphi(b)\n    =\n    \\varphi(x).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{remark}\\label{rem:linear_map_iff_function_on_basis}\n  \\Fullref{thm:linear_map_iff_function_on_basis} is very powerful in that is allows to study linear maps given their value at only a small subset of vectors. The connection between multilinear \\hyperref[def:multilinear_function]{maps} and \\hyperref[def:left_module_tensor_product]{tensors} is based on this idea.\n\\end{remark}\n\n\\begin{corollary}\\label{thm:linear_maps_agree_on_free_module_if_they_agree_on_basis}\n  If two linear maps from the free left module \\( M \\) to \\( N \\) agree on a basis of \\( M \\), they agree on the whole module.\n\\end{corollary}\n\n\\begin{proposition}\\label{thm:left_module_basis_cardinality}\\mcite{ProofWiki:bases_of_free_module_have_same_cardinality}\n  All bases in a free left module over a commutative unital ring have the same cardinality.\n\\end{proposition}\n\n\\begin{definition}\\label{def:left_module_tensor_product}\\mcite[574]{Knapp2016BasicAlgebra}\n  Let \\( R \\) be a unital ring. Let \\( M \\) be a right \\( R \\)-module and \\( N \\) be a left \\( R \\)-module. Define the free \\hyperref[def:free_abelian_group]{abelian group} \\( G \\) generated by the basis \\( M \\times N \\), that is,\n  \\begin{equation*}\n    G \\coloneqq \\oplus_{(m,n) \\in M \\times N} \\BbbZ.\n  \\end{equation*}\n\n  Denote by \\( e_{m,n} \\) the \\( (m,n) \\)-th basis vector and by \\( t_{m,n} \\) the \\( (m,n) \\)-th coordinate of \\( t \\in G \\) (we can have only a finite amount of nonzero coordinates since \\( G \\) is a direct sum).\n\n  We can regard \\( G \\) as a left \\( R \\)-module with scalar multiplication given by\n  \\begin{equation*}\n    (r t)_{(m,n)} \\coloneqq t_{(rm,n)}.\n  \\end{equation*}\n\n  Let \\( H \\) be the submodule of \\( G \\) generated by\n  \\begin{itemize}\n    \\item \\( e_{(m_1 - m_2, n)} - e_{(m_1,n)} - e_{(m_2,n)} \\), \\( m_1, m_2, n \\in G \\)\n    \\item \\( e_{(m, n_1 - n_2)} - e_{(m,n_1)} - e_{(m,n_2)} \\), \\( m, n_1, n_2 \\in G \\)\n    \\item \\( e_{(rm,n)} - e_{(m,rn)} \\), \\( m, n \\in G \\) and \\( r \\in R \\)\n  \\end{itemize}\n\n  Define the \\term{tensor product} of \\( M \\) and \\( N \\) to be the \\( R \\)-module\n  \\begin{equation*}\n    M \\otimes N \\coloneqq G / H.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{theorem}\\label{thm:tensor_product_universal_property}\\mcite[thm. 10.18]{Knapp2016BasicAlgebra}\n  Let \\( R \\) be a unital ring. Let \\( M \\) be a right \\( R \\)-module and \\( N \\) be a left \\( R \\)-module and let \\( M \\otimes N \\) be their \\hyperref[def:left_module_tensor_product]{tensor product} with \\( q: M \\times N \\to M \\otimes N \\) being the corresponding quotient map.\n\n  The tensor product \\( M \\otimes N \\) satisfies the following universal mapping property: for every \\( R \\)-module \\( K \\) and any bilinear \\hyperref[def:multilinear_function]{map} \\( f: M \\times N \\to K \\) there exists a unique map \\( \\hat f: M \\otimes N \\to K \\) such that\n  \\begin{equation*}\n    f = \\hat f \\circ q,\n  \\end{equation*}\n  that is, the following diagram commutes:\n\n  \\begin{alignedeq}\\label{thm:tensor_product_universal_property/diagram}\n    \\text{\\todo{Add diagram}}\\iffalse\\begin{mplibcode}\n      beginfig(1);\n      input metapost/graphs;\n\n      v1 := thelabel(\"$M \\times N$\", origin);\n      v2 := thelabel(\"$M \\otimes N$\", (2, 0) scaled u);\n      v3 := thelabel(\"$K$\", (1, -1) scaled u);\n\n      a1 := straight_arc(v1, v2);\n      a2 := straight_arc(v2, v3);\n      a3 := straight_arc(v1, v3);\n\n      draw_vertices(v);\n      draw_arcs(a);\n\n      label.top(\"$q$\", straight_arc_midpoint of a1);\n      label.lrt(\"$\\hat f$\", straight_arc_midpoint of a2);\n      label.llft(\"$f$\", straight_arc_midpoint of a3);\n      endfig;\n    \\end{mplibcode}\\fi\n  \\end{alignedeq}\n\\end{theorem}\n\n\\begin{proposition}\\label{thm:tensor_product_with_underlying_ring}\\mcite[677]{Knapp2016BasicAlgebra}\n  Let \\( R \\) be a unital ring (regarded as a right module) and \\( B \\) be a left \\( R \\)-module. Their \\hyperref[def:left_module_tensor_product]{tensor product} satisfies\n  \\begin{equation*}\n    R \\otimes M \\cong M.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{definition}\\label{def:algebra_over_ring}\\mcite[408]{Knapp2016BasicAlgebra}\n  Let \\( R \\) be a commutative unital ring. We say that the left \\( R \\)-module \\( A \\) is an \\( R \\)-\\term{algebra} if we define an additional bilinear \\term{vector multiplication} operation\n  \\begin{equation*}\n    \\odot: A \\times A \\to A\n  \\end{equation*}\n  such that for \\( x, y \\in M \\) and \\( t \\in R \\)\n  \\begin{equation*}\n    t \\cdot (x \\odot y) = (t \\cdot x) \\odot y = x \\odot (t \\cdot y).\n  \\end{equation*}\n\n  Both vector and scalar multiplication are usually denoted by juxtaposition.\n\n  If \\( \\odot \\) is associative, commutative, unital or invertible, we add this prefix to \\( A \\), e.g. A is a commutative algebra if \\( \\odot \\) is commutative.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:functions_over_ring_form_algebra}\n  Let \\( X \\) be an arbitrary nonempty set and \\( R \\) be a commutative unital ring. Define\n  \\begin{equation*}\n    A \\coloneqq \\cat{Set}(X, R)\n  \\end{equation*}\n  to be the set of all functions from \\( X \\) to \\( R \\) (see \\fullref{def:category_of_small_sets}). Then \\( A \\) is an \\( R \\)-algebra with the operations being defined pointwise, that is,\n  \\begin{balign*}\n    [f + g](x)     & \\coloneqq f(x) + g(x)     \\\\\n    [f \\odot g](x) & \\coloneqq f(x) \\circ g(x) \\\\\n    [rf](x)        & \\coloneqq r f(x)\n  \\end{balign*}\n\n  We call the algebra \\( A \\) the \\term{algebra of functions} from \\( X \\) to \\( R \\).\n\n  If \\( X \\) itself has a ring structure, we consider the set of ring \\hyperref[thm:ring_homomorphism_simpler_conditions]{homomorphisms}\n  \\begin{equation*}\n    \\cat{Ring}(X, R),\n  \\end{equation*}\n  which is usually a strict subset of \\( \\cat{Set}(X, R) \\). This set is usually denoted by \\( \\hom(X, R) \\).\n\n  If \\( R \\) is a module, but not necessarily a ring, then \\( \\cat{Set}(X, R) \\) is a only module since we do not necessarily have multiplication. See \\fullref{def:linear_operator}.\n\\end{proposition}\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{definition}\\label{def:left_module_annihilator}\\mcite[30]{КоцевСидеров2016}\n  Fix a subset \\( S \\subseteq M \\) of a left \\( R \\)-module \\( M \\). We define the \\term{annihilator} of \\( S \\) as the ideal\n  \\begin{equation*}\n    \\op{ann}(S) \\coloneqq \\{ r \\in R \\colon rS = \\{ 0 \\} \\}.\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "c5cbc0498c31347d122052a75c169c0fce01a1ed", "size": 28053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/modules.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/modules.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/modules.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.9538461538, "max_line_length": 398, "alphanum_fraction": 0.6475599758, "num_tokens": 9264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028205, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6386145114394726}}
{"text": "\\chapter[Linear Programming]{Linear Programming}\\label{chp:linear_programming}\n\n\n% Introduction\n\\chapterinitial{F}{inding} the best configuration of some system can be\nchallenging, especially when there is a seemingly endless amount of possible\nsolutions. Optimisation techniques are a way to mathematically derive solutions\nthat maximise or minimise some objective function, subject to a number of\nfeasibility constraints. When all components of the problem can be written in a\nlinear way, then linear programming\\index{linear programming} is one technique\nthat can be used to find the solution.\n\n\\section{Problem}\\label{sec:linear_programming_problem}\n\nA university runs 14 modules over three subjects: Art, Biology, and Chemistry.\nEach subject runs core modules and optional modules.\nTable~\\ref{tab:modules} gives the module numbers for each of these.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lll}\n\\toprule\n\\textbf{Art Core} & \\textbf{Biology Core} & \\textbf{Chemistry Core} \\\\\n\\midrule\nM00 & M05 & M09 \\\\\nM01 & M06 & M10 \\\\\n\\midrule\n\\textbf{Art Optional} & \\textbf{Biology Optional} & \\textbf{Chemistry Optional}\\\\\n\\midrule\nM02 & M07 & M11 \\\\\nM03 & M08 & M12 \\\\\nM04 &     & M13 \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\caption{List of modules on offer at the university.}\n\\label{tab:modules}\n\\end{table}\n\nThe university is required to schedule examinations for each of these modules.\nThe university would like the exams to be scheduled using the least amount of\ntime slots. However not all modules can be scheduled at the same time\nas they share some students:\n\n\\begin{itemize}\n  \\item All art modules share students;\n  \\item all biology modules share students;\n  \\item all chemistry modules share students;\n  \\item biology students have the option of taking optional modules from\n  chemistry, so all biology modules may share students with optional chemistry\n  modules;\n  \\item chemistry students have the option of taking optional modules from\n  biology, so all chemistry modules may share students with optional biology\n  modules;\n  \\item biology students have the option of taking core art modules, and so all\n  biology modules may share students with core art modules.\n\\end{itemize}\n\nHow can every exam be scheduled with no clashes, using the least amount of\ntime slots?\n\n\\section{Theory}\\label{sec:linear_programming_theory}\n\nLinear programming is a method that solves a type of\noptimisation\\index{optimisation} problem of a number of variables by making use\nof some concepts of higher dimensional geometry~\\cite{conforti2014integer}.\nOptimisation here refers to finding the variable that gives either the maximum\nor minimum of some linear function, called the objective function.\n\nLinear programming employs algorithms such as the Simplex\nmethod\\index{Simplex method} to efficiently search some feasible convex\nregion, stopping at the optimum. To do this, an objective function function and\nconstraints need to be defined.\n\nTo illustrate this a classic 2-dimensional example will be used:\n\\(\\pounds 50\\) of profit can be made on each\ntonne of paint A produced, and \\(\\pounds 60\\) profit on each tonne of paint B\nproduced. A tonne of paint A needs 4 tonnes of component X and 5 tonnes of\ncomponent Y. A tonne of paint B needs 6 tonnes of component X and 4 tonnes of\ncomponent Y. Only 24 tonnes of X and 20 tonnes of Y are available per day. How\nmuch of paint A and paint B should be produced to maximise profit?\n\nThis is formulated as a linear objective function, representing total profit,\nthat is to be maximised; and two linear constraints, representing the\navailability of components X and Y. They are written as:\n\n\\begin{align}\n\\text{Maximise: } 50 A + 60 B & \\label{eqn:objective_paint} \\\\\n\\text{Subject to: } & \\nonumber \\\\\n4 A + 6 B &\\leq 24 \\label{eqn:ingredientX} \\\\\n5 A + 4 B &\\leq 20 \\label{eqn:ingredientY}\n\\end{align}\n\nNow this is a linear system in 2-dimensional space with coordinates A and B.\nThese are called the decision variables, what is required are the values of A\nand B that optimises the objective function given by\nexpression~\\ref{eqn:objective_paint}.\n\nInequalities~\\ref{eqn:ingredientX} and~\\ref{eqn:ingredientY} correspond to the\namount of component X and Y available per day. These, along with the additional\nconstraints that a negative amount of paint cannot be produced (\\(A \\geq 0\\) and\n\\(B \\geq 0\\)), form a convex region, shown in Figure~\\ref{fig:paint_lp}.\nThis shaded region shows the pairs of values of \\(A\\) and \\(B\\) which are\nfeasible, that is they satisfy the constraints.\n\n\\begin{figure}\n\\begin{center}\n\\includestandalone[width=\\textwidth]{assets/paint_LP}\n\\end{center}\n    \\caption{Visual representation of the paint linear programming\n    problem. The feasible convex\n    region is shaded in grey; the objective function with arbitrary value is shown\nin a dashed line.}\n\\label{fig:paint_lp}\n\\end{figure}\n\nExpression~\\ref{eqn:objective_paint} corresponds to the total profit, which is\nthe value to be maximised. As a line in 2-dimensional space,\nthis expression fixes its gradient, but its value determines the size of the\n\\(y\\)-intercept. Therefore optimising this function corresponds to pushing a line\nwith that gradient to its furthest extreme within the feasible region,\ndemonstrated in Figure~\\ref{fig:paint_lp}.\nTherefore for this problem the optimum occurs in a particular vertex of the\nfeasible region, at \\(A = \\frac{12}{7}\\) and \\(B = \\frac{20}{7}\\).\n\nThis works well as \\(A\\) and \\(B\\) can take any real value in the feasible region.\nSome problems must be formulated as integer linear\nprogramming\\index{integer linear programming} problems where the decision\nvariables are restricted to integers. There are a number of methods that can\nhelp adapt a real solution to an integer solution. These include cutting\nplanes\\index{cutting planes}, which introduce new constraints around the real\nsolution to force an integer value; and branch and bound\\index{branch and bound}\nmethods, where we iteratively convert decision variables to their closest two\nintegers and remove any infeasible solutions~\\cite{conforti2014integer}.\n\nBoth Python and R have libraries that carry out linear and integer\nprogramming algorithms. When solving these kinds of problems, formulating\nthem as linear systems is the most important challenge.\n\nConsider again the exam scheduling\\index{exam scheduling} problem from\nSection~\\ref{sec:linear_programming_problem} which\nwill now be formulated as an integer linear programming problem.\nDefine \\(M\\) as the set of all modules to be scheduled, and define \\(T\\) as the set\nof possible time slots. At worst each exam is\nscheduled for a different day, thus \\(|T| = |M| = 14\\) in this case.\nLet \\(\\{X_{mt} \\text{ for } m \\in M \\text{ and } t \\in T\\}\\) be a set of binary\ndecision variables, that is \\(X_{mt} = 1\\) if module \\(m\\) is scheduled for time\n\\(t\\), and \\(0\\) otherwise.\n\nThere are six distinct sets of modules in which exams cannot be scheduled\nsimultaneously: \\(A_c\\), \\(A_o\\) representing core and optional art modules\nrespectively; \\(B_c\\), \\(B_o\\) representing core and optional biology modules\nrespectively; and \\(C_c\\), \\(C_o\\) representing core and optional chemistry modules\nrespectively.\nTherefore \\(M = A_c \\cup A_o \\cup B_c \\cup B_o \\cup C_c \\cup C_o\\).\n\nAdditionally there are further clashes between these sets:\n\\begin{itemize}\n  \\item No modules in \\(A_c \\cup A_o\\) can be scheduled together as they may\n  share students, this is given by the constraint in inequality~\\ref{eqn:clique1}.\n  \\item No modules in \\(B_c \\cup B_o \\cup A_c\\), can be scheduled together as\n  they may share students, given by inequality~\\ref{eqn:clique2}.\n  \\item No modules in \\(B_c \\cup B_o \\cup C_o\\), can be scheduled together as\n  they may share students, given by inequality~\\ref{eqn:clique3}.\n  \\item No modules in \\(B_o \\cup C_c \\cup C_o\\), can be scheduled together as\n  they may share students, given by inequality~\\ref{eqn:clique4}.\n\\end{itemize}\n\nDefine \\(\\{Y_t \\text{ for } t \\in T\\}\\) as a set of auxiliary binary\ndecision variables, where \\(Y_t\\) is 1 if time slot \\(t\\) is being used. This is\nenforced by Inequality~\\ref{eqn:auxiliary}.\n\nEquation~\\ref{eqn:schedule_all_modules},\nensures all modules are scheduled once and once only.\nThus altogether the formulation becomes:\n\n\\begin{align}\n\\text{Minimise: } \\sum_{t \\in T} Y_j & \\label{eqn:objective_modules} \\\\\n\\text{Subject to: } & \\nonumber \\\\\n\\frac{1}{|M|} \\sum_{m \\in M} X_{mt} &\\leq Y_j \\text{ for all } j \\in T \\label{eqn:auxiliary} \\\\\n\\sum_{t \\in T} X_{mt} &= 1 \\text{ for all } m \\in M \\label{eqn:schedule_all_modules} \\\\\n\\sum_{m \\in A_c \\cup A_o} X_{mt} &\\leq 1 \\text{ for all } t \\in T \\label{eqn:clique1} \\\\\n\\sum_{m \\in B_c \\cup B_o \\cup A_c} X_{mt} &\\leq 1 \\text{ for all } t \\in T \\label{eqn:clique2} \\\\\n\\sum_{m \\in B_c \\cup B_o \\cup C_o} X_{mt} &\\leq 1 \\text{ for all } t \\in T \\label{eqn:clique3} \\\\\n\\sum_{m \\in B_o \\cup C_c \\cup C_o} X_{mt} &\\leq 1 \\text{ for all } t \\in T \\label{eqn:clique4}\n\\end{align}\n\nAnother common way to define this linear programming problem is by representing the\ncoefficients of the constraints as a matrix\\index{matrix}.\nThat is:\n\n\\begin{align}\n\\text{Minimise: } c^T Z & \\\\\n\\text{Subject to: } & \\nonumber \\\\\nA Z & \\star b\n\\end{align}\n\nwhere \\(Z\\) is a vector\\index{vector} representing the decision variables, \\(c\\)\nis the coefficients of \\(Z\\) in the objective function, \\(A\\) is the matrix of the\ncoefficients of \\(Z\\) in the constraints, \\(b\\) is the vector of the right hand\nside of the constraints, and \\(\\star\\) represents either \\(\\leq\\), \\(=\\) or\n\\(\\geq\\) as required.\n\nAs \\(Z\\) is a one-dimensional vector of decisions variables,\nthe matrix \\(X\\) and the vector \\(Y\\) can be `flattened' together to form this\nnew variable.\nThis is done by first ordering \\(X\\) then \\(Y\\), within that\nordering by time slot, then within that ordering by module number.\nTherefore:\n\n\\begin{align}\nZ_{|M|t + m} &= X_{mt}\\\\\nZ_{|M|^2 + m} &= Y_m\n\\end{align}\n\nwhere \\(t\\) and \\(m\\) are indices starting at 0.\nFor example \\(Z_{17}\\) would correspond to \\(X_{3, 2}\\), the decision variable\nrepresenting whether module number 4 is scheduled on day 3; \\(Z_{208}\\) would\ncorrespond to \\(Y_{12}\\), the decision variable representing whether there is an\nexam scheduled for day 12.\n\nParameters \\(c\\), \\(A\\), and \\(b\\) can be determined by using this same conversion\nfrom the model in Equations~\\ref{eqn:objective_modules} to \\ref{eqn:clique4}.\nThe vector \\(c\\) would be \\(|M|^2\\) zeroes followed by \\(|M|\\) ones.\nThe vector \\(b\\) would be zeroes for all the rows representing\nEquation~\\ref{eqn:auxiliary}, and ones for all other constraints.\n\n\\section{Solving with Python}\\label{sec:linear_programming_solving-with-python}\n\nIn this book the Python library Pulp\\index{Pulp}~\\cite{mitchell2011pulp} will be\nused to formulate and solve the integer programming problem. First a function to\ncreate the binary problem variables for a given set of times and modules is needed:\n\n\\begin{pyin}\nimport pulp\n\n\ndef get_variables(modules, times):\n    \"\"\"Returns the binary variables for a given timetabling\n    problem.\n\n    Args:\n        modules: The complete collection of modules to be\n                 timetabled.\n        times: The collection of available time slots.\n\n    Returns:\n        A tuple containing the decision variables x and y.\n    \"\"\"\n    xshape = (modules, times)\n    x = pulp.LpVariable.dicts(\"X\", xshape, cat=pulp.LpBinary)\n    y = pulp.LpVariable.dicts(\"Y\", times, cat=pulp.LpBinary)\n    return x, y\n\\end{pyin}\n\nThe specific modules and times relating to the problem can now be used to\nobtain the corresponding variables:\n\n\\begin{pyin}\nAc = [0, 1]\nAo = [2, 3, 4]\nBc = [5, 6]\nBo = [7, 8]\nCc = [9, 10]\nCo = [11, 12, 13]\nmodules = Ac + Ao + Bc + Bo + Cc + Co\ntimes = range(14)\nx, y = get_variables(modules=modules, times=times)\n\\end{pyin}\n\nNow \\mintinline{python}{y} is a dictionary of binary decision variables, with\nkeys as elements of the list \\mintinline{python}{times}. \\(Y_3\\) corresponds to\nthe third day:\n\n\\begin{pyin}\nprint(y[3])\n\\end{pyin}\n\n\\begin{pyout}\nY_3\n\\end{pyout}\n\nWhile \\mintinline{python}{x} is a dictionary of dictionaries of binary decision\nvariables, with keys as elements of the lists \\mintinline{python}{modules} and\n\\mintinline{python}{times}. \\(X_{2,5}\\) is the variable corresponding\nto module 2 being scheduled on day 5:\n\n\\begin{pyin}\nprint(x[2][5])\n\\end{pyin}\n\n\\begin{pyout}\nX_2_5\n\\end{pyout}\n\n\nThe next step is to create a Pulp object with the corresponding variables,\nobjective function, constraints and solve it. This is done with the following\nfunction:\n\n\\begin{pyin}\ndef get_solution(Ac, Ao, Bc, Bo, Cc, Co, times):\n    \"\"\"Returns the binary variables corresponding to the solution\n    of given timetabling problem.\n\n    Args:\n        Ac: The set of core art modules\n        Ao: The set of optional art modules\n        Bc: The set of core biology modules\n        Bo: The set of optional biology modules\n        Cc: The set of core chemistry modules\n        Co: The set of optional chemistry modules\n        times: The collection of available time slots.\n\n    Returns:\n        A tuple containing the decision variables x and y.\n    \"\"\"\n    modules = Ac + Ao + Bc + Bo + Cc + Co\n    x, y = get_variables(modules=modules, times=times)\n    prob = pulp.LpProblem(\"ExamScheduling\", pulp.LpMinimize)\n    objective_function = sum([y[day] for day in times])\n    prob += objective_function\n\n    M = 1 / len(modules)\n    for day in times:\n        prob += M * sum(x[m][day] for m in modules) <= y[day]\n        prob += sum([x[mod][day] for mod in Ac + Ao]) <= 1\n        prob += sum([x[mod][day] for mod in Bc + Bo + Co]) <= 1\n        prob += sum([x[mod][day] for mod in Bc + Bo + Ac]) <= 1\n        prob += sum([x[mod][day] for mod in Cc + Co + Bo]) <= 1\n\n    for mod in modules:\n        prob += sum(x[mod][day] for day in times) == 1\n\n    prob.solve(pulp.apis.PULP_CBC_CMD(msg=False))\n    return x, y\n\\end{pyin}\n\nUsing this, the solution \\(x\\) of the original problem can be obtained:\n\n\\begin{pyin}\nx, y = get_solution(\n    Ac=Ac, Ao=Ao, Bc=Bc, Bo=Bo, Cc=Cc, Co=Co, times=times\n)\n\\end{pyin}\n\nThese can be\ninspected, for example \\(x_{25}\\) is a boolean variable relating to if module 2\nis scheduled on the 5th day.\n\n\\begin{pyin}\nprint(x[2][5].value())\n\\end{pyin}\n\n\\begin{pyout}\n0.0\n\\end{pyout}\n\nThis was assigned the value 0, and so module 2 was not scheduled for that day.\nHowever, module 2 was scheduled for day 9:\n\n\\begin{pyin}\nprint(x[2][9].value())\n\\end{pyin}\n\n\\begin{pyout}\n1.0\n\\end{pyout}\n\nThis was assigned a value of 1, and so module 2 was scheduled for that day.\n\nThe following function creates a readable schedule:\n\n\\begin{pyin}\ndef get_schedule(x, y, Ac, Ao, Bc, Bo, Cc, Co, times):\n    \"\"\"Returns a human readable schedule corresponding to the\n    solution of given timetabling problem.\n\n    Args:\n        Ac: The set of core art modules\n        Ao: The set of optional art modules\n        Bc: The set of core biology modules\n        Bo: The set of optional biology modules\n        Cc: The set of core chemistry modules\n        Co: The set of optional chemistry modules\n        times: The collection of available time slots.\n\n    Returns:\n        A string with the schedule\n    \"\"\"\n    modules = Ac + Ao + Bc + Bo + Cc + Co\n\n    schedule = \"\"\n    for day in times:\n        if y[day].value() == 1:\n            schedule += f\"\\nDay {day}: \"\n            for mod in modules:\n                if x[mod][day].value() == 1:\n                    schedule += f\"{mod}, \"\n    return schedule\n\\end{pyin}\n\nThus:\n\n\\begin{pyin}\nschedule = get_schedule(\n    x=x,\n    y=y,\n    times=times,\n    Ac=Ac,\n    Ao=Ao,\n    Bc=Bc,\n    Bo=Bo,\n    Cc=Cc,\n    Co=Co,\n)\nprint(schedule)\n\\end{pyin}\n\ngives:\n\n\\begin{pyout}\n\nDay 0: 1, 12, \nDay 5: 0, 13, \nDay 6: 11, \nDay 7: 4, 6, 10, \nDay 8: 3, 5, 9, \nDay 9: 2, 7, \nDay 13: 8,\n\\end{pyout}\n\nThe order of the days do not matter here, but we 7 days are required in order to\nschedule all exams with no clashes, with at most three exams scheduled each day.\n\n\\section{Solving with R}\\label{sec:linear_programming_solving-with-R}\n\nThe R package ROI\\index{ROI}, the R Optimization\nInfrastructure\\index{R Optimization Infrastructure} will be used here. This is\na library of code that acts as a front end to a number of other solvers that\nneed to be installed externally, allowing a range of optimisation problems to be\nsolved with a number of different solvers.  The solver that will be used here is\ncalled the CBC~\\cite{forrest2005cbc} MILP Solver\\index{CBC MILP Solver}, which\nneeds to be installed. The rcbc\\index{rcbc}~\\cite{shumacher2021rcbc} package is\nalso necessary but cannot be installed in the usual way. Installation\ninstructions for both, depend on the operating system and can be found at the\ndocumentation page for the ROI~\\cite{theussl2017roi} package\\footnote{As of the\ntime of writing, this can be found at \\url{https://roi.r-forge.r-project.org/installation.html}}.\n\nThe ROI package requires that the linear programming problem is\nrepresented in its matrix form, with a one-dimensional array of decision\nvariables. Therefore the form of the model described at the end of\nSection~\\ref{sec:linear_programming_theory} will be used.\nFunctions that define the coefficients of the objective function \\(c\\), the coefficient\nmatrix \\(A\\), the vector of the right hand side of the constraints \\(b\\), and the\nvector of equality or inequalities directions \\(\\star\\) are needed.\n\nFirst the objective function:\n\n\\begin{Rin-no-test}\n#' Writes the row of coefficients for the objective function\n#'\n#' @param n_modules: the number of modules to schedule\n#' @param n_days: the maximum number of days to schedule\n#'\n#' @return the objective function row to minimise\nwrite_objective <- function(n_modules, n_days){\n  all_days <- rep(0, n_modules * n_days)\n  Ys <- rep(1, n_days)\n  append(all_days, Ys)\n}\n\\end{Rin-no-test}\n\nFor 3 modules and 3 days:\n\n\\begin{Rin-no-test}\nobjectives <- write_objective(n_modules = 3, n_days = 3)\nprint(objectives)\n\\end{Rin-no-test}\n\nWhich gives the following array, corresponding to the coefficients of the\narray \\(Z\\) for Equation~\\ref{eqn:objective_modules}.\n\n\\begin{Rout-no-test}\n[1] 0 0 0 0 0 0 0 0 0 1 1 1\n\\end{Rout-no-test}\n\nThe following function is used to write one row of that coefficients matrix, for\na given day, for a given set of clashes, corresponding to\nInequalities~\\ref{eqn:clique1} to \\ref{eqn:clique4}:\n\n\\begin{Rin-no-test}\n#' Writes the constraint row dealing with clashes\n#'\n#' @param clashes: a vector of module indices that all cannot\n#'                 be scheduled at the same time\n#' @param day: an integer representing the day\n#'\n#' @return the constraint row corresponding to that set of\n#'         clashes on that day\nwrite_X_clashes <- function(clashes, day, n_days, n_modules){\n  today <- rep(0, n_modules)\n  today[clashes] = 1\n  before_today <- rep(0, n_modules * (day - 1))\n  after_today <- rep(0, n_modules * (n_days - day))\n  all_days <- c(before_today, today, after_today)\n  full_coeffs <- c(all_days, rep(0, n_days))\n  full_coeffs\n}\n\\end{Rin-no-test}\n\nwhere \\mintinline{R}{clashes} is an array containing the module numbers of a set\nof modules that may all share students.\n\nThe following function is used to write one row of the coefficients matrix, for\neach module, ensuring that each module is scheduled on one day and one day only,\ncorresponding to Equation~\\ref{eqn:schedule_all_modules}:\n\n\\begin{Rin-no-test}\n#' Writes the constraint row to ensure that every module is\n#' scheduled once and only once\n#'\n#' @param module: an integer representing the module\n#'\n#' @return the constraint row corresponding to scheduling a\n#'         module on only one day\nwrite_X_requirements <- function(module, n_days, n_modules){\n  today <- rep(0, n_modules)\n  today[module] = 1\n  all_days <- rep(today, n_days)\n  full_coeffs <- c(all_days, rep(0, n_days))\n  full_coeffs\n}\n\\end{Rin-no-test}\n\nThe following function is used to write one row of the coefficients matrix\ncorresponding to the auxiliary constraints of Inequality~\\ref{eqn:auxiliary}:\n\n\\begin{Rin-no-test}\n#' Writes the constraint row representing the Y variable,\n#' whether at least one exam is scheduled on that day\n#'\n#' @param day: an integer representing the day\n#'\n#' @return the constraint row corresponding to creating Y\nwrite_Y_constraints <- function(day, n_days, n_modules){\n  today <- rep(1, n_modules)\n  before_today <- rep(0, n_modules * (day - 1))\n  after_today <- rep(0, n_modules * (n_days - day))\n  all_days <- c(before_today, today, after_today)\n  all_Ys <- rep(0, n_days)\n  all_Ys[day] = -n_modules\n  full_coeffs <- append(all_days, all_Ys)\n  full_coeffs\n}\n\\end{Rin-no-test}\n\nFinally the following function uses all previous functions to assemble a\ncoefficients matrix.\nIt loops though the parameters for each constraint row required, uses the\nappropriate function to create the row of the coefficients matrix, sets the\nappropriate inequality direction (\\(\\leq\\), \\(=\\), \\(\\geq\\)), and the value of\nthe right hand side.\nIt returns all three components:\n\n\\begin{Rin-no-test}\n#' Writes all the constraints as a matrix, column of\n#' inequalities, and right hand side column.\n#'\n#' @param list_clashes: a list of vectors with sets of modules\n#         that cannot be scheduled at the same time\n#'\n#' @return f.con the LHS of the constraints as a matrix\n#' @return f.dir the directions of the inequalities\n#' @return f.rhs the values of the RHS of the inequalities\nwrite_constraints <- function(list_clashes, n_days, n_modules){\n  all_rows <- c()\n  all_dirs <- c()\n  all_rhss <- c()\n  n_rows <- 0\n\n  for (clash in list_clashes){\n    for (day in 1:n_days){\n      clashes <- write_X_clashes(clash, day, n_days, n_modules)\n      all_rows <- append(all_rows, clashes)\n      all_dirs <- append(all_dirs, \"<=\")\n      all_rhss <- append(all_rhss, 1)\n      n_rows <- n_rows + 1\n    }\n  }\n  for (module in 1:n_modules){\n    reqs <- write_X_requirements(module, n_days, n_modules)\n    all_rows <- append(all_rows, reqs)\n    all_dirs <- append(all_dirs, \"==\")\n    all_rhss <- append(all_rhss, 1)\n    n_rows <- n_rows + 1\n  }\n  for (day in 1:n_days){\n    Yconstraints <- write_Y_constraints(day, n_days, n_modules)\n    all_rows <- append(all_rows, Yconstraints)\n    all_dirs <- append(all_dirs, \"<=\")\n    all_rhss <- append(all_rhss, 0)\n    n_rows <- n_rows + 1\n  }\n  f.con <- matrix(all_rows, nrow = n_rows, byrow = TRUE)\n  f.dir <- all_dirs\n  f.rhs <- all_rhss\n  list(f.con, f.dir, f.rhs)\n}\n\\end{Rin-no-test}\n\nFor demonstration, with 2 modules and 2 possible days, with the single\nconstraint that both modules cannot be scheduled at the same time, then:\n\n\\begin{Rin-no-test}\nwrite_constraints(\n  list_clashes = list(c(1, 2)),\n  n_days = 2,\n  n_modules = 2\n)\n\\end{Rin-no-test}\n\nThis would give 3 components:\n\n\\begin{itemize}\n  \\item a coefficient matrix of the left hand side of the constraints, \\(A\\),\n  (rows 1 and 2 corresponding to the clash on days 1 and 2, row 3 ensuring\n  module 1 is scheduled on one day only, row 4 ensuring module 2 is scheduled on\n  one day only, and rows 5 and 6 defining the decision variables \\(Y\\));\n  \\item an array of direction of the constraint inequalities, \\(\\star\\);\n  \\item and an array of the right hand side values of the constraints, \\(b\\).\n\\end{itemize}\n\n\\begin{Rout-no-test}\n[[1]]\n     [,1] [,2] [,3] [,4] [,5] [,6]\n[1,]    1    1    0    0    0    0\n[2,]    0    0    1    1    0    0\n[3,]    1    0    1    0    0    0\n[4,]    0    1    0    1    0    0\n[5,]    1    1    0    0   -2    0\n[6,]    0    0    1    1    0   -2\n\n[[2]]\n[1] \"<=\" \"<=\" \"==\" \"==\" \"<=\" \"<=\"\n\n[[3]]\n[1] 1 1 1 1 0 0\n\\end{Rout-no-test}\n\nNow, the problem will be solved.\nFirst some parameters, including the sets of modules that all share\nstudents, that is the list of clashes are needed:\n\n\\begin{Rin-no-test}\nn_modules = 14\nn_days = 14\nAc <- c(0, 1)\nAo <- c(2, 3, 4)\nBc <- c(5, 6)\nBo <- c(7, 8)\nCc <- c(9, 10)\nCo <- c(11, 12, 13)\nlist_clashes <- list(\n  c(Ac, Ao),\n  c(Bc, Bo, Co),\n  c(Bc, Bo, Ac),\n  c(Bo, Cc, Co)\n)\n\\end{Rin-no-test}\n\nThen, the functions defined above are used to create the objective function and\nthe 3 elements of the constraints:\n\n\\begin{Rin-no-test}\nconstraints <- write_constraints(\n  list_clashes = list_clashes,\n  n_days = n_days,\n  n_modules = n_modules\n)\nf.con <- constraints[[1]]\nf.dir <- constraints[[2]]\nf.rhs <- constraints[[3]]\nf.obj <- write_objective(n_modules = n_modules, n_days = n_days)\n\\end{Rin-no-test}\n\nFinally, once these objects are in place, the\nROI library is used to construct an optimisation problem object:\n\n\\begin{Rin-no-test}\nlibrary(ROI)\n\nmilp <- OP(\n  objective = L_objective(f.obj),\n  constraints = L_constraint(L = f.con, dir = f.dir, rhs = f.rhs),\n  types = rep(\"B\", length(f.obj)),\n  maximum = FALSE\n)\n\\end{Rin-no-test}\n\nThis creates an \\mintinline{R}{OP} object from our objective row\n\\mintinline{R}{f.obj}, and our constraints which are made up from the three\ncomponents \\mintinline{R}{f.con}, \\mintinline{R}{f.dir} and\n\\mintinline{R}{f.rhs}.\nWhen creating this object the \\mintinline{R}{types} as binary\nvariables are indicated (an array of \\mintinline{R}{\"B\"} for each decision\nvariable).\nThe objective function is to be minimised so\n\\mintinline{R}{maximum = FALSE} is used.\n\nNow to solve:\n\n\\begin{Rin-no-test}\nsol <- ROI_solve(milp)\n\\end{Rin-no-test}\n\nThe solver will output information about the solve process and runtime.\n\n\\begin{Rin-no-test}\nprint(sol$solution)\n\\end{Rin-no-test}\n\n\\begin{Rout-no-test}\n  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0\n [30] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n [59] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0\n [88] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0\n[117] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0\n[146] 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0\n[175] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0\n[204] 1 0 1 1 1 0 1\n\\end{Rout-no-test}\n\nThis gives the values of each of the \\(Z\\) decision variables.\nWe know the structure of this, that is the first 14 variables are the modules\nscheduled for day 1, and so on.\nThe following code prints a readable schedule:\n\n\\begin{Rin-no-test}\n#' Gives a human readable schedule corresponding to the\n#' solution of a given timetable problem.\n#'\n#' @param sol: a solution to the timetabling problem\n#' @param n_modules: the number of modules to schedule\n#' @param n_days: the maximum number of days to schedule\n#'\n#' @return A string with the schedule\nget_schedule <- function(sol, n_days, n_modules){\n  schedule = \"\"\n  for (day in 1:n_days){\n    if (sol$solution[(n_days * n_modules) + day] == 1){\n      schedule <- paste(schedule, \"\\n\", \"Day\", day, \":\")\n      for (module in 1:n_modules){\n        var <- ((day - 1) * n_modules) + module\n        if (sol$solution[var] == 1){\n          schedule <- paste(schedule, module)\n        }\n      }\n    }\n  }\n  schedule\n}\n\\end{Rin-no-test}\n\nThus:\n\n\\begin{Rin-no-test}\nschedule <- get_schedule(\n  sol = sol,\n  n_days = n_days,\n  n_modules = n_modules\n)\ncat(schedule)\n\\end{Rin-no-test}\n\ngives:\n\n\\begin{Rout-no-test}\n\n \"Day 2 : 4 11\"\n \"Day 6 : 1 12\"\n \"Day 8 : 7\"\n \"Day 10 : 8\"\n \"Day 11 : 3 13\"\n \"Day 12 : 2 6 9 14\"\n \"Day 14 : 5 10\"\n\\end{Rout-no-test}\n\nThis gives that 7 days are the minimum required to schedule the 14 exams without\nclashes, with either 1, 2 or 4 exams scheduled on each day.\n\n\\section{Wider context}\\label{sec:linear_programming_wider_context}\n\nThe overview given here on linear programming covers a wide breath of the subject\nalthough not much depth. For specific algorithmic approaches to the underlying\nalgorithms and problem types, such as branch and bound\\index{branch and bound} and\ncutting plane\\index{cutting plane} methods as well as some minor extensions\nsee~\\cite{conforti2014integer, sultan2014linear}.\n\nThe efficiency of linear programming as well as the ability to model\nlinear situations imply that it is often used for a variety of applications.\nTheatre scheduling as one such application is given\nin~\\cite{guerriero2011operational}.\nScheduling is indeed a wide ranging sub application of linear programming\nwhich can also be used to schedule sport seasons~\\cite{duran2007scheduling}.\n\nOther applications include the transportation\nproblem\\index{transportation problem}~\\cite{diaz2014survey} which can be used to\nfind a best allocation of a fleet of delivery vehicles; the fire station\nlocation problem\\index{fire station location problem}~\\cite{schreuder1981application}\nused to minimise travel times to at-risk areas; and the bin packing\\index{bin packing}\nproblem~\\cite{hifi2010linear} in which a number of, possibly irregular,\nshapes are packed into the smallest possible number of bins.\n", "meta": {"hexsha": "ea30a1ada5641535cd3bb92a7a7bd3384a13ba43", "size": 28672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/chapters/08/main.tex", "max_stars_repo_name": "drvinceknight/amwoss", "max_stars_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-21T21:35:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T21:35:44.000Z", "max_issues_repo_path": "src/chapters/08/main.tex", "max_issues_repo_name": "drvinceknight/amwoss", "max_issues_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 71, "max_issues_repo_issues_event_min_datetime": "2019-11-18T11:00:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-21T22:49:40.000Z", "max_forks_repo_path": "src/chapters/08/main.tex", "max_forks_repo_name": "drvinceknight/amwoss", "max_forks_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-15T12:00:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-15T12:00:49.000Z", "avg_line_length": 35.2235872236, "max_line_length": 97, "alphanum_fraction": 0.7120884487, "num_tokens": 8450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6386145057070209}}
{"text": "\\section{Independence Models}\n\n\\begin{frame}{Statistical Models}\n    \\begin{block}{Definition}\n    A \\emph{statistical model} $\\mc{P}$ is the collection of probability distributions, usually parameterised by a function  called a \\emph{parametrisation}\n    $$ \\Theta \\ra \\mc{P}, \\quad \\text{given by} \\quad \\theta \\mapsto P_{\\theta},\\quad \\text{so that}\\quad \\mc{P} = \\{ P_{\\theta} : \\theta \\in \\Theta \\}, $$\n    where $\\Theta$ is the \\emph{parameter space}. $\\Theta$ is usually a subset of $\\RR^{n}$.\n    \\end{block}\n\n    \\begin{block}{McCullagh, \\cite{PM2002}}\n    This should be defined using category theory.\n    \\end{block}\n\n\\end{frame}\n\n\\begin{frame}{Contingency Tables}\n    \n    \\begin{itemize}\n        \\item Classify using two criteria with $r$ and $c$ levels, yielding two random variables $X$ and $Y$. \n        \\item Note outcomes as $[r] := \\{1,\\ldots, r\\}$, and $[c] := \\{ 1, \\ldots, c \\}$.\n    \\end{itemize}\n    \n    All information about $X$ and $Y$ is contained in the \\emph{joint probabilities}:\n    $$ p_{ij} = P(X = i; Y = j), \\quad i \\in [r],\\ j \\in [c]. $$\n\n    \\begin{itemize}\n        \\item These in turn determine the \\emph{marginal probabilities}:\n    \\end{itemize}\n    \\vspace*{-1pt}\n    \\begin{equation*}\n        \\begin{split}\n            p_{i+} &:= \\sum_{j = 1}^{c} p_{ij} = P(X = i), \\quad i \\in [r], \\\\\n            p_{+j} &:= \\sum_{i = 1}^{r} p_{ij} = P(Y = j), \\quad j \\in [c].\n        \\end{split}\n    \\end{equation*}\n\n\\end{frame}\n\n\\begin{frame}\n    \\begin{block}{Definition}\n    \\begin{itemize}\n        \\item Two random variables $X$ and $Y$ are \\emph{independent} if the joint probabilities factor as $p_{ij} = p_{i+}\\cdot p_{+j}$, for all $i \\in [r]$ and $j \\in [c]$. \n        \\item Denote independence of $X$ and $Y$ by $X \\indep Y$.\n    \\end{itemize}\n    \\end{block}\n\n    \\begin{block}{Proposition, \\cite{BSSSMD2009}}\n        \\emph{Two random variables $X$ and $Y$ are independent if and only if the $(r \\times c)$-matrix, $p = (p_{ij})$, has rank one.}\n    \\end{block}\n\n    For a $(2 \\times 2)$-table, we thus have:\n\n\\begin{center}\n\\begin{tabular}{lcc}\n        & $P(Y=1)$ & $P(Y=2)$\\\\\\hline\n$P(X=1)$ & $p_{11}$ & $p_{12}$\\\\\n$P(X=2)$ & $p_{21}$ & $p_{22}$\\\\\\hline\n\\end{tabular}\n$ \\ \\overset{X \\indep Y}{\\longleadsto{1.25}} \\ p_{11}p_{22} = p_{12}p_{21}. $\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Some Geometry}\n\n    Suppose now we select $n$ cases, giving rise to $n$ independent pairs of discrete random variables:\n    $$ \\begin{pmatrix} X^{(1)} \\\\ Y^{(1)} \\end{pmatrix}, \\begin{pmatrix} X^{(2)} \\\\ Y^{(2)} \\end{pmatrix}, \\ldots, \\begin{pmatrix} X^{(n)} \\\\ Y^{(n)} \\end{pmatrix}, $$\n    all drawn from the same distribution, i.e.:\n    $$ P( X^{(k)} = i; Y^{(k)} = j ) = p_{ij}, \\quad \\text{for all } i \\in [r],\\ j \\in [c],\\ k \\in [n]. $$\n\n    \\begin{block}{Probability Simplices}\n    Joint probability matrix $p = (p_{ij})$ is an \\emph{unknown} element of the $(rc-1)$-dimensional \\emph{probability simplex}:\n    $$ \\Delta_{rc-1} = \\Set{ q \\in \\RR^{r\\times c} | q_{ij} \\geq 0, \\text{ for all } i,j, \\text{ and } \\sum_{i = 1}^{r}\\sum_{j = 1}^{c} q_{ij} = 1 }. $$\n    \\end{block}\n\n\\end{frame}\n\n\\begin{frame}\n\n    \\begin{block}{Definitions}\n        \\begin{itemize}\n        \\item A \\emph{statistical model} $\\mc{M}$ is a subset of $\\Delta_{rc-1}$. It represents the set of all candidates for the unknown distribution $p$.\n\n        \\item The \\emph{independence model} for $X$ and $Y$ is the set\n        $$ \\mc{M}_{X \\indep Y} := \\Set{ p \\in \\Delta_{rc - 1} | \\rank(p) = 1 }. $$\n        \\end{itemize}\n    \\end{block}\n\n    $\\mc{M}_{X \\indep Y}$ is the intersection of $\\Delta_{rc-1}$ and the set of all matrices $p = (p_{ij})$ such that\n    $$ p_{ij}p_{kl} - p_{il}p_{jk} = 0, \\quad (1 \\leq i < k \\leq r, \\text{ and } 1 \\leq j < l \\leq c). $$\n\n    These are called \\emph{Segre varieties} in algebraic geometry.\n\n\\end{frame}\n", "meta": {"hexsha": "51181e214245bd15d752339e50b4534481d5cf3e", "size": 3851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/independence.tex", "max_stars_repo_name": "bencwbrown/PGColloquium-06-11-2020", "max_stars_repo_head_hexsha": "853e91be69ff80c3e214ffcd97afe1db2ae458e8", "max_stars_repo_licenses": ["MIT"], "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/independence.tex", "max_issues_repo_name": "bencwbrown/PGColloquium-06-11-2020", "max_issues_repo_head_hexsha": "853e91be69ff80c3e214ffcd97afe1db2ae458e8", "max_issues_repo_licenses": ["MIT"], "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/independence.tex", "max_forks_repo_name": "bencwbrown/PGColloquium-06-11-2020", "max_forks_repo_head_hexsha": "853e91be69ff80c3e214ffcd97afe1db2ae458e8", "max_forks_repo_licenses": ["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.9680851064, "max_line_length": 175, "alphanum_fraction": 0.5798493898, "num_tokens": 1417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6386016236240624}}
{"text": "\\section{Introduction}\n% a contextual description of the goals of experiment\n\nIn 1921, Michelson and Peace developed the concept of {\\it astronomy interferometry} \\cite{michel}, measuring the {\\it angular diameter} of one the brightness star in the sky, {\\it Betelgeuse}, with an {\\it optical telescope}. Nowadays,  Michelson and Peace techniques have broad applications in astronomy to measure stellar diameters \\cite{sbu}.\n\n{\\it Optical} (wavelength ranges of 390 to 750 nanometers) or {\\it Radio interference} (wavelength range of hundreds of meters to millimeters) \\cite{wiki} can be achieved by superimposing signals from more than one telescope, yielding superior {\\it resolutions} than that offered by the telescope alone \\cite{brand}. This is due the fact that the orders of magnitude of the wavelengths in the radio electromagnetic spectra are scalables to the {\\it baselines distances}. Interferometry is a powerful tool in radio astronomy. \n\nA {\\it radio interferometer} measuring an extensive source such as the Sun will show a proportional relation of the dimensions of the experiment (\\ie measurable baseline lengths), to the radio wavelength detected, and  to the {\\it sizes of fringe}, in the resulting power spectra. In addition, precise values for the baseline lengths can be inferred by observing the power spectra of a point source (\\eg an artificial geostationary satellite).\n\nIn our experiment, we make use of a two-mirrors  radio interferometer, assembled in the Stony Brook University\\cite{sbu}, to measure the angular diameter of the Sun, $\\Phi_{sun}$. We show that the Sun is roughly resolved when viewed in {\\it single-dish mode}, but it is well resolved when {\\it observed interferometrically}. \n\\bigskip\n\n\n\\subsection{The Geometry of Radio Interferometry}\n\nThe principle of {\\it superposition of waves}, figure \\ref{int}, states that when two or more waves are incident on the same point, the {\\it total displacement} at that point is equal to the {\\it vector sum of the displacements of the individual waves}. If a crest of a wave meets a crest of another wave of the same frequency at the same point, the {\\it magnitude of the displacement} is the {\\it sum of the individual magnitudes}, yielding a {\\it constructive interference}. If a crest of one wave meets a trough of another wave, the magnitude of the displacements equals the difference in the individual magnitudes, yielding a {\\it  destructive interference} \\cite{brand}.\n\n\\begin{figure}[htb]\n\\begin{center}\n\\includegraphics[scale=0.55]{figs/inter.png}\n\\caption{Interference between two plane wave from a distance source at different angles, from \\cite{brand}. The signals are vectorially added, constructively (a), (c), and destructively  (b). }\n \\end{center}\n\\label{int}\n\\end{figure}\n\n\n\nAn interferometer will detect and vectorially add signals from two different positions, figure \\ref{fig:t}-a. The signal arrives on the two {\\it mirrors}, being then mixed in the {\\it antenna receiver}. The separation between the two positions (mirrors) is named {\\it baseline length}, $B$.\n\n\\begin{figure}[htb]\n\\begin{center}\n\n \\includegraphics[scale=0.45]{figs/time.png}  \\includegraphics[scale=0.81]{figs/ele.jpg}\n\\caption{(left)  a -  Signal detection on two mirrors on a radio telescope separated by a baseline length $B$, from \\cite{sbu}. (right) b - Elevation and azimuth angles in the dish.}\n\\label{fig:t}\n \n\\end{center}\n\\end{figure}\n\n\nFrom an arbitrary origin, we define the horizontal variable angle of the telescope pointing, $\\theta$, and the fixed horizontal angle coordinates of the object in the sky, $\\theta_0$, as in figure \\ref{fig:t}. The angle $\\theta_0$ will be later related to the actual azimuth, $A$, of the object. It will be also useful to calculate the {\\it declination}, $\\delta$ of the object (equatorial coordinates), that can obtained from the {\\it elevation}, $E$, the {\\it azimuth}, and the geographical latitude $\\phi$ (horizontal coordinates)\\cite{wiki},\n\\begin{equation}\n\\sin \\delta = \\sin \\phi \\cdot \\sin E + \\cos \\phi \\cdot \\cos E \\cdot \\cos A.\n\\label{dec}\n\\end{equation}\n\n\n\nThe signal wavefronts arrive at the telescope in phases because one of the sources is overhead. The {\\it time delay}, $\\tau$, of the signal at the position 2 (figure \\ref{fig:t}-a), is related to difference between these two angles, the baseline length $B$, and the electromagnetic radiation speed, {\\it c},\n\\begin{equation}\n\\tau = \\frac{B \\sin(\\theta - \\theta_0)}{c} \\approx \\frac{B(\\theta - \\theta_0)}{c},\n\\label{t}\n\\end{equation}\nwhere we use the fact that $\\theta-\\theta_0\\ll1$, such that the Taylor-expansion for small-angle approximation allows $    \\sin \\theta \\approx \\theta $.\n\n\\bigskip\n\n\\subsection{The Physics of Radio Interferometry}\n\nElectromagnetic radiation can be written in terms of their perpendicular {\\it electric fields, E}, and {\\it magnetic fields, B}, where the last can be simply derived from the first with the {\\it Maxwell Equations} \\cite{jackson}.\n\nThe radio signal is electromagnetic radiation. At the frequency $\\nu$, its time-sinusoidal amplitude arriving at position 1 (figure \\ref{fig:t}-a) can be described as a plane wave with the  electric field  amplitude \\cite{sbu},\n$$\\mathbf E_1(t) = \\mathbf E(\\theta_0)   \\cos [2\\pi \\nu t] .$$\n\nThe signal arriving at position 2 at that same time has traveled $B \\sin(\\theta - \\theta_0)$ more than $E_1(t)$, and its electric field amplitude  is\n$$\\mathbf E_2(t) =  \\mathbf E(\\theta_0)  \\cos [2\\pi \\nu (t-\\tau)] .$$\n\n\n\nIn the  interferometer receiver, the two signals are vectorially added,\n$$\n\\mathbf E_{tot}(t) =  \\mathbf   E_1(t) + \\mathbf E_2(t),\n$$\n and the receiver detects the {\\it total power} of the signal, $P(t)$.  The radio frequency, $\\nu$, is large compared to a data sampling rate of the receiver, and the total power detected  is {\\it time averaged} (or integrated) \\cite{sbu} \\cite {brand} \\cite{jackson},\n\\begin{eqnarray}\nP(t) &=& \\langle\\mathbf E_{tot}(t)^2 \\rangle, \\nonumber \\\\\n& =&   E^2(\\theta_0) [1+ \\cos (2\\pi \\nu \\tau)],  \\nonumber \\\\ \nP(\\theta)&=& E^2(\\theta_0) [1+ \\cos (2\\pi B_{\\lambda} (\\theta - \\theta_0))],\n\\label{p}\n\\end{eqnarray}\nwhere \n$B_{\\lambda} \\equiv B/\\lambda,$ \nis the {\\it normalized baseline length} to the wavelength $\\lambda = c/\\nu$ and we have applied the results from equation (\\ref{t}).\n\nConsidering that the object has an extension in the sky,  we can rewrite equation (\\ref{p}) as a continuum total power law,\n\\begin{eqnarray}\nP(\\theta) = \\int \\varepsilon (\\theta_0) d\\theta_0 \\Bigg [1+ \\cos \\Big (2\\pi B_{\\lambda} (\\theta - \\theta_0)\\Big)\\Bigg ].\n\\label{p22}\n\\end{eqnarray}\n\nAn astronomical object can have any kind of structure, this will result on many kinds of the {\\it energy density distribution},  $\\varepsilon(\\theta_0)$. The telescope interferometer receiver will measure the  sinusoidal power intensity response of the object given by equation (\\ref{p22}), where $\\theta$ are the fringes pattern due the interferometry. This quantity will be directly related to the {\\it Fourier transformation} of the energy density distribution of the object.\n\n\\bigskip\n\n\n\n\\subsection{Obtaining the Baseline Lengths from a Point Source }\n\n\n\nFor a punctual source (artificial geostationary satellite), the energy density varying  on $\\theta_0$ (as we sweep the telescope)  is a $\\delta$-function at the position of the object:\n\\begin{eqnarray}\n \\varepsilon_{sat} (\\theta_0) = \\varepsilon_0 \\delta (\\theta_0). \n\\label{del}\n\\end{eqnarray}\n\nAn expect profile of the total power (amplitude squared) of a point source measured interferometrically can be seen in the figure \\ref{bas}. The pattern of this figure can be thought as resolved  as a serie of point sources, slightly displaced, where the interference and the peaks and valleys shrink towards the central value of one. \n\n\nWe insert equation (\\ref{del}) into (\\ref{p22}) and integrate. As we have mentioned in the beginning of this session,  measurements of a point source yields the accurate measurement of  baseline lengths. The total power is zero in the fringe's minimums (destructive interference, as shown in the figure \\ref{int}), becomes\n\\begin{eqnarray}\nP_{sat}(\\theta) = \\varepsilon_0  \\Bigg [1+ \\cos \\Big (2\\pi B_{\\lambda} (\\theta - \\theta_0) \\Big ) \\Bigg] \\equiv 0,\n\\label{p223}\n\\end{eqnarray}\nmeaning\n\\begin{eqnarray}\n2\\pi B_{\\lambda} (\\theta - \\theta_0) & =& (2n+1) \\pi  \\nonumber \\\\\nB_{\\lambda} (\\theta - \\theta_0) & =& \\frac{2n+1}{2}. \\nonumber\n\\end{eqnarray}\n\nTherefore, the separation between adjacent null positions (\\ie the {\\it angular size of the component} we are measuring) gives the value of the baseline lengths,\n\\begin{eqnarray}\nB_{\\lambda} \\Delta \\theta_{12} &=& \\frac{2(n_1 - n_2)}{2},\\nonumber \\\\\nB^{\\Delta \\theta}_{\\lambda} &\\approx& \\frac{1}{\\Delta \\theta}.\n\\end{eqnarray}\n(as we can observe, again in the figure  \\ref{bas}). We say it is an approximate value because the rotation of the earth plays a role here, it continuously reorients the telescope, causing the directions of the constructive/destructive interference to scan across the radio source. For instance, the earth rotates $0.5^o$ each every 2 minutes.  This oscillation/modulation should be at a much lower frequency than the radio frequency \\cite{brand}.\n\n\\begin{figure}[htb]\n\\centering\n \\includegraphics[scale=0.55]{figs/bas.png}\n\\caption{Example plot of total power as function of telescope pointing, $\\theta$ for a point source such as the satellite, from \\cite{sbu}. }\n\\label{bas}\n\\end{figure}\n\n\nIn addition, with the  actual  declination of the object, $\\delta$, from equation (\\ref{dec}), the fringe $\\Delta \\theta$ is the {\\it Fourier transform} of the fringe period $\\Delta t$.  Considering the angular frequency of earth rotation as $\\omega = 15^o / h$, we can also obtain the baseline lengths writing \n\\begin{equation}\n  B^{\\Delta t}_{\\lambda} = \\frac{1}{\\cos(\\delta) \\sin(\\omega \\Delta t)}.\n\\label{BB}\n\\end{equation}\n\nIn the rest of this session, we shall write $B_{\\lambda}$  for simplicity.\n\n\n\n\n\\bigskip\n\n\\subsection{Calculating the Angular Diameter of the Sun} \\label{visb}\n\n\nWe can rewrite the total power given by equation (\\ref{p22}),\n$$ P_{sun}(\\theta) = \\int \\varepsilon (\\theta_0) d\\theta_0 + \\int \\varepsilon (\\theta_0) \\cos (2\\pi B_{\\lambda} (\\theta - \\theta_0)) d\\theta_0.$$\n\nThis is the the Fourier transformation of the object's energy density distribution and we can prove it rewriting the above equation in the same fashion as in \\cite{sbu}:\n$$P_{sun}(\\theta) = S_{sun} [1+V(\\theta,B_{\\lambda})],$$\nwhere\n$$ S_{sun} = \\int \\varepsilon (\\theta_0) d\\theta_0,$$\nis the full spectra of the Sun (obtained as a single dish rather than as interferometer), and\n\\begin{eqnarray}\nV(\\theta, B_{\\lambda})&=& \\frac{1}{S_{sun}} \\int \\varepsilon (\\theta_0) \\cos [2\\pi B_{\\lambda} (\\theta-\\theta_0)] d\\theta_0 ,\\nonumber \\\\\n&=& V_{sun} (B_{\\lambda}) \\cos [2\\pi B_{\\lambda} \\theta],\n\\end{eqnarray}\n where we gauge the {\\it zero-phase position} of the coordinates to eliminate a phase. $V_{sun}$ is the visibility function of the Sun (an amplitude of the Fourier transform a baseline length $B_{\\lambda}$),\n\\begin{equation}\nV_{sun}(B_{\\lambda}) = \\frac{1}{S_{sun}} \\int \\varepsilon (\\theta_0) e^{-i2\\pi B_{\\lambda} \\theta_0}d\\theta_0.\n\\end{equation}\n\nWe can compare this to the observed total power law,\n$$P_{sun}(\\theta) = S_{sun} \\Big [1 + V_0(B_{\\lambda}) \\cos [2\\pi B_{\\lambda} (\\theta - \\Delta \\theta)]\\Big].$$\n\n\\bigskip\n\nTo extract the power function from an astronomical source, $P_{sun}(\\theta)$, we sweep the object by changing the direction of the telescope pointing, $\\theta$. We see a  sinusoidal curve plus an {\\it offset} proportional to  $\\theta$, as shown in the figure \\ref{psun}, together with maximum and minimum values for the total power function.\n\n\n\n\\begin{figure}[htb]\n\\centering\n \\includegraphics[scale=0.55]{figs/psun.png}\n\\caption{Example plot of total power as function of telescope pointing, $\\theta$ for a extended source, such as the Sun, from \\cite{sbu}. }\n\\label{psun}\n\\end{figure}\n\nIt is straightforward to rewrite out results in terms of $P_{max}$ and $P_{min}$,\n\\begin{equation}\nP_{max} = S_{sun} [1 + V_{sun}(B_{\\lambda})], \n\\end{equation}\n\\begin{equation}\n P_{min} = S_{sun }[1-V_{sun}(B_{\\lambda})].\n\\end{equation}\n\nThe {\\it visibility function}  is then\n\\begin{eqnarray}\nV_{sun}(B_{\\lambda}) &=& \\frac{P_{max} - P_{min}}{P_{max} + P_{min}}.\n\\label{vis}\n\\end{eqnarray}\nwhich is a {\\it sinc} function in term of  the baseline lengths,\n\\begin{eqnarray}\nV_{sun}(B_{\\lambda}) &=& \\frac{\\sin  ( \\pi   B_{\\lambda} \\Phi_{sun}  )}{ \\pi B_{\\lambda} {\\Phi_{sun}}}, \\nonumber \\\\\n&\\equiv& \\mbox{ sinc } (B_{\\lambda} {\\Phi_{sun}}).\n\\label{vissinc}\n\\end{eqnarray}\n\n\nIn this experiment we apply  these properties of the visibility function as a Fourier component of our measurement to obtain the final values of the angular diameter of the sun.\n\n\n", "meta": {"hexsha": "9414fc1297e8960d61d90bb55c22f0f28a84e9dd", "size": 12842, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/intro.tex", "max_stars_repo_name": "bt3gl/Tool-Calculating_the_Diameter_of_Sun", "max_stars_repo_head_hexsha": "f8f7729c2caad2f411e9835a3a28d33a03dff73e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-02-21T17:41:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T17:48:02.000Z", "max_issues_repo_path": "tex/intro.tex", "max_issues_repo_name": "bt3gl/Calculating_the_Diameter_of_Sun", "max_issues_repo_head_hexsha": "f8f7729c2caad2f411e9835a3a28d33a03dff73e", "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/intro.tex", "max_forks_repo_name": "bt3gl/Calculating_the_Diameter_of_Sun", "max_forks_repo_head_hexsha": "f8f7729c2caad2f411e9835a3a28d33a03dff73e", "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": 61.4449760766, "max_line_length": 675, "alphanum_fraction": 0.7326740383, "num_tokens": 3590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6386016115159021}}
{"text": "\\documentclass[notitlepage, twocolumn]{article}\n\\usepackage{fullpage}\n\\usepackage[affil-it]{authblk}\n\\usepackage{hyperref}\n\\usepackage{algpseudocode}\n\\usepackage[]{algorithmicx}\n\\usepackage{algorithm}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage[backend=bibtex, style=numeric]{biblatex}\n\\usepackage{caption}\n\\usepackage{pdfpages}\n\n\\captionsetup[ruled]{labelsep=period}\n\n\\makeatletter\n\\@addtoreset{algorithm}{section}% algorithm counter resets every section\n\\makeatother\n\n\\renewcommand{\\thealgorithm}{\\thesection.\\arabic{algorithm}}\n\n\\addbibresource{report.bib}\n\n\\def\\ft{\\mathcal{F}}\n\\algblockdefx[spawn]{Spawn}{EndSpawn}\n[1]{\\textbf{spawn process for} #1 \\textbf{do}}\n{\\textbf{end spawn}}\n\n\\def\\CC{\\mathbb{C}}\t% Complex\n\n\\newcommand{\\set}[1]{\\lbrace #1 \\rbrace}\n\\newcommand{\\paren}[1]{\\left( #1 \\right)}\n\n\\title{\\bf\nGPU Accelerated Fast Fourier Transform\n}\n\n\\date{December 2015}\n\\author{\nMatt McCarthy\n}\n\\affil{Christopher Newport University\\\\\n\\textbf{CPSC 621 Parallel Processing}\\\\\n\\texttt{\\href{mailto:matthew.mccarthy.12@cnu.edu}{matthew.mccarthy.12@cnu.edu}}\n}\n\n\\begin{document}\n\\nocite{*}\n\\maketitle\n\n\\noindent\\textbf{Abstract}\nWe empirically investigate the performance benefits of parallel fast Fourier transform running on the GPU over a sequential version running on the GPU.\n\n\\section{Background}\n\n\\subsection{Discrete Fourier Transform}\n\nThe discrete Fourier transform is a mathematical transformation that takes a set of Complex-valued signals and outputs a set of Complex-valued frequencies.\nFor an $n$-dimensional Complex-valued vector $\\mathbf{X}$, the discrete Fourier transform $\\mathbf{Y}=\\mathcal{F}(X)$ is given by\n\\[\n\tY_j = \\sum_{k=0}^n x_k \\omega^{jk}\n\\]\nwhere $\\omega$ is the $n$-th root of unity, $e^{2\\pi i/n}$.\nSince $\\mathbf{Y}$ is an $n$-dimensional, Complex-valued vector, we can see that the discrete Fourier transform has a complexity of $\\Theta(n^2)$.\n\n\\subsection{Fast Fourier Transform}\n\nFurthermore, we can split the discrete Fourier transform into even and odd sums for $n=2m$, yielding\n\\[\n\tY_j = \\sum_{k=0}^m x_{2k}\\omega^{2jk} + \\omega^j\\sum_{k=0}^m x_{2k+1}\\omega^{2jk}\n\\]\nwhich is two separate discrete Fourier transforms.\nSuppose $n=2^k$.\nIf we iterate this process, we get the following algorithm called the one-dimensional, unordered radix 2, fast Fourier transform in Algorithm 1.1.\n\\begin{algorithm}\n\t\\caption{Recursive FFT}\n\t\\begin{algorithmic}[1]\n\t\t\\Function{R-FFT}{$\\mathbf{X}$,$\\mathbf{Y}$,$n$,$\\omega$}\n\t\t\t\\If{$n$=1}\n\t\t\t\t\\State $y_0=x_0$\n\t\t\t\\Else\n\t\t\t\t\\State Let $\\mathbf{Q}=\\mathbf{0},\\mathbf{T}=\\mathbf{0}\\in\\CC^n$\n\t\t\t\t\\State Let $\\mathbf{X_e}=(x_0, x_2,\\ldots,x_{n-2})$\n\t\t\t\t\\State Let $\\mathbf{X_o}=(x_1, x_3,\\ldots,x_{n-1})$\n\t\t\t\t\\State \\Call{R-FFT}{$\\mathbf{X_e}$,$\\mathbf{Q_e}$,$n/2$,$\\omega^2$}\n\t\t\t\t\\State \\Call{R-FFT}{$\\mathbf{X_o}$,$\\mathbf{T_o}$,$n/2$,$\\omega^2$}\n\t\t\t\t\\ForAll{$j\\in\\set{0,1,\\ldots,n-1}$}\n\t\t\t\t\t\\State $y_j=q_{j\\mod{n/2}}+\\omega^i t_{j\\mod{n/2}}$\n\t\t\t\t\\EndFor\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsubsection{Cooley Tukey}\n\nFurthermore, we have an iterative formulation of the prior algorithm, called the Cooley Tukey algorithm for one-dimensional, unordered radix 2, fast Fourier transforms.\n\n\\begin{algorithm}\n\t\\caption{Cooley-Tukey FFT}\n\t\\begin{algorithmic}[1]\n\t\t\\Function{I-FFT}{$\\mathbf{X}$,$\\mathbf{Y}$,$n$}\n\t\t\t\\State $t:=\\lg n$\n\t\t\t\\State $\\mathbf{R}=\\mathbf{X}$\n\t\t\t\\For{$m=0$ to $t-1$}\n\t\t\t\t\\State $\\mathbf{S}=\\mathbf{R}$\n\t\t\t\t\\For{$l=0$ to $n-1$}\n\t\t\t\t\t\\State Let $(b_0b_1\\ldots b_{t-1})$ be the binary expansion of $l$\n\t\t\t\t\t\\State $j:=(b_0\\ldots b_{m-1}0b_{m+1}\\ldots b_{t-1})$\n\t\t\t\t\t\\State $k:=(b_0\\ldots b_{m-1}1b_{m+1}\\ldots b_{t-1})$\n\t\t\t\t\t\\State $r_i:= s_j+s_k\\omega^{(b_mb_{m-1}\\ldots b_0 0\\ldots0)}$\n\t\t\t\t\\EndFor\n\t\t\t\\EndFor\n\t\t\t\\State $\\mathbf{Y}:=\\mathbf{R}$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nFrom this pseudo-code, we can determine the complexity of fast Fourier transform as described by Algorithm 1.2.\nWe begin by noting that we iterate through the outer loop precisely $\\lg n$ times and the inner loop $n$ times.\nTherefore our complexity is $T_1=\\Theta(n\\lg n)$.\n\n\\subsection{Parallelization}\n\nFor our parallelization, we use a simplified version of the binary exchange algorithm, a parallelization of the Cooley Tukey algorithm designed for use on a hypercube.\nSince our implementation runs on a single GPU, any thread can access any memory location via a pointer.\nHowever, this also complicates the matter by introducing a potential for data races.\nWe solve this by modifying the algorithm to work as follows in Algorithm 1.3.\n\\begin{algorithm}\n\t\\caption{Parallel FFT}\n\t\\begin{algorithmic}[1]\n\t\t\\Function{PAR-FFT}{$\\mathbf{X}$,$\\mathbf{Y}$,$n$}\n\t\t\t\\State $t:=\\lg n$, $BLK:=n/p$\n\t\t\t\\State $\\mathbf{R}=\\mathbf{X}$\n\t\t\t\\State $\\mathbf{S}=\\mathbf{0}$\n\t\t\t\\For{$m=0$ to $t-1$}\n\t\t\t\t\\State Swap pointers $\\mathbf{R}$ and $\\mathbf{S}$\n\t\t\t\t\\Spawn{$l=0$ to $BLK-1$}\n\t\t\t\t\t\\For{$c=l\\cdot BLK$, to $l\\cdot(BLK+1)$}\n\t\t\t\t\t\t\\State Let $(b_0b_1\\ldots b_{t-1})$ be the binary expansion of $c$\n\t\t\t\t\t\t\\State $j:=(b_0\\ldots b_{m-1}0b_{m+1}\\ldots b_{t-1})$\n\t\t\t\t\t\t\\State $k:=(b_0\\ldots b_{m-1}1b_{m+1}\\ldots b_{t-1})$\n\t\t\t\t\t\t\\State $r_i:= s_j+s_k\\omega^{(b_mb_{m-1}\\ldots b_0 0\\ldots0)}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndSpawn\n\t\t\t\t\\State \\textbf{sync}\n\t\t\t\\EndFor\n\t\t\t\\State $\\mathbf{Y}:=\\mathbf{R}$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\nIn each iteration, we only write to $\\mathbf{R}$ and only read from $\\mathbf{S}$.\nSince we wait until each thread is complete before moving on to the next iteration, we avoid the potential to use old or incorrect data.\n\nIf we inspect the parallelization, we see that the outer loop runs $\\lg n$ times.\nHowever, the inner loop is ran on $p$ processes, each of which handle $n/p$ iterations.\nTherefore, the computation cost is $\\Theta(n/p\\lg n)$.\nMoreover, for communication we simply do two reads from VRAM on each iteration of the inner loop, however some values will be in cache so we may get better performance than that.\nErgo, the communication cost is $O(n/p\\lg n)$.\nThus, the parallel runtime will be $T_p = \\Theta(n/p \\lg n)$ and is cost optimal if and only if $p\\leq n$.\n\n\\section{Experimental Design}\n\nThe goal of the experiment is to empirically determine the effect of parallelization on the runtime of the Cooley Tukey algorithm.\nTo this end we want to measure the runtime of fast Fourier transform using differing sizes of $n$, the dimension of our Complex valued vector, and $t$, the number of threads.\nLet $\\mathcal{N}$ be the set of vector dimensions we will test and let $\\mathcal{T}$ be the set of thread counts we will test.\nFurthermore, we specify that each $n\\in\\mathcal{N}$ and each $t\\in\\mathcal{T}$ be powers of two.\n\nFor $t=1$, we will run the Cooley Tukey algorithm on random Complex valued vectors of dimension $n$ for each $n\\in\\mathcal{N}$.\nOtherwise, we run our parallelization of the Cooley Tukey algorithm on Complex valued vectors of dimension $n$ for each $n\\in\\mathcal{N}$.\nMoreover, before and after each run, we copy the input to the GPU and the output from the GPU.\nWe take the system time before copying the input to the GPU and again after copying the output to the host.\nWe do not check the output for correctness during the test in order to save time, but instead checked the correctness of the algorithm beforehand.\n\n\\section{Test Environment}\n\n\\subsection{Test System}\n\nThe machine used to run the test has an Intel i7 4770k running at 4.2GHz, 16GB of RAM, and a Nvidia GTX 970 with a core clock of 1342MHz and memory clock of 7000MHz.\nThe computer was running Arch Linux on Linux kernel 4.2.5 with Nvidia driver version 358.16 and CUDA 7.5.\n\n\\subsection{Test Program}\n\nFirstly, all code can be located at \\url{https://github.com/matt-mccarthy/fast-fourier-transform} in the \\verb|fast-fourier| folder.\nWe also include a version of the code in the Appendix.\n\nWe wrote all code in CUDA C++.\nFurthermore all code was compiled with the CUDA toolkit 7.5 and GCC 5.2.0 using the command \\verb|nvcc| \\verb| -std=c++11| \\verb|-rdc=true| \\verb|-arch=compute_52| \\verb|-code=sm_52 -O3|.\nThe library source file is \\verb|src/fast-fourier.cu|, and the sequential and parallel main functions are located in \\verb|sequential-fft.cu| and \\verb|parallel-fft.cu| respectively.\n\nIn both the sequential fast Fourier and parallel fast Fourier, we ran into issues with dynamically allocating memory in a CUDA kernel.\nNamely, if we allocated and freed often enough, we ran out of memory.\nTo avoid this issue entirely, we made all allocations of giant arrays occur in main once and then reused those arrays.\nAs a note, the \\verb|binary_stor| array is where we store the binary representation of our index $l$ for each thread.\nWhile this design is suboptimal (ideally, each thread would create its own so others can not touch it), it works and the performance impact should be neglible for large enough $n$.\n\nMoreover, our GPU code is entirely without any conditional statements except the ones for determining whether or not our for loop is within its bounds.\nAnother note about the code is that at the end of each iteration of the outer for loop, we call \\verb|cudaDeviceSynchronize| which blocks until our \\verb|transformer| kernel completes.\nWe do this in order to ensure syncrhonization across all threads and prevent data races.\nFurthermore, the \\verb|transformer| kernel must always be called from another kernel that runs on exactly one thread.\nWe do this in order to keep all code running on the device and prevent useless communication between the CPU and GPU.\n\nFor our test we took, $\\mathcal{N}=\\set{2^{17},2^{19},2^{21},2^{23},2^{25}}$ and $\\mathcal{T}=\\set{1,4,16,64,256,1024}$, all of which are less than the number of cores on our GTX 970.\nWe chose $\\mathcal{N}$ such that we would get a runtime for 1MB of data on the low end, and 1GB of data on the high end since each complex value is a typedef'd \\verb|float2|.\nMoreover, we ran each combination of $n$ and $t$ 10 times each.\nAll runtimes were measured and recorded in milliseconds, and our result files are included in Appendix B.\n\n\\section{Results}\n\n\\begin{figure}\\label{results}\n\t\\centering\n\n\t\\includegraphics[scale=0.35]{results.png}\n\t\\caption{Runtime vs Array Size}\n\\end{figure}\n\n\\begin{figure}\\label{res-table}\n\t\\centering\n\t\\begin{small}\n\t\\[\n\t\t\\begin{array}{r|c|c|c|c|c}\n\t\t\t& 2^{17} & 2^{19} & 2^{21} & 2^{23} & 2^{25}\\\\\\hline\n\t\t\t2^0& 7.37 & 35.8 & 162 & 773 & 3.42\\cdot10^6\\\\\\hline\n\t\t\t2^2& 1.75 & 8.47 & 38.5 & 183  & 813\\\\\\hline\n\t\t\t2^4& .446 & 2.15 & 9.75 & 46.4 & 205.8\\\\\\hline\n\t\t\t2^6& .117 & .552 & 2.51 & 11.9 & 52.8\\\\\\hline\n\t\t\t2^8& .034 & .149 & .669 & 3.14 & 14.3\\\\\\hline\n\t\t\t2^{10}& 0.011 & .046 & .201 & .975 & 4.65\n\t\t\\end{array}\n\t\\]\n\t\\end{small}\n\t\\caption{The table of runtimes at $(n,t)$ in s}\n\\end{figure}\n\nFigure 2 lists the runtimes for each $t$ (row index) at size $n$ (column index).\nMoreover, the graphs all look like the standard $x\\ln x$ curve.\nBy inspection, we see that $T_{2k}\\approx T_{2k+2}/4$, which is exactly what we are looking for.\nSo naively, we can say that this has a linear speedup.\n\nWe also attempted to compute on 1GB of random complex numbers, or precisely, $2^{27}$ complex numbers.\nThe parallel runtime for $t=1024$ was approximately 22s, however, after many hours of running the sequential version at this $n$ did not complete.\nUpon deeper analysis, we learned that with perfect linear speedup, the sequential version would have a runtime roughly 1000 times greater than $T_{1024}$, namely 6 hours.\nDue to time constraints, we had to abandon this size of $n$ and make our maximum $2^{25}$.\nFurthermore, due to memory constraints, we could not test for any $n\\geq 2^{28}$ since we have to allocate two arrays of 2GB each in order to compute on it and our 970 has 4GB VRAM.\n\n\\section{Future Work}\n\nIn our study, VRAM limitations and time constraints prevented us from harnessing extremely large values of $n$.\nOne way to extend this study to larger values of $n$ is to simply use GPUs that have more than 4GB of VRAM like the Titan X and simply run tests with larger values of $n$.\n\nAnother, more interesting path to explore is to distribute the problem across multiple GPUs.\nIf we split it smartly, we should be able to utilize the extra VRAM without incurring too much communication overhead.\nOf course, the inter-GPU communication is also a factor and we would need to decide the best way to manage it.\nThis latter method can also scale to a GPU farm.\n\n\\section{Conclusion}\n\nOur analysis of the algorithm determined that for $t \\leq n$, we should get perfect linear speedup and the data provides empirical evidence for that, with 1024 threads executing approximately 1000 times faster than the sequential.\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "d7aa7794203e9efb6e297ba016f9d8e40b31e18d", "size": 12771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "matt-mccarthy/fast-fourier-transform", "max_stars_repo_head_hexsha": "58ce4e63b9e2a00fe7c22b27fab98b66aaf120e5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-10T01:26:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-10T01:26:51.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "matt-mccarthy/fast-fourier-transform", "max_issues_repo_head_hexsha": "58ce4e63b9e2a00fe7c22b27fab98b66aaf120e5", "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/paper.tex", "max_forks_repo_name": "matt-mccarthy/fast-fourier-transform", "max_forks_repo_head_hexsha": "58ce4e63b9e2a00fe7c22b27fab98b66aaf120e5", "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.1924528302, "max_line_length": 230, "alphanum_fraction": 0.7284472633, "num_tokens": 3939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.638601610141561}}
{"text": "% !TEX root = main.tex\n\nAn important problem in statistics is to estimate the distribution of a random variable from a set of observations. For example, certain observations may be known (or assumed) to have an exponential distribution and we want to estimate the rate parameter $\\lambda$ of the distribution, or observations may be taken from a normal distribution and we want to estimate the mean $\\mu$ and variance $\\sigma^2$ of the distribution.\n\n%-------------------------------------------------\n\\section{Random samples}\\label{sec:random_samples}\n\nFirst we define random vectors. These are simply vectors of random variables.\n\n\\begin{definition}\\label{def:random_vector}\nLet $X_1,X_2,\\ldots,X_n$ be random variables defined on the same probability space. The vector-valued function\n\\[\n\\begin{array}{rccl}\n\\mathbf{X}:\t& \\Omega \t& \\longrightarrow \t\t& \\R^n \\\\\n\t\t\t& \\omega\t& \\mapsto\t& \\big[X_1(\\omega), X_2(\\omega),\\ldots, X_n(\\omega)\\big]\n\\end{array}\n\\]\nis called a \\emph{random vector} of size $n$. The individual $X_i$ are called the \\emph{component variables} of $\\mathbf{X}$ and a vector $\\mathbf{x} = (x_1,x_2\\ldots,x_n)\\in\\R^n$ is called a \\emph{realisation} of $\\mathbf{X}$, where $x_i$ is the value taken by the corresponding component variable $X_i$.\n\\end{definition}\n\nThe behaviour of a random vector is completely described by the joint CDF of its component variables.\n\\begin{definition}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random vector.\n\\ben\n\\it \nThe \\emph{joint distribution} of $\\mathbf{X}$ is the function $\\prob_{\\mathbf{X}}(B) = \\prob(\\mathbf{X}\\in B)$ defined on subsets of $\\R^n$.\n\\it\nThe \\emph{joint CDF} of $\\mathbf{X}$ is the function $F_{\\mathbf{X}}:\\R^n\\to[0,1]$ given by\n\\begin{align*}\nF_{\\mathbf{X}}(\\mathbf{x}) \t= \\prob(\\mathbf{X}\\leq\\mathbf{x})\n\t\t\t\t\t\t\t& = \\prob(X_1\\leq x_1, X_2\\leq x_2, \\ldots, X_n\\leq x_n) \\\\\n%\t\t\t\t\t\t\t& = \\prob\\big(\\{\\omega:X_1(\\omega)\\leq x_1, X_2(\\omega)\\leq x_2, \\ldots, X_n(\\omega)\\leq x_n\\}\\big).\n\\end{align*}\n\\een\n\\end{definition}\n\nIn general the component variables $X_i$ might depend on each other and have different distributions. Our analysis is greatly simplified by assuming that the $X_i$ are \\emph{independent} and \\emph{identically distributed}.% random variables.\n\n\\begin{definition}\\label{def:random_sample}\nLet $X$ be a random variable. A \\emph{random sample from the distribution of $X$} is a random vector with the property that the component variables $X_i$ are independent and have the same distribution as $X$.\n\\end{definition}\n\nBy independence the joint CDF of a random sample is just the product of its marginal CDFs and because each $X_i$ has the same distribution as $X$, this can be expressed entirely in terms of the CDF of $X$.\n \n\\begin{lemma}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the distribution of $X$. Then the joint CDF and joint PMF/PDF of $\\mathbf{X}$ can be written respectively as\n\\[\nF_{\\mathbf{X}}(\\mathbf{x}) = \\textstyle\\prod_{i=1}^n F_X(x_i) \n\\qquad\\text{and}\\qquad\nf_{\\mathbf{X}}(\\mathbf{x}) = \\textstyle\\prod_{i=1}^n f_X(x_i)\n%\\qquad\\text{respecively},\n\\]\nwhere $F_X$ and $f_X$ are the CDF and PMF/PDF of $X$ respectively, and $\\boldx=(x_1,x_2,\\ldots,x_n)$ is a realisation of the sample.. \n\\end{lemma}\n\\begin{proof}\n\\begin{align*}\nF_{\\mathbf{X}}(\\mathbf{x})\n\t& = \\prob(X_1\\leq x_1, X_2\\leq x_2, \\ldots, X_n\\leq x_n) \\\\\n\t& = \\prob(X_1\\leq x_1)\\prob(X_2\\leq x_2)\\ldots\\prob(X_n\\leq x_n) \\quad\\text{(by independence)} \\\\\n\t& = F_X(x_1)F_X(x_2)\\cdots F_X(x_n) \\quad\\text{(because each $X_i$ has the same distribution as $X$)}\\\\\n\t& = \\textstyle\\prod_{i=1}^n F_X(x_i).\n\\end{align*}\n\\end{proof}\n\n%\\begin{example}\n%Let $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the $\\text{Exponential}(\\lambda)$ distribution, where $\\lambda>0$ is a rate parameter. Then the joint CDF and joint PDF of $\\mathbf{X}$ are respectively\n%\\begin{align*}\n%F_{\\mathbf{X}}(\\mathbf{x}) \n%\t& = \\textstyle\\prod_{i=1}^n\\big[1-\\exp(-\\lambda x_i)\\big] \\\\\n%f_{\\mathbf{X}}(\\mathbf{x}) \n%\t& = \\textstyle\\prod_{i=1}^n\\lambda \\exp(\\lambda x_i) = \\lambda^n\\exp(-\\lambda\\sum_{i=1}^n x_i).\n%\\end{align*}\n%\\end{example}\n%The same relationship holds for PMFs (discrete case) and PDFs (continuous case).\n%\\begin{corollary}\n%If $\\boldX=(X_1,X_2,\\ldots,X_n)$ is a random sample from the distribution of $X$, the joint PMF/PDF of $\\mathbf{X}$ can be written as\n%\\[\n%f_{\\mathbf{X}}(\\mathbf{x}) = \\textstyle\\prod_{i=1}^n f_X(x_i)\n%\\]\n%for all $\\boldx=(x_1,x_2,\\ldots,x_n)\\in\\R^n$, where $f_X$ is the PMF/PDF of $X$.\n%\\end{corollary}\n\n", "meta": {"hexsha": "1e28925b9d38812a09e646e047fdd344423fa3ca", "size": 4521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/07A_random_samples.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/07A_random_samples.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/07A_random_samples.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": 54.4698795181, "max_line_length": 425, "alphanum_fraction": 0.696084937, "num_tokens": 1548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.638583914354033}}
{"text": "\\input{settings}\n\n\\begin{document}\n\n\\lhead{Sergio Arnaud}\n\\rhead{ Statistical learning (MT7038) \\\\ Proyect 3 - Neural networks }\n\\cfoot{\\thepage of \\pageref{LastPage}}\n\n\\section{Backpropagation}\n\nThe purpose of this assignment is to implement a complete solution for training a neural network. In practice this is of course done by packages and programs, but it is important to have done it at least once yourselves.\n\nUsing backpropagation and stochastic gradient descent we will fit a nerual network with two hidden layers, and sigmoid activation, to the function $y(x) = x^3$ on the interval $(-2, 2)$. Let $\\theta = \\{(W_i, b_i), i = 1, 2, 3\\}$ be the parameters of the model, then the network function is given by\n\n\\begin{align*}\n    f(x,\\theta) = W_3h_2 + b_3 \\quad h_2 = \\sigma(W_2h_1 + b_2) \\quad h_1 = \\sigma(W_1x + b_1)\n\\end{align*}\n\n\\subsection{Dimensions of the Parameters}\n\nAssume that both hidden layers has $n$ hidden units, i.e. $h = (h1, . . . , hn)$ . Give the dimensions of all the\nparameters $(W_i,bi)$, $i=1,2,3$\n\\begin{align*}\n    W_1 \\in \\mathbb{R}^{n \\times 1} \\quad b_1 \\in \\mathbb{R}^{n \\times 1}\\\\\n    W_2 \\in \\mathbb{R}^{n \\times n} \\quad b_2 \\in \\mathbb{R}^{n \\times 1} \\\\\n    W_3 \\in \\mathbb{R}^{1 \\times n} \\quad b_3 \\in \\mathbb{R} \\ \\ \\ \\ \\\n\\end{align*}\n\n\\subsection{Calculating the Derivatives.}\n\nLet $L(x_i, y_i, \\theta) = (y_i - f(x_i; \\theta))^2$. Given the observation $(x,y)$ calculate the derivatives of $L(x,y;\\theta)$.\n\n\\begin{align*}\n    \\frac{\\partial L}{\\partial W_{i}^3} &= 2(y-f(x,\\theta))h^2_i\\\\\n    \\frac{\\partial L}{\\partial b_{i}^3} &= 2(y-f(x,\\theta))\\\\\n    \\frac{\\partial L}{\\partial h_{i}^2} &= \\frac{\\partial L}{\\partial b_{i}^3}W_i^3 \\\\\\\\\n    \\frac{\\partial L}{\\partial W_{ij}^2} &= \\frac{\\partial L}{\\partial h_{i}^2}(h_i^2(1-h_i2))h_j^1 \\\\\n    \\frac{\\partial L}{\\partial b_{i}^2} &=  \\frac{\\partial L}{\\partial h_{i}^2}(h_i^2(1-h_i2)) \\\\\n    \\frac{\\partial L}{\\partial h_{i}^1} &= \\frac{\\partial L}{\\partial b_{i}^2}W_{ii}^2 \\\\\\\\\n    \\frac{\\partial L}{\\partial W_{i}^3} &= \\frac{\\partial L}{\\partial h_{i}^1}(h_i^1(1-h_i^1))x \\\\\n    \\frac{\\partial L}{\\partial b_{i}^3} &= \\frac{\\partial L}{\\partial h_{i}^1}(h_i^1(1-h_i^1)) \\\\\n\\end{align*}\n\n\\subsection{Fitting the Model}\n\nThe following code fites a feed forward neural network with 2 hiddel layers (125 hidden units) to the function $y(x) = x^3$.\n\n\\begin{lstlisting}[language=R]\n\nsigm <- function(x){\n  f <- function(y){\n    return(1/(1+exp(-y)))\n  }\n  return( sapply(x,f) )\n}\n\ninitParams <- function(nrHiddenUnits, xDim) {\n  W <- list()\n  b <- list()\n\n  # First hidden layer\n  W_1 <- matrix(0.05*rnorm(nrHiddenUnits * xDim), ncol = xDim,\n  nrow = nrHiddenUnits, byrow = TRUE)\n  b_1 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = 1,\n  nrow = nrHiddenUnits, byrow = TRUE)\n\n  # Second hidden layer\n  W_2 <- matrix(0.05*rnorm(nrHiddenUnits * xDim), ncol = nrHiddenUnits,\n  nrow = nrHiddenUnits, byrow = TRUE)\n  b_2 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = 1,\n  nrow = nrHiddenUnits, byrow = TRUE)\n\n  # Output layer\n  W_3 <- matrix(0.05*rnorm(nrHiddenUnits), ncol = nrHiddenUnits,\n  nrow = 1, byrow = TRUE)\n  b_3 <- 0.05*rnorm(1)\n\n  W[[1]] <- W_1\n  W[[2]] <- W_2\n  W[[3]] <- W_3\n\n  b[[1]] <- b_1\n  b[[2]] <- b_2\n  b[[3]] <- b_3\n\n  return(list(\"W\" = W,\"b\" = b))\n}\n\n\nforwardPass <- function(x,W,b){\n  #First hidden Layer\n  h_1 <- sigm(W[[1]] %*% x + b[[1]])\n\n  #Second hidden Layer\n  h_2 <- sigm(W[[2]] %*% h_1 + b[[2]])\n\n  #Output Layer\n  y <- W[[3]] %*% h_2 + b[[3]]\n\n  return( list(\"output\" = y, \"hiddenLayer1\" = h_1, \"hiddenLayer2\" = h_2 ) )\n}\n\ngradient <- function(x,y,W,b){\n\n  net <- forwardPass(x,W,b)\n  h_1 <- net$hiddenLayer1\n  h_2 <- net$hiddenLayer2\n\n  output <- net$output[[1]]\n\n  W_3 <- W[[3]]\n  W_2 <- W[[2]]\n  W_1 <- W[[1]]\n\n  b_1 <- b[[1]]\n  b_2 <- b[[2]]\n  b_3 <- b[[3]]\n\n  #dL/dW_3\n  dW_3 <- 0*W_3\n  for (j in 1:dim(dW_3)[2]) {\n    dW_3[1,j] <- -2*(y-output)*h_2[j]\n  }\n  #dL/db_3\n  db_3 <- -2*(y-output)\n  #dL/dh_2\n  dh_2 <- 0*h_2\n  for ( i in 1:length(h_2) ) {\n    dh_2[i] <- db_3*W_3[1,i]\n  }\n\n\n  #dL/dW_2\n  dW_2 <- 0*W_2\n  for (i in 1:(dim(dW_2)[1])){\n    for (j in 1:(dim(dW_2)[2])) {\n      dW_2[i,j] <- dh_2[i]*(h_2[i]*(1-h_2[i]))*h_1[j]\n    }\n  }\n  #dL/db_2\n  db_2 <- 0*b_2\n  for (i in 1:length(db_2)) {\n   db_2[i] <- dh_2[i]*(h_2[i]*(1-h_2[i]))\n  }\n  #dL/dh_1\n  dh_1 <- 0*h_1\n  for (i in 1:length(dh_1)) {\n   dh_1[i] <- db_2[i]*W_2[i,i]\n  }\n\n\n  #dL/dW_1\n  dW_1 <- 0*W_1\n  for (i in 1:(dim(dW_1)[1])){\n    for (j in 1:(dim(dW_1)[2])) {\n      dW_1[i,j] <- dh_1[i]*(h_1[i]*(1-h_1[i]))*x\n    }\n  }\n  #dL/db_1\n  db_1 <- 0*b_1\n  for (i in 1:length(db_1)) {\n   db_1[i] <- dh_1[i]*(h_1[i]*(1-h_1[i]))\n  }\n\n  return( list(\"dW_1\" = dW_1, \"dW_2\" = dW_2, \"dW_3\" = dW_3,\n  \"db_1\" = db_1, \"db_2\" = db_2, \"db_3\" = db_3) )\n}\n\nbackPropagation <- function(){\n  learningRate <- 0.01\n  params <- initParams(125,1)\n\n  N= 100000\n  for (iter in 1:N) {\n    x <- -2+4*runif(1)\n    y <- x^3\n    grad <- gradient(x,y,params$W, params$b)\n\n    params$W[[1]] <- params$W[[1]]-learningRate*grad$dW_1\n    params$W[[2]] <- params$W[[2]]-learningRate*grad$dW_2\n    params$W[[3]] <- params$W[[3]]-learningRate*grad$dW_3\n\n    params$b[[1]] <- params$b[[1]]-learningRate*grad$db_1\n    params$b[[2]] <- params$b[[2]]-learningRate*grad$db_2\n    params$b[[3]] <- params$b[[3]]-learningRate*grad$db_3\n\n    #if (iter %% 1000 == 0) print(iter)\n  }\n  return( params )\n}\n\nans = backPropagation()\n\\end{lstlisting}\n\nNow, we plot the predicted values of our model against the true curve $f(x) = x^3$. As we can see, the results resemble the true model really good.\n\n\\begin{lstlisting}[language=R]\ncall_forward_pass <- function(x){\n  forwardPass(x,ans$W, ans$b)$output\n}\n\ndf <- tibble(x = seq(-2,2,.05)) %>%\n        mutate(y = map(x, ~call_forward_pass(.x)), y = as.numeric(y))\n\nggplot(df, aes(x,y)) +\n  geom_point() +\n  stat_function(fun=function(x) x^3, col = 'red') +\n  scale_colour_manual(\"Lgend title\", values = c(\"red\", \"blue\"))\n\\end{lstlisting}\n\n\\begin{figure}[H]\n    \\begin{center}\n        \\includegraphics[width=0.9\\textwidth]{img/img1.jpg}\n        \\caption{}\n    \\end{center}\n\\end{figure}\n\n\\section{Learning Keras}\nIn this assignment we will fit a neural network for classifying images. We will use Keras, which is an extensive deep learning package in Python. Keras can be used in R through the keras package. But first we need to install it, see the steps below.\n\nTo get started with Keras follow the tutorial at \\url{https://keras.rstudio.com/articles/getting\\_started.html}.\n\nThe documentationt to the fit function is availible at: \\url{https://keras.rstudio.com/reference/fit.keras.engine}. training.Model.html. Look at the documentation and answer the following questions:\n\n- Explain what a batch size is.\n- Explain what an epoch is.\n- Explain why the shuffle argument is default set to true, i.e. why do you want to shuffle? Can you think of example’s when shuffling is a bad idea?\n\n\\subsection{Batch Size}\nIs the number of samples that will be propagated through the network per gradient update, that is to say in one forward/backward pass. Some of the advantages of using a batch size smaller than the number of all samples are that it requires less memory and that the training process is usually faster because we update the weights after each propagation. A disadvantage of using a batch size smaller than the number of samples is that the smaller the batch the less accurate the estimate of the gradient will be. In general we have\n\\begin{itemize}\n    \\item  \\textbf{Batch Gradient Descent}. Batch Size = Size of Training Set\n    \\item \\textbf{Stochastic Gradient Descent}. Batch Size = 1\n    \\item \\textbf{Mini-Batch Gradient Descent}. 1 < Batch Size < Size of Training Set. Popular batch sizes include 32, 64, and 128 samples.\n\\end{itemize}\n\n\\subsection{Epoch}\nIn general, one epoch means that each sample in the training dataset has had an opportunity to update the internal model parameters, an epoch is comprised of one or more batches. A way to understand it is the following: we have a first for-loop over the number of epochs, in each loop we will a nested for-loop that iterates over each batch of sample.\n\nIn keras, the epoch parameter defines the number times that the learning algorithm will work through the entire training dataset.\n\n\\subsection{Shuffle}\nThis argument is a boolean that determines whether to shuffle the trining data before each epoch. The reason to set it by default is that we want the model to understand all inputs equally. For example, if the data is ordered by class, then the training result will be a bad one because the model will have a higher accuracy for the last class it trains than the first one.\n\nAnother reason why shuffle is true by default is that the objective function might have numerous minima, and therefore gradient descent algorithms are susceptible to becoming \"stuck\" in those minima. This is likely to occur if the set of observations is unchanged over all training iterations. Shuffling observations might help the solver to \"bounce\" out of a local minimum.\n\nFor the Batch Gradient Descent process (Batch Size = Size of Training Set) shuffling is unnecessary.\n\n\n\\section{Fitting a Model in keras}\n\nNow we'll fit a feed-forward neural network to the dataset \\textit{dataset\\_fashion\\_mnist()}. For the following part python was used.\n\n\\begin{python}\nimport keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D\nfrom keras.datasets import fashion_mnist\n\nfrom matplotlib import pyplot as plt\n\n# Loading fashion_mnist dataset\nfashion_mnist = keras.datasets.fashion_mnist\n(train, test = fashion_mnist.load_data()\n(train_images, train_labels) = train\n(test_images, test_labels) = test\n\n# Turning pixel values to values in the interval $[0,1]$\ntrain_images = train_images / 255.0\ntest_images = test_images / 255.0\n\n# Reshaping\ntrain_images = train_images.reshape(-1,28,28,1)\ntrain_images = train_images.astype('float32')\ntest_images = test_images.reshape(-1,28,28,1)\ntest_images = test_images.astype('float32')\n\n# Neural net architecture\nmodel = Sequential()\n\n# Convolutional and max pooling layers since we are dealing with images\nmodel.add(Conv2D(filters=64, kernel_size=2,\n                 padding='same', activation='relu',\n                 input_shape=(28,28,1)))\nmodel.add(MaxPooling2D(pool_size=2))\n# Dropout to deal with overfitting\nmodel.add(Dropout(0.25))\n\n# Repeat convolutional - max pooling - dropout\nmodel.add(Conv2D(filters=32, kernel_size=2,\n                 padding='same', activation='relu'))\nmodel.add(MaxPooling2D(pool_size=2))\nmodel.add(Dropout(0.25))\n\n# Flattening\nmodel.add(Flatten())\n\n# Dense layer with 128 hidden units and relu activation\nmodel.add(Dense(128, activation='relu'))\n\n# Droput to deal with overfitting\nmodel.add(Dropout(0.5))\n\n# Output layer\nmodel.add(Dense(10, activation='softmax'))\n\n# Compiling model\nmodel.compile(loss = 'sparse_categorical_crossentropy',\n              optimizer = keras.optimizers.adam(),\n              metrics = ['accuracy'])\n\n# Training\nmodel.fit(train_images, train_labels, epochs=10, validation_split=0.2)\n\n# Evaluating\ntest_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)\n# Test error = 0.914\n\n# Plotting validation curve\nhistory = model.history\nplt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'val'], loc='upper left')\nplt.show()\n\\end{python}\n\nThe test error was $.914$ and the validation curve is given in the following figure:\n\\begin{figure}[H]\n    \\begin{center}\n        \\includegraphics[width=0.8\\textwidth]{img/img2.jpg}\n        \\caption{Validation curve}\n    \\end{center}\n\\end{figure}\n\n\n\\end{document}\n", "meta": {"hexsha": "d0bcf1ef0f27c515c8c62e8b75a27d956bdf5ab0", "size": 11734, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/Proyect3_solution.tex", "max_stars_repo_name": "SergioArnaud/Statistical-Learning", "max_stars_repo_head_hexsha": "e4ee81c02fea996794df70a277f1ad51e6fb1a83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-13T21:25:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-13T21:25:23.000Z", "max_issues_repo_path": "HW3/Proyect3_solution.tex", "max_issues_repo_name": "SergioArnaud/Statistical-Learning", "max_issues_repo_head_hexsha": "e4ee81c02fea996794df70a277f1ad51e6fb1a83", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW3/Proyect3_solution.tex", "max_forks_repo_name": "SergioArnaud/Statistical-Learning", "max_forks_repo_head_hexsha": "e4ee81c02fea996794df70a277f1ad51e6fb1a83", "max_forks_repo_licenses": ["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.5117647059, "max_line_length": 530, "alphanum_fraction": 0.6781148798, "num_tokens": 3762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6385839136377387}}
{"text": "\\chapter{Interpreting a Logistic Regression Model \\label{chapter:logreg}}\n\nThis chapter is similar to Chapter~\\ref{chapter:linreg} but focuses on logistic regression models. As we saw in Chapter~\\ref{chapter:linreg}, linear regression models are used in situations where the outcome of a supervised learning problem, $y$, follows a normal distribution, conditional on the values of the predictors. \\textbf{Logistic regression} models, in contrast, handle situations where the outcome, $y$, is binary: either 0 or 1. We first encountered these models as examples of classification algorithms in Chapter~\\ref{chapter:classification}. Because of their popularity in the clinical domain, it's important to understand how these models are fit and how to interpret the summary output produced by software. \n\nUnfortunately, a full understanding of logistic regression requires knowledge of maximum likelihood estimation. We will, therefore, skip over some of the details until we've had more time to explore this topic. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{ER Readmissions Example from Chapter~\\ref{chapter:classification} \\label{sect:eragain}}\n\nIn Chapter~\\ref{chapter:classification}, we saw an example where information about two predictors -- a disease severity score ($x_1$) and a social determinants score ($x_2$) -- was used to predict a binary outcome: whether a patient would be readmitted to the ER within 30 days of discharge. We tried three different supervised learning algorithms, one of which was a logistic regression model (Section~\\ref{ssect:logreg}). The output from that model is repeated below.\n\n\\begin{center}\n\\includegraphics[width=0.35\\textwidth]{img/esl-logistic.png}\n\\includegraphics[width=0.64\\textwidth]{img/glm-binomial-example.png}\n\\end{center}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Understanding the Model Summary}\n\nA logistic regression model looks like this (see also Section~\\ref{ssect:logreg}):\n\\begin{equation} \\log \\frac{\\mu}{1-\\mu} = \\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p \\label{eqn:logistic} \\end{equation}\nwhere $\\mu$ is the mean of the Bernoulli distribution (see Section~\\ref{sect:bernoulli}) governing our binary outcome, $y$; in other words, it is the probability that $y = 1$. \n\nYou will note that there is no independent error term here as there was in linear regression. That's because the variance and mean of a Bernoulli distribution are coupled and depend only on $\\mu$ (again, see Section~\\ref{sect:bernoulli}). \n\\vspace{3mm}\n\n\\begin{question}{question:logreglink}\nIn logistic regression, $\\mu$ itself is not equal the sum of the predictors; instead, the \\textbf{logit} of $\\mu$ is their sum. Based on what you know about $\\mu$, why is a logistic regression model not of the form\n$$ \\mu = \\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p \\text{?}$$\nWe will explore this further in Chapter~\\ref{chapter:glms}.\n\\end{question}\n\n\\begin{question}{}\nThe decision boundary in logistic regression (see picture above) occurs where the sum of the linear predictors, $\\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p$, is zero. What value of $\\mu$ does this correspond to? Why does this make sense, intuitively?\n\\end{question}\n\n\\subsection{The Call}\n\nThe first line of the output repeats the call you made to the \\verb|glm| function in R to fit the model. The \\texttt{glm} package fits a variety of different generalized linear models using maximum likelihood estimation (see Chapter~\\ref{chapter:mlebasics}; this will also be discussed in more detail in Chapter~\\ref{chapter:glms}). The \\texttt{family = \"binomial\"} argument tells the function to fit a logistic regression model.\n\n\\subsection{Coefficients and Standard Errors}\n\nLogistic regression models, like other GLMs, are fit using maximum likelihood (see Chapter~\\ref{chapter:mlebasics} for a brief introduction). We will skip most of the details for now, but you can gain intuition by staring at Equation~\\ref{eqn:logistic}. This equation says that the model's predicted value of $\\mu$, the probability that the outcome will be positive ($y=1$), is controlled by the values of the predictors and their coefficients $\\beta_0, \\dots, \\beta_p$. \n\nBy adjusting the values of the $\\beta$s, the model causes $\\mu$ to be high in regions of the feature space where $y=1$ and low where $y=0$. The values of the $\\beta$s that do this the best are called the \\textbf{maximum likelihood estimates}, and they are the coefficients shown in the model output.\n\nAs with linear regression, a full understanding of the standard errors requires matrix multiplication. However, they are related to the same factors that drive the standard errors in linear regression: (1) the spread of the values of the corresponding covariate about its mean (more spread will decrease the standard error) and (2) correlations between that covariate and other covariates in the model (tighter correlations will increase the standard error).\n\\vspace{5mm}\n\n\\begin{question}{}\nLooking at the form of the logistic regression model\n$$ \\log \\frac{\\mu}{1-\\mu} = \\beta_0 + \\beta_1 x_1 + \\dots + \\beta_p x_p $$\nwhat does the value of each of the $\\beta$s mean? What is $\\beta_j$ telling us about how $y$ varies with the predictor $j$, all else being equal?\n\\end{question}\n\n\\begin{question}{}\nThe \\textbf{odds} of something happening are defined as $\\mu/(1-\\mu)$, where $\\mu$ is the probability that the thing occurs. In our example model, we are interested in the odds that $y=1$ (the patient is readmitted). Does a unit increase in $x_1$ (disease severity score) increase or decrease the odds that a patient will be readmitted? What about $x_2$ (social determinants score)? \n\\end{question}\n\n\\begin{question}{}\nWhat are the odds of readmission for a patient with:\n\\begin{enumerate}[label=(\\alph*)] \n\\item $x_1 = 0.1$ and $x_2 = 0.3$?\n\\item $x_1 = 0.1$ and $x_2 = -1.3$?\n\\item $x_1 = 1.1$ and $x_2 = 0.3$?\n\\end{enumerate}\n\\end{question}\n\n\\subsection{Hypothesis Tests of Coefficients}\n\nJust as in linear regression, we can use our coefficients and standard errors to perform a hypothesis test on each regression coefficient, $\\beta_j$, against the null hypothesis that $\\beta_j = 0$ (the predictor $x_j$ has no effect on the outcome). In logistic regression, the quantity $\\hat{\\beta_j}/\\text{se}(\\hat{\\beta}_j)$ will follow a normal distribution under the null.\n\\vspace{3mm}\n\n\\begin{question}{question:nulllogregexample}\nBelow are the null distributions for the hypothesis tests of our three regression coefficients, $\\beta_0$, $\\beta_1$, and $\\beta_2$. In each graph, the maximum likelihood estimate of the coefficient is shown as a vertical dashed line. Based on these graphs, can you tell why the $p$-values for $\\beta_0$ and $\\beta_2$ are low and the one for $\\beta_1$ is high? What is the intuition behind this?\n\\begin{center}\n\\includegraphics[width=0.45\\textwidth]{img/logreg-example-beta-0.png}\n\\includegraphics[width=0.45\\textwidth]{img/logreg-example-beta-1.png}\n\\includegraphics[width=0.45\\textwidth]{img/logreg-example-beta-2.png}\n\\end{center}\n\\end{question}\n\n\\subsection{Deviance and Deviance Residuals}\n\nThe \\textbf{deviance} (called \\textbf{residual deviance} in the model output) plays a role in GLMs akin to that of the residual standard error in linear regression; it is a measure of the residual variation in the outcome not explained by the model. The \\textbf{null deviance} is the deviance for a model that only includes an intercept. Under the null hypothesis that all of the $\\beta$s are zero except the intercept (i.e, a model with no predictors explains the data as well as our model), the difference\n$$ \\text{null deviance} - \\text{residual deviance} $$\nis distributed as $\\chi^2_p$, a chi-squared distribution (see Section~\\ref{sect:chisqdist}) with $p$ degrees of freedom, where $p$ is the number of predictors.\n\\vspace{5mm}\n\n\\begin{question}{}\nThis test is a hypothesis test of the null hypothesis that a model with no predictors fits our data as well as our model, where goodness of fit is measured by the deviance (lower is better). What is this hypothesis test akin to in the linear regression model output?\n\\end{question}\n\n\\begin{question}{}\nThe difference in null and residual deviances in this case is $67.72$. It follows a $\\chi^2_2$ distribution under the null. A plot of the $\\chi^2_2$ distribution and our test statistic is shown below. What do these findings indicate about the $p$-value of this goodness of fit test and what does it mean?\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/logreg-example-goodness-of-fit-test.png}\n\\end{center}\n\\end{question}\n\nIn the GLM context, there are multiple types of residual (more on this later). \\textbf{Deviance residuals} quantify the contributions of the individual samples to the deviance. Unfortunately, the output from \\texttt{glm} is confusing because what \\texttt{glm} calls a deviance residual in the model summary is actually something called a \\textbf{working residual}. We will ignore this part of the output until we understand more about the inner workings of GLMs. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Example: Low Birthweight Dataset \\label{sect:lowbwt}}\n\nThe goal of this study was to identify risk factors associated with giving birth to a low birth weight baby (a baby weighing less than 2500 grams). Infant mortality rates and birth defect rates are very high for low birth weight babies. A woman's behavior during pregnancy (including diet, smoking habits, and receiving prenatal care) can greatly alter the chances of carrying the baby to term and, consequently, of delivering a baby of normal birth weight.\n\nData were collected on 189 women, 59 of which had low birth weight babies and 130 of which had normal birth weight babies\\footnote{SOURCE: Hosmer and Lemeshow (2000) \\emph{Applied Logistic Regression: Second Edition}. Data were collected at Baystate Medical Center, Springfield, Massachusetts during 1986.}.\n\n\\begin{center}\n\\texttt{ \\small\n\\begin{tabular}{ll}\n\\toprule\nLOW & Low birth weight (0 = birth weight $\\geq$ 2500 g;\\\\\n& 1 = birth weight $< 2500$ g) \\\\\nAGE & Age of mother in years \\\\\nLWT & Mother's weight in pounds at last menstrual period \\\\\nRACE & Race (1 = white, 2 = black, 3 = other) \\\\\nSMOKE & Smoking status during pregnancy (1 = yes, 0 = no) \\\\\nPTL & History of premature labor (0 = none, 1 = one, etc.) \\\\\nHT & History of hypertension (0 = no, 1 = yes) \\\\\nUI & Presence of uterine irritability (0 = no, 1 = yes) \\\\\nFTV & Number of physician visits during the first trimester \\\\\nBWT & Birth weight in grams \\\\\n\\bottomrule\n\\end{tabular}\n}\n\\end{center}\n\nWe will build a model that predicts the value of \\texttt{LOW} based on all of the other covariates except, of course, \\texttt{BWT}. (Why not use \\texttt{BWT}?) \n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/logreg-low-bwt-example-model.png}\n\\end{center}\n\n\\begin{question}{}\nIn this model, is the effect of one predictor (say, \\verb|AGE|) impacted by the value(s) of any of the other predictor(s)? How does this differ from the other classification algorithms we've seen (KNN and decision trees)? What are the advantages and disadvantages of this choice? \n\\end{question}\n\n\\begin{question}{}\nComment on how the variable \\texttt{RACE} enters into the model here. Does this make sense in light of what that variable means and how it potentially interacts with the other study variables?\n\\end{question}\n\n\\begin{question}{}\nInterpret the values of each of these coefficients. Based on the coefficient values and their standard errors, which predictor(s) do you think have the greatest impact on whether or not a woman has a low birthweight baby? \n\\end{question}\n", "meta": {"hexsha": "cd7a660f69b6ba841dcc04b19a2d220e83c703a6", "size": 11764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-logistic-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-logistic-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-logistic-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": 78.4266666667, "max_line_length": 725, "alphanum_fraction": 0.75, "num_tokens": 2939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6385839115497753}}
{"text": "\\documentclass[12pt]{amsart}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem*{corollary}{Corollary}\n\\newtheorem*{lemma}{Lemma}\n\\theoremstyle{definition}\n\\newtheorem{problem}{Problem}\n\n\\newcommand{\\C}{\\mathbb{C}}\n\\DeclareMathOperator{\\re}{Re}\n\\renewcommand{\\iint}{\\int\\!\\!\\!\\int}   \n\\newcommand{\\Beta}{B}\n\n\\addtolength{\\headheight}{1.5pt}  \n\n\\begin{document}\n\n\\title{Lu Qi-Keng's Problem}\n\n\\author{Harold P. Boas}\n\n\\address{Department of Mathematics, Texas A\\&M University,\n  College Station, TX 77843--3368, USA}\n\n\\email{boas@math.tamu.edu}\n\n\\thanks{This article is based on a lecture at the third Korean\n  several complex variables symposium in December 1998.  The\n  author thanks GARC, the Global Analysis Research Center at\n  Seoul National University, for sponsoring his participation in\n  this international conference.}  \n\n\\thanks{The author's research was partially supported by grant\n  number DMS-9801539 from the National Science Foundation of the\n  United States of America.}\n\n\n\\begin{abstract}\n  This expository article, intended to be accessible to students,\n  surveys results about the presence or absence of zeroes of the\n  Bergman kernel function of a bounded domain in~\\(\\C^n\\). Six\n  open problems are stated.\n\\end{abstract}\n\n\\subjclass{Primary 32H10}\n\n\\maketitle\n\n\\setcounter{tocdepth}{1}\n\\tableofcontents\n\n\\section{Introduction}\nWhen does a convergent infinite series of holomorphic functions\nhave zeroes?  This question is a fundamental, difficult problem\nin mathematics.\n\nFor example, the series \\(\\sum_{n=0}^\\infty z^n/n!\\) is\nzero-free, but how can one tell this without a priori knowledge\nthat the series represents the exponential function? Changing the\ninitial term of this series produces a new series that does have\nzeroes, since the range of the exponential function is all\nnon-zero complex numbers. The problem of determining when a\nseries has zeroes is essentially equivalent to the hard problem\nof determining the range of a holomorphic function that is\npresented as a series.\n\nA famous instance of the problem of locating zeroes of infinite\nseries is the Riemann hypothesis about the zeta function: namely,\nthe conjecture that when \\(0<\\re z<1/2\\), the convergent series\n\\(\\sum_{n=1}^\\infty (-1)^n/n^z\\) has no zeroes. This formulation\nof the Riemann hypothesis is equivalent to the usual statement\nthat the zeroes of \\(\\zeta(z)\\) in the critical strip where\n\\(0<\\re z<1\\) all lie on the line where \\(\\re z=1/2\\). Indeed,\nwhen \\(\\re z>1\\), absolute convergence justifies writing that\n\\begin{equation*}\n\\sum_{n=1}^\\infty \\frac{(-1)^n}{n^z} = -\\sum_{n=1}^\\infty\n\\frac{1}{n^z} +2\\sum_{\\text{even \\(n\\)}}\\frac{1}{n^z}\n=\\zeta(z)(2^{1-z}-1).\n\\end{equation*}\nBy the principle of persistence of functional relationships, the\nexpressions on the outer ends of this equality still agree when\n\\(0<\\re z<1\\), so \\(\\zeta(z)\\) and \\(\\sum_{n=1}^\\infty\n(-1)^n/n^z\\) have the same zeroes in the interior of the critical\nstrip. Moreover, the well known functional equation for the zeta\nfunction implies that the zeroes of~\\(\\zeta\\) in the critical\nstrip are symmetric about the point~\\(1/2\\), so it suffices to\nexamine the left half of the critical strip for zeroes.\n\nIn this article, I shall discuss a different instance of the\ngeneral problem of locating zeroes of infinite series.  The\nBergman kernel function is most conveniently expressed as the sum\nof a convergent infinite series.  In 1966, Lu Qi-Keng \\cite{lu}\nasked: for which domains is the Bergman kernel function\n\\(K(z,w)\\) zero-free? I shall address three general methods for\napproaching this problem, and I shall give examples both of\ndomains whose Bergman kernel functions are zero-free and of\ndomains whose Bergman kernel functions have zeroes.\n\n\\section{The Bergman kernel function}\n\\subsection{Definition}\nThe Bergman kernel function \\(K(z,w)\\) of a domain~\\(D\\) in\n\\(\\C^n\\) is the unique\nsesqui-holomorphic\\footnote{Sesqui-holomorphic means holomorphic\n  in the first variable and conjugate holomorphic in the second\n  variable.} function satisfying the skew-symmetry property that\n\\(K(z,w)=\\overline {K(w,z)}\\) and the reproducing property that\n\\begin{equation*}\nf(z)=\\int_D K(z,w) f(w) \\,d\\text{Volume}_w  \\qquad \\text{for all\n  $z$ in $D$}\n\\end{equation*}\nfor every square-integrable holomorphic function~\\(f\\) on~\\(D\\).\nEquivalently, \\(K(z,w)=\\sum_j\n\\varphi_j(z)\\overline{\\varphi_j(w)}\\), where \\(\\{\\varphi_j\\}\\) is\nan orthonormal basis for the Hilbert space of square-integrable\nholomorphic functions on~\\(D\\). To compute the Bergman kernel\nfunction, one typically chooses an orthogonal basis, calculates\nthe normalizing factors, and sums the series.\n\nFor example, the monomials \\(1\\), \\(z\\), \\(z^2\\), \n\\ldots, are orthogonal on the unit disk in the complex plane, and\nthe norm of \\(z^k\\) is \\((\\int_{0}^{2\\pi} \\int_{0}^{1}\nr^{2k+1}\\,dr\\,d\\theta)^{1/2}\\), or \\(\\sqrt{2\\pi/(2k+2)}\\).\nTherefore the Bergman kernel function \\(K(z,w)\\) of the unit disk\nequals\n\\begin{equation}\n  \\label{eq:disk}\n  \\sum_{k=0}^\\infty \\frac{k+1}{\\pi} \\cdot z^k \\bar w^k \n  = \\frac{1}{\\pi}\\cdot \\frac{1}{(1-z\\bar w)^2}.\n\\end{equation}\nThis result is compatible with the Cauchy integral formula\n\\begin{equation*}\nf(z)=\\frac{1}{2\\pi i}\\oint_{|w|=1}\n\\frac{f(w)}{w-z}\\,dw,\n\\end{equation*}\nwhich can be rewritten by Green's formula as\n\\begin{equation*}\nf(z)=\\frac{1}{\\pi}\\iint_{|w|<1} \\frac{f(w)}{(1-z\\bar w)^2}\n\\,d\\text{Area}_w,\n\\end{equation*}\nthus confirming that the kernel function~\\eqref{eq:disk} does\nhave the required reproducing property.\n \n\\subsection{Transformation rule}\nIf \\(f:D_1\\to D_2\\) is a biholomorphic\\footnote{Biholomorphic\n  means holomorphic with a holomorphic inverse.} mapping, and if\n\\(K_1\\) and~\\(K_2\\) denote the Bergman kernel functions of the\ndomains \\(D_1\\) and~\\(D_2\\) in~\\(\\C^n\\), then\n\\begin{equation}\n\\label{eq:transform}\nK_1(z,w)=(\\det f'(z)) K_2(f(z), f(w)) (\\,\\overline{\\det f'(w)}\\,).\n\\end{equation}\nThis relationship holds because if \\(\\{\\varphi_j\\}\\) is an\northonormal basis for the square-integrable holomorphic functions\non~\\(D_2\\), then \\(\\{(\\det f') \\,\\varphi_j\\circ f\\}\\) is an\northonormal basis for the square-integrable holomorphic functions\non~\\(D_1\\). For example, scaling~\\eqref{eq:disk} shows that the\nBergman kernel function of the disk of radius~\\(r\\) is equal to\n\\(\\dfrac{1}{\\pi r^2}\\cdot \\dfrac{1}{(1-z\\bar w/r^2)^2}\\).\n\nIt is an observation of Steven~R. Bell \\cite{bell1981, bell1982}\nthat a similar transformation rule holds even when \\(f:D_1\\to\nD_2\\) is a branched \\(m\\)-fold covering (a proper holomorphic\nmapping): namely,\n\\begin{equation*}\n\\sum_{k=1}^m K_1(z, f_k^{-1}(w)) \n(\\,\\overline{\\det (f_k^{-1})'(w)}\\,) =\n(\\det f'(z)) K_2(f(z),w),\n\\end{equation*}\nwhere the \\(f_k^{-1}\\) are the \\(m\\) holomorphic local inverses\nof~\\(f\\).  This formula is not valid on the branching set, where\nlocal inverses are not defined.\n\nThe Bergman kernel function \\(K(z,w)\\) of a simply-connected\nplanar domain~\\(D\\) is related to the Riemann mapping\nfunction~\\(f\\) that maps~\\(D\\) onto the unit disk, taking the\npoint~\\(a\\) to~\\(0\\): namely,\n\\begin{equation}\n\\label{eq:riemann}\nf'(z)=K(z,a)\\sqrt{\\frac{\\pi}{K(a,a)}}.\n\\end{equation}\nIndeed, the  transformation rule~\\eqref{eq:transform} implies that\n\\begin{equation*}\nK(z,w)=f'(z)\\cdot\\frac{1}{\\pi}\\cdot\n\\frac{1}{(1-f(z)\\overline{f(w)}\\,)^2}\\cdot\\overline{f'(w)}.\n\\end{equation*}\nSince \\(f(a)=0\\), and \\(f'(a)\\) is real and positive,\nsetting \\(w=a\\) implies that\n\\begin{math}\n\\pi K(z,a)=f'(z) f'(a)\n\\end{math},\nand then setting \\(z=a\\) makes it possible to eliminate~\\(f'(a)\\)\nto obtain~\\eqref{eq:riemann}.\n\nSince the Riemann mapping function solves a certain extremal\nproblem, the connection in one dimension with the Bergman kernel\nfunction suggests studying the Bergman kernel function in higher\ndimensions in connection with extremal problems.\n\n\\subsection{Extremal properties}\n\\label{extremal}\nOne can use extremal characterizations of the Bergman kernel\nfunction to help prove theorems about convergence of the Bergman\nkernel functions of a convergent sequence of domains.  In the\nfollowing two properties, the point~\\(w\\) is fixed in a\ndomain~\\(D\\) in~\\(\\C^n\\), and \\(\\{\\varphi_j\\}\\) is an orthonormal\nbasis for the Hilbert space \\(A^2(D)\\) of square-integrable\nholomorphic functions on~\\(D\\).\n\n\\begin{enumerate}\n\\item In the class of holomorphic functions~\\(f\\) on~\\(D\\) such\n  that \\(\\int_D |f|^2\\le 1\\), the maximal value of \\(|f(w)|^2\\)\n  is \\(K(w,w)\\). In other words, \\(K(w,w)\\) is the square of the\n  norm of the functional from \\(A^2(D)\\) to~\\(\\C\\) that\n  evaluates a function at the point~\\(w\\).\n  \n  Indeed, if \\(f(z)=\\sum_j c_j \\varphi_j(z)\\), and if \\(\\sum_j\n  |c_j|^2\\le1\\), then the Cauchy-Schwarz inequality implies that\n  \\(|\\sum_j c_j \\varphi_j(w)|^2\\) is bounded above by \\(\\sum_j\n  |\\varphi_j(w)|^2\\), which equals \\(K(w,w)\\); and the upper\n  bound is attained if \\(c_j\\) is taken equal to\n  \\(\\overline{\\varphi_j(w)}/(\\sum_j |\\varphi_j(w)|^2)^{1/2}\\).\n  \n\\item In the class of holomorphic functions~\\(f\\) on~\\(D\\)\n  satisfying the nonlinear constraint that \\(f(w)\\ge \\int_D\n  |f|^2\\), the function with the maximal value at~\\(w\\) is\n  \\(K(\\cdot,w)\\).\n  \n  Indeed, it is evident that the function \\(K(\\cdot,w)= \\sum_j\n  \\overline{\\varphi_j(w)}\\,\\varphi_j\\) is in the class. On the\n  other hand, if \\(f=\\sum_j c_j \\varphi_j\\) is an arbitrary\n  member of the class, then the preceding extremal property\n  implies that \\(f(w)^2\\le K(w,w)\\sum_j |c_j|^2\\); and since the\n  defining property of the class implies that \\((\\sum_j\n  |c_j|^2)^2 \\le f(w)^2\\), it follows that \\(\\sum_j|c_j|^2\\le\n  K(w,w)\\), and hence \\(f(w)\\le K(w,w)\\).\n\\end{enumerate}\n\n\\section{Motivation for Lu Qi-Keng's problem}\nThe Riemann mapping theorem characterizes the planar domains that\nare biholomorphically equivalent to the unit disk. In higher\ndimensions, there is no Riemann mapping theorem,\\footnote{More\n  precisely, in order to obtain a generalized Riemann mapping\n  theorem, one needs either new hypotheses \\cite{chernji} or new\n  definitions \\cite{semmes}.} and two natural problems arise.\n\n\\begin{enumerate}\n\\item Are there canonical representatives of biholomorphic\n  equivalence classes of domains?\n  \n\\item How can one tell that two particular domains are\nbiholomorphically inequivalent?\n\\end{enumerate}\n\nAs an approach to the first question, Stefan Bergman introduced\nthe notion of a ``representative domain'' to which a given domain\nmay be mapped by ``representative coordinates''.  If \\(g_{jk}\\)\ndenotes the Bergman metric\n\\begin{math}\n\\dfrac{\\partial^2}{\\partial z_j\\partial\\bar  z_k}\\log K(z,z)\n\\end{math},\nwhere \\(K\\)~is the Bergman kernel function, then the local\nrepresentative coordinates based at the point~\\(a\\) are\n\\begin{equation*}\n\\sum_{k=1}^n\ng_{kj}^{-1}(a) \\left. \\frac{\\partial}{\\partial \\bar w_k} \\log\n\\frac{K(z,w)}{K(w,w)} \\right|_{w=a}, \\qquad j=1, \\dotsc, n.\n\\end{equation*}\nThese coordinates take \\(a\\) to~\\(0\\) and have complex Jacobian\nmatrix at~\\(a\\) equal to the identity.\n\nZeroes of the Bergman kernel function \\(K(z,w)\\) evidently pose\nan obstruction to the global definition of Bergman representative\ncoordinates. This observation was Lu Qi-Keng's motivation for\nasking which domains have zero-free Bergman kernel functions.\n\nOn the other hand, if the Bergman kernel function of a domain\ndoes have zeroes, then the transformation\nrule~\\eqref{eq:transform} shows that the zero set is a\nbiholomorphically invariant object. Therefore zero sets of\nBergman kernel functions could be a tool for addressing the\nsecond question stated above. This idea has not yet been\nexploited in the literature.\n\n\\section{First examples}\n\\label{first}\nThe Bergman kernel function~\\eqref{eq:disk} of the unit disk is\nevidently zero-free.  Consequently, the Bergman kernel function\nof every bounded, simply connected, planar domain is zero-free:\napply either the transformation rule~\\eqref{eq:transform} or the\nexplicit formula~\\eqref{eq:riemann} relating the Riemann mapping\nfunction to the Bergman kernel function.\n\nOn the other hand, the Bergman kernel function of every annulus\ndoes have zeroes \\cite{rosenthal,skwar}; more generally, the\nBergman kernel function of every bounded, multiply connected,\nplanar domain with smooth boundary has zeroes \\cite{suitayamada}.\n\nIsolated singularities of square-integrable holomorphic functions\nare removable, and therefore the Bergman kernel function does not\nsee isolated punctures in a domain.  For example, the Bergman\nkernel function of a punctured disk is zero-free. On the other\nhand, a finitely connected planar domain with no singleton\nboundary component can be mapped biholomorphically to a smoothly\nbounded domain.  Consequently, if a bounded planar domain is\nfinitely connected and has at least two non-singleton boundary\ncomponents, then its Bergman kernel function has zeroes.\n\nI do not know if a corresponding statement holds for infinitely\nconnected planar domains. For example, delete from the open unit\ndisk a countable sequence of pairwise disjoint closed disks that\naccumulate only at the boundary of the unit disk. Does the\nBergman kernel function of the resulting domain have zeroes?\n\n\\begin{problem}\n  Give necessary and sufficient conditions on an infinitely\n  connected planar domain for its Bergman kernel function to have\n  zeroes.\n\\end{problem}\n\nIt is easy to see that in higher dimensions, the Bergman kernel\nfunction of a product domain is the product of the Bergman kernel\nfunctions of the lower dimensional domains. Consequently, the\nBergman kernel function of a polydisc is zero-free, while the\nBergman kernel function of the Cartesian product of a disc with\nan annulus does have zeroes. The Bergman kernel function\n\\(K(z,w)\\) of the unit ball in~\\(\\C^n\\) is the zero-free function\n\\(\\dfrac{n!}{\\pi^n}\\cdot \\dfrac{1}{(1-\\langle\nz,w\\rangle)^{n+1}}\\), where \\(\\langle z,w\\rangle\\) denotes the\nscalar product \\(z_1\\bar w_1 + \\dots + z_n \\bar w_n\\).\n\nEven without knowing this explicit formula, one can see that the\nBergman kernel function of the unit ball is zero-free.  Since the\nball is a complete circular domain,\\footnote{A domain is called\n  complete circular if whenever it contains a point~\\(z\\), it\n  also contains the one-dimensional disk \\(\\{\\,\\lambda z:\n  |\\lambda|\\le1\\,\\}\\).}  its space of square-integrable\nholomorphic functions has an orthonormal basis whose first\nelement is a constant (namely, the reciprocal of the square root\nof the volume of the domain) and whose other elements are\nfunctions that vanish at the origin.  Consequently, the Bergman\nkernel function~\\(K\\) has the property that \\(K(z,0)\\) is a\nnon-zero constant function of~\\(z\\). Since the ball is\nhomogeneous,\\footnote{A domain is called homogeneous if it has a\n  transitive automorphism group, that is, if any point of the\n  domain can be mapped to any other point by a biholomorphic\n  self-mapping of the domain.}  the transformation\nrule~\\eqref{eq:transform} implies that the Bergman kernel\nfunction is nowhere zero. The same argument shows that every\nbounded, homogeneous, complete circular domain has a zero-free\nBergman kernel function \\cite{belldavid}.\n\nFor many years it was thought that sufficiently nice,\ntopologically trivial, bounded domains in~\\(\\C^n\\) should have\nzero-free Bergman kernel functions. For example, all strongly\nconvex,\\footnote{The statement is also true for strongly\n  pseudoconvex domains, that is, domains that locally can be\n  mapped biholomorphically to strongly convex domains.}\nsufficiently small perturbations of the ball have zero-free\nBergman kernel functions if ``small'' is interpreted in the\n\\(C^\\infty\\) topology on domains \\cite{greenekrantz}.  It turns\nout, however, to be the generic situation for the Bergman kernel\nfunction of a domain of holomorphy to have zeroes, if ``generic''\nis interpreted in the very flexible Hausdorff topology on domains\n\\cite{boasgeneric}.\n\n\\begin{problem}\n  Do there exist arbitrarily small class \\(C^1\\) perturbations of\n  the ball whose Bergman kernel functions have zeroes?\n\\end{problem}\n\nI shall now discuss three techniques that can be used to show the\nexistence of interesting domains whose Bergman kernel functions\nhave zeroes.\n\n\\section{Variation of domains}\n\\label{variation-domains}\nIf reasonable domains \\(\\Omega_j\\) converge in a reasonable way\nto a limiting domain \\(\\Omega\\), then the Bergman kernel\nfunctions \\(K_{\\Omega_j}(z,w)\\) converge to \\(K_\\Omega(z,w)\\)\nuniformly on compact subsets of \\(\\Omega\\times\\Omega\\).  The word\n``reasonable'' can be made precise \\cite{boasgeneric}, but here I\nwill simply mention two examples of reasonable behavior. The\nfirst example is a fundamental theorem of I.~P. Ramadanov\n\\cite{ramadanov} which started the whole theory.\n\\begin{itemize}\n\\item The \\(\\Omega_j\\) form an increasing sequence whose union\n  is~\\(\\Omega\\).\n  \n\\item The \\(\\Omega_j\\) are bounded pseudoconvex\\footnote{A domain\nis pseudoconvex if it is the union of an increasing sequence of\nstrongly pseudoconvex domains, as defined in the preceding\nfootnote. According to the solution of the Levi problem (see, for\nexample, \\cite{Krantz}), pseudoconvex domains are the same as\ndomains of holomorphy.} domains whose complements converge in the\nHausdorff metric to the complement of an~\\(\\Omega\\) whose\nboundary is locally a graph.\n\\end{itemize}\nAn example of unreasonable convergence is a sequence of disks\nshrinking down to a disk with a slit \\cite{skwarczynski}.\n\nThe proof of the convergence theorem exploits the extremal\ncharacterization of the Bergman kernel function from\nsection~\\ref{extremal}. The application to Lu Qi-Keng's problem\nis that by Hurwitz's theorem, if the Bergman kernel function of\nthe limiting domain~\\(\\Omega\\) has zeroes, then so does the\nBergman kernel function of the approximating domain~\\(\\Omega_j\\)\nwhen \\(j\\)~is sufficiently large.\n\nConsequently, to construct a nice domain whose Bergman kernel\nfunction has zeroes, it suffices to construct a degenerate domain\nwhose Bergman kernel function has zeroes, and then to approximate\nthe degenerate domain by nice ones. For example, an easy\ncalculation shows that constant functions are not\nsquare-integrable on the domain\n\\begin{equation}\n\\label{eq:counterex}\n  \\left\\{\\, (z_1,z_2)\\in\\mathbf{C}^2: |z_2|<\\frac{1}{1+|z_1|}\\,\n\\right\\},\n\\end{equation}\nalthough the domain does support some non-constant\nsquare-integrable holomorphic functions. Therefore the Bergman\nkernel function of this domain has a zero at the origin, but is\nnot identically zero.  By approximating this domain from inside,\none sees that there exists a bounded, smooth, logarithmically\nconvex, complete Reinhardt domain\\footnote{A domain is called\n  complete Reinhardt if whenever it contains a point\n  \\((z_1,\\dotsc,z_n)\\), it also contains the polydisc\n  \\(\\{\\,(\\lambda_1z_1, \\dotsc, \\lambda_nz_n): |\\lambda_1|\\le1,\n  \\dotsc, |\\lambda_n|\\le1\\,\\}\\). The logarithmically convex\n  complete Reinhardt domains are the convergence domains of power\n  series.}  whose Bergman kernel function has zeroes\n\\cite{boascounterexample}.  This example was surprising when it\nwas first discovered; indeed, it contradicts a theorem previously\npublished by two different authors \\cite[Theorem~1]{matsuura},\n\\cite[Corollary]{kakurai} and applied by a third \\cite{kanemaru}.\n\nNguy\\^en Vi\\^et Anh, a student in Marseille, recently showed\n\\cite{anh} how to approximate the domain~\\eqref{eq:counterex}\nfrom inside by \\emph{concrete} domains that are smooth,\nalgebraic, logarithmically convex, complete Reinhardt domains.\nNamely, the domain defined by the inequality\n\\begin{equation}\n\\label{eq:anh}\n  |z_2|^{2k}(1+|z_1|)^{2k} + |z_2|^{2k}(1-|z_1|)^{2k} + \\left(\n  \\frac{|z_1|^2+|z_2|^2} {k}\\right)^k <1\n\\end{equation}\nhas the indicated properties when \\(k\\)~is a positive integer,\nand so the Bergman kernel function of this domain must have\nzeroes when \\(k\\)~is sufficiently large.\n\n\\begin{problem}\n  How large must \\(k\\) be in order for the Bergman kernel\n  function of the domain~\\eqref{eq:anh} to have zeroes?\n\\end{problem}\n\nThe technique of variation of domains can be used to prove the\nstatement at the end of section~\\ref{first} that every nice\ndomain can be arbitrarily closely approximated in the Hausdorff\nmetric by a nice domain whose Bergman kernel function has zeroes.\nView the starting domain as the Earth, and place in orbit around\nthe Earth a small copy of one of the bounded domains just\ndiscussed. The Bergman kernel function of this disconnected\nregion has zeroes because the Bergman kernel function of the\nsatellite has zeroes. Now attach the satellite to the Earth by a\nthin tether. If the tether is sufficiently thin, then the\nprinciple of variation of domains implies that the Bergman kernel\nfunction of the joined domain has zeroes. According to the\nbarbell lemma \\cite[Chapter~5, Exercise~21]{Krantz} in a suitable\nformulation \\cite{boasgeneric}, the joined domain can be made\nstrongly pseudoconvex if the Earth is.\n\n\\section{Variation of weights}\nIn the representation of the Bergman kernel function as an\ninfinite series \\(\\sum_j \\varphi_j(z)\\overline{\\varphi_j(w)}\\),\nthe basis elements~\\(\\varphi_j\\) are supposed to be orthonormal\nfor integration with respect to Lebesgue measure.  It is natural\nto consider the analogous construction when Lebesgue measure is\nmultiplied by a positive weight function.\n\nFor instance, if \\(G\\)~is a domain in~\\(\\C^n\\), and \\(\\Omega\\)~is\na Hartogs domain in~\\(\\C^{n+1}\\) with base~\\(G\\), which means\nthat \\(\\Omega = \\{\\,(z,z_{n+1})\\in\\C^{n+1}: z\\in G\\) and\n\\(|z_{n+1}|<r(z)\\,\\}\\), where \\(r\\)~is a positive function\non~\\(G\\), then the Bergman kernel function of~\\(\\Omega\\)\nrestricted to the base~\\(G\\) equals the weighted Bergman kernel\nfunction of~\\(G\\) corresponding to the weight \\(\\pi r^2\\). This\nfollows because the Bergman kernel function is uniquely\ndetermined by its reproducing property, and holomorphic functions\non~\\(G\\) correspond to holomorphic functions on~\\(\\Omega\\) that\nare independent of the extra variable. Consequently, zeroes of\nweighted Bergman kernel functions give rise to zeroes of ordinary\nBergman kernel functions of higher-dimensional domains.\n\nAs a concrete example, consider on a bounded domain~\\(G\\)\nin~\\(\\C^n\\) containing the origin the weight function\n\\(\\exp(-t\\|z\\|)\\), where \\(t\\) is a real parameter, and\n\\(\\|z\\|\\)~denotes the Euclidean length\n\\(\\sqrt{|z_1|^2+\\dots+|z_n|^2}\\).  Let \\(K_t(z,w)\\) denote the\nBergman kernel function of~\\(G\\) with respect to this weight. It\nis a special case of a recent theorem of Miroslav Engli{\\v{s}}\n\\cite{englis} that this weighted Bergman kernel function must\nhave zeroes near the origin when \\(t\\)~is sufficiently large.\n\nRemarkably, the proof depends on the non-smoothness of the weight\nfunction.  The idea is to show that\n\\(\\lim_{t\\to\\infty}K_t(z,z)^{1/t}=e^{\\|z\\|}\\). It follows that\nthe function \\(K_t(z,w)\\) cannot be zero-free for every\nlarge~$t$, for if it were, then a sesqui-holomorphic branch of\n\\(K_t(z,w)^{1/t}\\) could be defined near the origin.  When\n\\(t\\to\\infty\\), there would be a limiting sesqui-holomorphic\nfunction \\(L(z,w)\\) such that \\(L(z,z)=e^{\\|z\\|}\\); but this is\nimpossible because the function~\\(e^{\\|z\\|}\\) is not real\nanalytic at the origin.\n\nThe verification that\n\\(\\lim_{t\\to\\infty}K_t(z,z)^{1/t}=e^{\\|z\\|}\\) is carried out via\nan upper estimate and a lower estimate.  Let \\(\\|f\\|_t\\) denote\nthe weighted norm \\((\\int_G |f(w)|^2 e^{-t\\|w\\|}\\, dV_w)^{1/2}\\).\nIf \\(f\\)~is a holomorphic function, and \\(B_z\\)~is a small ball\ncentered at~\\(z\\) with volume \\(|B_z|\\), then the mean-value\nproperty of holomorphic functions and the Cauchy-Schwarz\ninequality imply that \\(|f(z)|\\) is bounded above by \\(\\|f\\|_{t}\n\\,|B_z|^{-1} (\\int_{B_z} e^{t\\|w\\|}\\, dV_w)^{1/2}\\). Therefore\n\\(K_t(z,z)\\), which is the square of the norm of the point\nevaluation functional, is bounded above by \\(|B_z|^{-1}\n\\sup_{w\\in B_z} e^{t\\|w\\|}\\), and so \\(\\limsup_{t\\to \\infty}\nK_t(z,z)^{1/t} \\le \\sup_{w\\in B_z} e^{\\|w\\|}\\). Now let the\nradius of the ball~\\(B_z\\) shrink to zero to conclude that\n\\(\\limsup_{t\\to \\infty} K_t(z,z)^{1/t} \\le e^{\\|z\\|}\\).\n\nFor the lower bound, use the convexity of the Euclidean norm and\nthe representation of a supporting hyperplane as the zero set of\nthe real part of a linear holomorphic function. For each\npoint~\\(z\\) in the domain, there is a holomorphic function~\\(g\\)\nsuch that \\(\\re g(w)\\le\\|w\\|\\) for all~\\(w\\), and \\(\\re\ng(z)=\\|z\\|\\).  Since \\(K_t(z,z)\\) is the square of the norm of\nthe point evaluation functional, it is no smaller than\n\\(|e^{tg(z)}|/\\|e^{tg/2}\\|_t^2\\), which in turn is no smaller\nthan \\(e^{t\\|z\\|}\\) divided by the volume of the domain.\nConsequently, \\(\\liminf_{t\\to\\infty} K_t(z,z)^{1/t}\\ge\ne^{\\|z\\|}\\).\n\n  \\begin{problem}\n    For concrete examples, determine how large \\(t\\) must be\n    taken in Engli{\\v{s}}'s theorem to guarantee that the\n    weighted Bergman kernel function has zeroes.\n  \\end{problem}\n\n\\section{Weighted disk kernels and convex domains}\nIn the preceding section, I remarked that the Bergman kernel\nfunction of a Hartogs domain in~\\(\\C^{n+1}\\) is related to a\nweighted Bergman kernel function on the base domain in~\\(\\C^n\\).\nFor the same reason, a multi-dimensional domain that is fibered\nover a one-dimensional base has a Bergman kernel function that is\nrelated to a weighted Bergman kernel function on the base.  In\nthis section, I shall discuss an interesting example of this\ngeneral principle.\n\nThe domain in~\\(\\C^n\\) defined by the inequality\n\\begin{equation}\n\\label{eq:ex}\n|z_1| + |z_2|^{2/p_2} + \\dots + |z_n|^{2/p_n} <1\n\\end{equation}\nhas a Bergman kernel function whose restriction to the\n\\(z_1\\)-axis is proportional to the weighted Bergman kernel\nfunction for the unit disk \\(\\{z\\in\\C: |z|<1\\}\\) with weight\n\\((1-|z|)^{p_2+\\dots+p_n}\\).  Here the~\\(p_j\\) can be arbitrary\npositive real numbers, and the proportionality constant is the\nvolume of the \\((n-1)\\)-dimensional domain defined by the\ninequality\n\\begin{equation*}\n|z_2|^{2/p_2} + \\dots + |z_n|^{2/p_n} <1.\n\\end{equation*}\n\nAccordingly, it is useful to compute explicitly the weighted\nBergman kernel function~\\(K_q\\) for the unit disk with weight\n\\((1-|z|)^q\\), where \\(q>0\\).  The square of the norm of the\nmonomial \\(z^k\\) with weight factor \\( (1-|z|)^q\\) is\n\\begin{equation*}\n\\int_0^{2\\pi}\\int_0^1 r^{2k+1} (1-r)^q \\,dr\\,d\\theta = \n2\\pi \\Beta(2k+2,q+1),\n\\end{equation*}\nwhere \\(\\Beta\\) is the Beta function defined in terms of the\nGamma function by \\(\\Beta(a,b)= \\Gamma(a)\n\\Gamma(b)/\\Gamma(a+b)\\).  Consequently, the weighted Bergman\nkernel function \\(K_q(z,w)\\) equals\n\\((2\\pi)^{-1}\\sum_{k=0}^\\infty (z\\bar w)^k/\\Beta(2k+2,q+1)\\). A\nclosed form expression for this series is most conveniently\nwritten in terms of the squares of the variables:\n\\begin{equation}\n\\label{eq:q}\nK_q(z^2, w^2)= \\frac{(q+1)}{4\\pi z\\bar w} \\left[ \\frac{1}{(1-z\\bar\nw)^{q+2}} - \\frac{1}{(1+z\\bar w)^{q+2}} \\right].\n\\end{equation}\nThe powers of $(1\\pm z\\bar w)$ are to be understood as principal\nbranches.  The validity of this closed form expression can be\nverified by the binomial series expansion.\n\nThe explicit expression~\\eqref{eq:q} implies that the weighted\nBergman kernel function~\\(K_q\\) has zeroes in the interior of the\nunit disk if and only if \\(q>2\\). Indeed, taking limits\nin~\\eqref{eq:q} shows that \\(K_q\\)~is not equal to~\\(0\\) when\neither coordinate is equal to~\\(0\\), so it is only necessary to\ndecide if \\((1-t)^{q+2}=(1+t)^{q+2}\\) for some non-zero~\\(t\\) in\nthe unit disk. Since the mapping \\(t\\mapsto (1+t)/(1-t)\\) takes\nthe unit disk bijectively to the right half-plane, with the\norigin going to the point~\\(1\\), following this mapping by the\nmapping \\(u\\mapsto u^{q+2}\\) produces a composite mapping that\ntakes some non-zero point of the open unit disk to the\npoint~\\(1\\) if and only if \\(q>2\\).\n\nConsequently, the Bergman kernel function of the\ndomain~\\eqref{eq:ex} is guaranteed to have zeroes if\n\\(p_2+\\dots+p_n >2\\). Moreover, this domain is geometrically\nconvex if no~\\(p_j\\) exceeds~\\(2\\).  Therefore, one can exhibit\nmany concrete examples of convex domains whose Bergman kernel\nfunctions have zeroes \\cite{boasfustraube}. Here are some:\n\\begin{equation}\n\\label{eq:convex}\n\\begin{gathered}\n\\{\\,z\\in\\C^3: |z_1|+|z_2|+|z_3|<1\\,\\}, \\\\\n\\{\\,z\\in\\C^3: |z_1|+|z_2|+|z_3|^2<1\\,\\}, \\\\\n\\{\\,z\\in\\C^4: |z_1|+|z_2|^2+|z_3|^2+|z_4|^4<1\\,\\}.\n\\end{gathered}\n\\end{equation}\n\nUsing a different method, Peter Pflug and E.~H. Youssfi found\nsome other interesting examples of convex domains whose Bergman\nkernel functions have zeroes.  Even though the ``minimal ball''\nin~\\(\\C^n\\) defined by the inequality\n\\begin{equation}\n\\label{eq:minimal}\n  |z_1|^2+\\dots+|z_n|^2 + |z_1^2+\\dots+z_n^2| <1\n\\end{equation}\nlacks multi-circular symmetry, its Bergman kernel function is\nknown explicitly \\cite{opy}, and in \\cite{pflugyoussfi} the\nauthors analyzed the explicit formula to see that the Bergman\nkernel function of this domain has zeroes when \\(n\\ge4\\).\n\nAlthough the convex domains defined by \\eqref{eq:convex}\nand~\\eqref{eq:minimal} do not have smooth boundaries, they can be\napproximated from inside by smoothly bounded, strongly convex\ndomains.  From the method of variation of domains in\nsection~\\ref{variation-domains}, it follows that when \\(n\\ge3\\),\nthere exist smoothly bounded, strongly convex domains in~\\(\\C^n\\)\nwhose Bergman kernel functions have zeroes.  Pflug and Youssfi\neven showed in \\cite{pflugyoussfi} how to write down concrete\nexamples of bounded, smooth, algebraic, strongly convex domains\nthat approximate~\\eqref{eq:minimal} from inside.\n\nUsing the same idea, Nguy\\^en Vi\\^et Anh \\cite{anh} gave concrete\nexamples of bounded, smooth, algebraic, strongly convex,\nReinhardt domains in~\\(\\C^n\\) whose Bergman kernel functions have\nzeroes when \\(n\\ge3\\). For example, when \\(k\\)~is a sufficiently\nlarge positive integer, the inequality\n\\begin{equation}\n\\label{eq:alg}\n(|z_1|^2+|z_2|^2+|z_3|^2)^{2k} + \\sum_{\\substack{ \\pm \\\\ \\text{(8\nterms)}}} (\\pm |z_1| \\pm |z_2| \\pm |z_3|)^{2k} <1\n\\end{equation}\ndefines such a domain in~\\(\\C^3\\).  \n\nTo see that~\\eqref{eq:alg} has the required properties, first\nobserve that the \\(\\ell_{2k}\\) norm decreases to the\n\\(\\ell_\\infty\\) norm as \\(k\\to\\infty\\), so these domains are\ninterior approximations to the domain \\(\\{\\,z\\in\\C^3:\n|z_1|+|z_2|+|z_3|<1\\,\\}\\), which is one of the domains\n\\eqref{eq:convex} whose Bergman kernel functions have zeroes.\nThe odd powers of the \\(|z_j|\\) in the expansion\nof~\\eqref{eq:alg} cancel out by symmetry, so the defining\nfunction is equivalent to a polynomial.  It would be obvious that\nthe defining function~\\eqref{eq:alg} is convex if it had \\(\\re\nz_j\\) in place of~\\(|z_j|\\), for a convex function of a linear\nfunction is convex; now observe that positive combinations of\neven powers are increasing, and the composite of a convex\nincreasing function with the convex function~\\(|z_j|\\) is convex.\n\nThe two-dimensional domain defined by the inequality\n\\(|z_1|+|z_2|<1\\) is a borderline case for the preceding\nconsiderations. It turns out \\cite{boasfustraube} that the\nBergman kernel function of this domain has no zeroes in the\ninterior of the domain, although it does have zeroes on the\nboundary.\n\n\\begin{problem}\n  Exhibit a bounded convex domain in~\\(\\C^2\\) whose Bergman\n  kernel function has zeroes in the interior of the domain.\n\\end{problem}\n\n\\section{Conclusion}\nIt is a difficult problem to determine whether the Bergman kernel\nfunction of a specific domain has zeroes or not. If the kernel\nfunction is presented as an infinite series, then locating the\nzeroes may be of the same order of difficulty as proving the\nRiemann hypothesis; and even if the series can be summed in\nclosed form, determining whether or not \\(0\\)~is in the range may\nbe hard.\n\nIn this article, I have emphasized examples in which the Bergman\nkernel function does have zeroes. As the subject developed\nhistorically, such examples were considered surprising. From our\ncurrent perspective, it would be more surprising to find some\nsimple geometric condition guaranteeing that the Bergman kernel\nfunction is zero-free.\n\nStudents planning further investigation of the Bergman kernel\nfunction might consult, in addition to the journal articles I\nhave cited, Bell's book \\cite{bellbook} about the one-dimensional\ntheory, the book of Jarnicki and Pflug \\cite{jarnickipflug}, and\nStefan Bergman's own book \\cite{bergman}.  I offer the following\nproblem as an illustration of how much remains to be discovered\nabout the zeroes of the Bergman kernel function.\n\n\\begin{problem}\n  Characterize the vectors \\((p_1, p_2, \\dots, p_n)\\) of positive\n  numbers for which the Bergman kernel function of the domain\n  in~\\(\\C^n\\) defined by the inequality\n\\begin{equation*}\n|z_1|^{2/p_1}+|z_2|^{2/p_2} + \\dots + |z_n|^{2/p_n} <1\n\\end{equation*}\nis zero-free.\n\\end{problem}\n\n\n%\\bibliographystyle{amsplain} \\bibliography{luqikeng}\n%\\providecommand{\\bysame}{\\leavevmode\\hbox to3em{\\hrulefill}\\thinspace}\n\n\\begin{thebibliography}{10}\n\n\\bibitem{anh} Nguy\\^en~Vi\\^et Anh, \\emph{The {L}u {Q}i-{K}eng\nconjecture fails for strongly convex algebraic complete\n{R}einhardt domains in $\\mathbf{C}\\sp n\\ (n\\ge3)$},\nProc. Amer. Math. Soc., to appear.\n\n\\bibitem{belldavid} David Bell, \\emph{Some properties of the\n{B}ergman kernel function}, Compositio Math. \\textbf{21} (1969),\n329--330.\n\n\\bibitem{bell1981} Steven~R. Bell, \\emph{Proper holomorphic\nmappings and the {B}ergman projection}, Duke Math. J. \\textbf{48}\n(1981), no.~1, 167--175.\n\n\\bibitem{bell1982} \\bysame, \\emph{The {B}ergman kernel function\nand proper holomorphic mappings},\nTrans. Amer. Math. Soc. \\textbf{270} (1982), no.~2, 685--691.\n\n\\bibitem{bellbook} \\bysame, \\emph{The {C}auchy transform,\npotential theory, and conformal mapping}, CRC Press, 1992.\n\n\\bibitem{bergman} Stefan Bergman, \\emph{The kernel function and\nconformal mapping}, revised ed., American Mathematical Society,\n1970.\n\n\\bibitem{boascounterexample} Harold~P. Boas, \\emph{Counterexample\nto the {L}u {Q}i-{K}eng conjecture}, Proc.\nAmer. Math. Soc. \\textbf{97} (1986), no.~2, 374--375.\n\n\\bibitem{boasgeneric} \\bysame, \\emph{The {L}u {Q}i-{K}eng\nconjecture fails generically}, Proc. Amer.\nMath. Soc. \\textbf{124} (1996), no.~7, 2021--2027.\n\n\\bibitem{boasfustraube} Harold~P. Boas, Siqi Fu, and\nEmil~J. Straube, \\emph{The {B}ergman kernel function: explicit\nformulas and zeroes}, Proc. Amer. Math. Soc. \\textbf{127} (1999),\nno.~3, 805--811.\n\n\\bibitem{chernji} Shiing-Shen Chern and Shanyu Ji, \\emph{On the\n{R}iemann mapping theorem}, Ann.  of Math. (2) \\textbf{144}\n(1996), no.~2, 421--439.\n\n\\bibitem{englis} Miroslav Engli{\\v{s}}, \\emph{Asymptotic\nbehaviour of reproducing kernels of weighted {B}ergman spaces},\nTrans. Amer. Math. Soc. \\textbf{349} (1997), no.~9, 3717--3735.\n\n\\bibitem{greenekrantz} R.~E. Greene and Steven~G. Krantz,\n  \\emph{Stability properties of the {B}ergman kernel and\n    curvature properties of bounded domains}, Recent developments\n  in several complex variables, Princeton Univ. Press, 1981,\n  pp.~179--198.\n  \n\\bibitem{jarnickipflug} Marek Jarnicki and Peter Pflug,\n  \\emph{Invariant distances and metrics in complex analysis},\n  Walter de Gruyter \\& Co., 1993.\n\n\\bibitem{kakurai}\nShigeki Kakurai, \\emph{On the Lu Qi-Keng conjecture},\nRep. Fac. Engrg. Kanagawa Univ. no.~17 (1979), 3--4.\n\n\\bibitem{kanemaru}\nTadayoshi Kanemaru,  \n\\emph{A remark on the Lu Qi Keng conjecture},\nMem. Fac. Ed. Kumamoto Univ. Natur. Sci. no.~31 (1982), 1--3. \n\n\\bibitem{Krantz} Steven~G. Krantz, \\emph{Function theory of\nseveral complex variables}, second ed., Wadsworth \\& Brooks/Cole,\n1992.\n\n\\bibitem{lu} Lu~Qi-keng, \\emph{On {K}aehler manifolds with\nconstant curvature}, Chinese Math.--Acta \\textbf{8} (1966),\n283--298.\n\n\\bibitem{matsuura} Shozo Matsuura, \\emph{On the {L}u {Q}i-{K}eng\nconjecture and the {B}ergman representative domains}, Pacific\nJ. Math. \\textbf{49} (1973), 407--416.\n\n\\bibitem{opy} K.~Oeljeklaus, P.~Pflug, and E.~H. Youssfi,\n\\emph{The {B}ergman kernel of the minimal ball and applications},\nAnn. Inst. Fourier (Grenoble) \\textbf{47} (1997), no.~3,\n915--928.\n\n\\bibitem{pflugyoussfi} P.~Pflug and E.~H. Youssfi, \\emph{The {L}u\n{Q}i-{K}eng conjecture fails for strongly convex algebraic\ndomains}, Arch. Math. (Basel) \\textbf{71} (1998), no.~3,\n240--245.\n\n\\bibitem{ramadanov} I.~Ramadanov, \\emph{Sur une propri\\'et\\'e de\nla fonction de {B}ergman}, C. R.  Acad. Bulgare Sci. \\textbf{20}\n(1967), 759--762.\n\n\\bibitem{rosenthal} Paul Rosenthal, \\emph{On the zeros of the\n{B}ergman function in doubly-connected domains},\nProc. Amer. Math. Soc. \\textbf{21} (1969), 33--35.\n\n\\bibitem{semmes} Stephen Semmes, \\emph{A generalization of\n{R}iemann mappings and geometric structures on a space of domains\nin $\\mathbf{C}\\sp n$}, Mem. Amer. Math. Soc.  \\textbf{98} (1992),\nno.~472.\n\n\\bibitem{skwar} M.~Skwarczy{\\'n}ski, \\emph{The invariant distance\nin the theory of pseudoconformal transformations and the {L}u\n{Q}i-keng conjecture}, Proc.  Amer. Math. Soc. \\textbf{22}\n(1969), 305--310.\n\n\\bibitem{skwarczynski} Maciej Skwarczy{\\'n}ski,\n\\emph{Biholomorphic invariants related to the {B}ergman\nfunction}, Dissertationes Math. \\textbf{173} (1980).\n\n\\bibitem{suitayamada} Nobuyuki Suita and Akira Yamada, \\emph{On\nthe {L}u {Q}i-keng conjecture}, Proc.\nAmer. Math. Soc. \\textbf{59} (1976), no.~2, 222--224.\n\n\\end{thebibliography}\n\n\n\\end{document}\n", "meta": {"hexsha": "8d6058b66baaa58467cab1af9c8206aaef23e4c1", "size": 37218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "benchmark/src/test-data/0001/math0001036/math0001036.tex", "max_stars_repo_name": "e-sim/pdf-text-extraction-benchmark", "max_stars_repo_head_hexsha": "42eede9867e5795a6fc040b0a7ce92da3ddd3120", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-08-23T19:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-23T19:07:01.000Z", "max_issues_repo_path": "benchmark/src/test-data/0001/math0001036/math0001036.tex", "max_issues_repo_name": "e-sim/pdf-text-extraction-benchmark", "max_issues_repo_head_hexsha": "42eede9867e5795a6fc040b0a7ce92da3ddd3120", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "benchmark/src/test-data/0001/math0001036/math0001036.tex", "max_forks_repo_name": "e-sim/pdf-text-extraction-benchmark", "max_forks_repo_head_hexsha": "42eede9867e5795a6fc040b0a7ce92da3ddd3120", "max_forks_repo_licenses": ["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.9929078014, "max_line_length": 71, "alphanum_fraction": 0.7359610941, "num_tokens": 11430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7662936537604181, "lm_q1q2_score": 0.6385713615980096}}
{"text": "%\\documentclass[notitlepage,aps,pre,onecolumn]{revtex4-1}\n\\documentclass{article}\n\\usepackage{fullpage}\n\n\\usepackage{color}\n\\usepackage{amsmath,amsfonts,graphicx,enumerate,color,hyperref}\n\\usepackage{bm,braket,cancel}\n\\usepackage{tabularx}\n\\usepackage[normalem]{ulem}\n\\newcommand{\\pa}{\\partial}\n\\newcommand{\\abs}[1]{\\left| #1 \\right|}\n\\newcommand{\\avg}[1]{\\left\\langle #1 \\right\\rangle}\n\\newcommand{\\red}[1]{{\\color{red} #1}}\n\\newcommand{\\dd}[2]{\\frac{d^2 #1}{d #2^2}}\n\\newcommand{\\pd}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\pdd}[2]{\\frac{\\partial^2 #1}{{\\partial #2}^2}}\n\\renewcommand{\\L}{\\mathfrak{L}}\n\\renewcommand{\\O}{\\mathcal{O}\\left(\\epsilon^2\\right)}\n\\newcommand{\\s}[1]{^{(#1)}}\n\\newcommand{\\0}{^{(0)}}\n\n\\usepackage[usenames]{xcolor}\n\\hypersetup{\n    colorlinks,\n    linkcolor={blue!50!black},%{red!80!black},\n    citecolor={blue!50!black},\n    urlcolor={blue!80!black}\n}\n\\begin{document}\n\\title{Advection-diffusion of a scalar}\n\\author{YBS}\n\\maketitle\n\n\\section{Governing equations}\nThe time evolution of the concentration $c(\\bm r, t)$ of a chemical which undergoes simultaneous diffusion (with diffusion constant $\\eta$) and advection by a velocity field $\\bm v(\\bm r , t)$ is given by \n\\begin{align}\n\\pd{c}{t}+\\bm v \\cdot \\nabla c=\\eta \\nabla^2 c\n\\label{eq:eom}\n\\end{align}\nTe left-hand-side is the material time derivative (aka advective derivative).  The right-hand-side is diffusion. Physically, $\\bm v$ should also satisfy an evolution equation of its own, but for our purposes we'll just assume it's constant in time. However, we will add the (physically valid) constraint that $\\bm v$ is divergence-free, i.e.~$\\nabla\\cdot v=\\sum_i \\pa_i v_i=0$. In 2D, a divergence-free vector field over a periodic domain $[0,2\\pi]\\times[0,2\\pi]$ can be decomposed to Fourier components of the form\n\\begin{align}\nv_x&= \\sum_i A_i m_i \\cos (m_i y+\\beta_i ) \\cos (n_i x+\\alpha_i )\\ , &\nv_y&=\\sum_i A_i  n_i \\sin (m_i y+\\beta_i ) \\sin (n_i x+\\alpha_i )\\ ,\n\\end{align}\nwhere $A_i$ is the amplitude, $m_i, n_i$ are integers ($(m_i, n_i)$  is the wave-vector), and $\\alpha_i, \\beta_i$ are phases. For the simulation I simply draw all these parameters from a uniform distribution, using 5 terms for each simulation. \n\n\\section{Numerical implementation}\nFirst, we write the time derivative explicitly as\n\\begin{align}\n\\pd{c}{t}=\\eta \\nabla^2 c - \\bm v\\cdot\\nabla c=\\eta \\nabla^2 c - \\nabla \\cdot (c \\bm v)\\ .\n\\label{eq:3}\n\\end{align}\nThe last transition is valid because $\\nabla\\cdot \\bm v=0$.\n\nThe equations are solved on a square grid, using a staggered grid for $v$. That is, $c$ is calculated on the points $ \\left(2\\pi \\frac{i}{N},2\\pi \\frac{j}{N}\\right)$ where $N$ is the number of grid points in each dimension (currently 200) and $i,j$ are integers between 0 and $N-1$. $v$ is (pre-)computed on the points $ \\left(2\\pi \\frac{i-\\frac{1}{2}}{N},2\\pi \\frac{j-\\frac{1}{2}}{N}\\right)$. This allows implementing the right-hand-side of Eq.~\\eqref{eq:3} in a conservative way, i.e.~the spatial integral the right-hand-side vanishes (or alternatively, the spatial integral of $c$ remains constant in time, as it should).\n \nThe generation of the velocity field (and the shifted spatial mesh) is done by \\verb|generate_v_field|. The script \\verb|run_collect_save| runs many simulations and collects them in a \\verb|hdf5| file. \nThe file produced by \\texttt{run\\_collect\\_save} have this format: \n\n\\begin{itemize}\n\t\\item The name of the file is the value of $\\eta$.\n\t\\item \\verb|t| is the list of times for which the solutions are calculated\t(uniformly spaced).\n\t\\item \\verb|x| and \\verb|y| are matrices of shape $N\\times N$ with the \\texttt{x} and \\texttt{y} coordinates of the\tfinite-differences grid for \\verb|c|.\n\t\\item Each file contains 50 realizations, which are at groups \\texttt{/001},\n\t\\texttt{/002}, \\ldots{}, \\texttt{/050}: \n\t\\item \\texttt{/XXX/c} is an\n\t\\texttt{ndarray} of shape \\texttt{[n,n,len(t)]} that contains the\n\tconcentration field. \\texttt{c[i,j,k]} is the value of the\n\tconcentration field at position \\texttt{x[i,j]} and\n\t\\texttt{y[i,j]} at time \\texttt{t[k]}. In other words,\n\t\\texttt{c[...,i]} is the snapshot of the concentration field at time\n\t\\texttt{t[i]}. \n\t\\item The group \\texttt{/XXX} also contains\n\t\\texttt{/XXX/u},\\texttt{/XXX/v}, which are the \\texttt{x} and \\texttt{y}\n\tcomponents of the velocity field. Note that \\texttt{u} and \\texttt{v}\n\tare not evaluated at the same grid points as c since we use a staggered\n\tscheme to ensure conservation. The functional form of \\texttt{u} and\n\t\\texttt{v} is given in both MATLAB and Mathematica syntax in the\n\tattributes of \\texttt{/XXX}.\n\\end{itemize} \n\n\n\\end{document}", "meta": {"hexsha": "9072629217f9d14c2e240d24d8f304e2c3ac8de6", "size": 4649, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "explanation.tex", "max_stars_repo_name": "yohai/advection-diffusion", "max_stars_repo_head_hexsha": "1e277812b548d010a82605cecd835ec07c79c605", "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": "explanation.tex", "max_issues_repo_name": "yohai/advection-diffusion", "max_issues_repo_head_hexsha": "1e277812b548d010a82605cecd835ec07c79c605", "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": "explanation.tex", "max_forks_repo_name": "yohai/advection-diffusion", "max_forks_repo_head_hexsha": "1e277812b548d010a82605cecd835ec07c79c605", "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": 56.0120481928, "max_line_length": 624, "alphanum_fraction": 0.7143471714, "num_tokens": 1515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938677, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.638571334946474}}
{"text": "\n\\subsection{Extreme learning machines}\n\nThis is an alternative to backprobagation for training a feedforward neural network.\n\nWe start with random parameters for each layer \\(W_i\\).\n\nWe have:\n\n\\(\\hat y=W_2\\sigma (W_1 x)\\)\n\nEtc.\n\nWe calculate:\n\n\\(W_2=\\sigma(W_1x)^+Y\\)\n\nSo \\(W_1\\) is random and not updated.\n\n\\(W_2\\) is assigned to minimise loss, where \\(W_2\\) has no activation function.\n\n", "meta": {"hexsha": "88096d2e6cbde4da133f09eac185e310e4780e7a", "size": 390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksAlternative/01-03-extreme.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/neuralNetworksAlternative/01-03-extreme.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/neuralNetworksAlternative/01-03-extreme.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.7272727273, "max_line_length": 84, "alphanum_fraction": 0.7179487179, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6385063742602194}}
{"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-05.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 5a Keeping focused}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices.\n\n   expr := A_{a} v^{a} + B_{a} v^{a} + C_{a} v^{a}.  # cdb (ex-05.100,expr)\n\n   zoom (expr,$B_{a} Q??$)                           # cdb (ex-05.101,expr)\n   substitute (expr, $v^{a} -> w^{a}$)               # cdb (ex-05.102,expr)\n   unzoom (expr)                                     # cdb (ex-05.103,expr)\n\n   checkpoint.append (expr)\n\\end{cadabra}\n\n\\begin{align*}\n   \\cdb{ex-05.100} &= \\Cdb{ex-05.101}\\\\\n                   &= \\Cdb{ex-05.102}\\\\\n                   &= \\Cdb{ex-05.103}\n\\end{align*}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 5b Tags}\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   def add_tags (obj,tag):\n      n = 0\n      ans = Ex('0')\n      for i in obj.top().terms():\n         foo = obj[i]\n         bah = Ex(tag+'_{'+str(n)+'}')\n         ans := @(ans) + @(bah) @(foo).\n         n = n + 1\n      return ans\n\n   def clear_tags (obj,tag):\n      ans := @(obj).\n      foo  = Ex(tag+'_{a?} -> 1')\n      substitute (ans,foo)\n      return ans\n\n   expr := 2 V_{p q} - 3 V_{q p}.                    # cdb (ex-05.200,expr)\n\n   expr = add_tags (expr,'\\\\mu')                     # cdb (ex-05.201,expr)\n\n   zoom       (expr, $\\mu_{1} Q??$)                  # cdb (ex-05.202,expr)\n   substitute (expr, $V_{a b} -> - V_{b a}$)         # cdb (ex-05.203,expr)\n   unzoom     (expr)                                 # cdb (ex-05.204,expr)\n\n   expr = clear_tags (expr,'\\\\mu')                   # cdb (ex-05.205,expr)\n\n   checkpoint.append (expr)\n\\end{cadabra}\n\n\\begin{align*}\n   \\cdb{ex-05.200} &= \\Cdb{ex-05.201}\\\\\n                   &= \\Cdb{ex-05.202}\\\\\n                   &= \\Cdb{ex-05.203}\\\\\n                   &= \\Cdb{ex-05.204}\\\\\n                   &= \\Cdb{ex-05.205}\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", "meta": {"hexsha": "ac8f193709fac0cd581369d0e292a2f9f08446d0", "size": 2776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-05.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-05.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-05.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": 27.4851485149, "max_line_length": 94, "alphanum_fraction": 0.4347982709, "num_tokens": 837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673133042217, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6383516844297176}}
{"text": "\\input{../../UCLHeader.tex}\n\\input{../../UCLCommands.tex}\n\\begin{document}\n\\title{Error Correction - Lecture 1}\n\\author{with Dan Browne}\n\\maketitle\n\\tableofcontents\n\n\\section{Introduction}\nError correction is at the core of realistic quantum computing. If you think of quantum computation, you should also think of error correction. Any vision of quantum computing without error correction is fundamentally flawed. This course will introduce all the various notions of quantum error correction that are common in the field. \n\n\\section{Classical Repetition Code}\nIn this section, we will first have a look at classical repetition code in order to understand how classical error correction is done. \n\nFor the classical bit $x$, which can take on values $ x \\in [0,1]$, there are two possible errors. Either the bit gets flipped, such that $0 \\rightarrow 1 $ or $1 \\rightarrow 0$, or the bit is lost. \n\nWe can decompose most codes in terms of these errors. To protect from these errors, we \\textbf{encode} our bits into several bits, such that \n\\beq\n0 \\rightarrow 000\n\\eeq\n\\beq\n1 \\rightarrow 111\n\\eeq\nThen, an error on the 2nd bit would cause\n\\beq\n000 \\rightarrow 010\n\\eeq\n\\beq\n111 \\rightarrow 101\n\\eeq\nIf we query the values of the bits, we can take a majority vote and then correct the bit accordingly. This would work for the error described above. However, for two errors on two of the qubits, we find\n\\beq\n000 \\xrightarrow{error} 110 \\xrightarrow{correction} 111 \\xrightarrow{decoding} 1\n\\eeq\n\\beq\n111 \\xrightarrow{error} 001 \\xrightarrow{correction} 000 \\xrightarrow{decoding} 0\n\\eeq\nAs we can see, the correction and decoding process are unable to correctly negate the error. \n\nWe call the expression for the encoded bit a \\textbf{codeword}. We also make a distinction between detection and correction of an error. It is always true that correction is easier than correction. Finally, consider\n\\beq\n000 \\xrightarrow{error} 111\n\\eeq\n\\beq\n111 \\xrightarrow{error} 000\n\\eeq\nThis error cannot be corrected because we cannot detect it. Whenever an error maps a codeword into another codeword, we become unable to correct it. It is a very general concept. \n\n\\section{Code distance}\nWe can define the \\textbf{Hamming distance}. Given two $n$ bit strings, $A$ and $B$, the Hamming distance is the number of bits that you need to flip in order to go from $A$ to $B$. As an example, let $A = 010$ and $B = 001$. We require two flips to go from $A$ to $B$. Thus, $D_H = 2$. \n\nIt also follows that the Hamming distance is the number of errors that we cannot correct for. \n\nLet us define another important concept, the \\textbf{Hamming weight}. The Hamming weight is the number of nonzero bits in our codeword. \n\nFinally, the \\textbf{code distance} is the maximum distance of the code, which in turn is the smallest Hamming distance between codewords. \n\n\\emph{Example}: For an $n$ bit repetition code, the distance of the code is $n$. A number of $n-1$ bitflips are detectable. \n\nUltimately, the error correction that we perform is limited by our choice of correction method. Consider the following table of errors on the $000$ codeword:\n\n\\begin{tabular}{c| c}\n\\hline\nNo. of errors &Codeword\\\\ \n0 & 000 \\\\ \n1 & 001 \\\\ \\hline\n2 & 011 \\\\\n3 &111\n\\end{tabular}\nWe have drawn the line at the point where we can no longer correct for errors. We can draw the Hamming distance around a codeword as a sphere. Every error inside the sphere will be mapped onto the codeword at its centre, but once an error takes us out of the sphere, it will be corrected into a codeword different from its original one. \n\nIn other words, we don't want the spheres to overlap. This leaves us with a number of $\\frac{n-1}{2}$ correctable errors for an $n$ bit repetition code. Note that when $n-1$ is odd, we must always round down to the nearest integer. \n\n\n\\section{Computations}\nConsider the encoded NOT gate. It has the following function on the encoded bits:\n\\beq\n0 \\xrightarrow{NOT} 1\n\\eeq\n\\beq\n1 \\xrightarrow{NOT} 0 \n\\eeq\nIn the repetition code, flipping all $n$ bits implements a \\textbf{logical NOT gate}. By logical, we mean that the gate affects the entire codeword that we have stored to mimic the effect of a single bit. \n\n\\section{Going Quantum}\nWould the same concepts carry over without any problem into the quantum regime? Unfortunately not. The repetition code is a prime example where the \\textbf{no-cloning theorem} prevents us from copying arbitrary quantum states into multiples of themselves. \n\nThe following aspects significantly complicate the transition to quantum error correction:\n\\begin{itemize}\n\\item[1] The no-cloning theorem forbids arbitrary qubit states from being copied. \n\\item[2] Measurements change the state, which complicates detection. \n\\item[3] Quantum errors are much more complicated than classical errors - there are more ways in which they can occur. \n\\end{itemize}\n\nThe last point might require some clarification. Any unitary transformation can become an error. In addition, we have the various ways in which a quantum state can decohere. Together, they add up to an infinite amount of errors, compared to just the single classical error!\n\n\\section{The Quantum Repetition Code}\nThis is an example of the most naive way in which we can start considering the quantum correction of errors. However, as we shall see later, even the quantum repetition code is an example of a more powerful formalism. \n\nWe take the basis states, and we clone the computational basis states, such that \n\\beq\n\\ket{0} \\rightarrow \\ket{000} = \\ket{0}_L\n\\eeq\n\\beq\n\\ket{1} \\rightarrow \\ket{111} = \\ket{1}_L\n\\eeq\nHere, $\\ket{0}_L$ and $\\ket{1}_L$ are the logical qubits. We also say that the codewords, $\\ket{000}, \\ket{111}$ live in a \\textbf{codespace}. We say that the codespace is spanned by the codewords. \n\nFor an arbitrary superposition, we obtain\n\\beq\n\\alpha \\ket{0} + \\beta \\ket{1} \\rightarrow \\alpha \\ket{000} + \\beta \\ket{111}\n\\eeq\nNote that since we are only copying the basis states, it is not cloning and therefore perfectly allowed. \n\n\\subsection{The bit-flip error}\nThe bit-flip error takes us\n\\beq\n\\ket{0} \\rightarrow \\ket{1}\n\\eeq\nand vice versa. It is equivalent to the Pauli $X$ matrix\n\\beq\nX = \\bpmat 0 & 1 \\\\ 1 & 0\\epmat\n\\eeq\nSo an error on the 2nd qubit of our three-qubit example would look like\n\\beq\nI \\otimes X \\otimes I = \\alpha \\ket{010} + \\beta \\ket{101}\n\\eeq\nHow can we correct for this error? We are not allowed to measure the qubits individually, since this measurement would tell us about the state and thus collapse the superposition. Instead, we introduce the concept of \\textbf{parity}. The state $\\ket{00}$ has even parity, and $\\ket{01}$ has odd parity. We can then measure without collapsing the superposition, because the states in the above superposition, for example, have the same parity. We can measure a property as long as it belongs to every state in the superposition. \n\nFor the three-qubit code example, we have that $\\ket{000}$, and $\\ket{111}$ are examples of even parity states, and $\\ket{010}, \\ket{110}$ are examples of odd parity states. \n\nSo, we need a measurement that tells us about the parity without distinguishing the states. In order to perform this measurement, we require a CNOT gate and an ancilla qubit. Then, we apply the CNOT gate to each of our two (or three) qubits and the ancilla, and finally we read off the ancilla. Thus, \n\\beq\n\\ket{00} \\rightarrow \\ket{0}_A\n\\eeq\n\\beq\n\\ket{11} \\rightarrow \\ket{0}_A\n\\eeq\n\\beq\n\\ket{01} \\rightarrow \\ket{1}_A\n\\eeq\n\\beq\n\\ket{10} \\rightarrow \\ket{1}_A\n\\eeq\nwhere $\\ket{0}_A$ is the ancilla. However, we can also perform this measurement in a simpler way, that uses fewer gates. For example, the $Z$ gate will measure Pauli $Z$ in the computational basis. This will tell us about the parity of the qubits. \n\nWe must consider the parity of all the pair of the code. For the three-qubit code, the $Z\\otimes Z$ measurement will have outcome $+1$ for even parity, and $-1$ for odd parity when applied to two of the three qubits. \n\nSo, for the three-qubit repetition code, we can think of three measurements that allows us to check the parity. \n\\beq\nZ \\otimes Z \\otimes I\n\\eeq\n\\beq\nZ \\otimes I \\otimes Z\n\\eeq\n\\beq\nI \\otimes Z \\otimes Z\n\\eeq\nBut note that since $ZZ = I$, the last measurement can actually be formed as a product of the other two. This is a sign of an underlying group-theoretical structure which we will explore more thoroughly in upcoming lectures. \n\n\\section{Correcting quantum errors}\nAssume that there is only one error on our arbitrary superposition, \n\\beq\nZ \\otimes I \\otimes I \\left( \\alpha \\ket{000} + \\beta \\ket{111} \\right) = \\alpha \\ket{100} + \\beta \\ket{011} \n\\eeq\nThen, if we apply the parity measurements defined above, we find\n\\beq\nZ \\otimes Z \\otimes I \\rightarrow - 1\n\\eeq\n\\beq\nZ \\otimes I \\otimes Z \\rightarrow - 1 \n\\eeq\n\\beq\nI \\otimes Z \\otimes Z \\rightarrow +1\n\\eeq\nand similarly for every other error. \n\nWe can write down a so-called \\textbf{syndrome table} for all possible one-qubit $X$ errors. \n\n\\begin{tabular}{|c|c|c|}\n$X\\otimes I \\otimes I $& $I \\otimes X \\otimes I$ & $I \\otimes I \\otimes X$ \\\\ \\hline\n--  &-- & + \\\\ \\hline\n-- & + & -- \\\\ \\hline\n+ & -- & --  \\\\ \\hline\n\\end{tabular}\n\nSo, our correction strategy should be:\n\\begin{itemize}\n\\item Identify where the error occurred \n\\item Apply a bit-flip operation where the error occurs\n\\end{itemize}\n\n\\section{More general errors}\nLet us consider a general error\n\\beq\nU = e^{- i \\theta X} = \\cos{\\theta} I - i \\sin{\\theta} X\n\\eeq\nSo that for our general superposition, we have\n\\beq\n\\alpha \\ket{000} + \\beta \\ket{111} = \\cos{\\theta} \\left( \\alpha \\ket{000} + \\beta \\ket{111} \\right) - i \\sin{\\theta} \\left( \\alpha \\ket{100} + \\beta \\ket{011} \\right)\n\\eeq\nBut now, measuring with $Z\\otimes Z \\otimes I$ collapses the superposition to either of the terms. But, if $\\theta \\ll 1$, then detecting the error will correct it!\n\nThis simple example is very powerful. It tells us that our error correction strategy will work in general. \n\n\n\\section{The encoding circuit}\nIn order to encode our qubits into logical qubits, for the case of the repetition code we want a circuit that gives us\n\\beq\n\\alpha \\ket{0} \\rightarrow \\alpha \\ket{000}\n\\eeq\nThis cannot be just a unitary. Instead, we need an \\textbf{isometry}, which is a unitary plus a Hilbert space expansion. The following circuit encodes the qubit:\n\nstuff\n\nAll encoding is based on CNOT gates. In summary, we have that \n\\begin{itemize}\n\\item The encoding circuit encodes the state\n\\item Two measurements detect the errors \n\\item $X$ gates corrects the errors\n\\end{itemize}\n\n\\section{Logical operators}\nConsider the logical $X$ operator. It flips the computational basis state. How can we achieve this on our encoded qubit? One stupid way to do this would be to decode our codewords, such that \n\\beq\n\\alpha \\ket{000} + \\beta \\ket{111} \\rightarrow \\alpha \\ket{0} + \\beta \\ket{1}\n\\eeq\napply a single gate and then re-encode them. This is not a good way, since it requires a lot of gates. \n\nThe good way would be to apply the operator\n\\beq\nX\\otimes X \\otimes X = \\bar{X}\n\\eeq\nwhich we call the logical $X$ operator.  Clearly\n\\beq\n\\bar{X} \\ket{0}_L = \\bar{X} \\ket{000} = \\ket{111} = \\ket{1}_L\n\\eeq\nwhich is what we want. \n\nSimilarly for the logical $Z$ operator, we want\n\\beq\n\\alpha \\ket{000} + \\beta \\ket{111} \\rightarrow \\alpha \\ket{000} - \\beta \\ket{111}\n\\eeq\nBut now, there are many different ways in which we can do this. We have $ZII, IZI, IIZ, $ and $ZZZ$ that all achieve the right thing (note that we have dropped the tensor product notation). Each of the first three operators has weight 1. This means that they are indistinguishable from a single $Z$ error. \n\nRecalling what we said before about code distance and the Hamming distance, it means that the code cannot protect against a $Z$ error, also called a phase error. \n\n\\section{Distance of a Quantum Code}\nThe logical operators are equal to the smallest undetectable error. We can define the minimum distance $d$ in a quantum code as the smallest weight of a non-identity logical operator. That is, the smallest weight is the undetectable error. \n\nSo, given what we know about the repetition code, we find that it has distance $d = 1$, which is very bad. \n\n\\emph{Note on notation}: we will use so called ($n,k,d$) notation,  where \\\\\n$n$ is the number of physical qubits used to write one logical qubit, \\\\$k$ is the number of encoded qubits \\\\\n$d$ is the quantum distance of the code\n\nIt follows that $k < n$ always. \n\n\\section{Correcting phase errors}\nCan we think of a way to correct a single $Z$ error? We first note that \n\\beq\nZ = HXH\n\\eeq\nand we know that the repetition code can correct for $X$ error. Thus, we try applying $H\\otimes H\\otimes H $ on the repetition code. We find\n\\beq\n\\alpha \\ket{000} + \\beta \\ket{111} \\rightarrow \\alpha \\ket{+++} + \\beta \\ket{---}\n\\eeq\nThen, we measure with the operators $XXI, XIX$ and $IXX$. Again note that the last measurement can be made up of the previous two. We then measure the parity in the $\\{\\ket{+}, \\ket{-}\\}$ basis. We again make use of   CNOT and an ancilla to record the measurement. \n\nWe get positive outcomes for even parity, and negative outcomes for odd parity. This works exactly the same as in the $\\{\\ket{0}, \\ket{1}\\}$ basis. \n\nBut just like the previous code failed for phase errors, this code fails for bit-flip errors. So is there a way to combine both approaches? \n\n\\section{The Shor code}\nThe code idea is: encode a bit-flip code in a phase flip code. That is, take\n\\beq\n\\ket{+} \\rightarrow \\ket{+++}\n\\eeq\n\\beq\n\\ket{-} \\rightarrow \\ket{---}\n\\eeq\nTake each qubit and encode them in the bit-flip code. This is called \\textbf{code concatenation}. We encode each codeword into more codewords. \n\nSo we get the following code\n\\beq\n\\ket{0}_L \\rightarrow \\ket{+}_{bitflip} \\ket{+}_{bitflip} \\ket{+}_{bitflip} = \\left( \\ket{000} + \\ket{111} \\right)^{\\otimes 3}\n\\eeq\n\\beq\n\\ket{1}_L \\rightarrow \\ket{-}_{bitflip} \\ket{-}_{bitflip}\\ket{-}_{bitflip} = \\left( \\ket{000}- \\ket{111} \\right)^{\\otimes 3}\n\\eeq\nNote here that we have neglected to write out the normalisation. This is intentional, as it would quickly get very messy. \n\nThe logical operators are then for this code\n\\beq\n\\bar{X} = ZII \\otimes ZII \\otimes ZII = ZIIZIIZII\n\\eeq\n\\beq\n\\bar{Z} = XXXIIIIII\n\\eeq\nThe distance of the Shor code is 3, and the error that we can correct for is\n\\beq\n\\frac{3-1}{2} \\sim 1\n\\eeq\n\\end{document}\n\n", "meta": {"hexsha": "02169e2ab56388b3af26d75b9b12715fbe57f51c", "size": 14426, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Error Correction Lecture 22 Feb 2016.tex", "max_stars_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_stars_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-04-01T04:53:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-09T07:01:28.000Z", "max_issues_repo_path": "Error Correction Lecture 22 Feb 2016.tex", "max_issues_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_issues_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Error Correction Lecture 22 Feb 2016.tex", "max_forks_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_forks_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_forks_repo_licenses": ["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.1437908497, "max_line_length": 528, "alphanum_fraction": 0.7421322612, "num_tokens": 4164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.6383516736945117}}
{"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 203 Problem Set 6}\n\\author{Michael Kwok}\n\\begin{document}\n\n\\maketitle\n\\begin{multicols}{2}\n\\section*{1}\n\\subsection*{a}\n\\begin{align}\n    \\left(I_1 + 10^{-5} V_2\\right) 1000 &= V_1\\\\\n    10000 I_2 - 100 V_1 &= V_2\n\\end{align}\n\nExpanding equation (1) then substituting in equation (2):\n\n\\begin{align*}\n    &1000 I_1 + 0.01 V_2 = V_1\\\\\n    &1000 I_1 + 0.01 \\left(10000 I_2 - 100 V_1\\right) = V_1\\\\\n    &1000 I_1 + 100 I_2 = 2 V_1\n\\end{align*}\n\nForming the following equations:\n\n\\begin{align}\n    V_1 &= 500 I_1 + 50 I_2\\\\\n    V_2 &= -50000 I_1 + 5000 I_2\n\\end{align}\n\n$$\n  [Z] = \n  \\begin{bmatrix}\n  500 & 50\\\\\n  -50000 & 5000\n  \\end{bmatrix}\n  \\si{\\ohm}\n$$\n\\subsection*{b}\nThe network is not reciprocal. $Z_{12} \\neq Z_{21}$\n\\subsection*{c}\n$$\n\\frac{V_1}{I_1} = R_{in}\n$$\n\\begin{align*}\n    V_2 &= -I_2 R_L\\\\\n    &= -4000 I_2\n\\end{align*}\n\\begin{align*}\n    -4000 I_2 &= -50000 I_1 + 5000 I_2\\\\\n    -9000 I_2 &= -50000 I_1\\\\\n    I_2 &= \\frac{50}{9}I_1\\\\\n    V_1 &= 500 I_1 + \\frac{2500}{9} I_1\\\\\n    \\frac{V_1}{I_1} &= \\SI{778}{\\ohm}\\\\\n    R_in &= \\SI{778}{\\ohm}\n\\end{align*}\n\\section*{2}\n\\begin{align}\n    I_1 &= \\frac{V_1}{100} + \\frac{V_a}{500} + \\frac{V_1}{250}\\\\\n    I_2 &= \\frac{V_2}{200} - \\frac{V_1}{250}\\\\\n    V_a &= 250 I_2 + V_1\n\\end{align}\n\nEquation (7) into (5)\n\n\\begin{equation}\n    I_1 = \\frac{V_1}{100} + \\frac{250 I_2 + V_1}{500} + \\frac{V_1}{250}\n\\end{equation}\n\\begin{align*}\n    500 I_1 &- 250 I_2 = 5 V_1 + V_1 + 2 V_1\\\\\n    500 I_1 &- 250 I_2 = 8 V_1 \\\\\n    500 I_1 &- 250 \\left( \\frac{V_2}{200} - \\frac{V_1}{250} \\right) = 8 V_1\\\\\n    500 I_1 &- \\frac{250}{200} V_2 + V_1 = 8 V_1\\\\\n    7V_1 &= 500 I_1 - \\frac{5}{4}V_2\\\\\n    V_1 &= \\frac{500}{7} I_1 - \\frac{5}{28} V_2\n\\end{align*}\n\n\\begin{align*}\n    I_2 &= \\frac{V_2}{200} - \\frac{1}{250} \\frac{500}{7} I_1 + \\frac{5}{28}\\frac{1}{250} V_2\\\\\n    &= -\\frac{2}{7} I_1 + \\frac{1}{175} V_2\n\\end{align*}\n\n$$\n  [h] = \n  \\begin{bmatrix}\n  \\frac{500}{7} & -\\frac{5}{28}\\\\\n  -\\frac{2}{7} & \\frac{1}{175}\n  \\end{bmatrix}\n$$\n\n$h_{11}$ has unit of $\\si{\\ohm}$, $h_{22}$ has unit of $\\si{\\per\\ohm}$\n\n\\section*{3}\n$R_{eq}$ can be calculated with $V_s = 0$\n\n$$\n    V_1 = -4 I_1\n$$\n\n\\begin{align}\n    -4 I_1 &= 2 I_1 + V_2\\\\\n    I_2 &= 5 I_1 + 2 V_2\n\\end{align}\n\\begin{align*}\n    -6 I_1 &= V_2\\\\\n    I_1 &= -\\frac{1}{6} V_2\n\\end{align*}\n\\begin{align*}\n    I_2 &= -\\frac{5}{6} V_2 + 2 V_2\\\\\n    \\frac{I_2}{V_2} &= \\frac{7}{6}\\\\\n    R_{eq} &= \\frac{6}{7}\\si{\\ohm}\n\\end{align*}\n\n\\section*{4}\nFor $y_1$, the CL circuit.\n\\begin{align}\nI_1 = \\frac{V_1}{\\frac{1}{sC}} + \\frac{V_1 - V_2}{sL}\\\\\nI_2 = \\frac{V_2 - V_1}{sL} + \\frac{V_2}{\\frac{1}{sC}}\n\\end{align}\n\\begin{align*}\n    I_1 = sV_1 + \\frac{1}{s} V_1 - \\frac{1}{s}V_2\\\\\n    I_2 = sV_2 + \\frac{1}{s} V_2 - \\frac{1}{s}V_1\n\\end{align*}\n$$\n  [y_1] = \n  \\begin{bmatrix}\n  \\frac{s^2 +1}{s} & -\\frac{1}{s}\\\\\n  -\\frac{1}{s} & \\frac{s^2 +1}{s}\n  \\end{bmatrix}\n  \\si{\\per\\ohm}\n$$\nFor $y_2$, the RC circuit.\n\\begin{align}\nI_1 = \\frac{V_1-V_2}{\\frac{1}{sC}} + \\frac{V_1}{1}\\\\\nI_2 = \\frac{V_2-V_1}{\\frac{1}{sC}} + \\frac{V_2}{1}\n\\end{align}\n\\begin{align*}\n    I_1 = (s+1)V_1 - s V_2\\\\\n    I_2 = -sV_1 + (s+1)V_2\n\\end{align*}\n$$\n  [y_2] = \n  \\begin{bmatrix}\n  s+1 & -s\\\\\n  -s & s+1\n  \\end{bmatrix}\n  \\si{\\per\\ohm}\n$$\n$$\n[y] = [y_1] + [y_2] = \n  \\begin{bmatrix}\n  \\frac{2s^2 + s + 1}{s} & -\\frac{s^2+1}{s}\\\\\n  -\\frac{s^2+1}{s} & \\frac{2s^2 + s + 1}{s}\n  \\end{bmatrix}\n  \\si{\\per\\ohm}\n$$\n\\section*{5}\n\\subsection*{a}\n\\begin{align}\n    I_1 &= \\frac{V_1}{4} + \\frac{V_1 - V_2}{2}\\\\\n    I_2 &= \\frac{V_2}{3} + \\frac{V_2 - V_1}{2}\n\\end{align}\n\\begin{align}\n    4 I_1 &= V_1 + 2 V_1 - 2 V_2\\\\\n    6 I_2 &= 2 V_2 + 3 V_2 - 3 V_1\n\\end{align}\nUsing Equation (18):\n\\begin{align*}\n    6 I_2 - 5 V_2 &= - 3 V_1\\\\\n    V_1 &= \\frac{5}{3} V_2 - 2 I_2\n\\end{align*}\n\nUsing Equation (17):\n\\begin{align*}\n    4 I_1 &= 5 V_2 - 6 I_2 -2 V_2\\\\\n    4 I_1 &= 3 V_2 - 6 I_2\\\\\n    I_1 &= \\frac{3}{4} V_2 - \\frac{3}{2} I_2\n\\end{align*}\n\n\\begin{align*}\n3 V_1 &= 4 I_1 + 2 V_2\\\\\n V_1 &= \\frac{4}{3} \\left( \\frac{3}{4} V_2 - \\frac{3}{2} I_2\\right) +\\frac{2}{3} V_2\\\\\n &= V_2 - 2 I_2 + \\frac{2}{3} V_2\\\\\n &= \\frac{5}{3} V_2 - 2I_2\n\\end{align*}\n$$\n[t] = \n  \\begin{bmatrix}\n  \\frac{5}{3} & 2\\\\\n  \\frac{3}{4} & \\frac{3}{2}\n  \\end{bmatrix}\n$$\n$t_{12}$ has unit of $\\si{\\ohm}$, $t_{21}$ has unit of $\\si{\\per\\ohm}$\n\\subsection*{b}\n$$\n[t] = [t_1][t_2] = \n  \\begin{bmatrix}\n  \\frac{5}{3} & 2\\\\\n  \\frac{3}{4} & \\frac{3}{2}\n  \\end{bmatrix}\n  \\begin{bmatrix}\n  1 & 0\\\\\n  \\frac{1}{6} & 1\n  \\end{bmatrix}\n$$\n$$\n= \n  \\begin{bmatrix}\n  2 & 2\\\\\n  1 & \\frac{3}{2}\n  \\end{bmatrix}\n$$\n\n\\end{multicols}\n\\end{document}\n", "meta": {"hexsha": "9235435bbefb2cf7fb38b3acff5afd26d3082985", "size": 4739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/ECE203/ECE203Ps6.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/ECE203/ECE203Ps6.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/ECE203/ECE203Ps6.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": 21.3468468468, "max_line_length": 94, "alphanum_fraction": 0.5376661743, "num_tokens": 2467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6383390715870474}}
{"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\\usepackage{tabularx}\n\n% First and foremost, never use the environment eqnarray. It is not recommended because spacing is inconsistent.\n\n\\begin{document}\n\n\\section*{System of equations}\n\n\n\\subsection*{Summary of the environments}\n\n\\begin{table}[h]\n\t\\begin{tabularx}{\\textwidth}{| X | X | X |}\n\t\\hline\n\t\\textbf{Environment names} & \\textbf{Description} & \\textbf{Notes} \\\\\n\t\\hline\n\t\\emph{gather} and \\emph{gather*} & Consecutive equations with an alignment to the center. & \\\\\n\t\\hline\n\t\\emph{align}, \\emph{align*}, \\emph{aligned} and \\emph{split} & Consecutive equations with user-defined alignment. & \\\\\n\t\\hline\n\t\\emph{flalign} and \\emph{flalign*} & Similar to \\emph{align}, but left aligns first equation column, and right aligns last column. & \\\\\n\t\\hline\n\t\\emph{alignat} and \\emph{alignat*} & Takes an argument specifying number of columns. Allows control of the horizontal space between equations. & This environment takes one argument, the number of “equation columns”: count the maximum number of \\&s in any row, add 1 and divide by 2. \\\\\n\t\\hline\n\t\\emph{array} & Advanced alignment scenario. Enables to control how to columns are aligned. & \\\\\n\t\\hline\n\t\\emph{multline} and \\emph{multline*} & First line left aligned, last line right aligned. & Equation number aligned vertically with first line and not centered as with other environments. \\\\\n\t\\hline\n\t\\emph{eqnarray} and \\emph{eqnarray*} & Similar to \\emph{align} and \\emph{align*}. & Not recommended because spacing is inconsistent. \\\\\n\t\\hline\n\t\\end{tabularx}\n\\end{table}\n\nThis table is based on the one available on Wikibooks, \\LaTeX Advanced Mathematics.\n\n\\newpage\n\n\n\\subsection*{Grouping and centering equations with \\emph{gather}}\n\n\\begin{gather}\n\tx + 2y - z = 4 \\\\\n\tx + y - 5z = -1 \\\\\n\t2x - z = 10\n\\end{gather}\n\nIn addition, the environment \\emph{gather*} removes the equation numbering. The environment \\emph{gathered} and can be used in another mathematical environment.\n\n\n\\subsection*{Align equations with \\emph{align}}\n\n\\begin{align}\n\tx + 2y - z &= 4 \\\\\n\tx + y - 5z &= -1 \\\\\n\t2x - z &= 10\n\\end{align}\n\nThis environment can also be used to align equations on the same line:\n\n\\begin{align*}\n\tf(x)  &= a x^2+b x +c   &   g(x)  &= d x^3 \\\\\n\tf'(x) &= 2 a x +b       &   g'(x) &= 3 d x^2\n\\end{align*}\n\nIn addition, the environment \\emph{align*} removes the equation numbering. The environment \\emph{aligned} and \\emph{split} are the similar to \\emph{align} and \\emph{align*} but can be used in another mathematical environment.\n\n\\subsubsection*{Align equations with \\emph{align} and \\emph{subequations}}\n\nThe environment \\emph{subequations} changes the way how \\LaTeX counts the equations.\n\n\\begin{subequations}\n\t\\begin{align}\n\t\tx + 2y - z &= 4 \\\\\n\t\tx + y - 5z &= -1 \\\\\n\t\t2x - z &= 10\n\t\\end{align}\n\\end{subequations}\n\n\\subsubsection*{Braces a system of equations}\n\nThe environment \\emph{aligned} is similar to align, to be used inside another mathematics environment.\n\n% The commands \\left and \\right insert a brace. The type of the brace is written just after the command.\n% When \\left is called, \\right is mandatory.\n\\[\n\\left(\n\\begin{aligned}\n\tx + 2y - z &= 4 \\\\\n\tx + y - 5z &= -1 \\\\\n\t2x - z &= 10\n\\end{aligned}\n\\right)\n\\]\n\n% In the case where only one brace is needed, the other brace must be marked with a point (.) to hide it.\n\\[\n\\left\\{\n\\begin{aligned}\nx + 2y - z &= 4 \\\\\nx + y - 5z &= -1 \\\\\n2x - z &= 10\n\\end{aligned}\n\\right.\n\\]\n\n\n\\subsection*{Align equations to the left with \\emph{flalign}}\n\n\\begin{flalign}\na &= b+c &\\\\\n&= 1+1 &\\\\\n&= 2  &\n\\end{flalign}\n\nIn addition, the environment \\emph{flalign*} removes the equation numbering.\n\n\n\\subsection*{Align equations with \\emph{alignat}}\n\nThe environment \\emph{alignat} enables to control of the horizontal space between equations. Indeed, no addition space is added between equation, at the opposite of the environment \\emph{align}.\n\nThe mathematical development below is aligned according the arrow and the equal signs.\n\n\\begin{alignat}{2}\n\t&& \\sqrt{4 x^2} - 1 &= 0 \\\\\n\t&\\Rightarrow & \\sqrt{4} \\sqrt{x^2} &= 1 \\\\\n\t&\\Rightarrow & 2 \\left|x\\right| &= 1 \\\\\n\t&\\Rightarrow & x &= \\pm \\frac{1}{2}\n\\end{alignat}\n\nThis environment takes an argument specifying number of columns. The rule of thumb to determine the argument is to count the maximum number of \\& symbols on one row, add 1 and divide by 2.\n\nIn addition, the environment \\emph{alignat*} removes the equation numbering. The environment \\emph{alignedat} and \\emph{alignedat*} and can be used in another mathematical environment.\n\n\n\\subsection*{Align equations with \\emph{array}}\n\nThe environment \\emph{array} is for more advanced scenario. It is basically the same as \\emph{align}, but the columns and their alignment are explicitly indicated. It must be used in the math mode.\n\n\\[\n\\left\\{\n\\begin{array}{ r c l}\n\t\tx + z &=& y - 4 \\\\\n\t\t5z &=& x + y -1 \\\\\n\t\t2x - y &=& 10 - y\n\\end{array}\n\\right.\n\\]\n\n\n\\subsection*{Displaying long equations}\n\nThe environment \\emph{multline} can be used to display formula on multiple lines.\n\n\\begin{multline*}\n\tf(x) = 60x^{15} + 56x^{14} + 52x^{13} + 48x^{12} + 44x^{11} + 40x^{10} + 36x^{9} + 32x^{8}\\\\\n\t+ 28x^{7} + 24x^{6} + 20x^{5} + 16x^{4} + 12x^{3} + 8x^{2} + 4\n\\end{multline*}\n\n\\end{document}", "meta": {"hexsha": "bf2f47a1f627c203615121b9fcc6a68e025e0be1", "size": 5365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/system-of-equations.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/system-of-equations.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/system-of-equations.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": 31.5588235294, "max_line_length": 286, "alphanum_fraction": 0.6943150047, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.9086179031191509, "lm_q1q2_score": 0.6383313876286082}}
{"text": "\\chapter{Background \\& Related Work}\n\\label{chap:background}\n\nIn this section, constraint optimization and the distributed, as well as dynamic variants are briefly explained and brought into context of the related work. Also, the meeting scheduling problem will be described and different algorithm designs and their advantages and disadvantages are going to be briefly discussed.\n    \n\\section{Dynamic Distributed Constraint Optimization}\n\n% -----------------Constraint Optimization --------------------\n    \nA constraint optimization problem (COP) contains a set of variables \\(V=\\{V_{1},V_{2}, ...,  V_{n}\\}\\). These variables are assigned to a value or state \\(s_{j} \\in S_{j}\\), which is contained in a set of possible values defined by a finite problem domain \\(D=\\{D_{1},D_{2}, ...,  D_{n}\\}\\). A constraint \\(C = <V_{c}, R_{c}>\\) contains one (unary), two (binary) or multiple (k-ary) variables and their relationship. The constraint defines a rule for the variables that needs to be fulfilled. One of those rules could be that none of the variables should take the same value. This would for example be the case for a meeting scheduling problem where none of the meetings should take place at the same time. \\newline\nA utility function for the constraint \\({c}_{k}\\) on variable state \\(s\\) in the form of \\(u_{{c}_{k}}(s_{{c}_{k}})\\) needs to be formulated that defines a certain cost respectively reward for a given configuration of the involved states. The global utility function \\(u_{g}\\) would then be the summation of all utility functions of all constraints. \n\n\\[u_{g}(s) = u_{c_{1}}(s_{c_{1}}) \\oplus \\cdots \\oplus u_{c_{k}}(s_{c_{k}}) \\oplus \\cdots \\oplus u_{c_{l}}(s_{c_{l}}) \\] \n\nConstraints can be attributed with varying levels of importance through weighting. One can, instead of so-called soft constraints, define hard constraints by multiplying their utility instead of using addition in the global utility function. By defining the utility of a violated hard constraint as 0, the global utility would also go to 0 if this hard constraint is not satisfied \\cite{Chapman2011, Petcu2003}. A problem only containing hard constraints would represent a constraint satisfaction problem (CSP). A formal definition of such a combined utility function including soft constraints (SC) and hard constraints (HC) would look like the following formula, where the product of all hard constraints is multiplied by the sum of all utilities of a state \\(s\\) in the soft constraint utility functions:\n\n\\[ u_{g}(s) = \\prod_{\\substack{hc_{k} \\in HC}} u_{SC_{g}}(s) \\bigg( \\sum_{sc_{k} \\in SC} u_{SC_{g}}(s) \\bigg)\\] \n\n\n% ----------------- Distributed Constraint Optimization --------------------\nThe definition of a distributed constraint optimization problem (DCOP) extends the basic constraint optimization by distributing sets of variables to autonomous agents. These agents all have the goal to maximize the utility of their variables in a private utility function and thereby also contribute to a global utility function. Agent's whose variables are linked to at least one common constraint are called neighbours \\cite{Chapman2011, Farinelli, Petcu2003}.\n\\newline\\newline \n% ----------------- Dynamic Distributed Constraint Optimization --------------------\nThe problem definition in dynamic distribute constraint optimization (DynDCO) is, as a further extension to DCOPs, moved from a static to a dynamic attribute. Constraints can change and  therefore change neighbourhoods and the outcome of private and global utility functions. A change of constraints inherently changes the area of satisfying solutions if hard constraints have been included in a problem definition. \\cite{Nguyen2012} state that changing the constraints might lead to the discovery of a better global optima. \\cite{Maillera} define a dynamic distributed constraint satisfaction problem (DCSP) as a sequence of DCSPs \\(\\{P_{0}, P_{1}, ..., P_{n}\\}\\) where every DCSP is a static problem definition. \\(P_{i}\\) is therefore a result of the previous DSCP in the sequence and also a result of the added and removed constraints: \\(P_{i} = P_{i-1} + c_{i^{a}} - c_{i^{r}}\\). This definition should also hold for DynDCOPs. Utility functions could also be dynamically changed. Modifying this property could especially have an impact on real-world problems like meeting scheduling, where it could move the global optima from one disconnected solution space to another \\cite{Nguyen2012}. Furthermore, variables could be added or removed in a dynamic setting and the problem domain \\(D\\) also could be changed during the course of the problem solving process.\n\n\\section{Meeting Scheduling Problem}  \n\n%--------------------- Introduction with examples\nScheduling is the problem of allocating tasks to a given set of ressources in an optimal order. The meeting scheduling problem is an exemplary type of this family of problems and is supposedly well-know to all of us. Participants of a meeting have private schedules with preferences when a meeting should be held according to their calendar. The challenge is to identify a time for a meeting that maximizes the preferences of all participants while being valid in then sense that every person is able to attend \\cite{Farinelli}. \\cite{Scheduling} have formally defined a meeting scheduling problem as:\n\n\\begin{itemize}\n\\item \\(P = {p1, p, ... pn}\\) is the set of people where every person has a calendar that holds r slots, \\(S = {s1,s2,s3}\\)\n\\item \\(M = {m1, m2, ..., m3}\\) is a set of k meetings\n\\item \\(At = {at1, at2, ..., atk}\\) defines all attendee's of a meeting\n\\end{itemize}\n\nThe c parameter has been neglected as it is not relevant to this thesis. From the definition of a valid solution, one can derive two important criteria to the problem solving process:\n\\theoremstyle{definition}\n\\newtheorem{hardconstraint1}{Validity Criterium}\n\\begin{hardconstraint1}\nAll participants need to agree on the same time for the meeting.\n\\end{hardconstraint1}\n\\begin{hardconstraint1}\nMeetings need to be scheduled in a way that there are no overlaps of meeting times in the schedules of the participants.\n\\end{hardconstraint1}\n    \nThere is further an inherent privacy aspect to the problem. Meeting participants are often not willing to share their schedules with others except to find a time for the specific meeting. It will later be shown that some of the algorithms can guarantee this privacy to a certain degree \\cite{Farinelli} \\cite{Scheduling}. The meeting scheduling problem will be mapped as a distributed constraint optimization problem in the design chapter.\n    \n    %--------------------- Explanation of the components with formal definition\n\\section{Algorithm Design Approaches}\n\n\\begin{figure}[h]\n\\includegraphics[width=400px]{graphics/overview_algos}\n\\caption{Categorization of DCO algorithms \\cite{Chapman2011}}\n\\label{fig:categorization}\n\\end{figure}\n\n\\cite{Chapman2011} categorize distributed constraint optimization algorithms into local-iterative and distributed complete algorithms. They further divide local-iterative into message-passing algorithms and approximate best-response algorithms (Figure \\ref{fig:categorization}). The following subsections are going to explain the differences between the three categories and introduce the specific algorithms, which have been chosen from these three different approaches for benchmarking. Advantages, as well as disadvantages will be described and which behaviour one can expect of these algorithms under certain parameter configurations.\n\n%Other Approaches: Bee Hive optimization, Genetic Algorithms, .. DynDCOAA, SBDO, Bee Colony algorithm, Ant colony algorithm, adopt, dsa-a, dsa-b stochastic ...\\cite{Likhachev}\n    \n\\subsection{Distributed Complete}\n\n%-----------------  Basic Concept and Advantages Disadvantes ----------------------\nDistributed complete algorithms always discover a configuration of value assignments for a set of variables that maximizes the global utility function. This completeness guarantee increases the complexity of computation and leads to exponentially growing message numbers or calculations when increasing the amount of variables in a problem. Messages between agents often contain complex structures and constraint problems usually need to be transformed to an extensive graph structure \\cite{Chapman2011}. These types of algorithms therefore are not expected to scale well and quickly find qualitative solutions, but they fit well if one wants to find the maximal utility of a problem. \n    %----------------- Chosen algorithm ----------------------\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=250px]{graphics/pseudotree}\n\\caption{Pseudotree in DPOP \\cite{Petcu2003}}\n\\label{fig:pseudotree}\n\\end{figure}\n\nFor this thesis, it was decided to implement the Dynamic Programming OPptimization algorithm (DPOP) proposed by \\cite{Petcu2003} as a comparison to the local-iterative approaches. In this algorithm, constraint optimization problems need to be converted to a pseudotree (Fig. \\ref{fig:pseudotree}), which is a modification of a DFS Tree. The original DCOP graph is transformed in a way that previous neighbours are placed in the same branches of a binary tree. They are connected trough ordinary tree edges and additionally, so-called back-edges between unconnected previous neighbours are established. The leaf nodes propose UTIL messages containing their utility values for each value assignment upwards the tree and the root node sends a VALUE message downwards, containing the best value to choose as a variable state. Nodes in the middle of the tree propagate UTIL and VALUE messages. The message structure is fairly complex as it involves all the utilities of the pseudoparents connected by the back-edges and their context in the graph, which increases the message size exponentially. The number of messages on the other hand is linear \\cite{Petcu2003}.\n\n%----------- Dynamics -----------------------\n\\subsection{Local-Iterative - Best Response}\n\n%-----------------  Basic Concept and Advantages Disadvantes ----------------------\nIn a local-iterative best-response algorithm, agents only communicate their current state, e.g. their value assignment and react to these value messages in the best possible way from their perspective. The agents are only connected to their neighbours with whom they share constraints and there exists no complex graph structure controlling the message flow \\cite{Chapman2011}. Through this local property, the types of algorithms should be inherently scalable as the messages and computations do not increase exponentially. Further, this approach is optimal from a privacy perspective as the neighbours only share their current preference and no other details of their schedule \\cite{Chapman2010}. %\\cite{Maheswaran} % Achtung muss das richtig paper finden\n\\newline\\newline\n%----------------- Chosen algorithm: Structure, Messages --------------------- \nFor this thesis, it was decided to implement the Maximum-Gain Messaging algorithm (MGM). In this algorithm, agents  calculate the maximal gain in utility they can achieve when assigning to another value and send this value as a message. If they have the highest gain compared to all received gain messages from their neighbours, the local value is changed. Otherwise the local value stays the same. This algorithm fullfills the anytime property, i.e it can provide a solution at every timepoint during calculation and also reaches good solutions quickly \\cite{Chapman2010}. As the decision of an agent depends on a complete set of message of all of its neighbours, this algorithm will supposedly not perform well in asynchronous running mode. This type of algorithm does further not always converge and the deliverance of an optimal solution to a problem is not guaranteed.\n\n\\subsection{Local-Iterative - Message Passing}\n%-----------------  Basic Concept and Advantages Disadvantes ----------------------\nThe difference of message-passing to best-response algorithms lays in the fact that the agents send and receive messages containing a specific data structure, which contains the utilities respectively costs that various assignments hold for a local variable. Received messages are used to calculate the next message, which is sent to the connected neighbours. These types of algorithms are - like best-response algorithms - able to provide an acceptable solution in a short period of time, but also share the charasteric to sometimes not converge or not providing an optimal solution \\cite{Chapman2011}.\n%-----------------  Choosen algorithm ----------------------\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=170px]{graphics/factorgraph}\n\\caption{Conversion of a general DCOP to a factor graph \\cite{Zivan2012}}\n\\label{fig:factorgraph}\n\\end{figure}\n\nFor this thesis, it was decided to implement the MaxSum algorithm introduced by \\cite{Farinelli2008}. The algorithm has currently gotten a lot of attention from researchers. For this work, the algorithm is especially interesting because of its proposed abilities in dynamic environments.  \\cite{Farinelli2008} wrote in their paper:\n\\begin{quote}\n[...] we note that if messages are continuously propagated,\nand the states of the agents are continuously updated, then the algorithm may be applied to dynamic problems where the interactions between agents, or the utilities resulting from these interactions, may change at any time.\n\\end{quote}\n\nIn MaxSum, the original DCOP graph is transformed to a factor graph, which is a form of a bipartite graph and of cyclic nature (Fig. \\ref{fig:factorgraph}). After the transformation, an agent is made up of a variable and a function node, whereas variables are connected to all corresponding function nodes of  their previous neighbours. The function nodes are vice versa connected to all previous neighbours of its variable node. \n% ------------- Messages sent --------------------\nThe messages sent from variable nodes differ from the function nodes. A message from variable to function contains for every value \\(d \\in D_{x}\\) the sum of utilities regarding this value, which the node has received from all connected function nodes. It is important to note that this sum does not include the values provided by the message target. The values are normalized at this point to avoid an infinite increase of the sum of the utilities. A message from a function node to a variable node holds for every value  \\(d \\in D_{x}\\)  the summation of all costs received from all connected variable nodes except the message receiver and the original cost respectively utility of the constraint represented by the function node \\cite{Zivan2012}.\n\n\n    \n    ", "meta": {"hexsha": "3c1d594a574f0b3a4690eaec8779d07889778966", "size": 14685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/report/section-relatedwork/relatedwork.tex", "max_stars_repo_name": "danihegglin/DynDCO", "max_stars_repo_head_hexsha": "4186857d1183eeff5721434f12afdca664af9c4b", "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": "documentation/report/section-relatedwork/relatedwork.tex", "max_issues_repo_name": "danihegglin/DynDCO", "max_issues_repo_head_hexsha": "4186857d1183eeff5721434f12afdca664af9c4b", "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": "documentation/report/section-relatedwork/relatedwork.tex", "max_forks_repo_name": "danihegglin/DynDCO", "max_forks_repo_head_hexsha": "4186857d1183eeff5721434f12afdca664af9c4b", "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": 135.9722222222, "max_line_length": 1363, "alphanum_fraction": 0.7721484508, "num_tokens": 3106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6381869538068311}}
{"text": "\\documentclass[11pt,letterpaper]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\n\\usepackage[charter]{mathdesign}\n\\usepackage{fullpage}\n\\pagestyle{empty}\n\n\\input{../fncextra}\n\n\\begin{document}\n\t\n\\begin{center}\n  \\bf \n  Project: To be continued\n\\end{center}\n\t\n\nRecall the case of a circular elastic membrane pinned at $z=1$ and subjected to an electrostatic force applied on the plane $z=0$. If we exploit the circular symmetry, we can reduce the problem to a BVP in the disk radius $r$:\n\\begin{equation}\n  \\label{eq:mems}\n  u''(r) + \\frac{1}{r} u'(r) = \\frac{\\lambda}{u^2},  \\qquad u'(0)=0, \\quad u(1)=1.\n\\end{equation}\nThis has been used as a model for an actuator device in a microelectromechanical system (MEMS). Because we would have some headaches with division by zero in this ODE, we multiply through by $r$ to get\n\\begin{equation}\n  \\label{eq:rmems}\n  r u''(r) + u'(r) = \\frac{r\\lambda}{u^2}.\n\\end{equation}\n\nThe behavior of this system as a function of the field strength $\\lambda$ is quite interesting. Clearly $u\\equiv 1$, $\\lambda=0$ is a trivial solution. As $\\lambda$ increases from zero, the membrane begins to deflect downward toward zero, with the greatest amount of deflection (i.e., smallest value of $u$) at the center point $r=0$. The amount of deflection continues to decrease until, at some critical value $\\lambda^*$, no solution exists. However, for some values $\\lambda < \\lambda^*$ there are at least two valid solutions. It's not at all clear how to figure out good initial guesses that will drive a Newton-type iteration to find the others. \n\nWhen the BVP is discretized, we use $n+1$ unknown values of $u$ and $n+1$ equations to specify them. But if we also think of $\\lambda$ as a parameter, we have $n+1$ equations in $n+2$ variables. This defines a curve or path in $(n+2)$-dimensional space---just like $x^2+y^2=1$ defines a curve in the plane. The situation can be visualized by this graph:\n\\begin{center}\n  \\includegraphics{strip_path}\n\\end{center}\n(This picture is \\emph{not} quantitatively accurate for your results!) \n\nWhat we really want to do is follow along the path, a technique known as \\emph{continuation}. There are many ways this can be done, but this particular problem gives us a fairly easy option. The key is to observe in the figure above that $\\lambda$ is a poor choice for parameterizing the path, because it fails the ``vertical line test.'' We are fortunate that in this problem, the value $u(0)$ is monotonic along the path, so it will serve as the parameter. To be specific, we solve a discretized form of~\\eqref{eq:rmems} for the $n+2$ unknowns $\\lambda,u_0,u_1,\\ldots,u_n$. As has been our practice, the ODE is discretized at the $n-1$ interior nodes only. To this are added the \\emph{three} supplemental conditions\n\\begin{equation}\n  \\label{eq:threebc}\n  u'(0)=0, \\qquad u(1)=1, \\qquad u(0)=1-s,\n\\end{equation}\nwhere $0\\le s < 1$ is a value under your control. You start at $s=0$ with the trivial solution mentioned above, then gradually increase $s$ to get a sequence $s_1,s_2,\\ldots$, corresponding to solutions $(\\lambda_1,\\bfu_1),(\\lambda_2,\\bfu_2)\\ldots$, which are points along the path. When solving the nonlinear equations for $s=s_{k+1}$, the starting guess should be $(\\lambda_k,\\bfu_k)$, which is hopefully near the next point. \n\n\n\\subsection*{Project assignment}\n\\label{sec:project-assignment}\n\nThe heart of the assignment is a function\n\\begin{verbatim}\n[u,lambda] = mems_solve(u0,lam0,s)\n\\end{verbatim}\nthat solves the ODE with the three side conditions in~\\eqref{eq:threebc}. Here \\texttt{lam0} is an initial guess for $\\lambda$, and the $(n+1)$-vector \\texttt{u0} is an initial guess for $\\bfu$. You should model this function after \\texttt{bvp}, but your function does not need to solve a general problem, just the specific one at hand. Like \\texttt{bvp}, your function will call \\texttt{levenberg} on a subfunction named \\texttt{residual}, but your version of \\texttt{residual} evaluates $n+2$ quantities for values of the $n+2$ variables in a given vector $\\bfz=\n\\begin{bmatrix}\n  \\lambda \\\\ \\bfu \n\\end{bmatrix}$. \nOnce \\verb!mems_solve! is working, you can call it within a loop to implement the steady increase of $s$. \n\nYour objectives are:\n\\begin{enumerate}\n\\item Find $\\lambda^*$ to at least two significant digits. This means taking small enough steps along the curve as well as giving evidence that the answer has converged as a function of the discretization size $n$.\n\\item Find a second turning point, $\\lambda^\\dagger<\\lambda^*$, to two digits. Past this turning point, $\\lambda$ begins to increase again as a function of $s$. \n\\item Make a plot like the one above for $0\\le s \\le 0.99$. \n\\item On one graph, plot $u(r)$ against $r$ for $s=0.1,0.3,0.5,0.7,0.9,0.95$. \n\\item How accurately can you find $\\lambda^*$? Think about how to get the most out the discretization accuracy and how to use something more sophisticated than just taking super-small steps in $s$. Style points matter here!\n\\end{enumerate}\n\nSubmit a PDF report describing your results and providing any necessary supporting information. Keep it concise and to the point---for instance, don't describe multiple attempts at the last item above, just your best one. Don't forget to label your plots! Also include your \\verb!mems_solve.m! and the code to reproduce the results for items~1--3 above. \n\n\\end{document}\n\n", "meta": {"hexsha": "8e925105bb7c7a0c3b2f38588c6370cc20037bfc", "size": 5444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/mems/mems.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": "projects/mems/mems.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": "projects/mems/mems.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": 72.5866666667, "max_line_length": 717, "alphanum_fraction": 0.7441219691, "num_tokens": 1536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.6381869515396136}}
{"text": "\\chapter{Introduction to linear regression}\n\\label{linRegrForTwoVar}\n\n\\index{linear regression|textbf}\n\nLinear regression is a very powerful statistical technique. Many people have some familiarity with regression just from reading the news, where graphs with straight lines are overlaid on scatterplots. Linear models can be used for prediction or to evaluate whether there is a linear relationship between two numerical variables.\n\nFigure~\\ref{perfLinearModel} shows two variables whose relationship can be modeled perfectly with a straight line. The equation for the line is\n\\begin{eqnarray*}\ny = 5 + 57.49x\n\\end{eqnarray*}\nImagine what a perfect linear relationship would mean: you would know the exact value of $y$ just by knowing the value of $x$. This is unrealistic in almost any natural process. For example, if we took family income $x$, this value would provide some useful information about how much financial support $y$ a college may offer a prospective student. However, there would still be variability in financial support, even when comparing students whose families have similar financial backgrounds.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.6\\textwidth]{05/figures/perfLinearModel/perfLinearModel}\n   \\caption{Requests from twelve separate buyers were simultaneously placed with a trading company to purchase Target Corporation stock (ticker \\texttt{TGT}, April 26th, 2012), and the total cost of the shares were reported. Because the cost is computed using a linear formula, the linear fit is perfect.}\n   \\label{perfLinearModel}\n\\end{figure}\n\nLinear regression assumes that the relationship between two variables, $x$ and $y$, can be modeled by a straight line:\n\\begin{eqnarray}\ny = \\beta_0 + \\beta_1x\n\\label{genLinModelWNoErrorTerm}\n\\end{eqnarray}\n\\marginpar[\\raggedright\\vspace{-10mm}\n\n$\\beta_0, \\beta_1$\\vspace{0.7mm}\\\\\\footnotesize Linear model\\\\ parameters]{\\raggedright\\vspace{-10mm}\n\n$\\beta_0, \\beta_1$\\vspace{0.7mm}\\\\\\footnotesize Linear model\\\\ parameters}where $\\beta_0$ and $\\beta_1$ represent two model parameters\\index{parameter} ($\\beta$ is the Greek letter \\emph{beta}\\index{Greek!beta@beta ($\\beta$)}). These parameters are estimated using data, and we write their point estimates as $b_0$ and $b_1$. When we use $x$ to predict $y$, we usually call $x$ the explanatory or \\textbf{predictor} variable, and we call $y$ the response.\n\nIt is rare for all of the data to fall on a straight line, as seen in the three scatterplots in Figure~\\ref{imperfLinearModel}. In each case, the data fall around a straight line, even if none of the observations fall exactly on the line. The first plot shows a relatively strong downward linear trend, where the remaining variability in the data around the line is minor relative to the strength of the relationship between $x$ and $y$. The second plot shows an upward trend that, while evident, is not as strong as the first. The last plot shows a very weak downward trend in the data, so slight we can hardly notice it. In each of these examples, we will have some uncertainty regarding our estimates of the model parameters, $\\beta_0$ and $\\beta_1$. For instance, we might wonder, should we move the line up or down a little, or should we tilt it more or less? As we move forward in this chapter, we will learn different criteria for line-fitting, and we will also learn about the uncertainty associated with estimates of model parameters.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=\\textwidth]{05/figures/imperfLinearModel/imperfLinearModel}\n   \\caption{Three data sets where a linear model may be useful even though the data do not all fall exactly on the line.}\n   \\label{imperfLinearModel}\n\\end{figure}\n\nWe will also see examples in this chapter where fitting a straight line to the data, even if there is a clear relationship between the variables, is not helpful. One such case is shown in Figure~\\ref{notGoodAtAllForALinearModel} where there is a very strong relationship between the variables even though the trend is not linear. We will discuss nonlinear trends in this chapter\\MultipleRegressionChapter{ and the next}{}, but the details of fitting nonlinear models are saved for a later course.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.87\\textwidth]{05/figures/notGoodAtAllForALinearModel/notGoodAtAllForALinearModel}\n   \\caption{A linear model is not useful in this nonlinear case. These data are from an introductory physics experiment.}\n   \\label{notGoodAtAllForALinearModel}\n\\end{figure}\n\n\\textA{\\newpage}\n\n\n%__________________\n\\section{Line fitting, residuals, and correlation}\n\\label{lineFittingResidualsCorrelation}\n\nIt is helpful to think deeply about the line fitting process. In this section, we examine criteria for identifying a linear model and introduce a new statistic, \\emph{correlation}.\n\n\\subsection{Beginning with straight lines}\n\n\\index{data!possum|(}\n\nScatterplots were introduced in Chapter~\\ref{introductionToData} as a graphical technique to present two numerical variables simultaneously. Such plots permit the relationship between the variables to be examined with ease. Figure~\\ref{scattHeadLTotalL} shows a scatterplot for the head length and total length of 104 brushtail possums from Australia. Each point represents a single possum from the data.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.85\\textwidth]{05/figures/scattHeadLTotalL/scattHeadLTotalL}\n   \\caption{A scatterplot showing head length against total length for 104 brushtail possums. A point representing a possum with head length 94.1mm and total length 89cm is highlighted.}\n   \\label{scattHeadLTotalL}\n\\end{figure}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.8\\textwidth]{05/figures/possumPic/possumPic}\n   \\caption{The common brushtail possum of Australia. Photo by wollombi on Flickr}\n   \\label{possumPic}\n\\end{figure}\n\nThe head and total length variables are associated. Possums with an above average total length also tend to have above average head lengths. While the relationship is not perfectly linear, it could be helpful to partially explain the connection between these variables with a straight line.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.9\\textwidth]{05/figures/scattHeadLTotalLTube/scattHeadLTotalLTube}\n   \\caption{The figure on the left shows head length versus total length, and reveals that many of the points could be captured by a straight band. On the right, we see that a curved band is more appropriate in the scatterplot for \\textbf{weight} and \\textbf{mpgCity} from the \\textbf{cars} data set.}\n   \\label{scattHeadLTotalLTube}\n\\end{figure}\n\nStraight lines should only be used when the data appear to have a linear relationship, such as the case shown in the left panel of Figure~\\ref{scattHeadLTotalLTube}. The right panel of Figure~\\ref{scattHeadLTotalLTube} shows a case where a curved line would be more useful in understanding the relationship between the two variables.\n\n\\begin{caution}\n{Watch out for curved trends}\n{We only consider models based on straight lines in this chapter. If data show a nonlinear trend, like that in the right panel of Figure~\\ref{scattHeadLTotalLTube}, more advanced techniques should be used.\\vspace{0.7mm}}\n\\end{caution}\n\n\n\\textA{\\pagebreak}\n\n\\subsection{Fitting a line by eye}\n\nWe want to describe the relationship between the head length and total length variables in the possum data set using a line. In this example, we will use the total length as the predictor variable, $x$, to predict a possum's head length, $y$. We could fit the linear relationship by eye, as in Figure~\\ref{scattHeadLTotalLLine}. The equation for this line is\n\\begin{eqnarray}\n\\hat{y} = 41 + 0.59x\n\\label{headLLinModTotalL}\n\\end{eqnarray}\nWe can use this line to discuss properties of possums. For instance, the equation predicts a possum with a total length of 80 cm will have a head length of\n\\begin{align*}\n\\hat{y} &= 41 + 0.59\\times 80 \\\\\n\t&= 88.2 % mm\n\\end{align*}\nA ``hat'' on $y$ is used to signify that this is an estimate. This estimate may be viewed as an average: the equation predicts that possums with a total length of 80 cm will have an average head length of 88.2 mm. Absent further information about an 80 cm possum, the prediction for head length that uses the average is a reasonable estimate.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.8\\textwidth]{05/figures/scattHeadLTotalLLine/scattHeadLTotalLLine}\n   \\caption{A reasonable linear model was fit to represent the relationship between head length and total length.}\n   \\label{scattHeadLTotalLLine}\n\\end{figure}\n\n\\subsection{Residuals}\n\n\\index{residual|(}\n\n\\termsub{Residuals}{residual} are the leftover variation in the data after accounting for the model fit:\n\\begin{align*}\n\\text{Data} = \\text{Fit} + \\text{Residual}\n\\end{align*}\nEach observation will have a residual. If an observation is above the regression line, then its residual, the vertical distance from the observation to the line, is positive. Observations below the line have negative residuals. One goal in picking the right linear model is for these residuals to be as small as possible.\n\nThree observations are noted specially in Figure~\\ref{scattHeadLTotalLLine}. The observation marked by an ``$\\times$'' has a small, negative residual of about -1; the observation marked by ``$+$'' has a large residual of about +7; and the observation marked by ``$\\triangle$'' has a moderate residual of about -4. The size of a residual is usually discussed in terms of its absolute value. For example, the residual for ``$\\triangle$'' is larger than that of ``$\\times$'' because $|-4|$ is larger than $|-1|$.\n\n\\begin{termBox}{\\tBoxTitle{Residual: difference between observed and expected}\nThe residual of the $i^{th}$ observation $(x_i, y_i)$ is the difference of the observed response ($y_i$) and the response we would predict based on the model fit ($\\hat{y}_i$):\n\\begin{eqnarray*}\ne_i = y_i - \\hat{y}_i\n\\end{eqnarray*}\nWe typically identify $\\hat{y}_i$ by plugging $x_i$ into the model.}\n\\end{termBox}\n\n\\begin{example}{The linear fit shown in Figure~\\ref{scattHeadLTotalLLine} is given as $\\hat{y} = 41 + 0.59x$. Based on this line, formally compute the residual of the observation $(77.0, 85.3)$. This observation is denoted by ``$\\times$'' on the plot. Check it against the earlier visual estimate,~-1.}\nWe first compute the predicted value of point ``$\\times$'' based on the model:\n\\begin{eqnarray*}\n\\hat{y}_{\\times} = 41+0.59x_{\\times} = 41+0.59\\times 77.0 = 86.4\n\\end{eqnarray*}\nNext we compute the difference of the actual head length and the predicted head length:\n\\begin{eqnarray*}\ne_{\\times} = y_{\\times} - \\hat{y}_{\\times} = 85.3 -  86.4 = -1.1\n\\end{eqnarray*}\nThis is very close to the visual estimate of -1.\n\\end{example}\n\n\\begin{exercise}\nIf a model underestimates an observation, will the residual be positive or negative? What about if it overestimates the observation?\\footnote{If a model underestimates an observation, then the model estimate is below the actual. The residual, which is the actual observation value minus the model estimate, must then be positive. The opposite is true when the model overestimates the observation: the residual is negative.}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the residuals for the observations $(85.0, 98.6)$ (``$+$'' in the figure) and $(95.5, 94.0)$ (``$\\triangle$'') using the linear relationship $\\hat{y} = 41 + 0.59x$. \\footnote{($+$) First compute the predicted value based on the model: $$\\hat{y}_{+} = 41+0.59x_{+} = 41+0.59\\times 85.0 = 91.15$$ Then the residual is given by $$e_{+} = y_{+} - \\hat{y}_{+} = 98.6-91.15=7.45$$This was close to the earlier estimate of 7.\n\n($\\triangle$) $\\hat{y}_{\\triangle} = 41+0.59x_{\\triangle} = 97.3$. $e_{\\triangle} = y_{\\triangle} - \\hat{y}_{\\triangle} = -3.3$, close to the estimate of -4.}\n\\end{exercise}\n\nResiduals are helpful in evaluating how well a linear model fits a data set. We often display them in a \\textbf{residual plot} such as the one shown in Figure~\\ref{scattHeadLTotalLResidualPlot} for the regression line in Figure~\\ref{scattHeadLTotalLLine}. The residuals are plotted at their original horizontal locations but with the vertical coordinate as the residual. For instance, the point $(85.0,98.6)_{+}$ had a residual of 7.45, so in the residual plot it is placed at $(85.0, 7.45)$. Creating a residual plot is sort of like tipping the scatterplot over so the regression line is horizontal. \n\\index{data!possum|)}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.73\\textwidth]{05/figures/scattHeadLTotalLResidualPlot/scattHeadLTotalLResidualPlot}\n   \\caption{Residual plot for the model in Figure~\\ref{scattHeadLTotalLLine}.}\n   \\label{scattHeadLTotalLResidualPlot}\n\\end{figure}\n\n\\begin{example}{One purpose of residual plots is to identify characteristics or patterns still apparent in data after fitting a model. Figure~\\ref{sampleLinesAndResPlots} shows three scatterplots with linear models in the first row and residual plots in the second row. Can you identify any patterns remaining in the residuals?}\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=\\textwidth]{05/figures/sampleLinesAndResPlots/sampleLinesAndResPlots}\n   \\caption{Sample data with their best fitting lines (top row) and their corresponding residual plots (bottom row).}\n   \\label{sampleLinesAndResPlots}\n\\end{figure}\nIn the first data set (first column), the residuals show no obvious patterns. The residuals appear to be scattered randomly around the dashed line that represents 0.\n\nThe second data set shows a pattern in the residuals. There is some curvature in the scatterplot, which is more obvious in the residual plot. We should not use a straight line to model these data. Instead, a more advanced technique should be used.\n\nThe last plot shows very little upwards trend, and the residuals also show no obvious patterns. It is reasonable to try to fit a linear model to the data. However, it is unclear whether there is statistically significant evidence that the slope parameter is different from zero. The point estimate of the slope parameter, labeled $b_1$, is not zero, but we might wonder if this could just be due to chance. We will address this sort of scenario in Section~\\ref{inferenceForLinearRegression}.\n\\index{residual|)}\n\\end{example}\n\n\\subsection{Describing linear relationships with correlation}\n\n\\index{correlation|(}\n\n\\begin{termBox}{\\tBoxTitle{Correlation: strength of a linear relationship}\n\\termsub{Correlation}{correlation}, which always takes values between -1 and 1, describes the strength of the linear relationship between two variables. We denote the correlation by $R$.}\n\\end{termBox}\\marginpar[\\raggedright\\vspace{-11.5mm}\n\n$R$\\\\\\footnotesize correlation]{\\raggedright\\vspace{-11.5mm}\n\n$R$\\\\\\footnotesize correlation}\n\nWe can compute the correlation using a formula, just as we did with the sample mean and standard deviation. However, this formula is rather complex,\\footnote{Formally, we can compute the correlation for observations $(x_1, y_1)$, $(x_2, y_2)$, ..., $(x_n, y_n)$ using the formula\n\\begin{eqnarray*}\nR = \\frac{1}{n-1}\\sum_{i=1}^{n} \\frac{x_i-\\bar{x}}{s_x}\\frac{y_i-\\bar{y}}{s_y}\n\\end{eqnarray*}\nwhere $\\bar{x}$, $\\bar{y}$, $s_x$, and $s_y$ are the sample means and standard deviations for each variable.} so we generally perform the calculations on a computer or calculator. Figure~\\ref{posNegCorPlots} shows eight plots and their corresponding correlations. Only when the relationship is perfectly linear is the correlation either -1 or 1. If the relationship is strong and positive, the correlation will be near +1. If it is strong and negative, it will be near -1. If there is no apparent linear relationship between the variables, then the correlation will be near zero.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.9\\textwidth]{05/figures/posNegCorPlots/posNegCorPlots}\n   \\caption{Sample scatterplots and their correlations. The first row shows variables with a positive relationship, represented by the trend up and to the right. The second row shows variables with a negative trend, where a large value in one variable is associated with a low value in the other.}\n   \\label{posNegCorPlots}\n\\end{figure}\n\nThe correlation is intended to quantify the strength of a linear trend. Nonlinear trends, even when strong, sometimes produce correlations that do not reflect the strength of the relationship; see three such examples in Figure~\\ref{corForNonLinearPlots}.\n\n\\begin{figure}\n   \\centering\n   \\includegraphics[width=0.96\\textwidth]{05/figures/posNegCorPlots/corForNonLinearPlots}\n   \\caption{Sample scatterplots and their correlations. In each case, there is a strong relationship between the variables. However, the correlation is not very strong, and the relationship is not linear.}\n   \\label{corForNonLinearPlots}\n\\end{figure}\n\n\\begin{exercise}\nIt appears no straight line would fit any of the datasets represented in Figure~\\ref{corForNonLinearPlots}. Instead, try drawing nonlinear curves on each plot. Once you create a curve for each, describe what is important in your fit.\\footnote{We'll leave it to you to draw the lines. In general, the lines you draw should be close to most points and reflect overall trends in the data.}\n\\index{correlation|)}\n\\end{exercise}\n\n\n%__________________\n\\section{Fitting a line by least squares regression}\n\\label{fittingALineByLSR}\n\n\\index{least squares regression|(}\n\nFitting linear models by eye is open to criticism since it is based on an individual preference. In this section, we use \\emph{least squares regression} as a more rigorous approach.\n\nThis section considers family income and gift aid data from a random sample of fifty students in the 2011 freshman class of Elmhurst College in Illinois.\\footnote{These data were sampled from a table of data for all freshman from the 2011 class at Elmhurst College that accompanied an article titled \\emph{What Students Really Pay to Go to College} published online by \\emph{The~Chronicle of Higher Education}: \\href{http://chronicle.com/article/What-Students-Really-Pay-to-Go/131435}{chronicle.com/article/What-Students-Really-Pay-to-Go/131435}} Gift aid is financial aid that does not need to be paid back, as opposed to a loan. A scatterplot of the data is shown in Figure~\\ref{elmhurstScatterW2Lines} along with two linear fits. The lines follow a negative trend in the data; students who have higher family incomes tended to have lower gift aid from the university.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.75\\textwidth]{05/figures/elmhurstPlots/elmhurstScatterW2Lines}\n\\caption{Gift aid and family income for a random sample of 50 freshman students from Elmhurst College. Two lines are fit to the data, the solid line being the \\emph{least squares line}.}\n\\label{elmhurstScatterW2Lines}\n\\end{figure}\n\n\\begin{exercise}\nIs the correlation positive or negative in Figure~\\ref{elmhurstScatterW2Lines}?\\footnote{Larger family incomes are associated with lower amounts of aid, so the correlation will be negative. Using a computer, the correlation can be computed: -0.499.}\n\\end{exercise}\n\n\n\\subsection{An objective measure for finding the best line}\n\nWe begin by thinking about what we mean by ``best''. Mathematically, we want a line that has small residuals. Perhaps our criterion could minimize the sum of the residual magnitudes:\\textA{\\vspace{-4mm}}\n\\begin{eqnarray}\n|e_1| + |e_2| + \\dots + |e_n|\n\\label{sumOfAbsoluteValueOfResiduals}\n\\end{eqnarray}\nwhich we could accomplish with a computer program. The resulting dashed line shown in Figure~\\ref{elmhurstScatterW2Lines} demonstrates this fit can be quite reasonable. However, a more common practice is to choose the line that minimizes the sum of the squared residuals:\\textA{\\vspace{-1mm}}\n\\begin{eqnarray}\ne_{1}^2 + e_{2}^2 + \\dots + e_{n}^2\n\\label{sumOfSquaresForResiduals}\n\\end{eqnarray}\nThe line that minimizes this \\textbf{least squares criterion} is represented as the solid line in Figure~\\ref{elmhurstScatterW2Lines}. This is commonly called the \\textbf{least squares line}. The following are three possible reasons to choose Criterion~\\eqref{sumOfSquaresForResiduals} over Criterion~\\eqref{sumOfAbsoluteValueOfResiduals}:\n\\begin{enumerate}\n\\item It is the most commonly used method.\n\\item Computing the line based on Criterion~\\eqref{sumOfSquaresForResiduals} is much easier by hand and in most statistical software.\n\\item In many applications, a residual twice as large as another residual is more than twice as bad. For example, being off by 4 is usually more than twice as bad as being off by 2. Squaring the residuals accounts for this discrepancy.\n\\end{enumerate}\nThe first two reasons are largely for tradition and convenience; the last reason explains why Criterion~\\eqref{sumOfSquaresForResiduals} is typically most helpful.\\footnote{There are applications where Criterion~\\eqref{sumOfAbsoluteValueOfResiduals} may be more useful, and there are plenty of other criteria we might consider. However, this book only applies the least squares criterion.}\n\n\n\\subsection{Finding the least squares line}\n\\label{findingTheLeastSquaresLineSection}\n\nFor the Elmhurst data, we could write the equation of the least squares regression line as\n\\begin{eqnarray*}\n\\widehat{aid} = \\beta_0 + \\beta_{1}\\times family\\_\\hspace{0.3mm}income\n\\end{eqnarray*}\nHere the equation is set up to predict gift aid based on a student's family income, which would be useful to students considering Elmhurst. These two values, $\\beta_0$ and $\\beta_1$, are the \\emph{parameters} of the regression line.\n\nAs in Chapters~4-6, the parameters are estimated using observed data. In practice, this estimation is done using a computer in the same way that other estimates, like a sample mean, can be estimated using a computer or calculator. However, we can also find the parameter estimates by applying two properties of the least squares line:\n\\begin{itemize}\n\\setlength{\\itemsep}{0mm}\n\\item The slope of the least squares line can be estimated by\n\\begin{eqnarray}\nb_1 = \\frac{s_y}{s_x} R\n\\label{slopeOfLSRLine}\n\\end{eqnarray}\nwhere $R$ is the correlation between the two variables, and $s_x$ and $s_y$ are the sample standard deviations of the explanatory variable %(variable on the horizontal axis) \nand response% (variable on the vertical axis)\n, respectively.\n\\item If $\\bar{x}$ is the mean of the horizontal variable (from the data) and $\\bar{y}$ is the mean of the vertical variable, then the point $(\\bar{x}, \\bar{y})$ is on the least squares line.\n\\end{itemize}\n\\marginpar[\\raggedright\\vspace{0.5mm}\n\n$b_0, b_1$\\vspace{0.5mm}\\\\\\footnotesize Sample\\\\estimates\\\\ of $\\beta_0$, $\\beta_1$]{\\raggedright\\vspace{0.5mm}\n\n$b_0, b_1$\\vspace{0.5mm}\\\\\\footnotesize Sample\\\\estimates\\\\ of $\\beta_0$, $\\beta_1$}We use $b_0$ and $b_1$ to represent the point estimates of the parameters $\\beta_0$ and $\\beta_1$.\n\n\\begin{exercise}\nTable~\\ref{summaryStatsOfSATGPAData} shows the sample means for the family income and gift aid as \\$101,800 and \\$19,940, respectively. Plot the point $(101.8, 19.94)$ on Figure~\\vref{elmhurstScatterW2Lines} to verify it falls on the least squares line (the solid line).\\footnote{If you need help finding this location, draw a straight line up from the x-value of 100 (or thereabout). Then draw a horizontal line at 20 (or thereabout). These lines should intersect on the least squares line.}\n\\end{exercise}\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{l rr}\n\\hline\n\\vspace{-4mm} & & \\\\\n\\vspace{0.4mm}\t&\t\\ \\ family income, in \\$1000s (``$x$'')\t& \\ \\ gift aid, in \\$1000s (``$y$'') \\\\\n\\hline\n  \\vspace{-3.9mm} & & \\\\\nmean\t& $\\bar{x} = 101.8$\t\t& $\\bar{y} = 19.94$ \\\\\nsd\t\t& $s_x = 63.2$\t\t& $s_y = 5.46$\\vspace{0.4mm} \\\\\n\\hline\n\\vspace{-4mm}\\ &\\\\\n\t& \\multicolumn{2}{r}{$R=-0.499$} \\\\\n\\hline\n\\end{tabular}\n\\caption{Summary statistics for family income and gift aid.}\n\\label{summaryStatsOfSATGPAData}\n\\end{table}\n\n\\begin{exercise} \\label{findingTheSlopeOfTheLSRLineForIncomeAndAid}\nUsing the summary statistics in Table~\\ref{summaryStatsOfSATGPAData}, compute the slope for the regression line of gift aid against family income.\\footnote{Apply Equation~\\eqref{slopeOfLSRLine} with the summary statistics from Table~\\ref{summaryStatsOfSATGPAData} to compute the slope:\n\\begin{eqnarray*}\nb_1 = \\frac{s_y}{s_x} R = \\frac{5.46}{63.2}(-0.499) = -0.0431\n\\end{eqnarray*}\\vspace{-3mm}}\n\\end{exercise}\n\nYou might recall the \\textbf{point-slope} form of a line from math class (another common form is \\emph{slope-intercept}). Given the slope of a line and a point on the line, $(x_0, y_0)$, the equation for the line can be written as\n\\begin{eqnarray}\ny - y_0 = slope\\times (x - x_0)\n\\label{pointSlopeFormForALine}\n\\end{eqnarray}\nA common exercise to become more familiar with foundations of least squares regression is to use basic summary statistics and point-slope form to produce the least squares line. \n\n\\begin{tipBox}{\\tipBoxTitle{Identifying the least squares line from summary statistics}\nTo identify the least squares line from summary statistics:\\vspace{-1mm}\n\\begin{itemize}\n\\setlength{\\itemsep}{0mm}\n\\item Estimate the slope parameter, $\\beta_1$, by calculating $b_1$ using Equation~\\eqref{slopeOfLSRLine}.\n\\item Noting that the point $(\\bar{x}, \\bar{y})$ is on the least squares line, use $x_0=\\bar{x}$ and $y_0=\\bar{y}$ along with the slope $b_1$ in the point-slope equation:\n$$y - \\bar{y} = b_1 (x - \\bar{x}) $$\n\\item Simplify the equation.\\vspace{0.5mm}\n\\end{itemize}}\n\\end{tipBox}\n\n\\textA{\\pagebreak}\n\n\\begin{example}{Using the point $(101.8, 19.94)$ from the sample means and the slope estimate $b_1 = -0.0431$ from Guided Practice~\\ref{findingTheSlopeOfTheLSRLineForIncomeAndAid}, find the least-squares line for predicting aid based on family income.} \\label{exampleToFindLSRLineOfElmhurstData}\nApply the point-slope equation using $(101.8, 19.94)$ and the slope $b_1 = -0.0431$:\n\\begin{align*}\ny - y_0     &= b_1 (x - x_0) \\\\\ny - 19.94  &= -0.0431(x - 101.8)\n\\end{align*}\nExpanding the right side and then adding 19.94 to each side, the equation simplifies:\n$$ \\widehat{aid} = 24.3 - 0.0431 \\times family\\_\\hspace{0.3mm}income $$\nHere we have replaced $y$ with $\\widehat{aid}$ and $x$ with $family\\_\\hspace{0.3mm}income$ to put the equation in context.\n\\end{example}\n\nWe mentioned earlier that a computer is usually used to compute the least squares line. A summary table based on computer output is shown in Table~\\ref{rOutputForIncomeAidLSRLine} for the Elmhurst data. The first column of numbers provides estimates for ${b}_0$ and ${b}_1$, respectively. Compare these to the result from Example~\\ref{exampleToFindLSRLineOfElmhurstData}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{l rrrr}\n  \\hline\n  \\vspace{-3.7mm} & & & & \\\\\n & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\\\ \n  \\hline\n  \\vspace{-3.6mm} & & & & \\\\\n(Intercept) & 24.3193 & 1.2915 & 18.83 & 0.0000 \\\\ \nfamily\\_\\hspace{0.3mm}income & -0.0431 & 0.0108 & -3.98 & 0.0002 \\\\ \n  \\hline\n\\end{tabular}\n\\caption{Summary of least squares fit for the Elmhurst data. Compare the parameter estimates in the first column to the results of Example~\\ref{exampleToFindLSRLineOfElmhurstData}.}\n\\label{rOutputForIncomeAidLSRLine}\n\\end{table}\n\n\\begin{example}{Examine the second, third, and fourth columns in Table~\\ref{rOutputForIncomeAidLSRLine}. Can you guess what they represent?}\nWe'll describe the meaning of the columns using the second row, which corresponds to~$\\beta_1$. The first column provides the point estimate for $\\beta_1$, as we calculated in an earlier example: -0.0431. The second column is a standard error for this point estimate: 0.0108. The third column is a $t$ test statistic for the null hypothesis that $\\beta_1 = 0$: $T=-3.98$. The last column is the p-value for the $t$ test statistic for the null hypothesis $\\beta_1=0$ and a two-sided alternative hypothesis: 0.0002. We will get into more of these details in Section~\\ref{inferenceForLinearRegression}.\n\\end{example}\n\n\\begin{example}{Suppose a high school senior is considering Elmhurst College. Can she simply use the linear equation that we have estimated to calculate her financial aid from the university?}\nShe may use it as an estimate, though some qualifiers on this approach are important. First, the data all come from one freshman class, and the way aid is determined by the university may change from year to year. Second, the equation will provide an imperfect estimate. While the linear equation is good at capturing the trend in the data, no individual student's aid will be perfectly predicted.\n\\index{least squares regression|)}\n\\end{example} \n\n\\subsection{Interpreting regression line parameter estimates}\n\n\\index{least squares regression!interpreting parameters|(}\n\nInterpreting parameters in a regression model is often one of the most important steps in the analysis.\n\n\\begin{example}{The slope and intercept estimates for the Elmhurst data are -0.0431 and 24.3. What do these numbers really mean?}\nInterpreting the slope parameter is helpful in almost any application. For each additional \\$1,000 of family income, we would expect a student to receive a net difference of $\\$\\text{1,000}\\times (-0.0431) = -\\$43.10$ in aid on average, i.e. \\$43.10 \\emph{less}. Note that a higher family income corresponds to less aid because the coefficient of family income is negative in the model. We must be cautious in this interpretation: while there is a real association, we cannot interpret a causal connection between the variables because these data are observational. That is, increasing a student's family income may not cause the student's aid to drop. (It would be reasonable to contact the college and ask if the relationship is causal, i.e. if Elmhurst College's aid decisions are partially based on students' family income.)\n\nThe estimated intercept $b_0=24.3$ (in \\$1000s) describes the average aid if a student's family had no income. The meaning of the intercept is relevant to this application since the family income for some students at Elmhurst is \\$0. In other applications, the intercept may have little or no practical value if there are no observations where $x$ is near zero.\n\\end{example}\n\n\\begin{termBox}{\\tBoxTitle{Interpreting parameters estimated by least squares}\nThe slope describes the estimated difference in the $y$ variable if the explanatory variable $x$ for a case happened to be one unit larger. The intercept describes the average outcome of $y$ if $x=0$ \\emph{and} the linear model is valid all the way to $x=0$, which in many applications is not the case.}\n\\index{least squares regression!interpreting parameters|)}\n\\end{termBox}\n\n\\subsection{Extrapolation is treacherous}\n\n\\index{least squares regression!extrapolation|(}\n\n{\\em\\small When those blizzards hit the East Coast this winter, it proved to my satisfaction that global warming was a fraud. That snow was freezing cold. But in an alarming trend, temperatures this spring have risen. Consider this: On February $6^{th}$ it was 10 degrees. Today it hit almost 80. At this rate, by August it will be 220 degrees. So clearly folks the climate debate rages on.\\vspace{0.5mm}}\n\n\\noindent\\hspace{\\textwidth}\\hspace{-40mm}Stephen Colbert\n\n\\noindent\\hspace{\\textwidth}\\hspace{-40mm}April 6th, 2010 \\footnote{\\urlwofont{http://www.colbertnation.com/the-colbert-report-videos/269929/}} \\\\\n\nLinear models can be used to approximate the relationship between two variables. However, these models have real limitations. Linear regression is simply a modeling framework. The truth is almost always much more complex than our simple line. For example, we do not know how the data outside of our limited window will behave.\n\n\\textA{\\pagebreak}\n\n\\begin{example}{Use the model $\\widehat{aid} = 24.3 - 0.0431\\times family\\_\\hspace{0.3mm}income$ to estimate the aid of another freshman student whose family had income of \\$1 million.}\nRecall that the units of family income are in \\$1000s, so we want to calculate the aid for $family\\_\\hspace{0.3mm}income = 1000$:\n\\begin{align*}\n24.3 - 0.0431\\times family\\_\\hspace{0.3mm}income  = 24.3 - 0.0431\\times 1000 = -18.8\n\\end{align*}\nThe model predicts this student will have -\\$18,800 in aid (!). Elmhurst College cannot (or at least does not) require any students to pay extra on top of tuition to attend.\n\\end{example}\n\nApplying a model estimate to values outside of the realm of the original data is called \\textbf{extrapolation}. Generally, a linear model is only an approximation of the real relationship between two variables. If we extrapolate, we are making an unreliable bet that the approximate linear relationship will be valid in places where it has not been explored.\n\n\\index{least squares regression!extrapolation|)}\n\n\\subsection{Using $R^2$ to describe the strength of a fit}\n\n\\index{least squares regression!R-squared ($R^2$)|(}\n\nWe evaluated the strength of the linear relationship between two variables earlier using the correlation, $R$. However, it is more common to explain the strength of a linear fit using $R^2$, called \\termsub{R-squared}{least squares regression!R-squared ($R^2$)}. If provided with a linear model, we might like to describe how closely the data cluster around the linear fit.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.75\\textwidth]{05/figures/elmhurstPlots/elmhurstScatterWLSROnly}\n\\caption{Gift aid and family income for a random sample of 50 freshman students from Elmhurst College, shown with the least squares regression line.}\n\\label{elmhurstScatterWLSROnly}\n\\end{figure}\n\nThe $R^2$ of a linear model describes the amount of variation in the response that is explained by the least squares line. For example, consider the Elmhurst data, shown in Figure~\\ref{elmhurstScatterWLSROnly}. The variance of the response variable, aid received, is $s_{aid}^2=29.8$. However, if we apply our least squares line, then this model reduces our uncertainty in predicting aid using a student's family income. The variability in the residuals describes how much variation remains after using the model: $s_{_{RES}}^2 = 22.4$. In short, there was a reduction of\n$$\\frac{s_{aid}^2 - s_{_{RES}}^2}{s_{_{aid}}^2}\n\t= \\frac{29.8 - 22.4}{29.8} = \\frac{7.5}{29.8}\n\t= 0.25$$\nor about  25\\% in the data's variation by using information about family income for predicting aid using a linear model. This corresponds exactly to the R-squared value:\n\\begin{align*}\nR &= -0.499 &R^2 &= 0.25\n\\end{align*}\n\n\\begin{exercise}\nIf a linear model has a very strong negative relationship with a correlation of -0.97, how much of the variation in the response is explained by the explanatory variable?\\footnote{About $R^2 = (-0.97)^2 = 0.94$ or 94\\% of the variation is explained by the linear model.}\n\\index{least squares regression!R-squared ($R^2$)|)}\n\\end{exercise}\n\n\\subsection{Categorical predictors with two levels}\n\\label{categoricalPredictorsWithTwoLevels}\n\nCategorical variables are also useful in predicting outcomes. Here we consider a categorical predictor with two levels (recall that a \\emph{level} is the same as a \\emph{category}). We'll consider Ebay auctions for a video game, \\emph{Mario Kart} for the Nintendo Wii, where both the total price of the auction and the condition of the game were recorded.\\footnote{These data were collected in Fall 2009 and may be found at \\href{http://www.openintro.org}{openintro.org}.} Here we want to predict total price based on game condition, which takes values \\resp{used} and \\resp{new}. A plot of the auction data is shown in Figure~\\ref{marioKartNewUsed}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.65\\textwidth]{05/figures/marioKartNewUsed/marioKartNewUsed}\n\\caption{Total auction prices for the video game \\emph{Mario Kart}, divided into used ($x=0$) and new ($x=1$) condition games. The least squares regression line is also shown.}\n\\label{marioKartNewUsed}\n\\end{figure}\n\nTo incorporate the game condition variable into a regression equation, we must convert the categories into a numerical form. We will do so using an \\textbf{indicator variable} called \\textbf{cond\\_\\hspace{0.3mm}new}, which takes value 1 when the game is new and 0 when the game is used. Using this indicator variable, the linear model may be written as\n\\begin{align*}\n\\widehat{price} = \\beta_0 + \\beta_1 \\times \\text{\\textbf{cond\\_\\hspace{0.3mm}new}}\n\\end{align*}\nThe fitted model is summarized in Table~\\ref{marioKartNewUsedRegrSummary}, and the model with its parameter estimates is given as\n\\begin{align*}\n\\widehat{price} = 42.87 + 10.90 \\times \\text{\\textbf{cond\\_\\hspace{0.3mm}new}}\n\\end{align*}\n\n\\begin{table}\n\\centering\n\\begin{tabular}{rrrrr}\n  \\hline\n  \\vspace{-3.7mm} & & & & \\\\\n & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\\\ \n  \\hline\n  \\vspace{-3.6mm} & & & & \\\\\n(Intercept) & 42.87 & 0.81 & 52.67 & 0.0000 \\\\ \n  cond\\_\\hspace{0.3mm}new & 10.90 & 1.26 & 8.66 & 0.0000 \\\\ \n   \\hline\n\\end{tabular}\n\\caption{Least squares regression summary for the final auction price against the condition of the game.}\n\\label{marioKartNewUsedRegrSummary}\n\\end{table}\n\n\\begin{example}{Interpret the two parameters estimated in the model for the price of \\emph{Mario Kart} in eBay auctions.}\nThe intercept is the estimated price when \\textbf{cond\\_\\hspace{0.3mm}new} takes value 0, i.e. when the game is in used condition. That is, the average selling price of a used version of the game is \\$42.87.\n\nThe slope indicates that, on average, new games sell for about \\$10.90 more than used games.\n\\end{example}\n\n\\begin{tipBox}{\\tipBoxTitle{Interpreting model estimates for categorical predictors.}\nThe estimated intercept is the value of the response variable for the first category (i.e. the category corresponding to an indicator value of 0). The estimated slope is the average change in the response variable between the two categories.}\n\\end{tipBox}\n\n\\MultipleRegression{We'll elaborate further on this Ebay auction data in Chapter~\\ref{multipleRegressionAndANOVA}, where we examine the influence of many predictor variables simultaneously using multiple regression\\index{multiple regression}. In multiple regression, we will consider the association of auction price with regard to each variable while controlling for the influence of other variables. This is especially important since some of the predictors are associated. For example, auctions with games in new condition also often came with more accessories.}{}\n\n\n%__________________\n\\section{Types of outliers in linear regression}\n\\label{typesOfOutliersInLinearRegression}\n\nIn this section, we identify criteria for determining which outliers are important and influential.\n\nOutliers in regression are observations that fall far from the ``cloud'' of points. These points are especially important because they can have a strong influence on the least squares line.\n\n\\textA{\\pagebreak}\n\n\\begin{example}{There are six plots shown in Figure~\\ref{outlierPlots} along with the least squares line and residual plots. For each scatterplot and residual plot pair, identify any obvious outliers and note how they influence the least squares line. Recall that an outlier is any point that doesn't appear to belong with the vast majority of the other points.}\\label{outlierPlotsExample}\n\\begin{itemize}\n\\item[(1)] There is one outlier far from the other points, though it only appears to slightly influence the line.\n\\item[(2)] There is one outlier on the right, though it is quite close to the least squares line, which suggests it wasn't very influential.\n\\item[(3)] There is one point far away from the cloud, and this outlier appears to pull the least squares line up on the right; examine how the line around the primary cloud doesn't appear to fit very well.\n\\item[(4)] There is a primary cloud and then a small secondary cloud of four outliers. The secondary cloud appears to be influencing the line somewhat strongly, making the least square line fit poorly almost everywhere. There might be an interesting explanation for the dual clouds, which is something that could be investigated.\n\\item[(5)] There is no obvious trend in the main cloud of points and the outlier on the right appears to largely control the slope of the least squares line.\n\\item[(6)] There is one outlier far from the cloud, however, it falls quite close to the least squares line and does not appear to be very influential.\n\\end{itemize}\n\\end{example}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{05/figures/outlierPlots/outlierPlots}\n\\caption{Six plots, each with a least squares line and residual plot. All data sets have at least one outlier.}\n\\label{outlierPlots}\n\\end{figure}\n\nExamine the residual plots in Figure~\\ref{outlierPlots}. You will probably find that there is some trend in the main clouds of (3) and (4). In these cases, the outliers influenced the slope of the least squares lines. In (5), data with no clear trend were assigned a line with a large trend simply due to one outlier (!).\n \n \\begin{termBox}{\\tBoxTitle{Leverage}\nPoints that fall horizontally away from the center of the cloud tend to pull harder on the line, so we call them points with \\textbf{high leverage}.}\n\\end{termBox}\n\nPoints that fall horizontally far from the line are points of high leverage; these points can strongly influence the slope of the least squares line. If one of these high leverage points does appear to actually invoke its influence on the slope of the line -- as in cases (3), (4), and (5) of Example~\\ref{outlierPlotsExample} -- then we call it an \\textbf{influential point}. Usually we can say a point is influential if, had we fitted the line without it, the influential point would have been unusually far from the least squares line.\n\nIt is tempting to remove outliers. Don't do this without a very good reason. Models that ignore exceptional (and interesting) cases often perform poorly. For instance, if a financial firm ignored the largest market swings -- the ``outliers'' --  they would soon go bankrupt by making poorly thought-out investments.\n\n\\begin{caution}{Don't ignore outliers when fitting a final model}\n{If there are outliers in the data, they should not be removed or ignored without a~good reason. Whatever final model is fit to the data would not be very helpful if it ignores the most exceptional cases.}\n\\end{caution}\n\n\\begin{caution}{Outliers for a categorical predictor with two levels}{\nBe cautious about using a categorical predictor when one of the levels has very few observations. When this happens, those few observations become influential points.}\n\\end{caution}\n\n\n%__________________\n\\section{Inference for linear regression}\n\\label{inferenceForLinearRegression}\n\nIn this section we discuss uncertainty in the estimates of the slope and y-intercept for a regression line. Just as we identified standard errors for point estimates in previous chapters, we first discuss standard errors for these new estimates. However, in the case of regression, we will identify standard errors using statistical software.\n\n\n\\subsection{Conditions for the least squares line}\n\nWhen performing inference on a least squares line, we generally require the following:\n\\begin{description}\n\\setlength{\\itemsep}{0mm}\n\\item[Linearity.] The data should show a linear trend. If there is a nonlinear trend (e.g. left panel of Figure~\\ref{whatCanGoWrongWithLinearModel}), an advanced regression method from another book or later course should be applied.\n\\item[Nearly normal residuals.] Generally the residuals must be nearly normal.\nWhen this condition is found to be unreasonable, it is usually because of outliers or concerns about influential points, which we  will discuss in greater depth in Section~\\ref{typesOfOutliersInLinearRegression}. An example of non-normal residuals is shown in the second panel of Figure~\\ref{whatCanGoWrongWithLinearModel}.\n\\item[Constant variability.] The variability of points around the least squares line remains roughly constant. An example of non-constant variability is shown in the third panel of Figure~\\ref{whatCanGoWrongWithLinearModel}.\n\\item[Independent observations.] Be cautious about applying regression to data collected sequentially in what is called a \\textbf{time series}. Such data may have an underlying structure that should be considered in a model and analysis. An example of a time series where independence is violated is shown in the fourth panel of Figure~\\ref{whatCanGoWrongWithLinearModel}.\n%The observations in the data set must be independent. A common example of data that are not independent are data collected sequentially, called \\textbf{time series data}, where consecutive observations tend to be close to one another. Plotting the data in the order it was collected is often helpful for evaluating this condition.\n\\end{description}\nFor additional information on checking regression conditions, see Section~\\ref{multipleRegressionModelAssumptions}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{05/figures/whatCanGoWrongWithLinearModel/whatCanGoWrongWithLinearModel}\n\\caption{Four examples showing when the methods in this chapter are insufficient to apply to the data. In the left panel, a straight line does not fit the data. In the second panel, there are outliers; two points on the left are relatively distant from the rest of the data, and one of these points is very far away from the line. In the third panel, the variability of the data around the line increases with larger values of $x$. In the last panel, a time series data set is shown, where successive observations are highly correlated.}\n\\label{whatCanGoWrongWithLinearModel}\n\\end{figure}\n\n\\begin{example}{Should we have concerns about applying inference to the Elmhurst data in Figure~\\ref{elmhurstScatterLSRLine_conditions}?}\nThe trend appears to be linear, the data fall around the line with no obvious outliers, the variance is roughly constant. These are also not time series observations. It would be reasonable to analyze the model using inference.\n\\end{example}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.75\\textwidth]{05/figures/elmhurstPlots/elmhurstScatterLSRLine_conditions}\n\\caption{Gift aid and family income for a random sample of 50 freshman students from Elmhurst College. Two lines are fit to the data, the solid line being the \\emph{least squares line}.}\n\\label{elmhurstScatterLSRLine_conditions}\n\\end{figure}\n\n\n\n\n\\subsection{Midterm elections and unemployment}\n\n\\index{data!midterm elections|(}\n\nElections for members of the United States House of Representatives occur every two years, coinciding every four years with the U.S. Presidential election. The set of House elections occurring during the middle of a Presidential term are called \\indexthis{midterm elections}{midterm election}. In America's two-party system, one political theory suggests the higher the unemployment rate, the worse the President's party will do in the midterm elections.\n\nTo assess the validity of this claim, we can compile historical data and look for a connection. We consider every midterm election from 1898 to 2010, with the exception of those elections during the Great Depression. Figure~\\ref{unemploymentAndChangeInHouse} shows these data and the least-squares regression line: \\vspace{-2mm}\n\\begin{align*}\n&\\text{\\% change in House seats for President's party}  \\\\\n&\\qquad\\qquad= -6.71 - 1.00\\times \\text{(unemployment rate)}\n\\end{align*}\nWe consider the percent change in the number of seats of the President's party (e.g. percent change in the number of seats for Democrats in 2010) against the unemployment rate.\n\nExamining the data, there are no clear deviations from linearity, the constant variance condition, or in the normality of residuals (though we don't examine a normal probability plot here). While the data are collected sequentially, a separate analysis was used to check for any apparent correlation between successive observations; no such correlation was found.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.95\\textwidth]{05/figures/unemploymentAndChangeInHouse/unemploymentAndChangeInHouse}\n\\caption{The percent change in House seats for the President's party in each election from 1898 to 2010 plotted against the unemployment rate. The two points for the Great Depression have been removed, and a least squares regression line has been fit to the data.}\n\\label{unemploymentAndChangeInHouse}\n\\end{figure}\n\n\\begin{exercise}\nThe data for the Great Depression (1934 and 1938) were removed because the unemployment rate was 21\\% and 18\\%, respectively. Do you agree that they should be removed for this investigation? Why or why not?\\footnote{We will provide two considerations. Each of these points would have very high leverage on any least-squares regression line, and years with such high unemployment may not help us understand what would happen in other years where the unemployment is only modestly high. On the other hand, these are exceptional cases, and we would be discarding important information if we exclude them from a final analysis.}\n\\end{exercise}\n\nThere is a negative slope in the line shown in Figure~\\ref{unemploymentAndChangeInHouse}. However, this slope (and the y-intercept) are only estimates of the parameter values. We might wonder, is this convincing evidence that the ``true'' linear model has a negative slope? That is, do the data provide strong evidence that the political theory is accurate? We can frame this investigation into a two-sided statistical hypothesis test. We use a two-sided test since a statistically significant result in either direction would be interesting.\n\\begin{itemize}\n\\item[$H_0$:] $\\beta_1 = 0$. The true linear model has slope zero.\n\\item[$H_A$:] $\\beta_1 \\neq 0$. The true linear model has a slope different than zero. The higher the unemployment, the greater the loss for the President's party in the House of Representatives, or vice-versa.\n\\end{itemize}\nWe would reject $H_0$ in favor of $H_A$ if the data provide strong evidence that the true slope parameter is less than zero. To assess the hypotheses, we identify a standard error for the estimate, compute an appropriate test statistic, and identify the p-value.\n\n\n\\subsection{Understanding regression output from software}\n\\label{testStatisticForTheSlope}\n\nJust like other point estimates we have seen before, we can compute a standard error and test statistic for $b_1$. We will generally label the test statistic using a $T$, since it follows the $t$ distribution.\n\nWe will rely on statistical software to compute the standard error and leave the explanation of how this standard error is determined to a second or third statistics course. Table~\\ref{midtermElectionUnemploymentRRegressionOutput} shows software output for the least squares regression line in Figure~\\ref{unemploymentAndChangeInHouse}. The row labeled \\emph{unemp} represents the information for the slope, which is the coefficient of the unemployment variable.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{rrrrr}\n  \\hline\n  \\vspace{-3.7mm} & & & & \\\\\n & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\\\ \n  \\hline\n  \\vspace{-3.6mm} & & & & \\\\\n(Intercept) & -6.7142 & 5.4567 & -1.23 & 0.2300 \\\\ \n  unemp & -1.0010 & 0.8717 & -1.15 & 0.2617 \\\\ \n   \\hline\n   \\multicolumn{5}{r}{$df=25$} \\\\\n\\end{tabular}\n\\caption{Output from statistical software for the regression line modeling the midterm election gains and losses for the President's party as a response to unemployment.}\n\\label{midtermElectionUnemploymentRRegressionOutput}\n\\end{table}\n\n\\begin{example}{What do the first and second columns of Table~\\ref{midtermElectionUnemploymentRRegressionOutput} represent?}\nThe entries in the first column represent the least squares estimates, $b_0$ and $b_1$, and the values in the second column correspond to the standard errors of each estimate.\n\\end{example}\n\nWe previously used a $t$ test statistic for hypothesis testing in the context of numerical data. Regression is very similar. In the hypotheses we consider, the null value for the slope is 0, so we can compute the test statistic using the T (or Z) score formula:\n\\begin{align*}\nT = \\frac{\\text{estimate} - \\text{null value}}{\\text{SE}} = \\frac{-1.0010 - 0}{0.8717} = -1.15\n\\end{align*}\nWe can look for the two-tailed p-value -- shown in Figure~\\ref{oneSidedTailForMidtermUnemploymentHT} -- using the probability table for the $t$ distribution in Appendix~\\ref{tDistributionTable} on page~\\pageref{tDistributionTable}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.82\\textwidth]{05/figures/pValueMidtermUnemploymentHT/pValueMidtermUnemploymentHT}\n\\caption{The distribution shown here is the sampling distribution for $b_1$, if the null hypothesis was true. The shaded tail represents the p-value for the hypothesis test evaluating whether there is convincing evidence that higher unemployment corresponds to a greater loss of House seats for the President's party during a midterm election.}\n\\label{oneSidedTailForMidtermUnemploymentHT}\n\\end{figure}\n\n\\textA{\\pagebreak}\n\n\\begin{example}{Table~\\ref{midtermElectionUnemploymentRRegressionOutput} offers the degrees of freedom for the test statistic $T$: $df=25$. Identify the p-value for the hypothesis test.}\nLooking in the 25 degrees of freedom row in Appendix~\\ref{tDistributionTable}, we see that the absolute value of the test statistic is smaller than any value listed, which means the tail area and therefore also the p-value is larger than 0.200 (two tails!). Because the p-value is so large, we fail to reject the null hypothesis. That is, the data do not provide convincing evidence that unemployment is a good predictor of how well a president's party will do in the midterm elections for the House of Representatives.\n\\index{data!midterm elections|)}\n\\end{example}\n\nWe could have identified the $t$ test statistic from the software output in Table~\\ref{midtermElectionUnemploymentRRegressionOutput}, shown in the second row (unemp) and third column (t value). The entry in the second row and last column in Table~\\ref{midtermElectionUnemploymentRRegressionOutput} represents the p-value for the two-sided hypothesis test where the null value is zero.\n\n\\begin{termBox}{\\tBoxTitle{Inference for regression}\nWe usually rely on statistical software to identify point estimates and standard errors for parameters of a regression line. After verifying conditions hold for fitting a line, we can use the methods learned in Section~\\ref{oneSampleMeansWithTDistribution} for the $t$ distribution to create confidence intervals for regression parameters or to evaluate hypothesis tests.}\n\\end{termBox}\n\n\\begin{caution}{Don't carelessly use the p-value from regression output}{The last column in regression output often lists p-values for one particular hypothesis: a two-sided test where the null value is zero. If a hypothesis test should be one-sided or a comparison is being made to a value other than zero, be cautious about using the software output to obtain the p-value.}\n\\end{caution}\n\n\\textA{\\pagebreak}\n\n\\begin{example}{Examine Figure~\\vref{elmhurstScatterWLSROnly}, which relates the Elmhurst College aid and student family income. How sure are you that the slope is statistically significantly different from zero? That is, do you think a formal hypothesis test would reject the claim that the true slope of the line should be zero?} \\label{overallAidIncomeInformalAssessmentOfRegressionLineSlope}\nWhile the relationship between the variables is not perfect, there is an evident decreasing trend in the data. This suggests the hypothesis test will reject the null claim that the slope is zero.\n\\end{example}\n\n\\begin{exercise}\nTable~\\ref{rOutputForIncomeAidLSRLineInInferenceSection} shows statistical software output from fitting the least squares regression line shown in Figure~\\ref{elmhurstScatterWLSROnly}. Use this output to formally evaluate the following hypotheses. $H_0$: The true coefficient for family income is zero. $H_A$: The true coefficient for family income is not zero.\\footnote{We look in the second row corresponding to the family income variable. We see the point estimate of the slope of the line is -0.0431, the standard error of this estimate is 0.0108, and the $t$ test statistic is -3.98. The p-value corresponds exactly to the two-sided test we are interested in: 0.0002. The p-value is so small that we reject the null hypothesis and conclude that family income and financial aid at Elmhurst College for freshman entering in the year 2011 are negatively correlated and the true slope parameter is indeed less than 0, just as we believed in Example~\\ref{overallAidIncomeInformalAssessmentOfRegressionLineSlope}.}\n\\end{exercise}\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{rrrrr}\n  \\hline\n  \\vspace{-3.7mm} & & & & \\\\\n & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\\\ \n  \\hline\n  \\vspace{-3.6mm} & & & & \\\\\n(Intercept) & 24.3193 & 1.2915 & 18.83 & 0.0000 \\\\ \nfamily\\_\\hspace{0.3mm}income & -0.0431 & 0.0108 & -3.98 & 0.0002 \\\\ \n   \\hline\n   \\multicolumn{5}{r}{$df=48$} \\\\\n\\end{tabular}\n\\caption{Summary of least squares fit for the Elmhurst College data.\\textA{\\vspace{-5mm}}}\n\\label{rOutputForIncomeAidLSRLineInInferenceSection}\n\\end{table}\n\n\\begin{tipBox}{\\tipBoxTitle{Always check assumptions}\nIf conditions for fitting the regression line do not hold, then the methods presented here should not be applied. The standard error or distribution assumption of the point estimate -- assumed to be normal when applying the $t$ test statistic -- may not be valid.}\n\\end{tipBox}\n\n\\ANOVASection{\\subsection{An alternative test statistic}\n\nWe considered the $t$ test statistic as a way to evaluate the strength of evidence for a hypothesis test in Section~\\ref{testStatisticForTheSlope}. However, we could focus on $R^2$. Recall that $R^2$ described the proportion of variability in the response variable ($y$) explained by the explanatory variable ($x$). If this proportion is large, then this suggests a linear relationship exists between the variables. If this proportion is small, then the evidence provided by the data may not be convincing.\n\nThis concept -- considering the amount of variability in the response variable explained by the explanatory variable -- is a key component in some statistical techniques. The \\emph{analysis of variance (ANOVA)}\\index{analysis of variance (ANOVA)} technique introduced in Section~\\ref{anovaAndRegrWithCategoricalVariables} uses this general principle. The method states that if enough variability is explained away by the categories, then we would conclude the mean varied between the categories. On the other hand, we might not be convinced if only a little variability is explained. ANOVA can be further employed in advanced regression modeling to evaluate the inclusion of explanatory variables, though we leave these details to a later course.}{}\n\n\n", "meta": {"hexsha": "7ebb1bcca3793349b5713744f33c25c8c5497e7c", "size": 58759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ISRS1/Tex/05-V01.tex", "max_stars_repo_name": "amthapar/Crump_Stat", "max_stars_repo_head_hexsha": "8baa0a79d4e996c10b30d41af4d331e887bbaf1c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-09T23:52:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-09T23:52:33.000Z", "max_issues_repo_path": "ISRS1/Tex/05-V01.tex", "max_issues_repo_name": "amthapar/Crump_Stat", "max_issues_repo_head_hexsha": "8baa0a79d4e996c10b30d41af4d331e887bbaf1c", "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": "ISRS1/Tex/05-V01.tex", "max_forks_repo_name": "amthapar/Crump_Stat", "max_forks_repo_head_hexsha": "8baa0a79d4e996c10b30d41af4d331e887bbaf1c", "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": 81.158839779, "max_line_length": 1043, "alphanum_fraction": 0.7791487262, "num_tokens": 15013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6380921174581481}}
{"text": "\\section{Circuits}\n  \\subsection{Capacitants}\n  Previously we found that $E=\\frac{\\sigma}{2\\epsilon_0}+\\frac{\\sigma}{2\\epsilon_0}=\\frac{\\sigma}{\\epsilon_0}$ where $\\sigma = \\frac{Q}{A}$. Let's find potential $V$ between the plates. Recall that $v=-\\int\\vec{E}\\cdot d\\vec{s}$.\n  \\begin{align*}\n    V&=-\\int_0^d\\vec{E}\\cdot d\\vec{s}\\\\\n    \\text{for } \\vec{E}&=\\frac{\\sigma}{\\epsilon_0}\\\\\n    V&=-\\int_0^d Eds=-\\int_0^d Edx\\\\\n    &=-E\\int_0^d dx\\\\\n    V&=-Ed \\text{ This is from the pos to negative plate}\\\\\n    \\shortintertext{Equivilently from - to + plate:}\\\\\n    V&=-int_0^d \\vec{E}\\cdot d\\vec{s}\\\\\n    &=-int_0^d(-Eds)=\\int_0^d Edx\\\\\n    V&=Ed \\text{ This is from neg to pos plate}\n    \\shortintertext{Now we want to relate our two equations to a charge to find the charge within the plate.}\n  \\end{align*}\n  Consider that if there are more charges on the plates, then the potential (difference) between them will be larger. Difference is in paranthesis because we could have had a $\\Delta V$ instead of just a V if we wanted. The potential goes with the field, and the field is larger if we have more charges in it.\n  \\begin{align*}\n    Q~V\\\\\n    \\shortintertext{Let us introduce capacitance $C$ such that $Q=CV$. In magnitude, we found $V=Ed$, which gives the potential difference accross the plates. And $E=\\frac{\\sigma}{\\epsilon_0}$}\\\\\n    V&=\\frac{\\sigma}{\\epsilon_0}d=\\frac{1}{\\epsilon}\\frac{Q}{A}d\\\\\n    \\shortintertext{Using our new definition of $V=\\frac{Q}{C}$, we find:}\\\\\n    \\frac{1}{\\epsilon_0}\\frac{Q}{A}d&=\\frac{Q}{C}\\\\\n    C&=\\epsilon_0 \\frac{A}{d}\\\\\n    \\shortintertext{This is for parallel plate capacitance. This only depends on geometry. Due to the equation $Q=CV$, as soon as we know the charge on the plates we can easily determine the potential energy of the plates. $Q=CV$ is true for all capacitors.}\n  \\end{align*}\n  Let's discuss combining capacitors. For a parallel plate capacitor, we found that it's capacitance is $C=\\epsilon_0 \\frac{A}{d}$. What if we stacked plates together? What would the capacitancebe for this combined system?\n  \\begin{align*}\n    A_{new}&=A_1+A_2+A_3\\\\\n    &=\\frac{d}{\\epsilon_0}C_1+\\frac{d}{\\epsilon_0}C_2+\\frac{d}{\\epsilon_0}C_3\\\\\n    \\frac{d}{\\epsilon_0}C_{new}&=\\frac{d}{\\epsilon_0}C_1+\\frac{d}{\\epsilon_0}C_2+\\frac{d}{\\epsilon_0}C_3\\\\\n    \\shortintertext{d is the same everywhere, and $\\epsilon_0$ is a constant so they both cancel}\\\\\n    C_{new}&=C_1+C_2+C-3\\\\\n    C_{new}&= C_{parallel}\\\\\n    \\shortintertext{Capacitants increase when area is increased.}\n  \\end{align*}\n  What if instead we put capacitors one after another (in sequential order)? The area is the same, and the two middle sets of plates are going to have zero charge.\n  \\begin{align*}\n    d_{new}&=d_1+d_2+d_3\\\\\n    \\epsilon_0\\frac{A}{C_{new}}&=\\epsilon_0\\frac{A}{C_1}+\\epsilon_0\\frac{A}{C_2}+\\epsilon_0\\frac{A}{C_3}\\\\\n    \\frac{1}{C_{series}}&=\\frac{1}{C_1}+\\frac{1}{C_2}+\\frac{1}{C_3}+...\\\\\n    C_{series}&=\\left[\\frac{1}{C_1}+\\frac{1}{C_2}+\\frac{1}{C_3}+...\\right]\\\\\n  \\end{align*}\n  Capacitance let's us calculate the energy stored inside of the field between its plates. This is similar to throwing a ball from a lower surface to a hgiher one. The kinetic energy is changed into potential energy. \n  \\begin{align*}\n    \\shortintertext{Recall that $U=VQ$.}\\\\\n    \\shortintertext{Consider:}\\\\\n    dU&=VdQ\\\\\n    \\shortintertext{and $Q=CV$}\\\\\n    \\to dU&=\\frac{Q}{C}dQ\\\\\n    U&=\\frac{1}{C}\\int QdQ\\\\\n    &=\\frac{1}{C}\\frac{1}{2}Q^2\\\\\n    &=\\frac{1}{2}\\frac{1}{C}C^2V^2\\\\\n    \\alignedbox{U}{=\\frac{1}{2}CV^2}\n    \\shortintertext{Or}\\\\\n    \\alignedbox{U}{=\\frac{1}{2}\\frac{Q^2}{C}}\\\\\n    U&=\\frac{1}{2}Q^2\\frac{V}{Q}\\\\\n    \\alignedbox{U}{\\frac{1}{2}QV}\\\\\n  \\end{align*}\n  Let's discuss energy density.\n  \\begin{align*}\n    u&=\\frac{U}{volume}\\\\\n    \\shortintertext{This is always true, but for a parallel-plate capacitor, the volume is:}\n    volume&=Ad\\\\\n    \\shortintertext{Then,}\\\\\n    U&=\\frac{1}{2}CV^2\\\\\n    \\to u&=\\frac{1}{2}CV^2\\frac{1}{Ad}\\\\\n    &=\\frac{1}{2}\\left(\\epsilon_0\\frac{A}{d}\\right)V^2\\frac{1}{Ad}\\\\\n    u&=\\frac{\\epsilon_0}{2}\\frac{V^2}{d^2}\\\\\n    u&=\\frac{\\epsilon_0}{2}\\left(\\frac{V}{d}\\right)^2\\\\\n    \\shortintertext{Recall,}\\\\\n    V&=Ed\\\\\n    \\to E&=\\frac{V}{d}\\\\\n    \\shortintertext{We find}\\\\\n    \\alignedbox{u}{=\\frac{\\epsilon_0}{2}E^2}\\\\\n    \\shortintertext{Energy density relies solely on the energy field between the plates.}\\\\\n  \\end{align*}\n\n  \\subsubsection{Example 1}\n  Let's find the capacitance C of the demo capacitor. The area of the capacitor is A ($A=\\pi r^2$) for $r=6cm$. $A=\\pi 35cm^2$, also d is 2cm. We also need $\\epsilon_0$. This number is a constant. i$\\epsilon_0 = 8.85\\times10^{-12} \\frac{F}{m}$, where F stands for ferads. For parallel plates, $C=\\epsilon_0\\frac{A}{d}$. The units are ferads $(F)$.\n  \\begin{align*}\n    C&=\\left(8.85\\times10^{-12}\\frac{F}{m}\\right)\\left(\\frac{\\pi 36cm^2}{2cm}\\right)\\left(\\frac{1m}{100cm}\\right)\\\\\n    \\alignedbox{C}{=5.00\\times10^{-12}F=5pF}\\\\\n    \\shortintertext{C of the other two objects:}\\\\\n    C_{blue}&=10\\mu F=10\\times10^{-6}F=10^{-5}F\\\\\n    C_{brown}&=0.33\\mu F=0.33\\times10^{-6}F=3.3\\times10^{-7}\\\\\n  \\end{align*}\n  The capacitance of a capacitor is typically given within tolerances, not as raw numbers.\n  Let's find the electric field around the first capacitor. If there is no charge on the plates, then there is no electric field between the plates, thus the capacitor is not storing any energy. An analogy to gravity: if there is no mass for two plates you're trying to calculate gravity for, then there is no gravity between the two plates. By adding electric charge to the plates, a field is created between them in which energy is stored.\n  \\begin{align*}\n    U&=\\frac{1}{2}CV^2\\\\\n    Q&=CV\\\\\n    U&=\\frac{1}{2}QV\\\\\n    &=\\frac{1}{2}\\frac{Q^2}{C}\\\\\n    \\shortintertext{Let's put a 9V battery across our capacitor.}\\\\\n    U&=\\frac{1}{2}CV^2\\\\\n    &=\\frac{1}{2}(5\\times10^{-12}F)(9V)^2\\\\\n    U&=2.03\\times10^{-10}J\\\\\n    \\alignedbox{U}{=.203nJ}\\\\\n  \\end{align*}\n  Consider a microwave oven. Many are powered at around 1200 Watts. We run it for 2 minutes. How much energy does this use? How much time is how much energy used?\n  \\begin{align*}\n    P&=\\frac{\\Delta E}{\\Delta T}\\\\\n    \\Delta E &= P\\Delta T\\\\\n    &=\\left(1200\\frac{J}{s}\\right)(120s)\\\\\n    \\alignedbox{\\Delta E}{=144000J}\\\\\n    &=144kJ\n  \\end{align*}\n  There are some benefits for something using a low amount of power.  Let's recall that $C=5\\times10^{-5}$. Q of d would like instead $10\\times10^{-17}F$. d can combine capacitors. Consider $C=\\epsilon\\frac{A}{d}$. If you want more capacitance, you can increase the area. If you double the area you double the capacitance.\n  \\begin{align*}\n    C&=C_1+C_2\\\\\n    &=2C\\\\\n    &=10\\times10^{-12}\\\\\n  \\end{align*}\n  \\subsubsection{Example 2}\n  There is a potential across the plates such that if a charge is placed you can easily calculate the potential energy and then the kinetic energy. Let's find the capacitants of something that is not necessarily parallel plates. We still need 2 plates, but they are not going to be flat plates. We are going to calculate the capacitance of a spherical capacitor.\n  \\begin{align*}\n    Q&=CV\\\\\n    C_{parallelplates}=\\epsilon_0\\frac{A}{d}\\\\\n    \\shortintertext{The capacitance of a capacitor is always fully defined.}\\\\\n    \\shortintertext{For the spherical case, let's find C. Q is the charge on either plate, NOT BOTH. This is to prevent having zero as your Q value. The easiest way to find the voltage is by using Gauss' law to find $\\vec{E}$ to find the electric field then using that to solve for the volutage.}\\\\\n    \\vec{E}&=0 \\text{ }r<a\\\\\n    \\vec{E}&=0 \\text{ }r>b\\\\\n    \\shortintertext{For $a<r<b$:}\\\\\n    \\oint E\\cdot d\\vec{a}&=\\frac{q_{enc}}{\\epsilon_0}\\\\\n    E(4\\pi r^2)&=\\frac{Q}{\\epsilon_0}\\\\\n    \\alignedbox{\\vec{E}}{=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\hat{r}}\\\\\n    V&=-\\int\\vec{E}\\cdot d\\vec{l}\n    \\shortintertext{From $r=a$ to $r=b$}\\\\\n    V&=-\\int_a^b\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\hat{r}\\cdot d\\vec{r}\\\\\n    \\shortintertext{Potential is always path independent. The dot product enforces it in this situation. It always ends up being $E\\cdot dl$ which is in the $r$ direction. Therefore the direction does not matter but the start and endpoints do matter. Analagous to gravity where the potential energy remains the same regardless of the horizontal position of an object.}\\\\\n    &=-\\frac{1}{r\\pi\\epsilon_0}Q\\int_a^b\\frac{1}{r^2}\\hat{r}\\cdot dr\\hat{r}\\\\\n    \\shortintertext{This can be done because it is being written in it's direction vector times the magnitude. This will make the computations easier. Now we are able to find the dot product because the unit vectors are being dotted now as well.}\\\\\n    &=-\\frac{1}{4\\pi\\epsilon_0}Q\\int_a^b r^{-2}dr\\\\\n    V&=-\\frac{1}{4\\pi\\epsilon_0}Q(-r^{-1})\\Big|_{r=a}^{r=b}\\\\\n    V&=\\frac{1}{4\\pi\\epsilon_0}Q\\left(\\frac{1}{b}-\\frac{1}{a}\\right)\\\\\n    \\shortintertext{We need to ask ourselves if the sign or the units make sense for the sign. From $a\\to b$, the voltage should decrease because it's being taken away from the electric charge. V is always a scalar so our \"direction\" is correct. We can now use $Q=CV$. $Q$ is not the total charge, it is the charge on either plate.}\\\\\n    C&=\\frac{Q}{V}=\\frac{|Q|}{|V|}\\\\\n    &=\\frac{Q}{\\frac{1}{4\\pi\\epsilon_0}Q\\left(\\frac{1}{a}-\\frac{1}{b}\\right)}\\\\\n    &=4\\pi\\epsilon_0\\left(\\frac{1}{a}-\\frac{1}{b}\\right)^{-1}\\\\\n    \\alignedbox{C}{=4\\pi\\epsilon_0\\frac{ab}{b-a}}\n  \\end{align*}\n  \\subsection{Dialectics}\n  We can nicely build capacitors by placing insulators between the plates. If you can decrease the space between the capacitors, then there is a higher capacitance level. For parallel plates,\n  \\begin{align*}\n    \\vec{E_{new}}&=\\vec{E}+\\vec{E_i}\\\\\n    \\vec{E_{new}}&<\\vec{E}\\\\\n    \\vec{E_{new}}&=\\frac{1}{\\kappa}\\vec{E}\\\\\n    C&=\\kappa C_0\\\\\n  \\end{align*}\n  \\subsection{Current and Resistance}\n  Electric current is the movement of charges in time. $I=\\frac{dq}{dt}$ This means that in order to have a current, the mobile charges must be in the presence of an electric field. If you apply a force, then the charges start to move and the movement of charges is an electric current. Imagine a region with some charges and due to external charges, an external electric field affects the charges in the original region. All of the charges are going to move in the direction of the field. Because of this, the motion of the charges is messy. Also, electrons on a conductor. The electrons are all initially going to be spread out along the conductor, but if an electric field is implemented along the surface of the field, all of the charges are going to move the opposite direction of the electric field. The charges end up zigzagging along the path of the conductor.\n  \\newline\\newline\n  Charge is given in Coulombs (C). The elementary charge is $e=1.602\\times 10^{-19}C$. The unit for current is $\\frac{C}{s}$. This is also called an ampere or amp (A). \\newline\\newline Consider a copper wire being influenced by an external electric field (figure 4.9.1). $v_d$ is the drift velocity. This is the average speed of charged particles moving in a current. What about for electrons in a copper wire?\n  \\begin{align*}\n    \\shortintertext{We've said:}\n    I&=\\frac{dq}{dt}\\\\\n    \\shortintertext{Let's break it down into individual charges:}\\\\\n    I&=\\frac{d(eN)}{dt}\\\\\n    &=e\\frac{dN}{dT}\\\\\n    &=e\\frac{ndV}{dt}\\\\\n    \\shortintertext{Where $n$ is the number of electrons in a volume}\\\\\n    &=e\\frac{nAdl}{dt}\\\\\n    &=enAv_d\\\\\n    \\alignedbox{v_d}{=\\frac{I}{enA}}\\\\\n  \\end{align*}\n  For a current of 10A, consider a copper wire of radius 1mm.We know that $e=1.602\\times 10^{-19}$, and $A=\\pi r^2$ for $r=1mm$. The number density is around $10^{23}\\frac{1}{cm}\\left(\\frac{100cm}{m}\\right)^3=10^{29}\\frac{1}{m^3}$. Plugging these numbers in we will find a typical drift velocity of about $v_d \\approx 10^{-4}\\frac{m}{s}$ or $0.1\\frac{mm}{s}$. This is very slow.\\newline\\newline\n  Current dencity is: \n  \\begin{align*}\n    dI&=\\vec{J}\\cdot d\\vec{A}\\\\\n    I&=\\int\\vec{J}\\cdot d\\vec{A}\\\\\n  \\end{align*}\n  Why do I care about $\\vec{J}$ in the first place? When the electrons move in the wire, the external electric field forces them down the wire making those electrons move through a volume of the form $V=Al$. A is the crosssectional area of the wire, so current density let's us relate the movement of the electrons to the shape/geometry of the wire. $\\vec{J}$ flows through $d\\vec{A}$. The stronger the external field, the larger the current density. \n  \\begin{align*}\n    \\vec{J}&\\approx\\vec{E}\\\\\n    \\vec{J}&=\\sigma\\vec{E}\\\\\n    \\vec{J}&=\\frac{1}{\\rho}\\vec{E}\\\\\n  \\end{align*}\n  $\\sigma$ is electric conductance, and $\\rho$ is electric resistivity. Further, $\\rho=\\frac{1}{\\sigma}$. Both $\\rho$ and $\\sigma$ depend of the properties of the materials of the wire. You can think of $\\sigma$ as telling us how good of a conductor a given material is. Whereas, $\\rho$ tells us how poor of a conductor the material is.\n  \\begin{align*}\n    \\shortintertext{Figure 4.9.3}\n    \\vec{E}=\\rho\\vec{J}\\\\\n    \\shortintertext{Let's consider uniform $\\vec{E}$ considering magnitudes:}\\\\\n    E&=\\rho J\\\\\n    &=\\rho\\frac{I}{A}\n    \\shortintertext{You can do this substitution because of the following:}\\\\\n    \\int dI&=\\int\\vec{J}\\cdot d\\vec{A}\\\\\n    &=\\int JdA\\\\\n    &=J\\int dA\\\\\n    I&=JA\\\\\n    \\shortintertext{When electric charges are uniform we can calculate the voltage:}\\\\\n    V&=-\\int\\vec{E}\\cdot d\\vec{l}\\\\\n    &=-\\int Edl\\\\\n    &=-E\\int dl\\\\\n    V&=-El\\\\\n    \\shortintertext{Now substituting for E:}\n    \\frac{V}{l}&=\\rho\\frac{I}{A}\\\\\n    V&=I\\rho\\frac{l}{A}\\\\\n    \\text{Where }R&=\\rho\\frac{l}{A}\\text{ called resistance.}\\\\\n    \\shortintertext{Notice that R depends on material $\\rho$ and on geometry $\\frac{l}{A}$}\\\\\n    I=\\frac{V}{R}=\\frac{V}{\\rho}\\frac{A}{l}\\\\\n  \\end{align*}\n  Resistance depends on geometry and resistivity. Resistivity is a property of a material (intrinsic property). $R=\\rho\\frac{l}{A}$.\n  \\subsubsection{Example 1}\n  Let's find the resistivity $\\rho$ for the power resistor. We know that $R=10\\Omega$. The length of the resistor is $L=18cm$, and the area is $A=2cm\\times1cm$. Using the equation above, we can solve for $\\rho$ and find the resistance of the object.\n  \\begin{align*}\n    R&=\\rho\\frac{l}{A}\\\\\n    \\rho&=R\\frac{A}{L}\\\\\n    \\rho&=10\\Omega\\left(\\frac{2cm^2}{18cm}\\right)\\left(\\frac{1m}{100cm}\\right)\\\\\n    \\alignedbox{\\rho}{=0.0111\\Omega m}\\\\\n  \\end{align*}\n  For comparison's sake, the resistivity of silver is $\\rho_{silver}=1.59\\times10^{-8}\\Omega m$.\n  \\subsubsection{Example 2}\n  Resistors in series. There is a long resistor with another resistor right behind it ($r_1,r_2, r_3$). What is the net (equivalent) resistance? An electron goes from one resistor to the next and so on. \n  \\begin{align*}\n    R&=\\rho\\frac{L}{A}\\to L=R\\frac{A}{\\rho}\\\\\n    L_{eq}&=L_1+L_2+L_3\\\\\n    R_{eq}\\frac{A}{\\rho}&=R_{1}\\frac{A}{\\rho}+R_{2}\\frac{A}{\\rho}+R_{3}\\frac{A}{\\rho}\\\\\n    \\alignedbox{R_{eq}}{=R_1+R_2+R_3}\\\\\n  \\end{align*}\n  \\subsubsection{Example 2}\n  Resistors in parallel. If resistors are in parallel, then the charges see the resistors as one large resistor. Analogous to a river. If a river widens, then the water slows down. Adding up the areas:\n  \\begin{align*}\n    A_{eq}&=A_1+A_2+A_3\\\\\n    A&=\\rho\\frac{l}{R}\\\\\n    \\rho\\frac{L}{R_{eq}}&=\\rho\\frac{L}{R_{1}}+\\rho\\frac{L}{R_{2}}+\\rho\\frac{L}{R_{3}}\\\\\n    \\alignedbox{\\frac{1}{R_{eq}}}{=\\frac{1}{R_{1}}+\\frac{1}{R_{2}}+\\frac{1}{R_{3}}}\\\\\n  \\end{align*}\n  In series:\\newline\n  $R_{eq}=R_1+R_2+R_3$\\newline\n  $C_{eq}=\\left(\\frac{1}{C_1}+\\frac{1}{C_2}+\\frac{1}{C_3}+\\right)$\\newline\n  In parallel:\\newline\n  $R_{eq}=\\left(\\frac{1}{R_1}+\\frac{1}{R_2}+\\frac{1}{R_3}+\\right)$\\newline\n  $C_{eq}=C_1+C_2+C_3$\\newline\n  For some capacitors, if there are only two of them\n  \\begin{align*}\n    C_{eq}&=\\left(\\frac{1}{C_1}+\\frac{1}{C_2}\\right)^{-1}\\\\\n    &=\\frac{1}{\\frac{1}{C_1}+\\frac{1}{c_2}}\\\\\n    C_{eq}&=\\frac{1}{\\frac{1}{C_1}+\\frac{1}{c_2}}\\frac{C_1C_2}{C_1C_2}\\\\\n    &=\\frac{1}{C_2+C_1}\\frac{C_1C_2}{1}\\\\\n    \\alignedbox{C_{eq}}{=\\frac{C_1C_2}{C_1+C_2}}\\\\\n    \\alignedbox{R_{eq}}{=\\frac{R_1R_2}{R_1+R_2}}\\\\\n  \\end{align*}\n  Electrical Power\n  \\begin{align*}\n    P&=\\frac{dW}{dt}=\\frac{dU}{dt}\\\\\n    P&=\\frac{d(qV)}{dt}\\\\\n    \\shortintertext{For a given voltage, the power output is:}\n    P&=V\\frac{dq}{dt}\\\\\n    P&=VI\\\\\n    \\alignedbox{P}{=IV}\\\\\n    \\shortintertext{For a circuit with a resistance R,}\\\\\n    V&=IR\\\\\n    \\to P=I^2R \\text{ and } P=\\frac{V^2}{R}\\\\\n  \\end{align*}\n  Household outlets in America supply 120 Volts. In order to change the power output of an appliance, we must adjust its resistance to change the current. We want $P_{max}=I_{max}V$. We know that $V=IR$.\n  \\begin{align*}\n    I_{max}&=\\frac{V}{R_{max}}\n  \\end{align*}\n  For some resistor of resistance R, the power it outputs is $P=I^2R$. The resistor will disipate energy as heat.\n  \\subsubsection{Example 3}\n  Say a wire of diameter $d=4mm$ has a current through it, $I=6mA$. Assume a uniform current density.\n  \\begin{align*}\n    dI&=\\vec{J}\\cdot d\\vec{a}\\\\\n    \\int dI &=\\int Jda\\\\\n    I&=J\\int da\\\\\n    I&=JA\\\\\n    \\alignedbox{J}{=\\frac{I}{A}}\\\\\n    \\shortintertext{Recall,}\\\\\n    \\vec{E}&=\\sigma\\vec{J}\\\\\n    \\to V&= IR\\\\\n  \\end{align*}\n  \\subsection{Circuits and Circuit Analysis}\n  Let's start with an example and then lets discuss the physical implications of the example after\n  \\subsubsection{Example 1}\n  \\begin{figure}[!h]\n    \\centering\n    \\begin{circuitikz} \\draw\n    (0,0) to[battery=$V_0$] (0,4)\n          to[resistor=$R_0$, i>_=$I_0$] (4,4)\n          to[resistor=$R_1$, i>_=$I_0$] (4,0)\n          to[resistor=$R_2$, i>_=$I_0$] (0,0)\n    ;\n    \\end{circuitikz}\n  \\end{figure}\n  There is one current that describes this entire circuit. Let's let $V_0 = 11V$, $R_0=10k\\Omega$, $R_1=12k\\Omega$, and $R_2=35k\\Omega$. To get $I_0$ we need to know $R_eq$. These resistors are all in series with each other. Because they are all in series,we know that:\n  \\begin{align*}\n    R_{eq}&=R_0+R_1+R_2\\\\\n    &=57k\\Omega\\\\\n    \\shortintertext{Then with $V=IR$ we set:}\\\\\n    V_0&=I_0R_{eq}\\\\\n    \\alignedbox{I_0}{=\\frac{V_0}{R_{eq}}}\\\\\n    I_0&=\\frac{11V}{57k\\Omega}=0.193mA\n  \\end{align*}\n  If you start somewhere in a gravatational field, and you move something down, it has changed in its potential energy. Because electric force is conservative, a charge that travels any path and then comes back to its original location has no net change in potential energy\n  \\begin{align*}\n    \\shortintertext{For a given loop,}\\\\\n    \\sum qV_{loop}&=0\\\\\n    \\sum V_{loop}&=0\\\\\n  \\end{align*}\n  To use this, pick any starting location. Take a complete path that's called a loop and consider the change in voltage across various circuit elements. For a battery or a power supply, if you travel from the negative to the positive, you have an increase in voltage across the battery. Converse also works. For a resistor, if you are traveling \\underline{with} the current, voltage will \\underline{drop} across the resistor. \n  \\newline\\newline\n  Let's try a clockwise loop from the top left corner.\n  \\begin{align*}\n    \\sum V_{loop} &=\\\\\n    -I_0R_0-I_0R_1-I_0R_2+V_0&=0\\\\\n    V_0&=I_0(R_0+R_1+R_2)\\\\\n    V_{R_0}&=-I_0R_0=(-0.193mA)(10k\\Omega)\\\\\n    V_{R_0}&=-1.93V\\\\\n    V_{R_1}&=-2.32V\\\\\n    V_{R_2}&=-6.76V\\\\\n    \\alignedbox{\\sum V_{loop}}{=-11.0V}\\\\\n    P_{R_0}&=IV\\\\\n    IV&=0.37mW\\\\\n  \\end{align*}\n  \\subsubsection{Example 2}\n  \\begin{figure}[!h]\n    \\centering\n    \\begin{circuitikz}\n      \\draw\n      (4,4) to[battery=$I_0$] (0,4) \n            to[short, -*, i=$I_0$] (0,2)\n            node[label={[font=\\footnotesize]left:X}] {}\n            to[R=$R_1$, i>_=$I_1$] (4,2) \n            node[label={[font=\\footnotesize]right:Y}] {} -- (4,4)\n      (0,2) -- (0,0)\n            to[R=$R_2$, i>_=$I_2$] (4,0) \n            to[short, -*] (4,2)\n      ;\n    \\end{circuitikz}\n  \\end{figure}\n  \\begin{align*}\n    \\sum V_{loop}&=0\\\\\n    a&:-V_0+I_1R_1=0\\\\\n    b&:-I_1R_1+I_2R_2=0\\\\\n    \\alignedbox{\\sum I_{in}}{=\\sum I_{out}}\\\\\n    x&:I_0=I_1+I_2\\\\\n    y&:I_1+I_2=I_0\\\\\n  \\end{align*}\n  \\newline\n  There are basically two rules when it comes to circuit analysis. $\\sum V_{loop} = 0$ and $\\sum I_{in}=I_{out}$. This is essentially conservation of energy and conservation of charge. Let's consider the following circuit.\n  \\begin{figure}[!h]\n    \\centering\n    \\begin{circuitikz}\n      \\draw\n      (4,4) to[isource=$I_0$] (0,4) \n            to[short, -*, i=$I_0$] (0,2)\n            node[label={[font=\\footnotesize]left:X}] {}\n            to[R=$R_1$, i>_=$I_1$] (4,2) \n            node[label={[font=\\footnotesize]right:Y}] {} -- (4,4)\n      (0,2) -- (0,0)\n            to[R=$R_2$, i>_=$I_2$] (4,0) \n            to[short, -*] (4,2)\n      ;\n    \\end{circuitikz}\n  \\end{figure}\n  Let's let $V_0=11V$, $R_1=12k\\Omega$, and $R_2=35k\\Omega$. First let's find the current directly out of the battery.\n  \\begin{align*}\n    R_{eq}&=\\frac{R_1R_2}{R_1+R_2}=8.94k\\Omega\\\\\n    V_0&=I_0R_{eq}\\\\\n    \\alignedbox{I_0}{=\\frac{V_0}{R_{eq}}}\\\\\n    I_0&=\\frac{11V}{8.94k\\Omega}=1.23mA\\\\\n    P_0=I_0V_0&=(1.23mA)(11V)=13.5mW\\\\\n    \\shortintertext{Now let's find the current through each resistor. Let's start with going from the batter to $R_1$ and back (a). and then going from $R_2$ through $R_1$. The third loop could go from the battery to $R_2$ and back but it is not important to do so because all of the variables show up in these two equations already.}\\\\\n    \\sum V_{loop}&=0\\\\\n    a&) V_0-I_1R_1 = 0\\\\\n    b&) I_1R_1-I_1R_2 = 0\\\\\n    \\sum I_{in}&=\\sum I_{out}\\\\\n    x&)I_0=I_1+I_2\\\\\n    y&)I_1+I_2=I_0\\\\\n    \\shortintertext{We have already done the physics, and now we must solve for the things that we do not know. This is just basic algebra.}\\\\\n    \\to V_0&=I_1R_1\\\\\n    I_1&=\\frac{V_0}{R_0}\\\\\n    &=\\frac{11V}{12k\\Omega}\\\\\n    \\alignedbox{I_1}{=0.917mA}\\\\\n    \\to I_2&=I_0-I_1\\\\\n    &=1.23mA-0.917mA\\\\\n    \\alignedbox{I_2}{=0.313mA}\n    \\shortintertext{Now let's find the power of these two resistors. Remember $V=IV=I^2R=\\frac{V^2}{R}$}\\\\\n    P_1&=I_1^2R_1=(0.917mA)^2(12k\\Omega)\\\\\n    P_1&=10.1mW\\\\\n    P_2&=I_2^2R_2=(0.313mA)^2(35k\\Omega)\\\\\n    P_2&=3.43mW\\\\\n    \\shortintertext{Notice that $P_1+P_2=13.5mW$, which is the same amount of power that the batter puts out! Now let's find the voltage drops across $R_1+R_2$ from $IV$}\\\\\n    V_1&=\\frac{P_1}{I_1}=\\frac{10.1mW}{0.916mA}\\\\\n    V_1&=11.0V\\\\\n    V_2&=\\frac{P_2}{I_2}=\\frac{3.43mW}{0.313mA}\\\\\n    V_2&=11.0V\\\\\n    \\shortintertext{Notice that $V_1=V_2=V_0$. We get the same voltage across all three.}\n  \\end{align*}\n  The voltage drops across parallel segments of circuit are \\underline{equal}. $V_0$, $R_1$, and $R_2$ are all in parallel, which means they all have the same voltage. We essentially did it with the first loop but we did not. Energy is conserved, but voltage is \\underline{NOT} conservative. To determine how to combine the resistors, you \\underline{must} first determine where the charge will flow.\n  \\subsubsection{Example (Draw Later)}\n  \\begin{figure}[h!]\n    \\centering\n    \\begin{circuitikz}\n      \\draw (10,0) to[isource=$V_0$] (10,8) \n                   to[R=$R_0$](5,8) -- (0,8)\n                   to[R=$R_4$](0,4) \n                   to[R=$R_5$](0,0) -- (10,0)\n            (5,8)  to[R=$R_1$] (5,4) -- (7.5, 4) \n                   to[R=$R_3$](7.5,0)\n            (5,4) -- (2.5, 4) \n                   to[R=$R_2$](2.5, 0);\n    \\end{circuitikz}    \n  \\end{figure}\n  There is a short within this circuit, which means it flows without resistance. Even with a short, you still calculate everything the same way. Let's find the current out of the battery and the power output of $R_0$\n  \\begin{align*}\n    \\sum V_{bat} &=0\\\\\n    \\sum I_{in} &= \\sum I_{out}\\\\\n    \\shortintertext{A quick way to get $I_0$ is using $V_0=I_0R_{eq}$. Let's find $R_{eq}$}\\\\\n    R_{eq}&=R_0\\frac{R_{45}R_{123}}{R_{45}+R{123}}\\\\\n    \\text{Also, } R_{45}&=R_4+R_5\\\\\n    R_{123}&=R_1+\\frac{R_2R_3}{R_2+R_3}\\\\\n    \\alignedbox{R_{eq}}{=R_0+\\frac{\\left(R_4+R_5\\right)\\left(R_1+\\frac{R_2R_3}{R_2+R_3}\\right)}{R_4+R_5+R_1+\\frac{R_2R_3}{R_2+R_3}}}\\\\\n  \\end{align*}\n  \\subsubsection{Using measuring tools}\n  How to measure current using a digital multimeter.\\newline\\newline\n  To measure current, we must carefullt add the ammeter to the circuit. To use an ammeter you must break the circuit. So in order to add an ammeter, first be sure the circuit is \\underline{not} currently powered! Plug the hole with the ammeter and \\underline{then} turn on the power supply.\\newline\\newline\n  How to measure voltage using a DMM.\\newline\\newline\n  Set the DMM to the voltmeter. Set the DMM to be a voltage. We then add the loads across the element whose voltage drop we want to measure. We must not break the circuit or turn off the power supply to measure the voltage.\\newline\\newline\n  Ammeters go into circuits and have low internal resistance, while voltmeters go across circuit elements and have high internal resistance.\n  \\subsection{Resistors and Capacitors in Circuits}\n  \\begin{align*}\n    V_R&=IR\\\\\n    V_C=\\frac{Q}{C}\\\\\n    \\shortintertext{When the swtich is closed:}\\\\\n    V_R&=V_C=0\\\\\n    \\shortintertext{Let's throw the switch to the position (a):}.\\\\\n    \\shortintertext{There are no junctions and there is only one loop:}\\\\\n    \\sum V_{loop} = 0\\\\\n    V_0-IR-\\frac{Q}{C}&=0\\\\\n  \\end{align*}\n  How much charge acumulates on the plates? What is Q in terms of capacitance, resistance, and the battery. The amount of charge that accumulates within the circuit is a property of the circuit only, wheras battery voltage, resistance, and capacitance are functions of themselves. Using $I=\\frac{dQ}{dt}$, we get an equation that's a differential. We must get $dQ$ with $Q$ and we must get $dt$ with $t$.\n  \\begin{align*}\n    V_0-R\\frac{dQ}{dt}-\\frac{Q}{C}&=0\\\\\n    V_0-\\frac{Q}{C}&=R\\frac{dQ}{dt}\\\\\n    CV_0-Q&=RC\\frac{dQ}{dt}\\\\\n    \\frac{1}{RC}&=\\frac{1}{CV_0-Q}\\frac{dQ}{dt}\\\\\n    \\frac{dt}{RC}&=\\frac{dQ}{CV_0-Q}\\\\\n    \\int_0^t\\frac{dt}{RC}&=\\int_0^Q\\frac{dQ}{CV_0-Q}\\\\\n    \\shortintertext{Let $U=CV_0-Q$, and $du=-dQ$:}\\\\\n    \\frac{1}{RC}(t-0)&=\\int_{CV_0}^{CV_0-Q}\\frac{-du}{u}\\\\\n    \\frac{t}{RC}&=-ln\\left(\\frac{CV_0-Q}{CV_0}\\right)\\\\\n    e^{-\\frac{t}{RC}}&=\\frac{CV_0-Q}{CV_0}\\\\\n    CV_0e^{-\\frac{t}{RC}}&=CV_0-Q\\\\\n    Q&=CV_0-CV_0e^{-\\frac{t}{RC}}\\\\\n    \\alignedbox{Q(t)}{=CV_0\\left(1-e^{-\\frac{t}{RC}}\\right)}\\\\\n    \\text{Charging} &\\text{ a capacitor}\\\\\n    \\shortintertext{At $t=0$}\n    Q(0)&=CV_0\\left(1-e^{-\\frac{0}{RC}}\\right)=0\\\\\n    \\shortintertext{After a long time, $Q=CV_0$}\\\\\n    V_0&=IR-\\frac{CV_0}{C}=0\\\\\n    V_0-IR&=V_0\\\\\n    \\shortintertext{This is only true if $I=0$. If we take the dervivative of our $Q(t)$ then we can see how current depends on time:}\\\\\n    I(t)&=\\frac{d}{dt}Q(t)\\\\\n    &=CV_0\\left(0-\\frac{-1}{RC}e^{-\\frac{t}{RC}}\\right)\\\\\n    \\alignedbox{I(t)}{=\\frac{V_0}{R}e^{-\\frac{t}{RC}}}\\\\\n    \\shortintertext{Charging a capacitor. Notice that RC has dimension of time.}\n  \\end{align*}\n  \\newpage", "meta": {"hexsha": "e8e0eca7da666934d21290eb16eefda9b1c415ec", "size": 26993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics204/Sections/5Circuits.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/5Circuits.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/5Circuits.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": 58.8082788671, "max_line_length": 868, "alphanum_fraction": 0.6493164895, "num_tokens": 9845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6380921075720765}}
{"text": "% section3\r\n\\chapter {Matrices and Matrix Algebra}\r\n\r\n\\section{Operations on Matrices}\r\n\r\nNo MATLAB problems in this section.\r\n\r\n\r\n\\section{Inverses; Algebraic Properties of Matrices}\r\n\r\n\\begin{exer}\r\nIn this problem, we compute $A^{5} - 3A^{3} + 7A - 4I$ for the matrix $A$, where\r\n$$\r\nA = \\left[\\begin{array}{rrrr} 1&\\hspace{3mm} 2&\\hspace{1mm} -3&\\hspace{2mm} 0\\\\ 1 & 1 & -2 & 1 \\\\ 2 & 1 & 3 & 4 \\\\ -3 & 2 & 2 & -8 \\end{array} \\right].\r\n$$\r\n\\begin{enumerate}\r\n\r\n\\vspace{2mm}\r\n\\item[(a)]  Using the syntax $A$\\hspace{1mm}$\\hat{}$\\hspace{1mm}$k$ which produces the $k$-th power of a square matrix and the command \\textit{eye} for the identity matrix, compute the above matrix polynomial.\r\n\r\n\\vspace{1mm}\r\n\\item[(b)]  Using the command \\textit{polyvalm}, compute the above matrix polynomial.\r\n\r\n\\vspace{1mm}\r\n\\item[(c)]  Tell what happens if you type the syntax $A.$\\hspace{1mm}$\\hat{}$\\hspace{1mm}$k$.\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n% Construct the matrix A.\r\nA = [1 2 -3 0; 1 1 -2 1; 2 1 3 4; -3 2 2 -8]; \r\n\r\n% (a)\r\nresult_a = A^5 + (-3)*A^3 + 7*A + (-4)*eye(4);\r\n\r\n% Display the matrix polynomial.\r\ndisp('The result of the matrix polynomial is');\r\ndisp(result_a) \r\n\r\n% (b)\r\n% Coefficient of the matrix polynomial.\r\ncoeff_poly = [1 0 -3 0 7 -4]; \r\n\r\n% Evaluate the matrix polynomial of coefficient\r\n% with coeff_poly vector with the input matrix A.\r\nresult_b = polyvalm(coeff_poly, A);\r\n\r\n% Display the matrix polynomial.\r\ndisp('The result of the matrix polynomial is');\r\ndisp(result_b);\r\n\r\n% (c)\r\ndisp('The result of A.^2 is'); disp(A.^2);\r\ndisp('The result of A.^3 is'); disp(A.^3);\r\ndisp('The result of A.^4 is'); disp(A.^4);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe result of the matrix polynomial is\r\n         874       -1272         -39        3021\r\n        2580       -2306        -723        7536\r\n        5191       -4121       -2444       14563\r\n      -16852       12539        5649      -46917\r\n\r\nThe result of the matrix polynomial is\r\n         874       -1272         -39        3021\r\n        2580       -2306        -723        7536\r\n        5191       -4121       -2444       14563\r\n      -16852       12539        5649      -46917\r\n\r\nThe result of A.^2 is\r\n     1     4     9     0\r\n     1     1     4     1\r\n     4     1     9    16\r\n     9     4     4    64\r\n\r\nThe result of A.^3 is\r\n     1     8   -27     0\r\n     1     1    -8     1\r\n     8     1    27    64\r\n   -27     8     8  -512\r\n\r\nThe result of A.^4 is\r\n           1          16          81           0\r\n           1           1          16           1\r\n          16           1          81         256\r\n          81          16          16        4096\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\noindent From the results, we can see that the syntax $A.$\\hspace{1mm}$\\hat{}$\\hspace{1mm}$k$ produces the entrywise $k$-th powers of the matrix $A$.\r\n\r\n\\end{sol}\r\n\r\n\r\n\r\n\\section{Elementary Matrices; A Method for Finding $A^{-1}$}\r\n\r\n\r\n\r\n\\begin{exer}\r\n\r\nIn this problem, we solve the linear system $A \\mathbf{x} = \\mathbf{b}$ by using matrix inversion, where\r\n$$\r\nA = \\left[\\begin{array}{rrrr} 3 &\\hspace{2.5mm} 3 & -4 & -3 \\\\ 0 & 6 & 1 & 1\\\\ 5 & 4 & 2 & 1 \\\\ 2 & 3 & 3 & 2 \\end{array} \\right] \\hspace{2mm} \\mathrm{and} \\hspace{3mm} \\textbf{b} = \\left[\\begin{array}{r} -2 \\\\ 3 \\\\ 5 \\\\ 1 \\end{array} \\right].\r\n$$\r\n\r\n\\begin{enumerate}\r\n%8a\r\n\\item[(a)] Use the MATLAB command \\textit{inv} or the syntax $A$\\hspace{1mm}$\\hat{}$\\hspace{1mm}$(-1)$ to find the inverse of $A$.\r\n\\vspace{1mm}\r\n%8b\r\n\\item[(b)] Display the output matrix as a rational form, NOT decimally. You may use the command \\textit{format}.\r\n\\vspace{1mm}\r\n%8c\r\n\\item[(c)] Using the result of (a), compute the solution of the linear system $A \\mathbf{x} = \\mathbf{b}$ by taking $\\mathbf{x} = A^{-1} \\mathbf{b}$.\r\n\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n% Construct the matrix A and the right-hand-side vector b.\r\nA = [3 3 -4 -3; 0 6 1 1; 5 4 2 1; 2 3 3 2]; \r\nb = [-2 3 5 1]'; \r\n\r\n% (a)\r\n% Use the command inv.\r\nInv_A1 = inv(A); \r\n\r\n% Use the syntax A^(-1).\r\nInv_A2 = A^(-1); \r\n\r\n% (b)\r\nformat rat; \r\ndisp('The result of the command inv is'); disp(Inv_A1);\r\ndisp('The result of the syntax A^(-1) is'); disp(Inv_A2);\r\n\r\n% (c)\r\n% Since A is invertible, the solution to Ax=b is x=A^(-1)*b.\r\nx = Inv_A1 * b;\r\ndisp('The solution to Ax=b is x = A^(-1)*b'); disp(x');\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe result of the command inv is\r\n -7    5   12  -19\r\n  3   -2   -5    8\r\n 41  -30  -69  111\r\n-59   43   99 -159\r\n\r\nThe result of the syntax A^(-1) is\r\n -7    5   12  -19\r\n  3   -2   -5    8\r\n 41  -30  -69  111\r\n-59   43   99 -159\r\n\r\nThe solution to Ax=b is x = A^(-1)*b\r\n    70      -29     -406      583\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\r\n\r\n\\section{Subspaces and Linear Independence}\r\n\r\n\r\n\\begin{exer} (\\textit{Sigma notation})\\\\\r\nCompute the linear combination \r\n$$\\mathbf{v}=\\Sigma_{j=1}^{25} c_{j}\\mathbf{v}_{j}$$\r\nfor $c_{j}=1/j$ and $\\mathbf{v}_{j}=(\\sin j, \\cos j).$\r\n\r\n\\end{exer}\r\n\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nv=zeros(1,2);\r\nfor i=1:25\r\n    v=v+(1/i)*[sin(i), cos(i)];\r\nend\r\ndisp(v);\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\n1.0322    0.0553\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\r\n\\begin{exer} Let $\\mathbf{v_{1}}=(4, 3, 2, 1)$, $\\mathbf{v_{2}}=(5, 1, 2, 4)$, $\\mathbf{v_{3}}=(7, 1, 5, 3)$, $\\mathbf{x}=(16, 5, 9, 8)$, and $\\mathbf{y}=(3, 1, 2, 7)$. Determine whether $\\mathbf{x}$ and $\\mathbf{y}$ lie in $\\textrm{span}\\{\\mathbf{v_{1}}, \\mathbf{v_{2}}, \\mathbf{v_{3}}\\}$.\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n% Construct v1, v2, v3, x, y\r\nv1=[4 3 2 1]'; v2=[5 1 2 4]'; v3=[7 1 5 3]';\r\nx=[16 5 9 8]'; y=[3 1 2 7]';\r\n\r\n% Augmented matrices [v1|v2|v3|x] and [v1|v2|v3|y]\r\nX=[v1 v2 v3 x];\r\nY=[v1 v2 v3 y];\r\n\r\ndisp('Reduced row echelon form of [v1 v2 v3 x] is');\r\ndisp(rref(X));\r\ndisp('Reduced row echelon form of [v1 v2 v3 y] is');\r\ndisp(rref(Y));\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nReduced row echelon form of [v1 v2 v3 x] is\r\n       1              0              0              1       \r\n       0              1              0              1       \r\n       0              0              1              1       \r\n       0              0              0              0       \r\n\r\nReduced row echelon form of [v1 v2 v3 y] is\r\n       1              0              0              0       \r\n       0              1              0              0       \r\n       0              0              1              0       \r\n       0              0              0              1      \r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\noindent Therefore, $\\mathbf{x}$ lies in $\\textrm{span}\\{\\mathbf{v_{1}}, \\mathbf{v_{2}}, \\mathbf{v_{3}}\\}$ and $\\mathbf{y}$ does not lie in $\\textrm{span}\\{\\mathbf{v_{1}}, \\mathbf{v_{2}}, \\mathbf{v_{3}}\\}$. \r\n\\end{sol}\r\n\r\n\r\n%\\begin{exer} (\\textit{Linear Combinations})\\\\\r\n%Use the MATLAB command \\textit{rref} to express the vector $\\mathbf{b}=(-21, \\hspace{1mm}-60, \\hspace{1mm}-3, \\hspace{1mm}108, \\hspace{1mm}84)$ as a linear combination of $\\mathbf{v_{1}}$, $\\mathbf{v_{2}}$, and $\\mathbf{v_{3}}$ where $\\mathbf{v_{1}}=(1, \\hspace{1mm} -1, \\hspace{1mm}3, \\hspace{1mm}11, \\hspace{1mm}20)$, $\\mathbf{v_{2}}=(10, \\hspace{1mm}5, \\hspace{1mm}15, \\hspace{1mm}20, \\hspace{1mm}11)$, and $\\mathbf{v_{3}}=(3, \\hspace{1mm}3, \\hspace{1mm}4, \\hspace{1mm}4, \\hspace{1mm}9)$.\r\n%\r\n%\\end{exer}\r\n%\r\n%\r\n%\\begin{sol}\r\n%\r\n%\\begin{verbatim}\r\n%\r\n%% Construct b as a column vector.\r\n%b = [-21 -60 -3 108 84]'; \r\n%\r\n%% Set v1, v2, v3 as column vectors.\r\n%v1 = [1 -1 3 11 20]';\r\n%v2 = [10 5 15 20 11]';\r\n%v3 = [3 3 4 4 9]'; \r\n%\r\n%% Set a matrix A with column vectors v1, v2 and v3. \r\n%A = [v1 v2 v3];\r\n%\r\n%% Construct the augmented matrix [A | b].\r\n%augA = [A b]; \r\n%\r\n%% Find the reduced row echelon form of augA.\r\n%rref_augA = rref(augA); \r\n%\r\n%% Extract the solution vector from rref_augA.\r\n%x = rref_augA(1:3, 4); \r\n%\r\n%% From the result of rref_augA, we get rank(A) = rank([A | b]),\r\n%% hence, we can find each coefficient of this linear combination.\r\n%% Otherwise, we cannot find a linear combination of b as v1, v2, and v3.\r\n%\r\n%% Moreover, since rank(A) = rank([A | b]) = the number of columns of A,\r\n%% b is uniquely expressed as a linear combination of v1, v2, and v3.\r\n%\r\n%format rat % Display the result as an integer form.\r\n%disp('b is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where');\r\n%disp('x(1) ='); disp(x(1)); \r\n%disp('x(2) ='); disp(x(2));\r\n%disp('x(3) ='); disp(x(3));\r\n%\\end{verbatim}\r\n%\r\n%\r\n%\\begin{outputs}\r\n%\r\n%\\begin{verbatim}\r\n%\r\n%b is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where\r\n%x(1) =\r\n%      12\r\n%\r\n%x(2) =\r\n%       3\r\n%\r\n%x(3) =\r\n%     -21\r\n%\\end{verbatim}\r\n%\\end{outputs}\r\n%\\end{sol}\r\n\r\n\\section{The Geometry of Linear Systems}\r\n\r\n\r\nNo MATLAB problems in this section.\r\n\r\n%%% Week2\r\n\\newpage\r\n\\section{Matrices with Special Forms}\r\n\r\n\\begin{exer} (\\textit{Inverting $(I-A)$})\r\n\\begin{enumerate}\r\n%7a\r\n\\item[(a)]  (\\textit{Inverting $(I-A)$ when $A$ is nilpotent}) Using MATLAB, show that the matrix \r\n$$\r\nA = \\left[\\begin{array}{rrr} 2&\\quad 11&\\quad 3\\\\ -2 & -11 & -3\\\\ 8 & 35 & 9 \\end{array} \\right]\r\n$$\r\nis nilpotent, and then use Theorem~3.6.6 in the text book to compute $(I-A)^{-1}$. Check your answer by computing the inverse directly in MATLAB.\r\n\\vspace{1mm}\r\n\r\n\\item[(b)] (\\textit{Approximating $(I-A)^{-1}$ by a power series}) Using MATLAB, confirm that the matrix\r\n$$\r\nA = \\left[\\displaystyle\\begin{array}{rrr} 0&\\quad \\displaystyle\\frac{1}{4}&\\quad \\displaystyle\\frac{1}{8}\\\\ \\displaystyle\\frac{1}{4} & \\displaystyle\\frac{1}{8} & \\displaystyle\\frac{1}{10}\\\\ \\displaystyle\\frac{1}{8} & \\displaystyle\\frac{1}{10} & \\displaystyle\\frac{1}{10} \\end{array} \\right]\r\n$$\r\nsatisfies the condition in Theorem~3.6.7 of the text book. You may use the command \\textit{sum}. Since $A$ satisfies that condition, $(I-A)$ is invertible and can be expressed by the series in Formula~(18) in Section~3.6 of the text book. Compute the approximation $$(I-A)^{-1}\\approx I+A+A^2+A^3+\\cdots+A^{10},$$ and compare it with the inverse of $I-A$ produced directly by MATLAB. To how many decimal places do the results agree? You may use the command \\textit{format} to display the output with long digits.\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\n\\begin{enumerate}\r\n\\item[(a)]\r\n\\begin{verbatim}\r\n% (a)-i\r\nA = [ 2 11 3 ; -2 -11 -3; 8 35 9];  % Construct the matrix A.\r\n% Compute the A^2, A^3, ... , and display.\r\ndisp('A^2 is'); disp(A^2);\r\ndisp('A^3 is'); disp(A^3);\r\n\r\n% (a)-ii Comparing two result\r\n\r\n% By Theorem 3.6.6, (I-A)^(-1)=I+A+A^2.\r\nresult1=eye(3)+A+A^2;  \r\n\r\n% Compute the inverse of (I-A) directly.\r\nresult2=inv(eye(3)-A);\r\ndisp('I+A+A^2 is'); disp(result1);\r\ndisp('(I-A)^(-1) is'); disp(result2);\r\n\r\n% Display as a rational form.\r\nformat rat;\t\r\ndisp('Rational form of (I-A)^(-1) is');disp(result2);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nA^2 is\r\n     6     6     0\r\n    -6    -6     0\r\n    18    18     0\r\n\r\nA^3 is\r\n     0     0     0\r\n     0     0     0\r\n     0     0     0\r\n\r\nI+A+A^2 is\r\n     9    17     3\r\n    -8   -16    -3\r\n    26    53    10\r\n\r\n(I-A)^(-1) is\r\n    9.0000   17.0000    3.0000\r\n   -8.0000  -16.0000   -3.0000\r\n   26.0000   53.0000   10.0000\r\n\r\nRational form of (I-A)^(-1) is\r\n       9             17              3       \r\n      -8            -16             -3       \r\n      26             53             10       \r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\noindent Since $A^{3} = \\mathbf{0}$, $A$ is nilpotent. \r\nBy the Theorem $3.6.6$, since $A^{3} = \\mathbf{0}$, $I-A$ is invertible and $(I-A)^{-1} = I + A + A^{2}.$ To check answer by computing the inverse directly in MATLAB, we implement as in the next page.\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Construct the matrix A.\r\nA=[0 1/4 1/8; 1/4 1/8 1/10; 1/8 1/10 1/10]; \r\n\r\n% Check that the condition in Theorem 3.6.7 \r\n% of the text book is satisfied for matrix A.\r\ncolumn_sum=sum(abs(A),1);   % column-wise sum \r\nrow_sum=sum(abs(A),2);  % row-wise sum\r\ndisp('The sum of the absolute values of the entries in each column is');\r\ndisp(column_sum);\r\ndisp('The sum of the absolute values of the entries in each row is');\r\ndisp(row_sum);\r\n\r\nresult3=eye(size(A))+A+A^2+A^3+A^4+A^5+A^6+A^7+A^8+A^9+A^10;\r\nresult4=inv(eye(3)-A);\r\n\r\nformat long;\t% Display the result with long digits\r\ndisp('With format long');\r\ndisp('Approximated inv(I-A) is'); disp(result3);\r\ndisp('Exact inv(I-A) is'); disp(result4);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe sum of the absolute values of the entries in each column is\r\n       3/8           19/40          13/40    \r\n\r\nThe sum of the absolute values of the entries in each row is\r\n       3/8     \r\n      19/40    \r\n      13/40    \r\n\r\nWith format long\r\nApproximated inv(I-A) is\r\n   1.108587459181130   0.338615080927493   0.191581699462210\r\n   0.338615080927493   1.260966638806045   0.187122081247432\r\n   0.191581699462210   0.187122081247432   1.158500720998029\r\n\r\nExact inv(I-A) is\r\n   1.108610894508188   0.338643199287067   0.191600757491367\r\n   0.338643199287067   1.261000334187368   0.187144925921800\r\n   0.191600757491367   0.187144925921800   1.158516208087334\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\noindent The approximation result agrees with the exact result to 2 decimal places.\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\r\n\\section{Matrix Factorizations; $LU$-Decomposition}\r\n\r\n\\begin{exer}(\\textit{LU-decompositions})\r\nIn this problem, we find an $LU$-decomposition of $A$, where $A$ is given in the \\mbox{Example $2$} of the Section $3.7$.\r\n\r\n\\vspace{2mm}\r\n\\begin{enumerate}\r\n\\item[(a)] Find an $LU$-decomposition of $A$ by following the procedure given in the Example $2$.\r\n\\vspace{1mm}\r\n\\item[(b)] Solve the linear system $A \\mathbf{x} = \\mathbf{b}$ by using the $LU$-decomposition of $A$ obtained in (a), where $\\textbf{b} = \\left[\\begin{array}{r} 0 \\\\ -2 \\\\ 1 \\end{array} \\right].$\r\n\\vspace{1mm}\r\n\\item[(c)] Tell what happens if you use the MATLAB command \\textit{lu} of $A$. Explain why this result differs from the result in (a).\r\n\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n%(a)\r\nA = [6 -2 0; 9 -1 1; 3 7 5]; % Set the matrix A.\r\n\r\nformat rat; % Display results as a rational form.\r\n\r\n% Initialization of U and L.\r\nU = A; L = eye(3); \r\n\r\n% Multiply the first row by 1/6.\r\nU(1,:)=(1/6)*U(1,:); \r\n% L(1,1) is the inverse of 1/6.\r\nL(1,1)=(1/6)^(-1); \r\n\r\n% Add (-9) times the first to the second.\r\nU(2,:)=((-9)*U(1,:))+U(2,:);\r\n% L(2,1) is the negative of (-9).\r\nL(2,1)=-(-9); \r\n\r\n% Add (-3) times the first to the third.\r\nU(3,:)=((-3)*U(1,:))+U(3,:); \r\n% L(3,1) is the negative of (-3).\r\nL(3,1)=-(-3); \r\n\r\n% Multiply the second row by 1/2.\r\nU(2,:)=(1/2)*U(2,:);\r\n% L(2,2) is the inverse of 1/2.\r\nL(2,2)=(1/2)^(-1); \r\n\r\n% Add (-8) times the second to the third.\r\nU(3,:)=((-8)*U(2,:))+U(3,:); \r\n% L(3,2) is the negative of (-8).\r\nL(3,2)=-(-8); \r\n\r\ndisp('A is'); disp(A);\r\ndisp('The Lower Triangular part L is'); disp(L);\r\ndisp('The Upper Triangular part U is'); disp(U);\r\ndisp('The product L*U is'); disp(L*U);\r\n\r\n%(b)\r\n% Solve the linear system Ax=b \r\n% by using the LU-decomposition obtained in (a).\r\n\r\n% First, let us solve L*y = b by forward substitution.\r\n % Set the right-hand-side vector b.\r\nb = [0 -2 1]';\r\n\r\n % Initialization of the solution vector y.\r\ny = zeros(3, 1);\r\ny(1) = b(1) / L(1, 1);\r\ny(2) = (b(2) - (L(2, 1)*y(1))) / L(2, 2);\r\ny(3) = (b(3) - (L(3, 1)*y(1)) - (L(3, 2)*y(2))) / L(3, 3);\r\n\r\n% Next, let us solve U*x = y by backward substitution.\r\nx = zeros(3, 1); % Initialization of the solution vector x.\r\nx(3) = y(3) / U(3, 3);\r\nx(2) = (y(2) - (U(2, 3)*x(3))) / U(2, 2);\r\nx(1) = (y(1) - (U(1, 3)*x(3)) - (U(1, 2)*x(2))) / U(1, 1);\r\n\r\ndisp('The solution to Ax=b by the LU-decomposition is'); disp(x');\r\n\r\n% (c)\r\nfprintf('Using MATLAB command lu\\n');\r\n% LU decomposition of A with a permutation matrix.\r\n[L U P] = lu(A);\r\n\r\ndisp('Lower triangular part L is'); disp(L);\r\ndisp('Upper triangular part U is'); disp(U);\r\ndisp('The permutation matrix P is'); disp(P);\r\ndisp('PA='); disp(P*A); disp('LU='); disp(L*U);\r\n\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nA is\r\n       6             -2              0\r\n       9             -1              1\r\n       3              7              5\r\n\r\nThe Lower Triangular part L is\r\n       6              0              0\r\n       9              2              0\r\n       3              8              1\r\n\r\nThe Upper Triangular part U is\r\n       1             -1/3            0\r\n       0              1              1/2\r\n       0              0              1\r\n\r\nThe product L*U is\r\n       6             -2              0\r\n       9             -1              1\r\n       3              7              5\r\n\r\nThe solution to Ax=b by the LU-decomposition is\r\n     -11/6          -11/2            9\r\n\r\nUsing MATLAB command lu\r\n\r\nLower triangular part L is\r\n       1              0              0\r\n       1/3            1              0\r\n       2/3           -2/11           1\r\nUpper triangular part U is\r\n       9             -1              1\r\n       0             22/3           14/3\r\n       0              0              2/11\r\nThe permutation matrix P is\r\n       0              1              0\r\n       0              0              1\r\n       1              0              0\r\nPA=\r\n       9             -1              1\r\n       3              7              5\r\n       6             -2              0\r\nLU=\r\n       9             -1              1\r\n       3              7              5\r\n       6             -2              0\r\n\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\\noindent Since the permutation matrix $P$ is not the identity matrix, the MATLAB command \\textit{lu} gave us an $LU$-decomposition after multiplying $A$ by the permutation matrix $P$, hence, this decomposition is a $PLU$-decomposition of $A$ because $PA=LU$. Since at least one row interchange of $A$ occurred in the process of $LU$-decomposition, this result is different from the previous decomposition obtained in $(a)$.\r\n\r\n\\end{sol}\r\n\r\n\r\n\\vspace{3mm}\r\n\\begin{exer} (\\textit{LU-decomposition})\r\n\\begin{enumerate}\r\n\\item[(a)] The MATLAB command \\textit{lu} is used to find the $LU$-decomposition of a matrix $A$. Tell what happens if you use the command $lu$ for $A$, where $A$ is given in the Example 2 of the Section 3.7. Explain why this result differs from the result in the textbook.\r\n\\vspace{1mm}\r\n\\item[(b)] Using MATLAB, observe what happens when you try to find an $LU$-decomposition of a singular matrix.\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n% (a)\r\n% Construct the matrix A.\r\nA=[6 -2 0; 9 -1 1; 3 7 5]; \r\n\r\n% LU decomposition of A.\r\n[L U P]=lu(A); \r\ndisp('[L U P]=lu(A)');\r\ndisp('L'); disp(L); disp('U'); disp(U); disp('P'); disp(P);\r\n\r\n% (b)\r\n% Construct the some singular matrices.\r\nA1=[1 0 0; -2 0 0; 4 6 1]; \r\nA2=[1 -2 7; -4 8 5; 2 -4 3];\r\nA3=[1 0 0; -2 0 0; 4 6 1]; \r\n\r\n% LU decompositions of them.\r\n[L1 U1 P1]=lu(A1); [L2 U2 P2]=lu(A2); [L3 U3 P3]=lu(A3); \r\ndisp('[L1 U1 P1]=lu(A1)'); disp('L1');disp(L1);disp('U1');disp(U1);\r\ndisp('[L2 U2 P2]=lu(A2)'); disp('L2');disp(L2); disp('U2');disp(U2);\r\ndisp('[L3 U3 P3]=lu(A3)'); disp('L3');disp(L3); disp('U3');disp(U3);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\n[L U P]=lu(A)\r\nL\r\n    1.0000         0         0\r\n    0.3333    1.0000         0\r\n    0.6667   -0.1818    1.0000\r\n\r\nU\r\n    9.0000   -1.0000    1.0000\r\n         0    7.3333    4.6667\r\n         0         0    0.1818\r\n\r\nP\r\n     0     1     0\r\n     0     0     1\r\n     1     0     0\r\n\r\n\r\n[L1 U1 P1]=lu(A1)\r\nL1\r\n    1.0000         0         0\r\n   -0.5000    1.0000         0\r\n    0.2500   -0.5000    1.0000\r\nU1\r\n    4.0000    6.0000    1.0000\r\n         0    3.0000    0.5000\r\n         0         0         0\r\n         \r\n[L2 U2 P2]=lu(A2)\r\nL2\r\n    1.0000         0         0\r\n   -0.2500    1.0000         0\r\n   -0.5000         0    1.0000\r\nU2\r\n   -4.0000    8.0000    5.0000\r\n         0         0    8.2500\r\n         0         0    5.5000\r\n         \r\n[L3 U3 P3]=lu(A3)\r\nL3\r\n    1.0000         0         0\r\n   -0.5000    1.0000         0\r\n    0.2500   -0.5000    1.0000\r\nU3\r\n    4.0000    6.0000    1.0000\r\n         0    3.0000    0.5000\r\n         0         0         0\r\n         \r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\noindent \\textit{Remark on (a).} Since the permutation matrix $P$ is not the identity matrix, the MATLAB command \\textit{lu} gave us an $LU$-decomposition after multiplying $A$ by the permutation matrix $P$, hence, this decomposition is a $PLU$-decomposition of $A$ because $PA=LU$. Since at least one row interchange of $A$ occurred in the process of $LU$-decomposition, this result is different from the decomposition result in the textbook.\r\n\r\n\\vspace{2mm}\r\n\\noindent \\textit{Remark on (b).} When we try $LU$-decomposition of the sigular matrices using the MATLAB command \\textit{lu}, the resulting upper triangular matrices are singular.\r\n\r\n\\end{sol}", "meta": {"hexsha": "983c54ac603ab403bc5a3784ddf5adf6eecea95b", "size": 20934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section3.tex", "max_stars_repo_name": "mireiffe/mas109_matlab_2021_2", "max_stars_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section3.tex", "max_issues_repo_name": "mireiffe/mas109_matlab_2021_2", "max_issues_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-19T08:29:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T08:29:55.000Z", "max_forks_repo_path": "files/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section3.tex", "max_forks_repo_name": "mireiffe/mas109_matlab_2021_2", "max_forks_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_forks_repo_licenses": ["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.1559888579, "max_line_length": 513, "alphanum_fraction": 0.5418935703, "num_tokens": 7519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6380518839333109}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{graphicx}\n\\usepackage{multicol}\n\\usepackage[top=0.8in, bottom=0.8in, left=0.8in, right=0.8in]{geometry}\n% add other packages here\n\\usepackage[font=small,labelfont=bf]{caption} % Required for specifying captions to tables and figures\n\n\n% put your group number and names in the author field\n\\title{\\bf Exercise 2: A Reactive Agent for the Pickup and Delivery Problem}\n\\author{Group \\textnumero 70: Jelena Banjac, Stratos Triantafyllou}\n\n% the report should not be longer than 3 pages\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Problem Representation}\n\n\\subsection{Representation Description}\n% describe how you design the state representation, the possible actions, the reward table and the probability transition table\n\nOur implementation assumes as state a route from an origin city to a destination city. The next city the vehicle will visit next is modeled as an action. If a vehicle on a route is carrying out a delivery task, no destination city is defined - implemented with the method \\texttt{hasTask()}.\n\nThis flag is used in the creation of the reward table. If the vehicle is carrying out a delivery task next, then the added reward R(s, a) is computed based on the income for the delivery from the destination city in s to the next city as defined in the action a, subtracting the distance between these two cities. If the vehicle is just moving to the next city without delivering a task, we just subtract the distance between the cities.\n\nTo compute transition probabilities, if the vehicle is carrying out a delivery task, we use the probability that the agent moves between the origin and the destination city. If the vehicle is just moving to a neighbor city, each neighbor has the same probability and the transition is random.\n\n\n\\subsection{Implementation Details}\n% describe the implementation details of the representations above and the implementation details of the reinforcement learning algorithm you implemented\nImplementation of the state is in the \\texttt{state.RouteState} with parameters \\texttt{fromCity} and \\texttt{toCity}. The initialization of all the states is done in the method \\texttt{initializeStates}. In total we have ${N}^2$ states. \nThe action is implemented in the class \\texttt{action.RouteAction} with parameter \\texttt{neighborCity}. The method \\texttt{initializeActions} is initializing all the actions. In total we have N actions.\nBefore Reinforcement Learning Algorithm (RLA), we fill in the Reward table - \\texttt{R(s,a)}. Reward is calculated differently depending whther the agent has a tas or not. We also initialize Q-table - \\texttt{Q(s,a)} together with the vector with state values and corresponding action to take in that state - \\texttt{V}. When Q table is initialized, it does not use all the combinations of state and action. The constraints are: the agent cannot stay in the same city and if there is no delivery, the action needs to be a neighbor city.\nThese tables are all located in the \\texttt{tables.Tables}.\nWe compute this vector in method \\texttt{rla()} by value iteration. This value improves with each iteration, and our stopping criteria is until the difference between two successive iteration is smaller than $\\epsilon$=0.001.\n\n\n\\section{Results}\n% in this section, you describe several results from the experiments with your reactive agent\nIn this section, we will describe several results from the experiments with our reactive agent.\n\n\\subsection{Experiment 1: Discount factor}\n% the purpose of this experiment is to understand how the discount factor influences the result\nIn the first experiment, we want to understand how discount factor $\\gamma$ influences the results. The discount factor represents how much we discount the future, i.e. how much an agent is taking care of rewards from the future states. If the $\\gamma$=0, it means that we discard the future totally. Whereas, the higher the value of $\\gamma$, the higher the effect of the future on the value of state value V(S). \n\n\\subsubsection{Setting}\n% you describe how you perform the experiment (you also need to specify the configuration used for the experiment)\nThis experiment was performed with the following settings:\n(1) discount factor for our reactive agent: $\\gamma$ $\\epsilon$ [0.15, 0.50, 0.85, 0.95, 0.99]; (2) cost per km for all vehicles is 5 CHF; (3) capacity of all the vehicles is 30 KG; (4) speed of all the vehicles vehicle is 220 KM/H; (5) topology is Switzerland.\n\n\n\\subsubsection{Observations}\n% you describe the experimental results and the conclusions you inferred from these results\nNumber of iterations of RLA algorithm until good enough is: [6, 9, 11, 9, 7] for the discount factors $\\gamma$ $\\epsilon$ [0.99, 0.95, 0.95, 0.85, 0.50, 0.15], respectively. We run several times (3 times) in order to get a confidence intervals of total profits and reward per kilometer results. Using this information we can find the best value of $\\gamma$. \n\n\n\\begin{multicols}{2}\n\\includegraphics[scale=0.2]{ex1-rpk-full.png}\n\\captionof{figure}{Reward per kilometer - full image}\n\n\\includegraphics[scale=0.2]{ex1-rpk-zoomed.png}\n\\captionof{figure}{Reward per kilometer - zoomed}\n\\end{multicols}\n\n\\begin{multicols}{2}\n\\includegraphics[scale=0.2]{ex1-tp-full.png}\n\\captionof{figure}{Total profit - full image}\n\n\\includegraphics[scale=0.2]{ex1-tp-zoomed.png}\n\\captionof{figure}{Total profit - zoomed}\n\\end{multicols}\n\nFrom the images above, we can see that with our settings the agent that performs the best is the one with the discount factor $\\gamma$ = 0.85. It means that it takes into an account the future pretty highly.\n\n\\subsection{Experiment 2: Comparisons with dummy agents}\n% you compare the results of your agent with two dummy agents: the random agent that was already given in the starter files and another dummy agent that you define and create. You should report the results from the simulations using the topologies given in the starter files and optionally, additional topologies that you create.\nIn this experiment, we compare the results of our agent with two dummy agents: the random agent in the starter files and another dummy agent that has $\\gamma$=0. We perform this experiment on different typologies.\n\n\\subsubsection{Setting}\n% you describe how you perform the experiment and you describe the dummy agent you created (you also need to specify the configuration used for the experiment)\nThe first dummy agent is a random agent does not implement the Reinforcement Learning Algorithm (RLA) and chooses the next path to move randomly. The second dummy agent is the agent that discards the effect of the future states, therefore, it acts only to maximize an immediate reward. The third agent is our final agent that performs the best.\nAdditional settings we have are: (1) cost per km for all vehicles is 5 CHF; (2) capacity of all the vehicles is 30 KG; (3) speed of all the vehicles vehicle is 220 KM/H\n\n\n\\subsubsection{Observations}\n% elaborate on the observed results\n\n\\begin{multicols}{2}\n\\includegraphics[scale=0.18]{ex2-rpk-full.png}\n\\captionof{figure}{Switzerland topology - Reward per kilometer (full image)}\n\n\\includegraphics[scale=0.18]{ex2-rpk-zoomed.png}\n\\captionof{figure}{Switzerland - Reward per kilometer (zoomed)}\n\\end{multicols}\n\n\\begin{multicols}{2}\n\\includegraphics[scale=0.19]{ex2-tp-full.png}\n\\captionof{figure}{Switzerland - Total profit (full image)}\n\n\\includegraphics[scale=0.19]{ex2-tp-zoomed.png}\n\\captionof{figure}{Switzerland - Total profit (zoomed)}\n\\end{multicols}\nFrom the images of the performance of agents in Swiss topology, we can see that random agent (green) performs worse than the ones that implement the RLA, see Fig.5, Fig.6, Fig.7, and Fig.8. Even the agent that is using the discount factor $\\gamma$=0 is performing better than the random one (which is expected since it is maximizing an immediate reward and does not go randomly). The agent which we think was the best was the one with $\\gamma$=0.85 (blue). \n\n\\begin{multicols}{2}\n\\includegraphics[scale=0.19]{fr1.png}\n\\captionof{figure}{France - Total profit (zoomed)}\n\n\\includegraphics[scale=0.19]{fr2.png}\n\\captionof{figure}{France - Reward per kilometer (full)}\n\\end{multicols}\nHowever, when we ran the agents in a different topology (France), we got that the random one still performs the worse, however, the agent with $\\gamma$=0.95 performs better than the one with $\\gamma$=0.85. And the agent that gets the immediate reward has performance with the result in between these agents, see Fig.9 and Fig.10. We did the same for the topology of England. The discount factor that performs the best there was $\\gamma$=0.5. More information can be found in the notebooks.\n\n\\end{document}", "meta": {"hexsha": "5d2e99e6a06068e45c041fdfc882b05d6080790a", "size": 8738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-reactive/banjac-triantafyllou-ex2/doc/banjac-triantafyllou-ex2.tex", "max_stars_repo_name": "JelenaBanjac/intelligent-agents", "max_stars_repo_head_hexsha": "c6a7f412c9c60b50a1f312d1ceab71cbe654a5bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-14T13:32:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-14T13:32:26.000Z", "max_issues_repo_path": "2-reactive/banjac-triantafyllou-ex2/doc/banjac-triantafyllou-ex2.tex", "max_issues_repo_name": "JelenaBanjac/intelligent-agents", "max_issues_repo_head_hexsha": "c6a7f412c9c60b50a1f312d1ceab71cbe654a5bc", "max_issues_repo_licenses": ["MIT"], "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-reactive/banjac-triantafyllou-ex2/doc/banjac-triantafyllou-ex2.tex", "max_forks_repo_name": "JelenaBanjac/intelligent-agents", "max_forks_repo_head_hexsha": "c6a7f412c9c60b50a1f312d1ceab71cbe654a5bc", "max_forks_repo_licenses": ["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.4285714286, "max_line_length": 536, "alphanum_fraction": 0.7823300526, "num_tokens": 2110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6380518827959273}}
{"text": "\\RequirePackage[l2tabu, orthodox]{nag}\n\\documentclass[landscape, letterpaper, 8pt]{extarticle}\n\n\\usepackage[margin=.25in]{geometry}\n\\usepackage{fontspec}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{multicol}\n\\usepackage{enumitem}\n\\usepackage{scrextend}\n\n%\\setmainfont{Lato}\n%\\linespread{0.2}\n\n\\renewcommand{\\complement}[1]{{#1}^\\mathsf{c}}\n\\DeclarePairedDelimiter{\\floor}{\\lfloor}{\\rfloor}\n\n\\begin{document}\n\\begin{multicols}{3}\n    \\section*{Logic Properties}\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item \\textbf{Generalization: } $p~\\therefore p \\lor q$ and $q~\\therefore p \\lor q$\n        \\item \\textbf{Specialization: } $p \\land q~\\therefore p$ or $q$\n        \\item \\textbf{Conjunction: } $p,~q~\\therefore p \\land q$\n        \\item \\textbf{Eliminiation: } $p \\lor q,~\\neg q~\\therefore p$\n        \\item \\textbf{Division into Cases: } $p \\lor q,~p\\implies r,~q\\implies r~\\therefore r$\n        \\item \\textbf{Contradiction Rule: } $\\neg p \\implies c~\\therefore p$\n    \\end{itemize}\n    \\subsection*{Implies}\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item \\textbf{Statement: } $p \\implies q$\n        \\item \\textbf{Converse: } $q \\implies p$\n        \\item \\textbf{Inverse: } $\\neg p \\implies \\neg q$\n        \\item \\textbf{Contrapositive: } $\\neg q \\implies \\neg p$\n    \\end{itemize}\n    \\subsection*{Quantified}\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item \\textbf{Universal Instantiation: } $\\forall x,~P(x)~\\therefore P(a)$ also applies to $\\exists$.\n        \\item \\textbf{Universal Generalization: }$P(a)~\\therefore \\forall x,~P(x)$ also applies to $\\exists$.\n        \\item \\textbf{Negation: }$\\neg(\\forall x, Q(X)) \\equiv \\exists x, \\neg Q(x)$ and $\\neg(\\exists x, Q(X)) \\equiv \\forall x, \\neg Q(x)$.\n        \\item \\textbf{Universal Modus Ponens: } $\\forall x, P(x)\\implies Q(x),~P(a)~\\therefore Q(a)$ does not apply to $\\exists$.\n        \\item \\textbf{Universal Modus Tolens: } $\\forall x, P(x)\\implies Q(x),~\\neg Q(a) \\therefore \\neg P(a)$ does not apply to $\\exists$.\n        \\item \\textbf{Converse Error: }$ \\begin{aligned}\n                                 & \\forall x, P(x) \\implies Q(x) \\\\\n                                 & Q(a)                          \\\\\n                      \\therefore & P(a)\n                  \\end{aligned}$\n        \\item \\textbf{Inverse Error: } $\\begin{aligned}\n                                 & \\forall x, P(x) \\implies Q(x) \\\\\n                                 & \\neg P(a)                     \\\\\n                      \\therefore & Q(a)\n                  \\end{aligned}$\n\n    \\end{itemize}\n    \\section*{Induction}\n    \\subsection*{Strong Induction}\n    \\textbf{Let} $P(n)$ be the property to be proven, let $a$ and $b$ be fixed integers where $a\\leq b$.\n\n    Suppose the following:\n    \\begin{enumerate}[noitemsep,nolistsep]\n        \\item \\textbf{Basis:} $P(a), P(a+1), \\ldots P(b)$ are true.\n        \\item \\textbf{Induction:} For all integers $k\\geq b$, if $P(i)$ is true for all integers from $a$ to $k$ then $P(k+1)$ is true.\n        \\item Hence for all integers $n\\geq a, P(n)$ is true.\n    \\end{enumerate}\n    \\section*{Number Theory}\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item \\textbf{Even} $n$ is even $\\iff \\exists k, n = 2k$.\n        \\item \\textbf{Odd} $n$ is odd $\\iff \\exists k, n = 2k+1$.\n        \\item \\textbf{Prime} $n$ is prime $\\iff \\forall r, s$, if $n = rs$ then $r=1$ and $s = n$ or vice versa.\n        \\item \\textbf{Composite} $n$ is composite $\\iff \\exists r, s$, if $n = rs$ and $1 < r < s$ and $1 < s < n$.\n        \\item \\textbf{Rational} $r$ is rational $\\iff \\exists a, b$ such that $r = \\frac{a}{b}$ and $b \\neq 0$.\n        \\item \\textbf{Divisible} $d|n \\iff \\exists k$ such that $n=dk$.\n    \\end{itemize}\n    \\section*{Sets}\n    Can be proven by using Induction, Algebra or Element method.\n\n    Element Method: Usually with equality or subset relations: prove that an element in LHS is an element in RHS.\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item Proper Subset: $A \\subseteq B$ \\textbf{AND} there is one element in B that is \\textbf{not} in A\n        \\item Power Set: $\\wp(\\{x, y, z\\}) = \\{\\emptyset, \\{x\\}, \\{y\\}, \\{z\\},\\\\\n                  \\{x, y\\},\\{x, z\\}, \\{y, z\\}, \\{x, y, z\\}$\n        \\item Disjoint set:$A\\cap B = \\varnothing$\n    \\end{itemize}\n    \\subsection*{Identities}\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item Commutative Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup B = B \\cup A $ and $A \\cap B = B \\cap A$\n              \\end{itemize}\n        \\item Associative Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $(A \\cup B) \\cup C = A \\cup (B \\cup C)$ and $(A \\cap B) \\cap C = A \\cap (B \\cap C)$\n              \\end{itemize}\n        \\item Distributive Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)$\n                  \\item $A \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C)$\n              \\end{itemize}\n        \\item Identity Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup \\varnothing = A$ and $A \\cap U$\n              \\end{itemize}\n        \\item Idempotent Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup A = A$ and $A\\cap A = A$\n              \\end{itemize}\n        \\item Universal Bound Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup U = U$ and $A  \\cap \\varnothing = \\varnothing$\n              \\end{itemize}\n        \\item DeMorgan's Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $\\complement{(A \\cup B)} = \\complement{A} \\cap \\complement{B}$ and $\\complement{(A \\cap B)} = \\complement{A} \\cup \\complement{B}$\n              \\end{itemize}\n        \\item Absorption Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A \\cup (A \\cap B) = A$ and $A \\cap (A \\cup B) = A$\n              \\end{itemize}\n        \\item Set Difference Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A-B = A \\cap \\complement{B}$\n              \\end{itemize}\n        \\item Complement Law\n              \\begin{itemize}[noitemsep,nolistsep]\n                  \\item $A\\cup \\complement{A} = U$ and $A \\cap \\complement{A} = \\varnothing$\n              \\end{itemize}\n    \\end{itemize}\n    \\section*{Functions}\n    A function $f$ from a set $X$ to a set $Y$ denoted by $f: X \\to Y$ where $X$ is the domain and $Y$ is the co-domain.\n    Every element in $X$ relates to some element in $Y$ and each element in $X$ must map to at most one element in $Y$.\n    \\subsection*{One-to-One functions}\n    $\\forall x_1, x_2 \\in X[(F(x_1) = F(x_2)) \\implies (x_1 = x_2)]$\n    \\subsection*{Onto functions}\n    $\\forall y \\in Y[ \\exists x \\in X \\text{ where } F(x)=y]$\n    \\subsection*{Inverse functions}\n    $F^{-1}(y) = x\\text{ where }F(x) = y$.\n    $F(x)$ has to be bijective (both one-to-one and onto).\n    \\section*{Relations}\n    A partition of set $A$ is a collection of nonempty, mutually disjoint subsets whose union is $A$, i.e. $A_1 \\cup A_2 \\cup A_3 \\cup \\ldots \\cup A_i = A$\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item Reflexive $\\forall x \\in A[(x, x) \\in \\mathbb{R}]$\n        \\item Symmetric $\\forall x, y \\in A[(x, y) \\in \\mathbb{R} \\implies (y, x) \\in \\mathbb{R}]$\n        \\item Transitive $\\forall x, y, z \\in A[(x R y \\land y R z)\\implies x R z]$\n        \\item Partition-induced relation: $\\forall x, y \\in A[x R y \\iff (x, y) \\in \\text{single partition }A_i]$\n        \\item Equivalence Relation: When a relation is relation is reflexive, symmetric and transitive.\n        \\item Identity Relation: $I_A = \\{(x, y) \\in A \\times A~|~x=y\\}$\n    \\end{itemize}\n    \\subsection*{Equivalence Classes}\n    The subset of all elements that are related to $a$.\n\n    Suppose $A$ is a set and $R$ is an equivalence relation on $A$. For each element $a$ in $A$, the \\textbf{equivalence class of $a$}, $[a]$ or \\textbf{class of $a$} is the set of all elements $x$ in $A$ such that $x$ is related to $a$ by $R$. \\[[a] = \\{x \\in A~|~x~R~a\\}\\]\n    \\section*{Partial Order Relations}\n    A relation that is reflexive, antisymmetric and transitive.\n    \\subsection*{Antisymmetry}\n    A relation is antisymmetric if $x R y \\land y R x,~x = y$\n    A relation is \\textbf{not} antisymmetric if $x R y \\land y R x\\text{ but }x \\neq y$\n    \\section*{Counting}\n    $P(E)$ is \\[P(E) = |E|/|S|\\] where S is the set of possible outcomes and E is the set of events.\n\n    Number of elements: $|{n, n+1, n+2, \\ldots, m}| = m - n + 1$\n    \\subsection*{Permutations and Combinations}\n    Number of possible arrangements of n units: $n!$\n    \\begin{itemize}[noitemsep,nolistsep]\n        \\item With $n_1$ duplicates: $\\frac{n!}{n_1!}$\n        \\item With $m$ units in certain order: $(n-(m-1))!$\n        \\item In a circle/rotation: $\\frac{n!}{n}$ (Let 1 be fixed, arrange the rest.)\n    \\end{itemize}\n\n    $P(n, r) = \\frac{n!}{(n-r)!}$\n\n    $C(n, r) = \\binom{n}{r} = \\frac{P(n, r)}{r!}$\n\n    Number of Combinations with repetitions allowed: $\\binom{r+n-1}{r}$\n\n    $\\binom{n}{r} = \\binom{n}{n-r}$\n\n    Pascal's Formula: $\\binom{n+1}{r} = \\binom{n}{r-1}+ \\binom{n}{r}$\n\n    Binomial Theorem:\\begin{align*}\n        (a+b)^n & = \\sum_{k=0}^n\\binom{n}{k} a^{n-k}b^k                                  \\\\\n                & = a^n + \\binom{n}{1} a^{n-1} b^1                                       \\\\\n                & + \\binom{n}{2} a^{n-2} b^2 + \\ldots + \\binom{n}{n-1} a^1 b^{n-1} + b^n \\\\\n    \\end{align*}\n    \\subsection*{Pigeonhole Principle}\n    If $n$ pigeons fly into $m$ pigeonholes, and $n > km$ for some $k \\in \\mathbb{Z}^+$ then at least one pigeonhole contains k+1 or more pigeons.\n\n    Generalized: \\[k = \\floor*{\\frac{n}{m}}\\]\n\n    \"The maximum value has at least the average value, for any non-empty finite bag of real numbers\" -Prof. Djikstra\n    \\section*{Examples}\n    \\newtheorem{example}{Example}\n    \\subsection*{Strong Induction}\n    \\begin{example}\n        \\begin{equation*}\n            \\begin{aligned}\n                f(n) = \\begin{cases}\n                    1                   & \\text{if }n=1      \\\\\n                    3                   & \\text{if }n=2      \\\\\n                    f(n-1) + 2f(n-2) +3 & \\text{if } n\\geq 3\n                \\end{cases}\n            \\end{aligned}\n        \\end{equation*}\n        Using mathematical induction, prove that for all $n \\geq 3: f(n) \\geq 2^n$\n\n        Answer:\n        \\begin{equation*}\n            \\begin{aligned}\n                f(k+1) =f(k)+ 2f(k-1)+3              \\\\\n                \\text{Use fact that $f(n) \\geq 2^n$} \\\\\n                f(k+1) \\geq 2^k+2\\cdot 2^{k-1} +3    \\\\\n                \\text{and } f(k+1) \\geq 2^k + 2^k +3 = 2^{k+1} + 3 \\geq 2^{k+1}\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n    \\subsection*{Weak Induction}\n    \\begin{example}\n        What is the smallest value of k such that any integer postage of k, or\n        more, cents can be formed by using only 3-cent and 8-cent stamps?\n\n        Use mathematical induction to prove that all integer postages of k, or more, cents can be\n        obtained.\n        \\begin{equation*}\n            \\begin{aligned}\n                \\textbf{Basis: } P(n):                             & n = 3a + 8b       \\\\\n                \\textbf{Induction: } P(n+1):                       & n+1 = 3a' + 8b'   \\\\\n                \\textbf{Case 1: } \\text{if } b \\geq 1, n = 3a + 8b & \\text{, so}       \\\\\n                n+1 = 3a+1+8b                                      & = 8(b-1) + 9 + 3a \\\\\n                n+1                                                & = 8(b-1) +3(a+3)  \\\\\n                \\textbf{Hence }a' = a+3      \\text{ and }          & b' = b - 1        \\\\\n                \\textbf{Case 2: } \\text{if } b = 0, n = 3a         &                   \\\\\n                \\text{Since }n \\geq 14,~a \\geq 5                                       \\\\\n                n+1 = 1 + 15 + 3(l-5)                              & = 16+ 3(l-5)      \\\\\n                \\textbf{Hence }a' = l-5      \\text{ and }          & b' = 2            \\\\\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n    \\begin{example}\n        Recall that the $n$'th Harmonic number, $H_n$, is defined as:\n        \\[\n            H_n = 1+ \\frac{1}{2} + \\frac{1}{3} + \\ldots + \\frac{1}{n}\n        \\]\n        Use mathematical induction to prove that for all positive integers $n$:\n        \\[\n            H_1 + H_2 + \\ldots + H_n = (n+1)H_n -n\n        \\]\n        Answer:\n        \\begin{equation*}\n            \\begin{aligned}\n                \\textbf{Basis: } P(n): & H_1 + H_2 + \\ldots + H_n = (n+1) H_n-n \\\\\n                P(1):                  & H_1 = 1 = 2H_1 -1                      \\\\\n            \\end{aligned}\n        \\end{equation*}\n        \\begin{equation*}\n            \\begin{aligned}\n                \\textbf{Induction: } & H_1 + \\ldots + H_k + H_{k+1} = (k+1)H_k - k + H_{k+1}                  \\\\\n                \\text{Using IH for k}                                                                         \\\\\n                =                    & (k+1)(1+\\frac{1}{2}+\\ldots+\\frac{1}{k})-k  +(1+\\ldots + \\frac{1}{k+1}) \\\\\n                =                    & \\ldots                                                                 \\\\\n                % Rest of the fucking owl\n                =                    & (k+2) (1+\\frac{1}{2} + \\ldots + \\frac{1}{k+1}) - (k+1)\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n    \\subsection*{Functions}\n    Let $f: X \\mapsto Y$ and $g: Y \\mapsto Z$ be functions. Indicate whether each statement below is true or false. Give a proof for each true statement and a counterexample for each false statement.\n\n    \\textbf{a) If $g \\circ f$ is onto then $f$ is onto.}\n\n    \\textbf{Answer: } False.\n\n    $X = {1, 2}, Y = {1, 2, 3}, Z = {1, 2}, f(1) = 1, f(2) = 2, g(1) = 1, g(2) = 2, g(3) = 2$\n\n    \\textbf{b) If $g \\circ f$ is onto then $g$ is onto.}\n\n    \\textbf{Answer: } True.\n\n    Let $z \\in Z$. There exists $x \\in X$ such that $g(f(x)) = z$ since $g \\circ f$ is onto. So $g(y) = z$ for $y = f(x)$. Therefore $g$ is onto.\n\n    \\textbf{c) If $g \\circ f$ is one-to-one then $f$ is one-to-one.}\n\n    \\textbf{Answer: } True.\n\n    Let $x_1, x_2 \\in X$ such that $f(x_1) = f(x_2)$.\n    \n    Then $g(f(x_1)) = g(f(x_2))$. Now $g(f(x_1)) = g(f(x_2))$ by definition of composition. Therefore $x_1 = x_2$ since $g \\circ f$ is one-to-one. This implies $f$ is one-to-one.\n\n    \\textbf{d) If $g \\circ f$ is one-to-one then $g$ is one-to-one.}\n\n    \\textbf{Answer: } False.\n\n    Use part (a).\n\n    \\subsection*{Counting}\n    \\begin{example}\n        How many three-digit integers are divisible by 5?\n        \\begin{equation*}\n            \\begin{aligned}\n                \\text{Three-digit integers} = {100, 101, \\ldots, 999}                                         \\\\\n                \\left\\lfloor \\frac{100}{5} \\right\\rfloor = 20, \\left\\lfloor \\frac{999}{5} \\right\\rfloor = 199 \\\\\n                \\text{by number of elements theorem: } 199-20 + 1 = 180\n            \\end{aligned}\n        \\end{equation*}\n    \\end{example}\n    \\begin{example}\n        Consider a robot moving in an $m \\times n$ grid, where $m\\leq n$. It starts at the coordinate $(1,1)$. At each step, when it is at position $(i,j)$, it either moves one square up to $(i+1, j)$ or one square right to $(i, j+1)$. How many ways can the robot travel from $(1,1)$ to $(m,n)$? Justify your answer.\n\n        Answer:\n        \\begin{align*}\n            m - 1 \\text{ possible steps up.}               \\\\\n            n - 1 \\text{ possible steps right.}            \\\\\n            (m - 1) + (n - 1) \\text{ total steps.}         \\\\\n            \\text{Each step up and right are the same, so} \\\\\n            \\frac{(m+n - 2)!}{(m-1)!(n-1)!}                \\\\\n        \\end{align*}\n    \\end{example}\n    \\subsection*{Direct proofs}\n    \\begin{example}\n        $6-7\\sqrt{2}$ is irrational.\n        \\begin{align*}\n            \\text{Assume } 6-7\\sqrt{2} = \\frac{p}{q} \\text{ where } p, q \\in \\mathbb{Z} \\land q \\not = 0. \\\\\n            \\sqrt{2} = \\frac{\\left(\\frac{p}{q}-6\\right)}{-7} = \\frac{p-6q}{-7q}                           \\\\\n        \\end{align*}\n        This is rational as both the numerator and denominator are products and differences of integers and thus are integers, and the denominator is not equal to zero.\n    \\end{example}\n    \\subsection*{Pigeonhole Princple}\n    \\begin{example}\n        For every 27 word sequence in a paragraph, at least two words will start with the same letter.\n\n        \\textbf{Reason: } There are 27 words that can start with the 26 different English letters. By the pigeonhole principle, two of the words must start with the same letter.\n    \\end{example}\n    \\begin{example}\n        If a theatre holds 1300 people, how many seats need to be filled to ensure that two people have the same first and last initials?\n\n        \\textbf{Answer: } 26 letters in English language, Fname.Lname = 1 letter on each initial. $26 * 26$ means at least 1 person as each combination of initials. $26 * 26 +1$ ensures at least 1 duplicate.\n    \\end{example}\n    \\begin{example}\n        Let ABC be an equilateral triangle with AB = 1. Show that by selecting 10 points, there are at least two with distance $\\leq \\frac{1}{3}$ apart.\n\n        \\textbf{Answer: } If you split up the triangle by $\\frac{1}{3}$ lengths, you will create 9 slots. The 10th will be in the same triangle as another, which is less than $\\frac{1}{3}$.\n    \\end{example}\n    \\begin{example}\n        Prove with the pigeonhole principle that having 100 whole numbers, one can choose 15 of them so that the difference of any 2 is divisible by 7?\n\n        \\textbf{Answer: } Use the generalized pigeonhole principle.\n\n        Let $S: \\{1\\ldots100\\}.~S' = S \\mod 7 = \\{1 \\mod 7 \\ldots 100 \\mod 7\\}$\n\n        Partition $S'$ into $7$ subsets of equal size where each subset has same value for $S \\mod 7$.\n\n        By generalized PHP, where $\\lfloor \\frac{units}{holes}\\rfloor$ units in each hole, there are at least $\\lfloor \\frac{100}{7} \\rfloor = 14$ remainders in each subset of $S'$.\n\n        $14 * 7 = 98$ which is $2$ less than $100$. We can place those $2$ with the other subsets that contain the same number, increasing the number to at least 15 for one or more of the subsets.\n\n    \\end{example}\n\\end{multicols}\n\\end{document}\n", "meta": {"hexsha": "acfb31550d0b959153c4cf4e7245f7e5541cb68a", "size": 18393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/CMPUT272.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": "Notes/CMPUT272.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": "Notes/CMPUT272.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": 51.5210084034, "max_line_length": 316, "alphanum_fraction": 0.5323220791, "num_tokens": 5947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.6379307370818696}}
{"text": "\\section{$I$-invariance of $\\Bun_G$, and $G$-CW-complexes}\nLet $G$ be a topological group. We need to show that the functor\n$\\Bun_G:\\Top^{op}\\to\\Set$ is $I$-invariant, i.e., the projection\n$X\\times I\\xrightarrow{\\pr}X$ induces an isomorphism\n$\\Bun_G(X)\\xrightarrow{\\simeq}\\Bun_G(X\\times I)$.\nInjectivity is easy: the composite $X\\xrightarrow{\\inc_0} X\\times\nI\\xrightarrow{\\pr}X$ gives you a splitting\n$\\Bun_G(X)\\xrightarrow{\\pr_\\ast}\\Bun_G(X\\times I)\\xrightarrow{\\inc_0}\\Bun_G(X)$\nwhose composite is the identity.\n\nThe rest of this lecture is devoted to proving surjectivity. We will prove this\nwhen $X$ is a CW-complex (Husemoller does the general case; see \\cite[\\S\n4.9]{husemoller}). We begin with a small digression.\n%Consider two principal $G$-bundles $P\\to X$ and $Q\\to Y$, with a map $f:X\\to\n%Y$. We would like to understand maps $P\\to f^\\ast Q$ over $X$, i.e.,\n%$G$-equivariant dotted maps that make the following diagram commute.\n%\\begin{equation*}\n%    \\xymatrix{\n%\tP\\ar@{-->}[r]^g\\ar[d] & Q\\ar[d]\\\\\n%\tX\\ar[r]_f & Y\n%    }\n%\\end{equation*}\n%Suppose I have $P\\to X\\times I$; then we get $in_0^\\ast P\\to X$. This has to\n%be what you get when you ---. All we have to do is construct a map $P\\to\n%in_0^\\ast P$ like in the diagram above.\n\\subsection{$G$-CW-complexes}\nWe would like to define CW-complexes with an action of the group $G$. The\nna\\\"ive definition (of a space with an action of the group $G$) will not be\nsufficient; rather, we will require that each cell have an action of $G$.\n\nIn other words, we will build $G$-CW-complexes out of ``$G$-cells''. This is\nsupposed to be something of the form $D^n\\times H\\backslash G$, where $H$ is a\nclosed subgroup of $G$. Here, the space $H\\backslash G$ is the orbit space,\nviewed as a right $G$-space. The boundary of the $G$-cell $D^n\\times\nH\\backslash G$ is just $\\partial D^n\\times H\\backslash G$. More precisely:\n\\begin{definition}\n    A $G$-CW-complex is a (right) $G$-space $X$ with a filtration\n    $0=X_{-1}\\subseteq X_0\\subseteq \\cdots\\subseteq X$ such that for all $n$,\n    there exists a pushout square:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\coprod\\partial D^n_\\alpha\\times H_\\alpha\\backslash G\\ar[r]\\ar[d] &\n\t    \\coprod D^n_\\alpha\\times H_\\alpha\\backslash G\\ar[d]\\\\\n\t    X_{n-1}\\ar[r] & X_n,\n\t    }\n    \\end{equation*}\n    and $X$ has the direct limit topology.\n\\end{definition}\nNotice that a CW-complex is a $G$-CW-complex for the trivial group $G$.\n\\begin{theorem}\n    If $G$ is a compact Lie group and $M$ a compact smooth $G$-manifold, then\n    $M$ admits a $G$-CW-structure.\n\\end{theorem}\nThis is the analogue of the classical result that a compact smooth manifold is\nhomotopy equivalent to a CW-complex, but it is much harder to prove the\nequivariant statement.\n\nNote that if $G$ acts principally (Definition \\ref{principaldefn}) on $P$, then\nevery $G$-CW-structure on $P$ is ``free'', i.e., $H_\\alpha = 0$.\n\\begin{enumerate}\n    \\item If $X$ is a $G$-CW-complex, then $X/G$ inherits a CW-structure whose\n\t$n$-skeleton is given by $(X/G)_n = X_n/G$.\n    \\item If $P\\to X$ is a principal $G$-bundle, then a CW-structure on $X$\n\tlifts to a $G$-CW-structure on $P$.\n\\end{enumerate}\n\\subsection{Proof of $I$-invariance}\nRecall that our goal is to prove that every $G$-bundle over $X\\times I$ is\npulled back from some vector bundle over $X$.\n\nAs a baby case of Theorem \\ref{Iinvariance} we will prove that if\n$X$ is contractible, then any principal $G$-bundle over $X$ is trivial, i.e.,\n$P\\simeq X\\times G$ as $G$-bundles.\n\nLet us first prove the following: if $P\\downarrow X$ has a section, then it's\ntrivial. Indeed, suppose we have a section $s:X\\to P$. Since $P$ has an action\nof the group on it, we may extend this to a map $X\\times G\\to P$ by sending\n$(x,g)\\mapsto gs(x)$. As this is a map of $G$-bundles over $X$, it is an\nisomorphism by Theorem \\ref{morphismiso}, as desired.\n\nTo prove the statement about triviality of any principal $G$-bundle over a\ncontractible space, it therefore suffices to construct a section for any\nprincipal $G$-bundle. Consider the constant map $X\\to P$. Then the following\ndiagram commutes up to homotopy, and hence (by Exercise\n\\ref{sectionuptohomotopy}(1)) there is an \\emph{actual} section of $P\\to X$, as\ndesired.\n\\begin{equation*}\n    \\xymatrix{\n\t& P\\ar[d]\\\\\n\tX\\ar[ur]^{\\mathrm{const}}\\ar[r] & X\n    }\n\\end{equation*}\nFor the general case, we will assume $X$ is a CW-complex. For notational\nconvenience, let us write $Y=X\\times I$. We will use descending induction to\nconstruct the desired principal $G$-bundle over $X$.\n\nTo do this, we will filter $Y$ by subcomplexes. Let $Y_0 = X\\times 0$; in\ngeneral, we define\n$$Y_n = X\\times 0\\cup X_{n-1}\\times I.$$\nIt follows that we may construct $Y_n$ out of $Y_{n-1}$ via a pushout:\n\\begin{equation*}\n    \\xymatrix{\n\t\\coprod_{\\alpha\\in\\Sigma_{n-1}}(\\partial D^{n-1}\\times I \\cup\n\tD^{n-1}_\\alpha\\times 0) \\ar[r]\\ar[d]_{\\coprod_{\\alpha\\in\\Sigma_{n-1}}\n\tf_\\alpha\\times 1_I\\cup\\phi_\\alpha\\times 0} &\n\t\\coprod_\\alpha(D^{n-1}_\\alpha\\times I) \\ar[d]\\\\\n\tY_{n-1}\\ar[r] & Y_n,\n    }\n\\end{equation*}\nwhere the maps $f_\\alpha$ and $\\phi_\\alpha$ are defined as:\n\\begin{equation*}\n    \\xymatrix{\n\t\\partial D^{n-1}_\\alpha\\ar[r]^{f_\\alpha}\\ar[d] & X_{n-2}\\ar[d]\\\\\n\tD^{n-1}_\\alpha\\ar[r]_{\\phi_\\alpha} & X_{n-1}\n    }\n\\end{equation*}\nIn other words, the $f_\\alpha$ are the attaching maps and the $\\phi_\\alpha$ are\nthe characteristic maps.\n\nConsider a principal $G$-bundle $P\\xrightarrow{p}Y = X\\times I$. Define $P_n =\np^{-1}(Y_n)$; then we can build $P_n$ from $P_{n-1}$ in a similar way:\n\\begin{equation*}\n    \\xymatrix{\n\t\\coprod_\\alpha(\\partial D^{n-1}_\\alpha\\times I\\cup D^{n-1}_\\alpha\\times\n\t0)\\times G\\ar[r]\\ar[d] & \\coprod_\\alpha (D^{n-1}_\\alpha\\times I)\\times\n\tG\\ar[d]\\\\\n\tP_{n-1}\\ar[r] & P_n\n    }\n\\end{equation*}\n%This makes sense since $D^n_\\alpha\\times I$ is a contractible space, and same\n%thing for the other factor.\nNote that this isn't \\emph{quite} a $G$-CW-structure. Recall that we are\nattempting to fill in a dotted map:\n\\begin{equation*}\n    \\xymatrix{\n\tP\\ar@{-->}[r]\\ar[d] & P_0\\ar[d]\\\\\n\tY\\ar[r]_{\\pr} & Y_0 = X\n    }\n\\end{equation*}\n\\todo{finish this...}\nI'm constructing this inductively-- we have $P_{n-1}\\to P_0$. So I want to define $\\coprod_\\alpha(D^{n-1}_\\alpha\\times I)\\times G\\to P_0$ that's equivariant. That's the same thing as a map $\\coprod_\\alpha (D^{n-1}_\\alpha\\times I)\\to P_0$ that's compatible with the map from $\\coprod(\\partial D^{n-1}_\\alpha\\times I\\cup D^{n-1}_\\alpha\\times 0)$. Namely, I want to fill in:\n\\begin{equation}\\label{finally}\n    \\xymatrix{\n\t\\coprod_\\alpha (\\partial D^{n-1}_\\alpha\\times I\\cup D^{n-1}_\\alpha\\times 0)\\ar[r]\\ar[d] & \\coprod_\\alpha(D^{n-1}_\\alpha\\times I)\\ar@{-->}[dddr]\\ar[d] & \\\\\n\t\\coprod_\\alpha(\\partial D^{n-1}_\\alpha\\times I\\cup D^{n-1}_\\alpha\\times 0)\\times G\\ar[r]\\ar[d] & \\coprod_\\alpha (D^{n-1}_\\alpha\\times I)\\times G\\ar@{-->}[ddr]\\ar[d] & \\\\\n\tP_{n-1}\\ar[drr]_{\\mathrm{induction}}\\ar[r] & P_n\\ar[dr] & \\\\\n\t& & P_0\\ar[d]\\\\\n\t& & X\n    }\n\\end{equation}\nNow, I know that $(D^{n-1}\\times I,\\partial D^{n-1}\\times I\\cup D^{n-1}\\times 0)\\simeq (D^{n-1}\\times I,D^{n-1}\\times 0)$. So what I have is:\n\\begin{equation*}\n    \\xymatrix{\n\tD^{n-1}\\times 0\\ar[d]\\ar[r]^{\\mathrm{induction}} & P_0\\ar[d]\\\\\n\tD^{n-1}\\times I\\ar[r]_{\\phi\\circ pr}\\ar@{-->}[ur] & X\n    }\n\\end{equation*}\nSo the dotted map exists, since $P_0\\to X$ is a fibration!\n\nOK, so note that I haven't checked that the outer diagram in Equation \\ref{finally} commutes, because otherwise we wouldn't get $P_n\\to P_0$.\n\\begin{exercise}\n    Check my question above.\n    \n    Turns out this is easy, because you have a factorization:\n\\begin{equation*}\n    \\xymatrix{\n\tD^{n-1}\\times 0\\ar[d]\\ar[r] & P_{n-1}\\ar[r]^{\\mathrm{induction}} & P_0\\ar[d]\\\\\n\tD^{n-1}\\times I\\ar[rr]_{\\phi\\circ pr}\\ar@{-->}[urr] & & X\n    }\n\\end{equation*}\n\\end{exercise}\nOh my god, look what time it is! Oh well, at least we got the proof done.\n", "meta": {"hexsha": "c40c8006b477e4d2dfa7078195a8f383226d38d7", "size": 7884, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-54-I-invariance.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-54-I-invariance.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-54-I-invariance.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": 45.8372093023, "max_line_length": 371, "alphanum_fraction": 0.6752917301, "num_tokens": 2859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6379307355782785}}
{"text": "\\section{Chain Adjacency and Incidence}\n\\label{chain-adjacencies-and-incidensies}\n%=========================================\n\nBoundary decompositions (B-reps) are the typical representations used in solid modeling and computer graphcs. The model boundary is partitioned into vertices (\\texttt{V}: 0-cells), edges (\\texttt{E}: 1-cells), and faces (\\texttt{F}: 2-cells), where faces are often triangles or more general convex cells. \n\n\\subsection{Boundary representation of solid models}\n\\label{boundary-representation-of-solid-models}\n%--------------------------------------------------\n\n\nIn particular, a typical solid modeling representation employs some specialized data structure to efficiently traverse the boundary, moving from some element to the adjacent ones (with same dimension) or to incident ones (with different dimension). Several data structures have been used for this purpose~\\cite{HofShapiro:2017}, taking into account both the efficiency of topological queries and the storage compactness. Three binary adjacency relations and six binary incidence relations can be needed by algorithms, as shown in Table~\\ref{tab:relations}a.\n\nUsing chain operators, or better their matrices, when an ordering of elements has been fixed inside the sets \\texttt{V}, \\texttt{E}, and \\texttt{F} using one-dimensional arrays, such binary relations can be represented and/or computed as shown in Table~\\ref{tab:relations}b. It is easy to show (see Table~\\ref{tab:relations}b), that all linear operators between chain spaces corresponding to binary relations between boundary elements can  be derived from $\\partial_1$ and $\\partial_2$ via matrix transposition or product over semirings~\\cite{DBLP:journals/corr/KepnerABBFGHKLM16,GraphBLAS:API:2017}.\n\n\\begin{table}[htp]\n\\caption{(a) The 9 binary relations between boundary elements, and the 16 binary relations between decompositive elements; (b) corresponding linear operators between chain spaces. Remember that $\\partial_p: C_p\\to C_{p-1}$ and that $\\delta_p = \\partial_{p+1}^\\top$. }\n\\begin{center}\n\\begin{tabular}{|c|ccc|c|}\n\\hline\n &\\texttt{V} & \\texttt{E} & \\texttt{F} & \\texttt{C} \\\\ \n\\hline\n\\texttt{V} &\\texttt{VV} & \\texttt{VE} & \\texttt{VF} & \\texttt{VC} \\\\ \n\\texttt{E} &\\texttt{EV} & \\texttt{EE} & \\texttt{EF} & \\texttt{EC} \\\\ \n\\texttt{F} &\\texttt{FV} & \\texttt{FE} & \\texttt{FF} & \\texttt{FC} \\\\ \n\\hline\n\\texttt{C} &\\texttt{CV} & \\texttt{CE} & \\texttt{CF} & \\texttt{CC} \\\\ \n\\hline\n\\end{tabular}\n$\\qquad$\n\\begin{tabular}{|c|ccc|c|}\n\\hline\n &\\texttt{$C_0$} & \\texttt{$C_1$} & \\texttt{$C_2$} & \\texttt{$C_3$} \\\\ \n\\hline\n\\texttt{$C_0$} & $[\\partial_1][\\delta_0]$ & $[\\partial_1]$ & $[\\partial_1][\\partial_2]$ & $[\\partial_1][\\partial_2][\\partial_3]$\\\\ \n\\texttt{$C_1$} & $[\\delta_0]$  & $[\\delta_0][\\partial_1]$ & $[\\partial_2]$ & $[\\partial_2][\\partial_3]$ \\\\ \n\\texttt{$C_2$} & $[\\delta_1][\\delta_0]$ & $[\\delta_1]$ & $[\\delta_1][\\partial_2]$ & $[\\partial_3]$ \\\\ \n\\hline\n\\texttt{$C_3$} & $[\\delta_2][\\delta_1][\\delta_0]$ & $[\\delta_2][\\delta_1]$ & $[\\delta_2]$ & $[\\delta_2][\\partial_3]$ \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\\label{tab:relations}\n\\end{table}%\n\n\nNote that we have assumed vectors as column matrices, so that an operator maps the column space to the row space of its matrix. Hence, in order to maintain the consistency between the two representations  we should read the relation $\\texttt{AB} \\subset \\texttt{A}\\times \\texttt{B}$ as a map $\\texttt{AB}: \\texttt{B} \\to \\texttt{A}$.\n\n\n\\subsection{Space Decompositions}\\label{space-decompositions}\n%-------------------------------------------------------------\nA similar representation scheme---called \\emph{decompositive} in~\\cite{Requicha:1980:RRS:356827.356833}---is also  used, both in solid modeling and in order to represent the domain decomposition in FEM and other discretizations of physical models. In this case a partition of the whole domain is provided, using cellular 3-complexes, given by \\texttt{V}, \\texttt{E}, \\texttt{F}, and \\texttt{C} sets of $0$-, 1-, 2- and 3-cells, where often the \\texttt{C} elements  are either tetrahedra or hexahedra.  \n\nFor the topology of a graph (cellular 1-complex) just $C_0$ (vertices) and $C_1$ (edges) are needed, so that a complete representation is given by the signed or unsigned matrix $[\\partial_1]$, corresponding to the relation $\\texttt{EV} \\equiv C_1\\to C_0$.\n\nIt is worth noting that operators $\\partial_1$, $\\partial_2$, and $\\partial_3$ are sufficient to represent the complete collection of $4\\times 4$ operators (see Table~\\ref{tab:relations}b), via matrix transposition or product over semirings. In other words, the \\emph{chain complex} $C_\\bullet = (C_p, \\partial_p)$ of boundary matrices, $1\\leq p\\leq 1,2,3$ is a \\emph{complete representation} of the topology of (a) graphs, (b) B-reps, and (c) decompositive representations, respectively. \n\nCellular complexes may be either \\emph{oriented} (signed) or \\emph{non-oriented} (unsigned). In the first case the elements of operator matrices are taken over the domain $D=\\{0,1\\}$; in the second case they belong to the domain $D=\\{-1,0,1\\}$, so that passing from a coefficient $+1$ to a coefficient $-1$ (or viceversa) the element orientation is reversed.\n\n\n\\subsection{Minimal representations}\\label{minimal-reps}\n\nMost of earlier algorithms and procedures~\\cite{\n4055948,\nAla:1992:PAB:616022.617736,\nBaumgart:1972:WEP:891970,\nbowyer1995introducing,\nbowyer1995svlis,\nBraid:1975:SSB:360715.360727,\nBrisson:1989:RGS:73833.73858,\ncadanda,\nDobkin:1987:PMT:41958.41967,\nGomes:1999:MMB:304012.304039,\nGuibas:1985:PMG:282918.282923,\nHoffmannK01,\nKalay:1989:HET:63718.63719,\nLee:2001:PES:376957.376976,\nLienhardt:1991:TMB:115604.115610,\nMantyla:1988:ISM:60949,\nPaoluzzi:1989:BAO:70248.70249,\nPaoluzzi:1993:DMS:169728.169719,\nPaoluzzi:1995:GPP:212332.212349,\nPascucci:1995:DCB:218013.218055,\nPratt94ashape,\nRaghothama:1999:CUD:304012.304019,\nRap97,\nRequichaVoelcker:77,\nRossignac:1991:CNG:115604.115606,\nRossignac:SGC:90,\nShapiro:1991:RSS:124951,\nShapiro:1995:PFS:218013.218029,\nSilva:81,\nWeiler:86,\nWeiler:88,\nWoo:85,\nwozny1990geometric,\nYamaguchi:85,\nyamaguchi1995ntb,\nZhou:2016:MAS:2897824.2925901,\nbieri:95,\nRossignac:89,\nHoffmann:91,\nHoffmann:1989:GSM:74803,\nHoffmann:1987:RSO:866286} \nwork with data\nstructures optimized for selected classes of geometric\nobjects. By contrast, our formulation, representation, and algorithms, cast in\nterms of (co)chain complexes of (co)boundary maps, may be\napplied to very different geometric objects, ranging from solid models\nto engineering meshes, geographical systems, biomedical images.\n\nGiven a set $S=\\{s_j\\}$, the \\emph{characteristic function} $\\chi_A: S\\to\\{0,1\\}$ takes value 1 for all elements of $A\\subseteq S$ and 0 at all elements of $S$ not in $A$. \nWe call \\emph{characteristic matrix} $M$ of a collection of subsets $A_i\\subseteq S$ ($i=1,\\ldots,n$) the binary  matrix $M=(m_{ij})$, with $m_{ij} = \\chi_{A_i}(s_j)$. {A  matrix $M_p$, whose rows are indexed by unit $p$-chains and columns are indexed by unit $0$-chains, provides a useful representation of a basis for the linear space $C_p$. Permuting (reindexing) either rows or columns provides a different basis.}   While chains are mostly presented as formal sums of cells, in the actual implementation their signed coordinate vectors are used as \\emph{sparse} arrays, and in particular as CSC (Compressed Sparse Column) maps : $\\N\\to\\{-1,0,1\\}$.\n\nIt is possible to show~\\cite{} that, when the $d$-cells are convex, the topology of a cellular $d$-complex is fully described by $M_{d-1}$ and by an embedding function $\\mu: \\texttt{V}\\to \\E^d$. When $d$-cells are more complex---say, non-convex or with holes---the triple $(M_{d-1}, M_{d-2}, \\mu)$ is needed to get a full knowledge of the topology of the complex.\n\nWe call \\texttt{LAR} (Linear Algebraic Representation) of subsets of a set \\texttt{V} (vertices), the array, indexed by ordinals (one-to-one with subsets), of arrays of indices to \\texttt{V} elements. This one is a compact representation of the \\emph{characteristic matrix} of the collection of subsets.\n\n\n", "meta": {"hexsha": "ce95741419e85a4b24a33a28109a62c766675058", "size": 8060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/incidence.tex", "max_stars_repo_name": "cvdlab/Chain-BLAS", "max_stars_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_stars_repo_licenses": ["MIT"], "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/incidence.tex", "max_issues_repo_name": "cvdlab/Chain-BLAS", "max_issues_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_issues_repo_licenses": ["MIT"], "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/incidence.tex", "max_forks_repo_name": "cvdlab/Chain-BLAS", "max_forks_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_forks_repo_licenses": ["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.1666666667, "max_line_length": 652, "alphanum_fraction": 0.7305210918, "num_tokens": 2546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6378781197916169}}
{"text": "\\chapter{Graphing Polynomials}\n\nIn using polynomials to solve real-world problems, it is often handy\nto know what the graph of the polynomial looks like. You have many of\nthe tools you need to start to sketch out the the graphs:\n\\begin{itemize}\n\\item To find where the graph crosses the y-axis, you can evaluate the polynomial at $x = 0$.\n\\item To find where the graph crosses the x-axis, you can find the roots of the polynomial.\n\\item To find the level spots on the graph (often the top of a hump or the bottom of a dip), you can take the derivative of the polynomial (which is a polynomial), and find the roots of that.\n\\end{itemize}\\index{polynomial!graphing}\n\n\\textit{FIXME: Diagram of those things}\n\nFor example, if you wanted to graph the polynomial $f(x) = -x^3 -x^2 +\n6x$, you might plug in a few values that are easy to compute:\n\\begin{itemize}\n\\item $f(-2) = -8$\n\\item $f(-1) = -6$\n\\item $f(0) = 0$\n\\item $f(1) = 4$\n\\item $f(2) = 0$ \n\\end{itemize}\n\nSo, right away we know two roots: $x = 0$ and $x = 2$. Are there\nothers? We won't know until we factor the polynomial:\n\\begin{multline*}\n  -x^3 -x^2 + 6x \\\\\n  = (-1x)(x^2 + x - 6) \\\\\n  = (-1x)(x + 3)(x - 2)\n\\end{multline*}\nSo, yes, there is a third root: $x = -3$\n\nWhat about the level spots? $f'(x) = -3x^2 - 2x + 6$. Where is that zero?\n\\begin{multline*}\n  -3x^2 -2x + 6 = 0 \\\\\n  x^2 + \\frac{2}{3}x - 2 = 0\n\\end{multline*}\nWe have a formula for quadratics like this:\n\\begin{multline*}\n  x = -\\frac{b}{2} \\pm \\frac{\\sqrt{b^2 - 4c}}{2} \\\\\n  = -\\frac{\\frac{2}{3}}{2} \\pm \\frac{\\sqrt{\\left(\\frac{2}{3}\\right)^2 - 4(-2)}}{2} \\\\\n  = -\\frac{1}{3} \\pm \\frac{\\sqrt{\\frac{4}{9} + 8}}{2} \\\\\n  = -\\frac{1}{3} \\pm \\frac{\\sqrt{\\frac{85}{9}}}{2} \\\\\n  = -\\frac{1}{3} \\pm \\frac{\\sqrt{85}}{6} \\\\\n  \\approx 1.20 \\text{ and } -1.87 \n\\end{multline*}\n\nNow you might plug those numbers in:\n\\begin{itemize}\n\\item $f(1.2) \\approx 4.0 $\n\\item $f(-1.87) \\approx -8.2$\n\\end{itemize}\n\n\\section{Leading term in graphing}\n\nThere is one more trick you need before you can draw a good graph of a\npolynomial. As you go father and farther to the left and right, where\ndoes the function go?  That is, does the graph go up on both ends\n(like a smile)? Or does it go down on both ends (like a frown)? Or\ndoes the negative end go down (frowny) while the positive end go up\n(smiley)? Or does the negative go up (smiley) and the positive end go\ndown (frowny)?\n\nAssuming the polynomial is not constant, there are only those four\npossibilties. It is determined entirely by the leading term of the\npolynomial.  If the degree of the leading term is even, both ends go\nin the same direction (both are smiley or both are frowny).  If the\ncoefficient of the leading term is positive, the positive end is\nsmiley.\n\nThe graph we are working on has a leading term of $-1x^3$. The degree is odd, thus the ends go in different directions. The coefficient is negative, so the positive end points down.  Now you can draw the graph, which should look something like this:\n\n\\includegraphics[width=\\textwidth]{annotated_graph.png}\n", "meta": {"hexsha": "0cc850046c06972883ca3ac458e16f64950f672e", "size": 3034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/graphs-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/graphs-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/graphs-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": 41.0, "max_line_length": 249, "alphanum_fraction": 0.6849044166, "num_tokens": 1005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6378781195966008}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{gcd -- gcd algorithm}\\linkedzero{gcd}\r\n%\r\n  \\subsection{gcd -- the greatest common divisor}\\linkedone{gcd}{gcd}\r\n   \\func{gcd}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor of two integers \\param{a} and \\param{b}.\\\\\r\n   \\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   \\quad \\param{a},\\ \\param{b} must be int, long or \\linkingone{rational}{Integer}.\r\n   Even if one of the arguments is negative, the result is non-negative.\\\\\r\n%\r\n  \\subsection{binarygcd -- binary gcd algorithm}\\linkedone{gcd}{binarygcd}\r\n   \\func{binarygcd}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor of two integers \\param{a} and \\param{b} by binary gcd algorithm.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad \\negok This function is an alias of \\linkingone{arygcd}{binarygcd}\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{a},\\ \\param{b} must be int, long, or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{extgcd -- extended gcd algorithm}\\linkedone{gcd}{extgcd}\r\n   \\func{extgcd}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{(\\out{integer},\\ \\out{integer},\\ \\out{integer})}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor $d$ of two integers \\param{a} and \\param{b} and $u,\\ v$ such that $d = \\param{a}u + \\param{b}v$.\\\\\r\n   \\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   \\quad \\param{a},\\ \\param{b} must be int, long, or \\linkingone{rational}{Integer}.\\\\\r\n   The returned value is a tuple (\\param{u},\\ \\param{v},\\ \\param{d}).\\\\\r\n%\r\n  \\subsection{lcm -- the least common multiple}\\linkedone{gcd}{lcm}\r\n   \\func{lcm}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the least common multiple of two integers \\param{a} and \\param{b}.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\negok If both \\param{a} and \\param{b} are zero, then it raises an exception.\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{a},\\ \\param{b} must be int, long, or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{gcd\\_of\\_list -- gcd of many integers}\\linkedone{gcd}{gcd\\_of\\_list}\r\n   \\func{gcd\\_of\\_list}{\\hiki{integers}{list}}{\\out{list}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return gcd of multiple integers.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad For given \\param{integers} $[x_1,\\ldots,x_n]$, return a list $[d,\\ [c_1,\\ldots,c_n]]$ such that $d=c_1 x_1+\\cdots+c_n x_n$, where $d$ is the greatest common divisor of $x_1,\\ldots, x_n$.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{integers} is a list which elements are int or long\\\\\r\n   This function returns $[d,\\ [c_1,\\ldots,c_n]]$, where $d,\\ c_i$ are an integer.\\\\\r\n%\r\n  \\subsection{coprime -- coprime check}\\linkedone{gcd}{coprime}\r\n   \\func{coprime}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{bool}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return True if \\param{a} and \\param{b} are coprime, False otherwise.\\\\\r\n   \\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   \\quad \\param{a},\\ \\param{b} are int, long, or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{pairwise\\_coprime -- coprime check of many integers}\\linkedone{gcd}{pairwise\\_coprime}\r\n   \\func{pairwise\\_coprime}{\\hiki{integers}{list}}{\\out{bool}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return True if all integers in \\param{integers} are pairwise coprime, False otherwise.\\\\\r\n   \\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   \\quad \\param{integers} is a list which elements are int, long, or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n\\begin{ex}\r\n>>> gcd.gcd(12, 18)\r\n6\r\n>>> gcd.gcd(12, -18)\r\n6\r\n>>> gcd.gcd(-12, -18)\r\n6\r\n>>> gcd.extgcd(12, -18)\r\n(-1, -1, 6)\r\n>>> gcd.extgcd(-12, -18)\r\n(1, -1, 6)\r\n>>> gcd.extgcd(0, -18)\r\n(0, -1, 18)\r\n>>> gcd.lcm(12, 18)\r\n36\r\n>>> gcd.lcm(12, -18)\r\n-36\r\n>>> gcd.gcd_of_list([60, 90, 210])\r\n[30, [-1, 1, 0]]\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": "1d49f2501ea39751c688b0122e24bddfc5134210", "size": 4346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/gcd.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/gcd.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/gcd.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.1228070175, "max_line_length": 198, "alphanum_fraction": 0.6352968247, "num_tokens": 1425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.6378780982891552}}
{"text": "%!TEX root = ../dokumentation.tex\n\\chapter{Implementation}\n\nThe implementation of ARIMA needs two separate scripts: One for predictions/forecasting and one for training a suitable model.\nNaturally the training script is going to use the prediction script in some way to test the current model and improve it.\n\nBoth scripts need to do three things: \nFirst, loading the time series and parameters p, d, q, P, D, Q, and s. Then differencing the time series according to d and D. And finally they both have to construct the auxiliary matrix $Z$. This matrix is needed to do different calculations within both scripts. The idea behind it, is to provide all the $X_{t-h}$ for any $h \\in [1, max(p, q, Ps, Qs, p + Ps, q + Qs]$ for each $\\hat{X}_t$ to be computed.\nThis means that there is p columns for \\acs{AR}$(p)$, q columns for \\acs{MA}$(q)$, P columns for \\acs{SAR}$(P)$, Q columns for \\acs{SMA}$(Q)$ and when combining non seasonal and seasonal models there is also additional $p \\cdot P$ and $q \\cdot Q$ columns. Each one of those columns corresponds to one of the $X_{t-h}$ terms found in equation for \\eqref{eq:multiplicative_SARIMA}. So essentially Z is constructed in a way that the n-th row of Z contains all the time series values needed to predict $X_n$.\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\scalebox{1}{\\includegraphics[width=1\\textwidth]{images/Zmatrix.png}}\n    \\caption{Schema of auxiliary matrix Z}\n\\end{figure}\n\nThe following function is designed to built such a matrix:\n\\begin{lstlisting}[caption=Prediction of \\acs{AR}$(p)$ or  \\acs{SAR}$(P)$ ,captionpos=b]\nconstructPredictorMatrix = function (Matrix[Double] X, Integer p, Integer P, Integer q, Integer Q, Integer s)return( Matrix[Double] Z){\n\tZ = matrix(0, nrow(X), p+P+Q+q+p*P+q*Q)\n\n\t# fills Z with values used for non seasonal AR prediction\n\tfor\t(i in seq(1, p, 1)){\n\t\tZ = addShiftedMatrix(Z, X, i, i)\n\t}\n\n\t#prediction values for seasonal AR \n\tfor(i in seq(1, P, 1)){\n\t\tZ = addShiftedMatrix(Z, X, (i * s), p + i)\n\t}\n\n\t#prediction values for combined models of non-seasonal and seasonal AR\n\tZ = addValuesForCombinedModel (Z, X, p, P, s, p + P)\n\n\t#prediction values for non seasonal MA \n\tfor(i in seq(1, q, 1)){\n\t\tZ = addShiftedMatrix(Z, X, i, p + P + p*P + i)\n\t}\n\n\t#prediction values for seasonal MA \n\tfor(i in seq(1,Q, 1)){\n\t\tZ = addShiftedMatrix(Z, X, (i * s), p + P + p*P + q + i)\n\t}\n\n\t#prediction values for combined models of non-seasonal and seasonal MA\n\tZ = addValuesForCombinedModel (Z, X, q, Q, s, p + P + p*P + q + Q )\n}\n\\end{lstlisting}\n\nThe idea behind this function is to add each column step by step. It starts with all the columns for non seasonal and seasonal \\acl{AR} and proceeds to \\acl{MA}.\n\n\n%TODO: Maybe add example of Z matrix here\n\n\\section{Prediction Script}\n\nThe task of the prediction script is simply to calculate the t-dimensional vector $\\hat{X}$ containing all the predictions $\\hat{X}_t$ for each $t \\in [1,T]$ with T being the number of rows of  $Z$. When using the prediction script for training purposes this is also equal to the size of the time series $X$ used for training.\n\nIn the simplest case of forecasting \\acs{AR}$(p)$ or  \\acs{SAR}$(P)$  the code for the \\lstinline{predict()} function is quite straight forward:\n\n\\begin{lstlisting}[caption=Prediction of \\acs{AR}$(p)$ or  \\acs{SAR}$(P)$ ,captionpos=b]\npredict = function(Matrix[Double] weights, Matrix[Double] Z) return (Matrix[Double] approximated_solution){\n\tapproximated_solution = Z%*%weights\n}\n\\end{lstlisting}\n\nFor predicting non seasonal and seasonal \\acs{SAR} at once the combination of the purely non seasonal and purely seasonal part have to be taken into consideration. This is done by constructing another auxiliary matrix $\\omega$ (referred to in the scripts as 'combined\\_weights') that holds all weights for $p$ and $P$ as well as all the combinations of those weights:\n\n\\begin{lstlisting}[caption=Prediction of \\acs{SAR}$(p)(P)$ ,captionpos=b]\ncombined_weights = weights\nif (p>0 & P>0){\n\tcombined_weights = rbind(combined_weights, matrix(weights[1:p,] %*% t(weights[p+1:p+P,]), rows=p*P, cols=1))\n}\napproximated_solution = Z%*%combined_weights\n\\end{lstlisting}\n\nLike already discussed in the chapter \\ref{arimamodel} and described in more detail with the equations \\eqref{eq:MA_q} through \\eqref{eq:example_MA_three_system_2}, calculating $\\hat{X}$ for \\acs{MA}(p) requires to construct a third matrix R to be used to describe the system of linear equations that needs to be solved with:\n\\[A = I + R\\]\n\n\\begin{lstlisting}[caption=Prediction of \\acs{MA}$(q)$ ,captionpos=b]\nb = Z%*%weights\nR = matrix(0, nrow(Z), nrow(Z))\nfor(i in seq(1, q, 1)){\n\td_ns = matrix(as.scalar(weights[P+p+i,1]), nrow(R)-i, 1)\n\tR[1+i:nrow(R),1:ncol(R)-i] = R[1+i:nrow(R),1:ncol(R)-i] + diag(d_ns)\n}\napproximated_solution = numerical_solvers::jacobi (A=A, b=b)\n\\end{lstlisting}\n\nThe equivalent for-loop can be implemented for \\acs{SMA} as well. With the only difference that instead of the term $i$ the term $i\\cdot s$ is to be used.\n\nTo solve the system of linear equations the \\textit{Jacobi} solver had to be implemented in the way it was described in chapter \\ref{jacobi}:\n\\begin{lstlisting}[caption=Prediction of \\acs{MA}$(q)$ ,captionpos=b]\njacobi = function (Matrix[Double] R, Matrix[Double] b, Double tolerance = 0.01, Integer max_iterations = 1000)  return (Matrix[Double] x){\n\tx = matrix(0, nrow(R), 1)\n  \tk = 0\n\tdiff = tolerance+1\n\twhile(k < max_iterations & diff > tolerance){\n\t\tx_k = b - R%*%x\n\t\tdiff = sum((x_k-x)^2)\n\t\tx = x_k\n\t\tk += 1\n\t}\n}\n\\end{lstlisting}\n\n\\section{Training Script}\n\n\n%Pseudo code/description arima training\n\n%Load Time Series X_t and parameters p, d, q, P, D, Q, and s\n%Difference X_tnon seasonaland seasonal\n%Build auxiliary matrix Z with the series X_t  as the first column, the target values and all the previous values from X_t that can be used to predict the target value at time  \n%Solve nonlinear optimization problem for ARMA(p,q)〖(P,Q)〗_s   to find best values for 〖 ϕ〗_i,〖 Φ〗_j,〖 θ〗_k,〖 Θ〗_l over a) Maximum likelihood estimation b) Nonlinear least squares method  \n\n\n\n%arima residuals and css \n%gradient of arima\n%bfgs\n\n%building Z\n\t%addshiftedMatrix\n    %addValuesForCombinedModel\n    \n%differencing\n\n\\chapter{Result}\n% What was tested\n\n\\section{Correctness Test}\n\n\\section{Performance Test}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "9985918cc8b0fc6a29df6066ab019f168e99d56d", "size": 6308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/04kapitel.tex", "max_stars_repo_name": "TobiasSchmidtDE/Scalable-Time-Series-Forecasting-with-ARIMA-for-SystemML", "max_stars_repo_head_hexsha": "c7935e293aae2d5dd3d10803537423c9dd24dc8e", "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": "content/04kapitel.tex", "max_issues_repo_name": "TobiasSchmidtDE/Scalable-Time-Series-Forecasting-with-ARIMA-for-SystemML", "max_issues_repo_head_hexsha": "c7935e293aae2d5dd3d10803537423c9dd24dc8e", "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": "content/04kapitel.tex", "max_forks_repo_name": "TobiasSchmidtDE/Scalable-Time-Series-Forecasting-with-ARIMA-for-SystemML", "max_forks_repo_head_hexsha": "c7935e293aae2d5dd3d10803537423c9dd24dc8e", "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": 41.2287581699, "max_line_length": 504, "alphanum_fraction": 0.7190868738, "num_tokens": 1861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6378226893959148}}
{"text": "\\section{Table of Laplace Transforms}\r\n\\noindent\r\nBelow is a brief table of Laplace transforms. Although most differential equations textbooks have a longer table, this table covers all Laplace transforms done in this text.\r\n\\renewcommand{\\arraystretch}{1.75}\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{ l | l }\r\n\t\t$f(t)$  & $F(s) = \\Laplace{f}$\t\\\\\r\n\t\t\\hline\r\n\t\t$f(at)$ & $\\frac{1}{a}F\\left(\\frac{s}{a}\\right)$\t\\\\\r\n\t\t$f'(t)$ & $sF(s) - f(0)$\t\\\\\r\n\t\t$f^{(n)}(t)$ & $s^nF(s) - \\sum_{i=0}^{n-1}{s^{n-i-1}f^{(i)}}(0)$\t\\\\\r\n\t\t$t^nf(t)$ & $(-1)^nF^{(n)}(s)$\t\\\\\r\n\t\t$\\frac{1}{t}f(t)$ & $\\int_s^\\infty{F(u) \\mathrm{d}u}$\t\\\\\r\n\t\t$a$ & $\\frac{a}{s}\\text{, } s > 0$ \\\\\r\n\t\t$e^{at}$ & $\\frac{1}{s-a}\\text{, } s > a$\t\\\\\r\n\t\t$t^n, n = 1,2,\\ldots$ & $\\frac{n!}{s^{n+1}}\\text{, } s < 0$\t\\\\\r\n\t\t$e^{at}t^n, n = 1,2,\\ldots$ & $\\frac{n!}{(s-a)^{n+1}}\\text{, } s > a$\t\\\\\r\n\t\t$\\sin{(bt)}$ & $\\frac{b}{s^2 + b^2}\\text{, } s > 0$ \\\\\r\n\t\t$\\cos{(bt)}$ & $\\frac{s}{s^2 + b^2}\\text{, } s > 0$ \\\\\r\n\t\t$e^{at}\\sin{(bt)}$ & $\\frac{s}{(s-a)^2 + b^2}\\text{, } s > a$ \\\\\r\n\t\t$e^{at}\\cos{(bt)}$ & $\\frac{s-a}{(s-a)^2 + b^2}\\text{, } s > a$ \\\\\r\n\t\\end{tabular}\r\n\\end{table}", "meta": {"hexsha": "815c849cb8f1a9d0170c4a61f4c74a2553968da4", "size": 1132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/appendix/laplaceTable/laplaceTable.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/appendix/laplaceTable/laplaceTable.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/appendix/laplaceTable/laplaceTable.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.1666666667, "max_line_length": 174, "alphanum_fraction": 0.4770318021, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.637822686835319}}
{"text": "% !TEX root = Main.tex\n\\section{Generative Models}\nDeep Probabilistic Models: $x^{l+1} = F^l(x^l) + W^l z^l$, $z^{l}\\sim \\mathcal{N}(0,1)$. Allows for easy sampling from complex distributions.\n\\subsection{Autoencoders (AE)}\nLearn low dim. representation. \nLinear: $min \\frac{1}{2k} \\sum_{i}^n ||x_i - DCx_i||^2$, C encoder, D decoder. Frobenius norm optimal solution from SVD(X): $C^*=U_d^T, D*=U_d$, $U$\nNon-linear: Use feedforward NN for encoding and decoding $F = H \\circ G$. \\\\\nDenoising: Perturb input $x := x + \\eta$\n\\subsection{Variational AE}\nGet gen. AE by constraining distribution of latent vars to follow a given distrib.\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item Condition on y, compute $q(z|y)$\n\t\\item sample $z^l \\sim q(z^l|y)$\n\t\\item forward $z^l$\n\t\\item backpropagate for generated example.\n\\end{inparaenum}\nMax ELBO $E_q[log p(x^{1:L},y;\\theta) - log q(x^{1:L};y)] \\leq log p (y;\\theta)$ \\\\ \nOr: $log p_\\theta(x^{i}) \\geq E_z[log p_\\theta(x^{i}|z)] - D_{KL}(q_\\theta(z|x^{i}||p_\\theta(z)))$\nAutoregressive Model: Gen. output 1 var at a time. \nPixel CNN: $p(x) = \\prod_i^{n^2} p(x_i|x_1,...,x_{i-1})$. \\\\\nAutoregr. process of order p: $x_t = \\sum_{i=1}^p \\phi_i x_{t-p} + \\delta_t$.\nSolve for $\\phi^*$ by MLE: $p(x, \\phi) = p(x_1)\\prod_{i=2}^n p(x_i|x_{i-1},...,x_1,\\phi)$ or via least sq. solution of the problem $\\phi^* = (X^TX)^{-1}X^Ty$", "meta": {"hexsha": "ecd8a967583d5957756870df40f5d5f8c35bed07", "size": 1356, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GenerativeModels.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": "GenerativeModels.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": "GenerativeModels.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": 61.6363636364, "max_line_length": 157, "alphanum_fraction": 0.6482300885, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6378070002258016}}
{"text": "\n\\section{Kernels\\label{app:kernels}}\nHere we list the elliptic \\pde's investigated in this work along with the associated kernels for their single- and double-layer potentials.\nIn this section, $\\vx$ and $\\vy$ are in $\\mathbb{R}^3$, $\\vx$ is the point of evaluation and $\\vy$ is a point on the boundary and $\\vr = \\vx - \\vy$. \nRecall that $\\vn$ is the outward pointing unit normal at $\\vy$ to the domain boundary $\\Gamma$.\nWe denote the single layer kernel, also known as the \\textit{fundamental solution} or \\textit{Green's function} of the \\pde, by $S$ and the double layer kernel by $D$.\n\\begin{enumerate}\n  \\item \\textit{Laplace equation}:\n    \\begin{align*}\n      &\\Delta u = 0\\\\\n      &S(\\vx,\\vy) = \\frac{1}{4\\pi}\\frac{1}{\\|\\vr\\|}, \\quad \n      D(\\vx, \\vy) = - \\frac{1}{4\\pi} \\frac{\\vr \\cdot \\mathbf{n}}{\\|\\vr\\|^3}\n    \\end{align*}\n  \\item \\textit{Stokes equation}:\n    \\begin{align*}\n      &\\mu\\Delta u - \\nabla p = 0, \\,\\, \\nabla \\cdot u = 0\\\\\n      &S(\\vx,\\vy) = \\frac{1}{8\\pi\\mu}\\left( \\frac{1}{\\|\\vr\\|} + \\frac{\\vr \\otimes\\vr}{\\|\\vr\\|^3}\\right), \\quad \n      D(\\vx, \\vy) = - \\frac{3}{4\\mu\\pi} \\frac{\\vr \\otimes\\vr}{\\|\\vr\\|^5}(\\vr \\cdot \\mathbf{n})\n    \\end{align*}\n  \\item \\textit{Elasticity equation}:\n    \\begin{align*}\n      &\\mu\\Delta u - \\frac{\\mu}{1-2\\nu}\\nabla(\\nabla \\cdot u) = 0\\\\\n      &S(\\vx,\\vy) = \\frac{1}{16\\pi\\mu(1-\\nu)}\\left( \\frac{3-4\\nu}{\\|\\vr\\|} + \\frac{\\vr \\otimes\\vr}{\\|\\vr\\|^3}\\right), \\\\\n      &D(\\vx, \\vy) = - \\frac{1-2\\nu}{8\\mu(1-\\nu)} \\left(\n      \\frac{1}{\\|\\vr\\|^3} \\left(\n      \\vr \\otimes \\vn - (\\vr\\cdot\\vn) I - \\vn \\otimes \\vr \n      \\right) - \\frac{3}{1-2\\nu}\n      \\frac{(\\vr\\cdot\\vn) (\\vr \\otimes \\vr)}{\\|\\vr\\|^5}\n      \\right)\n    \\end{align*}\n\\end{enumerate}\n", "meta": {"hexsha": "941bdad6553ac70d2bba1247839dfd0ff61d2267", "size": 1708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hedgehog/kernels.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/kernels.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/kernels.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": 53.375, "max_line_length": 167, "alphanum_fraction": 0.5690866511, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6378069948470367}}
{"text": "\\section*{Problem 2 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\nThe $Q$-value of a reaction is given by:$$Q=[m(\\text{x})+m(\\text{X})-m(\\text{y})-m(\\text{Y})]c^{2}.$$\n\n\\begin{spacing}{1.75}\t\n$^{235}\\text{\\normalfont{U}}+n \\rightarrow  \\-\\ ^{135}\\text{\\normalfont{I}}+ \\! ^{98}\\text{\\normalfont{Y}}+3n$\\\\\n\t\\tab $Q = [m(^{235}\\text{\\normalfont{U}})+m(n)-m(^{135}\\text{\\normalfont{I}})-m(^{98}\\text{\\normalfont{Y}})-3m(n)]c^{2}$\\\\\n\t\\tab $Q = [235.043924\\text{u}+1.008665\\text{u}-134.910048\\text{u}-97.922203\\text{u}-3(1.008665\\text{u})]c^{2}$\\\\\n\t\\tab $Q = 0.194343\\text{u} \\cdot c^{2}$\\\\\n\t\\tab $\\boxed{Q = 181.031 \\text{ MeV}}$ \n\\end{spacing}\n\n\n\\item \n\nThe binding energy $B(Z,A)$ for any nuclei can be found approximately from the equation:$$M(Z,A) = Zm(^{1}\\text{H})+(A-Z)m_{n}-B(Z,A)/c^{2},$$ where $M(Z,A),\\; Zm(^{1}\\text{H})$ and $m_{n}$ are experimentally calculated values. Per nucleon, the binding energy can be expressed as: $$B_{A}(Z,A) = [Zm(^{1}\\text{H})+(A-Z)m_{n}-M(Z,A)]c^{2}/A.$$\n\n\\begin{spacing}{1.75}\n\n\\textbf{$^{2}$H}\\\\\n$B_{A}(1,2) = [m(^{1}\\text{H})+(2-1)m_{n}-M(1,2)]c^{2}/2$\\\\\n$B_{A}(1,2) = [(1.007825\\text{u})+(1.008665\\text{u})-(2.014102\\text{u})]c^{2}/2$\\\\\n$B_{A}(1,2) = 0.001194\\text{u} \\cdot c^{2}$\\\\\n$\\boxed{B_{A}(1,2) = 1.112\\text{ MeV}}$\\\\\n\\textbf{$^{56}$Fe}\\\\\n$B_{A}(26,56) = [26m(^{1}\\text{H})+(56-26)m_{n}-M(26,56)]c^{2}/56$\\\\\n$B_{A}(26,56) = [26(1.007825\\text{u})+30(1.008665\\text{u})-(55.934939\\text{u})]c^{2}/56$\\\\\n$B_{A}(26,56) = 0.009437\\text{u} \\cdot c^{2}$\\\\\n$\\boxed{B_{Z}(26,56) = 8.791\\text{ MeV}}$\\\\\n\\textbf{$^{235}$U}\\\\\n$B_{A}(92,235) = [92m(^{1}\\text{H})+(235-92)m_{n}-M(92,235)]c^{2}/235$\\\\\n$B_{A}(92,235) = [92(1.007825\\text{u})+143(1.008665\\text{u})-(235.043924\\text{u})]c^{2}/235$\\\\\n$B_{A}(92,235) = 0.00814924 u\\text{u} \\cdot c^{2}$\\\\\n$\\boxed{B_{Z}(92,235) = 7.591\\text{ MeV}}$\n\\end{spacing}\n\n\\end{enumerate}\n\n", "meta": {"hexsha": "0784a91ada6b3329f6709e36b4d59cf35a0d7f8c", "size": 1854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc01/disc01_solution02.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_solution02.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_solution02.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": 43.1162790698, "max_line_length": 342, "alphanum_fraction": 0.5609492988, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6377370493054075}}
{"text": "\\graphicspath{{Pics/combi/geo/}}\n\n\\newpage\n\\section{Combinatorial Geometry}\n\n\n\\begin{myitemize}\n\\item \\href{https://blogm4e.files.wordpress.com/2016/08/combinatorial-geometry-maria-monks-mop-2010.pdf}{Combinatorial Geometry - Maria Monk (MOP 2010)}\n\\end{myitemize}\n\n\n\\begin{take_note*}{}\n    \\begin{itemize}[wide=0pt]\n        \\item Consider the convex hull made up of the points.\n        \\item Consider the extreme points: smallest or highest $ x $ or $ y $ coordinate.\n        \\item Find the triangle (quadrilateral, pentagon, etc.)  with the vertices being the points from your set $ S $, so that the area of the triangle is minimal/maximal.\n    \\end{itemize}\n\\end{take_note*}\n\n\\theo{https://en.wikipedia.org/wiki/Helly's_theorem}{Helly's Theorem}{Let $ X_1, ..., X_n $ be a finite collection of convex subsets of $ \\R^d $, with $ n > d $. If the intersection of every $ d + 1 $ of these sets is nonempty, then the whole collection has a nonempty intersection; that is,\n\\[\\bigcap _{j=1}^{n}X_{j}\\neq \\varnothing\\]}\n\n\n\\vspace{1em}\n\n\\begin{myitemize}\n    \\item \\href{https://math.berkeley.edu/~moorxu/misc/equiareal.pdf}{Sperner's\n        Lemma - Moor Xu}\n\\end{myitemize}\n\n\\theo{https://www.wikiwand.com/en/Sperner's_lemma}\n{Sperner's Lemma}{\n    Given a triangle $ABC$, and a triangulation $\\mathcal{T}$ of the triangle,\n    the set $S$ of vertices of $\\mathcal{T}$ is colored with three colors in\n    such a way that\n    \\begin{enumerate}\n        \\item $A, B$, and $C$ are colored $1, 2$, and $3$ respectively.\n        \\item Each vertex on an edge of $ABC$ is to be colored only with one of the\n            two colors of the ends of its edge. For example, each vertex on $AC$\n            must have a color either $1$ or $3$.\n    \\end{enumerate}\n    Then there exists a triangle from $\\mathcal{T}$, whose vertices are colored with the\n    three different colors. More precisely, there must be an odd number of\n    such triangles. \n}\n\n\n\\begin{prooof}\n    Consider a graph $G$ built from the triangulation $\\mathcal{T}$ as\n    follows:\\\\\n\n    {\\color{solC}The vertices of $G$ are the members of $\\mathcal{T}$ plus the\n    area outside the triangle.  Two vertices are connected with an edge if\n    their corresponding areas share a common border with an edge $1$--$2$.\\\\}\n\n    Note that on the interval $AB$ there is an odd number of borders colored\n    $1$--$2$. Therefore, the vertex of $G$ corresponding to the outer area has\n    an odd degree. \\\\\n\n    But since in a finite graph there is an even number of\n    vertices with odd degree, in the remaining graph, excluding the\n    outer area, there is {\\color{solC}an odd number of vertices with odd\n    degree} corresponding to members of $\\mathcal{T}$.\\\\\n\n    It can be easily seen that the only possible degree of a triangle from\n    $\\mathcal{T}$ is $0, 1$, or $2$, and that the degree $1$ corresponds to a\n    triangle colored with the three colors $1, 2$, and $3$.\\\\\n\n    Thus we have obtained a slightly stronger conclusion, which says that in a\n    triangulation $\\mathcal{T}$ there is an odd number (and at least one) of\n    full-colored triangles. \n\\end{prooof}\n\n\n\\theo{https://www.wikiwand.com/en/Brouwer_fixed-point_theorem}\n{Brouwer fixed-point theorem}{\n    Let $B^n$ be the $n$th dimensional ball. Then any continuous map\n    $f:B^n \\to B^n$ has a fixed point.\n}\n\n\\theo{https://en.wikipedia.org/wiki/Monsky's_theorem}\n{Monsky's theorem}{\n    If we triangulate a square with triangles of equal area, then there must\n    be an even number of triangles used.\n}\n\n\n\\theo{https://en.wikipedia.org/wiki/Pick's_theorem}\n{Pick's Theorem}{\n    A simple polygon $P$ has all of its vertices on the lattice points of $xy$\n    grid. If it's area is $A$, the number of lattice points inside the\n    polygon is $i$ and the number of lattice points on the boundary is $b$,\n    then \\textbf{Pick's theorem} states that\n    \\[A = i + \\frac{b}{2} -1\\] \n}\n\n\n\n\n\\newpage\n\\subsection{Problems}\n\n\\prob{https://artofproblemsolving.com/community/c6h535002p3067558}{ARO 2013 P9.4}{E}{$ N $ lines lie on a plane, no two of which are parallel and no three of which are concurrent. Prove that there exists a non-self-intersecting broken line $ A_1A_2A_3\\dots A_N $ with $ N $ parts, such that on each of the $ N $ lines lies exactly one of the $ N $ segments of the line.}\\label{problem:constructive_algo_8}\\label{problem:induction_type1_7}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1424941p8024557}{EGMO 2017 P3}{M}{There are $ 2017 $ lines in the plane such that no three of them go through the same point. Turbo the snail sits on a point on exactly one of the lines and starts sliding along the lines in the following fashion: she moves on a given line until she reaches an intersection of two lines. At the intersection, she follows her journey on the other line turning left or right, alternating her choice at each intersection point she reaches. She can only change direction at an intersection point. Can there exist a line segment through which she passes in both directions during her journey?}\\label{problem:plane_coloring_1}\n\n\\solu{The condition that tells us to go either right or left, seems very non-rigorous. So to rigorize this condition, instead of using right or left condition in the direction, we consider what’s on our right and left. (INTUITION) After some experiment we see (not all of us) that if we color the plane with two colors in a way where every neighboring regions have different colors, we find some interesting stuff. (CREATIVITY) With this we are done. \\hrf{plane_coloring}{Color the Plane}}\n\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h101306p571973}{ISL 2006 C2}{TE}{Let $ P $ be a regular $ 2006 $ -gon. A diagonal is called good if its endpoints divide the boundary of $ P $ into two parts, each composed of an odd number of sides of $ P $. The sides of $ P $ are also called good.\n\nSuppose $ P $ has been dissected into triangles by $ 2003 $ diagonals, no two of which have a common point in the interior of $ P $. Find the maximum number of isosceles triangles having two good sides that could appear in such a configuration.}\\label{problem:induction_type2_4}\\label{problem:bijection_9}\n\n\n\\solu{The straight way, induction.}\n\n\\solu{The intuitive way, bijection. There are at most $ n $ good triangles, there are $ 2n $ edges, so a mapping that takes a two edges to a single good triangle must exist. Finding it is not that hard.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h589865p3493114}{ARO 2014 P9.3}{E}{In a convex $ n $ -gon, several diagonals are drawn. Among these diagonals, a diagonal is called good if it intersects exactly one other diagonal drawn (in the interior of the $ n $ -gon). Find the maximum number of good diagonals.}\\label{problem:induction_type2_1}\n\n\\solu{There can be two cases, two good diagonals intersecting each other, and no two good diagonals intersecting each other. In the first case, we just use induction, and in the later, all of the good diagonals create a ``triangulation'' of the polygon, which gives us the numbers.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1181527p5720110}{ISL 2013 C2, IMO 2013 P2}{E}{A configuration of $ 4027 $ points in the plane is called Colombian if it consists of $ 2013 $ red points and $ 2014 $ blue points, and no three of the points of the configuration are collinear. By drawing some lines, the plane is divided into several regions. An arrangement of lines is good for a Colombian configuration if the following two conditions are satisfied:\n\n    \\begin{enumerate}\n\n        \\item No line passes through any point of the configuration.\n        \\item No region contains points of both colors.\n\n    \\end{enumerate}\n\nFind the least value of $ k $ such that for any Colombian configuration of $ 4027 $ points, there is a good arrangement of $ k $ lines.}\\label{problem:sandwiching_points_1}\n\n\\solu{Obviously a n00b would think about induction. The only problem occurs when the convex hull completely consists of red points. In this case, after some investigation, we should get the sandwiching two points idea.}\n\n\\solu{Another way of inductive approach is like this, as the problem condition says that no region contains points of both colors, which means if we connect any two red and blue points, some line must bisect this segment. Now \\hrf{problem:convex_hull_1}{it is known} that there is non intersecting partition of the points in to red-blue segments. So suppose in such a partition, we draw bisectors of each segments. Now there will be some holes in this proof. We see that to fill these holes, we have to focus on two red points with their respective blue partners, and draw the two bisectors in a way that separates the two red points form the blue points. So to remove further holes, we get the sandwiching idea.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h366745p2018324}{ILL 1985}{E}{Let $A$ and $B$ be two finite disjoint sets of points in the plane such that no three distinct points in $A \\cup B$ are collinear. Assume that at least one of the sets $A, B$ contains at least five points. Show that there exists a triangle all of whose vertices's are contained in $A$ or in $B$ that does not contain in its interior any point from the other set.}\n\n\\solu{Concentrating on one of the sets five points such that there is no other points of the same set inside the hull of those five points.}\\label{problem:convex_hull_2}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h79789p456611}{APMO 1999 P5}{M}{Let $S$ be a set of $2n+1$ points in the plane such that no three are collinear and no four concyclic. A circle will be called ``Good'' if it has $ 3 $ points of $S$ on its circumference, $n-1$ points in its interior and $n-1$ points in its exterior. Prove that the number of good circles has the same parity as $n$.}\n\n\n\\solu{When thinking about induction, got a feeling that double counting with the number of good circles going through pairs of points might be useful, because a good circle will be counted three times, if we can show that every pair has odd number of good circles, we are done. So, take a pair. Now we need to `sort' the points somehow. See that, we can't sort the points in a trivial way with numbers, so moving to angles. Now setting conditions for a point inside of a circle in terms of angles, we see amazing patter, and an easy way to calculate the number of good circle of that pair of points.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1113183p5083543}{ISL 2014 C1}{E}{Let $ n $ points be given inside a rectangle $ R $ such that no two of them lie on a line parallel to one of the sides of $ R $. The rectangle $ R $ is to be dissected into smaller rectangles with sides parallel to the sides of $ R $ in such a way that none of these rectangles contains any of the given points in its interior. Prove that we have to dissect $ R $ into at least $ n + 1 $ smaller rectangles.}\\label{problem:extreme_object_7}\\label{problem:double_counting_3}\n\n\\solu{Work with the largest continuous segments, and their endpoints.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h195050p1071295}{ISL 2007 C2}{EM}{A rectangle $ D$ is partitioned in several ($ \\ge2$) rectangles with sides parallel to those of $ D$. Given that any line parallel to one of the sides of $ D$, and having common points with the interior of $ D$, also has common interior points with the interior of at least one rectangle of the partition; prove that there is at least one rectangle of the partition having no common points with $ D$'s boundary.}\\label{problem:extreme_object_17}\n\n\\begin{minipage}{.6\\linewidth}\n    \\solu{\n        There existing such a rectangle means that there is a rectangular region\n        inside of the original rectangle. So what if we walked along the segments,\n        and cut a smaller rectangle from the inside of the rectangle? Like the way\n        in the game.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.4\\linewidth}\n    \\figdf{.8}{2007c2}{}\n\\end{minipage}\n\n\n\\solu{Starting from one corner, and taking the opposite corner of the rectangle containing that corner, we use infinite decent to reach a contradiction.}\n\n\\solu{Using \\hrf{problem:extreme_object_7}{ISL 2014 C1} as a lemma.}\n\n\\solu{Take one side of the square. Take a ``sandwiched'' rectangle touching that side. If no such rectangle exists, then it's just a special case that can be dealt with ease.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h5753p18977}{ISL 2003 C2}{E}{Let $D_1,D_2\\dots,D_n$ be closed discs in the plane. (A closed disc is the region limited by a circle, taken jointly with this circle.) Suppose that every point in the plane is contained in at most $2003$ discs $D_i$. Prove that there exists a disc $D_k$ which intersects at most $7\\cdot 2003 - 1 = 14020$ other discs $D_i$.}\n\n\\solu{Just go with the natural idea.}\n\n\\prob{https://artofproblemsolving.com/community/c6h5785p19086}{ISL 2003 C3}{E}{Let $n \\geq 5$ be a given integer. Determine the greatest integer $k$ for which there exists a polygon with $n$ vertices (convex or not, with non-selfintersecting boundary) having $k$ internal right angles.}\\label{problem:double_counting_10}\n\n\\solu{double count}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1389042p7736716}{Tournament of Towns 2015S S4}{A convex$N-$gon with equal sides is located inside a circle. Each side is extended in both directions up to the intersection with the circle so that it contains two new segments outside the polygon. Prove that one can paint some of these new $2N$ segments in red and the rest in blue so that the sum of lengths of all the red segments would be the same as for the blue ones.}\n\n\\solu{Just use what's the most natural, POP, on one vertex point.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h145844p825495}{USAMO 2007 P2}{E}{A square grid on the Euclidean plane consists of all points $(m,n)$, where $m$ and $n$ are integers. Is it possible to cover all grid points by an infinite family of discs with non-overlapping interiors if each disc in the family has radius at least $5$?}\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\prob{https://artofproblemsolving.com/community/c6h1135648p5301617}\n    {MEMO 2015 T4}{EM}{\n        Let $N$ be a positive integer. In each of the $N^2$ unit squares of an\n        $N\\times N$ board, one of the two diagonals is drawn. The drawn\n        diagonals divide the $N\\times N$ board into $K$ regions. For each $N$,\n        determine the smallest and the largest possible values of $K$.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.4\\linewidth}\n    \\figdf{.7}{MEMO2015T4}{}\n\\end{minipage}\n\n\n\\solu{An Algorithmic Approach: Consider each diagonal as $ 0 $ or $ 1 $, prove that the maximum configuration is the one with alternating $ 0, 1 $s and the minimum one is the one with all $ 0 $s.}\n\n\\solu{A Counting Approach: Just count and bound with the minimum areas of the regions.}\n\n\n\\prob{}{}{EM}{In every cells of a $ m\\times n $ grid, one of the two diagonals are drawn. Prove that there exist a path on these diagonals from left to right or from up to bottom of the grid.}\n\n\\solu{First remove the cycles, then take the largest path from left to right, and use induction.}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c132h1546693p9385334}{Math Price for Girls 2017 P4}{E}{A lattice point is a point in the plane whose two coordinates are both integers. A lattice line is a line in the plane that contains at least two lattice points. Is it possible to color every lattice point red or blue such that every lattice line contains exactly 2017 red lattice points? Prove that your answer is correct.}\n\n\\solu{Transfinite induction.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1217113p6063817}{China TST 2016 T3P2}{E}{In the coordinate plane the points with both coordinates being rational numbers are called rational points. For any positive integer $n$, is there a way to use $n$ colours to colour all rational points, every point is coloured one colour, such that any line segment with both endpoints being rational points contains the rational points of every colour?}\n\n\\solu{Transfinite induction}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1709989p11022201}{IGO 2018 A3}{E}{Find all possible values of integer $n > 3$ such that there is a convex $n$-gon in which, each diagonal is the perpendicular bisector of at least one other diagonal.}\n\n\\solu{Taking maximum terminal triangle.}\n\n\n\\prob{}{Lithuania ??}{E}{Prove that in every polygon there is a diagonal that cuts off a triangle and lies completely within the polygon.}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h202941p1116402}{Romanian TST 2008 T1P4}{E}{Prove that there exists a set $ S$ of $ n - 2$ points inside a convex polygon $ P$ with $ n$ sides, such that any triangle determined by $3$ vertices of $ P$ contains exactly one point from $ S$ inside or on the boundaries.}\n\n\\solu{Checking small cases inductively quickly shows a construction.}\n\n\n\\prob{}{Iran TST ??}{E}{In an isosceles right-angled triangle shaped billiards table, a ball starts moving from one of the vertices adjacent to hypotenuse. When it reaches to one side then it will reflect its path. Prove that if we reach to a vertex then it is not the vertex at initial position}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1662915p10561203}{APMO 2018 P4}{EM}{Let $ABC$ be an equilateral triangle. From the vertex $A$ we draw a ray towards the interior of the triangle such that the ray reaches one of the sides of the triangle. When the ray reaches a side, it then bounces off following the law of reflection, that is, if it arrives with a directed angle $\\alpha$, it leaves with a directed angle $180^{\\circ}-\\alpha$. After $n$ bounces, the ray returns to $A$ without ever landing on any of the other two vertices. Find all possible values of $n$.}\n\n\n\\solu{Reflect the whole board when just reflecting the ball doesn't seem to be helping. GLOBAL}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h195043p1071276}{ISL 2007 C5}{EM}{In the Cartesian coordinate plane define the strips $ S_n = \\{(x,y)|n\\le x < n + 1\\}$, $ n\\in\\mathbb{Z}$ and color each strip black or white. Prove that any rectangle which is not a square can be placed in the plane so that its vertices have the same color.}\n\n\\solu{Proceed step by step. See what happens if the parity of $ a, b $ are different. Then the case with two coprimes. In this case, we want to tilt the rectangle to some extent where the desired result is achieved. We just need to show that this is possible. A bit of wishful thinking and a bit of algebra does the rest.}\t\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1662910p10561186}{APMO 2018 P3}{M}{A collection of $n$ squares on the plane is called tri-connected if the following criteria are satisfied:\n\n    \\begin{enumerate}\n        \\item  All the squares are congruent.\n        \\item  If two squares have a point $P$ in common, then $P$ is a vertex of each of the squares.\n        \\item  Each square touches exactly three other squares.\n    \\end{enumerate}\n\nHow many positive integers $n$ are there with $2018\\leq n \\leq 3018$, such that there exists a collection of $n$ squares that is tri-connected?}\n\n\\solu{Play around to find that $ 6k $ for $ k>4 $ is good. Then play around a little bit more for a different construction. Another construction for $ 6k $ gives rise to a construction for $ 10k $. Which integers can be written as a sum of $ 6k $ and $ 10k $?}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1082935p4768413}{Iran 2005}{E}{A simple polygon is one where the perimeter of the polygon does not intersect itself (but is not necessarily convex). Prove that a simple polygon $P$ contains a diagonal which is completely inside $P$ such that the diagonal divides the perimeter into two parts both containing at least $\\frac{n}{3} - 1$ vertices. (Do not count the vertices which are endpoints of the diagonal.)}\n\n\\solu{Triangulate.}\t\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h287860p1555907}{ISL 2008 C3}{E}{In the coordinate plane consider the set $ S$ of all points with integer coordinates. For a positive integer $ k$, two distinct points $ a$, $ B\\in S$ will be called $ k$-friends if there is a point $ C\\in S$ such that the area of the triangle $ ABC$ is equal to $ k$. A set $ T\\subset S$ will be called $ k$-clique if every two points in $ T$ are $ k$-friends. Find the least positive integer $ k$ for which there exits a $ k$-clique with more than 200 elements.}\n\n\\solu{When does $ ax+by= c $ have integer solution? Fix one point as origin and check other points friendliness with other points.}\n\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1112753p5079689}{ISL 2015 C2}{E}{We say that a finite set $\\mathcal{S}$ of points in the plane is balanced if, for any two different points $A$ and $B$ in $\\mathcal{S}$, there is a point $C$ in $\\mathcal{S}$ such that $AC=BC$. We say that $\\mathcal{S}$ is centre-free if for any three different points $A$, $B$ and $C$ in $\\mathcal{S}$, there is no points $P$ in $\\mathcal{S}$ such that $PA=PB=PC$.\\\\\n\n    \\begin{enumerate}\n        \\item Show that for all integers $n\\ge 3$, there exists a balanced set consisting of $n$ points.\n        \\item Determine all integers $n\\ge 3$ for which there exists a balanced centre-free set consisting of $n$ points.\n\\end{enumerate}}\n\n\\solu{Simple, think about circles, then think about ``center-free'' in a graph theoritic manner.}\n\n\n\n\n\n\\newpage\n\\subsection{Chessboard Pieces}\n\n\n\\lem{}{What is the maximum number of knights that can be placed on a chessboard such that no two knights attack each other?}\\label{lemma:maximum_knight_problem}\n\n\\solu{A knight's move always changes the color of the cell.}\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1671290p10632348P}{IMO 2018 P4}{E/H}{A site is any point $(x, y)$ in the plane such that $x$ and $y$ are both positive integers less than or equal to 20.\\\\\n\n    Initially, each of the 400 sites is unoccupied. Amy and Ben take turns placing stones with Amy going first. On her turn, Amy places a new red stone on an unoccupied site such that the distance between any two sites occupied by red stones is not equal to $\\sqrt{5}$. On his turn, Ben places a new blue stone on any unoccupied site. (A site occupied by a blue stone is allowed to be at any distance from any other occupied site.) They stop as soon as a player cannot place a stone.\\\\\n\nFind the greatest $K$ such that Amy can ensure that she places at least $K$ red stones, no matter how Ben places his blue stones.}\\label{problem:coloring_3}\n\n\n\\solu{Using the \\hrf{lemma:maximum_knight_problem}{maximum knight problem} as a lemma.}\n\n\n\n\\prob{}{}{E}{How many rooks can be placed on an $ n\\times n $ board such that each rook attacks at most one other rook?}\n\n\\solu{Use graphs with one set of degrees being rows, and the other set of degrees being columns.}\n\n\n\\prob{https://en.wikipedia.org/wiki/Eight_queens_puzzle}{Eight queens puzzle}{}{How many queens can be placed on an $ n\\times n $ board such that no queen attacks another queen?}\n\n\\begin{minipage}[t][][b]{0.195\\linewidth}\n    \\figdf{1}{queen_88}{}\n\\end{minipage}\\hfill%\n\\begin{minipage}[t][][b]{0.342\\linewidth}\n    \\figdf{1}{queen_1414}{}\n\\end{minipage}\\hfill%\n\\begin{minipage}[t][][b]{0.366\\linewidth}\n    \\figdf{1}{queen_1515}{}\n\\end{minipage}\\hfill%\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1417932p7979120}{Serbia National D2P2}{HM}{How many queens can be placed on an $ n\\times n $ board such that each queen attacks at most one other queen?}\n\n\n\\prob{}{BdMO 2019 P10}{E}{Define a new chess piece named warrior. it can either go three steps forward and one step to the side, or t2wo steps forward and two steps to the side in some orientation. In a $ 2020\\times 2020 $ chessboard, prove that the mazimum number of warriors so that none of them attack each other is leass htan or equal to $ \\dfrac{2}{5} $ of the number of cells.}\n\n\\solu{Color and partition}\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\prob{https://artofproblemsolving.com/community/c6h1790447p11841777}\n    {RMM 2019 P4}{EM}{\n        Prove that for every positive integer $n$ there exists a (not\n        necessarily convex) polygon with no three collinear vertices, which\n        admits exactly $n$ diffferent triangulations.\n\n        (A triangulation is a dissection of the polygon into triangles by\n        interior diagonals which have no common interior points with each\n        other nor with the sides of the polygon)\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.4\\linewidth}\n    \\figdf{.9}{RMM2019P4}{Fixes}\n\\end{minipage}\n\n\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1062931p4608924}{China TST 2015 T1D2P1}{EM}{Prove that : For each integer $n \\ge 3$, there exists the positive integers $a_1<a_2< \\cdots <a_n$ , such that for $ i=1,2,\\cdots,n-2 $ , With $a_{i},a_{i+1},a_{i+2}$ may be formed as a triangle side length , and the area of the triangle is a positive integer.}\n\n\\solu{First of all we dont need to limit us to integers, we can work with rationals. We want to build $ a_4 $ from $ a_1, a_2, a_3 $. with $ a_4> a_3 $ while keeping the area rational i.e. keeping the height and base rational.}\n\n\n\n\\prob{https://codeforces.com/problemset/problem/1158/D}{Codeforces 1158D}{E}{You are given $ n $ points on the plane, and a sequence $ S $ of length $ n-2 $ consisting of $ L $ and $ R $. You need to generate a sequence of the points $ a_1, a_2\\dots a_n $ such that \n    \\begin{itemize}\n        \\item the polyline $ a_1a_2\\dots a_n $ is not self intersecting.\n        \\item the directed segment $ a_{i+1}a_{i+2} $ is on the left side of the the directed segment $ a_{i}a_{i+1} $ if $ S_i = L $, and on the right side if $ S_i = R $.\n\\end{itemize}}\n\n\n\n", "meta": {"hexsha": "c4161f3e85a598fe140cb7cabe71044add371201", "size": 25779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec7_combi_geo.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/sec7_combi_geo.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/sec7_combi_geo.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": 64.9345088161, "max_line_length": 713, "alphanum_fraction": 0.7404088599, "num_tokens": 7006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300048, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.6377370354431251}}
{"text": "\\chapter{Bayesian Neural Networks}\nA Bayesian neural network (BNN) is a probabilistic model build on the architecture of a neural network, but trained using Bayesian inference. The intent of such a model is to use the approximation capabilities of the neural networks, described in section \\ref{sec:neural_network}, combined with the capability of estimating uncertainty from Bayesian inference. These uncertainty estimating capabilities comes from considering the model parameters $\\boldsymbol{\\theta}$ as a random variable, such that predictions are made by considering the probability distribution of $\\boldsymbol{\\theta}$. BNNs can therefore be viewed as a special case of ensemble learning (\\cite{zhou_ensemble}) where the model ensemble is constructed by considering all possible values for $\\boldsymbol{\\theta}$. In practice we are not able to consider all possible values of $\\boldsymbol{\\theta}$ and sampling methods are used to sample different models as an approximation and there predictions are aggregated to make a single prediction.\\\\\n\\\\\nIn section \\ref{sec:bayesian_stat} we introduce two principal concepts of statistical inference; the frequentist and Bayesian paradigm and the main differences between these two paradigms. In section \\ref{sec:MC_methods} we introduce the basic theory of Monte Carlo methods and in section \\ref{sec:simple_BNN} we illustrate the main ideas behind Bayesian neural networks with a simple example. Since basic Monte Carlo methods are often inefficient when sampling from complex distributions we examine more sophisticated sampling methods based on Markov chains in section \\ref{sec:MCMC}.\n\\\\\n\\\\\nOne of these methods is the Metropolis algorithm, which we examine in section \\ref{sec:Metropolis}. Afterwards we examine the Hamiltonian Monte Carlo in section \\ref{sec:HMC}. This algorithm builds on the principles of Metropolis, but explores the target distribution more efficiently. Lastly in section \\ref{sec:nuts} we cover an extension of Hamiltonian Monte Carlo, that fixes possible inefficient \"U-turns\", called the No-U-Turn sampler. We end this chapter by briefly examining the choice of prior distributions in section \\ref{sec:priors} and how one can choose the parameters for these using a distribution.\n\n\n\n\n\n\\section{Bayesian \\& Frequentist Views of Learning}\\label{sec:bayesian_stat}\nIn this section we will introduce two concepts of statistical inference. These are the Bayesian and the frequentist paradigm.\n\\\\\n\\\\\nThe ideas behind Bayesian statistics goes back to the 18th century and is named after Thomas Bayes (\\cite{stigler1986history}). In Bayesian learning we consider the model parameters $\\boldsymbol{\\theta}$ as random and aim to learn the probability distribution of these. On the other hand the conventional frequentist methodology considers the model parameters $\\boldsymbol{\\theta}$ as fixed but unknown, while the point estimate $\\hat{\\boldsymbol{\\theta}}$ is a random variable, as it is a function of the dataset, which is assumed to be random.\n\\\\\n\\\\\nTo illustrate the difference between these two approaches in more detail, we will consider an example, which involves a simple coin toss. The uncertainty of the coin showing head or tails can be expressed by the coins probability $p$ of showing heads, which is often referred to as the bias of the coin. Since the properties of the coin is not known beforehand, we do not know the exact probability of showing heads. It could be a fair coin and have the probability $p=\\frac{1}{2}$ or it could be an unbalanced coin meaning that $p\\neq \\frac{1}{2}$.\n\\\\\n\\\\\nA Bayesian statistician would express this uncertainty by a probability distribution over possible values of the unknown probability $p$ and would then update the distribution as more observations become known. Frequentists would find the introduction of a distribution over parameter weights as pure nonsense. The frequentist would instead flip the coin a given number of times to form a dataset, and choose some estimator, for the unknown probability $p$ which would be most consistent with the data, an obvious choice would be the relative frequency of heads in the past coin tosses. \n\\\\\n\\\\\nThis example illustrates the main differences between these two paradigms and these differences will be highlighted in a more formal way in the subsequent sections.\n\n\n\n\\subsection{Maximum Likelihood Estimation} \\label{sec:mle}\nLet us now consider a dataset $\\boldsymbol{X}$, with $n$ examples $\\boldsymbol{x}^{(1)}, \\boldsymbol{x}^{(2)},\\ldots \\boldsymbol{x}^{(n)}$ drawn independently from the true but unknown distribution. We let\n$L(\\boldsymbol{\\theta}\\mid \\boldsymbol{X})\\equiv p(\\boldsymbol{X}\\mid \\boldsymbol{\\theta})$ denote the likelihood function, where $p\\lr{\\boldsymbol{X}\\mid\\boldsymbol{\\theta}}$ is a parametric family of probability distributions with parameter $\\boldsymbol{\\theta}$. A frequentist is, as described earlier, trying to find an estimate of the true parameter that have generated the data, we call such an estimate a point estimate and denote it by $\\hat{\\boldsymbol{\\theta}}$ to separate it from the true parameter. A point estimate can be viewed as a function of data $\\hat{\\boldsymbol{\\theta}}=g\\lr{\\boldsymbol{x}^{(1)}, \\boldsymbol{x}^{(2)},\\ldots \\boldsymbol{x}^{(n)}}$ which is drawn from a random process meaning that $\\hat{\\boldsymbol{\\theta}}$ is a random variable.\nIn most cases of frequentist inference a point estimate is found by maximizing the likelihood and is called the maximum likelihood estimate (MLE)\n\\begin{equation*}\n\\begin{split}\n       \\hat{\\boldsymbol{\\theta}}_{\\text{MLE}}&=\\argmax_{\\boldsymbol{\\theta}}{L(\\boldsymbol{\\theta}\\mid \\boldsymbol{X})}\\\\\n        & = \\argmax_{\\boldsymbol{\\theta}}{\\prod^n_{i=1}p\\lr{\\boldsymbol{x}^{(i)}\\mid \\boldsymbol{\\theta}}}\n\\end{split}\n\\end{equation*}\nIt is often more convenient to maximize a sum instead of a product, not only is it easier to handle sums when differentiating but it also helps stabilize the calculations numerically (\\cite{Goodfellow-et-al-2016}). Thus, we take the logarithm of the likelihood function to obtain the log-likelihood function $\\ell(\\boldsymbol{\\theta}\\mid \\boldsymbol{X})\\equiv \\log{p(\\boldsymbol{X}\\mid \\boldsymbol{\\theta})}$,\n\\begin{equation*}\n\\begin{split}\n       \\hat{\\boldsymbol{\\theta}}_{\\text{MLE}}&=\\argmax_{\\boldsymbol{\\theta}}{\\ell(\\boldsymbol{\\theta}\\mid \\boldsymbol{X})}\\\\\n        &=\\argmax_{\\boldsymbol{\\theta}}{\\sum^n_{i=1}\\log{p\\lr{\\boldsymbol{x}^{(i)}\\mid\\boldsymbol{\\theta}}}}\n\\end{split}\n\\end{equation*}\nand since the logarithm is a monotonic-increasing function, optimizing the log-likelihood is equivalent to optimizing the likelihood. \n\\\\\n\\\\\nWhen the size of the dataset is small the MLE is often prone to overfitting and regularization methods such as penalized maximum likelihood are applied, see \\cite{hastie01statisticallearning}.\n\\\\\n\\\\\nWe can generalize the maximum likelihood estimator to the case where our goal is to estimate a conditional distribution $p\\lr{\\boldsymbol{y}\\mid \\boldsymbol{X},\\boldsymbol{\\theta}}$, in order to predict $\\boldsymbol{y}$ given $\\boldsymbol{X}$ as described for supervised learning in section \\ref{sec:ml_basic}. In this case the conditional maximum likelihood is given by\n\\begin{equation*}\n    \\hat{\\boldsymbol{\\theta}}_{\\text{MLE}}=\\argmax_{\\boldsymbol{\\theta}}L\\lr{\\boldsymbol{\\theta}\\mid \\boldsymbol{y}}=\\argmax_{\\boldsymbol{\\theta}} p(\\boldsymbol{y} \\mid \\boldsymbol{X}, \\boldsymbol{\\theta})\n\\end{equation*}\nand if assume that the targets $\\boldsymbol{y}^{(1)},\\ldots \\boldsymbol{y}^{(n)}$ are i.i.d, we can write\n\\begin{equation*}\n    \\hat{\\boldsymbol{\\theta}}_{\\text{MLE}}=\\underset{\\boldsymbol{\\theta}}{\\arg \\max } \\sum_{i=1}^{n} \\log p\\left(\\boldsymbol{y}^{(i)} \\mid \\boldsymbol{x}^{(i)},\\boldsymbol{\\theta}\\right)\n\\end{equation*}\nThe sum of squared errors, obtained by summing over all datapoints in equation \\ref{eq:mse}, can be justified theoretically by the use of maximum likelihood with a Gaussian likelihood.\nTo see this, consider a regression model that outputs $f(\\boldsymbol{X};\\boldsymbol{\\theta})=\\boldsymbol{\\theta}\\boldsymbol{X}$, with real-valued targets $\\boldsymbol{y}$. If we define the likelihood as the conditional distribution of $\\boldsymbol{y}$ as Gaussian with mean given by the regression output $\\hat{y}\\equiv f(\\boldsymbol{X};\\boldsymbol{\\theta})$ and standard deviation $\\sigma$, we can write\n\\begin{equation*}\n    L(\\boldsymbol{\\theta}\\mid \\boldsymbol{y})=\\prod_{i=1}^{n} p\\left(y^{(i)} \\mid \\boldsymbol{x}^{(i)} , \\boldsymbol{\\theta}\\right)=\\prod_i^n\\frac{1}{\\sqrt{2\\pi\\sigma}}\\exp\\left(-(\\hat{y}^{(i)}-y^{(i)})^2/2\\sigma^2\\right)\n\\end{equation*}\nNext we take the\nlogarithm of the likelihood function which gives us the log-likelihood function\n\\begin{equation*}\n\\begin{split}\n        \\ell(\\boldsymbol{\\theta}\\mid \\boldsymbol{y})&=\\sum_i^n\\log\\frac{1}{\\sqrt{2\\pi\\sigma}}\\exp\\left(-(\\hat{y}^{(i)}-y^{(i)})^2/2\\sigma^2\\right)\\\\\n        &=-\\frac{n}{2} \\log \\sigma^{2}-\\frac{n}{2} \\log (2 \\pi)-\\frac{1}{2 \\sigma^{2}} \\sum_{i}^n\\left(\\hat{y}^{(i)}-y^{(i)}\\right)^{2}\n\\end{split}\n\\end{equation*}\nnote that $-\\frac{n}{2} \\log \\sigma^{2}-\\frac{n}{2} \\log (2 \\pi)$ does not depend on the model parameters $\\boldsymbol{\\theta}$ and can therefore be omitted when maximizing. Maximizing the log-likelihood is the same as minimizing the negative log-likehood, so we can write \n\\begin{equation*}\n\\begin{split}\n        \\min_{\\boldsymbol{\\theta}}{-\\ell(\\boldsymbol{\\theta}\\mid \\boldsymbol{y})}=\\frac{1}{2 \\sigma^{2}} \\sum_{i}^n\\left(\\hat{y}^{(i)}-y^{(i)}\\right)^{2}\n\\end{split}\n\\end{equation*}\nand since $\\frac{1}{2 \\sigma^{2}}$ does not depend on $\\boldsymbol{\\theta}$ either, we can see that minimizing the negative log-likelihood is the same as minimizing the sum of squared errors. \n\n\n\n\\subsection{Bayesian Learning and Prediction}\nA different approach than the frequentist perspective of the parameter value $\\boldsymbol{\\theta}$ as fixed but unknown and the point estimator $\\hat{\\boldsymbol{\\theta}}$ as a random variable, is taken with Bayesian inference. The Bayesian paradigm considers the dataset as fixed and observable, while the true parameter $\\boldsymbol{\\theta}$ is unknown, and thus considered a random variable. \n\\\\\n\\\\\nIn Bayesian statistics, we begin with defining a prior distribution $p(\\boldsymbol{\\theta})$ over the parameters. This prior distribution expresses our initial view on the parameters, before any data has been observed. When data becomes available, we update our prior distribution to a posterior distribution. The posterior distribution is defined by Bayes' rule\n\\begin{equation*}\n         p(\\boldsymbol{\\theta}|\\boldsymbol{X},\\boldsymbol{y})=\\frac{p(\\boldsymbol{\\theta})p(\\boldsymbol{y}|\\boldsymbol{X},\\boldsymbol{\\theta})}{p(\\boldsymbol{y})}\n\\end{equation*}\nand it combines the information about the data, that comes from the likelihood function $p(\\boldsymbol{y}|\\boldsymbol{X},\\boldsymbol{\\theta})$, with the prior distribution. $p(\\boldsymbol{y})$ is called the model evidence and is the distribution of the observed data marginalized over the parameters $p(\\boldsymbol{y})=\\int p(\\boldsymbol{y}\\mid \\boldsymbol{X}, \\boldsymbol{\\theta})p(\\boldsymbol{\\theta})d\\boldsymbol{\\theta}$. The model evidence is often intractable, since it requires integration over all possible values of $\\boldsymbol{\\theta}$, which in many applications requires integration over high-dimensional spaces. As a result, finding analytical solutions of the posterior is not possible for complex models. \nWe often ignore the evidence term, as it does not depend on $\\boldsymbol{\\theta}$ and thus for a fixed $\\boldsymbol{y}$ can be interpreted as a constant, we thus write\n\\begin{equation} \\label{eq:posterior}\n    p(\\boldsymbol{\\theta}|\\boldsymbol{X},\\boldsymbol{y})\\propto p(\\boldsymbol{\\theta})p(\\boldsymbol{y}\\mid \\boldsymbol{X},\\boldsymbol{\\theta})\n\\end{equation}\nAn important quality of the Bayesian method, is that it uses a full distribution over the parameters $\\boldsymbol{\\theta}$ to make predictions. Let us for example consider the case where we have observed a sample consisting of $n$ examples $\\boldsymbol{X}=\\boldsymbol{x}^{(1)}, \\boldsymbol{x}^{(2)},\\ldots, \\boldsymbol{x}^{(n)}$. To predict an unobserved label $\\boldsymbol{y}^{(n+1)}$ for a new example $\\boldsymbol{x}^{(n+1)}$ we need the \nposterior predictive distribution, that is to integrate the model predictions by the posterior\n\\begin{equation} \\label{eq:post_pred_distribution}\n    \\begin{split}\n        &p\\left(\\boldsymbol{y}^{(n+1)} \\mid \\boldsymbol{x}^{(n+1)}, \\lr{\\boldsymbol{x}^{(1)},\\boldsymbol{y}^{(1)}}, \\ldots, \\lr{\\boldsymbol{x}^{(n)}, \\boldsymbol{y}^{(n)}}\\right)\\\\\n        &=\\int p\\left(\\boldsymbol{y}^{(n+1)} \\mid \\boldsymbol{x}^{(n+1)}, \\boldsymbol{\\theta} \\right) p \\lr{\\boldsymbol{\\theta} \\mid \\lr{\\boldsymbol{x}^{(1)}, \\boldsymbol{y}^{(1)}}, \\ldots, \\lr{\\boldsymbol{x}^{(n)}, \\boldsymbol{y}^{(n)}}} \\, d \\boldsymbol{\\theta}\n    \\end{split}\n\\end{equation}\nThis is quite different from the maximum likelihood method, that uses a point estimate for $\\boldsymbol{\\theta}$ to make predictions on any unobserved data, the Bayesian method takes the uncertainty of estimating $\\boldsymbol{\\theta}$ into account when making predictions, which tends to do well in avoidance of overfitting (\\cite{Goodfellow-et-al-2016}).  \n\\\\\n\\\\\nAn important difference between the Bayesian approach and MLE, lies on the contribution of a prior distribution. The prior has the effect of shifting the probability mass towards regions of the parameter space, that are preferred a priori. According to \\cite{Goodfellow-et-al-2016}, the prior often expresses a preference for models that are simpler or more smooth. Critics of the Bayesian method often point their fingers at the prior distribution, and criticize it for being a subjective component that can affect the predictions of the model. According to \\cite{neal2012bayesian} Bayesian methods often do a lot better than a frequentist model, when training data is limited in availability, but suffers from high computational cost when the number of training examples are large. \n\\\\\n\\\\\n\\cite{neal2012bayesian} and \\cite{mackay1991} argues that Bayesian models embodies Occam's Razor, which is the principle that we should prefer simpler models to complex ones. This principle is a component often found in machine learning since a too complex model might overfit the data. This belief is justified when model parameters are estimated by maximum likelihood, but \\cite{neal2012bayesian} argues that one should not limit the complexity of Bayesian neural networks to prevent overfitting. The approach of training by minimizing loss might lead to a choice of model with increasing complexity the more data that is available. With a Bayesian approach adjusting the complexity of the model based on the amount of data available makes no sense, since a correct prior and model for 10 observations must be correct for 10.000 observations as well. One might however switch to a simple model if it seems unlikely that a complex computational expensive model will provide significant benefit. \n\\\\\n\\\\\nAs mentioned earlier, in many practical examples, the posterior distribution is intractable and therefore must be derived in some other way. Often we will use methods such as Monte Carlo to approximate the posterior distribution. \n\n\\subsection{Maximum a Posteriori (MAP) Estimation}\nA way to avoid the computational hurdle of approximating the entire Bayesian posterior, is to use a point estimate as an approximation. Instead of turning completely to frequentist methods and use MLE, one can still benefit of the Bayesian method, by allowing the prior to influence the choice of the point estimate. One way to do this, is to use the maximum a posteriori (MAP) point estimate. The MAP estimate is obtained by maximizing the posterior distribution\n\\begin{equation}\\label{eq: MAP}\n  \\begin{split}\n        \\hat{\\boldsymbol{\\theta}}_{\\text{MAP}}&=\\argmax_{\\boldsymbol{\\theta}}{p(\\boldsymbol{\\theta}\\mid \\boldsymbol{X},\\boldsymbol{y}})=\\argmax_{\\boldsymbol{\\theta}}{p(\\boldsymbol{y}\\mid \\boldsymbol{X},\\boldsymbol{\\theta}}) p(\\boldsymbol{\\theta})\\\\\n        &=\\argmax_{\\boldsymbol{\\theta}}{\\log p(\\boldsymbol{y}\\mid \\boldsymbol{X},\\boldsymbol{\\theta}})+ \\log p(\\boldsymbol{\\theta})\n  \\end{split}\n\\end{equation}\nnote that the evidence term has been omitted, since it does not depend on the parameter $\\boldsymbol{\\theta}$ and thus vanishes under maximization anyway. The bottom part of equation \\ref{eq: MAP} can be recognized as an equation consisting of the standard log-likelihood term plus a log-prior term. \\\\\n\\\\\nAs an example, consider a model with a Gaussian prior placed on the regression weights $\\boldsymbol{\\theta}$. If we specifically choose the prior to be given by $\\mathcal{N}\\left(\\boldsymbol{\\theta},0,\\frac{1}{\\alpha}\\boldsymbol{I}^2\\right)$, then the log-prior term in equation \\ref{eq: MAP} is proportional to the L2 norm introduced in \\ref{eq:L2_reg}, plus a term that does not depend on $\\boldsymbol{\\theta}$.\nNote also that the MAP estimate is the same as the MLE, when choosing a uniform prior, since the $p(\\boldsymbol{\\theta})$ becomes a constant function in equation \\ref{eq: MAP} and consequently we can ignore it when maximizing the expression. Compared to MLE, MAP estimation has the advantage that it can benefit from the information in the prior that cannot be found in the dataset. According to \\cite{Goodfellow-et-al-2016} this additional information, gained from the choice of prior, can reduce the variance in the MAP point estimate in direct comparison with MLE estimate, but this advantage has a price of an increased bias.\n\\\\\n\\\\\nMAP is closely related to Bayes optimal estimation, instead of finding the most probable hypothesis (set of parameters), it aims at finding the most probable label for a new example. The Bayes optimal estimation is done by predicting the $\\boldsymbol{y}^{(n+1)}$, which maximizes the posterior predictive distribution in equation \\ref{eq:post_pred_distribution}. We do not pursue the idea of Bayes optimal estimation, as we aim to minimize a loss function which is not always equivalent to predicting the most probable label. In this way we preserve the idea that the loss function dictates how much the algorithm should care about making certain predictions as explained in \\ref{sec:loss_func}.\n\\\\\n\\\\\nAn obvious disadvantage from using MAP estimation, is that it discards the information contained in the distribution. It is estimating distributions that make Bayesian methods attractive, especially if one wants to evaluate the uncertainty of the parameters. As we value access to this distribution higher than faster computational time we will not pursue MAP estimation any further.\n\n\\section{Monte Carlo Methods}\\label{sec:MC_methods}\nOne way of approximating intractable integrals, like the posterior predictive distribution in equation \\ref{eq:post_pred_distribution}, is to use Monte Carlo methods. The idea behind Monte Carlo methods is to view the integral as an expectation of some random variable with respect to a probability distribution $p(\\cdot)$. In the case of BNNs our random variable is the model parameters $\\boldsymbol{\\theta}$, and we can write the posterior predictive distribution as\n\\begin{equation}\n    \\begin{split}\n        &p\\left(\\boldsymbol{y}^{(n+1)} \\mid \\boldsymbol{x}^{(n+1)}, \\lr{\\boldsymbol{x}^{(1)},\\boldsymbol{y}^{(1)}}, \\ldots, \\lr{\\boldsymbol{x}^{(n)}, \\boldsymbol{y}^{(n)}}\\right)\\\\\n        &=\\int p\\left(\\boldsymbol{y}^{(n+1)} \\mid \\boldsymbol{x}^{(n+1)}, \\boldsymbol{\\theta}\\right) p \\lr{\\boldsymbol{\\theta} \\mid \\lr{\\boldsymbol{x}^{(1)}, \\boldsymbol{y}^{(1)}}, \\ldots, \\lr{\\boldsymbol{x}^{(n)}, \\boldsymbol{y}^{(n)}}} \\, d \\boldsymbol{\\theta}\\\\\n        &=\\int f\\lr{\\boldsymbol{\\theta}}\\hat{p}\\lr{\\boldsymbol{\\theta}} d\\boldsymbol{\\theta}\n    \\end{split}\n\\end{equation}\nwhere we use a simpler notation of $\\hat{p}\\lr{\\boldsymbol{\\theta}}$ to denote the posterior distribution. Such an integral can be interpreted as an expectation taking under the probability distribution $\\hat{p}(\\boldsymbol{\\theta})$ \n\\begin{equation*}\n    s=\\int f(\\boldsymbol{\\theta})\\hat{p}(\\boldsymbol{\\theta})  d \\boldsymbol{\\theta}=\\mathbb{E}_{\\hat{p}}[f(\\boldsymbol{\\theta})]\n\\end{equation*}\nNow in order to approximate $s$ we can draw samples from the distribution $\\hat{p}(\\boldsymbol{\\theta}) $ and approximate the expected value by the empirical average. If we draw $n$ samples $\\boldsymbol{\\theta}\\sim \\hat{p}(\\boldsymbol{\\theta})$ we can approximate $s$ by $\\hat{s}_n$\n\\begin{equation}\\label{eq:empirical_mean_MC}\n        \\hat{s}_{n}=\\frac{1}{n} \\sum_{i=1}^{n} f\\left(\\boldsymbol{\\theta}^{(i)}\\right)\n\\end{equation}\nThis implies the simplest situation, where it is possible to simulate directly from the probability distribution, which is often not possible.\n\\\\\n\\\\\nWe can justify this approximation theoretically, by noticing that $\\hat{s}_n$ is an unbiased estimator of $s$\n\\begin{equation*}\n    \\mathbb{E}_{\\hat{p}}\\left[\\hat{s}_{n}\\right]=\\frac{1}{n} \\sum_{i=1}^{n} \\mathbb{E}_{\\hat{p}}\\left[f\\left(\\boldsymbol{\\theta}^{(i)}\\right)\\right]=\\frac{1}{n} \\sum_{i=1}^{n} s=s\n\\end{equation*}\nadditionally the law of large numbers, states that if the samples $\\boldsymbol{\\theta}^{(i)}$ are independent and identical distributed (i.i.d), the empirical average converges to the true expectation almost surely\n\\begin{equation*}\n    \\lim _{n \\rightarrow \\infty} \\hat{s}_{n}=s\n\\end{equation*}\nthis only holds if the variance of the individual terms $\\operatorname{Var}[f\\lr{\\boldsymbol{\\theta}^{(i)}}]$ is bounded. To see this, we note that $\\operatorname{Var}[\\hat{s}_n]$ converges to zero as n goes to infinity, if and only if $\\operatorname{Var}[f\\lr{\\boldsymbol{\\theta}}]<\\infty$\n\\begin{equation*}\n    \\begin{split}\n\\operatorname{Var}\\left[\\hat{s}_{n}\\right] &=\\operatorname{Var}\\left[\\frac{1}{n} \\sum_{i=1}^{n} f(\\boldsymbol{\\theta}^{(i)})]\\right] \\\\ &=\\frac{1}{n^{2}} \\sum_{i=1}^{n} \\operatorname{Var}[f(\\boldsymbol{\\theta}^{(i)})]\n=\\frac{\\operatorname{Var}[f(\\boldsymbol{\\theta})]}{n}\n\\end{split}\n\\end{equation*}\nFurther the central limit theorem states that, if $\\mathbb{E}_{\\hat{p}}[f(\\boldsymbol{\\theta})]=s$ and $\\operatorname{Var}[f(\\boldsymbol{\\theta})]<\\infty$ then\n\\begin{equation*}\n    \\frac{\\hat{s}_{n}-s}{\\sqrt{\\operatorname{Var}[f(\\boldsymbol{\\theta})] / n}} \\sim \\mathcal{N}(0,1)\n\\end{equation*}\nwhich is equivalent to\n\\begin{equation*}\n    \\hat{s}_n\\sim \\mathcal{N}\\left(s,\\frac{\\operatorname{Var}[f(\\boldsymbol{\\theta})]}{n}\\right)\n\\end{equation*}\nWhich gives us a way of estimating confidence intervals around the estimate $\\hat{s}$. \\\\\n\\\\\nWhen it is infeasible or not possible to make simulations of $\\boldsymbol{\\theta}$ directly, Markov chain Monte Carlo methods can be used. such methods simulate from a target distribution by running a Markov chain, that eventually will converge to target distribution. Markov chain Monte Carlo methods will be examined more thoroughly in section \\ref{sec:MCMC}.\n\n\n\n\\section{A Simple Bayesian Neural Network} \\label{sec:simple_BNN}\nA simple example, inspired by \\cite{neal2012bayesian}, will illustrate the general concept of Bayesian learning for neural networks and the inefficiency of brute force methods of sampling. Figure \\ref{fig:simple_BNN} shows six BNNs whose weights and biases were drawn from independent standard normal prior distributions except output weights, which had a standard deviation of $\\frac{1}{\\sqrt{16}}$. The networks performs regression on six data points. \n\\\\\n\\\\\nThe six networks was chosen from a larger pool of $10^5$ networks with weights and biases sampled from identical prior distributions. The likelihood was computed for each of these networks and scaled so that the largest likelihood was 1. The networks were then accepted with the probability of this scaled likelihood for which only six was accepted. This approach resembles rejection sampling and embodies the posterior from equation \\ref{eq:posterior} by making the prior control the generation of candidate networks and the likelihood control which of these candidates are rejected.\nWe follow the suggestion of \\cite{neal2012bayesian} to model regression tasks with a conditional distribution for the real valued targets $\\boldsymbol{y}_k$, from $k$ neural networks with outputs $f_k(\\boldsymbol{x})$, defined by a Gaussian distribution\n\\begin{equation}\\label{eq:regr_taget_distribution}\n    p(\\boldsymbol{y} \\mid \\boldsymbol{x}) = \\prod_k \\frac{1}{\\sqrt{2 \\pi} \\sigma_k} \\exp{- \\frac{\\lr{f_k(\\boldsymbol{x}) - y_k}^2}{2 \\sigma_k^2}}\n\\end{equation}\nwith mean $f_k(\\boldsymbol{x})$ and standard deviation $\\sigma_k$ as a hyperparameter, which we choose to be $\\sigma_k = 0.1$ for all $k$.\n\\\\\n\\\\\nAccording to \\cite{neal2012bayesian} the optimal way to predict the target associated with various new examples, assuming we want to minimize the expected squared error, is to predict the mean of the predictive distribution in equation \\ref{eq:post_pred_distribution}. For a regression model defined by equation \\ref{eq:regr_taget_distribution} this is equal to predicting \n\\begin{equation*}\n    \\hat{\\boldsymbol{y}}^{(n+1)} = \\int f\\lr{\\boldsymbol{x}^{(n+1)}, \\boldsymbol{\\theta}} p\\lr{\\boldsymbol{\\theta} \\mid \\lr{\\boldsymbol{x}^{(1)}, \\boldsymbol{y}^{(1)}}, \\dots, \\lr{\\boldsymbol{x}^{(n+1)}, \\boldsymbol{y}^{(n+1)}}} \\, d \\boldsymbol{\\theta}\n\\end{equation*}\nAs we do not know this distribution, we resort to a Monte Carlo approximation by averaging over the outputs from the six neural networks, obtained by sampling parameters from the posterior. The average is shown in figure \\ref{fig:simple_BNN} by the solid line. But Bayesian inference can do more than a single-valued guess. By examining the function we can also see the uncertainty of the guesses, for example how rapidly uncertainty increases beyond the region of the data points. \n\\\\\n\\\\\nThis illustrates some of the benefits of using Bayesian inference for neural networks, but what remains is the downside of computational time. Generating $10^5$ samples to get six draws from the posterior is not very efficient and this only becomes more infeasible as the number of data points increase. \n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{pics/figure_simple_BNN.pdf}\n    \\caption{Sampled neural networks from a posterior predictive distribution that is based on a Gaussian prior and a Gaussian likelihood on the six data points. The average prediction of the networks are plotted along with a filled area defined by the average plus minus the standard deviation of the network predictions to represent uncertainty. The Python code for implementing this Bayesian neural network and the production of this figure can be seen in appendix \\ref{app:simple_BNN}}\n    \\label{fig:simple_BNN}\n\\end{figure}\n\\clearpage\n\\section{Markov Chain Monte Carlo}\\label{sec:MCMC}\n As mentioned in section \\ref{sec:bayesian_stat} the posterior distribution is often intractable and we might need simulation based methods to find a feasible solution. We want to be able to calculate posterior summaries like $\\mathbb{E}_{\\hat{p}}\\left[f(\\boldsymbol{\\theta})\\right]$ where $f(\\boldsymbol{\\theta})$ is some function over the parameters and the expectation is taken under the posterior distribution. Such an expectation is straightforward to approximate using the simple Monte Carlo method, described in section \\ref{sec:MC_methods}, when dealing with nice and low dimensional distributions. Other methods like importance sampling has often been proposed in the litterateur for simple problems, but rarely for high-dimensional problems as we often face with neural networks.\n \\\\\n \\\\\nThe simple example in section \\ref{sec:simple_BNN} illustrated that brute force methods are also not very useful in complex models like BNNs and we are instead motivated to use a collection of more sophisticated methods. This thesis will mainly pursue this motivation by exploring the Markov chain Monte Carlo (MCMC) methods. The main idea is to simulate a Markov chain, which has the posterior distribution as its stationary distribution. We will initially give a concise explanation of the fundamentals of Markov chains in section \\ref{sec:basic_mc} and follow this by exploring the most popular MCMC algorithms for sampling in BNNs.\n \n \n\\subsection{Markov Chains}\\label{sec:basic_mc}\nA stochastic process is a set of random variables that are defined over some probability space $\\left\\{X^{(t)} \\right\\}_{t\\in T}$, where $T\\subseteq \\mathbb{R}$ is the indexation and may be interpreted as a time index. In the context of machine learning, the set $T$ can be interpreted as the iterations of a simulation scheme. In stochastic simulation we typically have that $T=\\mathbb{N}$ and we can write the stochastic process as $\\left\\{X^{(n)}\\right\\}_{n\\geq 0}$, where $n$ reminds us that we have a discrete index set. Throughout this thesis we will only consider discrete time stochastic processes, since this is found to be most relevant when discussing stochastic simulation. \\\\\nA stochastic process is defined over a space of possible values called the state space $\\mathbb{S}$ and will in most applications be either integers or real values. \n\\\\\n\\\\\nWith the objective of modelling BNNs, we want to sample model parameters from the posterior distribution. These samples will then be used to make predictions for unseen data by approximating the posterior predictive distribution from equation \\ref{eq:post_pred_distribution} via Monte Carlo integration. In order to do this using MCMC we will consider the stochastic process $\\{\\boldsymbol{\\theta}^{(n)}\\}_{n\\geq 0}$. To make the description of MCMC methods more general in the next sections, we will denote the distribution we aim to sample from the target distribution and denote it $\\hat{p}(\\cdot)$. The target distribution in the case of BNNs is the posterior of the weights such that $\\hat{p}(\\boldsymbol{\\theta})\\equiv p(\\boldsymbol{\\theta}\\mid \\boldsymbol{X},\\boldsymbol{y})$.\n\\\\\n\\\\\nUsing Markov chain Monte Carlo we aim to sample from a stochastic process satisfying the Markov property. Such a process is defined by being dependant only on the previous state of the process and a set of transitional probabilities, or densities for a infinite state space, and is called a Markov chain. The Markov chain is defined by an initial distribution for the first state of the chain $\\boldsymbol{\\theta}^{(0)}$, and a transition density for the next states in the system. We write the transition density from transitioning from state $\\boldsymbol{\\theta}^{(n-1)}$ to another state $\\boldsymbol{\\theta}^{(n)}$ as $T(\\boldsymbol{\\theta}^{(n)}\\mid \\boldsymbol{\\theta}^{(n-1)})$. \\\\\n\\\\\nWhen sampling from the Markov chain we want to make sure that samples are actually coming from the desired distribution $\\hat{p}(\\boldsymbol{\\theta})$ no matter the initial distribution. To ensure this we must generate a Markov chain that has our desired distribution  $\\hat{p}\\lr{\\boldsymbol{\\theta}}$ as a stationary distribution. That is if $\\boldsymbol{\\theta}^{(n-1)}$ has distribution $\\hat{p}(\\cdot)$, then  $\\boldsymbol{\\theta}^{(n)}$ will have the same distribution, and this will hold for all future states of the chain. The property of a Markov chain having a stationary distribution is called the invariance property and is defined by\n\\begin{equation*}\n    \\pi(\\boldsymbol{\\theta}^{(n)})=\\int T(\\boldsymbol{\\theta}^{(n)}\\mid \\boldsymbol{\\theta}) \\pi(\\boldsymbol{\\theta})d\\boldsymbol{\\theta}\n\\end{equation*}\nA sufficient, but not necessary condition, that ensures that a particular $\\hat{p}(\\boldsymbol{\\theta})$ is stationary distribution is the detailed balance condition. The condition states if we let $T(\\cdot,\\cdot)$ be a transition density, which satisfies the following condition \n$$T(\\boldsymbol{\\theta}^{(n-1)}, \\boldsymbol{\\theta}^{(n)}) \\hat{p}(\\boldsymbol{\\theta}^{(n)})= T(\\boldsymbol{\\theta}^{(n)}, \\boldsymbol{\\theta}^{(n-1)})\\hat{p}(\\boldsymbol{\\theta}^{(n-1)})$$\nthen $\\hat{p}(\\cdot)$ is a stationary distribution of the Markov chain associated with the transition density $T(\\cdot,\\cdot)$. This property however only ensures that $\\hat{p}\\lr{\\boldsymbol{\\theta}}$ is stationary distribution but not that it is the only one, meaning that our Markov chain can end up sampling from the wrong distribution, even though it satisfies the detailed balance condition.\n\\\\\n\\\\\nTo guarantee that we sample from $\\hat{p} \\lr{\\boldsymbol{\\theta}}$ we need to ensure that the Markov chain has only this distribution as a stationary distribution. A Markov chain which has a unique stationary distribution, from which it converges to, from any initial state is called an ergodic Markov chain (see e.g \\cite{turkman2019computational}). For a Markov chain on a finite state space to be ergodic, it has to be irreducible and aperiodic. The same goes for a Markov chain on a infinite state space, but a slightly stronger condition called Harris recurrence is needed, see \\cite{gamerman2006markov}.                                   \n\\\\\n\\\\\nOften we discard or burn some of the initial states, since these may not be representative of the desired distribution, as the chain might not have reached the stationary distribution yet. These discarded steps are part of what is called the  burn-in period of the Markov chain. When the chain has reached the stationary distribution, it is possible to draw as many identical distributed samples as we wish for, but one should note that any successive samples will be highly correlated with each other and therefore not necessarily a good representative for the target distribution. \\cite{Goodfellow-et-al-2016} suggest a way to mitigate this problem, by only returning every $n$ successive sample. Because of both the burn-in period and the time required for the chain to return uncorrelated samples MCMCs are often computational expensive. \\\\\n\\\\\nIn order to produce truly independent samples, \\cite{Goodfellow-et-al-2016} suggest to run multiple Markov chains in parallel. They also mention that practitioners often chooses the number of chains to run in parallel, similar to the number of examples in a mini-batch and then draw the samples needed from this set of Markov chains. \n\n\n\\subsection{The Metropolis algorithm} \\label{sec:Metropolis}\nThe Metropolis algorithm is a MCMC method, which is used to sample from a distribution. \nThe Metropolis algorithm was originally introduced by \\cite{Metropolis1953} and was developed to simulate the states for a system of molecules. This was later further developed by \\cite{hastings70}, so that the algorithm could now simulate from a general distribution and not just a symmetric one, as it was previously based on. The Metropolis algorithm is an attractive MCMC method due to its versatility and simplicity.\\\\\n\\\\\nThe algorithm considers a target distribution $\\hat{p}(\\boldsymbol{\\theta})$ and a proposal distribution $q(\\boldsymbol{\\theta})$. The algorithm generates a Markov chain, by starting the chain at some arbitrarily point generated from the proposal distribution $\\boldsymbol{\\theta}^{(0)}\\sim q(\\boldsymbol{\\theta})$ and then proposing a candidate state for the next state in the chain $\\boldsymbol{\\theta}^{\\text{\\text{cand}}}$, where this candidate state is drawn from the conditional distribution on the previous state $\\boldsymbol{\\theta}^{\\text{\\text{cand}}}\\sim q(\\boldsymbol{\\theta}^{(n+1)}\\mid\\boldsymbol{\\theta}^{(n)})$. The next step is to decide whether or not to reject this new state based on the relative density to the old state. If the relative density is larger than one, we accept the new state, if the relative density is less than one, we accept the new state with probability $\\frac{\\hat{p}(\\boldsymbol{\\theta}^{\\text{\\text{cand}}})}{\\hat{p}(\\boldsymbol{\\theta}^{(n)})}$. In this context the Metropolis algorithm imposes the symmetry condition of on the proposal distribution, so that\n\\begin{equation*}\n    q(\\boldsymbol{\\theta}^{(n)}\\mid \\boldsymbol{\\theta}^{(n-1)})=q(\\boldsymbol{\\theta}^{(n-1)}\\mid \\boldsymbol{\\theta}^{(n)})\n\\end{equation*}\nA pseudocode version of the Metropolis algorithm can be seen in algorithm \\ref{algo_2}.\n% Metropolis Algorithm\n\\begin{algorithm}\\label{algo_2}\n\n\\SetAlgoLined\n\\KwInput{A proposal distribution $q$}\n\\KwOutput{A set of parameters $\\boldsymbol{\\theta^{(n)}}$ for $n = 1, \\dots, N$}\ninitialize $\\boldsymbol{\\theta}^{(0)}\\sim q(\\boldsymbol{\\theta})$;\n\n\\For{$n=1,2,\\ldots, N$}{\nPropose: $\\boldsymbol{\\theta}^{\\text{\\text{cand}}} \\sim q\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right)$\n\nAcceptance Probability:\n\n$ \\alpha\\left(\\boldsymbol{\\theta}^{\\text{\\text{cand}}} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right)=\\min \\left\\{1, \\frac{\\hat{p}\\left(\\boldsymbol{\\theta}^{\\text{\\text{cand}}}\\right)}{ \\hat{p}\\left(\\boldsymbol{\\theta}^{(n-1)}\\right)}\\right\\} $\n\n$u \\sim  \\text { Uniform }(0,1)\n$\n\n  \\uIf{$u<\\alpha$}{\n    Accept the proposal: $\\boldsymbol{\\theta}^{(n)} \\leftarrow \\boldsymbol{\\theta}^{\\text{\\text{cand}}}$\\;\n  }\n  \\Else{\n    Reject the proposal: $\\boldsymbol{\\theta}^{(n)} \\leftarrow \\boldsymbol{\\theta}^{(n-1)}$ \\;\n  }\n    }\n\\caption{Metropolis algorithm}\n\\end{algorithm}\nOne apparent problem is that due to the evidence term we can not calculate the posterior exactly, which is our target distribution $\\hat{p}\\lr{\\boldsymbol{\\theta}}$, so we can not directly calculate $\\frac{\\hat{p}(\\boldsymbol{\\theta}^{(n)})}{\\hat{p}\\left(\\boldsymbol{\\theta}^{(n-1)}\\right)}$. \nBut a nice property of Metropolis acceptance probability is that we only need a function that is proportional to the posterior, as any constant of proportionality will cancel out in the calculation of the acceptance probability. As the evidence term can be interpreted as a constant of proportionality, it will cancel out and we can instead use equation \\ref{eq:posterior} and calculate the ratio of the likelihood times the prior, which we are often able to.   \n\\\\\n\\\\\nTo show that the Metropolis algorithm is in fact sampling from the target distribution, we must show that the Markov chain converges to a stationary distribution which is our target distribution. If we assume that the Markov Chain is ergodic we can do this by showing that the metropolis satisfies the detailed balanced condition explained in section \\ref{sec:MCMC}.\\\\\n\\\\\nFor $\\boldsymbol{\\theta}^{(n)}\\neq \\boldsymbol{\\theta}^{(n-1)}$ the Metropolis algorithm has the following transitions densities,\n\\begin{equation*}\n    T\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right)=q\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right) \\min \\left(1, \\frac{\\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right)}{ \\hat{p}(\\boldsymbol{\\theta}^{(n-1)})}\\right)\n\\end{equation*}\nWe can show that this satisfies the detailed balanced condition by\n\\begin{equation*}\n\\begin{aligned}\nT\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right) \\hat{p}(\\boldsymbol{\\theta}^{(n-1)}) &=q\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right) \\min \\left(1,\\frac{ \\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right) }{ \\hat{p}(\\boldsymbol{\\theta}^{(n-1)})}\\right) \\hat{p}(\\boldsymbol{\\theta}^{(n-1)}) \\\\\n&=q\\left(\\boldsymbol{\\theta}^{(n)} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right) \\min \\left(\\hat{p}(\\boldsymbol{\\theta}^{(n-1)}), \\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right)\\right) \\\\\n&=q\\left(\\boldsymbol{\\theta}^{(n-1)} \\mid \\boldsymbol{\\theta}^{(n)}\\right) \\min \\left(\\hat{p}\\left(\\boldsymbol{\\theta}^{(n-1)}\\right), \\hat{p}(\\boldsymbol{\\theta}^{(n-1)})\\right) \\\\\n&=q\\left(\\boldsymbol{\\theta}^{(n-1)} \\mid \\boldsymbol{\\theta}^{(n)}\\right) \\min \\left(1, \\frac{\\hat{p}(\\boldsymbol{\\theta}^{(n-1)}) }{ \\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right)}\\right) \\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right) \\\\\n&=T\\left(\\boldsymbol{\\theta}^{(n-1)} \\mid \\boldsymbol{\\theta}^{(n)}\\right) \\hat{p}\\left(\\boldsymbol{\\theta}^{(n)}\\right)\n\\end{aligned}\n\\end{equation*}\nThis shows that the transitions proposed by the algorithm leaves the target distribution $\\hat{p}(\\boldsymbol{\\theta})$ invariant and therefore samples produced by this Markov chain all has the same stationary distribution $\\hat{p}(\\boldsymbol{\\theta})$, provided that the Markov chain is ergodic. However according to \\cite{neal2012bayesian} the Metropolis algorithm will not always produce an ergodic Markov chain and that this depends on the details of the target distribution and proposal distribution. If the produced Markov chain is not ergodic we might end up sampling from a stationary distribution that is not our target distribution.\n\\\\\n\\\\\nThere are many possible choices for the proposal distribution. \\cite{neal2012bayesian} mentions that a simple choice could be a Gaussian centered on $\\boldsymbol{\\theta}^{(n)}$ with standard deviation chosen so that the acceptance probability of the candidate state is reasonably high, since a very low acceptance ratio is usually unwanted, as many rejections means that we are inefficiently wasting computation time. He also notes that when sampling from high-dimensional and complex distributions, which is often the case with posteriors in BNNs, the standard deviation of such a proposal distribution will often have to be small compared to the extent of the target distribution, as large changes almost certainly will lead to a region of low probability. This will result in highly dependant states and many steps will be needed to arrive at distant points in the distribution. As suggested in section \\ref{sec:basic_mc} one way of coping with this problem is to throw away some of the samples or run multiple chains in parallel. \\\\\n\\\\\n\\cite{neal2012bayesian} further mentions that this problem with Metropolis is made worse due to its movements taking the inefficient form of a random walk instead of a systematic path, as can be seen in the illustration of a sampling with Metropolis in figure \\ref{fig:MH_sampling}. This inefficient movement yields slower convergence to the target distribution. This drawback, will be even more prominent in higher dimension and for more complex target distributions according to \\cite{gelmanbda04}. \\\\\n\\\\\nA more generalized version of the algorithm is the one introduced by \\cite{hastings70}, which allows for non-symmetric proposal distributions $q(\\boldsymbol{\\theta}^{(n)}\\mid \\boldsymbol{\\theta}^{(n-1)}) \\neq q(\\boldsymbol{\\theta}^{(n-1)}\\mid \\boldsymbol{\\theta}^{(n)})$. To correct for this asymmetry in the proposal distribution, the acceptance ratio is replaced by\n\\begin{equation}\\label{eq: hasti_pasti}\n\\alpha\\left(\\boldsymbol{\\theta}^{c a n d} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right)=\\min \\left\\{1, \\frac{q\\left(\\boldsymbol{\\theta}^{(n-1)} \\mid \\boldsymbol{\\theta}^{c a n d}\\right) \\hat{p}\\left(\\boldsymbol{\\theta}^{c a n d}\\right)}{q\\left(\\boldsymbol{\\theta}^{c a n d} \\mid \\boldsymbol{\\theta}^{(n-1)}\\right) \\hat{p}\\left(\\boldsymbol{\\theta}^{(n-1)}\\right)}\\right\\} \n\\end{equation}\nOne should note that the Metropolis algorithm is an instance of the generalized version, since equation \\ref{eq: hasti_pasti} is identical to the acceptance ratio in the original algorithm when allowance for a symmetric distribution. \\\\\n\\\\\nThe introduction of an asymmetric proposal distribution, is often useful when we want to increase the speed of the random walk generated by the Metropolis algorithm. However, this is often not sufficient for complicated models with high-dimensional target distributions as we face with Bayesian neural networks, see \\cite{gelmanbda04}.\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth, height=\\textheight, keepaspectratio]{pics/mh_randomWalk_behavior.pdf}\n    \\caption{Illustration of the convergence to a target distribution with 300 samples from the Metropolis algorithm. The target distribution is a bivariate Gaussian with mean \n        $\\boldsymbol{\\mu}= \\begin{bmatrix}\n            0 & 0\n            \\end{bmatrix}$ and covariance matrix\n            $\\boldsymbol{\\Sigma}= \n            \\begin{bmatrix}\n                1 & 0.6\\\\\n                0.6 & 1   \n            \\end{bmatrix}$. The Python code for producing this figure can be found in appendix \\ref{app:MH_code}.\n    }\n    \\label{fig:MH_sampling}\n\\end{figure}\n\\clearpage\n\n\\section{Hamiltonian Monte Carlo}\\label{sec:HMC}\nAnother way to generate proposals with a higher efficiency, is by updating the parameters by dynamical simulation and then use the Metropolis algorithm to accept or reject these proposals. Such an algorithm suppress the local random walk behavior and allow it to move faster and more rapidly through the target distribution. This method is called Hamiltonian 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 computational statistics when it was used for Bayesian neural networks in \\cite{neal2012bayesian}. This means that the Markov chain from which we sample in BNNs is produced analogous to paths of particles using Hamiltonian dynamics, and we will explain these dynamics using this physical analogy, as it gives a more intuitive idea of HMC.\n\\\\\n\\\\\nIt turns out that the HMC algorithm reduces correlation between successive sampled states, compared to the Metropolis Hastings algorithm in section \\ref{sec:Metropolis}, by proposing moves to distant states of the target distribution, which maintain a high probability of acceptance due to the properties of the simulated Hamiltonian dynamics. The reduced correlation imply that fewer Markov chain samples are needed to approximate integrals with respect to the target probability distribution.\n\n\\subsection{Hamiltonian Dynamics}\nBefore we move to the actual HMC algorithm, we will explain the Hamiltonian dynamics from which we produce the Markov chain for the algorithm. The Hamiltonian dynamics are used to describe how an object move around in a system or space. It is defined by the objects position $\\boldsymbol{q}\\in \\mathbb{R}^d$ and its momentum $\\boldsymbol{\\rho}\\in \\mathbb{R}^d$, which in the field of physics is equivalent to an object's mass times its velocity at some point in time. When performing HMC to generate samples from the target distribution $\\hat{p}(\\boldsymbol{\\theta})$, the position variable plays the role of the parameter vector and we will from now on let $\\boldsymbol{\\theta}\\equiv \\boldsymbol{q}$. The object's position is associated with a potential energy $U(\\boldsymbol{\\theta})$ and  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 often called the Hamiltonian\n\\begin{equation*}\nH(\\boldsymbol{\\theta},\\boldsymbol{\\rho})=U(\\boldsymbol{\\theta})+K(\\boldsymbol{\\rho})    \n\\end{equation*}       \nAn important property of the Hamiltonian is that it conserves the sum of the potential and kinetic energy, meaning 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}\nfor $i=1,2, \\ldots,d$. These are named Hamiltonian equations and represent a differential equations system. The Hamiltonian equations are 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 variables of the object at any point in the future $t^\\prime>t$. \\cite{neal2012bayesian} shows that these dynamics, along with the energy conserving property of the Hamiltonian, results in the process being reversible and preserving volume of the state space, which in turn provides a stationary distribution. \n\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 we have to approximate the differential equations which is done by discretizing time. We do this by splitting the time interval $dt$ into smaller intervals $\\varepsilon$. \n\\\\\n\\\\\nThe usual discretizing scheme for simulating Hamiltonian equations, is the Leapfrog method. The Leapfrog method takes a half step to update momentum variable then a whole step to update the position value, and finally the last half step to update momentum\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 the HMC properties of being reversible and preserve volume of the state space, ensuring that we sample from a stationary distribution.\n\n\n\\subsection{The Hamiltonian and Probability Distributions}\nWe have now explained what a Hamiltonian is and how we can simulate its dynamics by using the Leapfrog method. We will now connect this to MCMC theory from the previous sections in order to explain how to use HMC to sample from the posterior of the parameters in a BNN. In order to perform this connection, we need to relate the target distribution and the Hamiltonian, such that we can use the Hamiltonian equations to sample from the target distribution. A way of doing this, proposed by \\cite{neal2012bayesian}, is to use a concept from statistical mechanics known as the canonical (Boltzmann) distribution. We can write a probability distribution on $\\boldsymbol{\\theta}$ under the canonical distribution as\n\\begin{equation*}\n    p(\\boldsymbol{\\theta})\\propto \\exp\\left(\\frac{-E(\\boldsymbol{\\theta})}{T}\\right)\n\\end{equation*}\nwhere $E(\\boldsymbol{\\theta})$ can be any energy function defined over $\\boldsymbol{\\theta}$. $T$ is often called the temperature of the system and usually chosen to be equal to 1 as it plays no role in this application, see \\cite{neal2012bayesian}.\nOne should note that any probability distribution that is nowhere zero can be put into this form by letting $E(\\boldsymbol{\\theta})=-\\log p(\\boldsymbol{\\theta})-\\log Z$, for any convenient choice of normalization constant $Z$. Since the Hamiltonian is an energy function for the joint state of both position and momentum, a joint distribution can be defined by\n\\begin{equation*}\np(\\boldsymbol{\\theta},\\boldsymbol{\\rho})\\propto \\exp(-\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho}))   = \\exp(-U(\\boldsymbol{\\theta}))\\exp(-K(\\boldsymbol{\\rho}))\n\\end{equation*}\nAssuming Independence between $\\boldsymbol{\\theta}$ and $\\boldsymbol{\\rho}$ we can by the equation above write $U(\\boldsymbol{\\theta})=-\\log p(\\boldsymbol{\\theta})$ and $K(\\boldsymbol{\\rho})=-\\log p(\\boldsymbol{\\rho})$ meaning that the Hamiltonian can be interpreted as the log joint distribution on $(\\boldsymbol{\\theta},\\boldsymbol{\\rho})$. \n\\\\\n\\\\\nWe now have a joint distribution, in terms of the Hamiltonian function, which we know how to simulate from. But we are in fact only interested in samples of the position variable $\\boldsymbol{\\theta}$, which is samples from our target distribution, and not samples from the momentum variable $\\boldsymbol{\\rho}$, which is only introduced to make the algorithm move faster through the parameter space. This means that we can choose the marginal distribution of the momentum arbitrarily. This is often chosen by practitioners to be Gaussian, $\\boldsymbol{\\rho}\\sim \\mathcal{N}\\left(0, \\boldsymbol{\\Sigma} \\right)$, where $\\boldsymbol{\\Sigma}$ is some symmetric, positive-definite covariance matrix and often chosen to be diagonal, such that $\\boldsymbol{\\rho}$ is $d$-dimensional multivariate Gaussian, with the $d$ variables being independent. We follow the simple approach from \\cite{hoffman2011nouturn} and let $\\boldsymbol{\\Sigma}$ be the identity matrix $\\boldsymbol{I}$. This makes the dynamics of equation \\ref{eq:hamilton_equations} simplify to \n\\begin{equation*}\n\\begin{split}\n\\frac{d \\theta_{i}}{d t}&=\\rho_i \\\\\n\\frac{d \\rho_{i}}{d t}&=\\frac{\\partial \\log p(\\theta_{i})}{\\partial \\theta_i} \n\\end{split}\n\\end{equation*}\nA more rigorous examination of possible choices for the covariance matrix is provided by \\cite{neal2012mcmc}. \n\n\n\n\\subsection{The Hamiltonian Monte Carlo Algorithm}\nWe start the HMC algorithm from an initial state $\\lr{\\boldsymbol{\\theta}^{(0)},\\boldsymbol{\\rho}^{(0)}}$, and then we simulate the Hamiltonian dynamics for $t+\\varepsilon$ using the Leapfrog method. The states generated for the position and momentum variables at the end of the Leapfrog simulation is used as proposals for a new state $(\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}})$. These states needs to be accepted according to a criterion, because the leapfrog-discretization provides an error term in its approximation of the continuous Hamiltonian dynamics. This criterion is the Metropolis acceptance criterion,\n\\begin{equation}\\label{eq:hmc_acceptance}\n\\begin{split}\n    \\alpha\\left((\\boldsymbol{\\theta},\\boldsymbol{\\rho}) \\mapsto (\\boldsymbol{\\theta}^{\\text{cand}} , \\boldsymbol{\\rho}^{\\text{cand}} )\\right) &= \\min\\left\\{1, \\frac{p(\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}})}{p(\\boldsymbol{\\theta},\\boldsymbol{\\rho})} \\right\\}\\\\\n    &= \\min\\{1,\\exp\\left(\\log p(\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}})- \\log p(\\boldsymbol{\\theta}, \\boldsymbol{\\rho})  \\right)\\\\\n    &= \\min \\left\\{1,\\exp\\left(-\\H(\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}}) +\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho})\\right) \\right\\}\n\\end{split}\n\\end{equation}\nThis means that we follow the same logic as in the Metropolis algorithm, but use distributions provided by the Hamiltonian dynamics. With $\\boldsymbol{\\rho}\\sim \\mathcal{N}\\left(0,\\boldsymbol{I}\\right)$ this is equivalent to\n\\begin{equation*}\n\\alpha\\left((\\boldsymbol{\\theta},\\boldsymbol{\\rho}) \\mapsto (\\boldsymbol{\\theta}^{\\text{cand}} , \\boldsymbol{\\rho}^{\\text{cand}} )\\right) \n=\\min\\left\\{1,\\frac{\\exp\\left(\\mathcal{L}(\\boldsymbol{\\theta}^{\\text{cand}})-\\frac{1}{2}\\boldsymbol{\\rho}^{\\text{(cand)}^\\top}\\boldsymbol{\\rho}^{\\text{(cand)}}\\right)}{\\exp\\left(\\mathcal{L}(\\boldsymbol{\\theta})-\\frac{1}{2}\\boldsymbol{\\rho}^\\top\\boldsymbol{\\rho}\\right)}\\right\\}\n\\end{equation*}\nwhere $\\mathcal{L}\\left(\\boldsymbol{\\theta}\\right)$ is the log-probability distribution on $\\boldsymbol{\\theta}$.\n\\\\ \n\\\\\nWe see from the last part in equation \\ref{eq:hmc_acceptance} that if we could perfectly discretize the Hamiltonian dynamics, the Metropolis acceptance criterion would always be equal to 1 due to the energy conservation property of the Hamiltonian. Since this is usually not possible, the Metropolis acceptance criterion will often be lower than 1. We can see that if we get a small error in the discretization the term  $\\H(\\boldsymbol{\\theta},\\boldsymbol{\\rho})-\\H(\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}})$ in the exponent should be small, yielding a high acceptance rate. This way of making proposals is beneficial since it allows the Markov chain to effectively make large and uncorrelated moves in the state space, while keeping a high acceptance probability. HMC is written in pseudocode in algorithm \\ref{alg:HMC}. It takes in an initial value for the parameters $\\boldsymbol{\\theta}^{(0)}$, which is the starting point of the algorithm. The input $\\mathcal{L}$ is the log-probability distribution of $\\boldsymbol{\\theta}$, which is defined to be equal to the negative potential energy function. In BNN this is identical to the log-posterior distribution on the neural network parameters. One need to be able to at least evaluate the posterior distribution and its gradient or alternatively something proportional to it. In our case where the target distribution is the posterior distribution, we know that it is proportional to the likelihood times the prior, which we in most cases are able to evaluate. The $M$ input is the number of total iterations one would like to perform.\n\\\\\n\\\\\nThe algorithm also relies on a stepsize $\\varepsilon$ variable, that defines the size of the leapfrog step. If $\\varepsilon$ is chosen too be too large, the leapfrog simulation of the Hamiltonian will be inaccurate and lead to a very low rate of acceptance making the algorithm ineffectively waste of computational time. On the other hand, if we choose $\\varepsilon$ to be too small, we will waste computational time by taking too small steps. The sampling is also affected by a hyperparameter $L$, that defines how many leapfrog steps the algorithm performs before proposing a new candidate state. A very small value for $L$ will give successive samples that lie close to each other which results in the same undesirable random walk behavior as the Metropolis algorithm from section \\ref{sec:Metropolis}. Too large a value for $L$ might produce trajectories that loop back and retrace their steps, a behavior called U-turns. This behavior results in the algorithm inefficiently wasting time, sampling from the same area of the distribution again and again. Tuning these parameters can be hard and one are often forced to rely on heuristics based preliminary runs, see \\cite{neal2012mcmc}.\n\\\\\n\\\\\nIn figure \\ref{fig:HMC_Example} we have illustrated how HMC propose a candidate sample for a bivariate $\\mathcal{N}\\left(\\boldsymbol{0},\\boldsymbol{I}\\right)$ target distribution. In subfigure (a) and (b) we have chosen a proper value for $\\varepsilon$ and $L$ such that the algorithm generates proposals that are appropriately far from the previous ones. In subfigure (c) and (d) we have chosen larger values for $\\varepsilon$ and $L$, and we can see that the algorithm starts to loop-back, which results in identical proposals for each iteration and a large proportion of the target distribution will therefore never be visited. In the next section we will look into a modification of the HMC algorithm, so that we can avoid this kind of U-turn behavior.  \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=\\textwidth]{pics/HMC_Example.png}\n    \\caption{A simulation example with HMC for a bivariate Gaussian target distribution with $\\boldsymbol{\\mu}= \\begin{bmatrix}\n            0 & 0\n            \\end{bmatrix}$ and covariance matrix\n            $\\boldsymbol{\\Sigma}= \n            \\begin{bmatrix}\n                1 & 0\\\\\n                0 & 1   \n            \\end{bmatrix}$. Subfigure (a) and (b) shows a HMC simulation example with a proper choice for $\\varepsilon$ and $L$, where the target distribution is thoroughly explored. Subfigure (c) and (d) is the same example, modified with a poor choice of values for $\\varepsilon$ and $L$, where the target distribution is poorly approximated. This is especially clear on the plots of the marginal distributions where the histograms are far from the plotted correct distribution. The result is the U-Turn effect, which yield an ineffective exploration of the target distribution. The example has been generated with the interactive gallery provided by \\cite{feng} \\textcopyright MIT.}\n    \\label{fig:HMC_Example}\n\\end{figure}\n\n\\begin{algorithm}\\label{alg:HMC}\n\\SetAlgoLined\n\\SetKwFunction{Leapfrog}{Leapfrog}\n\\KwInput{An intial parameter $\\boldsymbol{\\theta}^{(0)}$}\n\\KwInput{A log-probability distribution $\\mathcal{L}$}\n\\KwInput{Total number of iterations $M$}\n\\KwInput{Size of leapfrog-steps $\\varepsilon$}\n\\KwInput{Number of leapfrog-steps before generating candidate state, $L$.}\n\\KwOutput{Set of accepted parameters}\n\n$\\text{Given } \\boldsymbol{\\theta}^{(0)},  \\mathcal{L}, M, \\varepsilon, L,$\\\\\n\\For{m=1,2 \\dots, M}{\nSample $\\boldsymbol{\\rho}^{(0)} \\sim \\mathcal{N}(0, \\boldsymbol{\\boldsymbol{I}})$ \\\\\nSet $ \\boldsymbol{\\theta}^{\\text{cand}} \\leftarrow \\boldsymbol{\\theta}^{(m-1)}, \\boldsymbol{\\rho}^{\\text{cand}} \\leftarrow \\boldsymbol{\\rho}^{(0)}$\\\\\n\\For{i = 1 to L}{\nSet $\\boldsymbol{\\theta}^{\\text{cand}}, \\boldsymbol{\\rho}^{\\text{cand}} \\leftarrow \\Leapfrog(\\boldsymbol{\\theta}^{\\text{cand}}, \\boldsymbol{\\rho}^{\\text{cand}}, \\varepsilon)$\n}\nNegate momentum: $\\boldsymbol{\\rho}^{\\text{cand}} \\leftarrow - \\boldsymbol{\\rho}^{\\text{cand}}$\\\\\nCompute acceptance probability:\\\\\n$\\alpha=\\min \\left\\{1, \\frac{\\exp \\left\\{\\mathcal{L}(\\boldsymbol{\\theta}^{\\text{cand}})-\\frac{1}{2} \\boldsymbol{\\rho}^{\\text{(cand)}^\\top}  \\boldsymbol{\\rho}^{\\text{cand}}\\right\\}}{\\exp \\left\\{\\mathcal{L}\\left(\\boldsymbol{\\theta}^{(m-1)}\\right)-\\frac{1}{2} \\boldsymbol{\\rho}^{(0)^\\top}  \\boldsymbol{\\rho}^{(0)}\\right\\}}\\right\\}$\\\\\nSample $u\\sim \\text{Uniform}(0,1)$\\\\\n \\uIf{$u<\\alpha$}{\n    Accept the proposal: $\\boldsymbol{\\theta}^{(m)} \\leftarrow \\boldsymbol{\\theta}^{c a n d}$\\\\\n  }\n  \\Else{\n    Reject the proposal: $\\boldsymbol{\\theta}^{(m)} \\leftarrow \\boldsymbol{\\theta}^{(m-1)}$ \\\\\n  }\n}\n\\SetKwProg{Fn}{Function}{:}{\\KwRet{$\\boldsymbol{\\theta}^{\\text{cand}},\\boldsymbol{\\rho}^{\\text{cand}}$}}\n\\Fn{\\Leapfrog{$\\boldsymbol{\\theta}$, $\\boldsymbol{\\rho}$, $\\varepsilon$}}{\n Set $\\boldsymbol{\\rho}^{\\text{cand}} \\leftarrow \\boldsymbol{\\rho}^{\\text{cand}}+(\\varepsilon / 2) \\nabla_{\\theta} \\mathcal{L}(\\theta)$\\\\\nSet $\\boldsymbol{\\theta}^{\\text{cand}} \\leftarrow \\theta+\\varepsilon \\boldsymbol{\\rho}^{\\text{cand}}$\\\\\nSet  $\\boldsymbol{\\rho}^{\\text{cand}} \\leftarrow \\boldsymbol{\\rho}\n^{\\text{cand}}+(\\varepsilon / 2) \\nabla_{\\theta} \\mathcal{L}(\\boldsymbol{\\theta}^{\\text{cand}})$\n  }\n\\caption{Hamiltonian Monte Carlo}\n\\end{algorithm}\n\n\n\n\n\\clearpage\n\\subsection{No-U-Turn Hamiltonian Monte Carlo}\\label{sec:nuts}\nIn this section we present an algorithm introduced by \\cite{hoffman2011nouturn} and evaluated by \\cite{nishio_arakawa_nouturn}, whose explanation we found more clear and concise. No-U-Turn (NUTS) extends HMC by eliminating the need to specify the trajectory length $L$. This algorithm gets its name by avoiding the possible U-Turning behavior shown in figure \\ref{fig:HMC_Example} (c) and (d). This is done by introducing a criterion that tells us when to stop simulating the dynamics to prevent a possible U-turn. The authors define this criterion to be when performing another leapfrog step will no longer increase the distance between the proposed state $\\boldsymbol{\\theta}^{\\text{cand}}$ and the initial value $\\boldsymbol{\\theta}^{(0)}$. More specifically, they choose a criterion, based on the derivative with respect to time of half the squared distance between the initial parameter $\\boldsymbol{\\theta}^{(0)}$ and the current state $\\boldsymbol{\\theta}^{\\text{cand}}$, meaning that leapfrog steps are performed until \n\\begin{equation*}\n\\begin{split}\n    \\frac{d}{d t} \\frac{(\\boldsymbol{\\theta}^{\\text{cand}}-\\boldsymbol{\\theta})^\\top \\cdot(\\boldsymbol{\\theta}^{\\text{cand}}-\\boldsymbol{\\theta})}{2}&=(\\boldsymbol{\\theta}^{\\text{cand}}-\\boldsymbol{\\theta})^\\top \\cdot \\frac{d}{d t}(\\boldsymbol{\\theta}^{\\text{cand}}-\\boldsymbol{\\theta})\\\\\n    &=(\\boldsymbol{\\theta}^{\\text{cand}}-\\boldsymbol{\\theta})^\\top \\cdot \\boldsymbol{\\rho}^{\\text{cand}} < 0\n\\end{split}\n\\end{equation*}\nHowever, \\cite{hoffman2011nouturn} notes that by doing this we do not have the guarantee of time reversibility, so the sampling algorithm might not converge to the correct distribution. NUTS overcomes this problem by using slice sampling and applying a double method suggested by \\cite{neal_slice_sampling}. \n\\\\\n\\\\\nNUTS augments the distribution of HMC, $p \\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}} \\propto \\exp{\\left(\\mathcal{L} \\lr{\\boldsymbol{\\theta}} - \\frac{1}{2} \\boldsymbol{\\rho}^\\top \\boldsymbol{\\rho}\\right)}$, to include a slice variable $u$ so that the joint probability of $\\boldsymbol{\\theta}, \\boldsymbol{\\rho}$ and $u$ is \n\\begin{equation*}\n    p \\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}, u} \\propto \\mathbf{1} \\lrs{ u \\in \\lrs{0,\\exp{\\left(\\mathcal{L} \\lr{\\boldsymbol{\\theta}} - \\frac{1}{2} \\boldsymbol{\\rho}^\\top \\boldsymbol{\\rho}\\right)}}}\n\\end{equation*}\nmeaning that the un-normalized marginal probability of $\\boldsymbol{\\theta}$ and $\\boldsymbol{\\rho}$ (gained by integrating over $u$) is \n\\begin{equation*}\n    p \\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}} \\propto \\exp{\\left(\\mathcal{L} \\lr{\\boldsymbol{\\theta}} - \\frac{1}{2} \\boldsymbol{\\rho}^\\top \\boldsymbol{\\rho}\\right)}\n\\end{equation*}\nThe conditional probabilities $p \\lr{u \\mid \\boldsymbol{\\theta}, \\boldsymbol{\\rho}}$ and $p \\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho} \\mid u}$ are each uniform as long as the condition\n\\begin{equation} \\label{eq:nuts_unif_condition}\n    u \\leq \\exp{\\left(\\mathcal{L} \\lr{\\boldsymbol{\\theta}} - \\frac{1}{2} \\boldsymbol{\\rho}^\\top \\boldsymbol{\\rho}\\right)}\n\\end{equation}\nis satisfied. The challenge of slice sampling is to find the bounds of the region for which this condition is satisfied. \\cite{neal_slice_sampling} proposes a doubling method, where the size of the initial segment containing the current value of $\\boldsymbol{\\theta}$ is randomly chosen and afterwards expanded by doubling its size until the samples are outside of the region. The expanding directions are randomly chosen to be leapfrog steps forward or backward in the Markov chain to satisfy reversibility.\n\\\\\n\\\\\nNUTS generates a finite set of all $\\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}}$ by iteratively doubling its size. The doubling process is stopped to satisfy the condition \n\\begin{equation*}\n    \\lr{\\boldsymbol{\\theta}^+ - \\boldsymbol{\\theta}^-}^\\top \\boldsymbol{\\rho}^- < 0 \\quad \\text{or} \\quad \\lr{\\boldsymbol{\\theta}^- - \\boldsymbol{\\theta}^+}^\\top \\boldsymbol{\\rho}^+ < 0\n\\end{equation*}\nwhere $\\boldsymbol{\\theta}^+, \\boldsymbol{\\rho}^-$ and $\\boldsymbol{\\theta}^+, \\boldsymbol{\\rho}^-$ is the leftmost and rightmost variables of all $\\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}}$ generated by the doubling process respectively. \n\\\\\n\\\\\nA subset of proposal candidates $\\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}}$, denoted by $\\mathbb{C}$, is selected from the doubling process to satisfy the condition in equation \\ref{eq:nuts_unif_condition}. The new values of $\\lr{\\boldsymbol{\\theta}^*, \\boldsymbol{\\rho}^*}$ are then afterwards sampled uniformly from $\\mathbb{C}$. \n\\\\\n\\\\\nTo further improve this algorithm \\cite{hoffman2011nouturn} used the following transition kernel in each step of doubling\n\\begin{equation*}\n\\resizebox{\\textwidth}{!}{$\nT\\left(\\boldsymbol{\\theta}^{*}, \\boldsymbol{\\rho}^{*} \\mid \\boldsymbol{\\theta},\\boldsymbol{\\rho}, \\mathbb{C}\\right)=\\begin{cases} \\frac{\\mathbf{1}\\left[\\boldsymbol{\\theta}^{*}, \\boldsymbol{\\rho}^{*} \\in \\mathbb{C}^{\\text{new}}\\right]}{\\left|\\mathbb{C}^{\\text{new}}\\right|} & \\text{  when } \\left|\\mathbb{C}^{\\text{new}}\\right|>\\left|\\mathbb{C}^{\\text{old}}\\right|\\\\\n\\frac{\\left|\\mathbb{C}^{\\text{new}}\\right|}{\\left|\\mathbb{C}^{\\text{old}}\\right|} \\frac{\\mathbf{1}\\left[\\boldsymbol{\\theta}^{*}, \\boldsymbol{\\rho}^{*} \\in \\mathbb{C}^{\\text{new}}\\right]}{\\left|\\mathbb{C}^{\\text{new}}\\right|}+\\left(1-\\frac{\\left|\\mathbb{C}^{\\text{new}}\\right|}{\\left|\\mathbb{C}^{\\text{old}}\\right|}\\right) \\mathbf{1}\\left[\\left(\\boldsymbol{\\theta}^{*}, \\boldsymbol{\\rho}^{*}\\right)=(\\boldsymbol{\\theta}, \\boldsymbol{\\rho})\\right] \n&\\text{  when } \\left|\\mathbb{C}^{\\text{new}}\\right|\\leq\\left|\\mathbb{C}^{\\text{old}}\\right|\n\\end{cases}$\n}\n\\end{equation*}\nwhere $\\mathbb{C}^{\\text{new}}$ is the subset of $\\lr{\\boldsymbol{\\theta}, \\boldsymbol{\\rho}}$, added by the last step of the doubling process and $\\mathbb{C}^{\\text{old}}$ is the disjoint subset of $\\mathbb{C}$ so that $\\mathbb{C} = \\mathbb{C}^{\\text{new}} \\cup \\mathbb{C}^{\\text{old}}$. This transition kernel proposes a move from a state in $\\mathbb{C}^{\\text{old}}$ to a random state in $\\mathbb{C}^{\\text{new}}$ and accepts this move with probability $\\frac{\\mathbb{C}^{\\text{new}}}{\\mathbb{C}^{\\text{old}}}$. The authors show that $T$ satisfies the detailed balance condition so that it leaves the uniform distribution over $\\mathbb{C}$ invariant. According to \\cite{nishio_arakawa_nouturn} this transitional kernel permits memory-efficient implementation and produces larger jumps on average than simple uniform sampling. \n\\\\\n\\\\\nNUTS is especially efficient as it can automatically choose a step size that achieves an acceptance probability around a desired level. The stepsize $\\varepsilon$ for the $j$th iteration of a NUTS Markov chain is tuned as follows\n\\begin{equation*}\n    \\begin{split}\n        \\log\\lr{\\varepsilon_{j+1}} &= \\mu - \\frac{\\sqrt{j}}{\\gamma} \\frac{1}{j + j_0} \\sum_{i=1}^j \\lr{\\delta - \\alpha_i}\\\\\n        \\log \\lr{\\bar{\\varepsilon}_{j+1}} &= \\eta_j \\log \\lr{\\varepsilon_{j+1}} + \\lr{1 - \\eta_j} \\log \\lr{\\bar{\\varepsilon}_j} \\\\\n        \\varepsilon_{j+1} &= \\bar{\\varepsilon}_{j+1}\n    \\end{split}\n\\end{equation*}\nwhere $\\alpha_j$ is an actual acceptance probability for the $j$th iteration, $\\delta$ is the desired average acceptance probability, $\\mu$ is a freely chosen point that the iterated $\\varepsilon_j$ shrinks towards, $\\gamma$ is a free parameter that controls the shrinkage amount towards $\\mu$ and $j_0$ is a free parameter that dampens early exploration. \n\\\\\n\\\\\n\\cite{hoffman2011nouturn} introduces the variables $\\eta_j = j^{-\\kappa}$ with $\\kappa < 1$ to give more recent iterates more weight. They show that this way of adapting stepsize guarantees that $\\alpha \\rightarrow \\delta$. They recommend setting $\\mu = \\log \\lr{10 \\varepsilon_1}$ and $\\delta \\approx 0.6$.\n\\\\\n\\\\\nNUTS tunes $\\varepsilon$ during a predetermined warm-up phase and fixes this value thereafter. Since the algorithm accepts or rejects $\\lr{\\boldsymbol{\\theta}^*, \\boldsymbol{\\rho}^*}$ from multiple candidates, an alternative statistic to the Metropolis acceptance probability must be defined. They do this by defining for each iteration the acceptance probability by\n\\begin{equation*}\n    \\alpha_{j}=\\frac{1}{\\left|B_{j}\\right|} \\sum_{\\boldsymbol{\\theta}, \\boldsymbol{\\rho} \\in B_{j}} \\min \\left\\{1, \\frac{p\\left(\\boldsymbol{\\theta}^{j}, \\boldsymbol{\\rho}^{j}\\right)}{p\\left(\\boldsymbol{\\theta}^{j-1}, \\boldsymbol{\\rho}^{j, 0}\\right)}\\right\\}\n\\end{equation*}\nThe pseudocode for NUTS can be seen in algorithm \\ref{alg:nuts}.\n\n\\begin{algorithm} \\label{alg:nuts}\n    \\SetAlgoLined\n    \\KwInput{Initial parameters $\\boldsymbol{\\theta}^{(0)}$}\n    \\KwInput{A log-probability distribution $\\mathcal{L}$}\n    \\KwInput{Initial size of leapfrog-steps $\\bar{\\varepsilon_0}$}\n    \\KwInput{Desired average of acceptance probability $\\delta$}\n    \\KwInput{Aim point for values of the iterated $\\varepsilon_j$ values $\\mu$}\n    \\KwInput{Parameter controlling shrinkage towards $\\mu$, $\\gamma$}\n    \\KwInput{Parameter that controls dampening of early exploration $j_0$}\n    \\KwInput{Parameter that controls how much more weight are given to more recent iterates $\\kappa < 1$}\n    \\KwInput{Total number of total number of iterations $J$}\n    \\KwInput{Total number of iterations for adapting size of leapfrog steps $J^{\\text{adapt}}$}\n    \\KwOutput{Samples from the target distribution}\n    \\For{j=0, \\dots,  J}{\n    Sample momentum $\\boldsymbol{\\rho}^{\\text{init}} \\sim N(0, \\boldsymbol{I})$\\\\\n    Sample auxiliary variable $u \\sim \\operatorname{Uniform}\\left(0, \\exp \\left(\\mathcal{L}\\left(\\boldsymbol{\\theta}^{(j)}\\right)-\\frac{1}{2}\\boldsymbol{\\rho}^{\\text{init}^{\\top}} \\boldsymbol{I}^{-1} \\boldsymbol{\\rho}^{\\text{init}}\\right)\\right)$\\\\\n    Generate $\\mathbb{C}$ by using the doubling method with transition kernel $T$. \\\\\n    Compute acceptance probability: $\\alpha_{j}=\\frac{1}{\\left|B_{j}\\right|} \\sum_{\\theta, \\boldsymbol{\\rho} \\in B_{j}} \\min \\left\\{1, \\frac{p\\left(\\boldsymbol{\\theta}^{j+1}, \\boldsymbol{\\rho}^{j+1}\\right)}{p\\left(\\boldsymbol{\\theta}^{j}, \\boldsymbol{\\rho}^{\\text{init}}\\right)}\\right\\}$\\\\\n     Accept the proposal $\\left(\\boldsymbol{\\theta}^{*}, \\boldsymbol{\\rho}^{*}\\right)$ with probability $\\alpha_{j}$. \\\\\n    \\uIf{$j\\leq J^{\\text{adapt}}$}{\n        $\\log\\lr{\\varepsilon_{j+1}} \\leftarrow \\mu - \\frac{\\sqrt{j}}{\\gamma} \\frac{1}{j + j_0} \\sum_{i=1}^j \\lr{\\delta - \\alpha_i}$\\\\\n        $\\log \\lr{\\bar{\\varepsilon}_{j+1}} \\leftarrow j^{-\\kappa}\\log \\lr{\\varepsilon_{j+1}} + \\lr{1 - j^{-\\kappa}} \\log \\lr{\\bar{\\varepsilon}_j}$ \\\\\n        $\\varepsilon_{j+1} \\leftarrow \\bar{\\varepsilon}_{j+1}$\n    }\n    \\Else{\n    $\\varepsilon_{j+1}=\\varepsilon_{J^{\\text{adapt}}}$\n    }    \n    }\n     \\caption{No-U-Turn Sampler with Dual Averaging. One can easily change this pseudocode to one that runs until a certain number of samples are collected. For a more detailed pseudocode see \\cite{hoffman2011nouturn}.}\n\\end{algorithm}\n\n\n\n\\clearpage\n\\section{Priors}\\label{sec:priors}\nFrom section \\ref{sec:bayesian_stat} and the example given in section \\ref{sec:simple_BNN} it is seen that Bayesian inference starts with a prior for the model parameters, which is supposed to embody ones prior beliefs about the assigned task. The prior is an important component and choosing a bad prior can affect the resulting posterior greatly. That said, the prior does have a diminishing effect on the posterior as the number of samples grow, as the likelihood will concentrate the posterior around a few highly likely parameters. One might think that if one has no qualified prior belief, then a weak prior, like a wide uniform distribution, can be a safe bet, but this can however have various unforeseen consequences as pointed out by \\cite{lemoine2019} and \\cite{sarma_kay2020}. \\\\\n\\\\\nThe prior component is however more than a dangerous element that threatens the quality of the posterior. The prior provides a principled mechanism for researchers to incorporate previous research and knowledge into the model. Priors can also be beneficial in small sample sizes as the prior acts to regularize and reduce the chances of overfitting.\nAlthough in neural networks the relationship between parameters and the problem can be very abstract and not as intuitive as in other machine learning models like linear regression models or support vector machines, so having qualified prior beliefs about the weights might not be so easy. \n\\\\\n\\\\\n\\cite{neal2012bayesian} stresses that even though it can seem like BNNs can be threatened by a lack of a suitable prior this is not the case, as much past work shows useful criteria for selecting suitable priors, even without full understanding of what the prior over the parameters will mean in terms of the output of the network. \\cite{mackay1991} and \\cite{MacKay1992} has produced results, that \\cite{neal2012bayesian} describes as at least reasonable, by giving the parameters Gaussian prior distributions. He lets the standard deviation of these distributions be selected as a hyperparameter, which allows the model to adapt to the data. \n\\\\\n\\\\\nAccording to \\cite{neal2012bayesian}, our prior knowledge will often be too unspecific to fix the parameter values chosen for the prior distribution, even if we have complete insight into their effects on the prior. We may then wish to treat these values as unknown hyperparameters, giving them a higher-level broad prior distribution, which we call a hyper-prior. \\cite{neal2012bayesian} refers to these as Hierarchical models. One benefit of such models is that the appropriate degree of regularization for the task can be determined automatically from the data, see \\cite{mackay1991} and \\cite{MacKay1992}. \n\n\n\n\n\n\n\n", "meta": {"hexsha": "077af2d76da2477004d8fcfd3e081659956d291b", "size": 75630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bayesian_neural_networks.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": "bayesian_neural_networks.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": "bayesian_neural_networks.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": 127.5379426644, "max_line_length": 1613, "alphanum_fraction": 0.7477984927, "num_tokens": 20168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6377370293776966}}
{"text": "%!TEX root = ../gfkg.tex\n\\subsection{Chapter 1}\n\n\\begin{p}%1\n\\end{p}\n\n\\begin{p}%2\n\\end{p}\n\n\\begin{p}%3\n\\end{p}\n\n\\begin{p}%4\n\\end{p}\n\n\n\\begin{p}%{5}\n{Given a Lie group $G$, define its identity component $G_0$ to be the connected component \ncontaining the identity element. Show that the identity component of any Lie group is a subgroup, and a Lie\ngroup in its own right.}\n\\end{p}\n{Suppose we have a path from the identity to $g\\in G_0$. Now map this \npath to a new path by multiplying each element by $h\\in G_0$. This path starts at $h$ and since the mapping is continuous, must remain in $G_0$. (Otherwise, smoothly mapping the group manifold to $\\R^n$ would show a \ndiscontinuity at some point.) Thus $hg\\in G_0$ for all $h,g\\in G_0$.\n\nThere's a certain tension between having a smooth manifold with disconnected pieces --- given a map from the \nthe manifold to itself, one must take care that it does not have a discontinuous action, mapping some points in one component to another component. When this map is an element of the group, this requirement makes\n$G_0$ into a subgroup.}\n\n\n\\begin{p}%{6}\n{Show that every element of O(3) is either a rotation about some axis or a rotation about some axis followed by a reflection through some plane. Show that the former class of elements are all in the identity component of O(3), while the latter are not. Conlude that the identity component of O(3) is SO(3).}\n\\end{p}\n{Rotations preserve the inner product between vectors, so with any rotation $R$ we can transform the standard orthonormal basis $\\{e_1,e_2,e_3\\}$ to another. But $Re_1$ is just the first column of $R$, so this fact means that $R^T R=\\mathbbm{1}$. Conversely, the condition $Q^TQ=\\mathbbm{1}$ means that $Q$ can be thought of as a set of orthonormal basis elements, and the action of $Q$ on the standard basis will produce this new basis. \nThis new basis need not be a rotated version of the standard basis, however, as it could also involve reflections. This corresponds to a negative determinant as the orientation of the standard basis is not preserved. \nAany such $Q$ can be decomposed into $Q=PR$ by using a reflection operator. Let $P'$ be the reflection through\nthe plane defined by the first two standard basis vectors, i.e.~the one flipping the third standard basis vector. Clearly $QP'=R$ for some rotation $R$, since it now has a unit determinant. Then write $QP'=QP'Q^TQ=PQ$,\ndefining $P=QP'Q^T$, which is symmetric: $P^T=QP'^TQ^T=QP'Q^T=P$. Thus $Q=PR$ for some rotation $R$ and reflection $P$. All rotations are connected to the identity, since we can imagine continuously varying the rotation amount. Thus the identity-connected component is SO(3). The reflections could not be the SO(3) since\nthey do not form a subgroup; the product of two reflections is a rotation.}\n\n\\begin{p}%7\n\\end{p}\n\n\\begin{p}%{8}\n{Show that if $\\rho:G\\rightarrow H$ is a homomorphism of groups, then $\\rho(1)=1$ and $\\rho(g^{-1})=\\rho(g)^{-1}$.}\n\\end{p}\n{First, the identity and inverses in a group are unique. Suppose there were\ntwo identity elements, $e$ and $1$. Then $ge=eg=g=g1=1g$ for all $g$ and in particular $e=e1=1$, using the\nidentity properties of first $1$ and then $e$. The uniqueness of the identity implies the uniqueness of inverses,\nfor suppose $g$ had two inverses, $h$ and $k$. Then $gh=gk=hg=hk=1$ and thus $hgh=h=hgk=k$.\nNow if $\\rho$ is to be a homomorphism, then $\\rho(g)=\\rho(g1)=\\rho(g)\\rho(1)$ for all $g$, whence $\\rho(1)$ is\nthe identity. Similarly, $\\rho(1)=\\rho(gg^{-1})=\\rho(g)\\rho(g^{-1})$ for all $g$. So $\\rho(g^{-1})$ must be \nthe inverse of $\\rho(g)$, i.e.~$\\rho(g)^{-1}$.}\n\n\\begin{p}%{9}\n{A $1\\times 1$ matrix is just a number, so show that U(1)$=\\{e^{i\\theta}:\\theta\\in\\R\\}$. In physics, an element of U(1) is a called a phase. Show that U(1) is isomorphic to SO(2), with an isomorphism being given by \n\\[\\rho(e^{i\\theta})=\\left(\\begin{array}{cc}\\cos\\theta & \\sin\\theta\\\\-\\sin\\theta & \\cos\\theta\\end{array}\\right).\\]}\n\\end{p}\n{First we check if the map is a homomorphism, and then if it is bijective. For the homomorphism we need\nto show that $\\rho(e^{i\\theta})\\rho(e^{i\\phi})=\\rho(e^{i(\\theta+\\phi)})$, which follows since\n\\[\\left(\\begin{array}{cc}\\cos\\theta & \\sin\\theta\\\\-\\sin\\theta & \\cos\\theta\\end{array}\\right)\\left(\\begin{array}{cc}\\cos\\phi & \\sin\\phi\\\\-\\sin\\phi & \\cos\\phi\\end{array}\\right)=\\left(\\begin{array}{cc}\\cos(\\theta+\\phi) & \\sin(\\theta+\\phi)\\\\-\\sin(\\theta+\\phi) & \\cos(\\theta+\\phi)\\end{array}\\right).\\]\nThe map is onto, since every element in SO(2) is of the given form, for some $\\theta$. It is one-to-one since\nunless $\\theta=\\phi$, $\\rho(e^{i\\theta})\\neq \\rho(e^{i\\phi})$.}\n\n\\begin{p}%10\n\\end{p}\n\n\\begin{p}%11\n\\end{p}\n\n\\begin{p}%{12}\n{Show that for any bilinear function $f:V\\times V'\\rightarrow W$ from vector spaces $V$ and $V'$ to $W$ there exists a unique linear function $F:V\\otimes V'\\rightarrow W$ such that $f(v,v')=F(v\\otimes v')$.}\n\\end{p}\n{\nHere we're not trying to prove abstractly that the tensor product has this property; this property is the definition\nof tensor product. We want to show this property holds for the tensor product given. For the function $f$ to be\nbilinear, it must obey $f(v,v')=f(v^ie_i,v'^j e'_j)=v^iv'^jf(e_i,e'_j)$. But $v\\otimes v'=v^iv'^je_i\\otimes e'_j$, so we can just define $F$ by the action on the basis: $F(e_i\\otimes e'_j)=f(e_i,e'_j)$. This set is a linearly independent basis, since the parts are linearly independent, and so the function defined this way is unique.} \n\n\\begin{p}%13\n\\end{p}\n\n\\begin{p}%14\n\\end{p}\n\n\\begin{p}%15\n\\end{p}\n\n\\begin{p}%16\n\\end{p}\n\n\\begin{p}%17\n\\end{p}\n\n\\begin{p}%{18}\n{Show that any $2\\times 2$ matrix may be uniquely expressed as a linear combination of Pauli matrixes $\\sigma_0,\\dots,\\sigma_3$ with complex coefficients, and that the matrix is hermitian iff these coefficients are real. Show tha tthe matrix is traceless iff the coefficient of $\\sigma_0$ vanishes.}\n\\end{p}\n{A general\n$2\\times 2$ matrix $A$ has components $a_{jk}$, i.e.~in the ``standard basis'' of matrices. By direct calculation we can also represent $A$ as $\\sum_{k}c_k\\sigma_k$ for $2c_0=a_{00}+a_{11}$, $2c_3=a_{00}-a_{11}$, $2c_1=a_{01}+a_{10}$, and $2c_2=i(a_{01}-a_{10})$. Hermiticity requires\nthat the $c_j$ are real, since the $\\sigma_j$ are, which can also be seen from direct calculation. $c_0$ is half the\ntrace, so the matrix is traceless exactly when $c_0=0$.}\n\n\\begin{p}%19\n\\end{p}\n\n\\begin{p}%{20}\n{Show that the determinant of the $2\\times 2$ matrix $a+bI+cJ+dK$ is $a^2+b^2+c^2+d^2$. Show that if $a,b,c,d$ are real and $a^2+b^2+c^2+d^2=1$, this matrix is unitary. Conclude that SU(2) is the unit sphere in $\\mathbb{H}$.}\n\\end{p}\n{In the usual representation the matrix is just $\\left(\\begin{array}{cc}a-id & -ib-c\\\\ -ib+c& a+id\\end{array}\\right)$, so the determinant follows. Direct calculation reveals $MM^\\dagger=$ det$(M)\\mathbbm{1}$. Regarding the matrices $I,J,K$ as the three quaternionic units, which we can do since they obey the same algebra as the matrices, we can see that any element of SU(2) can be regarded as a point\non the quaternionic unit sphere.}\n\n\\begin{p}%{21}\n{Show that the spin-0 representation of SU(2) is equivalent to the trivial representation in which every element of the group acts on $\\mathbbm{C}$ as the identity.}\n\\end{p}\n{To construct the representations, we \nstart from the homogeneous polynomials $f(x,y)$ on $(x,y)\\in\\mathbbm{C}^2$ of degree $2j$. This is a \nvector space of dimension $2j+1$ since $x^{2j},x^{2j-1}y,\\dots y^{2j}$ forms a basis. \nNow for any $g\\in$SU(2), let $U_j(g)$ be such that $(U_j(g)f)(v)=f(g^{-1}v)$ for $v\\in\\mathbbm{C}^2$. \nIn the case of spin-0, $f(x,y)=c$ for some constant $c$. Thus $f(g^{-1}v)=c=(U_0(g)f)(v)$ \nand we must therefore have $U_0(g)f=f$.}\n\n\\begin{p}%{22}\n{Show that the spin-1/2 represenation of SU(2) is equivalent to the fundamental representation in which every element $g\\in$SU(2) acts on $\\mathbbm{C}^2$ by matrix multiplication.}\n\\end{p}\n{Here the \nhomogeneous polynomials are simply $f(x,y)=ax+by$, i.e.~elements of $\\mathbbm{C}^2$. Then regarding\n$f$ as the column vector $\\bar{f}$, $f(x,y)$ becomes the inner product $\\bar{f}^T\\cdot(x,y)$. \n$f(g^{-1}v)$ is therefore $\\bar{f}^T\\cdot g^{-1}v=(g\\bar{f})^T\\cdot v$, so $U_{1/2}(g)f=gf$.}\n\n\\begin{p}%{23}\n{Show that for any representation $\\rho$ of a group $G$ on a vector space $V$ there is a dual or \ncontragredient representation $\\rho^*$ of $G$ on $V^*$, given by \n\\[(\\rho^*(g)f)(v)=f(\\rho(g^{-1})v)\\] for all $v\\in V, f\\in V^*$. \nShow that all the representations $U_j$ of \nSU(2) are equivalent to their duals.}\n\\end{p}\n{Clearly $\\rho^*(e)=1$, so we need to show that $\\rho^*(gh)=\\rho^*(g)\\rho^*(h)$. We have $(\\rho^*(gh)f)(v)=f(\\rho((gh)^{-1})v)=f(\\rho(h^{-1}g^{-1})v)=f(\\rho(h^{-1})\\rho(g^{-1})v)=(\\rho^*(g)\\rho^*(h)f)(v).$ }\n\n", "meta": {"hexsha": "a3fc870d7a0ce9c19c43dd82605936725bbfc7da", "size": 8801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/II1.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/II1.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/II1.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": 63.7753623188, "max_line_length": 438, "alphanum_fraction": 0.6928758096, "num_tokens": 2926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110202, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.6377370264331853}}
{"text": "\\subsection{Continuum extrapolation before infinite volume limit}\n\n\\begin{figure}[!htb]\n\\scalebox{1.05}{\\input{figure/continuum-extrapolation.pgf}}\n\\caption{\n    \\label{fig:continuum-extrapolation-spectrum}\n    Continuum extrapolation of the discrete finite volume spectrum with $L=1\\,[\\mathrm{fm}]$.\n    Each column represents a different implementation of the kinetic operator, rows correspond to eigenvalues of the hamiltonian sorted by value.\n    For visualization purposes we present each second eigenvalue starting at $E_2$ ($E_0$ was used to tune the interaction and is thus constant by construction).\n    Black dots are the eigenvalues at different lattice spacings, the green band is the model averaged fit function for best parameters and the blue band parallel to the x-axis is the continuum-extrapolated energy.\n    The uncertainty is dominated by the fluctuations over models; the propagated numerical uncertainty is negligible in comparison.\n    The dashed line corresponds to the expected result obtained by computing the intersection of the zeta function $S^{\\spherical}_3$ with the phase shifts.\n    The boundary of each frame corresponds to the poles of the zeta function.\n    Different energy extrapolations in the continuum agree with zeros of the \\Luscher zeta within uncertainty.\n    For finite discretization implementations ($n_s < \\infty$), the uncertainty drastically increases with the number of excited states ($\\sim 3$ orders of magnitude from $E_2^{(n_s)}$ to $E_{20}^{(n_s)}$).\n}\n\\end{figure}\n\nAfter tuning the contact interaction to the first zero of the spherical zeta function, we compute the spectrum of the hamiltonian.\nNext, we extrapolate the obtained energy eigenvalues to the continuum $\\epsilon \\to 0$ using a polynomial fit\n\\begin{equation}\n    E^{(n_s)}_i(\\epsilon) = E_i^{(n_s)} + \\sum\\limits_{n=1}^{n_\\mathrm{max}} e_{i,n}^{(n_s)} \\epsilon^n \\, .\n\\end{equation}\nBecause the contact interaction is expected to scale linear with the momentum cutoff and thus linear in $1/\\epsilon$ (see \\eqref{three-d-counterterm}), one cannot generally expect the fit coefficients $e_{i,n}^{(n_s)}$ to be zero for odd $n$ or $n < n_s$, despite the kinetic improvement~\\eqref{gamma determination}.\nNevertheless, we would expect the small $n$ coefficient for larger $n_s$ to be relatively smaller then small $n$ coefficients for smaller $n_s$: $e_{i,n}^{(n_{s_1})} < e_{i,n}^{(n_{s_2})}$ on average for $n_{s_1} > n_{s_2}$.\n\nWe individually fit each discretization implementation to extract the continuum energies $E_i^{(n_s)}$ using the software provided by \\Ref{peter_lepage_2016_60221}.\nBecause our numerical uncertainties have an estimated relative error at the order $~10^{-13}$, we must in principle fit the energy for relatively high values of $n_\\mathrm{max}$ which would require having many data points over different scales of $\\epsilon$.\nFor this reason we add further lattice spacings\n\\begin{equation}\n\t\\left\\{\n\t\t\\epsilon \\, [\\mathrm{fm}] =\n\t\t\\frac{1}{4}, \\frac{1}{5}, \\frac{1}{10},\n\t\t\\frac{1}{15}, \\frac{1}{20}, \\frac{1}{25},\n\t\t\\frac{1}{ 30}, \\frac{1}{ 35}, \\frac{1}{ 40},\n\t\t\\frac{1}{ 41}, \\frac{1}{ 42}, \\frac{1}{ 43},\n\t\t\\frac{1}{ 44}, \\frac{1}{45}, \\frac{1}{ 46},\n\t\t\\frac{1}{ 47}, \\frac{1}{ 48}, \\frac{1}{ 49}, \\frac{1}{ 50}\n\t\\right\\}\n\t\\, .\n\\end{equation}\nHowever, we still obtain $\\chi^2_{\\mathrm{d.o.f}} \\gg 1$ up to the point where it is computationally not feasible to add new data points for even smaller lattice spacings as the dimension of the hamiltonian scales with $(L/\\epsilon)^3$.\n\nFor this reason, we have decided to fit multiple fit models over the span of $n_\\mathrm{max} = \\{2, 3, 4, 5\\}$ and compare their results to estimate a systematic extrapolation uncertainty (unweighted average and standard deviation of results over models).\nWe repeat this procedure for each discretization and compare different continuum energies to decide wether the fits are consistent.\nThese values are compared to the spectrum predicted by L\\\"uscher's formalism.\n\n\\begin{figure}[H]\n\t\\centering\n    \\scalebox{0.8}{\\input{figure/continuum-extrapolation-ere.pgf}}\n    \\caption{\n        \\label{fig:continuum-extrapolation-ere}\n        Phase shifts computed by inserting the continuum-extrapolated spectrum for different discretization implementations $n_s$ and finite volumes $L$ in the zeta function $S^{\\spherical}_3$.\n        Data points indicate locations of the eigenvalue.\n        We show the propagated error associated with continuum extrapolation as an uncertainty band.\n        The black dashed line represents physical phase shifts.\n        Bands stop at different $x$ values because we stop presenting results after uncertainties become too large (but are still consistent with the physical phase shifts).\n        }\n\\end{figure}\n\nWe present the model average over best fits of the spectrum in \\figref{continuum-extrapolation-spectrum}.\nAlso, we provide access to the raw data and fitting scripts online at \\cite{luescher-nd_201}.\nWe observe that the model average for polynomials of degree 2 up to 5 is consistent over different discretization and agrees with the expected continuum results.\nWe noted that including higher polynomials with $n_\\mathrm{max} > 6$ resulted in overfitting of higher energy levels visible in oscillating fit functions which were generally were more favorable in model selection criteria\\footnote{\n    A potential cure for overfitting of higher polynomials would have been the marginalization of higher contributions which would cast the contributions of higher neglected epsilon terms into the uncertainty of the data.\n    We eventually settled for an unweighted model average over smaller $n_\\mathrm{max}$ because the continuum-extrapolated spectrum was more consistent over different $n_s$.\n}.\nAs expected, the continuum limit becomes more uncertain for excited states.\nFurthermore, the $n_s = \\infty$ implementation provides the most precise results.\nSurprisingly a few energy levels in the $n_s = 1$ implementation have a more precise continuum limit on average than some improved implementations -- even though non-extrapolated energy values are further apart from the continuum as in the improved cases.\nThis effect is related to the continuum convergence pattern.\nWhile the $n_s = 1$ (and $n_s = \\infty$) energy values seem to converge against the continuum result from below (and respectively from above) for all excited states, the improved derivative eigenvalues change their convergence pattern.\nThe slope of the extrapolation function changes it sign from $E_2 \\to E_4$ for $n_s = 2$ and from $E_6 \\to E_8$ for  $n_s = 4$.\nThis suggests that the importance of fit model coefficients $e_{i,n}^{(n_s)}$ changes and thus makes it more difficult to perform the continuum limit.\n\nIn the next step, we use the continuum-extrapolated spectrum to convert it to phase shifts using the spherical zeta function.\nWe present the phase shifts in \\figref{continuum-extrapolation-ere}.\nIndependent of discretization scheme, we observe that the continuum-extrapolated results agree with the constant input phase shifts.\nBecause the zeta function is relatively steep, uncertainties in the continuum limit get drastically enhanced when converting to phase shifts (on average more than an order of magnitude).\nWe observe that for $x > 5$ all discretizations besides the exact-$p^2$ discretization come with significant uncertainties.\n\nWe emphasize that these findings are not unique to the unitary case, we obtain similar results for a non-zero scattering length.\nWe present data for an example non-unitarity scenario with $a_{30} = - 5$~fm in our repository \\cite{luescher-nd_201}.\n\n\\subsection{Using \\Luscher's formula before continuum extrapolation}\nNext we want to discuss what effects finite discretization artifacts have when applying L\\\"uscher's formalism to a spectrum for finite lattice spacings.\nWe insert the energy levels presented in \\figref{continuum-extrapolation-spectrum} before taking the continuum limit and present results in figure \\figref{unimproved spherical}.\n\n\\begin{figure}[H]\n\t\\centering\n    \\scalebox{0.8}{\\input{figure/ere-contact-fitted_a-inv_+0.0_zeta_spherical_projector_a1g_n-eigs_200.pgf}}\n    \\caption{\n        \\label{fig:unimproved spherical}\n        We present energy eigenvalues presented in \\figref{continuum-extrapolation-spectrum} directly inserted $S^{\\spherical}_3$--without a continuum limit.\n        In the top row we show results for $L=1.0$~fm, in bottom we show $L=2.0$~fm, while in different columns we show different discretization schemes.\n        Even though results for $n_s = 2$ seem to be close to the continuum limit result, they start to drastically oscillate for higher energies.\n        While more improved discretization schemes seem to oscillate less, they do not lay on top of the continuum result where the difference is related to the lattice spacing.\n    }\n\\end{figure}\n\n\\begin{figure}[htb]\n    \\scalebox{1.0}{\\input{figure/ere-continuum-extrapolation.pgf}}\n    \\caption{\n        \\label{fig:iv-continuum}\n        Continuum limit of different phase shift points computed by inserting finite lattice spacing eigenstates in $S^{\\spherical}_3$ (see \\figref{unimproved spherical}).\n        Each column represents a different kinetic operator and each row tracks a different eigenvalue of the discrete finite-volume hamiltonian.\n        Note that both axis have a log scale and thus on these scales, a linear trend for the phase shifts suggests that they extrapolate to zero.\n    }\n\\end{figure}\n\nWe note that the phase shifts for $x > 10$ start to oscillate wildly.\nThis is the case because energy values are close to the poles of the zeta function (close to the frame boundaries in \\figref{continuum-extrapolation-spectrum}).  With an imperfect kinetic operator, the lattice artifacts in the energy can push energy levels past a pole in the continuum zeta.  This leads to multiple interacting energy levels on a single segment of the zeta function.\n\nFurthermore it seems like the small $x$ results for $n_s = 2$ seem to be closer to the expected flat result than other discretization schemes.\nThis behavior can be explained by \\figref{continuum-extrapolation-spectrum}.\nWhile other discretization schemes for $x < 8$ monotonically converge against the continuum limit, $n_s = 2$ data points converge non-monotonically and are therefore closer to the continuum by accident.\nIn this sense it is possible to select a discretization scheme which in principle converges slower against the continuum, but has an accidental good agreement with the continuum even though it is discrete.\n\nFor small energies, better discretization schemes or small lattice spacings, we observe that the phase shifts do not oscillate and monotonically increase in $x$ with no or small curvature.\nThis non-flat $x$-dependence seems to depend less on the employed discretization scheme but certainly on the value of the lattice spacing.\nThis suggests that artifacts of the imperfect kinetic operator are negligible compared to cutoff effects of the lattice spacing itself.\nThe non-zero lattice spacing induces effective-range-like effects.\nAs we will show in the next section, this effect arises from using the continuum $S^{\\spherical}$ rather than the lattice-aware $S^{\\dispersion}$.\n\nWe visualize the continuum limit of phase shift points in \\figref{iv-continuum}.\nSimilar to the case where we first extrapolated the spectrum to the continuum and computed phase shifts afterwards, the best discretization allows to also extrapolate higher excited states to zero--visible by the linear log-log dependence of the phase shifts on epsilon.\nWe note that similar to the case where we first extrapolated the spectrum to the continuum, the extrapolation of the phase shifts seems to work best for the same discretization schemes in the same energy range.\nFor example, while we find a linear log-log scaling region in \\figref{iv-continuum} for $n_s = 2$ and $x<6$, uncertainties of the $n_s =2$ extrapolation also start to increase in \\figref{continuum-extrapolation-spectrum} after $x>6$.\nHowever the $n_s = 4$ implementation seems to be stable longer in \\figref{iv-continuum} which is related to the $x>9$ state having a relatively larger continuum extrapolation uncertainty while also being close to the continuum value.\n", "meta": {"hexsha": "6b4537883830055f7c575b8cbc8b4837dddaa7ae", "size": 12315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/three-dimensions/regular-luescher.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/three-dimensions/regular-luescher.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/three-dimensions/regular-luescher.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": 94.7307692308, "max_line_length": 383, "alphanum_fraction": 0.7751522533, "num_tokens": 2937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6376884974942032}}
{"text": "\\columnbreak\n\\section{Model Validation}\n\n% ===\n\\subsection{Stability-based Validation}\n\n\\emph{Stability:}\\enspace\nSolutions on two data sets drawn from the same source should be similar.\n\n%\\emph{(In-)Stability:} Expected (dis-)agreement of solutions from two data sets from the same source.\n\n% ===\n\\subsection{Information-theoretic Validation}\n\n\\subsubsection{Shannon's Channel Coding Thm.}\n\n\\begin{itemize}\n    \\item \\textbf{Channel:}\\enspace\n        $(\\mathcal S, \\{p(\\cdot\\mid s)\\}_{s\\in\\mathcal S} )$,\\enspace\n        $\\mathcal S$: alphabet\n        \\begin{itemize}\n            \\item $\\epsilon$-noisy binary channel:\n                $p(\\hat s\\mid s) = \\big\\{ \\substack{\n                    1-\\epsilon \\:\\:\\text{if}\\:\\: \\hat s=s \\\\\n                    \\epsilon \\phantom{1-} \\:\\:\\text{if}\\:\\: \\hat s\\neq s}$\n        \\end{itemize}\n        \\vspace{-3pt}\n    \\item \\textbf{Capacity:}\\enspace\n        \\highlight{$\\mathrm{cap} = \\max_p I(S;\\hat S)$}\n        $\\rightsquigarrow p_S(s)$\n    \\item \\textbf{$\\bm{(M,n)}$-code:}\\enspace\n        is a pair $(Enc,Dec)$\\hfill\n        $\\color{gray} \\leftarrow\\text{scr. p.87}$\\\\\\quad\n        where $M$: \\#messages, $n$: code-length\n        \\begin{itemize}\n            \\item \\textbf{Rate:}\\enspace\n                $r = \\frac{\\log_2 M}{n}$\n                $\\Leftrightarrow$ $M=\\floor{2^{nr}}$\n            \\item \\textbf{Commu. err.:}\\enspace\n                $p\\ped{err} \\coloneqq \\max\\limits_{i\\leq M}\n                \\P{ Dec(\\widehat{ Enc(i) }) \\neq i }$\n        \\end{itemize}\n\\end{itemize}\n\nGoal / \\textbf{Best code:}\\enspace\n\\highlight*{$\\lim\\limits_{n\\to\\infty} \\frac{\\log M}{n}$\\enspace s.t.\\enspace $\\lim\\limits_{n\\to\\infty} p\\ped{err} \\to 0$}\n\n\\emph{Asymptotic equiparition property (AEP):}\n\\vspace{-2pt}\n\\begin{itemize}\n    \\item $A_\\epsilon^{(n)}$:\n        Typical set of sequences $(s_1,\\ldots,s_n) \\in \\mathcal S^n$\\\\\\qquad\n        $\\abs*{-\\frac1n \\log p_{S^n} (\\bm s^n) - H[S]} < \\epsilon$\\hfill\n        $\\color{gray} \\leftarrow \\text{scr. p.89}$\n    \\item $\\P*{(\\bm S^n, \\bm{\\hat S}^n) \\in A_\\epsilon^{(n)}} \\overset{n\\to\\infty}{\\to} 1$\\hfill\n        $\\color{gray} \\leftarrow \\text{scr. p.90}$\n    \\item \\highlight{$p\\ped{err} \\leq 2^{-n(\\mathrm{cap} - 3\\epsilon -r)}$}\n        $\\overset{n\\to\\infty}{\\to} 0$\\enspace if\\enspace \\highlight{$r<\\mathrm{cap}$}\n\\end{itemize}\n\n\n\\subsubsection{Algorithm Validation}\n\n\\textbf{Assumptions:}\n\\begin{itemize}\n    \\item Exponential solution space, i.e. $\\log\\abs{\\mathcal C} = \\mathcal O(n)$\n    \\item $\\mathcal A$'s output is probabilistic, i.e. $p(\\cdot \\mid X')$\n\\end{itemize}\n\n\\emph{Ideal variant:}\n\n\\textbf{Messages:}\\enspace\n$\\mathcal M = \\brace{ X'_1, \\ldots, X'_m }$\n\\vspace{-2pt}\n\n\\textbf{Code:}\\enspace\n$X'_i \\xrightarrow{Enc_{\\mathcal A}} p(\\cdot\\mid X'_i)\n\\xrightarrow{\\mathcal{C_A}} p(\\cdot\\mid X''_i)\n\\xrightarrow{Dec_{\\mathcal A}} \\hat X$\n\\iffalse\n    \\begin{itemize}\n        \\item $Enc_{\\mathcal A}$:\\enspace\n            encodes $X'_i \\in \\mathcal M$ as $p(\\cdot\\mid X'_i)$.\n        \\item $Dec_{\\mathcal A}$:\\enspace\n            selects $\\hat X = \\arg\\max\\limits_X \\kappa(X''_i, X)$\\\\\n            whereby $\\kappa(X'', X') \\coloneqq \\sum_c p(c\\mid X'') p(c\\mid X')$\n    \\end{itemize}\n\\fi\n\n\\emph{Empirical variant:}\n\n\\textbf{Messages:}\\enspace\n$\\mathcal M = \\brace{ \\tau_1, \\ldots, \\tau_m }$\ndrawn u.a.r. from $\\mathbb T$\n\\begin{itemize}\n    \\item Require\\enspace $\\sum_\\tau p(c\\mid \\tau\\circ X') \\approx \\frac{\\abs{\\mathbb T}}{\\abs{\\mathcal C}} \\pm \\rho$\\hfill\n        $\\color{gray} \\leftarrow \\text{scr. p.95}$\n\\end{itemize}\n\\vspace{-2pt}\n\n\\textbf{Code:}\\enspace\n$\\tau_i \\xrightarrow{Enc} p(\\cdot\\mid \\tau_i \\circ X')\n\\xrightarrow{\\mathcal{C_A}} p(\\cdot\\mid \\tau_i \\circ X'')\n\\xrightarrow{Dec} \\hat\\tau$\n\\begin{itemize}\n    \\item $Enc_{\\mathcal A}$:\\enspace\n        encodes $\\tau_i \\in \\mathcal M$ as $p(\\cdot\\mid \\tau_i \\circ X')$\n    \\item $Dec_{\\mathcal A}$:\\enspace\n        selects $\\hat\\tau = \\arg\\max\\limits_{\\color{red}\\tau} \\kappa(\\tau_i \\circ X'', {\\color{red}\\tau} \\circ X')$\\\\\n        whereby \\highlight{$\\kappa(X'', X') \\coloneqq \\sum_c p(c\\mid X'') p(c\\mid X')$}\n\\end{itemize}\n\n\\emph{Asymptotic Equipartition Property (AEP):}\n\n\\textit{AEP fulfilled}\\enspace if\\enspace \\highlight*{$\\log \\kappa(X',X'') \\overset{n\\to\\infty}{\\to} \\mathcal E$}\\\\\n\\enspace whereby $\\mathcal E \\coloneqq \\E[X',X'']{\\log\\kappa(X',X'')}$\n\\begin{itemize}\n    \\item $A^{(n)}_\\epsilon$: set of $(\\epsilon,n)$-typical pairs $X', X''$\\\\\\qquad\n        $\\abs*{ \\log\\kappa(X',X'') - \\mathcal E } < \\epsilon$\n    \\item \\highlight{$p\\ped{err} \\leq P_{(n)} \\color{gray} \\text{ c.f. scr. (6.19)}$}\n        $\\overset{n\\to\\infty}{\\to} 0$ \\enspace if\\enspace \\highlight{$\\frac{\\log m}{\\log\\abs{\\mathcal C}} < I$}\\\\\n        where $I \\coloneqq \\frac{1}{\\log\\abs{\\mathcal C}} \\E[X',X'']{\\log(\\abs{\\mathcal C} \\kappa(X',X''))}$\n\\end{itemize}\n\n% ===\n\\subsection{Applications of PA}\n\n\\emph{PA:}\\enskip\n\\textit{quantifies the amount of information that algorithms extract from phenomena.}\n$\\to$ quantified by \\textbf{capacity} (max. \\# distinguishable messages that can be communicated)\n\n\\emph{Temperature:}\\enspace\n$T^\\ast = \\arg\\max_T \\kappa(X',X'')$\n\n\\emph{Cost functions:}\\enspace\nGiven $R_1(\\cdot,\\cdot),\\ldots,R_s(\\cdot,\\cdot)$\\\\\n$\\max\\limits_{\\ell\\leq s} \\kappa_\\ell(X',X'') = \\max\\limits_{\\ell\\leq s} \\frac{1}{Z_{X'} Z_{X''}} \\sum\\limits_c \\eu^{-\\frac1T R_\\ell(c,X')} \\eu^{-\\frac1T R_\\ell(c,X'')}$\n\n\\emph{Algorithms:}\\enspace\n%\\textit{here for MST (min. span. tree)}\nMany MST (min. spanning tree) algo's are \\textbf{contractive} ($\\to$ sequence of candidate sol's).\n\\\\\n\\textbf{Approximation Set Coding (ASC):}\\\\\n\\quad $p\\ap{ASC}(c\\mid X') = \\begin{cases}\n    1 / \\abs*{G_\\gamma(X')}  & \\text{if}\\enspace c\\in G_\\gamma(X') \\\\[-2pt]\n    0   & \\text{otw.}\n\\end{cases}$\\\\\n\\quad $G_\\gamma(X') \\coloneqq \\brace*{ c\\in\\mathcal C : R(c,X') - \\min\\limits_{c\\in\\mathcal C} R(c,X') \\leq \\gamma }$\n\\begin{enumerate}\n    \\item Run $\\mathcal A$ to compute $G_t^{\\mathcal A}(X')$ and $G_t^{\\mathcal A}(X'')$,\\enspace for all $t$\n    \\vspace{2pt}\n    \\item $t^\\ast = \\arg\\max\\limits_t \\kappa(X',X'')\n        = \\arg\\max\\limits_t \\frac{\\abs*{G_t^{\\mathcal A}(X') \\:\\cap\\: G_t^{\\mathcal A}(X'')}}{\\abs*{G_t^{\\mathcal A}(X')} \\:\\cdot\\: \\abs*{G_t^{\\mathcal A}(X'')}}$\n    \\item $c^\\ast \\xleftarrow{\\$\\:\\text{sample}} \\mathrm{Unif}\\paren*{G_{t^\\ast}^{\\mathcal A}(X') \\cap G_{t^\\ast}^{\\mathcal A}(X'')}$\n\\end{enumerate}\n\n\n% ===\n", "meta": {"hexsha": "87d6f242018994f29de592cfdd6559619f88cc40", "size": 6379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/09_model_validation.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/09_model_validation.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/09_model_validation.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.1194968553, "max_line_length": 169, "alphanum_fraction": 0.5983696504, "num_tokens": 2425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6376884938879734}}
{"text": "\\chapter{Milky Way diffuse background study: denoising and inpainting}\n\\label{ch_inpainting}\n\n% \\markright{Milky Way diffuse background study: denoising and inpainting}\n\nIn order to extract a  diffuse emission, we want to remove the  point sources from the data. \nAs our HSD algorithm is very close to the MCA algorithm~\\citep{starck:sta04}, an idea is to mask the most intense sources and to modify our algorithm in order to interpolate through the gaps exactly as in the MCA-Inpainting algorithm~\\citep{inpainting:abrial06}. \nThis modified algorithm can be called MS-VSTS-Inpainting algorithm.\n\nThe problem can be reformulated as a convex constrained minimization problem:\n\n\\begin{equation}\n\\label{inp_eq34}\n\\begin{split}\n\\text{Arg} \\min_{\\mathbf{X}} \\| \\mathbf{ \\Phi}^{T}\\mathbf{X}\\|_1,\n\\text{s.t.} \\\\ \\: \\left\\{\\begin{array}{c}\\mathbf{X} \\geqslant 0 , \\\\\\forall (j,k)\\in \\mathcal{M},      (\\mathbf{ \\Phi}^{T}\\Pi \\mathbf{X})_j[k]=(\\mathbf{ \\Phi}^{T} \\mathbf{Y})_j[k] , \\end{array}\\right. \n\\end{split}\n\\end{equation}\nwhere $\\Pi$ is a binary mask ($1$ on valid data and $0$ on invalid data).\n\nThe iterative scheme can be adapted to cope with a binary mask, which gives:\n\\begin{eqnarray}\n\\tilde{\\mathbf{X}} = P_{+}[\\mathbf{ X}^{(n)} + \\mathbf{ \\Phi} P_{\\mathcal{M}} \\mathbf{ \\Phi}^{T} \\Pi (\\mathbf{ Y} - \\mathbf{ X}^{(n)})] , \\\\\n\\mathbf{X}^{(n+1)} = \\mathbf{ \\Phi} \\text{ST}_{\\lambda_n}[\\mathbf{ \\Phi}\\tilde{\\mathbf{X}}] .\n\\end{eqnarray}\n\n\nThe thresholding strategy has to be adapted. Indeed, for the impainting task we need to have a very large initial threshold in order to have a very smooth image in the beginning and to refine the details progressively. We chose an exponentially decreasing threshold:\n\\begin{equation}\n\\label{eq42}\n\\lambda_{n} = \\lambda_{\\max}  (2^{(\\frac{N_{\\max} - n}{N_{\\max} - 1})} -1),n=1,2,\\cdots,N_{\\max} ,\n\\end{equation}\nwhere $\\lambda_{\\max} = \\max (\\mathbf{\\Phi}^{T}\\mathbf{X})$.\n\n\\begin{algorithm}\n\\caption{MS-VST + IUWT Denoising + Inpainting}\n\\label{alg2}\n\n\\begin{algorithmic}[1]\n\\REQUIRE $\\quad$ data $a_0:=\\mathbf{Y}$, mask $\\Pi$, number of iterations $N_{\\max}$, threshold $\\kappa$.\\\\\n\\underline{\\emph{\\textbf{Detection}}} \\\\\n\\FOR{$j=1$ to $J$}\n\\STATE Compute $a_j$ and $d_j$ using (\\ref{eq27}).\n\\STATE Hard threshold $|d_j[k]|$ with threshold $\\kappa \\sigma_j$ and update $\\mathcal{M}$.\n\\ENDFOR \\\\\n\\underline{\\emph{\\textbf{Estimation}}} \\\\\n\\STATE Initialize $\\mathbf{X}^{(0)}=0$, $\\lambda_{0} = \\lambda_{\\max}$.\n\\FOR{$n=0$ to $N_{\\max}-1$}\n\\STATE $\\tilde{\\mathbf{X}}= P_{+}[\\mathbf{ X}^{(n)} + \\mathbf{ \\Phi} P_{\\mathcal{M}} \\mathbf{ \\Phi}^{T} \\Pi(\\mathbf{ Y} - \\mathbf{ X}^{(n)})]$.\n\\STATE $\\mathbf{X}^{(n+1)} = \\mathbf{ \\Phi}^\\text{ST}_{\\lambda_n}[\\mathbf{ \\Phi}^{T}\\tilde{\\mathbf{X}}]$.\n\\STATE $\\lambda_{n+1} = \\lambda_{\\max}  (2^{(\\frac{N_{\\max} - (n+1)}{N_{\\max} - 1})} -1)$\n\\ENDFOR\n\\STATE Get the estimate $\\hat{\\mathbf{\\Lambda}} = \\mathbf{X}^{(N_{\\max})}$.\n\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\section*{Experiment}\n\nWe applied this method on simulated Fermi data where we masked the most luminous sources.\n\nThe results are on Figure~\\ref{impainting}. The MS-VST + IUWT + Inpainting method (Algorithm~\\ref{alg2}) interpolates the missing data very well. Indeed, the missing part can not be seen anymore in the inpainted map, which shows that the diffuse emission component  has been correctly reconstructed.\n\n\n\\begin{figure}[htb]\n\\centering{\n\\includegraphics[width=5.5in]{13822fg22.pdf} \n\\includegraphics[width=5.5in]{13822fg23.pdf} \n}\n\\caption{MS-VSTS - Inpainting.\n\\emph{Top}: Fermi simulated map with Poisson noise and the most luminous sources masked.\n\\emph{Bottomt}: Fermi simulated map denoised and inpainted with wavelets (Algorithm~\\ref{alg2}).\nPictures are in logarithmic scale.\n}\n\\label{impainting}\n\\end{figure}\n", "meta": {"hexsha": "f6e48576b2225a6fa9fdae367eb802fe1ee68b54", "size": 3769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/msvst_inpainting.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_isap/msvst_inpainting.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_isap/msvst_inpainting.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": 47.7088607595, "max_line_length": 299, "alphanum_fraction": 0.6914300876, "num_tokens": 1297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6376824153773226}}
{"text": "\n\\documentclass[12pt]{amsart}\n\\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.\n\\usepackage{calculational}\n\\usepackage{unitb}\n\\usepackage{amsmath}\n\\geometry{a4paper} % or letter or a5paper or ... etc\n% \\geometry{landscape} % rotated page geometry\n\n% See the ``Article customise'' template for come common customisations\n\n\\title{A Sample Unit-B Toolkit proof}\n\\author{Simon Hudon}\n\\date{} % delete this line to display the current date\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\n%%% BEGIN DOCUMENT\n\\begin{document}\n\n\\maketitle\n%\\tableofcontents\n\n%\\section{}\n\n%\\begin{theorem} \n%Any conjunctive function is monotonic\n%\\begin{assumption}\n%f.(x \\land y) ~ \\equiv~ f.x \\land f.y\n%\\end{assumption}\n%\\end{theorem}\n%\\begin{dummy}\n\\begin{calculation}\n\tf.x \\le f.y\n\\hint{=}{ $\\le$ to $=$ and $\\uparrow$ }\n\tf.x \\uparrow f.y \\,=\\, f.y\n\\hint{=}{ $f$ over $\\uparrow$ }\n\tf.(x \\uparrow y) \\,=\\, f.y\n\\hint{\\follows}{ Leibniz }\n\tx \\uparrow y \\,=\\, y\n\\hint{=}{ $\\le$ from $=$ and $\\uparrow$ }\n\tx \\le y\n\\end{calculation}\n\n\\begin{calculation}\n\tf.x\n\\hint{\\le}{ $x \\le x\\uparrow y$ }\n\tf.x \\uparrow f.y\n\\hint{=}{ $f$ over $\\uparrow$ }\n\tf.(x \\uparrow y)\n\\hint{=}{ $x \\le y$ cast as $x\\uparrow y = y$ }\n\tf.y\n\\end{calculation}\n\n%\\subsection{}\n\n\\end{document}", "meta": {"hexsha": "cb93f5f5801346b487b392616be4328578f11935", "size": 1279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tests/sample.tex", "max_stars_repo_name": "literate-unitb/literate-unitb", "max_stars_repo_head_hexsha": "0d843456dc103bb09babc5b12855435d2e10f534", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-07-27T11:05:56.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-20T14:53:33.000Z", "max_issues_repo_path": "Tests/sample.tex", "max_issues_repo_name": "unitb/literate-unitb", "max_issues_repo_head_hexsha": "0d843456dc103bb09babc5b12855435d2e10f534", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 32, "max_issues_repo_issues_event_min_datetime": "2017-06-25T03:53:02.000Z", "max_issues_repo_issues_event_max_datetime": "2017-06-25T04:28:38.000Z", "max_forks_repo_path": "Tests/sample.tex", "max_forks_repo_name": "literate-unitb/literate-unitb", "max_forks_repo_head_hexsha": "0d843456dc103bb09babc5b12855435d2e10f534", "max_forks_repo_licenses": ["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.0517241379, "max_line_length": 82, "alphanum_fraction": 0.6653635653, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6376824059516099}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section{Geometry definition of \\texttt{pyFAI}}\n\nAll dimentions are in meter and all rotation are in radians.\n\n\\texttt{pyFAI} describes the position and orientation of the detector\nby six variables, collectively called the PONI, for point of normal\nincidence. In addition, a detector calibration is provided in the\nPONI-file to convert pixel coordinates into real-space coordinates. In\nthe simplest case this is a pixel size.  \n\n\\texttt{pyFAI} uses a coordinate system where the first axis (1)  is \nvertically up (or $y$), the second axis (2) is horizontal ($x$) towards the ring\ncenter (starboard), and the third axis (3) along the beam $z$. Note that\nin this order (1,2,3) is a right-handed coordinate system, which makes\n$xyz$ in the usual order a left-handed coordinate system!\n\nThe PONI parameters are: a distance $L$, the $y$ and $x$ coordinates\nof the point of normal incidence in meters, $\\mathrm{poni}_{1,2}$, and\n3 detector rotations, $\\theta_{1,2,3}$ about the $y$, $x$ and $z$\naxes. The inversion of the $x$ and $y$ axes is due to the arrangement\nof the detector data, with $x$-rows being the ``slow'' axis and\n$y$-columns the ``fast'' axis. Extra care has to be taken with the\nsigns of the rotations when converting form this coordinate system to\nanother.\n\nThe detector rotations are taken about the origin of the coordinate\nsystem (sample position). They are represented by the rotation\nmatrices:\n\n\\begin{align}\n  \\mathrm{R}_1(\\theta_1)\n  & =\n  \\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & \\cos(\\theta_1) & \\sin(\\theta_1) \\\\\n    0 & -\\sin(\\theta_1) & \\cos(\\theta_1)\n  \\end{bmatrix}\n  \\\\\n  \\mathrm{R}_2(\\theta_2)\n  & =\n  \\begin{bmatrix}\n    \\cos(\\theta_2) & 0 & -\\sin(\\theta_2) \\\\\n    0 & 1 & 0 \\\\\n    \\sin(\\theta_2) & 0 & \\cos(\\theta_2)\n  \\end{bmatrix}\n  \\\\\n  \\mathrm{R}_3(\\theta_3)\n  & =\n  \\begin{bmatrix}\n    \\cos(\\theta_3) & -\\sin(\\theta_3) & 0\\\\\n    \\sin(\\theta_3) & \\cos(\\theta_3) & 0\\\\\n    0 & 0 & 1  \n  \\end{bmatrix}\n  \\\\\n  R(\\theta_1, \\theta_2, \\theta_3)\n  & =\n  R_3(\\theta_3) \\cdot R_2(\\theta_2) \\cdot R_1(\\theta_1)\n\\end{align}\n\nLet $P$ be a point on the detector at pixel coordinates $(d_1, d_2)$\nin units $\\mathrm{px}$. In the most simple case (in the absence of\ndistortions) these are converted into coordinates in units of meters\nby multiplication with a scaling factor ``pixel size''\n($\\mathrm{pxsize}_{1,2}$m in units of $\\mathrm{m}/\\mathrm{px}$) and\nsubsequent subtraction of an offset ($\\mathrm{poni}_{1,2}$, in units of\nmeters and yielding the coordinates $(p_1, p_2)$ in meters.\n\n\\begin{align}\n  p_1 & = \\mathrm{pxsize}_1 d_1 - \\mathrm{poni}_1 \\\\\n  p_2 & = \\mathrm{pxsize}_2 d_2 - \\mathrm{poni}_2\n\\end{align}\n\nLet $L$ be the distance from the\norigin/sample/diffractometer center of rotation. In the absence of any\ndetector rotations, $L$ is taken along $z$, $p_1$ along the $x$-axis\n(horizontal) and $p_2$ along the $y$ axis (vertical). Then, in the\n``detector coordinate system''\n\n\\begin{align}\n  P & = \\begin{bmatrix} p_1 \\\\ p_2 \\\\ L \\end{bmatrix}\n\\end{align}\n\nThe coordinates in the laboratory system are obtained by\nmultiplication with the rotation matrix $R$\n\n\\begin{align}\n  \\begin{bmatrix} t_1 \\\\ t_2 \\\\ t_3 \\end{bmatrix}\n  = &\n  R_{\\mathtt{pyFAI}}(\\theta_1, \\theta_2, \\theta_3) \\cdot P\n  \\\\\n  = &\n  R_3(\\theta_3) \\cdot R_2(\\theta_2) \\cdot R_1(\\theta_1) \\cdot\n  \\begin{bmatrix}\n    \\mathrm{pxsize}_1 d_1 - \\mathrm{poni}_1 \\\\\n    \\mathrm{pxsize}_2 d_2 - \\mathrm{poni}_2 \\\\\n    L\n  \\end{bmatrix}\n  \\\\\n  = &\n  R_3(\\theta_3) \\cdot R_2(\\theta_2) \\cdot R_1(\\theta_1)\n  \\nonumber \\\\ &\n  \\cdot\n  \\left(\n  \\begin{bmatrix}\n    \\mathrm{pxsize}_1 & 0 & 0 \\\\\n    0 & \\mathrm{pxsize}_2 & 0 \\\\\n    0 & 0 & 1\n  \\end{bmatrix}\n  \\cdot\n  \\begin{bmatrix}\n    d_1 \\\\\n    d_2 \\\\\n    0\n  \\end{bmatrix}\n  +\n  \\begin{bmatrix}\n    - \\mathrm{poni}_1 \\\\\n    - \\mathrm{poni}_2 \\\\\n    L\n  \\end{bmatrix}\n  \\right)\n  \\label{eq-tpyFAI}\n\\end{align}\n\nThe inversion is straight-forward:\n\n\\begin{align}\n  R_1(-\\theta_1)\\cdot R_2(-\\theta_2) \\cdot R_3(-\\theta_3) \\cdot\n  \\begin{bmatrix} t_1 \\\\ t_2 \\\\ t_3\n  \\end{bmatrix}\n  & =\n  \\begin{bmatrix} p_1 \\\\ p_2 \\\\ L \\end{bmatrix}\n  \\label{eq-find-alpha}\n  \\\\\n  \\begin{bmatrix}\n    t_1 \\\\ t_2 \\\\ t_3\n  \\end{bmatrix}\n  & =\n  \\begin{bmatrix}\n    A_1  \\\\ A_2 \\\\ A_3 \n  \\end{bmatrix}\n  + \\alpha\n  \\begin{bmatrix}\n    k_1 \\\\ k_2 \\\\ k_3\n  \\end{bmatrix},\n\\end{align}\nwhere $A_{1,2,3}$ are the coordinates, in the laboratory system, of\nthe scattering center (grain, sub-grain or voxel), and $k_{1,2,3}$ is\nthe direction of the scattered beam. The third line ($\\ldots = L$) of\neq.~\\ref{eq-find-alpha} is then used to determine the free parameter\n$\\alpha$, which in turn is used in the first and second lines to find\n$p_{1,2}$ and thus $d_{1,2}$.\n\nAs the most trivial example we consider the case of no rotations,\n$\\theta_1 = \\theta_2 = \\theta_3 = 0$. Then\n\n\\begin{align}\n  A_3 + \\alpha k_3 & = L \\\\\n  \\alpha & = \\frac{L-A_3}{k_3} \\\\\n  p_1 & = A_1 + (L-A_3) \\frac{k_1}{k_3} \\\\\n  p_2 & = A_2 + (L-A_3) \\frac{k_2}{k_3}.\n\\end{align}\n\nWe see also that when all rotations are zero, $(\\mathrm{poni}_1,\n\\mathrm{poni_2})$ are the real space coordinates of the direct beam\n($A_{1,2,3}=k_{1,2}=0$) .\n\n\\section{Geometry definition of \\texttt{ImageD11}}\n\nFor maximum convenience, \\texttt{ImageD11} defines almost everything\ndifferently than \\texttt{pyFAI}.\n\nCoordinate system: \\texttt{ImageD11} uses the ID06 coordinate system\nwith $x$ along the beam, $y$ to port (away from the ring center), and\n$z$ up.\n\nUnits: As the system is somewhat scale-invariant, \\texttt{ImageD11}\nallows a free choice of the unit of length, which we will call $X$\nhere. The same unit has to be used for all translations, and for the\npixel size of the detector. The default used in the code appears to be\n$X = 1\\,\\mathrm{\\mu m}$, but it might as well be Planck lengths,\nmillimeters, inches, meters, tlalcuahuitl, furlongs, nautical miles,\nlight years, kparsec, or whatever else floats your boat. The only\nrequirement is that you can actually measure and express the detector\npixel size and COR-to-detector distance in your units of choice.\n\nParameters: \\texttt{ImageD11} defines the detector geometry via the\nfollowing parameters:\n\n\\begin{itemize}\n\\item Beam center $y_{\\mathrm{center}}$ and $z_{\\mathrm{center}}$:\n  Position of the direct beam on the detector, in $\\mathrm{px}$.\n\\item Pixel size $y_{\\mathrm{size}}$ and $z_{\\mathrm{size}}$ in\n  ${X}/{\\mathrm{px}}$.\n\\item Detector tilts $t_x$, $t_y$, and $t_z$, in $\\mathrm{rad}$. The\n  center of rotation is the point where the direct beam intersects the\n  detector.\n\\item Distance $D$, in units $X$, between the origin to the point\n  where the direct beam intersects the detector.\n\\item Detector flip matrix $O = \\begin{bmatrix} o_{11} & o_{12}\n  \\\\ o_{21} & o_{22} \\end{bmatrix}$. This matrix takes care of\n  correcting typical problems with the way pixel coordinates are\n  arranged on the detector. If, e.g., the detector is rotated by\n  $90^{\\circ}$, then $O=\\begin{bmatrix} 0 & 1 \\\\ -1 &\n  0\\end{bmatrix}$. If left and right (or up and down) are inverted on the\n  detector, then $o_{22} = -1$ ($o_{11}=-1$). \n\\end{itemize}\n\nIt appears that these conventions where defined under the assumption\nthat the detector is more or less centered in the direct beam, and\nthat the detector tilts are small.\n\nThe implementation in the code \\texttt{transform.py} is using the\nfollowing equations:\n\n\\begin{align}\n  R_{\\mathtt{ImageD11}}(\\theta_x, \\theta_y, \\theta_z)\n  & =\n  R_1(\\theta_x) \\cdot R_2(\\theta_y) \\cdot R_3(\\theta_z)\n  \\\\\n  \\begin{bmatrix}\n    p_z \\\\ p_y\n  \\end{bmatrix}\n  & =\n  \\begin{bmatrix}\n    o_{11} & o_{12}\n    \\\\ o_{21} & o_{22}\n  \\end{bmatrix}\n  \\cdot\n  \\begin{bmatrix}\n    (d_z - z_{\\mathrm{center}}) z_{\\mathrm{size}} \\\\\n    (d_y - y_{\\mathrm{center}}) y_{\\mathrm{size}}\n  \\end{bmatrix}\n  \\label{eq-p}\n  \\\\\n  \\begin{bmatrix}\n    t_x \\\\ t_y \\\\ t_z\n  \\end{bmatrix}\n  & =\n  R_{\\mathtt{ImageD11}}(\\theta_x, \\theta_y, \\theta_z)\n  \\cdot\n  \\begin{bmatrix}\n    0 \\\\ p_y \\\\ p_z\n  \\end{bmatrix}\n  +\n  \\begin{bmatrix}\n    D \\\\ 0 \\\\ 0\n  \\end{bmatrix}\n  \\label{eq-t}\n\\end{align}\nNote that the order of $y$ and $z$ is not the same in eqs.~\\ref{eq-p} and \\ref{eq-t}.\n\nThe same could be achieved more easily by\n\n\\begin{align}\n  \\begin{bmatrix}\n    t_x \\\\ t_y \\\\ t_z\n  \\end{bmatrix}\n  & =\n  R_{\\mathtt{ImageD11}}(\\theta_x, \\theta_y, \\theta_z)\n  \\cdot\n  \\begin{bmatrix}\n    1 & 0 & 0 \\\\\n    0 & y_{\\mathrm{size}} o_{22} & z_{\\mathrm{size}} o_{21} \\\\\n    0 & y_{\\mathrm{size}} o_{12} & z_{\\mathrm{size}} o_{11}\n  \\end{bmatrix}\n  \\cdot\n  \\begin{bmatrix}\n    D \\\\ p_y - y_{\\mathrm{center}} \\\\ p_z - z_{\\mathrm{center}}\n  \\end{bmatrix}.\n  \\label{eq-tImageD11}\n\\end{align}\n\n\\section{Conversion}\n\nThe transformation between the different coordinate systems is\nachieved by\n\\begin{align}\n  t_{\\mathtt{ImageD11}}\n  =\n  \\begin{bmatrix}\n    0 & 0 & 1 \\\\ 0 & -1 & 0 \\\\ 1 & 0 & 0\n  \\end{bmatrix}\n  t_{\\mathtt{pyFAI}},\n  \\label{eq-coordconv}\n\\end{align}\nwhere $t_{\\mathtt{ImageD11}}$ is given by eq.~\\ref{eq-tImageD11}, and\n$t_{\\mathtt{pyFAI}}$ is given by eq.~\\ref{eq-tpyFAI}. Substituting\nthese equations into eq.~\\ref{eq-coordconv}, one can them attempt to\nconvert \\texttt{pyFAI} parameters into \\texttt{ImageD11} parameters\nand vice versa. As \\texttt{pyFAI} does not allow for detector\nflipping, $o_{11}=o_{22}=1$ and $o_{12}=o_{21}=0$. Furthermore,\n$\\mathrm{pxsize}_1 = z_{\\mathrm{size}}$ and $\\mathrm{pxsize}_2 =\ny_{\\mathrm{size}}$. Because we assume that both equations describe the\nsame pixel, twice in detector coordinates and twice in real-space\ncoordinates, $p_y = p_2$ and $p_z = p_1$.\n\nCHECK IF $p_y = p_2$ or $p_y = - p_2$/$o_{22}=-1$ DUE TO\n\\texttt{pyFAI} LEFT HANDED COORDINATE SYSTEM!!!\n\nFor the translations, the equivalence is tractable by setting $p_1 =\np_2 = p_y = p_z = 0$. One obtains 3 equations that are coupled via the\nrotation matrices --- as the center of rotations are different, there\nshould be a noticeable influence of the distance on the offsets. In\ngeneral, $D \\geq L$ with $D=L$ only for $\\theta_1=\\theta_2=0$\n($\\theta_y = \\theta_z = 0$. Because the rotations are applied in\ndifferent order one can not assume, \\emph{a priori}, that the angles\nare the same! (If at least two tilt angles are small, this may be a\ngood approximation)\n\n\\end{document}\n", "meta": {"hexsha": "9ff0417cb0038f6f27a532e17491c961a3936a6f", "size": 10283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/source/geometry.tex", "max_stars_repo_name": "yugangzhang/pyFAI", "max_stars_repo_head_hexsha": "e0453b279dac1f165f637e2a2ed1d4ddf57d31ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2016-07-16T19:43:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T16:53:47.000Z", "max_issues_repo_path": "doc/source/geometry.tex", "max_issues_repo_name": "yugangzhang/pyFAI", "max_issues_repo_head_hexsha": "e0453b279dac1f165f637e2a2ed1d4ddf57d31ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1125, "max_issues_repo_issues_event_min_datetime": "2016-06-09T07:47:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:34:00.000Z", "max_forks_repo_path": "doc/source/geometry.tex", "max_forks_repo_name": "yugangzhang/pyFAI", "max_forks_repo_head_hexsha": "e0453b279dac1f165f637e2a2ed1d4ddf57d31ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 52, "max_forks_repo_forks_event_min_datetime": "2016-06-09T07:30:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T08:25:11.000Z", "avg_line_length": 32.3364779874, "max_line_length": 85, "alphanum_fraction": 0.6752893125, "num_tokens": 3583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6375741038544633}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\\usepackage{listings}\n\\title{\\bf{Turbine Formulation}}\n\\author{Nicholas Malaya, Roy Stogner, Robert D. Moser \\\\ Institute for\nComputational Engineering and Sciences \\\\ University of Texas at Austin}\n\\date{} \n\n\\begin{document}\n\\maketitle\n\\newpage\n\\section{Turbine Definitions}\n\nThe normal in the blade's velocity direction is, \n\\begin{equation}\nn_B = \\frac{u_B}{||u_B||}. \n\\end{equation}\nWhere $u_B$ is the blade velocity and is specified.\nThe normal in the fan vertical direction is also set, and is typically, \n\\begin{equation}\nn_v = \\left(0,0,1\\right)\n\\end{equation}\ne.g. pointing ``up''. Then the normal in the radial direction must be, \n\\begin{equation}\nn_r = n_B \\times n_v. \n\\end{equation}\n% The fan-wing-plane bit means that we're only looking at the projection\n% of velocity into the plane that's defined by the base velocity and\n% vertical direction. \n\n% (01:03:44 PM) Roy Stogner: The \"local relative velocity\" means that\n% we're taking the velocity not in the reference frame of the domain, but\n% in the reference frame of the wing.  So if the base velocity is U_B and\n% the air velocity is U, then the local relative velocity is U - U_B. \n% (01:04:25 PM) Roy Stogner: Note that we simplify that equation a tiny\n% bit by using the fact that U_B and N_R are perpendicular. \n\nThen, the fan-wing-plane component (e.g. the plane perpendicular to the \nradius) of local relative velocity is\n\\begin{equation}\nu_p = u - (u\\cdot n_r)\\cdot n_r - u_B. \n\\end{equation}\nWe can now define the lift and drag normals, where the direction\nopposing drag is, \n\\begin{equation}\nn_{\\text{drag}} = \\frac{u_p}{||u_p||} \n\\end{equation}\nand the direction opposing lift orthogonal to the drag and the radial direction, \n\\begin{equation}\nn_{\\text{lift}}= n_{\\text{drag}} \\times n_r. \n\\end{equation}\nNow the ``forward velocity'' in the reference frame of the turbine is, \n\\begin{equation}\nu_{\\text{fwd}}= -u_p \\cdot n_B\n\\end{equation}\nand the ``upward'' velocity in this frame is, \n\\begin{equation}\nu_{\\text{up}} = u_p \\cdot n_v. \n\\end{equation}\nFinally, we can specify the angle with respect to the fan velocity\ndirection as, \n\\begin{equation}\n \\theta_f = \\text{atan2}\\left(\\frac{u_{\\text{up}}}{u_{\\text{fwd}}}\\right)\n %\\theta_f = \\text{tan}^{-1}\\left(\\frac{u_{\\text{up}}}{u_{\\text{fwd}}}\\right)\n\\end{equation}\nwhile the angle with respect to the chord is this with the addition of\nthe angle of attack of the blade, \n\\begin{equation}\n \\theta = \\theta_f + \\alpha(r).\n\\end{equation}\nNow, we only need the drag polars in order to fully specify the force\non the blades.\n\n\\newpage\n\\section{Drag Polars}\n\nWe have been provided lift and drag as a function of angle of attack for\ntwo cases, the flat plate and semi-circle turbine blades. \nFor the flat plate, the drag polars are specified as,\n\n\\begin{lstlisting}\n    theta := ((t+pi/2)%pi)-pi/2; \n    lift   = 'if(abs(theta)<pi/24,theta*9,sin(2*theta))'\n    drag   = 'if(abs(theta)<pi/24,0.005+theta*theta*81/25,1-0.8*cos(2*theta))'\n\\end{lstlisting}\nfor example. \n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/flat}\n    \\caption{The flat plate interpolation.} \n    \\label{flat}\n  \\end{center}\n\\end{figure}\nAs shown in Figure \\ref{flat}, the fit is largely accurate. \n\nThe semi-circular plots are more complicated. Here, we use a high order\npolynomial fit to continuously interpolate between drag polars. This\nresults in a \n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/semi}\n    \\caption{The semi-circular plate interpolation.} \n    \\label{semi}\n  \\end{center}\n\\end{figure}\nAs shown in Figure \\ref{semi}, the fit is decent, but not remarkably accurate.\n\nThen, the force on the turbine is, \n\\begin{equation}\n \\boxed{F = \\frac{1}{2}\\frac{\\rho u_p^2 C}{A}\\left(C_l \\cdot\n\t\t\t\t\t      n_\\text{lift} + C_d \\cdot n_\\text{drag}  \\right)}\n\\end{equation}\n\nWhere C is the chord length (specified as input), and A is the area,\nwhich is also specified. For instance, the area swept might be, \n\\begin{lstlisting}\n     area_swept = '{r:=sqrt(x^2+y^2); 2*pi*r*(.6-.4)/4}'\n\\end{lstlisting}\nfor a 4 blade fan. The chord is specified similarly, for instance, \n\\begin{lstlisting}\n     chord_length = '.2*sqrt(2)'\n\\end{lstlisting}\nwould set a 0.28 meter chord length. \n%\n% ---------------------------------------------------\n% old turbine discussion:\n% ---------------------------------------------------\n\n% The penalty function will be added to the navier-stokes as, \n% % \\begin{align}\n% %  \\partial_t(\\rho u) = \\text{NS} &+ \\frac{1}{\\epsilon}(u-u_t)\\cdot n_p \\\\\n% %                                 &+ \\frac{1}{\\epsilon}(u-\\omega u_t)\\cdot n_p \\\\\n% % \\end{align}\n\n% \\begin{align}\n%  \\partial_t(\\rho u) = \\text{NS} + \\frac{1}{\\epsilon}(u-\\omega u_t)\\cdot n_p\n% \\end{align}\n\n% We will start by formulating a constant rotation speed\n% turbine. The rotor will have counter-clockwise spin with angular\n% velocity omega.   \n\n% \\begin{verbatim}\n%   base_velocity=\n%                 '{(r<r_max)*(z<zmax) * r * -sin(theta)*omega}\n%                  {(r<r_max)*(z<zmax) * r * cos(theta)*omega}\n%                  {0}'\n% \\end{verbatim}\n% There are a few problems with this formulation. One, in a turbine, the\n% fluid velocity is not necessarily identical to the blade velocity. \n% The turbine speed can take a range of values, and is often quoted as the\n% `tip-speed ratio'', $\\lambda$, which is,\n%  \\begin{equation}\n%   \\lambda = \\frac{\\omega R}{v}.\n%  \\end{equation}\n% Here, R is the radius of the turbine blades, omega the angular velocity,\n%  and v is the velocity of the fluid. Values for $\\lambda$ generate power\n%  in the range of 0-16, and are typically between 4 and 14. \n\n% Zmax will be the height of the vanes, which is approximately 0.84 meters in the laboratory, \n% and 1.0795 meters for the two-meter SoV configuration. Rmax will be the inner diameter of the vanes. \n\n%\n% ---------------------------------------------------\n% old discussion on determining the rotation speed:\n% ---------------------------------------------------\n% We now need to choose $\\omega$. At the Betz limit, the velocities will be\n% $V_{\\text{out}}/V_{\\text{in}} = 1/3$. Furthermore, the control volume\n% analysis implies that,\n% \\begin{equation}\n%  V_{\\text{turbine}} = \\frac{1}{2}\\left(V_{\\text{in}} + V_{\\text{out}} \\right)\n% \\end{equation}\n% then,\n% \\begin{align}\n%  V_{\\text{turbine}} &= \\left(\\frac{1}{2}\\right) \\left(\\frac{4}{3}\\right) V_{\\text{in}} \\\\\n%  &= \\frac{2}{3} V_{\\text{in}}.\n% \\end{align}\n% Note this is not the velocity of the turbine, but the velocity of the\n% fluid around the turbine. We can estimate the turbine speed from the\n% ``tip-speed ratio'', $\\lambda$, which is,\n% \\begin{equation}\n%  \\lambda = \\frac{\\omega R}{v}.\n% \\end{equation}\n% Here, R is the radius of the turbine blades, omega the angular velocity,\n% and v is the velocity of the fluid. Values for $\\lambda$ generate power\n% in the range of 0-16, and are typically between 4 and 14. Thus, our\n% angular velocity of the turbine is, \n% \\begin{equation}\n%  \\omega = \\frac{ 2 V_{\\text{in}}\\lambda}{3 R_{\\text{max}}}.\n% \\end{equation}\n\n% ---------------------------------------------------\n% refs\n% ---------------------------------------------------\n\n%\n% https://github.com/grinsfem/grins/tree/master/src/physics/src\n% https://github.com/grinsfem/grins/blob/master/src/physics/src/averaged_fan.C\n% https://github.com/grinsfem/grins/blob/master/src/physics/src/averaged_fan_base.C#L120\n% https://github.com/grinsfem/grins/blob/3f86653ab5ba01981193ccce142ea196d0a192de/src/physics/src/averaged_fan_base.C\n% https://github.com/grinsfem/grins/blob/34e2fc1e7d7143e0080f81c67bd584ce1236e2c1/src/physics/include/grins/averaged_fan.h\n% https://github.com/grinsfem/grins/blob/34e2fc1e7d7143e0080f81c67bd584ce1236e2c1/src/physics/include/grins/averaged_fan_base.h\n%\n\n\n\\end{document}\n", "meta": {"hexsha": "e88db8c69f7b15721febff9aa99a83d77bb63211", "size": 7905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/causa/turbine.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/causa/turbine.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/causa/turbine.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 37.6428571429, "max_line_length": 127, "alphanum_fraction": 0.6760278305, "num_tokens": 2398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904955, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6375315138838371}}
{"text": "\\newpage\n\n\\captionsetup{labelformat=empty}\n\n\\section*{\\texorpdfstring{Appendix C: VOI for conservation auctions\nheuristic solution \\emph{n} =\n2}{Appendix C: VOI for conservation auctions heuristic solution n = 2}}\\label{appendix-c-voi-for-conservation-auctions-heuristic-solution-n-2}\n\\addcontentsline{toc}{section}{Appendix C: VOI for conservation auctions\nheuristic solution \\emph{n} = 2}\n\n\\textbf{Priors}\n\nLet \\(A_1\\) and \\(A_2\\) be two assets. Each has some cost efficiency\n\\(c_1\\) and \\(c_2\\), both of which are uncertain with prior probability\ndistributions,\n\n\\begin{equation}\nc_1\\sim\\mathcal{N}(\\mu_1, \\sigma_1)\n(\\#eq:c1)\n\\end{equation}\n\nand\n\n\\begin{equation}\nc_2\\sim\\mathcal{N}(\\mu_2, \\sigma_2)\n(\\#eq:c2)\n\\end{equation}\n\nwhere \\(\\mu_1\\) and \\(\\mu_2\\) are the prior means and \\(\\sigma_1\\) and\n\\(\\sigma_2\\) are the prior standard deviations.\n\nLet \\(\\pi=\\Pr(c_1 > c_2)\\) and therefore,\n\n\\begin{equation}\n\\pi = \\Phi\\left(\\frac{\\mu_1-\\mu_2}{\\sqrt{\\sigma^2_1+\\sigma^2_2}}\\right)\n(\\#eq:c2)\n\\end{equation}\n\n\\textbf{Utilities}\n\nIf \\(\\pi > 1 - \\pi\\) then the optimal action is to purchase asset\n\\(A_1\\), otherwise it is to purchase \\(A_2\\).\n\nWe can assign utilities to each combination of the condition of \\(c_1\\)\nand \\(c_2\\), and each action such that,\n\n\\begin{equation}\n\\begin{aligned}\nu(c_1 > c_2, A_1)&=1\\\\\nu(c_1 < c_2, A_1)&=0\\\\\nu(c_1 > c_2, A_2)&=0\\\\\nu(c_1 < c_2, A_2)&=1\\\\\n\\end{aligned}\n(\\#eq:utilitiesapen)\n\\end{equation}\n\nTherefore the expected values of taking each action are\n\\(\\mathrm{E}[u(A_1)]=\\pi\\) and \\(\\mathrm{E}[u(A_2)]=1-\\pi\\).\n\n\\textbf{Value of perfect information}\n\nIf we could reduce the uncertainty in the prior probabilites of \\(c_1\\)\nand \\(c_2\\) such that \\(\\pi\\) approached either limit, then the expected\nvalue of perfect information is,\n\n\\begin{equation}\n\\mathrm{EVPI}=1-\\max(\\pi, 1-\\pi)=\\min(\\pi, 1-\\pi)\n(\\#eq:evpiaucapen)\n\\end{equation}\n\n\\textbf{Preposterior analysis}\n\nNow let's assume we can sample from some process and learn about \\(c_1\\)\nand \\(c_2\\).\\\\\nLet \\(X_1\\) and \\(X_2\\) be observations from a process described by the\nfollowing sampling distributions,\n\n\\begin{equation}\nX_1\\sim\\mathcal{N}\\left(c_1, 1\\right)\n(\\#eq:x1)\n\\end{equation}\n\nand\n\n\\begin{equation}\nX_2\\sim\\mathcal{N}\\left(c_2, 1\\right)\n(\\#eq:x2)\n\\end{equation}\n\nwhere for simplicity the standard deviation is one.\n\nFurthermore, we can make \\(Mp\\) and \\(M(p-1)\\) observations of \\(X_1\\)\nand \\(X_2\\) respectively. Where \\(M\\) is the total number of samples the\nbudget allows and \\(p\\) and \\(p-1\\) are proportions of that budget\nallocated to each assets. Given the observations of \\(X_1\\) and \\(X_1\\)\nwith sample sizes \\(Mp\\) and \\(M(p-1)\\) we can update the prior beliefs\nin \\(c_1\\) and \\(c_2\\) and arrive at posterior distributions,\n\n\\begin{equation} \n\\begin{aligned}\nc_1^\\prime &\\sim \\mathcal{N}(\\mu^\\prime_1, \\sigma^\\prime_1)\\\\\nc_2^\\prime &\\sim \\mathcal{N}(\\mu^\\prime_2, \\sigma^\\prime_2)\n\\end{aligned}\n(\\#eq:posteriorcs)\n\\end{equation}\n\nwhere,\n\n\\begin{equation}\n\\begin{aligned}\n\\mu^\\prime_1 &= \\frac{\\mu_1 + X_1Mp\\sigma^2_1}{Mp\\sigma^2_1 + 1}\\\\\n\\sigma^\\prime_1 &= \\sqrt{\\frac{\\sigma^2_1}{Mp\\sigma^2_1 + 1}}\\\\\n\\mu^\\prime_2 &= \\frac{\\mu_2 + X_2M(p-1)\\sigma^2_2}{M(p-1)\\sigma^2_2 + 1}\\\\\n\\sigma^\\prime_2 &= \\sqrt{\\frac{\\sigma^2_2}{M(p-1)\\sigma^2_2 + 1}}\n\\end{aligned}\n(\\#eq:posteriormusig)\n\\end{equation}\n\n\\textbf{Value of sample information}\n\nNow we make the simplifying assumptions that\n\\(\\mathrm{E}[X_1]=\\mathrm{E}[c_1]=\\mu_1\\) and\n\\(\\mathrm{E}[X_1]=\\mathrm{E}[c_1]=\\mu_1=0\\).\n\nIn this scenario the prior probability of \\(c_1>c_2\\) is,\n\n\\begin{equation}\n\\pi=\\Phi\\left(\\frac{\\mu_1}{\\sqrt{\\sigma^2_1+\\sigma^2_2}}\\right)\n(\\#eq:priorpi)\n\\end{equation}\n\n, and the posterior is\n\n\\begin{equation}\n\\pi^\\prime=\\Phi\\left(\\frac{\\mu_1}{\\sqrt{\\frac{\\sigma^2_1}{Mp\\sigma^2_1 + 1}+\\frac{\\sigma^2_2}{M(p-1)\\sigma^2_2 + 1}}}\\right)\n(\\#eq:posteriorpi)\n\\end{equation}\n\nWe can now calculate the expected value of sample information,\n\n\\begin{equation}\n\\mathrm{EVSI}=\\max(\\pi^{\\prime}, 1-\\pi^{\\prime})-\\max(\\pi, 1-\\pi)\n(\\#eq:evsiaucapen)\n\\end{equation}\n\n\\textbf{Optimal sampling allocation}\n\nWith equations 10-12, for any given set of \\(\\mu_1\\), \\(\\sigma_1\\),\n\\(\\mu_2\\), and \\(M\\) we can find the optimal allocation to sample for\nasset \\(A_1\\), \\(p\\) to maximise the value of sample information.\n\n\\textbf{Summary}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Optimal allocation insensitive to ratio of \\(\\mu_a\\) to \\(\\mu_b\\).\n\\item\n  Optimal allocation sensitive to ratio of \\(\\sigma_1\\) to \\(\\sigma_2\\).\n\\item\n  Always preferential to sample asset with greater uncertainty.\n\\item\n  Solution is symmetrical.\n\\item\n  The \\(M\\) at which you start to allocate sampling to both assets is\n  proportional to the ratio of \\(\\sigma_1\\) to \\(\\sigma_2\\).\n\\item\n  The \\(M\\) at which you start to allocate sampling to both assets is\n  insensitive to whether \\(\\sigma_1 < \\sigma_2\\) or\n  \\(\\sigma_1 > \\sigma_2\\).\n\\item\n  Optimal allocation always has greater EVSI when\n  \\(\\sigma_1 \\neq \\sigma_2\\).\n\\end{itemize}\n\n\\textbf{\\(\\mu_1 > \\mu_2, \\sigma_1 \\gg \\sigma_2\\)}\n\nFirst let's examine the case where our prior belief is that \\(c_1\\) is\nsomewhat greater than \\(c_2\\), where \\(\\mu_1=.2\\) and \\(\\mu_2 = 0\\) but\nthe uncertainty in \\(\\theta_1\\) is far greater than in \\(\\theta_2\\),\n\\(\\sigma_1 = 2\\) and \\(\\sigma_2 = .2\\).\n\n\\includegraphics{figure/unnamed-chunk-2-1.png} \\clearpage\n\nIn this case, until we can take more than a total of 24 samples\n(\\(N=24\\)) the optimal allocation is to allocate all sampling effort to\nasset \\(A_1\\) (a). With a total budget greater than 24 samples, we start\nallocating sampling to asset \\(A_2\\) at a diminishing rate with total\nsample size and asymptoting at \\(p=0.5\\). The expected value of sample\ninformation (EVSI) increases with sample size with diminishing returns\nasymptoting below the EVPI (c). At all sample sizes, the optimal\nallocation has greater expected value than naive assumption of constant\nallocation of \\(p=0.5\\). The greatest benefit of allocating optimally is\nwhen the sample size is \\(N=10\\). As sample size increases the\nadditional benefit of allocating optimally declines asymptotically as\nthe optimal allocation approaches \\(p=0.5\\) (d).\n\n\\textbf{\\(\\mu_1 \\simeq \\mu_2, \\sigma_1 \\gg \\sigma_2\\)}\n\nHolding all the other parameters constant, let's examine a scenario\nwhere the prior expection of \\(c_1\\) is only marginally better than\n\\(c_2\\) (i.e., reduce \\(\\mu_1\\) to \\(.01\\)).\n\n\\includegraphics{figure/unnamed-chunk-3-1.png} \\clearpage\n\nWe still allocate in the same way as before (a). The EVPI approaches its\ntheoretical maxmimum of 0.5. But the value of sample information\nachievable for anything less than 200 samples is reduced to near zero\n(c). The shape of the additional benefit from optimal allocation is the\nsame but the scale has reduced and the optimal value of N has increased\nmeaning more samples must be taken to maxmise the additional gain in\nEVSI by using the optimal allocation vs the naive allocation of\n\\(p=0.5\\) (d).\n\n\\textbf{\\(\\mu_1 \\gg \\mu_2, \\sigma_1 \\gg \\sigma_2\\)}\n\nAll other parameters still the same, but now with \\(\\mu_1=1\\) much\ngreater than \\(\\mu_2\\).\n\n\\includegraphics{figure/unnamed-chunk-4-1.png} \\clearpage\n\nStill same optimal allocation (a). EVPI reduced as we start already more\ncertain that \\(A_1\\) is a better asset than \\(A_2\\). The return on\ninvesting in each additional sample diminishes quicker and sooner as\nEVSI asymptotes at nearer EVPI (c). The additional benefit in EVSI seen\nby sampling optimally has increased by peaks earlier at \\(N=2\\) (d).\n\n\\textbf{\\(\\mu_1 > \\mu_2, \\sigma_1 > \\sigma_2\\)}\n\nResetting \\(\\mu_1\\) now we examine what happens when \\(\\sigma_1\\) is\ndouble \\(\\sigma_2\\).\n\n\\includegraphics{figure/unnamed-chunk-5-1.png} \\clearpage\n\nThe optimal allocation has the same shape as before but now we allocate\nsampling to asset \\(A_2\\) sooner than before. Now if we take more than 3\nsamples we will allocate an increasing amount of them to asset \\(A_2\\)\n(a). The EVPI has been reduced as we have started off more certain that\n\\(A_1\\) is greater \\(A_2\\) (c). There is less advantage to sampling\noptimally rather than the naive allocation but the point at which the\nadditional benefit in EVSI peaks is at higher \\(N\\) (\\(N=2\\)) than when\n\\(\\sigma_1\\) was much more than \\(\\sigma_2\\) (d).\n\n\\textbf{\\(\\mu_1 > \\mu_2, \\sigma_1 = \\sigma_2\\)}\n\nNow increase the precision of \\(c_1\\) so that \\(\\sigma_1 = \\sigma_2\\).\n\n\\includegraphics{figure/unnamed-chunk-6-1.png} \\clearpage\n\nNow the optimal allocation is to just allocate evenly between the assets\n(i.e., the naive allocation is now optimal and there is effectively no\nadvantage to optimize) (a). The allocation is still insentive to the\nvalue of \\(\\mu_1\\) and the value of \\(\\sigma\\)'s. Decreasing the prior\nprecisions increases EVPI, and with it the point at which EVSI vs \\(N\\)\nasymptotes, but without changing the rate EVPI increases with \\(N\\).\nIncreaseing the value of \\(\\mu_1\\) decreases EVPI (but less sensitively\nthan changing the precision) and also increases the rate at which EVPI\nvs \\(N\\) approaches EVPI (c).\n\n\\textbf{\\(\\mu_1 > \\mu_2, \\sigma_1 \\ll \\sigma_2\\)}\n\nReturning to the original paramterisation now reverse the prior\nprecisions so that \\(\\tau^\\prime_a\\) is much greater than\n\\(\\tau^\\prime_b\\).\n\n\\includegraphics{figure/unnamed-chunk-7-1.png} \\clearpage\n\nThe allocation is the same but now reflected so that we still allocate\nto the asset with more uncertainty (a). This applies no matter what the\nother parameter values are (i.e., the problem is symetrical).\n\n\\captionsetup{labelformat=default}\n", "meta": {"hexsha": "ae4803922c4379e205e53fc4a027f3667799fc4c", "size": 9519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix1.tex", "max_stars_repo_name": "wkmor1/voiConsAuc", "max_stars_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "wkmor1/voiConsAuc", "max_issues_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "wkmor1/voiConsAuc", "max_forks_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_forks_repo_licenses": ["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.8681318681, "max_line_length": 142, "alphanum_fraction": 0.7184578212, "num_tokens": 3096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6375204519708686}}
{"text": "\\documentclass[./\\jobname.tex]{subfiles}\n\\begin{document}\n\n\\chapter{State of the Art}\n\\label{chap:state_of_the_art}\nThis chapter provides an overview of the current state of the art in solving \\gls{pde}. Included are the widely used \\gls{fem} as well as heuristic optimisation methods. Further, an introduction to the \\gls{de} framework is given, which provides the basis for the algorithms described in this thesis. \n\n\\section{Finite Element Method}\nCurrently, the Finite Element Method is the go-to approach to solve partial differential equations. The domain $\\Omega$ on which the \\gls{pde} is posed, is discretised into multiple smaller elements - as the name suggests. Thus, \\gls{fem} counts to the category of meshed methods. The underlying solution function $u(\\mathbf{x})$ to the PDE is then approximated by so called ``basis-functions'' $\\Phi(\\mathbf{x})$ limited to these finite elements. This thesis uses the open-source Netgen/NGSolve \\gls{fem} package (\\cite{schoberl_ngsolvengsolve_2020}). \n\nThe general steps taken to solve a PDE with an FEM solver are: \n\\begin{enumerate}\n\t\\item \\underline{Step: Strong Form} \\\\\n\t\t  This is the standard formulation of the linear \\gls{pde}. $\\mathbf{L}$ and $\\mathbf{B}$ are linear differential operators that include the derivatives. \\\\\n\t\t  \\begin{equation}\n\t\t  \\label{eq: strong form}\n\t\t\t  \\begin{split}\n\t\t\t  \t\\mathbf{x} \\in \\mathbb{R}^2 \\\\\n\t\t\t  \tu(\\mathbf{x}), f(\\mathbf{x}), g(\\mathbf{x}): \\Omega \\rightarrow \\mathbb{R} \\\\\n\t\t\t\t\\mathbf{L} u(\\mathbf{x}) = f(\\mathbf{x}) \\text{ on $\\Omega$} \\\\\n\t\t\t\t\\mathbf{B} u(\\mathbf{x}) = g(\\mathbf{x}) \\text{ on $\\partial \\Omega$}\n\t\t\t  \\end{split}\n\t\t  \\end{equation}\n\t\t  Further, only Dirichlet boundary conditions are considered, thus the boundary operator is always the identity matrix $\\mathbf{B} = \\mathbb{I}$. Therefore, the linear operator on the boundary $\\mathbf{B}$ can be disregarded, resulting in  \\\\\n\t\t  \\begin{equation}\n\t\t  \tu(\\mathbf{x})|_{\\partial \\Omega} = g(\\mathbf{x}) .\n\t\t  \\end{equation}\n\t\t  \n\t\\item \\underline{Step: Weak Form} \\\\\n\t\t  The next step is to reformulate the strong form into a usable weak form. This is equivalent to the strong form but written in an integral notation. In this equation, the $A$, $b$ and $c$ correspond to the constant factors of the derivatives in strong form. For the sake of completeness, this is kept abstract. In the \\gls{pde}s considered in this work, $A = \\mathbb{I}$ and $b=\\mathbf{0}$, $c = 0$. Currently, the so-called test-function $v(\\mathbf{x})$ is an arbitrary function, but it has to be 0 on the boundary $v(\\mathbf{x})|_{\\Omega} = 0$. The choice of the test-function correspond to different \\gls{fem} types (\\cite[p. 6f]{shen_spectral_2011}).\\\\\n\t\t  \\begin{equation}\n\t\t  \\label{eq: weak form}\n\t\t\t  \\begin{split}\n\t\t\t      \\underbrace{\\int_{\\Omega} - (\\nabla^T A \\nabla) u(\\mathbf{x}) v(\\mathbf{x}) dV - \\int_{\\Omega} b^T \\nabla u(\\mathbf{x}) v(\\mathbf{x}) dV + \\int_{\\Omega} c u(\\mathbf{x}) v(\\mathbf{x}) dV}_{a(u,v)} \\\\ = \\underbrace{\\int_{\\Omega} f(\\mathbf{x}) v(\\mathbf{x}) dV}_{F(v)}\n\t\t\t  \\end{split}\n\t\t  \\end{equation} \n\t\\item \\underline{Step: Discretisation of $\\Omega$} \\\\\n\t\t  Create a mesh of finite elements that span the whole domain. Usually these are triangles. Thus, this step is sometimes called ``triangulation''.\n\t\\item \\underline{Step: Basis functions} \\\\\n\t\t  Choose a basis function $\\Phi(\\mathbf{x})$ that can be used to approximate the solution $u(\\mathbf{x}) \\approx u_{h}(\\mathbf{x}) = \\sum_{i = 1}^{N} u_i \\Phi_i(\\mathbf{x})$. A common choice are Lagrange or Chebyshev polynomials. In the Galerkin type \\gls{fem}, the test-function $v(\\mathbf{x})$ is the same as the trail-function, thus $v(\\mathbf{x}) = \\sum_{j = 1}^{N} v_j \\Phi_j(\\mathbf{x})$. The choice of the basis function $\\Phi(\\mathbf{x})$ largely influences the computational effort.  $\\Phi(\\mathbf{x})$ should have a small support, to produce a thinly populated matrix $A$ in the linear system of equations \\eqref{eq:linear_system_of_equations} below.\n\t\\item \\underline{Step: Solution} \\\\\n\t\t  In the weak form, as seen in equation \\eqref{eq: weak form}, $a(u,v)$ is a continuous bilinear form and $F(v)$ is a continuous linear functional. Substituting $u$ and $v$ with their corresponding approximation from \\mbox{step 4} results in \n\t\t  \\begin{equation}\n\t\t  \\sum_{j=1}^{N} v_j \\sum_{i=1}^{N} u_i a(\\Phi_i, \\Phi_j) = \\sum_{j=1}^{N} v_j F(\\Phi_j).\n\t\t  \\end{equation} \n\t\t  Dividing by the $v_j$ values on both sides results in a linear system of equations, where the constant factors $u_i$ need to be determined.  \n\t\t  \\begin{equation}\n\t\t  \\label{eq:linear_system_of_equations}\n\t\t  \\underbrace{\\sum_{i=1}^{N} u_i a(\\Phi_i, \\Phi_j)}_{\\mathbf{A u}} = \\underbrace{F(\\Phi_j)}_{\\mathbf{b}} \\text{ for $j=1,...N$}\n\t\t  \\end{equation}\n\\end{enumerate}\n\nModern solvers include more complex and advanced techniques to further improve the solution error and the computation time. Some of the most important concepts that are also available in NGSolve are listed here. \n\n\\begin{itemize}\n\t\\item \\underline{Static Condensation}: \\\\\n\t\t  Depending on the number of discrete elements, the $\\mathbf{A}$ matrix can be very large. Inverting large matrices is very time consuming. Static condensation, also called Guyan reduction (\\cite{guyan_reduction_1965}), reduces this dimensionality by exploiting the structure of $\\mathbf{A}$. \n\t\\item \\underline{Preconditioner}: \\\\\n\t\t  Instead of solving the $\\mathbf{A}^{-1}$ exactly, this can also be approximated by a matrix that is similar to $\\mathbf{A}^{-1}$. The actual inverse can be iteratively approximated. NGSolve implements multiple different preconditioners and it even allows to create your own method. \n\t\\item \\underline{Adaptive Mesh Refinement}: \\\\\n\t\tThe accuracy of a FEM-approximated solution mainly depends on the density of the mesh. Typically, finer meshes tend to produce more accurate solutions, but the computation time is longer. This trade-off can be overcome by a self-adaptive mesh. NGSolve implements that in an adaptive loop that executes: \n\t\t\\begin{itemize}\n\t\t\t\\item Solve PDE (with coarse mesh)\n\t\t\t\\item Estimate Error (for every element)\n\t\t\t\\item Mark Elements (that have the greatest error)\n\t\t\t\\item Refine Elements (that were previously marked)\n\t\t\t\\item Repeat until degrees of freedom exceed a specified $N$\n\t\t\\end{itemize}\n\\end{itemize}\n\n\n\\section{Computational Intelligence Methods} \n\\label{chap:literature_overview}\n\nThe research community interested in computational intelligence solvers for differential equations has been steadily growing over the past 20 years. This chapter summarises the most important works done in the general field of development and application of such statistical numerical solvers. The following table \\ref{tab:literature_research} gives a brief overview of these papers and sorts them historically. \n\nIn general, all of these papers from the table use the \\gls{wrm}, or some variant of that concept, to transform their differential equation into an optimisation problem. This serves as the fitness function and is necessary to evaluate a possible candidate solution and perform the evolutionary selection. The fitness function is the function to be optimised. It is also called objective function and these terms are used interchangeably in this thesis. In short, the residual $R$ is defined through the differential equation itself and can be calculated by $R(u(\\mathbf{x})) = \\mathbf{L}u(\\mathbf{x}) - f(\\mathbf{x})$. The residual can be thought of as a functional that substitutes $u(\\mathbf{x})$ with an approximate solution $u_{apx}(\\mathbf{x})$ and returns a numerical score. The \\gls{wrm} method is further described in chapter \\ref{chap:opt_problem}.\n\n\\cite{howard_genetic_2001} is one of the first advances in this field. They approximate a subset of the convection-diffusion equations with \\gls{gp} (\\cite{koza_genetic_1992}). Their main idea is to use a polynomial of variable length as the candidate solution that is forced to satisfy the boundary condition. Their fitness value, as seen in equation \\eqref{eq:howard_fitness_2001}, is calculated by squaring the residual $R$ and integrating it over the domain. Since the polynomials are known, and the problems are restricted to a specific differential equation, the integral can be evaluated analytically. \n\n\\begin{equation}\n\\label{eq:howard_fitness_2001}\n\tF(u_{apx}(\\mathbf{x})) = -\\int_{\\Omega} R(u_{apx}(\\mathbf{x}))^2 dx\n\\end{equation}\n\n\\cite{kirstukas_hybrid_2005} proposes a three-step procedure. The first step is time consuming and employs \\gls{gp} techniques to find basis functions that span the solution space. The second step is faster and uses a Gram–Schmidt algorithm to compute the basis function multipliers to develop a complete solution for a given set of boundary conditions. Using linear solver methods, a set of coefficients is found that produces a single function that both satisfies the differential equation and the boundary or initial conditions at distinct points over the domain. These points are further called collocation points. \n\n\\cite{tsoulos_solving_2006} use \\gls{ge} (\\cite{ryan_grammatical_1998}) to find solutions to various differential equations. In contrary to \\gls{gp}, \\gls{ge} uses vectors instead of trees to represent the candidate string. The solution is evaluated as an analytical string, constructed of the functions $sin$, $cos$, $exp$ and $log$, as well as all digits and all four basic arithmetic operations. Because the \\gls{ge} step could result in virtually any function, the fitness integral from equation \\eqref{eq:howard_fitness_2001} can not be calculated analytically. Thus, the integral is approximated by evaluating the residual at collocation points within the domain. This is seen in equation \\eqref{eq:fit_func_tsoulos}. The algorithm was tested on multiple problems of \\gls{ode}, system of ODEs and \\gls{pde}. Only the results for ODEs were promising.\n\n\\begin{equation}\n\\label{eq:fit_func_tsoulos}\nF(u_{apx}(\\mathbf{x})) = \\sum_{i=1}^{n_C} ||R(u_{apx}(\\mathbf{x}_i))||^2\n\\end{equation} \n\n\\cite{mastorakis_unstable_2006} couples a \\gls{ga} (\\cite{holland_outline_1962}) with a \\gls{ds} method (\\cite{nelder_simplex_1965}) for the local solution refinement. The candidates are represented as polynomials of the order 5 where the coefficients are optimised. The boundary condition is directly incorporated into the candidate, thus simplifying the objective function to equation \\eqref{eq:fit_func_tsoulos}. The focus here is on unstable ODEs that can not be solved with finite difference methods. \n\n\\cite{sobester_genetic_2008} tried a radical different approach to incorporate the boundary condition into the solution. They found that using \\gls{gp} for the inner domain is only effective if the algorithm does not have to consider the boundary. They split the solution $u_{apx}(\\mathbf{x})$ into two parts where $u_{GP}(\\mathbf{x})$ represents the solution for the inner domain and $u_{RBF}(\\mathbf{x})$ ensures the boundary condition \n\\begin{equation}\n\\label{eq:solution_sobester}\nu(\\mathbf{x})_{apx} = u_{GP}(\\mathbf{x}) + u(\\mathbf{x})_{RBF}.\n\\end{equation}\nAt first, the \\gls{gp} step produced a trial solution according to the objective function \\eqref{eq:fit_func_tsoulos}. After the \\gls{gp} procedure, a linear combination of radial basis functions $u(\\mathbf{x})_{RBF} = \\sum_{j=1}^{n_B} \\alpha_j \\Phi (||\\mathbf{x}-\\mathbf{x}_{j}||)$ is specifically tailored to $u_{GP}(\\mathbf{x})$ that ensures the boundary condition at all $\\mathbf{x}_{j}$ points on $\\partial \\Omega$. Finding the parameters $\\alpha_j$ can be formulated as a least squares problem. \n\n\\cite{howard_genetic_2011} use a \\gls{gp} scheme to find the solution to a specific set of simplified convection-diffusion equations. They represent a candidate as discrete function value points over the domain. The function between these points is interpolated. The fitness function is similar to equation \\eqref{eq:fit_func_tsoulos} with the exception that the $n_C$ points are not predetermined. These points are sampled randomly in the domain, thus allowing the algorithm to approximate the solution aside from fixed base points. \n\n\\cite{chaquet_solving_2012} use a simple self-adaptive \\gls{es} (as developed by \\cite{schwefel_evolutionsstrategien_1977} and \\cite{rechenberg_evolutionsstrategien_1978}) to evolve the coefficients of a partial Fourier series. The fitness function is expressed in equation \\eqref{eq:fit_func_chaquet}. This is similar to the fitness function \\ref{eq:fit_func_tsoulos}, but it extends the definition of the boundary to also include Neumann conditions by introducing the linear differential operator $\\mathbf{B}$. The limit $n_C$ denotes the number of inner collocation points $\\mathbf{x}_i$ within the domain $\\Omega$, whereas $n_B$ is the number of discrete points $\\mathbf{x}_j$ on the boundary $\\partial \\Omega$. Further, a penalty factor $\\phi$ shifts the focus of the fitness to the boundary. Additionally, this objective function can also represent systems of differential equations, where the number of equations is denoted by $m$. To reduce the search dimension (represented by the number of harmonics), they developed a scheme that only optimises one harmonic at a time and freezes the other coefficients. This scheme is based on the often observed principle that lower frequencies are more important in reconstructing a signal than higher ones. Albeit this concept might not be valid for all possible functions, it worked on all differential equations of their testbed. \n\n\\begin{equation}\n\\label{eq:fit_func_chaquet_2012}\nF(u_{apx}(\\mathbf{x})) = \\frac{\\sum_{i=1}^{n_C} || \\mathbf{L}u_{apx}(\\mathbf{x}_i) - f(\\mathbf{x}_i)||^2 + \\phi \\sum_{j=1}^{n_B} || \\mathbf{B}u_{apx}(\\mathbf{x}_j) - g(\\mathbf{x}_j)||^2}{m (n_C + n_B)}  \n\\end{equation}\n\n\\cite{babaei_general_2013} takes a similar approach. They approximate a solution using a partial Fourier series. The optimal parameters for the candidates are found using a \\gls{pso} algorithm (\\cite{kennedy_particle_1995}). The fitness function consists of two parts, one for the inner area (equation \\eqref{eq:inner_WRF}) and one for the boundary (equation \\eqref{eq:boundary_penalty}). These are added together resulting in equation \\eqref{eq:inner_and_boundary_fitness}.\n\nThe weighted residual integral WRF is exactly the formulation of the \\gls{wrm} from chapter \\ref{chap:opt_problem}. $W$ is an arbitrary weighting function. The absolute values of $W$ and $R$ ensure that only positive values count towards the fitness. Instead of using a sum over collocation points, the integral is evaluated using a numerical integration scheme.\n\n\\begin{equation}\n\\label{eq:inner_WRF}\nWRF(u_{apx}(\\mathbf{x})) = \\int_{\\Omega} |W(\\mathbf{x)}| |R(u_{apx}(\\mathbf{x}))| dx\n\\end{equation} \n\nThe boundary condition is incorporated by summing up its normed violations at distinct points $\\mathbf{x}_i$. $K_j$ are penality multipliers that shift the focus to different points of the boundary. The concept of this penalty function originates from \\cite{rajeev_discrete_1992}.\n\n\\begin{equation}\n\\label{eq:boundary_penalty}\nPFV(u_{apx}(\\mathbf{x})) = WRF(u_{apx}(\\mathbf{x})) \\cdot \\sum_{j=1}^{n_B} K_j \\left(\\frac{u_{apx}(\\mathbf{x}_i)}{g(\\mathbf{x}_i)} - 1\\right)\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:inner_and_boundary_fitness}\nF(u_{apx}(\\mathbf{x})) = WRF(u_{apx}(\\mathbf{x})) + PFV(u_{apx}(\\mathbf{x}))\n\\end{equation}\n\n\\cite{panagant_solving_2014} use polynomials as a candidate representation. They do not specify the order or the type of the polynomial. They test five different simple versions of the optimisation algorithm \\gls{de} (\\cite{storn_differential_1997}). Further, they introduce a so called DE-New that increases the population size after every generation. Their proposition is that greater population sizes are better at finding good solutions. \n\n\\cite{sadollah_metaheuristic_2017} compares three different optimisation algorithms to approximate differential equations: \\gls{pso}, \\gls{hs} (\\cite{geem_new_2001}) and \\gls{wca} (\\cite{eskandar_water_2012}). They use the formulation in equation \\eqref{eq:inner_WRF}, where the weighting function is the same as the residual $|W(\\mathbf{x})| = |R(u_{apx}(\\mathbf{x}))| \\rightarrow WRF = \\int_{\\Omega} |R(u_{apx}(\\mathbf{x}))|^2 dx$. The integral is again approximated using a numerical integration scheme. They find that the \\gls{pso} is slightly better at producing low error solutions, however \\gls{wca} is better at satisfying the boundary condition. \n\nIn their paper \\cite{chaquet_using_2019} describe an algorithm that approximates a solution with a linear combination of Gaussian \\gls{rbf} as kernels:\n\\begin{equation}\nu(\\mathbf{x})_{apx} = \\sum_{i=1}^{N} \\omega_i e^{\\gamma_i (\\left||\\mathbf{x} - \\mathbf{c}_i\\right||^2)}\n\\end{equation}\nThe approximated function $u(\\mathbf{x})_{apx}$ can be fully determined by a finite number of parameters: $\\omega_i, \\gamma_i, \\mathbf{c}_i$. These are stacked together into a vector $\\mathbf{p_{apx}}$ and called the decision variables which are optimised by the algorithm. \nThe objective function can be seen in equation \\eqref{eq:fit_func_chaquet}. This is an update of the objective function in \\ref{eq:fit_func_chaquet_2012} where the inner collocation points also get scaled by a weighting function $\\xi(\\mathbf{x}_i)$.\n\\begin{equation}\n\\label{eq:fit_func_chaquet}\nF(u_{apx}(\\mathbf{x})) = \\frac{\\sum_{i=1}^{n_C} \\xi (\\mathbf{x}_i) || \\mathbf{L}u_{apx}(\\mathbf{x}_i) - f(\\mathbf{x}_i)||^2 + \\phi \\sum_{j=1}^{n_B} || \\mathbf{B}u_{apx}(\\mathbf{x}_j) - g(\\mathbf{x}_j)||^2}{m (n_C + n_B)}  \n\\end{equation}\nThe multipliers $\\xi(\\mathbf{x}_i)$ and $\\phi$ are weighting factors for either the inner or the boundary term. The whole term is normalised with the number of collocation points. \nThe parameters of the kernels are determined via a \\gls{cma_es} (\\cite{hansen_reducing_2003}). To further improve the solution, the evolutionary algorithm is coupled with a \\gls{ds} method to carry out the local search. The authors show empirically that the local search significantly improves the performance by testing the algorithm on a set of 32 differential equations. \n\n\\cite{fateh_differential_2019} use a simple variant of \\gls{de} where candidates are represented as discrete function value points within the domain. The function values between the grid points are linearly interpolated. This is a radical brute force approach that results in a massive search space dimension. Yet, the main advantage is that the solution is not limited to a decomposition of kernel functions and thus, even non-smooth functions can be approximated. Since this approach does not produce an analytical solution, the differential equation and the boundary condition is incorporated into the fitness function by taking the sum of squared residuals at every grid point, as seen in equation \\eqref{eq:fit_fateh}. The derivatives within the residual are calculated between two neighbouring points by the difference quotient. \n\\begin{equation}\n\\label{eq:fit_fateh}\nF(\\mathbf{x}) = \\sqrt{\\sum_{i=0}^{n} R(\\mathbf{x}_i)^2}\n\\end{equation}\n\n\n\n\\begin{table}[H]\n\t\\centering\n\t\\noindent\\adjustbox{max width=\\linewidth}{\n\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\n\t\t\t\\hline\n\t\t\t\\rowcolor[HTML]{\\farbeTabA}\n\t\t\t\n\t\t\tPaper & Algorithm & Representation & Problems \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{howard_genetic_2001}} & \\multilinecell{\\gls{gp}} & \\multilinecell{polynomial of \\\\ arbitrary length} & \\multilinecell{one-dimensional \\\\ steady-state \\\\ model of \\\\ convection-diffusion \\\\ equation} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{kirstukas_hybrid_2005}} & \\multilinecell{\\gls{gp}} & \\multilinecell{algebraic \\\\ expression} & \\multilinecell{heating of thin rod \\\\ heating by current} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{tsoulos_solving_2006}} & \\multilinecell{\\gls{ge}} & \\multilinecell{algebraic term} & \\multilinecell{set of ODEs \\\\ system of ODEs \\\\ and PDEs} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{mastorakis_unstable_2006}} & \\multilinecell{\\gls{ga}\\\\(global); \\\\ \\gls{ds}\\\\(local)} & \\multilinecell{5th order \\\\ polynomial}& \\multilinecell{unstable \\\\ ODEs} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{sobester_genetic_2008}} & \\multilinecell{\\gls{gp} \\\\ and \\\\ RBF-NN} & \\multilinecell{algebraic term \\\\ for inner; \\\\ RBF for boundary} & elliptic PDEs \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{howard_genetic_2011}} & \\multilinecell{\\gls{gp}} & function value grid & \\multilinecell{convection–diffusion \\\\ equation \\\\ at different \\\\ Peclet numbers } \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{chaquet_solving_2012}} & \\multilinecell{\\gls{es}} & \\multilinecell{partial sum \\\\ of Fourier series} & \\multilinecell{testbench of \\\\ ODEs \\\\ system of ODEs \\\\ and PDEs} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{babaei_general_2013}} & \\multilinecell{\\gls{pso}} & \\multilinecell{partial sum\\\\of Fourier series} & \\multilinecell{integro-differential equation\\\\system of linear ODEs \\\\ Brachistochrone \\\\ nonlinear Bernoulli} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{panagant_solving_2014}} & \\multilinecell{\\gls{de}} & \\multilinecell{polynomial of \\\\ unspecified order} & \\multilinecell{set of 6 \\\\ different PDEs}  \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{sadollah_metaheuristic_2017}} & \\multilinecell{\\gls{pso}\\\\\\gls{hs}\\\\\\gls{wca}} & \\multilinecell{partial sum\\\\of Fourier series} & \\multilinecell{singular BVP} \\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{chaquet_using_2019}} & \\multilinecell{\\gls{cma_es}\\\\(global); \\\\ \\gls{ds}\\\\(local)} & \\multilinecell{linear combination \\\\ of Gaussian kernels} & \\multilinecell{testbench of \\\\ ODEs \\\\ system of ODEs \\\\ and PDEs}\\\\ \\hline\n\t\t\t\n\t\t\t\\multilinecell{\\cite{fateh_differential_2019}} & \\multilinecell{\\gls{de}} & \\multilinecell{function value\\\\grid} & elliptic PDEs \\\\ \\hline\n\t\t\t\n\t\t\\end{tabular}\n\t}\n\t\\unterschrift{Literature research on the general topic of stochastic solver and their application. The papers are sorted by date of release. }{}{}\n\t\\label{tab:literature_research}\n\\end{table}\n\n\n\\section{Differential Evolution}\n\nThe differential evolution framework was first introduced in \\cite{storn_differential_1997}. Due to its simple and flexible structure, it quickly became one of the most successful evolutionary algorithm. Over the years, several adaptations to the original framework have been proposed and some of them currently count to the best performing algorithms, as the 100-Digit Challenge at GECCO 2019 (\\cite{suganthan_suganthancec2019_2020}) shows. \n\nThe main \\gls{de} framework consists of three necessary steps that continuously update a population of possible solutions. The population can be interpreted as a matrix, where each row-vector $\\mathbf{x}_i$, also called individual, represents a point within the search domain and has a fitness value corresponding to the fitness function $f(\\mathbf{x}_i): \\mathbb{R}^n \\rightarrow \\mathbb{R}$. The goal is to minimise the fitness function. These steps are performed in a loop until a predefined termination condition is reached. Each individual step is controlled by a user-defined parameter: \n\\begin{itemize}\n\t\\item \\underline{Mutation}: \\\\\n\t\t  Mutation strength parameter F;\\\\\n\t\t  The mutation uses the information from within the population to create a trial vector $v_i$. This is done by scaling the difference between some vectors in the population - hence the name \\textit{differential} evolution. The \\textit{/current-to-pbest/1} mutation operator can be seen in equation \\eqref{eq:mut_rand_1} where $x_i$ is the current individual, $x_{best}^p$ is one random vector of the p\\% top vectors, $x_{r1}$ is a random vector from the population while $\\tilde{x}_{r2}$ is randomly chosen from the population and the archive. $x_{r1}$ and $\\tilde{x}_{r2}$ must not describe the same individual.\n\t\t  \\begin{equation}\n\t\t  \\label{eq:mut_rand_1}\n\t\t  v_i = x_{i} + F_i(x_{best}^p - x_{i}) + F_i(x_{r1} - \\tilde{x}_{r2})\n\t\t  \\end{equation}\n\t\\item \\underline{Crossover}: \\\\\n\t\t  Crossover probability parameter CR;\\\\\n\t\t  The crossover procedure randomly mixes the information between the trial vector $v_i$ and a random candidate from the population $x_{i}$ to create a new trial vector $u_i$. The binomial crossover from equation \\eqref{eq:crs_bin} randomly takes elements from both vectors, where $K$ is a random index to ensure that at least one element from the trial vector $v_i$ is taken.\n\t\t  \\begin{equation}\n\t\t  \\label{eq:crs_bin}\n\t\t  u_{ij}=\\begin{cases}\n\t\t  v_{ij}, &\\text{if $j = K \\lor rand[0,1] \\leq CR$}\\\\\n\t\t  x_{ij}, &\\text{otherwise}\n\t\t  \\end{cases}\n\t\t  \\end{equation}\n\t\\item \\underline{Selection}: \\\\\n\t\t  Population size N;\\\\\n\t\t  The selection replaces the old candidate $x_i$ if the trial candidate $u_i$ is better as measured by the fitness function. This is performed for every individual in the population, then the next generation is started.\n\\end{itemize}  \n\nIn modern \\gls{de} variants, these parameters are self-adapted during the evolutionary process. This means that the algorithms can balance out between exploration of the search-space and exploitation of promising locations. \n\nA prominent example of a modern \\gls{de} with self-adaption is JADE, which was developed by \\cite{zhang_jade_2009}. The adaption is performed by taking successful F and CR values of the last generation into account. If a certain setting is successful in generating better candidates, newly selected F and CR gravitate towards that setting. The pseudocode is presented in the appendix \\ref{chap:pscode_jade}. \n\nThis idea was later refined by \\cite{tanabe_success-history_2013}. They propose a similar self-adaptive scheme but extend the ``memory'' for good F and CR parameters over multiple generations. This idea improves the robustness as compared to JADE. The pseudocode in appendix \\ref{chap:pscode_shade} shows the outline of this so called SHADE algorithm. \n\nThe latest iteration of SHADE is called L-SHADE (\\cite{tanabe_improving_2014}), which improves the performance by including a deterministic adaptive concept for the population size. At first, L-SHADE starts with a big population size, and reduces the number of individuals in a linear fashion by deleting bad candidates. This has the effect of reducing the number of unnecessary function evaluations. The code is displayed in the appendix \\ref{chap:pscode_lshade}. \n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "87a1b36b4066164d9f7d060fc2c93b33b5dd240b", "size": 26304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "master_thesis_doc/tex/State_of_the_Art.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_doc/tex/State_of_the_Art.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_doc/tex/State_of_the_Art.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": 109.6, "max_line_length": 1380, "alphanum_fraction": 0.7553984185, "num_tokens": 7144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.637520448720776}}
{"text": "%% -*- coding:utf-8 -*-\n\\chapter{Objects and morphisms}\n\n\\section{Equality}\n\nThe important question is how can we decide whenever an\nobject/morphism is equal to another object/morphism? The trivial\nanswer is possible if an \\mynameref{def:object} is a\n\\mynameref{def:set}. In the case we can say that 2 objects are equal\nif they contain the equivalent collection of elements. Unfortunately\nwe cannot do the same trick for categorical \\mynameref{def:object}s as\nsoon as they don't have any internal \nstructure but can use a \\mynameref{def:categorical_approach} (see \n\\mynameref{rem:set_vs_category}): if we cannot use ``microscope'' lets\nuse ``telescope'' and define the equality of objects and morphisms of\na category $\\cat{C}$ in the terms of whole $\\cathom{C}$.\n\n\\begin{definition}[Objects equality]\n\\label{def:object_equality}\nTwo \\mynameref{def:object}s $a$ and $b$ in \\mynameref{def:category}\n$\\cat{C}$ are equal if there exists an unique\n\\mynameref{def:isomorphism} $a \\cong_f b$. This also means that\nalso exist unique isomorphism $b \\cong_g a$. These two\n\\mynameref{def:morphism}s ($f$ and $g$) are related each other via \nthe following equations: $f \\circ g = \\idm{a}$ and $g \\circ f\n= \\idm{b}$. \n\\end{definition}\n\nUnlike \\mynameref{def:function}s between \\mynameref{def:set}s we don't\nhave any additional info \n\\footnote{\nfor instance info about sets internals. i.e. which elements of the sets\nare connected by the considered functions\n}\nabout \\mynameref{def:morphism}s except\ncategory theory axioms which the morphisms satisfy \n\\cite{bib:stackexchange:morphism:equality}. This leads us to the\nfollowing definition of morphims equality:\n\\begin{definition}[Morphisms equality]\n\\label{def:morphism_equality}\nTwo \\mynameref{def:morphism}s $f$ and $g$ in \\mynameref{def:category}\n$\\cat{C}$ are equal if the equality can be derived from the base axioms: \n\\begin{itemize}\n\\item \\mynameref{axm:composition}\n\\item \\mynameref{axm:associativity}\n\\item \\mynameref{def:id}: \\eqref{eq:leftid}, \\eqref{eq:rightid}\n\\end{itemize}\nor \\mynameref{def:commutative_diagram}s which postulate the equality.\n\\end{definition}\nAs an example lets proof the following theorem\n\\begin{theorem}[Identity is unique]\n\\label{thm:identity_unique}\nThe \\mynameref{def:id} is unique.\n\\begin{proof}\nConsider an \\mynameref{def:object} $a$ and it's \\mynameref{def:id} \n$\\idm{a}$. Let $\\exists f: a \\to a$ such that $f$ is also\nidentity. In the case \\eqref{eq:leftid} for $f$ as identity gives\n\\[\nf \\circ \\idm{a} = \\idm{a}.\n\\]\nFrom other side \\eqref{eq:rightid} for $\\idm{a}$ satisfied\n\\[\nf \\circ \\idm{a} = f\n\\]\ni.e.\n\\[\nf = f \\circ \\idm{a} = \\idm{a}\n\\] \nor\n$f = \\idm{a}$.\n\\end{proof}\n\\end{theorem}\n\n\\section{Initial and terminal objects}\n\\begin{definition}[Initial object]\n\\label{def:initial_object}\nLet $\\cat{C}$ is a \\mynameref{def:category}, the\n\\mynameref{def:object} $i \\in \\catob{C}$ is called\n\\textit{initial object} if $\\forall x \\in \\catob{C}\n\\exists! f_x: i \\to x \\in \\cathom{C}$.\n\\end{definition}\n\n\\begin{example}[Initial object][\\textbf{Set}]\n\\label{ex:set_initial_object}\nNote that there is only one function from empty set to any other sets\n\\cite{bib:proofwiki:Empty_Mapping_is_Unique} that makes the empty set\nas the \\mynameref{def:initial_object} in \\mynameref{def:setcategory}. \n\\end{example}\n\n\\begin{definition}[Terminal object]\n\\label{def:terminal_object}\nLet $\\cat{C}$ is a \\mynameref{def:category}, the\n\\mynameref{def:object} $t \\in \\catob{C}$ is called\n\\textit{terminal object} if $\\forall x \\in \\catob{C}\n\\exists! g_x: x \\to t \\in \\cathom{C}$.\n\\end{definition}\n\n\\begin{example}[Terminal object][\\textbf{Set}]\n\\label{ex:set_terminal_object}\n\\mynameref{def:terminal_object} in \\mynameref{def:setcategory} is a set\nwith one element i.e \\mynameref{def:singleton_set}. \n\\end{example}\n\nAs you can see the initial and terminal objects are opposite each\nother. I.e. if $i$ is an \\mynameref{def:initial_object} in $\\cat{C}$\nthen it will be \\mynameref{def:terminal_object} in\nthe \\mynameref{def:op_category} $\\cat{C^{op}}$.\n\n\\begin{theorem}[Initial object is unique]\n\\label{thm:initial_object_unique}\nLet $\\cat{C}$ is a category and $i, i' \\in \\catob{C}$ two\n\\mynameref{def:initial_object}s then there exists an unique\n\\mynameref{def:isomorphism} $u: i \\to i'$ (see\n\\mynameref{def:object_equality}) \n\\begin{proof}\nConsider the following \\mynameref{def:commutative_diagram} (see\n\\cref{fig:initial_object_unique}). As soon as $i$ initial object\n$\\exists! \\, u: i \\to i'$. From other side $i'$ is also initial object\nand therefore $\\exists! \\, u^{-1}: i' \\to i$. Combining them together\nvia composition we can get $u^{-1} \\circ u: i \\to i$ and $u \\circ\nu^{-1}: i' \\to i'$. From the fact that $i$ is initial object one can\nget that there exists\nonly one morphism $\\idm{i}: i \\to i$. The same is the truth for $i'$.\nTherefore $u^{-1} \\circ u = \\idm{i}$ and $u \\circ u^{-1} = \\idm{i'}$.\nThese complete the commutative diagram build and finishes the proof. \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[ele,label=above:$i$] (i1) at (0,3) {};    \n    \\node[ele,label=above:$i'$] (i2) at (3,3) {};    \n    \\node[ele,label=below:$i$] (i12) at (3,0) {};\n    \\node[ele,label=below:$i'$] (i22) at (6,0) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (i1) to\n    node[sloped,above]{$u$} (i2);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (i12) to\n    node[sloped,above]{$u$} (i22); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (i1) to\n    node[sloped,above]{$\\idm{i}$} (i12); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (i2) to\n    node[sloped,above]{$\\idm{i'}$} (i22); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (i2) to\n    node[right]{$u^{-1}$} (i12); \n  \\end{tikzpicture}\n  \\caption{Commutative diagram for initial object uniqueness  proof}\n  \\label{fig:initial_object_unique}\n\\end{figure}\n\\end{proof}\n\\end{theorem}\n\n\\begin{theorem}[Terminal object is unique]\n\\label{thm:terminal_object_unique}\nLet $\\cat{C}$ is a category and $t, t' \\in \\catob{C}$ two\n\\mynameref{def:terminal_object}s then there exists an unique\n\\mynameref{def:isomorphism} $v: t' \\to t$ (see\n\\mynameref{def:object_equality}) \n\\begin{proof}\nJust got to the \\mynameref{def:op_category} and revert arrows in\n\\cref{fig:initial_object_unique}. The result shown on\n\\cref{fig:terminal_object_unique} and it proofs the theorem statement.\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[ele,label=above:$t$] (t1) at (0,3) {};    \n    \\node[ele,label=above:$t'$] (t2) at (3,3) {};    \n    \\node[ele,label=below:$t$] (t12) at (3,0) {};\n    \\node[ele,label=below:$t'$] (t22) at (6,0) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (t2) to\n    node[sloped,above]{$v$} (t1);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (t22) to\n    node[sloped,above]{$v^{-1}$} (t12); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (t12) to\n    node[sloped,above]{$\\idm{t}$} (t1); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (t22) to\n    node[sloped,above]{$\\idm{t'}$} (t2); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (t12) to\n    node[right]{$v^{-1}$} (t2); \n  \\end{tikzpicture}\n  \\caption{Commutative diagram for terminal object uniqueness proof}\n  \\label{fig:terminal_object_unique}\n\\end{figure}\n\\end{proof}\n\\end{theorem}\n\n\\begin{example}[Toy example]\nIn our toy example \\cref{fig:pl_example} the type String is\n\\mynameref{def:initial_object} and type Bool is the\n\\mynameref{def:terminal_object}.\n\\end{example}\n\n\\section{Product and sum}\nThe pair of 2 objects is defined via the universal property in\nthe following way:\n\\begin{definition}[Product]\n\\label{def:product}\nLet we have a category $\\cat{C}$ and $c_1, c_2 \\in \\catob{C}$ -two\n\\mynameref{def:object}s then the product of the objects $c_1, c_2$ is\nanother object in $\\cat{C}$ $c = c_1 \\times c_2$ with 2\n\\mynameref{def:morphism}s $\\pi_1, \\pi_2$ such that $c_1 = \\pi_1(c),\nc_2 = \\pi(c_2)$ and the  \nfollowing universal property is satisfied: $\\forall c' \\in \\catob{C}$\nand morphisms $\\pi'_1: c' \\to c_1, \\pi'_2: c' \\to c_2$, exists unique\nmorphism $h$ such that the following diagram (see \\cref{fig:product})\ncommutes, i.e. $\\pi'_1 = \\pi_1 \\circ h, \\pi'_2 = \\pi_2 \\circ h$.\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[ele,label=left:$c_1$] (a) at (0,0) {};    \n    \\node[ele,label=right:$c_2$] (b) at (4,0) {};    \n    \\node[ele,label=below:$c$] (c) at (2,0) {};\n    \\node[ele,label=above:$c'$] (c') at (2,3) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (c) to\n    node[sloped,above]{$\\pi_1$} (a);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (c) to\n    node[sloped,above]{$\\pi_2$} (b); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (c') to\n    node[sloped,above]{$\\pi'_1$} (a); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (c') to\n    node[sloped,above]{$\\pi'_2$} (b); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (c') to\n    node[right]{$h$} (c); \n  \\end{tikzpicture}\n  \\caption{Product $c = c_1 \\times c_2$. $\\forall c, \\exists! h \\in\n    \\cathom{C}: \\pi'_1 = \\pi_1 \\circ h, \\pi'_2 = \\pi_2 \\circ h$.}\n  \\label{fig:product}\n\\end{figure}\nIn other words $h$ factorizes $\\pi'_{1,2}$.\n\\end{definition}\n\n\\begin{example}[Product][\\textbf{Set}]\n\\label{ex:set_product}\nThe \\mynameref{def:product} of two sets $A$ and $B$ in\n\\mynameref{def:setcategory} is defined \nas a \\mynameref{def:cartesian_product}: $A \\times B = \\{(a,b)| a \\in A, b \\in B\\}$. \n\\end{example}\n\nIf we invert arrows in \\mynameref{def:product} we will got another\nobject definition that is called sum\n\n\\begin{definition}[Sum]\n\\label{def:sum}\nLet we have a category $\\cat{C}$ and $c_1, c_2 \\in \\catob{C}$ -two\n\\mynameref{def:object}s then the sum of the objects $c_1, c_2$ is\nanother object in $\\cat{C}$ $c = c_1 \\oplus c_2$ with 2\n\\mynameref{def:morphism}s $i_1, i_2$ such that $c = i_1(c_1), c = i_2\n(c_2)$ and the \nfollowing universal property is satisfied: $\\forall c' \\in \\catob{C}$\nand morphisms $i'_1: c_1 \\to c', i'_2: c_2 \\to c'$, exists unique\nmorphism $h$ such that the following diagram (see \\cref{fig:sum})\ncommutes, i.e. $i'_1 = h \\circ i_1, i'_2 = h \\circ i_2$.\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[ele,label=left:$c_1$] (a) at (0,0) {};    \n    \\node[ele,label=right:$c_2$] (b) at (4,0) {};    \n    \\node[ele,label=below:$c$] (c) at (2,0) {};\n    \\node[ele,label=above:$c'$] (c') at (2,3) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to\n    node[sloped,above]{$i_1$} (c);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (b) to\n    node[sloped,above]{$i_2$} (c); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (a) to\n    node[sloped,above]{$i'_1$} (c'); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (b) to\n    node[sloped,above]{$i'_2$} (c'); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (c) to\n    node[right]{$h$} (c'); \n  \\end{tikzpicture}\n  \\caption{Sum $c = c_1 \\oplus c_2$. $\\forall c, \\exists! h \\in\n    \\cathom{C}: i'_1 = h \\circ i_1, i'_2 = h \\circ i_2 $.}\n  \\label{fig:sum}\n\\end{figure}\nIn other words $h$ factorizes $i'_{1,2}$.\n\\end{definition}\n\n\\begin{definition}[Disjoint union]\n  \\label{def:disjoint_union}\n  Let $\\{A_i: i \\in I\\}$ be a family of sets \n  indexed by $I$. The \n  \\textit{disjoint union} \\cite{wiki:disjointunion} of this family is\n  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\\end{definition}\n\n\\begin{example}[Sum][\\textbf{Set}]\n  \\label{ex:set_sum}\n  The \\mynameref{def:sum} of two sets $A$ and $B$ in\n  \\mynameref{def:setcategory} is defined as\n  \\mynameref{def:disjoint_union}.  \n\\end{example}\n\nThe \\mynameref{def:product} of objects will provide also a definition\nfor product of morphisms\n\\begin{definition}[Product of morphisms]\n\\label{def:product_of_morphisms}\nLet $\\cat{C}$ is a category and $a,a' \\in \\catob{C}$ and \n$b, b' \\in \\catob{C}$ are 2 pairs of \\mynameref{def:object}s that admit\n\\cref{def:product}. Consider 2 morphisms that connects the objects: \n$f: a \\to b, f': a' \\to b'$ then we can create a new unique morphism that\nconnects the products: $f \\times f': a \\times a' \\to b \\times b'$ and\nmakes the diagram commute (see \\cref{fig:product_of_morphisms}). \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[ele,label=above:$a$] (a) at (0,2) {};    \n    \\node[ele,label=above:$a \\times a'$] (aa') at (2,2) {};    \n    \\node[ele,label=above:$a'$] (a') at (4,2) {};    \n    \\node[ele,label=below:$b$] (b) at (0,0) {};    \n    \\node[ele,label=below:$b \\times b'$] (bb') at (2,0) {};    \n    \\node[ele,label=below:$b'$] (b') at (4,0) {};    \n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a) to\n    node[sloped,above]{$f$} (b);\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (a') to\n    node[sloped,above]{$f'$} (b');\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (aa') to\n    node[sloped,above]{$f \\times f'$} (bb');\n\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (aa') to\n    node[sloped,above]{$\\pi_a$} (a);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (aa') to\n    node[sloped,above]{$\\pi_{a'}$} (a'); \n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (bb') to\n    node[sloped,above]{$\\pi_b$} (b);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (bb') to\n    node[sloped,above]{$\\pi_{b'}$} (b'); \n  \\end{tikzpicture}\n  \\caption{Product of morphisms.}\n  \\label{fig:product_of_morphisms}\n\\end{figure}\n\\end{definition} \n\n\\section{Category as a monoid}\nConsider the following definition from abstract algebra\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\nWe can consider 2 \\mynameref{def:monoid}s. The first one has\n\\mynameref{def:product} as the binary operation and\n\\mynameref{def:terminal_object} as the identity element. As result we\njust got an analog of multiplication in the category theory. This is why\nthe terminal object is often denoted as $\\mathbf{1}$ and the operation\nis called as the product. \n\nAnother one is additional \\mynameref{def:monoid} that has\n\\mynameref{def:initial_object} as the identity element and the\n\\mynameref{def:sum} as the binary operation. The initial object in\nthat case  is often denoted as $\\mathbf{0}$. I.e. we can see a direct\nconnection with addition in algebra.\n\nIf we do such consideration then we can make a step forward and look\nat the distributive law that sum and multiplication satisfy.\n\\begin{definition}[Distributive category]\n\\label{def:distributive_category}\nA category $\\cat{C}$ is \\textit{distributive} if \n\\cite{wiki:distributive_category}\nit has finite\n\\mynameref{def:product}s and \\mynameref{def:sum}s such that \n$\\forall a,b,c \\in \\catob{C}$:\n\\[\na \\times b \\oplus a \\times c \\cong a \\times ( b \\oplus c )\n\\]\nand \n\\[\na \\times 0 \\cong 0\n\\]\nwhere $\\mathbf{0}$ is the \\mynameref{def:initial_object}.\n\\end{definition} \n\n\\begin{example}[Distributive category]\n\\label{ex:distributive_category}\n\\mynameref{def:setcategory} is an example \n\\cite{wiki:distributive_category}\nof \\mynameref{def:distributive_category}\n\nFrom other hand not all categories which have both product and sum are\ndistributive. One of such example is a category of all groups\n\\cite{wiki:distributive_category} \n$\\cat{Grp}$ where groups are considered as objects and group\nhomomorphisms as morphisms. \n\\end{example}\n\n\\section{Exponential}\nWe are going to talk about functions (aka morphisms) as\n\\mynameref{def:object}s. \n\n\\begin{example}[Hom set]\n\\label{ex:homset}\nConsider 2 sets $A$ and $B$ the set of functions between the 2 sets\nform a new set that is called as \\textit{Hom-set} and denoted as $A\n\\to B$. Thus if $A,B \\in \\catob{Set}$ then the Hom-set will also $A\n\\to B \\in \\catob{Set}$. \n\\end{example}\n\nThe construction of \\mynameref{ex:homset} is applied to\n\\mynameref{def:setcategory} but not to an arbitrary category because\nthe Hom-set is a set and therefore the object in the \\textbf{Set}\ncategory. I.e. if $\\cat{C}$ is a category and $a, b \\in \\catob{C}$\nthen the Hom-set $a \\to b \\in \\catob{Set}$ but we now want to\nconstruct something like to the Home-set but that is an object in\n$\\cat{C}$. This will be called as the function object. We will use the\nuniversal construction for the object definition.\n\n\\begin{definition}[Exponential]\n\\label{def:exponential}\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[ele,label=above:$z'$] (z1) at (0,3) {};    \n    \\node[ele,label=below:$z^y$] (zy) at (0,0) {};    \n    \\node[ele,label=above:$z' \\times y$] (z1y) at (3,3) {};\n    \\node[ele,label=below:$z^y \\times y$] (zyy) at (3,0) {};\n    \\node[ele,label=below:$z$] (z) at (6,0) {};\n\n    \\draw[->,thick,shorten <=2pt,shorten >=2pt] (z1) to\n    node[left]{$h$} (zy);\n    \\draw[->,thick,shorten <=2pt,shorten >=2] (z1y) to\n    node[left]{$h \\times \\idm{y}$} (zyy); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (z1y) to\n    node[sloped,above]{$e'$} (z); \n    \\draw[->,thick,shorten <=2pt,shorten >=2] (zyy) to\n    node[sloped,above]{$e$} (z); \n  \\end{tikzpicture}\n  \\caption{Exponential object}\n  \\label{fig:exponential}\n\\end{figure}\nLet $\\cat{C}$ is a category and $z, y \\in \\catob{C}$. We also assume\nthat $\\cat{C}$ allows all \\mynameref{def:product}s with $y$, i.e.\n$\\forall z' \\in \\catob{C}, \\exists z' \\times y$. An object $z^y$\ntogether with a \\mynameref{def:morphism} $e: z^y \\times y \\to z$ is \nan \\textit{exponential object} if $\\forall e' \\in \\cathom{C}$ and\n$\\forall z' \\in \\catob{C}$ exists an\nunique morphism $h: z' \\to z$ such that the\n\\mynameref{def:commutative_diagram} shown in \\cref{fig:exponential}\ncommutes:\n\\[\ne' = e \\circ \\left(h \\times \\idm{y} \\right)\n\\]\n\\end{definition}\n\n\\begin{example}[Exponential][\\textbf{Set}]\n\\label{ex:exponential_set}\nLets look at the \\mynameref{def:exponential} in $\\cat{Set}$. We want\nto show that the object corresponds to the function. Really if we want\nto define a function $f: X \\to Y$ then we should look at the\n\\mynameref{ex:homset} $F = X \\to Y$. $f \\in F$ - is an element of the\nHom-set. For the function application we have to take the argument $x\n\\in X$ and the function we want to apply $f \\in F$. Then we construct\nthe pair $(f,x) \\in F \\times X$. For the function application we have\nto call a \\mynameref{def:morphism} $e: F \\times X \\to Z$.\n\\footnote{$e$ from the word ``eval''}\nI.e. the\napplication $e(f, x)$ gives us $e(f, x) = y \\in Y$ - the function\nvalue. \n\\end{example}\n\n\\begin{definition}[Cartesian closed category]\n\\label{def:cartesian_closed_category}\nIf a category $\\cat{C}$ satisfies the following conditions then it is\ncalled \\textit{Cartesian closed category}\n\\begin{enumerate}\n\\item It has \\mynameref{def:terminal_object}\n\\item $\\forall a,b \\in \\catob{C}$ exists \\mynameref{def:product} $a\n  \\times b \\in \\catob{C}$.\n\\item $\\forall a,b \\in \\catob{C}$ exists \\mynameref{def:exponential}\n  $a^b \\in \\catob{C}$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}[Cartesian closed category]\n\\label{thm:ccc}\nIf $\\cat{C}$ is a \\mynameref{def:cartesian_closed_category} with\nfinite \\mynameref{def:sum} then it is a\n\\mynameref{def:distributive_category}.\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{theorem}\n\n\\section{Type algebra and Curry-Howard-Lambek correspondence}\n\\label{sec:curry_howard_lambek}\nThere is an interesting correspondence between computer programs and\nmathematical proofs. First of all consider a category of proofs\n\\subsection{\\textbf{Proof} category}\n\\begin{definition}[Proposition]\n\\label{def:proposition}\n\\textit{Proposition} is a statement that either true or false.\n\\end{definition}\n\nThere are 2 main propositions\n\\begin{definition}[True]\n\\label{def:true}\nA true statement is one that is correct, either in all cases or at\nleast in the sample case \\cite{bib:studycom:truefalse}. \n\\end{definition}\nand\n\\begin{definition}[False]\n\\label{def:false}\nA false statement is one that is not correct \\cite{bib:studycom:truefalse}. \n\\end{definition}\n\n\n\\begin{example}[Proposition]\n\\label{ex:proposition}\nThere is an example of correct (true) proposition\n\\[\n\\forall n \\in \\mathbb{R}: n^2 \\ge 0\n\\]\n\nThere is an example of incorrect (false) proposition\n\\[\n\\forall n \\in \\mathbb{C}: n^2 \\ge 0,\n\\]\nfor instance $i \\in \\mathbb{C}$ gives $i^2 = -1$.\n\n\\end{example}\n\n\\begin{definition}[Implication]\n\\label{def:implication} \\textit{An implication} is a\n\\mynameref{def:proposition} of the form $P \\implies Q$ i.e. if $P$\nthen $Q$ \\cite{bib:whatisaproof}.\n\\end{definition}\n\nThe main logical deduction rule is the following\n\\begin{definition}[Modus ponens]\n\\label{def:modusponens}\nIf $P$ is true and $P \\implies Q$ is true then $Q$ is also true. The\nrule is often written as \\cite{bib:whatisaproof}\n\\[\n\\frac{\n\\begin{array}{c}\nP \\\\\nP \\implies Q\n\\end{array}\n}{Q}\n\\]\nwhere if statements above the line are true then the statement below\nthe line is also true.\n\\end{definition}\n\n\\begin{definition}[Proof]\n\\label{def:proof}\n\\textit{Proof} is a verification \\cite{bib:whatisaproof} of a\n\\mynameref{def:proposition} by a chain of logical deduction from a\nbase set of axioms.\n\\end{definition}\n\nPropositions can be combined into new propositions via the following\nlogical operations\n\\begin{definition}[Conjunction]\n\\label{def:conjunction}\nConjunction or logical AND is the operation with following rules\n  \\begin{table}[H]\n    \\centering\n    \\caption{Conjunction}\n    \\label{tab:conjunction}\n      \\begin{tabular}{|l|l|l|}\n        \\hline\n        $a$ & $b$ & $a \\land b$ \\\\ \\hline\n        True & True & True \\\\ \\hline\n        True & False & False \\\\ \\hline\n        False & True & False \\\\ \\hline\n        False & False & False \\\\ \\hline\n      \\end{tabular}\n  \\end{table}\n\\end{definition}\n\\begin{definition}[Disjunction]\n\\label{def:disjunction}\nConjunction or logical OR is the operation with following rules\n  \\begin{table}[H]\n    \\centering\n    \\caption{Disjunction}\n    \\label{tab:disjunction}\n      \\begin{tabular}{|l|l|l|}\n        \\hline\n        $a$ & $b$ & $a \\lor b$ \\\\ \\hline\n        True & True & True \\\\ \\hline\n        True & False & True \\\\ \\hline\n        False & True & True \\\\ \\hline\n        False & False & False \\\\ \\hline\n      \\end{tabular}\n  \\end{table}\n\\end{definition}\n\nOperations in Boolean logic follow the distributive low:\n\\begin{equation}\na \\land ( b \\lor c) = (a \\land b) \\lor (a \\land c) \n\\nonumber\n\\end{equation}\ni.e. the operation $\\land$ corresponds to multiplication and $\\lor$ to\nsum. Therefore the $\\cat{Proof}$ can be considered as a\n\\mynameref{def:distributive_category}. \n\n\\begin{definition}[\\textbf{Proof} category]\n\\label{def:proof_category}\nThe $\\cat{Proof}$ category is a category where \\mynameref{def:proposition}s are\n\\mynameref{def:object}s and \\mynameref{def:proof}s are\n\\mynameref{def:morphism}s. I.e. proofs are used as connectors between\ndifferent propositions.\n\\end{definition}\n\nConsider different objects and constructions of the proof (logic)\ntheory from the categorical point of view\n\\begin{example}[Initial object][\\textbf{Proof}]\n\\label{ex:proof_initial_object}\nThe \\textit{false} statement can be considered as the initial object\nbecause for any other statement exists only one proof from the false\nstatement to that one.\n\\end{example}\n\n\\begin{example}[Terminal object][\\textbf{Proof}]\n\\label{ex:proof_terminal_object}\nThe \\textit{true} statement can be considered as the terminal object\n\\end{example}\n\n\\begin{example}[Product][\\textbf{Proof}]\n\\label{ex:proof_product}\n\\mynameref{def:conjunction} can be considered as\n\\mynameref{def:product} in \\mynameref{def:proof_category}.\n\\end{example}\n\n\\begin{example}[Sum][\\textbf{Proof}]\n\\label{ex:proof_sum}\n\\mynameref{def:disjunction} can be considered as\n\\mynameref{def:sum} in \\mynameref{def:proof_category}.\n\\end{example}\n\nThus we can declare the following correspondence (see\n\\cref{tab:curry_howard_lambek}) between logic \nproofs and \\mynameref{def:cartesian_closed_category} and therefore\nalso between programming languages.\n\\begin{table}[H]\n  \\centering\n  \\caption{Relation between logic proofs and programming languages}\n  \\label{tab:curry_howard_lambek}\n  \\begin{adjustbox}{width=1\\textwidth}\n    \\small\n    \\begin{tabular}{l|l|l}\n      \\toprule\n      \\mynameref{def:proof_category} & Programming language & \n      \\mynameref{def:cartesian_closed_category}\\\\\n      \\midrule\n      \\mynameref{def:proposition}/\\mynameref{def:implication} & Type &\n      \\mynameref{def:object} \\\\ \n      \\mynameref{def:proof} & Function type & \\mynameref{def:exponential} \\\\\n      \\mynameref{def:conjunction} & Product type & \\mynameref{def:product} \\\\\n      \\mynameref{def:disjunction} & Sum type & \\mynameref{def:sum} \\\\\n      \\mynameref{def:true} & unit type & \\mynameref{def:terminal_object} \\\\\n      \\mynameref{def:false} & botom type & \\mynameref{def:initial_object} \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{adjustbox}\n\\end{table}\n\n\\subsection{\\textbf{Hask} category}\n\\begin{example}[Initial object][\\textbf{Hask}]\nIf we avoid lazy evaluations in Haskell (see\n\\mynameref{rem:hask_lazy_eval}) then we can found several types\nas candidates for initial and terminal object in Haskell. \n\\label{ex:hask_initial_object}\n\\mynameref{def:initial_object} in \\mynameref{def:haskcategory} is a\ntype without values \n\\begin{minted}{haskell}\ndata Void\n\\end{minted}\ni.e. you cannot construct a object of the type.\n\nThere is only one function from the initial object:\n\\begin{minted}{haskell}\nabsurd :: Void -> a\n\\end{minted}\nThe function is called absurd because it does absurd action. Nobody\ncan proof that it does not exist. For the existence proof the\nfollowing absurd argument can be used: ``Just provide me an object type\n\\mintinline{haskell}{Void} and I will provide you the result of\nevaluation''.  \n\nThere is no function in opposite direction because it would had been\nused for the \\mintinline{haskell}{Void} object creation. \n\\end{example}\n\n\\begin{example}[Terminal object][\\textbf{Hask}]\n\\label{ex:hask_terminal_object}\nTerminal object (unit) in \\mynameref{def:haskcategory} keeps only one element\n\\begin{minted}{haskell}\ndata () = ()\n\\end{minted}\ni.e. you can create only one element of the type. You can use the\nfollowing function for the creation:\n\\begin{minted}{haskell}\nunit :: a -> ()\nunit _ = ()\n\\end{minted}\n\\end{example}\n\n\\begin{example}[Product][\\textbf{Hask}]\n\\label{ex:hask_product}\nThe \\mynameref{def:product} in \\mynameref{def:haskcategory} keeps a\npair and the constructor defined as follows\n\\begin{minted}{haskell}\n(,) :: a -> b -> (a, b)\n(,) x y = (x, y)\n\\end{minted}\nThere are 2 projectors: \n\\begin{minted}{haskell}\nfst :: (a, b) -> a\nfst (x, _) = x\nsnd :: (a, b) -> b\nsnd (_, y) = y\n\\end{minted}\n\\end{example}\n\n\\begin{example}[Sum][\\textbf{Hask}]\n\\label{ex:hask_sum}\nThe \\mynameref{def:sum} in \\mynameref{def:haskcategory} defined as\nfollows \n\\begin{minted}{haskell}\ndata Either a b = Left a | Right b\n\\end{minted}\n\nThe typical usage is via pattern matching for instance \n\\begin{minted}{haskell}\nfactor :: (a -> c) -> (b -> c) -> Either a b -> c\nfactor f _ (Left x) = f x\nfactor _ g (Right y) = g y\n\\end{minted}\n\\end{example}\n\n\\begin{example}[Distributive category][\\textbf{Hask}]\nAs soon as $\\cat{Hask}$ is a \\mynameref{def:cartesian_closed_category}\nthen by \\cref{thm:ccc} it is a \\mynameref{def:distributive_category}\ni.e. one can conclude that\n\\begin{minted}{haskell}\n(a,Either b c)\n\\end{minted}\nis the same to\n\\begin{minted}{haskell}\nEither (a, b) (a, c)\n\\end{minted}\n\\end{example}\n\n\\begin{example}[Exponential][\\textbf{Hask}]\n\\label{ex:exponential_hask}\nIt's not surprisingly that the \\mynameref{def:exponential} in\n$\\cat{Hask}$ is a function object i.e. $b^a$ can be written as  \n\\mintinline{haskell}{a -> b}.\n\\end{example}\n\n\\begin{example}[Type algebra]\n\\cref{ex:exponential_hask} gives interesting results with types\nmanipulations. For instance the type $a^{b+c}$ can be written as\n\\begin{minted}{haskell}\nEither b c -> a\n\\end{minted}\nfor the function we should have both functions \n\\mintinline{haskell}{b -> a} and \\mintinline{haskell}{b -> c}. I.e.\nthe code is equivalent to the following one\n\\begin{minted}{haskell}\n(b -> a, c -> a)\n\\end{minted}\nThese transformations correspond to the following simple algebraic\nequation \n\\[\na^{b+c} = a^b a^c.\n\\]\nThis is also called as \\textit{type algebra}.\n\\end{example}\n\n\\subsection{\\textbf{C++} category}\n\\begin{example}[Initial object][\\textbf{C++}]\n\\label{ex:cpp_initial_object}\nIn C++ exists a special type that does not hold any values and as\nresult cannot be created: \\mintinline{c++}{void}.\nYou cannot create an object of that type i.e. you will get a compiler\nerror if you try.\n\\end{example}\n\n\\begin{example}[Terminal object][\\textbf{C++}]\n\\label{ex:cpp_terminal_object}\nC++ 17 introduced a special type that keeps only one value -\n\\mintinline{c++}{std::monostate}:  \n\\begin{minted}{c++}\nnamespace std {\n  struct monostate {};\n}\n\\end{minted}\n\\end{example}\n\n\\begin{example}[Product][\\textbf{C++}]\n\\label{ex:cpp_product}\nThe \\mynameref{def:product} in \\mynameref{def:cppcategory} keeps a\npair and the constructor defined as follows\n\\begin{minted}{c++}\nnamespace std {\n  template< class A, class B > struct pair {\n    A first;\n    B second;\n  };\n}\n\\end{minted}\n\nThere is a simple usage example\n\\begin{minted}{c++}\n  std::pair<int, bool> p(0, false);\n\n  std::cout << \"First projector: \" << p.first << std::endl;\n  std::cout << \"Second projector: \" << p.second << std::endl;\n\n\\end{minted}\nReally any \\mintinline{c++}{struct} or \\mintinline{c++}{class} can be\nconsidered as a product. \n\\end{example}\n\n\\begin{example}[Sum][\\textbf{C++}]\n  \\label{ex:cpp_sum}\n  If we consider \\mynameref{def:object}s as types then\n  \\mynameref{def:sum} is an object that can be either one or another\n  type. The corresponding C/C++ construction that provides an ability\n  to keep one of two types is \\mintinline{c++}{union}. \n\n  %% There is an \\mintinline{haskell}{Either} implementation from\n  %% \\mynameref{ex:hask_sum} \n  %% \\begin{minted}{c++}\n  %%   template <typename A, typename B> class Either\n  %%   {\n  %%   public:\n  %%     Either(const Either& e) : is_left_(e.is_left_){\n  %%       if (is_left_){\n  %%         data.l = e.data.l;      \n  %%       } else {\n  %%         data.r = e.data.r;      \n  %%       }    \n  %%     }\n  %%     ~Either(){\n  %%       if (is_left_){\n  %%         data.l.~A();      \n  %%       } else {\n  %%         data.r.~B();      \n  %%       }        \n  %%     }      \n  %%     Either(const A& l) : data(l), is_left_(true){\n  %%     }\n  %%     Either(const B& r) : data(r), is_left_(false){\n  %%     }\n  %%     const A& left() const {\n  %%       if (!is_left_){\n  %%         throw std::logic_error(\"no left\");      \n  %%       }    \n  %%       return data.l;    \n  %%     }\n  %%     const B& right() const {\n  %%       if (is_left_){\n  %%         throw std::logic_error(\"no right\");      \n  %%       }    \n  %%       return data.r;    \n  %%     }\n  %%   private:\n  %%     union Data {\n  %%       Data() {}\n  %%       Data( const A& a) : l(a) {}\n  %%       Data (const B& b) : r(b) {}\n  %%       ~Data() {}\n  %%       A l;\n  %%       B r;\n  %%     } data;       \n  %%     bool is_left_;  \n  %%   };\n  %% \\end{minted}\n  %% The usage example:\n  %% \\begin{minted}{c++}\n  %%   template <typename A, typename B, typename C, typename D>\n  %%   auto factor(A f, B g, const Either<C, D>& either) {\n  %%     try {\n  %%       return f(either.left());               \n  %%     }\n  %%     catch(...) {\n  %%       return g(either.right());                              \n  %%     }\n  %%   };\n    \n  %%   auto stringLength = [](std::string s) {\n  %%     return static_cast<int>(s.size()); };\n  %%   auto id = [](auto x) { return x; };\n          \n  %%   Either<std::string, int> str = std::string(\"abc\");\n  %%   std::cout << \"String length:\" <<\n  %%   factor<>(stringLength, id, str) << std::endl;\n  %%   Either<std::string, int> i = 4;\n  %%   std::cout << \"id(int):\" <<\n  %%   factor<>(stringLength, id, i) << std::endl;\n  %% \\end{minted}\n\n  C++17 suggests \\mintinline{c++}{std:variant} as a safe replacement\n  for \\mintinline{c++}{union}. The example of the \\mintinline{c++}{factor}\n  function is below\n  \\begin{minted}{c++}\n    template <typename A, typename B, typename C, typename D>\n    auto factor(A f, B g, const std::variant<C, D>& either) {\n      try {\n        return f(std::get<C>(either));               \n      }\n      catch(...) {\n        return g(std::get<D>(either));                              \n      }\n    };\n  \\end{minted}\n  The simple usage as follows:\n  \\begin{minted}{c++}\n    std::variant<std::string, int> var = std::string(\"abc\");\n    std::cout << \"String length:\" <<\n    factor<>(stringLength, id, var) << std::endl;\n    var = 4;\n    std::cout << \"id(int):\" <<\n    factor<>(stringLength, id, var) << std::endl;    \n  \\end{minted}\n\n\\end{example}\nTBD\n\\subsection{\\textbf{Scala} category}\n\\begin{example}[Initial object][\\textbf{Scala}]\n\\label{ex:scala_initial_object}\nWe used a same trick as for \\mynameref{ex:hask_initial_object} in\n\\mynameref{def:haskcategory} and define\n\\mynameref{def:initial_object} in \\mynameref{def:scalacategory} as a\ntype without values \n\\begin{minted}{scala}\nsealed trait Void\n\\end{minted}\ni.e. you cannot construct a object of the type.\n\\end{example}\n\n\\begin{example}[Terminal object][\\textbf{Scala}]\n\\label{ex:scala_terminal_object}\nWe used a same trick as for \\mynameref{ex:hask_terminal_object}\nin \\mynameref{def:haskcategory} and define\n\\mynameref{def:terminal_object} in \\mynameref{def:scalacategory} as a\ntype with only one value\n\\begin{minted}{scala}\nabstract final class Unit extends AnyVal\n\\end{minted}\nTBD\ni.e. you can create only one element of the type.\n\\end{example}\n\nTBD\n\n\\section{Quantum mechanics}\n\\begin{example}[Initial object][\\textbf{FdHilb}]\n\\label{ex:quant_initial_object}\nWe will use a Hilber space of dimensional 0 as the\n\\mynameref{def:initial_object}. I.e. the set that does not have any\nstates in it.\n\\end{example}\n\n\\begin{example}[Terminal object][\\textbf{FdHilb}]\n  \\label{ex:quant_terminal_object}\nWe will use a Hilber space of dimensional 1 as the\n\\mynameref{def:terminal_object}. I.e. the set of complex numbers\n$\\mathbb{C}$.   \n\\end{example}\n\n\\begin{example}[Product][\\textbf{FdHilb}]\n  \\label{ex:quant_product}\n  The \\mynameref{def:product} in \\mynameref{def:fdhilbcategory} is a\n  \\mynameref{def:fdhilb_direct_sum}.\n\\end{example}\n\n\\begin{example}[Sum][\\textbf{FdHilb}]\n  \\label{ex:quant_sum}\n  The \\mynameref{def:sum} in \\mynameref{def:fdhilbcategory} is a\n  \\mynameref{def:fdhilb_direct_sum}.\n\\end{example}\n\nTBD\n\n", "meta": {"hexsha": "ced9944914b23a310e987a008f1c3674e1b99da9", "size": 35577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cattheory/objectsmorphisms.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/objectsmorphisms.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/objectsmorphisms.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.5743440233, "max_line_length": 84, "alphanum_fraction": 0.67338449, "num_tokens": 11943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.6374658228443074}}
{"text": "\\section{Change of Bases, Canonical Forms and Symmetries}\r\n\\subsection{Change of Bases in General}\r\nRecall that given a linear operator $T:V\\to W$, we can write its matrix form once we have specified the bases $\\{\\underline{e_1},\\underline{e_2},\\ldots,\\underline{e_n}\\}$ and $\\{\\underline{f_1},\\underline{f_2},\\ldots,\\underline{f_m}\\}$ for $V,W$.\r\nSo $T(\\underline{e_i})=A_{ai}\\underline{f_a}$ for some matrix $A$,\r\nFor other bases $\\{\\underline{e_i'}\\}$ and $\\{\\underline{f_i'}\\}$ for $V,W$, we have a matrix $A'$ with $T(\\underline{e_i'})=A'_{ai}\\underline{f_a'}$.\r\nSuppose the bases are related by $\\underline{e_i'}=P_{ji}\\underline{e_j}, \\underline{f_a'}=Q_{ba}\\underline{f_b}$.\r\nSo $P,Q$ are invertible and\r\n\\begin{proposition}\r\n    $A'=Q^{-1}AP$.\r\n\\end{proposition}\r\nWe say $P,Q$ constitutes a change of bases.\r\nThe column $i$ of $A$ consists of components of $T(\\underline{e_i})$ with respect to the basis $\\{\\underline{f_a}\\}$, column $i$ of $P$ consists of components of new basis vectors with respect to the old basis, similar for $Q$.\r\n\\begin{example}\r\n    Let $\\dim V=n=2$, $\\dim W=m=3$, and consider the linear map $T$ with $T(\\underline{e_1})=\\underline{f_1}+2\\underline{f_2}-\\underline{f_3}$ and $T(\\underline{e_2})=-\\underline{f_1}+2\\underline{f_2}+\\underline{f_3}$, so $T$ has matrix\r\n    $$A=\\begin{pmatrix}\r\n        1&-1\\\\\r\n        2&2\\\\\r\n        -1&1\r\n    \\end{pmatrix}$$\r\n    Under these choice of bases.\r\n    Now consider the new basis $\\underline{e_i'}$ for $V$ by\r\n    $$\\underline{e_1'}=\\underline{e_1}-\\underline{e_2},\\underline{e_2'}=\\underline{e_1}+\\underline{e_2}$$\r\n    which yields a changes of basis matrix\r\n    $$P=\\begin{pmatrix}\r\n        1&1\\\\\r\n        -1&1\r\n    \\end{pmatrix}$$\r\n    And a new basis $\\underline{f_i'}$ for $W$ is defined by $$\\underline{f_1'}=\\underline{f_1}-\\underline{f_3},\\underline{f_2'}=\\underline{f_2},\\underline{f_3'}=\\underline{f_1}+\\underline{f_3}$$\r\n    which has a matrix\r\n    $$Q=\\begin{pmatrix}\r\n        1&0&1\\\\\r\n        0&1&0\\\\\r\n        -1&0&1\r\n    \\end{pmatrix}$$\r\n    So the change of basis formula gives\r\n    $$A'=Q^{-1}AP=\\begin{pmatrix}\r\n        2&0\\\\\r\n        0&4\\\\\r\n        0&0\r\n    \\end{pmatrix}$$\r\n    which can be verified by direct calculation.\r\n\\end{example}\r\n\\begin{proof}\r\n    For vectors $\\underline{y},\\underline{x}$ with $\\underline{y}=A\\underline{x}$ for some invertible matrix (representing a basis) $A$, we denote the components in the respective components by\r\n    $$X=\\begin{pmatrix}\r\n        x_1\\\\\r\n        x_2\\\\\r\n        \\vdots\\\\\r\n        x_n\r\n    \\end{pmatrix},Y=\\begin{pmatrix}\r\n        y_1\\\\\r\n        y_2\\\\\r\n        \\vdots\\\\\r\n        y_n\r\n    \\end{pmatrix}$$\r\n    to avoid confusion.\r\n    So for a change of basis by matrix $P,Q$, the formula $Y=AX$ turns to $Y'=A'X'$, hence, we have $\\underline{x}=x_i\\underline{e_i}=x_j'\\underline{e_j'}=x_j'(\\underline{e_i}P_{ij})=P_{ij}x_j'\\underline{e_i}$.\r\n    Therefore $X=PX'$, similarly $Y=QY'$, so $A'X'=Y'=Q^{-1}Y=Q^{-1}AX=(Q^{-1}AP)X'$, so $A'=Q^{-1}AP$\r\n\\end{proof}\r\nIn the special cases where $V=W$ and the bases are the same for $V,W$ before and after the change of basis, then $A$ is transformed to a matrix similar to $A$ by that change-of-basis matrix.\r\nNote that this can justify immediately that $\\operatorname{tr}A'=\\operatorname{tr}A,\\det A'=\\det A,\\chi_{A'}=\\chi_A$ for similar matrices $A,A'$.\\\\\r\nIf $V=W=\\mathbb F^n$ where $\\mathbb F=\\mathbb R$ or $\\mathbb C$.\r\nFor a diagonalizable matrix $M$, then by changing the standard basis into the eigenbasis, $M$ becomes diagonal.\r\n\\begin{proof}[Alternative proof]\r\n    Take the linear map $T$, then\r\n    $$\\underline{f_a}Q_{ab}A'_{bi}=\\underline{f_b'}A'_{bi}=T(\\underline{e_i'})=T(\\underline{e_j}P_{ji})=P_{ji}T(\\underline{e_j})=\\underline{f_a}A_{aj}P_{ji}$$\r\n    So $AP=QA'$ by considering the coefficient of $\\underline{f_a}$.\r\n\\end{proof}\r\n\\subsection{Jordan Canonical/Normal Form}\r\nThis result classifies complex $n\\times n$ matrices up to similarity (i.e. conjugacy classes).\r\n\\begin{proposition}\r\n    Any $2\\times 2$ complex matrix $A$ is similar to one of the followings:\r\n    $$\r\n    \\begin{pmatrix}\r\n        \\lambda_1&0\\\\\r\n        0&\\lambda_2\r\n    \\end{pmatrix},\\lambda_1\\neq\\lambda_2;\r\n    \\begin{pmatrix}\r\n        \\lambda&0\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix};\r\n    \\begin{pmatrix}\r\n        \\lambda&1\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix}\r\n    $$\r\n    Where $\\lambda_1,\\lambda_2,\\lambda\\in\\mathbb C$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $A$ is diagonalizable (which includes the case where $\\chi_A$ has two distinct roots) then the proposition is immediate.\r\n    Otherwise, $\\chi_A(t)=c(t-\\lambda)^2,c\\neq 0$ and $\\operatorname{null}(A-\\lambda I)=1$ and we shall show that $A$ is similar to a matrix of the third form.\r\n    Indeed, let $\\underline{v}$ be an eigenvector for $\\lambda$ and $\\underline{w}$ any vector that is independent from $\\underline{v}$.\r\n    Then $A\\underline{v}=\\lambda\\underline{v},A\\underline{w}=\\alpha\\underline{v}+\\beta\\underline{w}$, then the matrix of this transformation under the basis $\\underline{v},\\underline{w}$ is\r\n    $$\\begin{pmatrix}\r\n        \\lambda&\\alpha\\\\\r\n        0&\\beta\r\n    \\end{pmatrix}$$\r\n    But then $\\beta=\\lambda$ by looking at the eigenvalue of matrices of this form, and $\\alpha\\neq 0$ by assumption.\r\n    So we can set $\\underline{u}=\\alpha\\underline{v}$, then under the basis $\\underline{u},\\underline{w}$, we get the matrix of $A$ to be\r\n    $$\\begin{pmatrix}\r\n        \\lambda&1\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix}$$\r\n    As claimed.\r\n\\end{proof}\r\n\\begin{proof}[Alternative approach for the third case]\r\n    If $A$ has characteristic polynomial of the form $\\chi_A(t)=c(t-\\lambda)^2$ with $c\\neq 0$ and $A\\neq \\lambda I$, then there is some vector $\\underline{w}$ with\r\n    $$(A-\\lambda I)\\underline{w}=\\underline{u}\\neq\\underline{0}$$\r\n    but by Cayley-Hamilton, we have\r\n    $$(A-\\lambda I)\\underline{u}=(A-\\lambda I)^2\\underline{w}=\\underline{0}$$\r\n    so $A$ is of the form under the basis $\\underline{u},\\underline{w}$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider\r\n    $$A=\\begin{pmatrix}\r\n        1&4\\\\\r\n        -1&5\r\n    \\end{pmatrix}$$\r\n    Then $\\lambda=3$ and we can have $\\underline{w}=(1,0)^\\top$, $\\underline{u}=(-2,-1)^\\top$, therefore\r\n    $$\\begin{pmatrix}\r\n        3&1\\\\\r\n        0&3\r\n    \\end{pmatrix}=\r\n    \\begin{pmatrix}\r\n        -2&1\\\\\r\n        -1&0\r\n    \\end{pmatrix}^{-1}\r\n    \\begin{pmatrix}\r\n        1&4\\\\\r\n        -1&5\r\n    \\end{pmatrix}\r\n    \\begin{pmatrix}\r\n        -2&1\\\\\r\n        -1&0\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{theorem}\r\n    Any $n\\times n$ complex matrix is similar to a matrix of the form\r\n    $$A'=\r\n    \\begin{pmatrix}\r\n        J_{n_1}(\\lambda_1)&&\\\\\r\n        &\\ddots&\\\\\r\n        &&J_{n_r}(\\lambda_r)\r\n    \\end{pmatrix}$$\r\n    where $\\lambda_1,\\ldots,\\lambda_r$ are the eigenvalues, $n_1+n_2+\\cdots+n_r=n$ and $J_p(\\lambda)$, the Jordan Block, is of the form\r\n    $$J_p(\\lambda)=\\begin{pmatrix}\r\n        \\lambda&1&&&\\\\\r\n        &\\lambda&1&&\\\\\r\n        &&\\lambda&&\\\\\r\n        &&&\\ddots&1\\\\\r\n        &&&&\\lambda\r\n    \\end{pmatrix}$$\r\n\\end{theorem}\r\n\\subsection{Quadrics and Conics}\r\nA quadric in $\\mathbb R^n$ is a hypersurface defined by\r\n$$Q(\\underline{x})=\\underline{x}^\\top A\\underline{x}+\\underline{b}^\\top\\underline{x}+c=0$$\r\nFor some real symmetric $n\\times n$ matrix $A$, $\\underline{b}\\in \\mathbb R^n,c\\in\\mathbb R$.\r\nSo $Q(\\underline{x})=A_{ij}x_ix_j+b_ix_i+c$.\\\\\r\nConsider classifying solutions up to geometrical equivalence, i.e. no distinction up to isometries.\r\n\\begin{theorem}\r\n    Any isometry in $\\mathbb R^n$ is a composition of translation and orthogonal transformation.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nIf $A$ in invertible, we can complete the square.\r\nWe set $\\underline{y}=\\underline{x}+A^{-1}\\underline{b}$, so $\\mathcal{F}(\\underline{y})=\\underline{y}^\\top A\\underline{y}=Q(\\underline{x})-k$ for some constant $k$.\r\nSo $Q(\\underline{x})=0\\iff \\mathcal F(\\underline{y})=k$ for some $k$, but the quadratic form is with respect to a new origin.\r\nIn this case, we can diagonalize $\\mathcal F$ and change the basis as appropriate and think of them as new coordinate (bases).\r\nThe case in $\\mathbb R^3$ has been discussed in the previous sections and we see that the quadrics are ellipsoids and hyperboloids (in $2$ directions).\\\\\r\nIf $A$ is singular, that is, if $A$ has one or more $0$ eigenvalue, things change.\\\\\r\nBack in $\\mathbb R^2$, if $A$ is invertible, then by our analysis above, we can write it as a (diagonalized) quadratic form $k=\\lambda_1x_1^2+\\lambda_2x_2^2$.\r\nFor $\\lambda_1,\\lambda_2>0$, $k>0$ gives an ellipse, $k=0$ gives a point and $k<0$ no solution.\r\nFor $\\lambda_1\\lambda_2<0$, so WLOG $\\lambda_1>0>\\lambda_2$, then we get a hyperbola for any $k\\neq 0$, and a pair of lines for $k=0$.\\\\\r\nIf $\\det A=0$, then unless $A$ is zero, we have $\\lambda_1\\neq 0$ and $\\lambda_2=0$, so we diagonaize $A$ in the original formula to get\r\n$$\\lambda_1x_1'^2+b_1'x_1'+b_2'x_2'+c=0\\iff \\lambda_1x_1''^2+b_2'x_2'+c'=0$$\r\nBy a shift in $x_1$.\r\nIf $b_2'=0$, then we again get a pair of lines for $c'<0$, a single line for $c'=0$ and no solution for $c'>0$.\r\nOtherwise $b_2'\\neq 0$, it gives a parabola.\\\\\r\nNote that all these changes of coordinates is prepresented by an isometry.\r\nThey are called conics because these shapes can be obtained by slicing the cone.\r\nThe general form for conics can be expressed in terms of $a,b$ semi-major and semi-minor axes or in terms of length unit $\\ell$ and eccentricity $e$.\\\\\r\nFor ellipses, we have the general form\r\n$$\\frac{x^2}{a^2}+\\frac{y^2}{b^2}=1$$\r\nWLOG $b>a$, then $b^2=(1-e^2)a^2$ for some $0\\le e<1$.\r\nSo we take this $e$ to be the eccentricity.\r\nSo the foci are at $x=\\pm ae$.\\\\\r\nAnd for parabola in the form $y^2=4ax$, the focus is at $x=a$ and $e=1$.\\\\\r\nFor hyperbola, i.e.\r\n$$\\frac{x^2}{a^2}-\\frac{y^2}{b^2}=1$$\r\nSo for $b^2=a^2(e^2-1)$ for $e>1$ the eccentricity.\r\nThe foci are $x=\\pm ae$.\r\n\\subsection{Symmetries and Transformation Groups}\r\nRecall from a previous section that $R$ is orthogonal iff $R^\\top R=RR^\\top=I$ iff it preserves dot products.\r\nThe set of such matrices is a group $\\operatorname{O}(n)$.\r\nAlso, given the properties above and the multiplictivity of $\\det$, $\\det R=\\pm 1$.\r\nAnd $\\operatorname{SO}(n)\\le \\operatorname{O}(n)$ is the set of orthogonal matrices with determinant $1$.\r\nWhile orthogonal matrices preserves lengths, angles and volumns (by alternating forms), special orthogonal matrices also preserves orientation.\r\nReflections belongs in $\\operatorname{O}(n)\\setminus\\operatorname{SO}(n)$.\r\nFor a specific $H\\in \\operatorname{O}(n)\\setminus\\operatorname{SO}(n)$, any element in $\\operatorname{O(n)}$ is of the form $R$ or $RH$ for some $R\\in\\operatorname{SO}(n)$.\r\nFor example, if $n$ is odd, then we can take $H=-I$\r\nWe can regard the transformation $x_i'=R_{ij}x_j$ in two ways:\\\\\r\nThe ``active'' way is to say the rotations transform vectors.\r\nThen $\\operatorname{SO}(n)\\star\\underline{x}$ would be a hypersphere.\r\nThe components $x_i'$ are components of new vector.\\\\\r\nBy contrast, the ``passive'' point of view is to think about the basis vectors and the vectors that they are mapped to, so $x_i'$ are the components of the same vector $\\underline{x}$ wrt a new (rotated) orthonormal basis.\r\n\\subsection{2-Dimensional Minkowski Space and Lorentz Transformations}\r\nConsider a new ``inner product'' in $\\mathbb R^2$ given by\r\n$$(\\underline{x},\\underline{y})=x^\\top J\\underline{y},J=\\begin{pmatrix}\r\n    1&0\\\\\r\n    0&-1\r\n\\end{pmatrix}$$\r\nAnd also we write $\\underline{x}=(x_0,x_1)^\\top$ and $\\underline{y}=(y_0,y_1)^\\top$.\r\nNote that all original properties of inner products hold except positive definiteness.\r\nWe can choose basis vectors that are orthonormal, which are the standard basis $\\underline{e_0},\\underline{e_1}$ with $(\\underline{e_0},\\underline{e_0})=1=-(\\underline{e_1},\\underline{e_1}), (\\underline{e_0},\\underline{e_1})=0$.\r\n\\begin{definition}\r\n    This ``new inner product'' is called the Minkowski metric, and $\\mathbb R^2$ equipped with it is called Minkowski space.\r\n\\end{definition}\r\nConsider\r\n$$M=\\begin{pmatrix}\r\n    M_{00}&M_{01}\\\\\r\n    M_{10}&M_{11}\r\n\\end{pmatrix}$$\r\nwhich preserves Minkowski metric if and only if $(M\\underline{x},M\\underline{y})=(\\underline{x},\\underline{y})$ if and only if\r\n$$\\underline{x}^\\top M^\\top JM\\underline{y}=\\underline{x}^\\top J\\underline{y}$$\r\nfor any $\\underline{x},\\underline{y}\\in\\mathbb R^2$, which happens iff $M^\\top JM=J$.\r\nBy taking determinant, $\\det(M)=\\pm 1$.\r\nSo all such $M$ constitutes a group and has a subgroup with $\\det M=1$ and $M_00>0$ is the Lorentz group.\\\\\r\nTo determine the general form of $M$ in Lorentz group, we can find it by requiring $M\\underline{e_0},M\\underline{e_1}$ to be orthonormal in this generalized sense, so $M$ is in the general form\r\n$$M(\\theta)=\\begin{pmatrix}\r\n    \\cosh\\theta&\\sinh\\theta\\\\\r\n    \\sinh\\theta&\\cosh\\theta\r\n\\end{pmatrix}$$\r\nFixed by $(M\\underline{e_0},M\\underline{e_0})=1$ and $M_{00}>0$.\r\nNote that $M(\\theta)M(\\phi)=M(\\theta+\\phi)$.\\\\\r\nCurves with $(\\underline{x},\\underline{x})=k$ with $k$ constant are simply hyperbolic.\r\nSince lengths are preserve, $\\underline{x'}=M\\underline{x}$ must lie on the same hyperbola.\\\\\r\nPhysically, we want to set\r\n$$M(\\theta)=\\gamma(v)\\begin{pmatrix}\r\n    1&v\\\\\r\n    v&1\r\n\\end{pmatrix}$$\r\nwhere $v=\\tanh\\theta$, then $|v|<1$ and $\\gamma(v)=(1-v^2)^{-1/2}$\r\nThen (with $x_0=t$ the time dimension and $x_1=x$ the space parameter)\r\n$$\\begin{cases}\r\n    t'=\\gamma(v)(t+vx)\\\\\r\n    x'=\\gamma(v)(x+vt)\r\n\\end{cases}$$\r\nThis is the Lorentz Transformation, or boost, relating time and space coordinates for observers moving with relative velocity $v<1$.\r\nThe $\\gamma$ factor here implies time dilation and length contraction.\r\nNote that $M(\\theta_3)=M_{\\theta_1}M_{\\theta_2}$ and $v_i=\\tanh(\\theta_i)$ gives $v_3=\\frac{v_1+v_2}{1+v_1v_2}$ which is consistent with $v<1$.", "meta": {"hexsha": "2c89a26b76abb298b12c83ef917eeb7706b7406b", "size": 13885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/bases.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": "7/bases.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": "7/bases.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": 55.3187250996, "max_line_length": 247, "alphanum_fraction": 0.6543752251, "num_tokens": 4686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.8577681122619885, "lm_q1q2_score": 0.6374658100824602}}
{"text": "\\section{Theory}\n\nIn the following section, equations and algorithms used to model the behavior of\na symmetric ideal gas centrifuge cascade from individual centrifuge properties\nare described. Details will also be provided to model centrifuge behavior\nwhen fed with a different feed enrichment than designed.\n\n\\subsection{Centrifuge properties}\n\n\\subsubsection{Separative power}\n\n\\paragraph{R\\\"aetz equation}\n\nAs described by Glaser in \\cite{glaser.2008}, the separative power of a single centrifuge can be express as an analytical solution \\cite{raetz.phd} of the\ndifferential equation for the gas centrifuge:\n\n\\begin{eqnarray}\n    \\label{eq:raetz}\n    \\delta U(L,F,\\theta,Z_{p}) &= &\\frac{1}{2}\n            F\\theta(1 - \\theta)\n            \\left(\\frac{\\Delta M}{2 RT}v_{a}^{2}\\right)^{2}\n            \\left(\\frac{r_{2}}{a}\\right)^{4}\n            \\left[1 - \\left(\\frac{r_{1}}{r_{2}}\\right)^{2}\\right]^{2}\n            \\label{eq_raetz}\\\\\n        &&\n            \\left[\n                \\left(\\frac{1+L/F}{\\theta}\\right)\n                (1- exp[ - A_{P}(L,F,\\theta)Z_{p}])  \\nonumber  \\right. \\\\\n        &&~~ + \\left.\\left(\\frac{L/F}{1 - \\theta}\\right)\n                (1 - exp[ -A_{W}(L,F,\\theta)(Z - Z_{p}])\\right]^{2}, \\nonumber\n                \\\\\n    \\textrm{with~ ~ ~ ~ ~}\n        A_{P} &= &\\frac{2\\pi D\\rho }{ ln(r_{2}/r_{1}) }\n                 \\frac{ 1 }{ F }\n                 \\frac{ 1-\\theta }{(1+L/F)(1-\\theta+L/F) }\\\\\n        A_{W} &= &\\frac{2\\pi D\\rho }{ ln(r_{2}/r_{1}) }\n                 \\frac{ 1 }{ F }\n                 \\frac{ 1-\\theta }{ (L/F)(1-\\theta+L/F) }\n\\end{eqnarray}\n\nIn this equation, the parameters of average gas temperature, $T$, peripheral speed,\n$v_a$, height, $h$, diameter, $d$, pressure ratio, $x$, feed flow rate, $F$,\ncounter-current flow ratio, $L/F$, are intrinsic to the centrifuge design.\nTo match the cascade design describe in \\cite{glaser.2008} and \\cite{walker.2017},\nP1-type centrifuge properties have been chosen (Table \\ref{tab:centrifuges}).\n\n\\begin{table}[htb]\n    \\centering\n    \\caption{Summary of the centrifuge parameters.}\n    \\begin{tabular}{ccccccc}\n        \\toprule\n        $T$[K] & $v$[m/s] & $h$[m] & $d$[m]   & $x$      & $F$[mg/s]  & $L/F$  \\\\\n        \\midrule\n        320    & $320$    & $1.8$  & $0.105$  & $10^{3}$ & $13$       & 2   \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\label{tab:centrifuges}\n\\end{table}\n\nThe variable $Z_p$ is the rectifier length, or the location of the feed point,\nand has an optimal axial location as defined by \\cite{raetz.phd}:\n\n\\begin{equation}\n    Z_p = \\frac{(1-\\theta)(1+L/F)}{1-\\theta+L/F}Z\n\\end{equation}\n\nThis optimizes the recitifer length based on the cut, $\\theta$, which is an expression\nof the fraction of the centrifuge feed that is output as product, and the counter-current\nflow, $L/F$. In practice, this value is a design parameter that is defined in the model\nduring the design of the centrifuge cascade.\n\nThe parameters $r_1$ and $r_2$ are the separation radii of the enriched material\n(here ${}^{235}\\mathrm{U}$ vs. ${}^{238}\\mathrm{U}$), $r_1$ being the withdrawal\nradius for the lighter isotope and $r_2$ for the heavier isotope. R\\\"aetz's\ntwo-shell model looks for optimal values between these two, as described by\nthe hydrodynamic equations. The radii ratio is optimized using the following relationship:\n\n\\begin{equation}\n    \\max \\left\\{ \\left[1-\\left(\\frac{r_1}{r_2}\\right)^2 \\right]^2 \\times \\left[ \\ln \\left(\\frac{r_2}{r_1} \\right) \\right]^{-1} \\right\\}\n\\end{equation}\n\nThis ratio can further be constrained by approximating $r_2$ as being very close\nto the inner centrifuge wall with radius $a$:\n\n\\begin{equation}\n    \\left(\\frac{r_1}{r_2}\\right) \\approx \\left(\\frac{r_1}{a}\\right) = \\sqrt{1 - \\frac{2RT}{M}(\\ln x)\\frac{1}{v_{a}^{2}}}\n\\end{equation}\n \nHere the gas constants are molar mass, $M$, temperature $T$, universal gas constant, $R$,\nand the pressure ratio, $x$ (typically $1000:1$) \\cite{}. %needs citation?\nThis relationship is valid when $v_a > 380 \\frac{\\mathrm{m}}{\\mathrm{s}}$.\nOtherwise, the relationship can be approximated $\\{\\frac{r_1}{r_2} \\approx 0.534 \\mid v_a \\leq 380 \\frac{\\mathrm{m}}{\\mathrm{s}}\\}$.\nIn order to decompose the ratio into each individual radius, knowledge on one\nof them is required. Glaser \\cite{glaser.2008} states that $r_2$ typically ranges\nfrom $96\\%$ to $99\\%$ the value of the inner centrifuge wall radius $a$. The exact\nbehavior of $r_2$ between these two values in operational conditions is unknown,\nbut a linear approximation can be made. It is assumed that $r_2$ is always at\nthe midpoint of these two extremes (i.e. $r_2 = 0.975 a$). Then, $r_1$ can be\nfound by simply multiplying this value by the ratio.\n\nWith this, all parameters of the separative power equation \\ref{eq:raetz} are\ndefined and a value can be calculated. Separative power, $\\delta U$, has units similar to the feed flow, that of $[mg/s]$.\n\n\\paragraph{First principle}\n\nIt can be shown \\cite{avery} that the separative power of a single centrifuge can be\nderived from first principles and expressed as a function of the feed-to-product enrichment factor, $\\alpha$, the cut, $\\theta$, and the feed rate, $F$:\n%I think we should replicate at least some of that here\n\n\\begin{equation} \\label{eq_alpha_principle}\n    \\delta U = \\frac{F}{2}\\frac{\\theta}{1-\\theta}(\\alpha-1)^{2}\n\\end{equation}\n\n\\subsection{Centrifuges basic properties and definition}\n\nThe outputs of a centrifuge relative to its input can be described with ratios\nof the abundance ($R = \\frac{N}{1-N}$) where the feed, product, and tail enrichment $N, N', N''$ respectively. Enrichment factors of $\\alpha$ (feed-to-product),\n$\\beta$ (feed-to-tail), and $\\gamma$ (tail-to-product) can then be defined:\n\n\\begin{subequations}\n    \\label{eq_alphabeta}\n    \\begin{equation} \\label{eq_alpha_def}\n        \\alpha = \\frac{1-N}{N}\\frac{N'}{1-N'}\n    \\end{equation}\n    \\begin{equation}\\label{eq_beta-def}\n        \\beta = \\frac{1-N''}{N''}\\frac{N}{1-N}\n    \\end{equation}\n    \\begin{equation}\\label{eq_gamma-def}\n        \\gamma = \\alpha \\, \\beta\n    \\end{equation}\n\\end{subequations}\n\n\n\\subsection{Cascade Design}\n\\subsubsection{Symmetric Cascade}\n\nA symmetric cascade is a cascade where a stage is fed using the tail, $T$, of the next stage and the product, $P$, of the previous one. The the cascade feeding stage, $F_{i}$ flow, with external feed, $F_{ext}$, is given by:\n\n\\begin{equation}\n    F_{i} = T_{i+1} + F_{i-1} ~(+ F_{ext})\n\\end{equation}\n\n\\subsubsection{Symmetric Ideal Cascade}\nThis model constructs cascades as symmetrical and ideal, with no losses in\nseparative work. This means that the tail assay of the next stage ($N''_{i+1}$)\nis the product assay of the previous stage ($N'_{i-1}$), which can be\nexpressed as:\n\n\\begin{equation}\n    \\forall i~ N_{i} = N'_{i-1} = N''_{i+1}~ ~\\Leftrightarrow~ ~\\forall (i,j)~\n    \\alpha_{i} = \\beta_{j}\n\\end{equation}\n\n\n\n\\subsection{Building the cascade}\n\nDesigning a symmetric ideal cascade beings with the feeding\nstage. As all the enrichment factors are equal across all the cascade, the\nfeeding stage is used to determine all subsequent stages.\nThe feed assay of the feeding stage, $N_{0}$, is fixed by the external feed assay\nprovided as an input.\n\nFrom equation \\eqref{eq_raetz} and \\eqref{eq_alpha_principle} it is possible to\nexpress the feed-to-product enrichment factor $\\alpha$ as a function of the feed rate $F$, the separative performance\n$\\delta U$ (a function of $\\theta$), and the cut $\\theta$:\n\n\\begin{equation} \\label{eq_alpha}\n    \\alpha = \\sqrt{\\frac{2\\delta U(\\theta)}{F} \\frac{1-\\theta}{\\theta}} + 1\n\\end{equation}\n\n\nFrom equations \\eqref{eq_alphabeta}, the product assay can be expressed as:\n\n\\begin{equation}\\label{eq_product_assay}\n    N' = \\frac{\\alpha \\frac{N}{1-N}}{1+\\alpha \\frac{N}{1-N}} = \\frac{\\alpha R}{1 + \\alpha R}\n\\end {equation}\n\n\nThen, from mass conservation, $N = \\theta N' + (1-\\theta)N''$ and equation\n\\eqref{eq_product_assay}, it is possible to express the feed-to-tail enrichment factor $\\beta$ as a function of only the feed abundance, $R$, the cut $\\theta$, and the feed-to-product enrichment factor, $\\alpha$:\n\n\\begin{subequations}\n    \\begin{equation}\\label{eq_beta_interim}\n        \\beta = \\left( 1 - \\frac{N - \\theta N'}{1-\\theta} \\right)\n                        \\left( \\frac{R}{\\frac{N - \\theta N'}{1 - \\theta}} \\right)\n    \\end{equation}\n    \\begin{equation}\\label{eq_beta}\n        \\beta =   R \\left(\\dfrac{1-\\theta}\n                        {\\dfrac{R}{R+1}- \\theta \\dfrac{\\alpha R}{1+\\alpha R}} -1\\right)\n    \\end{equation}\n\\end{subequations}\n\nFinally from equation \\eqref{eq_alpha} and \\eqref{eq_beta} it is possible to\ndetermine the cut, $\\theta$, required to build an ideal cascade:\n\n\\begin{eqnarray}\n    \\theta_{i} = \\dfrac{N_{i} - \\dfrac{1}{1 + \\beta/R_{i}}}{ \\dfrac{\\alpha R_{i}}{1 + \\alpha R_{i}} -\n           \\dfrac{1}{1 + \\beta/R_{i}}}\n           \\label{eq_theta}\n\\end{eqnarray}\n\n\nTo construct an ideal stage, a cut, $\\theta$, must first be computed.\nThis is found iteratively, searching for the optimal cut value where $\\alpha = \\beta$\nfor given feed and centrifuge parameters. With a separative power calculated,\nan $\\alpha$ and $\\beta$ value can be determined for an initial cut guess. This\nmodel assumes that the ideal cut for a stage should be between 0.1 and 0.9. The\ntwo enrichment factors are compared, and the higher or lower cut value is chosen\nby which pair of factors are closer. A new cut is determined from the chosen\nfactors, a new separative power is computed, and new $\\alpha$ and $\\beta$ values\nare compared. This process continues until, to some precision, the resulting\nenrichment factors are approximately equal. As illustrated in Fig. \\ref{fig_a_m_b},\nfor a given input feed assay, the ideal feeding stage typically has a $\\theta$\nvalue between 0.45 and 0.525 when $\\alpha = \\beta$.\n\n\\begin{figure}[h!] % replace 't' with 'b' to force it to be on the bottom\n    \\centering\n    \\includegraphics[scale=0.5]{alpha_minus_beta}\n    \\caption{Evolution of the difference between $\\alpha$ and $\\beta$ as a\n    function of the cut value for different of feed assays, 0.007 (black),\n    0.035 (red), 0.2 (green), 0.7 (black). }\n    \\label{fig_a_m_b}\n\\end{figure}\n\nThe number of machines required to construct a stage can then be computed using\nequation \\eqref{eq_alpha_principle} to solve for the centrifuge feed flow:\n\n\\begin{equation}\\label{eq_cent_feed}\n    F_c = \\frac{2 \\delta U}{(\\alpha - 1)^2} \\frac{M}{M_{238}} \\frac{1-\\theta}{\\theta}\n\\end{equation}\n\nWhere the molar mass ratio $\\frac{M}{M_{238}}$ accounts for the molar mass\ndifferences between the feed gas, $UF_6$, and the individual uranium isotopes\nbeing separated. The stage feed flow can then be divided by the individual\ncentrifuge feed flow, equation \\eqref{eq_cent_feed}, to find the exact number of\nmachines needed for the ideal stage. In practice, this number is rounded up to\naccount for fractional machines required.\n\n\nIn a cascade, as the stage feed-to-product enrichment factor $\\alpha_{i}$ and stage feed-to-tail enrichment factor $\\beta_{i}$ remain constant, only the value of\nthe cut, $\\theta_{i}$, changes across the different stages of a cascade.  This\nalgorithm assumes that the corresponding separative power $\\delta U$ (not\nre-computed) can be achieved with the chosen centrifuge design by tuning other\noperational parameters such as the rotation speed, counter-current flow\nratio, etc.  Once $\\theta_{i}$ is determined, it is possible to compute the\nproduct and the tail assays.\n\n\nThe design of the ideal symmetric cascade is performed through 2 steps. First,\nthe configuration and number of stages is determined, adding stages with product assay $N'_i$ calculated using equation \\ref{eq_product_assay}, until the\nproduct assay of the final stage is greater than or equal to the product targeted assay. The stage tails assay $N''_i$ is calculated similarly, until it is less than or equal to the tails desired assay.  This determines the number of enriching and stripping stages as well as their enrichment properties ($N_{i}$, $N'_{i}$, $N''_{i}$,$\\theta_{i}$).\n\n\nThe second step determines the relative flows at each stage, solving the linear\nflow equation, \\eqref{eq_flow}.\nThe cascade can then be populated with actual machines until the maximum number\nof available machines is reached.\n\n\\begin{equation}\n\\resizebox{\\linewidth}{!}{%\n$\\displaystyle\n\\setcounter{MaxMatrixCols}{20}\n\\begin{bmatrix}\n     -1      & 1-\\theta_{_{S+1}} & 0                 & ...  & 0            & 0            & 0             & 0             & 0             & ... & 0               & 0  & 0 \\\\\n\\theta_{_S}  & -1                & 1-\\theta_{_{S+2}} & ...  & 0            & 0            & 0             & 0             & 0             & ... & 0               & 0  & 0 \\\\\n             &                   &                   &      &              &              & ...           &               &               &     &                 &    &   \\\\\n 0           & 0                 & 0                 & ...  & \\theta_{_-2} & -1           & 1-\\theta_{_0} & 0             & 0             & ... & 0               & 0  & 0 \\\\\n 0           & 0                 & 0                 & ...  & 0            & \\theta_{_-1} & -1            & 1-\\theta_{_1} & 0             & ... & 0               & 0  & 0 \\\\\n 0           & 0                 & 0                 & ...  & 0            & 0            & \\theta_{_0}   & -1            & 1-\\theta_{_2} & ... & 0               & 0  & 0 \\\\\n             &                   &                   &      &              &              & ...           &               &               &     &                 &    &   \\\\\n 0           & 0                 & 0                 & ...  & 0            & 0            & 0             & 0             & 0             & ... & \\theta_{_{E-2}} & -1 & 1-\\theta_{_E} \\\\\n 0           & 0                 & 0                 & ...  & 0            & 0            & 0             & 0             & 0             & ... & 0               & \\theta_{_{E-1}} & -1\n \\end{bmatrix}\n \\times\n \\begin{bmatrix}\n     F_{_{S}}   \\\\\n     F_{_{S+1}} \\\\\n     \\cdots     \\\\\n     F_{_{-1}}  \\\\\n     F_{_{0} }  \\\\\n     F_{_{1} }  \\\\\n     \\cdots     \\\\\n     F_{_{E-1}} \\\\\n     F_{_{E}}\n \\end{bmatrix}\n =\n \\begin{bmatrix}\n     0      \\\\\n     0      \\\\\n     \\cdots \\\\\n     0      \\\\\n     F      \\\\\n     0      \\\\\n     \\cdots \\\\\n     0      \\\\\n     0\n\\end{bmatrix}\n$}\n%\\caption{caption needed!}\n\\label{eq_flow}\n\\end{equation}\n\n\n\n\\subsection{Misuse models}\n\nLittle information is available about optimising an existing enrichment cascade\nthat is being fed with a feed enrichment that does not match the design\nenrichment. Here, 3 different methods will be investigated.\n\nThe first method, A, assumes that no changes are being made to the cascade, i.e $\\delta U$, $F$ and $\\theta$ are fixed across all stages. The second method, B, assumes the cut value $\\theta$ is re-tuned at each stage to maintain the ideal state of the cascade, while $\\alpha$ and $\\beta$ remain fixed. The last method, C, described in \\cite{walker.2017} assumes the tails-to-product enrichment factor $\\gamma$ and the cut $\\theta$ remain constants\n(eq. \\eqref{eq_gamma-def}: $\\gamma = \\alpha\\beta$). Model behaviors and\nassumptions are summarized in Tab. \\ref{tab:models}.\n\n\\begin{table}[htb]\n\\centering\n  \\caption{Summary of misuse model properties.}\n\\begin{tabular}{l|ccc}\n\\toprule\n\nModel                &    A                 & B                  & C  \\\\\n\\midrule\nConstant parameters  & $\\alpha_i, \\theta_i$ & $\\alpha_i=\\beta_i$ & $\\gamma_i=\\alpha_i\\beta_i, \\theta_i$       \\\\\nVarying parameters   & $\\beta_i$            & $\\theta_i$         & $\\alpha_i, \\beta_i$                     \\\\\nAssays determination & blended              & ideal              & blended                  \\\\\nFlow                 & unchanged            & reduced            & unchanged       \\\\\n\n\\bottomrule\n\\end{tabular}\n  \\label{tab:models}\n\\end{table}\n\n\\subsubsection{Model A}\n\nThe tuning method A does not re-optimize $\\theta_i$, keeping the same flow as the\nideal configuration. From equation \\eqref{eq_alpha}, maintaining $\\delta U$ and\n$F$ while $\\theta$ is unchanged implies $\\alpha$ remains unchanged as well.\nAccording to equation \\eqref{eq_beta}, when $\\alpha$ and $\\theta$ are fixed, if\nthe feed assay ($N$) changes, $\\beta$ will change accordingly.  This breaks the\nideal status of the cascade, i.e. $N_{i} \\neq N'_{i-1} \\neq N''_{i+1}$.\n\n\nIn order to compute the proper product and tails assay at each stage, the tail\nand the product from the next and the previous stage respectively must be\nblended in order to determine the correct stage feed assay. All feed assays are\niteratively updated, blending the proper product and tails, then using the\nupdated feed assay, the new product and tails assays are recomputed. This\nprocess is repeated until the sum of the square difference in assays is smaller\nthan $10^{-8}$.  As the cut remains fixed at each stage, the flows do not need\nto be recomputed.\n\nThis model assumes that it is possible to maintain the separative power of a\ncentrifuges, $\\delta U$, for any feed assays $N$ while maintaining its cut\n$\\theta$ and feed flow $F$.\n\n\\subsubsection{Model B}\n\nUsing the second method, the cut value at each stage, $\\theta_i$, is retuned in\norder to maintain the $\\alpha_i$ and $\\beta_i$ at their original values\n(equation \\eqref{eq_theta}). Since the cascade remains ideal, the product and\ntails assay at each stage can easily be determined using equations\n\\eqref{eq_alphabeta}.\n\nAs the cut values change, the relative flow rates between the different stages\nare recomputed using equation \\eqref{eq_flow}.  Under this model, the flow at\neach stage of the original ideal cascade is assumed to be the maximum flow\nallowed at that stage.  Therefore, all of the recomputed flow rates are scaled\ntogether to ensure that no stage experiences a flow rate larger than that of\nthe original cascade.  Some stages may now experience flow rates much lower\nthan the original cascade.\n\n%% The flow rates are determinted as\n%% the largest flow rates allowed by the cascade design, number of centrifuges\n%% limiting the flow at each stage.\n\nThis model assumes that it is possible to tune a centrifuge separative power\n$\\delta U$, for any feed assay $N$, cut $\\theta$ and feed flow $F$, in order to\nmaintain its constant feed to product enrichment factor $\\alpha$.\n\n\n\n\n\\subsubsection{Model C}\nThe last model assumes that the tails to product enrichment factor remains\nconstant regardless to the feed assays. To compute the response of the cascade\none need to determine $\\alpha$ and $\\beta$ such that their product and\n$\\theta$ remain fixed.\nFrom equations \\eqref{eq_alphabeta} and the assay conservation equation $N =\n\\theta N' + (1-\\theta)N''$ it is possible to express the product, $N'$,\ndependent on the feed assay $N$, $\\gamma$, and the cut, $\\theta$, as one\nsolution of the second order equation \\eqref{eq_gamma_p}:\n\n\\begin{equation}\\label{eq_gamma_p}\n    \\theta(\\gamma-1)N'^2+((N+\\theta)(\\gamma-1)+1)N'-N\\gamma = 0\n\\end{equation}\n\n\nThe only solution allowing product assay to range between 0 and 1 is the\nfollowing :\n\n\\begin{equation}\\label{eq_model_b_sol}\n    N' = \\frac{N+\\theta}{2\\theta} +\n         \\frac{1 - \\sqrt{\\gamma^{2}(N-\\theta)^{2}\n                         + 2\\gamma( N^{2} + N - \\theta^{2} + \\theta)\n                         + (N + \\theta + 1)^{2}}}\n              {2\\theta(\\gamma - 1)}\n\\end{equation}\n\nOnce the product assay is known, one can trivially determine the tails assay,\n$\\alpha$ and $\\beta$, using equations \\eqref{eq_alphabeta} and mass\nconservation.\n\nSimilar to model A, because the cut values remain constant, the flows do not\nneed to be recomputed and the correct assays, $\\alpha$ and $\\beta$, are\ndetermined through iterative blending of the product assays of the previous\nstage and the tails assay of the next stage using equation\n\\eqref{eq_model_b_sol}.\n\nThis model assumes that it is possible to tune the centrifuge separative power\n$\\delta U$ in order to maintain for any feed assay $N$ and its tails to product\nenrichment factor $\\gamma$ while maintaining its cut $\\theta$ and feed flow $F$.\n\n%The speed at which each models reach a threshold of $90\\%$ enrichment is\n%illustrated in Figure \\ref{fig:model_comparison}. The production curve of\n%enrichment for each model is shown. The step functions for each model represent\n%the cascade configuration. Each step is one cascade in a chain of cascades and\n%the shape of the curve for each model gives an indication of how quickly the model\n%can reach the enrichment threshold. The main difference is that Model B reaches\n%the threshold faster, whereas Models A and C reach a higher enrichment value.\n%This highlights some of the immediate differences that would influence the choice\n%of using each model in a breakout scenario.\n\n%\\begin{figure}[ht]\n%    \\centering\n%    \\includegraphics[scale=0.4]{ModelComparison}\n%    \\caption{The curve of resulting product assays for each model is plotted.\n%    Since the feed assay of each cascade is fed into the next cascade in the\n%    chain, a linear relationship between the product and feed assays is plotted\n%    in black. The step function for each model represents the output of the\n%    cascade chain (each step is a cascade). While there are four steps for each\n%    model, Model B (green) reached the $90\\%$ enrichment threshold before\n%    Model A (red) or Model C (blue). However, in the same amount of steps, Models\n%    A and C are able to achieve a higher enrichment percent than Model B.}\n%    \\label{fig:model_comparison}\n%\\end{figure}\n", "meta": {"hexsha": "412a469a7a2d4076b71fba0dd0cb32b4fa7208fa", "size": 21566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory.tex", "max_stars_repo_name": "nuclearkatie/enrichment-paper", "max_stars_repo_head_hexsha": "223eea892a43948ded8ed611a2e4829ba19fe6ce", "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": "theory.tex", "max_issues_repo_name": "nuclearkatie/enrichment-paper", "max_issues_repo_head_hexsha": "223eea892a43948ded8ed611a2e4829ba19fe6ce", "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": "theory.tex", "max_forks_repo_name": "nuclearkatie/enrichment-paper", "max_forks_repo_head_hexsha": "223eea892a43948ded8ed611a2e4829ba19fe6ce", "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": 48.2460850112, "max_line_length": 447, "alphanum_fraction": 0.6522767319, "num_tokens": 6062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6374658036283322}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% =================================================================================================\n\\section*{Symmetrised derivatives of the connection}\n\nHere we compute, just for a check, the symmetrised derivatives of the connections.\nThese are defined by\n\\begin{align}\n   \\Gamma^{d}_{a(b,\\uc)} = \\Gamma^{d}_{a(b,c_1,c_2,\\cdots c_n)}\n\\end{align}\nNote that these are \\emph{not} the generalised connections. The generalised connections\ninvolve $\\Gamma^{d}_{(ab,\\uc)}$ and quadratice combinations of lower order generalised\nconnections (see eq (1) of {\\tt\\small ../genGamma.pdf}). Note that the\ngeneralised connections vanish at the origin (unlike the $\\Gamma^{d}_{a(b,\\uc)}$).\n\nThese results agree with those of Hatzinikitas equation (12) (arXiv:hep-th/0001078).\n\nThis code provides an indirect check on our results for the connection. It does not\nprove that the code {\\tt connection.tex} is correct but it does show that our\nresults are consistent with those of Hatzinikitas.\n\n\\clearpage\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{#}::Derivative.\n   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n   g_{a}^{b}::KroneckerDelta.\n   g^{a}_{b}::KroneckerDelta.\n   \\delta^{a}_{b}::KroneckerDelta.\n   \\delta_{a}^{b}::KroneckerDelta.\n\n   R_{a b c d}::RiemannTensor.\n   R^{a}_{b c d}::RiemannTensor.\n   R_{a b c}^{d}::RiemannTensor.\n\n   \\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).\n\n   x^{a}::Depends(D{#}).\n\n   g_{a b}::Depends(\\partial{#}).\n   R_{a b c d}::Depends(\\partial{#}).\n   R^{a}_{b c d}::Depends(\\partial{#}).\n   \\Gamma^{a}_{b c}::Depends(\\partial{#}).\n\n   R_{a b c d}::Depends(\\nabla{#}).\n   R^{a}_{b c d}::Depends(\\nabla{#}).\n\n   import cdblib\n\n   Gamma = cdblib.get ('Gamma','../connection.json')\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{cadabra}\n   tmp := D_{p}{@(Gamma)}.\n   distribute     (tmp)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   eliminate_kronecker (tmp)\n   substitute     (tmp,$x^{a}->0$)\n   sort_product   (tmp)\n   rename_dummies (tmp)\n   canonicalise   (tmp)\n\n   foo := A^{p} A^{b} @(tmp).\n   distribute     (foo) # cdb(foo.301,foo)\n   sort_product   (foo) # cdb(foo.302,foo)\n   rename_dummies (foo) # cdb(foo.303,foo)\n   canonicalise   (foo) # cdb(foo.304,foo)\n\n   # save the result\n   dGamma1 := @(foo).   # cdb (dGamma1.000,dGamma1)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\begin{dmath*} \\cdb*{foo.301} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.302} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.303} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.304} \\end{dmath*}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{cadabra}\n   tmp := D_{p q}{@(Gamma)}.\n   distribute     (tmp)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   eliminate_kronecker (tmp)\n   substitute     (tmp,$x^{a}->0$)\n   sort_product   (tmp)\n   rename_dummies (tmp)\n   canonicalise   (tmp)\n\n   foo := A^{p} A^{q} A^{b} @(tmp).\n   distribute     (foo) # cdb(foo.401,foo)\n   sort_product   (foo) # cdb(foo.402,foo)\n   rename_dummies (foo) # cdb(foo.403,foo)\n   canonicalise   (foo) # cdb(foo.404,foo)\n\n   # save the result\n   dGamma2 := @(foo).   # cdb (dGamma2.000,dGamma2)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\begin{dmath*} \\cdb*{foo.401} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.402} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.403} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.404} \\end{dmath*}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{cadabra}\n   tmp := D_{p q r}{@(Gamma)}.\n   distribute     (tmp)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   eliminate_kronecker (tmp)\n   substitute     (tmp,$x^{a}->0$)\n   sort_product   (tmp)\n   rename_dummies (tmp)\n   canonicalise   (tmp)\n\n   foo := A^{p} A^{q} A^{r} A^{b} @(tmp).\n   distribute     (foo) # cdb(foo.501,foo)\n   sort_product   (foo) # cdb(foo.502,foo)\n   rename_dummies (foo) # cdb(foo.503,foo)\n   canonicalise   (foo) # cdb(foo.504,foo)\n\n   # save the result\n   dGamma3 := @(foo).   # cdb (dGamma3.000,dGamma3)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   % \\begin{dmath*} \\cdb*{foo.501} \\end{dmath*}\n   % \\begin{dmath*} \\cdb*{foo.502} \\end{dmath*}\n   % \\begin{dmath*} \\cdb*{foo.503} \\end{dmath*}\n   \\begin{dmath*} \\cdb*{foo.504} \\end{dmath*}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{cadabra}\n   tmp := D_{p q r s}{@(Gamma)}.\n   distribute     (tmp)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   eliminate_kronecker (tmp)\n   substitute     (tmp,$x^{a}->0$)\n   sort_product   (tmp)\n   rename_dummies (tmp)\n   canonicalise   (tmp)\n\n   foo := A^{p} A^{q} A^{r} A^{s} A^{b} @(tmp).\n   distribute     (foo)\n   sort_product   (foo)\n   rename_dummies (foo)\n   canonicalise   (foo)\n\n   # save the result\n   dGamma4 := @(foo).   # cdb (dGamma4.000,dGamma4)\n\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{cadabra}\n   tmp := D_{p q r s t}{@(Gamma)}.\n   distribute     (tmp)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   unwrap         (tmp)\n   product_rule   (tmp)\n   distribute     (tmp)\n   substitute     (tmp,$D_{a}{x^{b}}->\\delta_{a}^{b}$)\n   eliminate_kronecker (tmp)\n   substitute     (tmp,$x^{a}->0$)\n   sort_product   (tmp)\n   rename_dummies (tmp)\n   canonicalise   (tmp)\n\n   foo := A^{p} A^{q} A^{r} A^{s} A^{t} A^{b} @(tmp).\n   distribute     (foo)\n   sort_product   (foo)\n   rename_dummies (foo)\n   canonicalise   (foo)\n\n   # save the result\n   dGamma5 := @(foo).   # cdb (dGamma5.000,dGamma5)\n\n\\end{cadabra}\n\n\\clearpage\n\nCompare these results against those of Hatzinikitas equation (12) (arXiv:hep-th/0001078).\nOur final $d\\Gamma$ is zero because our metric was expanded to order $x^5$ so the $\\Gamma$\nonly contain terms to order $x^4$. Hence the 5-th partial derivatices are zero.\n\n\\begin{dgroup*}\n   \\begin{dmath*} A^b A^c \\Gamma^{d}{}_{ab,c} = \\Cdb*{dGamma1.000} \\end{dmath*}\n   \\begin{dmath*} A^b A^c A^e \\Gamma^{d}{}_{ab,ce} = \\Cdb*{dGamma2.000} \\end{dmath*}\n   \\begin{dmath*} A^b A^c A^e A^f \\Gamma^{d}{}_{ab,cef} = \\Cdb*{dGamma3.000} \\end{dmath*}\n   \\begin{dmath*} A^b A^c A^e A^f A^g \\Gamma^{d}{}_{ab,cefg} = \\Cdb*{dGamma4.000} \\end{dmath*}\n   \\begin{dmath*} A^b A^c A^e A^f A^g A^h \\Gamma^{d}{}_{ab,cefgh} = \\Cdb*{dGamma5.000} \\end{dmath*}\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "6c9c90418e507c12dba29c6f94f169d4b5cfb4b1", "size": 7781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/checks/check-pGamma.tex", "max_stars_repo_name": "leo-brewin/riemann-normal-coords", "max_stars_repo_head_hexsha": "4e6546028229b6f43fcef1c0b83660cddc021716", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-20T16:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-20T16:15:58.000Z", "max_issues_repo_path": "source/cadabra/checks/check-pGamma.tex", "max_issues_repo_name": "leo-brewin/riemann-normal-coords", "max_issues_repo_head_hexsha": "4e6546028229b6f43fcef1c0b83660cddc021716", "max_issues_repo_licenses": ["MIT"], "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/checks/check-pGamma.tex", "max_forks_repo_name": "leo-brewin/riemann-normal-coords", "max_forks_repo_head_hexsha": "4e6546028229b6f43fcef1c0b83660cddc021716", "max_forks_repo_licenses": ["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.1920289855, "max_line_length": 99, "alphanum_fraction": 0.5820588613, "num_tokens": 2846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6373029846431818}}
{"text": "%==============================================================================\n\\chapter{Distances in Quantum Theory}\n\\label{chap:distappd}\n%==============================================================================\n\nThis chapter follows mostly \\cite{Wilde2009}. Some conventions follow those in \n\\cite{Petz2008}.\n\n%------------------------------------------------------------------------------\n\\section{Trace Distance}\n\\label{sec:trace-dist}\n%------------------------------------------------------------------------------\n\nTo begin with, define the \\emph{trace norm} or \\emph{$l_1$-norm} of an \nHermitian operator $M$ as\n\\begin{equation}\n\t\\dvbr{M}_1 \\coloneqq \\tr\\sqrt{M^\\dagger M}.\n\\end{equation}\nWhen the spectral decomposition $M = \\sum_i \\mu_i \\Ket{i}\\Bra{i}$ exists, the \ntrace norm reads\n\\begin{equation}\n\t\\dvbr{M}_1 \\equiv \\sum_i\\vbr{\\mu_i},\n\\end{equation}\nso the name $l_1$-norm comes. It is positive definite and homogeneous; the \ntriangle inequality also holds. Thus it can be used to define the \\emph{trace \ndistance} between Hermitian operators ${M}$ and ${N}$ as\n\\begin{equation}\n\\rfun{T}{{M}, {N}} \\coloneqq \\frac{1}{2} \\dvbr{M-N}_1 \\equiv\n\\frac{1}{2} \\tr \\sqrt{\\rbr{{M}-{N}}^\\dagger\\rbr{{M}-{N}}}.\n\\label{eq:def-trace-dist}\n\\end{equation}\nNow consider density operators $\\rho$ and $\\sigma$ only. Since $\\dvbr{\\rho}_1 \n\\equiv 1$, one sees\n\\begin{equation}\n0 \\le \\rfun{T}{{\\rho}, {\\sigma}} \\le 1,\n\\label{eq:def-trace-prop}\n\\end{equation}\nfollowed from positive definiteness and triangle inequality.\n\nThe following lemma helps constructing a physical interpretation of the \ndistance. Let the Hermitian operator $\\Lambda$ be such that all its eigenvalues \nlies within $\\sbr{0,1}$, then\n\\begin{equation}\n\\rfun{T}{{\\rho}, {\\sigma}} = \\max_{0 \\le {\\Lambda} \\le \\Bbbone}\n\\cfun{\\tr}{{\\Lambda}\\rbr{{\\rho}-{\\sigma}}}.\n\\end{equation}\nTo understand this, take $\\Lambda \\equiv \\Ket{\\alpha}\\Bra{\\alpha}$,\nwhere $\\Ket{\\alpha}$ is the eigenket of some observable $\\Alpha$, with \neigenvalue $\\alpha$. Then $\\tr\\cbr{\\Lambda \\rho}$ tells the probability of \nmeasuring $\\Alpha$ which gives the result $\\alpha$. Therefore $\\tr\\cbr{\\Lambda \n\\rbr{\\rho-\\sigma}}$ gives the difference of the probability above for $\\rho$ and \n$\\sigma$, and $\\rfun{T}{{\\rho}, {\\sigma}}$ is the maximal value of the \ndifference above.\n\nThough the trace distance is used in formulating \\cref{chap:quantifing}, it is \nrather formidable to compute due to the operatorial square root in \n\\cref{eq:def-trace-dist}. Therefore the author seeks other ways to evaluate the \nquantity.\n\n%------------------------------------------------------------------------------\n\\section{Fidelity}\n\\label{sec:fidelity}\n%------------------------------------------------------------------------------\n\nFidelity is another means to compare two quantum states. The simplest case \nof fidelity is that of two pure states,\n\\begin{equation}\n\\rfun{F}{\\Ket{\\alpha},\\Ket{\\beta}} \\coloneqq \\vbr{\\Braket{\\alpha | \\beta }}.\n\\end{equation}\nOne sees that it is just the modulus of the transition amplitude, a measure of \n\\emph{faithfulness}. For more general cases, fidelity is defined as\n\\begin{align}\n\\rfun{F}{\\Ket{\\alpha},{\\sigma}} &\\coloneqq \\sqrt{\\Braket{\\alpha | {\\sigma} | \n\\alpha}}, \\\\\n\\label{eq:fidelity-pure-mixed}\n\\rfun{F}{{\\rho},{\\sigma}} &\\coloneqq \\tr\\sqrt{{\\rho}^\\frac{1}{2} \n{\\sigma} {\\rho}^\\frac{1}{2}}.\n\\end{align}\nIn applications in this work, fidelity is solvable because only\n\\cref{eq:fidelity-pure-mixed} is needed.\n\nAn important property of fidelity is that it follows the \\emph{Fuchs--van de \nGraaf inequality} \\cite{Fuchs1999})\n\\begin{equation}\n1 - \\rfun{F}{{\\rho},{\\sigma}} \\le \\rfun{T}{{\\rho},{\\sigma}}\n\\le \\sqrt{1 - \\rfun{F^2}{{\\rho},{\\sigma}}}.\n\\label{eq:ineq-fvdg}\n\\end{equation}\nIn this work, the trace distances are evaluated by computing the fidelities \nexactly and inserting them to \\cref{eq:ineq-fvdg}.\n\nConsider a single harmonic oscillator with intrinsic frequency $\\Omega$, a \nthermalised state of it at temperature $T$ described by a density operator \n$\\rfun{\\rho}{T}$, as well as a generalised Gaussian state $\\Ket{\\omega}$ (see \n\\cref{sec:single-harosc}). In the following the fidelity of them will be \ncalculated.\n\nSince $\\rfun{\\rho}{T}$ is diagonal in the energy-eigenstate basis $\\Ket{n}$, one \nhas\n\\begin{equation}\n\\Braket{\\omega | \\rfun{\\rho}{T} | \\omega} = \\sum_{n=0}^{+\\infty}\n\\Braket{\\omega | n} \\Braket{n | \\rfun{\\rho}{T} | n} \\Braket{n | \\omega},\n\\label{eq:fidelity-1}\n\\end{equation}\nin which\n\\begin{align}\n\\Braket{n | \\omega} &= \n\\begin{cases} \\rbr{\\Omega  \\Re\\omega }^{\\frac{1}{4}}\n\\dfrac{2^{\\frac{1}{2}-m} \\sqrt{(2 m)!} }{m!}\n\\dfrac{(\\Omega -\\omega )^m}{(\\omega +\\Omega )^{m+\\frac{1}{2}}}\n& n = 2m, \\\\\n0 & n = 2m+1,\n\\end{cases}\n\\tag{\\ref{eq:n|omega} revisited} \\\\\n\\Braket{n | \\rho | n} &=\n\\frac{1}{Z}\\cfun{\\exp}{-\\rbr{n+\\frac{1}{2}}\\frac{\\Omega}{T}}\n\\equiv \n\\rbr{\\ee^{\\Omega/T}-1} \\cfun{\\exp}{-\\rbr{n+1}\\frac{\\Omega}{T}}.\n\\label{eq:n|rho|n}\n\\end{align}\nInserting \\cref{eq:n|omega,eq:n|rho|n} into \\cref{eq:fidelity-1}, one finds \nthat each term in the summation is of the form $b\\cdot\\binom{2m}{m}a^{2m}$ \nwhere $a$ and $b$ are expressions of $\\Omega$, $\\omega$ and $T$, which can be \ncomputed by using\n\\begin{equation}\n\\arcsin z = \\sum_{n=0}^{+\\infty} \\binom{2n}{n}\\frac{z^{2n+1}}{4^n\\rbr{2n+1}}\n\\end{equation}\nand taking derivative with respect to $z$ on both sides. Therefore the fidelity \nof $\\rho(T)$ and $\\Ket{\\omega}$ is computed to be\n\\begin{equation}\n\\rfun{F}{\\Ket{\\omega}, \\rho(T)} = \\sqrt{2} \\sqrt[4]{\\frac{\\Omega  \\Re{\\omega} \n\\left(\\ee^{\\Omega /T}-1\\right)^2}{(\\Omega -\\Re{\\omega})^2+\\Im{\\omega}^2 - \n\\ee^{2 \\Omega/T} \\rbr{(\\Omega +\\Re{\\omega})^2+\\Im{\\omega}^2})}},\n\\label{eq:fidelity-gg-th}\n\\end{equation}\nwhich can be used to set a bound on the trace distance by \\cref{eq:ineq-fvdg}.\n\n", "meta": {"hexsha": "6cf1caf0d4ca9d77ecca50c6784e8ee22eac0720", "size": 5790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ubonn-thesis-current/mythesis/sections/thesis_distappd.tex", "max_stars_repo_name": "cmp0xff/Masterarbeit", "max_stars_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_distappd.tex", "max_issues_repo_name": "cmp0xff/Masterarbeit", "max_issues_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_distappd.tex", "max_forks_repo_name": "cmp0xff/Masterarbeit", "max_forks_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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.9565217391, "max_line_length": 81, "alphanum_fraction": 0.6274611399, "num_tokens": 1870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6373029744732532}}
{"text": "%!TEX root =  ../main.tex\n% !TEX useTabs\n\n\\subsection{$r, \\theta$}\nApart from arbitrary roads running north-south and east-west, no one would ever walk solely\nin horizontal and vertical lines.  When you want to fly your plane somewhere, you turn the\nnose towards where you want to go, and walked the shortest path.  For example, you might\nknow that your friend is 3m east of you and 4m north, but you would never walk the 7m such \nludacrous path takes.  What is the shortest path ($r$)?  What angle would you turn ($\\theta$)?\n\n\\begin{tikzpicture}\n\t\\draw (0,0) -- (3,0) -- (3,4) -- (0,0);\n\t\\draw (1.5,0) node[anchor=north] {3m};\n\t\\draw (3,2) node[anchor=west] {4cm};\n\t\\draw (1.4,2) node[anchor=south] {$r$};\n\t\\draw (0.5,0.4) node {$\\theta$};\n\\end{tikzpicture}\n\nWell, by this point in this class, you are undoubtedly very used to using the Pythagorean Theorem\nto find hypotenuses, and inverse tangent to calculate angle.  While you should certainly be able to\ncalculate $r=5$, a calculator or table is required to know when tangent is $1.\\overline{3}$, \napproximately 0.927 radians.\n\nOn the other hand, suppose you knew something was 6 miles away, at an angle of $\\frac{2}{3}\\tau$.\nHow would you determine how far east-west and north-south it is?  Just as we learned with vectors,\nwe can use sine and cosine to calculate these values.  $\\sin(\\frac{2}{3}\\tau)=\\frac{y}{6}$ and \n$\\cos(\\frac{2}{3}\\tau)=\\frac{x}{6}$.  Solving for $x$ and $y$, we see the coordinates of the\ndestination are $(-3,-3\\sqrt{3})$.\n\n\\begin{derivation}{Polar Conversion Formulae}\n\\begin{equation}\n\tr^2=x^2+y^2\n\\end{equation}\n\\begin{equation}\n\t\\tan\\theta=\\frac{y}{x}\n\\end{equation}\n\\begin{equation}\n\tx=r\\cdot\\cos\\theta\n\\end{equation}\n\\begin{equation}\n\ty=r\\cdot\\sin\\theta\n\\end{equation}\n*The tangent equation doesn't work everywhere: what are the limitations on how we can use it?\n\\end{derivation}\n\n\\subsection{Properties}\nWorking with $r$ and $\\theta$ to the exclusion of $x$ and $y$ yields a different way of looking\nat the coordinate plane, called \\emph{polar coordinates}.  Locations are still labeled via ordered\npairs, but of the form $(r,\\theta)$.  Polar graph paper looks like this:\n\n  \\begin{tikzpicture}[scale=0.5]\n    %Circles \n    \\foreach \\r in {1, 2,...,7}\n      \\draw[thick] (0,0) circle (\\r);    \n     %half radii \n    %\\foreach \\r in {0.5, 1.5,...,7}\n      %\\draw[thin] (0,0) circle (\\r);\n    %1° Rays\n    %\\foreach \\a in {0, 1,...,359}\n      %\\draw[-] (\\a:7.7) -- (\\a:8);\n    %5° Rays\n    %\\foreach \\a in {0, 5,...,359}\n      %\\draw[-] (\\a:7.5) -- (\\a:8);      \n    %15° Rays\n    \\foreach \\a in {0, 15,...,359}\n      \\draw[thick] (\\a:1) -- (\\a:8); \n    %30° Rays\n    \\foreach \\a in {0, 30,...,359}\n      \\draw[thick] (0, 0) -- (\\a:8);\n    %Radius labels (background filled white)\n    %\\foreach \\r in {1, 2,...,7}\n      %\\draw (\\r,0) node[inner sep=1pt,below=3pt,rectangle,fill=white] {$\\r$};\n    %Main rays\n    \\foreach \\a in {0, 90,...,359}\n      \\draw[very thick] (0, 0) -- (\\a:8);\n\\end{tikzpicture}\n\n\\subsection{Negative Radii}\nThe ``spokes'' are every $\\frac{\\tau}{24}$, and the circles are every unit.  You might begin by turning\nthe angle first, and then ``walking out'' the radius.  On the polar graph, try locating $(3,\\frac{\\tau}{4})$.\nIt shouldn't be too complicated to see this is the same as the rectangular coordinate (0,3).  Angles\ngreater than $\\tau$ are not difficult to reduce to simpler terms, but what about negative radii?  \nWhere would $(-3,\\frac{3}{4}\\tau)$ take you?  We might imagine a person standing at the\npole (the origin on a polar graph), he or she would begin facing to the right, and then turning \ncounter-clockwise.  $\\frac{3}{4}\\tau$ is straight down, so our person's back is to the ``north''.  A\nnegative radii can be thought of as walking \\emph{backwards}, so $(3,\\frac{\\tau}{4})$ and\n$(-3,\\frac{3}{4}\\tau)$ take you to the same place!\n\n\n\\subsection{Polar Equations}\nJust as Cartesian (or rectangular) equations as $y$ equals something in terms of $x$, so\ntoo polar equations are written as $r$ equals something in terms of $\\theta$.  Press the `mode'\nbutton on your calculator, and you can see that there is an option called `POL', short for POLAR.\nAccept that option and see what the `y=' button has become!  What has the X button become?\n\nThe exercise or problems will walk you through many different types of $r=$ equations, and they\ncan all be demonstrated in your calculator.  However, just as you have to know how to graph\n$x=n$ even though it is not a function in rectangular, so too you should take a moment and reason\nthrough how to graph $\\theta=\\frac{1}{5}\\tau$ and similar equations. \n\nWhen we attempt plot points to determine the make-up of $x=3$, we see that $y$ can be anything.\nIn other words, (3,0); (3,1); (3,2); (3,-2); (3,-10), etc. are all on the graph.  When we take this principle\nover to graphing $\\theta=\\frac{5}{6}$, we recognize that any radius is possible, including negatives.\n~\\vfill\n", "meta": {"hexsha": "b0a3fd2c357fefb4bd947fb69855eb79cb148e22", "size": 4937, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch12/1201.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": "ch12/1201.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": "ch12/1201.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": 47.019047619, "max_line_length": 109, "alphanum_fraction": 0.6775369658, "num_tokens": 1561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568416, "lm_q2_score": 0.8198933271118222, "lm_q1q2_score": 0.637302960882539}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath} \n\n\\usepackage{pgfplots}\n\\usepackage{tikz}\n\\usepackage{nicefrac}\n\\pgfplotsset{every axis legend/.append style={\nat={(0,0)},\nanchor=north east}}\n\\usetikzlibrary{shapes,positioning,intersections,quotes}\n\n\\definecolor{darkgreen}{rgb}{0.0, 0.6, 0.0}\n\\definecolor{darkred}{rgb}{0.7, 0.0, 0.0}\n\n\\title{Interpolation}\n\\begin{document}\n\\def\\horzbar{\\text{magic}}\n\n  \\pagenumbering{gobble}\n  \\maketitle\n  \\newpage\n  \\pagenumbering{arabic}\n\n\\section*{Introduction}\n\nWe have to arrays of numbers $X$ and $Y$. Array $X$ contains independent data points. Array $Y$ contains dependent data points $y_i,i=1,…,m$.\n\nWe want to find a function $\\hat{y}(x)$, which gets the exact same value with given points.\\\\\n\n\n\\section*{Linear Interpolation}\n\nLinear interpolation is achieved by connecting two data points with a straight line.\n\nFor $x_i < x < x_{i+1}$:\n\n$$\\hat{y}(x) = y_i + \\frac{(y_{i+1} - y_{i})(x - x_{i})}{(x_{i+1} - x_{i})}.$$\n\n\\section*{Derivation}\n\n \n\\begin{tikzpicture}\n\n\t\\draw [dashed]  (-3, -1.9) -- (3, -1.9);\n\t\\draw [dashed]  (3, -5) -- (3, -1.9);\n\t\\draw [-stealth](-3,-5) -- (9,-5);\n\t\\draw [-stealth](-3,-5) -- (-3,1);\n\n    \\draw [stealth-stealth, blue](0,-3) -- (8,0);\n    \\draw [stealth-stealth, red](8,0) -- (8,-3);\n    \\draw [stealth-stealth, green](0,-3) -- (8,-3);\n    \\draw [stealth-stealth, black](0,-3.1) -- (3,-3.1);\n\n\t\\node[above right=0pt of {(8, 0)}, outer sep=2pt,fill=none] {$(x_2, y_2)$};\n\t\\node[above right=0pt of {(8, -1.8)}, outer sep=2pt,fill=none, darkred] {$y_2 - y_1$};\n\t\\node[above right=0pt of {(4.5, -3.6)}, outer sep=2pt,fill=none, darkgreen] {$x_2 - x_1$};\n\t\\node[above right=0pt of {(1, -3.6)}, outer sep=2pt,fill=none] {$x - x_1$};\n\t\\node[above right=0pt of {(-1,-3.7)}, outer sep=2pt,fill=none] {$(x_2, y_2)$};\n\t\\node[above right=0pt of {(-1,-1.7)}, outer sep=2pt,fill=none] {$y$};\n\t\\node[above right=0pt of {(3,-4.2)}, outer sep=2pt,fill=none] {$x$};\n\t\\node[above right=0pt of {(3,-2.7)}, outer sep=2pt,fill=none] {$h$};\n\n\\end{tikzpicture}\n\n\n$$\\alpha = \\frac{y_2 - y_1}{x_2 - x_1}$$\n\n$$h = \\alpha \\cdot (x - x_1)$$\n\n$$y = y_1 + h$$\n\n$$y = y_1 + (x - x_1) \\cdot \\frac{y_2 - y_1}{x_2 - x_1}$$\n\n\\section*{Example}\n\nWe are given two points A(-2, 0) and B (2, 2).\\\\\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=middle,\n        axis y line=middle,\n        width=8cm,\n        height=8cm,\n        xmin=-5,   % start the diagram at this x-coordinate\n        xmax= 5,   % end   the diagram at this x-coordinate\n        ymin=-5,   % start the diagram at this y-coordinate\n        ymax= 5,   % end   the diagram at this y-coordinate\n        xlabel=$x$,\n        ylabel=$y$,\n        legend cell align=left,\n        legend pos=south east,\n        legend style={draw=none},\n        tick align=outside,\n        enlargelimits=false]\n      % plot the function\n      \\addplot[domain=-5:5, blue, ultra thick,samples=500] {0.5*x + 1};\n      \\fill[red] (700,700) circle (3pt);\n    \t  \\fill[red] (300, 500) circle (3pt);\n    \t  \\draw [dashed]  (500, 700) -- (680, 700);\n    \t  \\draw [dashed]  (700, 500) -- (700, 680);\n    \t  \\node[above right=0pt of {(255,510)}, outer sep=2pt,fill=none] {A};\n\t  \\node[above right=0pt of {(655,710)}, outer sep=2pt,fill=none] {B};\n\t\\legend{$\\nicefrac{1}{2} \\cdot x$ + 1}\n    \\end{axis}\n\\end{tikzpicture}\n\nLet's try to evaluate the value of the function at $x=1$\n\n$$\\hat{y}(x) = y_i + \\frac{(y_{i+1} - y_{i})(x - x_{i})}{(x_{i+1} - x_{i})} = 0 + \\frac{(2 - 0)(1 - (-2))}{(2 - (-2))} = 1.5$$\n\n\\newpage\n\\section*{Cubic Spline}\n\nThe interpolating function in cubic spline interpolation is a set of piecewise cubic functions.\\\\\n\nFor $x_i < x < x_{i+1}$:\\\\\n\nWe have two points $(x_i, y_i)$ and $(x_{i+1}, y_{i+1})$  joined with a cubic polynomial:\n\n$$S_i(x) = a_i x^3 + b_i x^2 + c_i x + d_i$$\n\nFor $n$ points, there are $n-1$ cubic functions to find, and each cubic function requires four coefficients ($a_i, b_i, c_i, d_i$).\n\nThere are $4(n-1)$ unknowns to find.\\\\\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=middle,\n        axis y line=middle,\n        width=13cm, height=13cm,     % size of the image\n        grid = none,\n        grid style={dashed, gray!0},\n        %xmode=log,log basis x=10,\n        %ymode=log,log basis y=10,\n        xmin=-2,     % start the diagram at this x-coordinate\n        xmax= 4,    % end   the diagram at this x-coordinate\n        ymin=-7,     % start the diagram at this y-coordinate\n        ymax= 7,   % end   the diagram at this y-coordinate\n        %/pgfplots/xtick={0,1,...,60}, % make steps of length 5\n        %extra x ticks={23},\n        %extra y ticks={0.507297},\n        axis background/.style={fill=white},\n        ylabel=y,\n        xlabel=x,\n        %xticklabels={,,},\n        %yticklabels={,,},\n        tick align=outside,\n        tension=0.08]\n      % plot the stirling-formulae\n      \\addplot[name path global=a, domain=-2:4, blue, thick,samples=500] {-x*x*x + 4*x*x-x-4};\n       \\fill[red] (211, 39.3) circle (3pt);\n       \\fill[red] (455, 108.8) circle (3pt);\n       \\node[above right=0pt of {(211, 39.3)}, outer sep=2pt,fill=none] {$y_1$};\n    \t  \\node[above right=0pt of {(455, 108.8)}, outer sep=2pt,fill=none] {$y_2$};\n    \t   \\node[above right=0pt of {(250, 98.8)}, outer sep=2pt,fill=none] {$S_1(x)$};\n\\draw [-stealth](280,98) -- (350,82\n);\n    \\end{axis}\n\\end{tikzpicture}\n\n\\section*{Derivation}\n\nWe are trying to find a function $S_i(x) = a_i x^3 + b_i x^2 + c_i x + d_i$ going trough both points: $(x_i, y_i)$ and $x_{i+1}, y_{i+1}$.\n\n\\begin{align}\nS_i(x_i) &= y_i,\\quad i = 1,\\ldots,n-1,\n\\end{align}\n\\begin{align}\nS_i(x_{i+1}) &= y_{i+1},\\quad i = 1,\\ldots,n-1,\n\\end{align}\n\nSmoothness condition:\n\\begin{align}\nS'_i(x_{i+1}) &= S^{\\prime}_{i+1}(x_{i+1}),\\quad i = 1,\\ldots,n-2,\n\\end{align}\n\\begin{align}\nS''_i(x_{i+1}) &= S''_{i+1}(x_{i+1}),\\quad i = 1,\\ldots,n-2,\n\\end{align}\n\nBoundry condition: The curve is a “straight line” at the end points:\n\\begin{align}\nS''_1(x_1) &= 0\n\\end{align}\n\\begin{align}\nS''_{n-1}(x_n) &= 0\n\\end{align}\n\nLet $h_{i}=x_{i}-x_{i-1}$\n\nLet $S_i^{''}(x_i) = S_i^{''}(x_{i+1}) = M_i$\n\n$S_1^{''}(x_1)= M_0 = 0$ and $S_n^{''}(x_n) = M_n = 0$\n\nOther $M_i$ are unknown.\n\nBy Lagrange interpolation, we can interpolate each $S''_{i}$ on  $[x_{i-1},x_{i}]$:\n\n$$S''_{i}(x)=M_{i-1}{\\frac {x_{i}-x}{h_{i}}}+M_{i}{\\frac {x-x_{i-1}}{h_{i}}} \\quad for \\quad x\\in [x_{i-1},x_{i}]$$\n\nIntegrating the above equation twice and using the condition that $C_{i}(x_{i-1})=y_{i-1}$ and $ C_{i}(x_{i})=y_{i}$ to determine the constants of integration, we have.\n\n$$ S_{i}(x)=M_{i-1}{\\frac {(x_{i}-x)^{3}}{6h_{i}}}+M_{i}{\\frac {(x-x_{i-1})^{3}}{6h_{i}}}+\\left(y_{i-1}-{\\frac {M_{i-1}h_{i}^{2}}{6}}\\right){\\frac {x_{i}-x}{h_{i}}}+\\left(y_{i}-{\\frac {M_{i}h_{i}^{2}}{6}}\\right){\\frac {x-x_{i-1}}{h_{i}}}$$\n$${\\text{for}}\\quad x\\in [x_{i-1},x_{i}] $$\\\\\n\nThis expression gives us the cubic spline S(x) if $ M_{i},i=0,1,\\cdots ,n$ can be determined.\n$$S'_{i+1}(x)=-M_{i}{\\frac {(x_{i+1}-x)^{2}}{2h_{i+1}}}+M_{i+1}{\\frac {(x-x_{i})^{2}}{2h_{i+1}}}+{\\frac {y_{i+1}-y_{i}}{h_{i+1}}}-{\\frac {M_{i+1}-M_{i}}{6}}h_{i+1}$$\n\n$$S'_{i+1}(x_{i})=-M_{i}{\\frac {h_{i+1}}{2}}+{\\frac {y_{i+1}-y_{i}}{h_{i+1}}}-{\\frac {M_{i+1}-M_{i}}{6}}h_{i+1}$$\n\nSimilarly, when $x\\in [x_{i-1},x_{i}]$, we can shift the index to obtain\n\n\\begin{align}\nS'_{i}(x) &=-M_{i-1}{\\frac {(x_{i}-x)^{2}}{2h_{i}}}+M_{i}{\\frac {(x-x_{i-1})^{2}}{2h_{i}}}+{\\frac {y_{i}-y_{i-1}}{h_{i}}}-{\\frac {M_{i}-M_{i-1}}{6}}h_{i}\n\\end{align}\n\n \n$$ S'_{i}(x_{i})=M_{i}{\\frac {h_{i}}{2}}+{\\frac {y_{i}-y_{i-1}}{h_{i}}}-{\\frac {M_{i}-M_{i-1}}{6}}h_{i}$$\n\nSince $ S'_{i+1}(x_{i})=S'_{i}(x_{i})$, we can derive:\n\n$$\\mu _{i}M_{i-1}+2M_{i}+\\lambda _{i}M_{i+1}=d_{i}\\quad {\\text{for}}\\quad i=1,2,\\cdots ,n-1,$$\n \n$$\\mu _{i}={\\frac {h_{i}}{h_{i}+h_{i+1}}},\\quad \\lambda _{i}=1-\\mu _{i}={\\frac {h_{i+1}}{h_{i}+h_{i+1}}},\\quad {\\text{and}}\\quad d_{i}=6f[x_{i-1},x_{i},x_{i+1}]$$\n\nand $f[x_{i-1},x_{i},x_{i+1}]$ is a divided difference.\\\\\n\nAccording to different boundary conditions, we can solve the system of equations above to obtain the values of $M_{i}$'s.\\\\\n\n$S'_{1}(x_{0})=f'_{0}$ and $S'_{n}(x_{n})=f'_{n}$. According to equation (7), we can obtain:\n\n$$S'_{1}(x_{0})=-M_{0}{\\frac {(x_{1}-x_{0})^{2}}{2h_{1}}}+M_{1}{\\frac {(x_{0}-x_{0})^{2}}{2h_{1}}}+{\\frac {y_{1}-y_{0}}{h_{1}}}-{\\frac {M_{1}-M_{0}}{6}}h_{1}$$\n$$\\Rightarrow f'_{0}=-M_{0}{\\frac {h_{1}}{2}}+f[x_{0},x_{1}]-{\\frac {M_{1}-M_{0}}{6}}h_{1}$$\n$$\\Rightarrow 2M_{0}+M_{1}={\\frac {6}{h_{1}}}(f[x_{0},x_{1}]-f'_{0})=6f[x_{0},x_{0},x_{1}]$$\n\nAnalogously:\n\n$$ S'_{n}(x_{n})=-M_{n-1}{\\frac {(x_{n}-x_{n})^{2}}{2h_{n}}}+M_{n}{\\frac {(x_{n}-x_{n-1})^{2}}{2h_{n}}}+{\\frac {y_{n}-y_{n-1}}{h_{n}}}-{\\frac {M_{n}-M_{n-1}}{6}}h_{n}$$\n\n$$M_{n-1}+2M_{n}={\\frac {6}{h_{n}}}(f'_{n}-f[x_{n-1},x_{n}])=6f[x_{n-1},x_{n},x_{n+1}]$$\n\nLet:\\\\\n$\\lambda _{0}=\\mu _{n}=1,$\\\\\n$d_{0}=6f[x_{0},x_{0},x_{1}]$ and\\\\ \n$d_{n}=6f[x_{n-1},x_{n},x_{n}]$\n\n \n\\begin{equation*}\n  \\begin{bmatrix}\n    2 & \\lambda_0 \\\\ \n    \\mu_1 & 2 & \\lambda_1 \\\\ \n    & \\ddots & \\ddots & \\ddots \\\\\n    && \\ddots & \\ddots & \\ddots \\\\\n\t&&& \\ddots & \\ddots & \\ddots \\\\\n\t&&&& \\mu_{n-1} & 2 & \\lambda_{n-1} \\\\ \n\t&&&&& \\mu_{n} & 2 \\\\ \n  \\end{bmatrix}\n  %\n   \\begin{bmatrix}\n    M_0 \\\\\n    M_1 \\\\\n    \\vdots \\\\\n    \\vdots \\\\\n    \\vdots \\\\\n    M_{n-1} \\\\\n    M_n \\\\\n  \\end{bmatrix} \n  =\n   %\n  \\begin{bmatrix}\n    d_0 \\\\\n    d_1 \\\\\n    \\vdots \\\\\n    \\vdots \\\\\n    \\vdots \\\\\n    d_{n-1} \\\\\n    d_n \\\\\n  \\end{bmatrix} \n\\end{equation*}\n\n \\newpage\n\\section*{Lagrange Polynomial Interpolation}\n\nLagrange polynomial interpolation gives us a single polynomial that connects all of the data points.\n\nThat polynomial is denoted as $L(x)$. It is true that $L(x_i) = y_i$ for all points $(x_i, y_i)$ .\n\n$$L(x) = \\sum_{i = 1}^n y_i P_i(x).$$\n\nEach polynomial appearing in the sum is called a Lagrange basis polynomials, $P_i(x)$.\n\n$$P_i(x) = \\prod_{j = 1, j\\ne i}^n\\frac{x - x_j}{x_i - x_j},$$\n\n\n\\section*{Example}\n\nWe are given three points A(-1, 1), B(2, 3) and C(3,5).\\\\\n\n$$P_1(x) = \\frac{(x - x_2)(x - x_3)}{(x_1-x_2)(x_1-x_3)} = \\frac{(x - 2)(x - 3)}{(-1-2)(-1-3)} = \\frac{1}{12}(x^2 - 5x + 6)$$\n\n$$P_2(x) = \\frac{(x - x_1)(x - x_3)}{(x_2-x_1)(x_2-x_3)} = \\frac{(x + 1)(x - 3)}{(2 + 1)(2-3)} = -\\frac{1}{3}(x^2 - 2x - 3)$$\n\n$$P_3(x) = \\frac{(x - x_1)(x - x_2)}{(x_3-x_1)(x_3-x_2)} = \\frac{(x + 1)(x - 2)}{(3 + 1)(3-2)} =\\frac{1}{4}(x^2 -x - 2)$$\n\n$$ L(x) = 1 \\cdot P_1(x) + 3 \\cdot P_2(x) + 5 \\cdot P_3(x) $$\n\n$$ L(x) = 1 \\cdot P_1(x) + 3 \\cdot P_2(x) + 5 \\cdot P_3(x) $$\n\n$$ L(x) = \\frac{1}{3} x^2 + \\frac{1}{3} x + 1 $$\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=middle,\n        axis y line=middle,\n        width=10cm,\n        height=10cm,\n        xmin=-5,   % start the diagram at this x-coordinate\n        xmax= 6,   % end   the diagram at this x-coordinate\n        ymin= -1,   % start the diagram at this y-coordinate\n        ymax= 8,   % end   the diagram at this y-coordinate\n        xlabel=$x$,\n        ylabel=$y$,\n        legend cell align=left,\n        legend pos=north east,\n        legend style={draw=none},\n        tick align=outside,\n        enlargelimits=false,\n        xtick distance=1,\n        ytick distance=1]\n         \n      % plot the function\n      \\addplot[domain=-5:10, blue, ultra thick,samples=500] {1/3*(x^2 + x + 3)};\n\n      \\fill[red] (400, 20) circle (3pt);\n    \t  \\fill[red] (700, 40) circle (3pt);\n    \t  \\fill[red] (800, 60) circle (3pt);\n\n    \t  \\node[above right=0pt of {(340, 13)}, outer sep=2pt,fill=none] {A};\n\t  \\node[above right=0pt of {(630, 40)}, outer sep=2pt,fill=none] {B};\n\t \\node[above right=0pt of {(730, 60)}, outer sep=2pt,fill=none] {C};\n\n\t\\legend{$\\frac{1}{3} x^2 + \\frac{1}{3} x + 1$}\n\n    \\end{axis}\n\\end{tikzpicture}\n\n\\end{document}", "meta": {"hexsha": "8756c85492aa79c630898b4ddbf9b530a6d4f597", "size": 11717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/interpolation.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/interpolation.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/interpolation.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": 33.7665706052, "max_line_length": 239, "alphanum_fraction": 0.5567978151, "num_tokens": 5022, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.8947894675053567, "lm_q1q2_score": 0.6372978459442212}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=0.7in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{hyperref}\n\\hypersetup{colorlinks=true, urlcolor=green}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\begin{document}\n\n\\title{The Gory Details}\n\\author{Pavel Komarov}\n\\date{March 12, 2018}\n\\maketitle\n\nHere lies a full explanation of how multivariate Projection Pursuit Regression (PPR) and univariate Classification work, to the degree I currently understand. It is as much for me as for you, because I much prefer my own notation, and every time I have to dig in to the bones of the code and faff with the loss function, I end up having to refer to \\href{http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-3824.pdf}{the original paper}'s somewhat ambiguous, derivationless equations. Formerly I was attempting to deposit some of this knowledge in code comments, but they took up too much space while somehow remaining marvelously unreadable.\n\nThis is all in \\LaTeX\\ because \\href{https://github.com/github/markup/issues/897}{native math in markdown is amazingly still not supported by github}, so a \\texttt{.md} would really be no less uncomfortable than code comments. If you happen to want to know how I accomplished all this gorgeous formatting, the source \\texttt{.tex} is in the \\href{https://github.com/pavelkomarov/projection-pursuit/tree/master/doc}{/doc} subdirectory of the \\href{https://github.com/pavelkomarov/projection-pursuit}{repo} and can be compiled with \\texttt{pdflatex}.\n\nI attempt to follow a structure based on the \\href{https://www.youtube.com/watch?v=H6ygbGX8OV8&t=9m19s}{five components of any machine learning algorithm}:\n\n\\begin{enumerate}\n\t\\setlength\\itemsep{-2mm}\n\t\\item A Task/Problem Reduction\n\t\\item A Model\n\t\\item A Loss Function\n\t\\item An Optimization Scheme\n\t\\item Data\n\\end{enumerate}\n\n--or at least the middle three, since by the time the data for your task meets my algorithm you'll have abstracted away concerns about where it came from and what it actually means.\n\n\\section{The Model}\n\nPPR is a statistical model of the form:\n\n$$\\vec{y_i} = \\sum_{j=1}^{r} f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\vec{\\beta_j}^T$$\n\nwhere:\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $i$ iterates examples, the rows of input and output matrices\n\t\\item $j$ iterates the number of terms in the PPR ``additive model\"\n\t\\item $r$ is the total number of projections and functions (terms) in the PPR\n\t\\item $\\vec{y_i}$ is a $d$-dimensional vector, the $i$\\textsuperscript{th} row in an output matrix $\\pmb{Y} \\in \\mathbb{R}^{n \\times d}$\n\t\\item $\\vec{x_i}$ is a $p$-dimensional vector, the $i$\\textsuperscript{th} row of an input matrix $\\pmb{X} \\in \\mathbb{R}^{n \\times p}$\n\t\\item $\\vec{\\alpha_j}$ is the $j$\\textsuperscript{th} projection vector in the mdoel, a $p$-dimensional vector inner-producted with $\\vec{x_i}$\n\t\\item $f_j$ is the $j$\\textsuperscript{th} function in the model, mapping from $\\mathbb{R}^1 \\rightarrow \\mathbb{R}^1$\n\t\\item $\\vec{\\beta_j}^T$ is the transpose of $\\vec{\\beta_j}$, a $d$-dimensional vector outer-producted with the result of $f_j$ to yield a result in the output space\n\t\\item $\\cdot$ is an inner product\n\t\\item $\\otimes$ is an outer product\n\\end{itemize}\n\nThis can be ``vectorized\" as\n\n$$\\pmb{\\hat{Y}} = \\sum_{j=1}^r f_j(\\pmb{X} \\cdot \\vec{\\alpha_j}) \\otimes \\vec{\\beta_j}^T$$\n\nwhere the ``hat\" \\string^ distinguishes the answers predicted, as opposed to known training answers.\\newline\n\nI also term this the ``evaluation function\". It may seem complicated, but the idea is simple:\n\n\\begin{enumerate}\n\t\\setlength\\itemsep{-2mm}\n\t\\item Linearly project the input down to one dimension where it is easier to work with, thereby sidestepping the curse of dimensionality.\n\t\\item Find a sensible mapping from this reduced space to weighted ``residuals\", unexplained variance in the outputs. This is where the nonlinearity happens.\n\t\\item Unpack from the single-dimensional residual space to the output space with a kind of inverse projection.\n\\end{enumerate}\n\n\\subsection{A Word on Additive Models}\n\nIn practice a single projection-mapping-expansion is not descriptive enough to capture the richness of what may be a very complicated underlying relationship between $\\pmb{X}$ and $\\pmb{Y}$, so it is repeated $r$ times, each new ``stage\" only accounting for the variance left unexplained by the stages that have come before. Notice that, as per Taylor's Theorem and the no-doubt familiar universal approximation theorems, for certain classes of functions $f$, as $r$ goes to infinity the evaluation function can approximate any continuous functional relationship between inputs and outputs.\n\n\\section{The Loss Function}\n\nThe (supervised) learning process consists of minimizing a standard quadratic cost, or ``loss\", function:\n\n$$loss = \\sum_{i=1}^n w_i (y_i - \\hat{y_i})^2$$\n\nwhere:\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $i$ iterates all training examples\n\t\\item $n$ is the total number of training examples\n\t\\item $w_i$ is the weight of the $i$\\textsuperscript{th} example\n\t\\item $y_i$ is the known answer for example $i$\n\t\\item $\\hat{y_i}$ (``y-i-hat\") is the answer predicted by the model for example $i$\n\\end{itemize}\n\nIn words: Get as close as you can for all examples, where the penalty for predicting an example incorrectly scales with the square of how wrong you are.\n\nThere are other choices of loss function, including an absolute value loss with no square penalty. This can work better in cases where a nonliner penalty might cause the algorithm to account too strongly for a few outlier examples.\n\n(TODO) It is also possible to add regularization terms, which bias the optimization process to find smaller parameter values. This is good for numerical stability and has the added benefit of reducing the likelihood of overfit.\n\nUnfortunately, modifying the loss function in either of these ways means altering the optimization process, and that's a mathematical bear I just haven't chosen to wrestle with.\\newline\n\nPlugging the evaluation function in to the cost function yields a relationship between model parameters and loss. Because there are multiple dimensions in our vector $\\vec{y_i}$, we introduce a sum over them so the PPR is motivated to make good predictions for all entries of the output:\n\n$$loss = \\sum_{i=1}^n w_i \\sum_{k=1}^d w_k [y_{ik} - \\sum_{j=1}^r f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk}]^2$$\n\nwhere this new fauna:\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $k$ iterates the columns of the output $\\pmb{Y}$\n\t\\item $d$ is the number of outputs, the width of the output matrix $\\pmb{Y}$\n\t\\item $w_k$ is a scalar weight, the relative importance of the $k$\\textsuperscript{th} output dimension\n\t\\item $y_{ik}$ is the scalar $k$\\textsuperscript{th} entry in the vector $\\vec{y_i}$, itself the $i$\\textsuperscript{th} row of $\\pmb{Y}$\n\t\\item $\\beta_{jk}$ is the scalar $k$\\textsuperscript{th} entry of $\\vec{\\beta_j}$ from the evaluation function\n\\end{itemize}\n\nThis can be vectorized as\n\n$$loss = (\\vec{w_I}^T \\cdot (\\pmb{Y} - \\pmb{\\hat{Y}})^2) \\cdot \\vec{w_K}$$\n\nwhere\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $\\vec{w_I}$ is an $n$-vector containing all example weights, $w_i$\n\t\\item $\\vec{w_K}$ is a $d$-vector containing all output dimension weights, $w_k$\n\\end{itemize}\nand the sums disappear inside the inner products.\\newline\n\nThe parameters we need to optimize to make the PPR ``learn\" are $\\vec{\\alpha_j}$, $f_j$, and $\\vec{\\beta_j}$. $w_k$ are hyperparameters chosen by the user, just as $r$ is chosen. If output dimensions are on differing scales and the user wishes for the loss to be relative to those scales, then choosing $w_k$ inversely proportional to the variance of outputs causes the loss to treat outputs more evenly. If some output dimensions are more important than others, then setting their weights higher causes predictions in those dimensions to be closer.\n\n\\section{The Optimization Scheme}\n\nThe macroscopic optimization scheme to solve for so many different parameters is non-obvious but straightforward:\n\\begin{enumerate}\n\t\\setlength\\itemsep{-2mm}\n\t\\item Initialize all $\\vec{\\alpha_j}$, $f_j$ and $\\vec{\\beta_j}$ to something random. Let $j=1$. \n\t\\item Find the ``residual\" variance unexplained by all stages fit so far.\n\t\\item Project the input in to single dimension: $\\pmb{X} \\cdot \\vec{\\alpha_j}$.\n\t\\item Fit $f_j$ to a weighted residual target versus projections.\n\t\\item Use this $f_j$ to find a better setting for $\\vec{\\beta_j}$.\n\t\\item Use a Gauss-Newton scheme to solve for an update to $\\vec{\\alpha_j}$.\n\t\\item Repeat steps 3-6 until $f_j$, $\\vec{\\beta_j}$, and $\\vec{\\alpha_j}$ converge.\n\t\\item (optional) Use the newly converged parameters to retune all previous $f_t$, $\\vec{\\beta_t}$, $\\vec{\\alpha_t}$ where $t \\leq j$. (backfitting)\n\t\\item Increment $j$ and go back to step 2 until $j$ reaches $r$.\n\\end{enumerate}\n\nThe inner loop here is a form of \\textit{alternating optimization}, wherein all parameters except one are held constant, the best setting for that parameter given those constants is found, and the process cycled through all parameters until convergence. The outer loop builds up the additive model.\n\nBut this leaves some details unexplained. How exactly is the residual found? How are parameters found given fixed solutions to the others? How do we test for convergence?\n\n\\subsection{Finding The Residual}\n\nThe residual trick cleverly separates the contribution of the $j$\\textsuperscript{th} stage from the other terms in the additive model. Consider rephrasing the loss function as:\n\n$$loss = \\sum_{i=1}^n w_i \\sum_{k=1}^d w_k [y_{ik} - \\sum_{t \\neq j} f_t(\\vec{x_i} \\cdot \\vec{\\alpha_t}) \\otimes \\beta_{tk} - f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk}]^2$$\n\nNow if we let\n\n$$r_{ijk} = y_{ik} - \\sum_{t \\neq j} f_t(\\vec{x_i} \\cdot \\vec{\\alpha_t}) \\otimes \\beta_{tk}$$\n\nthen\n\n$$loss,\\ L = \\sum_{i=1}^n w_i \\sum_{k=1}^d w_k [r_{ijk} - f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk}]^2$$\n\nIn practice we will wish to find all $r_{ijk}$ for a particular $j$. Call this $\\pmb{R}_j \\in \\mathbb{R}^{n \\times d}$, the same space as the output. It can be found with\n\n$$\\pmb{R}_j = \\pmb{Y} - \\sum_{t \\neq j} f_t(\\pmb{X} \\cdot \\vec{\\alpha_t}) \\otimes \\vec{\\beta_t}$$\n\nwhere $f_t(\\pmb{X} \\cdot \\vec{\\alpha_t})$ is actually an $n$-vector.\n\n\\subsection{Optimizing $\\vec{\\beta_j}$ Given $\\vec{\\alpha_j}$ and $f_j$}\n\n$$loss\\ for\\ the\\ jth\\ term,\\ L_j = \\sum_{i=1}^n w_i \\sum_{k=1}^d w_k [r_{ijk} - f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk}]^2$$\n\nTo optimize with respect to a parameter, use good ol' calculus: Take a derivative, set equal to zero, and solve. Let's select $\\beta_{jk'}$, the $(k=k')$\\textsuperscript{th} entry of $\\vec{\\beta_j}$ as the parameter of interest.\n\n$$\\frac{\\partial L_j}{\\partial \\beta_{jk'}} = \\sum_{i=1}^n w_i w_{k'} [2(r_{ijk'} - f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk'})(-f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j}))] = 0$$\n\nNotice that the sum over $k$ disappears because no term where $k \\neq k'$ will contain our variable $\\beta_{jk'}$, so for the purposes of differentiation they are constant, and the derivative of constants is zero. Only the weight $w_{k'}$ remains.\n\nAlso, I've been using $\\otimes$ for consistency, but since $\\beta_{jk'}$ is scalar, an outer product is nothing special, just an ordinary multiplication. So we can do some algebra:\n\n$$ -2 w_{k'} \\sum_{i=1}^n w_i [r_{ijk'} f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j})] + 2 w_{k'} \\beta_{jk'} \\sum_{i=1}^n w_i [f_j^2(\\vec{x_i} \\cdot \\vec{\\alpha_j})] = 0 $$\n\n$$\\rightarrow \\beta_{jk'} = \\frac{\\sum_{i=1}^n w_i [r_{ijk'} f_j(\\vec{x_i} \\cdot \\vec{\\alpha_j})]}{\\sum_{i=1}^n w_i [f_j^2(\\vec{x_i} \\cdot \\vec{\\alpha_j})]}$$\n\nThis can be vectorized to find all entries of $\\vec{\\beta_j}$ at once:\n\n$$ \\vec{\\beta_j} = \\frac{\\pmb{R}_j^T \\cdot (\\vec{w_I} \\odot f_j(\\pmb{X} \\cdot \\alpha_j))}{f_j(\\pmb{X} \\cdot \\alpha_j) \\cdot (\\vec{w_I} \\odot f_j(\\pmb{X} \\cdot \\alpha_j))}$$\n\nwhere $\\odot$ is a Hadamard product, $\\vec{w_I}$ is an $n$-vector, $\\pmb{R}_j$ is the residuals, and the dot products are taken along the length-$n$ dimensions of these objects.\n\n\\subsection{Optimizing $f_j$ Given $\\vec{\\alpha_j}$ and $\\vec{\\beta_j}$}\n\nNow a similar argument, but this time consider the parameter of interest to be $f_{i'j}$, the $(i=i')$\\textsuperscript{th} entry of the $n$-vector formed by taking the inner product of $\\pmb{X}$ with $\\alpha_j$ and applying $f_j$ to each entry.\n\n\n$$\\frac{\\partial L_j}{\\partial f_{i'j}} = w_{i'} \\sum_{k=1}^d w_k [2(r_{i'jk} - f_{i'j} \\otimes \\beta_{jk})(-\\beta_{jk})] = 0$$\n\nThe sum over $i$ disappears because only the single term where $i=i'$ isn't constant to the derivative.\n\n$$\\rightarrow w_{i'} \\sum_{k=1}^d w_k [-2 r_{i'jk} \\beta_{jk} + 2 f_{i'j} \\beta_{jk}^2 ] = 0$$\n\n$$\\rightarrow 2 f_{i'j} \\sum_{k=1}^d w_k \\beta_{jk}^2 = 2 \\sum_{k=1}^d w_k r_{i'jk} \\beta_{jk}$$\n\n$$\\rightarrow f_{i'j} = \\frac{\\sum_{k=1}^d w_k r_{i'jk} \\beta_{jk}}{\\sum_{k=1}^d w_k \\beta_{jk}^2}$$\n\nAs in the case of $\\vec{\\beta_j}$, this can be vectorized.\n\n$$ f_j(\\pmb{X} \\cdot \\vec{\\alpha_j}) = \\frac{\\pmb{R}_j \\cdot (\\vec{w_K} \\odot \\vec{\\beta_j})}{\\vec{\\beta_j} \\cdot (\\vec{w_K} \\odot \\vec{\\beta_j})}$$\n\nThis provides targets for the funtion $f_j$. The task is to find the function that maps from this input to this output, for which there are numerous solvers (finding a polynomial by reducing to a linear inverse problem, for example). The example weights $w_i$ disappear in the algebra and so do not affect the targets, but they can be passed on to the function-fitter so it considers some examples more important than others.\n\n\\subsection{Optimizing $\\vec{\\alpha_j}$ Given $\\vec{\\beta_j}$ and $f_j$}\n\nThis is by far the toughest set of parameters to optimize, because they are nested inside the function. This time express the loss as:\n\n$$L_j = \\sum_{k=1}^d w_k [\\vec{w_I} \\odot \\vec{g_{jk}}^2]$$\n\nwhere\n\n$$ \\vec{g_{jk}} = \\vec{r_{jk}} - f_j(\\pmb{X} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk}$$\n\nwhere $\\vec{r_{jk}}$ is the $n$-vector formed by stacking $r_{ijk} \\forall i$ together, or equivalently the $k$\\textsuperscript{th} column of $\\pmb{R}_j$.\n\nThe weights can be factored in to the square to yield a form solveable with \\href{https://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm#Description}{Gauss-Newton}.\n\n$$L_j = \\sum_{k=1}^d \\vec{g_{jkw}}(\\vec{\\alpha_j})^2,$$\n\n$$\\vec{g_{jkw}} = \\sqrt{w_k} \\sqrt{\\vec{w_I}} \\odot (\\vec{r_{jk}} - f_j(\\pmb{X} \\cdot \\vec{\\alpha_j}) \\otimes \\beta_{jk})$$\n\nFind the Jacobian:\n\n$$J_{jk}[u,v] = \\frac{\\partial \\vec{g_{jkw}}(\\vec{\\alpha_j})[u]}{\\partial \\vec{\\alpha_j}[v]} = -\\sqrt{w_k} \\sqrt{w_u} \\dot{f_j}(\\vec{x_u} \\cdot \\vec{\\alpha_j}) \\beta_{jk} x_{uv}$$\n\nwhere $w_u$ is $\\vec{w_I}[u]$, the $u$\\textsuperscript{th} example weight, as distinct from $w_k$, which, remember, are output dimension weights.\n\n\\[\n\\rightarrow J_{jk} = -\\sqrt{w_k} \\beta_{jk}\n\\begin{bmatrix}\n\t\\sqrt{w_0} \\dot{f_j}(\\vec{x_0} \\cdot \\vec{\\alpha_j}) x_{00} & \\sqrt{w_0} \\dot{f_j}(\\vec{x_0} \\cdot \\vec{\\alpha_j}) x_{01} & \\dots & \\sqrt{w_0} \\dot{f_j}(\\vec{x_0} \\cdot \\vec{\\alpha_j}) x_{0p} \\\\\n    \\sqrt{w_1} \\dot{f_j}(\\vec{x_1} \\cdot \\vec{\\alpha_j}) x_{10} & \\sqrt{w_1} \\dot{f_j}(\\vec{x_1} \\cdot \\vec{\\alpha_j}) x_{11} & \\dots & \\sqrt{w_1} \\dot{f_j}(\\vec{x_1} \\cdot \\vec{\\alpha_j}) x_{1p}\\\\\n    \\vdots & & \\ddots & \\vdots\\\\\n    \\sqrt{w_n} \\dot{f_j}(\\vec{x_n} \\cdot \\vec{\\alpha_j}) x_{n0} & \\hdots & \\hdots & \\sqrt{w_n} \\dot{f_j}(\\vec{x_n} \\cdot \\vec{\\alpha_j}) x_{np}\n\\end{bmatrix}\n\\]\n\n$$= -\\sqrt{w_k} \\beta_{jk} (\\sqrt{\\vec{w_I}} \\odot \\dot{f_j}(\\pmb{X} \\cdot \\vec{\\alpha_j})) \\odot \\pmb{X}$$\n\nwhere everything left of the last $\\odot$ simplifies to an $n$-vector, so the Hadamard product is taken with each column of $\\pmb{X}$ individually.\\newline\n\nAs per Gauss-Newton, the update to the parameter $\\vec{\\alpha_j}$ to the function $\\vec{g_{jkw}}$ is given by the solution $\\vec{\\delta}$ to:\n\n$$\\left[ \\sum_{k=1}^d J_{jk}^T J_{jk} \\right] \\vec{\\delta} = \\sum_{k=1}^d J_{jk}^T \\vec{g_{jkw}}$$\n\nOn the left side is a $p \\times p$ matrix, and on the right a $p \\times 1$ vector, so we have an easy-to-solve linear inverse problem.\n\n$$ \\vec{\\alpha_j} = \\vec{\\alpha_j} + \\vec{\\delta} $$\n\nIn practice $\\vec{\\alpha_j}$ is renormalized after this update to avoid numerical drift and keep it from blowing up. Because $\\vec{\\alpha_j}$ is a projection vector only meant to flatten the data along some dimension, its magnitude does not really matter.\n\n\\subsection{Testing for Convergence}\n\nParameters are considered ``converged\" when their values across iterations cause a small-enough change in the value of the loss function.\n\nBecause we only make updates to the parameters governing stage $j$, we can make use the convenient identity\n\n$$\\pmb{Y} - \\pmb{\\hat{Y}} = \\pmb{R}_j - f_j(\\pmb{X} \\cdot \\vec{\\alpha_j}) \\otimes \\vec{\\beta_j}^T$$\n\nto calculate the loss quickly.\n\n\\section{Classification}\n\nLet the miscalssification risk $R$ be\n\n$$R = \\sum_{i=1}^n \\min_{k \\in [1,q]} \\sum_{c=1}^q l_{ck} p(c | \\vec{x_i})$$\n\nwhere\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $i$ iterates over examples\n\t\\item $q$ is the total number of classes in the problem\n\t\\item $\\min_k$ implements the optimal decision rule for each example\n\t\\item $l_{ck}$ is the user-specified loss for predicting $y=k$ when in truth $y=c$\n\t\\item the inner sum is the total loss for predicting $y=k$\n\t\\item $p(c | \\vec{x_i})$ is the true probability $y=c$ given input $\\vec{x_i}$\n\\end{itemize}\n\nThe unknown here is that conditional probability. If we define an indicator variable\n\n$$h_{ci} = 1\\ if\\ y_i=c,\\ 0\\ otherwise$$\n\nthen Friedman says we can rewrite the conditional probability as\n\n$$p(c | \\vec{x_i}) = \\frac{\\pi_c S}{s_c} E[h_{ci} | \\vec{x_i}]$$\n\nwhere\n\\begin{itemize}\n\t\\setlength\\itemsep{-2mm}\n\t\\item $\\pi_c$ is the prior probability that $y_i=c$ ($h_{ci}=1$), calculable from the training set with $\\frac{\\sum_{i=1}^n h_{ci}}{n}$\n\t\\item $s_c = \\sum_{i=1}^n w_i h_{ci}$, the cumulative weight of examples with classification $c$\n\t\\item $S = \\sum_{c=1}^q s_c$, the cumulative weight of everything, a constant\n\t\\item $E$ means the expected value\n\\end{itemize}\n\nThe coefficient can be expanded to\n\n$$\\frac{\\sum_{c=1}^q \\sum_{i=1}^n w_i h_{ci} * \\frac{\\sum_{i=1}^n h_{ci}}{n}}{\\sum_{i=1}^n w_i h_{ci}} \\propto \\frac{\\sum_{i=1}^n h_{ci}}{\\sum_{i=1}^n w_i h_{ci}}$$\n\nThis doesn't make any sense, because it says probabilities are \\textit{inversely} related to example weights, but we really want the probability of predicting a given class to be \\textit{directly} related to the importances of examples in that class. Convinced Friedman accidentally inverted the equation, the code and the following equations reinvert his inversion.\n\nNotice that if the weights $w_i$ in $s_c$ are uniform (so no example is considered any more important than any other), then $\\pi_c = s_c/S$, and all those terms cancel (regardless of the inversion).\n\nAdditionally, $l_{ck}$ is often simplified as\n\n$$l_{ck} = 1\\ if\\ c \\neq k,\\ 0\\ if\\ c=k$$\n\nSo rewrite the risk as\n\n$$R = \\sum_{i=1}^n \\min_{k \\in [1,q]} \\frac{1}{S} \\sum_{c=1}^q \\frac{s_c l_{ck}}{\\pi_c} E[h_{ci} | \\vec{x_i}]$$\n\nAnd with the simplifying assumptions that all examples are equally important and misclassification is equally bad between all class pairs it becomes:\n\n$$R = \\sum_{i=1}^n \\min_{k \\in [1,q]} \\sum_{c \\neq k} E[h_{ci} | \\vec{x_i}]$$\n\nOr equivalently:\n\n$$R = \\sum_{i=1}^n \\max_{k \\in [1,q]} E[h_{ci} | \\vec{x_i}]$$\n\nbecause the sum is minimized by excluding the largest expectation.\\newline\n\nNow, recognize $E[\\vec{h_c} | \\pmb{X}]$ is a vector of the values $E[h_{ci} | \\vec{x_i}]$, and for training data the expectation that $h_{ci}$ has a given value given $\\vec{x_i}$ is known to be either a one or a zero, so $E[\\vec{h_c} | \\pmb{X}] = \\vec{h_c}$, $h_{ci} \\forall i$ stacked together.\n\nFurther, recognize that stacking $\\vec{h_c}$ for all classes $c$ together as columns yields $\\pmb{H}$, a one-hot representation of the true classifications $\\pmb{Y}$. That is:\n\n\\[\n\\pmb{Y} =\n\\begin{bmatrix}\n1\\\\\n0\\\\\n2\\\\\n.\\\\\n.\\\\\n3\\\\\n\\end{bmatrix}\n%%%%%\n\\ \\ \\ \\ \\ \\ \\ \\pmb{H} =\n\\begin{bmatrix}\n0 & 1 & 0 & 0\\\\\n1 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0\\\\\n& \\hdots & \\hdots\\\\\n& \\hdots & \\hdots\\\\\n0 & 0 & 0 & 1\n\\end{bmatrix}\n\\]\n\nAnd now we can model $\\pmb{H}$ with a multivariate projection pursuit regression model, where we take the predicted class of example $i$ to be:\n\n$$\\hat{y_i} = \\argmax_c \\hat{h_{ci}} $$\n\nThat is: the predicted class is the index of the column where the largest value in the $i$\\textsuperscript{th} row of $\\hat{\\pmb{H}}$, the predicted $\\pmb{H}$, is located. If $\\pmb{Y}$ is filled with generalized categories rather than numbers, then categoricals can be assigned numbers for the construction of $\\pmb{H}$, and argmaxes can be translated back at prediction-time.\n\nAnd just like that we have reduced univariate classification to multivariate regression! There is one caveat: Training the model to make these predictions should ideally involve optimizing the the misclassification risk as the loss function, not the sum-of-squares loss function from section 2 as is done for actual regression. But the $\\max_k$ in the risk equation makes it nonconvex, which means we can no longer employ the methods detailed in section 3 to find model parameters.\n\nFortunately, Friedman assures us (and experiment bears out) that using the quatratic loss function is acceptable, and if we wish to account for examples being of differing importances or specify a funky non-uniform pairwise loss scheme, all we have to do is use weights:\n\n$$w_c = \\frac{s_c}{S \\pi_c} \\sum_{k \\in [1,q]} l_{ck}$$\n\nSince weights are relative, the constant $S$ and the normalization by the constant $n$ in the calculation of $\\pi_c$ can be dropped to yeild:\n\n$$w_c = \\frac{\\sum_{i=1}^n w_i h_{ci}}{\\sum_{i=1}^n h_{ci}} \\sum_{k \\in [1,q]} l_{ck}$$\n\nVectorizing to obtain this weight for all classes at once we get:\n\n$$\\vec{w_C} = \\frac{\\vec{w_I} \\cdot \\pmb{H}}{\\sum_{i=1}^n \\pmb{H}} \\odot \\sum_{k=1}^q \\pmb{L}$$\n\nwhere $\\pmb{L}[c,k] = l_{ck}$, the sum over $k$ amounts to a sum along the horizontal (second) axis, the sum over $n$ of $\\pmb{H}$ amounts to a sum along the vertical (first) axis, and the division is pointwise on the vectors involved.\n\n\\end{document}\n", "meta": {"hexsha": "c25501d74eb12864c7246806019912731565faee", "size": 22286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math.tex", "max_stars_repo_name": "pavelkomarov/projection-pursuit-regression", "max_stars_repo_head_hexsha": "d8d4d0a72a0ba7f64d240bc3b14129ccd9c7cf9e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2018-02-08T21:24:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:05:26.000Z", "max_issues_repo_path": "doc/math.tex", "max_issues_repo_name": "pavelkomarov/projection-pursuit-regression", "max_issues_repo_head_hexsha": "d8d4d0a72a0ba7f64d240bc3b14129ccd9c7cf9e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-20T00:22:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T19:59:57.000Z", "max_forks_repo_path": "doc/math.tex", "max_forks_repo_name": "pavelkomarov/projection-pursuit-regression", "max_forks_repo_head_hexsha": "d8d4d0a72a0ba7f64d240bc3b14129ccd9c7cf9e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-02-24T00:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T01:48:03.000Z", "avg_line_length": 59.5882352941, "max_line_length": 644, "alphanum_fraction": 0.7099973077, "num_tokens": 7091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6371376071713631}}
{"text": "\\chapter{Breaking the continuum hypothesis}\nWe now use the technique of forcing to break the\nContinuum Hypothesis by choosing a good poset $\\Po$.\nAs I mentioned earlier, one can also build a model\nwhere the Continuum Hypothesis is true;\nthis is called the \\emph{constructible universe},\n(this model is often called ``$V=L$'').\nHowever, I think it's more fun when things break\\dots\n\n%\\section{Forcing $V \\neq L$ is really easy}\n%As a small aside, to check we're on the right track we show the following result.\n%\n%\\begin{theorem}[$V \\ne L$]\n%\tLet $M$ be a countable transitive model of $\\ZFC$.\n%\tLet $\\Po \\in M$ be \\emph{any} splitting poset,\n%\tand let $G \\subseteq \\Po$ be $M$-generic.\n%\tThen $M[G] \\vDash (V \\neq L)$.\n%\\end{theorem}\n%\\begin{proof}\n%\tSince $L$ has a $\\Sigma_1$ definition,\n%\twe have \\[ L^{M[G]} = L^M \\subseteq M \\subsetneq M[G] \\]\n%\twhere the last part follows from $G \\notin M[G]$.\n%\\end{proof}\n%\n%Thus $M[G] \\vDash \\ZFC + (V \\ne L)$ for any splitting poset $\\Po$,\n%and we are one step closer to breaking $\\CH$.\n\n\\section{Adding in reals}\nStarting with a \\emph{countable} transitive model $M$.\n\nWe want to choose $\\Po \\in M$ such that $(\\aleph_2)^M$ many real numbers appear,\nand then worry about cardinal collapse later.\n\nRecall the earlier situation where we set $\\Po$ to be the infinite complete binary tree; its nodes can be thought of as partial functions $n \\to 2$ where $n < \\omega$.\nThen $G$ itself is a path down this tree; i.e.\\ it can be encoded as a total function $G : \\omega \\to 2$,\nand corresponds to a real number.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(8cm);\n\t\tpair P = Drawing(\"\\varnothing\", (0,4), dir(90), red);\n\t\tpair P0 = Drawing(\"0\", (-5,2), 1.5*dir(90), red);\n\t\tpair P1 = Drawing(\"1\", (5,2),  1.5*dir(90));\n\t\tpair P00 = Drawing(\"00\", (-7,0), 1.4*dir(120));\n\t\tpair P01 = Drawing(\"01\", (-3,0), 1.4*dir(60), red);\n\t\tpair P10 = Drawing(\"10\", (3,0),  1.4*dir(120));\n\t\tpair P11 = Drawing(\"11\", (7,0),  1.4*dir(60));\n\n\t\tpair P000 = Drawing(\"000\", (-8,-3));\n\t\tpair P001 = Drawing(\"001\", (-6,-3));\n\t\tpair P010 = Drawing(\"010\", (-4,-3), red);\n\t\tpair P011 = Drawing(\"011\", (-2,-3));\n\n\t\tpair P100 = Drawing(\"100\", (2,-3));\n\t\tpair P101 = Drawing(\"101\", (4,-3));\n\t\tpair P110 = Drawing(\"110\", (6,-3));\n\t\tpair P111 = Drawing(\"111\", (8,-3));\n\n\t\tdraw(P01--P0--P00);\n\t\tdraw(P11--P1--P10);\n\t\tdraw(P0--P--P1);\n\t\tdraw(P000--P00--P001);\n\t\tdraw(P100--P10--P101);\n\t\tdraw(P010--P01--P011);\n\t\tdraw(P110--P11--P111);\n\n\t\tdraw(P--P0--P01--P010--(P010+2*dir(-90)), red+1.4);\n\t\tMP(\"G\", P010+2*dir(-90), dir(-90), red);\n\t\\end{asy}\n\\end{center}\n\nWe want to do something similar,\nbut with $\\omega_2$ many real numbers instead of just one.\nIn light of this, consider in $M$ the poset\n\\[\n\t\\Po = \\opname{Add} \\left( \\omega_2, \\omega \\right)\n\t\\defeq \\left( \\left\\{ p : \\omega_2 \\times \\omega \\to 2,\n\t\t\\dom(p) \\text{ is finite} \\right\\},\n\t\\supseteq \\right).\n\\]\nThese elements $p$ (conditions) are ``partial functions'':\nwe take some finite subset of $\\omega_2 \\times \\omega$ and map it into $2=\\{0,1\\}$.\n(Here $\\dom(p)$ denotes the domain of $p$,\nwhich is the finite subset of $\\omega_2 \\times \\omega$ mentioned.)\nMoreover, we say $p \\le q$ if $\\dom(p) \\supseteq \\dom(q)$\nand the two functions agree over $\\dom(q)$.\n\n\\begin{ques}\n\tWhat is the maximal element $1_\\Po$ here?\n\\end{ques}\n\n\\begin{exercise}\n\tShow that a generic $G$ can be encoded as a function $\\omega_2 \\times \\omega \\to 2$.\n\\end{exercise}\n\n%Let $G \\subseteq \\opname{Add}(\\omega_2, \\omega)$ be an $M$-generic.\n%We claim that, like in the binary case, $G$ can be encoded as a function $\\omega_2 \\times \\omega \\to 2$.\n%To see this, consider $\\alpha \\in \\omega_2$ and $n \\in \\omega$; we have the dense set\n%\\[ D_{\\alpha, n}\n%\t= \\left\\{ p \\in \\opname{Add}(\\omega_2, \\omega)\n%\t\\mid (\\alpha, n) \\in \\dom(p) \\right\\}\n%\\]\n%(this is obviously dense, given any $p$ add in $(\\alpha, n)$ if it's not in there already).\n%So $G$ hits this dense set, meaning that for every $(\\alpha, n)$ there's a function in $G$ which defines it.\n%Using the fact that $G$ is upwards closed and a filter, we may as before we may interpret $G$ as a function $\\omega_2 \\times \\omega \\to 2$.\n\n\\begin{lemma}[$G$ encodes distinct real numbers]\n\tFor $\\alpha \\in \\omega_2$ define\n\t\\[ G_\\alpha = \\left\\{ n \\mid G\\left( \\alpha,n \\right) = 0 \\right\\} \\in \\PP(\\NN). \\]\n\tThen $G_\\alpha \\neq G_\\beta$ for any $\\alpha \\neq \\beta$.\n\\end{lemma}\n\\begin{proof}\n\tWe claim that the set\n\t\\[ D = \\left\\{ q \\mid \\exists n \\in \\omega :\n\t\tq\\left( \\alpha, n \\right) \\neq q\\left( \\beta, n \\right)\n\t\t\\text{ are both defined}\n\t\\right\\} \\]\n\tis dense.\n\t\\begin{ques}\n\t\tCheck this.\n\t\t(Use the fact that the domains are all finite.)\n\t\\end{ques}\n%\tThis is pretty easy to see.\n%\tConsider $p \\in \\opname{Add}(\\omega_2, \\omega)$.\n%\tThen you can find an $n$ such that\n%\tneither $(\\alpha, n)$ nor $(\\beta, n)$ is defined,\n%\tjust because $\\dom(p)$ is finite.\n%\tThen you make $p'$ as $p$ plus $p'( (\\alpha, n) ) = 1$\n%\tand $p'( (\\beta, n) ) = 0$.\n%\tHence the set is dense.\n\n\tSince $G$ is an $M$-generic it hits this dense set $D$.\n\tHence $G_\\alpha \\neq G_\\beta$.\n\\end{proof}\n\nSince $G \\in M[G]$ and $M[G] \\vDash \\ZFC$,\nit follows that each $G_\\alpha$ is in $M[G]$.\nSo there are at least $\\aleph_2^M$ real numbers in $M[G]$.\nWe are done once we can show there is no cardinal collapse.\n\n\\section{The countable chain condition}\nIt remains to show that with $\\Po = \\opname{Add}(\\omega, \\omega_2)$, we have that\n\\[ \\aleph_2^{M[G]} = \\aleph_2^M. \\]\nIn that case, since $M[G]$ will have $\\aleph_2^M = \\aleph_2^{M[G]}$ many reals, we will be done.\n\nTo do this, we'll rely on a combinatorial property of $\\Po$:\n\\begin{definition}\n\tWe say that $A \\subseteq \\mathcal P$ is a \\vocab{strong antichain}\n\tif for any distinct $p$ and $q$ in $A$, we have $p \\perp q$.\n\\end{definition}\n\\begin{example}[Example of an antichain]\n\tIn the infinite binary tree, \n\tthe set $A = \\{00, 01, 10, 11\\}$ is a strong antichain\n\t(in fact maximal by inclusion).\n\\end{example}\nThis is stronger than the notion of ``antichain'' than you might be used to!\\footnote{%\n\tIn the context of forcing, some authors use ``antichain'' to refer to ``strong antichain''.\n\tI think this is lame.}\nWe don't merely require that every two elements are incomparable,\nbut that they are in fact \\emph{incompatible}.\n\\begin{ques}\n\tDraw a finite poset and an antichain of it which is not strong.\n\\end{ques}\n\n\\begin{definition}\n\tA poset $\\Po$ has the \\vocab{$\\kappa$-chain condition}\n\t(where $\\kappa$ is a cardinal) if all strong antichains\n\tin $\\Po$ have size less than $\\kappa$.\n\tThe special case $\\kappa = \\aleph_1$ is called the \\vocab{countable chain condition},\n\tbecause it implies that every strong antichain is countable.\n\\end{definition}\n\nWe are going to show that if the poset has the $\\kappa$-chain condition\nthen it preserves all cardinals greater than $\\kappa$.\n% or was it > \\kappa?\nIn particular, the countable chain condition will show that $\\Po$ preserves all the cardinals.\nThen, we'll show that $\\opname{Add}(\\omega, \\omega_2)$ does indeed have this property.\nThis will complete the proof.\n\nWe isolate a useful lemma:\n\\begin{lemma}[Possible values argument]\n\tSuppose $M$ is a transitive model of $\\ZFC$ and $\\Po$ is a partial order\n\tsuch that $\\Po$ has the $\\kappa$-chain condition in $M$.\n\tLet $X,Y \\in M$ and let $f: X \\to Y$\n\tbe some function in $M[G]$, but $f \\notin M$.\n\n\tThen there exists a function $F \\in M$, with $F: X \\to \\PP(Y)$ and such that\n\tfor any $x \\in X$,\n\t\\[ f(x) \\in F(x) \\quad\\text{and}\\quad \\left\\lvert F(x) \\right\\rvert^M < \\kappa. \\]\n\\end{lemma}\nWhat this is saying is that if $f$ is some new function that's generated,\n$M$ is still able to pin down the values of $f$ to at most $\\kappa$ many values.\n\n\\begin{proof}\n\tThe idea behind the proof is easy: any possible value of $f$ gives us some condition in\n\tthe poset $\\Po$ which forces it.\n\tSince distinct values must have incompatible conditions,\n\tthe $\\kappa$-chain condition guarantees\n\tthere are at most $\\kappa$ such values.\n\n\tHere are the details.\n\tLet $\\dot f$, $\\check X$, $\\check Y$ be names for $f$, $X$, $Y$.\n\tStart with a condition $p$ such that $p$ forces the sentence\n\t\\[ \\text{``$\\dot f$ is a function from $\\check X$ to $\\check Y$''}. \\]\n\tWe'll work just below here.\n\n\tFor each $x \\in X$, we can consider (using the Axiom of Choice) a maximal strong antichain $A(x)$\n\tof incompatible conditions $q \\le p$ which forces $f(x)$ to equal some value $y \\in Y$.\n\tThen, we let $F(x)$ collect all the resulting $y$-values.\n\tThese are all possible values, and there are less than $\\kappa$ of them.\n\\end{proof}\n\n\\section{Preserving cardinals}\nAs we saw earlier, cardinal collapse can still occur.\nFor the Continuum Hypothesis we want to avoid this possibility,\nso we can add in $\\aleph_2^M$ many real numbers and have $\\aleph_2^{M[G]} = \\aleph_2^M$.\nIt turns out that to verify this, one can check a weaker result.\n\n\\begin{definition}\n\tFor $M$ a transitive model of $\\ZFC$ and $\\Po \\in M$ a poset,\n\twe say $\\Po$ \\vocab{preserves cardinals} if\n\t$\\forall G \\subseteq \\Po$ an $M$-generic,\n\tthe model $M$ and $M[G]$ agree on the sentence ``$\\kappa$ is a cardinal'' for every $\\kappa$.\n\tSimilarly we say $\\Po$ \\vocab{preserves regular cardinals} if $M$ and $M[G]$\n\tagree on the sentence ``$\\kappa$ is a regular cardinal'' for every $\\kappa$.\n\\end{definition}\nIntuition:\nIn a model $M$, it's possible that two ordinals which are in bijection in $V$ are no longer in bijection in $M$.\nSimilarly, it might be the case that some cardinal $\\kappa \\in M$ is regular,\nbut stops being regular in $V$ because some function $f : \\ol\\kappa \\to \\kappa$ is cofinal but happened to only exist in $V$.\nIn still other words, ``$\\kappa$ is a regular cardinal '' turns out to be a $\\Pi_1$ statement too.\n\nFortunately, each implies the other.\nWe quote the following without proof.\n\\begin{proposition}[Preserving cardinals $\\iff$ preserving regular cardinals]\n\tLet $M$ be a transitive model of $\\ZFC$.\n\tLet $\\Po \\in M$ be a poset.\n\tThen for any $\\lambda$,\n\t\t$\\Po$ preserves cardinalities less than or equal to $\\lambda$\n\t\tif and only if $\\Po$ preserves regular cardinals less than or equal to $\\lambda$.\n\tMoreover the same holds if we replace ``less than or equal to''\n\tby ``greater than or equal to''.\n\\end{proposition}\n\nThus, to show that $\\Po$ preserves cardinality and cofinalities\nit suffices to show that $\\Po$ preserves regularity.\nThe following theorem lets us do this:\n\\begin{theorem}[Chain conditions preserve regular cardinals]\n\tLet $M$ be a transitive model of ZFC, and let $\\Po \\in M$ be a poset.\n\tSuppose $M$ satisfies the sentence ``$\\Po$ has the $\\kappa$ chain condition and $\\kappa$ is regular''.\n\tThen $\\Po$ preserves regularity greater than or equal to $\\kappa$.\n\\end{theorem}\n\\begin{proof}\n\tUse the Possible Values Argument.\n\t\\Cref{prob:chain}.\n\\end{proof}\n\nIn particular, if $\\Po$ has the countable chain condition then $\\Po$ preserves \\emph{all} the cardinals (and cofinalities).\nTherefore, it remains to show that $\\opname{Add}(\\omega, \\omega_2)$ satisfies the countable chain condition.\n\n\\section{Infinite combinatorics}\nWe now prove that $\\opname{Add}(\\omega, \\omega_2)$ satisfies the countable chain condition.\nThis is purely combinatorial, and so we work briefly.\n\n\\begin{definition}\n\tSuppose $C$ is an uncountable collection of finite sets.\n\t$C$ is a \\vocab{$\\Delta$-system} if there exists a \\vocab{root} $R$\n\twith the condition that for any distinct $X$ and $Y$\n\tin $C$, we have $X \\cap Y = R$.\n\\end{definition}\n\n\\begin{lemma}\n\t[$\\Delta$-System lemma] Suppose $C$ is an uncountable collection of finite sets.\n\tThen $\\exists \\ol C \\subseteq C$ such that $\\ol C$ is an uncountable $\\Delta$-system.\n\\end{lemma}\n\\begin{proof}\n\tThere exists an integer $n$ such that $C$ has uncountably many guys of length $n$.\n\tSo we can throw away all the other sets, and just assume that all sets in $C$ have size $n$.\n\n\tWe now proceed by induction on $n$.\n\tThe base case $n=1$ is trivial, since we can just take $R = \\varnothing$.\n\tFor the inductive step we consider two cases.\n\n\tFirst, assume there exists an $a \\in C$ contained in uncountably many $F \\in C$.\n\tThrow away all the other guys.\n\tThen we can just delete $a$, and apply the inductive hypothesis.\n\n\tNow assume that for every $a$, only countably many members of $C$ have $a$ in them.\n\tWe claim we can even get a $\\ol C$ with $R = \\varnothing$.\n\tFirst, pick $F_0 \\in C$.\n\tIt's straightforward to construct an $F_1$ such that $F_1 \\cap F_0 = \\varnothing$.\n\tAnd we can just construct $F_2, F_3, \\dots$\n\\end{proof}\n\n\\begin{lemma}\n\tFor all $\\kappa$, $\\opname{Add}(\\omega, \\kappa)$ satisfies the countable chain condition.\n\\end{lemma}\n\\begin{proof}\n\tAssume not. Let\n\t\\[ \\left\\{ p_\\alpha : \\alpha < \\omega_1 \\right\\} \\]\n\tbe a strong antichain.  Let\n\t\\[ C = \\left\\{ \\dom(p_\\alpha) : \\alpha < \\omega_1 \\right\\}. \\]\n\tLet $\\ol C \\subseteq C$ be such that $\\ol C$ is uncountable, and $\\ol C$ is a $\\Delta$-system with root $R$.\n\tThen let\n\t\\[ B = \\left\\{ p_\\alpha : \\dom(p_\\alpha) \\in R \\right\\}. \\]\n\tEach $p_\\alpha \\in B$ is a function $p_\\alpha : R \\to \\{0,1\\}$,\n\tso there are two that are the same.\n\\end{proof}\n\nThus, we have proven that the Continuum Hypothesis cannot be proven in $\\ZFC$.\n\n\\section\\problemhead\n\\begin{problem}\n\t\\label{prob:chain}\n\tLet $M$ be a transitive model of ZFC, and let $\\Po \\in M$ be a poset.\n\tSuppose $M$ satisfies the sentence ``$\\Po$ has the $\\kappa$ chain condition and $\\kappa$ is regular''.\n\tShow that $\\Po$ preserves regularity greater than or equal to $\\kappa$.\n\t\\begin{hint}\n\t\tAssume not, and take $\\lambda > \\kappa$ regular in $M$;\n\t\tif $f : \\ol \\lambda \\to \\lambda$,\n\t\tuse the Possible Values Argument on $f$ to generate a function in $M$\n\t\tthat breaks cofinality of $\\lambda$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIt suffices to show that $\\Po$ preserves regularity greater than or equal to $\\kappa$.\n\t\tConsider $\\lambda > \\kappa$ which is regular in $M$,\n\t\tand suppose for contradiction that $\\lambda$ is not regular in $M[G]$.\n\t\tThat's the same as saying that there is a function $f \\in M[G]$,\n\t\t$f : \\ol \\lambda \\to \\lambda$ cofinal, with $\\ol \\lambda < \\lambda$.\n\t\tThen by the Possible Values Argument,\n\t\tthere exists a function $F \\in M$ from $\\ol \\lambda \\to \\PP(\\lambda)$\n\t\tsuch that $f(\\alpha) \\in F(\\alpha)$ and $\\left\\lvert F(\\alpha) \\right\\rvert^M < \\kappa$\n\t\tfor every $\\alpha$.\n\n\t\tNow we work in $M$ again.\n\t\tNote for each $\\alpha \\in \\ol\\lambda$,\n\t\t$F(\\alpha)$ is bounded in $\\lambda$ since $\\lambda$ is regular in $M$ and\n\t\tgreater than $\\left\\lvert F(\\alpha) \\right\\rvert$.\n\t\tNow look at the function $\\ol \\lambda \\to \\lambda$ in $M$ by just\n\t\t\\[ \\alpha \\mapsto \\cup F(\\alpha) < \\lambda. \\]\n\t\tThis is cofinal in $M$, contradiction.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "bf270ad51cc206776403049efa7da959eff43952", "size": 14670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/set-theory/CH.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/set-theory/CH.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/set-theory/CH.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": 42.6453488372, "max_line_length": 167, "alphanum_fraction": 0.678868439, "num_tokens": 4781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6371361886829685}}
{"text": "%\n%  Teori.tex\n%  Part of VertEgg documentation\n%\n\n\\chapter{Theory of Vertical Egg Distributions}\n\n\\section{The Equations}\\label{sec:equations}\n\n\nNeglecting horizontal processes, the evolution of the vertical\ndistribution\nof a class of fish eggs is governed by a simple \\emph{conservation}\nprinciple\\index{conservation principle}\n\n\\begin{equation}\\label{eq:consprin}\n\\begin{split}\n  \\text{The change}\\ & \\text{in the number of eggs between two depth levels} \\\\\n  & = \\text{the number of eggs entering at the lower level} \\\\\n  & - \\text{the number of eggs leaving at the upper level} \\\\\n  & + \\text{the number of eggs spawned} \\\\\n  & - \\text{the number of eggs that hatched or died}\n\\end{split}\n\\end{equation}\n\nTo put this in a more mathematical formulation, let the variable\n$z$ denote depth and $t$ time. The $z$-axis is chosen to point\n\\emph{up}, that is $z = 0$ at the surface and negative values are\nused in the water column. This choice is opposite from\n\\cite{sund83,sund91} and \\cite{west89}. The present choice is\nmotivated by the most\ncommon axis-convention in 3D hydrodynamic ocean modelling.\n\nTo make the theory more convenient mathematically, a\n\\emphi{continuum} approach is used, where the eggs are\nreplaced by a continuous egg \\emphi{concentration}.  Let $\\phi =\n\\phi(z,t)$ denote this egg concentration at depth $z$ and time\n$t$. Let $F = F(z,t)$ be the upwards egg \\emphi{flux}, i.e.\\ the net\nnumber of eggs passing upwards per time unit at depth $z$ and time\n$t$. Similarly, let $Q = Q(z,t)$ denote the \\emphi{source term}, the\nnumber of eggs spawned minus the numbers that hatched or died per\ndepth and time unit at depth $z$ and time $t$.  The source term can\nalso be used to take care of other processes, such as loss of eggs by\nhorizontal advection.\n\nThe conservation principle \\ref{eq:consprin} can then be formulated\nin \\emphi{integral form}\n\\begin{equation}\\label{eq:intlaw}\n\\int_{z_1}^{z_2} \\!\\phi(z,t_2)\\,dz - \\int_{z_1}^{z_2}\\!\\phi(z,t_1)\\,dz\n   = \\int_{t_1}^{t_2} \\!F(z_1,t)\\,dt\n   - \\int_{t_1}^{t_2} \\!F(z_2,t)\\,dt\n   + \\int_{t_1}^{t_2}\\!\\int_{z_1}^{z_2} \\!Q(z,t)\\,dzdt\n\\end{equation}\nMathematically this can be reformulated in mixed form, differential in time\nand integral in space\n\\begin{equation}\\label{eq:diffintlaw}\n  \\pddt \\left( \\int_{z_1}^{z_2} \\!\\phi(z,t)\\,dz \\right) =\n  F({z_1},t) - F({z_2},t) + \\int_{z_1}^{z_2}\\!Q(z,t)\\,dz\n  \\quad \\mbox{for} \\ -H \\le {z_1} < {z_2} \\le 0 .\n\\end{equation}\nor in pure \\emph{differential} form\\index{differential form}\n\\begin{equation}\\label{eq:difflaw}\n  \\Pd{\\phi}{t} =  - \\Pd{F}{z} + Q\n\\end{equation}\n\nThe flux is decomposed in two parts, the \\emphi{convective flux} and the\n\\emphi{diffusive flux}.  The convection is due to the terminal buoyant\nvelocity $w = w(z,t)$ of the egg which is computed by the density\ndifference from the surroundings  and the egg size as described in section\n\\ref{sec:velocity}. The formulation is simply,\n\\begin{equation}\\label{eq:convflux}\n  \\Fconv = w \\phi .\n\\end{equation}\nThe diffusion is caused by turbulent mixing and is modelled by\nFick's law\\index{Fick's law} using the vertical eddy diffusion\n\\index{eddy diffusion} $K = K(z,t)$,\n\\begin{equation}\\label{eq:fick}\n  \\Fdiff = - K \\frac{\\partial \\phi}{\\partial z} .\n\\end{equation}\n\nOften the source term $Q$ can be separated in a\n\\emph{spawning}\\index{spawning term} or \\emph{production}\nterm\\index{production term} independent of the egg concentration\n\\begin{equation}\\label{eq:spawn}\n  \\Qspawn = P\n\\end{equation}\nand a \\emph{mortality}\\index{mortality term} or \\emph{loss}\nterm\\index{loss term} depending on the concentration\n\\begin{equation}\\label{eq:loss}\n  \\Qloss = - \\alpha \\phi\n\\end{equation}\nUsing this the differential conservation law (\\ref{eq:difflaw})\nbecomes\n\\bel{eq:difflawfull}\n\\Pd{\\phi}{t} =  - \\pddz (w \\phi) + \\pddz (K \\Pd{\\phi}{z}) + P - \\alpha \\phi\n\\end{equation}\nThis parabolic partial differential equations is\ncalled the \\emph{convection-diffusion}\\index{convection-diffusion equation}\nor \\emph{transport} equation\\index{transport equation}.\n\nThe boundary conditions\\index{boundary conditions} are simply no flux\nacross the surface and bottom,\n\\bel{eq:boundcond}\n  F(0,t) = F(-H,t) = 0,\n\\end{equation}\nand the initial condition is given by\n\\bel{eq:initcond}\n  \\phi(z,0) = \\phi_0(z),  \\quad -H \\le z \\le 0.\n\\end{equation}\n\n\\section{Solutions of the equations}\n\nUnder simplified circumstances the equations in section~\\ref{sec:equations}\ncan be solved analytically. This section examines some of these solutions.\n\n\\subsection{Vertical integrated equation}\\label{sec:vertint}\n\nLet $\\Phi$ denote the total concentration, $\\Phi = \\Vint \\phi dz$.\nTake the vertical integral of equation~(\\ref{eq:difflawfull}) and\nuse the boundary conditions (\\ref{eq:boundcond}) gives\n\\be\n\\Od{\\Phi}{t} = P^{tot} - \\Vint \\!\\alpha \\phi \\, dz\n\\end{equation}\nwhere $P^{tot} = \\Vint P dz$ is the total spawning contribution.\nWithout any source terms the total concentration $\\Phi$ is constant.\nTo reach a steady state solution with spawning, the loss term $\\alpha$\nmust be nonzero.\n\n\nIf $\\alpha$ is a positive\nconstant, the solution to the equation above is\n\\be\n  \\Phi(t) = \\e^{-\\alpha t} \\Phi(0)\n         + (1 - \\e^{-\\alpha t})  \\frac{P^{tot}}{\\alpha}\n\\end{equation}\nwith steady state solution $\\Phi = P^{tot}/\\alpha$.\nIf $\\alpha = 0$ the solution is simply\n\\be\n  \\Phi(t) = \\Phi(0) + t P^{tot} .\n\\end{equation}\n\n\n\\subsection{Stationary solution}\\index{stationary solution}\n\nA stationary solution solves the conservation law\n\\pref{eq:difflaw} without the time derivative\n\\begin{equation}\\label{eq:stateq}\n  \\Od{F}{z} = Q\n\\end{equation}\nwith boundary conditions $F(0) = F(-H) = 0$ given by \\pref{eq:boundcond}.\nThe condition for the existence of this solution is that the total\nsource term vanishes,\n\\begin{equation}\n  Q^{tot} = \\Vint \\!Q \\, dz= 0\n\\end{equation}\nthe flux function is then given by integrating \\pref{eq:stateq}\n\\begin{equation}\n  F(z) = \\int_{-H}^z \\! Q(s) \\, ds = - \\int_z^0 \\! Q(s) \\, ds .\n\\end{equation}\n\nWithout source term the expression above reduces to $F = 0$, i.e.\\ the\nnet flux is zero everywhere. This simply says that in a steady state\nconvection is balanced by diffusion\n\\bel{eq:sstate}\n  w \\phi - K \\Pd{\\phi}{z} = 0 .\n\\end{equation}\nThis is an ordinary differential equation for $\\phi(z)$.\nThe boundary conditions \\pref{eq:boundcond} does not contain more information.\nA unique solution can nevertheless be singled out by the\nintegral condition\n\\begin{equation}\\label{eq:intcond}\n  \\Vint \\!\\phi(z)\\,dz = \\Phi .\n\\end{equation}\nIn other words, among all the solutions of (\\ref{eq:sstate})\nchoose the one with correct vertically integrated concentration.\n\nTo simplify the notation put $m = w / K$ and let $M(z) = - \\int_z^0 m(s)\nds$. Then the stationary solution is\n\\begin{equation}\\label{eq:sstatesol}\n  \\phi(z) = \\frac{\\Phi}{\\int_{-H}^0 \\e^{M(s)} ds} \\e^{M(z)} .\n\\end{equation}\n\n\\subsubsection{Constant coefficients}\n\nThe case with constant coefficients was studied by Sundby\n\\shortcite{sund83}.  In this case $M(z) = m z$ and the solution is a\ntruncated exponential distribution,\n\\begin{equation}\\label{eq:eggsact}\n  \\phi_m(z) = \\Phi \\frac{m}{1 - \\e^{-mH}} \\e^{mz} .\n\\end{equation}\nIn the toolbox, this solution is computed by the function \\edbi{eggsact}.\nThis solution has the following symmetry between ascending and\ndescending velocity,\n\\begin{equation}\\label{eq:symmetry}\n  \\phi_{-m}(z) = \\phi_m(-H-z)\n\\end{equation}\n\nWith large depth and/or high ascending velocity  the\neffect of the bottom may be neglected. In this case the distribution\nis well approximated by an exponential distribution \\index{exponential\ndistribution} with parameter $\\lambda = 1 / m$, that is\n\\begin{equation}\n  \\phi_m(z) \\approx \\Phi m \\e^{mz}, \\quad \\text{for $mH \\gg 1$} .\n\\end{equation}\n\n\nFor positive values of $m$ the following series development from\n\\citep{sund83} is valid\n\\begin{equation}\n  \\phi_m(z) = \\Phi m \\e^{mz} \\sum_{j = 0}^{\\infty} \\e^{-jmH}, \\quad m > 0 .\n\\end{equation}\nThe zero-th term of this expansion is the exponential distribution above.\nFor negative values of $m$ the symmetry relation (\\ref{eq:symmetry})\ncan be used,\n\\begin{equation}\n  \\phi_m(z) = - \\Phi m \\e^{mz} \\sum_{j = 1}^{\\infty} \\e^{jmH}, \\quad m < 0 .\n\\end{equation}\n\nTo compute the mean and variance of the distribution the constant\nfactor $\\Phi$ can be dropped. The moment generating function is then\n\\begin{equation}\\label{eq:momgen}\n  \\psi(t) = \\int_{-H}^0 \\frac{m}{1 - \\e^{-mH}} \\e^{(m+t)z} dz\n          = \\frac{m}{1 - \\e^{-mH}} \\frac{1 - \\e^{-(m+t)H}}{m+t}.\n\\end{equation}\nDifferentiating $\\psi$ gives the moments of the distribution.\nThe mean depth is given by\n\\begin{equation}\\label{eq:eggsactmean}\n  \\mu = \\psi'(0) = - \\frac{1}{m} + \\frac{H}{\\e^{mH} - 1}\n\\end{equation}\nThe function $\\mu = \\mu(m)$ with $H = 100\\m$ is plotted in\nfigure~\\ref{fig:mdepth}.  The variance is\n\\begin{equation}\\label{eq:eggsactvar}\n       \\psi''(0) - \\mu^2\n      = \\frac{2 - \\e^{-mH}(m^2 H^2 + 2 m H + 2)}{m^2 ( 1 - \\e^{-mH})} - \\mu^2\n\\end{equation}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[height=6cm]{mdepth}\n\\end{center}\n\\caption{Mean depth $\\mu$ as a function of $m$}\\label{fig:mdepth}\n\\end{figure}\n\n\\subsubsection{Piecewise constant coefficients}\n\nThe solution (\\ref{eq:eggsact}) can easily be extended to a piecewise\nconstant $m$.\nLet $0 = z_0 > \\cdots > z_m = -H$ be a partition of the water column\nwith $m(z) = m_i$ on the interval $I_i = (z_i, z_{i-1})$.\nThen the stationary solution restricted to the interval $I_i$ is\ngiven as\n\\begin{equation}\\label{eq:pwconst}\n  \\phi(z) = C_i \\e^{m_i z}, \\quad \\mbox{for} \\ z_i < z < z_{i-1}\n\\end{equation}\nThe $C_i$-s are determined by continuity\nof the solution\n\\begin{equation}\n  C_i \\e^{m_i z_i} = C_{i+1} \\e^{m_{i+1} z_i}, \\quad  i = 1, \\ldots, m-1\n\\end{equation}\nand the integral condition~(\\ref{eq:intcond})\n\\begin{equation}\n   \\sum_{i = 1}^m C_i \\int_{z_i}^{z_{i-1}} \\e^{m_i z} dz\n   = \\sum_{i = 1}^m C_i \\frac{\\e^{m_i z_{i-1}} - \\e^{m_i z_i}}{m_i}\n   = \\Phi .\n\\end{equation}\nThis method is used in the function \\edbi{sstate} to approximate the\ngeneral steady state solution. More details of the implementation is\ngiven in section~\\ref{sec:statprob}.\n\n\n\\subsubsection{Linear coefficients}\n\nIn Sundby \\shortcite{sund91} the solution is derived for $m$ linear.\nLet $m$ be given as $m(z) = a (z-z_0)$. Then $M(z) =\n\\half a ((z - z_0)^2 - z_0^2)$. Taking the last term into the\nconstant $C$, the solution becomes\n\\begin{equation}\n  \\phi(z) = C \\e^{\\half a (z - z_0)^2} .\n\\end{equation}\nBathypelagic eggs are neutral buoyant at $z = z_0$, raising if deeper\nand sinking if higher in the water column. In this case the coefficient\n$a$ is negative and the concentration has a normal distribution about $z =\nz_0$ with variance $\\sigma^2 = {1 / |a|}$.\n\n%In a sample of eggs the diameters and buoyancies differ from egg to egg.\n%A more realistic model of the stationary situation will therefore be to\n%use a distribution of the $m$-values. This task was studied by Sundby (1983).\n%...\n\n\n\\subsubsection{Stationary solution with source terms}\n\nWith source terms, the steady state equation is\n\\begin{equation}\\label{eq:srcsstate}\n  0 = - \\pddz (w \\phi) + \\pddz (K \\Pd{\\phi}{z}) + P - \\alpha \\phi .\n\\end{equation}\nThis is a general second order ordinary\ndifferential equation. With constant coefficients the equation becomes\n\\begin{equation}\\label{eq:srcsacteq}\n  K \\phi'' - w \\phi' - \\alpha \\phi = - P\n\\end{equation}\nand the no flux boundary conditions are\n\\begin{equation}\n  K \\phi' - w \\phi, \\quad z = 0, z = -H .\n\\end{equation}\nThe solution can be written\n\\bel{eq:srssact}\n  \\phi(z) = A \\e^{az} - B \\e^{-bz} + \\frac{P}{\\alpha}\n\\end{equation}\nwith\n\\begin{align}\n  a & = \\frac{1}{2K} ( \\sqrt{w^2 + 4 \\alpha K} + w ) \\\\\n  b & = \\frac{1}{2K} ( \\sqrt{w^2 + 4 \\alpha K} - w ) \\\\\n  A & = \\frac{w P}{\\alpha b K} \\frac{1-\\e^{-b H}}{1-\\e^{-(a+b)H}} \\\\\n  B & = \\frac{w P}{\\alpha a K} \\e^{-b H} \\frac{1-\\e^{-a H}}{1-\\e^{-(a+b)H}} .\n\\end{align}\n\nThis function is computed in the toolbox by the function \\edbi{srcsact}.\nThe signs are chosen such that positive velocity $w$ makes all terms\npositive. For negative velocities a symmetry property\nsimilar to equation~(\\ref{eq:symmetry})\ncan be used, if\n$\\phi(z)$ is a solution to equation (\\ref{eq:srcsacteq}) and boundary\nconditions (\\ref{eq:boundcond}) then $\\phi(-H-z)$ is a solution the\nsame equation and boundary conditions with the opposite sign on $w$.\nIn other words,\n\\begin{equation}\n  \\phi_{-w}(z) = \\phi_w(-H-z) .\n\\end{equation}\n\n\n\\section{The Terminal Egg Velocity}\\label{sec:velocity}\n\\index{egg velocity}\\index{terminal velocity}\n\nAn egg in sea water will reach its terminal velocity $w$, where the\nbuoyant forcing balances the frictional drag. This velocity is a\nfunction of the difference $\\Delta \\rho = \\rho - \\rho_e$ between the\ndensity of the water and the egg, the egg diameter $d$, the\nacceleration $g$ due to gravity and the molecular\nviscosity\\index{molecular viscosity}. Here the \\emph{dynamic}\nmolecular viscosity\\index{dynamic viscosity} $\\mu$ is used.\n\nThe situation is characterised by the non-dimensional \\emphi{Reynolds\nnumber},\n\\begin{equation}\n  Re = \\frac{\\rho d w}{\\mu}\n\\end{equation}\nFor low values, $Re < 0.5$, the terminal velocity is given by\n\\emphi{Stokes' formula}\n\\begin{equation}\\label{eq:stokes}\n  w = \\frac{1}{18} \\frac{g d^2 \\Delta \\rho}{\\mu} .\n\\end{equation}\nThis formula was obtained by Stokes \\shortcite{stok1851}. The\nderivation of the formula is given in almost any textbook on\nfluid dynamics, for instance \\citep{yih77}.\n\n\nCombining these equations, one obtains an expression for $D$, the maximum\ndiameter for which Stokes' velocity applies,\n\\begin{equation}\n  D^3 = \\frac{9 \\mu^2}{\\rho g \\Delta \\rho}\n\\end{equation}\n\n\nIn the intermediate region $0.5 < Re < 5$, Dallavalle (1948) gave an\nempirical formula\\index{Dallavalle's formula}\n\\begin{equation}\\label{eq:dallavalle}\n  w = K_I (d - \\zeta D) \\Delta \\rho^{2/3} \\mu^{-1/3}\n\\end{equation}\nwhere $\\zeta = 0.4$ for a sphere. The coefficient $K_I$ is determined\nby the requirement that both formulas should give the same answer for\n$Re = 0.5$ or equivalently $d = D$.\nThis gives\n\\begin{equation}\n  K_I = \\frac{5}{54} 9^{1/3} g^{2/3} \\rho^{-1/3}\n         = 0.0875 \\text{kg}^{-1/3} \\,\n             \\text{m}^{5/3} \\text{s}^{-4/3} .\n\\end{equation}\n\nThe formulas above are implemented as the function \\edbi{eggvel} in\nthe VertEgg toolbox. The buoyancy of a fish egg is often given as the\nsalinity $S_e$ where the egg is neutrally buoyant. The function\n\\edbi{eggvelst} computes the terminal velocity in this case.\n\n\nTo compute the egg velocity the density, $\\rho$ of water is needed.\nIn the toolbox only density at surface pressure is presently\navailable.  This is computed by the function \\edbi{dens0} by the\nUNESCO formula \\citep{UNES81}.  The function \\edbi{sw\\_dens} in the\nSEAWATER toolbox\\index{SEAWATER} \\citep{morg94} has implemented the\nfull UNESCO equation of state.\n\nThe dynamic molecular\nviscosity\\index{viscosity!molecular}\\index{viscosity!dynamic} $\\mu$ of\nsea water is tabulated in table \\ref{tab:molvisc} taken from Sverdrup\n\\emph{et al.}\n\\shortcite{sver52}. The values decrease  with temperature and increase\nslowly with salinity. The dependence on pressure is insignificant, and is\nneglected here.\n\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\\hline\\hline\nSalinity   & \\multicolumn{7}{c|}{Temperature [\\deg C]} \\\\\n\\cline{2-8}\n[psu] & 0 & 5 & 10 & 15 & 20 & 25 & 30 \\\\\n\\hline\n 0 & 1.79 &  1.52 & 1.31 & 1.14 & 1.01 & 0.89 & 0.80 \\\\\n10 & 1.82 &  1.55 & 1.34 & 1.17 & 1.03 & 0.91 & 0.82 \\\\\n20 & 1.85 &  1.58 & 1.36 & 1.19 & 1.05 & 0.93 & 0.84 \\\\\n30 & 1.88 &  1.60 & 1.38 & 1.21 & 1.07 & 0.95 & 0.86 \\\\\n35 & 1.89 &  1.61 & 1.39 & 1.22 & 1.09 & 0.96 & 0.87 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n \\caption{Dynamic molecular viscosity of sea water\n  with unit $10^{-3} \\,\\text{kgm}^{-1}\\text{s}^{-1}$}\n  \\label{tab:molvisc}\n\\end{table}\n\n\nUsing linear least squares regression the table is approximated by the\nfollowing function where $T$ is the temperature in \\deg C and $S$ is\nthe salinity in psu.\n\\begin{equation}\\label{eq:molvisc}\n  \\mu = 10^{-3} \\, (1.7915 - 0.0538 \\, T + 0.007 \\, T^2 - 0.0023 \\, S )\n            \\:   \\text{kgm}^{-1}\\text{s}^{-1} ,\n\\end{equation}\nThis reproduces table \\ref{tab:molvisc} with an absolute error less\nthan $2 \\times 10^{-5}\\, \\text{kgm}^{-1}\\text{s}^{-1}$ and a relative\nerror of 1.7 \\%. This is good enough to compute egg velocities where\nthe uncertainty in the other variables are larger.  This formula is\nimplemented by the function\n\\edbi{molvisc} in the toolbox. Riley and Skirrow \\shortcite{rile75}\ngive a more precise formula which requires more computational effort.\n", "meta": {"hexsha": "743a25596ba9545eede1c276d872e7716424f39d", "size": 16652, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/teori.tex", "max_stars_repo_name": "bjornaa/Vertegg", "max_stars_repo_head_hexsha": "836ed0857b2f6bc1a7399a20b28b3e4320810b15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Rapport/teori.tex", "max_issues_repo_name": "bjornaa/Vertegg", "max_issues_repo_head_hexsha": "836ed0857b2f6bc1a7399a20b28b3e4320810b15", "max_issues_repo_licenses": ["MIT"], "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/teori.tex", "max_forks_repo_name": "bjornaa/Vertegg", "max_forks_repo_head_hexsha": "836ed0857b2f6bc1a7399a20b28b3e4320810b15", "max_forks_repo_licenses": ["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.0182648402, "max_line_length": 79, "alphanum_fraction": 0.6976939707, "num_tokens": 5597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6371361718049927}}
{"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\n\\title{Geometry with complex numbers \\#1}\n\\author{@all.about.mathematics}\n\n\\begin{document}\n\n\\maketitle\n\\pagecolor{black}\n\\LARGE\n\\section{Introduction}\nIn this series of posts, we discuss representations of geometrical objects with complex numbers and use them to prove some famous geometry theorems! We'll focus on lines and points in this post!\n\n\\noindent{Enjoy :D}\n\\newpage\n\\Large\n\\section{Lines with complex numbers}\nFirst, let's think about lines segments on the complex plane. Let $z_1, z_2 \\in\\mathbb{C}$. How can we represent the line segment from $z_1$ and $z_2$? \n\n\\noindent{We know that the vector from $z_1$ to $z_2$ is $z_2-z_1$, so we can represent the line segment by the equation}\n$$l=z_1+t(z_2-z_1)=z_1+tv$$\nWhere $t$ is a parameter so that $0\\leq t\\leq 1$ and $v$ is a non-zero vector in the direction of the line. Therefore, the line segment is the collection of all possible points $l$. Besides, if we let $t$ be any real number, then we get the line passing through $z_1$ and $z_2$.\n\n\\noindent\nFor example, let $z_1=3-2i$ and $z_2=4+5i$. Then the equation\n$$L:3-2i+t(1+7i)$$\nWith $0\\leq t\\leq 1$ is the line segment from $z_1$ to $z_2$, and if $t\\in\\mathbb{R}$ then it is the line passing through $z_1$ and $z_2$. \n\n\\newpage\n\\section{Finding points of division}\nLet's say we have 2 points $z_1,z_2\\in\\mathbb{C}$. Suppose we want to find a $z_3$ on the line segment $z_1 z_2$ such that it divides the length of the line segment by the ratio $a:b$, which is equivalent to \n$$|z_1-z_3|:|z_2-z_3|=a:b$$\nConsider the equation \n$$L:=z_1+t(z_2-z_1)\\qquad 0\\leq t \\leq 1$$\nTo find $z_3$, \n$$t=\\frac{a}{a+b}\\implies z_3=z_1+\\frac{a}{a+b}(z_2-z_1)=\\frac{bz_1+az_2}{a+b}$$\n\n\\noindent\nFor example, let $z_1=4+5i\\:,\\: z_2=-4-3i$ and suppose we want to find $z_3$ such that it divides $z_1z_2$ by $3:5$. Then\n$$z_3=\\frac{5(4+5i)+3(-4-3i)}{3+5}=\\frac{8+16i}{8}=1+2i$$\n\n\\newpage\n\\section{Parallel lines}\nGiven 2 lines $L_1\\:,\\: L_2$ and their equations \n$$L_1:z_1+tv_1 \\qquad t\\in\\mathbb{R}$$\n$$L_1:z_2+sv_2 \\qquad s\\in\\mathbb{R}$$\nIt is easy to see that if $v_1$ and $v_2$ are parallel, i.e.\n$$\\exists k\\in\\mathbb{R}:v_1=kv_2 $$\nStay tuned for the next post! We are going to use what we've learned here to easily prove a very useful theorem!\n\\end{document}", "meta": {"hexsha": "aaa7028724079cf8f762420ae1619c44d7d5d188", "size": 2729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tig. and Geometry/all.about.mathematics' questions/Complex number and geometry 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": "Tig. and Geometry/all.about.mathematics' questions/Complex number and geometry 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": "Tig. and Geometry/all.about.mathematics' questions/Complex number and geometry 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": 41.3484848485, "max_line_length": 278, "alphanum_fraction": 0.719311103, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6371361610936053}}
{"text": "\\chapter{Separating Hyperplanes, Lagrange Multipliers, and Convex Duality}\n% \\documentclass[draft,11pt]{article}\n%\\documentclass[11pt]{article}\n%\\input{../defs}\n%\\input{../layout-defs}\n%\\usepackage{amsmath}\n%\\usepackage{amssymb}\n%\\usepackage{amsthm}\n%\\usepackage{graphicx}\n%\\usepackage{float}\n%\\usepackage[ruled,vlined]{algorithm2e}\n%\\SetKwBlock{Repeat}{repeat}{}\n%%% for this lecture\n%\\newcommand{\\gap}{\\text{gap}}\n% \\newtheorem{theorem}{Definition}\n%\\interfootnotelinepenalty=10000\n% \\newtheorem{lemma}{Lemma}\n\n%\\usepackage{tikz}\n%\\usetikzlibrary{arrows}\n\n\n%%%% ADD MACROS HERE\n% feel free to add more macros here\n\n%\\begin{document}\n\n\\sloppy\n%\\lecture{12 --- Wednesday, May 13th}\n%{Spring 2020}{Rasmus Kyng, Scribe: Tim Taubner}{\n% Separating Hyperplanes, Lagrange Multipliers, and Convex Duality}\n\n\\section{Overview}\nFirst part of this chapter introduces the concept of a separating hyperplane of two sets followed by a proof that for two closed, convex and disjoint sets a separating hyperplane always exists.\nThis is a variant of the more general \\emph{separating hyperplane theorem}%\n\\footnote{Wikipedia is good on this: \\href{https://en.wikipedia.org/wiki/Hyperplane_separation_theorem}{https://en.wikipedia.org/wiki/Hyperplane\\_separation\\_theorem}} %\ndue to Minkowski.\nThen \\emph{Lagrange multipliers} $\\xx$, $\\ss$ of a convex optimization\nproblem\n\\begin{align*}\n    \\min_y{}\\ & \\energy(\\yy) \\\\ \\nonumber\n\\text{s.t.}\\  & \\AA\\yy = \\bb \\\\ \\nonumber\n              & c(\\yy) \\leq 0\n\\end{align*}\nare introduced and with that, the \\emph{Lagrangian} \\begin{equation*} \\LL(\\yy, \\xx, \\ss) = \\energy(\\yy) + \\xx^{\\trp}(\\bb - \\AA\\yy) + \\ss^{\\trp}c(\\yy) \\end{equation*}\nis defined.\nFinally, we deal with the dual problem\n\\begin{align*}\n     \\max_{\\xx, \\ss, \\ss \\geq 0}{} L(\\xx,  \\ss),\n\\end{align*}\nwhere $L(\\xx, \\ss) = \\min_y L(\\yy, \\xx, \\ss)$. We show \\emph{weak\n  duality}, i.e.\\ $L(\\yy, \\xx, \\ss) \\leq \\energy(\\yy)$ and that assuming \\emph{Slater's condition} the values of both the primal and dual is equal, which is referred to as \\emph{strong duality}.\n\n\\section{Separating Hyperplane Theorem}\nSuppose we have two convex subsets $A, B \\subseteq \\R^n$ that are disjoint ($A \\cup B = \\emptyset$).\nWe wish to show that there will always be a (hyper-)plane $H$ that separates these two sets, i.e.~ $A$ lies on one side, and $B$ on the other side of $H$.\n\nSo what exactly do we mean by Hyperplane? Let's define it.\n\\begin{definition}[Hyperplane]\nA \\emph{hyperplane} $H$ of dimension $n$ is the subset $H := \\{\\xx \\in \\R^n : \\ip{\\nn, \\xx} = \\mu\\}$.\nWe say $H$ has \\emph{normal} $\\nn \\in \\R^n$ and \\emph{threshold} $\\mu$.\nIt is required that $\\nn \\neq \\veczero$.\n\\end{definition}\n\nEvery hyperplane divides $\\R^n$ into two halfspaces $\\{\\xx : \\ip{\\vv, \\xx} \\geq \\mu\\}$ and $\\{\\xx : \\ip{\\vv, \\xx} \\leq \\mu\\}.$\nIt separates two sets, if they lie in different halfspaces. We formally define separating hyperplane as follows.\n\n\\begin{definition}[Separating Hyperplane]\nWe say a hyperplane $H$ \\emph{separates} two sets $A, B$ iff\n\\begin{align*}\n  \\forall \\aa \\in A:& \\ip{\\nn, \\aa} \\geq \\mu \\\\\n  \\forall \\bb \\in B:& \\ip{\\nn, \\bb} \\leq \\mu\n\\end{align*}\nIf we replace $\\geq$ with $>$ and $\\leq$ with $<$ we say $H$ \\emph{strictly} separates $A$ and $B$.\n\\end{definition}\n\nIt is easy to see that there exists disjoint non-convex sets that can not be\nseparated by a hyperplane (e.g.\\ a point cannot be separated from a\nring around it). But can two disjoint convex sets always be strictly separated by a hyperplane?\nThe answer is no: consider the two-dimensional case depicted in\n\\autoref{fig:lefthyper} with $A = \\{ (x,y): x \\leq 0\\}$ and $B = \\{\n(x, y) : x> 0 \\text{ and } y \\geq \\frac{1}{x}\\}$. Clearly they are disjoint; however the only separating hyperplane is $H = \\{ (x, y): x = 0\\}$ but it intersects $A$.\n\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=1\\textwidth]{fig/lec12-non-strict-separator.png}\n  \\caption{The sets $A = \\{ (x, y): x \\leq 0\\}$ and $B = \\{ (x, y): x\n    > 0 \\text{ and } y \\geq \\frac{1}{x} \\}$ only permit a non-strictly separating hyperplane.}\n  \\label{fig:lefthyper}\n\\end{figure}\n\nOne can prove that there exists a non-strictly separating hyperplane for any two disjoint convex sets.\nWe will prove that if we further require $A$,$B$ to be closed and\nbounded, then a strictly separating hyperplane always exists. (Note in\nthe example above how our choice of $B$ is not bounded.)\n\n\\begin{theorem}[Separating Hyperplane Theorem; closed, bounded sets] \\label{th:shtcb}\nFor two closed, bounded, and disjoint convex sets $A, B \\in \\R^n$ there exists a strictly separating hyperplane $H$.\nOne such hyperplane is given by normal $\\nn = \\dd - \\cc$ and threshold $\\mu = \\frac{1}{2}\\left(\\norm{\\dd}_2^2 - \\norm{\\cc}_2^2\\right)$, where $\\cc \\in A$, $\\dd \\in B$ are the minimizers of the distance between $A$ and $B$\n\\begin{equation*} \\text{dist}(A, B) = \\min_{\\aa\\in A, \\bb \\in B}\\norm{\\aa-\\bb}_2 > 0.\\end{equation*}\n% Note that this distance is strictly larger than zero.\n\\end{theorem}\n\\begin{proof}\n  We omit the proof that $\\text{dist}(A, B) = \\min_{\\aa\\in A, \\bb \\in\n    B}\\norm{\\aa-\\bb}_2 > 0$, which follows from $A,B$ being disjoint,\n  closed, and bounded.\nNow, we want to show that $\\ip{\\nn,\\bb} > \\mu$ for all $\\bb \\in B$; then $\\ip{\\nn,\\aa} < \\mu$ for all $\\aa\\in A$ follows by symmetry.\nObserve that\n\\vspace{-1em}\n\\begin{align*}\n  \\ip{\\nn, \\dd} - \\mu&= \\ip{\\dd-\\cc,\\dd} - \\frac{1}{2}\\left(\\norm{\\dd}_2^2-\\norm{\\cc}_2^2\\right)\\\\\n                    &= \\norm{\\dd}_2^2 - \\dd^{\\trp}\\cc - \\frac{1}{2}\\norm{\\dd}_2^2 + \\frac{1}{2}\\norm{\\cc}_2^2 \\\\\n\t\t\t\t\t\t\t\t\t\t&= \\frac{1}{2}\\norm{\\dd-\\cc}_2^2 > 0.\n\\end{align*}\nSo suppose there exists $\\uu \\in B$ such that $\\ip{\\nn, \\uu} - \\mu \\leq 0$.\nWe now look at the line defined by the distance minimizer $\\dd$ and the point on the ``wrong side'' $\\uu$.\nDefine $\\bb(\\lambda) = \\dd + \\lambda(\\uu - \\dd)$, and take the derivative of the distance between $\\bb(\\lambda)$ and $\\cc$.\nEvaluated at $\\lambda=0$ (which is when $\\bb(\\lambda) = \\dd$), this yields\n\\begin{equation*}\n  \\left.\\frac{d}{d\\lambda} \\norm{\\bb(\\lambda) - \\cc}_2^2\\right\\rvert_{\\lambda=0} =\n\t\\left.2\\ip{\\dd-\\lambda\\dd+\\lambda\\uu-\\cc,\\uu-\\dd}\\right\\rvert_{\\lambda=0} =\n\t2\\ip{\\dd-\\cc, \\uu-\\dd}.\n\\end{equation*}\n\nHowever, this would imply that the gradient is strictly negative since\n\\begin{align*}\n\\ip{\\nn, \\uu} - \\mu & = \\ip{\\dd-\\cc,\\uu} - \\ip{\\dd-\\cc,\\dd} + \\ip{\\dd-\\cc,\\dd} - \\mu \\\\\n                  & = \\ip{\\dd-\\cc,\\uu-\\dd} + \\norm{\\dd}_2^2 - \\ip{\\cc,\\dd} - \\frac{1}{2}\\norm{\\dd}_2^2+\\frac{1}{2}\\norm{\\cc}_2^2 \\\\\n                  & = \\ip{\\dd-\\cc,\\uu-\\dd} + \\frac{1}{2}\\norm{\\dd-\\cc}_2^2 \\leq 0.\n\\end{align*}\nThis contradicts the minimality of $\\dd$ and thus concludes this proof.\n\\end{proof}\n\nA more general separating hyperplane theorem holds even when the sets\nare not closed and bounded:\n\n\\begin{theorem}[Separating Hyperplane Theorem] \\label{th:sht}\nGiven two disjoint convex sets $A, B \\in \\R^n$ there exists a hyperplane $H$\nseparating them.\n\\end{theorem}\n\n\n\\section{Lagrange Multipliers and Duality of Convex Problems}\n\nIn this Section, we'll learn about \\emph{Langrange Multipliers} and\nhow they lead to convex duality.\nBut first, let's see an example to help illustrate where these ideas\ncome from.\n\nImagine you were to prove that for all $\\xx \\in \\R^n$ we have $\\norm{\\xx}_p \\leq n^{\\frac{1}{2} - \\frac{1}{p}}\\norm{\\xx}_2$ for some $1 \\leq p \\leq 2;$.\nWe can look at this as optimizing $\\max_{\\xx} \\norm{\\xx}_p$ subject to $\\norm{\\xx}_2$ being constant, e.g.\\ simply $\\norm{\\xx}_2 = 1$. Then the statement above follows from a scaling argument.\n\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=.48\\textwidth]{fig/lec12-2p-norms.jpeg}\n  \\caption{Looking at fixed $\\norm{\\xx}_p = \\alpha$ and $\\norm{\\xx}_2=1$. (Here, $p = 1.5$.)}\n  \\label{fig:2-p-norm}\n\\end{figure}\n\nIf we move from $\\xx$ to $\\xx + \\ddelta$ with $\\ddelta \\perp \\grad_{\\xx}\\norm{\\xx}_2$ and $\\ddelta \\not\\perp \\grad_{\\xx}\\norm{\\xx}_p$ means that for infinitesimally small $\\ddelta$ the 2-norm stays constant but the $p$-norm changes.\nThat means for either $\\xx - \\ddelta$ or $\\xx + \\ddelta$ the $p$-norm increases\nwhile the 2-norm stays constant. Hence at the maximum of $\\norm{\\xx}_p$ the gradients of both norms have to be parallel, i.e.~\\begin{equation*}\\grad_{\\xx}\\left(\\norm{\\xx}_p - \\lambda\\norm{\\xx}_2\\right) = 0.\\end{equation*}\n%Here, $\\lambda$ is the\nThis insight is the core idea of Lagrange multipliers (in this case $\\lambda$).\n\nNote that here the problem is not convex, because $\\{ \\xx: \\norm{\\xx}_2^2 =\n1 \\}$ is not convex and because we are asking to \\emph{maximize} a norm.\nIn the following we will study Lagrange multipliers for general convex problems.\n\n\\subsection{General Convex Problems}\n\nA full formal treament of convex duality would require us to be more careful\nabout using $\\inf$ and $\\sup$ in place of $\\min$ and $\\max$, as well\nas considering problems that have no feasible solutions.\nToday, we'll ignore these concerns.\n\nLet us consider a general convex optimization problem with convex objective, linear equality constraints and convex inequality constraints\n\\begin{align}\n  \\label{eq:primalprob}\n     \\min_{y \\in S}{} & \\energy(\\yy) \\\\ \\nonumber\n\\text{s.t.}\\  & \\AA\\yy = \\bb \\\\ \\nonumber\n              & \\cc(\\yy) \\leq \\veczero,\n\\end{align}\nwhere $\\energy(\\yy): S \\rightarrow \\R$ is defined on a convex subset $S \\subseteq \\R^n$, $\\AA \\in \\R^{m\\times n}$\nand $\\cc(\\yy)$ is a vector of constraints $\\cc(\\yy) = \\left(c_i(\\yy)\\right)_{i \\in [k]}$.\nFor every $i \\in [k]$ the function $c_i: S \\rightarrow \\R$ is convex.\n\n\\begin{definition}[Primal feasibility]\nWe say that $\\yy \\in S$ is \\emph{primal feasible} if all constraints are satisfied, i.e.~$\\AA\\yy = \\bb$ and $\\cc(\\yy) \\leq \\veczero$.\n\\end{definition}\n\nIn the following we will denote by $\\alpha^* = \\energy(\\yy^*)$ the optimal value of the primal program where $\\yy^*$ is an minimizer.\n\n\\begin{definition}\nNext we introduce the \\emph{dual variables} $\\xx \\in \\R^m$, $\\ss \\in \\R^k$ and define the \\emph{Lagrangian} as\n\\begin{equation*} L(\\yy, \\xx, \\ss) = \\energy(\\yy) + \\xx^{\\trp}(\\bb-\\AA\\yy) + \\ss^{\\trp}\\cc(\\yy). \\end{equation*}\nWe also define a Lagrangian only in terms of the dual variables by minimizing over $\\yy$ as\n\\begin{equation*} L(\\xx, \\ss) = \\min_{\\yy}L(\\yy, \\xx, \\ss). \\end{equation*}\n\\end{definition}\n\n\\begin{definition}[Dual feasibility]\nWe say $(\\xx, \\ss)$ is dual feasible if $\\ss \\geq 0$.\nIf additionally $\\yy$ is primal feasible, we say $(\\yy, \\xx, \\ss)$ is primal-dual feasible.\n\\end{definition}\n\n\\begin{definition}[Dual problem]\nWe define the \\emph{dual problem} as\n\\begin{align}\n  \\label{eq:dualprob}\n  \\max_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}}\n  \\min_{\\yy}L(\\yy, \\xx, \\ss)\n  =\n  \\max_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}} L(\\xx,  \\ss)\n  \\end{align}\nand denote the optimal dual value by $\\beta^*$.\n\\end{definition}\n\n\nFor each $\\yy$, the Lagrangian $L(\\yy, \\xx,\n\\ss)$ is linear in $(\\xx,\\ss)$ and hence also concave in them.\nHence $L(\\xx,  \\ss)$ is a concave function, because it is the pointwise\nminimum (over $\\yy$), of a collection of concave functions in\n$(\\xx,\\ss)$.\n\nThis also means that the dual problem is really a convex optimization\nproblem in disguise, because we can flip the sign of $-L(\\xx,  \\ss)$\nto get a convex function and minimizing this is equivalent to\nmaximizing $L(\\xx,  \\ss)$.\n\\begin{align*}\n  \\max_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}} L(\\xx,  \\ss)\n  =\n  -\n  \\min_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}} -L(\\xx,  \\ss)\n\\end{align*}\n\n% Of course, we can write the dual problem using the\n% $\\min_{\\yy}L(\\yy, \\xx, \\ss)$ notation as\n% \\[\n%   \\max_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}}\n%   \\min_{\\yy}L(\\yy, \\xx, \\ss)\n%   =\n%   \\max_{\\substack{\\xx, \\ss \\\\ \\ss \\geq 0}} L(\\xx,  \\ss)\n%   \\]\n\n\n\n\\subsection{Weak Duality}\n\\label{sec:weakdual}\nFirst we see that the primal problem can be written in terms of the Lagrangian as\n\\begin{equation}\n  \\label{eq:primalminmax}\n  \\alpha^* = \\min_{\\yy}\\max_{\\xx; \\ss\\geq\\veczero} L(\\yy, \\xx, \\ss)\n\\end{equation}\nThis is because for a minimizing $\\yy$ all constraints have to be satisfied and the Lagrangian simplifies to $L(\\yy,\\xx,\\ss) = \\energy(\\yy)$.\nIf $\\AA\\xx - \\bb = \\veczero$ was violated, making $\\xx$ large sends $L(\\yy,\\xx,\\ss) \\rightarrow \\infty$.\nAnd if $\\cc(\\yy) \\leq \\veczero$ is violated, we can make $L(\\yy,\\xx,\\ss) \\rightarrow \\infty$ by choosing large $\\ss$.\n\nNote that we require $\\ss \\geq \\veczero$, as we only want to penalize the violation of the inequality constraints in one direction, i.e.\\ when $\\cc(\\yy) > 0$.\n\n%\\begin{theorem}[Weak Duality]\nFor any primal-dual feasible $\\yy,\\xx,\\ss$ we have\n$L(\\yy, \\xx, \\ss) \\leq \\energy(\\yy)$ and hence also $L(\\xx, \\ss) = \\min_y L(\\yy, \\xx, \\ss) \\leq \\energy(\\yy)$.\n\nIn other words $\\max_{\\xx; \\ss \\geq 0} L(\\xx, \\ss) = \\beta^* \\leq \\alpha^*$.\nThis is referred to as \\emph{weak duality}.\n\nUsing the forms in Equations~\\eqref{eq:dualprob} and\n\\eqref{eq:primalminmax}, we can also state this as\n\\begin{equation*}\n  \\alpha^* = \\min_{\\yy}\\max_{\\xx; \\ss\\geq\\veczero} L(\\yy, \\xx, \\ss)\n  \\geq\n  \\max_{\\xx; \\ss\\geq\\veczero} \\min_{\\yy} L(\\yy, \\xx, \\ss)\n  =\n  \\beta^*\n  .\n\\end{equation*}\n\n\\subsection{Strong Duality}\nSo now that we have proved weak duality $\\beta^* \\leq \\alpha^*$,\nwhat is strong duality? $\\beta^* = \\alpha^*$?\nThe answer is yes, but strong duality only holds under some conditions.\n\nOne sufficient condition we look at today is a variant of \\emph{Slater's condition}%\n\n\\begin{definition}[Slater's condition with full domain] \\label{def:slater}\nA (primal) problem as defined in \\eqref{eq:primalprob} with $S = \\R^n$ fulfills\nSlater's condition if there exists a \\emph{strictly feasible} point,\ni.e.\\ there exists $\\yytil$ s.t.\\ $\\AA\\yytil = \\bb$ and $\\cc(\\yytil) <\n\\veczero$.\nThis means that the strictly feasible point $\\yytil$ lies strictly inside the set $\\{\\yy : \\cc(\\yy) \\leq \\veczero\\}$ defined by the inequality constraints.\n\\end{definition}\n\n\\begin{theorem}\n  \\label{thm:slaterstrongduality}\nFor a problem satisfying Slater's condition, strong duality holds, i.e.\\ $\\alpha^* = \\beta^*$.\nIn other words, the optimal value of the primal problem $\\alpha^*$ is equal to the optimal value of the dual.\n\\end{theorem}\n\nTo extend Slater's condition to the case when the domain $S$ is a\nstrict subset of $\\R^n$, we need the notion of a ``relative interior''.\n\n% \\begin{definition}[Affine hull] \\label{def:affhull}\n% Given a set $S \\subset \\R^n$, the \\emph{affine hull} of $S$, denoted $\\operatorname{aff}(S)$, is the\n% union of $S$ and all lines through any pair of points in $S$.\n% We can also write this as\n% \\[\n%   \\operatorname{aff}(S) = \\setof{\\alpha \\xx + (1-\\alpha) \\yy : \\xx,\n%     \\yy \\in S, \\alpha \\in \\R}. \n%   \\]\n% \\end{definition}\n\n\\begin{definition}[Relative interior] \\label{def:relint}\n  Given a convex set $S \\subset \\R^n$, the \\emph{relative interior} of $S$ is\n  \\[\n    \\operatorname{relint}(S) = \\setof{x \\in S : \\text{ for all } \\yy\n      \\in S \\text{ there exists } \\epsilon > 0 \\text{ such that }\n      \\xx - \\epsilon(\\yy - \\xx) \\in S}\n    .\n  \\]\n\\end{definition}\nIn other words, $\\xx \\in \\operatorname{relint}(S)$ if starting at $\\xx\n\\in S$ we can move\n``away'' from any $\\yy \\in S$ by a little and still be in $\\SS$.\nAs an example, suppose $S = \\setof{(s,t) \\in \\R^2 \\text{ such that } s\n  \\geq 0 \\text{ and } t = 0}$.\nThen $(0,0) \\in S$ but $(0,0) \\not\\in \\operatorname{relint}(S)$, while\n$(1,0) \\in \\operatorname{relint}(S)$.\n\nNow, we can state a more general version of Slater's condition.\n\n\\begin{definition}[Slater's condition] \\label{def:slatergeneral}\nA (primal) problem as defined in \\eqref{eq:primalprob} fulfills\nSlater's condition if there exists a \\emph{strictly feasible} point\n$\\yy \\in \\operatorname{relint}(S)$.\nWe require $\\AA\\yytil = \\bb$ and $\\cc(\\yytil) <\n\\veczero$.\nThis means that the strictly feasible point $\\yytil$ lies strictly inside the set $\\{\\yy : \\cc(\\yy) \\leq \\veczero\\}$ defined by the inequality constraints.\n\\end{definition}\n\nTheorem~\\ref{thm:slaterstrongduality} also holds given the general\nSlater's condition of Definition~\\ref{def:slatergeneral}.\n\n\\paragraph{How are we going to prove this?} Before we prove the theorem, let's make a few observations to get us\nwarmed up. If you get bored, skip ahead to the proof.\n\nIt is sufficient to prove that $\\alpha^* \\leq \\beta^*$, as the statement then follows in conjunction with weak duality.\nWe define the set\n\\begin{equation*} G = \\{(\\energy(\\yy), \\AA\\yy - \\bb, \\cc(\\yy)) : \\yy \\in S \\}, \\end{equation*}\nwhere $S \\subseteq \\R^n$ is the domain of $\\energy$.\n\nImmediately, we observe that we can write the optimal primal value as\n\\begin{equation*} \\alpha^* = \\min \\{t:(t,\\vv,\\uu) \\in G, \\vv = \\veczero, \\uu \\leq \\veczero\\}. \\end{equation*}\nSimilarly, we can write the Lagrangian (after minimizing over $\\yy$)\n\\begin{equation*} L(\\xx, \\ss) = \\min_{(t,\\vv,\\uu) \\in G} (1, \\xx, \\ss)^{\\trp} (t, \\vv, \\uu). \\end{equation*}\nThis is equivalent to the inequality, for $(t,\\vv,\\uu) \\in G$,\n\\begin{equation*} (1, \\xx, \\ss)^{\\trp}(t, \\vv, \\uu) \\geq L(\\xx, \\ss). \\end{equation*}\nwhich defines a hyperplane with $\\nn = (1,\\xx,\\ss)$ and $\\mu = L(\\xx,\n\\ss)$ such that $G$ is on one side.\n\nTo establish strong duality, we would like to show the existence of a\nhyperplane such that for $(t,\\vv,\\uu) \\in G$\n\\[\n  \\nn^{\\trp}(t, \\vv, \\uu) \\geq \\alpha^* \\text{ and } \\nn = (1,\\xxhat,\\sshat)\n  \\text{ with } \\sshat \\geq \\veczero.\n\\]\nThen we would immediately get\n\\begin{equation*}\n \\beta^* \\geq L(\\xxhat,\\sshat)= \\min_{(t,\\vv,\\uu) \\in G} (1, \\xx,\n \\ss)^{\\trp} (t, \\vv, \\uu) \\geq \\alpha^* .\n\\end{equation*}\n\nPerhaps not surprisingly, we will use the Separating\nHyperplane Theorem.\nWhat are the challenges we need to deal with?\n\\begin{itemize}\n\\item We need to replace $G$ with a convex set (which we will call\n  $A$) and separate $A$ from some other convex set (which we will call $B$).\n\\item We need to make sure the hyperplane normal $\\nn$ has $1$ in the first\n  coordinate and $\\ss \\geq \\veczero$, and the hyperplane threshold is $\\alpha^*$.\n\\end{itemize}\n\n% The proof we are about to see handles these things in one neat\n% stroke: Essentially, we replace $G$ with the convex set that comes from replacing\n% the convex functions $\\energy$ and $\\cc$ with their epigraphs.\n\n% If strong duality indeed holds,\n% and is obtained at some $L(\\yyhat,\\xxhat,\\sshat)$\n% then the reasoning we used to prove weak duality in\n% Section~\\ref{sec:weakdual} seems to suggest that a dual point\n% $(\\xx^*,\\ss^*)$ maximizing $L(\\xx,\\ss)$ will occur at a feasible\n% $\\yy$, since otherwise $L(\\yy,\\xx,\\ss)$ could be reduced further by\n% changing $(\\xx,\\ss)$ to penalize $\\yy$.\n% Of course, it's not clear whether this could then be counter-acted by\n% changing $\\yy$.\n\n\n% \\begin{itemize}\n% \\item and correspond to a feasible $\\yy$ in the sense that\n%   $L(\\xx^*,\\ss^*) = (\\yy,\\xx^*,\\ss^*)$\n%   \\item be dual feasible,\n% \\end{itemize}\n% If the minimizing $\\yy$ is not feasible,  but\n\n\n\n%  Then by considering a feasible $\\yyhat$ for the primal problem, we\n%   get\n%   \\begin{align**}\n%     \\beta^*\n%     & \\geq L(\\xxhat,\\sshat) \\\\\n%     &= (1, \\xxhat,\\sshat)^{\\trp}(\\energy(\\yyhat), \\AA\\yyhat - \\bb, \\cc(\\yyhat))\n%       \\geq \\energy(\\yyhat) \\geq \\alpha^*\n%   \\end{align**}\n% This sandwiching also tells us that $\\yyhat$ and $(\\xxhat,\\sshat)$\n% must be optimal for the primal and dual problems respectively.\n\n% Clearly, we like to ensure that\n\n\n% We'd like to show that\n% for some dual-feasible $(\\xxhat,\\sshat)$ maximizing $L(\\xx,\n% \\ss)$, then the hyperplane inequality doesn't have any slack, i.e. it\n% holds with equality at some point, and furthermore, equality is\n% obtained at some $(t, \\vv, \\xx) = (\\energy(\\yyhat), \\AA \\yyhat - \\bb,\n% \\cc(\\yyhat))$ where $\\yyhat$ is feasible.\n\n\n\n\n\n% When we proved weak duality in Section~\\ref{sec:weakdual}, our reasoning\n\n\\begin{proof}[Proof of Theorem~\\ref{thm:slaterstrongduality}.]\n  For simplicity, our proof will assume that $S = \\R^n$, but only a little\n  extra work is required to handle the general case.\n\n  Let's move to on finding two convex disjoints sets $A, B$ to enable the use of the separating hyperplane \\autoref{th:sht}.\n\nFirst set we define $A$, roughly speaking, as a multi-dimensional epigraph of\n$G$. More precisely\n\\begin{equation*} A = \\{(t, \\vv, \\uu) : \\exists \\yy \\in S, t \\geq \\energy(\\yy), \\vv = \\AA\\yy - \\bb, \\uu \\geq \\cc(\\yy)\\}. \\end{equation*}\nNote that $A$ is a convex set. The proof is similar to the proof that the epigraph of a convex function is a convex set.\nThe optimal value of the primal program can be now written as\n\\begin{equation*} \\alpha^* = \\min_{(t,\\veczero,\\veczero) \\in A} t. \\end{equation*}\nAnd we define another set $B$ of the same dimensionality as $A$ by\n\\begin{equation*} B := \\{(r \\in \\R, \\veczero \\in \\R^m, \\veczero \\in \\R^k) : r < \\alpha^* \\}. \\end{equation*}\nThis set $B$ is convex, as it is a ray.\nAn example of two such sets $A,B$ is illustrated in \\autoref{fig:ab}.\n\nWe show that $A \\cap B = \\emptyset$ by contradiction.\nSuppose $A, B$ are not disjoint; then there exists $\\yy$ such that\n\\begin{equation*} (\\energy(\\yy), \\AA\\yy-\\bb, \\cc(\\yy)) = (r, \\veczero, \\uu) \\end{equation*}\nwith $\\uu \\leq \\veczero$.\nBut this means that $\\yy$ is feasible and  $\\energy(\\yy) = r < \\alpha^*$; contradicting the optimality of $\\alpha^*$.\n\n% Now let's move back to proving that strong duality follows from Slater's condition.\n%As Slater's condition requires the existence of a $\\yy$ such that $\\AA\\yy = \\bb$\nTo make things simpler,\nwe assume that our linear constraint matrix $\\AA \\in \\R^{m\\times n}$,\nhas full row rank and $m < n$ (but very little extra work is required to\ndeal with the remaining cases, which we omit).\n\nAs we just proved, $A$ and $B$ are convex and disjoint sets and hence the separating hyperplane theorem (\\autoref{th:sht}) we introduced earlier in this chapter implies the existence a separating hyperplane.\nThis means there exists a normal\n$\\nn = (\\tilde\\rho, \\xxtil, \\sstil)$ and threshold\n% \\footnote{To prevent confusion, the threshold here is denoted $\\mu$ instead of $alpha$} %\n$\\mu$ and with $A$ on one side, i.e.\\\n%\\begin{equation*} (t, \\vv, \\uu) \\in A \\implies \\begin{pmatrix}t \\vv^{\\trp} \\uu^{\\trp}\\end{pmatrix}\\begin{pmatrix}\\tilde\\rho \\\\ \\xxtil \\\\ \\sstil\\end{pmatrix} \\geq \\alpha \\end{equation*}\n\\begin{equation} \\label{eq:A}\n(t, \\vv, \\uu) \\in A \\implies (t, \\vv, \\uu)^{\\trp}(\\tilde\\rho, \\xxtil, \\sstil) \\geq \\mu\n\\end{equation}\nand the set $B$ on the other side:\n\\begin{equation} \\label{eq:B}\n(t, \\vv, \\uu) \\in B \\implies (t, \\vv, \\uu)^{\\trp}(\\tilde\\rho, \\xxtil, \\sstil) \\leq \\mu.\n\\end{equation}\n\nNow, we claim that $\\sstil \\geq 0$. Suppose $\\sstil(i) < 0$, then for $\\uu(i) \\rightarrow \\infty$ the threshold would grow unbounded, i.e.\\ $\\mu \\rightarrow -\\infty$ contradicting that the threshold $\\mu$ is finite by the separating hyperplane theorem.\nSimilarly we claim $\\tilde\\rho \\geq 0$, as if this were not the case, having $t \\rightarrow \\infty$ implies that $\\mu \\rightarrow -\\infty$ again contradicting the finiteness of $\\mu$.\n\nFrom Equation~\\eqref{eq:B} it follows that $t\\tilde\\rho \\leq \\mu$ for all $t < \\alpha^*$ which implies that $t\\tilde\\rho \\leq \\mu$ for $t = \\alpha^*$ by taking the limit. Hence we have $\\alpha^*\\tilde\\rho \\leq \\mu$.\nFrom $(t, \\vv, \\uu) \\in A$ we get from  Equation~\\eqref{eq:A}\n\\begin{equation*}\n(\\tilde\\rho, \\xxtil, \\sstil)^{\\trp}(t, \\vv, \\uu) \\geq \\mu \\geq \\alpha^*\\tilde\\rho\n\\end{equation*}\nand thus\n\\begin{equation}\\label{eq:rhotilde}\n(\\tilde\\rho, \\xxtil, \\sstil)^{\\trp}(\\energy(\\yy), \\AA\\yy-\\bb,\\cc(\\yy)) \\geq \\alpha^*\\tilde\\rho.\n\\end{equation}\n\n\nNow we consider two cases; starting with the ``good'' case where $\\tilde\\rho > 0$.\nDividing  Equation~\\eqref{eq:rhotilde} by $\\tilde\\rho$ gives\n\\begin{equation*}\n  \\energy(\\yy) + \\frac{\\xxtil^{\\trp}}{\\tilde\\rho}(\\AA\\yy - \\bb) + \\frac{\\sstil^{\\trp}}{\\tilde\\rho}\\cc(\\yy) \\geq \\alpha^*.\n\\end{equation*}\nNoting that the left hand side above is $L(\\yy, \\frac{\\xxtil}{\\tilde\\rho}, \\frac{\\sstil}{\\tilde\\rho})$\nand that the equation holds for arbitrary $\\yy$; therefore also for the minimum we get\n\\begin{equation*} \\min_{\\yy}{L\\left(\\yy, \\frac{\\xxtil}{\\tilde\\rho}, \\frac{\\sstil}{\\tilde\\rho}\\right)}\\geq \\alpha^* \\end{equation*}\nand hence via definition of $\\beta^*$ finally\n\\begin{equation*} \\beta^* \\geq L\\left(\\frac{\\xxtil}{\\tilde\\rho},\\frac{\\sstil}{\\tilde\\rho}\\right) \\geq \\alpha^*. \\end{equation*}\n\nNext consider the ``bad'' case $\\tilde\\rho = 0$.\nAs $\\alpha^*\\tilde\\rho \\leq \\mu$, we have $0 \\leq \\mu$.\nFrom  Equation~\\eqref{eq:A} we get\n\\begin{equation*}\n  \\cc(\\yy)^{\\trp}\\ss + \\xx^{\\trp}(\\bb-\\AA\\yy) \\geq \\mu \\geq 0.\n\\end{equation*}\nAs Slater's condition holds, there is an interior point $\\yytil$, i.e.\\ it satisfies $\\bb - \\AA\\yytil = \\veczero$ and $\\cc(\\yytil) < \\veczero$. Together with the equation above this yields\n\\begin{equation*} \\cc(\\yytil)^{\\trp}\\sstil + \\xxtil^{\\trp}\\veczero \\geq 0 \\end{equation*}\nwhich implies\n$\\cc(\\yytil)^{\\trp}\\sstil \\geq 0 $\nand as $\\cc(\\yytil) < \\veczero$ this means $\\sstil = \\veczero$.\n\nAs the normal $(\\tilde\\rho,\\sstil,\\xxtil)$ of the hyperplane can not be all zeroes, this means the last ``component'' $\\xxtil$ must contain a non-zero entry, i.e.\\ $\\xxtil \\neq \\veczero$.\nFurthermore $\\xxtil^{\\trp}(\\bb - \\AA\\yytil) = \\veczero$, $\\cc(\\yytil) < \\veczero$ and $\\AA$ has full row rank, hence there exists $\\ddelta$ such that\n\\begin{equation*}\n\\xxtil^{\\trp}(\\bb-\\AA(\\yytil+\\ddelta)) < \\veczero \\text{ and } \\cc(\\yytil + \\ddelta) < 0.\n\\end{equation*}\nThis, however, means that there is a point in $A$ on the wrong side of the hyperplane, as\n\\begin{equation*}\n(\\tilde\\rho, \\xxtil, \\sstil)^{\\trp}(\\energy(\\yytil+\\ddelta), \\bb-\\AA(\\yytil+\\ddelta), \\cc(\\yytil+\\ddelta)) < 0\n\\end{equation*}\nbut the threshold is $\\mu \\geq 0$.\n\\end{proof}\n\n\\begin{remark*}\n  Note that our reasoning about why $\\ss \\geq \\veczero$ in the proof\n  above is very similar to our reasoning for why the primal program\n  can be written as Problem~\\eqref{eq:primalminmax}.\n\\end{remark*}\n\n\\paragraph{Example.}\nAs an example of $A$ and $B$ as they appear in the above proof,\nconsider\n\\[\n\\min_{\\substack{y \\in (0,\\infty) \\\\ 1/y\n    -1 \\leq 0}}\ny^2\n\\]\n This leads to $\\alpha^* = 1,\n    y^* =1$, and $A = \\setof{ (t,u): y \\in (0,\\infty) \\text{ and } t >y^2\n       \\text{ and } u \\geq 1/y-1}$, and $B = \\setof{ (t,0) : t < 1}$ and the separating hyperplane normal is $\\nn = (1,2)$.\nThese two sets $A,B$ are illustrated in \\autoref{fig:ab}.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=.9\\textwidth]{fig/lec12-the-sets-a-b.jpg}\n  \\caption{Example of the convex sets $A$ and $B$ we wish to separate by hyperplane.}\n\\label{fig:ab}\n\\end{figure}\n\n\n\n\\subsection{The Gradient Perspective}\nLet's come back to what we said earlier about parallel gradient.\nSuppose $\\yy^*$ is an optimizer of the primal problem and $\\xx^*, \\ss^*$ for the dual.\nWe thus have\n\\[ L(\\yy^*, \\xx^*, \\ss^*) = \\alpha^* = \\beta^*. \\]\nBecause $L(\\yy, \\xx^*, \\ss^*)$ is a convex function in $\\yy$, it also\nfollows that if $\\energy: S \\to \\R$ and $\\cc$ are differentiable and the minimizer\n$\\yy^*$ is not on the boundary of $S$, then we must have that the\ngradient w.r.t. $\\yy$ is zero, i.e.\n\\begin{equation*} \\left.\\grad_{\\yy}L(\\yy, \\xx^*, \\ss^*)\\right|_{\\yy=\\yy^*} = 0 \\end{equation*}\nand plugging in\n\\[ L(\\yy, \\xx^*, \\ss^*) = \\energy(\\yy) + \\xx^{\\trp}(\\bb - \\AA\\yy) + \\ss^{\\trp}\\cc(\\yy) \\]\nyields\n\\begin{equation*} \\grad\\energy(\\yy) + \\xx^{\\trp}\\grad_y(\\bb-\\AA\\yy) + \\ss^{\\trp}\\grad\\cc(\\yy) = \\veczero. \\end{equation*}\nAnd this connects to our point of the parallel gradients from the beginning of this section.\n\n\\subsection{Complementary Slackness}\n\nWe will see more of this next time, but if we look at $\\yy^*$ we see that\n\\begin{equation*}\\energy(\\yy^*) =  \\alpha^* = \\energy(\\yy^*) + \\xx^{\\trp}(\\bb - \\AA\\yy^*) + \\ss^{\\trp}\\cc(\\yy^*) = \\energy(\\yy^*) + \\ss^{\\trp}\\cc(\\yy^*) \\end{equation*}\nand hence when the $i$-th convex constraint is not active, i.e.\\ $c_i(\\yy^*) < 0$ the \\emph{slack} must be zero, i.e.\\ $\\ss(i) = 0$.\nConversely if the slack is non-zero, that is $\\ss(i) \\neq 0$ implies that the constraint is active, i.e.\\ $c_i(\\yy^*) = 0$.\n\nA good reference for this is Boyd's free online book ``Convex\noptimization'' (linked to on the course website).\nIt provides a number of different interpretations of duality. One\nparticularly interesting one comes from economics:\neconomists see the slack variables $\\ss$ as prices for violating the constraints.\n\n%\\end{document}\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"agao21_script\"\n%%% End:\n", "meta": {"hexsha": "f921f7b21dcde7bf1663519ee984544718e9cf13", "size": 28431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture12_mod.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/lecture12_mod.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/lecture12_mod.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": 48.4344122658, "max_line_length": 252, "alphanum_fraction": 0.6675108157, "num_tokens": 9760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6371021340742857}}
{"text": "\\subsection{Group actions}\\label{subsec:group_actions}\n\n\\begin{definition}\\label{def:endomorphism_monoid}\n  For every object \\( X \\) in an arbitrary \\hyperref[def:category]{category} \\( \\cat{C} \\), the set \\( \\cat{C}(X) \\) is a \\hyperref[def:monoid]{monoid} with morphism composition as the monoid operation and \\( \\id_X \\) as the monoid identity.\n\n  Outside of \\hyperref[sec:category_theory]{category theory}, whenever the category \\( \\cat{C} \\) is clear from the context, we call \\( \\cat{C}(X) \\) the \\term{endomorphism monoid} over \\( X \\) and denote it by \\( \\End(X) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:monoid_action}\n  Let \\( M \\) be a \\hyperref[def:monoid]{monoid} and let \\( X \\) be an object in some \\hyperref[def:category]{category} \\( \\cat{C} \\).\n\n  We will define monoid actions of \\( M \\) on \\( X \\), which we will sometimes call \\term{left monoid actions}. There are also \\term{right monoid actions}, which are only briefly mentioned in \\fullref{def:monoid_action/functor}.\n\n  A \\term{monoid action} can be defined equivalently as:\n  \\begin{thmenum}\n    \\thmitem{def:monoid_action/homomorphism} A \\hyperref[def:monoid/homomorphism]{homomorphism} from \\( M \\) to the \\hyperref[def:endomorphism_monoid]{endomorphism monoid} \\( \\End(X) \\).\n\n    \\thmitem{def:monoid_action/functor} A \\hyperref[def:functor]{functor} from the \\hyperref[def:monoid_delooping]{delooping} \\( \\cat{B}_M \\) to \\( \\cat{C} \\).\n\n    Right actions are \\hyperref[rem:contravariant_functor]{contravariant functors}.\n\n    \\thmitem{def:monoid_action/family} An \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ \\Phi_m }_{m \\in M} \\) of \\hyperref[def:morphism_invertibility/endomorphism]{endomorphisms} of \\( X \\) such that\n    \\begin{align}\n      &\\Phi_e = \\id_X, \\label{eq:def:monoid_action/family/identity}\\tag{\\logic{MA1}} \\\\\n      &\\Phi_{mn} = \\Phi_m \\bincirc \\Phi_n. \\label{eq:def:monoid_action/family/compatibility}\\tag{\\logic{MA2}}\n    \\end{align}\n\n    This defines a function \\( \\Phi: M \\times A \\to A \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:monoid_action/homomorphism}{def:monoid_action/functor} Suppose that we have a monoid homomorphism \\( \\Phi: M \\to \\End(X) \\). Define the functor\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: \\cat{B}_M \\to \\cat{C} \\\\\n      &F(\\anon) \\coloneqq X \\\\\n      &F(m) \\coloneqq \\Phi(m).\n    \\end{aligned}\n  \\end{equation*}\n\n  This is indeed a functor because \\eqref{eq:def:functor/CF1} follows from \\eqref{eq:def:pointed_set/homomorphism} and \\eqref{eq:def:functor/CF2} follows from \\eqref{eq:def:magma/homomorphism}.\n\n  \\ImplicationSubProof{def:monoid_action/functor}{def:monoid_action/family} Suppose that we have a functor \\( F: \\cat{B}_M \\to \\cat{C} \\). Let \\( X \\coloneqq F(\\anon) \\) and define the \\( M \\)-indexed family\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi_m: X \\to X \\\\\n      &\\Phi_m \\coloneqq F(m).\n    \\end{aligned}\n  \\end{equation*}\n\n  It satisfies the necessary axioms:\n  \\begin{itemize}\n    \\item \\ref{eq:def:monoid_action/family/identity} holds:\n    \\begin{equation*}\n      \\Phi_e\n      =\n      F(e)\n      \\reloset {\\eqref{eq:def:functor/CF1}} =\n      \\id_A.\n    \\end{equation*}\n\n    \\item \\ref{eq:def:monoid_action/family/compatibility} holds: for every pair \\( m, n \\in M \\), we have\n    \\begin{equation*}\n      \\Phi_{mn}\n      =\n      F(mn)\n      \\reloset {\\eqref{eq:def:functor/CF2}} =\n      F(m) \\bincirc F(n)\n      =\n      \\Phi_m \\bincirc \\Phi_n\n    \\end{equation*}\n  \\end{itemize}\n\n  \\ImplicationSubProof{def:monoid_action/family}{def:monoid_action/homomorphism} Suppose that we have an indexed family \\( \\seq{ \\Phi_m }_{m \\in M} \\) of endomorphisms of \\( A \\) that satisfies the axioms for left action. Regard this indexed family as a function \\( \\Phi: M \\to \\End(X) \\).\n\n  Then \\( \\Phi \\) is a monoid homomorphism because \\ref{eq:def:monoid_action/family/identity} implies \\( \\Phi(e) = \\id_X \\) and \\eqref{eq:def:monoid_action/family/compatibility} implies\n  \\begin{equation*}\n    \\Phi(mn) = \\Phi(m) \\bincirc \\Phi(n).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:monoid_is_action}\n  Every \\hyperref[def:monoid]{monoid} \\hyperref[def:monoid_action]{acts} on itself via the family of functions \\( h \\mapsto g \\cdot h \\) indexed by \\( g \\). These functions are not monoid homomorphisms in general.\n\n  Compare this result to \\fullref{thm:cayleys_theorem}.\n\\end{proposition}\n\\begin{proof}\n  The family satisfies \\fullref{def:monoid_action/family}:\n  \\begin{itemize}\n    \\item \\ref{eq:def:monoid_action/family/identity} follows from \\eqref{eq:def:monoid/theory/identity}.\n\n    \\item \\ref{eq:def:monoid_action/family/compatibility} follows from associativity:\n    \\begin{equation*}\n      [h \\mapsto g_1 \\cdot h] \\bincirc [h \\mapsto g_2 \\cdot h] = [h \\mapsto g_1 \\cdot (g_2 \\cdot h)] = [h \\mapsto (g_1 \\cdot g_2) \\cdot h].\n    \\end{equation*}\n  \\end{itemize}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:exponentiation_monoid_action}\n  The \\hyperref[def:set_of_natural_numbers]{natural numbers} \\( \\BbbN \\) (\\hyperref[rem:peano_arithmetic_zero]{with zero}) act on any \\hyperref[def:monoid]{monoid} by \\hyperref[def:monoid/exponentiation]{exponentiation} via the family of function \\( g \\mapsto g^n \\) indexed by \\( n \\in \\BbbN \\).\n\n  Compare this result to \\fullref{thm:exponentiation_group_action}.\n\\end{proposition}\n\\begin{proof}\n  This family satisfies \\fullref{def:monoid_action/family}:\n  \\begin{itemize}\n    \\item \\ref{eq:def:monoid_action/family/identity} is obvious.\n    \\item \\ref{eq:def:monoid_action/family/compatibility} follows from \\fullref{thm:magma_exponentiation_properties/repeated}.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\\label{def:automorphism_group}\n  For every object \\( X \\) in a \\hyperref[def:groupoid]{groupoid} \\( \\cat{G} \\), the set \\( \\cat{G}(X) \\) is a \\hyperref[def:group]{group} with morphism composition as the group operation.\n\n  Similarly to \\hyperref[def:endomorphism_monoid]{endomorphism monoids}, whenever the groupoid \\( \\cat{G} \\) is clear from the context, we call \\( \\cat{G}(X) \\) the \\term{automorphism group} over \\( X \\) and denote it by \\( \\aut(X) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:symmetric_group}\n  We call the \\hyperref[def:automorphism_group]{automorphism group} of a set \\( A \\) the \\term{symmetric group}\\footnote{The term possibly comes from symmetric functions defined in \\fullref{def:symmetric_function}} on \\( A \\) and denote it by \\( S(A) \\). The group \\( S(A) \\) consists of bijective functions, which we call \\term{permutations}.\n\n  Rather than for arbitrary sets, we often consider symmetric group\n  \\begin{equation*}\n    S_n \\coloneqq S(\\set{ 1, 2, \\ldots, n }).\n  \\end{equation*}\n\n  It is conventional to call \\( S_n \\) the \\enquote{symmetric group on \\( n \\) letters}.\n\n  \\begin{thmenum}\n    \\thmitem{def:symmetric_group/permutation} It is common to write a permutation \\( \\sigma \\) in \\( S_n \\) as\n    \\begin{equation*}\n      \\begin{pmatrix}\n        1         & \\cdots & n \\\\\n        \\sigma(1) & \\cdots & \\sigma(n)\n      \\end{pmatrix}\n    \\end{equation*}\n\n    \\thmitem{def:symmetric_group/cycle} If there exists a finite sequence \\( k_1, \\ldots, k_m \\) of distinct numbers such that \\( \\sigma(k_m) = k_1 \\) and \\( \\sigma(k_{i+1}) = \\sigma(k_i) \\) for each \\( i < m \\), we say that the permutation is \\term{cyclic} or a \\term{cycle} of \\term{length} \\( m \\). For brevity, we denote this cycle by \\( \\cycle{k_1, \\cdots, k_m} \\).\n\n    We call cycles of length \\( 1 \\) \\term{trivial cycles} or \\term{loops} and cycles of length \\( 2 \\) --- \\term{transpositions}. Every \\hyperref[def:symmetric_group/cycle]{transposition} is an \\hyperref[def:set_with_involution]{involution}, and thus a transposition is equal to its inverse permutation.\n\n    \\thmitem{def:symmetric_group/disjoint_cycle} If \\( \\cycle{k_1, \\cdots, k_m} \\) and \\( \\cycle{s_1, \\cdots, s_l} \\) are two cycles and if the sets \\( \\set{ k_1, \\ldots, k_m } \\) and \\( \\set{ s_1, \\ldots, s_l } \\) are disjoint, we say that the cycles themselves are \\term{disjoint}.\n\n    Two disjoint cycles commute. That is,\n    \\begin{equation*}\n      \\cycle{k_1, \\cdots, k_m} \\bincirc \\cycle{s_1, \\cdots, s_l} = \\cycle{s_1, \\cdots, s_l} \\bincirc \\cycle{k_1, \\cdots, k_m}.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:cycle_transposition_decomposition}\n  Every nontrivial cycle \\( \\cycle{ k_1, \\cdots, k_m } \\) can be decomposed into the product of transpositions\n  \\begin{equation*}\n    \\cycle{ k_1, \\cdots, k_m } = \\cycle{ k_1, k_m } \\bincirc \\cycle{ k_1, k_{m-1} } \\bincirc \\cdots \\bincirc \\cycle{ k_1, k_2 }.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:symmetric_group_cardinality}\n  The \\hyperref[def:symmetric_group]{symmetric group} \\( S_n \\) has \\( n! \\) elements.\n\\end{proposition}\n\\begin{proof}\n  We use induction on \\( n \\). The case \\( n = 1 \\) is trivial. Suppose that \\( S_{n-1} \\) has \\( (n-1)! \\) elements. Then \\( S_n \\) is obtained by permuting \\( n \\) with each element of \\( S_{n-1} \\). That is,\n  \\begin{equation*}\n    S_n = \\set{ \\cycle{ k, n } \\bincirc \\sigma \\given \\sigma \\in S_{n-1} \\T{and} 1 \\leq k \\leq n }.\n  \\end{equation*}\n\n  It follows that\n  \\begin{equation*}\n    \\card(S_n) = n \\cdot \\card(S_{n-1}) = n (n-1)! = n!.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:group_action}\n  Let \\( G \\) be a \\hyperref[def:group]{group} and let \\( X \\) be an object in some \\hyperref[def:concrete_category]{concrete category} \\( \\cat{C} \\).\n\n  We will define group actions as a special case of \\hyperref[def:monoid_action]{monoid actions}, with the same remarks regarding left and right group actions.\n\n  A \\term{group action} can be defined equivalently as:\n  \\begin{thmenum}\n    \\thmitem{def:group_action/homomorphism} A \\hyperref[def:group/homomorphism]{homomorphism} from \\( G \\) to the \\hyperref[def:automorphism_group]{automorphism group} \\( \\aut(X) \\).\n\n    Right actions are homomorphisms from the \\hyperref[def:monoid/opposite]{opposite} group \\( G^{\\opcat} \\) to \\( \\aut(X) \\).\n\n    \\thmitem{def:group_action/functor} A \\hyperref[def:functor]{functor} from the \\hyperref[def:monoid_delooping]{delooping} \\( \\cat{B}_G \\) to \\( \\cat{C} \\).\n\n    Right actions are \\hyperref[rem:contravariant_functor]{contravariant functors}.\n\n    \\thmitem{def:group_action/family} An \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ \\Phi_x }_{x \\in G} \\) of \\hyperref[def:morphism_invertibility/isomorphism]{isomorphisms} of \\( X \\) such that, for every pair \\( g, h \\in G \\),\n    \\begin{equation}\\label{eq:def:group_action/family/compatibility}\\tag{\\logic{GA}}\n      \\Phi_{gh} = \\Phi_g \\bincirc \\Phi_h.\n    \\end{equation}\n\n    This defines a function \\( \\Phi: G \\times A \\to A \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  The proof of equivalence is simple; it is similar to \\fullref{def:monoid_action}.\n\\end{proof}\n\n\\begin{theorem}[Cayley's theorem]\\label{thm:cayleys_theorem}\n  Every \\hyperref[def:group]{group} \\hyperref[def:group_action]{acts} on itself via the family of functions \\( y \\mapsto x \\cdot y \\) indexed by \\( x \\). These functions are not group homomorphisms in general.\n\n  Compare this result to \\fullref{thm:monoid_is_action}.\n\\end{theorem}\n\\begin{proof}\n  Follows directly from \\fullref{thm:monoid_is_action} and \\fullref{thm:group_operation_induces_bijections}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:exponentiation_group_action}\n  The \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) act on any \\hyperref[def:group]{group} by \\hyperref[def:monoid/exponentiation]{exponentiation} via the family of function \\( g \\mapsto g^n \\) indexed by \\( n \\in \\BbbZ \\).\n\n  Compare this result to \\fullref{thm:exponentiation_monoid_action}.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:exponentiation_monoid_action}.\n\\end{proof}\n\n\\begin{definition}\\label{def:group_action_orbit}\\mcite[163]{Knapp2016BasicAlgebra}\n  The \\term{orbit} of \\( x \\) under the \\hyperref[def:group_action]{group action} \\( \\Phi: G \\to \\End(X) \\) is the set\n  \\begin{equation*}\n    \\set{ \\Phi_g(x) \\given g \\in G }.\n  \\end{equation*}\n\n  This is the set of all members of \\( X \\) \\enquote{reachable} from \\( x \\) via the action.\n\n  The relation \\( g \\sim h \\) on \\( G \\), defined to hold if \\( g \\) and \\( h \\) have the same \\hyperref[def:group_action_orbit]{orbit}, is an \\hyperref[def:equivalence_relation]{equivalence relation}. The quotient set \\( G / {\\sim} \\) is a partition of \\( G \\) into sets called \\term{orbits}.\n\\end{definition}\n\n\\begin{example}\\label{ex:plane_rotation_action_orbits}\n  Consider the action of the additive group of \\( \\BbbR \\) on \\( \\BbbR^2 \\) given by the \\hyperref[def:euclidean_transformation/rotation]{rotation} \\hyperref[def:array/matrix]{matrices}\n  \\begin{equation*}\n    \\Phi_r \\coloneqq \\begin{pmatrix}\n      \\cos(r)  & \\sin(r) \\\\\n      -\\sin(r) & \\cos(r) \\\\\n    \\end{pmatrix}\n  \\end{equation*}\n\n  Fix a nonzero vector \\( (x, y)^T \\) in \\( \\BbbR^2 \\) with norm \\( l \\). Since rotation matrices are orthogonal, they preserve norms. Furthermore, given a vector of norm \\( l \\), with the angle \\( r \\) defined via \\eqref{eq:def:angle/measure}, \\( \\Phi_r^{-1} \\) sends the vector to \\( (x, y)^T \\).\n\n  The \\hyperref[def:group_action_orbit]{orbit} of \\( (x, y)^T \\) is thus a \\hyperref[def:quadratic_plane_curve/ellipse]{circle} at the origin with radius \\( l \\).\n\\end{example}\n\n\\begin{proposition}\\label{thm:group_conjugation_action}\\mcite[165]{Knapp2016BasicAlgebra}\n  Every \\hyperref[def:group]{group} \\hyperref[def:group_action]{acts} on itself via the \\term{conjugation automorphisms} defined as\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi_g: G \\to G, \\\\\n      &\\Phi_g(h) \\coloneqq g h g^{-1}.\n    \\end{aligned}\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{definition}\\label{def:inner_and_outer_automorphisms}\\mcite[exer. 6.12.15]{Knapp2016BasicAlgebra}\n  Denote by \\( \\Phi: G \\to \\aut(G) \\) the \\hyperref[thm:group_conjugation_action]{conjugation action} on the group \\( G \\).\n\n  The \\term{inner automorphisms group} of \\( G \\) is\n  \\begin{equation*}\n    \\op{inn}(G) \\coloneqq \\set{ \\Phi_g \\given g \\in G }.\n  \\end{equation*}\n\n  The \\term{outer automorphism group} is the \\hyperref[def:group/quotient]{quotient group}\n  \\begin{equation*}\n    \\op{out}(G) \\coloneqq \\aut(G) / \\op{inn}(G).\n  \\end{equation*}\n\\end{definition}\n\\begin{defproof}\n  We will show that \\( \\op{inn}(G) \\) is a \\hyperref[thm:normal_subgroup_equivalences]{normal subgroup} of \\( \\aut(G) \\).\n\n  Fix a member \\( g \\) of \\( G \\) and define the inner automorphism\n  \\begin{equation*}\n    \\varphi(h) \\coloneqq gh^{-1}g.\n  \\end{equation*}\n\n  Let \\( \\psi \\) be an arbitrary automorphism of \\( G \\). Then\n  \\begin{equation*}\n    [\\varphi \\bincirc \\psi \\bincirc \\varphi^{-1}](h)\n    =\n    \\varphi(g \\varphi^{-1}(h) g^{-1})\n    =\n    \\varphi(g) h \\varphi(g^{-1}),\n  \\end{equation*}\n  and thus \\( \\varphi \\bincirc \\psi \\bincirc \\varphi^{-1} \\) is again an inner automorphism.\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:permutation_decomposition_existence}\n  Let \\( S_n \\) be a \\hyperref[def:symmetric_group]{symmetric group} and let \\( \\sigma \\) be a permutation in \\( S_n \\). Then there exists a finite sequence \\( c_1, \\ldots, c_m \\) of nontrivial \\hyperref[def:symmetric_group/disjoint_cycle]{disjoint cycles} such that\n  \\begin{equation*}\n    \\sigma = c_1 \\bincirc \\cdots \\bincirc c_m.\n  \\end{equation*}\n\n  The case where \\( \\sigma \\) is the identity permutation corresponds to \\( m = 0 \\).\n\n  We call this a \\term{cycle decomposition} of \\( \\sigma \\). Via \\fullref{thm:cycle_transposition_decomposition}, this permutation can further be decomposed into a composition of individual transpositions. We call the latter a \\term{transposition decomposition} of \\( \\sigma \\).\n\n  Neither decomposition is unique. Nonetheless, existence is sufficient for most practical purposes, including permutation parity defined in \\fullref{def:permutation_parity}.\n\\end{proposition}\n\\begin{proof}\n  Suppose that \\( \\sigma \\) is not the identity.\n\n  Consider the \\hyperref[def:group_action]{group action}\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi^{(\\sigma)}: \\braket{ \\sigma } \\times \\set{ 1, \\ldots, n } \\to \\set{ 1, \\ldots, n } \\\\\n      &\\Phi^{(\\sigma)}_\\sigma(k) \\coloneqq \\sigma(k)\n    \\end{aligned}\n  \\end{equation*}\n  of the \\hyperref[def:first_order_generated_substructure]{generated subgroup} \\( \\braket{ \\sigma } \\).\n\n  The \\hyperref[def:group_action_orbit]{orbit} of \\( k \\) under \\( \\Phi^{(\\sigma)} \\) is the set\n  \\begin{equation*}\n    O_\\sigma(k) \\coloneqq \\set{ \\sigma^m(k) \\given m \\in \\BbbZ }\n  \\end{equation*}\n  of all numbers reachable from \\( k \\) via iterated application of \\( \\sigma \\) or \\( \\sigma^{-1} \\). The family\n  \\begin{equation*}\n    \\set{ O_\\sigma(k) \\given k = 1, \\ldots, n }\n  \\end{equation*}\n  of orbits partitions \\( 1, \\ldots, n \\) into disjoint subsets.\n\n  Each orbit \\( O \\) has a smallest element \\( o \\); and \\( O_\\sigma(o) = O \\). This smallest element uniquely identifies a cycle\n  \\begin{equation*}\n    \\cycle{o, \\sigma(o), \\sigma^2(o), \\ldots, \\sigma^{c-1}(o)},\n  \\end{equation*}\n  where \\( c \\) is the cardinality of \\( O_\\sigma(o) \\).\n\n  Ignoring the trivial cycles, we obtain a unique set of disjoint nontrivial cycles for every permutation \\( \\sigma \\) in \\( S_n \\), which we call the \\term{cycle decomposition} of \\( \\sigma \\). Denote this set by \\( C_\\sigma \\).\n\n  We must prove that \\( C_\\sigma \\) is family of disjoint sets. Let \\( O_\\sigma(k_1) \\) and \\( O_\\sigma(k_2) \\) be two orbits.\n\n  Suppose that there exists a number \\( k \\in O_\\sigma(k_2) \\cap O_\\sigma(k_1) \\). Then there exist \\( m_1, m_2 \\leq n \\) such that \\( k = \\sigma^{m_1}(k_1) \\) and \\( k = \\sigma^{m_2}(k_2) \\). Then\n  \\begin{equation*}\n    k_1 = \\sigma^{-m_1}(k) = \\sigma^{-m_1}(\\sigma^{m_2}(k_2)) = \\sigma^{m_2 - m_1}(k_2),\n  \\end{equation*}\n  and thus \\( O_\\sigma(k_2) \\subseteq O_\\sigma(k_1) \\). We can analogously obtain the converse inclusion.\n\n  Therefore, if two orbits have a nonempty intersection, they are equal.\n\n  Finally, we will use induction on \\( m \\) to show that these cycles give us \\( \\sigma \\). The case \\( m = 0 \\) is trivial. For the inductive hypothesis, note that \\( c_1^{-1} \\sigma \\) has as cycles \\( c_2, \\ldots, c_m \\) because all the numbers in \\( c_1 \\) are fixed points of \\( c_1^{-1} \\sigma \\). Thus, the inductive hypothesis holds for \\( c_1^{-1} \\sigma \\).\n\n  From\n  \\begin{equation*}\n    c_1^{-1} \\sigma = c_2 \\bincirc \\cdots \\bincirc c_m\n  \\end{equation*}\n  it follows that\n  \\begin{equation*}\n    \\sigma = c_1 \\bincirc \\cdots \\bincirc c_m.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{lemma}\\label{thm:permutation_parity_correctness}\n  If a \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\sigma \\in S_n \\) can be decomposed into \\hyperref[def:symmetric_group/cycle]{transpositions} as both\n  \\begin{equation}\\label{eq:thm:permutation_parity_correctness/k}\n    \\sigma = \\underbrace{\\cycle{ k_1, k_2 } \\bincirc \\cycle{ k_3, k_4 } \\bincirc \\cdots \\bincirc \\cycle{ k_{2n-1}, k_{2n} }}_{n \\T*{transpositions}}\n  \\end{equation}\n  and\n  \\begin{equation}\\label{eq:thm:permutation_parity_correctness/l}\n    \\sigma = \\underbrace{\\cycle{ l_1, l_2 } \\bincirc \\cycle{ l_3, l_4 } \\bincirc \\cdots \\bincirc \\cycle{ l_{2m-1}, l_{2m} }}_{m \\T*{transpositions}},\n  \\end{equation}\n  then \\( n - m \\) is an even number.\n\\end{lemma}\n\\begin{proof}\n  We will use induction on \\( n \\). First consider the base case \\( n = 0 \\). Then \\( \\sigma \\) is the identity. Hence, every transposition in \\eqref{eq:thm:permutation_parity_correctness/l} should be present twice so that its action cancels out. Therefore, \\( m \\) is an even number.\n\n  Now suppose that the statement holds for \\( n - 1 \\). Add (compose on the right) the last transposition \\( \\cycle{ k_{2n-1}, k_{2n} } \\) of \\eqref{eq:thm:permutation_parity_correctness/k} to both \\eqref{eq:thm:permutation_parity_correctness/k} and \\eqref{eq:thm:permutation_parity_correctness/l}. The obtained permutations are obviously equal. Furthermore, since \\( \\cycle{ k_{2n-1}, k_{2n} } \\) is its own inverse, we can just as well remove \\( \\cycle{ k_{2n-1}, k_{2n} } \\) from \\eqref{eq:thm:permutation_parity_correctness/k} to obtain a decomposition into \\( n - 1 \\) (rather than \\( n + 1 \\)) transpositions.\n\n  By the inductive hypothesis, \\( (n - 1) - (m + 1) = n - m - 2 \\) is an even number. Therefore, \\( n - m \\) is also an even number.\n\\end{proof}\n\n\\begin{definition}\\label{def:permutation_parity}\n  We say that a \\hyperref[def:symmetric_group/permutation]{permutation} \\( \\sigma \\in S_n \\) is \\term{even} (resp. \\term{odd}) if a decomposition of \\( \\sigma \\) into \\hyperref[def:symmetric_group/cycle]{transpositions} has an even (resp. odd) number of transpositions.\n\n  By \\fullref{thm:permutation_decomposition_existence}, such a decomposition exists. By \\fullref{thm:permutation_parity_correctness}, all such decompositions yield the same parity even if they decompose into a differing number of transpositions.\n\n  We correspondingly define the \\term{sign} of a permutation as\n  \\begin{equation*}\n    \\begin{aligned}\n       &\\sgn: S_n \\to \\BbbZ, \\\\\n       &\\sgn(\\sigma) \\coloneqq \\begin{cases}\n        1,  &\\sigma \\T{is even} \\\\\n        -1, &\\sigma \\T{is odd}\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:alternating_group}\n  The \\term{alternating group} \\( A_n \\) on \\( n \\) letters is the subgroup of all \\hyperref[def:permutation_parity]{even permutation} in the \\hyperref[def:symmetric_group]{symmetric group} \\( S_n \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:alternating_group_cardinality}\n  The \\hyperref[def:alternating_group]{alternating group} \\( A_n \\) has \\( \\ifrac {n!} 2 \\) elements.\n\\end{proposition}\n\\begin{proof}\n  The proof is similar to that of \\fullref{thm:symmetric_group_cardinality}, but is a little different.\n\n  We use induction on \\( n \\). The case \\( n = 1 \\) is trivial. Suppose that \\( A_{n-1} \\) has \\( \\ifrac {(n-1)!} 2 \\) elements. Then\n  \\begin{equation*}\n    A_n = \\set{ \\cycle{ k, n } \\bincirc \\sigma \\given \\sigma \\in S_{n-1} \\setminus A_{n-1} \\T{and} 1 \\leq k \\leq n }.\n  \\end{equation*}\n\n  We obtain \\( A_n \\) by taking all the odd permutations in \\( S_{n-1} \\) and composing them with one new transposition. It follows that\n  \\begin{equation*}\n    \\card(A_n) = n \\cdot \\card(S_{n-1} \\setminus A_{n-1}) = n \\frac {(n-1)!} 2 = \\frac {n!} 2.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:s3_and_a3}\n  The \\hyperref[def:symmetric_group]{symmetric group} \\( S_3 \\) contains the following \\hyperref[def:symmetric_group/permutation]{permutations}:\n  \\begin{equation*}\n    S_3\n    \\coloneqq\n    \\set[\\vast]\n    {\n      \\begin{pmatrix}\n        1 & 2 & 3 \\\\\n        1 & 2 & 3\n      \\end{pmatrix},\n      \\underbrace\n        {\n          \\begin{pmatrix}\n            1 & 2 & 3 \\\\\n            2 & 1 & 3\n          \\end{pmatrix}\n        }_{\n          \\cycle{ 1, 2 }\n        },\n      \\underbrace\n        {\n          \\begin{pmatrix}\n            1 & 2 & 3 \\\\\n            2 & 3 & 1\n          \\end{pmatrix}\n        }_{\n          \\cycle{ 1, 2, 3 }\n        },\n      \\underbrace\n        {\n          \\begin{pmatrix}\n            1 & 2 & 3 \\\\\n            3 & 2 & 1\n          \\end{pmatrix}\n        }_{\n          \\cycle{ 1, 3 }\n        },\n      \\underbrace\n        {\n          \\begin{pmatrix}\n            1 & 2 & 3 \\\\\n            3 & 1 & 2\n          \\end{pmatrix}\n        }_{\n          \\cycle{ 1, 3, 2 }\n        },\n      \\underbrace\n        {\n          \\begin{pmatrix}\n            1 & 2 & 3 \\\\\n            1 & 3 & 2\n          \\end{pmatrix}\n        }_{\n          \\cycle{ 2, 3 }\n        }\n    }\n  \\end{equation*}\n\n  We can observe the following:\n  \\begin{itemize}\n    \\item The permutations \\( \\cycle{ 1, 2, 3 } \\) and \\( \\cycle{ 1, 3, 2 } \\) are inverses of each other and all other permutations are involutions.\n\n    \\item Every conjugation automorphism is unique. This can be verified explicitly. Therefore, the \\hyperref[def:inner_and_outer_automorphisms]{inner automorphism group} \\( \\op{inn}(S_3) \\) is isomorphic to \\( S_3 \\).\n\n    \\item The \\hyperref[def:alternating_group]{alternating group} \\( A_3 \\) consists of the identity and the odd-length cycles \\( (1, 2, 3) \\) and \\( (1, 3, 2) \\).\n\n    \\item When restricted to \\( A_3 \\), all conjugation automorphisms are trivial. This can be verified explicitly. Therefore, the inner automorphism group \\( \\op{inn}(A_3) \\) is trivial, and hence\n    \\begin{equation*}\n      \\aut(A_3) \\cong \\op{out}(A_3).\n    \\end{equation*}\n\n    \\item The map \\( \\sigma \\mapsto \\sigma^{-1} \\), which fixes the identity and exchanges the two other permutations, is an automorphism of \\( A_3 \\). It is distinct from the identity, hence it is an outer automorphism.\n\n    This map is given by the restriction of the conjugation \\( \\sigma \\mapsto \\cycle{1, 2} \\sigma \\cycle{1, 2} \\) to \\( A_3 \\). It is an inner automorphism of \\( S_3 \\), but an outer automorphism of \\( A_3 \\).\n  \\end{itemize}\n\\end{example}\n\n\\begin{proposition}\\label{thm:group_epimorphisms_are_surjective}\\mcite[exer. I.5.5]{MacLane1994}\n  Every \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism} in \\hyperref[def:group/category]{\\( \\cat{Grp} \\)} is \\hyperref[def:function_invertibility/surjective]{surjective}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\varphi: G \\to H \\) be an epimorphism and suppose that it is not surjective. Let \\( M \\) be the smallest normal subgroup of \\( H \\) containing \\( \\img \\varphi \\).\n\n  If \\( M \\) has index \\( 2 \\) in \\( H \\), consider the quotient map \\( \\pi: H \\to H / M \\) and the constant map \\( c(h) \\coloneqq M \\). Then\n  \\begin{equation*}\n    \\pi \\bincirc \\varphi = c \\bincirc \\varphi.\n  \\end{equation*}\n\n  Since \\( \\varphi \\) is an epimorphism, we have \\( \\pi = c \\). But we have deliberately taken \\( \\pi \\) and \\( c \\) so that \\( \\pi \\neq c \\). The obtained contradiction shows that \\( M \\) must have an index greater than \\( 2 \\).\n\n  Let \\( M \\), \\( uM \\) and \\( vM \\) be different cosets. Define \\( \\sigma: H \\to H \\) as the \\hyperref[def:symmetric_group/permutation]{permutation} on \\( H \\) that exchanges \\( xu \\) with \\( xv \\) for every \\( x \\in M \\). Define the homomorphism\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\psi: H \\to S(H) \\\\\n      &\\psi(h) \\coloneqq (x \\mapsto hx),\n    \\end{aligned}\n  \\end{equation*}\n  where \\( S(H) \\) is the \\hyperref[def:symmetric_group]{symmetric group}.\n\n  This is indeed a homomorphism by \\fullref{thm:cayleys_theorem}. By \\fullref{thm:group_conjugation_action}, another homomorphism is\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\theta: H \\to S(H) \\\\\n      &\\theta(h) \\coloneqq \\sigma^{-1} \\bincirc \\psi(h) \\bincirc \\sigma.\n    \\end{aligned}\n  \\end{equation*}\n\n  Since \\( \\sigma \\) fixes the members of \\( M \\) in-place, we have \\( \\theta(h)\\restr_M = \\psi(h)\\restr_M \\). Since \\( M \\) contains the image of \\( \\varphi \\), this implies\n  \\begin{equation*}\n    \\psi \\bincirc \\varphi = \\theta \\bincirc \\varphi.\n  \\end{equation*}\n\n  Since \\( \\varphi \\) is an epimorphism, we have \\( \\psi = \\theta \\). But we have deliberately constructed \\( \\psi \\) and \\( \\theta \\) such that \\( \\psi \\neq \\theta \\). The obtained contradiction shows that \\( \\img \\varphi \\) cannot be a strict subgroup of \\( G \\). Therefore, \\( \\varphi \\) must be surjective.\n\\end{proof}\n\n\\begin{definition}\\label{def:dynamical_system}\\mimprovised\n  Suppose that \\( \\cat{C} \\) is a \\hyperref[def:concrete_category]{concrete category} and let \\( X \\) be an object of \\( \\cat{C} \\).\n\n  A \\term{dynamical system} is a \\hyperref[def:monoid_action]{monoid action} \\( \\Phi: T \\times X \\to X \\). We call \\( X \\) the \\term{phase space} of the system. In applications, we interpret the monoid \\( T \\) as \\term{time} and consider it to be \\hyperref[rem:additive_magma]{additive}. We call \\( \\Phi \\) the \\term{evolution function} of the system.\n\n  \\begin{thmenum}\n    \\thmitem{def:dynamical_system/ifs} If \\( T \\) is either the additive monoid of the \\hyperref[def:set_of_natural_numbers]{natural numbers} or the additive group of the \\hyperref[def:set_of_integers]{integers}, we say that the dynamical system has \\term{discrete time}.\n\n    Due to \\eqref{eq:def:monoid_action/family/compatibility}, \\( \\Phi_{n+1} = \\Phi_n \\bincirc \\Phi_1 \\) for any integer \\( n \\). Using \\hyperref[rem:induction/peano_arithmetic]{natural number induction} and \\fullref{thm:def:group/negative_power}, we can show that \\( \\Phi_n = \\Phi_1^n \\) for every integer \\( n \\).\n\n    Therefore, the entire evolution function of a discrete-time dynamical system is determined by a single endofunction \\( \\varphi: X \\to X \\). For this reason, we also refer to discrete-time dynamical systems as \\term{iterated function systems}.\n\n    \\thmitem{def:dynamical_system/semiflow} If \\( T \\) is the additive monoid of \\hyperref[def:set_of_real_numbers]{real numbers}, with or without \\hyperref[def:extended_real_numbers]{an infinite element}, we say that the system is a \\term{semiflow}.\n\n    \\thmitem{def:dynamical_system/flow} If \\( T \\) is the additive group of \\hyperref[def:set_of_real_numbers]{real numbers}, we say that the system is a \\term{flow}.\n  \\end{thmenum}\n\n  We will call the system \\term{discrete} if \\( T \\) is the monoid of zero-based \\hyperref[def:set_of_natural_numbers]{natural numbers} and \\term{continuous} if \\( T \\) is the monoid of nonnegative \\hyperref[def:set_of_real_numbers]{real numbers}, with or without \\hyperref[def:extended_real_numbers]{an infinite element}.\n\n  The monoid \\( T \\) can theoretically be a \\hyperref[def:group]{group}, in which case we consider \\hyperref[def:group_action]{group actions}, however negative time is not as often needed in practice.\n\\end{definition}\n\n\\begin{definition}\\label{def:dynamical_system_trajectory}\n  Fix a \\hyperref[def:dynamical_system]{dynamical system} with evolution function \\( \\Phi: T \\times X \\to X \\).\n\n  A \\term{trajectory} in a starting at the \\term{initial state} \\( x_0 \\in X \\) is an \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ x_t }_{t \\in T} \\) obtained as\n  \\begin{equation*}\n    x_t \\coloneqq \\Phi_t(x_0).\n  \\end{equation*}\n\n  The condition \\ref{eq:def:monoid_action/family/identity} ensures that \\( \\Phi_0(x_0) = x_0 \\), and \\ref{eq:def:monoid_action/family/compatibility} ensures that\n  \\begin{equation*}\n    x_{t + s}\n    =\n    \\Phi_{t + s}(x_0)\n    =\n    \\Phi_t(x_s).\n  \\end{equation*}\n\n  For discrete dynamical systems, trajectories are sequences.\n\\end{definition}\n", "meta": {"hexsha": "da75c25e38e7799b981089966b8688b334b8441c", "size": 30565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/group_actions.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/group_actions.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/group_actions.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": 53.8116197183, "max_line_length": 615, "alphanum_fraction": 0.6729919843, "num_tokens": 10061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867729389246, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6371021321583593}}
{"text": "\\begin{quote}\n    Spectral sequences are one of those things for which anybody who is\n    anybody must suffer through. Once you've done that, it's like linear\n    algebra. You stop thinking so much about the `inner workings' later.\n\n    -- Haynes Miller\n\\end{quote}\n\\section{The spectral sequence of a filtered complex}\nOur goal will be to describe a method for computing the homology of a chain\ncomplex. We will approach this problem by assuming that our chain complex is\nequipped with a filtration; then we will discuss how to compute the associated\ngraded of an induced filtration on the homology, given the homology of the\nassociated graded of the filtration on our chain complex.\n\nWe will start off with a definition.\n\\begin{definition}\n    A \\emph{filtered chain complex} is a chain complex $C_\\ast$ along with a\n    sequence of subcomplexes $F_s C_\\ast$ such that the group $C_n$ has a\n    filtration by\n    $$F_0 C_n\\subset F_1 C_n\\subseteq \\cdots,$$\n    such that $\\bigcup F_s C_n = C_n$.\n\\end{definition}\nThe differential on $C_\\ast$ begets the structure of a chain\ncomplex on the associated graded $\\gr_s C_n = F_s C_n/F_{s-1} C_n$; in other\nwords, the differential on $C_\\ast$ respects the filtration, hence begets a\ndifferential $d:\\gr_s C_n\\to \\gr_s C_{n-1}$.\n\nThe canonical example of a filtered chain complex to keep in mind is the\nhomology of a filtered space (such as a CW-complex). Let $X$ be a filtered\nspace, i.e., a space equipped with a filtration $X_0\\subseteq X_1\\subseteq\n\\cdots$ such that $\\bigcup X_n = X$. We then have a filtration of the chain\ncomplex $C_\\ast(X)$ by the subcomplexes $C_\\ast(X_n)$.\n\nFor ease of notation, let us write\n$$E^0_{s,t} = \\gr_s C_{s+t} = F_s C_{s+t}/F_{s-1} C_{s+t},$$\nso the differential on $C_\\ast$ gives a differential $d^0:E^0_{s,t}\\to\nE^0_{s,t-1}$. A first approximation to the homology of $C_\\ast$ might therefore\nbe the homology $H_{s+t}(\\gr_s C_\\ast)$. We will denote this group by\n$E^1_{s,t}$. This is the homology of the associated graded of the filtration\n$F_\\ast C_\\ast$.\n\nWe can get an even better approximation to $H_\\ast C_\\ast$ by noticing that\nthere is a differential even on $E^1_{s,t}$. By construction, there is a short\nexact sequence of chain complexes\n$$0\\to F_{s-1} C_\\ast\\to F_s C_\\ast\\to \\gr_s C_\\ast\\to 0,$$\nso we get a long exact sequence in homology. The differential on $E^1_{s,t}$ is\nthe composite of the boundary map in this long exact sequence with the natural\nmap $H_\\ast(F_{s-1} C_\\ast)\\to H_\\ast(\\gr_{s-1} C_\\ast)$; more precisely, it is\nthe composite\n$$d^1:E^1_{s,t} = H_{s+t}(\\gr_s C_\\ast)\\xar{\\partial} H_{s+t-1}(F_{s-1}\nC_\\ast)\\to H_{s+t-1}(\\gr_{s-1}C_\\ast) = E^1_{s-1,t}.$$\nIt is easy to check that $(d^1)^2 = 0$.\n\nThis construction is already familiar from cellular chains: in this case,\n$E^1_{s,t}$ is exactly $H_{s+t}(X_{s},X_{s-1})$, which is exactly the cellular\n$s$-chains when $t=0$ (and is $0$ if $t\\neq 0$). The $d^1$ differential is\nconstructed in exactly the same way as the differential on cellular chains.\n\nIn light of this, we define $E^2_{s,t}$ to be the homology of the chain complex\n$(E^1_{\\ast,\\ast}, d^1)$; explicitly, we let\n$$E^2_{s,t} = \\ker(d^1:E^1_{s,t}\\to E^1_{s-1,t})/\\img(d^1:E^1_{s+1,t}\\to\nE^1_{s,t}).$$\nDoes this also have a differential $d^2$? The answer is yes. We will\ninductively define $E^r_{s,t}$ via a similar formula: if $E^{r-1}_{\\ast,\\ast}$\nand the differential $d^{r-1}:E^{r-1}_{s,t}\\to E^{r-1}_{s-r+1,t+r-2}$ are both\ndefined, we set\n$$E^{r}_{s,t} = \\ker(d^{r-1}:E^{r-1}_{s,t}\\to\nE^{r-1}_{s-r+1,t+r-2})/\\img(d^{r-1}:E^{r-1}_{s+r-1,t-r+2}\\to E^{r-1}_{s,t}).$$\nThe differential $d^{r}:E^{r}_{s,t}\\to E^{r}_{s-r,t+r-1}$ is defined as\nfollows. Let $[x]\\in E^r_{s,t}$ be represented by an element of $x\\in\nE^1_{s,t}$, i.e., an element of $H_{s+t}(\\gr_s C_\\ast)$. As above, the boundary\nmap induces natural maps $\\partial:H_{s+t}(\\gr_s C_\\ast)\\to H_{s+t-1}(F_{s-1}\nC_\\ast)$ and $\\partial:H_{s+t-1}(F_{s-r} C_\\ast)\\to H_{s+t-1}(\\gr_{s-r}\nC_\\ast)$. The element $\\partial x\\in H_{s+t-1}(F_{s-1} C_\\ast)$ in fact lifts\nto an element of $H_{s+t-1}(F_{s-r} C_\\ast)$. The image of this element under\n$\\partial$ inside $H_{s+t-1}(\\gr_{s-r} C_\\ast) = E^1_{s-r,t+r-1}$ begets a\nclass in $E^r_{s-r,t+r-1}$; this is the desired differential.\n\\begin{exercise}\n    Fill in the missing details in this construction of $d^r$, and show that\n    $(d^r)^2 = 0$.\n\\end{exercise}\nWe have proven most of the statements in the following theorem.\n\\begin{thm-defn}\\label{filtered-sseq}\n    Let $F_\\ast C$ be a filtered complex. Then there exist natural\n    \\begin{enumerate}\n\t\\item bigraded groups $(E^r_{s,t})_{s\\geq 0, t\\in\\Z}$ for any $r\\geq\n\t    0$, and\n\t\\item differentials $d^r:E^r_{s,t} \\to E^r_{s-r,t+r - 1}$ for any\n\t    $r\\geq 0$.\n    \\end{enumerate}\n    such that $E^{r+1}_{s,t}$ is the homology of $(E^r_{\\ast,\\ast},d^r)$, and\n    $(E^0, d^0)$ and $(E^1, d^1)$ are as above. If $F_\\ast C$ is bounded\n    below, then this spectral sequence \\emph{converges to $\\gr_\\ast\n    H_\\ast(C)$}, in the sense that there is an isomorphism:\n    \\begin{equation}\\label{convergence}\n\tE^\\infty_{s,t} \\simeq \\gr_s H_{s+t}(C).\n    \\end{equation}\n\\end{thm-defn}\nThis is called a \\emph{homology spectral sequence}. One should think of each\n$E^r_{\\ast,\\ast}$ as a ``page'', with lattice points $E^r_{s,t}$. We still need\nto describe the symbols used in the formula \\eqref{convergence}.\n\nThere is a filtration $F_s H_n(C):=\\img(H_n(F_s C) \\to H_n(C))$, and $\\gr_s\nH_\\ast(C)$ is the associated graded of this filtration. Taking formula\n\\eqref{convergence} literally, we only obtain information about the associated\ngraded of the homology of $C_\\ast$. Over vector spaces, this is sufficient to\ndetermine the homology of $C_\\ast$, but in general, one needs to solve an\nextension problem.\n\nTo define the notation $E^\\infty$ used above, let us assume that the filtration\n$F_\\ast C$ is bounded below (so $F_{-1} C = 0$). It follows that $E^0_{s,t} =\nF_s C_{s+t}/F_{s-1} C_{s+t} = 0$ for $s<0$, so the spectral sequence of\nTheorem-Definition \\ref{filtered-sseq} is a ``right half plane'' spectral\nsequence. It follows that in our example, the differentials from the group in\nposition $(s,t)$ must have vanishing $d^{s+1}$ differential.\n\nIn turn, this implies that there is a surjection $E^{s+1}_{s,t} \\to\nE^{s+2}_{s,t}$. This continues: we get surjections\n$$E^{s+1}_{s,t}\\to E^{s+2}_{s,t}\\to E^{s+3}_{s,t}\\to\\cdots,$$\nand the direct limit of this directed system is defined to be $E^\\infty_{s,t}$.\n\nFor instance, in the case of cellular chains, we argued above that $E^1_{s,t} =\nH_{s+t}(X_s, X_{s-1})$, so that $E^1_{s,t} = 0$ if $t\\neq 0$, and the $d^1$\ndifferential is just the differential in the cellular chain complex. It follows\nthat $E^2_{s,t} = H_s^{cell}(X)$ if $t=0$, and is $0$ if $t\\neq 0$. All higher\ndifferentials are therefore zero (because either the target or the source is\nzero!), so $E^r_{s,t} = E^2_{s,t}$ for every $r\\geq 2$. In particular\n$E^\\infty_{s,t} = H_s^{cell}(X)$ when $t=0$, and is $0$ if $t\\neq 0$. There are\nno extension problems either: the filtration on $X$ is bounded below, so\nTheorem-Definition \\ref{filtered-sseq} implies that $\\gr_s H_{s+0}(X) = H_s(X)\n\\simeq H_s^{cell}(X) = E^\\infty_{s,t}$.\n\n%OK, so for our theorem, we have the following picture of $E^\\infty_{\\ast,\\ast}$:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t\\gr_0 H_n(C) \\simeq E^\\infty_{0,n} & & & \\\\\n%\t& \\gr_1 H_n(C) \\simeq E^\\infty_{1,n-1} & & \\\\\n%\t& & \\gr_2 H_n(C) \\simeq E^\\infty_{2,n-2} & & \\\\\n%\t& & & \\ddots\n%    }\n%\\end{equation*}\n%Note that $\\gr_0 H_n(C) = F_0 H_n(C) = \\img(H_n(F_0 C) \\to H_n(C))$.\n%\n%Maybe you still don't get the homology of $n$ (like if $F_\\ast$ is $0$).\n%But if $F_\\ast C$ is exhaustive, then $F_\\ast H_\\ast C$ is also exhaustive (I said this on Monday).\n%With this assumption, then we get all the associated graded pieces.\nIn a very precise sense, the datum of the spectral sequence of a filtered\ncomplex $F_\\ast C_\\ast$ determines the homology of $C_\\ast$:\n\\begin{corollary}\n    Let $C\\xrightarrow{f} D$ be a map of filtered complexes.\n    Assume that the filtration on $C$ and $D$ are bounded below and exhaustive.\n    Assume also that $E^r(f)$ is an isomorphism for some $r$.\n    Then $f_\\ast : H_\\ast(C) \\to H_\\ast(D)$ is an isomorphism.\n\\end{corollary}\n\\begin{proof}\n    The map $E^r(f)$ is an isomorphism which is also also a chain map, i.e., it\n    is compatible with the differential $d^r$. It follows that $E^{r+1}(f)$ is\n    an isomorphism. By induction, we conclude that $E^\\infty_{s,t}(f)$ is an\n    isomorphism for all $s,t$. Theorem-Definitino \\ref{filtered-sseq} implies\n    that the map $\\gr_s(f_\\ast):\\gr_s H_\\ast(C) \\to \\gr_s H(D)$ is an\n    isomorphism.\n    \n    We argue by induction using the short exact sequence:\n    $$\n    0 \\to F_s H_\\ast(C) \\to F_{s+1} H_\\ast(C) \\to \\gr_{s+1} H_\\ast(C) \\to 0.\n    $$\n    We have $\\gr_0 H_n(C) = F_0 H_n(C) = \\img(H_n(F_0 C) \\to H_n(C))$, so the\n    base case follows from the five lemma. In general, $f$ induces an\n    isomorphism an isomorphism on the groups on the left (by the inductive\n    hypothesis) and right (by the above discussion), so it follows that $F_s\n    f_\\ast$ is an isomorphism by the five lemma. Since the filtration $F_\\ast\n    C_\\ast$ was exhaustive, it follows that $f_\\ast$ is an isomorphism.\n\\end{proof}\n\\subsection{Serre spectral sequence}\\label{serre-sseq}\nIn this book, we will give two constructions of the Serre spectral sequence.\nThe second will appear later. Fix a fibration $E\\xrightarrow{p} B$, with $B$ a\nCW-complex. We obtain a filtration on $E$ by taking the preimage of the\n$s$-skeleton of $B$, i.e., $E_s = p^{-1} \\sk_s B$. It follows that there is a\nfiltration on $S_\\ast(E)$ given by\n$$F_s S_\\ast (E) = \\img(S_\\ast(p^{-1} \\sk_s(B)) \\to S_\\ast E).$$\nThis filtration is bounded below and exhaustive. The resulting spectral\nsequence of Theorem-Definition \\ref{filtered-sseq} is the Serre spectral\nsequence.\n%The low terms might depend on the CW-structure, but higher terms won't.\n\nLet us be more explicit. We have a pushout square:\n\\begin{equation*}\n    \\xymatrix{\n\tE_{s-1}\\ar[r]\\ar[d] & E_s\\ar[d]\\\\\n\tB_{s-1}\\ar[r] & B_s\\\\\n\t\\coprod_{\\alpha\\in\\Sigma_s}S^{s-1}_\\alpha\\ar[r]\\ar[u] & \\coprod_{\\alpha\\in\\Sigma_s} D^s_\\alpha\\ar[u]\n    }\n\\end{equation*}\n%I can pullback $E_s$ via:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t\\coprod_{\\alpha\\in \\Sigma_s} D^s_\\alpha\\times F_\\alpha\\ar[r]\\ar[d] & E_s\\ar[d]\\\\\n%\t\\coprod_{\\alpha\\in \\Sigma_s} D^s_\\alpha\\ar[r] & B_s\n%    }\n%\\end{equation*}\nLet $F_\\alpha$ be the preimage of the center of $\\alpha$ cell. In particular,\nwe have a pushout:\n\\begin{equation*}\n    \\xymatrix{\n\tE_{s-1}\\ar[r] & E_s\\\\\n\t\\coprod_{\\alpha\\in\\Sigma_s} S^{s-1}_\\alpha\\times F_\\alpha\\ar[r]\\ar[u] & \\coprod_{\\alpha\\in\\Sigma_s} D^s_\\alpha \\times F_\\alpha\\ar[u]\n    }\n\\end{equation*}\nWe know that\n$$E^1_{s,t} = H_{s+t}(E_s,E_{s-1}) = \\bigoplus_{\\alpha\\in \\Sigma_s}\nH_{s+t}(D^s_\\alpha\\times F_\\alpha, S^{s-1}_\\alpha\\times F_\\alpha).$$\nWe can suggestively view this as $\\bigoplus_{\\alpha\\in\\Sigma_s}\nH_{s+1}((D^s_\\alpha, S^{s-1}_\\alpha)\\times F_\\alpha)$. By the K\\\"unneth\nformula (at least, if our coefficients are in a field), this is exactly\n$\\bigoplus_{\\alpha\\in\\Sigma_s} H_t(F_\\alpha)$. In analogy with our discussion\nabove regarding the spectral sequence coming from the cellular chain complex,\none would like to think of this as ``$C_s(B;H_t(F_\\alpha))$''. Sadly, there are\nmany things wrong with writing this.\n\nFor instance, suppose $B$ isn't connected. The fibers $F_\\alpha$ could have\ncompletely different homotopy types, so the symbol $C_s(B;H_t(F_\\alpha))$\ndoes not make any sense. Even if $B$ was path-connected, there would still be\nno canonical way to identify the fibers over different points. Instead, we\nobtain a functor $H_t(p^{-1}(-)):\\Pi_1(B) \\to \\mathbf{Ab}$, i.e., a ``local\ncoefficient system'' on $B$. So, the right thing to say is ``$E^2_{s,t} =\nH_s(B;\\underline{H_t(\\mathrm{fiber})})$''.\n\nTo define precisely what $H_s(B;\\underline{H_t(\\mathrm{fiber})})$ means, let us\npick a basepoint in $B$, and build the universal cover $\\widetilde{B}\\to B$.\nThis has an action of $\\pi_1(B,\\ast)$, so we obtain an action of\n$\\pi_1(B,\\ast)$ on the chain complex $S_\\ast(\\widetilde{B})$. Said differently,\n$S_\\ast(\\widetilde{B})$ is a chain complex of right modules over\n$\\Z[\\pi_1(B)]$. If $B$ is connected, a local coefficient system on $B$ is the\nsame thing as a (left) action of $\\pi_1(B)$ on $H_t(p^{-1}(\\ast))$. Then, we\ndefine a chain complex:\n$$\nS_\\ast(B;\\underline{H_t(p^{-1}(\\ast))}) = S_\\ast(\\widetilde{B})\n\\otimes_{\\Z[\\pi_1(B)]} H_t(p^{-1}(\\ast));\n$$\nthe differential is induced by the $\\Z[\\pi_1(B)]$-equivariant differential on\n$S_\\ast(\\widetilde{B})$. Our discussion above implies that the homology of this\nchain complex is the $E^2$-page.\n\nWe will always be in the case where that local system is trivial, so that\n$H_\\ast(B;\\underline{H_\\ast(p^{-1}(\\ast))})$ is just\n$H_\\ast(B;H_\\ast(p^{-1}(\\ast)))$. For instance, this is the case if $\\pi_1(B)$\nacts trivially on the fiber. In particular, this is the case if $B$ is simply\nconnected. \n", "meta": {"hexsha": "f48b7bfbf08c36862ca22cfd0412d1dae64436f4", "size": 13068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-61-serre-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-61-serre-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-61-serre-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": 52.4819277108, "max_line_length": 133, "alphanum_fraction": 0.6826599327, "num_tokens": 4578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.6371021244946543}}
{"text": "\\documentclass[fleqn]{article}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath}\n\\usepackage[colorlinks=true]{hyperref}\n\\usepackage{tikz}\n\\usetikzlibrary{calc,patterns,angles,quotes}\n\n\\begin{document}\n\\begin{center}\n  {\\bfseries Solution to assignment \\#2}\\\\\n  Introduction to GR, 2020 Fall\\\\\n  International Centre for Theoretical Sciences\\\\\n  Instructor: Prof. Bala Iyer, Tutor: Md Arif Shaikh\\footnote{\\href{mailto: arif.shaikh@icts.res.in}{arif.shaikh@icts.res.in}}\\\\\n  % Due on October 04, 2020 11:59 PM.\n\\end{center}\n\\hrule\n\n\n\\section{Parallel transport along $r=$ constant line on the surface of a cone}\n\n\\begin{center}\n  \\begin{tikzpicture}\n  \\draw[cyan] (0,3) ellipse (2cm and 0.5cm);\n  \\draw[->] (0, 0) -- (0, 4) node[above] {$z$};\n  \\draw[->] (0, 0) -- (4, 0) node[right] {$y$};\n  \\draw[->] (0, 0) -- (-3, -2) node[left] {$x$};\n  \\draw[cyan] (0, 0) -- (2, 3);\n  \\draw[cyan] (0, 0) -- (-2, 3);\n  \\draw (0, 0.5) arc (90:110:1) node[left] {$\\alpha$} ;\n  \\draw[orange] (0, 1.5) ellipse (1cm and 0.25cm);\n  \\draw[fill=red] (0.5, 1.28) circle (0.05cm);\n  \\draw (0, 1.5) -- (0.5, 1.28) node[right] {$(r, \\phi)$};\n  \\draw (0, 1.5) -- (-3, -0.5);\n  \\draw (0, 1.5) -- (4, 1.5);\n  \\draw[red] (0.5, 1.28) arc (-80:-100:2.3) node[below] {$\\phi$}; \n\\end{tikzpicture}\n\\end{center}\n\nWe have a cone with opening angle $2\\alpha$ embedded in the 3-dimensional flat space. $r$ is the distance measured from the apex. A constant $r$ line on the surface of the cone would be parameterised by the angle $\\phi$. The 3-dimensional flat metric in spherical polar coordinate is given by\n\n\\begin{equation}\n  \\label{eq:3-d-flat-metric}\n  ds^2_{3d} = dr^2 + r^2d\\theta^2 + r^2\\sin^2\\theta d\\phi^2.\n\\end{equation}\n$\\theta$ is the angle w.r.t to the $z$-axis. On the surface of the cone, $\\theta=\\alpha=$ constant. Thus the metric on the surface of the cone becomes\n\\begin{equation}\n  \\label{eq:2-d-metric-on-cone}\n  \\boxed{ds^2 = dr^2 + r^2\\sin^2\\alpha d\\phi^2.}\n\\end{equation}\n\n\\noindent\\fbox{\\parbox{\\textwidth}{{\\bfseries What is parallel transport of a tensor?}\n    Parallel transport is defined in the following way: A tensor field $T^{\\mu...}_{\\nu...}$  is said to be {\\itshape parallel transported} along a curve $\\gamma:=x^\\alpha(\\lambda)$ if the covariant derivative of the tensor field along the curve vanishes: $D_\\lambda T^{\\mu...}_{\\nu...} = u^\\eta \\nabla_\\eta T^{\\mu...}_{\\nu...}= 0$, where $u^\\eta = dx^\\eta/d\\lambda$.}}\n\n\\vspace{0.5cm}\n\nIn the given problem we are asked to compute the rotation of a vector $V^\\mu$ when it is parallel transported along the $r=$ constant line from $\\phi=0$ to $\\phi=2\\pi$. Thus the curve $\\gamma$ is represented by $x^\\mu(\\lambda) = (r_0, \\phi(\\lambda))$. The condition for parallel transport of $V^\\mu$ along $\\gamma$ then becomes\n\n\\begin{equation}\n  \\label{eq:parallel-transport-along-r-constant}\n  u^\\mu\\nabla_\\mu V^\\nu = 0 \\to \\dot{\\phi}\\nabla_\\phi V^\\mu = 0\\to \\nabla_\\phi V^\\mu = 0 \\to \\boxed{\\partial_\\phi V^\\mu + \\Gamma^\\mu_{\\phi \\nu} V^\\nu = 0}.\n\\end{equation}\n\nTo find out the Christofell symbols we use the geodesic equations. The geodesic equations could be obtained from the Lagrangian $L = (1/2)g_{\\mu\\nu}\\dot{x}^\\mu\\dot{x}^\\nu$ where $\\dot{x}^\\mu = dx^\\mu/d\\tau$ (we take $\\lambda = \\tau$ the propertime). The geodesic e.o.m is given by\n\\begin{equation}\n  \\label{eq:geodesic-eom}\n  \\frac{d}{d\\tau}\\left(\\frac{\\partial L}{\\partial \\dot{x^\\mu}}\\right) - \\frac{\\partial L}{\\partial x^\\mu} = 0\n\\end{equation}\n\nWith the Lagrangian given by\n\\begin{equation}\n  \\label{eq:Lagrangian}\n  L = \\frac{1}{2}(\\dot{r}^2 + r^2\\sin^2\\alpha\\dot{\\phi}^{2})\n\\end{equation}\nThe e.o.m for $r$ becomes\n\\begin{equation}\n  \\label{eq:eom-r}\n  \\ddot{r} - r\\sin^2\\alpha \\dot{\\phi}^{2} = 0,\n\\end{equation}\nwhich provides $\\Gamma^{r}_{\\phi\\phi} = - r\\sin^2\\alpha$.\nSimilarly e.o.m for $\\phi$ is given by\n\\begin{equation}\n  \\label{eq:eom-phi}\n  \\ddot{\\phi} + \\frac{2}{r}\\dot{r}\\dot{\\phi} = 0,\n\\end{equation}\nwhich provides $\\Gamma^{\\phi}_{r\\phi} = \\Gamma^{r}_{\\phi r} = \\frac{1}{r}$. Thus we have\n\\begin{equation}\n  \\label{eq:Christofell-symbols}\n  \\boxed{\\Gamma^{r}_{\\phi\\phi} = - r\\sin^2\\alpha,\\qquad \\Gamma^{\\phi}_{r\\phi} = \\Gamma^{r}_{\\phi r} = \\frac{1}{r}}.\n\\end{equation}\n\nThus Eq. (\\ref{eq:parallel-transport-along-r-constant}) becomes \n\\begin{equation}\n  \\label{eq:parallel-transport}\n  \\partial_\\phi V^{\\mu} + \\Gamma^{\\mu}_{\\phi\\nu}V^\\nu = 0.\n\\end{equation}\n\nFor $\\mu=r,\\phi$ this gives the following equations\n\\begin{equation}\n  \\label{eq:r-phi}\n  \\partial_\\phi V^{r} + \\Gamma^{r}_{\\phi\\nu}V^\\nu = 0,\\qquad\n  \\partial_\\phi V^{\\phi} + \\Gamma^{\\phi}_{\\phi\\nu}V^\\nu = 0.\n\\end{equation}\nwhich using Eq.~\\eqref{eq:Christofell-symbols} becomes\n\\begin{equation}\n  \\label{eq:r-phi-2}\n \t \\partial_\\phi V^{r} + \\Gamma^{r}_{\\phi\\nu}V^\\nu = 0,\\qquad\n  \\partial_\\phi V^{\\phi} + \\Gamma^{\\phi}_{\\phi\\nu}V^\\nu = 0.\n\\end{equation}\n\nor after differentiating with respect to $\\phi$,\n\\begin{equation}\n  \\label{eq:r-phi-3}\n  \\partial_\\phi^2 V^r + \\sin^2\\alpha V^r = 0,\\qquad   \\partial_\\phi^2 V^\\phi + \\sin^2\\alpha V^\\phi = 0\n\\end{equation}\nWhich has the following general solutions\n\\begin{equation}\n  \\label{eq:r-phi-solution}\n  \\boxed{V^r = A^r_1 \\sin(\\sin\\alpha \\phi) + A^r_2 \\cos(\\sin\\alpha \\phi),\\quad V^\\phi = A^\\phi_1 \\sin(\\sin\\alpha \\phi) + A^\\phi_2 \\cos(\\sin\\alpha \\phi)}.\n\\end{equation}\nDenoting the values of the components at $\\phi=0$ with suffix `0' the solutions becomes\n\n\\begin{equation}\n  \\label{eq:r-phi-solution-2}\n  \\boxed{V^r = A^r_1 \\sin(\\sin\\alpha \\phi) + V^r_0 \\cos(\\sin\\alpha \\phi),\\quad V^\\phi = A^\\phi_1 \\sin(\\sin\\alpha \\phi) + V^\\phi_0 \\cos(\\sin\\alpha \\phi)}.\n\\end{equation}\nNow, the constants are not all independent, there are only two independent constants. Thus the other two components could be written in terms of the $A^r_0$ and $A^\\phi_0$ using equation \\eqref{eq:r-phi-2}. This provides\n\\begin{equation}\n  \\label{eq:constants}\n  A^r_1 = r \\sin\\alpha V^\\phi_0,\\quad A^\\phi_1 = - V^r_0/r\\sin\\alpha.\n\\end{equation}\nThus finally we have the solutions\n\\begin{equation}\n  \\label{eq:r-phi-solution-final}\n  \\boxed{V^r =  V^\\phi_0 r \\sin\\alpha \\sin(\\phi\\sin\\alpha) + V^r_0 \\cos(\\phi\\sin\\alpha),\\quad V^\\phi =  - \\frac{V^r_0}{r\\sin\\alpha} \\sin(\\phi\\sin\\alpha) + V^\\phi_0 \\cos(\\phi\\sin\\alpha)}.\n\\end{equation}\nNow we move to a orthonormal set of basis given by $E_r = \\partial_r, E_\\phi = (1/\\sin\\alpha)\\partial_\\phi$. In this basis, we can rewrite the components of the $V$ as\n\\begin{equation}\n  \\label{eq:V-in-orthonormal}\n  \\hat{V}^r = V^r,\\quad \\hat{V}^\\phi = r\\sin\\alpha V^\\phi.\n\\end{equation}\nThus in this basis, we have the transformation\n\\begin{equation}\n  \\label{eq:transformation-orthonormal}\n  \\boxed{\\begin{bmatrix}\n      \\hat{V}^r \\\\\n      \\hat{V}^\\phi\n    \\end{bmatrix} =\n    \\begin{bmatrix}\n      \\cos(\\phi\\sin\\alpha) & \\sin(\\phi\\sin\\alpha)\\\\\n      -\\sin(\\phi\\sin\\alpha) & \\cos(\\phi\\sin\\alpha)\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      \\hat{V}^r_0 \\\\\n      \\hat{V}^\\phi_0\n    \\end{bmatrix}}\n\\end{equation}\nThus the components are rotated by an angle $\\beta = \\phi\\sin\\alpha$. For $\\alpha = 2\\pi$ this rotation equals $\\beta = 2\\pi\\sin\\alpha$.\n\n\\end{document}", "meta": {"hexsha": "6a69e90296a8be5d3ef67068ce65f70623b1d901", "size": 7108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sol-assignment-2/Solution_assignment_2_icts_igr_2020_fall.tex", "max_stars_repo_name": "mdarifshaikh/GR-Fall-2020-ICTS", "max_stars_repo_head_hexsha": "4b651c965b58d899a98f6ebe838a6bc30c3c37ef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sol-assignment-2/Solution_assignment_2_icts_igr_2020_fall.tex", "max_issues_repo_name": "mdarifshaikh/GR-Fall-2020-ICTS", "max_issues_repo_head_hexsha": "4b651c965b58d899a98f6ebe838a6bc30c3c37ef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sol-assignment-2/Solution_assignment_2_icts_igr_2020_fall.tex", "max_forks_repo_name": "mdarifshaikh/GR-Fall-2020-ICTS", "max_forks_repo_head_hexsha": "4b651c965b58d899a98f6ebe838a6bc30c3c37ef", "max_forks_repo_licenses": ["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.425, "max_line_length": 369, "alphanum_fraction": 0.6551772651, "num_tokens": 2722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.637102122578728}}
{"text": "%% LyX 2.3.2-1 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\\usepackage[T1]{fontenc}\n\\usepackage[latin9]{luainputenc}\n\\usepackage{babel}\n\\usepackage{array}\n\\usepackage{textcomp}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[unicode=true]\n {hyperref}\n\n\\makeatletter\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.\n%% Because html converters don't know tabularnewline\n\\providecommand{\\tabularnewline}{\\\\}\n\n\\makeatother\n\n\\begin{document}\n\\title{Chapter 7: Chi-square Test}\n\\maketitle\n\n\\section{Example}\n\\begin{enumerate}\n\\item $H_{0}:$ The die is fair $\\left(p=\\frac{1}{6}\\right)$\n\\item $H_{1}:$ The die is unfair $\\left(p\\neq\\frac{1}{6}\\right)$\n\\item At $\\alpha=0.05$, critical value = $\\chi_{\\alpha;m-t-1}^{2}$.\n\\item ~\n\\begin{align*}\n\\chi_{0.05;6-0-1}^{2} & =\\chi_{0.05;5}^{2}\\\\\n & =11.070\n\\end{align*}\n\\item Rejection region: (remember Chi-square distribution does NOT have\na negative region)\n\\[\n\\chi^{2}>11.07\n\\]\n\\item %\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\\hline \nNumber & 1 & 2 & 3 & 4 & 5 & 6 & Total\\tabularnewline\n\\hline \n\\hline \n$O_{i}$ & 89 & 113 & 98 & 104 & 117 & 79 & 600\\tabularnewline\n\\hline \n$E_{i}$ & 100 & 100 & 100 & 100 & 100 & 100 & 600\\tabularnewline\n\\hline \n$O_{i}-E_{i}$ & -11 & 13 & -2 & -4 & 17 & -21 & \\tabularnewline\n\\hline \n$\\left(O_{i}-E_{i}\\right)^{2}$ & 121 & 169 & 4 & 16 & 289 & 441 & \\tabularnewline\n\\hline \n$\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$ & 1.21 & 1.69 & 0.04 & 0.16 & 2.89 & 4.41 & 10.40\\tabularnewline\n\\hline \n\\end{tabular}\n\\item Since $\\chi^{2}=10.40<11.07$, we failed to reject $H_{0}$ at 5\\%\nsignificance level. Hence, we do not have enough evidence to conclude\nthat the observed frequencies are significantly different from those\nexpected of a fair die.\n\\end{enumerate}\n\n\\section{Example}\n\nSince every city have equal sales potential, therefore, each sale\nshould be $\\frac{\\sum x}{n}$, which is the mean.\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Claim: Each of the seven cities have equal sales potential. $\\left(H_{0}\\right)$\n\\item Opposite: Each of the seven cities do not have equal sales potential.\n$\\left(H_{1}\\right)$\n\\item $H_{0}:A=B=C=D=E=F=G$\n\\item $H_{1}:A\\neq B\\neq C\\neq D\\neq E\\neq F\\neq G$\n\\end{enumerate}\n\\item Find the critical value\n\\begin{enumerate}\n\\item $\\alpha=0.05$\n\\item $\\chi_{0.05;7-1}^{2}=\\chi_{0.05;6}^{2}=12.592$\n\\end{enumerate}\n\\item Find the rejection region\n\\begin{enumerate}\n\\item $\\chi^{2}>12.592$\n\\end{enumerate}\n\\item %\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\hline \nCity & A & B & C & D & E & F & G & Total\\tabularnewline\n\\hline \n\\hline \n$O_{i}$ & 120 & 185 & 260 & 190 & 210 & 175 & 260 & \\tabularnewline\n\\hline \n$E_{i}$ & 200 & 200 & 200 & 200 & 200 & 200 & 200 & 1400\\tabularnewline\n\\hline \n$\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$ & $\\frac{\\left(120-200\\right)^{2}}{200}=32$ & $\\frac{\\left(185-200\\right)^{2}}{200}=1.125$ & $\\frac{\\left(260-200\\right)^{2}}{200}=18$ & $\\frac{\\left(190-200\\right)^{2}}{200}=0.5$ & $\\frac{\\left(210-200\\right)^{2}}{200}=0.5$ & $\\frac{\\left(175-200\\right)^{2}}{200}=3.125$ & $\\frac{\\left(260-200\\right)^{2}}{200}=18$ & 73.25\\tabularnewline\n\\hline \n\\end{tabular}\n\\item Since $\\chi^{2}=73.25>12.592$, we reject $H_{0}$and do not have\nenough evidence to conclude that each of the seven cities have equal\nsales potential.\n\\end{enumerate}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Claim: The local hospital follows the national pattern. $\\left(H_{0}\\right)$\n\\item Oppo: The local hospital do not follow the national pattern. $\\left(H_{1}\\right)$\n\\end{enumerate}\n\\item Find the rejection region\n\\begin{enumerate}\n\\item $\\alpha=0.05$\n\\item $\\chi_{0.05;7-1}^{2}=\\chi_{0.05;6}^{2}=12.592$\n\\item Rejection region: $\\chi^{2}>12.592$\n\\end{enumerate}\n\\item Find the Chi-square score\n\\item %\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\hline \nNumber of times admitted & 1 & 2 & 3 & 4 & 5 & 6 & 7 & Total\\tabularnewline\n\\hline \n\\hline \n$O_{i}$ & 165 & 79 & 50 & 44 & 32 & 20 & 10 & 400\\tabularnewline\n\\hline \n$E_{i}$ & 400{*}40\\%=160 & 80 & 56 & 40 & 32 & 24 & 8 & \\tabularnewline\n\\hline \n$\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$ & $\\frac{\\left(165-160\\right)^{2}}{160}$ & $\\frac{\\left(79-80\\right)^{2}}{80}$ & $\\frac{\\left(50-56\\right)^{2}}{56}$ & $\\frac{\\left(44-40\\right)^{2}}{40}$ & $\\frac{\\left(32-32\\right)^{2}}{32}$ & $\\frac{\\left(20-24\\right)^{2}}{24}$ & $\\frac{\\left(10-8\\right)^{2}}{8}$ & 2.378\\tabularnewline\n\\hline \n\\end{tabular}\n\\item Since $\\chi^{2}=2.378<12.592$, we failed to reject $H_{0}$. Hence,\nwe conclude that the local hospital follows the national pattern.\n\\end{enumerate}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Claim: The results support the theory $\\left(H_{0}\\right)$\n\\item Opposite: The results do not support the theory $\\left(H_{1}\\right)$\n\\end{enumerate}\n\\item Find the rejection region\n\\begin{enumerate}\n\\item $\\chi_{0.05;3-1}^{2}=5.991$\n\\item $\\chi^{2}>5.991$\n\\end{enumerate}\n\\item Calculate the Chi-score\n\\begin{enumerate}\n\\item %\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline \nColor & $O_{i}$ & $E_{i}$ & $\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$ & \\tabularnewline\n\\hline \n\\hline \nRed & 84 & 83.25 & 0.00676 & \\tabularnewline\n\\hline \nBlue & 92 & 83.25 & 0.91967 & \\tabularnewline\n\\hline \nPurple & 157 & 166.5 & 0.54204 & \\tabularnewline\n\\hline \n & 333 &  & 1.46847 & \\tabularnewline\n\\hline \n\\end{tabular}\n\\end{enumerate}\n\\item $\\chi^{2}=1.46847<5.991$. We failed to reject $H_{0}$ at $\\alpha=0.05$\nand conclude that the result support the genetic theory.\n\\end{enumerate}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Claim: The random number generator is working incorrectly. $H_{1}$\n\\item Hypo: The random number generator is working correctly. $H_{0}$\n\\end{enumerate}\n\\item The critical value\n\\begin{enumerate}\n\\item $\\chi_{0.05;6-1}^{2}=11.070$\n\\item Rejection region: $\\chi^{2}>11.070$\n\\end{enumerate}\n\\item Find the test statistic\n\\begin{enumerate}\n\\item %\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline \nInterval & $O_{i}$ & Probability, $P_{i}$ & $E_{i}=500*P_{i}$ & $\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$\\tabularnewline\n\\hline \n\\hline \n$s<4$ & 10 & $P\\left(Z<\\frac{4-6}{1}\\right)=P\\left(Z<\\text{\\textminus}2\\right)=0.02275$ & 11.375 & 0.16621\\tabularnewline\n\\hline \n$4\\le s<5$ & 75 & 0.13595 & 67.975 & 0.74601\\tabularnewline\n\\hline \n$5\\le s<6$ & 163 & 0.34130 & 170.65 & 0.34294\\tabularnewline\n\\hline \n$6\\le s<7$ & 174 & 0.34130 & 170.65 & 0.06576\\tabularnewline\n\\hline \n$7\\le s<8$ & 66 & 0.13595 & 67.975 & 0.05738\\tabularnewline\n\\hline \n$s\\ge8$ & 12 & 0.02285 & 11.375 & 0.3434\\tabularnewline\n\\hline \nTotal &  & 1.0000 & 500 & \\textbf{1.39264}\\tabularnewline\n\\hline \n\\end{tabular}\n\\item Note: For the probability, use the Z-score\n\\[\nP\\left(s>\\bar{x}\\right)=P\\left(Z>\\frac{\\bar{x}-\\mu}{\\sigma}\\right)\n\\]\n\\item Use \\href{http://onlinestatbook.com/2/calculators/normal_dist.html}{Normal Distribution Calculator from OnlineStatBook}\nto quickly calculate without converting to normal.\n\\end{enumerate}\n\\item Conclusion\n\\begin{enumerate}\n\\item Since $\\chi_{2}=1.39264<11.070$, we failed to reject $H_{0}$, and\nhence conclude that the random number generator is working correctly.\n\\end{enumerate}\n\\end{enumerate}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Claim: The distribution of X is $B\\left(3,0.25\\right)$ $\\left(H_{0}\\right)$\n\\item Oppo: The distribution of X is not $B\\left(3,0.25\\right)$ $\\left(H_{1}\\right)$\n\\end{enumerate}\n\\item Find the critical value\n\\[\n\\alpha=0.01\n\\]\n\n\\begin{enumerate}\n\\item Critical value\n\\begin{align*}\n\\chi_{\\alpha;m-t-1}^{2} & =\\chi_{0.01;3-0-1}^{2}\\\\\n & =\\chi_{0.01;2}^{2}\\\\\n & =9.210\n\\end{align*}\n\\end{enumerate}\n\\item Rejection region\n\\[\n\\chi^{2}>9.210\n\\]\n\n\\begin{enumerate}\n\\item If this is true, the probability distribution of X is \n\\[\nP\\left(X=x\\right)=^{3}C_{x}\\left(0.25\\right)^{x}0.75^{3-x}\n\\]\n\\end{enumerate}\n\\item %\n\\begin{tabular}{|c|c|c|c|c|c|}\n\\hline \nX & $O_{i}$ & Probability, $p_{i}$ & $E_{i}=64p_{i}$ & $\\frac{\\left(O_{i}-E_{i}\\right)^{2}}{E_{i}}$ & Total\\tabularnewline\n\\hline \n\\hline \n0 & 21 & $\\frac{21}{21+31+12+0}=0.4219$ & 27 & 1.333 & \\tabularnewline\n\\hline \n1 & 31 & 0.4219 & 27 & 0.5926 & \\tabularnewline\n\\hline \n2,3 & 12 & 0.1563 & 10 & 0.4 & 2.3259\\tabularnewline\n\\hline \n\\end{tabular}\n\\begin{enumerate}\n\\item $p_{0}=^{3}C_{0}*\\left(0.25\\right)^{0}*\\left(0.75\\right)^{3}=0.4219$\n\\item $p_{1}=^{3}C_{1}*\\left(0.25\\right)^{1}*\\left(0.75\\right)^{2}=0.4219$\n\\item $p_{2+3}=^{3}C_{2}*\\left(0.25\\right)^{2}*\\left(0.75\\right)^{1}+{}^{3}C_{3}*\\left(0.25\\right)^{3}=0.1563$\n\\end{enumerate}\n\\item Since $\\chi^{2}=2.3259<9.210.$ We failed to reject $H_{0}$, and\nhence do not have enough evidence to show that the recorded data do\nnot fit $B\\left(3,0.25\\right)$.\n\\end{enumerate}\n\n\\section{Example}\n\nNote: We should not round it from 2.02 to 2.00, oterhwise it will\nbe inaccurate during exams.\n\n\\section{Example}\n\n\\subsection{Extra Notes}\n\nBy following the probability multiplication rule, if they are independent,\nthe expected frequency for a field in a two-way table will be\n\\begin{enumerate}\n\\item Proportion probability of something happening in the row, multiple\nby the proportion probability of something happening in a column (to\nget row {*} column proportion) and then multipled by the sample size.\n\\item Eg:\n\\[\n1000\\left(sample\\right)*\\left(\\frac{100}{1000}\\left(row\\right)*\\frac{100}{1000}\\left(column\\right)\\right)=10\\left(expected\\right)\n\\]\n\\end{enumerate}\n\n\\subsection{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item The number of accidents depend on the visits by the inspector. $\\left(H_{0}\\right)$\n\\item The number of accidents do not depend on the visits by the inspector.\n$\\left(H_{1}\\right)$\n\\end{enumerate}\n\\item Critical value\n\\begin{align*}\n\\chi_{0.05;\\left(4-1\\right)\\left(2-1\\right)}^{2} & =\\chi_{0.05;3}^{2}\\\\\n & =7.815\n\\end{align*}\n\n\\begin{enumerate}\n\\item Note : $D.O.F.=\\left(Row-1\\right)\\left(Column-1\\right)$\n\\item ~\\includegraphics[width=0.8\\paperwidth,height=0.8\\textheight,keepaspectratio]{lyx-img/c7q8expected}\n\\end{enumerate}\n\\item Rejection region\n\\[\n\\chi^{2}>7.815\n\\]\n\\item Find the test-statistic\n\\begin{align*}\n\\chi^{2} & =\\frac{\\left(33-27.778\\right)^{2}}{27.778}+\\frac{\\left(8-13.889\\right)^{2}}{13.889}+\\frac{\\left(5-5.556\\right)^{2}}{5.556}+\\frac{\\left(4-2.778\\right)^{2}}{5.556}+\\frac{\\left(67-72.222\\right)^{2}}{72.222}+\\frac{\\left(42-36.111\\right)^{2}}{36.111}+\\frac{\\left(15-14.444\\right)^{2}}{14.444}+\\frac{\\left(6-7.222\\right)^{2}}{7.222}\\\\\n & =5.3692\n\\end{align*}\n\\item Conclusion\n\\begin{enumerate}\n\\item Since $\\chi^{2}=5.3692<7.815$. We failed to reject $H_{0}$, and\nhence do not have enough evidence to conclude that the number of accidents\ndo not depend on the visits by the inspector.\n\\end{enumerate}\n\\end{enumerate}\n\n\\section{Example}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item Hypo: The coin is fair $\\left(H_{1}\\right)$\n\\item Oppo: The coin is unfair $\\left(H_{0}\\right)$\n\\end{enumerate}\n\\item Critical value at $\\alpha=0.05$\n\\begin{enumerate}\n\\item Critical value: $\\chi_{0.05;2-0-1}^{2}=\\chi_{0.05;1}^{2}=3.841$\n\\end{enumerate}\n\\item Rejection range: $\\chi^{2}>3.841$\n\\item Test-statistics\n\\begin{align*}\n\\chi^{2} & =\\sum_{i=1}^{m}\\frac{\\left(\\left|O_{i}-E_{i}\\right|-0.5\\right)^{2}}{E_{i}}\\\\\n & =\\frac{\\left(\\left|115-100\\right|-0.5\\right)^{2}}{100}+\\frac{\\left(\\left|85-100\\right|-0.5\\right)^{2}}{100}\\\\\n & =4.205\n\\end{align*}\n\\end{enumerate}\n\n\\section{Example}\n\\begin{enumerate}\n\\item Hypothesis\n\\begin{enumerate}\n\\item $\\left(H_{0}\\right)$ There is no association between taking the new\ndrug and attack by the disease\n\\item $\\left(H_{1}\\right)$ There is an association between taking the new\ndrug and attack by the disease\n\\end{enumerate}\n\\item Critical value\n\\begin{enumerate}\n\\item $\\chi_{0.05;\\left(2-1\\right)\\left(2-1\\right)}^{2}=\\chi_{0.05;1}^{2}=3.841$\n\\end{enumerate}\n\\item Rejection range\n\\begin{enumerate}\n\\item $\\chi^{2}>3.841$\n\\end{enumerate}\n\\item Test-statistic (apply Yate's correction because $D.O.F.=1$)\n\\begin{enumerate}\n\\item ~%\n\\begin{tabular}{|>{\\centering}p{0.8\\textwidth}|c|c|c|}\n\\hline \n & Drugged & Drugless & Total row\\tabularnewline\n\\hline \n\\hline \nAttacked & 24 & 32 & 56\\tabularnewline\n\\hline \nExpected & (35.47) & (20.53) & \\tabularnewline\n\\hline \nNot attacked & 52 & 12 & 64\\tabularnewline\n\\hline \nExpected & (40.53) & (23.47) & \\tabularnewline\n\\hline \nTotal column & 76 & 44 & 120\\tabularnewline\n\\hline \n\\end{tabular}\n\\item $\\chi^{2}=\\frac{\\left(\\left|24-35.47\\right|-0.5\\right)^{2}}{35.47}+\\frac{\\left(\\left|32-20.53\\right|-0.5\\right)^{2}}{20.53}+\\frac{\\left(\\left|52-40.53\\right|-0.5\\right)^{2}}{40.53}+\\frac{\\left(\\left|12-23.47\\right|-0.5\\right)^{2}}{23.47}=17.351$\n\\end{enumerate}\n\\item Conclusion\n\\begin{enumerate}\n\\item Since $\\chi^{2}=17.351>3.841$, we reject $H_{0}$. Therefore we have\nenough evidence to conclude that there is an association between taking\nthe new drug and attack by the disease.\n\\end{enumerate}\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "ae7275f6df93e348804e14a259c3728be78f1df9", "size": 13079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "y2s1/statistics-ii/lectures/c7-chi-square.tex", "max_stars_repo_name": "ouldevloper/university", "max_stars_repo_head_hexsha": "4bb4a7e86912b46aa625900d2985b4d1e436cf4e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-06-22T14:29:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T16:58:12.000Z", "max_issues_repo_path": "y2s1/statistics-ii/lectures/c7-chi-square.tex", "max_issues_repo_name": "ouldevloper/university", "max_issues_repo_head_hexsha": "4bb4a7e86912b46aa625900d2985b4d1e436cf4e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-06-30T06:38:00.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-08T06:37:57.000Z", "max_forks_repo_path": "y2s1/statistics-ii/lectures/c7-chi-square.tex", "max_forks_repo_name": "ouldevloper/university", "max_forks_repo_head_hexsha": "4bb4a7e86912b46aa625900d2985b4d1e436cf4e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-04-04T12:59:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T22:44:58.000Z", "avg_line_length": 32.9445843829, "max_line_length": 383, "alphanum_fraction": 0.671534521, "num_tokens": 5055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6370770848828544}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Lagrangians and Coordinate Transformations}\n\\begin{p}\nIf we transform $x, y$ into polar coordinates, what happens to the principle of least action? What do Lagrange’s equations become for a particle in a two-dimensional potential $U(x,y)$, now using polar coordinates. What are the generalized forces and generalized momenta? \n\\end{p}\n\\begin{s}\nSince the Lagrangian is invariant of the choice of coordinates, nothing happens; the principle of least action still holds (the Lagrangian and action integral are equivalent between the two coordinate systems):\n\\[S[r, \\theta] = \\int_{t_1}^{t_2}\\LL(r, \\dot{r}, \\theta, \\dot{\\theta}, t)dt = \\int_{t_1}^{t_2} \\LL(x, \\dot{x}, y, \\dot{y}, t)dt = S[x, y]\\]\nUsing the fact that $\\v{r} = r\\rhat$ and $\\dot{\\v{r}} = \\dot{r}\\rhat + r\\dot{\\phi}\\phihat$ The Lagrangian becomes:\n\\[\\LL = T - U = \\frac{1}{2}m\\dot{\\v{r}}^2 - U(x,y) = \\frac{1}{2}m(\\dot{r}^2 + r^2\\dot{\\phi}^2) - U(r, \\theta)\\]\nSo Lagrange's equations become:\n\\[\\dpd{\\LL}{r} = \\dod{}{t}\\dpd{\\LL}{\\dot{r}} \\implies -\\dpd{U}{r} + mr\\dot{\\phi}^2 = m\\ddot{r}\\]\nSo the generalized force is $-\\dpd{U}{r} + mr\\dot{\\phi}^2$ and the generalized momentum is $m\\dot{r}$.\n\\[\\dpd{\\LL}{\\phi} = \\dod{}{t}\\dpd{\\LL}{\\dot{\\phi}} \\implies -\\dpd{U}{\\phi} = mr^2\\ddot{\\phi}  \\]\nSo the generalized force is $-\\dpd{U}{\\phi}$ (which is just the torque!) and the generalized momentum is $mr^2\\dot{\\phi}$ (which is the angular momentum!).\n\\end{s}\n\n\\begin{p}\nWrite the Lagrangian for two particles interacting through a potential $U(\\v{r}_1, \\v{r}_2)$, using the “lab frame” coordinates $\\v{r}_1, \\v{r}_2$. How does the potential simplify if it is translationally-invariant? How does it simplify if it is orientationally-invariant (i.e. central)? \n\\end{p}\n\\begin{s}\nThe Lagrangian is given by:\n\\[\\LL = \\frac{1}{2}m_1\\dot{\\v{r}}_1^2 + \\frac{1}{2}m_2\\dot{\\v{r}}_2^2 - U(x,y)\\]\nIf the potential is translationally invariant, then there is no difference if we move the entire system through space; hence, it can only depend on the difference, i.e. $U(\\v{r}_1 - \\v{r}_2)$. If it is orientationally-invariant (central), then it only depends on the magnitude of the the difference, i.e. $U(\\abs{\\v{r}_1 - \\v{r}_2})$.\n\\end{s}\n\n\\begin{p}\nRewrite the kinetic energy in terms of the centre of mass (CM) and relative coordinates, $\\v{R}, \\v{r}$. What are the Lagrange equations in these coordinates?\n\\begin{center}\n    \\includegraphics[scale=0.6]{Lecture-3/W3-img1.png}\n\\end{center}\n\\end{p}\n\\begin{s}\nWe have that the relative coordinate is $\\v{r} = \\v{r}_1 - \\v{r}_2$ and $U = U(\\abs{\\v{r}})$. The CM position is given by:\n\\[\\v{R} = \\frac{m_1\\v{r}_1 + m_2\\v{r}_2}{m_1 + m_2}\\]\nLet us also define the combined mass $M = m_1 + m_2$, we then have that:\n\\[T = \\frac{1}{2}\\left(m_1\\dot{\\v{r}}_1^2 + m_2\\dot{\\v{r}}_2^2\\right) = \\frac{1}{2}\\left(m_1\\left(\\dot{\\v{R}} + \\frac{m_2}{M}\\dot{\\v{r}}\\right)^2 + m_2\\left(\\dot{\\v{R}} - \\frac{m_1}{M}\\dot{\\v{r}}\\right)^2\\right) = \\frac{1}{2}\\left(M\\dot{\\v{R}}^2 + \\frac{m_1m_2}{M}\\dot{\\v{r}}^2\\right)\\]\nSo defining the reduced mass $\\mu = \\frac{m_1m_2}{M}$ we have:\n\\[\\LL = T - U = \\frac{M}{2}\\dot{\\v{R}}^2 + \\left(\\frac{\\mu}{2}\\dot{\\v{r}}^2 - U(r)\\right)\\]\nWe end up with a Lagrangian that has essentially two independent terms; a COM motion term (which is trivial, just a particle of mass $M$) and a relative position term which is equivalent to a particle of mass $\\mu$ subject to potential $U(r)$. We have essentially converted a two particle problem into what is effectively a one particle problem. This makes the two-body problem analytically (somewhat) easy to solve with this method.\n\\end{s}\n\n\\begin{p}\nWrite the expressions for $\\v{r}_1$ and $\\v{r}_2$ in terms of appropriate generalized coordinates, for the double pendulum. \n\\begin{center}\n    \\includegraphics[scale=0.6]{Lecture-3/W3-img2.png}\n\\end{center}\n\\end{p}\n\\begin{s}\nTrigonometry to get the position vectors:\n\\[\\v{r}_1 = l_1\\sin\\phi_1\\xhat + l_1\\cos\\phi_1\\yhat\\]\n\\[\\v{r}_2 = \\left(l_1\\sin\\phi_1 + l_2\\sin\\phi_2\\right)\\xhat + \\left(l_1\\cos\\phi_1 + l_2\\cos\\phi_2\\right)\\yhat\\]\nThis problem has four degrees of freedom (motion in the plane) but two constraints that $\\abs{\\v{r}_1} = l_1$ and $\\abs{\\v{r}_2 - \\v{r}_1} = l_2$. This leaves to two generalized coordinates. Note that the constraints $f(\\v{r}_1, \\cdots, \\v{r}_n, t) = 0$ are called \"holonomic\" and are in general nice for solving problems.\n\\end{s}\n\\end{document}", "meta": {"hexsha": "518d92aeb7b8a2a34a291a3613b01d92e1eef66b", "size": 4469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-3/Worksheet-3.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-3/Worksheet-3.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-3/Worksheet-3.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": 78.4035087719, "max_line_length": 433, "alphanum_fraction": 0.6791228463, "num_tokens": 1616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6370770695551566}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\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\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\n\\section{Numericals}\n\n\\begin{problem} 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\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\n\\section{Exploration}\n\n\\begin{problem}\n  Does the function $f : \\C \\to \\C$ given by $f(z) = \\conj{z}$ have a\n  primitive?\n\\end{problem}\n\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\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\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\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\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  \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\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\n\\begin{problem}\\label{cauchy-integral-formula}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\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\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\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\n\\end{document}\n", "meta": {"hexsha": "62944bfa6c136e77371251cd3214a8bd5a1e83b8", "size": 4254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set04.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/set04.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/set04.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": 30.3857142857, "max_line_length": 145, "alphanum_fraction": 0.6290550071, "num_tokens": 1558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6370690680871391}}
{"text": "\\section{Working Principle}\n\nFeature Kernel can be implemented in various ways, here we'll describe our implementation. \n\n\\subsection{Usage Ratio} \\label{sec:usage-ratio}\nOne of the first decisions that need to be made is size of the sub model.\nFirst of all, we can define the \\emph{Usage Ratio} (ur) as \n\\begin{align}\n    ur := \\frac{\\text{Sub model size}}{\\text{Full model size}} \\label{eq:usage-ratio}\n\\end{align}\n\nOf course a fixed $ur$, very easy to program, is not a good idea. \nIt is completely arbitrary and it may be to much in some case and not enough in other situations. \nA good choice is to having an automatically adjusting $ur$. In the current implementation $ur$ is initially set to the fixed value\\footnote{This value is hard-coded} of $0.01$, so initially\na sub model large one hundredth of the whole model. This value has been chosen because it is small enough, so it is very unlikely that a sub problem so small\nis already feasible, but also it is not too small because it can lead to a slow convergence. \n\n\n$ur$ value is automatically adjusted according to the status of the current sub problem:\n\n\n\\subsubsection*{Sub problem linearly infeasible}\\label{subsec:lin-infeasible-action}\n\n    In this case the random sub model is so small that is very unlikely that another random sub model\n    with the same size can be feasible. So to find a feasible sub model (at least in the continuous) \n    it is necessary to increase $ur$ significantly. This is the function used to update $ur$ in this case. \n    \\begin{align}\n        &ur_{i+i} = \\sqrt[m]{u_{i}^{n}}\\label{eq:ur-infease-grow} \\\\\n        With:&\\nonumber \\\\\n        &m > n > 1 \\nonumber\n    \\end{align}\n\n    This function, or better class of functions, has been chosen for three reasons:\n    \\begin{itemize}\n        \\item It has a fixed point in 1, so is not possible that such a series produces an $ur$ larger then 1.\n        \\item It is pretty fast as the beginning and than it becomes slower as $ur$ gets closer to 1.\n        \\item It allows to have a large number of points during the growth.\n    \\end{itemize}\n\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=\\textwidth,keepaspectratio]{plot_initial_increase}\n        \\caption{Infeasible $ur$ Growth example}\\label{fig:inf-grow-plot}\n    \\end{figure}\n    \n    In Figure \\ref{fig:inf-grow-plot} are shown four different configuration. This possible to notice that those function\n    grows quickly at the beginning, approximately from $ur = 0.01$ to $ur = 0.6 / 0.8$ then it starts settling\n    to $ur = 0.95 / 1$.\n\n    \n    Because the porpoise is to grow $ur$ until the generate model is large enough to be feasible, but not so large \n    that the sub model is practically as complex as the whole model. Also we'd like to have $ur$ to grow fast, so the number\n    of infeasible models is as limited as possible, but not too fast otherwise we'll get sub model that are too large for their\n    purpose. Last but not least we'd like to have an large number of points so the number of iteration to get to one should be high \n    but not excessive.\n    For those reason the current Feature Kernel implementation uses $n = 4$ and $m = 5$ to define the growth function.\n\n    \n\n\n\\subsubsection*{Sub problem is linearly feasible}\n    \\begin{align}\n        &u_{i+i} = 1.1 u_{i} \\label{eq:ur-lin-fease-grow}\n    \\end{align}\n\n    Once the model is proven to be feasible in the continuous, Feature Kernel tries to make it also feasible in the \n    integer. This can be done by simply trying over and over, and by chance it is possible that some of those sub models\n    become integer feasible. Feature Kernel does not rely (too much) on chance and to increase its possibility to get \n    a feasible sub model it increase $ur$ by 10\\%. This value has been chosen hoping that when the solution is feasible \n    in the continuous it is also close to be feasible in the integer. So this 10\\% increase should be done just a few times\n    before getting a feasible integer problem. If that holds true $ur$ should never become too close to 1.  \n    It also possible that some models requires all the variables to become integer feasible. In this case this 10\\% increase \n    can lead to a $ur > 1$, if this happens Feature Kernel simply set $ur = 1$.\n\n\\subsubsection*{Sub problem is integer feasible}\n    \\begin{align}\n        &u_{i+i} = 0.9 u_{i} \\label{eq:ur-fease-grow}\n    \\end{align}\n\n\n    If an integer feasible sub model is found means that the current $ur$ is able to provide some other integer feasible solutions. \n    The Feature Kernel goal is to find a ranking based on a machine learning technique, so to find a valuable answer Feature Kernel needs\n    some sub models that are integer feasible and some other that are feasible only in the continuous. This is why when an integer feasible\n    sub model is found Feature Kernel decreases $ur$ by 10\\%. This value has been chosen to mirror the value from Eq \\ref{eq:ur-lin-fease-grow}.\n    Of course a 10\\% decrease can lead to a very small $ur$ in few iterations, but consider that once the problem turn again into an integer infeasible \n    size the growth function turns into the method described in \\Cref{subsec:lin-infeasible-action}.\n\n\nThose three growth function will try to keep $ur$ switching between integer feasibility, continuous feasibility and infeasibility. This should provide \na meaningful dataset, rich of different statuses sub problem, to fed into the machine learning algorithm. \n\n\n\\subsubsection{Feasibility Threshold}\n\nNow it is possible to define those two indexes:\n\\begin{itemize}\n    \\item Continuous Feasibility Threshold (CFT): is the average $ur$ of sub problems that are feasible in the continuous but not in the integer.\n    \\item Integer Feasibility Threshold (IFT): is the average $ur$ of sub problems that are integer feasible.\n\\end{itemize}\n\n\nThose values allow the user to get an idea of some properties of the specific instance. They allow to understand if the problem is suitable for Kernel Search or not. \nFor example is it happens that IFT is very close to 1 it is very unlikely that an incremental solution, like the one built by Kernel Search, can provide a good solution in\na shot period of time. On the other side if IFT (and/or CFT) are reasonably low it is possible for this problem to be solved using Kernel Search, in fact in this situation\nan incremental solution is a good idea to solve the problem, potentially to a value vary close to the optimal. \n\n\n\\subsection{Sub Problem Construction}\n\nThe algorithm to build the random sub model is presented in the following pseudocode\n\\input{algorithms/generate_random_sub_model.tex}\n\n\n\n\\subsection{Sub Problem Solution}\nEach sub problem needs to be solved in order to understand if it is integer feasible, continuous feasible or infeasible. \nThis is done in two steps: first prove continuous feasibility, second prove integer feasibility. \n\n\\subsubsection{Continuous Feasibility}\nIn this first step the sub model is relaxed (integer constraints are removed) and then it is solved to the optimal. The optimal solution is needed for a \npractical reason: Random Forrest requires for each variable of each instance to have a value. This value cannot be a random one or simply one or zero. It\nmust be a significant value, so we'll use the value of the variable in the linear solution. Out of base variables are not set to any special value, they are \nsimply kept to zero. Base variables of course are set to their base value. \n\nIf the sub problem happens to be infeasible in the continuous domain then this sub problem is considered as meaningless and it will not be uses in the training of the Random Forrest\n\n\n\\subsubsection{Integer Feasibility}\nIn the second step the model is solved as it is. In this scenario is of course possible to solve the problem at the optimal but is pointless: \n\\begin{itemize}\n    \\item it's slow\n    \\item there is already a value for the variables\n    \\item we are looking for feasibility not for a solution\n\\end{itemize}\nSo in our implementation the solver is set to search for just one solution, so we are able to prove if the problem is feasible or not: if a solution is found then the model is feasible, otherwise\nis infeasible.\n\n\n\\subsubsection{Time Limit}\\label{sec:timeout}\nIn some cases even a sub problem solved once may take to long. This issue can be unacceptable within a method like Feature Kernel where the number of sub problem to solve can be very high: it \nis pointless to use a method for a faster initial kernel generation if it take more then the standard method. To avoid this issue is important to properly set a time limit. Feature Kernel\nsupports two time limits:\n\\begin{itemize}\n    \\item Minimum Time: this is the time limit used at the beginning of method and is increased each time a sub model end due to a timeout\n    \\item Maximum Time: the upper time limit, when this value is reached the actual time limit value won't increase even if the model ends due to a timeout\n\\end{itemize}\n\n\n\\subsubsection{Possible Sub Model Results}\\label{sec:submodel-result}\nConsidering the various steps and their configuration a sub problem can end with four different status:\n\\begin{enumerate}\n    \\item Infeasible: the model is infeasible in the continuous domain\n    \\item Linear Feasible: the model is feasible in the continuous but not in the integer\n    \\item Integer Feasible: the model is feasible in the integer\n    \\item Timeout: the solver reach the configured time limit, nothing could be said about the feasibility. \n\\end{enumerate}\n\n\\input{algorithms/solve_sub_model.tex}\n\n\\subsection{Kernel Construction}\n\nThis is the final step and is  made out of two components: variable sorting and variable split. \nVariable sorting is the step involving   the Random Forrest, where the solved models are joined into a dataset and then used to train the Model. The second component, namely variable split,\ntakes care for the split of variables between the initial kernel and the bucket variables.\n\n\\subsubsection{Variable Sort}\nWhen all the sub problem have been solved those solutions must be joined into a dataset. In our implementation Feature Kernel build the dataset only from instances \nwith final status of integer or continuous feasibility. Of course infeasible instances cannot be used in the dataset: variables does not have a value. For the same reason\nalso sub problems ended in timeout are to be considered insignificant, also them haven't a value.\n\nIn order to train the Random Forrest is important to modify the collected solution accordingly to the Random Forrest requirements. Once built the dataset it is possible to \nstart training the Random Forrest. In general it is an extremely fast process. We won't show a general pseudocode about this \nstep because it is very reach of implementation details. \nThe only thing that meters is that now we have a variable ranking.\n\n\n\\subsubsection{Variable Split}\nOnce we've got a variable ranking, Feature Kernel sorts the variables (from the highest ranking one). The top variables will be uses as kernel variables, the bottom ones will be\nthe buckets. Now Feature Kernel need to now the point to split kernel and variables. In our implementation this point is computed automatically according to the $ur$. \nAt the current time it is possible to use four different split points:\n\\begin{itemize}\n    \\item Minimum Continuous Feasibility: the size of the smallest sub model that happens to be continuous feasible\n    \\item  Maximum Continuous Feasibility: the size of the largest sub model that happens to be continuous feasible\n    \\item Minimum Integer Feasibility: the size of the smallest sub model that happens to be integer feasible\n    \\item Maximum Integer Feasibility: the size of the largest sub model that happens to be integer feasible\n\\end{itemize}\n\n\nOnce the variables are split Feature Kernel can build\\footnote{Depending on the actual Kernel Search implementation} the initial Kernel and the buckets. From now on Kernel Search can \nproceed as usual. \n\n\n\\subsubsection{Feature Kernel Pseudocode}\nAt this point, after all this theoretical description, we'll provide a pseudocode that should provide a guide for those who wants to implement Feature Kernel them self.\n\n\\input{algorithms/feature_kernel.tex}\n\n\\input{algorithms/build_solutions.tex}\n\n", "meta": {"hexsha": "df24dd71d56126c52592e94353cd33eab44f80e8", "size": 12344, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "working_principle.tex", "max_stars_repo_name": "Optimization-Algorithms/Feature-Kernel", "max_stars_repo_head_hexsha": "157c3775c5ca239000557d18cf3d6bbb3b350e33", "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": "working_principle.tex", "max_issues_repo_name": "Optimization-Algorithms/Feature-Kernel", "max_issues_repo_head_hexsha": "157c3775c5ca239000557d18cf3d6bbb3b350e33", "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": "working_principle.tex", "max_forks_repo_name": "Optimization-Algorithms/Feature-Kernel", "max_forks_repo_head_hexsha": "157c3775c5ca239000557d18cf3d6bbb3b350e33", "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": 61.4129353234, "max_line_length": 195, "alphanum_fraction": 0.7669313027, "num_tokens": 2813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.754914997895581, "lm_q1q2_score": 0.6370690666052246}}
{"text": "\\chapter{Spinless \\Pelectron + \\Pmuon scattering}\nFor the following calculations we will consider the elastic electromagnetic scattering of scalar electrons and muons. That is, the particles considered are solutions of the Klein-Gordon equation.\n\nThe process has one diagram:\n\\begin{figure}[h]\n\\centering\n\\include{figures/emuscatter}\n\\caption{Diagram for the t-channel process \\HepProcess{\\Pelectron+\\Pmuon\\to\\Pelectron+\\Pmuon} with scalar particles.\\label{fig:emuscatter}}\n\\end{figure}\n\n\\section{Electrodynamics of scalars}\\label{sec:EMdynamics}\nThe equations of motion for a particle may be modified to include the electromagnetic interaction via a 4-potential $A$ via the substitution\n\\begin{equation}\np^\\mu \\rightarrow p^\\mu + eA^\\mu.\n\\end{equation}\nThen the Klein-Gordon equation, \\eqref{eq:KleinGordon}, becomes\n\\begin{equation}\n\\left( i\\partial_\\mu + eA_\\mu \\right)\\left( i\\partial^\\mu + eA^\\mu \\right)\\psi = m^2\\psi.\n\\end{equation}\nExpanding out the left-hand side and collecting the free-particle kinetic and mass terms, we can identify an expression for the electromagnetic potential, $V$,\n\\begin{equation}\n\\left( \\partial_\\mu\\partial^\\mu + m^2 \\right)\\psi = \\left( ie\\partial_\\mu A^\\mu + ieA_\\mu\\partial^\\mu + e^2A_\\mu A^\\mu \\right)\\psi \\equiv -V(x) \\,\\psi.\n\\end{equation}\nUnder the weak field approximation, we may ignore the second-order term $A_\\mu A^\\mu$, so that\n\\begin{equation}\nV(x) \\approx -ie\\left( \\partial_\\mu A^\\mu + A_\\mu\\partial^\\mu \\right)\n\\end{equation}\n\n\\section{Scattering amplitude}\nThe amplitude for a particle with wavefunction $\\phi_i$ to scatter from potential $V$ and subsequently have the wavefunction $\\phi_f$ is given by\n\\begin{align}\nT_{fi} &= -i \\int \\dd[4]{x} \\, \\phi_f^* \\, V \\, \\phi_i \\\\\n&= -i \\int \\dd[4]{x} \\, \\phi_f^* \\, (-ie) \\left( \\partial_\\mu A^\\mu + A_\\mu\\partial^\\mu \\right) \\, \\phi_i\n\\end{align}\nwhere the weak field form of the EM potential has been substituted for $V$. Integrating by parts, the first term in the integral evaluates to\n\\begin{equation}\n\\int \\dd[4]{x} \\, \\phi_f^* \\, \\partial_\\mu A^\\mu \\, \\phi_i = \\left[ \\phi_f^* \\, A^\\mu \\, \\phi_i \\right]_{-\\infty}^{+\\infty} - \\int \\dd[4]{x} \\, \\left( \\partial_\\mu \\phi_f^* \\right) A^\\mu \\, \\phi_i\n\\end{equation}\nand the boundary term in square brackets goes to zero for a vanishing (i.e.~local) potential. Therefore, the scattering amplitude becomes\n\\begin{align}\nT_{fi} &= -i \\int \\dd[4]{x} \\,(-ie)\\left( \\phi_f^* A_\\mu \\partial^\\mu \\phi_i - (\\partial_\\mu \\phi_f^*) A^\\mu \\phi_i \\right) \\nonumber \\\\\n&= -i \\int \\dd[4]{x} \\, A^\\mu \\,(-ie)\\left( \\phi_f^* \\partial_\\mu \\phi_i - (\\partial_\\mu \\phi_f^*) \\phi_i \\right) \\nonumber \\\\\n&= -i \\int \\dd[4]{x} \\, A^\\mu \\, j_\\mu^{fi} \\label{eq:scatterAmp}\n\\end{align}\nwhere we have identified the current density,\n\\begin{equation}\nj_\\mu^{fi} = -ie \\left( \\phi_f^* \\partial_\\mu \\phi_i - (\\partial_\\mu \\phi_f^*) \\phi_i \\right).\n\\end{equation}\nThis is the current-potential formulation, where we identify the scattering process with a current $j_\\mu^{fi}$ and potential $A^\\mu$.\n\nAt the vertex changing A to C, the scalar electron has plane wavefunctions,\n\\begin{equation}\n\\phi_A(x) = N_A \\, e^{-iP_Ax}, \\quad \\phi_C(x) = N_C \\, e^{-iP_Cx},\n\\end{equation}\ngiving the current,\n\\begin{equation}\nj_\\mu^{CA} = -e \\, N_C^* \\, N_A \\, e^{i(P_C-P_A)x} \\, (P_A + P_C)_\\mu. \\label{eq:current}\n\\end{equation}\nThis will be the current in the current-potential formulation. Similarly, the current flowing through the other vertex is given by\n\\begin{equation}\nj_\\mu^{DB} = -e \\, N_D^* \\, N_B \\, e^{i(P_D-P_B)x} \\, (P_B + P_D)_\\mu.\n\\end{equation}\n\nWe wish to identify the potential $A^\\mu$ associated with the current $j_\\mu^{DB}$. For the potential to describe fields that behave according to Maxwell's equations, it must itself obey the Poisson equation (see Section \\ref{sec:maxwell} below),\n\\begin{equation}\n\\partial^2 A^\\mu = j^\\mu.\n\\end{equation}\nIt can be verified that the potential\n\\begin{equation}\nA_{DB}^\\mu = \\frac{- g^{\\mu\\nu} j^{DB}_\\nu}{q^2} \\label{eq:potential}\n\\end{equation}\nis a solution via substitution,\n\\begin{align}\n\\partial^2 \\left( \\frac{-g^{\\mu\\nu} j^{DB}_\\nu}{q^2} \\right) &= -\\frac{1}{q^2} \\left[ i(P_D - P_B) \\right]^2 \\, j_{DB}^\\mu \\nonumber \\\\\n&= j_{DB}^\\mu\n\\end{align}\nwhere $q^2 = (P_D - P_B)^2 = t$ is the 4-momentum of the propagating photon.\n\nInserting the above forms for the current, \\eqref{eq:current}, and potential, \\eqref{eq:potential}, into the expression for the scattering amplitude, \\eqref{eq:scatterAmp},\n\\begin{equation}\nT_{fi} = \\frac{ie^2}{q^2} \\int \\dd[4]{x} \\, N_C^* \\, N_A \\, N_D^* \\, N_B \\, (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\, e^{i(P_C+P_D-P_A-P_B)x}\n\\end{equation}\n\n\\section{Scattering rate}\nTo calculate the cross-section, we would like to know the rate $W_{fi}$ of particles being scattered per unit time and volume,\n\\begin{equation}\\boxed{\nW_{fi} = \\frac{T_{fi}^* T_{fi}}{T \\times V}\n}\\end{equation}\n\n\nAssume the scattering takes place in a volume $V$. We use the covariant normalisation to $2E$ particles in the volume, giving\n\\begin{equation}\nN_i = \\frac{1}{\\sqrt{V}} \\quad \\text{for $i=A,B,C,D$.}\n\\end{equation}\nThen the amplitude becomes\n\\begin{equation}\nT_{fi} = \\frac{ie^2}{q^2 \\, V^2} \\int \\dd[4]{x} \\, (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\, e^{i(P_C+P_D-P_A-P_B)x}\n\\end{equation}\ngiving a probability\n\\begin{align}\nT_{fi}^* T_{fi} &= \\frac{e^4}{q^4 \\, V^4} \\int_{TV} \\dd[4]x \\int_{TV} \\dd[4]x^\\prime \\, \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2 \\, e^{i(P_C+P_D-P_A-P_B)(x-x^\\prime)} \\\\\n&= \\frac{e^4}{q^4 \\, V^4} \\left(\\sqrt{2\\pi}\\right)^4 \\, \\sqrt{TV} \\int_{TV} \\dd[4]{x} \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2 \\, e^{i(P_C+P_D-P_A-P_B)x} \\nonumber \\\\\n&= \\frac{e^4}{q^4 \\, V^4} \\left(\\sqrt{2\\pi}\\right)^8 \\, \\left(\\sqrt{TV}\\right)^2 \\, \\delta^{(4)}(P_C+P_D-P_A-P_B) \\,  \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2 \\nonumber \\\\\n&= \\frac{e^4}{q^4 \\, V^4} \\, (2\\pi)^4 \\, \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2\\, \\delta^{(4)}(P_C+P_D-P_A-P_B)\\, TV\n\\end{align}\nwhich gives the rate\n\\begin{equation}\nW_{fi} = \\frac{(2\\pi)^4\\,e^4}{q^4 \\, V^4} \\, \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2\\, \\delta^{(4)}(P_C+P_D-P_A-P_B).\n\\end{equation}\n\n\\section{Density of states}\nThe larger the number of final states per unit volume $N_f$ available to a process, the more likely it is to happen and hence the cross-section is proportional to $N_f$.\n\nIn the scattering problem the number of final states is the number of possible momenta inside $[\\vec{p}, \\vec{p}+\\dd[3]{\\vec{p}}]$ for the propagating photon with a given energy. This is given by\n\\begin{equation}\nN_f = \\frac{1}{2E} \\frac{\\dd[3]{\\vec{p}}}{\\Delta p}\n\\end{equation}\nwhere $\\Delta p$ is the separation in momentum space between adjacent states and the $1/2E$ factor is due to the fact that there are $2E$ particles inside the volume and we want the number of states for one particle.\n\nSince the scattering process is modelled as happening inside a volume $V$, the propagating photon has the wavefunction of a particle in an infinite potential well with the dimensions of $V$ (Dirichlet boundary conditions, $\\psi(0) = \\psi(L) = 0$). This leads to the quantisation of its allowed momentum,\n\\begin{align}\np_x &= \\frac{2\\pi}{L_x}\\, n_x, \\quad\np_y = \\frac{2\\pi}{L_y}\\, n_y, \\quad\np_z = \\frac{2\\pi}{L_z}\\, n_z.\n\\end{align}\nTherefore, the separation between momentum states is $2\\pi/L$ in each dimension. This leads to the density of states,\n\\begin{align}\nN_f &= \\frac{1}{2E} \\frac{L_x}{2\\pi} \\frac{L_x}{2\\pi} \\frac{L_x}{2\\pi} \\dd[3]{\\vec{p}} \\nonumber \\\\\n&= \\frac{1}{2E} \\frac{V}{(2\\pi)^3} \\dd[3]{\\vec{p}}.\n\\end{align}\n\nNow the photon's energy is shared amongst particles $C$ and $D$, so the density of final states becomes\n\\begin{align}\nN_f^{CD} &= \\frac{1}{2E_C} \\frac{V}{(2\\pi)^3} \\dd[3]{\\vec{p}_C} \\, \\frac{1}{2E_D} \\frac{V}{(2\\pi)^3} \\dd[3]{\\vec{p}_D} \\\\\n&= \\frac{1}{4E_CE_D}\\frac{V^2}{(2\\pi)^6} \\dd[3]{\\vec{p}_C} \\, \\dd[3]{\\vec{p}_D}\n\\end{align}\n\n\\section{Incoming flux}\nThe rate $W_{fi}$ scales with the flux of incoming particles, so the in cross-section calculation, it should be divided by a flux factor, $\\rho_A\\rho_Bu_{AB}$, where $\\rho_{AB}$ give the density of initial-state particles and $u_{AB} = u_A - u_B$ is their relative velocity.\n\\begin{align}\n\\rho_A\\rho_Bu_{AB} &= \\frac{2E_A}{V} \\frac{2E_B}{V} \\left( \\frac{p_A}{E_A} - \\frac{p_B}{E_B} \\right) \\\\\n&= \\frac{4}{V^2} \\left( p_A E_B - p_B E_A \\right).\n\\end{align}\nFor a collider in the centre of momentum (CM) frame, we have $p_A = -p_B$,\n\\begin{equation}\n\\rho_A\\rho_Bu_{AB} = \\frac{4p_A}{V^2} (E_B + E_A) = \\frac{4p_A\\sqrt{s}}{V^2}\n\\end{equation}\nwhere $\\sqrt{s} = E_A + E_B$ is the CM energy.\n\n\\section{Cross-section}\nNow we are ready to calculate the differential cross-section,\n\\begin{align}\n\\dd{\\sigma} &= \\frac{W_{fi}}{\\rho_A\\rho_Bu_{AB}} N_f \\\\\n&= \\left\\{ \\frac{(2\\pi)^4\\,e^4}{q^4 \\, V^4} \\, \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2\\, \\delta^{(4)}(P_C+P_D-P_A-P_B) \\right\\} \\frac{V^2}{4p_A\\sqrt{s}} \\frac{1}{4E_CE_D}\\frac{V^2}{(2\\pi)^6} \\dd[3]{\\vec{p}_C} \\, \\dd[3]{\\vec{p}_D} \\nonumber \\\\\n&= \\frac{e^4}{q^4V^2} \\frac{\\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2}{4p_A\\sqrt{s}} \\, \\dd{Q}\n\\end{align}\nwhere $\\dd{Q}$ is the Lorentz-invariant phase space factor\n\\begin{equation}\n\\dd{Q} = \\frac{V}{2E_C} \\frac{\\dd[3]{\\vec{p}_C}}{(2\\pi)^3} \\frac{V}{2E_D} \\frac{\\dd[3]{\\vec{p}_D}}{(2\\pi)^3} (2\\pi)^4 \\, \\delta^{(4)}(P_C+P_D-P_A-P_B)\n\\end{equation}\nIn the CM frame, we have that $\\vec{p}_A = -\\vec{p}_B$, so\n\\begin{equation}\n\\dd{Q} = \\frac{V^2}{(2\\pi)^2} \\, \\delta(\\sqrt{s} - E_C - E_D) \\, \\delta^{(3)}(\\vec{p_C} + \\vec{p_D}) \\, \\frac{\\dd[3]{\\vec{p}_C}}{2E_C} \\frac{\\dd[3]{\\vec{p}_D}}{2E_D}.\n\\end{equation}\nWe now integrate over all momenta for $D$, the unobserved particle. This gives,\n\\begin{align}\n\\dd{Q} &= \\frac{V^2}{(2\\pi)^2} \\frac{1}{4E_C E_D} \\, \\delta(\\sqrt{s} - E_C - E_D) \\, \\dd[3]{\\vec{p}_C} \\\\\n&= \\frac{V^2}{(2\\pi)^2} \\frac{1}{4E_C E_D} \\, \\delta(\\sqrt{s} - E_C - E_D) \\, p_C^2 \\, \\dd{p_C} \\, \\dd{\\Omega}\n\\end{align}\n\nNow from the relation $E^2 = p^2 + m^2$ we have that $E \\dd{E} = p\\dd{p}$, so\n\\begin{equation}\n\\dd{Q} = \\frac{V^2}{(2\\pi)^2} \\frac{p_C}{4 E_D} \\, \\delta(\\sqrt{s} - E_C - E_D)  \\, \\dd{E_C} \\, \\dd{\\Omega}\n\\end{equation}\n\nWe next want to integrate over $E_C$. To do so, write the expression in the $\\delta$ function as\n\\begin{align}\nf(E_C) &= \\sqrt{s} - E_C - E_D \\\\\n&= \\sqrt{s} - E_C - \\sqrt{p_D^2 + m_D^2} \\nonumber \\\\\n&= \\sqrt{s} - E_C - \\sqrt{p_C^2 + m_D^2} \\quad \\text{since $\\vec{p}_C = -\\vec{p}_D$} \\nonumber \\\\\n&= \\sqrt{s} - E_C - \\sqrt{E_C^2 - m_C^2 + m_D^2}.\n\\end{align}\nTherefore,\n\\begin{align}\n\\abs{\\dv{f}{E_C}} &= 1 + \\frac{E_C}{\\sqrt{E_C^2 - m_C^2 + m_D^2}} \\nonumber \\\\\n&= \\frac{\\sqrt{s}}{E_D}\n\\end{align}\nso the $\\delta$-function becomes\n\\begin{equation}\n\\delta(\\sqrt{s} - E_C - E_D) = \\delta(E_C) \\, \\frac{E_D}{\\sqrt{s}}\n\\end{equation}\nand the Lorentz-invariant phase space is\n\\begin{equation}\n\\dd{Q} = \\frac{V^2}{(2\\pi)^2} \\frac{p_C}{4\\sqrt{s}} \\, \\delta(E_C)\\, \\dd{E_C} \\, \\dd{\\Omega}.\n\\end{equation}\nIntegrating over the final-state particle's energy, $E_C$,\n\\begin{equation}\n\\dd{Q} = \\frac{V^2}{(2\\pi)^2} \\frac{p_C}{4\\sqrt{s}} \\, \\dd{\\Omega}.\n\\end{equation}\n\nSubstituting this back into the expression for the differential cross section,\n\\begin{equation}\\boxed{\n\\dv{\\sigma}{\\Omega} = \\frac{1}{64\\pi^2}\\frac{e^4}{q^4} \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2 \\frac{1}{s} \\, \\frac{p_C}{p_A}\n}.\\end{equation}\nThe fact that the cross-section is proportional to $1/s$, the inverse square of the SM energy means that we need increasingly higher luminosities to observe high energy scattering processes.\n\n\\section{Application: high-energy scattering}\nConsider the ultra-relativistic case, where $E \\gg m$ for all particles. In the CM frame, all particles now have the same energy $E = s/2$. Then we have that the Mandelstam $t$ variable is\n\\begin{align}\nq^2 = t &= (P_A - P_C)^2 \\\\\n&= \\mqty(E_A - E_C \\\\ \\vec{p}_A - \\vec{p}_C)^2 \\nonumber \\\\\n&= -2E^2 (1-\\cos\\theta)\n\\end{align}\n\nIn this case, the differential cross-section becomes\n\\begin{equation}\n\\dv{\\sigma}{\\Omega} = \\frac{e^4}{64\\pi^2} \\frac{\\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2}{4E^4 (1-\\cos\\theta)^2} \\frac{1}{s}.\n\\end{equation}\n\nNow we have, in the CM frame,\n\\begin{equation*}\nP_A = \\mqty(E \\\\ \\vec{p}) \\, \\quad P_B = \\mqty(E \\\\ -\\vec{p}) \\, \\quad P_C = \\mqty(E \\\\ \\vec{p^\\prime}) \\, \\quad P_D = \\mqty(E \\\\ -\\vec{p^\\prime}),\n\\end{equation*}\nand therefore,\n\\begin{align}\n(P_A + P_C)_\\mu (P_B + P_D)^\\mu &= \\mqty(2E \\\\ \\vec{p} + \\vec{p^\\prime}) \\mqty(2E \\\\ -\\vec{p} - \\vec{p^\\prime} ) \\quad \\text{with $\\abs{\\vec{p}} = \\abs{\\vec{p^\\prime}} = E$} \\nonumber \\\\\n&= (2E)^2 + (\\vec{p} + \\vec{p^\\prime})^2 \\nonumber \\\\\n&= 6E^2 + 2E^2 \\cos\\theta\n\\end{align}\n\\begin{equation}\n\\Rightarrow\\quad \\left[ (P_A + P_C)_\\mu (P_B + P_D)^\\mu \\right]^2 = 4E^4 (3 + \\cos\\theta)^2\n\\end{equation}\n\nSo the final answer is\n\\begin{equation}\n\\dv{\\sigma}{\\Omega} = \\frac{e^4}{64\\pi^2} \\left(\\frac{3+\\cos\\theta}{1-\\cos\\theta}\\right)^2 \\frac{1}{s}.\n\\end{equation}\n\n\\section{$1 \\to 2$ scattering (decay)}\nFor a single body of mass $M$ decaying into two particles, we replace the flux factor with the normalised energy density,\n\\begin{equation}\n\\rho = \\frac{2M}{V}\n\\end{equation}\nso the cross-section is given by\n\\begin{equation}\n\\dd{\\sigma} = \\frac{V}{2M} \\, W_{fi} \\, N_f.\n\\end{equation}\nwhere for a two-body final state, $N_f$ is the same as for above. However, $T_{fi}$ will obviously be different.\n", "meta": {"hexsha": "beed8ec9fafb5a6e7bb1e1390cda06e695f4b2eb", "size": 13434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/8_Spinless_e_mu_scattering.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/8_Spinless_e_mu_scattering.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/8_Spinless_e_mu_scattering.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": 53.9518072289, "max_line_length": 303, "alphanum_fraction": 0.6540866458, "num_tokens": 5229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6370019137980897}}
{"text": "\\section{Multi-armed Bandits}\nReinforcement learning involves evaluative feedback rather than instructive feedback. We get told whether our actions are good ones or not, rather than what the single best action to take is. This is a key distinction between reinforcement learning and supervised learning.\n\n\\subsection{A $k$-armed Bandit Problem}\nIn the $k$-armed bandit problem there are $k$ possible actions, each of which yields a numerical reward drawn from a stationary probability distribution for that action. We want to maximise the expected total reward, taking an action at each \\emph{time step}. Some notation:\n\n\\begin{itemize}\n    \\item Index timesteps by $t$\n    \\item Action $A_t$\n    \\item Corresponding reward $R_t$\n    \\item \\emph{Value} of action $a$ is $q_*(a) = \\mathbb{E}[R_t | A_t = a]$\n    \\item Estimate of value of action $a$ at $t$ is denoted $Q_t(a)$\n\\end{itemize}\n\nWe therefore want to choose $\\{a_1, \\dots, a_T\\}$ to maximise $\\sum_{t = 1}^T q_*(a_t)$.\\\\\n\\mbox{}\\\\ \nAt each timestep, the actions with the highest estimated reward are called the \\emph{greedy} actions. If we take this action, we say that we are \\emph{exploiting} our understanding of the values of actions. The other actions are known as \\emph{non-greedy} actions, sometimes we might want to take one of these to improve our estimate of their value. This is called \\emph{exploration}. The balance between exploration and exploitation is a key concept in reinforcement learning.\n\n\n\\subsection{Action-value Methods}\nWe may like to form estimates of the values of possible actions and then choose actions according to these estimates. Methods such as this are known as \\emph{action-value methods}. There are, of course, many ways of generating the estimates $Q_t(a)$. \\\\\n\\mbox{}\\\\\nAn $\\varepsilon$-greedy method is one in which with probability $\\varepsilon$ we take a random draw from all of the actions (choosing each action with equal probability), providing some exploration.\n\n\n\\setcounter{subsection}{4}\n\\subsection{Tracking a Non-stationary Problem}\nIf we decide to implement the sample average method, then at each iteration that we choose the given action we update our estimate by\n\\begin{equation}\n    Q_{n+1} = Q_n + \\frac1n [R_n - Q_n]\n\\end{equation}\nNote that this has the (soon to be familiar) form\n\\begin{equation}\n    \\mathrm{NewEstimate} \\gets \\mathrm{OldEstimate} + \\mathrm{StepSize}\\times[\\mathrm{Target} - \\mathrm{OldEstimate}].\n\\end{equation}\n\\mbox{}\\\\\nIf the problem was non-stationary, we might like to use a time weighted exponential average for our estimates (\\emph{exponential recency-weighted average}). This corresponds to a constant step-size $\\alpha \\in (0, 1]$ (you can check).\n\\begin{equation}\n    Q_{n+1} = Q_n + \\alpha [R_n - Q_n].\n\\end{equation}\n\\mbox{}\\\\\nWe might like to vary the step-size parameter. Write $\\alpha_n(a)$ for the step-size after the $n^{\\mathsf{th}}$ reward from action $a$. Of course, not all choices of $\\alpha_n(a)$ will give convergent estimates of the values of $a$. To converge with probability 1 we must have\n\\begin{equation}\n    \\sum_n \\alpha_n(a) = \\infty \\quad\\quad \\mathsf{and} \\quad\\quad  \\sum_n \\alpha_n(a)^2 < \\infty.\n\\end{equation}\nMeaning that the coefficients must be large enough to recover from initial fluctuations, but not so large that they don't converge in the long run. Although these conditions are used in theoretical work, they are seldom used in empirical work or applications. (Most reinforcement learning problems have non-stationary rewards, in which case convergence is undesirable.)\n\n\\subsection{Optimistic Initial Values}\nThe exponential recency weighted method is biased by the initial value one gives. If we like, we may set initial value estimates artificially high to encourage exploration in the short run -- this is called \\emph{optimistic initial values}. This is a useful trick for stationary problems, but does not apply so well to non-stationary problems as the added exploration is only temporary.\n\n\n\\subsection{Upper-Confidence Bound Action Selection}\nWe might like to discriminate between potential explorative actions. Note that $\\varepsilon$-greedy does not do this. We define the \\emph{upper-confidence bound} action at $t$ as follows\n\\begin{equation}\n    A_t \\doteq \\argmax_{a}\\left[ \\, Q_t(a)+ c \\sqrt{\\frac{\\mathrm{ln}(t)}{N_t(a)}} \\, \\right]\n\\end{equation}\nwhere $Q_t(a)$ is the value estimate for the action $a$ at time $t$, $c > 0$ is a parameter that controls the degree of exploration and $N_t(a)$ is the number of times that $a$ has been selected by time $t$. If $N_t(a) = 0$ then we consider $a$ a maximal action.\\\\\n\nThis approach favours actions with a higher estimated rewards but also favours actions with uncertain estimates (more precisely, actions that have been chosen few times).\n\n\n\\subsection{Gradient Bandit Algorithms}\nSuppose that we choose actions probabilistically based on a preference for each action, $H_t(a)$. Let the action at $t$ be denoted by $A_t$. We then define the probability of choosing action $a$ via the softmax\n\\begin{equation}\n    \\pi_t(a) \\doteq \\P{}(A_t = a) = \\frac{e^{H_t(a)}}{\\sum_i e^{H_t(i)}}.\n\\end{equation}\nWe then iteratively perform updates according to \n\\begin{equation}\n    H_{t+1}(a) = H_t(a) + (R_t - \\bar{R}_t)(\\mathds{1}_{A_t = a} - \\pi_t(a)),\n\\end{equation}\nwhere $\\bar{R}_t$ is the mean of previous rewards. The box in the notes shows that this is an instance of stochastic gradient ascent since the expected value of the update is equal to the update when doing gradient ascent on the (total) expected reward.", "meta": {"hexsha": "89b63a3199e6023edd6647a8ed514996c164d6cd", "size": 5563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter2/chapter2_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/chapter2/chapter2_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/chapter2/chapter2_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": 78.3521126761, "max_line_length": 477, "alphanum_fraction": 0.7524716879, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6370019118342373}}
{"text": "\\chapter{Audio Frequency Scaling methods}\\label{ch:scaling_methods}\n\\section{Introduction}\nThe human hearing system can detect \nacoustic vibrations and translate \nthose vibrations into sounds.\nThe detectable range of frequencies by the human ear\nis referred to as audio or sonic. This range\nspans over approximately \\(20kHz\\),\nstarting at \\(20Hz\\) to about \\(20kHz\\)\n\\cite{hearthres}.\n\nAs a result of aging, the hearing system's dynamic range \nas to the detectable bandwidth decreases,\nand by middle-age are set at about\n\\(20Hz \\div 14KHz\\)\\cite{Wiley2008ChangesIH}.\nAs such, the maximum hearable frequency\ndeclines with age.\n\nThe human ear's ability to distinguish \nbetween two different frequencies \nis not symmetric. \nFor example, the spectral distance between two \ndifferent frequencies in one distinct region does \nnot equal the spectral distance \nbetween two additional frequencies in other regions.\nDue to that asymmetry, the conventional linear \nspectral mapping is impractical for\nspeech analysis applications.\nThus, a different spectral mapping \nbased on a different scaling system\nthat mimics the human hearing as possible\nis applied instead as an alternative.\n\n\\section{Mel-Scaling}\nThe Mel-scaling method \nis a suggested solution to mapping \nstandard audio frequencies to perceived frequencies.\nThe basic idea that lies underneath it is that for\ndifferent pitches we assign varying bandwidth,\nsuch that they are equal in distance\nfrom each other, as rated by listeners.\nThe reference point has been chosen to be \n\\(1000 Hz = 1000 Mels\\).\n\nMel-scale was first described in \\cite{Volkmann} by Stevens and Volkmann,\nwhere the authors presented different curves for Mel-scaling.\n\nTwo common tables were composed\naccording to the Mel-scaling curves. One table by \nBeranek in 1949 \\cite{beranek1988acoustical} \nand the second by Umesh et al. in 1999 \\cite{UmeshMel}.\n\nThe most popular equation that models the Mel-scale\nis given by \\cite{o1987speech} and is typically referenced as\nthe \"Logarithm based Mel scale\":\n\\begin{equation}\\label{eq:mel_1}\n    Mel = \\ln \\left( 1 + \\frac{f}{700} \\right) \\cdot \\frac{1000}{\\ln(1+\\frac{1000}{700})} \n\\end{equation}\n\nEquation\\;[\\ref{eq:mel_1}] can be simplified as follows:\n\\begin{align}\n    Mel & = 1127 \\ln \\left( 1 + \\frac{f}{700} \\right) \\nonumber \\\\\n    Mel & = 2595 \\log_{10}\\left( 1 + \\frac{f}{700} \\right)\n\\end{align}\n\nThen, the reverse equation, converting Mels back to Hz,\ncan be written as:\n\n\\begin{align}\n    f[Hz] & = 700 \\left( 10^{\\frac{Mel}{2595}} -1  \\right)\n\\end{align}\n\n% \\subsection{Logarithm based Mel scale}\n% The most popular equation that models the Mel-scale\n% is given by \\cite{o1987speech}:\n% \\begin{equation}\n%     Mel = \\ln \\left( 1 + \\frac{f}{700} \\right) \\cdot \\frac{1000}{\\ln(1+\\frac{1000}{700})} \n% \\end{equation}\n% This can be simplified as follows:\n% \\begin{align}\n%     Mel & = 1127 \\ln \\left( 1 + \\frac{f}{700} \\right) \\nonumber \\\\\n%     Mel & = 2595 \\log_{10}\\left( 1 + \\frac{f}{700} \\right)\n% \\end{align}\n% Then, the reverse equation, converting Mels back to Hz,\n% can be written as:\n% \\begin{align}\n%     f[Hz] & = 700 \\left( 10^{\\frac{Mel}{2595}} -1  \\right)\n% \\end{align}\n% These modeling equations became de-facto the default way to\n% map audio frequencies to Mels.\n\n\\subsection{Mel scale approximations}\nComputing a logarithm for hardware devices, \nwhether it is the natural logarithm or any other base, \nis not very straightforward.\nFor example, this kind of computation might require special\ntechniques or long LUTs (look-up tables),\nwhich are extraordinarily resource hungry.\n\nInstead, other approximations that do not involve\ntrigonometric or logarithms, but only\nsimple arithmetic structures can be applied.\nBy doing so, we benefit from low resource\nutilization while maintaining high accuracy.\n\nMultiple approximation methods were studied in \\cite{fitmelscale}.\nTwo approximations are the most prominent for target HW devices.\n\\begin{align}\n    \\label{eq:melapproxa} Mel & = a + b \\cdot f \\\\ \n    Mel & = \\frac{f}{a \\cdot f + b} \\label{eq:melapproxb}\n\\end{align}\n\nWhere \\(a\\), \\(b\\) in Equation \\ref{eq:melapproxa} are defined as follows:\n\\begin{align}\n    a & = \\begin{cases}\n        127.7   &,\\;f \\leq 1000 \\\\\n        1322    &,\\;f > 1000\n    \\end{cases} \\nonumber \\\\\n    b & = \\begin{cases}\n        0.9     &,\\;f \\leq 1000 \\\\\n        0.19    &,\\;f > 1000\n    \\end{cases}\n\\end{align}\n\nwhile in Equation \\ref{eq:melapproxb} \\(a\\), \\(b\\) are:\n\\begin{align}\n    a & = \\begin{cases}\n        0.000244   &,\\;f \\leq 1000 \\\\\n        0.0004    &,\\;f > 1000\n    \\end{cases} \\nonumber \\\\\n    b & = \\begin{cases}\n        0.741   &,\\;f \\leq 1000 \\\\\n        0.603   &,\\;f > 1000\n    \\end{cases}\n\\end{align}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Scaling/images/mel_methods_comp}\n    \\caption{Mel scale comparisons with Beranek \\& Umesh tables}\\label{fig:mel_methods_comp}\n\\end{figure}\n\nFigure \\ref{fig:mel_methods_comp} has comparisons of three different \nMel-scale implementations with Beranek \\& Umesh tables.\nThe first column, Log Based Mel, represents\nO'Shaugnessy's famous log-based Mel modeling.\nThe Mel option \\#1, and Mel option \\#2 columns \nfollow the suggested approximations\ngiven in Equations \\ref{eq:melapproxa} \nand \\ref{eq:melapproxb}, respectively.\n\nFrom the last row of graphs, we can deduce that the approximation\nin Equation \\ref{eq:melapproxb} \nis the closest along with the range of audio frequencies\nto the tables provided by Beranek \\& Umesh.\nOn the other hand, the more simplified approximation \nin Equation\\ref{eq:melapproxa} seems \nto yield the highest errors.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Scaling/images/mel_lut}\n    \\caption{LUT based Mel FPGA implementation results}\\label{fig:mel_lut}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Scaling/images/mel_approx_no_opt}\n    \\caption{Mel approx. \\#1 FPGA implementation results}\\label{fig:mel_approx_no_opt}\n\\end{figure}\n\nFigures \\ref{fig:mel_lut}, \\ref{fig:mel_approx_no_opt} \npresent the results of FPGA implementations\nof O'Shaugnessy's log-based Mel and Mel approximation \\#1.\nNonetheless, high precision quantization settings were chosen\nfor the Mel approximation, U32.22,  \nthe shifting error received is higher compared \nto the conventional Log Mel scaling implementation.\nAlthough this error shift is compensated \njust by selecting the approximation method, \nthe straightforward approach \nturned out to be the non-optimized solution \nin terms of HW resources and power consumption,\nwhich utilized four times higher wattage on top of \\(25 \\div 30 \\%\\) \nadditional resources.\n\nInstead, two optimization workarounds were tested.\nThe first is the multiplication of the \\(a, b\\) coefficients\nin \\ref{eq:melapproxb} by 1000. \nThe second optimization is reorganizing the equation\nand storing the result in a sufficient precision\nfor the fractional part but lower resolution for the integer part.  \nThese optimizations lead to a reduction in the \nrequired number of bits for the fractional part.\nAs a result, both the frequency shifting error \nand the overall resource utilization are greatly improved.\n\nYet, the split in frequency bands results in two multiplied sets\nof coefficients for each band calculation.\nTherefore, choosing a more generalized set \nof coefficients for the entire audio band can help \nin the reduction of redundant LUTs and other combinational logic, \nsuch as selectors and multi-bus multiplexer cells.\n\nSelection of \\(a=0.24,\\;b=0.741\\), showed better results\nas can be seen in Figure \\ref{fig:mel_approx_logic_opt_generic}.\nThe accuracy estimation for the non-generic implementation\nis shown in Figure\\;\\ref{fig:mel_approx_logic_opt}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Scaling/images/mel_approx_logic_opt}\n    \\caption{Mel approx. \\#1 \\underline{optimized} FPGA implementation results}\\label{fig:mel_approx_logic_opt}\n\\end{figure}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Scaling/images/mel_approx_logic_opt_generic}\n    \\caption{Mel approx. \\#1 \\underline{optimized, generic} FPGA implementation results}\\label{fig:mel_approx_logic_opt_generic}\n\\end{figure}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    % \\centering\n    \\hspace*{-1.8cm}\n    \\arrayrulecolor{mtblborder}\n\\begin{tabular}{ !{\\color{mtblborder}\\vrule}l!{\\color{mtblborder}\\vrule}rcccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{mtblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{Latency \\([ns]\\)}  \n    & \\color{white}\\bf{Quant.} \n    & \\color{white}\\bf{Max Err. \\([\\Delta Hz]\\)}\n    & \\color{white}\\bf{Mean Err.}\n    & \\color{white}\\bf{Std Err.} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{mtbl} Log LUT Mel   & \\(14\\) (3 C.C) & U16/4 & 1.146 & 0.268 & 0.106 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Mel \\#1   & \\(9\\) (2 C.C) &  U32/22  & 1.338 & -0.873 & -0.359 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{mtbl} Mel \\#1 Opt      & \\(9\\) (2 C.C) &  U16/4  & 0.190 & -0.053 & 0.065 \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{wtbl} Mel \\#1 Generic     & \\(9\\) (2 C.C) &  U16/4  & \\color{gtblcaption}0.174 & \\color{gtblcaption}-0.035 & \\color{gtblcaption}0.061 \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel-Approx, log-based Mel performance comparison}\n\\label{tbl:mel_scale_performance}\n\\end{table}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{ytblborder}\n\\begin{tabular}{ !{\\color{ytblborder}\\vrule}l!{\\color{ytblborder}\\vrule}rrrrr| } \n    \\hline\n\n    \\hline\n    \\rowcolor{ytblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{FF} \n    & \\color{white}\\bf{LUT} \n    & \\color{white}\\bf{DSP} \n    & \\color{white}\\bf{LUTRAM} \n    & \\color{white}\\bf{BRAM} \\\\\n    % & \\color{white}\\bf{ORM} \n    % & \\color{white}\\bf{Clean} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{ytbl} Log LUT Mel   & 82(0.04\\%) & 276(0.23\\%) & 1(<1\\%) & 10(0.02\\%) & 1.5(1.04\\%)  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Mel \\#1     & 47(0.02\\%) & 530(0.45\\%) & 1(<1\\%) & 0(0\\%)  & 0(0\\%)    \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{ytbl} Mel \\#1 Opt      & 47(0.02\\%) & 271(0.23\\%) & 1(<1\\%) & 0(0\\%)  & 0(0\\%)    \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{wtbl} Mel \\#1 Generic     & \\color{gtblcaption}47(0.02\\%) & \\color{gtblcaption}269(0.19\\%) & \\color{gtblcaption}1(<1\\%) & \\color{gtblcaption}0(0\\%)  & \\color{gtblcaption}0(0\\%)    \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel scaling methods resource utilization table}\n\\label{tbl:mel_resource_util}\n\\end{table}\n\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{gtblborder}\n\\begin{tabular}{ |l|cccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{gtblcaption} \\color{white}\\bf{Parameter} \n    & \\color{white}\\bf{Log LUT Mel} \n    & \\color{white}\\bf{Mel \\#1} \n    & \\color{white}\\bf{Mel \\#1 Opt} \n    & \\color{white}\\bf{Mel \\#1 Generic} \\\\\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{5}{|c|}{\\bf{Dynamic Power [W]}}\\\\\n    \\hline\n    \\rowcolor{gtbl} Signals                 & 4.947 & 5.221 & 3.011 & 2.916  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Logic                   & 6.50 & 6.792 & 3.751 & 3.070  \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} DSP                     & 0.014 & 0.013 & 0.014  & 0.014 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} I/O                     & 18.236 & 26.263 & 7.207  & 6.378 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{dynmic}}\\) & \\textbf{29.697} & \\textbf{38.290} & \\textbf{13.983}  & \\textbf{\\colorbox{Goldenrod!70}{\\color{MidnightBlue}12.379}} \\\\\n    \\hline\n\n    % \\hline\n    % \\rowcolor{gtbl} Bark Scale      & 56(0.02\\%) & 218(\\%) & 1(<1\\%)   \\\\\n    % % \\cline{2-8}\n    % % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{5}{|c|}{\\bf{Static Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} PL Static               & 2.364 & 2.466 & 0.499  & 0.499 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} PS Static               & 0.068 & 0.071 & 0.020 & 0.018  \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{static}}\\) & \\textbf{2.432} & \\textbf{2.537} & \\textbf{0.519} & \\textbf{\\colorbox{Goldenrod!70}{\\color{MidnightBlue}0.517}}  \\\\\n    \\hline\n\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{5}{|c|}{\\bf{Total Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{total}}\\)  & \\textbf{32.13} & \\textbf{40.827} & \\textbf{14.502} & \\textbf{\\colorbox{Goldenrod!70}{\\color{MidnightBlue}12.896}}  \\\\\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel-Approx, log-based Mel, Bark Scale Power consumption}\n\\label{tbl:mel_scale_pwr_tbl}\n\\end{table}\n\nThe LUT implementation makes use of a \\(log_{2}\\) look-up table.\nHowever, an additional step is \nneeded for the natural logarithm or other log bases. \nSince the logarithm bases are constant, \nthe LUT result is divided by the \\(log_{2}\\) of the base,\nwhether it be the natural base or base ten.\nThis logarithm bases \nconvention is described in Equation\\;\\ref{eq:log_base_conv}.\n\\begin{align}\\label{eq:log_base_conv}\n    \\log_{b}(a)  & = \\frac{\\log_{x}(a)}{\\log_{x}(b)}\n\\end{align}\n\n\nTable\\;\\ref{tbl:mel_scale_performance} summarizes\nthe performance comparison between the different Mel scaling\nimplementation approaches. \n\nThe HW setup is for the PYNQ-Z1 development board.\nHence, the results are unique to that specific \nHW device and probably change for other \nFPGA devices and development boards.\n\nLatencies were simulated with Xilinx Vivado Suit\nfor an operating clock frequency of \\(225MHz\\).\nIn this operating condition, no timing violations were reported.\n\nTables\\;\\ref{tbl:mel_resource_util} and \\ref{tbl:mel_scale_pwr_tbl}\nshow the synthesis and implementation results \nplus the power estimation reports. \nThese reports were taken from the Xilinx Vivado Suit application.\n\n\\section{Bark-Scaling}\nAnother scaling method is the Bark scale which is based on\nthe same principle of retaining the same perceptual distances.\nThe Bark scale is divided into critical \nbands corresponding to the critical hearing bands. \nEach band has a bandwidth similar \nto the psychoacoustic band of the corresponding \n``filter'' in the human hearing system \nand is ranked with a unique number.\n\n\\subsection{Bark Critical Bands}\nLike the Mel scale, several equations were proposed to model best\nthe Bark scale and its critical bands.\n\nThe first method was introduced in \\cite{1908630}.\nA proposed approximation to the Bark scaling is described in \n\\cite{TraunmullerScale}; this paper also introduces the \ncorrection of the band boundaries to ensure more \ncorrectness with the original Bark scaling.\n\nFour different equations were proposed to model\nthe Bark scale.\n\nThe first by Zwicker is well described in\\cite{1908630} and\nis given by the following equation:\n\\begin{align}% Zwicker Eq\n    Bark & = \\tan^{-1}\\left\\{ 0.00073f \\right\\} + 3.5 \\tan^{-1}\\left\\{ \n            \\left( \\frac{f}{7500} \\right)^{2}\n        \\right\\}\n\\end{align}\n\nAnother proposed equation by Traunmuller \\cite{TraunmullerScale} is:\n\\begin{align}\\label{eq:traunmuller_no_fix}% Traunmuller Eq + Correction\n    Bark & = \\frac{26.81f}{1960 + f} - 0.53\n\\end{align}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/Traunmuller_nofix}\n    \\caption{Traunmuller no fix}\\label{fig:Traunmuller_nofix}\n\\end{figure}\n\nDenoting Traunmuller's original\nBark scale given in Equation \\ref{eq:traunmuller_no_fix} as \\(Bark'\\),\nthe fixed form for Traunmuller's Bark equation is:\n\\begin{align}\n    Bark & = \\begin{cases}\n        0.3 + 0.85\\cdot \\left( Bark' \\right) \n        &,\\;Bark' < 2 \\\\\n        Bark' + 0.22\\cdot \\left( Bark' - 20.1 \\right) \n        &,\\;Bark' > 20.1\n    \\end{cases}\n\\end{align}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/Traunmuller_fix}\n    \\caption{Traunmuller fix}\\label{fig:Traunmuller_fix}\n\\end{figure}\n\nThe fourth possible modeling equation is proposed by\nSchroeder in \\cite{SchroederScale} and is as follows:\n% Schroeder Eq\n\\begin{align}\n    Bark & = 7\\ln \\left( \\frac{f}{650} + \\sqrt{1 + \\frac{f^{2}}{422500} }  \\right)\n\\end{align}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/bark_comparison}\n    \\caption{Bark comparisons}\\label{fig:bark_comparison}\n\\end{figure}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/bark_comparison2}\n    \\caption{Bark comparison}\\label{fig:wer_23}\n\\end{figure}\n\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/Zwicker}\n    \\caption{Zwicker}\\label{fig:Zwicker}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Experiments/images/Schroeder}\n    \\caption{Schroeder}\\label{fig:Schroeder}\n\\end{figure}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Scaling/images/bark_traunmuller_no_fix}\n    \\caption{Schroeder}\\label{fig:bark_traunmuller_no_fix}\n\\end{figure}\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    % \\centering\n    \\hspace*{-1.8cm}\n    \\arrayrulecolor{mtblborder}\n\\begin{tabular}{ !{\\color{mtblborder}\\vrule}l!{\\color{mtblborder}\\vrule}rcccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{mtblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{Latency \\([ns]\\)}  \n    & \\color{white}\\bf{Quant.} \n    & \\color{white}\\bf{Max Err. \\([\\Delta Hz]\\)}\n    & \\color{white}\\bf{Mean Err.}\n    & \\color{white}\\bf{Std Err.} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{mtbl} Traunmuller w/ Fix   & 14 (3 C.C) & U10/5 & N.A & N.A & N.a \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Traunmuller w/o Fix  & 9 (2 C.C) &  U9/4  & 0.0443 & 0.0015 & 0.0180 \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Traunmuller's Bark scale implementations performance comparison}\n\\label{tbl:bark_implementations_performance}\n\\end{table}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{ytblborder}\n\\begin{tabular}{ !{\\color{ytblborder}\\vrule}l!{\\color{ytblborder}\\vrule}rrrrr| } \n    \\hline\n\n    \\hline\n    \\rowcolor{ytblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{FF} \n    & \\color{white}\\bf{LUT} \n    & \\color{white}\\bf{DSP} \n    & \\color{white}\\bf{LUTRAM} \n    & \\color{white}\\bf{BRAM} \\\\\n    % & \\color{white}\\bf{ORM} \n    % & \\color{white}\\bf{Clean} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{ytbl} Traunmuller w/ Fix   & 43(0.02\\%) & 302(0.26\\%) & 1(<1\\%) & 0(0\\%) & 0(0\\%)  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Traunmuller w/o Fix      & 27(0.01\\%) & 284(0.24\\%) & 1(<1\\%) & 0(0\\%)  & 0(0\\%)    \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Traunmuller's Bark scale implementations resource utilization table}\n\\label{tbl:Bark_resource_util}\n\\end{table}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{gtblborder}\n\\begin{tabular}{ |l|cc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{gtblcaption} \\color{white}\\bf{Parameter} \n    & \\color{white}\\bf{Traunmuller w/ Fix} \n    & \\color{white}\\bf{Traunmuller w/o Fix} \\\\\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Dynamic Power [W]}}\\\\\n    \\hline\n    \\rowcolor{gtbl} Signals                 & 2.380 & 2.192   \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Logic                   & 3.079 & 2.957   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} DSP                     & 1.445 & 0.014  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} I/O                     & 4.022 & 4.022  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{dynmic}}\\) & \\textbf{10.923} & \\textbf{\\color{gtblborder}9.186}  \\\\\n    \\hline\n\n    % \\hline\n    % \\rowcolor{gtbl} Bark Scale      & 56(0.02\\%) & 218(\\%) & 1(<1\\%)   \\\\\n    % % \\cline{2-8}\n    % % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Static Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} PL Static               & 0.469 & 0.437  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} PS Static               & 0.017 & 0.016   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{static}}\\) & \\textbf{0.486} & \\textbf{\\color{gtblborder}0.453}   \\\\\n    \\hline\n\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Total Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{total}}\\)  & \\textbf{11.412} & \\textbf{\\color{gtblborder}9.639}  \\\\\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Traunmuller's Bark scale implementations Power consumption}\n\\label{tbl:bark_scale_pwr_tbl}\n\\end{table}\n\n\n\\section{ERB - Equivalent Rectangular Bandwidth}\nLike the Bark scaling method, the ERB scale aims \nto rescale the audio spectrum in different \nbandwidths corresponding to the human hearing ``filters''.\n\nThis approach slightly differs from the Bark scale\nbecause the filters' model is according\nto a rectangular filter with an equivalent\nbandwidth.\n\n\\begin{align}\\label{eq:erb_eq}\n    ERBs = 11.17\\ln (47.065 - \\frac{676170.42}{f + 14678.5})    \n\\end{align}\n\nA proposed approximation is given by:\n\\begin{align}\\label{eq:erb_approx_eq}\n    ERBs = 21.4 \\cdot \\log_{10} (1 + 0.00437f)    \n\\end{align}\n\n\n% \\subsection{ERB Critical Bands}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Scaling/images/erb}\n    \\caption{LUT based ERB FPGA implementation results}\\label{fig:erb_fpga}\n\\end{figure}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Scaling/images/erb_approx}\n    \\caption{LUT based ERB approx. FPGA implementation results}\\label{fig:erb_approx}\n\\end{figure}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    % \\hspace*{-1.8cm}\n    \\arrayrulecolor{mtblborder}\n\\begin{tabular}{ !{\\color{mtblborder}\\vrule}l!{\\color{mtblborder}\\vrule}rcccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{mtblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{Latency \\([ns]\\)}  \n    & \\color{white}\\bf{Quant.} \n    & \\color{white}\\bf{Max Err. \\([\\Delta C]\\)}\n    & \\color{white}\\bf{Mean Err.}\n    & \\color{white}\\bf{Std Err.} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{mtbl} ERB   & 23 (5 C.C) & U16/10 & 0.0153 & 0.0130 & 0.0018 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} ERB Approx  & 14 (3 C.C) &  U16/10  & 6.210m & -0.408m & 0.657m \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{ERB and ERB approx performance comparison}\n\\label{tbl:erb_scale_performance}\n\\end{table}\n\nTable\\;\\ref{tbl:erb_scale_performance} presents the performance\ncomparison between the implementations of the pure ERB\nand the ERB approximation\ngiven by Equations\\;\\ref{eq:erb_eq} \nand \\ref{eq:erb_approx_eq}, respectively. The error terms\nfor the ERBs are measured in \\(\\Delta C\\), indicating the\nerror in Cams rather than in frequency units (Hz). \nEquation\\;\\ref{eq:cams_hz} can be used to convert Cams to Hz.\n\n\\begin{align}\\label{eq:cams_hz}\n    f = \\frac{676170.42}{47.065 - e^{0.0895\\cdot C}} - 14678.5\n\\end{align}\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{ytblborder}\n\\begin{tabular}{ !{\\color{ytblborder}\\vrule}l!{\\color{ytblborder}\\vrule}rrrrr| } \n    \\hline\n\n    \\hline\n    \\rowcolor{ytblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{FF} \n    & \\color{white}\\bf{LUT} \n    & \\color{white}\\bf{DSP} \n    & \\color{white}\\bf{LUTRAM} \n    & \\color{white}\\bf{BRAM} \\\\\n    % & \\color{white}\\bf{ORM} \n    % & \\color{white}\\bf{Clean} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{ytbl} ERB   & 112(0.05\\%) & 824(0.70\\%) & 1(<1\\%) & 1(0.02\\%) & 1.5(1.04\\%)  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} ERB Approx      & 103(0.04\\%) & 564(0.48\\%) & 1(<1\\%) & 1(0.01\\%)  & 1.5(1.04\\%)    \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel scaling methods resource utilization table}\n\\label{tbl:ERB_resource_util}\n\\end{table}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{gtblborder}\n\\begin{tabular}{ |l|cc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{gtblcaption} \\color{white}\\bf{Parameter} \n    & \\color{white}\\bf{ERB} \n    & \\color{white}\\bf{ERB Approx} \\\\\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Dynamic Power [W]}}\\\\\n    \\hline\n    \\rowcolor{gtbl} Signals                 & 12.691 & 5.525   \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Logic                   & 17.576 & 7.478   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} DSP                     & 0.067 & 0.049  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} I/O                     & 17.379 & 17.373  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{dynmic}}\\) & \\textbf{47.713} & \\textbf{\\color{gtblborder}31.519}  \\\\\n    \\hline\n\n    % \\hline\n    % \\rowcolor{gtbl} Bark Scale      & 56(0.02\\%) & 218(\\%) & 1(<1\\%)   \\\\\n    % % \\cline{2-8}\n    % % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Static Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} PL Static               & 2.971 & 1.510  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} PS Static               & 0.084 & 0.046   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{static}}\\) & \\textbf{3.055} & \\textbf{\\color{gtblborder}1.556}   \\\\\n    \\hline\n\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{3}{|c|}{\\bf{Total Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{total}}\\)  & \\textbf{50.768} & \\textbf{\\color{gtblborder}33.075}  \\\\\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{ERB vs. ERB approx Power consumption}\n\\label{tbl:erb_scale_pwr_tbl}\n\\end{table}\n\n\n\n\n% \\begin{table}[H]\n%     % for more info see: https://www.overleaf.com/learn/latex/tables\n%     \\centering\n%     \\begin{tabular}{|c|r|r|r|r|r|}\n%       \\hline\n%       $N$ & Latency ($\\mu s$) & FF & LUT & DSP48 & BRAM \\\\\n%       \\hline\n%         3  & 4.80  &   3889 (27.6\\%)                 &    3901 (54.9\\%)                  &   90 (25.0\\%) & 0 (0.0\\%) \\\\\n%         4  & 6.34  &  63657 (45.1\\%)                 &   64149 (90.4\\%)                  &  144 (40.0\\%) & 0 (0.0\\%) \\\\\n%         8  & 12.50 & 231199 (\\textcolor{red}{164\\%}) &  252446 (\\textcolor{red}{356\\%})  &  272 (75.6\\%) & 0 (0.0\\%) \\\\\n%         16 & 24.82 & 895377 (\\textcolor{red}{635\\%}) & 1040992 (\\textcolor{red}{1466\\%}) &  144 (40.0\\%) & 0 (0.0\\%) \\\\\n%        \\hline\n%     \\end{tabular}\n%     \\caption{\\bf{ IQRD Performance:} Latency, Resource Utilization, and Power for \\(log_{10}\\) LUT on FPGA}\n%     \\label{tbl:IQRD_perf}\n% \\end{table}\n\n\\section{Summary}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    \\centering\n    \\arrayrulecolor{ytblborder}\n\\begin{tabular}{ !{\\color{ytblborder}\\vrule}l!{\\color{ytblborder}\\vrule}rrrrr| } \n    \\hline\n\n    \\hline\n    \\rowcolor{ytblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{FF} \n    & \\color{white}\\bf{LUT} \n    & \\color{white}\\bf{DSP} \n    & \\color{white}\\bf{LUTRAM} \n    & \\color{white}\\bf{BRAM} \\\\\n    % & \\color{white}\\bf{ORM} \n    % & \\color{white}\\bf{Clean} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{ytbl} Log-Based Mel   & 82(0.04\\%) & 276(0.23\\%) & 1(<1\\%) & 10(0.02\\%) & 1.5(1.04\\%) \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Mel \\#1 Generic     & 47(0.02\\%) & 269(0.19\\%) & 1(<1\\%) & 0(0\\%)  & 0(0\\%)    \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{ytbl} Bark Scale w/ fix     & 43(0.02\\%) & 302(0.26\\%) & 1(<1\\%) & 0(0\\%) & 0(0\\%)  \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{wtbl} Bark Scale w/o fix     & 27(0.01\\%) & 284(0.24\\%) & 1(<1\\%) & 0(0\\%)  & 0(0\\%)    \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{ytbl} Approx. ERB     & 103(0.04\\%) & 564(0.48\\%) & 1(<1\\%) & 1(0.01\\%)  & 1.5(1.04\\%)    \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel-Approx, log-based Mel, Bark Scale}\n\\label{tbl:IQRD_perf}\n\\end{table}\n\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    % \\centering\n    \\hspace*{-1cm}\n    \\arrayrulecolor{gtblborder}\n\\begin{tabular}{ |l|ccccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{gtblcaption} \\color{white}\\bf{Parameter} \n    & \\color{white}\\bf{Mel LUT}\n    & \\color{white}\\bf{Mel Gen}\n    & \\color{white}\\bf{Bark w/}\n    & \\color{white}\\bf{Bark w/o}\n    & \\color{white}\\bf{Approx. ERB} \\\\\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{6}{|c|}{\\bf{Dynamic Power [W]}}\\\\\n    \\hline\n    \\rowcolor{gtbl} Signals & 4.947 & 2.916 & 2.380 & 2.192 & 5.525  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Logic & 6.50 & 3.070 & 3.079 & 2.957 & 7.478  \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} DSP & 0.014 & 0.014 & 1.445 & 0.014 & 0.049  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} I/O & 18.236 & 6.378 & 4.022 & 4.022 & 17.373  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{dynmic}}\\) & \\textbf{29.697} & \\textbf{12.379} & \\textbf{10.923} & \\textbf{9.186} & \\textbf{31.519}  \\\\\n    \\hline\n\n    % \\hline\n    % \\rowcolor{gtbl} Bark Scale      & 56(0.02\\%) & 218(\\%) & 1(<1\\%)   \\\\\n    % % \\cline{2-8}\n    % % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{6}{|c|}{\\bf{Static Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} PL Static               & 2.364 & 0.499 & 0.469 & 0.437 & 1.510  \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} PS Static               & 0.068 & 0.018 & 0.017 & 0.016 & 0.046  \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{static}}\\) & \\textbf{2.432} & \\textbf{0.517} & \\textbf{0.486} & \\textbf{0.453} & \\textbf{1.556}  \\\\\n    \\hline\n\n    \\hline\\hline\n    \\rowcolor{wtbl}\\multicolumn{6}{|c|}{\\bf{Total Power [W]}}   \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{gtbl} \\(\\mathbf{P_{total}}\\)  & \\textbf{32.13} & \\textbf{12.896} & \\textbf{11.412} & \\textbf{9.639} & \\textbf{33.075}  \\\\\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel-Approx, log-based Mel, Bark Scale Power consumption}\n\\label{tbl:sum_scale_pwr_tbl}\n\\end{table}\n\n\n\n\n% \\begin{table}[H]\n%     % for more info see: https://www.overleaf.com/learn/latex/tables\n%     \\centering\n%     \\arrayrulecolor{gtblborder}\n% \\begin{tabular}{ !{\\color{gtblborder}\\vrule}l!{\\color{gtblborder}\\vrule}rrrrrr| } \n%     \\hline\n\n%     \\hline\n%     \\rowcolor{gtblcaption} \\color{white}\\bf{Algorithm} \n%     & \\color{white}\\bf{Signals} \n%     & \\color{white}\\bf{Logic} \n%     & \\color{white}\\bf{DSP} \n%     & \\color{white}\\bf{IO} \n%     & \\color{white}\\bf{BRAM}\n%     & \\color{white}\\bf{Total} \\\\\n%     \\hline\n\n%     \\hline\n%     \\rowcolor{gtbl} Log Based Mel   & 82(0.04\\%) & 276(\\%) & 1(<1\\%) & 18 & 1.5 & 0 \\\\\n%     \\hline\n    \n%     \\hline\n%     \\rowcolor{wtbl} Approx. Mel     & 47(0.02\\%) & 230(\\%) & 1(<1\\%) & 0  & 0   & 0 \\\\\n%     \\hline\n    \n%     \\hline\n%     \\rowcolor{gtbl} Bark Scale      & 56(0.02\\%) & 218(\\%) & 1(<1\\%) & 0  & 0   & 0 \\\\\n%     % \\cline{2-8}\n%     % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n%     \\hline\n\n%     \\hline\n% \\end{tabular}\n% \\arrayrulecolor{black}\n% \\caption{Mel-Approx, log based Mel, Bark Scale Power consumption}\n% \\label{tbl:scale_pwr_tbl}\n% \\end{table}\n\n\n\\begin{table}[H]\n    % for more info see: https://www.overleaf.com/learn/latex/tables\n    % \\centering\n    \\hspace*{-1.8cm}\n    \\arrayrulecolor{mtblborder}\n\\begin{tabular}{ !{\\color{mtblborder}\\vrule}l!{\\color{mtblborder}\\vrule}rcccc| } \n    \\hline\n\n    \\hline\n    \\rowcolor{mtblcaption} \\color{white}\\bf{Algorithm} \n    & \\color{white}\\bf{Latency \\([ns]\\)}  \n    & \\color{white}\\bf{Quant.} \n    & \\color{white}\\bf{Max Err. \\([\\Delta Hz]\\)}\n    & \\color{white}\\bf{Mean Err.}\n    & \\color{white}\\bf{Std Err.} \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{mtbl} Log-Based Mel   & 14 (3 C.C) & U16/4 & 1.146 & 0.268 & 0.106 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{wtbl} Mel \\#1 Generic     & 9 (2 C.C) &  U16/4  & 0.174 & -0.035 & 0.061 \\\\\n    \\hline\n    \n    \\hline\n    \\rowcolor{mtbl} Bark Scale w/ fix      & 14 (3 C.C) &  U10/5 & N.A & N.A & N.A \\\\\n    % \\cline{2-8}\n    % \\multirow{-2}{*}{\\cellcolor{ytbl}\\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\\\ \n    \\hline\n\n    \\hline\n    \\rowcolor{wtbl} Bark Scale w/o fix     & 9 (2 C.C) &  U9/4  & 0.0443 & 1.5m & 0.0015 \\\\\n    \\hline\n\n    \\hline\n    \\rowcolor{mtbl} ERB Approx.     & 14 (3 C.C) &  U16/10  & 0.292 & 0.104 & 0.134 \\\\\n    \\hline\n\n    \\hline\n\\end{tabular}\n\\arrayrulecolor{black}\n\\caption{Mel-Approx, log-based Mel, Bark Scale performance comparison}\n\\label{tbl:scale_pwr_tbl}\n\\end{table}\n\n\n\n", "meta": {"hexsha": "b9eacd1127bf8cb0d644d74b3405fa28ff05bcf6", "size": 33149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/Scaling/scaling.tex", "max_stars_repo_name": "aviadb/research", "max_stars_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Dissertation/Scaling/scaling.tex", "max_issues_repo_name": "aviadb/research", "max_issues_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Dissertation/Scaling/scaling.tex", "max_forks_repo_name": "aviadb/research", "max_forks_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_forks_repo_licenses": ["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.4506641366, "max_line_length": 196, "alphanum_fraction": 0.630456424, "num_tokens": 11851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6370019117386725}}
{"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\\usepackage{pgfplots}\n\\usepackage[RPvoltages, american, betterproportions, siunitx]{circuitikz}\n\\pgfplotsset{compat=1.16}\n\\pgfplotsset{scaled x ticks=true}\n\n\\title{ECE 203 Problem Set 5}\n\\author{Michael Kwok}\n\\date{March 2020}\n\\begin{document}\n\n\\maketitle\n\\begin{multicols}{2}\n\\section*{1}\n\\subsection*{a}\n\n\\begin{align*}\n    \\omega_0 &= \\frac{1}{\\sqrt{L C}} = \\boxed{\\SI{1390.77}{\\radian\\per\\second}}\\\\\n    f_0 &= \\frac{\\omega_0}{2\\pi} = \\boxed{\\SI{221.3}{\\hertz}}\\\\\n    Q_0 &= \\omega_0 R C\\\\\n    &= 1390.77 \\cdot 1000 \\cdot \\num{47d-6} = \\boxed{65.37}\n\\end{align*}\n\n\\subsection*{b}\n\n\\begin{align*}\n    \\omega_0 \\text{ parallel} &= \\omega_0 \\text{ series}\\\\\n    f_0 \\text{ parallel} &= f_0 \\text{ series}\\\\\n    Q_0 \\text{ series} &= \\frac{1}{Q_0 \\text{ parallel}}\\\\\n\\end{align*}\n\\begin{align*}\n    \\omega_0 &= \\boxed{\\SI{1390.77}{\\radian\\per\\second}}\\\\\n    f_0 &= \\boxed{\\SI{221.3}{\\hertz}}\\\\\n    Q_0 &= \\boxed{0.0153}\n\\end{align*}\n\n\\subsection*{c}\n\nThe parallel configuration is better as the quality factor is higher, which by definition means that the filter is more selective.\n\n\\section*{2}\n\\subsection*{a}\n\n\\begin{align*}\n    Q_0 &= \\omega_0 R C\\\\\n    \\omega_0 &= 2\\pi f_0 \\\\\n    Q_0 &= 2\\pi f_0 R C\\\\\n\\end{align*}\n\n\\begin{align*}\n    R  &= \\frac{V}{I}\\\\\n       &= \\frac{\\num{125e-3}}{2e-6}\\\\\n       &= \\boxed{\\SI{62500}{\\ohm}}\\\\\n    RC &= \\frac{40}{2\\pi \\cdot 1000000}\\\\\n    C  &= \\frac{\\num{6.366197724e-6}}{62500}\\\\\n       &= \\SI{1.018591636e-10}{\\farad}\\\\\n       &= \\boxed{\\SI{102}{\\pico\\farad}}\n\\end{align*}\n\\begin{align*}\n    \\omega_0 &= \\frac{1}{\\sqrt{LC}}\\\\\n    \\num{2\\pi e-6} &= \\frac{1}{\\sqrt{LC}}\\\\\n    LC &= \\left(\\frac{1}{\\num{2\\pi e-6}}\\right)^2\\\\\n    L &= \\boxed{\\num{2.5e-4}}\n\\end{align*}\n\n\\subsection*{b}\n\\begin{align*}\n\\text{Using Z at } \\omega = 2000,\\\\\nR= \\boxed{\\SI{8}{\\kilo\\ohm}}\n\\end{align*}\n\\begin{align*}\n    Z&=\\left( \\frac{1}{R} + \\frac{1}{j \\omega L} + j \\omega C \\right) ^{-1}\\\\\n    \\frac{1}{4000} e^{-j \\theta} &= \\frac{1}{8000} + \\frac{1}{1800 L j} + 1800 C j\\\\\n    \\frac{1}{4000} \\cos \\theta &= \\frac{1}{8000}\\\\\n    \\cos\\theta &= \\frac{1}{2}\\\\\n    \\theta &= \\frac{\\pi}{3}\n\\end{align*}\n\\begin{align*}\n    -j\\frac{1}{4000} \\sin\\theta &= -j\\left( \\frac{1}{1800L} - 1800 C\\right)\\\\\n    \\frac{1800L}{4000} \\sin\\theta &= -(1800)^2 LC + 1\\\\\n    \\omega_0 &= 2000\\\\\n    &= \\frac{1}{\\sqrt{LC}}\\\\\n    LC&= \\frac{1}{\\num{4e6}}\\\\\n\\end{align*}\n\\begin{align*}\n    L\\sin\\theta &= 0.4222\\\\\n    L &= \\boxed{\\SI{0.488}{\\henry}}\\\\\n    C &= \\boxed{\\SI{5.133e-7}{\\farad}}\n\\end{align*}\n\n\\section*{3}\n\\subsection*{a}\n\\begin{align*}\n    Z_{in} &= 10 + j\\omega 3 + \\left( \\frac{1}{75} + \\frac{1}{15 + \\frac{675}{j\\omega}} \\right) ^{-1}\\\\\n    &= \\frac{90\\omega + (6 \\omega^2 - 1275)j}{2\\omega - 15j}\\\\\n    &= \\frac{\\left[ 90\\omega + (6 \\omega^2 - 1275)j \\right] [2\\omega + 15j]}{4\\omega^2 + 15^2}\\\\\n    &= \\frac{90\\omega^2 +19125 + \\left( 12\\omega^3 -1200 \\omega j \\right)}{4\\omega^2 + 15^2}\n\\end{align*}\n\\begin{align*}\n    12\\omega^3-1200\\omega &= 0\\\\\n    12\\omega^3 &= 1200\\omega\\\\\n    \\omega^2 &= 100\\\\\n    \\omega &= \\boxed{\\SI{10}{\\radian\\per\\second}}\n\\end{align*}\n\n\\subsection*{b}\n\\begin{align*}\n    Z_{in} &= 10 + 30j + \\left( \\frac{1}{75} + \\frac{1}{15 + \\frac{675}{j10}} \\right)^{-1}\\\\\n    &= 10 + 30j - 30j + 35\\\\\n    &= \\boxed{\\SI{45}{\\ohm}}\n\\end{align*}\n\n\\section*{4}\nUse a test voltage $V_{in}$\n\n\\begin{circuitikz}\n\\draw (0,0) to[V=$V_{in}$] (0,2) -- (4,2);\n\\draw (0,0) -- (7,0) to[cV] (7,2);\n\\draw (2,2) to[C, i=$I_C$](2,0);\n\\draw (4,0) to[R, i=$I_R$](4,2);\n\\draw (4,2) to[L] (7,2);\n\\end{circuitikz}\n\n\\begin{align*}\n    I_C &= V_{in}\\num{e-8}j\\omega\\\\\n    I_R &= -\\frac{V_{in}}{10000}\\\\\n\\end{align*}\n    Using KCL on node above resistor,\n\\begin{align*}\n    -I_C + I_R &+\\frac{V_{in} - \\num{e5}I_R}{\\num{4.4e-3}j\\omega } = 0\\\\\n    -V_{in}\\num{e-8}j\\omega-\\frac{V_{in}}{10000} &+\\frac{V_{in} - \\num{e5}I_R}{\\num{4.4e-3}j\\omega} = 0\\\\\n    Y = &\\frac{V_{in}\\num{e-8}j\\omega +\\frac{V_{in}}{10000} +\\frac{V_{in} \\left( 1+\\frac{\\num{e5}}{10000}\\right)}{\\num{4.4e-3}j\\omega}}{V_{in}}\\\\\n    = &\\boxed{\\num{e-8}j\\omega +\\frac{1}{10000} -\\frac{2500}{\\omega}j}\n\\end{align*}\nFinding $\\omega_0$ and $Q_0$.\n\n$\\omega_0$ is when coefficient of $j = 0$\n\\begin{align*}\n    \\text{Start with: }\\num{e-8}j\\omega&+\\frac{1}{10000} -\\frac{2500}{\\omega}j\\\\\n    \\num{e-8}j\\omega &-\\frac{2500}{\\omega}j = 0\\\\\n    \\omega^2 &= \\num{2.5e4}\\\\\n    \\omega &= \\boxed{\\SI{500}{\\kilo\\radian}}\\\\\n    Q_0 &= \\omega_0 R C\\\\\n    &\\boxed{= 50}\n\\end{align*}\n\\section*{5}\n\\subsection*{a}\n$H_{dB} = 20 \\log(|\\tilde{H}(j\\omega)|)$\n\\begin{enumerate}\n    \\item $20 \\log(0.2) = \\boxed{-13.979}$\n    \\item $20 \\log(13) = \\boxed{22.3}$\n    \\item $20 \\log(|\\frac{100}{23j +21}|) = \\log(|\\frac{2300 j - 2100}{23^2+21^2}|) = 20 \\log(3.21) = \\boxed{10.13}$\n\\end{enumerate}\n\\subsection*{b}\n$|\\tilde{H}(j\\omega)| = 10^{\\frac{H_{dB}}{20}}$\n\\begin{enumerate}\n    \\item $|\\tilde{H}(j\\omega)| = \\boxed{39.8}$\n    \\item $|\\tilde{H}(j\\omega)| = \\boxed{0.447}$\n    \\item $|\\tilde{H}(j\\omega)| = \\boxed{1.00}$\n\\end{enumerate}\n\\end{multicols}\n\\subsection*{c}\n\\begin{align*}\n    \\tilde{H}(j\\omega) &= \\frac{V_{out}}{V_{in}}\\\\\n    Z &= 1+ \\frac{1}{j\\omega \\num{100e-6}}\\\\\n    \\tilde{H}(j\\omega) &= \\frac{1}{1 + j\\omega\\num{100e-6}}\\\\\n    H_{dB} &= 20 \\log(|\\tilde{H}(j\\omega)|) = 20\\log\\left(\\frac{1}{\\num{e-8}\\omega^{2} + 1}\\right)\\\\\n    \\angle\\tilde{H}(j\\omega) &= -\\arctan\\left(0.0001\\omega\\right)\n\\end{align*}\n\\begin{figure}\n    \\centering\n\\begin{tikzpicture}\n\\begin{axis}[xmode=log,\nxmin=1,\nxmax=1000000,\nymin=-40,\nymax=10,\ngrid=both]\n\\addplot table [smooth, x={omega}, y={result}, col sep=comma, mark=none]{res1.csv};\n\\addplot[gray,ultra thick, opacity=0.6] coordinates {\n(1,0)\n(10000,0)\n(99500, -40)};\n\\end{axis}\n\\end{tikzpicture}\n    \\caption{Magnitude bode plot}\n    \\label{fig:my_label}\n\\end{figure}\n\\begin{figure}\n    \\centering\n\\begin{tikzpicture}\n\\begin{axis}[xmode=log,\nxmin=1,\nxmax=1000000,\nymin=-135,\nymax=45,\nytick={45,0,-45,-90,-135},\ngrid=both]\n\\addplot table [smooth, x={omega}, y={atan}, col sep=comma, mark=none]{res1.csv};\n\\addplot[gray,ultra thick, opacity=0.6] coordinates {\n(1,0)\n(1000,0)\n(100000,-90)\n(1000000, -90)};\n\\end{axis}\n\\end{tikzpicture}\n    \\caption{Phase bode plot}\n    \\label{fig:label2}\n\\end{figure}\n\\end{document}\n", "meta": {"hexsha": "ad0c0fd93e897790aa2c7348d281c58ca2ef1f61", "size": 6379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/ECE203/ECE203PS5.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/ECE203/ECE203PS5.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/ECE203/ECE203PS5.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": 29.3963133641, "max_line_length": 145, "alphanum_fraction": 0.578147045, "num_tokens": 2878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6370019043610861}}
{"text": "\\section{Algebraic Structures}\n\n\\subsection{COFE}\n\n\\begin{defn}[Chain]\n  Given some set $T$ and an indexed family $({\\nequiv{n}} \\subseteq T \\times T)_{n \\in \\mathbb{N}}$ of equivalence relations, a \\emph{chain} is a function $c : \\mathbb{N} \\to T$ such that $\\All n, m. n \\leq m \\Ra c (m) \\nequiv{n} c (n)$.\n\\end{defn}\n\n\\begin{defn}\n  A \\emph{complete ordered family of equivalences} (COFE) is a tuple $(T, ({\\nequiv{n}} \\subseteq T \\times T)_{n \\in \\mathbb{N}}, \\lim : \\chain(T) \\to T)$ satisfying\n  \\begin{align*}\n    \\All n. (\\nequiv{n}) ~& \\text{is an equivalence relation} \\tagH{cofe-equiv} \\\\\n    \\All n, m.& n \\geq m \\Ra (\\nequiv{n}) \\subseteq (\\nequiv{m}) \\tagH{cofe-mono} \\\\\n    \\All x, y.& x = y \\Lra (\\All n. x \\nequiv{n} y) \\tagH{cofe-limit} \\\\\n    \\All n, c.& \\lim(c) \\nequiv{n} c(n+1) \\tagH{cofe-compl}\n  \\end{align*}\n\\end{defn}\n\n\\ralf{Copy the explanation from the paper, when that one is more polished.}\n\n\\begin{defn}\n  An element $x \\in A$ of a COFE is called \\emph{discrete} if\n  \\[ \\All y \\in A. x \\nequiv{0} y \\Ra x = y\\]\n  A COFE $A$ is called \\emph{discrete} if all its elements are discrete.\n\\end{defn}\n\n\\begin{defn}\n  A function $f : A \\to B$ between two COFEs is \\emph{non-expansive} if\n  \\[\\All n, x \\in A, y \\in A. x \\nequiv{n} y \\Ra f(x) \\nequiv{n} f(y) \\]\n  It is \\emph{contractive} if\n  \\[ \\All n, x \\in A, y \\in A. (\\All m < n. x \\nequiv{m} y) \\Ra f(x) \\nequiv{n} f(x) \\]\n\\end{defn}\n\n\\begin{defn}\n  The category $\\COFEs$ consists of COFEs as objects, and non-expansive functions as arrows.\n\\end{defn}\nNote that $\\COFEs$ is cartesian closed.\n\n\\begin{defn}\n  A functor $F : \\COFEs \\to COFEs$ is called \\emph{locally non-expansive} if its actions $F_1$ on arrows is itself a non-expansive map.\n  Similarly, $F$ is called \\emph{locally contractive} if $F_1$ is a contractive map.\n\\end{defn}\n\n\\subsection{RA}\n\n\\ralf{Define this, including frame-preserving updates.}\n\n\\subsection{CMRA}\n\n\\begin{defn}\n  A \\emph{CMRA} is a tuple $(\\monoid, (\\mval_n \\subseteq \\monoid)_{n \\in \\mathbb{N}}, \\mcore{-}: \\monoid \\to \\monoid, (\\mtimes) : \\monoid \\times \\monoid \\to \\monoid, (\\mdiv) : \\monoid \\times \\monoid \\to \\monoid)$ satisfying\n  \\begin{align*}\n    \\All n, m.& n \\geq m \\Ra V_n \\subseteq V_m \\tagH{cmra-valid-mono} \\\\\n    \\All \\melt, \\meltB, \\meltC.& (\\melt \\mtimes \\meltB) \\mtimes \\meltC = \\melt \\mtimes (\\meltB \\mtimes \\meltC) \\tagH{cmra-assoc} \\\\\n    \\All \\melt, \\meltB.& \\melt \\mtimes \\meltB = \\meltB \\mtimes \\melt \\tagH{cmra-comm} \\\\\n    \\All \\melt.& \\mcore\\melt \\mtimes \\melt = \\melt \\tagH{cmra-core-id} \\\\\n    \\All \\melt.& \\mcore{\\mcore\\melt} = \\mcore\\melt \\tagH{cmra-core-idem} \\\\\n    \\All \\melt, \\meltB.& \\melt \\leq \\meltB \\Ra \\mcore\\melt \\leq \\mcore\\meltB \\tagH{cmra-core-mono} \\\\\n    \\All n, \\melt, \\meltB.& (\\melt \\mtimes \\meltB) \\in \\mval_n \\Ra \\melt \\in \\mval_n \\tagH{cmra-valid-op} \\\\\n    \\All \\melt, \\meltB.& \\melt \\leq \\meltB \\Ra \\melt \\mtimes (\\meltB \\mdiv \\melt) = \\meltB \\tagH{cmra-div-op} \\\\\n    \\All n, \\melt, \\meltB_1, \\meltB_2.& \\omit\\rlap{$\\melt \\in \\mval_n \\land \\melt \\nequiv{n} \\meltB_1 \\mtimes \\meltB_2 \\Ra {}$} \\\\\n    &\\Exists \\meltC_1, \\meltC_2. \\melt = \\meltC_1 \\mtimes \\meltC_2 \\land \\meltC_1 \\nequiv{n} \\meltB_1 \\land \\meltC_2 \\nequiv{n} \\meltB_2 \\tagH{cmra-extend} \\\\\n    \\text{where}\\qquad\\qquad\\\\\n    \\melt \\leq \\meltB \\eqdef{}& \\Exists \\meltC. \\meltB = \\melt \\mtimes \\meltC \\tagH{cmra-incl}\n  \\end{align*}\n\\end{defn}\n\nNote that every RA is a CMRA, by picking the discrete COFE for the equivalence relation.\n\n\\ralf{Copy the rest of the explanation from the paper, when that one is more polished.}\n\n\\paragraph{The division operator $\\mdiv$.}\nOne way to describe $\\mdiv$ is to say that it extracts the witness from the extension order: If $\\melt \\leq \\meltB$, then $\\melt \\mdiv \\meltB$ computes the difference between the two elements (\\ruleref{cmra-div-op}).\nOtherwise, $\\mdiv$ can have arbitrary behavior.\nThis means that, in classical logic, the division operator can be defined for any PCM using the axiom of choice, and it will trivially satisfy \\ruleref{cmra-div-op}.\nHowever, notice that the division operator also has to be \\emph{non-expansive} --- so if the carrier $\\monoid$ is equipped with a non-trivial $\\nequiv{n}$, there is an additional proof obligation here.\nThis is crucial, for the following reason:\nConsidering that the extension order is defined using \\emph{equality}, there is a natural notion of a \\emph{step-indexed extension} order using the step-indexed equivalence of the underlying COFE:\n\\[ \\melt \\mincl{n} \\meltB \\eqdef \\Exists \\meltC. \\meltB \\nequiv{n} \\melt \\mtimes \\meltC \\tagH{cmra-inclM} \\]\nOne of the properties we would expect to hold is the usual correspondence between a step-indexed predicate and its non-step-indexed counterpart:\n\\[ \\All \\melt, \\meltB. \\melt \\leq \\meltB \\Lra (\\All n. \\melt \\mincl{n} \\meltB) \\tagH{cmra-incl-limit} \\]\nThe right-to-left direction here is trick.\nFor every $n$, we obtain a proof that $\\melt \\mincl{n} \\meltB$.\nFrom this, we could extract a sequence of witnesses $(\\meltC_m)_{m}$, and we need to arrive at a single witness $\\meltC$ showing that $\\melt \\leq \\meltB$.\nWithout the division operator, there is no reason to believe that such a witness exists.\nHowever, since we can use the division operator, and since we know that this operator is \\emph{non-expansive}, we can pick $\\meltC \\eqdef \\meltB \\mdiv \\melt$, and then we can prove that this is indeed the desired witness.\n\\ralf{Do we actually need this property anywhere?}\n\n\\paragraph{The extension axiom (\\ruleref{cmra-extend}).}\nNotice that the existential quantification in this axiom is \\emph{constructive}, \\ie it is a sigma type in Coq.\nThe purpose of this axiom is to compute $\\melt_1$, $\\melt_2$ completing the following square:\n\n\\ralf{Needs some magic to fix the baseline of the $\\nequiv{n}$, or so}\n\\begin{center}\n\\begin{tikzpicture}[every edge/.style={draw=none}]\n  \\node (a) at (0, 0) {$\\melt$};\n  \\node (b) at (1.7, 0) {$\\meltB$};\n  \\node (b12) at (1.7, -1) {$\\meltB_1 \\mtimes \\meltB_2$};\n  \\node (a12) at (0, -1) {$\\melt_1 \\mtimes \\melt_2$};\n\n  \\path (a) edge node {$\\nequiv{n}$} (b);\n  \\path (a12) edge node {$\\nequiv{n}$} (b12);\n  \\path (a) edge node [rotate=90] {$=$} (a12);\n  \\path (b) edge node [rotate=90] {$=$} (b12);\n\\end{tikzpicture}\\end{center}\nwhere the $n$-equivalence at the bottom is meant to apply to the pairs of elements, \\ie we demand $\\melt_1 \\nequiv{n} \\meltB_1$ and $\\melt_2 \\nequiv{n} \\meltB_2$.\nIn other words, extension carries the decomposition of $\\meltB$ into $\\meltB_1$ and $\\meltB_2$ over the $n$-equivalence of $\\melt$ and $\\meltB$, and yields a corresponding decomposition of $\\melt$ into $\\melt_1$ and $\\melt_2$.\nThis operation is needed to prove that $\\later$ commutes with existential quantification and separating conjunction:\n\\begin{mathpar}\n  \\axiom{\\later(\\Exists\\var:\\type. \\prop) \\Lra \\Exists\\var:\\type. \\later\\prop}\n  \\and\\axiom{\\later (\\prop * \\propB) \\Lra \\later\\prop * \\later\\propB}\n\\end{mathpar}\n(This assumes that the type $\\type$ is non-empty.)\n\n\\begin{defn}\n  An element $\\munit$ of a CMRA $\\monoid$ is called the \\emph{unit} of $\\monoid$ if it satisfies the following conditions:\n  \\begin{enumerate}[itemsep=0pt]\n  \\item $\\munit$ is valid: \\\\ $\\All n, \\munit \\in \\mval_n$\n  \\item $\\munit$ is left-identity of the operation: \\\\\n    $\\All \\melt \\in M. \\munit \\mtimes \\melt = \\melt$\n  \\item $\\munit$ is discrete\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{defn}\n  It is possible to do a \\emph{frame-preserving update} from $\\melt \\in \\monoid$ to $\\meltsB \\subseteq \\monoid$, written $\\melt \\mupd \\meltsB$, if\n  \\[ \\All n, \\melt_f. \\melt \\mtimes \\melt_f \\in \\mval_n \\Ra \\Exists \\meltB \\in \\meltsB. \\meltB \\mtimes \\melt_f \\in \\mval_n \\]\n\n  We further define $\\melt \\mupd \\meltB \\eqdef \\melt \\mupd \\set\\meltB$.\n\\end{defn}\nNote that for RAs, this and the RA-based definition of a frame-preserving update coincide.\n\n\\ralf{Describe discrete CMRAs, and how they correspond to RAs.}\n\n\\begin{defn}\n  A function $f : M \\to N$ between two CMRAs is \\emph{monotone} if it satisfies the following conditions:\n  \\begin{enumerate}[itemsep=0pt]\n  \\item $f$ is non-expansive\n  \\item $f$ preserves validity: \\\\\n    $\\All n, x \\in M. x \\in \\mval_n \\Ra f(x) \\in \\mval_n$\n  \\item $f$ preserves CMRA inclusion:\\\\\n    $\\All x, y. x \\mincl y \\Ra f(x) \\mincl f(y)$\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{defn}\n  The category $\\CMRAs$ consists of CMRAs as objects, and monotone functions as arrows.\n\\end{defn}\nNote that $\\CMRAs$ is a subcategory of $\\COFEs$.\nThe notion of a locally non-expansive (or contractive) functor naturally generalizes to functors between these categories.\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"iris\"\n%%% End: \n", "meta": {"hexsha": "63cb6f8189feb8f5c0f8b216e41b584edb4db197", "size": 8662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/algebra.tex", "max_stars_repo_name": "amintimany/iris-backup", "max_stars_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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/algebra.tex", "max_issues_repo_name": "amintimany/iris-backup", "max_issues_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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/algebra.tex", "max_forks_repo_name": "amintimany/iris-backup", "max_forks_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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.1719745223, "max_line_length": 237, "alphanum_fraction": 0.6804433156, "num_tokens": 3135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942232112239, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6369378451908307}}
{"text": "\r\n\\input{SingleAssignmentSetup.tex}\r\n\\input{../WeekTitles.tex}\r\n\\begin{document}\r\n\r\n\r\n\\begin{center}\r\n\\subsection*{MNTC P01 - Week \\#4 - \\WeekTitleFour}\r\n\\end{center}\r\n\r\n\\begin{enumerate}[1.]\r\n\\subsection*{Distance And Velocity}\r\n\r\n\\begin{multicols}{2}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The graph below shows the velocity, $v$, of an object (in\r\n    meters/sec). Estimate the total distance the object traveled\r\n    between $t = 0$ and $t = 6$.\r\n\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week04_DistanceAndVelocity/Velocity_1}\r\n    \r\n  \\end{Question}\r\n  \\begin{Solution}\r\n    Just counting the squares (each of which has area representing 10\r\n    (m/s)$\\cdot$(s) = 10 m of distance), and allowing for the partial\r\n    squares, we can see that the area under the curve from $t=0$ to\r\n    $t=6$ is between 140 and 150 units.  Therefore the distance\r\n    traveled is between 140 and 150 meters.\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The figure below shows the velocity of a particle, in cm/sec,\r\n    along the $t$-axis for $-3 \\le t \\le 3$ ($t$ in seconds). \r\n    \\begin{enumerate}\r\n    \\item Describe the motion in words. Is the particle changing\r\n      direction or always moving in the same direction? Is the\r\n      particle speeding up or slowing down?\r\n    \\item Make over- and underestimates of the distance traveled for \r\n      $-3 \\le t \\le 3$.\r\n    \\end{enumerate}\r\n\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week04_DistanceAndVelocity/Velocity_2}\r\n  \\end{Question}\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item The velocity is always positive, so the particle is moving\r\n      in the same direction throughout.  However, the particle is\r\n      speeding up until shortly before $t=0$, and slowing down\r\n      thereafter.\r\n    \\item The distance traveled is represented by the area under the\r\n      curve.  Using whole grid squares, we can overestimate the area\r\n      as 3+3+3+3+2+1 = 15 squares, and we can underestimate the area\r\n      as 1+2+2+1+0+0= 6 squares.  Each square represents 1\r\n      (cm/sec)$\\cdot$(s) = 1 cm, so the particle moved in one\r\n      direction between 6 and 15 cm.\r\n\r\n    \\end{enumerate}\r\n    \r\n  \\end{Solution}\r\n\r\n\r\n%*****************\r\n  \\begin{Question}\r\nFor questions \\ref{q:graph1_start} to \\ref{q:graph1_end}, the graph\r\n  shows the velocity, in cm/sec, of a particle moving along the\r\n  $x$-axis. Compute the particle's change in position, left (negative)\r\n  or right (positive), between times $t = 0$ and $t = 5$ seconds.\r\n\\end{Question}\r\n\r\n\\item ~\\\\\\label{q:graph1_start} \r\n  \\begin{Question}\r\n\r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity1}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    The velocity is constant and negative, so the change in position is $-3 \\cdot 5$ cm, that is 15 cm to the left.\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item ~\\\\\r\n  \\begin{Question}\r\n    \r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity2}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    From $t = 0$ to $t = 3$, the velocity is constant and positive, so\r\n    the change in position is $2 \\cdot 3$ cm, that is 6 cm to the right. \\\\\r\n    From $t = 3$ to $t = 5$, the velocity is negative and constant, so\r\n    the\r\n    change in position is $3 \\cdot 2$ cm, that is 6 cm to the left.  \\\\\r\n    Thus the total change in position is 0. The particle moves 6 cm to\r\n    the right, followed by 6 cm to the left, and returns to where it\r\n    started.\r\n  \\end{Solution}\r\n\r\n%******************\r\n\\item ~ \\\\\r\n  \\begin{Question}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity3}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    From $t = 0$ to $t = 5$ the velocity is positive so the change in\r\n    position is to the right. The area under the velocity graph gives\r\n    the distance traveled. The region is a triangle, and so has area\r\n    $(1/2)bh = (1/2)5 \\cdot 10 = 25$. Thus the change in position is 25 cm\r\n    to the right.\r\n  \\end{Solution}\r\n\r\n%******************\r\n\\item  ~ \\\\\\label{q:graph1_end}\r\n  \\begin{Question}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity4}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    From $t = 0$ to $t = 4$ the velocity is positive so the change in\r\n    position is to the right. The area under the velocity graph gives\r\n    the distance traveled. The region is a triangle, and so has area\r\n    $(1/2)bh = (1/2)4\\cdot 8 = 16$. Thus the change in position is 16 cm\r\n    to the right for$ t = 0$ to $t = 4$. \r\n\r\n    From $t = 4$ to $t = 5$, the velocity is negative so the change in\r\n    position is to the left. The distance traveled to the left is\r\n    given by the area of the triangle, $(1/2)bh = (1/2)1\\cdot 2 =\r\n    1$. \r\n\r\n    Thus the total change in position is $16-1= 15$ cm to the\r\n    right.\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n\\begin{Question}\r\n A car going 80 ft/s ( about 90 km/h) brakes to a stop in five seconds. Assume the deceleration is constant. \r\n \\begin{enumerate}\r\n \\item Graph the velocity against time, $t$, for $0 \\le t \\le 5$ seconds. \r\n \\item Represent, as an area on the graph, the total distance traveled\r\n   from the time the brakes are applied until the car comes to a stop.\r\n \\item Find this area and hence the distance traveled. \r\n% \\item Now find the total distance traveled using antidifferentiation.\r\n \\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}\r\n    \\item  ~\\\\\r\n\\includegraphics*[width=0.8\\linewidth]{graphics/Week04_DistanceAndVelocity/graph_car_decel}\r\n\\item The total distance is represented by the shaded region $A$, the area under the graph of $v(t)$.\r\n\\item $A$ is a triangle, so its area is \r\n$$A = \\frac{1}{2} \\mbox{(base)(height)} = \\frac{1}{2} (5 \\mbox{ sec})(80 \\mbox{ ft/s}) = 200 \\mbox{ ft}$$\r\n%\\item \r\n    \\end{enumerate}\r\n    \r\n  \\end{Solution}\r\n\r\n\r\n%******************\r\n\\item\r\n  \\begin{Question}\r\n     A baseball thrown directly upward at 96 ft/sec has velocity $v(t) = 96 - 32t$ ft/ sec at time $t$ seconds.\r\n     \\begin{enumerate}[(a)]\r\n\\item Graph the velocity from $t = 0$ to $t = 6$. \r\n\\item When does the baseball reach the peak of its flight? How high does it go? \r\n\\item How high is the baseball at time $t = 5$?\r\n     \\end{enumerate}\r\n  \\end{Question}\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item  See the figure below.\r\n\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week04_DistanceAndVelocity/ChangeInPosition_2}\r\n\r\n\\item The peak of the flight is when the velocity is 0, namely $t =\r\n  3$. The height at $t = 3$ is given by the area under the graph of\r\n  the velocity from $t = 0$ to $t = 3$; see the figure above. The\r\n  region is a triangle of base 3 seconds and altitude 96 ft/sec, so\r\n  the height is $(1/2)3 \\cdot 96 = 144$ feet.\r\n\\item The velocity is negative from $t = 3$ to $t = 5$, so the motion\r\n  is downward then. The distance traveled downward can be calculated\r\n  by the area of the triangular region which has base of 2 seconds and\r\n  altitude of -64 ft/sec. Thus, the baseball travels $(1/2)2 \\cdot 64\r\n  = 64$ feet downward from its peak height of 144 feet at $t =\r\n  3$. Thus, the height at time $t = 5$ is the total change in\r\n  position, $144 - 64 = 80$ feet.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n%******************\r\n\\item\r\n  \\begin{Question}\r\n    Two cars start at the same time and travel in the same direction\r\n    along a straight road. The graph below gives the velocity, $v$, of\r\n    each car as a function of time, $t$. Which car:\r\n  \\begin{enumerate}[(a)]\r\n  \\item Attains the larger maximum velocity? \r\n  \\item Stops first? \r\n  \\item Travels farther?\r\n  \\end{enumerate}\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week04_DistanceAndVelocity/CarVelocity1}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Car A has the largest maximum velocity because the peak of\r\n      car A's velocity curve is higher than the peak of B's.\r\n    \\item Car A stops first because the curve representing its\r\n      velocity hits zero (on the $t$-axis) first.\r\n    \\item Car B travels farther because the {\\bf area} under car B's\r\n      velocity curve is the larger, and area under the velocity graph\r\n      reprsents distance.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n%******************\r\n\\item\r\n  \\begin{Question}\r\n    Two cars travel in the same direction along a straight road. The graph below shows the velocity, $v$, of each car at time $t$. Car B starts 2 hours after car A and car B reaches a maximum velocity of 50 km/ hr. \r\n    \\begin{enumerate}[(a)]\r\n    \\item For approximately how long does each car travel? \\item\r\n      Estimate car A's maximum velocity. \\item Approximately how far\r\n      does each car travel?\r\n    \\end{enumerate}\r\n\\includegraphics[width=0.7\\linewidth]{graphics/Week04_DistanceAndVelocity/CarVelocity2}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Since car B starts at $t = 2$, the tick marks on the\r\n      horizontal axis (which we assume are equally spaced) are 2 hours\r\n      apart. Thus car B stops at $t = 6$ and travels for 4 hours.  Car\r\n      A starts at $t = 0$ and stops at $t = 8$, so it travels for 8\r\n      hours.\r\n    \\item Car A's maximum velocity is approximately twice that of car B (50 km/h), so A's max velocity is 100 km/hr.\r\n    \\item The distance traveled is given by the area of under the\r\n      velocity graph. Using the formula for the area of a triangle,\r\n      the distances are given by\r\n\\begin{align*}\r\n\\mbox{Car A travels} &=\r\n\\frac{1}{2} \\cdot \\mbox{Base }\\cdot \\mbox{Height} \\\\\r\n& = \\frac{1}{2} \\cdot 8 \\cdot 100 = 400 \\mbox{ km} \\\\\r\n\\mbox{Car B travels} &=\r\n\\frac{1}{2} \\cdot \\mbox{Base }\\cdot \\mbox{Height}\\\\\r\n& = \\frac{1}{2} \\cdot 4 \\cdot 50 = 100 \\mbox{ km}. \\\\\r\n\\end{align*}\r\n    \r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n\\end{multicols}\r\n\\hrulefill\r\n\\subsection*{The Definite Integral}\r\n\r\n\\begin{multicols}{2}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The figure below shows a Riemann sum approximation with $n$ subdivisions to $\\ds \\int_a^bf(x) dx$.\r\n    \\begin{enumerate}\r\n    \\item Is it a left- or right-hand approximation? Would the other one be larger or smaller? \r\n    \\item What are $a$, $b$, $n$ and $\\D x$?\r\n    \\end{enumerate}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral1}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Left-hand sum. Right-hand sum would be smaller. \r\n    \\item We have $a = 0$, $b = 2$, $n = 6$, $\\Delta x = \\frac{2}{6} = \\frac{1}{3}$.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Using the figure below, draw rectangles representing each of the\r\n    following Riemann sums for the function $f$ on the interval $0 \\le t \\le\r\n    8$. Calculate the value of each sum. \r\n\r\n\\includegraphics[width=0.5\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2}\r\n\\begin{enumerate}[(a)]\r\n\\item Left-hand sum with $\\D t = 4.$\r\n\\item Left-hand sum with $\\D t = 2$.\r\n\\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n\\begin{tabular}{cc}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2_solutions1} & \r\n\\includegraphics[width=0.4\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2_solutions3} \\\\\r\n(a) & (b) \\\\ \r\n\\end{tabular}\r\n\r\n(a) The left-hand sum with $n=2$ intervals, or $\\D t = 4$: $32 \\cdot 4 + 24 \\cdot 4$ = 224. \\\\\r\n(b) Left-hand sum with $n=4$ intervals, or $\\D t = 2$: $32 \\cdot 2 + 30 \\cdot 2 + 24 \\cdot 2 + 14 \\cdot 2 = 200$. \\\\\r\n\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The graph of a function $f(t)$ is given in the figure below.\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral3}\r\n\r\nWhich of the following four numbers could be an estimate of $\\ds \\int_0^1f(t) ~dt$, accurate to two decimal places? Explain how you chose your answer.  \\\\\r\n%\\begin{tabular}{ll}\r\n(a) -98.35   (b) 71.84 \r\n(c) 100.12   (d) 93.47\r\n%\\end{tabular}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    The graph given shows that $f$ is positive for $0 \\le t \\le\r\n    1$, so the integral value must be positive: the answer cannot be -98.35. \r\n\r\n    Since the graph is contained within a rectangle of height 100 and\r\n    length 1, the answer 100.12 is too large.\r\n\r\n    The graph of $f$ is well above the horizontal line y = 80 for\r\n    $0\\le t \\le 0.95$, so the integral is likely much higher then\r\n    71.84 $<$ 80, so out of the choices given the best estimate\r\n    is 93.47: answer (d).\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n\\begin{enumerate}[(a)]\r\n\\item What is the area between the graph of $f(x)$ shown below and\r\n  the $x$-axis, between $x = 0$ and $x = 5$?\r\n\\item What is $\\ds \\int_0^5 f(x)~dx$?\r\n\\end{enumerate}\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral4}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item The total area between $f(x)$ and the $x$-axis is the sum of\r\n      the two given areas, so area = 7 + 6 = 13.\r\n\\item  To find the integral, we note that from $x = 3$ to $x = 5$, the function lies below the $x$-axis, and hence makes a negative\r\ncontribution to the integral. So\r\n$$\\ds \\int_0^5 f(x)~dx = \\int_0^3 f(x)~dx + \\int_3^5 f(x)dx = 7 - 6 = 1$$\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    \\begin{enumerate}[(a)]\r\n    \\item On a sketch of $y =\\ln(x)$, represent the left Riemann sum\r\n      with $n = 2$ approximating $\\ds \\int_1^2 \\ln(x)~dx$. Write out\r\n      the terms in the sum, but do not evaluate it.\r\n    \\item Will this LEFT(4) estimate be an overestimate or an\r\n      underestimate of $\\ds \\int_1^2 \\ln(x)~dx$?\r\n    \\end{enumerate}\r\n  \\end{Question}\r\n  \\begin{enumerate}[(a)]\r\n  \\item Below are the left and right sums respectively. \\\\\r\n\\includegraphics[width=0.9\\linewidth]{graphics/Week04_TheDefiniteIntegral/Ln_solutions} \\\\\r\n\\begin{align*}\r\n\\mbox{ Left sum} & = f(1) \\Delta x + f(1.5) \\Delta x  \\\\\r\n& = \\underbrace{(\\ln1)}_{=0}0.5 + \\ln(1.5)0.5 = (\\ln 1.5)0.5\r\n\\end{align*}\r\n\\item Because the $y$ values on the left end of each interval are the\r\n  smallest on that interval, the sum built on them will be an\r\n  underestimate of the exact integral value.\r\n  \\end{enumerate}\r\n  \\begin{Solution}\r\n    \r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Estimate $\\ds \\int_1^2 x^2~ dx$ using left-hand sum with four\r\n    subdivisions. \r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n Left-hand sum gives: \\\\$1^2(1/4) + (1.25)^2(1/4) + (1.5)^2(1/4) + (1.75)^2(1/4) = 1.96875.$ \r\n\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Without computation, decide if\r\n    $\\ds \\int_0^{2\\pi} e^{-x} \\sin x~dx$ is positive or\r\n    negative. [Hint: use MATLAB to draw $e^{-x} \\sin(x)$ over the\r\n    given interval.]\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/ExpSin_solutions} \\\\\r\n\r\nLooking at the graph of $y = e^{-x} \\sin x$ shown above for\r\n$0 \\le x \\le 2\\pi$, we see that the area, $A_1$, which contributes a\r\npositive amount to the integral\r\n$\\ds \\int_0^{2 \\pi} e^{-x} \\sin(x)~dx$, is much larger than the area\r\n$A_2$, which contributes a negative amount to the integral.\r\n\r\nSince the positive integral contributions are larger than the\r\nnegative, the overall integral $\\ds \\int_0^{\\pi} e^{-x} \\sin(x)~dx$ will be {\\bf positive}.\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Graph $\\ds f(x) = \\begin{cases} 1-x & \\text{ if $0 \\le x\\le 1$}  \\\\\r\nx-1 & \\text{ if $1 < x\\le 2$}  \\\\\r\n\\end{cases}$\r\n\\item Find the {\\em exact} value of $\\ds \\int_0^2 f(x)~ dx$ (hint: sketch and see what shapes you get). \r\n\\item Calculate the 4-term left Riemann sum approximation to the\r\n  definite integral. How does the approximation compare to the exact\r\n  value?\r\n    \\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item  ~\\\\\r\n\\includegraphics[width=0.9\\linewidth]{graphics/Week04_TheDefiniteIntegral/Piecewise_solutions} \\\\ \r\n\\item The area is made up of two triangles, with total area of 2 $\\times$ (1/2)(1)(1) = 1 square unit. \r\n\\item Using $\\D x = 1/2$ in the 4-term Riemann sum shown in right-side\r\n  graph above, we have \r\n\\begin{align*}\r\n& \\mbox{Left hand sum}  \\\\\r\n&= f(0)\\D x + f(0.5)\\D x + f(1)\\D x + f(1.5)\\D x \\\\\r\n& = 1 \\left(\\frac{1}{2} \\right) + \\frac{1}{2} \\left(\\frac{1}{2} \\right) + 0 \\left(\\frac{1}{2} \\right) + \\frac{1}{2} \\left(\\frac{1}{2} \\right) \\\\\r\n&  = 1.\r\n\\end{align*} We notice that in this case the approximation is exactly\r\nequal to the exact value of the integral.  This is mostly coincidence\r\ndue to the simple shape of $f(x)$.  In general, approximations will\r\nnot work out to be exactly the same as the value of the integral.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\nUsing the figure below, find the values of     \r\n\r\n\\begin{tabular}{ll}\r\n(a) $\\ds \\int_a^b f(x)~dx$ & (b) $\\ds  \\int_b^c f(x)~dx$ \\\\\r\n(c) $\\ds \\int_a^c f(x)~dx$ & (d) $\\ds \\int_a^c ~|f(x)|~dx$\r\n\\end{tabular}\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral5}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item The area between the graph of $f(x)$ and the $x$-axis\r\n      between $x = a$ and $x = b$ is 13, so $\\ds \\int_a^bf(x)~dx = 13$.\r\n    \\item Since the graph of $f(x)$ is below the x-axis for $b < x <\r\n      c$, $\\ds \\int_b^c f(x)~ dx = -2$.\r\n\\item Since the graph of $f(x)$ is above the $x$-axis for $a < x < b$ and below for $b < x < c$,\r\n$\\ds \\int_a^c f(x)~dx = 13 - 2 = 11$.\r\n\\item The graph of $|f(x)|$ is the same as the graph of $f(x)$, except\r\n  that the part {\\em below} the $x$-axis is reflected to be {\\em\r\n    above} it (see graph of $|f(x)|$ below).  Thus $\\ds \\int_a^c\r\n  |f(x)|~ dx = 13 + 2 = 15$.\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/AbsValue_solutions}\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n%*****************\r\n\\item \r\n  \\begin{Question}\r\n    Given the figure below, and the statement that $\\ds \\int_{-2}^0 f(x)~dx = 4$, estimate \r\n\r\n\\begin{tabular}{ll}\r\n(a) $\\ds \\int_0^2 f(x)~dx$ & (b) $\\ds  \\int_{-2}^2 f(x)~dx$ \\\\\r\n(c) The total shaded area.\r\n\\end{tabular}\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral6}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    The region shaded between $x = 0$ and $x = 2$ appears to have\r\n    approximately the same area as the region shaded between $x = -2$\r\n    and $x = 0$, but it lies below the axis. Since $\\ds \\int_{-2}^0 f(x)~dx = 4$, we\r\n    have the following results: \r\n    \\begin{enumerate}\r\n    \\item $\\ds \\int_0^2f(x)~dx \\approx  \\mbox{ negative of }\\int_{-2}^0 f(x)~dx =-4$\r\n    \\item  $\\ds \\int_{-2}^2 f(x)~ dx \\approx 4 - 4 = 0$.  \r\n    \\item  The total area shaded is approximately 4 + 4 = 8.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Using the graph below, find $\\ds \\int_{-3}^0 f(x)~dx$. \r\n\\item If the area of the shaded region is $A$, estimate $\\ds \\int_{-3}^4 f(x)~ dx$.\r\n    \\end{enumerate}\r\n\\includegraphics[width=0.9\\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral7}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}\r\n    \\item $\\ds \\int_{-3}^0 f(x)~dx = -2$: counting squares or\r\n      computing areas of the triangles and rectangles in this region.\r\n    \\item We break the integral over the interval $x=-3\\ldots 5$ into\r\n      pieces, each of which we can find the areas of.\r\n\\begin{align*}\r\n \\int_{-3}^4 f(x)~dx & = \\int_{-3}^0 f(x)~dx + \\int_{0}^3 f(x)~dx + \\int_{3}^4 f(x)~dx \\\\\r\n& = -2 + 2 - \\frac{A}{2} \\\\\r\n&= \\frac{-A}{2}\r\n\\end{align*}\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Find the exact value of $\\ds \\int_0^{2\\pi} \\sin \\theta d\\theta$\r\n    without calculation (i.e. from a sketch).\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_TheDefiniteIntegral/Sine_solutions}\r\n\r\nFrom the graph of sine above, and the fact that the integral includes\r\na complete $[0, 2\\pi]$ cycle, it is clear from symmetry that the\r\npositive and negative contributions to the integral must be equal, so\r\n$$\\int_0^{2 \\pi} \\sin(\\theta)~d\\theta = 0$$\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The width, in feet, at various points along the fairway of a hole\r\n    on a golf course is given in the figure below. If one pound of\r\n    fertilizer covers 200 square feet, use a LEFT estimate the amount\r\n    of fertilizer needed to fertilize the fairway.\r\n\r\n\\includegraphics[width=0.9\\linewidth]{graphics/Week04_TheDefiniteIntegral/GolfHole}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    We approximate the area of the playing field by using Riemann\r\n    sums. On each 100 m horizontal interval, we use the width printed at the left end of the\r\ninterval as the other dimension.\r\n\\begin{align*}\r\n \\mbox{LEFT}(10) = & (0)(100) + 80(100) +  \\\\\r\n&85(100) +95(100) + \\\\\r\n&110(100) + 105(100) + \\\\\r\n&100(100) + 100(100) + \\\\\r\n&105(100) + 110(100) \\\\\r\n= & 89,000 \\mbox{ sq feet} \r\n\\end{align*}\r\n\r\n    Thus approximately\r\n    $\\ds \\frac{89,000 \\mbox{ sq. ft.}}{200 \\mbox{ sq. ft./lb}} = 445$\r\n    lbs. of fertilizer should be necessary.\r\n\r\n  \\end{Solution}\r\n\r\n\\end{multicols}\r\n\r\n\\hrulefill\r\n\r\n\\subsection*{Definite Integrals in Modeling}\r\n\r\n\\begin{multicols}{2}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The rate at which the world's oil is being consumed is\r\n    continuously increasing. Suppose the rate of oil consumption (in\r\n    billions of barrels per year) is given by the function $r = f(t)$,\r\n    where $t$ is measured in years and $t = 0$ is the start of 2004. \r\n    \\begin{enumerate}[(a)]\r\n    \\item Write a definite integral which represents the total\r\n      quantity of oil used between the start of 2004 and the start of\r\n      2009.\r\n    \\item Suppose $r = 32e^{0.05t}$. Using a left-hand sum with five\r\n    subdivisions, find an approximate value for the total quantity of\r\n    oil used between the start of 2004 and the start of 2009. \r\n  \\item Interpret each of the five terms in the sum from part (b) in\r\n    terms of oil consumption.\r\n    \\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Quantity used = $\\ds \\int^5_0 f(t)~dt$.\r\n\\item Using a left sum, our approximation is\r\n\\begin{align*}&32e^{0.05(0)}+ 32e^{0.05(1)}+ 32e^{0.05(2)}+ 32e^{0.05(3)}+ 32e^{0.05(4)}  \\\\\r\n&= 177.270.\r\n\\end{align*}\r\nSince $f$ is an increasing function, the left endpoint values of $f$\r\nare lower than anywhere else on the subintervals, so this represents\r\nan underestimate.\r\n\\item Each term is a lower estimate of one year's consumption of oil. \r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    As coal deposits are depleted, it becomes necessary to strip-mine\r\n    larger areas for each ton of coal. The graph below shows the\r\n    number of acres of land per million tons of coal that will be\r\n    defaced during strip-mining as a function of the number of million\r\n    tons removed, starting from the present day.\r\n    \\begin{enumerate}[(a)]\r\n    \\item Estimate the total number of acres defaced in extracting the\r\n      next 4 million tons of coal (measured from the present\r\n      day). Draw four rectangles under the curve, and compute their\r\n      area.\r\n    \\item Re-estimate the number of acres defaced using rectangles\r\n      above the curve.\r\n    \\item Combine your answers to parts (a) and (b) to get a better\r\n      estimate of the actual number of acres defaced.\r\n    \\end{enumerate}\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/Coal}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n\\item ~\\\\\r\n\\includegraphics[width=1.0\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/Coal_solutions} \\\\\r\nUsing rectangles under the curve, we get\r\n$$\\mbox{Acres defaced} \\approx (1)(0.2 + 0.4 + 1 + 2) = 3.6 \\mbox{ acres.}$$\r\n\\item Using rectangles above the curve, we get\r\n$$\\mbox{Acres defaced} \\approx (1)(0.4 + 1 + 2 + 3.5) = 6.9 \\mbox{ acres.}$$\r\n\\item The number of acres defaced is between 3.6 and 6.9, so we\r\n  estimate the average, 5.25 acres.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\nCoal gas is produced at a gasworks. Pollutants in the gas are removed by scrubbers, which become less and less efficient as time goes on. The following measurements, made at the start of each month, show the rate at which pollutants are escaping (in tons/ month) in the gas: \r\n\\begin{tabular}{lrrrrrrrr} \\hline\r\nTime (months)&0&1&2&3&4&5&6\\\\ \\hline\r\n Rate pollutants escape&5&7&8&10&13&16&20 \\\\ \r\n(tons/month) & \\\\ \\hline\r\n\\end{tabular} \r\n\\begin{enumerate}[(a)]\r\n\\item Make an overestimate and an underestimate of the total quantity\r\n  of pollutants that escape during the {\\bf first month}.\r\n\\item Make an overestimate and an underestimate of the total quantity\r\n  of pollutants that escape during the {\\bf six months} shown in the table.\r\n\\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item An overestimate is (7 tons/month)$\\cdot$ (1 month) = 7 tons. An underestimate is (5 tons/month)$\\cdot$(1 month) = 5 tons.\r\n    \\item An overestimate is 7+8+10+13+16+20 = 74 tons. An\r\n      underestimate is 5+7+8+10+13+16 = 59 tons.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    The graph below shows the rate of change of the quantity of water\r\n    in a water tower, in liters per day, during the month of April. If\r\n    the tower had 12,000 liters of water in it on April 1, estimate\r\n    the quantity of water in the tower on April 30.\r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/WaterTower2}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    Suppose $V(t)$ represents the total quantity of water in the water\r\n    tower at time $t$, where $t$ is in days since April 1. Then the\r\n    graph shown in the problem is a graph of the volume's rate of\r\n    change, or $\\ddt{V}$ or $V'(t)$. By the Fundamental Theorem, the\r\n    change in the volume over the 30 days of April is given by:\r\n$$V(30) - V(0) = \\int^{30}_0 V'(t)~dt.$$\r\nThis relationship means we can calculate the change in the volume of\r\nwater by calculating the area under the curve. Each box represents\r\nabout (50 l/d)$\\cdot$(6 d) = 300 liters. \r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/WaterTower2_soln}\r\n\r\nIn the red region, from $t = 0$ to $t = 12$, the graph is below the\r\n$t$ axis, indicating that water is being lost from the tower.  There\r\nis a little more than one\r\nbox, but for simplicity we'll call it one square, so roughly $\\approx 300$ liters were lost.  \\\\\r\nFrom $t = 12$ to $t = 30$ (blue region), there are between 6 and 7\r\nboxes in total\r\n(let's say 6 for simplicity), or roughly +1800 liters. \\\\\r\nThus, $$\\int^{30}_0 V'(t)~dt \\approx 1800 - 300 = 1500$$ This is the\r\nnet {\\em change} in the volume of water.  Solving for $V(30)$, the\r\n{\\em amount} of water on April 30th,\r\n\\begin{align*}\r\nV(30) & = V(0) + \\int^{30}_0 V'(t)~dt \\\\ \r\n& = 12,000 + 1500 = 13,500 \\mbox{ liters.}\r\n\\end{align*}\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    A bicyclist pedals along a straight road with velocity $v$ given\r\n    in the graph below. She starts 5 miles from a lake; positive\r\n    velocities take her away from the lake and negative velocities\r\n    take her toward the lake. When is the cyclist farthest from the\r\n    lake, and how far away is she then?\r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/LakeCyclist}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    Notice that the area of a square on the graph represents (10 mph)$\r\n    \\cdot$ (1/6) h = (5/3) miles. \r\n\r\n\\includegraphics[width=1.0\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/LakeCyclist_solutions}\r\n\r\nAt $t = 1/3$ hours, $v = 0$. The area between the curve $v$ and the\r\n$t$-axis over the interval $0 \\le t \\le 1/3$ is $\\ds -\\int^{1/3}_0 v\r\n~dt \\approx \\mbox{ one square} = 5/3$ miles.  Since $v$ is negative\r\nhere, she is moving toward the lake. Since she starts 5 miles from the\r\nlake at time $t=0$, at $t = 1/3$ she is about 5 - 5/3 = 10/3 miles\r\nfrom the lake (so closer than when she started).\r\n\r\n\r\nFor $1/3 \\le t \\le 1$, $v$ is positive, so she is moving away from the\r\nlake.  Her {\\em change} in distance from the lake between the times\r\n$t=0$ and the end point $t=1$ is given by\r\n\\begin{align*}\r\n\\int^1_0 v ~dt & =\r\n\\int^{1/3}_0 v ~dt +\r\n\\int^1_{1/3} v ~dt \\\\\r\n& \\approx -\r\n\\frac{5}{3} + 8 \\cdot\r\n\\frac{5}{3} =\r\n\\frac{35}{ 3} = 11.667 \\mbox{ miles,}\r\n\\end{align*}\r\nRelative to her starting point of 5 miles at $t=0$, the cyclist is\r\nabout 5 + 35/3 = 50/3 = 16.667 miles from the lake at $t=1$.  Since,\r\nstarting from the moment $t = 1/3$, she is always moving away from the\r\nlake, the cyclist will be farthest from the lake at the latest\r\npossible time, $t = 1$. The maximal distance at that time equals 50/3\r\n= 16.667 miles.\r\n  \\end{Solution}\r\n\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Height velocity graphs are used by endocrinologists (doctors\r\n    specializing in the study of hormones) to follow the progress of\r\n    children with growth deficiencies. The graph below shows the\r\n    height velocity curves of an average boy and an average girl\r\n    between ages 3 and 18.\r\n\r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/HeightVelocity}\r\n\\begin{enumerate}[(a)]\r\n\\item Which curve is for girls and which is for boys?  Explain how\r\n  you can tell.\r\n\\item About how much does the average boy grow between ages 3 and\r\n    10?\r\n  \\item The growth spurt associated with adolescence and the onset of\r\n    puberty occurs between ages 12 and 15 for the average boy and\r\n    between ages 10 and 12.5 for the average girl. Estimate the height\r\n    gained by each average child during this growth spurt.\r\n  \\item When fully grown, about how much taller is the average man\r\n    than the average woman? (The average boy and girl are about the\r\n    same height at age 3.)\r\n\\end{enumerate}\r\n\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Since men are generally taller than women, the curve with\r\n      the larger area under it is the height velocity of the boys.\r\n      The area under each curve represents the change in growth in\r\n      centimeters.  Therefore, the black curve is for boys, the\r\n      lighter grey one for girls.\r\n    \\item Each square below the height velocity curve has area (1 cm/yr) $\\cdot$\r\n       1 yr = 1 cm. Counting squares lying below the black curve\r\n      gives about 43 cm. Thus, on average, boys grow about 43 cm\r\n      between ages 3 and 10.\r\n    \\item Counting squares lying below the black curve gives about 23\r\n      cm growth for boys during their growth spurt. Counting squares\r\n      lying below the colored curve gives about 18 cm for girls during\r\n      their growth spurt.\r\n    \\item We can measure the difference in growth by counting squares\r\n      that lie between the two curves. Between ages 2 and 12.5, the\r\n      average girl grows faster than the average boy. Counting squares\r\n      yields about 5 cm between the colored and black curves for $2 \\le\r\n      x \\le 12.5$. Counting squares between the curves for $12.5 \\le x \\le\r\n      18$ gives about 18 squares.  Thus, there is a net increase of\r\n      boys over girls by about 18 - 5 = 13 cm.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n\\end{multicols}\r\n\r\n\\hrulefill\r\n\r\n\\subsection*{Properties of Definite Integrals}\r\n\r\n\\begin{multicols}{2}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Without integrating, show that $$2 \\le \\ds \\int_0^2 \\sqrt{1 + x^3}\r\n    ~dx \\le 6.$$\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    Notice that $f(x) = \\sqrt{1 + x^3}$ is increasing for $0 \\le x \\le\r\n    2$, since $x^3$ gets bigger as $x$ increases. This means that,\r\n    looking at the interval [0, 2] over which we are integrating,\r\n    $f(0) \\le f(x) \\le f(2)$. \r\n\r\n\r\nFor this function, $f(0) = \\sqrt{1 +0} = 1$ and $f(2) = \\sqrt{1 + 8} = 3$. Thus, the area under\r\n$f(x)$ lies between the area under the line $y = 1$ and the area under\r\nthe line $y = 3$ on the interval $0 \\le x \\le 2$. See the diagram\r\nbelow.  \r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralBound1_solutions}\r\n\r\nThat is,\r\n$$\\underbrace{1}_h\\underbrace{(2 - 0)}_w \\le \\int^2_0 \\sqrt{ 1 + x^3}~dx \\le \\underbrace{3}_h\\underbrace{(2 - 0)}_w$$\r\n\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n   Without calculating  the integral, explain why the following statements are false.\r\n   \\begin{enumerate}[(a)]\r\n   \\item $\\ds \\int_{-2}^{-1} e^{x^2} ~dx = -3$ \r\n   \\item $\\ds \\int_{-1}^{1} \\left| \\frac{\\cos(x+2)}{1 + \\tan^2x} \\right| ~dx = 0$.\r\n   \\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    (a) The integrand is always positive, so the integral (sum of positive $f(x)$ times positive $\\D x$ values) cannot be negative. \\\\\r\n    (b) The integrand is always $\\ge 0$ because of the absolute value\r\n    sign. If the integral = 0, then with a non-negative integrand, the\r\n    integrand must be exactly 0 at every $x$ value on the interval,\r\n    which is definitely not the case here.\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    Using the graph of $f(x)$ shown below, arrange the following\r\n    quantities in increasing order, from least to greatest.\r\n\r\n\\includegraphics[width=0.6\\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralRanking}\r\n\r\n\\begin{tabular}{ll}\r\n(i) $\\ds \\int_0^1 f(x)~dx $ & \r\n(ii)$\\ds \\int_1^2  f(x)~dx $ \\\\\r\n(iii)$\\ds \\int_0^2  f (x)~dx $ & \r\n(iv) $\\ds \\int_2^3 f(x)~dx $ \\\\\r\n(v) $-\\ds \\int_1^2  f(x)~dx $ &\r\n(vi) The number 0  \\\\\r\n(vii) The number 20  &\r\n(viii) The number -10\r\n\\end{tabular}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    See the figure below.\r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralRanking_solutions}\r\n\r\nSince $\\ds \\int^1_0 f(x)~dx = A_1$ and\r\n$\\ds \\int^2_1 f(x)~dx = -A_2$ and\r\n$\\ds \\int^3_2 f(x)~dx = A_3$, we know that\r\n$$0 < \\int^1_0 f(x)~dx < - \\int^2_1 f(x)~dx < \\int^3_2 f(x)~dx.$$\r\nIn addition,\r\n$\\ds \\int^2_0 f(x)~dx = A_1 - A_2$, which is negative, but smaller in magnitude than\r\n$\\ds \\int^2_1 f(x)~dx$. Thus\r\n$$\\int^2_1 f(x)~dx < \\int^2_0 f(x)~dx < 0.$$\r\nThe area $A_3$ lies inside a rectangle of height 20 and base 1, so\r\n$A_3 < 20$.   \\\\\r\nThe area $A_2$ lies inside a rectangle below the $x$-axis of\r\nheight 10 and width 1, so $-10 < A_2$. Thus: \r\n\\begin{center}\r\n(viii) $<$ (ii) $<$ (iii) $<$ (vi) $<$ (i) $<$ (v) $<$ (iv) $<$ (vii).\r\n\\end{center}\r\n  \\end{Solution}\r\n%*****************\r\n\\item\r\n  \\begin{Question}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Use the graph of $y = x e^{-x^2}$ shown below to explain why $\\ds \\int_{-3}^3 x e^{-x^2} ~dx= 0$.\r\n\\begin{center}\r\n\\includegraphics[width=0.5\\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/xexp_integral}\r\n\\end{center}\r\n\r\n    \\item Find the left-hand sum approximation with $n = 3$ to $\\ds\r\n      \\int_{0}^3 x e^{-x^2}~dx$. Give your answer to four decimal\r\n      places.\r\n    \\item Repeat part (b) for $\\ds \\int_{-3}^0 x e^{-x^2}~dx$.\r\n    \\item Do your answers to parts (b) and (c) add to 0? Explain.\r\n    \\end{enumerate}\r\n  \\end{Question}\r\n\r\n  \\begin{Solution}\r\n    \\begin{enumerate}[(a)]\r\n    \\item Since the function is symmetric around the origin, and the\r\n      interval used is also symmetric across $x=0$, the areas above\r\n      and below the x-axis cancel when we compute the integral. Thus,\r\n$$\\ds\\int^0_{-3} xe^{-x^2} dx = -\r\n\\int^3_0 xe^{-x^2} dx,$$\r\n $$\\mbox{ so } \\ds \\int^3_{-3} xe^{-x^2} dx =\r\n\\underbrace{\\int^0_{-3} xe^{-x^2} dx +\r\n\\int^3_0 xe^{-x^2} dx}_{\\mbox{equal magnitude, opposite signs}} = 0.$$\r\n\\item For $0 \\le x \\le 3$ with $n = 3$, we have $x_0 = 0, x_1 = 1, x_2 = 2, x_3 = 3$, and $\\D x = 1$. See the figure below. \r\n\r\n\\includegraphics[width=0.8\\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/xexp_integral_solutions}\r\n\r\n\\begin{align*}\r\n\\mbox{Left sum}& = f(x_0)\\D x + f(x_1)\\D x + f(x_2)\\D x \\\\\r\n& = 0e^{-0^2} \\cdot 1 + 1e^{-(1^2)} \\cdot 1 + 2e^{-(2^2)} \\cdot 1 \\\\\r\n& = 0.4045.\r\n\\end{align*}\r\n\\item For $-3 \\le x \\le 0$, with $n = 3$, we have $x_0 = -3, x_1 = -2, x_2 = -1, x_3 = 0$, and $\\D x = 1$. (See the diagram again.)\r\n\\begin{align*}\r\n\\mbox{Left sum} & = f(x_0)\\D x + f(x_1)\\D x + f(x_2)\\D x \\\\\r\n& = -3e^{-(-3)^2}\r\n\\cdot 1 - 2e^{-(-2)^2}\r\n\\cdot 1 - 1e^{-(-1)^2}\r\n\\cdot 1 \\\\\r\n& = -0.4049. \\\\\r\n\\end{align*}\r\n\\item No. The rectangles between $x=-3$ and 0 are not the same size as\r\n  those between $x=0$ and 3. See the diagram.  There are three\r\n  rectangles with nonzero height on [-3, 0] and only two on [0, 3], so\r\n  the estimates computed must be different, so we won't get the exact\r\n  result of zero using left sums.\r\n    \\end{enumerate}\r\n  \\end{Solution}\r\n\r\n\\end{multicols}\r\n\\hrulefill\r\n\r\n\\subsection*{Integration By Anti-Derivatives}\r\n\r\n\\begin{Question}\r\n  To practice computing anti-derivatives, do as many of the\r\n  problems from the following section as you need.\r\n\r\n\r\n  These problems are a good start for practicing anti-derivatives or\r\n  integration.  If you want more though, consult any calculus\r\n  textbook.\r\n\\end{Question}\r\n\r\n\\begin{Question}\r\nEvaluate the following integrals.\r\n\\end{Question}\r\n\r\n\\item \\begin{Question}\r\n  $\\ds \\int_{-1}^2 (x^3 - 2x) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{-1}^2 (x^3 - 2x) dx = \\left[ \\frac{x^4}{4} - x^2 \r\n    \\right]_{-1}^2 = \\left( \\frac{2^4}{4} - 2^2 \\right) - \\left( \\\r\n      \\frac{(-1)^4}{4} - (-1)^2 \\right) = (4 - 4) - (\\frac{1}{4} - 1) = 0\r\n    - (- \\frac{3}{4}) = \\frac{3}{4}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n  $\\ds \\int_{-1}^1 x^{100} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{-1}^1 x^{100} dx = \\left[ \\frac{1}{101} x^{101} \r\n    \\right]_{-1}^{1} = \\frac{1}{101} - (- \\frac{1}{101}) = \r\n    \\frac{2}{101}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n  $\\ds \\int_{1}^4 (5 - 2t +3t^2) dt$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^4 (5 - 2t - 3t^2) dt = [5t - t^2 + t^3]_1^4 = \r\n    (20 - 16 + 64) - (5 - 1 + 1) = 68 - 5 = 63$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n  $\\ds \\int_0^1 (1 + \\frac{1}{2} u^4 - \\frac{2}{5} u^9) du$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int_0^1 (1 + \\frac{1}{2} u^4 - \\frac{2}{5} u^9) du = \r\n    [u + \\frac{1}{10} u^5 - \\frac{1}{25} u^10]_0^1 = \r\n    (1 + \\frac{1}{10} - \\frac{1}{25}) - 0 = \\frac{50 + 5 - 2}{50} = \\frac{53}{50}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n  $\\ds \\int_1^9 \\sqrt{x} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^9 \\sqrt{x} dx = \\int_1^9 x^{1 / 2} dx = \r\n    \\left[ \\frac{x^{3 / 2}}{3 / 2} \\right]_1^9 =\r\n    \\frac{2}{3} \\left[ x^{2 / 3} \\right]_1^9 =\r\n    \\frac{2}{3} (9^{3 / 2} - 1^{3 / 2}) = \r\n    \\frac{2}{3} (27 - 1) = \\frac{52}{3}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^8 x^{-2 / 3} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    \r\n  $\\ds \\int_1^8 x^{-2 / 3} dx = \r\n    \\left[ \\frac{x^{1 / 3}}{1 / 3} \\right]_1^8 = \r\n    3 \\left[ x^{1 / 3} \\right]_1^8 = \r\n    3(8^{1 / 3} - 1^{1 / 3}) = 3(2 - 1) = 3$\r\n    \r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_{\\pi / 6}^{\\pi} \\sin \\theta d \\theta$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{\\pi / 6}^{\\pi} \\sin \\theta d \\theta =\r\n    \\left[ - \\cos \\theta \\right]_{\\pi / 6}^{\\pi} =\r\n    - \\cos \\pi - ( - \\cos \\frac{\\pi}{6} ) = \r\n    -(-1) - (- \\sqrt{3} / 2) = 1 + \\sqrt{3} / 2$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_{-5}^5 e~ dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  The number $e$ is just a constant. \r\n\r\n    $\\ds \\int_{-5}^5 e ~dx = [e x]_{-5}^5 = 5e - (-5e) = 10e$\r\n    \r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^1 (u + 2)(u - 3) du$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  You need to expand the product before you can integrate.  \r\n\r\n    $\\ds \\int_0^1 (u + 2)(u - 3) du = \\int_0^1 (u^2 - u - 6) du = \\left[\r\n      \\frac{1}{3} u^3 - \\frac{1}{2} u^2 - 6u \\right]_0^1 =\r\n    \\left(\\frac{1}{3} - \\frac{1}{2} - 6 \\right) - 0 = - \\frac{37}{6}$\r\n\\end{Solution}\r\n\r\n\r\n  \\item \\begin{Question}\r\n  $\\ds \\int_0^4 (4 - t) \\sqrt{t} ~dt$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\nTo evaluate this integral, you need to expand the product first; you can't integrate the product $(4-t)\\sqrt{t}$ as it is originally written.\r\n\r\n  $\\ds \\int_0^4 (4 - t) \\sqrt{t} dt = \\int_0^4 (4 - t) t^{1 / 2} dt =\r\n    \\int_0^4 (4t^{1 / 2} - t^{3 / 2}) dt = \r\n    \\left[ \\frac{8}{3} t^{3 / 2} - \\frac{2}{5} t^{5 / 2} \\right]_0^4 =\r\n    \\frac{8}{3} (8) - \\frac{2}{5} (32) = \r\n    \\frac{320 - 192}{15} = \\frac{128}{15}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^9 \\frac{x - 1}{\\sqrt{x}} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    \r\n  $\\ds \\int_1^9 \\frac{x - 1}{\\sqrt{x}} dx =\r\n    \\int_1^9 \\left( \\frac{x}{\\sqrt{x}} - \\frac{1}{\\sqrt{x}} \\right) dx\r\n    = \\int_1^9 (x^{1 / 2} - x^{-1 / 2}) dx =\r\n    \\left[\\frac{2}{3} x^{3 / 2} - 2x^{1 / 2} \\right]_1^9 = \r\n    (\\frac{2}{3} \\cdot 27 - 2 \\cdot 3) = (\\frac{2}{3} - 2) = \r\n    12 - (- \\frac{4}{3}) = \\frac{40}{3}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^2 (y - 1)(2y + 1) dy$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    \r\n  $\\ds \\int_0^2 (y - 1)(2y + 1) dy = \\int_0^2 (2y^2 - y - 1) dy =\r\n    \\left[ \\frac{2}{3} y^3 - \\frac{1}{2} y^2 - y \\right]_0^2 = \r\n    ( \\frac{16}{3} - 2 - 2) - 0 = \\frac{4}{3}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^{\\pi / 4} \\sec^2 t ~dt$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    \r\n  $\\ds \\int_0^{\\pi / 4} \\sec^2 t ~dt = [\\tan t]_0^{\\pi / 4} =\r\n    \\tan \\frac{\\pi}{4} - \\tan 0 = 1 - 0 = 1$\r\n    \r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^{\\pi / 4} \\sec \\theta \\tan \\theta d \\theta$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_0^{\\pi / 4} \\sec \\theta \\tan \\theta d \\theta = \r\n    [ \\sec \\theta ]_0^{\\pi / 4} = \r\n    \\sec \\frac{\\pi}{4} - \\sec 0 = \\sqrt{2} - 1$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^2 (1 + 2y)^2 dy$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^2 (1 + 2y)^2 dy = \r\n    \\int_1^2 (1 + 4y + 4y^2) dy =\r\n    [y + 2y^2 + \\frac{4}{3} y^3]_1^2 =\r\n    (2 + 8 + \\frac{32}{3}) - (1 + 2 + \\frac{4}{3}) = \r\n    \\frac{62}{3} - \\frac{13}{3} = \\frac{49}{3}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^3 (2 \\sin x - e^x) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_0^3 (2 \\sin x - e^x) dx = \r\n    [-2 \\cos 3 - e^3) - (-2 - 1) =\r\n    3 - 2 \\cos 3 - e^3$\r\n    \r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^2 \\frac{v^3 + 3v^6}{v^4} dv$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^2 \\frac{v^3 + 3v^6}{v^4} =\r\n    \\int_1^2 \\left( \\frac{1}{v} + 3v^2 \\right) dv =\r\n    [ \\ln |v| + v^3]_1^2 = \r\n    ( \\ln 2 + 8 ) - ( \\ln 1 + 1) =\r\n    \\ln 2 + 7$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^{18} \\sqrt{\\frac{3}{z}} dz$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^{18} \\sqrt{\\frac{3}{z}} dz =\r\n    \\int_1^{18} \\sqrt{3} z^{-1/2} dz =\r\n    \\sqrt{3} [ 2z^{1/2} ]_1^{18} =\r\n    2 \\sqrt{3} (18^{1/2} - 1^{1/2}) = \r\n    2 \\sqrt{3} (3 \\sqrt{2} - 1)$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_0^1 (x^e + e^x) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    \r\n  $\\ds \\int_0^1 (x^e e^x) dx = \r\n    \\left[ \\frac{x^{e + 1}}{e + 1} + e^x \\right]_0^1 =\r\n    \\left( \\frac{1}{e + 1} + e \\right) - (0 + 1) = \r\n    \\frac{1}{e + 1} + e - 1$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_{1 / \\sqrt{3}}^{\\sqrt{3}} \\frac{8}{1 + x^2} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{1 / \\sqrt{3}}^{\\sqrt{3}} \\frac{8}{1 + x^2} dx =\r\n    \\left[ 8 \\arctan x \\right]_{1 / \\sqrt{3}}^{\\sqrt{3}} =\r\n    8 \\left( \\frac{\\pi}{3} - \\frac{\\pi}{6} \\right) =\r\n    8 \\left( \\frac{\\pi}{6} \\right) = \\frac{4 \\pi}{3}$\r\n    \r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_1^2 \\frac{4 + u^2}{u^3} du$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_1^2 \\frac{4 + u^2}{u^3} du =\r\n    \\int_1^2 (4u^{-3} + u^{-1}) du =\r\n    \\left[ \\frac{4}{-2} u^{-2} + \\ln |u| \\right]_1^2 =\r\n    \\left[ \\frac{-2}{u^2} + \\ln u \\right]_1^2 =\r\n    (-\\frac{1}{2} + \\ln 2) - (-2 + \\ln 1) = \r\n    \\frac{3}{2} + \\ln 2$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_{-1}^1 e^{u + 1} du$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{-1}^1 e^{u + 1} du = \r\n    [e^{u + 1}]_{-1}^1 =\r\n    e^2 - e^0 = e^2 - 1$ [or start with $e^{u + 1} = e^u e^1$]\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n  $\\ds \\int_{1 / 2}^{1 / \\sqrt{2}} \\frac{4}{\\sqrt{1 - x^2}} dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\int_{1/2}^{1 / \\sqrt{2}} \\frac{4}{\\sqrt{1 - x^2}} dx =\r\n    \\left[ 4 \\arcsin x \\right]_{1/2}^{1 / \\sqrt{2}} =\r\n    4 \\left( \\frac{\\pi}{4} - \\frac{\\pi}{6} \\right) =\r\n    4(\\frac{\\pi}{12}) = \\frac{\\pi}{3}$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n$\\ds    \\int_0^{\\pi} f(x) dx \\text{ where } f(x) = \r\n    \\begin{cases}\r\n      \\sin x  & \\text{ if } 0 \\leq x < \\pi / 2 \\\\\r\n      \\cos x  & \\text{ if } \\pi / 2 \\leq x \\leq \\pi \\\\\r\n    \\end{cases}\r\n   $ \r\n\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\text{If } f(x) = \r\n    \\begin{cases}\r\n      \\sin x  & \\text{ if } 0 \\leq x < \\pi / 2 \\\\\r\n      \\cos x  & \\text{ if } \\pi / 2 \\leq x \\leq \\pi \\\\\r\n    \\end{cases}\r\n    $ then\r\n    \r\n    $\\ds \\int_{0}^{\\pi} f(x) dx = \r\n    \\int_0^{\\pi/2} \\sin x dx + \\int_{\\pi/2}^{\\pi} \\cos x dx =\r\n    [ - \\cos x]_0^{\\pi/2} + [ \\sin x ]_{\\pi / 2}^{\\pi} =\r\n    - \\cos \\frac{\\pi}{2} + \\cos 0 + \\sin \\pi - \\sin \\frac{\\pi}{2} = \r\n    -0 + 1 + 0 - 1 = 0$\r\n\\end{Solution}\r\n\r\n\\item \\begin{Question}\r\n    \r\n$\\ds    \\int_{-2}^2 f(x) dx \\text{ where } f(x) = \r\n    \\begin{cases}\r\n      2  & \\text{ if } -2 \\leq x \\leq 0 \\\\\r\n      4 - x^2 & \\text{ if } 0 < x \\leq 2 \\\\\r\n    \\end{cases}\r\n  $ \r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\ds \\text{If } f(x) =\r\n    \\begin{cases}\r\n      2  & \\text{ if } -2 \\leq x \\leq 0 \\\\\r\n      4 - x^2 & \\text{ if } 0 < x \\leq 2 \\\\\r\n    \\end{cases}\r\n    $ then\r\n    \r\n    $\\ds \\int_{-2}^{2} f(x) dx =\r\n    \\int_{-2}^{0} 2 dx + \\int_0^2 (4 - x^2) dx = \r\n    [2x]_{-2}^{0} + [4x - \\frac{1}{3} x^3 ]_0^2 =\r\n    [0 - (-4)] + (\\frac{16}{3} - 0) = \\frac{28}{3}$\r\n    \r\n\\end{Solution}\r\n\r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n    $\\int (x^2 + x^{-2}) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n    $\\int (x^2 + x^{-2})dx = \\frac{x^3}{3} + \\frac{x^{-1}}{-1} + C =\r\n      \\frac{1}{3} x^3 - \\frac{1}{x} + C$\r\n    \r\n\\end{Solution}\r\n      \r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n$\\int (\\sqrt{x^3} + \\sqrt[3]{x^2}) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int (\\sqrt{x^3} + \\sqrt[3]{x^2}) dx = \r\n  \\int (x^{3/2} + x^{2/3})dx =\r\n  \\frac{x^{5/2}}{5/2} + \\frac{x^{5/3}}{5/3} + C =\r\n  \\frac{2}{5} x^{5/2} + \\frac{3}{5} x^{5/3} + C$\r\n    \r\n\\end{Solution}\r\n      \r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n  $\\int (x^4 - \\frac{1}{2} x^3 + \\frac{1}{4} x - 2) dx$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int (x^4 - \\frac{1}{2} x^3 + \\frac{1}{4} x - 2) dx = \\frac{x^5}{5}\r\n  - \\frac{1}{2} \\frac{x^2}{4} + \\frac{1}{4} \\frac{x^2}{2} - 2x + C =\r\n  \\frac{1}{5} x^5 - \\frac{1}{8} x^4 + \\frac{1}{8} x^2 - 2x + C$\r\n    \r\n\\end{Solution}\r\n      \r\n      \r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n  $\\int (u + 4)(2u + 1) du$\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int (u + 4)(2u + 1) du =\r\n  \\int (2u^2 + 9u + 4)du = \r\n  2 \\frac{u^3}{3} + 9 \\frac{u^2}{2} + 4u + C =\r\n  \\frac{2}{3} u^3 + \\frac{9}{2} u^2 + 4u + c$\r\n\\end{Solution}\r\n\r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n    $\\int v (v^2 + 2)^2 dv$\r\n    \r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int v (v^2 + 2)^2 dv = \\int v(v^4 + 4v^2 + 4)dv = \\int (v^5 + 4v^3\r\n  + 4v)dv = \\frac{v^6}{6} + 4 \\frac{v^4}{4} + 4 \\frac{v^2}{2} + C =\r\n  \\frac{1}{6} v^6 + v^4 + 2 v^2 + C$\r\n    \r\n\\end{Solution}\r\n      \r\n      \r\n%*******************************\r\n\\item\r\n\\begin{Question}\r\n    $\\int \\frac{x^3 - 2 \\sqrt{x}}{x} dx$\r\n    \r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  $\\int \\frac{x^3 - 2 \\sqrt{x}}{x} dx = \r\n  \\int \\left( \\frac{x^3}{x} - \\frac{2x^{1/2}}{x} \\right) dx =\r\n  \\int (x^2 - 2x^{-1/2})dx =\r\n  \\frac{x^3}{3} - 2 \\frac{x^{1/2}}{1/2} + C =\r\n  \\frac{1}{3} x^3 - 4 \\sqrt{x} + C$\r\n\\end{Solution}\r\n\r\n      \r\n%*******************************\r\n\\item\r\n  \\begin{Question}\r\n    $\\int \\left( x^2 + 1 + \\frac{1}{x^2 + 1} \\right) dx$\r\n  \\end{Question}\r\n  \r\n  \\begin{Solution}\r\n    $\\int \\left( x^2 + 1 + \\frac{1}{x^2 + 1} \\right) dx =\r\n    \\frac{x^3}{3} + x + \\tan^{-1} x + C$\r\n  \\end{Solution}\r\n\r\n\r\n\\hrulefill\r\n\r\n\\subsection*{Numerical Integration with MATLAB}\r\n\r\n\\begin{Question}\r\n  In Questions \\ref{qmat1}-\\ref{qmat2}, consider the integrals which\r\n  were evaluated earlier in the practice problems using anti-derivatives\r\nand the Fundamental Theorem of Calculus.\r\n\r\nFor each integral, in MATLAB, now use the LEFT$(n)$ rule with $n=1000$\r\nto approximate the value of the integral; this does {\\bf not} require\r\nusing anti-derivatives.\r\n\\end{Question}\r\n\\item \\begin{Question} \\label{qmat1}\r\n  $\\ds \\int_{-1}^2 (x^3 - 2x) dx$, which equals $\\ds \\frac{3}{4}$.\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\n  See the file linked here: \\\\\r\n  \\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT1.m}{W04LEFT1.m} \\\\\r\n  Estimate with $n = 1000$ is $\\approx 0.7455$.  Exact value is $\\frac{3}{4} = 0.75$.\r\n\\end{Solution}\r\n% ******************************\r\n\\item \\begin{Question}\r\n  $\\ds \\int_{-1}^1 x^{100} dx$, which equals $\\ds \\frac{2}{101}$.\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\nSee the file linked here: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT2.m}{W04LEFT2.m} \\\\\r\n  Estimate with $n = 1000$ is $\\approx 0.0199$.  Exact value is $\\frac{2}{101} = 0.0198$.\r\n  \r\n\\end{Solution}\r\n\r\n% ******************************\r\n\\item \\begin{Question}\r\n  $\\ds \\int_{1}^4 (5 - 2t +3t^2) dt$, which equals 63.\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\nSee the file linked here: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT3.m}{W04LEFT3.m} \\\\\r\n  Estimate with $n = 1000$ is $\\approx 62.9415$.  Exact value is 63.0000.\r\n  \r\n\\end{Solution}\r\n\r\n% ******************************\r\n\\item \\begin{Question} \\label{qmat2}\r\n    $\\ds \\int_0^1 (1 + \\frac{1}{2} u^4 - \\frac{2}{5} u^9) du$, which\r\n    equals $\\ds \\frac{53}{50}$.\r\n\\end{Question}\r\n\r\n\\begin{Solution}\r\nSee the file linked here: \\\\ \r\n\\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT4.m}{W04LEFT4.m} \\\\\r\n  Estimate with $n = 1000$ is $\\approx 1.0599$.  Exact value is $\\frac{53}{50} = 1.06$.\r\n\\end{Solution}\r\n\r\n\\end{enumerate}\r\n\r\n\\end{document} \r\n", "meta": {"hexsha": "84d74d207118b6d5a2f3943f17e171ad3dcaee38", "size": 51034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PracticeProblems/Week04.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/Week04.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/Week04.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": 35.1716057891, "max_line_length": 276, "alphanum_fraction": 0.605341537, "num_tokens": 17765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8824278695464501, "lm_q1q2_score": 0.6368863198928134}}
{"text": "%-------------------------------------------------------------------------------------------------------------------------------------------------\n\\section{Genetic Algorithm}\n\\label{section:GA}\n%-------------------------------------------------------------------------------------------------------------------------------------------------\nOne of the drawbacks of using a Reinforcement Learning strategy is that the training schema can potentially lead to a localized solution space. Such a solution might not have evaluated all possible strategies. This drawback can be countered by using the robustness of methods such as Genetic Algorithms, which carry out more thorough search. We use such a method in order to evolve a Neural Network controller managing the bot in a 1 unit Vs 1 unit fight. This methodology is called \\emph{Neuro Evolution} in general.\n\n%-------------------------------------------------------------------------------------------------------------------------------------------------\n\\subsection{Representation} \nOur objective for the neural network is to be able to make informed decisions by interpreting the game state. Hence, a representation for the game state needs to be formulated. This representation needs to be minimal since the number of inputs to the neural network directly correlate to the size of the chromosome to be evolved. In this approach, we use 8 inputs, 4 for each unit involved in the combat: \n\\begin{enumerate}\n\\item \\emph{Shots to Death} - This heuristics utilizes the fact that all units in the game, at any given time, will be eliminated by a particular opponent unit in certain number of attack commands. This parameter can be used to represent several values at the same time - \\emph{Hit-points}, \\emph{Armor}, \\emph{Opponent's Damage} and \\emph{Damage Multiplier}, combined in equation:\n\\begin{equation}\n\\label{equation:nShots}\n\\text{shots}=\\left \\lceil\\frac{\\text{HP}}{(\\text{damage}\\times\\text{times}-\\text{armor}) \\times\\text{mul}} \\right \\rceil \\text{,}\n\\end{equation}\nThis input is normalized over the maximum value of shots left to death when the game starts (maximum hot-points).\n\\item \\emph{Distance} - This number signifies the distance of the unit from the opponent, which is normalized over its weapon range.\n\\item \\emph{Cooldown Left} - The number of updates left before the unit can shoot again, which is normalized with the largest weapon cooldown time for the two units.\n\\item \\emph{Speed} - The unit's top movement speed possible. This is again normalized by the maximum speed out of the two units.\n\\end{enumerate}\nThe neural network can provide 3 output values, each corresponding to an action's desirability ({\\bf Move Towards Enemy}, {\\bf Move Away from Enemy} or {\\bf Attack}). The action with the maximum desirability is performed.\n\n%-------------------------------------------------------------------------------------------------------------------------------------------------\n\\subsection{Algorithm Parameters}\n\\begin{enumerate}\n\\item \\emph{Fitness}: The fitness of a particular chromosome is an integer value representing a Win ($1$) or a Loss ($-1$). To average out inaccuracy in fitness due to randomness, each chromosome is tested $20$ times and the fitness is averaged out. An alternate method to judge the fitness of a chromosome is to take an average of difference of hitpoints of the two units at the end of a match.\n\\item \\emph{Choosing parents}: The natural selection method used in this project is Elite Selection. In a population of $N$ chromosomes, each reproduction cycle selects $\\frac{N}{3}$ parents for breeding. However the selection method is modified in such a way that the chromosome with the best fitness is always selected (in order to not forget fitness comparison). The rest of the parents selected are uniformly distributed from the top portion of the population and bottom portion. This version is also comparable to the Roulette-Wheel selection methodology, where segments of the total population have certain selection probabilities.\n\\item \\emph{Crossover}: The selected parents reproduce themselves by a simple one point crossover approach. The selection of the split point is normally distributed for each gene.\n\\item \\emph{Mutation}: Each child gets mutated with a predefined mutation probability (standard value used in experiments is $0.2$). It is a recommended strategy to mutate a gene representing neural network connection weight by adding a Gaussian Random number. This enables the weight to be not bound within a particular range and enhance progression in the search space.\n\\item \\emph{Population Refresh}: All newly produced children, two per parent (i.e. $\\frac{N}{3}$ parents generate $\\frac{N}{3}$ children), automatically replace the $\\frac{N}{3}$ chromosomes at the bottom of the population (not replacing if a chromosome which was selected for parenting). The remaining $\\frac{N}{3}$ part of the population is completely mutated, meaning that their each gene mutates with a probability of $1.0$.\n\\item \\emph{Optimization}: Genetic Algorithms need a lot of fitness updates, especially in this case where a match to test fitness of a chromosome takes approximately 7 sec. Therefore one performance optimization made for the project is to preserve the fitness value of chromosomes that have not changed. In general, these are the chromosomes that were selected for parenting.\n\\end{enumerate}\n\n%-------------------------------------------------------------------------------------------------------------------------------------------------\n\\subsection{Results} \n%%%\n\n\\begin{table}\n\\caption{average winning rate}\n\\begin{center}\n% Table generated by Excel2LaTeX from sheet 'Sheet1'\n\\begin{tabular}{|r|r|r|r|}\n\\hline\n       &       {\\bf mean }&    {\\bf stdev} &  {\\bf p-value} \\\\\n\\hline\n\t\\emph{8.8.4.3 (ref)} & $  0.025$ &  $ 0.099 $ &        --- \\\\\n\\hline\n\t\\emph{ 8.8.3 }&   $0.019$ &  $  0.099 $ & $ 0.459 $ \\\\\n\\hline\n \t\\emph{8.1.3 }&  $ 0.014$ &   $ 0.104 $ & $ 0.094 $ \\\\\n\\hline\n\\end{tabular}  \n\\label{table:winningRate}\n\\end{center}\n\\end{table}\n% ---------\n\n\\begin{enumerate}\n\\item Neural Network Structure - While designing the agent, one of the things on our mind was for the neural network to be able to process the inputs efficiently and try to decipher the optimal output values. But there is no way to understand the relation of the input values to the playing strategy for the agent. To test what structure of the neural network can achieve the most efficient results for the bot, we run T-tests with $3$ different structures of the network:\n\\begin{itemize}\n\\item Inputs (8), Hidden Layer (1), Output Layer (3)\n\\item Inputs (8), Hidden Layer (8), Output Layer (3)\n\\item Inputs (8), Hidden Layer (8), Hidden Layer (4), Output Layer (3)\n\\end{itemize}\nThe agent is trained in each case for a certain number of iterations (in this case they were trained for $60$ iterations) and then the best chromosome in each pool plays the game to create a sample space to be tested. The results for the T-test carried out on the three samples are presented in Table \\ref{table:winningRate}. The samples are compared with respect to the $8,8,4,3$ network. While comparing the network with the $8,8,3$ neural network, the relatively high p-value signifies that they are similar. This means that the using the larger network is an overkill as it provides relatively similar output quality as the smaller network. This, however is not the case with the $8,1,3$ network. The low p-value means that the samples are not similar. Then the decision to select a network falls on the which has a higher success-rate (which is already being measured by the average fitness value of the chromosomes).\n\\begin{figure}[htp]\n\\centerline{\\includegraphics[width=1.0\\columnwidth]{fig_GA_AverageFitness}}\n\\caption{Graph showing the progression of Average Fitness of population of size $10$, $20$ and $30$, respectively: NN configuration is $8,8,3$}\n\\label{fig:AverageFitness}\n\\end{figure}\n\\item Population Size - We are also interested in finding out the rate of convergence of the Genetic Algorithm, as well as its dependency on the population size. Generally a larger population size is preferred, since the high number of chromosomes provide a bigger search space for the algorithm to find a fit individual in. But this leads to a lot of overhead on the system to process individuals introduced on each iteration in the larger population. To assess this parameter, we look at a comparative Figure \\ref{fig:AverageFitness} showing the progression of average fitness of the populations of sizes $10$, $20$ and $30$. The population with size 10 seems to be too small and has slow convergence to the other two populations. The other two populations are very close in average performance and hence a smaller and more efficient population size is selected. \n\\begin{figure}[htp]\n\\centerline{\\includegraphics[width=1.0\\columnwidth]{fig_GA_Fitness_MinAvgMax}}\n\\caption{Graph showing the minimum, average and maximum fitness of population of size $10$, NN configuration is $8,8,3$}\n\\label{fig:minAvgMaxFitness}\n\\end{figure}\n\\item Fitness Spread - In a genetic algorithm, the reproduction and discard rules are used to introduce new individuals to the population that can spread the solution in a much broader spectrum. This counters the problems provided by other computation intelligence algorithms to get stuck in local minima. A way to test the spread of the population is by graphing the minimum, average and maximum fitness of a population (size = $10$), as shown in Figure \\ref{fig:minAvgMaxFitness}. A large distance between the minimum and maximum fitness points to the conclusion that the population is taking care of introducing diverse individuals.\n\\end{enumerate}\n\n%%%\n\\begin{figure}[htp]\n\\centerline{\\includegraphics[width=1.0\\columnwidth]{fig_GA_Speciation_Top2}}\n\\caption{Graph of Specie difference between the top two chromosomes}\n\\label{fig:specieTop2}\n\\end{figure}\n\\begin{figure}[htp]\n\\centerline{\\includegraphics[width=1.0\\columnwidth]{fig_GA_Speciation_next2}}\n\\caption{Graph of Specie difference between $2^{nd}$ and $3^{rd}$ ranked chromosomes}\n\\label{fig:specieNext2}\n\\end{figure}\n\n%-------------------------------------------------------------------------------------------------------------------------------------------------\n\\subsection{Discussion}\nAccording to our tests with the network structure and the population size, the best solution for our one versus one approach is a network structure of 8,8,3 and a population size of $20$. Although the bigger network also evolved well, in terms of performance we clearly have to choose the smaller one.\nAccording to the figure \\ref{fig:AverageFitness}, the population size of $20$, roughly scores as good as the population size of $30$. When we take the fact, that a smaller population size will evolve $\\frac{1}{3}$ faster, into account, we have to chose a population size of $20$.\n\nIf we measure the cumulative distance between each gene of the top two candidates in the populations which is depicted in Figure \\ref{fig:specieTop2}, we can see that the larger populations in genetic evolution hamper the evolving chances because of higher preservation of the top candidates. This can be attributes to the elite selection methodology we have employed that gives increasingly higher probability to the $1^{st}$ and $2^{nd}$ chromosomes to be selected for parenting.\nThis pattern becomes much more varied if we calculate the distance between the $2^{nd}$ and $3^{rd}$ chromosomes (Figure \\ref{fig:specieNext2}), which depicts the higher chances for the chromosomes on those positions to be mutated.\n%%%", "meta": {"hexsha": "a58d493e7afb99b0e52285875a2d06ad8fe0f203", "size": 11665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/_ga.tex", "max_stars_repo_name": "indusninja/sc-bw-ai", "max_stars_repo_head_hexsha": "c00a29ad3bf3421d7fdb1b0514424d69154ae7b9", "max_stars_repo_licenses": ["MIT"], "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/_ga.tex", "max_issues_repo_name": "indusninja/sc-bw-ai", "max_issues_repo_head_hexsha": "c00a29ad3bf3421d7fdb1b0514424d69154ae7b9", "max_issues_repo_licenses": ["MIT"], "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/_ga.tex", "max_forks_repo_name": "indusninja/sc-bw-ai", "max_forks_repo_head_hexsha": "c00a29ad3bf3421d7fdb1b0514424d69154ae7b9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 117.8282828283, "max_line_length": 922, "alphanum_fraction": 0.7195885126, "num_tokens": 2534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.636886314611307}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\begin{document}\n\\title{Eisenstein Triples: Connecting geometry and number theory}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{A number theory problem}\n\nWe start with a number theory puzzle: Can you find positive integer triples $(a,b,c)$ such that:\n\\[ \\frac{1}{a+c} + \\frac{1}{b+c} = \\frac{3}{a+b+c} \\]\n\nTo get started with our exploration, let's clear denominators by multiplying across by\n$(a+c)(b+c)(a+b+c)$ to get:\n\\begin{equation*}\n\\begin{split}\n(b+c)(a+b+c) + (a+c)(a+b+c) & = 3(a+c)(b+c) \\\\\na^2 + b^2 + 2c^2 + 2ab + 3bc + 3ac & = 3ab + 3ac + 3bc + 3c^2 \\\\\na^2 - ab + b^2 &= c^2\n\\end{split}\n\\end{equation*}\n\nOur goal will be to find positive integer solutions to this equation.\n\n\\section{A geometric aside}\n\nThis equation may look familiar to anyone who has come across the cosine rule in geometry.\nFor the sides of a triangle $(a,b,c)$ with opposite angles $(A,B,C)$:\n\n\\[ c^2 = a^2 + b^2 -2ab\\cos(C) \\]\n\nwith similar equations for $a^2, b^2$.\n\nRewriting the equation above in this form, we can see that the problem is equivalent to finding\ntriangles with integer sides $(a,b,c)$ such that $\\cos(C) = \\frac{1}{2}$ - that is,\n$C = \\frac{\\pi}{3}$. In other words, our challenge is to find triangles with one angle measuring\n$60^{\\circ}$ which have integer side lengths.\n\nThis is a well known problem that has been explored by many number theorists in the past, and\ntriples of this form are known as Eisenstein triples, named after the mathematician Eisenstein.\n\nBy considering the problem as one of triangles with a certain constraint, perhaps we can approach\nthis problem the way we would approach finding Pythagorean triples.\n\n\\section{Factoring sums of squares}\n\nOne way to generate Pythagorean triples is to factor $a^2+b^2$ over the Gaussian integers - that is,\nthe subset of the complex numbers $a+ib$ with $a,b\\in \\mathbb{Z}$. In the Gaussian integers, we can \nrewrite $ a^2 + b^2 = a^2 - b^2i^2$ as a difference of two squares - yielding a factorization:\n\\[ c^2 = a^2 + b^2 = (a+ib)(a-ib) \\]\n\nHow does this help? Well, if we take an arbitrary Gaussian integer $z = a+ib$, the length of $z$ is\n$|z| = \\sqrt{a^2+b^2}$ - so if we take the length of $z^2$, we are guaranteed to get an integer\nlength, since $|z|^2 = |z^2|$. We will have:\n\\begin{equation*}\n\t\\begin{split} \n\t\tz^2 &= (a+ib)^2 \\\\\n\t\t& = a^2-b^2 + i(2ab) \\\\\n\t\t|z^2| &= \\sqrt{(a^2-b^2)^2 + (2ab)^2 }\\\\\n\t\t|z|^2 &= a^2 + b^2 \\\\\n\t\t|z^2| &= |z|^2 \\\\\n\t\t\\Rightarrow (a^2-b^2)^2 + (2ab)^2 &= (a^2 + b^2)^2\n\t\\end{split}\n\\end{equation*}\n\nSo if we take \\textbf{any} positive integers $(a,b)$, we can generate a Pythagorean triple \n$(a^2-b^2, 2ab, a^2+b^2)$ from them.\n\nCan we use a similar approach with our puzzle? Indeed we can!\n\n\\section{Factoring the quadratic in $\\mathbb{C}$}\n\nWe can factor $a^2 - ab + b^2$ in complex numbers too by setting it equal to zero and using \nthe quadratic formula:\n\\begin{equation*}\n\t\\begin{split} \n\t\ta^2 - ab + b^2 &= 0 \\\\\n\t\ta &= \\frac{1}{2}\\left(b \\pm \\sqrt{b^2-4b^2}\\right) \\\\\n\t\t&= \\frac{b}{2}\\left(1 \\pm \\sqrt{3}i\\right)\n\t\\end{split}\n\\end{equation*}\n\nThe factorization is:\n\\[ a^2 - ab + b^2 = \n\\left(a + \\frac{b}{2}\\left(-1 - \\sqrt{3}i\\right) \\right)\n\\left(a + \\frac{b}{2}\\left(-1 + \\sqrt{3}i\\right) \\right) \\]\n\nIf you have done any complex analysis these roots might look familiar to you. Given \n$z = \\frac{1}{2}(-1+\\sqrt{3}i)$ then:\n\\begin{equation*}\n        \\begin{split} \n\t\tz^2 & = \\frac{1}{4}(-1+\\sqrt{3}i)^2 \\\\\n\t\t& = \\frac{1}{4}(1 - 2\\sqrt{3}i - 3) \\\\\n\t\t& = \\frac{1}{2}(-1 - \\sqrt{3}i) \\\\\n\t\t& = \\bar{z}\n        \\end{split}\n\\end{equation*}\n\nand:\n\n\\begin{equation*}\n        \\begin{split}\n                z^3 & = \\frac{1}{8}(-1+\\sqrt{3}i)^3 \\\\\n\t\t& = \\frac{1}{8}(- 1 + 3\\sqrt{3}i +9 -3\\sqrt{3}i) \\\\\n                & = 1\n        \\end{split}\n\\end{equation*}\n\nThese are the cube roots of unity, $\\omega = \\frac{1}{2}(-1+\\sqrt{3}i), \\omega^2 = \\frac{1}{2}(-1-\\sqrt{3}i)$.\nOne identity of the cube roots that we will use below is that $1 + \\omega + \\omega^2 = 0$, so \n$\\omega = -1 -\\omega^2$ and $\\omega^2 = -1 -\\omega$.\n\nWe can rewrite our original problem expression as:\n\\[ c^2 = (a+\\omega b)(a + \\omega^2 b) \\]\n\nLet's try the same trick as we used with Pythagorean triples, and see what happens when we start with\n$z = a + \\omega b$ for $a,b\\in \\mathbb{Z}$.\n\n\\begin{equation*}\n        \\begin{split}\n\t\t|z| & = \\sqrt{(a+\\frac{b}{2})^2 + (\\frac{\\sqrt{3}b}{2})^2} \\\\ \n\t\t    &= \\sqrt{a^2-ab+b^2} \n\t\\end{split}\n\\end{equation*}\n\nIn general, $|a+ \\omega b| = |a + \\omega^2 b| = \\sqrt{a^2-ab+b^2}$.\n\n\\begin{equation*}\n        \\begin{split}\n                z^2 & = a^2 + 2ab\\omega +\\omega^2 b^2 \\\\\n\t\tz^2 & = a^2 + 2ab\\omega +(-1 - \\omega) b^2 \\\\\n\t\t    & = (a^2 -b^2) + (2ab - b^2)\\omega \\\\\n\t\t|z^2| &= \\sqrt{(a^2-b^2)^2 - (a^2-b^2)(2ab-b^2) + (2ab-b^2)^2}\n\t\\end{split}\n\\end{equation*}\n\n\nAnd since $|z^2| = |z|^2$ we get:\n\\[ (a^2-ab+b^2)^2 = (a^2-b^2)^2 - (a^2-b^2)(2ab-b^2) + (2ab-b^2)^2 \\]\n\nSo, given any positive integers $(a,b)$, we can generate triples satisfying the equation \n$(a^2-b^2, 2ab-b^2, a^2-ab+b^2)$.\n\nTrying some values we find:\n\\begin{equation*}\n        \\begin{split}\n\t\t(a,b) = (2,1) & \\Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (3, 3, 3) \\\\\n\t\t(a,b) = (3,1) & \\Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (8, 5, 7) \\\\\n\t\t(a,b) = (4,3) & \\Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (7, 15, 13)\n\t\\end{split}\n\\end{equation*}\n\nWe can easily check that $7^2 = 8^2 - (8)(5) + 5^2$ and $13^2 = 7^2 - (7)(15) + 15^2$.\n\nWe have a formula to generate an infinite number of triples satisfying our equation $a^2-ab+b^2=c^2$ - nice!\nLet's check that they also solve our initial puzzle:\n\n\\begin{equation*}\n        \\begin{split}\n\t\t\\frac{1}{7+13} + \\frac{1}{15+13} & = \\frac{1}{20} + \\frac{1}{28} \\\\\n\t\t& = \\frac{48}{560} \\\\\n\t\t& = \\frac{3}{35} \\\\\n\t\t& = \\frac{3}{7 + 13 + 15}\n        \\end{split}\n\\end{equation*}\n\n\\section{A geometric approach}\n\nDoes this method yield all possible triples? It is hard to tell, but we have other tools that we can\nuse to find that answer. Again, we are going to start with a search for Pythagorean triples to\nexplore this approach.\n\n\\begin{figure}[htb]\n        \\center{\\includegraphics[width=0.9 \\linewidth]{Pythagorean_circle.png}}\n        \\caption{Finding rational points with a line of rational slope}\n        \\label{fig:pyth_circle}\n\\end{figure}\n\nReplacing $x = \\frac{a}{c}, y = \\frac{b}{c}$, we can see that finding integer solutions to $a^2 + b^2 = c^2$\nis equivalent to finding rational solutions to $x^2 + y^2 = 1$. This is the equation of a circle of radius 1,\ncentered on the origin.\n\nIf we can find a way to find all rational points on the perimeter of the circle, then we will have found all\npossible pythagrean triples, up to multiplication by a scalar (since if $a^2 + b^2 = c^2$, then\n$(ka)^2 + (kb)^2 = (kc)^2$ for all $k \\in \\mathbb{Z}$). One way we can do that is to find one rational\npoint on the circle (say, $(0,-1)$, and draw lines through that point with a rational slope. We can show\nthat, since the slope of the line is rational, and the equation of the circle has integer coefficients, then\nif one intersection point is rational (as it is by design), then the other point must also be rational.\n\nLet's take an example to see how it happens. The line of slope $t$ through $(x,y) = (-1,0)$ is:\n\\[ y = tx +t\\]\n\nClearly, $(-1,0)$ is on this line. Now, substituting this value of $y$ into the equation of the circle,\n$x^2+y^2-1 = 0$, we get:\n\\[x^2 + (tx+t)^2 -1 = (1+t^2)x^2 +2t^2x + t^2 -1 = 0 \\]\nAnd solving for $x$ we get $x = -1$ or $x = \\frac{1-t^2}{1+t^2}$. Substituting this value of $x$ back into\nour line, we get $y = \\frac{2t}{1+t^2}$. We can easily verify that for any value of $t$ that this satisfies\nthe equation of the circle, as expected. And since $t$ is rational, $x$ and $y$ are guaranteed to be\nrational too.\n\nIs it possible, though, that we would somehow miss rational points in the circle by this method? \nNo - given any rational point $(x,y)$ on the perimeter of the circle, the slope of the line through\n$(x,y)$ and $(-1,0)$ is $\\frac{y}{x+1}$, which is clearly rational. Since this would be a line with rational\nslope which goes through the point $(-1,0)$, we are guaranteed that by enumerating all of the rational\nnumbers for line slopes, we are guaranteed to hit all of the rational points on the circle.\n\nIf we take the slope to be $t = \\frac{m}{n}$ for $m,n \\in \\mathbb{Z}$ we can multiply across the\ntop and bottom by $n^2$ in the formulas for $x = \\frac{1-t^2}{1+t^2}, y = \\frac{2t}{1+t^2}$ to give\nthe Pythagorean triples $a = n^2-m^2, b = 2mn, c = n^2 + m^2$ for the familiar formula we found above.\n\nTaking this approach with our problem, we substitute $x = \\frac{a}{c}, y = \\frac{b}{c}$ to get the equation:\n\\[ x^2 - xy + y^2 = 1 \\]\n\n\\begin{figure}[htb]\n        \\center{\\includegraphics[width=0.9 \\linewidth]{Eisenstein_ellipse.png}}\n        \\caption{Finding rational points with a line of rational slope}\n        \\label{fig:eisen_ellipse}\n\\end{figure}\n\nThis is an ellipse, centered on the origin, which goes through the points $(0,-1), (0,1), (-1,0), (1,0)$\non the X and Y axis. There are also a few other \"nice\" rational points on the curve at $(-1,-1), (1,1)$.\n\nNow taking the same approach, given any rational number $t$, we can find the intersection points of our\nellipse and the line $y = t(x+1)$ (which again goes through $(-1,0)$):\n\n\\begin{equation*}\n        \\begin{split}\n\t\tx^2 - xy + y^2 & = x^2 - tx(x+1)+t^2(x+1)^2 \\\\\n\t\t&= (1-t+t^2)x^2 +(2t^2-t)x + t^2 \\\\\n\t\t&= 1 \n\t\\end{split}\n\\end{equation*}\n\nNow factoring to find the intersection points, we find, as expected, one of the points at $x=-1$, and\nthe other is a rational function of $t$:\n\\begin{equation*}\n\t\\begin{split}\n\t\t(1-t+t^2)x^2 + (2t^2-t)x + (t^2-1) &= 0 \\\\\n\t\t(x + 1)((1-t+t^2)x + (t^2 - 1)) = 0\n        \\end{split}\n\\end{equation*}\n\nSo we have $x = -1$ or $x = \\frac{1 - t^2}{1-t+t^2}$ for rational $t$.\n\nSubstituting the valie for $x$ back into the equation for the line:\n\\[ y = t(x+1) = \\frac{2t - t^2}{1-t+t^2} \\]\n\nAnd replacing $t = \\frac{m}{n}$ and multiplying through with $n^2$ above and below the line we get:\n\\[(x,y) = \\left(\\frac{n^2-m^2}{n^2-mn+m^2}, \\frac{2nm - m^2}{n^2-mn+ m^2}\\right) \\]\n\nAnd clearing a common denominator, we get an integer triple\n$(a,b,c) = (n^2 - m^2, 2nm - m^2, m^2 - mn + n^2)$ as before.\n\nA similar argument as before shows that this will find \\textbf{all} rational points on the\nellipse, giving all integer solutions to the original problem (after dividing out any common factors\nof $a, b, c$).\n\nInterestingly, if we take a different rational point on the ellipse, we will get a different, but\nequally valid, formula for generating Eisenstein triples from rational numbers. The equation of\na line through $(-1,-1)$, for example, is $y + 1 = t(x + 1)$. Isolating $y$, and substituting this\ninto the equation of the ellipse, we get:\n\\begin{equation*}\n        \\begin{split}\n\t\tx^2 - xy + y^2 - 1 & = x^2 - x(t(x+1)-1) + (t(x+1)-1)^2 - 1\\\\\n\t\t& = x^2 -tx^2 -tx + x + t^2(x^2+2x+1)-2t(x+1)+1 \\\\\n\t\t& = (1 - t + t^2)x^2 + (1 - 3t + 2t^2)x + (t^2-2t) \\\\\n\t\t& = (x+1)((1 - t + t^2)x + (t^2-2t)) = 0\n\t\\end{split}\n\\end{equation*}\n\nGiving the solutions $x = -1$ or $x = \\frac{2t-t^2}{1-t+t^2}$.\nSubstituting this back into the equation for the line, we get:\n\\begin{equation*} \n        \\begin{split}\n\t\ty &= t\\left(\\frac{2t-t^2}{1-t+t^2} + 1\\right) - 1 \\\\\n\t\t& = \\frac{t^2 + t}{1-t+t^2} - 1 \\\\\n\t\t& = \\frac{2t - 1}{1 - t + t^2}\n\t\\end{split}\n\\end{equation*}\n\nReplacing $t = \\frac{m}{n}$, we get:\n\\[ x = \\frac{2mn - m^2}{m^2 - mn + n^2}, y = \\frac{2mn - n^2}{m^2 - mn + n^2} \\]\nWhich gives an alternative form for triples of:\n\\[ (a,b,c) = (2mn - m^2, 2mn - n^2, m^2 -mn + n^2) \\]\n\nwhich, surprisingly perhaps, is exactly equivalent to the formula we found earlier.\n\n\\end{document}\n", "meta": {"hexsha": "5d2853ac067c2ce2f0aa000b049a585fcd862614", "size": 11910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "eisensten_triples.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": "eisensten_triples.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": "eisensten_triples.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": 40.2364864865, "max_line_length": 110, "alphanum_fraction": 0.6278757347, "num_tokens": 4374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6368766807388075}}
{"text": "\\chapter{Acceptance Sampling}\n\\chaptermark{Acceptance}\n\n% AQL\n% LTPD\n% RQL\n% LQL\n% Type A and Type B RO curves.\n\nWe can improve quality (read- conformance to specification) by introducing an inspection stage in our process.\nClearly, a full inspection is time consuming. \nIt may also be destructive (you don't want to re-package ice-cream after checking its texture \\dots).\nNo-inspection may be appropriate if you don't particularly care about your brand, or if production has very high capability indices.\nA reasonable, intermediate approach, is a partial random inspection, known as \\emph{acceptance sampling}.\nAs the name suggests, in acceptance sampling, one samples, then checks, then accepts (or not).\n\nAcceptance sampling can be seen as a control chart monitoring that triggers active intervention in the production. As such ,it is a crude type of \\emph{engineering control} (Sec.~\\ref{sec:terminology_statistical}).\nThe intervention is obvious. The monitoring is based on some continuous (variable) or discrete (attribute) of a sample of units from a \\emph{batch}, \\aka, a \\emph{lot}.\nSeen as a feedback control, it is not surprising that when designing an acceptance sampling scheme, we have similar decisions as when designing a control chart:\n\\begin{enumerate}\n\\item What is a batch? Just like choosing the sampling frequency in a Shewart chart. \nWe would like homogenous batches, i.e., with low inner variability. A box, a shipment, a day's production, are typical batches. \n\\item Within batch sampling scheme: just like rational grouping in Shewart chart. Typical approaches include \\emph{single sampling plans}, \\emph{double}, \\emph{multiple}, and \\emph{sequential sampling plans}.\nThis can be seen as the design of an experiment to be performed on each batch.\n\\item How many units? Just like choosing the sample size in a Shewart chart.\n\\item Decision cutoff: Just like setting control limits in a Shewart chart. \n\\end{enumerate}\nWe can readily see that the design of an acceptance sampling scheme is very similar to the design of a control chart. \nWe may construct an full blown economical optimization problem to design the sampling, as we did in Section~\\ref{sec:economical_considerations}. Just like control charts, however, it is more common to design sampling schemes using ``first-order'' power considerations. \nFor this reason, the \\emph{power function} will play a crucial role.\n\n\\section{Acceptance Sampling Terminology}\nAdapted from \\cite{natrella_nist/sematech_2010}.\n\\begin{description}\n\\item [LASP] A \\emph{lot acceptance sampling plan}, ultimately, a statistical test at the end of which we either accept a batch. In this text we typically use the \\emph{batch acceptance sampling scheme} for the same purpose. \n\\item [AQL] The \\emph{acceptable quality level}, or \\emph{acceptable quality limit}, is the highest proportion of defects acceptable to the producer. \n\\item [LTPD] The \\emph{lot tolerance percent defective} is the highest proportion of defects acceptable to the consumer. Clearly, $AQL<LTPD$. LTPD is also known as \\emph{rejectable quality level} (RQL), and \\emph{ limiting quality level} (LQL). \n\\item [OC Curve] The \\emph{operating characteristic curve} is the power function of an LSAP.\n\\item [Type-A and Type-B OC Curves] A \\emph{Type-A OC curve} is one computed assuming sampling from batches is done without replacement. Conversely, a \\emph{Type-B OC curve} is computed assuming sampling with replacement.\n\\item [Producer's Risk] The \\emph{producer's risk} is throwing away good batches. Formally, this is the probability of rejecting a batch with less than AQL defects. We consider there type-I errors.\n\\item [Consumer's Risk] The \\emph{consumer's risk} is accepting bad batches. Formally, this is the probability of accepting a batch with more than LTPD defects. We consider there type-II errors.\n\\item [Rectifying Inspection] An LASP where lots are not rejected but rather rectified. \n\\end{description}\n\n\n\n\\section{Single Sampling Scheme}\nIn the simplest LASP we base our decisions on a single random sample from each batch.\nThis obviously facilitates the statistical analysis of the properties of this LASP.\n\n\\subsubsection{Type-B Power Function}\n\nWhen sampling $n$ units from a batch with a proportion of $p$ defects, then the number of defects $\\x \\sim Binom(n,p)$.\nIf we reject a batch when more than $c$ defects are found, then the power function of a type-B LASP is given by\n\\begin{align}\n\\label{eq:power_accpet}\n\t\\pi_{n,c}(p)=P(\\x \\geq c)= \\sum_{k=c}^n \\binom{n}{k} p^k (1-p)^{1-k} .\n\\end{align}\nEq.(\\ref{eq:power_accpet}) may be evaluated manually, or with the \\rcode{pbinom()} \\R function. \n\nJust like any other hypothesis test, it is common practice to set $n,c$ so that control both the consumer's risk ($\\beta_{n,c}=1-\\pi_{n,c}$) and the producer's risk ($\\alpha_{n,c}$).\nBy adopting a the hypothesis testing philosophy, we solve $n,c$ so that \n\\begin{align}\n\\label{eq:power_acceptance}\n \\min \\set{n : \\pi_{n,c}\\geq \\pi_0 \\quad and \\quad \\alpha_{n,c}\\leq \\alpha_0 }.\n\\end{align}\nFor relating the LASP terminology to this problem, we need to observe that $$\\alpha_{n,c}=\\pi_{n,c}(p=AQL)$$ and $$\\pi_{n,c}=\\pi_{n,c}(p=LTPD).$$\nFor a producer who does not want to reject batches where $AQL=10\\%$ defects, with more than $\\alpha_0=10\\%$; \nand a consumer who does not want to accept batches where $LTPD=30\\%$, with less than $\\pi_0=80\\%$, \nwe have that their LASP would take $n=33$ samples, and reject a batch whenever the $\\x>4$, when $n=21$.\n\\begin{remark}[Approximate Power Calculations]\nThe problem to solve in Eq.(\\ref{eq:power_acceptance}) requires some non trivial iterations because of the discrete nature.\nIt is quite more convenient to replace the exact form of Eq.(\\ref{eq:power_accpet}) with a normal approximation, so that Eq.(\\ref{eq:power_acceptance}) has a closed form solution. \n\\end{remark}\n\n\n\n\\subsubsection{Type-A Power Function}\nIt is quite wired that we would sample with replacement from a batch.\nIt is quite more probable that we used the replacement assumption, only as an approximation because $n$ is small compared to the batch size $N$. \nIf this is not the case, the binomial distribution in Eq.(\\ref{eq:power_accpet}) should be replaced with the Hypergeometric distribution. \nFor all practical purposes, this means using the \\rcode{phyper()} \\R function, instead of \\rcode{pbinom()}.\n\n\n\n\\subsection{Double Sampling Scheme}\nIn a double sampling scheme, we first example $n_1$ units. \nWe may then decide to accept, reject, or sample another $n_2$ units. \nAfter those $n_2$ samples, we can accept or reject. \nThe idea of a power function remains the same, even if calculations are slightly more cumbersome.\nHere is our our policy:\nFor $x_1$ computed on the first $n_1$ samples:\nIf $x_1  < a_1$ then accept the batch;\nIf $x_1 \\geq  c_1$ then reject the batch;\nOtherwise, compute $x_2$ with $n_1+n_2$ samples.\nIf $x_2 < a_2$ accept the batch;\nIf $x_2 \\geq c_2$ then reject the batch.\n\nFor brevity, we denote all the design parameters of the scheme by $\\gamma:= (n_1,n_2,c_1,c_2,a_1,a_2)$. \nThe power function of such a scheme would thus be:\n\\begin{align}\n\t\\pi_\\gamma &:= P(\\set{\\x_1 \\geq c_1} \\union \\set{\\x_1 \\in [a_1,c_1], \\x_2 \\geq c_2}) \\\\\n\t&= P(\\x_1 \\geq c_1) + \\sum_{k=a_1}^{c_1} P(\\x_1 =k, \\x_2-\\x_1 \\geq c_2-k) \\\\\n\t\t&= P(\\x_1 \\geq c_1) + \\sum_{k=a_1}^{c_1} P(\\x_1 =k) P(\\x_2-\\x_1 \\geq c_2-k).\n\\end{align}\nWe may now use the fact that $\\x_1 \\sim Binom(n_1,p)$ and that $\\x_2-\\x_1 \\sim Binom(n_2,p)$, and quickly compute the power in \\R.\n\n\\begin{remark}[Redundancy]\nUnlike the single stage LASP, where we have two equations with two variables, in the two-stage case there are many $\\gamma$ configurations that will achieve given consumer and producer risks ($\\alpha_0,\\pi_0$).\nThe choice of the particular configuration should depend on the type of signal we expect. \nFor quick detection of strong signal (large $p$), choose small $n_1$. \nFor sensitive detection of subtle signal, choose large $n_1$. \n\\end{remark}\n\n\\begin{remark}[No Free Lunch]\nWhile it may seem that a two stage LASP is always better than a single stage LASP, this is not the case.\nTo see why, consider a weak signal ($p$ close to AQL). We may need all $n_1+n_2$ samples to get decent power. The first stage then add nothing except logistic complications.\n\\end{remark}\n\n\n\\section{Sequential Scheme}\nAt this point you should be thinking: why only two stages? \nClearly we may reject or accept a sample as each unit comes in.\nThis is exactly what Sequential LASPs are all about.\nWe will not give the details, except the observation that this is merely a type of sequential experiment as described in Section~\\ref{sec:sequantial}.\n\n\n\n\n\\section{Bibliographic Notes}\n[TODO]", "meta": {"hexsha": "c04f13049010a8ffb9b17a06545511390af76934", "size": 8722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Class_notes/acceptance.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/acceptance.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/acceptance.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": 66.5801526718, "max_line_length": 269, "alphanum_fraction": 0.7575097455, "num_tokens": 2368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6368766804521679}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.8 Symmetry of $R_{ab}$}\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   \\partial{#}::PartialDerivative;\n\n   g_{a b}::Metric;\n   g^{a b}::InverseMetric;\n\n   dgab := \\partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \\partial_{c}{g_{e f}}.\n                                                          # cdb (dgab.000,dgab)\n\n   Gamma := \\Gamma^{a}_{b c} -> (1/2) g^{a e} (   \\partial_{b}{g_{e c}}\n                                                + \\partial_{c}{g_{b e}}\n                                                - \\partial_{e}{g_{b c}}).\n                                                          # cdb (Gamma.000,Gamma)\n\n   Rabcd := R^{a}_{b c d} ->\n            \\partial_{c}{\\Gamma^{a}_{b d}} + \\Gamma^{a}_{e c} \\Gamma^{e}_{b d}\n          - \\partial_{d}{\\Gamma^{a}_{b c}} - \\Gamma^{a}_{e d} \\Gamma^{e}_{b c}.\n                                                          # cdb (Rabcd.000,Rabcd)\n\n   Rab := R_{a b} -> R^{c}_{a c b}.                       # cdb (Rab.000,Rab)\n\n   expr := 4 (R_{a b} - R_{b a}).                         # cdb (ex-0308.100,expr)\n\n   substitute   (expr, Rab)                               # cdb (ex-0308.101,expr)\n   substitute   (expr, Rabcd)                             # cdb (ex-0308.102,expr)\n   substitute   (expr, Gamma)                             # cdb (ex-0308.103,expr)\n\n   distribute   (expr)                                    # cdb (ex-0308.104,expr)\n   product_rule (expr)                                    # cdb (ex-0308.105,expr)\n   canonicalise (expr)                                    # cdb (ex-0308.106,expr)\n\n   substitute   (expr, dgab)                              # cdb (ex-0308.107,expr)\n   canonicalise (expr)                                    # cdb (ex-0308.108,expr)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0308.100} = \\Cdb*{ex-0308.101}\n                             = \\Cdb*{ex-0308.102}\n                             = \\Cdb*{ex-0308.103}\n                             = \\Cdb*{ex-0308.104}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0308.105}\n                             = \\Cdb*{ex-0308.106}\n                             = \\Cdb*{ex-0308.107}\n                             = \\Cdb*{ex-0308.108}}\n\\end{dgroup*}\n\n\\clearpage\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.8 Symmetry of $R_{ab}$ alternative solution}\n\nThis differs from the previous code by the inclusion of a call to \\verb|canonicalise| immediately\nafter the first two substitutions and a declaration that $\\Gamma^{a}{}_{bc}$ is symmetric in $bc$.\nThis pair of changes produces a more compact set of results than given above. Incidently, this also\nshows that $\\partial_{a}\\Gamma^{c}{}_{bc} = \\partial_{b}\\Gamma^{c}{}_{ac}$.\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   \\partial{#}::PartialDerivative;\n\n   \\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).\n\n   g_{a b}::Metric;\n   g^{a b}::InverseMetric;\n\n   dgab := \\partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \\partial_{c}{g_{e f}}.\n                                                          # cdb (dgab.000,dgab)\n\n   Gamma := \\Gamma^{a}_{b c} -> (1/2) g^{a e} (   \\partial_{b}{g_{e c}}\n                                                + \\partial_{c}{g_{b e}}\n                                                - \\partial_{e}{g_{b c}}).\n                                                          # cdb (Gamma.000,Gamma)\n\n   Rabcd := R^{a}_{b c d} ->\n            \\partial_{c}{\\Gamma^{a}_{b d}} + \\Gamma^{a}_{e c} \\Gamma^{e}_{b d}\n          - \\partial_{d}{\\Gamma^{a}_{b c}} - \\Gamma^{a}_{e d} \\Gamma^{e}_{b c}.\n                                                          # cdb (Rabcd.000,Rabcd)\n\n   Rab := R_{a b} -> R^{c}_{a c b}.                       # cdb (Rab.000,Rab)\n\n   expr := 4 (R_{a b} - R_{b a}).                         # cdb (ex-0308.200,expr)\n\n   substitute   (expr, Rab)                               # cdb (ex-0308.201,expr)\n   substitute   (expr, Rabcd)                             # cdb (ex-0308.202,expr)\n   canonicalise (expr)                                    # cdb (ex-0308.203,expr)\n   substitute   (expr, Gamma)                             # cdb (ex-0308.204,expr)\n\n   distribute   (expr)                                    # cdb (ex-0308.205,expr)\n   product_rule (expr)                                    # cdb (ex-0308.206,expr)\n   canonicalise (expr)                                    # cdb (ex-0308.207,expr)\n\n   substitute   (expr, dgab)                              # cdb (ex-0308.208,expr)\n   canonicalise (expr)                                    # cdb (ex-0308.209,expr)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0308.200} = \\Cdb*{ex-0308.201}\n                             = \\Cdb*{ex-0308.202}\n                             = \\Cdb*{ex-0308.203}\n                             = \\Cdb*{ex-0308.204}\n                             = \\Cdb*{ex-0308.205}\n                             = \\Cdb*{ex-0308.206}\n                             = \\Cdb*{ex-0308.207}\n                             = \\Cdb*{ex-0308.208}\n                             = \\Cdb*{ex-0308.209}}\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "59b2e0674fcae7b3862f5e5551e9034c94efb0c4", "size": 5450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0308.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-0308.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-0308.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.9516129032, "max_line_length": 99, "alphanum_fraction": 0.399266055, "num_tokens": 1573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6368766764763487}}
{"text": "\\section{Ambiguity}\n\nA sentence $x$ of $G$ is ambiguous iff it admits different syntax trees. In that case $G$ is ambiguous. The degree of ambiguity of $x$ is the number of distinct trees of $x$, of $G$ is the maximum over its sentences.\n\n\\paragraph{RegExp ambiguity} given an r.e. f , we number its letters and we obtain a numbered r.e. is ambiguous if the language defined by the numbered r.e. contains two distinct strings x and y that become identical when the numbers are erased.\n\n\n\\paragraph{Bilateral Recursions} $E \\rarr E + E | i$ becomes $E \\rarr i + E | i$.\n\n\\paragraph{Left-Right Recurions in different rules} $A \\rarr aA | Ab | c$. Remedies: generate using different rules or force an order of derivation.\n\n\\paragraph{Union of Languages} assume that the two non-terminal sets are disjoint, otherwise the union grammar would generate\na superlanguage that strictly contains both languages. If $L_1 \\cap L_2 \\ne \\emptyset$ then $L_1 \\cup L_2$ is ambiguous (the intersection has 2 derivations). Remedy: provide disjointed set of rules: $L_1 \\cap L_2$, $L_1 \\setminus L_2$ and $L_2 \\setminus L_1$.\n\n\\paragraph{Concatenation of Languages} if a suffix of a sentence of language one is also a prefix of a sentence of language two $G_1 . G_2$ is ambiguous if $\\exists x_1 \\in L_1, x_2 \\in L_2$ such that $x_1 = uv$ with $u \\in L_1$ and $x_2 = vz$ with $z \\in L_2$: $uvz$ can be $(uv)z$ or $u(vz)$.\n\n\\paragraph{Inherent Ambiguity} A language is inherently ambiguous if all its grammar are ambiguous, e.g. those where the intersection is not CF.\n\n\\paragraph{Lack of Order in Derivations} add a nonterminal to impose that one rule must follw the other $S \\rarr bSc | bbSc | \\epsilon$ becomes $S \\rarr bSc | D$, $D \\rarr bbDc | \\epsilon$.\n", "meta": {"hexsha": "154dbf43792d1cef5a565c02ad3b458c9a89f8bf", "size": 1739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grammars/ambiguity.tex", "max_stars_repo_name": "TiberioG/FLC-cheatsheet", "max_stars_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "grammars/ambiguity.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": "grammars/ambiguity.tex", "max_forks_repo_name": "TiberioG/FLC-cheatsheet", "max_forks_repo_head_hexsha": "d86e8ba9c80fece75ffccf47c273334b677f4934", "max_forks_repo_licenses": ["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.95, "max_line_length": 294, "alphanum_fraction": 0.7395054629, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6368766729304891}}
{"text": "\n\\documentclass[a4paper,12pt]{article}\n\\usepackage{graphicx}\n%\\usepackage{stix}\n\\usepackage{amsmath}\n\\newcommand\\addtag{\\refstepcounter{equation}\\tag{\\theequation}}\n\\begin{document}\n\n\\title{Diagnosed Particle Disaggregation}\n\\author{Jacob A. Cram}\n\\maketitle\n\n\\section{Definitions and Units}\n\n\\begin{equation}\n  m = C_m r^\\alpha %\\addtag\n  \\label{eqn:m}\n\\end{equation}\n\nAs in DeVries et al. [2014] particle mass m is a function of radius r and scales with a fractal dimension $\\alpha$. $C_m$ is a constant.\n\n\\begin{equation}\n  w = C_wr^\\gamma %\\addtag\n  \\label{eqn:w}\n\\end{equation}\n\nSinking speed also scales with mass to another constant $\\gamma$. \nAccording to Guidi et al. [2008] $\\gamma = \\alpha - 1$, but we'll keep things in terms of $\\gamma$ going forward.\n\n\\begin{equation}\n  F = nmw = n C_m C_w r^{\\alpha + \\gamma}\n\\end{equation}\n\nFlux F is a function of particle numbers, mass, and sinking speed.\n\n\n%\\includegraphics{ijFig2.png}\n\n\\begin{figure}[h]\n  \\includegraphics{ijFig2.png}\n  %\\includegraphics[natwidth=0.35\\textwidth]{ijFig2.png}\n  \n  \\centering\n  \\caption{Some number of particles $\\Delta n_j$ of size ``j'' remineralize to size ``j-1'' as they sink from depth ``i-1'' to depth ``i''.}\n  \\label{fig:boxes}\n\\end{figure}\n\nGoing forward we will determine the calculations for how many particles of size j in shallow depth i-1 remineralize into smaller particles of size j-1 in deeper depth i. We will call this term $\\Delta n_j$\n\n\\section{Conservation of particle number flux}\n\nIn the absence of disaggregation, the number of particles leaving a box of water is equal to the number of particles going into that box from above. In other words, particle \"number-flux\" is conserved. Thus the number of particles in the box is a function of the number of particles going into that box, and the difference in velocities between when the particle enters and when that particle leaves.\n\n\\begin{equation}\nn_{i-1, j-1}  {{w_{j-1}}\\over{w_j}} + n_{i-1,j} = n_{i,j-1} {{w_{j-1}}\\over{w_j}} + n_{i,j}\n\\label{eqn:nfcons}\n\\end{equation}\n\nWhere $n_{i-1,j}$ is the number of particles of size j (the bigger size) at depth i-1 (the shallower depth). The subscripts correspond to locations in Figure \\ref{fig:boxes}.\n\nWe can re-arrange equation \\ref{eqn:nfcons}\n\n\\begin{equation}\nn_{i-1, j-1} w_{j-1} + n_{i-1,j} w_j = n_{i,j-1} w_{j-1} + n_{i,j} w_j\n\\label{eqn:renfcons}\n\\end{equation}\n\n\nSubstitue in equation \\ref{eqn:w} into equation \\ref{eqn:renfcons}.\n\n\\begin{equation}\nn_{i-1, j-1} r^\\gamma_{j-1} + n_{i-1,j} r^\\gamma_j = n_{i,j-1} r^\\gamma_{j-1} + n_{i,j} r^\\gamma_j\n\\label{eqn:nra}\n\\end{equation}\n\nRearrange equation \\ref{eqn:nra}\n\\begin{equation}\nr^\\gamma_{j-1} (n_{i-1, j-1} - n_{i, j-1} ) = r^\\gamma_{j} (n_{i, j} - n_{i-1, j} ) = \\Phi\n\\label{eqn:phi}\n\\end{equation}\n\nWhere $\\Phi$ is a placeholder standing for either side of equation \\ref{eqn:phi}, which I will subsequently substitute into things.\n\n\\medskip\n\nSolve for $\\Delta n_j$\n \\begin{equation}\n\\Delta n_j = n_{i, j} - n_{i-1, j} = {{r^\\gamma_{j-1}}\\over{r^\\gamma_{j}}} (n_{i-1,j-1}-n_{i,j-1})\n \\end{equation}\n\n\\section{Conservation of Mass Flux}\n\nTotal flux defined is the sum of flux in each (observed) particle size bin. Particles not in an observed bin don't count towards total flux.\n\n\\begin{equation}\n\\Delta F = \\sum_{j = 2}^n \\Delta f_j + \\Delta f_1\n\\label{eqn:df}\n\\end{equation}\n\nHere $\\Delta f_j$ is the flux attenuation from bin of size j and $\\Delta f_1$ is the loss that comes from particles in bin 1 becoming small enough that you can no longer see them with the UVP.\n\nThe flux attenuation in a bin is the product of the rate of flux attenuation with depth of each individual particle ${\\partial f} \\over {\\partial z}$, the depth interval over which the particles attenuate $\\Delta z$ and the number of particles in that bin at the top of the depth interval $n_{i-1,j}$\n\n\\begin{equation}\n\\Delta f_j = {{\\partial f} \\over {\\partial z}} \\Delta z n_{i-1,j}\n\\label{eqn:dfj}\n\\end{equation}\n\nFurthermore, the rate of flux attenuation with respect to depth is the product of the rate of mass attenuation with respect to time ${{\\partial m} \\over {\\partial t}}$ , the inverse of the sinking speed ${{\\partial t} \\over {\\partial z}}$ , and the deriviative of the flux to mass relationship ${{\\partial f} \\over {\\partial m}}$.\n\n\\begin{equation}\n{{\\partial f} \\over {\\partial z}} = \n{{\\partial m} \\over {\\partial z}} {{\\partial f} \\over {\\partial m}} = \n{{\\partial m} \\over {\\partial t}} \n{{\\partial t} \\over {\\partial z}} \n{{\\partial f} \\over {\\partial m}}\n\\label{eqn:dfdz}\n\\end{equation}\n\nIn PRiSM, fractional mass loss as a function of time is the same for all particles of all sizes.\n\n\\medskip\n\nNow we are going to come up with the values for each of these terms.\n\n\\medskip\n\nThe particle remineralization rate $C_r$ is the same for particles of all sizes.\n\n\\begin{equation}\n{{\\partial m} \\over {\\partial t}} = C_r * m = C_r  C_m r^\\alpha\n\\label{eqn:dmdt}\n\\end{equation}\n\nSinking speed definition, substituting from equation \\ref{eqn:w}\n\\begin{equation}\n{{\\partial t} \\over {\\partial z}} = {1 \\over w} = {1 \\over C_w r^\\gamma}\n\\label{eqn:dtdz}\n\\end{equation}\n\nFlux for a given size class, substituting eqation \\ref{eqn:m}, and finally putting everything in terms of mass (rather than mass and radius, since the two are related)\n\\begin{equation}\nf = m w = m * C_w r^\\gamma = m * C_w ({m\\over C_m})^{\\gamma \\over \\alpha}\n\\label{eqn:f}\n\\end{equation}\n\nDerriving equation \\ref{eqn:f} with respect to mass, and substituting equation \\ref{eqn:m}\n\\begin{equation}\n{{\\partial f} \\over {\\partial m}} = \nCw(1+{\\gamma \\over \\alpha}) ({m \\over C_m}) ^ {\\gamma \\over \\alpha}=\nC_w(1+{\\gamma \\over \\alpha}) r ^ \\gamma\n\\label{eqn:dfdm}\n\\end{equation}\n\nFinally, we can construct our equation for flux attenuation by substituting equations \\ref{eqn:dmdt}, \\ref{eqn:dtdz} and \\ref{eqn:dfdm} into equation \\ref{eqn:dfdz}\n\n\\begin{equation}\n{{\\partial f} \\over {\\partial z}} = C_r C_m r^\\alpha(1+{\\gamma \\over \\alpha})\n\\end{equation}\n\n\nAnd now we can solve for equation \\ref{eqn:dfj}.\n\n\\begin{equation}\n\\Delta f_j = C_r C_m r^\\alpha (1+{\\gamma \\over \\alpha}) \\Delta z * n_{i-1,j}\n\\label{eqn:dfj}\n\\end{equation}\n\nWe also need to solve for $\\Delta f_1$ the flux ``attenuation'' that actually comes from particles leaving the smallest bin and escaping from what the UVP sees.\n\n\\begin{equation}\n\\Delta f_1 = \\Delta n_1 m_1 w_1 =  \\Delta n_1 C_m C_w r_1^{\\alpha + \\gamma}\n\\label{eqn:df0}\n\\end{equation}\n\nHere, $\\Delta n_1$ is the number of particles leaving bin j = 1, but we haven't solved for that yet.\n\n\\section{Solving for $\\Delta n_j$}\n\nRecall that $\\Delta n_j$ is the number of particles that migrate between bin ``j'' and bin ``j-1'' as the particles sink from depth ``i-1'' to depth ``i''.\n\nThe flux at the shallower depth is equal to the flux at the deeper depth, plus the flux that attenuated between those two depths. Since $f = nmw$ and we know m and w\n\n\\begin{equation}\nn_{i-1,j-1} C_m C_w r_{j-1}^{\\alpha + \\gamma} + n_{i-1,j} C_m C_w r_{j}^{\\alpha + \\gamma} =\nn_{i,j-1} C_m C_w r_{j-1}^{\\alpha + \\gamma} + n_{i,j} C_m C_w r_{j}^{\\alpha + \\gamma} + \\Delta f_j\n\\label{eqn:n4f}\n\\end{equation}\n\nThis equation can be re-arranged, and we can substitute in equation \\ref{eqn:dfj} for $\\Delta f_j$. \n \n% \\begin{equation}\n% C_m C_w r_{j-1} ^{\\alpha + \\gamma} (n_{i-1,j-1}- n_{i,j-1}) = \n% C_m C_w r_{j}^{\\alpha + \\gamma} (n_{i,j} - n_{i-1,j}) +  C_r C_m (1 + {\\gamma \\over \\alpha}) \\Delta z n_{i-1,j} r ^ \\alpha\n% \\end{equation}\n\nThe $C_m$ cancel out.\n\n\\begin{equation}\n C_w r_{j-1} ^{\\alpha + \\gamma} (n_{i-1,j-1}- n_{i,j-1}) = \n C_w r_{j}^{\\alpha + \\gamma} (n_{i,j} - n_{i-1,j}) +  C_r  (1 + {\\gamma \\over \\alpha}) \\Delta z n_{i-1,j} r ^ \\alpha\n\\end{equation}\n\nWe can then substitute in $\\Phi$ from equation \\ref{eqn:phi}.\n\\begin{equation}\nC_w r_{j-1} ^{\\alpha} \\Phi = \n C_w r_{j}^{\\alpha} \\Phi +  C_r  (1 + {\\gamma \\over \\alpha}) \\Delta z n_{i-1,j} r ^ \\alpha\n\\end{equation}\n\n\nRearrange\n% C_w \\Phi %(r_{j-1}^\\alpha - r_j^\\alpha)\n\n\\begin{equation}\nC_w\\Phi(r_{j-1}^\\alpha - r_j^\\alpha) = Cr(1 + {\\gamma \\over \\alpha}) \\Delta z r^{\\alpha} n_{i-1,j}\n\\end{equation}\n\nsolve for $\\Phi$\n\n\\begin{equation}\n\\Phi = {{{C_r \\over C_w} \\Delta z r^{\\alpha} n_{i-1,j}(1 + {\\gamma \\over \\alpha})} \\over {r_{j-1}^\\alpha - r_j^\\alpha}}\n\\end{equation}\n\n\\begin{equation}\n\\Delta n_j = {\\Phi \\over r_j^\\gamma} = {{{C_r \\over C_w} \\Delta z r^{\\alpha} n_{i-1,j}(1 + {\\gamma \\over \\alpha})} \\over {r_j^\\gamma(r_{j-1}^\\alpha - r_j^\\alpha})}\n\\label{eqn:dnj}\n\\end{equation}\n\n\\begin{equation}\n\\Delta n_{j-1} = {\\Phi \\over r_{j-1}^\\gamma} = {{\\Delta n_j r_j^\\gamma} \\over {r_{j-1}^\\gamma}}\n\\end{equation}\n\nAt this point, the only unsolved variable is $C_r$, which we can now calculate.\n\n\n\\section{Solving for $C_r$}\n\nWe can calculate $\\Delta F $, the attenuation of flux and can impose the size spectrum and all of the other constants. Here we find the $C_r$ that gives us the correct $\\Delta F $\n\nFirst, to solve equation \\ref{eqn:df} by substituting in equaitons \\ref{eqn:dfj} and \\ref{eqn:df0}\n\n\\begin{equation}\n\\Delta F = \\sum_{j = 2}^n \\Delta f_j + \\Delta f_1 = \n\\sum_{j = 2}^n \\left\\{C_r C_m r_j^\\alpha(1+{\\gamma \\over \\alpha}) \\Delta z n_{i-1,j} \\right\\} +\n\\Delta n_1 C_m C_w r_1^{\\alpha + \\gamma}\n\\end{equation}\n\nSubstitute equation \\ref{eqn:dnj} for $\\Delta n_j$ when j = 1 for $\\Delta n_1$\n\n\\begin{equation}\n\\Delta F = \\sum_{j = 2}^n \\Delta f_j + \\Delta f_1 = \n\\sum_{j = 2}^n \\left\\{C_r C_m r_j^\\alpha(1+{\\gamma \\over \\alpha}) \\Delta z n_{i-1,j} \\right\\} +\n {{{C_r \\over C_w} \\Delta z r_1^{\\alpha} n_{i-1,1}(1 + {\\gamma \\over \\alpha})} \\over {r_1^{\\gamma}(r_{0}^\\alpha - r_1^\\alpha})}\nC_m C_w r_1^{\\alpha + \\gamma}\n\\end{equation}\n\nIn the above, $r_0$ is the effective size of the particles smaller than the UVP can see. In principle this is arbitrary. Numbers closer to zero result in fewer particles in the smallest bin disapearing, larger ones to more of those particles disapearing. As $r_0$ approaches $r_1$ Cr approaches zero. They cannot be equal or the math breaks.\n\nPull what I can out of the sum operation, and cancel out $r^{\\gamma}$ and $C_w$ from the rightmost term\n\\begin{equation}\n\\Delta F =\nC_r C_m \\Delta z (1 + {\\gamma \\over \\alpha}) \\sum_{j = 2}^n \\left\\{r_j^\\alpha n_{i-1,j} \\right\\}\n+\n {{{C_r} \\Delta z r_1^{2 \\alpha} n_{i-1,1}(1 + {\\gamma \\over \\alpha})} \\over {(r_{0}^\\alpha - r_1^\\alpha})}\nC_m \n\\end{equation}\n\nNow we can solve for $C_r$\n\n\\begin{equation}\nC_r = {\n\\Delta F \\over \nC_m \\Delta z \n(1 + {\\gamma \\over \\alpha}) \\big[ \\sum_{j = 2}^n  \\big\\{\nr_j^\\alpha n_{i-1,j}\n\\big\\} +\n{{r_1^{2\\alpha}n_{i-1,1}}\\over{r_0^\\alpha - r_1^\\alpha}}\n\\big]\n}\n\\end{equation}\n\nThus for a pair of profiles, we can estemate the flux attenuation, calculate Cr from that, and then plug Cr (and the profile) into the equation \\ref{eqn:dnj} for $\\Delta n_j$. We can thus compute $\\Delta n_j$ for each size class to see how many particles from that bin move to the next bin smaller.\n\n\n\n \\end{document}\n\n\n", "meta": {"hexsha": "c99b3f33ef5ae5e36f62ff70255dd0babca59829", "size": 10936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EularianPRiSM_Math/DeltaNjMathV2020.tex", "max_stars_repo_name": "cramjaco/POMZ-ETNP-UVP-2017", "max_stars_repo_head_hexsha": "a942b0a5ba082c025869c70fd6b30609b460567e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EularianPRiSM_Math/DeltaNjMathV2020.tex", "max_issues_repo_name": "cramjaco/POMZ-ETNP-UVP-2017", "max_issues_repo_head_hexsha": "a942b0a5ba082c025869c70fd6b30609b460567e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EularianPRiSM_Math/DeltaNjMathV2020.tex", "max_forks_repo_name": "cramjaco/POMZ-ETNP-UVP-2017", "max_forks_repo_head_hexsha": "a942b0a5ba082c025869c70fd6b30609b460567e", "max_forks_repo_licenses": ["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.8408304498, "max_line_length": 400, "alphanum_fraction": 0.6823335772, "num_tokens": 3834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6368540477000008}}
{"text": "\\section{Temporal-Difference Learning}\n\n\\subsection{Exercise 6.1}\n\\subsubsection*{Q}\nIf $V$ changes during the episode, then (6.6) only holds approximately; what would the difference be between the two sides? Let $V_t$ denote the array of state values used at time $t$ in the TD error (6.5) and in the TD update (6.2). Redo the derivation above to determine the additional amount that must be added to the sum of TD errors in order to equal the Monte Carlo error.\n\\subsubsection*{A}\nWrite\n\\[\n    \\delta_t \\doteq R_{t+1} + \\gamma V_t(S_{t+1}) - V_t(S_t),\n\\]\nthen\n\\begin{align}\n    G_t - V_t(S_t) &= R_{t+1} + \\gamma G_{t+1} - V_t(S_t) \\\\\n                   &= \\delta_t + \\gamma [ G_{t+1} - V_{t+1}(S_{t+1})] + \\gamma [V_{t+1}(S_{t+1}) - V_t(S_{t+1})]\\\\\n                   &= \\delta_t + \\gamma [ G_{t+1} - V_{t+1}(S_{t+1})] + \\alpha \\gamma [R_{t+2} + \\gamma V_t(S_{t+2}) - V_t(S_{t+1})]\\\\\n                   &\\vdotswithin{=} \\notag\\\\\n                   &= \\sum_{k=t}^{T-1} \\gamma^{k-t} \\delta_k + \\alpha \\sum_{k=t}^{T-2} \\gamma^{k-t+1} [R_{k+2} + \\gamma V_k(S_{k+2}) - V_k(S_{k+1})].\n\\end{align}\n                   \n\\subsection{Exercise 6.2}\n\\subsubsection*{Q}\nThis is an exercise to help develop your intuition about why TD methods are often more efficient than Monte Carlo methods. Consider the driving home example and how it is addressed by TD and Monte Carlo methods. Can you imagine a scenario in which a TD update would be better on average than a Monte Carlo update? Give an example scenario—a description of past experience and a current state—in which you would expect the TD update to be better. Here’s a hint: Suppose you have lots of experience driving home from work. Then you move to a new building and a new parking lot (but you still enter the highway at the same place). Now you are starting to learn predictions for the new building. Can you see why TD updates are likely to be much better, at least initially, in this case? Might the same sort of thing happen in the original task?\n\\subsubsection*{A}\nTD updates incorporate prior information. Suppose we had a good value estimate for a trajectory $\\tau = S_1, S_2, \\dots, S_T$, then if we try to estimate the trajectory $\\tau = S_0, S_1, S_2, \\dots, S_T$ using MC then we need to see multiple episodes of this to get a good estimate of $V(S_0)$, not leveraging the info we already have on $\\tau$. TD would use info on $\\tau$ to back up the value of $S_0$ and hence converge much quicker. The key differences here are bootstrapping and online learning.\n\n\\subsection{Exercise 6.3}\n\\subsubsection*{Q}\nFrom the results shown in the left graph of the random walk example it appears that the first episode results in a change in only $V(A)$. What does this tell you about what happened on the first episode? Why was only the estimate for this one state changed? By exactly how much was it changed?\n\n\\subsubsection*{A}\nAll states apart from the terminal states were initialised to the same value (the terminal states must be initialised to 0) and the reward for non-terminal transitions is 0, so the TD(0) updates do nothing on the first pass to states that cannot lead directly to termination. \\\\\n\nIn the first run, the agent terminated on the left.\n\\begin{align}\n    V_1(A) &= V_0(A) + \\alpha[ 0 + \\gamma \\times 0 + V_0(A)]\\\\\n           &= (1-\\alpha) V_0(A) \\\\\n           &= 0.9 \\times 0.5 \\\\\n           &= \\frac{9}{20}.\n\\end{align}    \nThe value of the estimate for $A$ reduced by $\\alpha V_0(A) = 0.05$.\n\n\\subsection{Exercise 6.4}\n\\subsubsection*{Q}\nThe specific results shown in the right graph of the random walk example are dependent on the value of the step-size parameter, $\\alpha$. Do you think the conclusions about which algorithm is better would be affected if a wider range of $\\alpha$ values were used? Is there a different, fixed value of $\\alpha$ at which either algorithm would have performed significantly better than shown? Why or why not?\n\\subsubsection*{A}\n\n\\begin{itemize}\n    \\item General arguments given earlier about the benefits of TD are independent of $\\alpha$\n    \\item Increases in $\\alpha$ make the curve more \n    \\item Decreases in $\\alpha$ make the curve more smooth but make it converge slower.\n    \\item We see enough of a range here to decide between the two methods\n\\end{itemize}\n\n\\subsection{*Exercise 6.5}\n\\subsubsection*{Q}\nIn the right graph of the random walk example, the RMS error of the TD method seems to go down and then up again, particularly at high $\\alpha$s. What could have caused this? Do you think this always occurs, or might it be a function of how the approximate value function was initialized?\n\\subsubsection*{A}\nThe state C happens to have een initialised to its true value. As training starts, updates occur on outer states (making them more accurate individually) which makes the error across all states reduce. This happens until the residual inaccuracies in the outer states propagate to C. The higher values of $\\alpha$ make this effect more pronounced, because the value estimate for C changes more readily in these cases.\n\n\\subsection{Exercise 6.6}\n\\subsubsection*{Q}\nIn Example 6.2 we stated that the true values for the random walk example are $\\frac16$, $\\frac26$, $\\frac36$, $\\frac46$, and $\\frac56$ for states A through E. Describe at least two different ways that these could have been computed. Which would you guess we actually used? Why?\n\\subsubsection*{A}\nCould have used DP, but probably did the following calculation.\\\\\n\nFirst note that\n\\[\n    V(s) = \\E{}[\\mathds{1}\\{\\textsf{terminate on right from } S\\}] = \\P{}(\\textsf{terminate on right from } S).\n\\]\nAlso recognise that symmetry now implies $V(C) = 0.5$. Now\n\\begin{align*}\n    V(E) &= \\frac12 \\times 1 + \\frac12 \\times V(D) \\\\\n         &= \\frac12 + \\frac14[V(C) + V(E)],\n\\end{align*}\nso $V(E) = \\frac56$. We then get $V(D) = \\frac46$ and we can calculate the other states in the same way.\n\n\\subsection{*Exercise 6.7}\n\\subsubsection*{Q}\nDesign an off-policy version of the $TD(0)$ update that can be used with arbitrary target policy $\\pi$ and covering behavior policy $b$, using at each step $t$ the importance sampling ratio $\\rho_{t:t}$(5.3).\n\\subsubsection*{A}\nLet $G_t$ be returns from an episode generated by $b$. Then\n\\begin{align*}\n    v_\\pi(s) &= \\E{}[\\rho_{t:T-1}G_t | S_t=s]\\\\\n             &= \\E{}[\\rho_{t:T-1} R_{t+1} + \\gamma \\rho_{t:T-1}G_{t+1} | S_t=s] \\\\\n             &= \\rho_{t:t} \\E{}[R_{t+1}|S_t=s] + \\gamma \\rho_{t:t}\\E{}[\\rho_{t+1:T-1}G_{t+1} |S_t=s] \\\\\n             &= \\rho_{t:t} \\left( \\E{}[R_{t+1} | S_t=s] + \\E{}[\\rho_{t+1:T-1}G_t| S_t = s] \\right)\\\\\n             &= \\rho_{t:t} \\left( r(s, A_t) + v_\\pi(S_{t+1})\\right).\n\\end{align*}\nSo the update for off-policy TD(0) (by sampling approximation) is \n\\begin{equation}\n    V(S_t) \\leftarrow V(S_t) + \\alpha \\left[ \\rho_{t:t} R_{t+1} + \\rho_{t:t} \\gamma V(S_{t+1}) - V(S_t) \\right].\n\\end{equation}\n\n\\subsection{Exercise 6.8}\n\\subsubsection*{Q}\nShow that an action-value version of (6.6) holds for the action-value form of the TD error $\\delta_t = R_{t+1} + \\gamma Q(S_{t+1}, A_{t+1}) - Q(S_t, A_t)$, again assuming that the values don’t change from step to step.\n\\subsubsection*{A}\nWrite $\\delta_t \\doteq R_{t+1} + \\gamma Q(S_{t+1}, A_{t+1}) -  Q(S_t, A_t)$. Then the Monte-Carlo error is\n\\begin{align*}\n    G_t - Q(S_t, A_t) &= R_{t+1} + \\gamma G_{t+1} - Q(S_t, A_t) \\\\\n                      &= \\delta_t - \\gamma [Q(S_{t+1}, A_{t+1}) + G_{t+1}]\\\\\n                      &= \\sum_{k=t}^{T-1}\\gamma^{k-t}\\delta_k\n\\end{align*}\n\n\\subsection{Exercise 6.9 (programming): Windy Grid World with King's Moves}\n\\subsubsection*{Q}\nRe-solve the windy gridworld assuming eight possible actions, including the diagonal moves, rather than the usual four. How much better can you do with the extra actions? Can you do even better by including a ninth action that causes no movement at all other than that caused by the wind?\n\n\\subsubsection*{A}\n\\ProgrammingExercise\\\\\n\nOptimal trajectory is now 7 steps, rather than 15. Including the do-nothing action is not helpful in this example because the wind blows vertically and the goal position is not vertically separated from the start position. It could be useful in other wind environments though.\\\\\n\nBelow are the optimal trajectories for the book example (no diagonal moves) and for the exercise (king's moves). The numbers represent the wind strength in that position.\\\\\n\n\\includegraphics[width=\\textwidth]{\\ExerciseOutput/ex_6_9/optimal_no_diagonal_moves.png}\n\n\\includegraphics[width=\\textwidth]{\\ExerciseOutput/ex_6_9/optimal_with_diagonal_moves.png}\n\n\n\n\\subsection{Exercise 6.10 (programming): Stochastic Wind}\n\\subsubsection*{Q}\nRe-solve the windy gridworld task with King’s moves, assuming that the effect of the wind, if there is any, is stochastic, sometimes varying by 1 from the mean values given for each column. That is, a third of the time you move exactly according to these values, as in the previous exercise, but also a third of the time you move one cell above that, and another third of the time you move one cell below that. For example, if you are one cell to the right of the goal and you move left, then one-third of the time you move one cell above the goal, one-third of the time you move two cells above the goal, and one-third of the time you move to the goal.\n\n\\subsubsection*{A}\n\\ProgrammingExercise\\\\\n\nGreedy trajectory and learning curve shown below. Note that although the gradient of the learning curve becomes constant (so the algorithm converges), the greedy episode shown suffers from stochasticity in the wind.\n\n\\includegraphics[width=\\textwidth]{\\ExerciseOutput/ex_6_10/optimal.png}\n\n\\includegraphics[width=\\textwidth]{\\ExerciseOutput/ex_6_10/learning_curve.eps}\n\n\\subsection{Exercise 6.11}\n\\subsubsection*{Q}\nWhy is Q-learning considered an \\emph{off-policy} control method?\n\n\\subsubsection*{A}\nThe returns are sampled as if the agent followed the greedy policy with respect to $Q$.\n\n\\subsection{Exercise 6.12}\n\\subsubsection*{Q}\nSuppose action selection is greedy. Is Q-learning then exactly the same algorithm as Sarsa? Will they make exactly the same action selections and weight updates?\n\\subsubsection*{A}\nYes (?)\n\n\\subsection{Exercise 6.13}\n\\subsubsection*{Q}\nWhat are the update equations for Double Expected Sarsa with an $\\varepsilon$-greedy target policy?\n\\subsubsection*{A}\nExpected SARSA has the update \n\\[\n    Q(S_t, A_t) \\leftarrow Q(S_t, A_t) + \\alpha \\left[ R_{t+1} + \\gamma \\E{}[Q(S_{t+1}) | S_{t+1}] - Q(S_t, A_t)\\right]\n\\]\n\nThe update for $S_t, A_t$ is \n\\[\n    R_{t+1} + \\gamma \\sum_a \\pi(a|S_{t+1}) Q(S_{t+1}, a) - Q(S_t, A_t).\n\\]\nDouble expected SARSA would be keeping two $Q$ arrays and updating one of them each timestep, chosen with equal probability.\\\\\n\nFor an $\\varepsilon$-greedy policy we would increment $Q_1(S_t, A_t)$ by\n\\begin{equation}\n    \\alpha \\left[ R_{t+1} + \\gamma \\left( \\frac{\\varepsilon}{|\\mathcal{A}(a)|} \\sum_a Q_2(S_{t+1}, a) + (1-\\varepsilon)\\max_a\\{Q_2(S_{t+1}, a)\\} \\right) - Q_1(S_t, A_t)  \\right]\n\\end{equation}\nand the same with 1 and 2 reversed.\n\n\n\\subsection{Exercise 6.14}\n\\subsubsection*{Q}\nDescribe how the task of Jack’s Car Rental (Example 4.2) could be reformulated in terms of afterstates. Why, in terms of this specific task, would such a reformulation be likely to speed convergence?\n\n\\subsubsection*{A}\nOne might have coded this up initially with the states as the number of cars in each garage each evening. The agent then takes some action (moves some cars) and we transition stochastically to some state.\\\\\n\nAn alternative would be to introduce the number of cars in the morning (after the agent has moved cars) as an afterstate. This is because the agent is able to deterministically change the environment from evening to next morning (before rentals or returns).\\\\\n\nIn this case we would speed convergence by reducing the number of action-values to be calculated. For instance, we can now evaluate $(10, 0)$ moving one car and $(9, 1)$ moving no cars as the same afterstate $(9, 1)$.\n\n", "meta": {"hexsha": "0f63b67c4c9a2aaaaa05f0c5193b35d9a5a72cb7", "size": 11996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/chapters/chapter6/chapter6_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/chapter6/chapter6_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/chapter6/chapter6_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": 66.2762430939, "max_line_length": 840, "alphanum_fraction": 0.7131543848, "num_tokens": 3417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.636854037455907}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrmh}\n\\section*{\\hspace*{-1.6cm} tfrmh}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nMargenau-Hill time-frequency distribution.\n\\end{minipage}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrmh(x)\n[tfr,t,f] = tfrmh(x,t)\n[tfr,t,f] = tfrmh(x,t,N)\n[tfr,t,f] = tfrmh(x,t,N,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrmh} computes the Margenau-Hill distribution of a\n        discrete-time signal {\\ty x}, or the cross Margenau-Hill\n        representation between two signals. This distribution has the\n        following expression :\n\\begin{eqnarray*}\nMH_x(t,\\nu)&=&\\Re\\left\\{x(t)\\ X^*(\\nu)\\ e^{-j2\\pi \\nu t}\\right\\}\\\\\n&=&\\int_{-\\infty}^{+\\infty} \\frac{1}{2}\\ (x(t+\\tau)\\ x^*(t)+x(t)\\\nx^*(t-\\tau))\\ e^{-j2\\pi \\nu \\tau}\\ d\\tau.\n\\end{eqnarray*}\nIt corresponds to the real part of the Rihaczek distribution (see {\\ty\ntfrri}).\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{10cm} c}\nName & Description & Default\\\\\n\\hline\n        {\\ty x}     & signal if auto-MH, or {\\ty [x1,x2]} if cross-MH. {\\ty\n\t\t\t(Nx=length(x))}\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation\\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.1cm}\n\nWhen called without output arguments, {\\ty tfrmh} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4); tfrmh(sig,1:128,128,1);\n\\end{verbatim}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] H. Margenhau, R. Hill ``Correlation between Measurements in Quantum\nTheory'', Prog. Theor. Phys. Vol. 26, pp. 722-738, 1961.\n\\end{minipage}", "meta": {"hexsha": "971e741c86ee273e25464c15de3a68e2b56f5ca3", "size": 2446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrmh.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrmh.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrmh.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 28.7764705882, "max_line_length": 75, "alphanum_fraction": 0.6161079313, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6368540323937036}}
{"text": "\\subsection{Partial Fractions}\r\n\r\nIf we have a function that is the quotient 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 polynomial degree than the denominator.\r\n\r\n\\input{./backgroundReview/algebraPreCalc/partialFractions_example.tex}\r\n\r\n\r\nOne natural way to find these small denominators comes from the linear factors of the denominator where we keep complex roots in quadratic form.\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{./backgroundReview/algebraPreCalc/linearFactors.tex}\r\n\\input{./backgroundReview/algebraPreCalc/repeatedLinearFactors.tex}\r\n\\input{./backgroundReview/algebraPreCalc/quadraticFactors.tex}\r\n\\input{./backgroundReview/algebraPreCalc/repeatedQuadraticFactors.tex}\r\n\\input{./backgroundReview/algebraPreCalc/improperFractions.tex}\r\n", "meta": {"hexsha": "d9c4a6556055b9fe37710343b5b2dadc2f2e2d4a", "size": 1027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/backgroundReview/algebraPreCalc/partialFractions.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/partialFractions.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/partialFractions.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.4117647059, "max_line_length": 283, "alphanum_fraction": 0.8033106134, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6368540281153573}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrrgab}\n\\section*{\\hspace*{-1.6cm} tfrrgab}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nReassigned Gabor spectrogram time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,rtfr,hat] = tfrrgab(x) \n[tfr,rtfr,hat] = tfrrgab(x,t) \n[tfr,rtfr,hat] = tfrrgab(x,t,N) \n[tfr,rtfr,hat] = tfrrgab(x,t,N,Nh) \n[tfr,rtfr,hat] = tfrrgab(x,t,N,Nh,trace) \n[tfr,rtfr,hat] = tfrrgab(x,t,N,Nh,trace,k) \n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrrgab} computes the Gabor spectrogram and its reassigned\n        version.  The analysis window $h$ used in this spectrogram is a\n        gaussian window, which allows a 20 \\% faster algorithm than with\n        the {\\ty tfrrsp} function (windows $\\ens{T}_h$ and $\\ens{D}_h$\n        defined above are colinear in this case). The reassigned Gabor\n        spectrogram is given by the following expressions :\n\\begin{eqnarray*}\n S_x^{(r)}(t',\\nu';h)=\\iint_{-\\infty}^{+\\infty} S_x(t,\\nu;h)\\\n\\delta(t'-\\hat{t}(x;t,\\nu))\\ \\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\ dt\\ d\\nu,\n\\end{eqnarray*}\nwhere \n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu)=t-\\Re\\left\\{\\dfrac{F_x(t,\\nu;\\ens{T}_h)\\ F_x^*(t,\\nu;h)}\n{|F_x(t,\\nu;h)|^2}\\right\\} \\\\\n\\hat{\\nu}(x;t,\\nu)=\\nu+\\Im\\left\\{\\dfrac{F_x(t,\\nu;\\ens{D}_h)\\ F_x^*(t,\\nu;h)}\n{2\\pi\\ |F_x(t,\\nu;h)|^2}\\right\\}    \n\\end{eqnarray*}\nwith $\\ens{T}_h(t)=t\\ h(t)$ and $\\ens{D}_h(t)=\\frac{dh}{dt}(t)$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)})\\\\\n        {\\ty t}     & the time instant(s)           & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins      & {\\ty Nx}\\\\\n        {\\ty Nh}    & length of the gaussian window & {\\ty N/4}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                              & {\\ty 0}\\\\\n        {\\ty k}     & value at both extremities     & {\\ty 0.001}\\\\\n\n\\hline \\end{tabular*} \\end{minipage}\n\n%\\newpage\n\n\\hspace*{1.5cm} \\begin{minipage}[t]{13.5cm} \n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty tfr, rtfr} & time-frequency representation and its reassigned\n              version\\\\\n        {\\ty hat}   & complex matrix of the reassignment vectors\\\\\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrrgab} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4); \n         tfrrgab(sig,1:128,128,19,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and\nTime-Scale Representations by the Reassignment Method'' IEEE Transactions\non Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.\n\\end{minipage}\n\n", "meta": {"hexsha": "39221a13bb7b0f08711a0ef4deb6e63b070192f7", "size": 3433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrrgab.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrrgab.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrrgab.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 31.495412844, "max_line_length": 77, "alphanum_fraction": 0.6163705214, "num_tokens": 1312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6367025448948395}}
{"text": "\\section{Photons}\nSuppose you have a metal box at temperature $T$.\nThere is an electromagnetic field inside in equilibrium with the walls.\nThe field vanishes at the walls though.\n\nWhy should anybody study this?\nBecause all bodies which absorb all radiation shining on them (black bodies)\nemit radiation the same way when heated and a metal cavity is the best or\neasiest way to study.\n\nThe energy emitted by A equals the energy absorbed by a black body B equals the\nenergy emitted by B.\nThis is true frequency by frequency,\nso $u(\\nu)$ which is the energy density per unit is universal for every black\nbody.\n\nWe will find $u(\\nu)$ by applying equilibrium statistical mechanics to the\nelectromagnetic field inside the box.\n\nIn order to have a Hamiltonian formalism,\nwe'll use the variables\n$\\vec{A}(\\vec{r}, t)$ instead of $\\vec{E}$ and $\\vec{B}$.\n\nDifferent $\\vec{A}$'s differing by a gauge transformation,\ngive the same $\\vec{E}$ and $\\vec{B}$ and describe the same physics.\nWe'll impose the condition\n\\begin{align}\n    \\vec{\\nabla}\\cdot{A} &= 0\\\\\n    \\phi &= 0\n\\end{align}\nto select one $\\vec{A}$ for every physically distinct field $\\vec{E},\\vec{B}$.\nRecalling that we can recover the electric and magnetic fields with\n\\begin{align}\n    \\vec{E} &= -\\frac{\\partial A}{c \\partial t} - \\vec{\\nabla}\\phi\n    =\n    -\\frac{1}{c}\\frac{\\partial \\vec{A}}{\\partial t}\\\\\n    \\vec{B} &= \\vec{\\nabla}\\times\\vec{A}\n\\end{align}\nThe Lagrangian\n\\begin{align}\n    L &=\n    \\frac{1}{8\\pi} \\int d^3 r\\,\n    \\left[ \n    \\left( \\frac{\\partial \\vec{A}}{c \\partial t} \\right)^2\n    - \\left( \\vec{\\nabla}\\times\\vec{A} \\right)^2\n    \\right]\n\\end{align}\nleads to the equation of motion\n\\begin{align}\n    \\frac{1}{c^2} \\frac{\\partial A}{\\partial t^2}\n    - \\nabla^2 \\vec{A} &= 0\n\\end{align}\nwhich is equivalent to Maxwell's equations.\nThe Hamiltonian is\n\\begin{align}\n    H &=\n    \\int d^3r\\left[\n    \\vec{\\Pi}\\cdot \\frac{\\partial \\vec{A}}{\\partial t} - H\n    \\right]\\\\\n    &=\n    \\int d^3r\\,\\left[\n    \\Pi^2 4\\pi c^2\n    - \\frac{(4\\pi c)^2}{8\\pi} \\Pi^2\n    + \\frac{\\vec{\\nabla}\\times\\vec{A}}{8\\pi}\n    \\right]\n\\end{align}\nwhere\n\\begin{align}\n    \\vec{\\Pi} &:=\n    \\frac{\\partial H}{\\partial \\dot{\\vec{A}}(\\vec{r})}\n    =\n    \\frac{1}{4\\pi} \\frac{1}{c^2} \\frac{\\partial \\vec{A}}{\\partial t}\\\\\n\\end{align}\nso then\n\\begin{align}\n    H\n    &=\n    \\frac{1}{8\\pi} \\int d^3r\\,\\left[ \n    \\underbrace{\\left( 4\\pi c \\right)^2 \\Pi^2}_{E^2}\n    +\n    \\underbrace{\\vec{\\nabla}\\times\\vec{A}}_{B^2}\n    \\right]\n\\end{align}\nApplying a change of variables to\n\\begin{align}\n    \\vec{A}(\\vec{r}, t) &=\n    \\frac{1}{\\sqrt{V}} \\sum_k\n    \\vec{Q}(\\vec{k}, t) e^{i\\vec{k}\\cdot \\vec{r}}\\\\\n    \\vec{\\Pi}(\\vec{r}, t) &=\n    \\frac{1}{\\sqrt{V}} \\sum_k\n    \\frac{\\vec{P}(\\vec{k}, t)}{\\sqrt{4\\pi} c^2} e^{i\\vec{k}\\cdot\\vec{r}}\n\\end{align}\nwhere $\\vec{k}=\\frac{2\\pi}{L}\\vec{n}$ with $\\vec{n}=0,\\pm 1,\\ldots$\nand\n\\begin{align}\n    \\vec{Q}_{\\vec{k}}^* &= \\vec{Q}_{-\\vec{k}}\\\\\n    \\vec{P}_{\\vec{k}}^* &= \\vec{P}_{-\\vec{k}}\n\\end{align}\nso then the Hamiltonian becomes decoupled as\n\\begin{align}\n    H &=\n    \\frac{1}{2}\\sum_{k}\\left[ \n    \\vec{P}_{\\vec{k}}\\cdot\\vec{P}_{-\\vec{k}}\n    +\n    \\underbrace{c^2 k^2}_{=:\\omega_k^2}\n    \\vec{Q}_{\\vec{k}}\\cdot\\vec{Q}_{-\\vec{k}}\n    \\right]\n\\end{align}\nwhich is very much like the phonon Hamiltonian.\nClassically,\nthe energy density is given by the equipartition theorem\n\\begin{align}\n    E &=\n    \\sum_{k} \\frac{1}{2} k_B\n    \\times \\underbrace{2}_{\\textrm{$P$ and $Q$ are quadratic}}\n    \\times \\underbrace{2}_{\\textrm{2 independent polarizations}}\\\\\n    &\\approx V \\int d^3 k 2k_B T\\\\\n    &\\to \\infty\n\\end{align}\nThe divergence comes because contrary to the phonon case,\nthere is not cutoff at high momentum $k$.\nStill,\nthe contribution from every frequency range\n\\begin{align}\n    \\frac{E}{V} &=\n    \\frac{2k_B T}{2\\pi^2} \\int_{0}^{\\infty} dk\\, k^2\\\\\n    &=\n    \\int_{0}^{\\infty}\n    \\underbrace{\\frac{k_B T}{\\pi^2} \\frac{(2\\pi)^3}{c^3} \\nu^2}_{u(\\nu)}\n    \\, d\\nu\n\\end{align}\nand with $\\nu = \\frac{kc}{2\\pi}$,\nthe energy density between $\\nu$ and $\\nu + d\\nu $ is\n\\begin{align}\n    u(\\nu) \\, d\\nu &=\n    \\frac{8k_B T \\pi}{c^3} \\nu^2\\, d\\nu\n\\end{align}\nthis is known as the \\emph{Rayleigh-Jeans law},\nwhich agrees with experiments in the low frequency regime.\nBut not for high frequencies as it diverges!\n\nThe quantum theory is obtained by making\n$\\vec{A}$, $\\vec{\\Pi}$, $\\vec{Q}$ and $\\vec{P}$\ninto operators.\n\nAssuming canonical commutation relations for $\\vec{A}$ and $\\vec{\\Pi}$.\n\\begin{align}\n    \\left[ \\hat{A}_i(\\vec{r}), \\hat{\\Pi}_j(\\vec{r}') \\right]\n    =\n    i\\hbar \\delta_{ij} \\delta\\left( \\vec{r} - \\vec{r}' \\right)\n\\end{align}\nwe find\n\\begin{align}\n    \\left[ \\hat{A}_i(\\vec{r}), \\hat{\\Pi}_j(\\vec{r}') \\right] &=\n    \\frac{1}{V} \\sum_{k,k'}\n    e^{i\\left( \\vec{k}\\cdot\\vec{r} + \\vec{k}'\\cdot\\vec{r}' \\right)}\n    \\underbrace{ \\left[ Q_i(\\vec{k}), P_j(\\vec{k}') \\right]}_{%\n    i\\hbar \\delta_{ij} \\delta_{\\vec{k},-\\vec{k}'}\n    }\\\\\n    &=\n    \\frac{i\\hbar}{V} \\sum_{\\vec{k}}\n    e^{i\\vec{k}\\cdot\\left( \\vec{r} - \\vec{r}' \\right)} \\delta_{ij}\\\\\n    &=\n    i\\hbar \\delta_{ij} \\delta\\left( \\vec{r} - \\vec{r}' \\right)\n\\end{align}\nso then\n\\begin{align}\n    \\left[ Q_i\\left( \\vec{r} \\right), P_j\\left( \\vec{r}' \\right) \\right]\n    =\n    i\\hbar \\delta_{ij} \\delta_{\\vec{k}, -\\vec{k}'}\n\\end{align}\nand all the other commutators between $Q_k$ and $P_k$ vanish.\nWe then define\n\\begin{align}\n    \\hat{a}_{\\vec{k}}^{\\alpha} &=\n    \\left( \n    \\sqrt{\\frac{\\omega_k}{2\\hbar}} \\vec{Q}(\\vec{k})\n    + \\frac{i}{\\sqrt{2\\omega_k\\hbar}} \\vec{P}(\\vec{k})\n    \\right)\n    \\cdot e_{\\vec{k}}^{\\alpha}\\\\\n    {\\hat{a}_{\\vec{k}}^{\\alpha}}^\\dagger &=\n    \\left( \n    \\sqrt{\\frac{\\omega_k}{2\\hbar}} \\vec{Q}(\\vec{k})\n    - \\frac{i}{\\sqrt{2\\omega_k\\hbar}} \\vec{P}(\\vec{k})\n    \\right)\n    \\cdot e_{\\vec{k}}^{\\alpha}\n\\end{align}\nwhere $e_{\\vec{k}}^1$ and $e_{\\vec{k}}^2$\nare two unit vectors orthogonal to $\\vec{k}$,\nwhich are the polarization directions.\nAnd the commutation relations\n\\begin{align}\n    \\left[\n    \\hat{a}_{\\vec{k}}^{\\alpha},\n    {\\hat{a}_{\\vec{k}}^{\\beta}}^\\dagger,\n    \\right]\n    &=\n    -i \\sqrt{\\frac{\\omega_k}{2\\hbar}}\n    \\frac{1}{\\sqrt{2\\omega_{k'}\\hbar}}\n    \\underbrace{\\left[ Q_i(\\vec{k}), P_j(\\vec{k}'), \\right]}_{%\n    i\\hbar \\delta_{ij} \\delta_{k,k'}\n    }\n    e_i^{\\alpha}(k)\n    e_j^{\\beta}(k)\\nonumber\\\\\n    &\\qquad\n    - \\sqrt{\\frac{\\omega_{k'}}{2\\hbar}}\n    \\frac{1}{\\sqrt{2\\omega_k \\hbar}}\n    \\underbrace{\\left[ P_j(\\vec{k}), Q_i(\\vec{k}') \\right]}_{%\n    -i\\hbar \\delta_{ij} \\delta_{k,k'}\n    }\n    e_j^{\\alpha}(k)\n    e_i^{\\alpha}(k')\\\\\n    &=\n    \\delta_{\\alpha\\beta} \\delta_{\\vec{k},\\vec{k}'}\n\\end{align}\nand also\n\\begin{align}\n    \\left[ \\hat{a}_{\\vec{k}}^{\\alpha}, \\hat{a}_{\\vec{k}'}^{\\beta} \\right] =\n    \\left[\n    {\\hat{a}_{\\vec{k}}^{\\alpha}}^\\dagger,\n    {\\hat{a}_{\\vec{k}'}^{\\beta}}^\\dagger\n    \\right] = 0\n\\end{align}\nThus,\n$\\hat{a}^\\alpha(k)$ and ${\\hat{a}^{\\alpha}}^\\dagger(k)$\nare creation and annihilation operators for photons with momentum $k$ and\npolarization $e^{\\alpha}(k)$.\nIn terms of them,\nthe Hamiltonian is\n\\begin{align}\n    \\hat{H} &=\n    \\frac{1}{2} \\sum_{\\alpha=1,2} V \\int d^3k\\,\\left[\n    -\\frac{\\hbar\\omega_k}{2}\n    \\left( \n    \\hat{a}_{\\vec{k}}^{\\alpha}\n    - {\\hat{a}_{-\\vec{k}}^{\\alpha}}^\\dagger\n    \\right)\n    \\left( \n    \\hat{a}_{-\\vec{k}}^{\\alpha}\n    - {\\hat{a}_{\\vec{k}}^{\\alpha}}^\\dagger\n    \\right)\n    +\n    \\omega_k^2\n    \\left( \n    \\hat{a}_{\\vec{k}}^{\\alpha}\n    - {\\hat{a}_{-\\vec{k}}^{\\alpha}}^\\dagger\n    \\right)\n    \\left( \n    \\hat{a}_{-\\vec{k}}^{\\alpha}\n    - {\\hat{a}_{\\vec{k}}^{\\alpha}}^\\dagger\n    \\right)\n    \\right]\\\\\n    &\\approx\n    \\frac{1}{2} \\sum_{\\alpha=1,2} \\int d^3k\\left[ \n    \\frac{\\hbar\\omega_k}{2} 2\n    \\hat{a}_{k}^{\\alpha}\n    {\\hat{a}_{k}^{\\alpha}}^\\dagger\n    +\n    {\\hat{a}_{k}^{\\alpha}}^\\dagger\n    \\hat{a}_{k}^{\\alpha}\n    2\n    \\frac{\\hbar\\omega_k}{2}\n    \\right]\\\\\n    &=\n    \\sum_{\\alpha=1,2} \\int d^3k\\left[ \n    {\\hat{a}_{k}^{\\alpha}}^\\dagger\n    \\hat{a}_{k}^{\\alpha}\n    +\n    \\frac{1}{2}\n    \\right]\n    \\hbar\\omega_k\n\\end{align}\nso that's one harmonic oscillator for every $\\vec{k}$ and $\\alpha$.\n\nHow we can calculate the partition function\n\\begin{align}\n    Z &= \\Tr e^{-\\beta \\hat{H}}\\\\\n    &=\n    \\prod_{\\vec{k},\\alpha} \\sum_{n_k=0}^{\\infty}\n    e^{-\\beta\\hbar\\omega_k\\left( n_k + \\frac{1}{2} \\right)}\\\\\n    &= \\prod_{\\vec{k}, \\alpha}\n    \\frac{e^{-\\beta\\hbar\\omega_k/2}}{1 - e^{-\\beta\\omega_k\\hbar}}\\\\\n    &= \\prod_{\\vec{k},\\alpha} \\frac{2}{\\sinh(\\beta\\hbar\\omega_k/2)}\n\\end{align}\nand the free energy\n\\begin{align}\n    F &=\n    -k_B T \\ln Z\\\\\n    &=\n    k_B T \\sum_{\\vec{k}, \\alpha} \\ln\\left( \n    \\frac{1 - e^{-\\beta \\omega_k \\hbar}}{e^{-\\beta\\hbar\\omega_k/2}}\n    \\right)\\\\\n    &=\n    k_B T \\sum_{\\vec{k},\\alpha}\\left[ \n    \\ln\\left( \n    1 - e^{-\\beta\\hbar\\omega_k}\n    \\right)\n    +\n    k_B T \\beta \\hbar\\omega_k\n    \\right]\\\\\n    &=\n    k_B T \\sum_{\\vec{k},\\alpha}\\left[ \n    \\ln\\left( \n    1 - e^{-\\beta\\hbar\\omega_k}\n    \\right)\n    +\n    \\underbrace{\\hbar\\omega_k}_{\\textrm{$T$-independent zero-point energy}}\n    \\right]\\\\\n    &\\approx\n    2 k_B T V \\int d^3k \\ln\\left( \n    1 - e^{-\\beta \\hbar\\omega_k}\n    \\right)\n    + \\textrm{const}\n\\end{align}\nwhich is the free energy of an ideal gas of bosons with dispersion relation\n$\\omega_k=kc$ and two polarizations plus a constant.\n\nThe energy is then\n\\begin{align}\n    \\frac{E}{V} &=\n    2 \\int d^3 k \\frac{\\hbar ck}{e^{\\beta \\hbar c k} - 1}\\\\\n    &=\n    \\frac{2}{\\left( \\beta\\hbar c \\right)^3 }\n    \\frac{1}{2\\pi^2}\n    \\frac{1}{\\beta}\n    \\underbrace{\\int_{0}^{\\infty}\n    dx\\,\n    \\frac{x^3}{e^{x} - 1}}_{%\n    \\pi^4/15\n    }\\\\\n    &=\n    \\frac{\\pi^2 \\left( k_B T \\right)^4}{15 \\hbar^3 c^3}\n\\end{align}\nThis is the \\emph{Steffan-Boltzmann law}.\n\nAlso, to get the spectrum,\n\\begin{align}\n    \\frac{E}{V} &=\n    2 \\frac{1}{2\\pi^2} \\int_{0}^{\\infty} dk\\,\n    \\frac{k^2 \\hbar ck}{e^{\\beta\\hbar ck} - 1}\\\\\n    &=\n    \\frac{\\hbar c}{\\pi^2} \\left( \\frac{2\\pi}{c} \\right)^4\n    \\int_{0}^{\\infty} d\\nu\\,\n    \\frac{\\nu^3}{e^{\\beta h\\nu} - 1}\\\\\n    &=\n    \\int_{0}^{\\infty} d\\nu\\,\n    \\underbrace{%\n    \\frac{16\\pi^2\\hbar}{c^3}\n    \\frac{\\nu^3}{e^{\\beta h \\nu} - 1}}_{%\n    u(\\nu)\n    }\n\\end{align}\nwhere\n\\begin{align}\n    u(\\nu) = \n    \\frac{16\\pi^2\\hbar}{c^3}\n    \\frac{\\nu^3}{e^{\\beta h \\nu} - 1}\n\\end{align}\nis the energy per volume per frequency.\nThis is \\emph{Planck's law}.\n", "meta": {"hexsha": "a4da31424c15d2d2ad55a33cf745892cbc4e721c", "size": 10324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/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": "phys612/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": "phys612/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": 28.5983379501, "max_line_length": 79, "alphanum_fraction": 0.5700309957, "num_tokens": 4122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6367025278138644}}
{"text": "\\subsection{The Space of Germs}\r\nLet $D\\subset\\mathbb C$ a domain.\r\n\\begin{definition}\r\n    Let $(f,U)$ and $(g,V)$ be function elements on $D$.\r\n    For any $z\\in U\\cap V$, write $(f,U)\\equiv_z(g,V)$ if $f,g$ agree on a neighbourhood of $z$.\r\n\\end{definition}\r\nEasily $\\equiv_z$ is an equivalence relation.\r\n\\begin{definition}\r\n    Let $(f,U)$ be a function element and $z\\in U$.\r\n    The equivalence class of $(f,U)$ under $\\equiv_z$ is called the germ of $f$ at $z$ and is denoted by $[f]_z$.\r\n\\end{definition}\r\nSo two germs $[f]_z$ and $[g]_w$ are equal iff $z=w$ and $f=g$ on a neighbourhood of $z=w$.\r\nWe want to study all possible germs on a domain $D$.\r\n\\begin{definition}\r\n    The space of germ over $D$ is\r\n    $$\\mathcal G=\\{[f]_z:z\\in D,(f,D)\\text{ a function element with $z\\in U$}\\}$$\r\n\\end{definition}\r\nNow we defined it as a set, it is natural to endow a topology on it.\r\nFor any function element $(f,U)$ on $D$, let $[f]_U=\\{[f]_z:z\\in U\\}$.\r\n\\begin{lemma}\r\n    The collection $\\{[f]_U\\}$ for $U$ open in $D$ is a basis of a topology on $\\mathcal G$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $(f,U)$ and $(g,V)$ be function elements on $D$.\r\n    For any $[h]_z\\in [f]_U\\cap [g]_V$, then $h$ agrees with $f,g$ on a neighbourhood $W$ of $z$, therefore $[h]_W\\subset [f]_U\\cap[g]_V$.\r\n\\end{proof}\r\nThis is the topology we want.\r\n\\begin{lemma}\r\n    $\\mathcal G$ is Hausdorff.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Consider elements of $[f]_z,[g]_z\\in\\mathcal G$ with $[f]_z\\neq [g]_z$.\\\\\r\n    If $z\\neq w$ then we can choose function elements $(f,U)\\in [f]_z,(g,V)\\in[g]_w$ such that $U\\cap V=\\varnothing$, therefore $[f]_U$ and $[g]_V$ are disjoint.\\\\\r\n    If $z=w$, then we can choose an open neighbourhood $U$ such that $(f,U)\\in[f]_z$ and $(g,U)\\in [g]_z$.\r\n    Unless $[f]_U\\cap [g]_U=\\varnothing$, there is a germ $[h]_z\\subset [f]_U\\cap[g]_U$.\r\n    By the identity principle $f|_U=h|_U=g|_U$, which means $[f]_z=[h]_z=[g]_z$ due to the connectedness of $U$, contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $\\mathcal G$ be the space of germs over a domain $D$.\r\n    The forgetful map $\\pi:\\mathcal G\\to D$ is defined by $\\pi([f]_z)=z$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    For each component $G\\subset\\mathcal G$, the restriction $\\pi:G\\to D$ is a covering map.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Take an open $U\\subset D$.\r\n    Then the pre-image of $U$ has to be\r\n    $$\\pi^{-1}(U)=\\bigcup_{(f,V)\\text{ function element on }U}[f]_V$$\r\n    which is open.\r\n    So $\\pi$ is continuous.\\\\\r\n    For each open set in the form $[f]_U$, we have\r\n    $$(\\pi|_{[f]_U})^{-1}(z)=[f]_z$$\r\n    which is a continuous inverse of $\\pi|_{[f]_U}$.\r\n    This shows that $\\pi$ is a local homeomorphism, hence a covering map.\r\n\\end{proof}\r\nHence, by Lemma \\ref{covering_conformal}, $\\pi$ induces a well-defined conformal structure on $\\mathcal G$ (well, on each of its connected components) such that $\\pi$ is analytic.\r\nExplicitly, the atlas we have in mind consists of charts $(\\pi|_{[f]_U},[f]_U)$ across all the function elements $(f,U)$ on $D$.\r\n\\begin{definition}\r\n    Let $\\mathcal G$ be the space of germs on a domain $D$.\r\n    The evaluation map $\\mathcal E:\\mathcal G\\to\\mathbb C$ is defined by $\\mathcal E([f]_z)=f(z)$.\r\n\\end{definition}\r\nIn the chart $(\\pi|_{[f]_U},[f]_U)$, we have\r\n$$\\mathcal E\\circ(\\pi|_{[f]_U})^{-1}(z)=\\mathcal E([f]_z)=f(z)$$\r\nTherefore $\\mathcal E$ is analytic.", "meta": {"hexsha": "662d66ec7ca36471e730aa03e9c52ff401588aa4", "size": 3395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/germs.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": "8/germs.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": "8/germs.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": 53.046875, "max_line_length": 180, "alphanum_fraction": 0.6321060383, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6367025268321044}}
{"text": "%auto-ignore\n%! TEX root = ../Text.tex\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\n\\begin{document}\n\\section{Orientation, Poincar\\'e duality, Hodge decomposition}\n\\label{SubSec:CycStr}\n\nIn this section, a $\\DGA$ $V$ is a triple $(V,\\Dd,\\wedge)$, where \n\\begin{itemize}\n\\item $V = \\bigoplus_{n\\in \\Z} V^n$ is a $\\Z$-graded vector space,\n\\item $\\Dd: V\\rightarrow V$ a differential of degree $1$, and\n\\item $\\wedge: V\\otimes V \\rightarrow V$ an associative product of degree $0$ such that $\\Dd$ and $\\wedge$ satisfy the Leibnitz identity $\\Dd(v_1 \\wedge v_2) = \\Dd v_1 \\wedge v_2 + (-1)^{v_1} v_1 \\wedge\\Dd v_2$ for all homogenous $v_1$, $v_2\\in V$.\n%\\[ \\Dd(v_1 \\wedge v_2) = \\Dd v_1 \\wedge v_2 + (-1)^{v_1} v_1 \\wedge \\Dd v_2. \\]\n\\end{itemize}\nIn other words, we consider general, possibly non-unital and non-commutative, $\\Z$-graded $\\DGA$'s. We denote by $\\deg(v)$ the degree of a homogenous element $v\\in V$ and write $(-1)^v$ in the exponent.\n%We will consider two closely related notions on a $\\DGA$ --- an orientation and a cyclic structure.\n \n%We will not need degree shifts, and hence we will use $\\Abs{v}$ and $\\Deg(v)$ (and~$v$ in the exponent) to denote the degree of $v$ interchangeably.\n\n\\begin{Definition}[Orientations and cyclic structures]\\label{Def:CycStr} \nLet $(V,\\Dd)$ be a $\\Z$-graded cochain complex. We define the following:\n\\begin{itemize}\n\\item An \\emph{orientation in degree $n$} is a linear function $\\Or : V^n \\rightarrow \\R$ such that\n\\[\\Or \\neq 0\\quad\\text{and}\\quad\\Or \\circ \\Dd = 0. \\]\nIn other words, it is a surjective chain map $\\Or : (V,\\Dd) \\rightarrow (\\R[-n],0)$.\n\\item A~\\emph{cyclic structure of degree $n$} is a homogenous bilinear form $\\langle \\cdot, \\cdot \\rangle : V \\otimes V \\rightarrow \\R$ of degree $-n$ as a map such that for all homogenous $v_1$, $v_2\\in V$, we have\n\\begin{equation}\\label{Eq:CycStr}\n\\langle \\Dd v_1, v_2\\rangle = (-1)^{1+v_1 v_2} \\langle \\Dd v_2, v_1 \\rangle.\n\\end{equation}\n\\end{itemize}\nA cyclic structure on a $\\DGA$ $(V,\\Dd,\\wedge)$ is additionally required to satisfy  \n\\begin{equation}\\label{Eq:CycStrII}\n\\langle v_1 \\wedge v_2, v_3 \\rangle = (-1)^{v_3(v_1 + v_2)}\\langle v_3\\wedge v_1, v_2 \\rangle\n\\end{equation}\nfor all homogenous $v_1$, $v_2$, $v_3\\in V$.\n%Morphisms of such objects are morphisms of $\\DGA$'s preserving the cyclic structure, resp.~the orientation. \n\\end{Definition}\n\nAnalogously, one can define a cyclic structure on an $\\AInfty$-algebra.\n\n\\begin{Remark}[Cyclic $\\DGA$]\\label{Rem:Eq}\nA cyclic $\\DGA$ $(V,\\Pair,\\mu_1,\\mu_2)$ of degree $n$ from Definition~\\ref{Def:CyclicAinfty} is the same as a $\\DGA$ equipped with a cyclic structure~$\\langle\\cdot,\\cdot\\rangle$ of degree $n$ which is symmetric, i.e., \n\\[ \\langle v_1, v_2 \\rangle = (-1)^{v_1 v_2} \\langle v_2, v_1\\rangle \\]\nfor all homogenous $v_1$, $v_2\\in V$, and non-degenerate (see Definition~\\ref{Def:PoincDual}). The correspondence is via the degree shift\n\\begin{align*}\n\\mu_1(\\SuspU v) &= \\SuspU \\Dd(v),\\\\\n\\mu_2(\\SuspU v_1, \\SuspU v_2) &= (-1)^{v_1}\\SuspU(v_1\\wedge v_2),\\\\\n\\Pair(\\SuspU v_1, \\SuspU v_2) & = (-1)^{v_1} \\langle v_1,v_2\\rangle,\n\\end{align*}\nwhere $\\SuspU$ is a formal symbol of degree $-1$. From this reason, we sometimes call a $\\DGA$ equipped with a non-degenerate symmetric cyclic structure a cyclic $\\DGA$, although there are degree shifts involved.\n\\end{Remark}\n\nThe homology $\\H(V)\\coloneqq \\H(V,\\Dd)$ of a $\\DGA$ $(V,\\Dd,\\wedge)$ is also a $\\DGA$ with the induced product $\\wedge$ and with zero differential. Given an orientation $\\Or$ or a cyclic structure $\\langle\\cdot,\\cdot\\rangle$ on~$V$, we define the maps $\\Or^\\H: \\H(V) \\rightarrow \\R$ and $\\langle\\cdot,\\cdot\\rangle^\\H: \\H(V)\\otimes\\H(V)\\rightarrow\\R$ for all closed $h_1$, $h_2\\in V$ by\n\\begin{equation}\\label{Eq:IndOnHom}\n\\begin{aligned}\n\\Or^\\H([h_1]) &\\coloneqq \\Or(h_1)\\text{ and}\\\\\n\\langle[h_1],[h_2]\\rangle^\\H &\\coloneqq \\langle h_1, h_2\\rangle,\n\\end{aligned}\n\\end{equation}\nrespectively, where $[\\cdot]$ denotes the cohomology class. It is easy to see that $\\langle\\cdot,\\cdot\\rangle^\\H$ is a cyclic structure on $\\H(V)$ and that $\\Or^\\H$ is an orientation on $\\H(V)$ provided that $\\Restr{\\Or}{\\Ker \\Dd} \\neq 0$. \n\n\\begin{Proposition}[Orientation on homology]\\label{Prop:OrOnHomG}\nWe have the following:\n\\begin{ClaimList}\n\\item Let $(V,\\Dd)$ be a $\\Z$-graded cochain complex, and let $n\\in \\Z$. Given an orientation $\\tilde{\\Or}: \\H^n(V) \\rightarrow \\R$, there is an orientation $\\Or^V: V^n \\rightarrow \\R$ such that~$\\tilde{\\Or} = \\Or^\\H$. If $\\Dd V^n = 0$, then we have the correspondence\n\\[\\text{Orientations on }V\\text{ in degree }n\\ \\overset{1:1}{\\simeq}\\ \\text{Orientations on }\\H(V)\\text{ in degree }n. \\]  \n\\item If $(V_1,\\Dd_1,\\Or_1)$ and $(V_2,\\Dd_2,\\Or_2)$ are $\\Z$-graded cochain complexes oriented in degree $n$ with $\\Dd V_1^n = 0 = \\Dd V_2^n$, then a chain map $f: V_1 \\rightarrow V_2$ preserves the orientation if and only if the induced map $f_*: \\H(V_1) \\rightarrow \\H(V_2)$ preserves the induced orientation.\n\\end{ClaimList}\n\\end{Proposition}\n\\begin{proof}\n\\begin{ProofList}\n\\item We define $\\Or^V(v) \\coloneqq \\tilde{\\Or}([v])$ for all closed $v\\in V$ and extend it by $0$ to a complement of $\\Ker \\Dd$ in~$V$. It is obvious that $\\Or^\\H = \\tilde{\\Or}$. If $\\Dd V^n = 0$, any complement is trivial and $\\Or^V$ is uniquely determined by $\\Or^\\H$.\n\n\\item Let $v\\in V_1^n$. Because $\\Dd v = 0$, we have\n\\[ \\Or_2(f(v)) = \\Or^{\\H}_2([f(v)]) = \\Or^{\\H}_2(f_*[v]) = \\Or^{\\H}_1([v]) = \\Or_1(v). \\]\nThis finishes the proof.\\qedhere\n\\end{ProofList}\n\\end{proof}\n\nSuppose that $1$ is a unit for $(V,\\Dd,\\wedge)$, i.e., $1\\in V^0$, $\\Dd 1 = 0$ and $1\\wedge v = v \\wedge 1 = v$ for all $v\\in V$, and let $\\langle \\cdot,\\cdot\\rangle$ by a cyclic structure on $V$. For all homogenous $v_1$, $v_2\\in V$, we have \n\\begin{align*}\n\\langle v_1, v_2 \\rangle &= \\langle v_1\\wedge 1,v_2\\rangle \\\\\n& = (-1)^{v_1 v_2}\\langle 1\\wedge v_2, v_1 \\rangle \\\\\n& = (-1)^{v_1 v_2}\\langle v_2, v_1 \\rangle,  \n\\end{align*}\nand hence $\\langle \\cdot,\\cdot\\rangle$ is automatically symmetric.\n\nRecall that a $\\DGA$ is called commutative if $v_1 \\wedge v_2 = (-1)^{v_1 v_2} v_2\\wedge v_1$ for all homogenous $v_1$, $v_2\\in V$. Commutativity of a $\\DGA$ and symmetry of a general cyclic structure on it seem to be unrelated.\n\n%The induced cyclic structure on the $\\DGA$ $(\\H(V), 0, \\wedge)$ is denoted by the same symbol and defined by \n%\\begin{equation}\\label{Eq:IndHom}\n%\\langle [v_1], [v_2] \\rangle = \\langle v_1, v_2 \\rangle\\quad\\text{for all closed }v_1, v_2\\in V. \n%\\end{equation}\n%\n%The (induced) orientation in degree $n$ on $\\H(V)$ is denoted by $\\int: \\H^n(V) \\rightarrow \\R$; by definition, we have\n%\\begin{equation}\\label{Eq:IndOr}\n%\\int [v] = \\Or(v)\\quad\\text{for all closed }in V.\n%\\end{equation}\n\n%\n%It turns out that, e.g., for unital $\\DGA$'s with the degree bounded from above by~$n$, cyclic structures $\\langle\\cdot,\\cdot\\rangle$ of degree $n$ on $V$ are in one-to-one correspondence with orientations $\\int: \\H^n(V) \\rightarrow \\R$ on the homology. The precise relation is stated in the following lemma.\n\\begin{Proposition}[Correspondence of orientations and cyclic structures on $\\DGA$'s]\\label{Prop:OrAndCyc}\nLet $(V,\\Dd,\\wedge)$ be a $\\DGA$. Then the following holds:\n\\begin{ClaimList}\n\\item If $\\wedge$ is commutative, then any orientation $\\Or$ in degree $n$ induces a cyclic structure~$\\langle\\cdot,\\cdot\\rangle$ of degree $n$ which is given for all homogenous $v_1$, $v_2\\in V$ by\n\\begin{equation}\\label{Eq:PairForm}\n\\langle v_1, v_2 \\rangle \\coloneqq \\begin{cases}\n    \\Or(v_1 \\wedge v_2) & \\text{if }\\deg(v_1) + \\deg(v_2) = n, \\\\\n    0 & \\text{otherwise}. \\end{cases}\n\\end{equation}\n\\item If $1$ is a unit, then any non-zero cyclic structure $\\langle\\cdot,\\cdot\\rangle$ of degree $n$ induces an orientation~$\\Or$ in degree $n$ by defining \n\\begin{equation}\\label{Eq:OrForm}\n\\Or(v) \\coloneqq \\begin{cases}\n \\langle v, 1 \\rangle & \\text{for }v\\in V^n,\\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation}\n\\item For a unital commutative $\\DGA$ $(V,\\Dd,\\wedge,1)$, formulas \\eqref{Eq:PairForm} and \\eqref{Eq:OrForm} define the correspondence\n\\[ \\text{Orientations in degree }n\\ \\overset{1:1}{\\simeq}\\ \\text{Non-zero cyclic structures of degree }n.\\]\n%If moreover $(V,\\Dd,\\wedge,1)$ is unital, then there is a canonical correspondence\n%\\[ \\text{cyc.~str.~on }V\\text{ of degree }n\\ \\overset{1:1}{\\simeq}\\  \\text{ cyc.~str.~on }\\H(V)\\text{ of degree }n. \\]\n%%In particular, a DGA-morphism $f: V \\rightarrow V'$ preserves the corresponding structure on the chain level if and only if $f_*: \\H(V) \\rightarrow \\H(V')$ preserves it on homology.\n\\end{ClaimList}\n\\end{Proposition}\n\\begin{proof}\n\\begin{ProofList}\n\\item  Using the Leibnitz identity, properties of an orientation and commutativity, we check that\n\\begin{align*}\n\\langle \\Dd v_1, v_2 \\rangle &= \\Or(\\Dd v_1 \\wedge v_2) \\\\\n&= \\Or\\bigl(\\Dd(v_1\\wedge v_2) - (-1)^{v_1} v_1 \\wedge \\Dd v_2\\bigr) \\\\\n&= (-1)^{1+v_1}\\Or(v_1\\wedge\\Dd v_2)\\\\\n&= (-1)^{1+v_1 v_2} \\Or(\\Dd v_2 \\wedge v_1) \\\\\n&= (-1)^{1+v_1 v_2} \\langle \\Dd v_2, v_1\\rangle\n\\end{align*}\nand \n\\begin{align*}\n\\langle v_1\\wedge v_2, v_3\\rangle &= \\Or(v_1\\wedge v_2\\wedge v_3)\\\\\n&= (-1)^{v_3(v_1+v_2)} \\Or(v_3 \\wedge v_1 \\wedge v_2)\\\\\n&= (-1)^{v_3(v_1+v_2)} \\langle v_3\\wedge v_1, v_2\\rangle\n\\end{align*}\nfor all homogenous $v_1$, $v_2$, $v_3\\in V$.\n\\item For all $v\\in V$, we have\n\\begin{align*}\n\\Or(\\Dd v) = \\langle \\Dd v, 1 \\rangle = - \\langle \\Dd 1, v \\rangle = 0.\n\\end{align*}\nFrom $\\langle\\cdot,\\cdot\\rangle \\neq 0$ it follows that there are homogenous $v_1$, $v_2\\in V$ with $\\deg(v_1) + \\deg(v_2) = n$ such that $\\langle v_1, v_2 \\rangle \\neq 0$. Then $v_1\\wedge v_2\\in V^n$ and\n\\begin{align*}\n\\Or(v_1 \\wedge v_2) &= \\langle v_1\\wedge v_2,1\\rangle\\\\\n&= \\langle 1 \\wedge v_1, v_2\\rangle\\\\\n&=\\langle v_1,v_2\\rangle \\neq 0.\n\\end{align*}\nTherefore, $\\Or$ is an orientation on $V$.\n\\item This is a combination of (a) and (c) plus the uniqueness, which is easy to check.\\qedhere\n\\end{ProofList}\n\\end{proof}\n\n\\begin{Remark}[Volume forms]\\label{Rem:VolForms}\nIf $\\H^n(V) \\simeq \\R$, then orientations $\\Or: \\H^n(V)\\rightarrow\\R$  and elements $0\\neq [\\Vol] \\in \\H^n(V)$ called \\emph{volume forms} are in one-to-one correspondence via\n\\[ \\Or([\\Vol]) = 1. \\]\nA consequence is the following:\nSuppose that $(V_1,\\Dd_1,\\Or_1)$ and $(V_2,\\Dd_2,\\Or_2)$ are cochain complexes oriented in degree $n$ which satisfy \n\\begin{equation}\\label{Eq:SDDFG}\n\\H^n(V_1)\\simeq\\H^n(V_2)\\simeq\\R\\quad\\text{and}\\quad\\Dd_1 V_1^n \\simeq \\Dd_2 V_2^n = 0,\n\\end{equation}\nso that Proposition~\\ref{Prop:OrOnHomG} applies. Then a chain map $f: V_1 \\rightarrow V_2$ preserves orientation if and only if the induced map $f_*: \\H^n(V_1) \\rightarrow \\H^n(V_2)$ maps $[\\Vol_1]$ to $[\\Vol_2]$. In the category of unital commutative $\\DGA$'s satisfying \\eqref{Eq:SDDFG}, so that also Proposition~\\ref{Prop:OrAndCyc} holds, if the orientations come from cyclic structures, then $f$ preserves cyclic structure if and only if~$f_*$ preserves volume form.\n%If $V$ is an oriented augmented unital $\\DGA$ if the pairing is non-deg, one defines $\\Vol$ uniquely by requiring that $\\Vol \\perp \\bar{V}$ and $\\Or(\\Vol) = 1$.\n\\todo[noline,caption={DONE Augmented case}]{In the augmented unital case, if the pairing is non-deg, one defines $\\Vol$ uniquely by requiring that $\\Vol \\perp \\bar{V}$ and $\\Or(\\Vol) = 1$. Let us not write it.}\n\\end{Remark}\n\n\n%Observe that if the cyclic structure $\\langle\\cdot,\\cdot\\rangle$ comes from an orientation, which is always the case when the $\\DGA$ is unital by Proposition~\\ref{Prop:OrAndCyc}, then it is \\emph{graded symmetric} (shortly symmetric), i.e., it holds\n%\\[ \\langle v_1,v_2\\rangle = (-1)^{v_1 v_2}\\langle v_2,v_1\\rangle\\quad\\text{for all homogenous }v_1, v_2\\in V. \\]\n\n\\begin{Definition}[Non-degeneracy and Poincar\\'e duality]\\label{Def:PoincDual}\n%An orientation $\\Or: V \\rightarrow \\R$ on a graded vector space~$V$ is called \\emph{non-degenerate} if for every $v\\in V$, the following implication holds:\n%\\[ \\Or(v\\wedge w)= 0\\quad\\text{for all }w\\in V\\quad\\Implies\\quad v=0. \\]\nGiven a graded vector space~$V$, a homogenous bilinear form ($\\eqqcolon$\\,pairing) $\\langle\\cdot,\\cdot\\rangle: V\\otimes V \\rightarrow \\R$ of degree $-n$ as a map which is graded symmetric is called \\emph{non-degenerate} if for every $v\\in V$, the following implication holds:\n\\[ \\langle v,w \\rangle= 0\\quad\\text{for all }w\\in V\\quad\\Implies\\quad v=0. \\]\nWe say that $\\langle\\cdot,\\cdot\\rangle$ satisfies \\emph{Poincar\\'e duality} if the map $\\flat: V \\rightarrow V^{\\GD}$ (graded dual) defined by \n\\[\\flat(v)(w) \\coloneqq \\langle v,w\\rangle\\quad \\text{for all }v,w\\in V\\]\nis a graded isomorphism (it has degree $-n$ as a map) of graded vector spaces.\n\\end{Definition}\n\n\\begin{Remark}[On non-degeneracy and Poincar\\'e duality]\\phantomsection\\label{Rem:NonDegPD}\n\\begin{RemarkList}\n\\item Clearly, Poincar\\'e duality implies non-degeneracy. If the degree $k$ component $V^k$ of $V$ is finite-dimensional for every~$k\\in \\Z$ --- we say that $V$ is of \\emph{finite type} --- then the opposite is true as well. If $n=0$, then Poincar\\'e duality implies that $V$ is of finite type.\n%In this case, we obtain the well-known Poincar\\'e duality $V^k \\simeq V^{n-k}$.\n\\item If $V$ is non-negatively graded, then non-degeneracy of $\\langle\\cdot,\\cdot\\rangle: V\\otimes V \\rightarrow \\R$ implies $V = V^0 \\oplus \\dotsb \\oplus V^n$. Therefore, non-negatively graded vector spaces of finite type which admit a non-degenerate homogenous bilinear form are finite-dimensional.\n\\item The de Rham complex $(\\DR(M),\\Dd,\\wedge)$ of an oriented closed $n$-manifold~$M$ with the orientation $\\int: \\DR^n(M) \\rightarrow \\R$ is an oriented $\\DGA$ whose cyclic structure is non-degenerate but does not satisfy Poincar\\'e duality. On the other hand, the induced structure on homology $\\H(\\DR(M))$ satisfies Poincar\\'e duality.\n\\qedhere\n\\end{RemarkList}\n\\end{Remark}\n%\n%We now relate similar definitions from \\cite{Cieliebak2015}, \\cite{VanLe2019} and \\cite{Lambrechts2007} to our definitions:\n%\\begin{itemize}\n%\\item A ``cyclic $\\DGA$'' as defined in \\cite{Cieliebak2015} is a $\\DGA$ $(V,\\Dd,\\wedge)$ with a symmetric non-degenerate cyclic structure $\\langle \\cdot,\\cdot \\rangle : V \\otimes V \\rightarrow \\R$. Different signs in their definition occur because they consider the operations on the degree shift $V[1]$ (c.f., Definition~\\ref{Def:})\n%\\item A ``Poincar\\'e-DGCA of degree $n$'' as defined in \\cite{VanLe2019} is a unital commutative $\\DGA$ (shortly $\\uCDGA$) $(V,\\Dd,\\wedge,1)$ with $V=V^0\\oplus \\dotsb\\oplus V^n$ and with an orientation $\\int: \\H^n(V) \\rightarrow \\R$ such that $(\\H(V),\\wedge,\\int)$ is a finite-dimensional Poincar\\'e algebra.\n%\\item An ``oriented Poincar\\'e-CDGA'' as defined in \\cite{Lambrechts2007} is a $\\uCDGA$ with non-negatively graded $V$ of finite type such that $\\H(V)$ is a Poincar\\'e algebra.\n%\\end{itemize}\n%For unital cyclic $\\DGA$'s, cyclicity implies \\emph{graded symmetry} of $\\langle\\cdot,\\cdot\\rangle$. Indeed, for all homogenous $v_1$, $v_2\\in V$, we have\n%\\[ \\langle v_1, v_2 \\rangle = \\langle 1 \\wedge v_1, v_2 \\rangle = (-1)^{v_1 v_2} \\langle v_2 \\wedge 1, v_1 \\rangle = (-1)^{v_1 v_2} \\langle v_2, v_1\\rangle. \\]\n%Graded symmetry is also automatic for $\\langle\\cdot,\\cdot\\rangle$ coming from an orientation.\n%%For simplicity, we will assume from now on that $\\langle\\cdot,\\cdot\\rangle$ is symmetric.\n\nAn analog of the following definition is used in \\cite{Van2019} and also in \\cite{Lambrechts2007} (under the name ``set of orphans''). \n\n\\begin{Definition}[Degenerate subspace and non-degenerate quotient]\\label{Def:NonDegQ}\nGiven a symmetric pairing $\\langle\\cdot,\\cdot\\rangle: V\\otimes V\\rightarrow\\R$ on a graded vector space~$V$, we define the \\emph{degenerate subspace}~$V^\\perp\\subset V$ by \n\\begin{align*}\nV^\\perp\\coloneqq \\{ v\\in V \\mid \\langle w,v \\rangle = 0\\text{ for all }w\\in V\\}.\n\\end{align*}\nIf $(V,\\Dd,\\wedge)$ is a $\\DGA$ and $\\langle\\cdot,\\cdot\\rangle$ a cyclic structure, then \\eqref{Eq:CycStr} implies that $V^\\perp$ is a differential graded ideal in $V$, and thus we obtain the short exact sequence of $\\DGA$'s\n\\begin{equation}\\label{Eq:ImportantSES}\n\\begin{tikzcd}\n0 \\arrow{r} & V^\\perp \\arrow[hook]{r}{\\iota} & V \\arrow[two heads]{r}{\\pi^\\VansQuotient} & \\VansQuotient(V) \\coloneqq V / V^\\perp \\arrow{r} & 0,\n\\end{tikzcd}\n\\end{equation}\nwhere $\\iota$ is the inclusion and $\\pi^\\VansQuotient$ the canonical projection. We call the $\\DGA$ $\\VansQuotient(V)$ together with the induced non-degenerate cyclic structure $\\langle\\cdot,\\cdot\\rangle^\\VansQuotient$ such that $\\langle\\pi^\\VansQuotient(\\cdot),\\pi^\\VansQuotient(\\cdot)\\rangle^\\VansQuotient = \\langle\\cdot,\\cdot\\rangle$ the \\emph{non-degenerate quotient.}\n\\end{Definition}\n\nIt was observed in~\\cite{Van2019} that the question whether $(V^\\perp,\\Dd)$ is acyclic, and hence~$\\pi^\\VansQuotient$ is a quasi-isomorphism, turns out to be related to the existence of Hodge decomposition.\n\n\\begin{Definition}[Hodge decomposition]\\label{Def:HodgeDecomp}\nA cochain complex $(V,\\Dd)$ with a symmetric cyclic structure $\\langle\\cdot,\\cdot\\rangle: V\\otimes V \\rightarrow \\R$ is \\emph{of Hodge type} if there exist subspaces $\\Harm \\subset \\Ker \\Dd$ and $C\\subset V$ such that \n\\begin{equation}\\label{Eq:HodgeDecomp}\nV = \\Ker \\Dd \\oplus C, \\quad \\Ker \\Dd = \\Im \\Dd \\oplus \\Harm\\quad\\text{and}\\quad C \\perp \\Harm \\oplus C,\n\\end{equation}\nwhere $\\perp$ denotes the relation of being perpendicular with respect to $\\langle\\cdot,\\cdot\\rangle$. Such decomposition is called a \\emph{Hodge decomposition.} We call $\\Harm$ the \\emph{harmonic subspace} and $C$ the \\emph{coexact part}.\n\nGiven a Hodge decomposition, we define the \\emph{standard Hodge homotopy} $\\HtpStd: V \\rightarrow V$~by \n\\[\\HtpStd \\coloneqq \\begin{cases}\n    -(\\Restr{\\Dd}{C})^{-1} & \\text{on }\\Im \\Dd, \\\\\n    0 & \\text{on } \\Harm \\oplus C.\n   \\end{cases}\\]\nThen we have $\\Dd \\HtpStd = - \\pi_{\\Im \\Dd}$, $\\HtpStd \\Dd = -\\pi_{C}$, and hence \n\\[ [\\Dd,\\HtpStd] = \\Dd \\HtpStd + \\HtpStd \\Dd = \\pi_\\Harm - \\Id.\\]\n We call $(\\Harm,\\HtpStd)$ the \\emph{Hodge pair} associated to the Hodge decomposition \\eqref{Eq:HodgeDecomp}.\n\\end{Definition}\n\n\\begin{Proposition}[Non-deg., fin.~type implies Hodge type]\\label{Prop:NDegFin}\nAny cochain complex of finite type with a non-degenerate symmetric cyclic structure is of Hodge type.\n\\end{Proposition}\n\\begin{proof}\nThis is \\cite[Lemma~11.1]{Cieliebak2015}, and the proof uses formal Hodge theory.\n\\end{proof}\n\n\\begin{Remark}[Harmonic subspaces]\\label{Rem:RemarkHarm}\nIn the situation of Proposition~\\ref{Prop:NDegFin}, it was shown in \\cite[Remark~2.6]{Van2019} that for any complement $\\Harm$ of $\\im\\Dd$ in $\\ker\\Dd$ (in other words, the image of a section $\\H(V)\\rightarrow \\Ker\\Dd$) there is a coexact part $C$ such that $V=\\Harm \\oplus \\Im \\Dd \\oplus C$ is a Hodge decomposition. From this reason, we call any complement of $\\im \\Dd$ in $\\ker \\Dd$ a \\emph{harmonic subspace.}\\footnote{Given a Hodge decomposition $V=\\Harm\\oplus\\im\\Dd\\oplus C$ and a harmonic subspace $\\Harm'$, then it holds $\\Harm' = \\Graph(\\alpha: \\Harm \\rightarrow \\Dd V)$ because $\\Harm \\oplus \\Dd V = \\Harm' \\oplus \\Dd V$, and one can take $C'=\\Graph(- \\alpha^\\dagger - \\frac{1}{2}\\alpha\\alpha^\\dagger: C \\rightarrow \\Harm\\oplus\\Dd V)$.}\n\\end{Remark}\n\nThe following lemma will be used in the proof of Proposition~\\ref{Prop:HodgeAcyc}.\n\n\\begin{Lemma}[Complement of acyclic subcomplex over $\\R$]\\label{Lem:Pom}\nLet $f: V_1 \\rightarrow V_2$ be an injective chain map of cochain complexes $(V_1,\\Dd_1)$ and $(V_2,\\Dd_2)$ over $\\R$ such that $(V_1,\\Dd_1)$ is acyclic. Then there is a chain map $g: V_2 \\rightarrow V_1$ such that $g\\circ f=\\Id$.\\footnote{This lemma can be used to prove that over $\\R$, every surjective quasi-isomorphism is a deformation retraction and every injective quasi-isomorphism is a section of a deformation retraction.}\n\\end{Lemma}\n\n\\begin{proof}\nFor every $i\\in \\Z$, consider the diagram\n\\[\\begin{tikzcd}\n\\Ker \\Dd_1^i \\oplus C^i_1 \\arrow{r}{f^i} \\arrow{d}{\\Dd_1^i} & \\Ker \\Dd_2^i \\oplus C^i_2 \\arrow{d}{\\Dd_2^i} \\\\\n\\Ker \\Dd^{i+1}_1 \\oplus C^{i+1}_1 \\arrow{r}{f^{i+1}} & \\Ker \\Dd_2^{i+1} \\oplus C^{i+1}_2,\n\\end{tikzcd}\\]\nwhere $C^i_1$ is a complement of $\\Ker \\Dd_1^i$ in $V_1^i$ and $C^i_2$ is a complement of $\\Ker \\Dd_2^i$ in~$V_2^i$. With respect to this decomposition, we write\n\\begin{align*}\nf^i & = \\begin{pmatrix}\nf^{i}_{11} & f^i_{12} \\\\\nf^{i}_{21} & f^i_{22}\n\\end{pmatrix},  & g^i &= \\begin{pmatrix}\ng^{i}_{11} & g^i_{12} \\\\\ng^{i}_{21} & g^i_{22}\n\\end{pmatrix}, \\\\\n\\Dd^i_1 &= \\begin{pmatrix}\n0 & d^i_1 \\\\\n0 & 0\n\\end{pmatrix},& \\Dd^i_2 &= \\begin{pmatrix}\n0 & d^i_2 \\\\\n0 & 0\n\\end{pmatrix}.\n\\end{align*}\n\nThe assumption $\\H(V_1)=0$ implies that $d^i_1$ is an isomorphism. The fact that~$f$ is a chain map translates to\n\\begin{equation}\\label{Eq:EqEqEq}\nd_2^i f^i_{21} = 0,\\quad f^{i+1}_{21} d_1^i = 0,\\quad f^{i+1}_{11} d^i_1 = d^i_2 f^i_{22}.\n\\end{equation}\nFrom the second relation and surjectivity of $d_1^i$, we get that $f_{21}^{i+1} = 0$. Now,~$f^{i+1}_{11}$ has to be injective because it is the only possibly non-zero part of $f$ on $\\Ker d_1^{i+1}$. From the third relation of \\eqref{Eq:EqEqEq} and the fact that $d_1^i$ is injective, we get that $f_{22}^i$ is injective as well.\nRelations \\eqref{Eq:EqEqEq} hold also for $g$ with $d_1$ and $d_2$ switched. In particular, we have $g_{21}^{i}=0$. The relation $g \\circ f = \\Id$ translates using $f^i_{21} = g^i_{21} = 0$ to\n\\begin{equation}\\label{Eq:EqEq}\ng^i_{11} f^i_{11} = \\Id, \\quad g^i_{11} f^i_{12} + g^i_{12}f^i_{22}=0, \\quad g^i_{22} f^i_{22} = \\Id.\n\\end{equation}\nBecause $d_1^i$ is an isomorphism, the last equation is equivalent to \n\\[ \\Id = d_1^i g^i_{22}f^i_{22} (d_1^i)^{-1} = g^{i+1}_{11} d_2^i f^i_{22} (d_1^i)^{-1} = g^{i+1}_{11} f^{i+1}_{11} d_1^i (d_1^i)^{-1} = g^{i+1}_{11} f^{i+1}_{11}. \\]\n\nWe see that $g$ can be constructed as follows. For all $i\\in \\Z$, let $g_i^{11}$ be an arbitrary left inverse of $f_i^{11}$. Set $g_{22}^i \\coloneqq (d_1^i)^{-1}g_{11}^{i+1} d_2^i$ and $g_i^{21}\\coloneqq0$. Finally, $g_{12}^i$ has to be chosen such that the second equation of \\eqref{Eq:EqEq} is satisfied. This is possible since we can first define~$g_{12}^i$ on $\\Im f^i_{22}$ because~$f^i_{22}$ injective and then extend it by $0$ to a complement.\n\\end{proof}\n\nClaim (b) of the following proposition corresponds to \\cite[Lemma~2.8]{Van2019}. Claim (c) was suggested by Prof.~Hông Vân Lê via e-mail correspondence.\n\n\\begin{Proposition}[Hodge decomposition and acyclicity of $V^\\perp$]\\label{Prop:HodgeAcyc}\nLet $(V,\\Dd)$ be a cochain complex with a symmetric cyclic structure $\\langle\\cdot,\\cdot\\rangle: V\\otimes V\\rightarrow\\R$. If $V$ is of Hodge type, then the following implications hold:\n\\begin{ClaimList}\n\\item If $\\langle \\cdot,\\cdot \\rangle$ is non-degenerate, then $\\langle \\cdot,\\cdot \\rangle^\\H$ is non-degenerate.\n\\item If $\\langle \\cdot,\\cdot\\rangle^\\H$ is non-degenerate, then $(V^\\perp,\\Dd)$ is acyclic.\n\\end{ClaimList}\nMoreover, the following reverse implication holds:\n\\begin{ClaimList}[resume]\n\\item If $V$ is of finite type and $(V^\\perp,\\Dd)$ is acyclic, then $V$ is of Hodge type.\n\\end{ClaimList}\n\\end{Proposition}\n\\begin{proof}\n\\begin{ProofList}\n\\item Let $V = \\Im \\Dd \\oplus \\Harm \\oplus C$ be a Hodge decomposition. Then $\\Im \\Dd \\oplus C \\subset \\Harm^\\perp$, and hence\n\\[ \\langle \\Dd \\eta + b + c, b' \\rangle = \\langle b,b'\\rangle\\quad\\text{for all }\\eta\\in V, c\\in C\\text{ and }b, b'\\in \\Harm. \\]\nThe claim follows easily. Notice that having a Hodge decomposition, it holds\n\\[ \\Restr{\\langle \\cdot,\\cdot\\rangle}{\\Harm\\otimes \\Harm}\\text{ non-degenerate}\\quad\\Equiv\\quad \\Im\\Dd \\oplus C=\\Harm^\\perp. \\] \n\\item Consider a Hodge decomposition as above, and let $v\\in V^\\perp \\cap \\Ker \\Dd$ be a non-zero vector. Suppose that $v\\not\\in \\Im\\Dd$. Then $[v] \\neq 0$ in $\\H(V)$, and hence there is a $b\\in \\Harm$ such that $\\langle v,b \\rangle \\neq 0$ by non-degeneracy of $\\langle\\cdot,\\cdot\\rangle^\\H$. This is a contradiction with $v\\in V^\\perp$. Therefore, it holds $V^\\perp \\cap \\Ker \\Dd = V^\\perp \\cap \\Im \\Dd$. In particular, there is an $\\eta \\in C$ such that $v = \\Dd \\eta$. Now, for any $\\eta'\\in C$, $b\\in \\Harm$ and $c\\in C$, we have using $C\\perp \\Harm\\oplus C$ and $v\\in V^\\perp$ the following:\n\\begin{align*}\n\\langle \\Dd \\eta' + b + c, \\eta \\rangle &= \\langle \\Dd \\eta',\\eta \\rangle \\\\\n&=(-1)^{1+\\eta\\eta'}\\langle\\Dd\\eta,\\eta'\\rangle\\\\\n&= (-1)^{1+\\eta\\eta'}\\langle v,\\eta'\\rangle\\\\\n&= 0.\n\\end{align*}\nTherefore, it holds $\\eta\\in V^\\perp$, and we have shown that $V^\\perp \\cap \\Im\\Dd = \\Dd V^\\perp$. The claim follows.\n\\item Because $V^\\perp \\subset V$ is an acyclic subcomplex and we work over $\\R$, there is a complementary subcomplex $Z\\subset V$; i.e., $\\Dd Z\\subset Z$ and $V = V^\\perp\\oplus Z$. This follows from Lemma~\\ref{Lem:Pom} by setting $V^\\perp = \\Im f$ and $Z=\\Ker g$. \\Add[caption={Deformation retract over $\\R$ add},noline]{Add here deformation retract somewhere.}Now, the restriction of $\\langle\\cdot,\\cdot\\rangle$ to $Z$ is non-degenerate, and Proposition~\\ref{Prop:NDegFin} provides its Hodge decomposition $Z=\\Dd Z \\oplus \\Harm \\oplus D$. Let $E\\subset V^\\perp$ be a graded vector space which is complementary to $\\Dd V^\\perp$ in $V^\\perp$; i.e., $V^\\perp = \\Dd V^\\perp \\oplus E$. It is easy to check that $V=\\Im\\Dd\\oplus\\Harm\\oplus C$ with $C\\coloneqq D \\oplus E$ is a Hodge decomposition.\n\\qedhere\n\\end{ProofList}\n\\end{proof}\n\\todo[noline,caption={PD implies Hodge without fin type}]{Does the following hold without assuming finite type? I.e. does Poincar\\'e duality imply Hodge type?}\nThe following notions were taken from \\cite{Van2019}.\n\n\\begin{Definition}[Hodge subalgebra and small subalgebra]\\label{Def:SmallSubalg}\nConsider a $\\DGA$ $(V,\\Dd,\\wedge)$ with a symmetric cyclic structure $\\langle\\cdot,\\cdot\\rangle$. Suppose that it admits a Hodge decomposition with the Hodge pair $(\\Harm,\\HtpStd)$. A \\emph{Hodge subalgebra} is a differential graded subalgebra $W\\subset V$ which satisfies\n\\[ \\Harm\\subset W \\quad\\text{and}\\quad \\HtpStd W \\subset W. \\]\nWe denote the smallest Hodge subalgebra of $V$ by $\\VansSmall(V)$ and call it the \\emph{small subalgebra}. We stress that the definition of $\\VansSmall(V)$ depends on $(\\Harm,\\HtpStd)$!\n\\end{Definition}\n%In the situation of Definition~\\ref{Def:SmallSubalg}, it holds\n%\\[ \\VansSmall(V) = \\bigcap_{\\substack{W\\subset V\\\\\\text{Hodge subalgebra}}} W. \\]\n\nThe following is a version of \\cite[Proposition~3.3]{Van2019} which generalizes to the non-simply-connected case (see (iii) of Remark~\\ref{Rem:OnHodgeSubalg} below for the comparison).\n\n\\begin{Proposition}[Description of small subalgebra]\\label{Prop:SmallDescription}\nConsider the situation of Definition~\\ref{Def:SmallSubalg}. The small subalgebra $\\VansSmall(V)$ is generated as a graded vector space by Kontsevich-Soibelman--like evaluations of rooted binary trees with $k\\ge 1$ leaves labeled with homogenous elements of~$\\Harm$, interior vertices labeled with $\\wedge$ and interior edges labeled either with~$\\StdHtp$ or with~$\\Id$.\n\\end{Proposition}\n\\begin{proof}\nWe abbreviate $\\VansSmall \\coloneqq \\VansSmall(V)$, denote the set of labeled trees by $\\Trees$ and denote the vector space generated by evaluations of elements of $\\Trees$ by $\\langle \\Trees\\rangle$.\n\nClearly, we have $\\langle \\Trees\\rangle \\subset \\VansSmall$. For ``$=$'', it suffices to check that for any $T$, $T_1$, $T_2\\in\\Trees$, it holds $\\Dd T$, $\\HtpStd T$, $T_1 \\wedge T_2 \\in \\langle\\Trees\\rangle$, i.e., that $\\langle \\Trees\\rangle$ is a Hodge subalgebra.\n\nAs for $\\Dd T$, we imagine $\\Dd$ propagating from the root to the leaves. When it encounters $L\\wedge R$, where $L$ stands for the left and $R$ for the right sub-branch, it duplicates the tree and continues propagating in $L$ and $R$, respectively (we take the sum of the two copies in the end). This is justified by the Leibnitz identity $\\Dd(L\\wedge R) = \\Dd L\\wedge R + (-1)^L L \\wedge \\Dd R$. When it encouners $\\HtpStd$, it triples the tree and either goes past $\\HtpStd$ and continues propagating, or exchanges $\\HtpStd$ for $\\Id$ and stops, or exchanges $\\HtpStd$ for $\\pi_\\Harm$ and stops. This is justified by $\\Dd \\HtpStd = -\\HtpStd \\Dd - \\Id + \\pi_\\Harm$. If it encounters $\\Id$, nothing happens and it keeps propagating. If it reaches a leaf with $h\\in \\Harm$, then the corresponding tree evaluates to $0$. We see that we alway obtain an element of $\\langle\\Trees\\rangle$.\n\nAs for $\\HtpStd T$, we have either $\\HtpStd T = 0$ if the interior edge adjacent to the root ($\\eqqcolon$ the root edge) is labeled with $\\HtpStd$, or $\\HtpStd T$ is a new tree in $\\Trees$ which arises from $T$ by replacing $\\Id$ by $\\HtpStd$ on the root edge.\n\nAs for $T_1 \\wedge T_2$, using $\\Id = \\pi_\\Harm - \\Dd \\HtpStd - \\HtpStd \\Dd$ and the Leibnitz identity, we get\n\\begin{align*}\nT_1 \\wedge T_2 &= \\pi_\\Harm(T_1 \\wedge T_2) - (\\Dd \\HtpStd)(T_1 \\wedge T_2) - (\\HtpStd \\Dd)(T_1 \\wedge T_2) \\\\\n&= \\pi_\\Harm(T_1 \\wedge T_2) - \\Dd\\bigl(\\HtpStd(T_1 \\wedge T_2)\\bigr) - \\HtpStd(\\Dd T_1 \\wedge T_2)\n- (-1)^{T_1} \\HtpStd(T_1 \\wedge \\Dd T_2).\n\\end{align*}\nWe see that $T_1\\wedge T_2 \\in \\langle \\Trees\\rangle$.\n\\end{proof}\n\n\\begin{Remark}[On Hodge subalgebra and small subalgebra]\\phantomsection\\label{Rem:OnHodgeSubalg}\n\\begin{RemarkList}\n\\item Any Hodge subalgebra~$W$ inherits the Hodge decomposition\n\\begin{equation}\\label{Eq:InducedHodgeDecomp}\nW = \\Harm \\oplus \\Dd W \\oplus \\HtpStd W\n\\end{equation}\nwith the Hodge pair $(\\Harm,\\Restr{\\HtpStd}{W})$.\n\\item We will be in the situation of Definition~\\ref{Def:SmallSubalg} and use the notation of the proof of Proposition~\\ref{Prop:SmallDescription}. In addition, we suppose that $V$ is non-negatively graded. Having established $\\VansSmall = \\langle \\Trees \\rangle$, consider the Hodge decomposition \\eqref{Eq:InducedHodgeDecomp} for $W = \\VansSmall$. Let $\\widebar{\\VansSmall} = \\bigoplus_{k\\ge 1} \\VansSmall^k$ denote the reduced part of $\\VansSmall$, and let $\\langle\\widebar{\\VansSmall} \\wedge \\widebar{\\VansSmall}\\rangle$ denote the graded vector space generated by products $v_1 \\wedge v_2$ for $v_1$, $v_2\\in \\widebar{\\VansSmall}$. We have\n\\begin{align*}\n\\HtpStd\\langle\\Trees\\rangle &= \\bigl\\langle\\{ T\\in \\Trees \\text{ with }\\HtpStd\\text{ on the root edge}\\}\\bigr\\rangle \\\\\n&= \\HtpStd\\langle\\widebar{\\VansSmall} \\wedge \\widebar{\\VansSmall}\\rangle\n\\end{align*}\nand\n\\begin{align*}\n \\Dd\\langle\\Trees\\rangle &= \\Dd (\\pi_\\Harm - \\Dd \\HtpStd - \\HtpStd\\Dd)\\langle\\Trees\\rangle \\\\\n &= \\Dd \\HtpStd \\Dd \\langle\\Trees\\rangle \\\\\n &\\subset \\Dd \\HtpStd \\langle\\Trees\\rangle \\\\\n &\\subset \\Dd \\HtpStd\\langle\\widebar{\\VansSmall}\\wedge\\widebar{\\VansSmall}\\rangle.\n\\end{align*}\nIt holds even $\\Dd\\langle\\Trees\\rangle = \\Dd\\HtpStd\\langle\\widebar{\\VansSmall}\\wedge\\widebar{\\VansSmall}\\rangle$ due to \\eqref{Eq:InducedHodgeDecomp}. We can now write \\eqref{Eq:InducedHodgeDecomp} as \n\\begin{equation}\\label{Eq:VansFormula}\n\\VansSmall^k = \\Harm^k \\oplus \\Dd \\HtpStd \\langle\\widebar{\\VansSmall}\\wedge\\widebar{\\VansSmall}\\rangle^k \\oplus \\HtpStd \\langle\\widebar{\\VansSmall}\\wedge\\widebar{\\VansSmall}\\rangle^{k+1}.\n\\end{equation}\nIf $\\H^1 = 0$, this agrees with the formula from \\cite[Proposition~3.3]{Van2019}. In this case, it holds $\\VansSmall^1 = 0$, and hence $\\langle\\widebar{\\VansSmall}\\wedge\\widebar{\\VansSmall}\\rangle^{k+1}$ depends only on $\\VansSmall^i$ for $i<k$. Therefore, we can compute~$\\VansSmall^k$ from \\eqref{Eq:VansFormula} inductively starting with $\\VansSmall^0 = \\langle 1\\rangle$.\n\\item The previous remark implies the following: Let $(V,\\Dd,\\wedge)$ be a non-negatively graded $\\DGA$ with cyclic structure $\\langle\\cdot,\\cdot\\rangle$ of Hodge type. Suppose that $\\H^1(V)=0$. If $\\H(V)$ is of finite type, then so is $\\VansSmall(V)$.\n%\\item The subalgebra $\\VansSmall(V)$ ``resolves'' $V$; i.e., there is a $\\DGA$-quasi-isomorphism $\\VansSmall(V) \\xhookrightarrow{} V$ (the inclusion). Consider the smallest subalgebra $\\langle\\Harm\\rangle^\\wedge$ containing~$\\Harm$; similarly as $\\VansSmall(V)$, it is generated as graded vector space by evaluations of rooted binary trees with $\\Id$ on interior edges. The $\\DGA$ $\\langle\\Harm\\rangle^\\wedge$ also ``resolves'' $V$.\n\\item The advantage of $\\VansSmall(V)$ is that we have the diagram of pairing preserving $\\DGA$-quasi-isomorphisms\n\\[\\begin{tikzcd}\n V & \\VansSmall(V)\\arrow[hook']{l} \\arrow[two heads]{r} & \\VansQuotient(\\VansSmall(V)).\n\\end{tikzcd}\\]\nMoreover, in the case of (iii), the non-degenerate quotient is finite-dimensional, and hence a Poincar\\'e duality model of $V$ (see the next section).\n\\item Notice that if there is a quasi-isomorphism $f:\\H(V)\\rightarrow V$, then $\\VansSmall(V) = V$ for any Hodge decomposition with harmonic subspace $\\im f$.  \\qedhere\n\\end{RemarkList}\n\\end{Remark}\n\n\\begin{Proposition}[Properties of $\\VansSmall$ and $\\VansQuotient$]\\label{Prop:PropPropertiessd}\nLet $(V,\\Dd,\\wedge)$ be a $\\DGA$ with a symmetric cyclic structure $\\langle\\cdot,\\cdot\\rangle$. Suppose that it admits a Hodge decomposition with Hodge pair $(\\Harm,\\HtpStd)$. Then $\\VansSmall(V)$ and $\\VansQuotient(V)$ admit Hodge decompositions with the Hodge pairs $(\\Harm,\\HtpStd^\\VansSmall\\coloneqq\\Restr{\\HtpStd}{\\VansSmall(V)})$ and $(\\pi^\\VansQuotient(\\Harm),\\HtpStd^\\VansQuotient)$, respectively, where $\\pi^\\VansQuotient: V \\rightarrow \\VansQuotient(V)$ is the canonical projection and $\\HtpStd^\\VansQuotient$ the unique map on $\\VansQuotient(V)$ satisfying $\\HtpStd^\\VansQuotient \\circ \\pi^\\VansQuotient=\\pi^\\VansQuotient\\circ \\HtpStd$. Furthermore, with respect to the induced Hodge decompositions, we have\n\\begin{equation}\\label{Eq:QSRelations}\n\\VansSmall(\\VansSmall(V)) = \\VansSmall(V), \\quad \\VansQuotient(\\VansQuotient(V)) = \\VansQuotient(V)\\quad\\text{and}\\quad \\VansSmall(\\VansQuotient(\\VansSmall(V))) = \\VansQuotient(\\VansSmall(V)).\\end{equation}\n\\end{Proposition}\n\\begin{proof}\nThe fact that $\\VansSmall\\coloneqq\\VansSmall(V)$ admits a Hodge decomposition with Hodge pair $(\\Harm,\\HtpStd^\\VansSmall)$ was stated in (i) of Remark~\\ref{Rem:OnHodgeSubalg} and is easy to check.\n\nWe prove that $\\VansQuotient\\coloneqq \\VansQuotient(V)$ has a Hodge decomposition with Hodge pair $(\\pi^\\VansQuotient(\\Harm),\\HtpStd^\\VansQuotient)$. Because $\\pi^\\VansQuotient$ is a quasi-isomorphism, $\\pi^\\VansQuotient(\\Harm)$ is a harmonic subspace of $\\VansQuotient$, and we have $\\Ker \\Dd^\\VansQuotient = \\pi^\\VansQuotient(\\Harm)\\oplus \\Im \\Dd^\\VansQuotient$. Let $c\\in C$ with $\\Dd c \\in V^\\perp$ such that $\\pi^\\VansQuotient(c)\\in\\Ker\\Dd^\\VansQuotient \\cap \\pi^\\VansQuotient(C)$. From the cyclicity of $\\langle\\cdot,\\cdot\\rangle$ with respect to $\\Dd$ and from $C\\perp\\Harm\\oplus C$, it follows that $c\\in V^\\perp$, and thus $\\pi^\\VansQuotient(c)=0$. Together with surjectivity of $\\pi^\\VansQuotient$ this implies that $\\VansQuotient = \\ker \\Dd^\\VansQuotient \\oplus \\pi^\\VansQuotient(C)$. From $\\langle \\pi^\\VansQuotient(\\cdot),\\pi^\\VansQuotient(\\cdot)\\rangle^\\VansQuotient$, we see that $\\pi^\\VansQuotient(C) \\perp \\pi^\\VansQuotient(\\Harm) \\oplus \\pi^\\VansQuotient(C)$. Therefore, $\\VansQuotient = \\pi^\\VansQuotient(\\Harm)\\oplus\\Im\\Dd^\\VansQuotient\\oplus\\pi^\\VansQuotient(C)$ is a Hodge decomposition, and it is easy to see that its standard Hodge homotopy $\\HtpStd^\\VansQuotient$ satisfies $\\HtpStd^\\VansQuotient \\circ \\pi^\\VansQuotient=\\pi^\\VansQuotient\\circ \\HtpStd$. This defines $\\HtpStd^\\VansQuotient$ uniquely because $\\pi^\\VansQuotient$ is surjective.\n\nAs for the relations \\eqref{Eq:QSRelations}, the first two are clear. The third can be seen as follows. Since $\\pi^\\VansQuotient: V \\rightarrow \\VansQuotient$ is a $\\DGA$-morphism mapping the harmonic subspaces isomorphically onto each other and commuting with $\\Dd$ and $\\HtpStd$, the assignments $Y\\subset V \\mapsto \\pi^\\VansQuotient(Y)\\subset \\VansQuotient$ and $Z\\subset \\VansQuotient \\mapsto (\\pi^{\\VansQuotient})^{-1}(Z)\\subset V$ preserve Hodge subalgebras. Therefore, if $Z\\subset \\VansQuotient(\\VansSmall)$ is a Hodge subalgebra, then $(\\pi^\\VansQuotient)^{-1}(Z)\\subset\\VansSmall$ is a Hodge subalgebra. It holds even $(\\pi^\\VansQuotient)^{-1}(Z)=\\VansSmall$ by minimality of $\\VansSmall$, and hence $Z=\\VansQuotient(\\VansSmall)$ by surjectivity of~$\\pi^\\VansQuotient$.  \n\\end{proof}\n\n%In the ideal world, the isomorphism class of $\\VansQuotient(\\VansSmall(V))$ would not depend on the chosen Hodge decomposition of $V$. We collect some lemmas which shall point us to a uniqueness statement for $\\VansQuotient(\\VansSmall(V))$ below.\n\n%Notice that solely the fact that $\\langle\\cdot,\\cdot\\rangle$ is non-degenerate on $V$ does not imply that $\\VansSmall(V) \\simeq V$. A counterexample is $V = \\DR(M)$, where $M$ is a compact oriented manifold with $\\HDR^1(M) = 0$; indeed, by (iii) of Remark~\\ref{Rem:OnHodgeSubalg}, $\\VansSmall(\\DR(M))$ is of finite type because $\\HDR(M)$ is, but $\\DR(M)$ is not of finite type.\n\nA natural question is, how does $\\VansQuotient(\\VansSmall(V))$ depend on the chosen Hodge pair and how does it behave under quasi-isomorphisms? The following lemmas might be useful.\n\n\\begin{Lemma}[Kernel of pairing-preserving morphism]\\label{Lem:PomLemma}\nLet $V_1$ and $V_2$ be vector spaces with symmetric bilinear forms $\\langle \\cdot,\\cdot \\rangle_1: V_1 \\otimes V_1 \\rightarrow \\R$ and $\\langle \\cdot,\\cdot\\rangle_2: V_2\\otimes V_2 \\rightarrow \\R$, respectively. Let $f: V_1 \\rightarrow V_2$ be a linear map such that\n\\begin{equation}\\label{Eq:Isometryyy}\n\\langle v_1, v_2 \\rangle_1 = \\langle f(v_1), f(v_2) \\rangle_2 \\quad \\text{for all }v_1, v_2 \\in V_1.\n\\end{equation}\nThen it holds \n\\[ \\Ker f \\subset V_1^\\perp\\quad\\text{and}\\quad f(V_1^\\perp)\\subset f(V_1)^\\perp. \\]\nIn particular, the following statements are true:\n\\begin{ClaimList}\n\\item If $\\langle\\cdot,\\cdot\\rangle_1$ is non-degenerate, then $f$ is injective.\n\\item If $\\langle\\cdot,\\cdot\\rangle_2$ is non-degenerate and $f$ is surjective, then $\\Ker f = V_1^\\perp$.\n\\end{ClaimList}\n\\end{Lemma}\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{Lemma}[Injectivity on domain with non-degenerate orientation]\\label{Lem:AutomaticInjectivity}\nLet $(V_1,\\Dd_1,\\wedge_1)$ be a non-negatively graded commutative $\\DGA$ with an orientation $\\Or_1$ in degree $n$ such that the induced cyclic structure is non-degenerate. Let $(V_2,\\Dd_2,\\wedge_2)$ be any $\\DGA$, and let $f: V_1 \\rightarrow V_2$ be a morphism of $\\DGA$'s. Then injectivity of $f_*: \\H^n(V_1) \\rightarrow \\H^n(V_2)$ implies injectivity of $f: V_1 \\rightarrow V_2$.\n\\end{Lemma}\n\\begin{proof}\nFirstly, injectivity of a homogenous map is equivalent to degree-wise injectivity. Secondly, because $V_1$ is non-negatively graded and the cyclic structure of degree $n$ is non-degenerate, we have $V_1 = V_1^0\\oplus\\dotsb\\oplus V_1^n$. Now, suppose that $v\\in V_1^k$ for some $k=0$,~$\\dotsc$, $n$ satisfies $f(v) = 0$. For any $w\\in V^{n-k}$, the product $v\\wedge w$ lies in $V^n$, and thus $\\Dd(v\\wedge w)=0$. We compute\n\\begin{align*}\nf_* [v\\wedge w] = [f(v\\wedge w)] = [f(v)\\wedge f(w)] = 0,\n\\end{align*}\nand hence $v\\wedge w = \\Dd \\eta$ for some $\\eta \\in V_1^{n-1}$ by injectivity of $f_*$. Consequently, we have\n\\begin{align*}\n\\Or_1(v\\wedge w) &= \\Or_1(\\Dd \\eta) =0,\n\\end{align*}\nand hence $v = 0$ by non-degeneracy of $\\Or_1$.\n\\end{proof}\n\n\\begin{Lemma}[Small subalgebra of cyclic $\\DGA$ and quasi-iso.]\\label{Eq:LemSmallSub}\nLet $(V_1,\\Dd_1,\\wedge_1,\\langle\\cdot,\\cdot\\rangle_1)$ and~$(V_2,\\Dd_2,\\wedge_2,\\langle\\cdot,\\cdot\\rangle_2)$ be non-negatively graded unital commutative $\\DGA$'s of finite type with non-degenerate cyclic structures of degree $n$ (hence finite-dimensional). Let $f: V_1 \\rightarrow V_2$ be a $\\DGA$-morphism such that $f_*: (\\H(V_1),\\Or_1^\\H)\\rightarrow (\\H(V_2),\\Or_2^\\H)$ is an isomorphism. Then a Hodge decomposition of $V_1$ with Hodge pair $(\\Harm_1,\\HtpStd^1)$ induces a Hodge decomposition of~$V_2$ with Hodge pair $(f(\\Harm_1),\\HtpStd^2)$, where~$\\HtpStd^2$ satisfies $\\HtpStd^2 \\circ f = f\\circ \\HtpStd^1$. Consequently,~$f$ induces an isomorphism $\\VansSmall(V_1) \\simeq \\VansSmall(V_2)$.\n\\end{Lemma}\n\\begin{proof}\nBecause $f_*$ preserves orientation and it holds $V_1^{n+1} = 0 = V_2^{n+1}$, Proposition~\\ref{Prop:OrOnHomG} implies that $f$ preserves cyclic structure and hence is injective by Lemma~\\ref{Lem:PomLemma}. Let $V_1 = \\Harm_1 \\oplus \\Im \\Dd_1 \\oplus C_1$ be a Hodge decomposition. From the injectivity of $f$, it follows that\n\\[ f(V_1) = f(\\Harm_1) \\oplus \\Dd f(V_1) \\oplus f(C_1) \\]\nand that the restriction of $\\langle\\cdot,\\cdot\\rangle_2$ to $f(V_1)\\otimes f(V_1)$ is non-degenerate. Because $V_1$ is of finite type, $f(V_1)$ is of finite type, and so non-degeneracy implies Poincar\\'e duality $f(V_1)^{\\GD}\\simeq f(V_1)$. It follows that\n\\[ V_2 = f(V_1) \\oplus f(V_1)^\\perp.\\]\nCyclicity of $\\Dd_2$ with respect to $\\langle\\cdot,\\cdot\\rangle_2$ implies that $f(V_1)^\\perp\\subset V_2$ is a subcomplex. Because~$f$ is a quasi-isomorphism, we have $\\H(V_1)\\simeq \\H(f(V_1))\\simeq \\H(V_2)$; because the homology is additive, we have $\\H(V_2)\\simeq\\H(f(V_1))\\oplus\\H(f(V_1)^\\perp)\\simeq \\H(V_2)\\oplus\\H(f(V_1)^\\perp)$; finally, because $\\H(V_2)$ is of finite type, we have $\\H(f(V_1)^\\perp) = 0$. Because $V_2 = f(V_1) \\oplus f(V_1)^\\perp$ and $\\langle\\cdot,\\cdot\\rangle_2$ is non-degenerate, its restriction to $f(V_1)^\\perp$ is non-degenerate too. As $V_2$ and hence $f(V_1)^\\perp$ is of finite type, Proposition~\\ref{Prop:NDegFin} gives a Hodge decomposition $f(V_1)^\\perp = \\Dd f(V_1)^\\perp \\oplus C_2'$. It is easy to check that \n\\[ V_2 = f(\\Harm_1)\\oplus\\underbrace{\\bigl(\\Dd f(V_1) \\oplus \\Dd f(V_1)^\\perp)}_{\\displaystyle=\\Im\\Dd_2}\\oplus(\\underbrace{f(C_1)\\oplus C_2'}_{\\displaystyle\\eqqcolon C_2})\\]\nis a Hodge decomposition of $V_2$. The corresponding standard Hodge homotopy clearly satisfies $\\HtpStd^2 \\circ f = f\\circ \\HtpStd^1$, and it holds $\\HtpStd^2(f(V_1)) \\subset f(V_1)$, so that $f(V_1)$ is a Hodge subalgebra. By injectivity, it follows that $\\VansSmall(V_1) \\simeq \\VansSmall(V_2)$.\n\\end{proof}\n%\n%Application of this theory is possible since .\n%where the other arrows are the canonical inclusions and projections. How to get it?\n%\n%\\end{proof}\n%\n%\\begin{Lemma}\n%A small algebra is an image of a Sullivan's model. I.e., whenever $A$ is small and we have a quasi-isomorphism from the minimal model into $A$, then it has to be surjective --- this would be cool.\n%\n%Every orientation preserving quasi-isomorphism inside a small algebra has to be surjective. Then I have it!\n%\\end{Lemma}\n%\n%\n%\\begin{Example}\n%\\begin{ExampleList}\n%\\item The de Rham complex $\\DR(M)$ of a closed oriented manifold~$M$ is non-degenerate, of Hodge type and does not satisfy Poincar\\'e duality. Proposition~\\ref{Prop:HodgePModel} \n%applies and gives a weakly equivalent Poincar\\'e model.\n%\\item Example of finite-dimensional and not of Hodge type (Hence necessary degenerate). \n%\\item Example of infinite-dimensional non-degenerate and not of Hodge type. Maybe even Poincar\\'e duality?\n%\\item An example where two small subalgebras are not isomorphic. They do not even have to homotopy equivalent because image of homotopy equivalent morphisms do not have to.\n%\\end{ExampleList}\n%\\end{Example}\n%\n%\\begin{Proposition}[Small subalgebra in geometrically formal case]\\label{Prop:SmalGeomForm}\n%Let $(V,\\Dd,\\wedge)$ be a non-negatively graded unital commutative $\\DGA$ with a cyclic structure $\\langle\\cdot,\\cdot\\rangle$ of Hodge type such that the induced cyclic structure on $\\H(V)$ is non-degenerate. Suppose that there is $\\DGA$-quasi-isomorphism $f: \\H(V) \\rightarrow V$ preserving orientation on homology. Then there is a Hodge decomposition of $V$ with $\\Harm = \\im f$ and $f$ induces an isomorphism $\\H(V) \\simeq \\VansQuotient(\\VansSmall(V))$.\n%\\end{Proposition}\n%\n%\\begin{proof}\n%By Remark~\\ref{Rem:RemarkHarm}, there is a Hodge decomposition with $\\Harm = \\Im f$. Therefore, we can restrict the codomain of $f$ and obtain the $\\DGA$-quasi-isomorphism $\\tilde{f}: \\H(V) \\rightarrow \\VansSmall(V) \\rightarrow \\VansQuotient(\\VansSmall(V))$ which preserves orientation on homology. Lemma~\\ref{Eq:LemSmallSub} implies that there is a Hodge decomposition of $V$ such that $\\tilde{f}$ induces an isomorphism $\\VansSmall(\\H(V))\\simeq \\VansSmall(\\VansQuotient(\\VansSmall(V)))$. However, $\\VansSmall(\\H(V))=\\H(V)$ and $\\VansSmall(\\VansQuotient(\\VansSmall(V)))=\\VansQuotient(\\VansSmall(V))$ by Proposition~\\ref{Prop:PropPropertiessd}.\n%\\end{proof}\n\nSince $\\VansSmall=\\VansSmall(V)$ is ``small'', a question whether it can be fit inside the image of a Sullivan's minimal model arose. This would imply, under some additional assumptions, that for any two Hodge decompositions of $V$, the non-degenerate quotients $\\VansQuotient_1$, resp.~$\\VansQuotient_2$ of the corresponding small subalgebras $\\VansSmall_1$, resp.~$\\VansSmall_2$ would be isomorphic as Poincar\\'e duality algebras. Let us sketch the idea of this construction assuming that $f_1: \\Lambda U_1 \\twoheadrightarrow \\VansSmall_1$ and $f_2: \\Lambda U_2 \\twoheadrightarrow \\VansSmall_2$ are surjective Sullivan's minimal models. Uniqueness from \\cite[Theorem~2.24]{Felix2008} gives an isomorphism $\\Lambda U \\coloneqq \\Lambda U_1 \\simeq \\Lambda U_2$ such that the following diagram commutes up to homotopy of $\\DGA$'s:\n\\begin{equation}\\label{Eq:HpyCommutDiag}\n\\begin{tikzcd}\n& & \\VansSmall_1 \\arrow[hook]{ld}\\arrow{r} & \\VansQuotient_1 \\\\\n\\Lambda U \\arrow[bend left,two heads]{rru}{f_1}\\arrow[bend right,two heads]{rrd}[below]{f_2}  &  V & &  \\\\\n& & \\VansSmall_2 \\arrow[hook]{lu}\\arrow{r}& \\VansQuotient_2.\n\\end{tikzcd}\n\\end{equation}\nNow, $\\Lambda U \\xrightarrow{f_1} \\VansSmall_1 \\xhookrightarrow{} V$ and $\\Lambda U \\xrightarrow{f_2} \\VansSmall_2 \\xhookrightarrow{} V$ induce the same isomorphism on homology; this can be used to pullback the orientation~$\\Or^\\H$ on $\\H(V)$ to an orientation $\\tilde{\\Or}$ on $\\H(\\Lambda U)$, so that all maps in \\eqref{Eq:HpyCommutDiag} will preserve the orientation on homology. Under the assumptions $\\Dd V^n = 0$ and $\\Dd (\\Lambda U)^n = 0$, Proposition~\\ref{Prop:OrOnHomG} applies, and we obtain a cyclic structure $\\langle\\cdot,\\cdot\\rangle^{\\Lambda U}$ on $\\Lambda U$ which is preserved by both $f_1$ and~$f_2$ on the chain level. We denote $f_i^\\VansQuotient\\coloneqq \\pi^{\\VansQuotient}_i \\circ f_i$ and write down the following diagram with pairing-preserving $\\DGA$-quasi-isomorphisms:\n\\begin{equation}\\label{Eq:Diagram}\n\\begin{tikzcd}\n& \\arrow[two heads,swap]{ld}{f_1^\\VansQuotient} \\bigl(\\Lambda U,\\langle\\cdot,\\cdot\\rangle^{\\Lambda U}\\bigr)\\arrow[two heads]{rd}{f_2^\\VansQuotient}& \\\\\n\\bigl(\\VansQuotient_1,\\langle\\cdot,\\cdot\\rangle^{\\VansQuotient}_1\\bigr) & & \\bigl(\\VansQuotient_2,\\langle\\cdot,\\cdot\\rangle^{\\VansQuotient}_2 \\bigr).\n\\end{tikzcd}\n\\end{equation}\nClaim (b) of Lemma~\\ref{Lem:PomLemma} implies that $\\ker f_1^\\VansQuotient = \\ker f_2^\\VansQuotient = (\\Lambda U)^\\perp$, and hence\n\\[ \\VansQuotient_1 \\simeq  \\Lambda U / (\\Lambda U)^\\perp\\simeq \\VansQuotient_2. \\]\nUnfortunately, the next two examples show that one can not, in general, expect~$\\VansSmall_1$ and~$\\VansSmall_2$, or even $\\VansQuotient_1$ and $\\VansQuotient_2$ to be isomorphic and $\\VansSmall$ to fit inside the image of the minimal model.\\footnote{Note that it is always possible to construct a surjective (non-minimal) Sullivan model $f: \\Lambda U \\twoheadrightarrow V$ by taking the minimal Sullivan model and inductively adding generators $\\xi_i$ and $\\mu_i$ with $\\Dd \\mu_i = 0$ and $\\Dd \\xi_i = \\mu_i$ (the minimality condition on a Sullivan's algebra would require $\\Dd \\xi_i$ to be decomposable), and mapping them to $v\\in V$ and $\\Dd v$, respectively. Nevertheless, the uniqueness property of non-minimal Sullivan models is much weaker, see \\cite[Lemma~2.20]{Felix2008}.}\n\n\\begin{Example}[Small algebras are, in general, not unique and not contained in images of Sullivan minimal models]\\label{Ex:NonUniqueSmall}\nConsider $M=\\CP^2$, and let $\\Kaehler$ be the Fubini--Study form on~$M$.\nFor $\\alpha\\in\\DR^1(M)$, set $\\Kaehler_\\alpha \\coloneqq \\Kaehler + \\Dd\\alpha$.\nThen $K_\\alpha \\wedge K_\\alpha = K \\wedge K + \\Dd(2\\alpha\\wedge K + \\alpha \\wedge \\Dd\\alpha)$.\nWe can choose $\\alpha$ such that $\\Dd(2\\alpha\\wedge K + \\alpha\\wedge\\Dd\\alpha)\\neq 0$.\nConsider the Riemannian Hodge decomposition of $\\DR(M)$ with $\\Harm = \\langle 1, \\Kaehler, \\Kaehler\\wedge \\Kaehler\\rangle$.\nAccording to Remark~\\ref{Rem:RemarkHarm}, there is also a ``twisted'' Hodge decomposition with the harmonic subspace $\\Harm_\\alpha \\coloneqq \\langle 1, \\Kaehler_\\alpha, \\Kaehler \\wedge \\Kaehler\\rangle$.\n\nThe small subalgebra $\\VansSmall$ for the Riemann Hodge decomposition is $\\VansSmall=\\langle 1, \\Kaehler, \\Kaehler\\wedge\\Kaehler\\rangle$.\nThe small subalgebra $\\VansSmall_\\alpha$ for the twisted Hodge decomposition must contain $1$, $\\Kaehler_\\alpha$ and both $\\Kaehler_\\alpha\\wedge\\Kaehler_\\alpha$ and $\\Kaehler\\wedge\\Kaehler$ (we require $\\Harm_\\alpha\\subset\\VansSmall_\\alpha$ by definition).\nTherefore, it contains \n\\[\n\\Kaehler_\\alpha \\wedge \\Kaehler_\\alpha - \\Kaehler\\wedge\\Kaehler = \\Dd(2\\alpha\\wedge K + \\alpha\\wedge\\Dd\\alpha)\n\\]\nand also\n\\[\n\\StdPrpg^\\alpha\\Dd(2\\alpha\\wedge K + \\alpha\\wedge\\Dd\\alpha)=\\pi_{C_\\alpha}(2\\alpha\\wedge K + \\alpha\\wedge\\Dd\\alpha).\n\\]\nProposition~\\ref{Prop:SmallDescription} asserts that these vectors, together with $1$ and $\\Kaehler_\\alpha$, generate $\\VansSmall_\\alpha$ as a graded vector space.\nClearly, $\\VansSmall_\\alpha$ is not isomorphic to $\\VansSmall$ for generic $\\alpha$, but \n\\[\n\\VansQuotient(\\VansSmall_\\alpha)=\\langle1,\\Kaehler_\\alpha,\\Kaehler_\\alpha\\wedge\\Kaehler_\\alpha\\rangle\\simeq \\langle 1, \\Kaehler, \\Kaehler\\wedge\\Kaehler\\rangle= \\VansQuotient(\\VansSmall).\n\\]\nIn fact, the previous argument works in general and implies that for $\\CP^2$, the non-degenerate quotients of two small subalgebras are isomorphic as Poincar\\'e duality algebras (this does not hold for any $M$, see Example~\\ref{Ex:SUsix}).\n\nThe Sullivan minimal model of $M$ is the free $\\DGA$ $\\Model \\coloneqq \\Lambda(\\eta,\\mu)$ with $\\Abs{\\eta}=2$, $\\Abs{\\mu}=5$, $\\Dd\\eta = 0$ and $\\Dd\\mu=\\eta\\wedge\\eta$.\nA $\\DGA$-quasi-isomorphism $f: \\Model\\rightarrow\\DR(M)$ is specified by its values on~$\\eta$ and~$\\mu$; for example, $f(\\eta)\\coloneqq\\Kaehler$ and $f(\\mu)\\coloneqq 0$.\nWe see that neither $\\VansSmall_\\alpha$ nor $\\Harm_\\alpha$ can lie in $\\im f$ because $\\dim (\\im f)^{4}=1$ for any $f$.\n\\end{Example}\n\n\\begin{Example}[Non-degenerate quotients of small subalgebras for different Hodge decompositions are, in general, not isomorphic]\\label{Ex:SUsix}\nConsider $M=\\mathrm{SU}(6)$.\nIt is a compact simply-connected Lie group of dimension~$35$ ($=n^2 - 1$ for $n=6$) whose cohomology ring is freely generated by single elements in degrees  $3$, $5$,~$\\dotsc$,~$11$; see \\cite[Corollary~3.11]{Mimura1991}.\nThere is a biinvariant Riemannian metric and there are biinvariant differential forms $x_3$, $x_5$,~$\\dotsc$, $x_{11}$ in the corresponding degrees such that \n\\[\n\\Harm \\coloneqq \\Lambda(x_3, \\dotsc, x_{11})\\subset \\DR(M)\n\\]\nis the algebra of harmonic forms, see \\cite[Chapter~1]{Felix2008}.\n\nFor $\\eta_6\\in \\DR^6(M)$ and $\\eta_8\\in\\DR^8(M)$, which are going to be specified later, set\n\\[\n\\tilde{x}_7 \\coloneqq x_7 + \\Dd \\eta_6\\quad\\text{and}\\quad\\tilde{x}_9 \\coloneqq x_9 + \\Dd \\eta_8,\n\\]\nand let $\\Harm'$ denote the graded vector space obtained from $\\Harm$ by replacing the vectors $x_{7}$ and $x_{9}$ with $\\tilde{x}_7$ and $\\tilde{x}_9$, respectively.\nWe emphasize that we are replacing just the vectors, not the products; e.g., $x_7\\wedge x_9$ is an element of $\\Harm'$ but $\\tilde{x}_7\\wedge \\tilde{x}_9$ might not be.\nLet $\\VansSmall = \\Harm$ be the small subalgebra corresponding to the Riemannian Hodge decomposition, and let~$\\VansSmall'$ be the small subalgebra corresponding to a Hodge decomposition based on~$\\Harm'$ (such always exists by Remark~\\ref{Rem:RemarkHarm}).\nThe following elements in degrees $15$, resp.~$20$ must be contained in $\\VansSmall'$:\n\\begin{align*}\ny&\\coloneqq\\StdPrpg'(\\tilde{x}_7 \\wedge x_9 -x_7 \\wedge x_9)\\\\\n &=\\StdPrpg'\\Dd(\\eta_6 \\wedge x_9),\\\\\nz&\\coloneqq\\tilde{x}_9 \\wedge x_{11} - x_9 \\wedge x_{11}\\\\\n &=\\Dd(\\eta_8 \\wedge x_{11}).\n\\end{align*}\nUsing Stokes theorem and $\\Dd\\circ\\StdPrpg' = \\pi_{\\Im \\Dd}$, we get\n\\begin{align*}\n\\langle y,z\\rangle & = \\pm \\int_{M} \\StdPrpg'\\Dd(\\eta_6 \\wedge x_9) \\wedge\\Dd(\\eta_8 \\wedge x_{11})\\\\\n&= \\pm \\int_{M} \\Dd\\eta_6\\wedge \\eta_8 \\wedge x_9 \\wedge x_{11}.\n\\end{align*}\nWe claim that the integral can be made non-zero by a choice of $\\eta_6$ and $\\eta_8$.\nIndeed, because $x_9\\wedge x_{11}$ generates non-zero homology, there is an $m\\in M$ such that $x_9(m)\\wedge x_{11}(m)\\neq 0$.\nPick local coordinates $(x^i)$ centered at $m$, and let $\\alpha^I\\Diff{x}^I$ be a non-zero coefficient in $x_9(m)\\wedge x_{11}(m)$. Consider the complement $J = I^C$ and decompose $J= J_1 \\cup J_2$ into two parts with $\\Abs{J}_1 = 7$ and $\\Abs{J}_2 = 8$.\nFor some $0\\neq c\\in\\R$, set locally\n\\[\n\\eta_6 \\coloneqq ((x^{J_{11}}+c)\\Diff{x}^{J_1\\backslash\\{J_{11}\\}})\\quad\\text{and}\\quad\\eta_8=\\Diff{x}^{J_2},\n\\]\nand extend them to the whole of $M$ by multiplying with a bump function which is constant non-zero in a neighborhood of $m$.\nWe have achieved that the integrand $\\omega \\coloneqq \\Dd\\eta_6\\wedge \\eta_8 \\wedge x_9 \\wedge x_{11}$ is non-zero around $m$.\nBecause the intersection pairing is non-degenerate and because $\\omega \\neq 0$, there is a function $f\\in C^\\infty(M)$ such that $\\int_M f\\omega \\neq 0$.\nWe can now just rescale $\\eta_8$ by $f$.\n\nWe have shown that $z$ induces a non-zero element $\\pi_{\\VansQuotient}'(z)\\in \\VansQuotient(\\VansSmall')^{20}$, where $\\pi_{\\VansQuotient}': \\VansSmall' \\rightarrow \\VansSmall'/{\\VansSmall'}^\\perp$ is the canonical projection.\nNow, $\\pi_{\\VansQuotient}'$ is a $\\DGA$-morphism, and hence $\\pi_{\\VansQuotient}'(z)$ is exact.\nBecause $\\VansSmall'$ is of Hodge type, $\\pi_{\\VansQuotient}'$ is also a quasi-isomorphism, and hence $\\pi_{\\VansQuotient}'(x_{9}\\wedge x_{11})$ generates non-trivial homology.\nIt follows that $\\pi_{\\VansQuotient}'(z)$ is not a multiple of $\\pi_{\\VansQuotient}'(x_9\\wedge x_{11})$, and thus $\\dim \\VansQuotient(\\VansSmall')^{20} \\ge 2$.\nHowever, we have $\\VansQuotient(\\VansSmall)^{20} = \\Harm^{20} = \\langle x_9\\wedge x_{11} \\rangle$.\nThis shows that $\\VansQuotient(\\VansSmall)$ and $\\VansQuotient(\\VansSmall')$ can not be isomorphic as vector spaces.\n\\end{Example}\n\n%The following conjecture is based on a remark of Prof.~Hông Vân Lê, communicated in an e-mail correspondence, that ``the small subalgebra is the image of a minimal model''.\n\n%\\begin{Conjecture}[Hodge-Sullivan minimal model]\\label{Conj:HodgeSullMin}\n%Let $(V,\\Dd,\\wedge)$ be a non-negatively graded unital commutative $\\DGA$ with a cyclic structure $\\langle\\cdot,\\cdot\\rangle$ of Hodge type. Suppose that~$V$ is of finite type, $\\H^0(V) = \\R$ and $\\H^1(V) = 0$. Then for any Hodge decomposition of~$V$, there is a Sullivan minimal model $\\Lambda U \\rightarrow V$ (see \\cite{Felix2008} or Remark~\\ref{Rem:Models} later) whose image contains a Hodge subalgebra. \n%\\end{Conjecture}\n%\\begin{proof}[Idea of proof] The author tried to modify the well-known inductive construction of $\\Lambda U \\rightarrow V$ to achieve that its image is $\\HtpStd$-invariant; he observed that vanishing of higher homology groups might be required. In any case, it sufficient (and necessary) to prove that the image contains at least the trees from Proposition~\\ref{Prop:SmallDescription}.\n%\\end{proof}\n%If Conjecture~\\ref{Conj:HodgeSullMin} is true, then we have the following:\n%\\begin{Conjecture}[Uniqueness of non-degenerate small subalgebra]\\label{Conj:UnieqSmal}\n%Let $(V,\\Dd,\\wedge)$ be a non-negatively graded unital commutative $\\DGA$ with a cyclic structure $\\langle\\cdot,\\cdot\\rangle$ of degree $n$ of Hodge type. Suppose that~$\\H(V)$ is of finite type, $\\H^0(V) = \\R$ and $\\H^1(V) = 0$. Suppose, in addition, that $\\Dd V^n = 0$ and $\\Dd (\\Lambda U)^n = 0$ for the Sullivan minimal model $\\Lambda U$ of $V$. Then for any two Hodge decompositions with small subalgebras $\\VansSmall_1(V)$ and $\\VansSmall_2(V)$, there is a pairing-preserving isomorphism $\\VansQuotient(\\VansSmall_1(V))\\simeq\\VansQuotient(\\VansSmall_2(V))$.\n%\\end{Conjecture}\n%\\begin{proof}\n%\\end{proof}\n\nIt is not hard to come up with artificial examples of oriented $\\DGA$'s which are not of Hodge type.\\Add[noline,caption={Not of Hodge type}]{Example of an oriented dga without a Hodge decomposition.}\n\nThe following lemma and proposition show that in some cases it is possible to extend a $\\DGA$ to a $\\DGA$ of Hodge type.\n\n\\begin{Lemma}[Giving partners to non-degenerates]\\label{Lemma:Exte}\n Let $(V,\\Dd,\\wedge,\\Or)$ be a unital commutative $\\DGA$ which is non-negatively graded and oriented in degree $n$.\n For $k=\\lceil\\frac{n}{2}\\rceil$, $\\dotsc$, $n$, consider the following property $(P_k)$ of a direct sum decomposition%(``almost Hodge decomposition'')\n\\begin{equation}\\label{Eq:DecompOfV}\nV=\\Harm\\oplus \\Dd V \\oplus C,\n\\end{equation}\nwhere $\\Harm$ is a harmonic subspace and $C$ a complement of $\\ker \\Dd$ in $V$ perpendicular to~$\\Harm$ with respect to the induced cyclic structure $\\langle\\cdot,\\cdot\\rangle$:\n\\begin{description}\n\\item[$(P_{k})$] There is a complement $E$ of\n\\[\nC^\\perp\\coloneqq \\{ c^\\perp \\in C \\mid \\langle c^\\perp,c\\rangle=0\\text{ for all }c\\in C\\}\n\\]\nin $C$ and a homogenous linear map \n\\[\n\\rho:  E^{\\lceil n/2\\rceil}\\oplus \\dotsb \\oplus E^{k} \\longrightarrow \\Dd V\n\\]\nsuch that for all $e'\\in E$ and $c^\\perp\\in C^\\perp$, the following holds:\n\\begin{align}\n\\langle e', \\rho(e) \\rangle &=\\langle e', e \\rangle, \\label{Eq:ConditionTemp} \\\\\n\\langle c^\\perp, \\rho(e) \\rangle &=  0.\\label{Eq:ConditionTempII}\n\\end{align}\n\\end{description}\nSuppose that $V$ is non-negatively graded, of finite type and satisfies $V^0=\\Span\\{1\\}$ and $V^1 = 0$.\nSuppose that $n \\ge 5$ and that $(\\H(V), \\wedge, \\Or^\\H)$ is a Poincar\\'e duality algebra.\nGiven $\\lceil\\frac{n}{2}\\rceil\\le l\\le n$, suppose that $V$ admits a decomposition of type \\eqref{Eq:DecompOfV} such that either $l=\\lceil\\frac{n}{2}\\rceil$ or $l>\\lceil\\frac{n}{2}\\rceil$ and $(P_{l-1})$ holds.\nThen there is an $m\\in \\N_0$ and a Sullivan $\\DGA$ \n \\begin{equation}\\label{Eq:SullAlg}\n \\Lambda \\coloneqq \\Lambda(w_1,\\dotsc,w_m,z_1,\\dotsc,z_m)\n \\end{equation}\n specified by $\\deg w_i = l-1$, $\\deg z_i = l$, $\\Dd z_i = 0$ and $\\Dd w_i = z_i$ for all $i=1$, $\\dotsc$, $m$ such that the tensor product $\\DGA$ \n\\[\n \\hat{V}\\coloneqq V\\otimes \\Lambda\n \\]\n admits an orientation $\\hat{\\Or}: \\hat{V}\\to\\R$ which extends $\\Or: V \\rightarrow \\R$ on the canonical inclusion $V \\hookrightarrow\\hat{V}$, and there is a decomposition\n\\begin{equation}\\label{Eq:DevompOfVHat}\n\\hat{V} = \\hat{\\Harm}\\oplus \\Dd \\hat{V}\\oplus \\hat{C}\n\\end{equation}\nof type \\eqref{Eq:DecompOfV} for which $(P_{l})$ holds.\n\\end{Lemma}\n\n\\begin{proof}\nThe proof consists of a construction of $\\hat{\\Or}: \\hat{V}\\rightarrow\\R$, a construction of a harmonic subspace $\\hat{\\Harm}$ in $\\hat{V}$, a construction of a complement $\\hat{C}$ of $\\ker \\Dd$ in $\\hat{V}$, a degreewise description of $\\hat{C}$ and $\\hat{C}^\\perp$, a degreewise construction of a complement $\\hat{E}$ of $\\hat{C}^\\perp$ in $\\hat{C}$ and a proof of the property $(P_l)$ for the constructed decomposition.\n\\begin{description}[leftmargin=0pt,font=\\normalfont\\itshape]\n\\item[Construction of $\\hat{\\Or}$:]\nConsider the decomposition \\eqref{Eq:DecompOfV}.\nBecause $\\Dd : C \\rightarrow \\Dd V$ is an isomorphism, we can write\n\\begin{equation}\\label{Eq:VDecomp}\nV = \\Harm \\oplus \\underbrace{\\Dd E \\oplus \\Dd C^\\perp}_{\\displaystyle \\Dd V}\\oplus \\underbrace{E\\oplus C^\\perp}_{\\displaystyle C}.\n\\end{equation}\nThe restriction of $\\langle\\cdot,\\cdot\\rangle$ to $E$ is non-degenerate, and $V$ is of finite type by assumption; hence, $E$ is finite-dimensional.\nSet\n\\[\nm \\coloneqq \\dim E^l.\n\\]\nLet $\\xi_1$, $\\dotsc$, $\\xi_m$ be a basis of $E^{l}$ and $\\xi^1$, $\\dotsc$, $\\xi^m$ its dual basis in $E^{n-l}$.\nThe Sullivan algebra~$\\Lambda$ can be written as a direct sum \n\\begin{equation}\\label{Eq:LambdaDecomp}\n\\Lambda = \\bigoplus_{k=0}^\\infty \\Lambda_k\\quad\\text{with}\\quad\n\\Lambda_k = \\bigoplus_{\\substack{r, m \\ge 0 \\\\ r + m = k}}\\Lambda_r(w)\\otimes \\Lambda_m(z),\n\\end{equation}\nwhere $\\Lambda_r(w)$ and $\\Lambda_m(z)$ are the graded vector spaces generated by monomials $w_I = w_{i_1}\\dotsc w_{i_r}$ and $z_J = z_{j_1}\\dotsc z_{j_m}$ for all multiindices $I=\\{i_1, \\dotsc, i_r\\}$ and $J=\\{j_1,\\dotsc,j_m\\}$, respectively.\nThe direct sum decompositions~\\eqref{Eq:VDecomp} and~\\eqref{Eq:LambdaDecomp} induce a direct sum decomposition of $\\hat{V} = V \\otimes \\Lambda$ via the distributivity of $\\otimes$ and $\\oplus$.\nWe denote \n\\[\n\\hat{V}_k \\coloneqq V \\otimes \\Lambda_k\\quad\\text{for }k\\ge 0.\n\\]\nLet $\\hat{\\Or}: \\hat{V} \\to \\R$ be the linear map satisfying\n\\begin{align}\n\t\\hat{\\Or}(v) &\\coloneqq \\Or(v) && \\text{for all }v\\in V,\\\\\n\t\\hat{\\Or}(\\xi^i \\wedge z_j) &\\coloneqq \\Or(\\xi^i\\wedge \\xi_j) && \\text{and} \\\\\n\t\\hat{\\Or}(\\Dd \\xi^i \\wedge w_j) &\\coloneqq (-1)^{\\deg \\xi^i + 1}\\Or(\\xi^i \\wedge \\xi_j) && \\text{for all }i, j = 1, \\dotsc, m,\n\\end{align}\nand which is zero on $(\\Harm\\oplus\\Dd V\\oplus C^\\perp \\oplus \\bigoplus_{i\\ge 0, i \\neq n-l}E^i)\\otimes \\Lambda_1(z)$, on $(\\Harm\\oplus C \\oplus \\Dd C^\\perp \\oplus \\bigoplus_{i\\ge 0, i\\neq n-l} \\Dd E^i)\\otimes\\Lambda_1(w)$ and on $\\hat{V}_k$ for $k \\ge 2$.\n\nIn order to show that $\\hat{\\Or}$ is an orientation, we must check that $\\hat{\\Or}\\neq 0$ and $\\hat{\\Or}\\circ \\Dd = 0$.\nThe first condition is clear from $\\Restr{\\hat{\\Or}}{V} = \\Or \\neq 0$. \nAs for the second condition, $\\hat{V}$ is generated by elements $v \\wedge w_I \\wedge z_J$ for $v\\in V$ and multiindices $I$, $J$.\nIt holds $\\Dd \\hat{V}_k \\subset \\hat{V}_k$ for all~$k\\ge 0$, and hence $\\Dd \\hat{V} = \\bigoplus_{k=0}^\\infty \\Dd \\hat{V}_k$.\nFrom the definition of $\\hat{\\Or}$, we have immediately $\\Dd \\hat{V}_0 = \\Dd V \\subset \\ker \\Or \\subset \\ker \\hat{\\Or}$ and $\\bigoplus_{k=2}^\\infty \\Dd \\hat{V}_k \\subset \\ker\\hat{\\Or}$.\nAs for $\\Dd\\hat{V}_1$, we write $\\hat{V}_{1} = \\Span \\{v\\wedge w_j, v\\wedge z_j \\mid v\\in V, j=1,\\dotsc, m\\}$ as a graded vector space and compute\n\\begin{equation}\\label{Eq:DVI}\n\\begin{aligned}\n\t\\Dd \\hat{V}_1 &= \\Span\\{\\Dd(v\\wedge w_j), \\Dd(v\\wedge z_j) \\mid v\\in V, j=1, \\dotsc, m \\}\\\\\n\t&=\\Span\\{\\Dd v \\wedge w_j + (-1)^{\\Deg v} v \\wedge z_j \\mid v\\in V, j=1, \\dotsc, m\\}.\n\\end{aligned}\n\\end{equation}\nWrite $v\\in V^{n-l}$ as $v = h  + \\Dd c + c^\\perp + \\sum_{i=1}^m \\alpha_i \\xi^i$ for $h\\in \\Harm^{n-l}$, $c\\in C^{n-l-1}$, $c^\\perp\\in C^{\\perp n-l}$ and $\\alpha_i\\in \\R$, and compute for every $j=1$, $\\dotsc$, $m$ the following:\n\\begin{align*}\n\\hat{\\Or}(\\Dd v\\wedge w_j) & = \\hat{\\Or}\\Bigl(\\Dd c^\\perp \\wedge w_j + \\sum_{i=1}^m \\alpha_i \\Dd \\xi^i \\wedge w_j\\Bigr)\\\\\n&= \\sum_{i=1}^m \\alpha_i \\hat{\\Or}(\\Dd \\xi^i \\wedge w_j)\\\\\n&= \\sum_{i=1}^m (-1)^{\\deg \\xi^i + 1}\\alpha_i \\hat{\\Or}(\\xi^i \\wedge \\xi_j) \\\\\n&= (-1)^{n-l+1}\\sum_{i=1}^m \\alpha_i \\hat{\\Or}(\\xi^i \\wedge z_j)\\\\\n&= (-1)^{n-l+1}\\hat{\\Or}\\Bigl((h + \\Dd c + c^\\perp)\\wedge z_j +\\sum_{i=1}^m \\alpha_i \\xi^i \\wedge z_j \\Bigr) \\\\\n&= (-1)^{\\deg v + 1}\\hat{\\Or}(v\\wedge z_j).\n\\end{align*}\nConsequently, $\\Dd \\hat{V}_{1}\\subset \\ker \\hat{\\Or}$.\nThis shows $\\hat{\\Or}\\circ\\Dd = 0$.\n\nThe inclusion $V\\hookrightarrow\\hat{V}$ is clearly orientation preserving. \n\n\\item[Construction of $\\hat{\\Harm}$:]\nIt holds $\\bar{\\H}(\\Lambda) = 0$ for the reduced homology, and hence $\\H(\\hat{V}) \\simeq \\H(V)\\otimes\\H(\\Lambda) = \\H(V)$ by K\\\"unneth's formula. Because $\\Harm\\subset \\ker \\Dd$, $\\Harm\\cap\\im\\Dd = 0$ and $\\dim(\\Harm) = \\dim \\H(\\hat{V})$, $\\Harm$ is a complement of $\\Dd\\hat{V}$ in $\\ker \\Dd$. Therefore, \n\\[\n\\hat{\\Harm} \\coloneqq \\Harm\n\\]\nis a harmonic subspace of $\\hat{V}$.\nAlso note that $\\H(\\hat{V})=\\bigoplus_{k=0}^\\infty \\H(\\hat{V}_k)$ and $\\dim \\H(\\hat{V}) = \\dim \\H(\\hat{V}_0)$, and hence $\\H(\\hat{V}_k) = 0$ for all $k\\ge 1$.\n\n\\item[Construction of $\\hat{C}$:]\nWe construct $\\hat{C}$ as a direct sum $\\hat{C} = \\bigoplus_{k=0}^\\infty \\hat{C}_k$. \nSet \n\\[\n\\hat{C}_0 \\coloneqq C.\n\\]\nFor $k=1$, define\n\\begin{equation}\\label{Eq:CIDef}\n\\begin{aligned}\n \\tilde{C}_1 &\\coloneqq \\Span\\{v \\wedge w_i \\mid v\\in V, i=1, \\dotsc,m\\} \\subset \\hat{V}_1, \\\\\n  \\hat{C}_1 &\\coloneqq \\{\\tilde{c} - \\pi(\\tilde{c}) \\mid \\tilde{c}\\in \\tilde{C}_1\\}\\subset\\hat{V}_0\\oplus\\hat{V}_1,\n\\end{aligned}\n\\end{equation}\nwhere $\\pi: \\hat{V}\\rightarrow\\hat{\\Harm}$ is the orthogonal projection.\nFor all $k\\ge 2$, let $\\hat{C}_k \\subset \\hat{V}_k$ be an arbitrary complement of $\\ker\\Dd$ in $\\hat{V}_k$ as a graded vector space.\n\nWe show first that $\\hat{C}_i$ for $i\\ge 0$ are disjoint.\nClearly, $\\hat{C}_j \\cap \\sum_{i=0, i\\neq j}^\\infty \\hat{C}_i = 0$ for all $j\\ge 2$.\nBecause $(\\Harm + C)\\cap\\tilde{C}_1 = 0$ and $\\Harm \\cap C = 0$, it holds $\\hat{C}_1 \\cap \\hat{C}_0 = 0$, and $(\\hat{C}_0 + \\hat{C}_1) \\cap \\sum_{i\\ge 2} \\hat{C}_i = 0$ implies that $\\hat{C}_j \\cap \\sum_{i=0, i\\neq j}^\\infty \\hat{C}_i = 0$ holds also for $j=0$, $1$.\n\nWe show that $\\hat{C}=\\bigoplus_{k\\ge 0}\\hat{C}_k$ is a complement of $\\ker \\Dd$ in~$\\hat{V}$.\nFor $k\\ge 2$, $\\hat{C}_k$ are complements of $\\ker \\Dd$ in $\\hat{V}_k$ by construction.\nFor $k=0$, $\\hat{C}_0 \\oplus \\ker \\Dd \\cap \\hat{V}_0 = \\hat{V}_0$ follows from \\eqref{Eq:DecompOfV}. \nFor $k=1$, we compare \\eqref{Eq:DVI} and \\eqref{Eq:CIDef} to see that $\\tilde{C}_1 \\oplus \\Dd \\hat{V}_1 = \\hat{V}_1$.\nBecause $\\Harm\\subset \\ker \\Dd$, it is easy to see that $\\hat{C}_0\\oplus\\hat{C}_1$ is a complement of $\\ker \\Dd$ in $\\hat{V}_0\\oplus\\hat{V}_1$.\n\nFinally, $\\hat{C}_0 \\perp \\hat{\\Harm}$ holds by \\eqref{Eq:DecompOfV}, $\\hat{C}_1\\perp\\Harm$ holds by the construction of $\\hat{C}_1$ from $\\tilde{C}_1$ and $\\hat{C}_k \\perp \\Harm$ follows from the definition of $\\hat{\\Or}$.\n\n\\item[Degreewise description of $\\hat{C}$ and $\\hat{C}^\\perp$:]\nWe are interested in $\\hat{C}^i$ for $0\\le i\\le l$.\nFor all $k\\ge 2$, the graded vector space $\\hat{C}_k$ is concentrated in degrees $i\\ge 2(l-1)$.\nBut $2(l-1)>l$ due to $n\\ge 5$.\nTherefore, $\\hat{C}_k^i = 0$ for $k\\ge 2$ and $0\\le i \\le l$.\nWe denote $\\bar{V} \\coloneqq \\bigoplus_{i=1}^\\infty V^i$ and write $\\tilde{C}_1 = \\Lambda_1(w) \\oplus (\\bar{V}\\otimes \\Lambda_1(w))$.\nBecause $V^1=0$, the graded vector space $\\bar{V}\\otimes\\Lambda_1(w)$ is concentrated in degrees $i\\ge 2 + (l-1) = l + 1$. We obtain  \n\\begin{equation}\\label{Eq:CDegreewise}\n\\hat{C}^i = (\\hat{C}_0 \\oplus \\hat{C}_1)^i =\n \\begin{cases}\n \tC^i & \\text{for }0 \\le i \\le l-1, \\\\\n\tC^i + \\Span\\{ w_j \\mid j = 1, \\dotsc, m\\} & \\text{for }i = l - 1, \\\\\n\tC^i & \\text{for }i = l.\n \\end{cases}\n\\end{equation}\nHere we used that $\\hat{C}_1^{l-1} = \\tilde{C}_1^{l-1} = \\Span\\{ w_i \\mid i = 1, \\dotsc, m\\}$, which is true because $\\Lambda_1(w)\\perp\\Harm$ from the definition of $\\hat{\\Or}$.\n\nWe are now interested in $\\hat{C}^{\\perp i}$ for $n-l\\le i \\le l$.\nNote that $n-l \\le i \\le l$ is equivalent to $n-l \\le n-i \\le l$.\nBy definition, $\\hat{\\Or}$ vanishes on $C\\wedge\\Lambda_1(w)=C\\otimes\\Lambda_1(w)$ and $\\Lambda_1(w)\\wedge\\Lambda_1(w) \\subset \\Lambda_2(w)$.\nLooking at \\eqref{Eq:CDegreewise}, we see the following: \n\\begin{equation}\\label{Eq:CPerpDegreewise}\n\t\\hat{C}^{\\perp i} =\n\t\t\\begin{cases}\n\t\t\tC^{\\perp i} &  \\text{for }n-l \\le i \\le l - 2, \\\\\n\t\t\tC^{\\perp i} + \\Span\\{w_i\\mid i=1,\\dotsc,m\\} & \\text{for }i = l-1, \\\\\n\t\t\tC^{\\perp i} & \\text{for }i = l.\n\t\t\\end{cases}\t\t\n\\end{equation}\nBecause $\\hat{V}$ is non-negatively graded, it holds $\\hat{C}^{\\perp i} = \\hat{C}^i$ for $i>n$.\nNotice that $\\hat{C}^{\\perp i}$ might be smaller than $C^i$ for $0\\le i \\le n-l-1$.\nThe reason for this is a possible existence of $v_1$, $v_2\\in V$ such that $v_1 \\wedge v_2$ has a non-trivial $\\Dd E$-component and $\\langle v_1, v_2\\wedge w_i \\rangle = \\hat{\\Or}((v_1\\wedge v_2)\\wedge w_i) \\neq 0$.\n\n\\item[Construction of $\\hat{E}$:]\nBecause $\\hat{V}_i \\wedge \\hat{V}_j \\subset \\hat{V}_{i+j}$ and $\\hat{V}_k \\subset \\ker \\hat{\\Or}$ for $k\\ge 2$, we have $\\hat{C}_k \\subset \\hat{C}^\\perp$ for all $k\\ge 2$.\nIt follows that \n\\[\n\\hat{C}^\\perp = (\\hat{C}_0\\oplus\\hat{C}_1)\\cap\\hat{C}^\\perp \\oplus \\bigoplus_{k\\ge 2}\\hat{C}_k,\n\\]\nand hence it is enough to construct $\\hat{E} \\subset \\hat{C}_0\\oplus\\hat{C}_1$ such that $\\hat{E}\\oplus (\\hat{C}_0\\oplus\\hat{C}_1)\\cap\\hat{C}^\\perp = \\hat{C}_0\\oplus\\hat{C}_1$.\nBecause $E\\cap \\hat{C}^\\perp \\subset E \\cap C^\\perp = 0$, we can get $\\hat{E}$ by extending $E$.\nFor $0\\le i \\le n$, we define\n%For $n-l \\le i \\le l$, we set $\\hat{E}^i\\coloneqq E^i$.\n%For $i=0$, $\\dotsc$, $n-l-1$, we obtain $\\hat{E}^i$ from $E^i$ by adding elements from $C^i$.\n%For $i=l+1$, $\\dotsc$, $n$, we obtain $\\hat{E}^i$ from $E^i$ by adding elements from $\\hat{C}_0^i \\oplus \\hat{C}_1^i$.\n\\begin{equation}\\label{Eq:EDegreewise}\n\\hat{E}^i \\coloneqq\n\t\\begin{cases}\n\t\tE^i\\oplus \\Span\\{c_1^i,\\dotsc, c_{k_i}^i\\}\\text{ for }c_1^i, \\dotsc, c_{k_i}^i\\in C^i & \\text{for }0\\le i \\le n-l-1,\\\\\n\t\tE^i & \\text{for }n-l\\le i \\le l,\\\\\n\t\tE^i\\oplus\\Span\\{\\hat{v}_1,\\dotsc,\\hat{v}_k\\}\\text{ for }\\hat{v}_1^i,\\dotsc,\\hat{v}_{k_i}^i\\in(\\hat{C}_0\\oplus\\hat{C}_1)^i & \\text{for }l+1\\le i \\le n,\n\t\\end{cases}\n\\end{equation}\nwhere the existence of $c^i_j$ and $\\hat{v}^i_j$ and the fact that $\\hat{C} = \\hat{E}\\oplus\\hat{C}^\\perp$ are justified by \\eqref{Eq:CDegreewise}, \\eqref{Eq:CPerpDegreewise} and \\eqref{Eq:ConditionTempII}.\n\n\\item[Property $(P_l)$:] We define $\\hat{\\rho}: \\hat{E}^{\\lceil \\frac{n}{2}\\rceil}\\oplus\\dotsb\\oplus\\hat{E}^l \\rightarrow \\Dd\\hat{V}$ by $\\hat{\\rho} \\coloneqq \\rho$ on $\\hat{E}^{\\lceil \\frac{n}{2}\\rceil}\\oplus\\dotsb\\oplus\\hat{E}^{l-1}=E^{\\lceil \\frac{n}{2}\\rceil}\\oplus\\dotsb\\oplus E^{l-1}$ and by\n\\[\n\\hat{\\rho}(\\xi_i) \\coloneqq z_i\\quad\\text{for all }i=1, \\dotsc, m.\n\\]\nConditions \\eqref{Eq:ConditionTemp} and \\eqref{Eq:ConditionTempII} are checked easily using $(P_{l-1})$, \\eqref{Eq:CDegreewise}, \\eqref{Eq:CPerpDegreewise}, \\eqref{Eq:EDegreewise} and the definition of $\\hat{\\Or}$.\\qedhere\n%For $\\lceil\\frac{n}{2}\\rceil \\le i \\le l - 1$, \n%\\eqref{Eq:ConditionTemp} \\eqref{Eq:ConditionTempI}\n%\n%Given $\\lceil \\frac{n}{2} \\rceil \\le i \\le l - 1$ and $e\\in \\hat{E}^i = E^i$, there is $z\\in(\\im\\Dd)^i$ such that $\\langle e,f\\rangle = \\langle z,f\\rangle$ and $\\langle z,c^\\perp\\rangle=0$ for all $f\\in E^{n-i}$ and $c^\\perp\\in (C^\\perp)^{n-i}$. \n%Due to $j\\le l$ and $l\\le $\n%$n - j \\ge n - l$\n%\n%\n% we can write an $\\hat{e}\\in\\hat{E}^i$ as $\\hat{e} = e + c^\\perp + v \\wedge w + w$ for $e\\in E$, $c^\\perp\\in C^\\perp$, $v\\in V^{\\ge 2}$ and $w\\in \\Lambda_1(w)$.\n% It holds $\\deg(v\\wedge w) = l+1$, and hence $v=0$ for $k+1\\le i \\le l$; this summand is thus always zero.\n% It holds $\\deg w = l - 1$, and hence $w=0$ for $i\\neq l-1$.\n% In this case, $c^\\perp + w = \\hat{e}-e = \\hat{E}^{l-1}$ can pair non-trivially only with an element in degree $n - (l-1) \\le n - k = k+1 \\le l$.\n% However, since $\\hat{V}^l = V^l \\oplus \\Lambda_1(z)$, $\\hat{V}^{l-1} = V^{l-1}\\oplus\\Lambda_1(w)$ and $\\hat{V}^i = V^i$ for $i<l-1$, we see that $(c^\\perp + w)\\perp \\hat{C}$.\n% This implies $\\hat{e} = e$.\n% In the case $i = l$, we have $w=0$ and $v=0$. \n% Now, $\\hat{e}-e = c^\\perp \\in \\hat{E}^l$ can pair non-trivially only with an element in degree $n - l \\le n - k - 1 = k \\le l - 1$.\n% However, since $\\hat{C}^{l-1} = C^{l-1}\\oplus \\Lambda_1(w)$, we see that $c^\\perp \\hat{C}$.\n% This implies again that $\\hat{e} = e$.\n%\n% Let us check $(P_{l+1})$ for the decomposition consisting of $\\Harm$, $\\hat{C}$ and $\\hat{E}$. Let $k+1 \\le i \\le l$, and let $e\\in \\hat{E}^i = E^i$ (the equality has been previously proven).\n%\n%\n% We also need that $\\hat{E}^i = E^i$ for all $n-l+1 \\le i\\le k$. However, this is clear.\n\\end{description}\n\\end{proof}\n\n\\begin{Questions}\\phantomsection\\label{Q:QuestOnPoinc}\n\\begin{RemarkList}\n\\item Given a cochain complex $(V,\\Dd)$ with a symmetric pairing $\\langle\\cdot,\\cdot\\rangle$, which conditions have to be satisfied by the maps $\\pi_\\Harm$, $\\StdHtp: V\\rightarrow V$ so that $V=\\Im \\pi_\\Harm \\oplus \\Im \\Dd \\oplus \\Im \\StdHtp$ is a Hodge decomposition with Hodge pair $(\\Im \\pi_\\Harm, \\StdHtp)$? This would characterize Hodge decompositions in terms of Hodge pairs.\n\\item It should be possible to prove Lemma~\\ref{Lemma:Exte} also for $n\\le 4$ by hand. Check that! \n\\qedhere\n\\end{RemarkList}\n\\end{Questions}\n\\end{document}\n", "meta": {"hexsha": "a69d2cf7a5bbd639becd80e3d492fab8626ea3eb", "size": 72077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/Form_Or.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/Form_Or.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/Form_Or.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": 86.1135005974, "max_line_length": 1367, "alphanum_fraction": 0.6933834649, "num_tokens": 26664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563824, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6367025258995699}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage{amsmath}\n\\usepackage[colorlinks]{hyperref}\n\\usepackage{CJKutf8}\n\\title{Stokes' Theorem}\n\\author{Naitree Zhu}\n\\date{Last modified: \\today}\n\\begin{document}\n\\maketitle\nIn differential geometry, Stokes' theorem (also called the generalized Stokes' theorem) is a statement about the integration of differential forms on manifolds, which both simplifies and generalizes several theorems from vector calculus. \n Stokes' theorem says that the integral of a differential form $\\omega$ over the boundary of some orientable manifold $\\Omega$ is equal to the integral of its exterior derivative $\\mathrm{d}\\omega$ over the whole of $\\Omega$, i.e.\n\\begin{equation}\n\\int_{\\partial\\Omega} \\omega=\\int_\\Omega \\mathrm{d}\\omega\n\\end{equation}\n\nThis modern form\\footnote{For more deep informations about the \\emph{generalized} stokes' theorem:\\url{http://en.wikipedia.org/wiki/Stokes'_theorem}} of Stokes' theorem is a vast generalization of a classical result first discovered by Lord Kelvin, who communicated it to George Stokes in a letter dated July 2, 1850. Stokes set the theorem as a question on the 1854 Smith's Prize exam, which led to the result bearing his name. \nThis classical Kelvin--Stokes theorem relates the surface integral of the curl of a vector field $\\boldsymbol{F}$ over a surface $\\Sigma$ in Euclidean three-space to the line integral of the vector field over its boundary $\\partial\\Sigma$:\n\\begin{equation}\n\\iint_S \\nabla\\times \\boldsymbol{F}\\cdot \\mathrm{d}\\boldsymbol{S}=\\oint_{\\partial S}\\boldsymbol{F}\\cdot\\mathrm{d}\\boldsymbol{l}\n\\end{equation}\n\nThis classical statement, as well as the classical Divergence theorem, fundamental theorem of calculus, and Green's Theorem are simply special cases of the general formulation stated above.\n\\part{Special cases}\nThe general form of the Stokes theorem using differential forms is more powerful and easier to use than the special cases. The traditional versions can be formulated using Cartesian coordinates without the machinery of differential geometry, and thus are more accessible. Further, they are older and their names are more familiar as a result.\n The traditional forms are often considered more convenient by practicing scientists and engineers but the non-naturalness of the traditional formulation becomes apparent when using other coordinate systems, even familiar ones like spherical or cylindrical coordinates. There is potential for confusion in the way names are applied, and the use of dual formulations.\n\\section{Kelvin-Stokes theorem}\nThis is a (dualized) 1+1 dimensional case, for a 1-form (dualized because it is a statement about vector fields). This special case is often just referred to as the Stokes' theorem in many introductory university vector calculus courses and as used in physics and engineering. It is also sometimes known as the curl theorem.\n\nThe classical Kelvin–-Stokes theorem:\n\\begin{equation}\n\\iint_S \\nabla\\times \\boldsymbol{F}\\cdot \\mathrm{d}\\boldsymbol{S}=\\oint_{\\partial S}\\boldsymbol{F}\\cdot\\mathrm{d}\\boldsymbol{l}\n\\end{equation}\n\nwhich relates the surface integral of the curl of a vector field over a surface $\\Sigma$ in Euclidean three-space to the line integral of the vector field over its boundary, is a special case of the general Stokes theorem (with n = 2) once we identify a vector field with a 1-form using the metric on Euclidean three-space. \nThe curve of the line integral, $\\partial\\Sigma$, must have positive orientation, meaning that $d\\boldsymbol{l}$ points counterclockwise when the surface normal, $d\\boldsymbol{S}$, points toward the viewer, following the right-hand rule.\n\nOne consequence of the formula is that the field lines of a vector field with zero curl cannot be closed contours.\n\\begin{CJK}{UTF8}{gbsn}\n在式(3)中， 考虑场区内的任一曲面，由于场的旋度为0， 左边为0， 则右面说明在场区内场矢量沿任何一条闭合曲线的积分为0. 这就说明了该矢量场的场线是绝不闭合的，因为在任一场线上矢量场的方向沿着该场线，沿闭合场线的积分非0.\n\\end{CJK}\n\nIn Cartesian coordinates,the formula can be rewritten as:\n\\begin{equation}\n\\begin{split}\n\\iint_\\Sigma \\left\\lbrace\\left(\\frac{\\partial R}{\\partial y}-\\frac{\\partial Q}{\\partial z}\\right) dydz + \\left(\\frac{\\partial P}{\\partial z}-\\frac{\\partial R}{\\partial x}\\right) dzdx + \\left(\\frac{\\partial Q}{\\partial x}-\\frac{\\partial P}{\\partial y}\\right) dxdy\\right\\rbrace\\\\\n= \\oint_{\\partial\\Sigma} \\left\\lbrace P dx + Q dy + R dz\\right\\rbrace\n\\end{split}\n\\end{equation}\n\\section{2-dimensional: Green's theorem}\nGreen's theorem is immediately recognizable as the third integrand of both sides in the integral in terms of P, Q, and R cited above.\n\\section{Divergence theorem}\nLikewise, the Divergence theorem \n\\begin{equation}\n\\int_V \\nabla\\cdot\\boldsymbol{F} \\mathrm{d}V=\\oint_{\\partial V} \\boldsymbol{F}\\cdot \\mathrm{d}\\boldsymbol{S}\n\\end{equation}\nis a special case if we identify a vector field with the n-1 form obtained by contracting the vector field with the Euclidean volume form.\n\\end{document}", "meta": {"hexsha": "a3753fdf81fba970ede62b6043efe1d78f824844", "size": 4905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/Stokes' theorem/Stokes' theorem.tex", "max_stars_repo_name": "Naitreey/notes-and-knowledge", "max_stars_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-05-16T06:06:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-12T08:46:18.000Z", "max_issues_repo_path": "math/Stokes' theorem/Stokes' theorem.tex", "max_issues_repo_name": "Naitreey/notes-and-knowledge", "max_issues_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-04-06T01:46:22.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-13T03:11:33.000Z", "max_forks_repo_path": "math/Stokes' theorem/Stokes' theorem.tex", "max_forks_repo_name": "Naitreey/notes-and-knowledge", "max_forks_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-04-11T11:02:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-27T11:59:09.000Z", "avg_line_length": 86.0526315789, "max_line_length": 429, "alphanum_fraction": 0.7867482161, "num_tokens": 1322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6367013790544344}}
{"text": "\\section{Theory}\n\nOur dataset consists of images.  One could use each individual pixel as an individual input feature, but that loses any relative spacial locality information between pixels, and is therefore prone to errors due to location in the image of the object to be identified \\cite{lecun1998gradient}.  For example, if we want to identify if an image has a circle or not, looking at a set of pixels without knowing where they are located relative to eachother cannot be done in general.\n\nFor handwriting recognition, there are some features that some people have tried to extract to use in a learning algorithm.  These include aspect ratio, percent of thresholded pixels above the horizontal half plane, percent of thresholded pixels to the right of the vertical half plane, and so forth \\cite{web:wikihandwritfeat}.  It is unknown if these features will be sufficient to classify the characters.\n\n\\subsection{Convolutional Neural Networks}\n\nEarly on in the project, we received a recommendation to use Convolutional Neural Networks (CNNs).  CNNs have been shown to be very effective in image recognition \\cite{korekado2003convolutional} \\cite{ciresan2012multi}.  One significant advantage of CNNs is the ability to make the representation \\emph{invariant} to small translations of the input, such as for image recognition tasks \\cite{Bengio-et-al-2015-Book}.  Another useful aspect of CNNs are their ability to automate feature identification and extraction \\cite{Bengio-et-al-2015-Book}.\n\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=\\textwidth]{images/mylenet.png}\n  \\caption{\n    Convolution and pooling layers that make up a CNN followed by a\n    fully-connected Multi-layered Perceptron (MLP).\n    (from \\cite{Bengio-et-al-2015-Book})\n    }\n  \\label{fig:convnet}\n\\end{figure}\n\nCNNs are an example of multi-layered neural networks.  As can be seen in Figure~\\ref{fig:convnet}, CNNs have convolution layers and sub-sampling layers, also known as pooling layers.  The convolution layer uses multiple weight matrices to generate other images.  These are then pooled in order to reduce the dimensionality while at the same time introducing non-linearities.  The type of non-linearity depends on the function used in the pooling layer, such as a max function over a $4 \\times 4$ region.  We have a loss function at the end of the neural pipeline, and train the previous layers by performing back-propagation.  This back-propagation is simply gradient descent over all of the weight vectors in the whole network (by doing chain rule).\n\nWe studied some example code of CNN on \\url{deeplearning.net}.   By reading their code, we made two interesting observations.\n\\begin{description}\n  \\item[Kernels]\n    Multiple weight filters are generated at each convolution layer.  How do they not converge to the same weight vector?  We believe this has to do with the space not being convex and having multiple local minima, because of the introduced non-linearities at each layer.  We initialize the weight vectors with random values and hope that they find different local minima.  We treated this value as a hyper-parameter.  We suspect that having this value too high will both cause a significant increase in running time and cause the resultant classifier to overfit.\n  \\item[Weight bounds]\n    The initialization of the weight bounds seemed to be determined\n\\end{description}\n\n\\subsection{Theano}\n\nWe were pointed by Dustin Webb to the Theano python module for implementation of CNNs.  Theano takes mathematical expressions and compiles them into C++ to make for a robust and efficient framework \\cite{bergstra+al:2010-scipy}.  Theano was something completely new to us.  It uses symbolic expressions that can be compounded together.  You can define a loss function and have Theano symbolically generate the gradient for use in stochastic gradient descent.\n\n\\subsection{Linear Classifiers}\n\nEven though we chose to use CNNs, we decided to first employ the linear classifiers we learned in class for comparison and to learn how to use Theano.  We chose to use Perceptron, Averaged Perceptron, SVM, and Logistic Regression.  These all can be implemented using stochastic gradient descent even though Perceptron is usually not directly implemented in that way.\n", "meta": {"hexsha": "f7560a76a13f51eba81e55b1c6fff9e8fe88c6d8", "size": 4274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "final-report/internal/02-theory.tex", "max_stars_repo_name": "mikebentley15/cs6350_project_ml", "max_stars_repo_head_hexsha": "9ed83a514ae8548ae1a219d6e4fadc210b987254", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-18T00:58:36.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-18T00:58:36.000Z", "max_issues_repo_path": "final-report/internal/02-theory.tex", "max_issues_repo_name": "mikebentley15/cs6350_project_ml", "max_issues_repo_head_hexsha": "9ed83a514ae8548ae1a219d6e4fadc210b987254", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "final-report/internal/02-theory.tex", "max_forks_repo_name": "mikebentley15/cs6350_project_ml", "max_forks_repo_head_hexsha": "9ed83a514ae8548ae1a219d6e4fadc210b987254", "max_forks_repo_licenses": ["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.5897435897, "max_line_length": 750, "alphanum_fraction": 0.7980814226, "num_tokens": 946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.636701373782538}}
{"text": "\\section{Introduction}\\label{sec:introduction}\n\nSingle-particle cryo-electron microscopy (cryo-EM) has revolutionized the field of structural biology over the last decades~\\cite{dubochet1988cryo, frank2006three, chap0-nat2015MethodYear}.\nThe use of electron beams to image ice-embedded samples has permitted the recovery of 3D bio-structures at unprecedented resolution.\nThis ``resolution revolution'' has had a tremendous impact in biomedical research, providing invaluable insights into the biological processes that underlie many current diseases.\n\nIn single-particle cryo-EM, every 3D particle adopts a random orientation $\\bth_i$ in the ice layer before being imaged.\nHence, the projection geometry associated to each acquired 2D projection (\\figref{imaging-geometry}) is unknown.\nYet, this knowledge is essential for the tomographic reconstruction of bio-structures~\\cite{Natterer2001mathematics}.\nWe consider that a cryo-EM measurement (\\ie, a projection) $\\p_i \\in \\R^{n_p}$ is acquired through\n\\begin{equation}\n    \\label{eqn:imaging-model}\n    \\p_i = \\mathbf{C}_{\\boldsymbol\\varphi} \\mathbf{S}_{\\mathbf{t}_i} \\mathbf{P}_{\\bth_i} \\x + \\mathbf{n},\n\\end{equation}\nwhere $\\x \\in \\R^{n_x}$ is the unknown 3D density map~\\cite{dimaio_creating_2007} (Coulomb potential).\n%\\mdeff{Alternative notation: $\\p_i = \\mathbf{C}(\\boldsymbol\\varphi) \\mathbf{S}(\\mathbf{t}) \\mathbf{P}(\\bth_i) \\x + \\mathbf{n}$ if we want to write $\\mathbf{R}(\\bth_i) = \\mathbf{R}(q_i) = \\mathbf{R}(-q_i)$ later.}\n%\\mdeff{Alternative notation: $\\x: \\R^3 \\rightarrow \\R$ and $\\p_i: \\R^2 \\rightarrow \\R$ as functions, so $\\x$ can be rotated by $\\mathbf{R} \\in \\mathbf{SO}(3)$ as $\\mathbf{R}\\x$. But then $\\x$ is not a vector for the SiameseNN.}\nThe operator $\\mathbf{P}_{\\bth_i}: \\R^{n_x} \\to \\R^{n_p}$ is the projection along the orientation $\\bth_i$ (\\ie, the x-ray transform).\n% consistency: 3D pose = orientation\nThe operator $\\mathbf{S}_{\\mathbf{t}_i}: \\R^{n_p} \\to \\R^{n_p}$ is a shift of the projection by $\\mathbf{t}_i = (t_{i_1}, t_{i_2})$.\nThe convolution operator $\\mathbf{C}_{\\boldsymbol\\varphi}: \\R^{n_p} \\to \\R^{n_p}$ models the microscope point-spread function (PSF) with parameters $\\boldsymbol\\varphi = (d_1, d_2, \\alpha_\\mathrm{ast})$, where $d_1$ is the defocus-major, $d_2$ is the defocus-minor, and $\\alpha_\\mathrm{ast}$ is the angle of astigmatism~\\cite{vulovic_image_2013,rullgard_simulation_2011}.\nFinally, $\\mathbf{n} \\in \\R^{n_p}$ represents additive noise.\n\\figref{different-projections} illustrates the effect of projection, shift, and noise.\nThe challenge is then to reconstruct $\\x$ from a set of projections $\\{\\p_i\\}_{i=1}^P$ acquired along unknown orientations.\n%\\mdeff{We shall decompose $\\mathbf{P}_{\\bth_i}$ into a rotation $R(\\bth_i)$ and an integration.} \\lau{The most straightforward way is to simply rewrite $P_theta$ as a rotation operator, followed by a summation operator along lines. That being said, now that I look at it, I would suggest not to rewrite it like this; this is really not so standard in the cryo-EM community. Plus everyone now that the rotation operator is implicitly contained in the projection one, so it's not really needed either.}\n\n% \\tdplotsetmaincoords{60}{110}\n% \\pgfmathsetmacro{\\rvec}{.8}\n% \\pgfmathsetmacro{\\thetavec}{30}\n% \\pgfmathsetmacro{\\phivec}{60}\n% \\begin{figure}\n% \\centering\n% \\begin{tikzpicture}[scale=4,tdplot_main_coords]\n%     \\coordinate (O) at (0,0,0);\n%     \\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$\\bsx_1$};\n%     \\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$\\bsx_2$};\n%     \\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$\\bsx_3$};\n%     \\tdplotsetcoord{P}{\\rvec}{\\thetavec}{\\phivec}\n%     \\draw[-stealth,very thick,color=red] (O) -- (P);\n%     \\draw[dashed, color=red] (O) -- (Pxy);\n%     \\draw[dashed, color=red] (P) -- (Pxy);\n%     \\tdplotdrawarc{(O)}{0.2}{0}{\\phivec}{anchor=north}{$\\theta_1$}\n%     \\tdplotsetthetaplanecoords{\\phivec}\n%     \\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}%\n%         {\\thetavec}{anchor=south west}{$\\theta_2$}\n%     \\draw[dashed,tdplot_rotated_coords] (\\rvec,0,0) arc (0:90:\\rvec);\n%     \\draw[dashed] (\\rvec,0,0) arc (0:90:\\rvec);\n%     \\tdplotsetrotatedcoords{\\phivec}{\\thetavec}{0}\n%     \\tdplotsetrotatedcoordsorigin{(P)}\n%     \\draw[dashed,blue,tdplot_rotated_coords,-] (-.4,0,0)\n%         -- (.4,0,0) node[anchor=north west]{};\n%     \\draw[dashed,blue,tdplot_rotated_coords,-] (0,-.4,0)\n%         -- (0,.4,0) node[anchor=west]{};\n%     \\draw[blue,tdplot_rotated_coords,-]  (-.4,.4,0) -- (.4,.4,0)  -- (.4,-.4,0) -- (-.4,-.4,0) -- (-.4,.4,0)   node[anchor=north]{};\n%     \\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.2}{0}%\n%         {30}{anchor=north west,color=black}{$\\theta_3$}\n%     \\tdplotsetrotatedcoords{\\phivec}{\\thetavec}{30}\n%     \\draw[thick,tdplot_rotated_coords,->] (0,0,0)\n%         -- (.3,0,0) node[anchor=north west]{$\\bsy_1$};\n%     \\draw[thick,tdplot_rotated_coords,->] (0,0,0)\n%         -- (0,.3,0) node[anchor=west]{$\\bsy_2$};\n%     \\node[blue] at (0.4,0.45,1.2) {$\\Omega_{\\mathrm{2D}}$};\n%     \\node[red] at (1.5,0.75,1.2) {$\\bvth_{\\bth}$};\n%     \\tdplotsetrotatedthetaplanecoords{45}\n% \\end{tikzpicture}\n% \\caption*{\\mdeff{Kept as reference for \\figref{imaging-geometry} as this tikz figure is beautiful. Will be commented out in the end.}}\n% \\end{figure}\n\n\\begin{figure}\n    \\begin{minipage}[t]{0.48\\linewidth}\n        \\centering\n        \\includegraphics[height=0.7\\linewidth]{geomProj3D}\n        \\caption{%\n            % * (i) what we mean by a projection and an orientation (the two most important objects of our paper), and\n            % * (ii) how a projection (=integration through z in the new coordinate system) is made from a 3D volume.\n            % $\\p_i = \\mathbf{P} \\Rot(\\bth) \\x$ \\todo{($\\mathbf{P}$ is a projection/integration)}.\n            Geometry of the imaging model defined in \\eqnref{imaging-model}.\n            The 3D density $\\x$ in the coordinate system $(x_1, x_2, x_3)$ is imaged along the \\textit{orientation} $\\bth$ to produce the 2D \\textit{projection} $\\p$ in the coordinate system $(y_1, y_2)$ of the microscope's detector plane.\n            The orientation $\\bth = (\\theta_3, \\theta_2, \\theta_1)$ is decomposed as the direction $(\\theta_2, \\theta_1) \\in [0,\\pi] \\times [0,2\\pi[$ (parameterizing the sphere $\\mathbb{S}^2$) and the in-plane rotation $\\theta_3 \\in [0,2\\pi[$ (parameterizing the circle $\\mathbb{S}^1$).\n            In our work, we represent the orientation $\\bth$ as a unit quaternion $q$.\n            %The 3D rotation $\\Rot(\\bth) = \\Rot(q) \\in \\SO(3)$ maps the object coordinate system to the projection coordinate system.\n            %\\mdeff{$\\Rot$, $\\bth$, and $q$ all represent orientations. That's the problem with notation that separates the representation not the semantic (though we might need that separation later).}\n        }\\label{fig:imaging-geometry}\n    \\end{minipage}\n    \\hfill\n    \\begin{minipage}[t]{0.48\\linewidth}\n        \\centering\n        \\includegraphics[height=0.7\\linewidth]{intuition-method}\n        \\caption{%\n            Single-particle cryo-EM produces $P$ projections (with $P$ in the order of $10^5$) from unknown orientations: $\\{(\\p_i, q_i)\\}_{i=1}^P$.\n            Observing that distances between orientations constrain the latter, we aim to \\textit{recover the orientations} $\\{q_i\\}$ from $\\{d_q(q_i, q_j)\\}$, where $d_q(q_i, q_j)$ is the distance (angle) between orientations $q_i$ and $q_j$.\n            Observing that the similarity between projections depends on their relative orientation, we aim to \\textit{estimate the distance} $d_q(q_i, q_j)$ from the projections $(\\p_i, \\p_j)$.\n            % \\todo{The projections don't look to be on the surface of the sphere: They should be on tangent planes.}\n            % \\todo{The gray line to the center is the projection direction to be labeled $(\\theta_1, \\theta_2)$ with a color consistent with \\figref{imaging-geometry}.}\n            % \\todo{The two green arcs seems too much like a single one.}\n        }\\label{fig:intuition-method}\n    \\end{minipage}\n\\end{figure}\n\n% RELATED WORKS\n\nA popular approach is to alternatively refine the 3D structure and estimated orientations~\\cite{penczek1994ribosome,Baker1996,Dempster1977,sigworth1998maximum,scheres2012bayesian,zehni2020joint}.\nYet, the outcome of these iterative-refinement procedures is often predicated on the quality of the initial reconstruction, or, equivalently, on the initial estimation of the orientations~\\cite{sorzano2006optimization,henderson2012outcome}.\n\nSeveral methods have been designed to produce a first rough \\textit{ab initio} structure for the refinement procedure~\\cite{singer2020computational}. \\textit{Moment-matching} techniques~\\cite{kam1980reconstruction, salzman1990method,goncharov1988integral,sharon2019method} reconstruct an initial structure such that the first few moments of the distribution of its theoretical measurements match the ones of its experimental projections; however, they typically remain sensitive to error in data and can require relatively high computational complexity. Based on the central-slice theorem, \\textit{common-lines} methods~\\cite{van1987angular, penczek1994ribosome,mallick2006structure,singer2010detecting,wang2013orientation,greenberg2017common,pragier2019common} aim at uniquely determining the orientations of each projection by identifying the common-lines between triplets of projections---a real challenge given the massive amount of noise. Alternatively, the marginalized maximum likelihood (ML) formulation of the reconstruction problem~\\cite{sigworth1998maximum}---classically used for the iterative-refinement procedures themselves---can be minimized using stochastic gradient descent~\\cite{punjani2017cryosparc}.\nThis permits to avoid the need for an initial volume estimate, at the possible cost of greater convergence instability.\n\nMore recently, the recovery of geometrical information from unknown view tomography of 2D point sources has been proposed~\\cite{zehni2019distance}, but the extension to 3D cryo-EM tomography is not straightforward.\nFinally,~\\cite{miolane2019estimation} proposed to recover the in-plane rotations by learning to embed projections in an appropriate latent space, but only after directions had been estimated through three rounds of 2D classification in RELION\\@.\n\n%Several methods have been designed to produce a first rough \\textit{ab initio} structure for the refinement procedure~\\cite{singer2020computational}.\n%An early approach~\\cite{kam1980reconstruction} proposed to reconstruct an initial structure such that the first few moments of the distribution of its theoretical measurements match the ones of its experimental projections.\n%Since then, \\textit{moment-matching} techniques have been refined and extended~\\cite{salzman1990method,goncharov1988integral,sharon2019method}, \\eg, to accommodate for non-uniform orientation configurations.\n%However, they typically remain sensitive to error in data and can require relatively high computational complexity.\n\n%Another popular approach relies on the central-slice theorem, which relates the Fourier transform of a projection to a plane (orthogonal to the projection direction) in the Fourier transform of the 3D object~\\cite{Natterer2001mathematics}.\n%Hence, every two projections \\textit{de facto} share a common 1D intersection in the 3D Fourier domain, and three projections theoretically suffice to define a coordinate system from which their orientations can be deduced~\\cite{van1987angular}.\n%Exploiting this principle, \\textit{common-lines} methods aim at uniquely determining the orientations of each projection by identifying the common-lines between triplets of projections~\\cite{penczek1994ribosome,mallick2006structure,singer2010detecting,wang2013orientation,greenberg2017common,pragier2019common}---a real challenge given the massive amount of noise.\n%If needs be for downside: sensitivity to high-noise levels, small particles, etc.\n\nDespite the aforementioned advances, providing a robust initial volume remains a challenge due to the high-dimensionality and ill-posedness of the underlying optimization problem.\n%\\mdeff{How is our method different from previous work? What's its singularity? Why do we expect it to solve the aforementioned issues? This isn't a survey: The related work is here to build a stage for our work to stand on.}\nOn the other hand, the remarkable ability of convolutional neural networks to capture relevant representations of images has had a profound influence in imaging~\\cite{lecun2015deep}.\n% and our ability to model the imaging / forward model / simulate training data.\n%%%\nIn this work, we present a learning-based approach to recover the unknown orientations directly from the acquired set of projections---without the need for an intermediate reconstruction procedure or an initial volume estimate.\n%, hence bypassing some of the aforementioned limitations.\n% \\mdeff{That's method:} The novelty consists in first estimating the relative distances between pairs of projections (by using a Siamese neural network previously trained on a synthetic dataset), and then recovering the absolute orientation of each projections from these relative distances.\n% By doing so, orientations are recovered without the need for an intermediate reconstruction procedure or an initial volume estimate, which has useful implications for SPA\\@.\n%\\mdeff{``bypassing some limitations'' and ``has useful implications'' are too vague IMO\\@. Could we be more specific? Not on the how (that's the method) but on the why. Think about an ML audience.}\n%\\mdeff{Idea: Our method is direct (as opposed to iterative refinement schemes) and does not require any prior model of the reconstructed protein.}\n%Our two-step method  learns to estimate the unknown orientation $\\bth_i$ (represented by a unit quaternion $q_i$) associated to each projection $\\p_i$ in a single-particle cryo-EM dataset without relying on any intermediate reconstruction procedure.\n\n%\\mdeff{Content. (p1) Why is the general problem of protein reconstruction important and difficult. (p2) Short background on single-particle cryo-EM and how reconstruction is done. (p3) Previous work on orientation estimation (or initial structure estimation). If there's none (because people have researched other routes), state it and write why it's an interesting route to explore. How does it compare to initial rough structure estimation? Or whatever the other routes are. (p4) Our contribution on top of previous work.}\n", "meta": {"hexsha": "0025c4e1f25ebe0afdeecace561828c0696cc091", "size": 14540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/1_introduction.tex", "max_stars_repo_name": "mdeff/paper-cryoem-orientation-recovery", "max_stars_repo_head_hexsha": "ebae0e4e28c706c233d88f5c34dd427b4274cb47", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-23T18:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-23T18:20:37.000Z", "max_issues_repo_path": "sections/1_introduction.tex", "max_issues_repo_name": "mdeff/paper-cryoem-orientation-recovery", "max_issues_repo_head_hexsha": "ebae0e4e28c706c233d88f5c34dd427b4274cb47", "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/1_introduction.tex", "max_forks_repo_name": "mdeff/paper-cryoem-orientation-recovery", "max_forks_repo_head_hexsha": "ebae0e4e28c706c233d88f5c34dd427b4274cb47", "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": 107.7037037037, "max_line_length": 1220, "alphanum_fraction": 0.7435350757, "num_tokens": 4061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6367013711973895}}
{"text": "\\section{The {\\tt simplesine} Model}\n\\label{sec:simplesine-model}\n\nIn the following chapters,\nwe use a simple sine wave model, {\\tt simplesine}, to illustrate \\TrickHLA\\ in action.\nUnderstanding the model and how it is used in a Trick \\sdefine file\nis important for those chapters.\nThis section introduces \\simplesine with that in mind.\n\n% -----------------------------------------------------------------------\n\\subsection{Description}\n\nThe system modeled by \\simplesine is an undamped harmonic oscillator,\nthe dynamics of which are governed by the differential equation\n\\begin{equation}\n\\ddot{x} + w^2 x = 0,\n\\label{eq:EOM}\n\\end{equation}\nwhich has an analytic solution of the form\n\\begin{subequations}\n\\label{eq:analytic-equations}\n\\begin{align}\nx(t)       &= A        \\sin {(\\omega t + \\phi)}, \\\\\n\\dot{x}(t) &= A \\omega \\cos {(\\omega t + \\phi)}.\n\\end{align}\n\\end{subequations}\n\nThe relevant model data are\nthe dynamic {\\em state}, $(x, \\dot{x})$ and\nthe constant system {\\em parameters}, $(A, \\phi, \\omega)$,\nwhere the parameters are specified as inputs\nand the state is calculated dynamically as simulation outputs.\\footnote{\nIn this model, the initial state cannot be specified as inputs explicitly\nbut rather through the parameters $A$ and $\\phi$.\n}\n\nThe \\simplesine model has functions that may be used to calculate the state\nanalytically based on equations~\\ref{eq:analytic-equations}.\nIt can also propagate the state approximately\nbased on numerical integration of the differential equations.\nThe integration involves the calculation of the derivative of\nthe 2-vector $\\boldsymbol{z}$ defined as\n\n\\begin{equation}\n\\label{eq:differential-equations}\n  \\boldsymbol{z}(t)\n  \\equiv \\left\\{\n            \\begin{array}{c}\n              x(t)\\\\ \\dot{x}(t)\n            \\end{array}\n     \\right\\} \\\\\n  = \\left\\{\n            \\begin{array}{r}\n              A \\sin{(\\omega t + \\phi)} \\\\ A \\omega \\cos{(\\omega t + \\phi)}\n            \\end{array}\n     \\right\\}\n\\end{equation}\n\nSo that\n\n\\begin{equation}\n\\label{eq:derivative-equations}\n  \\dot{\\boldsymbol{z}}(t)\n  = \\left\\{\n            \\begin{array}{c}\n              \\dot{x}(t)\\\\ \\ddot{x}(t)\n            \\end{array}\n     \\right\\} \\\\\n  = \\left\\{\n            \\begin{array}{r}\n              \\dot{x}(t)\\\\ - \\omega^2 x(t)\n            \\end{array}\n     \\right\\} \\\\\n  = \\left\\{\n            \\begin{array}{r}\n                    A w \\cos{(\\omega t + \\phi)} \\\\\n                    - A w^2 \\omega \\sin{(\\omega t + \\phi)}\n            \\end{array}\n     \\right\\}\n\\end{equation}\n\n% -------------------------------------\n\\subsection{Model}\n\nThe source code for the \\simplesine model is organized into three directories:\n{\\tt data}, {\\tt include} and {\\tt src}.\nThe files in these directories are discussed below.\n\n% ----------\n\\subsubsection{Include Files}\n\nThe \\simplesine C/C++ include files are in directory {\\tt simplesine/include}.\nA list of the files is shown below.\n\n{\n\\begin{center}\n\\scriptsize\n\\begin{tabular}{|l|l|}\n\\hline\n{\\em filename} \\\\\n\\hline\n\\hline\n{\\tt simplesine.h} \\\\\n\\hline\n{\\tt simplesine\\_InteractionHandler.h} \\\\\n\\hline\n{\\tt simplesine\\_LagCompensator.h} \\\\\n\\hline\n{\\tt simplesine\\_Packing.h} \\\\\n\\hline\n{\\tt simplesine\\_proto.h} \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n}\n\n\\paragraph{\\tt simplesine.h}\nThis file declares the fundamental \\simplesine data structures.\nThere is a single data structure that in turn holds state- and parameter-related\ndata structures.\nIn the simulations that follow, the {\\tt simplesine\\_T} structure will be\nfrequently declared as a {\\tt sim\\_object} in the \\sdefine files\nwhen the simulations need to model a sine wave.\n\nThe {\\tt simplesine\\_T} structure consists of a {\\em state} substructure,\nwhich holds $x$ and $\\dot{x}$\nand a parameters substructure which holds the constant {\\em parameters,}\n$A$, $\\phi$ and $\\omega$.\nIn this model, only the parameters\nmay be set from the input processor.\nThe state may only be calculated by a Trick job.\nThe purpose of this is to ensure that the state and parameters are never\ninitialized to inconsistent values.\\footnote{\n  Of course, this requires that developers remember to explicitly\n  call {\\tt simplesine\\_calc()} as an initialization job for every\n  \\simplesine sim variable.\n}\n\nThe complete file is shown in Appendix~\\ref{sec:simplesine-h}.\n\n\\paragraph{\\tt simplesine\\_proto.h}\nThis file declares the C functions exported by the \\simplesine model.\nThese functions may be used in an \\sdefine file as Trick jobs.\nFunctions of particular interest are\n\\begin{itemize}\n  \\item{\\tt simplesine\\_calc()}, which calculates the state, $(x, \\dot{x})$\n    according to equations~\\ref{eq:analytic-equations},\\footnote{\n      Since only the \\simplesine parameters have default values,\n      this job may be used as an initialization job to initialize\n      the state from the parameters.\n    }\n  \\item{\\tt simplesine\\_deriv()} and {\\tt simplesine\\_integ()}, which\n    are used to numerically integrate equations~\\ref{eq:differential-equations}\n    using the standard Trick integration scheme,\n  \\item{\\tt simplesine\\_copyXXX()}, several routines which copy \\simplesine\n    data from one data structure to another, and\n  \\item{\\tt simplesine\\_calcError()}, which calculates the error between\none \\simplesine state and the true values based on equations~\\ref{eq:analytic-equations}.\n\\end{itemize}\n\n\nThe complete file is shown in Appendix~\\ref{sec:simplesine-proto-h}.\n\n\\paragraph{\\tt simplesine\\_InteractionHandler.hh}\nThis file declares the \\simplesine C++ class which acts as a\n\\TrickHLA\\ {\\em interaction handler}.\nIt is a subclass of {\\tt TrickHLAInteractionHandler},\nwhich is the \\TrickHLA\\ class which defines how interactions\nare sent and received.\n\nThe complete file is shown in Appendix~\\ref{sec:simplesine-InteractionHandler-hh}.\n\n\\paragraph{\\tt simplesine\\_LagCompensator.hh}\nThis file declares the \\simplesine C++ class which acts as a\n\\TrickHLA\\ {\\em lag compensator}.\nIt is a subclass of {\\tt TrickHLALagCompensator},\nwhich is the \\TrickHLA\\ class which defines how federates may compensate\nfor HLA-time lags created as a result of sending data to remote federates\nand transfering ownership between federates.\n\nThe complete file is shown in Appendix~\\ref{sec:simplesine-LagCompensator-hh}.\n\n\\paragraph{\\tt simplesine\\_Packing.hh}\nThis file declares the \\simplesine C++ class which may be optionally\nused by developers to {\\em pack} outbound data prior to sending via HLA\nand {\\em upack} is upon receipt from HLA.\nIt is a subclass of {\\tt TrickHLAPacking},\nwhich has {\\tt pack()} and {\\tt unpack()} virtual methods that implement\nthe application-specific packing and unpacking logic.\n\nThe complete file is shown in Appendix~\\ref{sec:simplesine-Packing-hh}.\n\n\n% ----------\n\\subsubsection{Source Files}\n\nThe \\simplesine C/C++ source files are in the directory {\\tt simplesine/src}.\n\nThe implementation of the \\simplesine functions and classes is in\n{\\tt .c} and {\\tt .cpp} files located in the {\\tt simplesine/src} directory.\nThe C functions are mainly implemented one function per file\\footnote{\n  The copy functions\n  ({\\tt simplesine\\_copyParams()},\n  {\\tt simplesine\\_copyParams()}, and\n  {\\tt simplesine\\_copyParams()})\n  are located in a single file, {\\tt simplesine\\_copy.c}.\n},\nand the C++ classes are implemented one class per file.\nThe file names are shown in the table below:\n\n{\n\\begin{center}\n\\scriptsize\n\\begin{tabular}{|l|l|}\n\\hline\n{\\em filename} & {\\em implements what?} \\\\\n\\hline\n\\hline\n{\\tt simplesine\\_calc.c} & {\\tt simplesine\\_copy()} \\\\\n\\hline\n{\\tt simplesine\\_calcError.c} & {\\tt simplesine\\_calcError()} \\\\\n\\hline\n{\\tt simplesine\\_compensate.c} & {\\tt simplesine\\_compensate()} \\\\\n\\hline\n{\\tt simplesine\\_copy.c} & the {\\tt simplesine\\_copyXXX()} functions \\\\\n\\hline\n{\\tt simplesine\\_deriv.c} & {\\tt simplesine\\_deriv()} \\\\\n\\hline\n{\\tt simplesine\\_integ.c} & {\\tt simplesine\\_integ()} \\\\\n\\hline\n{\\tt simplesine\\_propagate.c} & {\\tt simplesine\\_propagate()} \\\\\n\\hline\n\\hline\n{\\tt simplesine\\_InteractionHandler.cpp} & the \\TrickHLA\\ interaction handler class \\\\\n\\hline\n{\\tt simplesine\\_LagCompensator.cpp} & the \\TrickHLA\\ lag compensator class \\\\\n\\hline\n{\\tt simplesine\\_Packing.cpp} & the \\TrickHLA\\ packing/unpacking class \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n}\n\n\n% ----------\n\\subsubsection{Data Files}\n\nThis {\\tt simplesine/data} directory\nconsists Trick input files for default \\simplesine data.\n\nDepending on how you build your \\sdefine file, these files may be used\nas ``fallback'' initializations for your data.\nIn the simulations that follow, the actual initial values\nwill often override the defaults in these files.\\footnote{\n  Sine the \\simplesine state data are output-only,\n  they cannot be set directly from the Trick input processor.\n  Consequently, there is no default data file for\n  {\\tt simplesine\\_state\\_T}.\n}\n\nThe files are shown below.\n\n{\n\\begin{center}\n\\scriptsize\n\\begin{tabular}{|l|l|}\n\\hline\n{\\em filename} & {\\em description} \\\\\n\\hline\n\\hline\n{\\tt integ.d}\n  &\n  Default numerical integration parameters.\n  \\\\\n\\hline\n{\\tt simplesine.d}\n  &\n  Default \\simplesine parameters with uninitialized state.\n  \\\\\n\\hline\n\\hline\n{\\tt simplesine\\_params.d}\n  &\n  Default \\simplesine parameters.\n  \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n}\n", "meta": {"hexsha": "ea897b4602af19b541330f12038aa6df08c2ef00", "size": 9194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/TrickHLA/LaTeX/TrickHLAUser-prelim-simplesine.tex", "max_stars_repo_name": "jiajlin/TrickHLA", "max_stars_repo_head_hexsha": "ae704b97049579e997593ae6d8dd016010b8fa1e", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2020-03-04T14:23:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T10:47:21.000Z", "max_issues_repo_path": "docs/TrickHLA/LaTeX/TrickHLAUser-prelim-simplesine.tex", "max_issues_repo_name": "jiajlin/TrickHLA", "max_issues_repo_head_hexsha": "ae704b97049579e997593ae6d8dd016010b8fa1e", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 57, "max_issues_repo_issues_event_min_datetime": "2020-06-04T16:03:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-17T20:54:35.000Z", "max_forks_repo_path": "docs/TrickHLA/LaTeX/TrickHLAUser-prelim-simplesine.tex", "max_forks_repo_name": "jiajlin/TrickHLA", "max_forks_repo_head_hexsha": "ae704b97049579e997593ae6d8dd016010b8fa1e", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-08-25T05:51:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T18:37:38.000Z", "avg_line_length": 31.7034482759, "max_line_length": 89, "alphanum_fraction": 0.7054600827, "num_tokens": 2468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7879311981328134, "lm_q1q2_score": 0.6367013677464728}}
{"text": "\\section{Predicate Logic \\& Correctness}\n\n\\begin{itemize}\n\t\n\t\\item Propositional operators\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item not ($ \\lnot $), and ($ \\land $), or ($ \\lor $)\n\t\t\n\t\t\\item implication ($ \\implies $) -- $ P \\implies Q \\equiv \\lnot P \\lor Q $\n\t\t\n\t\t\\item equivalence ($ \\iff $) -- $ P \\iff Q \\equiv (P \\implies Q) \\land (Q \\implies P)$\n\t\t\n\t\\end{itemize}\n\t\n\t\\item Operator precedence (tightest-binding first): $ \\lnot $, $ \\land $, $ \\lor $, $ \\implies $\n\t\n\t\\item Quantifiers\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item for all ($ \\forall $)\n\t\t\n\t\t\\item there exists ($ \\exists $)\n\t\t\n\t\t\\item Example: $ \\forall x \\in \\mathbb{N} \\cdot x \\ge 0 $\n\t\t\n\t\t\\item The type of the bound variable may be implicit, e.g. $ \\forall x \\cdot x \\ge 0 $\n\t\t\n\t\\end{itemize}\n\n\t\\item Entailment\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P \\implies Q $ is a tautology (always true) then $ P $ is stronger than $ Q $\n\t\t\n\t\t\\item Equivalently: $ P $ entails $ Q $ ($ P \\entails Q $)\n\t\t\n\t\\end{itemize}\n\n\t\\item Substitution\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ P[x \\backslash a] $ -- Substitute all occurrences of $ x $ by $ a $ in $ P $\n\t\t\n\t\t\\item $ P[x, y \\backslash a, b] $ -- Substitute $ a $ and $ b $ for $ x $ and $ y $ \\textbf{simultaneously}\n\t\t\n\t\\end{itemize}\n\n\t\\item Hoare triples -- $ \\hoare{P}{S}{Q} $\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ P $ is the precondition, $ S $ is the program and $ Q $ is the postcondition\n\t\t\n\t\t\\item If $ P $ is true before $ S $ executes, then $ S $ will terminate and $ Q $ will be true when it does\n\t\t\n\t\t\\item The program must terminate if started in $ \\text{States}_{_P} $ (total correctness)\n\t\t\n\t\\end{itemize}\n\t\n\t\\item Weakest preconditions\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item For a program $ S $ and postcondition $ Q $, $ wp(S, Q) $ is the unique weakest possible precondition such that the triple $ \\hoare{P}{S}{Q} $ will be true\n\t\t\n\t\t\\item $ \\forall P \\cdot (\\hoare{P}{S}{Q}) \\implies (P \\entails wp(S, Q)) $\n\t\t\n\t\\end{itemize}\n\t\t\n\\end{itemize}", "meta": {"hexsha": "0beb71b11ae3effc3d185aff1736be9855aebc32", "size": 1929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSSE3100/predicate.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": "CSSE3100/predicate.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": "CSSE3100/predicate.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": 25.72, "max_line_length": 163, "alphanum_fraction": 0.6018662519, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.636701365734451}}
{"text": "\\subsection{Simplifications}\n\n\\begin{frame}\n  \\frametitle{Simplifications}\n\n  \\scriptsize\n\n  We use {\\bf simplification} rules to fight the two problems in previous slide,\n  before bit-blasting everything\n  \\vfill\n  \\pause\n  \\begin{center}\n  \\scalebox{.4}{\\input{simplification.pdf_t}}\n  \\end{center}\n  \\vfill\n  \\pause\n  Simplifications exploit properties of \\bitvectors to try to reduce\n  the complexity of the formula. We see here some examples, but many\n  more rules do exist. Also, it is very important the way they are\n  combined together \n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Trivial Simplifications}\n\n  The following are trivial consequences of the semantic of \\bitvectors and\n  \\formulae in general\n  \\vfill\n  \\pause\n  \\bitvectors trivial simplifications\n  \\begin{itemize}\n    \\item $t = t\\ \\Rightarrow\\ \\top$\\ \\ \\ \\ for a generic term\n    \\item $c = d\\ \\Rightarrow\\ \\bot$\\ \\ \\ \\ for two different constants $c$ and $d$\n    \\item $t \\band 0\\ldots0\\ \\Rightarrow\\ 0\\ldots0$\\ \\ \\ \\ for a generic term\n    \\item \\ldots\n  \\end{itemize}\n  \\vfill\n  \\pause\n  \\begin{itemize}\n    \\item $\\varphi \\wedge \\varphi\\ \\Rightarrow\\ \\varphi$\\ \\ \\ \\ for a generic formula\n    \\item $\\varphi \\wedge \\top\\ \\Rightarrow\\ \\varphi$\\ \\ \\ \\ for a generic formula\n    \\item $\\varphi \\vee \\top\\ \\Rightarrow\\ \\top$\\ \\ \\ \\ for a generic formula\n    \\item \\ldots\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Ground Term evaluation}\n  \n  If a term is {\\bf ground}, i.e., it contains no variables, then it\n  can be always simplified to a single constant\n  \\vfill\n  \\pause\n  Examples:\n  \\begin{itemize}\n    \\item $0000 :: 1000\\ \\Rightarrow 00001000$\n    \\item $0010[1:0]\\ \\Rightarrow 10$\n    \\item $0100 + 0101\\ \\Rightarrow 1001$\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Variable Elimination Rule}\n\n  Suppose that the input formula $\\varphi$ is of the kind\n  \\vfill\n  $$\n  \\varphi'\\ \\wedge\\ (\\w{x}{n} = \\w{t}{n})\n  $$\n  \\vfill\n  where $\\w{x}{n}$ is a variable, and $\\w{t}{n}$ is a term {\\bf not containing} $\\w{x}{n}$\n  \\pause\n  \\vfill\n  then we can rewrite $\\varphi$ as\n  $$\n  \\varphi'[\\w{t}{n}/\\w{x}{n}]\n  $$\n  \\vfill\n  i.e., we replace every occurrence of $\\w{x}{n}$ by $\\w{t}{n}$. \\pause We save $n$\n  Boolean variables in the reduction to SAT\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Concatenation Elimination Rule}\n\n  Suppose that we have the equality\n  \\vfill\n  $$\n  \\w{t}{n} :: \\w{s}{m} = \\w{r}{n} :: \\w{u}{m}\n  $$\n  \\vfill\n  then, because the concatenations {\\bf match}, we can rewrite it as\n  \\pause\n  \\vfill\n  $$\n  (\\w{t}{n} = \\w{r}{n}) \\wedge (\\w{s}{m} = \\w{u}{m}) \n  $$\n  \\vfill\n  this rewriting may give more opportunity for applications of previous rules\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Exercizes}\n\n  \\begin{enumerate}\n\n    \\item Complete the missing cases in procedures Bit-Blast-Term and Bit-Blast\n    \\vfill\n    \\item Bit-Blast the formula $\\neg(\\w{x}{3} = 000) \\wedge (\\w{x}{3} \\band \\w{y}{3}) = (\\w{x}{3} + \\w{y}{3})$ \n    \\vfill\n    \\item Simplify the formula $(\\w{x}{4} :: \\w{y}{4}) = (\\w{z}{4} :: \\w{x}{4}) \\wedge \\neg( \\w{y}{4} = \\w{z}{4})$ \n\n  \\end{enumerate}\n\n\\end{frame}\n", "meta": {"hexsha": "ebe4234956d99da3f56c9327c6ff04c9f0dd718b", "size": 3117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture2/simplification.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": "lecture2/simplification.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": "lecture2/simplification.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": 25.7603305785, "max_line_length": 115, "alphanum_fraction": 0.6374719281, "num_tokens": 1096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6367013637224292}}
{"text": "\n\\subsection{Cubic polynomials}\n\nCubic polynomials are of the form \\(ax^3+bx^2+cx+d=0\\).\n\n\\subsection{Solving specific cases}\n\nWe start by solving when \\(b=0\\), that is:\n\n\\(aX^3+bx+c=0\\)\n\n\\subsection{Solving the general case}\n\n", "meta": {"hexsha": "fb26c82d5bb2a9d448bb735fd859ae7413bb48ec", "size": 227, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/polynomialsMulti/03-01-cubic.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/polynomialsMulti/03-01-cubic.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/polynomialsMulti/03-01-cubic.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.2142857143, "max_line_length": 55, "alphanum_fraction": 0.704845815, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6365078817915104}}
{"text": "\\section{Average Value of a Function}{}{}\\label{sec:Average Value}\nThe average of some finite set of values is a familiar concept. If,\nfor example, the class scores on a quiz are 10, 9, 10, 8, 7, 5, 7, 6,\n3, 2, 7, 8, then the average score is the sum of these numbers divided\nby the size of the class:\n$$\n  \\hbox{average score} = {10+ 9+ 10+ 8+ 7+ 5+ 7+ 6+\n  3+ 2+ 7+ 8\\over 12}={82\\over 12}\\approx 6.83.\n$$\nSuppose that between $t=0$ and $t=1$ the speed of an object is\n$\\sin(\\pi t)$. What is the average speed of the object over that time?\nThe question sounds as if it must make sense, yet we can't merely add\nup some number of speeds and divide, since the speed is changing\ncontinuously over the time interval.\n\nTo make sense of ``average'' in this context, we fall back on the idea\nof approximation. Consider the speed of the object at tenth of a\nsecond intervals: $\\sin 0$, $\\sin(0.1\\pi)$, $\\sin(0.2\\pi)$,\n$\\sin(0.3\\pi)$,\\dots, $\\sin(0.9\\pi)$. The average speed ``should'' be\nfairly close to the average of these ten speeds:\n$$\n  {1\\over 10}\\sum_{i=0}^9 \\sin(\\pi i/10)\\approx {1\\over 10}6.3=0.63.\n$$\nOf course, if we compute more speeds at more times, the average of\nthese speeds should be closer to the ``real'' average. If we take the\naverage of $n$ speeds at evenly spaced times, we get:\n$${1\\over n}\\sum_{i=0}^{n-1} \\sin(\\pi i/n).$$\nHere the individual times are $\\ds t_i=i/n$, so rewriting slightly we have\n$${1\\over n}\\sum_{i=0}^{n-1} \\sin(\\pi t_i).$$\nThis is almost the sort of sum that we know turns into an integral;\nwhat's apparently missing is $\\Delta t$---but in fact, $\\Delta t=1/n$,\nthe length of each subinterval. So rewriting again:\n$$\n  \\sum_{i=0}^{n-1} \\sin(\\pi t_i){1\\over n}=\n  \\sum_{i=0}^{n-1} \\sin(\\pi t_i)\\Delta t.\n$$\nNow this has exactly the right form, so that in the limit we get\n$$\n  \\hbox{average speed} = \\int_0^1 \\sin(\\pi t)\\,dt=\n  \\left.-{\\cos(\\pi t)\\over\\pi}\\right|_0^1=\n  -{\\cos(\\pi)\\over \\pi}+{\\cos(0)\\over\\pi}={2\\over\\pi}\\approx\n  0.6366\\approx 0.64.\n$$\n\nIt's not entirely obvious from this one simple example how to compute\nsuch an average in general. Let's look at a somewhat more complicated\ncase. Suppose that the velocity of an object is $\\ds 16\nt^2+5$ feet per second. \nWhat is the average velocity between $t=1$ and $t=3$? Again we\nset up an approximation to the average:\n$${1\\over n}\\sum_{i=0}^{n-1} 16t_i^2+5,$$\nwhere the values $\\ds t_i$ are evenly spaced \ntimes between 1 and 3. Once again we are ``missing'' $\\Delta t$, and\nthis time $1/n$ is not the correct value. What is $\\Delta t$ in\ngeneral? It is the length of a subinterval; in this case we take the\ninterval $[1,3]$ and divide it into $n$ subintervals, so each\nhas length $(3-1)/n=2/n=\\Delta t$. Now with the usual ``multiply and\ndivide by the same thing'' trick we can rewrite the sum:\n$$\n  {1\\over n}\\sum_{i=0}^{n-1} 16t_i^2+5=\n  {1\\over 3-1}\\sum_{i=0}^{n-1} (16t_i^2+5){3-1\\over n}=\n  {1\\over 2}\\sum_{i=0}^{n-1} (16t_i^2+5){2\\over n}=\n  {1\\over 2}\\sum_{i=0}^{n-1} (16t_i^2+5)\\Delta t.\n$$\nIn the limit this becomes\n$${1\\over 2}\\int_1^3 16t^2+5\\,dt={1\\over 2}{446\\over 3}={223\\over 3}.$$\nDoes this seem reasonable? Let's picture it: In\nFigure~\\xrefn{fig:average speed} we see the velocity function together\nwith the horizontal line $y=223/3\\approx 74.3$. Certainly \nthe height of the\nhorizontal line looks at least plausible for the average height of the\ncurve.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,0.4truemm>\n\\setplotarea x from 0 to 3.1, y from 0 to 150\n\\axis bottom ticks numbered from 0 to 3 by 1 /\n\\axis left ticks numbered from 0 to 150 by 25 /\n\\putrule from 1 74.3 to 3 74.3\n\\setquadratic\n\\plot 0.000 5.000 0.150 5.360 0.300 6.440 0.450 8.240 0.600 10.760 \n0.750 14.000 0.900 17.960 1.050 22.640 1.200 28.040 1.350 34.160 \n1.500 41.000 1.650 48.560 1.800 56.840 1.950 65.840 2.100 75.560 \n2.250 86.000 2.400 97.160 2.550 109.040 2.700 121.640 2.850 134.960 \n3.000 149.000 /\n\\setdashes\n\\putrule from 1 0 to 1 74.3\n\\putrule from 3 0 to 3 74.3\n\\endpicture}}\n%\\endtexonly\n%\\htmlfigure{Integration_applications-average_value.html}\n\\caption{\\label{fig:average speed}\nAverage velocity.\n}\n\\endfigure\n\nHere's another way to interpret ``average'' that may make our\ncomputation appear even more reasonable. The object of our example\ngoes a certain distance between $t=1$ and $t=3$. If instead the object\nwere to travel at the average speed over the same time, it should go\nthe same distance. At an average speed of $223/3$ feet per second for\ntwo seconds the object would go $446/3$ feet. How far does it actually\ngo? We know how to compute this:\n$$\\int_1^3 v(t)\\,dt = \\int_1^3 16t^2+5\\,dt={446\\over 3}.$$\nSo now we see that another interpretation of the calculation is:\n$${1\\over 2}\\int_1^3 16t^2+5\\,dt={1\\over 2}{446\\over 3}={223\\over 3}$$\nwhich is the total distance traveled divided by the time in transit, namely,\nthe usual interpretation of average speed.\n\nIn the case of speed, or more properly velocity, we can always\ninterpret ``average'' as total (net) distance divided by time. However, in\nthe case of a different sort of quantity this interpretation does not\nobviously apply, while the approximation approach always does. We might\ninterpret the same problem geometrically: What is the average height\nof $16x^2+5$ on the interval $[1,3]$? We approximate this in exactly\nthe same way, by adding up many sample heights and dividing by the\nnumber of samples. In the limit we get the same result:\n$$\n  \\lim_{n\\to\\infty}{1\\over n}\\sum_{i=0}^{n-1} 16x_i^2+5=\n  {1\\over 2}\\int_1^3 16x^2+5\\,dx={1\\over 2}{446\\over 3}={223\\over 3}.\n$$\nWe can interpret this result in a slightly different way. The area\nunder $y=16x^2+5$ above $[1,3]$ is\n$$\\int_1^3 16t^2+5\\,dt={446\\over 3}.$$ \nThe area under $y=223/3$ over the same interval $[1,3]$ is simply the\narea of a rectangle that is 2 by $223/3$ with area $446/3$. So the\naverage height of a function is the height of the horizontal line that\nproduces the same area over the given interval.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Average Value}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the average height of $\\cos x$ over the intervals\n$[0,\\pi/2]$, $[-\\pi/2,\\pi/2]$, and $[0,2\\pi]$.\n\\begin{sol}\n $2/\\pi$; $2/\\pi$; $0$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the average height of $\\ds x^2$ over the interval\n$[-2,2]$.\n\\begin{sol}\n $4/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the average height of $\\ds 1/x^2$ over the interval\n$[1,A]$.\n\\begin{sol}\n $1/A$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the average height of $\\ds \\sqrt{1-x^2}$ over the interval\n$[-1,1]$.\n\\begin{sol}\n $\\pi/4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n An object moves with velocity $\\ds v(t)=-t^2+1$ feet per second\nbetween $t=0$ and $t=2$. Find the average velocity and the average\nspeed of the object between $t=0$ and $t=2$.\n\\begin{sol}\n $-1/3$, $1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The observation deck on the 102nd floor of the Empire State Building\nis 1,224 feet above the ground. If a steel ball is dropped from the\nobservation deck its velocity at time $t$ is approximately $v(t)=-32t$\nfeet per second. Find the average speed between the time it is dropped\nand the time it hits the ground, and find its speed when it hits the\nground.\n\\begin{sol}\n $\\ds -4\\sqrt{1224}$ ft/s; $\\ds -8\\sqrt{1224}$ ft/s\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "165c46f14b0260cc79139efdd18eea664f6ad5c2", "size": 7487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-4-average-value.org.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": "8-applications-of-integration/8-4-average-value.org.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": "8-applications-of-integration/8-4-average-value.org.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.435, "max_line_length": 76, "alphanum_fraction": 0.6890610391, "num_tokens": 2649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.709019146082187, "lm_q2_score": 0.8976952934758465, "lm_q1q2_score": 0.6364831504222429}}
{"text": "\n\\subsection{Modelling homogeneous preferences with multinomial logit}\n\n\\subsection{Recap}\n\nOur model is:\n\n\\(U_{ij}=\\Theta z_{ij} + \\epsilon_{ij}\\)\n\n\\(U_{ij}=\\alpha_i x_j -\\beta_i p_{ij} + \\theta_j d_i +\\epsilon_{ij}\\)\n\n\\subsection{Homogeneous model}\n\nWe model all customers as having the same preferences.\n\n\\(U_{ij}=\\alpha x_j -\\beta p_{ij} + \\theta_j d_i +\\epsilon_{ij}\\)\n\n\\subsection{The multinomial logit assumption}\n\nIf errors are IID and extreme we get:\n\n\\(P_{ij}=\\dfrac{e^{\\Theta z_j}}{\\sum_k e^{\\Theta z_k }}\\)\n\n\\subsection{The outside option}\n\nA user has the option of not buying anything.\n\n\\(U_0=0\\)\n\nThis gives us the following shares:\n\n\\(P_{ij}=\\dfrac{e^{\\Theta z_j}}{e^0+\\sum_{k=1} e^{\\Theta z_k }}\\)\n\n\\(P_{ij}=\\dfrac{e^{\\Theta z_j}}{1+\\sum_{k=1} e^{\\Theta z_k }}\\)\n\n\\subsection{Own-price elasticity of demand}\n\n\\(P_{ij}=\\dfrac{e^{\\Theta z_j}}{1+\\sum_{k=1}} e^{\\Theta z_k }\\)\n\n\\(P_{ij}=\\dfrac{e^{\\alpha x_j -\\beta p_j + \\theta_j d_i}}{1+\\sum_{k=1} e^{ \\alpha x_k -\\beta p_k +\\theta_k d_i}}\\)\n\n\\(\\dfrac{\\delta P_{ij} }{\\delta p_j}\\dfrac{p_j}{P_{ij}}=-\\beta p_j(1-P_{ij})\\)\n\n\\(\\dfrac{\\delta P_{ij} }{\\delta p_k}\\dfrac{p_j}{P_{ij}}=\\beta p_kP_{ij}\\)\n\nThis means that the lower the price, the lower the own price elasticity of demand.\n\nThis means that mark ups are higher for cheaper goods, which doesn't always match reality.\n\nThis can be adjusted by changing the form. For example we could use \\(\\ln p\\) or \\(p^2\\).\n\nHowever, we are still getting the shape by assumption.\n\n\\subsection{Cross-price elasticity of demand}\n\n\\subsection{Getting aggregate market shares}\n\n\\(s_j = \\dfrac{1}{n}\\sum_i P_{ij}\\)\n\n", "meta": {"hexsha": "417eeede2a296b1e01657b01c70ba4cd9296ce82", "size": 1614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumerDiscrete/03-01-discrete.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/consumerDiscrete/03-01-discrete.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/consumerDiscrete/03-01-discrete.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.9, "max_line_length": 114, "alphanum_fraction": 0.6790582404, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703476, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6364831475113657}}
{"text": "\\documentclass[letter]{article}\n\\renewcommand{\\baselinestretch}{1.25}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{pythonhighlight}\n\\usepackage{hyperref}\n\n\\allowdisplaybreaks\n\n%opening\n\\title{MECH 6327 - Homework 2}\n\\author{Jonas Wagner}\n\\date{2021, March 3}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\\textbf{(Probably not necessary... but its long)}\n\\tableofcontents\n\n\\newpage\n\\section{Problem Set 1: Convex Sets}\n\n\\subsection{Problem 2.5}\n\\textbf{Problem:}\\\\\nWhat is the distance between two parallel hyperplanes: $\\{x \\in \\real^n | a^T x = b_1\\}$ and $\\{x \\in \\real^n | a^T x = b_2\\}$?\\\\\n\n\\noindent\n\\textbf{Solution:}\\\\\nUnder the assumption that $a\\in \\real^n$ and $b_1,b_2 \\in \\real$, the quantity $a^T x_0$ represents the component of $x_0$ in the normal direction. Similarly, the quantities $b_1$ and $b_2$ represent the euclidean distance of the hyperplane from the origin (in the normal direction). Since the hyperplanes are parrellel, the distance between them is the difference between their offsets:\n\\begin{equation}\n\t\\text{Distance between hyperplanes: } b_1 - b_2\n\\end{equation}\n\n\n\\subsection{Problem 2.7}\n\\textbf{Problem:}\\\\\n\\textit{Voronoi description of halfspace.} Let $a$ and $b$ be distinct points in $\\real^n$. Show that the set of all points that are closer to $a$ than $b$ via the euclidean norm is a halfspace. Describe it explicitly as an inequality and draw a picture.\n\n\\noindent\n\\textbf{Solution:}\\\\\nThe set of all points closer to $a$ then $b$ can be defined as:\n\\begin{equation}\n\t\\{x \\in \\real^n \\ | \\ \\norm{x-a}_2 \\leq \\norm{x-b}_2\\}\n\\end{equation}\n\nThe boundary defining this halfspace will be a plane defined by the normal vector $c$ representing the distance between $a$ and $b$, and the offset coefficient $d$ describing intersection of the plane through the half-way point between $a$ and $b$. The quantities $c$ and $d$ can therefore be defined by:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tc &= b - a\\\\\n\t\td &= \\frac{c^T a + c^T b}{2}\\\\\n\t\t  &= \\frac{1}{2} c^T (a+b)\n\t\\end{aligned}\n\\end{equation}\n\nThe halfspace, that is equivalent to $x$, can be described by the following:\n\\begin{equation}\n\t\\{x\\in \\real^n \\ | \\ c^T x \\leq d\\}\n\\end{equation}\n\nThis can be visualized in two dimensions for $a = \\mqty[2\\\\4]$ and $b = \\mqty[-3\\\\7]$. The boundary (the red line) is calculated in the standard form using $$x_2 = \\frac{-1}{c_2} \\qty(c_1 * x_1 - d)$$ and then plotted. The half-space itself is the region below the boundary.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width = 0.7\\linewidth]{fig/pblm2_7}\n\t\\caption{Visualization of the boundary for the halfspace.}\n\t\\label{fig:pblm2_7}\n\\end{figure}\n\n\n%\\newpage\n\\subsection{Problem 2.12}\n\\textbf{Problem:}\\\\\nWhich of the following sets are convex?\\\\\n\n\\noindent\n\\textbf{Solution:}\n\\subsubsection{(a) - Slab}\nA slab defined as $$\\{x \\in \\real^n \\ | \\ \\alpha \\leq a^T x \\leq \\beta\\}$$ \\textbf{is convex} as it consists of the intersection of two halfspaces which themselves are complex.\n\n\\subsubsection{(b) - Rectangle/Hyperrectangle}\nA rectangle set defined as $$\\{x \\in \\real^n \\ | \\ \\alpha_i \\leq x_i \\leq \\beta_i, \\ i = 1,\\dots,n\\}$$ \\textbf{is convex} as it is composed of the intersections of half spaces which are themselves convex. This is similar to the polyhedrons/polytopes that by definition are also convex.\n\n\\subsubsection{(c) - Wedge}\nA wedge set given as $$\\{x \\in \\real^n \\ | \\ a_1^T x \\leq b_1, a_2^T x \\leq b_2\\}$$ \\textbf{is convex} as it is just an intersection of two halfspaces (a polyhedron).\n\n\\subsubsection{(d) - Closer to a point then a set}\nA set of points closer to a given point than a given set is defined as $$\\{x \\| \\norm{x-x_0}_2 \\leq \\norm{x - y}_2 \\ \\forall y \\in S\\}$$ where $S\\subset\\real^n$ \\textbf{is not convex} in general. This is because there is not enough information about $y$ for a conclusion to be made whether it is convex or not. A counter example would be if $y$ is a point in orbit around a convex shape $S$ that would end up generating a concave $x$.\n\n\\subsubsection{(e) - Closer to a set then another set}\nA set of points closer to a given set than another given set is defined as $$\\{x \\ | \\ \\textbf{dist}(x,S) \\leq \\textbf{dist}(x,T)\\}$$ where $S, T \\subset\\real^n$, and $$\\textbf{dist}(x,S) = \\inf\\{\\norm{x-z}_2 \\ | \\ z \\in S\\}$$ \\textbf{is not convex} in general. This is because there is not enough information about $S$ and $T$ for a conclusion to be made whether it is convex or not. A counter example includes if $S$ or $T$ themselves are a concave shave that causes the set $x$ to also be concave and therefore not convex.\n\n\n\\subsubsection{(f) - Set of the sum being within a convex set}\nThe set defined as $$\\{x \\ | \\ x + S_2 \\subseteq S_1\\}$$ with $S_1$ being convex \\textbf{is not complex} in general. This is because we do not know enough information about $S_2$ to conclude that $x$ is conncex purely due to the relationship with the convex set $S_1$.\\\\\n\n\\subsubsection{(g) - Set with weighted distances to two points}\nThe set of all points that is closer to $a$ then $b$ by at least a factor of $\\theta$, defined as $$\\{x \\in \\real^n \\ | \\ \\norm{x-a}_2 \\leq \\theta \\norm{x-b}_2\\}$$ with $a \\neq b$ and $0 \\leq \\theta \\leq 1$ \\textbf{is convex.} This is know because, as proven in a previous problem, a hyperplane is formed for a similarity stated problem which itself is convex. When the distance to $a$ must be less then a portion of the distance to $b$ it will cause the psudo-hyperplane to curve inwards and untimely remain convex.\n\n\n\\newpage\n\\subsection{Problem 2.28}\n\\textbf{Problem:}\\\\\nDefine the positive semi-definite cone ($S_+^n$) for $n = 1, 2, 3$ in terms of ordinary inequalities with the matrix coefficients themselves.\n\n\\noindent\n\\textbf{Solution:}\\\\\nThe positive semi-definite cone is defined for size $n$ as the set of all symmetric matrices that are positive semi-definite:\n\\begin{equation}\n\tS_+^n \\equiv \\{x \\in S^n \\ | \\ x \\succeq 0\\}\n\\end{equation}\nOne method to ensure that a matrix is positive semi-definite is to ensure that its leading principle minors are all non-negative (strictly positive for positive definite).\\\\\n\nFor $n=1$ the required inequalities are simple, \n\\begin{equation}\n\tX = \\mqty[x_1] \\in S_+^1 \\iff x_1 \\geq 0\n\\end{equation}\n\nFor $n=2$ the inequalities can be found by ensuring the leading principle minors are all non negative:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tm_1 &= \\det[x_1]\\\\\n\t\t&= x_1\\\\\n\t\tm_2 &= \\det \\mqty[x_1 & x_2 \\\\ x_2 & x_3] \\\\\n\t\t&= x_1 x_3 - x_2^2\n\t\\end{aligned}\n\\end{equation}\nThese definitions of the minors can be then be used to construct inequalities such that all the minors are positive:\n\\begin{equation}\n\tX = \\mqty[x_1 & x_2 \\\\ x_2 & x_3] \\in S_+^2 \\ \\iff \\ \\mqty{x_1 \\geq 0\\\\  x_1 x_3 \\geq x_2^2}\n\\end{equation}\n\nFor $n=3$ the inequalities can be found by ensuring the leading principle minors are all non negative:\n\\begin{equation}\n\t\\begin{aligned}\n\t\tm_1 &= \\det[x_1]\\\\\n\t\t&= x_1\\\\\n\t\tm_2 &= \\det \\mqty[x_1 & x_2 \\\\ x_2 & x_4] \\\\\n\t\t&= x_1 x_4 - x_2^2\\\\\n\t\tm_3 &= \\det \\mqty[x_1 & x_2 & x_3\\\\ x_2 & x_4 & x_5\\\\ x_3 & x_5 & x_6]\\\\\n\t\t&= x_1 (x_1 x_4 - x_2^2) - x_2 (x_2 x_6 - x_3 x_5) + x_3 (x_2 x_5 - x_3 x_4)\\\\\n\t\t&= x_1^2 x_4 - x_1 x_2^2 - x_2^2 x_6 + x_2 x_3 x_5 + x_2 x_3 x_5 - x_3^2 x_4\n\t\\end{aligned}\n\\end{equation}\nThese definitions of the minors can be then be used to construct inequalities such that all the minors are positive:\n\\begin{equation}\n\tX = \\mqty[x_1 & x_2 & x_3\\\\ x_2 & x_4 & x_5\\\\ x_3 & x_5 & x_6] \\in S_+^2 \\ \\iff \\ \n\t\\mqty{x_1 \\geq 0\\\\\n\t\t\tx_1 x_4 \\geq x_2^2\\\\\n\t\t x_1 x_2^2 + x_2^2 x_6 + x_3^2 x_4 \\geq x_1^2 x_4 + 2 x_2 x_3 x_5}\n\\end{equation}\n\n\\subsection{Problem 2.33}\nThe monotone non-negative cone is defined as all the nonnegative vectors with components sorted in non-increasing order:\n\\begin{equation}\n\tK_{m+} = \\{x \\in \\real^n \\ | \\ x_1 \\geq x_2 \\geq \\cdots \\geq x_n \\geq n\\}\n\\end{equation}\n\n\\subsubsection{Part a}\n\\textbf{Problem:}\\\\\nShow that $K_{m+}$ is a proper cone.\n\n\\noindent\n\\textbf{Solution:}\\\\\nA set, $C \\subseteq \\real^n$, is considered a cone if\n\\begin{equation}\n\t\\theta x \\in C \\ \\forall x \\in C \\text{ and } \\theta \\geq 0\n\\end{equation}\n\nIt can be easily seen that the set $K_{m+}$ satisfies this condition as scaling each element of the matrix $x \\in K_{m+}$ will equally be scaled by the same amount and the conditions of non-increasing order will still apply. This guarantees that $K_{m+}$ is in fact a cone.\\\\\nTo ensure convexity, the definition of convexity and of a cone can be incorporated into the following test:\\\\\nThe set $C \\subseteq \\real^n$ is a convex cone iff\n\\begin{equation}\n\t\\theta_1 x_1 + \\theta_2 x_2 \\in C \\ \\forall x_1,x_2 \\in C, \\theta_1, \\theta_2 \\geq 0\n\\end{equation}\nIt is also clear that $K_{m+}$ will satisfy as if each element element of one of the matrices is scaled it maintains the nonincreasing order. The same is true for summing two $K_{m+}$ matrices as the nonincreasing order will be maintained.\\\\\nIt is also clear that the cone is closed because the complimentary set $K_{m+}'$ is clearly open.\\\\\nSimilarily, $K_{m+}$ is solid because its definition includes all all of the subspace above the cone's boundary.\\\\\nThe cone is also known to be pointed because the definition defines that all of the vectors contained within the set are nonnegative. It is therefore only ever possible for elements to be in the positive sector (quadrant/octant/etc.). This means the cone cannot contain a line.\\\\\nWe can finish stating that $K_{m+}$ is a proper cone because it is a cone, convex, closed, solid, and pointed.\n\n\\newpage\n\\subsubsection{Part b}\n\\textbf{Problem:}\\\\\nFind the dual cone, $K_{m+}^*$.\n\n\\noindent\n\\textbf{Solution:}\\\\\nA dual cone for $K$ is defined as:\n\\begin{equation}\n\tK^* = \\{y \\in \\real^n \\ | \\ x^ Ty \\geq 0 \\ \\forall x \\in K\\}\n\\end{equation}\nThe left side of the inequality that defines the dual cone can also be written in summation form as: $$x^T y = \\sum_{i=1}^{n} x_i y_i \\geq 0$$\nIt is known that the following is equivalent:\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\sum_{i=1}^{n} x_i y_i &= (x_1 - x_2) y_1 + (x_2 - x_3) (y_1 + y_2) + \\cdots \\\\\n\t\t\t\t\t\t&= + (x_{n-1} - x_n) (y_1 + \\cdots + y_{n-1}) + x_n (y_1 + \\cdots + y_n)\n\t\\end{aligned}\n\\end{equation}\nBy definition, $x_1 \\geq x_2 \\geq \\cdots \\geq x_n \\geq n$, thus it can be said that each $(x_i - x_j)$ term in the expanded form is positive. In order for the inequality to always hold true, each $(y_1 + \\dots + y_i)$, must be positive as well. This can be achieved by defining that the elements of y are never decreasing.\\\\\nThus, the dual cone of $K_{k+}$ can be defined as:\n\\begin{equation}\n\tK_{m+}^{*} = K_{m-} = \\{x \\in \\real_{+}^n \\ | \\ x_1 \\leq x_2 \\leq \\dots \\leq x_n\\} \n\\end{equation}\n\n\n\\newpage\n\\section{Problem Set 2: Convex Functions}\n\n\\subsection{Problem 3.6}\n(Note to self... remember to remove this time: Proofs don't really seem required... pretty simple question)\\\\\n\\textbf{Problem:}\\\\\nWhat is the epigraph for the following convex functions?\\\\\n\n\\noindent\n\\textbf{Solution:}\\\\\nThe epigraph is defined as \n\\begin{equation}\n\t\\textbf{epi} f = \\{(x,t) \\ | \\ x \\in \\textbf{dom} f, f(x) \\leq t\\}\n\\end{equation}\nwhere $\\textbf{epi} f \\subset R^{n+1}$. This is equivalent to saying the space 'above' the function.\n\n\\subsubsection{(a) - Epigraph of a halfspace}\nThe epigraph of a halfspace in $n$ dimensions is a halfspace in $n+1$ dimensions.\n\n\\subsubsection{(b) - Epigraph of a convex cone}\nThe epigraph of a convex cone is another convex cone of in a higher dimension. (It might be possible to generalize it to a triangular slab type thing)\n\n\\subsubsection{(c) - Epigraph of a polyhedron}\nThe epigraph of a polyhedron is another polyhedron.\n\n\\newpage\n\\subsection{Problem 3.16}\n\\textbf{Problem:}\\\\\nDetermine if the following functions are convex, concave, quasiconvex, or quasiconcave.\n\n\\noindent\n\\textbf{Solution:}\\\\\n\\subsubsection{(a) - $e^x - 1$}\nLet $$f(x) = e^x - 1$$ on $\\real$.\\\\\n$f(x)$ \\textbf{is convex} and can be proven in multiple ways. For instance, visualizing the epigraph of the function, it is clear that a convex set is produced. Additionally, $f(x)$ can be constructed by putting the convex function $e^x$ through the convex affine function $x - 1$.\n\n\\subsubsection{(b) - $x_1 x_2$}\nLet $$f(x_1,x_2) = x_1 x_2$$ over the domain $\\real_{++}^2$.\\\\\nThis function \\textbf{is convex} and can be demonstrated using the definition:\n\\begin{align}\n\tf(\\theta x + (1-\\theta)y) &= \\theta f(x) + (1-\\theta) f(y)\\\\\n\t (\\theta x_1 + (1-\\theta) y_1) (\\theta x_2 + (1-\\theta) y_2)&= \\theta x_1 x_2 + (1- \\theta) y_1 y_2\\nonumber\\\\\n\t\\theta^2 x_1 x_2 + \\theta(1-\\theta)y_1 x_2 + \\theta (1-\\theta) x_1 y_2 + (1-\\theta)^2 y_1 y_2 &= \\theta x_1 x_2 + (1- \\theta) y_1 y_2\\nonumber\\\\\n\t\\theta^2 x_1 x_2 + (\\theta-\\theta^2) (x_1 y_2 + x_2 y_1) + (1- 2 \\theta + \\theta^2) y_1 y_2 &= \\theta x_1 x_2 + (1- \\theta) y_1 y_2\n\\end{align}\nIf we analyze each set of terms it not explicitly clear by the result, but within the domain $\\real_{++}^2$ the equality holds true.\n\n\\subsubsection{(c) - $1/(x_1 x_2)$}\nLet $$f(x_1,x_2) = 1/(x_1 x_2)$$ be defined over the domain $R_{++}^2$.\\\\\n\nThis function \\textbf{is convex}.\n\n\\subsubsection{(d) - $x_1/x_2$}\nLet $$f(x_1,x_2) = x_1/x_2$$ be defined over the domain $R_{++}^2$.\\\\\nThis function \\textbf{is convex}.\n\n\\subsection{(e) - $x_1^2 / x_2$}\nLet $$f(x_1,x_2) = x_1^2 / x_2$$ be defined over the domain $R \\cross R_{+}$.\nThis function \\textbf{is convex}.\n\n\n\\subsection{(f) - $x_1^\\alpha x_2^{1-\\alpha}$}\nLet $$f(x_1,x_2) = x_1^\\alpha x_2^{1-\\alpha}$$ with $0 \\leq \\alpha 1$ be defined over the domain $\\real_{++}^2$.\\\\\nThis function \\textbf{is not convex}.\n\n\n\\newpage\n\\subsection{Problem 3.18a}\n\\textbf{Problem:}\\\\\nUsing the proof of concavity of the log-determinant function to show that $$f(X) = \\trace(X^{-1})$$ is convex over the domain $S_{++}^n$.\\\\\n\n\\noindent\n\\textbf{Solution:}\\\\\nA proof of the concavity for the $$f(X) = \\log \\det X$$ is given as follows:\\\\\nGiven an arbritrary line, $X = Z + t V$, with $Z, V \\in S^n$, the function $$g(t) = f(Z + t V)$$ can be defined within $\\{x \\ | \\ Z + t V \\succ 0\\}$. It can then be assumed (without loss of generalizty) that $t = 0$ is in the interval (so that $Z \\succ 0$ is defined). This then allows the following:\n\\begin{align}\n\tg(t) &= \\log \\det(Z+tV)\\\\\n\t\t &= \\log \\det(Z^{1/2} (I + t Z^{-1/2}V Z^{-1/2})Z^{1/2})\\\\\n\t\t &= \\sum_{i=1}^n \\log(1 + t \\lambda_i) + \\log \\det Z\n\\end{align}\nwith $\\lambda_1, \\dots, \\lambda_n$ being the eigenvalues of $Z^{-1/2} V Z^{-1/2}$.\\\\\nThis allows for the first and second derivatives to be computed as:\n\\begin{align}\n\tg'(t) &= \\sum_{i=1}^n \\cfrac{\\lambda_i}{1 + t \\lambda_i}\\\\\n\tg''(t) &= -\\sum_{i=1}^n \\cfrac{\\lambda_i^2}{(1 + t \\lambda_i)^2}\n\\end{align}\nSince $g''(t) \\leq 0$, it can be concluded that $f$ is concave.\\\\\n\nThis proof can then be applied to the trace(X{-1}) is also concave.\\\\\nFirst, Let\n\\begin{equation}\n\tf(X) = \\trace(X^{-1})\n\\end{equation}\nbe defined on the domain $\\mathbf{S}_{++}^n$.\\\\\nAn arbritrary line can then be defined as\n\\begin{equation}\n\tg(t) = f(Z + tV)\n\\end{equation}\nover the domain $\\{x \\ | \\ Z + t V \\succ 0\\}$.\nIt can then be assumed (without loss of generality) that $t = 0$ is in the interval (so that $Z \\succ 0$ is defined). This then allows the following:\n\\begin{align}\n\tg(t) &= \\trace\\qty(\\qty(Z+tV)^{-1})\\\\\n\t&= \\trace\\qty(\\qty(Z^{1/2} (I + t Z^{-1/2}V Z^{-1/2})Z^{1/2})^{-1})\\\\\n\t\\intertext{from the fact that $(ABC)^{-1} = C^{-1}B^{-1}A^{-1}$, this can be manipulated to be}\n\t&= \\trace\\qty(Z^{-1/2} \\qty(I + t Z^{-1/2}V Z^{-1/2})^{-1}Z^{-1/2})\\\\\n\t\\intertext{since $\\trace(ABC) = \\trace(CAB)$,}\n\t&= \\trace\\qty(Z^{-1/2} Z^{-1/2} \\qty(I + t Z^{-1/2} V Z^{-1/2})^{-1})\\\\\n\t\\intertext{by taking the eigenfactor decomposition of $Z^{-1/2} V Z^{-1/2} = Q \\Lambda Q^{-1}$, this can be rewritten as:}\n\t&= \\trace\\qty(Z^{-1} \\qty(I + t Q \\Lambda Q^{-1})^{-1})\\\\\n\t&= \\trace\\qty(Z^{-1} \\qty(Q \\qty( I + t \\Lambda )Q^{-1})^{-1})\\\\\n\t&= \\trace\\qty(Z^{-1} Q \\qty( I + t \\Lambda)^{-1}Q^{-1})\\\\\n\t\\intertext{since $\\trace(ABC) = \\trace(CAB)$,}\n\t&= \\trace\\qty(Q Z^{-1} Q^{-1}\\qty( I + t \\Lambda)^{-1})\\\\\n\t\\intertext{By the definition of the trace, we can rewite this as}\n\t&= \\sum_{i=1}^n \\qty(Q^T Z^{-1} Q)_{ii} \\qty(1 + t \\lambda_i)^{-1}\n\\end{align}\nThis allows for the first and second derivatives to be computed as:\n\\begin{align}\n\tg'(t) &= -\\sum_{i=1}^n \\qty(Q^T Z^{-1} Q)_{ii} \\cfrac{\\lambda_i}{\\qty(1 + t \\lambda_i)^{-2}}\\\\\n\tg''(t) &= 2\\sum_{i=1}^n \\qty(Q^T Z^{-1} Q)_{ii} \\cfrac{\\lambda_i^2}{\\qty(1 + t \\lambda_i)^{-3}}\n\\end{align}\nSince $g''(t) \\leq 0$, it can be concluded that $f$ is concave.\\\\\n\n\n\\newpage\n\\subsection{Problem 3.22}\n\\textbf{Problem:}\\\\\nUse various composition rules to show that the following functions are convex.\n\n\\noindent\n\\textbf{Solution:}\\\\\n\\subsubsection{(a) - double log functions}\nLet $$f(x) = -\\log(-\\log(\\sum_{i=1}^m e^{a_i^T x + b_i}))$$ be defined over the domain $\\{x \\ | \\ \\sum_{i=1}^m e^{a_i^T x + b_i} < 1\\}$.\\\\\nIt is known that $$\\log(\\sum_{i=1}^{n} e^{y_i})$$ is convex. Since all compositions of convex functions with affine functions are also convex, it can be said that $$\\sum_{i=1}^m e^{a_i^T x + b_i}$$ is also convex.\\\\\nAdditionally, it is known that the $\\log()$ function is concave, but when the sign changes it becomes convex, thus the composition of $-g(-g(h(x)))$ is convex for the concave function $g(x) = \\log(x)$.\\\\\nTherefore, the function $f(x)$ is convex.\n\n\\subsubsection{(b) - square root of some product sum}\nLet $$f(x,u,v) = - \\sqrt{uv - x^T x}$$ be defined over the domain $\\{(x,u,v) \\ | \\ uv > x^T x, u, v > 0\\}$.\\\\\nIt is known that $g(x) = x^x / u$ is convex for $u>0$ and that $h(x)-\\sqrt{x_1 x_2}$ is convex on $\\real_{++}^2$.\\\\\nThe function $f(x,u,v)$ can be manipulated as follows:\n\\begin{align*}\n\tf(x,u,v) \t&= - \\sqrt{uv - x^T x}\\\\\n\t\t\t\t&= - \\sqrt{u \\qty(v -\\cfrac{x^T x}{u})}\n\\end{align*}\nFrom what we know about the underling functions, it can be said that the convex function $g(x)$ is summed with $v$ (a convex combination) and then used as an input to the convex function $h(x)$, resulting in an overall convex function.\n\n\\newpage\n\\subsubsection{(c) - log of some product sum}\nLet $$f(x,u,v) = - \\log(uv - x^T x)$$ be defined over the domain $\\{(x,u,v) \\ | \\ uv > x^T x, u, v > 0\\}$.\\\\\nIt is known that $g(x) = x^x / u$ is convex for $u>0$ as well as that the $h(x) = \\log(x)$ function is concave.\\\\\nPerforming the same manipulation as in the previous problem, $f(x,u,v)$ can be written as: $$f(x,u,v) = -\\log(u \\qty(v - \\cfrac{x^Tx}{u}))$$\nFrom this it can be derived that the convex function $g(x)$ is summed with $v$ (a convex combination) and then used as an input to the concave function $h(x)$ but is then negated to result in an overall convex function.\n\n\n\\subsubsection{(d) - complicated root of a powered sum and norm}\nLet $$ f(x,t) = -\\qty(t^p - \\norm{x}_p^p)^{1/p}$$ be defined with $p>1$ over the domain $\\{(x,t) \\ | \\ t \\geq \\norm{x}_p\\}$.\\\\\nIt is known that $g(x,u) = \\norm{x}_p^p / u^{p-1}$ is convex for $u >0$ and that $h(x,y) = -x^{1/p} y^{1 - 1/p}$ is convex over $\\real_{++}^2$.\\\\\n$f(x,t)$ can be manipulated as follows:\n\\begin{align}\n\tf(x,t)\t&= -\\qty(t^p - \\norm{x}_p^p)^{1/p}\\\\\n\t\t\t&= -\\qty(t^{p-1}\\qty(t - \\cfrac{\\norm{x}_p^p}{t^{p-1}}))^{1/p}\\\\\n\t\t\t&= -t^{1 - 1/p}\\qty(t - \\cfrac{\\norm{x}_p^p}{t^{p-1}})^{1/p}\\\\\n\\end{align}\nFrom this it is clear that the known convex function $g(x,t)$ is put through a weighted sum (which over the domain is never negative) and then is composed with the known convex function $h(x,t)$. This means that the original function $f(x,t)$ is a convex function.\n\n\\newpage\n\\subsubsection{(e) - complicated log of a powered sum and norm}\nLet $$ f(x,t) = - \\log(t^p - \\norm{x}_p^p)$$ with $p >1$ be defined over the domain $\\{(x,t) \\ | \\ t \\geq \\norm{x}_p\\}$.\\\\\nIt is known that $g(x,u) = \\norm{x}_p^p / u^{p-1}$ is convex for $u > 0$ and that (with the negative sign) the function $h(x) = - log(x)$ is convex.\n$f(x,t)$ can be manipulated as follows:\n\\begin{align}\n\tf(x,t)\t&= -\\log(t^p - \\norm{x}_p^p)\\\\\n\t\t\t&= -\\log\\qty(t^{p-1}\\qty(t - \\cfrac{\\norm{x}_p^p}{t^{p-1}}))\\\\\n\t\t\t&= -\\log\\qty(t^{p-1}) - \\log\\qty(t - \\cfrac{\\norm{x}_p^p}{t^{p-1}})\n\\end{align}\nFrom this it is clear that the known convex function $g(x,t)$ is put through a weighted sum (which over the domain is never negative) and then is composed with the known convex function $h(x,t)$. This means that the original function $f(x,t)$ is a convex function.\n\n\\end{document}\n", "meta": {"hexsha": "0837d6c8728681e395c057e6bea0d8ef5053ed6f", "size": 20415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW2/MECH6327-HW2.tex", "max_stars_repo_name": "jonaswagner2826/MECH6327", "max_stars_repo_head_hexsha": "2b55aaf6f9e1bcf5cc684f5c853cadec26acf9d2", "max_stars_repo_licenses": ["MIT"], "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/HW2/MECH6327-HW2.tex", "max_issues_repo_name": "jonaswagner2826/MECH6327", "max_issues_repo_head_hexsha": "2b55aaf6f9e1bcf5cc684f5c853cadec26acf9d2", "max_issues_repo_licenses": ["MIT"], "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/HW2/MECH6327-HW2.tex", "max_forks_repo_name": "jonaswagner2826/MECH6327", "max_forks_repo_head_hexsha": "2b55aaf6f9e1bcf5cc684f5c853cadec26acf9d2", "max_forks_repo_licenses": ["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.0790816327, "max_line_length": 525, "alphanum_fraction": 0.6686749939, "num_tokens": 7271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6364760434048118}}
{"text": "%!TEX root = TTK4150-Summary.tex\n\\section{Feedback linearization}\nConsider a class of nonlinear systems of the form\n\n\\begin{equation}\\label{eq:nonlinear-system}\n\t\\begin{split}\n\t\t\\dot{x} &= f(x) + G(x)u             \\\\\n\t\ty       &= h(x)                     \\\\\n\t\tu       &= \\alpha (x) + \\beta (x) v \\\\\n\t\tz       &= T(x)\n\t\\end{split}\n\\end{equation}\nwhere $u$ is a state feedback conboller, and $T$ is a change of variables.\n\nTo be able to cancel nonlinearities with feedback the input and non-linearities must appear together as a sum $\\lambda (x) + u$ or as a product $\\lambda (x) u$, where the matrix $\\lambda(x)$ is non-singular in the domain of interest, and $u = \\beta(x) v, \\beta(x) = \\lambda^{-1}$.\n\n\\paragraph{Definition 13.1}\nA nonlinear system as \\eqref{eq:nonlinear-system} where $f:D \\to R^n$ and $G : D \\to R^{n \\times p}$ are sufficiently smooth on a domain $D \\subseteq R^n$, is said to be feedback linearizable  (or input-state linearizable) if there exists a diffeomorphism $T:D \\to R^n$ such that $D_z = T(D)$ contains the origin and the change of variables $z = T(x)$ transforms \\eqref{eq:nonlinear-system} into the form\n\\begin{equation}\n\t\\dot{z} = Az + B\\lambda (x) [u - \\alpha(x)]\n\\end{equation}\nwith $(A,B)$ controllable and $\\lambda(x)$ nonsingular $\\forall x \\in D$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Input-output linearization}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nConsider \\eqref{eq:nonlinear-system} which satisfies Def. 13.1. The derivative $\\dot{y}$ is given by\n\\begin{equation}\n\t\\dot{y} = \\pd{h}{x} \\del{f(x) + g(x)} \\triangleq L_f h(x) + L_g h(x) u\n\\end{equation}\nwhere $L_f h(x) \\triangleq \\pd{h}{x} f(x) $ is the \\emph{Lie Derivative} of $h$ w.r.t. $f$.\n\n\\paragraph{Relative degree}\nThe relative degree is the number of times $y$ must be differentiated until $u \\in D_0 \\subseteq D$ appears. A system must have a well defined relative degree to be input-output linearizable. (It must also be minimum phase.)\n\n\\paragraph{Diffeomorphism}\nWikipedia: \\emph{In mathematics, a diffeomorphism is an isomorphism of smooth manifolds. It is an invertible function that maps one differentiable manifold to another such that both the function and its inverse are smooth.}\n\n\\paragraph{Theorem 13.1}\nConsider \\eqref{eq:nonlinear-system} with relative degree $\\rho \\leq n$ in D. If $\\rho = n$, then for every $x_0 \\in D$, a neighborhood N of $x_0$ exists such that the map\n\\begin{equation}\n\tT(x) =\n\t\\left[\n\t\\begin{array}{ccc}\n\t\th(x)     \\\\\n\t\tL_f h(x) \\\\\n\t\t\\vdots   \\\\\n\t\tL_f^{n-1} h(x)\n\t\\end{array}\n\t\\right]\n\\end{equation}\nrestricted to N, is a diffeomorphism on N. If $\\rho < n$, then, for every $x_0 \\in D$, a neighborhood N of $x_0$ and smooth function $\\phi_1 (x), \\dots , \\phi_{n-\\rho} (x)$ exist such that \n\\begin{equation}\n\t\\pd{\\phi_i}{x} g(x) = 0, \\mbox{ for } 1 \\leq i \\leq n-\\rho, \\forall x \\in D_0\n\\end{equation}\nis satisfied $\\forall x \\in N$ and the map\n\\begin{equation}\n\tz = T(x) =\n\t\\left[\n\t\\begin{array}{ccc}\n\t\t\\phi_1(x)         \\\\\n\t\t\\vdots            \\\\\n\t\t\\phi_{n-\\rho}(x)  \\\\\n\t\t---               \\\\\n\t\th(x)              \\\\\n\t\t\\vdots            \\\\\n\t\tL_f^{\\rho-1} h(x)\n\t\\end{array}\n\t\\right]\n\t\\triangleq\n\t\\left[\n\t\\begin{array}{ccc}\n\t\t\\phi(x) \\\\\n\t\t---     \\\\\n\t\t\\psi(x)\n\t\\end{array}\n\t\\right]\n\t\\triangleq\n\t\\left[\n\t\\begin{array}{ccc}\n\t\t\\eta \\\\\n\t\t---  \\\\\n\t\t\\xi\n\t\\end{array}\n\t\\right]\n\\end{equation}\nrestricted to N, is a diffeomorphism on N.\n\n\\paragraph{Method}\n\\begin{enumerate}\n\t\\item Set system on following form $\\dot{x} = f(x) + g(x)u$\n\t\\item Find the relative degree $\\rho$, ($\\rho = n \\Rightarrow$ no internal dynamics)\n\t\\item Write the system in normal form (external and internal dynamics)\n\t\\item Choose $u$ to cancel the nonlinearities\n\t\\item Analyze the zero-dynamics\n\t\\item Choose $v$ to solve the control problem\n\\end{enumerate}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Full-state linearization}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{State feedback control}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "240b4f53551e480eb008d3dd2abbc228fed3af68", "size": 3965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4150 Nonlinear control systems/sec-feedback-linearization.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-feedback-linearization.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-feedback-linearization.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": 37.4056603774, "max_line_length": 404, "alphanum_fraction": 0.6257250946, "num_tokens": 1269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6364760380124257}}
{"text": "% !TEX root = ./Basilisk-avsLibrary20170812.tex\n\n\\section{User Guide}\n\n\\subsection{{\\tt linearAlgebra} Library}\nThe linear algebra library provides numerous C-based functions to perform basic matrix math operations.  For a complete list of functions supported, consult the {\\tt linearAlgebra.h} file. \n\n\\subsubsection{Vector Operations}\nThe vector related functions all begin with a letter '{\\tt v}' and are broken down in the following categories depending on if the linear algebra operation is performed on a matrix of a general size, or of a specific size of 2, 3, 4 or 6.\n\\begin{itemize}\n\t\\item if the function is  {\\tt vXXXX()} the code works on a $n$x1 matrix of arbitrary length $n$.  \n\t\\item if the function is {\\tt v2XXXX()}  the code works on a matrix of length 2 defined as {\\tt double vec[2]}.\n\t\\item if the function is {\\tt v3XXXX()}  the code works on a matrix of length 2 defined as {\\tt double vec[3]}.\n\t\\item if the function is {\\tt v4XXXX()} the code works on a matrix of length 2 defined as {\\tt double vec[4]}.\n\\end{itemize}\n\nThe most extensive set of linear algebra support functions are for operation on 3 and 4 dimensional matrices common with orbital mechanics (position and velocity vector representations) and attitude dynamics (working with 3- and 4-parameter attitude descriptions).  The following list details what vector operation each function performs:\n\\begin{itemize}\n\t\\item {\\tt Copy}: Copies vector $\\bm v_{1}$ into vector $\\bm v_{2}$\n\t\\item {\\tt SetZero}: Returns a zero vector\n\t\\item {\\tt Set}: Sets the vector representation to specific values\n\t\\item {\\tt Add}: Sums  $\\bm v_{1}$ and  $\\bm v_{2}$\n\t\\item {\\tt Subtract}: Returns the difference  $\\bm v_{1}$ - $\\bm v_{2}$\n\t\\item {\\tt Scale}: Returns $\\bm v_{1}$ multiplied by a scalar $\\alpha$\n\t\\item {\\tt Dot}: Returns the dot product $\\bm v_{1} \\cdot \\bm v_{2}$\n\t\\item {\\tt OuterProduct}: Returns the outer product $\\bm v_{1} \\bm v_{2}^{T}$\n\t\\item {\\tt Normalize}: Returns a normalized vector $\\bm v_{1}/ v_{1}$\n\t\\item {\\tt MaxAbs}: Returns the largest element of a vector\n\t\\item {\\tt IsEqual}: Checks if two vector represnetations are identical\t\n\t\\item {\\tt IsZero}: Checks if a vector is full of zero elements\n\t\\item {\\tt Print}: Prints the vector representation to a file\n\t\\item {\\tt Sort}: Sorts the vector elements by size\n\t\\item {\\tt Print}: Prints the vector representation to a file\n\t\\item {\\tt PrintScreen}: Prints the vector representation to the screen\n\\end{itemize}\n\n\n\n\n\n\\subsubsection{Matrix Operations}\nThe matrix related functions are all labeled with a letter '{\\tt M}' and are broken down into the following matrix dimension related categories:\n\\begin{itemize}\n\t\\item  {\\tt mXXXXy()}: the code works on a $n\\times m$ matrix of arbitrary dimension $n$ and $m$.\n\t\\item {\\tt m22XXXX()}: the code works on a $2\\times 2$ matrix defined through {\\tt mat[2][2]}. \n\t\\item {\\tt m33XXXX()}: the code works on a $3\\times 3$ matrix defined through {\\tt mat[3]3]}. \n\t\\item {\\tt m44XXXX()}: the code works on a $4\\times 4$ matrix defined through {\\tt mat[4][4]}. \n\\end{itemize}\n\nThe following list provides an overview of the supported matrix functions.  Note that not al dimensions have all functions provided, but the 2, 3, and 4 dimensional matrix support is pretty complete.  \n\\begin{itemize}\n\t\\item {\\tt SetIdentity}: Returns an identity matrix\n\t\\item {\\tt SetZero}: Returns a zero matrix\n\t\\item {\\tt Set}: Creates a matrix with specific values\n\t\\item {\\tt Copy}: Copies the matrix $[M_{1}]$ into $[M_{2}]$\n\t\\item {\\tt m33MultM33}: Performs the matrix to matrix multiplication $[M_{1}][M_{2}]$\n\t\\item {\\tt m33MultM33t}: Performs the matrix to matrix multiplication $[M_{1}][M_{2}]^{T}$\n\t\\item {\\tt m33tMultM33}: Performs the matrix to matrix multiplication $[M_{1}]^{T}[M_{2}]$\n\t\\item {\\tt m33MultV3}: Computes $[M_{1}]\\bm v_{1}$ \n\t\\item {\\tt m33tMultV3}: Computes $[M_{1}]^{T}\\bm v_{1}$ \n\t\\item {\\tt v3tMultM33}: Computes $\\bm v_{1}^{T}[M_{1}]$ \n\t\\item {\\tt v3tMultM33t}: Computes  $\\bm v_{1}^{T}[M_{1}]^{T}$\n\t\\item {\\tt Tilde}: Returns the skew-symmetric matrix $[\\tilde{\\bm v}_{1}]$\n\t\\item {\\tt Transpose}: Returns $[M_{1}]^{T}$\n\t\\item {\\tt Add}: Returns the sum $[M_{1}] + [M_{2}]$\n\t\\item {\\tt Subtract}: Returns the difference $[M_{1}] - [M_{2}]$\n\t\\item {\\tt Scale}: Returns the scaled matrix $\\alpha [M_{1}]$\n\t\\item {\\tt Trace}: Compute the matrix trace $\\sum M_{ii}$\n\t\\item {\\tt Determinant}: Returns the square matrix determinant\n\t\\item {\\tt IsEqual}: Checks if all matrix elements are equal\n\t\\item {\\tt IsZero}: Checks if all matrix elements are zero\n\t\\item {\\tt Print}: Prints the matrix representation to a file\n\t\\item {\\tt PrintScreen}: Prints the matrix representation to the screen\n\t\\item {\\tt Inverse}: Returns the matrix inverse $[M_{1}]^{-1}$\n\t\\item {\\tt SingularValues}: Computes the singular values of $[M_{1}]$\n\t\\item {\\tt EigenValues}: Computes the Eigenvalues of $[M_{1}]$\n\t\\item {\\tt ConditionNumber}: Computes the condition number of $[M_{1}]$\n\\end{itemize}\n\n\n\n\n\\subsection{{\\tt rigidBodyKinematics} Library}\n\nThe following discussion is a brief overview of the {\\tt rigidBodyKinematics} library function notation.  Please see Appendix E in Reference~\\citenum{schaub} for a complete description:\n\\begin{itemize}\n\t\\item {\\tt XXX2YYY}: Converts the attitude coordinates {\\tt XXX} to {\\tt YYY}\n\t\\item {\\tt addXXX}: Add the two attitude descriptions $\\bm x_{1} = \\bm x_{\\cal B/F}$ and $\\bm x_{2}= \\bm x_{\\cal F/N}$ to return the sequential rotation of first $\\bm x_{1}$ and then $\\bm x_{2}$.  Returns is the description $\\bm x_{3} = \\bm x_{\\cal B/N}$\n\t\\item {\\tt subXXX}: Subtract the two attitude descriptions $\\bm x_{1} = \\bm x_{\\cal F/N}$ and $\\bm x_{2}= \\bm x_{\\cal B/N}$ to return the relative orientation $\\bm x_{3} = \\bm x_{\\cal F/B}$\n\t\\item {\\tt BmatXXX}: Returns the matrix $[B]$ of the differential kinematic equations of the attitude parameters {\\tt XXX} in Reference~\\citenum{schaub}.  Note the scalar multiplier is not included here.  For example, with MRPs\\cite{survey} $[B]$ is defined as $$\\dot{\\bm \\sigma}_{\\cal B/N} = \\frac{1}{4}[B(\\bm\\sigma_{\\cal B/N})] \\leftexp{B}{\\bm\\omega}_{\\cal B/N}$$\n\t\\item {\\tt BinvXXX}: Returns the matrix inverse $[B]^{-1}$ of the attitude parameters {\\tt XXX}\n\t\\item {\\tt dX}: Returns the time derivatives of the attitude parameters {\\tt XXX} as a function of these parameters and the body angular velocity vector $\\bm \\omega$\n\t\\item {\\tt Mi}: Returns the single-axis DCM about the $\\hat{\\bm b}_{i}$ axis\n\t\\item {\\tt wrapToPi}: Makes sure that an angle  lies within $\\pm\\pi$\n\\end{itemize}\n\n\n\n\n\\subsection{{\\tt orbitalMotion} Library}\n\n\\subsubsection{Orbit Anomaly Angle Conversions}\nTo convert between the various anomaly angles, the following functions are defined:\n\\begin{itemize}\n\t\\item {\\tt double f2E(double f, double e)}\n\t\\item {\\tt double E2f(double Ecc, double e)}\n\t\\item {\\tt double E2M(double Ecc, double e)}\n\t\\item {\\tt double M2E(double M, double e)}, with a change conversion tolerance of $10^{-13}$ and a maximum iteration limit of 200\n\t\\item {\\tt double f2H(double f, double e)}\n\t\\item {\\tt double H2f(double H, double e)}\n\t\\item {\\tt double H2N(double H, double e)}\n\t\\item {\\tt double N2H(double N, double e)}, with a change conversion tolerance of $10^{-13}$ and a maximum iteration limit of 200\n\\end{itemize}\n\n\n\n\\subsubsection{Orbit Element Conversion}\nTo convert from classical orbit elements to inertial Cartesian coordinates, the function\n\\begin{verbatim}\n\telem2rv(double mu, classicElements *elements, double *rVec, double *vVec)\n\\end{verbatim}\nis used where {\\tt mu} is the gravitational constant of the 2-body problem, the classical elements are defined through \n$$\n\t(a, e, i, \\Omega, \\omega, f)\n$$\nwhere the anomaly angle is typically given by $f$, unless the orbit is a rectilinear motion in which case the anomaly angle input is $E$.  The function returns the inertial position and velocity vectors in the arrays {\\tt rVec} and {\\tt vVec}.  \n\nTo convert from  inertial Cartesian coordinates to classical orbit elements, the function\n\\begin{verbatim}\n\trv2elem(double mu, double *rVec, double *vVec, classicElements *elements)\n\\end{verbatim}\nBeyond the classical elements listed above, this routine also stores the radius of perapses $r_{p}$ and apoapses $r_{a}$, as well as $\\alpha = \\dfrac{1}{a}$.  \n\n\n\\subsubsection{Space Environment Functions}\n\\paragraph{Atmospheric Density}\nThe Earth's atmospheric density $\\rho$ is computed using\\\\\n\\indent\t{\\tt double atmosphericDensity(double alt)} \\\\\nThe density is returned as a scalar value.  \n\n\\paragraph{Mean Debye Length}\nThe mean Debye Length for the near-Earth environment is approximated, very crudely, through a polynomial fit.  The function returns the scalar $\\lambda_{d}$ and is called through \\\\\n\\indent {\\tt double debyeLength(double alt)}\n\n\\paragraph{Atmospheric Drag Acceleration}\nTo compute an estimate of  the Earth's atmospheric drag acceleration, use the function: \\\\\n\\indent {\\tt void atmosphericDrag(double Cd, double A, double m, double *rvec, double *vvec, double *advec)}\n\nThe inputs are the ballistic drag coefficient {\\tt Cd}, the velocity-projected cross-sectional area {\\tt A}, as well as the spacecraft mass {\\tt m}.  Given the inertial position vectors {\\tt rvec} and {\\tt vvec}, the function returns the drag acceleration {\\tt advec}.  \n\n\\paragraph{Gravitational Zonal Harmonics}\nThis function returns the inertial acceleration due to a planets zonal Harmonic.  The function call is:\\\\\n\\indent {\\tt  void jPerturb(double *rvec, int num, double *ajtot, ...)}\n\nIf not option argument is provided, then the zonal harmonics of Earth are simulated.  About other celestial objects only the $J_{2}$ harmonic is implemented.  Here the object is specified through the {\\tt CelestialObject\\_t} enumeration.  For example, to get the $J_{2}$ zonal harmonic about Venus the argument {\\tt CELESTIAL\\_VENUS} is provided.  \n\n\\paragraph{Solar Radiation Pressure Acceleration}\nTo compute the inertial disturbance acceleration due to the solar radiation pressure use  the function\\\\\n\\indent {\\tt void solarRad(double A, double m, double *sunvec, double *arvec)}\n\nHere {\\tt A} is the projected surface area, {\\tt m} is the spacecraft mass, {\\tt sunvec} is the sun position vector to the Sun in units of AU.  \n\n\n\n\n\n", "meta": {"hexsha": "73cefe623e32729e0c5543a88cf2c391c5fc14dc", "size": 10256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/utilitiesSelfCheck/_Documentation/secUserGuide.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/simulation/utilitiesSelfCheck/_Documentation/secUserGuide.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/simulation/utilitiesSelfCheck/_Documentation/secUserGuide.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": 61.4131736527, "max_line_length": 366, "alphanum_fraction": 0.7233814353, "num_tokens": 2856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.636457606510781}}
{"text": "\\documentclass[epsfig,10pt,fullpage]{article}\n\n\\newcommand{\\LabNum}{7}\n\\newcommand{\\CommonDocsPath}{../../../common/docs}\n\\input{\\CommonDocsPath/preamble.tex}\n\n\\begin{document}\n\n\\centerline{\\huge Digital Logic}\n~\\\\\n\\centerline{\\huge Laboratory Exercise \\LabNum}\n~\\\\\n\\centerline{\\large Finite State Machines}\n~\\\\\n\n\\noindent\nThis is an exercise in using finite state machines.\n~\\\\\n\n\\section*{Part I}\n\\addcontentsline{toc}{1}{Part I}\nWe wish to implement a finite state machine (FSM) that recognizes two specific sequences \nof applied input symbols, namely four consecutive 1s or four consecutive 0s. There is an \ninput $w$ and an output $z$. Whenever $w = 1$\nor $w = 0$ for four consecutive clock pulses the value of $z$ has to be 1; \notherwise, $z = 0$. Overlapping sequences\nare allowed, so that if $w = 1$ for five consecutive clock pulses the output $z$\nwill be equal to 1 after the fourth and\nfifth pulses. Figure~\\ref{fig:sequence_diagram} illustrates the required relationship between $w$ and $z$.\n\n\\begin{figure}[H]\n\\centerline{\n\\includegraphics{figures/figure1.pdf}}\n\\caption{Required timing for the output $z$.}\n\\label{fig:sequence_diagram}\n\\end{figure}\n\nA state diagram for this FSM is shown in Figure~\\ref{fig:state_diagram}. For this part you are to manually\nderive an FSM circuit that implements this state diagram, including the logic expressions\nthat feed each of the state flip-flops. To\nimplement the FSM use nine state flip-flops called $y_8, \\ldots, y_0$ and the \none-hot state assignment given in Table~\\ref{tab:state_assignment}.\n\n\\begin{figure}[H]\n\\centerline{\n\\includegraphics{figures/figure2.pdf}}\n\\caption{A state diagram for the FSM.}\n\\label{fig:state_diagram}\n\\end{figure}\n\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{c|c}\n~ & State Code \\\\ \nName & $y_8 y_7 y_6 y_5 y_4 y_3 y_2 y_1 y_0$ \\\\ \\hline\n\\rule[-0.075in]{0in}{0.25in}{\\bf A} & $000000001$ \\\\ \n{\\bf B} & $000000010$ \\\\ \n{\\bf C} & $000000100$ \\\\ \n{\\bf D} & $000001000$ \\\\ \n{\\bf E} & $000010000$ \\\\ \n{\\bf F} & $000100000$ \\\\ \n{\\bf G} & $001000000$ \\\\ \n{\\bf H} & $010000000$ \\\\ \n{\\bf I} & $100000000$ \\\\ \n\\end{tabular}\n\\end{center}\n\\caption{One-hot codes for the FSM.}\n\\label{tab:state_assignment}\n\\end{table}\n~\\\\\n~\\\\\nDesign and implement your circuit on your DE-series board as follows:\n\n\\begin{enumerate}\n\\item Create a new Quartus\\textsuperscript{\\textregistered} project for the FSM circuit. \n\n\\item Write a Verilog file that instantiates the nine flip-flops in the circuit and which\nspecifies the logic expressions that drive the flip-flop input ports. Use only\nsimple {\\bf assign} statements in your Verilog code to specify the logic feeding the\nflip-flops. Note that the one-hot code enables you to derive these expressions by\ninspection.\n\nUse the toggle switch {\\it SW}$_0$ as an active-low synchronous reset input\nfor the FSM, use {\\it SW}$_1$ as the {\\it w} input, and the pushbutton {\\it KEY}$_0$ as the clock input which \nis applied manually.  Use the red light {\\it LEDR}$_9$ as the output $z$, \nand assign the state flip-flop outputs to the red lights {\\it LEDR}$_8$ to {\\it LEDR}$_0$.\n\n\\item Include the Verilog file in your project, and assign the pins on the FPGA to \nconnect to the switches and the LEDs.\n\n\\item Simulate the behavior of your circuit.\n\n\\item Once you are confident that the circuit works properly as a result of your\nsimulation, download the circuit into the FPGA chip.  Test the functionality of your \ndesign by applying the input sequences and observing the output LEDs. Make sure that the\nFSM properly transitions between states as displayed on the red LEDs, and that it produces\nthe correct output values on {\\it LEDR}$_9$.\n\n\\item Finally, consider a modification of the one-hot code given in Table~\\ref{tab:state_assignment}. It is often \ndesirable to set all flip-flop outputs to the value 0 in the reset state.\n\nTable~\\ref{tab:modified_state_assignment} shows a modified one-hot state assignment in which the reset state, {\\it A},\nuses all 0s. This is accomplished by inverting the state variable $y_0$. \nCreate a modified version of your Verilog code that implements this state\nassignment. ({\\it Hint}: you should need to make very few changes to the logic expressions\nin your circuit to implement the modified state assignment.) \n\n\\item Compile your new circuit and test it.\n\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{c|c}\n~ & State Code \\\\ \nName & $y_8 y_7 y_6 y_5 y_4 y_3 y_2 y_1 y_0$ \\\\ \\hline\n\\rule[-0.075in]{0in}{0.25in}{\\bf A} & $000000000$ \\\\ \n{\\bf B} & $000000011$ \\\\ \n{\\bf C} & $000000101$ \\\\ \n{\\bf D} & $000001001$ \\\\ \n{\\bf E} & $000010001$ \\\\ \n{\\bf F} & $000100001$ \\\\ \n{\\bf G} & $001000001$ \\\\ \n{\\bf H} & $010000001$ \\\\ \n{\\bf I} & $100000001$ \\\\\n\\end{tabular}\n\\end{center}\n\\caption{Modified one-hot codes for the FSM.}\n\\label{tab:modified_state_assignment}\n\\end{table}\n\n\\end{enumerate}\n\n\\section*{Part II}\n\\addcontentsline{toc}{2}{Part II}\nFor this part you are to write another style of Verilog code for the FSM in Figure 2. In\nthis version of the code you should not manually derive the logic expressions needed for\neach state flip-flop. Instead, describe the state table for the FSM by using a\nVerilog {\\bf case} statement in an {\\bf always} block, and use another {\\bf always} block to\ninstantiate the state flip-flops. You can use a third {\\bf always} block or simple assignment\nstatements to specify the output $z$. To implement the FSM, use four state flip-flops\n$y_3, \\ldots, y_0$ and binary codes, as shown in Table~\\ref{tab:bincodes}.\n\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{c|c}\n~ & State Code \\\\ \nName & $y_3 y_2 y_1 y_0$ \\\\ \\hline\n\\rule[-0.075in]{0in}{0.25in}{\\bf A} & $0000$ \\\\ \n{\\bf B} & $0001$ \\\\ \n{\\bf C} & $0010$ \\\\ \n{\\bf D} & $0011$ \\\\ \n{\\bf E} & $0100$ \\\\ \n{\\bf F} & $0101$ \\\\ \n{\\bf G} & $0110$ \\\\ \n{\\bf H} & $0111$ \\\\ \n{\\bf I} & $1000$ \\\\ \n\\end{tabular}\n\\end{center}\n\\caption{Binary codes for the FSM.}\n\\label{tab:bincodes}\n\\end{table}\n\nA suggested skeleton of the Verilog code is given in Figure~\\ref{fig:skeleton_code}.\n\n\\begin{figure}[H]\n\\begin{center}\n\\begin{minipage}[t]{12.5 cm}\n\\begin{tabbing}\nZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\kill\n{\\bf module} ~part2 (~$\\ldots$~);\\\\\n\\>$\\ldots$ define input and output ports\\\\\n~\\\\\n\\>$\\ldots$ define signals\\\\\n\\>{\\bf reg} [3:0] y\\_Q, Y\\_D;  \\>\\>\\>\\>\\>\\>\\>\\>// y\\_Q represents current state, Y\\_D represents next state\\\\\n\\>{\\bf parameter} A = 4'b0000, B = 4'b0001, C = 4'b0010, D = 4'b0011, E = 4'b0100,\\\\\n\\>\\>F = 4'b0101, G = 4'b0110, H = 4'b0111, I = 4'b1000;\\\\\n~\\\\\n\\>{\\bf always} @(w, y\\_Q)\\\\\n\\>{\\bf begin}: state\\_table\\\\\n\\>\\>{\\bf case} (y\\_Q)\\\\\n\\>\\>\\>A:\t\\>{\\bf if} (!w) Y\\_D = B;\\\\\n\\>\\>\\>\\>{\\bf else} Y\\_D = F;\\\\\n\\>\\>\\>$\\ldots$ remainder of state table \\\\\n\\>\\>\\>{\\bf default}: Y\\_D = 4'bxxxx;\\\\\n\\>\\>{\\bf endcase}\\\\\n\\>{\\bf end} // state\\_table\\\\\n\\\\\n\\>{\\bf always} @({\\bf posedge} Clock)\\\\\n\\>{\\bf begin}: state\\_FFs\\\\\n\\>\\>$\\ldots$ \\\\\n\\>{\\bf end} // state\\_FFS\\\\\n\\\\\n\\>$\\ldots$ assignments for output z and the LEDs\\\\\n{\\bf endmodule}\n~\\rule{5.0in}{0in}\\\\\n\\end{tabbing}\n\\end{minipage}\n\\end{center}\n\\caption{Skeleton Verilog code for the FSM.}\n\\label{fig:skeleton_code}\n\\end{figure}\n~\\\\\nImplement your circuit as follows.\n\n\\begin{enumerate}\n\\item Create a new project for the FSM.\n\n\\item Include in the project your Verilog file that uses the style of code in Figure 3.\nUse the same switches, pushbuttons, and lights that were used in Part I.\n\n\\item Before compiling your code it is necessary to explicitly tell the Synthesis tool in\nQuartus that you wish to have the finite state machine implemented using the state\nassignment specified in your Verilog code. If you do not explicitly give this\nsetting to Quartus, the Synthesis tool will automatically use a state assignment of\nits own choosing, and it will ignore the state codes specified in your Verilog code. To\nmake this setting, choose {\\sf Assignments > Settings} in Quartus, and click on the\n{\\sf Compiler Settings} item on the left side of the window, then click on \nthe {\\sf Advanced Settings (Synthesis)} button.  As indicated in Figure 4, change the \nparameter {\\sf State Machine Processing} to the setting {\\sf User-Encoded}.\n\n\\item Compile your project. To examine the circuit produced by Quartus open \nthe RTL Viewer tool. Double-click\non the box shown in the circuit that represents the finite state machine, and determine\nwhether the state diagram that it shows properly corresponds to the one in Figure 2.\nTo see the state codes used for your FSM, open the Compilation Report, select the {\\sf Analysis\nand Synthesis} section of the report, and click on {\\sf State Machines}.\n\n\\item Download the circuit into the FPGA chip and test its functionality.\n\n\\item In step 3 you instructed the Quartus Synthesis tool to use the state\nassignment given in your Verilog code. To see the result of removing this setting, open\nagain the Quartus settings window by choosing {\\sf Assignments > Settings}, and \nclick on the {\\sf Compiler Settings} item on the left side of the window, then click on \nthe {\\sf Advanced Settings (Synthesis)} button. Change the setting for  \n{\\sf State Machine Processing} from {\\sf User-Encoded} to {\\sf One-Hot}. Recompile the\ncircuit and then open the report file, select the {\\sf Analysis\nand Synthesis} section of the report, and click on {\\sf State Machines}.\nCompare the state codes shown to those given in Table~\\ref{tab:modified_state_assignment}, and\ndiscuss any differences that you observe.\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centerline{\n\\includegraphics[scale = 0.75]{figures/figure4.png}}\n\\caption{Specifying the state assignment method in Quartus.}\n\\label{fig:fig7_4}\n\\end{figure}\n\n\\section*{Part III}\n\\addcontentsline{toc}{3}{Part III}\nThe sequence detector can be implemented in a straightforward manner using shift registers,\ninstead of using the more formal approach described above. Create Verilog code that\ninstantiates two 4-bit shift registers; one is for recognizing a sequence of four 0s, and\nthe other for four 1s. Include the appropriate logic expressions in your design\nto produce the output $z$. Make a Quartus project for your design and implement\nthe circuit on your DE-series board. Use the switches and LEDs on the board in a similar way as\nyou did for Parts I and II and observe the behavior of your shift registers and the\noutput $z$. Answer the following question: could you use just one 4-bit shift\nregister, rather than two? Explain your answer.\n\n~\\newpage\n\\section*{Part IV}\n\\addcontentsline{toc}{4}{Part IV}\nIn this part of the exercise you are to implement a Morse-code encoder using an FSM. The Morse code uses\npatterns of short and long pulses to represent a message. Each letter is represented as a sequence of dots\n(a short pulse), and dashes (a long pulse). For example, the first eight letters of the alphabet have the\nfollowing representation:\n~\\\\\n\\begin{center}\n\\begin{minipage}[t]{12.5 cm}\n\\begin{tabbing}\nZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\=ZZ\\kill\n\\>A\\>\\>{\\bf $\\bullet$  ---}\\\\\n\\>B\\>\\>{\\bf ---  $\\bullet$  $\\bullet$  $\\bullet$}\\\\\n\\>C\\>\\>{\\bf ---  $\\bullet$  ---  $\\bullet$}\\\\\n\\>D\\>\\>{\\bf ---  $\\bullet$  $\\bullet$}\\\\\n\\>E\\>\\>{\\bf $\\bullet$}\\\\\n\\>F\\>\\>{\\bf $\\bullet$  $\\bullet$  ---  $\\bullet$}\\\\\n\\>G\\>\\>{\\bf ---  ---  $\\bullet$}\\\\\n\\>H\\>\\>{\\bf $\\bullet$  $\\bullet$  $\\bullet$  $\\bullet$}\\\\\n\\end{tabbing}\n\\end{minipage}\n\\end{center}\n\n~\\\\\nDesign and implement a Morse-code encoder circuit using an FSM. Your circuit should take as input one of the first eight letters of the alphabet and display the Morse code for it on a red LED. Use switches {\\it SW}$_{2-0}$ and pushbuttons {\\it KEY}$_{1-0}$ as inputs. When a user presses {\\it KEY}$_1$, the circuit should display the Morse code for a letter specified by {\\it SW}$_{2-0}$ (000 for A, 001 for B, etc.), using 0.5-second pulses to represent dots, and 1.5-second pulses to represent dashes. Pushbutton {\\it KEY}$_0$ should function as an asynchronous reset. \n\nA high-level schematic diagram of a possible circuit for the Morse-code encoder \nis shown in Figure~\\ref{fig:morse_code_cct}.\n\n\\begin{figure} [H]\n\\begin{center}\n\t\\includegraphics[scale = 0.9]{figures/fig_morse_code_circuit_schematic.pdf}\n\\end{center}\n\\caption{High-level schematic diagram of the circuit for Part IV.}\n\\label{fig:morse_code_cct}\n\\end{figure}\n\n\n\\input{\\CommonDocsPath/copyright.tex}\n\\end{document}\n", "meta": {"hexsha": "b40a339f48866e9b9e6bddbcc4c1eb2176a5a98d", "size": 12284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "verilog/lab7/doc/verilog_lab7.tex", "max_stars_repo_name": "fpgacademy/Lab_Exercises_Digital_Logic", "max_stars_repo_head_hexsha": "f4119b617a5af228a032f8f0ff27a299b496ad78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-09T23:21:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T23:21:40.000Z", "max_issues_repo_path": "verilog/lab7/doc/verilog_lab7.tex", "max_issues_repo_name": "fpgacademy/Lab_Exercises_Digital_Logic", "max_issues_repo_head_hexsha": "f4119b617a5af228a032f8f0ff27a299b496ad78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "verilog/lab7/doc/verilog_lab7.tex", "max_forks_repo_name": "fpgacademy/Lab_Exercises_Digital_Logic", "max_forks_repo_head_hexsha": "f4119b617a5af228a032f8f0ff27a299b496ad78", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-15T16:44:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T16:44:27.000Z", "avg_line_length": 40.8106312292, "max_line_length": 571, "alphanum_fraction": 0.7163790296, "num_tokens": 3685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.6364575966927811}}
{"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{November 7, 2014}\n\\maketitle\n\\section*{5.3.J}\nLet $m(x,y)=\\max\\{x,y\\}$. prove that $m$ is continuous and then show that $h(x)=\\max\\{f(x),g(x)\\}$ is continuous if $f(x)$ and $g(x)$ are continuous.\n\ncase 1, $m(x,y)=x,m(x_1,y_1)=x_1$ then $|m(x,y)-m(x_1,y_1)|=|x-x_1|$. take $r=\\varepsilon$ and then $||(x,y)-(x_1,y_1)||<r$ then $|m(x,y)-m(x_1,y_1)|<\\varepsilon$. similar with $m(x,y)=x$ and $m(x_1,y_1)=y_1$ is similar\n\nnow if $m(x,y)=x$ and $m(x_1,y_1)=y_1$ then $-\\varepsilon<x-y_1<\\varepsilon$.\n\\begin{align*}\n  -r<x-x_1<r\\\\\n  -r<y-y_1<r\\\\\n  x>y\\\\\n  y_1>x_1\\\\\n  -y_1<-x_1\\\\\n  (x-y_1)<(x-x_1)\\\\\n\\end{align*}\nSo if $x-x_1<\\varepsilon$ then $(x-y_1)<\\varepsilon$. \n\\begin{align*}\n  y-y1<x-y1\\\\\n  \\text{if }y-y1>-\\varepsilon\\\\\n  \\text{then }x-y1>-\\varepsilon\\\\\n\\end{align*}\nso $r=\\varepsilon$ will give us $|x-y1|<\\varepsilon$\n\nnow let $\\varepsilon\\circ f(x)=\\varepsilon_1(f(x)=(f(x),0)$ and $\\varepsilon_2\\circ g(x)=\\varepsilon_2(g(x)=(0,g(x))$. and $h(x)=m\\circ(\\varepsilon\\circ f(x)+\\varepsilon\\circ g(x))$\n\nbecause sum and composition of continuous functions are continuous, then h is continuous. induction gives us continuity for $\\max\\{f_1(x),\\dots,f_m(x)\\}$\n\n\\section*{5.4H,I\\& 5.5F}\nlet $f:\\mathbb{R}\\to\\mathbb{R}$ be periodic and continuous, ie $\\exists d>0$ such that $\\forall x\\in \\mathbb{R}, f(x+d)=f(x)$.\n\n\\subsection*{show it attains max min}\nlook at $y\\in[x,x+d]$ then $\\exists a,b\\in [x,x+d]$ such that $f(a)\\le f(y)\\le f(b)$. periodicity gives us same properties on all of $\\mathbb{R}$\n\\subsection*{show that it is bounded and uniformally continuous}\n\\subsection*{find a function $f:\\mathbb{R}^2\\to \\mathbb{R}$ such that $f(x+1,y)=f(x,y)\\forall(x,y)$ but $f$ is not bounded or does not attain it's max}\n\\end{document}\n", "meta": {"hexsha": "da5217af6f5069a896488431c9e202467e6b8dd4", "size": 1993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real analysis/analysis-notes-2014-11-07.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-11-07.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-11-07.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": 39.86, "max_line_length": 219, "alphanum_fraction": 0.6588058204, "num_tokens": 819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.6364561866951493}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Local B-Spline}\n\\label{local_b_spline}\n\nThis method creates the smooth, parametric representation of the surface over the entire modelling area by sequentially creating the n-th number of the control lattices with the increasing resolution, in each cell of which the spline surface is calculated, from which a value is assigned to each node in the grid. This is mine sentence and I want it to stay, anyway. So, let's merge it! An undeniable advantage of the method is the qualitative approximation of highly scattered, irregularly spaced set of the points in a fully automatic mode that does not require any complicated settings from the user and a significant increase in the productivity due to the use of B-Splines in the hierarchy of the control grids.\\\\\n\nThe method algorithm has the following steps:`\n\\begin{itemize}\n\t\\item \n\tThe $ \\Omega = {(x,y) | 0 \\le x < m, 0 \\le y < n} $ area is created, covering all $ P $ input data which equals $ {(x_{c},y_{c},z_{c})} $ in 3D space, where $ (x_{c},y_{c}) $ is the point of input data in 2D space of $ \\Omega $ area; \n\t\\item \n\tThe control lattices $ \\Phi_{n} $ are created sequentially with increasing resolution (i.e. the number of lattice cells is constantly increasing), covering the $ \\Omega $ area. \n\t\n\tThe lattice creation algorithm:\n\t\\begin{itemize}\n\t\t\\item \n\t\tThe $ \\Phi_{n} (m=1, n=1) $ lattice is created (see \\pic{phi_lattice}) containing $ (m+3)\\times(n+3) $ nodes (at the beginning $ (1+3)\\times(1+3) = 16 nodes $, then at each iteration the value of m and n is multiplied by 1.25 and the resulting number of nodes is rounded). Each lattice cell will be described in one spline surface, by calculating the bicubic spline function using the formula:\n\t\t\n\t\t$$\n\t\tf(x,y) = \\sum_{k=0}^3 \\sum_{l=0}^3 B_{k}(s)B_{l}(t)\\phi_{(i+k)(j+l)},\n\t\t$$\n\t\t\n\t\twhere $ i = \\lfloor x \\rfloor -1 $, $ \\lfloor y \\rfloor -1 $, $ s= x - \\lfloor x \\rfloor $, $ t = y - \\lfloor y \\rfloor $, $ B_{k} $ and $ B_{l} $ - uniform cubic B-spline basis functions defined as:\n\t\t\n\t\t$$\n\t\tB_{0}(t) = (1-t)^3 \\div 6,\n\t\t$$\n\t\t\n\t\t$$\n\t\tB_{1}(t) = (3t^3 - 6t^2 + 4) \\div 6,\n\t\t$$\n\t\t\n\t\t$$\n\t\tB_{2}(t) = (-3t^3 +3t^2 +3t + 1) \\div 6,\n\t\t$$\n\t\t\n\t\t$$\n\t\tB_{3}(t) = t^3 \\div 6.\n\t\t$$\n\t\t\n\t\t\\begin{figure}[h]\n\t\t\t\\center{\n\t\t\t\t\\includegraphics[width=0.6\\textwidth]{pics_geology/phi_lattice.png}\n\t\t\t}\n\t\t\t\\caption{Schematic representation of the conditional lattice $ \\Phi $ covering the $ \\Omega $ area with the set of the scattered points as well as the proximity data set $ \\phi $ with the control point $ \\phi_{ij} $. In this case, the resulting B-spline function value will be assigned to the node where the control point is located $ \\phi_{ij} $.}\n\t\t\t\\label{ris:phi_lattice}\n\t\t\\end{figure} \n\t\t\n\t\t\\clearpage\n\t\t\n\t\t\\item\n\t\tEach lattice cell of $ \\Phi_{n} $ will be presented as a spline patch, on the basis of which a value is assigned to each lattice node, thus enabling a parametric surface model to be created. For the approximation of the scattered source point data $ P $, a bicubic B-Spline function is defined inside the cell of the $ \\Phi $ lattice. Each cell of the $ \\Phi_{n} $ lattice will be presented as a spline surface, from which a value is assigned to each node in the grid;\n\t\t\n\t\tThe spline surface creation algorithm:\n\t\t\\begin{itemize}\n\t\t\t\\item \n\t\t\tThe proximity data set $ \\phi $ is created, consisting of 16 nodes, which allows you to limit the number of points affecting the value of a node to only those points that are inside this area (see \\pic{phi_lattice});\n\t\t\t\\item\n\t\t\tThe impact of each source point $ (x_{c},y_{c}) $  which has been placed in the proximity data set $ \\phi $ is sequentially calculated using the formula:\n\t\t\t\n\t\t\t$$\n\t\t\t\\phi_{ij} = \\frac{\\sum_{c} \\omega_{c}^2 \\phi_{c}}{\\sum_{c}, \\omega_{c}^2}\n\t\t\t$$\n\t\t\t\n\t\t\twhere $ \\omega_{c} = \\omega_{kl} =  B_{k}(s)B_{l}(t) $, $ k = (i+1) - \\lfloor x_{c} \\rfloor $, $ l = (j+1) - \\lfloor y_{c} \\rfloor $, $ s = x_{c} - \\lfloor x_{c} \\rfloor $, $ t = y_{c} - \\lfloor y_{c} \\rfloor $, and $ \\phi_{c} $ in turn is calculated using the formula:\n\t\t\t\n\t\t\t$$\n\t\t\t\\phi_{c} = \\frac{\\omega_{c} z_{c}}{\\sum_{a=0}^3 \\sum_{b=0}^3 \\omega_{ab}^2}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tThe value that affects the resulting function of the bicubic spline $ f $ is assigned to the coefficient $ \\phi_{ij} $.\n\t\t\\end{itemize}\n\t\t\\begin{info}\n\t\t\tCells with no source points inside it may appear while the lattice resolution increases. In this case, such cells will be represented by spline surfaces with zero values.\n\t\t\\end{info}\n\t\t\\item \n\t\tAfter estimating the obtained values in each $ \\Phi_{n} $ node, we subtract them from the source data (i.e. we calculate the discrepancies between the source data and the surface model $ \\Phi_{n} $);\n\t\t\\item\t\n\t\tThe algorithm continues to create the new lattices multiplying the number of cells by 1.25 at each subsequent iteration. The iterative process is repeated until the lattice $ \\Phi_{n} $ becomes as detailed as requested by the user at the \\textbf{Grid Properties};\n\t\\end{itemize}\n\t\\item \n\tThe algorithm then splits all lattices of the previous iterations $ \\Phi_{n-1} $ to achieve the resolution of the last $ \\Phi_{n} $ lattice, sums up the obtained values of all lattices, which results in the desired surface $ \\Phi_{ij} $.\n\\end{itemize}\n\nThe parametric surface model built on each iteration represents the difference between the source data and the sum of the surfaces obtained on all previous iterations (see \\pic{local_b_spline}).\n\n\\begin{figure}[h]\n\t\\center{\n\t\t\\includegraphics[width=0.5\\textwidth]{pics_geology/local_b_spline.png}\n\t}\n\t\\caption{Interpolation of points set using the Local B-spline method on the grid in 10 m steps, both X and Y.}\n\t\\label{ris:local_b_spline}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "2ebaa7c95e5ff5103ec1c7c9daf7bb8cefd6db00", "size": 5737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "local_b_spline_eng.tex", "max_stars_repo_name": "aretmii/aretmii_test", "max_stars_repo_head_hexsha": "50dfaecf69fad82c262eab2e1402661654c77f87", "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": "local_b_spline_eng.tex", "max_issues_repo_name": "aretmii/aretmii_test", "max_issues_repo_head_hexsha": "50dfaecf69fad82c262eab2e1402661654c77f87", "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": "local_b_spline_eng.tex", "max_forks_repo_name": "aretmii/aretmii_test", "max_forks_repo_head_hexsha": "50dfaecf69fad82c262eab2e1402661654c77f87", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-30T22:53:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-30T22:53:28.000Z", "avg_line_length": 59.7604166667, "max_line_length": 718, "alphanum_fraction": 0.692347917, "num_tokens": 1736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6364561728372929}}
{"text": "\n\\section{Numerical methods}\nRecall that we compute the buckling eigenmodes via computing the zeros\nof the determinant of linear system corresponding to a Nystr\\\"{o}m \ndiscretization of the integral operator $A(k)$ in~\\cref{eq:inteqfinal}.\nAs in section~\\cref{sec:spec}, let $\\tilde{A}_{k}$ denote the discretized\nlinear system.\nThus, the three main ingredients for the fast and accurate computation\nof buckling eigenvalues (and its corresponding eigenfunctions) are\nhigh order Nystr\\\"{o}m discretizations of the integral operator \n$A(k)$; for a given parameter $k$, the rapid evaluation of the determinant \n$\\tilde{A}_{k}$; and finding the zeros of $\\text{det}(\\tilde{A}_{k})$ (which\nis non-linear in $k$) while minimizing the function evaluations.\n\nFor discretizing the integral operator using the\nNystr\\\"{o}m method, we divide the boundary $\\Gamma$ into\npanels and represent the unknown density and the\nboundary data by their values at scaled Gauss-Legendre\nnodes on each panel. \nLet $n_{p}$ denote the number of Gauss-Legendre panels.\nWe discretize each panel using 16 scaled Gauss-Legendre nodes.\nThen $n_{d} = 16 n_{p}$ is the number of discretization points \non the boundary.\nLet $\\bx_{j}$ denote the discretization nodes, $w_{j}$ denote the\nappropriately scaled Gauss-Legendre quadrature weights for smooth functions,\nand $\\bmu_{j}$ denote the unknown density at $\\bx_{j}$.\nWhen forming the linear system, we use scaled unknowns, \n$\\bmu_{j} \\sqrt{w_{j}}$, so that the spectral properties of the \ndiscrete system with respect to the $l_2$ norm\nare approximations of the spectral properties of the continuous\nsystem as on operator on $L_2$ (for more on this point of view, \nsee \\cite{bremer2012}).\nThe integral kernels $K_{ij}$ in~\\cref{eq:inteqfinal} \nare either smooth or have a weak (logarithmic) singularity. \nFor the smooth kernels, we use standard \nGauss-Legendre quadrature rule.\nFor kernels with a logarithmic singularity, we use order $20$ \ngeneralized Gaussian quadrature rule~\\cite{bremer2010,bremer2010u}.\nNote that the resulting discretized linear system $\\tilde{A}_{k}$ \nis a dense matrix of size $M=2n_{d}+N+1$, \nwhere $N$ is the number of connected components.\n\nFor small problems ($M \\leq 10^3$), we directly compute\n$\\text{det}(\\tilde{A}_{k})$ using standard linear algebra routines\nfrom LAPACK. \nHowever, since the matrix $\\tilde{A}_{k}$ is dense,\nthe computational complexity of computing $\\text{det}(\\tilde{A}_{k})$ \nusing LAPACK routines is $O(M^3)$.\nMoreover, for evaluating the buckling eigenmodes, $\\text{det}(\\tilde{A}_{k})$\nmust be evaluated for many different values of $k$.\nThus, for larger problems, we use the HIFIE method for evaluating\n$\\text{det}(\\tilde{A}_{k})$. \nThis method exploits the rank structure of $\\tilde{A}_{k}$ (large blocks\nof $\\tilde{A}_{k}$ corresponding to interactions between well-separated\nclusters are low-rank) and evaluates the determinant in O($M \\cdot \\log{M})$ \nCPU-time.\n\n\n", "meta": {"hexsha": "86e6a2502aea4e37769fc9f9033f7f973efc2514", "size": 2940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01/05numerics.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/05numerics.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/05numerics.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": 49.8305084746, "max_line_length": 77, "alphanum_fraction": 0.7595238095, "num_tokens": 808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6364561728372928}}
{"text": "\\section{Supplementary Information}\n\\subsection{Absorption Harmonic Oscillator Model}\nWe will find useful here the generic form of the Franck Condon Overlap factor for a displaced harmonic oscillator with the same curvature in the ground and excited states:\n\\begin{align}\n\tO_{m}^{n} &= \\left(-1\\right)^{n} \\sqrt{\\frac{e^{-S}S^{m+n}}{m!n!}} \\sum_{j=0}^{\\min \\left( m,n\\right)} \\frac{m!n!(-1)^j S^{-j}}{j!(m-j)!(n-j)!}\n\t\\label{eqn:overlap}\n\\end{align}\n\\subsubsection{Linear Correction}\nTo calculate the electric field ratio for a linear non-Condon correction for a system starting in the 0th state:\n\\begin{align*}\n\t\\mu_{0,\\lambda} =& \\mu_0 \\bra{0} \\left( 1 + c_1\\left(\\hat{a} + \\hat{a}^{\\dagger}\\right) \\right) \\ket{\\lambda} \\\\\n\t=& \\mu_0\\left( \\delta_{0,\\lambda} + c_1 \\delta_{1, \\lambda}\\right)\n\\end{align*}\n\n\\begin{align}\n\tH_{(1)}(0,k) &=\\frac{\\sum_{\\lambda,\\nu} \\left[ \\delta_{0,\\lambda} + c^*\\delta_{\\lambda, 1} \\right]\\left[ \\delta_{0,\\nu} + c \\delta_{\\nu, 1} \\right]   O_{\\lambda}^{k+1} O_{\\nu}^{k+1} }{\\sum_{l,n} \\left[ \\delta_{0,l} + c^*\\delta_{l, 1} \\right]\\left[ \\delta_{0,n} + c \\delta_{n, 1} \\right]   O_{l}^{k} O_{n}^{k} }\\\\\n\t&= \\frac{ \\left[ O_{0}^{k+1} + c^*O_{1}^{k+1} \\right]\\left[ O_{0}^{k+1} + c O_{1}^{k+1} \\right]   }{\\left[ O_{0}^{k} + c^*O_{1}^{k} \\right]\\left[ O_{0}^{k} + c O_{1}^{k}\\right]     } \\\\\n\t&=  \\frac{\\left| O_{0}^{k+1} + cO_{1}^{k+1}  \\right|^2 }{\\left|O_{0}^{k} + cO_{1}^{k} \\right|^2} \\\\\n\t&= \\left(\\frac{O_{0}^{k+1}}{O_{0}^{k}} \\right)^2   \\frac{ \\left|1 + c\\frac{O_{1}^{k+1}}{O_{0}^{k+1}}  \\right|^2}{\\left|1 + c\\frac{O_{1}^{k} }{O_{0}^{k}}\\right|^2}\n\\end{align}\n\nFor this, several quantities can be computed\n\n\\begin{align}\n\tO_{0}^{k+1} &= \\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{k + 1}}{(k+1)!}} \\\\\n\tO_{1}^{k+1} &= \\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{1+k+1}}{(k+1)!}} \\sum_{j=0}^{\\min \\left( 1,k+1 \\right)} \\frac{(k+1)!(-1)^j S^{-j}}{j!(1-j)!(k+1-j)!}\\\\\n\t&= \\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{1+k+1}}{(k+1)!}} \\left[  \\frac{(k+1)! }{(k+1)!}  - \\frac{(k+1)! S^{-1}}{k!}\\right]\\\\\n\t&= \\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{1+k+1}}{(k+1)!}} \\left[  1  - \\frac{(k+1) }{S}\\right]\n\\end{align}\nthen the desired ratio is\n\\begin{align}\n\t\\frac{O_{1}^{k+1}}{ O_{0}^{k+1}} &=  \\frac{\\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{1+k+1}}{(k+1)!}} \\left[  1  - \\frac{(k+1) }{S}\\right]}{\\left(-1\\right)^{k+1} \\sqrt{\\frac{e^{-S}S^{k + 1}}{(k+1)!}}}\\\\\n\t&=  \\frac{ \\sqrt{\\frac{e^{-S}S^{1+k+1}}{(k+1)!}} }{ \\sqrt{\\frac{e^{-S}S^{k + 1}}{(k+1)!}}} \\left[  1  - \\frac{(k+1) }{S}\\right]\\\\\n\t&= \\sqrt{S} \\left[  1  - \\frac{(k+1) }{S}\\right]\n\\end{align}\nas for the other ratio:\n\\begin{align}\n\tO_{0}^{k} &= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{k }}{k!}} \\\\\n\tO_{1}^{k} &= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{1+k}}{k!}} \\sum_{j=0}^{\\min \\left( 1,k \\right)} \\frac{k!(-1)^j S^{-j}}{j!(1-j)!(k-j)!}\n\\end{align}\nfirst we start with the case where $k\\geq1$\n\\begin{align}\n\tO_{1}^{k} &= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{1+k}}{k!}} \\left[ \\frac{k! }{k!} - \\frac{k! S^{-1}}{(k-1)!} \\right] \\\\\n\t&= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{1+k}}{k!}} \\left[ 1 - \\frac{k}{S} \\right]\n\\end{align}\nif $k=0$ then the summation above will be unity and the same equation will thus work for both.  Now when we bring it back into the ratio:\n\\begin{align}\n\t\\frac{O_{1}^{k}}{O_{0}^{k}} &= \\frac{\\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{1+k}}{k!}} \\left[ 1 - \\frac{k}{S} \\right]}{\\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{k }}{k!}}}\\\\\n\t&= \\sqrt{S} \\left[  1  - \\frac{k }{S}\\right]\n\\end{align}\nWhich after substitution leads to\n\\begin{align}\n\tH_{(1)}(0,k)&= \\frac{S }{k+1 } \\frac{\\left| 1 + c\\sqrt{S} \\left( 1  - \\frac{k+1}{S} \\right) \\right|^2}{\\left| 1 + c \\sqrt{S} \\left( 1  - \\frac{k}{S} \\right)\\right|^2 }\n\\end{align}\n\n\n\\subsubsection{Quadratic Correction}\nbut for a quadratic correction:\n\\begin{align*}\n\t\\mu^{(2)}_{0,\\lambda} =& \\mu_0 \\bra{0} \\left( 1 + c_2\\left(\\hat{a} + \\hat{a}^{\\dagger}\\right)^2\\right) \\ket{\\lambda}\\\\\n\t=& \\mu_0 \\bra{0} \\left( 1 + c_2\\left(\\hat{N} + 1 + \\hat{a}\\hat{a} + \\hat{a}^{\\dagger}\\hat{a}^{\\dagger}\\right)\\right) \\ket{\\lambda}\\\\\n\t=& \\mu_0 \\left( \\left(1 + c_2\\right) \\delta_{0,\\lambda} + c_2\\sqrt{2}\\delta_{2,\\lambda} \\right) \\\\\n\t=& \\frac{\\mu_0}{\\left(1 + c_2\\right)} \\left(  \\delta_{0,\\lambda} + \\frac{c_2\\sqrt{2}}{\\left(1 + c_2\\right)} \\delta_{2,\\lambda} \\right) \\\\\n\t=& \\mu_0' \\left(  \\delta_{0,\\lambda} + c_2' \\delta_{2,\\lambda} \\right)\n\\end{align*}\nwhich gives us for the peak ratios instead\n\\begin{align}\n\tH_{(2)}(0,k) &= \\frac{\\left| O_{0}^{k+1} + c_2' O_{2}^{k+1}  \\right|^2 }{\\left|O_{0}^{k} +  c_2' O_{2}^{k} \\right|^2} \\\\\n\t&=  \\left(\\frac{O_{0}^{k+1}}{O_{0}^{k}} \\right)^2   \\frac{ \\left|1 + c_2'\\frac{O_{2}^{k+1}}{O_{0}^{k+1}}  \\right|^2}{\\left|1 + c_2'\\frac{O_{2}^{k} }{O_{0}^{k}}\\right|^2}\n\\end{align}\n\nInstead of getting algebraic expressions for $O_{n\\geq2}^{k}$ as we did for $O_{1}^{k}$, we instead implement Equation \\ref{eqn:overlap} directly in our solver.\n\n\\subsubsection{3  Correction}\nThe cubic correction looks like so:\n\\begin{align*}\n\t\\mu^{(3)}_{0,\\lambda} =& \\mu_0 \\bra{0} \\left( 1 + c_3\\left(\\hat{a} + \\hat{a}^{\\dagger}\\right)^3\\right) \\ket{\\lambda}\\\\\n\t=& \\mu_0 \\bra{0} \\left( 1 + c_3 \\left(\\hat{a} + \\hat{a}^{\\dagger}\\right) \\left(\\hat{N} + 1 + \\hat{a}\\hat{a} + \\hat{a}^{\\dagger}\\hat{a}^{\\dagger}\\right)\\right)\\ket{\\lambda}\\\\\n\t=& \\mu_0 \\left( \\bra{0}  + c_3 \\bra{1}  \\left(\\hat{N} + 1 + \\hat{a}\\hat{a} + \\hat{a}^{\\dagger}\\hat{a}^{\\dagger}\\right)\\right)\\ket{\\lambda}\\\\\n\t=& \\mu_0 \\left( \\bra{0}  + c_3   \\left(2\\bra{1}  +\\sqrt{6}\\bra{3} \\right)\\right)\\ket{\\lambda}\\\\\n\t=& \\mu_0 \\left( \\delta_{0,\\lambda}  + c_3   \\left(2\\delta_{1,\\lambda}  +\\sqrt{6}\\delta_{3,\\lambda} \\right)\\right)\n\\end{align*}\nwhich indicates it makes more sense to treat (1,3) and not just (3):\n\\begin{align*}\n\t\\mu^{(1,3)}_{0,\\lambda} =& \\mu_0 \\left( \\delta_{0,\\lambda}  +  \\delta_{1,\\lambda} \\left(2c_3 + c_1\\right)   +c_3 \\sqrt{6}\\delta_{3,\\lambda} \\right)\\\\\n\t=& \\mu_0 \\left( \\delta_{0,\\lambda}  +  c_1' \\delta_{1,\\lambda} +c_3 \\sqrt{6}\\delta_{3,\\lambda} \\right)\\\\\n\tc_1' =& \\left(2c_3 + c_1\\right)\\\\\n\tc_3' =& c_3 \\sqrt{6} \\\\\n\tc_1 =& \\left(c_1'  - 2\\frac{c_3'}{\\sqrt{6}} \\right)\n\\end{align*}\n\\subsubsection{4  Correction}\nLooking at a quadratic correction:\n\\begin{align*}\n\t\\mu^{(4)}_{0,\\lambda} =& \\mu_0 \\bra{0} \\left( 1 + c_4\\left(\\hat{a} + \\hat{a}^{\\dagger}\\right)^4\\right) \\ket{\\lambda}\\\\\n\t=& \\mu_0 \\bra{0} \\left( 1 + c_4 \\left(\\hat{N} + 1 + \\hat{a}\\hat{a} + \\hat{a}^{\\dagger}\\hat{a}^{\\dagger}\\right)^2 \\right) \\ket{\\lambda} \\\\\n\t=& \\mu_0  \\left( \\delta_{0, \\lambda} + c_4 \\bra{0} \\left(1 + \\hat{a}\\hat{a}\\right)\\left(\\hat{N} + 1 + \\hat{a}\\hat{a} + \\hat{a}^{\\dagger}\\hat{a}^{\\dagger}\\right) \\ket{\\lambda}\\right)  \\\\\n\t=& \\mu_0  \\left( \\delta_{0, \\lambda} + c_4\\left[ 3 \\delta_{0, \\lambda} + 4\\sqrt{2}\\delta_{2, \\lambda}  + 2\\sqrt{6}\\delta_{4, \\lambda}  \\right]\\right)  \\\\\n\t=& \\mu_0  \\left( \\delta_{0, \\lambda} \\left( 1 + 3c_4 \\right) + 4\\sqrt{2}c_4\\delta_{2, \\lambda}  + 2\\sqrt{6}c_4\\delta_{4, \\lambda}\\right)\\\\\n\t=& \\mu_0'  \\left( \\delta_{0, \\lambda}  + \\frac{4\\sqrt{2}c_4}{1 + 3c_4 }\\delta_{2, \\lambda}  + \\frac{2\\sqrt{6}c_4}{1 + 3c_4 }\\delta_{4, \\lambda}\\right)\n\\end{align*}\nmuch like for (3) we had to consider (1,3) to be more accurate, it makes no sense to consider (4) on its own; we'll need to introduce (2) as well to get (2,4):\n\\begin{align*}\n\t\\mu^{(2,4)}_{0,\\lambda} =& \\mu_0  \\left( \\delta_{0, \\lambda} \\left( 1 + c_2 + 3c_4 \\right) + \\left( \\sqrt{2} c_2 + 4\\sqrt{2}c_4 \\right)\\delta_{2, \\lambda}  + 2\\sqrt{6}c_4\\delta_{4, \\lambda}\\right)\\\\\n\t=& \\mu_0'  \\left( \\delta_{0, \\lambda} + \\frac{\\sqrt{2} c_2 + 4\\sqrt{2}c_4 }{1 + c_2 + 3c_4 }\\delta_{2, \\lambda}  + \\frac{2\\sqrt{6}c_4}{1 + c_2 + 3c_4 }\\delta_{4, \\lambda}\\right) \\\\\n\tc_2' &= \\frac{\\sqrt{2} c_2 + 4\\sqrt{2}c_4 }{1 + c_2 + 3c_4 } \\\\\n\tc_4' &= \\frac{2\\sqrt{6}c_4}{1 + c_2 + 3c_4 }\n\\end{align*}\nwhich when inverted turns into:\n\\begin{align*}\n\tc_2 &= -\\frac{2 \\left(\\sqrt{6} c_2'-2 \\sqrt{2} c_4'\\right)}{2 \\sqrt{6} c_2'-\\sqrt{2} c_4'-4 \\sqrt{3}}\\\\\n\tc_4 &= \\frac{c_4' \\left(3 \\sqrt{2} c_4'-4 \\sqrt{3}\\right)}{\\left(2 \\sqrt{6}-3 c_4'\\right) \\left(2 \\sqrt{6} c_2'-\\sqrt{2} c_4'-4 \\sqrt{3}\\right)}\n\\end{align*}\n\n\n\\subsubsection{Generic Correction}\nIt becomes clear that we should be able to define an arbitrary-order correction (at least for $\\eta=0$) rather simply by adding together generic $x^n$ operator\n\n\\begin{align*}\n\t\\mu_{0,\\lambda} = \\sum_n c_n \\mu^{(n)}_{0,\\lambda} =& \\sum_n c_n \\bra{0} \\left(\\hat{a} + \\hat{a}^{\\dagger}\\right)^n  \\ket{\\lambda}\n\\end{align*}\nthis would then feed in to our expression for $H$:\n\\begin{align}\n\tH_{(\\{i\\})}(0,k)&= \\frac{S}{k+1}   \\frac{ \\left|1 + \\sum_{l = \\{i\\}} c'_l \\frac{O_{l}^{k+1}}{O_{0}^{k+1}}  \\right|^2}{\\left|1 + \\sum_{l = \\{i\\}} c'_l \\frac{O_{l}^{k} }{O_{0}^{k}}\\right|^2}\n\\end{align}\nwhere the transformation from $c'$ back into $c$ would have to be calculated for any individual  $H_{(\\{i\\})}$ but is non-trivial.  We saw above that the squared operator brought amplitude back to zero and in general, all even operators will bring back amplitude to all even operators in order below and the same with odd operators.\n\n% GRAVEYARD\n% \\begin{align}\n% \tO_{2}^{k} &= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{2+k}}{2!k!}} \\sum_{j=0}^{\\min \\left( 2,k\\right)} \\frac{2!k!(-1)^j S^{-j}}{j!(2-j)!(k-j)!}\n% \\end{align}\n% if $k>2$:\n% \\begin{align}\n% \tO_{2}^{k} &= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{2+k}}{2!k!}} \\sum_{j=0}^{2} \\frac{2!k!(-1)^j S^{-j}}{j!(2-j)!(k-j)!} \\\\\n% \t&= \\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{2+k}}{2!k!}} \\left(1 - \\frac{2 k}{S} + \\frac{k(k-1)}{S^2 }  \\right)\n% \\end{align}\n% then one can see like we did above that this holds for $k=0,1$ and we can continue on to the ratios:\n% \\begin{align}\n% \t\\frac{O_{2}^{k}}{O_{0}^{k}} &= \\frac{\\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{2+k}}{2!k!}} \\left(1 - \\frac{2 k}{S} + \\frac{k(k-1)}{S^2 }  \\right)}{\\left(-1\\right)^{k} \\sqrt{\\frac{e^{-S}S^{k }}{k!}}}\\\\\n% \t&= \\sqrt{\\frac{S^{2}}{2}} \\left(1 - \\frac{2 k}{S} + \\frac{k(k-1)}{S^2 }  \\right)\\\\\n% \t\\frac{O_{2}^{k+1}}{O_{0}^{k+1}} &= \\sqrt{\\frac{S^{2}}{2}} \\left(1 - \\frac{2 (k+1)}{S} + \\frac{k(k+1)}{S^2 }  \\right)\n% \\end{align}\n", "meta": {"hexsha": "69d9eb14c3b03549a9587c1084050d04ff3a1b21", "size": 10097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DetectingNonCondonPaper/supplement.tex", "max_stars_repo_name": "jgoodknight/dissertation", "max_stars_repo_head_hexsha": "012ad400e1246d2a7e63cc640be4f7b4bf56db00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-21T06:20:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-21T06:20:42.000Z", "max_issues_repo_path": "DetectingNonCondonPaper/supplement.tex", "max_issues_repo_name": "jgoodknight/dissertation", "max_issues_repo_head_hexsha": "012ad400e1246d2a7e63cc640be4f7b4bf56db00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DetectingNonCondonPaper/supplement.tex", "max_forks_repo_name": "jgoodknight/dissertation", "max_forks_repo_head_hexsha": "012ad400e1246d2a7e63cc640be4f7b4bf56db00", "max_forks_repo_licenses": ["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.1056338028, "max_line_length": 332, "alphanum_fraction": 0.5677924136, "num_tokens": 4738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6364561576838511}}
{"text": "\\chapter{Complex Problem Set}\n\\begin{abox}\n\tPractise Set-1\n\\end{abox}\n\n\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item The value of the integral $\\int_{C} d z z^{2} e^{z}$, where $C$ is an open contour in the complex $z$-plane as shown in the figure below, is:\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=9cm]{diagram-20211005-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{5}{e}+e$\n\t\t\\task[\\textbf{B.}] $e-\\frac{5}{e}$\n\t\t\\task[\\textbf{C.}] $\\frac{5}{e}-e$\n\t\t\\task[\\textbf{D.}] $-\\frac{5}{e}-e$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext { If we complete the contour, then by Cauchy integral theorem }\n\t\t\\int_{-1}^{1} d z z^{2} e^{z}+\\int_{C} d z z^{2} e^{z}&=0 \\Rightarrow \\int_{C} d z z^{2} e^{z}=-\\int_{-1}^{1} d z z^{2} e^{z}\\\\&=-\\left[z^{2} e^{z}-2 z e^{2}+2 e^{2}\\right]_{-1}^{1}=\\frac{5}{e}-e\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item Which of the following is an analytic function of the complex variable $z=x+i y$ in the domain $|z|<2 ?$\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $(3+x-i y)^{7}$\n\t\t\\task[\\textbf{B.}] $(1+x+i y)^{4}(7-x-i y)^{3}$\n\t\t\\task[\\textbf{C.}] $(1-x-i y)^{4}(7-x+i y)^{3}$\n\t\t\\task[\\textbf{D.}] $(x+i y-1)^{1 / 2}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\tPut $z=x+i y .$ If $\\bar{z}=x-i y$ appears in any of the expressions then that expression is non-analytic. For option (D) we have a branch point singularity as the power is $\\frac{1}{2}$ which is fractional. Hence only option (B) is analytic.\\\\\\\\\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\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\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{1}{(z-1)(z-2)}&=\\frac{1}{z-2}-\\frac{1}{z-1}=\\frac{1}{1-z}+\\frac{1}{(z-1)-1}\\\\&=\\frac{1}{1-z}-(1+(1-z))^{-1}\\\\\n\t\t&=\\frac{1}{1-z}-\\left[1+(1-z)+\\frac{(-1)(-2)}{2 !}(1-z)^{2}+\\frac{(-1)(-2)(-3)}{3 !}(1-z)^{3} \\ldots\\right]\\\\\n\t\t&=\\frac{1}{1-z}-\\left[z+(1-z)^{2}-(1-z)^{3}+\\ldots . .\\right]\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\n\t\\item Let $u(x, y)=x+\\frac{1}{2}\\left(x^{2}-y^{2}\\right)$ be the real part of analytic function $f(z)$ of the complex variable $z=x+i y$. The imaginary part of $f(z)$ is\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $y+x y$\n\t\t\\task[\\textbf{B.}] $x y$\n\t\t\\task[\\textbf{C.}] $y$\n\t\t\\task[\\textbf{D.}] $y^{2}-x^{2}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tu(x, y)&=x+\\frac{1}{2}\\left(x^{2}-y^{2}\\right), v(x, y)=?\\\\\n\t\t\\text{Check }\\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y}\\text{ and } \\frac{\\partial u}{\\partial y}=-\\frac{\\partial v}{\\partial x}\\\\\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y}, \\quad \\frac{\\partial v}{\\partial y}=1+x, \\\\ v&=y+x y+f(x)\\\\\n\t\t\\frac{\\partial u}{\\partial y}&=-\\frac{\\partial v}{\\partial x} \\Rightarrow \\frac{\\partial v}{\\partial x}=+y, \\\\ v&=y x+f(y)\\\\\n\t\ty+x y+f(x)&=y x+f(y)\\\\\n\t\t\\text{If }f(x)&=0\\quad \\quad\n\t\tf(y)=y\\\\\n\t\tv&=x y+y\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item The value of the integral $\\int_{C} \\frac{z^{3} d z}{\\left(z^{2}-5 z+6\\right)}$, where $C$ is a closed contour defined by the equation $2|z|-5=0$, traversed in the anti-clockwise direction, is\n\t{\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-16 \\pi i$\n\t\t\\task[\\textbf{B.}] $16 \\pi \\mathrm{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\\begin{answer}\n\t\t\\begin{align*}\n\t\tz^{2}-5 z+6&=0 \\Rightarrow z^{2}-2 z-3 z+6\\\\&=0 \\Rightarrow z(z-2)-3(z-2)=0 \\Rightarrow z=3,2\\\\\n\t\t2|z|&=5 \\Rightarrow|z|=2.5,\\text{ only 2 will be inside.}\\\\\n\t\t\\text{Residue }&=\\left.(z-2) \\frac{z^{3}}{(z-3)(z-2)}\\right|_{z=2}=\\frac{8}{2-3}\\\\&=-8 \\Rightarrow \\int \\frac{z^{3} d z}{z^{2}-5 z+6}=2 \\pi i(-8)=-16 \\pi i\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item  With $z=x+i y$, which of the following functions $f(x, y)$ is NOT a (complex) analytic function of $z$ ?\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $f(x, y)=(x+i y-8)^{3}\\left(4+x^{2}-y^{2}+2 i x y\\right)^{7}$\n\t\t\\task[\\textbf{B.}] $f(x, y)=(x+i y)^{7}(1-x-i y)^{3}$\n\t\t\\task[\\textbf{C.}] $f(x, y)=\\left(x^{2}-y^{2}+2 i x y-3\\right)^{5}$\n\t\t\\task[\\textbf{D.}] $f(x, y)=(1-x+i y)^{4}(2+x+i y)^{6}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(x, y)&=(1-x+i y)^{4}(2+x+i y)^{6}\\\\&=\\{1-(x-i y)\\}^{4}(2+x+i y)^{6}\\\\\n\t\t\\text{Due to present of }\\bar{z}&=(x-i y)\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (D)}\n\t\\end{answer}\n\t\\item  Which of the following functions cannot be the real part of a complex analytic function of $z=x+i y ?$\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $x^{2} y$\n\t\t\\task[\\textbf{B.}]  $x^{2}-y^{2}$\n\t\t\\task[\\textbf{C.}] $x^{3}-3 x y^{2}$\n\t\t\\task[\\textbf{D.}] $3 x^{2} y-y-y^{3}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{ Let $x^{2} y$ be real part of a complex function. Use Milne Thomson's method to write analytic complex function. The real part of that function should be (1) but that is not the case. So this cannot be real part of an analytic function. Also,}\n\t\tz^{2}&=(x+i y)^{2}=x^{2}-y^{2}+2 i x y,\\text{ Real part option (2)}\\\\\n\t\tz^{3}&=(x+i y)^{3}=x^{3}-i y^{3}+3 i x y(x+i y)\\\\\n\t\t&=x^{3}-i y^{3}+3 i x^{2} y-3 x y^{2},\\text{ Real part option (3)}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item  Given that the integral $\\int_{0}^{\\infty} \\frac{d x}{y^{2}+x^{2}}=\\frac{\\pi}{2 y}$, the value of $\\int_{0}^{\\infty} \\frac{d x}{\\left(y^{2}+x^{2}\\right)^{2}}$ is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{y^{3}}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\pi}{4 y^{3}}$\n\t\t\\task[\\textbf{C.}]  $\\frac{\\pi}{8 y^{3}}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\pi}{2 y^{3}}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\int_{0}^{\\infty} \\frac{d x}{\\left(y^{2}+x^{2}\\right)^{2}}&=\\frac{1}{2} \\int_{-\\infty}^{\\infty} \\frac{d x}{\\left(y^{2}+x^{2}\\right)^{2}},\\text{ pole is of }2^{\\text {nd }}\\text{ order at }x=i y,\\text{ residue }=1 /\\left(4 i y^{3}\\right)\\\\\n\t\t\\text{Integral }&=\\left(\\frac{1}{2}\\right)(2 \\pi i) \\frac{1}{4 i y^{3}}=\\frac{\\pi}{\\left(4 y^{3}\\right)}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If $C$ is the contour defined by $|z|=\\frac{1}{2}$, the value of the integral\n\t$$\n\t\\oint_{C} \\frac{d z}{\\sin ^{2} z}\n\t$$\n\tis\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\infty$\n\t\t\\task[\\textbf{B.}] $2 \\pi i$\n\t\t\\task[\\textbf{C.}] 0\n\t\t\\task[\\textbf{D.}] $\\pi i$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{1}{\\sin ^{2} z} \\quad\\left(|z|=\\frac{1}{2}\\right)\\\\\n\t\t\\sin z&=z-\\frac{z^{3}}{\\lfloor 3}+\\frac{z^{5}}{\\lfloor 5} \\ldots . \\Rightarrow \\frac{1}{\\sin ^{2} z}=\\frac{1}{\\left(z-\\frac{z^{3}}{\\frac{3}{3}}+\\frac{z^{5}}{5} \\cdots\\right)^{2}}\\\\\n\t\t\\Rightarrow \\frac{1}{\\sin ^{2} z}&=\\frac{1}{z^{2}}\\left[1-\\frac{z^{2}}{\\lfloor 3}+\\frac{z^{4}}{\\lfloor 5} \\ldots .\\right]^{-2} \\Rightarrow \\oint_{C} \\frac{d z}{\\sin ^{2} z}=0\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item The principal value of the integral $\\int_{-\\infty}^{\\infty} \\frac{\\sin (2 x)}{x^{3}} d x$ is\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(4)\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\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Let }f(z)&=\\frac{e^{i 2 z}}{z^{3}}\\\\\n\t\t\\lim _{2 \\rightarrow 0}(z-0)^{3} f(z)&=\\lim _{z \\rightarrow 0}(z-0)^{3} \\frac{e^{i 2 z}}{z^{3}}\\\\&=1(\\text{ finite and }\\neq 0) \\Rightarrow z=0 \\text{is pole of order 3} .\\\\\n\t\t\\text{Residue }R&=\\frac{1}{2 !} \\lim _{z \\rightarrow 0} \\frac{d^{2}}{d z^{2}}\\left[(z-0)^{3} \\frac{e^{i 2 z}}{z^{3}}\\right]=-2\\\\\n\t\t\\Rightarrow \\int_{-\\infty}^{\\infty} f(x) d x&=\\pi i \\Sigma R=\\pi i(-2)=-2 \\pi i \\Rightarrow \\operatorname{Im} .\\text{ Part }\\\\&=-2 \\pi \\Rightarrow \\int_{-\\infty}^{\\infty} f(x) d x=-2 \\pi\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item The Laurent series expansion of the function $f(z)=e^{2}+e^{1 / 2}$ about $z=0$ is given by\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\sum_{n=-\\infty}^{\\infty} \\frac{z^{n}}{n !}$ for all $|z|<\\infty$\n\t\t\\task[\\textbf{B.}] $\\sum_{n=0}^{\\infty}\\left(z^{n}+\\frac{1}{z^{n}}\\right) \\frac{1}{n !}$ only if $0<|z|<1$\n\t\t\\task[\\textbf{C.}] $\\sum_{n=0}^{\\infty}\\left(z^{n}+\\frac{1}{z^{n}}\\right) \\frac{1}{n !}$ for all $0<|z|<\\infty$\n\t\t\\task[\\textbf{D.}]  $\\sum_{n=-\\infty}^{\\infty} \\frac{z^{n}}{n !}$ only if $|z|<1$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\te^{z}&=\\left(1+z+\\frac{z^{2}}{2 !}+\\ldots\\right)=\\sum_{n=0}^{\\infty} \\frac{z^{n}}{n !}\\text{ and }e^{1 / z}\\\\&=1+\\frac{1}{z}+\\frac{1}{2 !} \\frac{1}{z^{2}}+\\ldots .=\\sum_{n=0}^{\\infty} \\frac{1}{z^{n} n !}\\\\\n\t\t\\Rightarrow f(z)&=\\left(e^{z}+e^{1 / 2}\\right)=\\sum_{n=0}^{\\infty}\\left(z^{n}+\\frac{1}{z^{n}}\\right) \\frac{1}{n !},\\text{ for all }0<|z|<\\infty\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item Consider the function $f(z)=\\frac{1}{z} \\ln (1-z)$ of a complex variable $z=r e^{i \\theta}(r \\geq 0, \\quad-\\infty<\\theta<\\infty)$. The singularities of $f(z)$ are as follows:\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}]  Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ only for $0 \\leq \\theta<2 \\pi$\n\t\t\\task[\\textbf{B.}] Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ for all $\\theta$ other than $0 \\leq \\theta<2 \\pi$\n\t\t\\task[\\textbf{C.}] Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ for all $\\theta$\n\t\t\\task[\\textbf{D.}] Branch points at $z=0, z=1$ and $z=\\infty$.\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{For }f(z)&=\\frac{1}{z} \\ln (1-z)=\\frac{1}{z}\\left(-z-\\frac{z^{2}}{2}-\\frac{z^{3}}{3}-\\ldots . .\\right)\\\\&=-1-\\frac{z}{2}-\\frac{z^{2}}{3}-\\ldots .\n\t\t\\intertext{There is no principal part and when $z \\rightarrow 0, f(z)=-1 .$ So there is removable singularity at $z=0$. Also $z=1$ and $z=\\infty$ is Branch point.}\n\t\t\\end{align*}\n\t\tNone of the above is correct\n\t\\end{answer}\n\t\\item  The value of integral $\\int_{-\\infty}^{\\infty} \\frac{d x}{1+x^{4}}$\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{\\sqrt{2}}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\pi}{2}$\n\t\t\\task[\\textbf{C.}] $\\sqrt{2} \\pi$\n\t\t\\task[\\textbf{D.}] $2 \\pi$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\int_{-\\infty}^{\\infty} \\frac{d z}{1+z^{4}} \\quad \\because|z|=R\\\\\n\t\t\\text{Now, pole }z&=e^{(2 n+1) \\frac{\\pi}{4}}\\\\\n\t\tn&=0, \\quad \\Rightarrow z_{0}=e^{\\frac{i \\pi}{4}}=\\frac{1}{\\sqrt{2}}+i \\frac{1}{\\sqrt{2}}, n\\\\&=2 \\Rightarrow z_{2}=\\frac{-1}{\\sqrt{2}}-i \\frac{1}{\\sqrt{2}}\\\\\n\t\tn&=1 \\Rightarrow z_{1}=e^{\\frac{i 3 \\pi}{4}}=\\frac{-1}{\\sqrt{2}}+i \\frac{1}{\\sqrt{2}}, n\\\\&=3 \\Rightarrow z_{3}=+\\frac{1}{\\sqrt{2}}-i \\frac{1}{\\sqrt{2}}\n\t\t\\intertext{only $z_{0}$ and $z_{1}$ lies in contour}\n\t\t\\text{i.e., residue at }\\left(z=e^{\\frac{i \\pi}{4}}\\right)&=\\frac{1}{4}\\left(-\\frac{1}{\\sqrt{2}}-i \\frac{1}{\\sqrt{2}}\\right)\\\\\n\t\t\\text{residue at }\\left(z=e^{\\frac{i 3 \\pi}{4}}\\right)&=\\frac{1}{4}\\left(\\frac{1}{\\sqrt{2}}-i \\frac{1}{\\sqrt{2}}\\right)\\\\\n\t\t\\text{now }\\int_{-\\infty}^{\\infty} \\frac{d x}{x^{4}+1}&=2 \\pi i \\Sigma \\operatorname{Re} S=\\frac{\\pi}{\\sqrt{2}}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item  The function $\\frac{Z}{\\sin \\pi z^{2}}$ of a complex variable $z$ has\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] A simple pole at 0 and poles of order 2 at $\\pm \\sqrt{n}$ for $n=1,2,3 \\ldots$\n\t\t\\task[\\textbf{B.}] A simple pole at 0 and poles of order 2 at $\\pm \\sqrt{n}$ and $\\pm i \\sqrt{n}$ for $n=1,2,3 \\ldots$\n\t\t\\task[\\textbf{C.}] Poles of order 2 at $\\pm \\sqrt{n}, n=0,1,2,3 \\ldots$\n\t\t\\task[\\textbf{D.}] Poles of order 2 at $\\pm n, n=0,1,2,3 \\ldots$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{z}{\\sin \\pi z^{2}}=\\frac{z}{\\pi z^{2} \\frac{\\sin \\pi z^{2}}{\\pi z^{2}}}\\\\\n\t\t\\text{\tat }z&=0,\\text{ it is a simple pole since,} \\lim _{z \\rightarrow 0} \\frac{\\sin \\pi z^{2}}{\\pi z^{2}}=1\\\\\n\t\t\\text{Also, }\\sin \\pi z^{2}&=\\sin n \\pi \\Rightarrow \\pi \\mathrm{z}^{2}\\\\&=\\pm n \\pi, z=\\pm \\sqrt{n}, \\pm i \\sqrt{n}\\\\\n\t\t\\lim _{z \\rightarrow \\sqrt{n}}&(z-\\sqrt{n})^{2} \\cdot \\frac{z}{\\sin \\pi z^{2}}, \\text{exists. So its pole of order 2}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\n\t\\item The value of the contour integral $\\frac{1}{2 \\pi i} \\oint_{C} \\frac{e^{4 z}-1}{\\cosh (z)-2 \\sinh (z)} d z$ around the unit circle $C$ traversed in the anti-clockwise direction, is\n\t{\\exyear{NET/JRF(JUNE-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] 2\n\t\t\\task[\\textbf{C.}] $\\frac{-8}{\\sqrt{3}}$\n\t\t\\task[\\textbf{D.}] $-\\tanh \\left(\\frac{1}{2}\\right)$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{e^{4 z}-1}{\\cosh z-2 \\sinh z}=\\frac{e^{4 z}-1}{\\frac{e^{2}+e^{-z}}{2}-\\left(e^{z}-e^{-z}\\right)}\\\\&=\\frac{e^{42}-1}{-\\frac{e^{z}}{2}+\\frac{3}{2} e^{-z}}\\\\\n\t\t\\Rightarrow f(z)&=\\frac{2 e^{2}\\left(e^{4 z}-1\\right)}{\\left(3-e^{2 z}\\right)}=\\frac{2\\left(e^{5 z}-e^{z}\\right)}{\\left(3-e^{2 z}\\right)}\\\\\n\t\t\\text{For pole at }z&=z_{0}, 3-e^{2 \\xi_{0}}=0 \\Rightarrow e^{2 z_{0}}\\\\&=3 \\Rightarrow z_{0}=\\frac{\\ln 3}{2}\n\t\t\\intertext{It has simple pole at $z_{0}$}\n\t\t\\operatorname{Re}\\left(z_{0}\\right)&=\\lim _{z \\rightarrow z_{0}}\\left(z-z_{0}\\right) f(z)=\\lim _{2 \\rightarrow z_{0}}\\left(z-z_{0}\\right) \\frac{2\\left(e^{5 z}-e^{2}\\right)}{3-e^{22}}\\\\\n\t\t&=\\lim _{z \\rightarrow z_{0}} \\frac{\\left(z-z_{0}\\right) \\times 2\\left(5 e^{5 z}-e^{z}\\right)+2\\left(e^{5 z}-e^{z}\\right) \\times 1}{-2 e^{2 z}}\\\\&=-\\left(\\frac{e^{5 z_{0}}-e^{z_{0}}}{e^{2 z_{0}}}\\right)\\\\\n\t\t&=-\\left(\\frac{(\\sqrt{3})^{5}-\\sqrt{3}}{3}\\right)=-\\left(\\frac{9 \\sqrt{3}-\\sqrt{3}}{3}\\right)=-\\frac{8}{\\sqrt{3}}\\\\\n\t\t\\frac{1}{2 \\pi i} \\oint f(z) d z&=\\frac{1}{2 \\pi i} \\times 2 \\pi i \\sum\\text{ Residue } =-\\frac{8}{\\sqrt{3}}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item  Let $u(x, y)=e^{a x} \\cos (b y)$ be the real part of a function $f(z)=u(x, y)+i v(x, y)$ of the complex variable $z=x+i y$, where $a, b$ are real constants and $a \\neq 0 .$ The function $f(z)$ is complex analytic everywhere in the complex plane if and only if\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $b=0$\n\t\t\\task[\\textbf{B.}] $b=\\pm a$\n\t\t\\task[\\textbf{C.}] $b=\\pm 2 \\pi a$\n\t\t\\task[\\textbf{D.}]  $b=a \\pm 2 \\pi$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{The function $f(z)$ will be analytic everywhere in the complex plane if and only if it satisfies the Cauchy Riemann equation in that region.}\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y}\\text{ and } \\frac{\\partial u}{\\partial y}=-\\frac{\\partial v}{\\partial x}\\\\\n\t\t\\text{Hence }a e^{a x} \\cos (b y)&=\\frac{\\partial v}{\\partial y}\\hspace{2cm}\\text{(i)}\\\\\n\t\t\\text{and }b e^{a x} \\sin (b y)&=\\frac{\\partial v}{\\partial x}\\hspace{2cm}\\text{(ii)}\n\t\t\\intertext{From equation (i)}\n\t\tv(x, y)&=\\frac{a e^{a x} \\sin (b y)}{b}+c(y)\\hspace{2cm}\\text{(iii)}\n\t\t\\intertext{Differentiating partially with $x$ gives}\n\t\t\\frac{\\partial v}{\\partial x}&=\\frac{a^{2} e^{a x} \\sin (b y)}{b}\\hspace{2cm}\\text{(iv)}\n\t\t\\intertext{From equation (iii) and (iv)}\n\t\tb e^{a x} \\sin (b y)&=\\frac{a^{2} e^{a x} \\sin (b y)}{b}\\\\\n\t\t\\Rightarrow b^{2}&=a^{2} \\Rightarrow b=\\pm a\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\n\t\\item  The integral $\\oint_{\\Gamma} \\frac{z e^{i \\pi z / 2}}{z^{2}-1} d z$ along the closed contour $\\Gamma$ shown in the figure is\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20211005(19)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $2 \\pi$\n\t\t\\task[\\textbf{C.}] $-2 \\pi$\n\t\t\\task[\\textbf{D.}] $4 \\pi i$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{z e^{i z \\pi / 2}}{(z+1)(z-1)}\\\\\n\t\t\\text{For }z&=+1\\text{ anti-clockwise}\\\\\n\t\tI&=2 \\pi i \\lim _{z \\rightarrow 1} \\frac{z e^{i \\pi z / 2}}{(z+1)}=\\frac{2 \\pi i}{2} e^{i \\pi / 2}=\\pi i e^{i \\pi / 2}\\\\\n\t\t\\text{For }z&=-1\\\\\n\t\tI&=-2 \\pi i \\lim _{z \\rightarrow-1} \\frac{z e^{i \\pi z / 2}}{(z-1)}=-2 \\pi i \\times \\frac{(-1) e^{-i \\pi / 2}}{(-2)}=-\\pi i e^{-i \\pi / 2}\\\\\n\t\t\\text{Integral }&=\\pi i \\frac{\\left(e^{i \\pi / 2}-e^{-i \\pi / 2}\\right)}{2 i} \\times 2 i=2 \\pi i^{2} \\sin \\frac{\\pi}{2}=-2 \\pi\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item What is the value of $a$ for which $f(x, y)=2 x+3\\left(x^{2}-y^{2}\\right)+2 i(3 x y+a y)$ is an analytic function of complex variable $z=x+i y$\n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 1\n\t\t\\task[\\textbf{B.}] 0\n\t\t\\task[\\textbf{C.}] 3\n\t\t\\task[\\textbf{D.}] 2\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(x, y)&=2 x+3\\left(x^{2}-y^{2}\\right)+2 i(3 x y+\\alpha y)\\\\\n\t\tu&=2 x+3\\left(x^{2}-y^{2}\\right), v=2(3 x y+\\alpha y)\\\\\n\t\t\\text{C-R conditions: }u_{x}&=v_{y}, u_{y}=-v_{x}\\\\\n\t\t2+3(2 x)&=2(3 x+\\alpha) \\Rightarrow \\alpha=1 \\Rightarrow-6 y=-6 y\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item  The value of the integral $\\oint_{C} \\frac{d z}{z} \\frac{\\tanh 2 z}{\\sin \\pi z}$, where $C$ is a circle of radius $\\frac{\\pi}{2}$, traversed counter-clockwise, with centre at $z=0$, is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 4\n\t\t\\task[\\textbf{B.}] $4 i$\n\t\t\\task[\\textbf{C.}] $2 i$\n\t\t\\task[\\textbf{D.}] 0\n\t\\end{tasks}\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.5cm,width=5.5cm]{diagram-20211005(2)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t&\\oint_{C} \\frac{d z}{z} \\frac{\\tanh 2 z}{\\sin \\pi z} d z\\\\\n\t\tz&=0,1,-1, \\frac{\\pi i}{4}, \\frac{-\\pi i}{4}\\\\\n\t\tf(z)&=\\frac{2 z-\\frac{1}{3}(2 z)^{3}+\\frac{2}{15}(2 z)^{5} \\ldots .}{z\\left(\\pi z-\\frac{\\pi^{3} z^{3}}{3 !}+\\ldots\\right)}\\\\\n\t\t\\frac{2}{\\pi z}&\\left(1-\\frac{1}{2} z^{2}+\\ldots\\right)\\left(1-\\frac{\\pi^{2} z^{2}}{2 !}+\\ldots\\right)\\\\\n\t\tb_{1}&=\\frac{2}{\\pi}\\\\\n\t\t\\text{As Re } z&=1, \\frac{\\tanh ^{2}}{-\\pi}\\text{ and }\\operatorname{Re} z=-1, \\frac{\\tanh ^{2}}{-\\pi}\\\\\n\t\t\\operatorname{Re} z&=\\frac{i \\pi}{4}=-\\frac{1}{\\pi}\\left(2 \\operatorname{cosec} h \\frac{\\pi^{2}}{4}\\right)\\\\\n\t\t\\operatorname{Re} z&=\\frac{-i \\pi}{4}=-\\frac{1}{\\pi}\\left(2 \\operatorname{cosec} \\mathrm{h} \\frac{\\pi^{2}}{4}\\right)\n\t\t\\intertext{$I=2 \\pi i \\Sigma R=4 i$ only when 0 lies inside, otherwise wrong question.}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\n\t\\item The integral $I=\\int_{C} e^{z} d z$ is evaluated from the point $(-1,0)$ to $(1,0)$ along the contour $C$, which is an arc of the parabola $y=x^{2}-1$, as shown in the figure. The value of $I$ is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{diagram-20211005(3)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  0\n\t\t\\task[\\textbf{B.}] $2 \\sinh 1$\n\t\t\\task[\\textbf{C.}]  $e^{2 i} \\sinh 1$\n\t\t\\task[\\textbf{D.}] $e+e^{-1}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\int_{C} f(z) d z&=2 \\pi i \\Sigma R\\\\\n\t\t\\int_{C} f(z) d z+\\int_{1}^{-1} e^{x} d x&=0\\\\\n\t\t\\int_{C} f(z) d z&=-\\int_{1}^{-1} e^{x} d x=\\int_{1}^{-1} e^{x} d x\\\\&=\\frac{\\left(e^{1}-e^{-1}\\right)}{2} \\cdot 2=2 \\sinh 1\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\t\\end{answer}\n\t\\item The contour $C$ of the following integral\n\t$$\n\t\\oint_{C} d z \\frac{\\sqrt{(z-1)(z-3)}}{\\left(z^{2}-25\\right)^{3}}\n\t$$\n\tin the complex $z$ plane is shown in the figure below.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=6cm]{diagram-20211005(8)-crop}\n\t\\end{figure}\n\tThis integral is equivalent to an integral along the contours\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(4)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{B.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(5)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{C.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(6)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{D.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(7)-crop}\n\t\t\\end{figure}\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{$z=1,3$ are branch points $\\infty$ is not a branch point 1 branch cut 3}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item  Let $C$ be the circle of radius $\\frac{\\pi}{4}$ centered at $z=\\frac{1}{4}$ in the complex $z$-plane that is traversed counter-clockwise. The value of the contour integral $\\oint_{C} \\frac{z^{2}}{\\sin ^{2} 4 z} d z$ is\n\t{\\exyear{NET/JRF(DEC-2019)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $\\frac{i \\pi^{2}}{4}$\n\t\t\\task[\\textbf{C.}] $\\frac{i \\pi^{2}}{16}$\n\t\t\\task[\\textbf{D.}] $\\frac{i \\pi}{4}$\n\t\\end{tasks}\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=3cm]{diagram-20211026(16)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tf(z)&=\\left(\\frac{\\pi}{\\sin 4 z}\\right)^{2}\\\\\n\t\tz_{0}&=0, \\frac{\\pi}{4}\\text{ are poles}\\\\\n\t\t4 z&=n \\pi, z=0, \\frac{\\pi}{4}\n\t\t\\intertext{Others are outside the contour.}\n\t\t\\text{Residue at }z&=0\\text{ is }\\left[\\frac{\\pi}{4 z-\\frac{4^{3} z^{3}}{3 !}+\\ldots}\\right]^{2}\\\\\n\t\t&=\\left[\\frac{1}{4-\\frac{4^{3} z^{2}}{3 !}+\\ldots .}\\right]^{2}\\qquad \\text{ No terms for } \\frac{1}{z}, b_{1}=0\\\\\n\t\t&=\\left[4-\\frac{4^{3} z^{2}}{3 !}+\\ldots .\\right]^{-2}\\\\\n\t\t\\text{Residue for }z&=\\frac{\\pi}{4}\\\\\n\t\tz-\\frac{\\pi}{4}&=t\n\t\t\\intertext{$\\sin (4 t+\\pi)=-\\sin 4 t \\quad$ (But square so no effect)}\n\t\t&\\left[\\frac{t+\\frac{\\pi}{4}}{\\sin 4\\left(t+\\frac{\\pi}{4}\\right)}\\right]^{2}\\\\\n\t\t\\left(\\frac{t+\\frac{\\pi}{4}}{\\sin 4 t}\\right)^{2}&=\\frac{t^{2}+\\frac{\\pi^{2}}{4}+2 t \\cdot \\frac{\\pi}{4}}{\\sin ^{2} 4 t}\\\\\n\t\t\\frac{\\pi}{2} \\frac{t}{16 t^{2}[1-\\ldots .]^{2}}&=\\frac{\\pi}{32 t}[1-\\ldots .]^{-2} \\text{(from first term)}\\\\\n\t\tb_{1}&=\\frac{\\pi}{32}\\\\\n\t\t\\oint_{C} \\frac{z^{2}}{\\sin ^{2} 4 z} d z&=2 \\pi i\\left[0+\\frac{\\pi}{32}\\right]=\\frac{i \\pi^{2}}{16}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item  A function of a complex variable $z$ is defined by the integral $f(z)=\\oint_{\\Gamma} \\frac{w^{2}-2}{w-z} d w$, where $\\Gamma$ is a circular contour of radius 3 , centred at origin, running counter-clockwise in the $w$ - plane. The value of the function at $z=(2-i)$ is\n\t{\\exyear{NET/JRF(JUNE-2020)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $1-4 i$\n\t\t\\task[\\textbf{C.}]  $8 \\pi+2 \\pi \\mathrm{i}$\n\t\t\\task[\\textbf{D.}] $-\\frac{2}{\\pi}-\\frac{i}{2 \\pi}$\n\t\\end{tasks}\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=4.6cm]{diagram-20211027-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tf(z)&=\\oint_{\\Gamma} \\frac{w^{2}-2}{w-z} d w\\\\\n\t\t\\omega&=z\\text{ is a simple pole.}\\\\\n\t\t\\text{Residue }\\lim _{\\omega \\rightarrow z}(\\omega-z) \\frac{\\left(\\omega^{2}-2\\right)}{(\\omega-z)}&=(2-i)^{2}-2 \\\\&=4-1-4 i-2=(1-4 i)\\\\\n\t\tf(z)&=\\oint_{\\Gamma} \\frac{w^{2}-2}{w-z} d w=2 \\pi i(1-4 i)=2 \\pi i+8 \\pi\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\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{B}\\\\\\hline \n\t\t3&\\textbf{B} &4&\\textbf{A} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{D} \\\\\\hline\n\t\t7&\\textbf{A}&8&\\textbf{-}\\\\\\hline\n\t\t9&\\textbf{C}&10&\\textbf{A}\\\\\\hline\n\t\t11&\\textbf{C} &12&\\textbf{-}\\\\\\hline\n\t\t13&\\textbf{A}&14&\\textbf{B}\\\\\\hline\n\t\t15&\\textbf{C}&16&\\textbf{B}\\\\\\hline\n\t\t17&\\textbf{C} &18&\\textbf{A}\\\\\\hline\n\t\t19&\\textbf{B}&20&\\textbf{B}\\\\\\hline\n\t\t21&\\textbf{C}&22&\\textbf{C}\\\\\\hline\n\t\t23&\\textbf{C}& &\\\\\\hline\n\t\t\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\t\\item  The value of the integral $\\oint_{C} \\frac{e^{z} \\sin (z)}{z^{2}} d z$, where the contour $C$ is the unit circle: $|z-2|=1$, is\n\t{\\exyear{GATE 2010}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $2 \\pi i$\n\t\t\\task[\\textbf{B.}] $4 \\pi i$\n\t\t\\task[\\textbf{C.}] $\\pi i$\n\t\t\\task[\\textbf{D.}] 0\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{$|z-2|=1 \\Rightarrow 1<z<3$ i.e. the pole $z=0$ does not lie inside the contour.}\n\t\t\\therefore \\quad \\oint_{C} \\frac{e^{z} \\sin z}{z^{2}} d z=2 \\pi i \\times 0=0 .\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (D)}\n\t\\end{answer}\n\t\\item Which of the following statements is TRUE for the function $f(z)=\\frac{z \\sin z}{(z-\\pi)^{2}}$ ?\n\t{\\exyear{GATE 2011}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $f(z)$ is analytic everywhere in the complex plane\n\t\t\\task[\\textbf{B.}] $f(z)$ has a zero at $z=\\pi$\n\t\t\\task[\\textbf{C.}] $f(z)$ has a pole of order 2 at $z=\\pi$\n\t\t\\task[\\textbf{D.}] $f(z)$ has a simple pole at $z=\\pi$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)=\\frac{z \\sin z}{(z-\\pi)^{2}}\\text{ has a pole of order 2 at }z=\\pi\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item For the function $f(z)=\\frac{16 z}{(z+3)(z-1)^{2}}$, the residue at the pole $z=1$ is (your answer should be an integer)-------\n\t{\\exyear{GATE 2013}}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tAt }z&=1,\\text{ pole is of order 2 .} \\\\&\\text{So, residue is }\\frac{1}{\\lfloor-1} \\frac{d^{2-1}}{d z^{2-1}}\\left[\\frac{(z-1)^{2} 16 z}{(z+3)(z-1)^{2}}\\right]_{z=1}=3\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The value of the integral\n\t$$\n\t\\oint_{C} \\frac{z^{2}}{e^{z}+1} d z\n\t$$\n\twhere $C$ is the circle $|z|=4$, is\n\t{\\exyear{GATE 2014}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $2 \\pi i$\n\t\t\\task[\\textbf{B.}] $2 \\pi^{2} i$\n\t\t\\task[\\textbf{C.}]  $4 \\pi^{3} i$\n\t\t\\task[\\textbf{D.}] $4 \\pi^{2} i$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tPole }e^{z}&=-1 \\Rightarrow e^{z}=e^{i(2 m+1) \\pi}\\text{ where }m=0,1,2,3 \\ldots \\ldots\\\\\n\t\t\\text{For }z&=i \\pi,\\text{ Res }=\\lim _{z=i \\pi} \\frac{\\phi(z)}{\\phi^{\\prime}(z)}\\\\&=-\\frac{\\pi^{2}}{e^{i \\pi}}=\\pi^{2}\\\\\n\t\t\\text{Similarly, for }z&=-i \\pi,\\text{ Res }=\\pi^{2}\\\\\n\t\t\\therefore I&=2 \\pi i\\left(\\pi^{2}+\\pi^{2}\\right)=4 \\pi^{3} i\n\t\t\\end{align*}\n\t\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\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 statements is correct?\n\t{\\exyear{GATE 2015}}\n\t\\begin{tasks}(1)\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\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{1}{z\\left(z+\\frac{1}{2}\\right) \\cos (z \\pi)}\\\\\n\t\t\\text{\tFor $n^{t h}$ order pole, Res. }&=\\lim _{z \\rightarrow a}(z-a)^{n} f(z)=\\text{ finite}\\\\\n\t\t\\text{At }z&=0, \\lim _{z \\rightarrow 0} z f(z)=\\text{ finite }\\\\\\Rightarrow z&=0\\text{ is a simple pole.}\\\\\n\t\t\\text{At }z&=-\\frac{1}{2}, \\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{\\left(z+\\frac{1}{2}\\right)^{2}}{z\\left(z+\\frac{1}{2}\\right) \\cos z \\pi}=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{\\left(z+\\frac{1}{2}\\right)}{z \\cos z \\pi}\\\\&=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{1}{1 . \\cos z \\pi+z . \\pi(-\\sin z \\pi)}\\\\\n\t\t&=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{1}{\\cos z \\pi-z \\pi \\sin z \\pi}=\\frac{1}{-\\frac{\\pi}{2}}\\\\&=-\\frac{2}{\\pi}=\\text{ finite}\\\\\n\t\t\\Rightarrow f(z)\\text{ has second order pole at }z&=-\\frac{1}{2}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item  Consider $w=f(z)=u(x, y)+i v(x, y)$ to be an analytic function in a domain $D$. Which one of the following options is NOT correct?\n\t{\\exyear{GATE 2015}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $u(x, y)$ satisfies Laplace equation in D\n\t\t\\task[\\textbf{B.}]  $v(x, y)$ satisfies Laplace equation in $D$\n\t\t\\task[\\textbf{C.}] $\\int_{1}^{z_{2}} f(z) d z$ is dependent on the choice of the contour between $z_{1}$ and $z_{2}$ in $D$\n\t\t\\task[\\textbf{D.}]  $f(z)$ can be Taylor expended in $D$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tw&=f(z)=u(x, y)+i v(x, y)\\text{ to be an analytic function in a domain }D, \\int_{z_{1}}^{z_{2}} f(z) d z\\text{ is}\\\\\n\t\t&\\text{independent of the choice of the contour between }z_{1}\\text{ and }z_{2}\\text{ in }D.\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item A function $y(z)$ satisfies the ordinary differential equation $y^{\\prime \\prime}+\\frac{1}{z} y^{\\prime}-\\frac{m^{2}}{z^{2}} y=0$, where\\\\\n\t$m=0,1,2,3, \\ldots . .$ Consider the four statements P, Q, R, S as given below.\\\\\n\t$\\mathrm{P}: z^{m}$ and $z^{-m}$ are linearly independent solutions for all values of $m$\\\\\n\tQ: $z^{m}$ and $z^{-m}$ are linearly independent solutions for all values of $m>0$\\\\\n\t$\\mathrm{R}$ : $\\ln z$ and 1 are linearly independent solutions for $m=0$\\\\\n\tS: $z^{m}$ and $\\ln z$ are linearly independent solutions for all values of $m$\\\\\n\tThe correct option for the combination of valid statements is\n\t{\\exyear{GATE 2015}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] P, R and S only\n\t\t\\task[\\textbf{B.}]  P and R only\n\t\t\\task[\\textbf{C.}] $\\mathrm{Q}$ and $\\mathrm{R}$ only\n\t\t\\task[\\textbf{D.}] $\\mathrm{R}$ and $\\mathrm{S}$ only\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\ty^{\\prime \\prime}+\\frac{1}{z} y^{\\prime}-\\frac{m^{2}}{z^{2}} y&=0 \\Rightarrow z^{2} y^{\\prime \\prime}+z y^{\\prime}-m^{2} y\\\\&=0, m=0,1,2,3, \\ldots, \\quad z=e^{x}, D=\\frac{d}{d x}\\\\\n\t\t\\text{\tIf }m&=0 ; \\quad z^{2} y^{\\prime \\prime}+z y^{\\prime}=0,[D(D-1)+D] y\\\\&=0 \\Rightarrow\\left[D^{2}-D+D\\right] y=0\\\\\n\t\tD^{2} y&=0 \\Rightarrow y=c_{1}+c_{2} x \\Rightarrow y\\\\&=c_{1}+c_{2} \\ln z \\quad \\text{( $R$ is correct)}\\\\\n\t\t\\text{And if }m &\\neq 0, m>0,\\text{ then }m \\neq 0,\\text{ then }\\left(D^{2}-m^{2}\\right) y\\\\&=0 \\Rightarrow D=\\pm m\\\\\n\t\ty&=c_{1} e^{m x}+c_{2} e^{-m x}=c_{1} e^{m \\log z}+c_{2} e^{-m \\log z}\\\\&=c_{1} z^{m}+c_{2} z^{-m}\\\\\n\t\t\\text{or if }m &\\neq 0, m>0,\\text{ then}\\\\\n\t\ty&=c_{1} \\cosh (m \\log (z))+i c_{2} \\sinh (m \\log (x)), \\quad m>0\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)} \n\t\\end{answer}\n\t\\item  Which of the following is an analytic function of $z$ everywhere in the complex plane?\n\t{\\exyear{GATE 2016}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $z^{2}$\n\t\t\\task[\\textbf{B.}]  $\\left(z^{*}\\right)^{2}$\n\t\t\\task[\\textbf{C.}] $|z|^{2}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{z}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tz^{2}&=(x+i y)^{2}=x^{2}-y^{2}+i(2 x y) \\Rightarrow u\\\\&=x^{2}-y^{2}\\text{ and }v=2 x y\\\\\n\t\t\\text{Cauchy Riemann equations }\\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y}=2 x, \\quad \\frac{\\partial v}{\\partial x}=-\\frac{\\partial u}{\\partial y}=2 y\\text{ satisfies.}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\t\\item The contour integral $\\oint \\frac{d z}{1+z^{2}}$ evaluated along a contour going from $-\\infty$ to $+\\infty$ along the\n\treal axis and closed in the lower half-plane circle is equal to............... (up to two decimal places).\n\t{\\exyear{GATE 2017}}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\oint_{c} \\frac{1}{1+z^{2}} d z&=\\int_{-\\infty}^{+\\infty} \\frac{1}{1+x^{2}} d x+\\oint_{c} \\frac{1}{1+z^{2}} d z\\\\\n\t\t\\text{Poles, }1+z^{2}&=0 \\Rightarrow z=\\pm i, \\quad z=-i\\text{ is inside }C\\\\\n\t\t\\therefore \\operatorname{Res}(z=-i)&=\\lim _{z \\rightarrow-i}(z+i) \\frac{1}{(z-i)(z+i)}\\\\&=\\frac{1}{-i-i}=\\frac{1}{-2 i}\\\\\n\t\t\\int_{-\\infty}^{+\\infty} \\frac{1}{1+x^{2}} d x&=-\\frac{1}{2 i} \\times-2 \\pi i=\\pi\n\t\t\\intertext{(Since, here we use lower half plane i.e., we traversed in clockwise direction, hence we have to take $-2 \\pi i$ )}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The imaginary part of an analytic complex function is $v(x, y)=2 x y+3 y .$ The real part of the function is zero at the origin. The value of the real part of the function at $1+i$ is ................. (up to two decimal places)\n\t{\\exyear{GATE 2017}}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{Solution: The imaginary part of the given analytic function is $v(x, y)=2 x y+3 y .$ From the\n\t\t\tCauchy - Riemann condition}\n\t\t\\frac{\\partial v}{\\partial y}&=\\frac{\\partial u}{\\partial x}=2 x+3\n\t\t\\intertext{Integrating partially gives}\n\t\tu(x, y)&=x^{2}+3 x+g(y)\\\\\n\t\t\\intertext{From the second Cauchy - Riemann condition}\n\t\t\\frac{\\partial u}{\\partial y}&=-\\frac{\\partial v}{\\partial x},\\text{ we obtain} \\frac{\\partial u}{\\partial y}\\\\&=-2 y, \\mu(x, y)=-y^{2}+g(x)\\\\\n\t\t\\frac{d g(y)}{d y}&=-2 y \\Rightarrow g(y)=-y^{2}+c\\\\\n\t\t\\text{\tHence, }u(x, y)&=x^{2}+3 x-y^{2}+c\n\t\t\\intertext{Since, the real part of the analytic function is zero at the origin.}\n\t\t\\text{Hence, }0&=0+0-0+c \\Rightarrow c=0\\\\\n\t\t\\text{Thus, }u(x, y)&=x^{2}+3 x-y^{2}\\\\\n\t\t\\therefore f(z)&=\\left(x^{2}+3 x-y^{2}\\right)+i(2 x y+3 y)\n\t\t\\intertext{Thus, the value of real part when}\n\t\tz&=1+i, i.e. x=1\\text{ and }y=1\\text{ is }u(x, y)\\\\&=(1)^{2}+3(1)-1=3\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The absolute value of the integral\n\t$$\n\t\\int \\frac{5 z^{3}+3 z^{2}}{z^{2}-4} d z\n\t$$\n\tover the circle $|z-1.5|=1$ in complex plane, is $\\ldots$ (up to two decimal places).\n\t{\\exyear{GATE 2018}}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\frac{5 z^{3}+3 z^{2}}{(z-2)(z+2)}\\\\\n\t\t\\text{Pole, }z&=2,-2\\\\\n\t\tz&=-2 \\text{ is outside the center}\\\\\n\t\t|-2-1.5|>1&\\text{So, will not be considered}\\\\\n\t\t\\text{\tNow, }\\operatorname{Re} s(2)&=\\lim _{z \\rightarrow 2}(z-2) \\frac{\\left(5 z^{3}+3 z^{2}\\right)}{(z-2)(z+2)}\\\\&=\\frac{52^{3}+32^{2}}{4}=\\frac{40+12}{4}=13\\\\\n\t\tI&=2 \\pi i \\times residue =2 \\pi i \\times 13\\\\&=26 \\times 3.14 \\Rightarrow I=81.64\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The pole of the function $f(z)=\\cot z$ at $z=0$ is\n\t{\\exyear{GATE 2019}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] A removable pole\n\t\t\\task[\\textbf{B.}] An essential singularity\n\t\t\\task[\\textbf{C.}]  A simple pole\n\t\t\\task[\\textbf{D.}] A second order pole\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tf(z)&=\\cot z\\text{ at }z=0\\\\\n\t\tf(z)&=\\frac{1}{\\tan z} \\quad z=0\\text{ is a simple pole }\\\\f(z)&=\\frac{1}{z}\\left[1-\\frac{1}{3} z^{2}+\\ldots .\\right]\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\t\\end{answer}\n\t\\item The value of the integral $\\int_{-\\infty}^{\\infty} \\frac{\\cos (k x)}{x^{2}+a^{2}} d x$, where $k>0$ and $a>0$, is\n\t{\\exyear{GATE 2019}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{a} e^{-k a}$\n\t\t\\task[\\textbf{B.}] $\\frac{2 \\pi}{a} e^{-k a}$\n\t\t\\task[\\textbf{C.}] $\\frac{\\pi}{2 a} e^{-k a}$\n\t\t\\task[\\textbf{D.}] $\\frac{3 \\pi}{2 a} e^{-k a}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t&\\int_{-\\infty}^{\\infty} \\frac{\\cos k x}{x^{2}+a^{2}} d x\\\\\n\t\tf(z)&=\\frac{e^{i k x}}{z^{2}+a^{2}}=\\frac{e^{i k z}}{(z+i a)(z-i a)}\\\\\n\t\tI&=\\operatorname{Re} .2 \\pi i \\times \\frac{e^{i k(i a)}}{2 i a}=\\frac{\\pi e^{-k a}}{a}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\t\\end{answer}\n\\item The value of the integral $\\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+1\\right)^{2}} d x$ is\n{\\exyear{ JEST 2012}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]0\n\t\\task[\\textbf{b.}]$\\frac{-\\pi}{4}$\n\t\\task[\\textbf{c.}] $\\frac{-\\pi}{2}$\n\t\\task[\\textbf{d.}] $\\frac{\\pi}{2}$\n\\end{tasks}\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4.6cm]{JEST 01 2012}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+1\\right)^{2}} d x&=\\int_{0}^{\\infty} \\frac{\\ln z}{\\left(z^{2}+1\\right)^{2}} d z\\\\\n\t\\text{Let us }&\\text{consider new function }f(z)=\\left(\\frac{\\ln z}{z^{2}+1}\\right)^{2},\\text{ then }I=\\int_{0}^{\\infty}\\left(\\frac{\\ln z}{z^{2}+1}\\right)^{2} d z\\\\\n\\text{\tPole at }z&=\\pm i\\text{ is simple pole of second order.}\\\\\n\\text{\tResidue at }z&=i\\text{ is}\\\\\n&=\\frac{d}{d z}(z-i)^{2} \\frac{(\\ln z)^{2}}{(z-i)^{2}(z+i)^{2}}=\\frac{d}{d z} \\frac{(\\ln z)^{2}}{(z+i)^{2}}\\\\\n&=\\frac{(z+i)^{2} 2(\\ln z) \\cdot \\frac{1}{z}-(\\ln z)^{2} \\cdot 2(z+i)}{(z+i)^{4}}=\\frac{(z+i) 2 \\ln (z) \\frac{1}{z}-(\\ln z)^{2} \\cdot 2}{(z+i)^{3}}\\\\\n&=\\frac{(2 i) 2 \\times \\frac{1}{i} \\ln i-(\\ln i)^{2} \\cdot 2}{(2 i)^{3}}=\\frac{4 \\frac{i \\pi}{2}-\\left(\\frac{i \\pi}{2}\\right)^{2} \\times 2}{-8 i}=\\frac{2 \\pi i+\\frac{\\pi^{2}}{2}}{-8 i}\\\\\n\\left.\\Rightarrow \\operatorname{Res}\\right|_{z=i}&=\\frac{-\\pi}{4}+\\frac{\\pi^{2}}{16} i\\\\\n\\text{Similarly, at }z&=-i ;\\left.\\operatorname{Res}\\right|_{z=-i}=\\frac{-\\pi}{4}-\\frac{\\pi^{2}}{16} i\\\\\nI&=\\int_{0}^{\\infty}\\left(\\frac{\\ln z}{z^{2}+1}\\right)^{2} d z=2 \\pi i\\left(\\frac{-\\pi}{4}+\\frac{\\pi^{2}}{16} i-\\frac{\\pi}{4}-\\frac{\\pi^{2}}{16} i\\right)=-\\pi^{2} i\\\\\n-\\pi^{2} i&=\\left(\\int_{R} \\int_{A} \\int_{B}\\right) f(z) d z=\\left(\\iint_{A B}\\right) f(z) d z ;\\qquad \\left[\\because \\int_{A B}\\right.\\text{ vanish }]\\\\\n\\text{Along path }A ;& \\quad z=-x+i \\varepsilon\\text{ and along path }B ; \\quad z=-x-i \\varepsilon\\\\\n\\text{Thus }-\\pi^{2} i&=\\left(\\iint_{A B}\\right) f(z) d z=-\\int_{-\\infty}^{0}\\left[\\frac{\\ln (-x+i \\varepsilon)}{(-x+i \\varepsilon)^{2}+1}\\right] d x-\\int_{0}^{\\infty}\\left[\\frac{\\ln (-x-i \\varepsilon)}{(-x-i \\varepsilon)^{2}+1}\\right] d x\\\\\n\\Rightarrow-\\pi^{2} i&=\\int_{0}^{\\infty}\\left[\\frac{\\ln (-x+i \\varepsilon)}{(-x+i \\varepsilon)^{2}+1}\\right]^{2} d x-\\int_{0}^{\\infty}\\left[\\frac{\\ln (-x-i \\varepsilon)}{(-x-i \\varepsilon)^{2}+1}\\right]^{2} d x\\\\\n\\Rightarrow-\\pi^{2} i&=\\int_{0}^{\\infty}\\left[\\frac{\\ln (x)+i \\pi}{1+x^{2}}\\right]^{2} d x-\\int_{0}^{\\infty}\\left[\\frac{\\ln (x)-i \\pi}{1+x^{2}}\\right]^{2} d x ; \\quad \\varepsilon \\rightarrow 0\\\\\n\\Rightarrow-\\pi^{2} i&=\\int_{0}^{\\infty} \\frac{(\\ln (x)+i \\pi)^{2}-(\\ln (x)-i \\pi)^{2}}{\\left(1+x^{2}\\right)^{2}} d x\\\\&=4 \\pi i \\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+1\\right)^{2}} \\Rightarrow \\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+1\\right)^{2}}=\\frac{-i \\pi^{2}}{4 \\pi i}=\\frac{-\\pi}{4}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (B)}\n\\end{answer}\n\\item Compute $\\lim _{z \\rightarrow 0} \\frac{\\operatorname{Re}\\left(z^{2}\\right)+\\operatorname{Im}\\left(z^{2}\\right)}{z^{2}}$\n{\\exyear{ JEST 2013}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] The limit does not exist\n\t\\task[\\textbf{b.}]1\n\t\\task[\\textbf{c.}]$-i$\n\t\\task[\\textbf{d.}] $-1$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\lim _{z \\rightarrow 0} \\frac{\\operatorname{Re}\\left(z^{2}\\right)+\\operatorname{Im}\\left(z^{2}\\right)}{z^{2}}&=\\lim _{z \\rightarrow 0} \\frac{x^{2}-y^{2}+2 x y}{x^{2}-y^{2}+2 i x y}=\\lim _{y=0 \\atop x \\rightarrow 0} \\frac{x^{2}-y^{2}+2 x y}{x^{2}-y^{2}+2 i x y}=1\\\\\n\t\\lim _{x=0 \\atop y \\rightarrow 0} \\frac{x^{2}-y^{2}+2 x y}{x^{2}-y^{2}+2 i x y}&=1\\text{ and }\\lim _{y=x \\atop x \\rightarrow 0} \\frac{x^{2}-y^{2}+2 x y}{x^{2}-y^{2}+2 i x y}=-i\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\\end{answer}\n\\item The value of limit\n$$\n\\lim _{z \\rightarrow i} \\frac{z^{10}+1}{z^{6}+1}\n$$\nis equal to\n{\\exyear{ JEST 2014}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]1\n\t\\task[\\textbf{b.}]0\n\t\\task[\\textbf{c.}] $\\frac{-10}{3}$\n\t\\task[\\textbf{d.}] $\\frac{5}{3}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\lim _{z \\rightarrow i} \\frac{z^{10}+1}{z^{6}+1}=\\lim _{z \\rightarrow i} \\frac{10 z^{9}}{6 z^{5}}=\\lim _{z \\rightarrow i} \\frac{10 z^{4}}{6}=\\frac{10}{6}=\\frac{5}{3}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (D)}\n\\end{answer}\n\\item The value of integral\n$$\nI=\\oint \\frac{\\sin z}{2 z-\\pi} d z\n$$\nwith $c$ a circle $|z|=2$, is\n{\\exyear{ JEST 2014}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] 0\n\t\\task[\\textbf{b.}]$2 \\pi i$\n\t\\task[\\textbf{c.}] $\\pi i$\n\t\\task[\\textbf{d.}]  $-\\pi i$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tI&=\\oint_{C} \\frac{\\sin z}{2 z-\\pi},\\text{ for pole }2 z-\\pi=0 \\Rightarrow z=\\frac{\\pi}{2}\\\\\n\\text{\tResidue at }z&=\\frac{\\pi}{2}\n\t\\because|z|=2\\text{, so pole will lie within the contour}\\\\\n\tI&=\\oint_{C} \\frac{e^{i z}}{2\\left(z-\\frac{\\pi}{2}\\right)}=\\sum R \\times 2 \\pi i\\\\\n\t\\left.\\operatorname{Res}\\right|_{z=\\frac{\\pi}{2}}&=\\frac{\\left(z-\\frac{\\pi}{2}\\right) e^{i z}}{2\\left(z-\\frac{\\pi}{2}\\right)}=\\frac{e^{i \\pi / 2}}{2}=\\frac{i}{2}\\text{ (taking imaginary part); Residue }=\\frac{1}{2}\\\\\n\t\\text{Now, }I&=\\frac{1}{2} \\times 2 \\pi i=\\pi i\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\\end{answer}\n\\item Given an analytic function $f(z)=\\phi(x, y)+i \\psi(x, y)$, where $\\phi(x, y)=x^{2}+4 x-y^{2}+2 y$\nIf $C$ is a constant, which of the following relations is true?\n{\\exyear{ JEST 2015}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\psi(x, y)=x^{2} y+4 y+C$\n\t\\task[\\textbf{b.}]$\\psi(x, y)=2 x y-2 x+C$\n\t\\task[\\textbf{c.}]$\\psi(x, y)=2 x y+4 y-2 x+C$\n\t\\task[\\textbf{d.}] $\\psi(x, y)=x^{2} y-2 x+C$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align}\n\tu&=\\phi(x, y)=x^{2}+4 x-y^{2}+2 y, v=\\psi\\notag\\\\\n\t\\text{From C.R. equation, }\\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y}, \\Rightarrow \\frac{\\partial \\phi}{\\partial x}=\\frac{\\partial \\psi}{\\partial y}, \\frac{\\partial u}{\\partial y}=-\\frac{\\partial v}{\\partial x} \\Rightarrow \\frac{\\partial \\phi}{\\partial y}=-\\frac{\\partial \\psi}{\\partial x}\\notag\\\\\n\t\\text{Now, }\\frac{\\partial \\phi}{\\partial x}&=2 x+4=\\frac{\\partial \\psi}{\\partial y}\\notag\\\\\n\t\\Rightarrow \\psi&=2 x y+4 y+f(x)\\label{CN 01}\\\\\n\t\\text{and }\\frac{\\partial \\phi}{\\partial y}&=-2 y+2 \\Rightarrow \\frac{\\partial \\psi}{\\partial x}=+2 y-2\\notag\\\\\n\t\\psi&=2 x y+2 x+f(y)\\label{CN 02}\\\\\n\t\\text{From (\\ref{CN 01}) and (\\ref{CN 02}), }&2 x y+4 y+f(x)=2 x y-2 x+f(y)\\notag\\\\\n\tf(x)&=-2 x, \\quad f(y)=4 y \\notag\\\\\n\t\\psi&=2 x y+4 y-2 x+c\\notag\n\t\\end{align}\n\t\tSo the correct answer is \\textbf{Option (C)}\n\\end{answer}\n\\item Which one is the image of the complex domain $\\{z \\mid x y \\geq 1, x+y>0\\}$ under the mapping $f(z)=z^{2}$, if $z=x+i y ?$\n{\\exyear{ JEST 2017}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}] $\\{z \\mid x y \\geq 1, x+y>0\\}$\n\t\\task[\\textbf{b.}]$\\{z \\mid x \\geq 2, x+y>0\\}$\n\t\\task[\\textbf{c.}]$\\{z \\mid y \\geq 2 \\forall x\\}$\n\t\\task[\\textbf{d.}] $\\{z \\mid y \\geq 1 \\forall x\\}$\n\\end{tasks}\n\\item The integral $I=\\int_{1}^{\\infty} \\frac{\\sqrt{x-1}}{(1+x)^{2}} d x$ is\n{\\exyear{ JEST 2017}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{\\sqrt{2}}$\n\t\\task[\\textbf{b.}]$\\frac{\\pi}{2 \\sqrt{2}}$\n\t\\task[\\textbf{c.}]$\\frac{\\sqrt{\\pi}}{2}$\n\t\\task[\\textbf{d.}]$\\sqrt{\\frac{\\pi}{2}}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tI&=\\int_{1}^{\\infty} \\frac{\\sqrt{x-1}}{(1+x)^{2}} d x\\\\\n\\text{\tPut,} x&=\\left(1+z^{2}\\right), d x=2 z d z\\\\\n\t\\text{Hence, }I&=\\int_{0}^{\\infty} \\frac{2 z^{2} d z}{\\left(2+z^{2}\\right)^{2}}\\\\\n\t\\text{Here poles, }\\left(2+z^{2}\\right)&=0 \\Rightarrow(z+i \\sqrt{2})(z-i \\sqrt{2})=0\\\\\n\\text{\tOnly }&(z=i \\sqrt{2})\\text{ poles is allowed}\\\\\n\\text{Then }R(i \\sqrt{2})&=\\lim _{z \\rightarrow i \\sqrt{2}} \\frac{1}{\\sqrt{2-1}} \\frac{d}{d z}\\left[\\frac{2 z^{2}(z-i \\sqrt{2})^{2}}{(z-i \\sqrt{2})^{2}(z+i \\sqrt{2})^{2}}\\right]\\\\\n&=\\lim _{z \\rightarrow i \\sqrt{2}}\\left[\\frac{(z+i \\sqrt{2})^{2} \\cdot 4 z-2 z^{2} \\cdot 2(z+i \\sqrt{2})}{(z+i \\sqrt{2})^{4}}\\right]\\\\\n&=\\frac{(2 i \\sqrt{2})^{2} \\times 4(i \\sqrt{2})-2(i \\sqrt{2})^{2} \\cdot 2(2 i \\sqrt{2})}{(2 i \\sqrt{2})^{4}}\\\\&=-\\frac{32 \\sqrt{2} i+16 \\sqrt{2} i}{64}=-\\frac{16 \\sqrt{2} i}{64}=-\\frac{i}{2 \\sqrt{2}}\\\\\n\\text{Hence, }\\int_{-\\infty}^{\\infty} \\frac{2 z^{2}}{\\left(2+z^{2}\\right)^{2}} d z&=2 \\pi i\\left(-\\frac{i}{2 \\sqrt{2}}\\right)=\\frac{\\pi}{\\sqrt{2}}\\\\\n\\Rightarrow \\int_{0}^{\\infty} \\frac{2 z^{2}}{\\left(2+z^{2}\\right)^{2}} d z&=\\frac{\\pi}{2 \\sqrt{2}} \\Rightarrow \\int_{i}^{\\infty} \\frac{\\sqrt{x-1}}{(1+x)^{2}} d x=\\frac{\\pi}{2 \\sqrt{2}}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (B)}\n\\end{answer}\n\\item The integral\n$$\n\\int_{-\\infty}^{\\infty} \\frac{\\cos x}{x^{2}+1} d x \\text { is }\n$$\n{\\exyear{ JEST 2018}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{e}$\n\t\\task[\\textbf{b.}] $\\pi e^{-2}$\n\t\\task[\\textbf{c.}]$\\pi$\n\t\\task[\\textbf{d.}] zero\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tf(z)&=\\frac{e^{i z}}{z^{2}+1}=\\frac{e^{i z}}{(z+i)(z-i)}\\\\\n\t\\int_{-\\infty}^{\\infty} \\frac{\\cos x}{x^{2}+1} d x&=\\operatorname{Re} 2 \\pi i \\times \\frac{e^{i \\cdot i}}{z i}=\\frac{\\pi}{e}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (A)}\n\\end{answer}\n\\item Consider the function $f(x, y)=|x|-i|y| .$ In which domain of the complex plane is this function analytic?\n{\\exyear{ JEST 2019}}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]First and second quadrants\n\t\\task[\\textbf{b.}]Second and third quadrants\n\t\\task[\\textbf{c.}]Second and fourth quadrants\n\t\\task[\\textbf{d.}]  Nowhere\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t f(x, y)&=|x|-i|y|\\\\\n\tf(x, y)&=x-i y=\\bar{z}\\\\\n\tf(x, y)&=-x-i y=-z\\\\\n\tf(x, y)&=-x+i y=-\\bar{z}\\\\\n\tf(x, y)&=x+i y=z\n\t\\intertext{We know $\\bar{z}$ is not analytic and $z$ and $-z$ are analytic. }\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (C)}\n\\end{answer}\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.7cm}||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{C}\\\\\\hline \n\t\t3&\\textbf{3(NAT)} &4&\\textbf{C} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{C} \\\\\\hline\n\t\t7&\\textbf{C}&8&\\textbf{A}\\\\\\hline\n\t\t9&\\textbf{$\\pi$(NAT)}&10&\\textbf{3(NAT)}\\\\\\hline\n\t\t11&\\textbf{81.64(NAT)} &12&\\textbf{C}\\\\\\hline\n\t\t13&\\textbf{A}& 14&\\textbf{B}\\\\\\hline\n\t\t15&\\textbf{A}&16 &\\textbf{D}\\\\\\hline\n\t\t17&\\textbf{C}&18&\\textbf{C}\\\\\\hline\n\t\t19&\\textbf{-} &20&\\textbf{B}\\\\\\hline\n\t\t21&\\textbf{A}&22&\\textbf{C}\\\\\\hline\n\t\\end{tabular}\n\\end{table}", "meta": {"hexsha": "de7b256ec826e15e935d0ebb9801bf328921ba90", "size": 46216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Complex Problem Set Solutions.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/Complex Problem Set Solutions.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/Complex Problem Set Solutions.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.8986784141, "max_line_length": 316, "alphanum_fraction": 0.5804916046, "num_tokens": 21072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.6363555804186913}}
{"text": "\\section{Data Description and Preprocessing}\n\\subsection{Fundamental Data Description}\n\nThe data used within this project was obtained from a study carried out as part of a research program for the \\textit{UK Forensic Science Service} \\cite{ForensicScienceInduction}. The data set contained a total of $214$ glass fragments that were obtained in a pre-split of $149$ training and $65$ test samples. For each glass fragment, a total of nine features were recorded, including a measure of the refractive index (RI), which describes how fast light travels through a material. It is a standard measure in glass analysis as it varies significantly for different types of glass. The remaining eight measured features described the chemical composition of the glass fragment in percent. Table \\ref{features} lists all measured features.\n\\newline\n\n\\begin{table}[!ht]\n  \\footnotesize\n  \\centering\n\\begin{tabular}{ c c c c c c c c c }\n \\toprule\n \\textbf{RI} & \\textbf{Na} & \\textbf{Mg} & \\textbf{Al} & \\textbf{Si} & \\textbf{K} & \\textbf{Ca} & \\textbf{Ba} & \\textbf{Fe} \\\\ \n \\midrule \n Refractive Index & Sodium & Magnesium & Aluminium & Silicon & Potassium & Calcium & Barium & Iron \\\\ \n \\bottomrule\n\\end{tabular}\n\\captionsetup{justification=centering,margin=2cm}\n\\caption{Observed Features for Glass Fragments}\n\\label{features}\n\\end{table}\n\nEach glass fragment in the data set belonged to one of six classes. In the data the classes were integer-encoded and mapped to the respective glass types depicted in Table \\ref{classes}.\n\\newline\n\n\\begin{table}[!ht]\n  \\footnotesize\n  \\centering\n\\begin{tabular}{ c c }\n \\toprule\n Integer Code & Glass Type \\\\\n \\midrule \n 1 & Window from building (float processed) \\\\\n 2 & Window from building (non-float processed) \\\\ \n 3 & Window from vehicle \\\\\n 5 & Container \\\\\n 6 & Tableware \\\\\n 7 & Headlamp \\\\\n \\bottomrule\n\\end{tabular}\n\\captionsetup{justification=centering,margin=2cm}\n\\caption{Glass Types and their Encoding}\n\\label{classes}\n\\end{table}\n\n\\subsection{Data Cleaning}\nAll data integrity checks carried out, such as checking for missing values, checking for the ranges of each feature, and adding up the percentages in the chemical composition in all glass fragments, did not report any major inconsistencies. Thus, no further data cleaning was necessary.\n\n% To get reproducible results, the training data was further divided into a training and validation split, that were used in the training of all models. Furthermore, all splits were normalised using a standard normalisation, meaning that each feature was transformed such that it had a zero mean and unit variance. This was crucial for ensuring that each feature contributed to the PCA analysis independently of its scale and the gradient descent training algorithm in the neural network to work properly.", "meta": {"hexsha": "30aa9c6b4b6657c6606b20887936b95b74d98005", "size": 2798, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/02_preproc.tex", "max_stars_repo_name": "jonas-mika/ml-project", "max_stars_repo_head_hexsha": "c052c33010033cd9fd596eb5ac4d270d1bf98ee3", "max_stars_repo_licenses": ["MIT"], "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/02_preproc.tex", "max_issues_repo_name": "jonas-mika/ml-project", "max_issues_repo_head_hexsha": "c052c33010033cd9fd596eb5ac4d270d1bf98ee3", "max_issues_repo_licenses": ["MIT"], "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/02_preproc.tex", "max_forks_repo_name": "jonas-mika/ml-project", "max_forks_repo_head_hexsha": "c052c33010033cd9fd596eb5ac4d270d1bf98ee3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-29T17:23:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-29T17:23:15.000Z", "avg_line_length": 58.2916666667, "max_line_length": 741, "alphanum_fraction": 0.7719799857, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.8244619177503206, "lm_q1q2_score": 0.6363555790854374}}
{"text": "\\section{Stiefel-Whitney classes, immersions, cobordisms}\nThere is a result analogous to Theorem \\ref{chern-classes} for all vector\nbundles (not necessarily oriented):\n\\begin{theorem}\n    There exist a unique family of characteristic classes $w_i:\\Vect_n(X) \\to\n    H^n(X;\\FF_2)$ such that for $0\\leq i$ and $i>n$, we have $w_i=0$, and:\n    \\begin{enumerate}\n\t\\item $w_0 = 1$;\n\t\\item $w_1(\\lambda) = e(\\lambda)$; and\n\t\\item the Whitney sum formula holds:\n\t    \\begin{equation*}\n\t\tw_k(\\xi\\oplus\\eta) = \\sum_{i+j=k} w_i(\\xi)\\cup w_j(\\eta)\n\t    \\end{equation*}\n    \\end{enumerate}\n    Moreover:\n    $$\n    H^\\ast(BO(n);\\FF_2) = \\FF_2[w_1,\\cdots,w_n],\n    $$\n    where $w_n = e_2$.\n\\end{theorem}\n\\begin{remark}\n    We can express the Whitney sum formula simply by defining the \\emph{total\n    Steifel-Whitney class}\n    $$1 + w_1 + w_2 + \\cdots=:w.$$\n    Then the Whitney sum formula is just\n    $$\n    w(\\xi\\oplus\\eta) = w(\\xi)\\cdot w(\\eta).\n    $$\n    Likewise, the Whitney sum formula can be stated by defining the total Chern\n    class.\n\\end{remark}\n\\begin{remark}\\label{sw-stability}\n    Again, the Steifel-Whitney classes are stable:\n    $$w(\\xi\\oplus k\\epsilon) = w(\\xi).$$\n\\end{remark}\nAgain, Grothendieck's definition works since the splitting principle holds.\nThere is an injection $H^\\ast(BO(n))\\hookrightarrow H^\\ast(B(\\Z/2\\Z)^n)$. To\ncompute $H^\\ast(BO(n))$, our argument for computing $H^\\ast(BU(n))$ does not\nimmediately go through, although there is a fiber sequence\n$$S^{n-1} \\to EO(n)\\times_{O(n)} O(n)/O(n-1)\\to BO(n);$$\nthe problem is that $n-1$ can be even or odd. We still have a Gysin sequence,\nthough:\n$$\n\\cdots\\to H^{q-n}(BO(n))\\xar{e\\cdot} H^q(BO(n)) \\xar{\\pi^\\ast} H^q(BO(n-1)) \\to H^{q-n+1}(BO(n))\\to\\cdots\n$$\nIn order to apply our argument for computing $H^\\ast(BU(n))$ to this case, we\nonly need to know that $e$ is a nonzero divisor. The splitting principle gave a\nmonomorphism $H^\\ast(BO(n)) \\hookrightarrow H^\\ast((\\RP^\\infty)^n)$. The fact\nthat $e$ is a nonzero divisor follows from the observation that under this map,\n$$e_2=w_n\\mapsto e_2(\\lambda_1\\oplus\\cdots\\oplus\\lambda_n) = t_1\\cdots t_n,$$\nusing the same argument as in \\S \\ref{euler-multiplicativity}; however,\n$t_1\\cdots t_n$ {is} a nonzero divisor, since $H^\\ast((\\RP^\\infty)^n)$ is an\nintegral domain.\n\\subsection{Immersions of manifolds}\nThe theory developed above has some interesting applications to differential\ngeometry.\n\\begin{definition}\n    Let $M^n$ be a smooth closed manifold. An \\emph{immersion} is a smooth map\n    from $M^n$ to $\\RR^{n+k}$, denoted $f:M^n\\looparrowright \\RR^{n+k}$, such\n    that $(\\tau_{M^n})_x \\hookrightarrow (\\tau_{\\RR^{n+k}})_{f(x)}$ for $x\\in\n    M$.\n\\end{definition}\nInformally: crossings are allows, but not cusps.\n%It's a big problem in topology to try to eliminate the crossings.\n\\begin{example}\n    There is an immersion $\\RP^2 \\looparrowright \\RR^3$, known as \\emph{Boy's\n    surface}.\n\\end{example}\n\\begin{question}\n    When can a manifold admit an immersion into an Euclidean space?\n\\end{question}\nAssume we had an immersion $i:M^n\\looparrowright \\RR^{n+k}$.\nThen we have an embedding $f:\\tau_M \\to i^\\ast \\tau_{\\RR^{n+k}}$ into a trivial\nbundle over $M$, so $\\tau_M$ has a $k$-dimensional complement, called $\\xi$\nsuch that\n$$\\tau_M\\oplus\\xi = (n+k)\\epsilon.$$\nApply the total Steifel-Whitney class, we have\n$$w(\\tau)w(\\xi) = 1,$$\nsince there's no higher Steifel-Whitney class of a trivial bundle. In\nparticular,\n$$\nw(\\xi) = w(\\tau)^{-1}.\n$$\n\\begin{example}\n    Let $M = \\RP^n\\looparrowright \\RR^{n+k}$. Then, we know that\n    $$\\tau_{\\RP^n}\\oplus\\epsilon\\simeq (n+1)\\lambda^\\ast \\simeq (n+1)\\lambda,$$\n    where $\\lambda\\downarrow \\RP^n$ is the canonical line bundle. By Remark\n    \\ref{sw-stability}, we have\n    $$w(\\tau_{\\RP^n}) = w(\\tau_{\\RP^n}\\oplus\\eta) = w((n+1)\\lambda) =\n    w(\\lambda)^{n+1}.$$\n    It remains to compute $w(\\lambda)$. Only the first Steifel-Whitney class is\n    nonzero. Writing $H^\\ast(\\RP^n) = \\FF_2[x]/x^{n+1}$, we therefore have\n    $w(\\lambda) = x$. In particular,\n    $$w(\\tau_{\\RP^n}) = (1+x)^{n+1} = \\sum^n_{i=0}\\binom{n+1}{i}x^i.$$\n    It follows that\n    $$w_i(\\tau_{\\RP^n}) = \\binom{n+1}{i}x^i.$$\n    The total Steifel-Whitney class of the complement of the tangent bundle is:\n    $$w(\\xi) = (1+x)^{-n-1}.$$\n    The most interesting case is when $n$ is a power of $2$, i.e., $n=2^s$ for\n    some integer $s$. In this case, since taking powers of $2$ is linear in\n    characteristic $2$, we have\n    $$w(\\xi) = (1+x)^{-1-2^s} = (1+x)^{-1}(1+x)^{-2^s} =\n    (1+x)^{-1}(1+x^{2^s})^{-1}.\n    %= (1+x+x^2+\\cdots)(1+x^{2^s}+\\cdots)\n    $$\n    As all terms of degree greater than $2^s$ are zero, we conclude that\n    So\n    $$w(\\xi) = 1+x+x^2+\\cdots+x^{2^s-1}+2x^s = 1+x+x^2+\\cdots+x^{2^s-1}.$$\n    As $x^{2^s-1}\\neq 0$, this means that $k = \\dim\\xi \\geq 2^s-1$. We\n    conclude:\n    \\begin{theorem}\n\tThere is no immersion $\\RP^{2^s}\\looparrowright \\RR^{2\\cdot 2^{s}-2}$.\n    \\end{theorem}\n    The following result applied to $\\RP^{2^s}$ shows that the above result is\n    sharp:\n    \\begin{theorem}[Whitney]\n\tAny smooth compact closed manifold $M^n \\looparrowright \\RR^{2n-1}$.\n    \\end{theorem}\n    However, Whitney's result is \\emph{not} sharp for a general smooth compact\n    closed manifold. Rather, we have:\n    \\begin{theorem}[Brown--Peterson, Cohen]\n\tA closed compact smooth $n$-manifold $M^n \\looparrowright\n\t\\RR^{2n-\\alpha(n)}$, where $\\alpha(n)$ is the number of $1$s in the\n\tdyadic expansion of $n$.\n    \\end{theorem}\n    This result is sharp, since if $n=\\sum 2^{d_i}$ for the dyadic expansion,\n    then $M = \\prod_i \\RP^{2^{d_i}} \\not \\looparrowright \\RR^{2n-\\alpha(n)-1}$.\n\\end{example}\n%There was a period of time in the late '60s, etc. when a lot of effort was put\n%in to stronger and stronger immersion results.\n\\subsection{Cobordism, characteristic numbers}\nIf we have a smooth closed compact $n$-manifold, then it embeds in $\\RR^{n+k}$\nfor some $k\\gg 0$. The normal bundle then satisfies\n$$\\tau_M\\oplus \\nu_M = (n+k)\\epsilon.$$\nA piece of differential topology tells us that if $k$ is large, then\n$\\nu_M\\oplus N\\epsilon$ is independent of the bundle for some $N$.\n\nThis example, combined with Remark \\ref{stability}, shows that $w(\\nu_M)$ is\nindependent of $k$. We are therefore motivated to think of Stiefel-Whitney\nclasses as coming from $H^\\ast(BO;\\FF_2) = \\FF_2[w_1,w_2,\\cdots]$, where $BO =\n\\varinjlim BO(n)$. Similarly, Chern classes should be thought of as coming from\n$H^\\ast(BU;\\Z) = \\Z[c_1,c_2,\\cdots]$. This exa\n\\begin{definition}\n    The characteristic number of a smooth closed compact $n$-manifold\n    $M$ is defined to be $\\langle w(\\nu_M),[M]\\rangle$.\n\\end{definition}\nNote that the fundamental class $[M]$ exists, since our coefficients are in\n$\\FF_2$, where everything is orientable.\n\nThis definition is very useful when thinking about cobordisms. \n\\begin{definition}\\label{cobordism}\n    Two (smooth closed compact) $n$-manifolds $M, N$ are \\emph{(co)bordant} if\n    there is an $(n+1)$-dimensional manifold $W^{n+1}$ with boundary such that\n    $$\\partial W\\simeq M\\sqcup N.$$\n\\end{definition}\nFor instance, when $n=0$, the manifold $\\ast\\sqcup \\ast$ is \\emph{not}\ncobordant to $\\ast$, but it is cobordant to the empty set. However,\n$\\ast\\sqcup\\ast\\sqcup\\ast$ is cobordant to $\\ast$. Any manifold is cobordant\nto itself, since $\\partial(M\\times I) = M\\sqcup M$. In fact, cobordism forms\nan equivalence relation on manifolds.\n\n\\begin{example}\n    A classic example of a cobordism is the ``pair of pants''; this is the\n    following cobordism between $S^1$ and $S^1\\sqcup S^1$:\n    \\todo{add image}\n\\end{example}\n\nLet us define\n$$\n\\Omega^O_n = \\{\\text{cobordism classes of $n$-manifolds}\\}.\n$$\nThis forms a group: the addition is given by disjoint union. Note that every\nelement is its own inverse. Moreover, $\\bigoplus_n \\Omega^O_n = \\Omega^O_\\ast$\nforms a graded ring, where the product is given by the Cartesian product of\nmanifolds. Our discussion following Definition \\ref{cobordism} shows that\n$\\Omega^O_0 = \\FF_2$.\n\\begin{exercise}\\label{nullbordant}\n    Every $1$-manifold is nullbordant, i.e., cobordant to the point.\n\\end{exercise}\nThom made the following observation. Suppose an $n$-manifold $M$ is embedded\ninto Euclidean space, and that $M$ is nullbordant via some $(n+1)$-manifold\n$W$, so that $\\nu_W|_{M} = \\nu_M$. In particular,\n$$\\langle w(\\nu_M),[M]\\rangle = \\langle w(\\nu_W)|_{M},[M]\\rangle.$$\nOn the other hand, the boundary map $H_{n+1}(W,M) \\xar{\\partial} H_n(M)$ sends\nthe relative fundamental class $[W,M]$ to $[M]$. Thus\n$$\\langle w(\\nu_M),[M]\\rangle = \\langle w(\\nu_M),\\partial[W,M]\\rangle = \\langle\n\\delta w(\\nu_M),[W,M]\\rangle.$$\nHowever, we have an exact sequence\n$$H^n(W)\\xar{i^\\ast} H^n(M) \\xar{\\delta} H^{n+1}(W,M).$$\nSince $w(\\nu_M)$ is in the image of $i^\\ast$, it follows that $\\delta w(\\nu_M)\n= 0$. In particular, the characteristic number of a nullbordant manifold is\nzero. Thus, we find that ``Stiefel-Whitney numbers tell all'':\n\\begin{prop}\n    Characteristic numbers are cobordism invariants. In other words,\n    characteristic numbers give a map\n    $$\\Omega^O_n \\to \\Hom(H^n(BO),\\FF_2)\\simeq H_n(BO).$$\n\\end{prop}\nMore is true:\n\\begin{theorem}[Thom, 1954]\\label{thom-sw}\n    The map of graded rings $\\Omega^O_\\ast\\to H_\\ast(BO)$ defined by the\n    characteristic number is an inclusion. Concretely, if $w(M^n) = w(N^n)$ for\n    all $w\\in H^n(BO)$, then $M^n$ and $N^n$ are cobordant.\n\\end{theorem}\nThe way that Thom proved this was by expressing $\\Omega^O_\\ast$ is the graded\nhomotopy ring of some space, which he showed is the product of mod $2$\nEilenberg-MacLane spaces. Along the way, he also showed that:\n$$\n\\Omega^O_\\ast = \\FF_2[x_i:i\\neq 2^s-1] = \\FF_2[x_2,x_4,x_5,x_6,x_8,\\cdots]\n$$\nThis recovers the result of Exercise \\ref{nullbordant} (and so much more!).\n", "meta": {"hexsha": "1106befc2c52cab4349aa60aa1b8e6d1ea9abff9", "size": 9816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-73-steifel-whitney-classes.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-73-steifel-whitney-classes.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-73-steifel-whitney-classes.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": 46.5213270142, "max_line_length": 105, "alphanum_fraction": 0.6726772616, "num_tokens": 3390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.6363555787541626}}
{"text": "\\section{Universal Hashing}\r\n\r\n\\def\\E{\\mathbb{E}}\r\n\\toclesssubsection{Introduction}\r\n\r\n\\begin{frame}{Universal Hashing}{Thought Experiment}\r\n  \\textbf{Thought Experiment:}\\\\\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      A {\\color{MainA}hash function} is defined for a given\r\n      {\\color{MainA}key set}\r\n    \\item<2->\r\n      Find a {\\color{MainA}set of keys} resulting in a degenerated\r\n      {\\color{MainA}hash table}\r\n      \\begin{itemize}\r\n        \\item<3->\\textit{The {\\color{MainA}hash function} stays fixed}\\\\\r\n        \\item<4->\\textit{For table size of 100: try $100 \\times (99 + 1)$ different numbers}\\\\\r\n       \\item<5->\\textit{Worst case: all 100 {\\color{MainA}key sets} map to\r\n         one bucket}\r\n      \\end{itemize}\r\n    \\item<5->\r\n      \\textbf{Now:} find a solution to avoid that problem\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Idea}\r\n  \\textbf{Solution:} {\\color{MainA}universal hashing}\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      Out of a set of hash functions we randomly choose one\r\n    \\item<2->\r\n      The {\\color{MainA}expected result} of the hash function is an equal\r\n      distribution over the buckets\r\n    \\item<3->\r\n      This hash function stays fixed for the lifetime of table\\\\\r\n      Optional: copy table with new hash when degenerated\r\n  \\end{itemize}\r\n  \\onslide<1->{\r\n  \\vspace{-0.5em}\r\n  \\begin{columns}\r\n    \\begin{column}[T]{0.33\\linewidth}\r\n      \\begin{figure}[!h]\r\n        \\begin{adjustbox}{height=0.8\\linewidth}\r\n          \\input{Images/UniversalHashing/Hash_1_Crossing.tikz}\r\n        \\end{adjustbox}\r\n        \\caption{Hash func. 1}\r\n        \\label{fig:universal_hashing:hash_function_crossing}\r\n      \\end{figure}\r\n    \\end{column}\r\n    \\begin{column}[T]{0.33\\linewidth}\r\n      \\begin{figure}[!h]\r\n        \\begin{adjustbox}{height=0.8\\linewidth}\r\n          \\input{Images/UniversalHashing/Hash_2_Normal.tikz}\r\n        \\end{adjustbox}\r\n        \\caption{Hash func. 2}\r\n        \\label{fig:universal_hashing:hash_function_normal}\r\n      \\end{figure}\r\n    \\end{column}\r\n    \\begin{column}[T]{0.33\\linewidth}\r\n      \\begin{figure}[!h]\r\n        \\begin{adjustbox}{height=0.8\\linewidth}\r\n          \\input{Images/UniversalHashing/Hash_3_Colliding.tikz}\r\n        \\end{adjustbox}\r\n        \\caption{Hash func. coll.}\r\n        \\label{fig:universal_hashing:hash_function_colliding}\r\n      \\end{figure}\r\n    \\end{column}\r\n  \\end{columns}}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Definition}\r\n  \\textbf{Definition:}\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      We call {\\color{MainA}$\\mathbb{U}$} the set (universe) of\r\n      possible keys\r\n    \\item<2->\r\n      The size {\\color{MainA}$m$} of the hash table {\\color{MainA}$T$}\r\n    \\item<3->\r\n      Set of hash functions\r\n      {\\color{MainA}$\\mathbb{H} = \\{h_1, h_2,\\dots, h_n\\}$} with\r\n      {\\color{MainA}$h_i: \\mathbb{U} \\to \\{0,\\dots, m - 1\\}$}\r\n    \\item<5-> Idea: runtime should be\r\n      $\\color{MainA} O(1+\\frac{\\vert \\mathbb{S}\\vert}{m})$,\r\n      \\rlap{where $\\color{MainA}\\frac{\\vert \\mathbb{S} \\vert}{m}$ is the\r\n      table load}\r\n  \\end{itemize}%\\vspace*{-2em}\r\n  \\begin{figure}[!b]%\r\n    \\begin{adjustbox}{height=0.32\\linewidth}%\r\n      \\input{Images/UniversalHashing/HashFunction.tikz}%\r\n    \\end{adjustbox}\r\n    \\vspace*{-1.0em}%\r\n    \\onslide<3->\\caption{Hash function $h_1$}%\r\n    \\label{fig:universal_hashing:hash_function_definition}\r\n  \\end{figure}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Definition}\r\n  \\begin{columns}\r\n    \\begin{column}{0.5\\linewidth}\r\n      \\begin{itemize}\r\n        \\item<1->\r\n          We choose two random keys\r\n          {\\color{MainA}$x, y \\in \\mathbb{U} \\mid x \\neq y$}\r\n        \\item<2->\r\n          An average of 3 out of 15 functions produce collisions\r\n      \\end{itemize}\r\n    \\end{column}\r\n    \\begin{column}{0.5\\linewidth}\r\n      \\begin{figure}[!t]%\r\n        \\begin{adjustbox}{width=\\linewidth}\r\n          \\input{Images/UniversalHashing/HashUniverse.tikz}%\r\n        \\end{adjustbox}\r\n        \\caption{Set of hash functions $\\mathbb{H}$}%\r\n        \\label{fig:universal_hashing:hash_universe}\r\n      \\end{figure}\r\n    \\end{column}\r\n  \\end{columns}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Definition}\r\n  \\textbf{Definition:}\r\n  {\\color{MainA}$\\mathbb{H}$} is {\\color{MainA}$c$-universal} if\r\n  {\\color{MainA}$\\forall x, y \\in \\mathbb{U} \\mid x \\neq y:$\r\n  \\begin{displaymath}\r\n    \\overbrace{\r\n      \\frac{\r\n        \\vert \\{h \\in \\mathbb{H}\\!: h(x) = h(y)\\} \\vert\r\n      }{\r\n      \\underbrace{\\vert \\mathbb{H} \\vert}_\\text{{\\color{black}Number of hash functions}}\r\n      }\r\n    }^\\text{\r\n      {\\color{black}Number of hash functions that create collisions}\r\n    }\r\n    \\leq c \\cdot \\frac{1}{m}, \\hspace*{1.5em} c \\in \\mathbb{R}\r\n  \\end{displaymath}}\r\n  \\vspace{-1em}\r\n  \\begin{itemize}\r\n  \\item<2->\r\n      In other words, given an arbitrary but fixed pair\r\n      {\\color{MainA}$x, y$}.\\\\\r\n      If {\\color{MainA}$h \\in \\mathbb{H}$} is chosen randomly then\\\\\r\n      \\onslide<3->{\r\n        \\begin{center}\r\n          \\color{MainA}\r\n          $Prob ( h(x) = h(y) ) \\leq c \\cdot \\frac{1}{m}$\r\n        \\end{center}\r\n      }\r\n  \\end{itemize}\r\n  \\onslide <4->\r\n  \\begin{block}{Note: If the hash function assigns each key $x$ and $y$\r\n      randomly to buckets then:}\r\n    {\\onslide<5->$Prob( Collision ) = \\frac{1}{m} \\Leftrightarrow c = 1$}\r\n  \\end{block}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Definition}\r\n  \\begin{columns}\r\n    \\begin{column}{0.5\\linewidth}\r\n      \\begin{itemize}\r\n        \\item\r\n          {\\color{MainA}$\\mathbb{U}$}:\r\n          key universe\r\n        \\item\r\n          {\\color{MainA}$\\mathbb{S}$}:\r\n          used Keys\r\n        \\item\r\n          {\\color{MainA}$\\mathbb{S}_i \\subseteq \\mathbb{S}$}:\r\n          keys mapping to Bucket {\\color{MainA}$i$} (\\enquote{synonyms})\r\n       \\item\r\n         Ideal would be\r\n         {\\color{MainA}$\\vert \\mathbb{S}_i \\vert =\\dfrac{\\vert \\mathbb{S} \\vert}{m}$}\r\n      \\end{itemize}\r\n    \\end{column}\r\n    \\begin{column}{0.5\\linewidth}\r\n      \\begin{figure}[!h]%\r\n        \\begin{adjustbox}{width=\\linewidth}%\r\n          \\input{Images/UniversalHashing/HashFunctionToBucket.tikz}%\r\n        \\end{adjustbox}\r\n        \\caption{Hash function {\\color{MainA}$h \\in \\mathbb{H}$}}%\r\n        \\label{fig:universal_hashing:hash_function_to_bucket}\r\n      \\end{figure}\r\n    \\end{column}\r\n  \\end{columns}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Universal Hashing}{Definition}\r\n  \\begin{itemize}\r\n    \\item<1->\r\n      Let {\\color{MainA}$\\mathbb{H}$} be a {\\color{MainA}$c$}-universal class of hash functions\r\n    \\item<2->\r\n      Let {\\color{MainA}$\\mathbb{S}$} be a set of keys and {\\color{MainA}$h \\in \\mathbb{H}$} selected randomly\r\n    \\item<3->\r\n      Let {\\color{MainA}$\\mathbb{S}_i$} be the key {\\color{MainA}$x$} for which {\\color{MainA}$h(x) = i$}\r\n    \\item<4->\r\n      The expected average number of elements to search through per \r\n      bucket is {\\color{MainA}\\[\\E{}\\left[\\vert \\mathbb{S}_i \\vert\\right]\r\n        \\leq 1 + c \\cdot \\frac{\\vert \\mathbb{S} \\vert}{m}\\]}\r\n    \\item<5->\r\n      Particulary: if  {\\color{MainA}($m = \\Omega(\\vert \\mathbb{S} \\vert)$)} then\r\n      {\\color{MainA}$\\E{}\\left[\\vert \\mathbb{S}_i \\vert\\right] = \\mathcal{O}(n)$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n", "meta": {"hexsha": "cd2d83b4af154dcd9e301606002d8f86db304ea0", "size": 7697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-5/Chapter/eng/030_UniversalHashing.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/030_UniversalHashing.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/030_UniversalHashing.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.6342592593, "max_line_length": 111, "alphanum_fraction": 0.5530726257, "num_tokens": 2387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619134371954, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6363555714294206}}
{"text": "\\section{Differential Geometry of Space Curves}\r\n\\subsection{Parameterized Curve by Arc Length}\r\n\\begin{definition}\r\n    A parameterized curve $C$ is the image of a continuous map $[a,b]\\to \\mathbb R^3$ sending $t\\mapsto \\underline{x}(t)$.\r\n    We say $C$ is a differentiable parameterized curve if each component $x_i(t)$ is differentiable.\r\n    We say $C$ is regular if $\\underline{x}^\\prime(t)\\neq\\underline{0}$ for any $t$.\\\\\r\n    A regular and differentiable curve is called smooth.\r\n\\end{definition}\r\nSince it is an applied course (sadly), we will assert that our curve is as differentiable as we like.\\\\\r\nTo find the length of this curve, we partition the interval $[a,b]$ by $a=t_0<t_1<t_2<\\cdots <t_{n-1}<t_n=b$.\r\nWe define the length $l(C,P)$ with respect to this partition $P$ to be\r\n$$l(C,P)=\\sum_{i=0}^{n-1}|\\underline{x}(t_{i+1})-\\underline{x}(t_i)|$$\r\nBy some applied-maths-intuition nonsense, we get that if we make the differences $t_{i+1}-t_i$ small enough, we are going to approach the length of the curve $C$, independent of the way we approach the limit.\r\nSo an applied mathematician will then set\r\n\\begin{definition}\r\n    The length $l(C)$ of the curve $C$ is\r\n    $$\\lim_{t_{i+1}-t_i\\to 0}l(C,P)$$\r\n    which, as that applied mathematician will discover joyfully, equals\r\n    $$\\int_{a}^b|\\underline{x}^\\prime(t)|\\,\\mathrm dt$$\r\n    Sometimes we write it as\r\n    $$\\int_C\\mathrm ds$$\r\n\\end{definition}\r\nAgain by intuition we are gonna write $\\mathrm ds=\\sqrt{\\sum_i\\dot{x}_i^2}\\mathrm dt=\\sqrt{\\sum_i\\mathrm dx_i^2}$.\r\n\\begin{definition}\r\n    We define\r\n    $$\\int_Cf\\,\\mathrm ds=\\int_a^bf(\\underline{x}(t))|\\underline{\\dot{x}}(t)|\\,\\mathrm dt$$\r\n    for smooth curve $C$.\r\n    And for piecewise smooth curve $C=C_1\\cup C_2\\cup\\cdots\\cup C_n$, we set\r\n    $$\\int_Cf\\,\\mathrm ds=\\sum_{i=1}^n\\int_{C_i}f\\,\\mathrm ds$$\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Let $C$ be a circle of radius $r>0$, so we can parameterize it by $(r\\cos t,r\\sin t,0), t\\in [0,2\\pi]$, and we unsurprisingly find that its length is $2\\pi r$.\\\\\r\n    2. Take $C$ be the same circle as in 1, we have\r\n    $$\\int_C x^2y\\,\\mathrm ds=\\int_a^b (r\\cos t)^2(r\\sin t) r\\,\\mathrm dt=0$$\r\n\\end{example}\r\n\\begin{proposition}\r\n    The way we define curve integrals is independent of parameterization.\r\n\\end{proposition}\r\n\\begin{example}\r\n    If we parameterize the circle as $(r\\cos(2t),r\\sin(2t),0),t\\in [0,\\pi]$, we still get the same thing.\r\n\\end{example}\r\n\\begin{proof}\r\n    Let $\\underline{s_1}(t),\\underline{s_2}(\\tau),t\\in[a,b],\\tau\\in[\\alpha,\\beta]$ be two different parameterizations of $C$, then there exists a function $\\tau\\to t(\\tau)$ such that $\\underline{s_1}(t(\\tau))=\\underline{s_2}(\\tau)$.\r\n    Assume that $\\mathrm dt/\\mathrm d\\tau$ is nonzero and $t(\\tau)$ is a differentiable, invertible, and have differentiable inverse, then we have\r\n    $$\\underline{s_2}^\\prime(\\tau)=\\frac{\\mathrm d\\underline{s_1}\\circ t}{\\mathrm d\\tau}=\\underline{s_1}^\\prime(t)t^\\prime(\\tau)$$\r\n    If $\\mathrm dt/\\mathrm d\\tau>0$, we have\r\n    $$\\int_\\alpha^\\beta|\\underline{s_2}^\\prime(\\tau)|\\,\\mathrm d\\tau=\\int_\\alpha^\\beta|\\underline{s_1}^\\prime(t(\\tau))|t^\\prime(\\tau)\\,\\mathrm d\\tau=\\int_a^b|\\underline{s_1}^\\prime(t)|\\,\\mathrm dt$$\r\n    Similar for other cases.\r\n\\end{proof}\r\nWe now know the arc length is\r\n$$s(t)=\\int_{t_0}^t|\\underline{\\dot{x}}(u)|\\,\\mathrm du$$\r\nOn a regular curve, $\\mathrm ds/\\mathrm dt=|\\underline{\\dot{r}}(t)|>0$, this tells us that we can indeed parameterize each regular curve wrt arc length.\r\nThis is done by observing $\\mathrm dt/\\mathrm ds=1/|\\underline{\\dot{r}}(t)|$ which means we can write $\\underline{r}(s)=\\underline{r}(t(s))$, where we have\r\n$$\\frac{\\mathrm d\\underline{r}}{\\mathrm ds}=\\frac{\\underline{\\dot{r}}(t)}{|\\underline{\\dot{r}}(t)|}$$\r\nwhich is a unit vector.\r\nTherefore,\r\n\\begin{lemma}\r\n    Any smooth curve $C$ has a parameterization $\\underline{r}(s)$ such that\r\n    $$\\left|\\frac{\\mathrm dr}{\\mathrm ds}\\right|\\equiv 1$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Followed from above.\r\n\\end{proof}\r\n\\subsection{Curvature and Torsion}\r\nThroughout this section, we are only interested in smooth curves $C$ parameterized by arc length $\\underline{r}(s)$.\r\n\\begin{definition}\r\n    The tangent vector is defined as $\\underline{t}(s)=\\underline{r}^\\prime(s)$.\r\n\\end{definition}\r\nNote that $\\underline{t}$ is always unit as it is an arc length parameterization.\r\n\\begin{definition}\r\n    The curvature of $\\underline{r}(s)$ is defined as $\\kappa(s)=|\\underline{t}^\\prime(s)|=|\\underline{r}^{\\prime\\prime}(s)|$.\r\n\\end{definition}\r\nNote that if we differentiate $\\underline{t}\\cdot\\underline{t}=1$, then we have $\\underline{t}\\cdot\\underline{t}^\\prime=0$.\r\nThis shows that the unit vector in the direction $t^\\prime$ has a geometric interpretation as the normal to a curve, so we define\r\n\\begin{definition}\r\n    The principal normal $\\underline{n}$ is the (unit) vector such that $\\underline{t}^\\prime=\\kappa\\underline{n}$.\r\n\\end{definition}\r\nNaturally, when we already have a pair of orthonormal vectors in $\\mathbb R^3$, adding a third one seems to be the next step to do.\r\n\\begin{definition}\r\n    In $\\mathbb R^3$, the binormal $\\underline{b}$ is defined as $\\underline{b}=\\underline{t}\\times\\underline{n}$.\r\n\\end{definition}\r\nThen the vectors $\\underline{t},\\underline{n},\\underline{b}$ form an orthonormal basis for $\\mathbb R^3$.\r\nAgain we have $\\underline{b}\\cdot\\underline{b}^\\prime=0$ as $\\underline{b}$ is unit.\r\nBut we also have $\\underline{t}\\cdot\\underline{b}=0$, we get $\\underline{t}\\cdot\\underline{b}^\\prime=0$.\r\nHence $\\underline{n},\\underline{b}^\\prime$ are parallel.\r\n\\begin{definition}\r\n    The torsion $\\tau$ is defined as such that $\\underline{b}^\\prime=-\\tau\\underline{n}$.\r\n\\end{definition}\r\nSo we have got there\r\n$$\\begin{cases}\r\n    \\underline{t}^\\prime=\\kappa\\underline{n}=\\kappa(\\underline{b}\\times\\underline{t})\\\\\r\n    \\underline{b}^\\prime=-\\tau\\underline{n}=\\tau(\\underline{t}\\times\\underline{b})\r\n\\end{cases}$$\r\nIntuitively and truthfully\r\n\\begin{proposition}\r\n    The curvature and torsion uniquely defines a curve up to rigid motion.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Picard-Lindel\\\"of Theorem.\r\n\\end{proof}\r\nThe Taylor expansion of $\\underline{r}(t)$ around $0$ shows\r\n$$\\underline{r}(s)=\\underline{r}(0)+s\\underline{t}(0)+\\frac{1}{2}s^2\\kappa\\underline{n}(0)+o(s^2)$$\r\nNow we turn to consider the circle of best fit around $\\underline{r_0}$.\r\nParameterize the circle (with radiu $r$) by and expand to see that the second order term is somewhat like $s^2\\underline{n}/(2r)$, so it is natural to define\r\n\\begin{definition}\r\n    The radius of curvature is defined as $r=1/\\kappa$.\r\n\\end{definition}", "meta": {"hexsha": "d24533db21a7188f3fde99ba9eb26c7d46069813", "size": 6651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/curves.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": "1/curves.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": "1/curves.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": 62.1588785047, "max_line_length": 233, "alphanum_fraction": 0.685460833, "num_tokens": 2109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.6363456847764882}}
{"text": "\\problemname{Limbo: Part 2}\n\n\\noindent Dominick Cobb and Arthur are ``extractors\" who perform corporate espionage. Using experimental military technology that gives them access to shared dream worlds, they infiltrate their targets' subconscious to extract valuable information. Cobb and his entourage are contacted by a mysterious Japanese syndicate and given a seemingly impossible task: instead of extracting information, do the opposite -- plant a new idea in the target's mind.\\\\\n\nCobb just figured out how to calculate the slowness of time in each dream level, but he is still missing a vital piece of the plan -- the architecture. For this challenging mission he has hired the brilliant young architect Ariadne to design a dream space, complete with all the aesthetic and tactile details. Cobb's target will be brought into that dream space, where they will fill it with details from their own subconscious and memories.\\\\\n\nAs extractors go into deeper dream levels, the perception of time slows down. This means subjects will be able to explore exponentially more space. Since dreams can go infinitely deep (onwards to Limbo), the architecture of a dream should be infinite in area. The master layout is denoted by a two-dimensional grid that starts at row $0$, column $0$, and extends infinitely downwards and to the right. Ariadne cannot simply draw a map of this space (since it is infinite), so she must come up with a program that \"generates\" the dream space to extend as large as the team needs to go deeper. She has an infinite number of building blocks, numbered $0, 1, 2, 3, 4, \\dots$, which must be used in that order.\\\\\n\nIn dream level $0$ (reality), the dream space consists of the single block $0$. With each deeper dream level, the area of the space doubles. To prevent the dream space from implosion due to growing too narrowly in a single direction, Ariadne has designed the space to double in \\textit{alternating directions}, with new blocks filling in the space sequentially based on the direction of doubling. For example, the first few levels of the dream map are depicted as follows:\\\\\n\n\\begin{center}\n\\begin{minipage}{8cm}\n\\begin{verbatim}\n    0          0 1         0 1       0 1 4 6\n                           2 3       2 3 5 7\n\n(Reality)   (Level 1)   (Level 2)   (Level 3)\n\n\n   0  1  4  6         0  1  4  6 16 20 24 28\n   2  3  5  7         2  3  5  7 17 21 25 29\n   8  9 10 11         8  9 10 11 18 22 26 30\n  12 13 14 15        12 13 14 15 19 23 27 31\n\n   (Level 4)                (Level 5)\n\n\\end{verbatim}\n\\end{minipage}\n\\end{center}\n\nAriadne's program must be able to generate any part of the map at will. Given only the row and column coordinates for a particular location in the dream space, can you determine the number of the building block that will be used?\n\n\\section*{Input}\nThe first line of input consists of a single integer $T$ ($1 \\leq T \\leq 100$), the number of test cases.\\\\\n$T$ lines follow, each of which is a test case consisting of two space-separated integers, $R$ and $C$ ($0 \\leq R, C \\leq 10^{9}$), specifying a particular row and column in the dream-space.\\\\\n\n\\section*{Output}\nFor each test case, print, on a separate line, the number of the building block at coordinates $(R, C)$.\\\\\nNote: the answer can be large, and may not necessarily fit in a 32-bit integer.\\\\\n", "meta": {"hexsha": "a48ae9ffecb4c721a21e2e1dc2c4a6e00081968a", "size": 3329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "limbo2/problem_statement/problem.en.tex", "max_stars_repo_name": "csecutsc/utscode2", "max_stars_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-30T15:06:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T06:50:25.000Z", "max_issues_repo_path": "limbo2/problem_statement/problem.en.tex", "max_issues_repo_name": "csecutsc/utscode2", "max_issues_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "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": "limbo2/problem_statement/problem.en.tex", "max_forks_repo_name": "csecutsc/utscode2", "max_forks_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T04:10:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T04:10:51.000Z", "avg_line_length": 83.225, "max_line_length": 707, "alphanum_fraction": 0.7308501051, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145997, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6363456802174213}}
{"text": "%% This file is part of the CroMagnon project\n%% Copyright 2015 David W. Hogg\n\n\\documentclass[12pt]{article}\n\\usepackage{url}\n\\input{vc}\n\n\\newcommand{\\like}{L}\n\\newcommand{\\dd}{\\mathrm{d}}\n\\newcommand{\\inverse}{^{-1}}\n\\newcommand{\\transpose}{^{\\mathsf{T}}}\n\n\\begin{document}\n\n\\section*{Notes on log-sum-exp%\n\\footnote{\\raggedright This document is available (in source-code form) at \\giturl.\nThis precise version has git hash \\texttt{\\githash~(\\gitdate)}.}}\n\\noindent\nDavid W. Hogg (NYU) (SCDA) (MPIA)\n\n\\bigskip\n\nGenerically in probabilistic inference problems we encounter quantities like\n\\begin{eqnarray}\n  Q\n  &=& \\ln\\sum_{k=1}^K\\exp q_k\n  \\quad,\n\\end{eqnarray}\nwhere the $q_k$ are simple functions (for example, they might have simple\nderivatives with respect to parameters $\\theta$).\nLet's take the full derivative of $Q$:\n\\begin{eqnarray}\n  \\frac{\\dd Q}{\\dd\\theta}\n  &=& \\left[\\sum_{k=1}^K\\exp q_k\\right]\\inverse\n      \\,\\frac{\\dd}{\\dd\\theta}\\left[\\sum_{k=1}^K\\exp q_k\\right] \\\\\n  &=& \\left[\\sum_{k=1}^K\\exp q_k\\right]\\inverse\n      \\,\\left[\\sum_{k=1}^K\\frac{\\dd q_k}{\\dd\\theta}\\exp q_k\\right]\n  \\quad;\n\\end{eqnarray}\nthat is, the derivative of $Q$ is just the $\\exp q_k$-weighted average\nof derivatives of the $q_k$.\nThat's good!\n\nIn the particular case of cryo-EM, the objective function is related\nto a marginalized likelihood $\\like$ which looks like\n\\begin{eqnarray}\n  Q\n  &=&\n  \\sum_{n=1}^N Q_n \\\\\n  Q_n\n  &=& -2\\,\\ln\\like_n \\\\\n  &=& -2\\,\\ln\\sum_{k=1}^K P_k\\,\\exp(\\ln\\like_{nk}) \\\\\n  &=& -2\\,\\ln\\sum_{k=1}^K P_k\\,\\exp(-\\frac{1}{2}\\,\\chi^2_{nk}) \\\\\n  \\chi^2_{nk}\n  &=& [y_n - \\mu_{nk}]\\transpose\\cdot C_n\\inverse\\cdot [y_n - \\mu_{nk}]\n  \\quad,\n\\end{eqnarray}\nwhere the sum is over $k$ samples or grid locations in angles and\noffets, the $P_k$ are weights for those samples (typically roughly\n$1/K$), $y_n$ is the $n$th data point (tiny image), the $\\mu_{nk}$ are\nthe predictions for data point $n$ at angles and offsets $k$, and\n$C_n$ is a covariance matrix for the (Gaussian) noise model.\nThe predictions $\\mu_{nk}$ depend on the three-dimensional shape\nparameters or representation $\\theta$.\n\nTaking derivatives with respect to parameters,\n\\begin{eqnarray}\n  \\frac{\\dd Q}{\\dd\\theta}\n  &=&\n  \\sum_{n=1}^N \\frac{\\dd Q_n}{\\dd\\theta} \\\\\n  \\frac{\\dd Q_n}{\\dd\\theta}\n  &=& -2\\,\\left[\\sum_{k=1}^K P_k\\,\\exp(-\\frac{1}{2}\\,\\chi^2_{nk})\\right]\\inverse\n        \\,\\left[\\sum_{k=1}^K -\\frac{1}{2}\\,P_k\\,\\exp(-\\frac{1}{2}\\,\\chi^2_{nk})\\,\\frac{\\dd\\chi^2_{nk}}{\\dd\\theta}\\right] \\\\\n  \\frac{\\dd\\chi^2_{nk}}{\\dd\\theta}\n  &=& -2\\,[y_n - \\mu_{nk}]\\transpose\\cdot C_n\\inverse\\cdot\\frac{\\dd\\mu_{nk}}{\\dd\\theta}\n  \\quad.\n\\end{eqnarray}\n\nThere is a literature on using the expectation-maximization (E-M)\nalgorithm to optimize marginalized likelihoods that have the logsumexp\nform.\nA good pedagogical (but not original) reference is Bishop (2006; ch\n9).\nThe E-M algorithm is clever because it optimizes a marginalized\nlikelihood of the form of the $Q$ defined above, without ever\nexplicitly constructing the marginalized likelihood or its\nderivatives.\nAnd the proof is beautiful!\nRumors fly, however, that E-M is not the best optimizer for many\nreal problems (Salakhutdinov 2003a, 2003b), and that if we are willing\nto compute the derivatives, we might get to the local optimum faster,\neven given the extra cost per iteration.\n\n\\begin{trivlist}\\raggedright\n\\item\nBishop,~C., 2006,\n\\textit{Pattern Recognition and Machine Learning},\nSpringer-Verlag, New York\n{\\footnotesize ISBN:978-0-387-31073-2}.\n\\item\nSalakhutdinov,~R., Roweis,~S., \\& Ghahramani,~Z., 2003a,\n``Optimization with EM and Expectation-Conjugate-Gradient'',\n\\textit{Proc.~20~ICML},\n{\\footnotesize \\url{http://www.cs.nyu.edu/~roweis/papers/emecgicml03.pdf}}.\n\\item\nSalakhutdinov,~R., Roweis,~S., \\& Ghahramani,~Z., 2003b,\n``On the Convergence of Bound Optimization Algorithms'',\n\\textit{Proc.~19~UAI (UAI2003)},\n{\\footnotesize \\url{http://arxiv.org/abs/1212.2490}}.\n\\end{trivlist}\n\n\\end{document}\n", "meta": {"hexsha": "dda5f7b3bb508975527eaded5f921c8c0df9f85f", "size": 3948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/logsumexp.tex", "max_stars_repo_name": "davidwhogg/CryoEM", "max_stars_repo_head_hexsha": "4ced7aa2216efeb9cdb657ab4ef47bf7ba0709e4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-18T15:48:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-18T15:48:00.000Z", "max_issues_repo_path": "papers/logsumexp.tex", "max_issues_repo_name": "davidwhogg/CroMagnon", "max_issues_repo_head_hexsha": "4ced7aa2216efeb9cdb657ab4ef47bf7ba0709e4", "max_issues_repo_licenses": ["MIT"], "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/logsumexp.tex", "max_forks_repo_name": "davidwhogg/CroMagnon", "max_forks_repo_head_hexsha": "4ced7aa2216efeb9cdb657ab4ef47bf7ba0709e4", "max_forks_repo_licenses": ["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.9380530973, "max_line_length": 123, "alphanum_fraction": 0.696301925, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6363456725847159}}
{"text": "\\section{Algorithms}\n\n\\subsection{Cristofeledes algorithm}\nObjective: solve TSP with $\\frac{3}{2}$-approximation\n\\begin{enumerate}\n    \\item Construct an MST\n    \\item Extract the odd degree vertices\n    \\item Find a matching, using odd degree vertex from (2)\n    \\item Combine the edges from the tree with those in the matching\n    \\item Form a eularian circuit\n    \\item Short the the traversal path to form a hamiltonian cycle\n\\end{enumerate}\n\n\\subsection{Double-tree algorithm}\n2-approximation\n\\begin{enumerate}\n    \\item Construct MST\n    \\item Give each node a redundant entry (graph can now be traversed like\n            an~\\nameref{eularian} graph)\n    \\item Traverse the nodes from start to finish (DFS), but only retain the first\n        time occurence of a city\n\\end{enumerate}\n\n\\subsection{Dijkstra}\nAssign all nodes distance = $\\infty$\nStart at given node $s$. Assign all neighboring nodes their distance from $s$\nto $n$. Proceed to the lowest cost. Repeat. Whenever a better match is found,\nuse the new path instead. The result is a path from $s$ to $t$, or an MST.\\\n\n\\subsection{K-center}\n2-approximation. A form of clustering.\n\\begin{enumerate}\n    \\item Pick arbitrary $i \\in V$\n    \\item $S \\rightarrow \\left\\{i\\right\\}$\n    \\item pick other node furthest away from k, add to $S$\n    \\item repeat, furthest away from all previous picked nodes.\n\\end{enumerate}\n\n\\subsection{Kruskal's algorithm}\nAlways choose cheapest edge that does not include two pre-discovered nodes.\nReturns MST.\\\n\n\\subsection{Nearest addition}\n2-approximation\n\\begin{enumerate}\n    \\item Find two closest cities\n    \\item Traverse from i to j and back\n    \\item Repeat, consider from each node\n\\end{enumerate}\n\n\\subsection{Prim's algorithm}\nStart at a given node $s$. Choose the cheapest edge. \nNow repeat, just that you consider $s$ and the node you added. Etc.\nNever choose an edge that leads to a pre-discovered vertex.\n\n\\subsection{List scheduling algorithm}\\label{listschedule}\n    Whenever a machine is idle, assign it a job.\n    This algorithm runs $\\leq 2\\times OPT$.\n\n    \\begin{proof}\n        Note that $OPT = \\frac{\\sum{p_{i}}}{m}$\n        We know that the last job, $l$, starts at time $t$. Since we've always\n        assigned jobs whenever we could, that means that all machines have \n        so far been busy. Hence we know:\n        $$\n            t \\leq \\frac{\\sum{p_{j} - p_{l}}}{m} \\leq OPT - \\frac{p_{l}}{m}\n        $$\n        Since $OPT$ is lower bounded as the average work done by each machine.\n\n        We can now bound the maximal finishing time: \n        $$\n            C_{\\max} \\leq t + p_{l} \\leq OPT + p_{l}\\times (1 - \\frac{1}{m}) \n            \\leq (2 - \\frac{1}{m})\\times OPT\n        $$\n    \\end{proof}\n\n    \\subsection{Longest processing time rule}\\label{srpt}\n    As~\\nameref{listschedule}, just that you first sort the jobs in order of \n    length; put the longest jobs first. This algorithm has approximation ratio\n    $\\frac{4}{3} \\times OPT$\n\n    \\subsection{Shortest remaining time, SRFT}\\label{sprt}\n    In this scheduling algorithm, the process with the smallest amount of time\n    remaining until completion is selected to execute.\n    This algorithm is applied to~\\nameref{pre-emptive} schedules\n\n\\subsection{Knapsack DP}\n    Fill out two arrays of $n \\times B$, where $B$ is the capacity of \n    the knapsack. In row $i$, consider item $b_{i}$ against the capacity given\n    in column $j$. If $j \\geq w_{i}$, compare the value of $A_{i,j}$ to \n    $A_{i-1,j}$ and use whichever is greater. For all cases where $b_{i} \\geq\n    j$, consider which is better: to use $b_{i} + A_{i-1,j-w_{i}}$,\n    or retain the value above. The last equation is: to use current item + \n    whatever we can fit in on the remaining weight, given by the line above.\n    Make sure to simeoltaneously maintain a ``keep-array'' that gives 1 or zero,\n    indicating whether or not you've used item $b_{i}$.\n\n    In backtracking, start in the lower right of the keep array.\n    Whenever you get a 1, include item $i$ and decrement $i$ and $j$ by one.\n    Whenever you get a zero, decrement $i$ alone.\n\n    The above mentioned runs in $O(n\\times W)$, where $W$ is the capasity of \n    the knapsack. The algorithm is \\textit{exact}, but pseudopolynomial, since\n    $W = \\sum{w_{i}}$, which in binary becomes $\\log_{2} W$, which hence \n    becomes $O(\\log_{2}W^{n})$. An~\\nameref{FPTAS} exists, see book.\n", "meta": {"hexsha": "cf27fe45644ab0462f1f4c088562bf408f9621a7", "size": 4404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/methods/algorithms.tex", "max_stars_repo_name": "andsild/NotusVitae", "max_stars_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": "src/methods/algorithms.tex", "max_issues_repo_name": "andsild/NotusVitae", "max_issues_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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/methods/algorithms.tex", "max_forks_repo_name": "andsild/NotusVitae", "max_forks_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": 41.5471698113, "max_line_length": 82, "alphanum_fraction": 0.687102634, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6363456725847159}}
{"text": "\n\\section{Model Description}\n\n\\subsection{Problem Statement}\n\n\\begin{figure}[!htb]\n\t\\centering\n\t\\includegraphics[width=0.49\\textwidth]{./Figures/Disegno1.eps}\n\t\\caption{Spacecraft with depleting mass and definition of frames and variables}\n\t\\label{fig:Spacecraft}\n\\end{figure}\n\nThe following derivation is a shortened version from Reference\\cite{Panicucci:2017fu}. To help define the problem, Figure~\\ref{fig:Spacecraft} is displayed. This problem involves a spacecraft consisting of a hub which is a rigid body and has a center of mass location labeled as point $B_c$. The hub has $M$ number of tanks and $N$ number of thrusters attached to it. The figure only shows one tank and one thruster but the analytical development is general. The $i_{\\text{th}}$ tank has a center of mass location labeled as $F_{c_i}$ and the $j_{\\text{th}}$ thruster is located at $B_j$. The body fixed reference frame $\\mathcal{B}$: $\\{\\bm{\\hat{b}}_1\\,, \\bm{\\hat{b}}_2\\,,\\bm{\\hat{b}}_3 \\}$ with origin $B$ can be oriented in any direction and point $B$ can be located anywhere fixed to the hub. This means that point $B$ and the center of mass location of the spacecraft, $C$, are not necessarily coincident. As a result, the vector $\\bm c$ defines the vector pointing from the body frame origin to the center of mass fo the spacecraft. The inertial reference frame $\\mathcal{N}$: $\\{\\bm{\\hat{n}}_1\\,, \\bm{\\hat{n}}_2\\,,\\bm{\\hat{n}}_3 \\}$ is centered at $N$ and is fixed in inertial space.\n\t\n\tThroughout this paper, vector calculus is used and the notation to define certain quantities needs to be introduced. A position vector, $ \\bm{r}_{C/N}$, is the vector pointing from $N$ to $C$. $\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}$ is the angular velocity of the $\\mathcal{B}$ frame with respect to the $\\mathcal{N}$ frame.\n\t$\\dot{\\bm{r}}$ denotes an inertial time derivate of vector $\\bm{r}$ and  $\\bm{r}'$ defines a time derivate of $\\bm{r}$ with respect to the body frame. Using these definitions, the following describes the Reynolds transport theorem used in this formulation.\n\n\\subsection{Equations of Motion}\n\\subsubsection{Reynolds Transport Theorem and Continuity Equation}\nIn this section the main tool used for the  development of the governing equations is presented and explained. The Reynolds transport theorem provides a basic tool to pass from a Lagrangian formulation, based on the analysis of particles moving in space, to an Eulerian one, which considers a fixed space volume where physical quantities are exchanged through the boundaries.\n\\begin{figure}[!htb]\n\t\\centering\n\t\\includegraphics[width=0.49\\textwidth]{./Figures/DefSyst.eps}\n\t\\caption{Division of the total system in spacecraft and exhausted gas. The control surface $\\mathcal{A}_{\\text{sc}}$ represents the exchanging surface between the two subsystems.}\n\t\\label{fig:DefSyst}\n\\end{figure}\nIn the present document, the Lagrangian system is labeled $\\textit{Body}$, the moving volume of the Eulerian approach is labeled $\\mathcal{V}_{\\text{sc}}$ and its surface $\\mathcal{A}_{\\text{sc}}$ are represented in Figure \\ref{fig:DefSyst}.\n\nBy using this notation, the Reynolds transport theorem affirms:\n\n\\begin{equation}\n\t\\frac{^\\mathcal{D}\\text{d}}{\\text{d}t}\\int_{\\text{Body}} \\rho\\,\\bm{f}\\text{d}\\mathcal{V} = \\frac{^\\mathcal{D} \\text{d}}{\\text{d}\\,t}\\int_{\\mathcal{V}_\\text{sc}} \\rho\\,\\bm{f}\\text{d}\\mathcal{V}  + \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{f} \\left(\\bm{v}_{\\text{rel}}\\cdot \\hat{\\bm{n}}\\right)\\text{d}A\n\\end{equation}\n\\noindent\nwhere $\\bm{f}$ is a general vectorial quantity transported out from the control volume, $\\rho$ is the density of the infinitesimal mass $\\text{d}m$, $\\hat{\\bm{n}}$ the surface normal considered positive if exiting from the control volume, $\\mathcal{D}$ is a generic reference frame and $\\bm{v}_{\\text{rel}}$ is the relative velocity of the particles flowing out from the surface with respect to the control surface itself. This last quantity can be easily defined as $\\bm{v}_{\\text{rel}}(\\bm{x},t) =\\displaystyle\\frac{^\\mathcal{D}\\text{d}}{\\text{d}t}\\bm{r}_{M/B}(\\bm{x},t) - \\bm{v}_{\\text{surf}}(\\bm{x},t)$ where $\\displaystyle\\frac{^\\mathcal{D}\\text{d}}{\\text{d}t}\\bm{r}_{M/B}(\\bm{x},t)$ is the particles' velocity with respect to the $\\mathcal{D}$ frame and $\\bm{v}_{\\text{surf}}(\\bm{x},t)$ is the control surface velocity with respect to the $\\mathcal{D}$ reference frame.\\newline\nMoreover, if the control volume is fixed in the $\\mathcal{D}$ frame and a no deformable control volume is considered, the following relation is proved:\n\n\\begin{equation}\n\t\\frac{^\\mathcal{D}\\text{d}}{\\text{d}\\,t}\\int_{\\text{Body}} \\rho\\,\\bm{f}\\text{d}\\mathcal{V} = \\int_{\\mathcal{V}_\\text{sc}} \\frac{ ^\\mathcal{D}\\partial}{\\partial\\,t}\\left(\\rho\\,\\bm{f}\\right)\\text{d}\\mathcal{V}+ \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{f} \\left(\\frac{^\\mathcal{D}\\text{d}}{\\text{d}t}\\bm{r}_{M/B}\\right)\\cdot \\hat{\\bm{n}}\\,\\text{d}A\n\\end{equation}\n\nAn additional key equation that is used throughout the paper is the continuity equation. First, the continuity equation is gathered:\n\n\\begin{equation}\n\t\\frac{^\\mathcal{B}\\text{d}}{\\text{d}t}\\int_{\\text{Body}} \\rho\\, \\text{d}m = \\frac{^\\mathcal{B}\\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_\\text{sc}} \\rho\\, \\text{d}\\mathcal{V} + \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B} \\cdot \\hat{\\bm{n}}\\,\\text{d}\\mathcal{A}=0\n\\end{equation}\n\\noindent\nThus, by defining $\\dot{m}_\\text{sc} = \\frac{^\\mathcal{B}\\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_\\text{sc}} \\rho\\, \\text{d}\\mathcal{V}$:\n\n\\begin{equation}\\label{eq:cambVar}\n\t\\dot{m}_\\text{sc} = - \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B} \\cdot \\hat{\\bm{n}}\\,\\text{d}\\mathcal{A} \\qquad \\Rightarrow \\qquad \\text{d}\\dot{m} = \\rho\\,\\bm{r}'_{M/B} \\cdot \\hat{\\bm{n}}\\,\\text{d}\\mathcal{A}\n\\end{equation}\nThis definition will be used in the derivation of the EOMs. The translational EOM is developed in the following section.\n\n\\subsubsection{Translational Equation of Motion}\nThe derivation of the translational EOM must begins considering Newton's law for a closed system:\n\n\\begin{equation}\\label{eq:eq3}\n\t\\frac{^{\\mathcal{N}}\\text{d}}{\\text{d}\\,t}\\int_{\\text{Body}}\\dot{\\bm{r}}_{M/N}\\,\t\\text{d}m= \\bm{F}_{\\text{ext}}\n\\end{equation}\nwhere $\\dot{\\bm{r}}_{M/N}$ is the velocity of the particle at the $M$ point expressed with respect to the inertial reference frame and $\\bm{F}_{\\text{ext}}$ is the sum of the external forces experienced by the body.\n\nAs the total mass of the system is constant, the differentiation operator is brought inside the integration: \n\\begin{equation}\\label{eq:eq4}\n\t\\frac{^{\\mathcal{N}}\\text{d}}{\\text{d}\\,t}\\int_{\\text{Body}}\\dot{\\bm{r}}_{M/N}\\,\t\\text{d}m= \\int_{\\text{Body}}\\ddot{\\bm{r}}_{M/N}\\,\\text{d}m\n\\end{equation}\nThe acceleration of the origin of the $\\mathcal{B}$ frame is expressed as:\n\n\\begin{equation}\\label{eq:RcRbacc}\n\t\\ddot{\\bm{r}}_{M/N} = \\ddot{\\bm{r}}_{B/N} + \\ddot{\\bm{r}}_{M/B}\n\\end{equation}\nBy using the kinematic transport theorem, the expression of $\\ddot{\\bm{r}}_{M/B}$ is found:\n\n\\begin{equation}\\label{eq:rMB_ddot}\n\t\\dot{\\bm{r}}_{M/B} = \\bm{r}'_{M/B} + \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\times\\bm{r}_{M/B}\n\\end{equation}\n\\begin{equation}\\label{eq:rMB_dot}\n\t\\ddot{\\bm{r}}_{M/B} = \\bm{r}''_{M/B}+2\\,\\bm{\\omega}_{\\cal{B}/\\cal{N}}\\times\n\t\\bm{r}'_{M/B} + \\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\times \\bm{r}_{M/B} + \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\times\\left(\\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{B/M} \\right)\n\\end{equation}\n\nA Lagrangian formulation of the linear momentum equation is deduced by using Equations \\eqref{eq:eq3}, \\eqref{eq:eq4}, \\eqref{eq:RcRbacc} and \\eqref{eq:rMB_dot}: \n\n\\begin{multline}\\label{eq:eq11}\n\t\\int_{\\text{Body}}\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}m +\\\\+\n\t2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\times\\int_{\\text{Body}}\\bm{r}'_{M/B}\\text{d}m + \\int_{\\text{Body}}\\bm{r}''_{M/B}\\text{d}m = \\bm{F}_{\\text{ext}}\n\\end{multline}\n\nThe system mass is constant, therefore the derivative operator can be applied after the integration. This yields:\n\n\\begin{equation}\t\n\t\\int_{\\text{Body}}\\bm{r}'_{M/B}\\text{d}m = \\frac{^{\\mathcal{B}}\\text{d}}{\\text{d}t}\\int_{\\text{Body}}\\bm{r}_{M/B}\\text{d}m\n\\end{equation}\n\\begin{equation}\n\t\\int_{\\text{Body}}\\bm{r}''_{M/B}\\text{d}m = \\frac{^{\\mathcal{B}}\\text{d}^2}{\\text{d}t^2}\\int_{\\text{Body}}\\bm{r}_{M/B}\\text{d}m\n\\end{equation}\n\nBy using the Reynolds transport theorem, the two previous equations can be expressed in a space fixed volume, shown in Figure \\ref{fig:DefSyst}. Performing this conversion results in the following equations:\n\n\\begin{equation}\n\t\\frac{^{\\mathcal{B}}\\text{d}}{\\text{d}t}\\int_{\\text{Body}}\\bm{r}_{M/B} \\,\\text{d}m = \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B}\\,\\text{d}\\mathcal{V} + \\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}}\\,\\bm{r}_{M/B}\\text{d}A\n\\end{equation}\n\\begin{multline}\n\t\\frac{^{\\mathcal{B}}\\text{d}^2}{\\text{d}t^2}\\int_{\\text{Body}}\\bm{r}_{M/B}\\, \\text{d}m = \\frac{^{\\mathcal{B}} \\text{d}^2}{\\text{d}t^2}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\,\\text{d}\\mathcal{V} +\\\\+ \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t} \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}_{M/B}\\,\\text{d}A + \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}'_{M/B}\\,\\text{d}A\n\\end{multline}\n\\noindent\nwhere $\\bm{v}_{\\text{rel}} = \\bm{r}' _{M/B}$ because point $B$ is fixed with respect to the spacecraft.  Equation \\eqref{eq:eq11} is re-organized by using the previous relations in order to convert it to an Eulerian approach, i.e. based on a volume-based  derivation:\n\n\\begin{multline}\n\t\\int_{\\text{Body}}\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}m +\\\\+\n\t2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\times\\left(\\,\\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B}\\,\\text{d}\\mathcal{V} + \\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}}\\,\\bm{r}_{M/B}\\text{d}A\\right) \\;+ \t \\frac{^{\\mathcal{B}} \\text{d}^2}{\\text{d}t^2}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\,\\text{d}\\mathcal{V} +\\\\+ \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t} \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}_{M/B}\\,\\text{d}A + \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}'_{M/B}\\,\\text{d}A  \n\t= \\bm{F}_{\\text{ext}}\n\\end{multline} \n\nAs explained in previous work, if all of the mass is contained in the control volume at the initial time, then a particular relation results because no mass is outside the control volume at $t=0$ and the dynamic quantities will be transported out during the integration. This relationship is quantified in the following equation:\n\n\\begin{multline}\n\t\\bm{F}_{\\text{ext}} - \\int_{\\text{Body}}\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}m \n\t= \\int_{\\mathcal{V}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{vol}}+\\\\ +\\int_{\\mathcal{A}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{surf}} - \\int_{\\mathcal{V}_{\\text{sc}}}\\rho\\,\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}\\mathcal{V}\n\\end{multline}  \n\\noindent\nwhere the forces are divided into volumetric forces and the forces applied on the spacecraft surface. Rearranging this result, replacing the definition of $\\bm{F}_{\\text{ext}}$, and isolating the forces to the right hand side of the equation yields:\n\\begin{multline}\\label{eq:ComplTranslEOM}\n\t\\int_{\\mathcal{V}_{\\text{sc}}}\\rho\\,\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}\\mathcal{V} +\\\\+\n\t2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\times\\left(\\,\\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B}\\,\\text{d}\\mathcal{V}\\; + \\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}}\\,\\bm{r}_{M/B}\\text{d}A\\right) \\;+ \t \\frac{^{\\mathcal{B}} \\text{d}^2}{\\text{d}t^2}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\,\\text{d}\\mathcal{V} +\\\\+ \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t} \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}_{M/B}\\,\\text{d}A + \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}'_{M/B}\\,\\text{d}A  \n\t= \\int_{\\mathcal{V}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{vol}} +\\int_{\\mathcal{A}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{surf}}\n\\end{multline}\n\nOne goal for this paper is to develop the EOMs of a spacecraft with depleting mass without the necessity of continuing to track the depleted mass once it has left the spacecraft. One aspect of achieving this goal, is to define the center of mass of the spacecraft with respect to point $B$, including the remaining fuel while disregarding the spent fuel. This variable, $\\bm{c} = \\bm{r}_{C/B}$, is defined as:\n\\begin{equation}\\label{eq:def_rCB}\n\t\\bm{c}=\\frac{m_{\\text{hub}}\\,\\bm{r}_{Bc/B} + \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\,\\bm{r}_{Fc_i/B}}{m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}}\n\\end{equation}\nwhere $m_{\\text{hub}}$ is the mass of the hub, $m_{\\text{fuel}_i}$ is the i-th tank's fuel mass and $\\bm{r}_{Fc_i/B}$ is the position of the center of mass of the i-th tank's fuel.\nIn order to infer the influence of the mass variation in the EOMs equation of motion the first and second time derivatives with respect to the body frame of $\\bm c$ is defined:\n\n\\begin{multline}\\label{eq:eq17}\n\t\\bm{c}' = \\frac{\\sum_{i=1}^{M}\\left(\\dot{m}_{\\text{fuel}_i}\\bm{r}_{Fc_i/B} + m_{\\text{fuel}_i}\\bm{r}'_{Fc_i/B}\\right)}{m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}} + \\vspace{5pt}\\\\\n\t- \\frac{\\left(\\sum_{i=1}^{M}\\dot{m}_{\\text{fuel}_i}\\right)\\left(m_{\\text{hub}}\\,\\bm{r}_{Bc/B} + \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\,\\bm{r}_{Fc_i/B}\\right)}{\\left(m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\right)^2}\n\\end{multline}\n\n\\begin{multline}\\label{eq:eq18}\n\t\\bm{c}'' = \\frac{\\sum_{i=1}^{M}\\left(\\ddot{m}_{\\text{fuel}_i}\\bm{r}_{Fc_i/B} +2\\,\\dot{m}_{\\text{fuel}_i}\\bm{r}'_{Fc_i/B}+ m_{\\text{fuel}_i}\\bm{r}''_{Fc_i/B}\\right)}{m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}} + \\vspace{5pt}\\\\\n\t- \\frac{\\left(\\sum_{i=1}^{M}\\ddot{m}_{\\text{fuel}_i}\\right)\\left(m_{\\text{hub}}\\,\\bm{r}_{Bc/B} + \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\,\\bm{r}_{Fc_i/B}\\right)  }{\\left(m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\right)^2} +\\\\-\n\t\\frac{2\\,\\left(\\sum_{i=1}^{M}\\dot{m}_{\\text{fuel}_i}\\right)\\sum_{i=1}^{M}\\left(\\dot{m}_{\\text{fuel}_i}\\bm{r}_{Fc_i/B} + m_{\\text{fuel}_i}\\bm{r}'_{Fc_i/B}\\right) }{\\left(m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\right)^2} +\\\\\n\t+ \\frac{2\\,\\left(\\sum_{i=1}^{M}\\dot{m}_{\\text{fuel}_i}\\right)^2\\left(m_{\\text{hub}}\\bm{r}_{Bc/B} +\\sum_{i=1}^{M} m_{\\text{fuel}_i}\\bm{r}_{Fc_i/B}\\right)}{\\left(m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}\\right)^3}\n\\end{multline}\nUsing these definitions of $\\bm c$, the translational EOM can be simplified. Additionally, some assumptions need to be defined to further simplify the translational EOM. The hub is assumed to be rigid, therefore deformations are not considered. The mass flow within the tanks and the thrusters is assumed to be a second order effect and ignored for this paper. The particles are assumed to be accelerated instantaneously from the spacecraft velocity, $\\dot{\\bm{r}}_{B/N}$, to the exhausted velocity $\\bm{v}_{\\text{exh}}$ at the nozzle. And the exhausted velocity $\\bm{v}_{\\text{exh}}$ is considered constant and parallel to the nozzle's normal $\\hat{\\bm{n}}$.\n\nThe first integral in Eqn. \\eqref{eq:ComplTranslEOM} is computed using the fact that $\\bm{r}_{M/B} = \\bm{c} + \\bm{r}_{M/C}$ and the result is shown in the following equation:\n\n\\begin{multline}\\label{eq:eq19}\n\t\\int_{\\mathcal{V}_{\\text{sc}}}\\rho\\,\\left(\\ddot{\\bm{r}}_{B/N} + \\dot{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{r}_{M/B} + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{r}_{M/B}\\right)\\right)\\text{d}\\mathcal{V} = \\\\=\n\tm_{\\text{sc}} \\,\\bm{\\ddot{r}}_{B/N} + m_{\\text{sc}}\\,\\bm{\\dot{\\omega}}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{c} + m_{\\text{sc}}\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{c}\\right) \n\\end{multline}\n\\noindent \nwhere $m_{\\text{sc}}=m_{\\text{hub}}+ \\sum_{i=1}^{M}m_{\\text{fuel}_i}$ is the instantaneous mass of the spacecraft. The second and fourth integrals are computed and yield:\n\n\\begin{equation}\\label{eq:eq20}\n\t\\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B}\\,\\text{d}\\mathcal{V} = \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t}\\left(m_{\\text{sc}}\\,\\bm{c}\\right) = m_{\\text{sc}}\\,\\bm{c}' + \\dot{m}_{\\text{fuel}}\\bm{c}\n\\end{equation}\n\\begin{equation}\\label{eq:eq21}\n\t\\frac{^{\\mathcal{B}} \\text{d}^2}{\\text{d}t^2}\\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\,\\text{d}\\mathcal{V} = \\frac{^{\\mathcal{B}} \\text{d}^2}{\\text{d}t^2} \\left(m_{\\text{sc}}\\,\\bm{c}\\right) = m_{\\text{sc}}\\,\\bm{c}'' + 2\\,\\dot{m}_{\\text{fuel}}\\,\\bm{c}' + \\ddot{m}_{\\text{fuel}}\\bm{c}\n\\end{equation}\nwhere $\\dot{m}_{\\text{fuel}} = \\sum_{i=1}^{M}\\dot{m}_{\\text{fuel}_i}$ and $\\ddot{m}_{\\text{fuel}} = \\sum_{i=1}^{M}\\ddot{m}_{\\text{fuel}_i}$.\n\nIn order to find the term calculated on the reference surface seen in the third, fifth and sixth integrals,  it is convenient to separate the integrals on the surface of each nozzle. Moreover, as the fuel's properties are flowing out of a surface plane, it is convenient to consider that  $\\bm{r}_{M/B} = \\bm{r}_{M/Fc_j}+ \\bm{r}_{Fc_j/B} $ where $Fc_i$ is the area's geometric center. Finally, an appropriate variable transformation is given in Eqn. \\eqref{eq:cambVar}. Performing these calculations on the third integral results in:\n\\begin{equation}\\label{eq:eq22}\n\t\\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}}\\,\\bm{r}_{M/B}\\,\\text{d}A =-\\sum_{j=1}^{N} \\int_{\\dot{m}_{\\text{noz}_j}}\\left(\\bm{r}_{M/N_j}+ \\bm{r}_{N_j/B}\\right)\\text{d}\\dot{m}  =-\\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j}\\bm{r}_{N_j/B}\n\\end{equation}\n\\noindent\nwhere the first part of the integral is null because of barycenter definition and $\\dot{m}_{\\text{noz}_j}$ is the mass flow of the $j-$th nozzle. The fifth integral in Eq.~\\eqref{eq:ComplTranslEOM} yields:\n\\begin{equation}\\label{eq:eq23}\n\t\\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t} \\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}_{M/B}\\,\\text{d}A = \\frac{^{\\mathcal{B}} \\text{d}}{\\text{d}t} \\left(-\\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j}\\bm{r}_{N_j/B}\\right) = -\\sum_{j=1}^{N}\\ddot{m}_{\\text{noz}_j}\\bm{r}_{N_j/B}\n\\end{equation}\n\\noindent\nUsing the assumption introduced earlier in this section, $\\bm{r}'_{M/B} = \\bm{v}_{\\text{exh}}$, the sixth is integral is found and can be in the following equation:\n\n\\begin{equation}\\label{eq:eq24}\n\t\\int_{\\mathcal{A}_\\text{sc}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{\\hat{n}} \\,\\bm{r}'_{M/B} \\,\\text{d}A  =\\sum_{j=1}^{N}\\int_{\\mathcal{A}_{\\text{noz}_j}}\\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{n}\\,\\bm{r}'_{M/B}\\text{d}A = -\\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j}\\,\\bm{v}_{\\text{exh}_j}\n\\end{equation}\n\\noindent\nwhere $\\bm{v}_{\\text{exh}_j}$ is the exhausted velocity of a particle exiting from the $j-$th nozzle.\n\nThe two integrals on the right-hand-side of Eq.~\\eqref{eq:ComplTranslEOM} depends on the force model chosen. Therefore, to not lose generality, the resulting surface integral due to the pressure jump between the nozzle and the environment is the only term that is analytically computed seen in the following equation:\n\n\\begin{equation}\\label{eq:eq25}\n\t\\int_{\\mathcal{V}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{vol}} +\\int_{\\mathcal{A}_{\\text{sc}}} \\text{d}\\bm{F}_{\\text{surf}} = \\bm{F}_{\\text{ext, vol}} + \\bm{F}_{\\text{ext, surf}} + \\sum_{j=1}^{N}\\frac{\\bm{v}_{\\text{exh}_j}}{v_{\\text{exh}_j}}\\,A_{\\text{noz}_j}\\,(p_{\\text{exh}_j} - p_{\\text{atm}})\n\\end{equation}\n\\noindent\nwhere $\\bm{F}_{\\text{ext, vol}}$ are the external forces acting on the control volume, $\\bm{F}_{\\text{ext, surf}}$ are the external forces accelerating the control surface, $p_{\\text{exh}_j}$ is the particles' exhausted pressure at the $j-$th nozzle and  $p_{\\text{atm}}$ is the atmospheric pressure.\n\nFinally, Equation \\eqref{eq:ComplTranslEOM} is rewritten considering the nozzles' geometry and fluid properties by using Equations~\\eqref{eq:eq20}-~\\eqref{eq:eq25}:\n\\begin{multline}\n\tm_{\\text{sc}} \\bm{\\ddot{r}}_{B/N} + m_{\\text{sc}}\\,\\bm{\\dot{\\omega}}_{\\mathcal{B}/\\mathcal{N}} \\times\\bm{c} + m_{\\text{sc}}\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times\\left(\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\times\\bm{c}\\right) + m_{\\text{sc}}\\,\\bm{c}'' + 2\\,\\dot{m}_{\\text{fuel}}\\,\\bm{c}' +\\\\+ \\ddot{m}_{\\text{fuel}}\\bm{c} + 2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times \\bigg(m_{\\text{sc}}\\,\\bm{c}'+ \\dot{m}_{\\text{fuel}}\\bm{c} - \\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j}\\bm{r}_{N_j/B}  \\bigg) - \\sum_{j=1}^{N}\\ddot{m}_{\\text{noz}_j}\\bm{r}_{N_j/B}\t+\\\\-\n\t\\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j}\\,\\bm{v}_{\\text{exh}_j} = \\bm{F}_{\\text{ext, vol}} + \\bm{F}_{\\text{ext, surf}} + \\sum_{j=1}^{N}\\frac{\\bm{v}_{\\text{exh}_j}}{v_{\\text{exh}_j}}\\,A_{\\text{noz}_j}\\,(p_{\\text{exh}_j} - p_{\\text{atm}})\n\\end{multline}\nThe previous equation is modified by defining the following quantity:\n\n\\begin{equation}\\label{eq:IspRel}\n\t\\bm{F}_{\\text{thr}_j}= \\bm{v}_{\\text{exh}_j}\\,\\left(\\frac{A_{\\text{noz}_j}}{v_{\\text{exh}_j}}\\,(p_{\\text{exh}_j} - p_{\\text{atm}}) + \\dot{m}_{\\text{noz}_j}\\right) = I_{\\text{sp}_j}\\,g_0\\,\\dot{m}_{\\text{noz}_j}\\frac{\\bm{v}_{\\text{exh}_j}}{v_{\\text{exh}_j}}\n\\end{equation}\n\nFor further simplicity, the cross product is substituted with the associated skew symmetric matrix, and the translational equation is written in a more compact form:\n\n\\begin{multline}\\label{eq:eq29}\n\t\\ddot{\\bm{r}}_{B/N} + \\left[\\tilde{\\bm{c}}\\right]^T\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} =  \\frac{\\bm{F}_{\\text{thr}}}{m_{\\text{sc}}} - 2\\,\\frac{\\dot{m}_{\\text{fuel}}}{m_{\\text{sc}}}\\,\\left(c' + \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\\times\\bm{c}\\right) - \\bm{c}''+2\\,\\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]^T\n\t\\bm{c}'\\\\- \\ddot{m}_{\\text{fuel}}\\,\\bm{c} + \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]^T \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\bm{c} +\\frac{2}{m_{\\text{sc}}}\\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j} \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\bm{r}_{N_j/B}\n\t\\\\+ \\frac{\t1}{m_{\\text{sc}}} \\sum_{j=1}^{N}\\ddot{m}_{\\text{noz}_j}\\bm{r}_{Fc_j/B}  +\\frac{\\bm{F}_{\\text{ext, vol}}}{m_{\\text{sc}}}  + \\frac{\\bm{F}_{\\text{ext, surf}}}{m_{\\text{sc}}} \n\\end{multline}\nMultiplying my \n\n\\begin{multline}\\label{eq:eq30}\nm_{\\text{sc}} \\ddot{\\bm{r}}_{B/N} - m_{\\text{sc}} \\left[\\tilde{\\bm{c}}\\right]\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} =  \\bm{F}_{\\text{thr}} - 2\\,\\dot{m}_{\\text{fuel}} \\left(c' + \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\\times\\bm{c}\\right) - m_{\\text{sc}} \\bm{c}''-2 m_{\\text{sc}} \\,\\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\n\\bm{c}'\\\\- m_{\\text{sc}} \\ddot{m}_{\\text{fuel}}\\,\\bm{c} - m_{\\text{sc}} \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\bm{c} +2 \\sum_{j=1}^{N}\\dot{m}_{\\text{noz}_j} \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\bm{r}_{N_j/B}\n\\\\+ \\sum_{j=1}^{N}\\ddot{m}_{\\text{noz}_j}\\bm{r}_{Fc_j/B}  +\\bm{F}_{\\text{ext, vol}} + \\bm{F}_{\\text{ext, surf}}\n\\end{multline}\nThis EOM is the translational equation for an open system subjected to external forces $\\bm{F}_{\\text{ext, vol}} \\text{ and } \\bm{F}_{\\text{ext, surf}}$ and thrust $\\bm{F}_{\\text{thr}}=\\sum_{j=1}^{N}\\bm{F}_{\\text{thr}_j}$ due to mass depletion of the spacecraft, represented in Figure \\ref{fig:Spacecraft}.\nFrom this equation, it can be deduced that the variation of the mass inside the spacecraft directly impacts the position of the satellite with respect to the origin as the body fixed point $B$ changes its state of motion according to the variation of the tanks' linear inertia. In the next section, the rotational EOM for the spacecraft is developed.\n\n\\subsubsection{Rotational Equation of Motion}\nThe goal of this section is to develop the EOM associated with attitude dynamics of a spacecraft with depleting mass due to thrusters pulling mass from fuel tanks. Beginning from Newton's equation:\n\n\\begin{equation}\n\t\\ddot{\\bm{r}}_{M/N}\\,\\text{\\text{d}}m=\\text{d}\\bm{F} \\quad \\Rightarrow \\quad\n\t\\bm{r}_{M/N} \\times \\ddot{\\bm{r}}_{M/N}\\,\\text{d}m =\\bm{r}_{M/N} \\times \\text{d}\\bm{F}\n\\end{equation}\nand performing an integration over the system:\n\n\\begin{equation}\n\t\\int_{\\text{Body}} \\bm{r}_{M/N} \\times \\ddot{\\bm{r}}_{M/N}\\,\\text{d}m = \\int_{\\text{Body}}\\bm{r}_{M/N} \\times \\text{d}\\bm{F}\n\\end{equation}\nThe term on the left-hand side of the previous equation is manipulated in order to define the momentum about point $B$. This manipulation can be seen in the following equation:\n\n\\begin{multline}\\label{eq:eq32}\n\t\\int_{\\text{Body}} \\rho\\,\\bm{r}_{M/N} \\times \\ddot{\\bm{r}}_{M/N}\\,\\text{d}\\mathcal{V} = \\int_{\\text{Body}} \\rho\\,\\bm{r}_{M/B} \\times \\ddot{\\bm{r}}_{M/B}\\,\\text{d}\\mathcal{V} +\\\\ + \\int_{\\text{Body}} \\rho\\,\\bm{r}_{B/N} \\times \\ddot{\\bm{r}}_{M/N}\\,\\text{d}\\mathcal{V} + \\int_{\\text{Body}} \\rho\\,\\bm{r}_{M/B} \\times \\ddot{\\bm{r}}_{B/N}\\,\\text{d}\\mathcal{V} = \\int_{\\text{Body}}\\bm{r}_{M/N} \\times \\text{d}\\bm{F}\n\\end{multline}\nKnowing that $\\ddot{\\bm{r}}_{M/N}\\,\\text{\\text{d}}m=\\text{d}\\bm{F}$, the torque caused by the forces acting on the body is  easily defined:\n\n\\begin{equation}\n\t\\int_{\\text{Body}}\\bm{r}_{M/N} \\times \\text{d}\\bm{F}-\\int_{\\text{Body}}  \\rho\\,\\bm{r}_{B/N} \\times \\ddot{\\bm{r}}_{M/N}\\,\\text{d}\\mathcal{V} \n\t= \\int_{\\text{Body}} \\left(\\bm{r}_{M/N}-\\bm{r}_{B/N}\\right) \\times \\text{d}\\bm{F} = \\bm{L}_{B}\n\\end{equation}\n\\noindent\nwhere $\\bm{L}_{B}$ is the torque with respect to the body-fixed point $B$.\n\nAs the mass of the system is constant, the derivative of the angular momentum about point $B$ is inferred from Equation~\\eqref{eq:eq32} due to a property of the cross product and the previously explained Reynold's transport theorem:\n\n\\begin{multline}\n\t\\int_{\\text{Body}}  \\rho\\,\\bm{r}_{M/B} \\times \\ddot{\\bm{r}}_{M/B}\\,\\text{d}\\mathcal{V}  = \\frac{^\\mathcal{N}\\text{d}}{\\text{d}t} \\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\times \\dot{\\bm{r}}_{M/B}\\,\\text{d}\\mathcal{V} + \\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B} \\cdot\\bm{\\hat{n}} \\left(\\bm{r}_{M/B} \\times \\dot{\\bm{r}}_{M/B}\\right)\\text{d}A\n\\end{multline} \n\nMoreover, similar to the translational equation, if all the mass of the system is assumed to be contained inside the control volume at the initial time, the following relationship results:\n\n\\begin{multline}\n\t\\int_{\\text{Body}} \\rho\\,\\bm{r}_{M/B} \\times \\ddot{\\bm{r}}_{B/N}\\,\\text{d}\\mathcal{V} -  \\bm{L}_{B}=  \\int_{\\mathcal{V}_{\\text{sc}}} \\rho\\,\\bm{r}_{M/B} \\times \\ddot{\\bm{r}}_{B/N}\\,\\text{d}\\mathcal{V} -  \\int_{\\mathcal{V}_{\\text{sc}}}\\bm{r}_{M/B} \\times \\text{d}\\bm{F}_{\\text{vol}} +\\\\- \\int_{\\mathcal{A}_{\\text{sc}}} \\bm{r}_{M/B} \\times\\text{d}\\bm{F}_{\\text{surf}} = {m}_{\\text{sc}} \\bm{c} \\times \\ddot{\\bm{r}}_{B/N}-\\bm{L}_{B,\\,\\text{vol}}-\\bm{L}_{B,\\,\\text{surf}}\n\\end{multline}\n\\noindent\nwhere $\\bm{L}_{B,\\,\\text{vol}}\\text{ and }\\bm{L}_{B,\\,\\text{surf}}$ are the torques caused by the volume and surface forces about point $B$. The general rotational equation for a control volume in a rotating reference frame is reorganized:\n\n\\begin{multline}\\label{eq:eq36}\n\t\\dot{\\bm{H}}_{\\text{sc, }B} + \\int_{\\mathcal{A}_{\\text{sc}}} \\rho\\,\\bm{r}'_{M/B} \\cdot\\bm{\\hat{n}} \\left(\\bm{r}_{M/B} \\times \\dot{\\bm{r}}_{M/B}\\right)\\text{d}A +{m}_{\\text{sc}} \\bm{c} \\times \\ddot{\\bm{r}}_{B/N}=\\bm{L}_{B,\\,\\text{vol}}+\\bm{L}_{B,\\,\\text{surf}}\n\\end{multline}\n\nTo perform the inertial derivative of $\\bm{H}_{\\text{sc, }B}$, first the definition of $\\bm{H}_{\\text{sc, }B}$ is defined:\n\\begin{multline}\n\t\\bm{H}_{\\text{sc, }B}= \\left[I_{\\text{hub},\\,B_c}\\right] \\bm{\\omega}_{\\cal{B}/\\cal{N}} + \\bm{r}_{Bc/B} \\times m_\\text{hub} \\,\\dot{\\bm{r}}_{Bc/B} +\\\\ +\\sum_{i=1}^{M}\\left(\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right]\\, \\bm{\\omega}_{\\cal{B}/\\cal{N}} + \\bm{r}_{Fc_i/B} \\times m_{\\text{fuel}_i}\\, \\dot{\\bm{r}}_{Fc_i/B}\\right)\n\\end{multline}\nwhere $\\left[I_{\\text{hub},\\,B_c}\\right]$ is the hub's inertia about its center of mass, $B_c$, and $\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right]$ is the $i-$th tank's inertia about its center of mass, $Fc_i$. Furthermore, an analytical expression of mass depletion in the rotational motion is deduced:\n\\begin{multline}\\label{eq:HscB_dot}\n\t\\dot{\\bm{H}}_{\\text{sc, }B} = \\left[I_{\\text{hub},\\,Bc}\\right]\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\left(\\left[I_{\\text{hub},\\,Bc}\\right]\\bm{\\omega}_{\\cal{B}/\\cal{N}}\\right)+ \\bm{r}_{Bc/B} \\times m_\\text{hub}\\,\\ddot{\\bm{r}}_{Bc/B} +\\\\\n\t+ \\sum_{i=1}^{M}\\left(\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right] \\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\left(\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right]\\, \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\right) \n\t+ \\bm{r}_{Fc_i/B} \\times m_{\\text{fuel}_i}\\, \\ddot{\\bm{r}}_{Fc_i/B}+\\right.\\\\ \n\t\\left.+ \\bm{r}_{Fc_i/B} \\times \\dot{m}_{\\text{fuel}_i} \\,\\dot{\\bm{r}}_{Fc_i/B} + \\left[I_{\\text{fuel}_i,\\, Fc_i}\\right]' \\, \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\right)\n\\end{multline}\n\nIt should be noted here that any relative motion of particles inside the fuel tanks of the spacecraft has been neglected and, as a consequence, the effects both of the Coriolis' acceleration and of the whirling motion of the fuel on the spacecraft dynamics have not been considered.\n\nAdditionally, the inertial time derivate of the vectors $\\bm{r}_{Bc/B}$ and $\\bm{r}_{Fc_i/B}$ is computed using the transport theorem between the two reference frames given in Equations \\eqref{eq:rMB_ddot} and \\eqref{eq:rMB_dot} and, considering that the point $B_c$ is fixed in the $\\mathcal{B}$ frame, Equation \\eqref{eq:HscB_dot} is rewritten:\n\n\\begin{multline}\\label{eq:HscB_complic}\n\t\\dot{\\bm{H}}_{\\text{sc, }B} = \\left[I_{\\text{hub},\\,Bc}\\right]\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\left(\\left[I_{\\text{hub},\\,Bc}\\right]\\bm{\\omega}_{\\cal{B}/\\cal{N}}\\right) \n\t+ \\bm{r}_{Bc/B} \\times m_\\text{hub}\\,\\left(\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{Bc/B} +\\right.\\\\\n\t+\\left. \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\left(\\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{Bc/B}\\right) \\right) \n\t+\\sum_{i=1}^{M} \\bigl(\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right] \\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\left(\\left[I_{\\text{fuel}_i,\\,Fc_i}\\right] \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\right) +\\\\ \n\t+ \\bm{r}_{Fc_i/B} \\times m_{\\text{fuel}_i}\\, \\bigl( \\bm{r}''_{Fc_i/B} + 2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times \\bm{r}'_{Fc_i/B}\n\t+ \\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{Fc_i/B} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times\n\t\\left(\\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{Fc_i/B}\\right) \\bigr)+\\\\ \n\t+\n\t\\bm{r}_{Fc_i/B} \\times \\dot{m}_{\\text{fuel}_i} \\,\\left(\\bm{r}'_{Fc_i/B}+\\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{Fc_i/B}\\right) \n\t+ \\left[I_{\\text{fuel,}_i,\\,Fc_i}\\right]' \\, \\bm{\\omega}_{\\cal{B}/\\cal{N}}\\bigr)\n\\end{multline}\n\nIn order to simplify compact Equation \\eqref{eq:HscB_complic} the following inertia matrices are defined using the skew symmetric matrix to replace the cross product:\n\\begin{equation}\\label{eq:eq44}\n\t\\left[I_{\\text{hub},\\,B}\\right]= \\left[I_{\\text{hub},\\,Bc}\\right] + m_\\text{hub}\\, \\left[\\tilde{\\bm{r}}_{Bc/B}\\right]\\left[\\tilde{\\bm{r}}_{Bc/B}\\right]^T \n\\end{equation}\n\\begin{equation}\\label{eq:eq45}\n\t\\left[I_{\\text{fuel}_i,\\,B}\\right]= \\left[I_{\\text{fuel}_i,\\,Fc_i}\\right] + m_{\\text{fuel}_i}\\, \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]^T\n\\end{equation}\n\\begin{equation}\\label{eq:eq46}\n\t\\left[I_{\\text{sc, }B}\\right]=  \\left[I_{\\text{hub},\\,B}\\right] + \\sum_{i=1}^{M}\\left[I_{\\text{fuel}_i,\\,B}\\right]\n\\end{equation}\nMoreover, using the Jacobi identity for the cross product $\n\\mathbf {a} \\times (\\mathbf {b} \\times \\mathbf {c} )+\\mathbf {b} \\times (\\mathbf {c} \\times \\mathbf {a} )+\\mathbf {c} \\times (\\mathbf {a} \\times \\mathbf {b} )=\\mathbf {0}$, the body relative time derivative of the fuel inertia in the $\\mathcal{B}$ reference frame is introduced:\n\n\\begin{multline}\\label{eq:eq47}\n\t\\bm{r}_{Fc_i/B} \\times \\left(2\\,\\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times \\bm{r}'_{Fc_i/B}\\right) =-\\bm{r}_{Fc_i/B} \\times \\left( \\bm{r}'_{Fc_i/B} \\times \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\right) \n\t+\\\\-\\bm{r}'_{Fc_i/B} \\times \\left( \\bm{r}_{Fc_i/B} \\times \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}}\\right) + \\bm{\\omega}_{\\mathcal{B}/\\mathcal{N}} \\times \\left(\\bm{r}_{Fc_i/B}\\times \\bm{r}'_{Fc_i/B}\\right)\n\\end{multline}\n\\begin{multline}\\label{eq:eq48}\n\t\\left[I_{\\text{fuel}_i,\\,B}\\right]'= \\left[I_{\\text{fuel}_i,\\,Fc_i}\\right] + \\dot{m}_{\\text{fuel}_i}\\, \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]^T +\\\\+ m_{\\text{fuel}_i}\\, \\left(\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]\\left[\\tilde{\\bm{r}}'_{Fc_i/B}\\right]^T+ \\left[\\tilde{\\bm{r}}'_{Fc_i/B}\\right]\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]^T\\right)\n\\end{multline}\nBy substituting Equations \\eqref{eq:eq44}-\\eqref{eq:eq48} Eq.\\eqref{eq:HscB_complic} is simplified to:\n\\begin{multline}\\label{eq:eq49}\n\t\\dot{\\bm{H}}_{\\text{sc, }B} = \\left[I_{\\text{sc, }B}\\right]\\,\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\\left[I_{\\text{sc, }B}\\right]\\,\\bm{\\omega}_{\\cal{B}/\\cal{N}} + \\sum_{i=1}^{M}\\left(m_{\\text{fuel}_i}\\,\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right] \\bm{r}''_{Fc_i/B} +\\right. \\\\\n\t\\left.+ \\dot{m}_{\\text{fuel}_i} \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]\\bm{r}'_{Fc_i/B}+ \\left[I_{\\text{fuel}_i,\\,B}\\right]' \\, \\bm{\\omega}_{\\cal{B}/\\cal{N}}\n\t+ \\left[\\tilde{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\right] \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right] \\bm{r}'_{Fc_i/B}\\right)\n\\end{multline}\n\nConsidering that at the nozzles's exit, $\\dot{\\bm{r}}_{M/B} = \\bm{v}_{exh_j} + \\bm{\\omega}_{\\cal{B}/\\cal{N}} \\times \\bm{r}_{M/B}$ and $\\text{d}\\dot{m} =- \\rho\\,\\bm{r}_{M/B}'\\cdot\\hat{\\bm{n}} \\,\\text{d}A$, the surface integral is expressed in terms of the nozzles' surface:\n\\begin{multline}\\label{eq:eq50}\n\t\\int_{A_{\\text{exh}}} \\rho\\,\\bm{r}'_{M/B}\\cdot\\bm{n} \\left(\\bm{r}_{M/B} \\times \\dot{\\bm{r}}_{M/B}\\right)\\text{d}A =- \\sum_{j=1}^{N}\\int_{\\dot{m}_{\\text{noz}_j}}\\bm{r}_{M/B} \\times  \\bm{v}_{\\text{exh}_j}\\,\\text{d}\\dot{m}+\\\\\n\t+ \\sum_{j=1}^{N}\\int_{\\dot{m}_{\\text{noz}_j}}\\bm{r}_{M/B} \\times\\left( \\bm{r}_{M/B}\\times \\bm{\\omega} _{\\mathcal{B}/\\mathcal{N}}\\right)\\,\\text{d}\\dot{m}\n\\end{multline}\nEquation~\\eqref{eq:eq36} is updated with Equations \\eqref{eq:eq49} and \\eqref{eq:eq50}:\n\\begin{multline}\n\t\\dot{\\bm{H}}_{\\text{sc, }B} = \\left[I_{\\text{sc, }B}\\right]\\,\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\\left[I_{\\text{sc, }B}\\right]\\,\\bm{\\omega}_{\\cal{B}/\\cal{N}} + \\sum_{i=1}^{M}\\left(m_{\\text{fuel}_i}\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right] \\bm{r}''_{Fc_i/B} + \\left[I_{\\text{fuel}_i,\\,B}\\right]' \\bm{\\omega}_{\\cal{B}/\\cal{N}}\n\t+\\right. \\\\\n\t\\left.+ \\dot{m}_{\\text{fuel}_i} \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]\\bm{r}'_{Fc_i/B}+  {m}_{\\text{fuel}_i}\\,\\left[\\tilde{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\right] \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right] \\bm{r}'_{Fc_i/B}\\right)\n\t+\\sum_{j=1}^{N}\\int_{\\dot{m}_{\\text{noz}_j}}\\left[\\tilde{\\bm{r}}_{M/B}\\right] ^T  \\bm{v}_{\\text{exh}_j}\\,\\text{d}\\dot{m}+\\\\\n\t+\\sum_{j=1}^{N}\\int_{\\dot{m}_{\\text{noz}_j}}\\left[\\tilde{\\bm{r}}_{M/B}\\right]   \\left[\\tilde{\\bm{r}}_{M/B}\\right]  \\bm{\\omega} _{\\mathcal{B}/\\mathcal{N}} \\,\\text{d}\\dot{m} +\\left[\\tilde{\\bm{c}}\\right] m_{\\text{sc}}\\,\\ddot{\\bm{r}}_{B/N}=\\bm{L}_{B,\\,\\text{vol}}+\\bm{L}_{B,\\,\\text{surf}} \n\\end{multline}\n\nThe torque of each thruster nozzle is computed by the exhausting flow pressure distribution and by the lever arm distance from point $B$ and the application point of the force:\n\\begin{equation}\n\t\\bm{L}_{B_{\\text{thr}_j}} = \\bm{L}_{B_{\\text{sc, noz}_j}} + \\int_{\\dot{m}_{\\text{noz}_j}}\\bm{r}_{M/B} \\times  \\bm{v}_{\\text{noz}_j}\\,\\text{d}\\dot{m}\n\\end{equation}\nFurthermore, a term taking into account the angular momentum variation caused by mass depletion is defined:\n\n\\begin{equation}\\label{eq:eq53}\n\t\\left[K\\right]= \\sum_{i=1}^{M}\\left[I_{\\text{fuel}_i,\\,B}\\right] '\t+\\sum_{j=1}^{N} \\int_{\\dot{m}_{\\text{noz}_j}}\\left[\\tilde{\\bm{r}}_{M/B}\\right] \\left[\\tilde{\\bm{r}}_{M/B}\\right]\\,\\text{d}\\dot{m} \n\\end{equation}\n\nThe second integral in Equation \\eqref{eq:eq53} is computed evaluating the momentum exchanged due to the fuel exiting the nozzle area (assuming a circular nozzle), coincident the interface surface between the spacecraft and the exhausted fuel:\n\n\\begin{multline}\n\t\\int_{\\dot{m}_{\\text{noz}_j}}\\left[\\tilde{\\bm{r}}_{M/B}\\right] \\left[\\tilde{\\bm{r}}_{M/B}\\right]\\,\\text{d}\\dot{m} \n\t=\\int_{\\dot{m}_{\\text{noz}_j}}\\left(\\left[\\tilde{\\bm{r}}_{N_j/B}\\right] + \\left[\\tilde{\\bm{r}}_{M/N_j}\\right]\\right)\\left(\\left[\\tilde{\\bm{r}}_{N_j/B}\\right] + \\left[\\tilde{\\bm{r}}_{M/N_j}\\right]\\right)\\,\\text{d}\\dot{m} =\\\\\n\t=-\\dot{m}_{\\text{noz}_j}\\left(\\left[\\tilde{\\bm{r}}_{N_j/B}\\right]\\left[\\tilde{\\bm{r}}_{N_j/B}\\right]^T + \\frac{A_{\\text{noz}_j}}{4\\,\\pi}\\left[BM_j\\right]\\left[\\begin{matrix}\n\t\t2&0&0\\\\\n\t\t0&1&0\\\\\n\t\t0&0&1\n\t\\end{matrix}\\right]\\left[BM_j\\right]^T\\right)\n\\end{multline}\n\\noindent\nwhere $A_{\\text{noz}_j}$ is the exiting area of the j-th nozzle and $\\left[BM_j\\right]$ is the direction cosine matrix (DCM) from from the j-th nozzle frame $\\mathcal{M}_j$, defined to have its origin at the $N_j$ point and its first axis in the exhausting velocity direction $\\bm{v}_{\\text{exh}_j}$, to the $\\mathcal{B}$ frame.\nFinally the rotational EOM is written as:\n\\begin{multline}\\label{eq:eq55}\n\t\\left[I_{\\text{sc, }B}\\right]\\,\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} + m_{\\text{sc}} \\left[\\tilde{\\bm{c}}\\right]\\ddot{\\bm{r}}_{B/N}= \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]^T\\left[I_{\\text{sc, }B}\\right]\\,\\bm{\\omega}_{\\cal{B}/\\cal{N}} - \\left[K\\right]\\,\\bm{\\omega} _{\\mathcal{B}/\\mathcal{N}}+\\\\+ \\sum_{i=1}^{M}\\left(m_{\\text{fuel}_i}\\,\\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]^T \\bm{r}''_{Fc_i/B} + \n\t{m}_{\\text{fuel}_i}\\,\n\t\\left[\\tilde{\\bm{\\omega}}_{\\mathcal{B}/\\mathcal{N}}\\right]^T \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right] \\bm{r}'_{Fc_i/B}+\\right.\\\\+\\left.\\dot{m}_{\\text{fuel}_i} \\left[\\tilde{\\bm{r}}_{Fc_i/B}\\right]^T\\bm{r}'_{Fc_i/B}\\right)\n\t+ \\bm{L}_{B,\\,\\text{vol}}+\\bm{L}_{B,\\,\\text{surf}}  + \\sum_{j=1}^{N}\\bm{L}_{B_{\\text{thr}_j}} \n\\end{multline}\nThis concludes the derivation of the EOMs needed to describe the translational and rotational motion of a spacecraft with depleting mass due to thrusters. The following section describes the models used for the fuel tanks.\n\n\\subsection{Tank models}\nDifferent tank models could be developed to perfectly suit the needs of the spacecraft's fuel chain configuration. In the present paper five reservoir models will be considered as examples and their properties, such as inertia variation and barycenter motion, will be gathered.\\newline\nThe models and their main hypothesis are presented below:\n\n\\begin{itemize}\n\t\\item The constant tank's volume model where a spherical reservoir maintains a fixed geometry, i.e. a constant radius, and a fixed barycenter.\n\t\\item The constant fuel's density model where a spherical tank keeps its geometrical shape but gradually change its volume, so its radius, to maintain constant the density of the fuel and it has a fixed center of mass. \n\t\\item The emptying tank model where the fuel leaks out from an outlet in the spherical reservoir and the quantity of fuel decrease perpendicularly to the output direction modifying the barycenter position and the body's inertia accordingly to the mass distribution inside the tank.\n\t\\item The uniform burn cylinder model where a cylindrical tank does not change its geometrical shape and volume but the gas gradually decrease its density. As a consequence, the fuel barycenter remains fixed and the inertia varies accordingly to the mass variation.\n\t\\item The centrifugal burn cylinder model where a cylindrical tank is considered and the fuel burns radially from the center until the walls without breaking the tank's symmetry. The inertia tensor derivative is computed from these hypothesis and the barycenter remains in its initial position because the symmetry is conserved.\n\\end{itemize}\n\n\\subsubsection{The constant tank's volume model}\nThis model takes into account the variation of the fuel inside considering no variation of the volume off the tank. By looking at Figure \\ref{fig:CostTankVol}:\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width = 0.33\\textwidth]{./Figures/ConstVolTank.eps}\n\t\\caption{Geometrical properties of the constant volume sphere.}\n\t\\label{fig:CostTankVol}\n\\end{figure}\n\n\\begin{equation}\n\tV_{\\text{tank}}= const \\quad \\Rightarrow \\quad R_{\\text{tank}} = const\n\\end{equation}\n\\begin{equation}\n\t\\left[I_{\\text{fuel, }Tc}\\right] = \\frac{2}{5}\\,m_{\\text{fuel}} \\,R_{\\text{tank}}^2\\, \\left[I_{3\\times3}\\right]\n\\end{equation} \n\\begin{equation}\n\t\\left[I_{\\text{fuel, }Tc}\\right]' = \\frac{2}{5}\\,\\dot{m}_{\\text{fuel}} \\,R_{\\text{tank}}^2\\, \\left[I_{3\\times3}\\right]\n\\end{equation}\n\nMoreover the position of the center of mass of the tank does not change, so:\n\n\\begin{equation}\n\t\\bm{r}'_{Tc/B} = 0 \\qquad\\qquad \\bm{r}''_{Tc/B}=0\n\\end{equation}\n\\subsubsection{The constant fuel's density model}\nThe second model considers a shape-changing tank adapting itself to keep the fuel's density constant. Thus,according to Figure \\ref{fig:ConstDensTank}:\n\\begin{figure}[hb!]\n\t\\centering\n\t\\includegraphics[width = 0.33\\textwidth]{./Figures/ConstDensTank.eps}\n\t\\caption{Geometrical properties of the constant density sphere.}\n\t\\label{fig:ConstDensTank}\n\\end{figure}\n\\begin{equation}\n\t\\begin{cases}\n\t\t\\dot{V}_{\\text{tank}} = \\frac{\\dot{m}_{\\text{fuel}}}{\\rho_{\\text{fuel}}} \\vspace{3pt}\\\\\n\t\t\\dot{V}_{\\text{tank}} = 4\\,\\pi\\,R_{\\text{tank}}^2\\,\\dot{R}_{\\text{tank}}\n\t\\end{cases}\n\t\\quad \\Rightarrow \\quad \\dot{R}_{\\text{tank}} = \\frac{\\dot{m}_{\\text{fuel}}}{4\\pi\\,R_{\\text{tank}}^2\\,\\rho_{\\text{fuel}}}\n\\end{equation}\n\nAs a consequence:\n\n\\begin{equation}\n\t\\left[I_{\\text{fuel, }Tc}\\right]= \\frac{2}{5}\\,m_{\\text{fuel}} \\,R_{\\text{tank}}^2\\, \\left[I_{3\\times3}\\right]\n\\end{equation}\n\\begin{multline}\n\t\\left[I_{\\text{fuel, }Tc}\\right]' =  \\frac{2}{5}\\left(R^2_{\\text{tank}}+\\frac{m_{\\text{fuel}}}{2\\pi\\,R_{\\text{tank}}\\,\\rho_{\\text{fuel}}}\\right)\\dot{m}_{\\text{fuel}}\\,\\left[I_{3\\times3} \\right] =\\\\\n\t= \\frac{2}{5}\\left(R^2_{\\text{tank}} + \\frac{2}{3}\\,R^2_{\\text{tank}}\\right)\\dot{m}_{\\text{fuel}}\\left[I_{3\\times3}\\right] = \\frac{2}{3}\\dot{m}_{\\text{fuel}}R^2_{\\text{tank}}\\left[I_{3\\times3}\\right]\n\\end{multline}\n\nAs in the previous model:\n\n\\begin{equation}\n\t\\bm{r}'_{Tc/B} = 0 \\qquad\\qquad \\bm{r}''_{Tc/B}=0\n\\end{equation}\n\n\\subsubsection{The emptying tank model}\nIn this case the mass variation stats from the opposite point to the outlet, that will be called from now on the pole, perpendicularly to the vector connecting the pole and the outlet.\\newline\nThe following notation will be used: $\\theta \\in (0\\,, \\pi)$ will be the latitude angle counted from the pole till the outlet,  $\\phi \\in (0\\,,2\\,\\pi)$ will note the longitude angle, the radius will be $r \\in (0,\\,R_{\\text{tank}})$. Moreover the $\\theta^*$ will denote the angle between the pole and the circumference of the fuel's free surface. The volume $\\mathcal{V}$ and the center of mass of the tank can be computed using notations in figure \\ref{fig:EmpTank}:\n\n\\begin{figure}[hb!]\n\t\\centering\n\t\\includegraphics[width = 0.8\\textwidth]{./Figures/EmpTank.eps}\n\t\\caption{Geometrical properties of the emptying tank model.}\n\t\\label{fig:EmpTank}\n\\end{figure}\n\n\n\\begin{multline}\n\t\\mathcal{V}(\\theta^*)=\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}}r^2\\,\\sin{\\theta\\,\\text{d}\\theta}\\,\\text{d}\\phi\\,\\text{d}r\\;+\\\\\n\t+\\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}}r^2\\,\\sin{\\theta\\,\\text{d}\\theta}\\,\\text{d}\\phi\\,\\text{d}r= \\frac{2\\,\\pi\\,R_{\\text{tank}}^3}{3}\\left[1+\\frac{3}{2}\\cos{\\theta^*}-\\frac{1}{2}\\cos^3{\\theta^*}\\right]\n\\end{multline}\n\\vspace{3pt}\n\\begin{multline}\n\t\\bm{r}_{Tc/B}\\cdot\\bm{\\hat{k}}_3 = \\bm{r}_{Tc'/B}\\cdot\\bm{\\hat{k}}_3 +  \\frac{1}{\\mathcal{V}(\\theta^*)}\\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}}r^3\\,\\sin{\\theta}\\cos{\\theta}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\;+\\right.\\\\\\left.+\\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}}r^3\\,\\sin{\\theta}\\cos{\\theta}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right)\n\t= \\frac{\\pi\\,R_{\\text{tank}}^4}\n\t{4\\,\\mathcal{V}(\\theta^*)}\\left[2\\,\\cos^2{\\theta^*} - \\cos^4{\\theta^*}-1\\right]\n\\end{multline}\n\\noindent\nwhere $\\bm{\\hat{k}}_3$ is the outlet-to-pole axis of the reference frame of the sphere and $\\bm{r}_{Tc'/B}$ the constant vector from $B$ to the center of the sphere.\\newline\nConsidering that $m_{\\text{fuel}}=\\rho_{\\text{fuel}}\\mathcal{V}\\,$, the derivatives in the $\\mathcal{B}$ reference frame can be performed:\n\n\\begin{multline}\n\t\\bm{r}'_{Tc/B}\\cdot\\bm{\\hat{k}}_3 =- \\frac{\\pi\\,R_{\\text{tank}}^4\\,\\rho_{\\text{fuel}}}{4\\,m^2_{\\text{fuel}}}\\left[4\\,m_{\\text{fuel}}\\dot{\\theta^*}\\,\\sin^3{\\theta^*}\\cos{\\theta^*} +\\right.\\\\\n\t\\left.+ \\dot{m}_{\\text{fuel}}\\left(2\\,\\cos^2{\\theta^*} - \\cos^4{\\theta^*}-1\\right)\\right]\n\\end{multline}\n\\begin{multline}\n\t\\bm{r}''_{Tc/B}\\cdot\\bm{\\hat{k}}_3 =- \\frac{\\pi\\,R_{\\text{tank}}^4\\,\\rho_{\\text{fuel}}}{2\\,m^3_{\\text{fuel}}}\\left[4\\,m_{\\text{fuel}}\\sin^3{\\theta^*}\\cos{\\theta^*} \\left(\\ddot{\\theta^*}\\,m_{\\text{fuel}} - 2\\,\\dot{\\theta^*}\\,\\dot{m}_{\\text{fuel}}\\right)+\\right.\\\\\n\t\\left.-4\\,m^2_{\\text{fuel}}\\,\\dot{\\theta^*}^2\\sin^2{\\theta^*}\\left(3\\,\\cos^2{\\theta^*} -\\sin^2{\\theta^*}\\right)+\\right.\\\\\n\t+\\left. \\left(2\\,\\cos^2{\\theta^*} - \\cos^4{\\theta^*}-1\\right)\\left(m_{\\text{fuel}}\\ddot{m}_{\\text{fuel}} - 2\\,\\dot{m}^2_{\\text{fuel}}\\right)\\right]\n\\end{multline}\n\nThe relation among $\\dot{m}_{\\text{fuel}}\\,$, $\\ddot{m}_{\\text{fuel}}\\, $, $\\dot{\\theta^*} $ and $\\ddot{\\theta^*} $ is deduced from the derivation of the relation between the volume $\\mathcal{V}$ and $m_{\\text{fuel}}$:\n\n\\begin{equation*}\n\tm_{\\text{fuel}}=\\rho_{\\text{fuel}}\\mathcal{V}(\\theta^*) \\quad \\Rightarrow \\quad \\dot{m}_{\\text{fuel}}=\\rho_{\\text{fuel}}\\dot{\\mathcal{V}}(\\theta^*)\n\\end{equation*}\n\\begin{equation}\n\t\\dot{m}_{\\text{fuel}} = -\\pi\\,\\rho_{\\text{fuel}} R_{\\text{tank}}^3 \\sin^3{\\theta^*}\\;\\dot{\\theta}^*\n\\end{equation}\n\n\\begin{equation}\n\t\\ddot{m}_{\\text{fuel}} = -\\pi\\,\\rho_{\\text{fuel}} R_{\\text{tank}}^3 \\sin^2{\\theta^*}\\left( \\ddot{\\theta^*}\\sin{\\theta^*} + 3\\, \\dot{\\theta^*}^2\\cos{\\theta^*}\\right)\n\\end{equation}\n\nFinally $\\theta^*$ can be found:\n\\begin{equation}\n\tm_{\\text{fuel}}=\\rho_{\\text{fuel}}\\mathcal{V}(\\theta^*) \\; \\Rightarrow \\; m_{\\text{fuel}} = \\frac{2}{3}\\pi\\, \\rho_{\\text{fuel}}\\,R_{\\text{tank}}^3\\left[1+\\frac{3}{2}\\cos{\\theta^*}- \\frac{1}{2}\\cos^3{\\theta^*}\\right]\n\\end{equation}\n\nAs far as the inertia concerns:\n\n\\begin{multline}\n\tI_{3\\,3} = \\rho_{\\text{fuel}} \\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\sin^3{\\theta}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r  \\vspace{3pt}\\right.+\\\\\n\t\\left.+ \\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}} r^4\\,\\sin^3{\\theta}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right)  =\\\\\n\t= \\frac{2}{5}\\pi\\,\\rho_{\\text{fuel}}R^5_{\\text{tank}}\\left[\\frac{2}{5}  + \\frac{1}{4}\\cos{\\theta^*}\\sin^4{\\theta^*} -\\frac{1}{12}\\left(\\cos{3\\theta^*} - 9\\cos{\\theta^*}\\right)\\right]\n\\end{multline}\n\n\\begin{multline}\n\tI_{2\\,2} =\\rho_{\\text{fuel}} \\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\left(\\sin{\\theta}-\\sin^3{\\theta}\\sin^2{\\phi}\\right)\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r + \\vspace{3pt}\\right.\\\\\n\t\\left.+ \\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}} r^4\\,\\left(\\sin{\\theta}-\\sin^3{\\theta}\\sin^2{\\phi}\\right)\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right) =\n\t\\frac{2}{5}\\pi\\,\\rho_{\\text{fuel}}R^5_{\\text{tank}}\\left[\\frac{2}{3} +\\right.\\\\\n\t\\left.- \\frac{1}{4}\\cos^5{\\theta^*}  +\\frac{1}{24}\\left(\\cos{3\\theta^*} -9\\cos{\\theta^*}\\right)  +\\frac{5}{4}\\cos{\\theta^*} +\\frac{1}{8} \\cos{\\theta^*}\\sin^4{\\theta^*}\\right]\n\\end{multline}\n\n\\begin{multline}\n\tI_{1\\,1} =\\rho_{\\text{fuel}} \\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\left(\\sin{\\theta}-\\sin^3{\\theta}\\cos^2{\\phi}\\right)\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r+\\right.\\\\\n\t\\left.+ \\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}} r^4\\,\\left(\\sin{\\theta}-\\sin^3{\\theta}\\cos^2{\\phi}\\right)\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right) = I_{2\\,2}\n\\end{multline}\n\\vspace{3pt}\n\\begin{multline}\n\tI_{1\\,2} = \\rho_{\\text{fuel}} \\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\sin^3{\\theta}\\cos{\\phi}\\sin{\\phi}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r \\right.+\\\\\n\t\\left.+\\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}} r^4\\,\\sin^3{\\theta}\\cos{\\phi}\\sin{\\phi}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right)= 0\n\\end{multline}\n\\vspace{3pt}\n\\begin{multline}\n\tI_{1\\,3} = \\rho_{\\text{fuel}} \\left(\\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\sin^2{\\theta}\\cos{\\theta}\\cos{\\phi}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\right.+\\\\\n\t+\\int_{0}^{2\\,\\pi}\\int_{\\theta^*}^{\\pi}\\int_{0}^{R_{\\text{tank}}} r^4\\,\\sin^2{\\theta}\\cos{\\theta}\\cos{\\phi}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r\\left.\\right) = 0\n\\end{multline}\n\\vspace{3pt}\n\\begin{multline}\n\tI_{2\\,3} = \\rho_{\\text{fuel}} \\int_{0}^{2\\,\\pi}\\int_{0}^{\\theta^*}\\int_{0}^{R_{\\text{tank}}\\frac{\\cos{\\theta^*}}{\\cos{\\theta}}} r^4\\,\\sin^2{\\theta}\\cos{\\theta}\\sin{\\phi}\\,\\text{d}\\theta\\,\\text{d}\\phi\\,\\text{d}r = 0 \\vspace{5pt}\n\\end{multline}\n\\noindent\nbecause $\\int_{0}^{2\\,\\pi}\\cos{\\phi}\\sin{\\phi} =\\int_{0}^{2\\,\\pi}\\sin{\\phi} = \\int_{0}^{2\\,\\pi}\\cos{\\phi}=0 $.\\newline\nFrom those calculations the derivatives, in the tank reference frame, can be computed:\n\n\\begin{multline}\n\tI'_{3\\,3}\t= \\frac{2}{5}\\pi\\,\\rho_{\\text{fuel}}R^5_{\\text{tank}} \\, \\dot{\\theta^*}\\left[ \\cos^2{\\theta^*}\\sin^3{\\theta^*} -\\frac{1}{4}\\sin^5{\\theta^*} +\\frac{1}{4}\\sin{3\\theta^*} -\\frac{3}{4}\\sin{\\theta^*} \\right]\n\\end{multline}\n\\begin{multline}\n\tI'_{2\\,2}\t= I'_{1\\,1}= \\frac{2}{5}\\pi\\,\\rho_{\\text{fuel}}R^5_{\\text{tank}} \\, \\dot{\\theta^*}\\left[ \\frac{5}{4}\\sin{\\theta^*}\\cos{\\theta^*} -\\frac{5}{4}\\sin{\\theta^*} -\\frac{1}{8}\\sin{3\\theta^*} +\\right.\\\\\n\t\\left. + \\frac{3}{8} \\sin{\\theta^*} + \\frac{1}{2}\\cos^2{\\theta^*}\\sin^3{\\theta^*} -\\frac{1}{8} \\sin^5{\\theta^*} \\right]\n\\end{multline}\n\n\\subsubsection{Uniform burn cylinder}\nThis model consider a cylindrical tank whose geometry remains constant while fuel density changes.\n\\begin{figure}[htb!]\n\t\\centering\n\t\\includegraphics[width = 0.7\\textwidth]{./Figures/UnifCyl.eps}\n\t\\caption{Geometrical properties of the uniform burn cylinder}\n\t\\label{fig:UnfBurnCyl}\n\\end{figure}\nFrom these considerations and by looking at Figure \\ref{fig:UnfBurnCyl}, the inertia tensor and its derivative could be evaluated:\n\n\\begin{equation}\n\tI_{1\\,1}=I_{2\\,2} = m_{\\text{fuel}} \\left[\\frac{R^2}{4} + \\frac{h^2}{3}\\right]\\qquad I_{3\\,3} = m_{\\text{fuel}}\\,\\frac{R^2}{2}\n\\end{equation}\n\\begin{equation}\n\tI'_{1\\,1}=I_{2\\,2} = \\dot{m}_{\\text{fuel}} \\left[\\frac{R^2}{4} + \\frac{h^2}{3}\\right]\\qquad I'_{3\\,3} = \\dot{m}_{\\text{fuel}}\\,\\frac{R^2}{2}\n\\end{equation}\n\\noindent\nwhere $R$ is the cylinder radius and $h$ its half-height.\\newline\nMoreover, as the position of the center of mass of the tank does not change:\n\n\\begin{equation}\n\t\\bm{r}'_{Tc/B} = 0 \\qquad\\qquad \\bm{r}''_{Tc/B}=0\n\\end{equation}\n\n\\subsubsection{Centrifugal burn cylinder}\nThe present model consider a cylinder filled with propellant burning radially from the center to the edge. The geometry properties and their nomenclature can be seen in Figure \\ref{fig:CentrCyl}.\n\n\\begin{figure}[htb!]\n\t\\centering\n\t\\includegraphics[width = 0.7\\textwidth]{./Figures/CentrCyl.eps}\n\t\\caption{Geometrical properties of the centrifugal burn cylinder}\n\t\\label{fig:CentrCyl}\n\\end{figure}\nBy denoting $r$ the distance of the fuel surface from the axis of the cylinder, this quantity can be easily computed from the amount of mass in the tank:\n\n\\begin{equation}\n\tr =\\sqrt{R^2 - \\frac{m_\\text{fuel}}{2\\,\\pi\\,\\rho\\,h}}\n\\end{equation}\n\\noindent\nwhere $R$ is the cylinder radius, $h$ its half-height and $\\rho$ the fuel density.\\newline\nAs in the previous models, the time derivative of $r$ can be gathered from volume-mass relation:\n\n\\begin{equation}\n\t\\dot{m}_\\text{fuel} = - 4\\pi\\rho\\,h\\,r\\,\\dot{r}\n\\end{equation}\n\nAs a consequence:\n\\begin{equation}\n\tI_{1\\,1} = I_{2\\,2} = m_\\text{fuel}\\left[\\frac{R^2+ r^2}{4} +\\frac{h^2}{3}\\right]\n\\end{equation}\n\\begin{equation}\n\tI_{3\\,3} = m_\\text{fuel}\\left[\\frac{R^2+ r^2}{2} \\right]\n\\end{equation}\n\nMoreover, their time derivatives in the tank's reference frame can be computed:\n\\begin{equation}\n\tI'_{1\\,1} = I'_{2\\,2} = \\dot{m}_\\text{fuel}\\left[\\frac{r^2}{2}+\\frac{h^2}{3}\\right]\n\\end{equation}\n\\begin{equation}\n\tI'_{3\\,3}  = \\dot{m}_\\text{fuel}\\,r^2\n\\end{equation}\n\nFinally, the tank's center of mass does not move as the mass variation is symmetric. Thus:\n\\begin{equation}\n\t\\bm{r}'_{Tc/B} = 0 \\qquad\\qquad \\bm{r}''_{Tc/B}=0\n\\end{equation}\n\n\\subsection{Update-Only Equations}\n\nEqs.\\eqref{eq:eq30} and \\eqref{eq:eq55} are the translational and rotational EOMs for the fully coupled dynamics of mass depletion. However, it is common to use an \"update-only\" method for mass depletion which does not consider mass depletion as a dynamical effect. In contrast to the fully coupled model it simply updates the mass properties of the spacecraft. The equations for the \"update-only\" can be simplified to:\n\n\\begin{equation}\\label{eq:eq31}\nm_{\\text{sc}} \\ddot{\\bm{r}}_{B/N} - m_{\\text{sc}} \\left[\\tilde{\\bm{c}}\\right]\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} =  \\bm{F}_{\\text{thr}} - m_{\\text{sc}} \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right] \\bm{c} \n\\end{equation}\n\n\\begin{equation}\\label{eq:eq55}\nm_{\\text{sc}} \\left[\\tilde{\\bm{c}}\\right]\\ddot{\\bm{r}}_{B/N} + \\left[I_{\\text{sc, }B}\\right]\\,\\dot{\\bm{\\omega}}_{\\cal{B}/\\cal{N}} = - \\left[\\tilde{\\bm{\\omega}}_{\\cal{B}/\\cal{N}}\\right]\\left[I_{\\text{sc, }B}\\right]\\,\\bm{\\omega}_{\\cal{B}/\\cal{N}}\n+ \\bm{L}_{B} + \\sum_{j=1}^{N}\\bm{L}_{B_{\\text{thr}_j}} \n\\end{equation}\n\n\n\n", "meta": {"hexsha": "dbf0f088b987e36cbf1b11377c89e44a6fffc355", "size": 55036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/FuelTank/_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/simulation/dynamics/FuelTank/_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/simulation/dynamics/FuelTank/_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": 89.3441558442, "max_line_length": 1190, "alphanum_fraction": 0.6542081547, "num_tokens": 21920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450968, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6363067803525977}}
{"text": "\\chapter{About prototype set models}\r\n\\label{ch_about}\r\n%\r\nThis report describes a supervised learning method we call the prototype set or `proset' algorithm.\r\nIt is an attempt to apply feature selection via the elastic net penalty to a nonlinear distribution model inspired by kernel regression.\r\nThe algorithm is implemented as Python package \\texttt{proset} using an interface compatible with machine learning library \\texttt{sklearn} \\cite{Pedregosa_11}.\\par\r\n%\r\nThe elastic net penalty was proposed by Zou and Hastie \\cite{Zou_05} as a combination of $L_1$- and $L_2$-regularization for linear regression.\r\nRegularization with either penalty has been studied by several authors in different contexts, usually with the purpose of preventing overfitting or finding a robust solution to an ill-conditioned problem.\r\nIn case of linear regression, the name `ridge regression' for applying an $L_2$-penalty appears to be due to Hoerl and Kennard \\cite{Hoerl_70}.\r\nThe LASSO algorithm that uses an $L_1$-penalty was proposed by Tibshirani \\cite{Tibshirani_96}.\\par\r\n%\r\nThe main advantage of an $L_1$-penalty over an $L_2$-penalty is that its derivative does not vanish near the origin.\r\nThus, a sufficiently large penalty weight selects features by forcing some model coefficients exactly to zero.\r\nThe main disadvantage is that the penalty term is not differentiable at zero, which means that model fitting usually requires specialized solvers.\r\nFor example, Andrew and Gao \\cite{Andrew_07} developed the OWL-QN algorithm to minimize an otherwise smooth objective function with an additional $L_1$-term.\r\nThis algorithm solves the optimization problem restricted to a particular orthant via backtracking line search.\r\nThe absolute value of each coefficient is represented as plus or minus identity depending on the orthant, so the restricted problem is everywhere differentiable.\r\nIf an optimum is found where any coefficients are exactly zero, the generalized Kuhn-Tucker conditions for the subgradient of the original term determine whether the solution is a local minimum or can be improved by moving to another orthant.\r\nIn case of proset, all model coefficients nonnegative, so optimization is naturally restricted to the first orthant.\r\nThus, we can rely on a standard algorithm for constrained continuous optimization like L-BFGS-B \\cite{Byrd_95}.\\par\r\n%\r\nZou and Hastie \\cite{Zou_05} show that a combined $L_1$- and $L_2$-penalty overcome some issues observed for the $L_1$-penalty applied to linear regression, but which we expect to affect other models as well.\r\nOne of these issues is that, in case of several highly correlated features, the LASSO tends to arbitrarily select only one of them.\r\nWith the elastic net penalty, highly correlated features are typically either included or excluded as a group.\r\nFurthermore, empirical results indicate that $L_2$-regularization improves the quality of the selected models.\r\nFor these reasons and because an $L_2$-penalty does not complicate the optimization problem, we decided to use an elastic net penalty for fitting proset models.\\par\r\n%\r\nTo derive a penalized version of negative log-likelihood, we follow the approach used by Friedman, Hastie, and Tibshirani \\cite{Friedman_10} for applying elastic net regularization to generalized linear models (GLMs).\r\nThis method is implemented as R package \\texttt{glmnet} \\cite{Friedman_10} for a variety of link functions.\r\nIn each case, a functional like this is minimized to determine model coefficients (with optional observation weights):\\par\r\n%\r\n\\begin{equation}\r\nf_{\\alpha,\\lambda}\\left(\\beta\\left|\\{(x_i,y_i)\\}_i\\right.\\right):=\\frac{1}{N}\\sum_{i=1}^Nl(y_i,\\beta_0+\\beta^Tx_i)+\\lambda\\left(\\frac{\\alpha}{2}\\sum_{j=1}^d\\beta_j^2+(1-\\alpha)\\sum_{j=1}^d|\\beta_j|\\right)\\label{eq_regularization}\r\n\\end{equation}\r\n%\r\nHere, $(x_i,y_i)$ are $N\\gg1$ observations with feature vectors $x_i\\in\\R^d$ and associated targets $y_i\\in\\R$, or some suitable subset thereof, e.g., the integers from $0$ to $K-1$ in case of classification with $K>1$ classes.\r\nThe link function $l$ is the negative log-likelihood for target $y_i$ conditional on a linear combination of $x_i$ with coefficients $\\beta\\in\\R^d$ and intercept $\\beta_0\\in\\R$.\r\nPenalty weights $\\lambda\\geq0$ and $\\alpha\\in[0,1]$ determine the overall magnitude of the elastic net penalty and the relative importance of the $L_1$- and $L_2$-terms.\r\nNote that the we have reversed the role of $\\alpha$ compared to the formulation used in \\cite{Friedman_10}, i.e., $\\alpha=1$ is pure $L_2$-regularization.\\par\r\n%\r\nFeature selection via $L_1$-penalty is a powerful technique.\r\nIt allows the user to evaluate a large number of potential input variables without having to worry about overfitting.\r\nUnfortunately, linear regression and GLMs are limited in the achievable model quality.\r\nAs the fitting procedure only deals with feature weights in the linear combination, modeling a nonlinear relationship requires that the effect is anticipated and explicitly coded as features.\r\nGeneralized additive models (GAMs) mitigate this somewhat by automatically applying nonlinear transform to the features.\r\nHowever, these transforms are restricted to a particular function class, e.g., splines with a predefined order and number of knots, and modeling higher order interactions can lead to a prohibitive number of terms.\r\nThe main reason for developing proset was to try overcoming these issues by using a different expression for the conditional distribution.\\par\r\n%\r\nThe distribution model for proset estimators is inspired by kernel-based methods from nonparametric statistics, in particular the Nadaraya-Watson estimator \\cite{Nadaraya_64}\\cite{Watson_64}.\r\nThis regression method uses a locally weighted average of the target values for training data to compute the conditional expectation of the target at an arbitrary point.\r\nLet $K:\\R\\rightarrow\\R$ be a kernel function, meaning that it is nonnegative, symmetric around the origin, and integrates to one.\r\nThen, for any bandwidth $h>0$, $K_h(x):=\\frac{1}{h}K\\left(\\frac{x}{h}\\right)$ is also a kernel function.\r\nGiven $N$ training samples $(x_n, y_n)\\in\\R^2$, the Nadaraya-Watson estimator with bandwidth $h$ at $x\\in\\R$ is defined as\r\n%\r\n\\begin{equation}\r\n\\hat{m}_h(x):=\\frac{\\sum_{n=1}^Ny_nK_h(x-x_n)}{\\sum_{n=1}^NK_h(x-x_n)}\\label{eq_nadaraya_watson}\r\n\\end{equation}\r\n%\r\nAs $K_h$ goes to zero for $x\\rightarrow\\pm\\infty$, samples where $x_n$ is close to $x$ have the most impact on $\\hat{m}(x)$.\r\nThe bandwidth controls the degree of smoothing, i.e., the impact of distant points increases with $h$.\r\nThe approach can be extended to multiple features using a multivariate kernel function with positive semi-definite bandwidth matrix $H$.\r\nUnlike GLMs or even GAMs, the Nadaraya-Watson estimator can approximate an arbitrary, smooth relationship between the features and target, as shown, e.g., by Devroye \\cite{Devroye_78}.\\par\r\n%\r\nLocally weighted averaging can also be used to estimate the conditional distribution itself instead of its expectation.\r\nThis requires replacing $y$ in (\\ref{eq_nadaraya_watson}) with a kernel function centered on $y$.\r\nA general framework that covers both continuous and discrete targets is proposed by Hall, Racine, and Li in \\cite{Hall_04}.\r\nThe prototype set algorithm uses a similar approach.\r\nA full description is given later, but two key features of proset models are:\r\n%\r\n\\begin{itemize}\r\n\\item The bandwidth matrix is limited to a diagonal structure.\r\nTo select features, we apply an elastic-net penalty to the inverse bandwidth term for each feature.\r\nThus, the penalty counteracts overfitting by enforcing smoothness and removing irrelevant features from the model altogether.\r\n%\r\n\\item Instead of including all samples with unit weight, the proset estimator includes only a subset of the training data with individual weights.\r\nThese are fitted subject to a separate elastic-net penalty term, which ensures that points are only included if they are suitably `representative' of their neighborhood.\r\n\\end{itemize}\r\n%\r\nWe refer to the set of training points selected for a proset model as `prototypes', which is how the method gets its name.\r\nNote that the term `prototype' has two slightly different meanings in English, both of which can be said to apply here:\r\n%\r\n\\begin{itemize}\r\n\\item A `prototype' can be a typical example in the sense of `archetype'.\r\nThe selected samples are considered typical for their neighborhood in the feature space.\r\n%\r\n\\item A `prototype' can be an incomplete version in the sense of `demonstrator'.\r\nDue to feature selection, each sample included in the model is reduced to its essential features.\r\n\\end{itemize}\r\n%\r\n\\section{Properties of proset}\r\n\\label{sec_properties}\r\n%\r\nThe first version of the \\texttt{proset} package implements a classifier -- a regressor is planned for a future release.\r\nChapter \\ref{ch_classifier} describes the model in detail, shows how to select good hyperparameters, and provides evaluation results for several public data sets and artificial test cases.\r\nFor comparison, we also trained k-nearest-neighbor (kNN)\\footnote{\r\nThe kNN method is commonly attributed to Fix and Hodges \\cite{Fix_51}, although they study nonparametric density estimators for discriminatory analysis, not supervised learning.\r\n}\r\nand extreme gradient boosting (XGBoost) \\cite{Chen_16} classifiers on the same data.\r\nThe former algorithm is conceptually close to proset as it relies on local averaging.\r\nThere is even an extension for $k=1$, Hart's `condensed nearest neighbor' algorithm \\cite{Hart_68}, concerned with extracting a subset of representative points from the training data.\r\nXGBoost has become a kind of industry standard for machine learning with highly informative features, i.e., those problems not requiring deep learning.\r\nEmpirical results shows that it is often very good at optimizing a model in terms of a chosen metric.\r\nBoth algorithms are capable of representing a nonlinear relationship between the features and target.\\par\r\n%\r\nIn the benchmark study, we optimize the models on each data set for minimal log-loss.\r\nFor the best performing algorithm, we compute the sum of cross-validation mean and standard deviation for log-loss using the optimal hyperparameters.\r\nIf another algorithm reaches a score less than or equal to this threshold, we consider it `equivalent' to the best model.\r\nTable \\ref{tab_classifier_comparison} summarizes the relative performance of the classifiers on eleven test cases.\r\nA model is rated as either `best' (lowest log-loss), `equivalent' (log-loss less than or equal to the threshold), `worse' (log-loss above the threshold), or `worst' (classifier returns constant estimator).\\par\r\n%\r\n\\begin{table}\r\n\\caption{Comparison of classification algorithms}\r\n\\label{tab_classifier_comparison}\r\n%\r\n\\begin{center}\r\n\\begin{tabular}{|lcccc|}\r\n\\hline\r\n&\\multicolumn{4}{c|}{\\textbf{Log-loss score}}\\\\\r\n\\textbf{Classifier}&\\textbf{Best}&\\textbf{Equivalent}&\\textbf{Worse}&\\textbf{Worst$^*$}\\\\\r\nproset&4&2&5&--\\\\\r\nkNN&1&3&6&1\\\\\r\nXGBoost&7&--&2&2\\\\\r\n\\multicolumn{5}{|l|}{$^*$ Algorithm returns constant estimator.}\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nFor the test cases -- which are of course not representative of anything in particular -- the performance of proset is in-between kNN and XGBoost.\r\nThere are also several instances where two or all three of the models are equivalent.\r\nThe exception are three of the four cases where XGBoost is `worse' or `worst'.\r\nThese are artificial data sets where the target is a deterministic function of five or six features.\r\nThe fourth data set is very small and performance on testing data highly variable.\\par\r\n%\r\nOur study contains artificial test cases relying on the interaction of three to six features.\r\nXGBoost provides very good results up to four features, is worse than the other two models for five features, and fails on six features.\r\nThis may be a limitation of the binary decision trees used as base learners.\r\nBoth kNN and proset models have some predictive value for the higher order interaction terms, although results are far from perfect given that the relationship between features and target is deterministic.\r\nIf we add six more irrelevant features to the sixth order interaction, kNN also fails.\r\nThe proset classifier is able to select only the relevant inputs and produce a nontrivial estimate as before.\\par\r\n%\r\nOne particular strength of proset models we found while studying the example cases is that they tend to be highly explainable.\r\nThis is due to feature selection and that fact that the distance-based approach allows for geometric interpretation.\r\nAnother important reason is that the estimate for a particular sample tends to depend meaningfully only on a few prototypes, although the total number can go into the hundreds or thousands.\r\nChapter \\ref{ch_explainability} `Explainability' shows examples for the following:\r\n%\r\n\\begin{itemize}\r\n\\item Feature selection makes it easier for humans to review the model structure.\r\nIf the number of relevant features is small, users can assess whether the choice is sensible and study low-dimensional representations like scatter plots or cuts through the decision space.\r\n%\r\n\\item Prototype selection simplifies reviewing the model structure even if the number of features is large.\r\nWe can perform weighted PCA on the feature matrix for the prototypes and use this to create low-dimensional maps of the data.\r\nAlso, a check whether the training data has labeling errors or artifacts can start with the smaller set of prototypes.\r\n%\r\n\\item The estimate for a particular sample can be explained by reviewing the prototypes with the highest impact.\r\nThis is an explanation in terms of similar training instances instead of more abstract properties, which can help nontechnical users to understand and trust the model.\r\n%\r\n\\item Proset rates new samples based on their absolute distance to the prototypes.\r\nThat means the algorithm can detect whether a new sample is far away from the training data and the estimate should not be relied on.\r\n\\end{itemize}\r\n%\r\nNote that the last three properties do not require the selected number of features to be small.\r\nFor example, proset could be used as the final stage in transfer learning and add its capabilities to a model of arbitrary complexity like a deep neural network.\r\n%\r\n\\section{The curse of dimensionality}\r\n\\label{sec_curse}\r\n%\r\nThe Nadaraya-Watson estimator is known to have poor convergence properties in feature spaces of high dimension.\r\nFor $n$ samples in a $d$-dimensional space, the asymptotic rate of convergence for the error is $n^{-\\frac{4}{4+d}}$ \\cite{Haerdle_04}.\r\nThis is due to the trade-off between the point-wise bias and variance.\r\nConsider the simple case where $H$ is a diagonal matrix with constant bandwidth $h_n$ in each dimension.\r\nTo reduce the bias, $h_n$ has to converge to zero as $n$ goes to infinity.\r\nTo reduce the variance, the number of training points with nonnegligible impact on the estimator at any one point has to go to infinity with $n$.\r\nAs the volume containing such points is proportional to $h_n^d$, the number of points is proportional to $nh_n^d$.\r\nThus, the bandwidth can only converge to zero very slowly with $n$ if $d$ is large, with a corresponding slow reduction in bias.\\par\r\n%\r\nWhat are the implications for proset?\r\nFeature selection is obviously beneficial as the convergence rate of the estimator should depend only on the number of features included in the model.\r\nThe impact of prototype selection is harder to quantify.\r\nConsider a target distribution that can be replicated exactly by proset, i.e., it is generated by local averaging using a finite number of kernel functions for weighting.\r\nIn this situation, the bandwidth does no longer have to vanish asymptotically with $n$ to yield a small bias.\r\nWe have established no theoretical results, but it would be interesting to study the convergence behavior for distributions that can be reproduced or at least closely approximated by proset.\\par\r\n%\r\nThe case with the largest dimension in the benchmark study has a 64 features.\r\nProset selects around 30 of these to build a model with reasonable performance, although XGBoost achieves a better log-loss.\r\nThis number of features is not particularly large for a classification problem.\r\nHowever, it appears to be quite large compared to problems that are typically considered feasible for local kernel methods.\r\nFor comparison, we found published examples with 8 features (local linear regression: Ormoneit and Hastie \\cite{Ormoneit_99}),\r\n7 to 17 features depending on the encoding of categorical variables (nonparametric conditional distribution: Bontemps, Racine, and Simoni \\cite{Bontemps_09}),\r\nor 24 variables, of which any one can serve as target (the largest sample data set for R package \\texttt{np}: Hayfield and Racine \\cite{Hayfield_08}).\r\n%\r\n\\section{Release history}\r\n\\label{sec_release_history}\r\n%\r\nThese versions of the \\texttt{proset} Python package have been released:\r\n%\r\n\\begin{description}\r\n\\item[0.1.0:] implementation of proset classifier using algorithm L-BFGS-B \\cite{Byrd_95} for parameter estimation;\r\nhelper functions for model fitting and plotting;\r\nbenchmark code for hyperparameter selection, comparison to other classifiers, and demonstration of explanatory features;\r\nfirst version of technical report.\r\n\\end{description}\r\n%\r\n\\endinput\r\n", "meta": {"hexsha": "76dda7050d9366cf66320aa4484e67179347ca7c", "size": 17460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/about.tex", "max_stars_repo_name": "NRuf77/proset", "max_stars_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_stars_repo_licenses": ["MIT"], "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/about.tex", "max_issues_repo_name": "NRuf77/proset", "max_issues_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_issues_repo_licenses": ["MIT"], "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/about.tex", "max_forks_repo_name": "NRuf77/proset", "max_forks_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_forks_repo_licenses": ["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.7572815534, "max_line_length": 243, "alphanum_fraction": 0.7888316151, "num_tokens": 3962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.636306764494387}}
{"text": "% Chapter X\n\n\\chapter{Creating models} % Chapter title\n\n\\label{Creating models} % For referencing the chapter elsewhere, use \n\nThe previous section described the basic building blocks of Figaro models. Out of these building blocks, a wide variety of models can be created. This section describes how to build a range of models.\n\n\\section{Basic models}\n\nOne of the first things you can do with an element is to assign it to a Scala value:\n\n\\begin{flushleft}\n\\texttt{val burglary = Flip(0.01)}\n\\end{flushleft}\n\n\\marginpar{\\texttt{val} in Figaro represents an immutable value. When a thing is assigned to a val, data inside the thing can change but the reference stored in the val is constant}\n\nA \\texttt{val} represents a field (in this case burglary) that takes on an immutable value (in this case the element \\texttt{Flip(0.01)}). A field is not a variable; its value cannot be changed (Note that the scala assignment of the field \\texttt{burglary} cannot change, but the value of the Figaro element that is assigned to it, \\texttt{Flip(0.01)}, \\emph{can} change). You can use the value of a field by referring to its name:\n\n\\begin{flushleft}\n\\texttt{val alarm = If(burglary, Flip(0.9), Flip(0.1))}\n\\end{flushleft}\n\nRecall that an element defines a process that probabilistically produces a value. If an element is referred to multiple times, it must produce the same value everywhere it appears. Consider:\n\n\\begin{flushleft}\n\\texttt{val x = Flip(0.5)\n\\newline val y = x === x}\n\\end{flushleft}\n\nAlthough we don't know the value, \\texttt{x} must produce the same value on both sides of the equality test. Therefore, \\texttt{y} produces the value \\texttt{true} with probability 1. In contrast, in\n\n\\begin{flushleft}\n\\texttt{val y = Flip(0.5) === Flip(0.5)}\n\\end{flushleft}\n\nthe left and right hand sides are distinct elements (each call produces a new \\texttt{Flip}), so they need not produce the same value. Therefore, \\texttt{y} will produce \\texttt{true} with probability 0.5.\n\nWith the tools we have defined so far, we can easily create a Bayesian network. In the following code, \\texttt{CPD} is a library element (based on \\texttt{Chain}) that makes it easy to define conditional probability distributions:\n\n\\begin{flushleft}\n\\marginpar{This example is found in Burglary.scala}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline import com.cra.figaro.library.compound.CPD\n\\newline\n\\newline val burglary = Flip(0.01)\n\\newline\n\\newline val earthquake = Flip(0.0001)\n\\marginpar{Scala statements can be written on multiple lines}\n\\newline\n\\newline val alarm = CPD(burglary, earthquake,\n\\newline \\tab (false, false) -> Flip(0.001),\n\\newline \\tab (false, true) -> Flip(0.1), \n\\newline \\tab (true, false) -> Flip(0.9), \n\\newline \\tab (true, true) -> Flip(0.99))\n\\newline \n\\newline val johnCalls = CPD(alarm,\n\\newline \\tab false -> Flip(0.01),\n\\newline \\tab true -> Flip(0.7))}\n\\end{flushleft}\n\nWith \\texttt{CPD}, every single combination of values of the parents needs to be listed. \\texttt{RichCPD} provides a more flexible format that allows for specification of structures such as context specific independence. Each clause in a \\texttt{RichCPD} consists of a tuple of cases, one for each parent. A case can be \\texttt{OneOf} a set of values, \\texttt{NoneOf} a set of values (meaning that it matches all values except for the ones listed), or *, meaning that it accepts all values. For example:\n\n\\begin{flushleft}\n\\texttt{import com.cra.figaro.language.\\_}\n\\newline \\texttt{import com.cra.figaro.library.compound.RichCPD}\n\\newline \\texttt{val x1 = Select(0.1 -> 1, 0.2 -> 2, 0.3 -> 3, 0.4 -> 4)}\n\\newline \\texttt{val x2 = Flip(0.6) \n\\newline val x3 = Constant (5) \n\\newline val x4 = Flip(0.8)\n\\newline val y = RichCPD(x1, x2, x3, x4,\n\\newline \\tab (OneOf(1, 2), *, OneOf(5), *) -> Flip(0.1), \n\\newline \\tab (NoneOf(4), OneOf(false), *, *) -> Flip(0.7), \n\\newline \\tab (*, *, NoneOf(6, 7), OneOf(true)) -> Flip(0.9), \n\\newline \\tab (*, *, *, OneOf(false)) -> Constant (true))}\n\\end{flushleft}\n\nA particular combination of values of the parents is matched against each row in turn, and the first match is chosen. For example, the combination (1, false, 5, true) matches the first three rows, so the first result (\\texttt{Flip(0.1)}) is chosen. All possible values of the parent still need to be accounted for in the argument list using a combination of \\texttt{OneOf}, \\texttt{NoneOf} and *.\n\n\\section{Conditions and constraints}\n\nSo far, we have described models that generate the values of elements. It is also possible to influence the values of elements by imposing conditions or constraints on them.\n\nA \\emph{condition} represents something the value of the element must satisfy. Only values that satisfy the condition are possible. Every element has a condition, which is a function from a value of the element to a Boolean. If the element is of type \\texttt{Element[T]}, the condition is of type \\texttt{T => Boolean}. Conditions can have multiple purposes. One is to assert evidence, by specifying something that is known about an element. Alternatively, a condition can specify a structural property of a model, for example, that only one of two teams playing a game can be the winner.\n\nThe default condition of an element returns true for all values. The condition can be changed using \\texttt{setCondition}:\n\n\\begin{flushleft}\n\\texttt{val x1 = Select(0.1 -> 1, 0.2 -> 2, 0.3 -> 3, 0.4 -> 4)\nx1.setCondition((i: Int) => i == 1 || i == 4)}\n\\end{flushleft}\n\nwhich says that \\texttt{x1} must have value 1 or 4. We can add a condition on top of existing conditions using the \\texttt{addCondition} method. For example, the following code says that not only must \\texttt{x1} equal 1 or 4, it must also be odd:\n\n\\begin{flushleft}\n\\texttt{x1.addCondition((i: Int) => i \\% 2 == 1)}\n\\end{flushleft}\n\nThe \\texttt{observe} method provides an easy way to specify a condition that only allows a single value. For example, to specify that \\texttt{x1} must have the value 2, we can use\n\n\\begin{flushleft}\n\\texttt{x1.observe(2)}\n\\end{flushleft}\n\nNote that using \\texttt{observe} will remove all previous conditions on an element.\n\nA \\emph{constraint} provides a way to specify a potential or weighting over an element. It is a function from a value of the element to a Double, so if the element has type \\texttt{Element[T]}, the constraint is of type \\texttt{T => Double}.\n\nConstraints serve multiple purposes in Figaro. One is to specify soft evidence on an element. For example, if in the above Bayesian network we think we heard John call but we're not sure, we might introduce the constraint\n\n\\begin{flushleft}\n\\texttt{johnCalls.setConstraint((b: Boolean) => \n\\newline \\tab if (b) 1.0; else 0.1)}\n\\end{flushleft}\n\nThis line will have the effect of making John calling 10 times more likely than not, all else being equal. Another purpose of constraints is to define some probabilistic relationships conveniently that are more difficult to express without them. Consider the following example, in which we are modeling the process of firms bidding for a contract and one of them being selected as the winner.\n\n\\begin{flushleft}\n\\marginpar{This example is found in Firms.scala}\n\\texttt{import com.cra.figaro.language.\\_}\n\\newline \\texttt{import com.cra.figaro.library.atomic.\\_}\n\\newline \\texttt{import com.cra.figaro.library.compound.If}\n\\newline\n\\newline \\texttt{class Firm \\{\n\\newline \\tab val efficient = Flip(0.3)\n\\newline \\tab val bid = If(efficient, continuous.Uniform(5, 15),\n\\newline continuous.Uniform(10, 20))\n\\newline \\} \n\\newline\n\\newline \\texttt{val firms = Array.fill(20)(new Firm)\n\\newline val winner = discrete.Uniform(firms:\\_*)\n\\newline val winningBid = Chain(winner, (f: Firm) => f.bid)\n\\newline winningBid.setConstraint((d: Double) => 20 $-$ d)}\n}\n\\end{flushleft}\n\nThis example shows some new Scala features. First, we have a class definition (the \\texttt{Firm} class). A class creates a type that can be instantiated to create instances. The \\texttt{Firm} class has two fields, \\texttt{efficient} and \\texttt{bid}. Note that bid makes use of \\texttt{continuous.Uniform}. This is the continuous uniform element defined in the \\texttt{library.atomic.continuous} package, but we did not import the members of this package, only the members of the \\texttt{library.atomic} package. The reason we did things this way is that later in the example, we use the discrete uniform, and we want to be explicit about which uniform element we mean at each point.\n\nOnce we have defined the \\texttt{Firm} class, we create an array named \\texttt{firms} consisting of 20 instances of \\texttt{Firm.Array.fill(20)(new Firm)} creates an array filled with the result of 20 different invocations of \\texttt{new Firm}, each of which creates a separate instance of  \\texttt{Firm} (and separate Figaro elements in each class). We then define the winner to be one of the firms, chosen uniformly. Note the notation \\texttt{firms:\\_*.} The element \\texttt{discrete.Uniform} takes as arguments an explicit sequence of values of variable length, for example, \\texttt{discrete.Uniform(1, 2, 5)} or \\texttt{discrete.Uniform(\"x\")}. Since \\texttt{firms} is a single field representing an array, we must convert it into a sequence of arguments, which is accomplished using the \\texttt{:\\_*} notation. The field \\texttt{winner} represents an \\texttt{Element[Firm]}; it is intended to mean the winning bidder, although so far we have done nothing to relate the winner to its bid.\n \nThe next line is interesting. It allows us to identify the bid of the winning bidder as an element with a name, even though we don't know who the winner is. We can do this because even though we don't know who the winner is, we can refer to the \\texttt{winner} field, and because the value of \\texttt{winner}, whatever it is, is a \\texttt{Firm} that has a \\texttt{bid} field, which is an element that can be referred to. It is important to realize that this \\texttt{Chain} does not create a new element but rather refers to the element \\texttt{f.bid} that was created previously.\n\nFinally, we introduce the constraint, which says that a winning bid of d has weight \\texttt{20 $-$ d}. This means that a winning bid of 5 is 15 times more likely than a winning bid of 19. The effect is to make the winning bid more likely to be low. Note that in this model, the winning bid is not necessarily the lowest bid. For various reasons, the lowest bidder might not win the contract, perhaps because they offer a poor quality service or they don't have the right connections. Using a constraint, the model is specified very simply using a discrete uniform selection and a simple constraint.\n\nConstraints are also useful for expressing undirected models such as relational Markov networks or Markov logic networks. To illustrate, we will use a version of the friends and smokers example. This example involves a number of people and their smoking habits. People have some propensity to smoke, and people are likely to have the same smoking habit as their friends.\n\n\\begin{flushleft}\n\\marginpar{This example is found in Smokers.scala}\n\\texttt{import com.cra.figaro.language.Flip\n\\newline import com.cra.figaro.library.compound.\\textasciicircum \\textasciicircum\n\\newline \n\\newline class Person \\{\n\\newline \\tab val smokes = Flip(0.6) \n\\newline \\} \n\\newline \n\\newline val alice, bob, clara = new Person\n\\newline val friends = List((alice, bob), (bob, clara))\n\\newline clara.smokes.observe(true) \n\\newline\n\\marginpar{Single line function definitions in Scala do not need bracketing}\n\\newline def smokingInfluence(pair: (Boolean, Boolean)) = \n\\newline \\tab if (pair.\\_1 == pair.\\_2) 3.0; else 1.0\n\\newline\n\\newline for \\{ (p1, p2) <- friends \\} \\{\n\\newline \\tab \\textasciicircum \\textasciicircum(p1.smokes, p2.smokes).setConstraint(smokingInfluence)\n\\newline \\} }  \n\\end{flushleft}\n\nFirst, we create a \\texttt{Person} class with a \\texttt{smokes} field. We create three different people and a network of friends, represented by a list of pairs of people. We also observe that one of the people smokes.\n\nNow we create the constraint function \\texttt{smokingInfluence}. This function takes a pair of Booleans, and returns 3.0 if they are the same, 1.0 if different. The intended meaning of this function is to compare the smoking habit of two friends, and say that having the same smoking habit is three times as likely as a different smoking habit, all else being equal.\n\nFinally, we apply the constraint to all the pairs of friends. The code uses a Scala feature called a \"for comprehension\". The notation for \\texttt{\\{ (p1, p2) <- friends \\}} { \"do something\" } iterates through all pairs of people in the \\texttt{friends} list and executes \"do something\" for each pair. In this case, \"do something\" is \"add the constraint on their smoking habits to the pair of friends\". The notation \\texttt{\\textasciicircum \\textasciicircum(p1.smokes, p2.smokes)} takes each pair of friends and creates the pair element consisting of their smoking habits. We then assign the \\texttt{smokingInfluence} constraint to this pair.\n\n\\section{Classes, instances, and relationships}\n\nThe object-oriented nature of Scala makes Figaro ideal for representing probabilistic models involving objects and relationships such as probabilistic relational models (PRMs). \nIn the following example, we will see how to define general classes of object, and create instances of a class by using a subclass of the class specially designed for the instance.\n\nIn this example, we are given two possible sources and a sample that came from one of the sources, and want to determine which source the sample came from based on the strength of the match with each\nsource.\n\n\\begin{flushleft}\n\\marginpar{Abstract classes in Scala are similar as in Java; they cannot be instantiated}\n\\texttt{class Source(val name: String)\n\\newline\n\\newline abstract class Sample \\{\n\\newline \\tab val fromSource : Element[Source] \n\\newline \\}\n\\newline\n\\newline class Pair(val source: Source, val sample: Sample) \\{\n\\newline \\tab val isTheRightSource = Apply(sample.fromSource, (s: Source) => s == source)\n\\newline \\tab val distance = If(isTheRightSource, \n\\newline \\tab Normal(0.0, 1.0), \n\\newline \\tab Uniform(0.0, 10.0))\n\\newline \\}\n\\newline\n\\marginpar{Defining class contents at instantiation time will override undefined values}\n\\newline val source1 = new Source(\"Source 1\") \n\\newline val source2 = new Source(\"Source 2\") \n\\newline val sample1 = new Sample \\{ \n\\newline val fromSource = Select(0.5 -> source1, 0.5 -> source2)\n\\newline \\}\n\\newline val pair1 = new Pair(source1, sample1)\n\\newline val pair2 = new Pair(source2, sample1)\n\\newline \n\\newline pair1.distance.setCondition((d:Double) => (d > 0.15 \\&\\& d < 0.25))\n\\newline pair2.distance.setCondition((d:Double) => (d > 1.45 \\&\\& d < 1.55)) }\n\\end{flushleft}\n\nWe begin by creating classes representing sources and samples, where each sample comes from a source. Note that \\texttt{Sample} is an abstract class, because in this class we do not say anything about what source the sample came from (the from \\texttt{Source} field has not been assigned an \\texttt{Element[Source]} yet). We then create the \\texttt{Pair} class representing a pair of a source and a sample. \\texttt{Pair} has two fields: \\texttt{isTheRightSource}, which produces true if the sample is from the source in the pair, and \\texttt{distance}, which measures the closeness of the match between the sample and the source (lower distance means better match). The distance will tend to be smaller if the sample is from the right source but will not always be so.\n\nNow it's time to create some instances. Note that the \\texttt{Source} class takes an argument which is the name of the source. When we create instances \\texttt{source1} and \\texttt{source2} of this class, we supply the name argument. Next, we create an instance of \\texttt{Sample}. Since \\texttt{Sample} is abstract, we need to supply a definition of \\texttt{fromSource}. We can do that right in line here, specifying that \\texttt{sample1} could come either from \\texttt{source1} or \\texttt{source2}, each with probability 0.5. Finally, we create pairs pairing both of the sources to \\texttt{sample1} and create conditions about the distances. The conditions are ranges rather than exact observations because exact observations on continuous elements can be problematic for many types of inference algorithms.\n\nUsing similar techniques, we can create a PRM. The following example shows the classical actors and movies PRM. There are three classes: actors, movies, and appearances relating actors to movies. Whether an actor receives an award for an appearance depends on the fame of the actor and the quality of the movie. The Figaro code for this example is as follows:\n\n\\begin{flushleft}\n\\marginpar{This example can be found in SimpleMovie.scala}\n\\texttt{import com.cra.figaro.library.compound.CPD\n\\newline import com.cra.figaro.language.\\_\n\\newline\n\\newline class Actor \\{\n\\newline \\tab val famous = Flip(0.1)\n\\newline \\}\n\\newline\n\\newline class Movie \\{\n\\newline \\tab val quality = Select(0.3 -> 'low, 0.5 -> 'medium, 0.2 -> 'high)\n\\newline \\}\n\\newline\n\\marginpar{The ' in front of a string creates a Scala symbol, which are treated like \\texttt{String} constants}\n\\newline class Appearance(actor: Actor, movie: Movie) \\{\n\\newline \\tab def probAward(quality: Symbol, famous: Boolean) = \n\\newline \\tab  \\tab  (quality, famous) match \\{ \n\\newline \\tab \\tab  case ('low, false) => 0.001\n\\newline \\tab \\tab  case ('low, true) => 0.01 \n\\newline \\tab \\tab  case ('medium, false) => 0.01\n\\newline \\tab \\tab  case ('medium, true) => 0.05\n\\newline \\tab \\tab  case ('high, false) => 0.05\n\\newline \\tab \\tab  case ('high, true) => 0.2\n\\newline \\tab \\tab \\}\n\\newline \\tab  val award = SwitchingFlip(Apply(movie.quality, actor.famous, (q: Symbol, f: Boolean) => probAward(q, f)))\n\\newline \\}\n\\newline\n\\newline val actor1 = new Actor \n\\newline val actor2 = new Actor \n\\newline val actor3 = new Actor \n\\newline val movie1 = new Movie \n\\newline val movie2 = new Movie\n\\newline val appearance1 = new Appearance(actor1, movie1) \n\\newline val appearance2 = new Appearance(actor2, movie2) \n\\newline val appearance3 = new Appearance(actor3, movie2) \n\\newline actor3.famous.observe(true) \n\\newline movie2.quality.observe('high)\n\\newline \n\\marginpar{The \\texttt{\\_.award} notation is Scala shorthand to retrieve the award value of each element of the map}\n\\newline // Ensure that exactly one appearance gets an award. \n\\newline def uniqueAwardCondition(awards: List[Boolean]) =\n\\newline \\tab awards.count((b: Boolean) => b) == 1\n\\newline val allAwards: Element[List[Boolean]] = \n\\newline \\tab Inject(appearances.map(\\_.award):\\_*)\n\\newline allAwards.setCondition(uniqueAwardCondition)}\n\\end{flushleft}\n\nThe code is self-explanatory except for the last few lines, which enforce the condition that an award is given to exactly one appearance. The function \\texttt{uniqueAwardCondition} takes a list of award Booleans and returns true if exactly one Boolean in the list is true. The count method counts the number of elements in the list that satisfy the predicate contained in its argument. In this case the predicate is \\texttt{(b: Boolean) => b} which is true precisely when the element of the list is true. So \\texttt{awards.count((b: Boolean) => b)} counts the number of elements in the list that are true.\n\nWe then define the \\texttt{allAwards} element to be the element over lists of Booleans consisting of the award field of all the appearances.  Here we have a new notation: \\texttt{appearances.map(\\_.award)}. We have already seen the \\texttt{map} method, which applies a function to every element of a list and returns a new list consisting of the results. In this case, the argument to map is the function \\texttt{\\_.award}. This is shorthand for a function of one argument in which the argument appears once in the body and in which the type of the argument is known. Here, the type of the argument is clearly an appearance. We could have used \\texttt{appearance => appearance.award}. The notation \\texttt{\\_.award} is short for this. Finally, we impose the \\texttt{uniqueAwardCondition} on \\texttt{allAwards}, ensuring that exactly one appearance is awarded.\n\n\\section{Mutable fields}\n\nUp to this point, all our Figaro programs have been purely functional. All elements have been defined by a \\texttt{val}, and they have been immutable. In principle, all programs can be written in a purely functional style. However, this can make it quite inconvenient to represent situations in which different entities refer to each other. Scala supports both functional and non-functional styles of programming, allowing us to gain the benefits of both.\n\nFor example, let's expand the actors and movies example so that actors have a skill, and the quality of a movie depends on the skill of the actors in it. In turn, the fame of an actor depends on the quality of the movies in which he or she has appeared. We have created a mutual dependence of actors on movies which is hard to represent in a purely functional style. We can capture it in Figaro using the following code:\n\n\\begin{flushleft}\n\\marginpar{This example can be found in MutableMovie.scala}\n\\texttt{import com.cra.figaro.library.compound.CPD\n\\newline import com.cra.figaro.language.\\_\n\\newline \n\\newline class Actor \\{\n\\newline \\tab var movies: List[Movie] = List()\n\\newline \\tab lazy val skillful = Flip(0.1)\n\\newline \\tab lazy val famous =\n\\newline \\tab Flip(Apply(Inject(movies.map(\\_.quality):\\_*), probFamous \\_))\n\\newline \\tab private def probFamous(qualities: Seq[Symbol]) =\n\\newline \\tab if (qualities.count(\\_ == 'high) >= 2) 0.8; else 0.1\n\\newline \\}\n\\newline \n\\newline class Movie \\{\n\\newline \\tab var actors: List[Actor] = List()\n\\newline \\tab lazy val actorsAllGood = Apply(Inject(actors.map(\\_.skillful):\\_*), (s: Seq[Boolean]) => !(s.contains(false)))\n\\newline lazy val probLow = \n\\newline Apply(actorsAllGood, (b: Boolean) => if (b) 0.2; else 0.5)\n\\newline lazy val probHigh = \n\\newline Apply(actorsAllGood, (b: Boolean) => if (b) 0.5; else 0.2)\n\\newline lazy val quality = \n\\newline Select(probLow -> 'low, Constant(0.3) -> 'medium, probHigh -> 'high)\n\\newline \\}\n\\newline \n\\newline class Appearance(actor: Actor, movie: Movie) \\{\n\\newline \\tab actor.movies ::= movie\n\\marginpar{\\texttt{::=} is Scala shorthand for list concatenation}\n\\newline \\tab movie.actors ::= actor\n\\newline \n\\newline \\tab def probAward(quality: Symbol, famous: Boolean) =\n\\newline \\tab \\tab (quality, famous) match \\{\n\\newline \\tab \\tab case ('low, false) => 0.001\n\\newline \\tab \\tab case ('low, true) => 0.01\n\\newline \\tab \\tab case ('medium, false) => 0.01\n\\newline \\tab \\tab case ('medium, true) => 0.05\n\\newline \\tab \\tab case ('high, false) => 0.05\n\\newline \\tab \\tab case ('high, true) => 0.2\n\\newline \\tab \\tab \\}\n\\newline \\tab lazy val award = SwitchingFlip(Apply(movie.quality, actor.famous, (q: Symbol, f: Boolean) => probAward(q, f)))\n\\newline \\}\n\\newline \n\\newline val actor1 = new Actor \n\\newline val actor2 = new Actor \n\\newline val actor3 = new Actor \n\\newline val movie1 = new Movie \n\\newline val movie2 = new Movie\n\\newline val appearance1 = new Appearance(actor1, movie1)\n\\newline val appearance2 = new Appearance(actor2, movie2) \n\\newline val appearance3 = new Appearance(actor3, movie2) \n\\newline actor3.famous.observe(true) \n\\newline movie2.quality.observe('high)\n\\newline \n\\newline // Ensure that exactly one appearance gets an award. \n\\newline def uniqueAwardCondition(awards: List[Boolean]) =\n\\newline \\tab awards.count((b: Boolean) => b) == 1 \n\\newline val allAwards: Element[List[Boolean]] =\n\\newline \\tab Inject(appearances.map(\\_.award):\\_*)\n\\newline allAwards.setCondition(uniqueAwardCondition)\n}\n\\end{flushleft}\n\nFirst, note that the \\texttt{Actor} class has a \\texttt{movies} field, whose purpose is to indicate the list of movies the actor has appeared in. Likewise, the \\texttt{Movie} class has an \\texttt{actors} field to represent the actors who appear in it. If these fields were immutable, we would need to create all the movies an actor appears in before we create the actor, and we would need to create all the actors appearing in a movie before the movie, which is impossible. Therefore, we use mutable variables, which are indicated in Scala by the \\texttt{var} keyword.\n\nThe initial value of both \\texttt{movies} and \\texttt{actors} is an empty list. We add elements to them later. In fact, whenever we create an appearance, we make sure to add the movie to the actor's list of movies and vice versa. This is achieved by the first two lines of the \\texttt{Appearance} class. The notation \\texttt{actor.movies ::= movie} is short for \\texttt{actor.movies = movie :: actor.movies}, which prepends movie to the current \\texttt{actor.movies} list, and replaces the current list with the new list. The \\texttt{::=} notation is a variant of the familiar \\texttt{+=} notation common in many languages.\n\nThe \\texttt{Actor} class has \\texttt{skillful} and \\texttt{famous} fields. Rather than an ordinary \\texttt{val}, each of these fields is defined to be \\texttt{lazy val}, which means that their contents are not determined until they are required by some other computation. This is necessary for us because their contents can depend on the list of movies the actor appears in. For example, whether the actor is famous depends on whether at least two movies have high quality, as defined by \\texttt{probFamous}. (Comment on the notation: the underscore after \\texttt{probFamous} is required here to tell Scala that what is desired is the \\texttt{probFamous} function itself, not its application to arguments.)   If \\texttt{famous} was an ordinary \\texttt{val}, its value (an \\texttt{Element[Boolean]}) would be computed at the point it is defined, so it would use an empty list of movies. Because we want to use the correct list of movies in defining it, we postpone evaluating it until the movies list has been filled. For \\texttt{actor3}, this will happen when we make the observation \\texttt{actor3.famous.observe(true)}, which we make sure to delay until after all the appearances have been created. For other actors, the \\texttt{famous} field will be evaluated even later, during inference. Care should be taken with declaring elements as lazy. Side effects and unintended consequences can occur if a lazy element declared outside a Chain is first required (i.e., created) during the execution of a Chain.\n\nDo not hesitate to use mutation if it will help you organize your program in a logical way. In one application, we have found it convenient to use a hash table that maps concepts to their associated elements. This allowed us to create the element associated with a concept as the concept was introduced. If we later had to refer to the same concept again, we could easily access its element.\n\n\\section{Universes}\n\nA central concept in Figaro is a \\emph{universe}. A universe is simply a collection of elements. Reasoning algorithms operate on a universe (or, as we shall see for dependent universe reasoning, on multiple connected universes). Most of the time while using Figaro, you will not need to create a new universe and can rely on the default universe, which is just called \\texttt{universe}. It can be accessed using\n\n\\begin{flushleft}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline import com.cra.figaro.language.Universe.\\_}\n\\end{flushleft}\n\nIf you do need a different universe, you can call \\texttt{Universe.create\\-New()}. This creates a new universe and sets the default universe to it. If you are going to need the old default universe, you will need a way to refer to it. You could use\n\n\\begin{flushleft}\n\\texttt{val u1 = Universe.universe\n\\newline val u2 = Universe.createNew()}\n\\end{flushleft}\n\n\\texttt{u1} will now refer to the old default universe while \\texttt{u2} refers to the new one. Every element belongs to exactly one universe. Ordinarily, when an element is created, it is assigned to the current default universe. As we will see below when we talk about element collections, it is possible to assign a particular element to a different universe from the current default.\n\nElements can be activated or deactivated. Elements that are inactive are not operated on by reasoning algorithms. Elements are active when created. To deactivate an element \\texttt{e} use \\texttt{e.deactivate()}; to reactivate it, use \\texttt{e.activate()}. When a compound element is created that uses a parent element, the parent must already be active.\n\nYou can get a list of all active elements in universe \\texttt{u} using \\texttt{u.active\\-Elements}. There are many more methods of a universe that are useful for writing reasoning algorithms. See the documentation in Universe.scala for more details.\n\n\\section{Names, element collections, and references}\n\nSuppose we want to create a PRM in which we are uncertain about the value of an attribute whose value is itself an instance of another class (which is called reference uncertainty). For example, suppose we have the following classes and instances:\n\n\\begin{flushleft}\n\\marginpar{This example can be found in CarAndEngine.scala}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline \n\\newline abstract class Engine \\{ val power : Element[Symbol] \\}\n\\newline class V8 extends Engine \\{\n\\newline \\tab val power = Select(0.8 -> 'low, 0.2 -> 'high) \n\\newline \\}\n\\newline class V6 extends Engine \\{\n\\newline \\tab val power = Select(0.8 -> 'low, 0.2 -> 'high)\n\\newline \\}\n\\newline \n\\newline object MySuperEngine extends V8 \\{\n\\newline \\tab val power = Constant('high)\n\\newline \\}\n\\newline class Car \\{\n\\newline \\tab val engine = Uniform[Engine](new V8, new V6, MySuperEngine)\n\\newline \\tab val speed = CPD(?,\n\\newline \\tab 'high -> Constant(90.0),\n\\newline \\tab 'medium -> Constant(80.0),\n\\newline \\tab 'low -> Constant(70.0))\n\\newline \\}\n}\n\\end{flushleft}\n\nWe want the speed of the car to depend on the power of its engine, but we have uncertainty over what the engine actually is. What should we put in place of the question mark? The obvious choice is \\texttt{engine.power}, but this does not work because engine is an \\texttt{Element\\-[Engine]}, not an instance of \\texttt{Engine}.\n\nTo get around this problem, Figaro provides \\emph{names} and \\emph{element collections}. Every element has a name and belongs to an element collection. By default, the name is the empty string and the element collection is the default universe at the time the element is created, which works because universes are element collections. So, most of the time, as in the tutorial to this point, you don't have to worry about the name and element collection of an element. To assign a name and element collection to an element explicitly, you provide an extra pair of arguments when creating it.\n\nWe can give the engine a name and make it belong to the car as an element collection as follows:\n\n\\begin{flushleft}\n\\texttt{class Car extends ElementCollection \\{\n\\newline \\tab val engine = Uniform[Engine](new V8, new V6, MySuperEngine)(\"engine\", this)\n\\newline \\}\n}\n\\end{flushleft}\n\nIn the first line we make the \\texttt{Car} class inherit from \\texttt{ElementCollect\\-ion}, so that every instance of \\texttt{Car} is an element collection. In the fourth line, we assign engine the name \"engine\" and add it to the instance of Car being created, which is referred to by \\texttt{this} within the \\texttt{Car} class. We similarly make the abstract \\texttt{Engine} class inherit  element collections and assign \\texttt{power} the name \"power\" within \\texttt{V*, V6, and MySuperEngine} within each subclass of  \\texttt{Engine}.\n\nAn element collection, like a universe, is simply a set of elements. The difference is that a universe is also a set of elements on which a reasoning algorithm operates. An element collection provides the ability to refer to an element by name. For example, if \\texttt{car} is an instance of \\texttt{Car}, we can use \\texttt{car.get[Engine](\"engine\")} to get at the element named \"engine\". The \\texttt{get} method takes a type parameter, which is the value type of the element being referred to. The notation \\texttt{[Engine]} specifies this type parameter, and serves to make sure that the expression \\texttt{car.get[Engine](\"engine\")} has type \\texttt{Element[Engine]}.\n\nThe key ability of element collections that allows them to solve our puzzle is their ability to get at elements embedded in the value of an element.  It uses \\emph{references} to do this. A reference is a series of names separated by dots. For example, \"engine.power\" is a reference. When we call \\texttt{car.get[Symbol](\"engine.power\")}, it refers to the element named \"power\" within the \\emph{value} of the element named \"engine\" within the car. The value of this expression is a \\texttt{ReferenceElement} that captures the uncertainty about which power element is actually being referred to. In a particular state of the world, i.e., an assignment of values to all elements, it is possible to determine the value of engine and therefore which \\texttt{power} element is being referred to. So a \\texttt{ReferenceElement} is a deterministic element that defines a way to get its value in any possible world.\n\nSo, finally, the answer to our puzzle is that in place of the question mark, we put \\texttt{get[Symbol](\"engine.power\")}. This applies the get method to the instance of \\texttt{Car} being created. Here is the full example:\n\n\\begin{flushleft}\n\\marginpar{This example can be found in MultiValuedReferenceUncertainty.scala}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline\n\\newline abstract class Engine extends ElementCollection \\{\n\\newline \\tab val power : Element[Symbol]\n\\newline \\}\n\\newline class V8 extends Engine \\{\n\\newline \\tab val power = Select(0.8 -> 'low, 0.2 -> 'high)(\"power\", this)\n\\newline \\}\n\\newline class V6 extends Engine \\{\n\\newline \\tab val power = Select(0.8 -> 'low, 0.2 -> 'high)(\"power\", this)\n\\newline \\}\n\\newline object MySuperEngine extends V8 \\{\n\\newline \\tab val power = Constant('high)(\"power\", this)\n\\newline \\}\n\\newline class Car extends ElementCollection \\{\n\\newline \\tab val engine = Uniform[Engine](new V8, new V6, MySuperEngine)(\"engine\", this)\n\\newline \\tab val speed = CPD(\n\\newline \\tab get[Symbol](\"engine.power\"),\n\\newline \\tab 'high -> Constant(90.0),\n\\newline \\tab 'medium -> Constant(80.0),\n\\newline \\tab 'low -> Constant(70.0))\n\\newline )\n\\newline \\}\n}\n\\end{flushleft}\n\n\\section{Multi-valued references and aggregates}\n\nThe previous subsection described how to refer to elements using references that identify a single element. A feature of PRMs is the ability to define multi-valued relationships, where an entity is related to multiple entities via an attribute. In Figaro, we use multi-valued references and aggregates to capture these kinds of situations. For example:\n\n\\begin{flushleft}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline \n\\newline class Component extends ElementCollection \\{\n\\newline \\tab val f = Select(0.2 -> 2, 0.3 -> 3, 0.5 -> 5)(\"f\", this)\n\\newline \\}\n\\newline \n\\newline val specialComponent1 = new Component \n\\newline val specialComponent2 = new Component\n\\newline \n\\newline def makeComponent() =\n\\newline \\tab Select(0.1 -> specialComponent1,\n\\newline \\tab 0.2 -> specialComponent2,\n\\newline \\tab 0.7 -> new Component)\n\\newline \n\\newline class Container extends ElementCollection \\{\n\\newline \\tab  val components = MakeList(Select(0.5 -> 1, 0.5 -> 2), makeComponent)(\"components\", this)\n\\newline \n\\marginpar{The body of the sum function is shorthand notation for Scala's fold function. Fold iterates through a sequence and applies a function to the previous\nresult and each new entry in turn. The (\\_ + \\_ ) notation will add the previous value to each value in \\texttt{xs}.}\n\\newline val sum = getAggregate((xs: MultiSet[Int]) => (0 /: xs)(\\_ + \\_))(\"components.f\") \n\\newline \\}\n}\n\\end{flushleft}\n\nFirst, we create a \\texttt{Component} class with an element named \"f\". We then define two specific instances of \\texttt{Component}. Next, we define a \\texttt{makeComponent} function that either produces one of the specific instances or a new instance of \\texttt{Component} that is distinct from all other instances. We then define a \\texttt{Container} class that contains components. Now, the contained components are a list that has either one or two elements, each produced by \\texttt{makeComponent}. We then create a \\texttt{sum} element that aggregates the values of all elements referred to by \"components.f\"; that is, the values of the elements named \"f\" in all the values of the element named \"components\".\n\nMulti-valued references have \"set semantics\". If the same element appears more than once as the target of the reference, it only contributes one value to the aggregate. So, if the components list has two components, both of which are \\texttt{specialComponent1}, whose value is 2, the value of the aggregate will be 2, not 4. On the other hand, if two different target elements both have the same value, both values contribute to the aggregate. For example, if the components are \\texttt{specialComponent1} and \\texttt{specialComponent2}, and both have value 2, the value of the aggregate is 4.\n\nA comment on the code: The code defining \\texttt{sum} might look mysterious. This code takes a list of integers and returns their sum. This is a standard Scala idiom that unfortunately is a bit obscure if you're not familiar with it. It is used to \"fold\" a function through a list. We begin with 0 and then repeatedly add the current result to the next element of the list until the list is exhausted. The notation \\texttt{(\\_ + \\_)} is shorthand for the function that takes two arguments and adds them. The notation \\texttt{(0 /: xs}) means that this function should be folded through \\texttt{xs}, starting from 0.\n\n\\section{Open Universe Models}\n\nWe close this section by showing how Figaro can be used to represent \"open universe\" situations. An open universe situation is one in which we don't know what objects are there, how many there are, which objects are the same as which other objects, and so on. In our example situation, there are an unknown number of sources that is geometrically distributed. Each source is uniformly distributed between 0 and 1. There is some number of observed samples, each drawn from a single unknown source. This is the classic data association problem in which we want to determine which sample comes from which source, and in particular which two samples actually come from the same source. The Figaro code for the example is as follows:\n\n\\begin{flushleft}\n\\marginpar{This example can be found in OpenUniverse.scala}\n\\texttt{import com.cra.figaro.language.\\_\n\\newline import com.cra.figaro.library.atomic.continuous.Uniform \n\\newline import com.cra.figaro.library.atomic.continuous.Normal \n\\newline import com.cra.figaro.library.atomic.discrete.Geometric \n\\newline import com.cra.figaro.library.compound.\\{MakeList, IntSelector\\}\n\\newline \n\\newline def source(): Element[Double] = Uniform(0.0, 1.0)\n\\newline \n\\newline val numSources = Geometric(0.9)\n\\newline \n\\newline val sources = MakeList(numSources, source \\_)\n\\newline \n\\newline class Sample \\{\n\\newline \\tab val sourceNum = IntSelector(numSources)\n\\newline \\tab val source =\n\\newline \\tab Apply(sources, sourceNum, (s: Seq[Double], i: Int) => s(i))\n\\newline \\tab val position =\n\\newline \\tab NonCachingChain(source, (x: Double) => Normal(x, 1.0))\n\\newline \\}\n\\newline \n\\newline val sample1 = new Sample \n\\newline val sample2 = new Sample\n\\newline \n\\newline val equal = sample1.source === sample2.source \n\\newline \n\\newline sample1.position.addCondition((y: Double) => y >= 0.7 \\&\\& y < 0.8)\n\\newline sample2.position.addCondition((y: Double) => y >= 0.7 \\&\\& y < 0.8) \n}\n\\end{flushleft}\n\nMost of this should be self-explanatory at this point. There are a couple of interesting new element classes being used. \\texttt{MakeList} takes an element over integers and a function that generates elements over a certain type (in this case doubles). It returns an element over lists of the appropriate type (in this case lists of doubles) whose length is distributed according to the first argument and in which each element is generated according to the second argument. In our example, \\texttt{sources} is a list of sources whose length is geometrically distributed and in which each source is generated according to the source model. A notable aspect of the \\texttt{MakeList} class, which is important for reasoning algorithms, is that the elements generating the values in the list are stored as an infinite lazy stream. Depending on the value of the first argument, the value of the \\texttt{MakeList} is a finite prefix of the values of elements in the stream. As a result of this design, we don't create a completely fresh list each time the length of the list changes. \\texttt{MakeList} could also have been used in the previous section's example to define the \\texttt{components} element of the \\texttt{Container} class.\n\nThe second new element class is \\texttt{IntSelector} which takes an element over integers and returns an element that produces uniformly a number between 0 and the value of its argument (exclusive). This element can be used to generate a random index into a list produced by \\texttt{MakeList}. \\texttt{IntSelector} also has an interesting implementation that has benefits for reasoning algorithms (especially Metropolis- Hastings). The \\texttt{Randomness} is an infinite stream of uniformly distributed doubles between 0 and 1. Given a particular value of the integer argument, the selected index is the one with the highest randomness value in the finite portion of the stream defined by the argument.\n\n\n\n\n", "meta": {"hexsha": "bab17c6fe391ab9332d664533c0d7db7cede3951", "size": 41704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FigaroLaTeX/Tutorial/Sections/4CreatingModels.tex", "max_stars_repo_name": "wkretschmer/figaro", "max_stars_repo_head_hexsha": "ab45d86d7f2b23c77d242b15396f0f704d40570c", "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": "FigaroLaTeX/Tutorial/Sections/4CreatingModels.tex", "max_issues_repo_name": "wkretschmer/figaro", "max_issues_repo_head_hexsha": "ab45d86d7f2b23c77d242b15396f0f704d40570c", "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": "FigaroLaTeX/Tutorial/Sections/4CreatingModels.tex", "max_forks_repo_name": "wkretschmer/figaro", "max_forks_repo_head_hexsha": "ab45d86d7f2b23c77d242b15396f0f704d40570c", "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": 79.7399617591, "max_line_length": 1507, "alphanum_fraction": 0.7623968924, "num_tokens": 10566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6363010681017458}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 10, 2022}\n\\subsection{Jacobi Symbol \\emph{continued}}\n\\recall\n\\begin{definition*}[Jacobi Symbol]\n    Let $b\\in\\ZZ_+$ be odd, and let $a\\in\\ZZ$. We write $b = p-1p_2\\cdots p_m$, where $p_i$ are primes (not necessarily distinct). Then we have\n    \\[\\lege{a}{b} = \\lege{a}{p_1}\\lege{a}{p_2}\\cdots \\lege{a}{p_m}\\]\n    is called the \\ul{Jacobi symbol}.\n\\end{definition*}\n\nThis generalizes the Legendre symbol. We have basic properties that\n\\begin{align*}\n    \\lege{a_1a_2}{b} & = \\lege{a_1}{b}\\lege{a_2}{b} \\\\\n    \\lege{a}{b_1b_2} & = \\lege{a}{b_1}\\lege{a}{b_2}\n\\end{align*}\nWe noted that $\\lege{a}{b} = -1$ implies that $a$ is \\emph{not} a quadratic residue mod $b$ but $\\lege{a}{b} = 1$ does not imply $a$ is a quadratic residue mod $b$.\n\nWe also stated analogues of the reciprocity laws for the Legendre symbol.\n\n\\begin{lemma}\\label{lemma:multiplicativity-for-jacobi}\n    Let $r, s\\in\\ZZ_+$ be odd. Then\n    \\begin{enumerate}[(a)]\n        \\item $\\displaystyle\\frac{rs-1}{2}\\equiv \\frac{r-1}{2} + \\frac{s-1}{2}\\mod 2$.\n        \\item $\\displaystyle\\frac{r^2s^2 - 1}{8} \\equiv \\frac{r^2-1}{8} + \\frac{s^2 - 1}{8}\\mod 2$.\n    \\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n    ~\\begin{enumerate}[(a)]\n        \\item $(r-1)(s-1)\\equiv 0\\mod 4$. Hence\n              \\begin{align*}\n                  rs - 1 & \\equiv (r-1)(s-1) + r + s - 2\\mod 4          \\\\\n                         & \\equiv r + s - 2\\mod{4}                      \\\\\n                         & \\equiv (r-1) + (s-1)\\mod{4}                  \\\\\n                         & \\equiv \\frac{r-1}{2} + \\frac{s-1}{2} \\mod{2}\n              \\end{align*}\n              which gives (a).\n        \\item We follow the same procedure, more or less. $(r^2-1)(s^2-1)\\equiv 0\\mod{16}$, so\n              \\begin{align*}\n                  r^2s^2-1 & \\equiv (r^2-1)(s^2-1)+r^2+s^2-2\\mod{16}         \\\\\n                           & \\equiv (r^2-1)+(s^2-1)\\mod{16}                  \\\\\n                           & \\equiv \\frac{r^2-1}{8} + \\frac{s^2-1}{8}\\mod{2}\n              \\end{align*}\n              which gives (b).\n    \\end{enumerate}\n\\end{proof}\n\n\\begin{corollary}\n    let $r_1, r_2, \\dots, r_m\\in\\ZZ_+$ be odd. Then\n    \\begin{enumerate}[(a)]\n        \\item $\\displaystyle\n                  \\sum_{i=1}^m \\frac{r_i-1}{2} \\equiv \\frac{r_1r_2\\cdots r_m - 1}{2}\\mod 2\n              $.\n        \\item $\\displaystyle\n                  \\sum_{i=1}^m \\frac{r_i^2 - 1}{2}\\equiv \\frac{r_1^2r_2^2\\cdots r_m^2 - 1}{8}\\mod 2\n              $.\n    \\end{enumerate}\n\\end{corollary}\n\\begin{proof}\n    By induction on $m$ from \\cref{lemma:multiplicativity-for-jacobi}.\n\\end{proof}\n\nWe restate the reciprocity laws but for Jacobi symbols, \\cref{prop:5.2.2}:\n\\begin{proposition*}[5.2.2 of Text]\n    We have the following properties about the Jacobi symbol:\n    \\begin{enumerate}[(a)]\n        \\item \\[\\lege{-1}{b} = (-1)^{\\frac{b-1}{2}}\\]\n        \\item \\[\\lege{2}{b} = (-1)^{\\frac{b^2 - 1}{8}}\\]\n        \\item If $a, b\\in\\ZZ_+$, then\n              \\[\\lege{a}{b}\\lege{b}{a} = (-1)^{\\frac{a-1}{2}\\frac{b-1}{2}}\\]\n    \\end{enumerate}\n\\end{proposition*}\n\\begin{proof}[Proof of \\cref{prop:5.2.2}]\n    ~\\begin{enumerate}\n        \\item[(a) $+$ (b)] are immediate from the corollary (factor $b$, sum exponents and take the parity of the exponent) and the supplemental laws of quadratic reciprocity.\n        \\item[(c)] Let\n            \\begin{align*}\n                a & =q_1q_2\\cdots q_l   \\\\\n                b & = p_1p_2\\cdots p_m.\n            \\end{align*}\n            Then\n            \\begin{align*}\n                \\lege{a}{b}\\lege{b}{a} & = \\prod_{i}\\prod_{j} \\lege{q_i}{p_j}\\lege{p_i}{q_j}                                     \\\\\n                                       & = (-1)^{\\sum_i \\sum_j \\left(\\frac{q_i-1}{2}\\right)\\left(\\frac{p_j-1}{2}\\right)}\n                \\intertext{Applying the corollary, }\n                                       & = (-1)^{\\left(\\sum_i \\frac{q_i - 1}{2}\\right)\\left(\\sum_j \\frac{p_j - 1}{2}\\right)}     \\\\\n                                       & = (-1)^{\\left(\\frac{(\\sum_i q_i) - 1}{2}\\right)\\left(\\frac{(\\sum_j p_j) - 1}{2}\\right)} \\\\\n                                       & = (-1)^{\\left(\\frac{a-1}{2}\\right)\\left(\\frac{b-1}{2}\\right)}\n            \\end{align*}\n            which is as desired!\n    \\end{enumerate}\n\\end{proof}\n\\begin{example}\n    We try to compute with the Jacobi symbol. Recall \\cref{example:legendre-symbol}\n    \\[\\lege{219}{383}\\]\n    where we repeatedly factored and flipped. With a Jacobi symbol, we don't need to start with factoring; we can forego factorization of top argument and simply repeatedly flip:\n    \\begin{align*}\n        \\lege{219}{383} & = - \\lege{383}{219} = -\\lege{164}{219} = - \\lege{4}{219}\\lege{41}{219} = - \\lege{41}{219} \\\\\n                        & = - \\lege{219}{41} = - \\lege{14}{41} = - \\lege{2}{41}\\lege{7}{41} = -\\lege{7}{41}         \\\\\n                        & = -\\lege{41}{7} = -\\lege{-1}{7} = \\boxed{1}.\n    \\end{align*}\n\\end{example}\nWhat we did here is to exploit the fact that \\emph{all} Legendre symbols agree with Jacobi symbols, we treat it as a Jacobi symbol and do `Jacobi-\\emph{like}' manipulations on it.\n\\begin{center}\n    \\includegraphics[width=0.4\\textwidth]{images/jacobi_legendre_reveal.jpeg}\n\\end{center}\n\n\\emph{This marks the dividing line between the first half and latter half of the course! Everything up to this point is fair game on the midterm. We also now switch to Stewart and Tall.}\n\n\\subsection{Number Fields}\n\\begin{definition}[Algebraic Numbers]\n    A complex number $x$ is called \\ul{algebraic} if it is algebraic over $\\QQ$, i.e., if it satisfies a nonzero polynomial equation over $\\QQ$.\n\n    We denote the set of algebraic numbers over $\\QQ$ as $\\overline{\\QQ}$.\n\\end{definition}\n\\begin{proposition}\n    The set $\\overline{\\QQ}$ of algebraic numbers is a subfield of $\\CC$. That is, addition and multiplication is closed, and we have inverses for nonzero elements.\n\\end{proposition}\n\\begin{proof}\n    The key point is that if $L / K$ is a field extension, then $\\alpha\\in L$ is algebraic over $K$ iff $K(\\alpha)/K$ is finite.\n\n    So suppose $\\alpha, \\beta\\in\\overline{\\QQ}$. Then $\\QQ(\\alpha)/\\QQ$ and $\\QQ(\\beta)/\\QQ$ are finite. Thus $\\QQ(\\alpha, \\beta)/\\QQ$ is finite (and all pieces of the associated diamond are finite extensions as well).\n\n    \\[\n        \\xymatrix{\n            \\QQ \\ar[d] \\ar[r] &\\QQ(\\alpha)\\ar[d]\\\\\n            \\QQ(\\beta) \\ar[r] &\\QQ(\\alpha, \\beta)}\n    \\]\n\n\n    Since $\\alpha + \\beta$, $\\alpha - \\beta$, $\\alpha\\beta$ and for $\\beta \\neq 0$, $\\alpha/\\beta \\in \\QQ(\\alpha, \\beta)$. This means that all of these elements are algebraic over $\\QQ$.\n\\end{proof}\n\n\\begin{definition}\n    A \\ul{number field} is a subfield $K$ of $\\CC$ such that $[K : \\QQ] < \\infty$.\n\\end{definition}\n\nThus every element of a number field is algebraic, so $K\\subseteq \\overline{Q}$.\n\nBy the definition of a finite extension, every number field has the form\n\\[K = \\QQ(\\alpha_1, \\alpha_2, \\dots, \\alpha_N)\\text{ for some }\\alpha_1, \\dots, \\alpha_n\\in\\overline{\\QQ}\\]\n\nHowever, something stronger than this holds.\n\n\\begin{theorem}[Primitive Element Theorem]\n    If $K$ is a number field, then $K = \\QQ(\\theta)$ for some $\\theta\\in\\overline{\\QQ}$.\n\\end{theorem}\n\\begin{proof}[Proof sketch]\n    It is enough to show that if\n    \\[K = K_1(\\alpha, \\beta), \\]\n    then $K = K_1(\\theta)$ for some $\\theta\\in\\overline{\\QQ}$.\n\n    Suppose the minimum polynomials (over $\\QQ$) of $\\alpha$ and $\\beta$ respectively are (factored over roots in $\\CC$):\n    \\begin{align*}\n        (t-\\alpha_1)(t-\\alpha_2)\\cdots (t-\\alpha_n)\\qquad \\alpha_1 & = \\alpha \\\\\n        (t-\\beta_1)(t-\\beta_2)\\cdots (t-\\beta_n)\\qquad \\beta_1     & = \\beta  \\\\\n    \\end{align*}\n    These polynomials are separable. Hence for each $i$ and each $k\\neq 1$, there exists at most one $x\\in K_1$ such that\n    \\[\\alpha_i + x\\beta_k = \\alpha_1 + x\\beta_1.\\]\n    (This only holds for more $x$ when you have $\\beta_k$ and $\\beta_1$ colliding). There are only finitely many of these equations, so we can choose a nonzero $c\\in K_1$ such that\n    \\[\\alpha_i + c\\beta_k \\neq \\alpha_1 + c\\beta_1\\]\n    for any $1\\leq i\\leq n$ and $2\\leq k\\leq m$.\n\n    Define $\\theta = \\alpha + c\\beta$. We claim that\n    \\[K_1(\\alpha, \\beta) = K_1(\\theta)\\]\n    for which the proof is on page 39 of Stewart Tall.\n\\end{proof}", "meta": {"hexsha": "334d8f7d64a8b0221fad204938ee50fc0f467021", "size": 8315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-10.tex", "max_stars_repo_name": "jchen/math1560-notes", "max_stars_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-02T15:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T20:28:48.000Z", "max_issues_repo_path": "lectures/2022-03-10.tex", "max_issues_repo_name": "jchen/math1560-notes", "max_issues_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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-10.tex", "max_forks_repo_name": "jchen/math1560-notes", "max_forks_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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": 50.0903614458, "max_line_length": 218, "alphanum_fraction": 0.5704149128, "num_tokens": 2827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.6363010641098987}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{wrapfig}\n\\usepackage{pseudocode}\n\\usepackage{url}\n\\usepackage[backref, colorlinks=true, citecolor=red, urlcolor=blue, pdfauthor={Jyh-Ming Lien}]{hyperref}\n\\graphicspath{{images/}}\n\n\\newcommand{\\handout}[5]{\n  \\noindent\n  \\begin{center}\n  \\framebox{\n    \\vbox{\n      \\hbox to 5.78in { {\\bf } \\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}{#4}{#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 Report}{Fall 2017}{Anthony Sermania}{Computational Geometry}\n\n\\section{Summary of the two methods}\n\n\\subsection{hedcuter method}\nThe hedcuter method is as follows:\n\nHedcut:\n\\begin{enumerate}\n\\item Create a set of n random initial points (keep on random probability, favoring darker areas)\n\\item Compute the Weighted Centroidal Voronoi Tessellation (CVT)\n\\item Generate Disks\n\\end{enumerate}\n\nComputing The CVT:\n\\begin{enumerate}\n\t\\item While (we have fewer iterations than the limit AND the max-displacement is greater than some threshold:\n\t\\begin{enumerate}\n\t\\item Computer the Voronoi\n\t\\item Shift Voronoi cell sites towards cell centroids (and record displacement\n\t\\end{enumerate}\n\\end{enumerate}\n\n\nCompute the Voronoi\n\\begin{enumerate}\n\\item For each input site\n\t\\begin{enumerate}\n\t\\item redirect site to corresponding position in resized image (fake enhanced resolution)\n\t\\item determine distance based on color of site\n\t\\item add site to open list/heap\n\t\\end{enumerate}\n\t\n\\item while heap is not empty\n\\begin{enumerate}\n\t\\item cell <- max heap element (pop)\n\t\\item if distance has been updated or cell has been visited\n\t\t\\begin{enumerate}\n\t\t\\item skip\n\t\t\\end{enumerate}\n\t\t\n\t\\item for each neighbor of cell\n\t\\begin{enumerate}\n\t\\item if cell.distance+neighbor.distance < neighbor.distance\n\t\\begin{enumerate}\n\t\\item set neighbor.distance <- cell.distance+neighbor.distance\n\t\t\t\\item make neighbor.root <- cell.root\n\t\t\t\\item push neighbor into heap\n\t\\end{enumerate}\n\t\t\t\n\t\\end{enumerate}\n\t\t\n\\end{enumerate}\n\t\n\\item For each cell in image\n\t\\begin{enumerate}\n\t\\item determine root of cell\n\t\\item add cell to cell.root's coverage\n\t\\end{enumerate}\n\t\n\\item Remove all cells with coverage.empty\n\\end{enumerate}\n\n\nMove voronoi cell sites to their new locations (and record displacement)\n\\begin{enumerate}\n\\item For each cell\n\\begin{enumerate}\n\\item calculate new position as average of positions in coverage\n\\item Generate high res img\n\\item newpos <- (0, 0), total <- 0\n\\item for each cell c in cell.coverage\n\\begin{enumerate}\n\\item newpos += c.distance*c.pos\n\\item total += c.distance\n\\end{enumerate}\n\n\\item newpos /= total to normalize\n\\item newpos /= subpixels to redirect to original image\n\\item store manhattan distance from new to old position\n\\end{enumerate}\n\n\\item return the max displacement (manhattan distance) or average of displacements (depending on termination mode)\n\\end{enumerate}\n\n\nGenerate Disks\n\\begin{enumerate}\n\\item Collect the darkness/color of the area in a voronoi cell\n\\item Create a disk at cell site (center)\n\\item Color/darken cell according to the average color/darkness of the pixels i the cell\n\\end{enumerate}\n\n\n\\subsection{voronoi method}\nThis one was a little bit tougher to work through mentally. At the highest level it uses Lloyd's Algorithm as so:\n\nWhile generating points (xi) not converged to centroid\n\\begin{enumerate}\n\\item compute voronoi diagram of xi\n\\item compute centroid Ci\n\\item move generating point xi to centroid Ci\n\\end{enumerate}\n\n\nThe Voronoi diagram computation is done differently here, utilizing an entire Voronoi Generation class that appears to implement a half-edge mechanism for doing it's work after some initial set up. It is extremely well commented; rather than just essentially replicating the comments, here is an overview of the half-edge voronoi generation:\n\n\\begin{enumerate}\n\\item While there are events:\n\\begin{enumerate}\n\\item If the lowest site is lower than the lowest vector intersection process the site\n\\begin{enumerate}\n\\item Get left and right half edges, plus the edge of the left halfedge (or the bottom site if there's no edge)\n\\item create a bisector for the left edge (or bottom site) and if it intersects the left edge shuffle the vertices so the left edge and bisector share a vertex.\n\\item Create a new half edge right of the first (only at the moment) bisector\n\\item if this new bisector intersects with the right halfedge, add the bisector halfedge to the ordered linked list of verts\n\\item get next site\n\\end{enumerate}\n\n\\item else process the lowest vector intersection\n\\begin{enumerate}\n\\item Get the halfedge for the intersection vector, as well as the surrounding halfedges\n\\item get the sites of the of the exterior halfedges\n\\item consider a circle passing through the triple of sites obtained\n\\item get the vertex that caused the event\n\\item set the endpoints of the left and right half edges to be this vertex\n\\item mark the lowest half edge for deletion\n\\item clear events for right halfedge\n\\item mark right halfedge for deletion\n\\item if the site to left of the event is higher than site to the right, swap them\n\\item create an edge between the two sites\n\\item create a half edge for this edge\n\\item insert the new bisector to the right of the left halfedge\n\\item cleanup (reposition half-edges not intersecting the bisector that should)\n\\end{enumerate}\n\n\\end{enumerate}\n\n\\end{enumerate}\n\n\nThat still got pretty verbose, but it's not quite done. Once this routine has run, the generator that ran it is used to collect the edges before completing (this process is straightforward and is not detailed here).\n\nNow it moves to step 2, redistributing the stipples (bringing them closer to the centroids of the Voronoi cells). This is done in parallel where applicable.\n\n\\begin{enumerate}\n\\item Do some setup (make pairs of points and edge lists)\n\\item For each pair:\n\\begin{enumerate}\n\\item Calculate Centroid\n\\item update Radius and vertex X/Y positions to be that of the calculated centroid\n\\item determine displacement of point\n\\end{enumerate}\n\\item average displacement of all points\n\\end{enumerate}\n\n\nCalculating a Centroid:\nAccording to the paper, \\textit{Weighted Voronoi Stippling} by Adrian Secord, there are some integrals being done here. The implementation provided however seems to work around that, operating primarily on distance constraints:\n\n\\begin{enumerate}\n\\item Compute the Clip Lines\n\\item For all points in this space if a point is inside it's polygon, it contributes to the area density\n\\item If a cell is not completely white, shift the centroid according to the weighted-spot:area density ratio (that's a weird way to put it, but it's what's happening)\n\\item Iterate over the available edges and determine the nearest and farthest, using one of those distances to determine the size of the stipple (nearest if NoOverlap, Farthest otherwise) and scale by the area:max-area ratio\n\\item Return the pair of the original point and the radius.\n\\end{enumerate}\n\n\n\n\\section{Comparison of the two methods}\nBoth methods saw fair success. I will however claim the voronoi code to be superior overall.\n\nLet's start with hedcut though. For one thing, hedcut was not consistent across multiple runs with the same parameters. Take for instance the following images:\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.4]{fairyeyes-10000-r4-1.png}\n\\includegraphics[scale=0.4]{fairyeyes-10000-r4-2.png}\n\\end{figure}\n\nWe can see here that the two images, run with the same parameters (radius 4, 10,000 stipples) produced different stipplings. By contrast, here are two images from the voronoi code with the equivalent parameters (4,000 stipples, color, overlap)\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.4]{fairyeyes-4k-color-2.png}\n\\includegraphics[scale=0.4]{fairyeyes-4k-color-3.png}\n\\end{figure}\n\nAnd two more from voronoi, this time with no overlap.\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.4]{fairyeyes-noverlap-4k-color.png}\n\\includegraphics[scale=0.4]{fairyeyes-noverlap-4k-color-2.png}\n\\end{figure}\n\nIt is worth noting I discovered later that hedcut might by consistent with sufficiently many iterations (see Improvements).\n\nIn terms of speed, hedcut may be faster in the simplest circumstances, coming out at around the same computatin time for 10,000 stipples as voronoi did for 4,000 and 8,000, however voronoi never seemed to vary much with number of dots- just by image. Hedcut on the other hand does take longer the more dots there are. The two images below are both 100,000 stipples. The image on the left is the hedcut image, created in 16.22 seconds; the one on the right is from voronoi, created in 4.43 seconds (not substantially slower than the 8,000 or 4,000 stipple runs for voronoi).\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.4]{fairyeyes-hedcut-100000.png}\n\\includegraphics[scale=0.4]{fairyeyes-voronoi-100000.png}\n\\end{figure}\n\nBeyond that time difference, the level of image fidelity with this many stipples is vastly superior in the voronoi image. I suspect the difference in speed comes from the use of so many loops in the hedcut code. The difference in quality is undoubtedly due to the stronger implementation of varied stipple sizes (based purely on the voronoi cell size) in the voronoi code. The hedcut code uses a base radius which is scaled, resulting in much weirder stipple sizes. It does however improve it's image fidelity with successive iterations (see below), perhaps even gaining on voronoi for image quality.\n\n\\section{Improvement of hedcuter method}\nWhile I technically made two improvements to hedcut, I can only claim one of them was significant. The insignificant one was some compiler optimizations; this ended up not amounting to any consistently measurable improvement, and moreover wasn't a significant revamp to the code, so I would understand considering it poorly. Given that I was working on Windows in the end, and this required some working knowledge of Visual Studio (2013), maybe it's worth something? I ultimately did not try a third attempt due to time- much of which was wasted either trying to get the project to run (copy-paste .dll saved the day) or interviewing CS 110 students one at a time.\n\nI did however make one very significant change that yielded marvelous improvements. There was a point in move-sites where the code was creating a higher resolution version of our source image to do centroid-relocation math in before redirecting the result back to the source image resolution. Being located in move-sites, it was being run for every voronoi cell, every iteration of the algorithm. This struck me as highly inefficient. So I relocated it to just before we began running the algorithm in full- we never change the source image, so the higher res version should never change either. I was initially confused because I was mistakenly attributing the benefits of greater iterations to this change, but I did discover my folly.\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.5]{sunbros-plain-itr1-100000.png}\n\\includegraphics[scale=0.5]{sunbros-plain-itr3-100000.png}\n\\caption{Original Code. Left is 1 iteration; Right is 3 iterations. A fair improvement can be seen by increasing the number of iterations.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.5]{sunbros-lessrescale-itr1-100000.png}\n\\includegraphics[scale=0.5]{sunbros-lessrescale-itr3-100000.png}\n\\caption{The revised version. As before, left is 1 iteration and right is 3. The images are quite similar to their original counterparts. It is possible the hedcut algorithm gains consistency with increasing iterations- a costly but evidently worthwhile gain.}\n\\end{figure}\n\nSo, No significant changes in the images from this. However, consider for a moment the following tables, indicating run times for various runs using the sunbros.png image for 1 or 3 iterations, before and after the change.\n\n\\begin{figure}[H]\n\\includegraphics[scale=0.8]{hedcut-table.png}\n\\end{figure}\n\\begin{figure}[H]\n\\includegraphics[scale=0.8]{hedcut-results.png}\n\\end{figure}\n\nA 99 percent improvement! That image rescaling must have been taking a hefty toll to run for so many iterations, seemingly unnecessarily!\n\nAfter seeing the improvements made here, I decided to accept the negligible impact of the compiler optimizations; this now performs even better than the voronoi implementation in terms of run time.\n\nI did make several other efforts that ultimately were not completed. I made a few attempts to determine the stipple size solely using the voronoi cell area, but concluded that I would have to backtrack a litte further than I was comfortable doing and risk breaking other key parts of the code. I also swapped the random number generator for the uniform gaussian to the included MT19937 generator during the sample point creation. This had no noticeable difference however (pictures omitted because I'm already lost in ths LaTeX thing).\n\n\\bibliographystyle{plain}\n\\bibliography{report}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "cd1336fe60dc4b2bb58373b535f84a0edf801f3f", "size": 13886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/report.tex", "max_stars_repo_name": "TheOnePercent44/cs633-hedcut", "max_stars_repo_head_hexsha": "0d5fc6fb0af82dff315f311bd44b1c6b37dd278a", "max_stars_repo_licenses": ["MIT"], "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/report.tex", "max_issues_repo_name": "TheOnePercent44/cs633-hedcut", "max_issues_repo_head_hexsha": "0d5fc6fb0af82dff315f311bd44b1c6b37dd278a", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "TheOnePercent44/cs633-hedcut", "max_forks_repo_head_hexsha": "0d5fc6fb0af82dff315f311bd44b1c6b37dd278a", "max_forks_repo_licenses": ["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.9801324503, "max_line_length": 737, "alphanum_fraction": 0.7835229728, "num_tokens": 3502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6363010623839583}}
{"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{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*{lem}{Lemma}\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*{Problem}\na)  Let $x_0 , ... , x_{n-1}$ and $M$ be positive real numbers.  Find real numbers $a_0, ..., a_n$ so that $\\sum_{i = 0}^{n-1} x_i a_i$ is maximized subject to the constraint that $\\sum_{i = 0}^{n-1} a_i ^2 = M$\n\\\\\nb) If you used the definition of the cosine between vectors as part of your solution in a), prove independently that your solutiion is correct (the definition depends on the result being established here).\n\n\\section*{Solution (contributed by Juan Carlos Ramirez)}\nConsider the equivalent problem (controlling over $a$):\nminimize $-x^Ta$\nsubject to $a^Ta=M$.\nLet is relax the constraint to consider the problem\nminimize $-a^Tx$\nsubject to $a^Ta \\leq M$.\nIf we find that the minimum of this relaxed version satisfies $a^Ta=M$ then it is also a minimum of the original problem (since it contains the feasible set for the original problem). The feasible set is a closed ball, so it is compact and since $f_0(a)=-x^Tc is$  linear, it is also continuous and it achieves a minimum in the closed ball (the minimum exists). Let us also note $f_0$ is convex and infinitely differentiable.\nLet $f_1(a) = a^Ta-M$. Then $f_1$ is also convex, inifinitely differentiable, and there is a point $a_s=0$ such that $f_1(a_s)<0$. So the problem satisfies Slater's condition, and since $f_1$ is convex, any local minimum of the problem will satisfy KKT conditions (In particular any global minima), i.e.  $(a^*,\\lambda^*)$:\n$f_1(a^*)<=0$ (Primal Feasibility constraint)\n$\\lambda^*>=0$ (Dual Feasibility constraint)\n$\\lambda^* f_1(a^*)=0$ (Complimentary slackness CS)\n$\\nabla f_0(a^*)= -\\lambda^* f_1(a^*)$ (First order condition FOC)\nUsing the FOC, we see that $\\lambda^*$ cannot be 0, since then $-x=0$, but x is a prechosen vector with all positive entries. Therefore, $\\lambda^*>0$ and by CS condition $f_1(x^*)=0$ (this gives us that $*(a^*)^Ta^*=M$ and therefore both minimization problems are have the same minimum).\nUsing FOC again we get\n$$ -x=-\\lambda^*(2a*)$$\n\nor\n$$a^*=x/(2\\lambda^*)$$\n\nand therefore\n$$(a^*)^Ta^*=x^Tx/(2\\lambda^*)^2$$\n\nSo\n$$(\\lambda^*)=\\sqrt{x^Tx}/(2\\sqrt{M}$$\n\nand\n$$a^*=\\sqrt{M}x/\\sqrt{x^Tx}$$\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "f2d3c656ab47ed14175fd24338c7d3d9c69dae6d", "size": 2878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maxDot/maxDot.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": "maxDot/maxDot.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": "maxDot/maxDot.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": 45.6825396825, "max_line_length": 425, "alphanum_fraction": 0.7213342599, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174789, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6362298088405859}}
{"text": "% Preamble.\n\\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%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{17}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-06-18}\n\n\\title{\\vspace{-2\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Find the matrix that rotates space $30 \\degree$ counterclockwise about\nthe vector $\\vec{n} = \\begin{pmatrix} 1 \\\\ 0 \\\\ -1 \\end{pmatrix}$.}\n\\\\[\\baselineskip]\nThe plane normal to $\\vec{n}$ can be represented by the equation\n\\begin{equation*}\n\t0\n\t=\n\t\\vec{n} \\cdot \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t=\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ -1 \\end{pmatrix}\n\t\\cdot\n\t\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}\n\t=\n\tx - z\n\t.\n\\end{equation*}\nLet $\\vec{v}_1 = \\vec{n}$. \\\\\nA vector that is orthogonal to $\\vec{v}_1$ can be found on the plane\n$0 = x - z$:\n\\begin{equation*}\n\t\\vec{v}_2 = \\begin{pmatrix} 1 \\\\ 0 \\\\ 1 \\end{pmatrix}\n\t.\n\\end{equation*}\nThe vector that is orthogonal to both $\\vec{v}_1$ and $\\vec{v}_2$ can be found\nby computing the cross product of $\\vec{v}_1$ and $\\vec{v}_2$:\n\\begin{equation*}\n\t\\vec{v}_3 = \\vec{v}_1 \\times \\vec{v}_2 =\n\t\\begin{pmatrix} 0 \\\\ -2 \\\\ 0 \\end{pmatrix}\n\t.\n\\end{equation*}\nA convenient basis for describing the rotation can be constructed from\nnormalizing the orthogonal triple $\\vec{v}_1$, $\\vec{v}_2$, and $\\vec{v}_3$.\nLet such a basis be $\\mathcal{B}$, where\n\\begin{equation*}\n\t\\mathcal{B}\n\t=\n\t\\left\\{ \\hat{v}_1, \\hat{v}_2, \\hat{v}_3 \\right\\}\n\t=\n\t\\left\\{\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{\\sqrt{2}} \\\\\n\t\t\t0 \\\\\n\t\t\t-\\frac{1}{\\sqrt{2}}\n\t\t\\end{pmatrix}\n\t\t,\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{\\sqrt{2}} \\\\\n\t\t\t0 \\\\\n\t\t\t\\frac{1}{\\sqrt{2}}\n\t\t\\end{pmatrix}\n\t\t,\n\t\t\\begin{pmatrix}\n\t\t\t0 \\\\\n\t\t\t-1 \\\\\n\t\t\t0\n\t\t\\end{pmatrix}\n\t\\right\\}\n\t,\n\\end{equation*}\nin contrast to the standard basis $\\mathcal{S}$, where\n\\begin{equation*}\n\t\\mathcal{S}\n\t=\n\t\\left\\{\n\t\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix},\n\t\t\\begin{pmatrix} 0 \\\\ 1 \\\\ 0 \\end{pmatrix},\n\t\t\\begin{pmatrix} 0 \\\\ 0 \\\\ 1 \\end{pmatrix}\n\t\\right\\}\n\t.\n\\end{equation*}\n\\newpage \\noindent\nIn basis $\\mathcal{B}$ the rotation of interest is a $30 \\degree$\ncounterclockwise rotation about $\\hat{v}_1$. \\\\\nLet ${\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}$ be the matrix for such a rotation in\nbasis $\\mathcal{B}$ so that\n\\begin{equation*}\n\t{\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}\n\t=\n\t\\begin{pmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & \\cos(30 \\degree) & -\\sin(30 \\degree) \\\\\n\t\t0 & \\sin(30 \\degree) & \\cos(30 \\degree)\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nLet ${\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}}$ be the matrix with columns\n$\\hat{v}_1$, $\\hat{v}_2$, and $\\hat{v}_3$ so that\n\\begin{equation*}\n\t{\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}}\n\t=\n\t\\begin{pmatrix}\n\t\t\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\\n\t\t0 & 0 & -1 \\\\\n\t\t-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n${\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}}$ can be thought of as the matrix that\nconverts an input ${\\{\\vec{x}\\}}_{\\mathcal{B}}$ (a vector described in basis\n$\\mathcal{B}$) to ${\\{\\vec{x}\\}}_{\\mathcal{S}}$ (the same vector but\ndescribed in basis $\\mathcal{S}$). \\\\\nSimilarly, let ${\\{I\\}}_{\\mathcal{S}}^{\\mathcal{B}}$ be the matrix that\nconverts from basis $\\mathcal{S}$ to $\\mathcal{B}$, so that\n\\begin{equation*}\n\t{\\{I\\}}_{\\mathcal{S}}^{\\mathcal{B}}\n\t=\n\t{\\left( {\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}} \\right)}^{-1}\n\t=\n\t{\\left( {\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}} \\right)}^{\\text{T}}\n\t=\n\t\\begin{pmatrix}\n\t\t\\frac{1}{\\sqrt{2}} & 0 & -\\frac{1}{\\sqrt{2}} \\\\\n\t\t\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n\t\t0 & -1 & 0\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nLet ${\\{R\\}}_{\\mathcal{S}}^{\\mathcal{S}}$ be the rotation of interest in\nstandard basis. \\\\\n${\\{R\\}}_{\\mathcal{S}}^{\\mathcal{S}}$ can be computed as the composition of\nfirstly the transformation from basis $\\mathcal{S}$ to $\\mathcal{B}$, then the\nrotation of interest under basis $\\mathcal{B}$, and finally the transformation\nfrom basis $\\mathcal{B}$ back to $\\mathcal{S}$:\n\\begin{align*}\n\t{\\{R\\}}_{\\mathcal{S}}^{\\mathcal{S}}\n\t&=\n\t{{\\{I\\}}_{\\mathcal{B}}^{\\mathcal{S}}}\n\t\\cdot\n\t{{\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}}\n\t\\cdot\n\t{{\\{I\\}}_{\\mathcal{S}}^{\\mathcal{B}}}\n\t\\\\\n\t&=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0 \\\\\n\t\t\t0 & 0 & -1 \\\\\n\t\t\t-\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} & 0\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & 0 \\\\\n\t\t\t0 & \\cos(30 \\degree) & -\\sin(30 \\degree) \\\\\n\t\t\t0 & \\sin(30 \\degree) & \\cos(30 \\degree)\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{\\sqrt{2}} & 0 & -\\frac{1}{\\sqrt{2}} \\\\\n\t\t\t\\frac{1}{\\sqrt{2}} & 0 & \\frac{1}{\\sqrt{2}} \\\\\n\t\t\t0 & -1 & 0\n\t\t\\end{pmatrix}\n\t}\n\t.\n\\end{align*}\n\n\\section*{2.}\n\\textit{Let $\\vec{a} = \\begin{pmatrix} 5 \\\\ 0 \\\\ 0 \\end{pmatrix}$ and\n$\\vec{b} = \\begin{pmatrix} 0 \\\\ 3 \\\\ 4 \\end{pmatrix}$. \\\\\nFind the vector $\\vec{v}$ that is $\\vec{a}$ rotated $40 \\degree$ toward\n$\\vec{b}$.} \\\\[\\baselineskip]\nNote that $\\vec{a} \\cdot \\vec{b} = 0$, meaning that the two vectors are\northogonal. \\\\\nA vector $\\vec{c}$ in the axis of rotation can be found by computing\n\\begin{equation*}\n\t\\vec{c}\n\t=\n\t\\vec{a} \\times \\vec{b}\n\t=\n\t\\begin{pmatrix} 0 \\\\ -20 \\\\ 15 \\end{pmatrix}\n\t.\n\\end{equation*}\nLet the basis $\\mathcal{B}$ be constructed from the triple $\\vec{a}$,\n$\\vec{b}$, and $\\vec{c}$:\n\\begin{equation*}\n\t\\mathcal{B}\n\t=\n\t\\left\\{ \\vec{a}, \\vec{b}, \\vec{c} \\right\\}\n\t=\n\t\\left\\{\n\t\t\\begin{pmatrix} 5 \\\\ 0 \\\\ 0 \\end{pmatrix},\n\t\t\\begin{pmatrix} 0 \\\\ 3 \\\\ 4 \\end{pmatrix},\n\t\t\\begin{pmatrix} 0 \\\\ -20 \\\\ 15 \\end{pmatrix}\n\t\\right\\}\n\t.\n\\end{equation*}\nLet ${\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}$ be the matrix for the rotation of\ninterest about $\\vec{c}$ in basis $\\mathcal{B}$:\n\\begin{equation*}\n\t{\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(40 \\degree) & -\\sin(40 \\degree) & 0 \\\\\n\t\t\\sin(40 \\degree) & \\cos(40 \\degree) & 0 \\\\\n\t\t0 & 0 & 1\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nUsing ${\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}$, \n\\begin{gather*}\n\t{\\{\\vec{v}\\}}_{\\mathcal{B}}\n\t=\n\t{\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}\n\t{\\{\\vec{a}\\}}_{\\mathcal{B}}\n\t=\n\t{\\{R\\}}_{\\mathcal{B}}^{\\mathcal{B}}\n\t\\begin{pmatrix} 1 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\t\\cos(40 \\degree) \\\\\n\t\t\\sin(40 \\degree) \\\\\n\t\t0\n\t\\end{pmatrix}\n\t,\n\t\\\\\n\t\\vec{v}\n\t=\n\t\\cos(40 \\degree)\n\t\\begin{pmatrix} 5 \\\\ 0 \\\\ 0 \\end{pmatrix}\n\t+\n\t\\sin(40 \\degree)\n\t\\begin{pmatrix} 0 \\\\ 3 \\\\ 4 \\end{pmatrix}\n\t+\n\t0\n\t\\begin{pmatrix} 0 \\\\ -20 \\\\ 15 \\end{pmatrix}\n\t=\n\t\\boxed{\n\t\t\\begin{pmatrix}\n\t\t\t5 \\cos(40 \\degree) \\\\\n\t\t\t3 \\sin(40 \\degree) \\\\\n\t\t\t4 \\sin(40 \\degree)\n\t\t\\end{pmatrix}\n\t}\n\t.\n\\end{gather*}\n\n\\end{document}", "meta": {"hexsha": "d7c47583a6c0f1470e3f5fc02f1fd15ae21de9de", "size": 6810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw17/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/hw17/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/hw17/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.8935361217, "max_line_length": 78, "alphanum_fraction": 0.5898678414, "num_tokens": 2928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6362297998713579}}
{"text": "\\chapter{Permutation representations}\r\n\\section {Basic Results}\r\n{\\bf Lemma 1:} \r\nLet $H \\le G$ and $Hg_1 , ..., Hg_n$ be the cosets; the map\r\n$\\pi(g): \\langle Hg_1, ..., Hg_n \\rangle \\mapsto \\langle Hg_1 g, ..., Hg_n g \\rangle $ \r\nis a map from $G$ to $\\Sigma_n$\r\nwhose kernel is the largest normal subgroup of $G$ in $H$; in fact,\r\n$ker(\\pi) = \\bigcap_{i=1}^n H^{x_i}$.\r\n\\\\\r\n\\\\\r\n{\\bf Corollary:}  If $G$ is simple and $G > H$ with $|G:H| = k$ then\r\n$|G| \\mid k!$.\r\n\\section {Imprimitivity}\r\n{\\bf Definition 1:}\r\nA \\emph{system of imprimitivity for permutation \r\ngroup $G$:} is a set, ${\\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 g \\Delta = \\emptyset$ or\r\n$\\Delta = g \\Delta$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem: 1}\r\nIf $H<G$ and $G$ is simple then $|G| \\mid |G:H|!$. \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet  $\\pi: G \\rightarrow Perm(G/H)$ be the map from $G$ to the permutations on the right\r\ncosets of $H$ in $G$.  $G/ker(\\pi)$ is an injection into $S_{|G:H|}$ and $ker(\\pi)=1$ so\r\n$|G| \\mid |G:H|!$.\r\n\\end{quote}\r\n{\\bf Definition 2:}\r\nA permutation is \\emph{primitive} if there is no non-trivial set of imprimitivity.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 3:}\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\n\\\\\r\n\\\\\r\n{\\bf Normal Subgroups of Primitive Groups Theorem:}  \r\nLet $G$ be primitive on $\\Omega$ and $1 \\ne N \\lhd G$.  Then either $N \\subseteq G_a$ or\r\n$N$ acts transitively on $\\Omega$.  If the action is regular, $N$ is a minimal normal subgroup.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\Delta(a)= Na$.  If $\\Delta(a)= \\{ a \\}$, $N \\subseteq G_a$ and we're done.\r\nSuppose $a \\ne b \\in Na$.  Since $G$ is transitive, $\\exists g \\in G: ga=b$ so\r\n$g \\Delta(a)= gNa= (gN g^{-1} ) ga= Nb = \\Delta(b)$.  But $b \\in Na$ so $Nb = Na$.\r\nThus $\\Delta(a)$ is an imprimitive block.  Since $G^{\\Omega}$ is primitive, $\\Delta(a)= \\Omega$\r\nand $N$ is transitive.\r\n\\end{quote}\r\n{\\bf Iwasawa's Theorem:}  Let $G$ be a primitive permutation group and suppose (1) $G'=G$ and\r\n(2) $\\exists A$ with $A$ solvable  and $A \\lhd G_a: G=\r\n\\langle A^G \\rangle $ then $G$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $1 < N \\lhd G$.  Since $N$ is transitive by the previous result, $NG_a=G$.  Further,\r\n$G_a \\subseteq N_G(NA)$ and $N \\subseteq N_G(NA)$ and so $G= NG_a= N_G(NA)$. So $NA \\lhd G$ and\r\n$(NA)^G =NA \\lhd G$ but $ \\langle A^G \\rangle = G$ so $NA=G$. \r\nSince $A$ is solvable, so is $G/N$ and\r\n$(G/N)'=(G/N)$ and so $N = G$.\r\n\\end{quote}\r\n{\\bf Theorem 2:}\r\nIf $\\Delta \\subseteq \\Omega$ and $\\alpha \\in \\Omega$ then \r\n$\\psi( \\alpha ) = \\bigcap_{\\alpha \\in g \\Delta} g \\Delta$ is a block of a transitive\r\ngroup $G \\subseteq Sym(\\Omega)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\beta= h \\alpha$ and\r\nnote that \r\n$h \\psi( \\alpha ) = \\bigcap_{h \\alpha \\in hg \\Delta} hg \\Delta= \\psi( \\beta )$ so\r\n$ |\\psi( \\alpha )|= |\\psi( \\beta )| $.   Now suppose $\\beta \\in \\psi( \\alpha )$ then\r\n$\\alpha \\in g \\Delta \\rightarrow \\beta \\in g \\Delta$ so \r\n$\\bigcap_{\\beta \\in g \\Delta} g \\Delta \\supseteq \\bigcap_{\\alpha \\in g \\Delta} g \\Delta$ and\r\nso, $\\psi( \\beta ) = \\psi ( \\alpha )$ since they both have the same number of elements.  We have\r\nshown $\\beta \\in \\psi( \\alpha ) \\rightarrow  \\psi( \\beta ) = \\psi( \\alpha )$ and thus\r\n$\\psi( \\alpha ) \\cap \\psi( \\beta ) = \\emptyset$  or \r\n$\\psi( \\alpha ) = \\psi( \\beta )$.\r\n\\end{quote}\r\n{\\bf Theorem 3:}\r\n$G$ is primitive iff $G_{\\alpha}$ is maximal.\r\nA transitive group is imprimitive iff $\\exists Z$: $G_{\\alpha} < Z < G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $b \\ne a$.  Suppose $a, b \\in \\Delta_i$ with $\\{ \\Delta_i \\}$ a set of\r\nimprimitivity and suppose $g a= b$.  Then $g \\Delta_i = \\Delta_i$ and \r\n$ \\langle g, G_a \\rangle > G_a$\r\nstabilises the block containing $a$.  So if $G_a$ is not primitive then $G_a$ is not maximal.\r\nIf $G > M > G_a$ and $M$ is maximal, $Ma$ is a set of imprimitivity so $G$ is not primitive.\r\n\\end{quote}\r\n{\\bf Definition 4:}\r\n$G$ acts \\emph{regularly} on $\\Omega$ if $\\forall \\alpha, \\beta \\in \\Omega,\r\n\\exists ! g: \\alpha^g= \\beta$.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 4:}  Let $G$ be $n-$fold transitive on $\\Omega$, $n \\ge 2$ and $N$ a regular\r\nnormal subgroup of $G$ then $n \\le 4$ and \r\n(1) If $n=2$, $N$ is an elementary abelian $p-$group; \r\n(2) If $n=3$, $N$ is an elementary abelian $2-$group or $N=C_3$ and $G=S_3$;\r\n(3) If $n=4$, $N= C_2 \\times C_2$ and $G=S_4$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $n \\geq 2$ and $\\alpha \\in \\Omega$.  $G_{\\alpha}$ is $(n-1)$-fold transitive on $\\Omega - \\{ \\alpha \\}$ and\r\nhence on $N^{\\#}$ so $\\exists g: x^g=y, x,y \\in N^{\\#}$.  Thus every element of $N^{\\#}$ has the same order, $p$.\r\n$N= {\\mathbb Z}(N)$ and $N$ is abelian (and hence elementary abelian).\r\nIf $n \\geq 3$, $3 \\leq |N|=|\\Omega|$.  If $n=3$, $G=S_3$.  If $p \\geq 3$, $x_1 \\neq x_1^{-1}=x_2$.  Let $x_3$ be another \r\nelement.  Then $x_1^g= x_2, x_2^g=x_3$ for some $g$ and this is contradictory so $p=2$.\r\nIf $n \\geq 4$, $N$ is an elementary abelian $2$-group.  Let $U= \\langle x_1 \\rangle \\times \\langle x_2 \\rangle$.\r\nIf $N \\neq U$, put $x_3=x_1 x_2$ and choose $x_4 \\notin U$.  Then $\\exists g \\in G:$\r\n$x_1^g= x_1$,\r\n$x_2^g= x_2$, and\r\n$x_3^g= x_4$ which is again contradictory.\r\n\\end{quote}\r\n{\\bf Definition 5:}\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 \\emph{rank of the permutation group} is number of orbitals.\r\n$\\Delta^p= \\{ (y,x): (x, y) \\in \\Delta \\}$ is called the \\emph{paired orbit}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 5:}\r\nOn a self-paired orbit $\\Delta$, the graph ${\\cal G}=(G, X,\\Delta)$ is \r\nsymmetric and $G$ is transitive on edges.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $\\Delta$ is self-paired, the graph is symmetric.  \r\n\\end{quote}\r\n{\\bf Theorem 6:}\r\n$G$ is primitive iff ${\\cal G}$ is connected.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$G$ is maximal so $G= \\langle G_x , G_y \\rangle , x \\ne y$.\r\n\\end{quote}\r\n{\\bf Definition 6:}\r\nA transitive permutation group is \\emph{regular} if $|X|= |G^X|$ or, equivalently \r\n$|G_x|=1, \\forall x \\in X$ and $G^X$, transitive.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 7:}\r\nLet $X$ be a faithful primitive $G-set$ with $G_x$ simple.  Then either $G$ is simple or\r\nevery non-trivial normal subgroup $H$ of $G$ is a regular normal subgroup.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $1 \\ne H \\lhd G$.  Since $G$ is primitive, $H$ is transitive.  $H_x= H \\cap G_x \\lhd G_x$\r\nso, since $G_x$ is simple,  $H_x = 1$ of $H_x= G_x$.  If $H_x=1$, $H$ is a regular normal subgroup\r\nof $G$.  So $H_x = G_x$ and since $H$ is transitive, $|H:H_x|= |G:G_x|$, so $G$ is simple.\r\n\\end{quote}\r\n{\\bf Definition 7:} $A$ acts \\emph{semi-regularly} on $G$ if $C_G(a)=1, \\forall a \\in A^{\\#}$.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 8:}\r\nSuppose $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\\begin{quote}\r\n\\emph{Proof:}  \r\n(1) each orbit of $A$ on $G^{\\#}$ has length $|A|$.  (2) is clear (second part comes from coprime action).\r\n(3) By Schur, the set of $A$-invariant Sylow $p$-groups is non-empty.  Since $C_G(A)= 1$ is transitive on this\r\nset, the subgroup is unique. (4) $[g,a]= [h,a]$ iff $h g^{-1} \\in C_G(a)$.  The commutator map is already an\r\ninjection and since $G$ is finite, it is a bijection. (5)  Let $t \\in Inv(A)$ and $g \\in G$.  By previous result,\r\n$g= [h,t]$ for some $h \\in G$ and $g^t = (h^{-1} h^t)^t= g^{-1}$.  Therefore $x^t =x^{-1}$ and $G$ is abelian.\r\nFinally, if $s \\in Inv(A)$, $s$ inverts $G$ so $st \\in C_A(G)=1$ and $t$ is unique.\r\n\\end{quote}\r\n{\\bf Theorem 9:}\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$.  \r\nThen $G_{\\delta}= \\langle v(\\gamma)sv(\\gamma^{s})^{-1} | \\gamma \\in \\Delta, s \\in S \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSee, Stellmacher.\r\n\\end{quote}\r\n\\section {Fixed point free automorphisms} \r\n{\\bf Fixed Point Free:}  An automorphism, $\\phi$ acting on $G$ is fixed point free if $C_G(\\phi) =1$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 1:} Let $\\phi$ be a fixed point free automorphism acting on $G$ with $|\\phi|=n$.  Then\r\n(1) $y \\in G$ then $y= x^{-1}(x \\phi)$ for some $x$, and \r\n(2) $\\forall x \\in G, x(x \\phi) (x \\phi^2) \\ldots (x \\phi^{n-1}) = 1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$x^{-1}(x\\phi) = y^{-1}(y\\phi)$ $\\rightarrow$ $y x^{-1} = (y x^{-1})\\phi$, so $x=y$.  Thus\r\n$|{x^{-1}(x\\phi): x \\in G}| = |G|-1$ and (1) holds. Since $\\exists y: x= y^{-1}(y\\phi)$, so\r\n$x(x \\phi) (x \\phi^2) \\ldots (x \\phi^{n-1}) =\r\ny^{-1}(y \\phi) (y \\phi^2) \\ldots (y \\phi^{n-1})^{n-1}) = y^{-1}y = 1$.\r\n\\end{quote}\r\n{\\bf Lemma 2:} Let $\\phi$ be a fixed point free automorphism acting on $G$ then $\\phi$ leaves a unique\r\n$S_p$subgroup of $G$ invariant.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $Q \\in S_p(G), (Q)\\phi = y^{-1}Qy$.  $y^{-1}= (z\\phi)z^{-1}$ and $y = z(z^{-1}]phi)$.\r\n$Q\\phi = (z\\phi) (z^{-1}Q z) (z^{-1}\\phi)$ and $(z^{-1}Qz)\\phi= z^{-1}Qz$ and thus\r\n$\\phi$ leaves $P=z^{-1}Qz$ fixed.  If both $P, Q$ are $\\phi$-invariant and \r\n$Q=x^{-1}Px$ then\r\n$Q=(x^{-1}\\phi)P(x(phi)$ and $(x\\phi)x^{-1} \\in N(P) = N$ but $N$ is $\\phi$-invariant and\r\n$\\phi$ is fixed point free on $N$ so $\\exists z: y=(z\\phi)z^{-1}$.\r\n$(z\\phi)z^{-1}=\r\n(x\\phi)x^{-1}$ $\\rightarrow$ $x=z$.\r\n\\end{quote}\r\n{\\bf Lemma 3:} Let $\\phi$ be a fixed point free automorphism acting on $G$, $H \\lhd G$ and $H= H\\phi$ then\r\n$\\phi$ is fixed point free on $G/H$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet ${\\overline G} = G/H$ and ${\\overline x} = {\\overline x}\\phi$.  ${\\overline x}^{-1}({\\overline x}\\phi)$\r\nso $y= x^{-1}(x\\phi) \\in H$.  Since $\\phi$ induces a fixed point free automorphism on $H$, $y= z^{-1}(z\\phi)$.\r\nSo $x = z$, $x \\in H$ and ${\\overline x} = 1$.  Thus $\\phi$ induces a fixed point free automorphism on\r\n${\\overline G}$.\r\n\\end{quote}\r\n{\\bf Lemma 4:} Let $\\phi$ be a fixed point free automorphism acting on $G$ of order $2$, then $G$ is abelian.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $x(x\\phi) = 1$, $x^{-1} = (x\\phi)$.  If \r\n$x, y \\in G$, $y^{-1}x^{-1} = (xy)^{-1}= ((x\\phi)(y\\phi))^{-1} = x^{-1} y^{-1}$, so $G$ is abelian.\r\n\\end{quote}\r\n{\\bf Lemma 5:} Let $\\phi$ be a fixed point free automorphism acting on $G$ of order $3$, then $G$ is\r\nnilpotent and $[x, x\\phi]=1, \\forall x \\in G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$x(x\\phi)(x\\phi^2)=1$, so $x(x\\phi)= (x\\phi^2)^{-1}$ and $x$ commutes with $x\\phi$ for any $x \\in G$.\r\nLet $P$ be the unique $\\phi$-invariant $S_p$ subgroup of $G, \\forall p \\in \\pi(G)$.  We show\r\n$P \\lhd G$.\r\nSuppose not and\r\n$Q \\ne P \\in S_p(G)$ and pick $x \\in Q \\setminus P$, put $H=\\langle x, x\\phi \\rangle$.\r\n$H$ is a $p$-group since $[x, x\\phi]=1$ and $H'=1$ and $H \\phi = H$.  So $H \\subseteq P$ but then\r\n$x \\in P$.\r\n\\end{quote}\r\n{\\bf Thompson:}\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 of prime order is nilpotent.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $G$ be a counterexample of minimal order and $\\phi$ be a fixed point free automorphism of prime order $r$.\r\n$G$ has a proper normal subgroup, $H \\ne 1$ with $H\\phi=H$.  By induction, $H$ is nilpotent and $\\phi$\r\nis a fixed point free automorphism on $G/H$ so $G/H$ is nilpotent and $G$ is solvable.  If $G$ has no non-trivial\r\nnormal subgroup, which is $H$-invariant.  Let $P \\in S_p(G), p \\ne 2$ with $P\\phi=P$.  Put\r\n$N= N_G({\\mathbb Z}(J(P)))$, $ {\\mathbb Z}(J(P))) \\; char \\; P$.  If $N < G$, $N$ is nilpotent:\r\n$N$ has a normal $p$-complement, $K$.  By the Thompson $p$-complement theorem, $G=KP$, $K\\phi = K$ so\r\n$K = 1$ and $P=G$ so $G$ is nilpotent.  We may assume $G$ is solvable.\r\nSuppose $H_1, H_2 \\lhd G$ $H_i\\phi = H_i$, $H_1 \\cap H_2 = 1$.  ${\\overline G_i} = G/H_i$ is nilpotent\r\nso ${\\overline L} = {\\overline G_1} \\times {\\overline G_2}$ is too.  $x\\phi = (H_1x, H_2x)$.\r\n$\\psi: G \\rightarrow {\\overline G_1} \\times {\\overline G_2}$.  $G\\psi$ is nilpotent.\r\nLet $N$ a minimal normal subgroup of $G$, $N$ is elementary abelian and ${\\overline G} = G/N$ is nilpotent.\r\n${\\overline G}$ is not a $p$-group.  Let ${\\overline Q} \\in S_q({\\overline G})$ with \r\n${\\overline Q} = {\\overline Q} \\phi$, $q \\ne p$.  Let ${\\overline M}$ be a minimal $\\phi$-invariant\r\nsubgroup of $\\Omega_1({\\mathbb Z}({\\overline Q}))$.  ${\\overline M} \\ne 1$ and ${\\overline M} \\lhd {\\overline G}$\r\nsince ${\\overline G}$ is nilpotent.  Let $H$ be the inverse image of ${\\overline M}$ then\r\n$H=NM$ and $M$ is a non-trivial elementary abelian $q$-group.  $H \\lhd G$, $H\\phi = H$ and $M\\phi=M$.\r\n$\\phi$ acts irreducibly on $M$.  $H \\subset G$ then $H$ is nilpotent.\r\n$M \\; char \\; H \\lhd G$ and $M$ and $N$ are two minimal normal $\\phi$-invariant subgroup and\r\n$M \\cap N \\ne 1$.  $C_M(N)\\phi = C_M(N)$ since $\\phi$ acts irreducibly on $M$.  Either\r\n$C_M(N) = 1$ or $C_M(N) = N$.\r\nIf $C_M(N) = N$, $G$ is nilpotent so $C_M(N) = 1$.  Let $G^*$ be the semidirect product of\r\n$M$ by $\\langle \\phi \\rangle$.  $G^*$ acts irreducibly on $N$ as a vector space since\r\n$C_M(N) = 1$ and $\\phi$ is fixed point free.  But $G^*$ is a $p'$-group $C_{M^*}(M) = M$ and\r\n$G^*/M$ has order $q$ so $C_N(\\phi) \\ne 1$.\r\n\\end{quote}\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\\section {Mathieu groups are simple}\r\nWe will use one result from a future section here.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:} \r\nLet $N$ be a finite group $G \\subseteq Aut(N)$.  Then $G$ acts as a permutation group on $N^{\\#}$.  Further, \\\\\r\n(i) If $G$ is transitive, then $N$ is an elementary abelian $p$-group.\r\n\\\\\r\n(ii) If $G$ is $2$-transitive, then $N$ is either an elementary abelian $2$-group or $|N|=3$.\r\n\\\\\r\n(iii) If $G$ is $3$-transitive, then $|N|=4$.\r\n\\\\\r\n(iv) $G$ cannot be $4$-transitive.\r\n\\\\\r\n\\begin{quote}\r\n\\emph{Proof:}  These are all clear.\r\n\\end{quote}\r\n{\\bf Theorem 2:} \r\nLet $G$ be an transitive permutation group and $N \\lhd G$.  Then $N$ is ${\\frac 1 2}$ transitive.  If\r\n$N \\ne 1$ and $G$ is primitive then $N$ is transitive.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $B$ be an orbit of $N$ of minimal length. $B^{Ng}= B^{gN} = B^g$, so $B^g$ is a union of orbits of $N$.\r\nBy minimality of $|B|$, $B^g$ is a single $N$ orbit.  These form a system of imprimitivity.\r\n\\end{quote}\r\n{\\bf Theorem 3:} \r\nLet $G$ be primitive with no regular normal subgroups.  If $G_a$ is simple then $G$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $N \\lhd G$.  $N_a \\leq (N \\cap G_a) \\lhd G_a$ so either $N_a =1$ or $N=G_a$.  If $N_a=1$, $N$\r\nis a regular normal subgroup.\r\n\\end{quote}\r\n{\\bf Theorem 4:} \r\nLet $G$ be $m$-transitive on $A$, $|A|=n$ with a regular normal subgroup, $N$.\\\\\r\n(i) if $m=2$, then $n = |N|= p^k$\r\n\\\\\r\n(ii) if $m=3$, then $n = 3$ or $n = 2^k$ or $n = 3$.\r\n\\\\\r\n(iii) if $m=4$, then $n = 4$.\r\n\\\\\r\n(iv) We cannot have $m>4$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\end{quote}\r\n{\\bf Theorem 5:}  Let $G$ be transitive and $H < G$ also be transitive.  The $G= H G_a$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nClear.\r\n\\end{quote}\r\n{\\bf Theorem:}  The Mathieu groups are simple.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\nStep 1: $M_{11}$ is simple.\\\\\r\n\\\\\r\nPut $G = M_{11}$ so $|G| = 11 \\cdot 10 \\cdot 9 \\cdot 8$.  Let $P=\\langle x\\rangle$ be a subgroup of order\r\n$11$. $P$ acts transitively on $\\Omega$.  If $P \\subseteq A$, $A$, abelian, then $A$ is transitive and regualr so\r\n$A=P$.  Thus $C_G(P)=P$.  Since $|Aut(P)|=10$, $|N_G(P)/P| \\mid 10$.\r\nIf $2 \\mid N_G(P)$ let $y \\in N_G(P), |y|=2$. $y$ has a fixed point since $11$ is odd and $x^y = x^{-1}$.  Thus\r\n$y$ is a product of $5$ transpositions thus $y \\notin A_{11}$ which is a contradiction.  So $|N_G(P)/P|$ is $1$ or $5$.\r\nLet $1 \\ne H \\lhd G, H \\ne G$.  Since $G$ is primitive, $H$ is transitive and $11 \\mid |H|, P \\subseteq H$.\r\n$G= H G_a$ and $G_a \\subseteq N_G(P)$ so $G= H N_G(P)$ and $N_G(P) \\nsubseteq H$ and $N_H(P)=P$.  So, in $H$,\r\n$P$ is in the center of its normalizer and $H$ has a normal $11$ complement, $K$.  $K \\lhd G$ and $11 \\nmid |K|$ so\r\n$K = 1$.  Thus $H=K$ and $|G|=55$, which is a contradiction.\r\n\\\\\r\nStep 2:  $PSL_3(4)$ is simple. This was already shown.\r\n\\\\\r\n\\\\\r\nStep 3:\r\nBy the above result, $M_{12}, M_{22}, M_{23}, M_{24}$ cannot ahve a regular normal subgroup.\r\nThese groups are all $3$-transitive.  $M_{11} = (M_{12})_a$ so $M_{12}$ is simple.\r\n$PSL_3(4)  = (M_{22})_a$, $M_{22} = (M_{23})_a$, and $M_{23} = (M_{24})_a$ proving their simplicity.\r\n\\end{quote}\r\n", "meta": {"hexsha": "8174683e23a1c894ec46be1ea53fe51c77559685", "size": 17353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtPermutations.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/gtPermutations.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/gtPermutations.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": 51.0382352941, "max_line_length": 122, "alphanum_fraction": 0.5947098484, "num_tokens": 6871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6362007535866648}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\\usepackage{mystyle}\n\n\\begin{document}\n\n\\section{Matrices and Vector Spaces}\n\n\\begin{defn}[Echelon Form]\n\tA matrix is in Echelon form if:\n\t\\begin{enumerate}\n\t\t\\item all non-zero rows come before zero rows\n\t\t\\item below each pivot is a column of zeros\n\t\t\\item each pivot is to the right of the previous pivot\n\t\\end{enumerate}\n\n\tIf each pivot is $1$ then the matrix is in row echelon form and if\n\tthere is a column of zeros above each pivot, the matrix is in reduced\n\trow echelon form (RRE).\n\\end{defn}\n\n\\begin{defn}[Rank]\n\tLet $A$ be an $n \\times m$ matrix. Its rank is equal to the number of\n\tnon-zero rows in its echelon form. This is denoted by $\\rho(A)$.\n\\end{defn}\n\n\\begin{defn}[Subspace]\n\tLet $U \\subset \\RR^n$. $U$ is a subspace if:\n\t\\begin{enumerate}\n\t\t\\item $\\bm{0} \\in U$\n\t\t\\item $U$ is closed under addition and scalar multiplication\n\t\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}[Vector Space]\n\t$V$ is a vector space of a field $\\FF$ if:\n\t\\begin{enumerate}\n\t\t\\item addition is commutative and associative\n\t\t\\item neutral and inverse additive elements exist\n\t\t\\item scalar multiplication is commutative and associative\n\t\t\\item $1$ is the neutral scalar\n\t\t\\item $(a+b)\\bm{d} = a\\bm{d} + b\\bm{d} \\quad \\forall a,b \\in \\FF, \\bm{d} \\in V$\n\t\t\\item $(\\bm{a} + \\bm{b})d = \\bm{a}d + \\bm{b}d \\quad \\forall \\bm{a},\\bm{b} \\in V, d \\in \\FF$\n\t\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}[Null Space]\n\tIf $A \\in M_{m \\times n}(\\RR)$, the null space is defined as:\n\t\\[\n\t\tN(A) = \\{ \\bm{x} \\in \\RR^n \\mid A\\bm{x} = \\bm{0} \\}\n\t\\]\n\\end{defn}\n\n\\begin{prop}\n\tIf $A \\in M_{m \\times n}(\\RR)$, the null space $N(A)$ is a\n\tsubspace of $\\RR^n$.\n\\end{prop}\n\n\\begin{proof}\n\tIt is clear that $\\bm{0} \\in N(A)$. It remains to be shown\n\tthat addition and scalar multiplication are closed.\n\n\tLet $x,y \\in \\RR^n$. We know that $\\RR^n$ is a vector space,\n\thence $A(x+y) = Ax + Ay = \\bm{0}$.\n\n\tLet $x \\in \\RR^n, \\, a \\in \\RR$. $A(ax) = a(Ax) = a\\bm{0} = \\bm{0}$.\n\\end{proof}\n\n\\begin{defn}[Image Space]\n\t$Im A = \\{ \\bm{y} \\in \\RR^m \\mid \\bm{y} = A\\bm{x}, \\bm{x} \\in \\RR^n \\}$\n\\end{defn}\n\n\\begin{prop}\n\t$Im A$ is a subspace of $\\RR^m$.\n\\end{prop}\n\n\\begin{proof}\n\tWe know that $\\bm{0} \\in \\RR^n$ hence $A\\bm{0} = 0 \\in Im A$.\n\n\tLet $y_1 = Ax_1, y_2 = Ax_2 \\in \\RR^m$.\n\t\\[\n\t\ty_1 + y_2 = Ax_1 + Ax_2 = A(x_1 + x_2)\n\t\\]\n\t\\[\n\t\tx_1 + x_2 \\in \\RR^n \\Rightarrow y_1 + y_2 \\in Im A\n\t\\]\n\n\tLet $k \\in \\RR, y \\in Im A$.\n\t\\[\n\t\tky = kAx = Akx\n\t\\]\n\t\\[\n\t\tkx \\in \\RR^n \\Rightarrow ky \\in Im A\n\t\\]\n\\end{proof}\n\n\\begin{ex}\n\tFind $N(A)$ and $Im(A)$ where\n\t\\[\n\t\tA =\n\t\t\\begin{pmatrix}\n\t\t\t1  & 3 & -2 \\\\\n\t\t\t-2 & 4 & 4\n\t\t\\end{pmatrix}\n\t\\]\n\n\tFirst we find the RRE of $A$:\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t1  & 3 & -2 \\\\\n\t\t\t-2 & 4 & 4\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 3  & -2 \\\\\n\t\t\t0 & 10 & 0\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 3 & -2 \\\\\n\t\t\t0 & 1 & 0\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & -2 \\\\\n\t\t\t0 & 1 & 0\n\t\t\\end{pmatrix}\n\t\\]\n\n\t$N(A)$:\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & -2 \\\\\n\t\t\t0 & 1 & 0\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tx_1 \\\\\n\t\t\tx_2 \\\\\n\t\t\tx_3\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t0 \\\\\n\t\t\t0 \\\\\n\t\t\t0\n\t\t\\end{pmatrix}\n\t\\]\n\t\\[\n\t\t\\Rightarrow x_2 = 0, \\quad x_1 = 2x_3\n\t\\]\n\t\\[\n\t\t\\Rightarrow N(A) = k\n\t\t\\begin{pmatrix}\n\t\t\t2 \\\\\n\t\t\t0 \\\\\n\t\t\t1\n\t\t\\end{pmatrix}\n\t\t, k \\in \\RR\n\t\\]\n\n\t$Im(A)$:\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\ty_1 \\\\\n\t\t\ty_2 \\\\\n\t\t\ty_3\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1  & 3 & -2 \\\\\n\t\t\t-2 & 4 & 4\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tx_1 \\\\\n\t\t\tx_2 \\\\\n\t\t\tx_3\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\tx_1   + 3x_2 - 2x_3  \\\\\n\t\t\t-2x_1 + 4x_2 + 4x_3\n\t\t\\end{pmatrix}\n\t\\]\n\t\\[\n\t\t= x_1\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t-2\n\t\t\\end{pmatrix}\n\t\t+ x_2\n\t\t\\begin{pmatrix}\n\t\t\t3 \\\\\n\t\t\t4\n\t\t\\end{pmatrix}\n\t\t+ x_3\n\t\t\\begin{pmatrix}\n\t\t\t-2 \\\\\n\t\t\t4\n\t\t\\end{pmatrix}\n\t\\]\n\n\tNote that the vectors in this expression are simply the columns of $A$, in fact in general:\n\t\\[ Im(A) = \\{x_1 a_{i1} + \\cdots + x_1 a_{in}\\} \\]\n\tHence the image space is sometimes referred to as the column space.\n\\end{ex}\n\nAnother example of a vector space is the space of polynomials over a field $\\FF$:\n\\[\n\t\\FF[x] =\n\t\\{a_0 + a_1 x + \\cdots + a_n x^2 \\mid a_i \\in \\FF, n \\in \\NN_0\\}\n\\]\ne.g. $\\RR[x]$ is a vs over $\\RR$.\nAddition and scalar multiplication work as expected.\n\nWe can also define a vs on a set of funtions:\n\\[\n\tV = \\{f:[0,1] \\to \\RR\\}\n\\]\nAddition:\n\\[\n\t(g+f)(x) = g(x) + f(x)\n\\]\nScalar multiplication:\n\\[\n\t(\\alpha f)(x) = \\alpha (f(x)), \\alpha \\in \\RR\n\\]\n\n% TODO: prove these examples ^^.\n\n\\begin{defn}[Transpose]\n\tIf $A = a(i,j) \\in M_{m \\times n}(\\RR)$, then its transpose is\n\t\\[ A^T = a(j,i) \\]\n\ti.e its columns are swapped with its rows.\n\\end{defn}\n\\begin{defn}[Symmetric]\n\tA matrix $A \\in M_{n}(\\RR)$ is called symmetric iff\n\t\\[ A^T = A. \\]\n\\end{defn}\n\nProperties of $A^T$:\n\\[\n\t{(A^T)}^T = A\n\\]\n\\[\n\t{(A+B)}^T = A^T + B^T\n\\]\n\\[\n\t{(AC)}^T = C^T A^T\n\\]\n\n\\section{Spanning sets, linear independence, bases}\n\n\\begin{defn}[Linear Combination]\n\tLet $V$ be a vector space over $\\RR$. A linear combination of vectors in $V$ is given as:\n\t\\[\n\t\t\\alpha_1 v_1 + \\alpha_2 v_2 + \\cdots + \\alpha_r v_r, \\quad\n\t\t\\alpha_i \\in \\RR, \\, v_i \\in V\n\t\\]\n\\end{defn}\n\n\\begin{prop}\n\t$U = \\{\n\t\t\\alpha_1 v_1 + \\alpha_2 v_2 + \\cdots + \\alpha_r v_r \\mid\n\t\t\\alpha_i \\in \\RR, \\, v_i \\in V\n\t\\}$ is a subspace.\n\\end{prop}\n\n\\begin{proof}\n\t\\[\n\t\t\\alpha_i = 0 \\, \\forall i \\Rightarrow 0 + \\cdots + 0 = 0\n\t\\]\n\t\\[\n\t\t\\Rightarrow \\bm{0} \\in U\n\t\\]\n\t\\[\n\t\ta = \\sum_{i=0}^r \\alpha_i v_i \\quad\n\t\tb = \\sum_{i=0}^r \\beta_i v_i \\\\\n\t\\]\n\t\\begin{align*}\n\t\t\\Rightarrow a + b &= \\sum (\\alpha_i v_i + \\beta_i v_i) \\\\\n\t\t&= \\sum (\\alpha_i + \\beta_i) v_i \\in U\n\t\\end{align*}\n\n\t\\[\n\t\ta = \\sum \\alpha_i v_i \\quad \\lambda \\in \\RR\n\t\\]\n\t\\[\n\t\t\\lambda a = \\sum \\lambda \\alpha_i v_i \\quad\n\t\t\\lambda \\alpha_i \\in \\RR \\, \\forall i\n\t\t\\Rightarrow \\lambda a \\in U\n\t\\]\n\\end{proof}\n\n\\begin{defn}[Spanning Set]\n\tLet $V$ be a vector space and $W$ be a subspace. A set of vectors\n\t$\\{v_1, \\ldots, v_r\\} \\subset V$ is a spanning set for $W$ if\n\t\\[\n\t\tW =\n\t\t\\{\\alpha_1 v_1 + \\cdots + \\alpha_r v_r \\mid \\alpha_i \\in \\RR\\}\n\t\t= sp\\{v_1, \\ldots, v_r\\}\n\t\\]\n\tWe say that $\\{v_1, \\ldots, v_r\\}$ spans $W$.\n\\end{defn}\n\n\\begin{ex}\n\tIf $A = \\begin{pmatrix}\n\t\t1  & 3 & -2 \\\\\n\t\t-2 & 4 & 4\n\t\\end{pmatrix}$ we know that\n\t\\[\n\t\tIm(A) = x_1\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t-2\n\t\t\\end{pmatrix}\n\t\t+ x_2\n\t\t\\begin{pmatrix}\n\t\t\t3 \\\\\n\t\t\t4\n\t\t\\end{pmatrix}\n\t\t+ x_3\n\t\t\\begin{pmatrix}\n\t\t\t-2 \\\\\n\t\t\t4\n\t\t\\end{pmatrix}\n\t\\]\n\n\tWe can also say that\n\t\\[\n\t\tIm(A) = sp\\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t-2\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t3 \\\\\n\t\t\t\t4\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t-2 \\\\\n\t\t\t\t4\n\t\t\t\\end{pmatrix}\n\t\t\\right\\}\n\t\\]\n\tsince every element in $Im(A)$ is a linear combination of these vectors.\n\\end{ex}\n\n\\begin{ex}\n\t\\[\n\t\t\\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t0 \\\\\n\t\t\t\t0\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t0 \\\\\n\t\t\t\t1 \\\\\n\t\t\t\t0\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t0 \\\\\n\t\t\t\t0 \\\\\n\t\t\t\t1\n\t\t\t\\end{pmatrix}\n\t\t\\right\\}\n\t\\]\n\tspans $\\RR^3$.\n\\end{ex}\n\n\\begin{ex}\n\tLet\n\t\\[\n\t\tW = \\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\ta + b + 2c \\\\\n\t\t\t\tb + c \\\\\n\t\t\t\ta + c\n\t\t\t\\end{pmatrix}\n\t\t\t\\mid a,b,c \\in \\RR\n\t\t\\right\\}\n\t\t\\subset \\RR^3\n\t\\]\n\tthen\n\t\\[\n\t\tw = a\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t0 \\\\\n\t\t\t1\n\t\t\\end{pmatrix}\n\t\t+ b\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t1 \\\\\n\t\t\t0\n\t\t\\end{pmatrix}\n\t\t+ c\n\t\t\\begin{pmatrix}\n\t\t\t2 \\\\\n\t\t\t1 \\\\\n\t\t\t1\n\t\t\\end{pmatrix}\n\t\t\\forall w \\in W\n\t\\]\n\t\\[\n\t\t\\Rightarrow W = sp\\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t0 \\\\\n\t\t\t\t1\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t1 \\\\\n\t\t\t\t0\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t2 \\\\\n\t\t\t\t1 \\\\\n\t\t\t\t1\n\t\t\t\\end{pmatrix}\n\t\t\\right\\}\n\t\\]\n\n\tAlso, since\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t2 \\\\\n\t\t\t1 \\\\\n\t\t\t1\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t0 \\\\\n\t\t\t1\n\t\t\\end{pmatrix}\n\t\t+\n\t\t\\begin{pmatrix}\n\t\t\t1 \\\\\n\t\t\t1 \\\\\n\t\t\t0\n\t\t\\end{pmatrix},\n\t\\]\n\t\\[\n\t\tW = sp\\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t0 \\\\\n\t\t\t\t1\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t1 \\\\\n\t\t\t\t0\n\t\t\t\\end{pmatrix}\n\t\t\\right\\}\n\t\\]\n\\end{ex}\n\n\\begin{defn}[Linear Independence]\n\tLet $V$ be a vector space. A set of vectors\n\t$\\{v_1, \\ldots, v_r \\mid v_i \\in V \\}$\n\tis linearly independent if\n\t\\[\n\t\t\\alpha_1 v_1 + \\cdots + \\alpha_r v_r = 0\n\t\t\\implies \\alpha_1 = \\cdots = \\alpha_r = 0.\n\t\\]\n\\end{defn}\n\n\\begin{thm}\n\tLet $v_1, \\ldots, v_r \\in \\RR^n$ and $A$ be the matrix whose\n\tcolumns correspond to the vectors $v_i$, then the set\n\t$\\{v_1, \\ldots, v_r\\}$ is linearly independent iff\n\t$A\\bm{x} = 0$ has the unique solution $x = 0$ iff $\\rho(A) = r$.\n\\end{thm}\n\n\\begin{proof}\n\tBy definition of linear independence,\n\t\\[\n\t\tx_1 v_1 + \\cdots + x_r v_r = 0\n\t\t\\iff\n\t\tx_i = 0 \\, \\forall i\n\t\\]\n\tThis is clearly equivalent to saying that $\\bm x$ is the\n\tonly solution to $A\\bm x = 0$.\n\n\tA matrix equation like this can have a unique solution iff\n\t$\\rho(A) = r$, otherwise there would be free variables resulting\n\tin a range of solutions.\n\\end{proof}\n\nWe now know that any matrix whose rank is equal to the number of its\nrows forms a linearly independent spanning set for a subspace of\n$\\RR^n$.\n\n\\begin{cor}\n\tAny set of $m > n$ vectors in $\\RR^n$ is linearly dependent.\n\\end{cor}\n\n\\begin{cor}\n\tThe columns of the indentity matrix $I_n$ form a linearly\n\tindependent spanning set of $\\RR^n$.\n\\end{cor}\n\n\\begin{defn}[Basis]\n\tA subset $B$ of a vector space $V$ is called a basis of $V$ if $B$ is linearly independent and $B$ spans $V$.\n\\end{defn}\n\n\\begin{rem}\n\tWhen considering $\\RR^n$ or its subsets, a basis will always be\n\tfinite; however a basis can be infinite, for example\n\t$\\{1, x, x^2, \\ldots\\}$ is a basis of $\\RR[x]$.\n\\end{rem}\n\n\\begin{ex}\n\t\\[\n\t\t\\left\\{\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t2 \\\\\n\t\t\t\t3\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t1 \\\\\n\t\t\t\t-1 \\\\\n\t\t\t\t0\n\t\t\t\\end{pmatrix}\n\t\t\t,\n\t\t\t\\begin{pmatrix}\n\t\t\t\t5 \\\\\n\t\t\t\t4 \\\\\n\t\t\t\t4\n\t\t\t\\end{pmatrix}\n\t\t\\right\\}\n\t\\]\n\tis a basis of $\\RR^3$.\n\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t1 & 1  & 5 \\\\\n\t\t\t2 & -1 & 4 \\\\\n\t\t\t3 & 0  & 4\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 1  & 5  \\\\\n\t\t\t0 & -3 & -6 \\\\\n\t\t\t0 & -3 & -11\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 1  & 5  \\\\\n\t\t\t0 & -3 & -6 \\\\\n\t\t\t0 & 0  & -5\n\t\t\\end{pmatrix}\n\t\\]\n\n\tWe can see that the rank is $3$ hence this set is linearly independent.\n\t\\[\n\t\t\\begin{pmatrix}\n\t\t\t1 & 1  & 5  \\\\\n\t\t\t0 & -3 & -6 \\\\\n\t\t\t0 & 0  & -5\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 1 & 5  \\\\\n\t\t\t0 & 1 & -2 \\\\\n\t\t\t0 & 0 & 1\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t1 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 1\n\t\t\\end{pmatrix}\n\t\\]\n\n\tThis shows that this set spans $\\RR^3$ and is therefore a basis.\n\\end{ex}\n\n\\begin{thm}\n\tLet $V$ be a vector space over $\\RR$. If $U = \\{v_1, \\ldots,\n\tv_r\\}$ spans $V$ and no proper subset of $U$ spans $V$, then $U$\n\tis a basis for $V$.\n\\end{thm}\n\n\\begin{proof}\n\tWe know that $U$ spans $V$ so we need only prove that $U$ is linearly independent. We will do so using the contrapositive method.\n\n\tIf $U$ is not linearly independent then $\\exists v_i \\in U$ such that\n\t\\[\n\t\tv_i = \\alpha_1 v_1 + \\cdots + \\alpha_{i-1} v_{i-1} +\n\t\t\\alpha_{i+1} v_{i+1} + \\cdots + \\alpha_r v_r\n\t\\]\n\t\\[\n\t\t\\implies\n\t\tW = {v_1, \\ldots, v_{i-1}, v_{i+1}, \\ldots, v_r}\n\t\t\\subset U\n\t\\]\n\tspans $V$.\n\n\tTherefore, if there is no such $W$, $U$ must be linearly\n\tindependent and hence a basis.\n\\end{proof}\n\n\\begin{thm}\n\tLet $V$ be a vector space over $\\RR$. If $U = \\{v_1, \\ldots, v_r\\}$\n\tis a linearly independent subset of $V$ and no proper, linearly\n\tindependent  subset $W$ of $V$, where $W$ contains $U$, then $U$\n\tis a basis of $V$.\n\\end{thm}\n\n\\begin{proof}\n\tWe know $U$ is linearly independent so we need only show that it\n\tspans $V$.\n\n\tLet $v \\in V \\setminus U$. According to our assumption that no\n\tlinearly independent subset exists between $U$ and $V$, this\n\tmeans that $\\{v_1, \\ldots, v_r, v\\}$ is  not linearly\n\tindependent; hence any element in this set can be expressed as a\n\tlinear combination of the rest.\n\n\t\\[\n\t\t\\implies\n\t\tv = \\sum_{i=1}^r \\alpha_i v_i \\quad \\forall v \\in V\n\t\\]\n\n\tTherefore, $U$ spans $V$ and $U$ is a basis for $V$.\n\\end{proof}\n\n%TODO: look into Mac Lane generalisation of this lemma.\n\\begin{lemma}[Exchange (Steinitz)]\n\tLet $V$ be a vector space. Let $S = \\{a_1, \\ldots, \\_s\\}$ be a\n\tspanning set for a subspace $U \\subset V$ and let $B = \\{b_1,\n\t\\ldots, b_r\\}$ be a linearly independent subset of $U$. The $r\n\t\\leq s$ and there exists a set $S_r$ containing $B$ and some\n\telements from $S$ such that $U$ is spanned by $S_r$.\n\\end{lemma}\n\n%TODO: be consistent with sp and span, declare them as operators:\n%\\DeclareMathOperator\\span{span}\n\\begin{proof}\n\t\\[\n\t\tb_1 \\in U = sp(S)\n\t\t\\implies b_1 = \\sum_{i=1}^s \\alpha_i a_i,\n\t\\]\n\twhere not all $a_i = 0$ (else $b_1 = 0$).\n\t\\[\n\t\t\\implies a_1 = \\alpha_1^{-1}\n\t\t( b_1 - \\alpha_2 a_2 - \\cdots - \\alpha_s a_s )\n\t\\]\n\n\tAssume we have replaced $(a_1, \\ldots, a_k)$ with\n\t$(b_1, \\ldots, b_k)$ in this manner, so that\n\t$U$ is spanned by $\\{ b_1, \\ldots, b_k, a_{k+1}, \\ldots, a_s \\}$.\n\n\tExchange $b_{k+1}$:\n\t\\[ b_{k+1} \\in U \\]\n\t\\[\n\t\t\\implies b_{k+1} =\n\t\t\\beta_1 b_1 + \\cdots + \\beta_k b_k\n\t\t+ \\alpha_{k+1} a_{k+1} + \\cdots + \\alpha_s a_s\n\t\\]\n\tagain, not all coefficients are zero.\n\n\tAt least one $\\alpha_i \\neq 0$ else $b_{k+1}$ would be a linear\n\tcombination of $\\{ b_1, \\ldots, b_k \\}$.\n\n\t\\[\n\t\t\\implies \\alpha_{k+1} = \\alpha_{k+1}^{-1}\n\t\t(\n\t\t\tb_{k+1} - \\beta_1 b_1 - \\cdots - \\beta_k b_k\n\t\t\t- \\alpha_{k+2} a_{k+2} - \\cdots - \\alpha_s a_s\n\t\t)\n\t\\]\n\n\tSo for all $1 \\leq k \\leq r$ we can replace $a_k$ with $b_k$, giving:\n\t\\[\n\t\tU = span \\{ b_1, \\ldots, b_{k+1}, a_{k+2}, \\ldots, a_s \\}\n\t\\]\n\\end{proof}\n\nThis result is significant because when we have a basis, $B$, for a\nvector space, $V$, it can be used as the linearly independent set or the\nspanning set. This tells us that any spanning set for $V$ has a greater\nor equal cardinality compared with $B$ and that any linearly independent\nsubset of $V$ has a cardinality smaller than or equal to that of $B$.\nThe next result follows from this.\n\n\\begin{cor}\n\tAny two bases for a vector space have the same number elements.\n\\end{cor}\n\n\\begin{defn}[Dimension]\n\tThe number of elements in a basis for a vector space is the dimension of the vector space.\n\\end{defn}\n\n\\begin{rem}\n\tLet $U$ be a vector space with dimension $n$ and $S \\subset U$\n\tsuch that $|S| = n$. If $S$ spans $U$ or if $S$ is linearly\n\tindependent, then $S$ must be a basis of $U$.\n\\end{rem}\n\n\\section{Rank and Nullity}\n\n\\begin{defn}[Nullity]\n\tThe nullity of a matrix $A$ is the dimension of its null space.\n\\end{defn}\n\n\\begin{defn}[Rowspace]\n\tLet $A \\in M_{m \\times n}$ an $a_{ij}$ be the $i^{th}$ row of $A$.\n\tThe rowspace of $A$ is:\n\t\\[\n\t\tsp \\{ a_{1j}, \\ldots, a{nj} \\}\n\t\\]\n\\end{defn}\n\nNote that the dimension of the rowspace is the number of non-zero rows\nin echelon form, i.e.\\ the (row) rank. We can refer to the column rank as\nthe dimension of the column/image space.\n\n\\begin{thm}[Row rank equals column rank]\n\tLet $A \\in M_{m \\times n}$, then $\\rho(A) = \\rho(A^T)$. In other\n\twords, the row rank and column rank are equal.\n\\end{thm}\n\n\\begin{proof}\n\tLet the column rank of $A$ be $r = \\rho(A^T)$. Let $C$ be the\n\tmatrix whose columns form a basis for the column space of $A$.\n\n\tEvery column of $A$ can be expressed as a linear combination of\n\tthe columns in $C$ hence there is a matrix $R$ such that\n\t$A = CR$.\n\n\tThis means that every column of $A$ can be given as a linear\n\tcombination of the rows of $R$, which implies that it is a\n\tspanning set for the row space of $A$.\n\n\tThere are $r$ columns in $C$, hence $r$ rows in $R$ so, by the\n\tExchange Lemma, we know that $\\rho(A) \\leq r = \\rho(A^T)$.\n\n\tWe can apply this same process to the matrix $A^T$, where the\n\trows and columns (and hence their ranks) are swapped. From this\n\twe see that $\\rho(A^T) \\leq \\rho({(A^T)}^T) = \\rho(A)$.\n\n\t\\[\n\t\t\\implies \\rho(A) = \\rho(A^T)\n\t\\]\n\\end{proof}\n\n\\begin{thm}\n\tLet $A \\in M_n(\\RR)$ with $Ax = b$, then the following statement\n\tare equivalent:\n\t\\begin{enumerate}\n\t\t\\item\n\t\t\t$Ax = b$ has a unique solution\n\t\t\\item\n\t\t\t$\\rho(A) = n$\n\t\t\\item\n\t\t\t$A$ is equivalent to $I_n$\n\t\t\\item\n\t\t\t$A$ is invertible\n\t\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n\tWe have already seen $1 \\iff 2$ and $2 \\iff 3$ is obvious\n\tconsidering the RRE form of $A$.\n\n\t$3 \\implies 4$ because by reducing $A$ to $I_n$, we can use the\n\tproduct of the row operations to construct the inverse matrix.\n\n\t$4 \\implies 3$:\n\t\\[ \\exists A^{-1} \\implies A^{-1}A = I_n \\]\n\t$A^{-1}$ can be split into row operations that, when applied to\n\t$A$, yields $I_n$.\n\\end{proof}\n\n\\section{Determinants}\n\n\\begin{defn}\n\tThe $(i,j)$-minor of $A \\in M_n$ is the $(n-1)\\times(n-1)$\n\tmatrix obtained by removing the $i^{th}$ row and $j^{th}$\n\tcolumn. It is often denoted $M_{i,j}$.\n\\end{defn}\n\n\\begin{defn}[Determinant]\n\tThe determinant is defined recursively:\n\t\\[ n=1 \\implies \\det [a] = a \\]\n\t\\[ n=k \\implies \\det A = \\sum_{j=1}^k a_{1,j} C_{1,j} \\]\n\twhere\n\t\\[ C_{i,j} = {(-1)}^{i+j} \\det(M_{i,j}) \\]\n\tis the $(i,j)$-cofactor.\n\\end{defn}\n\n\\subsection{Properties of the Determinant}\n\n\\begin{enumerate}\n\t\\item\n\t\tIf any row is all zeros, $\\det A = 0$\n\t\\item\n\t\tIf $B$ is obtained by adding one row of $A$ to a\n\t\tdifferent one, $\\det A = \\det B$\n\t\\item\n\t\tIf $B$ is obtained by swapping one row of $A$ with\n\t\tanother, $\\det A = -\\det B$\n\t\\item\n\t\tIf $B$ is obtained by multiplying one row of $A$ by\n\t\t$\\alpha$, $\\alpha \\det A = \\det B$\n\t\\item\n\t\tIf $A$ is upper triangular, then $\\det A$ is the product\n\t\tof the diagonal elements\n\t\\item\n\t\t$\\det(A^T) = \\det(A)$\n\t\\item\n\t\t$\\det(AB) = \\det(A) \\det(B)$\n\\end{enumerate}\n\nWe will not prove most of these here, but property 5 can be deduced\nsimply enough using the others and induction.\n\n\\begin{proof}\nThe $n=1$ case is obvious, so we may assume the property holds for\n$n=k$.\n\n\\[\n\tA =\n\t\\begin{bmatrix}\n\t\ta_{1,1}   & \\cdots & a_{1,k}   & a_{1,k+1} \\\\\n\t\t\\vdots    & \\ddots & \\vdots    & \\vdots    \\\\\n\t\ta_{k,1}   & \\cdots & a{k,k}    & a_{k,k+1} \\\\\n\t\ta_{k+1,1} & \\cdots & a_{k+1,k} & a_{k+1,K+1}\n\t\\end{bmatrix}\n\\]\n\nThe other row properties allow us to traverse any row in order to\ncalculate the determinant, so we can choose the bottom row. This is all\nzeros except for the element $a_{k+1,k+1}$. We can see that\n\\[\n\t\\det A = a_{k+1,K+1} \\det A_k\n\\]\nwhich is the product of the diagonals.\n\\end{proof}\n\nSome futher properties can be deduced from those we have already described:\n\\begin{itemize}\n\t\\item\n\t\tIf any two rows are identical then $\\det A = 0$ (using 1,2,4)\n\t\\item\n\t\tAll row properties also apply to columns (due to 6)\n\t\\item\n\t\tThe determinant is commutative (due to 7)\n\t\\item\n\t\t$\\det(\\alpha A) = \\alpha^n \\det A$ (due to 4)\n\t\\item\n\t\t$\\det I_n = 1$ (using 5)\n\\end{itemize}\n\n\\section{Eigenvalues and Eigenvectors}\n\n\\begin{defn}[Eigenvalues and Eigenvectors]\n\tLet $A \\in M_n(\\RR)$ and $\\lambda \\in \\RR$. If $\\exists x \\neq\n\t0$ such that $Ax = \\lambda x$, then $\\lambda$ is called an\n\tEigenvalue of $A$ and $x$ is called an Eigenvector of $A$.\n\\end{defn}\n\n\\begin{lemma}\n\t$\\exists A^{-1} \\iff |A| \\neq 0$\n\\end{lemma}\n\n%TODO: deduce the method for calculating the inverse (springer)\n\\begin{proof}\n\tAssume $\\exists A^{-1}$\n\t\\[ \\implies |A^{-1}A| = |I| = 1 \\]\n\t\\[ \\implies |A^{-1}||A| = 1 \\]\n\t\\[ \\implies |A| \\neq 0 \\]\n\n\tAssume $|A| \\neq 0$. This means we can use the standard method\n\tto calculate the inverse.\n\\end{proof}\n\n\\begin{lemma}\n\t$\\lambda$ is an Eigenvalue $\\iff |A - \\lambda I_n| = 0$.\n\\end{lemma}\n\n\\begin{proof}\n\t\\[ Ax = \\lambda x \\iff Ax = \\lambda I_n x \\iff (A - \\lambda I_n)x = 0 \\]\n\n\tBy definition, $x \\neq 0$ hence $(A - \\lambda I_n)$ cannot have an inverse.\n\n\t\\[ \\iff |A - \\lambda I_n| = 0 \\]\n\\end{proof}\n\n\\begin{defn}[Characteristic Equation]\n\t$|A - \\lambda I_n| = 0$ is called the characteristic equation of\n\t$A$. Solving it for $\\lambda$ yields eigenvalues for $A$, which\n\tcan be used to find eigenvectors from $(A - \\lambda I_n)x = 0$.\n\\end{defn}\n\n\\section{Linear Transformations}\n\n\\begin{defn}[Linear Transformation]\n\tLet $V$ and $W$ be vector spaces over $\\RR$. A function $T:V \\to\n\tW$ is a linear transformation if $\\forall v_1, v_2 \\in V, \\alpha\n\t\\in \\RR$ we have\n\t\\begin{enumerate}\n\t\t\\item\n\t\t\t$T(v_1 + v_2) = T(v_1) + T(v_2)$\n\t\t\\item\n\t\t\t$T(\\alpha v_1) = \\alpha T(v_1)$\n\t\\end{enumerate}\n\\end{defn}\n\n\\begin{defn}[Kernel]\n\t\\[ \\ker T = \\{ v \\in V \\mid T(v) = 0 \\} \\]\n\\end{defn}\n\n\\begin{defn}\n\t\\[ \\im T = \\{ w \\in W \\mid w = T(v), v \\in V \\} \\]\n\\end{defn}\n\n\\begin{prop}\n\t$\\ker T$ is a subspace of $V$ and $\\im T$ is a subspace of $W$.\n\\end{prop}\n\n\\begin{proof}\n\tLet $v_1, v_2 \\in \\ker T$, then\n\t\\[ T(0) = T(v_1-v_1) = T(v_1) - T(v_1) = 0 \\implies 0 \\in \\ker T \\]\n\t\\[ T(v_1 + v_2) = T(v_1) + T(v_2) = 0 \\]\n\t\\[ T(\\alpha v_1) = \\alpha T(v_1) = \\alpha \\cdot 0 = 0 \\]\n\n\t$T(v_1), T(v_2) \\in \\im T$\n\t\\[ T(0) = T(v_1 - v_1) = T(v_1) - T(v_1) = 0 \\]\n\t\\[ v_1 + v_2 \\in V \\implies T(v_1) + T(v_2) = T(v_1 + v_2) \\in \\im T \\]\n\t\\[ \\alpha v_1 \\in V \\implies \\alpha T(v_1) = T(\\alpha v_1) \\in \\im T \\]\n\\end{proof}\n\n\\begin{prop}\n\tLet $T$ be a linear map. $T$ is injective $\\iff \\ker T = 0$.\n\\end{prop}\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t& &(T(x) = T(y) \\implies x = y) \\\\\n\t\t&\\iff &(T(x) - T(y) = 0 \\implies x - y = 0) \\\\\n\t\t&\\iff &(T(x-y) = 0 \\implies x-y = 0) \\\\\n\t\t&\\iff &(T(v) = 0 \\implies v = 0) \\\\\n\t\t&\\iff &\\ker T = 0\n\t\\end{align*}\n\\end{proof}\n\n\\begin{rem}\n\tIt is clear that $T: V \\to W$ is surjective $\\iff \\im T = W$.\n\\end{rem}\n\n\\begin{defn}[Isomorphism]\n\tA linear transformation $T:V \\to W$ is an isomorphism if $T$ is\n\tbijective i.e.\\ $\\ker T = 0$ and $\\im T = W$.\n\\end{defn}\n\n\\begin{defn}\n\tLet $T:V \\to W$ be a linear transformation. Let $v_1, \\ldots,\n\tv_n$ be a basis for $V$, then the matrix of the transformation\n\tis the matrix $M_T \\in M_{m \\times n}$ whose columns are\n\t$T(v_i)$.\n\\end{defn}\n\n\\begin{prop}\n\tLet $T:\\RR^n \\to \\RR^m$ be a linear transformation, then $T(x) =\n\tM_T \\cdot x$.\n\\end{prop}\n\n\\begin{proof}\n\tLet $\\{e_I\\}$ be the stadard basis for $\\RR^n$ (columns of $I_n$) and $T(e_i) = f_i$.\n\t\\begin{align*}\n\t\tT(x) &= T\n\t\t\\left(\n\t\t\t\\begin{pmatrix}\n\t\t\t\tx_1 \\\\\n\t\t\t\t\\vdots \\\\\n\t\t\t\tx_n\n\t\t\t\\end{pmatrix}\n\t\t\\right) \\\\\n\t\t&= T(x_1 e_1 + \\cdots + x_n e_n) \\\\\n\t\t&= x_1 T(e_1) + \\cdots + x_n T(e_n) \\\\\n\t\t&= x_1 f_1 + \\cdots + x_n f_n \\\\\n\t\t&=\n\t\t\\begin{pmatrix}\n\t\t\t\\uparrow   &        & \\uparrow \\\\\n\t\t\tf_1        & \\cdots & f_n      \\\\\n\t\t\t\\downarrow &        & \\downarrow\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tx_1 \\\\\n\t\t\t\\vdots \\\\\n\t\t\tx_n\n\t\t\\end{pmatrix} \\\\\n\t\t&= M_T \\cdot x\n\t\\end{align*}\n\\end{proof}\n\n\\begin{cor}\n\tLet $T:V \\to W$ be a linear transformation and $M_T$ be its\n\tmatrix with respect to the bases $B_V$ and $B_W$, then\n\t\\begin{align*}\n\t\t\\ker T & = N(M_T) \\\\\n\t\t\\im T  & = \\im M_T\n\t\\end{align*}\n\\end{cor}\n\n\\begin{defn}[Change of basis]\n\tThe matrix of $id:V \\to W$ with respect to the bases $B_1$ and\n\t$B_2$ is called the change of basis matrix, from $B_1$ to $B_2$.\n\\end{defn}\n\n\\begin{defn}[Eigenvalues and Eigenvectors]\n\tLet $T:V \\to W$ be a linear transformation. If $\\exists \\lambda\n\t\\in \\RR$ and $0 \\neq v \\in V$ such that $T(v) = \\lambda v$, then\n\t$\\lambda$ is and eigenvalue and $v$ is an eigenvector.\n\\end{defn}\n\n\\end{document}\n", "meta": {"hexsha": "c316888834a2585407667cab1ec12bbc0324e5d4", "size": 22834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/linear_algebra.tex", "max_stars_repo_name": "judgedreads/maths", "max_stars_repo_head_hexsha": "51ff47883510cd0d8281a024dcdcd7fa634d23dd", "max_stars_repo_licenses": ["MIT"], "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/linear_algebra.tex", "max_issues_repo_name": "judgedreads/maths", "max_issues_repo_head_hexsha": "51ff47883510cd0d8281a024dcdcd7fa634d23dd", "max_issues_repo_licenses": ["MIT"], "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/linear_algebra.tex", "max_forks_repo_name": "judgedreads/maths", "max_forks_repo_head_hexsha": "51ff47883510cd0d8281a024dcdcd7fa634d23dd", "max_forks_repo_licenses": ["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.1045498548, "max_line_length": 130, "alphanum_fraction": 0.5904353158, "num_tokens": 9475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6362007464904963}}
{"text": "\\chapter{Statistics in Photometry}\n\nSo far we've seen how the photometry should be done. But we haven't seriously discussed how to analize the uncertainties, i.e., the error-bars of each measurement such as magnitude. \n\n\\section{Pixel-wise Uncertainty}\nAn object frame consist of at least bias, dark, flat, cosmic-ray, target's signal, and sky, as well as readout noise. For the $ j $-th pixel, they are denoted as:\n\\begin{itemize}\n\\item $ \\tilde{N}_j $: the raw pixel value of the object frame in ADU.\n\\item $ B_j $: the bias in ADU.\n\\item $ D_j $: the dark in ADU.\n\\item $ F_j $: the flat in ADU (\\textit{not necessarily} normalized; see \\textbf{Note} at the end).\n\\item $ C_j $: the cosmic-ray in ADU.\n\\item $ I_j $: the object signal count in ADU.\n\\item $ S_j $: the sky signal in ADU.\n\\end{itemize}\nIn some cases, such as infrared detectors, the gain and readout noise may differ for each pixel, so I will denote gain and readout noise of the $ j $-th pixel as $ g_j \\,[\\mathrm{e/ADU}]$ and $ R_j \\,[\\mathrm{e}] $. Then we define the bias-subtracted pixel value\n\\begin{equation}\n  N_j = \\tilde{N}_j - B_j = D_j + (I_j + S_j + C_j) F_j\n\\end{equation}\nNote that the dark is not affected by the flat value. Since this pixel value should follow a Poisson distribution, which is approximated as a Gaussian distribution,\n\\begin{equation}\n  N_j \n    \\simdot \\mathcal{N} \\left (\n      N_j ,~ \n      \\frac{N_j}{g_j} + \\left (\\frac{R_j}{g_j} \\right )^2 \n    \\right ) ~.\n\\end{equation}\n\n\\subsection{Dark Estimation}\nTo estimate dark $ D_j $, you should have taken nearly tens of dark frames, and combined it. From the median value of the frames, you may have obtained the estimation of the dark $ \\hat{D}_j $ (for brevity, I will just use $ D_j $ without the caret $ \\hat{\\cdot} $). During the combination, you can obtain the uncertainty of the dark at the $ j $-th pixel, $ \\Delta D_j $, as\n\\begin{equation}\n  \\Delta D_j = \\mathrm{sstd} (D_j^{i=1..N_\\mathrm{Dark}}) \n    := \\sqrt{ \\frac{\\sum_{i=1}^{N_\\mathrm{Dark}} (D_j^{i} - \\bar{D})^2}\n      {N_\\mathrm{Dark} - 1}} \n    \\equiv \\mathrm{std}(D_j^{i=1..N_\\mathrm{Dark}}) \n      \\times \\sqrt{\\frac{N_\\mathrm{Dark}}{N_\\mathrm{Dark} - 1}} ~,\n\\end{equation}\nwhere $ D_j^{i} $ is the dark current (ADU) of the $ j $-th pixel at the $ i $-th dark frame, $ \\mathrm{sstd} $ and $ \\mathrm{std} $ are the \\textit{sample} standard deviation (\\texttt{np.std(x, ddof=1)}) and standard deviation (\\texttt{np.std(x)}) functions, respectively, and $ N_\\mathrm{Dark} $ is the number of dark framses used. Here it is assumed $ D_j $ roughly follows a Gaussian distribution so that $ \\mathrm{sstd} $ becomes an unbiased estimator\\footnote{An unbiased estimator of a random variable $ X $, $ \\hat{X} $ is defined such that the expectation value of $ \\hat{X} $ is the same as the true value $ X_\\mathrm{true} $.} of the true standard deviation. Note that you should \\emph{not} divide it by the number of dark frames (such as Thm \\ref{thm: clt}), because \\textbf{what you will need is not the uncertainty of the \\emph{mean} value, but the uncertainty of one pixel value that will have been added to the object frame}. \n%, and $ N_\\mathrm{Dark} $ is the number of dark frames. This is based on the CLT (Thm \\ref{thm: clt}). Note the strong point of the CLT helps us here: CLT holds regardless of the distribution of $ D_j^{i} $! Even if we don't know anything about its distribution, we can use CLT without caring about it.\n\nTherefore, to the first order,\n\\begin{equation}\n\\begin{aligned}\n  \\tilde{O}_j = N_j - D_j \n    &\\simdot \\mathcal{N} \n      \\left ( \\tilde{O}_j,~ \n        \\frac{N_j}{g_j} + \\left (\\frac{R_j}{g_j} \\right )^2 + (\\Delta D_j)^2 \\right ) \\\\\n  \\mathrm{or}\n    &\\simdot \\mathcal{N} \n        \\left ( \\tilde{O}_j,~ \n          \\frac{\\tilde{O}_j}{g_j} \n          + \\frac{D_j}{g_j} \n          + \\left (\\frac{R_j}{g_j} \\right )^2 \n          + (\\Delta D_j)^2 \\right ) ~.\n\\end{aligned}\n\\end{equation}\nNote that we have been using $ N_j/g_j = (\\tilde{O}_j + D_j)/g_j $ term in $ \\Delta N_j $. This makes sence only if the Poissonity of dark is assumed.\n\n\\subsection{Flat Estimation}\nUnlike the dark current, which is a probabilistic electron generation, the flat, i.e., the pixel sensitivity, is a characterestic value of the detector and optics, so it should not change at each exposure. Therefore, following the CLT (Thm \\ref{thm: clt}): \n\\begin{equation}\n  \\Delta F_j \n    = \\frac{\\mathrm{sstd} (F_j^{i=1..N_\\mathrm{Flat}})} {\\sqrt{N_\\mathrm{Flat}}}\n    := \\sqrt{ \\frac{1}{N_\\mathrm{Flat}}\n       \\frac{\\sum_{i=1}^{N_\\mathrm{Flat}} (F_j^{i} - \\bar{F})^2}{N_\\mathrm{Flat} - 1}} \n       \\equiv \\frac{\\mathrm{std}(F_j^{i=1..N})}{\\sqrt{N_\\mathrm{Flat} - 1}} ~,\n\\end{equation}\nwhere $ F_j^{i} $ is the flat frame pixel value (ADU) of the $ j $-th pixel at the $ i $-th flat frame, $ \\mathrm{sstd} $ is the sample standard deviation function and $ N_\\mathrm{Flat} $ is the number of the used flat frames. \n\nGenerally speaking, $ F_j $ must be about $ 10^4 $ ADU or more, so that the signal-to-noise ratio from Poisson statistics is larger than about 100. Moreover, you should have obtained, say, $ N_\\mathrm{flat} = 9 $, this will increase by a factor of 3. Therefore, the uncertainty in the flat $ \\Delta F_j $, is around 0.1 \\% order. In some observatories, people take hundreds of flats at one time to get flat as good as roughly 0.01 \\% order, assuming it won't change over certain period of time.\n\nAlthough there are mathematically known ratio distribution, i.e., the pdf of $ Z := X/Y $ where $ X, Y \\sim \\mathcal{N}(\\mu_{X, Y}, \\sigma_{X, Y}^2) $ and the covariance is zero, what we are interested in is only a rough estimation of the uncertainties\\footnote{If you are interested in, see FiellerEC (1932) Biometrika, 24, 428; HinkleyDV (1969) Biometrika, 56, 635;  D\\'{i}az-Franc\\'{e}s+RubioFJ (2013) Statistical Papers, 54, 309, as well as \\href{https://en.wikipedia.org/wiki/Ratio_distribution}{Wikipedia}. For the ratio of $ N_j/F_j $, i.e., when the denominator has so high signal-to-noise ratio, the distribution is roughly a Gaussian with $ \\mathcal{N}(\\mu_X, \\sigma_X^2) $ as we assume in this section.}. From the propagation of error, \n\\begin{equation}\n\\begin{aligned}\n  O_j = \\frac{N_j - D_j}{F_j} = I_j + S_j + C_j\n    &\\simdot \\mathcal{N} \n      \\left ( O_j,~ \n        O_j^2 \\left [ \n        \\left (\\frac{\\Delta \\tilde{O}_j}{\\tilde{O}_j} \\right )^2 \n        + \\left (\\frac{\\Delta F_j}{F_j} \\right )^2 \\right ] \\right ) ~.\n\\end{aligned}\n\\end{equation}\nSubstituting previously obtained distribution of $ \\tilde{O}_j $,\n\\begin{equation}\n  O_j \n    \\simdot \\mathcal{N} \n      \\left ( O_j,~ \n        \\frac{O_j}{g_jF_j} \n        + \\frac{D_j}{g_j F_j^2} \n        + \\left (\\frac{R_j}{g_j F_j} \\right )^2 \n        + \\left  (\\frac{\\Delta D_j}{F_j} \\right )^2\n        + O_j^2 \\left (\\frac{\\Delta F_j}{F_j} \\right )^2\n        \\right ) ~.\n\\end{equation}\n\n%Note that this variance is also obtained by the following logic: $ F_j $ has too high signal-to-noise ratio, $ \\Delta F_j / F_j \\ll 1 $, we can just assume $ F_j $ is a perfectly known constant without any uncertainty. Then $ O_j = \\tilde{O}_j / F_j \\simdot \\mathcal{N}(O_j, (\\Delta \\tilde{O}_j)^2 / F_j^2) $, which is what we have above.\n\n\n\\subsection{Final Pixel-wise Uncertainty}\nMany times the $ C_j $ is removed by the so-called \\emph{cosmic-ray rejection} algorithms. \n\\begin{thm}[Pixel-wise Error]\nThe final, cosmic-ray removed pixel value will follow\n\\begin{equation} \\label{eq: pix error}\n\\begin{aligned}\n  O_j^\\mathrm{cr} = \\frac{N_j - D_j}{F_j} - C_j = I_j + S_j \n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{O_j}{g_jF_j} \n        + \\frac{D_j}{g_j F_j^2} \n        + \\left (\\frac{R_j}{g_j F_j} \\right )^2 \n        + \\left (\\frac{\\Delta D_j}{F_j} \\right )^2 \n        + O_j^2 \\left (\\frac{\\Delta F_j}{F_j} \\right )^2\n        \\right ) \\\\\n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{N_j}{g_jF_j^2} \n        + \\left (\\frac{R_j}{g_j F_j} \\right )^2 \n        + \\left  (\\frac{\\Delta D_j}{F_j} \\right )^2 \n        + O_j^2 \\left (\\frac{\\Delta F_j}{F_j} \\right )^2\n        \\right ) \n\\end{aligned}\n\\end{equation}\nHere, $ O_j $ is the bias, dark, and flat corrected pixel value before the cosmic-ray removal, while $ N_j $ is only bias-subtracted pixel value. Usually the uncertainty from the estimation for $ C_j $ is ignored as it is too difficult to estimate. \n\\end{thm}\n\nIn practical application, the following approximations may be used:\n\\begin{enumerate}\n\\item Calculating the $ \\Delta D_j $ term all the time is annoying, and moreover, it is likely for most pixels $ \\Delta D_j \\ll \\Delta O_j $, except for hot/bad pixels\\footnote{Bad pixels must be masked properly prior to any sane calculation, as they are known to be ``wrong'' data. This is usually provided as a pixel mask file (e.g., \\texttt{.bpm} file) by the observatory.}. Therefore, people just ignore it and set it to 0.  Theoretically, however, $ \\Delta D_j > (R_j/g_j) $, because $\\Delta D_j = \\mathrm{sstd} (D_j^{i}) $ and $ D_j^{i} \\simdot \\mathcal{N} \\left (D_j^{i},~ D_j^{i}/g_j + (R_j/g_j)^2 \\right ) $. Therefore, a more reasonable approximation, or the lower limit of the uncertainty, would be $ R_j/g_j $. \n\\item Frequently, $ \\Delta F_j/F_j $ is much smaller than $ \\Delta \\tilde{O}_j/\\tilde{O}_j $ (or we can increase $ N_\\mathrm{Flat} $ to force that this holds), so the flat-error term is negligible. StetsonPB, for instance, asked the user to give a constant $ \\Delta F_j/F_j \\equiv \\sigma_F $ for all pixels, such as 0, 0.01, or 0.0075, in \\texttt{DAOPHOT}.\n\\item Many times we use the normalized flat (for more discussion, see below) such that its mean or median is 1, so $ F_j \\sim 1 $ for all pixel. Then all $ F_j $ in \\cref{eq: pix error} can be just ignored.\n\\item The $ D_j $ term is negligible for many times. It is not negligible only for hot pixels where $ D_j \\gg 1 $, but likely the observer did not put the target of interest at where hot pixels present. Moreover, state-of-the-art CCDs, such as Subaru FOCAS for instance, has too small dark current $ D_j < 0.1 \\,\\mathrm{e/s} $. Therefore, most important parts in the object frames will have negligible $ D_j $ compared to $ O_j^\\mathrm{cr} $. Therefore, this term is also ignored many times.\n\\end{enumerate}\n\nSummarizing, \\cref{eq: pix error} is approximated as\n\\begin{equation} \n\\begin{aligned}\n  O_j^\\mathrm{cr} \n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{O_j}{g_jF_j} \n        + \\frac{D_j}{g_j F_j^2} \n        + \\left (\\frac{R_j}{g_j F_j} \\right )^2 \n        + \\left  (\\frac{\\Delta D_j}{F_j} \\right )^2 \n        + O_j^2 \\left (\\frac{\\Delta F_j}{F_j} \\right )^2\n        \\right ) \\\\\n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{O_j}{g_jF_j} \n        + \\frac{D_j}{g_j F_j^2} \n        + 2 \\left (\\frac{R_j}{g_j F_j} \\right )^2\n        + \\sigma_F O_j^2 \n        \\right ) \\\\\n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{O_j}{g_j} \n        + \\frac{D_j}{g_j} \n        + 2 \\left (\\frac{R_j}{g_j} \\right )^2\n        + \\sigma_F O_j^2\n        \\right ) \\\\\n    &\\simdot \\mathcal{N} \n      \\left ( O_j^\\mathrm{cr},~ \n        \\frac{O_j}{g_j} \n        + 2 \\left (\\frac{R_j}{g_j} \\right )^2\n        + \\sigma_F O_j^2\n        \\right ) \\\\\n\\end{aligned}\n\\end{equation}\nMost frequently people even drop the factor 2 and $ \\sigma_F $, and write $ O_j^\\mathrm{cr} \\simdot \\mathcal{N} \\left ( O_j^\\mathrm{cr},~ O_j/g_j + (R_j/g_j)^2 \\right ) $. The first dropping ($ 2(R_j/g_j)^2 \\rightarrow (R_j/g_j)^2 $) may be justified because one $ (R_j/g_j)^2 $ came from the uncertainty in dark, and we usually ignore anything from dark\\footnote{Some high-spec observatories even skip taking dark frames (e.g., Subaru).}. \n\n\\subsubsection{Note}\n\\textbf{The flat frames are frequently assumed to be normalized}, i.e., the mean or median of $ F_j $ values of the frame is around 1. In the generalized error estimation given in this book, this normalization is not important. However, astronomers (including all tasks of IRAF) have conventionally used a very simplified version of error estimation, that is, the Poisson component of the pixel error is approximated as $ \\sqrt{O_j/g_j} $: $ O_j \\simdot \\mathcal{N} (O_j, O_j/g_j) $. Note the factor $ F_j $ is missing! The true signal-to-noise ratio is $ O_j / \\Delta O_j \\approx \\sqrt{O_j / (g_j F_j)} $, while in this approximation, it is $ \\sqrt{O_j / g_j} $. If the flat was normalized, $ F_j \\sim 1 $, so these two are similar. If it were not normalized, however, the signal-to-noise ratio in this classical approximation will be underestimated by a factor of $ \\sqrt{F_j} \\sim \\sqrt{10^4 \\,(\\mathrm{ADU})} = 100 $!! You will be calculating wrong uncertainty in that case.\n\n\nFrom STSDAS package, \\texttt{stsdas/pkg/hst\\_calib/wfpc/noise/fitnoise.x}: noise = R if pixel value not positive, otherwise, $ \\sqrt{R^2 + N/g + (N \\times \\texttt{scalen}/100)^2} $ where \\texttt{scalen} is maybe an uncertainty of pixel (flat uncertainty?) in percentage.\n\n%#################################################################################\n%#\t\t\t\t\t\t\t\t\t\t#\n%# NOISEFUNC --\tCalculate the square-root of the variance expected at the \t#\n%#\t\tgiven DN level, based upon the noise model parameters.  \t#\n%#\t\t\t\t\t\t\t\t\t\t#\n%#\tInitial code:\t7/91 by RAShaw\t\t\t\t\t\t#\n%\n%real procedure noisefn(dn) \n%\n%include\t\"nmcom.h\"\n%\n%#  Calling argument\n%real\tdn\t\t# Value of pixel in Data Numbers\n%\n%# Local variables\n%real\ttmp\n%real\tnoise\t\t# Function value\n%\n%begin\n%\ttmp = scalen / 100.\n%\tif (dn <= 0.) \n%\t    noise = readn \n%\telse\n%\t    noise = sqrt (readn * readn + dn / gain + dn * dn * tmp * tmp) \n%\treturn (noise)\n%end\n\n\n\\subsection{Signal-to-Noise Ratio (SNR)}\n\\textbf{SNR} $ := \\mathrm{signal}/\\mathrm{noise} $, is an estimation of the quality of the data. Simply speaking, the signal is the sky subtracted aperture summation. On the other hand, noise is the square root of the aperture summation on the \\textit{variance map} (the map of $ (\\Delta O_j)^2 $).\n\n\\begin{ex}[Maximum pixel-wise SNR]\nConsider a classic CCD, which loses linearity at around 60,000 ADU (bias subtracted value). Say gain is $ g_j = 1.0 $, there is neither readout noise ($ R_j = 0.0 $) nor dark ($ D_j = 0.0 $), and there is no flat pattern ($ F_j = 1.0 $, $ \\sigma_F = 0 $). Then only the Poisson noise term remains and thus the maximum SNR of the pixel is \n\\begin{equation}\n  \\mathrm{SNR}_\\mathrm{max}^\\mathrm{pixel} \n    \\approx \\frac{60000}{\\sqrt{60000}} = \\sqrt{60000} = 245 ~.\n\\end{equation}\nEven if the CCD has high bias, lose linearity earlier, high gain, etc, you should always get $ \\mathrm{SNR}_\\mathrm{max}^\\mathrm{pixel} \\sim 250 $.\n\\end{ex}\n\n\\begin{ex}[Maximum photometric SNR]\nConsider the same CCD and now you have a simple circular Gaussian star (i.e., perfect Gaussian PSF) in the image, almost saturated but not saturated. The peak value before the saturation will be roughly 60,000 ADU after the sky subtraction. That is, this star has a radial profile $ I(r) \\approx 60000 e^{-r^2/2\\sigma^2} $. Depending on the seeing size and pixel scale, $ \\sigma $ will change. \n\nFor the case if the $ \\mathrm{FWHM} \\ll 1 \\,\\mathrm{pix} $, $ \\mathrm{apsum} \\approx 60,000 $, so the maximum SNR is $ \\mathrm{SNR}_\\mathrm{max}^\\mathrm{star} \\approx \\mathrm{SNR}_\\mathrm{max}^\\mathrm{pixel} \\sim 250 $.\n \nIf the FWHM is much larger than 1 pixel (say, 5 pixel), 60,000 is roughly the peak value of the Gaussian function. The integration of such Gaussian function is $ \\sqrt{2 \\pi} \\sigma \\times 60,000 \\sim 60,000 \\times \\mathrm{FWHM} $, where FWHM is in pixel unit (note that $ \\sqrt{2\\pi}\\sigma = 2.51 \\sigma \\approx \\mathrm{FWHM} $). Therefore, \n\\begin{equation}\n \\mathrm{SNR}_\\mathrm{max}^\\mathrm{star} \n \\approx \\frac{60000 \\mathrm{FWHM}}{\\sqrt{60000 \\mathrm{FWHM}}}\n \\sim 250 \\sqrt{\\mathrm{FWHM}}\n\\end{equation}\n\nOtherwise, $ \\int_{-0.5}^{0.5}\\int_{-0.5}^{0.5} I(x, y) dx dy = 60,000 $, so it is a bit complicated to calculate (you may use the fact that the integration of Gaussian function is analytically expressed using erf). But you may simply use the above rule-of-thumb to check the maximum SNR.\n\nIn reality, uncertainty in sky, dark, readout noise will increase the noise and thus decrease the SNR. Gain larger than unity will have an effect of increasing SNR by factor of $ \\sqrt{g} $. The PSF usually have longer tail than Gaussian, and this will increase the SNR.\n\\end{ex}\n\nThe magnitude system used in astronomy uses the logarithmic scale. From Pogson's formula, $ I_1/I_2 = 10^{-0.4 \\Delta m} $ for two objects having fluxes $ I_1 $ and $ I_2 $, and magnitude difference $ \\Delta m $. When $ \\Delta m $ is small, $ \\Delta m $ is the fractional difference of the fluxes. For example, $ \\Delta m = 0.01 $ means $ I_1/I_2 \\approx 0.99 $ or the flux difference is 0.01 (1 \\%). See \\cref{fig:deltamag} for the validity of this approximation. \n\n\\begin{figure} [ht!]\n  \\centering\n  \\includegraphics[width=0.5\\linewidth]{figs/delta_mag}\n  \\caption{The delta magnitude plot.}\n  \\label{fig:deltamag}\n\\end{figure}\n\nDifferently put, if $ \\Delta m =0.01 $ was the magnitude \\textit{uncertainty} of the object, the uncertainty in flux is 1 \\%, or $ \\mathrm{SNR} = 100 $. Therefore, SNR can be directly converted to the magnitude uncertainty and vice versa. The $ \\mathrm{SNR}_\\mathrm{max}^\\mathrm{pixel} = 250 $ translates to $ \\Delta m \\sim 1/250 = 0.004 $.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "bb891482d55a2aadd3589a75f93fdb0ecc81e38d", "size": 17423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Books/chaps/03_stats_phot.tex", "max_stars_repo_name": "ysBach/SNU_AOclass", "max_stars_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-03-23T06:14:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T01:49:51.000Z", "max_issues_repo_path": "Books/chaps/03_stats_phot.tex", "max_issues_repo_name": "ysBach/SNU_AOclass", "max_issues_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-05-04T17:21:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-24T11:41:55.000Z", "max_forks_repo_path": "Books/chaps/03_stats_phot.tex", "max_forks_repo_name": "ysBach/SNU_AOclass", "max_forks_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-05-10T14:19:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T09:18:08.000Z", "avg_line_length": 66.754789272, "max_line_length": 978, "alphanum_fraction": 0.6701486541, "num_tokens": 5595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6361593629969559}}
{"text": "\\chapter{Hypothesis Testing and p-values}\n\n\\begin{ex}\n  Suppose that the true value of $\\theta$ is $\\theta_\\star\\neq \\theta_0$. Then\n  \\begin{align*}\n    W\n    =\\frac{\\thetahat-\\theta_0}{\\sehat}\n    =\\frac{\\thetahat-\\theta_\\star+\\theta_\\star-\\theta_0}{\\sehat}\n    =\\frac{\\thetahat-\\theta_\\star}{\\sehat}-\\frac{\\theta_0-\\theta_\\star}{\\sehat},\n  \\end{align*}\n  and therefore\n  \\begin{align*}\n    \\P{|W|>z_{\\alpha/2}}\n     & =\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}-\\frac{\\theta_0-\\theta_\\star}{\\sehat}>z_{\\alpha/2}}\n    +\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}-\\frac{\\theta_0-\\theta_\\star}{\\sehat}<-z_{\\alpha/2}}       \\\\\n     & =\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}>\\frac{\\theta_0-\\theta_\\star}{\\sehat} + z_{\\alpha/2}}\n    +\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}<\\frac{\\theta_0-\\theta_\\star}{\\sehat}-z_{\\alpha/2}}        \\\\\n     & =1-\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}<\\frac{\\theta_0-\\theta_\\star}{\\sehat} + z_{\\alpha/2}}\n    +\\P{\\frac{\\thetahat-\\theta_\\star}{\\sehat}<\\frac{\\theta_0-\\theta_\\star}{\\sehat}-z_{\\alpha/2}},\n  \\end{align*}\n  which, since $(\\thetahat-\\theta_\\star)/\\sehat \\approx N(0, 1)$, implies that\n  \\[\n    \\P{|W|>z_{\\alpha/2}}\\approx\n    1-\\Phi\\left(\\frac{\\theta_0-\\theta_\\star}{\\sehat} + z_{\\alpha/2}\\right)\n    +\\Phi\\left(\\frac{\\theta_0-\\theta_\\star}{\\sehat}-z_{\\alpha/2}\\right).\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  By Theorem 10.12,\n  \\[\n    p=\\mathbb{P}_{\\theta_0}{(T(X^n)\\geq T(x^n))}=1-F(T(x^n)),\n  \\]\n  where $T(X^n)\\sim F$ under $H_0:\\theta=\\theta_0$. Therefore,\n  \\[\n    \\P{p<y}\n    =\\P{1-F(T(Y^n))<y},\n  \\]\n  where $T(Y^n)\\sim F$ and therefore by Exercise 2.15,\n  $F(T(Y^n))\\sim\\text{Uniform}(0, 1)$. Finally, note that if\n  $U\\sim\\text{Uniform}(0,1)$ then $1-U\\sim\\text{Uniform}(0,1)$ as well, and that\n  therefore\n  \\[\n    \\P{p<y}=yI_{[0,1]}(y),\n  \\]\n  the CDF of a $\\text{Uniform}(0,1)$ distribution.\n\\end{ex}\n\n\\begin{ex}\n  Note that $\\theta_0\\not\\in C$, where\n  \\[\n    C=(\\thetahat-\\sehat \\, z_{\\alpha/2}, \\thetahat+\\sehat \\, z_{\\alpha/2}),\n  \\]\n  if and only if\n  \\[\n    \\theta_0> \\thetahat+\\sehat\\, z_{\\alpha/2}\\text{, or }\n    \\theta_0< \\thetahat-\\sehat\\, z_{\\alpha/2}.\n  \\]\n  This is equivalent to\n  \\[\n    |\\theta_0-\\thetahat|> \\sehat\\, z_{\\alpha/2},\n  \\]\n  which is equivalent to\n  \\[\n    \\frac{|\\thetahat-\\theta_0|}{\\sehat} > z_{\\alpha/2},\n  \\]\n  but this is precisely the size $\\alpha$ Wald test.\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\[\n    p\\text{-value}\n    =\\inf\\left\\{\\alpha \\mid T(X^n)\\geq c_\\alpha\\right\\},\n  \\]\n  where $\\alpha=\\sup_{\\theta\\in\\Theta_0}\\mathbb{P}_{\\theta}(T(X^n)\\geq\n    c_\\alpha)$ is a decreasing function of $c_\\alpha$, and that therefore,\n  having observed $x^n$, the smallest value of $\\alpha$ will be obtained for\n  the largest $c_\\alpha$ such that we still reject the null, $c_\\alpha=T(x^n)$.\n  The size of the test for which we reject the null is then\n  \\[\n    \\sup_{\\theta\\in\\Theta_0}\\mathbb{P}_{\\theta}(T(X^n)\\geq T(x^n))\n  \\]\n  and therefore\n  \\[\n    p\\text{-value}\n    =\\sup_{\\theta\\in\\Theta_0}\\mathbb{P}_{\\theta}(T(X^n)\\geq T(x^n)),\n  \\]\n  or, in the case where $\\Theta_0=\\{\\theta_0\\}$, the supremum is over only a\n  single element and therefore\n  \\[\n    p\\text{-value}\n    =\\mathbb{P}_{\\theta_0}(T(X^n)\\geq T(x^n)).\n  \\]\n\\end{ex}\n\n% 5\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Uniform}(0,\\theta)$ and\n  $Y=\\max\\{X_1,\\ldots,X_n\\}$.\n  \\begin{enumerate}[(a)]\n    \\item We have\n          \\begin{align*}\n            \\beta(\\theta_0)\n             & =\\mathbb{P}_{\\theta_0}(Y>c)                                              \\\\\n             & =1-\\mathbb{P}_{\\theta_0}(Y\\leq c)                                        \\\\\n             & =1-\\mathbb{P}_{\\theta_0}(X_1\\leq c)\\cdots\\mathbb{P}_{\\theta'}(X_n\\leq c) \\\\\n             & =1-(c/\\theta_0)^n\n          \\end{align*}\n          for $c\\in[0,\\theta_0]$.\n    \\item Solving\n          \\[\n            0.05=1-(c/\\theta_0)^n\n          \\]\n          for $c$ we get\n          \\[\n            c=0.95^{1/n}\\theta_0,\n          \\]\n          or, substituting $0.5$ for $\\theta_0$,\n          \\[\n            c=0.5\\cdot 0.95^{1/n}.\n          \\]\n    \\item We have\n          \\[\n            p=1-(0.48/0.5)^{n},\n          \\]\n          which implies that $p\\approx 0.558$, which means that the test does\n          not provide any evidence against $H_0$.\n    \\item Note that $Y=0.52$ is outside the range $[0,\\theta_0]$, and therefore\n          $\\mathbb{P}_{\\theta_0}(Y>0.52)=0$. The $p$-value is therefore $0$, and\n          we can thus reject $H_0$ at any level.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Since we will need to construct a confidence interval, we will use the Wald\n  test for a Binomial distribution. Let $H_0: p=1/2$ and $H_1:p\\neq 1/2$. By\n  Exercise 10.15, $\\phat=X/n=922/1919$ with\n  $\\sehat{\\phat}=\\sqrt{\\phat(1-\\phat)/n}$. The test statistic is\n  \\[\n    \\frac{|\\phat-p_0|}{\\sehat(\\phat)}\n  \\]\n  and thus by Theorem 10.13 the $p$-value is given by\n  \\[\n    \\P{|Z|>\\frac{|\\phat-p_0|}{\\sqrt{\\phat(1-\\phat)/n}}}\n    =2\\Phi\\left(\n    -\\frac{|\\phat-p_0|}{\\sqrt{\\phat(1-\\phat)/n}}\n    \\right).\n  \\]\n  \\inputminted{python}{../code/10-06.py}\n  \\inputminted{text}{../output/10-06.txt}\n\n  The test indicates weak evidence against $H_0$.\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Let $X_1$ be the distribution of the proportion of three-letter words\n          in the Twain essays, and let $X_2$ be the distribution in the\n          Snodgrass essays. Recall from Example 10.8 that the plug-in estimator\n          for a difference of means $d=\\mu_1-\\mu_2$ is given by the difference\n          of the plug-in estimators of the means, the sample averages. Thus,\n          \\[\n            \\widehat{d}=\\Xbar_1-\\Xbar_2,\n          \\]\n          with\n          \\[\n            \\sehat(\\widehat{d})\n            =\\sqrt{(\\sehat(\\muhat_1))^2+(\\sehat(\\muhat_2))^2},\n          \\]\n          where\n          \\[\n            \\sehat(\\muhat_j)=\\frac{1}{\\sqrt{n_j}}\n            \\sqrt{\\frac{1}{n_j}\\sum_{i=1}^{n_j}(X_{j,i}-\\Xbar_j)^2}.\n          \\]\n\n          Note that $H_0: d=0$, and therefore the size $\\alpha$ Wald test for\n          this hypothesis is obtained by checking whether\n          \\[\n            \\frac{\\left|\\Xbar_1-\\Xbar_2\\right|}{\n              \\sqrt{(\\sehat(\\Xbar_1))^2+(\\sehat(\\Xbar_2))^2}}\n            > z_{\\alpha/2}.\n          \\]\n\n          \\inputminted{python}{../code/10-07.py}\n          \\inputminted{text}{../output/10-07.txt}\n\n          We may conclude that there is very strong evidence to reject the null\n          hypothesis, i.e.\\ that the proportion of three-letter words is\n          similarly distributed in both sets of essays.\n    \\item We obtain the same result from the permutation test: we have very\n          strong evidence that the samples comes from sets with different means.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim N(\\theta, 1)$. We are testing $H_0:\\theta=0$ versus\n  $H_1:\\theta=1$, using the rejection region $R=\\{x^n \\mid T(x^n)>c\\}$ where\n  $T(x^n)=\\Xbar$.\n  \\begin{enumerate}[(a)]\n    \\item Note that\n          \\begin{align*}\n            \\alpha\n             & = \\mathbb{P}_{\\theta=0}\\left(\\Xbar > c \\right)                 \\\\\n             & = \\mathbb{P}_{\\theta=0}\\left(\\sqrt{n}\\Xbar > \\sqrt{n}c \\right) \\\\\n             & = \\mathbb{P}_{\\theta=0}\\left(Z > \\sqrt{n}c \\right)             \\\\\n             & = 1-\\Phi(\\sqrt{n}c),\n          \\end{align*}\n          and that therefore $c=z_{\\alpha}/\\sqrt{n}$.\n    \\item We have\n          \\begin{align*}\n            \\beta(1)\n             & = \\mathbb{P}_{\\theta=1}\\left(\\Xbar > c \\right)                         \\\\\n             & = \\mathbb{P}_{\\theta=1}\\left(\\Xbar-1 > c-1 \\right)                     \\\\\n             & = \\mathbb{P}_{\\theta=1}\\left(\\sqrt{n}(\\Xbar-1) > \\sqrt{n}(c-1) \\right) \\\\\n             & = \\mathbb{P}_{\\theta=1}\\left(z > \\sqrt{n}(c-1) \\right)                 \\\\\n             & = 1-\\Phi(\\sqrt{n}({c-1}))                                              \\\\\n             & = 1-\\Phi(z_\\alpha-\\sqrt{n}).\n          \\end{align*}\n    \\item Note that\n          \\begin{align*}\n            \\lim_{n\\to\\infty}\\beta_n(1)\n             & =\\lim_{n\\to\\infty}[1-\\Phi(z_\\alpha-\\sqrt{n})] \\\\\n             & =1-\\lim_{u\\to-\\infty}\\Phi(u)                  \\\\\n             & =1.\n          \\end{align*}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Note that\n  \\begin{align*}\n    \\beta(\\theta_1)\n     & =\\mathbb{P}_{\\theta_1}\\left(\\left|\\frac{\\thetahat-\\theta_0}{\\sehat}\\right| > z_{\\alpha/2} \\right) \\\\\n     & =\\mathbb{P}_{\\theta_1}\\left(\\frac{\\thetahat-\\theta_0}{\\sehat} > z_{\\alpha/2} \\right)\n    +\\mathbb{P}_{\\theta_1}\\left(\\frac{\\thetahat-\\theta_0}{\\sehat} < -z_{\\alpha/2} \\right)                \\\\\n     & =1\n    -\\mathbb{P}_{\\theta_1}\\left(\\frac{\\thetahat-\\theta_0}{\\sehat} < z_{\\alpha/2} \\right)\n    +\\mathbb{P}_{\\theta_1}\\left(\\frac{\\thetahat-\\theta_0}{\\sehat} < -z_{\\alpha/2} \\right)                \\\\\n     & =1\n    -\\mathbb{P}_{\\theta_1}\n    \\left(\\frac{\\thetahat-\\theta_1}{\\sehat}\n    +\\frac{\\theta_1-\\theta_0}{\\sehat}\n    < z_{\\alpha/2} \\right)\n    +\\mathbb{P}_{\\theta_1}\\left(\n    \\frac{\\thetahat-\\theta_1}{\\sehat}\n    +\\frac{\\theta_1-\\theta_0}{\\sehat}\n    < -z_{\\alpha/2} \\right)                                                                              \\\\\n     & =1\n    -\\mathbb{P}_{\\theta_1}\n    \\left(\\frac{\\thetahat-\\theta_1}{\\sehat}\n    < z_{\\alpha/2}\n    -\\frac{\\theta_1-\\theta_0}{\\sehat}\n    \\right)\n    +\\mathbb{P}_{\\theta_1}\\left(\n    \\frac{\\thetahat-\\theta_1}{\\sehat}\n    < -z_{\\alpha/2}\n    -\\frac{\\theta_1-\\theta_0}{\\sehat}\n    \\right)                                                                                              \\\\\n     & =1-\\lim_{n\\to\\infty}\\Phi\\left(z_{\\alpha/2}-\\sqrt{nI(\\thetahat)}(\\theta_1-\\theta_0)\\right)\n    +\\lim_{n\\to\\infty}\\Phi\\left(-z_{\\alpha/2}-\\sqrt{nI(\\thetahat)}(\\theta_1-\\theta_0)\\right),\n  \\end{align*}\n  or, since $\\theta_1>\\theta_0$,\n  \\[\n    \\beta(\\theta_1)\n    = 1 - \\lim_{u\\to-\\infty}\\Phi(u)+\\lim_{u\\to-\\infty}\\Phi(u)\n    = 1.\n  \\]\n\\end{ex}\n\n% 10\n\\begin{ex}\n  We will use the Wald test to check whether there is a difference between the\n  proportion of deaths before the Chinese Harvest Moon Festival between the two\n  groups.\n  \\inputminted{python}{../code/10-10.py}\n  \\inputminted{text}{../output/10-10.txt}\n\n  We find that there is little to no evidence against $H_0$.\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item\n          \\inputminted{python}{../code/10-11.py}\n          \\inputminted{text}{../output/10-11.txt}\n          Since only the $p$-value for Chlorpromazine is less than $0.05$, the\n          only null hypothesis that we may reject is that the placebo is\n          similarly effective as Chlorpromazine.\n    \\item Our finding remains statistically significant at the $0.05$ level\n          under both the Bonferroni or the Benjamini-Hochberg multiple\n          testing method corrections.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Let $X_1,\\ldots,X_n\\sim\\text{Poisson}(\\lambda)$. We begin by computing\n          the maximum likelihood estimator for $\\lambda$. Recall that then\n          \\[\n            f(x;\\lambda)=e^{-\\lambda}\\frac{\\lambda^x}{x!},\n          \\]\n          and that therefore\n          \\[\n            \\ell_n(\\lambda)=\\sum_{i=1}^n-\\lambda+X_i\\log(\\lambda)+\\log(X_i!).\n          \\]\n          Hence,\n          \\[\n            \\frac{\\d\\ell_n(\\lambda)}{\\d\\lambda}\n            =\\sum_{i=1}^n\\left[-1+\\frac{X_i}{\\lambda}\\right]\n            =\\frac{n(\\Xbar-\\lambda)}{\\lambda}\n            \\text{ implies }\n            \\lambda=\\Xbar,\n          \\]\n          and it is clear by the second derivative test that this is a maximum.\n          Hence, $\\widehat{\\lambda}=\\Xbar$, and\n          $\\sehat(\\widehat{\\lambda})=\\sqrt{\\Xbar/n}$.\n\n          Let $H_0:\\lambda=\\lambda_0$. Then, the size $\\alpha$ Wald test is\n          given by rejecting $H_0$ when\n          \\[\n            \\frac{\\sqrt{n}|\\Xbar-\\lambda_0|}{\\sqrt{\\Xbar}}>z_{\\alpha/2}.\n          \\]\n    \\item\n          \\inputminted{python}{../code/10-12.py}\n          \\inputminted{text}{../output/10-12.txt}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots, X_n\\sim N(\\mu, \\sigma^2)$. Recall from Example 9.11 that then\n  \\[\n    \\ell(\\mu, \\sigma)\n    =-n\\log\\sigma -\\frac{nS^2}{2\\sigma^2}-\\frac{n(\\Xbar-\\mu)^2}{2\\sigma^2}.\n  \\]\n  Therefore,\n  \\[\n    \\frac{\\pd \\ell(\\mu, \\sigma)}{\\pd \\mu}\n    =\\frac{n(\\Xbar-\\mu)}{\\sigma^2}\n    \\text{ implies }\n    \\muhat = \\overline{X},\n  \\]\n  and\n  \\[\n    \\frac{\\pd \\ell(\\Xbar, \\sigma)}{\\pd \\sigma}=-\\frac{n}{\\sigma}+\\frac{nS^2}{\\sigma^3}\n    \\text{ implies }\n    \\sigmahat = S.\n  \\]\n  We have $\\Theta_0=\\{(\\mu, \\sigma) \\mid \\mu=\\mu_0\\}$ and so for the likelihood\n  ratio test we have\n  \\begin{align*}\n    \\lambda\n     & = 2\\log\\left(\\frac{\\sup_{\\theta\\in\\Theta}\\L(\\theta)}{\\sup_{\\theta_0\\in\\Theta_0}\\L(\\theta_0)} \\right) \\\\\n     & =2\\ell(\\Xbar, S)-2\\ell(\\mu_0, S)                                                                     \\\\\n     & =\\frac{n(\\Xbar-\\mu_0)^2}{S^2},\n  \\end{align*}\n  where, under $H_0$, we expect $\\lambda\\rightsquigarrow \\chi^2$, and\n  therefore have $p$-value\n  \\[\n    \\P{\\chi^2>\\frac{n(\\Xbar-\\mu_0)^2}{S^2}}.\n  \\]\n\n  Recall that $\\se(\\muhat)=\\sigma/\\sqrt{n}$, and that therefore the $p$-value\n  for the Wald test is given by\n  \\[\n    \\P{|Z|>\\frac{\\sqrt{n}|\\Xbar -\\mu_0|}{S}},\n  \\]\n  or, by squaring both sides,\n  \\[\n    \\P{Z^2>\\frac{n(\\Xbar -\\mu_0)^2}{S^2}},\n  \\]\n  which is equivalent to the likelihood-ratio test since $Z^2$ has a chi-squared\n  distribution.\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots, X_n\\sim N(\\mu, \\sigma^2)$. Recall that\n  \\[\n    \\ell(\\mu, \\sigma)=-n\\log\\sigma -\\frac{nS^2}{2\\sigma^2}-\\frac{n(\\Xbar-\\mu)^2}{2\\sigma^2},\n  \\]\n  and by an identical argument to the previous problem,\n  \\[\n    \\muhat=\\Xbar\\text{ and }\\sigmahat=S.\n  \\]\n  We then have $\\Theta_0=\\{(\\mu, \\sigma) \\mid \\sigma=\\sigma_0\\}$, and therefore\n  \\begin{align*}\n    \\lambda\n     & =2\\log\\left(\\frac{\\sup_{\\theta\\in\\Theta}\\L(\\theta)}{\\sup_{\\theta_0\\in\\Theta_0}\\L(\\theta_0)} \\right) \\\\\n     & =2\\ell(\\Xbar, S)-2\\ell(\\Xbar, \\sigma_0)                                                             \\\\\n     & = n\\left[2\\log\\frac{\\sigma_0}{S}+\\frac{S^2}{\\sigma_0^2}-1\\right]                                    \\\\\n     & = 2n\\log\\frac{\\sigma_0}{S}+\\frac{n(S^2-\\sigma_0^2)}{\\sigma_0^2},\n  \\end{align*}\n  where, under $H_0$, we expect $\\lambda\\rightsquigarrow \\chi^2$, and\n  therefore have $p$-value\n  \\[\n    \\P{\\chi^2>\n      2n\\log\\frac{\\sigma_0}{S}+\\frac{n(S^2-\\sigma_0^2)}{\\sigma_0^2}\n    }.\n  \\]\n\n  Recall that $\\se(\\sigmahat)=\\sigma/\\sqrt{2n}$, and that therefore the\n  $p$-value for the Wald test is given by\n  \\[\n    \\P{|Z|>\\frac{\\sqrt{2n}|S -\\sigma_0|}{S}},\n  \\]\n  or,\n  \\[\n    \\P{Z^2>\\frac{2n(S -\\sigma_0)^2}{S^2}}.\n  \\]\n\\end{ex}\n\n% 15\n\\begin{ex}\n  Let $X \\sim \\text{Binomial}(n, p)$. Note that then\n  \\[\n    \\ell(n, p)=\\log\\binom{n}{X}+X\\log{p}+(n-X)\\log(1-p),\n  \\]\n  and therefore\n  \\[\n    \\frac{\\pd\\ell(n, p)}{\\pd{p}}\n    =\\frac{X}{p}-\\frac{n-X}{1-p}\n    \\text{ implies }\n    \\phat =X/n.\n  \\]\n\n  We have $\\Theta_0=\\{p_0\\}$. Therefore,\n  \\[\n    \\lambda\n    =2\\log\\left(\\frac{\\sup_{\\theta\\in\\Theta}\\L(\\theta)}{\\sup_{\\theta_0\\in\\Theta_0}\\L(\\theta_0)} \\right)\n    =2\\ell(n, \\phat)-2\\ell(n, p_0)\n    =2X\\log\\left(\\frac{\\phat}{p_0}\\right)+2(n-X)\\log\\left(\\frac{1-\\phat}{1-p_0}\\right),\n  \\]\n  where, under $H_0$, we expect $\\lambda\\rightsquigarrow \\chi^2$.\n\n  Note that by Exercise 9.7, $\\sehat(\\phat)=\\sqrt{\\phat(1-\\phat)/n}$, and\n  therefore the $p$-value of the Wald test is given by\n  \\[\n    \\P{|Z|>\\frac{\\sqrt{n}|\\phat-p_0|}{\\sqrt{\\phat(1-\\phat)}}}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $\\ell(\\theta)$ be a log-likelihood. Note that then the second degree\n  Taylor polynomial expansion of $\\ell$ around the MLE $\\thetahat$ is given by\n  \\[\n    \\ell(\\theta)\n    \\approx\n    \\ell(\\thetahat)+\\ell'(\\thetahat)(\\theta-\\thetahat)\n    +\\frac{1}{2}\\ell''(\\thetahat)(\\theta-\\thetahat)^2,\n  \\]\n  and therefore,\n  \\[\n    \\lambda\n    =2\\ell(\\thetahat)-2\\ell(\\theta_0)\n    \\approx -\\ell''(\\thetahat)(\\thetahat-\\theta_0)^2\n    = I(\\thetahat)(\\thetahat-\\theta_0)^2\n    = \\frac{(\\thetahat-\\theta_0)^2}{\\sehat^2(\\thetahat)},\n  \\]\n  however, this is precisely $W^2$.\n\n  To complete the proof and show that $\\frac{W^2}{\\lambda}\\xrightarrow{P} 1$, we\n  need to be able to show that the error of our quadratic approximation to the\n  log-likelihood decreases with sample size, but this is not true in general,\n  and it does not look like we have any of the relevant results in the book.\n\\end{ex}", "meta": {"hexsha": "d1e969c997c2ac064889b28cc445bac830311df3", "size": 16381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch10.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/ch10.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/ch10.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": 35.2279569892, "max_line_length": 110, "alphanum_fraction": 0.5436176058, "num_tokens": 6038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6361593378498861}}
{"text": "\n\\subsection{Choice set}\n\nEconomic agents face options from some set. This could be consumption choices, numbers of hours to work, or how much capital to invest in at a factory.\n\n\\subsubsection{Utility functions}\n\nCalculating choices: Unrestricted choices\n\nThe choice of an agent is the selection which corresponds to the highest value of the utility function. Consider:\n\n\\(f=2(x-1)^2-10\\)\n\nWe can easily calculate that even if the agent can choose any real number \\(x\\), they will chose \\(1\\).\n\nThis approach can be used if there are not meaningful constraints, or those constraints are implicit in the utility function. For example a firm can be modelled as profit maximising, where profit is a function of revenue and costs, with a single maximising value.\n\nOther agents, such as a consumers, may instead have utility over consumption and leisure, and a separate constraint over this. This could be solved using simultaneous equations, but such an approach is not always desirable.\n\n", "meta": {"hexsha": "6bdb9feba4e0316a6b073c0caaa2bd65c7f9d948", "size": 986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/singleAgent/01-01-axiomsChoiceSet.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/singleAgent/01-01-axiomsChoiceSet.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/singleAgent/01-01-axiomsChoiceSet.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": 49.3, "max_line_length": 263, "alphanum_fraction": 0.7900608519, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6360411974287461}}
{"text": "\\documentclass[a4paper,11pt,final]{article}\n\\usepackage{fancyvrb, color, graphicx, hyperref, amsmath, url}\n\\usepackage{palatino}\n\\usepackage[a4paper,text={16.5cm,25.2cm},centering]{geometry}\n\n\\hypersetup\n{   pdfauthor = {Matti Pastell},\n  pdftitle={FIR filter design with Python and SciPy},\n  colorlinks=TRUE,\n  linkcolor=black,\n  citecolor=blue,\n  urlcolor=blue\n}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1.2ex}\n\n\n\n\\title{FIR filter design with Python and SciPy}\n\\author{Matti Pastell \\\\ \\url{http://mpastell.com}}\n\\date{15th April 2013}\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Introduction}\n\nThis an example of a document that can be published using\n\\href{http://mpastell.com/pweave}{Pweave}. Text is written\nusing \\LaTeX{} and code between \\texttt{<<>>} and \\texttt{@} is executed\nand results are included in the resulting document.\n\nYou can define various options for code chunks to control code\nexecution and formatting (see\n\\href{http://mpastell.com/pweave/usage.html\\#code-chunk-options}{Pweave\ndocs}).\n\n\\section{FIR Filter Design}\n\nWe'll implement lowpass, highpass and ' bandpass FIR filters. If you\nwant to read more about DSP I highly recommend\n\\href{http://www.dspguide.com/}{The Scientist and Engineer's Guide to\nDigital Signal Processing} which is freely available online.\n\n\\subsection{Functions for frequency, phase, impulse and step response}\n\nLet's first define functions to plot filter properties.\n\n\n\n\\begin{verbatim}\nfrom pylab import *\nimport scipy.signal as signal\nimport warnings\nwarnings.simplefilter(\"ignore\")\n\n#Plot frequency and phase response\ndef mfreqz(b,a=1):\n    w,h = signal.freqz(b,a)\n    h_dB = 20 * log10 (abs(h))\n    subplot(211)\n    plot(w/max(w),h_dB)\n    ylim(-150, 5)\n    ylabel('Magnitude (db)')\n    xlabel(r'Normalized Frequency (x$\\pi$rad/sample)')\n    title(r'Frequency response')\n    subplot(212)\n    h_Phase = unwrap(arctan2(imag(h),real(h)))\n    plot(w/max(w),h_Phase)\n    ylabel('Phase (radians)')\n    xlabel(r'Normalized Frequency (x$\\pi$rad/sample)')\n    title(r'Phase response')\n    subplots_adjust(hspace=0.5)\n\n#Plot step and impulse response\ndef impz(b,a=1):\n    l = len(b)\n    impulse = repeat(0.,l); impulse[0] =1.\n    x = arange(0,l)\n    response = signal.lfilter(b,a,impulse)\n    subplot(211)\n    stem(x, response)\n    ylabel('Amplitude')\n    xlabel(r'n (samples)')\n    title(r'Impulse response')\n    subplot(212)\n    step = cumsum(response)\n    stem(x, step)\n    ylabel('Amplitude')\n    xlabel(r'n (samples)')\n    title(r'Step response')\n    subplots_adjust(hspace=0.5)\n\\end{verbatim}\n\n\n\\subsection{Lowpass FIR filter}\n\nDesigning a lowpass FIR filter is very simple to do with SciPy, all you\nneed to do is to define the window length, cut off frequency and the\nwindow.\n\nThe Hamming window is defined as:\n$w(n) = \\alpha - \\beta\\cos\\frac{2\\pi n}{N-1}$, where $\\alpha=0.54$ and\n$\\beta=0.46$\n\nThe next code chunk is executed in term mode, see the source document\nfor syntax. Notice also that Pweave can now catch multiple\nfigures/code chunk.\n\n\n\\begin{verbatim}\nn = 61\na = signal.firwin(n, cutoff = 0.3, window = \"hamming\")\n#Frequency and phase response\nmfreqz(a)\n#Impulse and step response\np = figure(2)\nimpz(a)\n\\end{verbatim}\n\\includegraphics[width= \\linewidth]{figures/FIR_design_verb_figure2_1.pdf}\n\\includegraphics[width= \\linewidth]{figures/FIR_design_verb_figure2_2.pdf}\n\n\n\\subsection{Highpass FIR Filter}\n\nLet's define a highpass FIR filter:\n\n\n\\begin{verbatim}\nn = 101\na = signal.firwin(n, cutoff = 0.3, window = \"hanning\", pass_zero=False)\nmfreqz(a)\n\\end{verbatim}\n\\includegraphics[width= \\linewidth]{figures/FIR_design_verb_figure3_1.pdf}\n\n\n\\subsection{Bandpass FIR filter}\n\nNotice that the plot has a caption defined in code chunk options.\n\n\n\n\\begin{verbatim}\nn = 1001\na = signal.firwin(n, cutoff = [0.2, 0.5], window = 'blackmanharris', pass_zero = False)\nmfreqz(a)\n\\end{verbatim}\n\\begin{figure}[htpb]\n\\center\n\\includegraphics[width= \\linewidth]{figures/FIR_design_verb_figure4_1.pdf}\n\\caption{Bandpass FIR filter.}\n\\label{fig:None}\n\\end{figure}\n\n\n\\end{document}\n", "meta": {"hexsha": "fb08e872b1323721836fcdbbd5f132bce4e1d0a3", "size": 4036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tests/weave/tex/FIR_design_verb_REF.tex", "max_stars_repo_name": "piccolbo/Pweave", "max_stars_repo_head_hexsha": "62a740e46c16b3aecce53aa951792b33ac93e1a2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-14T17:48:36.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-14T17:48:36.000Z", "max_issues_repo_path": "tests/weave/tex/FIR_design_verb_REF.tex", "max_issues_repo_name": "piccolbo/Pweave", "max_issues_repo_head_hexsha": "62a740e46c16b3aecce53aa951792b33ac93e1a2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-12-13T05:00:33.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-15T19:07:01.000Z", "max_forks_repo_path": "tests/weave/tex/FIR_design_verb_REF.tex", "max_forks_repo_name": "piccolbo/Pweave", "max_forks_repo_head_hexsha": "62a740e46c16b3aecce53aa951792b33ac93e1a2", "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": 25.3836477987, "max_line_length": 87, "alphanum_fraction": 0.7252229931, "num_tokens": 1186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431679972357831, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.6360411841898131}}
{"text": "%%%%%PLEASE CONSIDER CORRECTIONS AT PLACES INDICATED%%%%%%%%\n\\documentclass{discussion}\n%%%%%Packages Used, add more if necessary%%%%\n\\providecommand{\\tightlist}{%\n\\setlength{\\itemsep}{2pt}\\setlength{\\parskip}{0pt}} \n\n\n\\newenvironment{answer}\n  {\\vspace{-1em}\\begin{proof}[Answer]}\n  {\\end{proof}}\n\n\\usepackage[ruled]{algorithm2e}\n\\begin{document}\n\n%%%%%CHANGE HERE%%%%%%%%%\n%%%%%\\lecture{the ordinal number of the tutorial}{lecture title}{Instructor's name}%%%%%%%%\n\\lecture{6}{Ensemble Methods}{Chansoo Lee}{}\n\n%%%%%CHANGE HERE%%%%%%%\n%%%%%\\section{title of the section} similarly with the rest \\section{} or \\subsection{} or \\subsubsection{} etc\n\n   \n\\renewcommand{\\R}{\\mathbb{R}}\n\\renewcommand{\\vec}[1]{\\mathbf{#1}}\n\\newcommand{\\Dtrain}{\\mathcal{D}_{\\mathrm{train}}}\n\\newcommand{\\tm}{\\mathbf{\\theta}_{\\text{model}}}\n\\newcommand{\\xtest}{\\mathbf{\\x}_{\\text{test}}}\n\\newcommand{\\test}{\\mathrm{test}}\n\\newcommand{\\pred}{\\mathrm{pred}}\n\n\\newcommand{\\D}{\\mathcal{D}}\n\\newcommand{\\F}{F}\n\\newcommand{\\WL}{\\mathrm{WL}}\n\\section{Important Concepts}\n\\paragraph{True vs Empirical Risk} Simply put,  \\emph{risk} is the \\emph{expected loss}. If we take the expectation over true data distribution, we get true risk. If we take the expectation over \\emph{empirical probability density estimate} (which is uniform over a finite data, HW3 problem 2), we get empirical risk.\n\nNow, let us define these formally. Suppose the data is i.i.d. samples from a distribution $Q$. Then, the \\emph{true risk} (or simply \\emph{risk}) of hypothesis $h$ is the expectation of the loss function $\\ell$ over $Q$:\n\\[R(h) = \\mathbb{E}_{(\\mathbf{x},y) \\sim Q}[\\ell(h(\\mathbf{x}), y)].\\]\nWe have seen a very similar expression in homework 3.\n\nThe true risk cannot be computed, because $Q$ is unknown. The learning algorithm, however, can approximate the true risk using training examples $S = \\{(\\vec{x}_i, y_i)\\}_{i=1}^{n}$:\n\\[R_S(h) = \\frac{1}{n} \\sum_{i=1}^{n} \\ell(h(\\mathbf{x}_i), y_i).\\]\nAs $n$ goes to infinity, the empirical risk converges to the true risk.\n\n\nFor example, consider linear regression. The weight vector $\\mathbf{w}$ is the model parameter, and the prediction function $h(\\mathbf{x}) = \\mathbf{w}^\\top \\mathbf{x}$ is the associated hypothesis. Define our loss function as $\\ell(h(\\mathbf{x}), y) = (h(\\mathbf{x}) - y)^2$. The unregularized linear regression corresponds to \\emph{empirical risk minimization} where your \\emph{hypothesis class} is restricted to linear functions.\n\n\\paragraph{Bagging vs Boosting} Bagging focuses on aggregating outputs of multiple hypotheses independently trained on different (sub)samples of train data. \n\nBoosting is more holistic approach, which sequentially chooses the weights on hypotheses and the weights on train examples. \n\n\\begin{exercise}\nCan each hypothesis in the ensemble be trained in a parallel manner for bagging? How about for boosting?\n\\end{exercise}\n\\begin{answer}\nBagging can be, but boosting cannot be due to its sequential nature.\n\\end{answer}\n\n\n\\begin{exercise}\nWith access to distributed system, is bagging always computationally superior to boosting?\n\\end{exercise}\n\\begin{answer}\n  Bagging reduces the variance only; its performance is essentially the average performance of the hypotheses in the ensemble. Each hypothesis in a boosted ensemble, on the other hand, needs to only satisfy weak learning hypothesis, which usually takes only a trivial amount of computing power.\n\\end{answer}\n\n\\section{AdaBoost}\nLet $S = \\{(\\vec{x}_i, y_i)\\}_{i=1}^{n}$ be the training set of examples. Let $\\WL$ be a $\\gamma$-weak learning algorithm that takes a distribution over input space (as a tuple of weights and samples) and returns a hypothesis (classifier) $f_t$ with error at most $\\frac{1}{2} - \\gamma$. Let $T$ be the number of iterations.\n\n\\begin{algorithm}\n\\caption{AdaBoost}\n\\KwIn{$S, \\WL, T$ as defined in the text}\n  initialize $\\mathbf{w}^1 = (1,\\ldots,1)$ \\\\\n  \\For{$t = 1,\\ldots, T$}{\n    normalize $\\vec{w}^{t}$ \\\\\n    invoke weak learner $f_t = \\WL(\\vec{w}^t, S)$ \\\\\n    compute $r_t = \\sum_{i=1}^{n} w_i^t \\mathbf{1}[y_i \\neq f_t(\\vec{x}_i)]$ \\\\\n    let $\\displaystyle\\alpha_t = \\frac{1}{2} \\log(\\frac{1}{r_t} - 1)$ \\\\\n    update $\\displaystyle w_i^{t+1} = w_i^{t} \\exp(-\\alpha_t y_i f_t(\\vec{x}_i))$ \\\\\n  }\n  \\KwOut{Return $\\F_T = \\sum_{t=1}^{T} \\alpha_t f_t$}\n\\end{algorithm}\n\n\\begin{theorem}\n  The training error (empirical risk) of AdaBoost satisfies:\n  \\[R_S(\\F_T) := \\frac{1}{n} \\sum_{i=1}^{n} \\mathbf{1}[\\F_T(\\vec{x}_i) \\neq y_i] \\leq \\exp(-2 \\gamma^2 T).\\]\n\\end{theorem}\n\\begin{proof} For each $t$, let\n\\[\\textstyle \\F_t = \\sum_{s=1}^{t} \\alpha_s f_s\\]\nand let $z_t$ be the normalizing constant for $\\vec{w}^t$, which is (by inductive argument)\n\\[z_t = \\frac{1}{n}\\sum_{i=1}^{n} \\exp(-y_i \\F_t (\\vec{x}_i)).\\]\n\\emph{(Optional paragraph.)} The proof is left for exercise. Roughly speaking, we update $w_i$ in a multiplicative manner, adding $-\\alpha_t y_i f_t(\\mathbf{x}_i)$ to the exponent every round. So at round $t$, we have $\\exp(-\\sum_{s=1}^{t} \\alpha_s y_i f_s(\\mathbf{x}_i)) = \\exp(-y_i \\F_s(\\mathbf{x}_i))$. The base case for $t=1$ gives the $(1/n)$.\n\n\nNote that the exponential function acts as a \\emph{smooth} upper bound on the loss of a hypothesis $h$, as $\\mathbf{1}[h(\\vec{x}) \\neq y] \\leq \\exp(-y h(\\vec{x})).$ So,\n$R_S(\\F_T) \\leq z_T$ and it suffices to show that $z_T \\leq \\exp(-2\\gamma^2 T)$. In other words, our normalization constant $z_t$ coincides with an upper bound on the empirical risk of $\\F_t$.\n\n\nRewrite \\[z_T = \\frac{z_T}{z_{T-1}} \\cdots \\frac{z_2}{z_1}.\\]\nIt suffices to show that for every $t$, \\[\\frac{z_{t+1}}{z_t} \\leq \\exp(-2\\gamma^2)\\]\nThis means that the \\emph{upper bound} on the empirical risk decreases in a multiplicative manner (fraction of mistakes fixed as opposed to a fixed number of mistakes fixed) every round. The actual empirical risk, however, might oscillate. Higher $\\gamma$ means faster decay in the upper bound, as it should.\n\n\\emph{The rest of the proof is optional:} Now,\n\\begin{align*}\n  \\frac{z_{t+1}}{z_t} &= \\frac{\\sum_{i=1}^{n} \\exp(-y_i \\F_{t+1}(\\vec{x}_i))}{z_t} \\\\\n  &= \\frac{\\sum_{i=1}^{n} \\exp(-y_i \\F_{t}(\\vec{x}_i)) \\exp(-y_i \\alpha_{t+1} f_{t+1}(\\vec{x}_i))}{z_t} \\\\\n  &=\\sum_{i=1}^{n} w_i^{t+1} \\exp(-y_i \\alpha_{t+1} f_{t+1}(\\vec{x}_i)) \\\\\n  &= \\exp(-\\alpha_{t+1})(1-r_{t+1}) + \\exp(\\alpha_{t+1})r_{t+1} \\\\\n  &= \\frac{1}{\\sqrt{1/r_{t+1} - 1}}(1-r_{t+1}) + \\sqrt{1/r_{t+1} - 1} \\ r_{t+1} \\\\\n  &= 2\\sqrt{r_{t+1} (1-r_{t+1})} \\leq 2 \\sqrt{\\left(\\frac{1}{2} - \\gamma\\right) \\left(\\frac{1}{2} + \\gamma\\right)} = \\sqrt{1 - 4\\gamma^2}.\n\\end{align*}\nTo complete the proof, use the inequality $1 - a \\leq e^{-a}$.\n\\end{proof}\n\nGenerally, minimizing a all-or-nothing (0-or-1 or 0-or-infinity) loss function is \\emph{computationally} hard in the sense of NP-hardness. Hence, we use a \\emph{surrogate loss} function that is continuous and convex. The \\emph{hinge loss} for soft-SVM is one such example which converts a 0-or-$\\infty$ loss function to a linear-and-flat function. Similarly, AdaBoost can be considered an algorithm that minimizes the exponential loss function. The key difference is that the exponential loss directly upper bounds the classification error, whereas the hinge loss does not.\n\n\\begin{exercise}\nExplain the semantics of the variables used in AdaBoost: $\\mathbf{w}^t$, $f_t$, $r_t$, $\\alpha_t$ and $F_t$.\n\\end{exercise}\n\n\\begin{exercise} Answer the following questions:\n\\begin{itemize}\n  \\item Convince yourself that $r_t$ is the  risk of $f_t$ when the true distribution is $\\mathbf{w}^t$.\n    \\[r_t = \\mathbb{E}_{i \\sim \\mathbf{w}^t}\\left[\\mathbf{1}[f_t(\\vec{x}_i) \\neq y_i]\\right].  \\]\n \\item Is $\\alpha_t$ an increasing or decreasing function of $r_t$? Why does it make sense, considering how we construct the final output $\\F_T$?\n \\begin{answer}\n   Decreasing. $f_t$ that had higher risk should contribute less to the final output $F_T$.\n \\end{answer}\n \\item The update rule for $w_i$ shows that the amount of change in $w_i^t$ is increasing or decreasing in $\\alpha_t$? Why does it make sense?\n  \\begin{answer}\n   Increasing. The weight $w_i$ should reflect how difficult it is to classify the $i$-th example correctly, so we can focus on the difficult examples. If $\\alpha_t$ is large, then $f_t$ performed well overall and thus it is a ``trustworthy'' hypothesis. Its mistakes should affect our opinion on how difficult each example is, more so than a non-trustworthy hypothesis (low $\\alpha_t$) would.\n \\end{answer}\n\\end{itemize}  \n\\end{exercise}\n\n\\begin{exercise}\nDoes AdaBoost guarantee a zero test error?\n\\end{exercise}\n\n\\begin{answer}\n  No. AdaBoost guarantees that if $T$ is sufficently large, then the \\emph{empirical risk} ultimately becomes 0. But it says nothing about the test error aka true risk.\n\\end{answer}\n\n\\section{Generalized Boosting (Optional)}\n\n\\subsection{Coordinate Descent}\nCoordinate descent is a variation of gradient descent, where you change a single coordinate per iteration. For example, suppose we want to minimize \n\\[J(a,b) = (a - 2)^2 (b + 1)^2 \\]\n% with gradient\n% \\[\\nabla J(a,b) = (2(a-2)(b+1), (a-2)^2).\\]\n\nFix the learning rate $\\eta = .1$. Initialize (arbitrarily) $a=b=0$. In the first round, we change $a$. So, we look at the partial derivative \n\\[\\frac{\\partial J}{\\partial a} = 2(a-2)(b+1)^2\\]\nwhich we evaluate at $a=b=0$ and get $-4$. Now we perform the coordinate descent update and get $a=.4, b=0$. We repeat the process for $b$:\n\\[\\frac{\\partial J}{\\partial b} = 2(a-2)^2(b+1)\\]\nwhich we evaluate at the current point and get $5.12$. So we perform the update and get $a=.4,b= -.512$, we repeat this process, and eventually converge to $a=2, b=-1$.\n\n\n\\subsection{Boosting as Coordinate Descent}\nWe observe that boosting is a slight variation of coordinate descent on a function of $T$ variables, where we do a single sweep through each variable. We use the notation $\\hat{\\ell}$ (in lecture notes, its $\\phi$) to denote the surrogate loss function. Assume that $\\partial{\\ell}/\\partial{\\alpha_t}$ is always negative. We first define the objective function\n\\[J(\\alpha_1, \\ldots, \\alpha_T) = \\frac{1}{n} \\sum_{i=1}^{n}\\hat{\\ell}\\left(y_i \\sum_{t=1}^{T} \\alpha_{t}f_t (\\vec{x}_i)\\right) =  \\frac{1}{n} \\sum_{i=1}^{n}\\hat{\\ell}\\left(y_i \\sum_{t=1}^{T} \\F_t (\\vec{x}_i)\\right).\\]\n\nWe initialize $\\alpha_t = 0$ for all $t$, and we do coordinate descent. At $t$-th iteration, we have\n\\[J(\\alpha_1, \\ldots, \\alpha_{T}) = \\frac{1}{n} \\sum_{i=1}^{n}\\hat{\\ell}\\left(y_i \\sum_{s=1}^{t-1} \\alpha_{s}f_s + y_i \\alpha_t f_t (\\vec{x}_i)\\right),\\]\nwhere $\\alpha_{t+1}, \\ldots, \\alpha_T$ terms are ommitted because they are still 0.\n\nHence, we update $\\alpha_t$ using the partial derivative:\n\\[\\frac{\\partial J}{\\partial \\alpha_t} = \\frac{1}{n} \\sum_{i=1}^{n} \\hat{\\ell}'_t(y_i \\F_{t-1}(\\vec{x}_i) + \\alpha_t y_i f_t(\\vec{x}_i)) y_i f_t(\\vec{x}_i)\\]\nwhere $\\hat{\\ell}'_t = \\frac{\\partial \\hat{\\ell}}{\\partial \\alpha_t}$ as a shorthand notation.\n\n\nBut we also have to choose $f_t$ which is not a number but a hypothesis. A smart way of choosing $f_t$ is such that the derivative is the largest, so we get the steepest coordinate descent update; that is, we choose $f_t$ to maximize the (directional) derivative:\n\\[\\arg\\max_{f_t} \\frac{\\partial J_t}{\\partial \\alpha_t}\\Big|_{\\alpha_t = 0} = \\arg\\max_{f_t} \\frac{1}{n} \\sum_{i=1}^{n} \\hat{\\ell}(y_i \\F_{t-1}) y_i f_t = \\arg\\min_{f_t} \\frac{1}{n} \\sum_{i=1}^{n} \\frac{\\hat{\\ell}'_t(y_i \\F_{t-1})}{\\sum_{i=1}^{n}\\hat{\\ell}_t'(y_i \\F_{t-1})} y_i f_t.\\]\n\nThe last equality is because $\\ell'$ is always negative. We cannot compute the exact minimizer (if that is the case, we don't even need boosting!). Instead, we have an algorithm $\\WL$ which will ``try'' to minimize the above and return a weak learning hypothesis $f_t$.\n\nOnce we fix $f_t$, it turns out that we can be very smart with how we update $\\alpha_t$, instead of doing the standard coordinate descent update. In particular, we update $\\alpha_t$ to be the minimizer:\n\\[\\alpha_t = \\arg\\min_{\\alpha} J(\\alpha_{1},\\ldots,\\alpha_{t-1},\\alpha).\\]\n\n% \\paragraph{AdaBoost as Coordinate Descent}\n% For AdaBoost, $\\hat{\\ell}$ is the exponential loss $\\hat{\\ell}(u) = \\exp(-u)$. So,\n% \\begin{align*}\n% \\sum w_i \\exp(-y_i f(\\vec{x}_i) \\alpha_t) \n% &\\leq \\sum_{i} \\frac{1 -y_i f(\\vec{x}_i)}{2} w_i \\exp(\\alpha^t) + \\sum_{i} \\frac{1 + y_i f(\\vec{x}_i)}{2} w_i \\exp(- \\alpha^t) \\\\\n% &= \\frac{1}{2} \\exp(\\alpha^{t}) - \\frac{1 - r_t}{2} \\exp(-\\alpha_t)\n% \\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "d28ded47f69fe22ca1cb7319269e5036d441e5a2", "size": 12456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discussion06_ensemble/discussion06_ensemble.tex", "max_stars_repo_name": "xipengwang/umich-eecs445-f16", "max_stars_repo_head_hexsha": "298407af9fd417c1b6daa6127b17cb2c34c2c772", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 97, "max_stars_repo_stars_event_min_datetime": "2016-09-11T23:15:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T08:03:24.000Z", "max_issues_repo_path": "discussion06_ensemble/discussion06_ensemble.tex", "max_issues_repo_name": "eecs445-f16/umich-eecs445-f16", "max_issues_repo_head_hexsha": "298407af9fd417c1b6daa6127b17cb2c34c2c772", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "discussion06_ensemble/discussion06_ensemble.tex", "max_forks_repo_name": "eecs445-f16/umich-eecs445-f16", "max_forks_repo_head_hexsha": "298407af9fd417c1b6daa6127b17cb2c34c2c772", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 77, "max_forks_repo_forks_event_min_datetime": "2016-09-12T20:50:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T14:41:23.000Z", "avg_line_length": 65.9047619048, "max_line_length": 573, "alphanum_fraction": 0.6897880539, "num_tokens": 4081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6358755579203013}}
{"text": "\\documentclass[10pt]{article}\n\\author{Alex Peyrard}\n\\title{equivalences}\n\n\\begin{document}\n\\maketitle\n\n\\section{Equivalences}\n\\[(1) \\Leftrightarrow \\forall\\varepsilon>0, \\lim_{n \\to \\infty} Pr(|X_{n}-Y|<\\varepsilon)=1\\]\n\\[(4) \\Leftrightarrow \\forall\\varepsilon>0, \\lim_{n \\to \\infty} Pr(|X_{n}-Y|\\leq\\varepsilon)=1\\]\n\\section{Proof that $(1) \\Rightarrow (4)$}\n\\[\\lim_{n \\to \\infty} Pr(|X_{n}-Y|<\\varepsilon) \\leq \\lim_{n \\to \\infty} Pr(|X_{n}-Y|\\leq\\varepsilon)\\]\n\\[\\lim_{n \\to \\infty} Pr(|X_{n}-Y|<\\varepsilon) = 1\\]\nWe thus have\n\\[1 <= \\lim_{n \\to \\infty} Pr(|X_{n}-Y|\\leq\\varepsilon) <= 1\\]\nSo \\[ \\lim_{n \\to \\infty} Pr(|X_{n}-Y|\\leq\\varepsilon) = 1 \\]\nQED\n\\section{Proof that $(4) \\Rightarrow (1)$}\n\\end{document}", "meta": {"hexsha": "ed58d661b906371601d67e356c9b48d7732be755", "size": 717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ICT/equivalences.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/equivalences.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/equivalences.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": 37.7368421053, "max_line_length": 103, "alphanum_fraction": 0.6443514644, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324938410783, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.635875557252491}}
{"text": "\\subsection{Bonus: Construct the Reals from the Rationals}\r\nThe definition of convergence and Cauchy sequence makes sense in $\\mathbb Q$ as well.\r\nThe matters, there are sequences in $\\mathbb Q$ that ``want to converge'' (being Cauchy) but don't, like $1,1.4,1.41,1.414$.\r\nIn fact, every $x\\in\\mathbb R$ is a limit of a sequence in $\\mathbb Q$ (by e.g. decimal expansion).\r\nSo we can define\r\n$$\\mathbb R=\\{(x_n)\\in\\mathbb Q: (x_n)\\text{ is Cauchy}\\}/\\sim$$\r\nwhere $\\sim$ is an equivalence relation defined by $(x_n)\\sim (y_n)\\iff x_n-y_n\\to 0$.\r\n\\begin{proposition}\r\n    This is indeed the real number with the intuitive definition of operations and order.\r\n\\end{proposition}\r\nIn particular $(x_n)\\ge0=(0,0,\\ldots)$ iff $\\exists N\\in\\mathbb n,\\forall n>N,x_n\\ge 0$.\r\n\\begin{proof}\r\n    Other properties are trivial, so we shall check the least-upper-bound property.\r\n    Note that the least-upper-bound property, the monotone sequence theorem and the statement that every Cauchy sequence converges are equivalent.\r\n    So we shall prove that every Cauchy sequence converges.\r\n    Suppose $(x_{m,n})=((x_m)_n)$ is a Cauchy sequence in $\\mathbb R$ defined the way we made it.\r\n    Then the sequence $(y_k)=x_{k,k}$ goes to the limit we want.\r\n\\end{proof}", "meta": {"hexsha": "ae3c821c47342974d253b5ba4287d1fb9d137971", "size": 1252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/rq.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": "2/rq.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": "2/rq.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": 69.5555555556, "max_line_length": 147, "alphanum_fraction": 0.71485623, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6358755537510418}}
{"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\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 5 for Bayesian Data Analysis}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 6.1a}\n{\n    Under the model assumption of identical effect for each group, we fix the hyperparameter $\\tau=0$ in our normal hierarchical model. Plug it in and we obtain $\\theta_j \\sim N(7.7, 4.1^2)$. The posterior predictive distribution is simulated as follows: \\\\\n    1) generate $\\theta \\sim N(7.7, 4.1^2)$, and \\\\\n    2) generate $y_j^\\mathrm{rep} \\sim N(\\theta, \\sigma_j^2)$ for each $j$, followed by \\\\\n    3) calculate the order stastistics out of $y_j^\\mathrm{rep}$ for each $j$.\n\n    The observed order statistics are approximately the order statistics calculated from the replicated simulations above. \n    \\begin{figure}[H]\n      \\centering\n      \\includegraphics[width = 1.0\\linewidth]{data.vs.png}\n      \\caption{Observed order statistics v.s. Simulations order statistics}\n    \\end{figure}\n    \\begin{lstlisting}\n    > mod = lm((data.simulated - data.observed) ~ data.observed)\n    > summary(mod)\n    \n    Call:\n    lm(formula = (data.simulated - data.observed) ~ data.observed)\n    \n    Residuals:\n        Min      1Q  Median      3Q     Max \n    -4.4555 -1.1794  0.3315  2.2663  2.6837 \n    \n    Coefficients:\n                  Estimate Std. Error t value Pr(>|t|)\n    (Intercept)   -1.30976    1.33122  -0.984    0.363\n    data.observed  0.07826    0.10150   0.771    0.470\n    \n    Residual standard error: 2.805 on 6 degrees of freedom\n    Multiple R-squared:  0.09014,\tAdjusted R-squared:  -0.06151 \n    F-statistic: 0.5944 on 1 and 6 DF,  p-value: 0.47\n    \\end{lstlisting}\n    The p-value is 0.47, so the null hypothesis of unit slope cannot be rejected. We therefore conclude that the model fits the aspect of data here. \n}\n\n\\section*{Question 6.1b}\n{\n    The model of identical effect for each group assumes that $\\theta_j = \\theta$ for all $j$, and that school A has better effect than school C simply \\emph{by chance}. But the model assumption can be skeptical given the observation, as we wonder whether there is other factors that cause school A to perform better than schoold C. In this case, the likelihood of the assumption of identical effects is far from being convincing, especially compared to the hierarchical models. \n}\n\n\\section*{Question 6.6a}\n{\n    We have 7 ones and 13 zeros out of the $n=20$ observations. \n    \\begin{itemize}\n        \\item \\textbf{Assume stops at 20th observation:}\\quad The likelihood is proportional to $\\theta^{7} (1-\\theta)^{13}$, according to the binomial model with number of observations fixed to 20.\n        \\item \\textbf{Assume stops at 13th zero:}\\quad The likelihood is also proportional to $\\theta^{7} (1-\\theta)^{13}$, \\emph{up to a different scale}, according to the negative binomial model with number of failures fixed to 13 with the last trial fixed to zero. \n    \\end{itemize}\n    There is no difference with the likelihood except for a constant factor. Therefore, the posterior distribution does not change, either.\n}\n\n\\section*{Question 6.6b}\n{\n    Generate $\\theta$ from $p(\\theta) \\sim \\theta^{7} (1-\\theta)^{13}$ for 10000 times, and generate $y^\\mathrm{rep}$ under the new protocol (stops at the 13th zero) each time. \n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 1.0\\linewidth]{switches.histogram.png}\n        \\caption{Histogram of number of switches}\n    \\end{figure}\n\n    First, the statistic T has a distribution with a heavier tail. This is because the number of observations can exceed the limit of $n=20$ under the new protocol. \n\n    Second, we find that T is more likely to be an even number than an odd number when $T < 10$. A possible explanation is: The last few observations must be zeros when $T$ is small, since the last one must be zero and there is few switches. Note that there must be $13$ zeros in total. Therefore, the distribution of $T$ is highly related to the specific value of $T$, i.e. $p(T=k)$ is more sensitive to $k$ when $k$ is relatively small. \n}\n\n\\section*{Source Code in R}\n{\n    \\begin{lstlisting}[language=R]\n    # Question 6.1\n    data.observed = c(28, 18, 12, 8, 7, 1, -1, -3)\n    data.simulated = c(26, 19, 14, 10, 6, 2, -3, -9)\n    \n    png(\"data.vs.png\", width=800, height=600)\n    plot(data.observed, data.simulated, main=\"Simulated v.s. simulated order statistics\")\n    dev.off()\n    \n    mod = lm((data.simulated - data.observed) ~ data.observed)\n    summary(mod)\n    \n    \n    # Question 6.6\n    T0 = 3 # number of switches\n    N = 10000\n    T = 1:N\n    theta = rbeta(N, shape1=7+1, shape2=13+1)\n    for (j in 1:N) {\n        count.switches = 0\n        y.last = rbinom(1, size=1, prob=theta[j])\n        count.zeros = 1 - y.last\n        while (1) {\n        y = rbinom(1, size=1, prob=theta[j])\n        if (y != y.last) {\n            count.switches = count.switches + 1\n        }\n        count.zeros = count.zeros + 1 - y.last\n        if (count.zeros > 12.5) {\n            break;\n        }\n        y.last = y\n        }\n        T[j] = count.switches\n    }\n    png(\"switches.histogram.png\", width=800, height=600)\n    hist(T, breaks=seq(-0.5, max(T)+0.5))\n    dev.off()\n    \\end{lstlisting}\n}\n\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "a073d8fad13512fc157e9f9a9e2a7485b8fe675f", "size": 5807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW5/Homework5.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": "HW5/Homework5.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": "HW5/Homework5.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": 42.0797101449, "max_line_length": 479, "alphanum_fraction": 0.6729808851, "num_tokens": 1732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6358755489139716}}
{"text": "\\subsubsection{Direction Matters}\r\n\\noindent\r\n\\begin{lemma}\r\n\t\\begin{equation*}\r\n\t\t\\int\\limits_{-C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = -\\int\\limits_{C}{\\vec{F}\\mathrm{d}\\vec{r}}\r\n\t\\end{equation*}\r\n\\end{lemma}\r\nThat is, the direction in which one takes a line integral matters. You can think of this as the wind helping you sail in one direction (positive line integral) but fighting against you in the opposite direction (negative line integral).", "meta": {"hexsha": "57fad3ae7fe1939b32fd82715ac4e6d35bddccab", "size": 446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/directionMatters.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/directionMatters.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/directionMatters.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": 55.75, "max_line_length": 236, "alphanum_fraction": 0.7286995516, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.635807711324228}}
{"text": "% Created 2020-11-11 Wed 19:46\n% Intended LaTeX compiler: pdflatex\n\\documentclass[11pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\author{Muaz Alhaider and Zakariya Ahmed}\n\\date{\\today}\n\\title{Program 2}\n\\hypersetup{\n pdfauthor={Muaz Alhaider and Zakariya Ahmed},\n pdftitle={Program 2},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 27.1 (Org mode 9.3)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section*{Modules}\n\\label{sec:orgeb98485}\n\n\\subsection*{Transitional Probability}\n\\label{sec:org7d7cbf4}\n   \\begin{math}\n    Transitional\\ Probability(Pos_i, Dir) = \\\\\n     (Pos_{from\\ left}:Drift(Left), Pos_{from\\ straight}:Drift(Straight), Pos_{from\\ right}:Drift(Right)): (\\text{For smoothing})\n\\end{math}\n\n\\newline\n\\begin{math}\n\\\\ \\\\\nTransitional\\ Probability(Pos_i, Dir) =\\\\ (Pos_{from\\ left}:Drift(Left), Pos_{from\\ straight}:Drift(Straight), Pos_{from\\ right}:Drift(Right), Pos_{from\\ behind}:Drift(Straight)): (\\text{For prediction})\n\\\\ \\\\\n\\end{math}\n\n\n\\emph{Left}, \\emph{Right}, and \\emph{Straight} are all positions defined in relation to what \\emph{Dir} is: if \\emph{Dir} is EAST, then \\emph{Left} is SOUTH, \\emph{Right} is NORTH, and Straight is EAST for example.\n\nHere, transitional probability has two forms: one which is all paths that converge to a point, and another where they diverge from a point. Prediction (as the name implies) wants all the possible paths to a point, which is why we include \\(Pos_{from\\ behind}\\). Smoothing however, does not use that, which is why it's not included.\n\n\n\\subsection*{Prediction}\n\\label{sec:org59a7289}\n$$Prediction(Grid, Direction) = \\left\\{pos_i \\in Grid \\mid \\sum_{(Pos_j, DriftProb)}^{Transition\\ Probability(pos_i, direction)} DriftProb \\cdot P(Pos_j) \\right \\}$$\n\n\\(Prediction(Grid, Direction)\\) (as the name implies) attempts to predict where the agent will be given previous information. It does this by transforming the grid by the expression  \\(\\sum^{Transition\\ Probability(pos_i, direction)}_{(Pos_j, DriftProb)} DriftProb \\cdot P(Pos_j)\\).This gets the probability of an agent drifting (or if direction is straight, accurately going to) a point, and what is the probability the agent would be at the point \\(Pos_j\\).\n\n\n\\subsection*{Evidence Conditional Probability}\n\\label{sec:org7e2fa92}\n   \\begin{math}\n  Evidence\\ Conditional\\ Probability(Pos_i, Evidence)= \\\\\n  \\prod^{\\text{Directions} }_{dir=W} Sense(evidence[pos_i dir], actual[pos_i+dir])\n\\end{math}\n\nThis is the expression we use to get the evidence conditional probability: it's the product of each the evidecne's value at a direction times what's actually in the value of the direction. So if \\emph{Left} has opened, but evidence says it's closed, it's 0.2. Taking the product of all direction's sensed value and actual value, it will result in the Evidence Conditional Probability at \\(Pos_i\\) given \\(Evidence\\)\n\n\\subsection*{Filtering}\n\\label{sec:org2604945}\n\n\n   \\begin{math}\nFiltering(Grid, Evidence) = \\{pos_i \\in Grid \\mid\\\\\n\\frac{P(pos_i) \\cdot Evidence\\ Conditional\\ Probability(pos_i, Evidence) }{\\sum^{all\\ positions}_{pos} P(pos_i) \\cdot Evidence\\ Conditional\\ Probability(pos_i, evidence) } \\}\n\\end{math}\n\n\n\nFiltering is a transformation upon the grid: each value gets transformed by the expression \\(\\frac{P(pos_i) \\cdot Evidence\\ Conditional\\ Probability(pos_i, Evidence) }{\\sum^{all\\ positions}_{pos} P(pos_i) \\cdot Evidence\\ Conditional\\ Probability(pos_i, evidence) }\\), which for purposes of making it easier to talk about, will be expressed as \\(Filter\\ Step(pos_i, Evidence)\\). \\(Filter\\ Step\\) is conditional probability of each point times what probabilty of the  point previously, and then dividing it  by the sum of all points on the grid. \n\n\\section*{Results}\n\\label{sec:org4a73001}\nThe code outputs the following:\n\\begin{verbatim}\njulia SUBMIT.jl\n\\end{verbatim}\n\n\\section*{Screenshots}\n\\label{sec:org3466924}\n\\begin{center}\n\\includegraphics[width=.9\\linewidth]{data/a9/3abd3f-f652-4b14-a3ef-d46d087ebe0c/screenshot-20201111-135323.png}\n\\end{center}\n\\begin{center}\n\\includegraphics[width=.9\\linewidth]{data/a9/3abd3f-f652-4b14-a3ef-d46d087ebe0c/screenshot-20201111-135329.png}\n\\end{center}\n\n\\section*{Who did what}\n\\label{sec:org8a29d99}\n\\subsection*{Zakariya}\n\\label{sec:org52942fd}\n\\begin{itemize}\n\\item Transitional probability/prediction algorithm, code and report.\n\\end{itemize}\n\\subsection*{Muaz}\n\\label{sec:org5f24d77}\n\\begin{itemize}\n\\item Conditional Evidence probability, filtering and smoothing algorithm and code.\n\\end{itemize}\n\\end{document}\n", "meta": {"hexsha": "99a3c0725c0b71b7c2b296903a1a6f6f63f92346", "size": 4786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "submit.tex", "max_stars_repo_name": "MuazAlhaidar/Fall-2020---Robot-Localization-with-HMM-Algorithm---Console---Group-Project", "max_stars_repo_head_hexsha": "ca6daf03f9b4f5a5d6d0a047478fcf7215c5587e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "submit.tex", "max_issues_repo_name": "MuazAlhaidar/Fall-2020---Robot-Localization-with-HMM-Algorithm---Console---Group-Project", "max_issues_repo_head_hexsha": "ca6daf03f9b4f5a5d6d0a047478fcf7215c5587e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "submit.tex", "max_forks_repo_name": "MuazAlhaidar/Fall-2020---Robot-Localization-with-HMM-Algorithm---Console---Group-Project", "max_forks_repo_head_hexsha": "ca6daf03f9b4f5a5d6d0a047478fcf7215c5587e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-31T15:20:42.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-31T15:20:42.000Z", "avg_line_length": 42.7321428571, "max_line_length": 544, "alphanum_fraction": 0.7540743836, "num_tokens": 1402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.635807711324228}}
{"text": "\\subsection{Solving}\n\n\\begin{frame}\n  \\frametitle{Solving}\n\n  Suppose that no negative cycle exists in $G(V,E)$ for $\\babst{\\mu}$, \n  how do we find a model $\\mu$ for the integer variables ?\n  \\vfill\n  \\pause\n  State-of-the-art methods employ SSSP (Single Source Shortest Paths) algorithms,\n  such as the {\\bf Bellman-Ford} algorithm (or its variations), as follows:\n  \\begin{itemize}\n    \\item we add an artificial vertex $I$ to $V$, and add $\\{ (I,x_1;0), \\ldots, (I,x_n;0) \\}$ to $E$\n          (notice that this never creates negative cycles)\n    \\vfill\n\n    \\item Compute the shortest paths from source $I$ (run Bellman-Ford). Let $\\pi(x)$ be the shortest path\n          from $I$ to $x$, for all $x \\in V$\n    \\vfill\n\n    \\item The model $\\mu$ can be computed as $\\mu(x) = -\\pi(x)$ for all $x \\in V$ (see later why)\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bellman-Ford} \n\n  $\\pi(x)$: current distance of $x$ from $I$\\\\\n  $TBV$: queue of vertexes To Be Visited\\\\\n\n  \\begin{tabbing}\n  as \\= a \\= a \\= a \\= as \\= asdfasdfasdfasdfasdfasdfasdfasdf \\= \\kill\n  1  \\> $\\pi(x) = \\infty$ for all $x \\in V, x \\not= I$ \\\\\n  2  \\> $\\pi(I) = 0$ \\\\\n  3  \\> $TBV.pushBack( I )$ \\\\\n  4  \\> while ( $TBV.size(\\ ) > 0$ ) \\\\\n  5  \\> \\> $s = TBV.popFront(\\ )$ \\\\\n  6  \\> \\> foreach $(s,t;w) \\in E$         \\> \\> \\> \\> // for each outgoing edge \\\\\n  7  \\> \\> \\> if ( $\\pi(t) - \\pi(s) > w$ )    \\> \\> \\> // is too far ? \\\\\n  8  \\> \\> \\> \\> $\\pi(t) = \\pi(s) + w$           \\> \\> // relax (decrease $\\pi(t)$) \\\\\n  9  \\> \\> \\> \\> if ( $TBV.has( t ) == false$ ) \\\\ \n  10 \\> \\> \\> \\> \\> $TBV.pushBack( t )$             \\> // enqueue t if not there \\\\\n  \\end{tabbing}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bellman-Ford, Example} \n\n  \\scriptsize\n    \n  $\\pi(x)$: current distance of $x$ from $I$\\\\\n  $TBV$: queue of vertexes To Be Visited\\\\\n\n  \\begin{columns}\n\n  \\begin{column}{.45\\textwidth}\n    \\begin{tabbing}\n    as \\= a \\= a \\= a \\= as \\= asdfasdfasdfasdfasdfasdfasdfasdf \\= \\kill\n    \\> \\coloneat{$\\pi(x) = \\infty$ for all $x \\in V, x \\not= I$}{3|handout:0} \\\\\n    \\> \\coloneat{$\\pi(I) = 0$}{3|handout:0} \\\\\n    \\> \\coloneat{$TBV.pushBack( I )$}{3|handout:0} \\\\\n    \\> while ( $TBV.size(\\ ) > 0$ ) \\\\\n    \\> \\> \\coloneat{$s = TBV.popFront(\\ )$}{4,7,10|handout:0} \\\\\n    \\> \\> \\coloneat{foreach $(s,t;w) \\in E$}{5,8,11|handout:0} \\\\\n    \\> \\> \\> \\coloneat{if ( $\\pi(t) - \\pi(s) > w$ )}{5,8,11|handout:0} \\\\\n    \\> \\> \\> \\> \\coloneat{$\\pi(t) = \\pi(s) + w$}{5,8,11|handout:0} \\\\\n    \\> \\> \\> \\> \\coloneat{if ( $TBV.has( t ) == false$ )}{5,8,11|handout:0} \\\\ \n    \\> \\> \\> \\> \\> \\coloneat{$TBV.pushBack( t )$}{5,8,11|handout:0} \\\\\n    \\end{tabbing}\n\n    $TBV = $ [ \\only<3|handout:0>{$I$}\\only<5,6|handout:0>{$x$}\\only<6|handout:0>{$,\\,$}\\only<6-9|handout:0>{$y,$}\\only<6-12|handout:0>{$z,w,t$} ] \\\\\n    Current vertex: \\only<4,5|handout:0>{$I$}\\only<7,8|handout:0>{$x$}\\only<10,11|handout:0>{$y$} \\\\\n    Current edge: \\only<5|handout:0>{$(I,x;0)$}\\only<11|handout:0>{$(y,z;-1)$} \n  \\end{column}\n\n  \\begin{column}{.55\\textwidth}\n    \\begin{center}\n    \\begin{overlayarea}{.55\\textwidth}{3cm}\n      \\only<1|handout:0>{\\input{example_bf}}\n      \\only<2|handout:0>{\\input{example_bf_1}}\n      \\only<3|handout:0>{\\input{example_bf_2}}\n      \\only<4|handout:0>{\\input{example_bf_3}}\n      \\only<5|handout:0>{\\input{example_bf_4}}\n      \\only<6|handout:0>{\\input{example_bf_5}}\n      \\only<7,8|handout:0>{\\input{example_bf_6}}\n      \\only<9|handout:0>{\\input{example_bf_5}}\n      \\only<10|handout:0>{\\input{example_bf_7}}\n      \\only<11|handout:0>{\\input{example_bf_8}}\n      \\only<12|handout:0>{\\input{example_bf_9}}\n      \\only<13|handout:0>{\\input{example_bf_10}}\n      \\only<14>{\\input{example_bf_11}}\n    \\end{overlayarea}\n    \\end{center}\n  \\end{column}\n\n  \\end{columns}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bellman-Ford, consideration}\n\n  \\scriptsize\n\n  \\begin{exampleblock}{Invariant}\n  At the end of BF, $\\pi(x)$ holds the shortest distance from $I$ to $x$, for all $x \\in V$ \\\\\n  \\end{exampleblock}\n  \\vfill\n  \\pause\n  \\begin{lemma}[Shortest Path]\n  At the end of BF, $\\pi(y) - \\pi(x) \\leq c$ holds for all $(x,y;c) \\in E$\n  \\end{lemma}\n  \\vfill\n  \\pause\n  \\begin{proof}\n  Suppose, for the sake of contradiction, that for an edge $(x,y;c)$, we have $\\pi(y) - \\pi(x) > c$\n    \\begin{center}\n      \\input{arc_proof}\n    \\end{center}\n    \\vspace{-30pt}\n    $\\pi(x)$ is the shortest dist. from $I$ to $x$ (by Invariant). But since $\\pi(y) > \\pi(x) + c$, \n    the shortest path from $I$ to $y$ is $\\pi(x) + c$. So $\\pi(y)$ is not the shortest dist. Contradiction.\n  \\end{proof}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Finding a model $\\mu$}\n\n  Because of the previous lemma we have that\n  \\vfill\n  \\begin{center}\n    $\\pi(y) - \\pi(x) \\leq c\\quad\\quad$ holds for all $(x,y;c) \\in E$\n  \\end{center}\n  \\vfill\n  So, if we take $\\quad\\quad\\mu(x) = -\\pi(x)\\quad\\quad$ we have that\n  \\vfill\n  \\begin{center}\n    $\\mu(x) - \\mu(y) \\leq c\\quad\\quad$ holds for all constraints in $\\babst{\\mu}$\n  \\end{center}\n  \\vfill\n  and therefore $\\mu$ is a model\n\n\\end{frame}\n", "meta": {"hexsha": "6a87c636820eeaf706acb4de02aaa10816cbfdec", "size": 5057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture5/solving.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": "lecture5/solving.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": "lecture5/solving.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": 34.4013605442, "max_line_length": 149, "alphanum_fraction": 0.5653549535, "num_tokens": 2042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6358077091401595}}
{"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 4}\n\nProve that all problems that are NP-complete are polynomially equivalent, in the sense that if $A$ and $B$ are NP-complete then $A \\leq_P B$ and $B \\leq_P A$.\n\n\\subsection*{Solution}\n\nBy definition, $A$ is NP-complete if and only if $A$ is in NP and for \\textbf{any} problem $B$ in NP, $B\\leq_P A$.\nProof is immediately attained by using assumptions that $A$ and $B$ are NP-complete, which means they are in NP.\nSince $B$ is in NP, using the assumption that $A$ is NP-hard, we can obtain $B \\leq_P A$.\nSimilarly, since $A$ is in NP, using the assumption that $B$ is NP-hard, we can write $A \\leq_P B$.\nTherefore, both NP-complete problems are equivalent.\n", "meta": {"hexsha": "13cbf21288997ed6712b359c9ff3fc9fee1d21d2", "size": 1033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q04.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/hw06q04.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/hw06q04.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": 54.3684210526, "max_line_length": 158, "alphanum_fraction": 0.6398838335, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7690802264851918, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.6358076954636326}}
{"text": "\\epigraph{``Since Newton, mankind has come to realise that the law of physics are always expressed in the language of differential equations\"}{Steven Strogatz}\n\n\\section{Finite Difference Method}\\label{fdm_section}\n\\subsection{Introduction}\nThe use of numerical models for the simulation of dynamics within the atmosphere typically involves the solution of a set of partial differential equations. These equations generally describe three processes: advection, adjustment and diffusion. \n\n\\begin{definition}\nAdvection is the transport of a substance by bulk motion.\n\\end{definition}\n\n\\begin{definition}\nAdjustment is how the mass and wind fields adjust to one another.\n\\end{definition}\n\n\\begin{definition}\nDiffusion is the movement of a liquid, or gas from an area of high concentration to an area of low concentration.\n\\end{definition}\n\nMost meteorological problems involving partial differential equations generally fall into three distinct categories: initial value problems, boundary value problems, and eigenvalue problems. The meteorological problems associated with this project are solely initial value problems\\cite{numerical_methods}. An initial value problem is a situation where you want to predict the future state of a given system, given the necessary initial conditions. Unfortunately, the equations describing the evolution of the atmosphere do not have exact analytical solutions.\n\n\\begin{definition}\nAn analytical function is the most precise way of representing a  physical field as it gives us the value of this field at any point in space, and at any instant in time.\n\\end{definition}\n\nWhen an analytical solution does not exist, an approximate numerical solution is found using a specified computational technique\\cite{numerical_methods}. For the purposes of this project, the finite difference method will be utilised. It must be noted, however, that there are several other methods to acquire an approximate numerical solution, with the finite element method and the spectral method being just a few.\n\nThe idea of the finite difference method is to approximate the derivatives in the partial differential equations with differences between adjacent points in space and in time. The advantages of this being that the problem becomes an algebraic one, and that a continuous problem becomes a discrete one.\n\n\\subsection{Derivation of the Finite Difference Method}\n\nIn order to derive the finite difference method, it is necessary to look at the Taylor series expansion of the function.\n\n\\begin{definition}\nThe Taylor series of a function is the limit of that function's Taylor polynomials as the degree increases.\n\\end{definition}\n\nThe Taylor series expansion of $f(x)$ can be represented as the following:\n\n\\begin{equation}\n    f(x + \\Delta x) = f(x) + \\frac{d f}{d x}(x) \\frac{\\Delta x}{1!} + \\frac{d^2 f}{d x^2}(x) \\frac{\\Delta x^2}{2!} + ... + \\frac{d^n f}{d x^n}(x) \\frac{\\Delta x^n}{n!} + ...\n\\end{equation}\n\\begin{equation}\n    f(x - \\Delta x) = f(x) + \\frac{d f}{d x}(x) \\frac{-\\Delta x}{1!} + \\frac{d^2 f}{d x^2}(x) \\frac{(-\\Delta x)^2}{2!} + ... + \\frac{d^n f}{d x^n}(x) \\frac{(-\\Delta x)^n}{n!} + ...\n\\end{equation}\n\nThe higher order terms, which will be represented as $\\mathcal{O}(\\Delta x)$ from this point on, become less important as $\\Delta x$ approaches zero.\n\n\\begin{equation}\n    \\Rightarrow f(x + \\Delta x) = f(x) + \\frac{d f}{d x}(x) \\frac{\\Delta x}{1!} + \\frac{d^2 f}{d x^2}(x) \\frac{\\Delta x^2}{2!} + [\\mathcal{O}(\\Delta x^3)] \n    \\label{fds}\n\\end{equation}\n\\begin{equation}\n    \\Rightarrow f(x - \\Delta x) = f(x) - \\frac{d f}{d x}(x) \\frac{\\Delta x}{1!} + \\frac{d^2 f}{d x^2}(x) \\frac{\\Delta x^2}{2!} + [\\mathcal{O}(\\Delta x^3)]\n    \\label{bds}\n\\end{equation}\n\nThese higher order terms are neglected, and the following approximation for the derivative of $f(x)$ is found:\n\n\\begin{equation}\n    \\Rightarrow \\frac{d f}{d x}(x) = \\frac{f(x + \\Delta x) - f(x)}{\\Delta x} + \\mathcal{O}(\\Delta x)\n\\end{equation}\n\\begin{equation}\n    \\Rightarrow \\frac{d f}{d x}(x) = \\frac{f(x - \\Delta x) - f(x)}{\\Delta x} + \\mathcal{O}(\\Delta x)\n\\end{equation}\n\nThese are called the forward and backward difference schemes respectively, and by keeping only the leading order terms, an error of order $\\mathcal{O}(\\Delta x)$ is occurred. It is possible to obtain a better approximation by subtracting \\ref{bds} from \\ref{fds}, which yields equation \\ref{eq_fds_bds_subtract}.\n\n\\begin{equation}\n    \\frac{d f}{d x}(x) = \\frac{f(x + \\Delta x) - f(x - \\Delta x)}{\\Delta x} + \\mathcal{O}(\\Delta x^2)\n    \\label{eq_fds_bds_subtract}\n\\end{equation}\n\nThis particular approximation is called the central difference scheme, and has an error of order $\\mathcal{O}(\\Delta x^2)$. Therefore, this scheme is more accurate than the previously mentioned forward and backward difference schemes. It is possible to take more and more terms from the Taylor series expansion, however, there is an inherent trade off between accuracy and computational efficiency. \n\nIn relation to the atmosphere, what this method does is divide the atmosphere into several discrete horizontal layers, and each layer is divided up into grid cells. Following which, each equation is evaluated at the centre of the cell. Similarly, the time interval under consideration is sliced into a number of discrete time steps. The size of the grid step $\\Delta x$ and time step $\\Delta t$ determines the accuracy of the scheme, with accuracy increasing as $\\Delta x$ and $\\Delta t$ approach zero. On a synoptic scale, $\\Delta x$ is generally equal to 500 km. For higher resolutions, the grid-size is smaller, which corresponds to a greater computational burden. As such, there is a trade off between accuracy and computational performance. For Eulerian schemes, the typical time step is 2 minutes. As such, since the software will use an Eulerian scheme, the time step will be 2 minutes\\cite{leapfrog_slides_one}.\n\n\\subsection{FTCS Scheme}\\label{ftcs_section}\n\nGiven the information mentioned in the previous section, the most obvious scheme to approximate a differential equation, which will be used to predict the future state of the atmosphere, would be to combine the central difference scheme for space and the forward difference scheme for time (FTCS). This scheme would allow us access to the increased accuracy of the central difference scheme, while maintaining two time variable unknowns. If only it was that simple! Let's take the example of the 1-D linear advection equation for temperature. This equation is represented as the following:\n\n\\begin{equation}\n    \\frac{\\partial T}{\\partial t} + u \\frac{\\partial T}{\\partial x} = 0\n    \\label{1d_temp_eq}\n\\end{equation}\n\nUsing the FTCS scheme mentioned above, this equation can be approximated as:\n\n\\begin{equation}\n    \\frac{T^{n+1}_{i} - T^{n}_{i}}{\\Delta t} + u \\frac{T^{n}_{i+1} - T^{n}_{i-1}}{2 \\Delta x} = 0\n\\end{equation}\n\nIt can be shown, by using Fourier Series, that:\n\n\\begin{equation}\n    |\\lambda_j|^2 = 1 + \\alpha^2(\\sin{j \\Delta x}^2)\n\\end{equation}\n\nTherefore, $|\\lambda_j|^2 \\geq 1$, and so the scheme is said to be absolutely unstable. What it means for a scheme to be unstable is that if there is a slight change in the initial value, the result of the computation will change dramatically. The stability of a scheme is important in meteorological problems because if slight deviations from the mathematical model caused by unavoidable errors in measurement do not have a correspondingly slight effect on the approximate numerical solution, the mathematical equations describing the problem will not accurately predict the future outcome\\cite{ftcs_leapfrog}. For a more detailed technical explanation of the stability of this scheme and the leapfrog scheme (discussed in section \\ref{leapfrog}), please see the following article: \\url{https://www.ecmwf.int/sites/default/files/elibrary/2002/16948-numerical-methods.pdf}.\n\n\\subsection{Leapfrog Scheme}\\label{leapfrog}\n\nThis scheme is probably the most common scheme used for meteorological problems. The \"leapfrog\" refers to the centred\ntime difference which is used in conjunction with centred space differences. \n\nTaking the 1-D linear advection equation for temperature seen in equation \\ref{1d_temp_eq}, applying this scheme results in:\n\n\\begin{equation}\n    \\frac{T^{n+1}_{i} - T^{n-1}_{i}}{2 \\Delta t} + u \\frac{T^{n}_{i+1} - T^{n}_{i-1}}{2 \\Delta x} = 0\n\\end{equation}\n\nIt can be shown that this scheme is stable using a similar technique mentioned in section \\ref{ftcs_section}. This equation can then be rearranged for the forecast value $T^{n+1}_{i}$\\cite{ftcs_leapfrog}:\n\n\\begin{equation}\n    T^{n+1}_{i} = T^{n-1}_{i} - u \\frac{2 \\Delta t}{2 \\Delta x}(T^{n}_{i+1} - T^{n}_{i-1})\n\\end{equation}\n\nFor the physical equation, a single initial condition $T^{0}$ is sufficient to determine the solution. One problem with the leapfrog scheme is that two values of $T$ are required to start the computation. In addition to the physical initial condition $T^{0}$, a computational initial condition $T^{1}$ is required. This cannot be obtained using the leapfrog scheme, so a non-centred step is used to provide the value at $t = \\Delta t$. From which point on, the leapfrog scheme is used, however, the errors of the first step will persist. This method, however, still retains an error of order $\\mathcal{O}(\\Delta t^2)$. If you also use half of the time step for the forward time step, followed by leapfrog time steps; this will reduce the error introduced in the first step\\cite{leapfrog_slides_two}. This will be the method utilised within the software.\n\n\\subsection{Nonlinear Instability}\nA major problem which occurs while dealing with nonlinear partial differential equations is nonlinear instability. This is a problem where there is a nonlinear interaction between atmospheric waves\\cite{nonlinear_instability}.  \n\n\\begin{definition}\nAn atmospheric wave is a periodic disturbance in the fields of atmospheric variables (like geopotential height, temperature, or wind velocity) which may either propagate (travelling wave) or not (standing wave).\n\\end{definition}\n\nIf one of the waves involved in this nonlinear interaction have a wavelength less than $4 \\Delta x$ something called aliasing causes a channelling of energy towards the small wavelengths. The continuous feedback of energy leads to a catastrophic rise in the kinetic energy of wavelengths between $2 \\Delta x$ and $4 \\Delta x$. Within the software, a smoothing operator, which reduces the amplitude of the short waves while having little effect on the meteorologically important waves, is utilised\\cite{nonlinear_instability}.\n\nAnother problem to mention before moving on is that for nonlinear equations, the leapfrog scheme has a tendency to increase the amplitude of the computational mode with time This can separate the space dependence between the even and odd time steps. This problem can be rectified by applying a Robert-Asselin Time Filter. After $T^{n+1}$ is obtained a slight time smoothing is applied to $T^{n}$, where $\\gamma$ is on the order of 0.1\\cite{leapfrog_slides_two}:\n\n\\begin{equation}\n    T^{n} = T^{n} + \\gamma(T^{n+1} - 2 T^{n} + T^{n-1})\n\\end{equation}\n\n\\section{Ensemble Prediction System}\n\\subsection{Introduction}\nEnsemble Prediction Systems (EPS) are numerical weather prediction systems that allow for the estimation of uncertainty in a weather forecast, as well as, providing a better prediction for the future state of the atmosphere. Instead of running a atmospheric dynamical simulation once (this would be regarded as deterministic), the simulation is run many different time with slightly different initial conditions. Due to the high computational resources required to run these simulations, they are often run at half the resolution of an equivalent deterministic simulation. The ensemble prediction system has a control simulation that doesn't have any perturbations to the initial conditions. Each simulation that makes up the system is called an ensemble member\\cite{intro_efs}.\n\n\\subsection{Advantages of EPS}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.8\\linewidth]{Images/efs.jpg}\n    \\caption{Visualisation of the Advantages of an Ensemble Prediction System}\n    \\label{efs}\n\\end{figure}\n\nAs a consequence of Chaos Theory, a tiny difference in the initial conditions in a large system, such as the atmosphere, can result in drastically different forecasted events, so that even with a tiny error, it can become a large error in the forecasted future state of the atmosphere. Even with the most accurate observations, error cannot be avoided. Therefore, it is simply not possible to make a better forecast or simulation. This is why an ensemble prediction system is utilised. In an ensemble simulation, small perturbations are made to the initial conditions, after which, the simulation is re-run. If there is a large degree of overlap between the ensemble members, there will be a higher degree of confidence in the ensemble forecast, with the opposite also holding true\\cite{intro_efs}.\n\n\\subsection{Global EPS}\nThere are three distinct types of ensemble prediction systems: global, regional and convective-scale. Each system address different timescales, and different grid-sizes. A global ensemble prediction system is designed and used for medium-range forecasting between 3 and 15 days into the future. They use synoptic simulation models and are run at relatively low resolutions. Although they are primarily designed for use in the medium range, their global coverage means that they can also be used to provide short-range EPS forecasts in regions of the globe where no other EPS are currently available, and may be the only available option for certain countries. Considering the software is focused on synoptic scale simulations, this will be the system of interest\\cite{intro_efs}, The default number of ensemble members in the software is fifteen, which is typical for a global ensemble prediction system. The grid-size, used by the software, can be specified by the end-user in order to get a more detailed forecast (this will increase the amount of computational resources required to run the simulation), however, the default grid-size is of the scale of 1000 km. There is also a hard limit of a $5^{\\circ} \\times 5^{\\circ}$ cell, as a smaller cell size would result in inaccurate simulations due to the fact that the dynamical equations utilised by the software do not work on this scale. This will be discussed at greater depth in chapter \\ref{4}.\n\n\\section{Recurrent Neural Network}\n\\subsection{Introduction}\nWeather forecasting has traditionally been done by physical models of the atmosphere, which are unstable to perturbations, and thus are inaccurate for large periods of time\\cite{why_rnn}. Since machine learning techniques are more robust to perturbations, it would be logical to combine a neural network with a physical model. Weather forecasting is a sequential data problem, therefore, a recurrent neural network is the most suitable option for this task. \n\n\\begin{definition}\nA recurrent neural network is a class of artificial neural networks where connections between nodes form a directed graph along a temporal sequence.\n\\end{definition}\n\nBefore, we delve into the specific example of using a recurrent neural network to predict the future state of the atmosphere, it is necessary to review what a recurrent neural network is. Recurrent Neural Networks (RNNs) are neural networks that are used in situations where data is presented in a sequence. For example, let's say you want to predict the future position of a fast-moving ball. Without information on the previous position of the ball, it is only possible to make an inaccurate guess. If you had, however, a large number of snapshots of the previous position, you are then able to predict the future position of the ball with some certainty. RNNs excel at modelling sequential data such as these. This is due to sequential memory.\n\nIn order to intuitively understand sequential memory, the prime example would be the alphabet. While it is easy to say the alphabet from A-Z, it is much harder to go from Z-A. There is a logical reason why this is difficult. As a child, you learn the alphabet in a sequence. Sequential memory is a mechanism that makes it easier for your brain to recognise sequence patterns.\n\nIn a traditional neural network, there is a input layer, hidden layer, and a output layer. In a recurrent neural network, a loop is added that can be added to pass information forward as seen in the diagram below (provided by Towards Data Science)\\cite{intro_rnn}:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.2\\linewidth]{Images/rnn.png}\n    \\caption{Visualisation of a Recurrent Neural Network}\n\\end{figure}\n\nThe information that is forwarded is the hidden layer, which is a representation of previous inputs. How this works in practise is that you initialise your network layers and the hidden the initial hidden state. The shape and dimension of the hidden state will be dependent on the shape and dimension of your recurrent neural network. Then you loop through your inputs, pass the relevant parameter and hidden state into the RNN. The RNN returns the output and a modified hidden state. Last you pass the output to the output layer, and it returns a prediction. \n\nThere is, however, a major problem known as short-term memory. Short-term memory is caused by something known as the vanishing gradient problem, which is also prevalent in other neural network architectures. As the RNN processes more steps, it has troubles retaining information from previous steps. Short-Term memory and the vanishing gradient is due to the nature of back-propagation. This can be comprehended through understanding how a neural network is trained\\cite{intro_rnn}.\n\n\\begin{definition}\nBack-propagation is an algorithm used to train and optimise neural networks.\n\\end{definition}\n\nTo train a recurrent neural network, you use an application of back-propagation called back-propagation through time. Training a neural network has three major steps. First, the relevant data vector is normalised between 0 and 1, the vector is feed into the RNN, and it goes through an activation function. The activation function utilised in the software is the rectified linear activation function\\cite{lstm_rnn}. \n\n\\begin{definition}\nThe rectified linear activation function is a piece-wise linear function that will output the input directly if is positive, otherwise, it will output zero.\n\\end{definition}\n\nThe function is linear for values greater than zero, meaning it has a lot of the desirable properties of a linear activation function when training a neural network using back-propagation. Yet, it is a nonlinear function as negative values are always output as zero. As a result, the rectified function is linear for half of the input domain and nonlinear for the other half, it is referred to as a piece-wise linear function\\cite{relu}. This nonlinear element is extremely important if the system has a nonlinear component, for example in predicting the evolution of the future state of the atmosphere.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.65\\linewidth]{Images/relu.png}\n    \\caption{Sketch of the Rectified Linear Activation Function}\n\\end{figure}\n\nSecond, it outputs the results. Third, it compares the prediction to the ground truth using a loss function.\n\n\\begin{definition}\nA loss function outputs an error value which is an estimate of how poorly the network is performing.\n\\end{definition}\n\nThe lost function that will be utilised in the software will be the function for mean squared error. The reason for choosing this particular function is that it heavily penalises large errors, as it squares the difference between the predicted and actual value. A large error in a weather forecast is highly undesirable, hence, the use of this function. The function is represented below:\n\n\\begin{equation}\n    MSE = \\frac{1}{n}\\sum_{i=1}^n(Y_i-\\hat{Y_i})^2\n\\end{equation}\n\nIf  a vector of $n$ predictions is generated from a sample of $n$ data points on all variables, and $Y$ is the vector of observed values of the variable being predicted, with $\\hat{Y_i}$ being the predicted values.\n\n\\begin{definition}\nMean squared error is the average squared difference between the estimated values and the actual value.\n\\end{definition}\n\nReturning to the training of the RNN, it uses that error value from the loss function. to do back propagation which calculates the gradients for each time step in the network. The gradient is the value used to adjust the networks internal weights, allowing the network to learn. The bigger the gradient, the bigger the adjustments and vice versa. Here is where the problem lies. When doing back propagation, the gradient of the current time step is calculated with respect to the effects of the gradients, in the time step before it. So if the adjustments to the time step before it is small, then adjustments to the current time step will be even smaller.  The gradient values will exponentially shrink as it propagates through each time step. That causes gradients to exponentially shrink as it back propagates down. The earlier layers fail to do any learning as the internal weights are barely being adjusted due to extremely small gradients.\n\nBecause of vanishing gradients, the RNN doesn’t learn the long-range dependencies across time steps. So not being able to learn on earlier time steps causes the network to have a short-term memory. In order to combat this, a long short-term memory is used\\cite{intro_rnn}.\n\n\\subsection{LSTM}\nLSTM's were created as a solution to the short-term memory problem. They have internal mechanisms called gates that can regulate the flow of information. These gates can learn which data in a sequence is important to keep or throw away. By doing that, it can pass relevant information down the long chain of sequences to make predictions. For example, if you were interested in buying a particular, you might read a review in order to determine if the purchase of the product is a good decision. When you read a review, your brain subconsciously only remembers important keywords. You pick up words like ``amazing\", ``superb\", or ``awful\", you don't remember words such as \"the\", \"as\", or \"because\". This is what an LSTM does, it learns to keep only the relevant information to make predictions.\n\nAn LSTM has a similar control flow as a recurrent neural network. It processes data passing on information as it propagates forward. The differences are the operations within the LSTM’s cells. The core concept of LSTM’s are the cell state, and it’s various gates. The cell state is the method by which information is transferred down the sequence chain. The cell state, in theory, can carry relevant information throughout the processing of the sequence. So even information from the earlier time steps can make it’s way to later time steps, reducing the effects of short-term memory. As the cell state goes on its journey, information get’s added or removed to the cell state via gates\\cite{lstm_rnn}.\n\n\\begin{definition}\nA gate is an electric circuit with an output which depends on the combination of several inputs.\n\\end{definition}\n\nGates contain the sigmoid activation function. The sigmoid activation function squishes values between 0 and 1. That is helpful to update or forget data because any number getting multiplied by 0 is 0, causing values to disappears or be ``forgotten\". Any number multiplied by 1 is the same value therefore that value stay’s the same or is ``kept\".\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.65\\linewidth]{Images/sigmoid.png}\n    \\caption{Sketch of the Sigmoid Activation Function}\n\\end{figure}\n\nThere are three types of gates utilised within a neural network: a forget gate, an input gate, and an output gate. A forget gate decides what information should be thrown away or kept. Information from the previous hidden state and information from the current input is passed through the sigmoid function. An input gate is where the previous hidden state and current input into a sigmoid function. The output gate decides what the next hidden state should be. The hidden state is also used for predictions. First, we pass the previous hidden state and the current input into a sigmoid function. Then we pass the newly modified cell state to the rectified linear activation function. We multiply the rectified linear activation function output with the sigmoid output to decide what information the hidden state should carry. The output is the hidden state. The new cell state and the new hidden is then carried over to the next time step\\cite{lstm_rnn}.\n\n\\subsection{Implementation}\\label{implement_rnn}\nThe data set for the initial conditions (which is discussed in section \\ref{noaa_initial_conditions}) consists of three features: geopotential height, air temperature, and relative humidity. For the purposes of this specific project, the RNN will solely be trained on air temperature and relative humidity. Unfortunately, due to the COVID-19, there was a time constraint on the developed of the RNN, which resulted in the inability to also train the RNN on geopotential height. This is due to the lack of computational resources at my disposable. The data set in question is updated every six hours by the National Oceanic and Atmospheric Administration. This means for a single day, there will be four observations. The goal for this project will be to, first predict the relevant atmospheric parameter in seven days time given the last thirty days of data and combine this RNN prediction with the physical model prediction in an attempt to make a more accurate prediction overall. In order to make such predictions, it is necessary to create a window of the last 120 ($30 \\times 4$) observations to train the model\\cite{time_series}.\n\nAt the start, a seed is set in order to ensure reproducibility. As mentioned previously, it is important to scale features before training a neural network. Normalisation is a common way of doing this scaling by subtracting the mean and dividing by the standard deviation of each feature. In order for the most optimal performance, the method ``MinMaxScaler\" from the library, scikit-learn, is utilised within the software\\cite{scikit-learn}. An LSTM requires a 1-dimensional sequence, however, the atmosphere is a 3-dimensional system. Hence, it is necessary to flatten the 3-dimensional vector that represents the state of the atmosphere. This is done in order to avoid the need of repeatably running the RNN. Batches are then created to split the data into manageable sequences. The diagram on the following page shows how the data is represented after flattening the data and batching it (provided by Tensorflow)\\cite{time_series}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.5\\linewidth]{Images/data_rnn.png}\n    \\caption{Visualisation of how the data is represented after flattening and batching.}\n\\end{figure}\n\nFollowing this process, the data is feed into the RNN. The LSTM model is built using Keras in TensorFlow, which is an free and open-source software library for machine learning. It was developed by the Google Brain Team\\cite{tensorflow}. It is apparent that a multi-step model is needed as the model needs to learn to predict a range of future values. The source code for the LSTM model developed for the software is shown below:\n\n\\begin{minted}[mathescape,linenos,frame=lines]{python}\n# Prepossessed historical data, which has been flatten and batched.\nx_data, y_data = prepossessing_function(input_data)\n# Prepossessed initial conditions, which has been flatten and batched.\ninitial_conditions = prepossessing_function(input_initialconditions)\n\n# The network is shown data from the last 15 days.\npast_history = 15 * 4\n\n# The network predicts the next 7 days worth of steps.\nfuture_target = 7 * 4\n\n# Create, and train models.\n# Optimiser.\nopt = Adam(lr=1e-6, decay=1e-10, clipvalue=0.6)\n# Create model.\nmodel = Sequential()\nmodel.add(\n    LSTM(\n        400, activation='relu', input_shape=(past_history, features)\n    )\n)\nmodel.add(RepeatVector(future_target))\nmodel.add(LSTM(400, activation='relu', return_sequences=True))\nmodel.add(LSTM(400, activation='relu', return_sequences=True))\nmodel.add(LSTM(400, activation='relu', return_sequences=True))\nmodel.add(TimeDistributed(Dense(features)))\nmodel.compile(\n    optimizer=opt, loss='mse', metrics=['mean_absolute_error']\n)\n\n# Train.\nmodel.fit(\n    x_data, y_data, epochs=epochs, batch_size=10\n)\n\n# Predict.\nfuture_state = model.predict(initial_conditions)\n# Invert normalisation, and flattening.\nfuture_state = inverse_prepossessing(future_state)\n\\end{minted}\n\nThe model consists of four LSTM layers, which in combination are able to produce a more accurate and reliable prediction than a single LSTM layer. As is evident, the activation function for each LSTM is the rectified linear activation function, which is built into Keras. The number of epochs can be specified by the end user depending on the computational resources they have and what they need. More epochs will evidently lead to a more accurate neural network.\n\n\\begin{definition}\nAn epoch is one forward pass and one backward pass of all the training examples.\n\\end{definition}\n\n\\section{Initial Conditions}\\label{noaa_initial_conditions}\n\\subsection{Global Data Assimilation System}\nThe initial conditions utilised by the software are from the Global Data Assimilation System (GDAS), which is provided by the National Oceanic and Atmospheric Adminstration in the United States. The primary reason for utilising this data is that it is freely available to the general public. In an ideal world, data from the European Centre for Medium-Range Weather Forecasts would be utilised, however unfortunately, there data is not freely available to the general public. This fundamentally violates the software's open source principles (these principles are discussed in chapter \\ref{5}).\n\nThe GDAS is a model to place observations into a gridded model space for the purpose of initialising weather forecasts with observed data. This system is utilised by the National Center for Environmental Prediction for such a purpose. GDAS adds the following types of observations to a gridded, 3-D, model space: surface observations, balloon data, wind profiler data, aircraft reports, buoy observations, radar observations, and satellite observations\\cite{gdas}. The initial conditions provided by the GDAS to the software have a vertical pressure co-ordinate, or the vertical co-ordiante is pressure. This co-ordinate system is known as isobaric co-ordinates.\n\n\\subsection{Isobaric Co-Ordinates}\nIn coordinate systems applied to the earth, the vertical coordinate describes position in the vertical direction (that is, parallel to the force of effective gravity). In meteorology, pressure can be a more convenient vertical coordinate than altitude. One reason is that until recently, radiosondes, which are the primary means of gathering observations of weather variables above the earth’s surface, measure and reported pressure, temperature, and humidity, but not altitude, as they rise through the atmosphere\\cite{isobar_i}.\n\n\\begin{definition}\nA radiosonde is an instrument carried by balloon to various levels of the atmosphere and transmitting measurements by radio.\n\\end{definition}\n\nAnother reason is that on scales large enough for the hydrostatic approximation to be valid (this is discussed in section \\ref{hydro_balance}), the pressure-gradient force in the equations of motion becomes simpler and density no longer becomes an explicit variable in the tendency equations\\cite{isobar_i}. Thus,a given geopotential gradient implies the same geostrophic wind at any height, whereas a given horizontal pressure gradient implies different values of the geostrophic wind depending on the density\\cite{isobar_ii}.\n\nFrom the Global Data Assimilation System, three prognostic variables are chosen: geopotential height, air temperature, and relative humidity.\n\n\\begin{definition}\nGeopotential Height is the height above sea level of a pressure level. For example, if a station reports that the 500 hPa height at its location is 5600 m, it means that the level of the atmosphere over that station at which the atmospheric pressure is 500 hPa is 5600 meters above sea level.\n\\end{definition}\n\nGeophysical sciences such as meteorology often prefer to express the horizontal pressure gradient force as the gradient of geopotential along a constant-pressure surface, because then it has the properties of a conservative force. For example, the primitive equations which weather forecast models solve use hydrostatic pressure as a vertical coordinate, and express the slopes of those pressure surfaces in terms of geopotential height. As such, this will be a parameter of great interest. From the aforementioned three selected parameters, any other parameter that is needed in the software can be calculated, including the wind. This will be discussed in greater depth in the next chapter.  \n", "meta": {"hexsha": "cdfdaae05097b70a39dab6e4e8ca18a42429f219", "size": 33147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scifest/online/project-book/Chapters/Dynamical_Core.tex", "max_stars_repo_name": "amsimp/papers", "max_stars_repo_head_hexsha": "a212b3f65140f0292d51055be324a7c1b084e121", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-15T10:06:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-15T10:06:17.000Z", "max_issues_repo_path": "scifest/online/project-book/Chapters/Dynamical_Core.tex", "max_issues_repo_name": "amsimp/papers", "max_issues_repo_head_hexsha": "a212b3f65140f0292d51055be324a7c1b084e121", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scifest/online/project-book/Chapters/Dynamical_Core.tex", "max_forks_repo_name": "amsimp/papers", "max_forks_repo_head_hexsha": "a212b3f65140f0292d51055be324a7c1b084e121", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 104.5646687697, "max_line_length": 1451, "alphanum_fraction": 0.7887591637, "num_tokens": 7354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6358076938143955}}
{"text": "\\section{Computational Problems and Complexity}\n\\label{cc-sect}\n\nWe base this section on the definitions in Papadimitriou \\cite{papad-cc},\nto which we refer for further details.\n\nA {\\em deterministic Turing machine} $\\mathcal{M}$ (we will imply the\n``deterministic'' from now on) is a representation of an\nalgorithm that takes an {\\em input}, runs a algorithm\nmanipulating the input on a {\\em tape}, and returns an\n{\\em output} when it comes to a halting state (if it ever does).\n\nThe tape and its manipulation can be seen as follows: initially the tape\ncontains the input, given by a {\\em first symbol} $\\rhd$ followed by a\nfinite string of symbols $x\\in (\\Sigma \\setminus \\{ \\sqcup \\})^\\ast$,\nwhere $\\Sigma$ is the {\\em alphabet} of symbols of $\\mathcal{M}$\nand $\\sqcup$ is a special\nsymbol representing the {\\em blank} string.\nThe program is then carried on: a {\\em cursor} starts at the first symbol\nand follows the {\\em algorithm} given by a\n{\\em transition function} $\\delta$. The transition function depends on the\ncurrent {\\em state} $p\\in K$ and the current symbol $\\sigma\\in \\Sigma$: the\nformer is the ``instruction'' to follow, the latter the symbol in the\nposition of the cursor. The transition function returns the next\nstate $q\\in K$, the symbol $\\tau\\in \\Sigma$ to be written at the position\nof the cursor, and a direction in which the cursor will move on the tape.\nThe possible directions are ``left'', ``right'', or ``stay'', represented\nrespectively\nby $\\leftarrow,\\rightarrow,-$. The first symbol is never\noverwritten, and from there the cursor can only go left.\n\nIn some cases, the machine reaches the state\n{\\sc Yes} (the machine {\\em accepts} the input), {\\sc No} (the machine\n{\\em rejects} the input) or the {\\em halting state} $h$\nafter a finite amount of time. The output\nis then given by $\\mathcal{M}(x)=\\text{\\sc Yes}$ or\n$\\mathcal{M}(x)=\\text{\\sc No}$ if the machine accepts or rejects the input.\nIf the halting state $h$ is reached, the output is $\\mathcal{M}(x)=y$,\nwhere $y$ is the finite (possibly empty) string of symbols that is left on\nthe tape after the symbol $\\rhd$ and before any string of $\\sqcup$'s at the\nend. It is also possible that the machine doesn't halt on input $x$; we\ndenote this case as $\\mathcal{M}(x)=\\nearrow$.\n\nA problem $P$ that requires an output that is either ``{\\sc Yes}'' or\n``{\\sc No}'' is a {\\em decision problem}; its {\\em complement} is the\nproblem $\\overline{P}$ that outputs ``{\\sc No}'' for each instance\nof $P$ that outputs ``{\\sc Yes}'', and vice versa.\nA problem where the output can be a string $\\mathcal{M}(x)=y$ on the\noutput tape as above is a {\\em function problem}; note that no guarantee\non the halting state is required. If the output is a\nstring $\\mathcal{M}(x)=y$ satisfying a relation $R(x,y)$\nor the input is rejected if it is not\npossible to find any such string, the problem is a {\\em search problem}.\nA search problem where the input is never rejected is a {\\em total\nfunction problem}. By Theorem \\ref{nash-thm}, the problem $n$-Nash of\nTable \\ref{n-nash} is a total function problem.\n\n\\begin{problem}\n{$n$-Nash}\n{A $n$-player game.}\n{A Nash equilibrium of the game.}\n\\label{n-nash}\n\\end{problem}\n\nFormally, a Turing machine is $\\mathcal{M}=(K,\\Sigma,\\delta,s)$,\nwhere $K$ and $\\Sigma$ are finite, $\\Sigma\\cap K=\\varnothing$ and $\\Sigma$\nalways contains the symbols $\\sqcup$ and $\\rhd$.\nThe {\\em transition function} is $\\delta$, defined as follows,\nwhere $\\{ \\leftarrow,\\rightarrow,- \\}\\nsubseteq(K\\cup\\Sigma)$:\n\\[\n\\delta:K\\times \\Sigma\\longrightarrow (K\\cup\\{ h,\\ \\text{{\\sc Yes}},\\ \\text{{\\sc No}} \\})%\n\\times \\Sigma \\times \\{ \\leftarrow,\\rightarrow,- \\}.\n\\]\n\nA slightly different, although equivalent, model allows for\n{\\em multiple strings}: $k\\in \\naturals$ cursors move\non $k$ strings $\\sigma_i\\in \\Sigma^\\ast$; the states are still\nrepresented as $p\\in K$. The input is given in the tape of the first string;\nassuming the machine halts, the output is given in the tape of the $k$-th\nstring.\n\nA {\\em language} is a set of {\\em strings of symbols}\n$L\\subseteq(\\Sigma\\setminus\\{ \\sqcup \\})^\\ast$; a {\\em class} is a\nset of languages. Let $\\mathcal{M}$ be a Turing machine, and let\n$x\\in (\\Sigma\\setminus\\{ \\sqcup \\})^\\ast$.\nWe say that $\\mathcal{M}$ {\\em decides} $L$ if\neither $\\mathcal{M}(x)=\\text{{\\sc Yes}}$ if $x\\in L$ or\n$\\mathcal{M}(x)=\\text{{\\sc No}}$\nif $x\\notin L$. A Turing\nmachine $\\mathcal{M}$ {\\em accepts} $L$ if\n$x\\in L$ is a necessary and sufficient condition for\n$\\mathcal{M}(x)=\\text{{\\sc Yes}}$, and if $x\\notin L$ then\n$\\mathcal{M}(x)=\\text{{\\sc No}}$ or $\\mathcal M$\ndoes not halt.\nFinally, $\\mathcal{M}$ {\\em computes} a function\n$f:(\\Sigma\\setminus\\{ \\sqcup \\})^\\ast\\to\\Sigma^\\ast$ if\n$\\mathcal{M}(x)=f(x)$ for every $x\\in (\\Sigma\\setminus\\{ \\sqcup \\})^\\ast$.\n\nLet $P_1$ be a problem and let $x$ be an instance of $P_1$ that is encoded\nin $|x|$ bits. $P_1$ {\\em reduces to the problem $P_2$ in polynomial time}\nif there exists a function $f: \\{0,1\\}^\\ast \\to \\{0,1\\}^\\ast$, a\nTuring machine $\\mathcal{M}$, and a polynomial $p$\nsuch that for all $x\\in\\{0,1\\}^\\ast$\n\\begin{enumerate}\n\\item $x\\in P_1\\quad\\iff\\quad f(x)\\in P_2$;\n\\item $\\mathcal{M}$ computes $f(x)$;\n\\item $\\mathcal{M}$ stops after $p(|x|)$ steps.\n\\end{enumerate}\n\nFor any class $\\mathrm{C}$ of decision problems, the class of all complements\nof the problems in $\\mathrm{C}$ is the {\\em complement class}\n$\\mathrm{co-C}$. A problem $P$ is {\\em hard} for a class $\\mathrm{C}$\nif every problem in $\\mathrm{C}$ is polynomial-time reducible to $P$; that is,\nif $P$ is at least as hard to solve as every problem in $\\mathrm{C}$. A\n{\\em complete} problem for the class $\\mathrm{C}$ is a $\\mathrm{C}-hard$ problem\nthat is also in $\\mathrm{C}$.\nIntuitively, if $P_1$ is polynomial-time reducible to $P_2$, it takes\npolynomial time to ``translate'' $P_1$ to $P_2$, and then to\n``translate back'' a solution of $P_2$ as a solution of $P_1$.\nThis is particularly useful if $P_2$ is hard: then\nthe problem $P_1$ is at least as ``difficult''. Furthermore, if the problem\n$P_2$ is also complete in a class $\\mathrm{C}$, it can be used as a test\nof belonging to the class $C$.\n\nThe complexity class $\\mathrm{\\mathbf{P}}$ ({\\em polynomial-time})\ncontains all the\n{\\em polynomially decidable problems}, that is, all problems $P$ such that\nthere exists a Turing machine $\\mathcal{M}$ that outputs either {\\sc Yes} or\n{\\sc No} for all inputs $x\\in\\{0,1\\}^\\ast$ of $P$ after $p(|x|)$ steps,\nwhere $p$ is a polynomial.\nA problem $P$ belongs to the class $\\mathrm{\\mathbf{NP}}$\n({\\em non-deterministic polynomial-time}) if there exists a\nTuring machine $\\mathcal{M}$ and polynomials $p_1,p_2$ such that\n\\begin{enumerate}\n\\item for all $x\\in P$ there exists a {\\em certificate} $y\\in \\{0,1\\}^\\ast$\nsuch that \\mbox{$|y|\\leq p_1(|x|)$};\n\\item $\\mathcal{M}$ accepts the combined input $xy$, stopping after at most\n$p_2(|x| + |y|)$ steps;\n\\item for all $x\\notin P$ there does not exist $y\\in \\{0,1\\}^\\ast$ such\nthat $\\mathcal{M}$ accepts the combined input $xy$.\n\\end{enumerate}\nAn equivalent definition gives $\\mathrm{\\mathbf{NP}}$ as the class of all\nlanguages $L$ for which the binary relation $R(x,y)$ such\nthat $L=\\{ x\\ |\\ R(x,y) \\text{ holds for some } y \\}$ satisfies\nthe following conditions:\n\\begin{enumerate}\n\\item {\\em (polynomially balanced)} if $(x,y)\\in R$ then $|y|\\leq |x|^k$ for\nsome $k\\in \\naturals$;\n\\item {\\em (polynomially decidable)} if there is a Turing machine that\ndecides $L$ in polynomial time.\n\\end{enumerate}\nInformally, a decision problem is in\n$\\mathrm{\\mathbf{P}}$ if the answer to its question can be found in a\nnumber of steps that is polynomial in the input of the problem, and\na decision problem is in $\\mathrm{\\mathbf{NP}}$ if it takes\npolynomial time to verify whether the ``certificate'' $y$ is,\nindeed, a correct answer to the question posed by the problem.\nNotice that there may be many different certificates for each instance\nof a problem. Consider for instance the $\\mathrm{\\mathbf{NP}}$ problem\n{\\sc Hamilton Path},\ndefined as ``given an input graph $x$, is it possible to find a Hamiltonian\npath $y$ of $x$?'' There are graphs with more than one possible\nHamiltonian path, and each one of these can be used as certificate.\n\nIt is quite simple to see that $\\mathbf{P}\\subseteq \\mathbf{NP}$, but it is\nan important open\nproblem whether the inclusion is strict. If this were\nnot the case, it could be\nargued that there isn't any substantial difference between finding a\nsolution and verifying its validity. This seems to contradict most of\nthe human intellectual experience, where the value\nof an ``original'' discovery is perceived as fundamental; the\n``conventional'' view is therefore that $\\mathbf{P}\\neq\\mathbf{NP}$.\nAnother open problem is whether $\\mathbf{NP} = \\mathbf{co-NP}$; again,\nthis is widely believed to be false. Notice that if\n$\\mathbf{NP} \\neq \\mathbf{co-NP}$ then\nalso $\\mathbf{P} \\subsetneq \\mathbf{NP}$, but not vice versa.\n\nThe classes $\\mathbf{FP}$ and $\\mathbf{FNP}$ are analogous to\n$\\mathbf{P}$ and $\\mathbf{NP}$, respectively, but for function problems\ninstead of decision problems.\nFormally, {\\bf FNP} ({\\em function non-deterministic polynomial-time})\nis defined\nin Megiddo and Papadimitriou \\cite{megiddo-papad} as the class\nof problems of the form ``given an $x\\in\\Sigma^\\ast$,\nfind $y\\in \\Sigma^\\ast$ such that $(x,y)\\in R$, where R is a\npolynomially balanced binary relation, or reject the input.''\n$\\mathbf{FP}$ ({\\em function polynomial-time}) is the\nclass of all $\\mathbf{FNP}$ problems that can be solved in polynomial time.\nAs in the case of decision problems, it is not known whether\n$\\mathbf{FP} = \\mathbf{FNP}$; the question is actually equivalent\nto whether $\\mathbf{P} = \\mathbf{NP}$.\nMegiddo and Papadimitriou \\cite{megiddo-papad} also define the class\n$\\mathbf{TFNP}$ ({\\em total function non-deterministic polynomial-time})\nas the class of all $\\mathbf{FNP}$ problems where for every $x\\in\\Sigma^\\ast$\na solution $y\\in\\Sigma^\\ast$ is guaranteed to exist.\nFrom another point of view, $\\mathbf{TFNP} = \\mathbf{F(NP\\cap co-NP)}$,\nand the existence of a $\\mathbf{TFNP}$-complete problem would imply\nthat $\\mathbf{NP} = \\mathbf{co-NP}$.\nThe lack of $\\mathbf{TFNP}$-complete problems has led to define\na number of new classes; we will see more of this in\nsection \\ref{ppad-sect}.\n\nThe class $\\mathrm{\\mathbf{\\# P}}$ is the class of all function\nproblems that output the\nnumber of possible certificates\nfor a decision problem in $\\mathrm{\\mathbf{NP}}$.\nFormally: the\n{\\em counting problem} associated with a binary\nrelation $Q(x,y)$ is ``given $x$, how many $y$ are there such\nthat $(x,y)\\in Q$?'' Then $\\mathrm{\\mathbf{\\# P}}$ is the class of\nall\ncounting problems associated with binary relations that are both\npolynomially\nbalanced and polynomially decidable.\nIt is interesting to notice that there are\n$\\mathrm{\\mathbf{\\# P}}$-complete\nproblems for which the corresponding search problem can\nbe solved\nin polynomial time. An example close to the topic\nof this thesis is given in Brightwell \\cite{brightwell}: although finding\nan Eulerian circuit in an\nundirected graph takes polynomial time, counting the number of possible\ncircuits in the same graph is complete in $\\mathrm{\\mathbf{\\# P}}$.\n\nFinally, the class {\\bf PSPACE} is the set of decision problems that can be\nsolved by a Turing machine using an amount of tape space that is polynomial\nin the size of the input; although it can be proven that\n$\\mathbf{NP}\\subseteq \\mathbf{PSPACE}$, the possibility of an identity\nis yet another open problem.\n", "meta": {"hexsha": "4acfc5a24c109c8d912a27ea97e837fb657cb96a", "size": 11542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-1/complexity-classes.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/complexity-classes.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/complexity-classes.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": 49.9653679654, "max_line_length": 89, "alphanum_fraction": 0.7170334431, "num_tokens": 3443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6358076916303276}}
{"text": "%\n% STAT 100: Chance and Data Analysis - A Course Overview\n% Section: Probability\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Probability}\n\t\\label{sec:probability}\n\\subsection{Introduction}\n\t\\label{subsec:probability:introduction}\n\\begin{easylist}\n\n\t& \\emph{Experiment:} Process which creates a bag of outcomes\n\t& \\emph{Sample space:} Set of all possible outcomes\n\t\t&& Denoted by $S$\n\t& \\emph{Event:} Possible outcome which satisfies a given condition(s)\n\t\t&& Denoted by $E$\n\n\t& \\emph{Probability:} Value between 0 and 1 (inclusive) representing the proportion of times an outcome/event is expected\n\t\t&& Denoted by $P(event)$\n\t\t&& Calculation:\n\t\t\\begin{math}\n\t\t\tP(A) = \\frac{|A|}{|S|}\n\t\t\\end{math}\n\t\twhere |X| is the number of outcomes for X\n\t\t&& 0 means the event is impossible; 1 means the event is certain\n\t\t&& Represented either by a fraction or a decimal value\n\t\t\n\t\t&& E.g. The probability of getting an odd number when rolling a 6-sided die:\n\t\t\n\t\t\\medskip\n\t\t\\Deactivate\n\t\t\\begin{center}\n\t\t\t\\begin{tabular}{ r @{ = } l }\n\t\t\t\t$S$ & Results of rolling a 6-sided die = 1, 2, 3, 4, 5, 6 \\\\\n\t\t\t\t$|S|$ & 6 \\\\\n\t\t\t\t$E$ & Getting an odd number = 1, 3, 5 \\\\\n\t\t\t\t$|E|$ & 3 \\\\\n\t\t\t\t$P(E)$ & $\\frac{|E|}{|S|}$ = $\\frac{3}{6}$ = 0.5\n\t\t\t\\end{tabular}\n\t\t\t\\Activate\n\t\t\\end{center}\n\t\t\n\t& %TODO\n\n\n\\end{easylist}\n\\clearpage", "meta": {"hexsha": "faeb58c5693b3836182f163a4fafac0173d0df49", "size": 1301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stat-100-chance-and-data-analysis/tex/probability.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": "stat-100-chance-and-data-analysis/tex/probability.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": "stat-100-chance-and-data-analysis/tex/probability.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": 26.5510204082, "max_line_length": 122, "alphanum_fraction": 0.6456571868, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6357093101706854}}
{"text": "\\section{Reduced Order Modeling}\n\\label{sec:ROMs}\nTo provide a very simple idea of a ROM, assume that the final\nresponse space of a physical system is governed by the transfer\nfunction $H \\left (  \\overline{x}\\right)$ (see Section\n~\\ref{sec:mathBackground}), which, from a practical point of\nview, represents the outcome of the system based on the initial\nconditions  $\\overline{x}$. Now, sample the domain of variability of the\ninitial conditions $\\overline{x}$ to create a\nset of $N$ realizations of the input and response space $ \\left ( \\left (\n\\overline{x}_{i}, H \\left (  \\overline{x}_{i}\\right) \\right), i=1,N \\right)$,\nnamed ``training'' set. Based on the data set generated, it is possible\nto construct a mathematical representation $G\\left ( \\overline{x}:\n\\overline{x}_{i}\\right)$ of the\nreal system $H \\left (  \\overline{x}\\right)$, which will approximate its\nresponse (see Figure~\\ref{fig:ROMexampleOfPhysicalSystem}):\n\\begin{equation}\n\\label{eq:regressor}\nG\\left ( \\overline{x} \\right ):\\overline{x}_{i} \\rightarrow G\\left ( \\overline{x}_{i} \\right ) \\cong H\\left ( \\overline{x}_{i} \\right )\n\\end{equation}\nThe ROMs reported above are generally named ``regressors'', among\nwhich all the most common data fitting algorithms are found (e.g.,\nleast square for construction of linear models).\nAn important class of ROMs for the work presented here after is the\none containing the so called ``classifiers''. A classifier is a ROM that is\ncapable of representing the system behavior from a binary point of\nview (e.g., event happened/not happened or failure/success). It is a\nmodel (set of equations) that identifies to which category an object\nbelongs in the feature (input) space. Referring to the example that\nbrought to Equation ~\\ref{eq:regressor}, a classifier can be formally represented as follows (see\nFigure~\\ref{fig:ROMClassifierExampleOfPhysicalSystem}):\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=1.0\\textwidth]  {pics/ROMexampleOfPhysicalSystem.png}\n  \\caption{Example of reduced order model representation of physical system (regression).}\n  \\label{fig:ROMexampleOfPhysicalSystem}\n\\end{figure}\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=1.0\\textwidth]  {pics/ROMClassifierExampleOfPhysicalSystem.png}\n  \\caption{Example of reduced order model representation of physical system (classifier).}\n  \\label{fig:ROMClassifierExampleOfPhysicalSystem}\n\\end{figure}\n\n\\begin{equation}\n\\label{eq:classifier}\nG\\left ( \\overline{x} \\right ):\\overline{x}_{i} \\rightarrow G\\left ( \\overline{x}_{i} \\right ) \\cong\nC \\left ( H\\left ( \\overline{x}_{i} \\right ) \\right )\n\\end{equation}\n\nThe function $C\\left (  H\\left ( \\overline{x}_{i}  \\right ) = \\overline{\\theta}\n\\right ) $ is the so called ``goal'' function that is able to recast the\nresponse of the system $H\\left ( \\overline{x}_{i}  \\right )$ into a binary\nform (e.g., failure/success). As an example, referring to\nFigure~\\ref{fig:ROMClassifierExampleOfPhysicalSystem}, the\n``goal'' function would be:\n\\begin{equation}\n\\label{eq:goalFunctionClassifier}\nC\\left (   \\overline{\\theta}  \\right ) = \\left\\{\\begin{matrix}\n1 & if \\: \\overline{\\theta}>1.0 \\\\\n0 &  if \\: \\overline{\\theta} \\leq 1.0\n\\end{matrix}\\right.\n\\end{equation}\nHence, the ROM of type classifier $G\\left (  \\overline{x} \\right )$  will operate in the space transformed through the ``goal''  function $C\\left (   \\overline{\\theta}  \\right )$.\n\\\\The classifiers and regressors can be categorized into two main classes:\n\\begin{itemize}\n  \\item Model-based algorithms\n  \\item Data-based algorithms\n\\end{itemize}\nIn the first class, the created ROM aims to approximate the response\nof the system as a function of the input parameters. These algorithms\nconstruct a functional representation of the system. Examples of such ROM type are Support Vector Machines (SVMs), Kriging-based regressors, discriminant-based models, and polynomial chaos.\n\nOn the other side, data-based algorithms do not build a response-\nfunction-based ROM but classify or predict the response of the\nsystem from the neighborhood graph constructed from the training\ndata, without any dependencies on a particular prediction model.\nThese algorithms directly build a neighborhood structure as the\nROM (e.g., a relaxed Gabriel graph) on the initial training data. Examples of such ROM type are nearest neighbors and decision trees.\n\n\\textcolor{red}{\\\\It is important to NOTE that RAVEN uses a Z-score normalization of the training data before\n  constructing most of the ROMs:\n\\begin{equation}\n  \\mathit{\\mathbf{X}} = \\frac{(\\mathit{\\mathbf{X}}-\\mu )}{\\sigma }\n\\end{equation}\n }\nIn order to identify which ROMs get trained with data normalized by the previous reported normalization approach, please refer to the RAVEN user manual \\cite{RAVENuserManual}.\n\nRAVEN has support of several different ROMs,\nsuch as:\n\\begin{enumerate}\n  \\item \\textit{Nearest Neighbors approaches}\n  \\item \\textit{Support Vector Machines}\n  \\item \\textit{Inverse Weight regressors}\n  \\item \\textit{Spline regressors }, etc.\n\\end{enumerate}\nIn this section only few of them are going to be explained. \n\n\\subsection{Gaussian Process Models}\n\\label{sec:GPM}\nGaussian Processes (GPs)~\\cite{Rasmussen_GPM} are algorithms that extend multivariate Gaussian distributions to infinite dimensionality. A Gaussian process generates a data set located throughout some domain such that any finite subset of the range follows a multivariate Gaussian distribution. Now, the n observations in an arbitrary data set, $y={y_1,\\ldots,y_n}$, can always be imagined as a single point sampled from some multivariate ($n$-variate) Gaussian distribution.\nWhat relates one observation to another in such cases is just the covariance function, $k(x,x')$. A popular choice is the squared exponential:\n\\begin{equation}\nk(x,x')=\\sigma_{f}^{2}  exp \\left [ \\frac{-(x-x')^2}{2 l^2} \\right ]\n\\end{equation}\nwhere the maximum allowable covariance is defined as $\\sigma_{f}^{2}$; this should be high for functions that cover a broad range on the y axis. If $x \\simeq x'$, then $k(x,x')$ approach this maximum meaning $f(x)$ is very correlated to $f(x')$. On the other hand, if $x$ is very distant from $x'$, then $k(x,x' ) \\simeq 0$ (i.e., the two points cannot see each other.\nSo, for example, during interpolation at new $x$ values, distant observations will have negligible effect). How much effect this separation has will depend on the length parameter $l$.\nEach observation $y$ can be thought of as related to an underlying function $f(x)$ through a Gaussian noise model:\n\\begin{equation}\ny=f(x)+N(0,\\sigma_{n}^{2})\n\\end{equation}\nThe new kernel function can be written as:\n\\begin{equation}\nk(x,x')=\\sigma_{f}^{2}  exp \\left [ \\frac{-(x-x')^2}{2 l^2} \\right ] + \\sigma_{n}^{2} \\delta(x,x')\n\\end{equation}\nSo given $n$ observations $y$, the objective is to predict the value $y_*$ at the new point $x_*$. This process is performed by following this sequence of steps:\n\\begin{enumerate}\n\\item Calculate three matrices:\n\\begin{equation}\nK=\\begin{bmatrix}\nk(x_1,x_1) &  \\ldots & k(x_1,x_n)\\\\\n\\vdots  & \\ddots &\\vdots  \\\\\nk(x_n,x_1) &  \\ldots & k(x_n,x_n)\n\\end{bmatrix}\n\\end{equation}\n\\begin{equation}\nK_*= \\begin{bmatrix}\nk(x_*,x_1) & \\ldots & k(x_*,x_n)\n\\end{bmatrix}\n\\end{equation}\n\\begin{equation}\nK_{**}=k(x_*,x_*)\n\\end{equation}\n\\item The basic assumption of GPM is that:\n\\begin{equation}\n\\begin{bmatrix}\ny\\\\\ny_*\n\\end{bmatrix}\n=\\mathcal{N}(0,\\begin{bmatrix}\nK & K_{*}^{T}\\\\\nK_* & K_{**}\n\\end{bmatrix})\n\\end{equation}\n\\item The estimate $\\bar{y_*} $ for $y_*$ is the mean of this distribution\n\\begin{equation}\n\\bar{y_*}=K_* K^{-1}y\n\\end{equation}\n\\item The uncertainty associated to the estimate $\\bar{y_*} $ can be expressed in terms of variance of  $y_*$:\n\\begin{equation}\nvar(y_*)=K_{**}-k_* K^{-1} K_{*}^{T}\n\\end{equation}\n\\end{enumerate}\n\n\\subsection{Support Vector Machines}\n\\label{sec:SVM}\nThe Support Vector Machine (SVM)~\\cite{SVM_Burges} classifier is a methodology that aims to determine the optimal separation hyperplane between data sets having different labels.\nThe training data consist of $N$ data points $(x_i,y_i)$ $i=1,\\ldots,N$ where $x_i \\in \\mathbb{R}^M$ and $y_i \\in {-1,1}$.\nAssuming a linear property of the hyperplane  then its definition is:\n\\begin{equation}\n\\left \\{ x: f(x)=x^T\\beta+\\beta_0=0 \\right \\}\n\\end{equation}\nwhere $\\beta$ is a unit vector.\n\nThe SVM parameters $\\beta$ and $\\beta_0$  are determined by solving this optimization problem:\n\\begin{equation}\n\\left\\{\\begin{matrix}\n\\underset{\\beta,\\beta_0}{min} \\left \\| \\beta \\right \\|\\\\\n\\text{subject to } y_i(x_{i}^{T}\\beta+\\beta_0)\\geq 1 , \\quad i=1,\\dots,N\n\\end{matrix}\\right.\n\\end{equation}\n\nOnce the SVM parameters $\\beta$ and $\\beta_0$ are determined then the classification of a new point $\\bar{x}$ is given by:\n\\begin{equation}\nG(\\bar{x})=sign(\\bar{x}^T\\beta+\\beta_0)\n\\end{equation}\n\n\n\\subsection{KNN Classifier and KNR Regressor}\n\\label{sec:KNN_KNR}\nThe K Nearest Neighbor algorithm~\\cite{altman_KNN} (KNN) is a non-parametric method used for both regression and classification. The only input parameter is the variable $K$ which indicates the number of neighbors to be considered in the classification/regression process. The special case where the class is predicted to be the class of the closest training sample (i.e. when $K = 1$) is called the nearest neighbor algorithm. In binary (two class) classification problems, it is helpful to choose k to be an odd number as this avoids tied votes. The output depends on whether KNN is used for classification or regression:\n\\begin{itemize}\n\\item In KNN classification, the output is a class membership. An object is classified by a majority vote of its neighbors, with the object being assigned to the class most common among its $K$ nearest neighbors ($K$ is a positive integer, typically small). If $K = 1$, then the object is simply assigned to the class of that single nearest neighbor.\n\\item In KNN regression, the output is the property value for the object. This value is the average of the values of its $K$ nearest neighbors.\n\\end{itemize}\nBoth for classification and regression, it can be useful to assign weight to the contributions of the neighbors, so that the nearer neighbors contribute more to the average than the more distant ones. For example, a common weighting scheme consists in giving each neighbor a weight of $1/d$, where $d$ is the distance to the neighbor.\n\n\\subsection{Multi-Dimensional Interpolation}\n\\label{sec:ND_interp}\nThis section covers the methods that have been implemented in the CROW statistical library:\n\\begin{itemize}\n\\item Shepard's Method (see Section~\\ref{sec:shepard})\n\\item Multi-Dimensional Spline method (see Section~\\ref{sec:ND_spline}).\n\\end{itemize}\n\nThese two methods are interpolation methods that can be used in any dimension.\nIn RAVEN they are employed in two major applications:\n\\begin{enumerate}\n\\item ROMs\n\\item Multi-dimensional distributions.\n\\end{enumerate}\nFor both applications, given a set of $N$ data points $ (x_i,u_i )$  $i=1,\\ldots,N$ where $x_i$ are the coordinate in the input space $D \\subset \\mathbb{R}^M$ and $u_i \\in \\mathbb{R}$ is the outcome, the methods predicts the outcome $\\tilde{u}$ for a new coordinate $\\tilde{x}\\in \\mathbb{R}^n$.\n\n\n\\subsubsection{Shepard's Method}\n\\label{sec:shepard}\nThe Shepard interpolator~\\cite{Shepard} is also know as Inverse Distance Weighting (IDW) interpolator.\nThe starting point is a set of $N$ data points $ (x_i,u_i )$ for $i=1,\\ldots,N$.\nThe Inverse-Weight interpolator can be represented as a function $f_{IDW}(x)$ that, given a new coordinate in the input space $x$, generates a prediction on $u$ such that\n\\begin{equation}\nu:x \\in \\mathbb{R}^M \\rightarrow f_{IDW}(x) \\in \\mathbb{R}\n\\end{equation}\nbased on the distance $d(x,x_i)$ in the euclidean space between $x$ and $x_i$.\n\nSuch prediction $u=f_{IDW}(x)$ is performed by summing all data points $x_i$ $i=1,\\ldots,N$ weighted by a weighting parameter $w_i (x)$ as follows:\n\\begin{equation}\nf_{IDW}(x) =\n\\left\\{\n\\begin{matrix}\n\\sum_{i=1}^{N} w(x_i) u_i &  \\text{if } d(x,x_i) \\neq 0 \\\\\n u_i &  \\text{if } d(x,x_i) = 0\n\\end{matrix}\\right.\n\\end{equation}\nwhere\n\\begin{equation}\nw(x_i) =\\frac{w_i}{\\sum_{i=1}^{N} w_i}\n\\end{equation}\nand\n\\begin{equation}\nw_i = \\left ( \\frac{1}{d(x,x_i)} \\right )^p\n\\end{equation}\nLarge values of $p$ assign greater weight $w_i$ to data points $x_i$ closest to $x$, with the result turning into a mosaic of tiles (i.e., Voronoi diagram) with nearly constant interpolated value.\n\n\\subsubsection{Multi-Dimensional Spline}\n\\label{sec:ND_spline}\nThe Multi-Dimensional Spline (MDS)~\\cite{MD_spline} is a method that requires the sampled points $x_i$ to be lying in multi-dimensional cartesian grid.\nA generic grid $\\Delta_m$ for each dimension $m$ will be indicated as follows:\n\\begin{equation}\n\\Delta_m = \\{x_{0_m},x_{1_m},\\ldots,x_{p_m}\\} \\text{ for } m=1,\\ldots,M\n\\end{equation}\nThis methods construct a $M$-dimensional cubic spline so that, given a coordinate in the input space $x=(x_1,x_2,\\ldots,x_M)$, generates a prediction on $u$ such that\n\\begin{equation}\nu:x \\in \\mathbb{R}^M \\rightarrow f_{MDS}(x) \\in \\mathbb{R}\n\\end{equation}\nwhere\n\\begin{equation}\nf_{MDS}(x)=\\sum_{i_1=1}^{p_1+3} \\sum_{i_2=1}^{p_2+3} \\ldots \\sum_{i_M=1}^{p_M+3} c_{i_1,i_2,\\ldots,i_p} \\prod_{m=1}^{M} u_{i_j} (x_m)\n\\end{equation}\nwhere\n\\begin{equation}\nu_{i_j} (x_m) = \\Phi\\left ( \\frac{x_m-x_{0_m}}{h_j}+2-i_j  \\right )\n\\end{equation}\n\nThe cubic kernel $\\Phi(t)$ is defined as:\n\\begin{equation}\n\\Phi(t) = \\left\\{\\begin{matrix}\n(2-\\left | t \\right |)^3 & 1\\leq \\left | t \\right |\\leq 2 \\\\\n4-6\\left | t \\right |^2+3\\left | t \\right |^3 & \\left | t \\right |\\leq 1\\\\\n0 & \\text{elsewhere}\n\\end{matrix}\\right.\n\\end{equation}\n\nThe set of $\\prod_{m=1}^{M}(p_m+3)$ coefficients $c_{i_1,i_2,\\ldots,i_p}$  is determined when the interpolator is initialized.\n\n", "meta": {"hexsha": "f31b29c53a2b630fa4df6d8551a3d42356deed61", "size": 13827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory_manual/reducedOrderModeling.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/reducedOrderModeling.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/reducedOrderModeling.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": 52.1773584906, "max_line_length": 623, "alphanum_fraction": 0.7365299776, "num_tokens": 4113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616712, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6357092928520761}}
{"text": "\\chapter{Linear Models: Analysis of variance}\n\\label{ch:ANOVA}\n\nAims of this chapter \\footnote{Here you work with the script file {\\tt anova.R}}:\n\\begin{compactitem}\n\t\\item Plotting boxplots and barplots using factors\n\t\\item Fitting factors in linear models using analysis of variance\n\t\\item Diagnostic plots for explanatory factors\n\t\\item Exploring differences between levels of a factor\n\\end{compactitem}\n\n\\section{What is ANOVA?}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.4\\textwidth]{ANOVA_is_LM.pdf} \n\n\t\\caption{A dataset where an ANOVA would be appropriate. performing an \n\tANOVA test on this dataset is the same as fitting the linear model  \n\t$y  = \\beta_1  + \\beta_2 x_s + \\beta_3 x_a$, where $x_s$ and $x_a$ \n\tare two levels. There are three ``treatments'' here with the first \n\ttreatment, the control, captured by the baseline value $\\beta_1$ \n\t(the sample with the lowest value, on the far left)}\n\n\t\\label{fig:anova1} \n\n\\end{figure}\n\nA {\\it One-way analysis of variance} (one-way ANOVA) is a technique \nused to compare means of two or more samples representing numerical, \ncontinuous data. \n\nANOVA tests the null hypothesis that samples from two or more groups \nare drawn from populations with the {\\it same mean value}. To do this, \nANOVA uses the {\\it F}-statistic --- the ratio of the variance \ncalculated across the samples (groups) (the null hypothesis) to the \nvariance within the samples (groups). If the null hypothesis that the \ngroup means are drawn from populations with the same mean is indeed \ntrue, the between-group variance (numerator in the F-ratio) should be \nlower than the within-group variance (denominator). A higher ratio (and \n{\\it F} value) therefore implies that the samples were drawn from \npopulations with different mean values.\n\nThis is same as asking whether a linear model with a predictor (or \nexplanatory variable) with at least two categorical levels (or \nfactors), better accounts for the variance (Explained Sum of Squares, \nESS) than a null model of the form $y  = \\beta_1$ (Figure \n\\ref{fig:anova1}). Thus, ANOVA is just a type of linear model. \n\nBy the end of this chapter, it will make more sense to you how/why \nlinear regression models that we covered in Chapter \\ref{ch:regress}, \nof the form $y = \\beta_1  + \\beta_2 x$ (where $x$ is a continuous \npredictor variable),  require ANOVA to determine if the the model \nbetter fits than a null model of the form $y  = \\beta_1$.\n\nTypically, one-way ANOVA is used to test for differences among at least \nthree groups, since the two-group (or levels or factors) case can be \ncovered by a $t$-test (see Chapter~\\ref{ch:t_F_tests}). When there \nare only two means to compare, the $t$-test and the F-test are \nequivalent; the relation between ANOVA and t is given by $F = t^2$. \n\nAn extension of one-way ANOVA is two-way analysis of variance that \nexamines the influence of two different categorical independent \nvariables on one dependent variable --- we will look at multiple \npredictor variables in Chapter \\ref{ch:MulExpl} onwards.\n\n\\section{Calculating the ANOVA test statistic}\n\nANOVA ``partitions'' variability in your data as follows: \n\n\\begin{description}\n\n\t\\item[Total sum of squares (TSS)] This is sum of the squared \n\tdifference between the observed dependent variable ($y$) and the mean \n\tof the response variable $y$ (denoted by $\\bar{y}$), i.e., \n\t$$\\text{TSS} = \\sum_{i=1}^{n}(y_i - \\bar{y})^2$$ TSS tells us how \n\tmuch variation there is in the dependent variable without having any \n\tother information (your null model). You might notice that TSS is the \n\tnumerator of the sample variance you learned about in Chapter \n\t\\ref{ch:ExpDesign}.\n  \n\t\\item [Explained sum of squares (ESS)] Sum of the squared differences \n\tbetween the predicted $y$'s (denoted $\\hat{y}$'s) and $\\bar{y}$, or, \n\t$$\\text{ESS} = \\sum_{i=1}^{n} (\\hat{y}_i - \\bar{y})^2$$ ESS tells us \n\thow much of the variation in the dependent variable our alternative \n\t(linear) model was able to explain. That is, it's the reduction in \n\tuncertainty that occurs when the linear model is used to predict the \n\tresponses.\n\t\n\t\\item [Residual sum of squares (RSS)] Sum of the squared differences \n\tbetween the observed $y$'s (denoted by $y_i$) and the predicted \n\t$\\hat{y}$, or, $$\\text{RSS} = \\sum_{i=1}^{n} (\\hat{y}_i - y_i)^2$$ \n\tRSS tells us how much of the variation in the dependent variable our \n\tmodel could not explain. That is, it's the uncertainty that remains \n\teven after the linear model is used. The linear model is considered \n\tto be statistically significant if it can account for a large amount \n\tof variability in the response.\n\n\\end{description} \n\nAnd of course, TSS = ESS + RSS; the OLS method ``decomposes'' the total variation in the dependent variable into an explained component (ESS; explained by the predictor) and an unexplained or residual component (the RSS). \n\nThese sums of squares can then be used to calculate the statistical \nsignificance of the linear model (Regression, ANOVA, etc) through the \nF-Value (or F-Ratio), as follows: \n\n\\begin{center}\n\\def\\arraystretch{1.5}\n\\begin{tabular}{|>{\\centering}m{2cm}|>{\\centering}m{2.1cm}|>{\\centering}m{2cm}|>{\\centering}m{2cm}|p{1.5cm}|}\n\\hline\nType of Sum of Squares (SS)  & Calculation & Degrees of Freedom (DF) & \nMean Sum of Squares (MSS) & F-Value \\\\ \\hline\n\nTSS & $\\sum_{i=1}^{n}(y_i - \\bar{y})^2$   & $n-1$ &$\\frac{TSS}{n-1}$& \n\\multirow{3}{*}{ \n$\\frac{\\left(\\frac{ESS}{n_c-1}\\right)}{\\left(\\frac{RSS}{n-n_c}\\right)}$} \\\\ \\cline{1-4}\n\nESS & $\\sum_{i=1}^{n} (\\hat{y}_i - \\bar{y})^2$ & $n_c-1$ & $\\frac{ESS}{n_c-1}$ &  \\\\ \\cline{1-4}\n\nRSS & $\\sum_{i=1}^{n} (\\hat{y}_i - y_i)^2$ &  $n-n_c$ &  $\\frac{RSS}{n-n_c}$ & \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection{Degrees of freedom}\nThus each sum of squares has a corresponding degrees of freedom (DF) \nassociated with it that gives the Mean Sum of Squares (MSS)  --- the Sums of Squares divided by the corresponding degrees of freedom.\n\nThe TSS DF is one less than the number of observations $n-1$. This is because calculating TSS, needs $\\bar y$ , which imposes loss of one degree of freedom. Note that MSS is thus nothing but the sample variance.\n\nThe ESS DF is one less than the number of coefficients ($n_c$) \n(estimated parameters) in the model: $n_c-1$. Note that in the case \nwhere the linear model is an ANOVA, it the number of coefficients \nequals the number of ``treatments'' (the categories or levels in the \npredictor). So for example, in Fig. \\ref{fig:anova1}, there are three \ntreatments (predictors) and therefore three coefficients ($\\beta_1$, \n$\\beta_2$, $\\beta_3$), which means that the ESS degrees of freedom \nthere is $n_c-1 = 2$. \n\nThe RSS DF is the sample size $n$ minus the number of coefficients $n_c$, that is, $n - n_c$, because each estimated coefficient is an unknown parameter.\n\n\\subsection{The F-Value (or Ratio)}\n\nFinally, The F-Value or F-Ratio, the test statistic used to decide \nwhether the linear model fit is statistically significant, is the ratio \nof the Mean ESS to the Mean RSS. The null hypothesis is rejected if the \nF-ratio is large --- the model explains a significant amount of \nvariance. The p-value is then calculated from the F-distribution as you \nlearned before, in Chapter \\ref{ch:t_F_tests} (see Fig. \\ref{fig:fdist}).  \n\nAlso note that the Root Mean Square Error (RMSE), also known as the \nstandard error of the estimate, is the square root of the Mean RSS. It \nis the standard deviation of the data about the Linear model, rather \nthan about the sample mean.\n\n\\subsection{The $R^{2}$}\n\nFinally, $R^{2}$, also called the Coefficient of Determination, is the \nproportion of total error (TSS) explained by the model (ESS), so the \nratio ESS/TSS. That is it is the proportion of the variability in the \nresponse that is explained by  by the fitted model. Since TSS = ESS + \nRSS, $R^{2}$ can be rewritten as (TSS-RSS)/TSS = 1 - RSS/TSS. If a \nmodel has perfectly fits the data, $R^{2}=1$, and if it has no \npredictive capability $R^{2}=0$. In \nreality, $R^{2}$ will never be exactly 0 because even a null model will \nexplain some variance just by chance due to sampling error. Note that \n$R$, the square root of $R^2$, is the multiple correlation coefficient: \nthe correlation between the observed values ($y$), and the predicted \nvalues ($\\hat{y}$).\n\nAs additional predictors (end therefore linear model coefficients) are \nadded to a linear model, $R^2$ increases even when the new predictors \nadd no real predictive capability. The adjusted-$R^2$ tries to addresses this \nproblem of over-specification or over-fitting by including the degrees \nof freedom: Adjusted $R^2$ = 1 - (RSS/$n-n_c-2$)/(TSS/$n-1$) \n\\footnote{That is, it is 1 minus the ratio of the square of the \nstandard error of the estimate to the sample variance of the response}. \nThus additional predictors with little explanatory capability will increase \nthe ESS (and reduce the RSS), but they will also have lower RSS degrees of \nfreedom (because of the additional number of fitted coefficients, \n$n_c$'s)\\footnote{i.e., Standard error of the estimate won't \ndecrease}. Thus if the additional predictors have poor predictive \ncapability, these two reductions will cancel each other out. In other \nwords, the Adjusted $R^2$ penalizes the addition of new predictors to \nthe linear model, so you should always have a look at the Adjusted \n$R^2$ as a corrected measure of $R^2$.   \n\n\\section{A new dataset}\n\nIn this Chapter, we will use a new dataset of genome size and life \nhistory in mammals to try out a one-way ANOVA. The dataset is a \ncomposite of data taken from an online database of genome sizes and a \npublished database of mammalian life history:\n\n\\begin{compactdesc}\n\t\\item[Genome size] Average genome sizes for available mammal species \n\tare taken from the online database  \n\t\\href{www.genomesize.com}{www.genomesize.com}.\n\t\\item[Life history] Trait data for these species are taken from: \n\t\\href{http://esapubs.org/archive/ecol/e090/184/metadata.htm}{\n\tJones, K. E. {\\it et al.} (2009) PanTHERIA: a species-level database \n\tof life history, ecology, and geography of extant and recently \n\textinct mammals. Ecology 90, 2648--2648}.\n\\end{compactdesc}\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Download the file {\\tt MammalData.csv} from bitbucket and save \n\tto your {\\tt Data} directory.\n\t\\item Create a new blank script called {\\tt ANOVA\\_Prac.R} and add \n\tsome introductory comments.\n\t\\item Use {\\tt read.csv} to load the data in the data frame \n\t{\\tt mammals} and then {\\tt str} and {\\tt summary} to examine \n\tthe data.\n\\end{compactitem}\n\nThere are nine variables. The first two are the latin binomial and \ntaxonomic order of each species, followed by the species mean genome \nsize (`C value', picograms), adult body mass (g), diet breadth, habitat \nbreadth, litter size and then two factors showing whether the species \nare ground dwelling and their trophic level. For more information, see \nthe link above.\n\nYou will see from the output of {\\tt summary} that there is lots of \nmissing data for the life history traits.\n\n\\section{Exploring the data with boxplots}\n\nWe are interested in finding out whether the mean C value for species \nvaries predictably for different levels of life history traits (a \ntypical one-way ANOVA question). For example: \n\n\\begin{compactitem}\n\\item Do carnivores or herbivores have larger genome sizes?\n\\item Do ground dwelling mammals have larger or smaller genome sizes?\n\\end{compactitem}\n\nBefore we fit any models, we want to plot the data to see if the means \nwithin these groupings look different. We also want to check whether \nthe variance looks similar for each group: {\\it constant normal \nvariance}! A simple way is to look at box and whisker plots, showing \nthe median and range of the data:\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Use {\\tt plot(meanCvalue \\textasciitilde{} TrophicLevel, \n\tdata= mammals)} to generate a boxplot of the differences in genome \n\tsizes between trophic levels.\n\t\\item Looking at the plots, it is clear that there is more spread in \n\tthe data above the median than below. Create a new variable {\\tt \n\tlogCvalue} in the {\\tt mammals} data frame containing logged C \n\tvalues.\n\t\\item Create a boxplot of log C values within trophic groups.\n\t\\item Repeat the two plot commands to look at differences between \n\tground dwelling and other species.\n\\end{compactitem}\n\n\\section{Differences in means with barplots}\n\nBox and whisker plots show the median and spread in the data very \nclearly, but we want to test whether the means are different. This is \n$t$ test territory --- how different are the means given the standard \nerror --- so it is common to use barplots and standard error bars to \nshow these differences.\n\nWe're going to use some R code to construct a barplot by hand. We need \nto calculate the means and standard errors within trophic groups, but \nbefore we can do that, we need a new functions to calculate the \nstandard error of a mean:\n\n\\begin{lstlisting}\n\t\n# get standard error of the mean from a set of values (x)\n\nseMean <- function(x){\n\tx <- na.omit(x) # get rid of missing values\n\n\tse <- sqrt(var(x)/length(x)) # calculate the standard error\n\n\treturn(se) \t# tell the function to return the standard error\n}\n\n\\end{lstlisting}\n\t\nNow we can use the function {\\tt tapply}: it splits a variable up into \ngroups from a factor and calculates statistics on each group using a \nfunction.\n\\begin{lstlisting}\ntrophMeans <- tapply(mammals$logCvalue, mammals$TrophicLevel, FUN = \nmean, na.rm = TRUE)\n\nprint(trophMeans)\n\n Carnivore Herbivore  Omnivore \n     1.085     1.197     1.236 \n\\end{lstlisting}\n\n\\begin{lstlisting}\ntrophSE <- tapply(mammals$logCvalue, mammals$TrophicLevel, FUN = seMean)\n\nprint(trophSE)\n\n Carnivore Herbivore  Omnivore \n   0.03983   0.02206   0.01844 \n\\end{lstlisting}\n\nNow we have to put these values together on the plot:\n\n\\begin{lstlisting}\n# get the upper and lower limits of the error bars\nupperSE <- trophMeans + trophSE\nlowerSE <- trophMeans - trophSE\n\n# get a barplot\n# - this function can report where the middle of the bars are on the x-axis\n# - set the y axis limits to contain the error bars\n\nbarMids <- barplot(trophMeans, ylim=c(0, max(upperSE)), ylab = 'log C value (pg)')\n\n# Now use the function to add error bars\n# - draws arrows between the points (x0,y0) and (x1,y1)\n# - arrow heads at each end (code=3) and at 90 degree angles\n\narrows(barMids, upperSE, barMids, lowerSE, ang=90, code=3)\n\n\\end{lstlisting}\n\n\\begin{center}\n\t\\includegraphics[width=0.7\\textwidth]{TLbarplot.pdf}\n\\end{center} \n\nNow we need to draw all these pieces together into a script and get \nused to using them.\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Copy all the lines of code from this section into your script.\n\t\\item Run it and check you get the graph above.\n\t\\item Use the second two chunks as a model to plot a similar graph \n\tfor {\\tt GroundDwelling}. You should get something like the plot \n\tbelow.\n\\end{compactitem}\n\n\\begin{center}\n\t\\includegraphics[width=0.6\\textwidth]{GDbarplot.pdf}\t\n\\end{center}\n \n\\section{An alternative to barplots}\n\nThat is a lot of work to go through for a plot. Doing it the hard way \nuses some useful tricks, but one strength of R is that there is a huge \nlist of add-on packages that you can use to get new functions that \nother people have written.\n\nWe will use the {\\tt gplots} package to create  plots of group means \nand confidence intervals. Rather than plotting the means $\\pm$ 1 \nstandard error, the option {\\tt p=0.95} uses the standard error and the \nnumber of data points to get 95\\% confidence intervals. The default \n{\\tt connect=TRUE} option adds a line connecting the means, which isn't \nuseful here. \n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Replicate the code below into your script and run it to get the \n\tplots below.\n\\end{compactitem}\n\n\\begin{lstlisting}\n#Load the gplots package\n> library(gplots)\n\n# Get plots of group means and standard errors\n> par(mfrow=c(1,2))\n> plotmeans(logCvalue ~ TrophicLevel, data=mammals, p=0.95, connect=FALSE)\n> plotmeans(logCvalue ~ GroundDwelling, data=mammals, p=0.95, connect=FALSE)\n\\end{lstlisting}\n\n\n\\begin{center}\n\t\\includegraphics[width = \\textwidth]{test.pdf}\t\n\\end{center}\n\n\\section{Analysis of variance}\n\nHopefully, those plots should convince you that there are differences \nin genome size between different trophic groups and between ground \ndwelling and other mammals. We'll now use a linear model to test \nwhether those differences are significant.\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Using your code from Chapter~\\ref{ch:regress} as a guide, \n\tcreate a linear model called {\\tt trophicLM} which models log C value \n\tas a function of trophic group.\n\t\\item Use {\\tt anova} and  {\\tt summary} to look at the analysis of \n\tvariance table and then the coefficients of the model. \n\\end{compactitem}\n\nThe ANOVA table for the model should look like the one below: trophic \nlevel explains highly significant variation in genome size ($F= 7.22, \n\\textrm{df}=2 \\textrm{ and } 300, p =0.0009$). {\\it Note the style of \nreporting the result} - the statistic ($F$), degrees of freedom and $p$ \nvalue are all provided in support. It is common to contract this style \nto this: $F_{2,300}=7.22, p=0.0009$. \n\\begin{lstlisting}\n> anova(trophicLM)\n \n Analysis of Variance Table\n \n Response: logCvalue\n               Df Sum Sq Mean Sq F value  Pr(>F)    \n TrophicLevel   2   0.83   0.413    7.22 0.00087 ***\n Residuals    300  17.18   0.057                    \n ---\n Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\n\\end{lstlisting}\n\nHowever, look at the sum of squares column. Of a total of $17.18+0.83 = \n18.01$ units of sums of squares, only 0.83 are explained by trophic \nlevel: $0.83/18.01 \\approx 0.046$ or 4.6\\%. This ratio is called \n$r^2$, a measure of explanatory power, and shows that, although the \nmodel is very significant, it isn't very explanatory. We  care about \nexplanatory power or effect size, {\\it not} $p$ values.\n  \nThe coefficients table for the model looks like this:\n\n\\begin{lstlisting}\n> summary(trophicLM)\n \n Call:\n lm(formula = logCvalue ~ TrophicLevel, data = mammals)\n \n Residuals:\n     Min      1Q  Median      3Q     Max \n -0.5038 -0.1635 -0.0038  0.1511  0.9313 \n \n Coefficients:\n                       Estimate Std. Error t value Pr(>|t|)    \n (Intercept)             1.0851     0.0335   32.38  < 2e-16 ***\n TrophicLevelHerbivore   0.1119     0.0396    2.83  0.00503 ** \n TrophicLevelOmnivore    0.1513     0.0399    3.80  0.00018 ***\n ---\n Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n \n Residual standard error: 0.239 on 300 degrees of freedom\n   (76 observations deleted due to missingness)\n Multiple R-squared: 0.0459,\tAdjusted R-squared: 0.0396 \n F-statistic: 7.22 on 2 and 300 DF,  p-value: 0.000866 \n \n\\end{lstlisting} \n\nIt shows the following:\n\n\\begin{compactitem}\n\n\t\\item The reference level (or intercept) is for carnivores. Their \n\tmean genome size is significantly different from zero - this is not \n\tan exciting finding!\n\n\t\\item The mean genome size for both herbivores and omnivores are both \n\tsignificantly different from carnivores. Both larger in fact: \n\therbivore mean genome size = $1.085 + 0.112 = 1.197$ and omnivore \n\tmean genome size = $1.085 + 0.151 = 1.236$. These are the same group \n\tmeans we found above.\n\n\t\\item The $r^2$ is shown and is the 4.6\\% we calculated above. The \n\t{\\it adjusted} $r^2$ reduces the raw $r^2$ to account for the number \n\tof variables included in the model. That 4.6\\% would be even less \n\timpressive if we needed 6 explanatory variables to get it\\ldots\n\n\t\\item The $F$ statistic, as in the ANOVA table above.\n\n\\end{compactitem}\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Repeat the analysis of variance above to look at the effects of \n\tground dwelling on genome size.\n\\end{compactitem}\n\n\\section{Model criticism}\n\nThe next question must be  ---  and actually, we should do this before \nwe go anywhere near the model summaries --- is the model appropriate to \nthe data.\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Using Chapter \\ref{ch:regress} to guide you, get the four model \n\tdiagnostic plots for the trophic level model on a single figure.\n\\end{compactitem}\n\nThe four plots are:\n\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{modelDiag.pdf}\t\n\\end{center}\n\nNote that in regression, the predicted (or fitted) values from the \nmodel take a range along the relationship $y=a + bx$ (as we saw in the \nFigures \\ref{fig:DiagModDragon} \\& \\ref{fig:DiagModDamsel}). For ANOVA, \nthere are only a few predicted values --- one for each group mean. This \nmeans that the plots above look different but we are looking for the \nsame things: is there constant variance at each fitted value and are \nthe residuals normally distributed? The answer for this model looks to \nbe yes.\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Check the ground dwelling model in the same way.\n\\end{compactitem}\n \n\\section{Testing pairwise differences between levels}\n\nThe one thing that the trophic level model does not tell us is whether \nthere is a difference in genome size between omnivores and herbivores \n--- both are compared to carnivores, but not to each other. This is \nbecause of the multiple pairwise testing problem mentioned in Chapter \n\\ref{ch:t_F_tests} --- if you do \nlots of tests then you may find small $p$ values by chance and say \nsomething important is going on when it is just random chance. This is \ncalled a false positive or Type I error.\n \nWith a 95\\% confidence interval, there is a 5\\% chance of a false \npositive {\\it per test} but there are ways of getting a 5\\% chance \nacross a set (or family) of tests. For  linear models, we can use \nTukey's Honest Significant Difference test. We have to convert the {\\tt \nlm} object into an {\\tt aov} object first.\n\n\\begin{lstlisting}\n\n> TukeyTroph <- TukeyHSD(aov(trophicLM))\n> print(TukeyTroph)\n\t\n   Tukey multiple comparisons of means\n     95% family-wise confidence level\n \n Fit: aov(formula = trophicLM)\n \n $TrophicLevel\n                        diff      lwr    upr  p adj\n Herbivore-Carnivore 0.11186  0.01863 0.2051 0.0139\n Omnivore-Carnivore  0.15128  0.05741 0.2452 0.0005\n Omnivore-Herbivore  0.03942 -0.03161 0.1104 0.3923\n \n\\end{lstlisting}\n\nThe table shows the following:\n\\begin{compactitem}\n\n\t\\item The differences between the three possible pairs and then the \n\tlower and upper bounds of the 95\\% confidence interval for the \n\tdifference and a $p$ value. \n\n\t\\item In each case, we want to know if the difference could be zero: \n\tdoes the 95\\% confidence interval for each pair include zero.\n\n\t\\item For the first two pairs,  carnivores versus omnivores and \n\therbivores, the confidence intervals do not include zero, so they are \n\tsignificantly different. For the comparison between herbivores and \n\tomnivores, the interval does include zero (difference = 0.039, 95\\% \n\tCI's limits are -0.032 \\& 0.110), so these groups are not \n\tsignificantly different.\n\n\t\\item The $p$ values for the top two pairs are both larger (less \n\tsignificant) than in the summary table. The test has made it harder \n\tto find significant results.\n\n\\end{compactitem}\n\nYou can visualise these confidence intervals by plotting the Tukey \ntest. You have to tweak the graphics parameters to get a clean plot \nthough.\n\n\\begin{lstlisting}\n> par(las=1, mar=c(4,10,3,1))\n# las= 1 turns labels horizontal\n# mar makes the left margin wider (bottom, left, top, right)\n> plot(TukeyTroph)\n\\end{lstlisting} \n\nThe result should be:\n\n{\\centering \\includegraphics[width=0.8\\textwidth]{TukeyPLot.pdf} }\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Run the Tukey test in your script for both the trophic level \n\tand ground dwelling models.\n\\end{compactitem}\n\n\\section{Are the factors independent?}\n\nWe've looked at two models, using trophic level and ground dwelling. It \nis worth asking whether these are independent factors. What if, for \nexample, our herbivores are all big, ground dwellers? This is important \nto know because otherwise, a two-way ANOVA would not be appropriate. We \nwill look at interactions in Chapter \\ref{ch:MulExplInter}.\n\nOK, so we want to know whether the two factors are independent. This is \na job for the $\\chi^2$ test!\n\n\\subsection{The Chi-square test and count data}\n\nThe Chi-square test, also known as $\\chi^{2}$ test or chi-square test, \nis designed for scenarios where you want to statistically test how \nlikely it is that an observed distribution of values is due to chance. \nIt is also called a ``goodness of fit'' statistic, because it measures \nhow well the observed distribution of data fits with the distribution \nthat is expected if the variables of which measurements are made are \nindependent. In our mammals example below, the two variables are \ntrophic level and ground dwelling.\n\nNote that a $\\chi^{2}$ test is designed to analyze categorical data. \nThat is the data have been counted (count data) and divided into \ncategories. It is not meant for continuous data (such as body weight, \ngenome size, or height). For example, if you want to test whether \nattending class influences how students perform on an exam, using test \nscores (from 0-100) as data would not be appropriate for a Chi-square \ntest. However, arranging students into the categories ``Pass'' and \n``Fail'' and counting up how many fall in each categories would be \nappropriate. Additionally, the data in a Chi-square table (see below) \nshould not be in the form of percentages -- only count data are \nallowed! \n\n\\subsubsection{The Chi-square test with the mammals data}\n\nWe can easily build a table for a Chi-square test on the mammals \ndata as follows:\n  \n\\begin{lstlisting}\n> factorTable <- table(mammals$GroundDwelling, mammals$TrophicLevel)\n> print(factorTable) \n\n       Carnivore Herbivore Omnivore\n   No         26        45       64\n   Yes        22        62       40\n\\end{lstlisting}\n\nNow let's run the test:\n\n\\begin{lstlisting}\n> chisq.test(factorTable)\n  \n \tPearson's Chi-squared test\n \n data:  factorTable \n X-squared = 8.12, df = 2, p-value = 0.01725\n\\end{lstlisting}\n\nThe ``{\\tt X-squared}'' value is the $\\chi^{2}$ {\\it test statistic}, akin to the \nt-value of the t-test or W value in the Wilcox test. \n\nThe $\\chi^{2}$ statistic is calculated as the sum of the quantity \n$$ \\frac{(\\mathrm{Observed} - \\mathrm{Expected})^2}{\\mathrm{Expected}} $$\nacross all the cells/categories in the table (so the sum would be over \n6 categories in our current mammals example).\n   \n``Observed'' is the observed proportion of data that fall in a \ncertain category. For example, there are 26 species observed in the \n{\\tt Carnivore}, {\\tt No} category, and 22 in the {\\tt Carnivore}, {\\tt \nYes} category. \n\n``Expected'' is what count would be expected if the values in each \ncategory we truly independent. Each cell has its own expected value, \nwhich is simply calculated as the count one would expect in each \ncategory if the value were generated in proportion to the total number \nseen in that category. So in our example, the expected value for the \n{\\tt Carnivore}, {\\tt No} category would be\n$$26+22 \\mathrm{~(Total~number~of~carnivore~species)} \n\\times \\frac{26+45+64 \\mathrm{~(Total~number~in~the~''No''~category)}}{ \n26+22+45+62+64+40 \\mathrm{~(Total~number~of~species)}}$$  \n$$= 48 \\times \\frac{135}{259} = 25.02$$\n\nThe sum of all six (one for each cell in the table above) such \ncalculations would be the $\\chi^{2}$ value that R gave you through the \n{\\tt chisq.test()} above --- try it!\n\nNow back to the R output from the {\\tt chisq.test()} above. Why df = 2? \nThis is calculated as $DF = (r - 1) * (c - 1)$ where $r$ and $c$ are \nthe number of rows and columns in the $\\chi^{2}$ table, respectively. \nThe same principle you learned before applies here; you lose one degree \nof freedom for each new level of information you need to estimate: \nthere is uncertainity about the information (number of categories) in \nboth rows and columns, so you need to lose one degree of freedom for \neach. \n\nFinally, note that the p-value is significant --- we can conclude that the \nfactors aren't independent. From the table, carnivores can be either \nground dwelling or not, but herbivores tend to be ground dwelling and \nomnivores tend not to be. Ah well... it's OK. We will look at a better \nway to analyze these data using ``interactions'' in Chapter \n\\ref{ch:MulExplInter}.\n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Include and run the $\\chi^2$ test in your script.\n\\end{compactitem}\n\n\\section{Saving data}\n\nThe last thing to do is to save a copy of the mammal data, including \nour new column of log data, for use in later chapters. \n\n\\begin{compactitem}[$\\quad\\star$]\n\t\\item Use this code in your script to create the saved data in you \n\t{\\tt Data} directory :\n\\end{compactitem}\n\n\\begin{lstlisting}\nsave(mammals, file='../Data/mammals.Rdata')\n\\end{lstlisting}\t\n", "meta": {"hexsha": "ad7fea5418b54f83b9aa6b9b6e783f328eca122b", "size": 28824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archived/SilCompBioStat/anova.tex", "max_stars_repo_name": "mathemage/TheMulQuaBio", "max_stars_repo_head_hexsha": "63a0ad6803e2aa1b808bc4517009c18a8c190b4c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-12T13:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-12T13:33:14.000Z", "max_issues_repo_path": "archived/SilCompBioStat/anova.tex", "max_issues_repo_name": "OScott19/TheMulQuaBio", "max_issues_repo_head_hexsha": "197d710f76163469dfc7fa9d2d95ba3a739eccc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "archived/SilCompBioStat/anova.tex", "max_forks_repo_name": "OScott19/TheMulQuaBio", "max_forks_repo_head_hexsha": "197d710f76163469dfc7fa9d2d95ba3a739eccc7", "max_forks_repo_licenses": ["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.1184022825, "max_line_length": 222, "alphanum_fraction": 0.7345267832, "num_tokens": 8013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6356752189937401}}
{"text": "\\section{Graphs}\r\n\\begin{comment}\r\n\tUsing adjacency list:\r\n\t\\code{graphs/graph_template_adjlist.cpp}\r\n\tUsing adjacency matrix:\r\n\t\\code{graphs/graph_template_adjmat.cpp}\r\n\tUsing edge list:\r\n\t\\code{graphs/graph_template_edgelist.cpp}\r\n\\end{comment}\r\n\t\\subsection{Single-Source Shortest Paths}\r\n\t\t\\subsubsection{Dijkstra}\r\n\t\t\t\\code{graphs/shortest_paths/dijkstra.cpp}\r\n\t\t\\subsubsection{Bellman-Ford}\r\n\t\t\t\\code{graphs/shortest_paths/bellman_ford.cpp}\r\n    \\subsubsection{Shortest Path Faster Algorithm}\r\n      \\code{graphs/shortest_paths/spfa.cpp}\r\n\t\\subsection{All-Pairs Shortest Paths}\r\n\t\t\\subsubsection{Floyd-Washall}\r\n\t\t\t\\code{graphs/shortest_paths/floyd_warshall.cpp}\r\n\t\\subsection{Strongly Connected Components}\r\n\t\t\\subsubsection{Kosaraju}\r\n      \\code{graphs/scc/kosaraju.cpp}\r\n    \\subsubsectionRed{Tarjan's Offline Algorithm}\r\n      \\code{graphs/scc/tarjan.cpp}\r\n  \\subsectionRed{Minimum Mean Weight Cycle}\r\n    Run this for each strongly connected component\r\n    \\code{graphs/min_mean_cycle.cpp}\r\n\t\\subsection{Biconnected Components}\r\n\t  \\subsubsection{Bridges and Articulation Points}\r\n      \\code{graphs/bcc/bridges_artics.cpp}\r\n    \\subsubsection{Block Cut Tree}\r\n      \\code{graphs/bcc/block_cut_tree.cpp}\r\n\t\t\\subsubsection{Bridge Tree}\r\n      \\code{graphs/bcc/bridge_tree.cpp}\r\n\t\\subsection{Minimum Spanning Tree}\r\n\t\t\\subsubsection{Kruskal}\r\n      \\code{graphs/mst/kruskal.cpp}\r\n\t\t\\subsubsection{Prim}\r\n      \\code{graphs/mst/prim.cpp}\r\n\t\\subsectionRed{Euler Path/Cycle}\r\n    \\subsubsectionRed{Euler Path/Cycle in a Directed Graph}\r\n      \\code{graphs/euler_path.cpp}\r\n    \\subsubsectionRed{Euler Path/Cycle in an Undirected Graph}\r\n      \\code{graphs/euler_path_undirected.cpp}\r\n\t\\subsectionRed{Bipartite Matching}\r\n\t\t\\subsubsectionRed{Alternating Paths Algorithm}\r\n      \\code{graphs/bipartite_matching/bipartite_matching.cpp}\r\n\t\t\\subsubsectionRed{Hopcroft-Karp Algorithm}\r\n      \\code{graphs/bipartite_matching/hopcroft_karp.cpp}\r\n    \\subsubsectionRed{Minimum Vertex Cover in Bipartite Graphs}\r\n      \\code{graphs/bipartite_matching/bipartite_mvc.cpp}\r\n\t\\subsection{Maximum Flow}\r\n\t\t\\subsubsectionBlack{Edmonds-Karp} $O(VE^2)$\r\n\\begin{comment}\r\n\t\t\t\\code{graphs/max_flow/edmonds_karp.cpp}\r\n\\end{comment}\r\n\t\t\\subsubsection{Dinic}\r\n\t\t\t$O(V^2E)$\r\n\t\t\t\\code{graphs/max_flow/dinic.cpp}\r\n\t\t\\subsubsection{Push-relabel}\r\n\t\t\t$\\omega(VE+V^2\\sqrt{E})$, $O(V^3)$\r\n\t\t\t\\code{graphs/max_flow/push_relabel.cpp}\r\n    \\subsubsection{Gomory-Hu (All-pairs Maximum Flow)}\r\n      $O(V^3E)$, possibly amortized $O(V^2E)$ with a big constant factor.\r\n      \\code{graphs/max_flow/gomory_hu_tree.cpp}\r\n  \\subsection{Minimum Cost Maximum Flow}\r\n    \\code{graphs/max_flow/mcst.cpp}\r\n    \\subsubsection{Hungarian Algorithm}\r\n      \\code{graphs/max_flow/hungarian.cpp}\r\n  \\subsectionRed{Minimum Arborescence}\r\n    Given a weighted directed graph, finds a subset of edges of minimum\r\n    total weight so that there is a unique path from the root $r$ to each\r\n    vertex. Returns a vector of size $n$, where the $i$th element is the\r\n    edge for the $i$th vertex. The answer for the root is undefined!\r\n    \\code{graphs/arborescence.cpp}\r\n  \\subsectionRed{Blossom algorithm}\r\n    Finds a maximum matching in an arbitrary graph in $O(|V|^4)$ time. Be\r\n    vary of loop edges.\r\n    \\code{graphs/blossom.cpp}\r\n  \\subsection{Maximum Density Subgraph}\r\n    Given (weighted) undirected graph $G$. Binary search density. If $g$ is\r\n    current density, construct flow network: $(S, u, m)$, $(u, T,\r\n    m+2g-d_u)$, $(u,v,1)$, where $m$ is a large constant (larger than sum\r\n    of edge weights). Run floating-point max-flow. If minimum cut has empty\r\n    $S$-component, then maximum density is smaller than $g$, otherwise it's\r\n    larger. Distance between valid densities is at least $1/(n(n-1))$. Edge\r\n    case when density is $0$. This also works for weighted graphs by\r\n    replacing $d_u$ by the weighted degree, and doing more iterations (if\r\n    weights are not integers).\r\n  \\subsection{Maximum-Weight Closure}\r\n    Given a vertex-weighted directed graph $G$. Turn the graph into a flow\r\n    network, adding weight $\\infty$ to each edge. Add vertices $S,T$. For\r\n    each vertex $v$ of weight $w$, add edge $(S,v,w)$ if $w\\geq 0$, or edge\r\n    $(v,T,-w)$ if $w<0$. Sum of positive weights minus minimum $S-T$ cut is\r\n    the answer. Vertices reachable from $S$ are in the closure. The\r\n    maximum-weight closure is the same as the complement of the\r\n    minimum-weight closure on the graph with edges reversed.\r\n  \\subsection{Maximum Weighted Ind. Set in a Bipartite Graph}\r\n    This is the same as the minimum weighted vertex cover. Solve this by\r\n    constructing a flow network with edges $(S,u,w(u))$ for $u\\in L$,\r\n    $(v,T,w(v))$ for $v\\in R$ and $(u,v,\\infty)$ for $(u,v)\\in E$. The\r\n    minimum $S,T$-cut is the answer. Vertices adjacent to a cut edge are\r\n    in the vertex cover.\r\n  \\subsection{Synchronizing word problem}\r\n    A DFA has a synchronizing word (an input sequence that moves all states\r\n    to the same state) iff.\\ each pair of states has a synchronizing word.\r\n    That can be checked using reverse DFS over pairs of states. Finding the\r\n    shortest synchronizing word is NP-complete.\r\n  \\subsection{Max flow with lower bounds on edges}\r\n    % TODO: Test this!\r\n    Change edge $(u,v,l\\leq f\\leq c)$ to $(u,v,f\\leq c-l)$. Add edge\r\n    $(t,s,\\infty)$. Create super-nodes $S$, $T$. Let $M(u) = \\sum_{v}\r\n    l(v,u) - \\sum_{v} l(u,v)$. If $M(u)<0$, add edge $(u,T,-M(u))$, else\r\n    add edge $(S,u,M(u))$. Max flow from $S$ to $T$. If all edges from $S$\r\n    are saturated, then we have a feasible flow. Continue running max flow\r\n    from $s$ to $t$ in original graph.\r\n    % TODO: Was there something similar for vertex capacities that we should add?\r\n  \\subsection{Tutte matrix for general matching}\r\n    Create an $n\\times n$ matrix $A$. For each edge $(i,j)$, $i<j$, let\r\n    $A_{ij} = x_{ij}$ and $A_{ji} = -x_{ij}$. All other entries are $0$.\r\n    The determinant of $A$ is zero iff.\\ the graph has a perfect matching.\r\n    A randomized algorithm uses the Schwartz--Zippel lemma to check if it is\r\n    zero.\r\n  \\subsection{Heavy Light Decomposition}\r\n    \\code{graphs/heavy_light_decomposition.cpp}\r\n\t\\subsectionRed{Centroid Decomposition}\r\n    \\code{graphs/centroid_decomposition.cpp}\r\n\t\\subsection{Least Common Ancestor}\r\n\t\t\\subsubsection{Binary Lifting}\r\n      \\code{graphs/lca/binary_lifting.cpp}\r\n    \\subsubsection{Euler Tour Sparse Table}\r\n      \\code{graphs/lca/lca_sparse_table.cpp}\r\n    \\subsubsection{Tarjan Off-line LCA}\r\n      \\code{graphs/lca/tarjan.cpp}\r\n  \\subsection{Counting Spanning Trees}\r\n    Kirchoff's Theorem: The number of spanning trees of any graph is the\r\n    determinant of any cofactor of the Laplacian matrix in $O(n^3)$.\r\n    \\begin{enumerate}\r\n        \\item Let $A$ be the adjacency matrix.\r\n        \\item Let $D$ be the degree matrix (matrix with vertex degrees on the diagonal).\r\n        \\item Get $D-A$ and delete exactly one row and column. Any row and\r\n        column will do. This will be the cofactor matrix.\r\n        \\item Get the determinant of this cofactor matrix using Gauss-Jordan.\r\n        \\item $\\text{Spanning Trees} = \\left|\\mathrm{cofactor}(D-A) \\right|$\r\n    \\end{enumerate}\r\n  \\subsection{Erd\\H{o}s-Gallai Theorem}\r\n    A sequence of non-negative integers $d_1 \\ge \\cdots \\ge d_n$ can be represented as the\r\n    degree sequence of finite simple graph on $n$ vertices if and only if $d_1 + \\cdots + d_n$ is\r\n    even and the following holds for $1 \\le k \\le n$:\r\n    \\[\r\n    \\sum_{i=1}^n d_i \\le k(k-1) + \\sum_{i=k+1}^n \\min\\left(d_i, k\\right)\r\n    \\]\r\n  \\subsection{Tree Isomorphism}\r\n    \\code{graphs/tree_isomorphism.cpp}\r\n", "meta": {"hexsha": "c46407fa113865787f60626e8c5b290f4b39851a", "size": 7697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/graphs.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/graphs.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/graphs.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": 49.6580645161, "max_line_length": 98, "alphanum_fraction": 0.6955956866, "num_tokens": 2203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.635675206974867}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Difference Quotient}\n\n\n\\objective{Explain the various forms of the difference quotient and their meaning.}\n\n\nTo all appearances, limits seem to be about incredibly precise --- more precise\nthan anything in our universe --- or unmeasurably large inputs of functions.\nThis would seem to offer us nothing useful about the world we actually find ourselves\nin.  Such is not the case, however.\n\nIf we want to know about the rate of change of a function, we must typically ask \n``over what interval?''  We might suspect that there is a moment on the graph below\n($x\\approx.25$) where the average rate of change is 0.  How might we prove that?\nWe would have to travel some further amount in the $x$ direction, which would\nproduce some change in the $y$ value, because the rate of change is $\\frac{\\Delta y}\n{\\Delta x}$.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.6]{\\chapdir/pics/dq.png}\n% http://www.texample.net/tikz/examples/difference-quotient/\n\\caption{The difference quotient, as $\\Delta x$ approaches 0\\cite{tikzdq}.}\n\\end{center}\n\\end{figure}\n\nIn single-variable calculus, the difference quotient is usually the name for the expression\n\\begin{equation}\n\\lim_{h\\rightarrow0}\\frac {f(x+h)-f(x)}{(x+h)-x}\n\\end{equation}\n\nWhat does this represent?  We are looking for the rate of change of the function.  We begin\nby inputting $x$ (and, of course, receiving an output of $f(x)$).  We then move over a tiny \namount and measure the change in output, over the change in input.  That tiny amount is called\n$h$, and we take the limit as $h$ goes to 0.\n\nBecause we are evaluating the entire function this way, if we are able to answer the limit, \nwe will receive a new function as out answer.  This function is called the \\textbf{derivative} of\n$f(x)$.\n\n\n\\begin{derivation}{Derivative}\nThe derivative of a function $f(x)$ may be denoted $f'(x)$.  This style of writing is\ncalled \\textbf{Lagrange's notation}, after Joseph-Louis Lagrange\n\\end{derivation}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.9]{\\chapdir/pics/deriv.png}\n\\caption{The difference quotient produces a secant line \\cite{derivativedefinition}.}\n\\end{center}\n\\end{figure}\n\nSometimes it is too difficult or time consuming to find the entire derivative equation.\nWe might want to find the derivative at one location only, typically called $c$\n\n\\begin{equation}\n\\lim_{x\\rightarrow c}\\frac{f(x)-f(c)}{x-c}\n\\end{equation}\n\nThese tend to be much easier to solve, as they are typically removable discontinuities\nof the kind we solved in §2.1\n\n\\subsection{Theorems of Limits}\nLet's us generalize the properties of limits we have seen in action this chapter:\n\\begin{enumerate}\n\\item The limit of a product is the same as a product of limits\n\\item The limit of a sum is the same as a sum of limits\n\\item The limit of a quotient is the same as a quotient of limits (but $\\ne 0$)\n\\item The limit of a constant times a function is the same as a constant times a limit\n\\item the limit of a constant is a constant\n\\end{enumerate}\n", "meta": {"hexsha": "857da9cc6780214c519cabee5fdf0c379b01db10", "size": 3036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/0205.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/0205.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/0205.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": 39.9473684211, "max_line_length": 97, "alphanum_fraction": 0.755599473, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6356752029656676}}
{"text": "\n\\section{Main idea}\n\nConsider a \\emph{Riordan array} $\\mathcal{R}\\left(d(t),h(t)\\right)$ \ndefined over generating functions $d$ and $h$. \nBy definition, coefficients lying on \ncolumn $k$ are the coefficients of the following combination:\n\\begin{displaymath}\n    d(t)h(t)^k\n\\end{displaymath}\nour idea is to characterize $\\mathcal{R}$ doing a variable change, as the\nfollowing manipulation catches:\n\\begin{displaymath}\n    d(t)h(t)^k = d(t)(1 + (h(t)-1))^k = \\left[ \\left. d(\\hat{h}(1+y))(1+y)^k \\right|y = h(t)-1  \\right]\n\\end{displaymath}\nwhere function $\\hat{h}$ is the compositional inverse of $h$, the one that\nsatisfies $\\hat{h}(h(t)) = t$: in order to get $t$ back, apply $\\hat{h}$ to\nboth members of $y+1 = h(t)$.\nInside the square brackets there's a shape of a Riordan array, therefore:\n\\begin{displaymath}\n    \\begin{split}\n        \\mathcal{R}\\left(d(t),h(t)\\right) &= \\left[ \\mathcal{R}\\left(d(\\hat{h}(1+y)), 1+y\\right) \\left| y = h(t)-1 \\right. \\right]\\\\\n        &= \\mathcal{R}_{y=h(t)-1}\\left( f(y), 1+y \\right) =  \\mathcal{R}_{h(t)}\\left( g(h(t)), h(t) \\right) \n    \\end{split}\n\\end{displaymath}\n$\\mathcal{R}_{y=h(t)-1}$ is interesting since its first component $f(y)$ allows to \ndevelop a new array $\\mathcal{R}_{h(t)}$ where it's first component\nis a function $g$ in the ``variable'' $h(t)$, eventually the moral is:\n\\begin{quote}\n    \\graffito{$h$-characterization}\n    \\emph{function composition $d$ with $\\hat{h}$ yields array $\\mathcal{R}_{h(t)}$,\\\\\n        the $h$-characterization of $\\mathcal{R}$, which depends on function $h$ only }\n\\end{quote}\nIt's important to understand the meaning of those new symbols:\n\\begin{itemize}\n    \\item $\\mathcal{R}_{\\gamma=\\Omega(t)}$ denotes an array where a variable\n        substitution has to take place, namely $\\Omega(t)$ is the substitution \n        for variable $\\gamma$;\n        \\marginpar{$\\mathcal{R}_{t}(d(t),h(t))$ denotes verbosly, but correctly, the same\n            array $\\mathcal{R}(d(t),h(t))$ denotes}\n    \\item $\\mathcal{R}_{\\Omega(t)}$ denotes an array where $\\Omega(t)$ should \n        be seen as a variable, like a \\emph{datum}, and should not be expanded,\n        even if $\\Omega$'s definition is known. \n        % the same concept can be expressed as follow:\n            %(a point very important to understand: here $h(t)$ shouldn't be\n            %interpreted as a \\emph{function}, the one in $\\mathcal{R}$'s definition, instead\n            %abstract over it and consider it as a \\emph{variable}).\n        % this has been cut from a paragraph within `Group operations, revisited' section\n\\end{itemize}\n\n\\label{par:h:characterization:is:an:array:polymorphism} Moreover, the\n$h$-characterization $\\mathcal{R}_{h(t)}\\left(g(h(t)),h(t)\\right)$,\n\\marginpar{$\\mathcal{R}_{h(t)}$ is polymorphic} for some function $g$, can be\nused as a classic Riordan array, %\\emph{trasparently}, \nwhere traditional function $d$ satisfies $d(t) = g(h(t))$. \nOn the other hand, function $h$ is interpreted as usual.\n\n\n\\subsection{Applying it to known triangles}\n\nIn the following sections we characterize some well known \narrays under this development.\n\n\\subsubsection{Pascal}\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} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = \\frac{y}{1+y}\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))=2+y$ therefore:\n\\begin{displaymath} \n    \\mathcal{P}_{y=h(t)-1}\\left( 2+y, 1+y \\right)= \\mathcal{P}_{h(t)}\\left( 1+h(t), h(t) \\right)\n\\end{displaymath} \nNow study the generating function which carries coefficients lying on column $k$\nof $\\mathcal{P}_{h(t)}$:\n\\marginpar{this recall the Rogers' work about \\emph{renewal arrays}, \nwhich we described in \\autoref{sec:back:to:the:basics:rogers}} \n\\begin{displaymath} \n    h(t)^k + h(t)^{k+1}\n\\end{displaymath} \nhence column $k$ is the sum of $k$-fold and $(k+1)$-fold convolutions \nof function $h$ with itself.\n\n\\subsubsection{Fibonacci}\nLet $\\mathcal{F}$ be the Riordan array for the Fibonacci triangle,\ndefined as:\n\\begin{displaymath} \n    \\mathcal{F} = \\left(\\frac{1}{1-t-t^2}, \\frac{1-\\sqrt{1-4t}}{2}  \\right)\n\\end{displaymath} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = y - y^2\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))=\\frac{1}{1+y-2y^3-y^4}$ therefore:\n\\begin{displaymath} \n    \\begin{split} \n        & \\mathcal{F}_{y=h(t)-1}\\left( \\frac{1}{1+y-2y^3-y^4}, 1+y \\right) = \\mathcal{F}_{h(t)}\\left( \\frac{1}{1-h(t)+2h(t)^3-h(t)^4}, h(t) \\right)\\\\\n    \\end{split} \n\\end{displaymath} \nNow study the generating function which carries coefficients lying on column $k$\nof $\\mathcal{F}_{h(t)}$:\n\\begin{displaymath} \n    \\frac{h(t)^k}{1-h(t)+2h(t)^3-h(t)^4}\n\\end{displaymath} \n\n\\subsubsection{Catalan}\nLet $\\mathcal{C}$ be the Riordan array for the Catalan triangle,\ndefined as:\n\\begin{displaymath} \n    \\mathcal{C} = \\left(\\frac{1-\\sqrt{1-4t}}{2t}, \\frac{1-\\sqrt{1-4t}}{2}  \\right)\n\\end{displaymath} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = y - y^2\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))=\\frac{\\sqrt{4 \\, y^{2} + 4 \\, y + 1} - 1}{2 \\, {\\left(y + 1\\right)} y}$ therefore:\n\\marginpar{$h_{\\mathcal{F}}=h_{\\mathcal{C}}$, here function $d$ makes the difference}\n\\begin{displaymath} \n    \\begin{split} \n        &\\mathcal{C}_{y=h(t)-1}\\left(\\frac{\\sqrt{4 \\, y^{2} + 4 \\, y + 1} - 1}{2 \\, {\\left(y + 1\\right)} y}, 1+y \\right) \\\\\n        &= \\mathcal{C}_{h(t)}\\left(\\frac{\\sqrt{4 \\, h\\left(t\\right)^{2} - 4 \\, h\\left(t\\right) + 1} - 1}{2 \\, {\\left(h\\left(t\\right) - 1\\right)} h\\left(t\\right)}, h(t) \\right)\\\\\n        &= \\mathcal{C}_{h(t)}\\left(\\frac{\\sqrt{(2 h\\left(t\\right) -  1)^2} - 1}{2 \\, {\\left(h\\left(t\\right) - 1\\right)} h\\left(t\\right)}, h(t) \\right)\\\\\n    \\end{split} \n\\end{displaymath} \nBy cases on $\\sqrt{(2 h\\left(t\\right) -  1)^2}$:\n\\marginpar{$\\sqrt{x^{2}}=\\pm x$ trick}\n\\begin{itemize}\n    \\item $\\sqrt{(2 h\\left(t\\right) -  1)^2}=2 h\\left(t\\right) -  1$, hence:\n        \\begin{displaymath} \n            \\mathcal{C}_{h(t)}\\left(\\frac{2(h\\left(t\\right) -  1)}{2 \\, {\\left(h\\left(t\\right) - 1\\right)} h\\left(t\\right)}, h(t) \\right)=\n            \\mathcal{C}_{h(t)}\\left(\\frac{1}{h\\left(t\\right)}, h(t) \\right)\n        \\end{displaymath} \n        since $h(0)=0$ the previous result has no meaning, therefore discard this case;\n    \\item $\\sqrt{(2 h\\left(t\\right) -  1)^2}=1 -2 h\\left(t\\right)$, hence:\n        \\begin{displaymath} \n            \\mathcal{C}_{h(t)}\\left(\\frac{h\\left(t\\right)}{ {\\left(1-h\\left(t\\right) \\right)} h\\left(t\\right)}, h(t) \\right)=\n            \\mathcal{C}_{h(t)}\\left(\\frac{1}{1-h\\left(t\\right)}, h(t) \\right)\n        \\end{displaymath} \n        checking against $h(0)=0$ the previous result has meaning, therefore accept this case.\n\\end{itemize}\nNow study the generating function which carries coefficients lying on column $k$\nof $\\mathcal{C}_{h(t)}$:\n\\begin{displaymath} \n    \\frac{h(t)^{k}}{1-h\\left(t\\right)} \n\\end{displaymath} \n\n\n\\subsubsection{Motzkin, classic version}\n\nLet $\\mathcal{M}$ be the Riordan array for the Motzkin triangle, defined as:\n\\begin{displaymath} \n    \\mathcal{M} =\\left( \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t^2}, \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t}  \\right)\n\\end{displaymath} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = \\frac{y}{1+y+y^2}\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))$ equals:\n\\begin{lenghtydisplaymath} \n    \\begin{split} \n        & -\\frac{{\\left(y^{2} \\sqrt{\\frac{{\\left(y^{2} + 4 \\, y + 4\\right)} y^{2}}{{\\left(y^{2} + 3 \\, y + 3\\right)}^{2}}} - y^{2} + 3 \\, y \\sqrt{\\frac{{\\left(y^{2} + 4 \\, y + 4\\right)} y^{2}}{{\\left(y^{2} + 3 \\, y + 3\\right)}^{2}}} - 2 \\, y + 3 \\, \\sqrt{\\frac{{\\left(y^{2} + 4 \\, y + 4\\right)} y^{2}}{{\\left(y^{2} + 3 \\, y + 3\\right)}^{2}}} - 2\\right)} {\\left(y^{2} + 3 \\, y + 3\\right)}}{2 \\, {\\left(y + 1\\right)}^{2}} \\\\\n        & = -\\frac{{ \\left(\\sqrt{\\frac{{\\left(y^{2} + 4 \\, y + 4\\right)} y^{2}}{{\\left(y^{2} + 3 \\, y + 3\\right)}^{2}}} \\left( y^{2}+3y+3 \\right) -\\left(y^{2}+2y+2\\right)\\right){\\left(y^{2} + 3 \\, y + 3\\right)}}}{2 \\, {\\left(y + 1\\right)}^{2}} \\\\\n        & = -\\frac{ \\left(\\sqrt{\\left(y^{2} + 4 y + 4\\right) y^{2}} -\\left(y^{2}+2y+2\\right)\\right)\\left(y^{2} + 3y + 3\\right)}{2 {\\left(y + 1\\right)}^{2}} \\\\\n    \\end{split} \n\\end{lenghtydisplaymath} \nRecognize a perfect square $y^{2} + 4 y + 4 = (y+2)^{2}$:\n\\marginpar{we could also stop here and reason by cases about $\\pm\\left(\\left(y + 2\\right) y\\right)$\n    without going on substituting variable $y$ too soon\\ldots}\n\\begin{lenghtydisplaymath} \n        -\\frac{ \\left(\\sqrt{\\left(\\left(y + 2\\right) y\\right)^{2}} -\\left(y^{2}+2y+2\\right)\\right)\\left(y^{2} + 3y + 3\\right)}{2 {\\left(y + 1\\right)}^{2}} \n\\end{lenghtydisplaymath} \ntherefore:\n\\begin{lenghtydisplaymath} \n    \\begin{split} \n        &\\mathcal{M}_{y=h(t)-1}\\left(\n            -\\frac{ \\left(\\sqrt{\\left(\\left(y + 2\\right) y\\right)^{2}} -\\left(y^{2}+2y+2\\right)\\right)\\left(y^{2} + 3y + 3\\right)}{2 {\\left(y + 1\\right)}^{2}} , 1+y \\right) \\\\\n        &= \\mathcal{M}_{h(t)}\\left(\n        -\\frac{{\\left(\\sqrt{\\frac{{\\left(h(t)^{2} + 2 \\, h(t) + 1\\right)} {\\left(h(t) - 1\\right)}^{2}}{{\\left(h(t)^{2} + h(t) + 1\\right)}^{2}}}\\left( h(t)^{2} + h(t) + 1\\right) \n            - (h(t)^{2} + 1) \\right)} {\\left(h(t)^{2} + h(t) + 1\\right)}}{2 \\, h(t)^{2}} , h(t) \\right)\\\\\n        &= \\mathcal{M}_{h(t)}\\left(\n        -\\frac{{\\left(\\sqrt{\\left(h(t)^2 - 1\\right)^{2}} - (h(t)^{2} + 1) \\right)} {\\left(h(t)^{2} + h(t) + 1\\right)}}{2 \\, h(t)^{2}} , h(t) \\right)\\\\\n    \\end{split} \n\\end{lenghtydisplaymath} \nBy cases on $\\sqrt{\\left(h(t)^2 - 1\\right)^{2}}$:\n\\begin{itemize}\n    \\item $\\sqrt{\\left(h(t)^2 - 1\\right)^{2}}= h(t)^2 - 1$, hence:\n        \\begin{displaymath} \n            \\mathcal{M}_{h(t)}\\left(\\frac{ h(t)^{2} + h(t) + 1}{h(t)^{2}} , h(t) \\right)\\\\\n        \\end{displaymath} \n        since $h(0)=0$ the previous result has no meaning, therefore discard this case;\n    \\item $\\sqrt{\\left(h(t)^2 - 1\\right)^{2}}= 1-h(t)^2$, hence:\n        \\begin{displaymath} \n            \\mathcal{M}_{h(t)}\\left( h(t)^{2} + h(t) + 1, h(t) \\right)\\\\\n        \\end{displaymath} \n        checking against $h(0)=0$ the previous result has meaning, therefore accept this case.\n\\end{itemize}\n\nIt is interesting to note that the tedious derivation developed above can have\na simpler handling if we defer substituting $h(t)-1$ for $y$, consider the following \\ldots\nby cases on $\\sqrt{\\left(\\left(y + 2\\right) y\\right)^{2}}$:\n\\begin{itemize}\n    \\item $\\sqrt{\\left(\\left(y + 2\\right) y\\right)^{2}}=\\left(y + 2\\right) y$, hence:\n        \\begin{displaymath} \n            \\mathcal{M}_{y=h(t)-1}\\left(\\frac{y^{2} + 3y + 3}{{\\left(y + 1\\right)}^{2}} , 1+y \\right) = \n                \\mathcal{M}_{h(t)}\\left( \\frac{1+h(t)+h(t)^2}{h(t)^2}, h(t) \\right) \n        \\end{displaymath} \n        since $h(0)=0$ the previous result has no meaning, therefore discard this case;\n    \\item $\\sqrt{\\left(\\left(y + 2\\right) y\\right)^{2}}=-\\left(y + 2\\right) y$, hence:\n        \\begin{displaymath} \n            \\mathcal{M}_{y=h(t)-1}\\left(y^{2} + 3y + 3 , h(t) \\right) = \n                \\mathcal{M}_{h(t)}\\left( 1+h(t)+h(t)^2, h(t) \\right) \n        \\end{displaymath} \n        checking against $h(0)=0$ the previous result has meaning, therefore accept this case.\n\\end{itemize}\n\nIn both branches same definitions for $\\mathcal{M}_{h(t)}$ are reached applying\nsame checks, while at the same time substituting variable $y$ is easier. \n\\\\\\\\\nHowever, here it is the generating function which carries coefficients \nlying on column $k$ of $\\mathcal{M}_{h(t)}$:\n\\begin{displaymath} \n    h(t)^{k}+h(t)^{k+1}+h(t)^{k+2}\n\\end{displaymath} \n\n\n\\subsubsection{Motzkin, $\\mathcal{T}$ variant}\n\nLet $\\mathcal{T}$ be the Riordan array for a variant\nof the Motzkin array defined as:\n\\begin{displaymath} \n    \\mathcal{T} = \\left(\\frac{1}{\\sqrt{1-2t-3t^2}}, \n       \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t}  \\right)\n\\end{displaymath} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = \\frac{y}{1+y+y^2}\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))=\\sqrt{\\left(\\frac{y^2+3y+3}{(y+2)y}\\right)^{2}}$ therefore:\n\\begin{displaymath} \n    \\mathcal{T}_{y=h(t)-1}\\left( \\sqrt{\\left(\\frac{y^2+3y+3}{(y+2)y}\\right)^{2}}, 1+y \\right) = \n        \\mathcal{T}_{h(t)}\\left( \\sqrt{\\left(\\frac{h(t)^2+h(t)+1}{h(t)^2-1}\\right)^{2}}, h(t) \\right) \n\\end{displaymath} \nBy cases on $\\sqrt{\\left(\\frac{h(t)^2+h(t)+1}{h(t)^2-1}\\right)^{2}}$:\n\\begin{itemize}\n    \\item $\\sqrt{\\left(\\frac{h(t)^2+h(t)+1}{h(t)^2-1}\\right)^{2}}=\\frac{h(t)^2+h(t)+1}{h(t)^2-1}$, hence:\n        \\begin{displaymath} \n            \\mathcal{T}_{h(t)}\\left(\\frac{h(t)^2+h(t)+1}{h(t)^2-1}, h(t) \\right)\n        \\end{displaymath} \n        requirement $h(0)=0$ doesn't raise a non-sense, so use the \n        constraint $d(0)=1$, mandatory in order to have a \\emph{proper} array, although\n        condition can be relaxed to $d(0)\\neq0$:\n        \\begin{displaymath}\n            \\left. \\frac{h(t)^2+h(t)+1}{h(t)^2-1} \\right|_{t=0} = -1 \\not= 1 \n        \\end{displaymath} \n        so discard this case;\n    \\item $\\sqrt{\\left(\\frac{h(t)^2+h(t)+1}{h(t)^2-1}\\right)^{2}}=\\frac{h(t)^2+h(t)+1}{1-h(t)^2}$, hence:\n        \\begin{displaymath}\n            \\mathcal{T}_{h(t)}\\left(\\frac{h(t)^2+h(t)+1}{1-h(t)^2}, h(t) \\right)\n        \\end{displaymath} \n        requirement $h(0)=0$ doesn't raise a non-sense, so check $d(0)=1$ again:\n        \\begin{displaymath}\n            \\left. \\frac{h(t)^2+h(t)+1}{1-h(t)^2} \\right|_{t=0} = 1 \n        \\end{displaymath} \n        which fulfill the constraint, so accept this case.\n\\end{itemize}\nNow study the generating function which carries coefficients lying on column $k$\nof $\\mathcal{T}_{h(t)}$:\n\\marginpar{same numerator as in classic $\\mathcal{M}$ array, what's\n    the relation among function $d$ and multiplier $\\frac{1}{1-h(t)^{2}}$?}\n\\begin{displaymath} \n    \\frac{h(t)^{k}+h(t)^{k+1}+h(t)^{k+2}}{1-h(t)^2 }\n\\end{displaymath} \n\n\n\\subsubsection{Delannoy}\n\nLet $\\mathcal{D}$ be the Riordan array for the Delannoy triangle, defined as:\n\\begin{displaymath} \n    \\mathcal{D} =\\left( \\frac{1}{1-t}, \\frac{t(1+t)}{1-t}  \\right)\n\\end{displaymath} \ncomputing the compositional inverse of $h$ yields:\n\\begin{displaymath} \n    \\hat{h}(y) = \\frac{\\sqrt{1+6y+y^2}-y-1}{2}\n\\end{displaymath} \nso $f(y)=d(\\hat{h}(1+y))=\\frac{2}{4 + y - \\sqrt{y^2 + 8y + 8} }$ therefore:\n\\begin{displaymath} \n    \\begin{split}\n        & \\mathcal{D}_{y=h(t)-1}\\left( \\frac{2}{4+y-\\sqrt{y^2+8y+8}}, 1+y \\right)\\\\\n        &= \\mathcal{D}_{h(t)}\\left( \\frac{2}{3+h(t)-\\sqrt{h(t)^2+6h(t)+1}}, h(t) \\right) \\\\\n    \\end{split}\n\\end{displaymath} \nSince $h(t)^2+6h(t)+1$ isn't a perfect square, no problem arises with the previous\nderivation; now study the generating function which carries coefficients lying on column $k$\nof $\\mathcal{D}_{h(t)}$:\n\\begin{displaymath} \n    \\frac{2\\,h(t)^k}{3+h(t)-\\sqrt{h(t)^2+6h(t)+1}}\n\\end{displaymath} \n\n\\subsection{Points of view}\n\nLet $\\mathcal{R}\\left(d(t),h(t)\\right)$ be a Riordan array and $\\mathcal{R}_{h(t)}$ be\nits $h$-characterization.\n\nThe first point of view we would like to introduce is to see \n$\\mathcal{R}_{h(t)}$ as a \\emph{factorization} \\marginpar{$\\mathcal{R}_{h(t)}$ factorizes $\\mathcal{R}$}\nof $\\mathcal{R}$ in terms of $h(t)$. Namely, the structure of the characterization\ndepends both on functions $d$ and $\\hat{h}$, but the building block is function $h$\nalone. Moreover, second component of $\\mathcal{R}_{h(t)}$ is \\emph{always} function $h$ itself,\ntherefore $k$-fold convolution of function $h$ with itself in the generic\n$k$ column expansion is common both to $\\mathcal{R}$ both to $\\mathcal{R}_{h(t)}$.\n\nThe second point of view is to see $\\mathcal{R}_{h(t)}$ as a \\emph{schema} array \n\\marginpar{$\\mathcal{R}_{h(t)}$ is a schema}.\nTo understand this concept, abstract over $h(t)$ and think about it as a ``plugin'', \na ``context'' that can be filled with any function $g(t)$ you like, to get a new array\n$\\mathcal{R}^{\\stackrel{g(t)}{\\rightarrow}}$ (this notation is just a reminder that the array is obtained\nby plugging in $g(t)$ into the schema $\\mathcal{R}_{h(t)}$). It's pretty easy, and sound, to check:\n\\marginpar{plugging in $h(t)$ itself within schema $\\mathcal{R}_{h(t)}$ safely gets back\n    to the original array $\\mathcal{R}$}\n\\begin{displaymath}\n    \\mathcal{R}^{\\stackrel{h(t)}{\\rightarrow}} = \\mathcal{R}_{y=h(t)-1}\\left( d(\\hat{h}(1+y)), 1+y \\right) = \\mathcal{R}\n\\end{displaymath}\nwhile considering an arbitrary function $g(t)$:\n\\begin{displaymath}\n    \\mathcal{R}^{\\stackrel{g(t)}{\\rightarrow}} = \\mathcal{R}_{y=g(t)-1}\\left( d(\\hat{h}(1+y)), 1+y \\right) = \n    \\left( d(\\hat{h}(g(t))), g(t) \\right) \n\\end{displaymath}\nobserve how the first component of $\\mathcal{R}^{\\stackrel{g(t)}{\\rightarrow}}$ depends on\n$\\mathcal{R}$ by composition of functions $d$ and $\\hat{h}$. So, every array seems to have\na ``nested schema'' that allows to build new arrays.\n\\\\\\\\\nWe finish with a theorem about arrays in the \\emph{renewal} subgroup.\n\n\\begin{theorem}\n    Let $\\mathcal{R}\\left(d(t), h(t)\\right)$ be a Riordan array belonging\n    to the \\emph{renewal} subgroup, so $h(t)=td(t)$. Then:\n    \\marginpar{it can be written as $\\left[\\left.\\mathcal{R}\\left(A(y), y)\\right)\\right|y=h(t)\\right]$\n        or as $\\mathcal{R}_{y=h(t)}\\left(A(y), y)\\right)$ too}\n    \\begin{displaymath}\n        \\mathcal{R}_{h(t)}\\left(A(h(t)), h(t))\\right)\n    \\end{displaymath}\n    where $A$ is a \\ac{fps} over $\\mathcal{R}$'s $A$-sequence \n    $\\lbrace a_i \\rbrace_{i\\in\\mathbb{N}}$. \n\\end{theorem}\n\n\\begin{proof}\n    Recall that $A$-sequence of a Riordan array $\\mathcal{R}\\left(d(t), h(t)\\right)$\n    satisfies:\n    \\begin{displaymath}\n        h(t)=tA(h(t))\n    \\end{displaymath}\n    By hypothesis, assume $\\mathcal{R}$ belongs to the \\emph{renewal} subgroup, therefore\n    \\begin{displaymath}\n        \\mathcal{R}\\left(A(h(t)), h(t)\\right)\n    \\end{displaymath}\n    Let $\\mathcal{R}_{h(t)}\\left(g(h(t)), h(t)\\right)$ be the $h$-characterization of $\\mathcal{R}$,\n    for some function $g$. Now plug $h(t)$ into $\\mathcal{R}_{h(t)}$:\n    \\begin{displaymath}\n        \\mathcal{R}^{\\stackrel{h(t)}{\\rightarrow}} =\n            \\mathcal{R}\\left(g(h(t)), h(t)\\right)\n    \\end{displaymath}\n    But $\\mathcal{R}^{\\stackrel{h(t)}{\\rightarrow}} = \\mathcal{R}$, therefore \n    $[g(y)=A(y)|y=h(t)]$ follows, as required.\n\n\\end{proof}\n\n%\\marginpar{$\\mathcal{R}_{h(t)}\\left(A(h(t)), h(t))\\right)\\rightarrow\n    %\\mathcal{R}\\left(d(t), t\\,d(t)\\right)$ holds too}\n\\marginpar{the converse is true indeed, by $A$-sequence uniqueness}\nLooking at it deeply, it is possible to have a stronger formulation, namely the \nconverse holds indeed: the reason for this is the unique existence of an $A$-sequence\nfor each Riordan array, the argument follows using $h(t)=tA(h(t))$ again .\n\\\\\\\\\nThis little theorem shows a possible application of the factorization point of view.\nConsider the Motzkin array defined as:\n\\begin{displaymath} \n    \\mathcal{M} =\\left( \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t^2},\n       \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t}  \\right)\n\\end{displaymath} \nSurely $\\mathcal{M}$ is a renewal array and, being in the Riordan group, \nhas an $A$-sequence, which satisfies $A(t)=1+t+t^2$: \nthis information \\emph{can't} be read from the above definition.\n\\\\\\\\\n\\marginpar{finding $\\mathcal{M}$'s $A$-sequence}\nLet $h(t)=\\frac{1-t-\\sqrt{1-2t-3t^2}}{2t}$ be the second\ncomponent of Motzkin array $\\mathcal{M}$, which factor as follows:\n\\begin{displaymath} \n    \\mathcal{M}_{h(t)}\\left( 1+h(t)+h(t)^2, h(t) \\right) \n\\end{displaymath} \nusing this $h$-characterization, $A$-sequence $[A(y)=1+y+y^2|y=h(t)]$ can\nbe read from $\\mathcal{M}_{h(t)}$'s first component directly, without\nsolving the equation as usual:\n\\begin{displaymath} \n    \\frac{1-t-\\sqrt{1-2t-3t^2}}{2t} = t\\,A\\left(\\frac{1-t-\\sqrt{1-2t-3t^2}}{2t}\\right)\n\\end{displaymath} \n\n", "meta": {"hexsha": "17ca2bc9009d8b1f87ca60a9e2d04eb628222a72", "size": 19924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classicthesis/Chapters/h-characterization/main-idea.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/h-characterization/main-idea.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/h-characterization/main-idea.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.6857855362, "max_line_length": 422, "alphanum_fraction": 0.6125276049, "num_tokens": 7347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6355111023320651}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Null hypothesis siginficance testing}\\label{sec:nhst}\n\nLet $X$ be a random variable, let $\\mathcal{M}=\\{F(x;\\theta):\\theta\\in\\Theta\\}$ be a statistical model for its distribution and let $\\{\\Theta_0, \\Theta_1\\}$ be a \\emph{partition} of the parameter space:\n\\[\n\\Theta_0\\cup\\Theta_1 = \\Theta \\qquad\\text{and}\\qquad \\Theta_0\\cap\\Theta_1 = \\emptyset.\n\\]\nThis partition defines two possible statistical models for the distribution of $X$.\n\\[\n\\begin{array}{ll}\n\\text{The \\emph{null} model:}\t\t\t&\\quad\\mathcal{M}_0\t =\\{F(x,\\theta):\\theta\\in\\Theta_0\\}.\t\\\\\n\\text{The \\emph{alternative} model:}\t&\\quad\\mathcal{M}_1\t =\\{F(x,\\theta):\\theta\\in\\Theta_1\\}.\n\\end{array}\n\\]\nTo decide which model is the `correct' one, we need to test the claim that the true parameter belongs to the set $\\Theta_0$ against the alternative claim that it belongs to $\\Theta_1$. We denote these two hypotheses by $H_0$ and $H_1$ respectively and refer to them as follows.\n\n\\begin{center}\n\\begin{tabular}{ll} \\hline\nThe \\emph{null} hypothesis:\t\t& \\quad $H_0: \\theta\\in\\Theta_0$. \\\\\nThe \\emph{alternative} hypothesis:\t& \\quad $H_1: \\theta\\in\\Theta_1$. \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{definition}\n\\bit\n\\it A hypothesis which specifies a particular value of $\\theta$ is called a \\emph{simple hypothesis}.\n\\it A hypothesis which specifies a set of values for $\\theta$ is called a \\emph{composite hypothesis}.\n\\eit\n\\end{definition}\n\nFor example, $H_0:\\theta = \\theta_0$ is a simple hypothesis while $H_1:\\theta\\neq\\theta_0$ is a composite hypothesis.\n\n%-----------------------------\n\\subsection{Type I and Type II errors}\n\nIn the absence of any evidence to the contrary, we assume that $H_0$ is correct. Suppose we now obtain a random sample $\\mathbf{x}=(x_1,x_2,\\ldots,x_n)$ from the distribution of $X$, and compute an estimate $T(\\mathbf{x})$ of the true parameter value $\\theta$. We decide which hypothesis is correct based on the computed value of $T(\\mathbf{x})$:\n\\bit\n\\it if $T(\\mathbf{x})\\in\\Theta_0$ we retain the null hypothesis $H_0:\\theta\\in\\Theta_0$;\n\\it if $T(\\mathbf{x})\\in\\Theta_1$ we reject $H_0$ in favour of the alternative hypothesis $H_1:\\theta\\in\\Theta_1$.\n\\eit\n\n\\begin{definition}\n\\bit\n\\it A \\emph{Type I error} occurs when $\\theta\\in\\Theta_0$ but $T(\\mathbf{x})\\in\\Theta_1$, which leads us to incorrectly reject $H_0$. \n\\it A \\emph{Type II error} occurs when $\\theta\\in\\Theta_1$ but $T(\\mathbf{x})\\in\\Theta_0$, which leads us to incorrectly retain $H_0$.\n\\eit\n\\end{definition}\n\n% decision tables\nHypothesis tests can be respresented by \\emph{decision tables}:\n\\begin{center}\n\\begin{tabular}{|c|c|c|} \\hline\n\t\t\t\t\t\t\t\t\t\t\t& \\multicolumn{2}{c|}{Reality} \\\\ \nDecision\t\t\t\t\t\t\t\t\t& $H_0$ true ($\\theta\\in\\Theta_0$)\t& $H_0$ false ($\\theta\\in\\Theta_1$) \\\\ \\hline\nRetain $H_0$ ($T\\in\\Theta_0$)\t& Correct decision \t\t\t\t\t& Type II error \\\\ \nReject $H_0$ ($T\\in\\Theta_1$)\t& Type I error \t\t\t\t\t\t& Correct decision \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n%\\begin{center}\n%\\begin{tabular}{|c|c|c|} \\hline\n%\t\t\t\t\t\t\t& \\multicolumn{2}{c|}{Reality} \\\\ \n%Decision\t\t\t\t\t& $\\theta\\in\\Theta_0$\t\t& $\\theta\\in\\Theta_1$ \\\\ \\hline\n%$T\\in\\Theta_0$\t& Correct decision \t& Type II error \\\\ \n%$T\\in\\Theta_1$\t& Type I error \t\t& Correct decision \\\\ \\hline\n%\\end{tabular}\n%\\end{center}\n%\n% example\nDifferent applications use different terminology. A decision table for a radar system, where the null hypothesis asserts the absence of a target, might be as follows:\n%Here is decision table for a radar systems, where the null hypothesis asserts the absence of a target:\n\\begin{center}\n\\begin{tabular}{|c|c|c||c|} \\hline\n\t\t\t\t& \\multicolumn{2}{c||}{Reality} & \\\\\nDecision\t\t& \tTarget Absent\t& Target Present \t& Action\\\\  \\hline\nTarget Absent\t&\tClear\t\t\t& Miss \t\t\t\t& Stay silent \\\\\nTarget Present\t&\tFalse alarm \t& Hit \t\t\t\t& Sound alarm \\\\  \\hline\n\\end{tabular}\n\\end{center}\nHere is a decision table for a medical diagnosis, where the null hypothesis asserts the absence of a disease:\n\\begin{center}\n\\begin{tabular}{|c|c|c||c|} \\hline\n\t\t\t\t& \\multicolumn{2}{c||}{Reality} &  \\\\\nDecision\t\t& Disease Absent\t& Disease Present\t& Action \\\\  \\hline\nDisease Absent\t& True negative\t\t& False negative\t& Do nothing  \\\\\nDisease Present\t& False positive \t& True positive \t& Prescribe \\\\  \\hline\n\\end{tabular}\n\\end{center}\n\n\n%-----------------------------\n\\subsection{Critical regions}\n\n\\begin{definition}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample from the distribution of $X$. \nThe set of all possible realisations of $\\mathbf{X}$ is called the \\emph{sample space} which we denote by $D\\subseteq\\R^n$.\n\\end{definition}\n\n\\begin{center}\n%\\begin{table*}[ht]\n%\\centering\n\\begin{tabular}{lcl}\\hline\nModel ($\\mathcal{M}$)\t& & Sample space ($D$) \\\\ \\hline\nBernoulli\t\t\t\t& & binary vectors (of length $n$)\\\\\nPoisson\t\t\t\t\t& & vectors of non-negative integers \\\\\nNormal\t\t\t\t\t& & vectors of real numbers \\\\ \\hline\n\\end{tabular}\n%\\caption*{Examples of sample spaces}\n%\\end{table*}\n\\end{center}\n\n%\\bigskip\n%It can be shown that for every $\\theta\\in\\Theta$, there exits a unique probability measure \n%\\[\\begin{array}{rccl}\n%\\prob_{\\theta}:\t& \\mathcal{B}_n\t& \\to \t\t& [0,1] \\\\\n%\t\t\t\t& A\t\t\t\t& \\mapsto\t& \\prob(\\mathbf{X}\\in A)\n%\\end{array}\\]\n%(where $\\mathcal{B}_n$ is the Borel $\\sigma$-field over $\\R^n$) for which the component variables $X_i$ are independent and identically distribted according to $F(x;\\theta)$. This is called the \\emph{probability measure induced by $\\mathbf{X}$} on the sample space.\n%\n% defn: critical region\n\\begin{definition}\nA \\emph{hypothesis test} of a null hypothesis $H_0$ against an alternative hypothesis $H_1$ is defined by a subset of the sample space called the \\emph{critical region} of the test: we \\emph{reject} $H_0$ if $\\mathbf{X}\\in C$ but \\emph{retain} $H_0$ if $\\mathbf{X}\\notin C$.\n\\end{definition}\n\nCritical regions can be specified in terms of a \\emph{test statistic} say $T:D\\to\\R$, in which case the critical region is specified by one or more \\emph{critical values}. For example, we might define\n\\[\nC = \\{\\mathbf{x}\\in D : c_1\\leq T(\\mathbf{x})\\leq c_2\\}\n\\]\nin which case we reject $H_0$ if $T(\\mathbf{x})$ falls between the critial values $c_1$ and $c_2$.\n\n%% simple example\n%\\begin{example}\n%Let $X_1,X_2,\\ldots,X_n$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution, where $\\mu$ is unknown but $\\sigma^2$ is known. Using the sample mean as a test statistic, define a suitable critical region for testing the null hypothesis $H_0:\\mu=\\mu_0$ against the alternative hypothesis $H_1:\\mu\\neq\\mu_0$.\n%\\begin{solution}\n%If we assume that $H_0$ is true, then $X_i\\sim N(\\mu_0,\\sigma^2)$ and\n%\\[\n%\\frac{1}{n}\\sum_{i=1}^n X_i \\sim N\\left(\\mu_0, \\frac{\\sigma^2}{n}\\right).\n%\\]\n%For a particular realisation $\\boldx=(x_1,x_2,\\ldots,x_n)$ of the sample, if\n%\\bit\n%\\it $\\displaystyle\\frac{1}{n}\\sum_{i=1}^n x_i\\approx\\mu_0$, we might decide to retain the null hypothesis $H_0:\\mu=\\mu_0$, but if\n%\\it $\\displaystyle\\frac{1}{n}\\sum_{i=1}^n x_i\\not\\approx\\mu_0$, we might decide to reject $H_0$ in favour of the alternative $H_1:\\mu\\neq\\mu_0$.\n%\\eit\n%Thus we define the critical region\n%\\[\n%C = \\left\\{\\boldx\\in D: \\left|\\frac{1}{n}\\sum_{i=1}^n x_i - \\mu_0\\right| > c\\right\\},\n%\\]\n%where the critical value $c$ is chosen appropriately. \n%\\end{solution}\n%\\end{example}\n\n%-----------------------------\n\\subsection{The size (or significance level) of a test}\n\nWe would like to choose a critical region $C$ that minimises the probability of making both Type I and Type II errors. These are conflicting objectives, as illustrated by the following extreme cases.\n\\bit\n\\it If we choose $C=\\emptyset$ we will never reject $H_0$ (because the random sample never falls into $C$), so we never make Type I errors when $\\theta\\in\\Theta_0$ but always make Type II errors when $\\theta\\in\\Theta_1$.\n\\it If we choose $C=D$ we will always reject $H_0$ (because the random sample always falls into $C$), so we never make Type II errors when $\\theta\\in\\Theta_1$ but always make Type I errors when $\\theta\\in\\Theta_0$.\n\\eit\n\n% remark: status quo\n\\begin{remark}[Conservatie testing]\nThe null hypothesis represents the \\textit{status quo}. From a conservative standpoint, rejecting the status quo incorrectly (Type I error) is worse than retaining the status quo incorrectly (Type II error). As a result, hypothesis tests usually proceed in two stages:\n\\ben\n\\it find a set of tests for which $\\prob(\\text{Type I error})$ is bounded above by some acceptable value, then\n\\it choose one of these tests so that $\\prob(\\text{Type II error})$ is as small as possible.\n\\een\n\\end{remark}\n\n%We compute these probabilities over all possible realisations of the sample $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$. If $F(x;\\theta)$ is the common CDF of the $X_i$, it can be shown that for every $\\theta\\in\\Theta$, there exits a unique probability measure \n\\begin{definition}\nLet $\\mathbf{X}=(X_1,X_2,\\ldots,X_n)$ be a random sample and let $F_{\\theta}(x)$ be the common CDF of the component variables $X_i$. It can be shown that for every $\\theta\\in\\Theta$ there exits a unique probability measure $\\prob_\\theta$ on subsets of $\\R^n$ for which the component variables $X_i$ are independent and identically distribted according to $F_{\\theta}(x)$. This is called the \\emph{probability distribution induced by $\\mathbf{X}$} on the sample space and is denoted by $\\prob_{\\theta}(A)=\\prob_{\\theta}(\\mathbf{X}\\in A)$, which is the probability that %$\\mathbf{X}$\nthe random sample falls into the set $A\\subseteq\\R^n$ when the parameter value is $\\theta$.%: we often write $\\prob_{\\theta}(\\mathbf{X}\\in A)$ instead of $\\prob_{\\theta}(A)$.\n\\end{definition}\n\n% defn: size\n\\begin{definition}\nThe \\emph{size} of a critical region (also called the \\emph{significance level} of the test) is the maximum probability of making a Type I error. This is usually denoted by $\\alpha$,\n\\[\n\\alpha = \\max_{\\strut\\theta\\in\\Theta_0}\\ \\prob_{\\theta}(\\mathbf{X}\\in C).\n\\]\nIf $H_0$ is a simple hypothesis, say $H_0:\\theta=\\theta_0$, this reduces to $\\alpha = \\prob_{\\theta_0}(\\mathbf{X}\\in C)$.\n\\end{definition}\n\n\\begin{remark}[$p$-values]\nLet $T:D\\to\\R$ be a test statistic, let $C = \\{\\mathbf{x} : T(\\mathbf{x}) \\leq c\\}$ be a critical region and suppose that $\\mathbf{x}_{\\text{obs}}$ is the observed sample realisation. Then the \\emph{empirical size} (or $p$-value) of the test is defined to be\n\\[\np = \\max_{\\theta\\in\\Theta_0}\\,\\prob_{\\theta}\\big[ T(\\mathbf{X})\\leq T(\\mathbf{x}_{\\text{obs}})\\big].\n\\]\nIf $H_0$ is a simple hypothesis, say $H_0:\\theta=\\theta_0$, this reduces to \n\\[\np = \\prob_{\\theta_0}\\big[ T(\\mathbf{X})\\leq T(\\mathbf{x}_{\\text{obs}})\\big].\n\\] \nFor a test of size $\\alpha$, we reject $H_0$ if the empirical size satisfies $p\\leq\\alpha$.\n\\end{remark}\n\n\n%-----------------------------\n\\subsection{The power of a test} \n\nAmong all critical regions of size $\\alpha$ we would like to choose one that minimises the probability $\\prob_{\\theta}(\\mathbf{X}\\notin C)$ of making Type II errors for every $\\theta\\in\\Theta_1$, or equivalently a critical region that maximises $\\prob_{\\theta}(\\mathbf{X}\\in C)$ for every $\\theta\\in\\Theta_1$. \n\n\\begin{definition}\nLet $C$ be a critical region for testing $H_0:\\theta\\in\\Theta_0$ against $H_1:\\theta\\in\\Theta_1$. \nThe \\emph{power function} of the associated test is \n\\[\n\\gamma(\\theta) = \\prob_{\\theta}(\\mathbf{X}\\in C) \\quad\\text{which is defined for all $\\theta\\in\\Theta_1$.}\n\\]\nThe value $\\gamma(\\theta)$ is called the \\emph{power of the test to detect the alternative hypothesis at $\\theta\\in\\Theta_1$}.\n\\end{definition}\n\n% remark: beta\n\\begin{remark}\nThe probability of making Type II errors is often denoted by $\\beta$:\n\\begin{align*}\n\\beta(\\theta) \n\t& = \\prob_{\\theta}(\\mathbf{X}\\notin C) \\\\\n\t& = 1-\\gamma(\\theta).% \\quad \\text{for $\\theta\\in\\Theta_1$.}\n\\end{align*}\nTo maximise the power $\\gamma(\\theta)$ is to minimise the probability $\\beta(\\theta)$ of making a Type II error.\n\\end{remark}\n\n%% more powerful\n%Let $C_1$ and $C_2$ be two critical regions of size $\\alpha$, and let $\\gamma_1$ and $\\gamma_2$ respectively denote the power functions of the associated tests. If $\\gamma_1(\\theta) > \\gamma_2(\\theta)$ for all $\\theta\\in\\Theta_1$, we say that $C_1$ is a \\emph{more powerful test} than $C_2$. Later we prove that the \\emph{simple likelihood ratio test} is at least as powerful as any other test of a simple null hypothesis against a simple alternative.\n%\n\\begin{example}\nLet $X_1,X_2,\\ldots,X_8$ be a random sample from the $\\text{Poisson}(\\theta)$ distribution, where $\\theta>0$ is unknown. We reject the simple null hypothesis $H_0:\\theta=0.5$ in favour of the alternative $H_1:\\theta>0.5$ whenever the observed sum satisfies $\\sum_{i=1}^8 X_i \\geq 8$.\n\\ben\n\\it Compute the size of the test.\n\\it Compute the power of the test at $\\theta = 0.75$, $\\theta = 1.0$ and $\\theta = 1.25$.\n\\een\nUse the fact that if $X\\sim\\text{Poisson}(\\theta_1)$ and $Y\\sim\\text{Poisson}(\\theta_2)$ then $X+Y\\sim\\text{Poisson}(\\theta_1+\\theta_2)$.\n\\end{example}\n\n\\begin{solution}\nThe critical region of the test is \n\\[\nC = \\big\\{\\mathbf{x} : T(\\mathbf{x}) \\geq 8\\big\\}\n\\text{\\quad where\\quad}\nT(\\mathbf{X}) = \\sum_{i=1}^8 X_i.\n\\]\nBy the hint, if $X_i\\sim\\text{Poisson}(\\theta)$, then $T(\\boldX)\\sim\\text{Poisson}(8\\theta)$. This is our test statistic.\n\\ben\n\\it % << (i)\nUnder $H_0:\\theta=0.5$, we have $T\\sim\\text{Poisson}(4)$ so\n\\begin{align*}\n\\alpha\t= \\prob_{0.5}\\big(\\boldX\\in C\\big) \n\t\t& = \\prob(T\\geq 8) \\text{ where } T\\sim\\text{Poisson}(4) \\\\\n\t\t& = 1 - \\prob(T\\leq 7) \\text{ where } T\\sim\\text{Poisson}(4) \\\\\n\t\t& = 1 - 0.9489 = 0.0511 \\quad\\text{(from tables).}\n\\end{align*}\n\\it % << (ii)\nUnder $H_1:\\theta=0.75$, we have $T\\sim\\text{Poisson}(6)$ so\n\\begin{align*}\n\\gamma(0.75) = \\prob_{0.75}\\big(\\boldX\\in C\\big) \n\t\t\t& = \\prob(T\\geq 8)\\text{ where }T\\sim\\text{Poisson}(6) \\\\\n\t\t\t& = 1 - \\prob\\big(T\\leq 7)\\text{ where }T\\sim\\text{Poisson}(6) \\\\\n\t\t\t& = 1 - 0.7440 = 0.2560 \\quad\\text{(from tables).}\n\\end{align*}\nUnder $H_1:\\theta=1$, we have $T\\sim\\text{Poisson}(8)$ so\n\\begin{align*}\n\\gamma(1.0)\t= \\prob_{1.0}\\big(\\boldX\\in C\\big) \n\t\t\t& = \\prob(T\\geq 8)\\text{ where }T\\sim\\text{Poisson}(8) \\\\\n\t\t\t& = 1 - \\prob\\big(T\\leq 7)\\text{ where } T\\sim\\text{Poisson}(8) \\\\\n\t\t\t& = 1 - 0.4530 = 0.4570 \\quad\\text{(from tables).}\n\\end{align*}\nUnder $H_1:\\theta=1.25$, we have $T\\sim\\text{Poisson}(10)$ so\n\\begin{align*}\n\\gamma(1.25) = \\prob_{1.25}\\big(\\boldX\\in C;\\theta\\big)\n\t\t\t& = \\prob(T\\geq 8)\\text{ where } T\\sim\\text{Poisson}(10) \\\\\n\t\t\t& = 1 - \\prob(T\\leq 7)\\text{ where } T\\sim\\text{Poisson}(10) \\\\\n\t\t\t& = 1 - 0.2202 = 0.7798 \\quad\\text{(from tables).}\n\\end{align*}\nNotice that the power of the test to detect the alternative hypothesis \\emph{increases} as $\\theta$ moves away from the value $\\theta=0.5$ specified by the null hypothesis.\n\\een\n\\end{solution}\n\n\n", "meta": {"hexsha": "c517c8f1db132c3daecde1dacfb4c4b991e989ed", "size": 14796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/09A_nhst.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/09A_nhst.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/09A_nhst.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": 52.6548042705, "max_line_length": 581, "alphanum_fraction": 0.6865369019, "num_tokens": 5018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6355110962409118}}
{"text": "\\newpage\n\\section{Group extensions}\nToday our goal is to understand how addition of 2-digit numbers is equivalent to another abstract construction in group theory called group extensions.\nUsing this interpretation and some facts from group cohomology, we will eventually be able to answer the question,\n\\begin{q*}\n  What are all the normalized, symmetric, 2-cocycles $c:\\bbz/10 \\times \\bbz/10 \\rightarrow \\bbz/10$?\n\\end{q*}\n\\begin{mdframed}\n  \\adjustbox{scale=1,center}{%\n    \\begin{tikzcd}\n      &\\mbox{Adding 2-digit numbers}\n        \\ar[ddddr, leftrightarrow]\n        &\n      \\\\\\\\\\\\\\\\\n      \\mbox{\\color{white}2-cocycle condition}\n      & & \\text{Group extensions}\n    \\end{tikzcd}\n  }\n\\end{mdframed}\n\n\n\n\n\n\\subsection{Review: Group theory}\nAll our groups will be abelian unless otherwise specified.\n\nA map between abelian groups $\\varphi: G_1 \\longrightarrow G_2$ is a group homomorphism if it satisfies\n\\begin{align*}\n  \\varphi(a + b) = \\varphi(a) + \\varphi(b)\n\\end{align*}\n\n\\begin{qbox}(Practice problem)\n  \\label{q:groupHomsExamples}\n  Find all the group homomorphisms\n  \\begin{enumerate}\n    \\item $\\bbz \\longrightarrow \\bbz$,\n    \\item $\\bbz \\longrightarrow \\bbz/n$,\n    \\item $\\bbz/n \\longrightarrow \\bbz$,\n    \\item $\\bbz/n \\longrightarrow \\bbz/n^2$,\n    \\item $\\bbz/n^2 \\longrightarrow \\bbz/n$,\n  \\end{enumerate}\n  where $n$ is a positive integer.\n\\end{qbox}\n\n\\begin{qbox}\n  Let $M$ be an abelian group. Describe all the group homomorphisms $ \\bbz/n \\longrightarrow M$, where $n$ is a positive integer.\n  (This set will show up again when we discuss group cohomology.)\n\\end{qbox}\n\n\\begin{definition}\n  The \\emph{kernel} of a group homomorphism  $\\varphi: G_1 \\longrightarrow G_2$ is the set of elements $g \\in G_1$ such that $\\varphi(g) = 0$.\n  \\begin{align*}\n    \\ker \\varphi = \\set{ g \\in G_1 : \\varphi(g) = 0}\n  \\end{align*}\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{image} of a group homomorphism  $\\varphi: G_1 \\longrightarrow G_2$ is the set of elements $\\varphi(g) \\in G_2$ where $g \\in G_1$.\n  \\begin{align*}\n    \\im \\varphi = \\set{ \\varphi(g) : g \\in G_1}\n  \\end{align*}\n\\end{definition}\n\n\n\\begin{qbox}\n  Find the kernel and image of the group homomorphisms you found in Q.\\ref{q:groupHomsExamples}.\n\\end{qbox}\n\n\\begin{qbox}\n  Which of the group homomorphisms in Q.\\ref{q:groupHomsExamples} are\n  \\begin{enumerate}\n    \\item injective (=one-to-one)?\n    \\item surjective (=onto)?\n    \\item isomorphisms (=one-to-one and onto)?\n  \\end{enumerate}\n\\end{qbox}\n\n\\subsection*{Optional practice problems}\n\n\\begin{qbox}\n  Show that the image of a group homomorphism  $\\varphi: G_1 \\longrightarrow G_2$ is a subgroup of $G_2$.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that the kernel of a group homomorphism  $\\varphi: G_1 \\longrightarrow G_2$ is a subgroup of $G_1$.\n\\end{qbox}\n\n\\begin{qbox}\n  Show that for a group homomorphism $\\varphi: G_1 \\longrightarrow G_2$ we have $G_1 / \\ker \\varphi \\cong \\im \\varphi$.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Group extensions}\n\n\\begin{qbox}\n  \\label{q:inclusionMaps}\n  Consider the two inclusion maps,\n  \\begin{align*}\n    i_u: \\bbz/10 &\\longrightarrow \\bbz/100  &&& i_t: \\bbz/10 & \\longrightarrow \\bbz/100 \\\\\n    b &\\longmapsto \\tens{0}\\units{b} &&& a &\\longmapsto \\tens{a}\\units{0}\n  \\end{align*}\n  Which of these two maps is a group homomorphism?\n\\end{qbox}\n\n\\begin{qbox}\n  \\label{q:projectionMaps}\n  Consider the two projection maps,\n  \\begin{align*}\n    p_u: \\bbz/100 &\\longrightarrow \\bbz/10 &&& p_t: \\bbz/100 &\\longrightarrow \\bbz/10 \\\\\n    \\tens{a}\\units{b} &\\longmapsto {b} &&& \\tens{a}\\units{b} &\\longmapsto a\n  \\end{align*}\n  Which of these two maps is a group homomorphism?\n\\end{qbox}\n\n\n\\begin{qbox}\n  \\label{q:SES1}\n  For the $i$ and $p$ in Questions \\ref{q:inclusionMaps} and \\ref{q:projectionMaps} that are group homomorphisms, check that\n  \\begin{enumerate}\n    \\item $i$ is injective,\n    \\item $p$ is surjective,\n    \\item $\\im i = \\ker p$.\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{definition}\n  An \\emph{extension} of a group $K$ by $H$ is a group $G$ along with a pair of maps\n  \\begin{align*}\n    i: H \\longrightarrow G && p: G \\longrightarrow K\n  \\end{align*}\n  such that\n  \\begin{enumerate}\n    \\item $i$ is injective,\n    \\item $p$ is surjective,\n    \\item $\\im i = \\ker p$.\n  \\end{enumerate}\n\\end{definition}\n\nThis is often written as a \\emph{short exact sequence}\n\\begin{equation*}\n  \\begin{tikzcd}\n    0 \\ar[r] & H \\ar[r] &  G  \\ar[r] & K \\ar[r] & 0\n  \\end{tikzcd}\n\\end{equation*}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\nQ.\\ref{q:SES1} is saying that the following is a SES\n\\begin{equation*}\n  \\begin{tikzcd}\n    0 \\ar[r] & \\bbz/10 \\ar[r,\"i\"] &  \\bbz/100  \\ar[r,\"p\"] & \\bbz/10 \\ar[r] & 0 \\\\\n     & \\mbox{tens} \\ar[u, equal]  &  \\mbox{2-digit numbers}  \\ar[u,equal] & \\mbox{units}  \\ar[u, equal] &\n  \\end{tikzcd}\n\\end{equation*}\n\nIn fact, every group extension arises in this manner.\nConsider an extension of abelian groups,\n\\begin{equation*}\n  \\begin{tikzcd}\n    0 \\ar[r] & H \\ar[r,\"i\"] &  G  \\ar[r, \"p\"] & K \\ar[r] & 0.\n  \\end{tikzcd}\n\\end{equation*}\ni.e.\n\\begin{enumerate}\n  \\item $i$ is injective,\n  \\item $p$ is surjective,\n  \\item $\\im i = \\ker p$.\n\\end{enumerate}\n\nFor an element $a \\in H$, denote by $\\tens{a}\\units{0} \\in G$ the element $i(a)$.\nFor an element $b \\in K$, let $\\tens{0}\\units{b}$ be \\emph{some} element in $G$ such that $p(\\tens{0}\\units{b}) = b$.\nDefine $\\tens{a} \\units{b}$ to be the element $\\tens{a}\\units{0} + \\tens{0}\\units{b}$ in $G$.\n\n\\begin{qbox}\n  Show that $p(\\tens{a}\\units{0}) = 0$ for any $a \\in H$.\n\\end{qbox}\n\n% \\begin{qbox}\n%   % \\begin{enumerate}\n%   %   \\item\n%     Check that $\\tens{a_1}\\units{0} + \\tens{a_2}\\units{0} = \\tens{a_1 + a_2}\\units{0}$.\n%     % \\item Is it true that $\\tens{0}\\units{b_1} + \\tens{0}\\units{b_2} = \\tens{0}\\units{b_1 + b_2}$?\n%   % \\end{enumerate}\n% \\end{qbox}\n\n\\begin{qbox}\n  \\label{q:uniquenessOfDigits}\n  Let $a_1$, $a_2$ be elements in $H$ and let $b_1$, $b_2$ be elements in $K$, show that\\hint{Apply $p$ to both sides of $[a_1][b_1] = [a_2][b_2]$.}\n\\begin{align*}\n    [a_1][b_1] = [a_2][b_2] \\implies a_1 = a_2 \\mbox{ and } b_1 = b_2.\n\\end{align*}\n\\end{qbox}\n\n\\begin{qbox}\n  \\label{q:existenceOfDigits}\n  Show that for every element $g \\in G$, there exist unique elements $a \\in H$ and $ b \\in K $ such that $g = \\units{a}\\tens{b}$.\n  \\hint{Look at $p(g)$ and $g - \\tens{p(g)}\\units{0}$.}\n\\end{qbox}\n", "meta": {"hexsha": "a3e321fce9a21d4d8965257c2efbeec6914b0060", "size": 6341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.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": "02.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": "02.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": 28.0575221239, "max_line_length": 151, "alphanum_fraction": 0.6498974925, "num_tokens": 2364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825655188238, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.635506812714875}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb}\n\\newcommand\\set[1]{\\left\\{#1\\right\\}}\n\n\\begin{document}\n\\section{Probability method}\n\nTake a die. If the outcome is $5$ or $6$, roll again.\nIf the outcome is between $1$ and $4$, the number denotes the student's group.\n\nIf one group has reached cardinality $4$, it is excluded just like $5$ and $6$.\n\n\\textbf{Rationale:} As the result of $5$ or $6$ does not influence\nthe probability of outcomes $1$ to $4$, this defines a uniform discrete probability distribution.\n\n\\section{Probability space}\n\n\\[ \\Omega = \\operatorname{permutations}(\\set{1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}) \\]\nwhere the groups are implicitly defined by indices 1--4, 5--8, 9--12 and 13--16.\n\\[ \\mathcal A = \\mathcal P(\\Omega) \\]\n\\[ \\mathbb P(A) = \\frac14^{|A|} \\]\n\n\\section{In a group of friends}\n\nLet Peter and Alice be Moritz' friends.\nLet $\\mathbb P[M=1]$ be the probability that Moritz is assigned to group 1.\nLet $\\mathbb P[P=N]$ and $\\mathbb P[A=N]$ be correspondingly.\n\n\\[ \\mathbb P[M=1] = \\frac14 \\]\n\\[ \\mathbb P[M=N] = \\frac14 \\]\n\n\\[ \\mathbb P[M=1, P=1] = \\frac14 \\cdot \\frac14 \\]\n\\[ \\mathbb P[M=N, P=N] = \\sum_{N=1}^4 \\frac14 \\cdot \\frac14 = \\frac14 \\]\n\n\\[ \\mathbb P[M=1, P=1, A=1] = \\frac14 \\cdot \\frac14 \\cdot \\frac14 = \\frac14^3 \\]\n\\[ \\mathbb P[M=N, P=N, A=N] = \\sum_{N=1}^4 \\frac14^3 = 4 \\frac14^3 \\]\n\n\\section{Blackboard solution}\n\nApproach: All children draw balls from one urn.\n\n\\[ \\Omega = \\set{\\text{set partitions of $\\{1, \\dots, 16\\}$ in $4$-tary subsets}} \\]\n$(k_1, \\dots, k_{16})$\n\nWe can arrange 16 elements ($16!$).\nIn each group, you can arrange the students as well ($(4!)^5$)\n\n\\[ \\frac{16!}{(4!)^5} = 2627625 \\]\n\nMoritz' group consists of members:\n\\[ \\set{M, F_1, F_2, R} \\]\n\nWe can $13$ choices for the remaining child.\n\\[ \\frac{13 {12 \\choose 4} {8 \\choose 4} {4 \\choose 4} \\cdot 4}{{16 \\choose 4} {12 \\choose 4} {8 \\choose 4} {4 \\choose 4}} = \\frac{1}{35} \\]\n\nYou can also draw probability trees.\nYou get one branch $\\left(\\frac14 \\cdot \\frac3{15} \\cdot \\frac2{14}\\right) \\cdot 4 = \\frac1{35}$\n\n\\end{document}\n", "meta": {"hexsha": "d02d1993345244af4c503912efc1fe13d178c659", "size": 2090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability_theory_practicals/ex6/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/ex6/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/ex6/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": 34.262295082, "max_line_length": 140, "alphanum_fraction": 0.6488038278, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825659156573, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6355068110688238}}
{"text": "\\newpage\n\\subsection{Sample generators}\n\\label{sec:samplers}\nWhen rendering an image, Mitsuba has to solve a high-dimensional integration problem that involves the\ngeometry, materials, lights, and sensors that make up the scene. Because of the mathematical complexity\nof these integrals, it is generally impossible to solve them analytically --- instead, they\nare solved \\emph{numerically} by evaluating the function to be integrated at a large number of\ndifferent positions referred to as \\emph{samples}. Sample generators are an essential ingredient to this\nprocess: they produce points in a (hypothetical) infinite dimensional hypercube $[0,1]^{\\infty}$ that\nconstitute the canonical representation of these samples.\n\nTo do its work, a rendering algorithm, or \\emph{integrator}, will send many queries to the sample generator.\nGenerally, it will request subsequent 1D or 2D components of this infinite-dimensional ``point'' and map\nthem into a more convenient space (for instance,  positions on surfaces). This allows it to construct\nlight paths to eventually evaluate the flow of light through the scene.\n\nSince the whole process starts with a large number of points in the abstract space $[0,1]^{\\infty}$,\nit is natural to consider different ways of positioning them. Desirable properties of a sampler are\nthat it ``randomly'' covers the whole space evenly with samples, but without placing samples too close\nto each other. This leads to such notions as \\emph{stratified sampling} and \\emph{low-discrepancy}\nnumber sequences. The samplers in this section make different guarantees on the quality of generated\nsamples based on these criteria. To obtain intuition about their behavior, the provided point plots\nillustrate the resulting sample placement.\n", "meta": {"hexsha": "97762b709593069620fb41ae38ba37f4d931031f", "size": 1757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mitsuba-af602c6fd98a/doc/section_samplers.tex", "max_stars_repo_name": "NTForked-ML/pbrs", "max_stars_repo_head_hexsha": "0b405d92c12d257e2581366542762c9f0c3facce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2017-04-21T00:22:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T20:33:10.000Z", "max_issues_repo_path": "mitsuba-af602c6fd98a/doc/section_samplers.tex", "max_issues_repo_name": "NTForked-ML/pbrs", "max_issues_repo_head_hexsha": "0b405d92c12d257e2581366542762c9f0c3facce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-08-15T18:22:59.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-01T05:44:41.000Z", "max_forks_repo_path": "mitsuba-af602c6fd98a/doc/section_samplers.tex", "max_forks_repo_name": "NTForked-ML/pbrs", "max_forks_repo_head_hexsha": "0b405d92c12d257e2581366542762c9f0c3facce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2017-07-21T03:56:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T06:55:34.000Z", "avg_line_length": 73.2083333333, "max_line_length": 108, "alphanum_fraction": 0.8064883324, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6355067914482391}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrpwv}\n\\section*{\\hspace*{-1.6cm} tfrpwv}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nPseudo Wigner-Ville time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrpwv(x)\n[tfr,t,f] = tfrpwv(x,t)\n[tfr,t,f] = tfrpwv(x,t,N)\n[tfr,t,f] = tfrpwv(x,t,N,h)\n[tfr,t,f] = tfrpwv(x,t,N,h,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrpwv} computes the pseudo Wigner-Ville distribution of a\n        discrete-time signal {\\ty x}, or the cross pseudo Wigner-Ville\n        distribution between two signals. The pseudo Wigner-Ville\n        distribution writes\n\\[PW_x(t,\\nu)=\\int_{-\\infty}^{+\\infty} h(\\tau)\\ x(t+\\tau/2)\\ x^*(t-\\tau/2)\\\ne^{-j2\\pi \\nu \\tau}\\ d\\tau.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & signal if auto-PWV, or {\\ty [x1,x2]} if cross-PWV\n\t\t\t({\\ty Nx=length(x)}) \\\\ \n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty h}     & frequency smoothing window, in the time-domain,\n                {\\ty h(0)} being forced to {\\ty 1}   & {\\ty window(odd(N/4))}\\\\ \n        {\\ty trace}  & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation \\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrpwv} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4); \n         tfrpwv(sig);\n\\end{verbatim}\n\n\\newpage\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] T. Claasen, W. Mecklenbrauker ``The Wigner Distribution - A Tool for\nTime-Frequency Signal Analysis'' {\\it 3 parts} Philips\nJ. Res., Vol. 35, No. 3, 4/5, 6, pp. 217-250, 276-300, 372-389, 1980.\n\\end{minipage}\n", "meta": {"hexsha": "3670bf9af8e3ff325b64653aa901579491e208bd", "size": 2535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrpwv.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrpwv.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrpwv.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 28.8068181818, "max_line_length": 80, "alphanum_fraction": 0.608678501, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6355067821646254}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Dual Complex Numbers}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn exo-1 binion has the form\n\\begin{equation}\n    a_{0} + a_{1} A + a_{2} W + a_{3} AW\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the binions.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "d43762714164d063d030f11dad3e250cb4be1dc7", "size": 2090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/I.tex", "max_stars_repo_name": "meirizarrygelpi/plexifications", "max_stars_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_stars_repo_licenses": ["MIT"], "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/I.tex", "max_issues_repo_name": "meirizarrygelpi/plexifications", "max_issues_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_issues_repo_licenses": ["MIT"], "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/I.tex", "max_forks_repo_name": "meirizarrygelpi/plexifications", "max_forks_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_forks_repo_licenses": ["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.5, "max_line_length": 80, "alphanum_fraction": 0.1947368421, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.6926419958239132, "lm_q1q2_score": 0.6353623386464496}}
{"text": "\\section{Leader Value Calculation}\n\\label{sec:leader-value-calc}\n\nThis section details how we determine whether a node is entitled to lead (under\nthe Praos protocol) given the output of its verifiable random function\ncalculation.\n\n\\begin{figure}\n  \\emph{Values associated with the leader value calculations}\n  \\begin{equation*}\n  \\begin{array}{r@{~\\in~}lr}\n    \\var{certNat} & \\{n | n \\in \\N, n \\in [0,2^{512})\\} & \\text{Certified natural value from VRF} \\\\\n    \\var{f} & [0,1] & \\text{Active slot coefficient} \\\\\n    \\sigma & [0,1] & \\text{Stake proportion}\n  \\end{array}\n  \\end{equation*}\n\\end{figure}\n\n\\subsection{Computing the leader value}\n\nThe verifiable random function gives us a 64-byte random output. We interpret\nthis as a natural number $\\var{certNat}$ in the range $[0,2^{512})$.\n\n\\subsection{Node eligibility}\n\nAs per \\cite{ouroboros_praos}, a node is eligible to lead when its leader value\n$p < 1 - (1 - f)^\\sigma$. We have\n\n\\begin{align*}\n  p & < 1 - (1 -f)^\\sigma \\\\\n  \\iff \\left(\\frac{1}{1-p}\\right) & < \\exp{(-\\sigma \\cdot \\ln{(1-f)})}\n\\end{align*}\n\nThe latter inequality can be efficiently computed through use of its Taylor\nexpansion and error estimation to stop computing terms once we are certain that\nthe result will be either above or below the target value.\n\nWe carry out all computations using fixed precision arithmetic (specifically, we\nuse 34 decimal bits of precision, since this is enough to represent the fraction\nof a single lovelace.)\n\nAs such, we define the following:\n\n\\begin{align*}\n  p & = \\frac{\\var{certNat}}{2^{512}} \\\\\n  q & = 1 - p \\\\\n  c & = \\ln{(1 - f)}\n\\end{align*}\n\nand define the function \\textit{checkLeaderVal} as follows:\n\n\\begin{equation*}\n  \\fun{checkLeaderVal}~\\var{certNat}~\\sigma~\\var{f} =\n    \\left\\{\n      \\begin{array}{l@{~}r}\n        \\mathsf{True}, & f = 1 \\\\\n        \\frac{1}{q} < \\exp{(-\\sigma \\cdot c)}, & \\text{ otherwise}\n      \\end{array}\n    \\right.\n\\end{equation*}\n", "meta": {"hexsha": "b70a264d00384f9ff54601c738fc78ea81f2f3b0", "size": 1934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shelley/chain-and-ledger/formal-spec/leader-value.tex", "max_stars_repo_name": "ilap/cardano-ledger-specs", "max_stars_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 108, "max_stars_repo_stars_event_min_datetime": "2019-03-24T02:26:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-30T05:27:16.000Z", "max_issues_repo_path": "shelley/chain-and-ledger/formal-spec/leader-value.tex", "max_issues_repo_name": "ilap/cardano-ledger-specs", "max_issues_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1266, "max_issues_repo_issues_event_min_datetime": "2019-03-18T20:23:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-04T12:50:51.000Z", "max_forks_repo_path": "shelley/chain-and-ledger/formal-spec/leader-value.tex", "max_forks_repo_name": "ilap/cardano-ledger-specs", "max_forks_repo_head_hexsha": "6474f68b24d05175fc3fd44a9bdfa95bda703a25", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 86, "max_forks_repo_forks_event_min_datetime": "2019-03-29T06:53:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T17:17:15.000Z", "avg_line_length": 31.7049180328, "max_line_length": 100, "alphanum_fraction": 0.6747673216, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6353550809797328}}
{"text": "\\subsection{Complex Roots}\r\nConsider the $k^{th}$ power map $p_k:z\\mapsto z^k$.\r\nWe can ``invert'' it by $\\sqrt[k]{z}=\\exp(k^{-1}\\log z)$.\r\nThis multi-valued function can be analysed analogously to how we analyse $\\log$.\r\nTake $I(n)=((n-1)\\pi/2,(n+1)\\pi/2)$ as usual and $U_{I(n)}$ as before equipped with the same $f_{I(n)}:U_{I(n)}\\to\\mathbb C$ we did for $\\log$.\r\nThen consider $g_{I(n)}(z)=\\exp(k^{-1}f_{I(n)}(z))$ and the function elements $G_{I(n)}=(g_{I(n)},U_{I(n)})$.\r\nNow $G_{I(n)}$ only depends on $n\\bmod k$, so WLOG we can think of $n\\in\\mathbb Z/k\\mathbb Z$.\r\nEverything else is similar to what we did before, and we can get $G_{I(n)}\\sim G_{I(m)}$ iff $n-m\\equiv 0,\\pm 1\\pmod{k}$.\r\nFurthermore, a similar gluing constructio defines a path-connected Hausdorff space $R_k$ and maps\r\n\\[\r\n    \\begin{tikzcd}\r\n        R_k\\arrow{r}{g}\\arrow[swap]{dr}{\\pi}&\\mathbb C_\\star\\arrow{d}{p_k}\\\\\r\n        &\\mathbb C_\\star\r\n    \\end{tikzcd}\r\n\\]\r\nSo $g$ gives what we want from the $k^{th}$ root.", "meta": {"hexsha": "4b5cc568cce8d1efc884caad4c0739e70197f59b", "size": 995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/roots.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/roots.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/roots.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": 62.1875, "max_line_length": 144, "alphanum_fraction": 0.6311557789, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6352105437481881}}
{"text": "\\section{Permutations}\n\n\\prob{https://artofproblemsolving.com/community/c5h1434000p8108658}{USAMO 2017\n    P5}{M}{\n    Let $m_1, m_2, \\ldots, m_n$ be a collection of $n$ positive integers, not\n    necessarily distinct. For any sequence of integers $A = (a_1, \\ldots,\n    a_n)$ and any permutation $w = w_1, \\ldots, w_n$ of $m_1, \\ldots, m_n$,\n    define an $A$-inversion of $w$ to be a pair of entries $w_i, w_j$ with $i\n    < j$ for which one of the following conditions holds:\n    \\[\\begin{aligned}\n    a_i \\ge w_i > w_j,\\quad\n    w_j > a_i \\ge w_i,\\quad\n    w_i > w_j > a_i\n    \\end{aligned}\\]\n    Show that, for any two sequences of integers $A = (a_1, \\ldots, a_n)$ and $B =\n    (b_1, \\ldots, b_n)$, and for any positive integer $k$, the number of\n    permutations of $m_1, \\ldots, m_n$ having exactly $k$ $A$-inversions is equal\n    to the number of permutations of $m_1, \\ldots, m_n$ having exactly $k$ $B$-inversions.\n\n    \\index[cat]{Permutations!USAMO 2017 P5}\n    \\index[strat]{Bijection!USAMO 2017 P5}\n}\n\n\\begin{solution}\n    Notice that if we take $B$ as a sequence with all elements greater than\n    all $w_i$, then we have the $B$-inversions to be normal inversions wrt\n    $M$. So we need to show that there exists a bijection between $A$-inversion and\n    normal inversion. \\\\\n\n    So we can either show that there for a permutation $w$ with $k$ normal\n    inversions, there is a permutation $p$ with $k$ $A$-inversions. But we\n    soon figure out it is pretty hard.\\\\\n\n    If we try the other way, show that for every $w$ with $k$ $A$-inversions,\n    there is a $p$ with the same $k$ normal inversions, and if we can show\n    injectivity, we will be done. It turns out that this is much easier.\n\\end{solution}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h271833p1472110}\n{ISL 2008 C2}{E}{\n    Let $n \\in \\mathbb N$ and $A_n$ set of all permutations $(a_1, \\ldots,\n    a_n)$ of the set $\\{1, 2, \\ldots , n\\}$ for which\n    \\[k\\ |\\ 2(a_1 + \\cdots+ a_k), \\text{ for all } 1 \\leq k \\leq n.\\]\n    Find the number of elements of the set $A_n$.\n\n    \\index[cat]{Permutations!ISL 2008 C2}\n    \\index[strat]{Induction!ISL 2008 C2}\n}\n\n\\begin{solution}\n    First we try some smaller cases: $ |A_1| = 1$, $ |A_2| = 2$, $ |A_3| = 6$,\n    $ |A_4| = 12$, which has a clear pattern. So we proceed with induction.\\\\\n\n    With induction, we focus on $a_n$ only, it can have values eiher $n, 1$ or\n    $\\frac{n+1}{2}$. But the later case is impossible, and so we only have two\n    options for $a_n$, which gives us our desired inductive relation.\n\\end{solution}\n", "meta": {"hexsha": "2e687ce0596885b5f23d9dc04ce70122c979c86e", "size": 2569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combi/sec13_permutation.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/sec13_permutation.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/sec13_permutation.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.5423728814, "max_line_length": 90, "alphanum_fraction": 0.6605683145, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936484231889, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6352105437481881}}
{"text": "\\documentclass[11pt, oneside]{article}   \t% use \"amsart\" instead of \"article\" for AMSLaTeX format\n\\usepackage{fullpage}\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\n\\title{Brief Article}\n\\author{The Author}\n%\\date{}\t\t\t\t\t\t\t% Activate to display a given date or no date\n\n\\begin{document}\n%\\maketitle\n\n\\section{Mapping cylinder to 4 sides of cube}   \n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{cube_cylinder} \n\\end{center}      \n   \nGiven the cylinder $x^2 + y^2 = 1$ inscribed inside a $2 \\times 2 \\times 2$ cube\ncentered at the origin, we can project the cylindrical panorama onto the corresponding\nfour faces of the cube as follows.\nFor every pixel in the output image we cast a ray from the cube's center at $(0,0,0)$\nthrough the corresponding point on one of the cube's faces and determine where that\nray intersects the cylinder. We then map this point on the cylinder to the corresponding\npoint in the input image and (bilinearly) sample the input image at the point. \nThe resulting pixel color is assigned to the current output pixel.\n\nWe parameterize the ray emanating from \nthe cube's center $(0,0,0)$ through a point $(u,v,w)$ on a face of the cube as\n\\begin{equation}\n  \\mathbf{r}(t) = (0,0,0) + t\\cdot(u,v,w). \\label{eq:r}\n\\end{equation}\nThis ray intersects the cylinder where\n\\begin{equation}\n  (ut)^2 + (vt)^2 = 1.\n\\end{equation}\nSolving we get $t = 1/\\sqrt{u^2 + v^2},$ which we plug back into Equation~\\ref{eq:r} and\nget the cylindrical point\n\\begin{equation}\n  \\mathbf{p} = (x,y,z) = \\frac{(u,v,w)}{\\sqrt{u^2 + v^2}}. \\label{eq:p-cyl}\n\\end{equation}\nIn cylindrical coordinates we have\n\\begin{eqnarray}\n\\mathbf{p} = \\left(\\theta, z\\right), \\ \\ \\ \n  \\theta = \\mbox{atan2}\\left(y,x\\right) + \\pi/4. \\label{eq:theta}\n\\end{eqnarray}\nWe added $\\pi/4$ to $\\theta$ so that the left edge of the image corresponds to\nthe left edge of the cube's $x = 1$ face (instead of the middle of the face);\nThen we adjust for the appropriate image ``wrap-around:''\n\\begin{equation}\n\\theta' = \\left\\{\\begin{array}{ll}\n  \\theta        & \\theta \\geq 0 \\\\\n  \\theta + 2\\pi & \\theta < 0\n  \\end{array}\\right.\n\\end{equation}\nNow the left edge of the input image corresponds to the left edge of the output image.\nThe resulting pixel coordinate in the input image is\n\\begin{equation}\n(r,c) = \\left(\\frac{H}{2}\\left(z + 1\\right),\\ \\frac{W}{2\\pi}\\cdot \\theta'\\right).\n\\end{equation}\n\n\n\n\n\\begin{verbatim}\nfor row = 0 .. outImage.H-1 {\n    for col = 0 .. outImage.W-1 {\n       s = 4.0*col/outImage.W\n       face = floor(s)  // face = 0,1,2,3\n       f = s - face     // f = frac(s)\n       if face == 0 {   // (u,v,w) = point on cube\n           u = 1\n           v = 2*f - 1\n       } else if face == 1 {\n           u = 1 - 2*f\n           v = 1\n       } else if face == 2 {\n           u = -1\n           v = 1 - 2*f\n       } else {\n           u = 2*f - 1\n           v = -1\n       }\n       w = 2.0*row/outImage.H - 1\n       (x,y,z) = (u,v,w)/sqrt(u*u + v*v) // project onto cylinder\n       theta = atan2(y,x) + pi/4;        // cyl. coords, -3pi/4 <= theta <= 5pi/4\n       if theta < 0                      // map to [0,2*pi)\n           theta += 2*pi\n       r = inImage.H*(z + 1)/2.0         // map to input pixel\n       c = imImage.W*theta/(2*pi)\n       outImage(row,col) = inImage.sample(r,c)\n     }\n}\n\\end{verbatim}\n\n\\section{Mapping sphere to 6 sides of cube}  \n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{cube_sphere} \n\\end{center}      \n\nGiven the sphere $x^2 + y^2 + z^2= 1$ inscribed inside a $2 \\times 2 \\times 2$ cube\ncentered at the origin, we can project the spherical panorama onto the corresponding\nfour faces of the cube as follows.\nFor every pixel in the output image we cast a ray from the cube's center at $(0,0,0)$\nthrough the corresponding point on one of the cube's faces and determine where that\nray intersects the sphere. We then map this point on the sphere to the corresponding\npoint in the input image and (bilinearly) sample the input image at the point. \nThe resulting pixel color is assigned to the current output pixel.\n\nWe parameterize the ray emanating from \nthe cube's center $(0,0,0)$ through a point $(u,v,w)$ on a face of the cube \nand find where it intersects the unit sphere. We use the mapping defined at\n\\begin{verbatim}\nhttp://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html\n\\end{verbatim}\nyielding\n\\begin{eqnarray}\nx &=& u\\sqrt{1 - \\frac{v^2}{2} - \\frac{w^2}{2} + \\frac{v^2 w^2}{3}}, \\\\\ny &=& v\\sqrt{1 - \\frac{w^2}{2} - \\frac{u^2}{2} + \\frac{w^2 u^2}{3}}, \\\\\nz &=& w\\sqrt{1 - \\frac{u^2}{2} - \\frac{v^2}{2} + \\frac{u^2 v^2}{3}}.\n\\end{eqnarray}\nWe convert $(x,y,z)$ to the spherical coordinate $(\\theta, \\phi)$ where\nthe azimuthal angle is\n\\begin{equation}\n\\theta = \\mbox{atan2}\\left(y,x\\right)\n\\end{equation}\nand the elevation angle is\n\\begin{equation}\n\\phi = \\mbox{atan2}\\left(\\sqrt{x^2+y^2},\\ z\\right).\n\\end{equation}\n\n\\pagebreak\n\nWe divvy up the output image into $3 \\times 4 = 12$ squares where only 6 of the\nsquares actually map to the actual faces of the cube:\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{cube-coords} \n\\end{center}      \nWe pick $(u,v,w)$ coordinates for the unused corners so that the image has a toroidal topology.\n\n\\begin{verbatim}\nfor row = 0 .. outImage.H-1 {\n    for col = 0 .. outImage.W-1 {\n       a = 4.0*col/outImage.W\n       b = 3.0*row/outImage.H\n       (i,j) = (floor(a),floor(b))            // map to one of 12 squares\n       (s,t) = (a - i, b - j)                 // uvw interpolation values\n       (u,v,w) = bilerp(corners[j][i]), s,t)  // get cube coords w/in square\n       (x,y,z) = cubeToSphereCoords(u,v,w)   \n       (theta,phi) = cartesianToSpherical(x,y,z)\n       r = theta*inImage.W/(2*pi)\n       c = (phi + pi/2)*inImage.H/pi\n       outImage(row,col) = inImage.sample(r,c)\n     }\n}\n\\end{verbatim}\n\n\n\\end{document}  ", "meta": {"hexsha": "6308739fcdecf5e7cd6ecb06b0f4706cfd1194f9", "size": 5814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pano_to_cube.tex", "max_stars_repo_name": "wcochran/pano_to_cube", "max_stars_repo_head_hexsha": "5d5e6852f6b2917f27edb578428ccf28de601e60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-04-21T18:59:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T08:59:28.000Z", "max_issues_repo_path": "pano_to_cube.tex", "max_issues_repo_name": "wcochran/pano_to_cube", "max_issues_repo_head_hexsha": "5d5e6852f6b2917f27edb578428ccf28de601e60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pano_to_cube.tex", "max_forks_repo_name": "wcochran/pano_to_cube", "max_forks_repo_head_hexsha": "5d5e6852f6b2917f27edb578428ccf28de601e60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-02-20T06:33:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-14T06:45:31.000Z", "avg_line_length": 36.3375, "max_line_length": 97, "alphanum_fraction": 0.6357069143, "num_tokens": 1905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6352105348997152}}
{"text": "\\documentclass[epsfig,10pt,fullpage]{article}\n\n\\newcommand{\\LabNum}{2}\n\\newcommand{\\CommonDocsPath}{../../common/docs}\n\\input{\\CommonDocsPath/preamble.tex}\n\n\\begin{document}\n\n\\centerline{\\huge OpenCL}\n~\\\\\n\\centerline{\\huge Laboratory Exercise \\LabNum}\n~\\\\\n\\centerline{\\large Accelerating Computer Vision Techniques}\n~\\\\\n\nThis exercise introduces you to accelerating computer vision techniques using the Intel FPGA SDK for OpenCL. \n\n\\section*{The Canny Edge-detection Technique}\n\n\\noindent\nIn this exercise, we will implement a variation of the \\textit{Canny edge detector}, which is \na widely-used edge-detection scheme in computer vision applications. Figures~\\ref{fig:tracks} and \\ref{fig:tracks_edges} \nshow a sample image that is provided as the input to a Canny edge detector, as well as the \nresulting edge-detected output image. \n\n~\\\\\n\\noindent\nThe Canny edge-detection algorithm involves five stages which are applied to the input image in \nsuccession. The details of these stages are given below. As well, we will see how the sample \ninput image from Figure~\\ref{fig:tracks} is transformed as it passes through \neach stage.\n\n~\\\\\n~\\\\\n\\begin{figure}[h]\n\\centering\n\\begin{minipage}[b]{0.475\\textwidth}\n\t\\includegraphics[width=\\textwidth]{figures/tracks.png}\n\t\\caption{Original image.}\n\t\\label{fig:tracks}\n\\end{minipage}\n\\hfill\n\\begin{minipage}[b]{0.475\\textwidth}\n\t\\includegraphics[width=\\textwidth]{figures/tracks_edges.png}\n\t\\caption{Edge-detected image.}\n\t\\label{fig:tracks_edges}\n\\end{minipage}\n\\end{figure}\n\n\\pagebreak\n\n\\noindent\n\\section*{Stage 1: Grayscale Conversion}\n\nFigure~\\ref{fig:sample_stage1} shows the state of our sample image at the end of the grayscale \nconversion stage. This stage converts the input 24-bit bitmap color image (8 bits each for red, \ngreen, and blue) into an 8-bit grayscale image. The grayscale value at each pixel is calculated \nas the average of the three 8-bit color values of the original image.\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_stage1_grayscale.png}\n   \\end{center}\n   \\caption{The sample input image after the grayscale conversion stage.}\n\t\\label{fig:sample_stage1}\n\\end{figure}\n\n\\noindent\n\\section*{Stage 2: Gaussian Smoothing}\n\nFigure~\\ref{fig:sample_stage2} shows the state of our sample image at the end of the gaussian \nsmoothing stage. In this stage, a gaussian filter is used to smooth out the image, by \nmodifying noisy pixels (pixels that are unlike their neighbouring pixels) to be more like \ntheir neighbours. Shown below is the 5 x 5 gaussian filter operation that is applied to the \nimage. Note that the * denotes convolution, A is the original image, and B is the resulting \nfiltered image. The effect of this operation is that each pixel gets assigned the weighted \naverage value of the 5 x 5 grid of pixels surrounding each pixel.\n\n\\[\nB = 1/159\n\\begin{bmatrix}\n    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\n\\end{bmatrix} * A\n\\]\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_stage2_gaussian.png}\n   \\end{center}\n   \\caption{The sample input image after the gaussian smoothing stage.}\n\t\\label{fig:sample_stage2}\n\\end{figure}\n\n\\noindent\n\\section*{Stage 3: Sobel Operator} \n\nFigure~\\ref{fig:sample_stage3} shows the state of our sample image at the end of the sobel operator stage. This stage overwrites each pixel with the overall intensity gradient at that pixel. To calculate the overall intensity gradient, the gradient is first calculated in the horizontal ($C_x$) and vertical ($C_y$) directions across the pixel, using the matrices below:\n\n\\[\nC_x = \n\\begin{bmatrix}\n    -1 & 0 & 1  \\\\\n    -2 & 0 & 2  \\\\\n    -1 & 0 & 1 \n\\end{bmatrix} * B\n\\ \\ \\ \\ \\ \\ \\  \\ \\ \\ \\ \\  C_y = \n\\begin{bmatrix}\n    -1 & -2 & -1 \\\\\n    0 & 0 & 0 \\\\\n    1 & 2 & 1\n\\end{bmatrix} * B\n\\]\n\n~\\\\\n\\noindent\nThe magnitudes of the two gradients are then added to calculate the overall gradient intensity value for each pixel, resulting in the image C:\n\n\\[\nC = 0.5|C_x| + 0.5|C_y|\n\\]\n\n~\\\\\n\\noindent\nIn image C, which is the final output of this stage, the edges of the original image are highlighted as brighter pixels. Non-edges, which are areas with low intensity gradients, appear as darker pixels.\n\n~\\\\\n~\\\\\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_stage3_sobel.png}\n   \\end{center}\n   \\caption{The sample input image after the sobel operator stage.}\n\t\\label{fig:sample_stage3}\n\\end{figure}\n\n~\\\\\n\\noindent\nTo illustrate the effect of the sobel operator, let us examine different image boundaries that may exist in an image as shown in Figure~\\ref{fig:image_boundaries}. For each 3 x 3 image shown, we can use the sobel operator to calculate the intensity gradient at the center pixel. Let us examine the vertical boundary example, where there is a boundary between darker pixels on the left side of the image, and brighter pixels on the right side. In this example, $|C_x|$ of the center pixel can be calculated as |\\{-1*2 + 0*98 + 1*181\\} + \\{-2*1 + 0*94 + 2*178\\} + \\{-1*6 + 0*91 + 1*184\\}| = 711. In the vertical direction, $|C_y|$ for this pixel is calculated to be 7. The intensity gradient for this pixel is high in the horizontal direction, and low in the vertical direction, which is to be expected along a vertical boundary. The total intensity gradient for this pixel, is $0.5*711 + 0.5*7 = 359$ which saturates the 8-bit grayscale channel to value 255. The sobel operator would therefore detect this boundary as a strong edge, and the center pixel would become bright with a value of 255.\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.80]{figures/fig_image_boundaries.pdf}\n   \\end{center}\n   \\caption{Examples of boundaries in an image.}\n\t\\label{fig:image_boundaries}\n\\end{figure}\n\n~\\\\\n\\noindent\nIn the horizontal boundary case, we see that the vertical gradient is high ($|C_y|$ = 726) and the horizontal gradient is low ($|C_x|$ =  2). For the diagonal boundary case, the gradient is high in both directions with $|C_x|$ = 516 and $|C_y|$ = 552. Finally, for the non-boundary case, the gradients are low in both directions with $|C_x|$ = 4 and $|C_y|$ = 36. As the gradients are low, the center pixel would become dark with a value of $0.5*4 + 0.5*36 = 20$.\n\n\\noindent\n\\section*{Stage 4: Non-Maximum Suppression} \n\n\\noindent\nFigure~\\ref{fig:sample_stage4} shows the state of our sample image at the end of the non-maximum suppression stage. This stage aims to thin the thick and/or blurry edges that may have resulted from the sobel operator stage. Thick edges are problematic as many applications of edge detection benefit from the edges being as thin as possible. For example, to accurately calculate the surface area of an object, thin edges are desired as to not overlap with the surface. The non-maximum suppression stage thins the edges by removing the weaker (non-maximum) pixels of each edge, and keeping only the maxima. Figure~\\ref{fig:nonmaximum_suppression} shows the effect of non-maximum suppression on a sample image containing a blurry vertical line. Notice that the vertical line, which is originally three-pixels wide, becomes one-pixel wide.  \n\n~\\\\\n~\\\\\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_stage4_nonmax_suppression.png}\n   \\end{center}\n   \\caption{The sample input image after the non-maximum suppression stage.}\n\t\\label{fig:sample_stage4}\n\\end{figure}\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.8]{figures/fig_nonmaximum_suppression.pdf}\n   \\end{center}\n   \\caption{The effect of nonmaximum suppression on a blurred vertical line.}\n\t\\label{fig:nonmaximum_suppression}\n\\end{figure}\n\n\\noindent\n\\section*{Stage 5: Hysteresis}\n\nFigure~\\ref{fig:sample_stage5} shows the end result of the hysteresis stage. The goal of the hysteresis stage is to remove pixels that do not belong to an edge and weak edges altogether. This stage uses two user-defined thresholds: the high threshold and the low threshold. The hysteresis algorithm examines each pixel to determine whether: \n\n\\begin{enumerate}\n\\item the pixel exceeds the high threshold, or\n\\item the pixel exceeds the low threshold value and there exists at least one adjacent pixel (horizontally, vertically, or diagonally) that exceeds the high threshold.\n\\end{enumerate}\n\nIf at least one of the two criteria are met, the pixel is preserved. Otherwise, the pixel is removed by turning it black.\n \n~\\\\\n~\\\\\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_stage5_hysteresis.png}\n   \\end{center}\n   \\caption{The sample input image after the hysteresis stage.}\n\t\\label{fig:sample_stage5}\n\\end{figure}\n\n\\newpage\n\\section*{Part I}\n\nWrite a C++-language program that implements the five stages of the canny edge detector as described in the preceding sections. Start with the skeleton code provided in \\textit{/design\\_files/part1/}, which contains functionality for loading and storing 24-bit color BMP image files. Once a 24-bit color image is loaded into memory, your code should transform the pixels according to the five stages, then store the resulting edge-detected image. The skeleton also contains code that measures the runtime of your program, which we will use to compare with the OpenCL version. Test your program on the sample BMP \nimages provided in \\textit{/design\\_files/}\n\n\\section*{Part II}\n\nBefore we proceed with implementing a Canny edge detector using OpenCL, let us devise an efficient memory architecture for\nstoring the pixel values as they undergo transformations at each Canny stage. Recall that you have two types of memory at your disposal: global memory outside \nthe FPGA, and local memories inside the FPGA. The host program provides input data to the accelerator by placing it in global memory.\nSince global memory accesses are slow, your accelerator should cache the required pixels into local memory before using them.\nThe question then, is how to configure the FPGA's local memory resources to best cache the pixels. \n\nTo determine the best memory configuration, let us consider the pixel usage pattern for box operations.\nNote that the Gaussian smoothing, Sobel operator, non-max suppression, and hysteresis stages of the detector are all \ntypes of box operations, as they work on a box (or frame) of pixels to determine each output pixel. \nFigure~\\ref{fig:box_operation} depicts a 3x3 box operation (such as the 3x3 sobel operation) on three adjacent pixels of a 10-pixel-wide image. \nNotice that there is significant overlap (6 pixels) in the frames of successive operations.\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_box_operation}\n   \\end{center}\n   \\caption{A 3x3 box operation on three adjacent pixels of a 10-pixel-wide image.}\n\t\\label{fig:box_operation}\n\\end{figure}\n\nTo take advantage of the overlap in successive frames of box operations, we will use the FPGA's local memory resources to construct \nthe shift register design shown in Figure~\\ref{fig:shift_register}. The figure shows the shift register design for a 3x3 box operation that\nworks on 10-pixel wide images, but the idea can be extended for arbitrary box sizes and image widths.\nOnce a sufficient number of pixels have been loaded, the shift register provides a new 3x3 frame for the box operation at every cycle by simply\nshifting in a new pixel and shifting out the oldest pixel which is no longer be used.\n\n\\begin{figure}[H]\n   \\begin{center}\n       \\includegraphics[scale = 0.85]{figures/fig_shift_register}\n   \\end{center}\n   \\caption{The shift register for 3x3 box operations on 10-pixel wide images providing 3 frames over 3 cycles.}\n\t\\label{fig:shift_register}\n\\end{figure}\n\nHow many shift registers will you require for your canny edge detector? How large should each of these shift registers be, given that\nyour circuit works on images that are 720 pixels wide? How many pixels must be loaded into each shift register before the corresponding box operation\ncan start? Using such a shift register design requires you to zero pad the input image before \nshifting in its pixels, to properly operate on the boundaries of the image. \nWhy is zero padding necessary, and what is the necessary padding size for a given box size?\n\n\n\\section*{Part III}\n\nCreate an OpenCL application that implements the five stages of the canny edge detector.\nUse shift registers to hold the pixels as they undergo the Canny stages, and apply the box operations on the pixels\nwhile they are in flight through the shift registers. The shift registers should be the minimum length necessary to hold\nrequired pixels.\nWhen operating in its steady state, your accelerator should have a throughput of one pixel per clock cycle.\nThe accelerator is considered to be in its steady state when its shift registers are full. \nFor simplicity, do not zero pad the boundaries of the input image and accept some error along the boundary edge pixels.\nYour application must be able to operate on images that are 720 pixels wide with variable height.\nStart with the skeleton code provided in \\textit{/design\\_files/part3/}.\n\n~\\\\\nThe shift-register design methodology requires the use of Intel FPGA SDK for OpenCL's ability to infer shift registers from \nyour OpenCL code. This feature is described in Section \\textit{Inferring a Shift Register} of the document \\textit{Intel FPGA SDK for OpenCL Programming Guide}.\n\n\n\\input{\\CommonDocsPath/copyright.tex}\n\\end{document}\n", "meta": {"hexsha": "660472ab40961c66fa00d3d8c433ca14482ca390", "size": 13554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/doc/opencl_lab2.tex", "max_stars_repo_name": "fpgacademy/Lab_Exercises_OpenCL", "max_stars_repo_head_hexsha": "923005e0f727cfd922d3904ad21a47faa86c7a51", "max_stars_repo_licenses": ["MIT"], "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/doc/opencl_lab2.tex", "max_issues_repo_name": "fpgacademy/Lab_Exercises_OpenCL", "max_issues_repo_head_hexsha": "923005e0f727cfd922d3904ad21a47faa86c7a51", "max_issues_repo_licenses": ["MIT"], "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/doc/opencl_lab2.tex", "max_forks_repo_name": "fpgacademy/Lab_Exercises_OpenCL", "max_forks_repo_head_hexsha": "923005e0f727cfd922d3904ad21a47faa86c7a51", "max_forks_repo_licenses": ["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.2, "max_line_length": 1093, "alphanum_fraction": 0.7599232699, "num_tokens": 3495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115012, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6352105304754787}}
{"text": "\\section{Exercises in Simulation}\\label{S:xsSimulation}\n\\begin{ExerciseList}\n\\Exercise Suppose the continuous RV $X$ has PDF:\n\\[\nf_X(x) = \\left(\\pi(1+x^2) \\right)^{-1}\n\\]\nDevise an algorithm to transform samples from $\\uniform(0,1)$ RV to those from $X$. Present your answer as pseudo-code.\n\\Answer\nThis is nothing but the inversion sampler for the standard Cauchy RV $X$.\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "368c7b9fa59257f79293e922a58befd0e831ca2b", "size": 393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInSimulation.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/ExsInSimulation.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/ExsInSimulation.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": 32.75, "max_line_length": 119, "alphanum_fraction": 0.7353689567, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.635210528423082}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Debugging your Neural Nets and checking your Gradients}\n\\author{Rishit Dagli}\n\\date{April 2020}\n\n\\begin{document}\n\nNote this only contains major formulas and notes, the complete article could be found here - https://medium.com/@rishit.dagli/debugging-your-neural-nets-and-checking-your-gradients-f4d7f55da167\n\n\\maketitle\n\\section{Introduction}\nThis document contains a brief and all the major formulas discussed in my blog \"Debugging your Neural Nets and checking your Gradients\"\n\n\\maketitle\n\\section{Double sided derivatives}\n\nA formula derived to compute double sided derivative\n$$\\frac{f(\\theta + \\epsilon)-f(\\theta - \\epsilon)}{2 \\cdot \\epsilon} \\approx g(\\theta)$$\n\nWorking thee double sided derivative with example numbers\n$$\\frac{(1.01)^3  - (0.99)^3}{2 \\cdot 0.01} = 3.0001$$\n\nActual derivative for $f(\\theta ^ 3)$\n$$g(\\theta) = 3 \\cdot \\theta ^2 = 3$$\n\nOne sided derivative\n$$g(\\theta) = 3.0301$$\n\nComparing methods\n\\vspace{10}\n\n1. One sided derivative\n\nApproximation error = $0.0301$\n\\vspace{5}\n\n2. Double sided derivative\n\nApproximation error = $0.0001$\n\n\\maketitle\n\\section{Going a bit deeper}\n\n$$f^{'}=\\lim_{\\epsilon \\to 0} \\frac{f(\\theta + \\epsilon)-f(\\theta - \\epsilon)}{2 \\cdot \\epsilon} \\approx g(\\theta)$$ \n\niff $\\lim_{\\epsilon \\to 0}$\n\\vspace{5}\n\nif $\\epsilon \\neq 0$ then $error = O(\\epsilon ^2)$\n\\vspace{5}\n\nAgain $\\epsilon$ is a very small number of course less than 1, so $\\epsilon >> \\epsilon ^2$\n\nThe error function in case of double sided approach would be\n$$error = O(\\epsilon ^2)$$\n\nAnd for single sided approach it would be\n$$error = O(\\epsilon)$$\n\n\\maketitle\n\\section{Gradient Checking}\n\nConcatenate all $w^{[i]}$ and $b^{[i]}$ into one single huge vector called $\\theta$\n\nSo, now our cost function\n$$J(w^{[1]}, b^{[1]}, w^{[3]} ... w^{[n]}, b^{[n]}) = J(\\theta) \\hspace{20} \\cdot\\cdot\\cdot\\cdot\\cdot(*)$$\n\nNow you can also write \n$$J(\\theta) = J(\\theta_1, \\theta_2, \\theta_3 ... \\theta_n)$$\n\nExample for single iteration of $\\theta_5$\n$$d \\theta^{[5]} _{approx.} = \\frac{J(\\theta_1, \\theta_2 ... \\theta_5 + \\epsilon ... \\theta_n) - J(\\theta_1, \\theta_2 ... \\theta_5 - \\epsilon ... \\theta_n)}{2 \\cdot \\epsilon}$$\n\nConsidering the double sided discussion earlier\n$$d \\theta^{[5]} _{approx.} = \\frac{J(\\theta_1, \\theta_2 ... \\theta_5 + \\epsilon ... \\theta_n) - J(\\theta_1, \\theta_2 ... \\theta_5 - \\epsilon ... \\theta_n)}{2 \\cdot \\epsilon} \\approx d \\theta^{[i]} = \\frac{\\partial J}{\\partial \\theta_5}$$\n\nHaving this clear to us we can now repeat the same process not just for θ₅ but for all $i$ such that $i \\in (1, n)$ . So a pseudo Python code for this would look something like this-\n\n\\vspace{10}\nfor i in range(1, n+1):\n$$d \\theta^{[i]} _{approx.} = \\frac{J(\\theta_1, \\theta_2 ... \\theta_i + \\epsilon ... \\theta_n) - J(\\theta_1, \\theta_2 ... \\theta_i - \\epsilon ... \\theta_n)}{2 \\cdot \\epsilon}$$\n\n\\maketitle\n\\section{Approaching an outcome}\n\nComputing similarity\n$$\\frac{||d\\theta_{approx.} - d\\theta||_2}{||d\\theta_{approx.}||_2 + ||d\\theta||_2}$$\n\n\\maketitle\n\\section{Implementing in practice}\n\n\\begin{table}[]\n\\begin{tabular}{ll}\nDifference                               & Comments                                             \\\\\n                \\\\\n                \\\\\n\\textless{}= 10\\textasciicircum{}\\{-7\\}  & Keep up the good work, you are doing just wonderful! \\\\\n                \\\\\n10\\textasciicircum{}\\{-5\\}               & Okay, Double check components of my vectors          \\\\\n                  \\\\\n                                         & and check that none of the components are too large  \\\\\n                                                        \\\\\n=\\textgreater 10\\textasciicircum{}\\{-3\\} & Something to worry about, there might be a bug      \n\\end{tabular}\n\\end{table}\n\\end{document}\n", "meta": {"hexsha": "c69104c3446244af95edae26d0fbc1f076b2bbff", "size": 3796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "Rishit-dagli/Debugging-Neural-Nets", "max_stars_repo_head_hexsha": "fcc9666c8f3b285b6b0bedf58df1f731246fe837", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-13T10:13:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T03:49:37.000Z", "max_issues_repo_path": "main.tex", "max_issues_repo_name": "Rishit-dagli/Debugging-Neural-Nets", "max_issues_repo_head_hexsha": "fcc9666c8f3b285b6b0bedf58df1f731246fe837", "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": "main.tex", "max_forks_repo_name": "Rishit-dagli/Debugging-Neural-Nets", "max_forks_repo_head_hexsha": "fcc9666c8f3b285b6b0bedf58df1f731246fe837", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-15T14:12:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-15T14:12:31.000Z", "avg_line_length": 34.8256880734, "max_line_length": 238, "alphanum_fraction": 0.6319810327, "num_tokens": 1170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.6352018092514551}}
{"text": "Essential programming concepts and data structures are described in this chapter. The rest of the thesis relies on these terms.\n\n\\section{Related Data Structures}\n\n\\subsection{Binary Search Tree}\n\nA binary search tree is a data structure that implements \\findop, \\insertop, and \\removeop operations on a set of keys. Key~$K$ can be of any type, that has a total order. Throughout the thesis, trees with distinct keys are discussed, although of course, it is not the necessary condition.\n\nA binary tree (not to be confused with a binary search tree) consists of nodes. A node~$N$ consists of a key (defined as~\\func{key}{N}) and two references to other nodes~-- left child (defined as~\\func{left}{N}) and right child (defined as~\\func{right}{N}). A reference may contain a link to an existing node or a special value $nil$, that means that the reference is empty. A node that contains a link to a child is called a \\emph{parent} of this child node. Nodes may contain other attributes as well, but those are not substantial for this explanation. A node that has no children (\\(\\func{left}{N} = nil \\land \\func{right}{N} = nil\\)) is called a \\emph{leaf}.\n\nFrom the perspective of the graph theory, the binary tree is a simple oriented acyclic graph, where vertices are represented as nodes and edges are represented as links between a node and its left and right children. Every vertex in such graph has at most one incoming edge, i.e. every node can have at most one parent. Moreover, only one node has no parent~-- this node is called the \\emph{root} of a binary tree. The length of the longest path from any leaf to the root is known as the \\emph{height} of a binary tree. The \\emph{subtree} with a root in $N$ defined as $N$ and a set of nodes that can be reached from $N$ by child links.\n\nA binary \\emph{search} tree (\\emph{BST}) is a binary tree that satisfies the following condition: for each $N$, subtrees with the root in \\func{left}{N} and with the root in \\func{right}{N} contain only nodes with keys, that are less or equal than \\func{key}{N} and larger or equal than \\func{key}{N}, respectively. Using this property, it is possible to implement a fast lookup of a key $K$ in a binary search tree (see \\Cref{alg:bst_find}).\n\n%\\begin{float}{tbp}\n\\begin{algorithm}[t]\n\\caption{Lookup in $BST$}\\label{alg:bst_find}\n\\begin{algorithmic}[1]\n  \\Procedure{Find}{$root,K$}\\Comment{The node with key = $K$ or $nil$}\n    \\State $node\\gets root$\n    \\While{$node\\not= nil$}\n    \\If{$K = \\func{key}{node}$}\n      \\State \\textbf{return} $node$\n    \\ElsIf{$K < \\func{key}{node}$}\n      \\State $node \\gets \\func{left}{node}$\n    \\Else \\Comment{$K > \\func{key}{node}$}\n      \\State $node \\gets \\func{right}{node}$\n    \\EndIf\n    \\EndWhile\n    \\State \\textbf{return} $nil$\\Comment{The node was not found}\n  \\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n%\\end{float}\n\nThe complexity of this search algorithm is~$\\mathcal{O}(\\func{height}{T})$ (assuming that key comparison takes~$\\mathcal{O}(1)$). Furthermore, two remaining operations of a binary search tree, \\insertop and \\removeop, are implemented in the same fashion, and both of those operations have complexity~$\\mathcal{O}(\\func{height}{T})$ as well. Their implementation is described in detail in~\\cite[p.~327]{sedgewick}.\n\nThe tree height can vary between $\\mathcal{O}(\\func{size}{T})$,\n and $\\mathcal{O}(\\log(\\func{size}{T}))$ in case of a complete binary tree~\\cite{complete_bt}, where~$\\func{size}{T}$ is the count of nodes in~$T$. BST will maintain optimal operation time only if its structure is close to a complete binary tree and the height is bounded by $c \\times \\log(\\func{size}{T})$, where $c$ is a constant factor greater or equal~$1$.\n\n To keep the height logarithmic, even in a worst-case scenario, the \\emph{tree rebalancing} has been invented. The idea is that a tree keeps track of its structure and if it is not optimal, then the rebalancing is applied to restore optimal structure. The rebalancing can be achieved with the \\emph{tree rotation}\\cite[p.~435]{sedgewick}~-- the operation, that swaps a node with its parent in a way, that preserves the $BST$ property.\n\n\n\\subsection{AVL Tree}\n\nAVL tree was invented in 1962 by Georgy Adelson-Velsky and Evgenii Landis\\cite{avl_tree}. It is a classic example of a self-balancing $BST$. In fact, the height of the AVL tree is never greater than $1.4405\\times \\log(\\func{size}{T}) - 0.3277$ \\cite[p.~460]{knuth3}.\n\nSelf-balancing is achieved with the following approach: every node holds the difference between the heights of its left and right subtrees; this difference is called \\emph{balance factor}.\n\\emph{AVL property} requires the balance factor of every node to be in range of values $-1$, $0$ and~$1$.\n\nAfter every operation, that modifies the tree structure~-- \\insertop and \\removeop, balance factors are updated.\nIf at any step the balance factor happens to be $-2$ or $2$, a rotation or a double rotation is applied.\nThe rotation adjusts the heights of the left and right subtrees and, consequently, restores the AVL property. The exact AVL tree implementation is described in \\cite[p.~458]{knuth3}.\n\n\\subsection{Splay Tree}\n\\label{sssec:splay}\nAnother approach on tree balancing is presented in the Sleator and Tarjan work\\cite{splay_tree}~-- ``The efficiency of splay trees comes not from an explicit structural constraint, as with balanced trees, but from applying a simple restructuring heuristic, called splaying, whenever the tree is accessed.'' Term \\emph{splaying} stands for the process of using rotations (similar to ones in the AVL tree) to bring the last accessed node to the root.\n\nSleator and Tarjan proved that by using this approach, all three basic operations (\\findop, \\insertop and \\removeop) have a logarithmic time bound. Another benefit of splaying is that the most frequently accessed items tend to gather near the root, therefore improving access speed, especially on skewed input sequences~-- the sequences, in which only a small number of items are accessed often while other items occur rarer. This property is exploited in the Splay eviction policy (\\Cref{sssec:spolicy}).\n\nEven though splay trees show several interesting theoretical properties, in practice they are outperformed by more conventional BSTs, like AVL or Red-Black tree\\cite{splay_overview} (the performance evaluation of \\numdbname (\\Cref{sec:secanalysis}) reaffirms this statement). This is due to the fact that in the splay tree the structure of the tree is altered on every operation, including find operation, while AVL, for instance, modifies the tree only during insertions and removals.\n\nThe typical use scenario for those data structures is a scenario, where a vast majority of operations is the search operation, while updates are not so often. AVL and Red-Black trees happen to be faster because they execute fewer instructions per find operation. Moreover, they do not make any writes to memory during the lookup, and, as a consequence, there is lower load on the memory bus and the system cache.\n\nFurther researches on splay trees were focused in the main on how to reduce the number of rotations during splaying. An extensive overview of those optimizations is provided in \\cite{splay_overview}. One of the described techniques, the partial splaying is a modification of a conventional splay tree, where every node contains a counter that denotes a total count of accesses to this node. As usual, splaying is performed on every access, but the node is splayed only until its access count is less than the access count of its parent.\n\nW. Klostermeyer showed that this modification does not gain any noticeable advantage over a standard splay tree \\cite{partial_splaying}. However, partial splaying and other derived modifications can have some interesting properties specifically in application to a numerical database. It will be discussed in \\Cref{ch:alt}.\n\n\\subsection{Hash Table}\n\nA hash table is another popular data structure that implements dictionary abstract data type. It uses the entirely different approach on item storage and lookup. A hash table allocates a contiguous array $A$, which size is bounded by the expected number of items to be stored, often multiplied by the \\mbox{\\emph{load~factor}~$\\alpha$}. The items are stored in $A$.\n\nFirstly, let’s look at the simplified case: the key $K$ that is used in a hash table is of an integer type. Having $A$, $K$ and the value $V$, associated with $K$, it is possible to use a remainder of the division of $K$ by the size of $A$ as an index in $A$. Then, $V$ will be stored in $A$ at this index. This approach would give the best performance possible, as the $V$ can be retrieved immediately and \\emph{the~lookup time does not depend on~the~total count of~items} in the hash table. However, since the $modulo$ operation has been used, there can be several keys that point at the same index in $A$. This circumstance is called \\emph{collision}.\n\nTo deal with a collision, it is necessary to store $K$ itself together with $V$, so that in case of a collision it would be possible to tell if the stored $V$ is actually associated with the $K$ or another $K'$, that collides with $K$. Secondly, one must pick a strategy on how to deal with the case when two different keys, $K_1$ and $K_2$, that point at the same index are inserted. There are two main approaches:\n\\begin{description}\n\\item[Separate chaining (open hashing)]-- each element in $A$ is a linked list (or another data structure), that stores all pairs $\\langle K, V\\rangle$ that collides.\n\\pagebreak\n\\item[Linear probing (closed hashing)]-- if during insertion of $K$ in $A$ at the index $i$ a collision occurs ($i$ is already occupied), a special function $F$ is used to determine the second index at which $K$ can be inserted. If it is also occupied, 3rd and all consequent positions, generated by $F$, are used to try to insert the element.\n\\end{description}\n\nThe approach described above can be generalized on keys of any type $T$. It is achieved with the help of a \\emph{hash function}. This function takes an argument of type $T$ and maps it to an integer, called \\emph{hash}. This function must satisfy two properties:\n\n\\begin{block-description}\n\\blockitem[Determinism]-- it should \\emph{always} map the same input to the same hash.\n\\blockitem[Uniformity]-- if used with a uniformly generated random sequence of objects on input, the hash function should produce a uniformly distributed sequence of hashes.\n\\end{block-description}\n\nIn \\cite[p.~464]{sedgewick} Sedgewick and Wayne provide the detailed explanation of collision avoidance strategies as well as general information about hash tables. More information about hash function properties and hash function construction is presented in \\cite{knott}.\n\n\\section{Thread Synchronization}\n\n\n\n\\subsection{Coarse-grained Locking}\n\\label{sec:cgl}\nA trivial way to parallelize a sequential data structure is to eliminate a concurrent access at all. It can be achieved with a single mutual exclusion lock~-- \\emph{mutex}.\nWhile a thread holds a mutex, no other threads can lock the same mutex.\n\nThe sequential data structure is wrapped into the helper type, that locks the mutex in the beginning of every operation and releases it in the end, so that only one thread can access the data structure at a time, no matter how many threads are involved.\nThis approach is called the \\emph{coarse-grained locking}, in contrast with the \\emph{fine-grained locking}, where many locks are used and each lock protects only a part of the data structure, so other threads can freely access other parts.\n\nPros of this approach is a very trivial implementation and the absence of any special requirements on the underlying data structure. However, coarse-grained locking is only suitable when a data structure has a support role in the program and is used occasionally. If the data structure is the key element of the application, then a single lock becomes the bottleneck in the software, drastically decreasing program scalability. In this case one should use more sophisticated parallelization approaches.\n\n\\subsection{Binning}\n\\label{sec:pre_bin}\nThe evolution of coarse-grained locking is the \\emph{binning}. The main drawback of the previous approach is that a single lock becomes the main point of contention between threads. One way to cope with this is to increase the number of locks. In contrast with the fine-grained locking, the binning does not involve any modifications of the underlying container.\n\nFirstly, the numbers of bins~-- independent data structure instances~-- is chosen. Then a mapping between the item domain and a bin number is introduced. The mapping should yield a uniform distribution of mapped values. Every item is stored only in its assigned bin. Every bin has its own mutex, therefore the access to every bin is serialized. But since items are mapped uniformly, it is expected to produce much less contention than in case of a single lock.\n\n\\subsection{Fine-grained Locking}\n\\label{sec:fgl}\nThe fine-grained locking usually offers better scalability, than the previously discussed approaches. Instead of a single lock, many mutexes are used simultaneously. Every mutex protects its part of data. The contention between threads is lower as it is unlikely that several threads will access the same portion of data at the same time.\n\nHowever, this is true only if every portion has the same probability of being accessed (like in a concurrent hash table). In some data structures, typically binary trees, there are some nodes that are accessed (and are locked before access) oftener than others, e.g. the root in a binary tree.\n\n\\emph{Substantial modifications} got to be made to the data structure to integrate the fine-grained locking. Sometimes the overhead added by this approach is so big, that it brings to naught any potential speed-up. Fine-grained locking is not a silver bullet, but usually it offers a reasonable trade-off between implementation complexity and application scalability.\n", "meta": {"hexsha": "f734d730b5cb1acf75079c310528f29e66d45819", "size": 14023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Text/tex/1_Preliminaries.tex", "max_stars_repo_name": "metopa/bachelors_thesis", "max_stars_repo_head_hexsha": "7937368e8d34eb68b1e90a6097737d48ca72c174", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Text/tex/1_Preliminaries.tex", "max_issues_repo_name": "metopa/bachelors_thesis", "max_issues_repo_head_hexsha": "7937368e8d34eb68b1e90a6097737d48ca72c174", "max_issues_repo_licenses": ["MIT"], "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/tex/1_Preliminaries.tex", "max_forks_repo_name": "metopa/bachelors_thesis", "max_forks_repo_head_hexsha": "7937368e8d34eb68b1e90a6097737d48ca72c174", "max_forks_repo_licenses": ["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.8389830508, "max_line_length": 663, "alphanum_fraction": 0.7739428082, "num_tokens": 3317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6352018078124329}}
{"text": "\\section{Classifying spaces of groups}\\label{classifying-g-bundles}\n%I learned this attitude towards classifying spaces from Segal.\n%An article is on the website.\n%\nThe constructions of the previous sections can be summarized in a single\ndiagram:\n\\begin{equation*}\n    \\xymatrix{\n\t\\Cat\\ar[r]^{\\text{nerve}} & s\\Set\\ar[d]^{|-|}\\\\\n\t\\mathbf{Gp}\\ar@{^(->}[u]\\ar[r]_{B} & \\Top\n    }\n\\end{equation*}\nThe bottom functor is defined as the composite along the outer edge of the\ndiagram. The space $BG$ for a group $G$ is called the \\emph{classifying space\nof $G$}. At this point, it is far from clear what $BG$ is classifying. The goal\nof the next few sections is to demystify this definition.\n\n\\begin{lemma}\\label{conjugation-homotopic}\n    Let $G$ be a group, and $g\\in G$.  Let $c_g:G\\to G$ via $x\\mapsto\n    gxg^{-1}$.  Then the map $Bc_g:BG\\to BG$ is homotopic to the identity.\n\\end{lemma}\n\\begin{proof}\n    The homomorphism $c_g$ is a functor from $G$ to itself. It suffices to\n    prove that there is a natural transformation $\\theta$ from the identity to\n    $c_g$. This is rather easy to define: it sends the only object to the only\n    object: we define $\\theta_\\ast:\\ast\\to \\ast$ to be the map given by\n    $\\ast\\xrightarrow{g}\\ast$ specified by $g\\in \\Hom_G(\\ast,\\ast) = G$. In\n    order for $\\theta$ to be a natural transformation, we need the following\n    diagram to commute, which it obviously does:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    \\ast\\ar[d]_1\\ar[r]^g & \\ast\\ar[d]^{gxg^{-1}}\\\\\n\t    \\ast\\ar[r]_{g} & \\ast.\n\t    }\n    \\end{equation*}\n\\end{proof}\nGroups are famous for acting on objects. Viewing groups as categories allows\nfor an abstract definition a group action on a set: it is a functor $G\\to\n\\Set$. More generally, if $\\cc$ is a category, an action of $\\cc$ is a functor\n$\\cc\\xrightarrow{X}\\Set$. We write $X_c = X(c)$ for an object $c$ of $\\cc$.\n\\begin{definition}\n    The ``translation'' category $X\\cc$ has objects given by\n    $$\\mathrm{ob}(X\\cc) = \\coprod_{c\\in \\cc}X_c,$$\n    and morphisms defined via $\\Hom_{X\\cc}(x\\in X_c, y\\in X_d) = \\{f:c\\to\n    d:f_\\ast(x) = y\\}$.\n\\end{definition}\nThere is a projection $X\\cc\\to \\cc$. (For those in the know: this is a special\ncase of the Grothendieck construction.)\n\\begin{example}\n    The group $G$ acts on itself by left translation. We will write\n    $\\widetilde{G}$ for this $G$-set. The translation category $\\widetilde{G}G$\n    has objects as $G$, and maps $x\\to y$ are elements $yx^{-1}$. This category\n    is ``unicursal'', in the sense that there is exactly one map from one\n    object to another object. Every object is therefore initial and terminal,\n    so the classifying space of this category is trivial by the discussion at\n    the end of \\S \\ref{classifying-space-properties}. We will denote by $EG$\n    the classifying space $B(\\widetilde{G}G)$. The map $\\widetilde{G}G\\to G$\n    begets a canonical map $EG\\to BG$.\n\\end{example}\nThe $G$ also acts on itself by right translation. Because of associativity, the\nright and left actions commute with each other. It follows that the right\naction is equivariant with respect to the left action, so we get a right action\nof $G$ on $EG$.\n\\begin{claim}\n    This action of $G$ on $EG$ is a principal action, and the orbit projection\n    is $EG\\to BG$.\n\\end{claim}\nTo prove this, let us contemplate the set $N(\\widetilde{G}G)_n$. An element is\na chain of composable morphisms. In this case, it is actually just a sequence\nof $n+1$ elements in $G$, i.e., $N(\\widetilde{G}G)_n = G^{n+1}$. The right\naction of $G$ is simply the diagonal action. We claim that this is a free\naction. More precisely:\n\\begin{lemma}[Shearing]\n    If $G$ is a group and $X$ is a $G$-set, and if $X\\times^\\Delta G$ has the\n    diagonal $G$-action and $X\\times G$ has $G$ acting on the second factor by\n    right translation, then $X\\times^\\Delta G\\simeq X\\times G$ as $G$-sets.\n\\end{lemma}\n\\begin{proof}\n    Define a bijection $X\\times^\\Delta G\\mapsto X\\times G$ via $(x,g)\\mapsto\n    (xg^{-1},g)$. This map is equivariant since $(x,g)\\cdot h = (xh, gh)$,\n    while $(xg^{-1}, g) \\cdot h = (xg^{-1}, gh)$. The element $(xh, gh)$ is\n    sent to $(xh(gh)^{-1}, gh)$, as desired.\n    The inverse map $X\\times G\\to X\\times^\\Delta G$ is given by $(x,g)\\mapsto\n    (xg, g)$.\n\\end{proof}\nWe know that $G$ acts freely on $N(\\widetilde{G}G)_n$, soo a nonidentity group\nelement is always going to send a simplex to another simplex. It follows that\n$G$ acts freely on $EG$.\n\nTo prove the claim, we need to understand the orbit space. The shearing lemma\nshows that quotienting out by the action of $G$ simply cancels out one copy of\n$G$ from the product $N(\\widetilde{G}G) = G^n$. In symbols:\n$$N(\\widetilde{G} G)/G\\simeq G^n\\simeq (NG)_n.$$\nOf course, it remains to check the compatibility with the face and degeneracy\nmaps. We will not do this here; but one can verify that everything works out:\nthe realization is just $BG$!\n\nWe need to be careful: the arguments above establish that $EG/G \\simeq BG$ when\n$G$ is a finite group. The case when $G$ is a topological group is more\ncomplicated. To describe this generalization, we need a preliminary categorical\ndefinition.\n\nLet $\\cc$ be a category, with objects $\\cc_0$ and morphisms $\\cc_1$. Then we\nhave maps $\\cc_1\\times_{\\cc_0}\\cc_1\\xrightarrow{\\text{compose}}\\cc_1$ and two\nmaps (source and target) $\\cc_1\\to \\cc_0$, and the identity $\\cc_0\\to\\cc_1$.\nOne can specify the same data in any category $\\cd$ with pullbacks. Our\ninterest will be in the case $\\cd = \\Top$; in this case, we call $\\cc$ a\n``category in $\\Top$''.\n\n%The story described above works just as well if we were to consider functors\n%$X:\\cc\\to \\Top$ instead of $X:\\cc\\to \\Set$. Let $G$ be a topological group. Define $\\widetilde{G}$ to be a category in $\\Top$.\n%\n%An example is a topological group -- that's a category in $\\Top$.\nLet $G$ be a topological group acting on a space $X$. We can again define $XG$,\nalthough it is now a category in $\\Top$. Explicitly, $(XG)_0 = X$ and $(XG)_1 =\nG\\times X$ as spaces. The nerve of a topological category begets a simplicial\nspace. In general, we will have\n$$(N\\cc)_n = \\cc_1\\times_{\\cc_0}\\cc_1\\times\\cdots\\times_{\\cc_0}\\cc_1.$$\nThe geometric realization functor works in exactly the same way, so the\nrealization of a simplicial space gets a topological space.\n%\n%You need to put some mild topological conditions on the group for the theorem we proved above to be true.\n%Again, we have $\\widetilde{G}$ with $G$ acting on it.\n%Again, we let $EG = B\\widetilde{G}G$.\nThe above discussion passes through with some mild topological conditions on\n$G$ (namely, if $G$ is an absolute neighborhood retract of a Lie group); we\nconclude:\n\\begin{theorem}\n    Let $G$ be an absolute neighborhood retract of a Lie group. Then $EG$ is\n    contractible, and $G$ acts from the right principally. Moreover, the map\n    $EG\\to BG$ is the orbit projection.\n\\end{theorem}\nA generalization of this result is:\n\\begin{exercise}\n    Let $X$ be a $G$-set. Show that\n    $$EG\\times_G X \\simeq B(XG).$$\n\\end{exercise}\n", "meta": {"hexsha": "e140429ab0866fbf6d5d942db54ab5e38a9442ea", "size": 7037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-58-bundles-classifying-spaces.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-58-bundles-classifying-spaces.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-58-bundles-classifying-spaces.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.9927536232, "max_line_length": 127, "alphanum_fraction": 0.6983089385, "num_tokens": 2217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.6352018063734105}}
{"text": "% Preamble\n\\documentclass[11pt]{PyRollDocs}\n\\usepackage{textcomp}\n\n\\addbibresource{refs.bib}\n\n% Document\n\\begin{document}\n\n    \\title{The Wusatowski Spreading PyRoll Plugin}\n    \\author{Max Weiner}\n    \\date{\\today}\n\n    \\maketitle\n\n    This plugin provides a spreading modelling approach with Wusatowski's formula for flat rolling, adapted on groove rolling by an equivalent rectangle approach.\n\n\n    \\section{Model approach}\\label{sec:model-approach}\n\n    \\subsection{Wusatowski's spread equation}\\label{subsec:wusatowski's-spread-equation}\n\n    \\textcite{Wusatowski1969} proposed \\autoref{eq:wusatowski} for estimation of spreading in flat rolling,\n    where $\\gamma = \\frac{h_1}{h_0}$ is the compression. $h$ and $b$ are height and width of the workpiece with the indices\n    0 and 1 denoting the incoming respectively the outgoing profile. $a$, $c$, $d$ and $f$ are correction\n    coefficients for temperature, velocity, material and friction, respectively.\n\n    \\begin{equation}\n        \\beta = \\frac{b_1}{b_0} = a \\times c \\times d \\times f \\times \\gamma^{-w}\n        \\label{eq:wusatowski}\n    \\end{equation}\n\n    \\noindent The velocity coefficient $c$ can be assumed as below in dependence on the velocity $v$.\n\n    \\begin{equation}\n        c = \\left(-0.002958 + 0.00341 \\gamma \\right) v + 1.07168 - 0.10431 \\gamma\n        \\label{eq:velocity-coefficient}\n    \\end{equation}\n\n    $w$ is the spread exponent, many different expressions were given by various authors for its value.\n    The original expression by \\textcite{Wusatowski1969} is given in \\autoref{eq:exponent}, where $R$ is the roll radius.\n\n    \\begin{equation}\n        w = 10^{ \\num{-1.269} \\left( \\frac{h_0}{2 R} \\right)^{\\num{0.56}} \\frac{b_0}{h_0} }\n        \\label{eq:exponent}\n    \\end{equation}\n\n    \\subsection{Equivalent rectangle approach}\\label{subsec:equivalent-rectangle-approach}\n\n    Wusatowskis spreading model~\\cite{Wusatowski1969} was originally built for flat rolling.\n    A common approach for groove rolling is to calculate some equivalent rectangular profile to be able to use flat rolling models~\\cite{Hensel1978, Spittel1984}.\n    \\autoref{fig:equivalent_rectangle} shows 3 variants of calculating an equivalent rectangle of a profile.\n\n    \\begin{figure}\n        \\centering\n        \\includegraphics[width=\\linewidth]{equivalent_rectangle}\n        \\caption{Three methods of defining an equivalent rectangle of an oval groove}\n        \\label{fig:equivalent_rectangle}\n    \\end{figure}\n\n    The first variant is to keep the width constant and calculate the height $h'$ so that the cross section $A$ is\n    equal:\n\n    \\[\n        h' = \\frac{A}{b}\n    \\]\n\n    The second variant is to keep the height constant and calculate the width $b'$ so that the cross section $A$ is\n    equal:\n\n    \\[\n        b' = \\frac{A}{h}\n    \\]\n\n    Both represent the geometry of the profile poorly.\n    A better way is to keep the aspect ratio equal as propose by \\textcite{Spittel1984}:\n\n    \\[\n        h'' = \\sqrt{\\frac{A h}{b}}\n    \\]\n\n    \\[\n        b'' = \\sqrt{\\frac{A b}{h}}\n    \\]\n\n    This variant is used in the current implementation.\n    So $h$ and $b$ in Wusatowski's model are replaced with $h''$ and $b''$.\n    In the end, $b_1$ can be obtained from $b_1''$ by:\n\n    \\[\n        b_1 = \\frac{b_1'' h_1}{h_1''}\n    \\]\n\n\n    \\section{Usage instructions}\\label{sec:usage-instructions}\n\n    The plugin can be loaded under the name \\texttt{pyroll\\_wusatowski\\_spreading}.\n\n    An implementation of the \\lstinline{spread} hook on \\lstinline{RollPass} is provided,\n    calculating the spread using the equivalent rectangle approach and Wusatowski's model.\n\n    Several additional hooks on \\lstinline{RollPass} are defined, which are used in spread calculation, as listed in \\autoref{tab:hookspecs}.\n    Base implementations of them are provided, so it should work out of the box.\n    For \\lstinline{wusatowski_exponent} and \\lstinline{wusatowski_velocity_coefficient} the equations~\\ref{eq:exponent} and~\\ref{eq:velocity-coefficient} are implemented.\n    The others default to \\num{1}.\n    Provide your own hook implementations or set attributes on the \\lstinline{RollPass} instances to alter the spreading behavior.\n\n    \\begin{table}\n        \\centering\n        \\caption{Hooks specified by this plugin. Symbols as in \\autoref{eq:wusatowski}.}\n        \\label{tab:hookspecs}\n        \\begin{tabular}{ll}\n            \\toprule\n            Hook name                                     & Meaning                                \\\\\n            \\midrule\n            \\texttt{wusatowski\\_temperature\\_coefficient} & temperature correction coefficient $a$ \\\\\n            \\texttt{wusatowski\\_velocity\\_coefficient}    & velocity correction coefficient $c$    \\\\\n            \\texttt{wusatowski\\_material\\_coefficient}    & material correction coefficient $d$    \\\\\n            \\texttt{wusatowski\\_friction\\_coefficient}    & friction correction coefficient $f$    \\\\\n            \\texttt{wusatowski\\_exponent}                 & spread exponent $w$                    \\\\\n            \\bottomrule\n        \\end{tabular}\n    \\end{table}\n\n    \\printbibliography\n\n\\end{document}", "meta": {"hexsha": "8f96685ffb3fb5bcd0d1aa86af0cfbb2b0a3a1bb", "size": 5130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/docs.tex", "max_stars_repo_name": "pyroll-project/pyroll-wusatowski-spreading", "max_stars_repo_head_hexsha": "902ab86d666b0e9533b36da3cdc9c6ebdef8af53", "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/docs.tex", "max_issues_repo_name": "pyroll-project/pyroll-wusatowski-spreading", "max_issues_repo_head_hexsha": "902ab86d666b0e9533b36da3cdc9c6ebdef8af53", "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/docs.tex", "max_forks_repo_name": "pyroll-project/pyroll-wusatowski-spreading", "max_forks_repo_head_hexsha": "902ab86d666b0e9533b36da3cdc9c6ebdef8af53", "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": 40.3937007874, "max_line_length": 170, "alphanum_fraction": 0.6723196881, "num_tokens": 1366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516188, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6352017868004504}}
{"text": "\\section{Grammar as Network of FSA}\n\nGiven a EBNF grammar where every nonterminal has a unique rule. Any transition labelled with a nonterminal $B$ is a call to the automaton $M_B$.\n\n\\begin{description}\n    \\item[Machine] The FSA of a nonterminal\n    \\item[Automaton] the PDA that accepts $L(G)$\n    \\item[Net] the set of all machines\n\\end{description}\n\nThe machine $M_A$ must be \\emph{normalized}, initial state $0_A$ must have no entering arcs.\n\n\\subsection{Followers of nonterminal}\nGiven a final state of a machine, the \\emph{set of followers} if the set of all the terminal characters that can follow exiting the machine (including $\\dashv$). Given a state $q_A$:\n\\[\n    Ini(q_A) = Ini(L(q_A)) = \\{ a \\in \\Sigma | a\\Sigma^* \\cap L(q_A) \\ne \\emptyset \\}\n\\]\n\n\\textbf{Note}: $Ini$ cannot contain $\\epsilon$, it is empty iff $L(q_A)=\\{\\epsilon\\}$.\nTerminal $a$ is in $Ini(q_A)$ iff:\n\\begin{align*}\n    & \\exists \\text{ arc } q_A \\xrightarrow{a} r_A \\\\\n    & \\exists \\text{ arc } q_A \\xrightarrow{B} r_A \\land a \\in Ini(0_B) \\\\\n    & \\exists \\text{ arc } q_A \\xrightarrow{B} r_A \\land B \\text{ is nullable } \\land a \\in Ini(r_A)\n\\end{align*}\n", "meta": {"hexsha": "f3e84599338c10222bac7a19b65202b243bbd084", "size": 1142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parsing/network-of-fsa.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": "parsing/network-of-fsa.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": "parsing/network-of-fsa.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.9230769231, "max_line_length": 182, "alphanum_fraction": 0.6830122592, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6351778942336018}}
{"text": "\\chapter{Units and Conversions}\n\nAt this point, you are working with a lot of units: grams for weight,\njoules for energy, newtons for force, meters for distance, seconds for\ntime, etc. For each type of measurement, there are several different\nunits; for example, distance can be measured in feet, miles,\nand light-years.\n\n\\begin{mdframed}[style=important, frametitle={Some Equalencies}]\n\n\\begin{tabular}{r | l}\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Distance}}\\\\\n  1 mile & 1.6093 kilometers \\\\\n  1 foot & 0.3048 meters \\\\\n  1 inch & 2.54 centimeters \\\\\n  1 light-year & $9.461 \\times 10^{12}$ kilometers\\\\\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Volume}}\\\\\n  1 milliliter & 1 cubic centimeter \\\\\n  1 quart & 0.9461 liters \\\\\n  1 gallon & 3.7854 liters \\\\\n  1 fluid ounce & 29.6 milliliters \\\\\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Mass}}\\\\\n  1 pound & 0.4535924 kilograms\\\\\n  1 ounce & 0.4535924 grams\\\\\n  1 metric ton & 1000 kilograms \\\\\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Force}}\\\\\n  1 newton & 1 kilogram meter per sec$^2$\\\\\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Pressure}}\\\\\n  1 pascal & 1 newton per square meter \\\\\n  1 bar & 0.98692 atmosphere \\\\\n  1 pound per square inch & 6897 pascals \\\\\n  \\hline\n  \\multicolumn{2}{c}{\\textbf{Energy}}\\\\\n  1 joule & 1 newton meter \\\\\n  1 calorie & 4.184 joules \\\\\n  1 kilowatt-hour & $3.6 \\times 10^{6}$ joules  \\\\\n\\end{tabular}\\index{units table}\n\n(You don't need to memorize these! Just remember that this page is here.)\n\n\\end{mdframed}\n\nIn the metric system, prefixes are often used to express a multiple. Here are the common prefixes:\\index{metric system!prefixes}\n\n\\begin{mdframed}[style=important, frametitle={Common Prefixes for Metric Units}]\n\n\\begin{tabular}{r | l}\ngiga  & $\\times 10^{9}$\\\\\nmega  & $\\times 10^{6}$\\\\\nkilo  & $\\times 10^{3}$\\\\\nmilli  & $\\div 10^{3}$\\\\\nmicro  & $\\div 10^{6}$\\\\\nnano  & $\\div 10^{9}$\\\\\n\\end{tabular}\n\n(These are worth memorizing.)\n\n\\end{mdframed}\n\n\\section{Conversion Factors}\n\nHere is a really handy trick to remembering how to do conversions\nbetween units.\\index{conversion factors}\n\nOften, you will a table like the one above, and someone will ask you\n``How many miles are in 0.23 light-years?''  You know that 1 mile = 1.6093\nkilometers and that 1 light-year is $9.461 \\times 10^{12}$ kilometers.\nHow do you do the conversion?\n\nThe trick is to treat the two parts of the equality as a fraction that equals 1.  That is, you think:\n\n$$\\frac{1 \\text{ miles}}{1.6093 \\text{ km}} = \\frac{1.6093 \\text{ km}}{1 \\text{ miles}} = 1$$\n\nand\n\n$$\\frac{1 \\text{ light-years}}{9.461 \\times 10^{12} \\text{ km}} = \\frac{9.461 \\times 10^{12} \\text{ km}}{1 \\text{ light-years}} = 1$$\n\nWe call these fractions \\textit{conversion factors}.\n\nNow, your problem is\n\n$$0.23 \\text{ light-years} \\times \\textit{ Some conversion factors} = ? \\text{ miles}$$\n\nNote that when you multiply fractions together, things in the numerators can cancel with things in the denominator:\n\n$$\\left( \\frac{31\\pi}{47} \\right) \\left( \\frac{11}{37\\pi}\\right) = \\left(\\frac{31\\cancel{\\pi}}{47}\\right) \\left( \\frac{11}{37\\cancel{\\pi}}\\right) = \\left(\\frac{31}{47} \\right) \\left( \\frac{11}{37} \\right)$$\n\nWhen working with conversion factors, you will do the same with the units:\n\n\\begin{multline*}\n  0.23 \\text{ light-years} \\left( \\frac{9.461 \\times 10^{12} \\text{ km}}{1 \\text{ light-years}} \\right) \\left( \\frac{1 \\text{ miles}}{1.6093 \\text{ km}} \\right) = \\\\\n  0.23 \\text{ \\cancel{light-years}} \\left( \\times \\frac{9.461 \\times 10^{12} \\text{ \\cancel{km}}}{1 \\text{ \\cancel{light-years}}} \\right) \\left( \\frac{1 \\text{ miles}}{1.6093 \\text{ \\cancel{km}}}\\right) = \\frac{(0.23)(9.461 \\times 10^{12})}{1.6093} \\text{ miles}$$\n\\end{multline*}\n\n\\begin{Exercise}[title={Simple Conversion Factors}, label=simple_conversion_factors]\n\n  How many calories are in 4.5 killowatt-hours?\n  \n\\end{Exercise}\n\\begin{Answer}[ref=simple_conversion_factors]\n\n  $$4.5 \\text{ \\cancel{kWh}} \\left( \\frac{3.6 \\times 10^{6} \\text{ \\cancel{joules}}}{1 \\text{ \\cancel{kWh}}} \\right) \\left( \\frac{1 \\text{ calories}}{4.184 \\text{ \\cancel{joules}}}\\right) = \\frac{(4.5)(3.6 \\times 10^6)}{4.184} = 1.08 \\times 10^6 \\text {calories}$$\n  \n\\end{Answer}\n\n\\section{Conversion Factors and Ratios}\n\nConversion factors also work on ratios.  For example, if you are told\nthat a bug is moving 0.5 feet every 120 milliseconds. What is that in\nmeters per second?\n\nThe problem, then is\n\n$$\\frac{0.5 \\text{ feet}}{120 \\text{ milliseconds}} = \\frac{\\text{? m}}{second}$$\n\nSo you will need conversion factors to replace the ``feet'' with ``meters'' and to replace ``milliseconds'' with ``seconds'':\n\n\\begin{multline*}\n\\left(\\frac{0.5 \\text{ \\cancel{feet}}}{120 \\text{ \\cancel{milliseconds}}}\\right) \\left( \\frac{0.3048 \\text{ meters}}{1 \\text{ \\cancel{feet}}} \\right) \\left( \\frac{ 1000 \\text{ \\cancel{milliseconds}}} {1 \\text{ second}}\\right) = \\frac{(0.5)(0.3048)(1000)}{120}\\text{ m/second}\n\\end{multline*}\n\n\\begin{Exercise}[title={Conversion Factors}, label=conversion_factors]\n\nThe hole in the bottom of the boat lets in 0.1 gallons every 2 minutes.  How many milliliters per second is that?\n  \n\\end{Exercise}\n\\begin{Answer}[ref=onversion_factors]\n\n  \\begin{multline*}\n    \\frac{0.1 \\text{ \\cancel{gallons}}}{2 \\text{ \\cancel{minutes}}}\n  \\left( \\frac{3.7854 \\text{ \\cancel{liters}}}{1 \\text{ \\cancel{gallons}}} \\right)\n  \\left( \\frac{1000 \\text{ milliliters}}{1\\text{ \\cancel{liters}}}\\right)\n  \\left( \\frac{1 \\text{ \\cancel{minutes}}}{60 \\text{ seconds}} \\right) = \\\\\n  \\frac{(0.1)(3.7854)(1000)}{(2)(60)} \\text{ ml/second} = 3.1545 \\text{ ml/second}\n  \\end{multline*}\n  \n\\end{Answer}\n\n\\section{When Conversion Factors Don't Work}\n\nConversion factors only work when the units being converted are\nproportional to each other. Gallons and liters, for example are\nproportional to each other: If you have $n$ gallons, you have $n\n\\times 3.7854$ liters.\n\nDegrees celsius and degrees farenheit are \\textit{not} proportional to\neach other.  If your food is $n$ degrees celsius, it is $n \\times\n\\frac{9}{5} + 32$ degrees farenheit.  You can't use conversion factors\nto convert celsius to farenheit.\n", "meta": {"hexsha": "19974b3b705688e8ce15bcc2e3b6331e1acfd9da", "size": 6097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/units_conversions-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/MatterEnergy/units_conversions-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/units_conversions-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": 39.335483871, "max_line_length": 275, "alphanum_fraction": 0.6808266361, "num_tokens": 2100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.6351778930274604}}
{"text": "\\documentclass[twocolumn]{article}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section*{Proof of extremum}\n\\davidsays{I think this section should probably move to supplementary information, if we're going to send to Nature.  It suddenly gets way more mathematical here, and we start introducing Fourier space, etc.}\n\nTo show that a uniform potential gives the highest deliverable capacity, we consider a potential of interaction between guest and substrate $\\V(\\vec r)$ that varies with space.  In this proof we will actually make use of the Fourier transform of this potential:\n\\begin{align}\n    \\Vk \\equiv \\iiint \\V(\\vec r) e^{-i\\vec k\\cdot \\vec r} d\\vec r\n\\end{align}\nThe Fourier transform of a uniform potential is a Dirac delta function $\\tilde{\\V}(\\vec k)\\propto\\delta(\\vec k)$. Therefore, to show that a uniform potential extremizes the deliverable capacity, we must show that the functional derivative of the deliverable capacity with respect to $\\Vk$ is zero for \\emph{nonzero} values of $\\vec k$, i.e.\n\\begin{align}\n    \\frac{\\delta D}{\\delta \\Vk} &= 0, \\text{ if } \\vec k\\ne 0.\n\\end{align}\nWe note that this functional derivative may be non-zero for $\\vec k=0$ because we separately maximize with respect to the particular uniform potential $\\V$.\nThis means that\n\\begin{align}\n    \\frac{\\delta N_H}{\\delta \\V(\\vec k)} &= -\\frac{\\delta N_L}{\\delta \\Vk}\n\\end{align}\nwhere $N_H$ and $N_L$ are the number of particles at the low and high pressure.\n\nBecause the chemical potential $\\mu$ varies monotonically with $N$ at fixed temperature, we can consider how the chemical potential varies as we change $\\Vk$ with the number of molecules held fixed.  We demonstrate this using the cyclic chain rule, which shows us that\n\\begin{align}\n    \\left(\\frac{\\delta N}{\\delta \\Vk}\\right)_{\\mu} &=\n    -\\left(\\frac{\\delta \\mu}{\\delta \\V(\\vec k)}\\right)_{N}\n    \\left(\\frac{\\partial N}{\\partial \\mu}\\right)_{\\Vk}.\n\\end{align}\nSince changing the chemical potential changes the number of molecules in the general case, if we can show that $\\left(\\frac{\\delta \\mu}{\\delta \\V(\\vec k)}\\right)_{N}=0$ then we will have shown that $\\left(\\frac{\\delta N}{\\delta \\V(\\vec k)}\\right)_{\\mu}=0$.  Thus we consider\n\\begin{align}\n    \\left(\\frac{\\delta \\mu}{\\delta \\tilde\\V(\\vec k)}\\right)_N\n    &= \\left(\\frac{\\delta \\left(\\frac{\\partial F}{\\partial N}\\right)_{\\volume}}{\\delta \\Vk}\\right)_N\n    \\\\\n    &= \\left(\\frac{\\partial \\left(\\frac{\\delta F}{\\delta \\Vk}\\right)_{\\volume}}{\\partial N}\\right)_{\\volume}\n    \\label{eq:dmudpot}\n\\end{align}\nwhere we have made use of the derivative relationship between $\\mu$ and the Helmholtz free energy $F$, and have then reorderd the functional and partial derivatives.\nLet us consider the interior derivative first.  The derivative of the Helmholtz free energy with respect to the external potential $\\Vk$ just gives the number density:\n\\begin{align}\n    \\frac{\\delta F}{\\delta \\Vk} &= \\rho(\\vec k)\n\\end{align}\nThe number density is itself homogeneous for any system that is stable in a fluid state at this density (i.e. does not spontaneously crystallize), and thus has a Fourier transform that is proportional to a Dirac $\\delta$-function.  Thus the functional derivative $\\frac{\\delta F}{\\delta \\V(\\vec r)}$ is actually a uniform function.\nWe can insert this expression into Eq.~\\ref{eq:dmudpot} to find that\n\\begin{align}\n    \\frac{\\delta \\mu}{\\delta \\Vk} &\\propto \\delta(\\vec k) \\\\\n    \\frac{\\delta N}{\\delta \\Vk} &\\propto \\delta(\\vec k)\n\\end{align}\nThus the functional derivative of both the chemical potential and $N$ with regard to $\\V(\\vec r)$ are itself homogeneous.  Since we already maximize $D$ with respect to the homogeneous component of the potential (i.e. $\\vec k=0$), the derivative of $D$ with respect to any change of potential is zero.\n\nThis demonstrates that a homogeneous potential leads to an extremum value of the deliverable capacity.  This proof is insufficient, however, to show that it must be a true maximum.\n\n\\end{document}", "meta": {"hexsha": "a02de73967d4b666bf85d4e0a2bfece06090dc56", "size": 3971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gas-adsorption/supplemental-proof.tex", "max_stars_repo_name": "SimonEnsemble/thesis-pommerenck-1", "max_stars_repo_head_hexsha": "c546b981b0fa7cebbe80e32d45dee5e8714ea89c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-24T00:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-24T00:42:10.000Z", "max_issues_repo_path": "gas-adsorption/supplemental-proof.tex", "max_issues_repo_name": "SimonEnsemble/thesis-pommerenck-1", "max_issues_repo_head_hexsha": "c546b981b0fa7cebbe80e32d45dee5e8714ea89c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gas-adsorption/supplemental-proof.tex", "max_forks_repo_name": "SimonEnsemble/thesis-pommerenck-1", "max_forks_repo_head_hexsha": "c546b981b0fa7cebbe80e32d45dee5e8714ea89c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-23T18:42:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T18:42:16.000Z", "avg_line_length": 74.9245283019, "max_line_length": 340, "alphanum_fraction": 0.7280282045, "num_tokens": 1083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6351765308686635}}
{"text": "In this section, the governing equations of general dynamic problems in elastic-plastic solids are first written with a tensorial formalism based on the fourth-order stiffness tensor.\nThis framework leads on the one hand to the same characteristic structure as in \\cite{Raniecki,mandel_book}, so that well known results can be used.\nOn the other hand, it allows easy specialization to problems involving less than three space dimensions, such as the one-dimensional ones already treated in the literature.\n% This framework is more generic than the works mentioned in the introduction, which are formulated in matrix form based on the elastoplastic compliances, since it can be easily specialized to problems already treated in the literature.\n%\nSecond, the spectral analysis of the hyperbolic system written in an arbitrary direction is performed, which is motivated by the solution of Riemann problems in one space dimension in numerical schemes such as the Finite Volume Method (FVM) \\cite{Leveque,Toro}.\nThat approach furthermore avoids the seeking of bi-characteristics as proposed by \\textsc{Clifton} in order to build elastoplastic finite difference schemes \\cite{Clifton_thesis}.\nIt must be emphasized that the present work aims at highlighting a sufficient amount of information so as to enable numerical schemes to mimic the analytical behavior, and does not require the complete bi-characteristic structure.\n\n\\subsection{Governing equations}\nWe consider the isothermal deformation of a solid body of mass density $\\rho$ in the linearized geometrical framework.\nThe balance equation of linear momentum with neglected body forces, and the geometrical balance equations \\cite{Plohr,Gil_HE} are:  \n\\begin{equation}\n  \\label{eq:balance_equations}\n  %\\left\\lbrace\n    \\begin{aligned}\n    & \\rho \\dot{\\vect{v}} - \\nablav \\cdot \\tens{\\sigma} = \\vect{0} \\\\\n    &  \\dot{\\tens{\\eps}} - \\nablav \\cdot \\(\\frac{\\vect{v}\\otimes \\tens{I} + \\tens{I} \\boxtimes \\vect{v}}{2}\\) = \\vect{0} \n  \\end{aligned}\n%\\right.\n\\end{equation}\nwhere the operator $ \\boxtimes $ refers to the transpose on second and third indices of the classical tensor product, namely: $\\tens{I} \\boxtimes \\vect{v} = \\delta_{ik} v_j\\vect{e}_i \\otimes \\vect{e}_j \\otimes \\vect{e}_k$.\n%\nFurthermore, $\\tens{I}$, $\\vect{v}$, $\\tens{\\sigma}$ and $\\tens{\\eps}$ denote respectively the second-order identity tensor, the velocity vector, the Cauchy stress tensor and the linearized strain tensor.\nThe latter additively decomposes into an elastic strain $\\tens{\\eps}^e$ and a plastic strain $\\tens{\\eps}^p$ in the small strain case.\nAssuming Cartesian coordinates, system \\eqref{eq:balance_equations} can be written as:\n\\begin{equation}\n  \\label{eq:conservative_form}\n  \\drond{\\Ucb}{t} + \\drond{\\Fcb\\cdot \\vect{e}_i}{x_i}=\\tens{0}\n\\end{equation}\nwith the vector of conserved quantities $\\Ucb$ and the flux vectors $\\Fcb_i=\\Fcb\\cdot \\vect{e}_i$:\n\\begin{equation}\n  \\label{eq:vectors}\n  \\Ucb =\\matrice{\\rho\\vect{v} \\\\ \\tens{\\eps}} \\quad ; \\quad \\Fcb_i = \\matrice{-\\tens{\\sigma}\\cdot\\vect{e}_i\\\\-\\frac{\\vect{v}\\otimes\\vect{e}_i +\\vect{e}_i \\otimes\\vect{v} }{2} }\n\\end{equation}\nAlternatively, the introduction of an auxiliary vector of conserved quantities $\\Qcb$ allows rewriting equation \\eqref{eq:conservative_form} as a quasi-linear form by means of the chain rule \\cite{Trangenstein91}:\n\\begin{equation}\n  \\label{eq:quasi-linear_form}\n  \\drond{\\Qcb}{t} + \\Absf^i \\drond{\\Qcb}{x_i}=\\tens{0}\n\\end{equation}\nIn particular, by setting $\\Qcb=\\matrice{\\vect{v} \\\\ \\tens{\\sigma}}$, one writes:\n\\begin{equation}\n  \\label{eq:matrix-quasi}\n  \\Absf^i = \\(\\drond{\\Ucb}{\\Qcb}\\)^{-1}\\drond{\\Fcb_i}{\\Qcb} = -\\matrice{\\tens{0}^2 & \\frac{1}{\\rho}\\(\\frac{\\tens{I}\\otimes\\vect{e}_i + \\vect{e}_i\\otimes \\tens{I}}{2}\\)\\\\ \\Hbb\\cdot \\vect{e}_i & \\tens{0}^4},\n\\end{equation}\n$\\tens{0}^q$ being a $q$th-order zero tensor and $\\Hbb=\\drond{\\tens{\\sigma}}{\\tens{\\eps}}$ the fourth-order tangent modulus tensor.\nIt then appears that the characteristic structure of the hyperbolic problem, which is driven by the matrices $\\Absf^i$, depends on the nature of the deformation (\\textit{i.e. elastic or elastic-plastic}) through the tangent modulus.\n\n% On the other hand, following the Generalized Standard Material framework \\cite{GSM} a Helmholtz free-energy $\\psi$ depending on $\\tens{\\eps}$ and the set of additional internal variables $\\Vcb$ is assumed to  govern the evolution of the microstructure.\nFollowing the Generalized Standard Material framework \\cite{GSM}, the elastic-plastic constitutive response is described by a Helmholtz free-energy $\\psi$, convex with respect to $\\tens{\\eps}$ and the set of additional internal variables $\\Vcb$, and a yield surface $f$ in the case of associative plasticity. \nAssuming elastic isotropy, reversible evolutions are governed by the elastic law derived from Helmholtz's free energy:\n\\begin{equation}\n  \\label{eq:elastic_law}\n  \\tens{\\sigma} = \\Cbb: \\tens{\\eps}^e = 2\\mu \\tens{\\eps}^e + \\lambda \\tr \\tens{\\eps}^e \\: \\tens{I} \n\\end{equation}\nin which $(\\lambda,\\mu)$ are Lam{\\'e}'s parameters.\nThe inverse constitutive law can also be written based on Young's modulus and Poisson's ratio $(E,\\nu)$:\n\\begin{equation} \n  \\label{eq:elastic_inverse}\n  \\tens{\\eps}^e = \\Cbb^{-1}:\\tens{\\sigma} = \\frac{1+\\nu}{E} \\tens{\\sigma} - \\frac{\\nu}{E} \\tr \\tens{\\sigma}  \\: \\tens{I}\n\\end{equation}\n\n\nNext, restricting ourselves to isotropic hardening, the set $\\Vcb$ consists of the cumulated plastic strain $p$.\n%\nIn addition, the von-Mises yield surface is considered:\n\\begin{equation}\n  \\label{eq:von-Mises_yield}\n  f\\(\\tens{\\sigma},R \\)= \\sqrt{\\frac{3}{2}}\\norm{\\tens{s}} - \\(R(p)+\\sigma^y\\) \\leq 0 \\\\\n\\end{equation}\nwhere $\\tens{s}$ denotes the deviatoric part of the Cauchy stress tensor, $\\sigma^y$ is the yield stress in tension, and $-R(p)$ is the thermodynamical force conjugate to the cumulated plastic strain through some hardening law.\n% The evolution of the cumulated plastic strain follows from the consistency condition:\n% \\begin{equation}\n%   %\\label{eq:consistance}\n%   \\dot{f}=0 \\quad \\Leftrightarrow  \\quad  \\drond{f}{\\tens{\\sigma}}:\\tens{\\dot{\\sigma}} - \\drond{f}{R}\\:\\dot{R} =0\n% \\end{equation}\n% so that one writes:\n% \\begin{equation}\n%   \\label{eq:consistance}\n%   \\dot{R}=\\sqrt{\\frac{3}{2}}\\:\\frac{\\tens{s}:\\tens{\\dot{\\sigma}}}{\\norm{\\tens{s}}}\n% \\end{equation}\n% Then, the plastic flow rule:\n% \\begin{equation}\n%   \\label{eq:plastic_flow_rule}\n%   \\tens{\\dot{\\eps}}^p = \\dot{p}\\drond{f}{\\tens{\\sigma}}\n% \\end{equation}\nThe evolution of the plastic strain tensor and the cumulated plastic strain are governed by the following flow rule and hardening law respectively:\n\\begin{align}\n  \\label{eq:plastic_flow_rule}\n  & \\tens{\\dot{\\eps}}^p = \\lambda \\drond{f}{\\tens{\\sigma}} \\\\\n  \\label{eq:hardening_rule}\n  & \\dot{p} = -\\lambda \\drond{f}{R} %= \\lambda\n\\end{align}\nwhere the plastic multiplier $\\lambda$ and the yield surface obey the Kuhn-Tucker complementarity conditions:\n\\begin{equation}\n  \\label{eq:Kuhn-Tucker}\n  \\lambda \\geq 0 \\quad ;\\quad f \\leq 0 \\quad ; \\quad \\lambda f =0\n\\end{equation}\nalong with the consistency condition:\n\\begin{equation}\n  \\label{eq:consistency}\n  \\lambda \\dot{f}=0 %\\quad \\Leftrightarrow  \\quad  \\drond{f}{\\tens{\\sigma}}:\\tens{\\dot{\\sigma}} - \\drond{f}{R}\\:\\dot{R} =0\n\\end{equation}\n% From the above conditions, one deduces:\n% \\begin{equation}\n%   %\\label{eq:consistance}\n%   \\dot{f}=0 \\quad \\Leftrightarrow  \\quad  \\drond{f}{\\tens{\\sigma}}:\\tens{\\dot{\\sigma}} - \\drond{f}{R}\\:\\dot{R} =0\n% \\end{equation}\n% in such a way that:\n% \\begin{equation}\n%   \\label{eq:consistance}\n%   \\dot{R}=\\sqrt{\\frac{3}{2}}\\:\\frac{\\tens{s}:\\tens{\\dot{\\sigma}}}{\\norm{\\tens{s}}}\n% \\end{equation}\nTherefore, combining equations \\eqref{eq:plastic_flow_rule} and \\eqref{eq:hardening_rule}, the flow rule can be rewritten as:\n\\begin{equation}\n  \\label{eq:plastic_strain_rate}\n  \\tens{\\dot{\\eps}}^p = \\dot{p}\\:\\sqrt{\\frac{3}{2}}\\frac{\\tens{s}}{\\norm{\\tens{s}}}\n\\end{equation}\n\nGiven this description of internal processes, the thermodynamical framework then leads to the elastic-plastic constitutive equations during irreversible deformations by combining the elastic law \\eqref{eq:elastic_law}, the additive decomposition of the strain tensor and the plastic flow rule \\eqref{eq:plastic_strain_rate} \\cite{Simo}:\n\\begin{align}\n  \\label{eq:elastoplastic_tangent}\n  & \\tens{\\dot{\\sigma}} = \\Cbb^{ep}:\\tens{\\dot{\\eps}}=\\(\\Cbb - \\beta\\:\\tens{s}\\otimes\\tens{s} \\):\\tens{\\dot{\\eps}} \\\\\n  \\label{eq:plastic_flow}\n  % & \\beta = \\frac{6\\mu^2}{3\\mu +C}\\times\\frac{1}{\\tens{s}:\\tens{s}}\n  & \\beta = \\frac{6\\mu^2}{3\\mu +R'}\\times\\frac{1}{\\tens{s}:\\tens{s}}\n\\end{align}\nwhere the elastoplastic tangent modulus $\\Cbb^{ep}$ can be decomposed into the elasticity tensor $\\Cbb$ and another part depending on the direction of the plastic flow.\nTherefore, plastic evolutions involve $\\Hbb \\equiv \\Cbb^{ep}$ while elastic ones involve $\\Hbb\\equiv\\Cbb$.\n%$\n% \\begin{remark}\n%   In what follows, only linear isotropic hardening is considered by setting $R(p)=C p$ so that $R'=C$, with $C$ the hardening modulus.\n% \\end{remark}\n\n% Given this description of the internal processes, the thermodynamical framework then leads to the elastic-plastic constitutive equations for the components of the Cauchy stress tensor during irreversible deformations \\cite{Simo}:\n% \\begin{align}\n%   \\label{eq:elastoplastic_tangent}\n%   & \\tens{\\dot{\\sigma}} = \\Cbb^{ep}:\\tens{\\dot{\\eps}}=\\(\\Cbb - \\beta\\:\\tens{s}\\otimes\\tens{s} \\):\\tens{\\dot{\\eps}} \\\\\n%   \\label{eq:plastic_flow}\n%   % & \\beta = \\frac{6\\mu^2}{3\\mu +C}\\times\\frac{1}{\\tens{s}:\\tens{s}}\n%   & \\beta = \\frac{6\\mu^2}{3\\mu +R'}\\times\\frac{1}{\\tens{s}:\\tens{s}}\n% \\end{align}\n% where the elastoplastic tangent modulus $\\Cbb^{ep}$ can be decomposed into the elasticity tensor $\\Cbb$ and another part depending on the direction of the plastic flow.\n% In addition, the evolution of the cumulated plastic strain follows from the consistency condition:\n% \\begin{equation}\n%   %\\label{eq:consistance}\n%   \\dot{f}=0 \\quad \\Leftrightarrow  \\quad  \\drond{f}{\\tens{\\sigma}}:\\tens{\\dot{\\sigma}} - \\drond{f}{R}\\:\\dot{R} =0\n% \\end{equation}\n% so that one writes:\n% \\begin{equation}\n%   \\label{eq:consistance}\n%   C\\dot{p}=\\sqrt{\\frac{3}{2}}\\:\\frac{\\tens{s}:\\tens{\\dot{\\sigma}}}{\\norm{\\tens{s}}}\n% \\end{equation}\n% %Then, assuming  the existence of a dissipation pseudo-potential $\\phi(\\tens{\\sigma},-R(p))$, the plastic flow rule:\n% Then, the plastic flow rule:\n% \\begin{equation}\n%   \\label{eq:plastic_flow_rule}\n%   \\tens{\\dot{\\eps}}^p = \\dot{p}\\drond{f}{\\tens{\\sigma}}\n% \\end{equation}\n% finally leads to the evolution of the plastic part of the strain tensor:\n% \\begin{equation}\n%   \\label{eq:plastic_strain_rate}\n%   \\tens{\\dot{\\eps}}^p = \\dot{p}\\:\\sqrt{\\frac{3}{2}}\\frac{\\tens{s}}{\\norm{\\tens{s}}}\n% \\end{equation}\n\n% On the other hand, reversible evolutions are governed by the elastic law:\n% \\begin{equation}\n%     \\label{eq:elastic_law}\n%     \\tens{\\sigma} = \\Cbb: \\tens{\\eps}^e = 2\\mu \\tens{\\eps}^e + \\lambda \\tr \\tens{\\eps}^e \\: \\tens{I} \n% \\end{equation}\n% in which $(\\lambda,\\mu)$ are Lam{\\'e}'s parameters.\n% The inverse constitutive law also can be written based on Young's modulus and Poisson's ratio $(E,\\nu)$:\n% \\begin{equation} \n%   \\label{eq:elastic_inverse}\n%   \\tens{\\eps}^e = \\Cbb^{-1}:\\tens{\\sigma} = \\frac{1+\\nu}{E} \\tens{\\sigma} - \\frac{\\nu}{E} \\tr \\tens{\\sigma}  \\: \\tens{I}\n% \\end{equation}\n% Therefore, plastic evolutions involve $\\Hbb \\equiv \\Cbb^{ep}$ while elastic ones involve $\\Hbb\\equiv\\Cbb$.\n\n\\subsection{Spectral analysis}\n\\label{sec:spectral-analysis}\n\nConsidering an arbitrary direction of space $\\vect{n}$, the quasi-linear form \\eqref{eq:quasi-linear_form} reads: \n% The quasi-linear form of the sets of equations \\eqref{eq:balance_equations} and \\eqref{eq:plasticity_equations} in a Cartesian coordinate system and an arbitrary direction $\\vect{n}$ is:\n\\begin{equation}\n  \\label{eq:quasilinear_normal}\n  \\drond{\\Qcb}{t} + \\Jbsf \\drond{\\Qcb}{x_n} = \\vect{0} \n\\end{equation}\nwhere $x_n=\\vect{x}\\cdot\\vect{n}$ and $\\Jbsf=n_i\\Absf^i$ is the Jacobian matrix.\nSimple waves are solutions for which the vector $\\Qcb$ is constant along each curve of the one-parameter family $\\eta^K(x_n,t)=\\text{const}$.\nFor such \\textit{self-similar} solutions, system \\eqref{eq:quasilinear_normal} reads:\n\\begin{equation}\n  \\label{eq:simple_system}\n  \\(\\Jbsf -  c_K \\Ibsf \\vphantom{\\Qcb'(\\eta^K)}\\)\\Qcb'(\\eta^K)  = \\vect{0} \n\\end{equation}\nwhere $\\Ibsf$ is the $9\\times 9$ identity matrix and $c_K = -\\drond{\\eta^K}{t} / \\drond{\\eta^K}{x_n}$ appears to be the $K$th eigenvalue of the Jacobian matrix.\nThe problem therefore admits nontrivial solutions if $\\Jbsf$ has real eigenvalues and distinct left eigenvectors $\\Lcb^K= \\[ \\vect{v}^K \\: , \\: \\tens{\\sigma}^K \\]$ satisfying:\n\\begin{equation}\n  \\label{eq:eigen_system}\n  \\vect{\\Lc}^K \\(\\Jbsf - c_K \\Ibsf\\) = \\vect{0} \\qquad K=1,\\cdots,9\n\\end{equation}\n%The characteristic structure of the problem is given by the eigenvalues $c_K$ and the associated left eigenvectors $\\Lcb^K= \\[ \\vect{v}^K \\: , \\: \\tens{\\sigma}^K \\]$ of the Jacobian matrix satisfying:\n% \\begin{equation}\n%   \\label{eq:eigen_system}\n%   \\vect{\\Lc}^K \\(\\Jbsf - c_K \\Ibsf\\) = \\vect{0} \\qquad K=1,\\cdots,9\n% \\end{equation}\n%with $\\Ibsf$, the $9\\times 9$ identity matrix.\nThus, for non-zero eigenvalues one gets:\n\\begin{align}\n  \\label{eq:eigen_left_stress}\n  & -\\tens{\\sigma}^K:\\(\\Hbb\\cdot  \\vect{n}\\) - c_K  \\vect{v}^K =\\vect{0} \\\\\n  \\label{eq:eigen_left_velo}\n  & -\\frac{1}{\\rho}\\vect{v}^K\\otimes\\vect{n} - c_K \\tens{\\sigma}^K = \\tens{0}\n\\end{align}\nSubstitution of $\\tens{\\sigma}^K$ obtained from \\eqref{eq:eigen_left_velo} in \\eqref{eq:eigen_left_stress} leads to:\n\\begin{equation}\n  \\label{eq:acoustic_eigen}\n (\\vect{v}^K\\otimes\\vect{n}):\\(\\Hbb\\cdot  \\vect{n}\\) - \\rho c_K^2 \\vect{v}^K = \\tens{0}\n\\end{equation}\nwhich is the left eigensystem of the acoustic tensor $A_{ij}=n_k H_{ik j l}  n_l$.\nDue to the symmetry of $\\tens{A}$, system \\eqref{eq:acoustic_eigen} is equivalent to the right eigensystem:\n\\begin{equation}\n  \\label{eq:acoustic_eigen_system_lambda}\n  \\(  n_k H_{ik j l}  n_l - \\rho c_K^2 \\delta_{ij} \\) v_j^K =0\n\\end{equation}\nor alternatively, with the eigenvalues $\\omega_p$ and associated left eigenvectors of the acoustic tensor $\\vect{l}^q\\: \\: (q=1,2,3)$:\n\\begin{equation}\n  \\label{eq:acoustic_eigen_system}\n  \\vect{l}^q \\cdot \\( \\tens{A} - \\omega_q \\tens{I} \\)   = \\vect{0}\n\\end{equation}\nThe condition for system \\eqref{eq:quasilinear_normal} to be hyperbolic (real eigenvalues and independent eigenvectors) is thus ensured by the positive definiteness of the acoustic tensor, also known as the \\textit{strong ellipticity} condition \\cite{Foundation_of_elasticity}:\n\\begin{equation}\n  \\label{eq:strong_ellipticity}\n  (\\vect{m}\\otimes \\vect{n}): \\Hbb: (\\vect{n}\\otimes \\vect{m}) > 0 \\quad \\forall \\vect{n},\\vect{m} \\in \\Rbb^3 \\: ; \\: \\vect{n},\\vect{m} \\ne \\vect{0}\n\\end{equation}\nIf the condition holds, the acoustic tensor admits $3$ couples of eigenvalue--eigenvector $\\{\\omega_q,\\vect{l}^q\\}$ leading to $6$ couples $\\{c_K,\\Lcb^K\\}$ for the Jacobian matrix, the $3$ other eigenvalues being null \\cite{Kluth}.\nThe couples $\\{c_K,\\Lcb^K\\}$ are referred to as the \\textit{left characteristic fields}.\nNotice that since the elastic stiffness tensor $\\Cbb$ or the elastoplastic tangent modulus $\\Cbb^{ep}$ may be involved in equation \\eqref{eq:quasi-linear_form}, three left characteristic fields are obviously associated with elastic and elastic-plastic evolutions respectively.\nThe left eigenvectors related to the non-zero eigenvalues of the Jacobian matrix are obtained by using equation \\eqref{eq:eigen_left_velo} so that the following $6$ eigenfields of the quasi-linear form \\eqref{eq:quasilinear_normal} can be defined:\n\\begin{equation}\n  \\label{eq:left_eigenfields}\n    \\left\\lbrace \\pm \\sqrt{\\frac{\\omega_q}{\\rho_0}} ; \\: \\[ \\pm \\rho_0\\sqrt{\\frac{\\omega_q}{\\rho_0}} \\vect{l}^q , -\\vect{l}^q\\otimes \\vect{n} \\]  \\right\\rbrace ,\\: q=1,2,3\n\\end{equation}\nAt last, three independent left eigenvectors associated with the null eigenvalue of multiplicity $3$ can be found by solving equation \\eqref{eq:eigen_left_stress} for the null eigenvalue:\n\\begin{equation}\n  \\label{eq:left_null_eigenvectors}\n  \\tens{\\sigma}^K:\\(\\Hbb\\cdot  \\vect{n}\\) =\\vect{0},\\quad K=1,...,3\n\\end{equation}\n\nSince the above formulation is based on the elastoplastic stiffnesses rather than compliances, it differs from those of \\textsc{Bleich} \\cite{Bleich}, \\textsc{Clifton} \\cite{Clifton}, and hence from these of \\textsc{Ting} and \\textsc{Nan} \\cite{Ting68} and \\textsc{Ting} \\cite{Ting69}.\n%\nThe use of the tangent modulus $\\Hbb$ enables the specialization of equations \\eqref{eq:left_eigenfields} and \\eqref{eq:left_null_eigenvectors} to the plane strain and the plane stress cases, as we shall see in section \\ref{sec:2dproblem}.\n\n\\subsection{Known properties of the plastic waves}\n\\label{sec:plastic_speeds}\n\nLet us now recall some of the important results of \\textsc{Mandel} \\cite{Mandel62,Mandel69_thermoWaves} for which proofs can also be found in \\cite{mandel_book}.\n% eq (6.13)\nDenoting the elastic acoustic tensor as $\\tens{A}^e = \\vect{n} \\cdot \\Cbb \\cdot \\vect{n}$, the eigenvalue problem \\eqref{eq:acoustic_eigen_system} can be rewritten as:\n\\begin{equation}\n  \\label{eq:mod_eigen_acoustic}\n  \\vect{l}^q \\cdot \\( \\tens{B} - \\beta \\vect{a}\\otimes\\vect{a} \\)   = \\vect{0}\n\\end{equation}\nin which $\\tens{B}=\\tens{A}^e- \\omega_q \\tens{I}$ and $\\vect{a}=\\tens{s}\\cdot\\vect{n}$.\nThen, assuming that the coordinate axes coincide with the eigenbasis of $\\tens{A}^e$, the determinant of system \\eqref{eq:mod_eigen_acoustic} reads:\n\\begin{equation}\n  \\label{eq:polynomial_principal}\n  F(\\omega_q)=(A^e_1-\\omega_q)(A^e_2-\\omega_q)(A^e_3-\\omega_q) - \\beta\\[ (A^e_2-\\omega_q)(A^e_3-\\omega_q){a}^2_1 + (A^e_1-\\omega_q)(A^e_3-\\omega_q){a}^2_2 + (A^e_1-\\omega_q)(A^e_2-\\omega_q){a}^2_3 \\] =0\n\\end{equation}\nWith $\\beta>0$ and the eigenvalues of $\\tens{A^e}$ satisfying $A^e_1 \\geq A^e_2 \\geq A^e_3$, it comes out that:\n\\begin{equation}\n  \\label{eq:polynomial_property}\n  F\\(A^e_1\\) \\leq 0\\quad ; \\quad F\\(A^e_2\\) \\geq 0 \\quad ;\\quad F(A^e_3)\\leq 0 \\quad ; \\quad F(\\infty) < 0\n\\end{equation}\nfrom which the following conclusion is drawn.\n\\begin{property}[First Mandel's inequality]\n  \\label{pr:mandel_inequality}\n  For a unit normal vector $\\vect{n}$, the speeds of plastic waves $c_I^p\\geq c_{II}^p \\geq c_{III}^p$ are bounded by the elastic speeds $c_I^e\\geq c_{II}^e \\geq c_{III}^e$ according to:\n  \\begin{equation}\n    \\label{eq:Mandels_inequality}\n    c_I^e\\geq c_I^p\\geq c_{II}^e\\geq c_{II}^p \\geq c_{III}^e \\geq c_{III}^p \n  \\end{equation}\n\\end{property}\n\nConsider now equation \\eqref{eq:simple_system}, from which one gets for plastic evolutions:\n\\begin{align}\n  \\label{eq:right_eigen1}\n  & \\tens{\\sigma}' = -\\frac{1}{c_K} \\Hbb : \\( \\vect{n}\\otimes \\vect{v}' \\) \\\\\n  \\label{eq:right_eigen2}\n  & \\( \\tens{A}^{ep}  - \\rho c_K^2 \\tens{I} \\) \\vect{v}'  = \\vect{0}\n\\end{align}\nIf one of the plastic speed is equal to an elastic speed, the expansion of equation \\eqref{eq:right_eigen2} leads to:\n\\begin{equation}\n  \\label{eq:zero_dot_prod}\n  \\beta \\vect{a}\\cdot \\vect{v}' =0\n\\end{equation}\nThen, the projection of the variation $\\tens{\\sigma}'$ from equation \\eqref{eq:right_eigen1} onto the normal to the yield surface is:\n\\begin{equation}\n  \\label{eq:nutral_wave}\n  % \\drond{f}{\\tens{\\sigma}}:\\tens{\\sigma}' = -\\frac{1}{c_K}\\sqrt{\\frac{3}{2}} \\frac{\\tens{s}}{\\norm{\\tens{s}}} :  \\Hbb : \\( \\vect{n}\\otimes \\vect{v}' \\) = \\frac{1}{c_K}\\sqrt{\\frac{3}{2}} \\frac{\\mu - \\beta \\norm{\\tens{s}}}{\\norm{\\tens{s}}} \\vect{a}\\cdot\\vect{v}' = 0\n  \\drond{f}{\\tens{\\sigma}}:\\tens{\\sigma}'= \\frac{1}{c_K}\\sqrt{\\frac{3}{2}} \\frac{\\mu - \\beta \\norm{\\tens{s}}}{\\norm{\\tens{s}}} \\vect{a}\\cdot\\vect{v}' = 0\n\\end{equation}\nHence, if condition \\eqref{eq:zero_dot_prod} is satisfied, the stress increment is tangent to the yield surface.\n% Neutral waves\n\\begin{property}\n  \\label{pr:neutral_wave}\n  A plastic wave traveling with the speed of an elastic wave results in a stress path that is tangent to the yield surface in the stress space.\n  Such a wave is called a \\textit{neutral wave}.\n\\end{property}\n\n%In what follows, the above equations are specified to plane strain and plane stress cases.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"manuscript\"\n%%% End:\n", "meta": {"hexsha": "22c9da2f094ed3b114dfe7f72ffd77393402dba0", "size": 20380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papJmPs/characteristic_analysis.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": "papJmPs/characteristic_analysis.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": "papJmPs/characteristic_analysis.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": 64.4936708861, "max_line_length": 336, "alphanum_fraction": 0.7075564279, "num_tokens": 6844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6351765226767101}}
{"text": "\\chapter{Tree}\n\n\\section{Binary Tree}\n\\subsection{Introductions}\n\\runinhead{Get parent ref.} To get a parent reference (implicitly), \\textit{return the Node} of the current recursion function to its parent to maintain the path. Sample code:\n\\begin{java}\nNode deleteMin(Node x) {\n    if (x.left == null) return x.right;\n    x.left = deleteMin(x.left);\n    // x.count = 1+size(x.left)+size(x.right);\n    return x;\n}\n\\end{java}\n\\runinhead{Construct path from root to target.} To search a node in binary tree (not necessarily BST), use dfs:\n\\begin{python}\ndef dfs(self, root, t, path, found):\n    # post-call check\n    if not root: return        \n    if found[0]: return \n\n    path.append(root)\n    if root == t:\n        found[0] = True\n\n    self.dfs(root.left, t, path, found)\n    self.dfs(root.right, t, path, found)\n    if not found[0]:\n        path.pop()  # 1 pop() corresponds to 1 append()\n\\end{python}\nThe `found` is a wrapper for boolean to keep it referenced by all calling stack. \n\n\\runinhead{Lowest common ancestor.} In BST, the searching is straightforward. In normal binary tree, construct the path from root to $node_1$ and $node_2$ respectively, and \\textbf{diff} the two paths.\n\n\\runinhead{Find all paths.} Find all paths from root to leafs. For every currently visiting node, add itself to path; search left, search right and pop itself. Record current result when reaching the leaf.\n\\begin{python}\ndef dfs_path(self, cur, path, ret):\n    if not cur: return\n\n    path.append(cur)\n    if not cur.left and not cur.right:\n        ret.append(\"->\".join(map(lambda x: str(x.val), path)))\n\n    self.dfs_path(cur.left, path, ret)\n    self.dfs_path(cur.right, path, ret)\n    path.pop()\n\\end{python}\n\\subsection{Morris Traversal} \nTraversal with O(1) space. \\footnote{\\href{http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html}{ref}}\n\nTime complexity $O(3n).$ - find \\pyinline{pre} twice, \\pyinline{cur} traverse once. \\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=0.9in]{morris_time}}\n\\caption{Morris traversal time complexity}\n\\label{fig:morrisTime}\n\\end{figure}\n\n\\subsubsection{Inoder}\nAssign the current node's in-order predecessor's right child to itself (threading). Two ptr \\pyinline{cur}, \\pyinline{pre}. \n\nProcess:\n\\begin{enumerate}\n\\item If no left, \\textit{consume} \\pyinline{cur}, go right \n\\item If left, find in-order predecessor \\pyinline{pre}\n\\begin{enumerate}\n\\item If no thread (i.e. no \\pyinline{pre} right child), assign it to \\pyinline{cur}; go left\n\\item If thread, \\textit{consume} \\pyinline{cur}, go right. ($\\equiv$ no left). \n\\end{enumerate}\n\\end{enumerate}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=1.6in]{morris_inorder}}\n\\caption{Morris inorder traversal}\n\\label{fig:morrisInorder}\n\\end{figure}\n\\newpage\nCode:\n\\begin{python}\ndef morris_inorder(self, root):\n    cur = root\n    while cur:\n        if not cur.left:\n            self.consume(cur)\n            cur = cur.right\n        else:\n            pre = cur.left\n            while pre.right and pre.right != cur:\n                pre = pre.right\n\n            if not pre.right:\n                pre.right = cur\n                cur = cur.left\n            else:\n                pre.right = None\n                self.consume(cur)\n                cur = cur.right\n\\end{python}\n\\subsubsection{Preoder}\nSimilar to inorder. \n\nProcess:\n\\begin{enumerate}\n\\item If no left, \\textit{consume} \\pyinline{cur}, go right \n\\item If left, find in-order predecessor \\pyinline{pre}\n\\begin{enumerate}\n\\item If no thread (i.e. no \\pyinline{pre} right child), assign it to \\pyinline{cur}; \\textit{consume} \\pyinline{cur}, go left\n\\item If thread, go right. ($\\equiv$ no left, but no \\textit{consume}, since consume before). \n\\end{enumerate}\n\\end{enumerate}\n\n\\subsubsection{Postorder}\nMore tedious.\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=1.6in]{morris_postorder}}\n\\caption{Morris inorder traversal}\n\\label{fig:morrisInorder}\n\\end{figure}\n\nTODO\n\n\\section{Binary Search Tree (BST)}\n\\runinhead{Array and BST.}Given either the \\textbf{preorder} or \\textbf{postorder} (but not inorder) traversal of a BST containing N distinct keys, it is possible to reconstruct the shape of the BST. \n\\subsection{Rank}\n\\runinhead{Calculates rank.}\n\\begin{enumerate}\n\\item When inserting: \n  \\begin{enumerate}\n  \\item insert to an existing node: \\pyinline{node.cnt_this += 1}\n  \\item insert to left subtree: \\pyinline{node.cnt_left += 1}\n  \\item insert to right subtree: do nothing. \n\\end{enumerate}\n\\item When querying rank:\n  \\begin{enumerate}\n  \\item query equals current node: \\pyinline{return node.cnt_left}\n  \\item query goes to \\textbf{left} node: \\pyinline{return rank(node.left, val)};\n  \\item query goes to \\textbf{right} node: \\pyinline{return node.cnt_left} \\pyinline{+ node.cnt_this + rank(node.right, val)}\n  \\end{enumerate}\nNotice that the \\pyinline{rank} calculates a val's rank in a subtree.\n\\end{enumerate}\n\n\\runinhead{Count of smaller number before itself.} Given an array $A$. For each element $A_i$ in the array, count the number of element before this element $A_i$ is smaller than it and return count number array. Average $O(n \\log n)$\n\\\\\nClues:\n\\begin{enumerate}\n\\item Put $A[:i+1]$ into a BST; so as to count the rank of $A[i]$ in the BST\n\\end{enumerate}\nCodes:\n\\begin{python}\nclass Node(object):\n  def __init__(self, val):\n    \"\"\"Records the left subtree size\"\"\"\n    self.val = val\n    self.cnt_left = 0\n    self.cnt_this = 0\n    self.left, self.right = None, None\n\n\nclass BST(object):\n  def __init__(self):\n    self.root = None\n\n  def insert(self, root, val):\n    \"\"\"\n    :return: subtree's root after insertion\n    \"\"\"\n    if not root:\n      root = Node(val)\n\n    if root.val == val:\n      root.cnt_this += 1\n    elif val < root.val:\n      root.cnt_left += 1\n      root.left = self.insert(root.left, val)\n    else:\n      root.right = self.insert(root.right, val)\n\n    return root\n\n  def rank(self, root, val):\n    \"\"\"\n    Rank in the root's subtree\n    :return: number of items smaller than val\n    \"\"\"\n    if not root:\n      return 0\n    if root.val < val:\n      return (root.cnt_this+root.cnt_left+\n              self.rank(root.right, val))\n    elif root.val == val:\n      return root.cnt_left\n    else:\n      return self.rank(root.left, val)\n\n\nclass Solution(object):\n  def countOfSmallerNumberII(self, A):\n    tree = BST()\n    ret = []\n    for a in A:\n      tree.root = tree.insert(tree.root, a)\n      ret.append(tree.rank(tree.root, a))\n\n    return ret\n\\end{python}\nNotice: if worst case $O(n \\log n)$ is required, need to use Red-Back Tree - Section \\ref{rbtree}. However, there is a more elegant way using Segment Tree - Section \\ref{segmentTreeInversionCount}.\n\n\n\\subsection{Range search}\n\\runinhead{1-d range count}\n\\begin{java}\nint size(Key lo, Key hi) {\n    if (contains(hi)) return rank(hi)-rank(lo)+1;\n    else              return rank(hi)-rank(lo);\n}\n\\end{java}\n\n\\runinhead{Closest value} Find the value in BST that is closet to the \\pyinline{target}.\n\\\\\nClues:\n\\begin{enumerate}\n\\item Find the value just $\\leq$ the target.\n\\item Find the value just $\\geq$ the target.\n\\end{enumerate}\n\\\n\\\\\nCode for finding either the lower value or higher value:\n\\begin{python}\ndef find(self, root, target, ret, lower=True):\n  \"\"\"ret: result container\"\"\"\n  if not root: return\n\n  if root.val == target:\n    ret[0] = root.val\n    return\n\n  if root.val < target:\n    if lower:\n      ret[0] = max(ret[0], root.val)\n\n    self.find(root.right, target, ret, lower)\n  else:\n    if not lower:\n      ret[0] = min(ret[0], root.val)\n\n    self.find(root.left, target, ret, lower)\n\\end{python}\n\n\\runinhead{Closet values} Find $k$ values in BST that are closet to the \\pyinline{target}.\n\\\\\\\\\nClues:\n\\begin{enumerate}\n\\item Find the predecessors $\\triangleq \\{node | node.value \\leq target\\}$. Store in the stack. \n\\item Find the successors $\\triangleq \\{node | node.value \\geq target\\}$. Store in the stack.\n\\item Merge the predecessors and successors as in merge in MergeSort to get he $k$ values. \n\\end{enumerate}\n\\\n\\\\\nCode for finding the predecessors:\n\\begin{python}\ndef predecessors(self, root, target, stk):\n  if not root: return\n\n  self.predecessors(root.left, target, stk)\n  if root.val <= target:\n    stk.append(root.val)\n    self.predecessors(root.right, target, stk)\n\\end{python}\n\n\n\\section{Binary Index Tree (BIT)}\\label{BIT}\n\\subsection{Introduction}\nCompared to Segment Tree \\ref{section:segmentTree}, BIT is shorter and more elegant. BIT can do most of things that Segment Tree can do and it is easier to code. BIT updates and queries $$i\\rightarrow prefixSum$$ in $O(\\log n)$ time; however, BIT CANNOT query $$prefixSum \\rightarrow i$$\n\\subsection{Implementation}\nGiven an array $A$ of length $n $ starting from $1$. prefix sum $s[i]\\triangleq A_1+...+A_i$. BIT uses binary to maintain the array of prefix sum for querying and updating. For $i$-th node in the BIT, \n$$\nN[i]=A_{j+1}+...+A_i\n$$\n, where $j=i-lowbit(i)$, i.e. set $i$'s lowest bit 1 to 0. $lowbit(i)$ can be defined as \\pyinline{return i & -i}, using 2's complement. Notice that the summation ends with $A_i$ since easier to \\pyinline{set}.\n\nFor the range, we use $(j, i]$ here instead of $[j, i)$ since more elegant for \\pyinline{get(i)} and \\pyinline{set(i)}\n\\\\\\\\\nClues:\n\\begin{enumerate}\n\\item Binary \n\\item Low bit\n\\item BIT uses array index starting from \\textbf{1}, because 0 doesn't have $lowbit$.\n\\end{enumerate}\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=1.1in]{BITget}}\n\\caption{Binary Indexed Tree \\textit{get} Operation}\n\\label{fig:LABEL}\n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=1.05in]{BIT}}\n\\caption{Binary Indexed Tree \\textit{set} Operation}\n\\label{fig:LABEL}\n\\end{figure}\n\nTime complexity, longest update is along the leftmost branch, which takes $O(\\log_2 n)$ (e.g. 1, 10, 100, 1000, 10000); longest query is along a branch starting with node with all 1's (e.g. 1111, 1110, 1100, 1000), which also takes $O(\\log_2 n)$.\n\\newpage\nCode:\n\\begin{python}\nclass BIT(object):\n    def __init__(self, n):\n        \"\"\"BIT uses index starting from 1\"\"\"\n        self.N = [0 for _ in xrange(n+1)]\n\n    def lowbit(self, i):\n        return i & -i\n\n    def get(self, i):\n        ret = 0\n        while i > 0:\n            ret += self.N[i]\n            i -= self.lowbit(i)\n\n        return ret\n        \n    def set(self, i, val):\n        while i < len(self.N):\n            self.N[i] += val\n            i += self.lowbit(i)\n\\end{python}\n\n\n\\section{Segment Tree}\\label{section:segmentTree}\n\\subsection{Introduction}\nSegment Tree is specially built for \\textit{range queries}. \n\nThe structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment/interval. \n\nNotice that by practice, the interval is normally $[start, end)$ but sometimes it can be $[start, end]$, which depends on the question definition. \n\nStructure:  \n\\begin{lstlisting}[columns=flexible]\n# a Count Segment Tree\n                     [0, 4, count=3]\n                     /             \\\n          [0,2,count=1]             [2,4,count=2]\n          /         \\               /            \\\n   [0,1,count=1] [1,2,count=0] [2,3,count=1], [3,4,count=1]\n\\end{lstlisting}\nVariants:\n\\begin{enumerate}\n\\item Sum Segment Tree.\n\\item Min/Max Segment Tree.\n\\item Count Segment Tree. \n\\end{enumerate}\n\nFor a Maximum Segment Tree, which each node has an extra value max to store the maximum value in this node's interval.\n\n\\subsection{Operations}\nSegment Tree does a decent job for range queries.\n\\\\\nComponents in Segment Tree operations:\n\\begin{enumerate}\n\\item Build\n\\item Query \n\\item Modify\n\\item Search \n\\end{enumerate}\nNotice:\n\\begin{enumerate}\n\\item Only build need to change the start and end recursively.\n\\item Pre-check is preferred in recursive calls.\n\\end{enumerate}\nCode: Notice the code has abstracted out segment tree functions of sum, min/max or count, by abstracting the subtree combine function to \\pyinline{lambda}.\n\\begin{python}\nDEFAULT = 0\nf = lambda x, y: x+y\n\n\nclass Node(object):\n    def __init__(self, start, end, m):\n        self.start, self.end, self.m = start, end, m\n        self.left, self.right = None, None\n\n\nclass SegmentTree(object):\n    def __init__(self, A):\n        self.A = A\n        self.root = self.build_tree(0, len(self.A))\n\n    def build_tree(self, s, e):\n        \"\"\"\n        segment: [s, e)\n        Either check s+1==e or have root.right \n        only if have root.left\n        \"\"\"\n        if s >= e: return None\n        if s+1 == e: return Node(s, e, self.A[s])\n\n        left = self.build_tree(s, (s+e)/2)\n        right = self.build_tree((s+e)/2, e)\n\n        val = DEFAULT\n        if left: val = f(val, left.m)\n        if right: val = f(val, right.m)\n        root = Node(s, e, val)\n        root.left = left\n        root.right = right\n\n        return root\n\n    def query(self, root, s, e):\n        \"\"\"\n        :type root: Node\n        \"\"\"\n        if not root:\n            return DEFAULT\n\n        if s <= root.start and e >= root.end:\n            return root.m\n\n        if s >= root.end or e <= root.start:\n            return DEFAULT\n\n        l = self.query(root.left, s, e)\n        r = self.query(root.right, s, e)\n        return f(l, r)\n\n    def modify(self, root, idx, val):\n        \"\"\"\n        :type root: Node\n        \"\"\"\n        if not root or idx >= root.end or idx < root.start:\n            return\n\n        if idx == root.start and idx == root.end-1:\n            root.m = val\n            self.A[idx] = val\n            return\n\n        self.modify(root.left, idx, val)\n        self.modify(root.right, idx, val)\n\n        val = DEFAULT\n        if root.left:  val = f(val, root.left.m)\n        if root.right: val = f(val, root.right.m)\n        \n        root.m = val\n\\end{python}\nConcrete example - Count Segment Tree \\ref{inversionReconstruct}. \n\n\\newpage\n\\section{Trie}\n\\subsection{Basic}\nTrie is aka radix tree, prefix tree. \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.30]{trie.jpg}}\n\\caption{Trie}\n\\label{fig:trie} \n\\end{figure}\n\\runinhead{Notice:}\n\\begin{enumerate}\n\\item Children are stored in HashMap rather than ArrayList. \n\\item self.word to stores the word and indicates whether a word ends at the current\nnode. \n\\end{enumerate}\nCodes:\n\\begin{python}\nclass TrieNode(object):\n    def __init__(self, char):\n        self.char = char\n        self.word = None\n        self.children = {}  # map from char to TrieNode\n\n\nclass Trie(object):\n    def __init__(self):\n        self.root = TrieNode(None)\n\n    def add(self, word):\n        word = word.lower()\n        cur = self.root\n        for c in word:\n            if c not in cur.children:\n                cur.children[c] = TrieNode(c)\n            cur = cur.children[c]\n        cur.word = word\n\\end{python}\n\n\\subsection{Advanced}\nImplicit storage of word in TrieNode: \n\\begin{enumerate}\n\\item Implicitly stores the current word. \n\\item Implicitly stores the current char. \n\\item When insert new word, do not override the existing TrieNode. A flag to indicate\nwhether there is a word ending here.\n\\end{enumerate}\n\\newpage\nCode:\n\\begin{python}\nclass TrieNode:\n    def __init__(self):\n        \"\"\"Implicit storage\"\"\"\n        self.ended = False\n        self.children = {}\n\n\nclass Trie:\n    def __init__(self):\n        self.root = TrieNode()\n\n    def insert(self, word):\n        cur = self.root\n        for w in word:\n            if w not in cur.children:   # not override\n                cur.children[w] = TrieNode()\n            cur = cur.children[w]\n\n        cur.ended = True\n\n    def search(self, word):\n        cur = self.root\n        for w in word:\n            if w in cur.children:\n                cur = cur.children[w]\n            else:\n                return False\n\n        if not cur.ended:  # not ended here\n            return False\n\n        return True\n\n    def startsWith(self, prefix):\n        cur = self.root\n        for w in prefix:\n            if w in cur.children:\n                cur = cur.children[w]\n            else:\n                return False\n\n        return True\n\\end{python}\n\\subsection{Applications}\n\\begin{enumerate}\n\\item Word search in matrix.\n\\item Word look up in dictionary.\n\\end{enumerate}\n        \n     \n", "meta": {"hexsha": "56491e1834f358e30d6c0b92daf72074c034aa5f", "size": 16223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterTree.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": "chapterTree.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": "chapterTree.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": 29.5500910747, "max_line_length": 287, "alphanum_fraction": 0.647475806, "num_tokens": 4461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.8918110425624792, "lm_q1q2_score": 0.6351765158779495}}
{"text": "\\section{The Whitney sum formula}\n%Let me just repeat what I was rushing through at the end on Wednesday.\n%I wrote slightly incorrect things.\n%Let's look at $\\cc^n$.\n%Of course, $U(n)$ acts on this, and preserves the inner product.\n%Recall that $Fr(\\cc^n)$ is the space of orthonormal bases of $\\cc^n$.\n%Thus there's an action of $U(n)$ on this, and this is simply transitive, i.e., it's free and transitive.\n%Some would say that this is a ``torsor for $U(n)$''.\n%There's a basepoint in here, namely the standard basis, but you may forget about that.\n%\n%Now I can make various constructions.\n%For instance, think about $\\Fl(\\cc^n)$, which is the space of ordered orthonormal sets of $n$ lines in $\\cc^n$.\n%There's lots of isotropy now.\n%The isotropy group of the $U(n)$ action on the lines through the standard basis is now $T_n=U(1)^n$, i.e., diagonal matrices with roots of unity on the diagonal.\n%This is called the \\emph{(complete) flag manifold}.\n%\n%Another thing you could do as well -- you can forget the ordering.\n%This doesn't really have a name, I guess, but what I'm doing is considering $\\Fl(\\cc^n)/\\Sigma_n$, which is the space of unordered orthonormal lines in $\\cc^n$.\n%This is a homogeneous space, too, and it's $U(n)$ quotiented by permutation matrices where $1$ is any complex number of norm $1$.\n%For instance, if $N_{U(n)}(T^n) = \\Sigma_n\\cdot T^n$ is the normalizer, then $\\Fl(\\cc^n)/\\Sigma_n = U(n)/N(T^n)$.\n%I can consider the cofiber sequence $T^n\\hookrightarrow \\Sigma_n\\cdot T^n \\to W_n$, and the $W_n$ is called the Weyl group.\n%Something nice here is that\n%\\begin{equation*}\n%    \\xymatrix{\n%\tT^n\\ar@{^(->}[r] & \\Sigma_n\\cdot T^n\\ar[r] & W_n\\\\\n%\t& \\Sigma_n\\ar@{^(->}[u]\\ar[ur]^\\simeq & \n%    }\n%\\end{equation*}\n%To get projective space I consider the space of splittings of $\\cc^n$ into a line and its orthogonal complement -- but that's just giving a line because the metric determines the orthogonal complement.\n%\n%Consider a complex $n$-plane bundle $\\xi^n\\downarrow X$, with a metric.\n%Then $\\Fr(\\xi^n)\\to X$ is a principal $U(n)$-bundle over $X$.\n%I can form $E(\\xi) = \\Fr(\\xi)\\times_{U(n)}\\cc^n$, and $\\PP(\\xi) = \\Fr(\\xi)\\times_{U(n)} U(n)/(U(1)\\times U(n-1))$.\n%Note that $U(n)/(U(1)\\times U(n-1)) = \\CP^{n-1}$.\n%I can also consider $\\Fl(\\xi) = \\Fr(\\xi)\\times_{U(n} U(n)/T^n$.\n%\n%We found that $H^\\ast(X) \\hookrightarrow H^\\ast(\\Fl(\\xi))$.\n%This is the splitting principle.\n%\n%Let's look at the universal case $\\xi_n\\downarrow BU(n)$.\n%So, $\\Fl(\\xi_n) = EU(n)\\times_{U(n)} U(n)/T^n$, so this is $BT^n$.\n%It maps down to $BU(n)$, and the map is the one induced by the inclusion $T^n\\hookrightarrow U(n)$.\n%So, for any ring, we find that $H^\\ast(BU(n))\\hookrightarrow H^\\ast(BT^n)$.\n%We know that \n%$$\n%H^\\ast(BT^n) = \\Z[t_1,\\cdots,t_n]\n%$$\n%where $t_i = e(\\lambda_i)$ and $|t_i| = 2$, where $\\lambda_i = pr_i^\\ast\\lambda$ and $\\lambda\\downarrow \\CP^\\infty$ is the universal line bundle.\nAs we saw in the previous section, there is an injection\n$H^\\ast(BU(n))\\hookrightarrow H^\\ast(BT^n)$. What is the image of this map?\n\nThe symmetric group sits inside of $U(n)$, so it acts by conjugation on $U(n)$.\nThis action stabilizes this subgroup $T^n$. By naturality, $\\Sigma_n$ acts on\nthe classifying space $BT^n$. Since $\\Sigma_n$ acts by conjugation on $U(n)$,\nit acts on $BU(n)$ in a way that is homotopic to the identity (Lemma\n\\ref{conjugation-homotopic}). However, each element $\\sigma\\in \\Sigma_n$ simply\npermutes the factors in $BT^n = (\\CP^\\infty)^n$; we conclude that\n$H^\\ast(BU(n);R)$ actually sits inside the invariants\n$H^\\ast(BT^n;R)^{\\Sigma_n}$.\n\nRecall the following theorem from algebra:\n\\begin{theorem}\n    Let $\\Sigma_n$ act on the polynomial algebra $R[t_1,\\cdots,t_n]$ by\n    permuting the generators. Then\n    $$R[t_1,\\cdots,t_n]^{\\Sigma_n} = R[\\sigma_1^{(n)},\\cdots,\\sigma_n^{(n)}],$$\n    where the $\\sigma_i$ are the {elementary symmetric polynomials}, defined\n    via\n    $$\\prod^n_{i=1}(x-t_i) = \\sum^n_{j=0} \\sigma_i^{(n)}x^{n-i}.$$\n\\end{theorem}\nFor instance,\n$$\\sigma_1^{(n)} = -\\sum t_i,\\ \\sigma_n^{(n)} = (-1)^n\\prod t_i.$$\nIf we impose a grading on $R[t_1,\\cdots,t_n]$ such that $|t_i| = 2$, then\n$|\\sigma_i^{(n)}| = 2i$. It follows from our discussion in \\S\n\\ref{homology-bun} that the ring $H^\\ast(BT^n)^{\\Sigma_n}$ has the same size as\n$H^\\ast(BU(n))$.\n%they the same Poincar\\'{e} series. You could imagine that maybe it embeds as a\n%lattice inside the integers?\n\nConsider an injection of finitely generated abelian groups $M\\hookrightarrow\nN$, with quotient $Q$. Suppose that, after tensoring with any field, the map\n$M\\to N$ an isomorphism. If $Q\\otimes k = 0$, then $Q = 0$.\nIndeed, if $Q\\otimes \\QQ = 0$ then $Q$ is torsion. Similarly, if $Q\\otimes\n\\FF_p = 0$, then $Q$ has no $p$-component. In particular, $M\\simeq N$. Applying\nthis to the map $H^\\ast(BU(n)\\to H^\\ast(BT^n)^{\\Sigma_n}$, we find that\n$$\nH^\\ast(BU(n);R) \\xrightarrow{\\simeq} H^\\ast(BT^n;R)^{\\Sigma_n} =\nR[\\sigma_1^{(n)},\\cdots,\\sigma_n^{(n)}].\n$$\nWhat happens as $n$ varies? There is a map $R[t_1,\\cdots,t_n] \\to\nR[t_1,\\cdots,t_{n-1}]$ given by sending $t_n\\mapsto 0$ and $t_i\\mapsto t_i$ for\n$i\\neq n$. Of course, we cannot say that this map is equivariant with respect\nto the action of $\\Sigma_n$. However, it \\emph{is} equivariant with respect to\nthe action of $\\Sigma_{n-1}$ on $R[t_1,\\cdots,t_n]$ via the inclusion of\n$\\Sigma_{n-1}\\hookrightarrow \\Sigma_n$ as the stabilizer of\n$n\\in\\{1,\\cdots,n\\}$. Therefore, the $\\Sigma_n$-invariants sit inside the\n$\\Sigma_{n-1}$-invariants, giving a map\n$$\nR[t_1,\\cdots,t_n]^{\\Sigma_n} \\to R[t_1,\\cdots,t_n]^{\\Sigma_{n-1}} \\to\nR[t_1,\\cdots,t_{n-1}]^{\\Sigma_{n-1}}.\n$$\nWe also find that for $i<n$, we have $\\sigma_i^{(n)} \\mapsto \\sigma_i^{(n-1)}$\nand $\\sigma_n^{(n)} \\mapsto 0$.\n\\subsection{Where do the Chern classes go?}\\label{euler-multiplicativity}\nTo answer this question, we will need to understand the multiplicativity of the\nChern class. We begin with a discussion about the Euler class. Suppose $\\xi^p\\downarrow X,\\eta^q\\downarrow Y$ are oriented real\nvector bundles; then, we can consider the bundle $\\xi\\times\\eta\\downarrow X\\times Y$, which is\nanother oriented real vector bundle. The orientation is given by picking\noriented bases for $\\xi$ and $\\eta$.\n%There are lot of choices, but I'll put the first one first and the second one\n%second.\nWe claim that\n$$e(\\xi\\times\\eta) = e(\\xi)\\times e(\\eta) \\in H^{p+q}(X\\times Y).$$\nSince $D(\\xi\\times\\eta)$ is homeomorphic to $D(\\xi)\\times D(\\eta)$, and\n$S(\\xi\\times\\eta) = D(\\xi)\\times S(\\eta)\\cup S(\\xi)\\times D(\\eta)$, we learn\nfrom the relative K\\\"unneth formula that\n$$H^\\ast(D(\\xi\\times\\eta),S(\\xi\\times\\eta)) \\leftarrow\nH^\\ast(D(\\xi),S(\\xi))\\otimes H^\\ast(D(\\eta),S(\\eta)).$$\nIt follows that\n$$\nu_{\\xi\\times \\eta} = u_\\xi\\times u_\\eta\\in H^{p+q}(\\Th(\\xi)\\times\\Th(\\eta));\n$$\nthis proves the desired result since the Euler class is the image of the Thom\nclass under the map $H^n(\\Th(\\xi))\\to H^n(D(\\xi)) \\simeq H^n(B)$.\n\nConsider the diagonal map $\\Delta:X\\to X\\times X$. The cross product in\ncohomology then pulls back to the cup product, and the direct product of fiber\nbundles pulls back to the Whitney sum. It follows that\n$$e(\\xi\\oplus\\eta) = e(\\xi)\\cup e(\\eta).$$\n\nIf $\\xi^n\\downarrow X$ is an $n$-dimensional complex vector bundle, then we\ndefined\\footnote{There's a slight technical snag here: a complex bundle doesn't\nhave an orientation. However, its underlying oriented real vector bundle does.}\n$$\nc_n(\\xi) = (-1)^n e(\\xi_\\RR).\n$$\nWe need to describe the image of $c_n(\\xi_n)$ under the map $H^{2n}(BU(n)) \\to\nH^{2n}(BT^n)^{\\Sigma_n}$.\n\nLet $f:BT^n\\to BU(n)$ denote the map induced by the inclusion of the maximal\ntorus. Then, by construction, we have a splitting\n$$f^\\ast\\xi_n = \\lambda_1\\oplus\\cdots\\oplus \\lambda_n.$$\nThus,\n$$(-1)^ne(\\xi)\\mapsto (-1)^n e(\\lambda_1\\oplus\\cdots\\oplus \\lambda_n) = (-1)^n\ne(\\lambda_1)\\cup\\cdots\\cup e(\\lambda_n).$$\nThe discussion above implies that $f^\\ast$ sends the right hand side to\n$(-1)^nt_1\\cdots t_n = \\sigma_n^{(n)}$. In other words, the top Chern class\nmaps to $\\sigma_n^{(n)}$ under the map $f^\\ast$.\n\nOur discussion in the previous sections gives a commuting diagram:\n\\begin{equation*}\n    \\xymatrix{\n\tH^\\ast(BU(n)) \\ar[r] \\ar[d] & H^\\ast(BT^n)^{\\Sigma_n}\\ar[d]\\\\\n\tH^\\ast(BU(n-1)) \\ar[r] & H^\\ast(BT^{n-1})^{\\Sigma_{n-1}}\n    }\n\\end{equation*}\nArguing inductively, we find that going from the top left corner to the bottom\nleft corner to the bottom right corner sends\n$$c_i\\mapsto c_i\\mapsto \\sigma_i^{(n-1)}\\text{ for }i<n.$$\nLikewise, going from the top left corner to the top right corner to the bottom\nright corner sends\n$$c_i\\mapsto \\sigma_i^{(n)}\\mapsto \\sigma_i^{(n-1)}\\text{ for }i<n.$$\nWe conclude that the map $f^\\ast$ sends $c_i^{(i)}\\mapsto \\sigma_i^{(i)}$.\n\\subsection{Proving the Whitney sum formula}\nBy our discussion above, the Whitney sum formula of Theorem \\ref{chern-classes}\nreduces to proving the following identity:\n\\begin{equation}\\label{symmpol}\n    \\sigma^{(p+q)}_k = \\sum_{i+j=k}\\sigma_i^{(p)}\\cdot\\sigma_j^{(q)}\n\\end{equation}\ninside $\\Z[t_1,\\cdots,t_p,t_{p+1},\\cdots,t_{p+q}]$. Here, $\\sigma_i^{(p)}$ is\nthought of as a polynomial in $t_1,\\cdots,t_p$, while $\\sigma_i^{(q)}$ is\nthought of as a polynomial in $t_{p+1},\\cdots,t_{p+q}$. To derive Equation\n\\eqref{symmpol}, simply compare coefficients in the following:\n\\begin{align*}\n    \\sum_{k=0}^{p+q} \\sigma_k^{(p+q)}x^{p+q-k} & = \\prod^{p+q}_{i=1}(x-t_i)\\\\\n    & = \\prod^p_{i=1}(x-t_i)\\cdot\\prod^{p+q}_{j=p+1}(x-t_j)\\\\\n    & = \\left(\\sum^p_{i=0}\\sigma^{(p)}_i\n    x^{p-i}\\right)\\left(\\sum^q_{j=0}\\sigma_j^{(p)} x^{q-j}\\right)\\\\\n    & =\n    \\sum^{p+q}_{k=0}\\left(\\sum_{i+j=k}\\sigma_i^{(p)}\\sigma_j^{(q)}\\right)x^{p+q-k}.\n\\end{align*}\n", "meta": {"hexsha": "6ca6dbad4072a058d9698f3769493abb69cc480d", "size": 9707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-72-chern-roots.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-72-chern-roots.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-72-chern-roots.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": 53.6298342541, "max_line_length": 202, "alphanum_fraction": 0.6742556918, "num_tokens": 3390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8688267626522813, "lm_q1q2_score": 0.6351632581802854}}
{"text": "\\section{Question 3}\nQuestion 1 work well but in question 2 we have a long time delay so challenge for time optimization appears here. So we choise second system.\n\n\nSystem:\n$$\nG_{1_{(s)}} = \\dfrac{1}{(17s+1)(5s+1)}\\exp(-30s) = \\dfrac{1}{102s^2+23s+1}\n$$\nWe use Optimal PID to design controller with ITAE cost function. In program we use 40, 100, 400 and second for optimization but use 400 second for simulation to see system behavior. ITAE cost function work well in last question so we use this cost function in different time optimization.\n\\begin{figure}[H]\n    \\caption{Step responde with PID controller and ITAE cost function for different time}\n    \\centering\n    \\includegraphics[width=11cm]{../Figure/Q3/ITAE.png}\n\\end{figure}\nIn 40 second system is unstable but in other time system is stable and when we increse time PID conteller work better.", "meta": {"hexsha": "d16bdbe40dfc2daa7c818f0a608a35067992dec4", "size": 853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW VII/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 VII/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 VII/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": 56.8666666667, "max_line_length": 288, "alphanum_fraction": 0.7561547479, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6351632504815408}}
{"text": "\\section{Measurement Uncertainty Analysis}\n\n\\subsection{Uncertainty for resonance method}\n\nFor type-B uncertainty of $\\Delta L$,\n\n$$ \\frac{\\partial \\Delta L}{\\partial L_{10+i}}=1 $$\n$$ \\frac{\\partial \\Delta L}{\\partial L_i}=-1 $$\n$$ u_{L_{10+i}}=u_{L_i}=\\Delta_{dev}=1\\e{-5}m $$  \n\n\\[\n\\begin{split}\n    &\\Delta_{\\Delta L,B}=\\sqrt{(\\frac{\\partial \\Delta L}{\\partial\n        L_{10+i}})^2\\cdot (u_{L_{10+i}})^2+(\\frac{\\partial \\Delta\n        L}{\\partial L_i})^2\\cdot (u_{L_i})^2}\\\\ \n    &=0.014 \\times 10^{-3}m.\\\\\n\\end{split}\n\\]\n\nFor estimate type-A uncertainty,\nthe standard deviation of the average value can be caluculated as\n\n\\[\n    s_{\\overline{\\Delta L}}=\\sqrt{\\frac{1}{n(n-1)}\\sum_{i=1}^n(\\Delta\n      L_i-\\overline{\\Delta L})^2}. \n\\]\n\nFrom data of Table~\\ref{d1} we get that\n$s_{\\overline{\\Delta L}} = 0.01919\\e{-3}m$.\nConsidering $t_{0.95}=2.26$ for $n=10$,\nthe type-A uncertainty can be estimated as\n$\\Delta_{\\Delta L,A}=2.26 \\times 0.01919\\e{-3} = 0.0434\\e{-3}m$.\n\nThus the combined uncertainty is \n\n\\[\n\\begin{split}\n    &u_{\\Delta L}=\\sqrt{\\Delta_{\\Delta L,A}^2+\\Delta_{\\Delta\n        L,B}^2} \\\\\n    &= \\sqrt{(0.0434\\e{-3})^2+(0.014\\e{-3})^2} \\\\\n    &= 0.045\\e{-3}m\\\\ \n\\end{split}\n\\]\n    \n\\[\n\\begin{split}\n    &u_{r,\\Delta L}=\\frac{u_{\\Delta L}}{\\overline{\\Delta L}}\\times\n    100\\%=\\frac{0.045\\e{-3}}{50.94\\e{-3}}\\times100\\% \\\\\n    &=0.09\\%\\\\ \n\\end{split}\n\\]\n$$\\overline{\\Delta L}=(50.94 \\pm 0.05)\\e{-3}m, u_{r,\\Delta L}=0.10\\% $$\n  \n\nIn the same way, we obtain the uncertainty of wavelength $\\lambda=2\\Delta L/n$ \n\n\n$$\\frac{\\partial \\lambda}{\\partial \\Delta L}=\\frac{2}{10}=\\frac{1}{5}$$\n\n$$u_{\\Delta L}=0.05\\e{-3}m$$\n\n$$u_{\\lambda}=\\sqrt{(\\frac{\\partial \\lambda}{\\partial \\Delta L})^2\\cdot \n  (u_{\\Delta L})^2}\n  =\\frac{1}{5}\\times 0.05\\e{-3}=0.01\\e{-3}m$$\n\n$$u_{r,\\lambda}=\\frac{u_{\\lambda}}{\\overline{\\lambda}}\\times \n100\\%=\\frac{0.01\\e{-3}}{10.03\\e{-3}}=0.10\\%$$\n\n$$\\lambda=(10.03\\pm0.01)\\e{-3}m,\\quad u_{r,\\lambda}=0.10\\%$$\n\n\nand the uncertainty of the spped of sound in air $v=\\lambda f$\n\n$$\\frac{\\partial v}{\\partial \\lambda}=f,\n\\frac{\\partial v}{\\partial f}=\\lambda$$\n\n$$u_{\\lambda}=0.01\\e{-3}m, \nu_{f}=1Hz$$\n\n\\[\n\\begin{split}\n&u_{v}=\\sqrt{(\\frac{\\partial v}{\\partial \\lambda})^2\\cdot\n  (u_{\\lambda})^2+(\\frac{\\partial v}{\\partial f})^2\\cdot\n  (u_{f})^2}=\\sqrt{(f)^2\\cdot (u_{\\lambda})^2+(\\lambda)^2\\cdot\n  (u_{f})^2}\\\\ \n&\\quad =\\sqrt{(35000)^2\\cdot(0.01\\e{-3})^2+(10.03\\e{-3})^2\\cdot(1)^2}\n\\approx0.4m/s\\\\\n\\end{split}\n\\]\n\n$$u_{r,v}=\\frac{u_v}{\\overline{v}}\\times 100\\%=\\frac{0.4}{351.05}=0.10\\%$$\n$$v=351.05\\pm0.4 m/s,\\quad u_{r,v}=0.10\\%$$\n\n\\subsection{Uncertainty for phase comparison method}\n\nTo determine the type-B uncertainty of $\\Delta L$,\n\n\n$$\\frac{\\partial \\Delta L}{\\partial L_{6+i}}=1,\n\\quad \\frac{\\partial \\Delta L}{\\partial L_i}=-1$$ \n$$u_{L_{6+i}}=u_{L_i}=\\Delta_{dev}=1\\e{-5}m$$\n\n\n\\[\n\\begin{split}\n    &\\Delta_{\\Delta L,B}=\\sqrt{(\\frac{\\partial \\Delta L}{\\partial\n        L_{6+i}})^2\\cdot (u_{L_{6+i}})^2+(\\frac{\\partial \\Delta L}{\\partial\n        L_i})^2\\cdot (u_{L_i})^2}\\\\ \n    &\\quad\\quad =\\sqrt{2}\\times 1\\e{-5}\\approx0.014\\e{-3}m.\\\\ \n\\end{split}\n\\]\n\nFor type-A uncertainty, the standard deviation of the average value is caluculated as\n\n\\[\n    s_{\\overline{\\Delta L}}=\\sqrt{\\frac{1}{n(n-1)}\\sum_{i=1}^n(\\Delta\n      L_i-\\overline{\\Delta L})^2}. \n\\]\n\nUisng the data from Table \\ref{d2} we find that $s_{\\overline{\\Delta\n    L}}\\approx 0.6485\\e{-3}m$. Considering $t_{0.95}=2.57$ for $n=6$, the\ntype-A uncertainty is estimated as $\\Delta_{\\Delta\n  L,A}=2.57\\times0.6485\\e{-3}\\approx 1.67\\e{-3}m$. \n\nThus the combined uncertainty is \n\n\n$$u_{\\Delta L}=\\sqrt{\\Delta_{\\Delta L,A}^2+\\Delta_{\\Delta\n    L,B}^2}=\\sqrt{(1.67\\e{-3})^2+(0.014\\e{-3})^2}\\approx1.7\\e{-3}m$$\n\n$$u_{r,\\Delta L}=\\frac{u_{\\Delta L}}{\\overline{\\Delta L}}\\times\n100\\%=\\frac{1.7\\e{-3}}{59.84\\e{-3}}\\times100\\%\\approx3\\%$$\n\n$$\\overline{\\Delta L}=(59.84\\pm 1.7)\\e{-3}m,\\quad u_{r,\\Delta L}=3\\% $$\n\n\nSimilarly, we obtain the uncertainty of wavelength $\\lambda=\\Delta L/n$\n\n\n$$\\frac{\\partial \\lambda}{\\partial \\Delta L}=\\frac{1}{6}$$\n$$u_{\\Delta L}=1.7\\e{-3}m$$\n$$u_{\\lambda}=\\sqrt{(\\frac{\\partial \\lambda}{\\partial \\Delta L})^2\\cdot\n      (u_{\\Delta L})^2}=\\frac{1}{6}\\times 1.7\\e{-3}=0.3\\e{-3}m$$\n$$u_{r,\\lambda}=\\frac{u_{\\lambda}}{\\overline{\\lambda}}\\times\n100\\%=\\frac{0.3\\e{-3}}{9.973\\e{-3}}=3\\%$$\n$$\\lambda=(9.973\\pm0.3)\\e{-3}m,\\quad u_{r,\\lambda}=3\\%$$\n\n\nand the uncertainty of the spped of sound in air $v=\\lambda f$\n\n\n$$\\frac{\\partial v}{\\partial \\lambda}=f,\n\\quad \\frac{\\partial v}{\\partial f}=\\lambda$$ \n\n$$u_{\\lambda}=0.3\\e{-3}m,\\quad u_{f}=1Hz$$\n\n\\[\n\\begin{split}\n    &u_{v}=\\sqrt{(\\frac{\\partial v}{\\partial \\lambda})^2\\cdot\n      (u_{\\lambda})^2+(\\frac{\\partial v}{\\partial f})^2\\cdot\n      (u_{f})^2}=\\sqrt{(f)^2\\cdot (u_{\\lambda})^2+(\\lambda)^2\\cdot\n      (u_{f})^2},\\\\ \n    &\\quad =\\sqrt{(35000)^2\\cdot(0.3\\e{-3})^2+(9.97\\e{-3})^2\\cdot(1)^2}\n    \\approx10m/s,\\\\\n\\end{split}\n\\]\n\n\n$$u_{r,v}=\\frac{u_v}{\\overline{v}}\\times 100\\%=\\frac{10}{348.95}=3\\%$$\n$$v=348.95\\pm10 m/s,\\quad u_{r,v}=3\\%$$\n\n\n\\subsection{Uncertainty for the time difference method (liquid)}\n\nFrom MATLAB  fitting toolbox, the slope of $L\\ vs.\\ t$,\nwe obtain the information of the fit.  \n\n$$    v_{water}=1502\\pm20 m/s. $$\n\nwhere $\\pm 20m/s$ is the 0.95-confidence uncertainty, with $t_{0.95}=2.20$\nwhen $n=12$. THe relative uncertainty is that \n\n$$u_{r,v}=\\frac{u_v}{\\bar{v}}\\times100\\%=\\frac{20}{1502}=1.5\\%.$$\n\nHence the speed of sound in water is \n$$v_{water}=1502\\pm20m/s,\\quad u_{r,v}=1.5\\%. $$", "meta": {"hexsha": "72cfb298b5117d86911aad2df8424d7d72e283d9", "size": 5482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E4/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": "E4/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": "E4/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": 29.4731182796, "max_line_length": 85, "alphanum_fraction": 0.5926669099, "num_tokens": 2299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.6350837770774148}}
{"text": "% !TEX root = lectures.tex\n%\\input{lectureheader.tex}\n\n\\section{Rotating Coordinate Systems}\n\\bigskip\n\n\\subsection{Accelerating Frames}\n\nHere we again consider the effect of uniformly accelerating reference frames. If a particle is observed in an inertial reference frame, which we will denote with a prime, Newton's third law applies\n\\begin{equation}\nm\\frac{d^2\\vec{r}'}{dt^2}=\\vec{F}.\n\\end{equation}\nNow, if we have a second coordinate system,\n\\begin{equation}\n\\vec{r}=\\vec{r}'-\\vec{r}_0,~~~~\\vec{r_0}=\\frac{1}{2}\\vec{a}_0t^2.\n\\end{equation}\nWe would see that\n\\begin{equation}\nm\\frac{d^2\\vec{r}}{dt^2}=\\vec{F}-m\\vec{a}_0.\n\\end{equation}\nHere $\\vec{a}_0$ is the acceleration of the coordinate system. The last term acts like an additional apparent force. In fact, it acts like a contribution to the gravitational force which alters the acceleration of gravity by $\\delta\\vec{g}=-\\vec{a}_0$.\n\n\\subsection{Rotating Frames}\nIf you are on Earth's surface and if your reference frame is fixed with the surface, this is an example of an accelerating frame, where the acceleration is $\\omega^2 r_{\\perp}$, where $r_{\\perp}\\equiv\\sqrt{x^2+y^2}$, and $\\omega$ is the angular velocity of Earth's rotation. The acceleration is inward toward the axis of rotation, so the additional contribution to the apparent acceleration of gravity is outward in the $x-y$ plane. In contrast the usual $\\vec{g}$ is radially inward pointing toward the origin. \n\nIn the rotating coordinate system (not an inertial frame), motion is determined by the apparent force and one can define effective potentials. In addition to the normal gravitational potential energy, there is a contribution to the effective potential,\n\\begin{equation}\n\\delta U_{\\rm eff}=-\\frac{m}{2}\\omega^2r_\\perp^2=-\\frac{m}{2}r^2\\omega^2\\sin^2\\theta,\n\\end{equation}\nwhere $\\theta$ is the polar angle, measured from the north pole. If the true gravitational force can be considered as originating from a point in Earth's center, the net effective potential for a mass $m$ near Earth's surface could be \n\\begin{equation}\nU_{\\rm eff}=mgh-m\\frac{1}{2}\\omega^2(R+h)^2\\sin^2\\theta.\n\\end{equation}\n\n\\example\nHow much wider is Earth at the equator than the north-south distance between the poles assuming that the gravitational field above the surface can be approximated by that of a point mass at Earth's center.\n\n{\\bf Solution}: \nThe surface of the ocean must be at constant effective potential for a sample mass $m$. This means that if $h$ now refers to the height of the water\n\\[\nm g[h(\\theta=\\pi/2)-h(\\theta=0)]=\\frac{m}{2}\\omega^2(R+h)^2.\n\\]\nBecause $R>>h$, one can approximate $R+h\\rightarrow R$ on the right-hand side, thus\n\\[\nh(\\theta=\\pi)-h(\\theta=0)=\\frac{\\omega^2R^2}{2g}.\n\\]\nThis come out a bit less than 11 km, or a difference of near 22 km for the diameter of the Earth in the equatorial plane compared to a diameter between the poles. In reality, the difference is approximately 41 km. The discrepancy comes from the assumption that the true gravitational force can be treated as if it came from a point at Earth's center. This would be true if the distribution of mass was radially symmetric. However, Earth's center is molten and the rotation distorts the mass distribution. Remarkably this effect nearly doubles the elliptic distortion of Earth's shape. Due to this distortion, the top of Mount Everest is not the furthest point from the center of the Earth. That belongs to the top of a volcano, Chimborazo, in Equador, which is one degree in latitude below the Equator. Chimborazo is about 8500 ft lower than Everest when measured relative to sea level, but is 7700 feet further from the center of the Earth.\n\n\\exampleend\n\n\\subsection{Coriolis Force}\n\nConsider some vector $\\vec{A}$ according to an observer in a frame rotating about the $z$ axis with angular velocity $\\vec{\\omega}=\\omega\\hat{z}$. To an observer in the laboratory frame (the primed frame) the vector will change even if the vector appears fixed to the rotating observer. For a rotation of $\\Delta\\theta=\\omega\\Delta t$, the change of the vector due to the rotation is\n\\begin{eqnarray}\n\\Delta\\vec{A}'=\\vec{\\omega}\\times\\vec{A}\\Delta t.\n\\end{eqnarray}\nIf one includes the fact that $A$, the vector measured in the rotating frame, might be changing as a function of time,\n\\begin{eqnarray}\n\\label{eq:dAdtrot}\n\\Delta\\vec{A}'&=&\\Delta\\vec{A}+\\vec{\\omega}\\times\\vec{A}\\Delta t,\\\\\n\\nonumber\n\\frac{d}{dt}\\vec{A}'&=&\\frac{d}{dt}\\vec{A}+\\vec{\\omega}\\times\\vec{A}.\n\\end{eqnarray}\nIf the vector happens to be the position $\\vec{r}$,\n\\begin{eqnarray}\n\\dot{\\vec{r}}'&=&\\vec{v}'=\\vec{v}+\\vec{\\omega}\\times\\vec{r}.\n\\end{eqnarray}\nHere, the first term on the r.h.s. corresponds to the vector $\\vec{r}$ not being fixed, but changing with time, $\\dot{\\vec{r}}=\\vec{v}$. One can now use $\\vec{v}'=\\vec{v}+\\vec{\\omega}\\times\\vec{r}$ in place of $\\vec{A}$ in Eq. (\\ref{eq:dAdtrot}), and see\n\\begin{eqnarray}\n\\dot{\\vec{v}}'&=&\\frac{d}{dt}(\\vec{v}+\\vec{\\omega}\\times\\vec{r})+\\vec{\\omega}\\times(\\vec{v}+\\vec{\\omega}\\times\\vec{r})\\\\\n\\nonumber\n&=&\\dot{\\vec{v}}+\\vec{\\omega}\\times\\dot\\vec{r}+\\vec{\\omega}\\times\\left(\\vec{v}+\\vec{\\omega}\\times\\vec{r}\\right)\\\\\n\\nonumber\n&=&\\dot{\\vec{v}}+2\\vec{\\omega}\\times\\vec{v}+\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r}).\n\\end{eqnarray}\nBecause $\\dot{\\vec{v}}'$ is $\\vec{F}/m$,\n\\begin{eqnarray}\n\\label{eq:FmaRotatingFrame}\n\\vec{F}&=&m\\left\\{\\vec{a}+2\\vec{\\omega}\\times\\vec{v}+\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r})\\right\\},\\\\\n\\nonumber\nm\\vec{a}&=&\\vec{F}-2m\\vec{\\omega}\\times\\vec{v}-m\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r}).\n\\end{eqnarray}\nThe extra terms on the right behave like additional forces. Like gravitational forces, they are proportional to the mass, so the mass cancels for many problems. \n\nThe last term, $-m\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r})$, represents the centrifugal force. Using the vector identity, \n$\\vec{A}\\times(\\vec{B}\\times\\vec{C})=\\vec{B}(\\vec{A}\\cdot{\\vec{C}})-\\vec{C}(\\vec{A}\\cdot\\vec{B})$,\n\\begin{equation}\n-\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r})=\\omega^2\\vec{r}+(\\omega\\cdot\\vec{r})\\vec{\\omega}.\n\\end{equation}\nIf $\\vec{\\omega}$ is in the $z$ direction,\n\\begin{equation}\n-\\vec{\\omega}\\times(\\vec{\\omega}\\times\\vec{r})=\\omega^2(x\\hat{x}+y\\hat{y}).\n\\end{equation}\nThe centrifugal force points outward in the $x-y$ plane, and its magnitude is $m\\omega^2r_{\\rm\\perp}$, where $r_{\\rm\\perp}=\\sqrt{x^2+y^2}$.\n\nThe second term is Eq. (\\ref{eq:FmaRotatingFrame}) represents the Coriolis force. It does not enter problems like the shape of the Earth above because in that case the water was not moving relative to the rotating frame. Once an object is moving in a rotating frame, the particle is no longer being described in a single accelerating frame because at each point the acceleration is $-\\omega^2\\vec{r}$. \n\n\\example\nA ball is dropped from a height $h=500$m above Minneapolis. Due to the Coriolis force, it is deflected by an amount $\\delta x$ and $\\delta y$. Find the deflection. Ignore the centrifugal terms.\n\n{\\bf Solution}: The equations of motion are:\n\\begin{eqnarray*}\n\\frac{dv_x}{dt}&=&-2(\\omega_yv_z-\\omega_zv_y),\\\\\n\\frac{dv_y}{dt}&=&-2(\\omega_zv_x-\\omega_xv_z),\\\\\n\\frac{dv_z}{dt}&=&-g-2(\\omega_xv_y-\\omega_yv_x),\\\\\n\\omega_z&=&\\omega\\cos\\theta,~~~\\omega_y=\\omega\\sin\\theta,~~~\\omega_x=0.\n\\end{eqnarray*}\nHere the coordinate system is $\\hat{x}$ points east, $\\hat{y}$ points north and $\\hat{z}$ points upward.\n\nOne can now ignore all the Coriolis terms on the right-hand sides except for those with $v_z$. The other terms will all be doubly small. One can also throw out terms with $\\omega_x$. This gives\n\\begin{eqnarray*}\n\\frac{dv_x}{dt}&\\approx& -2\\omega v_z\\sin\\theta,\\\\\n\\frac{dv_y}{dt}&\\approx& 0,\\\\\n\\frac{dv_z}{dt}&\\approx& -g.\n\\end{eqnarray*}\nThere will be no significant deflection in the $y$ direction, $\\delta y=0$, but in the $x$ direction one can substitute $v_z=-gt$ above,\n\\begin{eqnarray*}\nv_x&\\approx&\\int_0^t dt'~2\\omega gt'\\sin\\theta=\\omega gt^2\\sin\\theta,\\\\\n\\delta x&\\approx& \\int_0^t dt'~v_x(t')=\\frac{g\\omega\\sin\\theta t^3}{3}.\n\\end{eqnarray*}\nOne can find the deflections by using $h=\\frac{1}{2}gt^2$, to find the time, and using the all-knowing internet to see that the latitude of Minneapolis is $44.6^\\circ$ or $\\theta=45.4^\\circ$.\n\\begin{eqnarray*}\nt&=&\\sqrt{2h/g}=10.1~{\\rm s},\\\\\n\\omega&=&\\frac{2\\pi}{3600\\cdot 24~{\\rm s}}=7.27\\times 10^{-5}~{\\rm s}^{-1},\\\\\n\\delta x&=&17.4~{\\rm cm}~~{\\rm(east)}.\n\\end{eqnarray*}\n\n\\exampleend\n\n\n\\subsection{The Foucault Pendulum}\nThe Foucault Pendulum is simply a regular pendulum moving in both horizontal directions, and with the Coriolis force included. In this case,\n\\begin{eqnarray*}\nm\\ddot{\\vec{r}}&=&\\vec{T}+m\\vec{g}-2m\\vec{\\Omega}\\times\\vec{v},\n\\end{eqnarray*}\nas the centrifugal force term is absorbed into the definition of $\\vec{g}$. The magnitude of the tension, $\\vec{T}$, is considered constant because we consider only small oscillations. Then $T\\approx mg$, and the components, using $\\hat{x},\\hat{y}$ to correspond to east and north respectively, are\n\\begin{eqnarray*}\nT_x=-mgx/L,~~~T_y=-mgy/L. \n\\end{eqnarray*}\nIf $\\Omega$ is the rotation of the earth, and if $\\theta$ is the polar angle, $\\pi-$lattitude, \n\\begin{eqnarray*}\n\\ddot{x}&=&-gx/L+2\\dot{y}\\Omega_z,\\\\\n\\ddot{y}&=&-gy/L-2\\dot{x}\\Omega_z.\n\\end{eqnarray*}\nHere we have used the fact that the oscillations are sufficiently small so we can ignore $v_z$. Using $\\omega_0\\equiv\\sqrt{k/m}$,\n\\begin{eqnarray*}\n\\ddot{x}-2\\Omega_z\\dot{y}+\\omega_0^2x&=&0\\\\\n\\ddot{y}+2\\Omega_z\\dot{x}+\\omega_0^2y&=&0,\n\\end{eqnarray*}\nwhere $\\Omega_z=|\\vec{\\Omega}|\\cos\\theta$, with $\\theta$ being the polar angle (zero at the north pole). The terms linear in time derivatives are what make life difficult. This will be solved with a trick. We will incorporate both differential equations into a single complex equation where the first/second are the real/imaginary parts.\n\\begin{eqnarray*}\n\\eta\\equiv x+iy,\\\\\n\\ddot{\\eta}+2i\\Omega_z\\dot{\\eta}+\\omega_0^2\\eta&=&0. \n\\end{eqnarray*}\n\nNow, we guess at a form for the solutions, $\\eta(t)=e^{-i\\alpha t}$, which turns the differential equation into\n\\begin{eqnarray*}\n-\\alpha^2+2\\Omega_z\\alpha+\\omega_0^2&=&0,\\\\\n\\alpha&=&\\Omega_z\\pm \\sqrt{\\Omega_z^2+\\omega_0^2},\\\\\n&\\approx&\\Omega_z\\pm \\omega_0.\n\\end{eqnarray*}\nThe solution with two arbitrary constants is then\n\\begin{eqnarray*}\n\\eta&=&e^{-i\\Omega_zt}\\left[C_1e^{i\\omega_0t}+C_2e^{-i\\omega_0t}\\right].\n\\end{eqnarray*}\nHere, $C_1$ and $C_2$ are complex, so they actually represent four arbitrary numbers. These four numbers should be fixed by the four initial conditions, i.e. $x(t=0), \\dot{x}(t=0), y(t=0)$ and $\\dot{y}(t=0)$. With some lengthy algebra, one can rewrite the expression as\n\\begin{eqnarray*}\n\\label{eq:precmess}\n\\eta&=&e^{-i\\Omega_zt}\\left[A\\cos(\\omega_0t+\\phi_A)+iB\\cos(\\omega_0t+\\phi_B)\\right].\n\\end{eqnarray*}\nHere, the four coefficients are represented by the two real arbitrary real amplitudes, $A$ and $B$, and two arbitrary phases, $\\phi_A$ and $\\phi_B$. For an initial condition where $y=0$ at $t=0$, one can see that $B=0$. This then gives\n\\begin{eqnarray*}\n\\eta(t)&=&Ae^{-i\\Omega_zt}\\cos(\\omega_0t+\\gamma)\\\\\n\\nonumber\n&=&A\\cos\\Omega_zt\\cos(\\omega_0t+\\gamma)+iA\\sin\\Omega_zt\\cos(\\omega_0t+\\gamma).\n\\end{eqnarray*}\nTranslating into $x$ and $y$,\n\\begin{eqnarray}\nx&=&A\\cos\\Omega_zt\\cos(\\omega_0t+\\gamma),\\\\\n\\nonumber\ny&=&A\\sin\\Omega_zt\\cos(\\omega_0t+\\gamma).\n\\end{eqnarray}\nAssuming the pendulum's frequency is much higher than Earth's rotational frequency, $\\omega_0>>\\Omega_z$, one can see that the plane of the pendulum simply precesses with angular velocity $\\Omega_z$. This means that in this limit the pendulum oscillates only in the $x$-direction with frequency many times before the phase $\\Omega_zt$ becomes noticeable. Eventually, when $\\Omega_zt=\\pi/2$, the motion is along the $y$-direction. If you were at the north pole, the motion would switch from the $x$-direction to the $y$ direction every 6 hours. Away from the north pole, $\\Omega_z\\ne|\\vec{\\Omega}|$ and the precession frequency is less.  At the equator it does not precess at all. If one were to repeat for the solutions where $A=0$ and $B\\ne 0$ in Eq. (\\ref{eq:precmess}), one would look at motions that started in the $y$-direction, then precessed toward the $-x$ direction. Linear combinations of the two sets of solutions give pendulum motions that resemble ellipses rather than simple back-and-forth motion.\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\n\\item Consider a pail of water spinning about a vertical axis at the center of the pail with frequency $\\omega$. Find the height of the water (within a constant) as a function the radius $r_\\perp$ from the axis of rotation. Use the concept of a centrifugal potential in the rotating frame.\n\n\\item A high-speed cannon shoots a projectile with an initial velocity\n  of 1000 m/s in the east direction. The cannon is situated in\n  Minneapolis (latitude of 45 degrees) The projectile velocity is\n  nearly horizontal and it hits the ground after a distance $x=3000$\n  m. Find the alteration of the point of impact in the north-south\n  ($y$) direction due to the Coriolis force. Assume the effect is\n  small so that you can approximate the eastward ($x$) component of\n  the velocity as being constant. Be sure to indicate whether the\n  deflection is north or south.\n\n\\item Someone wishes to use a Foucault pendulum as a crude clock. If the person lives in Minneapolis (latitude of $45^\\circ$), how much time will pass between having the pendulum swinging in the east-west direction until it swings in the north-south direction.\n\n\\end{enumerate}\n%\\end{document}\n", "meta": {"hexsha": "4008fcbe11fce634a7d563df259fb449a9574fa4", "size": 13604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/AdminBackground/lectures/chapter5.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/AdminBackground/lectures/chapter5.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/AdminBackground/lectures/chapter5.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": 66.3609756098, "max_line_length": 1011, "alphanum_fraction": 0.7280211702, "num_tokens": 4284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.6350837769816946}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath}\n\n\\begin{document}\n\n\\section{Why does Theorem VIII.1.14 not contradict Example VII.5.1}\n\nTake $\\mathbb{T}$ as the unit circle in the complex plane, and take $\\mathscr{A} = C(\\mathbb{T})$ and $\\mathscr{B}\\subset \\mathscr{A}$ the closure in $\\mathscr{A}$ of polynomials in $z$. $\\sigma_{\\mathscr{A}}(z)=\\mathbb{T}$ and $\\sigma_{\\mathscr{B}}(z)= cl \\mathbb{T} =$ unit disk.\n\nThis appears to contradict VIII.1.14 since $\\mathbb{B}$ is a subset of $\\mathscr{A}$ with a common identity (namely the function that maps $\\mathbb{T}$ to 1) and common norm (namely the sup norm), yet the spectra of a shared point (in this case z) differ.\n\nHowever, the premise of VIII.1.14  requires both $\\mathscr{A}$ and $\\mathscr{B}$ to be C* algebras, and while $\\mathscr{A}$ is closed under taking the adjoint, $\\mathscr{B}$ is not.\n\nTake z*, which as a function equals $z^{-1}/||z||$. The problem thus reduces to on what subset of the complex plane the function $1/z$ is holomorphic.\n\nHere my complex analysis is too weak, but certainly the whole unit disk would be no good since it contains a pole. I believe the circle is also out because of some fact about winding numbers that I can't remember.\n\n\\end{document}\n", "meta": {"hexsha": "eb5f3d9e7e546c127b6c4078c30a7381f598c526", "size": 1256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/8_C_star_Algebras/hw.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/8_C_star_Algebras/hw.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/8_C_star_Algebras/hw.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": 62.8, "max_line_length": 281, "alphanum_fraction": 0.722133758, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.6350837769099041}}
{"text": "\\section{Recursion Equations}\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Equation}\r\n  \\textbf{Recursion equation:}\r\n  \\begin{itemize}\r\n    \\item\r\n      Runtime description for recursive functions:\r\n  \\end{itemize}\r\n  \\vspace{2em}\r\n  \\begin{displaymath}\r\n    {\\color{MainA}T(n)} =\r\n    \\begin{cases}\r\n      \\hfill\r\n      \\smash{\r\n        \\overbrace{f_0(n)}^\\text{%\r\n          \\footnotesize%\r\n          trivial case for $n_0$\r\n        }\r\n      }\r\n      \\vphantom{f_0(n)} & n = n_0\\\\[0.5em]\r\n      \\smash{\r\n        \\underbrace{\r\n          a \\cdot {\\color{MainA}T\\left(\\frac{n}{b}\\right)}\r\n        }_\\text{\r\n          \\footnotesize%\r\n          \\begin{tabular}{c}\r\n            \\text{solving of {\\color{MainA}$a$}}\\\\\r\n            \\text{subproblems}\\\\\r\n            \\text{with reduced}\\\\\r\n            \\text{input size {\\color{MainA}$\\frac{n}{b}$}}\r\n          \\end{tabular}\r\n        }\r\n      } \\hspace{0.5em} + \\hspace{1.5em}\r\n      \\smash{\r\n        \\underbrace{\r\n          f(n)\r\n          \\vphantom{\\left(\\frac{n}{b}\\right)}\r\n        }_\\text{\r\n          \\makebox[0pt][c]{\r\n            \\footnotesize%\r\n            \\begin{tabular}{c}\r\n              slicing and\\\\\r\n              splicing of\\\\\r\n              subsolutions\r\n            \\end{tabular}\r\n          }\r\n        }\r\n      }\r\n      \\vphantom{\\left(\\frac{n}{b}\\right)}\r\n      &n > n_0\r\n    \\end{cases}\r\n  \\end{displaymath}\r\n  \\vspace{4em}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Equation}\r\n  \\textbf{Recursion equation:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n    Runtime descripion for recursive functions:\r\n    \\begin{displaymath}\r\n    {\\color{MainA}T(n)} = \\begin{cases}\r\n      f_0(n) & n = n_0\\\\\r\n      a \\cdot {\\color{MainA}T\\left(\\frac{n}{b}\\right)} + f(n) & n > n_0\r\n    \\end{cases}\r\n    \\end{displaymath}\r\n    \\item<3->\r\n      {\\color{MainA}$n_0$} is usually small, {\\color{MainA}$f_0(n_0) \\; \\in \\; \\Theta(1)$}\r\n    \\item<4->\r\n      Usually, {\\color{MainA}$a > 1$} and {\\color{MainA}$b > 1$}\r\n    \\item<5->\r\n      Dependent on the strategy of solving {\\color{MainA}$T(n)$}\r\n      {\\color{MainA}$f_0$} is ignored\r\n    \\item<6->\r\n      {\\color{MainA}$T(n)$} is only defined for integers of\r\n      {\\color{MainA}$\\frac{n}{b}$}, which is often ignored in benefit of\r\n      a simpler solution\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\subsection{Substitution Method}\r\n\r\n\\begin{frame}{Recursion Equations}{Substitution Method}\r\n  \\textbf{Substitution Method:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Guess the solution and prove it with induction\r\n    \\item<3->\r\n      Example:        \\color{MainA}\r\n      \\begin{displaymath}\r\n        T(n) = \\begin{cases}\r\n          \\hfill 1 & n = 1\\\\\r\n          2 \\cdot T\\left(\\frac{n}{2}\\right) + n & n > 1\r\n        \\end{cases}\r\n      \\end{displaymath}        \\color{black}\r\n    \\item<4->\r\n      Assumption:  {\\color{MainA}$T(n) = n + n \\cdot \\log_2 n$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Substitution Method}\r\n  \\textbf{Induction:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Induction basis (for {\\color{MainA}$n = 1$}):\r\n      ${\\color{MainA}T(1)} = 1 + 1 \\cdot \\log_2 1 = 1$\r\n    \\item<3->\r\n      Induction step (from {\\color{MainA}$\\frac{n}{2}$}\r\n      to {\\color{MainA}$n$}):\r\n      \\begin{align*}\r\n        \\onslide<4->{{\\color{MainA}T(n)} & =\r\n          2 \\cdot {\\color{MainA}T\\left(\\dfrac{n}{2}\\right)} + n\\\\}\r\n        \\onslide<5->{{} & \\stackrel{IA}{=} 2 \\cdot \\left(\r\n            \\dfrac{n}{2} + \\dfrac{n}{2} \\cdot \\log_2 \\dfrac{n}{2}\r\n          \\right) + n \\\\}\r\n        \\onslide<6->{{} & = 2 \\cdot \\left(\r\n            \\dfrac{n}{2} + \\dfrac{n}{2} \\cdot \\left(\\log_2 n - 1\\right)\r\n          \\right) + n}\\\\\r\n        \\onslide<7->{{} & = n + n \\, \\log_2 n - n + n\\\\}\r\n        \\onslide<8->{{} & = n + n \\, \\log_2 n}\r\n      \\end{align*}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Substitution Method}\r\n  \\textbf{Substitution Method:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Alternative assumption\r\n    \\item<3->\r\n      Example:\r\n      \\begin{displaymath}\r\n        \\color{MainA}\r\n        T(n) = \\begin{cases}\r\n          \\hfill 1 & n = 1\\\\\r\n          2 \\cdot T\\left(\\frac{n}{2}\\right) + n & n > 0\r\n        \\end{cases}\r\n      \\end{displaymath}\r\n    \\item<4->\r\n      Assumption:\r\n      {\\color{MainA}$T(n) \\, \\in \\, O(n \\, \\log n)$}\r\n    \\item<5->\r\n      Solution: Find {\\color{MainA}$c > 0$} with\r\n      {\\color{MainA}$T(n) \\leq c \\cdot n \\, \\log_2 n$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Substitution Method}\r\n  \\textbf{Induction:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Solution: Find {\\color{MainA}$c > 0$} with\r\n      {\\color{MainA}$T(n) \\leq c \\cdot n \\, \\log_2 n$}\r\n    \\item<3->\r\n      Induction step (from {\\color{MainA}$\\frac{n}{2}$} to\r\n      {\\color{MainA}$n$}):\r\n      \\begin{align*}\r\n        \\onslide<4->{{\\color{MainA}T(n)} & =\r\n          2 \\cdot {\\color{MainA}T\\left(\\dfrac{n}{2}\\right)} + n\\\\}\r\n        \\onslide<5->{{} & \\leq 2 \\cdot \\left(\r\n          c \\cdot \\dfrac{n}{2} \\, \\log_2 \\dfrac{n}{2}\\right) + n\\\\}\r\n        \\onslide<6->{{} & = c \\cdot n \\, \\log_2 n - c \\cdot n \\, \\log_2 2 + n\\\\}\r\n        \\onslide<7->{{} & = c \\cdot n \\, \\log_2 n - c \\cdot n + n\\\\}\r\n        \\onslide<8->{{} & \\leq c \\cdot n \\, \\log_2 n,\r\n          \\hspace{0.5em} {\\color{MainA}c \\geq 1}}\r\n      \\end{align*}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\subsection{Recursion Tree Method}\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Tree Method}\r\n  \\textbf{Recursion tree method:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Can be used to make assumptions about the runtime\r\n    \\item<3->\r\n      Example:\\\\\r\n      \\begin{displaymath}\r\n        {\\color{MainA}T(n)}\r\n        = 3 \\cdot {\\color{MainA}T\\left(\\dfrac{n}{4}\\right)} + \\Theta(n^2)\r\n        \\leq 3 \\cdot {\\color{MainA}T\\left(\\dfrac{n}{4}\\right)} + c \\cdot \r\n        n^2\r\n      \\end{displaymath}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Tree Method}\r\n  \\begin{figure}\r\n    \\begin{adjustbox}{width=\\linewidth}\r\n      \\input{Images/RecursionEquations/Example_RecursionTree.tikz}\r\n    \\end{adjustbox}\r\n    \\caption{recursion tree of example}\r\n    \\label{fig:recursion_equations:example_recursion_tree}\r\n  \\end{figure}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Tree Method}\r\n  \\begin{figure}\r\n    \\begin{adjustbox}{width=\\linewidth}\r\n      \\input{Images/RecursionEquations/Example_RecursionTree_Levels.tikz}\r\n    \\end{adjustbox}\r\n    \\caption{levels of the recursion tree}\r\n    \\label{fig:recursion_equations:example_recursion_tree_layer}\r\n  \\end{figure}\r\n\\end{frame}\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Tree Method Costs}\r\n  \\textbf{Costs of connecting the partial solutions:}\\\\\r\n  \\hspace{1.5em}(excludes the last layer)\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Size of partial problems on {\\color{MainA}level $i$}:\r\n      \\begin{math}\r\n        \\color{MainA}{\r\n          \\mathrm{s}_i(n) = \\left(\\frac{1}{4}\\right)^i \\cdot n\r\n        }\r\n      \\end{math}\r\n    \\item<3->\r\n      Costs of partial problems on {\\color{MainA}level $i$}:\r\n      \\begin{displaymath}\r\n        \\color{MainA}{\r\n          T_{i_p}(n) =\r\n          c \\cdot \\left(\\left(\\tfrac{1}{4}\\right)^i \\cdot n\\right)^2\r\n        }\r\n      \\end{displaymath}\r\n    \\item<4->\r\n      Number of partial problems on {\\color{MainA}level $i$}:\r\n      {\\color{MainA}$n_{i} = 3^{i}$}\r\n    \\item<5->\r\n      Costs on {\\color{MainA}level $i$}:\r\n        \\color{MainA}\r\n      \\begin{displaymath}\r\n        T_i(n) = 3^{i} \\cdot c \\cdot \\left(\r\n          \\left(\\tfrac{1}{4}\\right)^{i} \\cdot n\r\n        \\right)^2\r\n        = \\left(\\tfrac{3}{16}\\right)^{i} \\cdot c \\cdot n^2\r\n      \\end{displaymath}\r\n        \\color{black}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Recursion Tree Method Costs}\r\n  \\textbf{Costs of solving partial solutions:} (only the last layer)\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Size of partial problems on the {\\color{MainA}last level}:\r\n      {\\color{MainA}$\\mathrm{s}_{i+1}(n) = 1$}\r\n    \\item<3->\r\n      Costs of partial problem on the {\\color{MainA}last level}:\r\n      {\\color{MainA}$T_{i+1_p}(n) = d$}\r\n    \\item<4->\r\n      With this the depth of the tree is:\r\n      \\begin{displaymath}\r\n        \\left(\\tfrac{1}{4}\\right)^i \\cdot n = 1\r\n        \\hspace{1.5em}\\Rightarrow n = 4^i\r\n        \\hspace{1.5em}\\Rightarrow\\color{MainA} i = \\log_4 n\r\n      \\end{displaymath}\r\n      \\vspace{-1em}\r\n    \\item<5->\r\n      Number of partial problems on the {\\color{MainA}last level}:\r\n      \\begin{displaymath}\r\n        \\color{MainA}{n_{i+1} = 3^{\\log_4 n}    \\onslide<6-> \\quad=\r\n          n^{\\log_4 3}}  \\quad \\leftarrow \\text{next slide}\r\n      \\end{displaymath}\r\n    \\item<7->\r\n      Costs on the {\\color{MainA}last level}:\r\n      {\\color{MainA}$T_{i+1}(n) = d \\cdot n^{\\log_4 3}$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Fun with logarithm}{Logarithm}\r\n  \\begin{itemize}\r\n  \\item\r\n    Transforming $\\color{MainA}3^{\\log_4 n}$ using general log rules\r\n    {\\color{MainA}\r\n    \\begin{align*}\r\n      \\log_4 n & = \\log_4 \\left(3^{\\log_3 n} \\right) &&\r\n      \\qquad \\text{\\color{black}using } n= 3^{\\log_3 n}\\\\\r\n      \\onslide<2->{& = {\\log_3 n \\cdot \\log_4 3} &&\r\n        \\qquad \\text{\\color{black}using } \\log a^b = b \\cdot \\log a}\r\n    \\end{align*}}\r\n  \\item<3->\r\n    This proves the general log rule\r\n    {\\color{MainA}$\\log_b c = \\log_a c \\cdot \\log_b a$}\r\n  \\item<4->\r\n    Now the whole expression:\r\n\\color{MainA}\r\n    \\begin{align*}\r\n      3^{\\log_4 n} & = 3^{\\log_3 n \\cdot \\log_4 3} &&\r\n      \\qquad \\text{\\color{black}using reformulation above}\\\\\r\n      \\onslide<5->{& = {\\left(3^{\\log_3 n}\\right)}^{\\log_4 3} &&\r\n        \\qquad \\text{\\color{black}using }x^{a \\cdot b} = (x^a)^b}\\\\\r\n      \\onslide<6->{& = n^{\\log_4 3}}\r\n    \\end{align*}\r\n  \\item<7->\r\n    {\\color{gray}This term will recur in the master theorem}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Total costs}\r\n  \\textbf{Total costs:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Costs of {\\color{MainA}level i}:\r\n      $T_i(n) = \\left(\\frac{3}{16}\\right)^i \\cdot c \\cdot n^2$\r\n    \\item<3->\r\n      Costs of {\\color{MainA}last level}:\r\n      $T_{i+1}(n) = d \\cdot n^{\\log_4 3}$\r\n  \\end{itemize}\r\n  \\vspace{0.5em}\r\n  \\onslide<4->\r\n  \\begin{displaymath}\r\n    \\mathclap{T(n) =}\\underbrace{\r\n      \\sum\\limits_{i = 0}^{(\\log_4 n) - 1} \\left(\\tfrac{3}{16}\\right)^i\r\n      \\mathrlap{\\cdot c \\cdot n^2}\r\n    }_{\r\n      \\text{\r\n        \\footnotesize\r\n        \\begin{tabular}{c}\r\n          geometric series,\\\\\r\n          constant\\\\\r\n          \\color{gray}\r\n          $\\left(\\begin{array}{c}\r\n            \\text{even with}\\\\\r\n            \\text{infinite elements}\r\n          \\end{array}\\right)$\r\n        \\end{tabular}\r\n      }\r\n    } \\hspace{1.25em} + \\hspace{0.5em} \\underbrace{\r\n      d \\cdot n^{\\log_4 3}\r\n      \\vphantom{\\sum\\limits_{i = 0}^{(\\log_4 n) - 1}}\r\n    }_{\r\n      \\text{\r\n        \\makebox[0pt][c]{\r\n          \\footnotesize\r\n          \\begin{tabular}{c}\r\n            {\\color{MainA}$\\log_4 3 < 1$},\\\\\r\n            grows a lot\\\\\r\n            slower than {\\color{MainA}$n^2$}\r\n          \\end{tabular}\r\n        }\r\n      }\r\n    } ~ \\in \\mathcal{O}(n^2)\r\n  \\end{displaymath}\r\n  \\begin{itemize}\r\n    \\item<5->\r\n      Here: The costs of connecting the partial problems dominate\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Geometric Series}\r\n  \\begin{itemize}\r\n    \\item\r\n      \\textbf{Geometric progression:}\\\\\r\n      Quotient of two neighboring sequence parts is constant\r\n      \\begin{displaymath}\r\n        2^0, 2^1, 2^2, \\ldots, 2^k\r\n      \\end{displaymath}\r\n    \\item<2->\r\n      \\textbf{Geometric series:}\\\\\r\n      The series (cumulative sum) of a geometric sequence\\\\\r\n    \\item<3->\r\n      For $\\mid q \\mid < 1$:\r\n      \\begin{displaymath}\r\n        \\sum\\limits^{\\infty}_{k=0} a_0 \\cdot q^k = \\dfrac{a_0}{1 - q}\r\n        \\hspace{1.5em}\\Rightarrow\\text{constant}\r\n      \\end{displaymath}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Proof of $O(n^2)$}\r\n  \\textbf{Proof of $\\mathcal{O}(n^2)$:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      We know:\r\n      \\begin{align*}\r\n        T(n) &= 3T\\left(\\frac{n}{4}\\right) + \\Theta(n^2)\\\\\r\n        {} &\\leq 3T \\left(\\frac{n}{4}\\right) + c \\cdot n^2\r\n      \\end{align*}\r\n    \\item<3->\r\n      Assumption:\r\n      {\\color{MainA}$T(n) \\, \\in \\, \\mathcal{O}(n^2)$},\r\n      so there exists a {\\color{MainA}$k > 0$} with\r\n      \\begin{displaymath}\r\n        \\color{MainA}\r\n        T(n) \\leq k \\cdot n^2\r\n      \\end{displaymath}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Proof of $O(n^2)$}\r\n  \\textbf{Proof of $\\mathcal{O}(n^2)$:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Presumption:\r\n      {\\color{MainA}$T(n) \\, \\in \\, \\mathcal{O}(n^2)$},\r\n      so there exists a {\\color{MainA}$k > 0$} with\r\n      \\begin{displaymath}\r\n        \\color{MainA}{T(n) < k \\cdot n^2}\r\n      \\end{displaymath}\r\n    \\item<3->\r\n      Substitution method:\r\n      \\begin{align*}\r\n        \\onslide<4->{T(n) & \\leq 3 \\cdot T \\left( \\frac{n}{4}\\right)  + c \\cdot n^2\\\\}\r\n        \\onslide<5->{{} & \\leq 3 \\, k \\cdot \\left( \\frac{n}{4}\\right)^2  + c \\cdot n^2\\\\}\r\n        \\onslide<6->{{} & = \\frac{3}{16} \\, k \\cdot n^2  + c \\cdot n^2\\\\}\r\n        \\onslide<7->{{} & \\leq k \\cdot n^2\r\n        \\hspace{6em}\\text{for } k \\geq \\frac{16}{13} \\, c}\r\n      \\end{align*}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\subsection{Master theorem}\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem}\r\n  \\textbf{Master theorem:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Solution approach for a recursion equation of the form:\r\n      \\begin{displaymath}\r\n        \\color{MainA}{\r\n          T(n) = a \\cdot T\\left(\\frac{n}{b}\\right) + f(n),%\r\n          \\hspace{1.5em}a \\geq 1, b > 1\r\n        }\r\n      \\end{displaymath}\r\n    \\item<3->\r\n      {\\color{MainA}$T(n)$} is the runtime of an algorithm $\\ldots$\r\n      \\begin{itemize}\r\n        \\item<4->\r\n          $\\ldots$ which divides a {\\color{MainA}problem of size $n$}\r\n          in {\\color{MainA}$a$ partial problems}\r\n        \\item<5->\r\n          $\\ldots$ which solves each partial problem recursively\\newline\r\n          \\hphantom{$\\ldots$} with a\r\n          {\\color{MainA}runtime of $T\\left(\\tfrac{n}{b}\\right)$}\r\n        \\item<6->\r\n          $\\ldots$ which takes {\\color{MainA}$f(n)$} steps to\r\n          merge all partial solutions\r\n      \\end{itemize} \r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\subsubsection{Master theorem (Simple Form)}\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\textbf{Master theorem:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      In the examples we have seen that $\\ldots$\r\n      \\begin{itemize}\r\n        \\item<3->\r\n          Either the runtime of {\\color{MainA}connecting the solutions}\r\n          dominates\r\n        \\item<4->\r\n          Or the runtime of {\\color{MainA}solving the problems} dominates\r\n        \\item<5->\r\n          Or both have {\\color{MainA}equal influence on runtime}\r\n      \\end{itemize}\r\n    \\item<6->\r\n      \\textbf{Simple form:}\r\n      Special case with runtime of connecting the solutions\r\n      {\\color{MainA}$f(n) \\in O(n)$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\textbf{Simple form:}\r\n  \\onslide<2->\r\n  \\begin{displaymath}\r\n    \\color{MainA}{\r\n      T(n) = a \\cdot T\\left(\\frac{n}{b}\\right) +\r\n      \\underbrace{c \\cdot n}_{\r\n        \\text{\r\n          \\clap{\r\n            \\footnotesize\\color{black}\r\n            \\begin{tabular}{c}\r\n              Is any $f(n)$\\\\\r\n              in general form\r\n            \\end{tabular}\r\n          }\r\n        }\r\n      },\r\n      \\hspace{1.5em}a \\geq 1, b > 1, c > 0\r\n    }\r\n  \\end{displaymath}\r\n  \\begin{itemize}\r\n     \\item<3->\r\n       This yields a runtime of:\r\n  \\end{itemize}\r\n  \\onslide<4->\r\n  \\vspace{2em}\r\n  \\begin{displaymath}\r\n    T(n) = \\begin{cases}\r\n      \\Theta({\\color{MainA}\r\n        \\smash{\\overbrace{n^{\\log_b a}}^{\r\n          \\text{\\clap{Number of leaves}}\r\n        }}\r\n      }) & \\text{if } a > b\\\\\r\n      \\Theta(n \\, \\log n) & \\text{if } a = b\\\\\r\n      \\Theta(n) & \\text{if } a < b\r\n    \\end{cases}\r\n  \\end{displaymath}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\begin{figure}[!h]\r\n    \\begin{adjustbox}{width=\\linewidth}\r\n      \\def\\AlgoREDivide{3}% 3\r\n      \\def\\AlgoRESize{0.5}% 1/2\r\n      \\def\\AlgoREScale{4.444}% 15 / (3/2)^3\r\n      \\input{Images/RecursionEquations/ProblemSizeTree.tikz}\r\n    \\end{adjustbox}\r\n    \\caption{simple recursion equation with {\\color{MainA}$a = 3, b = 2$}}\r\n    \\label{fig:recursion_equations:master_theorem_tree_3_2}\r\n  \\end{figure}\r\n  \\onslide<2->\r\n  \\textbf{Case 1:} {\\color{MainA}$a > b$}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      Three partial problems with $\\frac{1}{2}$ the size\r\n    \\item<4->\r\n      Solving the partial problems dominates (last layer, leaves)\r\n    \\item<5->\r\n      Runtime of {\\color{MainA}$\\Theta(n^{\\log_b a})$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\begin{figure}[!h]\r\n    \\begin{adjustbox}{width=\\linewidth}\r\n      \\def\\AlgoREDivide{2}% 2\r\n      \\def\\AlgoRESize{0.5}% 1/2\r\n      \\def\\AlgoREScale{15}% 15\r\n      \\input{Images/RecursionEquations/ProblemSizeTree.tikz}\r\n    \\end{adjustbox}\r\n    \\caption{simple recursion equation with {\\color{MainA}$a = 2, b = 2$}}\r\n    \\label{fig:recursion_equations:master_theorem_tree_2_2}\r\n  \\end{figure}\r\n  \\onslide<2->\r\n  \\textbf{Case 2:} {\\color{MainA}$a = b$}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      Two partial problems with $\\frac{1}{2}$ the size\r\n    \\item<4->\r\n      Each layer has equal costs, $\\log n$ layers\r\n    \\item<5->\r\n      Runtime of {\\color{MainA}$\\Theta(n \\, \\log n)$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n%\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n%  \\begin{figure}[!h]\r\n%    \\begin{adjustbox}{width=\\linewidth}\r\n%      \\def\\AlgoREDivide{2}% 2\r\n%      \\def\\AlgoRESize{0.25}% 1/4\r\n%      \\def\\AlgoREScale{15}% 15\r\n%      \\input{Images/RecursionEquations/ProblemSizeTree.tikz}\r\n%    \\end{adjustbox}\r\n%    \\caption{simple recursion equation with\r\n%      {\\color{MainA}$a = 2, b = 4$}}\r\n%    \\label{fig:recursion_equations:master_theorem_tree_2_4}\r\n%  \\end{figure}\r\n%  \\textbf{Case 3:} {\\color{MainA}$a < b$}\r\n%  \\begin{itemize}\r\n%    \\item\r\n%      Two partial problems with $\\frac{1}{4}$ the size\r\n%    \\item\r\n%      Connecting all partial solutions dominates (first layer, root)\r\n%    \\item\r\n%      Runtime of {\\color{MainA}$\\Theta(n)$}\r\n%  \\end{itemize}\r\n%\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\begin{figure}[!h]\r\n    \\begin{adjustbox}{width=\\linewidth}\r\n      \\def\\AlgoREDivide{2}% 2\r\n      \\def\\AlgoRESize{0.33}% 1/3\r\n      \\def\\AlgoREScale{15}% 15\r\n      \\input{Images/RecursionEquations/ProblemSizeTree.tikz}\r\n    \\end{adjustbox}\r\n    \\caption{simple recursion equation with {\\color{MainA}$a = 2, b = 3$}}\r\n    \\label{fig:recursion_equations:master_theorem_tree_2_3}\r\n  \\end{figure}\r\n  \\onslide<2->\r\n  \\textbf{Case 3:} {\\color{MainA}$a < b$}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      Two partial problems with $\\frac{1}{3}$ the size\r\n    \\item<4->\r\n      Connecting all partial solutions dominates (first layer, root)\r\n    \\item<5->\r\n      Runtime of {\\color{MainA}$\\Theta(n)$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (Simple Form)}\r\n  \\textbf{For a recursion equation like}\r\n  \\begin{displaymath}\r\n    \\color{MainA}{%\r\n      T(n) = a \\cdot T\\left(\\frac{n}{b}\\right) + c \\cdot n,%\r\n      \\hspace{1.5em}a \\geq 1, b > 1, c > 0%\r\n    }%\r\n  \\end{displaymath}\r\n  \\vspace{-1.0em}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      $\\ldots$ yields a runtime of:\r\n  \\end{itemize}\r\n  \\onslide<3->\r\n  \\begin{displaymath}\r\n    T(n) = \\begin{cases}\r\n      \\Theta(n^{\\log_b a}) & \\text{if } a > b\\\\\r\n      \\Theta(n \\, \\log_b n) & \\text{if } a = b\\\\\r\n      \\Theta(n) & \\text{if } a < b\r\n    \\end{cases}\r\n  \\end{displaymath}\r\n  \\begin{itemize}\r\n    \\item<4->\r\n      Proof with \\textit{geometric series}:\r\n      Number of operations per layer grows / shrinks by constant factor\r\n      $\\tfrac{a}{b}$\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\subsubsection{Master theorem (General Form)}\r\n\r\n\\begin{frame}<beamer>{\\LectureToC}\r\n  \\tableofcontents[currentsection,\r\n    currentsubsection,\r\n    subsubsectionstyle=show/shaded/shaded/shaded]\r\n\\end{frame}\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form)}\r\n  \\textbf{Master theorem (general form):}\r\n  \\onslide<2->\r\n  \\begin{displaymath}\r\n  \\color{MainA}{%\r\n    T(n) = a \\cdot T\\left(\\frac{n}{b}\\right) + f(n),%\r\n    \\hspace{1.5em}a \\geq 1, b > 1%\r\n  }%\r\n  \\end{displaymath}\r\n  \\vspace{-1.0em}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      \\textbf{Case 1:}\r\n      {\\color{MainB}$T(n) \\in \\Theta(n^{\\log_b a})$}\r\n      \\hfill if {\\color{MainA}\r\n        $f(n) \\in \\mathcal{O}(n^{\\log_b a-\\varepsilon}), ~ \\varepsilon > 0$\r\n      }\\\\\r\n      {\\color{gray}Solving the partial problems dominates\\\\\r\n        (last layer, leaves)}\r\n      \\vspace{1.5em}\r\n    \\item<4->\r\n      \\textbf{Case 2:}\r\n      {\\color{MainB}$T(n) \\in \\Theta(n^{\\log_b a} \\log n)$}\r\n      \\hspace{1.5em} if {\\color{MainA}\r\n        $f(n) \\in \\Theta(n^{\\log_b a})$\r\n      }\\\\\r\n      {\\color{gray}Each layer has equal costs, $\\log_b n$ layers}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form)}\r\n  \\textbf{Master theorem (general form):}\r\n  \\begin{itemize}\r\n    \\item\r\n      \\textbf{Case 3:}\r\n      {\\color{MainB}$T(n) \\in \\Theta(f(n))$}\r\n      \\hfill if {\\color{MainA}\r\n        $f(n) \\in \\Omega(n^{\\log_b a+\\varepsilon}), ~ \\varepsilon > 0$\r\n      }\\\\\r\n      {\\color{gray}Connecting all partial solutions in first layer (root) dominates}\\\\[1.0em]\r\n      {\\color{MainA}Regularity condition:}\r\n      \\begin{align*}\r\n        a \\cdot f\\left(\\frac{n}{b}\\right) \\leq c \\cdot f(n), \\hspace{1.5em} &\r\n        0 \\leq c \\leq 1,\\\\\r\n        {} & n > n_0\r\n      \\end{align*}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form) - Case 1}\r\n  \\textbf{Case 1 - Example:}\r\n  \\onslide<2->{{\\color{MainB}$T(n) \\in \\Theta(n^{\\log_b a})$}}\r\n  \\hfill if {\\color{MainA}\r\n    $f(n) \\in O(n^{\\log_b a-\\varepsilon}), ~ \\varepsilon > 0$\r\n  }\\\\\r\n  {\\color{gray}Solving the partial problems dominates (last layer, leaves)}\r\n  \\vspace{1.0em}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      $T(n) = 8 \\cdot T(\\tfrac{n}{2}) + 1000 \\cdot n^2$\r\n      \\vspace{-0.5em}\r\n      \\begin{displaymath}\r\n        a = 8, ~ b = 2, ~ f(n) = 1000 \\cdot n^2, ~\r\n        \\smash{\\underbrace{\r\n          \\log_b a = \\log_2 8 = 3\r\n        }_{\\text{$n^3$ leaves}}}\r\n      \\end{displaymath}\r\n      {\\color{MainA}\\begin{math}\r\n        f(n) \\in \\mathcal{O}(n^{3-\\varepsilon})$\r\n        $\\Rightarrow$\r\n        $T(n) \\in \\Theta(n^3)\r\n      \\end{math}}\r\n      \\vspace{1.5em}\r\n    \\item<4->\r\n      $T(n) = 9 \\cdot T(\\tfrac{n}{3}) + 17 \\cdot n$\r\n      \\vspace{-0.5em}\r\n      \\begin{displaymath}\r\n        a = 9, ~ b = 3, ~ f(n) = 17 \\cdot n, ~\r\n        \\smash{\\underbrace{\r\n          \\log_b a = \\log_3 9 = 2\r\n        }_{\\text{$n^2$ leaves}}}\r\n      \\end{displaymath}\r\n      {\\color{MainA}\\begin{math}\r\n        f(n) \\in \\mathcal{O}(n^{2-\\varepsilon})$\r\n        $\\Rightarrow$\r\n        $T(n) \\in \\Theta(n^2)\r\n      \\end{math}}\r\n   \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form) - Case 2}\r\n  \\textbf{Case 2:}\r\n  \\onslide<2->{{\\color{MainB}$T(n) \\in \\Theta(n^{\\log_b a} \\log n)$}}\r\n  \\hspace{1.5em} if {\\color{MainA}\r\n    $f(n) \\in \\Theta(n^{\\log_b a})$\r\n  }\\\\\r\n  {\\color{gray}Each layer has equal costs, $\\log n$ layers}\r\n  \\vspace{1.0em}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      $T(n) = 2 \\cdot T(\\tfrac{n}{2}) + 10 \\cdot n$\r\n      \\vspace{-0.5em}\r\n      \\begin{displaymath}\r\n        a = 2, ~ b = 2, ~ f(n) = 10 \\cdot n, ~\r\n        \\smash{\\underbrace{\r\n          \\log_b a = \\log_2 2 = 1\r\n        }_{\\text{$n^1$ leaves}}}\r\n      \\end{displaymath}\r\n      {\\color{MainA}\\begin{math}\r\n        f(n) \\in \\Theta(n^{\\log_2 2})$\r\n        $\\Rightarrow$\r\n        $T(n) \\in \\Theta(n \\, \\log n)\r\n      \\end{math}}\r\n      \\vspace{1.0em}\r\n    \\item<4->\r\n      $T(n) = T(\\tfrac{2\\,n}{3}) + 1$\r\n      \\vspace{-0.5em}\r\n      \\begin{displaymath}\r\n        a = 1, ~ b = \\tfrac{3}{2}, ~ f(n) = 1, ~\r\n        \\smash{\\underbrace{\r\n          \\log_b a = \\log_{\\nicefrac{3}{2}} 1 = 0\r\n        }_{\\text{$n^0$ leaves $=$ 1 leaf}}}\r\n      \\end{displaymath}\r\n      \\hfill\\\\[1.0em]\r\n      {\\color{MainA}\\begin{math}\r\n        f(n) \\in \\Theta(n^{\\log_{\\nicefrac{3}{2}} 1})$\r\n        $\\Rightarrow$\r\n        $T(n) \\in \\Theta(n^0 \\log n) = \\Theta(\\log n)\r\n      \\end{math}}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form) - Case 3}\r\n  \\textbf{Case 3:}\r\n  \\onslide<2->{{\\color{MainB}$T(n) \\in \\Theta(f(n))$}}\r\n  \\hfill if {\\color{MainA}\r\n    $f(n) \\in \\Omega(n^{\\log_b a+\\varepsilon}), ~ \\varepsilon > 0$\r\n  }\\\\\r\n  {\\color{gray}Connecting all partial solutions in first layer (root) dominates}\r\n  \\vspace{1.0em}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      $T(n) = 2 \\cdot T(\\tfrac{n}{2}) + n^2$\r\n      \\vspace{-0.5em}\r\n      \\begin{displaymath}\r\n        a = 2, ~ b = 2, ~ f(n) = n^2, ~\r\n        \\smash{\\underbrace{\r\n          \\log_b a = \\log_2 2 = 1\r\n        }_{\\text{$n^1$ leaves}}}\r\n      \\end{displaymath}\r\n      {\\color{MainA}$f(n) \\in \\Omega(n^{1+\\varepsilon})$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form) - Case 3}\r\n  \\textbf{Case 3:}\r\n  {\\color{MainB}$T(n) \\in \\Theta(f(n))$}\r\n  \\hfill if {\\color{MainA}\r\n    $f(n) \\in \\Omega(n^{\\log_b a+\\varepsilon}), ~ \\varepsilon > 0$\r\n  }\\\\\r\n  {\\color{gray}Connecting all partial solutions in first layer (root) dominates}\r\n  \\vspace{1.0em}\r\n  \\begin{itemize}\r\n    \\item\r\n      $T(n) = 2 \\cdot T(\\tfrac{n}{2}) + n^2$\r\n    \\item<3->\r\n      {\\color{MainA}$f(n) \\in \\Omega(n^{1+\\varepsilon})$}\r\n    \\item<4->\r\n      Check if {\\color{MainA}regularity condition} also holds:\\\\\r\n      \\begin{align*}\r\n        a \\cdot f\\left(\\frac{n}{b}\\right) &\\leq c \\cdot f(n)\\\\\r\n        2 \\cdot \\left(\\frac{n}{2}\\right)^2 &\\leq c \\cdot n^2\r\n        \\hspace{1.5em} \\Rightarrow \\frac{1}{2} \\cdot n^2 \\leq c \\cdot n^2\r\n        \\hspace{1.5em} \\Rightarrow c \\geq \\frac{1}{2}\r\n      \\end{align*}\r\n      {\\color{MainA}$\\Rightarrow T(n) \\in \\Theta(n^2)$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem (General Form)}\r\n  \\textbf{Master theorem:}\r\n  \\begin{itemize}\r\n    \\item<2->\r\n      Not always applicable:\r\n      {\\color{MainA}$T(n) = 2 \\cdot T(\\frac{n}{2}) + n \\, \\log n$}\r\n  \\end{itemize}\r\n  \\onslide<3->\r\n  \\vspace{1.0em}\r\n  \\begin{displaymath}\r\n    a = 2, ~ b = 2, ~ f(n) = n \\, \\log n, ~\r\n    \\underbrace{\\log_b a = \\log_2 2 = 1}_{\\text{$n^1$ leaves}}\r\n  \\end{displaymath}\r\n  \\begin{itemize}\r\n    \\item<4->\r\n      \\textbf{Case 1:}\r\n      $f(n) \\notin O(n^{1-\\varepsilon})$\r\n    \\item<5->\r\n      \\textbf{Case 2:}\r\n      $f(n) \\notin \\Theta(n^1)$\r\n    \\item<6->\r\n      \\textbf{Case 3:}\r\n      $f(n) \\notin \\Omega(n^{1+\\varepsilon})$\r\n  \\end{itemize}\r\n  \\onslide<7->\r\n  \\begin{center}\r\n    {\\color{MainA}$n \\, \\log n$} is \\textit{asymptotically} larger than\r\n    {\\color{MainA}$n$},\\\\ but not \\textit{polynominal} larger\r\n  \\end{center}\r\n\\end{frame}\r\n\r\n%-------------------------------------------------------------------------------\r\n\r\n\\begin{frame}{Recursion Equations}{Master theorem - Summary}\r\n  \\textbf{Master theorem:}\r\n  \\onslide<2->\r\n  \\begin{displaymath}\r\n    \\color{MainA}{\r\n      T(n) = a \\cdot T\\left(\\frac{n}{b}\\right) + f(n)\r\n    }\r\n  \\end{displaymath}\r\n  \\vspace{-1.0em}\r\n  \\begin{itemize}\r\n    \\item<3->\r\n      Three cases depending on the dominance of the terms\r\n    \\item<4->\r\n      \\textbf{Case 1:}\r\n      Solving the partial problems is \\textit{polynominal} bigger than merging\r\n      all solutions\\\\\r\n      {\\color{MainA}$T(n) \\in \\Theta(n^{\\log_b a})$}, \\hspace{3.5em}\r\n      {\\color{gray}$T(n) \\in \\Theta(\\text{number of leaves})$}\r\n      \\vspace{0.5em}\r\n   \\item<5->\r\n     \\textbf{Case 2:}\r\n     Each layer has equal costs\\\\\r\n     {\\color{MainA}$T(n) \\in \\Theta(n^{\\log_b a} \\log n)$}, \\hspace{1.5em}\r\n     {\\color{gray}$\\log n$ layers}\r\n     \\vspace{0.5em}\r\n   \\item<6->\r\n     \\textbf{Case 3:}\r\n     Connecting all partial solutions is \\textit{polynominal} bigger than\r\n     solving all partial problems\\\\\r\n     {\\color{MainA}$T(n) \\in \\Theta(f(n))$}\r\n  \\end{itemize}\r\n\\end{frame}\r\n", "meta": {"hexsha": "75557b573ffd3b756aeae6cb8fd8a8e4dc0adf53", "size": 30874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-9/Chapter/eng/020_RecusionEquations.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-9/Chapter/eng/020_RecusionEquations.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-9/Chapter/eng/020_RecusionEquations.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.8796592119, "max_line_length": 94, "alphanum_fraction": 0.4988339703, "num_tokens": 10198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6350837674324118}}
{"text": "\\section{State Error Objective}\n\n\t\\begin{frame}\n\t\t\\frametitle{Robot Models Used}\n\t\t\\begin{columns}[T]\n\t\t\t\\begin{column}{0.45\\textwidth}\n\t\t\t\t\\onslide<2->{\n\t\t\t\t\\begin{block}{Cartesian Co-ordinate Model}\n\t\t\t\t\t\\[\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\dot{x} \\\\\n\t\t\t\t\t\t\\dot{y} \\\\\n\t\t\t\t\t\t\\dot{\\theta}\n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t=\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\cos(\\theta) & 0 \\\\\n\t\t\t\t\t\t\\sin(\\theta) & 0 \\\\\n\t\t\t\t\t\t0 & 1\n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\upsilon \\\\\n\t\t\t\t\t\t\\omega \n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t\\]\n\t\t\t\t\\end{block}\n\t\t\t\t}\n\t\t\t\t\\onslide<3->{\n\t\t\t\t\\begin{block}{Kino-dynamic Model}\n\t\t\t\t\t\\[\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\dot{x} \\\\\n\t\t\t\t\t\t\\dot{y} \\\\\n\t\t\t\t\t\t\\dot{\\theta} \\\\\n\t\t\t\t\t\t\\dot{\\upsilon} \\\\\n\t\t\t\t\t\t\\dot{\\omega}\n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t=\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\cos(\\theta) & 0 & 0 & 0 \\\\\n\t\t\t\t\t\t\\sin(\\theta) & 0 & 0 & 0 \\\\\n\t\t\t\t\t\t0 & 1 & 0 & 0 \\\\\n\t\t\t\t\t\t0 & 0 & 1 & 0 \\\\\n\t\t\t\t\t\t0 & 0 & 0 & 1\n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\t\\upsilon \\\\\n\t\t\t\t\t\t\\omega \\\\\n\t\t\t\t\t\ta \\\\\n\t\t\t\t\t\t\\alpha\n\t\t\t\t\t\\end{bmatrix}\n\t\t\t\t\t\\]\n\t\t\t\t\\end{block}\n\t\t\t\t}\n\t\t\t\\end{column}\n\t\t\t\\begin{column}{0.49\\textwidth}\n\t\t\t\t\\centering\n\t\t\t\t\\onslide<1->{\\includegraphics[scale=0.35]{pictures/robot_cart.pdf}}\n\t\t\t\\end{column}\n\t\t\\end{columns}\n\t\\end{frame}\n\n\t\\begin{frame}\n\t\t\\frametitle{Robot Models Used}\n\t\t\\begin{columns}[T]\n\t\t\t\\begin{column}{0.45\\textwidth}\n\t\t\t\t\\onslide<2->{\n\t\t\t\t\\begin{block}{Polar Co-ordinate Model}\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\\rho& = \\sqrt{(x-x_g)^2+(y-y_g)^2} \\\\[0.4cm]\n\t\t\t\t\t\t\\phi& = \\arctan2\\big((y-y_g),(x-x_g)\\big) \\\\[0.4cm]\n\t\t\t\t\t\t\\alpha&= \\theta - \\phi\n\t\t\t\t\t\\end{align*}\n\t\t\t\t\\end{block}\n\t\t\t\t}\n\t\t\t\\end{column}\n\t\t\t\\begin{column}{0.49\\textwidth}\n\t\t\t\t\\centering\n\t\t\t\t\\onslide<1->{\\includegraphics[scale=0.35]{pictures/robot_polar.pdf}}\n\t\t\t\\end{column}\n\t\t\\end{columns}\n\t\\end{frame}\n\n\t\\begin{frame}\n\t\t\\frametitle{NMPC General Formulation}\n\t\t\\begin{block}{NMPC Optimization Problem}\n\t\t\t\\begin{align*}\n\t\t\t\t&\\underset{\\mathbf{X}^*,\\mathbf{U}^*}{\\text{min    }}\n\t\t\t\t\\tikzmark{a9}J_{N_p}(\\mathbf{x}_k) = \\sum_{j=0}^{N_p}\\tikzmark{a11}\\ell (\\mathbf{x}_{k + j},\\mathbf{u}_{k + j}), \\\\\n\t\t\t\t&\\quad \\text{subject to:} \\notag  \\\\\n\t\t\t\t&\\quad\\quad \\tikzmark{a12}\\mathbf{x}_{k+j+1} = \\mathcal{F}(\\mathbf{x}_{k+j},\\mathbf{u}_{k+j}), & \\forall\\text{ } 0\\leq j\\leq N_p-1  \\\\ \n\t\t\t\t&\\quad\\quad \\tikzmark{a13}\\mathbf{x}_{k+j} \\in \\mathbb{X}, & \\forall \\text{ }0\\leq j\\leq N_p \\\\\n\t\t\t\t&\\quad\\quad \\tikzmark{a14}\\mathbf{u}_{k+j} \\in \\mathbb{U}, & \\forall \\text{ }0\\leq j\\leq N_p-1 \\\\\n\t\t\t\t&\\quad\\quad \\tikzmark{a15}\\mathbf{d}_{\\imath,k+j}  \\geq \\xi_o, & \\forall\\text{ } 0\\leq j\\leq N_p-1, \\text{ }\\forall\\text{ } \\imath \\in I_s\n\t\t\t\\end{align*}\n\t\t\\end{block}\n\t\n\t\t\\begin{tikzpicture}[overlay, remember picture]\n\t\t\t\\coordinate (A9) at ($({pic cs:a9})+(1ex, 1ex)$);\n\t\t\t\\coordinate (A11) at ($({pic cs:a11})+(1ex, 1ex)$);\n\t\t\t\\coordinate (A12) at ($({pic cs:a12})+(0ex, 0.5ex)$);\n\t\t\t\\coordinate (A13) at ($({pic cs:a13})+(0ex, 0.5ex)$);\n\t\t\t\\coordinate (A14) at ($({pic cs:a14})+(0ex, 0.5ex)$);\n\t\t\t\\coordinate (A15) at ($({pic cs:a15})+(1ex, -0.5ex)$);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A9), baseline] (n9) {};\n\t\t\t\\node[cyan, above of= n9, node distance = 3em] (t9_1) {\\small cost};\n\t\t\t\\node[cyan, above of= n9, node distance = 2em] (t9) {\\small function};\n\t\t\t\\draw [<-, cyan] (n9.north) to [below] (t9.south);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A11), baseline] (n11) {};\n\t\t\t\\node[cyan, above of= n11, node distance = 3em] (t11_1) {\\small regulatory};\n\t\t\t\\node[cyan, above of= n11, node distance = 2em] (t11) {\\small term};\n\t\t\t\\draw [<-, cyan] (n11.north) to [below] (t11.south);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A12), baseline] (n12) {};\n\t\t\t\\node[cyan, left of= n12, node distance = 4em] at (2.8,3) (t12) {\\small model};\n\t\t\t\\node[cyan, below of= t12, node distance = 1em] (t12_1) {\\small constraints};\n\t\t\t\\draw [<-, cyan] (n12.west) to [right] (t12.east);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A13), baseline] (n13) {};\n\t\t\t\\node[cyan, left of= n13, node distance = 4em] (t13) {\\small state};\n\t\t\t\\node[cyan, below of= t13, node distance = 1em] (t13_1) {\\small boundries};\n\t\t\t\\draw [<-, cyan] (n13.west) to [right] (t13.east);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A14), baseline] (n14) {};\n\t\t\t\\node[cyan, below of= t13, node distance = 3em] (t14) {\\small input};\n\t\t\t\\node[cyan, below of= t14, node distance = 1em] (t14_1) {\\small boundries};\n\t\t\t\\draw [<-, cyan] (n14.west) to [right] (t14.east);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A15), baseline] (n15) {};\n\t\t\t\\node[cyan, below of= n15, node distance = 3em] (t15_1) {\\small static};\n\t\t\t\\node[cyan, below of= n15, node distance = 2em] (t15) {\\small obstacles};\n\t\t\t\\draw [<-, cyan] (n15.south) to [above] (t15.north);\n\t\t\\end{tikzpicture}\n\t\\end{frame}\n\t\n\t\\begin{frame}\n\t\t\\frametitle{NMPC General Formulation}\n\t\t\\begin{block}{Regulatory Terms (e.g., Cartesian coordinate)}\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\ell (\\mathbf{x}_{k + j},\\mathbf{u}_{k + j}) = \\enspace\n\t\t\t\t\t\\tikzmark{a1}\n\t\t\t\t\t(\\mathbf{x}_{k + j} - \\mathbf{x}_{ref})^T \\enspace \\mathbf{Q_1} \\enspace (\\mathbf{x}_{k + j} - \\mathbf{x}_{ref})\n\t\t\t\t\t\\tikzmark{a2}\n\t\t\t\t\t\\enspace + \\enspace\n\t\t\t\t\t\\tikzmark{a3}\n\t\t\t\t\t\\Delta\\mathbf{u}_{k + j}^T \\enspace \\mathbf{R} \\enspace \\Delta\\mathbf{u}_{k + j}\n\t\t\t\t\t\\tikzmark{a4}\n\t\t\t\t\t\\enspace \\tikzmark{a7}-\\tikzmark{a8} \\enspace\n\t\t\t\t\t\\tikzmark{a5} \n\t\t\t\t\t\\sum_{i=0}^{I} \\mathbf{d}_{i,k + j}^T \\enspace \\mathbf{Q_2} \\enspace \\mathbf{d}_{i,k + j}\n\t\t\t\t\t\\tikzmark{a6}\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\\end{block}\n\t\t\\vfill\n\t\t\\vfill\n\t\t\\vfill\n\t\t\\begin{itemize}\n\t\t\t\\item $\\mathbf{d}_{i,k + j}$: distance between the robot and $i^{th}$ detected moving obstacle.\n\t\t\\end{itemize}\n\t\t\n\t\t\\begin{tikzpicture}[overlay, remember picture]\n\t\t\t\\coordinate (A1) at ($({pic cs:a1})+(+0.1ex, 2ex)$);\n\t\t\t\\coordinate (A2) at ($({pic cs:a2})+(-0.1ex,-0.5ex)$);\n\t\t\t\\coordinate (A3) at ($({pic cs:a3})+(+0.1ex, 2ex)$);\n\t\t\t\\coordinate (A4) at ($({pic cs:a4})+(-0.1ex,-0.5ex)$);\n\t\t\t\\coordinate (A5) at ($({pic cs:a5})+(+0.1ex, 3.5ex)$);\n\t\t\t\\coordinate (A6) at ($({pic cs:a6})+(-0.1ex,-2.5ex)$);\n\t\t\t\\coordinate (A7) at ($({pic cs:a7})+(+1ex, 0.5ex)$);\n\t\t\t\\coordinate (A8) at ($({pic cs:a8})+(-1ex, 0.5ex)$);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A1)(A2), draw=tugreen, thick, rounded corners] (n1) {};\n\t\t\t\\node[overlay, below of= n1, node distance = 6em] (t1) {State Error};\n\t\t\t\\node[overlay, below of= n1, node distance = 7em] (t1_1) {Objective};\n\t\t\t\\draw [thick, -latex, tugreen] (n1.south) to [above] (t1.north);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A3)(A4), draw=tugreen, thick, rounded corners] (n2) {};\n\t\t\t\\node[overlay, below of= n2, node distance = 6em] (t2) {Input Penealty};\n\t\t\t\\node[overlay, below of= n2, node distance = 7em] (t2_1) {Objective};\n\t\t\t\\draw [thick, -latex, tugreen] (n2.south) to [above] (t2.north);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A5)(A6), draw=tugreen, thick, rounded corners] (n3) {};\n\t\t\t\\node[overlay, below of= n3, node distance = 5.7em] (t3) {Dyn Obstacles};\n\t\t\t\\node[overlay, below of= n3, node distance = 6.7em] (t3_1) {Objective};\n\t\t\t\\draw [thick, -latex, tugreen] (n3.south) to [above] (t3.north);\n\t\t\t\\pause\n\t\t\t\\node [fit=(A7)(A8), draw=red, circle] (n4) {};\n\t\t\t\\node[overlay, red, above of= n4, node distance = 8em] (t4) {Maximization};\n\t\t\t\\draw [thick, -latex, red] (n4.north) to [below] (t4.south);\n\t\t\\end{tikzpicture}\n\t\t\n%\t\t\\tikz[baseline=(n1.base)]{\n%\t\t\t\\node[draw=tugreen, ,thick, rounded corners, inner sep=5pt] \n%\t\t\t(n1){$xfoz$};\n%\t\t\t\\node[overlay, below of= n1, node distance = 6em] (t1) {State Error};\n%\t\t\t\\draw [thick, -latex, tugreen] (n1.south) to [above] (t1.north);\n%\t\t}\n\t\\end{frame}\n\t\n%\t\\begin{frame}\n%\t\t\\frametitle{Cartesian Coordinate Model Block Diagram}\n%\t\t\\begin{figure}[hbtp]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[scale=0.7]{pictures/block_diagram_cart.pdf}\n%\t\t\t\\caption{NMPC Control Loop (Cartesian coordinate Model)}\n%\t\t\\end{figure}\n%\t\\end{frame}\n\n\t\\begin{frame}\n\t\t\\frametitle{NMPC General Formulation}\n\t\t\\begin{block}{Regulatory Terms (e.g., Polar coordinate)}\n\t\t\t\\parbox[c][4\\baselineskip][t]{\\textwidth}{\n\t\t\t\\begin{align*}\n\t\t\t\t\\ell_p (\\vartheta_{k + j},\\mathbf{u}_{k + j}) &= \n\t\t\t\t\\pmb{[} \\ell_{p,1}(\\cdot,\\cdot) \\enspace \\ell_{p,2}(\\cdot,\\cdot) \\enspace \\ell_{p,3}(\\cdot,\\cdot) \\pmb{]}\n\t\t\t\t\\enspace\n\t\t\t\t\\mathbf{Q_1} \\enspace\n\t\t\t\t\\begin{bmatrix}\n\t\t\t\t\t\\ell_{p,1}(\\cdot,\\cdot) \\\\\n\t\t\t\t\t\\ell_{p,2}(\\cdot,\\cdot) \\\\\n\t\t\t\t\t\\ell_{p,3}(\\cdot,\\cdot)\n\t\t\t\t\\end{bmatrix}\n\t\t\t\t+ \\cdots\n\t\t\t\\end{align*}\n\t\t\t}\n\t\t\\end{block}\n\t\tError state objective is the minimization of: \\\\[0.5cm]\n\t\t\\begin{itemize}\n\t\t\t\\item Euclidean distance: $\\ell_{p,1}(\\cdot,\\cdot) = \\sqrt{(x_{k+j} - x_{ref})^2+(y_{k+j} - y_{ref})^2}$ \\\\ [0.2cm]\n\t\t\t\\item Heading towards goal: $\\ell_{p,2}(\\cdot,\\cdot) = \\Big(\\theta_{k+j} - \\arctan2\\big((y_{k+j} - y_{ref}),(x_{k+j} - x_{ref})\\big)\\Big)^2$ \\\\ [0.2cm]\n\t\t\t\\item Reference orientation: $\\ell_{p,3}(\\cdot,\\cdot) = (\\theta_{k+j} - \\theta_{ref})^2$\n\t\t\\end{itemize}\n\t\\end{frame}\n\n%\t\\begin{frame}\n%\t\t\\frametitle{Polar Coordinate Model Block Diagram}\n%\t\t\\begin{figure}[hbtp]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[scale=0.64]{pictures/block_diagram_polar.pdf}\n%\t\t\t\\caption{NMPC Control Loop (Polar coordinate Model)}\n%\t\t\\end{figure}\n%\t\\end{frame}\n\n%\t\\begin{frame}\n%\t\t\\frametitle{Kino-dynamic Model Block Diagram}\n%\t\t\\begin{figure}[hbtp]\n%\t\t\t\\centering\n%\t\t\t\\includegraphics[scale=0.64]{pictures/block_diagram_kino.pdf}\n%\t\t\t\\caption{NMPC Control Loop (Kino-dynamic Model)}\n%\t\t\\end{figure}\n%\t\\end{frame}\n\n\t\\begin{frame}\n\t\t\\frametitle{Potential Collision Zone}\n\t\t\\centering\n\t\t\\includegraphics[scale=0.6]{pictures/robots_pot_coll.pdf}\n\t\\end{frame}\n\n", "meta": {"hexsha": "770e8a8bce9c050fbe64228db15138ba9438669b", "size": 9337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Kapitel_4.tex", "max_stars_repo_name": "smababou/latex_presentation", "max_stars_repo_head_hexsha": "c38b668cff733fc6feacbc135b5a785e6c7b32ef", "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": "Kapitel_4.tex", "max_issues_repo_name": "smababou/latex_presentation", "max_issues_repo_head_hexsha": "c38b668cff733fc6feacbc135b5a785e6c7b32ef", "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": "Kapitel_4.tex", "max_forks_repo_name": "smababou/latex_presentation", "max_forks_repo_head_hexsha": "c38b668cff733fc6feacbc135b5a785e6c7b32ef", "max_forks_repo_licenses": ["Beerware"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.6374045802, "max_line_length": 154, "alphanum_fraction": 0.5866980829, "num_tokens": 3964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.635075759052575}}
{"text": "\\section*{Web Appendix F}\n\nRecall that a density $f(x;\\theta)$ is identifiable if $f(x;\\theta_{1})=f(x;\\theta_{2})$\nfor all $x$ implies that $\\theta_{1}=\\theta_{2}.$ Call a density\n$f(x;\\theta)$ \\textit{strongly identifiable} if $f(x;\\theta_{1})/f(x;\\theta_{2})$\nbeing constant for all $x$ in an open interval $I$ implies that\n$\\theta_{1}=\\theta_{2}$.\n\\paragraph{Proposition A.}\\label{prop:identifiable}\n\nLet $f(x;\\theta)$ be a family of densities on $\\mathbb{R}$, $-\\infty=a_{1}<a_{2}<\\ldots<a_{k+1}=\\infty$\na sequence of cutoffs, and $f_{[a_{i},a_{i+1})}(x;\\theta)$ the density\n$f$ truncated to $[a_{i},a_{i+1})$. Let $\\lambda_{i},k=1,\\ldots k$\nbe positive numbers satisfying $\\sum_{i=1}^{k}\\lambda_{i}=1$. Then\nthe mixture\n\\[\ng(x;\\lambda,\\theta)=\\sum_{i=1}^{k}\\lambda_{i}f_{[a_{i},a_{i+1})}(x;\\theta)\n\\]\nis identifiable in $(\\lambda,\\theta)$ if $f(x;\\theta)$ is strongly\nidentifiable in $\\theta$.\n\n\\paragraph{Proof.}\nAssume that $g(x;\\lambda_{1},\\theta_{1})=g(x;\\lambda_{2},\\theta_{2})$.\nThen $$\\lambda_{1i}f_{[a_{i},a_{i+1})}(x;\\theta_{1})=\\lambda_{2i}f_{[a_{i},a_{i+1})}(x;\\theta_{2})$$\nfor all $i$, thus\n\\[\n\\frac{\\lambda_{1i}}{\\lambda_{2i}}=\\frac{f_{[a_{i},a_{i+1})}(x;\\theta_{1})}{f_{[a_{i},a_{i+1})}(x;\\theta_{2})}.\n\\]\nThis implies that $f(x;\\theta_{1})/f(x;\\theta_{2})$ is constant for\n$x\\in[a_{i},a_{i+1})$. But since $f(x;\\theta)$ is strongly identifiable,\n$\\theta_{1}=\\theta_{2}$, and, consequently, $\\lambda_1 = \\lambda_2$.\n\n\nIf $f(x;\\theta)$ is real analytic and nowhere zero, $f(x;\\theta_{1})/f(x;\\theta_{2})$\nis also real analytic and nowhere zero. By the Identity Theorem \\citep[Corollary 1.2.6]{Krantz2002-bt}, if the ratio\n$f(x;\\theta_{1})/f(x;\\theta_{2})$ is constant on some interval $I$,\nthen $f(x;\\theta_{1})/f(x;\\theta_{2})$ is constant everywhere, hence\n$f(x;\\theta_{1})=f(x;\\theta_{2})$ everywhere. Thus a family of real\nanalytic nowhere zero densities is identifiable if and only if it is\nstrongly identifiable. Every exponential family of densities on the form\n\\[\nf(x;\\theta)=h(x)\\exp(\\eta(\\theta)^{T}T(x)-A(\\theta))\n\\]\nsatisfies this property, provided only that $h$ is nowhere zero real analytic\nand $T$ is real analytic. In particular, the normal family satisfies\nthe properties.\n\nNot every density is strongly identifiable. For instance, mixtures of uniforms are not strongly identifiable. And indeed, Proposition A fails when $f$ is a mixture of uniforms.\n", "meta": {"hexsha": "c1c86018f4c063f506bca724f68bac466de5c2bd", "size": 2389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WebAppendix_F.tex", "max_stars_repo_name": "JonasMoss/p-hacking", "max_stars_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-14T23:18:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-14T23:18:58.000Z", "max_issues_repo_path": "WebAppendix_F.tex", "max_issues_repo_name": "JonasMoss/p-hacking", "max_issues_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-07-29T11:31:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-06T14:38:26.000Z", "max_forks_repo_path": "WebAppendix_F.tex", "max_forks_repo_name": "JonasMoss/p-hacking", "max_forks_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "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.7708333333, "max_line_length": 176, "alphanum_fraction": 0.6768522394, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6350336073029567}}
{"text": "\n\\section{Introduction}\n\nNeurons, like all other cells, require proteins to function. Because of their morphological diversity and the fact that synapses can be hundreds of micrometers away from the some, neurons require an exquisite control of protein and mRNA distributions in both time and space.\nExperimental evidence indicate the presence of mRNA in dendrites and recent reports highlight the importance of local translation in various forms of synaptic plasticities \\supercite{Hafner2019, Younts2016}.  \n\nIn their article, Fonkeu et al. (2019) develop a model framework to capture the spatial profiles of mRNA and protein in dendrites while taking into account: production, degradation, uni- and bi-directional transport \\supercite{Fonkeu2019}. Validation of the model is obtained  by comparing with experimental data obtained from the analysis of CaMKII$\\alpha$ mRNA, a major kinase involved in synaptic plasticity. \n\nHere, we aimed at replicating model-based figures (therefore excluding Figures 2, 4, S1, S2, S3 that are either experimental or explanatory models). Code was not available on public repositories, except small pieces of scripts. Overall, the replication was successfull with only minor quantitative differences. \n\n\\section{Methods}\n\nThe model is based on the following equations:\n\n\\textbf{Equation 1} describes the mRNA dynamics using transcription rate ($\\beta_{R}$), passive diffusion ($D_{R}$), transport velocity ($\\nu_{R}$), degradation rate ($k_{R}$) and half-life ($T_{1/2}$).\n\\begin{equation}\n  R^{den}_{ss}(x) = \\frac{\\beta_{R}\\lambda_{R}}{k_{R}} e^{-\\lambda_{R}x}x\n\\end{equation}\nwhere $\\lambda_{R} = \\frac{\\sqrt{\\nu^{2}_{R} + 4D_{R}k_{R}}-\\nu_{R}}{2D_{R}}$ and $k = \\frac{\\ln{2}}{T_{1/2}}$, $T_{1/2}$ being in seconds.\n\n\n\\textbf{Equation 2} describes protein dynamics using mRNA and protein transcription and translation rates ($\\beta_{R}$ and $\\beta_{P}$), diffusion coefficients ($D_{R}$ and $D_{P}$ respectively), transport velocities ($\\nu_{R}$ and $\\nu_{P}$) and degradation rates ($k_{R}$ and $k_{P}$).\n\n\\begin{equation}\n  P^{den}_{SS}(x) = \\frac{\\beta_{P}\\beta_{R}\\lambda_{R}}{k_{R}(D_{P}\\lambda^{2}_{R}+\\nu_{P}\\lambda_{R} - k_{P})}(-e^{-\\lambda_{R}x} + \\frac{D_{P}\\lambda_{P}\\lambda_{R} + \\nu_{P}\\lambda_{P}}{k_{P}}e^{-\\lambda_{P}x})\n\\end{equation}\n\nwhere $\\lambda_{P} = \\frac{\\sqrt{\\nu^{2}_{P} + 4D_{P}k_{P}}-\\nu_{P}}{2D_{P}}$\n\nIn the case of proteins with 3'UTR localizing them to the soma, the \\textbf{Equation 3} describes their distribution:\n\\begin{equation}\n  P^{som}_{ss}(x) = \\frac{\\beta_{P}\\beta_{R}\\lambda_{P}}{k_{R}k_{P}} e^{-\\lambda_{P}x}\n\\end{equation}\n\n\nIn neurons, both somatically and dendritically synthesized proteins contribute to the dendritic protein distribution. Thus, the total distribution of protein is a mixture of both \\textbf{Equation 2} and \\textbf{Equation 3} in the form of \\textbf{Equation 4}:\n\n\\begin{equation}\n  P^{tot}_{ss}(x) = S_{mRNA} \\cdot z \\cdot P^{som}_{ss}(x) + (1-S_{mRNA})  \\cdot P^{den}_{ss}(x)\n\\end{equation}\n\nwhere $S_{mRNA}$ denotes the fraction of mRNAs found in the soma and $z$ the fraction of somatically synthesized proteins that is transported to the dendrite.\n\n\n\\textbf{Table 1} provides values of rates used for simulations.\n\n\\begin{center}\n  \\begin{tabular}{|c|c|c|}\n    \\hline\n    & mRNA & Protein \\\\\n    \\hline\n    Transcription (mRNA/s) & $\\beta_{R} = 0.001$ & \\\\\n    \\hline\n    Translation (protein/s) & & $\\beta_{P} = 0.021$ \\\\\n    \\hline\n    Diffusion ($\\mu m^{2}/s$) & $D_{R}=3.4e^{-3}$ & $D_{P}=0.24$ \\\\\n    \\hline\n    Velocity ($\\mu m/s$) & $\\nu_{R}=6.7e^{-3}$ & $\\nu_{P}=0$ \\\\\n    \\hline\n    Half life & $T_{1/2}=16$ hours & $T_{1/2}=6.67$ days \\\\\n    \\hline\n  \\end{tabular}\n\\end{center}\n\n\\textbf{Table 2} provides values for other parameters. Values were rounded to 2 decimals. Of note, using these values can lead to slight changes in the quantitative results. Full values can be found in the code files.\n\n\\begin{center}\n  \\begin{tabular}{|c|c|}\n    \\hline\n    Name & Value \\\\\n    \\hline\n    $S_{mRNA}$ & 0.557 \\\\\n    \\hline\n    $z$ & 0.22 \\\\\n    \\hline\n  \\end{tabular}\n\\end{center}\n\n\n\\section{Results}\n\nIn \\textbf{Figure 1}, we show the range of possible dendritic mRNA and protein distributions according to the smallest and largest experimental values from the literature (Figure 1C,D in the orignal article). We observed small quantitative differences with values reported in the original article (31.1\\% instead of 29\\% reduction of protein cncentration in conditions of reduced protein mobility).  \n\n\\begin{figure}[H]\n  \\includegraphics[width=\\textwidth]{Figure1.pdf}\n  \\caption{Replication of the possible range of dendritic mRNA and protein distribution according to the literature.  Color code denotes the upper bound (dark blue and red) and lower bound (light blue and orange) for the respective distributions (\\textbf{A}) mRNA distribution obtained for candidate values from the literature. Upper bound: $D_{R} = 0.0038\\mu m^{2}/s$ and $\\nu_{R}=1.3\\mu m/s$. Lower bound:  $D_{R} = 0.003\\mu m^{2}/s$ and $\\nu_{R}=0.0058\\mu m/s$. (\\textbf{B}) Protein distribution obtained for candidate values from the literature.Upper bound: $D_{P} = 4.5\\mu m^{2}/s$ and $\\nu_{P}=0\\mu m/s$. Lower bound:  $D_{P} = 0.023\\mu m^{2}/s$ and $\\nu_{R}=0\\mu m/s$.} \n\\end{figure}\n\nIn \\textbf{Figure 2}, we show the influence of single parameter variations on mRNA and protein distribution. The initial parameters used are the one experimentally confirmed in the study: $D_{R}=3.4\\cdot10^{-3} \\mu m^{2}/s, \\nu_{R}=6.7 \\cdot 10^{-3} \\mu m/s$. Qualitative inspection of the obtained graphs showed similar behavior and allowed to reach similar conclusions. \n\n\\begin{figure}[H]\n  \\includegraphics[width=\\textwidth]{Figure2.png}\n  \\caption{Consequences of modulating mRNA parameters on mRNA and protein distributions. (\\textbf{A, B}) Impact of mRNA velocity. (\\textbf{D, E}) Impact of mRNA diffusion.(\\textbf{F, G}) Impact of mRNA lifetime. In all panels, distributions were normalizxed to the original value. Alternative normalization were also explored and were successfully replicated (LINK ??)}\n\\end{figure}\n\n\n\n\n\n", "meta": {"hexsha": "6b98da5f728d23978248bbeda0d58dae32e556d2", "size": 6110, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Article/content.tex", "max_stars_repo_name": "MathieuBo/ReFonkeu2019", "max_stars_repo_head_hexsha": "6841b2f0a6f83b298d2559e91bd9993ded87ea68", "max_stars_repo_licenses": ["MIT"], "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/content.tex", "max_issues_repo_name": "MathieuBo/ReFonkeu2019", "max_issues_repo_head_hexsha": "6841b2f0a6f83b298d2559e91bd9993ded87ea68", "max_issues_repo_licenses": ["MIT"], "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/content.tex", "max_forks_repo_name": "MathieuBo/ReFonkeu2019", "max_forks_repo_head_hexsha": "6841b2f0a6f83b298d2559e91bd9993ded87ea68", "max_forks_repo_licenses": ["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.1, "max_line_length": 677, "alphanum_fraction": 0.7134206219, "num_tokens": 1831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6350335900418235}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{fmlin}\n\\section*{\\hspace*{-1.6cm} fmlin}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nSignal with linear frequency modulation.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[y,iflaw] = fmlin(N)\n[y,iflaw] = fmlin(N,fnormi)\n[y,iflaw] = fmlin(N,fnormi,fnormf)\n[y,iflaw] = fmlin(N,fnormi,fnormf,t0)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty fmlin} generates a linear frequency modulation, going from\n{\\ty fnormi} to {\\ty fnormf}.  The phase of this modulation is such that\n{\\ty y(t0)=1}.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty N }      & number of points\\\\\n        {\\ty fnormi}  & initial normalized frequency & {\\ty 0.0}\\\\\n        {\\ty fnormf}  & final   normalized frequency & {\\ty 0.5}\\\\\n        {\\ty t0}      & time reference for the phase & {\\ty N/2}\\\\\n  \\hline {\\ty y}       & signal\\\\\n        {\\ty iflaw }  & instantaneous frequency law  \\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         z=amgauss(128,50,40).*fmlin(128,0.05,0.3,50); \n         plot(real(z));\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nfmconst, fmsin, fmodany, fmhyp, fmpar, fmpower.\n\\end{verbatim}\n\\end{minipage}\n\n", "meta": {"hexsha": "679818a8d33bb199d8a40c969a6c9b38b9116996", "size": 1743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/fmlin.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/fmlin.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/fmlin.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 22.9342105263, "max_line_length": 72, "alphanum_fraction": 0.6322432587, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.635033588155824}}
{"text": "% \\documentclass{article}\n% \\usepackage[utf8]{inputenc}\n% \\usepackage{amsmath}\n\n% \\title{Toda Lattice, Double Bracket}\n% \\author{Lusa Zhan}\n% \\date{September 2016}\n\n% \\begin{document}\n\n% \\maketitle\n\n\n% \\section{Equivalence between ODE and Lie bracket notation}\n\nThe central idea of analog sorting as described in~\\cite{bloch, brockett} makes use of the Toda lattice. The system of Hamiltonian equations in (1) associated with the Hamiltonian in (2) gives us the following set of equations\n\\begin{align*}\n\\dot{p_k} &= \\exp(q_{k-1}-q_{k})-\\exp(q_{k}-q_{k+1}) \\\\\n\\dot{q_k} &= p_k\n\\end{align*}\nwhere the boundary conditions are set so that $\\exp(x_0-x_1)=\\exp (x_n-x_{n+1})=0$.\n\nThis system is also analogous to the double bracket notation \n\\begin{align}\n\\dot{H} = [H,[H,N]]\n\\end{align}\n\nwhere the brackets stand for the Lie bracket $[A,B] = AB-BA$. The connection between the Hamiltonian system  and the double bracket notation of the Toda lattice will be discussed and outlined in the following sections.\n\n\\subsubsection{Toda lattice - ODE form}\n\nThe above system of ordinary differential equations can be transformed into the system described in~\\cite{harvard_robo} using a change of variables.\n\\begin{align}\nx_k &= -\\frac{1}{2}p_k \\nonumber \\\\\ny_k &= \\frac{1}{2}\\exp(\\frac{q_k-q_{k+1}}{2})\n\\end{align}\n\nIn that case, \n\\begin{align*}\n    \\dot{x_k} &= -\\frac{1}{2}\\dot{p_k} \\\\\n              &= -\\frac{1}{2}(exp(q_{k-1}-q_{k})-exp(q_{k}-q_{k+1})) \\\\\n              &= -\\frac{1}{2}(4y^2_{k-1}-4y^2_k) \\\\\n              &= 2y^2_k-2y^2_{k-1}\n\\end{align*}\n\nand \n\\begin{align*}\n    \\dot{y_k} &= \\frac{1}{2}\\exp(\\frac{q_k-q_{k+1}}{2})\\frac{\\dot q_k-\\dot q_{k+1}}{2} \\\\\n              &= y_k\\frac{p_k-p_{k+1}}{2} \\\\\n              &= y_k(x_{k+1}-x_k) \n\\end{align*}\n\nTaking into account the boundary conditions $y_0=y_n=0$, we get the desired system of ODEs with\n\\begin{align}\n    \\dot{x_k} &= 2y^2_k-2y^2_{k-1} \\nonumber \\\\\n    \\dot{y_k} &= y_k(x_{k+1}-x_k) \\\\\n    y_0 &= y_n = 0 \\nonumber\n\\end{align}\n\nThis is the system of ODEs we will solve in the analog chip and in our simulations.\n\n\n\\subsubsection{Toda lattice - Jacobi matrix}\n\nThe connection between the Toda lattice and the double bracket notation $\\dot{H} = [H,[H,N]]$ can be made through the Jacobi Matrix form of the Toda lattice. The Jacobi matrix for the Hamiltonian system after the change of variables (4) is given by\n\\begin{align}\n H = \\begin{bmatrix}\n    x_{1} & y_{1} & 0  & \\dots & 0 \\\\\n    y_{1} & x_{2} & y_{2} & \\dots & 0 \\\\\n     & & \\ddots & \\\\\n          &       & y_{n-2} & x_{n-1} & y_{n-1}\\\\\n    0 & \\hdots & & y_{n-1} & x_{n}\n\\end{bmatrix}\n\\end{align}\nThis is the form of $H$ required for analog sorting as outlined by Brockett in ~\\cite{brockett}.\n\nIn order to get the double bracket form, we need a diagonal matrix $N = \\text{diag}(n, n-1, \\dots, 1)$ whose role will be discussed in 2.5.1.\n\n\\begin{align*}\nN = \\begin{bmatrix}\n        n & 0 & \\hdots & 0 \\\\\n        0 & n-1 & \\\\\n        \\vdots &  & \\ddots & \\vdots \\\\\n        0 & \\hdots & & 1\n    \\end{bmatrix}\n\\end{align*}\n\nFrom this, we can calculate $[H[H,N]] = H[H,N]-[H,N]H$ step by step:\n\n\\[ \nHN = \\begin{bmatrix}\n        nx_1 & (n-1)y_1 & \\hdots & 0 \\\\\n        ny_1 & (n-1)x_2 & \\hdots & 0 \\\\\n        \\vdots & & \\ddots & 0\\\\\n         &  & 2x_{n-1} & y_{n-1} \\\\\n        0 & \\hdots & 2y_{n-1} & x_n\n\n    \\end{bmatrix}\n\\]\n\n\\[ \nNH = \\begin{bmatrix}\n        nx_1 & ny_1 & \\hdots & 0 \\\\\n        (n-1)y_1 & (n-1)x_2 & \\hdots & 0 \\\\\n        \\vdots & & \\ddots & 0\\\\\n         &  & 2x_{n-1} & 2y_{n-1} \\\\\n        0 & \\hdots & y_{n-1} & x_n\n\n    \\end{bmatrix}\n\\]\n\n\\[ \nHN-NH = \\begin{bmatrix}\n        0 & -y1 & \\hdots &  & 0 \\\\\n        y_1 & 0 & -y_2 & \\hdots & 0 \\\\\n        \\vdots & \\ddots & \\ddots & \\ddots & 0\\\\\n         & & y_{n-2}& 0 & -y_{n-1} \\\\\n        0 & & \\hdots & y_{n-1} & 0\n\n    \\end{bmatrix}\n\\]\n\n\\[ \nH[H,N] = \\begin{bmatrix}\n        y_1^2 & -x_1y_1 & \\hdots & 0 \\\\\n        x_2y_1 & -y_1^2+y^2_2 &\\hdots & 0 \\\\\n        y_1y_2 & \\ddots & & 0\\\\\n        \\vdots & & y^2_{n-1}-y^2_{n-2} & -x_{n-1}y_{n-1} \\\\\n        0 & \\hdots & x_ny_{n-1} & -y^2_{n-1}\n\n    \\end{bmatrix}\n\\]\n\n\\[ \n[H,N]H = \\begin{bmatrix}\n        y_1^2 & -x_2y_1 & \\hdots & 0 \\\\\n        x_1y_1 & y_1^2-y^2_2 &\\hdots & 0 \\\\\n        y_1y_2 & \\ddots & & 0\\\\\n        \\vdots &  & -y^2_{n-1}+y^2_{n-2} & -x_{n}y_{n-1} \\\\\n        0 & \\hdots & x_{n-1}y_{n-1} & y^2_{n-1}\n\n    \\end{bmatrix}\n\\]\n\\\\\n\nTherefore, we get \\\\\n\n\\[[H,[H,N]] = \n\\begin{bmatrix}\n    2y_1^2 & y_1(x_2-x_1) & 0 \\\\\n    y_1(x_2-x_1) & -2(y_1^2-y^2_2) & 0\\\\\n    0 & \\ddots & 0\\\\\n    \\vdots & & y_{n-1}(x_{n}-x_{n-1}) \\\\\n    0 & \\hdots & -2y^2_{n-1}\n\\end{bmatrix}\n\\]\n\nThis is equivalent to the result we get from combining the matrix form of $H$ with the values for $\\dot{x}$ and $\\dot{y}$\n\\[\\dot{H} = \\begin{bmatrix}\n    \\dot{x}_{1} & \\dot{y}_{1} & 0  & \\dots & 0 \\\\\n    \\dot{y}_{1} & \\dot{x}_{2} & \\dot{y}_{2} & \\dots & 0 \\\\\n     & & \\ddots & \\\\\n     & & \\dot{y}_{n-2} & \\dot{x}_{n-1} & \\dot{y}_{n-1}\\\\\n    0 & \\hdots & & \\dot{y}_{n-1} & \\dot{x}_{n}\n    \n\\end{bmatrix}\\]\n\nIn total, we conclude that the double bracket notation of the Toda lattice used in other papers is analogous to the system of ODEs. We use the equivalent system of ODEs to construct the analog sorter.\n\n\n", "meta": {"hexsha": "9baa2d84ac774b0592ff35bc702ef7f791c52c80", "size": 5217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/TodaDoubleBracket.tex", "max_stars_repo_name": "yipenghuang0302/sorting", "max_stars_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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": "reports/TodaDoubleBracket.tex", "max_issues_repo_name": "yipenghuang0302/sorting", "max_issues_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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": "reports/TodaDoubleBracket.tex", "max_forks_repo_name": "yipenghuang0302/sorting", "max_forks_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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.5087719298, "max_line_length": 248, "alphanum_fraction": 0.5620088173, "num_tokens": 2094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6350335880122545}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{array}\n\\usepackage{clrscode3e}\n\\usepackage{amsmath}\n\\usepackage{kbordermatrix}\n\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\title{Efficient Calculation of Interaction Features on Sparse Matrices}\n\\author{Andrew Nystrom}\n\\date{}\n\n\\maketitle\n\n\\begin{abstract}%   <- trailing '%' for backward compatibility of .sty file\nFILL THIS IN\n\\end{abstract}\n\n\\section{Introduction}\n\nIntroduction\nInteraction features are a way of capturing correlations between features in a machine \nlearning setting. A feature vector $\\vec{x}$ of dimensionality $D$ has second degree interaction features \n$\\{x_i \\cdot x_j : i, j \\in \\{0,1,..., D-1\\} \\land i < j\\}$, \nso a $D$ dimensional vector has $\\binom{D}{2} = \\frac{D^2-D}{2}$ second degree interaction features. A naive\napproach to calculating these features is to simply iterate through the combinations of the column indices.\nFor a sparse vector, many of the resulting interaction features would be zero, and could therefore be ignored.\nThis work describes a method to efficiently calculate second degree interaction features for a sparse matrix \nthat has time and space complexities that decrease quadratically with the density of the input matrix with respect to the naive approach.\n\n$\\{x_i \\cdot x_j : i, j \\in \\{0,1,..., D-1\\} \\land i \\le j\\}$  \\\\\n\\\\\n$\\{(i,j) : i, j \\in \\{0,1,..., D-1\\} \\land i \\le j\\} \\to \\{0, 1, ..., \\frac{D^2+D}{2}-1\\}$ \\\\\n\n$i$\n$j$\n\n$\\vec{x}$\n\n\\begin{codebox}\n\\Procname{$\\proc{Dense Polynomials}(A)$}\n    \\zi $N \\gets$ row count of $A$\n    \\zi $D \\gets$ column count of $A$\n    \\zi $B$ $\\gets$ Matrix of size $N \\times \\frac{D^2+D}{2}$\n    \\zi \\For $\\id{row}$ in $A$ \\Do\n    \\zi     $k \\gets 0$\n    \\zi     \\For $\\i \\gets 0 \\To D$ \\Do\n    \\zi         \\For $\\j \\gets i \\To D$ \\Do\n    \\zi             $B[i, k] \\gets \\id{row}[i] \\cdot \\id{row}[j]$\n    \\zi             $k \\gets k + 1$\n                \\End\n            \\End\n       \t\\End\n\\end{codebox}\n\n$[a, b, c, d, e]$\n\n$[ab, ac, ad, ae, bc, bd, be, cd, ce, de]$\n\n\n\\renewcommand{\\kbldelim}{(}% Left delimiter\n\\renewcommand{\\kbrdelim}{)}% Right delimiter\n\\[\n  \\kbordermatrix{\n        & x_0 & x_1 & x_2 & x_3 & x_4 \\\\\n    x_0 & 0 & 1 & 2 & 3 & 4\\\\\n    x_1 & - & 5 & 6 & 7 & 8\\\\\n    x_2 & - & - & 9 & 10 & 11\\\\\n    x_3 & - & - & - & 12 & 13\\\\\n    x_4 & - & - & - & - & 14\\\\\n  }\n\\]\n\n\n$\\text{polynomial-index}(i, j | D) = \\frac{2Di-i^2+2j-3i-2}{2}+i+1$\n\n%Consider the following matrix:\n\n%\\[ \\left( \\begin{array}{cccc}\n%3 & 0 & 0 & 3 \\\\\n%0 & 4 & 2 & 0 \\\\\n%1 & 2 & 0 & 3 \\end{array} \\right)\\]\n\\[ \\left( \\begin{array}{ccccc}\nA & b & c & d \\end{array} \\right)\\]\n\n%\\[ \\left( \\begin{array}{cccccccccc}\n%1 & 2 & 0 & 3 & 0 \\end{array} \\right)\\]\n\n\n%If each row is an instance vector, then the interaction feature matrix is\n\n%\\[ \\left( \\begin{array}{cccccc}\n%0 & 0 & 9 & 0 & 0 & 0 \\\\\n%0 & 0 & 0 & 8 & 0 & 0 \\\\\n%2 & 0 & 3 & 0 & 6 & 0 \\end{array} \\right)\\]\n\n%Note that there are $\\binom{D}{2} = \\frac{D^2-D}{2}$ columns in the interaction matrix, which is D choose 2, \n%since we generate products of all combinations of 2 features in the original matrix. \n%Which column corresponds with which product pair is not important so long as it’s \n%consistent. In this example, each column in the interaction matrix corresponded to the \n%following product pairs: $(1, 2),  (1, 3),  (1, 4),  (2, 3), ( 2, 4), (3, 4)$.\n\n%Notice that the interaction matrix contains many zero entries. This is of course because \n%the original matrix contained zero entries, so the interaction features, which are \n%products of pairs of features, contain many zeros. This means that the only products that \n%need to actually be calculated or those for which both features in the combination are \n%nonzero. If the original matrix is sparse and represented in a sparse matrix format \n%(e.g. compressed sparse row), a list of nonzero column indices are stored for each row \n%and are easily retrievable in $O(1)$ time. Interaction features can be generated from this \n%list via the following method.\n\n\\section{Approach}\nLet the list of nonzero columns for a given row $\\vec{x}$ be denoted by $N_{zc}$. The nonzero second degree \ninteraction features are simply the products of all combinations of two elements whose \ncolumns are in $N_{zc}$. However, to properly place an interaction feature into the correct column, a mapping from the column \nindex pairs of $N_{zc}$ into the columns of the interaction matrix is needed. The mapping is \nfrom the space (a, b) where a,b are in $1,2,..., D$ onto the space $1,2,..., \\frac{D^2-D}{2}$. This \nis isomorphic to mapping the coordinates of the upper triangle of a matrix onto a flat \nlist. The following is a proof by construction for such a mapping.\n\nINSERT JOHN'S PROOF HERE\n\nWith this mapping, an algorithm for generating second degree interaction features on a \nmatrix $A$ can be formulated as follows:\n\n\\begin{codebox}\n\\Procname{$\\proc{Sparse Polynomials}(A)$}\n    \\zi $\\func{map}(a, b) = \\frac{2Da-a^2+2b-3a-2}{2}+a+1$\n    \\zi $N \\gets$ row count of $A$\n    \\zi $D \\gets$ column count of $A$\n    \\zi $B$ $\\gets$ Compressed Sparse Row Matrix of size $N \\times \\frac{D^2+D}{2}$\n    \\zi \\For $\\id{row}$ in $A$ \\Do\n    \\zi     $N_{zc} \\gets$ nonzero columns of $row$\n    \\zi     \\For $i \\gets 0 \\To |N_{zc}|$ \\Do\n    \\zi         \\For $j \\gets i \\To |N_{zc}|$ \\Do\n    \\zi             $k \\gets \\func{map}(i, j)$\n    \\zi             $r \\gets$ index of $\\id{row}$\n    \\zi             $B[r, k] \\gets \\id{row}[i] \\cdot \\id{row}[j]$\n                \\End\n            \\End\n       \t\\End\n\\end{codebox}\n\n\\section{Complexity Analysis}\nAssume that A is a matrix with sparsity $0 < d < 1$, $N$ rows, and $D$ columns. Finding \ninteraction features with the proposed algorithm has time and space complexity \n$\\func{O}(d N D^2)$, \nwhereas a naive approach of using non-sparse matrices and multiplying all column \ncombinations has time and space complexity $\\func{O}(N D^2)$. The algorithm is therefore an \nimprovement by a factor of the density factor of $A$.\n\nThis can represent a large gain in speed and time. For example, the 20 Newsgroups dataset \nhas density $d$ of 0.12 when its unigrams are represented in a vector space model. This \nmeans the proposed approach would take less than $\\frac{1}{8}$ time and memory.\n\nThe real benefit of this method is revealed when the average complexity is analysed. The \nnumber of interactions calculated for a given row are $\\binom{|N_{zc}|}{2}$. If the matrix has \ndensity $d$, then on average, $N_{zc} = D d$, so the number of interaction features \ncalculated in total is \n\n\\begin{align*}\nN \\binom{d D}{2} &= N \\frac{(Dd)!}{2!(Dd-2)!}\\\\\n    \\\\\n    &= N \\frac{(D^2d^2-Dd)}{2}\n\\end{align*}\n\nThis means that the average complexity decreases quadratically with the density.\n\n\\section{Future Work}\nThe approach for generating second degree interaction features required a mapping from \ncombinations of two to the space $1,2,...,\\frac{D^2-D}{2}$, which is isomorphic to a mapping from \nthe indices of an upper triangular matrix to the indices of a flat list of the same size. \nTo generate third degree interaction features, a mapping from combinations of three \n$(a,b,c)$ to the space $1,2,...\\frac{D^3-3D^2+2D}{6}$ (which is $\\binom{D}{3}$), or the upper $3$-simplex of a tensor to a flat \nlist of the same size $\\frac{D^3-3D^2+2D}{6}$ would be required. In general, for interaction \nfeatures of degree k, the upper $k$-simplex of a $k$-dimensional tensor must be mapped to the \nspace $1,2,...\\frac{D!}{k!(D-k)!}$. A similar approach for finding these mappings could be taken \nas the one used here for $k=2$. \n\nMotivation for deriving mapping functions for higher orders\nof interaction features is that the average complexity of generating degree $k$ interaction\nfeatures is $N \\binom{Dd}{k}$, which decreases polynomially with respect to k compared to\ngenerating the features naively.\n\n    \n\\vskip 0.2in\n\\bibliography{sample}\n\n\\end{document}", "meta": {"hexsha": "5561e7a595a005b85bf41d82cb1155eee7a97e1a", "size": 7934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/various_spares_interaction.tex", "max_stars_repo_name": "AWNystrom/SparseInteraction", "max_stars_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-01-08T17:17:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-16T15:35:26.000Z", "max_issues_repo_path": "paper/various_spares_interaction.tex", "max_issues_repo_name": "AWNystrom/SparseInteraction", "max_issues_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "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/various_spares_interaction.tex", "max_forks_repo_name": "AWNystrom/SparseInteraction", "max_forks_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-01-08T17:28:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-08T17:36:00.000Z", "avg_line_length": 41.1088082902, "max_line_length": 137, "alphanum_fraction": 0.6656163348, "num_tokens": 2483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6349332448692815}}
{"text": "The is the first paragraph of the Softcover article template. It shows how to write a document in \\PolyTeX, a subset of the \\LaTeX\\ typesetting language optimized for writing ebooks.\\footnote{Pronunciations of ``LaTeX'' differ, but \\emph{lay}-tech is the one I prefer.}\n\nThis is the second paragraph, showing how to \\emph{emphasize} text. You can also make text \\textbf{bold}.\n\n\\section{A section}\n\\label{sec:a_section}\n\nThis is a section. We'll take a look at some of the features supported by Softcover.\n\n\\subsection{Source code}\n\nIn plain Markdown, you can typeset code samples and other verbatim text using four spaces of indentation:\n\n\\begin{verbatim}\ndef hello\n  puts \"hello, world\"\nend\n\\end{verbatim}\n\nSoftcover also supports GitHub-style ``code fencing'' with language-specific syntax highlighting:\n\n%= lang:ruby\n\\begin{code}\n# \"Hello, world!\" in Ruby.\ndef hello\n  puts \"hello, world!\"\nend\n\\end{code}\n\nThe second of these can be combined with Softcover's \\kode{codelisting} environment to make code listings via embedded \\LaTeX, as shown in Listing~\\ref{code:hello}.\n\n\\begin{codelisting}\n\\codecaption{Hello, world.}\n\\label{code:hello}\n%= lang:ruby\n\\begin{code}\n# \"Hello, world!\" in Ruby.\ndef hello\n  puts \"hello, world!\"\nend\n\\end{code}\n\\end{codelisting}\n\n\\subsection{Mathematics}\n\nSoftcover supports mathematical typesetting via embedded \\LaTeX. This includes both inline math, such as \\( \\phi^2 - \\phi - 1 = 0, \\) and centered math, such as\n\\[ \\phi^2 - \\phi - 1 = 0. \\]\nSoftcover also supports numbered equations via embedded \\LaTeX, as seen in Eq.~\\eqref{eq:phi} and Eq.~\\eqref{eq:gauss}.\n\n\\begin{equation}\n\\label{eq:phi}\n\\phi = \\frac{1+\\sqrt{5}}{2} \\approx 1.618\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:gauss}\n\\mathbf{\\nabla}\\cdot\\mathbf{B} = 0 \\qquad\\mbox{Gauss's law}\n\\end{equation}\n\n\\section{Images and tables}\n\\label{sec:images_and_tables}\n\nThis is the second section. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n\\subsection{Images}\n\nSoftcover supports the inclusion of images, like this:\n\n\\image{images/figures/01_michael_hartl_headshot.jpg}\n\nUsing \\LaTeX\\ labels, you can also include a caption (as in Figure~\\ref{fig:captioned_image}) or just a figure number (as in Figure~\\ref{fig:figure_number}).\n\n\\begin{figure}[h]\n\\begin{center}\n\\image{images/figures/01_michael_hartl_headshot.jpg}\n\\end{center}\n\\caption{Some dude.\\label{fig:captioned_image}}\n\\end{figure}\n\n\\begin{figure}[h]\n\\begin{center}\n\\image{images/figures/01_michael_hartl_headshot.jpg}\n\\end{center}\n\\caption{\\label{fig:figure_number}}\n\\end{figure}\n\n\\subsection{Tables}\n\nSoftcover supports raw tables via the \\LaTeX\\ \\kode{table} or \\kode{longtable} environments.\n\n\\begin{longtable}{|l|l|l|l|}\n\\hline\n\\textbf{HTTP request} & \\textbf{URL} & \\textbf{Action} & \\textbf{Purpose}\\\\\n\\kode{GET} & /users & \\kode{index} & page to list all users\\\\\n\\kode{GET} & /users/1 & \\kode{show} & page to show user with id \\kode{1}\\\\\n\\kode{GET} & /users/new & \\kode{new} & page to make a new user\\\\\n\\kode{POST} & /users & \\kode{create} & create a new user\\\\\n\\kode{GET} & /users/1/edit & \\kode{edit} & page to edit user with id \\kode{1}\\\\\n\\kode{PATCH} & /users/1 & \\kode{update} & update user with id \\kode{1}\\\\\n\\kode{DELETE} & /users/1 & \\kode{destroy} & delete user with id \\kode{1}\\\\\n\\hline\n\\end{longtable}\n\nSoftcover also supports \\kode{tabular} environments, as shown in Table~\\ref{table:figure_placement}.\n\n\\begin{table}\n\\caption{Options for a float placement specifier.\\label{table:figure_placement}}\n\\begin{tabular}{l|l}\n\\textbf{Specifier} & \\textbf{Placement} \\\\ \\hline\n\\kode{h} & Place the float \\emph{approximately} here \\\\\n\\kode{h!} & Place the float \\emph{(almost) exactly} here \\\\\n\\kode{t} & Place at the top of the page \\\\\n\\kode{b} & Place at the bottom of the page \\\\\n\\kode{p} & Put on a special page for floats only\n\\end{tabular}\n\\end{table}\n\n\\section{Final section}\n\nThis is the final section. The previous sections were Section~\\ref{sec:a_section} and Section~\\ref{sec:images_and_tables}.", "meta": {"hexsha": "d5cab97c12bbaed75218e0e232dc308333586649", "size": 4371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/softcover/article_template/chapters/an_article.tex", "max_stars_repo_name": "ngiger/softcover", "max_stars_repo_head_hexsha": "9350a14d1ead3538b6a307dc9cdf60e1f9b2267c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 331, "max_stars_repo_stars_event_min_datetime": "2015-01-03T00:13:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T18:03:00.000Z", "max_issues_repo_path": "lib/softcover/article_template/chapters/an_article.tex", "max_issues_repo_name": "ngiger/softcover", "max_issues_repo_head_hexsha": "9350a14d1ead3538b6a307dc9cdf60e1f9b2267c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 111, "max_issues_repo_issues_event_min_datetime": "2015-01-04T20:50:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T21:09:32.000Z", "max_forks_repo_path": "lib/softcover/article_template/chapters/an_article.tex", "max_forks_repo_name": "ngiger/softcover", "max_forks_repo_head_hexsha": "9350a14d1ead3538b6a307dc9cdf60e1f9b2267c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 49, "max_forks_repo_forks_event_min_datetime": "2015-02-10T22:25:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:43:46.000Z", "avg_line_length": 34.968, "max_line_length": 269, "alphanum_fraction": 0.7396476779, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.7905303285397348, "lm_q1q2_score": 0.6349332376596455}}
{"text": "\n\\section{The predicate \\Unchanged}\n\\Label{sec:unchanged}\n\nMany of the algorithms in this section iterate sequentially over one or several sequences.\nFor the verification of such algorithms it is often important to express that a section\nof an array, or the complete array, have remained \\emph{unchanged}.\nAs this cannot always be expressed by an \\inl{assigns} clause,\nwe introduce in the following listing the overloaded predicate\n\\logicref{Unchanged}.\nThe expression \\inl{Unchanged\\{K,L\\}(a,m,n)} is true if the range\n\\inl{a[m..n-1]} in state~\\inl{K} is element-wise equal to that range in state~\\inl{L}.\n\n\\input{Listings/Unchanged.acsl.tex}\n\nIn some situations we use the predicate \\ArrayUpdate,\nwhich relies on the predicate \\Unchanged and the the logic function \\logicref{At},\nto concisely describe which parts of an array have changed or remained unchanged\nwhen updating an individual array element.\n\n\n\\input{Listings/ArrayUpdate.acsl.tex}\n\n\\clearpage\n\nIn the following listing we show a few lemmas for \\logicref{Unchanged}\nthat we need for the verification of various algorithms.\n\n\\input{Listings/UnchangedLemmas.acsl.tex}\n\n\\begin{itemize}\n\\item\nLemma~\\logicref{UnchangedShrink} states that if the range~\\inl{a[m..n-1]} does\nnot change when going from state~\\inl{K} to state~\\inl{L}, then~\\inl{a[p..q-1]}\ndoes not change either, provided the latter is a subrange of the\nformer, i.e.\\ provided $0 \\leq m \\leq p \\leq q \\leq n$ holds.\n\n\\item\nLemma~\\logicref{UnchangedExtend} expresses the simple fact that ``unchangedness'' is an inductive property.\n\n\\item\nLemma~\\logicref{UnchangedShift} states how \\Unchanged behaves under pointer additions.\n\n\\item\nLemmas~\\logicref{UnchangedSymmetric} and~\\logicref{UnchangedTransitive} express respectively\nthe symmetry and transitivity of \\Unchanged with respect to program states.\n\n\\end{itemize}\n\n\n\\clearpage\n\n", "meta": {"hexsha": "059294aa85261fc38f45eac5c92c68821e95c2d4", "size": 1853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/mutating/unchanged.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/mutating/unchanged.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/mutating/unchanged.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": 34.9622641509, "max_line_length": 107, "alphanum_fraction": 0.7803561792, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6349332273915593}}
{"text": "\\chapter{Frequentist statistics}\n\nAttempts have been made to devise approaches to statistical inference that avoid treating parameters like random variables, and which thus avoid the use of priors and Bayes rule. Such approaches are known as \\textbf{frequentist statistics}, \\textbf{classical statistics} or \\textbf{orthodox statistics}. Instead of being based on the posterior distribution, they are based on the concept of a sampling distribution.\n\n\n\\section{Sampling distribution of an estimator}\nIn frequentist statistics, a parameter estimate $\\hat{\\vec{\\theta}}$ is computed by applying an \\textbf{estimator} $\\delta$ to some data $\\mathcal{D}$, so $\\hat{\\vec{\\theta}}=\\delta(\\mathcal{D})$. The parameter is viewed as fixed and the data as random, which is the exact opposite of the Bayesian approach. The uncertainty in the parameter estimate can be measured by computing the \\textbf{sampling distribution} of the estimator. To understand this\n\n\n\\subsection{Bootstrap}\nWe might think of the bootstrap distribution as a “poor man’s” Bayes posterior, see (Hastie et al. 2001, p235) for details.\n\n\n\\subsection{Large sample theory for the MLE *}\n\n\n\n\\section{Frequentist decision theory}\nIn frequentist or classical decision theory, there is a loss function and a likelihood, but there is no prior and hence no posterior or posterior expected loss. Thus there is no automatic way of deriving an optimal estimator, unlike the Bayesian case. Instead, in the frequentist approach, we are free to choose any estimator or decision procedure $f: \\mathcal{X} \\rightarrow \\mathcal{Y}$ we want.\n\nHaving chosen an estimator, we define its expected loss or \\textbf{risk} as follows:\n\\begin{equation}\\begin{split}\nR_{\\mathrm{exp}}(\\theta,f) & \\triangleq \\mathbb{E}_{p(\\tilde{\\mathcal{D}}|\\theta^*)}[L(\\theta^*, f(\\tilde{\\mathcal{D}}))] \\\\\n    & =\\int L(\\theta^*, f(\\tilde{\\mathcal{D}}))p(\\tilde{\\mathcal{D}}|\\theta^*)\\mathrm{d}\\tilde{\\mathcal{D}}\n\\end{split}\\end{equation}\nwhere˜$\\tilde{\\mathcal{D}}$ is data sampled from “nature’s distribution”, which is represented by parameter $\\theta^*$. In other words, the expectation is wrt the sampling distribution of the estimator. Compare this to the Bayesian posterior expected loss:\n\\begin{equation}\n\\rho(f|\\mathcal{D},)\n\\end{equation}\n\n\n\\section{Desirable properties of estimators}\n\n\n\\section{Empirical risk minimization}\n\n\n\\subsection{Regularized risk minimization}\n\n\n\\subsection{Structural risk minimization}\n\n\n\\subsection{Estimating the risk using cross validation}\n\n\n\\subsection{Upper bounding the risk using statistical learning theory *}\n\n\n\\subsection{Surrogate loss functions}\n\\label{sec:Surrogate-loss-functions}\n\n\\textbf{log-loss}\n\\begin{equation}\\label{eqn:log-loss}\nL_{\\mathrm{nll}}(y,\\eta)=-\\log p(y|\\vec{x},\\vec{w})=\\log(1+e^{-y\\eta})\n\\end{equation}\n\n\n\\section{Pathologies of frequentist statistics *}\n\n", "meta": {"hexsha": "6f84a8945789ad448de9d61bafdc5edac330ccca", "size": 2854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterFrequentistStatistics.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/chapterFrequentistStatistics.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/chapterFrequentistStatistics.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": 46.7868852459, "max_line_length": 450, "alphanum_fraction": 0.7631394534, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681086260461, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6348979576634237}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage[latin1]{inputenc}\n\\usepackage{geometry}\n\\usepackage{graphicx}\n\\usepackage{titlesec}\n\\usepackage{pagecolor}\n\n\\date{}\n\n\\begin{document}\n\\pagecolor{white}\n\n\\section{Question 1}\n\n$$n + d = 2011 <=> d = 2011 - n$$\n$$\\frac{n} {d} < \\frac{1}{3}$$\n$$\\frac{n}{2011 - n} <  \\frac{1}{3}$$\n$$3n < 2011 - n$$\n$$4n < 2011$$\n$$n < 502.75$$\nDue to the constraint that $n$ and $d$ are positive integers, the maximum value for $n$ is $502$. Therefore $d = 2011 - n = 2011 - 502 = 1509$.\n\n\\section{Question 2}\n\nLet X be the random variable modeling the outcome of the bet, where $x_1$ is the amount by which one's money, $m$, is increased in the event that the bet is favorable, and $x_2$ is the amount by which $m$ is increased if the bet is not favorable. We know that $x_1$ and $x_2$ are complements. Therefore, the expectation of such a variable $X$ is:\n\n$$E[X; m] = \\sum_i x_iP(x_i) = 3mP(x_1) - mP(x_2) = 3mP(x_1) - m(1 - P(x_1)) = 4mP(x_1) - m$$\n$$= m(4P(x_1) - 1)$$\nIn order for the bet to be favorable, we would need the expectation of $X$ to be positive, i.e.,:\n\n$$E[X; m] = m(4P(x_1) - 1) > 0$$\n$$P(x_1) > 0.25$$\nLet $n$ be the number of face cards in the first 5 cards, and let $c$ be the event where the sixth card is a face card, i.e., one's money is increased. Then:\n\n$$P(c | n = i) = \\frac{12 - i}{47} $$\nTherefore:\n$$P(c | n = 0) = 0.255$$\n$$P(c | n = 1) =  0.234$$\nThus we can see that the only way the bet is favorable (i.e., $P(x_1) = P(c | n = i) > 0.25$) is when $i = 0$. We now need to figure out the probability of such an occurrence:\n\n$$P(n = 0) = \\frac{{12 \\choose 0}{40 \\choose 5}}{{52 \\choose 5}} = 0.25318$$\n\n\\section{Question 3}\n\nWe have the following parameters for the Poisson distribution:\n\n$$\\lambda = 100 / 5 = 20$$\n$$\\alpha = 0.05$$\n$$n = 60$$\n$$k = n\\lambda = (60)(20) = 1200$$\n\n$$CI = [\\frac{1}{2}\\chi^2(\\frac{\\alpha}{2}; 2k), \\frac{1}{2}\\chi^2(1 - \\frac{\\alpha}{2}; 2k + 2)]\n= [\\frac{1}{2}\\chi^2(0.025; 2400), \\frac{1}{2}\\chi^2(0.975; 2402)]\n= [1133.1, 1269.9]$$\n\n\\section{Question 4}\n\nThis is a one-sided Z-test.\n\n$$Z^* = \\frac{\\hat{p} - p_0}{\\sqrt{\\frac{p_0(1-p_0)}{n}}}  = \\frac{(\\frac{26}{200} - 0.1)}{\\sqrt{\\frac{0.1(0.9)}{200}}} = 1.414$$\n$$p = P(Z \\geq Z^*) = 0.0787 > 0.05$$\nTherefore we fail to reject the null hypothesis.\n\n\\end{document}", "meta": {"hexsha": "9aa9142aaae1d7b39075215a0f0a3d0d526614c0", "size": 2375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scratch_work.tex", "max_stars_repo_name": "damoose717/stats_problems", "max_stars_repo_head_hexsha": "abbb4faf19a46c210a79d07f9d363aadac35cef3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "scratch_work.tex", "max_issues_repo_name": "damoose717/stats_problems", "max_issues_repo_head_hexsha": "abbb4faf19a46c210a79d07f9d363aadac35cef3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scratch_work.tex", "max_forks_repo_name": "damoose717/stats_problems", "max_forks_repo_head_hexsha": "abbb4faf19a46c210a79d07f9d363aadac35cef3", "max_forks_repo_licenses": ["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.9264705882, "max_line_length": 346, "alphanum_fraction": 0.6168421053, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.6348979558516188}}
{"text": "\\documentclass{article}\n\n\\begin{document}\n\n\\def\\subI{${}_I$}\n\\def\\subF{${}_F$}\n\\def\\subD{${}_D$}\n\\def\\ifso{\\mathbin{?}}\n\n\\section{Rounding}\n\nConverting a rational number $x \\in {\\cal Q}$ to a nearby\ninteger $n \\in {\\cal Z}$ can be done in surprisingly many\nways.  We shall take the floor operation\n\\[ \\lfloor x \\rfloor = \\max \\{n \\in {\\cal Z} | n \\le x\\} \\]\nas the basic operation.  We also need $\\bot$ (undefined),\neven$(n)$ testing whether $n$ is a multiple of 2,\n$p \\ifso t : f$ (if $p$ then $t$ else $f$), and $\\sigma(x)$ =\n$x\\ge 0 \\ifso 1 : -1$.\n\n\\begin{tabular}{lll}\nexact & $x=\\lfloor x\\rfloor \\ifso \\lfloor x \\rfloor : \\bot$ &\n        exception if not integral\\\\\ndown  & $\\lfloor x \\rfloor$             & floor\\\\\nup    & $\\lceil x \\rceil = -\\lfloor -x \\rfloor$ & ceiling\\\\\nin    & $\\sigma(x)\\times\\lfloor|x|\\rfloor$ & truncate\\\\\nout   & $\\sigma(x)\\times\\lfloor|x|+\\frac12\\rfloor$ & away from zero\\\\\neven  & $\\mbox{even}(\\lfloor x\\rfloor) \\ifso \\lfloor x \\rfloor\n        : \\lceil x \\rceil$ & round to even\\\\\nodd   & $\\mbox{even}(\\lfloor x\\rfloor) \\ifso \\lceil x \\rceil\n        : \\lfloor x \\rfloor$ & round to odd (not used in practice)\n\\end{tabular}\n\nNone of these is rounding.  For that we need\n\\[\\mbox{nearest} f x = d > \\frac12 \\ifso \\lceil x \\rceil :\n d < \\frac12 \\ifso \\lfloor x \\rfloor : f(x) \\]\n\\noindent where\n$ d = x - \\lfloor x \\rfloor $\n\nThis higher-order function can be combined with the seven conversions\nabove to make seven ``round to nearest'' modes such as nearest out\n(banker's rounding) or nearest even (IEEE rounding).\n\nThe claim of this paper is that executable specifications are important\nto find and correct mistakes.  Did you notice the mistake(s) above?\nNeither did two pre-publication readers.  The problem is that rounding\n$x$ to an even (odd) integer is not well defined when $x$ is an odd (even)\ninteger.  This issue was discovered by testing.  The solution for even\nis simple: if $x$ is exactly equal to an odd integer, round it to the\nnearest multiple of 4.  There is no sensible way to round 0 to an odd\ninteger, so we strike odd rounding from the list.\n\n\\section{Existing standards}\n\n\\subsection{ISO 10967 Language-independent arithmetic}\n\nRoughly speaking, the three parts of LIA cover everything\nin Fortran 95 and C99 and a little bit more.\n\nWe have to discuss ISO 10967 for two reasons: it is the\nstandard that is meant to serve as a reference for arithmetic\nin programming languages, and it does define fixed point\nnumbers (but no operations on them).  Any definition of\nfixed point arithmetic should be practically compatible with it.\n\nFurther, the 1998 edition provided axioms (though no evidence\nthat the system described was consistent with them) which could\nserve as models for checking a fixed-point specification.\n\nThe Language-independent arithmetic standard has three parts.\n\n\\subsubsection{Part: 1 Integer and floating point arithmetic}\nAn integer data type $I$ has parameters {\\it bounded}\\subI{}\ntrue if the set is finite, {\\it minint}\\subI{} being the\nsmallest value or $-\\infty$, and {\\it maxint}\\subI{} being the\nlargest value or $\\infty$.  If {\\it bounded}\\subI{} is true,\nthen {\\it minint}\\subI{} can be 0, -{\\it maxint}\\subI{}, or\n-({\\it maxint}\\subI{}+1).  Curiously, while both signed and\nunsigned bounded integers are allowed, unbounded integers\nmust be signed; ``unbounded natural numbers are not covered\nby this document.''  The usual 6 comparison operations are\ndefined.\n\nThe arithmetic operations are {\\it neg}\\subI{} (unary negation),\n{\\it add}\\subI{}, {\\it sub}\\subI{}, {\\it mul}\\subI{},\nflooring division {\\it quot}\\subI{} and the corresponding\nremainder {\\it mod}\\subI{}, {\\it abs}\\subI{},\nand {\\it signum}\\subI{} taking values 1 and -1.  The 1998 edition\nincluded {\\it sign}\\subI{} with values 1, 0, and -1, but that was\ndropped.  The 1998 edition included\ntruncating division {\\it div}${}^t_I$ and the corresponding\nremainder {\\it rem}${}^t_I$ and two additional remainder functions\n{\\it mod}${}^a_I$ and {\\it mod}${}^p_I$, all of which were deleted\nin the 2012 edition.\n\nLIA-1 integer arithmetic must handle overflow by causing\nan overflow indication.  This includes conversion to a \nsmaller integer type.  Wrapping arithmetic is covered in\npart 2.\n\nA floating point data type $F$ has parameters {\\it r}\\subF{}\n(radix), {\\it p}\\subF{} (precision), {\\it emax}\\subF{} (largest\nexponent), {\\it emin}\\subF{} (smallest exponent),\n{\\it denorm}\\subF{} (whether IEEE-style subnormals are supported),\nand {\\it ice\\_60559}\\subF{} (whether $F$ conforms to the IEEE\nstandard).  The usual 6 comparison operations are defined,\ntaking care to dodge around infinities and NaNs.\n\nAdditional tests {\\it isnegzero}\\subF{}, {\\it istiny}\\subF{},\n{\\it isnan}\\subF{}, and {\\it issignan}\\subF{} express tests that\ncannot be done using ordinary comparison against zero.\n\nThree sets of basic operations (rounding to nearest even, down,\nor up) are defined if {\\it denorm}\\subF{} is true, just the\nrounded to nearest set if {\\it denorm}\\subF{} is false.\nThe basic operations are {\\it add}, {\\it sub}, {\\it mul},\n{\\it div}, and {\\it sqrt}.\n\nSome arithmetic operations are not sensitive to rounding\nmode: {\\it abs}\\subF{}, two-valued {\\it signum}\\subF{},\nthe IEEE remainder {\\it residue}\\subF{}, {\\it intpart}\\subF{},\n{\\it fractpart}\\subF{}, {\\it succ}\\subF{} (next higher),\n{\\it pred}\\subF{} (next lower), and {\\it ulp}\\subF{}.\n\nThere are three conversions from floating point to integer:\n{\\it ceiling}${}_{F\\rightarrow I}$,\n{\\it floor}${}_{F\\rightarrow I}$, and\n{\\it rounding}${}_{F\\rightarrow I}$.\n\nSection 5.3.5 defines floating point to fixed point conversion\n(for the sake of format conversions like C's {\\tt \\%.$n$f}) and in\npassing defines unbounded fixed point types, with parameters\n{\\it r}\\subD{} (radix), {\\it d}\\subD{} (``density'' = scale),\nand {\\it dmax}\\subD{} (a positive element of $\\cal R$ or\nundefined).  Two sets are defined:\n\\begin{eqnarray*}\nD^* &=& \\{n/(r_D^{d_D}) | n \\in {\\cal Z}\\}\\\\\nD &=& D^* \\mbox{if unbounded}\\\\\nD &=& D^* \\cap [-dmax_D,dmax_D] \\mbox{if bounded}\n\\end{eqnarray*}\nThree rounding functions {\\it nearest}\\subD{} (our nearest even),\n{\\it up}\\subD{} (ceiling), and\n{\\it down}\\subD{} (floor), all ${\\cal R} \\rightarrow D^*$, are\ndefined.  Conversion from floating point to fixed point and\nfrom fixed point to floating point uses one of these rounding\nmodes just like the basic arithmetic operations.\n\nHowever, fixed point exists in LIA {\\it only} for I/O conversion;\nthere are no comparison or arithmetic operations on $D$.\n\nFloating point arithmetic with truncation is conspiciously\nabsent from the 2012 edition of LIA-1.  What it describes is\naccurately rounded arithmetic and the building blocks for\ninterval arithmetic.\n\n\\subsubsection{Part: 2 Elementary numerical functions}\n\nThis part was issued in 2001.  There are some slight ``continuity\nerrors'' due to the revision of LIA-1: {\\it iec\\_559}\\subF{} is\nnow {\\it iec\\_60559}\\subF{}, for example.  This is another example\nof why standards need to be machine-checked.\n\nThe additional integer operations include maximum, minimum,\ngreatest common divisor, and least common multiple\nof a pair or sequence, if $x\\ge y$ then $x-y$ else 0 (diminish),\ninteger power (but broken for $0^0$ so of very little use),\nfloored shifting by a power of 2 or 10, floored square root,\ndivisibility, evenness, oddness, floored ({\\it quot}\\subI{},\n{\\it mod}\\subI{}), rounded ({\\it ratio}\\subI{}, {\\it residue}\\subI{}),\nand ceilinged ({\\it group}\\subI{}, {\\it pad}) quotient and remainder.\n(The {\\it pad} operation is actually $\\lceil x/y \\rceil\\times y - x$.)\n\nThere are also wrapping versions of {\\it add}, {\\it sub}, and\n{\\it mul}, plus ``overflow'' versions giving you the high bits\nlost by wrapping so that multiprecision arithmetic can be written.\n\nThe additional floating point operations include maximum and\nminimum of a pair or sequence, diminish,  conversion to integral\nin floating form ({\\it floor}\\subF{}, {\\it rounding}\\subF{}, and\n{\\it ceiling}\\subF{}) together with {\\it *\\_rest}\\subF{} operations\nproviding the lost fraction parts exactly, square root (already\nin part 1) and reciprocal square root.  There is an operation\nfor multiplying two floats giving a result in a wider format with\na single rounding, just right for dot product.\n\nThe elementary transcendental operations include raising a\nfloating point number to an integer or floating point power,\nplus the usual exponential, logarithmic, trigonometric, and\nhyperbolic functions in several forms.\n\n\\subsubsection{Part 3: Complex integer and floating point\narithmetic and complex elementary numerical functions}\n\nThis part was issued in 2006.  It defines imaginary and\ncomplex integer and imaginary and complex floating point\ndata types, basic operations on them, and elementary\ntranscendental operations.  Maximum and minimum are extended\nto imaginary but not to complex types.\n\nPart 3 ends with recommended changes to some of the operations\ndefined in Part 2 ``so that the returned angle is for the\nproper quadrant''.  Again this suggests that a standard on which\ngreat care was taken might have benefited from testing.\n\n\\section{ISO/IEC/IEEE 60559:2011}\n\nThis is the standard for floating point arithmetic.\nIt is the ISO/IEC edition of IEEE 754:2008, which in\nturn was an update of classic IEEE 754 arithmetic to\ninclude decimal floating point.  It specifies\n32-, 64-, and 128-bit binary formats that can hold about 7,\n16, and 34 decimal digits respectively\nand 64- and 128-bit decimal formats that can hold\n16 and 34 decimal digits respectively (table 3.2).\n\nIt is common belief that IEEE 754 arithmetic is all but\nuniversal.  However, few systems support 128-bit binary floats\n(the popular ARM, x86, and x86-64 architectures do not; SPARC\ndoes), and even fewer support decimal floating-point natively\n(recent IBM z/Series and POWER machines do).\n\nIEEE 754 originally defined four rounding modes, up, down, in,\nand nearest even in our terminology.  The current standard\nadds nearest out (banker's rounding).\n\n\\subsection{COBOL}\n\nCOBOL is one of the oldest programming languages still in use.\nIt was designed to support accounting applications on small\nmachines.  For example, the Siemens 3003, regarded as ``a large-scale\n\\dots computer'', had 8000 words of\nstorage; the COBOL 61 compiler for that machine needed 10 passes.\nBrinch Hansen and House [ref] report that ``The major problem of\nimplementation turned out to be the numerous definition problems\ncreated by the vagueness of the official Cobol report.''\n\nOne of the major features of COBOL from the beginning was its\nuse of decimal fixed point arithmetic rather than floating point.\nAccounting applications required answers that were exact or\ncomputed according to known rounding rules.  Binary integers\nand floats were eventually adopted in 2002, but had been common\nextensions for many years.  \n\nA number is characterised by (a) whether it is signed or not,\n(b) its precision, and (c) its scale.  A declaration like\\\\\n77 SOME-NUMBER PICTURE S9$(b)$V$9(a)$\\\\\ndeclares a signed variable (S) with a precision of $b+a$\ndecimal digits and a scale of $a$.  The letter V designates\na virtual (not actually stored) decimal point.  In terms of\nLIA-1, this corresponds to $r_D = 10$, $d_D = a$,\n{\\it dmax}${}_D = (10^{a+b}-1)/10^b$.\n\nIn LIA-1, arithmetic is only defined between values of the\nsame type.  In COBOL, it is extremely common for the\noperands and result of an operation to be of different types.\nA typical instruction is\n\\begin{tabbing}\nwww\\=\\kill\nMULTIPLY X BY Y GIVING Z ROUNDED\\\\\n\\> ON SIZE ERROR {\\it statements}\\\\\n\\>  NOT SIZE ERROR {\\it statements}\\\\\nEND MULTIPLY  \n\\end{tabbing}\n\\noindent where the product $X\\times Y$ is computed\naccording to exact rational arithmetic, rounded to the\nscale of $Z$, and if the result is too large to fit,\nthe ON SIZE ERROR statements are executed, otherwise\nthe result is stored in Z and the NOT SIZE ERROR\nstatements are executed.\n\n\\subsubsection{Four semantics for arithmetic}\n\nThe previous paragraph is a lie.  The current COBOL standard does not\noffer a semantics for arithmetic.  It offers {\\it four} semantics for\narithmetic.  A COBOL program may contain an OPTIONS paragraph near\nthe beginning:\n\\begin{tabbing}\nwww\\=wwwwwwwwwwwwwwww\\=\\kill\nOPTIONS.\\\\\n\\> [ARITHMETIC IS \\{NATIVE $|$ STANDARD $|$\\\\\n\\> \\> STANDARD-BINARY $|$ STANDARD-DECIMAL \\}]\\\\\n\\> [DEFAULT ROUNDED MODE IS one of eight]\\\\\n\\> \\dots\\\\\n\\> [INTERMEDIATE ROUNDING IS one of four]\\\\\n\\end{tabbing}\n\nIn our terminology, the rounding modes are out, nearest out,\nnearest even, nearest in, exact, up, down, and in.\n\nThere is a subtle difference between these statements:\n\\begin{tabbing}\nMULTIPLY X BY Y GIVING Z.\\\\\nCOMPUTE Z = X * Y.\n\\end{tabbing}\nThe latter involves an arithmetic expression which has an\nintermediate result that is then assigned to the destination.\nThe former does not.  It appears that the MULTIPLY statement\ninvolves a single rounding whereas the COMPUTE statement may\ninvolve a double rounding.\n\n{\\it Native} arithmetic is whatever the implementor says it is.\n\n{\\it Standard} arithmetic is what used to be standard arithmetic in\nCOBOL-85.  It does not cover binary or floating-point operations,\nwhich are treated as native.  Standard arithmetic is declared to\nbe obsolete.  ``A standard intermediate data item is \\dots the\nunique value zero or an abstract, signed, normalized decimal\nfloating-point temporary data item \\dots with a precision of\n32 decimal digits'' and a scale of -999 to 999 (roughly speaking).\nIntermediate values are rounded in certain circumstances.\n\nIn expressions,\naddition, subtraction, multiplication, and\ndivision are are ``the exact [result] truncated\nto 32 significant digits, normalized, and stored in a standard\nintermediate data item''.\n\n{\\it Standard-binary} arithmetic requires arithmetic operations\nto be done according to IEEE binary floating-point\narithmetic (128-bit format).\n\n{\\it Standard-decimal} arithmetic requires arithmetic operations\nto be done according to IEEE decimal floating-point arithmetic\n(128-bit format).\n\nThe result is that the meaning of an arithmetic statement or\nexpressions can be changed by a line thousands of lines away.\n\nThe standard tries very hard to avoid using\nmathematical notation.  Let us take Format 5 of the\nDIVIDE statement as an example:\n\\begin{quote}\n\\begin{tabbing}\nwww\\=\\kill\nDIVIDE \\{identifier-2$|$literal-2\\} BY \\{identifier-1$|$literal-1\\}\\\\\n\\> GIVINE identifier-3 [rounded-prhase]\\\\\n\\> REMAINDER identifier-4\\\\\n\\> [ON SIZE ERROR imperative-statement-1]\\\\\n\\> [NOT SIZE ERROR imperative-statement-2]\\\\\n\\> [END-DIVIDE]\n\\end{tabbing}\n\n1) When native arithmetic is in effect, the quotient is the result\nof dividing the dividend by the divisor.  When standard arithmetic,\nstandard-decimal arithmetic, or standard-binary arithmetic is in\neffect, the quotient is the result of the arithmetic expression\n$$(\\mbox{dividend} / \\mbox{divisor})$$\nwhere the values of dividend and divisor are ...\n\n6b) The quotient is then formed as specified in general rule 1\nand stored in identifier-3 \\dots\n\n6c) If the size error condition is not raised, a subsidiary\nquotient is developed that is signed and derived from the\nquotient by truncation of digits at the least significant end\nand that has the same number of digits and the same decimal point\nlocation as the data item references by identifier-3.  The\nremainder is calculated as indicated in general rules 7 and is\nstored in the data item referenced by identifier-4 unless\nstoring the value would cause a size error condition \\dots\n\n7) When native arithmetic is in effect, the remainder is the\nresult of multiplying the subsidiary quotient and the divisor\nand subtracting the product from the dividend.  When standard\nstandard arithmetic, standard-decimal arithmetic, or\nstandard-binary arithmetic is in effect, the remainder is the\nresult of the arithmetic expression\n$$(\\mbox{divided} - (\\mbox{subsidiary-quotient} * \\mbox{divisor}))$$\nwhere \\dots\n\\end{quote}\n\nThe reason the standard {\\it does} use some expressions here is\nso that the rules for intermediate rounding apply to them.  With\n4 arithmetics, 8 intermediate roundings, and 4 default roundings,\na simple DIVIDE statement could mean 128 different things.\n\n\\subsection{PL/I}\n\nPL/I was introduced in the mid-1960s as a blend of Algol,\nFortran, and COBOL.  The ECMA-50 (1976), ANSI X3.53-1976, BS 7148:1990,\nNF Z 65-500, and ISO 6160:1979 standards for PL/I are all basically the\nsame.  They have expired.  BS ISO/IEC 6522:1992 (Information technology,\nProgramming languages, PL/I general purpose subset) is still current.\n\nPL/I fixed point types are characterised by a {\\it base} (2 or 10),\na {\\it precision} (total number of digits), and a {\\it scale} (number\nof digits after the radix point).  There are actually two sets of\nrules for determining the precision and scale of a result (ANSI and\nIBM).  For FIXED DECIMAL they coincide:\n\\begin{itemize}\n\\item\n$(p_1,s_1) \\pm (p_2,s_2) \\Rightarrow (p,s)$ where\\\\\n$s = s_1 \\vee s_2$\\\\\n$p = 1+s+(p_1-s_1 \\vee p_2-s_2)$\n\\item\n$(p_1,s_1) \\times (p_2,s_2) \\Rightarrow (p,s)$ where\\\\\n$s = s_1 + s_2$\\\\\n$p = 1+p_1+p_2$\n\\item\n$(p_1,s_1) / (p_2,s_2) \\Rightarrow (p,s)$ where\\\\\n$s = N-p_1+s_1-s+2$\\\\\n$p = N$ and $N$ is the implementation-defined maximum precision.\n\\item\nMOD$((p_1,s_1), (p_2,s_2)) \\Rightarrow (p,s)$ where\\\\\n$s - s_1 \\vee s_2$\\\\\n$p = N \\wedge (p_2 - s_2 + s)$.\n\\item\n$(p_1,s_1) ** k \\Rightarrow (p,s)$ where\\\\\n$s = s_1\\times k$\\\\\n$p = (p_1 + 1) \\times k - 1$, if $k$ is a literal integer.\n\\item\nROUND$((p_1,s_1), s) \\Rightarrow (p,s)$ where\\\\\n$s$ is given as the second argument\\\\\n$p = 1 \\vee (p_1-s_1+1-s \\wedge N)$\n\\end{itemize}\nThe rule for division can lead to some nasty surprises.\nFor example, 25+01/3 yields 25.3333333333333 but\n25+1/3 results in an overflow.  So there are special functions\nADD(x, y, p[, s]), SUBTRACT(x, y, p[, s]),  MULTIPLY(x, y, p[, s]),\nDIVIDE(x, y, p[, s]), \ncomputing a result to a specified precision and scale (default s = 0)\nin a single rounding.  There is no version of MOD with precision and\nscale parameters.  In assignment\nstatements, ``padding or truncation can occur on the left or the right.\nIf nonzero \\dots digits on the left are lost, the SIZE condition is\nraised.''  This means that a statement like\\\\\nX = X * Y;\\\\\nuses the ``in'' rounding mode.  Unlike COBOL, PL/I does not offer\ncontrol over rounding, not even using the special functions, so there is\nno way to change this.\n\n\\subsection{SQL}\n\nThe ISO/IEC 9075-1:2003 standard, SQL 2003, part 1,\nsays in section 4.4.3.1 that ``There are two classes of numeric\ntype: {\\it exact numeric}, which includes integer types and types\nwith specified precision and scale; and {\\it approximate numeric},\nwhich is essentially floating point, and for which a precision may\noptionally be specified.''  The result of an arithmetic operation\n``is of a numeric type that depends only on the numeric type of the\noperands.  If the result cannot be represented exactly in the result\ntype, then whether it is rounded or truncated is implementation-defined.\nAn exception condition is raised if the result is outside the range of\nnumeric values of the result type, or if the arithmetic operation is not\ndefined for the operands.''\n\nNumbers and arithmetic are defined in\nsection 4.4 of part 2.\n\\begin{quote}\n`An exact numeric type has a precision\n$P$ and a scale $S$.  $P$ is a positive integer that determines\nthe number of significant digits in a particular radix $R$,\nwhere $R$ is either 2 or 10.  $S$ is a non-negative integer.\nEvery value of an exact numeric type of scale $S$ is of the\nform $n\\times 10^{-S}$,\\footnote{It is possible that 10 should\nhave been $R$, but only INTEGER types with $S=0$ may have $R=2$.}\nwhere $n$ is an integer such that $-R^P \\le n < R^P$.\n[Note 13 --- Not every value in that range is necessarily a\nvalue of the type in question.]''\n\\end{quote}\nThe intent of note 13 may be to allow both sign-and-magnitude\nrepresentation for NUMERIC types and $R$'s-complement representation\nfor INTEGER types; it's not obvious why any other value would be\nexcluded.\n\nConversion may be done by rounding or truncation; it is not the\nprogrammer who chooses.\n\\begin{quote}\n``If an assignment of some number would result in a loss of its most\nsignificant digit, an exception condition is raised.  If least\nsignificant digits are lost, implementation-defined rounding or\ntruncating occurs, with no exception condition being raised.''\n\n``An approximation obtained by truncation of a numeric value $N$ for an\n$\\langle$exact numeric type$\\rangle$ $T$ is a value $V$ in $T$\nsuch that $N$ is not closer to\nzero than is $V$ and there is no value in $T$ between $V$ and $N$.\n\nAn approximation obtained by rounding of a numeric value $N$ for an\n$\\langle$exact numeric type$\\rangle$ $T$ is a value $V$ in $T$\nsuch that the absolute value of the difference between $N$\nand the numeric value of $V$ is not greater than half\nthe absolute value of the difference between two successive numeric\nvalues in $T$. If there is more than one such value $V$, then it is\nimplementation-defined which one is taken.''\n\\end{quote}\n\nAside from the non-portable nature of rounding,\narithmetic is supposed to be unsurprising:\n\\begin{quote}\n``Operations on numbers are performed according to the normal\nrules of arithmetic, within implementation-defined limits \\dots''\n\n``Numbers are compared with respect to their algebraic value.'' (8.2)\n\\end{quote}\n\nParaphrasing sections 4.4.3 and 6.26,\n\\begin{itemize}\n\\item The POWER function never returns an exact answer (unlike PL/I).\n\\item The floor and ceiling functions return exact integers $S=0$.\n\\item Unary plus, unary minus, and the absolute value function return a result\nof the same type as their argument.\n\\item  The MOD function only accepts integer arguments.\n\\item WIDTH\\_BUCKET$(x, l, u, n)$ appears to mean\n\\begin{tabbing}\nwww\\=www\\=\\kill\nif $l < u$ then\\\\\n\\> if $x<l$ then 0\\\\\n\\> else if $x \\ge u$ then $n+1$\\\\\n\\> else $\\lfloor n\\times((x-l)/(u-l)) \\rfloor$\\\\\nelse if $l > u$ then\\\\\n\\> if $x > l$ then 0\\\\\n\\> else if $x < u$ then $n+1$\\\\\n\\> else $\\lfloor n\\times((x-u)/(l-u)) \\rfloor$\\\\\n\\end{tabbing}\nand the result has the same type as $n$, which must be integral.\nA system that can implement this function ought to be able to\nimplement MOD on non-integral exact numbers.\n\\item If $x$ has radix $R$, precision $P_x$, and scale $S_x$,\nand $y$ has radix $R$, precision $P_y$, and scale $S_y$,\nthen $x+y$ and $x-y$ have scale max$(S_x,S_y)$ and\nimplementation-defined precision;\n\\item $x*y$ has scale $S_x+S_y$ and implementation-defined precision;\n\\item and $x/y$ has implementation-defined precision and\nimplementation-defined scale.\n\\item ``If the operator is not division and the mathematical result of\nthe operation is not exactly representable with the precision and scale\nof the result data type, then an exception condition is raised.''\n\\item ``If the operator is division and the approximate mathematical\nresult of the operation represented with the precision and scale of the\nresult data type loses one or more leading significant digits after\nrounding or truncating if necessary, then an exception condition is\nraised \\dots The choice of whether to round or truncate is\nimplementation-defined.''\n\\end{itemize}\n\nCOBOL and PL/I have fixed-point decimal types in order to support\naccounting.\nSQL was given fixed-point NUMERIC types in order to inter-operate\nwith COBOL and PL/I, and is very much used for accounting data.\nThe problem is that SQL arithmetic is {\\it not} guaranteed\nto be consistent with COBOL or PL/I or accounting rules:\n\\begin{itemize}\n\\item there is no programmer control over rounding;\n\\item there are no precisions that have to be supported,\nnot even older COBOL's 18 digits;\n\\item there is no fixed-point remainder; and\n\\item if you want to calculate the price of one\napple at \\$2.72 per dozen, $2.72/12$ could give\nyou the answer 0 if an implementation defined the\nscale for division to always be $S=0$.\n\\end{itemize}\n\n\\subsection{Smalltalk}\n\nSmalltalk-80 is the programming language that brought Object-Oriented\nprogramming and Integrated Development ENvironments to the world.\nIt got an ANSI standard in 1989.  The standard includes unbounded\nintegers, three sizes of floating point, rational numbers, and\na ScaledDecimal class.\n\nFor the semantics of operations on ScaledDecimal numbers,\nthe Smalltalk standard defers to ISO 10967 (LIA).  Unfortunately, LIA has,\nby intent and quite explicitly, nothing to say about fixed point\narithmetic.\n\nThe result is that implementations use one of four interpretations\nof ScaledDecimal:\n\\begin{itemize}\n\\item An arbitrary precision integer scaled by a power of 10.\nThis agrees well with the standard, which says that\n``Scaled decimal objects provide a precise representation of decimal\nfractions with an explicitly specified number of fractional digits.''.\n\\item An integer scaled by a power of 10, represented as a 16-byte\npacked decimal value.  This also agrees well with the standard.\n\\item An arbitrary precision rational number that is not in general\na whole multiple of a power of 10, rounded to a specified number of\ndigits when and only when printing.\n\\item The same, but with truncation instead of rounding.\n\\end{itemize}\nFor example,\n\\begin{tabbing}\n(2/3) asScaledDecimal: 2 $\\Longrightarrow$ 0.66s2\\\\\n``and'' 0.66s2 * 3 $\\Longrightarrow$ 1.98s2\\\\\n``but'' ((2/3) asScaledDecimal: 2) * 3 $\\Longrightarrow$ 2.00s2\n\\end{tabbing}\nin several Smalltalks (several others yield 0.67s2), while\n\\begin{tabbing}\n(2/3) asScaledDecimal: 2 $\\Longrightarrow$ 0.67s2\\\\\n0.67s2 * 3 $\\Longrightarrow$ 2.01s2\\\\\n((2/3) asScaledDecimal: 2) * 3 $\\Longrightarrow$ 2.01s2\n\\end{tabbing}\nin Smalltalks using a scaled-integer interpretation.\n\n% Standard: #+ #- #* #/ result scale is at least receiver scale.\n% Majority rule: result scale is max(receiver scale, operand scale).\n% astc: #+ #- => max(r,o); #* => r+o #/ ->\n% astc: x \\\\ y = x - ((x // y) * y) => #- rule\n%       x rem: y = x - ((x quo: y) * y) => #- rule.\n\n\\subsection{C$\\sharp$}\n\nSummary: decimal arithmetic is standard in C$\\sharp$.\nSuch numbers are value types, as in COBOL and PL/I.\nC$\\sharp$ does not support sufficient precision or sufficient scale\nto allow unproblematic conversion of COBOL 2002 code or\ndata, though it is adequate for COBOL 85.  There is no\nprogrammer control over rounding.  Scale is part of the\nvalue, not part of the type, and the rule for division\nmakes it hard to track scale at compile time.  Above all,\ndecimal arithmetic in C$\\sharp$ is exact {\\it except when\nit isn't}.  The compiler will not tell you when unexpected\nrounding {\\it might} happen, nor does the runtime system\ntell you when it {\\it has} happened.\n\nISO/IEC 23270:2006 defines C$\\sharp$ as it was in 2005.\nISO/IEC 23231:2012 defines the Common Language Infrastructure\nThe CLI standard omits the ``Extended numerics library'' (section\nIV.5.7), including System.Decimal, but the language standard\nhas much to say.\n\nSection 8.2.1 says\n\\begin{quote}\nThe {\\tt decimal} type is appropriate for calculations in which\nrounding errors caused by floating-point representations are\nunacceptable.\n\\end{quote}\n\nExcept for rounding errors introduced silently by C$\\sharp$ itself.\n\nSection 11.1.7 defines the {\\tt decimal} type.\n\\begin{quote}\nThe {\\tt decimal} type is a 128-bit data type suitable for\nfinancial and monetary calcuations.  The {\\tt decimal} type\ncan represent values including those in the range $1\\times 10^{-28}$\nthrough $1\\times 10^{28}$ with at least 28 significant digits.\nThe finite set of values of of type {\\tt decimal} are of the\nform $(-1)^s\\times c\\times 10^{-e}$, where the sign $s$ is 0 or 1,\nthe coefficient $c$ is given by $0\\le c<Cmax$ and the scale $e$\nis such that $Emin\\le e\\le Emax$, where $Cmax$ is at least\n$1\\times 10^{28}$, $Emin\\le 0$, and $Emax\\ge 28$.  The decimal\ntype does not necessarily support signed zeros, infinities, or\nNaN's.\n\nA {\\tt decimal} is represented as an integer scaled by a power of\nten.  For {\\it decimal}s with an absolute value less than {\\tt 1.0m},\nthe value is exact to at least the 28${}^{th}$ decimal place.\nFor {\\tt decimal}s with an absolute value greater than or equal to\n{\\tt 1.0m}, the value is exact to at least 28 digits.  Contrary\nto the {\\tt float} and {\\tt double} data types, decimal fractional\nvalues such as {\\tt 0.1} can be represented exactly in the\n{\\tt decimal} representation.  In the {\\tt float} and {\\tt double}\nrepresentations, such numbers often have non-terminating binary\nexpansions, making those representations more prone to round-off errors.\n\nThe result of an operation on values of type {\\it decimal} is that\nwhich would result from calculating an exact result (preserving\nscale, as defined for each operator) and then rounding to fit the\nrepresentation.  Results are rounded to the nearest representable\nvalue, and, when a result is equally close to two representable\nvalues, to the value that has an even number in the least significant\ndigit position (this is known as ``banker's rounding'').  That is,\nresults are exact to at least the 28${}^{th}$ decimal place.\nNote that rounding may produce a zero value from a non-zero value.\n\nIf a {\\tt decimal} arithmetic operation produces a result whose magnitude\nis too large for the {\\tt decimal format}, a\n{\\tt System.OverflowException} is thrown.\n\nThe {\\tt decimal} type has greater precision but may have a smaller\nrange than the floating-point types.  Thus, conversions from the\nfloating-point types to {\\it decimal} might produce overflow\nexceptions, and conversions from {\\tt decimal} to the floating-point\ntypes might cause loss of precision or overflow exceptions.  For\nthese reasons, no implicit conversions exist between the floating-point\ntypes and {\\tt decimal}, and without explicit casts, a compile-time\nerror occurs when floating-point and {\\tt decimal} operands are\ndirectly mixed in the same expression.\n\\end{quote}\n\nSection 14.7, ``arithmetic operators'', says\n\\begin{quote}\nThe scale of the result [of a decimal multiplication],\nbefore any rounding, is the sum of the scales of the two operands.\n\nThe scale of the result [of a decimal division],\nbefore any rounding, is the closest scale to the preferred scale which\nwill preserve a result equal to the exact result.  The preferred scale\nis the scale of x less the scale of y.\n\nThe scale of the result [of a decimal remainder],\nbefore any rounding, is the larger of the scales of the two operands,\nand the sign of the result, if non-zero, is the same as that of [the\nfirst operand].\n\nThe scale of the result [of a decimal addition or subtraction],\nbefore any rounding, is the larger of the scales of the two operands.\n\\end{quote}\n\nWith the exception of division, the scale rules are familiar and\nsensible. There is no division method that\ntakes a desired scale argument, unlike PL/I.\n\nThe scale rule for division appears to be intended to\nensure that scale($(x*y)/y$) = scale($x$), but if we take\n{\\tt 1.0m/3.0m} there is {\\bf no} scale which ``will preserve a\nresult equal to the exact result'', and this is the case for almost\nevery possible division.  What you get is the highest supported scale\nthat doesn't result in an overflow.\n\nThere is no direct way to ask a {\\tt decimal} for its scale,\nbut two numerically equivalent values can be operationally\ndistinguished:\n\\begin{tabbing}\n1.0m.ToString() $\\Longrightarrow$ \"1.0\"\\\\\n1.00m.ToString() $\\Longrightarrow$ \"1.00\"\\\\\n4.0m/2.0m $\\Longrightarrow$ 2\\\\\n4.00m/2.0m $\\Longrightarrow$ 2.0\n\\end{tabbing}\n\nThe remainder operator is the counterpart of the operation that\ndivides two decimal numbers giving an exact integer result.\nThere is no such operation.\n\nThe {\\tt System.Decimal} class has methods {\\tt Ceiling},\n{\\tt Round}, {\\tt Floor}, and {\\tt Truncate} which return exact\ninteger answers in {\\tt decimal} form, no integer\ntype is certain to be large enough.  The Round method has\noptional desired-scale and how-to-round-0.5 arguments,\nsupporting nearest out and nearest even.\n\n% C$\\sharp$ changes faster than ISO processes can keep up with.\n% The current specification is C$\\sharp$ version 6.0.\n\n\\subsection{Java}\n\nSummary: decimal numbers in Java are a reference type,\n{\\tt java.math.BigDecimal}, not a primitive type.\nThere are no literals for this type nor\nare the usual arithmetic operators available.\nIt is not described in the Java Language Specification.\nHowever, full control over rounding is possible, and\nJava gives exact results unless you ask for rounding.\nIt {\\it is} possible to convert COBOL 2002 and data to\nJava.  Any finite {\\tt float} or {\\tt double} value can\nbe represented exactly as a {\\tt BigDecimal}.\n\nThere is no international standard for Java, but there is the\nmuch-revised Java Language Specification\n[https://docs.oracle.com/javase/specs/jls/se8/html/index.html]\nand the Java Community Process for maintaining Java, which is not\nentirely unlike a standards process.\n\nThe version of Java current at the time of writing was 1.8,\nand that edition of the Java Language Specification has nothing to say\nabout {\\tt BigDecimal}.\n\nThe Java API Online Reference\n[https://docs.oracle.com/javase/8/docs/api/overview-summary.html]\nsays that\n\\begin{quote}\n[{\\tt BigDecimal}s are i]mmutable, arbitrary-precision\nsigned decimal numbers.  A {\\tt BigDecimal} consists of an\narbitrary precision integer {\\it unscaled value} and a 32-bit\ninteger {\\it scale} [which may be positive, negative, or zero].\nThe value represented by [a] {\\tt bigDecimal} is therefore\n$(\\mbox{unscaledValue} \\times 10^{-\\mbox{scale}})$.\n\nThe {\\tt BigDecimal} class gives its user complete control over\nrounding behavior.  If no rounding mode is specified and the exact\nresult cannot be represented, an exception is thrown; otherwise,\ncalculations can be carried out to a chosen precision and rounding mode\nby supplying an appropriate {\\tt MathContext} object to the operation.  In\neither case, eight rounding modes are provided for the control of\nrounding.\n\nWhen a {\\tt MathContext} object is supplied with a precision setting\n0f 0 \\dots, arithmetic operations are exact.  \\dots In the case of\ndivide, the exact quotient could have an infinitely long decimal\nexpansion; for example, 1 divided by 3.  If the quotient has a\nnonterminating decimal expansion and the operation is specified to\nreturn an exact result, an ArithmeticException is thrown.  Otherwise,\nthe exact result of the division is returned, as done for other\noperations.\n\nSince the same numerical value can have different representations (with\ndifferent scales), the rules of arithmetic and rounding must specify\nboth the numerical result and the scale used in the result's\nrepresentation.\n\nFor all arithmetic operators, the operation is carried out as though an\nexact intermediate result were first calculated and then rounded to the\nnumber of digits specified by the precision setting (if necessary),\nusing the selected rounding mode.\n\nBesides a logical exact result, each arithmetic operation has a\npreferred scale for representing a result.\n\n\\begin{tabular}{|l|l|}\n\\hline\nOperation | Preferred Scale of Result\\\\\n\\hline\nAdd | max(addend.scale(), augend.scale())\\\\\n\\hline\nSubtract | max(minuend.scale(), subtrahend.scale())\\\\\n\\hline\nMultiply | multiplier.scale() + multiplicand.scale()\\\\\n\\hline\nDivide | dividend.scale() - divisor.scale()\\\\\n\\hline\n\\end{tabular}\n\n\\dots an exact divide may have to use a larger scale [when]\nthe exact result has more digits.\n\n{\\tt BigDecimal}'s {\\it natural ordering} is\n{\\it inconsistent with equals}.\n\\end{quote}\n\nThe issue here is that {\\tt compareTo} compares the algebraic\nvalues of two {\\tt BigDecimal}s, but {\\tt equals} compares\ntheir representations.\n\nQuotient returning an integer in {\\tt BigDecimal} form and\ncorresponding remainder are supported.\n\n\\subsection{Swift}\n\nSummary: Swift supports decimal numbers with up to 38 digits\nand a scale of -128 to 127.  \n\nSwift is a fast-changing language pushed by Apple.\nAt the time of writing the current version was Swift 3.\n\nSwift 2 supported ``toll-free bridging'' to the Objective-C\ntype {\\tt NSDecimalNumber}, ``[a]n instance [of which]\ncan represent any number that can be expressed as\nmantissa\n$\\times$\n$10^{exponent}$\nwhere mantissa\nis a decimal integer up to 38 digits long, and exponent is an\ninteger from -128 through 127.''\n\nSwift 3 has a native {\\tt Decimal} ``value type which offers\nthe same functionality as the {\\tt NSDecimalNumber} reference\ntype, and the two can be used interchangeably in Swift code\nthat interacts with Objective-C APIs.''  Literals in integer\nor floating-point form can be used where Decimal literals\nare wanted, but they are first stored as Int or Float and\nthen converted to Decimal.\n\nSwift {\\tt Decimal}s include a NaN value but not infinities\nor negative zero.\n\nThe {\\tt NSDecimal} methods {\\tt adding}, {\\tt subtracting}, {\\tt multiplying},\n{\\tt dividing}, and {\\tt raising} have an optional\n{\\tt NSDecimalNumberBehavior} argument, like the corresponding\nJava methods, which specifies a desired scale and rounding\nmode, which can be up, down, in, or nearest out.\nThere is also {\\tt NSDecimalNumberHandler} which can specify\nwhat to do if an answer is inexact or overflows.\nIn Swift, there are methods {\\tt add, +}, {\\tt subtract, -},\n{\\tt multiply, *}, and {\\tt divide, /} without control arguments\nand NSDecimalAdd, NSDecimalSubtract, NSDecimalMultiply,\nand NSDecimalDivide methods with RoundingMode parameter.\n\n[The current state of the documentation for Swift 3 is\n{\\bf horrible}.  I'm having serious trouble finding\n{\\it anything} about how this all works.]\n\n\n\\end{document}\n", "meta": {"hexsha": "ea7f028b427f9bb8a4998300908d3e50252fc73e", "size": 37560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-stds.tex", "max_stars_repo_name": "nzok/decimal", "max_stars_repo_head_hexsha": "939e3403d706a2ab9dfa9fd24c17f2953e074b52", "max_stars_repo_licenses": ["MIT"], "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-stds.tex", "max_issues_repo_name": "nzok/decimal", "max_issues_repo_head_hexsha": "939e3403d706a2ab9dfa9fd24c17f2953e074b52", "max_issues_repo_licenses": ["MIT"], "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-stds.tex", "max_forks_repo_name": "nzok/decimal", "max_forks_repo_head_hexsha": "939e3403d706a2ab9dfa9fd24c17f2953e074b52", "max_forks_repo_licenses": ["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.9748283753, "max_line_length": 79, "alphanum_fraction": 0.751171459, "num_tokens": 9939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6348979446734558}}
{"text": "\\chapter{Advanced Simplifying Methods}\\label{ch07}\n\\section{Quine-McCluskey Simplification Method}\n\\subsection{Introduction}\n\n\\marginpar{This method was developed by W.V. Quine and Edward J. McCluskey and is sometimes called the method of prime implicants.} When a Boolean equation involves five or more variables it becomes very difficult to solve using standard algebra techniques or Karnaugh maps; however, the Quine-McCluskey algorithm can be used to solve these types of Boolean equations.  \n\nThe Quine-McCluskey method is based upon a simple Boolean algebra principle: if two expressions differ by only a single variable and its complement then those two expressions can be combined: \n\n\\begin{align}\n\t\\label{ASM:eq:quine-mccluskey_combining_complements}\n\tABC+ABC' &= AB \n\\end{align}\n\nThe Quine-McCluskey method looks for expressions that differ by only a single variable and combines them. Then it looks at the combined expressions to find those that differ by a single variable and combines them. The process continues until there are no expressions remaining to be combined.\n\n\\subsection{Example One}\n\\label{ASM:subsec:quine-mccluskey_ex_1}\n\n\\subsubsection{Step 1: Create the Implicants}\n\\label{ASM:subsubsec:quine-mccluskey_ex_1_step_1}\n\nEquation \\ref{ASM:eq:qm_ex_1} is the Sigma representation of a Boolean equation.\n\n\\begin{align}\n\t\\label{ASM:eq:qm_ex_1}\n\t\\int(A,B,C,D)=\\sum(0,1,2,5,6,7,9,10,11,14) \n\\end{align}\n\nTruth Table \\ref{ASM:tab:qm_ex_1_minterm_table} shows the input variables for the \\emph{True} minterm values.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{Minterm} & \\head{A} & \\head{B} & \\head{C} & \\head{D} \\\\\n\t\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t1 & 0 & 0 & 0 & 1 \\\\\n\t\t\t2 & 0 & 0 & 1 & 0 \\\\\n\t\t\t5 & 0 & 1 & 0 & 1 \\\\\n\t\t\t6 & 0 & 1 & 1 & 0 \\\\\n\t\t\t7 & 0 & 1 & 1 & 1 \\\\\n\t\t\t9 & 1 & 0 & 0 & 1 \\\\\n\t\t\t10 & 1 & 0 & 1 & 0 \\\\\n\t\t\t11 & 1 & 0 & 1 & 1 \\\\\n\t\t\t14 & 1 & 1 & 1 & 0 \n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: Minterm Table}\n  \\label{ASM:tab:qm_ex_1_minterm_table}\n\\end{table}\n\nTo simplify this equation, the minterms that evaluate to \\emph{True} (as listed above) are first placed in a minterm table so that they form sections that are easy to combine. Each section contains only the minterms that have the same number of ones. Thus, the first section contains all minterms with zero ones, the second section contains the minterms with one one, and so forth. Truth Table \\ref{ASM:tab:qm_ex_1_rearranged_table} shows the minterms rearranged appropriately.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{Number of 1's} & \\head{Minterm} & \\head{Binary} \\\\\n\t\t\t0 & 0 & 0000 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{1} & 1 & 0001 \\\\\n\t\t\t\t\t\t\t   & 2 & 0010 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{4}{*}{2} & 5  & 0101 \\\\\n\t\t\t\t\t\t\t   & 6  & 0110 \\\\\t\t\n\t\t\t\t\t\t\t   & 9  & 1001 \\\\\t\t\n\t\t\t\t\t\t\t   & 10 & 1010 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{3}{*}{3} & 7  & 0111 \\\\\n\t\t\t\t\t\t\t   & 11 & 1011 \\\\\t\t\n\t\t\t\t\t\t\t   & 14 & 1110 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: Rearranged Table}\n  \\label{ASM:tab:qm_ex_1_rearranged_table}\n\\end{table}\n\nStart combining minterms with other minterms to create Size Two Implicants (called that since each implicant combines two minterms), but only those terms that vary by a single binary digit can be combined. When two minterms are combined, the binary digit that is different between the minterms is replaced by a dash, indicating that the digit does not matter. For example, $ 0000 $ and $ 0001 $ can be combined to form $ 000- $. The table is modified to add a Size Two Implicant column that indicates all of the combined terms. Note that every minterm must be compared to every other minterm so all possible implicants are formed. This is easier than it sounds, though, since terms in section one must be compared only with section two, then those in section two are compared with section three, and so forth, since each section differs from the next by a single binary digit. The Size Two Implicant column contains the combined binary form along with the numbers of the minterms used to create that implicant. It is also important to mark all minterms that are used to create the Size Two Implicants since allowance must be made for any not combined. Therefore, in the following table, as a minterm is used it is also struck through. Table \\ref{ASM:tab:quine-mccluskey_ex_1_size_2_implicants} shows the Size Two Implicants that were found.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc|l} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{1's} & \\head{Mntrm} \n\t\t\t\t& \\head{Bin} & \\head{Size 2} \\\\\n\t\t\t                 0 & \\sout{0} & 0000 & 000- (0,1) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{2}{*}{1} & \\sout{1}  & 0001 & 00-0 (0,2) \\\\\n\t\t\t                   & \\sout{2}  & 0010 & 0-01 (1,5) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{4}{*}{2} & \\sout{5}  & 0101 & -001 (1,9) \\\\\n\t\t\t                   & \\sout{6}  & 0110 & 0-10 (2,6) \\\\\t\t\n\t\t\t                   & \\sout{9}  & 1001 & -010 (2,10) \\\\\t\t\n\t\t\t                   & \\sout{10} & 1010 & 01-1 (5,7) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{3} & \\sout{7}  & 0111 & 011- (6,7) \\\\\n\t\t\t                   & \\sout{11} & 1011 & -110 (6,14) \\\\\t\t\n\t\t\t                   & \\sout{14} & 1110 & 10-1 (9,11) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t                   &    &      & 101- (10,11) \\\\\n\t\t\t                   &    &      & 1-10 (10,14) \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: Size 2 Implicants}\n  \\label{ASM:tab:quine-mccluskey_ex_1_size_2_implicants}\n\\end{table}\n\nAll of the Size Two Implicants can now be combined to form Size Four Implicants (those that combine a total of four minterms). Again, it is essential to only combine those with only a single binary digit difference. For this step, the dash can be considered the same as a single binary digit, as long as it is in the same place for both implicants. Thus, $ -010 $ and $ -110 $ can be combined to $ --10 $, but $ -010 $ and $ 0-00 $ cannot be combined since the dash is in different places in those numbers. It helps to match up the dashes first and then look at the binary digits. Again, as the various size-two implicants are used they are marked; but notice that a single size-four implicant actually combines four size-two implicants. Table \\ref{ASM:tab:quine-mccluskey_ex_1_size_4_implicants} shows the Size Four Implicants.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc|l|l} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{1's} & \\head{Mntrm} \n\t\t\t& \\head{Bin} & \\head{Size 2} & \\head{Size 4} \\\\\n\t\t\t                 0 & \\sout{0}  & 0000 & 000- (0,1)  & --10 (2,10,6,14) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{2}{*}{1} & \\sout{1}  & 0001 & 00-0 (0,2)  & \\\\\n\t\t\t                   & \\sout{2}  & 0010 & 0-01 (1,5)  & \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{4}{*}{2} & \\sout{5}  & 0101 & -001 (1,9)  & \\\\\n                               & \\sout{6}  & 0110 & \\sout{0-10 (2,6)}  & \\\\\t\t\n\t\t\t                   & \\sout{9}  & 1001 & \\sout{-010 (2,10)} & \\\\\t\t\n\t\t\t                   & \\sout{10} & 1010 & 01-1 (5,7)  & \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{3} & \\sout{7}  & 0111 & 011- (6,7)  & \\\\\n\t\t\t                   & \\sout{11} & 1011 & \\sout{-110 (6,14)} & \\\\\t\t\n\t\t\t                   & \\sout{14} & 1110 & 10-1 (9,11) & \\\\\n\t\t\t\\cline{1-3}\n\t\t\t                   &           &      & 101- (10,11) & \\\\\n\t\t\t                   &           &      & \\sout{1-10 (10,14)} & \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: Size 4 Implicants}\n  \\label{ASM:tab:quine-mccluskey_ex_1_size_4_implicants}\n\\end{table}\n\nNone of the terms can be combined any further. All of the minterms or implicants that are not marked are \\emph{Prime Implicants}. In the table above, for example, the Size Two Implicant $ 000- $ is a Prime Implicant. The Prime Implicants will be placed in a chart and further processed in the next step. \n\n\\subsubsection{Step 2: The Prime Implicant Table}\n\\label{ASM:subsubsec:quine-mccluskey_ex_1_step_2}\n\nA \\emph{Prime Implicant Table} can now be constructed, as in Table \\ref{ASM:tab:qm_ex_1_prime_implicants}. The prime implicants are listed down the left side of the table, the decimal equivalent of the minterms goes across the top, and the Boolean representation of the prime implicants is listed down the right side of the table. \n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\\begin{tabular}{lccccccccccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t& \\head{0} & \\head{1} & \\head{2} & \\head{5}\n\t\t\t& \\head{6} & \\head{7} & \\head{9} & \\head{10}\n\t\t\t& \\head{11} & \\head{14} & \\\\\n\t\t\t\t\t\t\t%      0   1   2   5   6   7   9  10  11  14  \n\t\t\t$ 000-\\;(0,1) $       & X & X &   &   &   &   &   &   &   &   & $ A'B'C' $ \\\\\n\t\t\t$ 00-0\\;(0,2) $       & X &   & X &   &   &   &   &   &   &   & $ A'B'D' $ \\\\\n\t\t\t$ 0-01\\;(1,5) $       &   & X &   & X &   &   &   &   &   &   & $ A'C'D $ \\\\\n\t\t\t$ -001\\;(1,9) $       &   & X &   &   &   &   & X &   &   &   & $ B'C'D $ \\\\\n\t\t\t$ 01-1\\;(5,7) $       &   &   &   & X &   & X &   &   &   &   & $ A'BD $ \\\\\n\t\t\t$ 011-\\;(6,7) $       &   &   &   &   & X & X &   &   &   &   & $ A'BC $ \\\\\n\t\t\t$ 10-1\\;(9,11) $      &   &   &   &   &   &   & X &   & X &   & $ AB'D $ \\\\\n\t\t\t$ 101-\\;(10,11) $     &   &   &   &   &   &   &   & X & X &   & $ AB'C $ \\\\\n\t\t\t$ --10\\;(2,10,6,14) $ &   &   & X &   & X &   &   & X &   & X & $ CD' $ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: Prime Implicants}\n  \\label{ASM:tab:qm_ex_1_prime_implicants}\n\\end{table}\n\nAn \\emph{X} marks the intersection where each minterm (on the top row) is used to form one of the prime implicants (in the left column). Thus, minterm $ 0 $ (or $ 0000 $) is used to form the prime implicant $ 000- (0,1) $ in row one and $ 00-0 (0,2) $ in row two. \n\nThe Essential Prime Implicants can be found by looking for columns that contain only one \\emph{X}. The column for minterm $ 14 $ has only one \\emph{X}, in the last row, $ --10 (2,10,6,14) $; thus, it is an Essential Prime Implicant. That means that the term in the right column for the last row, $ CD' $, must appear in the final simplified equation. However, that term also covers the columns for $ 2 $, $ 6 $, and $ 10 $; so they can be removed from the table. The Prime Implicant table is then simplified to \\ref{ASM:tab:qm_ex_1_1st_iteration}.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccccccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{0} & \\head{1} & \\head{5}\n\t\t\t\t& \\head{7} & \\head{9} & \\head{11} & \\\\\n\t\t\t\t%                      0   1   5   7   9  11   \n\t\t\t\t$ 000-\\;(0,1) $       & X & X &   &   &   &   & $ A'B'C' $ \\\\\n\t\t\t\t$ 00-0\\;(0,2) $       & X &   &   &   &   &   & $ A'B'D' $ \\\\\n\t\t\t\t$ 0-01\\;(1,5) $       &   & X & X &   &   &   & $ A'C'D $ \\\\\n\t\t\t\t$ -001\\;(1,9) $       &   & X &   &   & X &   & $ B'C'D $ \\\\\n\t\t\t\t$ 01-1\\;(5,7) $       &   &   & X & X &   &   & $ A'BD $ \\\\\n\t\t\t\t$ 011-\\;(6,7) $       &   &   &   & X &   &   & $ A'BC $ \\\\\n\t\t\t\t$ 10-1\\;(9,11) $      &   &   &   &   & X & X & $ AB'D $ \\\\\n\t\t\t\t$ 101-\\;(10,11) $     &   &   &   &   &   & X & $ AB'C $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: 1st Iteration}\n  \\label{ASM:tab:qm_ex_1_1st_iteration}\n\\end{table}\n\nThe various rows can now be combined in any order the designer desires. For example, if row $ 10-1 (9,11) $, is selected as a required implicant in the solution, then minterms $ 9 $ and $ 11 $ are accounted for in the final equation, which means that all \\emph{X} marked in those columns can be removed. When that is done, then, rows $ 101- (10,11) $ and $ 10-1 (9,11) $ no longer have any marks in the table, and they can be removed. Table \\ref{ASM:tab:qm_ex_1_2nd_iteration} shows the last iteration of this solution. \n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccccccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{0} & \\head{1} & \\head{5}\n\t\t\t\t& \\head{7} & \\\\\n\t\t\t\t%                      0   1   5   7      \n\t\t\t\t$ 000-\\;(0,1) $       & X & X &   &   & $ A'B'C' $ \\\\\n\t\t\t\t$ 00-0\\;(0,2) $       & X &   &   &   & $ A'B'D' $ \\\\\n\t\t\t\t$ 0-01\\;(1,5) $       &   & X & X &   & $ A'C'D $ \\\\\n\t\t\t\t$ -001\\;(1,9) $       &   & X &   &   & $ B'C'D $ \\\\\n\t\t\t\t$ 01-1\\;(5,7) $       &   &   & X & X & $ A'BD $ \\\\\n\t\t\t\t$ 011-\\;(6,7) $       &   &   &   & X & $ A'BC $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: 2nd Iteration}\n  \\label{ASM:tab:qm_ex_1_2nd_iteration}\n\\end{table}\n\nThe designer next decided to select $ 01-1 (5,7) $, $ A'BD $, as a required implicant. That will include minterms $ 5 $ and $ 7 $, and those columns may be removed along with rows $ 01-1 (5,7) $, $ A'BD $, and $ 011- (6,7) $, $ A'BC $, as shown in Table \\ref{ASM:tab:qm_ex_1_3rd_iteration}.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccccccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{0} & \\head{1} & \\\\\n\t\t\t\t%                       0   1         \n\t\t\t\t$ 000-\\;(0,1) $       & X & X & $ A'B'C' $ \\\\\n\t\t\t\t$ 00-0\\;(0,2) $       & X &   & $ A'B'D' $ \\\\\n\t\t\t\t$ 0-01\\;(1,5) $       &   & X & $ A'C'D $ \\\\\n\t\t\t\t$ -001\\;(1,9) $       &   & X & $ B'C'D $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 1: 3rd Iteration}\n  \\label{ASM:tab:qm_ex_1_3rd_iteration}\n\\end{table}\n\nThe last two minterms ($ 0 $ and $ 1 $) can be covered by the implicant $ 000- (0,1) $, and that also eliminates the last three rows in the chart. \n\nThe original Boolean expression, then, has been simplified from ten minterms to Equation \\ref{ASM:eq:qm_ex_1_solution}.\n\n\\begin{align}\n\t\\label{ASM:eq:qm_ex_1_solution}\n\tA'B'C'+A'BD+AB'D+CD' = Y \n\\end{align}\n\n\\subsection{Example Two}\n\\label{ASM:subsec:quine-mccluskey_ex_2}\n\n\\subsubsection{Step 1: Create the Implicants}\n\\label{ASM:subsubsec:quine-mccluskey_ex_2_step_1}\n\nGiven Equation \\ref{ASM:eq:qm_ex_2}, which is a Sigma representation of a Boolean equation.\n\n\\begin{align}\n\\label{ASM:eq:qm_ex_2}\n\\int(A,B,C,D,E,F)=\\sum(0,1,8,9,12,13,14,15,32,33,37,39,48,56) \n\\end{align}\n\nTruth Table \\ref{ASM:tab:qm_ex_2_minterm_table} shows the \\emph{True} minterm values.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccccccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{Minterm} & \\head{A} & \\head{B} & \\head{C} \n\t\t\t\t& \\head{D} & \\head{E} & \\head{F} \\\\\n\t\t\t0  & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t1  & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n\t\t\t8  & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n\t\t\t9  & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n\t\t\t12 & 0 & 0 & 1 & 1 & 0 & 0 \\\\\n\t\t\t13 & 0 & 0 & 1 & 1 & 0 & 1 \\\\\n\t\t\t14 & 0 & 0 & 1 & 1 & 1 & 0 \\\\\n\t\t\t15 & 0 & 0 & 1 & 1 & 1 & 1 \\\\\n\t\t\t32 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t33 & 1 & 0 & 0 & 0 & 0 & 1 \\\\\n\t\t\t37 & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n\t\t\t39 & 1 & 0 & 0 & 1 & 1 & 1 \\\\\n\t\t\t48 & 1 & 1 & 0 & 0 & 0 & 0 \\\\\n\t\t\t56 & 1 & 1 & 1 & 0 & 0 & 0 \\\\\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: Minterm Table}\n  \\label{ASM:tab:qm_ex_2_minterm_table}\n\\end{table}\n\nTo simplify this equation, the minterms that evaluate to \\emph{True} are placed in a minterm table so that they form sections that are easy to combine. Each section contains only the minterms that have the same number of ones. Thus, the first section contains all minterms with zero ones, the second section contains the minterms with one one, and so forth. Table \\ref{ASM:tab:qm_ex_2_rearranged_table} shows the rearranged truth table.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{Number of 1's} & \\head{Minterm} & \\head{Binary} \\\\\n\t\t\t\t\t\t\t 0 & 0  & 000000 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{3}{*}{1} & 1  & 000001 \\\\\n                               & 8  & 001000 \\\\\n                               & 32 & 100000 \\\\\n \t\t\t\\hline\n\t\t\t\\multirow{4}{*}{2} & 9  & 001001 \\\\\n                               & 12 & 001100 \\\\\t\t\n\t\t\t\t\t\t\t   & 33 & 100001 \\\\\t\t\n\t\t\t\t\t\t\t   & 48 & 110000 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{3}{*}{3} & 13 & 001101 \\\\\n\t\t\t\t\t\t\t   & 14 & 001110 \\\\\t\t\n\t\t\t\t\t\t\t   & 37 & 100101 \\\\\t\t\n\t\t\t\t\t\t\t   & 56 & 111000 \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{4} & 15 & 001111 \\\\\n\t\t\t\t\t\t\t   & 39 & 100111 \\\\\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: Rearranged Table}\n  \\label{ASM:tab:qm_ex_2_rearranged_table}\n\\end{table}\n\nStart combining minterms with other minterms to create Size Two Implicants, as in Table \\ref{ASM:tab:qm_ex_2_size_2_implicants}.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc|c} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{1's} & \\head{Mntrm} & \\head{Bin} & \\head{Size 2} \\\\\n\t\t\t\t\t\t\t 0 & \\sout{0} & 000000 & 00000- (0,1) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{1} & \\sout{1}  & 000001 & -000000 (0,32) \\\\\n\t\t\t\t\t\t\t   & \\sout{8}  & 001000 & 00-000 (0,8) \\\\\n\t\t\t\t\t\t\t   & \\sout{32} & 100000 & -00001 (1,33) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{4}{*}{2} & \\sout{9}  & 001001 & 00-001 (1,9) \\\\\n\t\t\t\t\t\t\t   & \\sout{12} & 001100 & 10000- (32,33) \\\\\t\t\n\t\t\t\t  \t\t\t   & \\sout{33} & 100001 & 1-0000 (32,48) \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{48} & 110000 & 00100- (8,9) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{3} & \\sout{13} & 001101 & 001-00 (8,12) \\\\\n\t\t\t\t\t\t\t   & \\sout{14} & 001110 & 100-01 (33,37) \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{37} & 100101 & 001-01 (9,13) \\\\\t\t\n\t\t\t\t\t\t       & \\sout{56} & 111000 & 00110- (12,13) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{2}{*}{4} & \\sout{15} & 001111 & 0011-0 (12,14) \\\\\n\t\t\t\t\t\t\t   & \\sout{39} & 100111 & 11-000 (48,56) \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & 1001-1 (37,39) \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & 0011-1 (13,15) \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & 00111- (14,15) \\\\\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: Size Two Implicants}\n  \\label{ASM:tab:qm_ex_2_size_2_implicants}\n\\end{table}\n\nAll of the Size Two Implicants can now be combined to form Size Four Implicants, as in Table \\ref{ASM:tab:qm_ex_2_size_4_implicants}.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t% \\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccc|c|c} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\head{1's} & \\head{Mntrm} & \\head{Bin} \n\t\t\t\t& \\head{Size 2} & \\head{Size 4} \\\\\n\t\t\t\t\t\t\t  0 & \\sout{0} & 000000 & \\sout{00000- (0,1)}   & -0000- (0,1,32,33) \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{1} & \\sout{1}  & 000001 & \\sout{-000000 (0,32)} & 00-00- (0,1,8,9)\\\\\n\t\t\t\t\t\t\t   & \\sout{8}  & 001000 & \\sout{00-000 (0,8)}   & 001-0- (8,9,12,13)\\\\\n\t\t\t\t\t\t       & \\sout{32} & 100000 & \\sout{-00001 (1,33)}  & 0011-- (12,13,14,15)\\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{4}{*}{2} & \\sout{9}  & 001001 & \\sout{00-001 (1,9)}   & \\\\\n\t\t\t\t\t\t\t   & \\sout{12} & 001100 & \\sout{10000- (32,33)} & \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{33} & 100001 & 1-0000 (32,48)        & \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{48} & 110000 & \\sout{00100- (8,9)}   & \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{3}{*}{3} & \\sout{13} & 001101 & \\sout{001-00 (8,12)}  & \\\\\n\t\t\t\t\t\t\t   & \\sout{14} & 001110 & 100-01 (33,37)        & \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{37} & 100101 & \\sout{001-01 (9,13)}  & \\\\\t\t\n\t\t\t\t\t\t\t   & \\sout{56} & 111000 & \\sout{00110- (12,13)} & \\\\\n\t\t\t\\cline{1-3}\n\t\t\t\\multirow{2}{*}{4} & \\sout{15} & 001111 & \\sout{0011-0 (12,14)} & \\\\\n\t\t\t\t\t\t\t   & \\sout{39} & 100111 & 11-000 (48,56)        & \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & 1001-1 (37,39) \t\t        & \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & \\sout{0011-1 (13,15)}\t    & \\\\\t\t\n\t\t\t\t\t\t\t   &    &        & \\sout{00111- (14,15)} \t    & \\\\\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: Size 4 Implicants}\n  \\label{ASM:tab:qm_ex_2_size_4_implicants}\n\\end{table}\n\nNone of the terms can be combined any further. All of the minterms or implicants that are not struck through are \\emph{Prime Implicants}. In the table above, for example, $ 1-0000 $ is a Prime Implicant. The Prime Implicants are next placed in a table and further processed. \n\n\\subsubsection{Step 2: The Prime Implicant Table}\n\\label{ASM:subsubsec:quine-mccluskey_ex_2_step_2}\n\nA \\emph{Prime Implicant Table} can now be constructed, as in Table \\ref{ASM:tab:qm_ex_2_prime_implicants}. The prime implicants are listed down the left side of the table, the decimal equivalent of the minterms goes across the top, and the Boolean representation of the prime implicants is listed down the right side of the table. \n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccccccccccccccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{0} & \\head{1} & \\head{8} & \\head{9}\n\t\t\t\t& \\head{12} & \\head{13} & \\head{14} & \\head{15}\n\t\t\t\t& \\head{32} & \\head{33} & \\head{37} & \\head{39} \n\t\t\t\t& \\head{48} & \\head{56} & \\\\\n\t\t\t\t%      \t\t\t            0   1   8   9  12  13  14  15  32  33  37  39  48  56\n\t\t\t\t$ 11-000\\;(48,56) $       &   &   &   &   &   &   &   &   &   &   &   &   & X & X & $ ABD'D'F' $ \\\\\n\t\t\t\t$ 00-00-\\;(0,1,8,9) $     & X & X & X & X &   &   &   &   &   &   &   &   &   &   & $ A'B'D'E' $ \\\\\n\t\t\t\t$ 1001-1\\;(37,39) $       &   &   &   &   &   &   &   &   &   &   & X & X &   &   & $ AB'C'DF $ \\\\\n\t\t\t\t$ 1-0000\\;(32,48) $       &   &   &   &   &   &   &   &   & X &   &   &   & X &   & $ AC'D'E'F' $ \\\\\n\t\t\t\t$ 0011--\\;(12,13,14,15) $ &   &   &   &   & X & X & X & X &   &   &   &   &   &   & $ A'B'CD $ \\\\\n\t\t\t\t$ -0000-\\;(0,1,32,33) $   & X & X &   &   &   &   &   &   & X & X &   &   &   &   & $ B'C'D'E' $ \\\\\n\t\t\t\t$ 001-0-\\;(8,9,12,13) $   &   &   & X & X & X & X &   &   &   &   &   &   &   &   & $ A'B'CE' $ \\\\\n\t\t\t\t$ 100-01\\;(33,37) $       &   &   &   &   &   &   &   &   &   & X & X &   &   &   & $ AB'C'E'F $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: Prime Implicants}\n  \\label{ASM:tab:qm_ex_2_prime_implicants}\n\\end{table}\n\nIn the above table, there are four columns that contain only one \\emph{X}: $ 14 $, $ 15 $, $ 39 $, and $ 56 $. The rows that intersect the columns at that mark are \\emph{Essential Prime Inplicants}, and their Boolean Expressions must appear in the final equation. Therefore, the final equation will contain, at a minimum: $ A'B'CD $ (row $ 5 $, covers minterms $ 14 $ and $ 15 $), $ AB'C'DF $ (row $ 3 $, covers minterm $ 39 $), and $ ABD'E'F' $ (row $ 1 $, covers minterm $ 56 $). Since those expressions are in the final equation, the rows that contain those expressions can be removed from the chart in order to make further analysis less confusing. \n\nAlso, because the rows with Essential Prime Implicants are contained in the final equation, other minterms marked by those rows are covered and need no further consideration. For example, minterm $ 48 $ is covered by row one (used for minterm $ 56 $), so column $ 48 $ can be removed from the table. In a similar fashion, columns $ 12 $, $ 13 $, and $ 37 $ are covered by other minterms, so they can be removed from the table. Table \\ref{ASM:tab:qm_ex_2_1st_iteration} shows the next iteration of this process.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccccccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{0} & \\head{1} & \\head{8} & \\head{9}\n\t\t\t\t& \\head{32} & \\head{33} & \\\\\n\t\t\t\t%      \t\t\t            0   1   8   9  32  33 \n\t\t\t\t$ 00-00-\\;(0,1,8,9) $     & X & X & X & X &   &   & $ A'B'D'E' $ \\\\\n\t\t\t\t$ 1-0000\\;(32,48) $       &   &   &   &   & X &   & $ AC'D'E'F' $ \\\\\n\t\t\t\t$ -0000-\\;(0,1,32,33) $   & X & X &   &   & X & X & $ B'C'D'E' $ \\\\\n\t\t\t\t$ 001-0-\\;(8,9,12,13) $   &   &   & X & X &   &   & $ A'B'CE' $ \\\\\n\t\t\t\t$ 100-01\\;(33,37) $       &   &   &   &   &   & X & $ AB'C'E'F $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: 1st Iteration}\n  \\label{ASM:tab:qm_ex_2_1st_iteration}\n\\end{table}\n\nThe circuit designer can select the next term to include in the final equation from any of the five rows still remaining in the chart; however, the first term ($ 00-00- $, or $ A'B'D'E' $) would eliminate four columns, so that would be a logical next choice. When that term is selected for the final equation, then row one, $ 00-00- $, can be removed from the chart; and columns $ 0 $, $ 1 $, $ 8 $, and $ 9 $ can be removed since those minterms are covered. \n\nThe minterms marked for row $ 001-0- (8,9,12,13) $ are also covered, so this row can be removed. Table \\ref{ASM:tab:qm_ex_2_2nd_iteration} shows the next iteration.\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{adjustbox}{max width=\\textwidth}\n\t\t\t\\begin{tabular}{lccc} \n\t\t\t\t\\rowcolor{black!75}\n\t\t\t\t& \\head{32} & \\head{33} & \\\\\n\t\t\t\t%      \t\t\t           32  33 \n\t\t\t\t$ 1-0000\\;(32,48) $       & X &   & $ AC'D'E'F' $ \\\\\n\t\t\t\t$ -0000-\\;(0,1,32,33) $   & X & X & $ B'C'D'E' $ \\\\\n\t\t\t\t$ 100-01\\;(33,37) $       &   & X & $ AB'C'E'F $ \\\\\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t\\end{adjustbox}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Ex 2: 2nd Iteration}\n  \\label{ASM:tab:qm_ex_2_2nd_iteration}\n\\end{table}\n\nFor the next simplification, row $ -0000- $ is selected since that would also cover the minterms that are marked for all remaining rows. Thus, the expression $ B'C'D'E' $ will become part of the final equation. \n\nWhen the analysis is completed, the original equation (\\ref{ASM:eq:qm_ex_2}), which contained $ 14 $ minterms, is simplified into Equation \\ref{ASM:eq:qm_ex_2_solution}, which contains only five terms.\n\n\\begin{align}\n\t\\label{ASM:eq:qm_ex_2_solution}\n\tABD'E'F'+A'B'D'E'+AB'C'DF+A'B'CD+B'C'D'E' = Y \n\\end{align}\n\n\\subsection{Summary}\n\\label{ASM:subsec:quine-mccluskey_summary}\n\nWhile the Quine–McCluskey method is useful for large Boolean expressions containing multiple inputs, it is also tedious and prone to error when done by hand. Also, there are some Boolean expressions (called ``Cyclic'' and ``Semi-Cyclic'' Primes) that do not reduce using this method. Finally, both Karnaugh maps and Quine-McCluskey methods become very complex when more than one output is required of a circuit. Fortunately, many automated tools are available to simplify Boolean expressions using advanced mathematical techniques. \n\n\\subsection{Practice Problems}\n\\label{ASM:subsec:quine-mccluskey_practice_problems}\n\nThe following problems are presented as practice for using the Quine-McClusky method to simplify a Boolean expression. Note: designers can select different Prime Implicants so the simplified expression could vary from what is presented below. \n\n\\subsection{Practice Problems}\n\\label{ASM:subsec:practice_problems_karnaugh_maps}\n\n\\begin{table}[H]\n\t\\sffamily\n\t\\begin{center}\n\t\t\\begin{tabular}{c c p{6cm} }\n\t\t\t\\multirow{2}{*}{\\textbf{1}} \n\t\t\t& Expression & $ \\int(A,B,C,D) = \\sum(0,1,2,5,6,7,9,10,11,14) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ A'B'C'+A'BD+AB'D+CD' $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{2}} \n\t\t\t& Exression & $ \\int(A,B,C,D) = \\sum(0,1,2,3,6,7,8,9,14,15) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ A'C+BC+B'C' $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{3}} \n\t\t\t& Exression & $ \\int(A,B,C,D) = \\sum(1,5,7,8,9,10,11,13,15) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ C'D+AB'+BD $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{3}} \n\t\t\t& Exression & $ \\int(A,B,C,D,E) = \\sum(0,4,8,9,10,11,12,13,14,15,16,20,24,28) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ A'B+D'E' $ \\\\\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Quine-McCluskey Practice Problems}\n  \\label{ASM:tab:quine-mccluskey_practice_problems}\n\\end{table}\n\n%***************************************************************************\n% Section: Automated Tools\n%***************************************************************************\n\\clearpage\\section{Automated Tools}\n\\label{ASM:sec:automated_tools}\n\n\\subsection{Introduction}\n\\label{ASM:subsec:introduction_to_automated_tools}\n\nThere are numerous automated tools available to aid in simplifying complex Boolean equations. Many of the tools are quite expensive and intended for professionals working full time in large companies; but others are inexpensive, or even free of charge, and are more than adequate for student use. This topic introduces one such free tool: \\ac{KARMA}. \n\n\\subsection{KARMA}\n\\label{ASM:subsec:karma}\n\n\\subsubsection{Introduction}\n\\label{ASM:subsubsec:introduction_to_karma}\n\n\\ac{KARMA} is a free Java-based tool designed to help simplify Boolean expressions. Both an online and downloaded version of \\ac{KARMA} is available. The application can be found at: \\url{http://goo.gl/8Lmx5v}. Note: The version of \\ac{KARMA} used for this text is 3.62. A newer version may be available but the instructions presented here use only the base functions and will likely be applicable even in an updated version of the software.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_01}\n\t\\caption{Karma Initial Screen}\n\t\\label{fig:07_01}\n\\end{figure}\n\nThe right side of the screen contains a row of tools available in \\ac{KARMA} and the main part of the screen is a canvas where most of the work is done. The following tools are available:\n\n\n\\begin{itemize}\n\t\\item Logic2Logic. Converts between two different logical representations of data; for example, a Truth Table can be converted to Boolean expressions. \n\t\\item Logic Equivalence. Compares two functions and determines if they are equivalent; for example, a truth table can be compared to a SOP expression to see if they are the same. \n\t\\item Logic Probability. Calculates the probability of any one outcome for a given Boolean expression. \n\t\\item Karnaugh Map. Analyzes a Karnaugh map and returns the Minimized Expression. \n\t\\item KM Teaching Mode. Provides drill and practice with Karnaugh maps; for example, finding adjacent minterms on a 6-variable map. \n\t\\item SOP and POS. Finds the SOP and POS expressions for a given function. \n\t\\item Exclusive-OR. Uses XOR gates to simplify an expression. \n\t\\item Multiplexer-Based. Realizes a function using multiplexers. \n\t\\item Factorization. Factors Boolean expressions. \n\t\\item About. Information about \\ac{KARMA}. \n\\end{itemize}\n\nFor this lesson, only the Karnaugh Map analyzer will be used, and the initial screen for that function is below.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_02}\n\t\\caption{Karma K-Map Analyzer}\n\t\\label{fig:07_02}\n\\end{figure}\n\n\\subsubsection{Data Entry}\n\\label{ASM:subsubsec:karma_data_entry}\n\nWhen using \\ac{KARMA}, the first step is to input some sort of information about the circuit to be analyzed. That information can be entered in several different formats, but a truth table or a Boolean expression would best match this book. \n\nTo enter the initial data, click the \\emph{Load Function} button at the top of the canvas.\n\nBy default, the Load Function screen opens with a blank screen. In the lower left corner of the Load Function window, the Source Format for the input data can be selected. There is a template available for each of the different source formats; and that template can be used to help with data entry. The best way to work with \\ac{KARMA} is to click the ``Templates'' button and then select the data format of interest. Figure \\ref{ASM:fig:karma_expression_one_loaded} shows the ``Expression 1'' template. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_03}\n\t\\caption{Karma Expression One Loaded}\n\t\\label{fig:07_03}\n\\end{figure}\n\nThe designer would replace the ``inputs'' and ``onset'' lines with information for the circuit being simplified. Once the source data are entered into this window, click the \\emph{Load} button at the bottom of the window to load the data into \\ac{KARMA}. \n\n\\subsubsection{Data Source Formats}\n\\label{ASM:subsubsec:karma_data_source_formats}\n\n\\ac{KARMA} works with input data in any of six different formats: Boolean Expression, Truth Table, Integer, Minterms, \\ac{BLIF}, and \\ac{BDD}. \\ac{BLIF} and \\ac{BDD} are programming tools that are beyond the scope of this book and will not be covered. \n\n%TODO: maybe expand the book to include BLIF and BDD.\n\n\\paragraph{Expression}\n\\label{ASM:para:karma_expression}\n\nBoolean expressions can be defined in \\ac{KARMA} using the following format.\n\n{\\small \n\t\\begin{verbatim}\n   #Sample Expression\n   (!x1*!x2*!x4)+(!x1*x2*!x3)+(x1*!x4*!x5)+(x1*x3*x4) \n\t\\end{verbatim}\n}\n\nNotes:\n\n\\begin{itemize}\n\t\\item Any line that starts with a hash mark (``\\#'') is a comment and will be ignored by \\ac{KARMA}. \n\t\\item ``Not'' is indicated by a leading exclamation mark. Thus $ !x1 $ is the same as $ X1' $. \n\t\\item All operations are explicit. In real-number algebra the phrase ``AB'' is understood to be ``A*B.'' However, in \\ac{KARMA}, since variable names can be more than one character long, all operations must be explicitly stated. \\textsf{AND} is indicated by an asterisk and \\textsf{OR} is indicated by a plus sign. \n\t\\item No space is left between operations. \n\\end{itemize}\n\n\\paragraph{Truth Table}\n\\label{ASM:para:karma_truth_table}\n\nA truth table can be defined in \\ac{KARMA} using the following format.\n\n\\begin{verbatim}\n     #Sample Truth Table\n     inputs -> X, Y, Z\n     000: 1\n     001: 1\n     010: 0\n     011: 0\n     100: 0\n     101: 1\n     110: 0\n     111: 1 \n\\end{verbatim}\n\nNotes: \n\n\\begin{itemize}\n\t\\item Any line that starts with a hash mark (``\\#'') is a comment and will be ignored by \\ac{KARMA}. \n\t\\item The various inputs are named before they are used. In the example, there are three inputs: $ X $, $ Y $, and $ Z $. \n\t\\item Each row in the truth table is shown, along with the output expected. So, in the example above, an input of $ 000 $ should yield an output of $ 1 $. \n\t\\item An output of ``-'' is permitted and means ``don't care.'' \n\\end{itemize}\n\n\\paragraph{Integer}\n\\label{ASM:para:karma_integer}\n\nIn \\ac{KARMA}, an integer can be used to define the outputs of the truth table, so it is ``shorthand'' for an entire truth table input. Here is the example of the ``integer'' type input.\n\n\\begin{verbatim}\n     #Sample Integer Input\n     inputs -> A, B, C, D\n     onset -> E81A base 16 \n\\end{verbatim}\n\nNotes: \n\n\\begin{itemize}\n\t\\item Any line that starts with a hash mark (``\\#'') is a comment and will be ignored by \\ac{KARMA}. \n\t\\item Input variables are defined first. In this example, there are four inputs: $ A $, $ B $, $ C $, and $ D $. \n\t\\item The ``onset'' line indicates what combinations of inputs should yield a \\emph{True} on a truth table. In the example, the number $ E81A $ is a hexadecimal number that is written like this in binary: \n\\end{itemize}\n\n\\begin{verbatim}\n     1110 1000 0001 1010\n      E    8    1    A \n\\end{verbatim}\n\nThe least significant bit of the binary number, $ 0 $ in this example, corresponds to the output of the first row in the truth table; thus, it is false. Each bit to the left of the least significant bit corresponds to the next row, counting from $ 0000 $ to $ 1111 $. Here is the truth table generated by the hexadecimal integer $ E81A $: \n\n\\begin{table}[H]\n\t\\sffamily\n\t\\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\t\t\n\t\\begin{center}\n\t\t\\rowcolors{2}{gray!10}{white} % Color every other line a light gray\n\t\t\\begin{tabular}{ccccc} \n\t\t\t\\rowcolor{black!75}\n\t\t\t\\multicolumn{4}{c}{\\head{Inputs}} & \\head{Output} \\\\\n\t\t\tA & B & C & D & Y \\\\\n\t\t\t\\hline\n\t\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t0 & 0 & 0 & 1 & 1 \\\\\n\t\t\t0 & 0 & 1 & 0 & 0 \\\\\n\t\t\t0 & 0 & 1 & 1 & 1 \\\\\n\t\t\t0 & 1 & 0 & 0 & 1 \\\\\n\t\t\t0 & 1 & 0 & 1 & 0 \\\\\n\t\t\t0 & 1 & 1 & 0 & 0 \\\\\n\t\t\t0 & 1 & 1 & 1 & 0 \\\\\n\t\t\t1 & 0 & 0 & 0 & 0 \\\\\n\t\t\t1 & 0 & 0 & 1 & 0 \\\\\n\t\t\t1 & 0 & 1 & 0 & 0 \\\\\n\t\t\t1 & 0 & 1 & 1 & 1 \\\\\n\t\t\t1 & 1 & 0 & 0 & 0 \\\\\n\t\t\t1 & 1 & 0 & 1 & 1 \\\\\n\t\t\t1 & 1 & 1 & 0 & 1 \\\\\n\t\t\t1 & 1 & 1 & 1 & 1 \\\\\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Truth Table for KARMA}\n  \\label{03:tab:truth_table_for_karma}\n\\end{table}\n\nThe ``Output'' column contains the binary integer $ 1110\\;1000\\;0001\\;1010 $ (or $ E81A_{16} $) from bottom to top. \n\n\\paragraph{Terms}\n\\label{ASM:para:karma_terms}\n\nData input can be defined by using the minterms for the Boolean expression. Following is an example minterm input.\n\n\\begin{verbatim}\n     #Sample Minterms\n     inputs -> A, B, C, D\n     onset -> 0, 1, 2, 3, 5, 10 \n\\end{verbatim}\n\n\\begin{itemize}\n\t\\item Any line that starts with a hash mark (``\\#'') is a comment and will be ignored by \\ac{KARMA}. \n\t\\item The inputs, $ A $, $ B $, $ C $, and $ D $, are defined first. \n\t\\item The ``onset'' line indicates the minterm numbers that yield a \\emph{True} output. \n\t\\item This is similar to a \\ac{SOP} expression, and the digits in that expression could be directly entered on the onset line. For example, the onset line above would have been generated from the Sigma expression in Equation \\ref{ASM:eq:KARMA Input}.\n\\end{itemize}\n\n\\begin{align}\n\t\\label{ASM:eq:KARMA Input}\n\t\\int(A,B,C,D) &= \\sum(0,1,2,3,5,10)\n\\end{align}\n\n\\subsubsection{Truth Table and K-Map Input}\n\\label{ASM:subsubsec:karma_truth_table_and_kmap_input}\n\nWhile \\ac{KARMA} will accept a number of different input methods, as described above, one of the easiest to use is the Truth Table, and the related Karnaugh Map, and these are displayed by default when the Karnaugh Map function is selected. The value of any of the cells in the \\emph{Out} column in the Truth Table, or cells in the Karnaugh Map, can be cycled through $ 0 $, $ 1 $, and ``don't care'' (indicated by a dash) on each click of the mouse in the cell. The Truth Table and Karnaugh Map are synchronized as cells are clicked. The number of input variables can be adjusted by changing the \\emph{Var} setting at the top of the screen. Also, the placement of those variables on the Karnaugh Map can be adjusted as desired. \n\n\\subsubsection{Solution}\n\\label{ASM:subsubsec:karma_truth_table_and_kmap_input}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_04}\n\t\\caption{Karma Solution}\n\t\\label{fig:07_04}\n\\end{figure}\n\nTo simplify the Karnaugh Map, click the \\emph{Minimize} button. A number of windows will pop up (illustrated in Figure \\ref{ASM:fig:karma_solution}), each showing the circuit simplification in a slightly different way. Note: the following Boolean expression was entered to generate the illustrated simplification: $ A'C + A'B + AB'C' + B'C'D' $. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_05}\n\t\\caption{Karma Minimized Solution}\n\t\\label{fig:07_05}\n\\end{figure}\n\n\\marginpar{KARMA includes parenthesis for clarity, but the groups are obvious when the expression is written in normal Boolean form.}\n\nIn this solution, a \\emph{NOT} term is identified by a leading exclamation point; thus, the minimized expression is: $ A'D' + A'B + AB'C' + A'C $. \n\n\\paragraph{BDDeiro}\n\\label{ASM:para:karma_bddeiro}\n\nThe BDDeiro window is a visualization of a \\ac{BDD}, which graphically represents the solution to a logic network. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_06}\n\t\\caption{Karma BDDeiro Map}\n\t\\label{fig:07_06}\n\\end{figure}\n\nIn a \\ac{BDD}, each circle represents an input and the squares at the bottom of the diagram represent the two possible outputs: \\emph{False} and \\emph{True}. The lines are paths from the inputs to either a \\emph{False} or \\emph{True} output; thus, a truth table can be viewed graphically. A \\ac{BDD} is useful because it provides a compact, visual representation of a Boolean expression, and for any given Boolean expression there is one, and only one, \\ac{BDD} representing it. One disadvantage to using a \\ac{BDD} is its size, there are potentially two nodes for each input (except the first), and that can lead to a very large diagram.\n\nFigure \\ref{ASM:fig:karma_bddeiro_map} is actually a ``Reduced Order'' \\ac{BDD} and a number of nodes and paths have been consolidated to make the diagram as simple as possible. The top node represents the start of the decision diagram: input $ a $. If that input is \\emph{False}, then follow the dotted line down to node $ d $. (Note: the lines are color-coded to aid in their use; \\emph{False} lines are blue and \\emph{True} lines are red.) If node $ d $ is false, then that leads directly to output \\emph{True}. Thus $ A'D' $ gives a \\emph{True} output, and that is one of the minimized solutions. To follow one other path, if $ a $ is \\emph{True} (follow the solid line down and right), $ b $ is \\emph{False}, $ c $ is \\emph{False}, the output is \\emph{True}. Thus, $ AB'C' $ is \\emph{True}. In a similar way, all four \\emph{True} outputs, and three false outputs, can be traced from the top to bottom of the diagram. \n\n\\paragraph{Quine-McCluskey}\n\\label{ASM:para:quine-mccluskey}\n\n\\ac{KARMA} includes the complete Quine-McCluskey solution data. Several tables display the various Implicants and show how they are derived. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_07}\n\t\\caption{Karma Quine-McCluskey Solution}\n\t\\label{fig:07_07}\n\\end{figure}\n\n\\ac{KARMA} also displays the Covering Table for a Quine-McCluskey solution.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\maxwidth{.95\\linewidth}]{gfx/07_08}\n\t\\caption{Karma Quine-McCluskey Covering Table}\n\t\\label{fig:07_08}\n\\end{figure}\n\nEach of the minterms (down the left column) can be turned on or off by clicking on it. The smaller blue dots in the table indicate prime implicants and the larger red dots (if any) indicate essential prime implicants. Because this table is interactive, various different solutions can be attempted by clicking some of the colored dots to achieve the best possible simplification. \n\n\\subsubsection{Practice Problems}\n\\label{ASM:subsubsec:karma_practice_problems}\n\nThe following problems are presented as practice for using \\ac{KARMA} to simplify a Boolean expression. Note: designers can select different Prime Implicants so the simplified expression could vary from what is presented below.  \n\n\\begin{table}[H]\n\t\\sffamily\n\t\\begin{center}\n\t\t\\begin{tabular}{c c p{6cm} }\n\t\t\t\\multirow{2}{*}{\\textbf{1}} \n\t\t\t& Expression & $ \\int(A,B,C,D) = \\sum(5,6,7,9,10,11,13,14) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ BC'D+A'BC+ACD'+AB'D $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{2}} \n\t\t\t& Exression & $ A'BC'D+A'BCD'+A'BCD+AB'C'D+AB'CD'+AB'CD+ABC'D+ABCD' $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ BC'D+A'BC+ACD'+AB'D $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{3}} \n\t\t\t& Exression & A 4-variable Karnaugh Map where cells 5, 6, 7, 9, and 10 are True and 13, 14 are ``Don't Care'' \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ BC'D+AC'D+A'BC+ACD' $ \\\\\n\t\t\t\\hline\n\t\t\t\\multirow{2}{*}{\\textbf{3}} \n\t\t\t& Exression & $ \\int(A,B,C,D,E) = \\sum(0, 3, 4, 12, 13, 14, 15, 24, 25, 28, 29, 30) $ \\\\\n\t\t\t& \\cellcolor{gray!10} Simplified \n\t\t\t& \\cellcolor{gray!10} $ ABD'+A'B'C'DE+BCD'+A'BC+A'B'D'E' $ \\\\\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{KARMA Practice Problems}\n  \\label{ASM:tab:karma_practice_problems}\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", "meta": {"hexsha": "a0b2c255cb9623105f49853c2b13e86ae78677b1", "size": 44500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/07_Adv_Simp_Methods.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/07_Adv_Simp_Methods.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/07_Adv_Simp_Methods.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": 48.7938596491, "max_line_length": 1340, "alphanum_fraction": 0.6260898876, "num_tokens": 15824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.634831966733071}}
{"text": "\\section*{Introduction}\n\nIn this part, we present a development  for the \\coq{} proof assistant, after the work of Kirby and Paris. This formalization contains the following main parts:\n\n\\begin{itemize}\n\\item Representation in \\coq{} of hydras and hydra battles\n\\item A proof that every battle is finite and won by Hercules. This proof is based on a \\emph{variant} which maps any hydra to an ordinal strictly less than $\\epsilon_0$ and is strictly decreasing along any battle.\n\n\\item Using a combinatorial toolkit designed by J.~Ketonen and R.~Solovay~\\cite{KS81}, we prove that, for any ordinal $\\mu<\\epsilon_0$, there exists no such variant mapping any hydra to an ordinal stricly less than $\\mu$. Thus, the complexity of $\\epsilon_0$ is really needed in the previous proof.\n\n\\item We prove a relation between the length of a ``classic''  class of  battles \\footnote{This class is also called \\emph{standard} in this document (text and proofs). The \\emph{replication factor} of the hydra is exactly $i$ at the $i$-th round of the battle (see Sect~\\vref{sect:replication-def}).}\nand the Wainer-Hardy hierarchy of ``rapidly growing functions'' $H_\\alpha$~\\cite{Wainer1970}. The considered class of battles, which we call \\emph{standard}  is the most considered one in the scientific  litterature(including popularization).\n\\end{itemize}\n\n\nSimply put, this document tries to combines the scientific interest of two articles~\\cite{KP82, KS81} and a book~\\cite{schutte} with the playful activity of truly proving theorems.\nWe hope  that such a work, besides exploring a nice piece of discrete maths, \nwill show how \\coq{} and its standard library are well fitted to help us to understand some non-trivial mathematical developments, and also to experiment the constructive parts of  the proof through functional programming.\n\n We also hope to provide a little clarification on infinity (both potential and actual) through the notions of function, computation, limit,\n types and proofs.\n\n\n\n%\\section{Remarks}\n\n\\subsection*{Difference from Kirby and Paris's Work}\nIn~\\cite{KP82}, Kirby and Paris showed  that there is no proof of termination of all hydra battles in Peano Arithmetic (PA).\nSince we are used to writing proofs in higher order logic, the restriction to PA was quite unnatural for us. So we chosed to prove another statement without any reference to PA, by considering a class of proofs indexed by ordinal numbers upto $\\epsilon_0$.\n\n\\subsection*{State of the Development}\nThe \\coq{} scripts herein are in constant development since our contribution~\\cite{CantorContrib} on  notations for the ordinals $\\epsilon_0$ and $\\Gamma_0$.\nWe added new material : axiomatic definition of countable ordinals after Schütte~\\cite{schutte}, combinatorial aspects of $\\epsilon_0$, after Ketonen and Solovay~\\cite{KS81} and Kirby and Paris~\\cite{KP82}, recent \\coq{} technology: type classes, equations, etc.\n\nWe are now working in order to make clumsy proofs more readable, simplify definitions, and ``factorize'' proofs as much as possible. \nMany possible improvements are suggested as ``todo''s or ``projects'' in this text.\n\n\n\\section*{Future Work (projects)}\n\\index{Projects}\n\nThis document and the proof scripts are far from being complete.\n\nFirst, there must be a lot of typos to correct, references and index items to add. Many proofs are too complex and should be simplified, etc.\n\nThe following extensions are planned, but help is needed:\n\n\\begin{itemize}\n\\item Semi automatic tactics for proving inequalities $\\alpha < \\beta$, even when $\\alpha$ and $\\beta$ are not closed terms.\n\\item Extension to $\\Gamma_0$ (in Veblen normal form)\n\\item More lemmas about hierarchies of rapidly growing functions, and their relationship \n    with primitive recursive functions and provability in Peano arithmetic \n(following~\\cite{KS81, KP82}).\n\\item From \\coq's point of view, this development could be used as an illustration of the evolution of the software, every time new libraries and sets of tactics could help to simplify the proofs.\n\\end{itemize}\n\n\\subsection*{Main References}\n\nIn our development, we adapt the definitions and prove many theorems which\nwe found in the following articles. \n\\begin{itemize}\n\\item ``Accessible independence results for Peano arithmetic''  by Laurie Kirby and Jeff Paris~\\cite{KP82}\n\\item ''Rapidly growing Ramsey Functions'' by Jussi Ketonen and Robert Solovay~\\cite{KS81}\n\\item ``The Termite and the Tower'', by Will Sladek~\\cite{Sladek07thetermite}\n\\item Chapter V of ``Proof Theory'' by Kurt Schütte~\\cite{schutte}\n\\end{itemize}\n\n\n\n\n\n\n\\chapter{Hydras and Hydra Games}\n\n\\label{sec:orgheadline91}\n\n\n\n\n\nThis chapter is dedicated to the representation of hydras and rules of the hydra game in \\coq's specification language:~\\gallina. \n\nTechnically, a \\emph{hydra} is just a finite ordered tree, each node of which \nhas any number of sons. Note that, contrary to the computer science tradition, we will show the hydras \nwith the heads up and the foot (i.e., the root of the tree) down.\nFig.~\\ref{fig:Hy} represents such  a hydra, which will be referred to as \\texttt{Hy} in our examples (please look at the \nmodule~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}). \n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.6]\n\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4) {$\\bullet$};\n\\node (N3) at (2,6) {$\\bullet$};\n\\node (H0) at (0,2) {$\\Smiley[2][vertfluo]$};\n\\node (H1) at (0,8) {$\\Smiley[2][vertfluo]$};\n\\node (H2) at (4,8) {$\\Smiley[2][vertfluo]$};\n\\node (H4) at (4,2) {$\\Smiley[2][vertfluo]$};\n\\node (H5) at (4,4) {$\\Smiley[2][vertfluo]$};\n\\draw (foot) -- (N1)[very thick] ;\n\\draw (N1) -- (N2);\n\\draw (N2) -- (N3);\n\\draw (N3) to [bend left= 10]  (H1) ;\n\\draw (N3) to [bend right= 16] (H2);\n\\draw (foot) to [bend left= 10]  (H0) ;\n\\draw (foot) to [bend right = 10] (H4) ;\n\\draw (N1) to [bend right= 16] (H5);\n\\end{tikzpicture}\n\\caption{The hydra Hy \\label{fig:Hy}}\n\\end{figure}\n\n\n\nWe use a specific vocabulary for talking about hydras. Table~\\ref{tab:hyd2tree} shows the correspondance between our terminology and the usual vocabulary for trees in computer science.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tabular}{ll}\nHydras & Finite rooted trees\\\\\n\\hline\nfoot & root\\\\\nhead & leaf\\\\\nnode & node\\\\\nsegment  & (directed) edge \\\\\nsub-hydra & subtree\\\\\ndaughter & immediate subtree\\\\\n\\end{tabular}\n  \\caption{Translation from hydras to trees}\n  \\label{tab:hyd2tree}\n\\end{figure}\n\n\nThe hydra \\texttt{Hy} has a \\emph{foot} (below), five \\emph{heads}, and eight \\emph{segments}. \nWe leave it to the reader to define various parameters such as the height, the size, the highest arity (number of sons of a node) of a hydra. In our example, these parameters have the respective values : $4$, $9$ and $3$.\n\n\n\n\n\\subsection{The Rules of the Game}\n\n\\label{sec:orgheadline44}\n\\label{sect:replication-def}\n\nA \\emph{hydra battle} is a fight between Hercules and the Hydra. \nMore formally, a  battle is a sequence of \\emph{rounds}.\nAt each round:\n\\begin{itemize}\n\\item If the hydra is composed of just one head, the battle is finished\nand  Hercules is the winner.\n\\item Otherwise, Hercules chops off \\emph{one} head of the hydra,\n\n\\begin{itemize}\n\\item If the head is at distance 1 from the foot, the head is just lost by the hydra, with no more reaction.\n\\item Otherwise, let us denote by \\(r\\) the node that was at distance \\(2\\) from \nthe removed head in the direction of the foot,  and consider the  sub-hydra \\(h'\\) of \\(h\\), whose  root is \\(r\\) \\footnote{$h'$ will be called ``the wounded part of the hydra'' in the subsequent text. In Figures~\\vref{fig:Hy2} and ~\\vref{fig:Hy4}, this sub-hydra  is displayed in red.}. Let $n$ be some natural number.\nThen $h'$ is replaced by  $n+1$ of copies of \\(h'\\) which share the same root $r$.\n The \\emph{replication factor} $n$ may be different (and generally is)   at each round of the fight.\nIt may be chosen by the hydra, according to its strategy, or imposed by some \nparticular rule. In many presentations of hydra battles, this number is increased by $1$ at each round. In the following presentation, we will also consider battles where the hydra is free to choose its ~replication factor at each round of the battle\\footnote{Let us recall that, if the chopped-off head was at distance 1 from the foot, the replication factor is meaningless.}.\n\\end{itemize}\n\\end{itemize}\n\n\n\nNote that the description given in~\\cite{KP82} of the replication process in hydra battles is also  semi-formal. \n\n\\label{original-rules}\n\n\\begin{quote}\n  ``From the node that used to be attached to the head which was just chopped off, traverse one \nsegment towards the root until the next node is reached. From this node sprout $n$ replicas of \nthat part of the hydra (after decapitation) which is ``above'' the segment just traversed, i.e., those \nnodes and segments from which, in order to reach the root, this segment would have to be \ntraversed. If the head just chopped off had the root of its nodes, no new head is grown. ''\n\\end{quote}\n\nMoreover, we note that this description is in \\emph{imperative} terms. In order to build a formal  study of the properties of hydra battles, we prefer to use a mathematical vocabulary, i.e., graphs, relations, functions, etc.\nThus, the replication process will be represented as a binary relation on a data type \\texttt{Hydra},\nlinking the state of the hydra \\emph{before} and \\emph{after} the transformation.\nA battle will thus be represented as a sequence of terms of type \\texttt{Hydra}, respecting the rules of the game.\n\n\n\n\n\n\\subsection{Example}\nLet us start a battle between Hercules and the hydra \\texttt{Hy} of Fig.~\\ref{fig:Hy}.\n\nAt the first round, Hercules choses to chop off the rightmost head of \\texttt{Hy}.\nSince this head is near the floor, the hydra loses this head. Let us call \n \\texttt{Hy'} the resulting state of the hydra, represented in Fig.~\\vref{fig:Hy-prime}.\n\nNext, assume Hercules choses to chop off one of the two highest heads of \\texttt{Hy'}, for instance the rightmost one. Fig.~\\vref{fig:Hy2} represents the rotten neck in dashed lines, and the part that will be replicated in red. Assume also that the hydra decides to add 4 copies of the red part\\footnote{In other words, the replication factor at this round is equal to $4$.}. We obtain a new state \\texttt{Hy''} depicted in Fig.~\\ref{fig:Hy3}.\n\n\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.6]\n\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4) {$\\bullet$};\n\\node (N3) at (2,6) {$\\bullet$};\n\\node (H0) at (0,2) {$\\Smiley[2][vertfluo]$};\n\\node (H1) at (0,8) {$\\Smiley[2][vertfluo]$};\n\\node (H2) at (4,8) {$\\Smiley[2][vertfluo]$};\n\\node (H5) at (4,4) {$\\Smiley[2][vertfluo]$};\n%\\node (H4) at (6,0) {$\\Xey[2][lightgray]$};\n\\draw (foot) -- (N1)[very thick] ;\n\\draw (N1) -- (N2);\n\\draw (N2) -- (N3) ;\n\\draw (N3) to [bend left= 10]  (H1) ;\n\\draw (N3) to [bend right= 16] (H2);\n\\draw (foot) to [bend left= 10]  (H0) ;\n\\draw (N1) to [bend right= 16] (H5);\n\\end{tikzpicture}\n\n\\caption{Hy': the state  of Hy after one round \\label{fig:Hy-prime}}\n\\end{figure}\n\n\n\\begin{figure}[hp]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4)  {{\\color{lightred}$\\bullet$}};\n\\node (N3) at (2,6) {{\\color{lightred}$\\bullet$}};\n\\node (H0) at (0,2) {$\\Smiley[2][vertfluo]$};\n\\node (H1) at (0,8) {$\\Sey[2][lightred]$};\n%\\node (H2) at (5,0) {$\\Xey[2][lightgray]$};\n\\node (H5) at (4,4) {$\\Smiley[2][vertfluo]$};\n\\node (ex) at (5,8) {};\n\\draw (foot) -- (N1)[very thick] ;\n\\draw (N1) -- (N2);\n\\draw  (N2) -- (N3)[draw=lightred];\n\\draw (N3) to   [bend left= 10](H1) [draw=lightred];\n\\draw [dashed] (N3) to [bend left= 10](ex);\n\\draw (foot) to [bend left= 10]  (H0) ;\n\\draw (N1) to [bend right= 16] (H5);\n\\end{tikzpicture}\n\\caption{A second beheading}\n\\label{fig:Hy2}\n\\end{figure}\n\n\\begin{figure}[hp]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.6]\n\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4) {$\\bullet$};\n\\node (N3) at (2,6) {{\\color{lightred}$\\bullet$}};\n\\node (H1) at (0,8) {$\\Smiley[2][vertfluo]$};\n\\node (H11) at (2,8) {$\\Smiley[2][vertfluo]$};\n\\node (H12) at (4,8) {$\\Smiley[2][vertfluo]$};\n\\node (H13) at (6,8) {$\\Smiley[2][vertfluo]$};\n\\node (H14) at (8,8) {$\\Smiley[2][vertfluo]$};\n\n\\node (N3) at (1,6) {$\\bullet$};\n\\node (N31) at (2,6) {$\\bullet$};\n\\node (N32) at (3,6) {$\\bullet$};\n\\node (N33) at (4,6) {$\\bullet$};\n\\node (N34) at (5,6) {$\\bullet$};\n\n\\node (H0) at (0,2) {$\\Smiley[2][vertfluo]$};\n\\node (H5) at (4,4) {$\\Smiley[2][vertfluo]$};\n\\draw (foot) -- (N1)[very thick] ;\n\\draw (N1) -- (N2);\n\\draw (N2) -- (N3);\n\\draw (N2) -- (N31);\n\\draw (N2) -- (N32);\n\\draw (N2) -- (N33);\n\\draw (N2) -- (N34);\n\\draw (N3) to   [bend left= 10](H1) ;\n\\draw (N31) to   [bend left= 10](H11) ;\n\\draw (N32) to   [bend left= 10](H12) ;\n\\draw (N33) to   [bend left= 10](H13) ;\n\\draw (N34) to   [bend left= 10](H14) ;\n\\draw (foot) to [bend left= 10]  (H0) ;\n\\draw (N1) to [bend left= 10]  (H5) ;\n\\end{tikzpicture}\n\\caption{Hy'', the state of Hy after two rounds \\label{fig:Hy3}}\n\\end{figure}\n\nFigs.~\\ref{fig:Hy4} and~\\vref{fig:Hy5} represent a possible third round of the battle, with a replication factor equal to $2$. Let us call \\texttt{Hy'''} the state of the hydra after that third round.\n\n\\begin{figure}[hp]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.6]\n\n\\node (foot) at (2,0)  {{\\color{lightred}$\\bullet$}};\n\\node (N1) at (2,2) {{\\color{lightred}$\\bullet$}};\n\\node (N2) at (2,4) {{\\color{lightred}$\\bullet$}};\n\\node (N3) at (2,6) {{\\color{lightred}$\\bullet$}};\n\\node (exN4) at (4,4) {};\n\\node (H1) at (0,8) {$\\Sey[2][lightred]$};\n\\node (H11) at (2,8) {$\\Sey[2][lightred]$};\n\\node (H12) at (4,8) {$\\Sey[2][lightred]$};\n\\node (H13) at (6,8) {$\\Sey[2][lightred]$};\n\\node (H14) at (8,8) {$\\Sey[2][lightred]$};\n\n\\node (N3) at (1,6) {{\\color{lightred}$\\bullet$}};\n\\node (N31) at (2,6) {{\\color{lightred}$\\bullet$}};\n\\node (N32) at (3,6) {{\\color{lightred}$\\bullet$}};\n\\node (N33) at (4,6) {{\\color{lightred}$\\bullet$}};\n\\node (N34) at (5,6) {{\\color{lightred}$\\bullet$}};\n\n\\node (H0) at (0,2) {$\\Smiley[2][vertfluo]$};\n%\\node (H5) at (4,0) {$\\Xey[2][lightgray]$};\n\\draw (foot) -- (N1)[very thick,draw=lightred] ;\n\\draw (N1) -- (N2)[draw=lightred];\n\\draw (N2) -- (N3)[draw=lightred];\n\\draw (N2) -- (N31)[draw=lightred];\n\\draw (N2) -- (N32)[draw=lightred];\n\\draw (N2) -- (N33)[draw=lightred];\n\\draw (N2) -- (N34)[draw=lightred];\n\\draw (N3) to   [bend left= 10](H1) [draw=lightred];\n\\draw (N31) to   [bend left= 10](H11) [draw=lightred];\n\\draw (N32) to   [bend left= 10](H12) [draw=lightred];\n\\draw (N33) to   [bend left= 10](H13) [draw=lightred];\n\\draw (N34) to   [bend left= 10](H14) [draw=lightred];\n\\draw (foot) to [bend left= 10]  (H0) ;\n\\draw [dashed] (N1) to  [bend left= 10](exN4);\n\\end{tikzpicture}\n\\caption{A third beheading (wounded part in red) \\label{fig:Hy4}}\n\\end{figure}\n\n\\begin{figure}[hp]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.4]\n\n\\node (foot) at (10,0) {$\\bullet$};\n\n\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4) {$\\bullet$};\n\\node (N3) at (2,6) {{\\color{lightred}$\\bullet$}};\n\\node (H1) at (0,8) {$\\Smiley[1][vertfluo]$};\n\\node (H11) at (2,8) {$\\Smiley[1][vertfluo]$};\n\\node (H12) at (4,8) {$\\Smiley[1][vertfluo]$};\n\\node (H13) at (6,8) {$\\Smiley[1][vertfluo]$};\n\\node (H14) at (8,8) {$\\Smiley[1][vertfluo]$};\n\n\\node (N3) at (1,6) {$\\bullet$};\n\\node (N31) at (2,6) {$\\bullet$};\n\\node (N32) at (3,6) {$\\bullet$};\n\\node (N33) at (4,6) {$\\bullet$};\n\\node (N34) at (5,6) {$\\bullet$};\n\n\\node (H0) at (-3,3) {$\\Smiley[1][vertfluo]$};\n\n\\draw (foot) to [bend left=10] (N1)[very thick] ;\n\\draw (N1) -- (N2);\n\\draw (N2) -- (N3);\n\\draw (N2) -- (N31);\n\\draw (N2) -- (N32);\n\\draw (N2) -- (N33);\n\\draw (N2) -- (N34);\n\\draw (N3) to   [bend left= 10](H1) ;\n\\draw (N31) to   [bend left= 10](H11) ;\n\\draw (N32) to   [bend left= 10](H12) ;\n\\draw (N33) to   [bend left= 10](H13) ;\n\\draw (N34) to   [bend left= 10](H14) ;\n\\draw (foot) to [bend left = 15]  (H0) ;\n\n\n% second copy \n\\node (N01) at (12,2) {$\\bullet$};\n\\node (N02) at (12,4) {$\\bullet$};\n\\node (N03) at (12,6) {{\\color{lightred}$\\bullet$}};\n\\node (H001) at (10,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0011) at (12,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0012) at (14,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0013) at (16,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0014) at (18,8) {$\\Smiley[1][vertfluo]$};\n\n\\node (N03) at (11,6) {$\\bullet$};\n\\node (N031) at (12,6) {$\\bullet$};\n\\node (N032) at (13,6) {$\\bullet$};\n\\node (N033) at (14,6) {$\\bullet$};\n\\node (N034) at (15,6) {$\\bullet$};\n\n\\draw (foot) -- (N01)[very thick] ;\n\\draw (N01) -- (N02);\n\\draw (N02) -- (N03);\n\\draw (N02) -- (N031);\n\\draw (N02) -- (N032);\n\\draw (N02) -- (N033);\n\\draw (N02) -- (N034);\n\\draw (N03) to   [bend left= 10](H001) ;\n\\draw (N031) to   [bend left= 10](H0011) ;\n\\draw (N032) to   [bend left= 10](H0012) ;\n\\draw (N033) to   [bend left= 10](H0013) ;\n\\draw (N034) to   [bend left= 10](H0014) ;\n\n% third copy \n\\node (N001) at (22,2) {$\\bullet$};\n\\node (N002) at (22,4) {$\\bullet$};\n\\node (N003) at (22,6) {{\\color{lightred}$\\bullet$}};\n\\node (H001) at (20,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0011) at (22,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0012) at (24,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0013) at (26,8) {$\\Smiley[1][vertfluo]$};\n\\node (H0014) at (28,8) {$\\Smiley[1][vertfluo]$};\n\n\\node (N003) at (21,6) {$\\bullet$};\n\\node (N0031) at (22,6) {$\\bullet$};\n\\node (N0032) at (23,6) {$\\bullet$};\n\\node (N0033) at (24,6) {$\\bullet$};\n\\node (N0034) at (25,6) {$\\bullet$};\n\n\\draw (foot) -- (N001)[very thick] ;\n\\draw (N001) -- (N002);\n\\draw (N002) -- (N003);\n\\draw (N002) -- (N0031);\n\\draw (N002) -- (N0032);\n\\draw (N002) -- (N0033);\n\\draw (N002) -- (N0034);\n\\draw (N003) to   [bend left= 10](H001) ;\n\\draw (N0031) to   [bend left= 10](H0011) ;\n\\draw (N0032) to   [bend left= 10](H0012) ;\n\\draw (N0033) to   [bend left= 10](H0013) ;\n\\draw (N0034) to   [bend left= 10](H0014) ;\n\\end{tikzpicture}\n\\caption{The configuration Hy''' of Hy \\label{fig:Hy5}}\n\\end{figure}\n\\FloatBarrier\n\nWe leave it to the reader  to guess the following  rounds of the battle \\dots\n % Please keep in mind that, in this \n% the hydra is free to chose any number of replications at each time, whereas\n% Hercules chops only one head per round.\n\n% Let us precise that, in this game, Hercules wins if the hydra is eventually reduced \n% to a single head. \n% We know from~\\cite{KP82} that, whichever the initial configuration of the\n% hydra, and the strategies of both players, Hercules eventually wins. The \n% aforementionned paper shows also that there do not exist any \\emph{simple} proof of this result.\n\n\n\\section{Hydras and their Representation in \\emph{Coq}}\n\\label{sec:orgheadline48}\n\n\nIn order to describe trees where each node can have an arbitrary (but finite) number of sons, it usual to define a type where each node carries a \\emph{forest}, \\emph{i.e} a list of trees\n(see for instance Chapter 14, pages 400-406 of \\cite{BC04}).\n\nFor this purpose, we define two mutual \\emph{ad-hoc}  inductive types, where \\texttt{Hydra} is the main type, and \\texttt{Hydrae} is a helper for describing finite sequences of hydra.\n\\label{types:Hydra}\n\\label{types:Hydrae}\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#Hydra}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nInductive Hydra : Set :=\n| node :  Hydrae -> Hydra\nwith Hydrae : Set :=\n| hnil : Hydrae\n| hcons : Hydra -> Hydrae -> Hydrae.\n\\end{Coqsrc}\n\n%\\index{To do}\n\\index{Projects}\n\n\\begin{project}\nLook for an existing library on trees with nodes of arbitrary arity, in order to replace  this ad-hoc type with something more generic.\n\\end{project}\n\n\n\\index{Projects}\n\n\\begin{project}\n\n Another very similar representation could use the \\texttt{list} type family instead of the specific \ntype \\texttt{Hydrae}:\n\n\n\\begin{Coqalt}\nModule Alt.\n\nInductive Hydra: Set :=\n  hnode (daughters : list Hydra).\n\nEnd Alt.\n\\end{Coqalt}\n\nUsing this representation, re-define all the constructions of this chapter.\nYou will probably have to use patterns described for instance in~\\cite{BC04} or the archives of the Coq-club~\\cite{Coq}.\n\n  \n\\end{project}\n\n\n\\index{Projects}\n\n\\begin{project}\nThe type \\texttt{Hydra} above describes hydras as \\emph{plane trees}, i.e., as drawn on a sheet of paper or computer screen. Thus, hydras are \\emph{oriented},\nand it is appropriate to consider a \\emph{leftmost} or \\emph{rightmost} head of\nthe beast. It could be interesting to consider another representation, in which\nevery non-leaf node has a \\emph{multi-set} -- not an ordered list -- of daughters.\n\\end{project}\n\n\\subsubsection{Abbreviations}\n\nWe provide several notations for hydra patterns  which occur often in our developments. \n\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#head}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\n(** heads *)\nNotation head := (node hnil).\n \n(** nodes  with 1, 2 or 3 daughters *)\nNotation hyd1 h := (node (hcons h hnil)).\nNotation hyd2 h h' := (node (hcons h (hcons h' hnil))).\nNotation hyd3 h h' h'' := \n                   (node (hcons h (hcons h' (hcons h'' hnil)))).\n\\end{Coqsrc}\n\n\nFor instance, the hydra \\texttt{Hy}  of Figure~\\vref{fig:Hy} is defined in \\emph{Gallina} as follows:\n\n\\vspace{4mm}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html\\#Hy}{Hydra.Hydra\\_Examples}}\n\n\\begin{Coqsrc}\nExample Hy := hyd3 head\n                   (hyd2\n                      (hyd1 \n                         (hyd2 head head))\n                      head) \n                   head.\n\\end{Coqsrc}\n\n\n\nHydras quite frequently contain  multiple  copies of the same pattern. The following functions\nwill help us to describe and reason about replications in hydra battles.\n\n\\vspace{4pt}\n\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#hcons_mult}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nFixpoint hcons_mult (h:Hydra)(n:nat)(s:Hydrae):Hydrae :=\n  match n with \n  | O => s\n  | S p => hcons h (hcons_mult h p s)\n  end.\n\n(** hydra with n copies of the same daughter *)\n\nDefinition hyd_mult h n :=\n  node (hcons_mult h n hnil).\n\\end{Coqsrc}\n\n\\vspace{4mm}\n\n\n\nFor instance, the hydra $Hy''$ of Fig~\\vref{fig:Hy3}  can be defined in \\coq{} as follows:\n\n\\vspace{4pt}\n\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}}\n\n\\begin{Coqsrc}\nExample Hy'' := \n     hyd2 head\n          (hyd2 (hyd_mult (hyd1 head) 5)\n                head).\n\\end{Coqsrc}\n\n\n\n\n\\subsubsection{Recursive Functions on type \\texttt{Hydra}}\n\\label{sec:orgheadline41}\n\\label{sec:hsize-def}\n\n\n\n\nWhen defining a recursive function over the type \\texttt{Hydra}, one has to consider the three constructors \n\\texttt{node}, \\texttt{hnil} and \\texttt{hcons} of the mutually inductive types \\texttt{Hydra} and \\texttt{Hydrae}. \nLet us define for instance the function which  computes the number of nodes of any hydra:\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html}{Hydra.Hydra\\_Definitions}}\n\n\n\\begin{Coqsrc}\nFixpoint hsize (h:Hydra) : nat :=\n  match h with node l => S (lhsize l)\n  end\nwith lhsize l : nat :=\n  match l with hnil => 0\n            | hcons h hs => hsize h + lhsize hs \n  end.\n\n Compute hsize Hy.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 9\n     : nat \n\\end{Coqanswer}\n\n\nLikewise, the \\emph{height} (maximum distance between the foot and a head) \nis defined by mutual recursion:\n\n\\begin{Coqsrc}\nFixpoint height  (h:Hydra) : nat :=\n  match h with node l => lheight l\n  end\nwith lheight l : nat :=\n  match l with \n  | hnil => 0\n  | hcons h hs => Max.max (S (height h)) (lheight hs)\n  end.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nCompute height Hy.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 4\n     : nat  \n\\end{Coqanswer}\n\n\\index{Exercises}\n\n\\begin{exercise}\nDefine a function \\texttt{max\\_degree: Hydra $\\arrow$ nat} which  returns the highest degree of a node in any hydra. For instance, the evaluation of the term \\texttt{(max\\_degree Hy)} should return $3$.\n\\end{exercise}\n\n\\subsection{Induction Principles for Hydras}\n\\label{sec:orgheadline42}\n\n\nIn this section, we show how induction principles are used to prove properties on the type \n\\texttt{Hydra}. Let us consider for instance the following statement:\n\\begin{quote}\n  `` The height of any hydra is strictly less than its size. ''\n\\end{quote}\n\n\n\n\\subsubsection{A failed Attempt}\n\nOne may try to use the default tactic of proof by induction, which corresponds to an application of the automatically  generated  induction principle for  type \\texttt{Hydra}:\n\n\\begin{Coqanswer}\nHydra_ind :\nforall P : Hydra -> Prop,\n(forall h : Hydrae, P (node h)) -> forall h : Hydra, P h\n\\end{Coqanswer}\n\nLer us start a simple proof by induction.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}}\n\n\\begin{Coqbad}\nModule Bad.\n\nLemma height_lt_size (h:Hydra) :\n  height h <= hsize h.\nProof.\n  induction h as [s].\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n1 subgoal, subgoal 1 (ID 11)\n  \n  s : Hydrae\n  ============================\n   height (node s) <= hsize (node s)\n\\end{Coqanswer}\n\nWe might be tempted to do an induction on the sequence \\texttt{s}:\n\n% \\begin{Coqbad}\n% induction  s as [ | h s'].\n%   -   cbn; auto with arith.\n%   - \n% \\end{Coqbad}\n\n\n\\begin{Coqanswer}\n 1 focused subgoal\n(unfocused: 0), subgoal 1 (ID 19)\n  \n  h : Hydra\n  s' : Hydrae\n  IHs' : height (node s') <= hsize (node s')\n  ============================\n   height (node (hcons h s')) <= hsize (node (hcons h s'))\n\n\\end{Coqanswer}\n\nNote that the displayed subgoal does not contain any assumption on \\texttt{h}, thus there is no way to \ninfer any property about the height and size of the hydra \\texttt{(hcons h t)}.\n\n\\begin{Coqbad}\nAbort.\n\nEnd Bad.\n\\end{Coqbad}\n\n\\subsubsection{A Principle of Mutual Induction}\nIn order to get an appropriate induction scheme for the types \n\\texttt{Hydra} and \\texttt{Hydrae}, we can use  \\coq{}'s  command \\texttt{Scheme}.\n\n\n\\index{Coq!Techniques!Mutually inductive types}\n\\index{Coq!Commands!Scheme}\n\n\\begin{Coqsrc}\nScheme Hydra_rect2 := Induction for Hydra Sort Type\nwith Hydrae_rect2 := Induction for Hydrae Sort Type.\n\\end{Coqsrc}  \n\n\n\\begin{Coqsrc}\nCheck Hydra_rect2.\n\\end{Coqsrc}\n\n\n\\begin{Coqanswer}\nHydra_rect2\n : forall (P : Hydra -> Type) (P0 : Hydrae -> Type),\n   (forall h : Hydrae, P0 h -> P (node h)) ->\n    P0 hnil ->\n    (forall h : Hydra, P h -> \n             forall h0 : Hydrae, P0 h0 -> P0 (hcons h h0)) ->\n    forall h : Hydra, P h\n\\end{Coqanswer}  \n\n\n\n\n\\subsubsection{A Correct Proof}\n\nLet us now use \\texttt{Hydra\\_rect2} for proving that the height of any hydra is strictly less than its size.\nUsing this scheme requires an auxiliary predicate, called \\texttt{P0} in \\texttt{Hydra\\_rect2}'s statement. \nLet us begin by defining an ad-hoc version of \\texttt{List.Forall}.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}}\n\n\\begin{Coqsrc}\n(** All elements of s satisfy P *)\n\nFixpoint h_forall (P: Hydra -> Prop) (s: Hydrae) :=\n  match s with\n      hnil => True\n    | hcons h s' => P h /\\ h_forall P s'\n  end.\n \\end{Coqsrc}\n\n \\begin{Coqsrc}\nLemma height_lt_size (h:Hydra) :\n height h < hsize h.\nProof.\n  induction h using Hydra_rect2  with \n  (P0 :=  h_forall (fun h =>  height h < hsize h)).\n \\end{Coqsrc}\n\n\\begin{enumerate}\n\\item The first subgoal is as follows:\n\n\\begin{Coqanswer}\n\n  h: Hydrae\n  IHh : h_forall (fun h : Hydra => height h < hsize h) h\n  ============================\n   height (node s) < hsize (node s) \n\n\\end{Coqanswer}\n\nThis goal is easily solvable, using some arithmetic. We let the reader look at the source.\n\n\\item The second subgoal is trivial:\n\n\\begin{Coqanswer}\n\n  ============================\n    h_forall (fun h : Hydra => height h < hsize h) hnil\n\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  reflexivity.\n\\end{Coqsrc}\n\n\\item Finally, the last subgoal is also easy to solve:\n\n\n\n\\begin{Coqanswer}\n  h : Hydra\n  h0 : Hydrae\n  IHh : height h < hsize h\n  IHh0 : h_forall (fun h : Hydra => height h < hsize h) h0\n  ============================\n   h_forall (fun h1 : Hydra => height h1 < hsize h1) \n                 (hcons h h0)\n\\end{Coqanswer}  \n\n\n\n\\begin{Coqsrc}\n split;auto. \nQed.   \n\\end{Coqsrc}\n\n\\end{enumerate}\n\n\\index{Exercises}\n\n\\begin{exercise}\nIt happens very often that, in the proof of  a proposition of the form \n(\\texttt{$\\forall\\,$ h:Hydra, $P$ h}), the predicate \\texttt{P0}\nis  (\\texttt{h\\_forall $P$}).  Design a tactic for induction on hydras that frees the user from binding explicitly \\texttt{P0},  and solves trivial subgoals. Apply it for writing  a shorter proof of \\texttt{height\\_lt\\_size}.\n\\end{exercise}\n \n\n\n\\section{Relational Description of Hydra Battles}\n\n\nIn this section, we represent the rules of hydra battles as a binary relation associated with\na \\emph{round}, i.e., an interaction composed of the two following actions:\n\\begin{enumerate}\n\\item Hercules chops off one head of the hydra\n\\item Then, the  hydra replicates the wounded part (if the head is at distance $\\geq 2$ from the foot).\n\\end{enumerate}\nThe relation associated with each round of the battle is parameterized  by the \\emph{expected} replication  factor (irrelevant if the chopped head is at distance 1 from the foot,\nbut present for consistency's sake).\n\nIn our description,  we will apply the following naming convention: if $h$ represents the configuration of the hydra before a round, then the configuration of $h$ after this round will be called $h'$.\n Thus, we are going to define a proposition  (\\texttt{round\\_n $n\\;h\\;h'$})  whose intended meaning will be `` the hydra $h$  is transformed into $h'$  in a single round of a battle, with the expected replication factor $n$ ''.\n\n\nSince the replication of parts of the hydra depends on the distance of the chopped head from  the foot, we  decompose our description into two main  cases, under the form of a bunch of [mutually] inductive predicates over the types \\texttt{Hydra} and \\texttt{Hydrae}.\n\nThe mutually exclusive cases we consider are the following:\n\\begin{itemize}\n\\item \\textbf{R1}: The chopped off head was at distance 1 from the foot.\n\\item \\textbf{R2}: The chopped off head was at a distance greater than or equal to  $2$ from the foot.\n\\end{itemize}\n\n\n\n\\subsection{Chopping off a Head at Distance 1 from the Foot (Relation  R1)}\n\nIf Hercules chops off a head near the floor, there is no replication at all. We use an auxiliary \npredicate \\texttt{S0}, associated with the removing of one head from a sequence of hydras.\n\n\n\\vspace{4pt}\\emph{From Module\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nInductive S0 :  relation Hydrae :=\n| S0_first : forall s, S0  (hcons head s) s\n| S0_rest : forall  h s s',  S0  s s' ->\n                             S0  (hcons h s) (hcons h s').\n\nInductive R1  :  Hydra -> Hydra -> Prop :=\n| R1_intro : forall s s', S0 s s' -> R1 (node s) (node s').\n\\end{Coqsrc}\n\n\\subsubsection{Example}\n\\label{sec:orgheadline45}\n\nLet us represent in \\coq{}   the transformation of the hydra of Fig.~\\vref{fig:Hy} into\nthe configuration represented in Fig.~\\ref{fig:Hy-prime}.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}}\n\n\n\\begin{Coqsrc}\nExample Hy_1 : R1 Hy Hy'.\nProof. \n  split; right; right; left.\nQed.\n\\end{Coqsrc}\n\n\n\\subsection{Chopping off a Head at Distance \\texorpdfstring{$\\geq 2$}{>= 2} from the Foot (relation R2) }\n\n\nLet us now consider beheadings  where the chopped-off head is at distance greater than or equal to $2$ from the foot. All the following relations are parameterized by the replication factor  $n$.\n\n Let $s$ be a sequence of hydras. \nThe proposition (\\texttt{S1 n s s'}) holds if $s'$ is obtained by replacing some element $h$ of $s$ by \n$n+1$ copies of $h'$, where  the proposition (\\texttt{R1 h h'}) holds, in other words, $h'$ is just $h$, without the chopped-off  head. \\texttt{S1} is an inductive relation with two constructors that allow us to choose the position in $s'$ of the wounded sub-hydra $h$.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#S1}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nInductive S1 (n:nat)  : Hydrae -> Hydrae -> Prop :=\n| S1_first : forall s h h' ,   R1 h h' -> \n                  S1 n (hcons h s) (hcons_mult h' (S n) s)\n| S1_next : forall h s s',  S1 n s s' ->\n                   S1 n (hcons h s) (hcons h s').\n\\end{Coqsrc}\n\n\nThe rest of the definition is structured as two mutually inductive relations on hydras and sequences of hydras. The first constructor of \\texttt{R2} describes the case where the chopped head is exactly at height $2$. The others constructors allow us to consider beheadings at height strictly greater than $2$.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#R2}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nInductive R2 (n:nat)  :  Hydra -> Hydra -> Prop :=\n| R2_intro : forall s s', S1 n s s' -> R2 n (node s) (node s')\n| R2_intro_2 : forall s s', S2 n s s' -> R2 n (node s) (node s')\n\nwith S2 (n:nat) :  Hydrae -> Hydrae -> Prop :=\n|  S2_first : forall h h' s ,\n               R2 n  h h'  -> \n               S2  n (hcons h s) (hcons h'  s)\n|  S2_next  : forall h   r r',\n               S2 n   r r' ->\n               S2 n (hcons h r) (hcons h r').                  \n\\end{Coqsrc}\n\n\n\\subsubsection{Example}\nLet us prove the transformation of \\texttt{Hy'} into \\texttt{Hy''} (see Fig.~\\vref{fig:Hy3}). We use an experimental set of tactics for specifying the place where the \ninteraction between Hercules and the hydra holds. \n\n\n\\vspace{4pt}\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Examples.html}{Hydra.Hydra\\_Examples}}. \n\n\\begin{Coqsrc}\nExample R2_example:  R2 4 Hy' Hy''.\nProof.\n    (** move to 2nd sub-hydra (0-based indices) *) R2_up 1. \n    (** move to first sub-hydra *)  R2_up 0.\n    (** we're at distance 2 from the to-be-chopped-off head \n        let's go to the first daughter, \n        then chop-off the leftmost head *)  r2_d2  0 0. \nQed.\n\\end{Coqsrc}\n\nThe reader is encouraged to look at all the successive subgoals of this example.\n\\emph{Please consider also exercise~\\vref{exo:interactive-battle}.}\n\n\n\\subsection{Relation Associated with a Round}\n\nWe combine the two cases above into a single relation.\nFirst,  we define the  relation \\texttt{(round\\_n n h h')} where \\texttt{n} is the expected number of  replications (irrelevant in the case of an \\texttt{R1}-transformation).\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#round_n}{Hydra.Hydra\\_Definitions}}\n\n\\index{Predicates!round\\_n}\n\n\\begin{Coqsrc}\nDefinition round_n n h h' := R1 h h' \\/ R2 n h h'.  \n\\end{Coqsrc}\n\nBy abstraction over \\texttt{n}, we define a \\emph{round} (small step) of a battle:\n\n\\index{Predicates!round}\n\\label{sect:infix-round}\n\\begin{Coqsrc}\nDefinition round h h' := exists n,  round_n n h h'.\n\nInfix \"-1->\" := round (at level 60).\n\\end{Coqsrc}\n\n\\index{Projects}\n\n\\begin{project}\nGive a direct translation of Kirby and Paris's description of hydra battles (quoted on page~\\pageref{original-rules}) and prove that our relational description is consistent with theirs.\n\\end{project}\n\n\n\\subsection{Rounds and Battles}\n\n\nUsing library \\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Relations.Relation_Operators.html}{Relations.Relation\\_Operators}, we define \\texttt{round\\_plus},  the transitive closure of \\texttt{round}, and \\texttt{round\\_star},  the reflexive and transitive closure of \\texttt{round}.\n\n\\label{sect:infix-rounds} \n\n\\begin{Coqsrc}\nDefinition round_plus := clos_trans_1n Hydra round.\nInfix \"-+->\" := rounds (at level 60).\n\nDefinition round_star h h' := h = h' \\/ round_plus h h'.\nInfix \"-*->\" := round_star (at level 60).\n\\end{Coqsrc}\n\n\n\\index{Exercises}\n\n\\begin{exercise}\nProve the following lemma:\n\n\\begin{Coqsrc}\nLemma rounds_height : forall h h', \n   h -+-> h' -> height h' <= height h.  \n\\end{Coqsrc}\n  \n\\end{exercise}\n\n\\begin{remark}\n\\label{remark:transitive-closure}\n\\coq's library \\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Relations.Relation_Operators.html}{Coq.Relations.Relation\\_Operators} \ncontains three logically equivalent definitions of the transitive closure of a binary relation. This equivalence is proved in \n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Relations.Operators_Properties.html}{Coq.Relations.Operators\\_Properties} . \n\nWhy three definitions for a single mathematical concept?\nEach definition generates an associated induction principle. \n According to the form of statement one would like to prove, there is a ``best choice'':\n\n\\begin{itemize}\n\\item For proving $\\forall y, x\\,R^+\\,y \\;\\arrow\\; P\\,y$, prefer \n\\texttt{clos\\_trans\\_n1}\n\\item For proving $\\forall x,\\,x\\,R^+\\,y \\;\\arrow\\; P\\,x$, prefer \\texttt{clos\\_trans\\_1n}\n\\item For proving $\\forall x\\,y, \\,x\\,R^+\\,y \\;\\arrow\\;P\\,x\\,y$,  \nprefer \\texttt{clos\\_trans},\n\\end{itemize}\nBut there is no ``wrong choice'' at all: the equivalence lemmas in \\linebreak \n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Relations.Operators_Properties.html}{Coq.Relations.Operators\\_Properties} \n allow the user\nto convert any one of the three closures into another one before applying the corresponding elimination tactic.\nThe same remark also holds for reflexive and transitive closures. \n\\end{remark}\n\n\\index{Exercises}\n\n\\begin{exercise}\nDefine a restriction of \\coqsimple{round},  where Hercules always chops off\nthe leftmost among the lowest heads.\n\nProve that, if $h$ is not a simple head, then there exists a unique $h'$ such that \\texttt{h}  is transformed into \\texttt{ h'} in one round, according to this restriction.\n\n\n\\end{exercise}\n\n\\index{Exercises}\n\n\\begin{exercise}[Interactive battles]\n\\label{exo:interactive-battle}\nGiven a hydra \\texttt{h}, the specification of a hydra battle for \\texttt{h} is the type \n\\Verb@{h':Hydra | h -*-> h'}@. In order to avoid long sequences of \\texttt{split}, \\texttt{left}, and \n\\texttt{right}, design a set of dedicated tactics for the interactive building of a battle.\nYour tactics will have the following functionalities:\n\\begin{itemize}\n\\item  Chose to stop a battle, or continue\n\\item Chose an expected number of replications\n\\item Navigate in a hydra, looking for a head to chop off.\n\\end{itemize}\n\nUse your tactics for simulating a small part of a hydra battle, for instance the rounds which lead from\n\\texttt{Hy} to \\texttt{Hy'''}  (Fig.~\\vref{fig:Hy5}).\n\n\\textbf{Hints:} \n\\begin{itemize}\n\n\\item Please keep in mind that the last  configuration of your interactively built battle is known only at the end of the battle. Thus, you will have to create and solve subgoals with existential variables. For that purpose, the tactic \\texttt{eexists}, applied to the \ngoal \\Verb@{h':Hydra | h -*-> h'}@ generates the subgoal \\Verb|h -*-> ?h'|.\n\\item You may use Gérard Huet's \\emph{zipper} data structure~\\cite{zipper} for writing tactics associated with Hercule's  interactive search of a head to chop off.\n\\end{itemize}\n\n\n\n\n\n\n\\end{exercise}\n\n\n\n\n\\subsection{Classes of Battles}\n\\label{sect:battle-classes}\n\nIn some presentations of hydra battles, e.g.~\\cite{KP82, bauer2008}, the transformation associated with the $i$-th round may depend on $i$. For instance, in these articles, the replication factor at the $i$-th round is equal to $i$. In other examples, one can allow the hydra to apply any replication factor at any time. In order to be the most general as possible, we define the type of predicates which relate the state of the hydra before and after the $i$-th round of a battle.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html}{Hydra.Hydra\\_Definitions}}\n\\label{types:Battle}\n\n\\begin{Coqsrc}\nDefinition dep_round_t := nat -> Hydra -> Hydra -> Prop.\n\nClass Battle :=  {battle_r : dep_round_t;\n                  battle_inclusion : forall i h h',\n                      battle_r i h h' -> round h h'}.\n\n\\end{Coqsrc}\n\nThe most general class of battles is \\texttt{free}, which allows the hydra to chose any replication factor at every step:\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#free}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nProgram Instance free : Battle :=\n  (Build_Battle ( fun _  h h' => round h h') _).\n\\end{Coqsrc}\n\nWe chosed to call \\emph{standard} the kind of battles which appear  most often in the litterature and correspond to an arithmetic progression of the replication factor : $0,1,2,3, \\dots$\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#standard}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nProgram Instance standard : Battle := (Build_Battle round_n _).\nNext Obligation.\n  now exists i.  \nDefined.\n\\end{Coqsrc}\n\n\n\\subsection{Big Steps}\n\nLet $B$ be any instance of class \\texttt{Battle}. It is easy to define inductively the relation between the $i$-th and the $j$-th steps of a battle of type $B$.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#fight}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nInductive battle (B:Battle) : nat -> Hydra -> nat -> Hydra -> Prop :=\n\n| battle_1 : forall i h  h', battle_r   B i  h h' -> \n                            battle B i h (S i) h'\n| battle_n : forall i h  j h' h'',  battle_r  B i h h''  ->\n                                   battle B (S i) h'' j h'  ->\n                                   battle B i h j h'.\n\\end{Coqsrc}\n\n% \\begin{remark}\n%  The class \\texttt{free} is strongly related with the transitive closure  \\texttt{round\\_plus}, as expressed by the following lemmas.\n\n% \\vspace{4pt}\n% \\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Lemmas.html}{Hydra.Hydra\\_Lemmas}}\n\n%  \\begin{Coqsrc}\n%  Lemma battle_free_equiv1 : forall i j h h',  \n%              battle free i h j h' ->   h -+-> h'.\n \n%  Lemma battle_free_equiv2 : forall h h',\n%      h -+-> h' ->\n%     forall i, exists j,  battle free i h j h'.\n%  \\end{Coqsrc}\n\n% \\end{remark}\n\n\n\n\\section{A Long Battle}\n\\label{sect:big-battle}\n\n\nIn this section we consider a simple example of battle, starting with a small hydra,\nshown on figure~\\vref{fig:hinit}, with a simple strategy for both players:\n\n\\begin{itemize}\n\\item At each round, Hercules chops off the rightmost head of the hydra.\n\\item The battle is standard: at the round number $i$, the expected replication is $i$.\n\\end{itemize}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[thick, scale=0.30]\n \\node (foot) at (6,0) {$\\bullet$};\n\\node (n1) at  (3,3) {$\\bullet$};\n\\node (h1) at  (1,6) {$\\Smiley[1][green]$};\n\\node (h2) at  (3,6) {$\\Smiley[1][green]$};\n\\node (h3) at  (6,6) {$\\Smiley[1][green]$};\n\\node (h4) at  (6,6) {$\\Smiley[1][green]$};\n\\node (h5) at  (6,3) {$\\Smiley[1][green]$};\n\\node (h6) at  (9,3) {$\\Smiley[1][green]$};\n\\draw (foot) -- (n1);\n\\draw (n1) to   [bend left=20] (h1);\n\\draw (n1) to   (h2);\n\\draw (n1) to   [bend right=20] (h3);\n\\draw (foot) -- (h5);\n\\draw (foot) to  [bend right=20] (h6);\n\\end{tikzpicture}\n\n  \\caption{The hydra hinit}\n  \\label{fig:hinit}\n\\end{figure}\n\n\n\\begin{Coqsrc}\nDefinition hinit := hyd3 (hyd_mult head 3)  head head.  \n\\end{Coqsrc}\n\n\n\nThe lemma we would like to prove is ``The considered battle lasts exactly $N$ rounds'',\nwith $N$ being a natural number we gave to guess.\n\nBut the  battle is so long that no \\emph{test} can give us an estimation of its length, and we do need the expressive power of logic to compute this length. However, in order to  guess this length, we made some experiments, computing with \\gallina{}, \\coq{}'s  functional programming language.\nThus, we can consider this development as a collaboration of proof with computation.\n\nIn the following lines, we try to show faithfully how we found the value of the number $N$.\n\nThe complete proof is in file \\url{../theories/html/hydras.Hydra.BigBattle.html}. \n\n\\subsection{The beginning of Hostilities}\nDuring the two first rounds, our hydra loses its two rightmost heads. Thus just before the third round, it looks like in figure~\\vref{fig:hinit-plus2}.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[thick, scale=0.30]\n \\node (foot) at (3,0) {$\\bullet$};\n\\node (n1) at  (3,3) {$\\bullet$};\n\\node (h1) at  (1,6) {$\\Smiley[1][green]$};\n\\node (h2) at  (3,6) {$\\Smiley[1][green]$};\n\\node (h3) at  (6,6) {$\\Smiley[1][green]$};\n\\node (h4) at  (6,6) {$\\Smiley[1][green]$};\n\\draw (foot) -- (n1);\n\\draw (n1) to   [bend left=20] (h1);\n\\draw (n1) to   (h2);\n\\draw (n1) to   [bend right=20] (h3);\n\\end{tikzpicture}\n\n  \\caption{The hydra (hyd1 h3)}\n  \\label{fig:hinit-plus2}\n\\end{figure}\n\nThe following lemma  is a formal description of these first rounds, in terms of the\n\\texttt{battle} predicate.\n\n\\begin{Coqsrc}\nLemma L_0_2 : battle standard 0 hinit 2 (hyd1 h3).   \n\\end{Coqsrc}\n\n\n\\subsection{Looking for Regularities}\n\n\nA first study with pencil and paper suggested us that, after three rounds, the hydra always looks like in figure~\\vref{fig:hinit-plusn} (with a variable number of \nsubtrees of height 1 or 0).\nThus, we introduce handy notations.\n\n\\begin{Coqsrc}\nNotation h3 := (hyd_mult head 3).\nNotation h2 := (hyd_mult head 2).\nNotation h1 := (hyd1 head).\n\nDefinition hyd a b c := \n  node (hcons_mult h2  a\n             (hcons_mult h1  b\n                         (hcons_mult head c hnil))).\n\\end{Coqsrc}\n\n\nFor instance Fig~\\vref{fig:hinit-plusn} shows the hydra (\\texttt{hyd 3 4 2}). The hydra (\\texttt{hyd 0 0 0})  is the ``final'' hydra of any terminating battle, {i.e.},\na tree whith exactly one node and no edge.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[thick, scale=0.30]\n \\node (foot) at (15,0) {$\\bullet$};\n\\node (a) at  (3,4) {$\\bullet$};\n\\node (b) at  (6,4) {$\\bullet$};\n\\node (c) at  (9,4) {$\\bullet$};\n\\node (d) at  (13,4) {$\\bullet$};\n\\node (e) at  (16,4) {$\\bullet$};\n\\node (f) at  (19,4) {$\\bullet$};\n\\node (g) at  (22,4) {$\\bullet$};\n\\node (h) at  (25,4) {$\\Smiley[1][green]$};\n\\node (i) at  (28,4) {$\\Smiley[1][green]$};\n\\node (aa) at  (2.5,8) {$\\Smiley[1][green]$};\n\\node (ab) at  (3.5,8) {$\\Smiley[1][green]$};\n\\node (ba) at  (5.5,8) {$\\Smiley[1][green]$};\n\\node (bb) at  (6.5,8) {$\\Smiley[1][green]$};\n\\node (ca) at  (8.5,8) {$\\Smiley[1][green]$};\n\\node (cb) at  (9.5,8) {$\\Smiley[1][green]$};\n\\node (da) at  (13,8) {$\\Smiley[1][green]$};\n\\node (ea) at  (16,8) {$\\Smiley[1][green]$};\n\\node (fa) at  (19,8) {$\\Smiley[1][green]$};\n\\node (ga) at  (22,8) {$\\Smiley[1][green]$};\n\\draw (foot) -- (a);\n\\draw (foot) -- (b);\n\\draw (foot) -- (c);\n\\draw (foot) -- (d);\n\\draw (foot) -- (e);\n\\draw (foot) -- (f);\n\\draw (foot) -- (g);\n\\draw (foot) -- (h);\n\\draw (foot) -- (i);\n\\draw (a) -- (aa);\n\\draw (a) -- (ab);\n\\draw (b) -- (ba);\n\\draw (b) -- (bb);\n\\draw (c) -- (ca);\n\\draw (c) -- (cb);\n\\draw (d) -- (da);\n\\draw (e) -- (ea);\n\\draw (f) -- (fa);\n\\draw (g) -- (ga);\n% \\node (a) at  (3,4) {$\\bullet$};\n% \\node (h1) at  (1,6) \n% \\node (h2) at  (3,6) {$\\Smiley[1][green]$};\n% \\node (h3) at  (6,6) {$\\Smiley[1][green]$};\n% \\node (h4) at  (6,6) {$\\Smiley[1][green]$};\n% \\draw (foot) -- (n1);\n% \\draw (n1) to   [bend left=20] (h1);\n% \\draw (n1) to   (h2);\n% \\draw (n1) to   [bend right=20] (h3);\n\\end{tikzpicture}\n\n  \\caption{The hydra (hyd 3 4 2)}\n  \\label{fig:hinit-plusn}\n\\end{figure}\n\n\nWith these notations, we get a formal description of the first three rounds.\n\n\n\\begin{Coqsrc}\nLemma L_2_3 : battle standard 2 (hyd1 h3)  3 (hyd 3 0 0).\n\nLemma L_0_3 : battle standard 0 hinit 3 (hyd 3 0 0).\n\\end{Coqsrc}\n\n\n\\subsection{Computing \\dots}\nIn order to study \\emph{experimentally} the different  configurations of the  battle, we will use a simple datatype for representing the states as tuples composed of\nthe round number, and the respective number of daughters  \\texttt{h2}, \\texttt{h1}, and heads\nof the current hydra.\n\n\n\n\n\\begin{Coqsrc}\n Record state : Type :=\n    mks {round: nat ; n2 : nat ; n1 : nat ; nh : nat}.\n\\end{Coqsrc}\n\nThe following function returns the next configurarion of the game. \nNote that this function is defined only for making experiments and is not  ``certified''.  Formal proofs about our battle will only start with the lemma\n\\texttt{lemma:step-battle}, page~\\pageref{lemma:step-battle}.\n\n\n\\begin{Coqsrc}\nDefinition next (s : state) :=\n  match s with\n  | mks round a b (S c) => mks (S round) a b c\n  | mks round a (S b) 0 => mks (S round) a b (S round)\n  | mks round (S a) 0 0 => mks (S round) a (S round) 0\n  | _ => s\n  end.\n\\end{Coqsrc}\n\nWe can make bigger steps through iterations of \\texttt{next}.\nThe functional \\texttt{iterate}, similar to Standard Library's \\texttt{Nat.iter},\nis defined and studied in~\\href{../theories/html/hydras.Prelude.Iterates.html\\#iterate}{Prelude.Iterates}.\n\n\\label{Functions:iterate}\n\n\\begin{Coqsrc}\nFixpoint iterate {A:Type}(f : A -> A) (n: nat)(x:A) :=\n  match n with\n  | 0 => x\n  | S p => f (iterate  f p x)\n  end.\n\\end{Coqsrc}\n\n\n\nThe following function computes the state of the battle at the $n$-th round.\n\n\n\\begin{Coqsrc}\nDefinition test n := iterate next (n-3) (mks 3 3 0 0).\n\nCompute test 3.\n   (**\n     = {| round := 3; n2 := 3; n1 := 0; nh := 0 |}\n     : state\n    *)\n\nCompute test 4.\n (*\n  = {| round := 4; n2 := 2; n1 := 4; nh := 0 |}\n     : state\n *)\n\nCompute test 5.\n (*\n   = {| round := 5; n2 := 2; n1 := 3; nh := 5 |}\n     : state\n *)\n\nCompute test 2000.\n(*\n  = {| round := 2000; n2 := 1; n1 := 90; nh := 1102 |}\n     : state\n*)\n\\end{Coqsrc}\n\n\nThe battle we are studying seems to be awfully long. Let us concentrate our\ntests on some particular events : the states where $\\texttt{nh}=0$.\nFrom the value of \\texttt{test 5},  it is obvious that at the 10-th round, the counter \\texttt{nh} is equal to zero.\n\n \\begin{Coqsrc}\n Compute test 10.\n(*\n\n    = {| round := 10; n2 := 2; n1 := 3; nh := 0 |}\n     : state\n*)\n \\end{Coqsrc}\n\nThus, $ (1 + 11)$ rounds later, the \\texttt{n1} field is equal to $2$, and \n\\texttt{nh}   to $0$. \n\n\n\\begin{Coqsrc}\nCompute test 22.\n(*\n\n = {| round := 22; n2 := 2; n1 := 2; nh := 0 |}\n     : state\n*)\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\n Compute test 46.\n(*\n\n = {| round := 46; n2 := 2; n1 := 1; nh := 0 |}\n     : state\n\n*)\n\nCompute test 94.\n\n(*\n\n = {| round := 94; n2 := 2; n1 := 0; nh := 0 |}\n     : state\n\n*) \n\\end{Coqsrc}\n\n\nNext round, we decrement \\texttt{n2} and set \\texttt{n1} to $95$.\n\n\n\\begin{Coqsrc}\n Compute test 95.\n\n(*\n\n  = {| round := 95; n2 := 1; n1 := 95; nh := 0 |}\n     : state\n\n*)\n\\end{Coqsrc}\n\nWe now have some intuition of the sequence.\nIt looks like the next ``\\texttt{nh}=0'' event will happen at the $192=2(95+1)$-th round, then at the $2(192+1)$-th round, etc.\n\n\n\\begin{Coqsrc}\nDefinition doubleS (n : nat) := 2 * (S n).\n\nCompute test (doubleS 95).\n\n(**\n = {| round := 192; n2 := 1; n1 := 94; nh := 0 |}\n     : state\n *)\n\n\nCompute test (iterate doubleS 2 95).\n\n(*\n  = {| round := 386; n2 := 1; n1 := 93; nh := 0 |}\n     : state\n*)\n\\end{Coqsrc}\n\n\\subsection{Proving \\dots}\nWe are now able to reason about the sequence of transitions defined by our hydra battle. Instead of using the data-type \\texttt{state} we study the relationship\nbetween different configurations of the battle.\n\nLet us define a binary relation associated with every round of the battle.\nIn the following definition \\texttt{i} is associated with the round number (or date, if we consider a discrete time), and \\texttt{a}, \\texttt{b}, \\texttt{c} respectively associated with the number of \\texttt{h2}, \\texttt{h1} and heads connected to the hydra's foot.\n\n\\begin{Coqsrc}\nInductive one_step (i: nat) :\n  nat -> nat -> nat -> nat -> nat -> nat -> Prop :=\n| step1: forall a b c, one_step i a b (S c) a b c\n| step2:  forall a b, one_step i a (S b) 0 a b (S i)\n| step3: forall a, one_step i (S a) 0 0 a (S i) 0.\n\\end{Coqsrc}\n\nThe relation between \\texttt{one\\_step} and the rules of hydra battle is asserted by the following lemma. \n\n\\label{lemma:step-battle}\n\n\\begin{Coqsrc}\nLemma step_battle : forall i a b c a' b' c', \n   one_step i a b c a' b' c' ->\n   battle standard i (hyd  a b c)  (S i) (hyd a' b' c').\n\\end{Coqsrc}\n\nNext, we define ``big steps'' as the transitive closure of \\texttt{one\\_step},\nand reachability (from the initial configuration of figure~\\ref{fig:hinit} at time $0$).\n\n\n\n\\begin{Coqsrc}\n Inductive steps : nat -> nat -> nat -> nat ->\n                  nat -> nat -> nat -> nat -> Prop :=\n| steps1 : forall i a b c a' b' c',\n    one_step i a b c a' b' c' -> steps i a b c (S i) a' b' c'\n| steps_S : forall i a b c j a' b' c' k a'' b'' c'',\n    steps i a b c j a' b' c' ->\n    steps j a' b' c' k a'' b'' c'' ->\n    steps i a b c k  a'' b'' c''.\n\nDefinition reachable (i a b c : nat) : Prop :=\n  steps 3 3 0 0 i a b c.\n\\end{Coqsrc}\n\n\nThe following lemma establishes a relation between \\texttt{steps} and the predicate \\texttt{battle}.\n\n\\begin{Coqsrc}\n Lemma steps_battle : forall i a b c j a' b' c', \n   steps i a b c j a' b' c' ->\n   battle standard i (hyd  a b c)   j  (hyd a' b' c').\n\\end{Coqsrc}\n\nThus, any result about \\texttt{steps} will be applicable to standard battles.\nUsing the predicate \\texttt{steps} our study of the length of the considered battle\ncan  be decomposed into three parts:\n\n\\begin{enumerate}\n\\item  Characterization of regularities of some events\n\\item Study of the beginning of the battle\n\\item Computing the exact length of the battle.\n\\end{enumerate}\n\nFirst, we prove that, if at round $i$ the hydra is equal to\n(\\texttt{hyd a (S b) 0}), then it will be equal to (\\texttt{hyd a b 0}) at the $2(i+1)$-th round.  \n\n\\begin{Coqsrc}\nLemma LS : forall c a b i,  steps i a b (S c) (i + S c) a b 0.\nProof.\n  induction c.\n -   intros;  replace (i + 1) with (S i).\n     + repeat constructor.\n     + ring.\n -  intros; eapply  steps_S.\n   +   eleft;   apply rule1.\n   +   replace (i + S (S c)) with (S i + S c) by ring;  apply IHc.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma doubleS_law : forall  a b i, steps i a (S b) 0 (doubleS i) a b 0.\nProof.\n  intros;  eapply steps_S.\n  +   eleft;   apply step2.\n  +   unfold doubleS; replace (2 * S i) with (S i + S i) by ring; \n        apply LS.\nQed.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma reachable_S  : forall i a b, reachable i a (S b) 0 ->\n                                   reachable (doubleS i) a b 0.\nProof.\n  intros; right with  (1 := H); apply doubleS_law.\nQed.\n\\end{Coqsrc}\n\nFrom now on, the lemma \\texttt{reachable\\_S} allows us to watch larger steps of \nthe battle.\n\n\n\\begin{Coqsrc}\n Lemma L4 : reachable 4 2 4 0.\nProof.\n  left; constructor.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma L10 : reachable 10 2 3 0.\nProof.\n  change 10 with (doubleS 4).\n  apply reachable_S, L4.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma L22 : reachable 22 2 2 0.\nProof.\n  change 22 with (doubleS 10).\n  apply reachable_S, L10.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma L46 : reachable 46 2 1 0.\nProof.\n  change 46 with (doubleS 22); apply  reachable_S, L22.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma L94 : reachable 94 2 0 0.\nProof.\n  change 94 with (doubleS 46); apply reachable_S, L46.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma L95 : reachable 95 1 95 0.\nProof.\n  eapply steps_S.\n  -  eexact L94.\n  -  repeat constructor.\nQed.\n\\end{Coqsrc}\n\n\\subsection{Giant Steps}\n\nWe are now able to make bigger steps in the simulation of the battle.\nFirst, we iterate the lemma \\texttt{reachable\\_S}.\n\n\\begin{Coqsrc}\nLemma Bigstep : forall b i a , reachable i a b 0 ->\n                               reachable (iterate doubleS b i) a 0 0.\n Proof.\n  induction b.\n  -  trivial.\n  -  intros;  simpl;   apply reachable_S in H.\n     rewrite <- iterate_comm; now apply IHb.\n Qed.\n\\end{Coqsrc}\n\nApplying lemmas \\texttt{BigStep} and \\texttt{L95} we make a first jump.\n\n\n\\begin{Coqsrc}\n Definition M := (iterate doubleS 95 95).\n\nLemma L2_95 : reachable M 1 0 0.\nProof.\n  apply Bigstep,  L95.\nQed.\n\\end{Coqsrc}\n\nFigure~\\ref{fig:HM}  represents the hydra at the $M$-th round.\nAt the $(M+1)$-th round, it will look like in fig~\\ref{fig:HM-plus1}.\n\n\n\n\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (3,4) {$\\Smiley[2][green]$};\n\\node (N3) at (1,4) {$\\Smiley[2][green]$};\n\\draw (foot) -- (N1);\n\\draw (N1) to [bend right =15] (N2);\n\\draw (N1) to  [bend left=15](N3);\n\\end{tikzpicture}\n\\caption{\\label{fig:HM}}\nThe state of the hydra after $M$ rounds.\n% The hydra \\texttt{h} of the proof that \\(\\omega^2\\) is too small for proving Hercules' victory\n\n\\end{figure}\n\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\\node (foot) at (10,0) {$\\bullet$};\n\\node (N1) at (0,5) {$\\bullet$};\n\\node (N12) at (0,8) {$\\Smiley[2][green]$};\n\\node (N2) at (2,5) {$\\bullet$};\n\\node (N22) at (2,8) {$\\Smiley[2][green]$};\n\\node (N3) at (4,5) {$\\bullet$};\n\\node (N32) at (4,8) {$\\Smiley[2][green]$};\n\\node (N4) at (6,5) {$\\bullet$};\n\\node (N42) at (6,8) {$\\Smiley[2][green]$};\n\n\\node (Ndots) at (12,8) {\\Huge $\\dots$};\n\\node (Ndots2) at (12,5) {\\Huge $\\dots$};\n\n\\node (N8) at (18,5) {$\\bullet$};\n\\node (N82) at (18,8) {$\\Smiley[2][green]$};\n\\node (N9) at (20,5) {$\\bullet$};\n\\node (N92) at (20,8) {$\\Smiley[2][green]$};\n\n\n\\draw (foot) -- (N1);\n\\draw (foot) -- (N2);\n\\draw (foot) -- (N3);\n\\draw (foot) -- (N4);\n\\draw (foot) -- (N8);\n\\draw (foot) -- (N9);\n\\draw (N1) to  (N12);\n\\draw (N2) to  (N22);\n\\draw (N3) to  (N32);\n\\draw (N4) to  (N42);\n\\draw (N8) to  (N82);\n\\draw (N9) to  (N92);\n\\end{tikzpicture}\n\\caption{\\label{fig:HM-plus1}}\nThe state of the hydra after $M+1$ rounds (with $M+1$ heads). \n\n\\end{figure}\n\n\\begin{Coqsrc}\nLemma L2_95_S : reachable (S M) 0 (S M) 0.\nProof.\n  eright.\n  - apply L2_95.\n  -  left; constructor 3.\nQed.\n\\end{Coqsrc}\n\n\nThen, applying once more the lemma \\texttt{BigStep}, we get the exact time when\nHercules wins!\n\n\n\\begin{Coqsrc}\nDefinition N :=   iterate doubleS (S M) (S M).\n\nTheorem   SuperbigStep : reachable N  0 0 0 .\nProof.\n  apply Bigstep, L2_95_S.\nQed.\n\\end{Coqsrc}\n\nWe are now able to prove formally that the considered battle is \ncomposed of $N$ steps.\n\n\\begin{Coqsrc}\nLemma Almost_done :\n  battle standard 3 (hyd 3 0 0) N (hyd 0 0 0).\nProof. \n  apply steps_battle, SuperbigStep.\nQed.\n\nTheorem Done :\n  battle standard 0 hinit N head.\nProof.\n  eapply battle_trans.\n  -   apply Almost_done.\n  -  apply L_0_3.\nQed.\n\\end{Coqsrc}\n\n\n\n\\subsection{A Minoration Lemma}\n\nNow, we would like to get an intuition of  how big the number $N$ is.\nFor that purpose, we use a minoration of the function \\texttt{doubleS} by the\nfunction (\\texttt{fun n => 2 * n}).\n\n\\begin{Coqsrc}\nDefinition exp2 n := iterate (fun n => 2 * n) n 1.\n\\end{Coqsrc}\nUsing some facts (proven in \n\\href{../theories/html/hydras.Hydra.BigBattle.html}{hydras.Hydra.BigBattle}),we get several  minorations.\n\n\\begin{Coqsrc}\nLemma minoration_0 : forall n,  2 * n <= doubleS n.\n\nLemma minoration_1 : forall n x, exp2 n * x <= iterate doubleS n x.\n\nLemma minoration_2 : exp2 95 * 95 <= M.\n\nLemma minoration_3 : exp2 (S M) * S M <= N.\n\nLemma minoration : exp2 (exp2 95 * 95) <= N.\n\\end{Coqsrc}\n\n\nThe number $N$ is greater than or  equal to $2^{2^{95}\\times 95}.$ If we wrote $N$ in base $10$, $N$ would require at least $10^{30}$ digits!\n\n\n\\section{Generic Properties}\n\n\nThe example we just studied shows that the termination of any battle may take a very long time. If we want to study hydra battles in general, we have to consider \nany hydra and any strategy, both for Hercules and the hydra itself. So, we first  give some definitions, generally borrowed from transition systems vocabulary (see~\\cite{tel_2000} for instance).\n\n\n\\subsection{Liveliness}\n\n\nLet $B$ be an instance of \\texttt{Battle}. We say that $B$ is \\emph{alive} if\nfor any configuration $(i,h)$, where $h$ is not a head, there exists a further step in class $B$.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#Alive}{Hydra.Hydra\\_Definitions}}\n\n\\begin{Coqsrc}\nDefinition Alive (B : Battle) :=\n  forall i h, \n     h <> head -> {h' : Hydra |  B i h h'}.\n\\end{Coqsrc}\n\nThe theorems \\texttt{Alive\\_free} and \\texttt{Alive\\_standard} of the module \n\\url{../theories/html/hydras.Hydra.Hydra_Theorems.html} show that the classes \\texttt{free} and \\texttt{standard} satisfy this property.\n\n\\begin{Coqsrc}\nTheorem Alive_free: Alive free.\n\nTheorem Alive_standard: Alive standard.  \n\\end{Coqsrc}\n\nBoth theorems are proved with the help of the  following strongly specified function:\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Lemmas.html\\#next_round_dec}{Hydra.Hydra\\_Lemmas}}\n\n\\begin{Coqsrc}\nDefinition  next_round_dec n :\n forall h , (h = head) + {h' : Hydra & {R1 h h'} + {R2 n h  h'}}.\n\\end{Coqsrc}\n\n\n\\subsection{Termination}\n\nThe termination of all battles is naturally expressed by the predicate \\texttt{well\\_founded} defined in the module \\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Init.Wf.html}{Coq.Init.Wf} \n of the Standard Library.\n\n\\index{Predicates!Termination}\n\n\\begin{Coqsrc}\nDefinition Termination :=  well_founded (transp _ round).\n\\end{Coqsrc}\n\n\nLet $B$ be an instance of class \\texttt{Battle}. A \\emph{variant} for $B$ consists\nin a well-founded relation $<$  on some type \\texttt{A}, and a function\n(also called a \\emph{measure}) \\texttt{m:Hydra->A} such that for any successive steps $(i,h)$ and $(1+i,h')$  of a battle in $B$, the inequality $m(h')<m(h)$ holds.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Definitions.html\\#Hvariant}{Hydra.Hydra\\_Definitions}}\n\n\n\\label{sect:hvariant-def}\n\n\\begin{Coqsrc}\nClass Hvariant {A:Type}{Lt:relation A}(Wf: well_founded Lt)(B : Battle)\n  (m: Hydra -> A):   Prop :=\n  {variant_decr :forall i h h',\n      h <> head ->\n      battle_r  B i  h h' -> Lt (m h') (m h)}.\n\\end{Coqsrc}  \n\n\\index{Exercises}\n\n\\begin{exercise}\n Prove that, if there is an instance of (\\texttt{Hvariant Lt wf\\_Lt $B$ $m$}), then there exists no infinite battle in  $B$.\n\\end{exercise}\n\n\n\n\n\\subsection{A  Small Proof of Impossibility}\n\\index{Maths!Proofs of impossibility}\n\n\\label{omega-case}\n\nWhen one wants to prove a termination theorem with the help of a variant, \none has to consider first a well-founded set $(A,<)$, then a strictly decreasing measure on this set.  The following two lemmas show that if  the order structure $(A,<)$ is too simple, it is useless to look for a convenient measure, which simply no exists. Such kind of result is useful, because it saves you time and effort.\n\n\nThe best known well-founded order is the natural order on the set $\\mathbb{N}$ of natural numbers (the type \\texttt{nat} of Standard library). It would be interesting to look for some measure $m:\\texttt{nat}\\arrow\\texttt{nat}$ and prove it is a variant.\n\nUnfortunately, we can prove that \n\\emph{no} instance of class (\\texttt{WfVariant round Peano.lt $m$}) can be built, where\n$m$ is \\emph{any} function of type \\texttt{Hydra $\\arrow$ nat}.\n\n\nLet us present the main steps of that proof, the script of which  is in the module ~\\href{../theories/html/hydras.Hydra.Omega_Small.html}{Hydra/Omega\\_Small.v} \\footnote{ The name of this file means ``the ordinal $\\omega$ is too small for proving the termination of [free] hydra battles ''. In effect, the elements of $\\omega$, considered as a set, are just the natural numbers (see next chapter for more details)}.\n\n%\\subsubsection{Preliminaries}\n\n\nLet us assume there exists some variant $m$ from \\texttt{Hydra} into \\texttt{nat} for proving\n    the  termination of all hydra battles.\n\n\\begin{Coqsrc}\nSection Impossibility_Proof.\n Variable m : Hydra -> nat.\n Hypothesis Hvar : Hvariant lt_wf free m.\n\\end{Coqsrc}\n\nWe define an injection $\\iota$ from the type \\texttt{nat} into \\texttt{Hydra}.\nFor any natural number $i$, $\\iota(i)$ is the hydra composed of a foot and\n$i+1$ heads at height $1$. For instance, Fig.~\\ref{fig:flower} represents the hydra $\\iota(3)$.\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\\node (foot) at (4,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\Smiley[2][green]$};\n\\node (N2) at (4,2) {$\\Smiley[2][green]$};\n\\node (N3) at (6,2) {$\\Smiley[2][green]$};\n\\node (N4) at (8,2) {$\\Smiley[2][green]$};\n\\draw (foot) to [bend left =25] (N1);\n\\draw (foot) to [bend left =15] (N2);\n\\draw (foot) to [bend right =15] (N3);\n\\draw (foot) to [bend right =25] (N4);\n\\end{tikzpicture}\n\\caption{\\label{fig:flower}\nThe hydra $\\iota(3)$}\n\\end{figure}\n\n  \\begin{Coqsrc}\n  Let iota (i: nat) := hyd_mult head (S i).    \n  \\end{Coqsrc}\n\nLet us consider now some hydra \\texttt{big\\_h} out of the range of the injection $\\iota$ (see Fig.~\\vref{fig:h-omega-omega}).\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (2,4) {$\\Smiley[2][green]$};\n\\draw (foot) -- (N1);\n\\draw (N1) to  (N2);\n\\end{tikzpicture}\n\\caption{\\label{fig:h-omega-omega}}\n The hydra \\texttt{big\\_h}.\n\\end{figure}\n\n \\begin{Coqsrc}\n  Let big_h := hyd1 (hyd1 head).\n \\end{Coqsrc}\n\n Using the functions $m$ and $\\iota$, we define a second hydra \\texttt{small\\_h}, and show\n there is a one-round battle that transforms \\texttt{big\\_h} into \\texttt{small\\_h}. Please note that,\ndue to the hypothesis \\texttt{Hvar}, we are interested in the termination of \\emph{free} battles. \nThere is no problem to consider a round with (\\texttt{m big\\_h}) as the replication factor.\n\n  \\begin{Coqsrc}\n Let small_h := iota (m big_h).\n   \n Fact big_to_small : big_h -1-> small_h.\n Proof.\n      exists (m big_h); right; repeat constructor.     \n Qed.\n    \\end{Coqsrc}\n \nBut, by hypothesis, $m$ is a variant. Hence, we infer the following inequality.\n\n\n \\begin{Coqsrc}\nLemma m_lt : m small_h < m big_h.\n \\end{Coqsrc}\n\nIn order to get a contradiction, it suffices to  prove the inequality\n\\texttt{m big\\_h <= m small\\_h}, i.e.,  \\texttt{m big\\_h <= m (iota (m big\\_h))}.\n\nMore generally, we prove the following lemma: \n\n\\begin{Coqsrc}\nLemma m_ge : forall i:nat, i <= m (iota i).\n\\end{Coqsrc}\n\nIntuitively, it means that, from any hydra of the form (\\texttt{iota $i$}), the battle will \ntake (at least) $i$ rounds. Thus the associated measure cannot be less than $i$.\nTechnically, we prove this lemma by Peano induction on $i$.\n\n\\begin{itemize}\n\\item The base case $i=0$ is trivial\n\\item Otherwise, let $i$ be any natural number and assume  the inequality\n  $i \\leq m(\\iota(i))$.\n  \\begin{enumerate}\n  \\item  But the hydra $\\iota(S(i))$ can be transformed in one round into\n    $\\iota(i)$ (by losing its righmost head, for instance)\n  \\item Since $m$ is a variant, we have $m(\\iota(i)) < m(\\iota(S(i)))$,\n    hence  $i< m(\\iota(S(i)))$, which implies  $S(i)\\leq  m(\\iota(S(i)))$.\n  \\end{enumerate}\n\\end{itemize}\n\n Then our proof is almost finished.\n \n   \\begin{Coqsrc}\nTheorem Contradiction : False.\nProof.\n apply (Nat.lt_irrefl (m big_h));\n   apply  Lt.le_lt_trans with (m small_h).\n  - apply m_ge.\n  - apply m_lt.\nQed. \n\nEnd Impossibility_Proof.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\nProve that there exists no variant $m$ from \\texttt{Hydra} into \\texttt{nat} for proving\n    the  termination of all \\emph{standard} battles.\n\\end{exercise}\n\n\n\n\n\n\n\\subsubsection{Conclusion}\n\nIn order to build a variant for proving the termination of all hydra battles, we need to consider order structures more complex than the usual order on type \\texttt{nat}. \nThe notion of \\emph{ordinal number} provides a catalogue of well-founded order types.\nFor a reasonably large bunch of ordinal numbers, \\emph{ordinal notations} are data-types which allow the \\coq{} user to define functions, to compute and prove some properties, for instance by reflection.\n\nThe next chapter is dedicated to a generic implementation of ordinal notations, and chapter~\\ref{chap:T1} to a proof of termination of all hydra battles with the help of an ordinal notation for the interval $[0,\\epsilon_0)$.\n\n\n%--------------------------------------------------------------\n\n\\chapter{Introduction to Ordinal Numbers and Ordinal Notations}\n\n\nThe proof of termination of all hydra battles presented in~\\cite{KP82} is based\non \\emph{ordinal numbers}.\nFrom a mathematical point of view, an ordinal is a representant of an equivalence class for isomorphims of  totally ordered well-founded sets.\n\nFor the computer scientist, ordinals are tools for proving the totality of a given recursive function, or termination of a transition system. \\emph{Ordinal arithmetic} \nprovides a set of functions whose properties, like \\emph{monotony}, allow to define \\emph{variants}, \\emph{i.e.} strictly decreasing measures used in proofs of termination.\n\n\nLet us have a look at Figure~\\ref{fig:ordinal-sequence}. It presents a small sequence of ordinal numbers, which extends the sequence of natural numbers. \n\n\n\n\n\\begin{figure}[h]\n  \\centering\n\\fbox{\\Large\n  \\begin{minipage}{1.0\\linewidth}\n  \\begin{align*}\n     &\\textcolor{blue}{0},\\,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,\\ldots\\\\\n&\\textcolor{red}{\\omega},\\,\\omega+1,\\omega+2,\\omega+3,\\ldots\\\\\n&\\textcolor{red}{\\omega\\times 2},\\,\\omega\\times 2+1,\\ldots, \\textcolor{red}{\\omega\\times 3},\\,\\omega\\times 3+1,\\ldots, \\textcolor{red}{\\omega\\times 4},\\ldots,\\\\\n&\\textcolor{red}{\\omega^2},\\ldots, \\textcolor{red}{\\omega^2\\times 42},\\ldots,\\textcolor{red}{\\omega^3},\\ldots, \\textcolor{red}{\\omega^4},\\omega^4+1,\\ldots,\\\\\n&\\textcolor{red}{\\omega^\\omega},\\ldots, \\textcolor{red}{\\omega^\\omega+\\omega^7\\times 8},\\ldots,\\textcolor{red}{\\omega^\\omega\\times 2},\\omega^\\omega\\times 2+1, \\ldots,\\\\\n&\\textcolor{red}{\\omega^{\\omega^\\omega}},\\ldots, \\textcolor{red}{\\omega^{\\omega^\\omega}+\\omega^\\omega\\times 42+ \\omega^{55}+\\omega}, \\ldots, \\textcolor{red}{\\omega^{\\omega^{\\omega+1}}}, \\omega^{\\omega^{\\omega+1}}+1,\\dots\\\\\n& \\textcolor{red}{\\epsilon_0 (= \\omega^{\\epsilon_0)}}, \\epsilon_0+1, \\epsilon_0+2, \\epsilon_0+3, \\ldots,\\\\\n& \\textcolor{red}{\\epsilon_1}, \\ldots, \\textcolor{red}{\\epsilon_2}, \\ldots, \\textcolor{red}{\\epsilon_\\omega},\\ldots \\\\\n& \\textcolor{red}{\\Gamma_0}, \\Gamma_0+1, \\Gamma_0+2, \\Gamma_0+3,\\ldots, \\textcolor{red}{\\Gamma_0+\\omega}, \\ldots,\\\\\n&\\ldots\n  \\end{align*}   \n  \\end{minipage}}\n \n \n  \\caption{A short overview of the sequence of ordinal numbers}\n  \\label{fig:ordinal-sequence}\n\\end{figure}\n\n\nLet us comment some features of this figure:\n\n\\begin{itemize}\n\\item The ordinals are listed in a strictly increasing order. \n\\item Dots : ``$\\ldots$'' stand for  infinite sequences of ordinals, not shown for lack of space. For instance, the ordinal $42$ is not shown in the first line, but it exists, between $17$ and $\\omega$.\n\\item Each ordinal printed in black is the immediate successor of another ordinal. We call it a \\emph{successor} ordinal. For instance, $12$ is the successor of $11$, and $\\omega^4+1$ the successor of $\\omega^4$.\n\\item Ordinals (displayed in red)  that  follow immediately dots are called \\emph{limit ordinals}. With respect to the order induced by this sequence, any limit ordinal $\\alpha$ is the least upper bound of  the set $\\mathbb{O}_\\alpha$ of all ordinals strictly less than $\\alpha$.\n\\item\nFor instance $\\omega$ is the least upper bound of the set of all finite ordinals (in the first line). It is also the first limit ordinal, and the first infinite ordinal, in the sense that \nthe set $\\mathbb{O}_\\omega$ is infinite.\n\\item The ordinal $\\epsilon_0$ is the first number which is equal to its own exponential of base $\\omega$. It plays an important role in proof theory, and is particularly studied in chapters~\\ref{chap:T1} to \\ref{chap:alpha-large}.\n\\item Any ordinal is  either the ordinal \\textcolor{blue}{$0$},\na successor ordinal, or a \\textcolor{red}{limit ordinal}.\n\\end{itemize}\n\n\n\n\n\\section{The Mathematical Point of View}\n\n\\subsection{Well-ordered Sets}\nLet us start with some definitions.\nA  \\emph{well-ordered set} is a set provided with a binary relation $<$ which has the following properties.\n\\begin{description}\n\\item[irreflexivity] : $\\forall x\\in A, x\\not< x$\n\\item[transitivity] : $\\forall x\\,y\\,z\\in A, x<y \\Rightarrow y<z \\Rightarrow x<z$\n\\item[trichotomy]: $\\forall x\\,y\\in A, x<y \\vee x = y \\vee y < x$\n\\item[well foundedness]: $<$ is well-founded (every element of $A$ is accessible)\\footnote{In classical mathematics, we would say that there is no infinite sequence $a_1>a_2> \\dots a_n> a_{n+1}\\dots$ in $A$. In contrast, \\coq's standard library contains\nan inductive definition of a predicate \\texttt{Acc} which allows us to write \nconstructive proofs of accessibility (See \\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Init.Wf.html}{Coq.Init.Wf}).}.\n\\end{description}\n\nThe best known examples of well-ordered sets are the set $\\mathbb{N}$ of natural numbers (with the usual order $<$), as well as any finite segment $[0,i)=\\{j\\in\\mathbb{N}\\,|\\,j<i\\}$.\nThe disjoint union of two copies of $\\mathbb{N}$, \\emph{i.e.} the set $\\{0,1\\}\\times\\mathbb{N}$ is also well-ordered,\nwith respect to the order below:\n\n\\begin{align*}\n(i,j) < (i,k) & \\;\\textit{\\textbf{if} }\\; j < k\\\\\n(0,k) < (1,l) & \\;\\textit{\\textbf{for\\,any}}\\;k \\;\\textit{\\textbf{and}} \\; l\n\\end{align*}\n\n\\subsection{Ordinal Numbers}\n\n\\index{Maths!Ordinal numbers}\n\nLet $(A,<_A)$ and $(B,<_B)$ two well-ordered sets. $A$ and $B$ are said to have \\emph{the same order type} if \nthere exists a strictly monotonous bijection $b$ from $A$ to $B$, \\emph{i.e.} which verifies the proposition\n$\\forall x\\,y\\in A, x <_A y \\Rightarrow b(x) <_B  b(y)$.\n\nHaving the same order type is an equivalence relation between well-ordered sets. Ordinal numbers (in short \\emph{ordinals}) are descriptions (\\emph{names}) of the equivalence classes.\nFor instance, the order type of $(\\mathbb{N},<)$ is associated with the ordinal called  $\\omega$, and the order we considered on \nthe disjoint union of $\\mathbb{N}$ and itself is named $\\omega+\\omega$.\n\nIn a set-theoretic framework, one can consider any ordinal $\\alpha$ as a well-ordered set, whose  elements are just the ordinals strictly less than $\\alpha$, \\emph{i.e.} the \\emph{segment} $\\mathbb{O}_\\alpha=[0, \\alpha)$. So, one can speak about \\emph{finite}, \\emph{infinite}, \\emph{countable}, etc., ordinals. Nevertheless, since we work within type theory, \nwe do not identify ordinals as sets of ordinals, but the correspondance between ordinals and sets of ordinals is the function that maps $\\alpha$ to $\\mathbb{O}_\\alpha$.\nFor instance $\\mathbb{O}_\\omega=\\mathbb{N}$, and $\\mathbb{O}_7=\\{0,1,2,3,4,5,6\\}$.\n\n\nWe cannot cite all the litterature published on ordinals since Cantor's book \n\\cite{cantorbook}, and \nleave it to the reader to explore the bibliography. \n\n\n\\section{Ordinal Numbers in Coq}\n\nTwo kinds of representation of ordinals are defined herein.\n\n\\begin{itemize}\n\\item A ``mathematical'' representation of the set of countable ordinal numbers, afer Kurt Schütte~\\cite{schutte}. This representation uses several (hopefully harmless) axioms. We use it as a reference for proving the correctness of ordinal notations.\n\\item A family of \\emph{ordinal notations}, \\emph{i.e.} data types used to represent segments $[0,\\mu)$, where $\\mu$ is some countable ordinal. Each ordinal notation is defined inside the Calculus of Inductive Constructions (without axioms). Many functions are defined, allowing proofs by computation. Note that proofs of \ncorrectness of a given ordinal notation with respect to Schütte's model obviously use axioms.\nPlease execute the \\texttt{Print Assumptions} command in case of doubt.\n\\end{itemize}\n\n\\section{Countable Ordinals}\n\nChapter~\\ref{chap:schutte} of this document presents an adaptation to \\coq{} of an axiomatization in classical logic of the set of countable ordinals by K. Schütte~\\cite{schutte}. \nThat formalization is quite complex, technical and unshamedly non-constructive,  so we put its description  in the last chapter of this document. \n\nPlease note that Schütte considers the (uncountable) set $\\mathbb{O}$ of all countable ordinals. This set is well ordered (which is one of Schütte's axioms), and associates to any ordinal $\\alpha$ the segment $\\mathbb{O}_\\alpha$ of all ordinals strictly less than $\\alpha$.\n\nIn our adaptation to \\coq{}, we declare a type \\texttt{Ord}, a binary relation \\texttt{lt} (with infix notation \\texttt{\"\\_<\\_\"}, and assume Schütte's axiom. In Chapter~\\ref{chap:schutte},\nwe derive some interesting properties of countable ordinals from these axioms.\nIt is interesting to compare proofs of a given property (for instance the associativity of addition) in the computational framework of some ordinal notation, and in the axiomatic model of Schütte.\n\n\\section{Ordinal Notations}\n\n\nFortunately, the ordinals we need for  studying hydra battles are much simpler than Schütte's, and can be represented as quite simple data types in \\gallina. So, we will use \\emph{ordinal notations} (also called \\emph{[ordinal] notation systems}). \n\nLet $\\alpha$ be some (countable) ordinal; \nin \\coq{} terms, we call ordinal notation for $\\alpha$ a structure composed \nof:\n\\begin{itemize}\n\\item A data type $A$ for representing all ordinals strictly below $\\alpha$,\n\\item A well founded order $<$ on $A$, \n\\item A correct function for comparing two ordinals. Note  that the reflexive closure of $<$ is thus a \\emph{total order}.\n\\end{itemize}\n\n\nSuch a structure can be proved correct relatively to another ordinal notation or\nto Schütte's model.\n\n\n\n\n\\subsubsection*{Ordered Types}\n\nThe library ~\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Classes.RelationClasses.html}{%\nCoq.Classes.RelationClasses} contains some definitions and facts about binary relations, among them strict orders.\n\n\n\\begin{Coqsrc}\nVariable A: Type.\n\n  Class StrictOrder (R : relation A) : Prop := {\n    StrictOrder_Irreflexive :> Irreflexive R ;\n    StrictOrder_Transitive :> Transitive R }.\n\\end{Coqsrc}\n\n\n\n\\subsection{A Class for Ordinal Notations}\n\nThe following class definition, parameterized with a type $A$, a binary relation \\texttt{lt} on $A$, specifies that \\texttt{lt} is a well-founded strict order. The reflexive closure of \\texttt{lt}, (called \\texttt{le}, for ``less  or equal than'') is a total decidable order, implemented through a comparison function \\texttt{compare}.  The correctness of this function is expressed through Stdlib's type \n\\texttt{Datatypes.CompareSpec}.\n\n\n\\begin{Coqsrc}\nInductive CompareSpec (Peq Plt Pgt : Prop) : comparison -> Prop :=\n    CompEq : Peq -> CompareSpec Peq Plt Pgt Eq\n  | CompLt : Plt -> CompareSpec Peq Plt Pgt Lt\n  | CompGt : Pgt -> CompareSpec Peq Plt Pgt Gt\n\\end{Coqsrc}\n\n\\vspace{4pt}\n\\noindent\\emph{From Library~\\href{../theories/html/hydras.OrdinalNotations.Definitions.html}{OrdinalNotations.Definitions}}\n\n\\label{types:ON}\n\n\\begin{Coqsrc}\nClass ON {A:Type}(lt: relation A)\n      (compare : A -> A -> comparison)  :=\n  {\n  sto :> StrictOrder lt;\n  wf : well_founded lt;\n  compare_correct :\n    forall alpha beta:A,\n      CompareSpec (alpha=beta) (lt alpha beta) (lt beta alpha)\n                  (compare alpha beta);\n  }.\n\\end{Coqsrc}\n\nThe following definitions allow us to make implicit several guessable arguments.\n\\label{sect:on-lt-notation}\n\\label{sect:on-le-notation}\n\\begin{Coqsrc}\nDefinition on_t  {A:Type}{lt: relation A}\n            {compare : A -> A -> comparison}\n            {on : ON lt compare} := A.\n\nDefinition ON_compare {A:Type}{lt: relation A}\n            {compare : A -> A -> comparison}\n            {on : ON lt compare} := compare.\n\nDefinition ON_lt {A:Type}{lt: relation A}\n           {compare : A -> A -> comparison}\n           {on : ON lt compare} := lt.\nInfix \"o<\" := ON_lt : ON_scope.\n\nDefinition ON_le  {A:Type}{lt: relation A}\n           {compare : A -> A -> comparison}\n           {on : ON lt compare} :=\n  clos_refl _ ON_lt.\n\nInfix \"o<=\" := ON_le : ON_scope.\n\\end{Coqsrc}\n\n\n\\begin{remark}\nThe infix notations \\texttt{o<} and \\texttt{o<=} were defined in order to make apparent the distinction between the various notation scopes that may co-exist in a same statement. So the infix \\texttt{<} and \\texttt{<=} are reserved to the natural numbers. In the mathematical formulas, we still use $<$ and $\\leq$ for comparing ordinals.\n\\end{remark}\n\n\n\\subsection{Ordinal Notations and Measures for Proving Termination}\n\\label{sect:measure-ON}\n\nThe following lemma (together with the type class mechnism) allows us to use simply  measures towards an ordinal notation. It is just an application of  the libraries \\texttt{Coq.Wellfounded.Inverse\\_Image}\nand  \\texttt{Coq.Wellfounded.Inclusion}. \n\n\\begin{Coqsrc}\nDefinition measure_lt {A:Type}{lt: relation A}\n            {compare : A -> A -> comparison}\n            {on : ON lt compare}\n            {B : Type} (m : B -> A) : relation B :=\n             fun x y => on_lt (m x) (m y).\n            \nLemma wf_measure  {A:Type}(lt: relation A)\n            {compare : A -> A -> comparison}\n            {on : ON lt compare}\n            {B : Type}\n            (m : B -> A):  well_founded (measure_lt m). \n\\end{Coqsrc}\n\nA simple example of application is given in Sect.~\\vref{sect:merge-example}.\n\n\n\\section{Example: The Ordinal \\texorpdfstring{$\\omega$}{omega}}\n\n\n\n\nThe simplest example of ordinal notation is built over the type \\texttt{nat} of \\coq's standard library. We have only to apply already proven lemmas about Peano numbers.\n\n\\vspace{4pt}\n\\noindent\\emph{From Library~\\href{../theories/html/hydras.OrdinalNotations/ON_Omega.html}{OrdinalNotations.ON\\_Omega}}\n\n\n\\begin{Coqsrc}\nGlobal Instance Omega : ON  Peano.lt Nat.compare.\nProof.\n split.\n - apply Nat.lt_strorder.\n - apply Wf_nat.lt_wf.\n - apply Nat.compare_spec.\nQed.\n\nCompute ON_compare 6 9.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n     = Lt\n     : comparison\n\\end{Coqanswer}\n\n\\section{Sum of  Ordinal Notations}\n\nLet \\texttt{NA} and \\texttt{NB} be two ordinal notations, on the respective types \\texttt{A} and \\texttt{B}.\n\n We consider a new strict order\non the disjoint sum of the associated types, by putting all elements of \\texttt{A} before the elements of \\texttt{B} (thanks to Standard Library's relation operator \\texttt{le\\_AsB}).\n\n\n\\noindent\n\\emph{From Library~\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Relations.Relation_Operators.html}{Relations.Relation\\_Operators}}.\n\n\\begin{Coqanswer}\nInductive\nle_AsB (A B : Type) (leA : A -> A -> Prop) (leB : B -> B -> Prop)\n  : A + B -> A + B -> Prop :=\n| le_aa : forall x y : A, leA x y -> le_AsB A B leA leB (inl x) (inl y)\n| le_ab : forall (x : A) (y : B), le_AsB A B leA leB (inl x) (inr y)\n| le_bb : forall x y : B, leB x y -> le_AsB A B leA leB (inr x) (inr y)\n\\end{Coqanswer}\n\n\n\\vspace{4pt}\n\\noindent\\emph{From Library~\\href{../theories/html/hydras.OrdinalNotations/ON_plus.html}{OrdinalNotations.ON\\_plus}}\n\n\n\\begin{Coqsrc}\nSection Defs.\n\n  Context `(ltA: relation A)\n          (compareA : A -> A -> comparison)\n          (NA: ON ltA compareA).\n  Context `(ltB: relation B)\n          (compareB : B -> B -> comparison)\n          (NB: ON ltB compareB).\n\n\nDefinition t := (A + B)%type.\nArguments inl  {A B} _.\nArguments inr  {A B} _.\n\nDefinition lt : relation t := le_AsB _ _ ltA ltB.\n\\end{Coqsrc}\n\nBefore building an instance of \\texttt{ON}, we have to define a comparison function.\n\n\n\\begin{Coqsrc}\nDefinition compare (alpha beta: t) : comparison :=\n   match alpha, beta with\n     inl _, inr _ => Lt\n   | inl a, inl a' => compareA a a'\n   | inr b, inr b' => compareB b b'\n   | inr _, inl _ => Gt\n  end.\n\nLemma compare_correct alpha beta :\n    CompareSpec (alpha = beta) (lt alpha beta) (lt beta alpha)\n                            (compare alpha beta).\n\\end{Coqsrc}\n\nThe Lemma \\texttt{Wellfounded.Disjoint\\_Union.wf\\_disjoint\\_sum} of Standard Library\nhelps us to prove that our order \\texttt{lt} is well-founded.\n\n\n\\begin{Coqsrc}\nGlobal Instance ON_plus : ON lt compare.\nProof.\n  split.\n  - apply lt_strorder.\n  -  apply lt_wf.\n  - apply compare_correct.\nQed.\n\\end{Coqsrc}\n\n\n\n\n\n\n\\subsection{The Ordinal \\texorpdfstring{$\\omega+\\omega$}{omega + omega}}\n\nThe ordinal $\\omega+\\omega$ (also known as $\\omega\\times 2$) may be represented as the concatenation \nof two copies of $\\omega$ (Figure~\\ref{fig:omega-plus-omega}).\n\n\\begin{figure}[h]\n   \\centering\n   \\begin{tikzpicture}[very thick, scale=0.5]\n\\begin{scope}[color=blue]\n\\node(A0) at (2,0)[label=below:$0$]{$\\bullet$};\n\\node(A1) at (3,0)[label=below:$1$]{$\\bullet$};\n\\node(A2) at (4,0)[label=below:$2$]{$\\bullet$};\n\\node (Adots) at (6,0) {$\\ldots$};\n\\node(An) at (8,0)[label=below:$n$]{$\\bullet$};\n\\node(A2) at (10,0)[label=below:$n+1$]{$\\bullet$};\n\\node (Adots1) at (12,0) {$\\ldots$};\n\\end{scope}\n\\begin{scope}[color=red]\n\\node(B0) at (14,0)[label=below:$0$,label=above:\\textcolor{red}{$\\omega$}]{$\\bullet$};\n\\node(B1) at (16,0)[label=below:$1$, label=above:$\\omega+1$]{$\\bullet$};\n\\node(B2) at (18,0)[label=below:$2$,label=above:$\\omega+2$]{$\\bullet$};\n\\node (Bdots) at (20,0) {$\\ldots$};\n\\node (Bn) at (22,0) [label=below:$p$, label=above:$\\omega+p$]{$\\bullet$};\n\\node (Bdots2) at (24,0) {$\\ldots$};\n\\end{scope}\n\\end{tikzpicture}\n   \\caption{\\textcolor{blue}{$\\omega+{\\color{red}\\omega}$}}\n   \\label{fig:omega-plus-omega}\n \\end{figure}\n\nWe can define this notation in \\coq{} as an instance of \\texttt{ON\\_plus}.\n\n\n\\vspace{4pt}\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Omega_plus_omega.html}{OrdinalNotations.ON\\_Omega\\_plus\\_omega}}\n\n\\begin{Coqsrc}\nDefinition Omega_plus_Omega := ON_plus Omega Omega.\n\nExisting Instance Omega_plus_Omega.\nDefinition t := @ON_plus.t nat nat.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nExample ex1 : inl 7 o< inr 0.\nProof. constructor. Qed.\n\\end{Coqsrc}\n\nWe can now define abbreviations. For instance, the finite ordinals are represented by terms built with  the constructor \\texttt{inl}, and the first infinite ordinal $\\omega$ by the term \\texttt{(inr 0)}.\n\n\\begin{Coqsrc}\nDefinition fin (i:nat) : t := inl i.\nCoercion fin : nat >-> t.\n\nNotation \"'omega'\" := (inr  0:t).\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nExample ex1' : fin 7 o< omega.\nProof. constructor. Qed.\n\nLemma lt_omega alpha : \n     alpha o< omega <-> exists n:nat,  alpha = fin n.\n(* ... *)\n\\end{Coqsrc}\n\n\n% \\label{warning:coercions}\n% \\index{Coq!Techniques!Coercions} \n% \\begin{remark}\n% Beware of coercions and notation scopes!\n% Let us consider the following goal:\n\n% \\begin{Coqsrc}\n%  Goal (6 o< 8).\n%  auto with arith.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqanswer}\n% 1 subgoal (ID 9)\n  \n%   ============================\n%   6 o< 8\n% \\end{Coqanswer}\n\n% Please keep in mind that the current notation scope interprets the infix \\texttt{``<''} as the predicate \\texttt{Omega\\_plus\\_omega.lt} and not \\texttt{Nat.lt}. More,  the coercion mechanism converts the terms \\texttt{6:nat} [resp. \\texttt{8:nat} ]\n% into \\texttt{inl 6} [resp. \\texttt{inl 8}].  So, the initial goal is correctly interpreted by \\coq{}, but not as an inequality between two natural numbers.\n\n\n% \\begin{Coqsrc}\n% Set Printing All.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% 1 subgoal (ID 337)\n  \n%   ============================\n%   @on_lt nat Peano.lt Nat.compare Omega (S (S (S (S (S (S O))))))\n%     (S (S (S (S (S (S (S (S O))))))))\n% \\end{Coqanswer}\n\n\n% Anyway, the initial goal is provable, using \\texttt{le\\_AsB}'s first constructor.\n\n% \\begin{Coqsrc}\n%   constructor; auto with arith.\n% Qed.\n% \\end{Coqsrc}\n\n% \\end{remark}\n%\n\n\n\n\\section{Limits and Successors}\n\nLet us look again at our implementation of $\\omega+\\omega$. We can distinguish between the three kinds of ordinals seen in Fig~\\ref{fig:ordinal-sequence}:\n\n\\begin{itemize}\n\\item The least ordinal, \\texttt{(inl 0)}, also written \\texttt{(fin 0)}.\n\\item The limit ordinal $\\omega$.\n\\item The successor ordinals, either of the form \\texttt{(inl (S $i$))} or \\texttt{(inr (S $i$))}\n\\end{itemize}\n\n\\subsection{Definitions}\nIt would be interesting to specify at the most generic level, what is a zero, a successor or a limit ordinal. Let $<$ be a strict order on a type $A$.\n\n\\begin{itemize}\n\\item A \\emph{least} element is a minorant (in the large sense) of the full set  on $A$,\n\\item $y$ is a \\emph{successor} of $x$ if $x<y$ and there is no element between $x$ and $y$. We will also say that $x$ is a \\emph{predecessor} of $y$.\n\\item $x$ is a \\emph{limit} if $x$ is not a least element, and for any $y$ such that $yo<x$,\n there exists some $z$ such that $y<z<x$.\n\\end{itemize}\n\n\nThe following definitions are in Library \\href{../theories/html/hydras.Prelude.MoreOrders.html}{Prelude.MoreOrders}.\n\n\\begin{Coqsrc}\nSection A_given.\n  Variables (A : Type)  (lt: relation A).\n  \nLocal Infix \"<\" := lt.\nLocal Infix \"<=\" := (clos_refl _ lt).\n\nDefinition Least {sto : StrictOrder lt} (x : A):=\n  forall y,  x <= y.\n\nDefinition Successor {sto : StrictOrder lt} (y x : A):=\n  x < y /\\ (forall z,  x < z ->  z <  y -> False).\n\nDefinition Limit {sto : StrictOrder lt}  (x:A)  :=\n  (exists w:A,  w < x) /\\\n  (forall y:A, y < x -> exists z:A, y < z /\\ z < x).\n\\end{Coqsrc}\n\n\\index{Exercises}\n\\begin{exercise}\nProve, that, in any ordinal notation system, that every ordinal has at most one predecessor, and at most one successor. \n\\end{exercise}\n\n\\index{Exercises}\n\\begin{exercise}\nProve, that, in any ordinal notation system, that if $\\beta$ is a successor of $\\alpha$,\nthen for any $\\gamma$, $\\gamma<\\beta$ implies \n$\\gamma\\leq\\alpha$.\n\\end{exercise}\n\n\n\n\n\\subsection{Limits and Successors in \\texorpdfstring{$\\omega+\\omega$}{omega+omega}}\n\nUsing the definitions above, we can prove the following lemma:\n\n\\vspace{4pt}\n\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Omega_plus_omega.html}{OrdinalNotations.ON\\_Omega\\_plus\\_omega}}\n\n\\begin{Coqsrc}\nLemma limit_iff (alpha : t) : Limit alpha <-> alpha = omega.\n\\end{Coqsrc}\n\nRegarding successors, let us introduce the following definition:\n\n\\begin{Coqsrc}\nDefinition succ (alpha : t) :=\n  match alpha with\n    inl n => inl (S n)\n  | inr n => inr (S n)\n  end.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma Successor_correct alpha beta : Successor beta alpha <->\n                                     beta = succ alpha.\n\\end{Coqsrc}\n\nWe can also check whether an ordinal is a successor by a simple pattern matching:\n\n\\begin{Coqsrc}\nDefinition succb (alpha: t) : bool := match alpha with\n                                 | inr (S  _) | inl (S _) => true\n                                 | _ => false\n                                 end.\n\nLemma succb_correct (alpha : t) :\n    succb alpha <->  exists beta: t, alpha = succ beta.\n\\end{Coqsrc}\n\n\nFinally, the nature of any ordinal is decidable(inside this notation system) :\n\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.Generic.html}{OrdinalNotations.Generic}}\n\\begin{Coqsrc}\n  Definition ZeroLimitSucc_dec {A:Type}{lt: relation A}\n           {compare : A -> A -> comparison}\n           {on : ON lt compare} :=\n  forall alpha,\n    {Least alpha} +\n    {Limit alpha} +\n    {beta: A | Successor alpha beta}.\n(* ... *)\n\\end{Coqsrc}\n\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Omega_plus_omega.html}{OrdinalNotations.ON\\_Omega\\_plus\\_omega}}\n\n\\begin{Coqsrc}\nDefinition Zero_limit_succ_dec : ZeroLimitSucc_dec.\n\\end{Coqsrc}\n\n\\section{Product of Ordinal Notations}\n\nLet \\texttt{NA} and \\texttt{NB} be two ordinal notations, on the respective  ordered types \\texttt{A} and \\texttt{B}. The product of \\texttt{NA} and \\texttt{NB} is considered as the concatenation of $B$ copies of $A$, ordered by the lexicographic order on $B\\times A$.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_mult.html}{OrdinalNotations.ON\\_mult}}\n\n\\begin{Coqsrc}\nSection Defs.\n\n  Context `(ltA: relation A)\n          (compareA : A -> A -> comparison)\n          (NA: ON ltA compareA).\n  Context `(ltB: relation B)\n          (compareB : B -> B -> comparison)\n          (NB: ON ltB compareB).\n\nDefinition t := (B * A)%type.\nDefinition lt : relation t := lexico ltB ltA.\nDefinition le := clos_refl _ lt.\n\nDefinition compare (alpha beta: t) : comparison :=\n  match compareB (fst alpha) (fst beta) with\n  |  Eq => compareA (snd alpha) (snd beta)\n  | c => c\n  end.\n\nLemma compare_reflect alpha beta :\n  match (compare alpha beta)\n  with\n    Lt => lt alpha  beta\n  | Eq => alpha = beta\n  | Gt => lt beta  alpha\n  end.\n\nGlobal Instance ON_mult : ON lt compare.\n\nEnd Defs.\n\\end{Coqsrc}\n\n\\section{The Ordinal \\texorpdfstring{$\\omega^2$}{omega^2}}\n\nThe ordinal $\\omega^2$ (also called $\\phi_0(2)$, see Chap.~\\ref{chap:schutte}), is an instance of the multiplication presented in the last section.\n\n\\vspace{4pt}\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Omega2.html}{OrdinalNotations.ON\\_Omega2}}\n\n\\begin{Coqsrc}\nDefinition Omega2 := ON_mult Omega Omega.\nExisting Instance Omega2.\nDefinition t := ON_mult.t nat nat.\n\\end{Coqsrc}\n\n\n\n\\begin{Coqsrc}\nDefinition zero: t := (0,0).\n\nDefinition fin (n:nat) : t := (0, n).\n\nCoercion fin : nat >-> t.\n\nNotation \"'omega'\" := (1,0) : ON_scope.\n\nDefinition limitb (alpha : t) := \n match alpha with\n |  (S _, 0) => true\n | _ => false\nend.\n\\end{Coqsrc}\n\n\n\n\n\\subsection{Arithmetic of \\texorpdfstring{$\\omega^2$}{omega^2}} \n\n\\subsubsection{Successor}\n\nThe successor of any ordinal is defined by a simple pattern-matching.\nThis function is proved to be correct w.r.t. the \\texttt{Successor} predicate.\n\n\\begin{Coqsrc}\nDefinition succ (alpha : t) := (fst alpha, S (snd alpha)).\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma lt_succ_le alpha beta : alpha o< beta <-> succ alpha o<= beta.\n\nLemma lt_succ alpha : alpha o< succ alpha.\n\nLemma succ_ok alpha beta : Successor beta alpha <-> beta = succ alpha.\n\\end{Coqsrc}\n\n\\subsubsection{Addition}\n\nWe can define on \\texttt{Omega2} an addition which extends the addition on \\texttt{nat}.\n\n\\begin{Coqsrc}\nDefinition  plus (alpha beta : t) : t :=\n  match alpha,beta with\n  | (0, b), (0, b') => (0, b + b')\n  | (0,0), y  => y\n  | x, (0,0)  => x\n  | (0, b), (S n', b') => (S n', b')\n  | (S n, b), (S n', b') => (S n + S n', b')\n  | (S n, b), (0, b') => (S n, b + b')\n   end.\n\nInfix \"+\" := plus : o2_scope.\n\\end{Coqsrc}\n\nPlease note that this operation is not commutative:\n\n\\begin{Coqsrc}\nExample non_commutativity_of_plus :  omega + 3 <> 3 + omega.\nProof.\n  cbn.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 237)\n  \n  ============================\n(1, 3) <> omega.\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n discriminate.\nQed.\n\\end{Coqsrc}\n\n\n\\subsubsection{Multiplication}\n\nThe restriction of ordinal multiplication to the segment $[0,\\omega^2)$ is not a total function.\nFor instance $\\omega\\times\\omega= \\omega^2$ is outside the set of represented values.\nNevertheless, we can define two operations mixing natural numbers and ordinals.\n\n\\begin{Coqsrc}\n(** multiplication of an ordinal by a natural number *)\n\nDefinition mult_fin_r  (alpha : t) (p : nat): t :=\n  match alpha, p with\n |  (0,0), _  => zero\n |  _, 0 => zero\n |  (0, n), p => (0, n * p)\n |  ( n, b),  n' => ( n *  n', b)\n end.\nInfix \"*\" := mult_fin_r : o2_scope.\n\n(** multiplication of  a natural number by an ordinal *)\n\nDefinition mult_fin_l (n:nat)(alpha : t) : t :=\n  match n, alpha with\n |  0, _  => zero\n |  _, (0,0) => zero\n |   n , (0,n') => (0, (n*n')%nat)\n |  n, (n',p') => (n', (n * p')%nat)\n end.\n\nExample e1 : (omega * 7 + 15) * 3 = omega * 21 + 15.\nProof. reflexivity. Qed.\n\nExample e2 :  mult_fin_l 3 (omega * 7 + 15) = omega * 7 + 45.\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\nMultiplication with a finite ordinal and addition are related through the following lemma:\n\n\\begin{Coqsrc}\nLemma unique_decomposition alpha : \n    exists! i j: nat,  alpha = omega * i + j.\n\\end{Coqsrc}\n\n\\subsection{A Proof of Termination using \\texorpdfstring{$\\omega^2$}{omega^2}} \n\\label{sect:merge-example}.\n\nUsing the lemma of Sect.~\\vref{sect:measure-ON}, we can define easily a total function which merges two lists.\n\n\\index{Coq!Commands!Function}\n\n\\begin{Coqsrc}\n(* adapted from Pascal Manoury et al. *)\n\n\nRequire Import Coq.Program.Wf List.\nRequire Import FunInd Recdef.\n\nSection Merge.\n\n  Variable A: Type.\n\n  Local Definition m (p : list A * list A) :=\n    omega * length (fst p) + length (snd p).\n\n  Function  merge  (ltb: A -> A -> bool)\n          (xys: list A * list A)\n          {wf (measure_lt m) xys} :\n    list A :=\n    match xys with\n      (nil, ys) => ys\n    | (xs, nil) => xs\n    | (x :: xs, y :: ys) =>\n      if ltb x y then x :: merge  ltb (xs, (y :: ys))\n      else y :: merge  ltb ((x :: xs), ys)\n    end.\n\n  - intros; unfold m, measure_lt; cbn; destruct xs0; simpl; left; lia.\n  - intros; unfold m, measure_lt; cbn; destruct ys0; simpl; right; lia.\n   - auto.\n  Defined.\n\nEnd Merge.\n\nGoal forall l, merge nat Nat.leb (nil, l) = l.\n  intro; now rewrite merge_equation.\nQed.\n\\end{Coqsrc}\n \n\n\\subsection{Yet Another  Proof of Impossibility}\n\\label{omega2-case}\n\nIn Sect.~\\vref{omega-case}, we proved that there exists no variant towards \\texttt{nat}\n(\\emph{i.e.} the ordinal $\\omega$) for proving the termination of all hydra battles.\nWe  prove now that  the ordinal $\\omega^2$ is also insufficient for this purpose. \n\nThe proof we are going to develop has exactly the same structure as in Section~\\ref{omega-case}.\n Nevertheless, the proof of technical  lemmas is a little more complex, due to \n the structure of the lexicographic order on $\\mathbb{N}\\times\\mathbb{N}$. \nConsider for instance that there exists an infinite number of ordinals  between\n$\\omega$ and $\\omega\\times 2$.\n\n\n\nThe detailed  proof script is in the file \\url{../theories/html/hydras.Hydra.Omega2_Small.html}.\n\n\\subsubsection{Preliminaries}\nLet us assume there is a variant from \\texttt{Hydra} into $\\omega^2$  for proving the   termination of all hydra battles.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Omega2_Small.html}{Hydra.Omega2\\_Small}}\n\n\n\\begin{Coqsrc}\nSection Impossibility_Proof.\n  \n Variable m : Hydra -> ON_Omega2.t.\n  \n Context (Hvar : Hvariant (Generic.wf (ON:=Omega2))  free m).\n\\end{Coqsrc}\n\n\nLet us follow the same pattern as in Sect.~\\ref{omega-case}.\nFirst, we define an injection $\\iota$ from type \\texttt{t} into \\texttt{Hydra}, by\n associating to  each ordinal $\\omega\\times i+ j = (i,j)$ the hydra with $i$ branches of length $2$ and\n$j$ branches of length $1$.\n\n%% revenir ici\n\n\\vspace{4pt}\n\\emph{From Module ~\\href{../theories/html/hydras.Hydra.Omega2_Small.html\\#iota}{Hydra.Omega2\\_Small}}\n\n\\begin{Coqsrc}\n Let iota (p: ON_Omega2.t) := \n     node (hcons_mult (hyd1 head) (fst p)\n                                     (hcons_mult head (snd p) hnil)).\n  \\end{Coqsrc}\n\nFor instance, Figure~\\vref{fig:essai2} shows the hydra associated to the ordinal \n$(3,5)$, a.k.a. $\\omega\\times 3 + 5$.\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.4]\n\\node (foot) at (6,0) {$\\bullet$};\n\\node (N1) at (1,3) {$\\bullet$};\n\\node (N2) at (3,3) {$\\bullet$};\n\\node (N3) at (5,3) {$\\bullet$};\n\\node (N4) at (8,3) {$\\Smiley[2][green]$};\n\\node (N5) at (11,3) {$\\Smiley[2][green]$};\n\\node (N6) at (14,3) {$\\Smiley[2][green]$};\n\\node (N7) at (17,3){$\\Smiley[2][green]$};\n\\node (N8) at (20,3){$\\Smiley[2][green]$};\n\\node  (N9) at (0,5) {$\\Smiley[2][green]$};\n\\node (N10) at (2,5) {$\\Smiley[2][green]$};\n\\node (N11) at (4,5) {$\\Smiley[2][green]$};\n\\draw (foot) to [bend left=10] (N1);\n\\draw (foot) -- (N2);\n\\draw (foot) -- (N3);\n\\draw (foot) -- (N4);\n\\draw (foot) -- (N5);\n\\draw (foot) -- (N6);\n\\draw (foot) to [bend right=10] (N7);\n\\draw (foot) to [bend right=15] (N8);\n\\draw (N1) to [bend left=10] (N9);\n\\draw (N2) -- (N10);\n\\draw (N3) -- (N11);\n\\end{tikzpicture}\n\\caption{\\label{fig:essai2}\nThe hydra $\\iota(\\omega\\times 3+5)$}\n\\end{figure}\n\n\n\n\nLike in Sect.~\\ref{omega-case}, we build a hydra out of the range of \\texttt{iota} (represented in Fig.~\\vref{fig:h-omega2-small}).\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5]\n\\node (foot) at (2,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (3,4) {$\\Smiley[2][green]$};\n\\node (N3) at (1,4) {$\\Smiley[2][green]$};\n\\draw (foot) -- (N1);\n\\draw (N1) to [bend right =15] (N2);\n\\draw (N1) to  [bend left=15](N3);\n\\end{tikzpicture}\n\\caption{\\label{fig:h-omega2-small}}\n The hydra \\texttt{big\\_h}.\n\\end{figure}\n\n\n\\begin{Coqsrc}\n   Let big_h := hyd1 (hyd2 head head).  \n\\end{Coqsrc}\n \n In a second step, we build a ``smaller'' hydra.\n \n\\begin{Coqsrc}\n   Let small_h := iota (m big_h).\n\\end{Coqsrc}\n\nLike in Sect.~\\ref{omega-case}, we prove the double inequality \\texttt{m big\\_h o<= m small\\_h o< m big\\_h}, which is impossible.\n\n\\subsubsection{Proof of the Inequality \\texttt{m small\\_h o< m big\\_h}}\n\nIn order to prove the inequality  \\texttt{m\\_lt: m small\\_h o< m big\\_h}, it suffices to\nbuild a battle transforming \\texttt{big\\_h} into \\texttt{small\\_h}.\n\nFirst we prove that \\texttt{small\\_h} is reachable from \\texttt{big\\_h} in one or two steps. Let us decompose \\texttt{m big\\_h} as $(i,j)$.\nIf $j=0$, then one round suffices to transform \\texttt{big\\_h} into $\\iota(i,j)$.\nIf $j>0$, then a first round transforms \\texttt{big\\_h} into $\\iota(i+1,0)$ and a second round into $\\iota(i,j)$. So, we have the following result.\n\n\\begin{Coqsrc}\n  Lemma big_to_small: big_h -+-> small_h.\n\\end{Coqsrc}\n\nSince $m$ is a variant, we infer the following inequality:\n\n\\begin{Coqsrc}\n   Corollary m_lt : m small_h o< m big_h.\n\\end{Coqsrc}\n\n\n\\subsubsection{Proof of the Inequality \\texttt{m big\\_h o<= m small\\_h} }\n\n\nThe proof of the inequality \\texttt{m big\\_h o<= m small\\_h} is quite more complex than in Sect~\\ref{omega-case}.  If we consider any ordinal $\\alpha=(i,j)$, where $i>0$, there exists an infinite number of\nordinals stricly less than $\\alpha$, and there exists an infinite number of battles that start from\n$\\iota(\\alpha)$. Indeed, at any configuration $\\iota(k,0)$, where $k>0$, the hydra can freely choose any replication number. Intuitively, the measure of such a hydra must be large enough for taking into account\nall the possible battles issued from that hydra.\nLet us now give more technical details.\n\n\\begin{itemize}\n\\item The proof of the lemma \\texttt{m\\_ge : m big\\_h  o<= m small\\_h} uses well-founded induction on \\texttt{big\\_h}.\n\n\\item For any pair $p$, we have to distinguish between three cases, according to the value of $p$'s components.\n  \\begin{itemize}\n  \\item $p=(0,0)$\n  \\item $p=(i,0)$, where $i>0$\\,: $p$ corresponds to a limit ordinal\n  \\item $p=(i,j)$, where $j>0$\\,: $p$ is the successor of $(i,j-1)$.\n  \\end{itemize}\n\\end{itemize}\n\n\nLet us define the notion of elementary ``step'' of decreasing sequences in\n\\texttt{t}\n\n\n\\begin{Coqsrc}\n  Inductive step : t -> t -> Prop :=\n  | succ_step : forall i j,  step (i, S j) (i, j)\n  | limit_step : forall i j, step (S i, 0) (i, j).\n\\end{Coqsrc}\n\nThe following lemma establishes a correspondance between the relation\n\\texttt{step} and hydra battles.\n\n\\begin{Coqsrc}\n  Lemma step_to_battle : forall p q, step p q -> iota p -+-> iota q.\n\\end{Coqsrc}\n\n\\index{Maths!Transfinite induction}\n\nThus, starting from any inequality $q < p$ on type \\texttt{t}, we can build \nby \\emph{transfinite induction} (\\emph{i.e.} well-founded) over \\texttt{p} a battle \nthat transforms the hydra $\\iota(p)$ into $\\iota(q)$.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Omega2_Small.html\\#m_ge}{Hydra.Omega2\\_Small}}\n\n\\begin{Coqsrc}\n  Lemma m_ge : forall p : t,   p o<= m (iota p).\n  Proof.\n    unfold small_h; pattern (m big_h) .   \n     apply  well_founded_induction with (R := lt) (1:= lt_wf).\n     intro p ; pattern p;\n     apply  well_founded_induction with \n               (R := lt2) (1:= wf_lexico lt_wf lt_wf);\n     intros (i,j) IHij. \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  i, j : nat\n  IHij : forall y : t, y o< (i, j) -> y o<= m (iota y)\n  ============================\n  (i, j) o<= m (iota (i, j)) \n\\end{Coqanswer}\n\n\nThen we have  three cases to consider, according to the value of $p$.\n\\begin{itemize}\n\\item If $p=(0,0)$ then obviously, $\\iota(p)\\geq p = (0,0)$\n\\item If  $p=(i+1,0)$ for some $i\\in\\mathbb{N}$, we\n remark  that $p$ is strictly greater than any pair $ (i, j)$, where $j$ \nis any natural number.\n\nApplying the battle rules, for any $j$, we have $\\iota(i+1,j)  {\\round} \\iota(i, j) $, thus $m(\\iota(p)) > m(\\iota(i,j)$ since  $m$ is assumed to be a variant.\n\nApplying the induction hypothesis, we get the inequality\n $ m(\\iota(i,j)) \\geq (i,j)$ for any $j$. \n\nThus, $m(\\iota(p)) > (i,j)$ for any $j$.\nApplying the lemma \\texttt{limit\\_is\\_lub}, we get  the inequality\n$m(\\iota(i+1,0))\\geq (i+1,0)$\n\n\\item If $p=(i,j+1)$ with $j\\in\\mathbb{N}$, we have  $\\iota(p)  {\\round} \\iota(i, j) $,\nhence $m(\\iota(p))> m(\\iota(i,j)) \\geq (i,j)$, thus $m(\\iota(p))\\geq (i,j+1)=p$\n\n\\end{itemize}\n\n\\begin{Coqsrc}\n  (* ... *)\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{End of the Proof}\nFrom \\texttt{m\\_ge}, we get \\texttt{m big\\_h o<= m small\\_h = m (iota (m big\\_h)) }. \nSince $<$ is a strict order (irreflexive  and transitive), this inequality is incompatible with the strict inequality  \\texttt{m small\\_h o< m big\\_h} (lemma \\texttt{m\\_lt}).\n\n\n\\vspace{4pt}\n\\noindent\nIn \\coq (Module~\\href{../theories/html/hydras.Hydra.Omega2_Small.html\\#Impossible}{Hydra.Omega2\\_Small}):\n\n\\begin{Coqsrc}\n  Theorem Impossible: False.\n  Proof.\n    destruct (StrictOrder_Irreflexive (m big_h)).\n    apply le2_lt2_trans with (m small_h).\n    -  unfold small_h; apply m_ge.\n    -  apply m_lt. \nQed. \nEnd Impossibility_Proof.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\nProve that there exists no variant $m$ from \\texttt{Hydra} into $\\omega^2$ for proving\n    the  termination of all \\emph{standard} battles.\n\\end{exercise}\n\n\n\n\\begin{remark}\nIn Chapter~\\ref{ks-chapter}, we  prove a generalization of the impossibility lemmas of\nSect.~\\ref{omega-case} and this section, with the same proof structure, but with much more \ncomplex technical details.\n \\end{remark}\n\n% \\index{Exercises}\n% \\begin{exercise}\n\n% \\label{sec:orgheadline63}\n% Write \\emph{direct} proofs ({i.e.},  without applying the result and tools of Chap.~\\ref{ks-chapter}) that the following data structures  are too simple for defining a variant for any hydra battle.\n\n% \\begin{itemize}\n% \\item  $\\omega^n$ : the set of all $n$-uples of natural numbers, ordered  by \n%   lexicographic ordering\n% \\item  $\\omega^\\omega$: the set of all decreasing sequences (with respect to $\\le$)  of natural numbers, ordered by lexicographic ordering on lists.\n\n% For instance, the following inequality holds:\n% \\[\\langle 4,3,3,3,3,3,3,2,2,2 \\rangle\\,<\\,\\langle 4,4,2 \\rangle\\]\n% \\end{itemize}\n\n  \n% \\end{exercise}\n\n\n\\section{A Notation for Finite Ordinals}\n\n\nLet $n$ be some natural number. The segment associated with $n$ is the interval \n$[0,n)\\,=\\,\\{0,1,\\dots,n-1\\}$. \nOne may represent the ordinal $n$ by a sigma type.\n\n\n\\vspace{4pt}\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Finite.html}{OrdinalNotations.ON\\_Finite}}\n\n\\label{def: Finite-ord-type}\n\\begin{Coqsrc}\nCoercion is_true: bool >-> Sortclass.\n\nDefinition t (n:nat) := {i:nat | Nat.ltb i n}.\n\\end{Coqsrc}\n\nThe order on type (\\texttt{t $n$}) is defined through the projection on \\texttt{nat}.\n\n\n\\begin{Coqsrc}\nDefinition lt {n:nat} : relation (t n) :=\n  fun alpha beta => Nat.ltb ( proj1_sig alpha) (proj1_sig beta).\n\\end{Coqsrc}\n\nFor instance, let us build two elements of the segment $[0, 7)$, \\emph{i.e.} two\ninhabitants of   type (\\texttt{t 7}), and prove a simple  inequality (see Fig.~\\ref{fig:O7}).\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.6]\n\n\\node (N0) at (0,0) {$\\bullet$};\n\\node (i0) at (0,1) {$0$};\n\\node (N1) at (2,0) {$\\bullet$};\n\\node (i1) at (2,1) {$1$};\n\\node (N2) at (4,0) {$\\bullet$};\n\\node (i2) at (4,1) {$2$};\n\\node (N3) at (6,0) {$\\bullet$};\n\\node (i3) at (6,1) {$3$};\n\\node (N4) at (8,0) {$\\bullet$};\n\\node (i4) at (8,1) {$4$};\n\\node (N5) at (10,0) {$\\bullet$};\n\\node (i5) at (10,1) {$5$};\n\\node (N6) at (12,0) {$\\bullet$};\n\\node (i6) at (12,1) {$6$};\n\\node(alpha1) at (4,-1) {$\\alpha_1$};\n\\node(alpha2) at (10,-1) {$\\beta_1$};\n\\end{tikzpicture}\n\n\\caption{The segment $\\mathbb{O}_7$\\label{fig:O7}}\n\\end{figure}\n  \n\\index{Coq!Commands!Program}\n\n\\begin{Coqsrc}\nProgram Example alpha1 : t 7 := 2.\n\nProgram Example beta1 : t 7 := 5.\n\nExample i1 : lt  alpha1 beta1.\nProof. now compute. Qed.\n\\end{Coqsrc}\n\n\n\n\nNote that the type (\\texttt{t 0}) is empty, and that, for any natural number\n $n$, $n$ does not belong to (\\texttt{t $n$}).\n\n\\begin{Coqsrc}\nLemma t0_empty (alpha: t 0): False.\nProof.\n  destruct alpha.\n  destruct x; cbn in i; discriminate.\nQed.\n\n\nProgram Definition bad : t 10 := 10.\nNext Obligation.\n  compute.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 162)\n  \n  ============================\n  false = true\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nAbort.\n\\end{Coqsrc}\n\nNote also that attempting to compare a term  of type (\\texttt{t $n$}) with a term of\ntype (\\texttt{t $p$})  leads to an error if $n$ and $p$ are not convertible.\n\n\\begin{Coqsrc}\n\nProgram Example gamma1 : t 8 := 7.\n\nFail Goal lt alpha1 gamma1.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n The command has indeed failed with message:\nThe term \"gamma1\" has type \"t 8\" while it is expected to have type \"t 7\".\n\\end{Coqanswer}\n\n\nIn order to build an instance of \\texttt{OrdinalNotation}, we define a comparison function, by delegation to standard library's  \\texttt{Nat.compare}, and prove its correction.\n\n\\begin{Coqsrc}\nDefinition compare {n:nat} (alpha beta : t n) :=\n  Nat.compare (proj1_sig alpha) (proj1_sig beta).\n\nLemma compare_correct {n} (alpha beta : t n) :\n  CompareSpec (alpha = beta) (lt alpha beta) (lt beta alpha)\n              (compare alpha beta).\n\\end{Coqsrc}\n\n\\begin{remark}\n The proof of \\texttt{compare\\_correct} uses a well-known pattern of \\coq{}.\nLet us consider  the following subgoal.\n\n\\begin{Coqanswer}\n 1 subgoal (ID 110)\n  \n  n, x0 : nat\n  i, i0 : x0 <? S n\n  ============================\n  exist (fun i1 : nat => i1 <=? n) x0 i =\n  exist (fun i1 : nat => i1 <=? n) x0 i0\n\\end{Coqanswer}\n\nApplying the tactic \\texttt{f\\_equal} generates a simpler subgoal.\n\n\\begin{Coqanswer}\n1 subgoal (ID 112)\n  \n  n, x0 : nat\n  i, i0 : x0 <? S n\n  ============================\n  i = i0\n\\end{Coqanswer}\n\nWe have now to prove that there exists at most one  proof of (\\texttt{Nat.ltb x0 (S n)}). This is not obvious, but  a consequence of the following lemma of library \n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Logic.Eqdep_dec.html}{Coq.Logic.Eqdep\\_dec}.\n\n\\index{Coq!Techniques!Unicity of equality proofs}\n\\label{sect:eq-proof-unicity}\n\n\\begin{Coqanswer}\neq_proofs_unicity_on :\nforall (A : Type) (x : A),\n(forall y : A, x = y \\/ x <> y) -> \nforall (y : A) (p1 p2 : x = y), p1 = p2\n\\end{Coqanswer}\n\nThus unicity of proofs of \\texttt{Nat.ltb x0 (S n)}  comes from the decidability of\nequality on type \\texttt{bool}.\nThis is why we used the boolean function \\texttt{Nat.ltb} instead of the inductive predicate \\texttt{Nat.lt} in the definition of type \\texttt{t $n$} (see page~\\pageref{def: Finite-ord-type}).\nFor more information about this pattern, please look at the numerous mailing lists and \nFAQs on \\coq{}).\n\n\n\n\\end{remark}\n\n\nApplying lemmas of the libraries \\texttt{Coq.Wellfounded.Inverse\\_Image}, \\linebreak\n \\texttt{Coq.Wellfounded.Inclusion}, and \\texttt{Coq.Arith.Wf\\_nat}, we prove that our\nrelation \\texttt{lt} is well founded.\n\n\\begin{Coqsrc}\nLemma lt_wf (n:nat) : well_founded (@lt n).\n\\end{Coqsrc}\n\nNow we can build our instance of \\texttt{OrdinalNotation}.\n\n\\begin{Coqsrc}\nGlobal Instance sto n : StrictOrder (@lt n).\n\nGlobal Instance FinOrd (n:nat) : OrdinalNotation (sto n) compare.\nProof.\n  split.\n  - apply compare_correct.\n  - apply lt_wf.\nQed.\n\\end{Coqsrc}\n\n\\begin{remark}\nIt is important to keep in mind  that the integer $n$ is not an ``element'' of \\texttt{FinOrd $n$}. In set-theoretic presentations of ordinals, the set associated with the ordinal $n$ is $\\{0,1,\\dots,n-1\\}$. \nIn our formalization, the interpretation of an ordinal as a set is realized by the following definition\n(in ~\\href{../theories/html/hydras.OrdinalNotations.Generic.html}{OrdinalNotations.Generic}).\n\n\\begin{Coqsrc}\nDefinition bigO `{nA : @OrdinalNotation A ltA stoA compareA}\n           (a: A) : Ensemble A :=\n  fun x: A => ltA x a.\n\\end{Coqsrc}\n\\end{remark}\n\n\n\\begin{remark}\n There is no interesting arihmetic on finite ordinals, since functions like successor, addition, etc.,  cannot be represented in \\coq{} as \\emph{total} functions.\n\\end{remark}\n\n\\begin{remark}\nFinite ordinals are also formalized in MathComp~\\cite{SSR}.  See also Adam Chlipala's \\emph{CPDT}~\\cite{chlipalacpdt2011} for a thorough study of the use of dependent types.  \n\\end{remark}\n\n\n\n%%%\n\n\\section{Comparing two Ordinal Notations}\n\nIt is sometimes useful to compare two ordinal notations with respect to expressive power\n(the segment of ordinals  they represent). \n\nThe following class specifies a strict inclusion of segments. The notation \\texttt{OA} describes a segment $[0,\\alpha($, and \\texttt{OB} is a larger segment (which contains a notation for $\\alpha$, whilst $\\alpha$ is not represented in \\texttt{OA}). We require also  that the comparison functions of the two notation systems are compatible.\n\nIf \\texttt{OB} is presumed to be correct, the we can consider that \\texttt{OA} ``inherits'' its correcteness from the bigger notation system \\texttt{OB}.\n\n\n\\label{types:SubON}\n\n\\begin{Coqsrc}\nClass  SubON \n       `(OA : @ON A ltA  compareA)\n       `(OB : @ON B ltB  compareB)\n       (alpha :  B)\n       (iota : A -> B):=\n  {\n  SubON_compare: forall x y : A,  compareB (iota x) (iota y) =\n                                 compareA x y;\n  SubON_incl : forall x, ltB (iota x) alpha;\n  SubON_onto : forall y, ltB y alpha  -> exists x:A, iota x = y}.\n\\end{Coqsrc}\n\nFor instance, we prove that \\texttt{Omega} is a sub-notation of\n\\texttt{Omega\\_plus\\_Omega} (with $\\omega$ as the first ``new'' ordinal, and \\texttt{fin} as the injection).\n\n\\begin{Coqsrc}\nInstance Incl : SubON Omega Omega_plus_Omega omega fin.\n\\end{Coqsrc}\n\n\n\nWe can also show that, if $i<j$, then the segment $[0,i)$ is a ``sub-segment'' of\n$[0,j)$. Since the terms  ($t\\;i$) and ($t\\;j$) are not convertible, we consider a ``cast'' \nfunction $\\iota$ from ($t\\;i$) into ($t\\;j$), and prove that this function is  a monotonous bijection  from ($t\\;i$) to\nthe segment $[0,i)$ of ($t\\;j$).\n\n\n\n\n \\begin{figure}[h]\n   \\centering\n   \\begin{tikzpicture}[very thick, scale=0.6]\n\\begin{scope}[color=blue]\n\\node (A) at (0,0) {$A$};\n\\node(A0) at (2,0)[label=below:$0$]{$\\bullet$};\n\\node(A1) at (3,0)[label=below:$1$]{$\\bullet$};\n\\node(A2) at (4,0)[label=below:$2$]{$\\bullet$};\n\\node (Adots) at (6,0) {$\\ldots$};\n\\end{scope}\n\\begin{scope}[color=red]\n\\node (B) at (0,2) {$B$};\n\\node(B0) at (2,2)[label=above:$0$]{$\\bullet$};\n\\node(B1) at (3,2)[label=above:$1$]{$\\bullet$};\n\\node(B2) at (4,2)[label=above:$2$]{$\\bullet$};\n\\node (Bdots) at (6,2) {$\\ldots$};\n\\node (b) at (8,2) [label=above:$b$]{$\\bullet$};\n\\node (bsucc) at (9,2) [label=above:$b+1$]{$\\bullet$};\n\\node (Bdots2) at (10,2) {$\\ldots$};\n\\end{scope}\n\\begin{scope}[color=red!50!blue]\n\\draw [->,thin] (A0) -- node [auto] {$\\iota$} (B0);\n\\draw [->,thin] (A1) -- node [auto] {$\\iota$} (B1);\n\\draw [->,thin] (A2) -- node [auto] {$\\iota$} (B2);\n\\draw [->,thin] (Adots) -- node [auto] {$\\iota$} (Bdots);\n\\end{scope}\n\\end{tikzpicture}\n   \\caption{\\textcolor{blue}{$A$} is a sub-segment  of \\textcolor{red}{$B$}}\n   \\label{fig:subsegment}\n \\end{figure}\n\n\n\n\n\\index{Coq!Commands!Program}\n\nWe are now able to build an instance of \\texttt{SubON}. \n\n\\vspace{4pt}\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.OrdinalNotations.ON_Finite.html}{OrdinalNotations.ON\\_Finite}}\n\n\\begin{Coqsrc}\nSection Inclusion_ij.\n\n  Variables i j : nat.\n  Hypothesis Hij : (i < j)%nat.\n\n  Remark Ltb_ij : Nat.ltb i j.\n\n  Program Definition iota_ij  (alpha: t i) : t j :=  alpha.\n \n   Let b : t j := exist _ i Ltb_ij.\n   \n   Global Instance F_incl_ij  : SubON  (FinOrd i) (FinOrd j) b iota_ij.\n  (* ... *)\n\n  End Inclusion_ij.\n\\end{Coqsrc}\n         \n\n\n\\index{Exercises}\n\\begin{exercise}\nProve that \\texttt{Omega\\_plus\\_Omega} cannot be a sub-notation of \\texttt{Omega}.\n\\end{exercise}\n\n\\index{Projects}\n\\begin{project}\nAdapt the definition of \\texttt{Hvariant} (Sect.~\\ref{sect:hvariant-def}) in order to\nhave an ordinal notation as argument. Prove that if $O_A$ is a sub-notation of $O_B$, then any variant defined on  $O_A$ can be automatically transformed into \na variant on $O_B$.\n\\end{project}\n\n\n\n\n\\section{Comparing an Ordinal Notation with Schütte's Model}\n\nFinally, it may be interesting to compare an ordinal notation with the more theoretical model from Schütte (well, at least with our formalization of that model). This would be a relative proof of correctenss of the considered  ordinal  notation.\n\nThe following class specifies that a notation \\texttt{OA} describes a segment $[0,\\alpha)$,\nwhere $\\alpha$ is a countable ordinal \\emph{à la}  Schütte.\n\n\n\\label{types:ON-for}\n\n\\begin{Coqsrc}\nClass ON_correct `(alpha : Schutte_basics.Ord)\n     `(OA : @ON A ltA  compareA)\n      (iota : A -> Schutte_basics.Ord) :=\n  { ON_correct_inj : forall a, Schutte_basics.lt (iota a) alpha;\n    ON_correct_onto : forall beta, Schutte_basics.lt beta alpha ->\n                                exists b, iota b = beta;\n    On_compare_spec : forall a b:A,\n        match compareA a b with\n          Datatypes.Lt => Schutte_basics.lt (iota a) (iota b)\n        | Datatypes.Eq => iota a = iota b\n        | Datatypes.Gt => Schutte_basics.lt (iota b) (iota a)\n        end}.\n\\end{Coqsrc}\n\n\n\nFor instance, the following theorem tells that \\texttt{Epsilon0}, our notation system for the segment $[0,\\epsilon0)$ is a correct implementation of the theoretically defined  ordinal $\\epsilon_0$\n(see chapter~\\ref{chap:schutte} for more details).\n\n\n\\begin{Coqsrc}\nInstance Epsilon0_correct :\n  ON_correct epsilon0 Epsilon0  (fun alpha => inject (cnf alpha)).\n\\end{Coqsrc}\n\n\\index{Projects}\n\n\\begin{project}\n  When you have read Chapter~\\ref{chap:schutte}, prove that the sum of two ordinal notations \\texttt{ON\\_plus} implements the addition of ordinals.\n\\end{project}\n\n\n\n\n\n\\section{Isomorphism of Ordinal Notations}\n\n\nIn some cases we want to show that two notation systems describe the same segment (for instance $[0,3+\\omega)$ and $[0,\\omega)$\\;). For this purpose, one may prove that the two notation systems are order-isomorphic.\n\n\n\\label{types:ON-iso} \n\\begin{Coqsrc}\nClass  ON_Iso \n       `(OA : @ON A ltA compareA)\n       `(OB : @ON B ltB  compareB)\n       (f : A -> B)\n       (g : B -> A):=\n  {\n  iso_compare: forall x y : A, \n      compareB (f x) (f y) = compareA x y;\n  iso_inv1 : forall a, g (f a)= a;\n  iso_inv2 : forall b, f (g b) = b}.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\nLet $i$ be some natural number. Prove that the notation systems \n\\texttt{Omega} and (\\texttt{ON\\_plus (OrdFin $i$) Omega}) are isomorphic.\n\n{\\it \\textbf{Note:} This property reflects the equality $i+\\omega=\\omega$, that we prove also in larger notation systems, as well as in Schütte's model.}\n\nThis exercise is partially solved for $i=3$ (in ~\\href{../theories/html/hydras.OrdinalNotations.Example_3PlusOmega.html}{OrdinalNotations.Example\\_3PlusOmega}).\n\n\\end{exercise}\n\n\\index{Projects}\n\\label{exo:ON-mult}\n\\begin{project}\n% Define in \\coq{} the product of two ordinal notations $N_A$ and $N_B$.\n% If $A$ [resp. $B$] is the underlying type of $N_A$ [resp. $N_B$], the\n% product \\texttt{ON\\_mult $N_A$ $N_B$} is implemented over the cartesian product $B\\times A$ (with the lexicographic ordering).\n\nThis exercise is about the non-commutativity of the multiplication of ordinals, reflected in ordinal notations.\n\nFor instance, the\nelements of the product (\\texttt{ON\\_mult Omega (FinOrd 3)}) are ordered as follows.\n\\[(0,0),(0,1),(0,2),(0,3),(0,4),\\dots,{\\color{red}(1,0),} (1,1),(1,2),\\dots, {\\color{red}(2,0)},(2,1),(2,2),\\dots\\]\n\nNote that the elements of  (\\texttt{ON\\_mult (FinOrd 3) Omega}) are differently ordered (without limit ordinals):\n\\[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1),(0,2),(1,2),(2,2),(0,3),\\dots\\]\n\n\nProve formally  that \\texttt{ON\\_mult (FinOrd $i$) Omega} is isomorphic to\n\\texttt{Omega}  whilst\n\\texttt{Omega}  is a sub-notation of \\texttt{ON\\_mult Omega (FinOrd $i$)},\nfor any strictly positive $i$.\n\\end{project}\n\n\\index{Projects}\n\\begin{project}\nConsider two isomorphic ordinal notations \\texttt{OA} and \\texttt{OB}.\nProve that, if \\texttt{OA} [resp. \\texttt{OB}] is a correct implementation \nof $\\alpha$ [resp. $\\beta$], then $\\alpha=\\beta$.\n\\end{project}\n\n\n\\index{Projects}\n\\begin{project}\n\\label{project:succ-limit-dec}\nAdd to the class \\texttt{ON} the requirement that for any $\\alpha$ it is decidable whether $\\alpha$ is $0$, a successor or a limit ordinal.\n\n\n\\textbf{Hint:}   Beware of the instances associated with sum and product of notations!\n  You may consider additional fields \nto make the sum and product of notations ``compositional''.\n\n\\end{project}\n\n\\index{Projects}\n\\begin{project}\n\\label{project:on-setoid}\nReconsider the  class \\texttt{ON}, with an equivalence instead of Leibniz equality.\n\\end{project}\n\n\n\n\n\n%%%% ICI ICI\n\n\\section{Other Ordinal Notations}\n\n\\index{Projects}\n\n\\begin{project}\nThe directory \\texttt{theories/OmegaOmega} contains an ad-hoc formalization of $\\omega^\\omega$, contributed by Pascal Manoury. Every ordinal $\\alpha$ is represented by a list $l$ whose elements are the coefficients of $\\omega$ in  the Cantor normal form of $\\alpha$ (in reverse order). For instance, the ordinal \n$\\omega^{8}\\times 5 + \\omega^{6}\\times 8 + \\omega^2\\times 10 + \\omega + 7$ is represented by the list \\texttt{[5;0;8;0;0.0;10,1,7]}. \n\n\n Develop this representation and compare it with the other ordinal notations.\n\n\n\n\\end{project}\n\n\\index{Projects}\n\n\\begin{project}\nLet $N_A$ be a notation system for ordinals strictly less than $\\alpha$, \nwith the strict order $(A,<_A)$. Please build the notation system\n\\texttt{ON\\_Expl $N_A$}, on the type of multisets of elements of $A$\n(or, if preferred, the type of non-increasing finite sequences on $A$,\nprovided with the lexicographic ordering on lists).\n\nFor instance, let us take $N_A=\\texttt{Omega}$, and take $\\alpha=\\langle 4,4,2,1,0\\rangle$,\n $\\beta=\\langle 4,3,3,3,3,3,2\\rangle$, and $\\gamma=\\langle 5\\rangle$. Then $\\beta<\\alpha<\\gamma$. \n\nIn contrast the list $\\langle5,6,3,3\\rangle$ is not non-increasing (\\emph{i.e.} sorted w.r.t. $\\geq$), so it is not to be considered.\n\nNote that if the notation $N_A$ implements the ordinal \n$\\alpha$,  the new notation $\\omega^{N_A}$ must implement the ordinal $\\phi_0(\\alpha)$, a.k.a. $\\omega^\\alpha$ (see chapter~\\ref{chap:schutte})\n\n\\end{project}\n\n\n\n\\begin{remark}\n The set of ordinal terms in Cantor normal form (see Chap.~\\ref{chap:T1}) and \nin Veblen normal form (see \n\\href{../theories/html/hydras.Gamma0.Gamma0.html}{Gamma0.Gamma0}) are shown to be ordinal notation systems, but there is a lot of work to be done in order to unify ad-hoc  definitions and proofs which were written before the definition of the \\texttt{ON} type class.\n\\end{remark}\n\n\n\n\n\n\n\n\n\n\n%------------------------------------------------------------------------\n\n\\chapter[A proof of termination, using epsilon0]{A Proof of Termination, using Ordinals below \\texorpdfstring{$\\epsilon_0$}{Epsilon0}}\n\n\\label{cnf-math-def}\n\\label{chap:T1}\n\nIn this chapter, we adapt to \\coq{} the well-known~\\cite{KP82}  proof that Hercules eventually wins every battle, whichever the strategy  of each player.\nIn other words, we present  a formal and self contained proof of termination  of all [free] hydra battles.\nFirst, we take from Manolios and Vroon~\\cite{Manolios2005} a representation of the ordinal $\\epsilon_0$ as terms in Cantor normal form. Then, we define a variant for hydra battles as a measure that maps any hydra to some ordinal strictly less than $\\epsilon_0$.\n\n\n\n\\section{The Ordinal \\texorpdfstring{\\(\\epsilon_0\\)}{epsilon0}}\n\\label{sec:epsilon0-intro}\n\n\\subsection{Cantor Normal Form}\n\\index{Maths!Cantor normal form}\n\nThe ordinal \\(\\epsilon_0\\) is the least ordinal number that satisfies \nthe equation \\(\\alpha = \\omega^\\alpha\\), where \\(\\omega\\) is \nthe least infinite ordinal. Thus, we can consider \\(\\epsilon_0\\) as an\n\\emph{infinite} \\(\\omega\\)-tower.\nNevertheless, \nany ordinal strictly less that \\(\\epsilon_0\\) \ncan be finitely represented by a unique  \\emph{Cantor normal form}, \nthat is, an expression  which is either  the ordinal \\(0\\) or \na sum  \\(\\omega^{\\alpha_1} \\times n_1 + \\omega^{\\alpha_2} \\times n_2 + \n  \\dots + \\omega^{\\alpha_p} \\times n_p\\) where all the \\(\\alpha_i\\) \nare ordinals in Cantor  normal form, \\(\\alpha_1 > \\alpha_2 > \\alpha_p\\), \nand all the \\(n_i\\) are positive integers.\n\nAn example of Cantor normal form is displayed in Fig \\ref{fig:cnf-example}:\nNote that  any ordinal of\nthe form \\(\\omega^0 \\times i + 0\\) is just written \\(i\\).\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[scale=2, every node/.style={transform shape}]\n\\node[color=blue]{$\\omega^{(\\omega^\\omega\\,+\\, \\omega^2 \\times 8 \\,+\\, \\omega)}+ \\omega^\\omega + \\omega^4+ 6$};\n\\end{tikzpicture}\n\\caption{\\label{fig:cnf-example}\nAn ordinal in Cantor normal form}\n\\end{figure}\n\n\n\n\nIn the rest of this section, we define an inductive type for representing in \\texttt{Coq}\nall the ordinals strictly  less than  \\(\\epsilon_0\\), then extend some arithmetic operations\nto this type, and finally prove that our representation fits well with \nthe expected mathematical properties: the order we define is a well order, \nand the decomposition into Cantor normal form  is consistent \nwith the implementation of the arithmetic operations of exponentiation of base \\(\\omega\\) \nand addition.\n\n\\paragraph*{Remark}\n\\label{sec:orgheadline65}\nUnless explicitly mentionned, the term ``ordinal\" will be used instead of\n``ordinal strictly less than \\(\\epsilon_0\\)\" (except in Chapter~\\ref{chap:schutte} where it stands for ``countable ordinal'').\n\n\n\n\\subsection{A Data Type for  Ordinals in Cantor Normal Form}\n\\label{sec:orgheadline72}\n\\label{sec:T1-inductive-def}\n\n\n\n% Our user contribution~\\cite{CantorContrib} represents \n% the set of ordinals strictly less than $\\epsilon_0$ in Cantor normal form as in~\\cite{Manolios2005}, and also the set\n% of ordinals strictly  less than $\\Gamma_0$ in Veblen normal form.\n\n\n    Let us define an inductive type whose \nconstructors are respectively associated\nwith the ways to build Cantor normal forms:\n\n\\begin{itemize}\n\\item the ordinal \\(0\\)\n\\item the construction \\((\\alpha,\\, n,\\,\\beta)  \\mapsto \\omega^\\alpha \\times (n + 1)+ \\beta \\quad (n\\in\\mathbb{N})\\)\n\\end{itemize}\n\n\n\\vspace{4pt}\n\\noindent\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#T1}{Epsilon0.T1}}\n\n\\label{types:T1}\n%\\index{Constants!zero:T1}\n\n\n\\begin{Coqsrc}\nInductive T1 : Set  :=\n| zero : T1\n| ocons : T1 -> nat -> T1 -> T1.\n\\end{Coqsrc}\n\n\n\n\\subsubsection*{Remark}\n\\label{sec:orgheadline66}\n\n\nThe name \\texttt{T1} we gave to this data-type  is proper to this development and refers\nto a hierarchy of ordinal notations. For instance, in~\\cite{CantorContrib}, the following type is used to represent ordinals strictly less than \\(\\Gamma_0\\),  in Veblen normal form (see also~\\cite{schutte}).\n\n\n\\emph{Please look also at the library\n\\href{../theories/html/hydras.Gamma0.T2.html}{Gamma0.T2.html}}.\n\n\n\\begin{Coqsrc}\nInductive T2 : Set :=\n  zero : T2\n| gcons : T2 -> T2 -> nat -> T2 -> T2.\n\\end{Coqsrc}\n\n\\subsubsection{Example}\n\n\\label{alpha0-def}\nFor instance, the ordinal  $\\omega^\\omega+\\omega^3\\times 5+2$ is represented by the following term:\n\n\\begin{Coqsrc}\nExample alpha_0 : T1 :=\n  ocons (ocons (ocons zero 0 zero)\n               0\n               zero)\n        0\n       (ocons (ocons zero 2 zero)\n              4\n              (ocons zero 1 zero)).\n\\end{Coqsrc}\n\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.5, level 1/.style={sibling distance=6cm},\nlevel 2/.style={sibling distance=35mm},  \nlevel 3/.style={sibling distance=17mm}]\n\\node  {ocons}\n  child {  node {ocons}\n            child { node {ocons} child {node {zero}} child {node{0}} child{node{zero}}}\n         child {node {0}}\n         child {node {zero}}}\n    child {node {0}}\n   child {node {ocons} \n child { node {ocons} child {node {zero}} child {node{2}} child{node{zero}}}\n  child {node {4}}\n         child {node {ocons} child {node {zero}} child {node{1}} child{node{zero}}}};\n\n\\end{tikzpicture}\n\n\\caption{The tree-like representation of the ordinal $\\omega^\\omega+\\omega^3\\times 5 +2$\\label{fig:cnf-tree}}\n\n\\end{figure}\n\n\n\n\\paragraph{Remark}\nFor simplicity's sake, we chosed to forbid  expressions of the form $\\omega^\\alpha\\times 0 + \\beta$. Thus, the contruction (\\texttt{ocons $\\alpha$ $n$ $\\beta$}) is intented to represent the\nordinal $\\omega^\\alpha\\times(n+1)+\\beta$ and not $\\omega^\\alpha\\times n+\\beta$.\nIn a future version, we should replace  the type \\texttt{nat} with \\texttt{positive} in \\texttt{T1}'s \ndefinition. But this replacement would take a lot of time \\dots{}\n\n\\subsection{Abbreviations}\n\nSome abbreviations may help to write more concisely complex ordinal terms.\n\n\\subsubsection{Finite Ordinals}\n\\label{sec:orgheadline67}\n\nFor representing finite ordinals, \\emph{i.e.} natural numbers, we first introduce a notation for terms of the form $n+1$, then define a coercion from type \\texttt{nat} into \\texttt{T1}.\n\\label{sect:notation-FS}\n\n\\begin{Coqsrc}\nNotation \"'FS' n\" :=\n     (ocons zero n zero) (at level 10) : t1_scope.\n\\end{Coqsrc}\n\n\\label{sect:notation-F}\n\n\\begin{Coqsrc}\nDefinition fin (n:nat) : T1 := \n    match n with 0 => zero | S p => FS p end. \n\nCoercion fin  : nat >-> T1.\n\nExample ten : T1 := 10.   \n\\end{Coqsrc}\n\n% \\index{Coq!Techniques!Coercions}\n% \\index{Functions!Coercions@Coercions (from nat to ordinal types)}\n% \\begin{remark}\n% Please refer to the remark~\\pageref{warning:coercions} about the use of coercions.\n% % The use of coercions like \\texttt{fin} allow us to be close to the mathematical tradition where natural numbers are ordinals too.\n% % Nevertheless, it may happen that a goal like \\texttt{3 < 5} could be \n% % interpreted as \\texttt{(lt (fin 3) (fin 5))},  depending on the current notation scope.  \n% % When this misinterpretation happens, tactics like \\texttt{auto with arith}, \\texttt{lia} do not work!\n% % Thus, it is useful to write \\texttt{(3 < 5)\\%nat}  an inequality between two natural numbers. \n% \\end{remark}\n\n\n\\subsubsection{The Ordinal \\(\\omega\\)}\n\\label{sec:orgheadline68}\n\n  Since \\(\\omega\\)'s Cantor normal form is\ni.e. \\(\\omega^{\\omega^0}\\times 1+ 0\\), we can define the following abbreviation:\n\n\\label{sect:omega-notation2}\n\\begin{Coqsrc}\nNotation omega := (ocons (ocons zero 0 zero) 0 zero): t1_scope.\n\\end{Coqsrc}\n\nNote that \\texttt{omega} is not an identifier, thus any tactic like \\texttt{unfold omega} would fail.\n\n\n\\subsubsection{The Ordinal \\(\\omega^\\alpha\\), a.k.a. \\(\\phi_0(\\alpha)\\)}\n\\label{sec:orgheadline70}\n\nWe provide also a notation for ordinals of the form $\\omega^\\alpha$.\n\n\\label{sect:notation-phi0}\n\n\\index{Notations!phi0@phi0 (exponential of base omega)}\n\n\\begin{Coqsrc}\nNotation \"'phi0' alpha\" := (ocons alpha 0 zero) (at level 29) : t1_scope.\n\\end{Coqsrc}\n\n\\index{Maths!Additive principal ordinals}\n\n\\begin{remark}\n\\label{sec:orgheadline69}\nThe name \\(\\phi_0\\)\n   comes from ordinal numbers theory. In~\\cite{schutte}, Schütte defines \n$\\phi_0$  as the ordering (\\emph{i.e.} enumerating) function of the set  of \\emph{additive principal ordinals} \\emph{i.e.} strictly positive ordinals $\\alpha$ that verify $\\forall \\beta<\\alpha, \\beta+\\alpha=\\alpha$. For Schütte,  $\\omega^\\alpha$ is just a notation for $\\phi_0(\\alpha)$.  See also Chapter~\\ref{chap:schutte} of this document.\n\\end{remark}\n\n\n\n  \n\\subsubsection{The Hierarchy of \\(\\omega\\)-towers:}\n\\label{sec:orgheadline71}\n\nThe ordinal $\\epsilon_0$, although not represented by a finite term in Cantor normal form, is approximed by the sequence of $\\omega$-towers (see also Sect~\\vref{sect:epsilon0-as-limit} ).\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html}{Epsilon0.T1}}\n\n\\begin{Coqsrc}\nFixpoint omega_tower (height:nat) : T1 := \n match height with \n | 0 =>  1 \n | S h => phi0 (omega_tower h)\n end.\n\\end{Coqsrc}\n\nFor instance, Figure~\\ref{fig:tower7} represents  the ordinal returned by the\n evaluation of the term \\texttt{omega\\_tower 7}.\n\n\\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[scale=2, every node/.style={transform shape}]\n\\node[color=blue]{$\\omega^{{{\\omega}^{{{\\omega}}^{{{\\omega}}^{{\\omega^{{\\omega}^{\\omega}}}}}}}}$};\n\\end{tikzpicture}\n\\caption{\\label{fig:tower7}\nThe $\\omega$-tower of height 7}\n\\end{figure}\n\n\n\n\\subsection{Comparison between Ordinal Terms}\n\\label{sec:orgheadline73}\n\n\n% Our formalisation of Cantor Normal Form will take two steps:\n% 1 Definition of a strict order \\texttt{o<} on the type \\texttt{T1}, \n% 2 Using \\texttt{o<} for characterizing terms in normal form.\n\nIn order to compare two terms of type \\texttt{T1}, we define a recursive function \\texttt{compare} that maps two ordinals $\\alpha$ and $\\beta$ to a value of type \\texttt{comparison}. This type is defined in \\coq's standard library \n\\texttt{Init.Datatypes} and\ncontains three constructors:  \\texttt{Lt} (less than), \\texttt{Eq} (equal), and\n\\texttt{Gt} (greater than).\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#compare}{Epsilon0.T1}}\n\n\n\\begin{Coqsrc}\nFixpoint compare (alpha alpha':T1):comparison :=\n  match alpha, alpha' with\n    zero, zero => Eq\n  | zero, ocons a' n' b' => Lt\n  | _   , zero => Gt\n  | (ocons a n b),(ocons a' n' b') =>\n      (match compare a a' with \n          | Lt => Lt\n          | Gt => Gt\n          | Eq => (match lt_eq_lt_dec n n'\n                   with\n                       inleft  (left _) => Lt\n                     | inright _ => Gt\n                     |   _ => compare b b'\n                   end)\n       end)\n  end.\n\\end{Coqsrc}\n \nIt is now easy to define the boolean predicate \\texttt{lt\\_b $\\alpha$ $\\beta$}: \n`` $\\alpha$ is strictly less than $\\beta$ ''. By coercion to sort \\texttt{Prop} we define also the predicate \\texttt{lt}.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html}{Epsilon0.T1}}\n\n\n\\begin{Coqsrc}\nDefinition lt_b alpha beta : bool :=\n  match compare alpha beta with\n      Lt => true\n    | _ => false\n  end.\n\nDefinition lt alpha beta : Prop := lt_b alpha beta.\n\\end{Coqsrc}\n\n\\label{Predicates:lt-T1}\nPlease note that this definition of \\texttt{lt} makes it easy to write proofs by reflection, as shown by the following exampgles.\n\n\\begin{Coqsrc}\nExample E1 : lt (ocons omega 56 zero) (tower 3).\nProof. reflexivity. Qed.\n\nExample E2 : ~ lt (tower 3) (tower 3).\nProof.  discriminate.  Qed.\n\\end{Coqsrc}\n\nThe following lemmas establish relations between \\texttt{compare}, \nthe predicate \\texttt{lt} and Leibniz equality \\texttt{eq}.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#compare_refl}{Epsilon0.T1}}\n\n\n\\begin{Coqsrc}\nLemma compare_refl : forall alpha, compare alpha alpha =  Eq.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma compare_reflect : forall alpha beta,\n    match compare alpha beta with\n    |   Lt => lt alpha  beta\n    |   Eq => alpha = beta\n    |   Gt => lt beta  alpha\n    end.\n\\end{Coqsrc}\n\nWe prove also that the relation \\texttt{lt} is a strict total order.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#lt_irrefl}{Epsilon0.T1}}\n\n  \n\\begin{Coqsrc}\nTheorem lt_irrefl (alpha: T1):  ~ lt alpha alpha.\n\nTheorem lt_trans (alpha beta gamma : T1) :\n  lt alpha  beta -> lt beta gamma -> lt alpha gamma.\n\nDefinition lt_eq_lt_dec  :\n   forall alpha beta : T1, \n          {lt alpha  beta} + {alpha = beta} + {lt beta alpha}.\n\\end{Coqsrc}\n\n\nNote that the order \\texttt{lt} is not reflected \nin the structure (size and/or height) of the terms of \\texttt{T1}. \nFor instance the ordinal of Fig \\ref{fig:cnf-example} is strictly less\nthan the structurally simpler \\(\\omega^{\\omega^\\omega}\\times 2\\).\n\n\\subsubsection{A Predicate for Characterizing Normal Forms}\n\\label{sect:t1-nf}\n\n\\label{sec:orgheadline74}\n\\label{sec:orgheadline75}\nOur data-type \\texttt{T1} allows us to write expressions that\nare not properly in Cantor normal form as specified in Section \\ref{sec:epsilon0-intro}.\nFor instance, consider the following term of type  \\texttt{T1}. \n\n\\begin{Coqbad}\nExample bad_term  : T1 := ocons 1 1 (ocons omega 2 zero).\n\\end{Coqbad}\n\nThis term would have been written \\(\\omega^1\\times 2 + \\omega^\\omega \\times 3\\) in the usual mathematical notation. We note that the exponents of $\\omega$ are not in the right (strictly decreasing) order.\n\nWith the help of the order \\texttt{lt} on \\texttt{T1}, we are now able to characterize\nthe set of all well-formed ordinal terms:\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#nf_b}{Epsilon0.T1}}\n\n\\label{Predicates:nf-T1}\n\n\\begin{Coqsrc}\nFixpoint nf_b (alpha : T1) : bool :=\n  match alpha with\n    | zero => true\n    | ocons a n zero => nf_b a\n    | ocons a n ((ocons a' n' b') as b) =>\n      (nf_b a && nf_b b && lt_b a' a)%bool\n  end. \n\nDefinition nf alpha: Prop := nf_b alpha.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\n Compute nf_b alpha_0.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = true \n     : bool\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n Compute nf_b bad_term.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = false \n     : bool\n\\end{Coqanswer}\n\n\n\n\\subsection{Making Normality Implicit}\n  We would like to get rid of terms of type \\texttt{T1} which are not in Cantor normal form.\nA simple way to do this is to consider statements of the form \n\\texttt{forall alpha: T1, nf alpha -> $P$ alpha}, where $P$ is a predicate over type \\texttt{T1}, like in the following lemma \\footnote{Ordinal addition is formally defined a little later (page~\\ref{sect:infix-plus-T1})}.\n\n\\begin{Coqsrc}\nLemma plus_is_zero alpha beta :\n  nf alpha -> nf beta ->\n  alpha + beta  = zero -> alpha = zero /\\  beta = zero.\n\\end{Coqsrc}\n\nBut this style leads to clumsy statements, and generates too many sub-goals in interactive proofs (although often solved with \\texttt{auto} or \\texttt{eauto}).\n\nOne may encapsulate conditions of the form \\texttt{(nf $\\alpha$)} in\nthe most used predicates. For instance, we introduce the restriction of \\texttt{lt} to terms in normal form, and provide a handy notation for this restriction.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Prelude.Restriction.html}{Ordinals.Prelude.Restriction}}\n\n\\begin{Coqsrc}\nDefinition restrict {A:Type}(E: Ensemble A)(R: relation A) :=\n    fun a b => E a /\\ R a b /\\ E b.\n \\end{Coqsrc}\n\n \n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#LT}{Epsilon0.T1}}\n\n\\begin{Coqsrc}\nDefinition LT := restrict nf lt.\nInfix \"t1<\" := LT : t1_scope.\n\nDefinition LE := restrict nf le.\nInfix \"t1<=\" := LE : t1_scope.\n\\end{Coqsrc}\n\n\n\\label{Predicates:LT-T1}\n \n\nFor instance, in the following lemma, the condition that $\\alpha$ is in normal form is included in the condition $\\alpha< 1$.\n\n\\begin{Coqsrc}\nLemma LT_one : forall alpha, alpha t1< one -> alpha = zero.\n\\end{Coqsrc}\n\n  \n\\subsubsection{A Sigma Type for \\texorpdfstring{$\\epsilon_0$}{epsilon0}}\n\nAs we noticed in Sect.~\\ref{sect:t1-nf}, the type \\texttt{T1} is not a correct ordinal notation, since it contains terms that are not in Cantor normal form. In certain contexts (for instance in Sections~\\ref{sect:L-equations}, \\ref{sect:hardy},\nand \\ref{sect:wainer}),  we need to define total recursive functions on well-formed ordinal terms less  than $\\epsilon_0$, using the \\texttt{Equations} plug-in~\\cite{sozeau:hal-01671777}.\n In order to define a type whose inhabitants represent just ordinals, we build a type gathering a term of type \\texttt{T1} and a proof that this term is in normal form.\n \n\n\\label{sect:E0-def}\n\\label{types:E0}\n\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.E0.html}{Epsilon0.E0}}\n\n\n\n\\begin{Coqsrc}\nClass E0 : Type := t1_2o {cnf : T1; cnf_ok : nf cnf}.\n\\end{Coqsrc}\n\nMany constructs : types, predicates, functions, notations, etc., on type \\texttt{T1} are adapted to \\texttt{E0}.\n\nFirst, we declare a notation scope for \\texttt{E0}.\n\n\\begin{Coqsrc}\nDeclare Scope E0_scope.\nDelimit Scope E0_scope with e0.\nOpen Scope E0_scope.\n\\end{Coqsrc}\n\nThen we redefine the predicates of comparison.\n\n\\label{Predicates:Lt-E0}\n\n\\begin{Coqsrc}\nDefinition Lt (alpha beta : E0) := T1.LT (@cnf alpha) (@cnf beta).\nDefinition Le (alpha beta : E0) := T1.LE (@cnf alpha) (@cnf beta).\n\nInfix \"o<\" := Lt : E0_scope.\nInfix \"o<=\" := Le : E0_scope.\n\\end{Coqsrc}\n  \n\nEquality in \\texttt{E0} is just Leibniz equality. Note that, since \\texttt{nf} is\ndefined by a Boolean function, for  any term $\\alpha:\\texttt{T1}$, there exists at most one proof of \\texttt{nf $\\alpha$}, thus two ordinals of type \\texttt{E0} are\nequal if and only iff their projection to \\texttt{T1} are equal (see also Sect.~\\vref{sect:eq-proof-unicity}).\n\n\\index{Coq!Techniques!Unicity of equality proofs}\n\n\n\\begin{Coqsrc}\nRequire Import Logic.Eqdep_dec.\n\nLemma nf_proof_unicity :\n  forall (alpha:T1) (H H': nf alpha), H = H'.\n\nLemma E0_eq_iff alpha beta : alpha = beta <-> cnf alpha = cnf beta.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\\begin{exercise}\nIn earlier versions of this development, the predicate \\texttt{nf} was defined  inductively, with various constructors describing all possible cases.\n\\begin{enumerate}\n\\item Please give such a definition, in a dedicated module.\n\\item Prove the logical equivalence between your definition and ours.\n\\item Define a variant of the type \\texttt{E0} (with your definition of \\texttt{nf}).\n\\item Can you still prove a lemma like \\texttt{E0\\_eq\\_iff} ? With the help of an axiom from some module of the standard library ?\n\\end{enumerate}\n\\end{exercise}\nFor upgrading constants and fonctions of \\texttt{T1}, we have to prove that \nthe term they build is in normal form.\nFor instance, let us represent the ordinals $0$ and $\\omega$ as instances of the class \\texttt{E0}.\n\n\\label{sect:omega-T1}\n%\\index{Constants!zero:T1}\n\n\\begin{Coqsrc}\nInstance Zero : E0.\nProof.\n  now exists T1.zero.\nDefined.\n\nInstance _Omega : E0.\nProof.  now exists omega%t1. \nDefined.\n\nNotation \"'omega'\"  := _Omega : E0_scope.\n\\end{Coqsrc}\n\n\n\n\\subsection{Syntactic Definition of Limit and Successor Ordinals}\n\nPattern matching and structural recursion allow us to define the notions of successor and limit ordinal with the help of  boolean functions on type \\texttt{T1}. \n\n \\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#succb}{Epsilon0.T1}}\n\n\\begin{Coqsrc}\n  Fixpoint succb alpha :=\n  match alpha with\n      zero => false\n    | ocons zero _ _ => true\n    | ocons alpha n beta => succb beta\n  end.\n\nFixpoint limitb alpha :=\n  match alpha with\n      zero => false\n    | ocons zero _ _ => false\n    | ocons alpha n zero => true\n    | ocons alpha n beta => limitb beta\n  end.\n\\end{Coqsrc}\n\n\n\n\\begin{Coqsrc}\n  Compute limitb omega.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = true\n     : bool\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute succb 42.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = true\n     : bool\n   \\end{Coqanswer}\n\nThe correctness of these definitions with respect to the mathematical notions of\nlimit and successor ordinals is established through several lemmas. For instance,\nLemma \\texttt{canonS\\_limit}, page~\\pageref{lemma:canonS-limit}, shows that\nif $\\alpha$ is (syntactically) a limit ordinal, then it is the least upper bound of\na strictly increasing sequence of ordinals.\n\n\n   The following function is very useful in constructions by cases (proofs and function definitions).\n   \n\\begin{Coqsrc}\nDefinition zero_succ_limit (alpha: T1) :\n    {succb alpha} + {limitb alpha} +  {alpha=zero}.\n    (* ... *)\nDefined.\n\\end{Coqsrc}\n\n\n\n\\subsection{Arithmetic on \\texorpdfstring{$\\epsilon_0$}{epsilon0}}\n\\subsubsection{Successor}\n\nThe successor of any ordinal $\\alpha< \\epsilon_0$ is defined by structural \nrecursion on its Cantor normal form.\n\n\\label{Functions:succ-T1}\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.T1.html\\#succ}{Epsilon0.T1}}\n\n\\begin{Coqsrc}\nFixpoint succ (alpha:T1) : T1 :=\n  match alpha with \n   | zero => 1\n   | ocons zero n _ => ocons zero (S n) zero\n   | ocons beta n gamma => ocons beta n (succ gamma)\n end.\n\\end{Coqsrc}\n\n\nThe following lemma establishes the connection between the  function\n\\texttt{succ} and the Boolean predicate \\texttt{succb}.\n\n\n\\begin{Coqsrc}\n Lemma succb_iff alpha (Halpha : nf alpha) :\n  succb alpha <-> exists beta : T1, nf beta /\\ alpha = succ  beta.\n\\end{Coqsrc}\n\n\\index{Exercises}\n \\begin{exercise}\nProve in \\coq{} that for any ordinal $\\alpha<\\epsilon_0$, $\\alpha$ is a limit if \nand only if for all $\\beta<\\alpha$, the interval $[\\beta,\\alpha)$ is infinite.\n \\end{exercise}\n\n\n\\subsubsection{Addition and Multiplication}\n\nOrdinal addition and multiplication are also defined by structural recursion over the type \\texttt{T1}. Please note that they use the \\texttt{compare} function on some subterms of their arguments.\n\n\\label{sect:infix-plus-T1}\n\n\\begin{Coqsrc}\nFixpoint plus (alpha beta : T1) : T1 :=\n  match alpha,beta with\n |  zero, y  => y\n |  x, zero  => x\n |  ocons a n b, ocons a' n' b' =>\n    (match compare a a' with\n     | Lt => ocons a' n' b'\n     | Gt => (ocons a n (plus b (ocons a' n' b')))\n     | Eq  => (ocons a (S(n+n')) b')\n     end)\n  end\nwhere \"alpha + beta\" := (plus alpha beta) : t1_scope.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nFixpoint mult (alpha beta : T1) :T1 :=\n  match alpha,beta with\n |  zero, y  => zero\n |  x, zero => zero\n |  ocons zero n _, ocons zero n' _ => \n                 ocons zero (Peano.pred((S n) * (S n'))) zero\n |  ocons a n b, ocons zero n' b' =>  \n                 ocons a (Peano.pred((S n) * (S n'))) b\n |  ocons a n b, ocons a' n' b' =>\n     ocons (a + a') n' ((ocons a n b) * b')\n end\nwhere  \"alpha * beta\" := (mult alpha beta) : t1_scope.\n\\end{Coqsrc}\n\n\n\\subsubsection{Examples}\n\nThe following examples are instances of \\emph{proofs by computation}. Please note that  addition and multiplication on \\texttt{T1}\nare not commutative. Moreover,  both operations fail to be strictly monotonous in their first argument.\n\n\n\\begin{Coqsrc}\nExample e2 : 6 + omega = omega.\nProof. reflexivity. Qed.\n\nExample e'2 : omega t1< omega + 6.\nProof. now compute. Qed.\n\nExample e''2 : 6 * omega = omega.\nProof. reflexivity. Qed.\n\nExample e'''2 : omega t1< omega * 6.\nProof. now compute. Qed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma plus_not_monotonous_l : exists alpha beta gamma : T1,\n    alpha t1< beta /\\ alpha + gamma = beta + gamma.\nProof.\n  exists 3, 5, omega;  now  compute.\nQed.\n\nLemma mult_not_monotonous :  exists alpha beta gamma : T1,\n      alpha t1< beta /\\ alpha * gamma = beta * gamma.\nProof.\n  exists 3, 5, omega; now compute.\nQed.\n\\end{Coqsrc}\n\n\n\\subsection{Pretty Printing Ordinals in Cantor Normal Form}\n\\label{sect:ppT1}\n\nLet us consider again the ordinal $\\alpha_0$ defined in section~\\vref{alpha0-def}\nIf we ask \\coq{} to print its  normal form, we get a hardly readable term of type \\texttt{T1}.\n\n\\begin{Coqsrc}\nCompute alpha_0.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = ocons omega 0 (ocons (FS 2) 4 (FS 1))\n     : T1\n\\end{Coqanswer}\n\nThe following data type defines an abstract syntax for more readable ordinals terms in Cantor normal form:\n\n\\label{types:ppT1}\n\\index{Functions!pp@ pp (pretty printing terms in Cantor normal form)}\n\n\\begin{Coqsrc}\nInductive ppT1 : Set :=\n    P_fin : nat -> ppT1\n  | P_add : ppT1 -> ppT1 -> ppT1\n  | P_mult : ppT1 -> nat -> ppT1\n  | P_exp : ppT1 -> ppT1 -> ppT1\n  | P_omega : ppT1\n\\end{Coqsrc}\n\nThe function \\texttt{pp: T1 -> ppT1} converts any closed term of type \\texttt{T1} into a human-readable expression. For instance, let us convert the term \\texttt{alpha\\_0}.\n\n\\begin{Coqsrc}\nCompute pp alpha_0.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n     = (omega ^ omega + omega ^ 3 * 5 + 2)%pT1\n     : ppT1\n\\end{Coqanswer}\n\n\\index{Projects}\n\\begin{project}\nDesign  (in \\ocaml?) a set of tools for systematically pretty printing ordinal terms in Cantor normal form.\n\\end{project}\n\n\n\\subsubsection{Arithmetic on Type \\texttt{E0}}\n\n We define an addition in type \\texttt{E0}, using the function{T1.plus}\nand its properties.\n\n\\begin{Coqsrc}\nSearch   (nf (_ + _)%t1).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nplus_nf: forall a : T1, nf a -> forall b : T1, nf b -> nf (a + b)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nInstance plus (alpha beta : E0) : E0.\nProof.\n  refine (@mkord (T1.plus (@cnf alpha) (@cnf beta))_ );\n    apply plus_nf; apply cnf_ok.\nDefined.\n\nInfix \"+\" := plus : E0_scope.\n\nCheck omega + omega.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nomega + omega\n     : E0\n\\end{Coqanswer}\n\n\\index{Exercises}\n \\begin{exercise}\nLet $\\alpha$ be an ordinal. We say that $\\alpha$ is \\emph{infinite} iff the segment $[0,\\alpha)$ is an infinite set. \n\\begin{enumerate}\n\\item Adapt this definition to the type \\texttt{E0}.\n\\item Prove that \\emph{being infinite} is decidable on type \\texttt{E0}.\n\\item Prove that $\\alpha$ is infinite if and only if for all finite ordinal $i$,\n$i+\\alpha=\\alpha$.\n\\end{enumerate}\n \\end{exercise}\n\n\\section{Well-foundedness and Transfinite Induction}\n\n\\index{Maths!Transfinite induction}\n\n\\subsection{About  Well-foundedness}\n\\label{sec:orgheadline82}\n   In order to use \\texttt{T1} for proving termination results,\nwe need to prove that  our order \\texttt{<} is well-founded. Then we will get \\emph{transfinite induction} for free.\n\n\nThe proof of well-foundedness of the strict order $<$ on Cantor normal forms is already \navailable in the Cantor contribution by Castéran and Contejean~\\cite{CantorContrib}. That proof relies on a library on recursive path orderings written by\nE. Contejean. We present here  a direct proof of the same result, which does not require any knowledge on r.p.o.s.\n\n\\index{Exercises}\n\n\\begin{exercise}\nProve that the \\emph{total} order \\texttt{lt} on \\texttt{T1} is not well-founded. \n\\textbf{Hint:}  You will have to build a counter-example with terms of type \\texttt{T1}\nwhich are not in Cantor normal form.\n\\end{exercise}\n\n% \\subsubsection{The total order \\texttt{lt} on \\texttt{T1} is \\emph{not} well-founded}\n% \\label{sec:orgheadline76}\n\n% Let us recall that the data type \\texttt{T1} contains too many inhabitants, including\n% terms which are not in Cantor normal form. Thus, the following result is not \n% very surprising.\n\n% \\begin{Coqsrc}\n% Section lt_not_well_founded.\n  \n%   (* let us build the sequence of terms :\n%         omega + omega + .... + omega ^ 2   *)\n%   Let f := (fix f (i:nat): T1 :=\n%             match i with 0 => phi0 2\n%                        | S i => ocons 1 1 (f  i)\n%             end).\n\n \n%  Lemma  f_decreases : forall i, f (S i) <  f i.\n%  Proof.\n%   induction i; compute; auto with T1.\n%  Qed.\n\n%  Theorem lt_not_wf : ~  well_founded lt.\n%  Proof. \n%    intro wf; case (not_decreasing _ lt);auto.\n%    exists f; apply f_decreases.\n%  Qed.\n\n% End lt_not_well_founded.\n% \\end{Coqsrc}\n\n% Thus, we have \n\n\\subsubsection{A First Attempt}\n\\label{sec:orgheadline77}\n\\index{Coq!Techniques!Well-founded induction}\n\nIt is natural to try to prove by structural induction over \\texttt{T1} \nthat every term in normal form is accessible through \\texttt{LT}.\n\nUnfortunately, it won't work. Let us consider some well-formed term\n $\\alpha=\\texttt{ocons $\\beta\\;n\\;\\gamma$}$, and assume that \\(\\beta\\) and \\(\\gamma\\) are accessible\n through \\texttt{LT}. For proving the accessibility of $\\alpha$, we have to consider\nany well formed term \\(\\delta\\) such that \\(\\delta<\\alpha\\). \nBut nothing guarantees that \\(\\delta\\)  is strictly  less than \\(\\beta\\) nor \\(\\gamma\\), and we cannot use the induction hypotheses on   \\(\\beta\\) nor \\(\\gamma\\).\n\n\\begin{Coqbad}\nSection First_attempt.\n\n Lemma wf_LT : forall alpha,  nf alpha -> Acc LT alpha. \n Proof.\n  induction alpha as [| beta IHbeta n gamma IHgamma].\n  - split.\n    inversion 1.\n    destruct H2 as [H3 _];not_neg H3.\n  -  split; intros delta Hdelta.\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n1 subgoal (ID 560)\n  \n  beta : T1\n  n : nat\n  gamma : T1\n  IHbeta : nf beta -> Acc LT beta\n  IHgamma : nf gamma -> Acc LT gamma\n  H : nf (ocons beta n gamma)\n  delta : T1\n  Hdelta : delta t1< ocons beta n gamma\n  ============================\n  Acc LT delta\n \\end{Coqanswer}\n\n\\begin{Coqbad}\n  Abort.\n\\end{Coqbad}\n\nThe problem comes from the hypothesis \\texttt{Hdelta}. It does not prevent  \\(\\delta\\) to be bigger that \\(\\beta\\) or\n\\(\\gamma\\);\nfor instance \\(\\delta\\) may be of the form\n\\texttt{ocons $\\beta'$ $p'$  $\\gamma'$},\nwhere  \\(\\beta' \\leq  \\beta\\) and  \\(p' < n\\).\nThus, the induction hypotheses \\texttt{IHbeta} and \\texttt{IHgamma}  are useless for finishing our proof.\n\n\\subsubsection{Using a Stronger Inductive Predicate.}\n\\label{sec:orgheadline78}\n  Instead of trying to prove directly that any ordinal term \\(\\alpha\\) in normal form is accessible\nthrough \\texttt{LT}, we propose to show first that any well formed \nterm of the form \\(\\omega^\\alpha\\times(n+1)+\\beta\\) is accessible (which is a stronger result).\n\n\\begin{Coqsrc}\n Let Acc_strong (alpha:T1) :=\n      forall n beta, \n        nf (ocons alpha n beta) -> Acc LT (ocons alpha  n beta).\n\\end{Coqsrc}\n\nThe following lemma is an application of the strict inequality \n\\showmath{\\alpha < \\omega ^\\alpha}. If \\showmath{\\omega^\\alpha} is accessible,\nthen \\showmath{\\alpha} is \\emph{a fortiori} accessible.\n\n\\begin{Coqsrc}\n Lemma Acc_strong_stronger : forall alpha, \n     nf alpha -> Acc_strong  alpha -> Acc LT  alpha.\n Proof.\n  intros alpha H H0; apply acc_imp with (phi0 alpha).\n  - repeat split; trivial.\n    + now apply lt_a_phi0_a.\n  -  apply H0;  now apply single_nf.\nQed.\n\\end{Coqsrc}\n\nThus, it remains to prove that every ordinal strictly less than \\showmath{\\epsilon_0} \nis strongly accessible.\n\n% \\subsubsection{Structure of the proof of well-foundedness of \\texttt{LT}}\n\n\\label{sec:orgheadline81}\n\\label{proof-wf-epsilon0}\n\\paragraph{A helper}\n\\label{sec:orgheadline79}\n\nFirst, we prove that, for  any \\texttt{LT}-accessible term \\showmath{\\alpha}, \\showmath{\\alpha} is \nstrongly accessible too (\\emph{i.e.} any well formed\nterm (\\texttt{ocons $\\alpha$ $n$ $\\beta$})  is accessible).\n\n\\begin{Coqsrc}\nLemma Acc_implies_Acc_strong : \n   forall alpha, Acc LT  alpha -> Acc_strong alpha.\n\\end{Coqsrc}\n\n\nThe proof is structured as an induction on \\showmath{\\alpha}'s accessibility. Let us consider\nan accessible term $\\alpha$.\n\n\n\n\\begin{Coqanswer}\n  subgoal 1 \n\n  alpha : T1\n  Aalpha : forall y : T1,  y t1< alpha -> Acc LT y\n  IHalpha : forall y : T1,\n       LT y alpha ->\n       forall (n : nat) (beta : T1),\n       nf (ocons y n beta) -> Acc LT (ocons y n beta)\n  ============================\n   forall (n : nat) (beta : T1),\n   nf (ocons alpha n beta) -> Acc LT (ocons alpha n beta)\n\\end{Coqanswer}\n\nLet \\texttt{n:nat} and \\texttt{beta:T1} such that \\texttt{ocons alpha n beta} is in normal form. \nWe prove first that \\texttt{beta} is accessible,  which allows us to by well-founded induction on \\texttt{beta}, \nand natural induction on \\texttt{n}, that (\\texttt{ocons alpha n beta}) is accessible.\nThe proof, quite long, can be consulted in \\url{../theories/html/hydras.Epsilon0.T1.html} \n\n\\paragraph{Accessibility of any well-formed ordinal term}\n\\label{sec:orgheadline80}\n\nOur goal is still to prove accessibility of any well formed ordinal term.\nThanks to our previous lemmas, we are almost done.\n\n\\begin{Coqsrc}\n(* A (last) structural induction *)\n\nTheorem nf_Acc : forall alpha, nf alpha -> Acc LT  alpha.\nProof.\n induction alpha.\n-  intro; apply Acc_zero.\n -  intros; eapply Acc_implies_Acc_strong;auto.\n    apply IHalpha1;eauto.\n    apply nf_inv1 in H; auto. \nDefined.\n\nCorollary T1_wf : well_founded LT.\n\\end{Coqsrc}\n\n\\index{Maths!Transfinite induction}\n\n\\begin{Coqsrc}\n\nDefinition transfinite_recursor :\n forall (P:T1 -> Type),\n   (forall x:T1, \n     (forall y:T1, nf x -> nf y ->  lt y  x -> P y) -> P x) ->\n    forall alpha:T1, P alpha.\nProof.\n intros; apply well_founded_induction_type with LT.\n -  exact T1_wf;auto.\n - intros. apply X. intros; apply X0. repeat split;auto. \nDefined.\n\\end{Coqsrc}\n\nThe following tactic starts a proof by  transfinite induction on any ordinal \\mathcolor{$\\alpha<\\epsilon_0$}.\n\n\\begin{Coqsrc}\nLtac transfinite_induction alpha :=\n  pattern alpha; apply transfinite_recursor;[ | try assumption].\n\\end{Coqsrc}\n\n\n\\begin{remark}\n\\label{remark:a3pat}\nThe alternate proof of well-foundedness using \\'Evelyne Contejean's work on recursive path ordering~\\cite{DershowitzRPO, a3pat} is available in the library \\href{../theories/html/hydras.Epsilon0.Epsilon0rpo.html}{Epsilon0rpo}.\n \\end{remark}\n\n\n\\subsection{An Ordinal Notation for  \\texorpdfstring{$\\epsilon_0$}{epsilon0}}\n\nWe build an instance of \\texttt{ON}, and prove its correction w.r.t. Schutte's model.\n\n\\label{instance-epsilon0}\n\\begin{Coqsrc}\nInstance Epsilon0 : ON Lt compare.  \n(* ... *)\n\\end{Coqsrc}\n\n\n\\emph{From Module~\\href{../theories/html/hydras.Schutte.Schutte.Correctness_E0.html}{Schutte.Schutte.Correctness\\_E0}}\n\n\\begin{Coqsrc}\nInstance Epsilon0_correct :\n  ON_correct epsilon0 Epsilon0 (fun alpha => inject (cnf alpha)).\n\\end{Coqsrc}\n\n\\index{Projects}\n\\begin{project}\n \\emph{This exercise is a continuation of Project~\\vref{exo:ON-mult}.}\nUse \\texttt{ON\\_mult} to define an ordinal notation \\texttt{Omega2} for $\\omega^2=\\omega\\times\\omega$.\n\nProve that \\texttt{Omega2} is a sub-notation of \\texttt{Epsilon0}.\n\nDefine on \\texttt{Omega2} an addition compatible with the addition on \\texttt{Epsilon0}.\n\n\\textbf{Hint}. You may use the following definition (in \n\\href{../theories/html/hydras.OrdinalNotations.Definitions.html}{OrdinalNotations.Definitions}).\n\n\\begin{Coqsrc}\nDefinition SubON_same_op  `{OA : @ON A ltA  compareA}\n       `{OB : @ON B ltB  compareB}\n       {iota : A -> B} \n       {alpha: B}\n       {_ : SubON OA OB alpha iota}\n       (f : A -> A -> A)\n       (g : B -> B -> B)\n  :=\n  forall x y,  iota (f x y) = g (iota x) (iota y).\n\\end{Coqsrc}\n\n\\end{project}\n\n\\index{Projects}\n\\begin{project}\nThe class \\texttt{ON} of ordinal notations has been defined long after this \nchapter, and is not used yet in the development of the type \\texttt{E0}. \nA better integration of both notions should simplify the development on ordinals in Cantor normal form. This integration is planned for the future versions.\n\n\\end{project}\n\n\n\\section{A Variant for Hydra Battles}\n\n\\subsection{Natural Sum (a.k.a. Hessenberg's  Sum)}\n\\label{sec:orgheadline87}\n\\label{hydra-variant}\n\nNatural sum (Hessenberg's  sum) is a commutative and monotonous version of\naddition. It is used as an auxiliary operation  for defining variants\nfor hydra battles, where Hercules is allowed to chop off any  head of the hydra.\n\nIn the litterature, the natural sum of ordinals \\(\\alpha\\) and \\(\\beta\\) \nis often denoted by \\(\\alpha \\# \\beta\\)  or  \\(\\alpha \\oplus  \\beta\\).\nThus we called \\texttt{oplus} the associated \\emph{Coq} function.\n\n\\subsubsection{Definition of \\texttt{oplus}}\n\\label{sec:orgheadline84}\n%\\index{Functions!oplus @ oplus (Hessenberg commutative sum)}\n\nThe definition of \\texttt{oplus} is recursive in both of its \narguments, which makes a structural recursive definition a little \ncomplex.\nWe used the same pattern as for the \\texttt{merge} function on lists of library\n\\texttt{Coq.Sorting.Mergesort}.\n\n\\begin{enumerate}\n\\item Define a nested recursive function, using the \\texttt{Fix} \n    construct\n\n\\item Build a principle of induction dedicated to \\texttt{oplus}\n\n\\item Establish equations associated to each case of the definition.\n\\end{enumerate}\n\n\\paragraph{Nested recursive definition}\n\\label{sec:orgheadline83}\n\nThe following definition is composed of \n\\begin{itemize}\n\\item A main function \\texttt{oplus}, structurally recursive in its \nfirst argument \\texttt{alpha}\n\\item An auxiliary function \\texttt{oplus\\_aux} within the scope of \\texttt{alpha},\nstructurally recursive in its argument \\texttt{beta};  \\texttt{oplus\\_aux beta} \n   is supposed to compute  \\texttt{oplus alpha beta}.\n\\end{itemize}\n  \n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Hessenberg.html\\#oplus}{Epsilon0.Hessenberg}}\n\n\\label{sect:infix-oplus}\n\n\\begin{Coqsrc}\nFixpoint oplus (alpha beta : T1) : T1 :=\n  let fix oplus_aux beta {struct beta} :=\n      match alpha, beta with\n        | zero, _ => beta\n        | _,  zero => alpha\n        | ocons a1 n1 b1, ocons a2 n2 b2 =>\n          match compare a1 a2 with\n            |  Gt => ocons a1 n1 (oplus b1 beta)\n            |  Lt => ocons a2 n2 (oplus_aux b2)\n            |  Eq => ocons a1 (S (n1 + n2)%nat) (oplus b1 b2)\n          end\n      end\n  in oplus_aux beta.\n\nInfix \"o+\" := oplus  (at level 50, left associativity).\n\\end{Coqsrc}\n\n\nThe reader will note that each recursive call of the functions\n\\texttt{oplus} and \\texttt{oplus\\_aux} satisfies \\emph{Coq}'s constraint\non recursive definitions. The function \\texttt{oplus} is recursively called on a sub-term of its first argument,\nand \\texttt{oplus\\_aux} on a sub-term of its unique argument.\nThus, \\texttt{oplus}'s definition is accepted by \\coq{} as a structurally recursive function.\n\n\\subsubsection{Rewriting Lemmas}\n\\label{sec:orgheadline86}\n\n\\emph{Coq}'s constraints on recursive definitions result in \nthe quite  complex form of \\texttt{oplus}'s definition.\nProofs of properties of this function can be simpler if we\n \\emph{derive} rewriting lemmas that will help to simplify \nexpressions of the form (\\texttt{oplus $a$ $ b$}).\n\nA first set of lemmas correspond to the various cases of \\texttt{oplus}'s \ndefinition. They can be proved almost immediately, using \\texttt{cbn} \nand \\texttt{reflexivity} tactics.\n\n\n\n\\begin{Coqsrc}\nLemma oplus_alpha_0 (alpha : T1) : alpha o+ zero = alpha.\nProof.\n  destruct alpha; reflexivity.\nQed.\n\nLemma oplus_0_beta (beta : T1): zero o+ beta = beta.\nProof.\n  destruct beta; reflexivity.\nQed.\n\\end{Coqsrc}\n\n\n% \\subsubsection{A hand-made induction principle}\n% \\label{sec:orgheadline85}\n\n% \\index{Coq!Commands!Functional Scheme}\n\n% \\emph{Coq} contains a command  \\texttt{Functional Scheme} that \n% generates induction principles which correspond to recursive functions.\n% Unfortunately, the current version ( \\texttt{8.11.0} ) doesn't work on \\texttt{oplus},\n% probably because of the inner \\texttt{Fix}.\n\n% \\begin{Coqsrc}\n% Functional Scheme oplus_ind := Induction for oplus Sort Prop.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% Error: Anomaly \"todo.\" Please report at http://coq.inria.fr/bugs/.\n% \\end{Coqanswer}\n\n\n% Fortunately, it's a good exercise for a semi-experienced user, to write\n% her/him-self induction principles similar to the ones returned by\n% \\texttt{Functional Scheme}.\n\n% \\begin{itemize}\n% \\item First, we choose to write a version for sort \\texttt{Type}, since versions\n% for sorts \\texttt{Prop} and \\texttt{Set} can be easily derived from\n% the former one. According to \\emph{Coq}'s naming politics, we will call our \n% principle \\texttt{oplus\\_rect}\n\n% \\item The conclusion of \\texttt{oplus\\_rect} will be (\\texttt{$P$ a b (oplus a b)}),\n% where $P$ is an arbitrary function of type \n% \\texttt{T1 -> T1 -> T1 -> Type}\n\n% \\item The premises of \\texttt{oplus\\_rect} will describe how to build an induction \n% on the graph of \\texttt{oplus}.\n% \\end{itemize}\n\n% We are now ready to state and prove \\texttt{oplus\\_rect}, and the reader\n% will note that the statement is longer than the proof script itself,\n% which is a standard proof by induction, simplification and case-analysis \n% that follows  \\texttt{oplus}'s definition.\n\n% We associate also a tactic to the application of \\texttt{oplus\\_rect}.\n\n% \\begin{Coqsrc}\n%  Lemma oplus_rect:\n%       forall P: T1 -> T1 -> T1 -> Type, \n%         (forall a:T1, P zero a a) ->\n%         (forall a: T1, P a zero a) ->\n%         (forall a1 n1 b1 a2 n2 b2 o,\n%            compare a1 a2 = Gt ->\n%            P b1 (ocons a2 n2 b2) o ->\n%            P (ocons a1 n1 b1) (ocons a2 n2 b2)\n%              (ocons a1 n1 o)) ->\n%         (forall a1 n1 b1 a2 n2 b2 o,\n%            compare a1 a2 = Lt ->\n%            P (ocons a1 n1 b1) b2 o ->\n%            P (ocons a1 n1 b1) (ocons a2 n2 b2) \n%            (ocons a2 n2 o)) ->\n%         (forall a1 n1 b1 a2 n2 b2 o,\n%            compare a1 a2 = Eq ->\n%            P b1 b2 o ->\n%           P (ocons a1 n1 b1) (ocons a2 n2 b2)\n%             (ocons a1 (S (n1 + n2)%nat) o)) ->\n%          forall a b, P a b (oplus a b).\n% Proof with auto.\n%    induction a.\n%    -    intro; simpl; destruct b;auto.\n%    -   induction b.\n%        + apply X0.\n%        + case_eq (compare a1 b1).\n%          * intro Comp; unfold oplus; rewrite Comp.\n%            cbn; apply X3 ...\n%          * intro Comp; cbn; rewrite Comp; apply X2...\n%          * intro Comp; cbn; rewrite Comp ...\n%  Defined.\n\n\n% Ltac oplus_induction a b:= pattern (oplus a b); apply oplus_rect.\n% \\end{Coqsrc}\n\n% \\index{Exercises}\n\n% \\begin{exercise}\n% The induction principle \\texttt{oplus\\_rect} is still unused in our development. \n% Please build some nice examples of application.\n% \\end{exercise}\n\n\\index{Projects}\n\\begin{project}\nCompare \\texttt{oplus}'s definition (with inner fixpoint) with other possibilities\n(\\texttt{coq-equations}, \\texttt{Function}, etc.).\n\\end{project}\n\\subsection{More Theorems on Hessenberg's Sum}\n\nWe need to prove some properties of $\\oplus$, particularly about \nits relation with the order $<$ on \\texttt{T1}.\n\n\\subsubsection{Boundedness}\nIf $\\alpha$ and $\\beta$ are both strictly  less than  $\\omega^\\gamma$, then so is their natural sum\n$\\alpha \\oplus \\beta$. This result can be proved by structural induction on $\\gamma$.\n\n\n\\begin{Coqsrc}\nLemma lt_phi0_oplus : forall gamma alpha beta,\n                        lt_phi0 alpha gamma ->\n                        lt_phi0 beta gamma ->\n                        lt_phi0 (alpha o+ beta) gamma.\n\nProof with auto.\n  induction gamma; destruct alpha, beta.  \n(* ... *)\n\\end{Coqsrc}\n\n\\subsubsection{Commutativity, Associativity}\n\nWe prove  the commutativity of $\\oplus$ in two steps. \n\nFirst, we prove by transfinite induction on $\\alpha$ that the restriction of $\\oplus$ to the\ninterval $[0..\\alpha)$ is commutative.\n\n\\index{Maths!Transfinite induction}\n\n\\begin{Coqsrc}\nLemma oplus_comm_0 : forall alpha, nf alpha ->\n     forall a b,  nf a -> nf b ->\n                  lt a alpha ->\n                  lt b alpha ->\n                  a o+ b = b o+ a.\n Proof with eauto with T1.\n    intros alpha Halph; transfinite_induction alpha.\n(* rest of proof omitted *)  \n\\end{Coqsrc}\n\nThen, we infer  $\\oplus$'s commutativity for any pair of ordinals:\nLet $\\alpha$ and $\\beta$ be two ordinals strictly less than $\\epsilon_0$. Both ordinals $\\alpha$ and $\\beta$ are\nstrictly less than $\\textrm{max}(\\alpha,\\beta)+1$.\n    Thus, we have just to apply the lemma \\coqsimple{oplus\\_comm\\_0}.\n\n\\begin{Coqsrc}\n  Lemma oplus_comm : forall alpha beta, \n      nf alpha -> nf beta ->\n      alpha o+ beta =  beta o+ alpha.\n  Proof with eauto with T1.\n    intros alpha beta Halpha Hbeta;\n    apply oplus_comm_0 with (succ (max alpha beta)) ...  \n  (* ... *)\n\\end{Coqsrc}\n\nThe associativity of Hessenberg's sum is proved the same way.\n\n\n\\begin{Coqsrc}\n Lemma oplus_assoc_0 :\n    forall alpha,\n      nf alpha ->\n      forall a b c,  nf a -> nf b -> nf c ->\n                      lt a alpha ->\n                      lt b alpha -> lt c alpha ->\n                      a o+ (b o+ c) = (a o+ b) o+ c.\n  Proof with eauto with T1.\n    intros alpha Halpha.\n    transfinite_induction alpha.\n    (* ... *)\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\n Lemma oplus_assoc : forall alpha beta gamma,\n                        nf alpha -> nf beta -> nf gamma ->\n                                    alpha o+ (beta o+ gamma) =\n                                    alpha o+ beta o+ gamma.\n Proof with eauto with T1.\n    intros;\n    apply oplus_assoc_0 with (succ (max alpha (max beta gamma))) ...\n    (* ... *)   \n\\end{Coqsrc}\n\n\n\\subsubsection{Monotonicity}\n\nAt last, we prove that $\\oplus$ is strictly monotonous in both of its arguments.\n\n\\begin{Coqsrc}\nLemma oplus_strict_mono_LT_l (alpha beta gamma : T1) :\n  nf gamma   -> alpha  t1< beta ->\n  alpha o+ gamma  t1< beta o+ gamma.\n\nLemma oplus_strict_mono_LT_r (alpha beta gamma : T1) :\n  nf alpha -> beta t1< gamma ->\n  alpha o+ beta t1< alpha o+ gamma.\n\\end{Coqsrc}\n\n\\index{Projects}\n\n\\begin{project}\nThe library \\texttt{Hessenberg} looks too long (proof scripts and compilation).\nPlease try to make it simpler and more efficient!\nThanks!\n\\end{project}\n\n\\subsection{A Measure for Hydra-battle Termination}\n\n\\label{sec:hydra-measure}\n\nLet us define a measure from type \\texttt{Hydra} into \\texttt{T1}.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Hydra_Termination.html\\#m}{Hydra.Hydra\\_Termination}}\n\n\\begin{Coqsrc}\nFixpoint m (h:Hydra) : T1 :=\n  match h with head => zero\n             | node hs => ms hs\nend \nwith ms (s:Hydrae) :  T1 :=\n  match s with  hnil => zero\n              | hcons h s' => phi0 (m h) o+  ms s'\n end.  \n\\end{Coqsrc}\n\nFirst, we prove that the measure $m(h)$  of any hydra $h$ is a well-formed ordinal term of type \\texttt{T1}.\n\n\\begin{Coqsrc}\nLemma m_nf : forall h, nf (m h).\nProof.\n intro h; elim h using Hydra_rect2 \n            with (P0 := fun s =>  nf (ms s)).\n (* ... *)\n\nLemma ms_nf : forall s, nf (ms s).\nProof with auto with T1.\n(* ... *)\n\\end{Coqsrc}\n\nFor proving the termination of all hydra battles, we have to prove that\n\\texttt{m} is a variant. First, a few technical lemmas follow the decomposition of \\texttt{round} into several relations. Then the lemma \\texttt{round\\_decr} gathers all the cases.\n\n\\begin{Coqsrc}\nLemma S0_decr :\n  forall s s', S0  s s' -> ms s' t1< ms s.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma R1_decr : forall h h',\n                  R1 h h' -> m h' t1< m h.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma S1_decr n:\n  forall s s', S1 n s s' -> ms s' t1<  ms s.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma R2_decr n : forall h h', R2 n h h' -> m h'  t1< m h.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma round_decr : forall h h', h -1-> h' -> m h' t1< m h.\nProof.\n   destruct 1 as [n [H | H]].\n   -  now apply R1_decr.\n   -  now apply R2_decr with n.\nQed.\n\\end{Coqsrc}\n\nFinally, we prove the termination of all (free) battles.\n\n\\label{thm:every-battle-terminates}\n\n\\begin{Coqsrc}\nGlobal Instance HVariant : Hvariant lt_wf free var.\nProof.\n split; intros; eapply round_decr; eauto.\nQed.\n\nTheorem every_battle_terminates: Termination.\nProof. \n  red; apply Inclusion.wf_incl with \n         (R2 := fun h h' =>  m h t1< m h').\n   red; intros;  now apply round_decr.\n   apply Inverse_Image.wf_inverse_image, T1_wf.\nQed.\n\\end{Coqsrc}\n\n\n\\section*{Conclusion}\n\nLet us recall three results we have proved so far.\n\\begin{itemize}\n\\item There exists a strictly decreasing variant which maps \\texttt{Hydra} into \nthe segment $[0,\\epsilon_0)$ for proving the termination of any hydra battle\n\\item There exists \\emph{no} such variant from \\texttt{Hydra} into \n$[0,\\omega^2)$, \\emph{a fortiori} into $[0,\\omega)$.\n\\end{itemize}\n\nSo, a  natural question is `` Does there exist any strictly decreasing variant mapping\ntype \\texttt{Hydra} into some interval $[0,\\alpha[$ (where $\\alpha <\\epsilon_0$) for proving the termination of all hydra battles''. The next chapter is dedicated to a formal proof that there exists no such $\\alpha$, even if we consider a restriction to the set of ``standard'' battles.\n\n\n\n\n\n\n%\\include{epsilon0}\n\n\n%\\include{impossibility-proofs}\n\n\n\n\n%-------------------------------------------------------------------\n\n\\chapter[The Ketonen-Solovay machinery]{Strolling inside \\texorpdfstring{$\\epsilon_0$}{Epsilon0}: The Ketonen-Solovay Machinery\\label{ks-chapter}}\n\\label{chap:ketonen}\n\\index{Maths!Ketonen-Solovay machinery}\n\n\\section{Introduction}\nThe reader may think that our proof of termination in the previous  chapter requires a lot of mathematical tools and may be too  complex. So, the question is ``is there  any  simpler proof'' ?\n\nIn their article~\\cite{KP82}, Kirby and Paris show that this result cannot be proved in Peano arithmetic. Their proof uses some knowledge about model theory and non-standard models of Peano arithmetic. In this chapter, we focus on a specific class of proofs of termination of hydra battles: construction of some variant mapping the type \\texttt{Hydra} into a given initial  segment of ordinals. Our proof relies only on the Calculus of Inductive Constructions and is a natural complement of the results proven in the previous chapter.\n\n\\begin{itemize}\n\\item There is no variant mapping the type \\texttt{Hydra} into the interval $[0,\\omega^2)$ (section ~\\vref{omega2-case}), and a fortiori \n$[0,\\omega)$ (section ~\\vref{omega-case}).\n\n\\item There exists a variant which maps the type \\texttt{Hydra} into the\ninterval $[0,\\epsilon_0)$ (theorem \\texttt{every\\_battle\\_terminates}, in section~\\vref{thm:every-battle-terminates}).\n\\end{itemize}\n\n\nThus, a very natural question is the following one:\n\\begin{quote}\n  `` Is there  any variant from\n\\texttt{Hydra} into some interval $[0,\\mu)$, where $\\mu<\\epsilon_0$, for proving the termination of all hydra battles ?''\n\\end{quote}\n\nWe prove in \\coq{} the following result:\n\n\\begin{quote}\nThere is no variant for proving the termination of all hydra battles\nfrom \\texttt{Hydra} into the interval $[0..\\mu)$, where\n$\\mu< \\epsilon_0$.\nThe same impossibility holds even if we consider only standard battles (with the successive replication factors $0,1,2,\\dots,t,t+1,\\dots$).\n\\end{quote}\n\nOur proofs are  constructive and require no axioms: they are  closed terms of the CIC, and are mainly composed on function definitions and proofs of properties of these functions. \nThey  share much theoretical material with Kirby and Paris', although they do not use any knowledge about Peano arithmetic nor model  theory.  The combinatorial arguments we use and implement\ncome from \n an article by J.~Ketonen and R.~Solovay~\\cite{KS81}, already  cited in the work\n by L.~Kirby et J.~Paris.% on the termination of Goodstein sequences and hydra battles~\\cite{KP82}.\n Section $2$ of this article: ''A hierarchy of probably recursive functions'', contains a systematic study of \\emph{canonical sequences}, which are closely related to\nrounds of hydra battles. \nNevertheless, they have the same global structure as the simple proofs described in\nsections~\\vref{omega-case} and \\vref{omega2-case}. \nWe invite the reader to compare the three proofs step by step, lemma by lemma.\n\n\\section{Canonical Sequences}\n\\label{ketonen-solovay-sect}\n\\index{Maths!Canonical sequences}\n\nCanonical sequences are functions that associate an ordinal $\\canonseq{\\alpha}{i}$ to every ordinal $\\alpha<\\epsilon_0$ and positive integer $i$. They satisfy several nice properties:\n\n\\index{Maths!Transfinite induction}\n\\begin{itemize}\n\\item If $\\alpha\\not=0$, then $\\canonseq{\\alpha}{i}<\\alpha$. Thus canonical sequences can be used for proofs by transfinite induction or function definition by transfinite recursion\n\\item If $\\lambda$ is a limit ordinal, then $\\lambda$ is the least upper bound of the set \n$\\{\\canonseq{\\lambda}{i}\\;|\\,i\\in\\mathbb{N}_1\\}$\n\n\n\\item If $\\beta<\\alpha<\\epsilon_0$, then there is a ``path'' from $\\alpha$ to $\\beta$, \\emph{i.e.} a\nsequence $\\alpha_0=\\alpha, \\alpha_1, \\dots, \\alpha_n=\\beta$, where for every $k<n$, there exists some $i_k$ such that $\\alpha_{k+1}=\\canonseq{\\alpha_k}{i_k}$\n\\item Canonical sequences correspond tightly to rounds of hydra battles: if $\\alpha\\not=0$,\nthen $\\iota(\\alpha)$ is transformed into $\\iota(\\canonseq{\\alpha}{i+1})$ in one round with\nthe replication factor $i$ (Lemma \\href{../theories/html/hydras.Hydra.O2H.html\\#canonS_iota_i}{Hydra.O2H.canonS\\_iota\\_i}).\n\\item From the two previous properties, we infer that whenever $\\beta<\\alpha<\\epsilon_0$, there exists a (free) battle from $\\iota(\\alpha)$ to $\\iota(\\beta)$.\n\\end{itemize}\n\n\\begin{remark}\n  In~\\cite{KS81}, canonical sequences are defined for any ordinal $\\alpha <\\epsilon_0$,\nby stating that if $\\alpha$ is a successor ordinal $\\beta+1$,  the sequence associated with \n$\\alpha$ is simply the constant sequence whose terms are equal to $\\beta$.\nLikewise, the canonical sequence of $0$ maps any natural number to $0$.\n\nThis convention allows us to make total the function that maps any ordinal $\\alpha$ and natural number $i$ to the ordinal $\\canonseq{\\alpha}{i}$.\n\n\\end{remark}\n\n\nFirst, let us recall how canonical sequences are defined in~\\cite{KS81}. For efficiency's sake, we decided not to implement directly K.\\&S's definitions, but to define in \\gallina{} simply typed structurally recursive functions which share the abstract properties which are used in the mathematical proofs\\footnote{With a small difference: the $0$-th term of the canonical sequence is not the same in our development as in~\\cite{KS81}.}.\n\n\n\n\n\n\\subsubsection{Mathematical Definition of Canonical Sequences} \n\nIn~\\cite{KS81} the definition of $\\canonseq{\\alpha}{i}$ is based on the following remark:\n\\begin{quote}\nAny non-zero ordinal $\\alpha$ can be decomposed in a unique way as the product\n$\\omega^\\beta\\times (\\gamma+1)$.\n\\end{quote}\n\nThus the $\\canonseq{\\alpha}{i}$\\,s are defined in terms of this decomposition:\n\\begin{definition}[Canonical sequences: mathematical definition]\n\\label{def:canonseq-math}\n  \n\\end{definition}\n\\begin{mathframe}\n  \\begin{itemize}\n\\item Let $\\lambda<\\epsilon_0$ be a limit ordinal \n\n\\begin{itemize}\n\\item If $\\lambda=\\omega^{\\alpha+1}\\times (\\beta+1)$, then \n$\\canonseq{\\lambda}{i}= \\omega^{\\alpha+1}\\times\\beta +  \\omega^\\alpha \\times i$\n\\item If $\\lambda=\\omega^{\\gamma}\\times (\\beta+1)$, where $\\gamma<\\lambda$ is a limit ordinal, then \n$\\canonseq{\\lambda}{i}=\\omega^{\\gamma}\\times \\beta + \\omega^{\\canonseq{\\gamma}{i}}$\n\\end{itemize}\n\n\\item For successor ordinals, we have $\\canonseq{\\alpha+1}{i}= \\alpha$ \n\n\\item Finally, $\\canonseq{0}{i}= \\alpha$.\n\\end{itemize}\n\\end{mathframe}\n\n\\subsubsection{Canonical Sequences in Coq}\n\nOur definition may look more complex than the mathematical one, but\nuses plain structural recursion over the type \\coqsimple{T1}. Thus, tactics like\n\\coqsimple{cbn}, \\coqsimple{simpl}, \\coqsimple{compute}, etc., are applicable. For simplicity's sake, \nwe use an auxiliary function \\texttt{canonS} of type \\texttt{T1 -> nat  -> T1} such that\n(\\texttt{canonS  $\\alpha$ $i$}) is equal to $\\canonseq{\\alpha}{i+1}$.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Canon.html\\#canonS}{Epsilon0.Canon}}\n\n\\label{Functions:canonS}\n\\label{Functions:canon}\n\\begin{Coqsrc}\nFixpoint canonS alpha (i:nat) :=\n  match alpha with\n      zero => zero\n    | ocons zero 0 zero => zero\n    | ocons zero (S k) zero => FS k\n    | ocons gamma 0 zero =>\n      match pred gamma with\n          Some gamma' => ocons gamma' i zero\n        | None => ocons (canonS gamma i) 0 zero\n      end\n    | ocons gamma (S n) zero =>\n       match pred gamma with\n           Some gamma' => ocons gamma n (ocons gamma' i zero)\n         | None => ocons gamma n (ocons (canonS gamma i) 0 zero)\n       end\n    | ocons alpha n beta => ocons alpha n (canonS beta i)\n  end.\n\\end{Coqsrc}\n\n\nThe following function computes $\\canonseq{\\alpha}{i}$, except for the case $i=0$, where it simply returns $0$\\;\\footnote{This restriction did not prevent us from proving all the main theorems of~\\cite{KS81, KP82}. Nevertheless, in a future version of this development, we may define $\\canonseq{\\alpha}{0}$ exactly as \nin~\\cite{KS81}. But we are afraid this would  be done at the cost of making some proofs much more complex.}.\n\n\\begin{Coqsrc}\n Definition canon alpha i := \n   match i with 0 => zero | S j => canonS alpha j end. \n\\end{Coqsrc}\n\nFor instance \\coq's computing facilities allow us to verify the equalities\\linebreak \n\\mathcolor{$\\canonseq{\\omega^\\omega}{3} = \\omega^3$} and\n\\mathcolor{$\\canonseq{\\omega^\\omega*3}{42} = \\omega^\\omega*2 + \\omega^{42}$}.\n\n\n\\begin{Coqsrc}\nCompute (canon (omega ^ omega) 3).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = phi0 (FS 2) : T1\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nExample canon3 :  canon (omega ^ omega) 3 = omega ^ 3.\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nCompute pp (canon (omega ^ omega * 3) 42).  \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = (omega ^ omega * 2 + omega ^ 42)%pT1\n     : ppT1\n\\end{Coqanswer}\n\n\\index{Projects}\n\\begin{project}\nMany lemmas presented in this chapter were stated and proved before the introduction of \nthe type class \\texttt{ON} of ordinal notations, and in particular its  instance \\texttt{Epsilon0}.\nThus definitions and lemmas refer to the type \\texttt{T1} of possibly not well-formed terms.\nThis should be fixed in  a future version.\n\\end{project}\n\n\n\\subsection{Basic Properties of Canonical Sequences}\n\nWe did not  try to prove that our definition really implements Ketonen and Solovay's  \\cite{KS81}'s canonical sequences. The most important is that we were able to prove the \nabstract properties  of canonical sequences that are really used in our proof. The complete proofs are in the module\n~\\href{../theories/html/hydras.Epsilon0.Canon.html}{Epsilon0.Canon}\n\n\nProving the equality $\\canonseq{\\alpha+1}{i}=\\alpha$ is not \nas simple as suggested by the equations of definition~\\ref{def:canonseq-math}\\,.\nNevertheless, we can prove it by  plain structural induction on $\\alpha$.\n\n\\begin{Coqsrc}\nLemma canonS_succ i alpha :\n  nf alpha ->  canonS (succ alpha) i = alpha.\nProof.\n induction alpha.\n (* ... *)\n\\end{Coqsrc}\n\n\\subsubsection{Canonical Sequences and the Order $<$}\n\n\\index{Maths!Transfinite induction}\n\nWe prove by transfinite induction over $\\alpha$ that $\\canonseq{\\alpha}{i+1}$ is an ordinal strictly less than $\\alpha$ (assuming $\\alpha\\not=0$). This property allows us to use the function \\texttt{canonS} and its derivates in function definitions by transfinite recursion.\n\n\\label{lemma:canonS_LT}\n\\begin{Coqsrc}\nLemma canonS_LT i alpha :\n  nf alpha -> alpha <> zero -> canonS alpha i t1<  alpha.\n\\end{Coqsrc}\n\n\n\\subsubsection{Limit Ordinals are Really Limits}\nThe following theorem states that any limit ordinal $\\lambda<\\epsilon_0$ \nis the limit of the sequence \\showmath{\\canonseq{\\lambda}{i}\\;(1\\le i)}.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Canon.html\\#canonS_limit_strong}{Epsilon0.Canon}}\n\n\n\\begin{Coqsrc}\nLemma canonS_limit_strong (lambda : T1) : \n     nf lambda ->\n     limitb lambda  ->\n     forall beta, beta t1< lambda ->\n                  {i:nat | beta t1< canonS lambda i}.\n\nProof.\n  transfinite_induction_LT lambda.\n  (* ... *)\nDefined.\n\\end{Coqsrc}\n\n\\label{lemma:canonS-limit}\n\n\nNote the use of \\coq's \\texttt{sig} type in the theorem's statement, which\nrelates the boolean function \\texttt{limitb} defined on the \\texttt{T1} data-type with a constructive view of the limit of a sequence: for any $\\beta<\\lambda$, we can compute an item of the canonical sequence of $\\lambda$ which is greater than $\\beta$.\nWe can also state directly that $\\lambda$ is a (strict) least upper bound of the elements of its canonical sequence.\n\n\n\\begin{Coqsrc}\nLemma canonS_limit_lub (lambda : T1) :\n  nf lambda -> limitb lambda  ->\n  strict_lub (fun i => canonS lambda i) lambda.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\\label{exo:simply-typed-canonseq}\nInstead of using the \\texttt{sig} type, define a simply typed function that, given two ordinals $\\alpha$ and $\\beta$, returns a natural number $i$ such that, if $\\alpha$ is a limit ordinal and $\\beta<\\alpha$, then $\\beta< \\canonseq{\\alpha}{i+1}$. Of course, you will have to prove the correctness of your function.\n\\end{exercise}\n\n\n\n\n\n\n\\section{Accessibility inside \\texorpdfstring{$\\epsilon_0$}{epsilon0} : Paths}\n\\index{Maths!Accessibility inside epsilon0}\n\\label{sect:pathes-intro}\n\nLet us consider a kind of accessibility problem inside $\\epsilon_0$: given two ordinals $\\alpha$ and $\\beta$, where $\\beta<\\alpha<\\epsilon_0$, find a \\emph{path} consisting of a finite sequence $\\gamma_0=\\alpha,\\dots,\\gamma_l=\\beta$,\nwhere, for every $i<l$, $\\gamma_i \\not= 0$ \\footnote{This condition allows us to ignore paths which end by a lot of useless $0$s.} and there exists some strictly positive integer $s_i$\nsuch that $\\gamma_{i+1}=\\canonseq{\\gamma}{s_i}$,\n\nLet $s$ be the sequence $\\langle s_0,s_1,\\dots, s_{l-1} \\rangle$. We describe the\nexistence of such a path with the notation $\\alpha\\xrightarrow [s]{}\\beta$.\n\n\nFor instance, we have $\\omega*2 \\xrightarrow[2,2,2,4,5]{}3$, through the \npath $\\langle\\omega\\times 2, \\omega+2,\\omega+1,\\omega,4,3\\rangle$.\n\n\n\\begin{remark}\n  \n\nNote that, given $\\alpha$ and $\\beta$, where $\\beta < \\alpha$, the sequence $s$ which leads from $\\alpha$ to $\\beta$ is not unique.\n\nIndeed, if $\\alpha$ is a limit ordinal, the first element of $s$ can be any integer $i$ such that $\\beta<\\canonseq{\\alpha}{i}$, and if $\\alpha$ is a successor ordinal,\nthen the sequence $s$ can start with any positive integer.\n\n\nFor instance, we have also \n$\\omega*2 \\xrightarrow[3,4,5,6]{}\\omega$. \nLikewise,\n$\\omega*2 \\xrightarrow[1,2,1,4]{} 0$ and\n$\\omega*2 \\xrightarrow[3,3,3,3,3,3,3,3]{} 0$.\n\\end{remark}\n\n\\subsection{Formal Definition}\n\n\\label{path-to-definition}\n\nIn \\coq{}, the notion of path can be simply defined as an inductive predicate \nparameterized by the destination $\\beta$.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Paths.html}{Epsilon0.Paths}}\n\n\\index{Predicates!path\\_to}\n\\label{sect:path-to-def}\n\n\\begin{Coqsrc}\n(Definition transition_S i : relation T1 :=\n  fun alpha beta =>  alpha <> zero /\\ beta = canonS alpha i.\n\nDefinition transition i : relation T1 :=\n  match i with 0 => fun _ _ => False | S j => transition_S j end.\n\nInductive path_to (beta: T1) : list nat -> T1 -> Prop :=\n  path_to_1 : forall (i:nat) alpha , \n    i <> 0 ->\n    transition i alpha beta ->\n    path_to beta (i::nil) alpha\n| path_to_cons : forall i alpha s gamma,\n    i <> 0 ->\n    transition i alpha gamma ->\n    path_to beta  s gamma ->\n    path_to beta  (i::s) alpha.\n\\end{Coqsrc}\n\n\\begin{remark}\nThe definition above is parameterized with the \\emph{destination} of the path and indexed by the origin, hence the name \\texttt{path\\_to}. The rationale behind this choice is a personal preference of the developer  for the kind of eliminators generated by \\coq{} in this case. The symmetric option could have been also considered (see also Remark~\\vref{remark:transitive-closure}).\n\\end{remark}\n\n\n\n\\begin{remark}\nIn the present version of our library, we use a variant \\texttt{path\\_toS} of\n\\texttt{path\\_to}, where the proposition\n(\\texttt{path\\_toS $\\beta$ $s$ $\\alpha$}) is equivalent to\n(\\texttt{path\\_to $\\beta$ (shift $s$) $\\alpha$}). This variant is scheduled to be deprecated.\n\\end{remark}\n\n\\index{Exercises}\n\n\\begin{exercise}\nWrite a tactic for solving goals of the form (\\texttt{path\\_to $\\beta$ $s$ $\\alpha$})\nwhere $\\alpha$, $\\beta$ and $s$ are closed terms. \nYou should solve automatically the following goals:\n\n\\begin{Coqsrc}\n path_to omega (2::2::2::nil) (omega * 2).\n\n path_to omega (3::4::5::6::nil) (omega * 2).\n\n path_to zero (interval 3 14) (omega * 2).\n\n path_to zero (repeat 3 8) (omega * 2).\n\\end{Coqsrc}\n\n\\end{exercise}\n\n\n\n\\subsection{Existence of a Path}\n\n\\index{Maths!Transfinite induction}\n\nBy transfinite induction on $\\alpha$, we prove that for any $\\beta<\\alpha$, \none can build a path from $\\alpha$ to $\\beta$ (in other terms, $\\beta$ is accessible from $\\alpha$).\n\n\\begin{Coqsrc}\nLemma LT_path_to (alpha beta : T1) :\n  beta t1< alpha -> {s : list nat | path_to beta s alpha}.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}[continuation of exercise~\\vref{exo:simply-typed-canonseq}]\nDefine a simply typed function for computing a path from $\\alpha$ to $\\beta$.\n\\end{exercise}\n\n\n\\noindent \nFrom the lemma \\texttt{canonS\\_LT}~\\vref{lemma:canonS_LT}, we can convert any path into an inequality on ordinals (by induction on paths).\n\n\n\\begin{Coqsrc}\nLemma path_to_LT beta s alpha :\n  path_to beta s alpha -> nf alpha -> beta t1< alpha.\n\\end{Coqsrc}\n\n\\subsection{Paths and Hydra Battles}\n\\label{KS-o2h}\n\nIn order to apply our knowledge about  ordinal numbers less than $\\epsilon_0$ to the study of hydra battles, we define an injection\nfrom the interval $[0,\\epsilon_0)$ into the type \\texttt{Hydra}.\n\n\\vspace{4pt}\n\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.O2H.html}{Hydra.O2H}}\n\n\n\\begin{Coqsrc}\nFixpoint iota (alpha : T1) : Hydra :=\n  match alpha with\n  | T1.zero => head\n  | ocons gamma n beta => \n         node (hcons_mult (iota gamma) (S n) (iotas beta))\n  end \nwith iotas (alpha : T1) :  Hydrae :=\n       match alpha with\n       | T1.zero => hnil\n       | ocons alpha0 n beta  => \n           hcons_mult (iota alpha0) (S n) (iotas beta)\n       end.\n\\end{Coqsrc}  \n\n\n\n\nFor instance Fig.~\\ref{fig:iota-example} shows the image by $\\iota$ of the ordinal  \\textcolor{black}{$\\omega^{\\omega+2}+\\omega^\\omega \\times 2 + \\omega + 1$}\n\n  \\begin{figure}[htb]\n\\centering\n\\begin{tikzpicture}[very thick, scale=0.3]\n\\node (foot) at (10,0) {$\\bullet$};\n\\node (N1) at (2,2) {$\\bullet$};\n\\node (N2) at (10,2) {$\\bullet$};\n\\node (N22) at (7,2) {$\\bullet$};\n\\node (N3) at (14,2) {$\\bullet$};\n\\node (N4) at (18,2) {$\\Smiley[2][green]$};\n\\node (N5) at (0,4) {$\\bullet$};\n\\node (N6) at (2,5) {$\\Smiley[2][green]$};\n\\node (N7) at (4,6) {$\\Smiley[2][green]$};\n\\node (N88) at (7,4) {$\\bullet$};\n\\node (N8) at (10,4) {$\\bullet$};\n\\node (N9) at (14,6) {$\\Smiley[2][green]$};\n\\node (N10) at (0,8) {$\\Smiley[2][green]$};\n\\node (N11) at (10,7) {$\\Smiley[2][green]$};\n\\node (N111) at (7,7) {$\\Smiley[2][green]$};\n\\draw (foot) to [bend left=10] (N1);\n\\draw (foot) -- (N2);\n\\draw (foot) -- (N22);\n\\draw (foot) -- (N3);\n\\draw (foot) -- (N4);\n\\draw (N1) to  (N5);\n\\draw (N1) to   [bend left=10] (N6);\n\\draw (N1) to   [bend right=20] (N7);\n\\draw (N2) to  (N8);\n\\draw (N22) to  (N88);\n\\draw (N8) to  (N11);\n\\draw (N88) to  (N111);\n\\draw (N3) to  (N9);\n\\draw (N5) to  (N10);\n\\end{tikzpicture}\n\\caption{The hydra $\\iota(\\omega^{\\omega+2}+\\omega^\\omega \\times 2 + \\omega + 1$) \\label{fig:iota-example}}\n\n\\end{figure}\n\n\nThe following lemma (proved in ~\\href{../theories/html/hydras.Hydra.O2H.html}{Hydra.O2H.v}) maps  canonical sequences to rounds of hydra battles.\n\n\n\\label{lemma:canonS-iota}\n\n\\begin{Coqsrc}\nLemma canonS_iota i alpha :\n    nf alpha -> alpha <> 0 ->\n    iota alpha -1-> iota (canonS alpha i).\n\\end{Coqsrc}\n                \n\nThe next step of our development extends this relationship to\nthe order $<$ on $[0,\\epsilon_0)$ on one side, and hydra battles on the other side.\n\n\n\\begin{Coqsrc}\nLemma path_to_battle alpha s beta :\n  path_to  beta  s alpha -> nf alpha ->\n  iota alpha -+-> iota beta.\n\\end{Coqsrc}\n\nAs a corollary, we are now able to transform any inequality $\\beta<\\alpha<\\epsilon_0$ into a (free) battle.\n\n\\begin{Coqsrc}\nLemma LT_to_battle alpha beta :\n    beta t1< alpha ->  iota alpha -+-> iota beta.\n\\end{Coqsrc}\n\n\\section{A  Proof of Impossibility}\n\nWe now have  the tools for proving that  there exists no variant bounded by some $\\mu<\\epsilon_0$ for proving the termination   of all battles. The proof we are going to show is a proof by contradiction. It  can\n be considered as a generalization of the\nproofs described in  sections~\\vref{omega-case} and \\vref{omega2-case}.\n\n\n\nIn the module \\href{../theories/html/hydras.Hydra.Epsilon0_Needed_Generic.html}{Hydra.Epsilon0\\_Needed\\_Generic}, we assume there exists some variant $m$ bounded by some ordinal $\\mu<\\epsilon_0$. This part of the development is parameterized by some class $B$ of battles, which will be instantiated later to \\texttt{free} or \\texttt{standard}.\n\n\n\n\n\\begin{Coqsrc}\nClass BoundedVariant (B:Battle) :=\n  {\n    mu:T1 ;\n    m: Hydra -> T1;\n    mu_nf: nf mu;\n    Hvar: Hvariant T1_wf B m;\n    m_bounded: forall h, m h t1< mu\n  }.\n\\end{Coqsrc}\n\nLet us assume there exists such a variant:\n\n\\begin{Coqsrc}\nSection Bounded.\n  Context (B: Battle) (Hy : BoundedVariant B).\n\n  Hypothesis m_decrease : forall  i h h',\n        round_n i h h' -> m h' t1< m h.\n\\end{Coqsrc}\n\n\\label{remark:m-decrease}\n\\begin{remark}\n  The hypothesis \\texttt{m\\_decrease} is not provable  in general, but is satisfied by\nthe  \\texttt{free} and \\texttt{standard} kinds of battles. This trick allows to \n``factorize'' our proofs  of impossibility.\n\\end{remark}\n\n\\index{Maths!Transfinite induction}\n\nFirst, we prove that $m(\\iota(\\alpha))$ is always greater than or equal to $\\alpha$, by  transfinite induction over $\\alpha$.\n\n\\begin{Coqsrc}\nLemma m_ge_0 alpha:  nf alpha -> alpha t1<= m (iota alpha).\n\\end{Coqsrc}\n\n\n\\begin{itemize}\n\\item If $\\alpha=0$, the inequality trivially holds\n\\item If $\\alpha$ is the successor of  some ordinal $\\beta$, the inequality $\\beta \\leq m(\\iota(\\beta))$ holds (by induction hypothesis). But the hydra $\\iota(\\alpha)$ is transformed in one round into \n$\\iota(\\beta)$, thus $m(\\iota(\\beta))<m(\\iota(\\alpha))$. Hence $\\beta<m(\\iota(\\alpha))$, which implies $\\alpha \\leq m(\\iota(\\alpha))$\n\\item If $\\alpha$ is a limit ordinal, then $\\alpha$ is the least upper bound of the set\nof all  the $\\canonseq{\\alpha}{i}$.  Thus, we have just to prove that $\\canonseq{\\alpha}{i}< m(\\iota(\\alpha))$ for any $i$. \n\\begin{itemize}\n\\item Let $i$ be some natural number.\nBy the induction hypothesis, we have $\\canonseq{\\alpha}{i} \\leq m(\\iota(\\canonseq{\\alpha}{i}))$. But the hydra $\\iota(\\alpha)$ is transformed into $\\iota(\\canonseq{\\alpha}{i})$ in one round, thus $m(\\iota(\\canonseq{\\alpha}{i})) < m(\\iota(\\alpha))$, by our hypothesis \\texttt{m\\_decrease}.\n\\end{itemize}\n\\end{itemize}\n\nPlease note that the impossibility proofs of \nsections~\\vref{omega-case} and \\vref{omega2-case} contain a similar lemma, also called \\texttt{m\\_ge}.\nWe are now able to build a counter-example.\n\n\\begin{Coqsrc}\n  Definition big_h := iota mu.\n  Definition beta_h := m big_h.\n  Definition small_h := iota beta_h.\n\\end{Coqsrc}\n  \nFrom Lemma \\texttt{m\\_ge\\_0} we infer the following inequality :\n\n\\begin{Coqsrc}\n    Corollary m_ge_generic : m big_h t1<= m small_h.\n \\end{Coqsrc}\n\nThe (big) rest of the proof is dedicated to prove formally the converse inequality \n\\texttt{m small\\_h t1< m big\\_h}. \n\n\n\n\\subsection{The case of Free Battles}\n\\label{sec:free-battles-case}\nLet us now consider that $B$ is instantiated to \\texttt{free} (which means that we are considering proofs of termination of \\emph{all} battles). The following lemmas are proved in Module~\\href{../theories/html/hydras.Hydra.Epsilon0_Needed_Free.html}{Hydra.Epsilon0\\_Needed\\_Free}.\nThe case $B=\\texttt{standard}$ is studied in section~\\vref{std-case}.\n\n\n\n\\begin{Coqsrc}\nSection Impossibility_Proof.\n\n  Context (Var : BoundedVariant free ).\n  \\end{Coqsrc}\n\n\n\\begin{enumerate}\n\\item The following lemma is an application of \\texttt{m\\_ge\\_generic}, since \\texttt{free}\nsatisfies trivially the hypothesis \\texttt{m\\_decrease} (see page~\\pageref{remark:m-decrease}).\n\n\\begin{Coqsrc}\nLemma m_ge : m big_h t1<= m small_h.\n  Proof.\n    apply m_ge_generic.\n   (* ... *)\n\\end{Coqsrc}\n\n\\item From the hypothesis \\texttt{m\\_bounded}, we have \\texttt{m big\\_h t1< mu}\n\\item By Lemma \\texttt{LT\\_to\\_battle}, we get a (free) battle from\n\\texttt{big\\_h = iota mu} to \\texttt{small\\_h = iota (m big\\_h)}.\n\n\\begin{Coqsrc}\n  Lemma  big_to_small : big_h  -+-> small_h.\n\\end{Coqsrc}\n\\item From the hypotheses on $m$, we infer:\n\n\\begin{Coqsrc}\nLemma m_lt : m small_h t1< m big_h.\n\\end{Coqsrc}\n\n\n\\item From lemmas \\texttt{m\\_ge} and \\texttt{m\\_lt}, and the irreflexivity of $<$, we get a contradiction. \n\n  \\begin{Coqsrc}\nTheorem Impossibility_free : False.\n\nEnd Impossibility_Proof.\n\\end{Coqsrc}\n\n\n\\end{enumerate}\n\nWe have now proved there exists no bounded variant for the class of free battles.\n\n \n\\begin{Coqsrc}\nCheck Impossibility_free.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  Impossibility_free\n     : BoundedVariant free -> False\n\\end{Coqanswer}\n%%% ICI\n  \n\n\n\n\\section{The Case of Standard Battles}\n\\label{sec:standard-intro}\\label{std-case}\nOne may wonder if our theorem holds also in the framework of standard battles. Unfortunately, its proof relies on the lemma \\texttt{LT\\_to\\_round\\_plus} of\nModule~\\href{../theories/html/hydras.Hydra.O2H.html}{Hydra.O2H}.\n\n\\begin{Coqsrc}\nLemma LT_to_round_plus alpha beta :\n    beta t1< alpha ->  iota alpha -+-> iota beta.\n\\end{Coqsrc}\n\nThis lemma builds a battle out of any inequality $\\beta<\\alpha$. \nIt is a straightforward application of \\texttt{LT\\_path\\_to} of\nModule~\\href{../theories/html/hydras.Epsilon0.Paths.html}{Epsilon0.Paths}:\n\n\\begin{Coqsrc}\nLemma LT_path_to (alpha beta : T1) :\n  beta t1< alpha -> {s : list nat | path_to beta s alpha}.\n\\end{Coqsrc}\n\nThe sequence $s$, used to build the sequence of replication factors of the battle depends on \n$\\beta$, so we cannot be sure that the generated battle is a genuine standard battle.\n\n\nThe solution of this issue comes  once again from Ketonen and Solovay's article~\\cite{KS81}. Instead of considering plain paths, i.e. sequences \n$\\alpha_0=\\alpha,\\alpha_1,\\dots,\\alpha_k=\\beta$ where $\\alpha_{j+1}$ is equal\nto $\\canonseq{\\alpha_j}{i_j}$ where $i_j$ is \\emph{any} natural number, \nwe consider various constraints on these sequences.\nIn particular, a path is called \\emph{standard} if $i_{j+1} = i_j + 1$ for every $j<k$.\nIt  corresponds to a ``segment'' of some standard battles. \nPlease note that the vocabulary on paths is ours, but all the concepts come really from~\\cite{KS81}.\n\nIn \\coq{}, standard paths can be defined as follows.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.KS.html}{Epsilon0.KS}}\n\n\\begin{Coqsrc}\n(**  standard path from (i, alpha) to (j, beta) *)\n\nInductive standard_pathR(j:nat)( beta:T1):  nat -> T1 -> Prop :=\n  std_1 : forall i alpha, \n       beta = canon alpha i -> j = S i ->\n       standard_pathR j beta i  alpha\n| std_S : forall i alpha, \n      standard_pathR j beta (S i) (canon alpha i)  ->\n      standard_pathR j beta i alpha.\n\nDefinition standard_path  i alpha j beta := \n   standard_pathR j beta i alpha.\n\\end{Coqsrc}\n\nIn the mathematical text and figures, we shall use the notation \n$\\alpha \\xrightarrow[i,j]{}\\beta$ for the proposition \n(\\texttt{standard\\_path $i$ $\\alpha$ $j$ $\\beta$}).\nIn~\\cite{KS81} the notation is\n$\\alpha \\xrightarrow[i]{*}\\beta$\nfor \nthe proposition  $\\exists j, i<j \\wedge \\alpha \\xrightarrow[i,j]{} \\beta$.\n\n\n\nOur goal is now  to transform any inequality $\\beta<\\alpha<\\epsilon_0$ into a standard path $\\alpha \\xrightarrow[i,j]{} \\beta$ for some $i$ and $j$, then into a standard battle\nfrom $\\iota(\\alpha+i)$ to $\\iota(\\beta)$. \nFollowing~\\cite{KS81}, we proceed in two stages:\n\\begin{enumerate}\n\\item we simulate plain (free) paths from $\\alpha$ to $\\beta$ with\npaths made of steps $(\\gamma,\\canonseq{\\gamma}{n})$, \\emph{with the same $n$ all along the path}\n\\item we simulate any such path by a standard path.\n\\end{enumerate}\n\n\n\n\\subsection{Paths with a Constant Index}\n\nFirst of all, paths with a constant index \nenjoy nice properties. They are defined as paths where all the $i_j$ are equal to the same natural number $i$, for some $i>0$. \n\n\nLike in~\\cite{KS81}, we shall use the notation $\\alpha \\xrightarrow[i]{} \\beta$ for denoting such a path, also called an $i$-path.\n\n\\begin{Coqsrc}\nDefinition const_pathS i :=\n    clos_trans_1n T1 (fun alpha beta => beta = canonS alpha i).\n\nDefinition const_path i alpha beta :=\n  match i with\n    0 => False\n  | S j => const_pathS j alpha beta\nend.\n\\end{Coqsrc}\n\n% Paths with a given index can be effectively computed.\n% Given $i$, $\\alpha$ and $l$, the following function returns the ordinal $\\beta$ such that there exists a path \n% $\\alpha \\xrightarrow [i+1] {} \\beta$ of length $l$. \n\n% \\begin{Coqsrc}\n% Fixpoint const_funS (i:nat)(alpha : T1)(l:nat):  T1  :=\n%   match l\n%   with\n%   | 0 => alpha\n%   | S m => const_funS i (canonS i alpha) m\n%   end.\n% \\end{Coqsrc}\n\n% The following computations show  applications of \\texttt{constS\\_fun} to the \n% ordinal $\\omega^\\omega$, with various values of $i$ and $l$.\n\n% \\begin{Coqsrc}\n% Compute  (const_funS 2 (omega ^omega)  55).\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = zero\n%      : T1 \n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute pp (const_funS 2 (omega ^omega) 15).\n% \\end{Coqsrc}\n\n%   \\begin{Coqanswer}\n%  = (omega ^ 2 * 2)%pT1\n%      : ppT1   \n%   \\end{Coqanswer}\n\n\n% \\begin{Coqsrc}\n% Compute pp (const_funS 4 (omega^omega)  100).\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = (omega ^ 4 * 4 + omega ^ 3 * 4 + omega ^ 2 + omega * 4 + 4)%pT1\n%      : ppT1\n% \\end{Coqanswer}\n\n\n\n\nA most interesting property of $i$-paths is that we can ``upgrade'' their index, as stated by K.\\&S.'s Corollary 12.\n\n\\index{Maths!Transfinite induction}\n\n\\begin{Coqsrc}\nCorollary Cor12 (alpha : T1) :  nf alpha ->\n         forall beta i n, beta  t1< alpha  ->\n                i < n ->\n                 const_pathS i alpha beta ->\n                 const_pathS n alpha beta.\nProof.\n  transfinite_induction_lt alpha.\n  (* (long) proof skipped *)\n\\end{Coqsrc}\n\nWe  also use a version of \\texttt{Cor12} with large inequalities.\n\n\n\\begin{Coqsrc}\nCorollary Cor12_1 (alpha : T1) :\n  nf alpha ->\n  forall beta i n, beta t1< alpha ->\n                   i <= n ->\n                   const_pathS i alpha beta ->\n                   const_pathS n alpha beta.\n\\end{Coqsrc}\n\n\n\\subsubsection{Sketch of Proof of \\texttt{Cor12}}\n\\index{Maths!Transfinite induction}\n\nWe prove this lemma by transfinite induction on $\\alpha$.\nLet us consider a path $\\alpha \\xrightarrow [i]{} \\beta$ $(i>0)$. Its first step is\nthe pair $(\\alpha,\\canonseq{\\alpha}{i})$, We have $\\canonseq{\\alpha}{i}<\\alpha$ and\n$\\canonseq{\\alpha}{i} \\xrightarrow [i]{} \\beta$. \nLet $n$ be any natural number such that $n>i$.\nBy the induction hypothesis, there exists a path $\\canonseq{\\alpha}{n} \\xrightarrow[i]{} \\beta$.\n\\begin{itemize}\n\\item  If $\\alpha$ is a successor ordinal $\\gamma+1$, then $\\canonseq{\\alpha}{n} =\n\\canonseq{\\alpha}{i}=\\gamma$. Thus we have a path \n$\\alpha  \\xrightarrow [n]{}  \\gamma \\xrightarrow [n]{} \\beta$\n\\item If $\\alpha$ is a limit ordinal, we apply the following theorem (numbered \\texttt{2.4} in Ketonen and Solovay's article). \n\n%   \\begin{theorem}\n% Let $\\lambda$ be a limit ordinal, then for any pair of indices $0<i<j$, there is a path $\\canonseq{\\lambda}{j} \\xrightarrow[1]{} \\canonseq{\\lambda}{i}$.    \n%   \\end{theorem}\n\n\n  \\begin{Coqsrc}\nTheorem Theorem_2_4 (lambda : T1) :\n   nf lambda ->\n   limitb lambda  ->\n   forall i j, (i < j)%nat ->\n               const_pathS 0 (canonS lambda j)\n                             (canonS lambda i). \n  \\end{Coqsrc}\n\n We build the following paths :\n\n \\begin{enumerate}\n \\item $\\alpha \\xrightarrow[n]{} \\canonseq{\\alpha}{n}$\n \\item $\\canonseq{\\alpha}{n} \\xrightarrow[1]{} \\canonseq{\\alpha}{i}$ (by \\texttt{Theorem\\_2\\_4}),\n\\item $\\canonseq{\\alpha}{n} \\xrightarrow[n]{} \\canonseq{\\alpha}{i}$ (applying the induction hypothesis to the preceding path);\n\\item $\\canonseq{\\alpha}{i} \\xrightarrow[n]{} \\beta$ (applying the induction hypothesis)\\item $\\alpha \\xrightarrow[n]{} \\beta$ (by composition of 1, 3, and 4).\n\n\n \\end{enumerate}\n\n\n\\end{itemize}\n\n\n\n\n\n\\begin{remark}\n \\texttt{Cor12} ``casts'' $i$-paths into $n$-paths for any $n>i$.\nBut the obtained $n$-path can be much longer than the original $i$-path.\nThe following exercise will give an idea of this increase. \n\\end{remark}\n\n\\index{Exercises}\n\\begin{exercise}\n  Prove that  the length of the $i+1$-path from\n  $\\omega^\\omega$ to $\\omega^i$ is $1 + (i+1)^{(i+1)}$, for any $i$. Note that the $i$-path from\n  $\\omega^\\omega$ to $\\omega^i$ is only one step long.\n \\end{exercise}\n\n\nWhy is \\texttt{Cor12} so useful? \nLet us  consider two ordinals  $\\beta<\\alpha<\\epsilon_0$. By induction on $\\alpha$,\nwe decompose any inequality $\\beta<\\alpha$ into $\\beta < \\canonseq{\\alpha}{i}< \\alpha$, where $i$ is some integer. Applying collorary \\texttt{Cor12'} we build a $n$-path from $\\beta$ to $\\alpha$,\nwhere $n$ is the maximum of the indices $i$ met in the induction.\n\n Lemma 1, Section 2.6 of~\\cite{KS81} is naturally expressed in terms of \\coq's\n\\verb@sig@ construct.\n\n\\label{lemma:L-2_6-1}\n\\index{Coq!Techniques!Sigma types}\n\n\\begin{Coqsrc}\nLemma Lemma2_6_1 (alpha : T1) :  \n  nf alpha -> forall beta,  beta t1< alpha  ->\n  {n:nat | const_pathS n alpha beta}.\nProof.\n  transfinite_induction alpha.\n  (* ... *)\n\\end{Coqsrc}\n\n\n\nIntuitively, lemma   \\texttt{L2\\_6\\_1}  shows that if $\\beta<\\alpha<\\epsilon_0$, then there exists  a battle from $\\iota(\\alpha)$ to $\\iota(\\beta)$ where the replication factor is constant, although large enough. \n\n\n\n\n\n\n\n\\subsection{Casting Paths with a Constant Index into a Standard Path}\n\n%%% traduire la v.f.  (voir %%% A traduire %%%% )\n\nThe article~\\cite{KS81} contains \nthe following lemma, the proof of which is quite complex, which allows to simulate $i$-paths by $[i+1,j]$-paths, where $j$ is large enough.\n\n\n\\begin{Coqsrc}\n(* Lemma 1 page 300 of [KS] *)\n\nLemma constant_to_standard_path \n  (alpha beta : T1) (i : nat):\n  nf alpha -> const_pathS i alpha beta -> zero  t1< alpha ->\n  {l:nat | standard_path (S i) alpha j beta}.\n\\end{Coqsrc}\n\n \n\n\\subsubsection{Sketch of Proof of \\texttt{constant\\_to\\_standard\\_path}}\n\nOur proof follows the proof by Ketonen and Solovay, including its organization as a sequence of lemma.  Since it is a non-trivial proof, we will comment its main steps below.\n\n\\subsubsection*{Préliminaries}\n\n\nPlease note that, given an ordinal $\\alpha:\\texttt{T1}$, and two natural numbers $i$ and $l$, there exists at most a standard path $\\alpha \\xrightarrow [i,i+l]{*} \\beta$.\nThe following function computes $\\beta$ from $\\alpha$, $i$ and $l$.\n\n\\begin{Coqsrc}\nFixpoint standard_gnaw (i:nat)(alpha : T1)(l:nat):  T1  :=\n  match l with\n  | 0 => alpha\n  | S m => standard_gnaw (S i) (canon alpha i) m\n  end.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\n  Compute standard_gnaw 2 omega 15.\n(*   = zero\n     : T1 *)\nCompute pp (standard_gnaw 2 (omega^omega)  10).\n(*\n= (omega + 7)%pT1\n     : ppT1\n*)\nCompute pp (standard_gnaw 4 (omega^omega)  100).\n(*\n = (omega ^ 3 * 4 + omega ^ 2 * 5 + omega * 3 + 39)%pT1\n     : ppT1 *)\n\\end{Coqsrc}\n\n\\index{Maths!Transfinite induction}\n\nBy transfinite induction over  $\\alpha$, we prove that the ordinal $0$ is reachable from any ordinal $\\alpha<\\epsilon_0$ by some standard path.\n\n\n\\begin{Coqsrc}\nLemma standard_path_to_zero :\n  forall  alpha i, nf alpha ->\n                   {j: nat | standard_path (S i) alpha j zero}.\n\\end{Coqsrc}\n\n\\paragraph*{}\nNoq, let us consider two ordinals  $\\beta<\\alpha<\\epsilon_0$.  Let $p$  be some $(n+1)$-path from $\\alpha$ to $\\beta$.\n\n\\begin{Coqsrc}\n Section Constant_to_standard_Proof.\n\n  Variables (alpha beta: T1) (n : nat).\n  Hypotheses (Halpha: nf alpha) (Hpos : zero t1<  beta)\n             (p : const_pathS n alpha  beta).\n\\end{Coqsrc}\n\nApplying \\texttt{standard\\_path\\_to\\_zero}, $0$ is reachable from $\\alpha$ by some standard path  (see figure~\\vref{fig:belle-preuve-1}).\n\n\\begin{figure}[h]\n  \\centering\n \n\\begin{tikzpicture}[very thick, scale=0.25]\n\\node (alpha) at (0,0) {$\\alpha$};\n    \\node (beta) at (32, 0){$\\beta$};\n  \n\n  \\draw[->, very thick,blue] (alpha)-- node [below]{$n+1$} node [above] {$+$} (beta);\n\n  \\node (alpha1) at (5,5) {};\n  \\node (alpha2) at (13,5) {};\n    \\node (alpha3) at (20,5) {};\n  \\node (alphalast) at (35,5) {};\n  \\node (zero) at (45,0) {$0$};\n  \\draw [->, dashed,very thick,blue] (alpha)-- node [below, rotate=40]{$n+1$}  (alpha1);\n  \\draw [->, dashed,very thick,blue] (alpha1)-- node [below]{$n+2$}  (alpha2);\n   \\draw [->, dashed,very thick,blue] (alpha2)-- node [below]{$n+3$}  (alpha3);\n  \n  \\node (dots) at (24,5) {$\\dots$};\n  \\draw [->, dashed, very thick,blue] (alphalast)-- node [below, rotate=-26]{$n+p+1$}  (zero);\n\n\\end{tikzpicture}\n\\caption{A nice proof (1)}\n  \\label{fig:belle-preuve-1}\n\\end{figure}\n\n\n\\paragraph*{}\n\n\n\n\nSince comparison on \\texttt{T1} is decidable, one can compute the last step $\\gamma$ of the standard path from $(\\alpha,n+1)$  such that $\\beta\\leq \\gamma$.\nLet $l$ be the length of the path from $\\alpha$ to $\\gamma$.  \nThis step of the proof is illustrated in figure~\\vref{fig:belle-preuve-2}.\n\n\n\n\\begin{figure}[h]\n  \\centering\n \n\n\\begin{tikzpicture}[very thick, scale=0.25]\n\\node (alpha) at (0,0) {$\\alpha$};\n    \\node (beta) at (32, 0){$\\beta$};\n  \n\n\n\n  \\node (alpha1) at (5,5) {};\n  \\node (alpha2) at (13,5) {};\n  \\node (dots) at (17,5) {$\\ldots$};\n    \\node (alpha3) at (20,5) {};\n    \\node (gamma) at (24,0) {$\\gamma$};\n    \\node (delta) at (38,0) {$\\delta$};\n    \\draw [->, dashed,very thick,blue] (alpha)-- node [below,rotate=35]{$n+1$}  (alpha1);\n  \\draw [->, dashed,very thick,blue] (alpha1)-- node [below]{$n+2$}  (alpha2);\n   \\draw [->, dashed,very thick,blue] (alpha3)-- node [below,rotate = -48]{\\tiny $n+l$}  (gamma);\n   \\draw  [->, dashed, blue] (gamma) to    [bend left=80] node [below]{$n+l+1$} (delta);\n   \\draw[->, very thick,blue] (alpha) to [bend right=34] node [below]{$n+1$} node [above] {$+$} (beta);\n   \\draw[thick] (alpha)--  (gamma);\n   \\draw[thick] (gamma)--  node [above] {$\\geq$} (beta);\n    \\draw[thick] (beta)--  node [above] {$>$} (delta);\n\\end{tikzpicture}\n\n\\caption{A nice proof (2)}\n  \\label{fig:belle-preuve-2}\n\\end{figure}\n\n\\paragraph*{}\n\n\\begin{itemize}\n\\item If $\\beta=\\gamma$, its OK! We have got a standard path\nfrom  \n$\\alpha$ to $\\beta$ with successive indices  $n+1, n+2, \\dots, n+l+1$\n\n\\item Otherwise,  $\\beta < \\gamma$.  Let us consider  $\\delta=\\canonseq{\\gamma}{n+l+1}$.\nBy applying several times lemma \\texttt{Cor12},  one converts  every path of Fig~\\ref{fig:belle-preuve-2} into\n a $n+l+1$-path  (see figure~\\ref{fig:belle-preuve-3}).\n\n\nBut $\\gamma$ is on the $n+l+1$-path from $\\alpha$ to $\\beta$.\nAs shown by figure~\\vref{fig:fin-belle-preuve}, the ordinal $\\delta$, reachable from\n$\\gamma$ in one single step,  must be greater than or equal to $\\beta$, which contradicts our  hypothesis $\\beta < \\gamma$.\n\n\n\\begin{figure}[h]\n  \\centering\n  \n\\begin{tikzpicture}[very thick, scale=0.25]\n\\node (alpha) at (0,0) {$\\alpha$};\n    \\node (beta) at (32, 0){$\\beta$};\n    \\node (alpha1) at (5,5) {};\n  \\node (alpha2) at (13,5) {};\n  \\node (dots) at (17,5) {$\\ldots$};\n    \\node (alpha3) at (20,5) {};\n    \\node (gamma) at (24,0) {$\\gamma$};\n    \\node (delta) at (38,0) {$\\delta$};\n     \\draw [->, dashed,very thick,blue] (alpha)-- node [below, rotate = 40] {\\tiny $n+l+1$}  node [above, rotate = 40]{\\tiny $+$}  (alpha1);\n  \\draw [->, dashed,very thick,blue] (alpha1)-- node [below]{\\tiny $n+l+1$} node [above]{\\tiny $+$} (alpha2);\n   \\draw [->, dashed,very thick,blue] (alpha3)-- node [below, rotate = -48]{\\tiny $n+l+1$} node [above, rotate = -36]{\\tiny $+$}  (gamma);\n   \\draw  [->, dashed, blue] (gamma) to    [bend left=80] node [below]{\\tiny $n+l+1$} node [above]{\\color{red} $1$} (delta);\n   \\draw[->, very thick,blue] (alpha) to [bend right=34] node [below]{\\small $n+l+1$} node [above] {\\tiny $+$} (beta);\n    \\draw[thick] (gamma)--   node [above]{\\color{red} $>$}(beta);\n   \\draw[thick] (alpha)--  (gamma);\n  \n    \\draw[thick] (beta)--  node [above] {$>$} (delta);\n\n  \n  \n\\end{tikzpicture}\n\n\\caption{A nice proof (3)}\n  \\label{fig:belle-preuve-3}\n\\end{figure}\n\n\n\\begin{figure}[h]\n  \\centering\n\\begin{tikzpicture}[very thick, scale=0.25]\n\\node (alpha) at (0,0) {$\\alpha$};\n    \\node (beta) at (32, 0){$\\beta$};\n  \n  \\node (alpha1) at (5,5) {};\n  \\node (alpha2) at (13,5) {};\n  \\node (dots) at (15,5) {$\\ldots$};\n    \\node (alpha3) at (18,5) {};\n    \\node (gamma) at (24,0) {$\\gamma$};\n    \\node (delta) at (42,0) {$\\delta$};\n    \\draw [->, dashed,very thick,blue] (alpha)-- node [below, rotate = 40] {\\tiny $n+l+1$}  node [above, rotate = 40]{\\tiny $+$}  (alpha1);\n  \\draw [->, dashed,very thick,blue] (alpha1)-- node [below]{\\tiny $n+l+1$} node [above]{\\tiny $+$} (alpha2);\n   \\draw [->, dashed,very thick,blue] (alpha3)-- node [below, rotate = -36]{\\tiny $n+l+1$} node [above, rotate = -36]{\\tiny $+$}  (gamma);\n   \\draw  [->, dashed, blue] (gamma) to    [bend left=80] node [below]{\\small $n+l+1$} node [above]{\\color{red} $1$} (delta);\n   \\draw[->, very thick,blue] (alpha) to [bend right=34] node [below]{\\small $n+l+1$} node [above] {\\tiny $+$} (beta);\n   \\draw[thick] (alpha)--  (gamma);\n  \n    \\draw[thick] (gamma)--  node [below]{\\tiny $n+l+1$} node [above]{\\color{red} $+$}(beta);\n    \\draw[thick] (beta)--  node [above] {$>$} (delta);\n\n\\end{tikzpicture}\n\n\\caption{A nice proof (4)}\n  \\label{fig:fin-belle-preuve}\n\\end{figure}\n\n\n\\end{itemize}\n The only possible case is  thus $\\beta=\\gamma$, so we have got a standard path  from $\\alpha$ to $\\beta$.\n\n\n\\begin{Coqsrc}\n Lemma constant_to_standard_0 : \n    {l : nat | standard_fun (S n) alpha l = beta}.\n (* ... *)\n\nEnd Constant_to_standard_Proof.\n\\end{Coqsrc}\n\nHere is the full statement of the conversion from constant to standard paths.\n\n\\begin{Coqsrc}\nLemma constant_to_standard_path \n  (alpha beta : T1) (i : nat):\n  nf alpha -> const_pathS i alpha beta -> zero  t1< alpha ->\n  {j:nat | standard_path (S i) alpha j beta}.\n\\end{Coqsrc}\n\n\n\n\nApplying \\texttt{Lemma2\\_6\\_1} and \\texttt{constant\\_to\\_standard\\_path}, we get the following corollary.\n\n\\begin{Coqsrc}\nCorollary  LT_to_standard_path  (alpha beta : T1) :\n  beta t1< alpha ->\n  {n : nat & {j:nat | standard_path (S n) alpha j beta}}.\n\\end{Coqsrc}\n\n\n\\subsection{Back to Hydras}\n\\label{sec:standard-battles-cases}\nWe are now able to complete our proof that there exists no bounded variant for proving the termination of standard hydra battles. This proof can\nbe consulted in the module \n\\url{../theories/html/hydras.Hydra.Epsilon0_Needed_Std.html}.\nPlease note that it has the same global structure as in section\\ref{sec:free-battles-case} \n% ICI !\nApplying the  lemmas  \\texttt{Lemma2\\_6\\_1} of the module \n\\href{../theories/html/hydras.Epsilon0.Paths.html\\#Lemma2_6_1}%\n{\\texttt{Lemma2\\_6\\_1}}   and \n\\href{../theories/html/hydras.Epsilon0.Paths.html\\#constant_to_standard_path}%\n{\\texttt{constant\\_to\\_standard\\_path}},\nwe can convert any inequality $\\beta<\\alpha<\\epsilon_0$ into a standard path from\n$\\alpha$ to  $\\beta$, then into a fragment of a standard battle from \n$\\iota(\\alpha)$ to $\\iota(\\beta)$.\n\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Hydra.Epsilon0_Needed_Std.html\\#LT_to_standard_battle}{Hydra.Epsilon0\\_Needed\\_Std}}\n\n\\begin{Coqsrc}\nLemma LT_to_standard_battle :\n    forall alpha beta,\n      beta t1< alpha ->\n      exists n i,  battle standard  n (iota alpha) i (iota beta).\n\\end{Coqsrc}\n\n\nNext, please consider the following context:\n\n\\begin{Coqsrc}\nSection Impossibility_Proof.\n \n  Context (Var : BoundedVariant standard).\n \\end{Coqsrc}\n\nIn the same way as for free battles, we import a large inequality \nfrom \nthe module \\href{../theories/html/hydras.Hydra.Epsilon0_Needed_Generic.html}{Hydra.Epsilon0\\_Needed\\_Generic}.\n\n\n\\begin{Coqsrc}\n Lemma m_ge : m big_h t1<= m small_h.\n\\end{Coqsrc}\n\n\\paragraph*{} If remains to prove the following strict inequality, in order to have a contradiction.\n\n\\begin{Coqsrc}\nLemma m_lt : m small_h  t1< m big_h.\n\\end{Coqsrc}\n\n\n\\paragraph*{Sketch of proof:} Let us recall that $\\texttt{big\\_h} = \\iota(\\mu)$\n and $\\texttt{small\\_h} = \\iota (m (\\texttt{big\\_h}))$.\n\nSince $m(\\texttt{big\\_h})< \\mu$, there exists a standard path from $\\mu$ to\n$m(\\texttt{big\\_h})$, hence a   standard battle from $\\iota(\\mu)$  to\n$\\iota(m(\\texttt{big\\_h}))$,  i.e. from \\texttt{big\\_h} to \\texttt{small\\_h}.\n\nSince $m$ is assumed to be a variant for standard battles, we get the inequality  $m(\\texttt{small\\_h}) < m(\\texttt{big\\_h})$.\n\n\n\n\\subsection{Remarks}\n\nWe are grateful to \n J. Ketonen and R. Solovay  for the high quality of their explanations and proof details.\nOur proof follows tightly the sequence of lemmas in their article, with a focus on \nconstructive aspects.\nRoughly steaking, our implementation \\emph{builds}, out of a hypothetic \n  variant $m$, bounded by some ordinal $\\mu<\\epsilon_0$, a hydra \\texttt{big\\_h} which verifies the impossible inequality  $m(\\texttt{big\\_h})< m(\\texttt{big\\_h})$.\n\n\n\nOn may ask whether the preceding results are not too restrictive, since they \nrefer to a particular data type \\texttt{T1}.\nIn fact, our representation of ordinals strictly less than \n $\\epsilon_0$ is faithful to their mathematical definition, at least \nKurt Schütte's~\\cite{schutte}, as proved in Chapter~\\vref{chap:schutte}.\n(please see also \\href{../theories/html/hydras.Schutte.Correctness_E0.html}{the module \\texttt{Ordinals.Schutte.Correctness\\_E0}}).\n\nThus, we can infer that our theorems can be applied to any well order.\n\n\\index{Projects}\n\\begin{project}\nStudy a possible modification of the definition of a variant  (for  standard battles).\n\n\\begin{itemize}\n\\item The variant is assumed to be strictly decreasing \\emph{on configurations \nreachable from some initial configuration where the replication factor is equal to $0$}\n\\item The variant may depend on the number of the current round.\n\\end{itemize}\n\nIn other words, its type should be \\texttt{nat -> Hydra -> T1}, and it must \nverify the inequality $m\\, (S\\,i)\\, h' < m\\,i\\, h$ whenever the configuration \n$(i,h)$ is reachable from some initial configuration $(0,h_0)$\nand \\texttt{h} is transformed into \\texttt{h'} in the considered round.\nCan we still prove the theorems of section~\\ref{std-case} with this new definition?\n\n\\end{project}\n\n\n\n%---------------------------------------------------------------------\n\\chapter{Large Sets and Rapidly Growing Functions}\\label{chap:alpha-large}\n\n\n%\\section{Introduction}\n\nIn this chapter, we try to feel how long a standard battle can be.\nTo be precise, for any ordinal $\\alpha<\\epsilon_0$ and any positive integer $k$,\nwe give a minoration of the number of steps of a standard battle which\nstarts with the hydra $\\iota(\\alpha)$ and the replication factor $k$.\n\nWe express this number in terms of the Hardy hierarchy of fast-growing \nfunctions~\\cite{BW85, Wainer1970, KS81, Promel2013}.\n From the \\coq{} user's point of view, such  functions are  very \nattractive:  they are defined as functions  in \\gallina{}, and we can apply them \\emph{in theory}, but they are so complex that you will never be able to look at the result of the computation.\n Thus, our knowledge on these functions must rely on \\emph{proofs}. In our development, we use often the rewriting rules generated by \\coq's \\texttt{Equations} plug-in.\n\n\n\\section{Definitions}\n\n%\\subsection{Definition}\n\n\\begin{definition}\nLet $0<\\alpha<\\epsilon_0$ be any ordinal, and $s$ a sequence of strictly positive natural numbers. \nWe say that $s$ is \\emph{minimally $\\alpha$-large} (in short:\n\\emph{$\\alpha$-mlarge}) if $s$ if $s$ is $\\alpha$-large \n and every strict prefix of $s$ leads to a non-zero ordinal (\\emph{cf} Sect.~\\vref{sect:path-to-def}).\n\n\\index{Maths!Large sequences}\n\\index{Maths!Minimal large sequences}\n\n\\end{definition}\n\n\\vspace{4pt}\n\n\\noindent\n\\emph{From Module~ \\href{../theories/html/hydras.Epsilon0.Large_Sets.html\\#mlarge}{Epsilon0.Large\\_Sets}}\n\n\n\\index{Predicates!mlarge @ mlarge (minimal large sequences)}\n\\begin{Coqsrc}\nDefinition mlarge alpha (s:list nat) := path_to zero s alpha.\n\\end{Coqsrc}\n\n\n\n\\begin{remark}\n  Ketonen and Solovay~\\cite{KS81} consider  large finite \\emph{sets} of natural numbers,  but they are mainly used as sequences. Thus, we chosed to represent them explicitely as (sorted) lists. \n\nThey also consider large (but not minimally large) sets. They can be defined in\n\\coq{} as follows:\n\n\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Paths.html\\#gnaw}{Epsilon0.Paths}}\n\n\\begin{Coqsrc}\nFixpoint gnaw (alpha : T1) (s: list nat) :=\n  match s with\n    | nil => alpha\n    | (0::s') => gnaw  alpha s'\n    | (S i :: s')  =>  gnaw (canonS i alpha) s'\n  end.\n\nDefinition large alpha (s:list nat) := gnaw alpha s = zero.\n\\end{Coqsrc}\n\\end{remark}\n\n\n\nLet us consider two integers $k$ and $l$, such that $0<k<l$. In order to check whether the interval $[k,l]$ is minimally large for $\\alpha$, it is enough to\nfollow from $\\alpha$ the path associated with the interval $[k,l($ and verify that the last ordinal we obtain is equal to $1$.\n \n\\subsection{Example}\n\nFor instance the interval $[6,70]$ leads $\\omega^2$ to $\\omega\\times 2 + 56$. Thus this interval is not $\\omega^2$-mlarge.\n\n\n\\begin{Coqsrc}\nCompute pp (gnaw (omega * omega) (interval 6 70)).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = (omega * 2 + 56)%pT1\n     : ppT1\n\\end{Coqanswer}\n\nLet us try another computation.\n\n\\begin{Coqsrc}\nCompute (gnaw (omega * omega) (interval 6 700)).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = zero : T1\n\\end{Coqanswer}\n\nWe may say that the interval $[6,700]$ is $\\omega^2$-large, since it leads to $0$, but nothing assures us that the condition of minimality is satisfied.\n\nThe following lemma relates minimal largeness with the function \n\\texttt{gnaw}. \n\n\\begin{Coqsrc}\nLemma mlarge_iff alpha x (s:list nat) :\n  s <> nil -> ~ In 0 (x::s) ->\n  mlarge alpha (x::s) <-> gnaw alpha (but_last x s) = one.\n \\end{Coqsrc}\n\n\nFor instance, we can verify that the interval $[6,510]$ is $\\omega^2$-mlarge.\n\n\\vspace{4pt}\n \\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Large_Sets_Examples.html}{Epsilon0.Large\\_Sets\\_Examples}}\n\\begin{Coqsrc}\nExample Ex1 : mlarge (omega * omega) (interval 6 510).\n\\end{Coqsrc}\n\n\n\\section{The Length of Minimal Large Sequences}\n\nNow, consider any natural number $k>0$. We would like to compute\na number $l$ such that the interval $[k,l]$ is $\\alpha$-mlarge. So, \nthe standard battle starting with $\\iota(\\alpha)$ and the replication factor $k$ will end after $(l-k+1)$ steps.\n\n\n\nFirst, we notice that this  number $l$ exists, since the segment $[0,\\epsilon_0)$ is well-founded and $\\canonseq{\\alpha}{i}<\\alpha$ for any $i$ and $\\alpha>0$.\nMoreover, it is unique:\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Large_Sets.html}{Epsilon0.Large\\_Sets}}\n\\begin{Coqsrc}\nLemma mlarge_unicity alpha k l l' : \n  mlarge alpha (interval (S k) l) ->\n  mlarge alpha (interval (S k) l') ->\n  l = l'.\n\\end{Coqsrc}\n\nThus, it seems obvious that there must exist a function, parameterized by $\\alpha$ which associates to any  strictly positive integer $k$ the number $l$ such that\nthe interval $[k,l]$ is $\\alpha$-mlarge. It would be fine to write in \\gallina{} a definition like this:\n\n\\begin{Coqbad}\nFunction L (alpha: E0) (i:nat) :  nat := ...\n\\end{Coqbad}\n\nBut we do not know how to fill the dots yet \\dots{}   In the next section, we will \nuse \\coq{} to reason  about the \\emph{specification} of \\texttt{L},\nprove properties of any function which satisfies this specification.\nIn Sect.~\\ref{sect:L-equations}, we use the \\texttt{coq-equations} plug-in\nto define a function \\texttt{L\\_}, and prove its correctness w.r.t. its specification.\n\n\n\n%\\subsection{Looking for a function definition}\n\nLet $0<\\alpha<\\epsilon_0$ be an ordinal term. We consider the functions which associate to each stritly positive integer $k$ the number $l$, where \nthe interval $[k,l)$ is $\\alpha$-mlarge.\n\n\\begin{remark}\nThe upper bound of the considered interval has been chosen to be  $l-1$ and not $l$, in order to simplify some statements and proofs in composition lemmas associated to ordinals of the form $\\alpha\\times i$ and \n$\\omega^\\alpha\\times i + \\beta$.\nIn order to consider any ordinal below $\\epsilon_0$, we consider a special case for $\\alpha=0$.\n\\end{remark}\n\n\n\\subsection{Formal Specification}\n\nOur specification of the function \\texttt{L} is as follows:\n\n\\begin{Coqsrc}\nInductive L_spec : T1 -> (nat -> nat) -> Prop :=\n| L_spec0 : forall f, (forall k, f k = k) ->  L_spec zero f\n| L_spec1 : forall alpha f,\n    alpha <> zero ->\n    (forall k, mlarge alpha (interval (S k) (Nat.pred (f (S k))))) ->\n    L_spec alpha f.\n\\end{Coqsrc}\n\n\nNote that, for $\\alpha\\not=0$, the value of $f(0)$ is not specified.\nNevertheless, the restriction of $f$ to the set of strictly positive integers is unique (up to extensionnality).\n\n\\begin{Coqsrc}\nLemma L_spec_unicity alpha f g :\n  L_spec alpha f -> L_spec alpha g -> forall k, f (S k) = g (S k).\n\\end{Coqsrc}\n\n\n\\subsection{Abstract Properties}\n\n\n\nLet us now prove properties of any function $f$ (if any) which satisfies \n\\texttt{L\\_spec}. We are looking for properties which could be used for writing \\emph{equations} and prove the correctness of the function generated by the \\texttt{coq-equations} plug-in. Moreover, they will give us some examples of\n$L_\\alpha$ for small values of $\\alpha$. \n\n\nOur exploration of the $L_\\alpha$s  follows the usual scheme : transfinite induction, and proof-by-cases : zero, successors and limit ordinals.\n\n\\index{Maths!Transfinite induction}\n\n\\subsubsection{The  Ordinal Zero}\n\\label{sect:L-spec-zero}\nThe base case is directly a consequence of the specification.\n\n\\begin{Coqsrc}\nLemma L_zero_inv f : L_spec zero f -> forall k, f (S k) = S k.\n\\end{Coqsrc}\n\n\\subsubsection{Successor Ordinals}\n\\label{sect:L-spec-succ}\nLet $\\beta$ be some ordinal, and assume the arithmetic function $f$ satisfies \nthe specification $(\\texttt{L\\_spec}\\;\\beta)$.  Let $k$ be any natural number.\nAny path from $\\texttt{succ}\\,\\beta$ to $0$ starting at $k+1$ can be decomposed into a first step from $\\texttt{succ}\\,\\beta$ to $\\beta$, then a path from\n$\\beta$ at $k+2$ to $0$. \nBy hypothesis the interval $[k+2, f(k+2)-1]$ is $\\beta$-mlarge.\nBut the interval $[k+1, f(k+2)-1]$ is the concatenation of the singleton\n$\\{k+1\\}$ and the interval $[k+2, f(k+2)-1]$.\nSo, the function $\\lambda\\,k.\\,f(k+1)$ satisfies the specification $\\texttt{L\\_spec}\\,\\beta$.\n\n\nNote that our decomposition of intervals works only if the intervals we consider are not empty. In order to ensure this property, we assume that $f\\;k$ is always greater than $k$, which we note \\texttt{S <<= f}, or \\texttt{(fun\\_le S f)} (defined \nin~\\href{../theories/html/hydras.Prelude.Iterates.html\\#fun_le}{Prelude.Iterates}).\n\n\\begin{Coqsrc}\nDefinition fun_le f g  := forall n:nat,  f n <=  g n.\n\\end{Coqsrc}\n\nIt looks also natural to show that the functions we consider are strictly monotonous. The section on successor ordinals has thus the following structure.\n\n\\begin{Coqsrc}\nSection succ.\n   Variables (beta : T1) (f : nat -> nat).\n\n   Hypotheses (Hbeta : nf beta)\n              (f_mono : strict_mono f)\n              (f_Sle : S <<= f)\n              (f_ok : L_spec beta f).\n\n   Definition L_succ := fun k => f (S k).\n\n   Lemma L_succ_mono : strict_mono L_succ.\n\n   Lemma L_succ_Sle : S <<= L_succ.\n  \n   Lemma L_succ_ok : L_spec (succ beta) L_succ.\n     \nEnd succ.\n\n\\end{Coqsrc}\n\n\\subsubsection{Limit Ordinals}\n\\label{sect:L-spec-lim}\n\nLet $\\lambda<\\epsilon_0$ be any limit ordinal. In a similar way as for successors, we decompose any path from $\\lambda$ (at $k$) into a step to\n$\\canonseq{\\lambda}{k}$, then to $0$. In the following section, we assume that there exists à correct function for $\\canonseq{\\lambda}{k}$, \\emph{for any strictly positive $k$}.\n\n\\begin{Coqsrc}\nSection lim.\n  Variables (lambda : T1)\n            (Hnf : nf lambda)\n            (Hlim : limitb lambda)\n            (f : nat -> nat -> nat)\n            (H : forall k, L_spec (canonS lambda k) (f (S k))).\n  \n  Let L_lim k := f k (S k).\n\n  Lemma L_lim_ok : L_spec lambda L_lim.\n  \nEnd lim.\n\\end{Coqsrc}\n\n\\subsection{First Results}\n\nApplying the previous lemmas on successors and limit ordinals, \nwe get several correct implementations of \\texttt{(L\\_spec $\\alpha$)} for small values of $\\alpha$.\n\n\\subsubsection{Finite Ordinals}\n\nBy iterating the functional \\texttt{L\\_succ}, we get a realization of\n\\texttt{(L\\_spec (fin $i$))} for any natural number $i$. \n\n\\begin{Coqsrc}\nDefinition L_fin i := fun k => (i + k)%nat.\n\nLemma L_fin_ok i : L_spec (fin i) (L_fin i).\n\\end{Coqsrc}\n\n\\subsubsection{The First Limit Ordinal  \\texorpdfstring{$\\omega$}{omega}}\n\nThe lemmas \\texttt{L\\_fin\\_ok} and \\texttt{L\\_lim\\_ok}   allow us to get \nby diagonalization a correct implementation for \n\\texttt{L\\_spec omega}.\n\n\\begin{Coqsrc}\nDefinition L_omega k := S (2 * k)%nat.\n\nLemma L_omega_ok : L_spec omega L_omega.\n\\end{Coqsrc}\n\n\\subsubsection{Towards  \\texorpdfstring{$\\omega^2$}{omega*omega}}\n\nWe would like to get exact formulas for the ordinal $\\omega^2$, a.k.a.\n$\\phi_0(2)$. This ordinal is the limit of the sequence $\\omega\\times i\\;(i \\in \\mathbb{N}$. Thus, we have to study ordinals of this form, then use \nour lemma on limits.\n\nThe following lemma establishes a path from $\\omega\\times ( i+1)$ to\n$\\omega \\times i$.\n\n\\begin{Coqsrc}\nLemma path_to_omega_mult (i k:nat) :\n  path_to (omega * i) (interval (S k) (2 * (S k))) (omega * (S i)).\n\\end{Coqsrc}\n\nLet us consider a path from  $\\omega\\times(i+1)$ to $0$ starting at $k+1$.\nA first ``big step'' will lead to $\\omega\\times i$ at $2(k+1)$. If $i>0$, the\nnext jump leads to $\\omega\\times(i-1)$ at $2(2(k+1))+1$, etc.\n\n\nThe following lemma expresses the length of the mlarge sequences associated with the finite multiples of $\\omega$.\n\n\n\\begin{Coqsrc}\nLemma omega_mult_mlarge_0 i  : forall k,\n    mlarge  (omega * (S i))\n            (interval (S k)\n                      (Nat.pred (iterate (fun p =>  S (2 * p)%nat)\n                                         (S i)\n                                         (S k)))).\n\\end{Coqsrc}\n\nThus, we infer the following result:\n\n\\emph{From Module~ \\href{../theories/html/hydras.Epsilon0.Large_Sets.html\\#L_omega_mult}{Epsilon0.Large\\_Sets}}\n\n\\begin{Coqsrc}\nDefinition L_omega_mult i (x:nat) :=  iterate L_omega i x.\n\nLemma L_omega_mult_ok (i: nat) :  L_spec (omega * i) (L_omega_mult i).\n\\end{Coqsrc}\n\nFor instance, let us consider the ordinal $\\omega\\times 8$, and a sequence \nstarting at $k=5$.\n\n\\begin{Coqsrc}\nCompute L_omega_mult 8 5.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 1535\n     : nat\n\\end{Coqanswer}\n\nMore generally, we prove the equality $L_{\\omega\\times i}(k)=2^i\\times(k+1)-1$.\n\n\\begin{Coqsrc}\nLemma L_omega_mult_eqn (i : nat) :\n  forall (k : nat),  (0 < k)%nat  ->\n                     L_omega_mult i k = (exp2 i * S k - 1)%nat.\n\\end{Coqsrc}\n\n\nBy diagonalization, we obtain a simple formula for $L_{\\omega^2}$.\n\n\\begin{Coqsrc}\nDefinition L_omega_square k := iterate (fun z => S (2 * z)%nat)\n                                        k\n                                        (S k).\n\nLemma L_omega_square_eqn k :\n  (0 < k)%nat ->\n  L_omega_square k = (exp2 k * (k + 2) - 1)%nat.\n\n\nLemma L_omega_square_ok: L_spec (omega * omega) \n          L_omega_square.\n\nCompute L_omega_square 8.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 2559\n     : nat\n\\end{Coqanswer}\n\n\n%%%% ICI \n\n\n\\subsubsection{Going Further}\nLet us consider a last example, ``computing'' $L_{\\omega^3}$.\nSince the canonical sequence associated with this ordinal is composed of the\n$\\omega^2\\times i\\;(i\\in\\mathbb{N}_1)$, we have to study this sequence.\n\nTo this end, we prove a generic lemma, which expresses $L_{\\omega^\\alpha\\times i}$ as an iterate of $L_{\\omega^\\alpha}$. Note that in this lemma, we assume that the fonction associated with $\\alpha$ is stritly monotonous and \ngreater or equal than the successor function, and prove that $L_{\\omega^\\alpha\\times i}$satisfies  the same properties.\n\n\\begin{Coqsrc}\nSection phi0_mult.\n Variables (alpha : T1) (f : nat -> nat).\n Hypotheses (Halpha : nf alpha)\n            (f_mono : strict_mono f)\n            (f_Sle : S <<= f)\n            (f_ok : L_spec (phi0 alpha) f).\n\n Definition L_phi0_mult i := iterate f i.\n\nLemma L_phi0_mult_ok i: \n  L_spec (ocons alpha i zero)  (L_phi0_mult (S i)).\n\n Lemma L_phi0_mult_smono i: strict_mono (L_phi0_mult i).\n\n Lemma L_phi0_mult_Sle i: S <<=  L_phi0_mult (S i).\n\nEnd phi0_mult.\n\\end{Coqsrc}\n\nLet us look \nat the ordinal $\\omega^2\\times i$, using \\texttt{L\\_phi0\\_mult}\n\n\\begin{Coqsrc}\n Definition L_omega_square_times i :=  iterate L_omega_square i.\n\n Lemma L_omega_square_times_ok i : \n    L_spec (ocons 2 i zero) (L_omega_square_times (S i)).\n Proof.\n  apply L_phi0_mult_ok.\n  -  auto with T1.\n  -  apply L_omega_square_Sle.\n  -  apply L_omega_square_ok.\n Qed.\n\\end{Coqsrc}\n\n\nWe are now ready to get an exact formula for $L_{\\omega^3}$. \n\\begin{Coqsrc}\nDefinition L_omega_cube  := L_lim  L_omega_square_times .\n\nLemma L_omega_cube_ok : L_spec (phi0 3) L_omega_cube.\n\\end{Coqsrc}\n\n\nThe function  $L_{\\omega^3}$  is just obtained by diagonalization upon $L_{\\omega^2\\times i}$.\n\n\\begin{Coqsrc}\nLemma L_omega_cube_eqn i : \n   L_omega_cube i = L_omega_square_times i (S i).\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\nThus, for instance, $L_{\\omega^3}(3)=L_{\\omega^2\\times 4}(3)$.\nThus, we obtain an exact expression of this number.\n\n\n\\begin{Coqsrc}\nLemma L_omega_cube_3_eq:\n   let N := exp2 95 in\n   let P := (N * 97 - 1)%nat in\n   L_omega_cube 3  =  (exp2 P * (P + 2) - 1)%nat.\n\\end{Coqsrc}\n\n\nThis number is quite big. Using \\texttt{Ocaml}'s \\texttt{float} arithmetic,\nwe can [under-]approximate it by $2^{3.8\\times10^{30}}\\times 3.8\\times{10^{30}}$.\n\n\\begin{Coqsrc}\n# let exp2 x = 2.0 ** x;;\n\nval exp2 : float -> float = <fun>\n#   exp2 95.0 *. 97.0 -. 1.0;;\n- : float = 3.84256588194182037e+30\n# let n = exp2 95.0 ;;\n# let p = n *. 97.0 -. 1.0;;\nval p : float = 3.84256588194182037e+30\n\nEstimation :\n2 ** (3.84 e+30) * 3.84 e+30.\n\\end{Coqsrc}\n\n\n\\subsection{Using \\texttt{Equations}}\n\\label{sect:L-equations}\n\nNote that we did not define any function $L_\\alpha$ \\emph{for any $\\alpha<\\epsilon_0$} yet. We have got no more than a collection of proved realizations of $\\texttt{L\\_spec}\\;\\alpha$ for several values of $\\alpha$.\n\n\\index{Coq!Plug-ins!Equations}\n\nUsing the \\texttt{coq-equations} plug-in by \nM. Sozeau~\\cite{sozeau:hal-01671777}, we will now define a function \\texttt{L\\_} which maps any ordinal  $\\alpha<\\epsilon_0$ to a proven realization of \n$\\texttt{L\\_spec}\\;\\alpha$.   \n\\subsection{Definition}\n\nIn order to get a total function, we use our type \\texttt{E0} of well-formed ordinal terms,(see Sect~\\vref{sect:E0-def}).  Our definition is structured along a well-founded recursion and\na case-study (zero, limit and successor ordinals). \n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.L_alpha.html\\#L_}{L\\_alpha}).}\n\n\\label{Functions:L-alpha}\n \n\\begin{Coqsrc}\nFrom Equations Require Import Equations.\nRequire Import ArithRing Lia.\n\nInstance Olt : WellFounded Lt := Lt_wf.\nHint Resolve Olt : E0.\n\n(** Using Coq-Equations for building a function which satisfies \n    Large_sets.L_spec *)\n\nEquations  L_ (alpha: E0) (i:nat) :  nat  by wf  alpha Lt :=\n  L_ alpha  i with E0_eq_dec alpha Zero :=\n    { | left _ =>  i ;\n      | right nonzero\n          with Utils.dec (Limitb alpha) :=\n          { | left _ =>  L_ (Canon alpha i)  (S i) ;\n            | right notlimit =>  L_ (Pred alpha) (S i)}}.\n\nSolve All Obligations with auto with E0.\n\\end{Coqsrc}\n\nIt is worth looking at the answer from \\texttt{Equations} and check (with \\texttt{About} ) all the lemmas this plug-in gives you for free. We show here only a part of \\coq's anwer.\n\n\n\\begin{Coqanswer}\nL__obligations_obligation_1 is defined\nL__obligations_obligation_2 is defined\nL__obligations is defined\nL__clause_1 is defined\nL__functional is defined\nL_ is defined\n...\nL__equation_1 is defined\nL__graph_mut is defined\nL__graph_rect is recursively defined\nL__graph_correct is defined\nL__elim has type-checked, generating 1 obligation\nL__elim is defined\nFunctionalElimination_L_ is defined\nFunctionalInduction_L_ is defined\n\\end{Coqanswer}\n\nSometimes, these automatically generated statements may look cryptic. \n\n\\begin{Coqsrc}\nAbout L__equation_1.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nL__equation_1 :\nforall (alpha : E0) (i : nat),\nL_ alpha i = L__unfold_clause_1 alpha (E0_eq_dec alpha Zero) i\n\\end{Coqanswer}\n\nIn most cases, it may be useful to write human-readable  paraphrases of these statements.\n\n\\begin{Coqsrc}\nLemma L_zero_eqn : forall i, L_ Zero i = i.\nProof. intro i; now rewrite L__equation_1. Qed.\n\nLemma L_lim_eqn alpha i : Limitb alpha -> L_ alpha i =\n                                        L_ (Canon alpha i) (S i).\n\nLemma L_succ_eqn alpha i :  L_ (Succ alpha) i = L_  alpha (S i).\n\nHint Rewrite L_zero_eqn L_succ_eqn : L_rw.\n\\end{Coqsrc}\n\nUsing these three lemmas as rewrite rules, we can prove more properties of the functions \\texttt{L\\_$\\alpha$}.\n\n\\begin{Coqsrc}\nLemma L_finite : forall i k :nat,  L_ i k = (i+k)%nat.  \n(* Proof by induction on i, using L_zero_eqn and L_succ_eqn *)\n\nLemma L_omega : forall k, L_ omega%e0 k = S (2 * k)%nat.\n(* Proof using L_finite and L_lim_eqn *)\n\\end{Coqsrc}\n\nBy  well-founded induction on $\\alpha$, we prove the following lemmas:\n\n\\begin{Coqsrc}\nLemma L_ge_S alpha : alpha <> Zero -> S <<= L_ alpha.\n\nTheorem L_correct alpha : L_spec (cnf alpha) (L_ alpha).\n\\end{Coqsrc}\n\nPlease note that the proof of \\texttt{L\\_correct} applies the lemmas proven in Sections~\\ref{sect:L-spec-zero}, ~\\ref{sect:L-spec-succ} and ~\\ref{sect:L-spec-lim}.\nOur previous study of \\texttt{L\\_spec} allowed us to pave the way for the definition by \\texttt{Equations} and the correctness proof.\n\n\n\n\\subsubsection{Back to Hydra Battles}\n\nTheorem \\texttt{battle\\_length\\_std } of\nModule~\\href{../theories/html/hydras.Hydra.Hydra_Theorems.html\\#battle_length_std}{Hydra.Hydra\\_Theorems} relates the length of standard battles with the functions $L_\\alpha$.\n\n\\begin{Coqsrc}\nTheorem battle_length_std (alpha : E0)  :\n  alpha <> Zero ->\n  forall k, (1 <= k)%nat ->\n            battle_length standard k (iota (cnf alpha))\n                         (L_ alpha (S k) - k).\n\\end{Coqsrc}\n\n\n\\index{Projects}\n\\begin{project}\nInstead of considering standard paths and battles, consider ``constant'' paths and the corresponding battles. Please use \\texttt{Equations} in order to define the function that computes the length of the $k$-path which leads  from $\\alpha$ to $0$.\nProve a few  exact formulas and minoration lemmas.\n\\end{project}\n\n\\section{The Wainer-Hardy Hierarchy (Functions \\texorpdfstring{$H_\\alpha$}{\\texttt{H\\_alpha}})}\n\n\\label{sect:hardy}\nIn order to give an idea of the complexity of the functions  $L_\\alpha$s, we compare them with a better known family of functions, the so called \\emph{Wainer-Hardy hierarchy} of fast growing functions,\npresented for instance in~\\cite{Promel2013}. \n\\index{Maths!Hardy Hierarchy}\n\nFor each ordinal $\\alpha$ below $\\epsilon_0$, $H_\\alpha$ is a \ntotal arithmetic function, defined  by  transfinite recursion on $\\alpha$, according to three cases:\n\n\\index{Maths!Transfinite induction}\n\n\\begin{itemize}\n\\item If $\\alpha=0$, then $H_\\alpha (k)= k$ for any natural number $k$.\n\\item If $\\alpha=\\textrm{succ}(\\beta)$, then \n$H_\\alpha(k)=H_\\beta(k+1)$ for any $k \\in \\mathbb{N}$\n\\item If $\\alpha$ is a limit ordinal, then \n$H_\\alpha(k) = H_{(\\canonseq{\\alpha}{k+1})}(k)$ for any $k\\in \\mathbb{N}$.\n\\end{itemize}\n\n\\subsection{Hardy Functions in \\texttt{Coq}}\n\n\nWe define a function \\texttt{H\\_} of type \\texttt{E0 -> nat -> nat} by transfinite induction over the type \\texttt{E0} of the well formed ordinals below $\\epsilon_0$.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.H_alpha.html\\#H_}{Epsilon0.H\\_alpha}}\n\n\n\\index{Coq!Plug-ins!Equations}\n\\label{Functions:H-alpha}\n\n\\begin{Coqsrc}\nEquations H_ (alpha: E0) (i:nat) :  nat  by wf  alpha lt :=\n  H_ alpha  i with E0_eq_dec alpha Zero :=\n    { | left _ =>  i ;\n      | right nonzero\n          with Utils.dec (Limitb alpha) :=\n          { | left _ =>  H_ (Canon alpha (S i))  i ;\n            | right notlimit =>  H_ (Pred alpha) (S i)}}. \n\nSolve All Obligations with auto with E0.\n\\end{Coqsrc} \n \n\n\n\\begin{Coqsrc}\nLemma H_eq1 : forall i, H_ Zero i = i.\nProof.   intro i; now rewrite H__equation_1.  Qed.\n\nLemma H_eq2 alpha i : Is_Succ alpha ->\n                      H_ alpha i = H_ (Pred alpha) (S i).\n\nLemma H_eq3 alpha i : Limitb alpha ->\n                      H_ alpha i =  H_ (Canon alpha (S i)) i.\n\nLemma H_eq4  alpha i :  H_ (Succ alpha) i = H_ alpha (S i).\n\\end{Coqsrc}\n\n\n\\subsection{First  Steps of the Hardy hierarchy}\nUsing rewrite rules from \\texttt{H\\_eq1} to \\texttt{H\\_eq4}, we can explore the functions $H_\\alpha$ for some small values of $\\alpha$.\n\n\\subsubsection{Finite Ordinals} \n\nBy induction on $i$, we prove a simple expression of \\texttt{H\\_ (Fin i)}, where \n\\texttt{Fin $i$}  is the $i$-th finite ordinal.\n\n\\begin{Coqsrc}\nLemma H_Fin : forall i k: nat,  H_ (Fin i) k = (i+k)%nat.\nProof with eauto with E0.\n  induction i.\n  - intros; simpl OF; simpl; autorewrite with H_rw E0_rw ... \n  - intros ;simpl; autorewrite with H_rw E0_rw ... \n    rewrite IHi; lia. \nQed.\n\\end{Coqsrc}\n\n\\subsubsection{Multiples of \\texorpdfstring{$\\omega$}{omega}}\n\nSince the canonical sequence of $\\omega$ is composed of finite ordinals, \nit is easy to get the formula associated with $H_\\omega$.\n\n\n\\begin{Coqsrc}\nLemma H_omega : forall k, H_ Omega k = S (2 * k)%nat.\nProof with auto with E0.\n  intro k; rewrite H_eq3 ...\n  - replace (Canon omega (S k)) with (Fin (S k)).\n    + rewrite H_Fin; lia.\n    +  now autorewrite with E0_rw.\nQed.\n\\end{Coqsrc}\n\n\nBefore going further, we prove a useful rewriting lemma:\n\n\\begin{Coqsrc}\nLemma H_Plus_Fin alpha : forall i k : nat,\n    H_ (alpha + i)%e0 k = H_ alpha (i + k)%nat.\n(* Proof by induction on i *)\n\\end{Coqsrc}\n\n\nThen, we get easily formulas for $H_{\\omega+i}$, and $H_{\\omega\\times i}$ for any natural number $i$.\n\n\\begin{Coqsrc}\nLemma H_omega_double k : H_ (omega * 2)%e0 k =  (4 * k + 3)%nat.\nProof.\n rewrite H_lim_eqn; simpl Canon.\n - ochange  (CanonS  (omega * 2)%e0 k)  (omega + (S k))%e0.\n  + rewrite H_Plus_Fin, H_omega;  lia.\n  -  now compute.\nQed.\n\nLemma H_omega_3 k : H_ (omega * 3)%e0 k = (8 * k + 7)%nat.\n\nLemma H_omega_4 k : H_ (omega * 4)%e0 k = (16 * k + 15)%nat.\n\nLemma H_omega_i i  : forall k,\n    H_ (omega * i)%e0 k = (exp2 i * k + Nat.pred (exp2 i))%nat.\n\\end{Coqsrc}\n\nCrossing a new limit, we prove the following equality: \n$$H_{\\omega^2} (k) = 2 ^ {k+1} \\times (k+1) - 1$$.\n\n\\begin{Coqsrc}\n\nLemma H_omega_sqr : forall k,\n    H_ (Phi0  2)%e0 k = (exp2 (S k ) *  S k - 1)%nat.\nProof.\n  intro k; \n   rewrite H_lim_eqn; auto with E0.\n  - ochange (Canon (Phi0 2) (S k)) (omega * (S k))%e0.\n    +  rewrite H_omega_i; simpl (exp2 (S k)).\n       *  rewrite Nat.add_pred_r.\n          -- lia. \n          --   generalize (exp2_not_zero k);  lia.\n    + cbn; f_equal; lia.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{New Limits}\n\nOur next step would be to prove an exact formula for $H_{\\omega^\\omega}(k)$.\nSince the canonical sequence of $\\omega^\\omega$ is composed of all the\n$\\omega^i$, we first need to express $H_{\\omega^i}$ for any natural number $i$.\n\nLet $i$ and $k$ be two natural numbers. \nThe ordinal $\\canonseq{\\omega^(i+1)}{k}$ is the product\n$\\omega^i \\times k$, so we need also to consider ordinals of this form.\n\n\\begin{enumerate}\n\\item First,  we express $H_{\\omega^\\alpha \\times (i+2)}$ in terms of\n$H_{\\omega^\\alpha \\times (i+1)}$.\n\n\\begin{Coqsrc}\nLemma H_Omega_term_1 : alpha <> Zero -> forall  k,  \n    H_ (Omega_term alpha (S i)) k =\n    H_ (Omega_term alpha i) (H_ (Phi0 alpha) k).\n\\end{Coqsrc}\n\n\\item\nThen, we prove by induction on $i$ that $H_{\\omega^\\alpha \\times (i+1)}$ is just the\n$(i+1)$-th iterate of $H_{\\omega^\\alpha}$.\n\n\n\\begin{Coqsrc}\nLemma H_Omega_term (alpha : E0)  :\nalpha <> Zero -> forall i k, \n  H_ (Omega_term alpha i) k = iterate  (H_ (Phi0 alpha)) (S i) k.\n\\end{Coqsrc}\n\n\\item In particular, we have got a formula for $H_{\\omega^{i+1}}$.\n\n\\begin{Coqsrc}\nDefinition H_succ_fun f k := iterate f (S k) k.\n\nLemma H_Phi0_succ alpha  : alpha <> Zero -> forall k,\n      H_ (Phi0 (Succ alpha)) k = H_succ_fun (H_ (Phi0 alpha)) k. \n\nLemma H_Phi0_Si : forall i k,\n      H_ (Phi0 (S i)) k = iterate H_succ_fun i (H_ omega) k. \n\\end{Coqsrc}\n\n\\end{enumerate}\nWe get now a  formula for $H_{\\omega^3}$:\n\n\\begin{Coqsrc}\nLemma H_omega_cube : forall k,\n    H_ (Phi0 3)%e0 k = iterate (H_ (Phi0 2))  (S k) k.\nProof.\n  intro k; rewrite <-FinS_eq, -> Fin_Succ, H_Phi0_succ; auto.\n  compute; injection 1; discriminate.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{A Numerical Example}\n\nIt seems hard to capture the complexity of this function by looking only at this\n``exact'' formula. \nLet us consider a simple example, the number $H_{\\omega^3}(3)$.  \n\n\\begin{Coqsrc}\nSection H_omega_cube_3.\n  \nLet f k :=   (exp2 (S k ) * (S k) - 1)%nat.\n\nRemark R0 k :  H_ (Phi0 3)%e0 k = iterate f (S k) k.\n\\end{Coqsrc}\n\nThus, the number $H_{\\omega^3}(3)$ can be written as four nested applications of $f$.\n\n\\begin{Coqsrc}\nFact F0 : H_ (Phi0 3) 3 = f (f (f (f 3))).\n rewrite R0; reflexivity. \nQed.\n\\end{Coqsrc}\n\nIn order to make this statement more readable, we can introduce a local définition.\n\n\\begin{Coqsrc}\nLet N := (exp2 64 * 64 - 1)%nat.\n\\end{Coqsrc}\n\nThis number looks quite big; let us compute an approximation in \\texttt{Ocaml}:\n\n\n\\begin{Coqsrc}\n# (2.0 ** 64.0 *. 64.0 -. 1.0);; \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n- : float = 1.1805916207174113e+21\n\\end{Coqanswer}\n\n\n\\begin{Coqsrc}\nFact F1 : H_ (Phi0 3) 3 = f (f N).\nProof.\n rewrite H_omega_cube_0; reflexivity. \nQed.\n\n\nLemma F1_simpl : H_ (Phi0 3) 3 =\n                 (exp2 (exp2 (S N) * S N) * (exp2 (S N) * S N) - 1)%nat.\n\n\\end{Coqsrc}\n\n\nIn a more classical writing, this number is displayed as follows:\n\n{\\Large\n$$\nH_{\\omega^3}(3) =  2 ^ {(2 ^ {N + 1} \\times (N+1) } )  \\times  (2 ^ {N+1} \\times ( N +1) ) - 1\n$$\n}\n\n\nWe leave as an exercise to determine the best approximation as possible of\n the size of this number (for instance its number of digits).  For instance, if\nwe do not take into account the multiplications in the formula above,\nwe obtain that, in base $2$, the number $H_{\\omega^3}(3)$ has at least\n$2^{10^{21}}$  digits. But it is still an under-approximation !\n\n\n\\begin{Coqsrc}\nEnd H_omega_cube_3.\n\\end{Coqsrc}\n\n\n\n\nNow, we have got at last an exact formula for $H_{\\omega^\\omega}$.\n\n\\begin{Coqsrc}\nLemma H_Phi0_omega : forall k, H_ (Phi0 omega) k =\n                               iterate H_succ_fun  k (H_ omega) k.\nProof with auto with E0.\n  intro k; rewrite H_lim_eqn, <- H_Phi0_Si ...\n  -  rewrite CanonS_Canon, CanonS_Phi0_lim;  f_equal ...\nQed.\n\\end{Coqsrc}\n\nUsing extensionality of the functional \\texttt{iterate}, we can get a closed formula.\n\n\\begin{Coqsrc}\nLemma H_Phi0_omega_closed_formula k :\n  H_ (Phi0 omega) k =\n  iterate (fun (f: nat -> nat) (l : nat) => iterate  f (S l) l)\n               k\n               (fun k : nat => S (2 * k)%nat)\n               k.\n\\end{Coqsrc}\n\n\n\n\nNote that this short formula contains two occurences of the functional \\texttt{iterate}, the outer one is in fact a second-order iteration (on type \\texttt{nat -> nat)}\nand the inner one  first-order (on type \\texttt{nat}). \n\n\n\\subsection{Abstract Properties of H-functions}\n~\\label{sect:H-alpha-prop} \n\nSince pure computation seems to be useless for dealing with expressions of the form $H_\\alpha(k)$, even for small values of $\\alpha$ and $k$, we need to prove theorems for comparing $H_\\alpha(k)$ and $H_\\beta(l)$, in terms of comparison\nbetween $\\alpha$ and $\\beta$ on the one hand, $k$ and $l$ on the other hand.\n\nBut beware of non-theorems! For instance, one could believe that $H$ is monotonous in its first argument. The following proof shows this is false.\n\n\\begin{Coqsrc}\nRemark H_non_mono1 :\n  ~ (forall alpha beta k, (alpha o<= beta)%e0 ->\n                          (H_ alpha k <= H_ beta k)%nat).\nProof.\n intros H ;specialize (H 42 omega 3).\n assert (H0 :(42 o<= omega)%e0) by (repeat split; auto).  \n apply H in H0; rewrite H_Fin, H_omega  in H0; lia.\nQed.\n\\end{Coqsrc}\n\nOn the contrary, the fonctions of the Hardy hierarchy have the following five properties~\\cite{KS81}: for any $\\alpha < \\epsilon_0$,\n\\begin{itemize}\n\\item the function $H_\\alpha$ is strictly monotonous :\n      For all $n,p \\in\\mathbb{N}, n < p \\Rightarrow H_\\alpha(n)< H_\\alpha(p)$.\n\\item If $\\alpha \\not= 0$, then for every $n$, $n<H_\\alpha(n)$.\n\\item The function $H_\\alpha$ is pointwise less or equal than $H_{\\alpha+1}$\n\n\\item For any $n\\geq 1$, $H_\\alpha(n)<H_{\\alpha+1}(n)$.\n\\emph{We say that $H_{\\alpha+1}$ dominates $H_\\alpha$ from $1$}.\n\\item For any $n$ and $\\beta$, if $\\alpha \\xrightarrow[n]{} \\beta$, then\n$H_\\beta(n)\\leq H_\\alpha(n)$.\n\\end{itemize}\n\n\\index{Maths!Transfinite induction}\n\nIn \\coq{}, we follow the  proof in~\\cite{KS81}. This proof is mainly a single  proof by transfinite induction on $\\alpha$ of the conjonction of the five properties.\nFor each $\\alpha$, the three cases : $\\alpha=0$, $\\alpha$ is a limit, and \n$\\alpha$ is a successor are considered. Inside each case, the five sub-properties are proved sequentially. \n\n\n\\begin{definition}\n Let $f$ zand $g$ be two arithmetic  functions; $f$ is said to \\emph{dominate} $g$ if $f(p)>g(p)$ for any all sufficiently large $p$.\n\\end{definition}\n\n\n\\begin{Coqsrc}\nSection Proof_of_Abstract_Properties.\n  Record P (alpha:E0) : Prop :=\n    mkP {\n        PA : strict_mono (H_ alpha);\n        PB : alpha <> Zero -> forall n,  (n < H_ alpha n)%nat;\n        PC : H_ alpha <<= H_ (Succ alpha);\n        PD : dominates_from 1 (H_ (Succ alpha)) (H_ alpha);\n        PE : forall beta n, Canon_plus n alpha beta -> \n                            (H_ beta n <= H_ alpha n)%nat}.\n\n\nTheorem P_alpha : forall alpha, P alpha.\n  Proof.\n    intro alpha; apply well_founded_induction with lt.\n   (* rest of proof skipped *)\n\nSection Proof_of_Abstract_Properties.\n\\end{Coqsrc}\n\n\n\\subsection{Comparison between \\texttt{L\\_} and \\texttt{H\\_} }\n\nBy well-founded induction on $\\alpha$, we prove that our $L$ hierachy is ``almost'' the Hardy hierarchy (up to a small shift).\n\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.L_alpha.html\\#H_L_}{Epsilon0.L\\_alpha}}\n\n\\begin{Coqsrc}\n Theorem H_L_ alpha: forall i:nat,  (H_ alpha i <= L_ alpha (S i))%nat.\n\\end{Coqsrc}\n \n\\subsubsection{Back to Hydras}\n\nThe following theorem relates the length of (standard) battles with the Hardy hierarchy.\n\n\\emph{From Module~\\href{../theories/html/hydras.Epsilon0.L_alpha.html}{Epsilon0.L\\_alpha}}\n\n\\begin{Coqsrc}\nTheorem battle_length_std_Hardy (alpha : E0) :\n  alpha <> Zero ->\n  forall k , 1 <= k -> exists l: nat,  \n       H_ alpha k - k <= l /\\\n       battle_length standard k (iota (cnf alpha)) l.    \n\\end{Coqsrc}\n\n\n\n\\section{The Wainer Hierarchy (Functions \\texorpdfstring{$F_\\alpha$}{F\\_alpha})}\n\\label{sect:wainer}\n\n\\index{Maths!Wainer Hierarchy}\n\nThe Wainer hierarchy~\\cite{BW85, Wainer1970, KS81}, is also a family of fast growing functions, indexed by ordinals below $\\epsilon_0$, by the following equations:\n\n\\label{F_equations}\n\\begin{itemize}\n\\item $F_0(i)=i+1$\n\\item $F_{\\beta+1}(i)= (F_\\beta)^{(i+1)}(i)$, where $f^{(i)}$ is the $i$-th iterate of $f$.\n\\item $F_\\alpha(i) = F_{\\canonseq{\\alpha}{i}} (i)$ if $\\alpha$ is a limit ordinal.\n\\end{itemize}\n\nA first attempt is to write a definition of $F_\\alpha$ by equations, in the same as for $H\\_alpha$.  We use the functional \\texttt{iterate} defined in \nModule~\\href{../theories/html/hydras.Prelude.Iterates.html\\#iterate}{Prelude.Iterates}.\n\n\\begin{Coqsrc}\nFixpoint iterate {A:Type}(f : A -> A) (n: nat)(x:A) :=\n  match n with\n  | 0 => x\n  | S p => f (iterate  f p x)\n  end.\n\\end{Coqsrc}\n\nThe following code comes from \n \\url{../theories/html/hydras.Epsilon0.F_alpha.html}.\n\n\n\\index{Coq!Plug-ins!Equations}\n\\begin{Coqsrc}\nFail Equations F_ (alpha: E0) (i:nat) :  nat  by wf  alpha Lt :=\n  F_ alpha  i with E0_eq_dec alpha Zero :=\n    { | left _ =>  i ;\n      | right nonzero\n          with Utils.dec (Limitb alpha) :=\n          { | left _ =>  F_ (Canon alpha i)  i ;\n            | right notlimit =>  iterate (F_ (Pred alpha))  (S i) i}}.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nThe command has indeed failed with message:\nIn environment\nalpha : E0\nnotlimit : Limitb alpha = false\nnonzero : alpha <> Zero\ni : nat\nF_ : forall x : E0, nat -> x o< alpha -> nat\nThe term \"F_ (Pred alpha) ?x\" has type \"Pred alpha o< alpha -> nat\"\nwhile it is expected to have type \"Pred alpha o< alpha -> Pred alpha o< alpha\"\n(cannot unify \"nat\" and \"Pred alpha o< alpha\").\n\\end{Coqanswer}\n\n\nWe presume that this error comes from the recursive call of \\texttt{F\\_} inside\nan application of \\texttt{iterate}. The workaround we propose is to define first \nthe iteration of \\texttt{F\\_}  as an helper $F^*$, then to define the function $F$ as a ``iterating $F^*$ once''.\n\n\\texttt{Equations} accepts the following definition, relying on  lexicographic ordering on pairs $(\\alpha,n)$.\n\n\n\\label{sect:F-equations}\n\n\\index{Coq!Plug-ins!Equations}\n\\label{Functions:F-alpha}\n\\index{Maths! Fast growing functions}\n  \n\\begin{Coqsrc}\nDefinition call_lt (c c' : E0 * nat) :=\n  lexico Lt (Peano.lt) c c'.\n\nLemma call_lt_wf : well_founded call_lt.\n  unfold call_lt; apply Inverse_Image.wf_inverse_image,  wf_lexico.\n  -  apply E0.Lt_wf.\n  -  unfold Peano.lt; apply Nat.lt_wf_0. \nQed.\n\nInstance WF : WellFounded call_lt := call_lt_wf.\n\nEquations  F_star (c: E0 * nat) (i:nat) :  nat by wf  c call_lt :=\n    F_star (alpha, 0) i := i;\n    F_star (alpha, 1) i\n      with E0_eq_dec alpha Zero :=\n           { | left _ => S i ;\n             | right nonzero\n                 with Utils.dec (Limitb alpha) :=\n                 { | left _ => F_star (Canon alpha i,1) i ;\n                   | right notlimit =>\n                     F_star (Pred alpha, S i)  i}};\n    F_star (alpha,(S (S n))) i :=\n               F_star (alpha, 1) (F_star (alpha, (S n)) i).\n\n(* Finally, F_ alpha is defined as its first iterate ! *)\n\nDefinition F_  alpha i := F_star (alpha, 1) i.\n\\end{Coqsrc}\n\nIt is quite easy to prove that our function \\texttt{F\\_} satisfies the equations on page~\\pageref{sect:F-equations}.\n\n\\begin{Coqsrc}\nLemma F_zero_eqn : forall i, F_ Zero i = S i.\n\nLemma F_lim_eqn : forall alpha i,  Limitb alpha ->\n                               F_ alpha i = F_ (Canon alpha i) i.\n\nLemma F_succ_eqn : forall alpha i,\n    F_ (Succ alpha) i = iterate (F_ alpha) (S i) i.\n\\end{Coqsrc}\n\nAs for the Hardy functions, we can use these equalities as rewrite rules for\n``computing'' some values of $F_\\alpha(i)$, for small values of $\\alpha$.\n\n\\begin{Coqsrc}\nLemma LF1 : forall n,  F_ 1 n = S (2 * n).\n\nLemma LF2 : forall i, (exp2 i * i < F_ 2 i)%nat.\n\\end{Coqsrc}\n\n\nLike in Sect~\\ref{sect:H-alpha-prop}, we prove by induction the following properties (see~\\cite{KS81}). \n\n\\begin{Coqsrc}\nTheorem F_alpha_mono alpha : strict_mono (F_ alpha).\n \nTheorem F_alpha_ge_S alpha : forall n, (n < F_ alpha n)%nat.\n\nTheorem F_alpha_Succ_le alpha : F_ alpha <<= F_ (Succ alpha).\n\nTheorem F_alpha_dom alpha : dominates_from 1 (F_ (Succ alpha)) (F_ alpha).\n\nTheorem F_alpha_beta alpha : forall beta n, Canon_plus n alpha beta -> \n                                        (F_ beta n <= F_ alpha n)%nat.\n\\end{Coqsrc}\n\nAs a corollary, we prove the following proposition, p. 284 of~\\cite{KS81}.\n\n\\begin{quote}\n  If $\\beta<\\alpha$, $F_\\alpha$ dominates $F_\\beta$.\n\\end{quote}\n\n\\begin{Coqsrc}\nLemma Propp284 : forall alpha beta : E0, \n   beta o< alpha -> dominates (F_ alpha) (F_ beta).\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\nLet us quote a theorem from ~\\cite{KS81} (page 297).\n\n\\begin{quote}\n\\begin{align*}\n  H_{\\omega^\\alpha}(n+1) &\\geq F_{\\alpha}(n) \\quad (n\\geq 1, \\alpha<\\epsilon_0) \\\\\n F_{\\alpha}(n+1) &\\geq H_{\\omega^\\alpha}(n) \\quad (n\\geq 1, \\alpha<\\epsilon_0) \n\\end{align*}\nThus $H_{\\omega^\\alpha}$ and $F_{\\alpha}$ have essentially the same order of growth.\n\n\\end{quote}\n\n But, before trying to prove these facts, look at the definition of function $H$ in Ketonen and Solovay's paper ! Is it really the same as the definition we quote from Pr{\\H o}mel's chapter~\\cite{Promel2013},\nwhereas \\cite{KS81} define $H_\\alpha(n)$ as ``the least integer $k$ such that $[n,k]$ is $\\alpha$-large''. Thus, it may be useful to adapt the statement above.\n\n\n\n\\end{exercise}\n\n\\index{Exercises}\n\n\\begin{exercise}\nProve the following result~\\cite{KS81}(p. 298).\n\n\\begin{quote}\n   For $n\\geq 2$ and $\\alpha \\geq 3$, $F_\\alpha(n+1)\\geq 2^{F_\\alpha(n)}$.\n\\end{quote}\n\\end{exercise}\n\n\n\n%  \\subsection{Gnawing ordinals}\n\n% \\begin{definition}[After~\\cite{KS81}]\n%   Let $S$ be a finite set of positive integers, and $\\alpha$ be an ordinal strictly less than $\\epsilon_0$.  Let us denote by $s=s_1,s_2, \\dots, s_N$ the sequence of \n% the elements of $S$, enumerated in strictly increasing order.\n\n% We consider the sequence of ordinals $\\alpha_o=\\alpha, \\alpha_1=\\canonseq{\\alpha_0}{s_1},\\dots,\\alpha_{i+1}=\\canonseq{\\alpha_i}{s_{i+1}},\\dots, \n% \\alpha_{N}=\\canonseq{\\alpha_{N-1}}{s_N}$.\n% We denote by $\\gnaw{s}{\\alpha}$ the last ordinal of the sequence, \\emph{i.e.}  $\\alpha_N$.\n% \\end{definition}\n\n\n% The following function computes $\\gnaw{s}{\\alpha}$ by recursion on $s$.\n% \\vspace{4pt}\n\n\n\n% For instance, let us consider the ordinal $\\omega^\\omega$, and try some sequence of integers. \n\n\n% \\begin{Coqsrc}\n% Compute pp (gnaw (omega ^ omega) (1::nil)).  \n% \\end{Coqsrc}\n\n\n% \\begin{Coqanswer}\n%   = omega%pT1 : ppT1\n% \\end{Coqanswer}\n\n\n% \\begin{Coqsrc}\n% Compute pp (gnaw (omega ^ omega) (1::2::nil)).  \n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = P_fin 2\n%      : ppT1\n% \\end{Coqanswer}\n\n% Likewise, we can verify that $\\gnaw{\\omega^\\omega}{\\langle 1,2,3 \\rangle}=1$\n% and $\\gnaw{\\omega^\\omega}{\\langle 1,2,3,4 \\rangle}=0$.\n\n% \\begin{Coqsrc}\n% Example omega_omega_1_4 : gnaw (omega ^omega) (interval 1 4) = 0.\n% Proof. trivial. Qed.\n\n% Example omega_omega_1_3 : gnaw (omega ^omega) (interval 1 3) = 1.\n% Proof. trivial. Qed.\n% \\end{Coqsrc}\n\n% \\begin{remark}\n% \\label{remark:gnaw-vs-battles}\n% Let us consider an hydra battle, where Hercules always chops off the rightmost head of the hydra. Let $\\alpha<\\epsilon_0$ be an ordinal number, and \n% $s=\\langle i_1<i_2<\\dots<i_N\\rangle$ be  any finite sequence of positive integers.\n% Then the battle initiated by the hydra $\\iota(\\alpha)$, with $s$ as the sequence of successive replication factors, leads to the hydra $\\iota(\\gnaw{s}{\\alpha})$ as the final state.\n% \\end{remark}\n\n\n% \\subsection{Large sequences}\n\n% \\begin{remark}\n% In their article~\\cite{KS81}, Ketonen and Solovay use the appellation ``large set'' instead of ``large sequence'', but their definitions use an enumeration of the elements in increasing order. Thus, we shall use the term ``sequence'' when referring to our implementation in \\coq{}, and ``set'' when referring to the statements of~\\cite{KS81}.\n% \\end{remark}\n\n\n% \\begin{definition}[After\\cite{KS81}]\n% The sequence $s$ is said to be \\emph{$\\alpha$-large} if $\\gnaw{\\alpha}{s}=0$.  \n% \\end{definition}\n\n\n% \\begin{Coqsrc}\n% Definition largeb (alpha : T1) (s: list nat) :=\n%   match gnaw alpha s with\n%     | zero => true\n%     | _ => false\n%   end.\n\n\n% Definition large (alpha : T1) (s : list nat) : Prop :=\n%   largeb alpha s.\n% \\end{Coqsrc}\n\n\n\n\n% For instance, the sequence $\\langle 1,2,3,4 \\rangle$ is $\\omega^\\omega$-large but not\n% $\\omega^{\\omega+1}$-large, since $\\gnaw{\\omega^{\\omega+1}}{\\langle 1,2,3,4\\rangle}$ is equal to $\\omega \\times 2 + 4$.\n\n\n% %\\omega^\\omega+\\omega^2\\times 3 + \\omega\\times 4+ 5$.\n\n\n% \\begin{Coqsrc}\n% Compute largeb (omega^omega) (interval 1 4).  \n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = true : bool\n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute largeb (omega^(omega+1)) (interval 1 4).\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = false : bool\n% \\end{Coqanswer}\n\n\n% \\begin{remark}\n% A sequence $s$ is $\\alpha$-large if (still considering Hercules ``righmost-head'', tactic), it leads to Hercules' victory.\n% \\end{remark}\n\n\n% \\subsection{A little game}  \n\n% Let $\\alpha<\\epsilon_0$ be an ordinal, and $i$ a positive integer. We want to guess the least natural number  $j$  such that the interval $[i,i+j]$ is $\\alpha$-large.\n% Equivalently, we should have $\\gnaw{\\alpha}{[i, i+j-1]}=1$.\n\n% The following functions takes three arguments: an ordinal $\\alpha$, and two positive natural numbers  $i$ and $j$ (we assume, but not verify that $i$ and $j$ are strictly positive). It returns one of the three possible answers:\n\n% \\begin{itemize}\n% \\item \\texttt{Ok} if $j$ is the smallest integer such that the interval $[i,i+j]$ is $\\alpha$-large\n% \\item \\texttt{Too\\_far} if $[i,i+j]$ is  $\\alpha$-large, but $j$ is not the smallest such positive integer\n% \\item \\texttt{(Remaining $\\beta$)} if $j$ is too small, and gnawing $\\alpha$ with\n%   $[i,i+j]$ is still equal to $\\beta$, instead of $0$\n% \\end{itemize}\n\n\n% \\vspace{4pt}\n% \\noindent\n% \\emph{From Module~\\href{../theories/html/hydras.Epsilon0.Large_Sets_Demo.html}{Ordinals.Epsilon0.Large\\_Sets\\_Demo}}   \n\n% \\begin{Coqsrc}\n% Inductive answer : Set := You_won | Too_far | Remaining (rest : ppT1).\n\n% Definition large_set_check alpha i j :=\n%   let beta := gnaw alpha (interval i (Nat.pred j))\n%   in match beta with\n%      | one => Ok\n%      | zero => Too_far\n%      |  _ => Remaining (pp (canonseq j beta))\n%      end.\n% \\end{Coqsrc}\n\n% \\subsubsection{\\texorpdfstring{$\\omega$}{omega}-large intervals}\n\n\n% For instance, let us consider the ordinal $\\omega$ and start with $i=1$.\n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 1 2.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%      = Ok\n%      : answer\n% \\end{Coqanswer}\n\n% Let us give greater values of $i$, still with the ordinal $\\omega$.\n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 2 3.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqanswer}\n%   = Remaining 1\n%      : answer\n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 3 3.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Remaining 3\n%      : answer\n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 2 4.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqanswer}\n%   = Ok\n%      : answer\n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 3 6.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Ok\n%      : answer\n% \\end{Coqanswer}\n\n% It looks like every request to compute (\\texttt{large\\_set\\_check omega $i$ $2\\times i$})  will succeed. Let us try an example. \n\n% \\begin{Coqsrc}\n% Compute large_set_check omega 49 98.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Ok\n%      : answer\n% \\end{Coqanswer}\n\n% \\subsubsection{\\texorpdfstring{$\\omega^2$}{omega\\^{}2}-large intervals}\n\n% Still using \\texttt{Compute} and \\texttt{large\\_set\\_check}, we obtained the \n% following values of $j$, the least integer such that the interval $[i,j]$ is $\\omega^2$ large.\n\n% $$\n% \\begin{array}{|c|c|}\n% \\hline\n%   i & j \\\\\n% \\hline \n% 1 & 4 \\\\\n% 2 & 14 \\\\\n% 3 & 38 \\\\\n% 4 & 94 \\\\\n% 5 & 222 \\\\\n% % 6 & 510 \n% \\hline\n% \\end{array}\n% $$\n\n% \\begin{exercise}\n% Please give the 6-th and 7-th line of the array above.\n% \\end{exercise}\n\n\n% \\subsubsection{The limits of (pure) computation}\n\n% Let us now play with bigger ordinals, for instance $\\alpha=\\omega^\\omega$ or\n% $\\alpha=\\omega^{\\omega + 1}$. We notice that, even for small values of $i$, it is hard\n% to guess values of $j$ such that $[i,i+j]$ is $\\alpha$-large.\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ omega) 1 4.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%  = Ok\n%      : answer\n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ omega) 2 38.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%  = Ok\n%      : answer\n% \\end{Coqanswer}\n\n\n\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ omega) 3 1000.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Remaining (omega ^ 2 * 2 + omega * 220 + 798)%pT1\n%      : answer\n% \\end{Coqanswer}\n\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ omega) 3 1798.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Remaining (omega ^ 2 * 2 + omega * 220)%pT1\n%      : answer\n% \\end{Coqanswer}\n\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ omega) 3 5000.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%   = Remaining (omega ^ 2 * 2 + omega * 218 + 2198)%pT1\n%      : answer\n% \\end{Coqanswer}\n\n\n\n\n\n\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ (omega + 1)) 3 5000.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n%  = Remaining\n%          (omega ^ omega * 2 + omega ^ 3 * 4 + \n%           omega ^ 2 * 4 + omega * 1148 +  4222)%pT1\n%      : answer  \n% \\end{Coqanswer}\n\n% \\begin{Coqsrc}\n% Compute large_set_check (omega ^ (omega + 1)) 3 10000.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqanswer}\n% Warning: To avoid stack overflow, large numbers in nat are interpreted as\n% applications of Init.Nat.of_uint. [abstract-large-number,numbers]\n\n%     = Remaining\n%          (omega ^ omega * 2 + omega ^ 3 * 4 + \n%           omega ^ 2 * 4 + omega * 1147 +\n%           8446)%pT1\n%      : answer\n% \\end{Coqanswer}\n\n% Since computation is not enough, let us comme back to proofs, or, better, proofs \\emph{and} computations.\n\n% \\subsection{Proving largeness}\n\n\n\n% %%% ICI %%%\n\n% \\subsection{$n$-large and $\\omega$-large intervals }\n\n% A finite ordinal is just made out of \\texttt{zero} and \\texttt{succ} constructions.\n% Thus any sequence of strictly positive integers of length greater than  or equal to $n$ will completely gnaw the ordinal $n$.\n\n% Concerning the first limit ordinal $\\omega$ the largeness of a sequence $s$ depends only on its first element and the length of the rest of the sequence (please keep in mind that the argument $i$ of $\\canonseq{\\alpha}{i}$ is meaningful only if $\\alpha$ is a limit ordinal).\n% The following proposition is labeled $4.2$ in~\\cite{KS81}.\n\n% \\begin{proposition}\n%   For $n<\\omega$, a set $X$id $n$-large if and only if $|X|\\geq n$.\n% A finite set $X$ is $\\omega$-large if $|X|>\\min{X}$.\n% \\end{proposition}\n\n% Rewritten in terms of list of strictly positive integers, we get the following statements:\n\n% \\begin{Coqsrc}\n% Lemma large_n_iff : forall s (n:nat) , ~ In 0 s  ->\n%                                   large n s  <-> (n <= List.length s)%nat.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqsrc}\n% Lemma large_omega_iff : forall s n,  ~In 0 (n::s) -> \n%                                             large omega (n::s) <->\n%                                             (n <=  List.length s)%nat.\n% \\end{Coqsrc}\n\n\n\n% % \\begin{Coqsrc}\n% % (* sorted list of natural numbers greater than or equal to n *)\n\n% % Inductive sorted_ge (n: nat) : list nat -> Prop :=\n% % | sorted_ge_nil : sorted_ge n nil\n% % | sorted_ge_one : forall p, n<=p ->\n% %                             sorted_ge n (p::nil)\n% % | sorted_ge_cons: forall p q s,  n<=p -> p<q ->\n% %                                  sorted_ge p (q::s) ->\n% %                                  sorted_ge n (p::q::s).\n% % \\end{Coqsrc}\n\n\n\n% \\subsection{Mimimal large sequences}\n\n\n\n% Let us consider \\emph{minimal} large sequences, \\emph{i.e.} large sequences \n% the strict prefix of which do not lead to $0$. In other words, only the last ordinal \n% defined by the sequence is null.  For this purpose, we use the predicate \\texttt{path\\_to} introduced page~\\pageref{path-to-definition}.\n\n% \\begin{Coqsrc}\n% Definition mlarge alpha s := path_to zero s alpha.\n% \\end{Coqsrc}\n\n\n\n\n\n\n\n%----------------------------------------------------------------------\n\\chapter[Countable Ordinals (after Sch\\\"{u}tte)]{Kurt Schütte's Axiomatic Definition of Countable Ordinals}\n\n\\label{chap:schutte} \n%ON\n\nIn the present chapter, we  compare our implementation of the segment $[0,\\epsilon_0)$ with a mathematical text in order to ``validate'' our constructions.\nOur reference here is the axiomatic definition of the set of countable ordinals,\nin chapter V of Kurt Schütte's book `` Proof Theory ''~\\cite{schutte}.\n\n\\begin{remark}\n\\emph{In all this chapter, the word ``ordinal'' will be considered as a synonymous of\n``countable ordinal''}  \n\\end{remark}\n\n\n\nSchütte's definition of countable ordinals relies on the following three axioms:\n\nThere  exists a strictly ordered set , such that\n\\begin{enumerate}\n\\item  $(\\mathbb{O},<)$ is well-ordered\n\\item Every bounded subset of $\\mathbb{O}$  is countable\n\\item Every countable subset of $\\mathbb{O}$  is bounded.\n\\end{enumerate}\n\nStarting with these three axioms, Schütte re-defines the vocabulary about ordinal numbers: the null ordinal $0$, limits and successors, the addition of ordinals, the infinite ordinals $\\omega$, $\\epsilon_0$, $\\Gamma_0$, etc.\n\nThis chapter describes an adaptation to \\coq{} of Schütte's axiomatization. \n Unlike the rest of our libraries, our library\n\\href{../theories/html/hydras.Schutte.Schutte.html}{Ordinals.Schutte}\nis not constructive, and relies on several axioms.\n\n\\begin{itemize}\n\\item First, please keep in mind  that the set of countable ordinals is not countable. Thus, we cannot hope to represent all countable ordinals as finite terms of an inductive type, which was possible with  the set of ordinals strictly less than $\\epsilon_0$ (resp. $\\Gamma_0$)\n\\item We tried to be as close as possible to K. Schütte's text, which uses ``classical'' mathematics : excluded middle, Hilbert's $\\epsilon$ (choice) and Russel's $\\iota$ (definite description) operators. Both operators allow us to write definitions close to the natural mathematical language, such as ``$\\textrm{succ}$ is \\emph{the} least ordinal strictly greater than $\\alpha$''\n\\item Please note that only the library \\href{../theories/html/hydras.Schutte.Schutte.html}{Schutte/*.v} is ``contaminated'' by axioms, and that the rest of our libraries remain constructive.\n\\end{itemize}\n\n\\section{Declarations and Axioms}\n\nLet us declare a type \n\\texttt{Ord} for representing countable ordinals, and a binary relation\n \\texttt{lt}. Note that, in our development, \\texttt{Ord} is a type, while the \\emph{set} of countable ordinals (called $\\mathbb{O}$ by Schütte) \nis the full set over the type \\texttt{Ord}.\n\n\\label{types:Ord} \n\nWe use Florian Hatat's library on countable sets, written as he was a student of  \\emph{\\'Ecole Normale Supérieure de Lyon}. A set $A$ is countable if there is an injective function from $A$ to $\\mathbb{N}$ (see \nLibrary \\href{../theories/html/hydras.Schutte.Countable.html}%\n{\\texttt{Schutte.Countable}}).\n\n\n\\vspace{6pt}\n\n\\emph{From Module\\href{../theories/html/hydras.Schutte.Schutte_basics.html}%\n{\\texttt{Schutte.Schutte\\_basics}}}\n\n\\begin{Coqsrc}\nParameter Ord : Type.\nParameter lt : relation Ord.\nInfix \"<\" := lt : schutte_scope.\n\nDefinition ordinal := Full_set Ord.\n\\end{Coqsrc}\n\nSchütte's first axiom tells that \\texttt{lt} is a well order on the set \n\\texttt{ordinal} (The  class \\texttt{WO} is defined in\nModule~\\href{../theories/html/hydras.Schutte.Well_Orders.html}%\n{\\texttt{Well\\_Orders.v}}).\n\n\\label{types:WO}\n\n\\begin{Coqsrc}\nVariables (M:Type)\n         (Lt : relation M).\n  \nClass WO : Type:=\n    {\n      Lt_trans : Transitive  Lt;\n      Lt_irreflexive : forall a:M, ~ (Lt a a);\n      well_order : forall (X:Ensemble M)(a:M),\n          In X a ->\n          exists a0:M, least_member  X a0\n    }.\n\\end{Coqsrc}\n\n\n\n\\begin{Coqsrc}\n  Axiom AX1 : WO lt.\n\\end{Coqsrc}\n\nThe second and third axioms say that a subset $X$ of $\\mathbb{O}$ is\n(strictly) bounded if and only if it is countable. \n\n\n\n\\begin{Coqsrc}\nAxiom AX2 : forall X: Ensemble Ord, \n   (exists a,  (forall y, In X y -> y < a)) ->\n   countable X.\n\nAxiom AX3 : forall X : Ensemble Ord,\n              countable X -> \n              exists a,  forall y, In X y -> y < a.\n\\end{Coqsrc}\n\n\\texttt{AX2} and \\texttt{AX3} could have been replaced by a single axiom (using the \\texttt{iff} connector), but we decide to respect as most as possible the structure of Schütte's definitions.\n\n\\section{Additional  Axioms}\n\nThe adaptation of Schütte's mathematical discourse to \\coq{} led us to\nimport a few axioms from the standard library. We encourage the reader to consult \\coq{}'s FAQ about the safe use of axioms\n \\url{https://github.com/coq/coq/wiki/The-Logic-of-Coq#axioms}.\n\n\\subsubsection{Classical Logic}\n\nIn order to work with classical logic, we import the module\n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Logic.Classical.html}{Coq.Logic.Classical}  of \\coq{}'s standard library, specifially the following axiom:\n\n\\begin{Coqsrc}\n Axiom classic : forall P:Prop, P \\/ ~P.\n\\end{Coqsrc}\n\n\n\\subsubsection{Description Operators}\n\nIn order to respect Schütte's style, we imported also the library \n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Logic.Epsilon.html}{\\texttt{Coq.Logic.Epsilon}}.  The rest of this section presents a few examples of\nhow Hilbert's choice operator and Church's definite description allow us\n to write understandable definitions (close to the mathematical natural language).\n\n\n\\subsubsection{The Definition of zero}\n\nAccording to the  definition of a well order, every non-empty subset of \\texttt{Ord} has a least element. Furthermore, this least element is unique.\n\n\n\\begin{Coqsrc}\nRemark R : exists! z : Ord, least_member lt  ordinal z.\nProof.\n  destruct inh_Ord as [a]; apply (well_order (WO:=AX1)) with a .\n  split.\nQed.\n\\end{Coqsrc}\n\nAssume we want to call this element  \\texttt{zero}.\n\n\n\n\\begin{Coqsrc}\nDefinition zero : Ord.\nProof.\n  Fail destruct R.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nThe command has indeed failed with message:\nCase analysis on sort Type is not allowed for inductive \ndefinition ex.\n\\end{Coqanswer}\n\n\nIndeed, the basic logic of  \\coq{} does not allow us to eliminate a proof of a proposition \n$\\exists\\,x:A,\\,P(x)$ for building a term whose type lies in the sort \\texttt{Type}. \nThe reasons for this impossibility are explained in many documents~\\cite{BC04, chlipalacpdt2011, Coq}.\n\nLet us import the library \\texttt{Coq.Logic.Epsilon}, which contains the following axiom and lemmas.\n\n\n\\begin{Coqsrc}\nAxiom epsilon_statement:\n  forall (A : Type) (P : A->Prop), inhabited A ->\n    {x : A | (exists x, P x) -> P x}.\n\\end{Coqsrc}\n\nHilbert's $\\epsilon$ \\emph{operator} is derived from this  axiom.\n\n\\begin{Coqsrc}\n  Definition epsilon (A : Type) (i:inhabited A) (P : A->Prop) : A\n  := proj1_sig (epsilon_statement P i).\n\nLemma constructive_indefinite_description :\n  forall (A : Type) (P : A->Prop),\n    (exists x, P x) -> { x : A | P x }.\n\\end{Coqsrc}\n\n\n\n\nIf we consider the \\emph{unique existential} quantifier $\\exists!$, we obtain\nChurch's \\emph{definite description operator}.\n\n\\begin{Coqsrc}\nDefinition iota (A : Type) (i:inhabited A) (P : A->Prop) : A\n  := proj1_sig (iota_statement P i).\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\n Lemma constructive_definite_description :\n  forall (A : Type) (P : A->Prop),\n    (exists! x, P x) -> { x : A | P x }.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nDefinition iota_spec (A : Type) (i:inhabited A) (P : A->Prop) :\n  (exists! x:A, P x) -> P (iota i P)\n  := proj2_sig (iota_statement P i).\n\\end{Coqsrc}\n\n\n\nIndeed, the operators \\texttt{epsilon} and \\texttt{iota} allowed us to make our definitions \nquite close to Schütte's text. Our libraries \\href{../theories/html/hydras.Schutte.MoreEpsilonIota.html}%\n{\\texttt{Schutte.MoreEpsilonIota}}\nand\n\\href{../theories/html/hydras.Schutte.PartialFun.html}%\n{\\texttt{Schutte.PartialFun}} are extensions of \\texttt{Coq.logic.Epsilon} for making easier \nsuch definitions. See also an article in french~\\cite{PCiota}. \n\n\n\n\\begin{Coqsrc}\nClass InH (A: Type) : Prop :=\n   InHWit : inhabited A.\n\nDefinition some {A:Type} {H : InH A} (P: A -> Prop) := \n   epsilon (@InHWit A H) P.\n\nDefinition the {A:Type} {H : InH A} (P: A -> Prop) := \n   iota (@InHWit A H) P.\n\\end{Coqsrc}\n\nIn order to use these tools,  we had to tell \\coq{}  that the type \\texttt{Ord} is not empty:\n\n\\begin{Coqsrc}\nAxiom inh_Ord : inhabited Ord.\n\\end{Coqsrc}\n\n\nWe are now able to define \\texttt{zero} as the least ordinal. For this purpose,\nwe define a function returning the least element of any [non-empty]  subset.\n\n\n\\begin{Coqsrc}\nDefinition the_least {M: Type} {Lt}\n           {inh : InH M} {WO: WO Lt} (X: Ensemble M)  : M :=\n  the  (least_member  Lt X ).\n\\end{Coqsrc}\n\n\n\\vspace{4pt}\n\nFrom Module \\href{../theories/html/hydras.Schutte.Schutte_basics.html}%\n{\\texttt{~Schutte.Schutte\\_basics}}\n\n\\label{Constants:zero:Ord}\n\n\\begin{Coqsrc}\nDefinition zero: Ord :=the_least ordinal.\n\\end{Coqsrc}\n\nWe want to prove now that zero is less than or equal to any ordinal number.\n\n\\begin{Coqsrc}\nLemma zero_le (alpha : Ord) :  zero <= alpha.\nProof.\n  unfold zero, the_least, the; apply iota_ind.\n\\end{Coqsrc}\n\nAccording to the use of the description operator \\texttt{iota}, we have to solve  two trivial sub-goals.\n\\begin{enumerate}\n\\item Prove that there exists a unique least member of \\texttt{Ord}\n\\item Prove that being a least member of \\texttt{Ord} entails the announced inequality \n\\end{enumerate}\n\n\n\\begin{Coqanswer}\n2 subgoals (ID 155)\n  \n  alpha : Ord\n  ============================\n  exists ! x : Ord, least_member lt ordinal x\n\nsubgoal 2 (ID 156) is:\n forall a : Ord, unique (least_member lt ordinal) a -> \n                a <= alpha\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  -  apply the_least_unicity, Inh_ord.\n  -  destruct 1 as [[_ H1] _]; apply H1; split. \nQed.\n\\end{Coqsrc}\n\n\\subsubsection{Remarks on \\texttt{epsilon} and \\texttt{iota}}\n\n What would happen in case of a misuse of \\texttt{epsilon} or \\texttt{iota} ?\nFor instance, one could give a unsatisfiable specification to \\texttt{epsilon} or \na specification for \\texttt{iota} that admits several realizations.\n\nLet us consider an example:\n\n\\begin{Coqbad}\nModule Bad.\n\n Definition bottom := the_least (Empty_set Ord).\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n bottom is defined\n\\end{Coqanswer}\n\nSince we won't be able to prove the proposition\n\\linebreak \\Verb|{exists! a: Ord, least_member (Empty_set Ord) a|, the only properties we would be able to prove about \\texttt{bottom} would be \\emph{trivial} properties, \n\\emph{i.e.}, satisfied by \\emph{any} element of type \\texttt{Ord}, like for instance\n\\texttt{bottom = bottom}, or \\texttt{zero <= bottom}.\n\n\\begin{Coqbad}\nLemma le_zero_bottom : zero <= bottom. \nProof. apply zero_le. Qed.\n\nLemma bottom_eq : bottom = bottom.\nProof. trivial. Qed.\n\nLemma le_bottom_zero : bottom <= zero.\nProof.\n   unfold bottom, the_least, the; apply iota_ind.\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n2 subgoals (ID 413)\n  \n  ============================\n  exists ! x : Ord, least_member lt (Empty_set Ord) x\n\nsubgoal 2 (ID 414) is:\n forall a : Ord, unique (least_member lt (Empty_set Ord)) a -> \n      a <= zero\n\\end{Coqanswer}\n\n\\begin{Coqbad}\nAbort.\nEnd Bad.\n\\end{Coqbad}\n\n\nIn short, using \\texttt{epsilon} and \\texttt{iota} in our implementation of countable ordinals after Schütte has two main advantages.\n\n\n\\begin{itemize}\n\\item It allows us to give a \\emph{name} (using \\texttt{Definition}) two witnesses \nof existential quantifiers (let us recall that, in classical logic, one may consider non-constructive proofs of existential statements)\n\\item By separating definitions from proofs of [unique] existence, one may make definitions  more concise and readable. Look for instance at \nthe definitions of  \\texttt{zero}, \\texttt{succ}, \\texttt{plus}, etc. in the rest of this chapter.\n\\end{itemize}\n%%%% ICI ICI \n\n\\section{The  Successor Function}\n\nThe definition of the function \\texttt{succ:Ord -> Ord} is very concise. The successor of any ordinal $\\alpha$ is the smallest ordinal strictly greater than $\\alpha$.\n\n\\label{Functions:succ-sch}\n\n\\begin{Coqsrc}\nDefinition succ (alpha : Ord) := the_least (fun beta => alpha < beta).\n\\end{Coqsrc}\n\nUsing \\texttt{succ}, we define the folloing predicates.\n\n\\begin{Coqsrc}\nDefinition is_succ (alpha:Ord) := exists beta, alpha = succ beta.\n\nDefinition is_limit (alpha:Ord) := alpha <> zero /\\ ~ is_succ alpha.\n\\end{Coqsrc}\n\n\n\n% \\begin{remark}\n% Please look at remark~\\vref{warning:coercions}.\n% \\end{remark}\n\nHow do we prove properties of the successor function?\nFirst, we make its specification explicit.\n\n\\begin{Coqsrc}\nDefinition succ_spec (alpha:Ord) :=\n  least_member   lt (fun z => alpha < z).\n\\end{Coqsrc}\n\nThen, we prove that our function \\texttt{succ} meets this specification. \n\n\n\\begin{Coqsrc}\nLemma succ_ok : forall alpha,  succ_spec alpha  (succ alpha).\nProof.\n  intros; unfold succ, the_least, the;  apply iota_spec.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n1 subgoal (ID 172)\n  \n  alpha : Ord\n  ============================\n  exists ! x : Ord, succ_spec alpha x\n\\end{Coqanswer}\n\nWe have now to prove that the set of all ordinals strictly greater than $\\alpha$ has a unique least element. But the singleton set $\\{\\alpha\\}$ is countable, hence  bounded (by the axiom \\texttt{AX3}). Hence; the set $\\{\\beta\\in\\mathbb{O}|\\alpha < \\beta\\}$ is not empty\nand therefore has a unique least element.\n\nThe \\coq{} proof script is quite short.\n\n\\begin{Coqsrc}\n  destruct (@AX3 (Singleton _ alpha)).\n  - apply countable_singleton.\n  -  unfold succ_spec; apply the_least_unicity;  exists x; intuition.\nQed.     \n\\end{Coqsrc}\n\n\nWe can ``uncap'' the description operator for proving properties of the\n\\texttt{succ} function.\n\n\\begin{Coqsrc}\nLemma lt_succ (alpha : Ord) :  alpha < succ alpha.\nProof.\n  destruct  (succ_ok  alpha);  tauto.\nQed.\n\nHint Resolve lt_succ : schutte.\n\nLemma lt_succ_le (alpha beta : Ord):\n  alpha < beta -> succ alpha <= beta.\nProof with eauto with schutte.\n  intros  H;  pattern (succ alpha); apply the_least_ok ... \n  exists (succ alpha); red;apply lt_succ ...\nQed.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma lt_succ_le_2 (alpha beta : Ord):\n  alpha < succ beta -> alpha <= beta.\n\nLemma succ_mono (alpha beta : Ord):\n  alpha < beta -> succ alpha < succ beta.\n\nLemma succ_monoR (alpha beta : Ord) :\n succ alpha < succ beta -> alpha < beta.\n\nLemma lt_succ_lt (alpha beta : Ord) :\n  is_limit beta ->  alpha < beta -> succ alpha < beta.\n\\end{Coqsrc}\n\n\\section{Finite Ordinals}\n\nUsing \\texttt{succ}, it is now easy to define recursively all the finite ordinals.\n\n\\label{sect:notation-F-sch}\n\n\\begin{Coqsrc}\nReserved Notation \"'F' n\" (at level 29) .\n\nFixpoint finite (i:nat) : Ord :=\n  match i with \n            | 0 => zero\n            | S i => succ (F i)\n  end\nwhere \"'F' i\" := (finite i)  : schutte_scope.\n\nCoercion finite : nat >-> Ord.\n\\end{Coqsrc}\n\n\\section{The Definition of \\texttt{omega}}\nIn order to define $\\omega$, the first infinite ordinal, we use an operator which\n``returns'' the least upper bound (if it exists) of a subset $X\\subseteq \\mathbb{O}$.\nFor that purpose, we first use a predicate:\n(\\texttt{is\\_lub $D$ \\textit{lt} $X$ $a$}) if $a$ belongs to $D$ and is the least \nupper bound  of $X$ (with respect to \\textit{lt}).\n\n\n\\begin{Coqsrc}\nDefinition is_lub (M:Type)\n                  (D : Ensemble M)\n                  (lt : relation M)\n                  (X:Ensemble M)\n                  (a:M) :=\n   In _ D a  /\\ upper_bound  D lt X a  /\\\n   (forall y, In _ D y -> upper_bound  D lt X y  -> \n                  y = a \\/ lt a y).\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nDefinition sup_spec X lambda := is_lub ordinal lt X lambda.\n\nDefinition sup (X: Ensemble Ord) : Ord  := the  (sup_spec X).\n\nNotation \"'|_|' X\" := (sup X) (at level 29) : schutte_scope.\n\\end{Coqsrc}\n\n\n\nThen, we define the function \\texttt{omega\\_limit} which returns the least upper bound \nof the  (denumerable) range of any sequence \\texttt{s: nat -> Ord}. \nBy \\texttt{AX3} this range is bounded, hence the set of its upper bounds is not empty and has a least element.\n\n\n\\begin{Coqsrc}\nDefinition omega_limit (s:nat->Ord) : Ord \n  := |_| (seq_range s).\n\\end{Coqsrc}\n\nThen we define \\texttt{omega} as the limit of the sequence of finite ordinals.\n\n\n\\label{sect:notation-omega}\n\\begin{Coqsrc}\nDefinition _omega := omega_limit finite.\n\nNotation \"'omega'\" := (_omega) : schutte_scope.\n\\end{Coqsrc}\n\n\n\nAmong the numerous properties of the ordinal $\\omega$, les us quote the following ones\n(proved in Module \n\\href{../theories/html/hydras.Schutte.Schutte_basics.html\\#finite_lt_omega}{\\texttt{Schutte.Schutte\\_basics}})\n\n\\begin{Coqsrc}\nLemma finite_lt_omega : forall i: nat,  i < omega.\n\nLemma lt_omega_finite alpha : Ord) : \n  alpha < omega ->  exists i:nat, alpha =  i.\n\nLemma is_limit_omega : is_limit omega.\n\\end{Coqsrc}\n\n\n\\subsection{Ordering Functions and Ordinal Addition}\n\nAfter having defined the finite ordinals and the infinite ordinal $\\omega$, we  define the sum $\\alpha+\\beta$ of two countable ordinals.\nSchütte's definition looks like the following one:\n\n\\begin{quote}\n``$\\alpha+\\beta$ is the $\\beta$-th ordinal greater than or equal to $\\alpha$''\n\\end{quote}\n\n\nThe purpose of this section is to give a meaning to the construction\n``the $\\alpha$-th element of $X$''  where $X$ is any non-empty subset of $\\mathbb{O}$.\nWe follow Schütte's approach, by defining the notion of \\emph{ordering functions},\na way to associate a unique ordinal to each element of $X$.\nComplete definitions and proofs can be found in Module\n \\href{../theories/html/hydras.Schutte.Ordering_Functions.html}%\n{\\texttt{Schutte.Ordering\\_Functions}} ).\n\n\\subsection{Definitions}\n\nA \\emph{segment} is a set $A$ of ordinals such that, whenever  $\\alpha\\in A$ and\n$\\beta<\\alpha$, then $\\beta\\in A$; a segment is  \\emph{proper} if it strictly included in $\\mathbb{O}$.\n\n\\begin{Coqsrc}\n Definition segment (A: Ensemble Ord) :=\n  forall alpha beta, In A alpha -> beta < alpha -> In A  beta.\n\nDefinition proper_segment (A: Ensemble Ord) :=\n  segment A /\\ ~ Same_set A ordinal.\n\\end{Coqsrc}\n\n\nLet  $A$ be a segment, and $B$ a subset of $\\mathbb{O}$ : an \\emph{ordering function for $A$ and  $B$} is a strictly increasing bijection from $A$ to $B$.\nThe set $B$ is said to be an \\emph{ordering segment} of $A$.\nOur definition in \\coq{} is a direct translation of the mathematical text of~\\cite{schutte}.\n\n\\index{Maths!Ordering functions}\n\n\\begin{Coqsrc}\nDefinition ordering_function (f : Ord -> Ord)(A B : Ensemble Ord) :=\n segment A /\\\n (forall a, In A a -> In B (f a)) /\\\n (forall b, B b -> exists a, In A a /\\ f a = b) /\\\n forall a b, In A a -> In A b -> a < b ->  f a < f b.\n\nDefinition ordering_segment (A B : Ensemble Ord) :=\n  exists f : Ord -> Ord, ordering_function f A B.\n\\end{Coqsrc}\n\n\nWe are now able to associate with any subset $B$ of $\\mathbb{O}$ its ordering segment and ordering function.\n\n\\begin{Coqsrc}\nDefinition the_ordering_segment (B : Ensemble Ord) :=\n  the  (fun x => ordering_segment x B).\n\nDefinition ord  (B : Ensemble Ord) := \n  some (fun f => ordering_function f (the_ordering_segment B) B).\n\\end{Coqsrc}\n\nThus (\\texttt{ord $B \\;\\alpha$}) is the $\\alpha$-th element of $B$.\nPlease note that the last definition uses the epsilon-based operator \\texttt{some} and\nnot \\texttt{the}. This is due to the fact that we cannot prove the unicity (w.r.t. Leibniz' equality) of the ordering function of a given set. \nBy contrast, we admit the axiom  \\texttt{Extensionality\\_Ensembles}, from the library \n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Sets.Ensembles.html}{Coq.Sets.Ensembles}, so we use the operator \\texttt{the} in the definition of\n\\texttt{the\\_ordering\\_segment}.\n\nOne of the main theorems of\n\\href{../theories/html/hydras.Schutte.Ordering_Functions.html\\#ordering_function_ex}%\n{\\texttt{Ordering\\_Functions}} \nassociates a unique segment and a unique (up to extensionality) ordering function to every subset $B$ of $\\mathbb{O}$.\n\n\\begin{Coqsrc}\nAbout ordering_function_ex.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nforall B : Ensemble Ord,\n exists ! S : Ensemble Ord, \n      exists f : Ord -> Ord, ordering_function f S B\n\\end{Coqanswer}\n\n\n\\begin{Coqanswer}\nordering_function_unicity :\nforall (B S1 S2 : Ensemble Ord) (f1 f2 : Ord -> Ord),\nordering_function f1 S B ->\nordering_function f2 S2 B -> \nfun_equiv f1 f2 S1 S2\n\\end{Coqanswer}\n\nThus,  our function \\texttt{ord}  which enumerates the elements of $B$ is defined in a non-ambiguous way.\nLet us quote the following theorems (see Library\n\\href{../theories/html/hydras.Schutte.Ordering_Functions.html}%\n{\\texttt{Schutte.Ordering\\_Functions}} for more details).\n \n\n\\begin{Coqsrc}\nTheorem ordering_le : forall f A B,\n    ordering_function f A B ->\n    forall alpha, In A alpha -> alpha <= f alpha.\n\nTh_13_5_2 :\nforall (A B : Ensemble Ord) (f : Ord -> Ord),\nordering_function f A B -> Closed B -> continuous f A B\n\\end{Coqsrc}\n\n\n\\subsection{Ordinal Addition}\n\nWe are now ready to define and study addition on the type \\texttt{Ord}.\nThe following definitions and proofs can be consulted in Module\n\\href{../theories/html/hydras.Schutte.Addition.html}%\n{\\texttt{Schutte.Addition.v}}.\n\n\\begin{Coqsrc}\nDefinition plus alpha := ord  (ge alpha).\nNotation \"alpha + beta \" := (plus alpha beta) : schutte_scope.\n\\end{Coqsrc}\n\nIn other words,  $\\alpha + \\beta$ is the  $\\beta$-th ordinal greater than or equal to $\\alpha$. \nThanks to generic properties of ordering functions, we can show the following \nproperties of addition on $\\mathbb{O}$. First, we prove a useful lemma:\n\n\\begin{Coqsrc}\nLemma plus_elim (alpha : Ord) :\n  forall P : (Ord->Ord)->Prop,\n    (forall f: Ord->Ord, \n        ordering_function f ordinal (ge alpha)-> P f) ->\n    P (plus alpha).\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma alpha_plus_zero (alpha: Ord): alpha + zero = alpha.\nProof.\n pattern  (plus alpha); apply plus_elim; eauto.\n \\end{Coqsrc}\n\n \\begin{Coqanswer}\n 1 subgoal (ID 24)\n  \n  alpha : Ord\n  ============================\n  forall f : Ord -> Ord,\n  ordering_function f ordinal (ge alpha) -> \n  f zero = alpha\n \\end{Coqanswer}\n\n \\begin{Coqsrc}\n (* rest of proof skipped *)\n \\end{Coqsrc}\n\nThe following lemmas are proved the same way.\n\n \\begin{Coqsrc}\n\nLemma zero_plus_alpha (alpha : Ord) : zero + alpha = alpha.\n\nLemma le_plus_l (alpha beta : Ord) : alpha <= alpha + beta.\n\nLemma le_plus_r (alpha beta : Ord) :  beta <= alpha + beta.\n\nLemma plus_mono_r (alpha beta gamma : Ord) : \n    beta < gamma -> alpha + beta < alpha + gamma.\n\nLemma plus_of_succ (alpha beta : Ord) :\n    alpha + (succ beta) = succ (alpha + beta).\n\nTheorem plus_assoc (alpha beta gamma : Ord) :\n  alpha + (beta + gamma) = (alpha + beta) + gamma.\n\nLemma one_plus_omega :  1 + omega = omega.\n\nLemma finite_plus_infinite (n : nat) (alpha : Ord) :\n  omega <= alpha -> n + alpha = alpha.\n\\end{Coqsrc} \n\n\nIt isinteresting to compare the proof of these lemmas with the \ncomputational proofs of the corresponding statements in Module\n\\href{../theories/html/hydras.Epsilon0.T1.html}%\n{\\texttt{Epsilon0.T1}}. \nFor instance, the proof of the lemma \n\\texttt{one\\_plus\\_omega} uses the continuity of ordering functions (applied to  \\texttt{(plus 1)}) and compares the limit of the $\\omega$-sequences $i_{(i \\in \\mathbb{N})}$ and\n$(1+i)i_{(i \\in \\mathbb{N})}$, whereas in the library  \\texttt{Epsilon0/T1}, the equality \n$1+\\omega=\\omega$ is just proved with \\texttt{reflexivity}!\n\n\n\n\\subsubsection{Multiplication by a Natural Number}\n\nThe multiplication of an ordinal by a natural number is defined in terms of addition.\nThis operation is useful for the study of Cantor normal forms.\n\n\\begin{Coqsrc}\nFixpoint mult_Sn (alpha:Ord)(n:nat){struct n}: Ord :=\n match n with \n            | 0 => alpha\n            | S p => mult_Sn  alpha p + alpha\n end.\n\nDefinition mult_fin_r alpha n :=\n  match n with\n      0 => zero\n    | S p => mult_Sn alpha p\n  end.\n\nNotation \"alpha * n\" := (mult_fin_r alpha n) : schutte_scope.\n\\end{Coqsrc}\n\n\\section{The Exponential of Basis \\texorpdfstring{$\\omega$}{omega}}\n\nIn this section, we define the function which maps any $\\alpha\\in\\mathbb{O}$ to\nthe ordinal  $\\omega^\\alpha$, also written \n$\\phi_0(\\alpha)$. \nIt is an opportunity to apply the definitions and results of the preceding section. \nIndeed,  Schütte first defines a subset of $\\mathbb{O}$: the set of additive principal ordinals, and $\\phi_0$  is just defined as the ordering function of this set.\n\n\\subsection{Additive Principal Ordinals}\n\n\\index{Maths!Additive principal ordinals}\n\n\\begin{definition}\nA non-zero ordinal  $\\alpha$ is said to be \\emph{additive principal} if, for all  $\\beta<\\alpha$, $\\beta+\\alpha$ is equal to  $\\alpha$.\nWe call \\texttt{AP} the set of additive principal ordinals.\n\n\\end{definition}\n\n\n\n\\noindent\\emph{From Module \\href{../theories/html/hydras.Schutte.AP.html}%\n{\\texttt{Schutte.AP}}}\n\n\\begin{Coqsrc}\nDefinition AP : Ensemble Ord :=\n  fun alpha => \n  zero < alpha /\\\n  (forall beta, beta < alpha ->  beta + alpha = alpha).\n\\end{Coqsrc}\n\n\\subsection{The Function \\texttt{phi0}}\n\nLet us call  $\\phi_0$ the ordering function of \\texttt{AP}.\nIn the mathematical text, we shall use indifferently the notations  $\\omega^\\alpha$ and$\\phi_0(\\alpha)$. \n\n\n\\begin{Coqsrc}\nDefinition phi0 := ord AP.\n\nNotation \"'omega^'\" := phi0 (only parsing) : schutte_scope.\n\\end{Coqsrc}\n\n\\subsection{Omega-towers and the Ordinal \\texorpdfstring{$\\epsilon_0$}{epsilon0}}\n\n\nUsing $\\phi_0$, we can define recursively the set of finite omega-towers.\n\n\n\\begin{Coqsrc}\nFixpoint omega_tower (i : nat) : Ord :=\n  match i with\n    0 =>  1\n  | S j => phi0 (omega_tower j)\n  end.\n\\end{Coqsrc}\n\n\\label{sect:epsilon0-as-limit}\nThen, the ordinal  $\\epsilon_0$ is defined as the limit of the sequence of all finite towers (a kind of infinite tower).\n\n\\begin{Coqsrc}\nDefinition epsilon0 := omega_limit omega_tower.\n\\end{Coqsrc}\n\nThe rest of our library \\texttt{AP} is devoted to the proof of properties of additive principal ordinals, hence of the ordering function  $\\phi0$ and the ordinal $\\epsilon_0$ (which we could not express within the type \\texttt{T1}).\n\n\\subsection{Properties of the Set  \\texttt{AP}}\n\nThe set of additive principal ordinals is not empty: it contains at least the ordinals  $1$ and  $\\omega$. \n\n\\begin{Coqsrc}\nLemma AP_one : In AP 1.\n\nLemma AP_omega : In AP omega.\n\\end{Coqsrc}\n\nMoreover, $1$ is the least principal ordinal and $\\omega$ is the second element of\n\\texttt{AP}.\n\n\n\\begin{Coqsrc}\nLemma least_AP: least_member  lt AP 1. \n\nLemma omega_second_AP :\n  least_member   lt \n                  (fun alpha => 1 < alpha /\\ In AP alpha)\n                  omega.\n\\end{Coqsrc}\n\nThe set  \\texttt{AP} is  \\emph{closed} under addition, and unbounded.\n\n\\begin{Coqsrc}\nLemma AP_plus_closed (alpha beta gamma : Ord): \n     In AP alpha -> beta < alpha -> gamma < alpha ->\n     beta + gamma < alpha.\n\nTheorem AP_unbounded : Unbounded AP.\n\\end{Coqsrc}\n\nFinally, \\texttt{AP} is (topologically) \\emph{closed} and ordered by the segment of all countable ordinals.\n\n\\index{Predicates!Closed}\n\n\\begin{Coqsrc} \nDefinition Closed (B : Ensemble Ord) : Prop := \n  forall M, Included M B -> Inhabited _ M -> \n                 countable M -> In B (|_| M).\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nTheorem AP_closed : Closed AP.\n\nLemma AP_o_segment :  the_ordering_segment AP = ordinal.\n\\end{Coqsrc}\n\n\\subsubsection{Properties of the Function \\texorpdfstring{$\\phi_0$}{phi0}}\n \nThe ordering function $\\phi_0$ of the set \\texttt{AP} is defined on the full set $\\mathbb{O}$ and is continuous (Schütte calls such a  function  \\emph{normal}).\n\n\\begin{Coqsrc}\nTheorem normal_phi0 : normal phi0 AP.\n\\end{Coqsrc}\n\nThe following properties come from  the definition of $\\phi_0$ as the ordering function of \\texttt{AP}. It may be interesting to compare these proofs with the computational ones described in Chapter ~\\ref{chap:T1}.\n\n\\begin{Coqsrc}\nLemma AP_phi0 (alpha : Ord) : In AP (phi0 alpha).\n\nLemma phi0_zero : phi0 zero =  1.\n\nLemma phi0_mono (alpha beta : Ord) :\n  alpha < beta ->  phi0 alpha < phi0 beta.\n\nLemma phi0_inj (alpha beta : Ord) :\n    phi0 alpha = phi0 beta -> alpha = beta.\n\nLemma phi0_sup : forall (U: Ensemble Ord),\n   Inhabited _ U ->   countable U ->  phi0 (|_| U) = |_| (image U phi0).\n\nLemma is_limit_phi0 (alpha : Ord) :\n  zero < alpha ->  is_limit (phi0 alpha).\n\nLemma omega_eq : omega = phi0 1. \n\nLemma phi0_le (alpha : Ord) : alpha <= phi0 alpha.\n\\end{Coqsrc}\n\nPlease note that the lemma \\texttt{omega\\_eq} above, is consistent with the interpretation of the ordering function $\\phi_0$ as the exponential of basis $\\omega$. Indeed we could have written this lemma with our alternative notation:\n\n\\begin{Coqsrc}\n Lemma omega_eq : omega = omega^ 1.\n\\end{Coqsrc}\n\n\\section{More about \\texorpdfstring{$\\epsilon_0$}{\\texttt{epsilon0}}}\n\nLet us recall that the limit ordinal  $\\epsilon_0$ cannot be written within the type \\texttt{T1}. Since we are now considering the set of all countable ordinals, we can now prove some properties of this ordinal.\n\n\nWe prove the inequality  $\\alpha<\\omega^\\alpha$ whenever $\\alpha < \\epsilon_0$.\n\\emph{Note that this condition was implicit in Module \\href{../theories/html/hydras.Epsilon0/T1.html\\#lt_phi0}%\n{\\texttt{Epsilon0.T1}}.}\n\n\\begin{Coqsrc}\nLemma lt_phi0 (alpha : Ord):\n  alpha < epsilon0 -> alpha < phi0 alpha.\n\\end{Coqsrc}\n\nThe proof is as follows:\n\\begin{enumerate}\n\\item Since $\\alpha<\\epsilon_0$, consider the least $i$ such that $\\alpha$ is strictly less than the omega-tower of height $i$.\n\\item\n  \\begin{itemize}\n  \\item If $i=0$, then the result is trivial (because $\\alpha=0$)\n \\item  Otherwise let $i=j+1$; \n          $\\alpha$ is greater than or equal to the omega-tower of height $j$.\n         By monotonicity,  $\\phi_0(\\alpha)$ is greater than or equal to \n        the omega-tower of height $j+1$, thus strictly greater than $\\alpha$\n  \\end{itemize}\n \\end{enumerate}\n\nMoreover,  $\\epsilon_0$ is the least ordinal $\\alpha$ that verifies the equality \n$\\alpha = \\omega^\\alpha$, in other words the least fixpoint of the function  $\\phi_0$.\n\n\\begin{Coqsrc}\nTheorem epsilon0_lfp : least_fixpoint lt phi0 epsilon0.\n\\end{Coqsrc}\n\n\n\\section{Critical Ordinals}\n\n\\index{Maths!Critical ordinals}\n\nFor any  (countable) ordinal $\\alpha$, the set $\\textit{Cr}(\\alpha)$ is inductively defined \nas follows by Schütte (p.81 of~\\cite{schutte}).\n\n\\begin{quote}\n  \\begin{itemize}\n  \\item $\\textit{Cr}(0)$ is the set \\textit{AP} of additive principal ordinals.\n  \\item If $0<\\alpha$, then $\\textit{Cr}(\\alpha)$ is the intersection of all the sets of fixpoints of the $\\textit{Cr}(\\beta)$ for $\\beta<\\alpha$.\n  \\end{itemize}\n\\end{quote}\n\nThis definition is translated in \\coq{} in \nModule \\href{../theories/html/hydras.Schutte.Critical.html}%\n{\\texttt{Schutte.Critical}}, as the least fixpoint of a functional. \n\n\n\\begin{Coqsrc}\nDefinition Cr_fun : forall alpha : Ord,\n       (forall beta : Ord, beta < alpha -> Ensemble Ord) ->\n        Ensemble Ord \n:= \n   fun (alpha :Ord)\n        (Cr : forall beta, \n                beta < alpha -> Ensemble Ord) \n        (x : Ord) => (\n       (alpha = zero /\\ AP x) \\/\n       (zero < alpha /\\\n        forall beta (H:beta < alpha),\n          the_ordering_segment (Cr beta H) x /\\ ord (Cr  beta H) x = x)).\n\nDefinition Cr (alpha : Ord) : Ensemble Ord := \n    (Fix  all_ord_acc (fun (_:Ord) => Ensemble Ord) Cr_fun) alpha.\n\\end{Coqsrc}\n\n\\label{sect:phi-schutte}\n\n\\begin{Coqsrc}\nDefinition phi (alpha : Ord) : Ord -> Ord \n    :=  ord (Cr alpha).\n\nDefinition A (alpha : Ord) : Ensemble Ord :=\n  the_ordering_segment (Cr alpha).\n\\end{Coqsrc}\n\nFor instance,  we prove that $\\textit{Cr}(0)$ is the set of additive principals and that $\\epsilon_0$\nbelongs to $\\textit{Cr}(1)$.\n\n\\begin{Coqsrc}\nLemma Cr_zero_AP :  Cr 0 = AP\n\nLemma epsilon0_Cr1 : In (Cr 1) epsilon0.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\n Prove that $\\epsilon_0$ is the least element of $\\textit{Cr}(1)$.\n\\end{exercise}\n\n\n\\subsection{A flavor of Infinity}\n\n\n\nThe family of the $\\textit{Cr}(\\alpha)$s is made of infinitely many unbounded (hence infinite) sets.\nLet us quote Lemma 5, p. 82  of~\\cite{schutte}:\n\\begin{quote}\n  For all $\\alpha$, the set $\\textit{Cr}(\\alpha)$ is closed (for the least upper bound of non-empty countable sets) and unbounded.\n\\end{quote}\n\nWe prove this result by transfinite induction on $\\alpha$ of both properties.\n\nThe proof is still quite long, by transfinite induction over $\\alpha$.\n\n\n\\index{Coq!Techniques!Transfinite induction}\n\n\\begin{Coqsrc}\nSection Proof_of_Lemma5.\n  Let P (alpha:Ord) := Unbounded (Cr alpha) /\\ Closed (Cr alpha).\n \n Lemma Lemma5 : forall alpha, P alpha.\n(* ... *)\n End Proof_of_Lemma5.\n\nCorollary Unbounded_Cr alpha : Unbounded (Cr alpha).\nProof.\n  now destruct (Lemma5 alpha).\nQed.\n\nCorollary Closed_Cr alpha : Closed (Cr alpha).\nProof.\n  now destruct (Lemma5 alpha).\nQed.\n\\end{Coqsrc}\n\n\\section{Cantor Normal Form}\n\nThe notion of Cantor normal form is defined for all countable ordinals.\nNevertheless, note that, contrary to the implementation based on type \\texttt{T1},\nthe Cantor normal form of an ordinal $\\alpha$ may contain $\\alpha$ as a \nsub-term\\footnote{This would prevent us from trying to represent Cantor normal forms as finite trees (like in Sect.~\\ref{sec:T1-inductive-def})}.\n\n\nWe represent  Cantor normal forms as lists of ordinals.\nA  list $l$ is a Cantor normal form of a given ordinal $\\alpha$ if it satisfies two conditions:\n\n\n\n\\begin{itemize}\n\\item The list  $l$ is sorted (in decreasing order) w.r.t. the order $\\leq$\n\\item The sum of all the  $\\omega^{\\beta_i}$ where the $\\beta_i$ are the terms of $l$ (in this order) is equal to $\\alpha$.\n\\end{itemize}\n\n\n\n\\vspace{4pt}\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Schutte.CNF.html\\#cnf_t}%\n{\\texttt{Schutte.CNF}}}\n\n\n\\begin{Coqsrc}\n Definition cnf_t := list Ord.\n\nFixpoint eval (l : cnf_t) : Ord :=\n  match l with nil => zero\n              | beta :: l' => phi0 beta + eval l'\n  end.\n\nDefinition sorted (l: cnf_t) :=\n  LocallySorted (fun alpha beta => beta <= alpha) l.\n\nDefinition is_cnf_of (alpha : Ord)(l : cnf_t) : Prop :=\n  sorted l /\\ alpha = eval l.\n\\end{Coqsrc}\n\n\\index{Maths!Transfinite induction}\n\nBy transfinite induction on $\\alpha$, we prove that every countable ordinal $\\alpha$ \n has at least a Cantor normal form.\n\n\\begin{Coqsrc}\nTheorem cnf_exists (alpha : Ord) :\n  exists l: cnf_t, is_cnf_of alpha l.\n\\end{Coqsrc}\n\nBy structural induction on lists, we prove that this normal form is unique.\n\n\\begin{Coqsrc}\n Lemma cnf_unicity : forall l alpha, \n   is_cnf_of alpha l -> \n   forall l',  is_cnf_of alpha l' -> l=l'.\nProof.\n induction l.\n (*  ...  *)\n\nTheorem cnf_exists_unique (alpha:Ord) :\n  exists! l: cnf_t, is_cnf_of alpha l.\n\\end{Coqsrc}\n\n\nFinally, the following two lemmas relate  $\\epsilon_0$ with Cantor normal forms.\n\nIf $\\alpha<\\epsilon_0$, then the Cantor normal form of $\\alpha$ is made of ordinals strictly less than $\\alpha$.\n\n\\begin{Coqsrc}\nLemma cnf_lt_epsilon0 : \n forall l alpha, \n   is_cnf_of alpha l ->  alpha < epsilon0 ->\n   Forall (fun beta =>  beta < alpha) l.\n\\end{Coqsrc}\n\n\\index{Exercises}\n\n\\begin{exercise}\nPlease consider the following statement :\n\n\\begin{Coqsrc}\nLemma cnf_lt_epsilon0_iff : \n forall l alpha, \n   is_cnf_of alpha l ->  \n   (alpha < epsilon0 <->  Forall (fun beta =>  beta < alpha) l).\n\\end{Coqsrc}\n\nIs it true ?\n\\end{exercise}\n\nFinally, the Cantor normal form of $\\epsilon_0$ is just $\\omega^{\\epsilon_0}$.\n\n\\begin{Coqsrc}\nLemma cnf_of_epsilon0 : is_cnf_of epsilon0 (epsilon0 :: nil).\nProof.\n  split.\n  - constructor.  \n  - simpl;  now rewrite alpha_plus_zero, epsilon0_fxp.\nQed.\n\\end{Coqsrc}\n\n\\index{Projects}\n\n\\begin{project}\nImplement pages 82 to 85 of~\\cite{schutte} (critical, strongly critical, maximal critical ordinals, Feferman's ordinal $\\Gamma_0$).\n\\end{project}\n\n\\begin{remark}\nThe sub-directory \\href{../theories/html/hydras.Gamma0.html}%\n{\\texttt{theories/Gamma0}} contains an (incomplete, still undocumented) implementation of the set of ordinals below $\\Gamma_0$, represented in Veblen normal form. \n\\end{remark}\n\n\\section{An Embedding of \\texttt{T1} into \\texttt{Ord}}\n\n\nOur library \n\\href{../theories/html/hydras.Schutte.correctness_E0.html}%\n{\\texttt{Schutte.Correctness\\_E0}} establishes the link between two very different modelizations of ordinal numbers. In other words, it ``validates'' a data structure in terms of\na classical mathematical discourse considered as a model. \nFirst, we define a function from \\texttt{T1} into  \\texttt{Ord} by structural recursion.\n\n\\begin{Coqsrc}\nFixpoint inject (t:T1) : Ord :=\n match t with \n     | T1.zero => zero\n     | T1.ocons a n b =>  AP.phi0 (inject a) * S n + inject b\n end.  \n\\end{Coqsrc}\n\nThis function enjoys good commutation properties with respect to the main operations which\nallow us to build Cantor normal form.\n\n\\begin{Coqsrc}\nTheorem inject_of_zero : inject T1.zero = zero.\n\nTheorem inject_of_finite (n : nat):\n  inject (T1.fin n) =  n.\n\nTheorem inject_of_phi0 (alpha : T1):\n  inject (phi0 alpha) = AP.phi0 (inject alpha).\n\nTheorem inject_plus (alpha beta : T1): nf alpha -> nf beta ->\n  inject (alpha + beta)%t1 = inject alpha + inject beta.\n\nTheorem inject_mult_fin_r (alpha : T1)  :\n  nf alpha -> forall n:nat , inject (alpha *  n)%t1 =  inject alpha * n.\n\nTheorem inject_mono (beta gamma : T1) :\n  T1.lt  beta gamma -> \n  T1.nf beta -> T1.nf gamma -> \n  inject beta < inject gamma.\n\nTheorem inject_injective (beta gamma : T1) : nf beta -> nf gamma ->\n  inject beta = inject gamma -> beta = gamma.\n\\end{Coqsrc}\n\nFinally, we prove that \\texttt{inject} is a bijection from the set of all terms of \\texttt{T1} in normal form to the set \n\\texttt{members epsilon0} of the elements of \\texttt{Ord} strictly less than  $\\epsilon_0$.\n\n\\begin{Coqsrc}\nTheorem inject_lt_epsilon0 (alpha : T1):\n      inject alpha < epsilon0.\n\nTheorem embedding : \n     fun_bijection (nf: Ensemble T1)  (members epsilon0) inject.\n \\end{Coqsrc}\n\n\\subsection{Remarks}\nLet us recall that the library \\href{../theories/html/hydras.Schutte.Schutte.html}%\n{\\texttt{Schutte}} depends on five \\emph{axioms} and lies explicitly in the  \nframework of classical logic with a weak version of the axiom of choice\n(please look at the documentation of\n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Logic.ChoiceFacts.html}{\\texttt{Coq.Logic.ChoiceFacts}}).\nNevertheless, the other modules:\n\\href{../theories/html/hydras.Epsilon0.Epsilon0.html}%\n{\\texttt{Epsilon0}},\n\\href{../theories/html/hydras.Hydra.Hydra.html}%\n{\\texttt{Hydra}}, et \n\\href{../theories/html/hydras.Gamma0.Gamma0.html}%\n{\\texttt{Gamma0}}\ndo not import any axioms and are really constructive.\n\n\\index{Projects}\n\\begin{project}\nThere is no construction of ordinal multiplication in~\\cite{schutte}. \nIt would be interesting to derive this operation from Schütte's axioms,\nand prove its consistence with multiplication in ordinal notations for \n$\\epsilon_0$ and $\\Gamma_0$.\n\\end{project}\n\n\\section{Related Work}\n\nIn~\\cite{grimm:hal-00911710}, José Grimm establishes the consistency between our ordinal notations (\\texttt{T1} and \\texttt{T2} (Veblen normal form) and his implementation\nof ordinal numbers after Bourbaki's set theory.\n\n\n\\chapter{The Ordinal \\texorpdfstring{$\\Gamma_0$}{Gamma0} (first draft)}\n\n\n\\emph{This chapter and the files it presents are still very incomplete, considering the impressive properties of $\\Gamma_0$~\\cite{Gallier91}.  We hope to add new material soon, and accept contributions!}\n\n\n\\section{Introduction}\nWe present a notation system for the ordinal $\\Gamma_0$, following Chapter V, Section 14 of~\\cite{schutte}: ``A notation system for the ordinals $<\\Gamma_0$''.\nWe try to be as close as possible to Schütte's text and usual practices of \\coq{} developments.\n\nThe ordinal $\\Gamma_0$ is defined in Section 13 of ~\\cite{schutte} as the least \\emph{strongly critical ordinal}. It is widely known as the \\emph{Feferman-Schütte ordinal}.\n\n\nSection V, 13 of~\\cite{schutte} defines \\emph{strongly critical} and\n\\emph{maximal $\\alpha$-critical} ordinals: \n\n\\begin{itemize}\n\\item $\\alpha$ is strongly critical if\n$\\alpha$ is $\\alpha$-critical,\n\\item $\\gamma$ is maximal $\\alpha$-critical if $\\gamma$ is $\\alpha$-critical, and, for all $\\xi>\\alpha$, $\\gamma$ is not $\\xi$-critical.\n\n\\end{itemize}\n\n\n\n\n\n\\vspace{4pt}\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Schutte.Critical.html\\#strongly_critical}%\n{\\texttt{Schutte.Critical}}}\n\n\\begin{Coqsrc}\nDefinition strongly_critical alpha := In (Cr alpha) alpha.\n\nDefinition maximal_critical alpha : Ensemble Ord :=\n  fun gamma =>\n    In (Cr alpha) gamma /\\\n    forall xi, alpha < xi -> ~ In (Cr xi) gamma.\n\nDefinition Gamma0 := the_least strongly_critical.\n\\end{Coqsrc}\n\n\\index{Projects}\n\\begin{project}\nProve that a (countable)  ordinal $\\alpha$ is strongly critical iff \n$\\phi_\\alpha(0)=\\alpha$ (Theorem 13.13 of~\\cite{schutte} ). \n\\end{project}\n\n\n\\index{Projects}\n\\begin{project}\nProve that the set of strongly critical ordinals is unbounded and closed (Theorem 13.14 of~\\cite{schutte} ). Thus this set is not empty,  hence has a least element. Otherwise, the definition of $\\Gamma_0$ above would be useless.\n\\end{project}\n\n\n\n\nIn the present version of this development, we  only study $\\Gamma_0$ as a notation system, much more powerful than the ordinal notation for $\\epsilon_0$.\n\n%\\index{Projects}\n%\n%\\begin{project}\n% Schûtte's section 13 of~\\cite{schutte} contain several definitions and lemmas which give another view on $\\Gamma_0$.  We leave it as a project to implement them in \\coq{}.  \n%\\end{project}\n\n\n\n\n\\section{The Type \\texttt{T2} of Ordinal Terms}\n\nThe notation system for ordinals less than $\\gamma_0$ comes from the following theorem of~\\cite{schutte}, where $\\psi\\,\\alpha$ is the ordering function \nof the set of maximal $\\alpha$-critical ordinals.\n\n\n\\begin{quote}\n  Any ordinal $\\not= 0$ which is not strongly critical can be expressed in terms of $+$ and $\\psi$.\n\\end{quote}\n\n\\index{Projects}\n\\begin{project}\nThis theorem is not formally proved in this development yet. It should be!\n\\end{project}\n\n\nLike in Chapter~\\ref{chap:T1}, we define an inductive type with two constructors, one for $0$, the other for the construction $\\psi(\\alpha,\\beta)\\times(n+1)+\\gamma$, adapting a Manolios-Vroon-like notation~\\cite{Manolios2005} to\n\\emph{Veblen normal forms}.\n\\label{types:T2}\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Gamma0.T2.html\\#T2}%\n{\\texttt{Gamma0.T2}}}\n\\begin{Coqsrc}\n(**  [gcons alpha beta n gamma] is : [psi(alpha,beta)*(S n)+ gamma]  *)\n\nInductive T2 : Set :=\n| zero : T2\n| gcons : T2 -> T2  -> nat -> T2 -> T2.\n\nNotation \"[ alpha , beta ]\" := (gcons alpha beta 0 zero)\n                                 (at level 0): t2_scope.\n\\end{Coqsrc}\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=11cm]{epsilon0.jpg}\n  \\caption{Veblen normal form}\n  \\label{fig:gamma0}\n\\end{figure}\n\nLike in chapter~\\ref{chap:T1}, we get familiar with the type \\texttt{T2} by recognising simple constructs like finite ordinals, $\\omega$, etc., as inhabitants of \\texttt{T2}.\n\n\\begin{Coqsrc}\nNotation  \"'one'\"  := [zero,zero] : T2_scope.\n\n(** The (n+1)-th finite ordinal *)\nNotation \"'FS' n\" := (gcons zero zero n zero) (at level 10) : T2_scope.\n\n(** the [n]-th ordinal  *)\nDefinition fin (n:nat) := match n with 0 => zero | S p => FS p end.\n\nNotation \"'omega'\"  := [zero,one] : T2_scope.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nNotation \"'epsilon0'\"  := ([one,zero]) : T2_scope.\n\nDefinition epsilon alpha := [one, alpha].\n\\end{Coqsrc}\n\n\\section{How Big is \\texorpdfstring{$\\Gamma_0$}{\\texttt{Gamma0}}?}\n\nLet us define a strict order on type \\texttt{T2}. The following definition is \nan adaptation of Schütte's, taking into account the multiplications by a natural number (inspired by~\\cite{Manolios2005}, and also present in \\texttt{T1}).\n\n\\label{sect:t2-lt-def}\n\n\\begin{Coqsrc}\nInductive lt : T2 -> T2 -> Prop :=\n| (* 1 *) \n lt_1 : forall alpha beta n gamma,  zero t2< gcons alpha beta n gamma\n| (* 2 *)\n lt_2 : forall alpha1 alpha2 beta1 beta2 n1 n2 gamma1 gamma2, \n                alpha1 t2< alpha2 ->\n                beta1 t2< gcons alpha2 beta2 0 zero ->\n               gcons alpha1 beta1 n1 gamma1 t2<\n               gcons alpha2 beta2 n2 gamma2\n| (* 3 *)\n lt_3 : forall alpha1  beta1 beta2 n1 n2 gamma1 gamma2, \n               beta1 t2< beta2 ->\n               gcons alpha1 beta1 n1 gamma1 t2<\n               gcons alpha1 beta2 n2 gamma2\n\n| (* 4 *)\n lt_4 : forall alpha1 alpha2 beta1 beta2 n1 n2 gamma1 gamma2, \n               alpha2 t2< alpha1 ->\n               [alpha1, beta1] t2< beta2 ->\n               gcons alpha1 beta1 n1 gamma1 t2<\n               gcons alpha2 beta2 n2 gamma2\n\n| (* 5 *)\nlt_5 : forall alpha1 alpha2 beta1 n1 n2 gamma1 gamma2, \n               alpha2 t2< alpha1 ->\n               gcons alpha1 beta1 n1 gamma1 t2<\n               gcons alpha2  [alpha1, beta1] n2 gamma2\n\n| (* 6 *)\nlt_6 : forall alpha1 beta1  n1  n2 gamma1 gamma2,  (n1 < n2)%nat ->\n                                    gcons alpha1 beta1 n1 gamma1 t2< \n                                    gcons alpha1 beta1 n2 gamma2\n\n| (* 7 *)\n  lt_7 : forall alpha1 beta1 n1   gamma1 gamma2,  gamma1 t2< gamma2 ->\n                                      gcons alpha1 beta1 n1 gamma1 t2<\n                                      gcons alpha1 beta1 n1 gamma2\nwhere  \"o1 t2< o2\" := (lt o1 o2): T2_scope.\n\nHint Constructors lt : T2.\n\\end{Coqsrc}\n\nSeven constructors! In order to get accustomed with this definition, let us look at a small set of examples, covering all the constructors of \\texttt{lt}.\n\n\n\\subsection{Examples}\n\n\\subsubsection*{Proof of $0<\\epsilon_0$}\n\n\\begin{Coqsrc}\nExample Ex1: 0 t2< epsilon0.\nProof.  constructor 1. Qed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\omega<\\epsilon_0$}\n\n\\begin{Coqsrc}\nExample Ex2: omega t2< epsilon0.\nProof. info_auto with T2. (* uses lt_1 and lt_2 *) Qed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\psi(\\omega,8)\\times 13+56 < \\psi(\\omega,8)\\times 13+57 $}\n\n\\begin{Coqsrc}\nExample Ex3: gcons omega 8 12 56 t2<  gcons omega 8 12 57.\nProof.\n  constructor 7; constructor 6; auto with arith.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\epsilon_0<\\psi(2,1)$}\n\n\\begin{Coqsrc}\nExample Ex4: epsilon0 t2< [2,1].\nProof.\n   constructor 2; auto with T2.\n   - constructor 6; auto with arith.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\psi(2,1)<\\psi(2,3)$}\n\n\\begin{Coqsrc}\nExample Ex5 : [2,1] t2< [2,3].\nProof.\n  constructor 3; auto with T2.\n  - constructor 6; auto with arith.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\psi(1,0)\\times 13+ \\omega < \\psi(0,\\psi(2,1))$}\n\\label{sect:ex6-first-proof}\n\n\\begin{Coqsrc}\nExample Ex6 : gcons 1 0 12 omega t2< [0,[2,1]].\nProof.\n  constructor 4.\n  - constructor 1.\n  - constructor 2.\n    + constructor 6; auto with arith.\n    + constructor 1.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection*{Proof of $\\psi(2,1)\\times 43 + \\epsilon_0 < \\psi(1,\\psi(2,1))$}\n\n\\begin{Coqsrc}\nExample Ex7 : gcons 2 1 42 epsilon0 t2< [1, [2,1]].\nProof.\n constructor 5.\n constructor 6; auto with arith.\nQed.\n\\end{Coqsrc}\n\n\\index{Projects}\n\\begin{project}\nWrite a tactic that solves automatically goals of the form (\\texttt{$\\alpha$ t2< $\\beta$}), where $\\alpha$ and $\\beta$ are closed terms of type \\texttt{T2}.\n\\end{project}\n\n\\section{Veblen Normal Forms}\n\\begin{definition}\n  A term of the form $\\psi(\\alpha_1,\\beta_1)\\times n_1+ \\psi(\\alpha_2,\\beta_2)\\times n_2+\\dots+\\psi(\\alpha_k,\\beta_k)\\times n_k$ is said to be in\n \\emph{[Veblen] normal form} if for every $i<n$, $\\psi(\\alpha_i,\\beta_i)<\\psi(\\alpha_{i+1},\\beta_{i+1})$, all the $\\alpha_i$ and $\\beta_i$ are in normal form, and all the $n_i$ are strictly positive integers.\n\\end{definition}\n\n\\begin{Coqsrc}\nInductive nf : T2 -> Prop :=\n| zero_nf : nf zero\n| single_nf : forall a b n, nf a ->  nf b -> nf (gcons a b n zero)\n| gcons_nf : forall a b n a' b' n' c', \n                      [a', b'] t2< [a, b]  -> \n                      nf a -> nf b -> \n                      nf(gcons a' b' n' c')-> \n                      nf(gcons a b n (gcons a' b' n' c')).\n\\end{Coqsrc}\n\nLet us look at some positive examples (we have to prove some inversion lemmas before proving counter-examples).\n\n\n\\begin{Coqsrc}\nLemma  nf_fin i : nf (fin i).\nProof.\n  destruct i.\n  - auto with T2.\n  - constructor 2; auto with T2.\nQed.\n\nLemma nf_omega : nf omega.\nProof.  compute; auto with T2. Qed.\n\nLemma nf_epsilon0 : nf epsilon0.\nProof. constructor 2; auto with T2. Qed.\n\nLemma nf_epsilon : forall alpha, nf alpha -> nf (epsilon alpha).\nProof. compute; auto with T2. Qed.\n\nExample Ex8: nf (gcons 2 1 42 epsilon0).\nProof.\n  constructor 3; auto with T2.\n  - apply Ex4.\n  - apply nf_fin.\n  - apply nf_fin.\nQed.\n\\end{Coqsrc}\n\n\n\\subsection{Length of a Term}\n\nThe notion of \\emph{term length} is introduced by Schütte as a helper for proving (at least) the \\emph{trichotomy} property and transitivity of the strict order \\texttt{lt} on \\texttt{T2}. These properties are proved by induction on length.\n\n\\begin{Coqsrc}\nFixpoint nbterms (t:T2) : nat :=\n  match t with zero => 0\n             | gcons a b n v => (S n) + nbterms v\n  end.\n\nFixpoint t2_length (t:T2) : nat :=\n  match t  with \n    zero => 0\n  | gcons a b n v => \n       nbterms (gcons a b n v) + \n      2 * (Max.max (t2_length a)\n                              (Max.max (t2_length b) \n                                                (t2_length_aux v)))\n  end\nwith t2_length_aux (t:T2) : nat :=\n match t with \n | zero => 0\n  | gcons a b n v =>\n           Max.max (t2_length a) \n                            (Max.max (t2_length b) (t2_length_aux v))\n end.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nCompute t2_length (gcons 2 1 42 epsilon0).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 48 : nat\n\\end{Coqanswer}\n\n\\subsection{Trichotomy}\n\n\\emph{Trichotomy} is another name for the well-known property of decidable total ordering (like Standard Library's \\texttt{Compare\\_dec.lt\\_eq\\_lt\\_dec}).\n\nWe first prove by induction on $l$ the following lemma:\n\n\\vspace{4pt}\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Gamma0.Gamma0\\#tricho_aux}%\n{\\texttt{Gamma0.Gamma0}}}\n\n\\begin{Coqsrc}\nLemma tricho_aux (l: nat) : forall t t' :T2,\n      t2_length t + t2_length t' < l  ->\n      {t t2< t'} + {t = t'} + {t' t2<  t}.\n\\end{Coqsrc}\n\nThen we get our version of \\texttt{lt\\_eq\\_lt\\_dec}, and derive a comparison function;\n\n\\begin{Coqsrc}\nDefinition lt_eq_lt_dec (t t': T2) : {t t2< t'}+{t = t'}+{t' t2<  t}.\nProof.\n  eapply tricho_aux.\n  eapply lt_n_Sn.\nDefined.\n\nDefinition compare (t1 t2 : T2) : comparison := \n  match lt_eq_lt_dec t1 t2 with\n  | inleft (left _) => Lt\n  | inleft (right _) => Eq\n  | inright _ => Gt\n  end.\n\\end{Coqsrc}\n\nWith the help of \\texttt{compare}, we get a boolean version of \\texttt{nf}\n(being in Veblen normal form).\n\n\\begin{Coqsrc}\nFixpoint nfb (alpha : T2) : bool :=\n  match alpha with\n    zero => true\n  | gcons a b n zero => andb (nfb a) (nfb b)\n  | gcons a b n ((gcons a' b' n' c') as c) =>\n    match compare [a', b'] [a, b] with\n           Lt => andb (nfb a) (andb (nfb b) (nfb c))\n           | _ => false\n           end\nend.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nCompute compare (gcons 2 1 42 epsilon0) [2,2].\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = Lt\n     : comparison\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute nfb  (gcons 2 1 42 epsilon0).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = true\n     : bool\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute nfb (gcons 2 1 42 (gcons 2 2 4 epsilon0)).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = false\n     : bool\n\\end{Coqanswer}\n\n\\begin{remark}\nThe connexion between the predicate \\texttt{nf} and the relation \\texttt{lt} on one part, and the functions \\texttt{nfb} and \\texttt{compare} on the other, is expressed by the following lemmas:\n\n\\begin{Coqsrc}\nLemma nfb_equiv gamma : nfb gamma = true <-> nf gamma.\n\nLemma compare_correct alpha beta :\n  CompareSpec (alpha = beta) (lt alpha beta) (lt beta alpha)\n              (compare alpha beta).\n\\end{Coqsrc}\n\nThe function \\texttt{compare} helps to make easier proofs of inequalities of\nclosed terms of type \\texttt{T2}.\n\nFirst, we prove a lemma:\n\n\\begin{Coqsrc}\nLemma compare_Lt : forall alpha beta, compare alpha beta = Lt -> \n                                         alpha t2< beta.\nProof.\n  intros alpha beta; destruct (compare_correct alpha beta);\n    trivial; discriminate. \nQed.\n\\end{Coqsrc}\n\nThen, we give another version of the proof of Sect.~\\vref{sect:ex6-first-proof}.\n\n\\begin{Coqsrc}\nExample Ex6 : gcons 1 0 12 omega t2< [0,[2,1]].\nProof. now apply compare_Lt. Qed.\n\\end{Coqsrc}\n\n\\end{remark}\n\n\n\\section{Main Functions on \\texttt{T2}}\n\n\\subsection{Successor}\nThe successor function is defined by structural recursion.\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Gamma0.T2.html\\#succ}%\n{\\texttt{Gamma0.T2}}}\n\\begin{Coqsrc}\nFixpoint succ (a:T2) : T2 :=\n match a with zero => one\n             | gcons zero zero n c => fin (S (S n))\n             | gcons a b n c => gcons a b n (succ c)\n end.\n\\end{Coqsrc}\n\n\\subsection{Addition}\n\nLike for Cantor normal forms (see Sect.~\\ref{sect:infix-plus-T1}),  the definition of addition in \\texttt{T2}  requires comparison between ordinal terms.\n\n\n\\begin{Coqsrc}\nFixpoint plus (t1 t2 : T2) {struct t1}:T2 :=\n  match t1,t2 with\n  |  zero, y  => y\n  |  x, zero => x\n  |  gcons a b n c, gcons a' b' n' c' =>\n     (match compare (gcons a b 0 zero)\n                    (gcons a' b' 0 zero) with\n      | Lt => gcons a' b' n' c'\n      | Gt => gcons a b n (c + gcons a' b' n' c')\n      | Eq => gcons a b (S(n+n')) c'\n      end)\n  end\nwhere \"alpha + beta\" := (plus alpha beta): T2_scope.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nExample Ex7 : 3 + epsilon0 = epsilon0.\nProof. trivial. Qed.\n\\end{Coqsrc}\n\n\\subsection{The Veblen Function \\texorpdfstring{$\\phi$}{\\texttt{phi}}}\n\nThe enumeration function of critical ordinals, presented in Sect.~\\vref{sect:phi-schutte}, is recursively defined in type \\texttt{T2}.\n\n\\begin{Coqsrc}\nDefinition  phi (alpha beta : T2) : T2 :=\n  match beta with zero => [alpha, beta] \n             | [b1, b2] => \n               (match compare alpha b1\n                with Datatypes.Lt => [b1, b2 ]\n                | _ => [alpha,[b1, b2]]\n                end)\n             | gcons b1 b2 0 (gcons zero zero  n zero) => \n               (match compare alpha b1\n                with  Datatypes.Lt => \n                      [alpha, (gcons b1 b2 0 (fin n))]\n                | _ =>  [alpha, (gcons b1 b2 0 (fin (S n)))]\n                end)\n             | any_beta => [alpha, any_beta]\n  end.\n\\end{Coqsrc}\n\nDespite its complexity, the function \\texttt{phi} is well adapted to proofs by simplification or computation.\n\\begin{Coqsrc}\nExample Ex8:  phi 1 (succ epsilon0) = [1, [1,0] + 1].\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\n(**  All epsilons are fixpoints of phi 0 *)\n\nTheorem epsilon_fxp : forall beta, phi zero (epsilon beta) =\n                                   epsilon beta.\nProof. reflexivity. Qed.\n\nTheorem epsilon0_fxp : epsilon0 = phi zero epsilon0.\nProof. apply epsilon_fxp. Qed.\n\\end{Coqsrc}\n\n\nThe relation between the constructor $\\psi$ and the function $\\phi$ is\nstudied in~\\cite{schutte}, and partially implemented in this development.\n\\emph{Please contribute!}\n \nFor instance, the following theorem states that, if $\\gamma$ is the sum of a limit ordinal $\\beta$ and a finite ordinal $n$, and $\\beta$ is a fixpoint of\n$\\phi(\\alpha)$, then $\\psi(\\alpha,\\gamma)=\\phi_\\alpha(\\gamma+1)$.\n\n\\begin{Coqanswer}\nphi_psi :\nforall (alpha : T2) [beta gamma : T2] [n : nat],\nnf gamma ->\nlimit_plus_fin beta n gamma ->\nphi alpha beta = beta -> [alpha, gamma] = phi alpha (succ gamma)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nExample Ex9 : [zero, epsilon 2 + 4] = phi 0 (epsilon 2 + 5).\nProof. trivial. Qed.\n\\end{Coqsrc}\n\nOn the other hand, $\\phi$ can be expressed in terms of $\\psi$.\n\n\\begin{Coqanswer}\nphi_of_psi:\n  forall a b1 b2 : T2,\n  phi a [b1, b2] = (if lt_ge_dec a b1 then [b1, b2] else [a, [b1, b2]])\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nExample Ex10 : phi omega [epsilon0, 5] = [epsilon0, 5].\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\n\\index{Projects}\n\\begin{project}\nPlease study a way to pretty print ordinal terms in Veblen normal form (see Section~\\vref{sect:ppT1}).\n\\end{project}\n\n\\section{An Ordinal Notation for \\texorpdfstring{$\\Gamma_0$}{\\texttt{Gamma0}}}\n\nIn order to consider type \\texttt{T2} as an ordinal notation, we have to build an instance of class \\texttt{ON} (See Definition page~\\pageref{types:ON}).\n\nFirst, we define a type that contains only terms in Veblen normal form, and redefine \\texttt{lt} and \\texttt{compare} by delegation (see for comparison the construction of type \\texttt{E0} in Sect.~\\vref{sect:E0-def}).\n\n\\begin{Coqsrc}\nModule G0.\n\nClass G0 := mkg0 {vnf : T2; vnf_ok : nfb vnf}.\n\nDefinition lt (alpha beta : G0) := T2.lt (@vnf alpha) (@vnf beta).\n\nDefinition compare alpha beta := Gamma0.compare (@vnf alpha) (@vnf beta).\n\\end{Coqsrc}\n\nThen, we prove that \\texttt{lt} is a well-founded strict order and that the\nfunction \\texttt{compare} is correct.\n\n\\begin{Coqsrc}\nInstance lt_sto : StrictOrder lt.\n\nLemma lt_wf : well_founded lt.\n\nLemma compare_correct alpha beta :\n  CompareSpec (alpha = beta) (lt alpha beta) (lt beta alpha)\n              (compare alpha beta).\n\nInstance Gamma0: ON lt  compare.\nProof.\n  split.\n  - apply lt_sto.\n  - apply lt_wf. \n  - apply compare_correct.\nQed.\n\\end{Coqsrc}\n\n\n\\begin{remark}\nThe proof of \\texttt{lt\\_wf} has been written by \\'Evelyne Contejean, using her library on the recursive path ordering (see also remark~\\vref{remark:a3pat}).\n\\end{remark}\n\n\\index{Projects}\n\\begin{project}\nProve that \\texttt{Epsilon0} (page~\\pageref{instance-epsilon0})\nis a sub-notation system of \\texttt{Gamma0}.\n\nProve that the implemantations of \\texttt{succ}, \\texttt{+}, $\\phi_0$, etc.\nare compatible in both notation systems.\n\nNote that a function \\texttt{T1\\_inj} from \\texttt{T1} to \\texttt{T2} has already been defined. It may help to complete the task.\n\n\n\n\\noindent\\emph{From \\href{../theories/html/hydras.Gamma0.T2.html\\#T1_to_T2}%\n{\\texttt{Gamma0.T2}}}\n\\begin{Coqsrc}\n(* injection from T1 *)\n\nFixpoint T1_to_T2 (alpha :T1) : T2 :=\n  match alpha  with\n  | T1.zero => zero\n  | T1.ocons a n b => gcons zero (T1_to_T2 a) n (T1_to_T2 b)\n  end.\n\\end{Coqsrc}\n\n\\end{project}\n\n\\begin{project}\nProve that the notation system \\texttt{Gamma0} is a correct implementation \nof the segment $[0,\\Gamma_0)$ of the set of countable ordinals.\n\\end{project}\n\n\n\n\n\n\n", "meta": {"hexsha": "e9cfdda34f78b67cadd4b958814bb84d71dd18e1", "size": 323336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/part-hydras.tex", "max_stars_repo_name": "ybertot/hydra-battles", "max_stars_repo_head_hexsha": "597de4e718176bcf5eb8d3c97b060ddfe61b5367", "max_stars_repo_licenses": ["MIT"], "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/part-hydras.tex", "max_issues_repo_name": "ybertot/hydra-battles", "max_issues_repo_head_hexsha": "597de4e718176bcf5eb8d3c97b060ddfe61b5367", "max_issues_repo_licenses": ["MIT"], "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/part-hydras.tex", "max_forks_repo_name": "ybertot/hydra-battles", "max_forks_repo_head_hexsha": "597de4e718176bcf5eb8d3c97b060ddfe61b5367", "max_forks_repo_licenses": ["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.5680902498, "max_line_length": 534, "alphanum_fraction": 0.6811180939, "num_tokens": 103186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.78793120560257, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6347827382591877}}
{"text": "%!TEX root = paper.tex\n\nWe next moved on to develop a continuous erosion model that operates on smooth surfaces, in contrast to our previous discrete model that operated on piecewise linear surfaces. Physically this new model represents a surface being worn down gradually, such as a bar of soap in water or an ice cube melting. \n\n\\subsection*{Continuous Surface}\n\nWe will start by introducing a set of parametric equations to represent a surface. A parametric representation was chosen over an implicit one, so that we can use spectral methods and the FFT when integrating Equation \\ref{eq:erosion-diff-eq}, which we will discuss in detail in Section \\ref{sec:numerical-modeling}. \n\nLet us introduce $s \\in [0, 2\\pi)$ as our parameter with $s$ increasing counterclockwise along the surface. The coordinates of any point on the surface can be represented at time $t \\ge 0$ by two functions $x(t, s), y(t, s)$. Coordinates can be written more compactly as\n\n\\[ \n  \\bvec{r}(t, s) \\coloneqq \\paren{x(t, s), y(t, s)}\n\\]\n\n\\textbf{Note:} The reader should keep in mind that derivative operators still apply to each coordinate individually, e.g.\n\n\\[\n  \\frac{\\partial \\bvec{r}(t, s)}{\\partial t} \\coloneqq \\paren{\\frac{\\partial x(t, s)}{\\partial t}, \\frac{\\partial y(t, s)}{\\partial t}}\n\\]\n\nTo simplify our equations, we introduce the following vector calculus notation\n\n\\begin{align*}\n  \\dot{\\bvec{r}}(s)& \\coloneqq \\frac{\\partial \\bvec{r}(s)}{ds}\\\\\n  \\ddot{\\bvec{r}}(s)& \\coloneqq \\frac{\\partial^2 \\bvec{r}(s)}{ds^2}\n\\end{align*}\n\nThe equations for the initial shape that we will use in our simulations are shown below and a plot of the shape is shown in Figure \\ref{fig:blob-shape} ($T_i$ is the i\\textsuperscript{th} Chebyshev polynomial)\n\n\\begin{align*}\n  x(0, s) = \\cos(s) \\paren{2 T_0\\paren{\\frac{s-\\pi}{\\pi}} + T_2\\paren{\\frac{s-\\pi}{\\pi}}}\\\\\n  y(0, s) = \\sin(s) \\paren{2 T_0\\paren{\\frac{s-\\pi}{\\pi}} + T_4(\\paren{\\frac{s-\\pi}{\\pi}})}\n\\end{align*}\n\n\\begin{figure}[H]\n  \\begin{center}\n    \\includegraphics[keepaspectratio, width=4in]{blob_shape.pdf}\n  \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:blob-shape} Example shape.}\n\\end{figure}\n\nThe method used to represent the shape numerically will be explained in Section \\ref{sec:numerical-modeling}, but first we will take a moment to explain the various erosion processes that we will model in this section.\n\n\\subsection*{Continuous Erosion Processes}\n\nAll of the processes that we will look at in this section, will move points on the surface in the direction of the surface normal, which is defined as\n\n\\[\n  \\hat{n}(\\bvec{r}(s)) = (-\\dot{y}(s), \\dot{x}(s))\n\\]\n\nWe can now model our erosion process with the following differential equation, where $g(\\bvec{r}(s))$ is a function specific to the erosion process being modeled.\n\n\\begin{equation}\n  \\label{eq:erosion-diff-eq}\n  \\frac{\\partial \\bvec{r}(t, s)}{\\partial t} = g(\\bvec{r}(s)) \\; \\hat{n}(\\bvec{r}(s))\n\\end{equation}\n\n\\subsubsection*{Smoothing Process}\n\nOne of the processes that we will look at is a soap bar being worn down by a person holding it in their hand, which we will call the \\textit{Smoothing Process}. In this process, bumps on the object will get worn down quickest, because they are the first parts to come into contact with the person's hand. Technically the furthest protruding bumps will be worn down quickest, but to simplify the problem, we assume that every point on the surface wears down at a rate proportional to the curvature at the point. We will use a signed curvature $\\kappa$, so that a bump will have positive curvature, and an indentation will have negative curvature. \n\n\\[\n  \\kappa(\\bvec{r}(s)) = \\frac{\\dot{\\bvec{r}}(s) \\times \\ddot{\\bvec{r}}(s)}{\\norm{\\dot{\\bvec{r}}(s)}^3}\n\\]\n\nTo make bumps erode faster than indentations, we will use the following damping function\n\n\\begin{equation}\n  g(\\bvec{r}(s)) = \\tan^{-1}(\\beta \\, (\\kappa(\\bvec{r}(s)) - \\alpha)) + \\frac{\\pi}{2}\n\\end{equation}\n\nFor our simulations we chose $\\alpha = 1, \\; \\beta = 5$ so that $g(\\bvec{r}(s)) \\approx 1$ at the corners on our initial surface. This restriction is not based on the physics of the problem, and was chosen purely for the aesthetic look of the resulting simulation.\n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{g_1.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:g-1} Plot of $g(\\kappa)$ for \\textit{Smoothing Process}.}\n\\end{figure}\n\n\\subsubsection*{Bottom Recession Process}\n\nOur second process is an object sitting in a bath of acid, which we will call our \\textit{Bottom Recession Process}. In this process, the lowest points (smallest values of $y(s)$) on the surface will erode quickest.\n\n\\begin{gather}\n  f(s) = \\frac{1}{\\alpha \\, (y(s) - y_{min}) + \\beta} - \\gamma \\notag\\\\\n  g(s) = \\begin{cases}\n    f(s) \\qquad &\\text{for} \\quad f(s) > 0\\\\\n    0 \\qquad &\\text{otherwise}\n  \\end{cases}\n\\end{gather}\n\nFor our simulations we chose $\\alpha = 10, \\; \\beta = \\gamma = 0.1$ so that $g(\\bvec{r}(s)) \\approx 1$ for $y(s) \\approx y_{min}$.\n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{g_2.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:g-2} Plot of $g(y)$ for \\textit{Bottom Recession Process}.}\n\\end{figure}\n\n\n\\subsection*{Numerical Modeling}\\label{sec:numerical-modeling}\n\nWe chose to model the parametric surface functions $x, y$ with discrete Fourier series. This is because spectral methods using the DFT will maintain the smoothness of the surface much better than a local approximation of the surface using finite differences which only acts locally at points. The DFT and surface derivatives can be calculated quickly using the Fast Fourier Transform (refer to Appendix \\ref{sec:dft} for more details).\n\nTo integrate Equation \\ref{eq:erosion-diff-eq}, we sample the surface at parameter values $S_n = 2 \\pi \\, \\frac{n}{N} \\; , \\; n = 0, \\dotsc, N-1$, which gives us a matrix of initial evaluation points\n\n\\begin{align*} \n  X_0 =& \\bvec{r}\\paren{0, S}\\\\\n  =& \\begin{bmatrix}\n    x(0, S_1)& y(0, S_1)\\\\\n    \\vdots& \\vdots\\\\\n    x(0, S_N)& y(0, S_N)\\\\ \n  \\end{bmatrix}\n\\end{align*}\n\n\\textbf{Note:} When refering to vectors and matrices in our numerical models, we will use uppercase letters to distinguish them from continuous functions.\n\nForward time integration of Equation \\ref{eq:erosion-diff-eq} can then be implemented with standard ODE time stepping integration methods. In this paper, we used SciPy's {\\tt odeint} method for integrating Equation \\ref{eq:erosion-diff-eq}.\n\n\\subsection*{Point Collision Problems}\n\nUnfortunately, the simplicity gained from modeling the surface with a Fourier series is soon lost when we start time stepping. As can be seen in Figure \\ref{fig:remove-lowest-blob-bad}, the surface forms loops as time is increased (a physical impossibility).\n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{remove_lowest_blob_bad.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{Time integration of \\ref{eq:erosion-diff-eq} showing loop artifact.\\label{fig:remove-lowest-blob-bad}}\n\\end{figure}\n\nTo investigate why these loop artifacts occur, we will show a zoomed in portion of the same figure, with the evaluation points shown. \n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{remove_lowest_blob_bad_zoom.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{Expanded view of loop artifact.\\label{fig:remove-lowest-blog-bad-zoom}}\n\\end{figure}\n\nLooking closely, it can be seen that areas of high curvature form when evaluation points get close to each other, and this eventually leads to surface looping. Our guess is that this occurs because we are using discrete time stepping, so there are errors in the approximation of the shape's change with time. This is fine when the evaluation points are far from each other, but when they get close to each other, the errors become significant and affect the direction of the surface unit normal vectors. The folding causes unit normal vectors of nearby points to point at each other and which subsequently causes the points to cross over each other.\n\n\\subsection*{Redistributing Points}\n\nA seemingly obvious way to fix this problem would be to resample to get a set of evenly spaced evaluation points on the surface. This wouldn't be too difficult of a task, since we can integrate and sample at any point on the surface via the FFT. Unfortunately, if we pick points on the surface at arbitrary values of $s$, we lose spectral accuracy, because we are now sampling at unevenly spaced values of our parameter $s$, which we will call $\\tilde{S}$. The Discrete Fourier transform assumes that our points are sampled at evenly spaced values of $s$. Although we are working with the discrete Fourier transform, we need to return to the continuous equations to understand the problem. Redistribution in the continuous sense is a parameter transformation\n\n\\[ \n  \\tilde{s} = h(s)\n\\]\n\nwith the condition of even spacing being\n\n\\[\n  \\norm{\\frac{\\partial \\bvec{r}(s)}{\\partial \\tilde{s}}} = constant\n\\]\n\nOur shape function now becomes\n\n\\[ \\tilde{x}(s) = (x \\circ h)(s) \\]\n\nThere is absolutely no guarentee that the Fourier series of this composite function will decay at a reasonable rate, so using the DFT with our chosen resolution N could very poorly capture the surface shape. The method is not withough hope, since the technique of parameter transformation is utilized extensively in spectral methods such as the transformation $h(s) = \\cos(s)$ used for Chebyshev spectral methods to cluster evaluation points near the endpoints of the domain. We need to find a way to generate a parameter transformation $h(s)$ where $(x \\circ h)(s)$ has a rapidly decaying Fourier series.\n\n\\subsection*{Continuous Redistribution}\n\nIf we fix a time $t = t_1$, then we can define a differential equation that will allow us to redistribute the points and ensure that our redistributed points will still have a rapidly decaying Fourier series.\n\nPhysically $\\dot{\\bvec{r}}(t_1, s)$ is the surface tangent vector, and $\\ddot{\\bvec{r}}(t_1, s)$ is the rate of change of this surface tangent vector with respect to $s$. More importantly though, $\\norm{\\dot{\\bvec{r}}(t_1, s)}$ is inversely proportional to the density of evaluation points on the surface at $s$. We would like to shift the evaluation points away from denser areas, thus we need move the evaluation points in the direction of larger $\\norm{\\dot{\\bvec{r}}(t_1, s)}$, which is the projection of $\\ddot{\\bvec{r}}(t_1, s)$ onto the surface tangent vector.\n\n\\begin{equation}\n  a_t(t, s) = \\ddot{\\bvec{r}}(t, s) \\cdot \\dot{\\bvec{r}}(t, s)\n\\end{equation}\n\n\nWe can now set up a differential equation for this redistribution process.\n\n\\begin{equation}\n  \\label{eq:redist-diff-eq}\n  \\frac{\\partial \\bvec{r}(t_1, \\tilde{s}(t'))}{\\partial t'} = a_t(t_1, \\tilde{s}(t')) \\frac{\\dot{\\bvec{r}}(t_1, \\tilde{s}(t'))}{\\norm{\\dot{\\bvec{r}}(t_1, \\tilde{s}(t'))}} \\; , \\quad \\tilde{s}(0) = s\n\\end{equation}\n\nTo simplify the numerical computation, we can combine Equations \\ref{eq:erosion-diff-eq} and \\ref{eq:redist-diff-eq} to get a single ODE\n\n\\begin{equation}\n  \\frac{\\partial (\\bvec{r}(t, s))}{\\partial t} = g(t, s) \\; \\bhat{n}(t, s) + a_t(t, s) \\; \\frac{\\dot{\\bvec{r}}(t_1, s)}{\\norm{\\dot{\\bvec{r}}(t_1, s)}}\n\\end{equation}\n\nAs can be seen in Figure \\ref{fig:remove-points-blob-good}, this modification dramatically improves our algorithm.\n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{remove_points_blob_good.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:remove-points-blob-good}\\textit{Bottom recession process} simulation with point redistribution.}\n\\end{figure}\n\nIf we plot the evaluation points (Figure \\ref{fig:remove-points-blob-good-points}), it can be seen that the points nicely redistribute themselves as time increases to stay evenly spaced on the surface.\n\n\\begin{figure}[H]\n    \\begin{center}\n      \\includegraphics[keepaspectratio, width=4in]{remove_points_blob_good_points.pdf}\n    \\end{center}\n  \\vspace{-.2in} % corrects bad spacing\n  \\caption{\\label{fig:remove-points-blob-good-points}\\textit{Smoothing process} simulation with evaluation points shown.}\n\\end{figure}\n\n\\subsection*{Higher dimensions}\n\nA next logical step would be to generalize the algorithm to a 2-dimensional surface that would be parameterized by $s_1, s_2 \\in [0, 2\\pi)$. Much of the algorithm would be similar, except that we would need to use the 2-dimensional discrete Fourier transform (refer to Appendix \\ref{sec:dft}).\n\nThe surface normal vector equation for a surface in 3-dimensional space is the following\n\n\\[\n  \\bvec{n}(t, s_1, s_2) = \\frac{\\partial \\bvec{r}(t, s_1, s_2)}{\\partial s_1} \\times \\frac{\\partial \\bvec{r}(t, s_1, s_2)}{\\partial s_2} \n\\]\n\nCurvature $\\kappa$ could be generalized to mean curvature $H$\n\n\\begin{align*}\n  H(t, s_1, s_2)& = \\frac{\\nabla \\cdot \\bvec{n}(t, s_1, s_2)}{2}\\\\\n  &= \\frac{1}{2} \\paren{\\frac{\\partial \\bvec{n}_1(t, s_1, s_2)}{\\partial s_1} + \\frac{\\partial \\bvec{n}_2(t, s_1, s_2)}{\\partial s_2}}\n\\end{align*}\n\nAvoiding singularities when mapping the 2-dimensional surface to an N x N array would likely be difficult, but the mapping only needs to be used to sample the initial points on the object, and the redistribution algorithm can be oblivious to the mapping.\n\n", "meta": {"hexsha": "5ebbfc7f87547d7d5a81b56b2d6b39a5233ffbef", "size": 13513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/continuous_surface.tex", "max_stars_repo_name": "wangjohn/shape_of_stones", "max_stars_repo_head_hexsha": "c4d37ba76b93c12d31cf6efeac2f7ffdc8b64099", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-24T02:43:32.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-24T02:43:32.000Z", "max_issues_repo_path": "paper/continuous_surface.tex", "max_issues_repo_name": "wangjohn/shape_of_stones", "max_issues_repo_head_hexsha": "c4d37ba76b93c12d31cf6efeac2f7ffdc8b64099", "max_issues_repo_licenses": ["MIT"], "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/continuous_surface.tex", "max_forks_repo_name": "wangjohn/shape_of_stones", "max_forks_repo_head_hexsha": "c4d37ba76b93c12d31cf6efeac2f7ffdc8b64099", "max_forks_repo_licenses": ["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.9957081545, "max_line_length": 758, "alphanum_fraction": 0.7298897358, "num_tokens": 3853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6347827339124029}}
{"text": "%!TEX root = ../../report.tex\n\n\\subsubsection{Cellular Automaton} % (fold)\n\\label{ssub:cellular_automaton}\n\nIt's a model of a system of cells within a grid with a determined shape, each of this cells can be on one of a finite set of states. It evolves during a finite amount of time steps with a set of simple rules according with the state of the neighbouring cells.\nThe neighbourhood of the cell can be defined in many different ways, the most common is the use of the adjacent cells. \n\nIn the case where each cell have two possible states and the next generation state depends only on the previous state of the cell and the two immediate neighbors is called an \\emph{elementary cellular automaton}. In this case we have $2^3 = 8$ possible patterns for a neighborhood and $2^8 = 256$ sets of possible different rules. This rules are reffered by their \\emph{Wolfram code}, defined by Wolfram. \n\nA common initial state for yhis elementary cellular automata is a random line. But to able to compare the results between rules and get clean results other option is to start with a line with zeros except the middle cell with one. Applying this second option and the following set of rules (the rule 30):\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.85\\textwidth]{img/Theory/Cellular_A/Rules.png}\n\t\\caption{Example Production Rules\\cite{Shiffman2012}}\n\t\\label{fig:label}\n\\end{figure}\n\nwe get the pattern in the Figure~\\ref{fig:resultCA} that represents the evolution of this Cellular automaton over generations:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{img/Theory/Cellular_A/Result.png}\n    \\caption{Sierpiński Triangle, rule 90}\n    \\label{fig:resultCA}\n\\end{figure}\n\n\nIn Figure~\\ref{fig:resultCA} each line represents an iteration of the system with the application of the rules. With this set of rules a Sierpiński triangle is reproduced.\n\nCellular automata are used mainly to model phenomena that occurs in the physical world, most of them can only express the basic idea of a phenomenon but some are accurate enough to be able to make predictions.\n\nIn this context, cellular automata are used to model natural shapes and textures, the Figure~\\ref{fig:CAshell} shows a natural texture on a Textile Cone Snail that looks like the patterns formed with the cellular automaton in the Figure~\\ref{fig:CArule30}.\n\n\n\n\\begin{figure}\n        \\centering\n        \\begin{subfigure}[b]{0.6\\textwidth}\n                \\includegraphics[width=\\textwidth]{img/Theory/Cellular_A/shell.jpeg}\n                \\caption{a)}\n\t\t\t\t\\label{fig:CAshell}\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\n        \\begin{subfigure}[b]{0.9\\textwidth}\n                \\includegraphics[width=\\textwidth]{img/Theory/Cellular_A/Rule30.png}\n\t\t\t\t\\caption{b)}\n\t\t\t\t\\label{fig:CArule30}\n        \\end{subfigure}\n        \\caption{Example of the representation of natural patterns with cellular automata. a) Natural Shell, image from \\cite{Shiffman2012}. b) Pattern formed with the rule 30.}\n\t\t\\label{fig:CArule30shell}\n\\end{figure}\n\n\n% subsubsection cellular_automaton (end)", "meta": {"hexsha": "eb74da67b437d5af79a98c0c7e4938651479a1d0", "size": 3211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/overview/2-cellular_automaton.tex", "max_stars_repo_name": "arturalkaim/ProceduralGeneration", "max_stars_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_stars_repo_licenses": ["MIT"], "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/overview/2-cellular_automaton.tex", "max_issues_repo_name": "arturalkaim/ProceduralGeneration", "max_issues_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_issues_repo_licenses": ["MIT"], "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/overview/2-cellular_automaton.tex", "max_forks_repo_name": "arturalkaim/ProceduralGeneration", "max_forks_repo_head_hexsha": "736fcb8a15291ede1db069ad968527508bc081c4", "max_forks_repo_licenses": ["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.3620689655, "max_line_length": 405, "alphanum_fraction": 0.7461849891, "num_tokens": 825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6347827285642612}}
{"text": "\n\\subsection{Hard and soft classifiers}\n\nA hard classifier can return a sparce vector with \\(1\\) in the relevant classification.\n\nA soft classifier returns probabilities for each entry in the vector.\n\nThe vector represents  \\(P(Y=k|X=x)\\)\n\n\\subsection{Transforming soft classifiers into hard classifiers}\n\nWe can use a cutoff.\n\nIf there are more than two classes we can choose the one with the highest score.\n\n", "meta": {"hexsha": "437608ffbc1e2af712a8a39e10fafbbf220c5995", "size": 410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/02-04-hardSoft.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/02-04-hardSoft.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/02-04-hardSoft.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.625, "max_line_length": 87, "alphanum_fraction": 0.7756097561, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321889812552, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6347827258885675}}
{"text": "\\chapter{Classical Problems}\n\\section{Review of Basic Concept}\n\\begin{enumerate}\n\t\\item At the moment $t=0$ a stationary particle of mass $m$ experiences a time-dependent force $F=k t\\left(t^{\\prime}-t\\right)$, where $k$ is a constant vector, $t^{\\prime}$ is the time during which the given force acts. Find :\\\\\n\t(a) the momentum of the particle when the action of the force discontinued;\\\\\n\t(b) the distance covered by particle while the force acted.\n\t\\begin{answer}\n\t(a) Since $F=k t\\left(t^{\\prime}-t\\right)$, the direction of the force is fixed, as $k$ is a constant vector and the particle starts from rest, the motion will be in the direction of the force.\n\t\\begin{align*}\n\tm \\frac{d v}{d t}&=k t\\left(t^{\\prime}-t\\right),\\text{ from Newton's II law}\\\\\n\t\\text{Integrating, }\\int_{0}^{v} d v&=\\frac{k}{m} \\int_{0}^{t^{\\prime}} t\\left(t^{\\prime}-t\\right) d t=\\frac{k}{m}\\left[t^{\\prime} \\frac{t^{2}}{2}-\\frac{t^{3}}{3}\\right]_{0}^{t^{\\prime}} \\quad v=\\frac{k}{m} \\cdot \\frac{t^{\\prime 3}}{6}\\\\\n\\text{\tTherefore, momentum of the particle }p&=m v=k t \\frac{t^{\\prime 3}}{6}.\\\\\n\\text{(b) }d s=v d t \\Rightarrow s&=\\int_{0}^{s} d s=\\int_{0}^{t^{\\prime}} v d t=\\frac{k t^{\\prime 4}}{12 m}\n\t\\end{align*}\n\t\t\\end{answer}\n\t\\item A block of mass $m_{1}=4 \\mathrm{~kg}$ on a smooth inclined plane of $30^{\\circ}$ is connected by a cord over a small, frictionless pulley to a second block of mass $m_{2}=5 \\mathrm{~kg}$ hanging vertically. Calculate the acceleration with which the block moves and also the tension in the cord. Take $g=10 \\mathrm{~m} / \\mathrm{sec}^{2}$.\n\t\\begin{answer}\n\t\t\tThe different forces acting on the masses are shown in figure.\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[height=3.5cm,width=6cm]{diagram-20220216-crop}\n\t\t\t\\end{figure}\n\t\t\\begin{align}\n\\text{We have }T-m_{1} g \\sin \\theta&=m_{1} a \\label{1} \\\\\n\\text{ and }m_{2} g-T&=m_{2} a \\label{2}\\\\\n\\intertext{Solving equations (\\ref{1}) and (\\ref{2}), we get}\na&=\\frac{\\left(m_{2}-m_{1} \\sin \\theta\\right) g}{\\left(m_{1}+m_{2}\\right)}\\label{3}\\\\\n\\text { and } \\quad T & =m_{2} g\\left[1-\\frac{\\left(m_{2}-m_{1} \\sin \\theta\\right)}{\\left(m_{1}+m_{2}\\right)}\\right] \\notag\\\\\n \\text { or } \\quad T & =\\frac{m_{1} m_{2}(1+\\sin \\theta) g}{\\left(m_{1}+m_{2}\\right)}\\\\\n \\text{Here }m_{1}&=4 \\mathrm{~kg}, m_{2}=5 \\mathrm{~kg}, \\theta=30^{\\circ} \\text{and }g=10 \\mathrm{~m} / \\mathrm{s}\\notag\\\\\n  \\intertext{Substituting these values in equation (\\ref{3}), we get}\n T&=\\frac{5 \\times 4\\left(1+\\frac{1}{2}\\right) 10}{9}=\\frac{300}{9}=33.33 \\mathrm{~N}\\notag\n\\end{align}\n\t\\end{answer}\n\t\\item A particle of mass $m$ is connected to two springs of unstretched length ' $l$ ' and spring constant $k$ as show in figure. Calculate acceleration of particle if it is slightly displaced along X-direction.\n\t\\begin{answer}\n\t\t\tLet the particle is displaced by a distance $x$ along $+x$ direction as shown in figure.\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[height=4.5cm,width=2cm]{diagram-20220216(1)-crop}\n\t\t\t\\end{figure}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=2cm]{diagram-20220216(2)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\\text{\tTherefore, stretched length of spring }&=\\sqrt{l^{2}+x^{2}}\\\\\n\t\t\\text{elongation in springs }&=\\sqrt{l^{2}+x^{2}}-l\\\\\n\t\\text{\tRestoring force on the particle due to each spring} F&=k\\left(\\sqrt{l^{2}+x^{2}}-l\\right)\n\t\\intertext{ Because of restoring force the particle moves back towards its initial position.}\n\\text{\tEquation of motion of particle }F_{x}&=m \\frac{d^{2} x}{d t^{2}}\\\\\n\t\\text{or }-2 F \\cos \\theta&=m \\frac{d^{2} x}{d t^{2}}\\text{ or }-2 k\\left(\\sqrt{l^{2}+x^{2}}-l\\right) \\cdot \\frac{x}{\\sqrt{l^{2}+x^{2}}}=m \\frac{d^{2} x}{d t^{2}}\\\\\n\t\\text{Therefore, }\\frac{d^{2} x}{d t^{2}}&=-\\frac{2 k x}{m}\\left(1-\\frac{l}{\\sqrt{l^{2}+x^{2}}}\\right)\\text{ or }\\frac{d^{2} x}{d t^{2}}\\\\&=-\\frac{2 k x}{m}\\left[1-\\left(1+\\frac{x^{2}}{l^{2}}\\right)^{-1 / 2}\\right]\\\\\n\\text{\tSince, }&x<l,\\left(1+\\frac{x^{2}}{l^{2}}\\right)^{-1 / 2} \\approx 1-\\frac{x^{2}}{2 l^{2}}\\\\\n\\text{\tTherefore, }\\frac{d^{2} x}{d t^{2}}&=-\\frac{2 k x}{m}\\left[1-\\left(1-\\frac{x^{2}}{2 l^{2}}\\right)\\right]\\text{ or }\\frac{d^{2} x}{d t^{2}}=-\\frac{k x^{3}}{m l^{2}}\n\t\t\\end{align*}\n\t\\end{answer}\n\\item At the moment $t=0$, the force $F=k t$ is applied to a small body of mass $m$ resting on smooth horizontal plane $(k=$ constant). The permanent direction of this force forms an angle $\\theta$ with the horizontal (figure below). Find\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=10cm]{diagram-20220217-crop}\n\\end{figure}\n(a) the velocity of the body at the moment of its breaking off the plane;\\\\\n(b) the distance traversed by the body up to this moment.\n\n\\begin{answer}\n\t\tThe free body diagram is shown in figure.\n\t\\begin{align*}\n\t\\text{From figure: }R+F \\sin \\theta&=m g\\\\\n\t\\text{At breaking off, }R&=0, \\therefore F=\\frac{m g}{\\sin \\theta}\\\\\n\\text{\tNow }k t&=\\frac{m g}{\\sin \\theta}\\text{ or }t=\\frac{m g}{k \\sin \\theta}\n\\intertext{\t(a) If $a$ be the acceleration, then $F \\cos \\theta=m a$ }\n\\text{\tTherefore, }k t \\cos \\theta&=m \\times\\left(\\frac{d v}{d t}\\right) \\quad\\left(\\because a=\\frac{d v}{d t}\\right) .\n\\intertext{Integrating this expression within proper limits, we get $m \\int_{0}^{v} d v=k \\cos \\theta \\int_{0}^{m g / k \\sin \\theta} t d t$}\n\\text{ or }\\quad m v&=\\frac{k \\cos \\theta}{2}\\left[\\frac{m g}{k \\sin \\theta}\\right]^{2}\\text{ or }v=\\frac{m g^{2}}{2 k}\\left(\\frac{\\cos \\theta}{\\sin ^{2} \\theta}\\right)\\\\\n\\text{(b) Without putting the limits, we have }v&=\\frac{k \\cos \\theta}{2 m} t^{2}+C,\\text{ where $C=$ constant of integration.}\\\\\n\\text{When }t&=0, v=0\\text{ and hence }C=0.\\\\\n\\text{Now, }\\frac{d s}{d t}&=\\frac{k \\cos \\theta}{2 m} t^{2} \\int_{0}^{s} d s=\\frac{k \\cos \\theta}{2 m} \\int_{0}^{m g / k \\sin \\theta} t^{2} d t\\\\\ns&=\\frac{k \\cos \\theta}{2 m}\\left[\\frac{t^{3}}{3}\\right]_{0}^{m g / k \\sin \\theta} \\quad\\text{ or }s=\\frac{m^{2} g^{3} \\cos \\theta}{6 k^{2} \\sin ^{3} \\theta} .\n\t\\end{align*}\n\\end{answer}\n\\item Spherical particles of a given material of density $\\rho$ are released from rest inside a liquid medium of lower density. The viscous drag force may be approximated by the Stoke's law, i.e, $F_{d}=6 \\pi \\eta R \\mathrm{v}$, where $\\eta$ is the viscosity of the medium, $R$ the radius of a particle and $v$ its instantaneous velocity. If $\\tau(m)$ is the time taken by a particle of mass $m$ to reach half its terminal velocity, then the ratio $\\tau(8 m) / \\tau(m)$ is\n\\begin{answer}\n\t Each particle has same density but different radii and masses. We have to calculate time of fall in terms of mass of particle therefore we will write our equations explicitly in terms of mass and we will remove radius from our equations wherever it appears.\\\\Drag force on particles\n\t \\begin{align}\n\t F_{d}&=6 \\pi \\eta R \\mathrm{v}, \\quad\\text{ Mass of a particle }m=\\rho \\cdot \\frac{4}{3} \\pi R^{3}\\notag\\\\\n\t \\therefore R&=\\left(\\frac{3 m}{4 \\pi \\rho}\\right)^{1 / 3} \\quad \\therefore F_{d}\\notag\\\\&=6 \\pi \\eta\\left(\\frac{3 m}{4 \\pi \\rho}\\right)^{1 / 3} v=K m^{1 / 3} v\\text{, where }K=6 \\pi \\eta\\left(\\frac{3}{4 \\pi \\rho}\\right)^{1 / 3}\\notag\\\\\n\t\\intertext{ If $\\mathrm{B}$ is buoyancy force, then equation of motion of a particle is}\\notag\\\\\n\t m \\frac{d v}{d t}&=m g-F_{d}-B\\text{ where }\\mathrm{B}=\\frac{4}{3} \\pi R^{3} \\sigma g\\notag\\\\&=\\frac{4}{3} \\pi R^{3} \\rho g \\cdot \\frac{\\sigma}{\\rho}=m g \\frac{\\sigma}{\\rho}, \\sigma=\\text{ density of medium}\\notag\\\\\n\t \\therefore m \\frac{d v}{d t}&=m g-K m^{1 / 3} v-m g \\frac{\\sigma}{\\rho}, m \\frac{d v}{d t}=m g\\left(1-\\frac{\\sigma}{\\rho}\\right)-K m^{1 / 3} v \\notag\\\\\n\t \\text { or } \\frac{d v}{d t}&=g\\left(1-\\frac{\\sigma}{\\rho}\\right)-K m^{-2 / 3} v\\label{5}\\\\\n\t \\text{when terminal }&\\text{velocity is reached }\\frac{d v}{d t}=0\\notag\\\\\n\t \\therefore 0&=g\\left(1-\\frac{\\sigma}{\\rho}\\right)-K m^{-2 / 3} v_{t} \\quad \\therefore v_{t}=\\frac{g\\left(1-\\frac{\\sigma}{\\rho}\\right)}{K m^{-2 / 3}}\\label{6}\\\\\n\t\\intertext{ Now, if $\\tau$ be the time to reach half the terminal velocity then from (\\ref{5})}\\notag\\\\\n\t \\int_{0}^{1 / 2} \\frac{d v}{g\\left(1-\\frac{\\sigma}{\\rho}\\right)-K m^{-2 / 3} v}&=\\int_{0}^{\\tau} d t, \\quad \\therefore-\\frac{1}{K m^{-2 / 3}} \\ln \\left[\\frac{g\\left(1-\\frac{\\sigma}{\\rho}\\right)-\\frac{K m^{-2 / 3} v_{t}}{2}}{g\\left(1-\\frac{\\sigma}{\\rho}\\right)}\\right]=\\tau\\notag\\\\\n\t \\text{using value of $v_{t}$ from (\\ref{6}) we get, }\\tau&=\\frac{m^{2 / 3}}{K} \\ln 2 \\quad\\text{ or }\\quad \\tau(m)=\\frac{m^{2 / 3} \\ln 2}{K}\\notag\\\\\n\t  \\therefore \\tau(8 m) / \\tau(m)&=(8 m)^{2 / 3} / m^{2 / 3}=4\\notag\n\t \\end{align}\n\\end{answer}\n\\item A particle of unit mass is thrown vertically upward with initial speed $v_{0}$. It is acted upon by a drag force $b v^{2}$ in addition to gravity where $b$ is constant and $v$ is instantaneous velocity of particle. Calculate speed of the particle when it returns to the point from where it was thrown.\n\\begin{answer}\n\tIn presence of drag force only quantity that is common in upward and downward motion is the distance covered.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=7cm]{c prb01}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\text{For upward motion, initial speed }&=v_{0},\\\\\n\t \\text{final speed }&=0,\\text{ let height reached $=h$}\\\\\n\t \\text{ equation of motion }\\frac{d v}{d t}&=-g-b v^{2}\\\\\n\t\\text{or }\\frac{d v}{d y} \\cdot \\frac{d y}{d t}&=-g-b v^{3}, \\frac{d y}{d t}=v\\text{ or }\\frac{v d v}{g+b v^{2}}=-d y\\\\\n\t\\therefore \\int_{v}^{0} \\frac{v d v}{g+b v^{2}}&=-\\int_{0}^{h} d y\\\\\n\\text{\ton integration we get, }\\frac{1}{2 b} \\ln \\left(\\frac{g+b v_{0}^{2}}{g}\\right)&=h\\\\\n\\text{for downward motion, initial speed }&=0,\\text{ final speed $=v($ let $)$, height descended $=h$ }\\\\\n\\text{equation of motion }\\frac{d v}{d t}&=g-b v^{2}\\text{ or }\\frac{v d v}{g-b v^{2}}=d y\\text{ or }\\int_{0}^{v} \\frac{v d v}{g-b v^{2}}=\\int_{0}^{h} d y\\\\\n\\text{on integration we get, }\\frac{1}{2 b} \\ln \\left(\\frac{g}{g-b v^{2}}\\right)&=h\\\\\n\\text{Comparing (a) and (b) we get, }\\frac{g+b v_{0}^{2}}{g}&=\\frac{g}{g-b v^{2}}, \\quad g-b v^{2}=\\frac{g^{2}}{g+b v_{0}^{2}}\\\\\n\\text{or }v&=\\frac{v_{0}}{\\sqrt{1+\\frac{b v_{0}^{2}}{g}}} \\Rightarrow v<v_{0}\n\t\\end{align*}\n\tdue to drag force the particle returns with a speed less than its initial speed. If drag force were absent $b=0$, then $v=v_{0} .$ Therefore in absence of drag force particle returns with same speed as its initial value.\n\\end{answer}\n\\item A small ring of mass $m$ can slide on a smooth circular wire of radius $r$ and center $O$, which is fixed in a vertical plane. From a point on the wire at a vertical distance $r / 2$ above $O$, the ring is given a velocity $\\sqrt{(g r) }\\text { along the downward tangent to the wire. Show that it will just reach the highest point of the wire. }$ Find the reaction between the ring and the wire when the ring is at a vertical distance $r / 2$ below.\n\\begin{answer}\n\t\\begin{align}\n\\text{At point $C$, the velocity of the ring }&=\\sqrt{(r g)}.\\notag\\\\\n\\text{K.E. at }C&=\\frac{1}{2} m v^{2}=\\frac{1}{2} m r g\\text{ and P.E. at }C\\notag\\\\&=m g h=m g(A F)=m g(r+r / 2)=\\frac{3 m g r}{2}.\\notag\\\\\n\\text{Total energy }&=m g r\\left[\\frac{1}{2}+\\frac{3}{2}\\right]=2 m g r.\\label{7}\n\t\\end{align}\n\tIf the ring has to reach at $D$, with kinetic energy zero, its potential energy $=m g(2 r)$.\n\tBecuase the particle at $C$ has this amount of energy and it will just reach at $D$ with zero velocity.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.8cm,width=4.5cm]{diagram-20220217(1)-crop}\n\t\\end{figure}\n\tNow consider the ring at $B$, a distance $r / 2$ below $O$. Resolving $m g$ in two parts and considering the equilibrium, we get\n\t\\begin{align}\n\tN-m g \\cos \\theta&=\\frac{m v_{1}^{2}}{r}\\notag\\\\\n\tN&=\\frac{m v_{1}^{2}}{r}+m g \\cos \\theta\\label{8}\n\t\\intertext{Falling from $C$, i.e., through a distance $r$, the ring has lost a potential energy $m g r .$ This is the gain in kinetic energy.}\n\\text{\tHence, }\\frac{1}{2} m v_{1}^{2}&=\\frac{1}{2} m g r+m g r=\\frac{3}{2} m g r \\text{or }v_{1}^{2}=3 g r\\text{ or }\\frac{v_{1}^{2}}{r}=3 g.\\notag\\\\\n\\text{ Fromequation (\\ref{8}),} N&=m\\left(3 g+g \\times \\frac{1}{2}\\right)\n\t\\left(\\because \\cos \\theta=\\frac{1}{2}\\right)\\notag\\\\\\text{ or}& N=\\left(\\frac{7}{2}\\right) \\mathrm{mg}=3.5 \\mathrm{mg}.\\notag\n\t\\end{align}\n\\end{answer}\n\\item A $2.0 \\mathrm{~kg}$ block of mass, initially at rest, is dropped from a height of $0.40$ meter onto a spring whose force constant is $1960 \\mathrm{nt} /$ meter. Find the maximum distance that the spring will be compressed.\n\\begin{answer}\n\tThe situation is shown in figure. Let $m$ be the mass of the block and $k$ be the force constant of the spring.Let $l$ be the distance through which the spring is compressed. The total vertical fall of the block is $(h+l)$. Loss of the gravitational potential energy of the block $=m g(h+l)$.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=2.5cm]{diagram-20220217(2)-crop}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\text{Elastic potential energy }&\\text{in the spring }=\\left(\\frac{1}{2}\\right) k t^{2}.\n\\intertext{\tBy the law of conservation of energy}\n\tm g(h+l)&=\\frac{1}{2} k t^{2} \\text { or } \\frac{2 m g h}{k}+\\frac{2 m g}{k} l=l^{2} \\text { or } l^{2}-\\frac{2 m g}{k} l-\\frac{2 m g h}{k}=0\\\\\n\t\\therefore \\quad l&=\\frac{\\left(\\frac{2 m g}{k}\\right) \\pm \\sqrt{\\left[\\left(\\frac{2 m g}{k}\\right)^{2}+\\left(\\frac{8 m g h}{k}\\right)\\right]}}{2}\\\\\n\t\\text{According to given problem, }m&=2 \\mathrm{~kg}, h=0.40 \\mathrm{~m} \\text{and $k=1960$ newton/meter. Hence,}\\\\\n\tl&=\\frac{(2 \\times 2 \\times 9.8 / 1960) \\pm \\sqrt{(2 \\times 2 \\times 9.8 / 1960)^{2}+(8 \\times 2 \\times 9.8 \\times 0.40 / 1960)}}{2} \\\\\n\tl&=\\mathbf{0 . 1} \\text { meter. }\n\t\\end{align*}\n\\end{answer}\n\\item A particle of mass $3 \\mathrm{~kg}$ is moving under the action of a central force whose potential energy is given by $U(r)=10 r^{3}$ joule. For what energy and angular momentum will the orbit be a circle of radius $10 \\mathrm{~m}$ ? Calculate the time period of this motion.\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Given that }U(r)&=10 r^{3}.\n\t\\intertext{So the force $F$ acting on the particle is given by}\n\tF&=\\frac{\\partial U}{\\partial r}=-\\frac{\\partial}{\\partial r}\\left(10 r^{3}\\right)=-10 \\times 3 r^{2}=-30 r^{2}\\\\\n\t\\text{For circular motion of the particle }F&=\\frac{m v^{2}}{r}=30 r^{2}.\\\\\n\t\\text{Substituting the given values, we have }\\frac{3 \\times v^{2}}{10}&=30 \\times(10)^{2}\\text{ or }v=100 \\mathrm{~m} / \\mathrm{s}.\\\\\n\t\\text{The total energy in circular motion}\n\tE&=\\text{ K.E. }+\\text{ P.E. }=\\frac{1}{2} m v^{2}+U(r)\\\\&=\\frac{1}{2} \\times 3 \\times(100)^{2}+10 \\times(10)^{3}=2.5 \\times 10^{4}\\text{ joule}\\\\\n\t\\text{Angular momentum }&=m v r=3 \\times 100 \\times 10=3000 \\mathrm{~kg}-\\mathrm{m}^{2} / \\mathrm{sec}\\\\\n\t\\text{Time period }T&=\\frac{2 \\pi r}{v}=\\frac{2 \\times \\pi \\times 10}{100}=\\frac{\\pi}{5} \\mathrm{sec} .\n\t\\end{align*}\n\\end{answer}\n\\item In figure, $A B C D E$ is a channel in the vertical plane, part $B C D E$ being circular with radius $r$. A ball is released from $A$ and slides without friction and without rolling. Show that it will complete the loop path if $h$ is greater than $5 r / 2$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{diagram-20220217(3)-crop}\n\\end{figure}\n\\begin{answer}\n\t\\begin{align}\n\\intertext{\tLet $m$ be the mass of the ball. When the ball comes down to $B$, its loses its potential energy $m g h$ which is converted into kinetic energy. Let $v_{B}$, be the velocity of the ball at $B$. Then,}\\notag\\\\\n\tm g h&=\\frac{1}{2} m v_{B}^{2}\n\\intertext{\tThe ball now rises to a point $D$, where its potential energy is $m g(h-2 r) .$ If $v_{D}$ be the velocity of the ball at $D$, then}\\notag\\\\\n\tm g(h-2 r)&=\\frac{1}{2} m v_{D}^{2}\\label{09}\n\\intertext{\tNow to complete the circular path, it is necessary that the centripetal force acting upward at point $D$ should be equal or greater than the force $m g$ acting downward. Therefore,}\\notag\\\\\n\t\\frac{m v_{D}^{2}}{r} \\geq m g&\\text{ or }v_{D}^{2} \\geq r g\\\\\n\\text{\tFromequation (\\ref{09}) }v_{D}^{2}&=2 g(h-2 r)\\notag\\\\\n\t\\therefore \\quad 2 g(h-2 r) \\geq &r g, h \\geq \\frac{5}{2} r .\\notag\n\t\\end{align}\n\\end{answer}\n\\item A moving particle of mass $m$ collides head-on with a particle of mass $2 m$ which is initially at rest. Show that the particle $m$ will loose $8 / 9$ th part of its initial kinetic energy after the collision.\n\\begin{answer}\n\tLet $u_{1}$ be the initial velocity of mass $m$ before collision and $v_{1}$ and $v_{2}$ the velocities of masses $m$ and $2 m$ after collision respectively.\\\\\n\tAccording to the law of conservation of kinetic energy, we have\n\t\\begin{align}\n \\frac{1}{2} m u_{1}^{2}&=\\frac{1}{2} m v_{1}^{2}+\\frac{1}{2}(2 m) v_{2}^{2}\\notag \\\\ \\text { or } & u_{1}^{2}-v_{1}^{2}=2 v_{2}^{2} \\notag\\\\ \\text { or } & \\left(u_{1}-v_{1}\\right)\\left(u_{1}+v_{1}\\right)=2 v_{2}^{2}\\label{10}\n\\intertext{ By the law of conservation of momentum, we have}\\notag\n m u_{1}&=m v_{1}+(2 m) v_{2} \\notag\\\\\n \\left(u_{1}-v_{1}\\right)&=2 v_{2}\\label{11}\\\\\n\\text{ From eqs. (\\ref{10}) and (\\ref{11}), we get }\\left(u_{1}+v_{1}\\right)&=v_{2}\\label{12}\n\\intertext{ Substituting the value of $v_{2}$ from eq. (\\ref{12}) in eq. (\\ref{11}), we get}\\notag\\\\\nu_{1}-v_{1}=2\\left(u_{1}+v_{1}\\right) \\text { or }-3 v_{1}&=u_{1} \\text { or } v_{1}=-\\left(\\frac{1}{3}\\right) u_{1}\\label{13}\n\\intertext{Now the initial and final kinetic energies of mass $m$ are}\nK_{i}=\\left(\\frac{1}{2}\\right) m u_{1}^{2} \\text { and } K_{f}&=\\left(\\frac{1}{2}\\right) m v_{1}^{2}=\\left(\\frac{1}{2}\\right) m\\left(\\frac{u_{1}^{2}}{9}\\right)\\notag\\\\\n\\text{Therefore, fraction loss }&=\\frac{K_{i}-K_{f}}{K_{i}}=\\frac{\\frac{1}{2} m u_{1}^{2}\\left(1-\\frac{1}{9}\\right)}{\\frac{1}{2} m u_{1}^{2}}=\\frac{8}{9}\\notag\n\t\\end{align}\n\\end{answer}\n\\item A solid hemisphere of mass $M$ and radius $R$ is placed against a smooth wall as shown in the figure. what is normal reaction on the sphere due to the wall.\n\\begin{answer}\n\tCentre of mass of the hemisphere lies at a distance $\\frac{3 R}{8}$ from\n\tits base centre. The sphere is in equilibrium therefore torque about point A must be zero.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.2cm,width=9cm]{diagram-20220217(4)-crop}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\therefore N R-M g \\cdot \\frac{3 R}{8}&=0\\\\\n\t\\text{or, }N&=\\frac{3 M g}{8}\n\t\\end{align*}\n\\end{answer}\n\\item A thin rod of mass $M$ and length $L$ is suspended from one end while its other end lies on a smooth horizontal plane and makes an angle $\\alpha$ with the plane. Find the normal reaction from the plane and tension in the string from which it is suspended.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3cm,width=5cm]{diagram-20220217(5)-crop}\n\\end{figure}\n\\begin{align}\n\\text{For translational equilibrium }T+N&=M g \\label{14}\\\\\n\\text{For rotational }&\\text{equilibrium }\\notag\\\\\n\\text{Torque about lower}&\\text{ end of the rod is zero}\\notag\\\\\n\t\\therefore T . L \\cos \\alpha-M g \\frac{L}{2} \\cos \\alpha&=0 \\quad \\therefore \\quad T=\\frac{M g}{2}\\notag\\\\\n\t\\text{from (\\ref{14}) }N&=M g-T=M g-\\frac{M g}{2}=\\frac{M g}{2}\\notag\n\\end{align}\nExample: A uniform ladder of length 2L and mass 'm' leans against a wall in a vertical plane at an angle $\\theta$ to the horizontal. The floor is rough, having a coefficient of static friction $\\mu$\nA person of mass $M$ stands on the ladder at a distance $D$ from its base (see figure). If the wall is frictionless, the maximum distance $\\left(D_{\\max }\\right)$ up the ladder that the person can reach before the ladder slips is\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=4cm]{diagram-20220217(6)-crop}\n\\end{figure}\n\\begin{answer}\n\tLet us take ladder plus person as system. Various forces acting on the system are shown in the figure. For translational equilibrium we must have\n\t\\begin{align}\n\tN_{1}&=(M+m) g\\label{15}\\\\\n\tN_{2}&=f_{r}\\label{16}\\\\\n\t\\intertext{\tFor rotational equilibrium torque about lower end of the ladder must be zero. Therefore,}\\notag\\\\\n\tM g D \\cos \\theta+m g L \\cos \\theta-N_{2} .2 L \\sin \\theta&=0\\notag\\\\\n\t\\therefore N_{2}&=\\frac{g \\cot \\theta}{2}\\left[\\frac{M D}{L}+m\\right]\\notag\\\\\n\t\\therefore\\text{ from (\\ref{16}) we get, }f_{r}&=\\frac{g \\cot \\theta}{2}\\left[\\frac{D}{L} M+m\\right]\\notag\\\\\n\t\\text{since }f_{r} \\leq \\mu N_{1}, \\quad &\\therefore \\frac{g \\cot \\theta}{2}\\left[\\frac{D}{L} M+m\\right] \\leq \\mu(M+m) g\\notag\\\\\n\\text{\tor }D \\leq \\frac{L}{M}[2 \\mu(M+m) \\tan \\theta-m] \\quad &\\therefore D_{\\max }=L\\left[2 \\mu\\left(1+\\frac{m}{M}\\right) \\tan \\theta-\\frac{m}{M}\\right]\\notag\n\t\\end{align}\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=4.5cm,width=4.5cm]{diagram-20220217(7)-crop}\n \\end{figure}\n\\end{answer}\n\\item A body of mass $m$ rests on a horizontal plane with the friction coefficient $\\mu .$ At the moment $t=0$, a horizontal force is applied to it, which varies with time $F=k t$, where $k$ is a constant vector. Find the distance traversed by the body during first/seconds after the force action began.\n\\begin{answer}\n\tHere just after applying the force, the motion does not start due to friction force. As the applied force is proportional to time, let after a time $t_{0}$, the motion starts.\n\t\\begin{align*}\n\t\\text{Now, }F=k t_{0}=\\mu m g\\text{ or }t_{0}=\\left(\\frac{\\mu m g}{k}\\right)\n\\intertext{\tIf $t \\leq t_{0}$, the distance traversed by the body $s=0 .$}\n\\text{\tWhen }t \\leq t_{0},\\text{ then }F&=k\\left(t-t_{0}\\right)\n\t\\end{align*}\n\t\t\\begin{align}\n\t\\therefore \\quad m \\frac{d v}{d t}&=k\\left(t-t_{0}\\right)\\text{ or }m d v=k\\left(t-t_{0}\\right) d t \\ldots \\label{17}\\\\\n\\text{\tIntegrating equation (\\ref{17}), we get } m v&=\\frac{k}{2}\\left(t-t_{0}\\right)^{2}+C_{1}\\notag\\\\\n\t\\text{When }t&=t_{0}, v=0, \\therefore C_{1}=0\\notag\\\\\n\t\\therefore \\quad m v&=\\frac{k}{2}\\left(t-t_{0}\\right)^{2}\\\\\n\t\\text{Again }m \\frac{d s}{d t}&=\\frac{k}{2}\\left(t-t_{0}\\right)^{2}\\text{ or }m d s=\\frac{k}{2}\\left(t-t_{0}\\right)^{2} d t\\label{19}\\\\\n\t\\text{Integrating equation (\\ref{19}), we get }s&=\\frac{k}{6 m}\\left(t-t_{0}\\right)^{3}+C_{2}\\notag\\\\\n\\text{\tHere }C_{2}&=0\\text{ because when }t=t_{0}, s=0\\notag\\\\\n\t\\therefore \\quad s&=\\frac{k}{6 m}\\left(t-t_{0}\\right)^{3} .\\notag\n\t\\end{align}\n\\end{answer}\n\\item A falling rain drop accumulates moisture due to which its radius increases at a constant rate $k$. Neglecting drag calculate the speed of rain drop after it has fallen for a time $t$.\n\\begin{answer}\n\t\\begin{align}\n\t\\text{Equation of motion }\\frac{d p}{d t}&=m g\\label{20}\\\\\n\t\\text{given }\\frac{d r}{d t}&=k \\Rightarrow r=k t\\text{ (if initial radius is zero)}\\notag\\\\\n\t\\text{since }m&=\\frac{4}{3} \\pi r^{3} \\rho \\quad \\therefore \\frac{d m}{d t}=4 \\pi r^{2} \\cdot \\frac{d r}{d t} \\cdot \\rho\\notag\n\\intertext{\t$\\rho$ is density, we assume it to be constant}\\notag\n\t\\frac{d m}{d t} &=\\left(\\frac{4}{3} \\pi r^{3} \\rho\\right) \\cdot \\frac{3 k}{r} \\notag\\\\\n\t\\frac{d m}{d t} &=\\frac{3 m k}{r}\\label{21}\\\\\n\\intertext{\tDividing (\\ref{20}) by (\\ref{21}) we get}\\notag\n\\frac{d p}{d m}&=\\frac{g}{3 k} r \\quad d p=\\left(\\frac{g}{3 k}\\right) \\cdot\\left(\\frac{3 m}{4 \\pi \\rho}\\right)^{1 / 3} d m\\notag\\\\\n\\intertext{on integration we get}\\notag\n\\therefore \\quad p&=\\left(\\frac{g}{3 k}\\right)\\left(\\frac{3}{4 \\pi \\rho}\\right)^{1 / 3} \\cdot \\frac{m^{4 / 3}}{4 / 3}+c\\notag\\\\\n\\text{taking }p&=m=0\\text{ at }t=0,\\text{ we get }c=0\\notag\\\\\n\\therefore \\quad p&=\\frac{g}{4 k}\\left(\\frac{3}{4 \\pi \\rho}\\right)^{1 / 3} \\cdot m^{4 / 3}\\notag\\\\\n\\text{or }v&=\\left(\\frac{g}{4 k}\\right) \\cdot\\left(\\frac{3 m}{4 \\pi \\rho}\\right)^{1 / 3}\\notag\\\\\nv&=\\frac{g}{4 k} r \\Rightarrow v=\\frac{g}{4} t\\notag\n\t\\end{align}\n\\end{answer}\n\t\\item A particle of mass $2 \\mathrm{~kg}$ is moving such that at time $t$, its position, in metre, is given by $\\vec{r}(t)=5 \\hat{i}-2 t^{2} \\hat{j}$. The angular momentum of the particle at $t=2 \\mathrm{~s}$ about the origin, in $\\mathrm{kg} \\mathrm{m}^{2} \\mathrm{~s}^{-1}$, is\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$-40 \\hat{k}$\n\t\t\\task[\\textbf{b.}]$-80 \\hat{k}$\n\t\t\\task[\\textbf{c.}]$80 \\hat{k}$\n\t\t\\task[\\textbf{d.}]  $40 \\hat{k}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\vec{r} &=5 \\hat{i}-2 t^{2} \\hat{j} \\\\\n\t\t\\vec{v} &=\\frac{d \\vec{r}}{d t}=-4 t \\hat{j} \\\\\n\t\t\\vec{p} &=m \\vec{v}=2(-4 t \\hat{j})=-8 t \\hat{j} \\\\\n\t\t\\vec{L} &=\\vec{r} \\times \\vec{p}=\\left(5 \\hat{i}-2 t^{2} \\hat{j}\\right) \\times(-8 t \\hat{j}) \\\\\n\t\t&=-40 t \\hat{k}=-40 \\times 2 \\hat{k}=-80 \\hat{k}\n\t\t\\end{align*}\n\t\t\tHence correct answer is (b)\n\t\\end{answer}\n\t\\item The scalar potential corresponding to the force field $\\vec{F}=\\hat{i}(y+z)$\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]Is $y^{2} / 2$\n\t\t\\task[\\textbf{b.}] Is 1\n\t\t\\task[\\textbf{c.}]Is zero\n\t\t\\task[\\textbf{d.}] Does not exist\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\vec{F} &=\\hat{i}(y+z) \\\\\n\t\\vec{\\nabla} \\times \\vec{F}&=\\left|\\begin{array}{ccc}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ y+z & 0 & 0\\end{array}\\right|=\\hat{i}(0-0)-\\hat{j}(0-1)+\\hat{k}(0-1)=-\\hat{j}-\\hat{k} \\neq 0\n\t\t\\end{align*}\n\t\t\tForce is not conservative so we cannot define potential. \\\\Hence, correct answer is (d)\n\t\\end{answer}\n\\end{enumerate}\n\\section{Stability Analysis}\n\\begin{enumerate}\n\t\\item  A particle of mass $m$ is moving under a one dimensional potential $V(x)=-a x+b x^{2}$ where $a>$ 0 and $b>0$. Find the equilibrium points and find frequency of oscillation about the stable equilibrium.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{At equilibrium point, }\\left.\\frac{d V}{d x}\\right|_{x=x_{0}}=0\\\\\n\t\t\\therefore-a+2 b x_{0}=0 \\quad\\text{ or }\\quad x_{0}&=\\frac{a}{2 b}\\\\\n\t\\text{\tThus, }x_{0}&=\\frac{a}{2 b}\\text{ is an equilibrium point.}\n\\intertext{\tTo know whether it is stable or To know whether it is stable or unstable equilibrium point let us calculate second derivative of potential at equilibrium point.}\n\t\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=x_{0}}&=2 b>0\\\\\n\t\\text{Therefore }x_{0}=\\frac{a}{2 b}&\\text{ is stable equilibrium point, force constant }k=\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=x_{0}}=2 b\n\t\\intertext{Therefore, frequency of oscillation is}\n\t\\omega&=\\sqrt{\\frac{k}{m}}=\\sqrt{\\frac{2 b}{m}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Potential corresponding to force between the atoms of a diatomic molecule is $V(r)=\\frac{a}{r^{12}}-\\frac{b}{r^{6}}$ where $a$ and $b$ are positive constants and $r$ is separation between the atoms. Calculate bond length for stable configuration and also calculate frequency of oscillation of atoms if mass of each atom be $m$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\text{\tFor stable configuration }\\left.\\frac{d V}{d r}\\right|_{r=r_{0}}&=0\\\\\n\t\t-\\frac{12 a}{r_{0}^{13}}+\\frac{6 b}{r_{0}^{7}}=0 \\Rightarrow r_{0}&=\\left(\\frac{2 a}{b}\\right)^{1 / 6}\\\\\n\t\t\\text{Therefore bond length for stable configuration is }&\\left(\\frac{2 a}{b}\\right)^{1 / 6}\\\\\n\t\t\\text{Force constant }k=\\left.\\frac{d^{2} V}{d r^{2}}\\right|_{r=r_{0}}&=\\frac{12 \\times 13 a}{r_{0}^{14}}-\\frac{6 \\times 7 b}{r_{0}^{8}}=\\frac{1}{r_{0}^{8}}\\left(\\frac{12 \\times 13 a}{r_{0}^{6}}-6 \\times 7 b\\right)\\\\\n\t\t&=\\left(\\frac{b}{2 a}\\right)^{8 / 6}\\left(\\frac{12 \\times 13 a}{2 a / b}-42 b\\right)\\\\&=\\left(\\frac{b}{2 a}\\right)^{4 / 3} \\cdot 36 b=\\frac{18}{2^{1 / 3}} \\cdot \\frac{b^{7 / 3}}{a^{4 / 3}}\\\\\n\t\t\\text{Reduced mass of system }\\mu&=\\frac{m \\cdot m}{m+m}=m / 2\\\\\n\t\t\\text{Frequency of oscillation} \\omega=\\sqrt{\\frac{k}{\\mu}}&=\\sqrt{\\frac{18}{2^{1 / 3}} \\cdot \\frac{b^{7 / 3}}{m / 2 a^{4 / 3}}}=6\\left(\\frac{b^{7}}{2 m^{3} a^{4}}\\right)^{1 / 6}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\\item  A particle of mass ' $m$ ' is moving under potential $V(x)=a x^{3}-b x^{2}$. Initially the particle is at at stable point. What minimum speed be given to the particle so that it reaches unstable point. Plot potential versus $x$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{For equilibrium point }\\left.\\frac{d V}{d x}\\right|_{x=x_{0}}&=0\\\\\n\t\t3 a x_{0}^{2}-2 b x_{0}&=0 \\Rightarrow x_{0}=0, \\frac{2 b}{3 a}\\\\\n\t\t\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=x_{0}}&=6 a x_{0}-2 b,\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=0}=-2 b<0, \\therefore x_{0}=0\\text{ is unstable point }\\\\\n\t\t\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=\\frac{2 b}{3 a}}&=2 b>0, \\therefore x_{0}=\\frac{2 b}{3 a}\\text{ is stable point}\n\t\t\\intertext{To calculate speed let us apply conservation of energy.}\n\t\t\\text{Total energy initial }&=\\text{ Total energy final}\n\t\t\\intertext{(Kinetic Energy + Potential Energy) at $x=\\frac{2 b}{a}=($ Kinetic Energy $+$ Potential Energy) at $x=0$ for minimum speed $(u)$ at stable point the particle will just reach unstable point and stops there.}\n\t\t\t\\therefore \\frac{1}{2} m u^{2}+V\\left(x=\\frac{2 b}{3 a}\\right)&=\\frac{1}{2} m .0^{2}+V(x=0)\\\\\n\t\t\\frac{1}{2} m u^{2}+a\\left(\\frac{2 b}{3 a}\\right)^{3}-b\\left(\\frac{2 b}{3 a}\\right)^{2}&=0+0\\\\\n\t\tu^{2}=-\\frac{2}{m}\\left(\\frac{2 b}{3 a}\\right)^{2}\\left(\\frac{2 b}{3}-b\\right)&=\\frac{2}{m} \\cdot \\frac{4 b^{2}}{9 a^{2}} \\cdot \\frac{b}{3}=\\frac{8 b^{3}}{27 m a^{2}}\\\\\n\t\t\\therefore u&=\\sqrt{\\frac{8 b^{3}}{27 m a^{2}}}\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=5cm]{stability001}\n\t\t\\end{figure}\n\t\\end{answer}\n\t\\item  A particle is moving under potential $V(r)=\\frac{a}{r^{2}}-\\frac{b}{r} .$ Calculate the minimum value of potential energy.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\text{\tFor potential to be minimum }\\left.\\frac{d V}{d r}\\right|_{r=r_{0}}=0\\\\\n\t -\\frac{2 a}{r_{0}^{3}}+\\frac{b}{r_{0}^{2}}=0 \\quad \\therefore r_{0}&=\\frac{2 a}{b}\\\\\n\t \\left.\\frac{d^{2} V}{d r^{2}}\\right|_{r=r_{0}}=\\frac{6 a}{r_{0}^{4}}-\\frac{2 b}{r_{0}^{3}}&=\\frac{1}{r_{0}^{3}}\\left(\\frac{6 a}{r_{0}}-2 b\\right)=\\frac{1}{r_{0}^{3}}\\left(\\frac{6 a}{2 a / b}-2 b\\right)=\\frac{b}{r_{0}^{3}}>0\\\\\n\t \\text{Therefore at }r&=r_{0}\\text{ potential is minimum}\\\\\n\t \\therefore \\quad V_{\\min }&=V\\left(r_{0}\\right)=\\frac{1}{r_{0}}\\left(\\frac{a}{r_{0}}-b\\right)=-\\frac{b^{2}}{4 a}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  A cube is placed on the top of a fixed hemisphere as shown in figure. What should be relation between length of side of cube and radius of hemisphere so that cube has stable equilibrium.\n\t\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=6cm]{diagram-20220219(2)-crop}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=5.5cm,width=9cm]{diagram-20220219(3)-crop}\n\t\t\\end{figure}\n\t\tTo discuss equilibrium of cube we first write its potential energy as function of angle from its equilibrium position. As shown in the figure below, initially point A was in contact with spherical surface but now in displaced position point $\\mathrm{B}$ is in contact. Therefore,\n\t\t\\begin{align*}\n\t\tA B&=R \\theta\n\t\t\\intertext{Height of centre of cube from centre level of hemisphere is}\n\t\th&=O C+O^{\\prime} D \\\\\n\t\t&=O O^{\\prime} \\sin \\theta+O^{\\prime} S \\cos 0 \\\\\n\t\t&=A B \\sin \\theta+\\left(O^{\\prime} B+B S\\right) \\cos \\theta \\\\\n\t\t&=R \\theta \\sin \\theta+\\left(\\frac{L}{2}+R\\right) \\cos \\theta\n\t\t\\intertext{Potential energy of the cube}\n\t\tV(\\theta)&=M g h=M g\\left[R \\theta \\sin \\theta+\\left(\\frac{L}{2}+R\\right) \\cos \\theta\\right]\n\t\t\\intertext{$\\theta=0$ is equilibrium position of the cube. For this position to be stable equilibrium position, $\\left.\\frac{d^{2} V}{d \\theta^{2}}\\right|_{\\theta=0}>0$}\n\t&\\therefore \\frac{d^{2}}{d \\theta^{2}} M g\\left[R \\theta \\sin \\theta+\\left(\\frac{L}{2}+R\\right) \\cos \\theta\\right]_{\\theta=0}>0\\\\\n&\\text{\tor }\\frac{d}{d \\theta}\\left[R \\theta \\cos \\theta+R \\sin \\theta-\\left(\\frac{L}{2}+R\\right) \\sin \\theta\\right]_{\\theta=0}>0\\\\\n\t&\\text{or }\\left[R \\cos \\theta-R \\theta \\sin \\theta+R \\cos \\theta-\\left(\\frac{L}{2}+R\\right) \\cos \\theta\\right]_{\\theta=0}>0\\\\\n\t&\\text{or }\\left[2 R-\\left(\\frac{L}{2}+R\\right)\\right]>0 \\quad \\therefore R-\\frac{L}{2}>0\\text{ or }\\quad 2 R>L\n\t\\intertext{Thus, cube can be in stable equilibrium position if its side length is less than diameter of hemisphere}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  For the mass pulley system shown in figure, what should be relation between $m$ and $M$ so that system remains in stable equilibrium position. Pulley are smooth and strings are tight and inextensible\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20220218(4)-crop}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tThe pulleys are fixed. Therefore we can write potential energy of the system by specifying position of blocks with respect to pulleys.\\\\\n\t\tLet ' $l$ ' be length of string and ' $d$ ' be the half distance between two pulleys. Therefore, $l$ and $d$ are constants If $x$ be distance of $m$ below the pulley as shown in figure then potential energy of system is\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6cm]{diagram-20220219(4)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align}\n\t\tV(x)=-2 m g x-M g \\sqrt{(l-x)^{2}-d^{2}} \\quad &\\therefore \\frac{d V}{d x}=-2 m g+\\frac{M g(l-x)}{\\sqrt{(l-x)^{2}-d^{2}}}\\notag\\\\\n\t\t\\text{for equilibrium }\\left.\\frac{d V}{d x}\\right|_{x=x_{0}}=0 \\quad &\\therefore-2 m g+\\frac{M g\\left(l-x_{0}\\right)}{\\sqrt{\\left(l-x_{0}\\right)^{2}-d^{2}}}=0\\notag\\\\\n\t\\text{\tor }\\frac{2 m}{M}&=\\frac{l-x_{0}}{\\sqrt{\\left(l-x_{0}\\right)^{2}-d^{2}}}\\label{23}\\\\\n\t\\left.\\frac{d^{2} V}{d x^{2}}\\right|_{x=x_{0}}&=\\frac{M g d^{2}}{\\left[\\left(l-x_{0}\\right)^{2}-d^{2}\\right]^{3 / 2}}>0\\text{ for all values of $d>0$}\\notag\\\\\n\t\\text{since, }\\frac{l-x_{0}}{\\sqrt{\\left(l-x_{0}\\right)^{2}-d^{2}}}>1 \\quad &\\therefore\\text{ from (\\ref{23}) }\\frac{2 m}{M}>1\\text{ or }2 m>M\\notag\n\t\t\\end{align}\n\t\\end{answer}\n\\item The potential energy between two atoms are given $v(r)=\\frac{a}{r^{12}}-\\frac{b}{r^{6}}$ where $a, b$ positive constants.\n(i) Find the equilibrium distance of two atoms.\\\\\n(ii) Plot the potential\\\\\n(iii) Calculate the frequency of small oscillation.\\\\\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{(i) For equilibrium potential energy should be minimum.}\n\t\t\\frac{\\mathrm{dU}}{\\mathrm{dr}}=-\\frac{12 \\mathrm{a}}{\\mathrm{r}^{13}}+\\frac{6 \\mathrm{~b}}{\\mathrm{r}^{7}}&=0 \\Rightarrow \\mathrm{r}^{6}=\\frac{2 \\mathrm{a}}{\\mathrm{b}} \\\\\n\t\t\\mathrm{r}=\\left(\\frac{20}{\\mathrm{~b}}\\right)^{1 / 6}&=\\mathrm{r}_{0} \\\\\n\t\t\\mathrm{U}\\left(\\mathrm{r}_{0}\\right)=\\frac{\\mathrm{ab}^{2}}{4 \\mathrm{a}^{2}}-\\frac{\\mathrm{b} \\cdot \\mathrm{b}}{2 \\mathrm{a}}&=\\frac{\\mathrm{b}^{2}}{4 \\mathrm{a}}-\\frac{\\mathrm{b}^{2}}{2 \\mathrm{a}}=-\\frac{\\mathrm{b}^{2}}{4 \\mathrm{a}}\\\\\n\t\t\\frac{\\mathrm{dU}}{\\mathrm{dr}}=-\\frac{12 \\mathrm{a}}{\\mathrm{r}^{13}}+\\frac{6 \\mathrm{~b}}{\\mathrm{r}^{7}}&=0 \\Rightarrow \\mathrm{r}^{6}=\\frac{2 \\mathrm{a}}{\\mathrm{b}}\\\\ \\mathrm{r}=\\left(\\frac{20}{\\mathrm{~b}}\\right)^{1 / 6}&=\\mathrm{r}_{0} \\quad[\\text{ Position of stability equilibrium }]\\\\ \\mathrm{U}\\left(\\mathrm{r}_{0}\\right)=\\frac{\\mathrm{ab}^{2}}{4 \\mathrm{a}^{2}}-\\frac{\\mathrm{b} \\cdot \\mathrm{b}}{2 \\mathrm{a}}&=\\frac{\\mathrm{b}^{2}}{4 \\mathrm{a}}-\\frac{\\mathrm{b}^{2}}{2 \\mathrm{a}}=-\\frac{\\mathrm{b}^{2}}{4 \\mathrm{a}}\n\t\t\t\\end{align*}\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[height=5cm,width=9cm]{diagram-20220219(5)-crop}\n\t\t\t\\end{figure}\n\t\t\t\t\\begin{align*}\n\t\t\\mathrm{U}\\left(\\mathrm{r}_{0}\\right)=\\frac{-\\mathrm{b}^{2}}{4 \\mathrm{a}} ; \\mathrm{U}(\\mathrm{r})&=\\mathrm{U}\\left(\\mathrm{r}_{0}\\right)+\\left.\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right) \\frac{\\mathrm{dU}}{\\mathrm{dr}}\\right|_{\\mathrm{r}_{0}}+\\left.\\frac{\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right)^{2}}{2} \\frac{\\mathrm{d}^{2} \\mathrm{U}}{\\mathrm{dr}^{2}}\\right|_{\\mathrm{c}_{0}}\\\\\n\t\t\\frac{\\mathrm{d}^{2} \\mathrm{U}}{\\mathrm{dr}^{2}}=\\frac{12 \\times 13 \\mathrm{a}}{\\mathrm{r}^{14}}-\\frac{42 \\mathrm{~b}}{\\mathrm{r}^{8}} ;\\left.\\frac{\\mathrm{d}^{2} \\mathrm{U}}{\\mathrm{dr}^{2}}\\right|_{\\mathrm{k}_{0}}&=\\frac{156 \\mathrm{a}}{\\mathrm{r}^{14}}-\\frac{42 \\mathrm{~b}}{\\mathrm{r}^{8}}=\\frac{156 \\mathrm{a}}{(2 \\mathrm{a})^{1 / 6}}-\\frac{42 \\mathrm{~b}}{\\left(\\frac{2 \\mathrm{a}}{\\mathrm{h}}\\right)^{3 / 6}}\\\\\n\t\t&=\\frac{156 \\mathrm{a}}{\\left(\\frac{2 \\mathrm{a}}{\\mathrm{b}}\\right)^{1 / 3}}-\\frac{42 \\mathrm{~b}}{\\left(\\frac{2 \\mathrm{a}}{\\mathrm{b}}\\right)^{1 / 3}}=\\text { constant }=c\\\\\n\t\\intertext{\t(Force constant equivalent to spring constant)}\n\t\tU(r)&=U\\left(r_{0}\\right)+\\frac{c}{2}\\left(r-r_{0}\\right)^{2}\\\\\n\t\t\\text{So, the force }&=-\\frac{\\mathrm{dU}}{\\mathrm{dr}}=-\\frac{\\mathrm{c}}{2} \\cdot 2\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right)^{2}=-\\mathrm{c}\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right)\\\\\n\t\t\\text{Force }&=-\\nabla U ; U=U(r)\\text{ only}\\\\\n\t\t\\overrightarrow{\\mathrm{F}}&=\\mathrm{m} \\overline{\\mathrm{a}} \\text{(Here introduced to harmonic oscillator maynecessary).}\\\\\n\t\t \\text{Equation of motion, }&\\mathrm{m} \\frac{\\mathrm{d}^{2} \\mathrm{r}}{\\mathrm{dt}^{2}}=-\\mathrm{c}\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right) ; \\frac{\\mathrm{d}^{2} \\mathrm{r}}{\\mathrm{dt}^{2}}+\\frac{\\mathrm{c}}{\\mathrm{m}}\\left(\\mathrm{r}-\\mathrm{r}_{0}\\right)=0\\\\\n\t\t \\text{ Take }\\mathrm{c}&=m \\omega^{2} ; \\omega=\\sqrt{\\frac{\\mathrm{c}}{\\mathrm{m}}}\n\t\t \\intertext{A particle of mass ' $\\mathrm{m}$ ' moving in a potential} \\mathrm{V}(\\mathrm{x})&=\\frac{1}{2} \\mathrm{~m} \\omega_{0}^{2} \\mathrm{x}^{2}+\\frac{\\mathrm{a}}{2 \\mathrm{~m} \\mathrm{x}^{2}} \\quad\\left(\\omega_{0} \\&\\right. \\text{are constant })\n\t\t \\intertext{ Find the angular trequency of small oscillation.}\n\t\t\\frac{\\mathrm{dv}}{\\mathrm{dx}}&=m \\omega_{0}^{2} \\mathrm{x}-\\frac{\\mathrm{a}}{\\mathrm{m} \\mathrm{x}^{3}}=0\\\\\n\t\tm \\omega_{0}^{2} x_{0}-\\frac{a}{m x^{3}}&=0 ; x_{0}^{4}=\\frac{a}{m^{2} \\omega_{0}^{2}} ; \\chi_{0}=\\left(\\frac{a}{m^{2} \\omega_{0}^{2}}\\right)^{1 / 4}\\\\\n\t\t\\text{Equilibrium distance, }\\frac{d^{2} z}{d x^{2}}&=m \\omega_{0}^{2}+\\frac{3 a}{m x^{4}}\\\\\n\t\t\\left.\\frac{\\mathrm{d}^{2} \\mathrm{r}}{\\mathrm{dx}^{2}}\\right|_{\\mathrm{x}=\\mathrm{x}_{0}}&=m \\omega_{0}^{2}+\\frac{3 \\mathrm{a}}{\\mathrm{ma}} \\mathrm{m}^{2} \\omega^{2}=4 \\mathrm{~m} \\omega_{0}^{2} \\quad\\left(\\mathrm{x}_{0}^{4}=\\frac{\\mathrm{a}}{\\mathrm{m}^{2} \\omega_{0}^{2}}\\right)\\\\\n\t\t\\mathrm{U}(\\mathrm{x})&=\\mathrm{U}\\left(\\mathrm{x}_{0}\\right)+\\left.\\left(\\mathrm{x}-\\mathrm{x}_{0}\\right) \\frac{\\mathrm{dU}}{\\mathrm{dx}}\\right|_{\\mathrm{x}=\\mathrm{x}_{0}}+\\left.\\frac{\\left(\\mathrm{x}-\\mathrm{x}_{0}\\right)^{2}}{2} \\frac{\\mathrm{d}^{2} \\mathrm{U}}{\\mathrm{dx}^{2}}\\right|_{\\mathrm{x}=\\mathrm{x}_{0}}\\\\\n\t\t&=\\mathrm{U}\\left(\\mathrm{x}_{0}\\right)+\\left(\\mathrm{x}-\\mathrm{x}_{0}\\right)^{2} 2 \\mathrm{~m} \\omega_{0}^{2}\\\\\n\t\t\\text{Force }&=-\\frac{\\mathrm{dU}}{\\mathrm{dx}}=-4 \\mathrm{~m} \\omega_{0}^{2}\\left(\\mathrm{x}-\\mathrm{x}_{0}\\right)\\\\\n\t\\text{\tEquation of motion, }\\mathrm{m} \\frac{\\mathrm{d}^{2} \\mathrm{x}}{\\mathrm{dt}^{2}}&=\\mathrm{F}=-4 \\omega_{0}^{2}\\left(\\mathrm{x}-\\mathrm{x}_{0}\\right)\\\\\n\t\t\\frac{d^{2} x}{d t^{2}}+4 \\omega_{0}^{2}\\left(x-x_{0}\\right)&=0\\\\\n\t\t\\text{Hence, the frequency of small oscillation, }\\omega&=\\sqrt{4 \\omega_{0}^{2}}=2 \\omega_{0}.\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A particle of mass ' $m$ ' is constrained to move in one dimension under a potential $u(x)=\\frac{\\alpha}{x^{2}}-\\frac{\\beta}{x}$, where $\\alpha$ and $\\beta$ are positive constants. Show that period of small oscillations about the equilibrium point is\n\t$T=4 \\pi \\sqrt{\\frac{2 \\alpha^{3} m}{\\beta^{4}}}$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\text{\tAt equilibrium point }&\\left(x=x_{0}\\right)\\\\\n\t\t\\left.\\frac{d u}{d x}\\right|_{x=x_{0}}=0 \\\\\n\t\t-\\frac{2 \\alpha}{x_{0}^{3}}+\\frac{\\beta}{x_{0}^{2}}&=0\n\t\t\\hspace{1cm}\\therefore x_{0}=\\frac{2 \\alpha}{\\beta}=\n\t\t \\intertext{time period of oscillation is given by}\n\t\tT&=2 \\pi \\sqrt{\\frac{m}{k}}\n\t\\intertext{\twhere $k$ is force constant and is given by}\n\t\tk&=\\left.\\frac{d^{2} u}{d x^{2}}\\right|_{x=x_{0}} =\\frac{6 \\alpha}{x_{0}^{4}}-\\frac{2 \\beta}{x_{0}^{3}}=6 \\alpha \\cdot \\frac{\\beta^{4}}{16 \\alpha^{4}}-\\frac{2 \\beta^{4}}{8 \\alpha^{3}} \\\\\n\t\t&=\\frac{3}{8} \\cdot \\frac{\\beta^{4}}{\\alpha^{3}}-\\frac{2}{8} \\cdot \\frac{\\beta^{4}}{\\alpha^{3}} \\Rightarrow k=\\frac{\\beta^{4}}{8 \\alpha^{3}}\\\\\n\t\t\\therefore T&=2 \\pi \\sqrt{\\frac{8 \\alpha^{3}}{\\beta^{4}} \\cdot m}=4 \\pi \\sqrt{\\frac{2 \\alpha^{3} m}{\\beta^{4}}}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Central Force Motion}\n\\begin{enumerate}\n\t\\item  Equation of the orbit of a particle moving under central force is $r \\theta=\\beta$, where $\\beta$ is a constant. Find the force acting on the particle.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tr \\theta=\\beta,\\text{ therefore, }u&=\\frac{1}{r}=\\frac{\\theta}{\\beta} \\quad \\therefore \\frac{\\partial^{2} u}{\\partial \\theta^{2}}=0\\\\\n\t\t\\text{\tDifferential equation of orbit, }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}+u&=\\frac{-m f(r)}{L^{2} u^{2}}\\\\\n\t\t\\therefore 0+u=\\frac{-m f(r)}{L^{2} u^{2}} \\quad \\therefore \\quad f(r)&=\\frac{-L^{2} u^{3}}{m}=\\frac{-L^{2}}{m r^{3}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Equation of orbit of a particle moving under central force is $r^{n}=a \\cos n \\theta .$ Find the force on the particle.\n\t\\begin{answer}\n\t\t\\begin{align}\n\t\t\\text{\tGiven, }r^{n}=a \\cos n \\theta,\\text{ therefore, }u^{n}=\\frac{1}{a \\cos n \\theta}&=\\frac{1}{a} \\sec n \\theta \\label{25}\\\\\n\t\t\\text{ Taking $\\ln$ both sides we get, }n \\ln u&=\\ln \\left(\\frac{1}{a}\\right)+\\ln \\sec n \\theta\\notag\\\\\n\t\t\\text{Differentiating w.r.t. $\\theta$ we get, }\\frac{n}{u} \\frac{\\partial u}{\\partial \\theta}&=n \\tan n \\theta \\quad \\therefore \\frac{\\partial u}{\\partial \\theta}=u \\tan n \\theta\\notag\\\\\n\t\t\\text{Differentiating again w.r.t. $\\theta$ we get }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}&=\\frac{\\partial u}{\\partial \\theta} \\tan n \\theta+u n \\sec ^{2} n \\theta\\notag\\\\&=u \\tan ^{2} n \\theta+u n \\sec ^{2} n \\theta\\notag\\\\\n\t\t\\text{ Differential equation of orbit is }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}+u&=\\frac{-m f(r)}{L^{2} u^{2}}\\notag\\\\\n\t\tu \\tan ^{2} n \\theta+u n \\sec ^{2} n \\theta+u&=\\frac{-m f(r)}{L^{2} u^{2}}, u \\sec ^{2} n \\theta+u n \\sec ^{2} n \\theta=\\frac{-m f(r)}{L^{2} u^{2}}\\notag\\\\\n\t\t\\therefore f(r)&=-\\frac{L^{2} u^{3}(1+n) \\sec ^{2} n \\theta}{m}\\notag\\\\\n\t\t\\text{from (\\ref{25}) }\\sec ^{2} n \\theta&=a^{2} u^{2 n}\\notag\\\\\n\t\t\\therefore f(r)&=\\frac{-L^{2}(n+1) a^{2} u^{2 n+3}}{m}\\notag\\\\\n\t\t\\therefore \\quad f(r)&=\\frac{-L^{2}(n+1) a^{2}}{m} \\cdot \\frac{1}{r^{2 n+3}}\\notag\\\\\n\t\t\\text{Or }\n\t\tf(r) \\propto \\frac{1}{r^{2 n+3}}&\n\t\t\\text{and the force is attractive in nature.}\\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\item  A particle of mass $m$ is moving under a central force. The angular momentum of the partix $\\mathrm{L}$ and its equation of orbit is $r=A e^{k 0}$. Calculate potential energy of the particle.\n\t\\begin{answer}\n\t\t\\begin{align}\n\t\t\\text{Potential energy is given as }V(r)&=-\\int f(r) d r\\label{26}\n\t\t\\intertext{\tTherefore, let us first find $f(r)$.}\\notag\n\t\t\\text{Given }r=A e^{k \\theta},\\text{ thereforc, }u&=\\frac{1}{A} e^{-k \\theta} \\quad \\therefore \\frac{\\partial^{2} u}{\\partial \\theta^{2}}=k^{2} u\\notag\\\\\n\t\t\\text{Differential equation of orbit is }\\frac{\\partial^{2} u}{\\partial \\theta^{2}}+u&=\\frac{-m f(r)}{L^{2} u^{2}} \\quad \\therefore\\left(k^{2}+1\\right) u=\\frac{-m f(r)}{L^{2} u^{2}}\\notag\\\\\n\t\t\\therefore f(r)&=\\frac{-L^{2}\\left(k^{2}+1\\right) u^{3}}{m} \\text { or } f(r)=\\frac{-L^{2}\\left(k^{2}+1\\right)}{m r^{3}}\\notag\\\\\n\t\t\\text{Therefore, from (\\ref*{26}) }V(r)&=-\\int f(r) d r=\\frac{-L^{2}\\left(k^{2}+1\\right)}{2 m r^{2}}\\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\item  For a particle moving under gravitational force pericentre distance in parabolic orbit is $r_{p}$ while the radius of the circular orbit with same angular momentum is $r_{c}$. What is relation between $r_{p}$ and $r_c$ ?\n\t\\begin{answer}\n\t\tPericentre distance is the minimum distance $(\\cos \\theta=\\max =1)$ and for parabolic orbit $e=1 .$\n\t\t\\begin{align*}\n\t\t\\text{Therefore, }r_{\\min }&=\\frac{l}{1+e \\cos \\theta}=\\frac{l}{2}=r_{p}\\\\\n\t\t\\text{for circular orbit $e=0$, therefore }r_{c}&=\\frac{l}{1+e \\cos \\theta}=l \\quad \\therefore r_{p}=\\frac{r_{c}}{2}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Ratio of maximum to minimum speed of a planet revolving around the sun in an elliptical orbit is $2: 1$, What is eccentricity of the orbit?\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tGiven }\\frac{v_{\\max }}{v_{\\min }}=\\frac{2}{1} \\therefore \\frac{\\sqrt{\\frac{G M}{a}\\left(\\frac{1+e}{1-e}\\right)}}{\\sqrt{\\frac{G M}{a}\\left(\\frac{1-e}{1+e}\\right)}}=\\frac{2}{1} \\quad\\text{ or }\\quad \\frac{1+e}{1-e}=\\frac{2}{1} \\quad \\therefore e=\\frac{1}{3}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  A planet is revolving around the sun in a circular orbit. Due to some reason the speed of the planet suddenly becomes double. What is new orbit of the planet.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{\tOrbital speed of the planet is }&\\sqrt{\\frac{G M}{r}}\\\\\n\t\t\\text{New speed of the planet }&=2 \\sqrt{\\frac{G M}{r}}\\\\\n\t\t\\text{Therefore, new energy of the planet }&=\\frac{1}{2} m v^{2}-\\frac{G M m}{r}=\\frac{1}{2} m \\cdot \\frac{4 G M}{r}-\\frac{G M m}{r}=\\frac{2 G M m}{r}>0\n\t\t\\intertext{\tTotal energy of the planet becomes positive on doubling its speed therefore new orbit of the planet will be hyperbolic.}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\\begin{enumerate}\n\t\\item  A planet of mass $m$ and angular momentum $\\mathrm{L}$ moves in a circular orbit in a potential, $V(r)=-k / r$ where $k$ is a positive constant find the radius of stable circular orbit. If the planet is slightly perturbed, find angular frequency of radial oscillation.\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=1.5cm,width=6cm]{diagram-20220221(2)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tV_{e f f}=\\frac{L^{2}}{2 m r^{2}}+V(r)&=\\frac{L^{2}}{2 m r^{2}}-\\frac{k}{r}\\\\\n\t\t\\text{For stable point (orbit) }\\left.\\frac{\\partial V_{e f f}}{\\partial r}\\right|_{r=r_{0} .}&=0\\\\\n\t\t\\therefore-\\frac{L^{2}}{m r_{0}^{3}}+\\frac{k}{r_{0}^{2}}&=0 \\text { or } r_{0}=\\frac{L^{2}}{m k}\\\\\n\t\t\\text{\tTherefore radius of stable circular orbit is }L^{2} / \\mathrm{mk}\n\t\t\\end{align*}\n\t\tAngular frequency of oscillation about stable point:\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=0.7cm,width=6.4cm]{diagram-20220221-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\omega&=\\sqrt{\\frac{\\left.\\frac{\\partial^{2} V_{e f f}}{\\partial r^{2}}\\right|_{r=r_{0}}}{m}}=\\sqrt{\\frac{\\left(\\frac{3 L^{2}}{m r_{0}^{4}}-\\frac{2 k}{r_{0}^{3}}\\right)}{m}}\\\\\n\t\t&=\\sqrt{\\frac{\\frac{1}{r_{0}^{3}}\\left(\\frac{3 L^{2}}{m \\cdot \\frac{L^{2}}{m k}}-2 k\\right)}{m}}=\\sqrt{\\frac{k}{m r_{0}^{3}}}=\\sqrt{\\frac{k^{4} m^{2}}{L^{6}}}=\\frac{m k^{2}}{L^{3}}\n\t\t\\end{align*}\n\t\tactual radial oscillation is as shown in figure.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=4cm]{diagram-20220221(1)-crop}\n\t\t\\end{figure}\n\t\\end{answer}\n\t\\item  A small asteroid is approaching a massive star with a speed $v$ from very large distance, at an impact parameter ' $b$ ' as shown in figure. If the mass of the star is $M$ and its radius is $R$, then what is the minimum value of $b$ such that the asteroid will miss the star?\n\t\\begin{answer}\n\t\tAngular momentum of asteroid about centre of star is $L=m v b$\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=5cm]{diagram-20220221(3)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\text{Effective potential energy }V_{e f f}&=\\frac{-G M m}{r}+\\frac{L^{2}}{2 m r^{2}}=\\frac{-G M m}{r}+\\frac{m v^{2} b^{2}}{2 r^{2}}\n\t\t\\end{align*}\n\t\tFor minimum value of $b$ we will have to assume that asteroid just misses the star as shown in figure. Equivalent 1-d problem is also shown in figure\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=12cm]{diagram-20220221(7)-crop}\n\t\t\\end{figure}\n\t\t\\text{Total energy is conserved in central force motion }\n\t\t\\begin{align*}\n\t\t\\text{Therefore, }E_{1}&=E_{2}\\\\\n\t\t\\text{or }&\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{e f f}\\right)_{\\mathrm{at} r=\\infty}=\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{e f f}\\right)_{\\mathrm{at} r=R}\\\\\n\t\t\\frac{1}{2} m v^{2}-\\frac{G M m}{\\infty}+\\frac{m v^{2} b^{2}}{\\infty}&=\\left(\\frac{1}{2} m o^{2}-\\frac{G M m}{R}+\\frac{m v^{2} b^{2}}{2 R^{2}}\\right)\\\\\n\t\t\\therefore v^{2}+\\frac{2 G M}{R}&=\\frac{v^{2} b^{2}}{R^{2}} \\quad \\text { or } b=R \\sqrt{1+\\frac{2 G M}{R v^{2}}}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  A particle is thrown in radially outward direction from earth's surface with initial speed $\\sqrt{\\frac{3 G M}{4 R}}$ where $M$ is mass of earth $R$ is radius of earth. Find the height upto which particle goes.\n\t\\begin{answer}\n\t\tParticle has been thrown radially outward \n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=6.5cm]{diagram-20220221(6)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\text{therefore }L&=0, V_{e f f}=V(r)+\\frac{L^{2}}{2 m r^{2}}\\\\\n\t\t\\therefore V_{e f f}&=\\frac{-G M m}{r}+0\\\\\n\t\t\\intertext{from conservation of energy we get }E_{1}&=E_{2}\\\\\n\t\t\\text { or }\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{e f f}\\right)_{r=R}&=\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{d f}\\right)_{r=r} \\\\\n\t\t\\frac{1}{2} m \\cdot \\frac{3 G M}{4 R}-\\frac{G M m}{R}&=0-\\frac{G M m}{r} \\\\\n\t\t\\frac{3}{8 R}-\\frac{1}{R}&=-\\frac{1}{r} \\quad \\therefore r=\\frac{8 R}{5}\n\t\t\\end{align*}\n\t\tTherefore, maximum height from earth's surface $=r-R=\\frac{3 R}{5}$\n\t\\end{answer}\n\t\\item  A particle is thrown from the earth's surface with speed $\\sqrt{\\frac{G M}{R}}$ where $M=$ mass of earth\n\t$R=$ radius of earth. If direction of initial velocity makes an angle $\\alpha$ with the outward radial direction, find the maximum distance of the particle from centre of earth.\n\t\\begin{answer}\n\t\tAngular momentum of the particle is\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=5cm,width=8cm]{diagram-20220221(5)-crop}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tL &=m v \\sin \\alpha R=m \\sqrt{\\frac{G M}{R}} \\sin \\alpha R \\\\\n\t\t&=m \\sqrt{G M R} \\sin \\alpha \\\\\n\t\t\\therefore V_{e f f} &=V(r)+\\frac{L^{2}}{2 m r^{2}}=\\frac{-G M m}{r}+\\frac{G M m R}{2 r^{2}} \\sin ^{2} \\alpha\n\t\t\\end{align*}\n\t\tFrom conservation of energy we get $\\mathrm{E}_{1}=\\mathrm{E}_{2}$\n\t\t\\begin{align*}\n\t\t\\text{\tor }\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{e f f}\\right)_{r=R}&=\\left(\\frac{1}{2} m \\dot{r}^{2}+V_{e f f}\\right)_{r=r}\\text{ (see the figure)}\\\\\n\t\t\\frac{1}{2} m \\frac{G M}{R} \\cos ^{2} \\alpha-\\frac{G M m}{R}+\\frac{G M m}{2 R} \\sin ^{2} \\alpha&=\\frac{-G M m}{r}+\\frac{G M m R}{2 r^{2}} \\sin ^{2} \\alpha\\\\\n\t\t\\text{Divide both sides by }\\frac{G M m}{2 R}\\text{ to get }&\\cos ^{2} \\alpha-2+\\sin ^{2} \\alpha=-2 \\frac{R}{r}+\\frac{R^{2}}{r^{2}} \\sin ^{2} \\alpha\\\\\n\t\t\\text{or }-1=-2\\left(\\frac{R}{r}\\right)+\\left(\\frac{R}{r}\\right)^{2} \\sin ^{2} \\alpha \\quad &\\therefore\\left(\\frac{R}{r}\\right)^{2} \\sin ^{2} \\alpha-2\\left(\\frac{R}{r}\\right)+1=0\\\\\n\t\t\\therefore \\frac{R}{r}=\\frac{+2 \\pm \\sqrt{4-4 \\sin ^{2} \\alpha}}{2 \\sin ^{2} \\alpha} \\quad \\frac{R}{r}&=\\frac{+1 \\pm \\cos \\alpha}{\\sin ^{2} \\alpha} \\\\\n\t\t\\therefore r=\\frac{R \\sin ^{2} \\alpha}{1 \\pm \\cos \\alpha}=\\frac{R\\left(1-\\cos ^{2} \\alpha\\right)}{(1 \\pm \\cos \\alpha)} \\quad &\\therefore r=R(1-\\cos \\alpha) \\quad \\text { or } \\quad r=R(1+\\cos \\alpha)\n\t\t\\end{align*}\n\t\tSince $r$ must be greater than $r$. Therefore, $r=R(1+\\cos \\alpha)$\n\t\\end{answer}\n\t\\item  A particle moves under a central potential $V(r)=\\frac{-k}{r^{m}} .$ What should be value of $m$ for its orbit to be stable.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Corresponding is }f(r)&=-\\frac{\\partial V}{\\partial r}=\\frac{-m k}{r^{m+1}}=-m k r^{-(m+1)}\\\\\n\t\t\\text{\tWe know that for }f&=-k r^{n}\\text{ condition for stability is $n>-3$.} \n\t\t\\intertext{Therefore for orbit to be stable under given potential we must have.}\n\t\t-(m+1)>-3&\\text{ or }m+1<3 \\quad \\therefore m<2\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Lagrangian}\n\\begin{enumerate}\n\t\\item The Lagrangian of a particle of charge e and mass $m$ in applied electric and magnetic fields is given by $L=\\frac{1}{2} \\mathrm{~m} \\vec{v}^{2}+\\mathrm{e} \\overrightarrow{\\mathrm{A}} \\cdot \\vec{v}-\\mathrm{e} \\phi$, where $\\overrightarrow{\\mathrm{A}}$ and $\\phi$ are the vector and scalar potentials corresponding to the magnetic and electric fields, respectively. Which of the following statements is correct?\n\t \\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}] The carionically conjugate momentum of the particle is given by $\\overrightarrow{\\mathrm{p}}=\\mathrm{m} \\overrightarrow{\\mathrm{v}}$\n\t\t\\task[\\textbf{b.}]The Hamiltonian of the particle is given by $\\mathrm{H}=\\frac{\\overrightarrow{\\mathrm{p}}^{2}}{2 \\mathrm{~m}}+\\frac{\\mathrm{e}}{\\mathrm{m}} \\cdot \\overrightarrow{\\mathrm{A}} \\cdot \\overrightarrow{\\mathrm{p}}+\\mathrm{e} \\phi$\n\t\t\\task[\\textbf{c.}]L remains unchanged under a gauge transformation of the potentials.\n\t\t\\task[\\textbf{d.}]  Under a gauge transformation of the potentials, $\\mathrm{L}$ changes by the total time derivative of a function of $\\overrightarrow{\\mathrm{r}}$ and $\\mathrm{t}$.\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathrm{L}&=\\frac{1}{2} \\mathrm{~m} \\overrightarrow{\\mathrm{v}}-\\mathrm{e} \\phi+\\mathrm{e} \\overrightarrow{\\mathrm{A}} \\cdot \\overrightarrow{\\mathrm{v}}\n\t\\intertext{\tWe know that $\\vec{E}$ and $\\vec{B}$ fields are in variant under gauge transformation.}\n\t\t\\overrightarrow{\\mathrm{A}}(\\overrightarrow{\\mathrm{x}}, \\mathrm{t}) \\rightarrow \\overrightarrow{\\mathrm{A}}^{\\prime}&=\\overrightarrow{\\mathrm{A}}+\\vec{\\nabla} \\lambda(\\overrightarrow{\\mathrm{x}}, \\mathrm{t}) ; \\quad \\varphi(\\overrightarrow{\\mathrm{x}}, \\mathrm{t}) \\rightarrow \\varphi^{\\prime}=\\varphi-\\frac{\\partial \\lambda}{\\partial \\mathrm{t}}(\\overrightarrow{\\mathrm{x}}, \\mathrm{t})\n\t\\intertext{\twhere $\\lambda(\\vec{x}, t)$ is an arbitrary scalar function.}\n\t\t\\therefore \\quad \\mathrm{L} \\rightarrow \\mathrm{L}^{\\prime}&=\\mathrm{L}+\\mathrm{e}\\left(\\frac{\\partial \\lambda}{\\partial \\mathrm{t}}(\\overrightarrow{\\mathrm{x}}, \\mathrm{t})+\\overrightarrow{\\mathrm{v}} \\cdot \\vec{\\nabla} \\lambda(\\overrightarrow{\\mathrm{x}}, \\mathrm{t})\\right)\n\t\t\\end{align*}\n\t\tThe expression in bracket is just the total time derivative of $\\lambda(\\vec{x}, t)$.\\\\\n\t\tIf we add a total time derivative of a function of $\\overrightarrow{\\mathrm{x}}$ and $\\mathrm{t}$ to the Lagrangian, the equations of motion do not change.\\\\\n\t\tCorrect answer is option \\textbf{(d)}\n\t\\end{answer}\n\t\\item The Hamiltonian o fa system with $n$ degrees of freedom is given by \\\\$H\\left(q_{i}, \\ldots \\ldots \\ldots ., q_{n} ; p_{i}, \\ldots \\ldots \\ldots \\ldots, p_{n} ; t\\right)$\\\\\n\twith an explicit dependence on the time $t$. Which of the following is correct?\n\t \\begin{tasks}(1)\n\t\t\\task[\\textbf{a.}]Different phase trajectories cannot intersect each other\n\t\t\\task[\\textbf{b.}]H always represents the total energy of the system and is a constant of the motion.\n\t\t\\task[\\textbf{c.}]The equations $\\dot{\\mathrm{q}}_{\\mathrm{i}}=\\partial \\mathrm{H} / \\partial \\mathrm{p}_{\\mathrm{i}}, \\dot{\\mathrm{p}}_{\\mathrm{i}}=-\\partial \\mathrm{H} / \\partial \\mathrm{q}_{\\mathrm{i}}$ are not valid since H has explicit time dependence.\n\t\t\\task[\\textbf{d.}] Any initial volume element in phase space remains unchanged in magnitude under time evolution.\n\t\\end{tasks}\n\\begin{answer}\n\tAccording to Liouville's theorem, the phase volume occupied by a collection of system evolve according to - Hamilton's equation of motion, and will be preserved in time.\\\\\n\tCorrect answer is option \\textbf{(d)}\n\\end{answer}\n\t\\item A double pendulum consists of two point masses $m$ attached by massless strings of length $l$ as shown in the figure:\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4.5cm]{CM-02}\n\t\\end{figure}\n\tThe kinetic energy of the pendulum is :\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2} \\mathrm{~m} \\ell^{2}\\left[\\dot{\\theta}_{1}^{2}+\\dot{\\theta}_{2}^{2}\\right]$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2} m \\ell^{2}\\left[2 \\dot{\\theta}_{1}^{2}+\\dot{\\theta}_{2}^{2}+2 \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\dot{\\theta}_{1}-\\dot{\\theta}_{2}\\right)\\right]$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{2} m \\ell^{2}\\left[\\dot{\\theta}_{1}^{2}+2 \\dot{\\theta}_{2}^{2}+2 \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\dot{\\theta}_{1}-\\dot{\\theta}_{2}\\right)\\right]$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{2} \\mathrm{~m} \\ell^{2}\\left[2 \\dot{\\theta}_{1}^{2}+\\dot{\\theta}_{2}^{2}+2 \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\dot{\\theta}_{1}+\\dot{\\theta}_{2}\\right)\\right]$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\mathrm{x}_{1}&=\\ell \\sin \\theta_{1},  \\mathrm{x}_{2}=\\ell \\sin \\theta_{1}+\\ell \\sin \\theta_{2} \\\\ \\mathrm{y}_{1}&=-\\ell \\cos \\theta_{1},  \\mathrm{y}_{2}=-\\ell \\cos \\theta_{1}-\\ell \\cos \\theta_{2} \\\\ \\dot{\\mathrm{x}}_{1}&=\\ell \\cos \\theta_{1} \\dot{\\theta}_{1},  \\dot{\\mathrm{y}}_{1}=\\ell \\sin \\theta_{1} \\dot{\\theta}_{1}\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.5cm,width=6.5cm]{CM-03}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\dot{x}_{2}&=\\ell \\cos \\theta_{1} \\dot{\\theta}_{1}+\\ell \\cos \\theta_{2} \\dot{\\theta}_{2} ; \\quad \\dot{y}_{2}=\\ell \\sin \\theta_{1} \\dot{\\theta}_{1}+\\ell \\sin \\theta_{2} \\dot{\\theta}_{2},\\\\\n\t\tT&=\\frac{m}{2}\\left(\\dot{x}_{1}^{2}+\\dot{y}_{1}^{2}\\right)+\\frac{m}{2}\\left(\\dot{x}_{2}^{2}+\\dot{y}_{2}^{2}\\right)\\\\\n\t\t&=\\frac{\\mathrm{m}}{2} \\dot{\\theta}_{1}^{2} \\ell^{2}+\\frac{\\mathrm{m}}{2}\\left[\\dot{\\theta}_{1}^{2} \\ell^{2}+\\dot{\\theta}_{2}^{2} \\ell^{2}+2 \\ell^{2} \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\theta_{1}-\\theta_{2}\\right)\\right]\\\\\n\t\t&=\\frac{\\mathrm{m} \\ell^{2}}{2}\\left[2 \\dot{\\theta}_{1}^{2}+\\dot{\\theta}_{2}^{2}+2 \\dot{\\theta}_{1} \\dot{\\theta}_{2} \\cos \\left(\\theta_{1}-\\theta_{2}\\right)\\right]\n\t\t\\end{align*}\n\t\tCorrect answer is \\textbf{(b)}\n\t\\end{answer}\n\t\\item A particle of mass ' $\\mathrm{m}$ ' moves inside a bowl. If the surface of the bowl is given by the equation $\\mathrm{z}=\\frac{1}{2} \\mathrm{a}\\left(\\mathrm{x}^{2}+\\mathrm{y}^{2}\\right)$, where $a$ is a constant, the Lagrangian of the particle is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\phi}^{2}-g a r^{2}\\right)$\n\t\t\\task[\\textbf{b.}] $\\frac{1}{2} m\\left[\\left(1+a^{2} r^{2}\\right) \\dot{r}^{2}+r^{2} \\dot{\\phi}^{2}\\right]$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+r^{2} \\sin ^{2} \\dot{\\phi}^{2}-g a r^{2}\\right)$\n\t\t\\task[\\textbf{d.}]  $\\frac{1}{2} m\\left[\\left(1+a^{2} r^{2}\\right) \\dot{r}^{2}+r^{2} \\dot{\\phi}^{2}-g a r^{2}\\right]$\n\t\\end{tasks}\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=1.5cm,width=2cm]{CM-04}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tz&=\\frac{1}{2} a\\left(x^{2}+y^{2}\\right)=\\frac{1}{2} a r^{2} \\quad \\Rightarrow \\dot{z}=a r \\dot{r}\\\\\n\t\\text{\tK.E. }&=T=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)\\\\\n\t&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\varphi}^{2}+\\dot{z}^{2}\\right)\\\\\n\t&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\varphi}^{2}+a^{2} r^{2} \\dot{r}^{2}\\right) \\qquad\\text{ P.E.} =V=m g z=\\frac{1}{2} m g a r^{2}\\\\\n\tL&=T-V=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\varphi}^{2}+a^{2} r^{2} \\dot{r}^{2}-g a r^{2}\\right)=\\frac{1}{2} m\\left[\\left(1+a^{2} r^{2}\\right) r^{2}+r^{2} \\dot{\\varphi}^{2}-g a r^{2}\\right]\n\t\t\\end{align*}\n\t\tCorrect answer is option\\textbf{(d)}\n\t\\end{answer}\n\t\\item A mass point glides without friction on a cycloid, which is given by $x=a(\\vartheta-\\sin \\vartheta)$ and $y=a(1+\\cos \\vartheta)$ (with $0 \\leq \\vartheta \\leq 2 \\pi$ ). Determine\\\\\n\t(a) the Lagrangian, and\\\\\n\t(b) the equation of motion\\\\\n\t(c) Solve the equation of motion\n\t\\begin{answer}\n\t\tThe cycloid is represented by\n\t\t\\begin{align*}\n\t\tx=a(\\vartheta-\\sin \\vartheta), \\quad y=a(1+\\cos \\vartheta),\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.2cm,width=9cm]{CM-05}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\\text{\twhere }&0 \\leq \\vartheta \\leq 2 \\pi.\\text{ The kinetic energy is}\\\\\n\t\tT=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)&=\\frac{1}{2} m a^{2}\\left\\{[(1-\\cos \\vartheta) \\dot{\\vartheta}]^{2}+[-(\\sin \\vartheta) \\dot{\\vartheta}]^{2}\\right\\},\\\\\n\t\\text{\tand the potential energy is }V&=m g y=m g a(1+\\cos \\vartheta).\\\\\n\t\t\\text{The Lagrangian is given by }L&=T-V=m a^{2}(1-\\cos \\vartheta) \\dot{\\vartheta}^{2}-m g a(1+\\cos \\vartheta).\\\\\n\t\t\\text{The equation of motion then reads }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\vartheta}}\\right)-\\frac{\\partial L}{\\partial \\vartheta}=0,\\\\\n\t\\text{\ti.e., }\\quad &\\frac{d}{d t}\\left[2 m a^{2}(1-\\cos \\vartheta) \\dot{\\vartheta}\\right]-\\left[m a^{2}(\\sin \\vartheta) \\dot{\\vartheta}^{2}+m g a \\sin \\vartheta\\right]=0\\\\\n\t\\text{ or }\\quad &\\frac{d}{d t}[(1-\\cos \\vartheta) \\dot{\\vartheta}]-\\frac{1}{2}(\\sin \\vartheta) \\dot{\\vartheta}^{2}-\\frac{8}{2 a} \\sin \\vartheta=0,\\\\\n\t\\text{ i.e.,} \\quad&(1-\\cos \\vartheta) \\ddot{\\vartheta}+\\frac{1}{2}(\\sin \\vartheta) \\dot{\\vartheta}^{2}-\\frac{g}{2 a} \\sin \\vartheta=0.\\\\\n\\text{\tBy setting }u&=\\cos \\left(\\frac{\\vartheta}{2}\\right), \\text{one has }\\frac{d u}{d t}=-\\frac{1}{2} \\sin \\left(\\frac{\\vartheta}{2}\\right) \\dot{\\vartheta}\\text{ and } \\frac{d^{2} u}{d t^{2}}\\\\&=-\\frac{1}{2} \\sin \\left(\\frac{\\vartheta}{2}\\right) \\ddot{\\vartheta}-\\frac{1}{4} \\cos \\left(\\frac{\\vartheta}{2}\\right) \\dot{\\vartheta}^{2} .\\\\ \\text{Since }&\\cot \\left(\\frac{\\vartheta}{2}\\right)=\\sin \\frac{\\vartheta}{(1-\\cos \\vartheta)},\\text{ we can write as}\\\\\n\\ddot{\\vartheta}+\\frac{1}{2} \\cot \\left(\\frac{\\vartheta}{2}\\right) \\dot{\\vartheta}^{2}-\\frac{g}{2 a} \\cot \\left(\\frac{\\vartheta}{2}\\right)&=0,\\text{ and therefore,} \\frac{d^{2} u}{d t^{2}}+\\frac{g}{4 a} u=0. \n\\intertext{The solution of this differential equation is}\nu&=\\cos \\left(\\frac{\\vartheta}{2}\\right)=C_{1} \\cos \\sqrt{\\frac{g}{4 a}} t+C_{2} \\sin \\sqrt{\\frac{g}{4 a}} t \n\\intertext{ The motion is just like the vibration of an ordinary pendulum of length $l=4 a$. The arrangement is therefore called a \"cycloid pendulum\".}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \tThree particles of equal mass ' $m$ ' are connected by two identical massless springs of stiffiness constant ' $k$ ' as shown in the figure.\\\\\n\tIf $x_{1}, x_{2}$ and $x_{3}$ denote the displacements of the masses from their respective equilibrium positions, the potential energy of the system is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2} k\\left(x_{1}^{2}+x_{2}^{2}+x_{3}^{2}\\right)$\n\t\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\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\t\\task[\\textbf{d.}] $\\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\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Potential energy }&=\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}\\hspace{2cm}\n\t\t\\text{first spring}\\\\\n\t\\text{\tPotential energy }&=\\frac{1}{2} k\\left(x_{3}-x_{2}\\right)^{2}\\hspace{2cm}\n\t\\text{\tsecond spring}\n\t\\intertext{Potential energy of the system,}\n\t&=\\frac{1}{2} k\\left(x_{2}-x_{1}\\right)^{2}+\\frac{1}{2} k\\left(x_{3}-x_{2}\\right)^{2}=\\frac{1}{2} k\\left[x_{1}^{2}+x_{2}^{2}-2 x_{1} x_{2}+x_{2}^{2}+x_{3}^{2}-2 x_{2} x_{3}\\right]\\\\\n\t&=\\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\t\\end{align*}\n\t\tCorrect answer is option \\textbf{(d)}\n\t\\end{answer}\n\t\\item The Lagrangian of a particle of mass $m$ moving in one dimensions is given by\n\t$$\n\t\\mathrm{L}=\\frac{1}{2} \\mathrm{~m} \\dot{\\mathrm{x}}^{2}-\\mathrm{bx}\n\t$$\n\twhere $b$ is a positive constant. The coordinate of the particle $x(t)$ at time $t$ is given by: (in the following $c_{1}$ and $c_{2}$ are constants)\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-\\frac{b}{2 m} t^{2}+c_{1} t+c_{2}$\n\t\t\\task[\\textbf{b.}]$c_{1} t+c_{2}$\n\t\t\\task[\\textbf{c.}]$c_{1} \\cos \\left(\\frac{b t}{m}\\right)+c_{2} \\sin \\left(\\frac{b t}{m}\\right)$\n\t\t\\task[\\textbf{d.}] $c_{1} \\cosh \\left(\\frac{b t}{m}\\right)+c_{2} \\sin h\\left(\\frac{b t}{m}\\right)$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tL&=\\frac{1}{2} m \\dot{x}^{2}-b x=\\mathrm{T}-\\mathrm{V}\\\\\n\t\t\\therefore \\mathrm{V}&=b x\n\t\t\\intertext{ This is same as uniform gravitational potential. Therefore, solution must be of the form. This is same as uniform} \\mathrm{S}&=\\mathrm{S}_{0}+\\mathrm{ut}+\\frac{1}{2} \\mathrm{at}^{2}\n\t\t\\end{align*}\n\t\tCorrect answer is option \\textbf{(a)}\n\t\\end{answer}\n\t\\item A particle moves in a potential $V=x^{2}+y^{2}+\\frac{z^{2}}{2}$. Which component (s) of the angular momentum is $/$ are constant (s) of motion?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]None\n\t\t\\task[\\textbf{b.}]$L_{x}, L_{y}$ and $L_{z}$\n\t\t\\task[\\textbf{c.}]Only $L_{x}$ and $L_{y}$\n\t\t\\task[\\textbf{d.}] Only $\\mathrm{L}_{z}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Given }V(x, y, z)&=x^{2}+y^{2}+\\frac{z^{2}}{2}\n\t\\intertext{\tIn polar co-ordinate (spherical polar)}\n\tV&=r^{2} \\sin ^{2} \\theta+\\frac{r^{2} \\cos ^{2} \\theta}{2} \\quad\\left[\\begin{array}{l}x=r \\cos \\phi \\sin \\theta \\\\ y=r \\sin \\phi \\sin \\theta \\\\ z=r \\cos \\theta\\end{array}\\right.\n\\intertext{\tTherefore, Lagrangian of system is}\n\t\\mathrm{L}&=\\mathrm{T}-\\mathrm{V} \\\\\n\tL&=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}+r^{2} \\sin ^{2} \\theta \\dot{\\phi}^{2}\\right)-r^{2} \\sin ^{2} \\theta-\\frac{r^{2} \\cos ^{2} \\theta}{2}\n\t\t\\end{align*}\n\t\t$\\phi$ is cyclic, therefore $p_{\\phi}$ is constant of motion.\\\\\n\t\t$p_{\\phi}$ is equal to $L_{z}$. Therefore, $L_{z}$ is constant of motion.\\\\\n\t\tCorrect answer is option \\textbf{(d)}\n\t\\end{answer}\n\t\\item\tA particle of mass $m$ is projected with an initial velocity $u$ at an angle $\\alpha$ with the horizontal. Use Lagran equations to describe the motion of projectile. The resistance of air is negligible.\n\t\\begin{answer}\n\t\t\tLet $x, y$ be the coordinate of the particle at any instant. The system is holonomic because its positic confined to a plane and conservative because the only external force acting on the projectile is conse tive.\n\t\t\\begin{align*}\n\t\tT&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)\\text{ and }V=m g y\\\\\n\t\t\\therefore L&=T-V=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)-m g v\\\\\n\t\t\\frac{\\partial L}{\\partial \\dot{x}}&=m \\dot{x}\\text{ and } \\frac{\\partial L}{\\partial x}=0\\\\\n\t\t\\text{By Lagrange's equation, }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)&=\\frac{\\partial L}{\\partial x}\\\\\n\t\t\\therefore \\quad \\frac{d}{d t}(m \\dot{x})&=0 \\text { or } \\ddot{x} =0 \\\\\n\t\t\\frac{\\partial L}{\\partial \\dot{y}}&=m y \\text { and } \\frac{\\partial L}{\\partial y} =-m g\\\\\n\t\t\\text{By Lagrange's equation }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{y}}\\right)&=\\frac{\\partial L}{\\partial y}\\\\\n\t\t \\therefore \\quad \\frac{d}{d t}(m y)&=-m g\\text{ or }\\ddot{y}=-g\n\t\t \\intertext{Thus, $\\ddot{x}=0, \\ddot{y}=-g$ are the two equations describing the motion of a projectile. Proceeding with the first equation,}\n\t\t \\frac{d}{d t}\\left(\\frac{d x}{d t}\\right)&=0 \\text { or } d\\left(\\frac{d x}{d t}\\right)=0\\\\\n\t\t \\text{Integrating, }\\quad \\frac{d x}{d t}&=c_{1}(\\text{ a constant} )\\\\\n\t\t\\text{ At }t&=0, \\quad \\frac{d x}{d t}=u \\cos \\alpha ; \\quad \\therefore u \\cos \\alpha=c_{1}\\\\\n\t\t\\therefore \\quad \\frac{d x}{d t}&=u \\cos \\alpha, \\quad \\text { or } d x=u \\cos \\alpha d t\\\\\n\t\\text{\tIntegrating, }x&=(u \\cos \\alpha) t+x_{0}(\\text{ a constant })\\\\\n\\text{\tAt $t=0, x=0$, }&\\text{therefore, }x_{0}=0 ; x=(u \\cos \\alpha) t\n \\intertext{Proceeding with the second equation,}\n\t\\frac{d}{d t}\\left(\\frac{d y}{d t}\\right)&=-g, \\text { or } d\\left(\\frac{d y}{d t}\\right)=-g d t\\\\\n\\text{\tIntegrating, }\\frac{d y}{d t}&=-g t+c_{2}(\\mathrm{a}\\text{ constant })\\\\\n\t\\text{At }t&=0, \\frac{d y}{d t}=u \\sin \\alpha ; \\therefore u \\sin \\alpha=c_{2}\\\\\n\t\\therefore \\quad \\frac{d y}{d t}&=-g t+u \\sin \\alpha, o r d y=-g t d t+u \\sin \\alpha d t\\\\\n\\text{\tIntegrating, }y&=-\\frac{1}{2} g t^{2}+(u \\sin \\alpha) t+y_{0}\\\\\n\\text{\tAt }t&=0, y=0\\text{ and therefore, $y_{0}=0$}\\\\\n\t\\therefore \\quad y&=(u \\sin \\alpha) t-\\frac{1}{2} g t^{2}\n\t\t\\end{align*}\n\t\tThus, $x=(u \\cos \\alpha) t, y=(u \\sin \\alpha) t-\\frac{1}{2} g t^{2}$ are the two solved equation describing the motion of a projectile.\n\t\\end{answer}\n\t\\item A particle of mass $m$ is moving in a plane under the influence of a force directed towards a fixed point and varying inversely as the square of the distance from that point. Set up the Lagrangian and equations of motion of the particle.\n\t\\begin{answer}\n\t\tThe problem is best solved in polar coordinates with respect to the fixed point as origin and any line through it as the reference line. Let $(r, \\theta)$ be the polar coordinates of the particle at any time. Since there are two coordinates there will be two Lagrange's equations describing the motion of the particle. Motion is holonomic because the position of the particle is confined to a plane and conservative because the force is derivable from energy or energy is derivable from the force.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.5cm,width=5cm]{CM-06}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tT&=\\frac{1}{2} m \\dot{r}^{2} \\text{(linear kinetic energy)} +\\frac{1}{2} I \\dot{\\theta}^{2} \\text{(rotational $k$. energy)}\\\\\n\t\t\\text{Or, }\\quad T&=\\frac{1}{2} m \\dot{r}^{2}+\\frac{1}{2}\\left(m r^{2}\\right) \\dot{\\theta}^{2} \\quad\\left(\\because I=m r^{2}\\right)\n\t\t\\intertext{Since force varies inversely as the square of the distance and it is directed towards the origin, $F=-\\left(k / r^{2}\\right)$ where $k$ is a constant. But}\n\t\tF&=-\\left(\\frac{d V}{d r}\\right)\\\\\n\t\t\\therefore\\quad&=\\frac{k}{r^{2}}=-\\frac{d V}{d r}\\text{, or } d V=\\frac{k d r}{r^{2}}\\\\\n\t\t\\text{Integrating, }V&=-\\frac{k}{r}+V_{0}\\text{ (a constant)}\\\\\n\t\t\\text{At }r&=\\infty, V=0\\text{ and therefore, }V_{0}=0 ; \\therefore V=-\\left(\\frac{k}{r}\\right)\\\\\n\t\t\\therefore \\quad L&=T-V=\\frac{1}{2} m\\left(\\dot{r}^{2}+r^{2} \\dot{\\theta}^{2}\\right)+\\frac{k}{r}\\\\\n\t\t\\frac{\\partial L}{\\partial \\dot{r}}&=m \\dot{r}\\text{ and }\\frac{\\partial L}{\\partial r}=m r \\dot{\\theta}^{2}-\\frac{k}{r^{2}}\\\\\n\t\t\\frac{\\partial L}{\\partial \\dot{\\theta}}&=m r^{2} \\dot{\\theta}\\text{ and} \\frac{\\partial L}{\\partial \\theta}=0\\\\\n\t\t\\text{By Lagrange's equations of motion, }&\\left[\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial q_{k}}\\right)=\\frac{\\partial L}{\\partial q_{k}}\\right]\\text{ we have }\\\\\n\t\t\\frac{d}{d t}(m \\dot{r})&=m r \\dot{\\theta}^{2}-\\frac{k}{r^{2}}\\text{ and } \\frac{d}{d t}\\left(m r^{2} \\dot{\\theta}\\right)=0\\\\\n\t\t\\text{Or, }\\quad \\ddot{r}&=r \\dot{\\theta}^{2}-\\frac{k}{m r^{2}}\\text{ and} r^{2} \\dot{\\theta}=\\text{ constant}\\\\\n\t\\text{\tOr, }\\quad \\ddot{r}-r \\dot{\\theta}^{2}&=-\\frac{k}{m r^{2}}\\text{ or }\\ddot{r}-r \\dot{\\theta}^{2}=-\\frac{\\omega^{2}}{r^{2}}\\\\\n\\text{\twhere, }\\omega^{2}&=\\frac{k}{m}\\text{ and }r^{2} \\dot{\\theta}=h \\text{(another constant).}\n\\intertext{\tThus equations describing the motion of the particles are} \\ddot{r}-r \\dot{\\theta}^{2}&=-\\frac{\\omega^{2}}{r^{2}}\\text{ and }r^{2} \\dot{\\theta}=h\\text{ where }\\omega^{2}\\text{ and $h$ are constants.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Obtain the Lagrangian of a linear simple harmonic oscillator and the equation of motion in one dimension.\n\t\\begin{answer}\n\t\tIn a simple harmonic oscillator the particle is acted on by a force which is directed towards a fixed point (position of equilibrium) and whose magnitude varies linearly with the distance from the position ofequilibrium. That is, $F=-k x$ where $\\mathrm{x}$ is the distance of the particle from the equilibrium position.\n\t\t\\begin{align*}\n\t\t\\text{But}\n\t\tF&=-\\left(\\frac{d V}{d x}\\right) ; \\quad \\because d V=-F d x=h x d x\\\\\n\t\t\\text{Integrating, }\\quad V&=\\frac{1}{2} k x^{2}+V_{0}(a\\text{ constant })\\\\\n\t\\text{\tAt }x=0, V&=0\\text{ and therefore, }V_{0}=0\\\\\n\t\t\\therefore \\quad V&=\\frac{1}{2} k x^{2} ; \\quad T=\\frac{1}{2} m \\dot{x}^{2}\\\\\n\t\t\\therefore \\quad L&=T-V=\\frac{1}{2} m x^{2}-\\frac{1}{2} k x^{2}\\\\\n\t\\text{\tNow, }\\quad \\frac{\\partial L}{\\partial \\dot{x}}&=m \\dot{x}\\text{ and } \\frac{\\partial L}{\\partial \\dot{x}}=-k x\\\\\n\t\t\\text{By Lagrange's equation, }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)=\\frac{\\partial L}{\\partial x}\\\\\n\t\t\\therefore\\quad\\frac{d}{d t}(m x)&=-k x, \\text { or } m \\ddot{x}=-k x\n\t\t\\intertext{This is the equation of a simple harmonic oscillator in one dimension.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Figure below shows a solid cylinder with centre $G$ and radius $a$ rolling on the rough inside surface of a fixed cylinder with centre $O$ and radius $b>a$. Find the Lagrange equation of motion and deduce the period of small oscillations about the equilibrium position.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=7cm]{Lagrangian 01}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tIf the cylinder were not obliged to roll, the system would have two degrees of freedom with generalised coordinates $\\theta$ (the angle between $O G$ and the downward vertical) and $\\phi$ (the rotation angle of the cylinder measured from some reference position).\\\\\n\t\tThe roling condition imposes the kinematical constraint.\n\t\t\\begin{align*}\n\t\t(b-a) \\dot{\\theta}-a \\dot{\\phi}&=o\n\t\\intertext{\tThis constraint is integrable and is equivalent to the geometrical constraint.}\n\t(b-a) \\theta-a \\phi&=o\n\\intertext{\ton taking $\\phi=0$ when $\\theta=0$. Thus the rolling cylinder is a standard conservative system with one degree of freedom.}\n\\intertext{Take $\\theta$ as the generalised coordinate. Then the kinetic energy is given by}\nT &=\\frac{1}{2} m((b-a) \\dot{\\theta})^{2}+\\frac{1}{2}\\left(\\frac{1}{2} m a^{2}\\right) \\dot{\\phi}^{2} \\\\\n&=\\frac{1}{2} m((b-a) \\dot{\\theta})^{2}+\\frac{1}{2}\\left(\\frac{1}{2} m a^{2}\\right)\\left(\\frac{b-a}{a}\\right)^{2} \\dot{\\theta}=\\frac{3}{4} m(b-a)^{2} \\dot{\\theta}^{2}\\\\\n\\text{and the potential energy by }V&=-m g(b-a) \\cos \\theta\n\\intertext{There is only one Lagrange equation, namely}\n\\frac{d}{d t}\\left[\\frac{3}{2} m(b-a)^{2} \\dot{\\theta}\\right]-0*=-m g(b-a) \\sin \\theta\n\\intertext{which simplifies to give}\n\\ddot{\\theta}+\\frac{2 g}{3(b-a)} \\sin \\theta&=0\n\\intertext{Interestingly, this equation is identical to the exact equation for the oscillations of a simple pendulum of length $3(b-a) / 2$ as obtaind.}\n\\intertext{The linearised equation governing small oscillations of the cylinder about $\\theta=0$ is is}\n\\ddot{\\theta}+\\frac{2 g}{3(b-a)} \\theta&=0\n\\intertext{so that the period $\\tau$ of small oscillation is given by}\n\\tau&=2 \\pi\\left(\\frac{3(b-a)}{2 g}\\right)^{1 / 2}\n\t\t\\end{align*}\n\\end{answer}\n\\item A pendulum of mass $m$ is attached to a block of mass $M$. The block slides on a horizontal frictionless surface. Find the Lagrangian and equation of motion of the pendulum. For small amplitude oscillations, derive an expression for periodic time.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{Lagrangian 02}\n\\end{figure}\n\\begin{answer}\n\t\tLet at any time $t$ the coordinates of $M$ and $m$ be $\\left(x_{1}, 0\\right)$ and $\\left(x_{2}, y_{2}\\right)$ respectively.\n\t\\begin{align}\n\t\\text{Here, }\\quad x_{2}&=x_{1}+\\ell \\sin \\theta\\text{ and }ay_{2}=-\\ell \\cos \\theta.\\text{ The suitable generalized coordinates are $x_{1}$ and $\\theta$.}\\notag\\\\\n\t T &=\\frac{1}{2} M \\dot{x}_{1}^{2}+\\frac{1}{2} m\\left(\\dot{x}_{2}^{2}+\\dot{y}_{2}^{2}\\right) \\notag\\\\ &=\\frac{1}{2} M \\dot{x}_{1}^{2}+\\frac{1}{2} m\\left[\\left(\\dot{x}_{1}+\\ell \\dot{\\theta} \\cos \\theta\\right)^{2}+(\\ell \\dot{\\theta} \\sin \\theta)^{2}\\right] \\notag\\\\ &=\\frac{1}{2} M \\dot{x}_{1}^{2}+\\frac{1}{2} m\\left(\\dot{x}_{1}^{2}+\\ell^{2} \\dot{\\theta}^{2}+2 \\ell \\dot{x}_{1} \\dot{\\theta} \\cos \\theta\\right)\\notag\\\\\n\t (\\text{because }\\dot{x}_{2}&=\\dot{x}_{1}+\\ell \\cos \\theta \\dot{\\theta} \\text{and }\\dot{y}_{2}=\\ell \\sin \\theta \\dot{\\theta} )\\notag\\\\\n\t V&=-m g \\cos \\theta\\notag\\\\\n\t\\text{ Hence, }\\quad L&=T-V=\\frac{1}{2}(M+m) \\dot{x}_{1}^{2}+\\frac{1}{2} m \\ell^{2} \\dot{\\theta}^{2}+m \\ell \\dot{x}_{1} \\dot{\\theta} \\cos \\theta+m g \\ell \\cos \\theta\\notag\n\t\\intertext{We see that $x_{1}$ is cyclic coordinate, so}\\notag\n\t\\text{Here, }\\frac{\\partial L}{\\partial x_{1}}&=0\\text{ and }\\frac{\\partial L}{\\partial \\dot{x}_{1}}=(M+m) \\dot{x}_{1}+m \\ell \\dot{\\theta} \\cos \\theta\\text{ is conserved.}\\notag\\\\\n\t\\frac{\\partial L}{\\partial \\theta}&=m \\ell\\left(\\dot{x}_{1} \\dot{\\theta}+g\\right)(-\\sin \\theta) \\text { and } \\frac{\\partial L}{\\partial \\dot{\\theta}}=m \\ell^{2} \\dot{\\theta}+m \\ell \\dot{x}_{1} \\cos \\theta\\notag\n\\intertext{\tEquation of motion in $\\theta$ is}\\notag\n\tm \\ell^{2} \\ddot{\\theta}&+m \\ell \\ddot{x}_{1} \\cos \\theta+m \\ell(-\\sin \\theta) \\dot{\\theta} \\dot{x}_{1}-m \\ell(-\\sin \\theta) \\dot{x}_{1} \\dot{\\theta}+m g \\ell \\sin \\theta=0\\notag\\\\\n\\text{\tOr, }\\quad m \\ell^{2} \\ddot{\\theta}&+m \\ell \\cos \\theta \\ddot{x}_{1}+m g \\ell \\sin \\theta=0\\notag\\\\\n\t\\text{If }\\theta\\text{ is small, }&\\sin \\theta \\approx \\theta\\text{ and also }\\cos \\theta \\approx 1\\text{, then}\\notag\\\\\n\tm \\ell^{2} \\ddot{\\theta}&+m \\ell \\ddot{x}_{1}+m g \\ell \\theta=0\\notag\\\\\n\\text{\tOr,}\\quad \n\t\\ddot{\\theta}+\\frac{\\ddot{x}_{1}}{\\ell}&+\\frac{g}{\\ell} \\theta=0 \\label{CMP-25}\n\\intertext{\tEquation of motion in $x_{1}$ is}\\notag\n(M+m) \\ddot{x}_{1}&+m \\ell\\left(\\ddot{\\theta} \\cos \\theta-\\dot{\\theta}^{2} \\sin \\theta\\right)=0\\notag\\\\\n\\text{For small }\\theta,&\\left(\\cos \\theta \\cong 1, \\sin \\theta \\cong \\theta\\right.\\text{ and }\\dot{\\theta}^{2} \\theta\\text{ is negligible })\\notag\\\\\n(M+m) \\ddot{x}_{1}&+m \\ell \\ddot{\\theta}=0\\label{CMP-26}\n\\intertext{Fromequations (\\ref{CMP-25}) and (\\ref{CMP-26}), we have}\\notag\n\\ddot{\\theta}-\\frac{m \\ddot{\\theta}}{M+m}&+\\frac{g}{\\ell} \\theta=0\\notag\\\\\n\\text{Hence,}\\quad\n\\ddot{\\theta}&=-\\left[\\frac{M+m}{M}\\right] \\frac{g}{\\ell} \\theta\\notag\n\\intertext{This is the equation of simple harmonic motion whose period is given by}\\notag\nT&=2 \\pi \\sqrt{\\frac{\\ell}{g}} \\sqrt{\\frac{M}{M+m}}\\notag\n\t\\end{align}\n\\end{answer}\n\\item Auniform disc of radius ' $\\dot{a}$ ' and mass $m$, rotates about a fixed axis. A mass less rope is fixed to a points on the out side 'circumference' and leads to mass less spring which is intwin fastened to a fixed point. At a radius $a / 2$ another cord is fastenped to a spring which connects to a $m a, m$. Set up the Lagrange's eq. of the DISC and the mass.\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=6cm,width=5cm]{Lagrangian 03}\n\t\\end{figure}\n\tLet $b_{1}$ and $b_{2}$ be the original length of the spring 1 and 2 . Which the whole system is in eq. and the DISC is stationary.\\\\\n\tLet $\\theta$ be the angle the DISC has twined away from the eq. position. Then extension of the spring $-1$ is\n\t\\begin{align*}\n\tx_{1}&=a \\theta\n\t\\intertext{If the spring $-2$ is stretched by a distance $x_{2}$ the mass $m$ is low ered by a distance}\n\tx_{3}&=\\frac{a}{2} \\theta+x_{2}\\\\\n\tK.E.\\hspace{2cm}\n\t\\mathrm{T}&=\\mathrm{K} \\cdot \\mathrm{E} \\cdot\\text{ of }\\mathrm{DISC}+\\mathrm{K} \\cdot \\mathrm{E} \\cdot\\text{ of mass}\\\\\n\t&=\\frac{1}{2}(\\dot{\\theta})^{2}+\\frac{1}{2} m \\dot{x}_{3}^{2}=\\frac{1}{2} m a^{2} \\cdot \\dot{\\theta}^{2}+\\frac{1}{2} m\\left(\\frac{a}{2} \\dot{\\theta}+\\dot{x}_{2}\\right)^{2}\\\\\n\tP.E.\n\t\\hspace{2cm}V&=\\frac{1}{2} k x_{1}{ }^{2}+\\frac{1}{2} k x_{2}{ }^{2}-m g x_{3} .\n\\intertext{\tHence the Lagrangian for the system is}\n\\mathrm{L}&=\\mathrm{T}-\\mathrm{V} \\\\\n\\mathrm{L}&=\\frac{1}{2} m a^{2} \\dot{\\theta}^{2}+\\frac{1}{2} m\\left(\\frac{a^{2}}{4} \\dot{\\theta}^{2}+a \\dot{\\theta} \\dot{x}_{2}+\\dot{x}_{2}^{2}\\right)-\\frac{1}{2} k x_{1}^{2}-\\frac{1}{2} k x_{2}^{2}+m g\\left(\\frac{a}{2} \\theta+x_{2}\\right)\\\\\n\\text{Lagrangian eq. of motion, }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}_{2}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{2}}\\right)=0 \\Rightarrow \\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\left(\\frac{\\partial L}{\\partial \\theta}\\right)\\\\\n\\text { Or } \\quad \\frac{d}{d t}\\left[\\frac{1}{2} m a \\theta+m \\dot{x}_{2}\\right]&-\\left[-k x_{2}+m g\\right]=0  \\Rightarrow m \\ddot{x}_{2}+k x_{2}+\\frac{1}{2} m(a \\ddot{\\theta}-2 g)=0 \\\\ \n\\text { Or } \\quad \\ddot{x}+\\left(\\frac{k}{m}\\right) x_{2}&+\\frac{1}{2}(a \\ddot{\\theta}-2 g)=0 \\quad  \\Rightarrow \\frac{d}{d t}\\left[\\frac{1}{2} m a^{2} \\dot{\\theta}+\\frac{1}{2} m a^{2}+\\dot{\\theta} \\max _{2}\\right]-\\left[-k a^{2} \\theta+\\frac{m g a}{2}\\right]\\\\\n\\text{Or }\\quad \\frac{3}{4} m a^{2} \\ddot{\\theta}&+R a^{2} \\theta+\\frac{1}{2} m a\\left(\\ddot{x}_{2}-g\\right)=0\\\\\n\\text{Or }\\quad \\ddot{\\theta}&+\\left(\\frac{4}{3} \\frac{k}{m}\\right) \\theta+\\frac{2}{3 a}\\left(\\ddot{x}_{2}-g\\right)=0\n\\intertext{Which are the required equation of motion.}\n\t\\end{align*}\n\\end{answer}\n\\item Set up the lagrangian for the following system, where the pully is massless.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=4cm]{Lagrangian 04}\n\\end{figure}\n\\begin{answer}\n\t\\begin{align*}\n\t\\mathrm{T}&=\\frac{1}{2} m_{1} \\dot{x}_{1}^{2}+\\frac{1}{2} m_{2} \\dot{x}_{2}^{2}\\\\\n\t\\mathrm{~V}&=-m_{1} g x_{1}-m_{2} g x_{2}+\\frac{1}{2} k x_{1}^{2}\\\\\n\t\\mathrm{~L}&=\\frac{1}{2} m_{1} \\dot{x}_{1}^{2}+\\frac{1}{2} m_{2} \\dot{x}_{2}^{2}+m_{1} g x_{1}+m_{2} g x_{2}-\\frac{1}{2} k x_{1}^{2}\\\\\n\t\\text{Thus, equation of motion is }&=\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}_{1}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{1}}\\right)=0\\\\\n\t\\text{And }\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}_{2}}\\right)-\\left(\\frac{\\partial L}{\\partial x_{2}}\\right)=0\\\\\n\t\\Rightarrow \\quad m_{1} \\ddot{x}_{1}-m_{1} g+k x_{1}=0\\\\\n\t\\text{Say, }m_{2} \\ddot{x}_{2}-m_{2} g=0\n\t\\end{align*}\n\\end{answer}\n\\item Set up the lagrangian for the following system, the disk also have mass ' $m$ '.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=6cm,width=2.7cm]{Lagrangian 11}\n\\end{figure}\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=6cm,width=4cm]{Lagrangian 04}\n\t\\end{figure}\n\t\tLet $\\theta$ be the angle one disc has turned away from one equilibrium position. Then extension of the spring $x_{1}=a \\theta$\\\\\n\tMass $m$ is lowered by a distance $x_{2}=\\mathrm{a} \\theta$\n\t\\begin{align*}\n\\therefore \\quad \\mathrm{T} &=\\frac{1}{2} m(a \\dot{\\theta})^{2}+\\frac{1}{2} \\mathrm{I} \\dot{\\theta}^{2} \\\\ \\mathrm{~V} &=-\\mathrm{mga} \\theta+\\frac{1}{2} k \\theta^{2} a^{2} \\\\ \\mathrm{~L} &=\\frac{1}{2} m a^{2} \\dot{\\theta}^{2}+\\frac{1}{4} m a^{2} \\dot{\\theta}^{2}+m g a \\theta-\\frac{1}{2} k a^{2} \\theta^{2} \\\\\n\\text{Eq. of motion is}&\n\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\theta}\\right)-\\frac{\\partial L}{\\partial \\theta}=0\\\\\n\\Rightarrow \\quad &m a^{2} \\ddot{\\theta}+\\frac{1}{2} m a^{2} \\ddot{\\theta}-m g a+k a^{2} \\theta=0\\\\\n\\Rightarrow \\quad &\\frac{3}{2} m a \\ddot{\\theta}-m g+k a \\theta=0\\\\\n\\Rightarrow \\quad &\\ddot{\\theta}-\\frac{2}{3} g / a+\\frac{2}{3}\\left(\\frac{k}{m}\\right) \\theta=0\n\t\\end{align*}\n\\end{answer}\n\\item Two blocks connected by a spring of spring constant $k$ are free to slide frictionlessly along a horizontal surface, as shown in figure. The unstretched length of the spring is $a$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=1cm,width=6cm]{Lagrangian 06}\n\\end{figure}\nTwo masses connected by a spring sliding horizontally along a frictionless surface.\\\\\n(a) Identify a set of generalized coordinates and write the Lagrangian.\n\\begin{answer}\n\tAs generalized coordinates I choose $X$ and $u$, where $X$ is the position of the right edge of the block of mass $M$, and $X+u+a$ is the position of the left edge of the block of mass $m$, where $a$ is the unstretched length of the spring. Thus, the extension of the spring is $u$. The Lagrangian is then\n\t\\begin{align*}\n\tL&=\\frac{1}{2} M \\dot{X}^{2}+\\frac{1}{2} m(\\dot{X}+\\dot{u})^{2}-\\frac{1}{2} k u^{2}=\\frac{1}{2}(M+m) \\dot{X}^{2}+\\frac{1}{2} m \\dot{u}^{2}+m \\dot{X} \\dot{u}-\\frac{1}{2} k u^{2}\\\\\n\t&\\text{(b) Find the equation of motion.}\\\\\n\t&\\text{The canonical momenta are}\\\\\n\tp_{X} &\\equiv \\frac{\\partial L}{\\partial \\dot{X}}=(M+m) \\dot{X}+m \\dot{u}, p_{u} \\equiv \\frac{\\partial L}{\\partial \\dot{u}}=m(\\dot{X}+\\dot{u})\\\\\n\t&\\text{The corresponding equations of motion are then}\\\\\n\t&\\dot{p}_{X}=F_{X}=\\frac{\\partial L}{\\partial X} \\quad \\Rightarrow \\quad(M+m) \\ddot{X}+m \\ddot{u}=0 \\\\\n\t&\\dot{p}_{u}=F_{u}=\\frac{\\partial L}{\\partial u} \\quad \\Rightarrow \\quad m(\\ddot{X}+\\ddot{u})=-k u .\n\t\\end{align*}\n\t(c) Find all conserved quantities.\\\\\n\tThere are two conserved quantities. One is $p_{X}$ itself, as is evident from the fact that $L$ is cyclic in $X$. This is the conserved 'charge' $\\Lambda$ associated with the continuous symmetry $X \\rightarrow X+\\zeta$. i.e. $\\Lambda=p_{X}$. The other conserved quantity is the Hamiltonian $H$, since $L$ is cyclic in $t$. Furthermore, because the kinetic energy is homogeneous of degree two in the generalized velocities, we have that $H=E$, with\n\t\\begin{align*}\n\tE&=T+U=\\frac{1}{2}(M+m) \\dot{X}^{2}+\\frac{1}{2} m \\dot{u}^{2}+m \\dot{X} \\dot{u}+\\frac{1}{2} k u^{2} .\\\\\n\t\\intertext{It is possible to eliminate $\\dot{X}$, using the conservation of $\\Lambda$ :}\n\t\\dot{X}&=\\frac{\\Lambda-m \\dot{u}}{M+m} .\n\t\\intertext{This allows us to write}\n\tE&=\\frac{\\Lambda^{2}}{2(M+m)}+\\frac{M m \\dot{u}^{2}}{2(M+m)}+\\frac{1}{2} k u^{2}\n\t\\end{align*}\n\t(d) Find a complete solution to the equations of motion. As there are two degrees of freedom, your solution should involve 4 constants integration. You need not match initial conditions and you need not choose the quantities in part (c) to be among the constants.\\\\\n\tUsing conservation of $\\Lambda$, we may write $\\ddot{X}$ in terms of $\\ddot{x}$, in which case\n\t\\begin{align*}\n\t\\frac{M m}{M+m} \\ddot{u}&=-k u \\Rightarrow u(t)=A \\cos (\\Omega t)+B \\sin (\\Omega t)\\\\\n\\text{}\\Omega&=\\sqrt{\\frac{(M+m) k}{M m}} .\n\\intertext{\tFor the $X$ motion, we integrate equation above, obtaining}\nX(t)&=X_{0}+\\frac{\\Lambda t}{M+m}-\\frac{m}{M+m}(A \\cos (\\Omega t)-A+B \\sin (\\Omega t))\n\\intertext{There are thus four constant: $X_{0}, \\Lambda, A$ and $B$. Note that conservation of energy says}\nE&=\\frac{\\Lambda^{2}}{2(M+m)}+\\frac{1}{2} k\\left(A^{2}+B^{2}\\right)\n\t\\end{align*}\n\t\\textbf{Alternate solution :} We could choose $X$ as the position of the left block and $x$ as the position of the right block. In this case,\n\t\\begin{align*}\n\tL&=\\frac{1}{2} M \\dot{X}^{2}+\\frac{1}{2} m \\dot{x}^{2}-\\frac{1}{2} k(x-X-b)^{2} .\n\\intertext{\tHere, $b$ includes the unstretched length $a$ of the spring, but may also include the size of the blocks if say, $X$ and $x$ are measured relative to the blocks midpoint. The canonical momenta are}\np_{X}&=\\frac{\\partial L}{\\partial \\dot{X}}=M \\dot{X}, \\quad p_{x}=\\frac{\\partial L}{\\partial \\dot{x}}=m \\dot{x}\n\\intertext{The equation of motion are then}\n\\dot{p}_{X}&=F_{X}=\\frac{\\partial L}{\\partial X} \\quad \\Rightarrow \\quad M \\ddot{X}=k(x-X-b) \\\\\n\\dot{p}_{x}&=F_{x}=\\frac{\\partial L}{\\partial x} \\quad \\Rightarrow \\quad m \\ddot{x}=-k(x-X-b) .\n\\intertext{The one parameter family which leaves $L$ invariant is $X \\rightarrow X+\\zeta$ and $x \\rightarrow x+\\zeta$, i.e. simultaneous and identical displacement of both of the generalized coordinates. Then}\n\\Lambda&=M \\dot{X}+m \\dot{x}\n\\intertext{which is simply the $x$-components of the total momentum. Again, the energy is conserved.}\nE&=\\frac{1}{2} M \\dot{X}^{2}+\\frac{1}{2} m \\dot{x}^{2}+\\frac{1}{2} k(x-X-b)^{2} .\n\\intertext{We can combine the equations of motion to yield}\nM m \\frac{d^{2}}{d t^{2}}(x-X-b)&=-k(M+m)(x-X-b),\n\\intertext{which yields}\nx(t)-X(t)&=b+A \\cos (\\Omega t)+B \\sin (\\Omega t)\n\\intertext{From the conservation of $\\Lambda$, we have}\nM X(t)+m x(t)&=\\Lambda t+C\n\\intertext{where $C$ is another constant. Thus, we have the motion of the system in terms of four constant: $A, B, \\Lambda$ and $C$ }\nX(t)&=-\\frac{m}{M+m}(b+A \\cos (\\Omega t)+B \\sin (\\Omega t))+\\frac{\\Lambda t+C}{M+m}\\\\\nx(t)&=-\\frac{M}{M+m}(b+A \\cos (\\Omega t)+B \\sin (\\Omega t))+\\frac{\\Lambda t+C}{M+m}\n\t\\end{align*}\n\\end{answer}\n\\item A particle of charge $e$ moves in three dimensions in the presence of a uniform magnetic field $B=B_{0} \\hat{z}$ and a uniform electric field $E=E_{0} \\hat{x}$. The potential energy is\n$$\nU(r, \\dot{r})=-e E_{0} x-\\frac{e}{c} B_{0} x \\dot{y},\n$$\nwhere we have chosen the gauge $A=B_{0} x \\hat{y}$.\\\\\n(a) Find the canonical momenta $p_{x}, p_{y}$ and $p_{z}$\\\\\n(b) Identify all conserved quantities\\\\\n(c) Find a complete, general solution for the motion of the system $\\{x(t), y(t), x(t)\\}$.\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{( The Lagrangian is )}L&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)+\\frac{e}{c} B_{0} x \\dot{y}+e E_{0} x. \n\t\\intertext{The canonical momenta are}\n\tp_{x}=\\frac{\\partial L}{\\partial \\dot{x}}&=m \\dot{x} ; \\quad p_{y}=\\frac{\\partial L}{\\partial \\dot{y}}=m \\dot{y}+\\frac{e}{c} B_{0} x ; \\quad p_{x}=\\frac{\\partial L}{\\partial \\dot{z}}=m \\dot{z}\n\\intertext{\t(b) There are three conserved quantities. First is the momentum $p_{y}$, since $F_{y}=\\frac{\\partial L}{\\partial y}=0 .$ Second is the momentum $p_{z}$, since $F_{y}=\\frac{\\partial L}{\\partial z}=0$. The third conserved quantity is the Hamiltonian, since $\\frac{\\partial L}{\\partial t}=0$. We have }\nH&=p_{x} \\dot{x}+p_{y} \\dot{y}+p_{z} \\dot{z}-L\\\\\n\\Rightarrow \\quad H&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)-e E_{0} x\\\\\n\\text{(c) The equations of motion are }\\ddot{x}-\\omega_{c} \\dot{y}&=\\frac{e}{m} E_{0} ; \\ddot{y}+\\omega_{c} \\dot{x}=0 ; \\ddot{z}=0.\n\\intertext{The second equation can be integrated once to yield $\\dot{y}=\\omega_{c}\\left(x_{0}-x\\right)$, where $x_{0}$ is a constant. Substituting this into the first equation gives}\n\\ddot{x}+\\omega_{c}^{2} x&=\\omega_{c}^{2} x_{0}+\\frac{e}{m} E_{0} .\n\\intertext{This is the equation of a constantly forced harmonic oscillator. We can therefore write the generalsolution as}\nx(t)&=x_{0}+\\frac{e E_{0}}{m \\omega_{c}^{2}}+A \\cos \\left(\\omega_{c} t+\\delta\\right) \\\\\ny(t)&=y_{0}-\\frac{e E_{0}}{m \\omega_{c}} t-A \\sin \\left(\\omega_{c} t+\\delta\\right) \\\\\nz(t)&=z_{0}+\\dot{z}_{0} t\n\\intertext{Note that there are six constants, $\\left\\{A, \\delta, x_{0}, y_{0}, z_{0}, \\dot{z}_{0}\\right\\}$, are required for the general solution of three coupled second order ODEs.}\n\t\\end{align*}\n\\end{answer}\n\\item A point mass $m$ slides frictionlessly, under the influence of gravity, along a massive ring of radius $a$ and mass $M$. The ring is affixed by horizontal springs to two fixed vertical surfaces, as depicted in figure. Allmotion is within the plane of the figure.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=2cm,width=6cm]{Lagrangian 07}\n\\end{figure}\nA point mass $m$ slides frictionlessly along a massive ring of radius $a$ and mass $M$, which is affixed by horizontal springs to two fixed vertical surfaces.\n\\begin{answer}\n\t(a) Choose as generalized coordinates the horizontal displacement $X$ of the center of the ring with respect to equilibrium, and the angle $\\theta$ a radius to the mass $m$ makes with respect to the vertical (see figure). You may assume that at $X=0$ the spring are both unstretched. Find the Lagrangian $L(X, \\theta, \\dot{X}, \\dot{\\theta}, t)$.\\\\\n\tThe coordinates of the mass point are $x=X+a \\sin \\theta, y=-a \\cos \\theta$.\\\\\n\tThe kinetic energy is\n\t\\begin{align*}\nT &=\\frac{1}{2} M \\dot{X}^{2}+\\frac{1}{2} m(\\dot{X}+a \\cos \\theta \\dot{\\theta})^{2}+\\frac{1}{2} m a^{2} \\sin ^{2} \\theta \\dot{\\theta}^{2} \\\\ &=\\frac{1}{2}(M+m) \\dot{X}^{2}+\\frac{1}{2} m a^{2} \\dot{\\theta}^{2}+m a \\cos \\theta \\dot{X} \\dot{\\theta} .\\\\\n\\text{The potential energy is }U&=k X^{2}-m g a \\cos \\theta.\\\\\n\\text{Thus, the Lagrangian is}&=\\frac{1}{2}(M+m) \\dot{X}^{2}+\\frac{1}{2} m a^{2} \\dot{\\theta}^{2}+m a \\cos \\theta \\dot{X}-k X^{2}+m g a \\cos \\theta.\n\\intertext{(b) Find the generalized momenta $p_{X}$ and $p_{\\theta}$, and the generalized forces $F_{X}$ and $F_{\\theta}$}\n\\text{We have }p_{X}&=\\frac{\\partial L}{\\partial \\dot{X}}=(M+m) \\dot{X}+m a \\cos \\theta \\dot{\\theta}, p_{\\theta}=\\frac{\\partial L}{\\partial \\dot{\\theta}}=m a^{2} \\dot{\\theta}+m a \\cos \\theta \\dot{X}.\\\\\n\\text{For the forces, }F_{X}&=\\frac{\\partial L}{\\partial X}=-2 k X, \\quad F_{\\theta}=\\frac{\\partial L}{\\partial \\theta}=-m a \\sin \\theta \\dot{X} \\dot{\\theta}-m g a \\sin \\theta.\n\\intertext{(c) Derive the equations o motion.}\n\\text{The equations of motion arc }&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{q}_{\\sigma}}\\right)=\\frac{\\partial L}{\\partial q_{\\sigma}}, \\text{for each generalized coordinate }q_{\\sigma} .\\text{ For $X$ we have }\\\\\n(M+m) \\ddot{X}+m a \\cos \\theta \\ddot{\\theta}-m a \\sin \\theta \\dot{\\theta}^{2}&=-2 k X .\\\\\n\\text{For }\\theta, m a^{2} \\ddot{\\theta}+m a \\cos \\theta \\ddot{X}&=-m g a \\sin \\theta.\n\\intertext{(d) Find expression for all conserved $_{1}$ uantities.}\n\\intertext{Horizontal and vertical translationa $^{1}$ symmetries are broken by the springs and by gravity, respectively. The remaining symmetry is that of time translation. From $\\frac{d H}{d t}=-\\frac{\\partial L}{\\partial t}$, we have that $H=\\sum_{\\sigma} p_{\\sigma} \\dot{q}_{\\sigma}-L$ is conserved. For this problem, the kinetic energy is a homogeneous function of degree 2 in the generalized velocities, and the potential is velocity-independent. Thus,}\nH=T+U&=\\frac{1}{2}(M+m) \\dot{X}^{2}+\\frac{1}{2} m a^{2} \\dot{\\theta}^{2}+m a \\cos \\theta \\dot{X} \\dot{\\theta}+k X^{2}-m g a \\cos \\theta\n\t\\end{align*}\n\\end{answer}\n\\item A point particle of mass $m$ moves in three dimensions in a helical potential\n$$\nU(\\rho, \\phi, z)=U_{0} \\rho \\cos \\left(\\phi-\\frac{2 \\pi z}{b}\\right)\n$$\nWe call $b$ the pitch of the helix.\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{(a) Write down the Lagrangian, choosing $(\\rho, \\phi, z)$ as generalized coordinates.}\n\\text{\tThe Lagrangian is }L&=\\frac{1}{2} m\\left(\\dot{\\rho}^{2}+\\rho^{2} \\dot{\\phi}^{2}+\\dot{z}^{2}\\right)-U_{0} \\rho \\cos \\left(\\phi-\\frac{2 \\pi z}{b}\\right)\n\\intertext{\t(b) Find the equation of motion.}\n\t\\text{Clearly }p_{\\rho}&=m \\dot{\\rho} ; p_{\\phi}=m \\rho^{2} \\dot{\\phi} ; p_{z}=m \\dot{z},\\text{ and}\\\\\n\tF_{\\rho}=m \\rho \\dot{\\phi}^{2}-U_{0} \\cos \\left(\\phi-\\frac{2 \\pi z}{b}\\right), F_{\\phi}&=U_{0} \\rho \\sin \\left(\\phi-\\frac{2 \\pi z}{b}\\right), F_{z}=-\\frac{2 \\pi U_{0}}{b} \\rho \\sin \\left(\\phi-\\frac{2 \\pi z}{b}\\right) \\text {. }\n\\intertext{\tThus, the equation of motion are}\n\tm \\ddot{\\rho}&=m \\rho \\dot{\\phi}^{2}-U_{0} \\cos \\left(\\phi-\\frac{2 \\pi z}{b}\\right) \\\\\n\tm \\rho^{2} \\ddot{\\phi}+2 m \\rho \\dot{\\rho} \\dot{\\phi}&=U_{0} \\rho \\sin \\left(\\phi-\\frac{2 \\pi z}{b}\\right)\\\\\n\tm \\ddot{z}&=-\\frac{2 \\pi U_{0}}{b} \\rho \\sin \\left(\\phi-\\frac{2 \\pi z}{b}\\right)\n\t\\intertext{(c) Show that there exists a continuous one-parameter family of coordinate transformations which leaves $L$ invariant. Find the associated conserved quantity, $\\Lambda$. Is anything else conserved?}\n\t\\intertext{Due to the helical symmetry, we have that $\\phi \\rightarrow \\phi+\\zeta, z \\rightarrow z+\\frac{b}{2 \\pi} \\zeta$ is such a continuous one-parameter}\n\t\\intertext{family of coordinate transformations. Since it leaves the combination $\\phi-\\frac{2 \\pi z}{\\dot{b}}$ unchanged, we have that $\\frac{d L}{d \\zeta}=0$, and}\n\\Lambda &=\\left.p_{\\rho} \\frac{\\partial \\rho}{\\partial \\zeta}\\right|_{\\zeta=0}+\\left.p_{\\phi} \\frac{\\partial \\phi}{\\partial \\zeta}\\right|_{\\zeta=0}+\\left.p_{z} \\frac{\\partial z}{\\partial \\zeta}\\right|_{\\zeta=0} \\\\ &=p_{\\phi}+\\frac{b}{2 \\pi} p_{z} \\\\ &=m \\rho^{2} \\dot{\\phi}+\\frac{m b}{2 \\pi} \\dot{z}\n\\intertext{is the conserved Noether 'charge'. The other conserved quantity is the Hamiltonian,}\nH&=\\frac{1}{2} m\\left(\\dot{\\rho}^{2}+\\rho^{2} \\dot{\\phi}^{2}+\\dot{z}^{2}\\right)+U_{0} \\rho \\cos \\left(\\phi-\\frac{2 \\pi z}{b}\\right)\n\\intertext{Note that $H=T+U$ because $T$ is homogeneous of degree 2 and $U$ is homogeneous of degree 0 in the generalized velocities.} \n\t\\end{align*}\n\\end{answer}\n\\textbf{Statement for Linked Answer Q.12 and Q.13 :}\\\\\nA particle of mass $m$ is constrained to move in a vertical plane along a trajectory given by $x=\\mathrm{A} \\cos \\theta$, $y=\\mathrm{A} \\sin \\theta$, where $\\mathrm{A}$ is a constant.\n\\item The Lagrangian of the particle is\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{1}{2} m \\mathrm{~A}^{2} \\dot{\\theta}^{2}-m g \\mathrm{~A} \\cos \\theta$\n\t\\task[\\textbf{b.}]$\\frac{1}{2} m \\mathrm{~A}^{2} \\dot{\\theta}^{2}-m g \\mathrm{~A} \\sin \\theta$\n\t\\task[\\textbf{c.}] $\\frac{1}{2} m \\mathrm{~A}^{2} \\dot{\\theta}^{2}$\n\t\\task[\\textbf{d.}] $\\frac{1}{2} m \\mathrm{~A}^{2} \\dot{\\theta}^{2}+m g \\mathrm{~A} \\cos \\theta$\n\\end{tasks}\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.2cm,width=4.5cm]{Lagrangian 08}\n\t\\end{figure}\n\t\\begin{align*}\n\tL&=T-V\\\\\n\tL&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}\\right)-m g y^{x}\\\\\n\tx&=A \\cos \\theta, \\quad y=A \\sin \\theta\\\\\n\t\\dot{x}&=-A \\sin \\theta \\dot{\\theta}, \\quad \\dot{y}=A \\cos \\theta \\dot{\\theta}\\\\\n\t \\therefore \\quad L &=\\frac{1}{2} m\\left(A^{2} \\sin ^{2} \\theta \\dot{\\theta}^{2}+A^{2} \\cos ^{2} \\theta \\dot{\\theta}^{2}\\right)-m g A \\cos \\theta \\\\ L &=\\frac{1}{2} m A^{2} \\dot{\\theta}^{2}-m g A \\cos \\theta \n\t\\end{align*}\n\t Correct answer is option \\textbf{(a)}\n\\end{answer}\n\\item The equation of motion of the particle is\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\ddot{\\theta}-\\frac{g}{\\mathrm{~A}} \\cos \\theta=0$\n\t\\task[\\textbf{b.}]$\\ddot{\\theta}+\\frac{g}{\\mathrm{~A}} \\sin \\theta=0$\n\t\\task[\\textbf{c.}] $\\ddot{\\theta}=0$\n\t\\task[\\textbf{d.}]  $\\ddot{\\theta}-\\frac{g}{\\mathrm{~A}} \\sin \\theta=0$\n\\end{tasks}\n\\begin{answer}\n\tEquation of motion\n\t\\begin{align*}\n\t\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{\\theta}}\\right)-\\frac{\\partial L}{\\partial \\theta}&=0\\\\\n\t\\frac{d}{d t}\\left(m A^{2} \\dot{\\theta}\\right)-m g A \\sin \\theta&=0\\\\\n\tm A^{2} \\ddot{\\theta}-m g A \\sin \\theta&=0\\\\\n\t\\ddot{\\theta}-\\frac{g}{A} \\sin \\theta&=0\n\t\\end{align*}\n\tCorrect answer is option \\textbf{(d)}\n\\end{answer}\n\\item A particle of mass $M$ is attached to two identical springs of unstretched length $L_{0}$ and spring constant $k$. The entire system is placed on a horizontal frictionless table as shown in the figure. The mass is slightly puled along the surface of the table and perpendicular to the lengths of the springs and then let go. Using the Lagrangian equation (s) of motion, show whether the mass will execute simple harmonic motion. If so, find the time period.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=2.5cm,width=7cm]{Lagrangian 09}\n\\end{figure}\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=2.5cm,width=6cm]{Lagrangian 10}\n\t\\end{figure}\n\t\\begin{align*}\n\\text{\tKinetic energy }T&=\\frac{1}{2} m \\dot{x}^{2}\\\\\n\\text{\tpotential energy }V&=\\frac{1}{2} k\\left(\\sqrt{\\ell_{0}^{2}+x^{2}}-\\ell_{0}\\right)^{2}\n\\intertext{Number gravitational potential energy term because motion is taking place in horizontal plane.}\n\\text{Lagrangian }L&=T-V=\\frac{1}{2} m \\dot{x}^{2}-\\frac{1}{2} k\\left(\\sqrt{\\ell_{0}^{2}+x^{2}}-\\ell_{0}\\right)^{2}\n\\intertext{Lagrange's equation}\n&\\frac{d}{d t}\\left(\\frac{\\partial L}{\\partial \\dot{x}}\\right)-\\frac{\\partial L}{\\partial x}=0 \\\\\n&m \\ddot{x}+2 k\\left(\\sqrt{\\ell_{0}^{2}+x^{2}}-\\ell_{0}\\right) \\frac{x}{\\sqrt{\\ell_{0}^{2}+x^{2}}}=0 \\\\\n&m \\ddot{x}+2 k x\\left(1-\\frac{\\ell_{0}}{\\sqrt{\\ell_{0}^{2}+x^{2}}}\\right)=0\\\\\n\\text{for }&x<<\\ell_{0} \\quad m \\ddot{x}+2 k x\\left(1-\\left(1+\\frac{x^{2}}{\\ell_{0}^{2}}\\right)^{-1 / 2}\\right)=0\\\\\nm \\ddot{x}+2 k x\\left(1-1+\\frac{x^{2}}{2 \\ell_{0}^{2}}\\right)&=0 \\Rightarrow m \\ddot{x}+\\frac{k x^{3}}{\\ell_{0}^{2}}=0 \\ddot{x} \\alpha-x^{3}\n\\intertext{Motion is not simple harmonic.}\n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}\n\\section{Hamiltonian Mechanics}\n\\begin{enumerate}\n\t\\item Show that $\\frac{d H}{d t}=\\frac{\\partial H}{\\partial t}$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Since }H&=H\\left(q_{j}, p_{j}, t\\right)\\\\\n\t\t\\therefore \\quad \\frac{d H}{d t} & =\\frac{\\partial H}{\\partial t}+\\sum_{j} \\frac{\\partial H}{\\partial q_{j}}+\\sum_{j} \\frac{\\partial H}{\\partial p_{j}} \\dot{p}_{j} \\Rightarrow \\frac{d H}{d t}=\\frac{\\partial H}{\\partial t}+\\sum_{j}\\left(-\\dot{p}_{j} \\dot{q}_{j}\\right)+\\sum_{k}\\left(\\dot{q}_{j} \\dot{p}_{j}\\right) \\\\\n\t\t\\therefore \\quad \\frac{d H}{d t} & =\\frac{\\partial H}{\\partial t}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Obtain the Hamiltonian function of a compound pendulum and hence obtain the equation describing its motion.\n\t\\begin{answer}\n\t\tThe pendulum is a harmonic conservative system. It is holonomic because the constraint is on the position of the pendulum in the sense that it must vibrate in its own plane and conservative because the gravitational force acting on it is conservative. With reference to a frame fixed at the point of suspension with downward vertical as the reference line, we have\n\t\t\\begin{align*}\n\t\tT&=\\frac{1}{2} I \\dot{\\theta}^{2}\n\t\\intertext{\twhere $I$ is the moment of inertia of the pendulum about the axis passing through the point suspension and perpendicular to its plane.}\n\t\tV&=-m g \\ell \\cos \\theta\n\t\\intertext{\twhere $\\ell$ is the distance of the centre of gravity from the centre of suspension.}\n\\therefore & H=T+V=\\frac{1}{2} I \\dot{\\theta}^{2}-m g \\ell \\cos \\theta \\\\ \\text { Now, } & p_{\\theta}=\\frac{\\partial T}{\\partial \\dot{\\theta}}=I \\dot{\\theta} \\\\ \\therefore & H=\\frac{1}{2} I \\frac{p_{\\theta}^{2}}{I^{2}}-m g \\ell \\cos \\theta \\\\ \\text { Or, } & H=\\frac{p_{\\theta}^{2}}{I^{2}}-m g \\ell \\cos \\theta \\\\ & \\frac{\\partial H}{\\partial p_{\\theta}}=\\frac{p_{\\theta}}{I} \\text { and } \\frac{\\partial H}{\\partial p_{\\theta}}=-m g \\ell(-\\sin \\theta)=m g \\ell \\sin \\theta\\\\\n\\text{By Hamilton's general equations }&\\left(\\dot{p}_{k}=-\\frac{\\partial H}{\\partial q_{k}}\\right.\\text{ and }\n\\left.\\dot{q}_{k}=\\frac{\\partial H}{\\partial p_{k}}\\right)\\\\\n\\text{We have here }\\dot{p}_{\\theta}&=-\\frac{\\partial H}{\\partial \\theta}=-m g \\ell \\sin \\theta\\text{ and }\\dot{\\theta}=\\frac{\\partial H}{\\partial p_{\\theta}}=\\frac{p_{\\theta}}{I}\n\\intertext{These are the two equations describing the motion of a compound pendulum. However, these two equaions can be combined into a signle equation. Differentiating the second equation and eliminating $\\dot{p}_{\\theta}$,}\n\\intertext{we have}\n\\ddot{\\theta}&=\\frac{\\dot{p}_{\\theta}}{I} \\sin \\theta ; \\text { or } \\ddot{\\theta}+\\frac{m g I}{I} \\sin \\theta=0\n\\intertext{This is the required single equation that describes the motion of a compound pendulum.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A particle moves in the $x y$ plane under the influence of a central force depending on its distance from the origin.\\\\\n\t(a) Set up the Hamiltonian for the system\\\\\n\t(b) Obtain Hamilton's equations of motion\n\t\\begin{answer}\n\t\\begin{align}\n\t\\text{(a) }T \\text{(kinetic energy of of the particle) }&=\\frac{1}{2 m \\dot{r}^{2}}+\\frac{1}{2} I \\dot{\\theta}^{2}=\\frac{1}{2} m \\dot{r}^{2}+\\frac{1}{2} m r^{2} \\dot{\\theta}^{2}\\quad\n\t\\left(\\because I=m r^{2}\\right)\\notag\\\\\n\\therefore & H=T+V=\\frac{1}{2} m \\dot{r}^{2}+\\frac{1}{2} m r^{2} \\dot{\\theta}^{2}+V(r)\\notag \\\\ \\text { Now, } & p_{r}=\\frac{\\partial T}{\\partial \\dot{r}}=m \\dot{r} \\text { and } p_{\\theta}=\\frac{\\partial T}{\\partial \\dot{\\theta}}=I \\dot{\\theta}=m r^{2} \\dot{\\theta} \\notag\\\\ \\therefore & H=\\frac{1}{2} m \\cdot \\frac{p_{r}^{2}}{m^{2}}+\\frac{1}{2} m r^{2} \\frac{p_{\\theta}^{2}}{m^{2} r^{4}}+V(r) \\notag\\\\ \\text { Or, } & H=\\frac{p_{r}^{2}}{2 m}+\\frac{p_{\\theta}^{2}}{2 m r^{2}}+V(r)\\notag\n\\intertext{(b) We have from Hamilton's equation,}\n&\\left(\\dot{p}_{k}=-\\frac{\\partial H}{\\partial q_{k}} \\text { and } \\dot{q}_{k}=\\frac{\\partial H}{\\partial p_{k}}\\right) \\notag\\\\\n&\\dot{p}_{r}=-\\frac{\\partial H}{\\partial r}=-\\left(-\\frac{p_{\\theta}^{2}}{m r^{3}}+\\frac{\\partial V}{\\partial r}\\right)=\\frac{p_{\\theta}^{2}}{m r^{3}}-\\frac{\\partial V}{\\partial r} \\label{HM-29}\\\\\n&\\dot{r}=\\frac{\\partial H}{\\partial p_{r}}=\\frac{p_{r}}{m} \\label{HM-30}\\\\\n&\\dot{p}_{\\theta}=-\\frac{\\partial H}{\\partial \\theta}=0 \\label{HM-31}\\\\\n&\\dot{\\theta}=\\frac{\\partial H}{\\partial p_{\\theta}}=\\frac{p_{\\theta}}{m r^{2}}\\label{HM-32}\n\\intertext{Equations (\\ref{HM-29}), (\\ref{HM-30}), (\\ref{HM-31}) and (\\ref{HM-32}) are the required Hamilton's equations. However they can be combined to reduce the number of equations describing the motion. Equations (\\ref{HM-29}) and (\\ref{HM-30}) combine into (after elimination of $\\dot{p}_{r}$ )}\\notag\n\\ddot{r}&=\\frac{p_{\\theta}^{2}}{m^{2} r^{3}}-\\frac{1}{m} \\frac{\\partial V}{\\partial r}=\\frac{m^{2} r^{4} \\dot{\\theta}^{2}}{m^{2} r^{2}}-\\frac{1}{m} \\frac{\\partial V}{\\partial r}\\notag\n\\intertext{and (\\ref{HM-31}) and (\\ref{HM-32}) combine into (after elimination of $\\dot{p}_{\\theta}$ ) $\\ddot{\\theta}=0$ Thus the equations describing motion of the particle are}\n\\ddot{r}-r \\dot{\\theta}^{2}&=-\\frac{1}{m} \\frac{\\partial V}{\\partial r} \\text { and } \\ddot{\\theta}=0\\notag\\\\\n\\text{Or, }\\quad \\ddot{r}-r \\dot{\\theta}^{2}&=-\\frac{1}{m} \\frac{\\partial V}{\\partial r}\\text{ and }\\dot{\\theta}=\\frac{p_{\\theta}}{m r^{2}}=\\frac{a \\text { constant }}{m r^{2}}\\notag\\\\\n\\quad\\left(\\because p_{\\theta}=a\\right.&\\text{ constant from }\\left.(i i i)\\right)\\text{\n\tOr, }\\quad m r^{2} \\dot{\\theta}=a\\text{ constant}\\notag\n\t\\end{align}\n\t\\end{answer}\n\t\\item The Hamiltonian of a simple pendulum consisting of a mass ' $\\mathrm{m}$ ' attached to a massless string of length $l$ is $\\mathrm{H}=\\frac{\\mathrm{p}_{\\theta}^{2}}{2 \\mathrm{~m} \\ell^{2}}+\\mathrm{mg} \\ell(1-\\cos \\theta)$. If L denotes the Lagrangian, the value of $\\frac{\\mathrm{dL}}{\\mathrm{dt}}$ is :\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-\\frac{2 g}{\\ell} p_{\\theta} \\sin \\theta$\n\t\t\\task[\\textbf{b.}]$-\\frac{\\mathrm{g}}{\\ell} \\mathrm{p}_{\\theta} \\sin 2 \\theta$\n\t\t\\task[\\textbf{c.}] $\\frac{\\mathrm{g}}{\\ell} \\mathrm{p}_{\\theta} \\cos \\theta$\n\t\t\\task[\\textbf{d.}] $\\ell \\mathrm{p}_{\\theta}^{2} \\cos \\theta$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathrm{H}&=\\frac{\\mathrm{p}_{\\theta}^{2}}{2 \\mathrm{~m} \\ell^{2}}+\\mathrm{mg} \\ell(1-\\cos \\theta) \\Rightarrow \\mathrm{L}=\\sum_{\\mathrm{i}} \\mathrm{p}_{\\mathrm{i}} \\dot{\\mathrm{q}}_{\\mathrm{i}}-\\mathrm{H}=\\mathrm{p}_{\\theta} \\dot{\\theta}-\\mathrm{H}\\\\\n\t\t\\dot{\\theta}&=\\frac{\\partial \\mathrm{H}}{\\partial \\mathrm{p}_{\\theta}}=\\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}}\\text{ and }\\dot{\\mathrm{p}}_{\\theta}=-\\frac{\\partial \\mathrm{H}}{\\partial \\theta}=-\\mathrm{mg} \\ell \\sin \\theta\\\\\n\t\t\\text{Therefore, }\\mathrm{L}&=\\mathrm{p}_{\\theta} \\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}}-\\left[\\frac{\\mathrm{p}_{\\theta}^{2}}{2 \\mathrm{~m} \\ell^{2}}+\\mathrm{mg} \\ell(1-\\cos \\theta)\\right] \\Rightarrow \\mathrm{L}=\\frac{\\mathrm{p}_{\\theta}^{2}}{2 \\mathrm{~m} \\ell^{2}}-\\mathrm{mg} \\ell(1-\\cos \\theta)\\\\\n\t\t\\text{Since, }L&=L\\left(\\theta, p_{\\theta}\\right)\\text{Since, }\n\t\t -\\frac{L}{1}=\\frac{\\partial L}{\\partial p_{\\theta}} \\dot{p}_{\\theta}+\\frac{\\partial L}{\\partial \\theta} \\dot{\\theta}\\\\\n\t\t \\text{Now, }\\frac{\\partial \\mathrm{L}}{\\partial \\mathrm{p}_{\\theta}}&=\\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}}, \\quad \\dot{\\mathrm{p}}_{\\theta}=-1.1 \\mathrm{~g} \\ell \\sin \\theta, \\quad \\frac{\\partial \\mathrm{L}}{\\partial \\theta}=-\\mathrm{mg} \\ell \\sin \\theta, \\quad \\dot{\\theta}=\\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}} \\\\\n\t\t \\text{Then} \\frac{\\mathrm{dL}}{\\mathrm{dt}}&=\\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}}(-\\mathrm{mg} \\ell \\sin \\theta)-\\mathrm{mg} \\ell \\quad \\mathrm{n} \\theta \\frac{\\mathrm{p}_{\\theta}}{\\mathrm{m} \\ell^{2}}=-\\frac{2 \\mathrm{~g}}{\\ell} \\mathrm{p}_{\\theta} \\sin \\theta\n\t\t\\end{align*}\n\t\tCorrect option is \\textbf{(a)}\n\t\\end{answer}\n\t\\item The particel of mass $m$ is constrained to move on the surface of a cylinder of radius $a$ under an attractive central force $F$, given by\n\t$$\n\tF=-k r\n\t$$\n\twhere $k$ is the force constant. This force is proportional to the distance of the particle from the origin\n\\begin{answer}\n\t\tThe motion of the particle can be described in terms of the cartesian coordinates $\\mathrm{x}, \\mathrm{y}, \\mathrm{z}$ or cylindrical $\\rho, \\theta, z$ (See figure). The equation of constraint is\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=7cm,width=4.5cm]{Lagrangian 12}\n\t\t\\end{figure}\n\t\\begin{align}\n\t\\rho^{2}&=x^{2}+y^{2}=a^{2}\\label{HM-33-}\n\\intertext{\tTo find velocity in cylinderical coordinates, we can proceed as follows}\\notag\n\\text{The change in position along }\\rho&=d \\rho\\notag\\\\\n\\text{The change in position along }\\theta&=\\rho d \\theta\\notag\\\\\n\\text{The change in position along }z&=d z\n\\text{So, }v_{\\rho}=\\dot{\\rho}, v_{\\theta}=\\rho \\dot{\\theta}\\text{and} v_{z}=\\dot{z}\\notag\\\\\n\\text{So, we have }v^{2}&=v_{\\rho}^{2}+v_{\\theta}^{2}+v_{z}^{2}.\\notag\\\\\n\\text{The kinetic energy, }T&=\\frac{1}{2} m v^{2}=\\frac{1}{2}\\left(\\dot{\\rho}^{2}+\\rho^{2} \\dot{\\theta}^{2}+\\dot{z}^{2}\\right)\\notag\\\\\n\\text{Here, }\\rho&=a\\notag\\\\\n\\text{Therefore, }\\dot{\\rho}&=0,\\text{ and hence,}\\notag\\\\\nT &=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+\\dot{z}^{2}\\right) \\notag\\\\ \\text{and}\\quad V &=\\frac{1}{2} k r^{2}=\\frac{1}{2} k\\left(x^{2}+y^{2}+z^{2}\\right)=\\frac{1}{2} k\\left(a^{2}+z^{2}\\right)\\notag\\\\\n\\therefore \\quad L=T-V&=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}^{2}+\\dot{z}^{2}\\right)-\\frac{1}{2} k\\left(a^{2}+z^{2}\\right)\\label{HM-34-}\\\\\n\\text{Hence,}\np_{\\theta}&=\\frac{\\partial L}{\\partial \\dot{\\theta}}=m a^{2} \\dot{\\theta}\\text{ or} \\dot{\\theta}=\\frac{p_{\\theta}}{m a^{2}}\\notag\\\\\n\\text{and }\\quad p_{z}&=\\frac{\\partial L}{\\partial \\dot{z}}=m \\dot{z}\\text{ or} \\dot{z}=\\frac{p_{z}}{m}\\notag\\\\\n\\text{Therefore, }\\quad H&=T+V=\\frac{1}{2} m\\left(a^{2} \\dot{\\theta}+\\dot{z}^{2}\\right)+\\frac{1}{2} k\\left(a^{2}+z^{2}\\right)\\notag\\\\\n\\text { Or, } \\quad H&=\\frac{p_{\\theta}^{2}}{2 m a^{2}}+\\frac{p_{z}^{2}}{m}+\\frac{1}{2} k\\left(a^{2}+z^{2}\\right)\\label{HM-35-}\n\\intertext{Hence, the Hamilton's equation are}\\notag\\\\\n\\dot{z}&=\\frac{\\partial H}{\\partial p_{z}}=\\frac{p_{z}}{m}\\text{ or }p_{z}=m \\dot{z}\\label{HM-36-}\\\\\n\\dot{\\theta}&=\\frac{\\partial H}{\\partial p_{\\theta}}=\\frac{p_{\\theta}}{m a^{2}}\\text{ or }p_{\\theta}=m a^{2} \\dot{\\theta}\\label{HM-37-}\\\\\n-\\dot{p}_{z}&=\\frac{\\partial H}{\\partial z}=k z \\quad\\text{ or }\\quad \\dot{\\mathrm{p}}_{z}=-k z\\label{HM-38-}\\\\\n-\\dot{p}_{\\theta}&=\\frac{\\partial H}{\\partial \\theta}=0 \\quad\\text{ or }\np_{\\theta}= \\text{constant}\\label{HM-39-}\n\\intertext{From equation (\\ref{HM-36-}) and (\\ref{HM-38-}), we get}\nm \\ddot{z}+k z&=0\\notag\n\\intertext{which shows that the motion of the particle in z direction is simple harmonic with period $T$, given by}\\notag\nT&=2 \\pi \\sqrt{\\frac{m}{k}}\\notag\n\\intertext{From equation (\\ref{HM-37-}) and (\\ref{HM-39-}), we get}\\notag\np_{\\theta}&=m a^{2} \\dot{\\theta}=\\text { constant }\\notag\n\\intertext{Thus the angular momentum about Z-axis is a constant of motion.}\\notag\n\t\\end{align}\n\\end{answer}\n\t\\item Find equations of motion of particle moving near the surface of earth.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{Let us consider z-axis along upward vertical direction, the kinetic energy is}\n\t\tT&=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)\n\t\\intertext{\tFurther the applied force on the body is its weight acting in negative z-direction, i.e.,}\n\t\tF&=F_{z}-m g=-\\frac{\\partial V}{\\partial Z}\n\t\t\\intertext{This gives $V=m g Z$, on setting additive constant to zero Now} \n\t\\intertext{\tLagrangian is}\n\t\tL&=T-V=\\frac{1}{2} m\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)-m g Z\\\\\n\t\t\\text{So that }\\frac{\\partial L}{\\partial \\dot{x}}&=\\frac{\\partial T}{\\partial \\dot{x}}=p_{x}=m \\dot{x}\\text{ giving }\\dot{x}=\\frac{p_{x}}{m}\\\\\n\t\\text{\tAlso, }p_{y}&=m \\dot{y}, p_{z}=m \\dot{z}\\\\\n\t\t\\therefore \\quad \\dot{y}&=\\frac{p_{y}}{m}, \\dot{z}=\\frac{p_{z}}{m}\\\\\n\t\\intertext{\tHamiltonian for such a system is conserved, i.e.,}\n\t\tH&=T+V=\\frac{1}{2}\\left(\\dot{x}^{2}+\\dot{y}^{2}+\\dot{z}^{2}\\right)+m g Z=\\frac{1}{2 m}\\left(p_{x}^{2}+p_{y}^{2}+p_{z}^{2}\\right)+m g Z \\\\\n\t\t\\intertext { giving equations of motion }\n\t\t\\dot{p}_{x}&=-\\frac{\\partial H}{\\partial x}=0, \\quad \\dot{p}_{y}=-\\frac{\\partial H}{\\partial y}=0\\\\\n\t\t\\dot{p}_{z}&=-\\frac{\\partial H}{\\partial Z}=-m g\\\\\n\t\t\\therefore \\quad \\dot{x}&=\\frac{\\partial H}{\\partial p_{x}}=\\frac{p_{x}}{m}, \\quad \\dot{y}=\\frac{\\partial H}{\\partial p_{y}}=\\frac{p_{y}}{m}, \\dot{z}=\\frac{\\partial H}{\\partial Z}=\\frac{p_{z}}{m}\n\t\\intertext{ so we finally get,}\n\t\t\\ddot{x}&=\\frac{\\dot{p}_{y}}{m}=0, \\quad \\ddot{y}=\\frac{\\dot{p}_{y}}{m}=0, \\quad \\ddot{z}=\\frac{\\dot{p}_{z}}{m}=-g\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A mechanical system is described by the Hamiltonian $H(q, p)=\\frac{p^{2}}{2 m}+\\frac{1}{2} m \\omega^{2} q^{2}$. As a result of the canonical transformation generated by $F(q, Q)=-\\frac{Q}{q}$, the Hamiltonian in the new coordinate $Q$ and momentum $P$ becomes\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{2 m} Q^{2} P^{2}+\\frac{m \\omega^{2}}{2} Q^{2}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{2 m} Q^{2} P^{2}+\\frac{m \\omega^{2}}{2} P^{2}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{2 m} P^{2}+\\frac{m \\omega^{2}}{2} Q^{2}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{2 m} Q^{2} P^{4}+\\frac{m \\omega^{2}}{2} P^{-2}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tF(q, Q)&=-\\frac{Q}{q}\n\t\\intertext{\tDifferential relation for $F(q, Q)$}\n\t\tp&=\\frac{\\partial F}{\\partial q}, \\quad P=-\\frac{\\partial F}{\\partial Q}\\\\\n\t\t\\text{So, }\\quad p&=\\frac{Q}{q^{2}}, P=\\frac{1}{q} \\quad \\Rightarrow p=Q P^{2}\n\t\\intertext{\tNew Hamiltonian,}\n\t\tH^{\\prime}&=H+\\frac{\\partial F}{\\partial t}=H+0\\\\\n\t\tH^{\\prime}(Q, P)&=H(q, p)=\\frac{p^{2}}{2 m}+\\frac{1}{2} m \\omega^{2} q^{2}=\\frac{1}{2 m} Q^{2} P^{4}+\\frac{1}{2} m \\omega^{2} P^{-2}\n\t\t\\end{align*}\n\t\tCorrect answer is option \\textbf{(d)}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Small Oscillations}\n\\begin{enumerate}\n\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\\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\\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\\text{So, the frequency }v&=\\frac{\\omega}{2 \\pi}=\\frac{1}{\\pi \\ell} \\sqrt{\\frac{a}{m}}\n\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\t\\begin{answer}\n\t\t\\begin{align*}\n\t\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\t\\text{and }\\frac{\\partial^{2} V}{\\partial z^{2}}&=4>0\\text{ for all $z$}\n\t\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\t\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\\text{\t\tbecause}\\quad\n\t\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\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\\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\\intertext{So, the frequencies are $\\omega \\sqrt{2}, \\omega \\sqrt{2}$ and $2 \\omega$}\n\\intertext{\tNote that frequencies are always positive, hence we shouldn't write $\\Omega_{1}=\\pm \\omega \\sqrt{2}$ etc.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \\textbf{Coupled mass point on a circle:}\\\\\n\tFour mass points of mass $m$ move on a circle of radius $R$. Each mass point is coupled to its two neighboring points by a spring with spring constant $k$ (see figure below). Find the Lagrangian of the system and derive the equations of motion of the system. Calculate the eigenfrequencies of the system, and discuss the related eigenvibrations.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\intertext{\tThe kinetic energy of the system is given by}\n\t\tT&=\\frac{1}{2} m \\sum_{v=1}^{4} \\dot{s}_{v}^{2}\n\t\\intertext{\tFor small displacement from the equilibrium position, the potential reads}\n\t\tV&=\\frac{1}{2} k \\sum_{v=1}^{4}\\left(s_{v+1}-s_{v}\\right)^{2}, \\quad s_{4+1}=s_{1}\n\t\\intertext{\tWe set $s_{v}=R \\varphi_{v}$, and take the angles $\\varphi_{v}$ as generalized coordinates. Then the Lagrangian is}\n\t\tL&=T-V=\\frac{1}{2} m R^{2} \\sum_{v=1}^{4} \\dot{\\varphi}_{v}^{2}-\\frac{1}{2} k R^{2} \\sum_{v=1}^{4}\\left(\\varphi_{v+1}-\\varphi_{v}\\right)^{2}\n\t\\intertext{\tFrom the Lagrange equations}\n\t\t\\frac{d}{d t} \\frac{\\partial L}{\\partial \\dot{\\varphi}_{v}}&=\\frac{\\partial L}{\\partial \\varphi_{v}}\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.8cm,width=5cm]{small oscillations-01}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{we find the equations of motion:}\n\t\t\\frac{d}{d t} \\frac{\\partial L}{\\partial \\dot{\\varphi}_{v}}=m R \\ddot{\\varphi}_{v}=-\\frac{1}{2} k R^{2}\\left[2\\left(\\varphi_{v}-\\varphi_{v+1}\\right)+2\\left(\\varphi_{v}-\\varphi_{v+1}\\right)\\right]&=\\frac{\\partial L}{\\partial \\varphi_{v}} .\n\t\\intertext{\tFor the case of four mass points, we then obtain}\n\t\\ddot{\\varphi}_{1}=\\frac{k}{m}\\left(\\varphi_{2}-2 \\varphi_{1}+\\varphi_{4}\\right), \\quad \\ddot{\\varphi}_{2}&=\\frac{k}{m}\\left(\\varphi_{3}-2 \\varphi_{2}+\\varphi_{1}\\right)\\\\\n\t\\ddot{\\varphi}_{3}=\\frac{k}{m}\\left(\\varphi_{4}-2 \\varphi_{3}+\\varphi_{2}\\right), \\ddot{\\varphi}_{4}&=\\frac{k}{m}\\left(\\varphi_{1}-2 \\varphi_{4}+\\varphi_{3}\\right)\n\t\\intertext{With the ansatz $\\varphi_{v}=A_{v} \\cos \\omega t, \\ddot{\\varphi}_{v}=-A_{v} \\omega^{2} \\cos \\omega t$, we are led to the following linear system of equations:}\n\t\\left(\\begin{array}{cccc}2 \\frac{k}{m}-\\omega^{2} & -\\frac{k}{m} & 0 & -\\frac{k}{m} \\\\ -\\frac{k}{m} & 2 \\frac{k}{m}-\\omega^{2} & -\\frac{k}{m} & 0 \\\\ 0 & -\\frac{k}{m} & 2 \\frac{k}{m}-\\omega^{2} & -\\frac{k}{m} \\\\ -\\frac{k}{m} & 0 & -\\frac{k}{m} & 2 \\frac{k}{m}-\\omega^{2}\\end{array}\\right)\\left(\\begin{array}{l}A_{1} \\\\ A_{2} \\\\ A_{3}\\end{array}\\right)&=0\n\t\\intertext{For the nontrivial solutions, the determinant of the coefficient matrix must vanish. This condition leads to the determining equation for the eigenfrequencies:}\n\t\\left(2 \\frac{k}{m}-\\omega^{2}\\right)^{2}\\left(4 \\frac{k}{m}-\\omega^{2}\\right)\\left(-\\omega^{2}\\right)=0\n\t\\intertext{The frequencies are}\n\t\\omega_{1}^{2}=0, \\quad \\omega_{2}^{2}&=4 \\frac{k}{m}, \\quad \\omega_{3}^{2}=\\omega_{4}^{2}=2 \\frac{k}{m}\n\\intertext{\tTo calculate the related eigenvibrations, we insert these frequencies into the system of equations:}\n\t\\end{align*}\n\\begin{align*}\n\t&\\text{(1) }\\omega_{1}^{2}=0: A_{1}=A_{2}=A_{3}=A_{4} : \\text{The system does not vibrate but performs a uniform rotation}\\\\\n\t&\\text{(2) }\\omega_{2}^{2}=4 \\frac{k}{m}: A_{1}=A_{3}=-A_{2}=-A_{4}:\\text{ Two neighboring mass points perform an out-of-phase vibration}\\\\\n\t&\\text{(3) }\\omega_{3}^{2}=\\omega_{4}^{2}=2 \\frac{k}{m}: A_{1}=A_{2}=-A_{3}=-A_{4}\\text{ or }A_{1}=A_{4}=-A_{2}=-A_{3} :\\text{ Two neighboring mass points }\\\\&\\text{vibrate in phase}\n\t\\end{align*}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=8cm,width=11cm]{small oscillations-02}\n\t\\end{figure}\n\t\\end{answer}\n\t\\item Two equal masses coupled by two equal springs\n\tTwo equal masses move without friction on a plate. They are connected to each other and to the wall by two springs, as is indicated by Figure $7.3$. The two spring constants are equal, and the motion shall berestricted to a straight line (one-dimensional motion).\n\tFind\\\\\n\t(a) the equations of motion,\\\\\n\t(b) the normal frequencies, and\\\\\n\t(c) the anplitude ratios of the normal vibrations and the general solution.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{(a) Let $x_{1}$ and $x_{2}$ be the displacements from the rest positions. The cquations of motion then read}\n\t\tm \\ddot{x}_{1}&=-k x_{2}+k\\left(x_{2}-x_{1}\\right) \\\\\n\t\tm \\dot{x}_{2}&=-k\\left(x_{2}-x_{1}\\right)\n\t\t\\intertext{(b) For determining the normal frequencies, we use the ansatz}\n\t\tx_{1}&=A_{1} \\cos \\omega t, \\quad x_{2}=A_{2} \\cos \\omega t\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2cm,width=6.5cm]{small oscillations-03}\n\t\t\\end{figure}\n\t\t\\begin{align}\n\t\\intertext{\tand thereby get from $\\color{red}{(7.9)}$ and $(\\color{red}{7.10})$ the equations}\\notag\\\\\n\t\t&\\left(2 k-m \\omega^{2}\\right) A_{1}-k A_{2}=0 \\label{so-05}\\\\\n\t\t&-k A_{1}+\\left(k-m \\omega^{2}\\right) A_{2}=0\\notag\n\t\t\\intertext{From therequirement for nontrivial solutions of the system of equations, it follows that the determinant of coefficient vanishes:}\\notag\n\t\tD&=\\left|\\begin{array}{cc}\n\t\t2 k-m \\omega^{2} & -k \\notag\\\\\n\t\t-k & k-m \\omega^{2}\n\t\t\\end{array}\\right|=0\n\t\\intertext{\tFrom this follows the determining equation for the eigenfrequencies,}\\notag\n\t\t\\omega^{4}-3 \\frac{k}{m} \\omega^{2}+\\frac{k^{2}}{m^{2}}&=0\\notag\n\t\t\\intertext{with the positive solutions}\\notag\n\t\t\\omega_{1}=\\frac{\\sqrt{5}+1}{2} \\sqrt{\\frac{k}{m}} \\text { and } \\omega_{2}&=\\frac{\\sqrt{5}-1}{2} \\sqrt{\\frac{k}{m}}, \\omega_{1}>\\omega_{2} .\\notag\n\t\t\\intertext{By inserting the eigenfrequencies in (\\ref*{so-05}) one sees that the higher frequency $\\omega_{1}$ corresponds to the oppositephase mode, and the lower frequency $\\omega_{2}$ to the equal-phase normal vibration:}\\notag\n\t\t\\text{with }\\omega_{1}^{2}&=\\frac{1}{2}(3+\\sqrt{5}) \\frac{k}{m}, \\quad\\text{ it follows from (\\ref{so-05}) that }A_{2}=-\\frac{\\sqrt{5}-1}{2} A_{1}\\notag\\\\ \\text{with }\\omega_{2}^{2}&=\\frac{1}{2}(3-\\sqrt{5}) \\frac{k}{m},\\text{ it follows from (\\ref{so-05}) that }A_{2}=\\frac{\\sqrt{5}+1}{2} A_{1} .\\notag\n\t\t\\intertext{Since the two mass points are fixed in different ways, we find amplitudes of different magnitudes. The general solution is obtained as a superposition of the normal vibrations, using the calculated amplitudes ratios:}\\notag\n\t\tx_{1}(t)&=C_{1} \\cos \\left(\\omega_{1} t+\\varphi_{1}\\right)+C_{2} \\cos \\left(\\omega_{2} t+\\varphi_{2}\\right)\\notag\\\\\n\t\tx_{2}(t)&=-\\frac{\\sqrt{5}-1}{2} C_{1} \\cos \\left(\\omega_{1} t+\\varphi_{1}\\right)+\\frac{\\sqrt{5}+1}{2} C_{2} \\cos \\left(\\omega_{2} t+\\varphi_{2}\\right)\\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\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\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t 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) \\\\ &=\\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\t \\intertext{For frequencies of normal modes:}\n\t\t \\operatorname{det}\\left|\\omega^{2} \\hat{T}-\\hat{V}\\right|&=0\\\\\n\t\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\t \\Rightarrow 2 m^{2} \\omega^{4}+5 k^{2}-7 k m \\omega^{2}-2 k^{2}&=0\\\\\n\t\t \\Rightarrow 2\\left(m \\omega^{2}\\right)^{2}-7 k\\left(m \\omega^{2}\\right)+3 k^{2}&=0\\\\\n\t\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\t \\therefore \\omega&=\\sqrt{\\frac{3 k}{m}}, \\sqrt{\\frac{k}{2 m}}\n\t\t\\end{align*}\n\t\t Correct answer is option \\textbf{(a)}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Canonical Transformations}\n\\begin{enumerate}\n\t\\item Show that for a transformation to be canonical function \n\t$\\Sigma\\left(p_{i} d q_{i}-P_{i} d Q_{i}\\right)$ must be a perfect differential if the generating function does not contain time. \n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\intertext{\tWe have by the property of generating function in terms of $q, Q$ that is, $G=G\\left(q_{i}, Q_{i}, t\\right)$}\n\tp_{i}&=\\frac{\\partial G}{\\partial q_{i}}, P=-\\frac{\\partial G}{\\partial Q_{i}}\\text{ and }\\bar{H}-H=\\frac{\\partial G}{\\partial t}\\\\\n\\text{\tNow,}\\qquad\n\td G&=\\Sigma\\left(\\frac{\\partial G}{\\partial q_{i}} d q_{i}+\\frac{\\partial G}{\\partial Q_{i}} d Q_{i}\\right)+\\frac{\\partial G}{\\partial t} d t=\\Sigma\\left(p_{i} d q_{i}-P_{i} d Q_{i}\\right)+0 \\qquad\\left(\\because \\frac{\\partial G}{\\partial t}=0\\right)\\\\\n\t\\text{Hence, }&\\Sigma\\left(p_{i} d q_{i}-P_{i} d Q_{i}\\right)\\text{ is a perfect differential.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Show that $P=\\frac{1}{2}\\left(p^{2}+q^{2}\\right), Q=\\tan ^{-1} \\frac{q}{p}$ is canonical.\n\t\\begin{answer}\n\t\t Since the transformation equations do not contain time, the generating function also does not contain time. Hence, the condition for transformation to be canonical is that $(p d q-P d Q)$ be a perfect differential. Here we consider only one term in the summation because the system for which transformation equations are given is of one degree of freedom.\n\t\t\\begin{align*}\n\t\t\\text{Now, }\\quad p d q-P d Q&=p d q-\\frac{p^{2}+q^{2}}{2} d\\left(\\tan ^{-1} \\frac{q}{p}\\right)\\\\\n\t\t&=p d q-\\frac{p^{2}+q^{2}}{2} \\frac{p d-q d p}{p^{2}+q^{2}} \\quad\\left(\\because d\\left(\\tan ^{-1} x\\right)=\\frac{d x}{1+x^{2}}\\right)\\\\\n\t\t&=p d q-\\frac{1}{2} p d q+\\frac{1}{2} q d p=\\frac{1}{2} p d q+\\frac{1}{2} q d p=d\\left(\\frac{1}{2} p q\\right)\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the values of $\\alpha$ and $\\beta$ so that $Q=q^{\\alpha} \\cos p \\beta$ and $P=q^{\\alpha} \\sin p \\beta$ may be canonical. Also find the generating function, $G=G(p, Q)$ is perfect differential.\n\t\\begin{answer}\n\t\tHere the transformation equations do not contain time. Hence the condition for canonical transformation is that $p d q-P d Q$.\n\t\t\\begin{align*}\n\t\\text{\tHere,}\\quad\n\t\tp d q-P d Q&=p d q-q^{\\alpha} \\sin p d\\left(q^{\\alpha} \\cos p \\beta\\right)\\\\\n\t\t&=p d q-q^{\\alpha} \\sin p \\beta\\left(\\alpha q^{\\alpha-1} \\cos p \\beta-\\beta q^{\\alpha} \\sin p \\beta d p\\right)\\\\\n\t\t&=\\left(p-\\alpha q^{2 \\alpha-1} \\sin p \\beta \\cos p \\beta\\right) d q+\\beta q^{2 \\alpha} \\sin ^{2} p \\beta d p\n\t\t\\intertext{Now, $M(x, y) d x+N(x, y) d y$ is an exact differential when $\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}$. By this principle $p d q-P d Q$ is a perfect differential if}\n\t\t\\frac{\\partial}{\\partial p}\\left(p-\\alpha q^{2 \\alpha-1} \\sin p \\beta \\cos p \\beta\\right)&=\\frac{\\partial}{\\partial q}\\left(\\beta q^{2 \\alpha} \\sin ^{2} p \\beta\\right)\\\\\n\t\t\\text{or}\\quad1-\\alpha \\beta q^{2 \\alpha-1}\\left(1-2 \\sin ^{2} p \\beta\\right)&=2 \\alpha \\beta q^{2 \\alpha-1} \\sin ^{2} p \\beta\\\\\n\t\t\\text{or}\\quad1-\\alpha \\beta q^{2 \\alpha-1}+2 \\alpha \\beta q^{2 \\alpha-1} \\sin ^{2} p&=2 \\alpha \\beta q^{2 \\alpha-1} \\sin ^{2} p \\beta\\\\\n\t\t\\text{or}\\quad\\alpha \\beta q^{2 \\alpha-1}&=1\n\t\t\\intertext{Since, RHS is a constant, this equation is satisfied only when the power of $q$ is zero. Hence, $2 \\alpha-1=0$ or $\\alpha=\\frac{1}{2}$ and $\\beta=2$. Thus, $\\alpha=\\frac{1}{2}$ and $\\beta=2$ are the required values of $\\alpha$ and $\\beta$}\n\t\t\\end{align*}\n\t\t\\textbf{Generating function :} When the generating function is assumed to be $G=G(p, Q)$, we have\n\t\t\\begin{align*}\n\t\tq&=-\\frac{\\partial G}{\\partial p}\\text{ and }P=-\\frac{\\partial G}{\\partial Q}\\\\\n\t\t\\text{Here,}\\quad\n\t\tQ&=q^{1 / 2} \\cos 2 p \\text { or } q=\\left(\\frac{Q}{\\cos 2 p}\\right)^{2}\\\\\n\t\t\\text{ And }\\quad P&=q^{1 / 2} \\sin 2 p=\\left(\\frac{Q}{\\cos 2 p}\\right) \\sin 2 p=Q \\tan 2 p\\\\\n\t\t\\therefore \\quad \\frac{\\partial G}{\\partial p}&=-q=-\\left(\\frac{Q Q}{\\cos 2 p}\\right)^{2}\\text{ or }G=-Q^{2} \\int \\frac{\\partial p}{\\cos ^{2} 2 p}\\\\\n\t\t\\text{or}\\quad G&=-Q^{2} \\int \\sec ^{2} 2 p \\partial p=-\\frac{1}{2} Q^{2} \\tan 2 p\\\\\n\t\\text{\tThus, }G&=-\\frac{1}{2} Q^{2} \\tan 2 p\\text{ is the required generating function.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Show that the generating function for the transformation $p=\\frac{1}{Q}$ and $q=P Q^{2}$ is $G=\\frac{q}{Q}$\n\t\\begin{answer}\n\t\t Since we have to show that $G=\\frac{q}{Q}$ we assume that the generating function needed is a function of $q, Q$ that is, $G=G(q, Q)$. When $q$ and $Q$ are independent variables, the other two variables $p$ and $P$ are given by $p=\\frac{\\partial G}{\\partial q}$ and $P=-\\frac{\\partial G}{\\partial Q}$.\n\t\t\\begin{align*}\n\t\t\\text{Here, }\\quad p&=\\frac{1}{Q}\\text{ and hence here }\\frac{1}{Q}=\\frac{\\partial G}{\\partial q}\\text{ or }G=\\int \\frac{\\partial q}{Q}.\\\\\n\t\t\\text{Or }G&=\\frac{q}{Q}\n\t\\intertext{\tFrom the second relation also we can show that}\n\t\tG&=\\frac{q}{Q}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Show that if there exists a generating function $\\mathrm{G}$ such that $\\frac{d G}{d t}=L-\\bar{L}$ where $\\mathrm{L}$ and $\\bar{L}$ are the Lagrangians in old and new set of coordinates, then the transformation is canonical.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{By Hamilton's principle, }\\frac{d G}{d t}&=L-\\delta \\int_{t_{1}}^{t_{2}} L d t=0\\text{ and }\\delta \\int_{t_{1}}^{t_{2}} \\bar{L} d t=0\\\\\n\t\t\\text{Subtracting we have, }\\delta \\int_{t_{1}}^{t_{2}}(L-\\bar{L}) d t&=0\\\\\n\t\t\\text{By virtue of the given relation i.e. }\\frac{d G}{d t}&=L-\\bar{L}\\\\\n\t\t\\text{We have, }\\delta \\int_{t_{1}}^{t_{2}} \\frac{d G}{d t} d t=0\\text{, or} \\delta\\left[G\\left(t_{2}\\right)-G\\left(t_{1}\\right)\\right]&=0\\text{ which is the condition for canonical transformation.}\n\t\t\\intertext{Hence under the given condition the transformation is canonical.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Show that $G=-\\Sigma Q_{i} p_{i}$ generating on identity transformation.\n\t\\begin{answer}\n\t\t Let us define an identity transformation. When the coordinates of old set are equal to the coordinates of the new set, it is called an identity transformation.\\\\\n\t\t \\text { It is given here that the generating function is a function of } p, Q \\text { i.e. } G=G(p, Q)\n\t\t\\begin{align*}\n\t\t\\text{In this case we have, }q_{i}&=-\\frac{\\partial G}{\\partial p_{i}}\\text{ and }P_{i}=-\\frac{\\partial G}{\\partial Q_{i}}\n\t\t\\intertext{Here it is given that $G=-\\Sigma p_{i} Q_{i}$. As we have to take derivative of $G$ with respect to $p_{i}$, we change the suffix in the summation to $j$ i.e. we take $G=-\\Sigma p_{j} Q_{j}$.}\n\t\t\\therefore \\quad \\frac{\\partial G}{\\partial p_{i}}&=-\\Sigma\\left(p_{j} \\frac{\\partial Q_{j}}{\\partial p_{i}}+Q_{j} \\frac{\\partial p_{j}}{\\partial p_{i}}\\right)\\\\\n\t\\text{\tNow, }\\quad \\frac{\\partial Q_{j}}{\\partial p_{i}}&=0\\text{ because, $p, Q$ are selected as independent variables}\\\\\n\t\\text{here and }\\quad \\frac{\\partial p_{j}}{\\partial p_{i}}&=0\\text{ if $i \\neq j=1$ if $i=j$}\\\\\n\t\\text{Here, }\\quad \\frac{\\partial G}{\\partial p_{i}}&=-Q_{i} .\\text{ But }\\frac{\\partial G}{\\partial p_{i}}=-q_{i} (\\text{in general}).\\\\\n\t\\therefore \\quad q_{i}&=Q_{i}\\\\\n\t\\frac{\\partial G}{\\partial Q_{i}}&=-\\Sigma\\left(Q_{j} \\frac{\\partial p_{j}}{\\partial Q_{i}}+p_{j} \\frac{\\partial Q_{j}}{\\partial Q_{i}}\\right)=-p_{i}\\\\\n\t(\\text{Because }\\frac{\\partial p_{j}}{\\partial Q_{i}}&=0\\text{ and }\\frac{\\partial Q_{j}}{\\partial Q_{i}}=1\\text{ where }\\mathrm{i}=\\mathrm{j}\\text{, otherwise zero}).\\\\\n\t\\therefore \\quad p_{i}&=P_{i}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "68d1aa55dd571b761691f14251351183511714b4", "size": 133289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Classical Mechanics  -CSIR/chapter/Classical Problems.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/Classical Problems.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/Classical Problems.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": 80.9775212637, "max_line_length": 534, "alphanum_fraction": 0.6338257471, "num_tokens": 52542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321703143954, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6347827232161192}}
{"text": "\\section{Limits and Continuity}\r\nIf we want to differentiate, we need to make sense of a limit, so here goes.\r\n\\subsection{Limit of a function}\r\n\\begin{definition}\r\n    Suppose $a\\in\\mathbb C$ and $f:\\mathbb C\\setminus\\{a\\}\\to\\mathbb C$.\r\n    We say $\\lim_{z\\to a}f(z)=c\\in\\mathbb C$ if\r\n    $$\\forall\\epsilon>0,\\exists\\delta>0,|z-a|<\\delta\\implies |f(z)-c|<\\epsilon$$\r\n    Sometimes we write $f(z)\\to c$ as $z\\to a$.\r\n\\end{definition}\r\nWe say $\\lim_{z\\to a}f(z)$ is undefined if there is no $c$ with $\\lim_{z\\to a}f(z)=c$.\r\n\\begin{proposition}\r\n    If $\\lim_{z\\to a}f(z)=c$ and $\\lim_{z\\to a}f(z)=d$, then $c=d$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. If $f\\equiv c$, then $\\lim_{z\\to a}f(z)=c$ for any $a$, just take for example $\\delta=1$.\\\\\r\n    2. If $f(z)=z$, then $\\lim_{z\\to a}f(z)=a$, as we can take $\\delta=\\epsilon$.\\\\\r\n    3. If $f(z)=1_{\\mathbb C\\setminus\\{0\\}}$, then $\\lim_{z\\to 0}f(z)=1$, taking for example $\\delta=1$.\\\\\r\n    4. If\r\n    $$f(z)=\\begin{cases}\r\n        1\\text{, if $\\operatorname{Re}(z)>0$}\\\\\r\n        0\\text{, if $\\operatorname{Re}(z)=0$}\\\\\r\n        -1\\text{, if $\\operatorname{Re}(z)<0$}\r\n    \\end{cases}$$\r\n    then $\\lim_{z\\to 0}f(z)$ does not exist.\\\\\r\n    5. If $f(z)=z^2$, then $\\lim_{z\\to a}f(z)=a^2=f(a)$ by choosing $\\delta=\\min\\{\\epsilon/(2|a|+1),1\\}$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    $\\lim_{z\\to a}f(z)=c$ if and only if $\\forall (z_n)\\in\\mathbb C$ with $z_n\\to a$, we have $f(z_n)\\to c$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If the limit of the function is $c$, given $\\epsilon>0$, we can find $\\delta$ such that $|z-a|<\\delta\\implies |f(z)-c|<\\epsilon$.\r\n    Given a sequence $z_n\\to a$, we can find $N\\in\\mathbb N$ such that $\\forall n>N,|z_n-a|<\\delta$, so using this $N$, $\\forall n>N,|z_n-a|<\\delta\\implies |f(z_n)-c|<\\epsilon$, so $f(z_n)\\to c$.\\\\\r\n    Conversely, if $c$ is not the limit of that function, then $\\exists\\epsilon>0,\\forall\\delta>0,\\exists z\\in\\mathbb C,|z-a|<\\delta,|f(z)-c|>\\epsilon$.\r\n    So we choose such $z_n$ for $\\delta=1/n$, then $z_n\\to a$ but $|f(z_n)-c|>\\epsilon$ for any $n$, hence $f(z_n)$ does not tend to $c$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $f,g:\\mathbb C\\setminus\\{a\\}\\to\\mathbb C$, if $\\lim_{z\\to a}f(z)=c$ and $\\lim_{z\\to a}f(z)=d$, then\\\\\r\n    1. $\\lim_{z\\to a}(f(z)+g(z))=c+d$.\\\\\r\n    2. $\\lim_{z\\to a}f(z)g(z)=cd$.\\\\\r\n    3. If $c\\neq 0$, then $\\lim_{z\\to a}1/f(z)=1/c$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Using the preceding proposition and laws of limits for sequences.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Suppose $f,g:\\mathbb C\\setminus\\{a\\}\\to\\mathbb R$ such that\r\n    $$\\lim_{z\\to a}f(z)=c,\\lim_{z\\to a}g(z)=d$$\r\n    then,\\\\\r\n    1. If $\\forall z,f(z)\\ge g(z)$, then $c\\ge d$.\\\\\r\n    2. (Squeeze Rule) Let $h:\\mathbb C\\setminus\\{a\\}$ be such that $f\\ge h\\ge g$.\r\n    Then if $c=d$, we have $\\lim_{z\\to a}h(z)=c$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nWhat if $f:A\\to\\mathbb C$ where $A$ is a subset of $\\mathbb C$?\r\nDoes it still makes sense?\r\nDoes it change the limit?\r\nThe answer to the second question if obviously no.\r\nBut we can make sense of the limit.\r\n\\begin{definition}\r\n    Suppose $A$ is a subset of $\\mathbb C$.\r\n    We say $a\\in\\mathbb C$ is a limit point of $A$, if $\\forall\\delta>0,\\exists z\\in A,0<|z-a|<\\delta$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Any $a\\in [0,\\infty)$ is a limit point of $(0,\\infty)$, and $\\mathbb Z$ has no limit point.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $f:A\\to\\mathbb C$ and $a\\in\\mathbb C$ is a limit point of $A$, we say $\\lim_{z\\to a}f(z)=c$ if $\\forall\\epsilon>0,\\exists\\delta>0,z\\in A,0<|z-a|<\\delta\\implies |f(z)-c|<\\epsilon$.\r\n\\end{definition}\r\nEquivalently, $f(z_n)\\to c$ for any sequence $(z_n)\\in A$ such that $z_n\\to a$.\r\nAlso, it is also easy to show that the limit is unique.\r\n\\begin{definition}\r\n    For $f:\\mathbb R\\to\\mathbb R$, we define\r\n    $$\\lim_{x\\to a^+}f(x)=\\lim_{x\\to a}f|_{(a,\\infty)}(x),\\lim_{x\\to a^-}f(x)=\\lim_{x\\to a}f|_{(-\\infty,a)}(x)$$\r\n\\end{definition}\r\n\\subsection{Continuity}\r\n\\begin{definition}\r\n    Suppose $A\\subset\\mathbb C$, and $f:A\\to\\mathbb C$.\r\n    We say $f$ is continuous at $a\\in A$ if\r\n    $$\\forall\\epsilon>0,\\exists\\delta>0,z\\in A,|z-a|<\\delta\\implies |f(z)-f(a)|<\\epsilon$$\r\n\\end{definition}\r\n\\begin{remark}\r\n    $|f(a)-f(a)|=0<\\epsilon$, so this condition is equivalent to say $|f(z)-f(z)|<\\epsilon$ whenever $0<|z-a|<\\delta$.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Suppose $f:A\\to\\mathbb C$ and $a\\in A$, then the following conditions are equivalent:\\\\\r\n    1. $f$ is continuous at $a$.\\\\\r\n    2. Either $a$ is not a limit point of $A$ or $\\lim_{z\\to a}f(z)=f(a)$.\\\\\r\n    3. $f(z_n)\\to f(a)$ whenever $z_n\\to a$ is a sequence in $A$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Verify from definition.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Constant functions are continuous at every point.\r\n\\end{example}\r\n\\begin{definition}\r\n    We say $f:A\\to\\mathbb C$ is continuous if $f$ is continuous at every $a\\in A$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    2. The identity function is continous.\\\\\r\n    3. (non-example) $f:\\mathbb R\\to\\mathbb R$ by $f=1_{\\mathbb Q}$. is not continuous at any point.\\\\\r\n    4. Consider $f:\\mathbb R\\to\\mathbb R$ by\r\n    $$f(x)=\\begin{cases}\r\n        1/q\\text{, if $x$ is rational and $q=\\min\\{q\\in\\mathbb N:\\exists p\\in\\mathbb Z,x=p/q\\}$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Then $f$ is not continuous at any $x\\in\\mathbb Q\\setminus\\{0\\}$ but it is continuous at $a\\notin\\mathbb Q$.\\\\\r\n    5. $f:\\mathbb R_{\\ge 0}\\to\\mathbb R_{\\ge 0}$ by $x\\mapsto \\sqrt{x}$ is continuous.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Suppose $f,g:A\\to\\mathbb C$ for some $A\\subset\\mathbb C$ and they are both continuous at $a\\in A$.\r\n    Then $f+g,fg$ are continuous at $a$.\r\n    And if $f(a)\\neq 0$, then $1/f$ is continuous at $a$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    Everywhere in $\\mathbb C$ we have any constant function is continous, the identity is continuous, hence any linear function is continuous, therefore any polynomial is continuous.\r\n    Also any rational function is continuous at anywhere it is defined.\r\n\\end{example}\r\nThe function $\\exp$ is continuous, but we will not prove it now.\r\n\\begin{proposition}\r\n    Let $A,B,C\\subset\\mathbb C$ and $f:A\\to B,g:B\\to C$ such that $f$ is continuous at $a$ and $g$ continuous at $f(a)$, then $g\\circ f$ is continuous at $a$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Straightforward.\r\n\\end{proof}\r\n\\begin{example}\r\n    $g:(0,\\infty)\\to (0,\\infty),g(x)=\\sqrt{x}$ and $f:(0,\\infty)\\to(0,\\infty),f(x)=x^2+1$, so $x\\mapsto (g\\circ f)(x)=\\sqrt{x^2+1}$ is continuous.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Suppose $(x_n)$ is a sequence in $[a,b]$ and $x_n\\to x\\in\\mathbb R$, then $x\\in [a,b]$.\r\n\\end{lemma}\r\nNote that this is false if we replace $[a,b]$ by $(a,b)$.\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{theorem}[Intermediate Value Theorem]\r\n    If $f:[a,b]\\to\\mathbb R$ is continuous, and $f(a)\\le0,f(b)\\ge0$, then there is some $c\\in [a,b]$ such that $f(c)=0$.\r\n\\end{theorem}\r\nThis is false for $\\mathbb Q$.\r\n\\begin{remark}\r\n    Note that it does not matter if it is $f(a)\\le0,f(b)\\ge0$ or $f(b)\\le0,f(a)\\ge0$.\r\n    Also it suffices to show the case where the inequalities are both strict, so we will assume that in the proof.\r\n\\end{remark}\r\n\\begin{proof}\r\n    For $n\\in\\mathbb N$, we define $Q_n=\\{a+k(b-a)/n:0\\le k\\le n\\}$ and $P_n\\subset Q_n$ such that $\\forall x\\in P_n,f(x)\\le 0$, so $P_n$ is never empty.\r\n    Define $x_n=\\max P_n$, then $a\\le x_n\\le b-(b-a)/n$ and $f(x_n)\\le 0$.\r\n    We let $y_n=x_n+(b-a)/n=\\min Q_n\\setminus P_n\\subset [a,b]$, then by maximality of $x_n$ we have $f(y_n)>0$.\r\n    By Bolzano-Weierstrass Theorem, there is a subsequence $x_{n_k}$ that converges to some $c\\in [a,b]$ by the preceding lemma, so by continuity of $f$, $f(c)=\\lim_{n\\to\\infty}f(x_n)\\le 0$.\r\n    Therefore $y_{n_k}\\to c$ as well since $(b-a)/n_k\\to 0$, but then $f(c)=\\lim_{n\\to\\infty}f(y_n)\\ge 0$.\r\n    So $f(c)=0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    An odd degree polynomial has a root in $\\mathbb R$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f:[a,b]\\to\\mathbb R$ is continuous, and $f(a)=x,f(b)=y$, then for all $z$ in between $x,y$ there is some $c\\in [a,b]$ such that $f(c)=z$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $g:x\\mapsto x-z$ is continuous.\r\n    Then apply the preceding theorem.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Continuous function on bounded closed interval is bounded and attains its bounds.\r\n\\end{theorem}\r\nAgain it is not true in general for open intervals.\r\n\\begin{proof}\r\n    Suffice to show this for upper bounds.\r\n    Let $f:[a,b]\\to\\mathbb R$ be continuous.\r\n    Let $A=f([a,b])$.\r\n    Suppose $A$ is not bounded above, then $\\forall n\\in\\mathbb N,\\exists x_n\\in[a,b],f(x_n)>n$.\r\n    Then choose a convergent subsequence $(x_{n_k})$ of $(x_n)$, then $x_{n_k}\\to x\\in [a,b]$, but by continuity $f(x)=\\lim_{k\\to\\infty}f(x_k)\\ge\\lim_{k\\to\\infty}n_k\\to\\infty$, contradiction.\\\\\r\n    Now that $A$ is bounded above, we choose $M=\\sup A$, then $\\forall n\\in\\mathbb N$, we can choose $x_n\\in [a,b]$ such that $M-1/n<x_n\\le M$.\r\n    Choose a convergent subsequence $x_{n_k}\\to x\\in [a,b]$, then continuity tells us that $f(x)=\\lim_{k\\to\\infty}f(x_{n_k})$ which is bounded by $M-1/n_k,M$, hence $f(x)=M$ by Squeeze rule.\r\n\\end{proof}\r\n", "meta": {"hexsha": "5a63296d0cf1fce31a5d2dd6e28895071c22f747", "size": 9433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/limits.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": "3/limits.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": "3/limits.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": 50.7150537634, "max_line_length": 198, "alphanum_fraction": 0.6234495919, "num_tokens": 3533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.6347437041806239}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{url}\n\\title{Smooth Autonomous Paths on Tank Drive using Splines}\n\\date{Spring 2018}\n\\author{Lyra Solomon, Citrus Circuits}\n\\begin{document}\n\\maketitle\n\n\\section{Why Splines?}\nGetting from point to point efficiently is key to writing an effective autonomous routine.\nBefore using splines, we designed our paths by sequencing semicircles. This has two primary\nissues. Most visibly, where each drive action ends up depends on where it started, so a\nchange near the beginning of a routine means the entire rest of the routine has to be retuned.\nLess visibly, the transition between semicircles is imperfect because angular velocity is\nnot continuous. This year, we began using splines, or two-dimensional polynomials, to define\nsmooth curves between arbitrary states. This allowed us to do more in autonomous by getting\naround more efficiently and tuning faster.\n\n\\section{Notation Used in this Paper}\n\\paragraph{$a_{\\bot b}$} The rejection of $a$ onto $b$, $a-a_{\\parallel b}$.\n\\paragraph{$a_{\\parallel b}$} The projection of $a$ onto $b$, $(a \\cdot \\hat{b}) \\hat{b}$.\n\\paragraph{$\\hat{a}$} The unit vector in the direction of $a$, $\\frac{a}{\\lvert a \\rvert}$.\n\\paragraph{$a^\\bot$} The perpendicular of $a$, $\\begin{bmatrix} -a_1 \\\\ a_0 \\end{bmatrix}$.\n\\paragraph{$A^+$} The pseudoinverse of A.\n\\paragraph{$\\mathrm{cap}$} A function to ensure a value is in a given range,\n$\\mathrm{cap}(x, min, max) = \\mathrm{min}(max, \\mathrm{max}(min, x))$.\n\n\\section{Definitions of Symbols}\n\\paragraph{$d_0, d_f: \\mathbb{R}$} The additional mostly straight initial and final distances,\nspecified by the user to avoid obstacles or better handle nonzero $\\omega_0$ and $\\omega_f$.\n\\paragraph{$k: \\mathbb{R}_+$} The approximate curvature of the path.\n\\paragraph{$k_r: \\mathbb{R}_+$} The radius of the wheel base, half the distance between left and right wheels.\n\\paragraph{$r(s): [0,1] \\rightarrow \\mathbb{R}^2$} A curve which defines the shape of the path.\n$s$ is an arbitrary variable that doesn't correspond exactly to time.\n\\paragraph{$\\Delta r: \\mathbb{R}^2$} The total displacement $r(1)-r(0)$.\n\\paragraph{$v_0, v_f: \\mathbb{R}$} The initial and final velocity of the robot.\n\\paragraph{$\\omega_0, \\omega_f: \\mathbb{R}$} The initial and final angular velocity of the robot.\n\\paragraph{$u_{cap}: \\mathbb{R}_+$} The maximum voltage for feedforward control.\nShould be less than the battery voltage to allow feedback corrections.\n\\paragraph{$a_{cap}: \\mathbb{R}_+$} The maximum acceleration. This is limited since\nreversing direction at full power would result in the robot tipping or skidding.\n\n\\section{Paths}\nThe path the robot must follow is defined by six constraints - the initial and final position,\ntangent (which closely corresponds to velocity), and normal (which closely corresponds to acceleration).\nTherefore, the path must be a fifth-degree polynomial since that is the minimum degree with six coefficients.\nSince $r(s)=a_0+a_1s+a_2s^2+a_3s^3+a_4s^4+a_5s^5$, the constraints are\n$r(0)=a_0$, $r'(0)=a_1$, $r''(0)=2a_2$, $r(1)=a_0+a_1+a_2+a_3+a_4+a_5$,\n$r'(1)=a_1+2a_2+3a_3+4a_4+5a_5$, and $r''(1)=2a_2+6a_3+12a_4+20a_5$. Solving for the coefficients in\nterms of the constraints yields the following equation for $r(s)$:\n\\begin{align}\n\\notag r(s)=&r(0)+\\\\\n\\notag      &r'(0) \\cdot s+\\\\\n\\notag      &\\frac{1}{2}r''(0) \\cdot s^2+\\\\\n\\notag      &(-10r(0)-6r'(0)-\\frac{3}{2}r''(0)+\\frac{1}{2}r''(1)-4r'(1)+10r(1)) \\cdot s^3+\\\\\n\\notag      &(15r(0)+8r'(0)+\\frac{3}{2}r''(0)-r''(1)+7r'(1)-15r(1)) \\cdot s^4+\\\\\n            &(-6r(0)-3r'(0)-\\frac{1}{2}r''(0)+\\frac{1}{2}r''(1)-3r'(1)+6r(1)) \\cdot s^5\n\\end{align}\n\nThe positions $r(0)$ and $r(1)$ are two-dimensional vectors representing the initial and final position of the robot, respectively.\n\nThe tangents $r'(0)$ and $r'(1)$ are used primarily to define the shape of the curve.\nThey are two-dimensional vectors with direction defined by the robot's heading. Usually, their magnitude \nis set to the endpoint-to-endpoint length of the curve. This has the advantage of being very predictable,\nsince scaling the endpoints simply scales the curve, and being very quick to drive if the robot starts and\nends from rest. However, if the robot has a high enough initial or final velocity, the path will curve too\nquickly for the robot to follow. To fix this, we add an estimate of the extra stopping distance, $\\frac{1}{2}v^2k^2$,\nwhere $k$ is the estimated curvature.\n\\begin{equation}\nk = \\frac{2 \\cdot \\lvert \\Delta r_{\\bot r'(0)} \\rvert - \\Delta r_{\\bot r'(0)} \\widehat{\\cdot r'(1)}}{\\lvert \\Delta r \\rvert}\n\\end{equation}\nThis estimates the curvature by taking twice the sideways distance minus the amount of sideways distance accounted for\nby ending at a different angle, as a proportion of the total distance. An additional value is added by the\nuser if necessary to extend one end of the curve to avoid an obstacle. Experimentally, it was found that to\ndrive mostly straight for an additional distance $d$, approximately $5d$ should be added to the tangent.\nThe complete equation for $r'(0)$ is as follows ($r'(1)$ works the same way):\n\\begin{equation}\nr'(0)=(\\lvert \\Delta r \\rvert + \\frac{1}{2}v_0^2k^2 + 5d_0) \\cdot \\widehat{r'(0)}\n\\end{equation}\n\nThe normals $r''(0)$ and $r''(1)$ are used to ensure that the angular angular velocity at the endpoints is correct.\nThe equations $a=v^2/r$ and $r=v/\\omega$ give the following equation for $r''(0)$ ($r''(1)$ works the same way):\n\\begin{equation}\nr''(0)=r'(0)^\\bot \\cdot \\lvert r'(0) \\rvert \\cdot \\frac{\\omega_0}{v_0}\n\\end{equation}\n\n\\section{Reparameterization}\nFor the robot to follow the path, it must be given position and velocity as a function of time. First,\nthe polynomial is broken into a finite list of samples containing x, y, and heading at $s=0,\\frac{1}{n},\\hdots,\\frac{n-1}{n}$.\nFrom this, the drivetrain state is calculated at each sample using the following equations:\n\\begin{align}\n\\Delta x_{l,i} &= \\Delta r_i \\cdot T_i - k_r \\Delta \\theta_i \\\\\n\\Delta x_{r,i} &= \\Delta r_i \\cdot T_i + k_r \\Delta \\theta_i\n\\end{align}\nwhere $T$ is the unit tangent vector at the first sample and $k_r$ is the radius of the wheel base.\n\nTwo passes are needed to find the point in time at which each sample occurs - one which steps\nforwards using the maximum acceleration, and one which steps backwards using the maximum\ndeceleration.\n\nThe robot is assumed to follow the state-space equation $\\dot{x}=Ax+Bu$. On each pass,\nthe holding voltage $V_{holding}=-B^+Ax$ is calculated at each sample. On the forwards\npass, this is subtracted from the minimum and maximum voltage to give the amount of voltage\navailable for acceleration. On the backwards pass, it is added instead, since the output\nstate occurs before the input state.\n\n\\begin{align}\nu_{max} &= \\begin{bmatrix}  u_{cap} \\\\  u_{cap} \\end{bmatrix} - B^+Ax * \\mathrm{time direction} \\\\\nu_{min} &= \\begin{bmatrix} -u_{cap} \\\\ -u_{cap} \\end{bmatrix} - B^+Ax * \\mathrm{time direction}\n\\end{align}\n\nFor each side of the drivetrain, the maximum acceleration is calculated. In most cases,\nthe segment can be approximated as an arc, in which the acceleration on each side is\nproportional to the segment length. However, this approximation fails when one side needs\nto travel much further than the other. In that case, when computing the acceleration\nfor the shorter side, treat the other side as being shorter than it is. A reasonable cutoff\nis to cap the opposite side at three times the length. From the acceleration ratio, the\nvoltage ratio is calculated to find the maximum.\n\n\\begin{equation}\nu_{accel} = B^+ \\begin{bmatrix} a_{same} \\\\ a_{opposite} \\end{bmatrix}k\n\\end{equation}\n$u_{accel,max}:$ select largest $k$ such that no component of $u_{accel}$ is greater than its matching component in $u_{max}$. \\\\\n$u_{accel,min}:$ select smallest $k$ such that no component of $u_{accel}$ is less than its matching component in $u_{max}$.\n\nWhen the distance is forwards, select the maximum acceleration, when the distance is backwards,\nselect the minimum acceleration. In either of these cases,\n$a = \\mathrm{cap}(Bu_{accel}, -a_{cap}, a_{cap})$, and\n$v_f = \\sqrt{v_0^2+2ad}$, but with the sign set to that of the $d$.\n\nIn the case that the direction changes, take the next distance as well and assume the samples\nare evenly spaced in time, forming a quadratic equation where $x(0)=0$, $x(1)=d_1$, and $x(2)=d_1+d_2$,\n$x(s)=\\frac{d_2-d_1}{2}s^2+ks$.\nIf the total time from $s=0$ to $s=2$ is $T$,\n$x(t)=2\\frac{d_2-d_1}{T^2}t^2+kt$ and $a=4\\frac{d_2-d_1}{T^2}$.\nSelecting $a=a_{cap}$ and solving gives $T=2\\sqrt{\\frac{d_2-d_1}{a}}$,\nand $v_f=v(\\frac{T}{2})=\\frac{d_2+d_1}{T}$.\n\nDue to approximations and capping, the two velocities may not agree. The time each\nside of the drivetrain requires is calculated as $t=\\frac{2d}{v_0+v_f}$. The time\nrequired for the segment is $\\mathrm{max}(t_l, t_r)$, unless one side crosses $v=0$\nduring that segment, in which case the time from the other side is used to prevent\npossible floating point precision issues. The final velocity for each side is\nmultiplied by $\\frac{t_{side}}{t}$ so both sides are balanced. The balancing is done\non the final velocity instead of the average velocity to prevent errors from passed\non to the next segment.\n\n\\section{Interpolation}\nThe times that the robot needs to know the goal state are not the same as the sample times.\nBecause of this, the goal state must be calculated from the nearest samples. We maintain the\nindex of the segment the robot is currently following, and the time elapsed since the robot began\nthat segment. When the time elapsed exceeds the segment time, the time elapsed is decreased\nby that amount and the index is incremented. The path is considered complete when the segment\nindex is equal to the number of segments.\n\nThe goal position and velocity follow the equations $x=x_i+v_it+\\frac{1}{2}a^2$ and $v=v_i+at$,\nwhere $x_i$ and $v_i$ come from the sample at the start of the segment, $t$ is the time elapsed\nin the current segment, and $a=\\frac{v_{i+1}-v_i}{t_i}$, where $v_{i+1}$ comes from the sample\nat the end of the segment and $t_i$ is the segment time.\n\nThe goal angle $\\theta=\\omega t$, where $\\omega=\\frac{\\theta_{i+1}-\\theta_i}{t_i}$.\n\nThe goal Cartesian position has $p_x=p_{x,i}+d\\frac{cos{\\theta}+cos{\\theta_i}}{2}$\nand $p_y=p_{y,i}+d\\frac{sin{\\theta}+sin{\\theta_i}}{2}$, where the distance traveled this segment\n$d=\\frac{x_l+x_r-x_{l,i}-x_{r,i}}{2}$.\n\n\\section{Implementation}\nOur implementation of splines is in the directory \\path{/third_party/frc971/control_loops/paths/}\nof our robot code repository. The files \\path{path.*} contain the implementation of the paths\nsection, and the files \\path{trajectory.*} contain the implementation of the reparameterization\nand interpolation sections.\n\nWhen implementing or modifying spline code, important edge cases to test are driving backwards\nand turns sharp enough that one side needs to reverse direction.\n\\end{document}\n", "meta": {"hexsha": "9083ea0e16182bb8fbee5f537e468fb8d70771e4", "size": 10995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/splines.tex", "max_stars_repo_name": "hansonl02/frc-robot-code", "max_stars_repo_head_hexsha": "4b120c917a7709df9f010c9089a87c320bab3a16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 61, "max_stars_repo_stars_event_min_datetime": "2017-01-22T04:38:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T00:04:37.000Z", "max_issues_repo_path": "docs/splines.tex", "max_issues_repo_name": "hansonl02/frc-robot-code", "max_issues_repo_head_hexsha": "4b120c917a7709df9f010c9089a87c320bab3a16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-06-28T05:34:57.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-16T15:46:22.000Z", "max_forks_repo_path": "docs/splines.tex", "max_forks_repo_name": "hansonl02/frc-robot-code", "max_forks_repo_head_hexsha": "4b120c917a7709df9f010c9089a87c320bab3a16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2017-05-12T15:32:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T12:49:38.000Z", "avg_line_length": 61.7696629213, "max_line_length": 131, "alphanum_fraction": 0.7350613915, "num_tokens": 3236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6347436919195681}}
{"text": "\\chapter{Quadrilateral Quality Metrics}\n\nAll the metrics in this section are defined on a quadrilateral element with vertices\nshown in Figure~\\ref{f:quad}. Furthermore, we define the following edge vectors for\nconvenience. Note that each edge has two versions, one defined by its endpoints and\nanother indexed by sequential integers:\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_3 - \\vec P_2\\\\\n\\vec L_3 &=& \\vec P_0 - \\vec P_3\n\\end{array}\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\vec L_{01} &=& \\vec P_1 - \\vec P_0\\\\\n\\vec L_{12} &=& \\vec P_2 - \\vec P_1\\\\\n\\vec L_{23} &=& \\vec P_3 - \\vec P_2\\\\\n\\vec L_{30} &=& \\vec P_0 - \\vec P_3.\n\\end{array}\n\\end{equation*}\n\nThe quadrangle 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}\n\\]\nand the largest and smallest edge lenghts are, respectively,\n\\[\nL_{\\min} = \\min\\left(L_0, L_1, L_2, L_3\\right)\n  \\rule{2em}{0pt}\nL_{\\max} = \\max\\left(L_0, L_1, L_2, L_3\\right)\n\\]\n\nThe diagonals of a quadrilateral are denoted\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec D_0 &=& \\vec P_2 - \\vec P_0\n\\end{array}\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\vec D_1 &=& \\vec P_3 - \\vec P_1\n\\end{array}\n\\end{equation*}\nand the longest diagonal has length\n\\[\nD_{\\max} = \\max\\left\\{ \\normvec{D_0}, \\normvec{D_1} \\right\\}.\n\\]\n\n\\begin{figure}[htb]\n  \\centering\n  \\subfigure[Vertices of a quadrilateral.]{\\includegraphics[width=2in]{quad}}\n  \\subfigure[Principal axis vectors.]{\\includegraphics[width=2in]{quad-axes}}\n  \\caption{A quadrilateral showing notation used in metric definitions.%\n                                                                  \\label{f:quad}}\n\\end{figure}\n\nThe principal axes are\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec X_1 &=& \\left(\\vec P_1 - \\vec P_0\\right) + \\left(\\vec P_2 - \\vec P_3\\right)\\\\\n\\vec X_2 &=& \\left(\\vec P_2 - \\vec P_1\\right) + \\left(\\vec P_3 - \\vec P_0\\right)\n\\end{array}\n\\end{equation*}\nand the cross derivatives of the map from parametric to world space are oriented along\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec X_{12} &=& \\left(\\vec P_0 - \\vec P_1\\right) + \\left(\\vec P_2 - \\vec P_3\\right) =\\\\\n\\vec X_{21} &=& \\left(\\vec P_0 - \\vec P_3\\right) + \\left(\\vec P_2 - \\vec P_1\\right).\n\\end{array}\n\\end{equation*}\n\nEach corner has a normal vector associated with it\n\\begin{equation*}\n\\begin{array}{lcl}\n\\vec N_0 &=& \\vec L_3 \\times \\vec L_0\\\\\n\\vec N_1 &=& \\vec L_0 \\times \\vec L_1\n\\end{array}\n\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\vec N_2 &=& \\vec L_1 \\times \\vec L_2\\\\\n\\vec N_3 &=& \\vec L_2 \\times \\vec L_3\n\\end{array}\n\\end{equation*}\nand these vectors can be normalized to unit length:\n\\begin{equation*}\n\\begin{array}{lcl}\n\\hat n_0 &=& \\dfrac{\\vec N_0}{\\normvec{ N_0}}\\\\\n\\hat n_1 &=& \\dfrac{\\vec N_1}{\\normvec{ N_1}}\n\\end{array}\n\\rule{10em}{0pt}\n\\begin{array}{lcl}\n\\hat n_2 = \\dfrac{\\vec N_2}{\\normvec{ N_2}}\\\\\n\\hat n_3 = \\dfrac{\\vec N_3}{\\normvec{ N_3}}.\n\\end{array}\n\\end{equation*}\n\nIn addition to corner normals, we can define a ``center'' normal\n\\begin{equation*}\n\\vec N_{c} = \\vec X_1 \\times \\vec X_2\n\\end{equation*}\nand its unit-length companion\n\\begin{equation*}\n\\hat n_{c} = \\frac{\\vec N_{c}}{\\normvec{ N_{c}}}\n\\end{equation*}\nIn the event that the vertices of the quadrilateral are all\ncontained in the same plane, all the unit normals will be\nequivalent (i.e., $\\hat n_0 = \\hat n_1 = \\hat n_2 = \\hat n_3 = \\hat n_c$).\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[width=2in]{quad-vertex-areas}\n  \\caption{Areas associated with each quadrilateral vertex.%\n                                                    \\label{f:quad-vertex-areas}}\n\\end{figure}\n\nIt is often useful to partition the quadrilateral into four areas, one\nassociated with each vertex. These areas are denoted\n\\begin{equation*}\n\\alpha_k = \\hat n_c \\cdot \\vec N_k\\rule{10em}{0pt}\\forall k\\in\\{0,1,2,3\\}\n\\end{equation*}\nand are shown in Figure~\\ref{f:quad-vertex-areas}.\nIf $\\vec N_c = \\vec 0$, then the signed corner areas are undefined,\nand all the metrics which depend on $\\alpha_k$ are undefined.\nIn this case, we set $\\alpha_k = 0$ for $k=0,1,2,3$.\nWhen $\\alpha_k \\leq 0$ for any one or more $k$, the quadrilateral\nis degenerate.\nThis occurs when\nan element is so small its edge length approach the machine epsilon or\nwhen its vertices are collinear or\nwhen its vertices define a concave quadrilateral.\n\n% -------------------Metric Table-------------------\n\\newcommand{\\quadmetrictable}[8]{%\n  \\begin{center}\n  \\begin{tabular}{ll}\n    \\multicolumn{2}{r}{\\textbf{\\sffamily\\Large quadrilateral #1}}\\\\\\hline\n    Dimension:             & #2\\\\ \n    Acceptable Range:      & #3\\\\ \n    Normal Range:          & #4\\\\ \n    Full Range:            & #5\\\\ \n    $q$ for unit square:   & #6\\\\\n    Reference:             & #7\\\\\n    \\verd\\ function:       & \\texttt{#8}\\\\ \\hline\n  \\end{tabular} \n  \\end{center}\n}\n\n\\newpage \\input{QuadArea}\n\\newpage \\input{QuadAspectRatio}\n\\newpage \\input{QuadCondition}\n\\newpage \\input{QuadDistortion}\n\\newpage \\input{QuadEdgeRatio}\n\\newpage \\input{QuadJacobian}\n\\newpage \\input{QuadMaxAspectFrobenius}\n\\newpage \\input{QuadMaximumAngle}\n\\newpage \\input{QuadMaximumEdgeRatio}\n\\newpage \\input{QuadMedAspectFrobenius}\n\\newpage \\input{QuadMinimumAngle}\n\\newpage \\input{QuadOddy}\n\\newpage \\input{QuadRadiusRatio}\n\\newpage \\input{QuadRelativeSizeSquared}\n\\newpage \\input{QuadScaledJacobian}\n\\newpage \\input{QuadShape}\n\\newpage \\input{QuadShapeAndSize}\n\\newpage \\input{QuadShear}\n\\newpage \\input{QuadShearAndSize}\n\\newpage \\input{QuadSkew}\n\\newpage \\input{QuadStretch}\n\\newpage \\input{QuadTaper}\n\\newpage \\input{QuadWarpage}\n\n", "meta": {"hexsha": "ea30b2639b76550146eac4188d03aad96f6df1c3", "size": 5640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/Quad.tex", "max_stars_repo_name": "jcfr/VTK", "max_stars_repo_head_hexsha": "a6e753dfa791153bdf79c052956197ce612ed0f9", "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/Quad.tex", "max_issues_repo_name": "naucoin/VTKSlicerWidgets", "max_issues_repo_head_hexsha": "105cadce86576ea433f91347078a7815852c21c6", "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/Quad.tex", "max_forks_repo_name": "naucoin/VTKSlicerWidgets", "max_forks_repo_head_hexsha": "105cadce86576ea433f91347078a7815852c21c6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-16T01:07:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T13:07:34.000Z", "avg_line_length": 32.6011560694, "max_line_length": 87, "alphanum_fraction": 0.6723404255, "num_tokens": 2030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6347436857761347}}
{"text": "\\section{Linear Spectral Clustering Superpixel}\n\n\\begin{flushleft}\n    \\author{\n    Jiansheng Chen, \n    \\emph{Member, IEEE}, \n    Zhengqin Li,\n    \\emph{Student Member, IEEE}, \n    Bo Huang \n}\n\\end{flushleft}\n\n\\begin{center}\n    \\emph{IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 26, NO. 7, JULY 2017}\n\\end{center}\n\n\\subsection{INTRODUCTION}\nThe introduced technique is called SUPERPIXEL. Widely used in image \nprocessing for particular tasks such as image segmentation, image analysis, \nimage classification, target tracking, 3D reconstruction, surface retrieval and \nobject proposal. The purpose of this technique is to be able to group the \npixels into groups that delimit the edges of an object in order to be able \nto extract its content. Compared to other methods already existing in the \nstate of the art, characteristics such as size, number of superpixels and shape \nare not considered. The purpose of the elaborate story is to reduce the \ncomputational complexity. The three targets that must be satisfied by each \nsuperpixel algorithm are:\n\\begin{enumerate}\n    \\item Adhere well to the edges without forming overlaps on objects;\n    \\item Have a pre-processing technique useful to improve efficiency;\n    \\item Consider global information.\n\\end{enumerate}\nThe proposed system, called Linear Spectral Clustering (LSC), manages to \nsatisfy all the previous points with a high memory efficiency. In LSC, each \npixel is mapped to a point within a ten-dimensional space of characteristics \nin which the weighted K-means is applied for segmentation. \n\n\\subsection{LSC SUPERPIXEL}\nThe study focuses on the relationships between the results returned by the \noptimization functions, and those returned by two other equations. If the results \nare equivalent, then weighted k-means clustering can replace the highly \ncomplex eigen based method.\n\n\\subsubsection{Mathematical Backgrounds}\nThe task of LSC is to discover the relationships that exist between the objective \nfunctions ($ F_{N_{cuts}} $) (\\ref{FNcuts}), of the normalized cuts, and the objective functions \nof the weighted K-means ($ F_{km}$) (\\ref{Fkm}). \n\\begin{equation} \\label{Fkm}\n    F_{km} = \\sum_{k=1}^K\\sum_{p\\in\\pi_k}\\omega(p)= || \\phi(p)-m_k ||^2 \n\\end{equation}\n\\begin{equation} \\label{Centroid}\n    m_k = \\frac{\\sum_{q\\in\\pi_k}\\omega(q)\\phi(q)}{\\sum_{q\\in\\pi_k}\\omega(q)}\n\\end{equation}\n\\begin{equation} \\label{FNcuts}\n    F_{N_{cuts}} = \\frac{1}{K}\\sum_{k=1}^K\\frac{\\sum_{p\\in\\pi_k}\\sum_{q\\in\\pi_k}W(p,q)}{\\sum_{p\\in\\pi_k}\\sum_{q\\in{V}}W(p,q)}\n\\end{equation}\nWhere $ m_k $ (\\ref{Centroid}) represent the average point, or centroid, of each cluster. Within \nthe formulation of normalized cuts, each data Point corresponds to a node \nwithin a graph \\emph{G = (V, E, W)} where \\emph{V} is the set of all nodes, \\emph{E} represents \nthe set of all edges connected and \\emph{W} represents the result returned by a \nsimilarity function between nodes. The criterion of normalized cuts is based \non maximizing the $ F_{N_{cuts}} $ function. The minimization or maximization problems \nare called \\emph{optimization problems} which can be solved by using a positive kernel of \na matrix. To see the relationship between the two functions, the Dhillon's concept \\cite{0781426526} is extended, to obtain {\\bfseries Corollary \\ref{Corollary1}}:\n\n\\begin{corollary} \\label{Corollary1}\n    Optimizations of the objective functions of the weighted K-means\n    and the normalized cuts are mathematically equivalent if (\\ref{eq4}) and (\\ref{eq5}) \n    hold simultaneously. The symbol $ \\cdot $ stands for inner product.\n\\end{corollary}\n\n\\begin{equation} \\label{eq4}\n    \\omega(p)\\phi(p) \\cdot \\omega(q)\\phi(q) = W(p,q), \\forall p,q \\in V\n\\end{equation}\n\n\\begin{equation} \\label{eq5}\n    w(p) = \\sum_{q \\in V} W(p,q), \\forall p \\in V\n\\end{equation}\n\nAfter making various derivative calculations, $ F_{km} $ can be seen as: \n\\begin{equation}\n    F_{km} = C - K * F_{N_{cuts}} \n\\end{equation}\n\nFrom the above definition it is possible to note that the minimization of \n$ F_{km} $ is equivalent to the maximization of $ F_{N_{cuts}} $. Specifically, both $ F_{km} $ and \n$ F_{km} $ perform an identical partitioning of the n-dimensional space defined by \nthe function $ \\phi $.\n\n\\subsubsection{LSC Algorithm}\nThe purpose of LSC is to find the correct positive function W (p, q) in order \nto satisfy {\\emph{Corollary \\ref{Corollary1}}}. To achieve this, the Euclidean distance calculation \nwas used as an index of similarity between two pixels. Each pixel \\emph{p} is represented \nby five dimensional vectors \\emph{(l, a, b, x, y)} in the CIELAB color space, where \\emph{l} \nepresents brightness, \\emph{a} and \\emph{b} represent opposite colors and \\emph{x} and \\emph{y} represent\nthe coordinates of the plane. The similarity function, in order to satisfy \nthe positivity condition required by (\\ref{eq4}), is extended as a convergent Fourier series: \n\\begin{eqnarray}\n    W(p,q) & = & C_s^2(\\cos \\frac{\\pi}{2}(x_p-x_q)+\\cos\\frac{\\pi}{2}(y_p-y_q)) \\nonumber \\\\\n           &   &  + C_c^2(\\cos \\frac{\\pi}{2}(l_p-l_q)+\\cos\\frac{\\pi}{2}(\\alpha_p-\\alpha_q) \\nonumber \\\\\n           &   &  + \\cos\\frac{\\pi}{2}(\\beta_p-\\beta_q)x2.55^2)    \n\\end{eqnarray}\n\nWhere $ C_s $ and $ C_c $ are used to control the relative significance of\ncolor and spatial information. The mapping function that maps a point in a ten-dimensional\nspace is as follows:\n\\begin{equation}\n    \\begin{split}\n        \\phi(p) = \\frac{1}{\\omega(p)}[C_c\\cos\\frac{\\pi}{2}l_p, C_c\\sin\\frac{\\pi}{2}l_p, 2.55C_c\\cos\\frac{\\pi}{2}\\alpha_p \\\\\n        x 2.55C_c\\sin\\frac{\\pi}{2}\\alpha_p, 2.55C_c\\cos\\frac{\\pi}{2}\\beta_p, 2.55C_c\\sin\\frac{\\pi}{2}\\alpha_p, \\\\\n        x C_s\\cos\\frac{\\pi}{2}x_p, C_s\\sin\\frac{\\pi}{2}x_p, C_s\\cos\\frac{\\pi}{2}y_p, C_s\\sin\\frac{\\pi}{2}x_p]\n    \\end{split}\n\\end{equation}\nIn the defined space, the weighted K-mean clustering as well as being \nequivalent to the Fncuts optimization function, creates the optimal context to \noptimize it. The LCS algorithm takes two parameters as input; The image \nto be segmented and the preferred K number of superpixels that the \nalgorithm will have to produce. Each \\emph{K} pixel represents the central search point \nand its vector will be used as the weighted initial vector of the corresponding \ncluster. Each pixel is assigned to te cluster for which the weightedd mean \nis closet to the picel's vector in the ten-dimensional feature space. At each \nassignment, the weighted average and the central point will be updated until \nthe system convergence. Each cluster will form a superpixel and each of \nthese, if considered spatially small, can be joined to other clusters to form \na larger cluster. The total complexity achieved by LSC is \\emph{O(kN + nZ)}, where \n\\emph{k} represents the number of iterations, \\emph{N} the number of pixels, \\emph{n} the average \nnumber of adjacent neighbors and \\emph{z} represents the number of small \nisolated superpixels to be joined. This complexity, when compared with that \nachieved by other superpixel systems, is the lowest.\n\n\\subsection{COMPARATIVE EXPERIMENTS}\nIn order to evaluate the quantitative goodness of the proposed algorithm, \nthree comparison metrics are used: under segmentation error (\\emph{UE}) \\cite{0781426514}, boundary \nrecall (\\emph{BR}) and achievable segmentation accuracy (\\emph{ASA}). The \ngoal is to have a low UE value, while it is preferable to have high values in BR \nand ASA. A low percentage of UE indicates that the detected boundary is made \nup of a small amount of pixels not belonging to the object to be delimited. \nA segmentation is correct when at least two boundary pixel fall from at least \none superpixel boundary point. A high BR index indicates that the better \nsegmentation is obtained. On the other hand, the ASA metric indicates the \nlevel of accurancy achieved in the segmentation pashe of contour, obtained \nthanks to the various labels (ground-truth) placed on each superpixel. A \nhigh ASA value indicates that superpixel adapt well to objects. The experiments \nwere conducted on a set of 300 images belonging to the Barkeley \nSegmentation Database \\cite{0781426515}.\n\n\\subsubsection{Parameter Selection}\nWhen the ratio $ r = C_s / C_c $ is high, then the neighboring pixels tend to be \naggregated into a single cluster, forming superpixels with a regular shape \nand therefore potentially incorrect. On the other hand, when \\emph{r} is small, \nthen it means that the pixels tend to have similar colors, therefore both \nwill be grouped into a single cluster, forming irregular superpixels. In order to \nchoose an optimal r value, it is necessary to introduce a metric that calculates \nthe average  values of shape regularity. The average value of shape regularity \nis measured with a metric called superpixel compactness \\emph{(CP)} \\cite{0781426533} which is \ninversely proportional to the BR index. So as CP increases, the likelihood \nof regular shapes being created is greater and at the same time worse segmentation \nwill be generated as BR decreases. The r value will be chosen \nwhen the value resulting from $ (1-BR / CP) $ is the lowest. Therefore \\emph{r} can be \nused as a correction parameter. In order to control the search range of the \nK-means cluster algorithm, a $ \\tau $ parameter is used which is equal to at least \n0.5. This value will be multiplied by the spatial components, vertical ($ v_x $) \nand horizontal ($ v_y $), of the vector belonging to each point in space. Clearly, \nas this parameter increases, the size of each superpixel generated and the \ngeneral $ O(N) $ complexity will increase. In the experiments conducted, $ \\tau $ is \nset to 1.\n\n\\subsubsection{Comparison With State-of-the-Art}\nThe proposed system is compared with other existing superpixels algorithms \nin the state of the art. A comparison, in terms of boundary adherence and \nspeed in segmentation (Table \\ref{table superpixels}), when the number of superpixels \\emph{K} generated \nis 400. With a relatively high \\emph{K} number, LSC achieves the best \nperformance.\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{*{9}{|c}|}%%{|c|c|c|c|c|c|c|c|c|}\n        \\hline\n        & EneOpt0 & SEEDS & ERS & Lattices & NCuts & SLIC & Turbo & LSC \\\\\n        \\hline\n        \\bfseries{ADERENCE TO BOUNDARY} & & & & & & & & \\\\\n        \\emph{Under segmentation error} & 0.230 & 0.197 & 0.198 & 0.303 & 0.220 & 0.213 & 0.277 & \\bfseries{0.190}\\\\\n        \\emph{Boundary recall} & 0.765 & 0.918 & 0.920 & 0.811 & 0.789 & 0.837 & 0.739 & \\bfseries{0.926}\\\\\n        \\emph{Achievable segmentation accuracy} & 0.950 & 0.960 & 0.959 & 0.933 & 0.956 & 0.956 & 0.943 & \\bfseries{0.962}\\\\\n        \\hline\n        \\bfseries{SEGMENTATION SPEED} & & & & & & & & \\\\\n        \\emph{Computational complexity} & $ O(N^3/K^2) $ & $ O(N) $ & $ O(N^2 \\lg{N}) $ & $ O(N^{\\frac{3}{2}} \\lg{N}) $ & $ O(N^{\\frac{3}{2}}) $ & $ O(N) $ & $ O(N) $ & $ O(N) $\\\\\n        \\emph{Average time per image} & 3.35s & \\bfseries{0.0935}s & 0.969s & 0.284s & 93.4s & 0.125s & 6.61s & 0.334s\\\\\n        \\hline\n    \\end{tabular}\n    \\end{adjustbox}\n    \\caption{Performance metrics superpixel segmentation algorithms at K=400}\n    \\label{table superpixels}\n\\end{table}\nAs we can see from the results, the worst algorithm, in terms of time, \nis \\emph{NCuts}, while a good algorithm, which ranks second before \\emph{LSC}, is \\emph{SLIC}. \nUnlike the algorithm studied, SLIC uses an iterative K-means clustering \nperformed inside different feature spaces, based only on local characteristics. \nOn the other hand, LSC is able to use local and global features thanks to the \n$ \\phi $  mapping function, all to have a better segmentation. However, when \nK = 400, the CP value of the \\emph{ERS} \\cite{0781426508} and \\emph{SEEDS} \\cite{0781426509} algorithms are 0.151 \nand 0.280 respectively, while the CP value of LSC is 0.366. Looking at the data \nin the table, this makes us understand how LSC is able to have a better BR \nvalue despite having a higher CP value than the previous algorithms, this \nrepresents the strength of this algorithm. \n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width = 1 \\linewidth]{images/paper2/superpixelsComparison.png}\n    \\centering\n    \\caption{Superpixel results from different algorithms. (a) SEEDS. (b) NCuts. (c) SLIC. (d) ERS. (e) LSC.}\n    \\label{fig: superpixelsComparison}\n\\end{figure}\n\n\\subsection{APPLICATIONS}\n\\subsubsection{Class Segmentation}\nAn SVM-based multi-class object classifier trained on the histograms of the generated \nsuperpixels was used. In order for similar superpixels to have the same \nlabel, a conditional random field (CRF) is used to refine the segmentation. \nThanks to this model, the prediction made by the classifier will also \ntake into account the neighbors superpixels to the one to be labeled. The \nmethod used is that proposed in \\cite{0781426534} where the main unit of measurement is \nthat of the superpixel. In \\cite{0781426534} the quick shift (\\emph{QS}) algorithm is used for the \ngeneration of superpixels. The experiments were conducted on the \\emph{Graz-02} \ndatabase \\cite{0781426535} containing already labeled objects. The accuracy achieved by \nthe QS, ERS, SLIC and LSC algorithms is that shown in the Table \\ref{table accuracy}, while \nthe various segmentations, obtained from each of these, are visible in the \nfigure \\ref{fig: superpixelSegmentation}. As you can see, LSC performs a better segmentation than the other \nmethods, this happens because the information obtained from the histograms \nbelonging to the SIFT of different superpixel generated are used. In this way \nthere is a better adherence to the boundary of each object in addition the \nsuperpixels take on a highly irregular shape for objects in the foreground and \nmore regular for the background.\n\\begin{table}[h!]\n    \\centering\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{*{5}{|c}|}%%{|c|c|c|c|c|}\n        \\hline\n        & QS & ERS & SLIC & LSC\\\\\n        \\hline\n        bike & 72.2 & 74.2 & 76.3 & \\bfseries{76.9}\\\\\n        cars & 72.2 & 74.7 & 72.5 & \\bfseries{76.8}\\\\\n        person & 66.3 & 66.5 & 66.7 & \\bfseries{67.0}\\\\\n        \\hline\n    \\end{tabular}\n    \\end{adjustbox}\n    \\caption{Accuracy using different superpixels algorithms.}\n    \\label{table accuracy}\n\\end{table}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width = 1 \\linewidth]{images/paper2/superpixelAlgo.png}\n    \\centering\n    \\caption{Segmentation using different superpixels algorithms. (a) Original Image. (b) QS. (c) ERS. (d) SLIC. (e) LSC. (f)Ground Truth.}\n    \\label{fig: superpixelSegmentation}\n\\end{figure}\n\n\\subsubsection{Weakly Supervised Semantic Segmentation}\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width = 0.6 \\linewidth]{images/paper2/semanticSegmentation.png}\n    \\centering\n    \\caption{Weakly supervised semantic segmentation. (a) A training image with bounding boxes. (b) Output of soft-max layer of $ FCN_c $. (c) Coarse semantic segmentation result. (d) Superpixels with higher probability of foreground. (e) Fore-/Background segmentation result after iterative optimization. (f) Refined semantic segmentation result.}\n    \\label{fig: flowchartSemanticSegmentation}\n\\end{figure}\nAs the title suggests, the LSC algorithm is able to improve semantic segmentation \nwith a weakly supervised method. The images of the PASCAL \nVOC2012 database \\cite{0781426538} are used as tests, in which there are 1449 images\ncontaining labeled objects and the remaining 10582 images containing only \nbounding boxes used for training and validation. The flow chart of the proposed \nmethod can be seen in figure (\\ref{fig: flowchartSemanticSegmentation}). The steps are as follows: coarse \nsemantic segmentation, fore-/background segmentation and refined semantic \nsegmentation. In the first step there is a completely convolutional network, \ncalled $ FCN_c $, trained with images containing only the bounding boxes which \nwill be restricted in order to eliminate the border pixels that seem to be \nirrelevant. These new squares are used as positive examples, while the cut \nparts are used as negative examples. For each superpixel \\emph{p} generated within \neach bounding box $ i_{th} $, we set $ c_p^i $ as the average value of the colors of each \npixel within the superpixel and then we set $ l_p^i $ as the label to be estimated (0 \nbackgroud, 1 foreground). The separation of the background from the \nforeground is seen as an optimization problem\n\\begin{equation}\n    \\begin{split}\n        \\argmax\\limits_{l} \\sum_i\\sum_p(E_a(l_p^i,c_p^i) + \\lambda_1E_c(l_p^i, FCN_c)\\\\\n        + \\lambda_2\\sum_{q\\in N(p)}E_s(l_p^i,c_p^i,l_q^i,c_q^i)) \n    \\end{split}\n\\end{equation}\nWhere $ E_s $ is useful for capturing the smoothness prior produced by a covariance \nmatrix, $ E_c $ represents the probability that the superpixel belongs \nto the foreground, while $ E_a $, also called the appearance model, represents \nthe probability that a superpixel belongs to the background or foreground. \nAfter several iterations, which have the purpose of updating the foreground \nand background labels of the superpixels, a correct segmentation will be \nobtained. The segmentation obtained will be used to train a convolutional \nnetwork called $ FCN_r $ which is combined with a dense CRF model useful for \nformulating the final semantic segmentation model. This system is also \ncalled $ Joint_{sp} $. The model is compared with other supervivided methods \\cite{0781426541}, \na strong one, called \\emph{Strong}, and a weak one called \\emph{Bbox-seg}, the results of \nwhich can be seen in figure \\ref{fig: semanticSegmentation}. While the accuracy, measured with the intersection \nover-union (\\emph{IOU}), achieved by the systems mentioned is visible in the \ntable \\ref{table accuracy semantic segmentation}.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width = 0.7 \\linewidth]{images/paper2/segmentationAlgo.png}\n    \\centering\n    \\caption{Semantic segmentation. (a) Input image. (b) Strong. (c) Bbox-seg. (d) $ Joint_{sp} $ (LSC) }\n    \\label{fig: semanticSegmentation}\n\\end{figure}\n\n\\begin{table}[h!]\n    \\centering\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{*{3}{|c}|}%%{|c|c|c|}\n        \\hline\n        Strong & Bbox-seg & $ Joint_{sp} $ \\\\\n        \\hline\n        62.5 & 60.6 & \\bfseries{64.0} \\\\\n        \\hline\n    \\end{tabular}\n    \\end{adjustbox}\n    \\caption{Semantic segmentation accuracy in terms of Mean IOU (\\%)}\n    \\label{table accuracy semantic segmentation}\n\\end{table}\n\n\\subsection{CONCLUSIONS}\nLike all superpixel algorithms, there are still two problems that need to be \nsolved. The first concerns the number K of superpixels to be generated. Unfortunately, \nthis parameter still has to be entered manually and today there \nis no stable method that can establish a specific K number of superpixels on \neach type of image. The second, on the other hand, concerns the study of \nnew similarity techniques, instead of the one already used in this article \n($ W(p,q) $), useful for improving the performance, in terms of segmentation, \nof LSC.", "meta": {"hexsha": "484d23ab53bf74fe5ab9051c6cafc2fd8d3631a4", "size": 19103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/paper_2.tex", "max_stars_repo_name": "flavioforenza/Intelligent-Systems-project", "max_stars_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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": "papers/paper_2.tex", "max_issues_repo_name": "flavioforenza/Intelligent-Systems-project", "max_issues_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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": "papers/paper_2.tex", "max_forks_repo_name": "flavioforenza/Intelligent-Systems-project", "max_forks_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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.8541666667, "max_line_length": 348, "alphanum_fraction": 0.7340208344, "num_tokens": 5300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.634743675102559}}
{"text": "\\section{Spatial Discretization}\\label{se:SpatialDiscretization}\n\nWe discretize the two-moment model with a simple first-order finite volume method to illustrate how the closure affects the realizability-preserving property of the method.  \nBy assuming that the moments at time level $t^{n}$ ($\\bcM^{n}$) satisfy the bounds in Eq.~\\eqref{eq:MomentsBounds}, our goal is to identify sufficient conditions such that the moments at time level $t^{n+1}$ ($\\bcM^{n+1}$) also satisfy the bounds.\nTo simplify, we limit the discussion to one spatial dimension and employ a uniform Cartesian mesh.  \n(The extension to multiple spatial dimensions and high-order discretization using the discontinuous Galerkin method is given in~\\cite{chu_etal_2018}.)\n\nWe divide the spatial domain $D$ into $N$ uniform cells and denote the $i$-th cell by $\\bK_{i}$, with $i = 1,\\ldots,N$; i.e.,\n\\begin{equation*}\n  D = \\cup_{i = 1}^{N} \\bK_{i} \\quad \\text{with} \\quad\n  \\bK_{i}=\\{\\,x : x\\in(x_{i-1/2}, x_{i+1/2})\\},\n\\end{equation*}\nand cell width $\\dx = D/N$.  \nThe cell-average of the moments is defined as\n\\begin{equation}\n  \\bcM_{i} = \\dfrac{1}{\\dx} \\int_{\\bK_i}\\bcM dx.\n\\end{equation}\nIntegrating Eq.~\\eqref{eq:momentEquations} over each cell $\\bK_{i}$ gives\n\\begin{equation}\n  \\dfrac{d \\bcM_{i}}{d t} = - \\dfrac{1}{\\dx} \\left( \\widehat{\\bcF}(\\bcM_{i},\\bcM_{i+1}) -  \\widehat{\\bcF}(\\bcM_{i-1},\\bcM_{i})\\right) + \\f{1}{\\tau}\\,\\cC(\\bcM_{i}),\n  \\label{eq:SemiDiscretizatedMomentEquation}\n\\end{equation}\nwhere $\\widehat{\\bcF}(\\vect{\\cM}_{a},\\vect{\\cM}_{b})$ is the numerical flux and $\\f{1}{\\tau}\\,\\cC(\\bcM_{i})$ is the collision term evaluated with $\\bcM_{i}$.\nIn this paper we use the global Lax-Friedrichs flux (setting the largest absolute eigenvalue of the flux Jacobian to one):\n\\begin{equation}\n  \\widehat{\\bcF}_{\\LF}(\\vect{\\cM}_{a},\\vect{\\cM}_{b})\n  =\\f{1}{2}\\,\\big(\\,\\bcF(\\vect{\\cM}_{a})+\\bcF(\\vect{\\cM}_{b})-(\\,\\vect{\\cM}_{b}-\\vect{\\cM}_{a}\\,)\\,\\big).\n  \\label{eq:Lax-Friedrichs flux}\n\\end{equation}\nBy treating the transport term explicitly with forward Euler and the collision term implicitly with backward Euler, we have\n\\begin{align}\n  \\bcM_{i}^{n+1} = \\widetilde{\\bcM}^{n}_{i} + \\f{\\dt}{\\tau}\\,\\cC(\\bcM^{n+1}_{i}),\n  \\label{eq:MomentIMEX}\n\\end{align}\nwhere we have defined\n\\begin{align}\n  \\widetilde{\\bcM}^{n}_{i} \n  & = \\bcM_{i}^{n} - \\frac{\\dt}{\\dx} \\left( \\widehat{\\bcF}_{\\LF}(\\bcM^{n}_{i},\\bcM^{n}_{i+1}) -  \\widehat{\\bcF}_{\\LF}(\\bcM^{n}_{i-1},\\bcM^{n}_{i})\\right)\\nonumber \\\\\n  & = (1-\\beta)\\bcM_{i}^{n} + \\beta\\left[ \\f{1}{2}\\left( \\bcM^{n}_{i+1}-\\bcF(\\bcM^{n}_{i+1})\\right)  + \\f{1}{2}\\left( \\bcM^{n}_{i-1}+\\bcF(\\bcM^{n}_{i-1})\\right)\\right],\n  \\quad\\beta = \\frac{\\dt}{\\dx}.  \n\\label{eq:widetildeM}\n\\end{align}\n\nConsidering Eqs.~\\eqref{eq:MomentIMEX} and \\eqref{eq:widetildeM} and assuming that $\\bcM_{i}^{n}$ is realizable for all $i$, it can be shown (Lemma~3 in~\\cite{chu_etal_2018}) that $\\bcM^{n+1}_{i}$ is realizable provided $\\f{\\dt}{\\tau} > 0$. \n%and $\\widetilde{\\bcM}^{n}_{i}$ is realizable.  \nIn Eq.~\\eqref{eq:widetildeM}, if $\\beta \\in [0,1]$, $\\widetilde{\\bcM}^{n}_{i}$ is expressed as a convex combination of $\\bcM_{i}^{n}$ and the expression in the square brackets on the right-hand side of Eq.~\\eqref{eq:widetildeM}.  \nIt follows that $\\widetilde{\\bcM}^{n}_{i}$ is realizable if the expression inside the square brackets is realizable.  \nIt can be shown (Lemma~2 in~\\cite{chu_etal_2018}) that the expression in square brackets is realizable for a distribution satisfying $f\\in[0,1]$.  \nFor the two-moment model considered here, realizability depends on the algebraic closure.  \nSpecifically, if $\\bcM_{i}^{n}$ is realizable and the Eddington factor satisfies the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds}, then $\\bcM^{n+1}_{i}$ is realizable provided $\\beta \\in [0,1]$.  \nThus, realizability of $\\bcM^{n+1}_{i}$ requires both a closure based on Fermi-Dirac statistics and a Courant-Friedrichs-Lewy (CFL) condition $\\dt\\le\\dx$.  ", "meta": {"hexsha": "c80ebf0074ae5770f6aef8e74f5279443ea7ac3f", "size": 3943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/Astronum_2018/sections/SpatialDiscretization.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/Astronum_2018/sections/SpatialDiscretization.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/Astronum_2018/sections/SpatialDiscretization.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": 77.3137254902, "max_line_length": 247, "alphanum_fraction": 0.6796855186, "num_tokens": 1446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6346197297931168}}
{"text": "\\chapter{Cumulative distribution function of the Durbin-Watson statistic}\n\nLet us consider the linear regression model \\[ y_i = \\beta_0 +\n\\beta_1x_{i1} + \\ldots + \\beta_kx_{ik} + \\xi_i, \\] $i = 1, \\ldots, n$,\n$k \\geq 1$, $n > k + 1$, where $\\xi_i$ are independent identically\ndistributed normal variables with zero mean, or $y = X\\beta + \\xi$. The\nleast squares estimate of $\\beta$ is $b = (X^TX)^{-1}X^Ty$ and the\nvector of residuals from the regression is $e = y - Xb$. The\nDurbin-Watson $d$ statistic is defined by \\[ d = \\frac{\\sum_{i = 2}^n\n  (e_i - e_{i - 1})^2}{\\sum_{i = 1}^n e_i^2} \\] It is shown in\n\\cite[p.~426]{durbin-watson-1950} that $d_L \\leq d \\leq d_U$, where \\[\nd_L = \\frac{\\sum_{i = 1}^{n - k - 1} \\lambda_i \\zeta_i^2} {\\sum_{i =\n    1}^{n - k - 1} \\zeta_i^2}, \\] \\[ d_U = \\frac{\\sum_{i = 1}^{n - k -\n    1} \\lambda_{i + k} \\zeta_i^2} {\\sum_{i = 1}^{n - k - 1}\n  \\zeta_i^2}, \\] \\[ \\lambda_i = 2\\left(1 - \\cos \\frac{\\pi i}{n}\\right),\n\\quad i = 1, \\ldots, n - 1, \\] and $\\zeta_1, \\ldots, \\zeta_{n - 1}$ are\nindependent standard normal variables. The cumulative distribution\nfunctions of $d_L$ and $d_U$ are\n\\begin{align} \\label{eq:dwcdfdL}\n  \\Pr(d_L < x) &= \\Pr\\left(\\sum_{i = 1}^{n - k - 1} (x - \\lambda_i)\n  \\zeta_i^2 > 0 \\right), \\\\\n  \\label{eq:dwcdfdU}\n  \\Pr(d_U < x) &= \\Pr\\left(\\sum_{i = 1}^{n - k - 1} (x - \\lambda_{i + k})\n  \\zeta_i^2 > 0 \\right).\n\\end{align}\n\nIn both cases, the probabilities~(\\ref{eq:dwcdfdL})\nand~(\\ref{eq:dwcdfdU}) are of the form \\[ \\Pr\\left(\\sum_{i = 1}^m w_i\n\\zeta_i^2 > 0 \\right), \\] where $w_i$, $i = 1, \\ldots, m$, $m > 0$, are\nthose $x - \\lambda_i$ or $x - \\lambda_{i + k}$ which are not equal to 0.\nThey can be calculated by the formula (3.2) of\n\\cite[p.~422]{imhof-1961}, which states that if $w_i \\neq 0$, $i = 1,\n\\ldots, m$, then \\[ \\Pr\\left(\\sum_{i = 1}^m w_i \\zeta_i^2 > 0 \\right) =\n\\frac{1}{2} + \\frac{1}{\\pi} \\int_0^{+\\infty} f(u) du, \\] where\n\\begin{align*}\n  f(u) &= \\frac{\\sin \\theta(u)}{u \\rho(u)}, \\\\\n  \\theta(u) &= \\frac{1}{2} \\sum_{i = 1}^m \\arctan(w_iu), \\\\\n  \\rho(u) &= \\prod_{i = 1}^m (1 + w_i^2u^2)^{1 / 4}.\n\\end{align*}\nIt is shown in (3.3) of \\cite[p.~423]{imhof-1961} that\n\\begin{align}\n  \\nonumber\n  \\lim_{u \\rightarrow 0} f(u) &= \\frac{1}{2} \\sum_{i = 1}^m w_i, \\\\\n  \\nonumber\n  \\lim_{u \\rightarrow \\infty} \\theta(u) &= \\frac{\\pi}{4}\n  \\sum_{i = 1}^m \\sgn w_i, \\\\\n  \\label{eq:dwcdftail}\n  |\\frac{1}{\\pi} \\int_u^{+\\infty} f(u) du| & \\leq\n  \\frac{1}{\\pi} \\frac{2}{m} u^{-m / 2} \\prod_{i = 1}^m |w_i|^{-1 / 2}.\n\\end{align}\n\nTo achieve the result $\\mathit{prob}$ and the accuracy $\\mathit{eps}$\nsuch that\n\\begin{equation} \\label{eq:dwcdfprob}\n  \\mathit{prob} - \\mathit{eps} \\leq \\Pr \\left( \\sum_{i = 1}^m w_i\n  \\zeta_i^2 > 0 \\right) < \\mathit{prob} + \\mathit{eps}\n\\end{equation}\nwe put\n\\begin{equation} \\label{eq:dwcdfupperlimit}\n  u \\geq (\\frac{1}{\\pi} \\frac{2}{m} (\\prod_{i = 1}^m |w_i|^{-1 / 2}) /\n  (\\mathit{eps} / 2))^{2 / m}\n\\end{equation}\nso that by~(\\ref{eq:dwcdftail}) we have \\[ |\\frac{1}{\\pi}\n\\int_u^{+\\infty} f(u) du| \\leq \\mathit{eps} / 2 \\] and then calculate\n\\begin{equation} \\label{eq:dwcdfintegral}\n  \\frac{1}{\\pi} \\int_0^u f(u) du\n\\end{equation}\nby the Simpson method until two consecutive approximations differ no\nmore than $\\mathit{eps} / 2$. To have four significant digits after the\ncomma, we put $\\mathit{eps} = 0.000049$.\n\nThe function should not be used for low values of $n - k - 1$, say 1, 2,\n3, as integration~(\\ref{eq:dwcdfintegral}) fails. For $n - k - 1 = 1$ we\nhave\n\\begin{align*}\n  \\Pr(d_L < x) = 0 & \\quad \\mathrm{for} \\quad x \\leq \\lambda_1, \\\\\n  \\Pr(d_L < x) = 1 & \\quad \\mathrm{for} \\quad x > \\lambda_1, \\\\\n  \\Pr(d_U < x) = 0 & \\quad \\mathrm{for} \\quad x \\leq \\lambda_{1 + k}, \\\\\n  \\Pr(d_U < x) = 1 & \\quad \\mathrm{for} \\quad x > \\lambda_{1 + k}.\n\\end{align*}\nFor possible solution to this problem, see~\\cite{farebrother-1984}. See\nalso~\\cite{savin-white-1977}.\n", "meta": {"hexsha": "c7b5b6e5bbd0b8abc7b91a46b7716b2ac491c7ac", "size": 3872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/drbnwtsn.tex", "max_stars_repo_name": "shgalus/shg", "max_stars_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-05-21T04:14:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-31T17:15:15.000Z", "max_issues_repo_path": "doc/drbnwtsn.tex", "max_issues_repo_name": "shgalus/shg", "max_issues_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-05-21T05:31:04.000Z", "max_issues_repo_issues_event_max_datetime": "2015-05-21T05:31:04.000Z", "max_forks_repo_path": "doc/drbnwtsn.tex", "max_forks_repo_name": "shgalus/shg", "max_forks_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-05-21T04:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-18T12:35:22.000Z", "avg_line_length": 46.6506024096, "max_line_length": 73, "alphanum_fraction": 0.5973657025, "num_tokens": 1694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355188, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.6346013396545273}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{Sheet 6}\n\n\\subsection{Sphere pole Riemann coordinates}\n\nRecall from section \\ref{sec:spherical-surface-curvature} the spherical surface metric in the coordinates \\((\\theta,  \\varphi )\\): \n%\n\\begin{subequations}\n\\begin{align}\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{align}\n\\end{subequations}\n%\nand the Christoffel symbols, which are all zero except for \\(\\Gamma^{0}_{11}= - \\sin \\theta \\cos \\theta \\) and \\(\\Gamma^{1}_{01} = \\Gamma^{1}_{10} = 1/ \\tan \\theta \\).\n\nWe can plug these into the geodesic equation \\(u^{\\mu } \\nabla_{\\mu } u^{\\nu }\\), which comes out to be \n%\n\\begin{subequations}\n\\begin{align}\n  \\ddot{\\theta } &= + \\dot{\\varphi }^2 \\sin \\theta \\cos \\theta  \\\\\n  \\ddot{\\varphi } &= - 2 \\frac{\\dot{\\varphi } \\dot{\\theta } }{\\tan(\\theta )} \n\\,,\n\\end{align}\n\\end{subequations}\n%\nfor a trajectory \\((\\theta (s), \\varphi (s))\\) with velocity \\((\\dot{\\theta }, \\dot{\\varphi })\\): dots denote derivatives with respect to \\(s\\).\n\nNow, we want to check whether parallels and meridians are geodesics. First of all, we want to choose a parameter such that the velocity is of constant norm \\(1\\): the equation to satisfy is \n%\n\\begin{subequations}\n\\begin{align}\n  R^2 \\left[\\begin{array}{cc}\n  \\dot{\\theta} & \\dot{\\varphi}\n  \\end{array}\\right]\n  \\left[\\begin{array}{cc}\n  1 & 0 \\\\ \n  0 & \\sin^2 \\theta \n  \\end{array}\\right]\n  \\left[\\begin{array}{c}\n  \\dot{\\theta} \\\\ \n  \\dot{\\varphi}\n  \\end{array}\\right]\n  \\equiv 1\n\\,,\n\\end{align}\n\\end{subequations}\n%\nor \\(\\dot{\\theta}^2 + \\dot{\\varphi}^2 \\sin^2 \\theta = R^{-2}\\).\nMeridians have constant \\(\\varphi \\): for them, then, \\(\\dot{\\theta}^2 = R^{-2} \\), so an appropriate parametrization is \\((\\theta(s), \\varphi(s)) = (s/R, \\varphi_0 )\\).\nParallels have constant \\(\\theta \\): by an analogous line of reasoning, we parametrize them as \\((\\theta (s), \\varphi (s) )= (\\theta_0, s / R \\sin\\theta  )\\). \n\nOne can readily check that for meridians both of the geodesic equations are identities, while for parallels the second one is an identity but the first reads \\(0= \\cos \\theta  / \\sin \\theta \\): it can only be satisfied if \\(\\theta = \\pi /2\\).\nThis makes sense: geodesics on a sphere are great circles, and the only parallel which is a great circle is the equator. \n\n\\subsubsection{Riemann coordinates}\n\nThe coordinates we wish to use are \n%\n\\begin{subequations}\n\\begin{align}\n  x &= R \\theta \\cos \\varphi   \\\\\n  y &= R \\theta \\sin \\varphi \n\\,.\n\\end{align}\n\\end{subequations}\n%\n% whose tangent vectors at the north pole (i.e. \\(\\theta = 0\\)) are:\n% %\n% \\begin{subequations}\n% \\begin{align}\n%   \\dv[]{}{x} &= R \\cos \\varphi \\dv[]{}{\\theta } \n%   - R \\theta \\sin \\varphi \\dv[]{}{\\varphi } \n%   = R \\cos \\varphi \\dv[]{}{\\theta } \\\\ \n%   \\dv[]{}{y} &= R \\sin \\varphi \\dv[]{}{\\theta } \n%   + R \\theta \\cos \\varphi \\dv[]{}{\\varphi }\n% \\,,\n% \\end{align}\n% \\end{subequations}\n% %\n\nThey are in the form \\(x^{\\alpha } = \\theta n^{\\alpha }\\), for vectors \\(n^{\\alpha } = R (\\cos \\varphi, \\sin \\varphi )\\).\nAn orthonormal basis for these vectors can be found by selecting \\(\\varphi = 0, \\pi /2\\). \n\nAs we have shown before, the coordinates \\(x^{\\alpha }\\) describe geodesics if we consider them for fixed \\(\\varphi \\) and with parameter \\(\\theta \\), since they are meridians.\n\n\\subsubsection{Metric computation}\n\nThe metric transforms as \n%\n\\begin{align}\n  g_{\\mu \\nu }^{\\prime } \n  = \\pdv{x^{\\alpha }}{x^{\\prime \\mu }}\n  \\pdv{x^{\\beta }}{x^{\\prime  \\nu }}\n  g_{\\alpha \\beta }\n\\,,\n\\end{align}\n%\nso we need the inverse Jacobian, which is expressed in terms of the new coordinates \\(x^{\\prime \\mu } = (x, y)\\) and the old ones \\(x^{\\mu } = (\\theta , \\varphi )\\):\n%\n\\begin{subequations}\n\\begin{align}\n  \\pdv{x^{\\alpha }}{x^{\\prime \\mu }}\n  = \\left[\\begin{array}{cc}\n  \\frac{1}{R} \\frac{x}{\\sqrt{x^2 + y^2}} & \n  \\frac{1}{R} \\frac{y}{\\sqrt{x^2 + y^2}} \\\\ \n  \\frac{-y / x^2}{1 + (y/x)^2} & \n  \\frac{1/x}{1 + (y/x)^2}\n  \\end{array}\\right]\n\\,,\n\\end{align}\n\\end{subequations}\n%\nso we get, using the expansion \\(\\sin^2\\theta \\sim \\theta^2 - \\theta^{4} /3 + O (\\theta^{6})\\) and the identification \\(R^2\\theta^2 = x^2+y^2\\):\n%\n\\begin{subequations}\n\\begin{align}\n  g_{00}^{\\prime } &= R^2 \\qty(\\pdv{x^{0}}{x^{\\prime 0}})^2\n  + R^2 \\sin^2 \\theta \\qty(\\pdv{x^{1}}{x^{\\prime 0}})^2  \\\\\n  &= \\frac{x^2}{x^2+y^2} + R^2 \\sin^2 \\theta \\frac{y^2}{x^{4} \\qty(1 + (y/x)^2)^2}  \\\\\n  &=\\frac{1}{x^2+y^2} \\qty(x^2 + \\frac{R^2 \\sin^2\\theta y^2}{x^2+y^2})  \\\\\n  &= 1 - \\frac{y^2}{3R^2} + O((x^2+y^2)y^2)\n\\,,\n\\end{align}\n\\end{subequations}\n%\nwhile for the off-diagonal elements \\(g_{01}^{\\prime } = g_{10}^{\\prime }\\): \n%\n\\begin{subequations}\n\\begin{align}\n  g_{01}^{\\prime } &= R^2 \\pdv{x^{0}}{x^{\\prime 0}} \\pdv{x^{0}}{x^{\\prime 1}} \n  + R^2 \\sin^2 \\theta \\pdv{x^{1}}{x^{\\prime 0}} \\pdv{x^{1}}{x^{\\prime 1}}  \\\\\n  &= \\frac{xy}{x^2+y^2} + R^2 \\sin^2\\theta \\qty(- \\frac{xy}{(x^2+y^2)^2})  \\\\\n  &= \\frac{xy}{x^2+y^2} \\qty(1 - \\frac{R^2 \\sin^2\\theta }{x^2+y^2})  \\\\\n  &= \\frac{xy}{x^2+y^2} \\qty(\\frac{(x^2+y^2)^2}{3R^2 (x^2+y^2)}) + O(x^2+y^2) \\\\\n  &= \\frac{xy}{3R^2} + O(x^2+y^2)\n\\,,\n\\end{align}\n\\end{subequations}\n%\nand lastly for the element \\(g_{11}^{\\prime }\\): \n%\n\\begin{subequations}\n\\begin{align}\n  g_{11}^{\\prime } &=  R^2 \\qty(\\pdv{x^{0}}{x^{\\prime 1}})^2\n  + R^2 \\sin^2 \\theta \\qty(\\pdv{x^{1}}{x^{\\prime 1}})^2  \\\\\n  &= \\frac{y^2}{x^2+y^2} + R^2 \\sin^2 \\theta \\frac{1}{x^{2} \\qty(1 + (y/x)^2)^2}  \\\\\n  &= \\frac{1}{x^2+y^2} \\qty(y^2 +  R^2 \\sin^2\\theta \\frac{x^2}{x^2+y^2})  \\\\\n  &= 1 - \\frac{x^2}{3R^2} + O ((x^2+y^2) x^2)\n  \\,.\n\\end{align}\n\\end{subequations}\n\nAt the north pole \\(x=y=0\\), so there \\(g^{\\prime }_{\\mu \\nu }= \\delta_{\\mu \\nu }\\), and all the first derivatives calculated there vanish since there are no first order terms.\n\n\\subsubsection{Scalar curvature calculation}\n\nThe expression we have for the scalar curvature in a LIF is given in equation \\eqref{eq:ricci-scalar-LIF}.\n\nWe can evaluate it for \\(g_{\\mu \\nu }^{\\prime }\\). Do note  that the non-differentiated metric can be identified with the identity, and derivatives with upper and lower indices are the same. So, we get:\n%\n\\begin{align}\n  R _{\\text{Ric}} = \\tensor{g}{_{\\alpha \\nu , }^{\\alpha \\nu }} - \\delta^{\\mu \\nu } \\square g_{\\mu \\nu }\n\\,,\n\\end{align}\n%\nwhere the only nonvanishing terms are: \n%\n\\begin{align}\n  \\tensor{g}{_{\\alpha \\nu,}^{\\alpha \\nu }} = 2 \\pdv[2]{}{x}{y} \\qty(\\frac{xy}{3R^2}) = \\frac{2}{3R^2}\n\\,\n\\end{align}\n%\nand what was denoted as the Dalambertian before is just the Laplacian: \\(\\square = \\delta^{\\mu \\nu }\\partial_{\\mu } \\partial_{\\nu }= \\partial^2_{xx} + \\partial^2_{yy}\\):\n%\n\\begin{align}\n  \\delta^{\\mu \\nu } \\square g_{\\mu \\nu }\n  = \\partial_{xx}^2 g_{11} + \\partial_{yy}^2 g_{00}\n  = - 2 \\frac{2}{3R^2} \n\\,,\n\\end{align}\n%\nso in the end we get \n%\n\\begin{align}\n  R _{\\text{Ric}} = \\frac{2}{3R^2} + \\frac{4}{3R^2} = \\frac{2}{R^2}\n\\,,\n\\end{align}\n%\nwhich means that the curvature decreases as the radius increases, as we might expect.\n\n\\subsection{Schwarzschild metric curvature}\n\n\\subsubsection{Christoffel symbols}\n\nThe computation is tedious and not particularly enlightening: we start from the metric\n\\footnote{There is a typo in the homework assignment: the coefficients are written as functions of time.}\n%\n\\begin{align}\n  \\dd{s^2} = - A(r) \\dd{t^2}\n  + B(r) \\dd{r^2}\n  + r^2 \\qty(\\dd{\\theta^2} + \\sin^2\\theta \\dd{\\varphi^2})\n\\,,\n\\end{align}\n%\nand compute the Christoffel symbols with the usual formula: \n%\n\\begin{align}\n  \\Gamma^{\\mu }_{\\nu \\rho } =\n  \\frac{1}{2} g^{\\mu \\alpha }\\qty(g_{\\alpha \\nu , \\rho }\n  + g_{\\alpha \\rho, \\nu } - g_{\\nu \\rho , \\alpha })\n\\,,\n\\end{align}\n%\nwhere fortunately, since the metric is diagonal, we only need to compute one term in the sum (that is, \\(\\mu \\equiv \\alpha \\) always), and the two indices in the metric must be equal in order for the term to not vanish. \n\nThe metric only depends on \\(\\theta \\) and \\(r\\), so any derivatives with respect to \\(t\\) and \\(\\varphi \\) are to be discarded. \n\nWith this out of the way, we start computing the \\(40\\) independent symbols and find that the nonzero ones are (denoting differentiation with respect to \\(r\\) with a prime): \n%\n\\begin{subequations} \\label{eq:schwarzschild-christoffel}\n\\begin{align}\n  \\Gamma^{t}_{rt} &= \\frac{A^{\\prime }}{2A}  &\n  \\Gamma^{r}_{rr} &= \\frac{B^{\\prime }}{2B}  \\\\\n  \\Gamma^{r}_{tt} &= \\frac{A^{\\prime }}{2B}  &\n  \\Gamma^{\\theta }_{r \\theta } &= \\frac{1}{r}  \\\\\n  \\Gamma^{r}_{\\theta \\theta } &= -\\frac{r}{B}  &\n  \\Gamma^{\\varphi }_{r \\varphi } &= \\frac{1}{r}  \\\\\n  \\Gamma^{r}_{\\varphi \\varphi } &= - \\frac{r}{B} \\sin^2 \\theta  &\n  \\Gamma^{\\theta }_{\\varphi \\varphi } &= - \\sin \\theta \\cos \\theta  \\\\\n  \\Gamma^{\\varphi }_{\\theta \\varphi } &= \\frac{\\cos \\theta }{\\sin \\theta }\n\\,.\n\\end{align}\n\\end{subequations}\n\n\\subsubsection{Ricci component}\n\nWe want to compute \\(R^{\\mu }_{t \\mu t }\\), and in order to do so we must find the three components \\(R^{i}_{tit}\\) with varying \\(i\\) and sum them (here \\(i = r, \\theta,\\varphi \\)), since \\(R^{t}_{ttt}\\) vanishes by antisymmetry. \n\nIn general we have: \n%\n\\begin{subequations}\n\\begin{align}\n  R^{i}_{tit} &= 2 \\qty( \\Gamma^{i}_{[t| t, |i]}  + \\Gamma^{\\alpha }_{t[t} \\Gamma^{i}_{i] \\alpha })  \\\\\n  &= \\Gamma^{i}_{tt, i} - \\cancelto{}{\\Gamma^{i}_{it,t}}\n  + \\Gamma^{\\alpha }_{tt} \\Gamma^{i}_{i\\alpha }\n  - \\Gamma^{\\alpha }_{ti} \\Gamma^{i}_{t\\alpha }\n\\,.\n\\end{align}\n\\end{subequations}\n\nNote that the index \\(i\\) is consider not to be summed here, we are writing a formula for the components of the Riemann tensor; although the expression holds when summing over \\(i\\) as well. \n\nSo, we can compute this for the specific values of \\(i\\): for \\(i=r\\) we have \n%\n\\begin{subequations}\n\\begin{align}\n  R^{r}_{trt} &= \\Gamma^{r}_{tt, r} + \\Gamma^{\\alpha}_{tt} \n  \\Gamma^{r}_{r \\alpha } - \\Gamma^{\\alpha }_{tr} \\Gamma^{r}_{t \\alpha }  \\\\\n  &= \\qty(\\frac{A^{\\prime }}{2B})^{\\prime } + \\frac{A^{\\prime }}{2B} \\frac{B^{\\prime }}{2B} - \\frac{A^{\\prime }}{2A} \\frac{A^{\\prime }}{2B}  \\\\\n  &= \\frac{A^{\\prime \\prime}}{2B} - \\frac{A^{\\prime }}{2B^2} B^{\\prime } + \\frac{A^{\\prime }}{4B} \\qty(\\frac{B^{\\prime }}{B} - \\frac{A^{\\prime}}{A}) \\\\ \n  &= \\frac{A^{\\prime \\prime}}{2B} - \\frac{A^{\\prime }}{4B} \\qty(\\frac{A^{\\prime}}{A} + \\frac{B^{\\prime }}{B})\n  \\,,\n\\end{align}\n\\end{subequations}\n%\nfor \\(i= \\theta \\) instead \n%\n\\begin{subequations}\n\\begin{align}\n  R^{\\theta }_{t \\theta  t} &= \\cancelto{}{\\Gamma^{\\theta}_{tt, \\theta}} + \\Gamma^{\\alpha}_{tt} \n  \\Gamma^{\\theta}_{\\theta \\alpha } - \\cancelto{}{\\Gamma^{\\alpha }_{t\\theta} \\Gamma^{i}_{t \\alpha }}  \\\\\n  &= \\frac{A^{\\prime }}{2B} \\frac{1}{r}\n  \\,,\n\\end{align}\n\\end{subequations}\n%\nand for \\(i = \\varphi \\):  \n%\n\\begin{subequations}\n  \\begin{align}\n    R^{\\varphi }_{t \\varphi t} &= \\cancelto{}{\\Gamma^{\\varphi}_{tt, \\varphi}} + \\Gamma^{\\alpha}_{tt} \n    \\Gamma^{\\varphi}_{\\varphi \\alpha } - \\cancelto{}{\\Gamma^{\\alpha }_{t\\varphi} \\Gamma^{i}_{t \\alpha }}  \\\\\n    &= \\frac{A^{\\prime }}{2B} \\frac{1}{r}\n    \\,,\n  \\end{align}\n\\end{subequations}\n%\nso our final solution is \n%\n\\begin{subequations}\n\\begin{align}\n  R_{00} = \\sum_i R^{i}_{0i0} &= \\frac{A^{\\prime \\prime}}{2B} \n  - \\frac{A^{\\prime }}{4B} \\frac{(AB)^{\\prime }}{AB} + \\frac{A^{\\prime }}{Br}  \\\\\n  &= \\frac{A''}{2B} - \\frac{A^{\\prime 2} }{4AB} - \\frac{A' B' }{4B^2} + \\frac{A'}{Br}\n\\,.\n\\end{align}\n\\end{subequations}\n%\n\n\\subsection{Schwarzschild geometry orbits}\n\nThe derivation up to the equation for the perturbed orbit equation is documented in the lecture notes, I might copy it here later, but for now one can find it there.\n\nDuring the lecture we got up to the first order equation for the perturbation \\(w\\) for the orbit \\(u\\), written in the form \\(u(\\varphi ) = u_{c} \\qty(1+w(\\varphi ))\\): \n%\n\\begin{align}\n    \\dv[2]{w}{\\varphi }  = (6GMu_c-1) w\n\\,,\n\\end{align}\n%\nwhich is in the form \\(\\ddot{w} + \\omega^2 w = 0\\), for \\(\\omega^2 = 1- 6GMu_c\\). Now, we know that the first order equation must be complemented by the zeroth order one: \n%\n\\begin{align}\n    u_c = \\frac{GM}{l^2} + 3GM u_c^{2}\n\\,,\n\\end{align}\n%\nwhich can be solved for \\(u_c\\) to yield: \n%\n\\begin{align}\n  u_c = \\frac{1 \\pm \\sqrt{1 - 3 \\times 4 \\frac{G^2 M^2}{l^2}}}{6GM}\n\\,,\n\\end{align}\n%\ntherefore the square angular velocity of the perturbation's evolution is: \n%\n\\begin{align}\n  \\omega^2 = 1 - \\cancelto{}{6GM} \\qty(\\frac{1 \\pm \\sqrt{1 - 12 \\frac{G^2 M^2}{l^2}}}{ \\cancelto{}{6GM}})\n  = \\pm \\sqrt{1 - 12 \\frac{G^2 M^2}{l^2}}\n\\,.\n\\end{align}\n\nThe solution with the minus sign has no meaning for us, since the solution we want to consider must be stable, with positive \\(\\omega^2\\). So, the angular velocity is \n%\n\\begin{align}\n  \\omega = \\qty(1 - 12 \\frac{G^2M^2}{l^2})^{1/4}\n\\,,\n\\end{align}\n%\nand we know that angular velocity and period are related by \\(T = 2 \\pi / \\omega \\): therefore we get \n%\n\\begin{align}\n  T = 2 \\pi \\qty(1 - 12 \\frac{G^2M^2}{l^2})^{-1/4}\n\\,,\n\\end{align}\n%\nwhich we can Taylor expand: at \\(x=0\\) we have \n%\n\\begin{align}\n    (1-12x)^{-1/4} = 1 - \\frac{1}{4} (1-12 \\times 0)^{-5/4} (-12x) + O(x^2) = 1 + 3x + O(x^2 )\n\\,.\n\\end{align}\n%\n\nTherefore: \n%\n\\begin{align}\n  T = 2 \\pi \\qty(1 + 3 \\qty(\\frac{GM}{l})^2) + O\\qty(\\qty(\\frac{GM}{l})^{4})\n\\,,\n\\end{align}\n%\nwhich is approximately \\(2 \\pi \\) as we should expect: the Newtonian approximation is \\(l \\gg GM\\), and Newtonian orbits have a period of exactly \\(2 \\pi \\). Then we can read off the first-order correction directly from the first term in the expansion: it is \n%\n\\begin{align}\n  \\delta \\varphi = 6 \\pi \\qty(\\frac{GM}{l})^2\n\\,.\n\\end{align}\n%\n\nThe \\(M\\) here is the mass of the central object, while \\(l\\) is the angular momentum of the orbit. \n\n\n\n\\end{document}", "meta": {"hexsha": "9539bce43b56fe69c5bfd9bbe7ad637d6865538d", "size": 13628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/gr_exercises/sheet6.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/sheet6.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/sheet6.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": 35.8631578947, "max_line_length": 259, "alphanum_fraction": 0.603977106, "num_tokens": 5244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6346013334351631}}
{"text": "%%\n%% Hyperbolic Trig Identities\n%%\n%% Author: William Gao\n%% 09/04/2019\n%%\n\n\\documentclass[12pt]{article}\n\\setlength{\\parindent}{0pt}                  % disable indent globally\n\n\\RequirePackage[\n    letterpaper,\n    left=0.8in,\n    right=0.8in,\n    top=0.70in,\n    bottom=0.55in,\n    nohead\n]{geometry}\n\n% Packages\n\\usepackage{amssymb}\n\\usepackage[fleqn]{amsmath}\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks=true,\n    urlcolor=blue\n}\n\n\\newcommand{\\hzline}{\\noindent\\makebox[\\linewidth]{\\rule{0.8\\paperwidth}{0.4pt}}}\n\n\\title{Hyperbolic Trig Identities}\n%\\author{math2.org}\n\\author{Version 1.1}\n\\date{September 4, 2019}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nA compiled list of the most commonly used hyperbolic trig identities. Enjoy. \\\\\n\nAll credits goes to \\href{http://math2.org/math/trig/hyperbolics.htm}{math2.org}. If you have comments, corrections, or clarifications, please submit an issue or pull request on \\href{https://github.com/chemclub/calculus}{GitHub}.\n\n\\large\n\\section{Hyperbolic Definitions}\n\n\\begin{align*}\n& \\sinh x = \\frac{e^x-e^{-x}}{2} \\\\\n& \\operatorname{csch}x = \\frac{1}{\\sinh x} = \\frac{2}{e^x-e^{-x}}\n\\end{align*}\n\n\\begin{align*}\n& \\cosh x = \\frac{e^x+e^{-x}}{2} \\\\\n& \\operatorname{sech}x = \\frac{1}{\\cosh x} = \\frac{2}{e^x+e^{-x}}\n\\end{align*}\n\n\\begin{align*}\n& \\tanh x = \\frac{\\sinh x}{\\cosh x} = \\frac{e^x-e^{-x}}{e^x+e^{-x}} \\\\\n& \\operatorname{coth}x = \\frac{1}{\\tanh x} = \\frac{e^x+e^{-x}}{e^x-e^{-x}}\n\\end{align*}\n\n\n\\begin{align*}\n& \\cosh^2x-\\sinh^2x = 1 \\\\\n& \\tanh^2x+\\operatorname{sech}^2x = 1 \\\\\n& \\coth^2x-\\operatorname{csch}^2x = 1\n\\end{align*}\n\n\n\\section{Inverse Hyperbolic Definitions}\n\n\\begin{align*}\n& \\operatorname{arcsinh}z=\\ln\\left(z+\\sqrt{z^2+1}\\right) \\\\\n& \\operatorname{arccosh}z=\\ln\\left(z\\pm\\sqrt{z^2-1}\\right) \\\\\n& \\operatorname{arctanh}z=\\frac{1}{2}\\ln\\left(\\frac{1+z}{1-z}\\right)\n\\end{align*}\n\n\\begin{align*}\n& \\operatorname{arccsch}z=\\ln\\left(\\frac{1+\\sqrt{1+z^2}}{z}\\right) \\\\\n& \\operatorname{arcsech}z=\\ln\\left(\\frac{1+\\sqrt{1-z^2}}{z}\\right) \\\\\n& \\operatorname{arccoth}z=\\frac{1}{2}\\ln\\left(\\frac{z+1}{z-1}\\right)\n\\end{align*}\n\n\n\\section{Relations to Trigonometric Functions}\n\n\\begin{align*}\n& \\sinh z=-i\\sin\\left(iz\\right) \\\\\n& \\operatorname{csch}z=i\\csc\\left(iz\\right)\n\\end{align*}\n\n\\begin{align*}\n& \\cosh z=\\cos\\left(iz\\right) \\\\\n& \\operatorname{sech}z=\\sec\\left(iz\\right)\n\\end{align*}\n\n\\begin{align*}\n& \\tanh z=-i\\tan\\left(iz\\right) \\\\\n& \\coth z=i\\cot\\left(iz\\right)\n\\end{align*}\n\n\\end{document}\n\n", "meta": {"hexsha": "e556eef08bd6077ad8dccfb775703ef410ac664d", "size": 2481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "references/hyperbolic.tex", "max_stars_repo_name": "w-gao/calculus", "max_stars_repo_head_hexsha": "6048f127e4ff42ad7b03885a60c6025ae84e5a87", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "references/hyperbolic.tex", "max_issues_repo_name": "w-gao/calculus", "max_issues_repo_head_hexsha": "6048f127e4ff42ad7b03885a60c6025ae84e5a87", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "references/hyperbolic.tex", "max_forks_repo_name": "w-gao/calculus", "max_forks_repo_head_hexsha": "6048f127e4ff42ad7b03885a60c6025ae84e5a87", "max_forks_repo_licenses": ["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.6285714286, "max_line_length": 230, "alphanum_fraction": 0.6545747682, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6346006539989556}}
{"text": "\\documentclass{article}\n\n\\usepackage{geometry}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\newcommand{\\n}{^{\\mathrm{min}}}\n\\newcommand{\\x}{^{\\mathrm{max}}}\n\n\\begin{document}\n\n\\section{Timers}\n\nThese host-ticks timers are a bit weird.  In fact, originally I had\nthem \\emph{wrong}.\n\nLet $i\\n$ be the minimum interval, $i\\x$ the maximum.  $t_j$ is a\nticker value, $r_j$ is a remainder, $d_j$ is a duration of time\npassage, $\\delta_j$ is the amount by which the ticker advances.\n\nConsider\n\\[\n\\mathrm{Ticker}(t_0,r_0)\\xrightarrow{d_1}\n\\mathrm{Ticker}(t_1,r_1)\\xrightarrow{d_2}\n\\mathrm{Ticker}(t_2,r_2)\n\\]\nwhere $t_1 = t_0+\\delta_1$, $t_2=t_1+\\delta_2 =\nt_0+\\delta_1+\\delta_2$.\n\nThe original rule was:\n\\[\n\\exists i_j.\\;\ni\\n\\leq i_j \\wedge i_j\\leq i\\x \\wedge\n\\delta_j = \\left\\lfloor \\frac{r_{j-1}+d_j}{i_j} \\right\\rfloor \\wedge\nr_j = r_{j-1}+d_j - \\delta_j i_j\n\\]\n\nA crucial property is the following (roughly \\textbf{S1} and\n\\textbf{S2} in Lynch and Vaandrager 1996), which I shall call\nadditivity:\n\\[\n\\mathrm{Ticker}(t_0,r_0)\\xrightarrow{d_1}\n\\mathrm{Ticker}(t_1,r_1)\\xrightarrow{d_2}\n\\mathrm{Ticker}(t_2,r_2)\n\\Leftrightarrow\n\\mathrm{Ticker}(t_0,r_0)\\xrightarrow{d_1+d_2}\n\\mathrm{Ticker}(t_2,r_2)\n\\]\n\nThis does not hold for the original rule!  If $d_1 > d_2$, and we\nchoose $i_1=i\\n$ and $i_2=i\\x$, it can happen that even though $r_2 <\ni_2$, it is the case that $r_2 > i\\x_{12}$, where $i\\x_{12}$ is the\ngreatest interval consistent with $t_2$, i.e., $i\\x_{12} =\n\\frac{r_0+d_1+d_2-r_2}{\\delta_1+\\delta_2}$.  This means that no\n$i_{12}$ satisfying the condition of the rule exists.\n\nFor example: let $r_0 = 14$, $d_1=364$, $d_2=141$, $i_1=56$,\n$i_2=112$.  Then $\\delta_1=6$, $r_1=42$, $\\delta_2=1$, $r_2=71$.  But\nto achieve $r_{12}=71/56$ we must have\n$\\delta_{12}i_{12}=r_0+d_{12}-r_{12}=448$; and since $\\delta_{12}=7$,\nwe must have $i_{12}=64$.  But $\\delta_{12}=\\left\\lfloor \\frac{519}{64}\n\\right\\rfloor = 8 \\neq 7$, which is a CONTRADICTION.\n\nA new possible rule is as follows:\n\\[\n\\begin{array}{r@{}c@{}l}\n\\exists \\delta\\n_j \\delta\\x_j.\\;\\\\\n\\delta\\n_j &=& \\left\\lfloor \\frac{r_{j-1}+d_j}{i\\x} \\right\\rfloor \\wedge\\\\[1ex]\n\\delta\\x_j &=& \\left\\lfloor \\frac{r_{j-1}+d_j}{i\\n} \\right\\rfloor \\wedge\\\\\n\\delta\\n_j &{}\\leq \\delta_j\\leq{}&\\delta\\x_j \\wedge\\\\\nr_{j-1}+d_j-\\delta_j i\\x &{}\\leq r_j \\leq {}&r_{j-1}+d_j-\\delta_j i\\n \\wedge\\\\\n0 &{}\\leq r_j <{}& i\\x\n\\end{array}\n\\]\nwhere the $\\delta\\n_j, \\delta\\x_j$ are now naturals as well as\n$\\delta_j$ (note the strict inequality on $r_j < i\\x$ is still\nnecessary for the model).\n\nDoes this have the desired properties?\n\nArgh, I'm an idiot!  The reason I was having trouble proving the\nproperties was that the above rule is overconstrained.  It is\nsufficient to require:\n\\[\n\\begin{array}{r@{}c@{}l}\nr_{j-1}+d_j-\\delta_j i\\x &{}\\leq r_j \\leq {}&r_{j-1}+d_j-\\delta_j i\\n \\wedge\\\\\n0 &{}\\leq r_j <{}& i\\x\n\\end{array}\n\\]\nThe following results follow:\n\\begin{itemize}\n\\item $\\delta_j$ lies in the range $[\\left\\lfloor\n\\frac{r_{j-1}+d_j}{i\\x} \\right\\rfloor,\\left\\lfloor\n\\frac{r_{j-1}+d_j}{i\\n} \\right\\rfloor]$.\n\\item $r_j$ can then be determined\nfrom the inequations above---it is usually free in $[0,i\\x]$, but when\n$\\delta_j$ is chosen at or near the boundaries, it is restricted by\nthe other inequation.\n\\item The additivity property holds (this is trivial to verify: add\nthe first inequations for $j=1$ and $j=2$, and subtract $r_1$\nthrough).\n\\end{itemize}\n\n\n\\end{document}\n", "meta": {"hexsha": "69fefd68ecfd5730c9543e9add68d03f3596ff97", "size": 3411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "unmaintained/Net/TCP/Notes1/timers.tex", "max_stars_repo_name": "rems-project/netsem", "max_stars_repo_head_hexsha": "0b02450eee334fc42f74ad3da09d3ce1a0698a48", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2018-02-26T20:37:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T01:49:55.000Z", "max_issues_repo_path": "unmaintained/Net/TCP/Notes1/timers.tex", "max_issues_repo_name": "PeterSewell/netsem", "max_issues_repo_head_hexsha": "0b02450eee334fc42f74ad3da09d3ce1a0698a48", "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": "unmaintained/Net/TCP/Notes1/timers.tex", "max_forks_repo_name": "PeterSewell/netsem", "max_forks_repo_head_hexsha": "0b02450eee334fc42f74ad3da09d3ce1a0698a48", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-24T15:26:34.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-12T23:39:13.000Z", "avg_line_length": 32.179245283, "max_line_length": 79, "alphanum_fraction": 0.683963647, "num_tokens": 1347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.634600649854627}}
{"text": "\\section{Learning spectral clustering}\n\\label{ch:jordan04}\n\n\\textit{Learning spectral clustering} by Francis R. Bach and Michael I. Jordan. \\\\\nCited by 313. \\textit{Advances in Neural Information Processing Systems 16 (2004)}.\n\\newline\n\n\\textbf{Main point} is that the author derived \\begin{inparaenum}[\\itshape a\\upshape)]\n\\item a cost function for spectral clustering that minimize the error between a given partition and the minimum normalized cut\n\\item with respect to two algorithms one for spectral clustering and one for learning the similarity matrix.\n\\end{inparaenum}.\n\n\\subsection{Objective way of similarity measure}\nA general framework is provided for learning the similarity matrix for spectral clustering. New cost function $J(W,e)$ that characterizes how close the eigen structure of a similarity matrix $W$ is to a partition $e$. \n%\n%\\subsection{Spectral clustering}\n%Given a dataset $I$ of $P$ points in space $X$ and a $P \\times P$ similarity matrix $W$ that measures the similarity between the $P$ points. \n\n\\subsection{Learning the similarity matrix}\n\n\\begin{figure}[ht]\n\\begin{mdframed}\n\\begin{description}\n\\item[Assumption] \\hfill \\\\\ngiven $N$ datasets $D_n, n \\in \\{ 1, \\cdots, N \\}$ of points in $R^F$ where $D_n$ is composed of $P_n$ points $x_{np}, p \\in \\{ 1, \\cdots, P_n \\}$.\n\\item[Step 1] \\hfill \\\\\nfor each $n$ we know the partition $e_n$, so that target matrix $ \\Pi (e_n, \\alpha)$ can be computed from each dataset.\n\\item[Step 2] \\hfill \\\\\nfor each $n$, we have a similarity matrix $W_n (\\alpha)$\n\\item[Step 3] \\hfill \\\\\nThe cost function $H(\\alpha) = \\frac{1}{N} \\sum_n F( W_n(\\alpha), \\Pi_0 (e_n, \\alpha)) + C || \\alpha ||_1$.\n\\item[Step 4] \\hfill \\\\\nThe learning algorithm is the minimization of $H(\\alpha)$ with respect to $\\alpha \\in R_{+}^F$ using the method of conjugate gradient with line search.\n\\end{description}\n\\end{mdframed}\n\\caption{Learning similarity matrix}\n\\end{figure}\n\n", "meta": {"hexsha": "29e7738bee75f13e90f17a729b424cf7f7c3f298", "size": 1921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/references/reference_research/jordan04.tex", "max_stars_repo_name": "wsgan001/AnomalyDetection", "max_stars_repo_head_hexsha": "397673dc6ce978361a3fc6f2fd34879f69bc962a", "max_stars_repo_licenses": ["MIT"], "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/references/reference_research/jordan04.tex", "max_issues_repo_name": "wsgan001/AnomalyDetection", "max_issues_repo_head_hexsha": "397673dc6ce978361a3fc6f2fd34879f69bc962a", "max_issues_repo_licenses": ["MIT"], "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/references/reference_research/jordan04.tex", "max_forks_repo_name": "wsgan001/AnomalyDetection", "max_forks_repo_head_hexsha": "397673dc6ce978361a3fc6f2fd34879f69bc962a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-16T21:50:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-16T21:50:52.000Z", "avg_line_length": 49.2564102564, "max_line_length": 218, "alphanum_fraction": 0.7319104633, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6346006443288555}}
{"text": "% !TEX root = as_grf_sopt.tex\n\n\\subsection{DISCUSSIONS}\n\n\nOur approach and two other popular criteria, information gain from \\cite{srinivas2012information} and V-optimality of \\cite{mingji}, can also be connected by functions of the eigenvalues of the covariance matrix at each iteration.\n% Particularly, we are interested in primitives of monotone functions as described in \\cite{spectral_submod}.\n\n% From the rank-one update rule, \\eqref{eq:var_update}, the posterior covariance matrices at different iterations can be ordered using convex cone of postive semi-definite matrix (Loewner order) as \n% $\\bC_0\\succ\\bC_1\\succ\\dotsc\\succ\\bC_T\\succ\\mathbf{0}$. With this ordering, we can define monotone spectral operators, $h(\\bC_t)$, that maps Hermitian matrices to real values, such that \n% \\begin{equation*}\n% h(\\bC_t)>h(\\bC_{t'}) \\Leftrightarrow \\bC_t\\succ\\bC_{t'}\n% \\quad(\\Leftrightarrow t<t'). \n% \\end{equation*}\n\n\n\n\n% Many exploration heuristics can be written as a function of the spectral difference between the current model and one-step look-ahead posterior model. \nTo see this connection, assume the updated covariance matrix at iteration $(t+1)$ has eigen-decomposition $\\bC_t = \\sum_{j=1}^n \\lambda_{t,(j)}\\bq_{t,(j)} \\bq_{t,(j)}^\\top$, where $\\blambda_t=(\\lambda_{t,(1)}, \\dotsc,\\lambda_{t,(n)})^\\top$ represents the eigenvalues and  $\\{\\bq_{t,(j)}:j=1,\\dotsc,n\\}$ is the set of corresponding eigenvectors. Assume the eigenvalues are sorted by $\\lambda_{t,(1)}\\geq\\dotsc\\geq\\lambda_{t,(n)}\\geq0$.\nWe hope to connect $s_t(v)$ to the following spectral difference,\n % at the one-step difference of a spectral function $h(\\blambda_t):\\mathbb{R}^n\\to\\mathbb{R}$, as\n%\\begin{align}\n%\t\\rho(\\bC_t) &= \\sum_{j=1}^n h(\\lambda_{t,(j)}),\n%\t\\quad {\\rm s.t.} \\; \n%\th'(s)>0, \\forall s>0.\n%\\end{align}\n%Correspondingly, assuming an observation of $v$, the exploration heuristic is then,\n\\begin{equation}\n\t\\Delta h_t(v) = \n\th\\bigl(\\blambda_{t}\\bigr)\n\t-\n\th\\bigl(\\blambda_{t+1\\mid v}\\bigr) \n\t% \\\\\n\t% &{\\rm s.t. } \\;\n\t% h'(s)>0, \\forall s>0\n\\end{equation}\nwhere $h(\\blambda):\\mathbb{R}^n\\to\\mathbb{R}$ is a multivariate function defined on the eigenvalues.\nFurther, by the one-step update rule of \\eqref{eq:var_update}, $\\bC_t$ has Loewner order as \n$\\bC_0\\succ\\bC_1\\succ\\dotsc\\succ\\bC_T\\succ\\mathbf{0}$. \n% for any monotone increasing function $h:\\mathbb{R}^n\\to\\mathbb{R}$. \nIt is thus often desirable to require $h(\\cdot)$ to be monotone with respect to this ordering, i.e. $\\bC_t\\succ\\bC_{t'} \\Rightarrow h(\\blambda_t)\\geq h(\\blambda_{t'})$.\n% Notice that $\\bC_t$ is positive semi-definite and $\\lambda_{t,(j)}$ is monotone decreasing as $t$ increases, \n% by applying Weyl's inequality to rank-one updates at each iteration.\n\n% where the difference inside $h^{-1}(\\cdot)$ is nonnegative, because we can prove using induction and definition of eigen-vectors, for example with $j=1$\n% and \n% $\\bq_{t+1,(1)}$ being the eigen-vector corresponding to $\\lambda_{t+1,(1)}$ in the posterior model,\n% $\n\t% \\lambda_{t,(j)}^2 - \\lambda_{t+1,(1)}^2 \n\t% \\geq \n\t% \\nicefrac{\\langle \\bq_{t+1,(1)}, \\bc_{t+1}(v)\\rangle^2}{(\\sigma_n^2 - \\sigma_{t+1}^2(v))}\\geq0$.\n\n%For example, some reasonable choices of $s_t(v)$ are,\n%\\begin{numcases}{\\hspace{-2em}}\n%\t\\sqrt{ 1+\\nicefrac{\\sigma_t^2(v)}{\\sigma_n^2}}\n%\t & $h_{ig}(s) = -log(s)$\n%\t   \\label{eq:s-ig}\n%\t\\\\\t   \n%\t \\sqrt{\\tr(\\bC_{t}) - \\tr(\\bC_{t+1})},\n%\t   & $h_2(s) = s^2$\n%\t   \\label{eq:s-variance}\n%\t\\\\\n%\t \\lambda_{\\max}(\\bC_{t}) - \\lambda_{\\max}(\\bC_{t+1}),\n%\t \\hspace{-1em}\n%\t & $h_\\infty(s) = s^p, p\\to\\infty$\n%\t   \\label{eq:s-spectral}\n%\\end{numcases}\n\n\\textbf{Case 1}. $\n\th(\\blambda) = \\sum_j \\log(\\lambda_{(j)}).$ \n\t% the differential entropy of $\\mathcal{N}(\\bmu_t,\\bC_t)$. \n\tThen,\n$\t\\Delta h_t(v) \n\t= 2\\mathcal{I}_t(\\bff; y(v)) = \\log(1+\\frac{\\sigma_t^2(v)}{\\sigma_n^2}),\n\t% = \\sqrt{ 1+\\nicefrac{\\sigma_t^2(v)}{\\sigma_n^2}}.\n$ twice the information gain from $\\bff\\sim\\mathcal{N}(\\bmu_t, \\bC_t)$ to $\\mathcal{N}(\\bmu_{t+1\\mid v}, \\bC_{t+1\\mid v})$. \nThis metric is important to \\textbf{GP-UCB} \\citep{srinivas2012information}, which set $s_t(v)=\\sigma_t(v)$ and used the inequality, $\\log(1+\\frac{\\sigma_m^2}{\\sigma_n^2})  \\frac{\\sigma_t^2(v)}{\\sigma_m^2}\\leq\\log(1+\\frac{\\sigma_t^2(v)}{\\sigma_n^2}),$ where $\\sigma_m=\\max_{v,t}\\sigma_t(v)$, in its proofs.\n\n% This heuristic adds biases to maximize the differential information gain of the joint distribution of node values, turns out to pay too much attention to the graph periphery, which actually prevents information gathering in the true problem against intuition. Precisely, differential entropy is sensitive to tails of the distribution, which happens to be the place of the biggest model mismatch of our \\textsc{grf} models. \n\n\n\n\\textbf{Case 2}. $\n\th(\\blambda) = \\sum_j \\lambda_{(j)} $ \n\tgives\n\t$\n\t\\Delta h_t(v) = \\tr(\\bC_{t}) - \\tr(\\bC_{t+1\\mid v}) =  \\nicefrac{ \\| \\bc_t(v) \\|_2^2 }{(\\sigma_t^2(v) + \\sigma_n^2)}.\n$ For $\\sigma_n= 0$, $\\Delta h_t(v)$ is used as the greedy \\textbf{V-optimal} criterion for design of experiments by \\cite{mingji}.\n%, which though alleviates the situation by adding independence assumptions on the nodes and measuring the sum of the marginal variances, cannot completely address the selection bias at graph peripheries, because the self-variance term usually dominates the sum of squares of $\\|\\bc_t(v)\\|_2^2$.\n\n\n\\textbf{Case 3}. $\n\th(\\blambda) = \\lambda_{(1)}$ connects to the greedy design for \\textbf{E-optimality} \\citep{pukelsheim1993optimal}. To some extent, it is also related to greedy \\textbf{$\\Sigma$-Optimality}. First,\n\tapproximate $\\Delta h_t(v)$ by $\\partial\\lambda_{(j)} = \\bq_{(j)}^\\top \\partial(\\bC) \\bq_{(j)}$ around $\\bC=\\bC_t$, as\n\\vspace{-.5em}\n\\begin{equation*}\n\t\\Delta h_t(v) \n\t% &\n\t\\approx \n\t\\bq_{t,(1)}^\\top (\\bC_t-\\bC_{t+1|v}) \\bq_{t,(1)}\n\t= \n\t \\bigg( \n\t\t\\frac{|\\bc_t(v)^\\top \\bq_{t,(1)}|}\n\t{\\sqrt{\\sigma_t(v)^2 + \\sigma_n^2}}\n\t \\bigg)^2\n\t%  \\\\\n\t%  &=\n\t%  \\bigg( \n\t% \t\\frac{\\lambda_{(1)} \\cdot |q_{t(1)}(v)|}\n\t% {\\sqrt{\\sigma_t(v)^2 + \\sigma_n^2}}\n\t%  \\bigg)^2\n\t\\end{equation*}\nThe above resembles \\eqref{eq:sopt} if $\\bq_{t,(1)}\\propto \\bone$, which holds true for $t=0$ and $\\omega_0=0$ and approximately so for small $t$s.\n\n\n\nIn all these cases, exploration is measured by how much the objective, $h(\\blambda_T)$, is eventually decreased after $T$ iterations. \nEach definition of $h(\\blambda_t)$ aggregates the eigenvalues of the posterior covariance matrices in a different way, which \naffects the relative importance of large and small eigenvalues. In \\textbf{Case 1}, since $\\frac{\\partial \\log(\\lambda)}{\\partial \\lambda}=\\frac{1}{\\lambda}$, the same change introduced to a smaller $\\lambda$ will have a relatively larger impact on the objective.\n % than a larger $\\lambda$. \nSuch an effect is not evident in the other two cases. \nParticularly in \\textbf{Case 3}, changes to small eigenvalues are ignored unless they become the largest eigenvalue. \n\n\nEstablishing biases to penalize larger eigenvalues more has the benefit of improving global robustness because the posterior marginal variance of every node is upper-bounded by $\\lambda_{t,(1)}$. \nCompared with \\textbf{Cases 2} and \\textbf{3}, \\textbf{Case 1} is more sensitive to changes in small eigenvalues, which may be another explanation\nof \\textbf{GP-UCB}'s strong tendency to select peripheral nodes, as seen in Figure 4 of \\cite{MIG} or Figure 1(d) of \\cite{gotovos2013active}. \n\nAlthough Algorithm~\\ref{alg:main} is not built around the concept of functions on eigenvalues, it still establishes strong biases to penalize large eigenvalues in its initial explorations, per analysis in \\textbf{Case 3}. \nNote that \\textbf{$\\Sigma$-optimality} achieves a more complex goal than \\textbf{E-optimality}; exact execution of \\textbf{E-optimality} may over-simplify the model and select nodes between clusters for separation rather than inside them.\n\n\n% First, assuming that the principal eigen-vector of $\\bC_t$ is $\\bq_t$, then\n% $\n% \t\\lambda_{\\max}^2(\\bC_{t+1} \\mid v) \\approx \\lambda_{\\max}^2(\\bC_t) - \n% \t\\frac{\\langle \\bq_t,  \\bc_t(v)\\rangle^2}\n% \t{ (\\sigma_t^2(v) + \\sigma_n^2) }\n% $ and, compounding the square-root operator,\n% $\n% \ts_t(v) \\approx \\frac{1}{2\\lambda_{\\max}(\\bC_t)}\n% \t\\frac{\\bc_t(v)^\\top \\bq_t}\n% \t{\\sqrt{\\sigma_t(v)^2 + \\sigma_n^2}}.\n% $\n\n\n% This approximation works for the very first selections. Note that $\\bC_0^{-1}=\\bD-\\bA+\\omega_0\\bI$ has its smallest eigen-vector (with respect to $\\omega_0$) very close to $\\frac{1}{n}\\mathbf{1}$, that same vector carries to be $\\bq_0$ for the largest eigen-value of $\\bC_0$. At this point, $s_t(v)$ is our Sigma-optimality up to a selection-independent constant.\n\n\n% In fact, this approximation can be valid for larger $t$'s. Further break the graph down to different (relatively isolated) connected components, where each individual component is relatively unexplored, and therefore contains a principal eigen-vector,  relative to the component, which will approximate\n% $\\bq_{t,(c)}\\approx\\mathbf{1}_\\cC$, where $c$ is the rank of this eigen-vector and $\\cC$ the subset of nodes of this connected component. The more under-explored the component is, the more likely that $\\bq_{t,(c)}$ becomes the principal eigen-vector, $\\bq_t$ and also $\\bq_{t,(c)}$ gets close to $\\mathbf{1}_\\cC$.\n\n% In the meantime, every column on the current covariance matrix $\\bc_t(v)$ will also reflect independence between these (relatively isolated) components. Thus, the inner product can be roughly approximated as, \n% $ %\\begin{equation}\n% \t\\bq_t^\\top \\bc_t(v) \\approx \\mathbf{1}_\\cC^\\top \\bc_t(v)  + \\mathbf{1}_{\\bar{\\cC}}^\\top \\mathbf{0} = \\mathbf{1}^\\top \\bc_t(v),\n% $ %\\end{equation}\n% where $\\bar{\\cC}$ is the complement of $\\cC$. \n% Again, Sigma-optimality approximates the difference of the spectral norm between prior and one-step look-ahead covariance matrices.\n\n", "meta": {"hexsha": "e7441fae432eae9a4b1e6b686b5b6dde7dd5e85e", "size": 9837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texts/sec_discussions.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_discussions.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_discussions.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": 61.48125, "max_line_length": 434, "alphanum_fraction": 0.7007217648, "num_tokens": 3243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6346006401399197}}
{"text": "\\chapter{Experimental}\n\n\\section{Further development of the maximum proof}\nStarting point is:\n\\[\nv_{n+2}=\\frac{2}{\\left(2-\\prod_{i=1}^{n}\\beta_i\\right)\\cdot2^{\\alpha_{n+1}}}\n\\]\n\n\\par\\medskip\nIn order to show that $v_{n+2}<1$ we consider the worst case that maximizes $v_{n+2}$ by using the inserting the Engel expansion into the product:\n\\[\n\\prod_{i=1}^{n}\\beta_i=\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_i}\\right)=\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_i}\\right)=\\prod_{i=1}^{n}\\left(1+\\frac{1}{3\\frac{3^{i-1}(v_1+1)-2^{i-1}}{2^{i-1}}}\\right)\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\n\\par\\medskip\nThis leads to:\n\\[\nv_{n+2}=\\frac{2}{\\left(2-\\left(\\frac{1}{v_1}-\\frac{1}{v_1}\\left(\\frac{2}{3}\\right)^n+1\\right)\\right)\\cdot2^{\\alpha_{n+1}}}\n\\]\n\n\\par\\medskip\nMultiplying leads to\n\\[\n2^{\\alpha_{n+1}}v_1v_{n+2}-2^{\\alpha_{n+1}}v_{n+2}+2^{\\alpha_{n+1}}v_{n+2}\\left(\\frac{2}{3}\\right)^n-2v_1=0\n\\]\n\n\\par\\medskip\nNow we remove the variable $v_1$, because we know the relatonship between $v_1$ and $v_{n+2}$ in an Engel expansion (see \\ref{eq:asc_continued_fraction}):\n\\[\nv_1=\\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1\n\\]\n\n\\par\\medskip\nNow we substitute the term above into our equation:\n\\[\n2^{\\alpha_{n+1}}\\left(\\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1\\right)v_{n+2}-2^{\\alpha_{n+1}}v_{n+2}+2^{\\alpha_{n+1}}v_{n+2}\\left(\\frac{2}{3}\\right)^n-2\\left(\\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1\\right)=0\n\\]\n\n\\par\\medskip\nWe know that in an Engel expansion $\\alpha_{n+1}=1$ (we make onla one division by two between vertices). Via substitution $v_{n+2}=y$ we obtain a simple equation, which has for $y\\ge1$ only complex solutions having an imaginary part:\n\\[\n\\left(\\frac{(y+1)2^{n+1}}{3^{n+1}}-1\\right)y-y+y\\left(\\frac{2}{3}\\right)^n-\\left(\\frac{(y+1)2^{n+1}}{3^{n+1}}-1\\right)=0\n\\]\n\nLet us now substitute $\\left(\\frac{2}{3}\\right)^n$ with $z$:\n\\[\n\\left((y+1)\\frac{2}{3}z-1\\right)y-y+yz-\\left((y+1)\\frac{2}{3}z-1\\right)=0\n\\]\n\nHence $y=v_{n+2}$ must be smaller than 1.", "meta": {"hexsha": "655f537846518f9d008ed0e068d38cbca5b92563", "size": 2008, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v6.0/chapter/xx_experimental.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/xx_experimental.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/xx_experimental.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": 38.6153846154, "max_line_length": 233, "alphanum_fraction": 0.6309760956, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339907, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.634600637377034}}
{"text": "\\chapter{Semisimple algebras}\nIn what follows, \\textbf{assume the field $k$ is algebraically closed}.\n\nFix an algebra $A$ and suppose\nyou want to study its representations.\nWe have a ``direct sum'' operation already.\nSo, much like we pay special attention to prime numbers,\nwe're motivated to study irreducible representations\nand then build all the representations of $A$ from there.\n\nUnfortunately, we have seen (\\Cref{exer:irred_not_indecomp})\nthat there exists a representation which is not irreducible,\nand yet cannot be broken down as a direct sum (indecomposable).\nThis is \\emph{weird and bad}, so we want to give a name\nto representations which are more well-behaved.\nWe say that a representation is \\vocab{completely reducible}\nif it doesn't exhibit this bad behavior.\n\nEven better, we say a finite-dimensional algebra $A$\nis \\vocab{semisimple} if all its finite-dimensional\nrepresentations are completely reducible.\nSo when we study finite-dimensional representations of\nsemisimple algebras $A$,\nwe just have to figure out what the irreps are,\nand then piecing them together will give all\nthe representations of $A$.\n\nIn fact, semisimple algebras $A$ have even nicer properties.\nThe culminating point of the chapter is when we prove that\n$A$ is semisimple if and only if $A \\cong \\bigoplus_i \\Mat(V_i)$,\nwhere the $V_i$ are the irreps of $A$\n(yes, there are only finitely many!).\n\n\\section{Schur's lemma continued}\n\\prototype{For $V$ irreducible,\n\t$\\Homrep(V^{\\oplus 2}, V^{\\oplus 2}) \\cong k^{\\oplus 4}$.}\n\\begin{definition}\n\tFor an algebra $A$ and representations $V$ and $W$,\n\twe let $\\Homrep(V,W)$ be the set of intertwining operators between them.\n\t(It is also a $k$-algebra.)\n\\end{definition}\n\nBy Schur's lemma (since $k$ is algebraically closed,\nwhich again, we are taking as a standing assumption),\nwe already know that if $V$ and $W$ are irreps, then\n\\[\n\t\\Homrep(V,W) \\cong\n\t\\begin{cases}\n\t\tk & \\text{if $V \\cong W$} \\\\\n\t\t0 & \\text{if $V \\not\\cong W$}.\n\t\\end{cases}\n\\]\nCan we say anything more?\nFor example, it also tells us that\n\\[ \\Homrep(V, V^{\\oplus 2}) = k^{\\oplus 2}. \\]\nThe possible maps are $v \\mapsto (c_1v_1, c_2v_2)$ for some choice of $c_1, c_2 \\in k$.\n\nMore generally, suppose $V$ is an irrep and consider\n$\\Homrep(V^{\\oplus m}, V^{\\oplus n})$.\nIntertwining operators are determined completely\n$T : V^{\\oplus m} \\to V^{\\oplus n}$ by the $mn$ choices of compositions\n\\begin{diagram}\n\tV & \\rInj & V^{\\oplus m} & \\rTo^T & V^{\\oplus n} & \\rSurj & V\n\\end{diagram}\nwhere the first arrow is inclusion to the $i$th component of $V^{\\oplus m}$\n(for $1 \\le i \\le m$) and the second arrow is inclusion to the $j$th\ncomponent of $V^{\\oplus n}$ (for $1 \\le j \\le n$).\nHowever, by Schur's lemma on each of these compositions,\nwe know they must be constant.\n\nThus, $\\Homrep(V^{\\oplus n}, V^{\\oplus m})$ consist of $n \\times m$ ``matrices''\nof constants, and the map is provided by\n\\[\n\t\\begin{bmatrix}\n\t\tc_{11} & c_{12} & \\dots & c_{1(n-1)} & c_{1n} \\\\\n\t\tc_{21} & c_{22} & \\dots & c_{2(n-1)} & c_{1n} \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n\t\tc_{m1} & c_{m2} & \\dots & c_{m(n-1)} & c_{mn}\n\t\\end{bmatrix}\n\t\\begin{bmatrix} v_1 \\\\ v_2 \\\\ \\vdots \\\\ v_n \\end{bmatrix}\n\t\\in V^{\\oplus n}\n\\]\nwhere the $c_{ij} \\in k$ but $v_i \\in V$; note the type mismatch!\nThis is \\emph{not} just a linear map $V^{\\oplus n_i} \\to V^{\\oplus m_i}$;\nrather, the outputs are $m$ \\emph{linear combinations} of the inputs.\n\nMore generally, we have:\n\\begin{theorem}\n\t[Schur's lemma for completely reducible representations]\n\t\\label{thm:compred_schur}\n\tLet $V$ and $W$ be completely reducible representations,\n\tand set $V = \\bigoplus V_i^{\\oplus n_i}$, $W = \\bigoplus V_i^{\\oplus m_i}$\n\tfor integers $n_i, m_i \\ge 0$, where each $V_i$ is an irrep.\n\tThen\n\t\\[ \\Homrep(V, W)\n\t\t\\cong \\bigoplus_i \\Mat_{n_i \\times m_i}(k) \\]\n\tmeaning that an intertwining operator $T : V \\to W$\n\tamounts to, for each $i$, an $n_i \\times m_i$ matrix of constants\n\twhich gives a map $V_i^{\\oplus n_i} \\to V_i^{\\oplus m_i}$.\n\\end{theorem}\n\n\\begin{corollary}\n\t[Subrepresentations of completely reducible representations]\n\t\\label{cor:subrep_schur}\n\tLet $V = \\bigoplus V_i^{\\oplus n_i}$ be completely reducible.\n\tThen any subrepresentation $W$ of $V$ is isomorphic\n\tto $\\bigoplus V_i^{\\oplus m_i}$ where $m_i \\le n_i$ for each $i$,\n\tand the inclusion $W \\injto V$ is given\n\tby the direct sum of inclusion $V_i^{\\oplus m_i} \\injto V_i^{\\oplus n_i}$,\n\twhich are $n_i \\times m_i$ matrices.\n\\end{corollary}\n\\begin{proof}\n\tApply Schur's lemma to the inclusion $W \\injto V$.\n\\end{proof}\n\n\n\n\\section{Density theorem}\nWe are going to take advantage of the previous result to prove that\nfinite-dimensional algebras have finitely many irreps.\n\n\\begin{theorem}\n\t[Jacobson density theorem]\n\tLet $(V_1, \\rho_1)$, \\dots, $(V_r, \\rho_r)$ be pairwise nonisomorphic\n\tfinite-dimensional representations of $A$.\n\tThen there is a surjective map of vector spaces\n\t\\[ \\bigoplus_{i=1}^r \\rho_i : A \\surjto \\bigoplus_{i=1}^r \\Mat(V_i). \\]\n\\end{theorem}\nThe right way to think about this theorem is that\n\\begin{moral}\n\tDensity is the ``Chinese remainder theorem''\n\tfor irreps of $A$.\n\\end{moral}\nRecall that in number theory, the Chinese remainder theorem tells us\nthat given lots of ``unrelated'' congruences, we can find a single $N$\nwhich simultaneously satisfies them all.\nSimilarly, given lots of different nonisomorphic representations of $A$,\nthis means that we can select a single $a \\in A$ which induces any tuple\n$(\\rho_1(a), \\dots, \\rho_r(a))$ of actions we want --- a surprising result,\nsince even the $r=1$ case is not obvious at all!\n\n\\begin{diagram}\n\t&&& \\rho_1(a) &= M_1 \\in \\Mat(V_1) \\\\\n\t&& \\ruTo(3,2) & \\rho_2(a) &= M_2 \\in \\Mat(V_2) \\\\\n\t\\boxed{a \\in A} && \\ruTo(3,1) && \\vdots \\\\\n\t& \\rdTo(3,1) && \\rho_r(a) &= M_r \\in \\Mat(V_r) \\\\\n\\end{diagram}\n\nThis also gives us the non-obvious corollary\n\\begin{corollary}\n\t[Finiteness of number of representations]\n\tAny finite-dimensional algebra $A$ has at most $\\dim A$ irreps.\n\t\\label{cor:finiteness}\n\\end{corollary}\n\\begin{proof}\n\tIf $V_i$ are such irreps then \n\t$A \\surjto \\bigoplus_i V_i^{\\oplus \\dim V_i}$,\n\thence we have the inequality $\\sum (\\dim V_i)^2 \\le \\dim A$.\n\\end{proof}\n\n\\begin{proof}[Proof of density theorem]\n\tLet $V = V_1 \\oplus \\dots \\oplus V_r$, so $A$\n\tacts on $V = (V, \\rho)$ by $\\rho = \\bigoplus_i \\rho_i$.\n\tThus by \\Cref{prob:reg_mat}, we can instead consider $\\rho$\n\tas an \\emph{intertwining operator}\n\t\\[ \\rho : \\Reg(A) \\to \\bigoplus_{i=1}^r \\Mat(V_i)\n\t\t\\cong \\bigoplus_{i=1}^r V_i^{\\oplus d_i}. \\]\n\tWe will use this instead as it will be easier to work with.\n\n\tFirst, we handle the case $r = 1$.\n\tFix a basis $e_1$, \\dots, $e_n$ of $V = V_1$.\n\tAssuming for contradiction that the map is not surjective.\n\tThen there is a map of representations (by $\\rho$ and the isomorphism)\n\t$\\Reg(A) \\to V^{\\oplus n}$ given by $a \\mapsto (a \\cdot e_1, \\dots, a \\cdot e_n)$.\n\tBy hypothesis is not surjective:\n\tits image is a \\emph{proper} subrepresentation of $V^{\\oplus n}$.\n\tAssume its image is isomorphic to $V^{\\oplus m}$ for $m < n$,\n\tso by \\Cref{thm:compred_schur} there is a matrix of constants $X$ with\n\t\\begin{diagram}\n\t\t\\Reg(A) & \\rTo & V^{\\oplus n} & \\lInj^{X \\cdot -} & V^{\\oplus r} \\\\\n\t\ta & \\rMapsto & (a \\cdot e_1, \\dots, a \\cdot e_n) && \\\\\n\t\t1_A & \\rMapsto & (e_1, \\dots, e_n) & \\lMapsto & (v_1, \\dots, v_m)\n\t\\end{diagram}\n\twhere the two arrows in the top row have the same image;\n\thence the pre-image $(v_1, \\dots, v_m)$ of $(e_1, \\dots, e_n)$ can be found.\n\tBut since $r < n$ we can find constants $c_1, \\dots, c_n$ not all zero\n\tsuch that $X$ applied to the column vector $(c_1, \\dots, c_n)$ is zero:\n\t\\[\n\t\t\\sum_{i=1}^n c_ie_i\n\t\t=\n\t\t\\begin{bmatrix} c_1 & \\dots & c_n \\end{bmatrix}\n\t\t\\begin{bmatrix} e_1 \\\\ \\vdots \\\\ e_n \\end{bmatrix}\n\t\t=\n\t\t\\begin{bmatrix} c_1 & \\dots & c_n \\end{bmatrix}\n\t\tX\n\t\t\\begin{bmatrix} v_1 \\\\ \\vdots \\\\ v_m \\end{bmatrix}\n\t\t= 0\n\t\\]\n\tcontradicting the fact that $e_i$ are linearly independent.\n\tHence we conclude the theorem for $r=1$.\n\n\tAs for $r \\ge 2$, the image $\\rho\\im(A)$ is necessarily of the form\n\t$\\bigoplus_i V_i^{\\oplus r_i}$ (by \\Cref{cor:subrep_schur})\n\tand by the above $r_i = \\dim V_i$ for each $i$.\n\\end{proof}\n\n\\section{Semisimple algebras}\n\n\\begin{definition}\n\tA finite-dimensional algebra $A$ is a \\vocab{semisimple}\n\tif every finite-dimensional representation of $A$ is completely reducible.\n\\end{definition}\n\n\\begin{theorem}\n\t[Semisimple algebras]\n\tLet $A$ be a finite-dimensional algebra.\n\tThen the following are equivalent:\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $A \\cong \\bigoplus_i \\Mat_{d_i}(k)$ for some $d_i$.\n\t\t\\ii $A$ is semisimple.\n\t\t\\ii $\\Reg(A)$ is completely reducible.\n\t\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n\t(i) $\\implies$ (ii) follows\n\tfrom \\Cref{thm:rep_1mat} and \\Cref{prop:rep_direct_sum}.\n\t(ii) $\\implies$ (iii) is tautological.\n\n\tTo see (iii) $\\implies$ (i), we use the following clever trick.\n\tConsider\n\t\\[ \\Homrep(\\Reg(A), \\Reg(A)). \\]\n\tOn one hand, by \\Cref{prob:regA_intertwine},\n\tit is isomorphic to $A\\op$ ($A$ with opposite multiplication),\n\tbecause the only intertwining operators $\\Reg(A) \\to \\Reg(A)$\n\tare those of the form $- \\cdot a$.\n\tOn the other hand, suppose that we have set\n\t$ \\Reg(A) = \\bigoplus_i V_i^{\\oplus n_i} $.\n\tBy \\Cref{thm:compred_schur}, we have\n\t\\[ A\\op \\cong \\Homrep(\\Reg(A), \\Reg(A))\n\t\t= \\bigoplus_i \\Mat_{n_i \\times n_i}(k). \\]\n\tBut $\\Mat_n(k)\\op \\cong \\Mat_n(k)$ (just by transposing),\n\tso we recover the desired conclusion.\n\\end{proof}\n\nIn fact, if we combine the above result with\nthe density theorem (and \\Cref{cor:finiteness}), we obtain:\n\\begin{theorem}\n\t[Sum of squares formula]\n\tFor a finite-dimensional algebra $A$ we have\n\t\\[ \\sum_{i} \\dim(V_i)^2 \\le \\dim A \\]\n\twhere the $V_i$ are the irreps of $A$;\n\tequality holds exactly when $A$ is semisimple,\n\tin which case \n\t\\[ \\Reg(A) \\cong \\bigoplus_i \\Mat(V_i)\n\t\t\\cong \\bigoplus_I V_i^{\\oplus \\dim V_i}. \\]\n\\end{theorem}\n\\begin{proof}\n\tThe inequality was already mentioned in \\Cref{cor:finiteness}.\n\tIt is equality if and only if the map $\\rho : A \\to \\bigoplus_i \\Mat(V_i)$\n\tis an isomorphism; this means all $V_i$ are present.\n\\end{proof}\n\n\\begin{remark}\n\t[Digression]\n\tFor any finite-dimensional $A$, the kernel of the map\n\t$\\rho : A \\to \\bigoplus_i \\Mat(V_i)$ is denoted $\\opname{Rad}(A)$\n\tand is the so-called \\vocab{Jacobson radical} of $A$;\n\tit's the set of all $a \\in A$ which act by zero in all irreps of $A$.\n\tThe usual definition of ``semisimple'' given in books is that\n\tthis Jacobson radical is trivial.\n\\end{remark}\n\n\\section{Maschke's theorem}\nWe now prove that the representation theory of groups is as nice as possible.\n\\begin{theorem}\n\t[Maschke's theorem]\n\tLet $G$ be a finite group, and $k$ an algebraically closed\n\tfield whose characteristic does not divide $|G|$.\n\tThen $k[G]$ is semisimple.\n\\end{theorem}\nThis tells us that when studying representations of groups,\nall representations are completely reducible.\n\\begin{proof}\n\tConsider any finite-dimensional representation $(V, \\rho)$ of $k[G]$.\n\tGiven a proper subrepresentation $W \\subseteq V$,\n\tour goal is to construct a supplementary $G$-invariant subspace $W'$\n\twhich satisfies \\[ V = W \\oplus W'. \\]\n\tThis will show that indecomposable $\\iff$ irreducible,\n\twhich is enough to show $k[G]$ is semisimple.\n\n\tLet $\\pi : V \\to W$ be any projection of $V$ onto $W$,\n\tmeaning $\\pi(v) = v \\iff v \\in W$.\n\tWe consider the \\emph{averaging} map $P : V \\to V$ by\n\t\\[ \n\t\tP(v) = \\frac{1}{\\left\\lvert G \\right\\rvert}\n\t\t\\sum_{g \\in G} \\rho(g\\inv) \\circ \\pi \\circ \\rho(g).\n\t\\]\n\tWe'll use the following properties of the map:\n\t\\begin{exercise}\n\t\tShow that the map $P$ satisfies:\n\t\t\\begin{itemize}\n\t\t\t\\ii For any $w \\in W$, $P(w) = w$.\n\t\t\t\\ii For any $v \\in V$, $P(w) \\in W$.\n\t\t\t\\ii The map $P : V \\to V$ is an intertwining operator.\n\t\t\\end{itemize}\n\t\\end{exercise}\n\tThus $P$ is idempotent (it is the identity on its image $W$),\n\tso by \\Cref{prob:idempotent} we have $V = \\ker P \\oplus \\img P$,\n\tbut both $\\ker P$ and $\\img P$ are subrepresentations as desired.\n\\end{proof}\n\\begin{remark}\n\tIn the case where $k = \\CC$, there is a shorter proof.\n\tSuppose $B : V \\times V \\to \\CC$ is an arbitrary bilinear form.\n\tThen we can ``average'' it to obtain a new bilinear form\n\t\\[ \\left< v,w \\right> \\defeq \\frac{1}{|G|} \\sum_{g \\in G} B(g \\cdot v, g \\cdot w). \\]\n\tThe averaged form $\\left< -,- \\right>$ is $G$-invariant,\n\tin the sense that $\\left< v,w \\right> = \\left< g \\cdot v, g \\cdot w\\right>$.\n\tThen, one sees that if $W \\subseteq V$ is a subrepresentation,\n\tso is its orthogonal complement $W^\\perp$.\n\tThis implies the result.\n\\end{remark}\n\n\\section{Example: the representations of $\\CC[S_3]$}\nWe compute all irreps of $\\CC[S_3]$.\nI'll take for granted right now there are exactly three such representations\n(which will be immediate by the first theorem in the next chapter:\nwe'll in fact see that the number of representations of $G$\nis exactly equal to the number of conjugacy classes of $G$).\n\nGiven that, if the three representations of have dimension $d_1$, $d_2$, $d_3$ ,\nthen we ought to have\n\\[ d_1^2 + d_2^2 + d_3^2 = |G| = 6. \\]\nFrom this, combined with some deep arithmetic,\nwe deduce that we should have $d_1 = d_2 = 1$ and $d_3 = 2$\nor some permutation.\n\nIn fact, we can describe these representations explicitly.\nFirst, we define:\n\\begin{definition}\n\tLet $G$ be a group.\n\tThe complex \\vocab{trivial group representation} of a group $G$\n\tis the one-dimensional representation $\\Ctriv = (\\CC, \\rho)$\n\twhere $g \\cdot v = v$ for all $g \\in G$ and $v \\in \\CC$\n\t(i.e.\\ $\\rho(g) = \\id$ for all $g \\in G$).\n\\end{definition}\n\\begin{remark}\n\t[Warning] The trivial representation of an \\emph{algebra} $A$\n\tdoesn't make sense for us:\n\twe might want to set $a \\cdot v = v$ but this isn't linear in $A$.\n\t(You \\emph{could} try to force it to work by\n\tdeleting the condition $1_A \\cdot v = v$ from our definition;\n\tthen one can just set $a \\cdot v = 0$.\n\tBut even then $\\Ctriv$ would not be the trivial representation of $k[G]$.)\n\\end{remark}\n\nThen the representations are:\n\\begin{itemize}\n\t\\ii The one-dimensional $\\Ctriv$;\n\teach $\\sigma \\in S_3$ acts by the identity.\n\n\t\\ii There is a nontrivial one-dimensional representation\n\t$\\Csign$ where the map $S_3 \\to \\CC^\\times$ is given\n\tby sending $\\sigma$ to the sign of $\\sigma$.\n\tThus in $\\Csign$ every $\\sigma \\in S_3$ acts as $\\pm 1$.\n\tOf course, $\\Ctriv$ and $\\Csign$ are not isomorphic\n\t(as one-dimensional representations are never isomorphic\n\tunless the constants they act on coincide for all $a$,\n\tas we saw in \\Cref{prob:one_dim}).\n\n\t\\ii Finally, we have already seen the two-dimensional representation,\n\tbut now we give it a name.\n\tDefine $\\refl_0$ to be the representation whose vector space is\n\t$\\{ (x,y,z) \\mid x+y+z = 0 \\}$,\n\tand whose action of $S_3$ on it is permutation of coordinates.\n\t\\begin{exercise}\n\t\tShow that $\\refl_0$ is irreducible, for example by showing directly\n\t\tthat no subspace is invariant under the action of $S_3$.\n\t\\end{exercise}\n\tThus $V$ is also not isomorphic to the previous two representations.\n\\end{itemize}\nThis implies that these are all the irreps of $S_3$.\nNote that, if we take the representation $V$ of $S_3$ on $k^{\\oplus 3}$,\nwe just get that $V = \\refl_0 \\oplus \\CC_{\\text{triv}}$.\n\n\\section\\problemhead\n\n\\begin{problem}\n\tFind all the irreps of $\\CC[\\Zc n]$.\n\t\\begin{hint}\n\t\tThey are all one-dimensional, $n$ of them.\n\t\tWhat are the homomorphisms $\\Zc n \\to \\CC^\\times$?\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[Maschke requires $|G|$ finite]\n\tConsider the representation of the group $\\RR$\n\ton $\\CC^{\\oplus 2}$ under addition by a homomorphism\n\t\\[ \n\t\t\\RR \\to \\Mat_2(\\CC)\n\t\t\\quad\\text{by}\\quad\n\t\tt \\mapsto \n\t\t\\begin{bmatrix} 1 & t \\\\ 0 & 1 \\end{bmatrix}.\n\t\\]\n\tShow that this representation is not irreducible,\n\tbut it is indecomposable.\n\t\\begin{hint}\n\t\tThe span of $(1,0)$ is a subrepresentation.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tProve that all irreducible representations\n\tof a finite group are finite-dimensional.\n\t\\begin{hint}\n\t\tThis is actually easy.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tPick any $v \\in V$, then the subspace\n\t\tspanned by elements $g \\cdot v$ for $v \\in V$\n\t\tis $G$-invariant;\n\t\tthis is a finite-dimensional subspace,\n\t\tso it must equal all of $V$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tDetermine all the complex irreps of $D_{10}$.\n\t\\begin{hint}\n\t\tThere are only two one-dimensional ones\n\t\t(corresponding to the only two\n\t\thomomorphisms $D_{10} \\to \\CC^\\times$).\n\t\tSo the remaining ones are two-dimensional.\n\t\\end{hint}\n\\end{problem}\n", "meta": {"hexsha": "c8443330946789d4ede02085dfab70873c43f3e3", "size": 16509, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/rep-theory/semisimple.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/semisimple.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/semisimple.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": 37.7780320366, "max_line_length": 87, "alphanum_fraction": 0.6898055606, "num_tokens": 5613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.6346006359955911}}
{"text": "This module tries to recognize syntactic symmetries in the input formula and adds symmetry breaking constraints.\nThe core functionality is provided by \\texttt{carl} through \\texttt{carl::formula::breakSymmetries()} which internally encodes the formula as a graph and uses \\texttt{bliss} to find automorphisms on this graph.\n\n\\paragraph{Efficiency}\nFinding automorphisms is as difficult as determining whether two graphs are isomorphic, and it is not known whether this problem can be solved in polynomial or exponential time.\nIn practice, current solvers like \\texttt{bliss} perform very good on large graphs and we therefore assume this module to be sufficiently fast.\n", "meta": {"hexsha": "c755145e216f7afc906e05367ff0b33df8fd8af9", "size": 670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/smtrat-modules/SymmetryModule/SymmetryModule.tex", "max_stars_repo_name": "minemebarsha/smtrat", "max_stars_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_stars_repo_licenses": ["MIT"], "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/smtrat-modules/SymmetryModule/SymmetryModule.tex", "max_issues_repo_name": "minemebarsha/smtrat", "max_issues_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_issues_repo_licenses": ["MIT"], "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/smtrat-modules/SymmetryModule/SymmetryModule.tex", "max_forks_repo_name": "minemebarsha/smtrat", "max_forks_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_forks_repo_licenses": ["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.7142857143, "max_line_length": 210, "alphanum_fraction": 0.8194029851, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6346006325196802}}
{"text": "\n\\subsection{Endomorphisms on real functions}\n\nWe start with our vector \\(f(x)\\).\n\n\\(h(x)=f(x)g(x)\\)\n\nThe equivalent of the identity matrix is where \\(g(x)=1\\).\n\nThese are similar to endomorphisms where all off diagonal elements are \\(0\\).\n\n\\subsubsection{Differentiation}\n\n\\(h(x)=\\dfrac{\\delta }{\\delta x}f(x)\\)\n\n\\subsubsection{Integration}\n\n\\(h(x)=\\int_{-\\infty }^x f(z) dz\\)\n\n", "meta": {"hexsha": "1704f0dc45aa51c4b98806cb5f2425e8809bd6f2", "size": 379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/02-01-endomorphisms.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/02-01-endomorphisms.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/02-01-endomorphisms.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.95, "max_line_length": 77, "alphanum_fraction": 0.6781002639, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6345864081931504}}
{"text": "\\section{Neural Networks}\n\n% ##############################################################################\n\\subsection{Artificial Neural Networks}\n\\label{ssec:ArtificialNeuralNetworks}\n\nNeural networks are computing systems that are inspired by, but not identical to, biological neural networks that constitute animal brains. Such systems essentially \\emph{learn} to perform tasks by considering multiple samples, generally without being programmed with task-specific rules. They form a basis for deep machine learning~\\cite{goodfellow2016dl}.\n\nThe goal of a neural network is to approximate some unknown function $f$. For instance, when considering a classiﬁer, the transformation $y = \\func{f}{\\vx}$  maps the given input $\\vx$ to a category $y$. Such a network, therefore, defines a mapping and learns the value of the parameters that result in the best function approximation.\n\nThese models can be described with a directed acyclic graph denoting the sequential composition of several functions. More concretely, we might have three functions $\\suprbrackets{f}{1}$, $\\suprbrackets{f}{2}$ and $\\suprbrackets{f}{3}$, forming a chain, $\\func{f}{\\vx} = \\func{\\suprbrackets{f}{3}}{\\func{\\suprbrackets{f}{2}}{\\func{\\suprbrackets{f}{1}}{\\vx}}}$. These chain structures are the most commonly used structures in neural networks. Deep machine learning consists of multiple such layers of neurons that are trained using the \\emph{backpropagation} algorithm~\\cite{rumelhart1986backprop}.\n\n% ##############################################################################\n\\subsection{Convolutional Neural Networks}\n\\label{ssec:ConvolutionalNeuralNetworks}\n\nThis type of neural network has gained popularity in the computer vision community thanks to a never-seen-before performance on image classification task~\\cite{krizhevsky2012classification}. This approach processes images or other high dimensional, grid-like input and then learns the importance (weights and biases) of various aspects of the input data.\n\nThe successful ability of these networks to capture spatial properties via learned convolutional filters is the fundamental principle. Let $f$ and $g$ be functions. Then, the operation of convolution denoted by $\\star$ produces a third function, as a result of the following computation (demonstrating the commutativity property, too)~\\cite{goodfellow2016dl}:\n\\begin{equation}\n    \\label{eq:ConvolutionContinuous}\n    \\func{\\rbrackets{f \\star g}}{t} =\n    \\int_{-\\infty}^{\\infty}\n    \\func{f}{\\tau}\n    \\func{g}{t - \\tau}\n    d\\tau =\n    \\int_{-\\infty}^{\\infty}\n    \\func{f}{t -\\tau}\n    \\func{g}{\\tau}\n    d\\tau.\n\\end{equation}\nIn this setting, $f$ is the input, $g$ is the kernel, and the output of this operation is a feature map. During training, the aim is to learn the weights of the kernel matrix that produces a feature map based on which the model can solve the given task.\n\nLet $I$ be a two-dimensional input image and $K$ be a two-dimensional kernel. Then, for a given position $\\rbrackets{i, j}$ in the input image $I$, the discrete convolution can be written as\n\\begin{equation}\n    \\label{eq:ConvolutionDiscrete}\n    \\func{\\rbrackets{f \\star g}}{i, j} =\n    \\sum_{m}\n    \\sum_{n}\n    \\func{I}{m, n}\n    \\func{K}{i - m, j - n}.\n\\end{equation}\nMany machine learning libraries implement the cross-correlation operation, not the convolution operation by its strict definition. This operation is the same except for the fact that the kernel is not flipped. Thus, the result of the cross-correlation is given by\n\n\\begin{equation}\n    \\label{eq:CrossCorrelation}\n    \\func{\\rbrackets{f \\star g}}{i, j} =\n    \\sum_{m}\n    \\sum_{n}\n    \\func{I}{i + m, j + n}\n    \\func{K}{m, n}.\n\\end{equation}\n\nAn indispensable outcome of \\glspl{cnn} is the ability to capture hierarchical relations. Layers placed near the input of the model capture low-level features such as edges, colors, gradient orientations, and so on. On the other hand, layers placed further, deeper in the model, highlight semantic, abstract features that are specific to the task at hand.\n\nAnother prominent use case of \\glspl{cnn} is \\emph{transfer learning}, where a pre-trained model is adopted for a new task, utilizing the already learned features. These pre-trained models may come in various flavors, but typical ones are pre-trained for an image classification task using the \\datasetname{ImageNet} dataset~\\cite{deng2009imagenet}. The reasoning is that visual features such as edges and contours are vital to general object recognition tasks, hence it is not needed to learn coarse, rudimentary, low-level features from scratch all the time.\n", "meta": {"hexsha": "a31cf7276e54b3ebd9a3bab90c58400e32af94ff", "size": 4622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapters/theoretical_foundations/sections/neural_networks.tex", "max_stars_repo_name": "mondrasovic/phd_thesis", "max_stars_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_stars_repo_licenses": ["MIT"], "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/chapters/theoretical_foundations/sections/neural_networks.tex", "max_issues_repo_name": "mondrasovic/phd_thesis", "max_issues_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_issues_repo_licenses": ["MIT"], "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/chapters/theoretical_foundations/sections/neural_networks.tex", "max_forks_repo_name": "mondrasovic/phd_thesis", "max_forks_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_forks_repo_licenses": ["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.0877192982, "max_line_length": 597, "alphanum_fraction": 0.7345305063, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6345864043774874}}
{"text": "\\section{Algebraic Manipulations}\n\\subsection{Definitions}\nSophie Germain: \\[x^4 + 4y^4 = (x^2-2xy+y^2)(x^2+2xy+y^2)\\] \\\\\n$(x+y)^3 = x^3+3xy(x+y)+y^3 = x^3+3x^2y+3xy^2+y^3$. \\\\\n$(x-y)^3 = x^3-3xy(x-y)+y^3 = x^3-3x^2y+3xy^2-y^3$. \\\\\n$x^3 + y^3 = (x+y)(x^2-xy+y^2)$. \\\\\n$x^3 - y^3 = (x-y)(x^2+xy+y^2)$. \\\\\n$x^3+y^3+z^3-3xyz = (x+y+z)(x^2+y^2+z^2−xy−yz−zx)$.\n\n\\subsection{Practice Problems}\n\\begin{enumerate}\n  \\item Given that $x$ and $y$ are distinct nonzero real numbers such that $x+2/x=y+2/y$, what is $xy$?\n  \\\\ \\textbf{Solution}: \n  \\begin{align*}\n    x - y &= 2/y - 2/x \\\\\n    x - y &= \\frac{2x - 2y}{xy} \\\\\n    &= \\frac{2(x-y)}{xy} \\\\\n    &= \\frac{2}{xy} = 1 \\\\\n    xy &= \\boxed{2}.\n  \\end{align*}\n  \\item Suppose that real number $x$ satisfies $\\sqrt{49-x^2} - \\sqrt{25 - x^2} = 3$. What is the value of $\\sqrt{49-x^2} + \\sqrt{25 - x^2}$\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    &(\\sqrt{49-x^2} - \\sqrt{25 - x^2})(\\sqrt{49-x^2} + \\sqrt{25 - x^2}) \\\\\n    &= (49-x^2) - (25 - x^2) \\\\\n    &= 24 = 3(\\sqrt{49-x^2} + \\sqrt{25 - x^2})\n    (\\sqrt{49-x^2} + \\sqrt{25 - x^2}) = \\boxed{8}.\n  \\end{align*}\n  \\item What is the minimum value of the expression $x^2 + 8x + 13$ for any real $x$?\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    x^2 + 8x + 13 = (x + 4)^2 - 3 \\\\\n    \\min((x + 4)^2 - 3) = \\boxed{-3}.\n  \\end{align*}\n  \\item Real numbers $x$ and $y$ satisfy the equation $x^2+y^2=10x-6y-34$. What is $x+y$?\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    (x^2-10x) + (y^2+6y) = -34 \\\\\n    (x-5)^2+(y+3)^2 = 0 \\\\\n    x = 5, y = -3 \\\\\n    x+y = \\boxed{2}.\n  \\end{align*}\n  \\item There is a positive integer $n$ such that $(n+1)!+(n+2)! = n!\\cdot 440$. What is the sum of the digits of $n$?\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    n!(n+1)^2(n+2) &= n!(440) \\\\\n    (n+1)(n+3) &= 440 \\\\\n    ((n+2)+1)((n+2)-1) &= 440 \\\\\n    (n+2)^2-1^2 &= 440 \\\\\n    (n+2)^2 &= 441 \\\\\n    n + 2 &= 21 \\\\\n    n &= \\boxed{19}.\n  \\end{align*}\n  \\item For all integers $n \\geq 9$, the value of $\\frac{(n+2)! - (n+1)!}{n!}$ is always which of the following?\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    \\frac{n!((n+2)(n+1)-(n+1))}{n!} = (n+1)^2.\n  \\end{align*}\n  The expression must always be a perfect square.\n  \\item Let $f(x) = x^{2}(1-x)^{2}$. What is the value of the sum\n  $f \\left(\\frac{1}{2019} \\right)-f  \\left(\\frac{2}{2019} \\right)+f \\left(\\frac{3}{2019} \\right)-f \\left(\\frac{4}{2019} \\right)+\\cdots + f \\left(\\frac{2017}{2019} \\right) - f \\left(\\frac{2018}{2019} \\right)?$\n  \\\\ $\\textbf{(A) }0\\qquad\\textbf{(B) }\\frac{1}{2019^{4}}\\qquad\\textbf{(C) }\\frac{2018^{2}}{2019^{4}}\\qquad\\textbf{(D) }\\frac{2020^{2}}{2019^{4}}\\qquad\\textbf{(E) }1$\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    \\left( f \\left(\\frac{1}{2019} \\right) - f \\left(\\frac{1}{2019} \\right) \\right) +  \\left( f \\left(\\frac{2}{2019} \\right) - f \\left(\\frac{2}{2019} \\right) \\right) + \\cdots \\\\ + \\left( f \\left(\\frac{1009}{2019} \\right) - f \\left(\\frac{1009}{2019} \\right) \\right)\n  \\end{align*}\n  The answer is $\\boxed{\\textbf{(A) }0}$.\n  \\item Given that $x+\\frac{1}{x}=3$, find \n  \\begin{enumerate}\n    \\item $x^2+\\frac{1}{x^2} = (x + \\frac{1}{x})^2 = x^2 + 2 + \\frac{1}{x^2} = 3^2 - 2 = \\boxed{7}$.\n    \\item $x^3 + \\frac{1}{x^3} = (x+\\frac{1}{x})(x^2-1+\\frac{1}{x^2}) = 3(7-1)=\\boxed{18}$.\n    \\item $x^4 + \\frac{1}{x^4} = 7^2 + 2 = 49 + 2 = \\boxed{51}$.\n  \\end{enumerate}\n  \\item Real numbers $x$ and $y$ satisfy $x + y = 4$ and $x \\cdot y = -2$. What is the value of\\[x + \\frac{x^3}{y^2} + \\frac{y^3}{x^2} + y?\\]\n  $\\textbf{(A)}\\ 360\\qquad\\textbf{(B)}\\ 400\\qquad\\textbf{(C)}\\ 420\\qquad\\textbf{(D)}\\ 440\\qquad\\textbf{(E)}\\ 480$\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    &\\frac{x^3}{x^2}+\\frac{x^3}{y^2}+\\frac{y^3}{x^2}+\\frac{y^3}{y^2} \\\\\n    &= \\frac{x^3+y^3}{x^3}+\\frac{x^3+y^3}{y^2} \\\\\n    &= \\frac{88}{x^2} = \\frac{88(x^2+y^2)}{4} = \\boxed{44}.\n  \\end{align*}\n  \\item Let $r$, $s$, and $t$ be the three roots of the equation\\[8x^3 + 1001x + 2008 = 0.\\]Find $(r + s)^3 + (s + t)^3 + (t + r)^3$.\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    (r+s)^3 + (s+t)^3 + (t+r)^3  \\\\ = (0-t)^3 + (0-r)^3 + (0-s)^3 = -(r^3 + s^3 + t^3) \\\\\n    r^3 + s^3 + t^3 - 3rst = (r+s+t)(r^2 + s^2 + t^2 - rs - st - tr) = 0 \\\\\n    r^3+s^3+t^3 = 3rst = -251, -251 \\cdot -3 = \\boxed{753}.\n  \\end{align*}\n  \\item Find $3x^2y^2$ is $x$ and $y$ are integers such that $y^2+3x^2y^2=30x^2+517$.\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    a = x^2, b = y^2 \\\\\n    b+3ab = 30a+517 \\\\\n    ab + \\frac{b}{3} - 10a = \\frac{517}{3} \\\\\n    (a+\\frac{1}{3})(b-10) = \\frac{507}{3} \\\\\n    (3x^2 + 1)(y^2 - 10) = 507 \\\\\n    (x, y) = (\\pm 2, \\pm 7)\n  \\end{align*}\n  $3x^2y^2 = 3 \\cdot 4 \\cdot 49 = \\boxed{588}$.\n  \\item What is the remainder when $s^{202} + 202$ is divided by $2^{101} + 2^{51} + 1$.\n  \\item Two non-zero real numbers, $a$ and $b,$ satisfy $ab = a - b$. Which of the following is a possible value of $\\frac {a}{b} + \\frac {b}{a} - ab$?\n\n  \\textbf{Solution}:\n  \\begin{align*}\n    \\frac{a^2 + b^2}{ab} - ab &= \\frac{(a-b)^2+2ab}{ab} - ab \\\\\n    &= \\frac{(ab)^2 + 2ab}{ab} - ab \\\\\n    &= ab + 2 - ab = \\boxed{2} \\\\\n  \\end{align*}\n  \\item If $x + \\frac{1}{x} = 4$, then what is the value of $x^8 + \\frac{1}{x^8}$?\n\n  \\textbf{Solution}:\n  \\begin{align*}\n    x^2 + \\frac{1}{x^2} = 4^2 - 2 = 14 \\\\\n    x^4 + \\frac{1}{x^4} = 14^2 - 2 = 194 \\\\\n    x^8 = \\frac{1}{x^8} = 194^2 - 2 = \\boxed{37624}.\n  \\end{align*}\n  \\item Let $a$ and $b$ be relatively prime positive integers with $a>b>0$ and $\\dfrac{a^3-b^3}{(a-b)^3} = \\dfrac{73}{3}.$ What is $a-b?$\n  \\\\ \\textbf{Solution}:\n  \\begin{align*}\n    \\frac{a^3-b^3}{(a-b)^3} &= \\frac{(a-b)(a^2+ab+b^2)}{(a-b)^3} \\\\\n    &= \\frac{a^2+ab+b^2}{(a-b)^2} \\\\\n    &= \\frac{(a-b)^2 - 3ab}{(a-b)^2} \\\\\n    &= 1+\\frac{3ab}{(a-b)^2} \\\\\n    \\frac{3ab}{(a-b)^2} &= \\frac{70}{3} \\\\\n    9ab &= 70(a-b)^2 \\\\\n    3 \\sqrt{\\frac{ab}{70}} &= a - b \\\\\n    ab | 70&, 3 | a - b.\n  \\end{align*}\n  Thus $a = 10, b = 7$ so $a - b = \\boxed{3}$. \n  \\item If $(a - 1/a)^2 = 4$, what is the absolute value of $a^3 - 1/a^3$? \n\n  \\textbf{Solution}:\n  \\begin{align*}\n    a - \\frac{1}{a} &= 2 \\\\\n    (a - \\frac{1}{a})^3 &= a^3 - \\frac{1}{a^3} - 3(x - \\frac{1}{x}) \\\\\n    2^3 &= a^3 - \\frac{1}{a^3} - 6 \\\\\n    a^3 - \\frac{1}{a^3} &= \\boxed{14}\n  \\end{align*}\n\\end{enumerate}\n", "meta": {"hexsha": "74c56b15d0ea01fd37bdd841c890e0a7020fa46b", "size": 6215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/algebra/algebraic-manipulations/algebraic-manipulations.tex", "max_stars_repo_name": "coderinblack08/math-binder", "max_stars_repo_head_hexsha": "5126211d519de4835e5350babdb6bb2c752a0b62", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-07T01:58:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-21T17:58:32.000Z", "max_issues_repo_path": "tex/algebra/algebraic-manipulations/algebraic-manipulations.tex", "max_issues_repo_name": "coderinblack08/math-binder", "max_issues_repo_head_hexsha": "5126211d519de4835e5350babdb6bb2c752a0b62", "max_issues_repo_licenses": ["MIT"], "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/algebra/algebraic-manipulations/algebraic-manipulations.tex", "max_forks_repo_name": "coderinblack08/math-binder", "max_forks_repo_head_hexsha": "5126211d519de4835e5350babdb6bb2c752a0b62", "max_forks_repo_licenses": ["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.3928571429, "max_line_length": 263, "alphanum_fraction": 0.4962188254, "num_tokens": 2976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6345864024696558}}
{"text": "\\documentclass[main.tex]{subfiles}\r\n\\begin{document}\r\n\\chapter{Set Theory}\r\n\r\n\\epigraph{Sets are wild fam.}{Justin Goodman}\r\n\r\n\\minitoc\r\n\r\n\\section{Introduction}\r\n\r\nSets were introduced by Georg Cantor in the late 1800s. Cantor is the grandfather of set theory and continuity. We will see continuity topics later, including Cantor's famous diagonal argument. We can define all of discrete mathematics using sets. What is a set though?\r\n\r\n\\begin{defn}[Set\\index{Set}]\r\n\tAn unordered collection of unique objects. We denote sets using curly braces \\(\\{\\}\\) with objects appearing in them -- e.g.\\ \\(\\{\\circ, 3, \\pi, \\blacktriangle\\}\\)\r\n\\end{defn}\r\n\r\nEach part of this definition is important -- we do not have a set unless it satisfies the entire definition. We now examine the definition.\r\n\r\n\\begin{itemize}\r\n\t\\item A set is a \\textbf{collection} of stuff. Think of a set like a box. You can put things in your box, and you can take them out. Your box is special -- it can expand/contract to fit anything you like.\r\n\t\\item A set is \\textbf{unordered}. This simply means that any different ordering we give to a set does not change the equality property of the set -- \\(\\{1,2\\} = \\{2,1\\}\\)\r\n\t\\item A set contains \\textbf{objects}. A set can contain anything you want.\r\n\t\\item A set contains \\textbf{unique} objects. For any two distinct objects in a set, the objects cannot be equal. Sometimes we see books describe the sets \\(\\{1,1,2,3\\}\\) and \\(\\{1,2,3\\}\\) as equal, however we argue that the first set is not even a set!\\footnote{We would classify the set \\(\\{1,1,2,3\\}\\) as a \\textit{multi-set}} We recommend you ask your instructor about this distinction, and follow what they prefer.\r\n\\end{itemize}\r\n\r\nThis chapter includes an overview of set theory -- sets, operations, binary relations, and theorems.\r\n\r\n\\section{Building Sets}\r\n\r\nBefore we dive into set theory concepts, we first introduce a few ways to denote sets.\r\n\r\nTo start, you can simply denote a set by just writing each element inside some curly braces. For example, \\[\\{1,2,3\\}\\] describes the set containing 1, 2, and 3. This method is not useful when describing big sets, though. If your set has \\(2^{64}\\) elements, you would never be able to write them all out!\r\n\r\nTo solve this, we can use \\textit{ellipses} -- \\(\\cdots\\) -- three dots in a row. Ellipses inside a set simply mean that you take the implicit pattern described in the set already, and continue it (possibly indefinitely). For example, \\[\\{1,2,3,\\cdots,10\\} = \\{1,2,3,4,5,6,7,8,9,10\\}\\]\r\nHere, the pattern is described in the \\(1,2,3\\) part -- increase by 1. Now, \r\n\r\nSo far, the presented notations lack power. To combat this, we introduce set-builder notation. As the name implies, this is a way of building sets.\r\n\r\n\\begin{defn}[Set-builder Notation\\index{Set-builder Notation}]\r\n\tA way of defining sets. Syntax: \\(\\{\\,\\mbox{element} \\mid \\mbox{condition(s)}\\,\\}\\), read as, ``element \\textit{such that} condition(s) is (are) satisfied.'' For example, the set of even integers (which we will learn about soon) can be written as: \\(\\{e \\mid (\\exists k \\in \\Z)[e = 2k]\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{rem}\r\n\tYou may also see the \\(:\\) character instead of the \\(\\mid\\) character in set-builder notation. These are equivalent. \\(\\{e \\mid (\\exists k \\in \\Z)[e = 2k]\\} = \\{e : (\\exists k \\in \\Z)[e = 2k]\\}\\).\r\n\\end{rem}\r\n\r\nIt is pivotal that you know how to read and create sets this way. The syntax is very flexible because the conditions can be almost anything you like. The conditions should, however, relate to the set itself (otherwise the set would be trivially pointless).\r\n\r\n\\exsol{\r\n\tBuild a set that contains all square roots of even integers (for now, use the definition of even integers given previously).\r\n}{\r\n\t\\[S = \\{x \\mid (\\exists k \\in \\Z)[x^2 = 2k]\\}\\]\r\n}\r\n\r\n\\exsol{\r\n\tBuild a set that contains everything except for the object \\(\\star\\).\r\n}{\r\n\t\\[S = \\{y : y \\neq \\star\\}\\]\r\n}\r\n\r\nWith set-builder notation, we can describe the following set short-cut: \\[[n] = \\{i \\in \\Z \\mid 0 \\leq i \\leq n\\}\\].\r\nWe do not know what \\(\\Z\\) is just yet, but we will get there soon enough.\r\n\r\n\\begin{rem}\r\n\tSome authors denote \\([3] = \\{1,2,3\\}\\) since they do not include 0 as part of the natural numbers. More on this later. For now, just follow whatever your professor is doing.\r\n\\end{rem}\r\n\r\n\\begin{rem}\r\n\tSome authors also reserve \\([x]\\) to mean the floor function -- the greatest integer smaller than \\(x\\). As with anything in math, context is key. We will not use brackets to indicate the floor function, but you should be aware that different notation conventions exist.\r\n\\end{rem}\r\n\r\nFinally, we can describe continuous-interval sets. You may be familiar with the real number line -- this is a continuous line because there are no ``breaks'' between any two numbers you pull from it. Given any two numbers on the real number line, we can always take the midpoint to get another real number! How do we denote these intervals? We use interval notation:\r\n\\begin{itemize}\r\n\t\\item \\((x,y) = \\{r \\in \\R : x < r < y\\}\\)\r\n\t\\item \\((x,y] = \\{r \\in \\R : x < r \\leq y\\}\\)\r\n\t\\item \\([x,y) = \\{r \\in \\R : x \\leq r < y\\}\\)\r\n\t\\item \\([x,y] = \\{r \\in \\R : x \\leq r \\leq y\\}\\)\r\n\\end{itemize}\r\n\r\nA parenthesis means we \\textit{exclude} the associated number from the continuous interval, and a bracket means we \\textit{include} the associated number.\r\n\r\n\\section{Definitions}\r\n\r\nWe include a handful of definitions and notations we use in our study of set theory.\r\n\r\nBinary relations:\r\n\r\n\\begin{defn}[Member/Element]\r\n\tAn object that is part of a set. Symbol: \\(\\in\\). Example: \\(5 \\in \\{1,2,3,4,5\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Subset]\r\n\tA set of elements that are all members of another set. A subset CAN be equal to its parent set. Symbol: \\(\\subseteq\\). Example: for sets \\(S\\) and \\(T\\), \\(S \\subseteq T \\Leftrightarrow (\\forall s \\in S)[s \\in T]\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Proper Subset]\r\n\tA set of elements that are all members of another set, but the subset is NOT equal to the parent set. Symbol: \\(\\subset\\). Example: for sets \\(S\\) and \\(T\\), \\(S \\subset T \\Leftrightarrow (\\forall s \\in S)[(s \\in T) \\land (S \\neq T)]\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Superset]\r\n\tA flipped version of subset. Symbol: \\(\\supseteq\\). Example: for sets \\(S\\) and \\(T\\), \\(S \\supseteq T \\Leftrightarrow (\\forall t \\in T)[t \\in S]\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Proper Superset]\r\n\tA flipped version of proper subset. Symbol: \\(\\supset\\). Example: for sets \\(S\\) and \\(T\\), \\(S \\supset T \\Leftrightarrow (\\forall t \\in T)[(t \\in S) \\land (S \\neq T)]\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Equality]\r\n\tTwo sets are equal if and only if both sets are subsets of each other. Notation: for sets \\(S\\) and \\(T\\), \\(S = T \\Leftrightarrow (S \\subseteq T) \\land (T \\subseteq S)\\). To prove this, you can use set-builder notation \\& theorems (given later in this chapter) to show equivalence, or you can prove \\((e \\in S \\Rightarrow e \\in T) \\land (e \\in T \\Rightarrow e \\in S)\\)\r\n\\end{defn}\r\n\r\nThings:\r\n\r\n\\begin{defn}[Cardinality]\r\n\tThe number of elements in a set. Notation: for a set \\(S\\), cardinality is denoted by \\(|S|\\). For example, $|\\{2,3,4,5,6\\}| = 5$\r\n\\end{defn}\r\n\r\n\\begin{defn}[Empty/Null Set]\r\n\tThe set containing zero elements. Notation: $\\emptyset$ or $\\{\\}$ -- these symbols are \\textit{interchangable}. \\textbf{Note}: \\(|\\emptyset| = 0\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Universal Set]\r\n\tThe set of all possible sets. Notation: \\(U\\) is the Universal Set\r\n\\end{defn}\r\n\r\n\\begin{defn}[Power Set]\r\n\tThe set of all possible subsets of a set. Notation: of a set \\(S\\), the power set is denoted \\(\\mathcal{P}(S)\\). For example, \\(\\mathcal{P}(\\{1,2,3\\}) = \\{\\emptyset, \\{1\\}, \\{2\\}, \\{3\\}, \\{1,2\\}, \\{1,3\\}, \\{2,3\\}, \\{1,2,3\\}\\}\\). \\textbf{Note}: for any set \\(S\\), \\(|\\mathcal{P}(S)| = 2^{|S|}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Disjoint]\r\n\tTwo sets are disjoint if and only if both sets have no members in common. For two sets \\(S\\) and \\(T\\), this is equivalent to \\(S \\cap T = \\emptyset\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Partition]\r\n\t(of a set) A set of sets \\(T\\) where the union of every element in \\(T\\) equals the original set, and all elements in \\(T\\) are disjoint. For example, \\(\\{\\{1,2\\}, \\{3\\}, \\{4,5,6\\}\\}\\) is a partition of \\(\\{1,2,3,4,5,6\\}\\)\r\n\\end{defn}\r\n\r\nOperations:\r\n\r\n\\begin{defn}[Union]\r\n\t(of two sets) A set that includes all elements from both sets (discounting duplicates, since a set must contain unique elements). Notation: for sets \\(S\\) and \\(T\\), \\(S \\cup T = \\{e \\mid (e \\in S) \\lor (e \\in T)\\}\\). For example, \\(\\{1,2,3\\} \\cup \\{3,4,5\\} = \\{1,2,3,4,5\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Intersection]\r\n\t(of two sets) A set that includes only elements from both sets. Notation: for sets \\(S\\) and \\(T\\), \\(S \\cap T = \\{e \\mid (e \\in S) \\land (e \\in T)\\}\\). For example, \\(\\{1,2,3\\} \\cap \\{3,4,5\\} = \\{3\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Subtraction]\r\n\t(of two sets) A set representing the elements of the second set taken out of the first set. \\textbf{Note}: subtraction order \\textit{matters} (i.e.\\ subtraction is not commutative). Notation: for sets \\(S\\) and \\(T\\), \\(S - T = \\{e \\mid (e \\in S) \\land (e \\not\\in T)\\}\\). You may also see set subtraction represented as \\(S \\setminus T\\). For example, \\(\\{1,2,3\\} \\setminus \\{3,4,5\\} = \\{1,2\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Compliment]\r\n\t(of a set) A set containing every element from the universal set that is NOT contained in the original set. \\textbf{Note}: you can take the compliment with respect to different universes so long as you specify which one -- by default the universal set is assumed. Notation: for a set \\(S\\), the complement is noted as \\(S^{\\mathsf{c}}\\), or \\(S^{'}\\), or \\(\\overline{S}\\); with the universe \\(U\\), \\(S^{'} = \\{e \\mid e \\in (U - S)\\}\\)\r\n\\end{defn}\r\n\r\n\\begin{defn}[Cross Product]\r\n\t(of two sets) The set of all ordered pairings of two sets. Notation: for sets \\(S\\) and \\(T\\), \\(S \\times T = \\{(s,t) \\mid s \\in S \\land t \\in T\\}\\).\r\n\t\r\n\tNote: you can take the cross product of multiple sets. For sets \\(A_1 \\cdots A_n\\), the cross product \\(A_1 \\times A_2 \\times \\cdots \\times A_n = \\{(a_1, a_2, \\cdots, a_n) \\mid a_i \\in A_i\\}\\). When \\(A_1 = \\cdots = A_n = A\\) then we let \\(A^n = A_1 \\times A_2 \\times \\cdots \\times A_n\\)\r\n\\end{defn}\r\n\r\n\\section{Theorems}\r\n\r\nWe will not go into depth on the axioms of Zermelo–Fraenkel set theory. We do include a handful of nice theorems that will aid in proving statements about sets. Sometimes these are referred to as axioms, however we argue that the following statements can be derived from ZF set theory axioms and should hence be called theorems. It does not really matter though.\r\n\r\nYou are not required to memorize these theorems -- they will be given to you as a table.\r\n\\marginpar{See appendix \\ref{appendix:tables}.}\r\n\r\n\\begin{thm}[Commutativity]\r\n\tFor any sets \\(A\\) and \\(B\\) the union and intersection operations are commutative: \\[A \\cup B = B \\cup A\\] \\[A \\cap B = B \\cap A\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Associativity]\r\n\tFor any sets \\(A\\), \\(B\\), and \\(C\\) the union and intersection operations are associative: \\[(A \\cup B) \\cup C = A \\cup (B \\cup C)\\] \\[(A \\cap B) \\cap C = A \\cap (B \\cap C)\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Distributivity]\r\n\tFor any sets \\(A\\), \\(B\\), and \\(C\\) the union and intersection operations are distributive: \\[A \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C)\\] \\[A \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Identity]\r\n\tFor any set \\(A\\) and universe \\(U\\) the following hold: \\[A \\cup \\emptyset = A\\] \\[A \\cap U = A\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Inverse]\r\n\tFor any set \\(A\\) and universe \\(U\\) the following hold: \\[A \\cup A^{\\mathsf{c}} = U\\] \\[A \\cap A^{\\mathsf{c}} = \\emptyset\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Double Compliment]\r\n\tFor any set \\(A\\) the following holds: \\[(A^{\\mathsf{c}})^{\\mathsf{c}} = A\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Idempotence]\r\n\tFor any set \\(A\\) the following hold: \\[A \\cup A = A\\] \\[A \\cap A = A\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Universal Bound (Domination)]\r\n\tFor any set \\(A\\) and universe \\(U\\) the following hold: \\[A \\cup U = U\\] \\[A \\cap \\emptyset = \\emptyset\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[De Morgan's]\r\n\tFor any sets \\(A\\) and \\(B\\) the following hold: \\[(A \\cup B)^{\\mathsf{c}} = A^{\\mathsf{c}} \\cap B^{\\mathsf{c}}\\] \\[(A \\cap B)^{\\mathsf{c}} = A^{\\mathsf{c}} \\cup B^{\\mathsf{c}}\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Absorption]\r\n\tFor any sets \\(A\\) and \\(B\\) the following hold: \\[A \\cup (A \\cap B) = A\\] \\[A \\cap (A \\cup B) = A\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Absolute Compliment]\r\n\tFor a given universe \\(U\\) the following hold: \\[\\emptyset^{\\mathsf{c}} = U\\] \\[U^{\\mathsf{c}} = \\emptyset\\]\r\n\\end{thm}\r\n\r\n\\begin{thm}[Set Subtraction Equality]\r\n\t\\label{set-sub-eq}\r\n\tFor any sets \\(A\\) and \\(B\\) the set subtraction operation satisfies the following: \\[A - B = A \\cap B^{\\mathsf{c}}\\]\r\n\tThis establishes a relationship between the relative and absolute compliment\r\n\\end{thm}\r\n\r\nThe aforementioned theorems are helpful for simplifying complicated sets.\r\n\r\n\\exsol{\r\n\tSimplify the following expression: \\[((A \\cup B) \\cap C) \\cup ((A^{\\mathsf{c}} \\cap B^{\\mathsf{c}}) \\cup D^{\\mathsf{c}})^{\\mathsf{c}}\\]\r\n}{\r\n\tLots of compliments is a good indication for using De Morgan's.\r\n\t\\begin{align*}\r\n\t& ((A \\cup B) \\cap C) \\cup ((A^{\\mathsf{c}} \\cap B^{\\mathsf{c}}) \\cup D^{\\mathsf{c}})^{\\mathsf{c}} \\\\\r\n\t&= ((A \\cup B) \\cap C) \\cup ((A \\cup B)^{\\mathsf{c}} \\cup D^{\\mathsf{c}})^{\\mathsf{c}} & \\text{De Morgan's} \\\\\r\n\t&= ((A \\cup B) \\cap C) \\cup ((A \\cup B) \\cap D) & \\text{De Morgan's} \\\\\r\n\t&= (A \\cup B) \\cap (C \\cup D) & \\text{Distributivity}\r\n\t\\end{align*}\r\n}\r\n\r\n\\exsol{\r\n\t\\label{ex-prove-equivalence}\r\nShow the following equivalence: \\[A \\cup (B \\cup (A \\cap C)) = A \\cup B\\]\r\n}{\r\n\tSometimes just trying random things works out in your favor.\r\n\t\\begin{align*}\r\n\tA \\cup (B \\cup (A \\cap C)) &= A \\cup ((A \\cap C) \\cup B) & \\text{Commutativity} \\\\\r\n\t&= (A \\cup (A \\cap C)) \\cup B & \\text{Associativity} \\\\\r\n\t&= A \\cup B & \\text{Absorption}\r\n\t\\end{align*}\r\n}\r\n\r\n\\begin{rem}\r\n\tThere is a stark similarity between set and Boolean simplification.\r\n\\end{rem}\r\n\r\n\\section{Important Sets}\r\n\r\nWe introduce some notation for a handful of important sets.\r\n\r\n\\begin{defn}[The Natural Numbers -- \\(\\N\\)]\r\n\tThe standard discrete numbers with which you count. Some math classes start the naturals at 1, however in computer science we start the naturals at 0. Just remember simply that arrays utilize 0-indexing, so we do the same. The set looks like so: \\(\\{0,1,2,3,4,5,\\cdots\\}\\)\r\n\\end{defn}\r\n\r\nIn mathematics, we define the natural numbers \\textit{inductively} -- we will discuss induction in a few chapters. We introduce the inductive definition here. You do not need to know this, however we think it is interesting.\r\n\r\n\\begin{prop}[Inductive Definition of \\(\\N\\)]\r\n\t\\label{ind-defn-N}\r\n\tDefine a set \\(S \\subseteq \\R\\) to be \\textit{inductive} if and only if the following conditions hold:\r\n\t\\begin{itemize}\r\n\t\t\\item \\(0 \\in S\\)\r\n\t\t\\item if \\(x \\in S\\) then \\(x + 1 \\in S\\)\r\n\t\\end{itemize}\r\n\t\r\n\t\\noindent Define \\(\\N\\) as the intersection of all inductive sets.\r\n\\end{prop}\r\n\r\nUnderstandably you may be confused on the notation of \\(\\R\\) -- we will come back to this in a moment. For now, we continue to the integers.\r\n\r\n\\begin{defn}[The Integers -- \\(\\Z\\)]\r\n\tThe standard \\textit{signed} discrete numbers with which you count. The integers include all of the natural numbers as well as all of their negatives\\footnote{0 is neither positive nor negative, so we cannot take its negation, however we let \\(0 \\in \\Z\\)}. The set looks like so: \\(\\{\\cdots,-3,-2,-1,0,1,2,3,\\cdots\\}\\)\r\n\\end{defn}\r\n\r\nThe next set, which you may be familiar with, is the rationals.\r\n\r\n\\begin{defn}[The Rationals -- \\(\\Q\\)]\r\n\tThe set of numbers that can be written as a ratio (\\(\\Q\\)uotient) of integers. \\(\\Q = \\{x = \\frac{a}{b} \\mid a \\in \\Z \\land b \\in \\Z^{\\neq 0}\\}\\)\r\n\\end{defn}\r\n\r\nNaturally we can define somewhat of an `opposite' to the rationals.\r\n\r\n\\begin{defn}[The Irrationals -- \\(\\R \\setminus \\Q\\)]\r\n\tThe set of real numbers that do not satisfy the rational property. A provable example is that \\(\\sqrt{2} \\in \\R \\setminus \\Q\\)\r\n\\end{defn}\r\n\r\nThe real numbers are not the main focus in discrete mathematics, however we still provide a definition.\r\n\r\n\\begin{defn}[The Reals -- \\(\\R\\)]\r\n\tThe continuous interval \\((-\\infty, \\infty)\\). Any number that does not have the form \\(a+bi\\), where \\(i = \\sqrt{-1}\\)\r\n\\end{defn}\r\n\r\nIn an analytical mathematics course, the reals and irrationals are more strongly defined. The above definitions are enough for this course.\r\n\r\n\\section{Sets to Logic}\r\n\r\nWe can use set-builder notation along with our familiar logic rules to prove things about sets. This proof technique can be used to prove the theorems we showed earlier.\r\n\r\n\\exproof{\r\n\tProve theorem \\ref{set-sub-eq}: \\[A - B = A \\cap B^{\\mathsf{c}}\\]\r\n}{\r\n\t\\begin{align*}\r\n\tA - B &= \\{x \\mid x \\in A \\land x \\not\\in B\\}  & \\text{defn of subtraction} \\\\\r\n\t&= \\{x \\mid x \\in A \\land x \\in B^{\\mathsf{c}}\\} & \\text{defn of compliment} \\\\\r\n\t&= A \\cap B^{\\mathsf{c}} & \\text{defn of intersection}\r\n\t\\end{align*}\r\n}\r\n\r\n\\exproof{\r\n\tProve example \\ref{ex-prove-equivalence} \\[A \\cup (B \\cup (A \\cap C)) = A \\cup B\\]\r\n}{\r\n\t\\begin{align*}\r\n\t& A \\cup (B \\cup (A \\cap C)) \\\\\r\n\t&= \\{x \\mid x \\in A \\lor (x \\in B \\lor (x \\in A \\land x \\in C))\\} & \\text{defn of } \\cup/\\cap \\\\\r\n\t&= \\{x \\mid x \\in A \\lor ((x \\in A \\land x \\in C) \\lor x \\in B)\\} & \\text{Commutativity (logic)} \\\\\r\n\t&= \\{x \\mid (x \\in A \\lor (x \\in A \\land x \\in C)) \\lor x \\in B\\} & \\text{Associativity (logic)} \\\\\r\n\t&= \\{x \\mid x \\in A \\lor x \\in B\\} & \\text{Absorption (logic)} \\\\\r\n\t&= A \\cup B & \\text{defn of } \\cup\r\n\t\\end{align*}\r\n}\r\n\r\n\\section{Summary}\r\n\r\n\\begin{itemize}\r\n\t\\item Sets are unordered collections of unique objects\r\n\t\\item Many operations and theorems exist in set theory\r\n\t\\item \\(\\N, \\Z, \\Q, \\R \\setminus \\Q, \\R\\) are all important sets\r\n\\end{itemize}\r\n\r\n\\section{Practice}\r\n\r\n\\begin{enumerate}\r\n\t\\item Provide an example of a valid set, and an invalid set.\r\n\t\\item Build a set of natural numbers that are all multiples of 3.\r\n\t\\item Explain why the cardinality of a finite set is a natural number.\r\n\t\\item For two sets \\(A\\) and \\(B\\), is it necessarily the case that \\(|A \\cup B| = |A| + |B|\\)?\r\n\t\\item Explain intuitively why \\(|\\mathcal{P}(A)| = 2^{|A|}\\).\r\n\t\\item Is \\(\\{\\Z^-, 0, \\Z^+\\}\\) a valid partition of \\(\\Z\\)? Explain. If it is not, change the partition to make it valid.\r\n\t\\item Is \\(\\{\\{1,3,5,7,9,\\cdots\\} , \\{0,2,4,6,8,\\cdots\\}\\}\\) a valid partition of \\(\\N\\)? Explain. If it is not, change the partition to make it valid.\r\n\t\\item Provide a set \\(T\\) which is a valid partition of \\(\\N\\) such that \\(|T| = 5\\).\r\n\t\\item For each of the following, answer true or false:\r\n\t\\begin{enumerate}\r\n\t\t\\item \\(\\Z \\supset \\N\\)\r\n\t\t\\item \\(\\N \\in \\Z\\)\r\n\t\t\\item \\(0 \\in \\emptyset\\)\r\n\t\t\\item \\(\\emptyset \\in \\emptyset\\)\r\n\t\t\\item \\(\\emptyset \\subseteq \\emptyset\\)\r\n\t\t\\item \\(\\emptyset \\subset \\emptyset\\)\r\n\t\t\\item \\(\\mathcal{P}(\\emptyset) = \\emptyset\\)\r\n\t\\end{enumerate}\r\n\t\\item Simplify the expression \\(A^{\\mathsf{c}} \\cup (B \\cup A)^{\\mathsf{c}}\\).\r\n\t\\item Prove the two Absorption theorem statements are equivalent.\r\n\\end{enumerate}\r\n\r\n%\\section{Solutions}\r\n%\r\n%\\begin{enumerate}\r\n%\t\\item Valid: \\(\\{1,2,3\\}\\). Invalid: \\(1,2,3\\) (this is invalid because it is missing the \\(\\{\\}\\))\r\n%\t\\item Let \\(S = \\{x \\mid (\\exists k \\in \\N)[x = 3k]\\}\\)\r\n%\t\\item Consider that \\(\\N\\) contains all of the \\textit{counting} numbers. By taking the cardinality, you are simply \\textit{counting} the number of elements.\r\n%\t\\item The only case when \\(|A \\cup B| = |A| + |B|\\) is if \\(A \\cap B = \\emptyset\\). For example, \\(|\\{1,2,3\\} \\cup \\{3,4,5\\}| = |\\{1,2,3,4,5\\}| = 5 \\neq 6 = |\\{1,2,3\\}| + |\\{3,4,5\\}|\\)\r\n%\t\\item Consider each subset as a binary string, where each position in the string represents an element. 1 means the element is in the subset, and 0 means the element is not in the subset. The amount of strings total is \\(2^{\\text{length of each string}}\\). Since the length of each string is just the number of elements in \\(A\\), we recover that \\(|\\mathcal{P}(A)| = 2^{|A|}\\). The intuition here is to think of each element as being in or out of a subset.\r\n%\t\\item No -- each element in a partition must be a set, and 0 is not a set.\r\n%\t\\item Yes -- the first set contains all odd naturals, and the second set contains all even naturals. Since there is no overlap between odds and evens, the partition is valid. We will learn about this soon.\r\n%\t\\item One possibility: \\(T = \\{\\{0,1,2\\}, \\{4,5\\}, \\{3,6,9\\}, \\{7,8\\}, \\N^{\\geq 10}\\}\\)\r\n%\t\\item \r\n%\t\\begin{enumerate}\r\n%\t\t\\item True\r\n%\t\t\\item False\r\n%\t\t\\item False\r\n%\t\t\\item False\r\n%\t\t\\item True\r\n%\t\t\\item False\r\n%\t\t\\item False\r\n%\t\\end{enumerate}\r\n%\t\\item \r\n%\t\\begin{align*}\r\n%\tA^{\\mathsf{c}} \\cup (B \\cup A)^{\\mathsf{c}} &= A^{\\mathsf{c}} \\cup (B^{\\mathsf{c}} \\cap A^{\\mathsf{c}}) & \\text{De Morgan's} \\\\\r\n%\t&= A^{\\mathsf{c}} \\cup (A^{\\mathsf{c}} \\cap B^{\\mathsf{c}}) & \\text{Commutativity} \\\\\r\n%\t&= A^{\\mathsf{c}} & \\text{Absorption} \\\\\r\n%\t\\end{align*}\r\n%\t\\item \r\n%\t\\begin{align*}\r\n%\tA \\cup (A \\cap B) &= (A \\cup A) \\cap (A \\cup B) & \\text{Distributivity} \\\\\r\n%\t&= A \\cap (A \\cup B) & \\text{Idempotence}\r\n%\t\\end{align*}\r\n%\\end{enumerate}\r\n\\end{document}\r\n", "meta": {"hexsha": "21ba81a8f759838318d24122dcdaa32a8aecbd9a", "size": 21257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch-settheory.tex", "max_stars_repo_name": "jugoodma/250-textbook", "max_stars_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T14:39:11.000Z", "max_issues_repo_path": "ch-settheory.tex", "max_issues_repo_name": "jugoodma/250-textbook", "max_issues_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "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": "ch-settheory.tex", "max_forks_repo_name": "jugoodma/250-textbook", "max_forks_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-19T22:24:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-19T22:24:49.000Z", "avg_line_length": 54.5051282051, "max_line_length": 459, "alphanum_fraction": 0.648727478, "num_tokens": 7042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.634582123996719}}
{"text": "%!TEX root = ../notes.tex\n\\section{May 2, 2022}\n\\subsection{LLL Reduction}\n\\ul{Problem}: Given a lattice, find a good basis for the given lattice. Let's say we have\n\\begin{align*}\n    \\mathcal{B}  & = (\\bvec{v}_1, \\bvec{v}_2, \\dots, \\bvec{v}_n)    \\\\\n    \\mathcal{B}' & = (\\bvec{v}_1', \\bvec{v}_2', \\dots, \\bvec{v}_n')\n\\end{align*}\nwhere $\\mathcal{B}'$ is the corresponding vector space obtained from Gram-Schmidt. Note that this is \\emph{not} a basis of the lattice.\n\nWe have\n\\[\\bvec{v}_i' = \\bvec{v}_i - \\sum_{j < i}\\mu_{ij}\\bvec{v}_j'\\]\nwhere $\\mu_{ij} = \\frac{\\bvec{v}_i\\cdot \\bvec{v}_j'}{\\bvec{v}_i'\\cdot\\bvec{v}_i'}$.\n\nWhat do we know about $\\det\\{\\bvec{v}_i\\}$ and $\\det\\{\\bvec{v}_i'\\}$? We note that $\\det\\{\\bvec{v}_i\\} = \\det\\{\\bvec{v}_i'\\}$. This is as our row/column operations (except scaling) don't change determinant.\n\n\\ul{Ideas}:\n\nWe want some $\\bvec{v}_1, \\bvec{v}_2, \\dots, \\bvec{v}_n$ are approximately orthogonal.\n\nWe want $\\bvec{v}_1 \\leq \\bvec{v}_2 \\leq \\dots \\leq \\bvec{v}_n$ (approximately sorted).\n\n\\begin{definition}[LLL Reduction]\n    $\\mathcal{B}$ is LLL reduced if\n    \\begin{enumerate}\n        \\item \\emph{We want a measure of orthogonality, so we bound $\\mu_{ij}$ from Gram-Schmidt to a certain value. }\n\n              We have that\n              \\[\\boxed{|\\mu_{ij}| = \\left\\lvert\\frac{\\bvec{v}_i\\cdot \\bvec{v}_j'}{\\bvec{v}_i'\\cdot\\bvec{v}_i'}\\right\\rvert\\leq \\frac{1}{2}}\\]\n        \\item \\emph{We want our measure in a way that failure of exact orthogonality doesn't contribute.}\n\n              We take the projection of $\\bvec{v}_{i-1}$ onto\n              \\[\\langle\\bvec{v}_1, \\dots, \\bvec{v}_{i-2}\\rangle^\\perp\\]\n              and compare that with the length of the projection of $\\bvec{v}_i$ onto\n              \\[\\langle\\bvec{v}_1, \\dots, \\bvec{v}_{i-1}\\rangle^\\perp\\]\n              We want\n                  {\\small\n                      \\[\\frac{3}{4}\\left|\\left|\\ \\text{Projection of $\\bvec{v}_{i-1}$ onto } \\langle\\bvec{v}_1, \\dots, \\bvec{v}_{i-2}\\rangle^\\perp\\right|\\right|\\leq \\left|\\left|\\ \\text{Projection of $\\bvec{v}_{i}$ onto } \\langle\\bvec{v}_1, \\dots, \\bvec{v}_{i-1}\\rangle^\\perp\\right|\\right|\\]\n                  }\n              \\emph{Noting that $\\frac{3}{4}$ was arbitrarly chosen as a `fudge factor'.}\n\n              So we have\n              \\[\\frac{3}{4}||\\bvec{v}_{i-1}||^2\\leq ||\\bvec{v}_i' + \\mu_{i-1, i}\\cdot\\bvec{v}_{i-1}'||^2 = ||\\bvec{v}_i||^2 + \\mu_{i-1, i}^2\\cdot||\\bvec{v}_{i-1}'||\\]\n              so then\n              \\[\\boxed{||\\bvec{v}_i^2||\\geq\\left( \\frac{3}{4} - \\mu_{i-1, i}^2 \\right)\\cdot ||\\bvec{v}_{i-1}'||^2}\\]\n    \\end{enumerate}\n\\end{definition}\n\nOur goal is that we want an algorithm to find an LLL basis. Additionally, once we do find an LLL basis, we want to know that it will be sufficiently orthogonal.\n\nCode in \\textsf{lll.ipynb}.", "meta": {"hexsha": "97aba3bb29c2110606b8fba55c19a88bd23b6500", "size": 2811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-05-02.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-05-02.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-05-02.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": 55.1176470588, "max_line_length": 290, "alphanum_fraction": 0.5919601565, "num_tokens": 1054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.6345821106466725}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage{fullpage}\n\n\\usepackage{latexsym}         % for some symbols\n\\usepackage{amsmath}          % for maths\n\\usepackage{amssymb}          % for Real number symbol\n\\usepackage{graphicx}\n\\usepackage{algorithm}\n\\usepackage{algorithmic}\n\\usepackage{subfigure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Notation\n\n\\newcommand{\\normal}{\\mathcal{N}}\n\\newcommand{\\thetaall}{\\tilde{\\Theta}}\n\n\\newcommand{\\vect}[2]{\\begin{bmatrix} #1 \\\\ #2 \\end{bmatrix}}\n\\newcommand{\\mat}[4]{\\begin{bmatrix} #1 & #2\\\\ #3& #4 \\end{bmatrix}}\n\n\\newcommand{\\dotprod}[2]{\\langle #1 , #2 \\rangle}\n\\newcommand{\\trace}{\\mathrm{tr}}\n\\newcommand{\\deter}{\\mathrm{det}}\n\n% end notation\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\title{Distance between two 2D Gaussians}\n\\author{Cheng Soon Ong}\n\\date{24 March 2017}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Motivation}\n\nIn astronomy cross identification is the task of finding the same object in the sky in two images.\nThe location of each pixel is known, but the challenge lies in the fact that the two images are\nmeasured in different wavelengths.\nWhen doing radio cross identification we need to compare two distributions, one from the optical\nimage and a second from the radio image.\nWe assume here that each empirical distribution is well approximated by a single two dimensional\nGaussian.\nThe first step to cross identification is then to compute the distance between the two Gaussians.\n\n\\section{General abstract setup}\n\nOne way to measure the difference between two distributions is by using the Kullback-Leibler (KL)\ndivergence. This is asymmetric, and one often looks at the average of the KL divergence in\nboth directions. This section selects the relevant results\nfrom~\\cite{nielsen09clumnd,nielsen11staefd}.\n\nLet $\\normal(\\mu, S)$ denote the $d$ dimensional normal distribution with mean $\\mu$ and covariance\nmatrix $S$. We rewrite this Gaussian in its canonical decomposition in terms of its natural\nparameters. The sufficient statistics are stacked onto a tuple containing a $d$ dimensional vector\nand a $d\\times d$ matrix\n\\[\n  \\tilde{x} = (x, -\\frac{1}{2}xx^\\top)\n\\]\nassociated with the natural parameters\n\\begin{equation}\n  \\label{eq:nat-param}\n  \\thetaall = (\\theta, \\Theta) = \\left(S^{-1}\\mu, \\frac{1}{2} S^{-1}\\right)\n\\end{equation}\nThe KL divergence between two Gaussian distributions\n\\[\nN_p = \\normal(\\mu_p, S_p)\\qquad\\mbox{and}\\qquad N_q = \\normal(\\mu_q, S_q)\n\\]\nis given by the Bregman divergence with generator $F$\n\\begin{align}\n  KL(N_p||N_q) &= D_F(\\thetaall_q || \\thetaall_p)\\\\\n  &= F(\\thetaall_q) - F(\\thetaall_p) - \\dotprod{(\\thetaall_q - \\thetaall_p)}{\\nabla F(\\thetaall_p)}\n  \\label{eq:bregman-div}\n\\end{align}\nThe function $F$ turns out to be the log normaliser specifying the exponential family\n(of the Gaussian)\n\\begin{equation}\n  \\label{eq:log-normaliser}\n  F(\\thetaall) = \\frac{1}{4}\\trace(\\Theta^{-1} \\theta\\theta^\\top)\n    -\\frac{1}{2} \\log \\deter \\Theta + \\frac{d}{2}\\log 2\\pi.\n\\end{equation}\nThe gradient of $F$ is given by\n\\begin{equation}\n  \\label{eq:grad-log-normaliser}\n  \\nabla F(\\thetaall) = \\left(\n  \\frac{1}{2} \\Theta^{-1}\\theta\n  ,\n  -\\frac{1}{2} \\Theta^{-1} - \\frac{1}{4} (\\Theta^{-1}\\theta)(\\Theta^{-1}\\theta)^\\top\n  \\right).\n\\end{equation}\nThe inner product in \\eqref{eq:bregman-div} is the sum of the inner products of the\nvectors and matrices,\n\\[\n  \\dotprod{\\thetaall_p}{\\thetaall_q} = \\dotprod{\\theta_p}{\\theta_q} + \\dotprod{\\Theta_p}{\\Theta_q}\n\\]\nwhere the matrix inner product is $\\dotprod{\\Theta_p}{\\Theta_q} = \\trace(\\Theta_p\\Theta_q^\\top)$.\n\n\\section{Two dimensional Gaussian}\n\nWe explicitly show each element of the vector and matrix for a 2 dimensional Gaussian\nmean $\\mu$ and variance $S$,\n\\[\n  \\normal\\left( \\vect{\\mu_1}{\\mu_2}, \\mat{s_{11}}{s_{12}}{s_{21}}{s_{22}}\\right).\n\\]\nThe determinant and inverse of $S$ is given by\n\\begin{equation}\n  \\label{eq:det-S}\n  a := \\deter S = |s_{11} s_{22} - s_{21} s_{22}|\n\\end{equation}\nand\n\\begin{equation}\n  \\label{eq:inv-S}\n  S^{-1} = \\frac{1}{a}\\mat{s_{22}}{-s_{12}}{-s_{21}}{s_{11}}\n\\end{equation}\nrespectively.\nWe can then explicitly compute the parameters for the KL divergence in the previous section.\nStarting from the right most term in \\eqref{eq:bregman-div},\nsince $d=2$ the constant is $\\log 2\\pi$.\nRecall the relationship between determinants and inverses:\n\\[\n  \\deter S^{-1} = \\frac{1}{\\deter S}\n\\]\nBecause we are only considering a two dimensional problem, constants are squared in the determinant,\ni.e. $\\deter(c S) = c^2 \\deter S$.\nBy the definition of $\\Theta$, we have\n\\begin{align*}\n  \\frac{1}{2} \\log \\deter \\Theta &= \\frac{1}{2} \\log \\deter (\\frac{1}{2} S^{-1}) \\\\\n  &= \\frac{1}{2} \\log \\frac{1}{4} \\frac{1}{\\deter S}\\\\\n  &= \\frac{1}{2} \\log \\frac{1}{4a}\n\\end{align*}\nwhere the last line substitutes \\eqref{eq:det-S}.\nBy the definition of $\\theta$,\n\\begin{equation}\n  \\label{eq:theta}\n  \\theta = S^{-1}m = \\frac{1}{a}\\vect{s_{22}\\mu_1 - s_{12}\\mu_2}{s_{11}\\mu_2 - s_{21}\\mu_1}.\n\\end{equation}\n\nWe also require\n\\begin{align}\n  \\Theta^{-1}\\theta &= 2SS^{-1}m = 2m\\nonumber\\\\\n  &=\\vect{2\\mu_1}{2\\mu_2}\\label{eq:2mean},\n\\end{align}\nwhich allows us to compute terms in the gradient. By multiplying\n\\eqref{eq:2mean} and \\eqref{eq:theta} we have\n\\begin{align*}\n  \\Theta^{-1}\\theta\\theta^\\top &= \\frac{1}{a}\\vect{2\\mu_1}{2\\mu_2}\n  \\vect{s_{22}\\mu_1 - s_{12}\\mu_2}{s_{11}\\mu_2 - s_{21}\\mu_1}^\\top\\\\\n  &=\\frac{2}{a}\\mat{\\mu_1(s_{22}\\mu_1 - s_{12}\\mu_2)}{\\mu_1(s_{11}\\mu_2 - s_{21}\\mu_1)}{\\mu_2(s_{22}\\mu_1 - s_{12}\\mu_2)}{\\mu_2(s_{11}\\mu_2 - s_{21}\\mu_1)},\n\\end{align*}\nallowing us to calculate the first term of the log normaliser\n\\[\n  \\frac{1}{4}\\trace(\\Theta^{-1} \\theta\\theta^\\top)= \\frac{1}{2a}\n  \\left(\\mu_1(s_{22}\\mu_1 - s_{12}\\mu_2) + \\mu_2(s_{11}\\mu_2 - s_{21}\\mu_1)\\right).\n\\]\nSubstituting into \\eqref{eq:log-normaliser}, we have\n\\begin{equation}\n  \\label{eq:gauss-log-normaliser}\n  F(\\thetaall) = \\frac{1}{2a}\n  \\left(\\mu_1(s_{22}\\mu_1 - s_{12}\\mu_2) + \\mu_2(s_{11}\\mu_2 - s_{21}\\mu_1)\\right)\n  - \\frac{1}{2} \\log \\frac{1}{4a} + \\log 2\\pi.\n\\end{equation}\nSubstituting into \\eqref{eq:grad-log-normaliser}, we have\n\\begin{equation}\n  \\label{eq:gauss-grad-log-normaliser-vec}\n  \\frac{1}{2}\\Theta^{-1}\\theta = \\mu\n\\end{equation}\nand\n\\begin{equation}\n  \\label{eq:gauss-grad-log-normaliser-mat}\n  -\\frac{1}{2} \\Theta^{-1} - \\frac{1}{4} (\\Theta^{-1}\\theta)(\\Theta^{-1}\\theta)^\\top\n  =\n  - S - \\mu\\mu^\\top.\n\\end{equation}\nIt is likely that \\eqref{eq:gauss-log-normaliser} and \\eqref{eq:gauss-grad-log-normaliser-mat}\nare true in general for all Gaussians (not just 2D Gaussians).\n\n\\bibliographystyle{alpha}\n\\bibliography{gaussian}\n\\end{document}\n", "meta": {"hexsha": "285152a3210792de53203ca73f1ee441b1ee203f", "size": 6598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes/two-gaussians.tex", "max_stars_repo_name": "chengsoonong/crowdastro", "max_stars_repo_head_hexsha": "ce14432c36de0574b73d813304365b74446a61f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2015-11-07T15:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-20T05:29:58.000Z", "max_issues_repo_path": "tex/notes/two-gaussians.tex", "max_issues_repo_name": "chengsoonong/crowdastro", "max_issues_repo_head_hexsha": "ce14432c36de0574b73d813304365b74446a61f8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 234, "max_issues_repo_issues_event_min_datetime": "2016-02-21T23:53:16.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-27T00:26:08.000Z", "max_forks_repo_path": "tex/notes/two-gaussians.tex", "max_forks_repo_name": "chengsoonong/crowdastro", "max_forks_repo_head_hexsha": "ce14432c36de0574b73d813304365b74446a61f8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-11-07T00:20:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-03T13:37:15.000Z", "avg_line_length": 36.2527472527, "max_line_length": 156, "alphanum_fraction": 0.6841467111, "num_tokens": 2295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6345642203170545}}
{"text": "\\chapter{Geometric Parameters}\n\n\\section{Wing Basic Geometric Parameters}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=120mm]{eps/wing_geometric_parameters.eps}\n  \\caption{Wing basic geometric parameters}\n\\end{figure}\n\nAspect ratio is given by the following formula: \\cite{Raymer1992}\n\\begin{equation}\n  A = \\frac{b^2}{S}\n\\end{equation}\n\nTaper ratio is given by the following formula. \\cite{Raymer1992}\n\\begin{equation}\n  \\lambda = \\frac{c_t}{c_r}\n\\end{equation}\n\n\\section{Mean Aerodynamic Chord}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=120mm]{eps/wing_mean_aerodynamic_chord.eps}\n  \\caption{Mean aerodynamic chord}\n\\end{figure}\n\nFor tapper wing mean aerodynamic chord can be calculated using following formula: \\cite{Corke2003, Galinski2016}\n\\begin{equation}\n  \\hat c = \\frac{2}{3} c_r \\frac{1+\\lambda+\\lambda^2}{1+\\lambda}\n\\end{equation}\n\nFor more complex shapes mean aerodynamic chord is given as follows: \\cite{Paturski02}\n\\begin{equation}\n  \\hat c = \n  \\left(\n    \\int_{-\\frac{b}{2}}^{\\frac{b}{2}} \\left( c \\left( y \\right) \\right)^2 dy\n  \\right)\n  \\div\n  \\left(\n    \\int_{-\\frac{b}{2}}^{\\frac{b}{2}} \\left( c \\left( y \\right) \\right) dy\n  \\right)\n\\end{equation}\n\n\\section{Wing Aerodynamic Center}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=120mm]{eps/wing_aerodynamic_center.eps}\n  \\caption{Wing aerodynamic center}\n\\end{figure}\n\nPosition of wing aerodynamic center ${\\vec r}_{AC}$ is at 25\\% of the mean aerodynamic chord and its lateral coordinate is given by the following formula. \\cite{Raymer1992, Corke2003, Galinski2016, Torenbeek1982}\n\\begin{equation}\n  y_{AC} =\n  \\frac{ b \\left( 1 + 2 \\lambda \\right) }{ 6 \\left( 1 + \\lambda \\right) }\n\\end{equation}\n", "meta": {"hexsha": "74b26eea01e37254f2df0fa8a655b75335fbd264", "size": 1700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/data_1.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_1.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_1.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": 28.813559322, "max_line_length": 212, "alphanum_fraction": 0.7205882353, "num_tokens": 563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6345642158441807}}
{"text": "\\chapter{Workbook Assignment 1: Basic Probabilities and Visualisations}\n\n\\section{Bernoulli Distribution}\n\nAssumed a binary vote with outcome for or against is described by a Bernoulli distribution, with $P(vote = \"for\") = 0.69$. \nInterpreting this as a one-trial Bernoulli experiment with the two outcomes for and against - represented by success and no success respectively - we can visualize it as displayed in figure~\\eqref{fig:1a}.\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=16cm]{pics/1a.pdf}\n\\caption{Bernoulli distribution of one trial}\n\\label{fig:1a}\n\\end{figure}\n\\FloatBarrier\n\n\nAs this is a one-trial Bernoulli experiment, we can only observe the two outcomes $success = for$ and $no~success = against$. With provided information that $P(vote = \"for\") = 0.69$, we can calculate that $P(vote=”against”) = 1 - P(vote = \"for\") = 0.31$. This is visualized by the two bars in figure~\\eqref{fig:1a}. Following Hogg et al. \\cite[Chapter~3.1]{hogg}, the expected value of X, described by a Bernoulli Distribution, is: \n\\begin{equation}  \\mu = E(X) = (0)(1-p) + (1)(p) = p\n\\label{eq:expvaluebernoulli}\n\\end{equation}\nApplied to our problem,  $ \\mu = p = P(vote = \"for\") = 0.69 $.\nThis means if we would repeat the experiment one hundred times, we expect to observe 69 successes. \nThis result was achieved using Python 3.9 and the following code:\n\\begin{minted}{python}\nfrom scipy.stats import bernoulli\nimport numpy as np\nimport pandas as pd\nimport plotly.express as px\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\n#Dataset creation. Done manually as only one trial\np_for = 0.69\np_against = 0.31 #p_against = 1-p_for\ndf = pd.DataFrame([[1,p_for],[0,p_against]])\n\n#Visualisation\ntrace1 = go.Bar(x = df[0],y = df[1],width = 0.1,text = df[1], \n    textposition = 'auto')\nfig = make_subplots(x_title = 'Number of Successes',y_title = 'P(X = x)')\nfig.add_trace(trace1)\nfig.show()\nfig.write_image(\"figures/1a.pdf\")\n\\end{minted}\n\n\\section{Poisson Distribution}\n\nAssumed we try to model the number of meteorites falling on an ocean each year - why would a Poisson Distribution be a natural candidate?\n\n\nThe Poisson distribution is a discrete probability distribution representing the number of events occurring in a defined period. It assumes the events occur with a known constant mean rate and that the events are independent of the time since the last event \\cite[Chapter~4.6]{illowsky2018introductory}.\n\nThe event of a meteor impacting the world in a given year fulfills all requirements for such distribution. The event itself is of discrete nature as one cannot have a fractional count of impacts, and we assume meteorite impacts occur with a known constant mean rate and the impacts themselves are independent of the time since the last event. We do not know, whether the variance of the distribution is equal to the mean, but even if it was, we could relax this assumption by using the Poisson-based Gamma-Poisson distribution. For this exercise, we assume $\\sigma^2 = \\mu$. Additionally assuming $\\mu = 64$ allows an exemplary visualisation as in figure \\eqref{fig:1b}.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=16cm]{pics/1b.pdf}\n\\caption{Poisson distribution of annual meteorite impacts with $\\mu = 64$}\n\\label{fig:1b}\n\\end{figure}\n\\FloatBarrier\n\nTo ensure readability of the graphic, probabilities $<0.5$ percent are excluded. Additionally, the variance ($s^2 = 64.36$) is visualised as its root, the sample standard deviation $s$ ($s = 8.02$). Looking at mean ($\\bar{x} = 64.01$) and median ($m = 64$), one can barely see a difference, which is to be expected as the distribution displayed is not skewed. \n\nThe calculations for this exercise were done in python 3.9 using Jupyter notebooks with the following code: \n\n\\begin{minted}{python}\nfrom scipy.stats import poisson\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\n#creating a sample with fixed random state\nsize = 100000\nraw = pd.Series(data = poisson.rvs(64, size=size, random_state = 42))\n\n# calculating median, mean, variance, stdev\nmedian = raw.median()\nvar = raw.var()  # sample assumed\nmean = raw.mean()\nstdev = np.sqrt(var)\nstdev_range = pd.DataFrame([[raw.mean() - stdev, 0.025],\n                            [raw.mean() + stdev, 0.025]])\n\n# Filter to only display probabilities >=0.5%\ndf = pd.DataFrame(raw.value_counts())\ndf[0] = df[0].div(size)\ndf = df[df[0] >= 0.005]\n\n# Display measures\nprint(var)\nprint(stdev)\nprint(mean)\nprint(median)\n\n#creating graphic\ntrace1 = go.Bar(x = df.index, y = df[0],showlegend = False)\ntrace2 = go.Bar(x = [median], y = [0.055],width = [0.1], name = 'Median', \ntext = [median], textposition = 'outside')\ntrace3 = go.Line(x = stdev_range[0], y = stdev_range[1], \nname = 'Standard Deviation', text = ['-1 s', '+1 s'],\nmode =\"lines+markers+text\",textposition = \"bottom center\")\ntrace4 = go.Bar(x = [mean], y = [0.025],width = [0.15], name = 'Mean', \ntext = [mean], textposition = 'outside')\n\nfig = make_subplots(x_title = 'Annual Meteorite Impacts',\ny_title = 'P(X = x)')\nfig.add_trace(trace1)\nfig.add_trace(trace2)\nfig.add_trace(trace4)\nfig.add_trace(trace3)\nfig['layout'].update(barmode = 'overlay')\nfig.show()\n\nfig.write_image(\"figures/1b.pdf\")\n\\end{minted}\n\n\\section{Exponential Distributions}\nAssumed the probability that you need to wait more than the random variable of y hours to hear an owl from your room is described by:\n\\begin{equation}  f(Y > y) = 0.2\\overline{8}\\mathrm{e}^{-0.5y} + 0.7\\overline{1}\\mathrm{e}^{-0.25y}.\n\\label{eq:initcdf}\n\\end{equation}\nTo facilitate calculations, we reformulate the periodic numbers to fractions:\n\\begin{equation}  f(Y > y) = \\dfrac{13}{45}\\mathrm{e}^{-0.5y} + \\dfrac{32}{45}\\mathrm{e}^{-0.25y}.\n\\label{eq:initcdffractioned}\n\\end{equation}\nSuspecting that such events are usually exponentially distributed, we reformulate the probability in equation \\eqref{eq:truecdf} to the conventional expression \\cite{deisenroth}. \n\\begin{equation}  F_Y(y) = f(Y \\leq y) =1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y} + \\dfrac{32}{45}\\mathrm{e}^{-0.25y} \\right)\n\\label{eq:truecdf}\n\\end{equation}\nAs $Y$ and $y$ are defined as time and time cannot be negative in this case, the domain of the function we are interested in is $[0,+\\infty]$.\n\\begin{equation} f'_Y(y) = f''(Y \\leq y) = \n\\dfrac{-8\\mathrm{e}^{-\\frac{y}{4}}-13\\mathrm{e}^{-\\frac{y}{2}}}{180}\n\\label{eq:secderivative}\n\\end{equation}\n\nAs \\eqref{eq:secderivative}, the second derivative of formula \\eqref{eq:truecdf},  additionally has no real-valued solution for $y=0$, we can describe $F_Y(y)$ of \\eqref{eq:truecdf} as being upwards continuous monotonic increasing. Furthermore, $\\lim_{y\\to\\infty} F_Y(y)= 1$ and $F_Y(0)= 0$ for the support of $y$. This is sufficient evidence to assume that the provided distribution of the random variable $y$ is a cumulative distribution function (CDF) of the family of exponential distributions. \n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=16cm]{pics/1c1.pdf}\n\\caption{Visualisation of provided and reformulated CDF of task assignment}\n\\label{fig:1c1}\n\\end{figure}\n\\FloatBarrier\n\n\nFor any calculation regarding the probability to hear an owl within a time interval, we use the CDF. If we for example wanted to know $P(2 \\leq Y \\leq 4)$, the probability of needing to wait two to four hours to hear an owl, we would calculate it as described in equation \\eqref{eq:prob24}.\n\n\\begin{equation} P(2 \\leq Y \\leq 4) = P(Y \\leq 4) - P(Y \\leq 2)\n\\label{eq:prob24}\n\\end{equation}\nApplied to our distribution, we calculate\n\\begin{equation} P (2 \\leq Y \\leq 4) =1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-2} + \\dfrac{32}{45}\\mathrm{e}^{-1}\\right) -\\left[ 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-1} + \\dfrac{32}{45}\\mathrm{e}^{-0.5}\\right)\\right] \t\\approx 0.23688696\n\\label{eq:probcalc24}\n\\end{equation}\nConsequently, we can say that in 23.69 percent of cases, we have to wait in between two and four hours to hear an owl.\n\\\\\n\nNext to the CDF, we are also often interested in the corresponding probability density function (PDF). Generally, the PDF $f_Y(y)$ of a CDF $F_Y(y)$ is given by its first derivative \\cite[Chapter~4.3]{montgomery2010applied}:\n\\begin{equation}\nf_Y(y) = \\frac{df(Y \\leq y)}{dy}\n\\label{eq:firstderivative}\n\\end{equation}\nFor our CDF, the PDF is described by:\n\\begin{equation}\nf_Y(y) = \\dfrac{16\\mathrm{e}^{-\\frac{y}{4}}+13\\mathrm{e}^{-\\frac{y}{2}}}{90}\n\\label{eq:pdf}\n\\end{equation}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=17cm]{pics/1c2.pdf}\n\\caption{Visualisation of $f_Y(y)$ (PDF), the first two moments, and applicable quartiles}\n\\label{fig:1c2}\n\\end{figure}\n\\FloatBarrier\n\nThe graphical representation of the PDF in figure \\eqref{fig:1c2} also includes the mean value. This is calculated using equation \\eqref{eq:ExpValueHogg}, following the definition of an expectation for a random variable in Hogg et al. \\cite[Definition~1.8.1]{hogg}.\n\\begin{equation}\nE(X) = \\int^{+\\infty}_{-\\infty} x f_X(x) ~ dx\n\\label{eq:ExpValueHogg}\n\\end{equation}\nConditions for this to be true are that equation \\eqref{eq:ExpValueHoggcondition} is fulfilled and that $X$ is a continuous random variable with $f_X(x)$ as its PDF.\n\\begin{equation}\n\\int^{+\\infty}_{-\\infty} |x| f_X(x) ~ dx < \\infty\n\\label{eq:ExpValueHoggcondition}\n\\end{equation}\nBy the task assignment, we know that $Y$ is a continuous random variable. By equation \\eqref{eq:pdf}, we calculated $f_Y(y)$ as the PDF of $y$. Lastly, as $y \\in [0,\\infty)$, the left hand side of inequality \\eqref{eq:ExpValueHoggcondition} reduces to the right hand side of equation \\eqref{eq:ExpValueHogg} and the lower limit of the integral changes to 0. Consequently, if the mean or expected value $E(Y) < \\infty$, it is valid. The calculation for our random variable $y$ in \\eqref{eq:ExpValueCalculation} returns $E(Y) < \\infty$, we can therefore accept $3.4\\overline{2}$ hours as our expected value $E(Y)$ for the waiting time to hear an owl. \n%\n\\begin{equation}\nE(Y) = \\int^{+\\infty}_{0} y f_Y(y) ~ dy = \\int^{+\\infty}_{0} y\\left(\\dfrac{16\\mathrm{e}^{-\\frac{y}{4}}+13\\mathrm{e}^{-\\frac{y}{2}}}{90} \\right) ~dy = \\frac{154}{45} = 3.4\\overline{2}\n\\label{eq:ExpValueCalculation}\n\\end{equation}\nFollowing Hogg et al., the first moment or mean $\\mu = E(X)$, if $X$ is a random variable with existing expectation \\cite[Definition~1.9.1]{hogg}. This is the case for $Y$. Consequently, we can also assume that the mean value $\\mu = E(X) = 3.4\\overline{2}$. \n\\\\\nTo calculate the second moment, the variance $\\sigma^2$, we use definition 1.9.2 by Hogg et al. \\cite{hogg} as equation \\eqref{eq:HoggVariance}.\n\\begin{equation}\n\\sigma^2 = E(X^2) - \\mu^2\n\\label{eq:HoggVariance}\n\\end{equation}\n%\nThe variance of $y$ is calculated by \\eqref{eq:YVariance}, using the same assumptions as for equation \\eqref{eq:ExpValueCalculation}.\n\\begin{equation}\n\\sigma^2 = \\int^{+\\infty}_{0} y^2 f(y) ~ dy - \\mu^2\n= \\int^{+\\infty}_{0} \\dfrac{y^2\\left(16\\mathrm{e}^{-\\frac{y}{4}}+13\\mathrm{e}^{-\\frac{y}{2}}\\right)}{90} - \\left(\\frac{154}{45}\\right)^2\n= \\frac{27044}{2025} \\approx 13.3551\n\\label{eq:YVariance}\n\\end{equation}\n\nThe variance is also depicted in figure \\eqref{fig:1c2}     as its root, the standard deviation $\\sigma \\approx 3.6545$. \n\nBoth figures \\eqref{fig:1c1} and \\eqref{fig:1c2} furthermore display the first three quartiles of the PDF. Hogg et al. \\cite[Chapter~1.7.1]{hogg} define the second quartile, the median, as the point dividing area under the PDF into two areas of equal size, which again are divided into two areas of equal size by the first and third quartile. As the CDF is the integral of the PDF and consequently by nature describes the area under the curve of the PDF, we can simply use equation \\eqref{eq:truecdf} for the calculation of quartiles. We know that each quartile has to cover a quarter of the area under the curve of PDF \\eqref{eq:pdf}. This means we can substitute 0.25, 0.5 and 0.75 for $(F_Y \\leq y)$ in equation \\eqref{eq:truecdf} and solve for $y$ to get the quartiles. This is exemplarily done in equation \\eqref{eq:firstquartile} for the first quartile.\n\n\\begin{equation}\n\\begin{split}\n0.25 &\n=1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y_1} + \\dfrac{32}{45}\\mathrm{e}^{-0.25y_1} \\right)\\\\\ny_1&=\\ln \\left(\\frac{413529488+7788544\\sqrt{2779}}{332150625}\\right)\\\\\ny_1 &\\approx 0.9087 \n\\end{split}\n\\label{eq:firstquartile}\n\\end{equation}\n\nThe second and third quartile can be calculated in the same way, resulting in $y_2 \\approx 2.2430$ for the second quartile and $y_3 \\approx 4.6588$ for the third quartile. The calculations were done using symbolab \\cite{symbolab} with the following commands:\n\\begin{lstlisting}\nsolve 0.25 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}+\\dfrac{32}{45}\n\\mathrm{e}^{-0.25y} \\right)\n\nsolve 0.5 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}+\\dfrac{32}{45}\n\\mathrm{e}^{-0.25y} \\right)\n\nsolve 0.75 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}+\\dfrac{32}{45}\n\\mathrm{e}^{-0.25y} \\right)\n\\end{lstlisting}\n\nAs $\\lim_{y\\to\\infty} F_Y(y)= 1$, we would only get $\\infty$ as a result if we tried to calculate the fourth quartile $y_4$. The first three quartiles are visualised in figure \\eqref{fig:1c1} as points whereas in figure \\eqref{fig:1c2}, they are displayed as vertical lines to indicate that we want to highlight that the individual quartile $y_i$ has $i\\cdot25$ percent of PDF \\eqref{eq:pdf}'s area under the curve to its left. \n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=17cm]{pics/1c4.pdf}\n\\caption{Histogram of $f_Y(y)$ by minute}\n\\label{fig:1c4}\n\\end{figure}\n\\FloatBarrier\n\nLastly, figure \\eqref{fig:1c4} displays the PDF as a histogram per minute for one observation. If we for example had 1'000 observations, we would have approximately five observations where we hear an owl in the first minute. As the PDF is per hour while the histogram should be per minute, we need to divide every value $f_Y(y_i)$ for our 600 data points by 60. The standard y-axis comprises 10 hours for all graphics, we have 600 columns which might be too many. However, the graphics are created with python and Plotly, which allows for magnification, if desired. It can also be magnified in this document as it is a vector graphic.\nCalculations and visualisations were done in Jupyter notebooks using the following python code:\n\\begin{minted}{python}\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objs as go\nfrom plotly.subplots import make_subplots\nimport plotly\nimport plotly.express as px\n\n# Define initial function as written in task assignment (P(Y>y))\ndef func(y):  # cdf\n    return ((13 / 45) * np.exp(-0.5 * y) + (32 / 45) * np.exp(-0.25 * y))\n\n\n# Reformulate function so that you have a standard exponential function (P(Y<=y)\ndef realfunc(y):  # cdf\n    return 1 - func(y)\n\n\n# Define pdf of realfunc(x)\ndef pdf_realfunc(y):\n    # First derivative of realfunc(x) with respect to x\n    return (16 * np.exp(-y / 4) + 13 * np.exp(-y / 2)) / (90)\n\n\n# create datasets\nfunc_data = []\nrealfunc_data = []\npdf_realfunc_data = []\n\nfor i in np.arange(0, 10, 1 / 60):\n    func_data.append([i, func(i)])\n    realfunc_data.append([i, realfunc(i)])\n    pdf_realfunc_data.append([i, pdf_realfunc(i)])\n\n# create dataframes\nfunc_df = pd.DataFrame(func_data)\nrealfunc_df = pd.DataFrame(realfunc_data)\npdf_realfunc_df = pd.DataFrame(pdf_realfunc_data)\n\n# Calculate mean value\ny_mean = pdf_realfunc(154 / 45)\n\n# Calculate quartiles\n# symbolab.com: \"solve 0.25 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}\n# + \\dfrac{32}{45}\\mathrm{e}^{-0.25y} \\right)\"\nq1 = np.log(413529488 / 332150625 + 7788544 * np.sqrt(2779) / 332150625)\n\n# symbolab.com: \"solve 0.5 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}\n# + \\dfrac{32}{45}\\mathrm{e}^{-0.25y} \\right)\"\nq2 = np.log(19342148 / 4100625 + 411904 * np.sqrt(2194) / 4100625)\n\n# symbolab.com: \"solve 0.75 = 1-\\left( \\dfrac{13}{45}\\mathrm{e}^{-0.5y}\n# + \\dfrac{32}{45}\\mathrm{e}^{-0.25y} \\right)\"\nq3 = np.log(216370448 / 4100625 + 5392384 * np.sqrt(1609) / 4100625)\n\n# Visualisation of initial function and reformulated function\ncolor = px.colors.qualitative.Plotly\ntrace1 = go.Line(\n    x=func_df[0], \n    y=func_df[1], \n    name='P(Y > y)'\n)\ntrace2 = go.Line(\n    x=realfunc_df[0], \n    y=realfunc_df[1], \n    name='P(Y <= y) (CDF)'\n)\n# Additionally, the PDF of P(Y <= y) can be displayed.\n#trace3 = go.Line(x=pdf_realfunc_df[0],\n#                y=pdf_realfunc_df[1],\n#                name='PDF of P(Y <= y)'\n#)\ntrace9 = go.Scatter(\n    x=[q1],\n    y=[0.25],\n    showlegend=True,\n    name='Quartiles 1-3',\n    marker_color=color[9],\n    hovertext=['1st Quartile'],\n)\ntrace10 = go.Scatter(\n    x=[q2],\n    y=[0.5],\n    showlegend=False,\n    marker_color=color[9],\n    hovertext=['2nd Quartile (Median)'],\n)\ntrace11 = go.Scatter(\n    x=[q3],\n    y=[0.75],\n    showlegend=False,\n    marker_color=color[9],\n    hovertext=['3rd Quartile'],\n)\n# Mean (can also be displayed additionally)\n#trace6 = go.Scatter(x=[154 / 45], y=[y_mean], name='Mean')\n\n# Creating graphic\nfig = make_subplots(x_title=\"y (Hours)\", y_title=\"Probability\")\nfig.add_trace(trace1)\nfig.add_trace(trace2)\n#fig.add_trace(trace3)\n#fig.add_trace(trace6)\nfig.add_trace(trace9)\nfig.add_trace(trace10)\nfig.add_trace(trace11)\nfig.show()\nfig.write_image(\"figures/1c1.pdf\")\n\n# Visualisation of PDF\ncolor = px.colors.qualitative.Plotly\ntrace3 = go.Line(x=pdf_realfunc_df[0],\n                 y=pdf_realfunc_df[1],\n                 name='f_Y(y) (PDF)',\n                 marker_color=color[0])\ntrace6 = go.Scatter(x=[154 / 45],\n                    y=[y_mean],\n                    showlegend=True,\n                    name='Mean',\n                    marker_color=color[2])\ntrace7 = go.Bar(x=[154 / 45],\n                y=[y_mean],\n                showlegend=True,\n                name='Mean',\n                marker_color=color[2],\n                width=0.05)\ntrace8 = go.Line(x=[154 / 45, 154 / 45 + 3.66],\n                 y=[y_mean, y_mean],\n                 name='Standard Deviation',\n                 text=['Mean', '+1 std. dev.'],\n                 mode=\"lines+markers+text\",\n                 textposition=\"top center\",\n                 fillcolor=color[3])\ntrace9 = go.Bar(\n    x=[q1],\n    y=[pdf_realfunc(q1)],\n    showlegend=True,\n    name='Quartiles 1-3',\n    marker_color=color[9],\n    width=0.05,\n    text=['1st Quartile'],\n    textposition='outside',\n)\ntrace10 = go.Bar(\n    x=[q2],\n    y=[pdf_realfunc(q2)],\n    showlegend=False,\n    marker_color=color[9],\n    width=0.05,\n    text=['2nd Quartile (Median)'],\n    textposition='outside',\n)\ntrace11 = go.Bar(\n    x=[q3],\n    y=[pdf_realfunc(q3)],\n    showlegend=False,\n    marker_color=color[9],\n    width=0.05,\n    text=['3rd Quartile'],\n    textposition='outside',\n)\n\nfig = make_subplots(x_title=\"y (Hours)\", y_title=\"P(y)\")\nfig.add_trace(trace3)\nfig.add_trace(trace8)\nfig.add_trace(trace6)\n#fig.add_trace(trace7) #Additionally, this line can be uncommented\n#to get a vertical line for the mean for better visibility. This\n#might however be confusing as the mean is no indicator for area\n#under the curve, contrary to quartiles, which are displayed as\n#columns. Thus, this column was left in as comment, in case some-\n#one wants better visuability\nfig.add_trace(trace9)\nfig.add_trace(trace10)\nfig.add_trace(trace11)\n\nfig.update_layout(bargap=0.0, barmode='overlay')\nfig.update_traces(marker_line_width=0)\n\nfig.show()\nfig.write_image(\"figures/1c2.pdf\")\n\n# Zooming in on the mean, if wanted\n#fig.update_xaxes(range=[3.37, 3.47])\n#fig.update_yaxes(range=[0.099, 0.105])\n#fig.show()\n#fig.write_image(\"figures/1c3.pdf\")\n\n#Creating the Histogram per minute\n\ntrace4 = go.Bar(y=pdf_realfunc_df[1] / 60,\n                name=\"Histogram of f_Y(y)\",\n                marker_color='#3399FF')\n\nfig = make_subplots(x_title=\"y\", y_title=\"P(y)\")\n\nfig.add_trace(trace4)\n\nfig.update_layout(bargap=0.0, barmode='overlay')\nfig.update_traces(marker_line_width=0)\n\nfig.show()\nfig.write_image(\"figures/1c4.pdf\")\n\\end{minted}\n\n\\chapter{Workbook Assignment 2: Basic Probabilities and Visualizations }\t\n\n\\section{Visualisation, Expectations and (Co-)Variances}\nAssumed one has recorded mappings of X and Y values, what is an appropriate way of visualisation? How do you find the sample covariance as well as the expectation values and variances per variable; assuming the data comes in the following format?\\\\\n\\\\\n(1.754, 720.15), (-7.385, -260.86), (1.396, -340.56), (-3.304, 954.75), \n(-12.159, -370.12),\\\\ (-6.767, -259.89), (1.233, 261.89), (-7.056, 400.72), \n(-1.222, -94.33), (-0.722, -492.02),\\\\ (-5.065, -789.42), (-9.333, 301.86), \n(7.27, -17.04), (-1.989, 257.91), (3.582, -229.89), \\\\(-1.2, -349.18), \n(4.118, 226.05), (-1.834, -534.54), (-1.882, 610.91), (8.677, 70.11) \\\\\n\nAs the variables in the data are both continuous and the question addresses the calculation of correlation, the optimal visualisation is a scatter diagram as for example figure~\\eqref{fig:WorkbookAssignment2a}. Other possibilities are excluded as there is not much more information provided on the data set. A line graph for example would be appropriate if we had information that the observations show some development over some time domain. \n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=16cm]{pics/WorkbookAssignment2a.pdf}\n\\caption{Visualisation of provided X and Y values as scatter plot}\n\\label{fig:WorkbookAssignment2a}\n\\end{figure}\n\\FloatBarrier\nLooking at the scatter plot, one can observe that the data is quite evenly dispersed; no pattern can be determined at first glance. This rather evenly distributed data also suggests that the expected value for X and Y is rather close to 0. Calculating the expected value for each variable can be understood at the calculation of the expected value of a discrete random variable as the number of observations is discrete. Equation~\\eqref{eq:ExpValDiscrete} is therefore the formula to calculate the expected value \\cite{mathcenter}. \n\\begin{equation}  \nE(X) = \\sum \\left[x * P(x)\\right]\n\\label{eq:ExpValDiscrete}\n\\end{equation}\nThe results are consequently $E(X) = -1.5944$ and $E(Y) = 3.3250$.\nFollowing Bruce and Bruce \\cite{bruce2017practical}, the variance for a sample is calculated by \n\\begin{equation}  \ns^2 = \\frac{\\sum{(x-\\bar{x})^2}}{n-1}.\n\\label{eq:ExpValDiscrete}\n\\end{equation}\nThis computes to $s^2_x = -1.5944$ and $s^2_y = 3.3250$, where $\\bar{x} = E(X)$ and $\\bar{y} = E(Y)$.\nThe sample covariance is defined in Equation~\\eqref{eq:COV} (adapted from Bruce and Bruce \\cite{bruce2017practical}).\n\\begin{equation}  s_{xy} = \\frac{\\sum(x_{i}-\\bar{x})(y_{i}-\\bar{y})}{n-1}\n\\label{eq:COV}\n\\end{equation}\nApplying the formula to the provided data, $s_{xy} = 284.23$ can be observed. This indicates a positive relationship.\nThe calculations were done using Python 3.9 and the following code:\n\\begin{minted}{python}\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\ndata = (1.754, 720.15), (-7.385, -260.86), (1.396, -340.56), (-3.304, 954.75),\n(-12.159, -370.12), (-6.767, -259.89), (1.233, 261.89), (-7.056, 400.72), \n(-1.222, -94.33), (-0.722, -492.02), (-5.065, -789.42), (-9.333, 301.86),\n(7.27, -17.04), (-1.989, 257.91), (3.582, -229.89), (-1.2, -349.18), \n(4.118, 226.05), (-1.834, -534.54), (-1.882, 610.91), (8.677, 70.11)\ndata = pd.DataFrame(data)\ndata.columns = [\"X\", \"Y\"]\nprint(\"The variance of the variables is: \\n{}\".format(data.var()))\nprint(\"The expectation value for the variables is: \\n{}\".format(data.mean()))\nprint(\"The sample covariance is {}\".format(data.cov().iloc[0,1]))\n\ndata = data.set_index(\"X\")\n\nsns.scatterplot(data = data, x = \"X\", y = \"Y\", color = \"black\").set(\n    title = \"Visualisation of X and Y Values\")\nplt.savefig('./figures/2a.pdf')\n\\end{minted}\n\n\n\\section{Transformations}\nAssumed we have a ball being thrown at a random angle $\\theta$ [0,360) (in degrees) and a random radius $r$ $\\in$ [0,1] (in meters) both independent and uniform. What is the density of the variables $X$ and $Y$, which are the Cartesian coordinates of the point at angle $\\theta$ and radius $r$? And, furthermore, what is their expectation and variance?\n\nFollowing Illowsky and Dean \\cite[Chapter~5.2]{illowsky2018introductory}, the pdf of an uniformly distributed variable is $f(x) = \\frac{1}{b-a}$ for $a \\leq x \\leq b$. \n\nAs $\\theta,r \\sim \\mathcal{U}$, we can formulate the marginal distributions as described in \\eqref{eq:theta_untransformed} (using radiants) and \\eqref{eq:r_untransformed}.\n\n\\begin{equation}\nf_\\Theta(\\theta) = \n\\begin{cases} \n      \\frac{1}{2\\pi} & for~\\theta \\in [0,2\\pi)\\\\\n      0&elsewhere\n   \\end{cases}\n\\label{eq:theta_untransformed}\n\\end{equation}\n\n\\begin{equation}\nf_R(r) = \n\\begin{cases} \n      1 & for~r\\in[0,1]\\\\\n      0&elsewhere.\n   \\end{cases}\n\\label{eq:r_untransformed}\n\\end{equation}\n\nJoining these distributions returns the following joint pdf:\n\\begin{equation}\n\\begin{split}\nf_{R,\\Theta}(r,\\theta) = \n\\begin{cases} \n      \\frac{1}{2\\pi} & \\theta \\in [0,2\\pi),~ r\\in[0,1]\\\\\n      0&elsewhere.\n   \\end{cases}\n\\end{split}\n\\label{eq:joint_pdf_untransformed}\n\\end{equation}\n\nFollowing Dawkins \\cite{dawkins}, we can transform to Cartesian $x$ and $y$ using $x = rcos(\\theta)$ and $y=rsin(\\theta)$. For the transformation, we furthermore need their inverses, which calculate to \n\n\\begin{align*}\nx^2=r^2cos^2(\\theta)& \\qquad y^2=r^2sin^2(\\theta)\\\\\nx^2+y^2&=r^2cos^2(\\theta)sin^2(\\theta)\\\\\nx^2+y^2&=r^2\\\\\nr &= \\sqrt{x^2+y^2} = u_1(x,y)\\\\\n\\label{eq:r-1}\n\\end{align*}\nand\n\\begin{align*}\n r = \\frac{x}{cos(\\theta)}& \\qquad r = \\frac{y}{sin(\\theta)}\\\\\n \\frac{x}{cos(\\theta)} &= \\frac{y}{sin(\\theta)}\\\\\n \\frac{x}{cos(\\theta)} &= \\frac{y}{sin(\\theta)}\\\\\n \\frac{y}{x} &= \\frac{cos(\\theta)}{sin(\\theta)}\\\\\n \\frac{y}{x} &= tan(\\theta)\\\\\n \\theta &= tan^{-1}\\left(\\frac{y}{x}\\right) = u_2(x,y).\n\\label{eq:theta-1}\n\\end{align*}\n\nUsing the transformation theorem proved in Hogg et al. \\cite[Chapter~2.7]{hogg}, we get\n \n\\begin{equation}\n\\begin{split}\nf_{X,Y}(x,y) = f_{R,\\Theta}\\left(\\sqrt{x^2+y^2},tan^{-1}\\left(\\frac{y}{x}\\right)\\right) \\cdot |J|,\n%f_{X,Y}(x,y) = f_{r,\\theta}\\left(u_1,u_2\\right)\\right) \\cdot |J|\n\\end{split}\n\\label{eq:transtheorem}\n\\end{equation}\nwhere \n\\begin{equation}\n\\begin{split}\n|J| &=\n\\left|\n\\begin{matrix}\n\\frac{\\partial u_1}{\\partial x} & \n\\frac{\\partial u_1}{\\partial y}  \\\\[2ex] % <-- 1ex more space between rows of matrix\n\\frac{\\partial u_2}{\\partial x} & \n\\frac{\\partial u_2}{\\partial y}  \\\\[2ex]\n\\end{matrix}\n\\right|\n= \n\\left|\n\\begin{matrix}\n\\frac{x}{\\sqrt{x^2+y^2}}& \n\\frac{y}{\\sqrt{x^2+y^2}}  \\\\[2ex] % <-- 1ex more space between rows of matrix\n-\\frac{y}{y^2+x^2} & \n\\frac{x}{y^2+x^2}  \\\\[2ex]\n\\end{matrix}\n\\right|\\\\[2ex]\n&= \\frac{x}{\\sqrt{x^2+y^2}} \\cdot \\frac{x}{y^2+x^2} -\\frac{y}{\\sqrt{x^2+y^2}}  \\cdot \\left(-\\frac{y}{y^2+x^2}\\right)\\\\[2ex]\n&= \\frac{x^2+y^2}{(x^2+y^2)^{3/2}}\\\\[2ex]\n&=\\frac{1}{\\sqrt{x^2+y^2}},\n\\end{split}\n\\label{eq:jacobiandet}\n\\end{equation}\n\nwith the derivatives being calculated by Symbolab \\cite{symbolab} with the following commands:\n\\begin{lstlisting}\n\\frac{\\partial }{\\partial \\:x}\\left(\\sqrt{x^2+y^2}\\right)\n\\frac{\\partial }{\\partial \\:y}\\left(\\sqrt{x^2+y^2}\\right)\n\\frac{\\partial }{\\partial \\:x}\\left(tan^{-1}\\left(\\frac{y}{x}\\right)\\right)\n\\frac{\\partial }{\\partial \\:y}\\left(tan^{-1}\\left(\\frac{y}{x}\\right)\\right)\n\\end{lstlisting}\n\nSubstituting \\eqref{eq:jacobiandet} into \\eqref{eq:transtheorem}, we get\n\\begin{equation}\n\\begin{split}\nf_{X,Y}(x,y) &= f_{r,\\theta}\\left(\\sqrt{x^2+y^2},tan^{-1}\\left(\\frac{y}{x}\\right)\\right) \\cdot \\frac{1}{\\sqrt{x^2+y^2}}\\\\[2ex]\nf_{X,Y}(x,y) &= \\frac{1}{2\\pi} \\cdot \\frac{1}{\\sqrt{x^2+y^2}} = \\frac{1}{2\\pi\\sqrt{x^2+y^2}},\n%\\begin{cases} \n%      \\frac{1}{2\\pi} & \\theta \\in [0,2\\pi),~ r\\in[0,1]\\\\\n%      0&elsewhere\n%   \\end{cases}\n\\end{split}\n\\label{eq:transtheoremcomplete}\n\\end{equation}\n\nwhich represents the joint PDF of $X$ and $Y$.\\\\\nTo calculate their individual densities, the marginal distributions are needed. As proofed by Larsen and Marx \\cite[Theorem~3.7.2]{larsen2005introduction}, the marginal distribution for $X$ can be obtained by \n\n\\begin{equation}\n\\begin{split}\nf_{X}(x) = \\int_{0}^{\\sqrt{1-x^2}}\\frac{1}{2\\pi\\sqrt{x^2+y^2}} dy,\n\\end{split}\n\\label{eq:marginalX}\n\\end{equation}\n\nwhich calculates to \n\n\\begin{equation}\n\\begin{split}\nf_{X}(x) = \\frac{1}{2\\pi }\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right) \\quad x \\in (0,1)\n%https://www.symbolab.com/solver/step-by-step/%5Cint_%7B0%7D%5E%7B%5Csqrt%7B1-x%5E2%7D%7D%5Cfrac%7B1%7D%7B2%5Cpi%5Csqrt%7Bx%5E%7B2%7D%2By%5E%7B2%7D%7D%7D%20dy\n\\end{split}\n\\label{eq:marginalXcalculated}\n\\end{equation}\n\nusing Symbolab \\cite{symbolab} with the following code:\n\\begin{lstlisting}\n\\int _0^{\\sqrt{1-x^2}}\\frac{1}{2\\pi \\sqrt{x^2+y^2}}\\:dy\n\\end{lstlisting}\n\nPDF \\eqref{eq:transtheoremcomplete} is symmetric in $x$ and $y$ as $f_{X,Y}(x,y) = f_{Y,X}(y,x)$. Consequently, $f_Y(y)$ has similar form:\n\\begin{equation}\n\\begin{split}\nf_{Y}(y) = \\frac{1}{2\\pi }\\ln\\left(\\frac{\\sqrt{1-y^2}+1}{y}\\right) \\quad y \\in (0,1).\n\\end{split}\n\\label{eq:marginalYcalculated}\n\\end{equation}\nTo calculate the expected value, equation \\eqref{eq:ExpValueHogg} is used again:\n\\begin{equation}\n\\begin{split}\nE(X) &= \\int_0^1  \\frac{x}{2\\pi }\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right) dx\\\\\nE(X) &= \\frac{1}{2\\pi}\\int_0^1  x\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right) dx\\\\\nE(X) &= \\frac{1}{4\\pi } \\cdot \\left[x^2\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right)-\\sqrt{1-x^2}\\right]_0^1\\\\\nE(X)&= \\frac{1}{4\\pi} \\approx 0.07958.\n\\end{split}\n\\label{eq:expvalF_X}\n\\end{equation}\n$E(X) = E(Y)$, as again the same value calculates for $Y$ due to the symmetry of the distribution.\nWolframAlpha \\cite{wolfalph} was used for this calculation with the following input:\n\\begin{lstlisting}\n\\int_0^1  \\frac{x}{2\\pi }\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right)\n\\end{lstlisting}\n\nTo calculate the second moment, the variance - equation \\eqref{eq:HoggVariance} - is recalled:\n\\[\nVar(x) = E(X^2)-(E(X))^2,\n\\]\nwhere\n\\begin{equation}\n\\begin{split}\nE(X^2) =  \\frac{1}{2\\pi}\\int_0^1  x^2\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right) dx = \\frac{1}{24}\n\\end{split}\n\\label{eq:E(X^2)}\n\\end{equation}\nThis calculation was done in WolframAlpha \\cite{wolfalph} with the following input:\n\\begin{lstlisting}\n\\int_0^1  \\frac{x^2}{2\\pi }\\ln \\left(\\frac{\\sqrt{1-x^2}+1}{x}\\right)\n\\end{lstlisting}\nConsequently, \n\\begin{equation}\n\\begin{split}\nVar(X) = Var(Y) = \\frac{1}{24}- \\left(\\frac{1}{4\\pi}\\right)^2 = \\frac{2\\pi ^2-3}{48\\pi ^2} \\approx 0.1581.\n\\end{split}\n\\label{eq:VarXcalculated}\n\\end{equation}\n\n\n\n\\chapter{Workbook Assignment 3: A Simple Parameter Estimation}\t\n\nSupposed we have a network router with a total bandwith until it breaks down described by the random variable $S$, which is exponentially distributed:\n\\begin{equation}\n\\begin{split}\n%s(t) = f_S(t) =  \\frac{1}{\\theta} e^{-\\frac{t}{\\theta}}\ns(t) =  \\frac{1}{\\theta} e^{-\\frac{t}{\\theta}}.\n\\end{split}\n\\label{eq:exphardwarefailure}\n\\end{equation}\n\n\\section{Bandwith Total to Failure}\nAssumed we have another backup device, the bandwidth total to failure of both devices is described by $T$, which is the sum of $S_1$ and $S_2$, which each are described by \\eqref{eq:exphardwarefailure}. T is consequently\n\\begin{equation}\n\\begin{split}\nT = S_1 + S_2.\n\\end{split}\n\\label{eq:T}\n\\end{equation}\nBoth variables are random variables by task assignment and it can furthermore be assumed that they are independent as the performance of one device has no influence on the performance of another device. Furthermore, bandwidth is a continuous variable that cannot take negative values. With these assumptions about the variables, the sum of both variables is consequently calculated by convolution, following Larsen and Marx \\cite[Theorem~3.8.3]{larsen2005introduction}.\n\\begin{equation}\n\\begin{split}\nt(z) = \\int_{-\\infty}^\\infty s(t)s(z-t)~dt.\n\\end{split}\n\\label{eq:tz1}\n\\end{equation}\nAs only positive values can be obtained for the bandwidth, \\eqref{eq:tz1} simplifies to \n\\begin{equation}\n\\begin{split}\nt(z) = \\int_{0}^zs(t)s(z-t)~dt.\n\\end{split}\n\\label{eq:tz2}\n\\end{equation}\nInserting the density of $S$ yields\n\\begin{equation}\n\\begin{split}\nt(z) \n&= \\int_{0}^z \\left(\\frac{1}{\\theta} e^{-\\frac{t}{\\theta}}\\right)\n\\left(\\frac{1}{\\theta} e^{-\\frac{z-t}{\\theta}}\\right)~dt\\\\\n&= \\frac{1}{\\theta^2} e^{-\\frac{z}{\\theta}}\\int_{0}^z~dt\\\\\n&= \\frac{z}{\\theta^2} e^{-\\frac{z}{\\theta}}\\\\\n&= f_T(z;~\\theta).\n\\end{split}\n\\label{eq:tz3}\n\\end{equation}\n\n\\section{Likelihood Function}\nGiven an experiment with the dual-router-system yielding a sample $T_1$, $T_2$, ..., $T_n$, calculate the likelihood function for $\\theta$. Propose a transformation of this likelihood function whose maximum is the same and can be computed easily.\n\nFollowing Definition 5.2.1 in Larsen and Marx \\cite{larsen2005introduction}, the likelihood function is described by\n\\begin{equation}\n\\begin{split}\nL(\\theta) = \\prod_{i=1}^n f_Y(y_i;~\\theta),\n\\end{split}\n\\label{eq:LikelyhoodFunctionDefinition}\n\\end{equation}\nwhich, in the case of this tasks, is \n\\begin{equation}\n\\begin{split}\nL(\\theta) \n&= \\prod_{i=1}^n f_T(z_i;~\\theta)\\\\\n&= \\prod_{i=1}^n \\frac{z_i}{\\theta^2} e^{-\\frac{z_i}{\\theta}}\\\\\n\\end{split}\n\\label{eq:LikelyhoodFunction2}\n\\end{equation}\nand simplifies to \n\\begin{equation}\n\\begin{split}\nL(\\theta) \n&= \\theta^{-2n}\\left(\\prod_{i=1}^n z_i\\right)e^{-\\frac{1}{\\theta}\\sum_{i=1}^n z_i}.\n\\end{split}\n\\label{eq:LikelyhoodFunction3}\n\\end{equation}\nTo calculate the maximum likelihood, equation \\eqref{eq:LikelyhoodFunction3} must be derived with respect to $\\theta$ and equated to $0$. In its current form, such calculation quickly becomes computationally expensive and eventually inaccurate. To surpass such problem, \\eqref{eq:LikelyhoodFunction3} can be transformed using the natural logarithm as the value maximising $L(\\theta)$ also maximises $\\ln L(\\theta)$:\n\\begin{equation}\n\\begin{split}\n\\ln~L(\\theta) \n&= -2n\\ln\\theta + \\ln\\left(\\prod_{i=1}^n z_i\\right)-\\frac{1}{\\theta}\\sum_{i=1}^n z_i.\n\\end{split}\n\\label{eq:LikelyhoodFunction4}\n\\end{equation}\nThe derivation then yields\n\\begin{equation}\n\\begin{split}\n\\frac{d\\ln~L(\\theta)}{d\\theta}\n&= \\frac{-2n}{\\theta}+\\frac{1}{\\theta^2}\\sum_{i=1}^n z_i,\n\\end{split}\n\\label{eq:LikelyhoodFunction5}\n\\end{equation}\nwhich results in the maximum likelihood function when equated to $0$ and solved for $\\theta$:\n\\begin{equation}\n\\begin{split}\n\\frac{-2n}{\\theta}+\\frac{1}{\\theta^2}\\sum_{i=1}^n z_i = 0.\n\\end{split}\n\\label{eq:LikelyhoodFunction6}\n\\end{equation}\nThe maximum likelihood estimator $\\theta_e$ is consequently \n\\begin{equation}\n\\begin{split}\n\\theta_e =\\frac{1}{2n}\\sum_{i=1}^n z_i.\n\\end{split}\n\\label{eq:MLE}\n\\end{equation}\nIn an experiment with $n=5$ observations measuring the total bandwidth to failure, the following results were observed:\n\\begin{center}\n16, 86, 96, 17, 339.\n\\end{center}\nTo estimate the model-parameter with the maximum likelihood, the values are inserted into \\eqref{eq:MLE}:\n\\begin{equation}\n\\begin{split}\n\\theta_e =\\frac{1}{2\\cdot5}(16+86+96+17+339) = 55.4.\n\\end{split}\n\\label{eq:MLECalculation}\n\\end{equation}\nTo calculate the expectation of the bandwidth, we reuse equation \\eqref{eq:ExpValueHogg} which, applied to this task, is\n\\begin{equation}\n\\begin{split}\nE(T) = \\int_0^\\infty z\\frac{z}{\\theta^2} e^{-\\frac{z}{\\theta}}~dz,\\\\\n\\end{split}\n\\label{eq:expvalue3}\n\\end{equation}\nand calculates to \n\\begin{equation}\n\\begin{split}\nE(T) \n&= \\int_0^\\infty z\\frac{z}{55.4^2} e^{-\\frac{z}{55.4}}~dz\\\\\n&= 110.8.\n\\end{split}\n\\label{eq:expvalue4}\n\\end{equation}\nEquation \\eqref{eq:expvalue4} was calculated using symbolab \\cite{symbolab} with the following command:\n\\begin{lstlisting}\n\\int _0^{\\infty }\\:z\\frac{z}{55.4^2}\\:e^{-\\frac{z}{55.4}}\n\\end{lstlisting}\n\n\\chapter{Workbook Assignment 4: Hypothesis Test}\t\n\nAssumed we are producing high-quality hammers in our factory and want to model the production quality. From the last 1000 produced hammers, we observed an average weight of $\\mu_1=971~g$ and a standard deviation of $\\sigma_1 = 42~g$. As $n = 1000$, we assume that we can treat the point estimates for the mean and the standard deviation as population parameters.\n\nProduction inaccuracies are usually normally dispersed, and as we neither have access to the raw data of individual observations nor have information on any skewness or non-normal behaviour, a normal distribution $N(\\mu, \\sigma^2)$ is assumed.\nThe normal distribution is defined as follows \\cite[Definition~3.4.1]{hogg}: \n\n\\begin{equation} \\frac{1}{{\\sigma \\sqrt {2\\pi } }}e^{{{ - \\left( {x - \\mu } \\right)^2 } \\mathord{\\left/ {\\vphantom {{ - \\left( {x - \\mu } \\right)^2 } {2\\sigma ^2 }}} \\right. \\kern-\\nulldelimiterspace}{2\\sigma ^2 }}}.\n\\label{eq:normaldist}\n\\end{equation}\n\n\nIt depends on two parameters, the population standard deviation $\\sigma$ and the population mean $\\mu$, which both are provided. In general, any normal distribution has a bell-shaped form, indicating that it is symmetric and not skewed to any side. Apart from the mean and the standard deviation, we are not provided any further data.  The assumption of such model of course does not hold anymore if the data of the 1000 produced hammers introduces any kind of bias or skewness. \n\n\nOther distributions are excluded as they are not applicable to this case or are less fitting. A Binomial Distribution for example is not applicable as it is binary, whereas the independent variable central to this exercise - hammer weight - is continuous. \\\\Describing the hammer weight as a repeated Bernoulli trial would also be an option to model the distribution, however such endeavor would firstly approximate a normal distribution as well and would secondly assume that the weight measurements are integer variables, whereas they are of continuous nature. \\\\\nAnother popular distribution, the Poisson distribution, is also not applicable as it models the average number of events per time interval \\cite{bruce2017practical}. \\\\\nUsing an exponential distribution to model the weight dispersion of hammer production would imply that we expect for example continuously increasing counts of hammers for increasing weights, which is not a senseful assumption. \\\\\nConsequently, we assume that the normal distribution is the best approximation.\n\nUsing the normal distribution as approximation implies accepting several assumptions. We assume that the model has the x-axis as an horizontal asymptote, that its mean is equal to its median, that its mode is the same as its mean and that it is symmetric about the mean \\cite[Chapter~3.4]{hogg}.\n\nUsing \\eqref{eq:normaldist} with the provided parameters of $\\mu_1 = 971$ and $\\sigma_1 = 42$, the following model is proposed: \n\n\\begin{equation} \\frac{1}{{42 \\sqrt {2\\pi } }}e^{{{ - \\left( {x - 971 } \\right)^2 } \\mathord{\\left/ {\\vphantom {{ - \\left( {x - 971 } \\right)^2 } {2(42) ^2 }}} \\right. \\kern-\\nulldelimiterspace}{2(42) ^2 }}} ~~~=~~~ \\frac{1}{{42 \\sqrt {2\\pi } }}e^{{{ - \\left( {x - 971 } \\right)^2 } \\mathord{\\left/ {\\vphantom {{ - \\left( {x - 971 } \\right)^2 } {7056 }}} \\right. \\kern-\\nulldelimiterspace}{3528 }}}.\n\\label{eq:normaldistadapted}\n\\end{equation}\n\n\n\nAssumed a new production system for hammer production is tested. A random sample output of hammers of this new production output returns the following weights in grams: \\\\\n\n\\begin{center}\n    1009, 1069, 966, 952, 1084, 897, 909, 995, 975, 983.\n\\end{center}\n\nHow do we know if this new system's weight accuracy is better than the old system's accuracy, i.e. how do we find out whether the weight variance of the new system is lower than the variance of the old system?\n\nTo answer this question, we have to perform a statistical test comparing the variances of both samples, which requires hypotheses. Overall, we expect that the new system reduces weight variance and is more accurate. The hypotheses are consequently \n\n\\begin{center}\n$H_0~~:~~ \\sigma^2_2~=~\\sigma^2_1$\\\\ \n$H_1~~:~~ \\sigma^2_2~<~\\sigma^2_1$.\n\\end{center}\n\nwhere $\\sigma^2_1$ is defined as the population variance of the old production system and $\\sigma^2_2$ is defined as the population variance of the new production system.\n\nFollowing Larsen and Marx \\cite[Chapter 7.5]{larsen2005introduction}, the chi square distribution is needed for inferences on variances. To test our sample variance $s_2^2 = \\frac{32594.9}{9} \\approx 3621.66 $ against the variance $\\sigma^2_1 = 42^2 = 1764$, we can now use the Chi Square Test or the F-Test. As we earlier assumed that $\\sigma_1$ is the population variance instead of a sample variance, we do not need to rely on an F-Test and can work with the Chi Square Test. The hypotheses can then be formulated as \n\n\\begin{center}\n$H_0~~:~~ \\sigma^2_2~=~1764$\\\\ \n$H_1~~:~~ \\sigma^2_2~<~1764$.\n\\end{center}\n\nFollowing Larsen and Marx \\cite[Chapter 7.5]{larsen2005introduction}, the Chi Square test statistic is given by \n\n\\begin{equation}\n\\chi^2 = \\frac{(n-1)s_2^2}{\\sigma_1^2},\n\\label{eq:chisquarestatistic}\n\\end{equation}\n\nwith the decision rule of rejecting $H_0$ if \n\\\\\n\\begin{equation}\n\\chi^2 \\leq \\chi^2_{1-\\alpha,n-1},\n\\label{eq:decisionrule}\n\\end{equation}\n\\\\\nwhere our error probability $\\alpha$ is our level of significance. An usual assumption is a 95 percent confidence interval, which results in $\\alpha = 0.05$. As the losses, which an error in this test might incur, can be expected to be quite minor, there is no need to increase the confidence interval and to work with a smaller $\\alpha$.\n\n\nInserting the sample figures into \\eqref{eq:chisquarestatistic}, we observe \n\\begin{equation}\n\\chi^2 = \\frac{(10-1) \\cdot \\frac{32594.9}{9}}{1764} = \\frac{32594.9}{1764} \\approx 18.48.\n\\label{eq:chisqstatcalc}\n\\end{equation}\n\nUsing the lower-tail critical values of chi-square distribution of the Engineering Statistics Handbook \\cite{nist}, the critical value is approximated by \n\\\\\n\\begin{equation}\n\\chi^2_{0.95,9}\\approx 3.33,\n\\label{eq:criticalvalue}\n\\end{equation}\n\\\\\nwith the corresponding p-value of\n\\\\\n\\begin{equation}\np = P(\\chi^2 < 18.48) = 1-0.03 = 0.97,\n\\label{eq:pvalue}\n\\end{equation}\n\\\\\nusing the p-Value Calculator for a Chi-Square Test \\cite{freepvalue}. \n\nConsequently, as \n\\\\\n\\begin{equation}\n\\chi^2 \\nleq \\chi^2_{0.95,9}\n\\label{eq:criticalvalue}\n\\end{equation}\n\\\\\nor, put differently, the p-value is much larger than our $\\alpha$, we can not reject $H_0$ and can not say that the new model makes more constant weights. Looking at the large initial difference in variances $s_2^2 \\approx 3621.66 $ and $\\sigma^2_1 = 1764$, this result is not too surprising. \n\n\n\n\\chapter{Workbook Assignment 5: Sufficient Statistics}\t\nLet $X_1,~X_2,~...,~X_n$ be the random sample of a positive random variable $X$ having the density function \n\\begin{equation}\n\\begin{split}\nf_X(x;~\\theta) = \\frac{1}{2!~\\theta^3}x^2e^{-\\frac{x}{\\theta}}\n\\end{split}\n\\label{eq:suffpdf}\n\\end{equation}\nwith one parameter $\\theta \\in \\mathbb{R}+$. Find an estimator for $\\theta$ that is sufficient. \n\\\\\nLarsen and Marx define sufficient statistics as follows: \"Let $X_1 = k_1, . . . , X_n = k_n$ be a random sample of size $n$ from $p_X(k;~\\theta)$. The statistic $\\hat{\\theta} = h(X_1, . . . , X_n)$ is sufficient for $\\theta$ if the likelihood function, $L(\\theta)$, factors into the product of the pdf for $\\hat{\\theta}$ and a constant that does not involve $\\theta$ — that is, if\n\\begin{equation}\n\\begin{split}\nL(\\theta) \n= \\prod_{i=1}^n p_X(k_i;\\theta)\n=p_{\\hat{\\theta}}(\\theta_e;\\theta)b(k_1,...,k_n)\n\\end{split}\n\\label{eq:SufficientLikelihood}\n\\end{equation}\nA similar statement holds if the data consist of a random sample $Y_1~=~y_1,...,Y_n~=~ y_n$ drawn from a coninuous pdf $f_Y(y;\\theta)$.\" \\cite{larsen2005introduction}.\nThis can be constructed for the given density function \\eqref{eq:suffpdf}. Firstly, to calculate the likelihood function, its definition \\eqref{eq:LikelyhoodFunctionDefinition} is used.\n\\begin{equation}\n\\begin{split}\nL(\\theta) \n&= \\prod_{i=1}^n f_X(x_i;~\\theta)\\\\\n&= \\prod_{i=1}^n \\frac{1}{2!~\\theta^3}x_i^2e^{-\\frac{x_i}{\\theta}}.\\\\\n\\end{split}\n\\label{eq:SufficientLikelihood2}\n\\end{equation}\nThis can be simplified to \n\\begin{equation}\n\\begin{split}\nL(\\theta) \n&= \\frac{1}{2^n\\theta^{3n}}\\prod_{i=1}^n x_i^2e^{-\\frac{x_i}{\\theta}}\\\\\n&= \\frac{1}{2^n\\theta^{3n}} e^{-\\frac{1}{\\theta}\\sum_{i=1}^nx_i} \\left(\\prod_{i=1}^n x_i\\right)^2.\\\\\n\\end{split}\n\\label{eq:SufficientLikelihood3}\n\\end{equation}\nNow\n\\begin{equation}\n\\begin{split}\np_{\\hat{\\theta}}(\\theta_e;\\theta) = \\frac{1}{2^n\\theta^{3n}} e^{-\\frac{1}{\\theta}\\sum_{i=1}^nx_i}\n\\end{split}\n\\label{eq:SufficientLikelihood4}\n\\end{equation}\nand\n\\begin{equation}\n\\begin{split}\nb(k_1,...,k_n) = \\left(\\prod_{i=1}^n x_i\\right)^2.\n\\end{split}\n\\label{eq:SufficientLikelihood5}\n\\end{equation}\nAs \\eqref{eq:SufficientLikelihood5} is not a function of $\\theta$, $\\sum_{i=1}^nx_i$ is a sufficient estimator for $\\theta$.\n\n\n\n\n\n\n\\chapter{Workbook Assignment 6: Bayesian Estimates}\t\nLet $X_1, X_2, ... , X_{10}$ be a random sample from a gamma distribution with $\\alpha =3$ and $\\beta =1/\\theta$. Suppose we believe that $\\theta$ follows a gamma-distribution with $\\alpha =3$ and $\\beta = 2$.\n\n\\section{Posterior Distribution}\nTo calculate the posterior distribution, the following Bayesian model can be formulated from the task assignment:\n\\begin{equation}\n\\begin{split}\nX_i|\\theta &\\sim \\Gamma\\left(3,\\frac{1}{\\theta}\\right)\\\\\n\\Theta &\\sim \\Gamma(3,2).\n\\end{split}\n\\label{eq:Bayesmodel}\n\\end{equation}\nThe Gamma distribution which both $X$ and $\\Theta$ follow is given by Hogg et al. \\cite[Equation~3.3.2]{hogg}:\n\\begin{equation}\n\\begin{split}\nf(x) = \\frac{x^{\\alpha-1}e^{-\\frac{x}{\\beta}}}{\\Gamma(\\alpha)\\beta^\\alpha}\\quad x>0.\n\\end{split}\n\\label{eq:GammaDist}\n\\end{equation}\nGenerally, the posterior pdf $k(\\theta|X)$ is given by Hogg et al. as: \\cite[Equation~11.1.5]{hogg} \n\\begin{equation}\n\\begin{split}\nk(\\theta|x) = \\frac{L(x|\\theta)h(\\theta)}{g_1(x)}\n\\end{split}\n\\label{eq:Posterior}\n\\end{equation}\nwhere \n\\begin{equation}\n\\begin{split}\ng_1(x) = \\int_{-\\infty}^\\infty L(x|\\theta)h(\\theta) ~d\\theta.\n\\end{split}\n\\label{eq:g_1}\n\\end{equation}\nFollowing Hogg et al. \\cite[Chapter 11.1.1]{hogg} the simplified notation of \n\\begin{equation}\n\\begin{split}\nk(\\theta|x) \\propto L(x|\\theta)h(\\theta)\n\\end{split}\n\\label{eq:Posterior2}\n\\end{equation}\nis sufficient to calculate the posterior distribution as $g_1(x)$ is a normalising factor in this context. The calculation of $g_1(x)$ can consequently be dropped. $L(x|\\theta)$ is obtained by inserting the upper model of \\eqref{eq:Bayesmodel} into \\eqref{eq:GammaDist}:\n\\begin{equation}\n\\begin{split}\nL(x|\\theta) \n&= \\prod_{i=1}^n \\frac{x_i^{3-1}e^{-\\frac{x_i}{\\frac{1}{\\theta}}}}{\\Gamma(3)\\left(\\frac{1}{\\theta}\\right)^3} \\\\\n&= \\prod_{i=1}^n \\frac{x_i^{2}\\theta^3e^{-x_i\\theta}}{\\Gamma(3)}\\\\\n&= \\frac{x^{2n}\\theta^{3n}e^{-\\theta\\sum_{i=1}^nx_i}}{\\Gamma(3)^n}.\n\\end{split}\n\\label{eq:bayeslikelyhood}\n\\end{equation}\nThe prior pdf is given by the lower part of \\eqref{eq:Bayesmodel}:\n\\begin{equation}\n\\begin{split}\nh(\\theta) = \\frac{\\theta^{3-1}e^{-\\frac{\\theta}{2}}}{\\Gamma(3)2^3}\n=\\frac{\\theta^{2}e^{-\\frac{\\theta}{2}}}{8\\Gamma(3)} .\n\\end{split}\n\\label{eq:BayesPrior}\n\\end{equation}\nConsequently, \n\\begin{equation}\n\\begin{split}\nk(\\theta|x) \n\\propto \\frac{x^{2n}\\theta^{3n}e^{-\\theta\\sum_{i=1}^nx_i}}{\\Gamma(3)^n} \\frac{\\theta^{2}e^{-\\frac{\\theta}{2}}}{8\\Gamma(3)},\n\\end{split}\n\\label{eq:calculatedposterior}\n\\end{equation}\nassuming $0<\\theta<\\infty$. Dropping the constants results in \n\\begin{equation}\n\\begin{split}\nk(\\theta|x) \n&\\propto \\theta^{3n}\\theta^{2}e^{-\\theta\\sum_{i=1}^nx_i} e^{-\\frac{\\theta}{2}}\\\\\n&\\propto \\theta^{3n+2}e^{-\\theta(\\frac{1}{2}+\\sum_{i=1}^nx_i)}\n\\end{split}\n\\label{eq:calculatedposterior2}\n\\end{equation}\nLooking at the form of \\eqref{eq:calculatedposterior2}, it is apparent that it is a $\\Gamma$ function. $\\alpha$ and $\\beta$ can now be calculated using \\eqref{eq:calculatedposterior2}, \\eqref{eq:GammaDist} and $n=10$ from the assignment.\n\\begin{equation}\n\\begin{split}\n\\alpha-1 &= 3n+2\\\\\n\\alpha &= 33\n\\end{split}\n\\label{eq:postalpha}\n\\end{equation}\n\\begin{equation}\n\\begin{split}\n-\\frac{\\theta}{\\beta} &= -\\theta\\left(\\frac{1}{2}+\\sum_{i=1}^nx_i\\right)\\\\\n\\beta &= \\frac{1}{\\frac{1}{2}+\\sum_{i=1}^nx_i}\n\\end{split}\n\\label{eq:postbeta}\n\\end{equation}\nThe posterior distribution is consequently \n\\begin{equation}\n\\begin{split}\n\\Theta|X &\\sim \\Gamma\\left(33,\\frac{1}{\\frac{1}{2}+\\sum_{i=1}^nx_i}\\right).\n\\end{split}\n\\label{eq:Posteriormodel}\n\\end{equation}\n\n\\section{Bayes Point Estimate by Square-Error Loss Function}\nAssumed, $\\bar{x} = 16.5$ is observed, what is the Bayes point estimate associated with the square-error loss function?\nFollowing Theorem 5.8.1 \\cite{larsen2005introduction}, the Bayes estimate for $\\theta$ is the mean of the posterior if a square-error loss function is used. As the distribution is a Gamma-distribution, the mean or expected value is calculated by \n\\begin{equation}\n\\begin{split}\nE(X|\\Theta) = \\alpha\\beta,\n\\end{split}\n\\label{eq:expvalgamma}\n\\end{equation}\nas proven in Chapter 3.3 \\cite{hogg}. Using $\\alpha = 33$ and \n\\begin{equation}\n\\begin{split}\n\\beta &= \\frac{1}{\\frac{1}{2}+\\sum_{i=1}^nx_i}\\\\\n&=\\frac{1}{\\frac{1}{2}+n\\bar{x}}\\\\\n&=\\frac{1}{\\frac{1}{2}+10\\cdot16.5}\\\\\n&=\\frac{1}{165.5},\n\\end{split}\n\\label{eq:postbeta}\n\\end{equation}\nthe mean computes to \n\\begin{equation}\n\\begin{split}\nE(X|\\Theta) = \\frac{33}{165.5} \\approx 0.1994.\n\\end{split}\n\\label{eq:expvalgammacalc}\n\\end{equation}\n\n\\section{Point Estimate by Mode}\nWhat is the Bayes point estimate using the mode of the posterior distribution?\\\\\nAs the mode of a distribution is simply its highest point, it is the maximum of the posterior distribution. Consequently, the maximum is found by deriving the posterior distribution with respect to $\\theta$, equating it to 0 and solving it. The posterior distribution is\n\\begin{equation}\n\\begin{split}\nf(\\theta) = \\frac{\\theta^{32}e^{-\\theta(0.5+\\sum_{i=1}^n x_i)}}\n{\\Gamma(33)\\beta^\\alpha},\n\\end{split}\n\\label{eq:postdistinserted}\n\\end{equation}\nwhere the denominator is constant and can be excluded. The derivative computes to\n\\begin{equation}\n\\begin{split}\nf_\\theta'(\\theta) = 32\\theta^{31}e^{-\\theta\\left(0.5+\\sum_{i=1}^n x_i\\right)}+e^{-\\theta\\left(0.5+\\sum_{i=1}^n x_i\\right)}\\left(-0.5-\\sum_{i=1}^n x_i\\right)\\theta^{32}\n\\end{split}\n\\label{eq:postdistderived}\n\\end{equation}\nand results in the following roots if equated to 0:\n\\begin{equation}\n\\begin{split}\n\\theta_1 = 0 \\qquad \\theta_2 = \\frac{32}{0.5+\\sum_{i=1}^n x_i}.\n\\end{split}\n\\label{eq:roots}\n\\end{equation}\n$\\theta_1 = 0$ is no solution for a gamma distribution. Consequently, $\\theta_2$ is the only possible solution. Inserting $\\bar{x} = 16.5$ from previous section results in \n\\begin{equation}\n\\begin{split}\n\\theta_2 = \\frac{32}{0.5+10\\cdot16.5} = \\frac{32}{165.5} \\approx 0.1934.\n\\end{split}\n\\label{eq:rootsN}\n\\end{equation}\n", "meta": {"hexsha": "2d202e25aac2aa603323e0a667720fa85104edb6", "size": 50616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "020-Body.tex", "max_stars_repo_name": "Paul1911/Advanced-Statistics", "max_stars_repo_head_hexsha": "54163a8575235197a82594a722f3eaff2602b0dc", "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": "020-Body.tex", "max_issues_repo_name": "Paul1911/Advanced-Statistics", "max_issues_repo_head_hexsha": "54163a8575235197a82594a722f3eaff2602b0dc", "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": "020-Body.tex", "max_forks_repo_name": "Paul1911/Advanced-Statistics", "max_forks_repo_head_hexsha": "54163a8575235197a82594a722f3eaff2602b0dc", "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.6721311475, "max_line_length": 859, "alphanum_fraction": 0.7021495179, "num_tokens": 16836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.634564209457508}}
{"text": "% CREATED BY DAVID FRISK, 2016\n\\section{Theory}\nIn the following the section the underlying theory of the models used in the project are introduced and explained, along with relevant background and examples. \n\n\\subsection{CPG Model}\n\n\\subsubsection{Mathematical Model of Physical Behaviour}\n%CPG is a mathematical model of human/animal behaviour. Limit cycle, standing wave. Robust, can handle disturbance. (Model different different joints as CPG. Model different DoF as CPG.)\n\nBiological behaviour in mammals, such as walking or swimming, are usually repetative and oscillatory creating energy efficient movements. This can be seen in Figure \\ref{fig:walkingCycle}, which shows the walking cycle of a human, measured as the acceleration in Z-direction whilst walking. Due to the rhytmic patterns in the behaviour, it is possible to construct a mathematical model to mimic this type of behaviour. \n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=.75\\textwidth]{include/figure/reference_right_hip_z.png}\n    \\caption{Walking cycle of a human. Where \\textit{Z} is the horizontal direction of the reference system.}\n    \\label{fig:walkingCycle}\n\\end{figure}\n\nA Central Pattern Generator (CPG) is a mathematical model of a neural oscillator, a neural network that produces rhytmic patterned outputs without sensory feedback \\cite{CPGHauert}. The output of a CPG can be used as a model of biological rhytmic behaviour, for instance the activation of a certain muscle.\n\nThe activity of one muscle in an animal affect the activation of other muscles in its body automatically in order to distribute load and to achieve balance. Similarily CPGs can be modelled as a network, to account for more than a single muscle as well as the interaction between muscles.\n\n\n\n\\subsubsection{Model of Neural Oscillator} \\label{modelOfNeuralOscillator}\n%The different existing models. We chose the Matsuoka, show matsuoka sketch, describe parameters.\n\nThere exists many different models of CPGs \\cite{CPGmodels}, the model to be examined throughout this project is the half-centre model. The half-centre model proposes to account for the alternate activation of the extensor and flexor muscles in the limbs, originally inspired by a cat walking. A mathimatical model was proposed by K. Matsuoka \\cite{matsuoka}, using two mutually inhibatory neurons in each oscillator to account for the extensor-flexor behaviour. The model ensures that when one neuron is active, the other is surpressed, creating the oscillatory behaviour.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{include/figure/matsuoka.png}\n    \\caption{The Matsuoka model of a half-centre CPG \\cite{CPGwolff}, with parameters explained in Table \\ref{tab:parameters}.}\n    \\label{fig:matsuoka}\n\\end{figure}\n\nThe setup of the Matsuoka model is shown in Figure \\ref{fig:matsuoka}, with the parameters as described in Table \\ref{tab:parameters}. The behaviour of the model is described by the following equations \\cite{CPGequations}:\n\n\\begin{align}\n    \\tau_u \\dot{u}_i &= -u_i - \\beta v_i + \\sum^{n}_{j=1} w_{ij}y_j + u_0, \\\\\n    \\tau_v \\dot{v_i} &= -v_i + y_i, \\\\\n    y_i &= \\text{max}(0, u_i), \\\\\n    o &= y_2 - y_1\n\\end{align}\n\nwhere the model is simulated by integrating over time using Euler integration and timestep $\\Delta t$ and $\\dot{u}_i$, $\\dot{v}_i$ from above in:\n\n\\begin{align}\n    u_i(t + \\Delta t) &= u_i(t) + \\Delta t \\dot{u}_i, \\\\\n    v_i(t + \\Delta t) &= v_i(t) + \\Delta t \\dot{v}_i.\n\\end{align}\n\n\\begin{table}[htbp]\n    \\centering\n    \\begin{tabular}{|c|p{6.5cm}|c|c|}\n         \\hline\n\\textbf{Parameter} & \\textbf{Description} & \\textbf{Initial value} & \\textbf{Comment} \\\\ \\hline\n$z_i$ & input of neuron i &  & oscillating  \\\\ \\hline\n$u_0$ & external tonic input & 1.0 &  \\\\ \\hline\n$u_1$ & inner state of neuron 1 & 0.0 & fixed \\\\ \\hline\n$u_2$ & inner state of neuron 2 & 1.0 & fixed \\\\ \\hline\n$v_1$ & auxiliary variable measuring the degree of self-inhibition of neuron 1 & 1.0 & fixed \\\\ \\hline\n$v_2$ & auxiliary variable measuring the degree of self-inhibition of neuron 2 & 0.0 & fixed \\\\ \\hline\n$\\beta$ & modulation parameter & 2.5 &  \\\\ \\hline\n$w_{ij}$ & weights connecting neuron j to neuron i & -2.0 &  \\\\ \\hline\n$y_i$ & the output of neuron i & 0 & \\\\ \\hline\n$\\tau_u$ & time constant & 0.025 &  \\\\ \\hline\n$\\tau_v$ & time constant & 0.3 &  \\\\ \\hline\n$o$ & the output of the oscillator & & \\\\ \\hline\n    \\end{tabular}\n    \\caption{The parameters used in the Matsuoka model of a half-centre CPG.}\n    \\label{tab:parameters}\n\\end{table}\n\n\n\\subsubsection{Model of CPG Network} \\label{CPGnetwork}\n%Combining different CPG neurons on a network to model a human where each Neuron is a DoF.\n\nCoupling multiple CPGs into a network makes it possible to model more complex structures, such as an animal or a human. This can be done by connecting the output of one neuron to the input of another. This project investigatex the walking behaviour of a human implemented on a humanoid robot, thus human behaviour can be modelled by looking at the movement in different joints of the body, corresponding to the joints of the humanoid robot. Since the output of a CPG is one-dimensional over time, and human movement is three dimensional, one can imagine modelling the movement in each dimension with a separate CPG. The output signals can then be superimposed to obtain the total movement.\n\n\n\\subsubsection{Choice of Input to Oscillator} \\label{choiseOfInputToOscillator}\n%The different models (summing output and weights). Asyncronous vs syncronous.\n%2.1.3 in old report\nEach of the neurons in a CPG network have inputs ($z_i$) that are affected by the output of the other neurons ($o$). One can imagine that all neurons are fully connected, but by setting the weight between two neurons to zero, that weight is \\textit{removed}. The input to the neurons can be calculated in different ways, one way inspired by Liu et.al. \\cite{liu} is to define the inputs to neuron $i$ as\n\\begin{align}\nz_1 &= \\sum_{j \\text{ neighbour of } i} a_{ij}u_j, \\\\\nz_2 &= 0.\n\\end{align}\nAnother implementation inspired by Shan et.al. \\cite{shan} defines the inputs as\n\\begin{align}\nz_1 &= \\sum_{j \\text{ neighbour of } i} a_{ij}[y_j]^+, \\\\\nz_2 &= \\sum_{j \\text{ neighbour of } i} a_{ij}[y_j]^-,\n\\end{align}\nwhere \n\\begin{align}\n[y_j]^+ &:= \\text{max}(y_j,0), \\\\\n[y_j]^- &:= \\text{min}(y_j,0).\n\\end{align}\n\nNeurons can also be affected by an external tonic input ($u_0$). The amplitude of the oscillation in the CPG is proportional to the tonic input. If the input is oscillatory, the oscillator will lock to the frequency of the input. When the input is removed, the oscillator will smoothly return to the original frequency \\cite{CPGwolff}.\n\n\n\\subsection{Optimisation Using Genetic Algorithm}\nA CPG alone might not achieve satisfactory results, as the parameters in the CPG or network might need to be tweaked and optimised to achieve the desired behaviour. A commonly used technique for optimising behaviour is to use reinforcement learning to improve the model based on an external measure of success. This project uses a Genetic algorithm (GA) as a reinforcement learning technique to achieve desired walking behaviour. A genetic algorithm is an evoutionary algorithm that takes inspration from natural selection implemented as an optimisation problem \\cite{GAHauert}. \n\n\n\\subsubsection{Genome}\n%Difference between using only weights or the entire CPG network as genome.\n\n\nThe \\textit{genome} is a set of parameters that defines a proposed solution to the problem that the GA is trying to solve. One can imagine various different genomes when optimising the behaviour of a CPG, for instance the internal parameters in the CPG, shown in Table \\ref{tab:parameters}. The connection weights between neurons in a CPG network, as described in Section \\ref{CPGnetwork}, could also be used to account relation between CPGs in a network.\n\n\\subsubsection{Operators}\n%Init population, simulate behaviour, evaluation, selection, mutation, permutation\nThe basic implementation of a GA is in summary; initialise the population, simulate the behaviour, evaluate success, selecion process, mutation and permutations, repeat until converge. A more detailed description can be found in \\cite{wahde}. The evaluation process, also known as the \\textit{fitness function}, produces a fitness score which is the measurement the success of the individual. Since this project investigates walking behaviour in a humanoid robot, a fitness function may include e.g.; distance walked, time walked, stability, falling, walking style, etc.", "meta": {"hexsha": "4268542c73a519bb2ff715e346373c11cf761972", "size": 8591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/include/Theory.tex", "max_stars_repo_name": "horken7/bioloid-cpg", "max_stars_repo_head_hexsha": "d0e16e6699e5f6c19a9b0a6c11fc29798fc2b1d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-11-14T09:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T11:45:35.000Z", "max_issues_repo_path": "Report/include/Theory.tex", "max_issues_repo_name": "horken7/bioloid-cpg", "max_issues_repo_head_hexsha": "d0e16e6699e5f6c19a9b0a6c11fc29798fc2b1d9", "max_issues_repo_licenses": ["MIT"], "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/include/Theory.tex", "max_forks_repo_name": "horken7/bioloid-cpg", "max_forks_repo_head_hexsha": "d0e16e6699e5f6c19a9b0a6c11fc29798fc2b1d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-06T05:47:58.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-06T05:47:58.000Z", "avg_line_length": 74.0603448276, "max_line_length": 689, "alphanum_fraction": 0.7602141776, "num_tokens": 2217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6345182090738453}}
{"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\\_cdp.m} \n\n\\begin{par}\n\\textbf{Summary:} Implements ths ODE for simulating the cart-double pendulum dynamics.\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}  function dz = dynamics_cdp(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                                                    [6 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%   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%         dtheta1:  [rad/s] angular velocity of inner pendulum\n%         dtheta2:  [rad/s] angular velocity of outer pendulum\n%         theta1:   [rad]   angle of inner pendulum\n%         theta2:   [rad]   angle of outer pendulum\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-05\n\nfunction dz = dynamics_cdp(t,z,f)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\n% set up the system\nm1 = 0.5;  % [kg]     mass of cart\nm2 = 0.5;  % [kg]     mass of 1st pendulum\nm3 = 0.5;  % [kg]     mass of 2nd pendulum\nl2 = 0.6;  % [m]      length of 1st pendulum\nl3 = 0.6;  % [m]      length of 2nd pendulum\nb  = 0.1;  % [Ns/m]   coefficient of friction between cart and ground\ng  = 9.82; % [m/s^2]  acceleration of gravity\n\nif nargin == 3\n\n  A = [2*(m1+m2+m3) -(m2+2*m3)*l2*cos(z(5)) -m3*l3*cos(z(6))\n       -(3*m2+6*m3)*cos(z(5)) (2*m2+6*m3)*l2 3*m3*l3*cos(z(5)-z(6))\n       -3*cos(z(6)) 3*l2*cos(z(5)-z(6)) 2*l3];\n  b = [2*f(t)-2*b*z(2)-(m2+2*m3)*l2*z(3)^2*sin(z(5))-m3*l3*z(4)^2*sin(z(6))\n       (3*m2+6*m3)*g*sin(z(5))-3*m3*l3*z(4)^2*sin(z(5)-z(6))\n       3*l2*z(3)^2*sin(z(5)-z(6))+3*g*sin(z(6))];\n  x = A\\b;\n\n  dz = zeros(6,1);\n  dz(1) = z(2);\n  dz(2) = x(1);\n  dz(3) = x(2);\n  dz(4) = x(3);\n  dz(5) = z(3);\n  dz(6) = z(4);\n\nelse\n\n  dz = (m1+m2+m3)*z(2)^2/2+(m2/6+m3/2)*l2^2*z(3)^2+m3*l3^2*z(4)^2/6 ...\n       -(m2/2+m3)*l2*z(2)*z(3)*cos(z(5))-m3*l3*z(2)*z(4)*cos(z(6))/2 ...\n       +m3*l2*l3*z(3)*z(4) *cos(z(5)-z(6))/2+(m2/2+m3)*l2*g*cos(z(5)) ...\n       +m3*l3*g*cos(z(6))/2;\n\n% I2 = m2*l2^2/12;  % moment of inertia around pendulum midpoint (1st link)\n% I3 = m3*l3^2/12;  % moment of inertia around pendulum midpoint (2nd link)\n%\n%\n% dz = m1*z(2)^2/2 + m2/2*(z(2)^2-l2*z(2)*z(3)*cos(z(5))) ...\n%     + m3/2*(z(2)^2 - 2*l2*z(2)*z(3)*cos(z(5)) - l3*z(2)*z(4)*cos(z(6))) ...\n%     + m2*l2^2*z(3)^2/8 + I2*z(3)^2/2 ...\n%     + m3/2*(l2^2*z(3)^2 + l3^2*z(4)^2/4 + l2*l3*z(3)*z(4)*cos(z(5)-z(6))) ...\n%     + I3*z(4)^2/2 ...\n%     + m2*g*l2*cos(z(5))/2 + m3*g*(l2*cos(z(5))+l3*cos(z(6))/2);\n\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "c59d9d09721186a33c04ef8268bd87ba5eb5f8d4", "size": 3215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/dynamics_cdp.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_cdp.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_cdp.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": 30.3301886792, "max_line_length": 86, "alphanum_fraction": 0.5583203733, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6344420947636159}}
{"text": "% !TEX root = ../main.tex\n\\newpage\n\\section*{Nomenclature}\n\\addcontentsline{toc}{subsection}{Nomenclature}\n\\vspace{-.5cm}\n\\begin{alignat*}{2}\n& \\ic &&\\text{Imaginary unit.}\\\\\n&e \\text{ (or} \\exp\\text{)} &&\\text{Euler's number.}\\\\ \\\\\n& n&&\\text{Network node.}\\\\\n& N &&\\text{Network degree. The number of nodes in the network.}\\\\\n& A_{ij} &&\\text{Adjacency matrix. Models which node $i$ is connected to node $j$ and vice-versa.}\\\\\n& \\kmean &&\\text{Average node degree in the network.}\\\\\n& \\degree(n) = \\k &&\\text{Degree of node $n$, as a vector of the in- and out-degree $\\left(\\kin, \\kout \\right)$.}\\\\\n& \\kinb, \\koutb && \\text{Node degree vector of all in- and out degrees of the network.} \\\\\n& M_{\\k} &&\\text{Number of unique node degrees in the network. Cardinality of $\\K$.}\\\\\n& P(k), P(\\k) &&\\text{Univariate and bivariate network degree distribution.}\\\\\n&\\kmin, \\kmax &&\\text{Lowest and highest degree in a network.}\\\\ \n&\\gamma &&\\text{Degree exponent of a scale-free network.}\\\\ \n&p &&\\text{Probability threshold of forming a link in random networks.}\\\\ \\\\\n&\\theta_i(t) &&\\text{Phase variable function of the theta model (of neuron $i$).}\\\\\n& \\Pulse_s (\\theta)&&\\text{Pulse-shaped synaptic coupling function with sharpness } s \\text{.}\\\\\n&\\kappa &&\\text{Macroscopic coupling strength.}\\\\\n&\\eta_i, I_i(t) &&\\text{Excitability threshold and input current (of neuron $i$).}\\\\\n&g(\\eta \\rvert \\k) \\quad &&\\text{Excitability threshold distribution with mean $\\eta_0(\\k)$ and width $\\sigma(\\k)$.}\\\\ \\\\\n& Z(t) &&\\text{Kuramoto order parameter function.}\\\\\n& z(\\k, t) &&\\text{Synchronisation dynamics function for nodes of degree $\\k$.}\\\\\n& \\bar{Z}(t) &&\\text{Mean field order parameter function for arbitrary networks.}\\\\ \\\\\n& S_i^{\\rm in}(t), S_i^{\\rm out}(t)\\quad &&\\text{Spike trains received and emitted by neuron $i$ as a sum of delta functions in time.}\\\\ \n& K_{ij} &&\\text{Coupling matrix. Strength of the synaptic connections between neurons $i$ and $j$.}\\\\\n& \\Delta t_{ij} &&\\text{Time difference between spikes of neurons $i$ and $j$.}\\\\\n& W(t) &&\\text{Learning window. Correlation between change in synaptic strength and spike times.}\\\\ \n& \\phi(t) &&\\text{IP learning function. Correlation between excitability strength and spike times.}\\\\ \\\\\n& \\T &&\\text{Set of angles in [-$\\pi$, $\\pi$[.}\\\\\n& \\K &&\\text{Set of $M_{\\k}$ unique degrees in a network, support of $P$.}\\\\ \n& \\R, \\c &&\\text{Set of real and complex numbers.}\\\\ \n&  \\C && \\text{Set in the complex unit circle so that $\\C = \\{ z \\in \\c : \\: \\rvert z \\rvert \\leq 1 \\} $.} \\\\ \\\\\n& \\permute(v), \\permuteinv(v) &&\\text{Random permutation and inverse permutation of the elements of a vector $v$.}\\\\ \n\\end{alignat*}\n", "meta": {"hexsha": "562688d496113a4a2048335da2886e12d5c4563d", "size": 2679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Frontmatter/Nomenclature.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/Frontmatter/Nomenclature.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/Frontmatter/Nomenclature.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": 68.6923076923, "max_line_length": 137, "alphanum_fraction": 0.6621873834, "num_tokens": 854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6344228446851511}}
{"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{Math 217 -- Geometry and Physics -- Lec06}\n\\author{UCLA, Fall 2014}\n\\date{\\formatdate{15}{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\\maketitle\n\n\n\\section{More stuff}\n\nLet $E^r \\rightarrow M$ be a complex or real vector bundle on a compact closed manifold. \n\n\\begin{definition}\nDefine \n\\begin{eqn}\n\\Gamma(M,E) = \\Gamma(E) = \\set{ s : M \\rightarrow E \\text{ such that } \\pi \\circ s = \\opname{id}_M}.\n\\end{eqn}\n\\end{definition}\n\nFor example, we have\n\\begin{align}\n\\Gamma(T^*M) &= \\set{ \\sum_i f_i dx_i \\text{ on $U_\\alpha$}} \\\\\n\\Gamma(TM) &= \\set{ \\sum_i f_i \\pd{}{x_i} }.\n\\end{align}\n\n\\begin{definition}\nWe define $S^p E$ the symmetric products, $\\Lambda^p E$ the exterior products, and $\\Omega^p(M) = \\Gamma(\\Lambda^p T^*M)$.\n\\end{definition}\n\n\\begin{definition}\nWe define a connection on $E$ as a map\n\\begin{eqn}\n\\nabla : \\Gamma(E) \\rightarrow \\Gamma(T^*M \\otimes E)\n\\end{eqn}\nsuch that\n\\begin{enumerate}\n\\item $\\nabla(s_1 + s_2) = \\nabla s_1 + \\nabla s_2$, and\n\\item $\\nabla(fs) = (\\dif{f}) s + f (\\nabla s)$ for $f \\in C^\\infty (M)$. \n\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}\nWe define the curvature of $\\nabla$ as\n\\begin{eqn}\n\\Omega = \\nabla^2 : \\Gamma(E) \\rightarrow \\Gamma(\\Lambda^2 T^* M \\otimes E).\n\\end{eqn}\n\\end{definition}\n\n\\begin{claim} \n$\\Omega$ is a $C^\\infty(M)$-linear operator (tensor). \n\\end{claim}\n\n\\begin{proof}\nWe have\n\\begin{align}\n\\Omega(fs) &= \\nabla^2 (fs) = \\nabla(\\nabla(fs)) \\\\\n\t&= \\nabla( \\dif{f} \\, s) + \\nabla(f \\nabla s) \\\\\n\t&= [ \\underbrace{\\dif (\\dif{f})}_{=0} s + \\cancel{(-1) \\dif{f} \\nabla s}] + [\\cancel{\\dif{f} \\nabla s} + f \\nabla^2 s] \\\\\n\t&= f \\Omega(s).\n\\end{align}\n\\end{proof}\n\n\\begin{definition}\nGiven a curvature $\\Omega^\\nabla$, we can expand\n\\begin{eqn}\n\\det(t I_r + \\frac{i}{2\\pi} \\Omega^\\nabla) = \\underbrace{c_0^\\nabla(E)}_{1} t^r + \\underbrace{c_1^\\nabla(E)}_\\text{2-form} t^{r-1} + \\dots + \\underbrace{c_r^\\nabla(E)}_\\text{$2r$-form}.\n\\end{eqn}\nWe call $\\set{c_k^\\nabla(E)}$ the Chern forms of $(E,\\nabla)$. \n\\end{definition}\n\n\\begin{theorem}[Chern-Weil]\nLet $M$ be a compact closed manifold, $E$ a complex vector bundle. Then\n\\begin{enumerate}\n\\item $\\dif c_k^\\nabla(E) = 0$, which implies that\n\\item $[c_k^\\nabla(E)] \\in H^{2k}(M)$. Furthermore, $[c_k^\\nabla(E)]$ is independent of $\\nabla$, so we define $c_k(E) = [c_k^\\nabla(E)]$ as the \\textbf{Chern class} of $E$. \n\\end{enumerate}\n\\end{theorem}\n\nWe will see that Chern-Simons follows from Chern-Weil. \n\n\\begin{remark}\nGiven a function with series expansion\n\\begin{align}\nf(x) &= a_0 + a_1 x + \\dots + a_r x^r + \\dots \\in \\C[[x]], \\\\\n\\shortintertext{we have}\nf(\\Omega) &= a_0 I + a_1 \\Omega + \\dots + a_r \\Omega^r \\in \\C[\\Omega],\n\\end{align}\nthus,\n\\begin{eqn}\n\\tr f(\\Omega) = \\sum_{k=0}^n a_k \\tr \\Omega^k.\n\\end{eqn}\n\\end{remark}\n\n\\begin{lemma}\nWe find that\n\\begin{enumerate}\n\\item $\\dif \\tr f(\\Omega) = 0$, and\n\\item if $\\nabla'$ is another connection, then \n\\begin{eqn}\n\\tr f(\\Omega') - \\tr f(\\Omega) = \\dif{\\eta}\n\\end{eqn}\nfor some $\\eta \\in \\Omega^*(M)$.\n\\end{enumerate}\n\\end{lemma}\n\nThis lemma implies Chern-Weil. We also find that\n\\begin{align}\n\\det (I + \\frac{i}{2\\pi} \\Omega) &= \\exp \\tr \\log (I + \\frac{i}{2\\pi} \\Omega) \\\\\n\t&= \\exp \\log \\det (I + \\frac{i}{2\\pi} \\Omega),\n\\end{align}\nfrom the linear algebra identity $\\tr \\log A = \\log \\det A$. \n\n\\begin{remark}\nNow, given\n\\begin{eqn}\n\\omega, \\eta \\in \\Omega^*(M), \\qquad A, B \\in \\Gamma(\\opname{Hom}(E,E)) = \\opname{End}(E),\n\\end{eqn}\nwe have\n\\begin{eqn}\n[\\omega A, \\eta B] = (\\omega A)(\\eta B) - (-1)^{\\deg \\omega \\deg \\eta} (\\eta B) (\\omega A).\n\\end{eqn}\nThen we find\n\\begin{eqn}\n\\tr [\\omega A, \\eta B] = 0.\n\\end{eqn}\n\\end{remark}\n(Show this as an exercise.)\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "262ba0b582bec2fbf347f99ea8b11347e98874fa", "size": 3984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geometry/lec06.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": "geometry/lec06.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": "geometry/lec06.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": 27.6666666667, "max_line_length": 185, "alphanum_fraction": 0.6388052209, "num_tokens": 1538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.6343314246333641}}
{"text": "\\chapter{Ordinals}\n\\label{ch:ordinal}\n\\section{Counting for preschoolers}\nIn preschool, we were told to count as follows.\nWe defined a set of symbols $1$, $2$, $3$, $4$, \\dots.\nThen the teacher would hold up three apples and say:\n\\begin{quote}\n\t``One . . .\\ two . . .\\ three!  There are three apples.''\n\\end{quote}\n\n\\begin{center}\n\t\\includegraphics[height=5cm]{media/three-apples.jpg}\n\t\\\\ \\scriptsize Image from \\cite{img:apples}\n\\end{center}\n\nThe implicit definition is that the \\emph{last} number said is the final answer.\nThis raises some obvious problems if we try to count infinite sets,\nbut even in the finite world,\nthis method of counting fails for the simplest set of all:\nhow many apples are in the following picture?\n\n\\begin{center}\n\t\\includegraphics[height=7cm]{media/velociraptor.jpg}\n\t\\\\ \\scriptsize Image from \\cite{img:velociraptor}\n\\end{center}\n\nAnswer: $0$. There is nothing to say, and our method of counting has failed\nfor the simplest set of all: the empty set.\n\n\\section{Counting for set theorists}\n\\prototype{$\\omega+1 = \\{0,1,2,\\dots,\\omega\\}$ might work.}\nRather than using the \\emph{last} number listed, I propose instead\nstarting with a list of symbols $0$, $1$, $2$, \\dots\\ and making\nthe final answer the \\emph{first} number which was \\emph{not} said.\nThus to count three apples, we would say \n\\begin{quote}\n\t``Zero . . .\\ one . . .\\ two!  There are three apples.''\n\\end{quote}\nWe will call these numbers \\emph{ordinal numbers} (rigorous definition later).\nIn particular, we'll \\emph{define} each ordinal to be the set of things we say:\n\\begin{align*}\n\t0 &= \\varnothing \\\\\n\t1 &= \\{0\\} \\\\\n\t2 &= \\{0,1\\} \\\\\n\t3 &= \\{0,1,2\\} \\\\\n\t&\\vdotswithin=\n\\end{align*}\nIn this way we can write out the natural numbers.\nYou can have some fun with this, by saying things like\n\\[\n\t4 \\defeq\n\t\\left\\{ \n\t\t\\left\\{  \\right\\},\n\t\t\\left\\{ \\left\\{  \\right\\} \\right\\},\n\t\t\\left\\{ \\left\\{  \\right\\}, \\left\\{ \\left\\{  \\right\\} \\right\\} \\right\\},\n\t\t\\left\\{ \n\t\t\t\\left\\{  \\right\\},\n\t\t\t\\left\\{ \\left\\{  \\right\\} \\right\\},\n\t\t\t\\left\\{ \\left\\{  \\right\\}, \\left\\{ \\left\\{  \\right\\} \\right\\} \\right\\}\n\t\t\\right\\}\n\t\\right\\}.\n\\]\nIn this way, we soon write down all the natural numbers.\nThe next ordinal, $\\omega$,\\footnote{As mentioned in the last chapter,\n\tit's not immediate that $\\omega$ is a set;\n\tits existence is generally postulated by the $\\Infinity$ axiom.\n} is defined as\n\\begin{align*}\n\t\\omega &= \\left\\{ 0, 1, 2, \\dots \\right\\} \\\\\n\t\\intertext{Then comes}\n\t\\omega+1 &= \\left\\{ 0, 1, 2, \\dots, \\omega \\right\\} \\\\\n\t\\omega+2 &= \\left\\{ 0, 1, 2, \\dots, \\omega, \\omega+1 \\right\\} \\\\\n\t\\omega+3 &= \\left\\{ 0, 1, 2, \\dots, \\omega, \\omega+1, \\omega+2 \\right\\} \\\\\n\t&\\vdotswithin= \\\\\n\t\\intertext{And in this way we define $\\omega+n$, and eventually reach}\n\t\\omega \\cdot 2 = \\omega+\\omega &= \\left\\{ 0, 1, 2 \\dots, \\omega, \\omega+1, \\omega+2, \\dots \\right\\} \\\\\n\t\\omega \\cdot 2 + 1 &= \\left\\{ 0, 1, 2 \\dots, \\omega, \\omega+1, \\omega+2, \\dots, \\omega \\cdot 2 \\right\\}.\n\\end{align*}\nIn this way we obtain\n\\begin{align*}\n\t0,\\; & 1,\\; 2,\\; 3,\\; \\dots,\\; \\omega \\\\\n\t& \\omega+1,\\; \\omega+2,\\; \\dots,\\; \\omega+\\omega \\\\\n\t& \\omega \\cdot 2 +1,\\; \\omega \\cdot 2 +2,\\; \\dots,\\; \\omega \\cdot 3,\\; \\\\\n\t& \\vdots \\\\\n\t& \\omega^2 + 1,\\; \\omega^2+2,\\; \\dots \\\\\n\t& \\vdots \\\\\n\t& \\omega^3,\\; \\dots,\\; \\omega^4,\\; \\dots,\\; \\omega^\\omega \\\\\n\t& \\vdots \\\\\n\t& \\omega^{\\omega^{\\omega^{\\dots}}} \\\\\n\\end{align*}\n\nThe first several ordinals can be illustrated in a nice spiral.\n\\begin{center}\n\t\\includegraphics[scale=0.60]{media/500px-Omega-exp-omega-labeled.png}\n\\end{center}\n\n\n\\begin{remark}\n\t(Digression)\n\tThe number $\\omega^{\\omega^{\\omega^{\\dots}}}$ has a name, $\\eps_0$;\n\tit has the property that $\\omega^{\\eps_0} = \\eps_0$.\n\tThe reason for using ``$\\eps$'' (which is usually used to denote small quantities)\n\tis that, despite how huge it may appear, it is actually a countable set.\n\tMore on that later.\n\\end{remark}\n\n\\section{Definition of an ordinal}\nOur informal description of ordinals gives us a chain\n\\[ 0 \\in 1 \\in 2 \\in \\dots \\in \\omega \\in \\omega+1 \\in \\dots. \\]\nTo give the actual definition of an ordinal, I need to define two auxiliary terms first.\n\\begin{definition}\n\tA set $x$ is \\vocab{transitive} if whenever $z \\in y \\in x$, we have $z \\in x$ also.\n\\end{definition}\n\\begin{example}\n\t[$7$ is transitive]\n\tThe set $7$ is transitive: for example, $2 \\in 5 \\in 7 \\implies 2 \\in 7$.\n\\end{example}\n\\begin{ques}\n\tShow that this is equivalent to: whenever $y \\in x$, $y \\subseteq x$.\n\\end{ques}\nMoreover, recall the definition of ``well-ordering'': a strict linear order\nwith no infinite descending chains.\n\\begin{example}\n\t[$\\in$ is a well-ordering on $\\omega \\cdot 3$]\n\tIn $\\omega \\cdot 3$, we have an ordering\n\t\\[ 0 \\in 1 \\in 2 \\in \\dots \\in \\omega \\in \\omega+1 \\in \\dots\n\t\t\\in \\omega \\cdot 2 \\in \\omega \\cdot 2 + 1 \\in \\dots. \\]\n\twhich has no infinite descending chains.\n\tIndeed, a typical descending chain might look like\n\t\\[ \\omega \\cdot 2 + 6 \\ni \\omega \\cdot 2 \\ni\n\t\t\\omega + 2015 \\ni \\omega+3 \\ni \\omega \\ni 1000 \\ni 256 \\ni 42 \\ni 7 \\ni 0. \\]\n\tEven though there are infinitely many elements, there is no way\n\tto make an infinite descending chain.\n\\end{example}\n\\begin{exercise}\n\t(Important)\n\tConvince yourself there are no infinite\n\tdescending chains of ordinals at all,\n\twithout using the $\\Foundation$ axiom.\n\\end{exercise}\n\n\\begin{definition}\n\tAn \\vocab{ordinal} is a transitive set which is well-ordered by $\\in$.\n\tThe class of all ordinals is denoted $\\On$.\n\\end{definition}\n\n\\begin{ques}\n\tSatisfy yourself that this definition works.\n\\end{ques}\n\nWe typically use Greek letters $\\alpha$, $\\beta$, etc.\\ for ordinal numbers.\n\\begin{definition}\n\tWe write\n\t\\begin{itemize}\n\t\t\\ii $\\alpha < \\beta$ to mean $\\alpha \\in \\beta$,\n\t\tand $\\alpha > \\beta$ to mean $\\alpha \\ni \\beta$.\n\t\t\\ii $\\alpha \\le \\beta$ to mean $\\alpha \\in \\beta$ or $\\alpha = \\beta$,\n\t\tand $\\alpha \\ge \\beta$ to mean $\\alpha \\ni \\beta$ or $\\alpha = \\beta$,\n\t\\end{itemize}\n\\end{definition}\n\n\\begin{theorem}[Ordinals are strictly ordered]\n\tGiven any two ordinal numbers $\\alpha$ and $\\beta$,\n\teither $\\alpha < \\beta$, $\\alpha = \\beta$ or $\\alpha > \\beta$.\n\\end{theorem}\n\\begin{proof}\n\tSurprisingly annoying, thus omitted.\n\\end{proof}\n\\begin{theorem}[Ordinals represent all order types]\n\tSuppose $<$ is a well-ordering on a set $X$.\n\tThen there exists a unique ordinal $\\alpha$\n\tsuch that there is a bijection $\\alpha \\to X$\n\twhich is order preserving.\n\\end{theorem}\nThus ordinals represent the possible \\emph{equivalence classes} of order types.\nAny time you have a well-ordered set, it is isomorphic to a unique ordinal.\n\nWe now formalize the ``$+1$'' operation we were doing:\n\\begin{definition}\n\tGiven an ordinal $\\alpha$, we let $\\alpha+1 = \\alpha \\cup \\{\\alpha\\}$.\n\tAn ordinal of the form $\\alpha+1$ is called a \\vocab{successor ordinal}.\n\\end{definition}\n\\begin{definition}\n\tIf $\\lambda$ is an ordinal which is neither zero nor a successor ordinal,\n\tthen we say $\\lambda$ is a \\vocab{limit ordinal}.\n\\end{definition}\n\\begin{example}\n\t[Sucessor and limit ordinals]\n\t$7$, $\\omega+3$, $\\omega\\cdot2+2015$ are successor ordinals,\n\tbut $\\omega$ and $\\omega \\cdot 2$ are limit ordinals.\n\\end{example}\n\n\\section{Ordinals are ``tall''}\nFirst, we note that:\n\\begin{theorem}\n\t[There is no set of all ordinals]\n\t$\\On$ is a proper class.\n\\end{theorem}\n\\begin{proof}\n\tAssume for contradiction not.\n\tThen $\\On$ is well-ordered by $\\in$ and transitive, so $\\On$ is an ordinal,\n\ti.e.\\ $\\On \\in \\On$, which violates $\\Foundation$.\n\\end{proof}\n\\begin{exercise}\n\t[Unimportant] Give a proof without $\\Foundation$ by considering $\\On+1$.\n\\end{exercise}\n\nFrom this we deduce:\n\\begin{theorem}\n\t[Sets of ordinals are bounded]\n\tLet $A \\subseteq \\On$.\n\tThen there is some ordinal $\\alpha$ such that $A \\subseteq \\alpha$\n\t(i.e.\\ $A$ must be bounded).\n\\end{theorem}\n\\begin{proof}\n\tOtherwise, look at $\\bigcup A$.\n\tIt is a set.\n\tBut if $A$ is unbounded it must equal $\\On$,\n\twhich is a contradiction.\n\\end{proof}\nIn light of this, every set of ordinals has a \\vocab{supremum},\nwhich is the least upper bound. We denote this by $\\sup A$.\n\n\\begin{ques}\n\tShow that\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\sup (\\alpha+1) = \\alpha$ for any ordinal $\\alpha$.\n\t\t\\ii $\\sup \\lambda = \\lambda$ for any limit ordinal $\\lambda$.\n\t\\end{enumerate}\n\\end{ques}\n\nThe pictorial ``tall'' will be explained in a few sections.\n\n\\section{Transfinite induction and recursion}\nThe fact that $\\in$ has no infinite descending chains means that induction and recursion still work verbatim.\n\\begin{theorem}[Transfinite induction]\n\tGiven a statement $P(-)$, suppose that\n\t\\begin{itemize}\n\t\t\\ii $P(0)$ is true, and\n\t\t\\ii If $P(\\alpha)$ is true for all $\\alpha < \\beta$, then $P(\\beta)$ is true.\n\t\\end{itemize}\n\tThen $P(\\alpha)$ is true for every ordinal $\\alpha$.\n\\end{theorem}\n\\begin{theorem}\n\t[Transfinite recursion]\n\tTo define a sequence $x_\\alpha$ for every ordinal $\\alpha$,\n\tit suffices to\n\t\\begin{itemize}\n\t\t\\ii define $x_0$, then\n\t\t\\ii for any $\\beta$, define $x_\\beta$ for any $\\alpha < \\beta$.\n\t\\end{itemize}\n\\end{theorem}\n\nThe difference between this and normal induction lies in the \\emph{limit ordinals}.\nIn real life, we might only do things like ``define $x_{n+1} = \\dots$''.\nBut this is not enough to define $x_\\alpha$ for all $\\alpha$,\nbecause we can't hit $\\omega$ this way.\nSimilarly, the simple $+1$ doesn't let us hit the ordinal $2\\omega$,\neven if we already have $\\omega+n$ for all $n$.\nIn other words, simply incrementing by $1$ cannot get us past limit stages,\nbut using transfinite induction to jump upwards lets us sidestep this issue.\n\nSo a transfinite induction or recursion is very often broken up into three cases.\nIn the induction phrasing, it looks like\n\\begin{itemize}\n\t\\ii (Zero Case) First, resolve $P(0)$.\n\t\\ii (Successor Case) Show that from $P(\\alpha)$ we can get $P(\\alpha+1)$.\n\t\\ii (Limit Case) For $\\lambda$ a limit ordinal,\n\tshow that $P(\\lambda)$ holds given $P(\\alpha)$ for all $\\alpha < \\lambda$.\n\\end{itemize}\nSimilarly, transfinite recursion often is split into cases too.\n\\begin{itemize}\n\t\\ii (Zero Case) First, define $x_0$.\n\t\\ii (Successor Case) Define $x_{\\alpha+1}$ from $x_\\alpha$.\n\t\\ii (Limit Case) Define $x_\\lambda$ from $x_\\alpha$ for all $\\alpha < \\lambda$,\n\twhere $\\lambda$ is a limit ordinal.\n\\end{itemize}\nIn both situations, finite induction only does the first two cases,\nbut if we're able to do the third case we can climb above the barrier $\\omega$.\n\n\\section{Ordinal arithmetic}\n\\prototype{$1+\\omega=\\omega \\neq \\omega+1$.}\nTo give an example of transfinite recursion, let's define addition of ordinals.\nRecall that we defined $\\alpha+1 = \\alpha \\cup \\{\\alpha\\}$.\nBy transfinite recursion, let\n\\begin{align*}\n\t\\alpha + 0 &= \\alpha \\\\\n\t\\alpha + (\\beta + 1) &= (\\alpha + \\beta) + 1 \\\\\n\t\\alpha + \\lambda &= \\bigcup_{\\beta < \\lambda} (\\alpha + \\beta).\n\\end{align*}\nHere $\\lambda \\neq 0$.\n\nWe can also do this explicitly:\nThe picture is to just line up $\\alpha$ after $\\beta$.\nThat is, we can consider the set\n\\[\n\tX = \n\t\\left( \\left\\{ 0 \\right\\} \\times \\alpha \\right)\n\t\\cup\n\t\\left( \\left\\{ 1 \\right\\} \\times \\beta \\right)\n\\]\n(i.e.\\ we tag each element of $\\alpha$ with a $0$, and\neach element of $\\beta$ with a $1$).\nWe then impose a well-ordering on $X$ by a lexicographic ordering $\\llex$\n(sort by first component, then by second).\nThis well-ordering is isomorphic to a unique ordinal, \n\\begin{example}\n\t[$2+3=5$]\n\tUnder the explicit construction for $\\alpha = 2$ and $\\beta = 3$, we get the set\n\t\\[\n\t\tX = \\left\\{ (0,0) < (0,1) < (1,0) < (1,1) < (1,2) \\right\\}\n\t\\]\n\twhich is isomorphic to $5$.\n\\end{example}\n\n\\begin{example}[Ordinal arithmetic is not commutative]\n\tNote that $1 + \\omega = \\omega$!\n\tIndeed, under the transfinite definition, we have\n\t\\[ 1 + \\omega = \\cup_n (1+n) = 2 \\cup 3 \\cup 4 \\cup \\dots = \\omega. \\]\n\tWith the explicit construction, we have\n\t\\[ X = \\left\\{ (0,0) < (1,0) < (1,1) < (1,2) < \\dots \\right\\} \\]\n\twhich is isomorphic to $\\omega$.\n\\end{example}\n\\begin{exercise}\n\tShow that $n+\\omega = \\omega$ for any $n \\in \\omega$.\n\\end{exercise}\n\n\\begin{remark}\n\tOrdinal addition is not commutative.\n\tHowever, from the explicit construction\n\twe can see that it is at least associative.\n\\end{remark}\n\nSimilarly, we can define multiplication in two ways.\nBy transfinite induction:\n\\begin{align*}\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{align*}\nWe can also do an explicit construction: $\\alpha \\cdot \\beta$\nis the order type of\n\\[ \\llex \\text{ applied to } \\beta \\times \\alpha. \\]\n\\begin{example}[Ordinal multiplication is not commutative]\n\tWe have $\\omega \\cdot 2 = \\omega + \\omega$,\n\tbut $2 \\cdot \\omega = \\omega$.\n\\end{example}\n\\begin{exercise}\n\tProve this.\n\\end{exercise}\n\\begin{exercise}\n\tVerify that ordinal multiplication\n\t(like addition) is associative but not commutative.\n\t(Look at $\\gamma \\times \\beta \\times \\alpha$.)\n\\end{exercise}\n\nExponentiation can also be so defined, though the explicit construction is less natural.\n\\begin{align*}\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{align*}\n\\begin{exercise}\n\tVerify that $2^\\omega = \\omega$.\n\\end{exercise}\n\n\n\\section{The hierarchy of sets}\nWe now define the \\vocab{von Neumann Hierarchy} by transfinite recursion.\n\\begin{definition}\n\tBy transfinite recursion, we set\n\t\\begin{align*}\n\t\tV_0 &= \\varnothing \\\\\n\t\tV_{\\alpha + 1} &= \\PP(V_\\alpha) \\\\\n\t\tV_\\lambda &= \\bigcup_{\\alpha<\\lambda} V_\\alpha\n\t\\end{align*}\n\\end{definition}\nBy transfinite induction, we see $V_\\alpha$ is transitive\nand that $V_\\alpha \\subseteq V_\\beta$ for all $\\alpha < \\beta$.\n\n\\begin{example}[$V_\\alpha$ for $\\alpha \\le 3$]\n\tThe first few levels of the hierarchy are:\n\t\\begin{align*}\n\t\tV_0 &= \\varnothing \\\\\n\t\tV_1 &= \\left\\{ 0 \\right\\} \\\\\n\t\tV_2 &=  \\left\\{ 0, 1 \\right\\} \\\\\n\t\tV_3 &= \\left\\{ 0, 1, 2, \\left\\{ 1 \\right\\} \\right\\}.\n\t\\end{align*}\n\tNotice that for each $n$, $V_n$ consists of only finite sets,\n\tand each $n$ appears in $V_{n+1}$ for the first time.\n\tObserve that\n\t\\[ V_\\omega = \\bigcup_{n \\in \\omega} V_n \\]\n\tconsists only of finite sets; thus $\\omega$ appears for the first time\n\tin $V_{\\omega+1}$.\n\\end{example}\n\\begin{ques}\n\tHow many sets are in $V_5$?\n\\end{ques}\n\n\\begin{definition}\n\tThe \\vocab{rank} of a set $y$, denoted $\\rank(y)$,\n\tis the smallest ordinal $\\alpha$ such that $y \\in V_{\\alpha+1}$.\n\\end{definition}\n\\begin{example}\n\t$\\rank(2) = 2$, and actually $\\rank(\\alpha)=\\alpha$\n\tfor any ordinal $\\alpha$ (problem later).\n\tThis is the reason for the extra ``$+1$''.\n\\end{example}\n\\begin{ques}\n\tShow that $\\rank(y)$ is the smallest ordinal $\\alpha$\n\tsuch that $y \\subseteq V_\\alpha$.\n\\end{ques}\n\nIt's not yet clear that the rank of a set actually exists, so we prove:\n\\begin{theorem}[The von Neumann hierachy is complete]\n\tThe class $V$ is equal to $\\bigcup_{\\alpha \\in \\On} V_\\alpha$.\n\tIn other words, every set appears in some $V_\\alpha$.\n\\end{theorem}\n\\begin{proof}\n\tAssume for contradiction this is false.\n\tThe key is that because $\\in$ satisfies $\\Foundation$,\n\twe can take a $\\in$-minimal counterexample $x$.\n\tThus $\\rank(y)$ is defined for every $y \\in x$,\n\tand we can consider (by $\\Replacement$) the set\n\t\\[ \\left\\{ \\rank(y) \\mid y \\in x \\right\\}. \\]\n\tSince it is a set of ordinals, it is bounded.\n\tSo there is some large ordinal $\\alpha$ such that $y \\in V_\\alpha$\n\tfor all $y \\in x$, i.e.\\ $x \\subseteq V_\\alpha$,\n\tso $x \\in V_{\\alpha+1}$.\n\\end{proof}\n\nThis leads us to a picture of the universe $V$:\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(11cm);\n\t\tpair A = (12,30);\n\t\tpair B = -conj(A);\n\t\tpair M = midpoint(A--B);\n\t\tpair O = origin;\n\t\tMP(\"V\", A, dir(10));\n\t\tdraw(A--O--B);\n\n\t\tfill(A--O--B--cycle, opacity(0.3)+palecyan);\n\n\t\tMP(\"V_0 = \\varnothing\", origin, dir(-20));\n\t\tMP(\"V_1 = \\{\\varnothing\\}\", 0.05*A, dir(0));\n\t\tMP(\"V_2 = \\{\\varnothing, \\{\\varnothing\\} \\}\", 0.10*A, dir(0));\n\n\t\tdraw(MP(\"V_n\", 0.3*A, dir(0))--0.3*B);\n\t\tdraw(MP(\"V_{n+1} = \\mathcal P(V_n)\", 0.35*A, dir(0))--0.35*B);\n\t\tDrawing(\"n\", 0.35*M, dir(45));\n\n\t\tdraw(MP(\"V_\\omega = \\bigcup V_n\", 0.5*A, dir(0))--0.5*B);\n\t\tdraw(MP(\"V_{\\omega+1} = \\mathcal P(V_{\\omega})\", 0.55*A, dir(0))--0.55*B);\n\t\tDrawing(\"\\omega\", 0.55*M, dir(45));\n\t\tdraw(MP(\"V_{\\omega+2} = \\mathcal P(V_{\\omega+1})\", 0.6*A, dir(0))--0.6*B);\n\t\tDrawing(\"\\omega+1\", 0.6*M, dir(45));\n\n\t\tdraw(MP(\"V_{\\omega+\\omega}\", 0.8*A, dir(0))--0.8*B);\n\n\t\tdraw(origin--M);\n\t\tMP(\"\\mathrm{On}\", M, dir(90));\n\n\t\\end{asy}\n\\end{center}\n\nWe can imagine the universe $V$ as a triangle,\nbuilt in several stages or layers,\n$V_0 \\subsetneq V_1 \\subsetneq V_2 \\subsetneq \\dots$.\nThis universe doesn't have a top: but each of the $V_i$ do.\nHowever, the universe has a very clear bottom.\nEach stage is substantially wider than the previous one.\n\nIn the center of this universe are the ordinals:\nfor every successor $V_\\alpha$, exactly one new ordinal appears, namely $\\alpha$.\nThus we can picture the class of ordinals as a thin line\nthat stretches the entire height of the universe.\nA set has rank $\\alpha$ if it appears at the same stage that $\\alpha$ does.\n\n\nAll of number theory, the study of the integers, lives inside $V_\\omega$.\nReal analysis, the study of real numbers, lives inside $V_{\\omega+1}$, since a real number\ncan be encoded as a subset of $\\NN$ (by binary expansion).\nFunctional analysis lives one step past that, $V_{\\omega+2}$.\nFor all intents and purposes, most mathematics does not go beyond $V_{\\omega+\\omega}$.\nThis pales in comparison to the true magnitude of the whole universe.\n\n\\section\\problemhead\n\\begin{problem}\n\tProve that $\\rank(\\alpha) = \\alpha$ for any $\\alpha$\n\tby transfinite induction.\n\\end{problem}\n\n\\begin{problem}\n\t[Online Math Open]\n\tCount the number of transitive sets in $V_5$.\n\\end{problem}\n\n\\begin{problem}\n\t[Goodstein]\n\tLet $a_2$ be any positive integer.\n\tWe define the infinite sequence $a_2$, $a_3$, \\dots recursively as follows.\n\tIf $a_{n} = 0$, then $a_{n+1} = 0$.\n\tOtherwise, we write $a_n$ in base $n$,\n\tthen write all exponents in base $n$, and so on until all\n\tnumbers in the expression are at most $n$.\n\tThen we replace all instances of $n$ by $n+1$\n\t(including the exponents!), subtract $1$,\n\tand set the result to $a_{n+1}$.\n\tFor example, if $a_2 = 11$ we have\n\t\t\\begin{align*}\n\t\t\ta_2 &= 2^{3} + 2 + 1 = 2^{2+1} + 2 + 1 \\\\\n\t\t\ta_3 &= 3^{3+1}+3+1-1 = 3^{3+1} + 3\\\\\n\t\t\ta_4 &= 4^{4+1} + 4 - 1 = 4^{4+1} + 3 \\\\\n\t\t\ta_5 &= 5^{5+1} + 3 - 1 = 5^{5+1} + 2\n\t\t\\end{align*}\n\tand so on. Prove that $a_N = 0$ for some integer $N > 2$.\n\\end{problem}\n", "meta": {"hexsha": "61aebcb956ad7d8135fbd990c5d800ef86fb9f67", "size": 18528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/set-theory/ordinal.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/set-theory/ordinal.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/set-theory/ordinal.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.6994219653, "max_line_length": 109, "alphanum_fraction": 0.6692033679, "num_tokens": 6185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926008, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.634331424107507}}
{"text": "\n\\documentclass[a4paper]{article}\n%\\documentclass[11pt]{article}\n%\\documentclass[12pt]{article}\n%LATEX HEADER\n\n\\ifx\\pdfoutput\\undefined\n% we are running LaTeX, not pdflatex\n\\usepackage{graphicx}\n\\usepackage{overpic}\n\\else\n% we are running pdflatex, so convert .eps files to .pdf\n%\\usepackage[pdftex]{graphicx}\n\\usepackage{graphicx}\n\\usepackage{overpic}\n\\usepackage{epstopdf}\n\\fi \n\n\\usepackage{mathrsfs}\n\\usepackage{color} \n\\usepackage{verbatim}\n\\usepackage{epsfig}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{float}\n\\usepackage{setspace}\n\\usepackage{moreverb}\n\\usepackage{alltt}\n\\usepackage{ulem}\n\\usepackage{amsthm}\n\\usepackage{cancel} \n\\usepackage{verbatim}\n\n\n\n\n\\setlength{\\textwidth}{17cm}\n% for US letter\n%\\setlength{\\textheight}{22.5cm}\n% for A4\n\n\\setlength{\\textheight}{24cm}\n\\setlength{\\parskip}{0.3cm plus 0.1 cm minus 0.1 cm}\n\\setlength{\\oddsidemargin}{-0.5cm}\n\\setlength{\\topmargin}{0.5cm}\n\\setlength{\\headsep}{0cm}\n\\setlength{\\headheight}{0cm}\n\\setlength{\\parindent}{0.5cm}\n% remove extra space at top and bottom of lists\n%\\setlength{\\partopsep}{-2ex}\n\n\n% section,subsection and subsubsection \n% numbering enable\n\\setcounter{secnumdepth}{3}\n\\setcounter{tocdepth}{3}\n\n\\newcommand{\\bit}{\\begin{itemize}}\n\\newcommand{\\eit}{\\end{itemize}}\n\\newcommand{\\bnum}{\\begin{enumerate}}\n\\newcommand{\\enum}{\\end{enumerate}}\n\\newcommand{\\bt}{\\begin{tabular}}\n\\newcommand{\\et}{\\end{tabular}}\n\\newcommand{\\be}{\\begin{equation}}\n\\newcommand{\\ee}{\\end{equation}}\n\\newcommand{\\pdv}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\dv}[2]{\\frac{d #1}{d #2}}\n\\newcommand{\\ds}{\\displaystyle}\n\\newcommand{\\vect}[1]{\\mbox{\\boldmath $#1$}}\n\\newcommand{\\subs}[1]{$_{#1}$}\n\\newcommand{\\sups}[1]{$^{#1}$}\n%\\pagestyle{empty}% no page numbering\n\n%in order to obtain doublspacing put following 2 lines in the\n%preamble and the last line just above the place where the\n%double-spacing should commence.\n\\def\\doublespaced{\\baselineskip=1.5\\normalbaselineskip}\n\\let\\doublespace=\\doublespaced\n\n\\begin{document}\n\n\n% for double spacing\n\\title{\\Huge A Wrapper Class For LAPACK and BLAS }\n% \\Large\n\\date{\\today}\n\\author{Minh Tran\\\\Email: minh.t.tran@adelaide.edu.au}\n\\maketitle\n% %\\tableofcontents\n% %\\clearpage\n\n \n\n\n\n\\section{Introduction} \\label{Introduction}\nThe Matrix class is a wrapper class for LAPACK and BLAS. The class implements matrix solvers and operators typically used in mathematical modelling of physical systems. It is the hope of the author that the class will be useful for anyone working with C++ projects that require matrix operations.\n\n\n\n\\section{Examples} \\label{Examples}\nThe use of class will be demonstrated through examples.\n\n\n \n\n\n\\subsection{Example 1}\n \n\n \n$\\boldsymbol{A}_{1}$ = $\\begin{bmatrix}\n5 &  7 &  6 & 5 \\\\\n7 & 10 &  8 & 7 \\\\\n6 &  8 & 10 & 9 \\\\\n5 &  7 &  9 & 10 \n \\end{bmatrix}$ \\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{b}_{1}$ = $\\begin{bmatrix}\n23 \\\\ \n32 \\\\\n33 \\\\\n31 \n\\end{bmatrix}$\n\n\\vspace{0.5cm}\n\nConsider the system,\n\\begin{equation*}\n\\begin{aligned}\n\\left(5*\\boldsymbol{A}_{1}+\\boldsymbol{A}_{1}*15\\right)  * \\boldsymbol{x}_{1}  = \\boldsymbol{b}_{1}\n\\end{aligned}\n\\end{equation*}\n\n\n\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{x}_{1}  &= \\left(5*\\boldsymbol{A}_{1}+\\boldsymbol{A}_{1}*15\\right)^{-1} * \\boldsymbol{b}_{1} \\\\\n\\boldsymbol{x}_{1}  &= \n\\begin{bmatrix} \n\t\t0.050 \\\\\n\t\t0.050 \\\\\n\t\t0.050 \\\\\n\t\t0.050\n\\end{bmatrix}\n\\end{aligned}\n\\end{equation*}\n\n\n\nBelow are codes to compute $\\boldsymbol{x}_{1}$. The result is stored in the variable \\texttt{example1}.\n\\begin{verbatim} \ndouble A1[] = { 5 ,  7 ,  6 , 5 ,\n                7 , 10 ,  8 , 7 ,\n                6 ,  8 , 10 , 9 ,\n                5 ,  7 ,  9 , 10 };\ndouble b1[] = { 23 , 32 , 33 , 31 };\nMatrix P1(A1,4);   \nMatrix example1 = (5*P1+P1*15) | b1;  \n\\end{verbatim}\n\n\n\n\\subsection{Example 2}\n\n\n$\\boldsymbol{A}_{2}$ = $\\begin{bmatrix}\n0 & 1 & 2 \\\\\n3 & 4 & 5 \\\\ \n6 & 7 & 0 \\\\\n\\end{bmatrix}$ \\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{b}_{2}$ = $\\begin{bmatrix}\n1 \\\\ \n2 \\\\\n3 \\\\ \n\\end{bmatrix}$\n\n\\vspace{0.5cm}\n\nConsider the system,\n\\begin{equation*}\n\\begin{aligned}\n\\left( \\boldsymbol{A}_{2}*\\boldsymbol{A}_{2}*\\boldsymbol{A}_{2} \\right)  * \\boldsymbol{x}_{2}  = \\boldsymbol{b}_{2}\n\\end{aligned}\n\\end{equation*}\n\n\n\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{x}_{2}  &= \\left(\\boldsymbol{A}_{2}*\\boldsymbol{A}_{2}*\\boldsymbol{A}_{2} \\right)^{-1} * \\boldsymbol{b}_{2} \\\\\n\\boldsymbol{x}_{2}  &\\approx \n\\begin{bmatrix} \n-3.088 \\\\\n2.694 \\\\\n-0.569 \\\\\n\\end{bmatrix}\n\\end{aligned}\n\\end{equation*}\n\n\n\nBelow are codes to compute $\\boldsymbol{x}_{2}$. The result is stored in the variable \\texttt{example2}.\n\n\\begin{verbatim}  \ndouble A2[] = { 0 , 1 , 2 ,\n                3 , 4 , 5 , \n                6 , 7 , 0  };\ndouble B2[] = { 1 , 2 , 3 }; \nMatrix P2(A2, 3);\nMatrix example2 = (P2*P2*P2) | B2;  \n\\end{verbatim}\n\n\n \n\n\n\n\n\\subsection{Example 3 \\& 4} \n\n$\\boldsymbol{A}_{3}$ = $\\begin{bmatrix}\n 0 &  1 &  0 & 0\\\\\n-1 &  0 &  1 & 0\\\\ \n 0 & -1 &  0 & 1\\\\\n 0 &  0 & -1 & 0\\\\\n\\end{bmatrix}$ \\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{d}$ = $\\begin{bmatrix}\n1 \\\\ \n2 \\\\\n3 \\\\ \n4 \\\\ \n\\end{bmatrix}$\n\n\\vspace{0.5cm}\n\nConsider the system,\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{A}_{3} * \\boldsymbol{x}_{3}  = \\boldsymbol{d} \n\\end{aligned}\n\\end{equation*}\n\n\n\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{x}_{3}  &=  \\boldsymbol{A}_{3}  ^{-1} * \\boldsymbol{d}  \\\\\n\\boldsymbol{x}_{3}  &\\approx \n\\begin{bmatrix} \n-6 \\\\\n1 \\\\\n-4 \\\\\n4\\\\\n\\end{bmatrix}\n\\end{aligned}\n\\end{equation*}\n\n\n\nBelow are codes to compute $\\boldsymbol{x}_{3}$. The result is stored in the variables \\texttt{example3}. The system for \\texttt{example4} is a similar to  \\texttt{example3}. The main difference is $\\boldsymbol{d}$ is an array and $\\boldsymbol{Q}_{3}$ is a matrix object.\n \n\n\\begin{verbatim}  \ndouble a[] = { -1, -1, -1 };\ndouble b[] = { 0, 0, 0, 0};\ndouble c[] = { 1, 1, 1 };\ndouble d[] = { 1, 2, 3, 4 };\nMatrix Q3(d, 4,1); \nMatrix P3(a,b,c,4); \nMatrix example3 = P3 | d;\nMatrix example4 = P3 | Q3;\n\\end{verbatim}\n\n\n\n\n\n\n\n\n\\subsection{Example 5 \\& 6}\n\nThis example demonstrates the use of pseudo inverse to compute a solution of the system below.\n\n$\\boldsymbol{A}_{5}$ = $\\begin{bmatrix}\n -74 &  80 &  18 & -11 & -4 \\\\\n  14 & -69 &  21 &  28 & 0 \\\\ \n  66 & -72 &  -5 &   7 & 1 \\\\\n -12 &  66 & -30 & -23 & 3 \\\\\n   3 &   8 &  -7 &  -4 & 1 \\\\\n   4 & -12 &   4 &   4 & 0\\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{d}$ = $\\begin{bmatrix}\n51 \\\\\n-61 \\\\\n-56\\\\\n 69\\\\\n 10\\\\\n -12\\\\\n\\end{bmatrix}$\n\n\\vspace{0.5cm}\n\nConsider the system,\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{A}_{5} * \\boldsymbol{x}_{5}  = \\boldsymbol{d} \n\\end{aligned}\n\\end{equation*}\n\n\n\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{x}_{5}  &=  \\boldsymbol{A}_{5}  ^{-1} * \\boldsymbol{d}  \\\\\n\\boldsymbol{x}_{5}  &=\n\\begin{bmatrix} \n1 \\\\\n2 \\\\\n-1 \\\\\n3 \\\\\n-4 \\\\\n\\end{bmatrix}\n\\end{aligned}\n\\end{equation*}\n\n\n\nBelow are codes to compute $\\boldsymbol{x}_{5}$. The result is stored in the variables \\texttt{example5}. The system for \\texttt{example6} is a similar to  \\texttt{example5}. The main difference is $\\boldsymbol{b}_{5}$ is an array and $\\boldsymbol{Q}_{5}$ is a matrix object.\n\n\n\\begin{verbatim}  \ndouble A5[30] = {  -74 ,  80 ,  18 , -11 , -4 ,\n                    14 , -69 ,  21 ,  28 , 0 , \n                    66 , -72 ,  -5 ,   7 , 1 ,\n                   -12 ,  66 , -30 , -23 , 3 ,\n                     3 ,   8 ,  -7 ,  -4 , 1 ,\n                     4 , -12 ,   4 ,   4 , 0};\ndouble b5[6] = { 51 , -61 , -56 , 69 , 10 , -12 };\nMatrix P5(A5,6,5); \nMatrix example5 = P5 | b5;\nMatrix Q5(b5, 6, 1);\nMatrix example6 = P5 | Q5;\n\\end{verbatim}\n\n\n\n\n\n\n\n\n\\subsection{Example 7}\n\nConsider solving the system below,\n\n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x},\\boldsymbol{y}}{\\min} \\hspace{0.2cm} || \\boldsymbol{y} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}  \\boldsymbol{d}_{7} = \\boldsymbol{A}_{7}\\boldsymbol{x} + \\boldsymbol{B}_{7}\\boldsymbol{y}\n\\end{aligned}\n\\end{equation*}\n\n\n\n$\\boldsymbol{A}_{7}$ = $\\begin{bmatrix}\n1 &  2 &  1 & 4  \\\\\n-1 &  1 &  1 & 1  \\\\ \n-1 & -2 & -1 & 1  \\\\ \n-1 &  2 & -1 & -1 \\\\ \n1 &  1 &  1 & 2 \\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{B}_{7}$ = $\\begin{bmatrix}\n1 &  2 & 2 \\\\\n-1 &  1 & -2 \\\\ \n3 &  1 & 6 \\\\\n2 & -2 & 4 \\\\\n1 & -1 & 2\\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm}  \n$\\boldsymbol{d}_{7}$ = $\\begin{bmatrix}\n7.99 \\\\\n0.98 \\\\\n-2.98 \\\\\n3.04 \\\\\n4.02 \\\\\n\\end{bmatrix}$ \n\n\nSolution:\n\n\n$\\boldsymbol{x}$ = $\\begin{bmatrix}\n1.002951 \\\\\n2.001436 \\\\\n-0.987798 \\\\\n0.990908 \\\\\n\\end{bmatrix}$  \n\\hspace{0.5cm} , \\hspace{0.5cm}  \n$\\boldsymbol{y}$ = $\\begin{bmatrix}\n0.003436 \\\\\n-0.004417 \\\\\n0.006871 \\\\\n\\end{bmatrix}$ \n\n\nBelow are codes to compute $\\boldsymbol{x}$ and $\\boldsymbol{y}$. The variable \\texttt{info} is used to flag whether the algorithm is able to obtain a solution to the system.\n\n\n\n\\begin{verbatim} \ndouble *x7 = new double[4];\ndouble *y7 = new double[3];\ndouble A7[] = { 1 ,  2 ,  1 ,  4 ,\n               -1 ,  1 ,  1 ,  1 , \n               -1 , -2 , -1 ,  1 , \n               -1 ,  2 , -1 , -1 , \n                1 ,  1 ,  1 ,  2} ;\ndouble B7[] = { 1 ,  2 ,  2 ,\n               -1 ,  1 , -2 , \n                3 ,  1 ,  6 ,\n                2 , -2 ,  4 ,\n                1 , -1 , 2 };\ndouble d7[] = { 7.99 , 0.98 , -2.98 , 3.04 , 4.02 };\nMatrix P7(A7, B7, d7, 5, 4, 3); \nint info7 = P7.solve(x7,y7); \n\\end{verbatim}\n\n\n\n\n\\subsection{Example 8}\n\n\nConsider solving the system below,\n\n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x}_{8}}{\\min} \\hspace{0.2cm} ||\\boldsymbol{d}_{8} - \\boldsymbol{A}_{8}\\boldsymbol{x}_{8} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}   \\boldsymbol{H}_{8}\\boldsymbol{x}_{8} = \\boldsymbol{f}_{8}\n\\end{aligned}\n\\end{equation*}\n\n\n\n$\\boldsymbol{A}_{8}$ = $\\begin{bmatrix}\n1 &  1 & 1 \\\\ \n1 &  3 & 1 \\\\ \n1 & -1 & 1 \\\\\n1 &  1 & 1 \\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm} \n$\\boldsymbol{d}_{8}$ = $\\begin{bmatrix}\n1 \\\\  \n2 \\\\ \n3 \\\\ \n4\\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm}  \n$\\boldsymbol{H}_{8}$ = $\\begin{bmatrix}\n1 & 1 & 1 \\\\\n1 & 1 & -1 \\\\\n\\end{bmatrix}$ \n\\hspace{0.5cm} , \\hspace{0.5cm}   \n$\\boldsymbol{f}_{8}$ = $\\begin{bmatrix}\n7 \\\\\n4 \\\\\n\\end{bmatrix}$ \n\nSolution:\n\n\n$\\boldsymbol{x}_{8}$ = $\\begin{bmatrix}\n5.75 \\\\\n-0.25 \\\\\n1.5  \\\\\n\\end{bmatrix}$   \n\n\n\nBelow are codes to compute a solution to the system. The variable \\texttt{info} is used to flag whether the algorithm is able to obtain a solution to the system.\n\n\n\n\n\\begin{verbatim}  \ndouble A8[] = { 1 ,  1 , 1 , \n                1 ,  3 , 1 , \n                1 , -1 , 1 , \n                1 ,  1 , 1};\ndouble H8[] = { 1 , 1 , 1 ,\n                1 , 1 , -1 };\ndouble D8[] = { 1 ,  2 , 3 , 4 };\ndouble F8[] = { 7 ,\n4 };\ndouble *x8 = new double[3];\nMatrix P8(A8, D8, H8, F8, 4, 3, 2);\nint info8 = P8.solve(x8);\nprintf(\"\\n X8 = \\n \");\nMatrix::printMatrix(x8,3,1);\n\\end{verbatim}\n\n\n\\section{Constructor}\nBelow is a description of the syntax used to create a single matrix or a matrix system.\n\n\n\\subsection{Create a Single Matrix Object}\n\n\n\n\\subsubsection{\\texttt{Matrix( double Ain[], int nd )}}\n \nThis is used to create a square matrix with dimension of $n_{d}*n_{d}$.\nThe variable $A_{in}$ is an array storing entries of the matrix. The entries are read in row by row. \n\n \n\\subsubsection{\\texttt{Matrix(double Ain[], int nd , int md)}}\n\n\nThis is used to create a general matrix with dimension of $n_{d}*m_{d}$. \nThe variable $A_{in}$ is an array storing entries of the matrix. The entries are read in row by row. \n\n \n\\subsubsection{\\texttt{Matrix(double ain[], double bin[], double cin[], int nd)}}\n\nCreate a tridiagonal matrix with dimension of $n_{d}*n_{d}$.\nThe array $b_{in}$ is the main diagonal with $n_{d}$ number of entries. The array $a_{in}$ is the subdiagonal with $n_{d}-1$ number of entries. The array $c_{in}$ is the superdiagonal  with $n_{d}-1$ number of entries. \n\n\n\\subsubsection{\\texttt{Matrix(double Ain[], int nd, int md, bool isTranspose)}}\n\n\nThis is used to create a general matrix with dimension of $n_{d}*m_{d}$. The variable $A_{in}$ is an array storing entries of the matrix. The entries are read in row by row if \\texttt{isTranspose} is \\texttt{false}. On the other hand, if  \\texttt{isTranspose} is \\texttt{true} entries are read in column by column. \n\n\n\\subsubsection{\\texttt{Matrix(double Ain[], int nd, int md, bool isTranspose, int flag)}}\n\nThis is used to create a general matrix with dimension of $n_{d}*m_{d}$. The variable $A_{in}$ is an array storing entries of the matrix. The entries are read in row by row if \\texttt{isTranspose} is \\texttt{false}. On the other hand, if  \\texttt{isTranspose} is \\texttt{true} entries are read in column by column. The parameter input \\texttt{flag} is used to set the default \\texttt{info}  about the matrix. That is, if \\texttt{flag} = 0, then the matrix is non-singular. It should be noted that \\texttt{info}  is an instance field of the Matrix class.\n\n \n\\subsection{Create a Matrix System}\n\n\n\n\\subsubsection{\\texttt{Matrix(double Ain[], double din[], double Hin[], double fin[], int nd , int md, int pd)}}\n\nThis is used to construct the following matrix system.\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x}}{\\min} \\hspace{0.2cm} ||\\boldsymbol{d} - \\boldsymbol{A}\\boldsymbol{x} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}   \\boldsymbol{H}\\boldsymbol{x} = \\boldsymbol{f}\n\\end{aligned}\n\\end{equation*}\n\nDimension of the matrix: \n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{A} &\\hspace{0.7cm}&& \\text{dimension } n_{d}*m_{d} \\\\\n\\boldsymbol{H} &\\hspace{0.7cm}&& \\text{dimension } p_{d}*m_{d}\\\\\n\\boldsymbol{d} &\\hspace{0.7cm}&& \\text{dimension } n_{d}*1\\\\\n\\boldsymbol{f} &\\hspace{0.7cm}&& \\text{dimension } p_{d}*1\\\\\n\\boldsymbol{x} &\\hspace{0.7cm}&& \\text{dimension } m_{d}*1\\\\\n\\end{aligned}\n\\end{equation*}\n\n\nThe method ``\\texttt{int Matrix::solve(double xinout[])}\" is used to solve the system.\n\n\n\\subsubsection{\\texttt{Matrix(double Ain[], double Bin[], double din[], int nd, int md, int pd)}}\n\n\nThis is used to construct the following matrix system.\n\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x},\\boldsymbol{y}}{\\min} \\hspace{0.2cm} || \\boldsymbol{y} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}  \\boldsymbol{d}  = \\boldsymbol{A} \\boldsymbol{x} + \\boldsymbol{B} \\boldsymbol{y}\n\\end{aligned}\n\\end{equation*}\n\n\nDimension of the matrix: \n\\begin{equation*}\n\\begin{aligned}\n\\boldsymbol{A} &\\hspace{0.7cm}&& \\text{dimension } n_{d}*m_{d} \\\\\n\\boldsymbol{B} &\\hspace{0.7cm}&& \\text{dimension } n_{d}*p_{d} \\\\\n\\boldsymbol{d} &\\hspace{0.7cm}&& \\text{dimension } n_{d}*1 \\\\\n\\boldsymbol{x} &\\hspace{0.7cm}&& \\text{dimension } m_{d}*1 \\\\\n\\boldsymbol{y} &\\hspace{0.7cm}&& \\text{dimension } p_{d}*1 \\\\\n\\end{aligned}\n\\end{equation*}\n \nThe method  ``\\texttt{int Matrix::solve(double xinout[], double yinout[])}'' is used to solve the system.\n\n\n\\section{Methods} \n\n\\subsubsection{\\texttt{int Matrix::solve(double xinout[])}}\n\nThis method is used to solve the system \n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x}}{\\min} \\hspace{0.2cm} ||\\boldsymbol{d} - \\boldsymbol{A}\\boldsymbol{x} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}   \\boldsymbol{H}\\boldsymbol{x} = \\boldsymbol{f}\n\\end{aligned}\n\\end{equation*}\n\nSolution of the system is stored in the array $x_{inout}$.\n\n \n\\subsubsection{\\texttt{int Matrix::solve(double xinout[], double yinout[])}}\n \nThis method is used to solve the system \n \n\n\\begin{equation*}\n\\begin{aligned}\n\\underset{\\boldsymbol{x},\\boldsymbol{y}}{\\min} \\hspace{0.2cm} || \\boldsymbol{y} ||_{2}  \\hspace{0.5cm} \\text{ subject to } \\hspace{0.5cm}  \\boldsymbol{d}  = \\boldsymbol{A} \\boldsymbol{x} + \\boldsymbol{B} \\boldsymbol{y}\n\\end{aligned}\n\\end{equation*}\n\n \n Solution of the system is stored in the array $x_{inout}$ and $y_{inout}$ .\n\n\n\\subsubsection{\\texttt{ void Matrix::printMatrix()}}\n\nThis method is used to print to console all the matrix entries stored in the Matrix object. \n\n\n\\subsubsection{\\texttt{static void Matrix::printMatrix(double input[], int nd, int md)}}\n\nThis method is used to print to console all the matrix entries stored in an array \\texttt{input}. The dimension of the matrix is $n_{d}*m_{d}$.\n\n\n\\section{Operators} \n\t\\begin{tabular}{|c|c|l|} \n\t\t\\hline\n\t\tOperator & Example & Description    \\\\  \n\t\t\\hline\n\t\t+& $\\boldsymbol{A} + \\boldsymbol{B} $ & Adding two matrix object.  \\\\\n\t\t-& $\\boldsymbol{A} - \\boldsymbol{B}$ & Substract two matrix object.  \\\\\n\t\t*&   $c*\\boldsymbol{A}$  &  multiply matrix $\\boldsymbol{A}$ with a scalar $c$  \\\\\n\t\t*& $\\boldsymbol{A}*c$ & multiply matrix $\\boldsymbol{A}$ with a scalar $c$  \\\\\n\t\t*& $\\boldsymbol{A}*\\boldsymbol{B}$ &  multiply matrix two matrix together  \\\\\n\t\t$|$& $\\boldsymbol{A} \\hspace{0.1cm} | \\hspace{0.1cm} \\boldsymbol{b}$ & $\\boldsymbol{b}$ is an array, compute $\\boldsymbol{A}^{-1} \\boldsymbol{b}$.  If  $\\boldsymbol{A}$ is not a square, matrix pseudo inverse is used. \\\\\n\t\t$|$& $\\boldsymbol{A} \\hspace{0.1cm} | \\hspace{0.1cm} \\boldsymbol{B}$  &  $\\boldsymbol{B}$ is matrix, compute $\\boldsymbol{A}^{-1} \\boldsymbol{B}$. If  $\\boldsymbol{A}$ is not a square matrix, pseudo inverse is used. \\\\\n\t\t\\hline\n\t\\end{tabular} \n\n\n\n\n\\end{document}\n\n \n\n\n\n%\\font size\n%   1.  \\tiny\n%   2. \\scriptsize\n%   3. \\footnotesize\n%   4. \\small\n%   5. \\normalsize\n%   6. \\large\n%   7. \\Large\n%   8. \\LARGE\n%   9. \\huge\n%  10. \\Huge ", "meta": {"hexsha": "ea080c430d6a3243f8cfd41cf033952459ccee21", "size": 17320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/BLAS and LAPACK.tex", "max_stars_repo_name": "tran0208/BLAS-And-LAPACK-Wrapper", "max_stars_repo_head_hexsha": "c99ed6c3b92b20c620072cdac16e6020c8d3bc7c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-26T07:51:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-26T07:51:41.000Z", "max_issues_repo_path": "Documentation/BLAS and LAPACK.tex", "max_issues_repo_name": "tran0208/BLAS-And-LAPACK-Wrapper", "max_issues_repo_head_hexsha": "c99ed6c3b92b20c620072cdac16e6020c8d3bc7c", "max_issues_repo_licenses": ["MIT"], "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/BLAS and LAPACK.tex", "max_forks_repo_name": "tran0208/BLAS-And-LAPACK-Wrapper", "max_forks_repo_head_hexsha": "c99ed6c3b92b20c620072cdac16e6020c8d3bc7c", "max_forks_repo_licenses": ["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.3958944282, "max_line_length": 553, "alphanum_fraction": 0.6258083141, "num_tokens": 6420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6343314199988389}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Substitution and Tables}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nVarious exercises relating to substitution and the use of integral tables.\n\\end{abstract}\n\\maketitle\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}%[APEX0601SUBS06]\n\\[ \\int (12 x+14) \\left(3 x^2+7 x-1\\right)^5 dx = \\answer{\\frac{1}{3}(3 x^2+7 x-1)^6}+C \\]\n(Add a constant to your answer if needed so that it equals $1/3$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS11]\n\\[ \\int \\frac{e^{\\sqrt{x}}}{\\sqrt{x}} dx  = \\answer{2 e^{\\sqrt{x}}}+C \\]\n(Add a constant to your answer if needed so that it equals $2$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS09]\n\\[ \\int \\frac{x}{\\sqrt{x+3}} dx  = \\answer{\\frac{2}{3} (x-6) \\sqrt{x+3}}+C\\]\n(Add a constant to your answer if needed so that it equals $0$ at $x=6$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS33]\n\\[ \\int \\frac{\\ln |x|}{x} dx  = \\answer{\\frac{1}{2}\\ln^2 |x|}+C\\]\nRemember absolute value in your logarithm.\n(Add a constant to your answer if needed so that it equals $0$ at $x = 1$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS57]\n\\[ \\int \\sin x \\sqrt{\\cos x} dx =  \\answer{-\\frac{2}{3} \\cos ^{\\frac{3}{2}}(x)}+C\\]\n(Add a constant to your answer if needed so that it equals $-2/3$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS63]\n\\[  \\int \\frac{9 (2 x+3)}{3 x^2+9 x+7} dx = \\answer{3 \\ln \\left|3 x^2+9 x+7\\right|}+C \\]\nUse absolute values as needed in logarithms. (Add a constant to your answer if needed so that it equals $3 \\ln 7$ at $x = 0$.)\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS65]\n\\[ \\int \\frac{x}{x^4+81} dx = \\answer{\\frac{1}{18} \\arctan \\left(\\frac{x^2}{9}\\right)}+C \\]\n(Add a constant to your answer if needed so that it equals $0$ at $x = 0$.)\n\\begin{hint}\nMake a substitution $x^2 = 9 u$.\n\\end{hint}\n%\n%\n\\end{exercise}\n\n\\begin{exercise}%[APEX0601SUBS83]\nEvaluate the definite integral \\(\\displaystyle \\int_{-2}^{-1} (x+1)e^{x^2+2x+1}\\ dx. \\)\n\\begin{center}\n\\begin{prompt}\nValue = \\(\\answer{(1-e)/2}\\)\n\\end{prompt}\n\\end{center}\n%\n%\n\\end{exercise}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%[2016.13]\nEvaluate the integral $\\displaystyle \\int_1^3 \\left( x - \\sqrt{4 x^2 - 8 x + 13} \\right)  dx$ using the fact that $\\displaystyle \\int_0^4 \\sqrt{x^2 + 9} ~ dx =  \\frac{20 + 9 \\ln 3}{2}$.\n(Hints will not be displayed until you have chosen a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle -\\frac{4 + 9 \\ln 3}{6}\\)}\n\\choice[correct]{\\(\\displaystyle -\\frac{4 + 9 \\ln 3}{4}\\)}\n\\choice{\\(\\displaystyle -\\frac{4 + 9 \\ln 3}{2}\\)}\n\\choice{\\(\\displaystyle -4 - 9 \\ln 3\\)}\n\\choice{\\(\\displaystyle -8 - 18 \\ln 3\\)}\n\\choice{\\(\\displaystyle -12 - 27 \\ln 3\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst complete the square:\n\\[ 4 x^2 - 8 x + 13 = 4 x^2 - 8 x + 4 + (13 - 4) = (2x - 2)^2 + 9. \\] \\begin{hint} \nNext substitute $u = 2x-2$ (i.e., $x = \\frac{u}{2} + 1$). Then $du = 2 dx$ and $x=1 \\leftrightarrow u = 0$, $x=3 \\leftrightarrow u = 4$, so\n\\[ \\int_1^3 \\left( x - \\sqrt{4x^2 - 8x + 13} \\right) dx = \\int_0^4 \\left( \\frac{u}{2} + 1 - \\sqrt{u^2 + 9} \\right) \\frac{du}{2}. \\] \\begin{hint}\nNow use linearity of the integral to finish:\n\\[ \\int_0^4 \\frac{u}{4} ~ du + \\int_0^4 \\frac{1}{2} ~ du - \\int_0^4 \\frac{1}{2} \\sqrt{u^2+9} ~ du = \\left. \\frac{u^2}{8} \\right|_0^4 + \\left. \\frac{u}{2} \\right|_0^4 - \\frac{20 + 9 \\ln 3}{4} = 4 - \\frac{20+9 \\ln 3}{4} = - \\frac{4 + 9 \\ln 3}{4}.\\] \\end{hint}\\end{hint}\n\\end{feedback}\n\\end{question}\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "56bbbcd58398934cedfa6e756c9af890b85e15d8", "size": 3724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "techniques/08substitutionpractice.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/08substitutionpractice.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/08substitutionpractice.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": 34.8037383178, "max_line_length": 267, "alphanum_fraction": 0.6299677766, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6341966342746819}}
{"text": "\\section{Model}\n\\label{sec:model}\n\n\\subsection{Model components}\n\nThe core of this term project is to demonstrate the working of the human capital accumulation mechanism in light of demographic transitions. For this, I use a standard overlapping generations model with household heterogeneity by age. Household's maximize discounted lifetime utility from consumption by choosing between consumption, saving and effort invested in human capital accumulation in every model period subject to a budget constraint, borrowing constraint, time constraint and the human capital formation technology.\n\nHuman capital is produced with a technology commonly used in the literature and first introduced by \\cite{Ben-Porath1967}. Human capital next period is a function of the current level of human capital, $h_t$, and the effort exerted to produce additional human capital, $e_t$,\n$$ h_{t+1} = (1-\\delta_h) h_t + \\zeta (e_t h_t)^\\psi$$\nwhere $\\delta_h$ is the depreciation rate on human capital, $\\zeta$ is a scaling factor capturing average learning ability and $\\psi$ is the curvature parameter of the production technology.\n\nThe model features neither idiosyncratic income risk, nor aggregate risk of any kind, i.e. the only risk households are facing is mortality risk. Households are assumed to have perfect foresight regarding survival and idiosyncratic survival risk washes out in the aggregate. Accidental bequests, i.e. asset holdings of deceased households are taxed 100\\% and spent on non-productive government expenditures. The latter is a deviation from the framework in \\citet{LudwigSchelkleVogel2012}, where accidental bequests are redistributed to households via transfers. While altering the budget constraint of households, the  assumption taken for this term paper simplifies computation. In the original framework, income from transfers affects the consumption/ savings/ investment decision and, therefore, the level of accidental bequests. In effect, transfers act as an additional variable (next to aggregate capital, aggregate labor and pension benefits), that needs to be first guessed as input and then verified as results of aggregation. Thus, (wasteful) spending of tax revenue from accidental bequests removes one equlibrium condition.\n\nIn contrast to the original paper by \\cite{LudwigSchelkleVogel2012}, pension benefits are in this paper not linked to income histories. In other words, every retired agent qualifies for the same level of pension benefits. While the level of pension benefits remains an aggregate variable to be solved for by guess and verify, this assumption simplifies computation, as it is no longer necessary to keep track of a households earnings history to calculate pension benefit claims, effectively eliminating a state variable from the household problem. In the specific model used here, the difference is not too material, as in the absence of idiosyncratic risk other than mortality risk, all households of a given age are identical in their earnings history. However, this simplifying assumption becomes truly relevent when introducing idiosyncratic income risk to the model. Pension benefits are thus given by\n$$ b_j = \\begin{cases}\n\t\t\t\t0 \\;\\text{if}\\; j<J^r \\\\\n                \\bar{b} \\;\\text{if}\\; J^r \\leq j \\leq J \\\\\n\t\t\t\\end{cases} $$\n\nIn line with \\citet{LudwigSchelkleVogel2012}, households derive utility from consumption and do not have a bequest motive. Contrasting the original framework, I assume that households do not derive utility from leisure. This, in turn, means that households will use their entire time endowment to either earn income in the labor market or invest in accumulating human capital. While abstracting from the labor-leisure choice, one key margin of adjustment for the household in light of a changing environment is disabled. The remaining trade-off in the labor supply decision solely consists of investing time in earning labor income versus investing time in accumulating / maintaining human capital for higher future productivity. On one hand, this substantially simplifies the computational problem and on the other hand, the labor-leisure trade-off is removed from the analysis, thus making clearer the role of endogenous human capital accumulation.\n\nHouseholds offer capital and labor at competitive markets and earn interest rate $\\bar{r}$ on physical capital and wage rate $\\bar{w}$ on effective labor supply $(1-e_j) z_j$, where $z_j$ is the fixed and exogenous age-dependent labor efficiency multiplier. Moreover, households face a zero borrowing limit and the minimum level of human capital is assumed to be zero (the latter will not be binding during working age due to the assumption on the human capital formation technology). Finally, households take factor prices for capital and labor, as well as the level of pension benefits as given\n\nThe model is closed by a continuum of firms that rent out capital and labor on perfectly competitive input markets and produce the final output good using an identical Cobb-Douglas production function.\n\nThe household optimization problem in the stationary economy is given by\n\\begin{align*}\n    \\max_{\\{c_j, e_j, a_{j+1}, h_{j+1}\\}_{j=0}^J} & \\sum_{j=0}^J \\beta^j \\pi_{j} u(c_j) \\\\\n    \\text{s.t.} \\;  & c_j + a_{j+1} = (1+\\bar{r}) a_j + (1-\\tau) (1-e_j) z_j h_j + b_j \\quad\\text{for}\\; j=0,\\dots,J \\\\\n                    & h_{j+1} = (1-\\delta_h) h_j + \\zeta (e_j h_j)^\\psi \\quad\\text{for}\\; j=0,\\dots,J \\\\\n                    & a_{j+1} \\leq 0 \\quad \\quad\\text{for}\\; j=0,\\dots,J \\\\\n                    & h_{j+1} \\leq 0 \\quad \\quad\\text{for}\\; j=0,\\dots,J \\\\\n                    & e_j \\in [0, 1] \\quad \\quad\\text{for}\\; j=0,\\dots,J \\\\\n                    & a_0, h_0 \\;\\text{given}\n\\end{align*}\n\nThe household problem can be rewritten recursively, which yields an equivalent optimal programming problem given by a set of value functions $\\{V_j(a, h)\\}_{j=0}^J$ defined by\n\\begin{align*}\n    V_j (a, h) = \\max_{ \\{c, e, a', h' \\} } & [ u(c) + \\beta \\pi_{j, j+1} V_{j+1} (a', h') ]  \\\\\n    \\text{s.t.} \\;  & c + a' = (1+\\bar{r}) a + (1-\\tau) (1-e) z_j h + b_j \\\\\n                    & h' = (1-\\delta_h) h + \\zeta (e h)^\\psi \\\\\n                    & a' \\leq 0 \\\\\n                    & h' \\leq 0 \\\\\n                    & e \\in [0, 1]\n\\end{align*}\nfor all $j=0, \\dots, J$. Note that two of the four choice variables $\\{c, e, a', h' \\}$ can be substituted out using the budget constraint and the human capital accumulation equation.\n\n\\subsection{Equilibrium definition}\n\nUsing the reduced recursive characterization of the household problem, a stationary equilibrium in this economy is described by\n\\begin{enumerate}\n    \\item Sets of policy functions for physical and human capital by household age $\\{a'_{j}(a, h), h'_{j}(a, h) \\}_{j=0}^{J}$\n    \\item Factor prices $\\bar{r}, \\bar{w}$ and pension benefit level $\\bar{b}$\n\\end{enumerate}\nsuch that the following conditions hold:\n\\begin{enumerate}\n    \\item The policy functions solve the functional equations of the household problem for all ages $j=0, \\dots, J$\n    \\item Firms behave optimally in every period\n    \\item Government budget balances\n        $$ \\tau \\bar{w} \\sum_{j=0}^{J^r-1} (1 - e_j) h_{j} N_j = \\rho \\sum_{j=J^r}^J N_{j} b_{j} $$\n    \\item Factor markets clear\n        $$ K^D = \\sum_{j=0}^{J} a_j \\quad\\text{and}\\quad L^D = \\sum_{j=0}^{J^r-1} (1 - e_j) z_j $$\n\\end{enumerate}\n\nTo assess the transition from one stationary equilibrium to another, the time dimension is introduced to the model. Population dynamics are no longer assumed to be time invariant and, as a consequence, neither will be factor prices and household policy functions. For further analysis, I first provide an equilibrium definition.\n\n%An equilibrium in the economy with transitional dynamics is given by:\n%\\begin{enumerate}\n%    \\item Sequences of sets of policy functions for physical and human capital by household age and time $\\{ \\{c_{j, t}, a_{j+1, t+1}, h_{j+1, t+1} \\}_{j=0}^{J} \\}_{t=0}^{\\infty}$\n%    \\item Sequences of aggregate variables $\\{L_t, K_{t+1}, Y_t \\}_{t=0}^{\\infty}$\n%    \\item Sequences of factor prices $\\{r_t, w_t \\}_{t=0}^{\\infty}$ and pension benefit levels $\\{b_t\\}_{t=0}^{\\infty}$\n%\\end{enumerate}\n%such that the following conditions hold:\n%\\begin{enumerate}\n%    \\item The policy functions solve the functional equations of the household problem for all ages $j=0, \\dots, J$ and all times $t=0, \\dots$\n%    \\item Firms behave optimally in every period\n%    \\item Government budget balances in every period\n%    \\item Factor markets (labor, capital, and output) clear in every period\n%    \\item The initial state of the economy constitutes a stationary equilibrium\n%    \\item The system converges to a stationary equilibrium, i.e. the limits w.r.t. time $t$ of factor prices and policy functions exist and constitute a stationary equilibrium\n%        constitute\n%\\end{enumerate}\n%\n%The economy with transitional dynamics described above does not have a closed form solution, which means that numerical methods are required to solve it. Thus, for computational reasons, it is not feasible to %solve for the exact equilibrium, which motivates the following definition.\n\nAn equilibrium in the economy with transitional dynamics is given by some finite time $T$ and:\n\\begin{enumerate}\n    \\item Sequences of sets of policy functions for physical and human capital by household age and time $\\{ \\{c_{j, t}, a_{j+1, t+1}, h_{j+1, t+1} \\}_{j=0}^{J} \\}_{t=0}^{T}$\n    \\item Sequences of aggregate variables $\\{L_t, K_{t+1}, Y_t \\}_{t=0}^{T}$\n    \\item Sequences of factor prices $\\{r_t, w_t \\}_{t=0}^{T}$ and pension benefit levels $\\{b_t\\}_{t=0}^{T}$\n\\end{enumerate}\nsuch that the following conditions hold:\n\\begin{enumerate}\n    \\item The policy functions solve the functional equations of the household problem for all ages $j=0, \\dots, J$ and all times $t=0, \\dots$\n    \\item Firms behave optimally in every period\n    \\item Government budget balances in every period\n    \\item Factor markets (labor, capital, and output) clear in every period\n    \\item The initial state (at $t=0$) and the final state (at $t=T$) of the economy approximately constitute a stationary equilibrium\n\\end{enumerate}\nwhere the latter statement is interpreted in a numerical manner, i.e. up to a pre-specified tolerance level for the market clearing conditions.", "meta": {"hexsha": "9c7fff70b396f0420fe6b1295df4f0f4dae6eed4", "size": 10340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/paper/3_model.tex", "max_stars_repo_name": "simonjheiler/demographic_change_olg", "max_stars_repo_head_hexsha": "cd920989bdc7461efab533ea993ba3990bd46b8d", "max_stars_repo_licenses": ["MIT"], "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/paper/3_model.tex", "max_issues_repo_name": "simonjheiler/demographic_change_olg", "max_issues_repo_head_hexsha": "cd920989bdc7461efab533ea993ba3990bd46b8d", "max_issues_repo_licenses": ["MIT"], "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/paper/3_model.tex", "max_forks_repo_name": "simonjheiler/demographic_change_olg", "max_forks_repo_head_hexsha": "cd920989bdc7461efab533ea993ba3990bd46b8d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-16T01:37:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-16T01:37:35.000Z", "avg_line_length": 103.4, "max_line_length": 1135, "alphanum_fraction": 0.7323984526, "num_tokens": 2637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6341077242222961}}
{"text": "\\section{Stochastic Particle Tracing using Particle Filtering}\n\nAs presented above, the particle tracing result of a given seed position $x_0$ for the distribution-based data $\\mathcal{H}$ can be represented as a pdf $p({v_{0:n}}|{\\lambda_{0:n}})$ over the trace domain $\\Omega_{x_0}$, which is given by equation (8). However, $p({v_{0:n}}|{\\lambda_{0:n}})$ is high-dimensional, non-standard, and only known up to a proportionality constant, which makes it infeasible to be evaluated in closed-form. Therefore, a Monte Carlo based method needs to be used to approximate the target distribution. In this case, particle filtering as one of Sequential Monte Carlo methods is suitable to approximate the target distribution in iterations.\n\n\\subsection{Posterior Approximation with Properly Weighted Traces}\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[width=3in]{../figures/importance_sampling.eps}\n  \\caption{Non-weighted and weighted samples representing the probability density function $f(x)$. Fewer samples is needed to represent the target pdf by using weighted samples.}\n  \\label{importance_sampling}\n\\end{figure}\n\nIn order to work with the complicated target posterior density $p({v_{0:n}}|{\\lambda_{0:n}})$, a more convenient representation is needed to approximate it. By applying the particle filtering method, the target posterior density can be represented by a set of properly weighted traces, which are denoted as $\\{ v_{0:n}^i,w_n^i\\} _{i = 1}^{{N_s}}$, where $N_s$ is the number of samples and $ w_n^i,i = 0,...,{N_s} $ are the associated weights. Therefore, we can estimate some statistical properties, for example the mean, variance, and maximum likelihood of the target posterior density from the sample traces. Compared to the non-weighted samples used by the conventional Monte Carlo method, weighted samples can represent the target distribution more efficiently. A comparison between weighted and non-weighted samples is illustrated in Figure~\\ref{importance_sampling}. A common way of drawing properly weighted samples from the target distribution is to use importance sampling, which samples from a trivial distribution $q({v_{0:n}}|{\\lambda_{0:n}})$ called the importance function and assign a weight to each of the random samples according to\n\\begin{equation}\n  w_n = \\frac{{p({v_{0:n}}|{\\lambda_{0:n}})}}{{q({v_{0:n}}|{\\lambda_{0:n}})}}\n\\end{equation}\n\n\\subsection{Sequential Build-Up}\n\nSince the dimension of the target posterior density increases as the number of propagation steps in the particle tracing grows, which makes it difficult to directly obtain the final sample traces with a given step number $n$. By applying particle filtering we smoothly approach the final probability density by building up the sample traces sequentially. To do so, we put ${N_s}$ particles at the seed position $x_0$ and update them iteratively. At each iteration $t$, we have a set of properly weighted samples $\\{ v_{0:t-1}^i,w_{t-1}^i\\} _{i = 1}^{{N_s}}$ which represents the probability density $p({v_{0:t-1}}|{\\lambda_{0:t-1}})$, then each sample can be updated to step $t$ according to the recursive form of the posterior density $p({v_{0:t}}|{\\lambda_{0:t}})$, which can be written as:\n\\begin{equation}\n  p({v_{0:t}}|{\\lambda_{0:t}}) = p({v_{0:t - 1}}|{\\lambda_{0:t - 1}})p(v_t|v_{t-1},\\lambda_t)\n\\end{equation}\nwhere\n\\begin{equation}\n  p(v_t|v_{t-1},\\lambda_t) = \\frac{{p({\\lambda_t}|{v_t})p({v_t}|{v_{t - 1}})}}{{p({\\lambda_t}|{\\lambda_{0:t - 1}})}}\n\\end{equation}\nSince directly sampling vectors from $p(v_t|v_{t-1},\\lambda_t)$ is difficult, we make use of an alternative density function $q({v_t}|{v_{t - 1}},{\\lambda_t})$ which is so-call the importance function presented above. From the importance function, vector directions $v_t$ can be obtained, therefore the weights can be updated according to equation (13). Theoretically, the importance function can be any distribution for the vector direction $v_t$. However, a bad choice of the importance function may produce vector directions which have low probability in the target distribution. Hence, the choice of the importance function will influence the performance of the particle filtering algorithm significantly, which will be detailed in the next section. In order to iteratively update the weights on-line, the importance function is chosen to factorize such that:\n\\begin{equation}\n  q({v_{0:t}}|{\\lambda_{0:t}}) = q({v_{0:t - 1}}|{\\lambda_{0:t - 1}})q({v_t}|{v_{t - 1}},{\\lambda_t})\n\\end{equation}\nAfter getting random vector directions according to the importance density $q({v_t}|{v_{t - 1}},{\\lambda_t})$, the weights $\\{w_t^i\\} _{i = 1}^{{N_s}}$ of traces is updated based on $\\{w_{t-1}^i\\} _{i = 1}^{{N_s}}$. By substituting (14), (16) into (13), we can get the equation to update the weight:\n\\begin{equation}\n  w_t^i = w_{t - 1}^i\\frac{{p({\\lambda_t}|v_t^i)p(v_t^i|v_{t - 1}^i)}}{{q(v_t^i|v_{t - 1}^i,{\\lambda_t})p({\\lambda_t}|{\\lambda_{0:t - 1}})}}\n\\end{equation}\nSince the weights can be normalized by:\n\\begin{equation}\n  w_t^i = \\frac{{w_t^i}}{{\\sum\\limits_{j = 1}^{{N_s}} {w_t^j} }}\n\\end{equation}\nthe normalizing constant ${p({\\lambda_t}|{\\lambda_{0:t - 1}})}$ can be ignored. Therefore, the weight update equation can be simplified as\n\\begin{equation}\n  w_t^i \\propto w_{t - 1}^i\\frac{{p({\\lambda_t}|v_t^i)p(v_t^i|v_{t - 1}^i)}}{{q(v_t^i|v_{t - 1}^i,{\\lambda_t})}}\n\\end{equation}\n\nThe results provided by the particle filtering algorithm for a given seed position is a set of weighted traces which approximate the posterior probability distribution of the possible traces. We directly render them to see the uncertainty of the particle tracing process. With respect to the goal of visualizing the global phenomenon of the vector fields, streamlines originating from different seed positions need to be visualized together, which make it inappropriate to show all the sample traces for a given seed position all the time. To solve this problem, we extract the trace with highest probability based on the posterior density function and visualize all the most likely traces together. The most likely trace is chosen by maximum a posteriori probability (MAP) estimation, which is the trace with the maximal importance weight.\n\n\\subsection{Resampling and Choice of Importance Function}\n\nA common issue with the particle filtering algorithm is the degeneracy problem, which is that after several iterations, some samples will have extremely small weights. This means that the contribution of those samples to the posterior distribution is negligible. A reasonable measurement of degeneracy is the effective sample size $N_{eff}$ introduced in~\\cite{Liu98sequentialmonte}, which can be estimated by\n\\begin{equation}\n  {N_{eff}} = \\frac{1}{{\\sum\\limits_{i = 1}^{{N_s}} {{{(w_t^i)}^2}} }}\n\\end{equation}\nwhere $w_t^i$ is the normalized weight. The value of $N_{eff}$ is between $1$ and $N_s$ and the smaller $N_{eff}$ is, the weights degenerate more. The degeneracy problem is an undesirable effect in particle filters. The brute force approach to reduce this effect is to use a very large sample size, which is often impractical. Hence, we focus on two other methods.\n\n\\textbf{Resampling} The first method is to perform resampling~\\cite{doucet2001sequential, gordon:107} whenever the degeneracy becomes significant (i.e., when $N_{eff}$ is smaller than some hard threshold $N_t$). The key idea of resampling is to remove the traces that have small weights and duplicate the traces which have large weights. To do so, we generate a new set of weighted traces by resampling (with repalcement) $N_s$ times from the given set $\\{ v_{0:t}^i,w_t^i\\} _{i = 1}^{{N_s}}$, making use of the weights $\\{w_t^i\\} _{i = 1}^{{N_s}}$ as the probabilities for a sample to be resampled, then reset the weights to $w_t^i = \\frac{1}{{{N_s}}}$.\n\n\\textbf{Good Choice of Importance Function} The second method is choosing a good importance density $q({v_t}|{v_{t - 1}},{\\lambda_t})$. The optimal importance density function that minimizes the variance of the weights $w_t^i$ conditioned on $v_{t-1}$ and $\\lambda_t$, pointed out by Doucet et al. in~\\cite{Doucet00onsequential}, is $p(v_t|v_{t-1}, \\lambda_t)$. However, this optimal importance density requires the evaluation of the integral over the new state, which makes it difficult to sample efficiently from. Hence, we focus on designing a suboptimal importance density which can be easily sampled from and represents $p(v_t|v_{t-1}, \\lambda_t)$ well. A usual approach is to use the same distribution as the prior density as the importance function, which is called bootstrap filter or condensation algorithm. However, such importance function may not be always effective, since no observation information is used. As a result, the resulting particles are often outliers of the posterior distribution. Therefore, the observation density is used to determine the $v_t$. Since it is expensive to evaluate the observation density function and there is no need to use the actual observation density as the importance density for the particle filtering method, we choose the observed distribution $\\lambda_t$ as the importance density function.\n\n\\subsection{Algorithm Summary}\n\nOur stochastic particle tracing algorithm is summarized in Algorithm~\\ref{algo:pf}.\n\n\\begin{algorithm}[h]\n\\caption{Streamline Estimation with Particle Filtering} \\label{algo:pf}\n\\begin{algorithmic} [1]\n\n\\State Let $x_0$ be a given seed position, $n$ be the number of steps, $N_s$ be the number of samples.\n\\For {$t=0:n$}\n\\For {$i=1:N_s$}\n\\State Sample $v_t^i$ at position $x_t$ according to ${\\lambda_t}$\n\\State Compute weight $w_t^i$ according to (11), (12), and (19)\n\\EndFor\n\\State Normalize the weights $\\{w_t^i\\}_{i=1}^{N_s}$ according to (18)\n\\State Calculate $N_{eff}$ using (20)\n\\If {$N_{eff} < N_t$}\n\\State Resample $\\{ v_{0:t}^i,w_t^i\\} _{i = 1}^{{N_s}}$ to obtain $N_s$ equally-weighted particles $\\{ \\hat{v}_{0:t}^i,\\frac{1}{N_s}\\} _{i = 1}^{{N_s}}$\n\\EndIf\n\\State Propagate $x_t$ to $x_{t+1}$ according to (1)\n\\EndFor\n\n\\end{algorithmic}\n\\end{algorithm}\n", "meta": {"hexsha": "440e4d8182b6ccaa1d24bc4395b7689b0502f345", "size": 10067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/pvis2016/draft-method-pf.tex", "max_stars_repo_name": "hewenbin/pspf", "max_stars_repo_head_hexsha": "d51ac35f2e425d818c5b272c74b3ab9ef01bd5ff", "max_stars_repo_licenses": ["MIT"], "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/pvis2016/draft-method-pf.tex", "max_issues_repo_name": "hewenbin/pspf", "max_issues_repo_head_hexsha": "d51ac35f2e425d818c5b272c74b3ab9ef01bd5ff", "max_issues_repo_licenses": ["MIT"], "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/pvis2016/draft-method-pf.tex", "max_forks_repo_name": "hewenbin/pspf", "max_forks_repo_head_hexsha": "d51ac35f2e425d818c5b272c74b3ab9ef01bd5ff", "max_forks_repo_licenses": ["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.8452380952, "max_line_length": 1346, "alphanum_fraction": 0.7482864806, "num_tokens": 2741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.7122321720225279, "lm_q1q2_score": 0.6340961841905008}}
{"text": "\\subsection{Banach spaces}\\label{subsec:banach_spaces}\n\n\\begin{definition}\\label{def:banach_space}\n  A \\term{Banach space} is a \\hyperref[def:norm]{normed} \\hyperref[def:vector_space]{vector space} which is also a \\hyperref[def:complete_metric_space]{complete metric spaces} with the metric induced by the \\hyperref[def:norm_induced_metric]{norm}.\n\\end{definition}\n\n\\begin{definition}\\label{def:topological_duality_pairing}\n  Let \\( M \\) and \\( N \\) be left \\( R \\)-modules. A \\term{duality pairing} \\( \\inprod \\cdot \\cdot: M \\times N \\to R \\) is a \\hyperref[def:nondegenerate_bilinear_form]{nondegenerate} bilinear form.\n\n  The \\term{canonical duality pairing} of a vector space \\( V \\) over \\( F \\) is\n  \\begin{balign*}\n     & \\inprod \\cdot \\cdot: V^* \\times V \\to F \\\\\n     & \\inprod {x^*} x \\mapsto x^*(x).\n  \\end{balign*}\n\\end{definition}\n\n\\begin{example}\\label{ex:noncomplete_normed_space}\\mcite{MathCounterExamples:noncomplete_normed_space}\n  Consider the polynomial \\hyperref[def:algebra_of_polynomials]{algebra} \\( \\BbbR[x] \\) as a vector space with the supremum norm. We will show that it is not complete. Define the sequence\n  \\begin{equation*}\n    p_n(x) \\coloneqq \\sum_{k=0}^n \\frac{x^k} {2^k}, n = 1, 2, \\ldots\n  \\end{equation*}\n\n  Then the limit of the sequence in \\( C([0, 1]) \\) is the power series\n  \\begin{equation*}\n    \\lim_{n \\to \\infty} p_n(x)\n    =\n    \\sum_{k=0}^n \\frac{x^k} {2^k}\n    =\n    \\frac 2 {2 - x}.\n  \\end{equation*}\n\n  Since \\( \\BbbR[x] \\) is a subspace of \\( C([0, 1]) \\), we conclude that \\( \\BbbR[x] \\) has fundamental sequence, but we just demonstrated that its limit is not in \\( \\BbbR[x] \\).\n\\end{example}\n\n\\begin{definition}\\label{def:dual_norm}\n  Fix two nonempty Banach spaces \\( (X, \\norm{\\cdot}_X) \\) and \\( (Y, \\norm{\\cdot}_Y) \\). We define the \\term{operator norm} \\( \\norm{\\cdot}_{\\hom(X, Y)} \\) on \\( \\hom(X, Y) \\) equivalently as\n  \\begin{thmenum}\n    \\thmitem{def:dual_norm/sup_unit_sphere}\n    \\begin{equation*}\n      \\norm{L}_{\\hom(X, Y)} \\coloneqq \\sup_{\\norm{x}_X = 1} \\norm{Lx}_Y.\n    \\end{equation*}\n\n    \\thmitem{def:dual_norm/sup_unit_ball}\n    \\begin{equation*}\n      \\norm{L}_{\\hom(X, Y)} \\coloneqq \\sup_{\\norm{x}_X < 1} \\norm{Lx}_Y.\n    \\end{equation*}\n\n    \\thmitem{def:dual_norm/sup_nonzero}\n    \\begin{equation*}\n      \\norm{L}_{\\hom(X, Y)} \\coloneqq \\sup_{x \\neq 0_X} \\frac {\\norm{Lx}_Y} {\\norm{x}_X}.\n    \\end{equation*}\n\n    \\thmitem{def:dual_norm/inf}\n    \\begin{equation*}\n      \\norm{L}_{\\hom(X, Y)} \\coloneqq \\inf \\left\\{ c \\geq 0 \\colon \\norm{Lx}_Y \\leq c \\norm{x}_X \\right\\}.\n    \\end{equation*}\n  \\end{thmenum}\n\n  In particular, this induces a norm on \\( X^* \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:banach_space_support_function}\\mcite[exmpl. 3.2(a)]{Phelps1993})\n  Let \\( X \\) be a Banach space.\n\n  We define the \\term{support function \\( \\sigma_{A^*} \\) for the set of functionals \\( A^* \\subseteq X^* \\)} by\n  \\begin{balign*}\n     & \\sigma_{A^*}: X \\to \\BbbR \\cup \\{ \\infty \\}                             \\\\\n     & \\sigma_{A^*}(x) \\coloneqq \\sup \\{ \\inprod {x^*} x \\colon x^* \\in A^* \\}\n  \\end{balign*}\n\n  and the \\term{weak* support function \\( \\sigma^*_A \\) for the set of points \\( A \\subseteq X \\)} by\n  \\begin{balign*}\n     & \\sigma^*_A: X^* \\to \\BbbR \\cup \\{ \\infty \\}                          \\\\\n     & \\sigma^*_A(x^*) \\coloneqq \\sup \\{ \\inprod {x^*} x \\colon x \\in A \\}.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{definition}\\label{def:banach_space_slice}\\mcite[def. 2.17]{Phelps1993}\n  Given a linear functional \\( x^* \\), a nonempty subset \\( A \\) of \\( X \\) and a \\term{diameter} \\( \\alpha > 0 \\), the value \\( S(x^*, A, \\alpha) \\) is called a \\term{slice} of \\( A \\), where\n  \\begin{balign*}\n     & S: X^* \\times \\pow(X) \\times \\BbbR_{>0} \\mapsto \\pow(A)                                      \\\\\n     & S(x^*, A, \\alpha) \\coloneqq \\{ x \\in A \\colon \\inprod {x^*} x > \\sigma_A^*(x^*) - \\alpha \\}.\n  \\end{balign*}\n\n  We define a weak* slice of \\( A^* \\subseteq X^* \\) as \\( S^*(x, A^*, \\alpha) \\), where\n  \\begin{balign*}\n     & S^*: X \\times \\pow(X) \\times \\BbbR_{>0} \\mapsto \\pow(A)                                            \\\\\n     & S^*(x, A^*, \\alpha) \\coloneqq \\{ x^* \\in A^* \\colon \\inprod {x^*} x > \\sigma_{A^*}(x) - \\alpha \\}.\n  \\end{balign*}\n\n  If we need to make the underlying space explicit, we will use \\( S_X(x^*, A, \\alpha) \\) and \\( S_X^*(x, A^*, \\alpha) \\).\n\\end{definition}\n\n\\begin{proposition}\n  If \\( \\{ a_k \\}_{k=1}^\\infty \\) and \\( \\{ b_k \\}_{k=1}^\\infty \\) are sequences a in a \\hyperref[def:banach_space]{Banach} \\hyperref[def:algebra_over_ring]{algebra} \\( X \\), that converge to \\( a \\) and \\( b \\), correspondingly, then \\( a_k b_k \\to a b \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\delta > 0 \\) and let \\( k_0 \\) be an index such that for \\( k \\geq k_0 \\) we have both \\( \\norm{a - a_k} < \\delta \\) and \\( \\norm{b - b_k} < \\delta \\). Then\n  \\begin{balign*}\n    ab - a_k b_k\n     & =\n    (ab - a b_k) + (a b_k - a_k b) + (a_k b - a_k b_k)\n    =    \\\\ &=\n    a (b - b_k) + (a b_k - ab + ab - a_k b) + (-a_k)(b_k - b)\n    =    \\\\ &=\n    a (b - b_k) + a \\underbrace{(b_k - b)} + (a - a_k) b + (-a_k)\\underbrace{(b_k - b)}\n    =    \\\\ &=\n    a \\underbrace{(b - b_k)}_{\\in B(0, \\delta)} + \\underbrace{(a - a_k)}_{\\in B(0, \\delta)} \\underbrace{(b_k - b)}_{\\in B(0, \\delta)} + \\underbrace{(a - a_k)}_{\\in B(0, \\delta)} b.\n  \\end{balign*}\n\n  Therefore, \\( \\norm{ab - a_k b_k} < \\delta^2 + \\norm{a + b} \\delta \\). If we require \\( \\delta \\) to be strictly less than \\( 1 \\), we obtain \\( \\delta^2 < \\delta \\) and \\( \\norm{ab - a_k b_k} < (1 + \\norm{a + b}) \\delta \\).\n\n  Given an arbitrary \\( \\varepsilon > 0 \\), we can choose \\( \\delta = \\tfrac {\\min \\{\\varepsilon, 1 \\}} {1 + \\norm{a + b}} \\) in order to have \\( \\norm{ab - a_k b_k} < \\varepsilon \\) for some large enough \\( k \\).\n\n  Therefore, \\( a_k b_k \\to a b \\).\n\\end{proof}\n", "meta": {"hexsha": "c8ce8cf35677c7124101b547cf0a99b8497a4b12", "size": 5853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/banach_spaces.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/banach_spaces.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/banach_spaces.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": 50.0256410256, "max_line_length": 257, "alphanum_fraction": 0.5803861268, "num_tokens": 2226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290698, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6340773826983523}}
{"text": "\\subsection{SMT-LIB}\n\n\\begin{frame}[fragile]\n  \\frametitle{SMT-LIB (v2) \\url{http://www.smtlib.org}}\n\n  The SMT-LIB initiative \n  \\begin{itemize}\n    \\item defines a standard input language for \\smtsolvers\n    \\item defines theories and logics in which \\formulae can be written\n    \\item collects benchmarks \n  \\end{itemize}\n\n  \\vfill\n  \\pause\n  The SMT-LIB language allows to write \\formulae in a lisp-like format. E.g.:\n  \\begin{verbatim}\n    (< (+ x y) 0)\n    (= (f x y) (g z))\n  \\end{verbatim} \n  stand for $x + y < 0$ and $f(x,y) = g(z)$ respectively\n\n  \\vfill\n  \\pause\n  An SMT-LIB file looks more similar to a {\\bf set of commands} for\n  an \\smtsolver, rather then a logic formula\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{SMT-LIB Theories}\n\n  \\scriptsize\n\n  An SMT-LIB theory consists of some {\\bf sorts}, (e.g., \\SInt) \n  and of some functions (e.g., $-,+$). \n  Predicates are also considered functions, with codomain in \\SBoo\n  (e.g., $<,\\leq$). \\pause For instance\n\n  \\vfill\n  \\begin{tabular}{cc}\n  \\begin{minipage}{.4\\textwidth}\n  \\tiny\n  \\begin{verbatim}\n     (theory Ints\n\n      :sorts ((Int 0))\n     \n      :funs ((NUMERAL Int)\n             (- Int Int)\n             (- Int Int Int :left-assoc)\n             (+ Int Int Int :left-assoc) \n             (* Int Int Int :left-assoc)\n             (div Int Int Int :left-assoc)\n             (mod Int Int Int)\n             (abs Int Int)\n             (<= Int Int Bool :chainable)\n             (<  Int Int Bool :chainable)\n             (>= Int Int Bool :chainable)\n             (>  Int Int Bool :chainable)\n            )\n\n       [...]\n     )\n   \\end{verbatim}\n   \\end{minipage}\n   &\n   \\begin{minipage}{.4\\textwidth}\n     \\tiny\n      \\begin{verbatim}\n      (theory Core\n\n       :sorts ((Bool 0))\n\n       :funs ((true Bool)  \n              (false Bool)\n              (not Bool Bool)\n              (=> Bool Bool Bool :right-assoc)\n              (and Bool Bool Bool :left-assoc)\n              (or Bool Bool Bool :left-assoc)\n              (xor Bool Bool Bool :left-assoc)\n              (par (A) (= A A Bool :chainable))\n              (par (A) (distinct A A Bool :pairwise))\n              (par (A) (ite Bool A A A))\n             )\n\n       [...]\n      )\n      \\end{verbatim}\n      \\end{minipage} \\\\\n    \\multicolumn{2}{c}{\\tiny These definitions can be found at \\url{www.smtlib.org}}\n  \\end{tabular}\n  \\vfill\n  \\pause\n\n  The sorts and the function symbols declared in a theory are always {\\bf interpreted}.\n  This means that a to specify a model for a formula $\\varphi$, we just need to specify \n  the assignment of the variables to the concrete values in the sorts.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{SMT-LIB Logics}\n\n  \\scriptsize\n  The difference between ``logic'' and ``theory'' might look very subtle. \n  An SMT-LIB logic includes a theory definition, plus it describes some\n  restrictions on how \\formulae can be built. \\pause\n\n  \\vfill\n  \\hspace{-25pt}\n  \\begin{tabular}{ccc}\n  \\begin{minipage}{.4\\textwidth}\n    \\tiny\n    \\begin{verbatim}\n    (logic QF_LIA\n     \n     :theories (Ints)\n     \n     :language \n     \"Closed quantifier-free formulas built \n     over an arbitrary expansion of the\n     Ints signature with free constant symbols, \n     but whose terms of sort Int are all linear, \n     that is, have no occurrences of the function \n     symbols *, /, div, mod, and abs, except as \n     specified the :extensions attribute.\n     \"\n      \n     :extensions\n     \"Terms with _concrete_ coefficients are also \n     allowed, that is, terms of the form c, (* c x), \n     or (* x c)  where x is a free constant and c \n     is a term of the form n or (- n) for some numeral n.\n     \"\n    )\n    \\end{verbatim}\n  \\end{minipage}\n  & ~~~~ & \\pause\n  \\begin{minipage}{.4\\textwidth}\n    \\tiny\n    \\begin{verbatim}\n    (logic QF_IDL\n\n     :theories (Ints)\n\n     :language\n     \"Closed quantifier-free formulas with \n     atoms of the form:\n     - q\n     - (op (- x y) n),\n     - (op (- x y) (- n)), or\n     - (op x y)\n     where\n     - q is a variable or free constant symbol of sort Bool,\n     - op is <, <=, >, >=, =, or distinct,\n     - x, y are free constant symbols of sort Int, \n     - n is a numeral. \n     \"\n    )\n    \\end{verbatim}\n  \\end{minipage}\n  \\end{tabular}\n\n  \\vfill\n  \\pause\n\n  In the following we will not be so strict, and we will not make any distinction \n  between ``theories'' and ``logics'', calling both ``theories''. \\pause \n  For instance when we will say that we reason modulo the theory \\Lia we mean \n  that we are working with {\\tt QF\\_LIA} \\formulae\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{Writing an SMT-LIB file} \n  \\scriptsize\n\n  The logic can be specified with the command\n  \\begin{verbatim}\n    (set-logic QF_LIA)\n  \\end{verbatim}\n  \\vfill\n  \\pause\n  Variables are declared with\n  \\begin{verbatim}\n    (declare-fun x ( ) Int)\n  \\end{verbatim}\n  \\vfill\n  \\pause\n  A formula is specified with \n  \\begin{verbatim}\n    (assert (<= (+ x y) 0))\n  \\end{verbatim}\n  \\vfill\n  \\pause\n  Asks the tool to compute satisfiability of assertions\n  \\begin{verbatim}\n    (check-sat)\n  \\end{verbatim}\n  \\vfill\n  \\pause\n  Asks the tool to return a model (in case of sat result)\n  \\begin{verbatim}\n    (set-option :produce-models true)\n    ...\n    (get-value (x y))\n  \\end{verbatim}\n  \\vfill\n  \\pause\n  Disable annoying printouts\n  \\begin{verbatim}\n    (set-option :print-success false)\n  \\end{verbatim}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{Example}\n\n  \\begin{verbatim}\n    (set-logic QF_LIA)\n    (declare-fun x ( ) Int)\n    (declare-fun y ( ) Int)\n    (declare-fun a ( ) Bool)\n    (assert (<= (+ x y) 0))\n    (assert (= x 0))\n    (assert (or (not a) (= x 1) (>= y 0)))\n    (assert (not (= (+ y 1) 0)))\n    (check-sat)\n    (exit)\n  \\end{verbatim} \n\n  which stands for the \\Lia formula\n  $$\n  (x + y \\leq 0) \\wedge (x = 0) \\wedge ((\\neg a \\vee (x = 1) \\vee (y \\geq 0)) \\wedge \\neg(y + 1 = 0)\n  $$\n\n\\end{frame}\n", "meta": {"hexsha": "cd33ba6066b9035af7f42c9c733940504f7918fa", "size": 5925, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture1/smtlib.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/smtlib.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/smtlib.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": 24.7907949791, "max_line_length": 100, "alphanum_fraction": 0.5891983122, "num_tokens": 1848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6340773617489713}}
{"text": "\\section{Multi-armed Bandits}\n\n\\subsection{Exercise 1}\n$1 - \\epsilon = \\frac{1}{2}$.\n\n\\subsection{Exercise 2}\nExploration definitely happened at $t = 2$, since we switched from action 1 to action 2 despite\n$Q_2(1) = 1 > Q_2(2) = 0$. Similarly, exploration also definitely happened at $t = 5$, since at that\npoint action 2 would have been the greedy choice. Depending on how ties are broken during greedy selection,\nit is possible that exploration also happened at  $t = 3$, since at that point actions 1 and 2 would have\nbeen tied.\n\n\\subsection{Exercise 3}\nIntuitively, it seems clear that the $\\epsilon = 0.01$ strategy will perform the best both in terms of\ncumulative reward and probability of selecting the best action over the long run, as it will eventually\nfind the optimal action and choose it 99\\% of the time.\n\nTo put this more quantitatively, we can consider the performance of each of the 3 methods after $N$ trials,\nsuch that $N$ is large enough for the two $\\epsilon > 0$ approaches to have found the optimal action with a\nhigh degree of certainty (we can choose $N$ for any degree of certainty we like, courtesy of the law of\nlarge numbers). After $N$ trials, the probability that the $\\epsilon = 0.1$ strategy selects the best action is\n0.9, whereas for $\\epsilon = 0.01$ the probability is 0.99. For greedy, the probability is either 1 or 0 after\n$N$ trials, since there is no guarantee that it found the optimal action. Since it is unlikely (\\textbf{TODO:}\nmake this more precise) that greedy converged to the optimal action, the expected difference in cumulative\nreward after $N$ trials will quickly grow to favor the $\\epsilon = 0.01$ strategy.\n", "meta": {"hexsha": "039a1f4b27f8b556674d9b0712051200484bc008", "size": 1665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Reinforcement_Learning_Sutton_Barto/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": "Reinforcement_Learning_Sutton_Barto/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": "Reinforcement_Learning_Sutton_Barto/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": 64.0384615385, "max_line_length": 111, "alphanum_fraction": 0.7597597598, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6340307314579325}}
{"text": "\\chapter{Background}\\label{ch:background}\nIn this chapter we provide the background needed for different concepts that are discussed in this thesis. In section \\ref{sec:cnn} we introduce convolutional neural networks and how they are trained. Moreover we define the necessary terminology and provide the mathematical background required to navigate this thesis. Section \\ref{sec:synth} provides the terminology that we use throughout this thesis to describe small parts, synthetic images and real images.\n\n\n\\section{Convolutional Neural Networks}\\label{sec:cnn}\nA \\textbf{neural network} is a massively parallel distributed processor made up of single processing units, which has a natural propensity for storing experiential knowledge and making it available for use \\cite{haykin1994neural}. Convolutional neural networks are a special type of neural network. They are typically used to solve computer vision problems like image classification and object recognition.\n\nRegular neural networks consist of an \\textbf{input layer}, \\textbf{hidden layers} and an \\textbf{output layer}. Every layer is made up of a set of \\textbf{neurons}, where each neuron is fully connected to all neurons in the layer before. A neuron which has an input $x$ of size $n$ calculates the weighted sum $z$ as follows: \\[ z = \\sum_{i=1}^n w_ix_i + b_i \\] where $w$ is called \\textbf{weight} and $b$ is called \\textbf{bias}. The weights and biases of all the neurons in a network are called the network \\textbf{parameters}. Each neuron calculates its output $y$ by applying a differentiable non-linear function $\\varphi(\\cdot)$, called the \\textbf{activation function}, to the weighted sum of its input signals $z$. \\[y = \\varphi(z)\\] A neural networks relays the output of its neurons through a series of hidden layers. Finally, the last fully-connected layer, called the output layer, computes the predictions of the neural network. Figure \\ref{fig:NN} shows an example structure of a regular neural network.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.75\\textwidth]{NN}\n\\caption[A neural network with an input layer, two hidden layers and an output layer. Each neuron is fully connected to all the neurons in the preceding layer.]{A neural network with an input layer, two hidden layers and an output layer. Each neuron is fully connected to all the neurons in the preceding layer.\\footnotemark}\n\\label{fig:NN}\n\\end{figure}\n\\footnotetext{Image: http://cs231n.github.io/convolutional-networks/}\n\nConvolutional neural networks (CNNs) are structured differently. CNNs have 3 types of layers: \\textbf{convolution layers}, \\textbf{pooling layers} and \\textbf{fully connected} layers. Convolution layers slide a weighted matrix (called \\textbf{filter} or \\textbf{kernel}) over the previous layer, and calculate the sum of products. The size of the step that the filter takes while sliding is called a \\textbf{stride}. Figure \\ref{fig:CONV} shows how a convolution layer applies a 3x3 filter to the previous layer. A non-linear activation function is applied to the output of the convolution operation to create a \\textbf{feature map}. It is common to add a pooling layer after the convolution layer for subsampling, which reduces the convolution layer dimensionality. A frequently used type of pooling is \\textbf{max pooling} \\cite{weng1992cresceptron}. Max pooling divides the input layer into sections and computes the maximum activation of each section. Figure \\ref{fig:MP} shows how a max pooling layer applies a 2x2 filter to the preceding layer. Fully connected layers are similar to layers in a regular neural network. Each neuron in a fully connected layer is connected to all neurons in the previous layer.\n\nFigure \\ref{fig:lenet5} shows the LeNet-5 convolutional neural network, which was designed by LeCun et al. \\cite{lecun1998gradient} for handwritten digit recognition. LeNet-5 is an example of a CNN \\textbf{architecture}. A CNN architecture is a set up of different types of layers which are combined to predict the class of the input image.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{CONV}\n\\caption[A 3x3 filter is applied to the source pixel. Each weight in the filter is multiplied by the source's neighboring pixel in the corresponding position. The sum of products is used to calculate the destination pixel's value in the output feature map.]{A 3x3 filter is applied to the source pixel. Each weight in the filter is multiplied by the source's neighboring pixel in the corresponding position. The sum of products is used to calculate the destination pixel's value in the output feature map.\\footnotemark}\n\\label{fig:CONV}\n\\end{figure}\n\\footnotetext{Image: https://towardsdatascience.com/applied-deep-learning-part-4-convolutional-neural-networks-584bc134c1e2}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\textwidth]{MP}\n\\caption[A max-pooling filter of size 2x2 and stride 2 is applied to the source feature map. The maximum value of each filter is used in the destination feature map.]{A max-pooling filter of size 2x2 and stride 2 is applied to the source feature map. The maximum value of each filter is used in the destination feature map.\\footnotemark}\n\\label{fig:MP}\n\\end{figure}\n\\footnotetext{Image: http://cs231n.github.io/convolutional-networks/}\n\n\\begin{figure}[H]\n\\centering\n\\makebox[\\textwidth][c]{\\includegraphics[width=1.3\\textwidth]{lenet5}}\n\\caption[Architecture of the LeNet-5 convolutional neural network.]{Architecture of the LeNet-5 convolutional neural network.\\cite{lecun1989backpropagation}}\n\\label{fig:lenet5}\n\\end{figure}\n\nThe LeNet-5 network uses 3x3 filters with a stride of 1 for convolution layers and 2x2 filters with a stride of 2 for subsampling layers. LeNet-5 uses \\textbf{average pooling}, which calculates the average of the values in the filter.\n\nThe network takes a 32x32 image as input. The first layer is a convolution layer (C1), which applies 6 filters, followed by a subsampling layer (S2). Next comes another convolution layer (C3) which applies 16 filter, followed by a subsampling layer (S4). A final convolution layer (C5) that applies 120 filters follows S4. Afterwards comes a fully connected (F6) layer with 84 neurons. Finally, an output layer of size 10 is connected to F6. Each neuron in the output layer corresponds to the probability of the input image to be one of the 10 digits (0-9).\n\n\\subsection{Training a Convolutional Neural Network}\nWe train a CNN using supervised learning. Supervised learning entails that our network learns from examples. The network is presented with a \\textbf{dataset} of images. The dataset is divided into a \\textbf{training set}, a \\textbf{validation set} and a \\textbf{testing set}. Each set contains images and their corresponding \\textbf{labels} (also referred to as \\textbf{classes}). We train a CNN to predict the labels of images as seen in the training set. The validation set is used for intermediate assessment of the CNN performance during the training phase, while the testing set is used to assess the performance of the CNN after the training phase is done.\n\nCNNs process the training set in \\textbf{mini-batches}. While the use of large mini-batches increases the available computational parallelism, small batch training has been shown to provide improved generalization performance \\cite{masters2018revisiting}. It is also common for CNNs to process the whole training set multiple times. Each single iteration through the training set is called an \\textbf{epoch}. The batch size and number of epochs are examples of CNN \\textbf{hyperparameters}. Hyperparameters are network parameters that are not learnable, but rather optimized manually.\n\nTraining a convolutional neural network is the process of learning the right parameters (filter weights) to compute the correct labels from the input images in the training set. To do so, each CNN has a \\textbf{loss function}. A loss function calculates the error of the predictions made by the CNN. The loss of a CNN which predicts an output \\textit{y} on a training set that has the correct labels $\\hat{y}$ is calculated as follows: \\[L(y, \\hat{y}) = \\dfrac{1}{m}\\sum_{i=1}^m \\mathscr{L}(y_i, \\hat{y}_i)\\] where \\textit{m} is the number of examples in the training set, and $\\mathscr{L}(\\cdot)$ is a distance function that calculates the difference between pairwise instances in $y$ and $\\hat{y}$.\n\nAn \\textbf{optimization function} (or \\textbf{optimizer}) uses \\textbf{back propagation} \\cite{lecun1989backpropagation} to minimize the loss of a CNN during the training phase. The optimizer propagates the output of the loss function backwards by calculating the partial derivative of the loss function with respect to weights and using it to update the values of the weights.\n\nThe \\textbf{stochastic gradient descent (SGD)} optimizer updates the weights of a CNN that uses the loss function $L$ thusly: \\[w_{new}=w_{old}-\\alpha\\dfrac{\\partial L}{\\partial w_{old}}\\] where $\\alpha$ is called the \\textbf{learning rate}. The learning rate controls how fast the weights are updated during training. The learning rate is a tricky hyperparameter to tune. If it is too large, the optimizer might overshoot the optimum parameter values. If it is too small, the optimizer might never reach the optimal value.\n\n\\textbf{Transfer learning} \\cite{pan2010survey} is sometimes employed to speed up the training of convolutional neural networks. Transfer learning involves pre-training a CNN on images from a different domain, and then retraining the network on an image set that is specific to the desired classification task. The advantage of transfer learning is the ability to learn features from a different dataset. This is useful when we have a classification task in one domain of interest, but we only have sufficient training data in another domain. A common technique is to freeze the weights of earlier layers while training a CNN, meaning that the weights are set to be untrainable. The number of \\textbf{frozen layers} is a network hyperparameter.\n\n\n\\section{Small Part Classification}\\label{sec:synth}\nWe describe a system for the automatic classification of \\textbf{small parts} in aircraft engines. Small parts refer to the fasteners used to build the engine like screws, bolts and nuts.\n\nThere is a set of classification challenges that are specific to small parts. A number of small parts can only be separated by subtle distinctions. This difference can be a slight change in size, which means that small parts, unlike scale invariant categories, are sensitive to differences in size, length and width. Figure \\ref{fig:similar_small_parts} shows 2 screws that are identical except for a 6mm difference in length.\n\n\\begin{figure}[h]\n\\centering\n  \\includegraphics[width=0.5\\textwidth]{similar_small_parts}\n\\caption{Screw (a) is identical to screw (b) except that screw (a) is 6mm shorter than screw (b). An overhead light shines on the 2 screws. The reflection changes the natural color of their surface.}\n\\label{fig:similar_small_parts}\n\\end{figure}\n\nAircraft fasteners are metallic and have a shiny surface. The light reflection off the fastener surface disturbs the natural surface color as shown in figure \\ref{fig:similar_small_parts}, and may hide important features. Furthermore, the effect of the light reflection depends on the direction of the light, which may cause variance between images of a single small part.\n\nUnlike cases where the background can provide information, the background is non-informative to the classification of small parts. Additionally, exposure to a regular lighting condition, like an overhead light in a room, causes the fasteners to cast a shadow on their background. A fastener shadow is not a discriminative feature. Both the background and the fastener shadow are a source of noise for the classifier.\n\n\\subsection{Real and Synthetic Images}\nTo automatically classify small parts, we build a convolutional neural network that is trained on both \\textbf{real images} and \\textbf{synthetic images}. We define real images as the natural images of the small parts, taken using a camera. Synthetic images, on the other hand, are artificially created images. They are 2-dimensional renditions of \\textbf{3D models} of small parts. To generate synthetic images, we must create a \\textbf{synthetic scene}: an artificial environment created in 3D modeling software. Figure \\ref{fig:synthetic_scene} shows an example of a synthetic scene. A 3D model is placed in a synthetic scene in 3D modeling software. The software renders a 2D image of the environment to create a synthetic scene.\n\nThe real and synthetic images should capture the small parts and their corresponding 3D models from different angles and in different positions. To do so, we apply \\textbf{transformations} to the small parts and 3D models. There are two types of transformations: \\textbf{translation} to change the position of the target object, and \\textbf{rotation} to change the angle. Each transformation has a range. This prevents the target objects from being translated or rotated away from the camera view.\n\n\\begin{figure}[h]\n\\centering\n  \\includegraphics[width=0.75\\textwidth]{synthetic_scene}\n\\caption{A synthetic scene where a screw lies on a horizontal plane. (a) shows the isometric view of the scene while (b) shows the side view.}\n\\label{fig:synthetic_scene}\n\\end{figure}\n", "meta": {"hexsha": "5fc14eb0812f35cb12912d408a6216983239f679", "size": 13382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2-Background.tex", "max_stars_repo_name": "AmrARaouf/master-thesis", "max_stars_repo_head_hexsha": "9c9bea771d07d17498fd5dd5605cfd47c3707da5", "max_stars_repo_licenses": ["MIT"], "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-Background.tex", "max_issues_repo_name": "AmrARaouf/master-thesis", "max_issues_repo_head_hexsha": "9c9bea771d07d17498fd5dd5605cfd47c3707da5", "max_issues_repo_licenses": ["MIT"], "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-Background.tex", "max_forks_repo_name": "AmrARaouf/master-thesis", "max_forks_repo_head_hexsha": "9c9bea771d07d17498fd5dd5605cfd47c3707da5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 148.6888888889, "max_line_length": 1214, "alphanum_fraction": 0.7978628008, "num_tokens": 3108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.633927766261077}}
{"text": "\n\\subsection{Breaking monoalphabetic substitution ciphers with frequency analysis}\n\n(need to identify algorithm and needs to identify key)\n\nfinding substitution cyphers\n\nSearch space is larger, \\(26!=4*10^26\\). need alternative to brute force.\n\n\nLetter popularity. Compare against popularity for corpus. \nMonogram (ie letters); ngrams(ie n letter in a row frequency); common words.\n\n\nSingle letter words are I or A. More generally. corpus smaller for fewer letters\n\nCan test substitution cypher by matching each word against a corpus\n\n\n", "meta": {"hexsha": "2fd2b976939a27c57a6e8e7b9d67d9c0e1819afc", "size": 536, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/encryptionClassical/04-02-frequency.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/encryptionClassical/04-02-frequency.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/encryptionClassical/04-02-frequency.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.8, "max_line_length": 81, "alphanum_fraction": 0.7910447761, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6338689144321233}}
{"text": "\\chapter{Inequalities}\n\n\\begin{ex}\n  Let $X\\sim\\text{Exponential}(\\beta)$, and recall that $\\mu_X=\\beta$ and\n  $\\sigma^2_X=\\beta^2$. Then, for any $k>1$,\n  \\begin{align*}\n    \\P{|X-\\mu_X|\\geq k\\sigma_X}\n     & =\\P{|X-\\beta|\\geq k\\beta}                                    \\\\\n     & =\\P{X-\\beta\\geq k\\beta}+\\P{X-\\beta\\leq -k\\beta}              \\\\\n     & =\\P{X\\geq (k+1)\\beta}+\\P{X\\leq -(k+1)\\beta}                  \\\\\n     & =\\P{X\\geq (k+1)\\beta}                                        \\\\\n     & =\\int_{(k+1)\\beta}^\\infty \\frac{1}{\\beta}e^{-x/\\beta}\\,\\d{x} \\\\\n     & =\\int_{k+1}^\\infty e^{-u}\\,\\d{u}                             \\\\\n     & =e^{-(k+1)}.\n  \\end{align*}\n\n  The comparable bound obtained from Chebyshev's inequality is\n  \\begin{align*}\n    \\P{|X-\\mu_X|\\geq k\\sigma_X}<\\frac{\\beta^2}{k^2\\beta^2}=\\frac{1}{k^2}.\n  \\end{align*}\n  This is a weaker bound, since it decays quadratically in $k$, instead of\n  exponentially.\n\\end{ex}\n\n\\begin{ex}\n  Let $X\\sim\\text{Poisson}(\\lambda)$. Recall that $\\mu_X=\\lambda$ and\n  $\\sigma_X^2=\\lambda$. Note that\n  \\begin{align*}\n    \\P{|X-\\mu_X|\\geq \\lambda}\n     & =\\P{X-\\lambda\\geq \\lambda}+\\P{X-\\lambda\\leq -\\lambda}     \\\\\n     & =\\P{X\\geq \\lambda + \\lambda}+\\P{X\\leq -\\lambda + \\lambda} \\\\\n     & =\\P{X\\geq 2\\lambda}+\\P{X\\leq 0}                           \\\\\n     & =\\P{X\\geq 2\\lambda}.\n  \\end{align*}\n  However, by Chebyshev's inequality for $t=\\lambda$,\n  \\[\n    \\P{X\\geq 2\\lambda}\n    =\\P{|X-\\mu_X|\\geq \\lambda}\n    \\leq \\frac{1}{\\lambda}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Bernoulli}(p)$. Then\n  \\[\n    \\E{\\overline{X}_n}=\\frac{np}{n}=p,\\quad\n    \\var{\\overline{X}_n}=\\frac{np(p-1)}{n^2}=\\frac{p(p-1)}{n}.\n  \\]\n  Thus, by Chebyshev's inequality,\n  \\[\n    \\P{|\\overline{X}_n-p|>\\epsilon}\n    \\leq \\frac{\\frac{p(p-1)}{n}}{\\epsilon^2}\n    =\\frac{p(p-1)}{n\\epsilon^2}.\n  \\]\n\n  By Theorem 4.5, we also have\n  \\[\n    \\P{|\\overline{X}_n-p|>\\epsilon}\n    \\leq 2e^{-2n\\epsilon^2}.\n  \\]\n\n  Note that the bound from Chebyshev's inequality decays at the rate of $1/n$\n  as $n\\to\\infty$, while the bound from Hoeffding's inequality does so at an\n  exponential rate. Hence, for $n$ sufficiently large, Hoeffding's inequality\n  will provide a tighter bound.\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots X_n\\sim\\text{Bernoulli}(p)$. For any $\\alpha>0$ define\n  \\[\n    \\epsilon_n=\\sqrt{\\frac{1}{2n}\\log\\left(\\frac{2}{\\alpha}\\right)},\n  \\]\n  and let $C_n=(\\widehat{p}_n-\\epsilon_n, \\widehat{p}_n+\\epsilon_n)$.\n  \\begin{enumerate}[(a)]\n    \\item Note that\n          \\begin{align*}\n            \\P{C_n\\text{ contains } p}\n             & =\\P{|\\widehat{p}_n-p|\\leq \\epsilon_n} \\\\\n             & =1-\\P{|\\widehat{p}_n-p|> \\epsilon_n}  \\\\\n             & \\geq 1-2e^{-2n\\epsilon_n^2}           \\\\\n             & =1-2e^{-\\log(2/\\alpha)}               \\\\\n             & =1 - \\alpha.\n          \\end{align*}\n    \\item\n          \\inputminted{python}{../code/04-04b.py}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.9]{../images/04-04b}\n            \\caption{Graph of simulated coverage versus $n$ for $p=0.4$ and\n              $\\alpha=0.05$, with 50,000 simulations per $n$.}\n          \\end{figure}\n    \\item\n          \\inputminted{python}{../code/04-04c.py}\n          \\inputminted{text}{../output/04-04c.txt}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.9]{../images/04-04c}\n            \\caption{Graph of interval width versus $n$ for $\\alpha=0.05$.}\n          \\end{figure}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $Z\\sim N(0, 1)$. Then\n  \\[\n    \\P{|Z|>t}\n    =2\\P{Z>t}\n    =\\sqrt{\\frac{2}{\\pi}}\\frac{e^{-t^2/2}}{t},\n  \\]\n  since\n  \\begin{align*}\n    t\\P{Z>t}\n     & =t\\int_t^\\infty \\frac{1}{\\sqrt{2\\pi}}e^{-x^2/2}\\,\\d{x}    \\\\\n     & \\leq \\int_t^\\infty \\frac{x}{\\sqrt{2\\pi}}e^{-x^2/2}\\,\\d{x} \\\\\n     & =-\\frac{1}{\\sqrt{2\\pi}}e^{-x^2/2}\\bigg\\rvert_{x=t}^\\infty \\\\\n     & =\\frac{1}{\\sqrt{2\\pi}}e^{-t^2/2}.\n  \\end{align*}\n\\end{ex}\n\n\\begin{ex}\n  Let $k\\geq 3$ be an integer. Note that\n  \\begin{align*}\n    \\E{|Z|}\n     & =\\frac{2}{\\sqrt{2\\pi}}\\int_{0}^\\infty\\!xe^{-\\frac{1}{2}x^2}\\,\\d{x}\n    =-\\frac{2}{\\sqrt{2\\pi}}\\int_{0}^\\infty\\!e^{-u}\\,\\d{u}\n    =\\sqrt{\\frac{2}{\\pi}},                                                \\\\\n    \\E{|Z|^2}\n     & =\\E{Z^2}=\\var{Z}+\\E{Z}^2=1,\n  \\end{align*}\n  \\begin{align*}\n    \\E{|Z|^k}\n     & =\\frac{2}{\\sqrt{2\\pi}}\\int_{0}^\\infty\\!x^ke^{-\\frac{1}{2}x^2}\\,\\d{x}                  \\\\\n     & =\\frac{2}{\\sqrt{2\\pi}}\\frac{1}{2}\\int_0^\\infty\\!u^{(k-1)/2}e^{-u/2}\\,\\d{u}            \\\\\n     & =\\frac{2}{\\sqrt{2\\pi}}\\frac{1}{2}\\left[-2e^{-u/2}u^{(k-1)/2}\\bigg\\rvert_{u=0}^\\infty+\n    (k-1)\\int_0^\\infty e^{-u/2}u^{(k-3)/2}\\right]                                            \\\\\n     & =(k-1)\\frac{2}{\\sqrt{2\\pi}}\\frac{1}{2}\\int_0^\\infty e^{-u/2}u^{(k-3)/2}\\,\\d{u}        \\\\\n     & =(k-1)\\E{|Z|^{k-2}},\n  \\end{align*}\n  and that therefore\n  \\[\n    \\E{|Z|^k}=\\begin{cases}\n      \\sqrt{\\frac{2}{\\pi}}(k-1)!! & \\text{if $k$ is odd},  \\\\\n      (k-1)!!                     & \\text{if $k$ is even}.\n    \\end{cases}\n  \\]\n\n  Hence,\n  \\[\n    \\P{|Z|>t}\n    =\\P{|Z|^k>t^k}\n    \\leq \\frac{\\E{|Z|^k}}{t^k}\n    =\\begin{cases}\n      \\sqrt{\\frac{2}{\\pi}}\\frac{(k-1)!!}{t^k} & \\text{if $k$ is odd},  \\\\\n      \\frac{(k-1)!!}{t^k}                     & \\text{if $k$ is even},\n    \\end{cases}\n  \\]\n  or, in particular, $\\P{|Z|>t}<t_0$ for $t_0\\in\\left\\{\n    \\sqrt{\\frac{2}{\\pi}}\\frac{1}{t}, \\frac{1}{t^2}, 2\\sqrt{\\frac{2}{\\pi}}\\frac{1}{t^3},\n    \\frac{3}{t^4}, 8\\sqrt{\\frac{2}{\\pi}}\\frac{1}{t^5}\n    \\right\\}$.\n\n  Likewise, by Mill's inequality,\n  \\[\n    \\P{|Z|>t}\n    \\leq \\sqrt{\\frac{2}{\\pi}}\\frac{e^{-t^2/2}}{t}.\n  \\]\n\n  Finally,\n  \\begin{align*}\n    \\P{|Z|>t}\n    =\\frac{2}{\\sqrt{2\\pi}}\\int_{t}^\\infty\\!e^{-\\frac{1}{2}x^2}\\,\\d{x}\n    =\\erfc\\left(\\frac{t}{\\sqrt{2}}\\right).\n  \\end{align*}\n\n  \\inputminted{python}{../code/04-06.py}\n\n  \\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{../images/04-06}\n    \\caption{Graph of various lower bounds for $\\P{|Z|>t}$.}\n  \\end{figure}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim N(0,1)$. Then $X_1+X_2+\\cdots+X_n\\sim N(0, n)$ and\n  therefore\n  \\[\n    \\sqrt{n}\\cdot \\overline{X}_n=\\frac{\\sqrt{n}}{n}\\left(X_1+X_2+\\cdots+X_n\\right)\n  \\]\n  is a standard normal random variable. Thus, by Mill's inequality,\n  \\[\n    \\P{|\\overline{X}_n|>t}\n    =\\P{|\\sqrt{n}\\cdot \\overline{X}_n|>t\\sqrt{n}}\\leq \\sqrt{\\frac{2}{\\pi}}\\frac{\\exp(-t^2n/2)}{t\\sqrt{n}},\n  \\]\n  while, since $\\overline{X}_n\\sim N(0,1/n)$, by the Chebyshev bound,\n  \\[\n    \\P{|\\overline{X}_n|>t}\\leq \\frac{1}{nt^2}.\n  \\]\n\\end{ex}", "meta": {"hexsha": "f24f044a3f73c3f2d302a544077fc7d5bbba2bbb", "size": 6564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch04.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/ch04.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/ch04.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": 32.6567164179, "max_line_length": 106, "alphanum_fraction": 0.491773309, "num_tokens": 2786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289836, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.6338689032104863}}
{"text": "\\input{../newcommands}\n\nAlthough full PIC codes are powerful tools, which capture a wide range\nof physical phenomena, they also require large computational ressources.\nThis is partly due to the use of a 3D Cartesian grid, which\nleads to a very large number of grid cells. (Typical 3D simulations of\nlaser-wakefield acceleration require $\\sim 10^6$--$ 10^8$ grid\ncells.) For this reason, these algorithms need to be highly parallelized, and\nhigh-resolution simulations can only be run on costly large-scale\ncomputer facilities. However, when the driver is\ncylindrically-symmetric, it is possible to take advantage of the\nsymmetry of the problem to reduce the computational cost of the algorithm \\cite{godfrey1985iprop,LifschitzJCP2009,DavidsonJCP2015,Lehe2016}.\n\n\\subsection{Azimuthal decomposition}\nLet us consider the fields $\\vec{E}$, $\\vec{B}$, $\\vec{J}$ and $\\rho$\n in cylindral coordinates $(r,\\theta,z)$, expressed as a Fourier series in $\\theta$:\n%\n\\begin{equation}\nF(r,\\theta,z) = \\mathrm{Re}\\left[ \\sum_{\\ell=0}^\\infty\n  \\tilde{F}_{\\ell}(r,z) e^{-i\\ell\\theta} \\right]\n\\label{eq:chap2:azimuthal}\n\\end{equation}\n%\n\\begin{equation}\n\\mathrm{with} \\qquad \\tilde{F}_{\\ell} = C_\\ell \\int_0^{2\\pi} d\\theta\n\\,F(r,\\theta,z)e^{i\\ell\\theta} \\qquad\n\\label{eq:chap2:Fourier-coeffs}\n\\end{equation}\n\\begin{equation}\n\\mathrm{and} \\;\n\\left \\{ \\begin{array}{l l}\nC_{0} = 1/2\\pi &\\\\\nC_\\ell = 1/\\pi &\\mathrm{for}\\,\\ell > 0\n\\end{array} \\right.\n\\end{equation}\n%\nwhere $F$ represents any of the quantities $E_r$,\n$E_\\theta$, $E_z$, $B_r$, $B_\\theta$, $B_z$, $J_r$, $J_\\theta$, $J_z$\nare $\\rho$, and where the\n$\\tilde{F}_\\ell$ are the associated Fourier components ($\\ell$ is the\nindex of the corresponding azimuthal mode). In the general case, this\nazimuthal decomposition does not simplify the problem, since an\ninfinity of modes have to be considered in (\\ref{eq:chap2:azimuthal}). However, in the case of a\ncylindrically-symmetric laser pulse, only the very first modes have\nnon-zero components. For instance, the wakefield is represented\nexclusively by the mode $\\ell = 0$. (This is because the quantities $E_r$,\n$E_\\theta$, $E_z$, $B_r$, $B_\\theta$, $B_z$, $J_r$, $J_\\theta$, $J_z$\nand $\\rho$ associated with the\nwakefield are independent of $\\theta$.) On the other hand, the field\nof the laser pulse \\emph{does}\ndepend on $\\theta$, in cylindrical coordinates. For example, for a\ncylindrically-symmetric pulse propagating along $z$ and polarized along $\\vec{e}_\\alpha = \\cos(\\alpha)\\vec{e}_x + \\sin(\\alpha)\\vec{e}_y$:\n%\n\\begin{align}\n\\vec{E} &= E_0(r,z)\\vec{e}_\\alpha \\\\\n& = E_0(r,z) [\\; \\cos(\\alpha)(\\cos(\\theta)\\vec{e}_r - \\sin(\\theta)\\vec{e}_\\theta) \\; \\nonumber \\\\\n& + \\; \\sin(\\alpha)(\\sin(\\theta)\\vec{e}_r + \\cos(\\theta)\\vec{e}_\\theta) \\; ]\\\\\n& = \\mathrm{Re}[ \\; E_0(r,z) e^{i\\alpha} e^{-i\\theta} \\; ]\\vec{e}_r \\; \\nonumber \\\\\n& + \\; \\mathrm{Re}[ \\; -i E_0(r,z) e^{i\\alpha} e^{-i\\theta} \\; ]\\vec{e}_\\theta.\n\\end{align}\n%\nHere the amplitude $E_0$ does not depend on $\\theta$ because the pulse was assumed\nto be cylindrically symmetric. In this case, the above relation shows\nthat the fields $E_r$ and $E_\\theta$ of the laser are represented\nexclusively by the mode $\\ell = 1$. A similar calculation shows that\nthe same holds for $B_r$ and $B_\\theta$. On the whole, only the modes\n$\\ell = 0$ and $\\ell = 1$ are a priori necessary to model\nlaser-wakefield acceleration.\nUnder those conditions, the infinite sum in\n(\\ref{eq:chap2:azimuthal}) is truncated at a chosen $\\ell_{max}$. In\nprinciple, $\\ell_{max} = 1$ is sufficient for laser-wakefield\nacceleration. However, $\\ell_{max}$ is kept as a free parameter in the algorithm, in order to verify that\nhigher modes are negligible, as well as to allow for less-symmetric configurations.\nBecause codes based on this algorithm are able to take into account the modes with $\\ell > 0$, they are said to be\n``quasi-cylindrical'' (or ``quasi-3D'' by some authors \\cite{DavidsonJCP2015}), in contrast to cylindrical codes, which\nassume that all fields are independent of $\\theta$, and thus only\nconsider the mode $\\ell = 0$.\n\n\\subsection{Discretized Maxwell equations} When the Fourier expressions\nof the fields are injected into the Maxwell equations (written in\ncylindrical coordinates), the different azimuthal modes\ndecouple. In this case, the Maxwell-Amp\\`ere and Maxwell-Faraday equations\n-- which are needed to update the fields in the PIC cycle -- can be written separately\nfor each azimuthal mode $\\ell$:\n\\begin{subequations}\n\\begin{align}\n\\frac{\\partial \\tilde{B}_{r,\\ell} }{\\partial t} &=\n\\frac{i\\ell}{r}\\tilde{E}_{z,\\ell} + \\frac{\\partial\n  \\tilde{E}_{\\theta,\\ell}}{\\partial z} \\\\[3mm]\n\\frac{\\partial \\tilde{B}_{\\theta,\\ell} }{\\partial t} &=\n - \\frac{\\partial \\tilde{E}_{r,\\ell}}{\\partial z} + \\frac{\\partial\n  \\tilde{E}_{z,\\ell}}{\\partial r} \\\\[3mm]\n\\frac{\\partial \\tilde{B}_{z,\\ell} }{\\partial t} &=\n- \\frac{1}{r} \\frac{\\partial (r\\tilde{E}_{\\theta,\\ell})}{\\partial r} - \\frac{i\\ell}{r}\\tilde{E}_{r,\\ell} \\\\[3mm]\n\\frac{1}{c^2} \\frac{\\partial \\tilde{E}_{r,\\ell} }{\\partial t} &=\n-\\frac{i\\ell}{r}\\tilde{B}_{z,\\ell} - \\frac{\\partial\n  \\tilde{B}_{\\theta,\\ell}}{\\partial z} - \\mu_0 \\tilde{J}_{r,\\ell} \\\\[3mm]\n\\frac{1}{c^2}\\frac{\\partial \\tilde{E}_{\\theta,\\ell} }{\\partial t} &=\n \\frac{\\partial \\tilde{B}_{r,\\ell}}{\\partial z} - \\frac{\\partial\n  \\tilde{B}_{z,\\ell}}{\\partial r} - \\mu_0 \\tilde{J}_{\\theta,\\ell} \\\\[3mm]\n\\frac{1}{c^2}\\frac{\\partial \\tilde{E}_{z,\\ell} }{\\partial t} &=\n \\frac{1}{r} \\frac{\\partial (r\\tilde{B}_{\\theta,\\ell})}{\\partial r} +\n \\frac{i\\ell}{r}\\tilde{B}_{r,\\ell} - \\mu_0 \\tilde{J}_{z,\\ell}\n\\end{align}\n\\end{subequations}\n%\\begin{figure}\n%\\input{./Chap2/Circ_lattice.tex}\n%\\caption{Representation of the lattice in \\CCirc. The\n%  table shows at which\n%  position each component of the fields is defined ($j$,$k$ and\n%  $n$ are integers ; $\\Delta r$ and $\\Delta z$ are the\n%  spatial steps of the grid). The above sketch represents one grid\n%  cell, and the positions of the fields within it.}\n%\\label{fig:chap2:Circ_lattice}\n%\\end{figure}\nIn order to discretize these equations, each azimuthal mode is\nrepresented on a two-dimensional grid,\n%(The two dimensions correspond\n%to $r$ and $z$.) \\Cref{fig:chap2:Circ_lattice} summarizes the\n%positions of the different fields within one grid cell, as well as the\n%corresponding notations for these fields. Using these notations,\non which the discretized\nMaxwell-Amp\\`ere and Maxwell-Faraday equations are given by\n%\\begin{strip}\n%\\begin{align*}\n%\n%\\frac{ \\tBr{n+\\hf}{j,\\ell,k+\\hf}- \\tBr{n-\\hf}{j,\\ell,k+\\hf}\n%}{\\Delta t} =& \\frac{i\\,\\ell}{j\\Delta r}\\tEz{n}{j,\\ell,k+\\hf} + (D_z \\tilde{E}_{\\theta}^n)_{j,\\ell,k+\\hf} \\\\\n%\n%\\frac{ \\tBt{n+\\hf}{j+\\hf,\\ell,k+\\hf}- \\tBt{n-\\hf}{j+\\hf,\\ell,k+\\hf} }{\\Delta t} =& -(D_z \\tilde{E}_r^n)_{j+\\hf,\\ell,k+\\hf} + (D_r \\tilde{E}_z^{n})_{j+\\hf,\\ell,k+\\hf} \\\\\n%\n%\\frac{ \\tBz{n+\\hf}{j+\\hf,\\ell,k}- \\tBz{n-\\hf}{j+\\hf,\\ell,k} }{\\Delta t} =&\n% -\\frac{(j+1)\\tEt{n}{j+1,\\ell,k} - j\\tEt{n}{j,\\ell,k}}{(j+\\hf)\\Delta r} -\n%\\frac{i\\,\\ell}{(j+\\hf) \\Delta r}\\tEr{n}{j+\\hf,\\ell,k} \\\\\n%\n%\\frac{ \\tEr{n+1}{j+\\hf,\\ell,k}- \\tEr{n}{j+\\hf,\\ell,k}}{c^2 \\Delta t}\n%=& -\\frac{i\\,\\ell}{(j+\\hf)\\Delta r}\\tBz{n+\\hf}{j+\\hf,\\ell,k} - (D_z \\tilde{B}_{\\theta}^{n+\\hf})_{j+\\hf,\\ell,k} - \\mu_0\\tJr{n+\\hf}{j+\\hf,\\ell,k} \\\\\n%\n%\\frac{ \\tEt{n+1}{j,\\ell,k}- \\tEt{n}{j,\\ell,k}}{c^2 \\Delta t}\n%=& (D_z \\tilde{B}_r^{n+\\hf})_{j,\\ell,k} - (D_r \\tilde{B}_z^{n+\\hf})_{j,\\ell,k} - \\mu_0\\tJt{n+\\hf}{j,\\ell,k} \\\\\n%\n%\\frac{ \\tEz{n+1}{j,\\ell,k+\\hf}- \\tEz{n}{j,\\ell,k+\\hf}}{c^2 \\Delta t}\n%=&   \\frac{\\left(j+\\hf\\right)\\tBt{n+\\hf}{j+\\hf,\\ell,k+\\hf}  - \\left(j-\\hf\\right)\\tBt{n+\\hf}{j-\\hf,\\ell,k+\\hf}}{j\\Delta r} \\\\\n%& \\qquad  \\qquad + \\frac{i\\,\\ell}{j\\Delta r}\\tBr{n+\\hf}{j,\\ell,k+\\hf} - \\mu_0\\tJz{n+\\hf}{j,\\ell,k+\\hf}\n%\\end{align*}\n%\\end{strip}\n\n\\begin{subequations}\n\\begin{align}\n%\nD_{t}\\tilde{B}_r|_{j,\\ell,k+\\hf}^{n} \\nonumber\n=& \\frac{i\\,\\ell}{j\\Delta r}\\tEz{n}{j,\\ell,k+\\hf} \\\\\n& + D_z \\tilde{E}_{\\theta}|^n_{j,\\ell,k+\\hf} \\\\\n%\nD_{t}\\tilde{B}_\\theta|_{j+\\hf,\\ell,k+\\hf}^{n} \\nonumber\n=& -D_z \\tilde{E}_r|^n_{j+\\hf,\\ell,k+\\hf} \\\\\n& + D_r \\tilde{E}_z|^{n}_{j+\\hf,\\ell,k+\\hf} \\\\\n%\nD_{t}\\tilde{B}_z|_{j+\\hf,\\ell,k}^{n} =& \\nonumber\n -\\frac{(j+1)\\tEt{n}{j+1,\\ell,k} }{(j+\\hf)\\Delta r} \\\\ \\nonumber\n & +\\frac{ j\\tEt{n}{j,\\ell,k}}{(j+\\hf)\\Delta r} \\\\\n & - \\frac{i\\,\\ell}{(j+\\hf) \\Delta r}\\tEr{n}{j+\\hf,\\ell,k}\n\\end{align}\n\\end{subequations}\nfor the magnetic field components, and\n\\begin{subequations}\n\\begin{align}\n%\n\\frac{1}{c^2}D_{t}\\tilde{E}_r|_{j+\\hf,\\ell,k}^{n+\\hf} \\nonumber\n=& -\\frac{i\\,\\ell}{(j+\\hf)\\Delta r}\\tBz{n+\\hf}{j+\\hf,\\ell,k} \\\\\n& - D_z \\tilde{B}_{\\theta}|^{n+\\hf}_{j+\\hf,\\ell,k} \\nonumber\\\\\n& - \\mu_0\\tJr{n+\\hf}{j+\\hf,\\ell,k} \\\\\n%\n\\frac{1}{c^2}D_{t}\\tilde{E}_\\theta|_{j,\\ell,k}^{n+\\hf} \\nonumber\n=& D_z \\tilde{B}_r|^{n+\\hf}_{j,\\ell,k} - D_r \\tilde{B}_z|^{n+\\hf}_{j,\\ell,k} \\\\\n& - \\mu_0\\tJt{n+\\hf}{j,\\ell,k} \\\\\n%\n\\frac{1}{c^2}D_{t}\\tilde{E}_z|_{j,\\ell,k+\\hf}^{n+\\hf} \\nonumber\n=&   \\frac{\\left(j+\\hf\\right)\\tBt{n+\\hf}{j+\\hf,\\ell,k+\\hf} }{j\\Delta r} \\\\\n=&   -\\frac{\\left(j-\\hf\\right)\\tBt{n+\\hf}{j-\\hf,\\ell,k+\\hf}}{j\\Delta r} \\nonumber\\\\\n& + \\frac{i\\,\\ell}{j\\Delta r}\\tBr{n+\\hf}{j,\\ell,k+\\hf} \\nonumber\\\\\n& - \\mu_0\\tJz{n+\\hf}{j,\\ell,k+\\hf}\n\\end{align}\n\\end{subequations}\nfor the electric field components.\n\nThe numerical operator $D_r$ and $D_z$ are defined by\n\\begin{align*}\n(D_r F)_{j',\\ell,k'} = \\frac{F_{j'+\\hf,\\ell,k'}-F_{j'-\\hf,\\ell,k'} }{\\Delta r} \\\\\n(D_z F)_{j',\\ell,k'} = \\frac{F_{j',\\ell,k'+\\hf}-F_{j',\\ell,k'-\\hf} }{\\Delta z} \\\\\n\\end{align*}\nwhere $j'$ and $k'$ can be integers or half-integers. Notice\nthat these discretized Maxwell equations are not valid on-axis (i.e. for $j=0$), due to\nsingularities in some of the terms. Therefore, on the axis, these equations are replaced by specific boundary conditions, which are based on the symmetry properties of the fields (see \\cite{LifschitzJCP2009} for details).\n\nCompared to a 3D Cartesian calculation with $n_x\\times n_y \\times n_z$\ngrid cells, a quasi-cylindrical calculation with two modes ($l=0$ and $l=1$)\nwill require only $3 \\,n_r \\times n_z$ grid cells. Assuming $n_x=n_y=n_r=100$\nas a typical transverse resolution, a quasi-cylindrical calculation is typically\nover an order of magnitude less computationally demanding than its 3D Cartesian\nequivalent.\n", "meta": {"hexsha": "3bbbf9f8bd96380c8b8ca41255da48a1fbba521e", "size": 10226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Doxygen/pages/latex_theory/Cylindrical/Cylindrical.tex", "max_stars_repo_name": "LukeMcCulloch/PICSAR", "max_stars_repo_head_hexsha": "4c29ad7f923d158137296c6776f01011049075f0", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2020-06-22T17:38:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T17:20:30.000Z", "max_issues_repo_path": "Doxygen/pages/latex_theory/Cylindrical/Cylindrical.tex", "max_issues_repo_name": "LukeMcCulloch/PICSAR", "max_issues_repo_head_hexsha": "4c29ad7f923d158137296c6776f01011049075f0", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-11-03T10:55:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-07T17:00:36.000Z", "max_forks_repo_path": "Doxygen/pages/latex_theory/Cylindrical/Cylindrical.tex", "max_forks_repo_name": "LukeMcCulloch/PICSAR", "max_forks_repo_head_hexsha": "4c29ad7f923d158137296c6776f01011049075f0", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2020-06-23T13:54:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T21:51:38.000Z", "avg_line_length": 50.6237623762, "max_line_length": 221, "alphanum_fraction": 0.6582241346, "num_tokens": 3831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6338688882731429}}
{"text": "\\chapter{Flavors of rings}\nWe continue our exploration of rings by considering\nsome nice-ness properties that rings or ideals can satisfy,\nwhich will be valuable later on.\nAs before, number theory is interlaced as motivation.\nI guess I can tell you at the outset what the completed table\nis going to look like, so you know what to expect.\n\n\\begin{center}\n\t\\begin{tabular}[h]{lll}\n\t\tRing noun & Ideal adjective & Relation \\\\ \\hline\n\t\tPID & principal &\n\t\t\t$R$ is a PID $\\iff$ $R$ is an integral domain, \\\\\n\t\t\t&& \\qquad and every $I$ is principal \\\\\n\t\tNoetherian ring & finitely generated &\n\t\t\t$R$ is Noetherian $\\iff$ every $I$ is fin.\\ gen. \\\\\n\t\tfield & maximal & $R/I$ is a field $\\iff$ $I$ is maximal \\\\\n\t\tintegral domain & prime & $R/I$ is an integral domain\n\t\t\t$\\iff$ $I$ is prime \\\\\n\t\\end{tabular}\n\\end{center}\n\n\\section{Fields}\n\\prototype{$\\QQ$ is a field, but $\\ZZ$ is not.}\n\nWe already saw this definition last chapter:\na field $K$ is a nontrivial ring for which every nonzero element is a unit.\n\nIn particular, there are only two ideals in a field:\nthe ideal $(0)$, which is maximal, and the entire field $K$.\n\n\\section{Integral domains}\n\\prototype{$\\ZZ$ is an integral domain.}\n\nIn practice, we are often not so lucky that we have a full-fledged field.\nNow it would be nice if we could still conclude the zero product property:\nif $ab = 0$ then either $a = 0$ or $b = 0$.\nIf our ring is a field, this is true: if $b \\neq 0$,\nthen we can multiply by $b\\inv$ to get $a = 0$.\nBut many other rings we consider like $\\ZZ$ and $\\ZZ[x]$ also have this property,\ndespite not having division.\n\nNot all rings though: in $\\Zc{15}$,\n\\[ 3 \\cdot 5 \\equiv 0 \\pmod{15}. \\]\nIf $a, b \\neq 0$ but $ab=0$ then we say $a$ and $b$ are \\vocab{zero divisors}\nof the ring $R$.\nSo we give a name to such rings.\n\\begin{definition}\n\tA nontrivial ring with no zero divisors\n\tis called an \\vocab{integral domain}.\\footnote{Some\n\t\tauthors abbreviate this to ``domain'', notably Artin.}\n\\end{definition}\n\\begin{ques}\n\tShow that a field is an integral domain.\n\\end{ques}\n\\begin{exercise}\n\t[Cancellation in integral domains]\n\tSuppose $ac = bc$ in an integral domain, and $c \\neq 0$.\n\tShow that that $a = b$.\n\t(There is no $c\\inv$ to multiply by,\n\tso you have to use the definition.)\n\\end{exercise}\n\n\\begin{example}\n\t[Examples of integral domains]\n\tEvery field is an integral domain,\n\tso all the previous examples apply.\n\tIn addition:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\ZZ$ is an integral domain, but it is not a field.\n\t\t\\ii $\\RR[x]$ is not a field,\n\t\tsince there is no polynomial $P(x)$ with $xP(x) = 1$.\n\t\tHowever, $\\RR[x]$ is an integral domain,\n\t\tbecause if $P(x) Q(x) = 0$ then one of $P$ or $Q$ is zero.\n\t\t\\ii $\\ZZ[x]$ is also an example of an integral domain.\n\t\tIn fact, $R[x]$ is an integral domain for any integral domain $R$ (why?).\n\t\t\\ii $\\Zc n$ is a field (hence integral domain)\n\t\texactly when $n$ is prime.\n\t\tWhen $n$ is not prime, it is a ring but not an integral domain.\n\t\\end{enumerate}\n\tThe trivial ring $0$ is \\emph{not} considered an integral domain.\n\\end{example}\n\nAt this point, we go ahead and say:\n\\begin{definition}\n\tAn integral domain where all ideals are principal\n\tis called a \\vocab{principal ideal domain (PID)}.\n\\end{definition}\nThe ring $\\ZZ/6\\ZZ$ is an example of a ring\nwhich is a principal ideal ring, but not an integral domain.\nAs we alluded to earlier, we will never really use ``principal ideal ring''\nin any real way: we typically will want to strengthen it to PID.\n\n\\section{Prime ideals}\n\\prototype{$(5)$ is a prime ideal of $\\ZZ$.}\n\nWe know that every integer can be factored (up to sign)\nas a unique product of primes; for example $15 = 3 \\cdot 5$\nand $-10 = -2 \\cdot 5$.\nYou might remember the proof involves the so-called B\\'ezout's lemma,\nwhich essentially says that $(a,b) = (\\gcd(a,b))$;\nin other words we've carefully used the fact that $\\ZZ$ is a PID.\n\nIt turns out that for general rings, the situation is not as nice\nas factoring elements because most rings are not PID's.\nThe classic example of something going wrong is\n\\[ 6 = 2 \\cdot 3 = \\left( 1-\\sqrt{-5} \\right)\\left( 1+\\sqrt{-5} \\right) \\]\nin $\\ZZ[\\sqrt{-5}]$.\nNonetheless, we can sidestep the issue\nand talk about factoring \\emph{ideals}:\nsomehow the example $10 = 2 \\cdot 5$ should be $(10) = (2) \\cdot (5)$,\nwhich says ``every multiple of $10$ is the product of a\nmultiple of $2$ and a multiple of $5$''.\nI'd have to tell you then how to multiply two ideals, which I do\nin the chapter on unique factorization.\n\nLet's at least figure out what primes are.\nIn $\\ZZ$, we have that $p \\neq 1$ is prime if whenever $p \\mid xy$,\neither $p \\mid x$ or $p \\mid y$.\nWe port over this definition to our world of ideals.\n\\begin{definition}\n\t\\label{def:prime_ideal}\n\tA \\emph{proper} ideal $I \\subsetneq R$ is a \\vocab{prime ideal}\n\tif whenever $xy \\in I$, either $x \\in I$ or $y \\in I$.\n\\end{definition}\nThe condition that $I$ is proper is analogous to the\nfact that we don't consider $1$ to be a prime number.\n\n\\begin{example}[Examples and non-examples of prime ideals]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The ideal $(7)$ of $\\ZZ$ is prime.\n\t\t\\ii The ideal $(8)$ of $\\ZZ$ is not prime,\n\t\tsince $2 \\cdot 4 = 8$.\n\n\t\t\\ii The ideal $(x)$ of $\\ZZ[x]$ is prime.\n\t\t\\ii The ideal $(x^2)$ of $\\ZZ[x]$ is not prime,\n\t\tsince $x \\cdot x = x^2$.\n\n\t\t\\ii The ideal $(3,x)$ of $\\ZZ[x]$ is prime.\n\t\tThis is actually easiest to see\n\t\tusing \\Cref{thm:prime_ideal_quotient} below.\n\n\t\t\\ii The ideal $(5) = 5\\ZZ + 5i\\ZZ$ of $\\ZZ[i]$\n\t\tis not prime, since the elements\n\t\t$3+i$ and $3-i$ have product $10 \\in (5)$,\n\t\tyet neither is itself in $(5)$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{remark}\n\t\\label{rem:unit_sign_issue}\n\tIdeals have the nice property that they get rid of ``sign issues''.\n\tFor example, in $\\ZZ$, do we consider $-3$ to be a prime?\n\tWhen phrased with ideals, this annoyance goes away: $(-3) = (3)$.\n\tMore generally, for a ring $R$, talking about ideals\n\tlets us ignore multiplication by a unit.\n\t(Note that $-1$ is a unit in $\\ZZ$.)\n\\end{remark}\n\n\\begin{exercise}\n\tWhat do you call a ring $R$ for which the zero ideal $(0)$ is prime?\n\\end{exercise}\n\nWe also have:\n\\begin{theorem}[Prime ideal $\\iff$ quotient is integral domain]\n\t\\label{thm:prime_ideal_quotient}\n\tAn ideal $I$ is prime if and only if $R/I$ is an integral domain.\n\\end{theorem}\n\\begin{exercise}\n\t[Mandatory]\n\tConvince yourself the theorem is true;\n\tit is just definition chasing.\n\t(A possible start is to consider $R = \\ZZ$ and $I = (15)$.)\n\\end{exercise}\n\nI now must regrettably inform you that unique factorization is still\nnot true even with the notion of a ``prime'' ideal\n(though again I haven't told you how to multiply two ideals yet).\nBut it will become true with some additional assumptions\nthat will arise in algebraic number theory\n(relevant buzzword: Dedekind domain).\n\n\\section{Maximal ideals}\n\\prototype{The ideal $(x,5)$ is maximal in $\\ZZ[x]$, by quotient-ing.}\n\nHere's another flavor of an ideal.\n\\begin{definition}\n\tA proper ideal $I$ of a ring $R$ is \\vocab{maximal} if\n\tit is not contained in any other proper ideal.\n\\end{definition}\n\n\\begin{example}\n\t[Examples of maximal ideals]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The ideal $I = (7)$ of $\\ZZ$ is maximal, because\n\t\tif an ideal $J$ contains $7$\n\t\tand an element $n$ not in $I$\n\t\tit must contain $\\gcd(7,n) = 1$, and hence $J = \\ZZ$.\n\t\t\\ii The ideal $(x)$ is \\emph{not} maximal in $\\ZZ[x]$,\n\t\tbecause it's contained in $(x,5)$ (among others).\n\t\t\\ii On the other hand, $(x,5)$ is indeed maximal in $\\ZZ[x]$.\n\t\tThis is actually easiest to verify using\n\t\t\\Cref{thm:max_ideal_quotient} below.\n\t\t\\ii Also, $(x)$ is maximal in $\\CC[x]$,\n\t\tagain appealing to \\Cref{thm:max_ideal_quotient} below.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}\n\tWhat do you call a ring $R$ for which the zero ideal $(0)$ is maximal?\n\\end{exercise}\n\nThere's an analogous theorem to the one for prime ideals.\n\\begin{theorem}\n\t[$I$ maximal $\\iff$ $R/I$ field]\n\t\\label{thm:max_ideal_quotient}\n\tAn ideal $I$ is maximal if and only if $R/I$ is a field.\n\\end{theorem}\n\\begin{proof}\n\tA ring is a field if and only if $(0)$ is the only maximal ideal.\n\tSo this follows by \\Cref{prob:inclusion_preserving}.\n\\end{proof}\n\n\\begin{corollary}\n\t[Maximal ideals are prime]\n\tIf $I$ is a maximal ideal of a ring $R$, then $I$ is prime.\n\\end{corollary}\n\\begin{proof}\n\tIf $I$ is maximal, then $R/I$ is a field,\n\thence an integral domain, so $I$ is prime.\n\\end{proof}\n\nIn practice, because modding out by generated ideals is pretty convenient,\nthis is a very efficient way to check whether an ideal is maximal.\n\\begin{example}\n\t[Modding out in $\\ZZ{[x]}$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii This instantly implies that $(x,5)$ is a maximal ideal\n\t\tin $\\ZZ[x]$, because if we mod out by $x$ and $5$ in $\\ZZ[x]$,\n\t\twe just get $\\FF_5$, which is a field.\n\t\t\\ii On the other hand, modding out by just $x$ gives $\\ZZ$,\n\t\twhich is an integral domain but not a field; that's why $(x)$ is\n\t\tprime but not maximal.\n\t\\end{enumerate}\n\\end{example}\n\nAs we saw, any maximal ideal is prime.\nBut now note that $\\ZZ$ has the special property that\nall of its nonzero prime ideals are also maximal.\nIt's with this condition and a few other minor conditions\nthat you get a so-called \\emph{Dedekind domain}\nwhere prime factorization of ideals \\emph{does} work.\nMore on that later.\n\n\\section{Field of fractions}\n\\prototype{$\\Frac(\\ZZ) = \\QQ$.}\nAs long as we are here, we take the time to introduce a useful\nconstruction that turns any integral domain into a field.\n\n\\begin{definition}\n\tGiven an integral domain $R$,\n\twe define its \\vocab{field of fractions} or \\vocab{fraction field}\n\t$\\Frac(R)$ as follows:\n\tit consists of elements $a / b$, where $a,b \\in R$ and $b \\neq 0$.\n\tWe set $a / b \\sim c / d$ if and only if $bc = ad$.\n\tAddition and multiplication is defined by\n\t\\begin{align*}\n\t\t\\frac ab + \\frac cd &= \\frac{ad+bc}{bd} \\\\\n\t\t\\frac ab \\cdot \\frac cd &= \\frac{ac}{bd}.\n\t\\end{align*}\n\\end{definition}\nIn fact everything you know about $\\QQ$ basically carries over by analogy.\nYou can prove if you want that this indeed a field, but \nconsidering how comfortable we are that $\\QQ$ is well-defined,\nI wouldn't worry about it\\dots\n\n\\begin{definition}\n\tLet $k$ be a field.\n\tWe define $k(x) = \\Frac(k[x])$\n\t(read ``$k$ of $x$''),\n\tand call it the \\vocab{field of rational functions}.\n\\end{definition}\n\n\\begin{example}\n\t[Examples of fraction fields]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii By \\emph{definition}, $\\Frac(\\ZZ) = \\QQ$.\n\t\t\\ii The field $\\RR(x)$ consists of rational functions in $x$:\n\t\t\\[ \\RR(x) = \\left\\{ \\frac{f(x)}{g(x)} \\mid f,g \\in \\RR[x] \\right\\}. \\]\n\t\tFor example, $\\frac{2x}{x^2-3}$ might be a typical element.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{example}\n\t[Gaussian rationals]\n\t\\label{ex:gaussian_rationals}\n\tJust like we defined $\\ZZ[i]$ by abusing notation,\n\twe can also write $\\QQ(i) = \\Frac(\\ZZ[i])$.\n\tOfficially, it should consist of\n\t\\[ \\QQ(i) = \\left\\{ \\frac{f(i)}{g(i)} \\mid g(i) \\ne 0 \\right\\} \\]\n\tfor polynomials $f$ and $g$ with rational coefficients.\n\tBut since $i^2=-1$ this just leads to\n\t\\[ \\QQ(i) = \\left\\{ \\frac{a+bi}{c+di} \\mid a,b,c,d \\in \\QQ,\n\t\t(c,d) \\ne (0,0) \\right\\}. \\]\n\tAnd since $\\frac{1}{c+di} = \\frac{c-di}{c^2+d^2}$ we end up with\n\t\\[ \\QQ(i) = \\left\\{ a+bi \\mid a,b \\in \\QQ \\right\\}. \\]\n\\end{example}\n\n\n\\section{Unique factorization domains (UFD's)}\n\\prototype{$\\ZZ$ and polynomial rings in general.}\n\nHere is one stray definition that will be important\nfor those with a number-theoretic inclination.\nOver the positive integers, we have a fundamental theorem of arithmetic,\nstating that every integer is uniquely the product of prime numbers.\n\nWe can even make an analogous statement in $\\ZZ$ or $\\ZZ[i]$,\nif we allow representations like $6 = (-2)(-3)$ and so on.\nThe trick is that we only consider everything \\emph{up to units};\nso $6 = (-2)(-3) = 2 \\cdot 3$ are considered the same.\n\nThe general definition goes as follows.\n\\begin{definition}\n\tA nonzero non-unit of an integral domain $R$ is\n\t\\vocab{irreducible} if it cannot be written as the product of two non-units.\n\n\tAn integral domain $R$ is a \\vocab{unique factorization domain}\n\tif every nonzero non-unit of $R$ can be written\n\tas the product of irreducible elements,\n\twhich is unique up to multiplication by units.\n\\end{definition}\n\\begin{ques}\n\tVerify that $\\ZZ$ is a UFD.\n\\end{ques}\n\n\\begin{example}\n\t[Examples of UFD's]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Fields are a ``degenerate'' example of UFD's:\n\t\tevery nonzero element is a unit,\n\t\tso there is nothing to check.\n\n\t\t\\ii $\\ZZ$ is a UFD.\n\t\tThe irreducible elements are $p$ and $-p$,\n\t\tfor example $5$ or $-17$.\n\n\t\t\\ii $\\QQ[x]$ is a UFD:\n\t\tpolynomials with rational coefficients\n\t\tcan be uniquely factored, up to scaling by constants\n\t\t(as the units of $\\QQ[x]$ are just the rational numbers).\n\n\t\t\\ii $\\ZZ[x]$ is a UFD.\n\n\t\t\\ii The Gaussian integers $\\ZZ[i]$ turns out to be a UFD too\n\t\t(and this will be proved in the chapters on algebraic number theory).\n\n\t\t\\ii $\\ZZ[\\sqrt{-5}]$ is the classic non-example of a UFD:\n\t\tone may write\n\t\t\\[ 6 = 2 \\cdot 3 = \\left( 1-\\sqrt{-5} \\right)\n\t\t\t\\left( 1+\\sqrt{-5} \\right) \\]\n\t\tbut each of $2$, $3$, $1 \\pm \\sqrt{-5}$ is irreducible.\n\t\t(It turns out the right way to fix this is\n\t\tby considering prime \\emph{ideals} instead,\n\t\tand this is one big motivation for \\Cref{part:algnt1}.)\n\n\t\t\\ii Theorem we won't prove: every PID is a UFD.\n\t\t\\ii Theorem we won't prove: if $R$ is a UFD,\n\t\tso is $R[x]$ (and hence by induction so is\n\t\t$R[x,y]$, $R[x,y,z]$, \\dots).\n\t\\end{enumerate}\n\\end{example}\n\n\n\n\\section{\\problemhead}\nNot olympiad problems, but again the spirit is very close\nto what you might see in an olympiad.\n\n\\begin{problem}\n\tConsider the ring\n\t\\[ \\QQ[\\sqrt2] = \\left\\{ a + b\\sqrt2 \\mid a,b \\in \\QQ \\right\\}. \\]\n\tIs it a field?\n\t\\begin{hint}\n\t\tYes.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t[Homomorphisms from fields are injective]\n\t\\label{prob:field_hom}\n\tLet $K$ be a field and $R$ a ring.\n\tProve that any homomorphism $\\psi \\colon K \\to R$\n\tis injective.\\footnote{Note that $\\psi$\n\t\tcannot be the zero map for us,\n\t\tsince we require $\\psi(1_K) = 1_R$.\n\t\tYou sometimes find different statements in the literature.}\n\t\\begin{hint}\n\t\tThe kernel is an ideal of $K$!\n\t\\end{hint}\n\\end{problem}\n\n\\begin{sproblem}\n\t[Pre-image of prime ideals]\n\t\\label{prob:prime_preimage}\n\tSuppose $\\phi \\colon R \\to S$ is a ring homomorphism,\n\tand $I \\subseteq S$ is a prime ideal.\n\tProve that $\\phi\\pre(I)$ is prime as well.\n\t\\begin{hint}\n\t\tThis is just a definition chase.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tConsider $ab \\in \\phi\\pre(I)$,\n\t\tmeaning $\\phi(ab) = \\phi(a) \\phi(b) \\in I$.\n\t\tSince $I$ is prime, either $\\phi(a) \\in I$ or $\\phi(b) \\in I$.\n\t\tIn the former case we get $a \\in \\phi\\pre(I)$ as needed;\n\t\tthe latter case we get $b \\in \\phi\\pre(I)$.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{sproblem}\n\t\\gim\n\tLet $R$ be an integral domain with finitely many elements.\n\tProve that $R$ is a field.\n\t\\label{prob:finite_domain_field}\n\t\\begin{hint}\n\t\tFermat's little theorem type argument;\n\t\tcancellation holds in integral domains.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLet $x \\in R$ with $x \\neq 0$.\n\t\tLook at the powers $x$, $x^2$, \\dots.\n\t\tBy pigeonhole, eventually two of them coincide.\n\t\tSo assume $x^m = x^n$ where $m < n$, or equivalently\n\t\t\\[ 0  = x \\cdot x \\cdot \\dots \\cdot x\n\t\t\t\\cdot \\left( x^{n-m} - 1 \\right). \\]\n\t\tSince $x \\ne 0$, we get $x^{n-m} - 1 = 0$,\n\t\tor $x^{n-m} = 1$.\n\t\tSo $x^{n-m-1}$ is an inverse for $x$.\n\n\t\tThis means every nonzero element has an inverse,\n\t\tergo $R$ is a field.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{sproblem}\n\t[Krull's theorem]\n\t\\label{prob:krull_max_ideal}\n\tLet $R$ be a ring and $J$ a proper ideal.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Prove that if $R$ is Noetherian,\n\t\tthen $J$ is contained in a maximal ideal $I$.\n\t\t\\ii Use Zorn's lemma (\\Cref{ch:zorn})\n\t\tto prove the result even if $R$ isn't Noetherian.\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\tJust keep on adding in elements to get an ascending chain.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFor part (b), look at the poset of \\emph{proper} ideals.\n\t\tApply Zorn's lemma (again using a union trick to verify the condition;\n\t\tbe sure to verify that the union is proper!).\n\t\tIn part (a) we are given no ascending infinite chains,\n\t\tso no need to use Zorn's lemma.\n\t\\end{sol}\n\\end{sproblem}\n\n\\begin{problem}\n\t[{$\\Spec k[x]$}]\n\tDescribe the prime ideals of $\\CC[x]$ and $\\RR[x]$.\n\t\\begin{hint}\n\t\tUse the fact that both are PID's.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe ideal $(0)$ is of course prime in both.\n\t\tAlso, both rings are PID's.\n\n\t\tFor $\\CC[x]$ we get a prime ideal $(x-z)$ for each $z \\in \\CC$.\n\n\t\tFor $\\RR[x]$ a prime ideal $(x-a)$ for each $a \\in \\RR$\n\t\tand a prime ideal $(x^2 - ax + b)$ for each quadratic\n\t\twith two conjugate real roots.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tProve that any nonzero prime ideal of $\\ZZ[\\sqrt 2]$ is also a maximal ideal.\n\t%(This is starred since the main idea of the solution will get used extensively in\n\t%the algebraic NT chapters, even though the problem itself won't.)\n\t\\label{prob:dedekind_sample}\n\t\\begin{hint}\n\t\tShow that the quotient $\\ZZ[\\sqrt2]/I$ has finitely many elements\n\t\tfor any nonzero prime ideal $I$.\n\t\tTherefore, the quotient is an integral domain, it is also a field,\n\t\tand thus $I$ was a maximal ideal.\n\t\\end{hint}\n\\end{problem}\n\n", "meta": {"hexsha": "12be8944555d5c13841d58002929ee47fe2083ab", "size": 17291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/rings.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/H113/rings.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/H113/rings.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": 34.3757455268, "max_line_length": 83, "alphanum_fraction": 0.6832456191, "num_tokens": 5544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300048, "lm_q2_score": 0.8670357615200475, "lm_q1q2_score": 0.6338539314382297}}
{"text": "\\documentclass[a4paper,11pt]{article}\r\n\\usepackage{a4wide}\r\n\\usepackage{amsmath}\r\n\\usepackage{amssymb}\r\n\\begin{document}\r\n\\begin{center}\r\n  {\\LARGE\\bf Supplemental note for Week 2 Part 3}\r\n  \\end{center}\r\n\\begin{flushright}\r\n  {\\large\\bf ver. 20170418-01}\\\\\r\n \\ \\\\\r\n{\\large\\bf Ryoichi Yamamoto}\\\\\r\n\\end{flushright}\r\n\\section{Binomial distribution $\\rightarrow$ Normal distribution}\r\n\r\nStart from Eq.(C6) shown below.\r\n\\begin{eqnarray}\r\n  P(n)&=&\\frac{M!}{n!(M-n)!}p^n(1-p)^{M-n}\\\\\r\n  \\ln P(n)&=&\\ln M! -\\ln n! - \\ln (M-n)!+n\\ln p +(M-n)\\ln(1-p)\\\\\r\n  &=&M(\\ln M -1) -n(\\ln n -1) - (M-n)(\\ln (M-n)-1)\\\\& & + n\\ln p +(M-n)\\ln (1-p)\r\n\\end{eqnarray}\r\nHere we used Stirling's approximation  valid for large $n$.\r\n\\begin{equation}\r\n\\ln n!\\simeq n(\\ln n -1)\r\n\\end{equation}\r\nTake the 1st derivative of the above equation in terms of $n$.\r\n\\begin{eqnarray}\r\n  \\frac{d \\ln P}{dn}&=&-(\\ln n +1) + (\\ln(M-n)+1) + \\ln p -ln(1-p)\\\\\r\n  &=&-\\ln n + \\ln(M-n)+\\ln p -\\ln(1-p)\\\\\r\n  &=&\\ln \\left[\\frac{M-n}{n} \\right] - \\ln \\left[\\frac{1-p}{p} \\right] \r\n\\end{eqnarray}\r\nWhen $n$ and $M$ are both large, the peak in $P(n)$ and also in $\\ln P(n)$ is very sharp around the mean value $n=\\langle N\\rangle$, and thus\r\n\\begin{eqnarray}\r\n  \\left.\\frac{d \\ln P}{dn}\\right|_{n=\\langle N\\rangle} &=&\\ln \\left[\\frac{M-\\langle N\\rangle}{\\langle N\\rangle} \\right] - \\ln \\left[\\frac{1-p}{p} \\right] =0\\\\\r\n  \\therefore \\frac{M-\\langle N\\rangle}{\\langle N\\rangle} &=& \\frac{1-p}{p} \\\\\r\n  \\langle N\\rangle&=&Mp.\r\n\\end{eqnarray}\r\n\\\\\r\nConsider a Taylor expansion of $\\ln P(n)$ around the mean $\\langle N\\rangle$ by defining $n=\\langle N\\rangle+\\delta n$.\r\n\\begin{equation}\r\n  \\ln P(n) = \\ln (\\langle N\\rangle) + \\left.\\frac{d \\ln P}{dn}\\right|_{n=\\langle N\\rangle}\\delta n\r\n  + \\frac{1}{2}\\left.\\frac{d^2 \\ln P}{dn^2}\\right|_{n=\\langle N\\rangle}\\delta n^2 + \\cdots\r\n  \\end{equation}\r\nFrom Eq.(7),\r\n\\begin{eqnarray}\r\n  \\frac{d^2 \\ln P}{dn^2}&=&-\\frac{1}{n}-\\frac{1}{M-n}\\\\\r\n  \\left.\\frac{d^2 \\ln P}{dn^2}\\right|_{n=\\langle N\\rangle}&=&-\\frac{1}{Mp}-\\frac{1}{M-Mp}=-\\frac{1}{Mp(1-p)}=-\\sigma^{-2}.\r\n\\end{eqnarray}\r\nTerminate Eq.(12) at the 2nd order in terms of  $\\delta n$, and use Eqs.(9) and (14).\r\n\\begin{equation}\r\nP(n)=const.\\times\\exp\\left(-\\frac{\\delta n^2}{2\\sigma^2}\\right)\r\n\\end{equation}\r\nDetermine $const.$ so that that $\\int_{-\\infty}^{\\infty}P(n)dn=1$, we finally obtain the following normal distribution function with $\\langle N\\rangle=Mp$ and $\\sigma^2=Mp(1-p)$.\r\n\\begin{equation}\r\nP(n)=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left(-\\frac{(n-\\langle N\\rangle)^2}{2\\sigma^2}\\right)\r\n\\end{equation}\r\n\r\n\\section{Binomial distribution $\\rightarrow$ Poisson distribution}\r\n\r\nWe now consider the limit of $M\\rightarrow\\infty$ while $\\langle N\\rangle=Mp=a$ remains constant.\r\nNotice that the following approximations hold.\r\n\\begin{eqnarray}\r\n%p=\\frac{a}{M-1}&\\simeq&\\frac{a}{M}\\\\\r\nM-n&\\simeq& M\\\\\r\n  \\frac{M!}{(M-n)!}&=&M(M-1)\\cdots(M-n+1)\\simeq M^n\r\n\\end{eqnarray}\r\nAgain start from Eq.(C6), we can derive Poisson distribution as shown below\r\nwith $\\langle N\\rangle=Mp=a$ and $\\sigma^2=Mp(1-p)\\simeq a$.\r\n\\begin{eqnarray}\r\n  P(n)&=&\\frac{M!}{n!(M-n)!}p^n(1-p)^{M-n}\\\\\r\n  &\\simeq&\\frac{1}{n!}M^n\\left(\\frac{a}{M}\\right)^n\\left(1-\\frac{a}{M}\\right)^M\\\\\r\n  &\\simeq&\\frac{a^n e^{-a}}{n!}\r\n\\end{eqnarray}\r\nHere we used\r\n\\begin{equation}\r\n\\lim_{M\\rightarrow \\infty}\\left(1-\\frac{a}{M}\\right)^M= e^{-a}.\r\n\\end{equation}\r\n\\end{document}\r\n\r\n", "meta": {"hexsha": "ed28e83ca3637651a6b4cbf94cbc464125b96a57", "size": 3396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "edx-stochastic-data-analysis/downloaded_files/02/Supplemental_note_2-3.tex", "max_stars_repo_name": "mirandagil/extra-courses", "max_stars_repo_head_hexsha": "51858f5089b10b070de43ea3809697760aa261ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "edx-stochastic-data-analysis/downloaded_files/02/Supplemental_note_2-3.tex", "max_issues_repo_name": "mirandagil/extra-courses", "max_issues_repo_head_hexsha": "51858f5089b10b070de43ea3809697760aa261ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "edx-stochastic-data-analysis/downloaded_files/02/Supplemental_note_2-3.tex", "max_forks_repo_name": "mirandagil/extra-courses", "max_forks_repo_head_hexsha": "51858f5089b10b070de43ea3809697760aa261ec", "max_forks_repo_licenses": ["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.45, "max_line_length": 179, "alphanum_fraction": 0.6192579505, "num_tokens": 1355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.6338326376630498}}
{"text": "\\lab{IVP Methods}{IVP Methods}\n\\label{lab:IVP}\n\n\\objective{Implement several basic numerical methods for initial value problems, and use them to study harmonic oscillators.}\n\n\\section*{Methods for initial value problems}\nConsider the initial value problem \n\\begin{align*}\ny' &= f(x,y),\\,\\, a \\leq x \\leq b, \\\\\ny(a) &= y_0,\n\\end{align*}\nwhere $f$ is a continuous function. A solution 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$.  \n\nThere are many initial value problems (IVPs) where it is impossible to find a closed form (analytic) expression for the solution. \nFor other IVPs there is a closed form expression for the solution, but it may be difficult to interpret. \nIn either case, we can usually make good use of various methods of numerical approximation to study the solution. (It is still important to know mathematically that a solution exists, even when we cannot find an explicit solution!)\n\nConsider the initial value problem \n\\begin{align*}\ny'(x) &= \\sin y(x), \\\\\ny(0) &= y_0.\n\\end{align*}\nThis IVP does have solution, which is given implicitly by \n\\[x = \\ln \\left|\\frac{\\cos y_0 + \\cot y_0}{\\csc y + \\cot y} \\right|.\\]\nIn this case, to understand the general solution it helps to use an IVP solver to plot the integral curves for some initial values. It is easy to show that this differential equation has constant solutions $y_n(x) = n \\pi, n \\in \\mathbb{N}$. Knowing this, and after plotting several integral curves (see Figure \\ref{ivp:int_curves} ), it is obvious how solutions of this IVP will behave.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{Fig2.pdf}\n\\caption{Several integral curves for the differential equation $y' =\\sin y$, using the python solver \\li{dopri5}. }\n\\label{ivp:int_curves}\n\\end{figure}\n\n\n\nNumerical methods for solving intial 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.  For 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}. We then look for values $y_0,y_1, \\hdots, y_n$ that approximate our solution ( so $y_i \\approx y(x_i)$).  \n\nFor a fixed value of $i$, $ 1 \\leq i \\leq n$, 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*}\nFor small values of $h$ the quantity $\\frac{h^2}{2} y''(\\xi_i)$ will be negligible and so we will have\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 first order ($\\mathcal{O}(h^1)$) method called Euler's method: Let $y_0 = y(a)$, and for $i = 0, 1, \\hdots, n-1$, let $y_{i+1} = y_i +hf(x_i,y_i)$. \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\nTaylor's theorem also says 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*}\nso that 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 the backwards Euler method, another first order method: Let $y_0 = y(a)$ and for $i = 0, 1, \\hdots, n-1$, 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}$. Because of this these are called \\textit{one-step methods}. \n\nEuler's method is an explicit method. The backwards Euler method is an implicit method since an equation must be solved at each step to find $y_{i+1}$. Explicit and implicit methods usually have their own advantages and disadvantages. While implicit methods require an equation to be solved at each time step, they also often have bettern stability properties than the corresponding explicit methods.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{Fig1.pdf}\n\\caption{The solution of $y' -y= -2x+4, y(0) = 0$, is $y(x) = -2+2x + 2e^x.$ This is a plot of the solution, alongside approximations with Euler's method for several stepsizes.}\n\\label{ivp:euler}\n\\end{figure}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{Fig3.pdf}\n\\caption{The solution of $y' -y= -2x+4,$ $ y(0) = 0$, is $y(x) = -2+2x + 2e^x.$ This is a loglog plot of the relative error in numerically approximating $y(2)$, using stepsizes $h = 0.2,$ $0.1,$ $0.05,$ $0.025,$ and $0.0125$. The plot shows first, second, and fourth order convergence for the Euler method, Midpoint method, and the RK4 method, respectively.}\n\\label{ivp:relative_error}\n\\end{figure}\n\n\\begin{problem} The solution of the IVP\n\\begin{align*}\ny' + y &= 2-2x,\\,\\, 0 \\leq x \\leq 2, \\\\\ny(0) &= 0,\n\\end{align*}\nis given by $y(x) = 4-2x -4e^{-x}$. \nUse Euler's method to numerically approximate the solution with step sizes $h = 0.4, 0.2$, and $0.1.$ Plot your results.\n\\end{problem}\n\nSo how do we come up with numerical methods with higher order accuracy? Using 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 necessarily desirable. \n\nLet us look for a second order method of the form\n\n$y_{i+1} = y_i + a f(x_i+b, y_i+c).$\n\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$. This method is called the Midpoint method. IVP solvers with this general form are called \\textit{Runge-Kutta methods}. Another second order Runge-Kutta method is the modified Euler method: \n\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. In practice, the methods of order four, such as the following, are most commonly used: \n\\begin{enumerate}\n\\item Apply initial conditions.\n\\item $K_1 = f(x_i,y_i),$\n\\item $K_2 = f(x_i + \\frac{h}{2}, y_i + \\frac{h}{2} K_1),$\n\\item $K_3 = f(x_i + \\frac{h}{2} , y_i + \\frac{h}{2} K_2),$\n\\item $K_4 = f(x_{i+1} , y_i + h K_3),$\n\\item $y_{i+1} = y_i + \\frac{h}{6}(K_1 + 2K_2 + 2K_3 + K_4)$\n\\end{enumerate}\n\n\\begin{comment}\n\\begin{problem}\nSuppose a differential equation is given by\n\\[ y' = f(t).\\]\nIf we were to solve this by just integrating, which integration approximation method would 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\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.\n\n\\begin{problem} Consider the IVP given by \n\\begin{align*}\ny' + y &= 2-2x,\\,\\, 0 \\leq x \\leq 2, \\\\\ny(0) &= 0.\n\\end{align*}\nUse Euler's method, the Midpoint method, and RK4 to approximate the value of the solution at $x = 2$, with a stepsize of $h = 0.2,$ $ 0.1,$ $0.05 $, $0.025,$ and $0.0125.$ Create 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{problem}\n% Plot the solutions of \n% \\[ y' + y = 2-2x\\,\\, 0 \\leq x \\leq 2, \\] \n% with initial conditions $y(0) = 0, 2, 4, 6, $ and $8$. Use RK4 to compute the solutions. \n% \\end{problem}\n\n\\section*{Harmonic Oscillators and Resonance} Harmonic 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\tmy'' + \\gamma y' + ky &= f(t) ,\\\\\n\ty(0) &= y_0,\\\\\n\ty'(0) &= y'_0.\n\\end{align*}\n\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. This force is usually proportional to the $y'$, is always in the opposite direction of $y'$ (the \\emph{velocity}. You can think of it as drag), and represents energy leaving the system. \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(t) \\equiv 0$) rather than forced ($f(t) \\not = 0$). A simple harmonic oscillator can described by the IVP\n\\begin{align*}\nmy'' + ky &= 0,\\\\\ny(0) &= y_0,\\\\\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 \ndescribed by \n\\begin{align*}\nmy'' + ky &= 0,\\,\\, 0 \\leq t \\leq 20, \\\\\ny(0) &= 2, \\\\\ny'(0) &= -1,\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 solution $y(t)$.  Compare this with the solution of the IVP if  $m = 3$ and $k =1$. Consider: Why does the difference in solutions make sense physically?\n\\end{problem}\n\n\n\\section*{Damped free harmonic oscillators} We now consider damped free harmonic oscillators. These 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. There 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}$. Notice 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 RK4 method to solve for the damped free harmonic oscillator \n\\begin{align*}\ny'' +\\gamma y'+ y &= 0, \\,\\, 0 \\leq x \\leq 20,\\\\\ny(0) &= 1, \\\\\ny'(0) &= -1.\n\\end{align*} \nFor $\\gamma = 1/2,$ and $\\gamma = 1$, simultaneously plot the solutions $y(t)$ and find $y(20)$ accurate to four significant digits. (Check that the relative error is less than $5 \\cdot 10^{-5}$.)  How 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)$. If $\\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).\\]\nThis last solution contains a term that grows arbitrarily large as $t \\to \\infty$. \nIf we included damping then the solution would be bounded, but will still be large for small $\\gamma$ and $\\omega$ close to $\\omega_0$. \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. Mechanical resonance has \nbeen known to cause failure of bridges, buildings, and airplanes.\n\n\\begin{problem}\nUse the RK4 method to solve for the undamped forced harmonic oscillator\n\\begin{align*}\n2y'' + \\gamma y' + 2y &= 2 \\cos (\\omega x), \\,\\, 0 \\leq x \\leq 40,\\\\\ny(0) &= 2, \\\\\ny'(0) &= -1.\n\\end{align*} \nFor the following values of $\\gamma$ and $\\omega,$ plot the solution $y(t)$ and find $y(40)$ correct to four decimal places: \n\\begin{align*}\n\t(\\gamma, \\omega) &= (0.5, 1.5),\\\\\n\t &= (0.1, 1.1), \\\\\n\t&= (0.0, 1.0).\n\\end{align*}\n\\end{problem}\n\n", "meta": {"hexsha": "59ab80cac6ae83dcf632523c45a219d59648ae33", "size": 14653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/IVP/IVP.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/IVP/IVP.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/IVP/IVP.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.0155642023, "max_line_length": 420, "alphanum_fraction": 0.691940217, "num_tokens": 4722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.727975460709318, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.6337734561163697}}
{"text": "\\chapter{Centrality measures}\n\\section{Some famous centrality measures}\nThe centrality of a node is a common problem of various fields such as biology, computer science, sociology, psychology. There are some old and popular measures to compute the centrality:\n\\begin{itemize}\n\t\\item Closeness\n\t\\item Betweenness\n\\end{itemize}\nNext we examine some algorithms for computing them\n\\section{Closeness}\n\\subsection{Definition}\nIn words, the closeness says how a node is distant from the other nodes.\\\\\nThe formula for calculate is:\n\\begin{align*}\nc(v) = \\dfrac{n-1}{\\sum_{u \\in V} d(v,u)}\n\\end{align*}\nA variant of this definition for non strongly connected components is\n\\begin{align*}\nc(v)  = \\dfrac{r(v) -1}{f(v)} \\dfrac{r(v)-1}{n-1} = \\dfrac{(r(v) - 1)^2}{(n-1)f(v)}\n\\end{align*}\n where $ r(v) $ is the set of reachable nodes from v. If the graph is strongly connected we have the previous definition, in fact\n \\begin{align*}\n \t\\dfrac{(n - 1)^2}{(n-1)f(v)} = \\dfrac{n-1}{f(v)}\n \\end{align*}\n \\subsection{A simple approach}\n The initial idea for computing the closeness is doing a BFS from all nodes to obtain all the distances but this have time complexity $ O(nm) $ which is too much for real graph.\n \\section*{The pruned breadth first search}\n  A similar problem is find the top k nodes with lower closeness but for doing this we need before the pruned breadth first search.\\\\\n  \\subsection{The upper bound on closeness}\n The pruned breadth first search use a lower bound on the farness of the nodes from v, that is equivalent to an upper bound of the closeness.\\\\\n Let's define the following terms:\n \\begin{itemize}\n \t\\item $ \\Gamma_d(v) = $ set of nodes at level \\textit{d} of the BFS tree starting from \\textit{v}\n \t\\item $ \\gamma_d(v) = |\\Gamma_d(v)| $\n \t\\item $ f_d(v) = \\sum_{i=1}^{d} i \\cdot \\gamma_i(v) $\n \t\\item $ n_d(v) = \\sum_{i=1}^{d} \\gamma_i(v) $\n\\end{itemize}\nNow let's define a lower bound on closeness:\n\\begin{center}\n\t$ f(v) \\geq f_d(v) + (d+1) \\cdot  \\gamma_{d+1}(v) + (d+2)(r(v) - n_{d+1}(v))$\n\\end{center}\nSince $ n_{d+1}(v) = \\gamma_{d+1}(v) + n_d(v) $ we have\n\\begin{align*}\n\t f(v) &\\geq f_d(v) + (d+1) \\cdot \\gamma_{d+1}(v) + (d+2)\\left[r(v) - (\\gamma_{d+1}(v) + n_d(v))\\right] \\\\\n\t &= f_d(v) + (d+1) \\cdot \\gamma_{d+1}(v) - (d+2) \\cdot \\gamma_{d+1}(v) + (d+2)(r(v) - n_d(v)) \\\\\n\t &= f_d(v)   - \\gamma_{d+1}(v) + (d+2)(r(v) - n_d(v)) \n\\end{align*}\nWe must consider that at the level \\textit{d} we don't know how much is $ \\gamma_{d+1}(v) $ so we use an upper bound that is the sum of degree of nodes on level \\textit{d}:\n\\begin{align*}\n\t\\gamma_{d+1}(v) \\leq \\sum_{u \\in \\Gamma_d(v)} degree(u) := \\tilde{\\gamma}_{d+1}(v)\n\\end{align*}\nSo we use the latter approximation on lower bound of farness $ f(v) $ \n\\begin{align*}\n\t f(v) &\\geq \\tilde{f}_d(v, r(v)) :=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + (d+2)(r(v) - n_d(v))\n\\end{align*}\nthat is equivalent to an upper bound on closeness:\n\\begin{align*}\n\tc(v) \\leq \\dfrac{\\left[r(v) - 1 \\right]^2}{(n-1) \\cdot  \\tilde{f}_d(v, r(v)) } := \\tilde{c}_d(v) \n\\end{align*}\n\\subsubsection{How to prune the breadth first search}\nThe pruned breadth first search receive in input the following arguments:\n\\begin{itemize}\n\t\\item \\textit{v}: the starting node of pruned BFS\n\t\\item $ x_k $: the k-th biggest closeness value found until now (0 if not are processed at least k vertices)\n\\end{itemize}\nthen at each level \\textit{d} of \\textit{BFS} tree we check if $ x_k >  \\tilde{c}_d(v)  \\geq c_d(v)  $, and, if it is true, it means that it is not in the \\textit{k} lowest values of closeness in the graph, so we can stop the \\textit{BFS}.\n\\subsection{Compute the upper bound on closeness}\nOnce we have defined the algorithm in the latter section, then it remains one thing: calculate $ r(v) $ for each node.\\\\\nWe have four different cases:\n\\begin{itemize}\n\t\\item Graph indirected and strongly connected: $ r(v) \\rightarrow n \\,\\,\\forall v \\in V $\n\t\\item  Graph indirected but not strongly connected: A linear time scan graph is needed then set $ r(v) = |SCC| : v \\in SCC \\,\\, \\forall v \\in V $ that mean set $ r(v) $ to the size of strongly connected component where it belongs\n\t\\item Graph directed and strongly connected :  $ r(v) \\rightarrow n \\,\\,\\forall v \\in V $\n\t\\item Graph directed but not strongly connected : see below\n\\end{itemize}\n\\subsubsection{Graph directed but not strongly connected}\nSuppose that $ r(v) $ is included in the range $ [\\alpha(v) , \\omega(v)] $ a lower bound for $ \\dfrac{1}{c(v)} $ is obtained simply bi reverting the upper bound in the latter section:\n\\begin{align*}\n \\dfrac{1}{c(v)} \\geq \\dfrac{(n-1) \\cdot \\tilde{f}_d(v, r(v))}{(r(v) -1)^2}\n\\end{align*}\nThen if we define $ a = d+2  $ and $ b = \\tilde{\\gamma}_{d+1}(v) + a(n_d(v) -1) - f_d(v) $ we have that\n\\begin{align*}\n\tf(v) \\geq \\tilde{f}_d(v, r(v)) &=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + (d+2)(r(v) - n_d(v)) \\\\\n\t&=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + a \\cdot (r(v) - n_d(v)) \\\\\n\t&=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + a \\cdot (r(v) - n_d(v) + 1 - 1) \\\\\n\t&=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + a \\cdot (r(v) - 1))  - a \\cdot n_d(v) + a\\\\\n\t&=  f_d(v)   - \\tilde{\\gamma}_{d+1}(v) + a \\cdot (r(v) - 1))  + a (-  n_d(v) + 1)\\\\\n\t&=  a \\cdot (r(v) - 1))   - \\tilde{\\gamma}_{d+1}(v)   - a (  n_d(v) -1)  + f_d(v)\\\\\n\t&= a \\cdot (r(v) - 1))   - b\n\\end{align*}\n\nso we can write the lower bound as \n\\begin{align*}\n\\dfrac{1}{c(v)} \\geq \\dfrac{(n-1) \\cdot \\tilde{f}_d(v, r(v))}{(r(v) -1)^2} =(n-1)\\dfrac{a \\cdot (r(v) - 1))   - b}{(r(v) -1)^2}\n\\end{align*}\nNow consider the functions in the form $ g(x) = \\dfrac{ax - b}{x^2} $ and the derivative $ g'(x) = \\dfrac{-ax + 2b}{x^3} $: we can easily see that we have a zero in the derivative with $ x = \\dfrac{2b}{a} $ and it is a local maximum because x is positive in range $ 0 < x < \\frac{2b}{a} $ and negative in $ x > \\frac{2b}{a} $. Then this it implies that for $ x > 0 $ there aren't local minimum so for any interval $ [x_1, x_2] $ the local minimum in the interval is $ x_1  $ or $ x_2 $ that in formula is $ \\forall x \\in [x_1, x_2] \\,\\, g(x)  \\geq \\min(g(x_1), g(x_2))$\n\\begin{figure}[H]\n\t\\includegraphics[width=0.7\\linewidth]{img/local_maximum}\n\t\\caption{Plot of $ g(x) = \\dfrac{ax -b}{x^2} $ with $ a = b = 1 $}\n\t\\label{fig:localmaximum}\n\\end{figure}\nReturning to the lower bound of $ \\frac{1}{c(v)} $ we can use the same reasoning with $ (n-1)\\dfrac{a \\cdot (r(v) - 1))   - b}{(r(v) -1)^2} $ so we can say that \n\\begin{align*}\n\\dfrac{1}{c(v)} \\geq (n-1) \\cdot \\dfrac{\\tilde{f}_d(v, r(v))}{(r(v) -1)^2} \\geq (n-1) \\cdot \\min\\left( \\dfrac{\\tilde{f}_d(v, \\alpha(v))}{(\\alpha(v) -1)^2}, \\dfrac{\\tilde{f}_d(v, \\omega(v))}{(\\omega(v) -1)^2} \\right)\n\\end{align*}\n\n\\subsection{Compute $ \\alpha(v) \\text{ and }  \\omega(v) $}", "meta": {"hexsha": "50ae9718ed649d9616e0619ef82e7031b6951046", "size": 6712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/centrality.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/centrality.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/centrality.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": 63.320754717, "max_line_length": 569, "alphanum_fraction": 0.6373659118, "num_tokens": 2509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.6337734287313743}}
{"text": "\\section{Representations of Counterpoint and Harmony}\n\\label{sec:cpharmony}\n\nHarmony refers to simultaneously sounding tones (chords) and harmonic progression\na series of chords. It is in essence the of dual of counterpoint. A\nfundamental representation used in Music Tools is a grid of\n\\texttt{Point}s, where a \\texttt{Point} represents either a pitch, a\nhold of a previous pitch, or a rest.\n\n\\begin{alltt}\ndata Point : Set where\n  tone : Pitch \\(\\rightarrow\\) Point\n  hold : Pitch \\(\\rightarrow\\) Point\n  rest : Point\n\\end{alltt}\n\nMusic is thus considered to be quantized to some minimal duration,\nwith the horizontal dimension representing time and the vertical\ndimension representing pitch. A slice in the horizontal direction is a\n\\texttt{Melody}, represented as a vector of points of some length $n$. Similarly a slice\nin the vertical direction is a \\texttt{Chord}, again of some fixed length.\n\n\\begin{alltt}\ndata Melody (n : \\(\\mathbb{N}\\)) : Set where\n  melody : Vec Point n \\(\\rightarrow\\) Melody n\n\ndata Chord (n : \\(\\mathbb{N}\\)) : Set where\n  chord : Vec Point n \\(\\rightarrow\\) Chord n\n\\end{alltt}\n\nOne can think of the grid as several melodies in parallel of the same\nduration. This is essentially counterpoint, and thus given that\nname. Note the crucial use of dependent types here to ensure all\nmelodies have the same duration $d$. The counterpoint is specified to\nhave $v$ voices.\n\n\\begin{alltt}\ndata Counterpoint (v : \\(\\mathbb{N}\\)) (d : \\(\\mathbb{N}\\)): Set where\n  cp : Vec (Melody d) v \\(\\rightarrow\\) Counterpoint v d\n\\end{alltt}\n\nDually one can think of the grid as a series of chords, in another\nword a harmonic progression, although this is named \\texttt{Harmony}\nin the library for conciseness. Again dependent types enforce every\nchord has the same number of voices.\n\n\\begin{alltt}\ndata Harmony (v : \\(\\mathbb{N}\\)) (d : \\(\\mathbb{N}\\)): Set where\n  harmony : Vec (Chord v) d \\(\\rightarrow\\) Harmony v d\n\\end{alltt}\n\nConverting between \\texttt{Counterpoint} and \\texttt{Harmony} is\nsimply matrix transposition. These are fundamental representations\nthat can be used directly for analysis, for example, and there are\nfunctions to convert them to MIDI for sound generation.\n\nThere are many other ways to represent music, which have advantages in\ncertain contexts. For example in Section~\\ref{sec:cp}\n\\texttt{PitchInterval} and \\texttt{PitchInterval2} were used instead\nof \\texttt{Counterpoint} since they more explictly represent the\nstructure of the music in species counterpoint. It is straightforward\nto convert between the representations, and worth using the most\nappropriate type for a given situation.\n", "meta": {"hexsha": "54cef406d886bee88b665c29dffc512bb9699bb3", "size": 2635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/icfp20/cpharmony.tex", "max_stars_repo_name": "halfaya/MusicTools", "max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z", "max_issues_repo_path": "doc/icfp20/cpharmony.tex", "max_issues_repo_name": "halfaya/MusicTools", "max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z", "max_forks_repo_path": "doc/icfp20/cpharmony.tex", "max_forks_repo_name": "halfaya/MusicTools", "max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z", "avg_line_length": 41.171875, "max_line_length": 88, "alphanum_fraction": 0.7616698292, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6337081511411223}}
{"text": "\\chapter{Graphs}\n\n\\pgfplotsset{width=1\\columnwidth,compat=1.9}\n\n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot[color=red]{exp(x)};\n\\end{axis}\n\\end{tikzpicture}\n\n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot3[surf,]\n{exp(-x^2-y^2)*x};\n\\end{axis}\n\\end{tikzpicture}\n\n\\hskip 10pt\n\n\\begin{tikzpicture}\n\\begin{axis}[\naxis lines = left,\nxlabel = $x$,\nylabel = {$f(x)$},\n]\n%Below the red parabola is defined\n\\addplot [\ndomain=-10:10, \nsamples=100, \ncolor=red,\n]\n{x^2 - 2*x - 1};\n\\addlegendentry{$x^2 - 2x - 1$}\n%Here the blue parabloa is defined\n\\addplot [\ndomain=-10:10, \nsamples=100, \ncolor=blue,\n]\n{x^2 + 2*x + 1};\n\\addlegendentry{$x^2 + 2x + 1$}\n\n\\end{axis}\n\\end{tikzpicture}\n\n", "meta": {"hexsha": "dcbbdd68fd202424d492be404366dceba8cddf75", "size": 664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "graph.tex", "max_stars_repo_name": "christianhauschel/latex-summary", "max_stars_repo_head_hexsha": "54a14ecadc17209ddd6eafe2ffa9211538355570", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-05-01T08:11:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-11T19:21:00.000Z", "max_issues_repo_path": "graph.tex", "max_issues_repo_name": "ch101112/latex-summary", "max_issues_repo_head_hexsha": "2661049d27bb8f6fc6dbc64594dad1635003bbf1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "graph.tex", "max_forks_repo_name": "ch101112/latex-summary", "max_forks_repo_head_hexsha": "2661049d27bb8f6fc6dbc64594dad1635003bbf1", "max_forks_repo_licenses": ["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.4347826087, "max_line_length": 44, "alphanum_fraction": 0.6596385542, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.633708143189962}}
{"text": "\\chapter{Feedforward Neural Network}\n\nStarting from the late 2000's, neural networks have been experiencing an exciting resurgence in the big data era. Given recent improvements in processing speeds, large-scale deep neural networks (DNNs), a.k.a. deep learning, are able to deliver highly accurate results when tackling several problem domains, including computer vision, natural language processing, speech recognition, and other AI challenges. For instance, the systems using DNNs have reported breakthroughs in object recognition accuracy on the ImageNet dataset, and have even achieved human-level performance for face recognition. Motivated by these encouraging results, there has been a growing interest from both academia and industry (Google, Facebook, Amazon, etc.), both of whom have been devoted significant resources to investigate, improve and promote exploration into DNNs. DNNs are revolutionizing a number of traditional and emerging real-world applications, such as self-driving systems, automatic machine translations, drug discovery and toxicology.\n\nIn this chapter we will introduce the basics of deep feedforward neural networks, define related terminologies, and analyze how to train and use neural network model.\n\\section{Feedforward Networks}\nA \\textit{network model} is a model expressed through compositions of function, where the composition relations forms an directed acyclic graph. Figure \\ref{fig1} gives an example of a network model. In this example, $f_1$ and $f_3$ are composited by $f_2$ and $f_4$ separately, which in turn is composited $f_5$. Thus the expression of the entire model is\n\\begin{align*}\n\\label{enetwork}\nf(\\bm{x}) = f_5(f_2(f_1(\\bm{x})), f_4(f_3(\\bm{x})))\n\\end{align*}\nIn a network model, the input vector is denoted as $\\bm{x}\\in\\mathbb{R}^m$. If the information flows through the function that evaluates $\\bm{x}$, through each of the subsequent function, and finally goes to output vector $\\bm{y}\\in\\mathbb{R}^n$. Such network is called a \\textit{feedforward network}, as there is no feedback connections in which outputs of the model are fed back into itself.\n\n\\begin{wrapfigure}{r}{0.3\\textwidth}\n\\centering\n\\includegraphics[width=0.3\\textwidth]{Fig1}\n\\caption{Feedforward Network}\n\\label{fig1}\n\\end{wrapfigure}\n\n\n\nFunctions may form one or more layers according to which values they take as inputs (cf. Figure \\ref{fig2}). The functions that directly take input $\\bm{x}$ form the \\textit{input layer}, functions that take values from input-layer functions form the \\textit{first hidden layer}, and so on, until the last layer (call \\textit{output layer}) which returns the output of the entire model. The total number of layers is called \\textit{the depth} of the network. The \\textit{width} of a layer is defined to be the number of functions on the layer. The functions are sometimes referred to as units, neurons, or activation functions, depending on the context. Nowadays neural networks with more than 1000 layers were used for tasks in computer vision, which justifies the name \"deep learning\". The training data do not provide information on what values the intermediate layers should produce, thus these layers are referred to as \\textit{hidden layers}.\n\nThe information usually flow into a function from multiple sources. This is typically achieved by a weighted summation of the input values, possibly added with a bias value. For a single unit with activation function $\\sigma$, the relation between the input vector $\\bm x$ and the output vector $\\bm y$ is given in the form of\n\\begin{equation}\n    \\bm y = \\bm \\sigma(\\bm{W^Tx}+\\bm\\theta).\n\\end{equation}\nHere $\\bm W$ is a matrix of parameters representing the weighted summation of the input vector, $\\bm\\theta$ is a vector representing the bias value, and $\\bm\\sigma$ is the function that applies the activation function $\\sigma$ to each of its input coordinates. For the ease of notation, we use new notations\n$\\bm x' = (\\bm x^T, 1)^T$ and $\\bm W' = (\\bm W, \\bm\\theta^T)^T$ and simplify the notation above as\n\\begin{equation}\n \\bm y = \\bm \\sigma(\\bm{(W')^Tx'}).\n\\end{equation}\nFrom now on we will drop the primes and stick with the simplified notations. As an example, the overall expression of the model illustrated in Figure \\ref{fig2} can be expressed as\n\n\\begin{align*}\n\\bm{y} = \\bm{W_3^T\\cdot\\sigma(W_2^T\\cdot\\sigma\n(W_1^Tx))}\n\\end{align*}\n\nThe weight matrix related to the input of $j$-th layer is referred to as the weight matrix \\textit{of that layer}. Every layer except for the input layer has a corresponding weight matrix.\n\n\\begin{wrapfigure}{r}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{Fig2}\n\\caption{Feedforward Network}\n\\label{fig2}\n\\end{wrapfigure}\n%{\\bf complicated network}\n%Not every network model of interest is a layered feedforward network, as the topology of an acyclic graph can be quite complicated. Note that since there is no loop in the graph, one can still find a suitable order to let the information flow from input to output. Also there are network models that do contain directed cycles. An important class is called \\textit{recurrent neural network}. We will study recurrent neural network at a later stage of the seminar.\n\nThe goal of a feedforward network is to approximate a function $g(\\bm{x})$. More precisely, the goal is to find an appropriate set of weights so that the function representing the network is close to the target function $g$ (under certain measure). The challenge is to find a network model and a training method that is capable to well approximate the target function with limited memory space and computational power. The purpose the the next two sections is to introduce the basic setting of linear network models and neural network models, analyze their training procedures, and discuss the challenges of applying these models. \n\n\\section{Linear Feedforward Neural Network}\nOne way to understand feedforward networks is to begin with linear models and consider how to overcome their limitations. Linear models, such as logistic regression and linear regression, are appealing because they may be fit efficiently and reliably, either in closed form or with convex optimization. On the other hand, linear models also have the obvious defect that the model capacity is limited to linear functions, so the model cannot understand the interaction between any two input variables.\n\n{\\bf Linear Regression Model}. Linear Regression is the simplest form of regression. We model our system with a linear combination of features to produce one output. That is,\n\\begin{equation}\n  f(\\bm x, \\bm w) = \\bm w^T\\bm x\n\\end{equation}\nHere $\\bm x$ is the input vector, and $w_0$, $\\bm w$ are parameters. Our task is then to find the values for the parameters that provide the best fit to our training data. One way to measure the fitness of the parameters is to calculate the least squares error (loss function) over our dataset $S = \\{(\\bm x^1, y^1), ..., (\\bm x^N, y^N)\\}$\n\\begin{equation}\n  L(S, \\bm w) = \\frac{1}{2}\\sum_{i=1}^N(f(\\bm x^i, \\bm w)-y^i)^2\n\\end{equation}\n\nIn order to find the best fit, we must minimize $L(S, \\bm w)$. The approach using gradient descent takes the following form:\n\\begin{equation}\n  \\bm w \\leftarrow \\bm w-\\eta\\nabla_{\\bm w}L(S, \\bm w)\n\\end{equation}\nThe step size $\\eta$ may be application-dependent. The gradient of the loss function explicitly is expressed as\n\\begin{equation}\n  \\nabla_{\\bm w}L(S, \\bm w) = \\sum_i(\\bm w^T\\bm{x^i} - y^i)\\bm x^i = (\\bm{w^TX-y})\\cdot\\bm X\n\\end{equation}\nHere $\\bm X = (\\bm x^1,...,\\bm x^N)$ and $\\bm y=(y^1,...,y^N)$.\nNote that there exists a closed form solution for linear regression, thus this gradient descent method is rarely used in practice.\n\n{\\bf Logistic regression model}. Another example on linear feedforward network is logistic regression model. We model our system as\n\\begin{equation}\n%   \\tanh(\\bm w^T \\bm x + b), \\textit{ where } \\tanh(a) = \\frac{1-\\exp(a)}{1+\\exp(a)}\n\\frac{1}{1+\\exp(\\bm w^T \\bm x)}\n\\end{equation}\nWith training set $S = \\{(\\bm x^1, y^1), ..., (\\bm x^N, y^N)\\}$, the loss function is defined by the negative log-likelihood\n\\begin{equation}\n L(\\bm w) = \\sum_{i=1}^N\\log(1+\\exp(-y^i(\\bm w^T\\bm x^i)))\n\\end{equation}\nThe loss function is minimized by the gradient descent\n\\begin{equation}\n  \\bm w = \\bm w-\\eta\\nabla_{\\bm w}L(\\bm w)\n\\end{equation}\nwith $\\nabla_{\\bm w}L(\\bm w) = -\\sum_{i=1}^N y^i\\frac{\\exp(-y^i(\\bm w^T\\bm x^i+b))}{1+\\exp(-y^i(\\bm w^T\\bm x^i+b))}\\bm x^i$.\n\nThe convexity of the loss function guarantees that the gradient descent algorithm will find the minimum value.\n\n{\\bf Summary}.The key elements of a network model can be summarized as follows: \n\\begin{enumerate}\n    \\item A function representing a network structure.\n    \\item A loss function.\n    \\item An optimization algorithm that minimizes the value of the loss function.\n\\end{enumerate}\n\n{\\bf Limitations of Linear Network Model}. One important application of network models is the classification problem. A linear network is only capable of separating the dataset with hyperplanes. We are going to show a classical result on the limited capability of linear network models on classifying $p$ points in general position.\n\n\\begin{wrapfigure}{r}{0.4\\textwidth}\n\\centering\n\\includegraphics[width=0.4\\textwidth]{nonlinearseparable}\n\\caption{A non-linear dichotomy}\n\\label{fig4}\n\\end{wrapfigure}\n\nWhen $n$ points are partitioned into two classes, we call such classification a \\textit{dichotomy}. Moreover, we use the term \\textit{linearly separable dichotomies} to represent the dichotomies that are realizable by a linear classifier (the boundary between the classes is a hyperplane). Figure \\ref{fig4} shows an example of a non-linear dichotomy, as no straight line can separate the two blue points from the two red ones. In general, suppose that we have $p$ points in general position in $\\mathbb{R}^N$. There are $2^p$ ways to partition these $p$ points into two classes, i.e., the $p$ points can form $2^p$ different dichotomies. The following theorem shows that the proportion of linear separable dichotomies will converge to 0 as $p\\rightarrow\\infty$. \n\n% Cover's function counting theorem (1966)\n% Suppose we have $p$ points in $\\mathbb{R}^N$. Consider all possible partitions of these points into two classes. We have  $2^p$ such partitions. How many of there partitions yield linearly separable classes, i.e., where the two classes can be perfectly separated by an $(N-1)$-dimensional hyperplane? The only thing we assume about the points is that they are in general position, which means that any subset of $N$ or fewer points is linearly independent. \n\n\n%  A dichotomy is a partition of a whole (or a set) into two parts (subsets). In other words, this couple of parts must be jointly exhaustive: everything must belong to one part or the other, and mutually exclusive: nothing can belong simultaneously to both parts.\n% Such a partition is also frequently called a bipartition.\n\n\n% The two parts thus formed are complements. In logic, the partitions are opposites if there exists a proposition such that it holds over one and not the other.\n\n\n% Treating continuous variables or multicategorical variables as binary variables is called dichotomization. The discretization error inherent in dichotomization is temporarily ignored for modeling purposes.\n\n\\begin{theorem}[Cover, 1965]\nLet $C(p, N)$ be the number of dichotomies of $p$ points in $N$-dimensional space that can be separated by a hyperplane. Then\n\\begin{align*}\n\\lim_{p\\rightarrow\\infty}\\frac{C(p,N)}{2^p}=0.\n\\end{align*}\n\\end{theorem}\n\n\\begin{proof}\nFirstly, we will find an explicit expression for $C(p, N)$ through induction. Suppose there are $p$ points located on the plane in general position, and we are trying to add one more point. There are two possibilities:\n\n1) There exists a separating hyperplane that passes through the new point;\n\n2) There does not exist a separating hyperplane that passes through the new point.\n\nIn case 1), No matter which class the new point belongs to, one can always shift the hyperplane infinitesimally so that this point locates on the same side of the hyperplane with other members of the class. Thus in this case each separable partitions in $p$ points gives rise to two separable partitions in $(p+1)$ points. \n\nNow consider case 2). For any separating hyperplane, the new point must be on the same side with the same class of the previous $p$ points, as otherwise one can always construct a separating hyperplane that passes through the new point. Thus in this case each separable partitions in $p$ points will give rise to exactly on separable partitions in $(p+1)$ points. \n\nMoreover, the number of separable partitions in case 1) is equal to $C(p-1, N)$, as one degree of freedom is eliminated by requiring passing through the new point. Therefore we obtain the following recursive expression\n\n\\begin{align*}\nC(p+1, N) = 2C(p,N-1) + [C(p,N)-C(p, N-1)] = C(p,N) + C(p, N-1).\n\\end{align*}\n\nMoreover, we have $C(1, N)=0$ for all $N<1$ and $C(1, N)=2$ for all $N\\ge 1$. By induction we can prove\n\n\\begin{align*}\nC(p+1,N) = 2\\sum_{i=0}^{N-1}\\big(^p_i\\big).\n\\end{align*}\nHere by convention we have $\\big(^p_i\\big)=0$ for $p<i$.\n\nFinally derive\n\\begin{align*}\n&\\lim_{p\\rightarrow\\infty}\\frac{C(p,N)}{2^p}\n=2\\sum_{i=0}^{N-1}\\lim_{p\\rightarrow\\infty}\\frac{\\big(^p_i\\big)}{2^p}\n=2\\sum_{i=0}^{N-1}0\n=0.\n\\end{align*}\n\\end{proof}\n\nIt is possible to extend linear models to represent nonlinear functions to x by applying the model to a transformed input $\\phi(x)$ or with the \"kernel\" trick. These techniques are beyond the scope of this chapter.\n\n\\section{Feedforward Neural Network}{\\color{red}LZ: merge with chapter 1}\nNeural networks are a computational approach that is based on a large collection of neural units (artificial neurons), loosely mimicking the way a biological brain solves problems with large clusters of biological neurons connected by axons. Each neural unit is connected with many others, and links can be enforcing or inhibitory in their effect on the activation state of connected neural units.\n\nProposed in 1940$'$s, neural networks are one of the most representative models in the artificial intelligence field. Simply speaking, a neural network tries to make a system that process information as a network of human neurons. Starting from late 2000s, neural networks(NNs) have been experiencing their exciting resurgence in the emerging big data era. The technique with the use of large-size deep neural networks (DNNs), a.k.a. deep learning, have produced state-of-the-art accuracy results on several well-known datasets in different artificial intelligent tasks, such as computer vision, natural language processing, speech recognition, etc.\n\n{\\bf Sigmoid function}. The sigmoid function is defined by\n\\begin{equation}\n\\sigma(t) = \\frac{1}{1+e^{-t}}.\n\\end{equation}\nThe sigmoid function is monotonically increasing over $\\mathbb{R}$ and is infinitely-differentiable. It has limit 0 and 1 as $t$ approaches $+\\infty$ and $-\\infty$, respectively. The graph of $\\sigma(t)$ is shown in Figure \\ref{fsig}.\n\nA useful property of $\\sigma(t)$ is that its derivative can be expressed by the function itself.\n\n\\begin{lemma}\n\\label{lsig}\n$\\sigma'(t) = \\sigma(t)(1-\\sigma(t))$.\n\\end{lemma}\n\n\n\\begin{figure}\\label{fsig}\n\\centering\n\\includegraphics[width=0.3\\textwidth]{Sigmoid}\n\\caption{Sigmoid Function}\n\\end{figure}\n\n{\\bf Neural network model}. In Deep Learning, sigmoid function is used as the activation function to introduce nonlinearity in the model. Inspired by biological neurons, an activation function basically works as a switch that can set the neuron on \"ON\" or \"OFF\". Besides the sigmoid function, commonly used activation functions are:\n\n\\begin{enumerate}\n\\item\nBinary step function: $f(t) = \\mathbbm{1}_{t\\ge 0}$.\n\\item\nHyperbolic tangent function: $f(t) = tanh(t)=\\frac{2}{1+e^{2t}}-1$.\n\\item\nArctan function: $f(t) = \\tan^{-1}(t)$.\n\\item\nRectified linear unit (ReLU) $f(t) = max\\{0, t\\}$.\n\\end{enumerate}\n\nA \\textit{neural network} is a network model with non-linear unites on its hidden layers.\n\n% To extend the learning model from linear to non-linear, we need to define non-linear unit, for example\n\n% sigmoid function: expression, limits on both direction, derivative, \n\n% \"Derivative in terms of the output y\":\n% \\begin{align*}\n% y =& \\frac{1}{1+e^{-z}}\\\\\n% \\frac{dy}{dz}=&\\frac{-1(-e^{-z})}{(1+e^{-z})^2}\\\\\n% =&\\big(\\frac{1}{1+e^{-z}}\\big)\\big(\\frac{e^{-z}}{1+e^{-z}}\\big)\\\\\n% =&\\big(\\frac{1}{1+e^{-z}}\\big)\\big(1 - \\frac{1}{1+e^{-z}}\\big)\n% =y(1-y)\n% \\end{align*}\n% %Definition of activation function. Commonly used non-linear activation function: sigmoid, tanh, ReLU, binary step:\n\n% A activation function basically works as a switch that can set the neuron on \"ON\"(1) or \"OFF\"(0). Commonly used activation functions are:\n\n% The first one is sigmoid function:$\\sigma_1(v)=\\frac{1}{1+e^{-v}}$, if $\\sigma_1(v)>0.5$, we take it as an \"ON\", otherwise we take it as an \"OFF\".The second one is hyperbolic tangent:$\\sigma_2(v)=tanh^{-1}(v)$, if $\\sigma_2(v)>0$, we take it as an \"ON\", otherwise we take it as an \"OFF\". The third one is linear function:$\\sigma_3(v)$, for linear activation function, we have the similar setting for linear function just as the previous two activation functions.\n\n\n\n{\\bf Basic neural network model.} The first thing to do when defining a machine learning model is to set the \\textit{hyper-parameters}.  For a neural network, hyper-parameters include the depth of the network $d$, the width of each layer $n$, the learning rate for gradient descent $r$, and the initial values for weight matrices $(\\bm{W_1}(0),...,\\bm{W_d}(0))$ and biases $(\\bm{\\theta_1}(0),...,\\bm{\\theta_d}(0))$. \n\n Suppose we have $m$ labeled training examples \n$$\\{(\\bm{x^1, y^1}),...,(\\bm{x^m, y^m})\\}.$$ Let $\\sigma_k$ ($\\bm{W_k}$, $\\bm{\\theta_k}$, resp.) be the activation function (weight matrix, bias vector, resp.) for the $k-th$ hidden layer, $k=1,2,...,d-1$. Let $\\bm{W_d}$ and $\\bm{\\theta_d}$ be the weight matrix and bias vector for the output layer. \n\nThe neural network model can be defined recursively as follows:\n\\begin{equation}\n\\label{enn}\n\\aligned\nG_d(\\bm{x}; \\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) =& \\bm{W_d^T}\\bm{a_d}+\\bm{\\theta_d}\\\\\n\\bm{a_k} =& G_{k-1}(\\bm{x}; \\bm{W_1},...,\\bm{W_{k-1}},\\bm{\\theta_1},..,\\bm{\\theta_{k-1}})\\\\\nG_{k}(\\bm{x}; \\bm{W_1},...,\\bm{W_k},\\bm{\\theta_1},..,\\bm{\\theta_k})=&\n\\sigma(\\bm{W_k^Ta_k}+\\bm{\\theta_k}), k=2,...,d\\\\\nG_1(\\bm{x};\\bm{W_1},\\bm{\\theta_1})=&\\sigma(\\bm{W_1^Tx}+\\bm{\\theta_1}).\n\\endaligned\n\\end{equation}\n\nHere we use the convention $\\sigma(x_1,...,x_n) = (\\sigma(x_1),...,\\sigma(x_n))$. When no confusion will occur, we will abbreviate $G_k(\\bm{x}; \\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})$ as $G_k(\\bm{x}; \\bm{W_d},\\bm{\\theta_d})$ or even $G_k(\\bm{x})$. \n\n\n{\\bf Example: Representing XOR function}.\nAn \\textit{XOR function} (\"exclusive or\") is an operation on two binary values $x_1$ and $x_2$. When exactly one of these binary values is equal to 1, the XOR function return 1. Otherwise, it returns 0. Mathematically the XOR function can be expressed as:\n\\begin{equation}\n    f(x_1, x_2) = |x_1 - x_2|.\n\\end{equation}\nOur model provides a function $y = f(x_1, x_2;\\bm{W_1}, \\bm{W_2})$ and our learning algorithm will adapt the parameters $\\bm{W_1}, \\bm{W_2}$ to make $f$ as similar as possible the the XOR function.\n\\begin{wrapfigure}{r}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=0.25\\textwidth]{XOR}\n\\caption{Representing XOR Function}\n\\label{fig3}\n\\end{wrapfigure}\nFigure \\ref{fig3} defines the network model with one hidden layer that returns exactly the same value as an XOR function on every element of the domain $\\{(0,0), (0,1), (1,0), (1,1)\\}$. Here the activation functions on the hidden layer are \"perceptrons\" $\\mathbbm{1}_{x\\ge a}$, where $a$ is the number inside each neuron. The expression of the neural network is\n\\begin{equation}\n  f(x_1,x_2) = \\mathbbm{1}_{x\\ge 1}(x_1) -2\\mathbbm{1}_{x\\ge 2}(x_1+x_2) + \\mathbbm{1}_{x\\ge 1}(x_2).\n\\end{equation}\nEquivalently, if we use notations \n\\begin{equation}\\label{exor}\n    \\bm x = (x_1, x_2)^T, \n    \\bm{W_1} = \\left[\n    \\begin{array}{cc}\n        1 & 0 \\\\\n        1 & 1 \\\\\n        0 & 1 \n    \\end{array}\n    \\right],\n    \\bm{W_2} = \\left[\n    \\begin{array}{c}\n        1  \\\\\n        -2 \\\\\n        1 \n    \\end{array}\n    \\right],\n\\end{equation}\nthen equation \\eqref{exor} is equivalent to the expression obtained from the general definition following equation \\eqref{enn}\n\n% Marvin Minsky and Seymour Papert (1969) showed that it was impossible for a single layer perceptron network to learn an XOR function. \nIn this example, we simply specified the solution, then showed that it obtained zero error. In a real situation, there might be billions of model parameters and billions of training examples, so one cannot simply guess the solution as we did here. Instead, a gradient-based optimization algorithm can find parameters that produce very little error.\n\n% {\\bf Backpropagation}. Backpropagation is a common method of training artificial neural networks and used in conjunction with an optimization method such as gradient descent. The algorithm repeats a two phase cycle, propagation and weight update. When an input vector is presented to the network, it is propagated forward through the network, layer by layer, until it reaches the output layer. The output of the network is then compared to the desired output, using a loss function, and an error value is calculated for each of the neurons in the output layer. The error values are then propagated backwards, starting from the output, until each neuron has an associated error value which roughly represents its contribution to the original output.\n\n% {\\bf Loss function}. For backpropagation to work, two assumptions are made about the form of the error function. The first is that it can be written as an average $E = \\frac{1}{n}\\sum_xE_x$ over error functions $E_x$, for individual training examples, $x$. The reason for this assumption is that the backpropagation algorithm calculates the gradient of the error function for a single training example, which needs to be generalized to the overall error function. In practice, training examples are placed in batches, and the error is averaged at the end of the batch, which is then used to update the weights. The second assumption is that it can be written as a function of the outputs from the neural network.\n\n% {\\bf Example loss function}. Let $y$, $y'$ be vectors in $\\mathbb R^n$. Select an error function $E(y, y')$ measuring the difference between two outputs. The standard choice is $E(y, y') = 1/2\\|y-y'\\|^2$. The error function over $n$ training examples can be written as an average: \n% \\begin{equation}\n%   E=\\frac{1}{2n}\\sum_x\\|y(x)-y'(x)\\|^2\n% \\end{equation}\n% In order to demonstrate the idea of linear feedforward network, we give two examples \n\n% %Gradient computation:\n% We use Back Propagation to compute the gradient of loss function $(L)$. Firstly, we have a training set by which we can train our model: Training set:$\\{(x^i,y^i)|i=1,...,P\\}$. Then we introduce the approximating function: $F(x)=\\sigma(W^Tx+\\theta)$. Namely, we use $\\{(x^i, \\hat{y}^i)|\\hat{y}^i=F(x^i)\\}$  to approximate the relationship between $x^i$ and $y^i$. After defining the approximating function, we want to compute and minimize the bias(or distance) between our approximation $\\hat{y}^i$ and the real data $y^i$, so we introduce the loss function (L): L=$\\frac{1}{2}\\Sigma_{i=1}^{P}(y^i-\\hat{y}^i)^2=\\frac{1}{2}\\Sigma_{i=1}^{P}(y^i-F(x^i))^2$. After this step, our work switch to minimize the loss function (L). Usually, we use gradient descent method. Thus we must compute the gradient of our loss function. Back propagation is one of the most popular method we use to compute the gradient of loss function. The essence of back propagation is just variable substitution, we set: $a=W^Tx+\\theta, f=\\sigma(a)$. Then the computation of gradient by back propagation is just using chain rule to compute the gradient of loss function:\n\n% \\\t$\\frac{\\partial{L}}{\\partial{f^i}}=y^i-f^i$\n\n% \\\t$\\frac{\\partial{L}}{\\partial{a}}=\\frac{\\partial{L}}{\\partial{f^i}}\\frac{\\partial{f^i}}{\\partial{a}}=(y^i-f^i)\\sigma'(a)=(y^i-f^i)\\frac{1}{cosh^2(a)}$\n\n% %Example: approximate quadratic function:\n\n% Implement a neural network with two layers of fully connected weights, and use it to approximate quadratic function $f(x) = x^2$.\n\n% Firstly, we obtain the training data, that is, generate 100 values of inputs, find the corresponding function value. And then, we determine hyper-parameters, with two layers of weights, there should be one hidden layer. Decide how many neurons there should be which will depend on the amount of data.\n\n% The third step is to initialize weights, biases, and the learning rate. After that, we come to feedforward process which is to compute the output from each input value. We use the approximating function F to give the approximating value with respect to each point in training data. Then we want to compute the gradient of our loss function in order to minimize it. We often use back propagation, the steps of back propagation is defined in the previous section. Then we repeat feedforward process and back propagation several times when loss function becomes small enough. Now the model is trained. Finally, we test our neural network by generating another set of inputs and the corresponding value of f. Compute the loss of these test values, if the results are also small, we can say that our model is well-trained.\n\n% %Improving the performance of back-propagation:\n\n% There are several tricks to improve the performance of back-propagation: The first one is to avoid local minima which are not the global minima of our models. For example, we can make our loss function to become a convex function which has only one minimum. The second one is to keep derivatives from going to zero, if the derivative is very small, our decent efficiency becomes very low. The third choice is to compensate for error attenuation for deep layers or reduce learning rate when weights oscillate. Next one, we prefer to use small random initial random weights and small initial learning rate to avoid \"herd effect\", if the learning rate is large, the loss function may grow rather than decrease after each iteration.\n\n\n\n\n\\section{Training a neural network model} \n{\\color{red}LZ: repeated material removed}\n% The error of a neural network with respect to a sample $(\\bm{x},\\bm{y})$ is defined by a loss function\n% \\begin{equation}\n% \\label{eloss}\n% L(\\bm{x}, \\bm{y}; \\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) = \\frac{1}{2}\\|\\bm{y} - G_d(\\bm{x})\\|^2.\n% \\end{equation}\n\n% The goal of training a neural network model is to find values for parameters $(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})$ such that the total loss\n% \\begin{equation}\n% \\label{etotalloss}\n% L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) = \\sum_{i=1}^m L(\\bm{x^i}, \\bm{y^i}; \\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})\n% \\end{equation}\n% is very small. The parameters are adjusted according to $L_{total}$ using the following process called \\textit{back-propagation}:\n% \\begin{equation}\n% \\label{ebp}\n% \\aligned\n% \\bm{\\delta^d} =& \\frac{\\partial}{\\partial \\bm{a_d}}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})\\\\\n% =& \\sum_{i=1}^m \\frac{\\partial}{\\partial \\bm{a_d}}L(\\bm{x^i}, \\bm{y^i}; \\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})\\\\\n% =& \\sum_{i=1}^m \\big(\\bm{y^i} - G_d(\\bm{x_i})\\big)\\\\\n% \\bm{\\delta^k} =& \\frac{\\partial}{\\partial \\bm{a_k}}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})\\\\\n% =& \\frac{\\partial L_{total}}{\\partial \\bm{a_{k+1}}}\\frac{\\partial \\bm{a_{k+1}}}{\\partial \\bm{a_k}}\\\\\n% =& \\bm{\\delta^{k+1}}\\bm{W_k^T}\\sigma'(\\bm{W_k^Ta_k}+\\bm{\\theta_k}), k=1,...,d-1.\n% \\endaligned\n% \\end{equation}\n% For sigmoid activation function, we can apply Lemma \\ref{lsig} and obtain\n% \\begin{equation}\n% \\label{ebpsig}\n% \\bm{\\delta^k} =\\bm{\\delta^{k+1}}\\bm{W_k^T}\\circ \\sigma(\\bm{W_k^Ta_k}+\\bm{\\theta_k}) \\circ (\\bm{1} - \\sigma(\\bm{W_k^Ta_k}+\\bm{\\theta_k})), k=1,...,d-1.\n% \\end{equation}\n\n% Here $\\circ$ means element-wise multiplication of two vectors. The computation of $\\bm{\\delta^k}$ depends on the knowledge of $\\bm{\\delta^{k+1}}$, and hence the name back-propagation. The gradient of the loss function with respect to each parameter can be computed as follows: for each $k=1,...,d$ we have\n% \\begin{equation}\n% \\label{ebpparam}\n% \\aligned\n% \\frac{\\partial}{\\partial \\bm{W_k}}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) =& \\frac{\\partial}{\\partial G_k}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d})\\bm{a_k}=\\bm{\\delta^k}\\bm{a_k}\\\\\n% \\frac{\\partial}{\\partial \\bm{\\theta_k}}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) =& \\frac{\\partial}{\\partial G_k}L_{total}(\\bm{W_1},...,\\bm{W_d},\\bm{\\theta_1},..,\\bm{\\theta_d}) = \\bm{\\delta^k}\n% \\endaligned\n% \\end{equation}\n% Here $G_0 = \\bm{x}$. To obtain the expression in \\eqref{ebpparam} we use the following properties of matrix differentiation\n% \\begin{equation}\n% \\label{ediff}\n% \\aligned\n% \\frac{\\partial }{\\partial \\bm{A}}L(\\bm{Ax + b}) =& \\frac{\\partial L}{\\partial \\bm{Ax + b}}\\bm{X}\\\\\n% \\frac{\\partial }{\\partial \\bm{b}}L(\\bm{Ax + b}) =& \\frac{\\partial L}{\\partial \\bm{Ax + b}}\n% \\endaligned\n% \\end{equation}\n% (Add proof)\n\n% With the gradients computed, we use the following update rule to adjust the parameters: for $k=1,...,d,$\n% \\begin{equation}\n% \\label{ebpup}\n% \\aligned\n% \\bm{W_k} =& \\bm{W_k} - r\\frac{\\partial L_{total}}{\\partial \\bm{W_k}}\\\\\n% \\bm{\\theta_k} =& \\bm{\\theta_k} - r\\frac{\\partial L_{total}}{\\partial \\bm{\\theta_k}}\n% \\endaligned\n% \\end{equation}\n{\\bf Complexity} The arithmetic complexity of the back-propagation process is dominated by the matrix multiplication in \\eqref{ebp}. In practise variations of this algorithms such as \\textit{stochasitc gradient descent} (SGD) is used to avoid large-scale matrix multiplication.\n\n%\\section{A Back-Propagation Example}\n%We have seen a perceptron network with one hidden layer that represents the XOR function. In that case we hand-picked values for each parameter, while in practice a gradient-based optimization algorithm need to be applied. Here let's look at an example of finding a sigmoid network that approximate the XOR function.\n%\n%{\\bf XOR function}. Recall that the XOR (\"exclusive or\") function $f^*(x_1,x_2)$ takes two binary values $x_1$ and $x_2$ as input. Thus the domain of $f^*$ is $\\{(0,0),(0,1),(1,0),(1,1)\\}$. When exactly one of $(x_1,x_2)$ is equal to 1, the function returns 1. Otherwise, it returns 0.\n%\n%For the learning of XOR function, we are going to use a neural network with two input units, one hidden layer with three sigmoid units, and one output unit. Additionally, the hidden layer and the output layer will include a bias. The weights and biases are usually initialized with random values. Here for the ease of illustration we set the initial values as:\n%\n%\\begin{equation}\n%\\bm{W_1} = \\left[\n%\\begin{array}{ccc}\n%0.1 & 0.2 & 0.3\\\\\n%0.4 & 0.5 & 0.6\n%\\end{array}\n%\\right]\n%,\n%\\bm{W_2} = \\left[\n%\\begin{array}{c}\n%0.1\\\\\n%0\\\\\n%-0.1\n%\\end{array}\n%\\right]\n%,\n%\\bm{\\theta_1}= \\left[\n%\\begin{array}{c}\n%0.1\\\\\n%0.1\\\\\n%0.1\n%\\end{array}\n%\\right]\n%,\n%\\bm{\\theta_2} = 0.1.\n%\\end{equation}\n%\n%Note that in practice, the initial values for parameters are usually determined from a Gaussian distribution (possibly with normalization). This neural network model can be expressed mathematically as\n%\n%\\begin{equation}\n%\\bm{y} = \\bm{W_2^T}\\sigma(\\bm{W_1^Tx}+\\bm{\\theta_1})+\\bm{\\theta_2}\n%\\end{equation}\n%\n%{\\bf The forward pass.} For each input tuple from $\\{(0,0),(0,1),(1,0),(1,1)\\}$, we calculate the output value (by convention $\\sigma((x_1, ...,x_n)^T)=(\\sigma(x_1),... \\sigma(x_n))^T)$)\n%\\begin{enumerate}\n%\\item\n%input: $\\bm{x} = (0,0)^T$.\n%Hidden layer:\n%\\begin{equation}\n%\\aligned\n%\\bm{a} =& \\bm{W_1^Tx}+\\bm{\\theta_1} = (0.1,0.1,0.1)^T\\\\\n%\\bm{b} =& \\sigma(\\bm{a}) = (0.525,0.525,0.525)^T\n%\\endaligned\n%\\end{equation}\n%Output layer:\n%\\begin{equation}\n%\\bm{y} = \\bm{W_2^Tb}+\\bm{\\theta_2} = 0.1\n%\\end{equation}\n%\n%\\item\n%input: $\\bm{x} = (0,1)^T$.\n%Hidden layer:\n%\\begin{equation}\n%\\aligned\n%\\bm{a} =& \\bm{W_1^Tx}+\\bm{\\theta_1} = (0.5,0.6,0.7)^T\\\\\n%\\bm{b} =& \\sigma(\\bm{a}) = (0.622,0.646,0.668)^T\n%\\endaligned\n%\\end{equation}\n%\n%Output layer:\n%\\begin{equation}\n%\\bm{y} = \\bm{W_2^Tb}+\\bm{\\theta_2} = 0.0954\n%\\end{equation}\n%\n%\\item\n%input: $\\bm{x} = (1,0)^T$.\n%Hidden layer:\n%\\begin{equation}\n%\\aligned\n%\\bm{a} =& \\bm{W_1^Tx}+\\bm{\\theta_1} = (0.2,0.3,0.4)^T\\\\\n%\\bm{b} =& \\sigma(\\bm{a}) = (0.550,0.574,0.599)^T\n%\\endaligned\n%\\end{equation}\n%\n%Output layer:\n%\\begin{equation}\n%\\bm{y} = \\bm{W_2^Tb}+\\bm{\\theta_2} = -0.0951\n%\\end{equation}\n%\\item\n%input: $\\bm{x} = (1, 1)^T$.\n%Hidden layer:\n%\\begin{equation}\n%\\aligned\n%\\bm{a} =& \\bm{W_1^Tx}+\\bm{\\theta_1} = (0.6,0.8,1.0)^T\\\\\n%\\bm{b} =& \\sigma(\\bm{a} = (0.646,0.690,0.731)^T\n%\\endaligned\n%\\end{equation}\n%\n%Output layer:\n%\\begin{equation}\n%\\bm{y} = \\bm{W_2^Tb}+\\bm{\\theta_2} = 0.0914\n%\\end{equation}\n%\\end{enumerate}\n%\n%{\\bf Calculating the total error.} The set of inputs and outputs for XOR function includes\n%\\begin{align*}\n%    \\bm x^1 =& (0,0)^T, y^1 = 0\\\\\n%    \\bm x^2 =& (0,1)^T, y^2 = 1\\\\\n%    \\bm x^3 =& (1,0)^T, y^3 = 1\\\\\n%    \\bm x^4 =& (1,1)^T, y^4 = 0\n%\\end{align*}\n%The expression for the neural network model is\n%\\begin{equation}\n%G(\\bm x; \\bm W_1, \\bm W_2, \\bm \\theta_1, \\bm \\theta_2) = \\bm W_2^T\\sigma(\\bm W_1^T+\\bm\\theta_1)+\\bm\\theta_2.\n%\\end{equation}\n%We can now calculate the error for each output neuron using the squared error function and sum them to get the total error:\n%\\begin{equation}\n%L(\\bm x; \\bm W_1, \\bm W_2, \\bm \\theta_1, \\bm \\theta_2) = \\frac{1}{2}\\sum_i (\\bm{y^i} - G(\\bm x^i; \\bm W_1, \\bm W_2, \\bm \\theta_1, \\bm \\theta_2))^2= 0.828\n%\\end{equation}\n%\n%Here the sum is over all four possible inputs. Note that The $\\frac{1}{2}$ is included so that exponent is canceled when we differentiate later on. The result is eventually multiplied by a learning rate anyway so it doesn't matter that we introduce a constant here.\n%\n%{\\bf The Backward Pass}\n%Our goal with back-propagation is to update each of the weights in the network so that they cause the actual output to be closer the target output, thereby minimizing the error for each output neuron and the network as a whole.\n%\n%\\begin{enumerate}\n%\\item\n%Loss function: $L = 1/2\\sum_i(\\bm{y^i} - G(\\bm{x^i}))^2$\n%\\begin{equation}\n%\\frac{\\partial L}{\\partial \\bm{y}} = \\sum_i \\bm{y^i} - G(\\bm{x^i}) = 0.0915\n%\\end{equation}\n%\\item\n%Output layer: $\\bm{y} = \\bm{W_2^Tb}+\\bm{\\theta_2}$, $\\bm{b} = \\sigma(\\bm{a})$\n%\\begin{equation}\n%\\aligned\n%\\frac{\\partial L}{\\partial \\bm{W_2}} =& \\bm{b}\\big(\\frac{\\partial L}{\\partial \\bm{y}}\\big)^T = \\left[\n%\\begin{array}{c}\n%-0.949\\\\\n%-0.988\\\\\n%-1.027\n%\\end{array}\n%\\right]\n%\\\\\n%\\frac{\\partial L}{\\partial \\bm{b}} =& \\bm{W_2}\\big(\\frac{\\partial L}{\\partial \\bm{y}}\\big)=\\left[\n%\\begin{array}{c}\n%0.00915\\\\\n%0     \\\\\n%0.00915\n%\\end{array}\n%\\right]\\\\\n%\\frac{\\partial L}{\\partial \\bm{\\theta_2}} =& \\frac{\\partial L}{\\partial \\bm{y}}=-1.618\\\\\n%\\frac{\\partial L}{\\partial \\bm{a}} =& \\frac{\\partial L}{\\partial \\bm{b}}\\circ \\sigma'(\\bm{a}) = \\frac{\\partial L}{\\partial \\bm{b}}\\circ \\bm{b} \\circ (\\bm{1}-\\bm{b})\n%=\\left[\n%\\begin{array}{c}\n%0.0032\\\\\n% 0.0002      \\\\\n%-0.0022\n%\\end{array}\n%\\right]\n%\\endaligned\n%\\end{equation}\n%Here $\\circ$ represents element-wise multiplication, and $\\bm{1}$ represents the vector with all coordinate equal to 1.\n%\\item\n%Hidden layer:\n%\\begin{equation}\n%\\aligned\n%\\frac{\\partial L}{\\partial \\bm{W_1}} =& \\bm{x}\\big(\\frac{\\partial L}{\\partial \\bm{a}}\\big)^T = \\left[\n%\\begin{array}{ccc}\n%-0.0203 & 0        &  0.0199\\\\\n%-0.0191 & 0        &  0.0182\n%\\end{array}\n%\\right]\\\\\n%%\\frac{\\partial L}{\\partial \\bm{x}} =& \\bm{W_1}\\big(\\frac{\\partial L}{\\partial \\bm{a}}\\big)\\\\\n%\\frac{\\partial L}{\\partial \\bm{\\theta_1}} =& \\frac{\\partial L}{\\partial \\bm{a}}=\\left[\n%\\begin{array}{c}\n%0.00209\\\\\n%0\\\\\n%-0.00180\n%\\end{array}\n%\\right]\n%\\endaligned\n%\\end{equation}\n%\\item\n%Update parameters: fix learning rate $r = 0.01$\n%\\begin{equation}\n%\\aligned\n%\\bm{W_1} =& \\bm{W_1} - r\\frac{\\partial L}{\\partial \\bm{W_1}}\\\\\n%\\bm{W_2} =& \\bm{W_2} - r\\frac{\\partial L}{\\partial \\bm{W_2}}\\\\\n%\\bm{\\theta_1} =& \\bm{\\theta_1} - r\\frac{\\partial L}{\\partial \\bm{\\theta_1}}\\\\\n%\\bm{\\theta_2} =& \\bm{\\theta_2} - r\\frac{\\partial L}{\\partial \\bm{\\theta_2}}\n%\\endaligned\n%\\end{equation}\n%\\end{enumerate}\n%\n%After 30000 iterations, the total loss will drop to $6.97\\times 10^{-9}$. See Figure \\ref{fbp} for how the loss drops as iteration goes on.\n%\\begin{figure}[H]\n%\\label{fbp}\n%\\centering\n%\\includegraphics[scale=0.5]{Backpropfig}\n%\\caption{Total Loss after Each Iteration}\n%\\end{figure}\n%\n%The parameters now take values:\n%\\begin{equation}\n%\\bm{W_1} = \\left[\n%\\begin{array}{ccc}\n%1.070 & 1.055 & 3.465\\\\\n%1.052 & 1.091 & 3.524\n%\\end{array}\n%\\right]\n%,\n%\\bm{W_2} = \\left[\n%\\begin{array}{c}\n%-2.355\\\\\n%-2.349\\\\\n%3.488\n%\\end{array}\n%\\right]\n%,\n%\\bm{\\theta_1}= \\left[\n%\\begin{array}{c}\n%-1.208\\\\\n%-1.233\\\\\n%-0.650\n%\\end{array}\n%\\right]\n%,\n%\\bm{\\theta_2} = -0.125.\n%\\end{equation}\n%And for each input the neural network will return:\n%\\begin{equation}\n%\\aligned\n%(0,0)\\mapsto 0.00004\\\\\n%(0,1)\\mapsto 0.99994\\\\\n%(1,0)\\mapsto 0.99994\\\\\n%(1,1)\\mapsto 0.00008\n%\\endaligned\n%\\end{equation}\n", "meta": {"hexsha": "e7caeb621969a98d0b47265d19976d6b8d76779e", "size": 37475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/intro.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/intro.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/intro.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": 61.2336601307, "max_line_length": 1142, "alphanum_fraction": 0.7122615077, "num_tokens": 11422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6337081355755507}}
{"text": "%!TEX program = xelatex\n\\documentclass[12pt]{article}\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{mathtools}\n\\usepackage{array}\n\n\\newcommand{\\N}{\\ensuremath{\\mathbb{N}}}\n\\newcommand{\\R}{\\ensuremath{\\mathbb{R}}}\n\n\\begin{document}\n\n\\section*{Problem 10}\n\n\\begin{proof}\n  \\begin{align*}\n    \\lim_{x \\to 1^-}\\frac{g(x)-g(1)}{x-1} = \\lim_{x \\to 1^-} 3(x+1) = 6.\n  \\end{align*}\n  If we want $g(x)$ to be differentiable at $x=1$, we need $\\lim_{x \\to 1^+}\\frac{g(x)-g(1)}{x-1}=6$ as well. For any $x>1$,\n  \\begin{align*}\n    \\frac{g(x)-g(1)}{x-1} &= \\frac{a+bx - 3}{x-1} = \\frac{bx +(a-3)}{x-1}.\n  \\end{align*}\n  If $b\\not=0$, then we can factor out $b$ and obtain\n  \\begin{align*}\n    \\frac{g(x)-g(1)}{x-1} &= \\frac{b(x +\\frac{a-3}{b})}{x-1}.\n  \\end{align*}\n  If either $b=0$, or $b\\not=0$ but $\\frac{a-3}{b} \\not=-1$, then the difference quotient does not converge as $x \\rightarrow 1$. Therefore, $\\frac{a-3}{b}=-1 \\implies   a+b=3$. In this case,\n  \\begin{align*}\n    \\lim_{x \\to 1^+}\\frac{g(x)-g(1)}{x-1} = \\lim_{x \\to 1^+} \\frac{b(x-1)}{x-1} = b.\n  \\end{align*}\n  Therefore, we need to let $b=6$ and $a=3-b=-3$ for this function to be differentiable at $x=1$.\n\\end{proof}\n\n\n\\section*{Problem 17}\n\n\\begin{proof}\n  For any $x\\not=0$, we have\n  \\begin{align*}\n    \\frac{f(ax)-f(bx)}{cx} &= \\frac{1}{c} \\cdot \\frac{f(ax)-f(bx)}{x}\\\\\n                           &= \\frac{1}{c} \\cdot \\frac{f(ax)-f(0)+f(0)-f(bx)}{x}\\\\\n                           &= \\frac{1}{c} \\left[ \\frac{f(ax)-f(0)}{x} - \\frac{f(bx)- f(0)}{x} \\right]\n  \\end{align*}\n  Therefore,\n  \\begin{align*}\n   \\lim_{x \\to 0} \\frac{f(ax)-f(bx)}{cx}\n   &= \\lim_{x \\to 0} \\frac{1}{c} \\left[ \\frac{f(ax)-f(0)}{x} - \\frac{f(bx)- f(0)}{x} \\right] \\\\\n   &= \\lim_{x \\to 0} \\frac{1}{c} \\left[ \\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} - \\lim_{x \\to 0}\\frac{f(bx)- f(0)}{x} \\right] \\\\\n   &= \\frac{1}{c} \\left[ \\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} - \\lim_{x \\to 0}\\frac{f(bx)- f(0)}{x} \\right].\n  \\end{align*}\n  We will first prove that $\\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} =af^\\prime(0)$. There are two cases:\n  \\begin{enumerate}\n    \\item If $a=0$, then for any $x \\not=0$,\n      \\begin{align*}\n        \\frac{f(ax)-f(0)}{x} = \\frac{f(0)-f(0)}{x} = 0.\n      \\end{align*}\n      So $\\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} = \\lim_{x \\to 0} 0 =af^\\prime(0) $.\n    \\item If $a\\not=0$, then we can define $h(x)=ax$, which is continuous at $x=0$. Since $a\\not=0$, if $x \\not= 0$, $h(x)=ax \\not = h(0)$. Then, by Exercise 6, we obtain\n      \\begin{align*}\n        \\lim_{x \\to 0}\\frac{f(h(x))-f(h(0))}{h(x)- h(0)} = f^\\prime(h(0)),\n      \\end{align*}\n      which is\n      \\begin{align*}\n        \\lim_{x \\to 0}\\frac{f(ax)-f(0)}{ax} = f^\\prime(0).\n      \\end{align*}\n      Therefore,\n      \\begin{align*}\n        \\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} &= \\lim_{x \\to 0}a \\cdot \\frac{f(ax)-f(0)}{ax}\\\\\n                                           &= \\lim_{x \\to 0}a \\lim_{x \\to 0}\\cdot \\frac{f(ax)-f(0)}{ax}\\\\\n                                           &= af^\\prime(0).\n      \\end{align*}\n  \\end{enumerate}\n  Similarly, we can obtain $\\lim_{x \\to 0}\\frac{f(bx)-f(0)}{x} =bf^\\prime(0)$. Hence,\n  \\begin{align*}\n   \\lim_{x \\to 0} \\frac{f(ax)-f(bx)}{cx}\n   &= \\frac{1}{c} \\left[ \\lim_{x \\to 0}\\frac{f(ax)-f(0)}{x} - \\lim_{x \\to 0}\\frac{f(bx)- f(0)}{x} \\right] \\\\\n   &= \\frac{1}{c} \\left[ a f^\\prime(0)  - b f^\\prime(0) \\right] \\\\\n   &= \\left[ \\frac{a-b}{c} \\right]  f^\\prime(0)\n  \\end{align*}\n\\end{proof}\n\n\n\\section*{Problem 5}\n\n\\begin{proof}\n  By contradiction; suppose $f^{-1}$ is differentiable at $f(x_0)$, then because $f$ is differentiable at $x_0$, by the Chain Rule,\n  \\begin{align*}\n    \\left[ f^{-1}(f(x_0)) \\right]^\\prime &= \\left( f^{-1} \\right)^\\prime \\left(f(x_0)\\right) \\cdot f^\\prime(x_0)\\\\\n                                         &= \\left( f^{-1} \\right)^\\prime \\left(f(x_0)\\right) \\cdot 0\\\\ &= 0.\n  \\end{align*}\n  However, since $f^{-1} \\left( f(x) \\right) =x$ for any $x \\in I$ and $(x)^\\prime = 1 \\not=0$. We have reached a contradiction. Therefore, $f^{-1}$ is not differentiable at $x_0$.\n\\end{proof}\n\n\\section*{Problem 8}\n\n\\begin{proof}\n  Since the sequence $\\{x_n\\}$ is strictly increasing and bounded, by the Monotone Convergence Theorem, $\\{x_n\\}$ converges to some number $x_0 = \\sup \\{x_n \\,|\\, n \\in \\N\\}$. Because $x_n$ is strictly increasing, and $x_0 \\geq x_n$ for any $n \\in \\N$, we can prove that $x_n < x_0$ for any $n \\in \\N$.\n\n  By contradiction; suppose there is some $k \\in \\N$ such that $x_k = x_0$, then $x_{k+1} > x_k = x_0$, which contradicts the fact that $x_0$ is the supremum of $\\{x_n\\}$. Therefore, for any $n \\in \\N$, $x_n < x_0$.\n\n  Since $f:\\R \\rightarrow \\R$ is differentiable, $f$ is also continuous, so the sequence $f(x_n)$ converges to $f(x_0)$ as well. Because $\\{f(x_n)\\}$ is monotone increasing and convergent, $f(x_n)$ is bounded above by the Monotone Convergence Theorem. We can prove that the upper bound is $f(x_0)$, so that $f(x_n) \\leq f(x_0)$ for any $n \\in \\N$.\n\n  By contradiction; suppose there is some $k \\in \\N$ such that $f(x_k) > f(x_0)$. Then, by assumption, for any natural number $m \\geq k$, $f(x_m) \\geq f(x_k)$. However, since $f(x_n)$ is convergent, for any $\\varepsilon > 0$, there exists some $N\\in \\N$ such that if $n \\geq N$\n  \\begin{align*}\n    |f(x_n) - f(x_0)| < \\varepsilon \\implies f(x_n)< f(x_0) + \\varepsilon.\n  \\end{align*}\n  Set $\\varepsilon = f(x_k) - f(x_0) > 0$, then for any natural number $m \\geq k$,\n  \\begin{align*}\n    f(x_m) \\geq f(x_k) = f(x_0) + \\varepsilon\n  \\end{align*}\n  We have reached a contradiction because for this particular $\\varepsilon$ there could not exist any $N \\in \\N$ such that $n \\geq N \\implies f(x_n)< f(x_0)+\\varepsilon$.\n  Therefore, $f(x_0) = \\sup \\{f(x_n) \\,|\\, x \\in \\N\\}$.\n\n  Hence, for any $x \\not=x_0$, because $x_n < x_0$, the difference quotient\n  \\begin{align*}\n    \\frac{f(x_n)-f(x_0)}{x_n-x_0}\n  \\end{align*}\n  is always defined. Also, since $f(x_n) \\leq f(x_0)$,\n  \\begin{align*}\n    \\frac{f(x_n)-f(x_0)}{x_n-x_0} \\geq 0\n  \\end{align*}\n  for any $n \\in \\N$.\n\n  Because $f$ is differentiable, the difference quotient converges to some nonnegative number, so\n  \\begin{align*}\n    f^\\prime(x_0) = \\lim_{n \\to \\infty} \\frac{f(x_n)-f(x_0)}{x_n-x_0} \\geq 0.\n  \\end{align*}\n\\end{proof}\n\n\n\\end{document}\n", "meta": {"hexsha": "fcd028a62fbcad9ffd261f73efc245bab90a5ab1", "size": 6271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "test/issues/mail-1/minimal.tex", "max_stars_repo_name": "tiagoboldt/vimtex", "max_stars_repo_head_hexsha": "001545e8a3ac81f4e6e3fb1302d409d8efb6361e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-14T21:15:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-14T21:15:31.000Z", "max_issues_repo_path": "test/issues/mail-1/minimal.tex", "max_issues_repo_name": "tiagoboldt/vimtex", "max_issues_repo_head_hexsha": "001545e8a3ac81f4e6e3fb1302d409d8efb6361e", "max_issues_repo_licenses": ["MIT"], "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/issues/mail-1/minimal.tex", "max_forks_repo_name": "tiagoboldt/vimtex", "max_forks_repo_head_hexsha": "001545e8a3ac81f4e6e3fb1302d409d8efb6361e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-12T05:30:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T05:30:39.000Z", "avg_line_length": 47.1503759398, "max_line_length": 347, "alphanum_fraction": 0.564503269, "num_tokens": 2618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6336846657283346}}
{"text": "\\lab{Python}{The Top-flight Trio}{The Top-flight Trio}\n\\label{Lab:PythonAdvanced}\n\n\\section*{NumPy + SciPy}\nNumpy provides an extremely efficient, multidimensional array datatype.  Mastery of this array datatype will be invaluable in your journey through numerical computing with Python.  Without NumPy arrays, Python would be too slow to be an effective tool.  The secret is that NumPy arrays are actually thin wrappers around C arrays.  Arrays use zero-based indexing, just like the rest of Python.  Many of the operations on NumPy arrays are almost as fast as they would be in C.  SciPy is a more feature rich environment than NumPy, but uses the array datatype provided by NumPy.  In these labs, we will almost always exclusively use the SciPy library.\n\nTo make the SciPy library available for use, you must import it.  We prefer to import SciPy into its own namespace for cleaner, clearer code.\n\\begin{lstlisting}[style=python]\n: import scipy as sp\n\\end{lstlisting}\n\nThe best way to conceptually think of NumPy arrays is to visualize nested arrays.  For a $3\\times4$ matrix, think of an array that contains three arrays each of length four.  Let's practice with a three dimensional matrix.\n\n\\[\nA = \\begin{bmatrix}\n\\begin{bmatrix}\n0 & 1 \\\\\n2 & 3 \\\\\n4 & 5 \\\\\n6 & 7 \\\\\n8 & 9\n\\end{bmatrix}\n\\begin{bmatrix}\n10 & 11 \\\\\n12 & 13 \\\\\n14 & 15 \\\\\n16 & 17 \\\\\n18 & 19\n\\end{bmatrix}\n\\begin{bmatrix}\n20 & 21 \\\\\n22 & 23 \\\\\n24 & 25 \\\\\n26 & 27 \\\\\n28 & 29\n\\end{bmatrix}\n\\end{bmatrix}\n\\]\n\nNumPy tracks each dimension by an axis number, also starting at $0$.  A one dimensional array has only one axis, a two dimensional, two axis.  An $n$ dimensional array has $n$ axis.  Our three dimensional array has dimensions $(3,5,2)$.  If we wanted to retrieve the value $16$, we would need to first retrieve index $1$ in axis $0$.\n\\[\nA[1] = \\begin{bmatrix}\n10 & 11 \\\\\n12 & 13 \\\\\n14 & 15 \\\\\n16 & 17 \\\\\n18 & 19\n\\end{bmatrix}\n\\]\n\nThen we need to retrieve index $3$ in axis $1$.\n\\[\nA[1,3] = \\begin{bmatrix}\n         16 & 17 \\\\\n         \\end{bmatrix}\n\\]\n\nThen we retrieve index $0$ of axis $2$.\n\\[\nA[1,3,0] = 16\n\\]\n\n\\subsection*{Manipulating Arrays}\nArray operations are, by default, element wise.  This includes multiplying arrays.\n\n\\begin{lstlisting}[style=python]\n: a = sp.array(range(9)).reshape(3,3)\n#flip a left right and up down.  We make b an upside down and backwards copy of a\n: b = sp.flipud(sp.fliplr(a))\n: a + b\narray([[8, 8, 8],\n       [8, 8, 8],\n       [8, 8, 8]])\n: a * b #this is NOT matrix multiplication\narray([[ 0,  7, 12],\n       [15, 16, 15],\n       [12,  7,  0]])\n: sp.dot(a, b) #this is matrix multiplication\narray([[ 9,  6,  3],\n       [54, 42, 30],\n       [99, 78, 57]])\n\\end{lstlisting}\n\nUnlike Python lists, arrays are allocated upon creation and are not dynamic.  It is expensive to change the dimensions of an array after it has been allocated.  We will demonstrate this by adding columns to an array vs allocating the entire array and changing the elements.\n\n\\begin{lstlisting}[style=python]\ndef allocateAll(n):\n    #allocate an nxn array\n    A = sp.zeros((n,n))\n    for a in xrange(n):\n        for b in xrange(n):\n            A[a, b] = sp.math.cos(a*b)\n    return A\n\ndef appendOne(n):\n    A = sp.array([])\n    for a in xrange(n):\n        for b in xrange(n):\n\t    A = sp.append(A, sp.math.cos(a*b))\n    return A.reshape(n, n)\n\\end{lstlisting}\n\n\\begin{lstlisting}[style=python]\n: import mytimer\n: with mytimer.timer() as timer:\n:     for x in xrange(1, 50):\n:         timer.time(appendOne, x)\n:         timer.time(allocateAll, x)\n: #let's plot the results\n: import matplotlib.pyplot as plt\n: sizes = range(1,50)\n: plt.plot(sizes, timer.results['appendOne'], 'r')\n: plt.plot(sizes, timer.results['allocateAll'], 'b')\n: plt.show()\n\\end{lstlisting}\n\n\\begin{center}\n\\includegraphics[width=\\textwidth]{alloc_vs_resize.pdf}\n\\end{center}\n\nWhy the big difference?  When appending to an array, a new array has to be created with room for the new entry.  Then each element of the old array has to be copied to the new array ending with the new value being inserted at the end of the array.  It is best to allocate space for the final array and change the elements in the array as needed.\n\n\\section*{Saving and Loading Arrays}\nSciPy allows you to save arrays for later use and load them back again.\n\\begin{lstlisting}[style=python]\n: A = sp.rand(9,9)\n: B = sp.random.randint(50, size=(10,10))\n: sp.save(\"testA\", A) #saves a single array to a file\n: sp.savez(\"testAB\", A = A, B = B) #save multiple arrays to a file\n: a = sp.load(\"testA.npy\")\n: z = sp.load(\"testAB.npz\")\n: z.keys() #the arrays referenced by key\n\\end{lstlisting}\n\n\\begin{problem}\nDefine a function that will generate an array with the multiplication table for a number, $n$.  Make the function as short and concise as possible.\n\\end{problem}\n\n\\section*{Matplotlib}\nMatplotlib is a 2D plotting library for Python that can produce publication quality plots and graphs.  This library provides the visualization component to our numerical computing toolbox.\n\nWe import Matplotlib and make it available under the \\li{plt} namespace.\n\\begin{lstlisting}[style=python]\n: import matploblib.pyplot as plt\n: x = sp.linspace(0, 2*sp.pi)\n: plt.plot(x, sp.cos(x))\n: plt.show()\n\\end{lstlisting}\n\nPlotting with Matplotlib works much the same way as plotting with MATLAB.  Many of the command share similar names and accept similar inputs.  For a better idea of what Matplotlib can do, please visit their website at \\url{http://matploblib.sourceforge.net}\n\n\\section*{Practice}\nLet us look at the efficiency of NumPy arrays.  We will do this by implementing the Sieve of Eratosthenes using both arrays and lists.\n\n\\begin{problem}\nImplement the Sieve of Eratosthenes using Python lists.  Make the implementation \n\\end{problem}\n", "meta": {"hexsha": "c843fffd40afecb201dbc91581615dfb36d40595", "size": 5762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/advanced.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": "Python/advanced.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": "Python/advanced.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": 36.4683544304, "max_line_length": 648, "alphanum_fraction": 0.7034015967, "num_tokens": 1630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.6336846628189152}}
{"text": "\\section{Deep Learning: Basics}\n\\subsection{Basics}\n\\subsection{Activation Functions}\n\\subsection{Loss Functions}\n\\subsection{Backpropagation}\n\\subsection{Regularization Methods}\n\\subsection{Optimization Algorithms}\n\\subsection{Convolutional Networks}\n\\subsection{Recurrent Networks}\nRecurrent networks allow us to work with sequences, where $x_t$ is the input\nat time $t$, $h_t$ is the hidden state at time $t$, and $h_{t-1}$ is the\nprevious hidden state. RNNs allow us to propagate information through the\nhidden state $h$. Hidden states defualt to zero.\n\\subsubsection{Elman RNN}\nThe Elman RNN is the simplest layers, yet prone to both the vanishing and\nexploding gradient problem.\n\\begin{equation}\n  h_t = \\tanh \\left( W_{ih} x_t + b_{ih} + W_{hh} h_{t-1} + b_{hh} \\right)\n\\end{equation}\nHere, $W$ are weight matricies, and $b$ are bias vectors, one each for the\ninput and hidden vectors.\n\\subsubsection{Long Short-Term Memory}\nLSTM RNNs mitigate the vanishing gradient problem. They involve a more complex\nset of equations corresponding to gates that control the amount of infomation\nto propagate through the sequence. Here, $i$ is the input gate, $f$ is the\nforget gate, $g$ is the cell gate, and $o$ is the output gate. LSTMs have\ntwo hidden inputs, hidden state $h_t$ and cell state $c_t$.\n\\begin{equation}\n  \\begin{split}\n    i_t \\quad =& \\quad \\sigma \\left( W_{ii} x_t + b_{ii} + W_{hi} h_{t-1} + b_{hi} \\right) \\\\\n    f_t \\quad =& \\quad \\sigma \\left( W_{if} x_t + b_{if} + W_{hf} h_{t-1} + b_{hf} \\right) \\\\\n    g_t \\quad =& \\quad \\tanh \\left( W_{ig} x_t + b_{ig} + W_{hg} h_{t-1} + b_{hg} \\right) \\\\\n    o_t \\quad =& \\quad \\sigma \\left( W_{io} x_t + b_{io} + W_{ho} h_{t-1} + b_{ho} \\right) \\\\\n    c_t \\quad =& \\quad f_t \\circ c_{t-1} + i_t \\circ g_t \\\\\n    h_t \\quad =& \\quad o_t \\circ \\tanh \\left( c_t \\right) \\\\\n  \\end{split}\n\\end{equation}\nHere, $\\sigma$ is the sigmoid function.\n\\subsubsection{Gated Recurrent Unit}\nGRU RNNs are another rnn layer designed to mitigate the vanishing gradient\nproblem. Here, we have the $r$ reset gate, $z$ update gate, and $n$ is the\nnew gate. $\\sigma$ is the sigmoid function.\n\\begin{equation}\n  \\begin{split}\n    r_t \\quad =& \\quad \\sigma \\left( W_{ir} x_t + b_{ir} + W_{hr} h_{t-1} + b_{hr} \\right) \\\\\n    z_t \\quad =& \\quad \\sigma \\left( W_{iz} x_t + b_{iz} + W_{hz} h_{t-1} + b_{hz} \\right) \\\\\n    n_t \\quad =& \\quad \\tanh \\left( W_{in} x_t + b_{in} + r_t \\circ \\left( W_{hn} h_{t-1} + b_{hn} \\right) \\right) \\\\\n    h_t \\quad =& \\quad \\left(1-z_t\\right) \\circ n_t + z_t \\circ h_{t-1} \\\\\n  \\end{split}\n\\end{equation}\n\\subsubsection{Bidirectional RNNs}\nBidirectional RNNs run two separate RNN layers on the forward and reverse\nsequence, and then concatenates them into one output vector.\n\\begin{equation}\n  \\begin{split}\n    \\overrightarrow{h_f} \\quad =& \\quad \\operatorname{RNN}\\left(\\overrightarrow{x}\\right) \\\\\n    \\\\\n    \\overleftarrow{h_r} \\quad =& \\quad \\operatorname{RNN}\\left(\\overleftarrow{x}\\right) \\\\\n    \\\\\n    h_o \\quad =& \\quad \\left[\\overrightarrow{h_f} \\,;\\, \\overrightarrow{h_r} \\right] \\\\\n  \\end{split}\n\\end{equation}\nWhere $\\operatorname{RNN}$ can be any of the 3 previously mentioned layers.\n\\subsubsection{Vanishing/Exploding Gradient}\nThe vanishing and exploding gradient phenomena are often encountered in the\ncontext of RNNs. The reason why they happen is that it is difficult to\ncapture long term dependencies because of multiplicative gradient that can\nbe exponentially decreasing/increasing with respect to the number of layers.\n\\subsubsection{Gradient Clipping}\nGradient clipping is a technique used to cope with the exploding gradient\nproblem sometimes encountered when performing backpropagation.\nBy capping the maximum value for the gradient, this phenomenon is\ncontrolled in practice.\n\\begin{equation}\n  \\nabla \\mathcal{L}_{clipped} = \\min \\left( \\nabla \\mathcal{L}, \\, C  \\right)\n\\end{equation}\nFor some max value $C$.\n", "meta": {"hexsha": "d695846fb1f477a762c903fe2e1f3c835e41f064", "size": 3904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/dl_basics.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/dl_basics.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/dl_basics.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": 50.0512820513, "max_line_length": 117, "alphanum_fraction": 0.7090163934, "num_tokens": 1235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6336846617386331}}
{"text": "\\section{Linear Algebra}\n\\par Before anything else, I strongly recommend watching a series of short videos that will give you a very graphical notion of Linear Algebra. That series of videos is \\href{https://www.youtube.com/watch?v=fNk_zzaMoSs&list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab&index=1}{\\uline{“Essence of linear algebra” by 3Blue1Brown}}.\n\n\\vspace{1cm}\n\\par Here will be presented a concise analysis of Linear Algebra topics ranging from:\n\\begin{itemize}\n    \\item various topics from one of the best resources to learn linear algebra, the MIT professor \\textbf{Gilber Strang}'s \\href{https://ocw.mit.edu/courses/mathematics/18-06-linear-algebra-spring-2010/video-lectures/}{\\uline{lectures}}\n    \\item a summary of the above course can be found in \\href{https://medium.com/sho-jp/towards-understanding-linear-algebra-part-1-d43710535503}{\\ul{here}}\n    by Sho Nakagome (``A neuroengineer researching Brain Computer Interface (BCI)'');\n    \\item geometric interpretations on a basic matrix, from \\href{https://www.coranac.com/documents/geomatrix/}{\\ul{here}};\n    \\item orthogonality, from MIT \\href{https://ocw.mit.edu/courses/mathematics/18-06sc-linear-algebra-fall-2011/least-squares-determinants-and-eigenvalues/orthogonal-vectors-and-subspaces/MIT18_06SCF11_Ses2.1sum.pdf}{\\ul{here}};\n    \\item important information for Signal Processing and various other applications.\n\\end{itemize}\n\n\n\\subsection{What is a matrix?}\n\\par We know what a matrix looks like, but what it is exactly? \n\\par Well, it can be seen as a group of vectors, as an equation and probably as many other things I haven't figured out yet.\n\n\\subsubsection{A system of Equations}\n\\par Let's start as seeing it as means of simplifying the process of solving a set of equations. Imagine that we have the following equations:\n\n\\begin{equation}\n\\begin{cases}\n    3x + 5y = 11 \\\\\n    x + 4y = 6\n\\end{cases}\n\\end{equation}\n\n\\par These can be written in matrix from like this:\n\n\\begin{equation}\n    \\begin{bmatrix}\n        1 & 2 \\\\\n        3 & 4\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        x \\\\\n        y\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        11 \\\\\n        6\n    \\end{bmatrix}\n\\end{equation}\n\n\\par And solvable through the Row Echelon Form (REF):\n\\begin{equation} \\label{eq:ref}\n    \\begin{bmatrix}[cc|c]\n        3 & 5 & 11\\\\\n        1 & 4 & 6\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}[cc|c]\n        1 & 4 & 6\\\\\n        0 & -7 & -7\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}[cc|c]\n        1 & 4 & 6\\\\\n        0 & 7 & 7\n    \\end{bmatrix}\n\\end{equation}\n\n\\par Is important to note that to obtain the REF, only \\ul{elementary equation operations} can be used. These are the sum/subtraction of two equations, the multiplication of a equation by a scalar different from 0 and change the place of the equations. In the particular case of \\eqref{eq:ref} the operations that took place were: row1 - 3*row2, switch rows and multiply the last row by -1.\n\\par From the our new form, is trivial to go back to the equation formula and directly attribute values to x and y. However, a few calculations are still required. The absolute best way is using the Reduced Row Echelon Form (RREF). This consists of using the rows with less elements to ``cut out'' elements from the other rows, leading to a very simplified matrix (see \\eqref{eq:rref})\n\n\\begin{equation}\\label{eq:rref}\n    \\begin{bmatrix}[cc|c]\n        1 & 4 & 6\\\\\n        0 & 7 & 7\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}[cc|c]\n        1 & 4 & 6\\\\\n        0 & 1 & 1\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}[cc|c]\n        1 & 0 & 2\\\\\n        0 & 1 & 1\n    \\end{bmatrix}\n\\end{equation}\n\n\n\\par Note that this RREF is unique and characterised by 1's in the diagonal and in stairs, i.e the only non-zero entry in that column starting with the leftmost column. In this form, all results can be obtained immediately.\n\\par However, putting a matrix in this form isn't always possible. For instance, is impossible to do so if two rows are \\bb{linearly dependent} meaning that is possible to multiply a constant to one to obtain the other - seeing rows as equations, linear dependency can be thought of an equation that adds absolutely no other constraint to the solution set or, in other words, does the exact same as one equation that already exists thus can be discarded hence ending with more unknowns than equations.\n\n\\par Before further analysing the concept of linear dependency and all that derives from that, is pertinent to have yet another look at the matrix. A geometric interpretation is often useful.\n\n\\subsubsection{Vectors in Space}\n\\par Exactly, have you thought your matrix could be vectors in space?\n\\par Well, maybe this decomposition helps to thing about it:\n\n\\quickimage{./Images/algebra/1.jpeg}{.3}\n\n\\par Thus we can imagine the vectors (5,4) and (3,1) is space. And one solution to obtain the vector (11, 6) is by multiplying 2 by the first vector and 1 by the second.\n\n\\par Note that we broke the matrix in half and gave it a meaning: ``What do you have to multiply to this vector and to this vector to obtain the vector you want?'' Where the vectors were the columns of the matrix. And the solution were the x and the y that were going to scale those vectors.\n\n\\par One can also think, despite being a bit more complicated, that what we want is to write (11, 6) in the basis of those two vectors (3,1) and (5,4). This is how the matrix represents a transformation. We are transforming the \"normal\" into the space defined by those two vectors. Further note that that space is given by the column vectors of the matrix! This will be important in the future.\n\\par Let's have a look at basis and spaces.\n\n\\subsection{Basis, Spaces and Subspaces}\n\n\\par A space is nothing more than a set of vectors that can be obtained from a linear combination from vectors in the basis. \n\n\\par If we want to take a subset of a space that is also a space we call that a subspace.\n\n\\par About basis: these are the vectors which when linearly combined generate a certain space. Note that one space can have infinite many basis. Actually, any set of N linearly independent vectors from a space with dimension N is a basis of that space. A set of vectors is only considered a basis if it spans a space (all linear combinations of its vectors create a space) and the vectors in it are linearly independent. \n\n\\par A good image to describe what \"span\" is:\n\n\\quickimage{./Images/algebra/3.jpeg}{.3}\n\n\n\\subsubsection{Column Space or Range}\n\n\\par The range of A (ran(A)) is the space spanned by the columns of A.\n\n\\quickimage{./Images/algebra/2.jpeg}{.3}\n\n\\par As expected, the row space is nothing more than the exact same thing for the rows. \n\n\\subsubsection{Row Nullspace or Kernel}\n\n\\par The kernel of A (ker(A)) is the space created by the vectors that when A is applied to them the result is 0.\n\\par Mathematically, the nullspace of a is nothing more than the vectors $x$ that lead to $A x = 0$. \n\\par Note that that thinking from before as \"what vectors should be multiplied to get a certain solution\" will now have a problem: there can be more than one answer to the null result. This only happens if there is a problem with the transformation. If the transformation is well done (if the matrix has full rank), then the column subspace will be the full space and anything multiplied to the matrix will have one and only one solution. If the problem/matrix is ill-conditioned (the rank is less than the dimension of the vectors of the columns), then there can be more than one solution to a give problem. \n\n\n\\Vhrulefill\nFrom an answer in \\href{https://math.stackexchange.com/questions/987146/why-null-space-and-column-space/987657#987657}{\\uline{math.stackexchange.com}}: \n``Let's suppose that the matrix A represents a physical system. As an example, let's assume our system is a rocket, and A is a matrix representing the directions we can go based on our thrusters. So what do the null space and the column space represent?\n\nWell let's suppose we have a direction that we're interested in. Is it in our column space? If so, then we can move in that direction. The column space is the set of directions that we can achieve based on our thrusters. Let's suppose that we have three thrusters equally spaced around our rocket. If they're all perfectly functional then we can move in any direction. In this case our column space is the entire range. But what happens when a thruster breaks? Now we've only got two thrusters. Our linear system will have changed (the matrix A will be different), and our column space will be reduced.\n\nWhat's the null space? The null space are the set of thruster instructions that completely waste fuel. They're the set of instructions where our thrusters will thrust, but the direction will not be changed at all.''\n\n\\Vhrulefill\n\n\\par If you are someone with some linear algebra background you might have spotted some kind of connection between the null space and the column space. So it is worth to talk now about the rank and the relation these spaces.\n\n\\subsection{Rank and Spaces relationships}\n\n\\par The rank of the matrix is nothing more than the number of pivots in the Reduced Row Echelon Form.\n\\par Seeing a matrix as a set of equations with N variables, a full rank matrix has rank N meaning that is possible to discover the N variables without ambiguity. If the matrix is rank deficient or ill-ranked, that means we have too many unknowns for our equations.\n\n\\par Is common sense that if a matrix has more columns than rows, it won't have full rank as this is exactly the same as saying it will have more unknowns than equations.\n\n\\par In terms of the relations between the spaces: was it evident so far that the less precise is the matrix (the less rank it has compared to full rank), the more it will nullify vectors, in other words, take away their identity and the more vectors would the space that gets to zero have.\n\n\\par Therefore, the sum of the dimensions of the column span and nullsubspace should equal the rank that the matrix needs to be full rank, i.e the number of unknowns or simply the number of columns.\n\n\n\n\n\n\n(there are a few more subspaces and we still need to explain the question that is asked every time.)\n\n\n", "meta": {"hexsha": "a33ffdc1acc200c7005bcbb866cb6ec0c3ecfb73", "size": 10212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/LinearAlgebra.tex", "max_stars_repo_name": "jmoraispk/TheDocument", "max_stars_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_stars_repo_licenses": ["MIT"], "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/LinearAlgebra.tex", "max_issues_repo_name": "jmoraispk/TheDocument", "max_issues_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_issues_repo_licenses": ["MIT"], "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/LinearAlgebra.tex", "max_forks_repo_name": "jmoraispk/TheDocument", "max_forks_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_forks_repo_licenses": ["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.2682926829, "max_line_length": 609, "alphanum_fraction": 0.7468664316, "num_tokens": 2592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6336846584547862}}
{"text": "\\documentclass[master.tex]{subfiles}\n\\setcounter{section}{1}\n\n\\newcommand{\\poly}[3]{\\sum_{#1=0}^#3 {#2}_{#1}x^{#1}}\n\\newcommand{\\polyex}[2]{{#1}_#2 x^{#2} + {#1}_{#2-1}x^{#2-1} + \\ldots + {#1}_1 x + {#1}_0}\n\n\\begin{document}\n\\section{Ring Theory}\n\\subsection{Basic Definitions}\n\\newcommand{\\F}{\\mathbb{F}} \\newtheorem*{notation}{Notation}\n% Lecture 10/27/2016\n\n\\begin{defn*}\n  A \\emph{ring} is set \\(R\\) together with two binary operations \\(+\\) and \\(\\cdot\\) satisfying\n  \\begin{enumerate}[label=(\\roman*)]\n  \\item \\((R,+)\\) is an abelian group (denote the additive identity by \\(0\\))\n  \\item \\(\\cdot\\) is associative, \\((xy)z=x(yz)\\) for all \\(x,y \\in R\\)\n  \\item There exists a multiplicative identity (denoted \\(1 \\in R\\)).\n  \\item Distribution laws hold:\n    \\begin{align*}\n      x(y+z) &= xy + xz\\\\\n      (x+y)z &= xz+yz\n    \\end{align*}\n  \\end{enumerate}\n\\end{defn*}\n\n\\begin{defn*}\n  A \\emph{commutative ring} is a ring with the additional property that \\(xy=yx\\) for all \\(x,y \\in R\\).\n\\end{defn*}\nNotice that if multiplication is commutative either distribution law implies the other. One of the most basic\nobservations one can make is that \\(R\\) is the trivial ring \\(\\iff 1=0\\).\n\n\\begin{example*}\n  A few familiar rings: \\[\\Z,\\Z_n,\\Q,\\R,\\C\\] A non-commutative ring:\n  \\[M_n(\\F), n \\ge 2\\] or more generally take any ring \\(R\\).\n\\end{example*}\n\n\\begin{defn*}\n  A \\emph{skew field (or division ring)} is a ring \\(R\\) such that \\(R \\neq \\{0\\}\\) and \\(R \\setminus \\{0\\}\\) is a group\n  under multiplication.\n\\end{defn*}\n\n\\begin{defn*}\n  A \\emph{field} is a commutative skew field.\n\\end{defn*}\n\n\\begin{example*}\n  An example of a skew field is\n  \\[\\H = \\R + \\R i + \\R j + \\R k\\]\n\\end{example*}\n\nOne may form direct products of rings in the usual manner.\n\n\\begin{defn*}\n  A \\emph{ring homomorphism} is map \\(\\varphi \\colon R \\to S\\) between rings \\(R\\) and \\(S\\) satisfying\n  \\begin{enumerate}[label=(\\arabic*)]\n  \\item \\(\\varphi(x+y)=\\varphi(x)+\\varphi(y)\\)\n  \\item \\(\\varphi(xy)=\\varphi(x)\\varphi(y)\\)\n  \\item \\(\\varphi(1_R)=1_S\\)\n  \\end{enumerate}\n\\end{defn*}\n\nIn keeping with our demand that all of rings have unity, we also force our homomorphisms to respect the unital\nstructure. In particular our ring homomorphisms are morphisms in the category of commutative rings.\n\n\\begin{example*}\n  For us a map \\funcdeclaration{\\varphi}{R}{R \\times R}{r}{(r,0)} is not a ring homomorphism as\n  \\(1_{R \\times R} = (1,1)\\) while \\(\\varphi(1)=(1,0)\\).\n\\end{example*}\n\n\\begin{defn*}\n  A subset \\(S\\) of a ring \\(R\\) is a \\emph{subring} of \\(R\\) if\n  \\begin{enumerate}[label=(\\arabic*)]\n  \\item \\(S\\) is closed under both operations\n  \\item \\(1_R \\in S\\)\n  \\end{enumerate}\n\\end{defn*}\n\n\\begin{example*}\n  Under this definition \\(R \\times \\{0\\}\\) is not a subring of \\(R \\times R\\) as \\(1_R \\not \\in R \\times R\\) as long as\n  \\(R\\neq\\{0\\}\\).\n\\end{example*}\n\n\\begin{defn*}\n  An element \\(x \\in R\\) is said to be a \\emph{zero divisor} of \\(R\\) if there exists an element \\(y \\in R\\) such that\n  \\(y \\neq 0\\) and\n  \\[xy = 0 \\qquad \\text{ or } \\qquad yx = 0.\\]\n\\end{defn*}\n\n\\begin{defn*}\n  The commutative ring \\(R\\) is an \\emph{integral domain} if its only zero divisor is \\(0\\).\n\\end{defn*}\n\n\\begin{example*}\n  \\(\\Z_n\\) integral domain \\(\\iff n\\) is prime\n\\end{example*}\n\n\\begin{prop*}\n  \\(R\\) finite integral domain \\(\\implies\\) \\(R\\) is field.\n\\end{prop*}\n\n\\begin{defn*}\n  A \\(x \\in R\\) is a \\emph{unit} if \\(xy=1\\) and \\(yx=1\\).\n\\end{defn*}\n\n\\begin{defn*}\n  The group of units \\(R^\\times\\) of a ring is\n  \\[R^\\times = \\{x \\in R \\mid x\\text{ is a unit}\\}.\\]\n\\end{defn*}\n\n\\begin{example*}\n  \\begin{align*}\n    \\Z^\\times &= \\{-1,1\\}\\\\\n    \\Z_n^\\times &= \\{\\bar{a} \\mid (a,n)=1\\}\n  \\end{align*}\n\\end{example*}\n\n\\begin{prop*}\n  If \\(\\varphi \\colon R \\to S\\) is a homomorphism and \\(x \\in R^{\\times}\\) then \\(\\varphi(x) \\in S^\\times\\). In\n  particular this means \\(\\varphi(R^\\times) \\le S^\\times\\).\n\\end{prop*}\n\nEven if \\(\\varphi \\colon R \\twoheadrightarrow S\\) the image \\(\\varphi(R^\\times)\\) might not equal \\(S^\\times\\).\n\n\\begin{example*}\n  Consider the surjective function \\funcdeclaration{\\varphi}{\\Z}{\\Z_n}{a}{\\bar{a}} but \\(|\\Z_n^\\times|=\\varphi(n)>2\\) if\n  \\(n \\ge 7\\)\n\\end{example*}\n\n\\begin{notation}\n  From this point onwards \\(R\\) denotes a \\textbf{commutative ring}.\n\\end{notation}\n\n\\begin{defn*}\n  A non-empty subset \\(I \\subset R\\) is an \\emph{ideal} if\n  \\begin{enumerate}[label=(\\roman*)]\n  \\item \\(x,y \\in I \\implies x+y \\in I \\)\n  \\item \\(x \\in I, r \\in R \\implies rx \\in I\\)\n  \\end{enumerate}\n\\end{defn*}\nCondition one may be rephrased as \\((I,+)\\) forms an abelian group.\n\\begin{prop*}\n  An ideal \\(I=R \\iff 1 \\in R \\iff I \\cap R^\\times \\neq \\emptyset\\)\n\\end{prop*}\n\n\\begin{notation}\n  If \\(I\\) is an ideal of \\(R\\) we denote it as \\(I \\unlhd R\\).\n\\end{notation}\n\n\\begin{prop}\n  A ring homomorphism \\(\\varphi \\colon R \\to S\\) if \\(I \\unlhd R\\), \\(J \\unlhd S\\) then\n  \\[\\varphi(I) \\unlhd S \\iff \\varphi \\text{ is surjective }\\]\n  while\n  \\[\\varphi^{-1} \\unlhd R \\text{ is always true.}\\]\n\\end{prop}\n\n\\begin{defn*}\n  Let \\(I,J \\unlhd R\\) then we define\n  \\begin{align*}\n    I+J &:= \\{x+y \\mid x \\in I, y \\in J\\} \\unlhd R\\\\\n    IJ  &:= \\left\\{\\sum_{l=0}^nx_l y_l \\mid n \\in \\N, x_l \\in I, y_l \\in J\\right\\}.\n  \\end{align*}\n\\end{defn*}\nWe have defined \\(IJ\\) in the above manner to force \\(IJ\\) to be an abelian group, and hence an ideal.\n\n\\begin{defn*}\n  Given an ideal \\(I \\unlhd R\\) we may form the \\emph{quotient ring} denote \\(R/I\\) as follows\n  \\[R/I = \\{a+I\\mid a \\in R\\}.\\] This forms a ring under addition and multiplication by representatives.\n\\end{defn*}\n\n\\begin{thm}[Isomorphism Theorems For Rings] Given a ring homomorphism \\(\\varphi \\colon R \\to S\\). Then\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(\\varphi(R)\\) is a subring of \\(S\\) and \\(\\ker(\\varphi)=\\{r \\in R \\mid \\varphi(r)=0\\} \\unlhd R\\)\n  \\item \\(R/\\ker \\varphi \\isom \\varphi(R)\\)\n  \\item \\(I,J \\unlhd R\\) with \\(I \\subset J \\implies\\)\n    \\[J/I\\unlhd R/I\\] and\n    \\[(R/I)/(J/I) \\isom R/S.\\]\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{prop}{Correspondence Theorem}\n  Let \\(I \\unlhd R\\) define \\funcdeclaration{\\pi}{R}{R/I}{a}{\\bar{a}} Then there is a bijection\n  \\[\\{J \\unlhd R \\mid I \\subset J\\} \\longleftrightarrow \\{\\text{Ideals of } R/I \\}\\] given by\n  \\[J \\longmapsto J/I\\] and\n  \\[L \\longmapsto \\pi^{-1}(L).\\]\n\\end{prop}\n\n\\begin{proof}\n  First \\(\\bar{J}=J/I=\\pi(J)\\unlhd \\bar{R}\\) since \\(\\pi\\) is surjective \\(\\pi^{-1}(L) \\unlhd R\\) and contains\n  \\(I=\\pi^{-1}(O)\\). Claim: \\(gf(J)=\\pi^{-1}(J/I)=J\\). Assume \\(x \\in R\\) with \\(x \\in \\pi^{-1}(J/I)\\) then\n  \\(\\pi(x) \\in J/I\\). Then \\(x+I=y+I\\) for some \\(y \\in J\\). Thus \\(x \\in y + I \\subset J\\). Lastly\n  \\(fg(L)=\\pi(\\pi^{-1}(L))\\) since \\(\\pi\\) is surjective.\n\\end{proof}\n\n\\begin{defn}\n  A proper ideal \\(I \\lhd R\\) is called\n  \\begin{enumerate}\n  \\item a \\emph{prime ideal} if\n    \\[xy \\in I \\implies x \\in I \\text{ or } y \\in I.\\]\n  \\item a \\emph{maximal ideal} if\n    \\[\\forall J \\lhd R,\\ I \\subseteq J \\implies I=J.\\]\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{prop}\n  For every \\(I \\lhd R\\) there exists a maximal ideal \\(M\\) such that \\(I \\subseteq M\\) and \\(M \\lhd R\\).\n\\end{prop}\n\n\\begin{proof}[Short Proof]\n  This follows from Zorn's Lemma.\n\\end{proof}\n\nHere we will be pedantic and write out the proof in its entirety as it sets the flavor of proof for the existence of\nother maximal entities.\n\n\\begin{lem*}[Zorn's Lemma]\n  If \\(A\\) is a nonempty partially ordered set such that every chain in \\(A\\) has an upper bound in \\(A\\), then \\(A\\)\n  contains a maximal element.\n\\end{lem*}\n\n\\begin{proof}[Detailed Proof]\n  Define set \\(S=\\{J \\lhd R \\mid I \\subset J\\} \\neq \\emptyset\\). This set is never empty as \\(I \\in S\\) by\n  construction. The set \\(S\\) is partially ordered \\(j \\le J' \\iff J \\subseteq J'\\). Now check that every chain in \\(S\\)\n  has an upper bound. Let \\((I_\\alpha)_{\\alpha in A}\\) be a chain in \\(S\\) where \\(\\alpha, \\beta \\in A\\) then\n  \\(J_\\alpha \\subseteq J_\\beta\\) or \\(J_\\beta \\subseteq J_\\alpha\\). Here we can compare any two elements. The candidate\n  for an upper bound is\n  \\[J=\\bigcup_{\\alpha \\in A} J_\\alpha.\\] We must check the following requirements:\n  \\begin{enumerate}[label=(\\arabic*)]\n  \\item \\(I \\subset J\\)\n  \\item \\(J \\unlhd R\\)\n  \\item \\(J \\neq R\\).\n  \\end{enumerate}\n  The condition (1) is immediate as \\(I \\subset J_\\alpha\\) for each \\(\\alpha \\in A\\). To see (2) let \\(x,y \\in J\\) and\n  \\(r \\in R\\). Then there exists \\(\\alpha, \\beta \\in A\\) such for \\(x \\in I\\) and \\(y \\in J_\\beta\\) without loss of\n  generality \\(J_\\alpha \\subseteq J_\\beta\\). Then \\(x+y \\in J_\\beta \\subseteq J\\). Since \\(J_\\alpha\\) is an ideal for\n  \\(x \\in J_\\alpha\\) we have \\(rx \\in J_\\alpha \\subset J\\). Thus \\(J\\) is an ideal of \\(R\\). Lastly to see (3) notice\n  \\(1 \\not \\in J\\) since \\(1 \\not \\in J_\\alpha\\) for all \\(\\alpha \\in A\\) as each of these ideals is proper. Recall an\n  ideal is the whole ring if and only if it contains unity, thus we have \\(J \\neq R\\). We have shown that the conditions\n  of Zorn's Lemma hold, hence \\(S\\) has a maximal element.\n\\end{proof}\n\n\\begin{prop}\n  \\(I \\unlhd R\\)\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(I\\) is a prime ideal \\(\\iff\\) \\(R/I\\) integral domain.\n  \\item \\(I\\) is a maximal ideal \\(\\iff\\) \\(R/I\\) is a field.\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item For \\(x,y \\in R\\), the following are equivalent:\n    \\[xy \\in I \\implies x \\in \\text{ or } y \\in I\\\\\\] \\[\\iff\\]\n    \\[\\bar{x}\\bar{y}=\\bar{0} \\implies \\bar{x}=\\bar{0} \\text{ or } \\bar{y}=\\bar{0}\\] \\[\\iff\\] \\[\\text{R/I is an\n        integral domain}\\]\n  \\item \\(I\\) is maximal \\(\\iff I + Rx = \\{a+rx \\mid r \\in R\\} \\unlhd R\\)\n    \\[\\iff\\]\n    \\[\\bar{R}\\bar{x}=\\bar{R} \\ \\forall \\bar{x} \\neq \\bar{0} \\in \\bar{R}\\]\n    \\[\\iff\\]\n    \\[\\text{All non-zero elements of \\(\\bar{R}\\) are units.}\\]\n  \\end{enumerate}\n\n  \\begin{cor*}\n    Every maximal ideal is prime.\n  \\end{cor*}\n\\end{proof}\n\n\\begin{rmk}\n  Recall from the Correspondence Theorem that there is a bijection between ideals of \\(R\\) that contain an ideal \\(I\\)\n  and the ideals of \\(R/I\\). This bijection may be restricted to either the prime ideals or the maximal ideals. Yielding\n  a bijection between the prime/maximal ideals of \\(R\\) containing \\(I\\) and the prime/maximal ideals of \\(R/I\\).\n\\end{rmk}\n\n\\begin{defn*}\n  Given \\(S \\subseteq R\\) the \\emph{ideal generated by \\(S\\) in \\(R\\)} denoted \\((S)\\) is the smallest ideal of \\(R\\)\n  containing \\(S\\). More specifically it is defined to be\n  \\[(S)=\\bigcap_{S \\subset I \\unlhd R} I\\]\n\\end{defn*}\n\n\\begin{notation}\n  Given a finite set \\(S=\\{x_1,\\ldots,x_n\\} \\subset R\\) we write \\((x_1,\\ldots,x_n)\\) for\n  \\(\\left(\\{x_1,\\ldots,x_n\\}\\right)\\) which is exactly the set of all linear combinations of the elements of \\(S\\) with\n  coefficients from \\(R\\).\n\\end{notation}\n\n\\begin{defn*}\n  For \\(x \\in R\\) the ideal \\((x)=Rx=\\{rx \\mid r \\in R\\}\\) is called the principal ideal generated by the element \\(x\\).\n\\end{defn*}\n\n\\begin{defn}\n  An integral domain \\(R\\) is called a \\emph{principal ideal domain (PID)} if every ideal of \\(R\\) is principle.\n\\end{defn}\n\n\\begin{examples}\n  \\(Z\\), \\(\\F\\), \\(\\F[x]\\)\n\\end{examples}\n\n\\begin{notation}\n  \\(a,b \\in R\\) we say \\emph{\\(a\\) divides \\(b\\)} or \\(b\\)is a multiple of \\(R\\) if \\(\\exists c \\in R\\) such that\n  \\(ac=b\\) denoted \\(a \\mid b\\).\n\\end{notation}\n\n\\begin{rmk} Let \\(a \\in R\\)\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(\\{b \\in R \\mid a \\mid b\\}=(a)\\)\n  \\item \\(a \\mid 0\\) since \\(0=a \\cdot 0 \\)\n  \\item \\(u \\in R^\\times \\implies u \\mid a\\) since \\(u(u^{-1}a)=a\\)\n  \\item \\(ac=b\\) should not be written as \\(c=\\frac{b}{a}\\)since in general \\(\\frac{b}{a}\\) is ambiguous. Ex in \\(\\Z_6\\)\n    \\(2 \\times 2 = 4\\) but \\(2 \\times 5 = 4\\) also so is \\(\\frac{4}{2}=2\\) or 5.\n  \\end{enumerate}\n\\end{rmk}\n\n\\begin{defn}\n  Two ideals \\(I, J \\unlhd R\\) are called \\emph{comaximal} if \\(I+J=R\\) (\\(\\iff \\exists a \\in I, b \\in J\\) such that\n  \\(a+b=1\\))\n\\end{defn}\n\n\\begin{lem}\n  Given finitely many ideals \\(I_1,\\ldots, I_n\\) that are pairwise comaximal, then \\(I_1 \\cdots I_{n-1}\\) and \\(I_n\\)\n  are comaximal and \\(\\bigcap_{j=1}^n I_J = I_1 \\cdots I_n\\)\n\\end{lem}\n\n\\begin{proof}\n  We proceed by induction on \\(n\\). Consider when \\(n=2\\). One must show that that \\(I_1,I_2\\) comaximal\n  \\(\\implies I_1 \\cap I_2 \\subset I_1I_2\\). The other inclusion is obvious. If \\(I_1\\) and \\(I_2\\) are comaximal then\n  there exists \\(a \\in I_1\\) and \\(b \\in I_2\\) such that \\(a+b=1\\). Take \\(x \\in I_1 \\cap I_2\\) then \\(x=x \\cdot 1 =\n  x(a+b)=xa+xb\\). Since \\(xa,xb \\in I_1 I_2\\) we have that \\(x \\in I_1 I_2\\) as desired.\n\n  Now we consider the case when \\(n \\ge 3\\). If \\(I_j,I_n\\) are comaximal for \\(1 \\le j \\le n-1\\) then there must exist\n  \\(a_j \\in I_j\\) and \\(b_j \\in I_n\\) with \\(a_j+b_j = 1\\). Now\n  \\[1=1 \\cdots 1 = \\prod_{j=1}^{n=1}{a_j + b_j}\\]\n  Expanding and we see\n  \\[\\prod_{j=1}^{n-1}(a_j+b_j) \\in a_1 \\cdots a_{N=1}+I_n\\]\n  Then \\((I_1 \\ldots I_{n-1}I_n)=I_1 \\ldots I_{n-1} \\cap I_n\\)\n  which by the inductive hypothesis is exactly \\(\\bigcap_{j=1}^n I_J\\).\n\\end{proof}\n\n\\begin{prop}[Chinese Remainder Theorem]\n  Let \\(I_1, \\ldots, I_n \\unlhd R\\) and\n  \\funcdeclaration{\\varphi}{R}{\\bigtimes_{j=1}^n}{r}{(r+I_j)_{1 \\le j \\le n}}\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(\\varphi\\) is a ring homomorphism with \\(\\ker \\varphi = \\bigcap I_j\\)\n  \\item If \\(I_1, \\ldots I_n\\) are pairwise comaximal then \\(\\ker \\varphi = \\prod_{j=1}^n I_n\\) and if \\(\\varphi\\) is\n    surjective then\n    \\[\\sfrac{\\varphi}{ \\prod_{j=1}^n I_j} \\cong \\bigtimes_{j=1}^n R/I_j\\]\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item trivial\n  \\item \\(\\ker \\varphi = \\prod_{j=1}^n I_j\\) follows (a) and 2.1.12.\n    By 2.1.12 we get \\(\\forall 1 \\le l \\le n\\) that the ideals \\(\\hat{I_l}=\\prod_{j\\neq l, j=1} I_j\\) and \\(I_l\\) are\n    comaximal. Then there exists \\(x_l \\in \\hat{I_l}\\)and \\(y_l \\in I_l\\) such that \\(x_l + y_l = 1\\). Then \\(x_l \\equiv\n    0 \\pmod{I_j \\forall j \\neq l}\\) (this means that \\(\\bar{x_l} \\equiv 1 \\pmod{I_l}\\) (or \\(x_l + I_l = 1 I_l\\))).\n\n    Given \\((a_j + I_j)_{1 \\le j \\le n} \\in \\bigtimes_{j=1}^n{R/I_j}, (a_j \\in R)\\). We set \\(x=sum_{l=1}^n{a_l x_l} \\in\n    R\\). Now let \\(\\bar{\\phantom{}}\\) denote mod \\(I_j\\) for some fixed \\(j\\).\n\n    \\begin{align*}\n      \\bar{x} &= \\sum_{l=1}^n \\bar{a_l}\\bar{x_l}\\\\ \\tag{\\(\\bar{x_l}=\\bar{0}\\) if \\(\\l \\neq j\\)}\n              &= \\bar{a_j}\\bar{x_j}\n              &= \\bar{a_j}\\bar{1}\\\\\n              &= a_j + I_j.\n    \\end{align*}\n    This argument may be made for each \\(1 \\le j \\le n\\). This means that \\(\\varphi(x)=(\\bar(a_j)_{1 \\le j \\le n})\\). We\n    have thus shown our map to be surjective.\n  \\end{enumerate}\n\\end{proof}\n  \\begin{example*}[Special Case \\(R = \\Z\\)]\n    \\begin{enumerate}[label=(\\alph*)]\n    \\item \\(n=2\\), \\(I_1=(m)\\), \\(I_2=(n)\\) with \\((m,n)=1 \\implies\\)\n      \\[\\sfrac{\\Z}{mn} \\cong \\sfrac{\\Z}{m} \\times \\sfrac{\\Z}{n}\\]\n      See 1.2.3 where we already derived this fact using more elementary means.\n    \\item \\(n\\) arbitrary \\(p_1 \\ldots p_n\\) are distinct primes, \\(l_1, \\ldots, l_n \\in \\N\\), \\(I_j = (p_j^{e_j})_{1\n        \\le j \\le n} \\implies\\) \\[\\sfrac{\\Z}{\\primedecomposition{p}{e}{n}} \\cong \\bigtimes_{j=1}^n\n        \\sfrac{\\Z}{p_j^{e_j}}.\\]\n      This means there is always a solution to the system of congruences \\(x \\equiv a_j \\pmod{p_j^{ej}}\\). The injection\n      is uniquely determined modulo the product.\n    \\end{enumerate}\n  \\end{example*}\n  Notice that the above follows from the fact \\(a,b \\in R \\implies (a)(b)=(ab)\\).\n\n  \\subsection{Ring of Fractions}\n  One may ask if there is a canonical way to embed every ring \\(R\\) into some larger field. If \\(R\\) is not an integral\n  domain it can not be embedded into a field, because then the field would contain zero divisors. However the answer is\n  always yes for integral domains.  We generalize the construction of \\(\\Q\\) from \\(\\Z.\\) Consider the embedding\n  \\[\\Z \\hookrightarrow \\Q.\\]\n  The elements of \\(\\Q\\) can be viewed as equivalence classes of \\(\\Z \\times Z \\setminus \\{0\\}\\) under the relation\n  \\[(a,b) \\sim (c,d) \\iff ad=bc.\\]\n\n  Main motivations for introducing the rings of fractions:\n  \\begin{enumerate}\n  \\item Embedding integral domains into fields\n  \\item The concept of localization (a way to add inverses to a ring)\n  \\end{enumerate}\n\n  Compare with [DF] sections 7.5 and 15.4.\n\n  \\begin{defn}\n    A subset \\(D\\) of \\(R\\) is called \\emph{multiplicatively closed} if\n    \\begin{enumerate}[label=(\\arabic*)]\n    \\item \\(d,d' \\in D \\implies dd' \\in D\\)\n    \\item \\(1_R \\in D\\)\n    \\end{enumerate}\n  \\end{defn}\n\n  \\begin{example*}\n    \\begin{enumerate}[label=(\\alph*)]\n    \\item \\(R\\) is integral domain \\(\\implies R \\setminus \\{0\\}\\) is multiplicatively closed. (This is in fact a\n      characterization of integral domains)\n    \\item Any ring \\(R\\) with prime ideal \\(P \\lhd R \\leadsto D = R \\setminus P\\). Notice that (a) is a consequence of\n      this. Since \\(\\{0\\}\\) is prime \\(\\iff R\\) is an integral domain.\n    \\item \\(x \\in R \\leadsto D= \\{x^n \\mid n \\in \\N_0\\}\\)\n    \\end{enumerate}\n  \\end{example*}\n\n  The goal is to invert the elements of \\(D\\) inside some larger ring. We will denote the ring \\(D^{-1}R\\). Following\n  the construction of \\(\\Q\\) from \\(\\Z\\) one would think that equivalence relation \\((r,d)\\sim (r',d')\\) would do the\n  trick, however this relation fails to be transitive for \\(R\\) that are not integral domains (one would be required to\n  cancel at a certain step). The correct equivalence relation is given by\n  \\[(r,d) \\sim (r',d') \\iff \\exists e \\in D \\text{ s.t. } e(rd'-r'd)=0. \\] It is tedious to check that this is\n  transitive, however it is. Notice that in the case that \\(R\\) is an integral domain and \\(0 \\neq \\in D\\) this reduces\n  to the naive relation as \\(e(rd'-r'd)=0\\) implies \\(rd'-r'd=0\\) since there are no zero divisors and \\(e\\) by\n  assumption is nonzero.\n\n  \\begin{notation}\n    In this context \\(\\frac{r}{d}\\) denotes the equivalence class with representative \\((r,d)\\).\n  \\end{notation}\n\n  Now we define\n  \\[D^{-1}R= \\left\\{\\frac{r}{d} \\mid r \\in R, d \\in D\\right\\}.\\] We endow it with the operations\n  \\begin{align*}\n    \\frac{r}{d}+\\frac{s}{e} &\\coloneqq \\frac{re+sd}{de}\\\\\n    \\frac{r}{d}\\cdot\\frac{s}{e} &\\coloneqq \\frac{rs}{de}.\n  \\end{align*}\n  Since we are working with equivalence classes one must check the well-definedness of these operations. One may do this\n  by using the definition of the equivalence relation. Finally one may check that \\((D^{-1}R,+,\\cdot)\\) forms a\n  commutative ring with unity \\(1=\\frac{1_R}{1_R}\\). Further we have accomplished are goal as each \\(d \\in D\\) is a unit\n  in \\(D^{-1}R\\) with inverse \\(\\frac{1}{d}\\).\n\n  \\begin{rmk*}\n    \\[D^{-1}R = \\{0\\} \\iff 0 \\in D\\\\\\]\n    \\[D^{-1}R = \\{0\\} \\iff \\frac{1}{1}=\\frac{0}{1} \\iff \\exists d \\in D \\text{ s.t. } d(1-0)=0 \\iff d=0\\]\n  \\end{rmk*}\n  Dummit and Foote over restrictive by excluding all zero divisors from being included in \\(D\\). Rather one must exclude\n  both a zero divisor and its partner from being in \\(D\\) as then \\(D\\) would contain zero, however there is nothing\n  wrong with having one of the pair. However one must exclude nilpotent elements as we saw that\n  \\(\\{x^n \\mid n \\in \\N_0\\}\\) is multiplicatively closed meaning \\(D\\) would also contain zero.\n  \\begin{example*}\n    An important example of \\(D\\) containing zero divisors, but still being non-trivial is\n    \\[D=R \\setminus P\\] where \\(P\\) is a prime ideal of \\(R\\). The ideal ideal \\(P\\) must contain one of each pair of\n    the zero divisors of \\(R\\) otherwise \\(R/P\\) would not be an integral domain, but \\(R/P\\) is an integral domain\n    since \\(P\\) is a prime ideal.\n  \\end{example*}\n  We have a canonical map: \\funcdeclaration{j}{R}{D^{-1}R}{r}{\\frac{r}{1}} If \\(R\\) is not an integral domain then \\(j\\)\n  is not injective (even if \\(0 \\not \\in D\\)). One may see this by realizing\n  \\[\\ker j = \\{r \\in R \\mid dr = 0\\}.\\]\n  We summarize our construction and its properties in the following proposition:\n  \\begin{prop}Given a commutative ring \\(R\\) with unity.\n    \\begin{enumerate}[label=(\\alph*)]\n    \\item For any multiplicatively closed subset \\(D \\subseteq R\\), \\(\\left(D^{-1}R,+,\\cdot\\right)\\) is a commutative ring with unity\n      called the ring of fractions with respect to \\(D\\).\n    \\item \\(D^{-1}R=\\{0\\}\\iff 0 \\in D\\)\n    \\item There is a canonical map: \\funcdeclaration{j}{R}{D^{-1}R}{r}{\\frac{r}{1}} under which\n      \\(j(D) \\subseteq D^{-1}R^\\times\\).\n    \\item If \\(R\\) is an integral domain and \\(0 \\not \\in D\\) then \\(j\\) is injective.\n    \\item If \\(R\\) is an integral domain and \\(D=R \\setminus \\{0\\}\\) then \\(D^{-1}R\\) is a field containing a copy of\n      \\(R\\), namely \\(j(R)\\). In this case \\(D^{-1}R\\) is called the field of fractions of \\(R\\).\n    \\end{enumerate}\n    \\begin{notation}\n      \\[\\FieldFrac{R}=(R\\setminus\\{0\\})^{-1}R.\\]\n    \\end{notation}\n  \\end{prop}\n  Notice that in the above definition we referred to the resultant construction with the article ``the''. This hints at\n  some uniqueness floating around. We make this rigorous by characterizing the universal property of our construction.\n  \\begin{prop}[Universal Property of \\(D^{-1}R\\)]\n    For any ring \\(S\\) and any ring homomorphism \\(\\varphi \\colon R \\to S\\) which satisfies\n    \\(\\varphi(D) \\subset S^\\times\\), then there exists a unique ring homomorphism\n    \\(\\tilde{\\varphi} \\colon D^{-1}R \\to S\\) making the following diagram commute\n    \\begin{figure}[h]\n      \\centering\n      \\begin{tikzcd}\n        R \\arrow[r,\"\\varphi\"] \\arrow[d,\"j\"]& S\\\\\n        D^{-1}R \\arrow[ru,dashed,\"\\tilde{\\varphi}\"]\n      \\end{tikzcd}\n    \\end{figure}\n\n    Note that we required $\\phi(D) \\subset S^\\times$ because each $d \\in D$ is invertible in $D^{-1}R$, and we need it to remain invertible in $S$.\n  \\end{prop}\n  \\begin{prop}\n    Let \\(R\\) be an integral domain with field of fractions \\(F=D^{-1}R\\). If \\(\\varphi \\colon R \\to K\\) is an injective\n    ring homomorphism, where \\(K\\) is a field, then \\(K\\) contains an isomorphic copy of \\(F\\).\n  \\end{prop}\n  In this sense \\(F\\) is the ``smallest'' field that contains \\(R\\).\n  \\begin{proof}\n    The injectivity of \\(\\varphi\\) implies that \\(\\varphi(D) \\subset K \\setminus \\{0\\} = K^\\times\\). Thus we may invoke\n    the universal property of the ring of fractions, hence there exists \\(\\tilde{\\varphi} \\colon F \\to K\\) with\n    \\(\\tilde{\\varphi} \\circ j = \\varphi\\). This map is not the trivial map.  \\(\\tilde{\\varphi}\\) is injective because $\\varphi$ is injective and \\(\\tilde{\\varphi} \\circ j = \\varphi\\).  So we have our embedding.\n  \\end{proof}\n  Now we examine the ideal structure of \\(D^{-1}R\\) where \\(R \\neq 0\\) and \\(0 \\not \\in D\\).\n  \\begin{rmk} \\mbox{}\n    \\begin{enumerate}[label=(\\alph*)]\n    \\item \\[I \\unlhd R \\leadsto D^{-1}I = \\left\\{\\frac{a}{d} \\mid a \\in I, d \\in D\\right\\}\\]\n    \\item \\[D^{-1}I = D^{-1}R \\iff D \\cap I \\neq \\emptyset\\]\n    \\end{enumerate}\n  \\end{rmk}\n\n  \\begin{prop}\n    Define the map\n    \\begin{align*}\n      \\{I \\lhd R \\mid D \\cap I = \\emptyset\\} &\\longrightarrow \\{\\text{proper ideals of } D^{-1}R\\}\\\\\n      I &\\longmapsto D^{-1} I.\n    \\end{align*}\n    \\begin{enumerate}[label=(\\alph*)]\n    \\item The map is surjective. In general it is not injective.\n    \\item If \\(P \\lhd R\\) is a prime ideal of \\(R\\) and \\(P \\cap D = \\emptyset\\), then \\(j(D^{-1}P)=P\\).\n    \\item The map restricted to the prime ideals of \\(R\\) is a bijection.\n    \\end{enumerate}\n  \\end{prop}\n\n  \\begin{defn}\n    Observe that if \\(P \\lhd R\\) is a prime ideal, then \\(D = R \\setminus P\\) is multiplicatively closed (To prove this, use the fact that a prime ideal is generated by a prime element).  In this case, the ring of fractions \\(D^{-1}R\\)\n    is denoted \\(R_P\\) and called the \\emph{localization} of \\(R\\) at \\(P\\).\n  \\end{defn}\n\n  \\begin{cor}\n    The map\n    \\begin{align*}\n      \\{Q \\lhd R \\mid Q \\text{ prime and } Q \\subset P\\} &\\longrightarrow \\{\\text{prime ideals of } R_P \\}\\\\\n      Q& \\longmapsto D^{-1}Q\n    \\end{align*}\n    is an inclusion preserving bijection.\n  \\end{cor}\n  Consequence \\(D^{-1}P=PR_P\\) is the unique maximal ideal of \\(R_P\\).\n\n  \\begin{defn*}\n    A commutative ring is called a \\emph{local ring} if it has a unique maximal ideal.\n  \\end{defn*}\n  \\begin{example}\n    \\(R=\\Z, P=(p)\\). Then\n    \\[\\Z_{(P)}=\\left\\{\\frac{a}{b} \\mid a,b \\in \\Z, p \\;\\text{does not divide}\\; b\\right\\} \\subseteq \\Q = \\Z_{(0)}\\]\n    By the previous result, \\(\\Z_{(P)}\\) has two ideals: \\(\\{0\\}\\) and \\((p)\\Z_{(p)}\\). Notice that\n    \\[(p)\\Z_{(p)}=\\left\\{\\frac{a}{b} \\mid p \\text{ does not divide } b, p \\mid a\\right\\}\\]\n  \\end{example}\n  \\subsection{Polynomial Rings}\n  How \\textbf{not} to define the polynomial ring \\(R[x]\\).\n  \\begin{align*}\n    R[x] = \\left\\{f \\colon R \\to R \\mid \\exists a_{i} \\in R : f(x)=\\sum_{i=1}^na_ix^i\\right\\}\n  \\end{align*}\n  i.e. as functions that admit a representation as a polynomial.\n  \\begin{example}\n    \\(R = \\Z_p = \\F_p\\) consider \\(x, x^p \\in \\F_p[x]\\). Problem: \\(x\\) and \\(x^p\\) define the same function but have\n    different representations.\n  \\end{example}\n\n  \\begin{defn}\n    The \\emph{polynomial ring} (in one variable over \\(R\\)) \\((R[X],+,\\cdot)\\) is the set\n    \\begin{align*}\n      R[X] \\coloneqq \\left\\{(a_i)_{i \\in \\N_0} \\mid a_i \\in R, \\text{ with all but finitely many entries zero}\\right\\}\n    \\end{align*}\n    with operations\n    \\begin{align*}\n      (a_i) + (b_i) &\\coloneqq (a_i + b_i)\\\\\n      (a_i)(b_i) &\\coloneqq \\left(\\sum_{i=0}^k a_ib_{k-i}\\right)_{k \\in \\N_0}.\n    \\end{align*}\n  \\end{defn}\n  One may form this checks a commutative ring with identity \\(1=(1,0,0,\\ldots)\\). What requires the most work is\n  checking that the multiplication is associative.\n  \\begin{rmk*}\n    Elements of \\(R[x]\\) are called polynomials. There is a natural embedding\n    \\begin{align*}\n      R &\\hookrightarrow R[X]\\\\\n      a &\\mapsto (a,0,0,\\ldots)\n    \\end{align*}.\n    There is a distinguished element called \\(x\\) in \\(R[X]\\), namely we let\n    \\[x = (0,1,0,\\ldots).\\] For \\(a=(a_i)_{i \\in \\N_0}\\) one checks\n    \\begin{align*}\n      (xa)_0 &= 0\\\\\n      (xa)_i &= (a_{i-1})\n    \\end{align*}.\n    In other words this element \\(x\\) has the property that it shifts the coefficients.\n  \\end{rmk*}\n\n\\begin{defn}\n  Any element \\(0 \\neq a \\in R[x]\\) can be uniquely written in the form \\(\\poly{i}{a}{d}\\) with all \\(a_i \\in R\\) and\n  \\(a_d \\neq 0\\). The integer \\(d\\) is called the \\emph{degree} and is denoted \\(\\deg(a)\\). Note that\n  \\[deg(a) = 0 \\iff a \\in R \\setminus \\{0\\}\\] The element \\(a_d\\) is called \\emph{the leading coefficient} of \\(a\\) and\n  is denoted by \\(\\ell(a)\\). The polynomial \\(a\\) is \\emph{monic} if \\(\\ell(a)=1\\). We also define\n  \\(\\ell(0) \\coloneqq 0\\) and \\(\\deg(0) \\coloneqq - \\infty\\). This representation admits the operations in the follow\n  form:\n  \\begin{align*}\n    \\poly{i}{a}{d}+\\poly{i}{b}{e} &= \\sum_{i=0}^{\\max\\{d,e\\}}(a_i+b_i)x^i\\\\\n    \\poly{i}{a}{d}\\poly{j}{b}{e}  &= \\sum_{k=0}^{d+e}\\left(\\sum_{i=0}^k a_i b_{k-i}\\right)x^k\n  \\end{align*}\n  where \\(a_i \\coloneqq 0\\) for \\(i > d\\) and \\(b_j \\coloneqq 0\\) for \\(j > e\\). In expanded form:\n  \\begin{align*}\n    \\poly{i}{a}{d}\\poly{j}{b}{e} &= a_0 b_0 + (a_0 b_1 + a_1 b_0)x + \\ldots + a_db_e x^{d+e}\n  \\end{align*}\n\\end{defn}\nI have omitted a very tedious verification of the uniqueness of the representation.\n\\begin{rmk}\n  In a similar way we define the \\emph{power series ring} denoted \\(R[[x]]\\) as follow\n  \\[R[[x]] \\coloneqq \\left\\{(a_i)_{i \\in \\N_0}\\} \\mid a_i \\in R\\right\\}.\\] Here we have simply dropped the requirement\n  that all but a finite amount of terms must be zero. We define the operations in the same manner. Further notice that\n  there are no infinite sums being carried out. Also there is a natural inclusion\n  \\[R[x] \\hookrightarrow R[[x]]\\]\n\\end{rmk}\n\n\\begin{lem}\n  Let \\(f,g \\in R[x]\\).\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(\\deg(f+g) \\le \\max \\{\\deg f, \\deg g\\}\\)\n  \\item If \\(\\ell(f)\\) is not a zero divisor of \\(R\\) we have\n    \\[\\deg(fg) = \\deg(f)+\\deg(g)\\]\n  \\end{enumerate}\n\\end{lem}\n\n\n\\begin{example*}\n  If \\(l(f)\\) is a zero divisor we might have \\(\\deg f \\ deg g < \\deg f + \\deg g\\). Consider \\(R = \\Z_6\\) then\n  \\begin{align*}\n    (1+2x)(1+3x) = (1+5x)\n  \\end{align*}\n\\end{example*}\n\n\\begin{prop}\n  Let \\(R\\) be an integral domain. Then\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item \\(f,g \\in R[x]\\), \\[\\deg(fg)=\\deg(f)+deg(g)\\]\n  \\item \\(R[x]\\) is an integral domain\n  \\item \\(R[x]^\\times = R^\\times\\)\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  \\begin{enumerate}[label=(\\alph*)]\n  \\item Assume \\(f \\neq 0\\) and \\(g \\neq 0\\). Then since \\(R\\) is an integral domain \\(\\ell(f)\\) and \\(\\ell(g)\\) are not\n    zero divisors. Then by lemma 2.3.4b we have that \\(\\deg(fg)=\\deg(f)+\\deg(g)\\).\n  \\item \\(f \\neq 0 \\neq g \\implies \\deg(fg)=\\deg(f)+\\deg(g)\\) thus \\(\\deg(fg) \\ge 0\\), hence \\(fg \\neq 0\\)\n  \\item \\(R \\hookrightarrow R[x] \\implies R^\\times \\subseteq R[x]^\\times\\). Suppose \\(f,g\\) are units in \\(R[x]\\), and\n    then use the previous part to show \\(\\deg(f)+\\deg(g)=0\\), and hence \\(f,g \\in R\\).\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{rmk}\n  \\begin{enumerate}\n  \\item \\(\\polyex{a}{d}{i} \\in R[x]^\\times \\iff a_1, \\ldots, a_d\\) are nilpotent.\n  \\item Power Series Ring \\(R[[x]]\\) is defined the same was a polynomial ring, but we remove the requirement that all\n    but a finite amount of terms are zero.\n  \\end{enumerate}\n\\end{rmk}\n\n\\begin{prop}\n  Let \\(\\varphi \\colon R \\to S\\) be a ring homomorphism, and a choice for where \\(x \\mapsto a\\) there exists a unique\n  \\begin{figure}[h] \\centering\n    \\begin{tikzcd}\n      R \\arrow[r,\"\\varphi\"] \\arrow[rd,hook]& S \\\\\n      & R[x] \\arrow[u,dashed,\"\\exists! \\tilde{\\varphi}_a\"]\n    \\end{tikzcd}\n  \\end{figure}\n\\end{prop}\n\n\\end{document}\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"master.tex\"\n%%% End:\n", "meta": {"hexsha": "edabb998cd6ce450bf74b81087e3bdd7225c0750", "size": 29746, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "server/resources/ring_theory.tex", "max_stars_repo_name": "Ankit-Jaiswal/ParTEX", "max_stars_repo_head_hexsha": "a6e0c53bc311d74853fc6eb66acbaaff46f03126", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-15T10:59:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-15T10:59:28.000Z", "max_issues_repo_path": "server/resources/ring_theory.tex", "max_issues_repo_name": "Ankit-Jaiswal/ParTEX", "max_issues_repo_head_hexsha": "a6e0c53bc311d74853fc6eb66acbaaff46f03126", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2018-07-16T04:07:56.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-11T14:04:26.000Z", "max_forks_repo_path": "server/resources/ring_theory.tex", "max_forks_repo_name": "Ankit-Jaiswal/ParTEX", "max_forks_repo_head_hexsha": "a6e0c53bc311d74853fc6eb66acbaaff46f03126", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-16T05:35:54.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-16T05:35:54.000Z", "avg_line_length": 44.4633781764, "max_line_length": 235, "alphanum_fraction": 0.6160492167, "num_tokens": 10818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872019117029, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.633684650432382}}
{"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,mathtools,commath}\n\n\\DeclareMathOperator{\\Tr}{Tr}\n\\DeclareMathOperator{\\Id}{Id}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\usepackage{braket}\n\\usepackage{mathrsfs}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem*{lemma}{Lemma}\n\\newtheorem*{corollary}{Corollary}\n\n\n\\title{Quantum Computing - Assignment 4}\n\\author{Kishlaya Jaiswal}\n\n\\begin{document}\n\n\\maketitle\n\n\\subsection*{Exercise 1}\n\nLet $x \\in \\mathbb{Z}_N^*$ where $N = p_1^{\\alpha_1} \\ldots p_l^{\\alpha_l}$.\n\nLet $r$ be the order of $x \\pmod{N}$ and $r_i$ be the order of $x \\pmod{p_i^{\\alpha_i}}$. Notice that $r$ is the lcm of $r_1, r_2, \\ldots, r_l$\n\nDenote by $\\nu_2(n)$ the largest power of $2$ dividing $n$.\n\nNote that $r_i \\mid r$ for each $1 \\leq i \\leq l$. So if $r$ is odd then so are $r_i$; otherwise if $x^{r/2} \\equiv -1 \\pmod{N}$ then $x^{r/2} \\equiv -1 \\pmod{p_i^{\\alpha_i}}$ and so $r_i \\nmid (r/2) \\implies$ $\\nu_2(r) = \\nu_2(r_i)$ for each $1 \\leq i \\leq l$. We get\n\n$$P(r \\text{ is odd or } x^{r/2} \\equiv -1 \\pmod{N}) \\leq P(\\text{largest power of 2 that divides each } r_i \\text{ is same})$$\n\nNow we quote a lemma (from Nielsen and Chuang) which uses the fact that $\\mathbb{Z}_{p^{\\alpha}}^*$ is cyclic for odd prime $p$, to estimate the fraction of elements with particular largest power of $2$ in the order of any element of $\\mathbb{Z}_{p^{\\alpha}}^*$:\n\\begin{lemma}\nLet $p$ be an odd prime. Let $\\nu_2\\left(\\abs{\\mathbb{Z}_{p^{\\alpha}}^*}\\right) = d$. Then\n$$P(2^d \\text{ divides order of a randomly chosen element of } \\mathbb{Z}_{p^{\\alpha}}^*) = \\frac12$$ \n\\end{lemma}\n\nAs a corollary, we immediately get that if $y$ is chosen randomly from $\\mathbb{Z}_{p^{\\alpha}}^*$ then for any $n$\n\n$$P(\\nu_2(y) = n) \\leq \\frac12$$\n\nUsing Chinese Remainder Theorem and that $|\\mathbb{Z}_N^*| = |\\mathbb{Z}_{p_1^{\\alpha_1}}^*| \\ldots |\\mathbb{Z}_{p_l^{\\alpha_l}}^*|$, we get that choosing $x$ at random from $\\mathbb{Z}_N^*$ is equivalent to choosing $x_i$ at random from $\\mathbb{Z}_{p_i^{\\alpha_i}}^*$ independently for each $1 \\leq i \\leq l$. We argue by induction on $l \\geq 2$, that $P(\\text{largest power of 2 that divides each } r_i, 1 \\leq i \\leq l, \\text{ is same}) = P(\\nu_2(r_1) = \\cdots = \\nu_2(r_l)) \\leq \\frac{1}{2^{l-1}}$\n\nIf $l=2$, then set $m = \\nu_2\\left(\\abs{\\mathbb{Z}^*_{p_2^{\\alpha_2}}}\\right)$\n\\begin{align*}\n    P(\\nu_2(r_1) = \\nu_2(r_2)) &= \\sum_{k=0}^m P(\\nu_2(r_1) = \\nu_2(r_2), \\nu_2(r_2) = k) \\\\\n    &= \\sum_k P(\\nu_2(r_1) = k) P(\\nu_2(r_2) = k) \\\\\n    &\\leq \\frac12 \\sum_k P(\\nu_2(r_1) = k) \\\\\n    &\\leq \\frac12 P(\\nu_2(r_1) \\geq 0) \\\\\n    &= \\frac{1}{2}\n\\end{align*}\n\nSuppose it is true for some $l-1 \\geq 2$, then set $m = \\nu_2\\left(\\abs{\\mathbb{Z}^*_{p_l^{\\alpha_l}}}\\right)$\n\\begin{align*}\n    P(\\nu_2(r_1) = \\cdots = \\nu_2(r_l)) &= \\sum_{k=0}^m P(\\nu_2(r_1) = \\cdots = \\nu_2(r_l), \\nu_2(r_l) = k) \\\\\n    &= \\sum_k P(\\nu_2(r_1) = \\cdots = \\nu_2(r_{l-1}) = k) P(\\nu_2(r_l) = k) \\\\\n    &\\leq \\frac12 \\sum_k P(\\nu_2(r_1) = \\cdots = \\nu_2(r_{l-1}) = k) \\\\\n    &\\leq \\frac12 P(\\nu_2(r_1) = \\cdots = \\nu_2(r_{l-1})) \\\\\n    &\\leq \\frac12 \\left(\\frac{1}{2^{l-2}}\\right) \\text{ (by inductive hypothesis)} \\\\\n    &= \\frac{1}{2^{l-1}}\n\\end{align*}\n\nTherefore, we get \n\\begin{align*}\n    P(x \\text{ is good}) &= 1 - P(x \\text{ is not good}) \\\\\n    &= 1 - P(r \\text{ is odd or } x^{r/2} \\equiv -1 \\pmod{N}) \\\\\n    &\\geq 1 - P(\\text{largest power of 2 that divides each } r_i \\text{ is same}) \\\\\n    &\\geq 1 - \\frac{1}{2^{l-1}}\n\\end{align*}\n\n\n\n\n\n\\subsection*{Exercise 2}\n\nLet $a_0, a_1, \\ldots$ be a sequence of positive reals then denote by\n$$[a_0, \\ldots a_n] = a_0 + \\frac{1}{a_1+\\frac{1}{a_2 + \\frac{1}{\\cdots + \\frac{1}{a_n}}}}$$\n\nWe have the following lemma (from Nielsen and Chuang):\n\\begin{lemma}\nLet $a_0, a_1, \\ldots $ be a sequence of positive reals and sequences $p_n, q_n$ defined inductively by $p_0 = a_0, p_1 = 1 + a_0a_1$ and $q_0 = 1, q_1 = a_1$ and for all $n \\geq 2$\n$$p_n = a_n p_{n-1} + p_{n-2}$$\n$$q_n = a_n q_{n-1} + q_{n-2}$$\nthen $\\frac{p_n}{q_n} = [a_0, \\ldots, a_n]$\n\\end{lemma}\n\nAs a corollary we immediately get the following results\n\\begin{corollary}\nLet $a_0, a_1, \\ldots$ be a sequence of positive integers and $\\frac{p_n}{q_n} = [a_0, \\ldots, a_n]$ then $\\forall n\\geq 0$\n\\begin{itemize}\n    \\item $p_n, q_n$ are positive integers\n    \\item $q_n p_{n-1} - p_n q_{n-1} = (-1)^n$\n    \\item $(p_n, q_n) = 1$\n    \\item Both $p_n$ and $q_n$ are strictly increasing sequence\n\\end{itemize}\n\\end{corollary}\n\n\\begin{proof}\nClearly $p_0 = a_0, p_1 = 1 + a_0a_1$ and $q_0 = 1, q_1 = a_1$ are integers. Now using strong induction we get that $p_n = a_np_{n-1} + p_{n-2}, q_n = a_nq_{n-1} + q_{n-2}$ are integers. \\\\\n\nFor $n=1$, $q_1 p_0 - p_1 q_0 = a_0a_1 - (1 + a_0a_1) = (-1)$. Assume $q_{n-1} p_{n-2} - p_{n-1} q_{n-2} = (-1)^{n-1}$, then we have\n\n$$q_n p_{n-1} - p_n q_{n-1} = (a_n q_{n-1} + q_{n-2})p_{n-1} - (a_n p_{n-1} + p_{n-2})q_{n-1} = -(q_{n-1} p_{n-2} - p_{n-1} q_{n-2}) = (-1)^n$$\n\nIf $d \\mid p_n$ and $d \\mid q_n$ then $d \\mid q_n p_{n-1} - p_n q_{n-1} \\implies d \\mid (-1)^n$. Hence $(p_n, q_n) = 1$.\n\nAs $p_n$ and $q_n$ are both strictly positive sequence and $a_n$ is a positive integer, we get $p_n = a_n p_{n-1} + p_{n-2} > a_n p_{n-1} \\geq p_{n-1}$. Similarly $q_n > q_{n-1}$.\n\\end{proof}\n\nNow suppose $x \\in \\mathbb{Q}$ and that $\\abs{x - \\frac{p}{q}} < \\frac{1}{2q^2}$ \n\nWe can assume $(p,q) = 1$ because otherwise write $p/q = p'/q'$ where $(p', q') = 1$ and note that $\\abs{x - \\frac{p'}{q'}} < \\frac{1}{2q^2} < \\frac{1}{2q'^2}$ and so we can replace $p/q$ with $p'/q'$. \\\\\n\nLet $[a_0, \\ldots, a_n]$ be the continued fraction for $\\frac{p}{q}$ and $[a_0, \\ldots, a_i] = \\frac{p_i}{q_i}$, $\\forall 0 \\leq i \\leq n$. Then $p_n = p$ and $q_n = q$ as both $(p,q) = (p_n,q_n) = 1$ \\\\\n\nIf $x = \\frac{p}{q}$, then $[a_0, \\ldots, a_n]$ is the continued fraction expansion for $x$ and so $p/q$ is a convergent of the continued fraction expansion of $x$.\n\nIf $\\frac{p}{q} = [a_0]$ then $p=a_0, q=1$. So $\\abs{x-a_0}$ is a rational less than $\\frac12$. \n\nIf $x > a_0$ then $0 < x-a_0 < 1 \\implies x-a_0 = [0,b_0,\\ldots, b_m] \\implies x = [a_0,b_0,\\ldots, b_m]$ \n\nOtherwise if $x < a_0$ then in this case we first note that $p/q = [a_0] = [a_0 - 1, 1]$ and since $\\frac12 < x-a_0 + 1 < 1 \\implies x - a_0 + 1 = [0,1,b_1\\ldots, b_m] \\implies x = [a_0-1,1,b_1,\\ldots, b_m]$ and so in both the cases, $p/q$ is a convergent of the continued fraction expansion of $x$ \\\\\n\nOtherwise let $x = [a_0, \\ldots, a_n, y]$ ($n>0$) and we solve for $y$ as follows:\n$$x = \\frac{yp_n + p_{n-1}}{yq_n + q_{n-1}} \\text{ (by above lemma)}$$ $$\\implies y = \\frac{p_{n-1}-xq_{n-1}}{xq_n - p_n} = \\frac{q_np_{n-1}-p_nq_{n-1}}{q_n^2(x - \\frac{p_n}{q_n})} - \\frac{q_{n-1}}{q_n} = \\frac{(-1)^n}{q_n^2(x - \\frac{p_n}{q_n})} - \\frac{q_{n-1}}{q_n}$$\n\nNow if $a_n = 1$, then we can re-write $[a_0, \\ldots, a_{n-1}, a_n] = [a_0, \\ldots, a_{n-1} + 1]$. Otherwise, we can re-write $[a_0, \\ldots, a_{n-1}, a_n] = [a_0, \\ldots, a_{n-1}, a_n-1, 1]$. Therefore, we can appropriately modify $n$ such that $(-1)^n\\left(x - \\frac{p_n}{q_n}\\right) > 0$. Hence we get \n$$y = \\frac{1}{q_n^2\\abs{x - \\frac{p_n}{q_n}}} - \\frac{q_{n-1}}{q_n} > 1$$\nbecause $q_n^2\\abs{x - \\frac{p_n}{q_n}} < \\frac12$ and $q_n > q_{n-1}$ as $q_n$ is increasing.\n\nFinally, since $x$ is rational and $p_n, q_n$ are integers, we get that $y$ is a positive rational and we can find a continued fraction expansion for $y = [b_0, \\ldots, b_m]$. Therefore, we get $x = [a_0, \\ldots a_n, b_0, \\ldots b_m]$ as required.\n\n\n\n\n\n\\subsection*{Exercise 3}\nLet $X$ be the set of all search elements (needles) and $\\ket \\beta = \\frac{1}{\\sqrt x} \\sum_{i \\in X} \\ket i$ where $x = |X|$\n\nAnd let $\\ket \\alpha = \\frac{1}{\\sqrt{N-x}} \\sum_{i \\not \\in X} \\ket i$ where $N$ is the total number of items.\n\nDenote by $\\ket \\psi$ the uniform superposition of all states, that is\n$$\\ket \\psi = \\frac{1}{\\sqrt N} \\sum \\ket i = \\sqrt{1 - \\frac x N} \\ket \\alpha + \\sqrt{\\frac x N} \\ket \\beta = \\cos \\theta \\ket \\alpha + \\sin \\theta \\ket \\beta$$\n\nwhere $\\cos \\theta = \\sqrt{1-x/N}$. We define three operators:\n\\begin{itemize}\n    \\item Oracle operator $O$ where $O\\ket i = - \\ket i$ if $i \\in X$ otherwise $O\\ket i = \\ket i$\n    \\item Diffusion operator $D$ where $D = 2 \\ket \\psi \\bra \\psi - I$\n    \\item Grover operator $G = DO$\n\\end{itemize}\n\nNote that $O\\ket \\alpha = \\ket \\alpha$ and $O\\ket \\beta = -\\ket \\beta$\n\nNext note that, $\\braket{\\psi | \\alpha} = \\cos \\theta$ and $\\braket{\\psi | \\beta} = \\sin \\theta$ and so $D\\ket \\alpha = 2\\cos \\theta \\ket \\psi - \\ket \\alpha$ and $D\\ket \\beta = 2\\sin \\theta \\ket \\psi - \\ket \\beta$. Let $\\ket \\phi = \\cos x \\ket \\alpha + \\sin x \\ket \\beta$ be any general vector in the plane $P$ of $\\ket \\alpha$ and $\\ket \\beta$, then we have:\n\n\\begin{align*}\n    G \\ket \\phi &= (\\cos x) G \\ket \\alpha + (\\sin x) G \\ket \\beta \\\\\n    &= (\\cos x) D \\ket \\alpha - (\\sin x) D \\ket \\beta \\\\\n    &= \\cos x (2 \\cos \\theta \\ket \\psi - \\ket \\alpha) - \\sin x (2 \\sin \\theta \\ket \\psi - \\ket \\beta) \\\\\n    &= (2 \\cos x \\cos \\theta - 2 \\sin x \\sin \\theta) \\ket \\psi - \\cos x \\ket \\alpha + \\sin x \\ket \\beta \\\\\n    &= (2 \\cos x \\cos^2 \\theta - 2 \\sin x \\sin \\theta \\cos \\theta - \\cos x) \\ket \\alpha + (2 \\cos x \\cos \\theta \\sin \\theta - 2 \\sin x \\sin^2 \\theta + \\sin x) \\ket \\beta \\\\\n    &= cos (2\\theta + x) \\ket \\alpha + \\sin (2\\theta + x) \\ket \\beta \\\\\n    \\\\\n    \\implies G \\ket{\\psi} &= cos (3\\theta) \\ket \\alpha + \\sin (3\\theta) \\ket \\beta\n\\end{align*}\n\nTherefore, $G$ is a counter-clockwise rotation (by $2\\theta$) operator in $P$. And so it suffices to apply $G$ on $\\ket \\psi$ $k$ times such that $$2k\\theta \\sim \\frac{\\pi}{2} - \\theta \\implies k = \\floor*{\\frac{\\pi}{4}\\left(\\frac{1}{\\theta}\\right) - \\frac12} \\leq  \\frac{\\pi}{4\\theta}$$\n\nAnd using $\\theta \\geq \\sin \\theta = \\sqrt{x/N}$, we get $\\boxed{k \\leq \\frac{\\pi}{4}\\sqrt{\\frac{N}{x}}}$\n\nHence after $O(\\sqrt{N/x})$ oracle queries, with high probability, we can find one of the search elements.\n\n\n\\end{document}\n\n", "meta": {"hexsha": "7f4f1a11e76ce2663e5a914a934edf0318cf2470", "size": 10114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quantum_computing/assign4_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/assign4_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/assign4_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": 54.6702702703, "max_line_length": 502, "alphanum_fraction": 0.6029266363, "num_tokens": 4299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6336801042877676}}
{"text": "\\problemname{Cooking Water}\n``A watched pot never boils'', as the saying goes.\nChef Edward has been cooking for ages, and empirically the saying seems to be true in his kitchen -- he has yet to see a pot actually start boiling.\nHis wife Gunilla is a bit suspicious of Edward's claim though.\nShe knows how he often loses focus after a little while, and thinks that it is very likely Edward gets tired of watching after about the same period of time starting when he puts it on the stove.\n\nBeing scientifically minded, Gunilla quickly designed an experiment which could help Edward gain more insight into the boiling of pots.\nEvery time during the last week when Edward boiled a pot of water, he wrote down the intervals of time when he was not watching the pot.\nNow, he has a large log of these intervals, and wonders whether Gunilla is right (i.e. it may be the case Edward just happened to watch away every time the pot started boiling), or if his hypothesis is correct.\n\nGiven this data, is it possible that the pot actually starts boiling after the same amount of time, every time?\n\n\\section*{Input}\nThe first line of the input contains an integer $1 \\le N \\le 1\\,000$, the number of times Edward boiled water in the last week.\nThen, $N$ descriptions of a boiling follow.\nEach description contains two numbers $0 \\le a \\le b \\le 1\\,000$.\nThis means that Edward looked away during seconds $[a, b]$ (i.e. from the start of second $a$, to the end of second $b$), and that Edward first saw the pot boiling once he looked back.\n\n\\section*{Output}\nIf it is impossible that all the pots actually started boiling at the same point in time, output \\texttt{edward is right}.\nOtherwise, output \\texttt{gunilla has a point}.\n", "meta": {"hexsha": "29aaf458e14af745df22cc6d74a6b798b95ee3b0", "size": 1716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cookingwater/problem_statement/problem.en.tex", "max_stars_repo_name": "Kodsport/nova-challenge-2018", "max_stars_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-13T13:38:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-13T13:38:16.000Z", "max_issues_repo_path": "cookingwater/problem_statement/problem.en.tex", "max_issues_repo_name": "Kodsport/nova-challenge-2018", "max_issues_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "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": "cookingwater/problem_statement/problem.en.tex", "max_forks_repo_name": "Kodsport/nova-challenge-2018", "max_forks_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "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": 78.0, "max_line_length": 210, "alphanum_fraction": 0.770979021, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324983301567, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6336801035714044}}
{"text": "\n\\color{black}\n\\subsection*{Learning a Markov model}\n\nGiven a state sequence $\\vec{s}$ such as the one you just created, we may use maximum likelihood estimation techniques to estimate or ``learn'' a Markov model $\\lambda_{MLE}$ that is most likely to have produced $\\vec{s}$.\n\nMaximum likelihood estimates of the entries of the corresponding matrix $\\mat{P}_{\\lambda_{MLE}}$ are given by\n\\begin{equation*}\n\\bigl( \\mat{P}_{\\lambda_{MLE}} \\bigr)_{ji} = \\frac{n_{ji}}{\\sum_j n_{ji}}\n\\end{equation*}\nwhere the quantity $n_{ji}$ counts how often the transition $s_i \\rightarrow s_j$ occurs in sequence $\\vec{s}$.\n\nGiven the ``training'' sequence $\\vec{s}$ you created above, compute the entries of $\\mat{P}_{\\lambda_{MLE}}$. Round your results to two decimals.\n\\color{blue}\n%%%%%\n%%%%% enter your answer after the '=' sign\n%%%%%\n\\begin{equation*}\n\\mat{P}_{\\lambda_{MLE}} = \\begin{bmatrix} 0.3 & 0.2 & 0.5 \\\\ 0.5 & 0.3 & 0.2 \\\\ 0.2 & 0.5 & 0.3 \\end{bmatrix}\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\n\n\n", "meta": {"hexsha": "c228c735cc61b2804680f5cdf13eb405f47fa8f2", "size": 1004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SelfTest1SS2020/selfTestProblem3.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/selfTestProblem3.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/selfTestProblem3.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": 35.8571428571, "max_line_length": 222, "alphanum_fraction": 0.672310757, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6336800965926844}}
{"text": "\\mychapter{15}{Lesson 15} %181116\n\\section{Public key encryption (cont'd)} \n\n\\subsubsection{\\textsc{Cca}-security, revisited}\n\n\\begin{cryptogame}\n    {pkecca}\n    {Chosen ciphertext attacks, revisited for \\pke{} schemes}\n    {cca2}\n    \n    \\receive{$(\\pk, \\sk) \\pickUAR \\keygen(1^\\lambda)$}{$pk$}{}\n\n    \\cseqdelay\n    \\cseqbeginloop\n\n    \\send{}{$c'$}{}\n    \\receive{$m' = \\Dec(\\sk, c)$}{$m'$}{}\n\n    \\cseqendloop\n    \\cseqdelay\n\n    \\send{}{$m_0, m_1$}{}\n\n    \\receive{\\shortstack[l]{\n        $b \\pickUAR \\binary$ \\\\\n        $c \\pickUAR \\Enc(\\pk, m_b)$\n    }}{$c$}{}\n\n    \\cseqdelay\n    \\cseqbeginloop\n\n    \\send{}{$c'$}{}\n    \\receive{$m' = \\Dec(\\sk, c)$}{$m'$}{}\n\n    \\cseqendloop\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\\end{cryptogame}\n\n\\subsection{Trapdoor permutations}\n\nLet us consider the following scheme $\\Pi$, which is an adaption of the old \\cpa-secure \\ske{} to public keys:\n\\begin{itemize}\n    \\item $\\Enc(\\pk, m) = (r, f_\\pk(m \\oplus r))$, where $r \\sim \\unifdist(\\binary^\\lambda)$\n    \\item $\\Dec(\\sk, (c_0, c_1)) = g_\\sk(c_1) \\oplus c_0$\n    \\item Correctness: $g_\\sk(c_1) \\oplus c_0 = g_\\sk(f_\\pk (m \\oplus r)) \\oplus r = m \\oplus r \\oplus r = m$\n\\end{itemize}\n\nA \\emph{trapdoor permutation} (or \\tdp) is a \\owp{} having the following features:\n\n\\begin{itemize}\n    \\item A key pair is chosen \\uar{} by a key generator algorithm:\n    \\[\n        (\\pk, \\sk) \\pickUAR \\keygen(1^\\lambda)\n    \\]\n    \\item There is a function family $F \\in \\Xi_\\pk \\to (V_{\\pk} \\to V_{\\pk})$ such that:\n    \\begin{itemize}\n        \\item Computing $f_{\\pk}$ is efficient\n        \\item Domain sampling ($x \\pickUAR V_{\\pk}$) is efficient\n    \\end{itemize}\n    \\item There is an efficient function $g_{\\sk}$ that efficiently \\emph{inverts} $f_{\\pk}$, where $sk$ is the ``trapdoor'': \n    \\[\n        g(\\sk, f(\\pk, x)) = x\n    \\]\n    \\item No efficient adversary is able to invert $f_{\\pk}$ without knowing $\\sk$\n\\end{itemize}\n\nNote that because $\\pk$ is public, an adversary can perform any polynomial number of encryptions with $\\pk$, and see the corresponding ciphertext. This is the same characteristic of \\pke{} schemes we described just a while ago. It entails that, if left deterministic, a \\tdp{} is not \\cpa-secure.\n\nAlso, the scheme described above is not \\cpa-secure form the start: the adversary, by choosing two messages for the challenge, and receiving the ciphertext $(c_0 = r, c_1)$, along with the public key, has everything needed to reconstruct the encryption and check whichever message was encrypted, much like the problem of \\ufcma against a deterministic \\mac scheme.\n\n%The idea is to reuse the message as part of the randomness, or more in detail, use its hardcore predicate. The resulting scheme would then look like this:\nHere, in this scheme, we combine randomness and the notion of hardcore predicate $\\hc$:\n\n% AP190123 - IMPORTANT NOTE: This scheme is intended to work for single-bit messages\n\\begin{itemize}\n    \\item $(pk, sk) \\pickUAR \\keygen(1^\\lambda)$\n    \\item $r \\pickUAR \\Xi_{pk}$\n    \\item $c := \\Enc(\\pk, m) = (f_{\\pk}(r), \\hc(r) \\oplus m)$\n    \\item Correctness: $\\Dec(\\sk, c) = \\hc(g_{\\sk}(c_1)) \\oplus c_2$\n    % Exercise: If obscure, do the petty algebra on paper\n\\end{itemize}\n\n\\begin{theorem}\n    If $F$ is a \\tdp{} and $\\hc$ is hardcore for $f$, then the above scheme is \\cpa-secure.    \n\\end{theorem}\n\n\\begin{proof} The proof is left as exercise\n    \\todo{Apparently, the reduction here is not easy at all, some hints are needed.}\n\\end{proof}\n\n\\subsection{\\textsc{Tdp} examples}\n\nOne example stems form the factoring problem: let's look again at $\\integer_n^\\times$, where $n$is the product of two prime numbers $p$, and $q$:\n\n\\begin{theorem}[Chinese remainder theorem]\n    The following isomorphisms to $\\integer_n^\\times$ are true:\n\n    \\begin{itemize}\n        \\item $\\integer_n \\simeq \\integer_p \\times \\integer_q$\n        \\item $\\integer_n^\\times \\simeq \\integer_p^\\times \\times \\integer_q^\\times$\n    \\end{itemize}\n\n    Note that the theorem is more general, and holds for any two numbers $p$ and $q$ that are coprime.\n\\end{theorem}\n\nHow to use this theorem for constructing a \\pke{} scheme:\n\n\\begin{theorem}[Euler's totient theorem]\n    Let $x$, $n$ be two coprime numbers. Then $x^{\\varphi(n)} \\equiv_n 1$\n\\end{theorem}\n\nAlso, remember that $\\forall p, q \\in \\primenum \\implies \\varphi(pq) = (p - 1)(q - 1)$\n\nSo let $a$ be the public key such that $\\gcd(a, \\varphi(n)) = 1$, then $\\exists! b \\in \\integer_n : ab \\equiv_{\\varphi(n)} 1$; $b$ will be our private key. Define encryption as $f(a, m) = m^a \\mod n$, and then decryption as $g(b, c) = c^b \\mod n$. Observe that \n\\[\n    g(b, f(a, m)) = (m^a)^b = m^{ab} = m^{k \\varphi(n) + 1} = (m^{\\varphi(n)})^k m \\equiv_n m\n\\]\nbecause $ab = 1 \\mod \\varphi(n)$.\n\nSo we conjecture that the above is a valid \\tdp-based \\pke{} scheme. This is actually referred to as the \\emph{\\rsa{} assumption}, and is depicted in figure \\ref{cryptogame:rsaass}\n\n\\begin{cryptogame}\n    {rsaass}\n    {The \\rsa{} assumption}\n    {rsa}\n\n    \\receive{\\shortstack[l]{\n        $b \\pickUAR \\binary$ \\\\\n        $c \\pickUAR \\textrm{Enc}(pk, m_b)$\n    }}{$n, pk, m^{pk}$}{}\n\n    \\cseqdelay\n\n    \\send{}{$m'$}{\\textsc{Output 1 iff} $m' = m$}\n\n\\end{cryptogame}\n\n\nRelation to the factoring problem: $\\rsa \\implies \\textsc{fact}$\n\nProof: Given $p, q$, an adversary can compute $\\varphi(n) = (p - 1)(q - 1)$, and then find the inverse of the public key in $\\integer_{pq}^\\times$.\n\nIt hasn't been proven that $\\textsc{fact} \\implies \\rsa$\n\n\\section{Textbook \\rsa}\n\nThis is an insecure toy example of the more complex \\rsa{} (Rivest Shamir Adleman) scheme:\n\n\\begin{itemize}\n    \\item Setup: $(\\pk, \\sk) \\pickUAR \\keygen(\\integer_n^\\times) : \\sk \\equiv_{\\varphi(n)} \\pk^{-1}$\n    \\item Encryption: $\\Enc(\\pk, m) = m^{\\pk} \\mod n$\n    \\item Decryption: $\\Dec(\\sk, c) = c^{\\sk} \\mod n$\n    \\item Correctness: $\\Enc(\\pk, \\Dec(\\sk, m)) = m^{\\pk \\cdot \\sk} \\equiv_n m$\n\\end{itemize}\n\nAgain, since the encryption routine is deterministic, the scheme is not \\cpa-secure. However, a hardcore predicate can be inserted to the routine: $\\hat{m} = r||m$, where $r \\pickUAR \\binary^l$. Now the encryption is pseudorandom.\n\nSome interesting facts:\n\\begin{enumerate}\n    \\item $l \\in \\omega(log(\\lambda))$ otherwise a brute-force attack becomes viable.\n    \\item If $m \\in \\binary$, then the scheme is \\cpa-secure under \\rsa{} assumption, just use the standard \\tdp{}\n    \\item If $m$ is ``in the middle'': $\\binary \\leq m \\leq \\binary^l$; then \\rsa{} is believed to be secure (standard PKCS\\#1, 5)\n    \\item However, this construct is not \\cca-secure.\n    \\todo{Counterexample?}\n\\end{enumerate}\n\n\\subsection{Trapdoor Permutation from Factoring}\n\nHere is an attempt to build a \\tdp{} over the group $\\quadres(n)$: let's look at $f(x) \\equiv_n x^2$ where $f \\in \\integer_n^\\times \\to \\quadres_n (\\subset \\integer_n^\\times)$. Notice that this is not a permutation in general, so let's consider their \\textsc{crt}'s representation\\footnotemark, in order to restrict $f$'s domain:\n\n\\footnotetext{Those well-versed in number representation in computers may know this representation as the \\emph{residue number system}}\n\n\\[\n    x = (x_p \\equiv_p x, x_q \\equiv_q x), f(x) \\equiv_p x^2, x \\in \\integer_p^\\times\n\\]\n\nSince $\\integer_p^\\times$ is cyclic:\n\n\\begin{align*}\n    \\integer_p^\\times   &= \\{g^0, g^1, g^2, \\ldots  &&, g^{\\frac{p - 1}{2} - 1}              &&, g^{\\frac{(p-1)}{2}}                    &&, \\ldots, g^{p-2}         &&\\} \\\\\n    \\quadres_p          &= \\{g^0, g^2, g^4, \\ldots  &&, g^{2(\\frac{p - 1}{2} - 1) = p - 3}   &&, g^{2(\\frac{p-1}{2}) = p - 1 \\equiv 0}  &&, \\ldots, g^{2(p - 2)}    &&\\} \\\\\n\\end{align*}\n\nBecause of this, $|\\quadres_p| = \\frac{p - 1}{2}$. Moreover, since $g^{2\\frac{p-1}{2}} \\equiv_p 1$ and $g^{\\frac{p-1}{2}}$ cannot be 1 (since $g^0 \\neq g^{\\frac{p - 1}{2}} \\neq g^{p - 1}$ ) but must be one of the $p-1$ elements of $\\integer_p^\\times$, then $g^{\\frac{p-1}{2}} \\equiv_p -1$.\n    \nNow it's possible to show that $f: \\quadres_p \\to \\quadres_p$ is a permutation, and we are going to show how to find $f^{-1}$.\n\nAssume $p \\equiv_4 3$, meaning $\\exists t : p = 4t + 3 \\implies t = \\frac{p - 3}{4}$); then squaring modulo $p$ becomes a permutation. Given $y \\equiv_p x^2$, observe the following:\n\n\\begin{gather*}\n    (y^{t + 1})^2 = y^{2t + 2} = y^{2\\frac{p - 3}{4} + 2} = y^{\\frac{p - 1}{2} + 1} = (x^2)^{\\frac{p - 1}{2} + 1} = x^{p - 1} x^2 \\equiv_p x^2 \\\\\n    \\Downarrow \\\\\n    x = \\pm y^{t + 1}\n\\end{gather*}\n\nBut only one among $\\pm y^{t + 1}$ is a square: the positive one. Therefore:\n\\[ \n    p = 4t + 3 \\implies \\frac{p - 1}{2} = \\frac{4t + 2}{2} = 2t + 1\n\\]\nso $\\frac{p - 1}{2}$ is odd.\n\nNow, since we are considering just the elements of $\\quadres_p$, and we can write each $x \\in \\integer_p^\\times$ as $g^{z}$ for a $z \\in \\integer_p$:\n\\[\n    y = x^2  = (g^z)^2\n\\]\n\nSo, $y = g^{z'} \\in \\quadres_p \\Leftrightarrow z'$ is even. If $z'$ is odd, then $y \\notin \\quadres_p$.\n\nSince $\\frac{p - 1}{2}$ is odd, then $g^{\\frac{p - 1}{2}} \\notin \\quadres_p$, and since it is possible to generate all of the other numbers with odd exponents \n\\[\n    g^{odd}=g^{\\frac{p-1}{2} \\pm even} = g^{\\frac{p-1}{2}}g^{ \\pm even} \\implies -1(g^{\\pm even})\n\\]\nand $g$ powered to odd exponents will have this form. From here, it's possible to state the following:\n\n\\begin{lemma}\n    $\\forall z \\in \\quadres_p \\implies -z \\notin \\quadres_p$\n\\end{lemma}\n\n\\subsection{Rabin's Trapdoor permutation}\n\nNow we study a one-way function built on previous deductions about number theory and modular arithmetic. The \\emph{Rabin trapdoor permutation} is defined as: \n\\[\n    f(x) = x^2 \\mod n\n\\]\nwhere $n = pq$ for primes $p, q \\equiv_4 3$.\n\nWe can observe that the image of this function is $\\quadres_n$, a subset of $\\integer_n^\\times$.\n\nBecause of \\textsc{crt}, it is possible to state that $f$ maps as follows:\n\\[\n    x = (x_p, x_q) \\implies x^2 = (x^2_p, x^2_q)\n\\]\nsince each element of $\\integer_n$ has always two different forms, in $\\integer_p$ and in $\\integer_q$. So\n\\[\n    y \\in  \\quadres_n \\Leftrightarrow y_p \\in \\quadres_p \\wedge y_q \\in \\quadres_q\n\\]\n\nAs before, the image of $f$ is exactly\n\\[\n    \\quadres_n = \\{ y : \\exists x : y \\equiv_n x^2\\}\n\\]\n\nIf we try to invert the function $f$, even without applying the previous inversion algorithm, we easily note that among the 4 possible values:\n\n\\[\n    f^{-1}(y) = \\{(x_p, x_q),(-x_p, x_q),(x_p, -x_q)(-x_p, -x_q)\\}\n\\]\n\nonly 1 is a quadratic residue since we said, in the last lemma, that only one out of $-x_k, x_k$ is a quadratic residue for $k = q,p$.\n\nTherefore, we have that the Rabin's \\tdp{} is a permutation in $\\quadres_n$, and that the cardinality of $\\quadres_n$ is $\\frac{|\\integer_n^\\times|}{4}$. Furthermore, with the following claim we can state that the Rabin cryptosystem is a \\owf{} thanks to the \\textsc{fact} assumption.\n\n\\begin{claim}\n    Given $x$ and $z$ such that $x^2 \\equiv_n z^2 \\equiv_n y$:\n    \\[\n        x \\neq \\pm z \\implies n \\text{\\textup{ is factorizable}}\n    \\]\n\\end{claim}\n\n\\begin{proof}\n    Since $f^{-1}(y)$ has only one value out of four, $x \\neq \\pm z$ and $z$ is either $\\{(x_p, x_q), (-x_p, -x_q)\\}$, then:\n    \\[\n        x \\in \\{(x_p, -x_q), (-x_p, x_q)\\} \\implies x + z \\in \\{(0, 2x_q), (2x_p, 0)\\}\n    \\]\n    Now assume $x + z = (2x_p, 0)$ without loss of generality, since the proof for the other case is the same. We have that $x + z \\equiv_q 0$ and $x + z \\not\\equiv_p 0$. But then $\\gcd(x + z, n) = q$, and we obtain $q$.\n\\end{proof}\n\n\\begin{theorem}\n    Squaring mod $n$, where $n$ is a \\emph{Blum integer}\\footnotemark is a trapdoor permutation under the factoring assumption.\n\\end{theorem}\n\n\\footnotetext{a Blum integer $n$ is the product of two numbers $p$ and $q$ such that $p, q \\equiv_4 3$, as the definition of Rabin's \\tdp}\n\nSince we have already shown that Rabin's function is a permutation since it is invertible, we have to show that Rabin's function is also \\owf:\n\n\\begin{proposition}\n\\[\n    \\textsc{fact} \\implies f(x) \\in \\owf \\qedhere\n\\]\n\\end{proposition}\n\n\\begin{proof}\n    The proof is by contradiction. Assume there is an adversary \\adversary{} who, given $y \\equiv_n x^2$, can find an integer $z \\in \\integer_n$ such that $z^2 \\mod n = y$ while $z \\neq \\pm x$. We can build a reduction as the one in figure \\ref{cryptoredux:blumtdp} to show that \\adversary{} chooses $x$, here $\\mathcal{B}lum$ is a sampler for Blum integers:\n\n    % AP190902: The adversary had a \"fact\" subscript, is it important?\n    \\begin{cryptoredux}\n        {blumtdp}\n        {---}\n        {fact}\n        {rabin}[1.8]\n\n        \\receive{$(p, q, n) \\pickUAR \\mathcal{B}lum$}{$n = pq$}{}\n\n        \\cseqdelay\n\n        \\invoke{\\shortstack[l]{\n            $x \\pickUAR \\integer_n^\\times$ \\\\\n            $y \\equiv_n x^2$\n        }}{$n, y$}{}\n\n        \\cseqdelay\n\n        \\return{}{$z$}{$f(z) = f(x)$}\n        \n    \\end{cryptoredux}\n\n    \n    Once obtained $z\\neq \\pm x$ which $z^{2}=y$ we can use \\textbf{Claim 1}(just summing $x$ and $z$ and analyzing the result) to factorize $n$ in polynomial time. But factorizing $n$ in polynomial time is not possible.\n\\end{proof}\n", "meta": {"hexsha": "f8fd271c099a90cd8c51dcc3c19715592ad35777", "size": 13134, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_15.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_15.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_15.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.0961538462, "max_line_length": 364, "alphanum_fraction": 0.6340794884, "num_tokens": 4515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6336800923869613}}
{"text": "\\chapter{BACKGROUND STUDY}\n\\section{What is an algorithm?}An algorithm is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.Broadly,it is a step-by-step procedure for solving a problem or accomplishing some end especially by a computer.\\\\\n\\section{Classification of algorithms.}Based on various criteria, algorithms are divided into:-\\\\\nON THE BASIS OF SEQUENCE OF THE INTERNAL EXECUTIONS\\\\\n\\subsection{Deterministic algorithms.}Deterministic algorithms can be defined in terms of a state machine: a state\tdescribes what a machine is doing at a particular instant in time.If the machine is deterministic, this means that from this point onwards, its current state determines what its next state will be its course through the set of states is predetermined.This type of algorithms are such which, given a particular input, will always \tproduce the same output, with the underlying machine always passing through the same sequence of states.In simple words, deterministic algorithms produce on a given input the same results following the same computation steps.\\\\\nAlthough real programs are rarely purely deterministic, it is easier for humans as \twell as other programs to reason about programs that are.To solve real time problems if we use deterministic algorithm its time complexity increases exponentially when dimension increases.Example - if you are sorting elements that are strictly ordered(no equal elements) the output is well defined and so the algorithm is deterministic.\\\\\n\\subsection{Non-Deterministic algorithms.}A randomized or non-deterministic algorithm is an algorithm that, even for the same input, can exhibit different behaviors on different runs. It is different from its more familiar deterministic counterpart in its ability to arrive at outcomes using various routes. In other words, a non-deterministic algorithm represents a single path stemming into many paths, some of which may arrive at the same output and some of which may arrive at unique outputs.\nExample – Evolutionary algorithms.\\\\\nIn computational complexity theory, non-deterministic algorithms are ones that, at every possible step, can allow for multiple continuations (imagine a man walking down a path in a forest and, every time he steps further, he must pick which fork in the road he wishes to take). These algorithms do not arrive at a solution for every possible computational path; however, they are guaranteed to arrive at a correct solution for some path (i.e., the man walking through the forest may only find his cabin if he picks some combination of \"correct\" paths).\\\\\nTYPES OF RANDOMIZED ALGORITHMS:-\\\\\n1. \\textbf{Las Vegas type algorithms}\\\\\nA Las Vegas algorithm will always produce the same result on a given input.Randomization will only affect the order of the internal executions.Example- Quick sort\\\\\n2.\\textbf{ Monte Carlo type algorithms}\\\\\nIn the case of Monte Carlo algorithms, the result may might change, even be wrong.However, a Monte Carlo algorithm will produce the correct result with a certain probability. Example- PSO\\\\\n\\includegraphics[width=0.8\\textwidth]{./pic}\\\\[1cm]\nON THE BASIS OF availability OF INPUT:-\\\\\n\\subsection{Online algorithms.}Online algorithms are algorithms that do not know their input at the beginning; it is \tgiven to them online. Such algorithms are DYNAMIC in nature.Example - ski problem. A skier must decide every day she goes skiing, whether to rent or to buy skis, unless or until she decides to buy them. The skier does not know how many days she can ski, because the weather is unpredictable.\\\\\n\\subsection{Offline algorithms.}Offline algorithms are algorithms know their input at the beginning, i.e. input is predetermined.Such algorithms are STATIC in nature.\\\\\n\\section{Types of problems.}The total defined problem sphere has been divided into four classes - \\textbf{P, NP, NP-complete and NP-Hard problems}.\\\\\n\\subsection{ P and NP class.}\\textbf{P} is set of problems that can be solved by a deterministic algorithm in Polynomial time.\\\\\n\\textbf{NP} is set of decision problems that can be solved by a non-deterministic algorithm in Polynomial time.P is subset of NP (any problem that can be solved by deterministic machine in polynomial time can also be solved by non-deterministic machine in polynomial time).\\\\\n\\subsection{ NP-complete.}\\textbf{NP-complete} problems are the hardest problems in NP set. A decision problem is NP-complete if:\\\\\n1) L is in NP (Any given solution for NP-complete problems can be verified quickly, but there is no efficient known solution).\\\\\n2) Every problem in NP is reducible to L in polynomial time.\\\\\n\\subsection{NP-hard.}\\textbf{NP-Hard }- A problem is NP-Hard if it follows property 2 mentioned above, doesn’t need to follow property 1.This means a problem K is NP-Hard if every problem in NP is reducible to K in polynomial time but the problem may or may not be in NP. Therefore, NP-Complete set is also a subset of NP-Hard set.\\\\\n\\section{Why non-deterministic algorithm?}In algorithm design, non-deterministic algorithms are often used when the problem solved by the algorithm inherently allows multiple outcomes (or when there is a single outcome with multiple paths by which the outcome may be discovered, each equally preferable.\nAs we know that increasing dimension or input size increases the complexity of problem and using a deterministic algorithm under such situations, increases the time complexity exponentially. So, we use non-deterministic algorithms for such problems. The class of NP-complete and NP-hard problems falls under this category. Such problems can be solved using a deterministic algorithm, but then it would require huge amount of time, may be a day, an year or even more,which is not feasible in real-time.So,we use some non-determinism i.e. randomicity while solving such problems.Hence, to solve problems corresponding to NP-complete and NP-hard class we use non-deterministic algorithms.\\\\", "meta": {"hexsha": "7b40b1667f22487a17a2fd71aa95c57a648a961d", "size": 5996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prob-definition_1.tex", "max_stars_repo_name": "Ace139/final-year-thesis", "max_stars_repo_head_hexsha": "207ee3e1465ea1c8673ba2a3045228bcca22adbe", "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": "prob-definition_1.tex", "max_issues_repo_name": "Ace139/final-year-thesis", "max_issues_repo_head_hexsha": "207ee3e1465ea1c8673ba2a3045228bcca22adbe", "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": "prob-definition_1.tex", "max_forks_repo_name": "Ace139/final-year-thesis", "max_forks_repo_head_hexsha": "207ee3e1465ea1c8673ba2a3045228bcca22adbe", "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": 222.0740740741, "max_line_length": 687, "alphanum_fraction": 0.8032021348, "num_tokens": 1267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6336800923869613}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage[margin=2cm]{geometry}\n\n\\begin{document}\n\n\\tableofcontents\n\n\\newpage\n\\section{Signing algorithm}\n\n\\noindent\nConsider two certificates $P$ and $Q$ where $P$ is signed by $Q$.\nLet $s$ be the signature in $P$ and let $k$ be the public\nkey in $Q$.\n\n\\begin{center}\n\\begin{tabular}{|c|}\n\\hline\n$\\quad P\\quad$\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\\\\n\\hline\n$s$\\\\\n\\hline\n\\end{tabular}\n\\qquad\n\\begin{tabular}{|c|}\n\\hline\n$\\quad Q\\quad$\\\\\n\\\\\n\\\\\n\\hline\n$k$\\\\\n\\hline\n\\\\\n\\\\\n\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nBy necessity $s$ and $k$ are compatible.\nFor example, if $k$ is RSA 2048 then $s$ is a PKCS\\footnote{RFC 3447 Public-Key Cryptography Standards (PKCS)}\nsignature that is 2048 bits in length (256 bytes).\n\n\\bigskip\n\\noindent\nA hash digest of $P$ is contained in $s$.\nFor example, the following unencrypted signature $s$ is for RSA 2048 and hash digest SHA256.\n(Numerals are in hexadecimal.)\n\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n{\\footnotesize\\tt 00 01 ff $\\cdots$ ff 00 30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00 04 20} & HASH\\\\\n\\hline\n\\end{tabular}\n\n\\medskip\nSignature $s$ (plaintext)\n\\end{center}\n\n\\noindent\nThe length of HASH is 32 bytes because SHA256 is used.\nThe 19 byte sequence starting with $\\tt 30$ is from\n``Abstract Syntax Notation One.''\nThe {\\tt ff} bytes are pad bytes that are added to make the total length of the signature 2048 bits (256 bytes).\nHence there are $256-3-19-32=202$ pad bytes.\n\n\\bigskip\n\\noindent\nNote that the above signature is the unencrypted value of $s$.\nIn the actual certificate, $s$ is encrypted using the private key associated with $k$.\nAfter encryption, $s$ is still 256 bytes long.\n\n\\begin{center}\n\\begin{tabular}{|c|}\n\\hline\n{\\footnotesize\\tt\n76 b6 97 82 0f 06 b7 48 59 02 a0 2c f4 $\\cdots$\nfe c3 61 25 5b 1c da 77 9a a1 63 d4 49 cd}\\\\\n\\hline\n\\end{tabular}\n\n\\medskip\nSignature $s$ (encrypted)\n\\end{center}\n\n\\noindent\nTo prove that $P$ is signed by $Q$, $s$ is decrypted using $Q$'s public key $k$.\nThen if HASH matches a digest of $P$, the signing of $P$ by $Q$ is proven.\n\n\\bigskip\n\\noindent\nProving ``$P$ signed by $Q$'' proves that $s$ was encrypted using the private key associated with $k$.\nOnly the owner of $Q$ knows the private key.\nNo one can change the contents of $P$ without breaking the hash digest in $s$,\nand no one can change $s$ without knowing the private key.\nHence we can trust the contents of $P$ if we trust $Q$.\n\n\\newpage\n\\section{RSA functions}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nvoid rsa_encrypt_signature\n          (uint8_t *sig, int len, struct keyinfo *key)\n\\end{verbatim}\n\n\\noindent\nEncrypts signature {\\tt sig} in situ using the private key in {\\tt key}.\nArgument {\\tt len} is the length of the signature in bytes.\nThis function is used to sign a certificate.\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nuint8_t *rsa_decrypt_signature\n          (struct certinfo *p, struct certinfo *q)\n\\end{verbatim}\n\n\\noindent\nDecrypts the signature in certificate {\\tt p} using the public key in {\\tt q} and returns the result.\nOn success, the result is returned in a malloc'd buffer that the caller should free.\nThe length of the buffer is the same as the signature length.\nReturns NULL on error.\n\n\\newpage\n\\section{Elliptic curve functions}\n\n\\subsection{prime256v1}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nvoid ec256_encrypt\n          (struct keyinfo *key, uint8_t *hash, int len, uint8_t *sig)\n\\end{verbatim}\n\n\\noindent\nEncrypts {\\tt hash} using the private key in {\\tt key}.\nThe 64 byte result is returned in {\\tt sig}.\nThis function is used to sign a certificate.\n\n\\bigskip\n\\begin{tabular}{ll}\n{\\tt key} & Pointer to a private key.\\\\\n{\\tt hash} & Pointer to a hash digest value.\\\\\n{\\tt len} & Byte length of hash digest value (32 bytes maximum).\\\\\n{\\tt sig} & Pointer to a 64 byte buffer.\n\\end{tabular}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nint ec256_verify\n          (struct certinfo *p, struct certinfo *q)\n\\end{verbatim}\n\n\\noindent\nReturns 0 if certificate {\\tt p} is signed by {\\tt q}\nwhere the public key type of {\\tt q} is prime256v1.\n\n\\bigskip\n\\subsection{secp384r1}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nvoid ec384_encrypt\n          (struct keyinfo *key, uint8_t *hash, int len, uint8_t *sig)\n\\end{verbatim}\n\n\\noindent\nEncrypts {\\tt hash} using the private key in {\\tt key}.\nThe 96 byte result is returned in {\\tt sig}.\nThis function is used to sign a certificate.\n\n\\bigskip\n\\begin{tabular}{ll}\n{\\tt key} & Pointer to a private key.\\\\\n{\\tt hash} & Pointer to a hash digest value.\\\\\n{\\tt len} & Byte length of hash digest value (48 bytes maximum).\\\\\n{\\tt sig} & Pointer to a 96 byte buffer.\n\\end{tabular}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nint ec384_verify\n          (struct certinfo *p, struct certinfo *q)\n\\end{verbatim}\n\n\\noindent\nReturns 0 if certificate {\\tt p} is signed by {\\tt q}\nwhere the public key type of {\\tt q} is secp384r1.\n\n\\newpage\n\\section{Hash functions}\n\n\\bigskip\n\\bigskip\n\\begin{verbatim}\nvoid md5(uint8_t *buf, int len, uint8_t *out)\nvoid sha1(uint8_t *buf, int len, uint8_t *out)\nvoid sha224(uint8_t *buf, int len, uint8_t *out)\nvoid sha256(uint8_t *buf, int len, uint8_t *out)\nvoid sha384(uint8_t *buf, int len, uint8_t *out)\nvoid sha512(uint8_t *buf, int len, uint8_t *out)\n\\end{verbatim}\n\n\\noindent\nThe hash value of {\\tt buf} is returned in {\\tt out}.\nArgument {\\tt len} is the length of {\\tt buf} in bytes.\nThe following table shows the byte length of each result.\n\n\\bigskip\n\\noindent\n\\begin{tabular}{|l|l|}\n\\hline\nDigest & Length\\\\\n\\hline\nMD5 & 16 bytes\\\\\nSHA1 & 20\\\\\nSHA224 & 28\\\\\nSHA256 & 32\\\\\nSHA384 & 48\\\\\nSHA512 & 64\\\\\n\\hline\n\\end{tabular}\n\n\\bigskip\n\\noindent\nThe hash value of a certificate is encrypted in the certificate signature.\n\n\\newpage\n\\section{ASN.1 Encodings}\n\n\\noindent\nEncoded integers may have an extra leading 00 byte added due to encoding rules.\nEncoding rules add the 00 byte if the first byte of the unencoded integer is greater than 127.\n\n\\bigskip\n\\noindent\nFor example, a 256 byte RSA modulus that begins with hex 80 is encoded as 257 bytes.\n\n\\newpage\n\\subsection{RSA}\n\n\\subsubsection{Public key}\n\n\\noindent\nThe following example is for RSA 1024 which has a 128 byte modulus.\nThe two integers in the encoding are the modulus followed by the exponent.\n\n\\begin{verbatim}\n134 159:     SEQUENCE {\n137  13:       SEQUENCE {\n139   9:         OBJECT IDENTIFIER rsaEncryption (1 2 840 113549 1 1 1)\n150   0:         NULL\n       :         }\n152 141:       BIT STRING, encapsulates {\n156 137:         SEQUENCE {\n159 129:           INTEGER\n       :             00 C4 B9 4C 7D 39 E6 64 4E 66 88 92 60 24 AC C8\n       :             C7 80 19 3D B9 05 A9 0D 56 EE 2D B6 DB D9 73 C2\n       :             0C 97 6F E8 08 FE DC 5B 55 0A 5E FA B0 66 F7 B2\n       :             EA 78 31 45 4C 58 3D 49 F2 09 AF C8 37 81 86 7D\n       :             C1 55 1F 9F EA 8C DB ED 5B 28 2E 2D 7B CD 84 77\n       :             4D 06 9D 57 E7 BE 23 6F 39 08 73 F4 3C 89 35 AF\n       :             65 FE B1 C0 5B 19 A3 60 78 80 DB 07 6D 36 28 C8\n       :             A0 EB CA 2D 5C 1D B2 A0 9C 59 0F 6E E2 AA 9D B5\n       :             27\n291   3:           INTEGER 65537\n       :           }\n       :         }\n       :       }\n\\end{verbatim}\n\n\\subsubsection{Signature}\n\n\\noindent\nThe signature is the bit string field at the end of the certificate.\nThe length of the signature is the same as the unencoded RSA modulus.\nIn this case (RSA 1024) the length is 128 bytes.\n\n\\begin{verbatim}\n296  13:   SEQUENCE {\n298   9:     OBJECT IDENTIFIER sha256WithRSAEncryption (1 2 840 113549 1 1 11)\n309   0:     NULL\n       :     }\n311 129:   BIT STRING\n       :     7E 97 8C BA 48 9D 89 C8 98 E4 77 27 E4 01 54 4D\n       :     65 BB 96 04 46 43 C2 4A F4 6C B3 19 9A 4B 56 28\n       :     10 99 4C 5F 12 D9 3D 36 5F BC C7 C9 F2 28 1A 24\n       :     5D 09 05 AA 85 17 18 E6 B0 1D C9 C6 CD 8A AE 10\n       :     6F AA 9E 6E 09 B6 C5 85 54 2D CF 7B A0 B8 72 67\n       :     86 9C 51 35 8D ED 17 8A 48 23 A4 82 53 3C BE 29\n       :     5A 7D DA 00 B5 D3 9F EC 9A 6F 3D 95 B7 B4 64 72\n       :     56 D1 3C DA 62 BD 4B 45 81 C2 D4 35 E1 06 DB 24\n\\end{verbatim}\n\n\\newpage\n\\subsection{prime256v1}\n\n\\subsubsection{Public key}\n\n\\noindent\nBit string data is the byte sequence $(04\\mid X\\mid Y)$.\nThe length of $X$ is 32 bytes and the length of $Y$ is 32 bytes.\n\n\\begin{verbatim}\n162  89:     SEQUENCE {\n164  19:       SEQUENCE {\n166   7:         OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)\n175   8:         OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)\n       :         }\n185  66:       BIT STRING\n       :         04 AB AA 1E 30 A0 41 00 05 C5 7F 32 E3 99 B8 BE\n       :         3B 8A C1 4A A2 A3 4C CB 3C 44 97 04 4D D2 99 F1\n       :         E9 CD FE 63 B3 C4 B7 05 99 1B 94 1B 87 3B 47 BA\n       :         3A 76 AA 37 96 2F 89 47 31 53 EB 77 E6 43 17 D2\n       :         3B\n       :       }\n\\end{verbatim}\n\n\\subsubsection{Signature}\n\n\\noindent\nThe two integers in the encoding are $R$ followed by $S$.\nThe unencoded length of $R$ is 32 bytes and the unencoded length of $S$ is 32 bytes.\n\n\\begin{verbatim}\n253  10:   SEQUENCE {\n255   8:     OBJECT IDENTIFIER ecdsaWithSHA256 (1 2 840 10045 4 3 2)\n       :     }\n265  72:   BIT STRING, encapsulates {\n268  69:     SEQUENCE {\n270  33:       INTEGER\n       :         00 9F 3F A9 AE 97 A0 48 52 AA AA AF 3E CA BA 62\n       :         5F 6C 2C 46 BB 29 D0 19 A6 14 EA C0 5D 0E B9 B8\n       :         D5\n305  32:       INTEGER\n       :         16 76 0A FC 4D 9C 6F 65 BD D2 8B CA EF C5 6E 07\n       :         76 46 13 1D CF 39 A8 E3 80 D8 BD 2E B2 F9 89 0D\n       :       }\n       :     }\n\\end{verbatim}\n\n\\newpage\n\\subsection{secp384r1}\n\n\\subsubsection{Public key}\n\n\\noindent\nBit string data is the byte sequence $(04\\mid X\\mid Y)$.\nThe length of $X$ is 48 bytes and the length of $Y$ is 48 bytes.\n\n\\begin{verbatim}\n163 118:     SEQUENCE {\n165  16:       SEQUENCE {\n167   7:         OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)\n176   5:         OBJECT IDENTIFIER secp384r1 (1 3 132 0 34)\n       :         }\n183  98:       BIT STRING\n       :         04 42 62 D9 F6 76 24 10 AE 1B 60 1F 59 45 C5 7D\n       :         69 89 A3 A7 29 92 40 E6 BF FD F0 D0 20 55 BD 97\n       :         5E 2B D8 BB 14 56 30 08 6E F0 02 A8 DB F4 DD C5\n       :         BD DD 69 AB 39 B9 32 FC 55 D4 D5 8C 70 8E 27 3C\n       :         AA A0 72 67 22 AB 1D DF 41 B5 D4 99 6D 32 7C 06\n       :         ED 48 9F 31 E5 BD 10 AA 09 E7 5B 19 B6 8D 23 43\n       :         27\n       :       }\n\\end{verbatim}\n\n\\subsubsection{Signature}\n\n\\noindent\nThe two integers in the encoding are $R$ followed by $S$.\nThe unencoded length of $R$ is 48 bytes and the unencoded length of $S$ is 48 bytes.\n\n\\begin{verbatim}\n283  10:   SEQUENCE {\n285   8:     OBJECT IDENTIFIER ecdsaWithSHA256 (1 2 840 10045 4 3 2)\n       :     }\n295 104:   BIT STRING, encapsulates {\n298 101:     SEQUENCE {\n300  48:       INTEGER\n       :         33 30 98 0F AA 4C 83 A1 0C 17 F9 3F 2F 05 F7 92\n       :         2B 97 E9 2E E5 63 33 26 29 36 10 4F 65 2F E4 BA\n       :         FF 14 09 0E 6B 07 BC 3D 8C 62 E0 4E 9C 4E B4 37\n350  49:       INTEGER\n       :         00 F6 6E EC 4F F9 5B 37 DC 8D E3 E9 B3 CA 13 0C\n       :         5A BE F4 72 E4 4B 7A B4 BF C7 05 F1 71 83 77 68\n       :         DF CF F3 CA B2 3E C5 8F E6 7E 34 B7 B4 AB 6F D5\n       :         4F\n       :       }\n       :     }\n\\end{verbatim}\n\n\\newpage\n\\section{References}\n\n\\noindent\nCerticom Corp., ``Standards for Efficient Cryptography 1 (SEC 1: Elliptic Curve Cryptography)''\n\n\\bigskip\n\\noindent\nFIPS Publication 180-4, Secure Hash Standard\n\n\\bigskip\n\\noindent\nKaliski B., ``A Layman's Guide to a Subset of ASN.1, BER, and DER''\n\n\\bigskip\n\\noindent\nNIST, ``Mathematical routines for the NIST prime elliptic curves''\n\n\\bigskip\n\\noindent\nRFC 1321 The MD5 Message-Digest Algorithm\n\n\\bigskip\n\\noindent\nRFC 3447 Public-Key Cryptography Standards (PKCS)\n\n\\end{document}\n", "meta": {"hexsha": "02a139275a8bd06fd9122f97ee5a3d4baf41d2ae", "size": 11856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/certificate-tool.tex", "max_stars_repo_name": "georgeweigt/certificate-tool", "max_stars_repo_head_hexsha": "2d5c5c56d6fea9bbbedd9b0cd3c9edf244ae7834", "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/certificate-tool.tex", "max_issues_repo_name": "georgeweigt/certificate-tool", "max_issues_repo_head_hexsha": "2d5c5c56d6fea9bbbedd9b0cd3c9edf244ae7834", "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/certificate-tool.tex", "max_forks_repo_name": "georgeweigt/certificate-tool", "max_forks_repo_head_hexsha": "2d5c5c56d6fea9bbbedd9b0cd3c9edf244ae7834", "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": 27.3179723502, "max_line_length": 112, "alphanum_fraction": 0.6464237517, "num_tokens": 4383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7772998508568417, "lm_q1q2_score": 0.6336800854082412}}
{"text": "\\documentclass[a4paper,12pt]{report}\n\n\\usepackage{amsmath,amsfonts,mathtools}\n\\usepackage{hyperref}\n\n\\begin{document}\n\\title{MAT195 TextBook Notes}\n\\author{Aman Bhargava}\n\\date{January 2019}\n\\maketitle\n\n\\tableofcontents\n\n\n\\pagebreak\n\\section{Review: Memorizy Stuff}\n\\subsection{Trig Function Derivatives}\n\\def\\arraystretch{2}%\n\\begin{tabular}{cc}\n$ \\frac{d}{dx}sin(x) = cos(x) $ & $ \\frac{d}{dx}csc(x) = -csc(x)cot(x) $ \\\\\n$ \\frac{d}{dx}cos(x) = -sin(x) $ & $ \\frac{d}{dx}sec(x) = sec(x)tan(x) $ \\\\\n$ \\frac{d}{dx}tan(x) = sec^2(x) $ & $ \\frac{d}{dx}cot(x) = -csc^2(x) $ \\\\\n\\end{tabular}\n\n\\subsection{Inverse Trig Derivatives}\n\\def\\arraystretch{2}%\n\\begin{tabular}{cc}\n$ \\frac{d}{dx}sin^{-1}(x) = \\frac{1}{\\sqrt(1-x^2)} $ \\\\\n$ \\frac{d}{dx}cos^{-1}(x) = \\frac{-1}{\\sqrt(1-x^2)} $ \\\\\n$ \\frac{d}{dx}tan^{-1}(x) = \\frac{1}{1+x^2} $ \\\\\n\\end{tabular}\n\n\\subsection{How to complete the Square}\n\\begin{enumerate}\n\\item Put $ax^2 + bx$ in brackets and forcefully factor out the $a$\n\\item Add $ ( \\frac{b}{2})^2$ to the inside of the brackets and subtract it from the outside (you got it)\n\\item Factor and be happy that you've completed the square;\n\\end{enumerate}\n\n\\subsection{Trig Angle Sums}\n\\begin{enumerate}\n\\item $sin(A+B) = sin(A)cos(B) + cos(A)sin(B)$\n\\item $cos(A+B) = cos(A)cos(B) - sin(A)sin(B)$\n\\item $sin(A-B) = sin(A)cos(B) - cos(A)sin(B)$\n\\item $cos(A-B) = cos(A)cos(B) + sin(A)sin(B)$\n\\end{enumerate}\n\n\\subsection{Hyperbolic Trig Functions}\n\\subsection{Inverse Hyperbolic Trig Function}\n\n\\section{Introduction and Course Description}\n\\chapter{Techniques of Integration (Chapter 7 in Textbook)}\n\\section{Integration by Parts}\n\nIntegration by parts is basically just the reverse product rule.\\\\\n\nProduct rule: $d/dx [f(x)g(x)] = f'(x)g(x) + f(x)g'(x)$\\\\\n\nYou could reverse this simply, but it wouldn't be that useful. The more useful form that \\textit{is} the integration by parts formula looks like this: $$\\int [f(x)g'(x)] = f(x)g(x) - \\int [f'(x)g(x)]$$\n\nYou can think through that one pretty easily | you are just splitting up the initial integral, then moving half of it to the other side.\\\\\n\nThat's pretty useful, but there's an even more useful way to write the formula, and it looks like this: $$\\int u dv = uv - \\int v du$$\n\nThis works because we let $u = f(x)$ and $v = g(x)$. $g'(x) = v' = dv/dx$, and same with $u'$. So to get to that formula we go like this:\n\\begin{eqnarray}\n\\int uv' dx = uv - \\int u'v dx \\\\\n\\int u \\frac{dv}{dx} dx = uv - \\int v \\frac{du}{dx} dx \\\\\n\\int u dv = uv - \\int v du\n\\end{eqnarray}\n\n\\subsection{Tips for Integration by Parts:}\n\\begin{itemize}\n\\item When using the $uv$ equation, it's useful to define things in this order:\n\\begin{itemize}\n\\item u = ? dv = ?\n\\item du = ? v = ?\n\\item keeping in mind that $u'dx = du$ and $\\int \\frac{dv}{dx} dx = \\int v' = v$\n\\end{itemize}\n\\item Choose your $u$ so that it becomes simpler when differentiated, and let your $v$ be the thing that gets a little hairier.\n\\item Practice a lot from the textbook, ya dingus\n\\end{itemize}\n\n\\section{Trigonometric Integrals}\nThere are a bunch of configurations of trig functions for which we need to learn the steps necessary to take the integral. It's important to practice this because recognizing the form of the integral is the most difficult thing to do here.\n\\subsection{Strategy for $\\int sin^m (x)cos^n (x)$}\n\\paragraph{If the power of cosine is odd:}\n\"Save\" one of the cosine terms, and then express it as $\\int sin^m(x)cos^{2k+1}(x)*cos(x)$. Then turn the $cos^{2k+1}(x)$ into sin terms with pythagorean identity. Then substitute $u = sin(x)$ and solve.\n\\paragraph{If the power of sine is odd:} \nDo the same thing but reverse $sin$ and $cos$ (save one $sin(x)$ and sub $u$ for $cos(x)$\n\\paragraph{If both powers are even:} \nUse the following identities to help you solve it:\n\\begin{eqnarray}\nsin^2 (x) = 1/2 (1-cos(2x)) \\\\\ncos^2 (x) = 1/2 (1+cos(2x)) \\\\\nsinxcosx = 1/2 sin2x\n\\end{eqnarray}\n\n\\subsection{Strategy for $\\int tan^m (x)sec^n (x)$}\n\\paragraph{If the power of $sec(x)$ is even,} \"save\" a factor of $sec^2 (x)$ and use identity $sec^2 (x) = 1+tan^2 (x)$ to express the rest in terms of $tan(x)$. Then substitute $u = tan(x)$\n\\paragraph{If the power of tangent is odd,} save a factor of $sec(x)tan(x)$ and convert the rest of the $tan(x)$'s using $tan^2(x) = sec^2 (x) - 1$ \n\\paragraph{Also note the following:} $$\\int tan(x) dx = ln|sec(x)| + C$$ $$\\int sec(x) dx = ln|sec(x) + tan(x)| + C$$\n\\paragraph{Remember this as well:} $$\\frac{d}{dx} tan(x) = sec^2(x)$$ $$\\frac{d}{dx} sec(x) = sec(x)tan(x)$$\n\n\\subsection{Strategy for $\\int sin(mx)cos(nx) dx$}\nUse the following identities:\n\\begin{eqnarray}\nsin A cos B = 1/2 [sin(A-B) + sin(A+B)] \\\\\nsin A sin B = 1/2 [cos(A-B) - cos(A+B)] \\\\\ncos A cos B = 1/2 [cos(A-B) + cos(A+B)]\n\\end{eqnarray}\n\n\\subsection{Strategy for $\\int csc^m (x)cot^n (x) dx$}\nKnow the following things:\n\\begin{eqnarray}\n\\frac{d}{dx} csc(x) = -csc(x)cot(x) \\\\\ncot^2(x) = csc^2(x) - 1 \\\\\n\\frac{d}{dx} cot(x) = -csc^2(x)\n\\end{eqnarray}\n\n\\section{Trig Sub}\n\\paragraph{What is trig sub?} Trig sub is when you use the \\textit{inverse substitution} rule in conjunction with useful trigonometric identities and trigonometric integrals to solve integrals that you wouldn't otherwise be able to solve.\n\\subsection{Inverse Substitution}\nUnlike u-substitution, you are substituting in a non-equivalent function ($g(x)$) for x instead of substituting a variable like $u$ for the actual value of x. Hence, the following result arises: $$\\int f(x) dx = \\int f(g(x))g'(x) dx $$\n\\paragraph{Qualificiations:} $g$ must have an inverse function, and $g$ must be one-to-one.\n\\subsection{List of Trig Subs}\nThe main use of trig subs is to get rid of irritating radical signs that make integration hard. The following is a table of types (from the textbook):\n\n\\medskip\n\\begin{tabular}{c|l|c}\nExpression & Substitution & Identity \\\\\n\\hline\n$\\sqrt{a^2 - x^2}$ & $x = a sin \\theta$, $-\\pi/2 <= \\theta <= \\pi/2$ & $1-sin^2 \\theta = cos^2 \\theta$ \\\\\n$\\sqrt{a^2 + x^2}$ & $x = a tan \\theta$, $-\\pi/2 < \\theta < \\pi/2$ & $1+tan^2 \\theta = sec^2 \\theta$ \\\\\n$\\sqrt{x^2 - a^2}$ & $x = a sec \\theta$, $-\\pi/2 <= \\theta <= \\pi/2$ & $sec^2 \\theta - 1= tan^2 \\theta$ \\\\\n\\end{tabular}\n\n\\subsection{General Layout for Trig Sub}\n\\begin{enumerate}\n\\item Make sure there is no other way (e.g. u-sub, etc.)\n\\item If there is a quadratic in the root, complete the square\n\\item Recognize the stuff in the root as one of the three.\n\\item Set $x = a*trig(\\theta)$ and find $dx$ in terms of $\\theta$\n\\item Solve the stuff.\n\n\\end{enumerate}\n\n\\section{Partial Fractions}\nThis is just a way to break up rational functions in to little pieces that we can actually deal with.\nA proper rational function is one where the power on the top polynomial is lower than that of the bottom. Improper rationals are the other way around.\n\nIn order to use partial fractions, you need to make the rational function a proper one.\n\nThere are a few cases to consider for splitting things up into partial fractions:\n\n\\subsection{Denominator is only distinct Linear Factors}\n\\begin{enumerate}\n\\item Set an equality between the original rational and $\\frac{A}{(root_1)} + \\frac{B}{(root2)} + ...$\n\\item Multiply both sides by the denominator of the rational\n\\item Expand and solve for $A, B, ...$\n\\end{enumerate}\n\n\\subsection{Denominator is only Linear Factors but some are Repeated}\nIt's roughly the same as last time, EXCEPT:\n\\begin{enumerate}\n\\item Suppose $(root_1)$ is repeated $k$ times so $(root_1)^k$ is a factor\n\\item Then you need to use $\\frac{A_1}{(root_1)} + \\frac{A_2}{(root_1)^2} + ... + \\frac{A_k}{(root_1)^k}$\n\\item Now solve as you did last time.\n\\end{enumerate}\n\n\\subsection{Denominator has non-repeated Quadratic Factors}\nBasically just have a linear term on top in the expansion, so $\\frac{A_1x+B}{ax^2+bx+c}$ would be a term in the thing.\n\n\\paragraph{Also, } $\\int\\frac{dx}{x^2+a^2} = \\frac{1}{a}tan^{-1}(\\frac{x}{a})+C$\n\n\\subsection{Denominator has repeated Quadratic Factors}\nRoughly the same as when you have linear repeated factors. if you have $(root_1)^k$, then you get $$\\frac{Ax+B}{(root_1)} + \\frac{Cx+D}{(root_1)^2} + ... + \\frac{Yx+Z}{(root_1)^k}$$\nThen just solve as before.\n\n\\subsection{Rationalizing Substitutions}\nUse substitutions to make annoying functions into rational functions and solve from there. For instance, if you have a radical in the numerator, make the subsitution $u^2 = $ whatever was in the radical.\n\n\\section{Strategy for Solving Integrals}\n\\begin{enumerate}\n\\item Simplify the integrand with identities/algebra if possible.\n\\item Look for an obvious u-sub\n\\item Classify the integrand according to its form:\n\\begin{enumerate}\n\\item Trig integral ($sin^m(x)cos^n(x)$, etc.)\n\\item Rational Function\n\\item Integration by parts - especially with $polynomial * transcendental function$\n\\item Radicals $\\to$ consider trig sub ($x = atan\\theta$, etc.)\n\\end{enumerate}\n\\item Try again, using several methods, and drawing from your MASSIVE PAST EXPERIENCE\n\n\\end{enumerate}\n\n\n\\section{Improper Integrals (Involving Infinity)}\n\\subsection{Definition of Improper Integral}\n$\\int_{a}^{\\infty} f(x) dx = \\lim_{t \\to \\infty} \\int_a^t f(x) dx $\nConvergent improper integrals have an actual value. Divergent improper integrals don't.\nIntegrals from negative infinity to positive infinity exist if and only if the integral from -infinity to $a$ converges and the integral from $a$ to +infinity converges (it is the sum of the two).\n\n\\paragraph{For $\\int_1^{\\infty} \\frac{1}{x^p} dx$} is convergent if $p > 1$\n\n\\paragraph{For integrals where the y value goes to infinity}, then you take limits around where it goes to infinity, ya dingus.\n\n\\subsection{Comparison Theorem}\nYou can prove that an integral is convergent if you can find another one for which the function is strictly of greater magnitude that is convergent (and likewise for non-convergency)\n\n\\chapter{Further Applications of Integration}\n\\section{Arc Length}\n\\subsection{Definition of Arc Length}\nArc length is the actual length of a curve. It is defined as: $$L = \\lim_{n \\to \\infty} \\sum_{i = 1}^{n} |P_{i-1},P_i|$$\n\n\\subsection{Arc Length Formula}\n$$L = \\int_a^b \\sqrt{1 + [f'(x)]^2} dx $$\n\n\\section{Surface Area of Revolution}\n\\subsection{Surface Area of Revolution Formulae}\n$$S = \\int_a^b 2\\pi y \\sqrt{1+(\\frac{dy}{dx})^2}dx$$\n$$S = \\int_a^b 2\\pi y \\sqrt{1+(\\frac{dx}{dy})^2}dy$$\n\n\\paragraph{Simplified: For rotation around $x$-axis}\n$$S = \\int 2\\pi y ds$$\n\n\\paragraph{Simplified: For rotation around $y$-axis}\n$$S = \\int 2\\pi x ds$$\n\nWhere $$ds = \\sqrt{1+(\\frac{dy}{dx})^2}dx$$ or $$ds = \\sqrt{1+(\\frac{dx}{dy})^2)}dy$$\n\n\\section{Applications to Physics and Engineering}\n\\subsection{Hydrostatic Force}\nIntegral of the area of each slice times the pressure on that slice at that depth (pressure = density * depth)\n\n\\subsection{Center of Mass}\nFor a thin plate on the plane, the centroid is at $(\\bar{x}, \\bar{y})$ where:\n$$ \\bar{x} = \\frac{1}{A} \\int_a^b x(f(x)-g(x))dx $$\n$$ \\bar{y} = \\frac{1}{2A} \\int_a^b (f(x)^2 -g(x)^2) dx$$\n\n\\subsection{Rotating cross sections around line}\nIf cross section is completely outside of the line, volume = area * distanc traveled by cross section.\n\n\\chapter{Parametric Equations and Polar Coordinates}\n\\section{Parametric Equations}\n\\subsection{Tangents}\n$$\\frac{dy}{dx} = \\frac{ \\frac{dy}{dt} }{ \\frac{dx}{dt} }$$\n$$\\frac{d^2y}{dx^2} = \\frac{ \\frac{d}{dt}(\\frac{dy}{dx}) }{ \\frac{dx}{dt} }$$\n\n\\subsection{Integrals}\n\\subsubsection{Normal Integral: Area from $\\alpha \\to \\beta$}\n$$\\int_{\\alpha}^{\\beta}y(t)*\\frac{dx}{dt}dt$$\n\\subsubsection{Arc Length}\n$$L = \\int_{\\alpha}^{\\beta} \\sqrt{ \\frac{dx}{dt}^2 + \\frac{dy}{dt}^2 }dt$$\n\\subsubsection{Surface Area of Revolution: }\n$$S = \\int_{\\alpha}^{\\beta} 2\\pi y \\sqrt{\\frac{dx}{dt}^2 + \\frac{dy}{dt}^2}dt$$\n\n\n\n\\section{Polar Coordinates}\n\\subsection{Quick Info: }\n\\begin{enumerate}\n\\item Points are in form $(r, \\theta)$\n\\item Origin denoted by $O$ or as \"pole\"\n\\item For point $(x, y)$ in cartesian space and point $(r, \\theta)$:\n\\begin{itemize}\n\\item $x = r cos \\theta$\n\\item $y = r sin \\theta$\n\\item $tan \\theta = \\frac{y}{x}$\n\\end{itemize}\n\\end{enumerate}\n\n\\subsection{Symmetry}\nIf an equation is unchanged when $\\theta \\to -\\theta$, it is symmetric about line $\\theta = 0$\nIf an equation is unchanged when $r \\to -r$ OR $\\theta \\to \\theta + \\pi$, it is symmetric about the pole.\nIf an equation is unchanged when $\\theta \\to \\pi - \\theta$ then the curve is symmetric about the line $\\theta = \\pi/2$ (a vertical line in polar coordinates)\n\n\\subsection{Tangents to Polar Curves}\nTreat as parametric equation. Steps:\n$$ x = r cos \\theta = f(\\theta) cos (\\theta)$$\n$$ y = r sin \\theta = f(\\theta) sin (\\theta)$$\n\nThen $\\frac{dy}{dx}$ is just $\\frac{dy}{d\\theta}/\\frac{dx}{d\\theta}$\n\n\\section{Areas and Lengths in Polar Coordinates}\n\\subsection{Area}\n\\paragraph{Area of a Sector of a Circle}\n$$A = \\frac{1}{2}r^2\\theta$$\n\\paragraph{Area Inside Curve: }\n$$A = \\int_a^b \\frac{1}{2} (f(\\theta))^2 d\\theta $$\n$$A = \\int_a^b \\frac{1}{2} r^2 d\\theta $$\n\n\\subsection{Arc Length}\n\\subsubsection{Review of Parametric Arc Length}\n$$L = \\int_a^b \\sqrt{r^2 + (\\frac{dr}{d\\theta})^2 } d\\theta$$\n\n\n\\chapter{Infinite Sequences and Series}\n\\section{Sequences}\n\\paragraph{Definition: } List of numbers written in definite order. Notation is the same as set notation.\n\\subsection{Limits of Sequences}\n\\paragraph{A sequence has a limit $L$ if: } you can make $a_n$ as close as you want to $L$ by increasing $n$\n\nYou can encorporate ($\\delta$) $\\epsilon$ notation if you want to.\n\nAlso, if you can find a function that matches the sequence at all integer points, then you can just find the limit of the function using regular limit rules to find the limit of the sequence.\n\nYou can also disperse the a limit inside of a function.\n$$\\lim_{n \\to \\infty} sin(\\pi/n) = sin( \\lim_{n \\to \\infty} \\pi /n )$$\n\n\\subsection{Definitions}\n\\paragraph{Monotonic sequences} are sequences that are either strictly increasing or strictly decreasing.\n\\paragraph{Bounded above} if no value of $n$ will make $a_n$ greater than $M$. Ditto bounded below.\n\\paragraph{Monotonic Sequence Theorem: } Every bounded, monotonic sequence is convergent.\n\n\\section{Series}\n\\paragraph{A series is: } a sum of a sequence (often infinite)\n\\subsection{Partial Sums}\n$$s_1 = a_1, s_2 = a_1 + a_2, s_n = a_1 + ... + a_n$$\n$$s_n = \\sum_{i=1}^{n} a_i$$\n\\subsection{Infinite Series}\n$$\\sum_{n=1}{\\infty} a_n = \\lim_{a \\to \\infty} \\sum_{i=1}^{n} a_i$$\n\n\\subsection{Geometric Series}\nIf $a_n = (a_1)r^n$, then $s_n = a + ar + ar^2 + ... + ar^{n-1}$\n\n$$s_n = \\frac{a(1-r^n)}{1-r}$$\n\n\\subsection{Test for Divergence}\nIf $\\lim_{n \\to \\infty} a_n$ does not exist or equals $\\infty$, then the infinite series of $a_n$ is divergent.\n\n\\subsection{Working with Series}\nYou can add and subtract series normally.\n$$\\sum (a_n + b_n) = \\sum a_n + \\sum b_n$$\n$$\\sum (c * a_n) = c \\sum a_n$$\n\n\\subsection{Comparison Test}\nIf $a_n$ is less than $b_n$ for all $n$ and $\\sum^{\\infty}b_n$ converges, then $\\sum^{\\infty}a_n$ also converges. Likewise, if the sum of $b_n$ diverges and $a_n$ is greater for all $n$, then the sum of $a_n$ diverges. \n\n\\paragraph{Conditions for Comparison Test: } \n\\begin{enumerate}\n\\item Must be series with positive terms.\n\\end{enumerate}\n\n\\subsection{Limit Comparison Test}\nLet $a_n$ be one series you DON'T know the limit of and $b_n$ be another. Make sure $a_n/b_n$ divides nicely. let $c = \\lim_{n \\to \\infty}a_n/b_n$\n\nUse $c$ as a comparator - if it tells you that $a$ is bigger than $b$ and $b$ is known to be divergent, then $a$ must be divergent, etc.\n\n\\paragraph{Conditions for Limit Comparison Test}\n\\begin{enumerate}\n\\item $a_n$ and $b_N$ must both be series with positive terms.\n\\end{enumerate}\n\n\\subsection{P-Series}\nA p-series is of the form: $$\\sum_{n=1}^{\\infty} 1/{n^p}$$\nIf $p > 1$, it converges. Otherwise it diverges.\n\n\\section{The Integral Test and Estimates of Sums}\n\\subsection{Integral Test}\nIt's not easy to find the sum of series except for geometric series and $\\sum 1/[n(1+n)]$. \n\nTo prove that a sum diverges, take the integral of the continuous function $f(n) = a_n$ from $1 \\to \\infty$. If the integral is divergent, then so is the sum. If the integral is convergent, so is the sum. Think about the geometric argument and draw out the boxes on the page if necessary (reimann sums). \n\n\\paragraph{Conditions for Applying the Integral Test: }\n\\begin{enumerate}\n\\item Continuous\n\\item Positive\n\\item Decreasing\n\\end{enumerate}\n\n\\subsection{Estimating The Sum of a Series}\nAny partial sum of a series is an approximation of the infinite sum. We can get a good picture of how good the approximation is via the \\texttt{remainder}.\n$$R_n = s - s_n = a_{n+1} + a_{n+2} + ...$$\nBy the integral test (and intuition), the remainder is less than or equal to theintegral from $n$ to $\\infty$\n$$R_n = a_{n+1} + a_{n+2} + ... \\leq \\int_n^{\\infty}f(x)dx$$\n$$R_n \\geq \\int_{n+1}^{\\infty}f(x)dx$$\n\nIn other words, the \\paragraph{Remainder Estimate for the Integral Test} is:\n$$ \\int_{n+1}^{\\infty}f(x) dx \\leq R_n \\leq \\int_n^{\\infty}f(x) dx$$\n\n\\section{Comparison Tests}\n\\subsection{The Limit Comparison Test}\nLet $\\sum a_n$ and $\\sum b_n$ are series with positive terms. If $$lim_{n \\to \\infty} \\frac{a_n}{b_n} = c$$ and c is a finite number $>$ 0, then both either converge or diverge.\n\n\\section{Alternating Series}\nConvergence tests so far only apply to positive series. \n\\subsection{Alternating Series Test}\n$$\\sum_{n=1}^{\\infty} (-1)^{n-1} b_n = b_1 - b_2 + b_3 - b_4 + ... b_n > 0$$\n\\paragraph{If } the series obeys:\n\\begin{enumerate}\n\\item $b_{n+1} \\leq b_n$ for all n\n\\item $lim_{n \\to \\infty} b_n = 0$\n\\end{enumerate}\nThen the series is CONVERGENT.\n\n\\paragraph{Fun fact: } $s_{2n} \\leq b_1$ for all n. \n\n\\subsection{Estimating Sums for Alternating Series}\n\\paragraph{Alternating Series Estimation Theorem: } If $s = \\sum (-1)^{n-1} b_n$ where $b_n$ > 0, and the series $b$ converges to zero and is strictly decreases, then:\n$$ |R_n| = |s-s_n| \\leq b_{n+1} $$\n\n\\section{Absolute Convergence and Ratio and Roots Test}\n\\subsection{Absolute Convergence}\n\\paragraph{Definition: } $\\sum a_n$ is absolutely convergent if $\\sum |a_n|$ converges.\n\n\\paragraph{Conditional Convergence: } When a series is convergent, but not absolutely so (depends on the operators between values in series).\n\n\\subsection{Ratio Test}\n\\begin{enumerate}\n\\item if $lim_{n\\to\\infty} |(a_{n+1}/a_n| = L < 1$, then the sequence is \\textbf{absolutely convergent}\n\\item if the result of the above is $> 1$, then the sequence is \\textbf{divergent}\n\\item if the result of the above is $= 1$, then the ratio test was \\textbf{inconclusive}.\n\\end{enumerate}\n\n\\subsection{Root Test}\nThis is just the same as the ratio test, but as it turnt out, you can apply the ratio test to stuff inside nth roots and the same results will be forthcoming. \n\n\nBasically, if the limit of whatever inside the root is $<1$ then it converges and so on.\n\n\\subsection{Rearrangements}\n\\begin{enumerate}\n\\item Any rearrangement of a \\textbf{absolutely convergent} series is the same.\n\\end{enumerate}\n\nNon-absolutely convergent series don't have the same sums necessarily when the order is changed. \n\n\\section{Strategy for Series: }\n\\begin{enumerate}\n\\item Is it a p-series (form: $\\sum 1/{n^p}$)? If $p > 1$, it converges, otherwise, it doesn't. \n\\item Is it a geometric series (form: $\\sum ar^{n-1}$? If $|r| < 1$, then it converges. Otherwise it diverges.\n\\item If it is similar to a p-series or geometric series, use a comparison test.\n\\item If you can tell that $\\lim_{n\\to\\infty} a_n \\neq 0$, use \\textbf{Test for Divegence} \n\\item If it's $\\sum(-1)^{n-1}b_n$ or of a similar form, then alternating series tests are the way to go. \n\\item If it involves factorials or other products (e.g. constants raised to some power), use the ratio test. \n\\item Use the root test for if $a_n$ is of form $(b_n)^n$\n\\item If the corresponding integral is easy to evaluate, then use the integral test. \n\\end{enumerate}\n\n\\section{Power Series}\nOf the form: \n$$\\sum_{n=0}^{\\infty} c_n x^n = c_0 + c_1x + c_2x^2 + ... + c_nx^n$$\n\n$x$ is a variable, $c_n$ is a sequence of coefficients.\n\nConverges when $-1 < x < 1$ if all $c_n$ are one. \n\n\\paragraph{Power Series \"Centered at $a$\" or \"In $(x-a)$\"} when:\n$$\\sum_{n=0}^{\\infty} c_n(x-a)^n = c_0 + c_1(x-a) + c_2(x-a)^2 + ...$$\nAlways converges for $x = a$ because all terms after $c_0$ reduce to 0.\n\n\\subsection{3 Possibilities for Power Series}\n\\begin{enumerate}\n\\item The series converges only when x = a\n\\item The series converges for all x\n\\item There exists R so that if $|(x-a)| < R$ then the series will converge. R is \"radius of convergence\".\n\\end{enumerate}\n\n\\section{Representing Functions as Power Series}\n$$\\frac{1}{1-x} = 1 + x + x^2 + ... = \\sum_{n=0}^{\\infty}x^n$$ where |x|<1\n\nYou can take derivative/integral for x values that \\textbf{don't} cause it to diverge.\n\n\\paragraph{General Strategy for Representing as Power Series: }\nIntegrate/differentiate until it's in a similar form to $$\\frac{1}{1-x}$$\nThen convert to power series then integrate/differentiate back.\n\n\\section{Taylor and McLauren Series}\n\\subsection{Taylor Series}\n\\paragraph{If $f$ has a power series representation, } then:\n$$f(x) = \\sum_{n=0}^{\\infty} \\frac{f^{(n)} (a)}{n!} (x-a)^n$$\n\nMclauren Series is just a Taylor Series centered at 0.\n\n\\subsection{Finding the Radius of Convergence for Taylor Series}\nLet $a_n$ be whatever is inside the summation of the Taylor Series. Use $$L = |\\frac{a_{n+1}}{a_n}|$$ and the ratio test to see what values of x are necessary for it to converge (L < 1 to converge).\n\n\\subsection{Taylor's Inequality}\n\\paragraph{Pre-Inequality Theorem: } If $f(x) = T_n(x) + R_n(x)$ and $T_n(x)$ is the nth-degree Taylor polynomial and $R_n(x)$ is the remainder of the polynomial, then $\\lim_{n \\to \\infty} R_n(x) = 0$ (pretty obvious, huh?)\n\n\\paragraph{Taylor's Inequality (for real now)}\nIf $|f^{(n+1)}(x)| \t\\leq M$ for all $|x-a| \\leq d$ then $R_n(x)$ is follows:\n$$|R_n(x)| \\leq \\frac{M}{(n+1)!} |x-a|^{n+1}$$ for all $|x-a| \\leq d$\n\n\\paragraph{Useful facts and figures}\n$$lim_{n \\to \\infty} \\frac{x^n}{n!} = 0$$\n(for every x)\n\n\n$$e = \\sum_{n = 0}^{\\infty} \\frac{1}{n!}$$\n\n$$sin(x) = \\sum_{n=0}^{\\infty}(-1)^n \\frac{x^{2n+1}}{(2n+1)!}$$\n$$cos(x) = \\sum_{n=0}^{\\infty}(-1)^n \\frac{x^{2n}}{(2n)!}$$\n\n\\subsection{Manipulations of Power Series}\nDivide power series by long division informally...\n\n...\n\n\\chapter{All Continuous Functions are Integrable}\nThis section is pretty strange in my opinion. This course is mostly quite procedural and technique-based, but in the middle, we are suddenly spending a large chunk of time on one proof.\n\nThe questions pertaining to this proof are fairly straightforward if you know the terminology used in the proof well. So, I'll focus on that for this section rather than going over the proof again (the professors for this course posted a pretty decent PDF of the proof that you can read if you want all the details). \n\n\\section{Starting Point, Definitions: }\n$$\\int_a^b f(x) dx = \\lim_{||P|| \\to 0} \\sum_{i=1}^{n} f(x_i*)\\Delta x_i$$\n\n\\begin{enumerate}\n\\item $||P||$ is the size of any \\textbf{partition} in $[a, b]$\n\\item \\textbf{Lower sum sequence: } $$L_{2^n} = \\frac{(b-a)}{2^n} \\sum_{i=1}^{2^n} f_i^{min}$$\n\\item \\textbf{Upper sum sequence: } $$U_{2^n} = \\frac{(b-a)}{2^n} \\sum_{i=1}^{2^n} f_i^{max}$$\n\\item \\textbf{Note on upper/lower sequences: } they are obviously bounded, and as you increase the $n$ in the $2^n$, the lower sum sequence is \\textbf{strictly increasing} and the upper sum sequence is \\textbf{strrictly decreasing}. Think about it :)\n\\item How the squeeze theorem ties it all together: If you get that the upper and lower sum sequences converge, and you also understand that the true integral is \\textbf{always} between the values of the upper anas lower sums, then it's trivial to say that the limit as $n\\to \\infty$ of $L_{2^n}$ which is equal to that of $U_{2^n}$ is the value of the integral.\n\\item \\textbf{Definition of uniform continuity:} If you can find just one $\\delta$ for any $\\epsilon$ imposed for an area $[a, b]$ that satisfies the limit/continuity definitions for delta-epsilon proofs, then the function is uniformly continuous on that region $[a, b]$.A\n\\item \\textbf{Definition of span:} Span is $s = M-m$ where M is the max of an interval and m is the minimum of that interval.\n\\begin{enumerate}\n\\item \\textbf{Small span theorem:} For a continuous function on a given interval, you can divide the function into $2^n$ sub-intervals that have a span less than any given $\\epsilon > 0$\n\\end{enumerate}\n\\item Thanks to the \\textbf{small span theorem}, you can keep increasing $n$ in $2^n$ and dividing a region into that many parititions to make the difference between the max and the min of that partition approach zero, hence ensuring that the \\textbf{Upper sum sequence} will approach the \\textbf{Lower sum sequence}. \n\\end{enumerate}\n\n\\section{Tips for answering questions}\n\\begin{itemize}\n\\item If they ask you to prove that something is not integrable, think about why the $$L_{2^n}$$ would not converge with the $$U_{2^n}$$.\n\\item If they ask a proofy questions where you assert that there is a max/min on an interval, invoke the \\textbf{extreme value theorem}\n\\item \n\\end{itemize}\n\n\n\n\n\\section{Fourier Series}\n\\paragraph{Form of Fourier Series: }\n$$f(x) = a_0 + \\sum_{n=1}^{\\infty} (a_n cos(nx) + b_n sin(nx))$$\nfor $-\\pi \\leq x \\leq \\pi$\n\n\\paragraph{Finding Coefficients: }\n$$a_0 = \\frac{1}{2\\pi} \\int_{-\\pi}^{\\pi} f(x) dx$$\n\n$$a_n = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) cos(nx) dx$$\n\n$$b_n = \\frac{1}{\\pi} \\int_{-\\pi}^{\\pi} f(x) cos(nx) dx$$\n\n\\subsection{Fourier Convergence Theorem}\nHere are the prerequisites for the Fourier series to converge:\n\\begin{enumerate}\n\\item $f$ is periodic with period of $2\\pi$\n\\item $f$ and $f'$ are piecewise continuous on $[-\\pi, \\pi]$\n\\item Fourier series at x = $f(x)$ where $f(x)$ is continous. Otherwise, it is the mean of the two points.\n\\end{enumerate}\n\n\\subsection{Fourier Series for $T \\neq \\pi$}\nLet period be $2L$\n$$f(x) = a_0 + \\sum_{n=1}^{\\infty} [a_n cos(\\frac{n\\pi x}{L}) + b_n sin(\\frac{n\\pi x}{L})]$$\n$$a_0 = \\frac{1}{2L} \\int_{-L}^{L} f(x) dx$$\n$$a_n = \\frac{1}{L}\\int_{-L}^{L} f(x) cos(\\frac{n\\pi x}{L}) dx$$\n$$b_n = \\frac{1}{L}\\int_{-L}^{L} f(x) sin(\\frac{n\\pi x}{L}) dx$$\n\n\\chapter{Vectors and Space}\n\\section{Cylinders and Quadratic Surfaces}\n\\paragraph{Cylinder definition: } Surface of all lines that are paralell to a given line and pass through a given plane (e.g. $z = x^2$)\n\n\\paragraph{Quadratic Surface definition: } Second-degree equation with three variables (usually $x, y, z$). General form is:\n$$Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fzx + Gx + Hy + Iz + J = 0 $$\nHowever, by translation and rotation, standard form becomes:\n$$Ax^2 + By^2 + Cz^2 + D = 0$$\n\nTypes of Quadratic Surfaces:\n\\begin{enumerate}\n\\item Ellipsoid: $x^2/a^2 + y^2/b^2 + z^2/c^2 = 1$ \n\\item Elliptic Paraboloid: $z/c = x^2/a^2 + y^2/b^2$, looks like upward 3d hyperbolic cup. Horizontal traces = ellipses, vertical traces = parabolas. \n\\item Hyperbolic Parabaloid: $z/c = x^2/a^2 - y^2/b^2$, horizontal traces are hyperbolas, vertical = parabolas. \n\\item Cones: $z^2/c^2 = x^2/a^2 + y^2/b^2$, Horizontal traces = ellipses, vertical traces are hyperbolas unless at 0, where it is an x.\n\\item Hyperboloid of One Sheet: $x^2/a^2 + y^2/b^2 - z^2/c^2 = 1$, horizontal = ellipses, vertical = hyperbolas, axis of symmetry is the variable that is negative. \n\\item Hyperboloid of Two Sheets: $-x^2/a^2 - y^2/b^2 + z^2/c^2 = 1$, horizontal = ellipses, vertical = hyperbolas, two negatives indicates two sheets.\n\\end{enumerate}\n\n\\chapter{Vector Functions}\n\\section{Vector Functions and Space Curves}\nVector function is one where the domain is the set of real numbers and the range is $R^n$\n\n\\paragraph{Limits of Vector Functions: } Just take the limit of each of the internal functions.\n\n\\paragraph{Space Curve: } You give $x(t), y(t), $and$ z(t)$ \n\n\\paragraph{Vector equation for joining two points: } $$r(t) = (1-t)r_0 + tr_1$$\n\n\\section{Derivatives, Integrals of Vector Functions}\nIf $r(t) = [f(t), g(t), h(t)]$ then $r'(t) = [f'(t), g'(t), h'(t)]$\n\nAll derivative rules still apply, and product rule applies to dot and cross product!\n\n\\section{Basic Vector Operation Definitions}\n\\paragraph{Dot Product: } $$x * y = x_1y_1+x_2y_2+ ... + x_ny_n$$\n$$x * y = |x|*|y|*cos(\\theta)$$\n\\paragraph{Cross Product: } $$x \\times y = |x|*|y|*sin(\\theta) * n$$ where n is a vector normal to the plane formed by x and y.\n\n\\subsection{Integrals of Vector Functions}\nJust integrate each component of the function.\n\n\\section{Arc Length, Curvature of Vector Functions}\n\\subsection{Arc Length}\nPretty self explanatory - length of an arc through space from point a to point b (literally)\n$$L = \\int_a^b |r'(t)|dt$$\n$$L = \\int_a^b \\sqrt(f'[t]^2 + g'[t]^2 + h'[t]^2)$$\nWhere $r(t) = [f(t), g(t), h(t)]$\n\n\\paragraph{The arc length function } is defined as: \n$$s(t) = \\int_a^t |r'(u)| du = \\int_a^t \\sqrt{(dx/du)^2 + (dy/du)^2 + (dz/du)^2} du$$\n\n\\subsection{Curvature}\nA curve $r(t)$ is smooth is $r'(t)$ is continuous and $r'(t) \\neq 0$ on the interval. Basically, the tangent vector isn't allowed to turn discontinuously.\n\n$$T(t) = \\frac{r'(t)}{|r'(t)|}$$\nWhere $T(t)$ is the tangent vector at time $t$. \n\n\\paragraph{The curvature of a curve } is defined as:\n$$\\kappa = |\\frac{dT}{ds}|$$\n\nWhere $s$ is the \\textbf{arc length function} discussed previously.\n\n\\paragraph{Therefore: }\n$$\\kappa(t) = \\frac{|T'(t)|}{|r'(t)|}$$\n$$\\kappa(t) = \\frac{|r'(t) \\times r''(t)|}{|r'(t)|^3}$$\n$$\\kappa(x) = \\frac{|f''(x)|}{[1+(f'(x))^2]^{3/2}}$$\n\n\\subsection{Normal and Binormal Vectors}\n\\paragraph{Normal vector } $N(t)$ is defined as: \n$$N(t) = \\frac{T'(t)}{|T'(t)|}$$\n\n\\paragraph{Binormal vector } $B(t)$ is defined as:\n$$B(t) = T(t) \\times N(t)$$\nIt's whole shtick is that it is perpendicular to both T and N and is a unit vector.\n\n\\subsection{Velocity and Acceleration}\nThis section actually has some stuff that isn't entirely obvious about normal vectors and such to acceleration/velocity, so come back when you have time.\n\n\\chapter{Partial Derivatives}\n\\section{Functions of Several Variables}\n\\paragraph{A function of two variables } transforms each pair of Reals $(x, y)$ in a given set to a single real number. The given set is the domain, and the set of reals that the pair is transformed to is the range.\n\n\\paragraph{Level functions } are functions that have $f(x, y) = k$ for given ranges of $(x, y)$\n\n\\paragraph{Functions of 3 or more variables } are pretty easy to extrapolate from functions of two variables, tbh.\n\n\\section{Limits and Continuity with Functions of Several Variables}\n\\subsection{Limits}\n\\paragraph{Definition of limit } with many variables:\n$$\\lim_{(x, y) \\to (a, b)} f(x, y) = L$$\nif for every number $\\epsilon > 0$ there is a corresponding number $\\delta > 0$ s.t.\nif $0 < \\sqrt{(x-a)^2 + (y-b)^2} < \\delta$ then $|f(x, y) - L | < \\epsilon$\n\n\\paragraph{How to disprove that a limit exists: }\n\nIf $f(x, y) \\to L_1$ on one path (e.g. keeping x the same and varying y) while $f(x, y) \\to L_2$ from another path and $L_1 \\neq L_2$ then limit DNE.\n\n\\paragraph{Squeeze theorem } still holds in n-dimensional space. \n\n\\subsection{Continuity}\nRemember how finding limits of continuous functions is super easy because $\\lim_{x\\to a} f(x) = f(a)$ if $f(x)$ is continuous? Well that still holds.\n\n\\paragraph{Definition of continuity: }\n\n$f(x, y)$ is continuous if $\\lim_{(x, y) \\to (a, b)} f(x, y) = f(a, b)$ for all $(a, b)$ in $D$ ($D$ is domain)\n\n\\paragraph{Polynomials and rationals with more than 1 variable: }\n\nPolynomials with two variables are the sum of $cx^my^n$ where $c$ is constant and $m$ and $n$ are non-negative integers.\n\nAll polynomials of two variables are continuous. \n\n\n\\section{Partial Derivatives}\n\nWhen we take the derivatives of functions of multiple variables, we can pretend that all varaibles are static except for one and take the regular derivative of that one variable.\n\nFor instance, if we were plotting the \\textit{price of a house} $p$ based on the size $s$ and the proximity $d$ to the ocean, we can take the \\textbf{partial derivative} with respect to the size of the house at a certain proximity to the ocean by pretending that the proximity to the ocean is a constant and thus making the \\textit{price of house} function a function of just the size of the house. \n$$p(s, d)$$\n$$p_s(s) = p(s, 50)$$\nAbove is an arbitrary value of $d$ at which to take the partial derivative.\n\n$p_s'(s)$ is the partial derivative with respect to $s$ at distance $d=50$.\n\nBased on this definition, the limit definition of derivatives would work exactly how you think they would work (basically just varying one variable by factor $a$ and keeping the other one the same)\n\n$$f_x(x, y) = lim_{h\\to 0}\\frac{f(x+h, y)-f(x, y)}{h}$$\n$$f_y(x, y) = lim_{h\\to 0}\\frac{f(x, y+h)-f(x, y)}{h}$$\n\nOther notations for partial derivatives (let $z = f(x, y)$)\n\n$$f_x(x, y) = f_x = \\frac{\\partial f}{\\partial x} = \\frac{\\partial}{\\partial x} f(x, y) = \\frac{\\partial z}{\\partial x} = D_1f = D_xf$$\n$$f_y(x, y) = f_y = \\frac{\\partial f}{\\partial y} = \\frac{\\partial}{\\partial y} f(x, y) = \\frac{\\partial z}{\\partial y} = D_2f = D_yf$$\n\n\\paragraph{How to find: }\nRegard the non-mentioned variable in the notation as a constant and differentiate with respect to the mentioned variable.\n\n\\subsection{Higher Partial Derivatives}\n$$(f_x)_y = f_{xy} = f_{12} = \\frac{\\partial}{\\partial y} (\\frac{\\partial f}{\\partial x}) = \\frac{\\partial ^2 f}{\\partial y \\partial x} = \\frac{\\partial z}{\\partial y \\partial x}$$\n\n\\subsubsection{Clairaut's Theorem}\nIf $f_{xy}$ and $f_{yx}$ are both \\textbf{defined} and \\textbf{continuous} on disk $D$ then:\n$$f_{xy}(a, b) = f_{yx}(a, b)$$\n\n\\subsection{Partial Differential Equations}\nBasically, they exist. We don't really learn how to solve them much in this section/course(?) because that would be super hard. Like think about how hard normal differential equations are, then imagine if they were PARTIAL differentiatial equations. Plus, in real life, you'd just use a computer for them like a normal human being. \n\n\\section{Tangent Planes and Linear Approximations}\nThe tangent plane to a point on a function of multiple variables is the plane that contains the first-order partial derivatives of that function at that point. In essence, it is the set of all linear approximations to the vectors produced by taking the partial derivative with respect to each independent variable.\n\\subsection{Tangent Planes}\n\\paragraph{The form of a plane passing through given points } $x_0$, $y_0$, and $z_0$ is:\n$$A(x-x_0) + B(y-y_0) + C(z-z_0) = 0$$\n\nRearranging and substituting some knowledge, we get:\n\\paragraph{Formula for tangent plane to a point: }\n$$z - z_0 = f_{x}(x_0, y_0) (x-x_0) + f_y(x_0, y_0)(y-y_0)$$\n\n\\subsection{Linear Approximations}\nThe tangent plane is analogous to the tangent line for functions of one variable. Like with the linear approximations we are used to, you just plug the known coordinates into the tangent plane function to find the linear (tangent plane) approximation.\n$$f(x, y) = f_{x}(x_0, y_0)(x-x_0) + f_y(x_0, y_0)(y-y_0) + f(a, b)$$\n\n\\paragraph{Important theorem on differentiability: } If $f_x$ and $f_y$ exist near $(a, b)$ \\textbf{and are continuous at $(a, b)$} then $f(x, y)$ is differentiable at $(a, b)$\n\n\\paragraph{$\\epsilon$-ish Theorem on Differentiability: } $f$ is differentiable at $(a, b)$ if $\\Delta z$ can be expressed as: \n$$ \\Delta z = f_x(a, b)\\Delta x + f_y(a, b)\\Delta y + \\epsilon_1x + \\epsilon_2y$$\nAnd the value of $\\epsilon_1, \\epsilon_2$ tends to zero as $\\Delta x, \\Delta y \\to 0$\n\n\\subsection{Differentials}\n$$dy = f'(x) dx$$\n$$dz = f_x(x, y)dx + f_y(x, y)dy = \\frac{\\partial z}{\\partial x} dx + \\frac{\\partial z}{\\partial y}dy$$\n\n\\section{Chain Rule (With Many Variables)}\n\\paragraph{Normal chain rule: }\n$$\\frac{dy}{dt} = \\frac{dy}{dx} \\frac{dx}{dt}$$\n\n\\subsection{Chain Rule: Case 1}\n$z = f(x, y)$ and $x = g(t)$ and $y = h(t)$. If $x$ and $y$ are differentiable functions of $t$, then $z(t)$ is a differentiable function of $t$\n$$\\frac{dz}{dt} = \\frac{\\partial f}{\\partial x} \\frac{dx}{dt} + \\frac{\\partial f}{\\partial y} \\frac{dy}{dt}$$\n\n\\subsection{Chain Rule: Case 2}\nPretty pointless, just use the general rule.\n\n\\subsection{Chain Rule: General Rule} \nIf $u$ is a differentiable function of $n$ variables and each $x_j$ is a differentiable function of $m$ variables $t_1 ... t_m$, then\n$$\\frac{\\partial u}{\\partial t_i} = \\frac{\\partial u}{\\partial x_1}\\frac{\\partial x_1}{\\partial t_i} + ... + \\frac{\\partial u}{\\partial x_n} \\frac{\\partial x_n}{\\partial t_i}$$\n\n\\subsection{Implicit Differentiation}\nAssume that an equation $F(x, y) = 0$ implicitly defines $y$ as a differentiable function of $x$.\n\nIf we let $y = f(x)$, then the above becomes $F(x, f(x)) = 0$.\n\nFrom there, we can use the chain rule (case 1) to find $\\frac{\\partial F}{\\partial x}$\n\n$$\\frac{\\partial F}{\\partial x} \\frac{\\partial x}{\\partial x} + \\frac{\\partial F}{\\partial y} \\frac{\\partial y}{\\partial x} = 0$$\n\n\\paragraph{Resulting Implicit Differentiation Theorem}\n$$\\frac{dy}{dx} = - \\frac{ \\frac{\\partial F}{\\partial x} }{ \\frac{\\partial F}{\\partial y} } = - \\frac{F_x}{F_y}$$\n\n$$\\frac{\\partial z}{\\partial x} = - \\frac{F_x}{F_z}$$\n$$\\frac{\\partial z}{\\partial y} = - \\frac{F_y}{F_z}$$\n\n\\section{Directional Derivatives and the Gradient Vector}\nWhat if you want to know the instantaneous rate of change as you in a direction that isn't perfectly aligned with an axis? Recall how \nif you have a function $f(x, y)$ you can have partial derivatives $f_x, f_y$ that you can use to find $df/dx, df/dy$. However, \nif you had a function of two variables describing the shape of a hill and wanted to know the curvature of the hill at a particular\npoint, it's more useful to be able to be able to find the instaneous rate of change of $f$ with respect to any given direciton.\n\n\\subsection{Directional Derivatives}\n\nRecall the definitions of partial derivatives $f_x$ and $f_y$:\n$$f_x(x_0, y_0) = lim_{h \\to 0} \\frac{f(x_0+h, y_0)-f(x_0, y_0)}{h}$$\n$$f_y(x_0, y_0) = lim_{h \\to 0} \\frac{f(x_0, y_0+h)-f(x_0, y_0)}{h}$$\n\nNow we can imagine that these are the instantaneous rates of change of $f$ in the $i$ and $j$ directions (the unit vectors, not the imaginary numbers).\n\n\\subsubsection{Definition: }\nLet $u$ be a unit vector $[a, b]$. Then\n\n$$D_u f(x_0, y_0) = lim_{h \\to 0} \\frac{f(x_0+ha, y_0+hb)-f(x_0, y_0}{h}$$\n\nis the directional derivative in the direction of u, assuming the limit exists.\n\n\\subsubsection{More useful definition: }\n$$D_u f(x, y) = f_x(x, y)a + f_y(x, y)b$$\nif $u = [a, b]$ is a unit vector.\n\n\\subsection{Gradient Vector}\nThe gradient vector is just the partials packaged into a vector. Often notated as 'grad $f$' or $\\nabla f$ (pronounced \"del f\")\n\n$$\\nabla f = [f_x, f_y]$$\n\nAlso can be written:\n\n$$\\nabla f(x, y) = \\frac{\\partial f}{\\partial x} i + \\frac{\\partial f}{\\partial y} j$$\n\n\\subsubsection{Maximizing the Directional Derivative}\nThe motivation here is to find the direction of steepest slope for a multi-variable function.\n\n\nIt \\textbf{always} will occur when $u$ (the direction vector) is in the same direction as $\\nabla f(x)$ (where $x$ is a vector of the inputs to the function.\n\n\\subsubsection{Tangent Planes to Level Surfaces}\nLet's say that $F(x, y, z) = k$ defines a \\textbf{3D surface}, and let $P$ be a point on that surface.\n\nLet $C$ be a curve that lies on surface $F$ going through $P$. \n\n$C = r(t) = [x(t), y(t), z(t)]$. Let $t_0$ be paramater value corresponding to point $P$ on curve.\n\n$F(x(t), y(t), z(t)) = k$ because $C$ lies on $F$.\n\nDifferentiating both sides give: $$\\frac{\\partial F}{\\partial x} \\frac{dx}{dy} + \\frac{\\partial F}{\\partial y} \\frac{dy}{dt} + ... = 0$$\n\nSince $\\nabla F = [F_x, F_y, F_z]$, that means that:\n\n$$\\nabla F(t) * r'(t) = 0$$\n\nTherefore the gradient of a surface will always be \\textbf{perpendicular} to the tangent plane of that surface!\n\nRemember how to write the equation for the plane tangent to a 3d surface (think of the expansion of the linearization thing...)?\n\nHere's how you write the equation of the gradient line and also the line tangent to the tangent plane to a 3d curve.\n\n\n$$\\frac{x-x_0}{F_x(x_0, y_0, z_0} = \\frac{y-y_0}{F_y(x_0, y_0, z_0} = \\frac{z-z_0}{F_z(x_0, y_0, z_0}$$\n\n\\section{Maximum and Minimum Values}\n\n\\subsection{Definitions}\n\\textbf{Local} maxima/minima are greater/less than points that are close (partial derivatives are all zero if they exist there).\n\\textbf{Absolute} maxima/minima are greater/less than ALL points in a specified region (partial derivatives are all zero if they exist there).\n\n\\subsection{Second Derivative Test}\nThe first derivative test mentioned above is pretty straight forward to extrapolate from previous stuff we've learned about 2D functions.\n\nThe second derivative test is a little weirder.\n\n\\paragraph{The Test: }\nIf $(a, b)$ has $f_x, f_y = 0$, let $$D = D(a, b) = f_{xx}(a, b)f_{yy}(a, b) - [f_xy(a, b)]^2$$\n\\begin{enumerate}\n\\item If $D > 0$ and $f_{xx} > 0$, then $f(a, b)$ is a local \\textbf{minimum}. \n\\item If $D > 0$ and $f_{xx} < 0$, then $f(a, b)$ is a local \\textbf{maximum}. \n\\item If $D < 0$ then $f(a, b)$ is a \\textbf{saddle point}. \n\\item If $D = 0$ no information is gained.\n\\end{enumerate}\n\n\\paragraph{Memory trick for $D$}\n$$D = |\n\\begin{bmatrix}\n\tf_{xx} & f_{xy} \\\\\n\tf_{yx} & f_{yy}\n\\end{bmatrix}\n|$$\n\n\\subsection{Absolute Max/Min Values}\n\\paragraph{What is a bounded set? }\nRemember how we needed to have the extreme value theorem only applied to intervals that included the endpoints (i.e. $[a, b]$ but not $(a, b)$)?\n\nSame with the new extreme value theorem for $R^2$. When you define a disk like $$D = {(x, y) | x^2 + y^2 \\leq 1}$$ you NEED to have a $\\leq$ in order to have a \\textbf{closed set}.\n\n\\subsubsection{Extreme Value Theorem for Functions of Two Variables}\nIf disk $D$ is a closed set where continuous function $f(x, y)$ is defined in $R^2$, it will achieve a maximum and a minimum point at some points in $D$.\n\n\\paragraph{How to find absolute min/max on disk $D$: } \n\\begin{enumerate}\n\\item Find the values of f at critical points (first derivatives = 0) in $D$\n\\item Find extreme values of f on boundary $D$.\n\\item Largest value found are absolute maximae, smallest value found is absolute minimum.\n\\end{enumerate}\n\n\\section{Lagrange Multipliers}\nBasically a way to solve for the global max/min of functions of many variables (e.g. $f(x, y)$ under some constraint $g(x, y) = k$\n\nYou gotta find max/min $c$ s.t. $f(x, y) = c$ while $g(x, y) = k$ still.\n\nThis happens when $f(x, y)$ and $g(x, y) = k$ have common tangent lines $\\frac{dy}{dx}$ (otherwise $c$ could be increased further).\n\nTherefore the normal lines where $f$ and $g$ touch are the same. And so $$\\nabla f(x_0, y_0) = \\lambda \\nabla g(x_0, y_0)$$ when intersection is maximized (for some Lagrange Multiplier $\\lambda$)\n\n\\subsection{Method of Lagrange Multipliers}\nTo find max/min of $f(x, y, z)$ under constraint $g(x, y, z) = k$:\n\\begin{enumerate}\n\\item Find all values of $x, y, z$ and $\\lambda$ s.t. $$\\nabla f(x, y, z) = \\lambda \\nabla g(x, y, z)$$ and $g(x, y, z) = k$.\n\\item Evaluate $f$ at all found points. The largest is the maximum and the smallest is the minimum of $f$ under condition $g$.\n\\end{enumerate}\n(Assuming exterme values exist and $\\nabla g \\neq 0$ on surface $g(x, y, z) = k$)\n\n\\subsection{Lagrange Multipliers with Two Constraints}\nNow we have to find two multipliers $\\mu$ and $\\lambda$ as follows:\n$$\\nabla f(x, y, z) = \\lambda \\nabla g(x, y, z) + \\mu \\nabla h(x, y, z)$$\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "9d404c7d7b61f25ecd75beeb75c165f7e64d4e2b", "size": 43645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/MAT195.tex", "max_stars_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_stars_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-10-25T06:03:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T02:14:13.000Z", "max_issues_repo_path": "tex/MAT195.tex", "max_issues_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_issues_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_issues_repo_licenses": ["MIT"], "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/MAT195.tex", "max_forks_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_forks_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-05T14:21:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T19:01:31.000Z", "avg_line_length": 48.7109375, "max_line_length": 399, "alphanum_fraction": 0.6930003437, "num_tokens": 14016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.6335926172441241}}
{"text": "\\acresetall\n% This is an example chapter from 'Polar Codes for Software Radio'. Do not use it but delete it! It serves as an example!\n\\chapter{System model}\\label{chapter:systemmodel}\nPolar codes are defined for a specific system model.\nThe objective of this chapter is to introduce the key concepts.\nNotations are introduced and important terms are revisited in order to refer to them.\n\n\\section{Key channel coding concepts}\nThe system model used throughout this thesis follows the remarks in \\cite{Richardson:2008:MCT} and \\cite{polar:arikan09}.\nIt is intended to define the domain for which polar codes are developed.\n\nThe objective of channel coding is to transmit information from a source to a sink over a point-to-point connection with as few errors as possible.\nA source wants to transmit binary data  $u \\in \\mathcal{U} = \\{0, 1\\}$ to a sink where $u$ represents one draw of a binary uniformly distributed random variable.\nThe source symbols are encoded, transmitted over a channel and decoded afterwards in order to pass an estimate $\\hat{u}$ to a sink.\n\nThis thesis uses a common notation for vectors which is introduced here shortly.\nA variable $x$ may assume any value in an alphabet $x \\in \\mathcal{X}$.\nMultiple variables are combined into a vector $x^N = (x_0, \\dots , x_{N-1})$ of size $N$ with its alphabet $x^N \\in \\mathcal{X}^N$.\nA subvector of $x^N$ is denoted $x_i^j = (x_i, \\dots, x_{j-1})$ where $0 \\leq i \\leq j \\leq N$.\nA vector where $i=j$ is an empty vector.\nA vector $x^N$ may be split into even and odd subvectors which are denoted $x_{0,e}^{2n} = (x_0, x_2, \\dots, x_{2n-2})$, $x_{0,o}^{2n} = (x_1, x_3, \\dots, x_{2n-1})$.\nThis numbering convention is in accordance with \\cite{dijkstra:zerocounting}, where the author makes a strong point for this exact notation and some papers on polar codes follow it too, e.g. \\cite{polar:talvardy:howtoCC}.\n\n\n\\subsection{Encoder}\nThe encoder takes a frame $u^k$ and maps it to a binary codeword $x^N$, where $k$ and $N$ denote the vector sizes of a frame and a codeword respectively with $k \\leq N$.\nAn ensemble of all valid codewords for an encoder is a code $\\mathcal{C}$.\nIt should be noted that $|\\mathcal{C}| = |\\mathcal{X}^N|$ must hold in order for the code to be able to represent every possible frame.\n\nNot all possible symbols from $\\mathcal{X}^N$ are used for transmission.\nThe difference between all possible codewords $2^N$ and used codewords $2^k$ is called redundancy.\nWith those two values, the code rate is defined as $R = \\frac{k}{N}$.\nIt is a measure of efficient channel usage.\n\nThe encoder is assumed to be linear and to perform a one-to-one mapping of frames to codewords.\nA code is linear if $\\alpha x + \\alpha' x' \\in \\mathcal{C}$ for $\\forall x, x' \\in \\mathcal{C}$ and $\\forall \\alpha, \\alpha' \\in \\mathbb{F}$ hold.\nIt should be noted that all operations are done over the Galois field GF(2) or $\\mathbb{F} = \\{0, 1\\}$ if not stated otherwise.\nThen the expression can be simplified to \n\\begin{equation}\n x + x' \\in \\mathcal{C} \\quad \\textrm{for} \\quad \\forall x, x' \\in \\mathcal{C}.\n\\end{equation}\nA linear combination of two codewords must yield a codeword again.\n\nFor linear codes it is possible to find a generator matrix $G \\in \\mathbb{F}^{k \\times N}$ and obtain a codeword from a frame with $x^N = u^k G^{k \\times N}$.\nAll linear codes can be transformed into systematic form $G = I_k P$.\n$I_k$ is a $k \\times k$ dimensional identity matrix.\nIf $G$ is systematic, all elements of a frame $u^k$ are also elements of the codeword $x^N$.\nAlso, a parity check matrix $H = -P^T I_{N-k}$ with dimensions $(N-k) \\times N$ can be calculated from $G$.\nA parity check matrix satisfies $\\forall x \\in \\mathcal{C}: H x^T = 0^T $.\nThus, a parity check matrix can be used to verify correct codeword reception and furthermore error correction may be performed.\nError correction with $H$ may be done, e.g. syndrome decoding.\n\nA code can be characterized by the minimum distance between any two codewords.\nIn order to obtain this value we use the Hamming distance.\nThis distance $d(v^N,x^N)$ equals the number of positions in $v^N$ that differ from $x^N$.\nMinimum distance of a code is than defined by $d(\\mathcal{C}) = \\min\\{d(x,v): x,v \\in \\mathcal{C}, x \\neq v\\}$.\nFor linear codes this can be simplified to comparing all codewords to the zero codeword $d(\\mathcal{C}) = \\min\\{d(x,0): x \\in \\mathcal{C}, x \\neq 0\\}$ which is called Hamming weight.\n\n\\subsection{Channel model}\\label{sec:channel_model}\nChannel coding relies on a generic channel model.\nIts input is $x \\in \\mathcal{X}$ and its distorted output is $y \\in \\mathcal{Y}$.\nA channel is denoted $W: \\mathcal{X} \\rightarrow \\mathcal{Y}$ along with its transition probability $W(y|x), x \\in \\mathcal{X}, y \\in \\mathcal{Y}$.\nA \\ac{DMC} does not have memory, thus every symbol transmission is independent from any other.\nCombined with a binary input alphabet it is called a \\ac{BDMC}.\nFor a symmetric channel model, $P(y|1) = P(-y|-1)$ must hold for an output alphabet $y \\in \\mathcal{Y}, \\mathcal{Y} \\subset \\mathbb{R}$ \\cite{Richardson:2008:MCT}.\nAssuming symmetry for a \\ac{BDMC} leads to a symmetric \\ac{BDMC}.\nIn Sec. \\ref{theory:channels} several examples of such channels are discussed.\n\nThis channel concept may be extended to vector channels.\nA vector channel $W^N$ corresponds to $N$ independent uses of a channel $W$ which is denoted as $W^N : \\mathcal{X}^N \\rightarrow \\mathcal{Y}^N$.\nAlso, vector transition probabilities are denoted $W^N(y^N|x^N) = \\prod_{i=0}^{N-1} W(y_i|x_i)$.\n\n\\subsection{Decoder}\nA decoder receives a possibly erroneous codeword $y$ and checks its validity by asserting $H y^T = 0^T$, thus performing error detection.\nA more sophisticated decoder tries to correct errors by using redundant information transmitted in a codeword.\nAn optimal decoder strategy is to maximize the a-posteriori probability.\nGiven the probability of each codeword $P(x)$ and the channel transition probability $P(y|x)$, the task at hand is to find the most likely transmitted codeword $x$ under the observation $y$, $P(x|y)$.\nThis is denoted\n\\begin{equation}\n \\hat{x}^{MAP} = \\argmax_{x \\in \\mathcal{C}} p(x|y) = \\argmax_{x \\in \\mathcal{C}} p(y|x) \\frac{p(x)}{p(y)} = \\argmax_{x \\in \\mathcal{C}} p(y|x) p(x)\n\\end{equation}\nwith Bayes' rule.\nAssume every codeword is transmitted with same probability $P(x^{(i)}) = P(x^{(j)}), \\; \\forall x^{(i)}, x^{(j)} \\in \\mathcal{C}$.\nThis simplifies the equation and yields a \\ac{ML} decoder\n\\begin{equation}\n \\hat{x} = \\argmax_{x \\in \\mathcal{C}} p(y|x)\n\\end{equation}\nwhich estimates the most likely codeword to be transmitted given a received possibly erroneous codeword \\cite{Richardson:2008:MCT}.\nThis decoding principle could be employed in conjunction with the Hamming distance and thus yield $\\hat{x} = \\argmin_{x \\in \\mathcal{C}} d(x, y)$.\nIn conclusion the task at hand is to find a code which inserts redundancy intelligently, so a decoder can use this information to detect and correct transmission errors.\n\n\\subsection{Asymptotically good codes}\\label{theory:repetition_code}\nA repetition code is a very simple code which helps clarify certain key concepts in the channel coding domain.\nAssume the encoder and decoder use a repetition code.\nFor example a repetition code with $k=1$ and $N = 3$ has two codewords $\\mathcal{C} = \\{000, 111\\}$.\nThus in this example $R=\\frac{1}{3}$.\nWe can also obtain its generator and parity check matrices.\n\\begin{equation}\n G = \\begin{pmatrix} 1 & 1 & 1 \\end{pmatrix},\\qquad H = \\begin{pmatrix} 1 & 1 & 0 \\\\ 1 & 0 & 1 \\end{pmatrix}\n\\end{equation}\n$H$ can be used to detect if a transmission error occurred by verifying if $H x^T = 0^T$.\nIn case an error occurred, a \\ac{ML} decoder does a majority decision to estimate the most likely codeword.\n\nRepetition codes shed light on a problem common to a lot of codes.\nIf reliability of a code needs to be improved, it comes at the expense of a lower code rate.\nIncreasing $N$ comes at the expense of decreasing $R = \\frac{1}{N}$ because $k=1$ for all repetition codes.\nThus for a very reliable repetition code $\\lim_{N \\rightarrow \\infty} R$ tends towards $0$.\n\nThe above results leads to the definition of asymptotically good codes $\\mathcal{C}(N_s, k_s, d_s)$ \\cite{Friedrichs:2010:error-control-coding}.\nTwo properties must hold for this class of codes,\n\\begin{equation}\n R = \\lim_{s \\rightarrow \\infty} \\frac{k_s}{N_s} > 0 \\quad \\textrm{and} \\quad  \\lim_{s \\rightarrow \\infty} \\frac{d_s}{N_s} > 0.\n\\end{equation}\nThe code rate must be $>0$ for all codes which repetition codes do not satisfy.\nAnd the distance between codewords must grow proportionally to the code block size.\n\n\\section{Channels}\\label{theory:channels}\nSeveral common channel models exist to describe the characteristics of a physical transmission.\nCommon properties were discussed in Section \\ref{sec:channel_model} whereas in this Section the differences are targeted.\nThe three most important channel models for polar codes are presented, namely the \\ac{BSC}, the \\ac{BEC} and the \\ac{AWGN} channel.\n\n\\subsection{AWGN channel}\nAn \\ac{AWGN} channel as used in this thesis has a binary input alphabet and a continuous output alphabet $\\mathcal{Y} = \\mathbb{R}$.\nEach input symbol is affected by Gaussian noise to derive an output symbol.\nIts average corresponds to the input symbol value and the variance can be interpreted as a measure of noise.\nOften the input is \\ac{NRZ} encoded which turns a \\ac{ML} decision for a symbol into a sign decision.\n\n\\subsection{Capacity and reliability}\nChannels are often characterized by two important measures, capacity and reliability.\nThese measures are introduced in this Section.\nChannel capacity for symmetric \\ac{BDMC} can be calculated by\n\\begin{equation}\n I(W) = \\frac{1}{2} \\sum_{y \\in \\mathcal{Y}} \\sum_{x \\in \\mathcal{X}} W(y|x) \\log_2 \\frac{W(y|x)}{\\frac{1}{2} (W(y|0) + W(y|1))}.\n\\end{equation}\nIt defines the highest rate at which a reliable transmission over a channel $W$ can be conducted while the error probability may still tend towards $0$.\nIt is also called the Shannon capacity \\cite{sha49} for symmetric channels.\nThe Bhattacharyya parameter\n\\begin{equation}\n Z(W) = \\sum_{y \\in \\mathcal{Y}} \\sqrt{W(y|0) W(y|1)}\n\\end{equation}\nis used to quantify a channel's reliability where a lower value for $Z(W)$ indicates higher reliability.\nIt is also referred to as Z-parameter for obvious reasons.\nAlso, an upper \\ac{ML} decision error bound is given by $Z(W)$ \\cite{polar:arikan09}.\n", "meta": {"hexsha": "f41cf93e753578c6faa26f4eca2061f6a957e139", "size": 10495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "master-thesis/chapters/systemmodel.tex", "max_stars_repo_name": "primercuervo/cognitive_radio_ml", "max_stars_repo_head_hexsha": "641ba01c18815f5c58375ea2710511c5bbfe3522", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-08-28T15:44:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-16T15:50:15.000Z", "max_issues_repo_path": "master-thesis/chapters/systemmodel.tex", "max_issues_repo_name": "astro7x/cognitive_radio_ml", "max_issues_repo_head_hexsha": "641ba01c18815f5c58375ea2710511c5bbfe3522", "max_issues_repo_licenses": ["MIT"], "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/chapters/systemmodel.tex", "max_forks_repo_name": "astro7x/cognitive_radio_ml", "max_forks_repo_head_hexsha": "641ba01c18815f5c58375ea2710511c5bbfe3522", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-12-12T16:11:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T10:36:01.000Z", "avg_line_length": 72.8819444444, "max_line_length": 221, "alphanum_fraction": 0.7390185803, "num_tokens": 3027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6335925992809469}}
{"text": "\\section{Polynomial Parity Argument}\n\\label{ppad-sect}\n\nAs mentioned in section \\ref{cc-sect},\nMegiddo and Papadimitriou \\cite{megiddo-papad} have proved that,\nunless $\\mathrm{\\mathbf{NP}}=\\mathrm{\\mathbf{co-NP}}$,\nthe class $\\mathrm{\\mathbf{TFNP}}$\n({\\em total function non-deterministic polynomial-time})\ndoes not have complete problems.\nTo circumvent this\n\\linebreak[4]\nlimitation, Papadimitriou \\cite{ppad} focused\non the argument that proves that a problem in {\\bf TFNP} has indeed\na solution. To study this he introduced, among others, the classes\n$\\mathrm{\\mathbf{PPA}}$ ({\\em Polynomial Parity Argument}) and\n$\\mathrm{\\mathbf{PPAD}}$\n\\linebreak[4]\n({\\em Polynomial Parity Argument, Directed version}).\n\nThe existence of a solution for a problem in {\\bf PPA} can be proved\nusing the argument ``in any undirected graph with one odd-degree node\nthere must be another odd-degree node.''\n%% they exist - omit\n% It is interesting to notice that {\\bf PPA}-complete\n% problems are yet to be found.\nSimilarly, problems in {\\bf PPAD} are guaranteed to have a\nsolution by a proof employing the argument ``in any directed graph in\nwhich all vertices have indegree and outdegree at most one and there is\na {\\em source} (a node with indegree zero) there must be a {\\em sink}\n(a node with outdegree zero).''\nFormally: a polynomial-sized {\\em circuit} with $n$ {\\em input bits} and\n$m$ {\\em output bits} is a function $C:\\{ 0,1 \\}^n\\to \\{ 0,1 \\}^m$\nthat can be represented with polynomially many standard ``logic gates''.\nWe define {\\bf PPAD} as the class of problems reducible to\nthe problem {\\sc End Of The Line}, see Table \\ref{eotl}.\nThis is the definition given in Daskalakis, Goldberg and Papadimitriou\n\\cite{dgp}; the original definition in Papadimitriou \\cite{ppad} is given\nin terms of polynomial-time Turing machines instead of\npolynomial-sized circuits.\n\n\\begin{problem}\n{End Of The Line}\n{Two polynomial-sized circuits $S$ and $P$ with $n$ input bits and $n$\noutput bits such that $P(0^n)=0^n\\neq S(0^n)$.}\n{An input $x\\in \\{ 0,1 \\}^n$ such that $P(S(x))\\neq x$ or\n$S(P(x))\\neq x\\neq 0^n$}\n\\label{eotl}\n\\end{problem}\n\nThe problems in {\\bf PPAD} can be seen as a circuit $S$ (``successor''),\nand a circuit $P$ (``predecessor'') that are used to construct a directed\ngraph with an edge $(x,y)$ if and only if $S(x)=y$ and $P(y)=x$. Furthermore,\nthe graph is guaranteed to have a {\\em standard source} $0^n$, which is\nalso given in the\n\\linebreak[4]\ninput; this guarantees the existence of the\noutput, which is either a sink or a non-standard source.\nFigure \\ref{ppad-graph} presents an example of a graph implicit in a\n{\\bf PPAD} problem.\n\n\\clearpage\n\n\\begin{figure}[hbtp]\n\\strut\\hfill\n\\includegraphics[width=80ex]{chapter-3/fig-ppad/PPAD.pdf}%\n\\hfill\\strut\n\\caption[A PPAD problem]{%\nA {\\bf PPAD} problem as a directed graph with maximal indegree and\n\\linebreak[4]\noutdegree 1.\n\nThe input is given by the circuits $S$ (in green) and $P$ (in red) and\nthe standard source (the yellow node).\nThese circuits are used to define paths (in black), cycles (in blue) and\nisolated points (in purple).\n\nThe output can be either a sink\n(a red node) or a nonstandard source (a green node).\n}\n\\label{ppad-graph}\n\\end{figure}\n\nA graph for a {\\bf PPA} problem is analogous to Figure \\ref{ppad-graph}, but\nit is\n\\linebreak[5]\nundirected and instead of sources and sinks there are\ngeneric endpoints.\n\\linebreak[5]\nAnother class relying on proofs by parity argument is\n{\\bf PPADS}, defined by Daskalakis, Goldberg and Papadimitriou \\cite{dgp};\nits definition is analogous to {\\bf PPAD}, but the output of the problem is\nrequired to be a sink of the {\\sc End Of The Line} graph. We have that\n$\\mathbf{PPADS}\\subseteq\\mathbf{PPAD}\\subseteq\\mathbf{PPA}$; it is\nan open problem whether the inclusion is strict.\n\nAs we have already noticed, the problem $n$-{\\sc Nash}, see\nTable \\ref{n-nash}, is a\n\\linebreak[4]\ntotal function problem.\nPapadimitriou \\cite{ppad} proved that it\nbelongs to {\\bf TFNP}. Daskalakis, Goldberg and Papadimitriou \\cite{dgp} and\nChen and Deng \\cite{cd} have later proven its {\\bf PPAD}-completeness, the\nformer for $n\\geq 3$ and the latter for $n\\geq 2$.\nA small amendment of the proof in \\cite{dgp} can be found in Casetti\n\\cite{msc-diss}.\n\n\\begin{theorem}{\\rm (Daskalakis, Goldberg and Papadimitriou \\cite{dgp};\nChen and\n\\linebreak[5]\nDeng \\cite{cd})}\\label{nash-ppad-complete-thm}\nFor $n\\geq 2$, the problem {\\sc $n$-Nash} is {\\bf PPAD}-complete.\n\\end{theorem}\n", "meta": {"hexsha": "e063b674bbe568f099149063df308145f0d2e642", "size": 4468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-3/ppad.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-3/ppad.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-3/ppad.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": 39.5398230088, "max_line_length": 77, "alphanum_fraction": 0.7358997314, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.633503993601234}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{alltt,fullpage,graphics,color,epsfig,amsmath, amssymb}\n\\usepackage{hyperref}\n\\usepackage{boxedminipage}\n\\usepackage[ruled,vlined]{algorithm2e}\n\n\\newcommand{\\floor}[1]{\\lfloor #1 \\rfloor}\n\\newcommand{\\ceil}[1]{\\lceil #1 \\rceil}\n\n\\title{Algorithmic Game Theory HW2}\n\\author{Daniel Campos}\n\\date{October 30th, 2020}\n\\begin{document}\n\n\\maketitle\n\\begin{enumerate}\n\\section{Problem 1}\n%----------------------------------------------------------------------\n\\item \n\\begin{enumerate}\n    \\item (3 points) The following game has a unique Nash equilibrium. Find\nit, and prove that it is unique. (Hint: look for strict dominance.)\n\\begin{center}\n\\begin{tabular}{| c | c | c | c|}\n\\hline\n\\textbf{Strategy} & \\textbf{X} & \\textbf{Y} & \\textbf{Z} \\\\ \\hline \\hline\n\\textbf{A} & 4, 0 & 1, 1 & 4, 0 \\\\ \\hline\n\\textbf{B} & 1, 3 & 2, -1 & 3, 5 \\\\ \\hline\n\\textbf{C} & 0, 1 & 3, 0 & 3, 0 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\subsection{Solution}\nWe begin by seeking a strict dominance. Since there is no single strategy strict dominance we search for a mixed strategy strict dominance.\n\\begin{enumerate}\n    \\item For the mixed strategy A + C assume player 1 chooses strategy A with probability $p$ and strategy C with probability $1-p$ we find the following expected outcomes For player 2s strategy X $4(p) + 1(1-p)= 4p +1 -p = 3p +1$ which is > 1 which is the result of strategy B. For player 2s strategy Y $1(p) + 3(1-p) = p + 3 - 3p = 3 - 2p$ which for $p \\le 0.5$ is equal or better to strategy B. For player 2s strategy Z $4(p) + 3(1-p) = 4p+3-3p=3+p$ which for $p \\ge 0$ is an equal or better strategy than B. Thus mixed strategy A + C strictly dominates strategy B.\n    \\item For player 2 now that player 1 will not play strategy B their strategy Z is strictly dominated by X and Y since strategy Z only produces no gains. This leaves us with the table below. \n    \\item\n    \\begin{tabular}{| c | c | c |}\n    \\hline\n    \\textbf{Strategy} & \\textbf{X} & \\textbf{Y} \\\\ \\hline \\hline\n    \\textbf{A} & 4, 0 & 1, 1 \\\\ \\hline\n    \\textbf{C} & 0, 1 & 3, 0 \\\\ \\hline\n    \\end{tabular}\n    \\item In the table above we find no single strategy strict dominant equilibrium so once again we look for mixed strategies. Let the probability that player 1 chooses strategy  A be $p$ and the probability the choose strategy B $1-p$. We set the $E_x = E_y$ and since $E_x = 4*p + 0(1-p) = 4p + 0$ and $E_y = 1(p) + 3(1-p) = 3 - 2p$ thus $4p = 3 - 2p$ which simplifies to $6p = 3$ meaning $p=\\frac{1}{2}$.\n    \\item Similarly let the probability that player 2 chooses strategy X be $q$ and the probability they choose strategy Y $1-q$. $E_a = 0*q + 1(1-q) = 1 -q$ and $E_c = 1*q + 0(1-q) = q$ and since $E_c = E_a$ $1 - q = q$ which simplifies to $1 = 2q$ meaning $q = \\frac{1}{2}$. \n    \\item Since $q = \\frac{1}{2}$ and $p = \\frac{1}{2}$ AX, AY, CX, and CY are Nash equilibriums each with a probability $\\frac{1}{4}$\n\\end{enumerate} \n\n\\item (4 points). Construct a single $2 \\times 2$ normal-form game that simultaneously\nhas all four of the following properties:\n\\begin{enumerate}\n\\item The game does not have a dominant strategy Nash equilibrium (at least one player does not have a dominant strategy).\n\\item The game is solvable by iterated weak dominance (so that one pure strategy per player remains).\n\\item In addition to the iterated weak dominance solution (which is a Nash\nequilibrium), there is a second pure-strategy Nash equilibrium.\n\\item Both players strictly prefer the second equilibrium to the first.\n(Hints: the second pure-strategy equilibrium should not be strict; the pure strategy equilibria should be in opposite corners of the matrix.) If you cannot get all four properties, construct an example with as many of the properties as you can.\n\\end{enumerate}\n\\subsection{Solution}\n\\begin{center}\n\\begin{tabular}{| c |  c | c |}\n\\hline\n\\textbf{Strategy} & \\textbf{X} & \\textbf{Y}\\\\ \\hline \\hline\n\\textbf{a} & 1, 1 & 5, 3 \\\\ \\hline\n\\textbf{b} & 4, 2 & 6, 1 \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\begin{enumerate}\n\\item We meet not having a dominant strategy because  player 2(who plays rows) does not have a dominant strategy.\n\\item We meet the second criteria since player 1 has a dominant strategy and will always play strategy b. Since player 1 will always play strategy b player 2 will chose to play strategy X and the NE is 4,2.\n\\item We meet the third criteria and fourth criteria because we have a second pure-strategy NE of 5,3 which is opposite the iterate weak dominance NE. If both players had pure strategy then they would chose strategy Y and B giving them the maximum reward of 5,3.\n\\end{enumerate}\n\\item (3 points). Consider the following game:\n\\begin{center}\n\\begin{tabular}{| c | c | c |}\n\\hline\n\\textbf{Strategy} & \\textbf{X} & \\textbf{Y}\\\\ \\hline \\hline\n\\textbf{a} &2, 5 & 1, 5 \\\\ \\hline\n\\textbf{b} &7, 1 & 0, 0 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nFind a correlated equilibrium that places positive probability on all entries of the matrix, except the lower-right hand entry. Try to maximize the probability in the upper-left hand entry.\n\\end{enumerate}\n\\subsection{Solution}\nFirst Assume a third party draws one of three cards labeled (A,X), (A, Y), or (B,X) with the probabilities $\\frac{4}{8}$ , $\\frac{3}{8}$, $\\frac{1}{8}$. After drawing the card the third party informs the players of the strategy assigned to them on the card (but not the strategy assigned to their opponent). For player 1(playing rows) the expected utility of strategy a is $2*\\frac{1}{2} + 1*\\frac{1}{2} = 1.5$ and the expected utility of strategy b is $7*\\frac{1}{2} + 0*\\frac{1}{2} = 3.5$ meaning they would prefer strategy b. For player 2(playing columns) the expected utility of strategy x is $5*\\frac{1}{2} + 1*\\frac{1}{2} = 3$ and the expected utility of strategy y is $2*\\frac{1}{2} + 0*\\frac{1}{2} = 2.5$ so they prefer strategy X. If they play the card they are assigned player 1 has a expected utility of $2*\\frac{1}{2} + 7*\\frac{3}{8} + 1*\\frac{1}{8} = \\frac{30}{8} = 3.75$ and player 2 has a expected utility of $5*\\frac{1}{2} + 1*\\frac{3}{8} + 5*\\frac{1}{8} = \\frac{28}{8} = 3.5$. Since neither player has an incentive to deviate, this is a correlated equilibrium with the highest probability being in the upper left hand entry.\n\\item Consider a symmetric $2$ person game between Alice and Bob, with the same strategy set $S$ for both players. Let $A(i, j)$ and $B(i,j)$ denote the payoff of Alice and Bob respectively, when Alice plays $i$ and Bob plays $j$. We say that the game is symmetric if we have that $A(i,j) = B(j,i)$ for all $i,j \\in S$, {\\em i.e.,} $B=A^T$.\n\\section{Problem 2}\n\\begin{enumerate}\n    \\item (2 points) Can a symmetric game have a pure Nash equilibria? (even if all values $A(i,j)$ are different?)\n    \\subsection{Solution}\n    Yes. Take the prisoners dilemma as an example. One of the pure strategies is Betray, Betray. Both players betraying is a nash equilibria because both players are always better off betraying regardless of the other players choice. \n    \\item (2 points) Do all symmetric games have pure Nash equilibria?\n    \\subsection{Solution}\n    No. Take Rock Paper Scissors as an example. It is a  three strategy symmetric game with no pure-strategy equilibrium. None of the six pure strategies (RR, RP, RS, PP, PS, SS) are equilibria. The same goes for a game like the penny matching game where two players choose an action heads or tails. Player 1 wins if there is a match, player 2 if there is not. None of the pure-strategy profiles (HH,TT,HT,TH) constitute an equilibrium.\n    \\item (6 points) J. Nash showed that every symmetric game has a symmetric equilibrium, i.e., a probability distribution $x\\in \\Delta(S)$ such that $(x,x)$ is an Nash equilibrium. Using this fact derive a quadratic program to compute a symmetric equilibrium of game $(A,A^T)$. \n    \\subsection{Solution}\n    First we must define what a the nash equilibria are in matrix form. A nash equilibra for the game is a pair of strategies $(x, y) \\in \\delta_i \\delta_j$ such that $x^{T} A y \\ge x A y ,\\forall x \\in \\delta_i$ and $x^{T} A^{T} y \\ge x A^{T} y ,\\forall x \\in \\delta_j$. \\\\\n    Given that nash prove that that symmetric equilibrium are probability distributions we formalize this problem as a quadriatic feasability problem. \n    \n    \\begin{equation}\n    \\begin{split}\n    \\min_{x \\in \\mathbb{R}^i, y \\in \\mathbb{R}^j} \\; 0 \\; \\\\ subject \\; to \\; x^{T} A y \\ge x A y ,\\forall x \\in {1,...,i}, \\\\\n    x^{T} A^{T} y \\ge x A^{T} y ,\\forall y \\in {1,...,j}, \\\\\n    x_i \\ge 0, \\forall i \\in {1,...,i}, \\\\\n    y_i \\ge 0, \\forall j \\in {1,...,j}, \\\\\n    \\sum_{m=1}^{i}x_m = 1, \\\\\n    \\sum_{n=1}^{j}y_n = 1.\n    \\end{split}\n    \\end{equation}\n\\end{enumerate}\n\\section{Problem 3}\n\\item The $1$-dimensional Sperner's problem is defined on a 1-dimensional grid from $[0, 2^n-1]$, with each integer being a grid point. There are two colors, red and blue, represented by $0$ and $1$ respectively. \nThere is a Boolean circuit named {\\em Color,} which outputs the color ($0$/$1$ bit) of a grid point given its bit representation, such that,\nColor($0$) = red, Color($2^n-1$) = blue, and the remaining grid points get any color.\n\n\\begin{enumerate}\n    \\item (4 points) Show that there exists an integer $0\\le k \\le 2^n-1$ such that Color($k$)=red and Color($k+1$)=blue. Furthermore, we can compute it in $O(n)$ calls to the Boolean circuit ``Color''.\n    \\subsection{Solution}\n     To rephrase we know that essentially there is a discrete function that can create the 1d grid which produces values 0 and 1. Since it begins with 0 and ends with 1 then it much switch values an odd number of times. As such there is at least 1 integer k where this switch occurs and Color(k) = red and color(k+1) = blue. To find k we only need O(n) calls to the boolean circuit because at each call we essentially learn two things. If for spot k $0 \\ge k \\ge 2^n-1$ we call color(k) and we get blue we know that somewhere between [1,k] there has been a switch to blue and thus only need to further search in range [1,k-1]. If we call color(k) and the color is red we know that either we have not passed the switch point or there is at least one more switch between $[k+1,2^n-1]$. As a result we are essentially doing a binary search which is o(log(x)) and since our $x=n^2-1$ our search time is $< O(n-1) -1 $ since we know start and end(2 points) and our x value.\n    \\item (6 points) Show that checking if there are more than one such $k$s is NP-complete (hint: reduce from 3-SAT).\n    \\subsection{Solution}\n    To solve this we make this a 3-SAT problem by setting up the representation that a point $k = (x_1 \t\\land x_2 \t\\land x_3)$ where $x_1$ is color(k) = red, $x_2$ is color(k+1) = blue and $x_3$ is $ 0 \\le k \\le 2^n -1$. We must do this for every point in $[0,2^n-1]$ as a result we set up a graph where each each one of the 3 satisfy able variables is a vertex. Then if this value i is a k value then there will be an independent set of size k. Since we have to run this for every step in the grid the run time is np complete.\n\\end{enumerate}\n\\section{Problem 4}}\n\\item (10 points) In the town of Gamica, there is exactly one police patrol, two police stations ($s$ and $t$), and one robber. The robber plans to target a house on one of the streets at night, say on street $i\\in [n]$. If street $i$ is patrolled by the police then they get $r_i$ reward while the robber gets $\\zeta_i$ cost, otherwise police's cost is $c_i$ and the robber's reward is $\\rho_i$. \n\nEvery night, the police can patrol exactly one route from station $s$ to station $t$. \\textcolor{red}{At night all the streets are one way, and the street network forms a DAG}. Design a polynomial time algorithm to compute Stackelberg strategy of the police. \\\\\n\n{\\em (Hint: What is the corresponding DBR problem? Can that be solved in polynomial time?)}\nDefender's Best Response\n\\subsection{Solution}\nFirst off, I will start on declaring my assumptions. First assumption is that the robber will be at the house they are targeting all night and thus it does not matter when the police pass the house but only that the robbed house is on their path from s to t. The next assumption is the robber has no notion of previous day's path. Since the optimization goal is to pick the longest path from s to t police do not have incentive to change their strategy day to day. If a robber had a notion of the previous days route they would just chose something off the longest path. \\\\\nFollowing those assumptions the stackelberg strategy of the police is to find the longest path in the DAG from s to t so that they can cover the most houses. The reason this is the stacklberg strategy is the police are trying to optimize how many houses they can cover on their patrol and the way to maximize this is to take the longest path possible between the two stations. To find the longest distance we use algorithm \\ref{algo1} and then we use algorithm  \\ref{algo2} to find paths that match the longest length. We select from the longest paths one at random so the robber cannot predict. \\\\\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwResult{Longest Path distance finder}\n\\hspace*{\\algorithmicindent} \\textbf{Input:}Weighted DAG G = (V,E) \\\\\n\\hspace*{\\algorithmicindent} \\textbf{Output:} Largest path cost in G \\\\\nTopologically sort G \\\\\n\\For{vertex $v \\in V$} {\n    $dist(v) = max_{(u,v) \\in E} \\{dist(u) + w(u,v)$\\} }\n\\textbf{return} $max_{v \\in V} \\{dist(v)}$\n \n \\caption{Longest Path Distance Finder}\n \\label{algo1}\n\\end{algorithm}\\\\\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwResult{Police Patrolling Path}\n\\hspace*{\\algorithmicindent} \\textbf{Input:}all paths from s to t $P = [(s,v_1),(v_1,v2), ...,(v_n,t)]$ \\\\\n\\hspace*{\\algorithmicindent} \\textbf{Output:}max-distance = algorithm1 \\\\\npossible-paths = []\\\\\n\\For{$p \\in P$} {\n    \\If{$len(p) == max-distance$}{\n        possible-paths.add($p$)\n    } }\n\\textbf{return} possible-paths[random-number(0,len(possible-paths))]\n \\caption{Path Finder version1}\n \\label{algo2}\n\\end{algorithm}\\\\\nIf instead we assume that the polices preferences are common knowledge we must add some randomization to ensure that robber does not stay off the longest path. To ensure that police don't only follow the longest path we introduce a approximation variable $\\epsilon$. Instead of search for the longest path the police offices look for all paths within $\\epsilon$ of the longest path and then select one of these paths at random. $\\epsilon$ is a learned parameter and must be defined based on the actual DAG size and the desired policing behavior. Our modified stackleber strategy is shown in algorithm \\ref{algo3}. \\\\\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwResult{Police Patrolling Path}\n\\hspace*{\\algorithmicindent} \\textbf{Input:}all paths from s to t $P = [(s,v_1),(v_1,v2), ...,(v_n,t)]$ , $\\epsilon$ \\\\\n\\hspace*{\\algorithmicindent} \\textbf{Output:}max-distance = algorithm1 \\\\\npossible-paths = []\\\\\n\\For{$p \\in P$} {\n    \\If{$len(p) + \\epsilon \\ge max-distance$}{\n        possible-paths.add($p$)\n    } }\n\\textbf{return} possible-paths[random-number(0,len(possible-paths))]\n \\caption{Path Finder version1}\n \\label{algo3}\n\\end{algorithm}\\\\\nBoth of these implementations are polynomial time.\n\\section{Problem 5}\n\\item Consider the extensive-form game shown in the figure.\n\n\\begin{figure}[!ht]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{hw2-Figure.png}\n\\caption{An extensive-form game with imperfect information.}\n\\end{figure}\n\n\\begin{enumerate}\n    \\item (3 points). Give the normal-form representation of this game.\n    \\subsection{Solution}\n    Let player one represented by rows and player 2 by columns\n    \\begin{center}\n    \\begin{tabular}{| c | c | c |}\n    \\hline\n    \\textbf{Strategy} & \\textbf{L} & \\textbf{R} \\\\ \\hline \\hline\n    \\textbf{L} &  7,3 & 0,2\\\\ \\hline\n    \\textbf{M} &  0,2 &  7,3 \\\\ \\hline\n    \\textbf{R} &  1,0 & 3,3  \\\\ \\hline\n    \\end{tabular}\n    \\end{center}\n    \\item (3 points). Give a Nash equilibrium where player $1$ sometimes plays left. (Remember that you must specify each player's strategy at {\\em every} information set.)\n    One such equilibrium is Player 1 has a mixed strategy of $\\frac{1}{2}$ for L and $\\frac{1}{2}$  for R with an expected value of 3.5 and player 2 has a mixed strategy of $\\frac{1}{2}$ L and $\\frac{1}{2}$  R with an expected value of 2.50\n    \\subsection{Solution}\n    \\item (4 points). Characterize the subgame perfect equilibria of the game. (Remember that you must specify each player's strategy at {\\em every} information set.)\n    \\subsection{Solution}\n    This game has two sub-games: player 2 choice after player 1 plays their choice, and the entire game. For the sub game after player 1 has chosen there are 3 perfect equilibria. When player 1 plays L the subgame perfect equilibrium is R. When player 2 plays M player 2 plays R. When Player 1 plays R player player 2 plays R.For the whole game there are two perfect equilibria: Player 1 chooses L and Player 2 chooses L and player 1 chooses M and player 2 chooses R. Both of these are perfect equilibria because for those two choices Player 2 will employ a pure strategy(since in both cases 3 dominates 2. They are both perfect equilibria because there is no dominant strategy for player 1 as as a result they will play L with probability $\\frac{1}{2}$ and M with probability $\\frac{1}{2}$.\n\\end{enumerate}\n\\section{Problem 6}\n\\item (10 points) Consider an atomic selfish routing game in which all players have the same source vertex and sink vertex (and each controls one unit of flow). Assume that edge cost functions are non-decreasing, but do not assume that they are affine. Prove that a pure-strategy Nash equilibrium can be computed in polynomial time. Be sure to discuss the issue of fractional vs. integral flows, and explain how (or if) you use the hypothesis that edge cost functions are non-decreasing.\n\\medskip\n\\subsection{Solution}\nDefining some notation there is a set of $n$ players and there is a set of resource $S_i$ and a delay function $d_e(j)$ where it is nondecreasing. Let $s = (s_1,...,S-n)$ represent a state and the cost be represented by $c_i(s) = -u_i(s) = \\sum_{e \\in s_i} d_d(f_s(e)$  where $u$ is the utility.\\\\\nFirst we must prove that Every congestion game\nhas a pure Nash equilibrium. Our result of the routing is $\\phi (s) = \\sum_e \\sum_{j=1}^{f_s(e)} d_e(j)$. We can then swap the summations giving $\\phi(s) = \\sum_{i=1}^{n} \\sum_{e \\in s_i} d_e(f_s^{\\le i}(e)$. Lets then assume that there is some improvable defection where the defecting player is n. \\\\\nAs a result\\\\ $\\phi(s^') - \\phi(s) = \\sum_{e \\in s_i} d_e(f_s'^{\\le n}(e) - \\sum_{e \\in s_i} d_e(f_s^{\\le n}(e) $ \\\\ \n$= \\sum_{e \\in s_i} d_e(f_s'(e) - \\sum_{e \\in s_i} d_e(f_s(e)$ \\\\\n$= c_i(s^') - c_i(s)$. This shows that  $\\phi$ decreases on all parts of nash dynamics and hence $s$ was a pure equilibria.\\\\\nNow for our algorithm we apply a reduction of min-cost flow. Give a network $N=(V,E,s,t)$ where s is start and t is end, and the delay function $d_e$ we move through each edge in $N$ and replace the edge with n parallel. This is based on the idea of fraction flow where the demand of each player on a path can be split over several paths between edges as long as the costs are equal. Since the costs are equal each agent will use a separate path as it is the path with the least congestion. This allows the network to effectively have a unique path from s to t without really having a unique path(aka integral flow). Once each edge has been split into n parallel edges each with a capacity of 1 and a cost that is increasing per use we use our min-cost algorithm to find a flow. Since each path between each edge will now be used at most once then any min-cost flow is going to minimize $phi(s)$. This will run in polynomial time because the min-cost flow must now iterate over each edge E n times, for each d thus $O(|E|∗n∗d)$.\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "02cae7b977c0213e772be7f60249424350d205c6", "size": 19910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW2 Game Theory/main.tex", "max_stars_repo_name": "spacemanidol/CS-598-RM-Algorithmic-game-theory", "max_stars_repo_head_hexsha": "cc5b3e58137c98f4d03a21c7f0e651f7bb0a3a1e", "max_stars_repo_licenses": ["MIT"], "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/HW2 Game Theory/main.tex", "max_issues_repo_name": "spacemanidol/CS-598-RM-Algorithmic-game-theory", "max_issues_repo_head_hexsha": "cc5b3e58137c98f4d03a21c7f0e651f7bb0a3a1e", "max_issues_repo_licenses": ["MIT"], "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/HW2 Game Theory/main.tex", "max_forks_repo_name": "spacemanidol/CS-598-RM-Algorithmic-game-theory", "max_forks_repo_head_hexsha": "cc5b3e58137c98f4d03a21c7f0e651f7bb0a3a1e", "max_forks_repo_licenses": ["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.0904977376, "max_line_length": 1141, "alphanum_fraction": 0.7125062783, "num_tokens": 5856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6335039908247149}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\betadist}{Beta}\n\n\\usepackage{textcomp}\\usepackage{xcolor}\n\\newcommand{\\notaestesa}[2]{%\n  \\marginpar{\\color{red!75!black}\\textbf{\\texttimes}}%\n  {\\color{red!75!black}%\n    [\\,\\textbullet\\,\\textsf{\\textbf{#1:}}%\n    \\textsf{\\footnotesize#2}\\,\\textbullet\\,]}%\n}\n\\newcommand{\\SC}[1]{\\notaestesa{SC}{#1}}\n\n\\newcommand{\\ie}{\\textit{i.e.}}\n\\newcommand{\\eg}{\\textit{e.g.}}\n\n\\begin{document}\n\n% genotype quality\n%----------------------------------------------------------------------\n\\section{Genotype quality model}\n\nWe can model the genotype as the tossing of a coin.  In particular a\nread could be either correct or incorrect, in the sense that a read\ncould either respect the genotype or it could be an error | where such\nerror would happen with probability $\\epsilon$ | the technology error,\n\\eg, 15\\% in the case of PacBio.  Hence, the model would represent a\ncoin toss where the coin is not fair, in particular we would have a\n$(1-\\epsilon)$ probability of obtaining a head (\\ie, a correct read\naccording to the given genotype) and an $\\epsilon$ chance of obtaining\na tail (\\ie, an error in the read).\n    \nNow we consider a set of observations $D$ representing the reads\nassociated with a given genomic locus and denote as $\\theta$ the\nprobability of obtaining a correct genotype (tossing an head in our\nmetaphor).  We want to obtain a $\\theta$ that maximizes our\nobservations, thus we want the \\emph{Maximum a posteriori} (MAP) value\nfor $\\theta$:\n\n\\begin{equation}\n  \\begin{split}\n    \\theta_{MAP} &= \\argmax_\\theta P(\\theta | D) \\\\\n    &= \\argmax_\\theta P(D|\\theta)P(\\theta)\n  \\end{split}\n\\end{equation}\n\n\\noindent where the second equation is an expansion using Bayes's\ntheorem, and $P(D) = 1$, since we have the data.\n\nConsidering each term, we know that $P(D|\\theta)$ is the likelihood\nthat the outcome is distributed according to a Bernoulli model:\n$\\theta^{\\alpha_{C}} (1-\\theta)^{\\alpha_{E}}$, that is the probability\nof obtaining $\\alpha_{C}$ correct reads according to the genotype and\n$\\alpha_{E}$ errors in the reads.  Maximizing this value alone would\ngive us the \\emph{Maximum likelihood estimation} (MLE), which is,\nhowever, very dependent on the observations | indeed it would be\nextremely unreliable in cases where the number of reads is low.  For\nexample, recalling our coin tossing scenario, if we saw $n$ heads and\nno tail according to the MLE we would expect a tail in the $n+1$-st\ntoss with probability 0, even though this is clearly not the case.\n\nConsider now the factor $P(\\theta)$ which is the prior probability of\n$\\theta$, distributed according to a \\textit{Beta} distribution, in\ndetail:\n\\begin{equation*}\n  P(\\theta) = \\dfrac{\\theta^{\\beta_{C}-1} (1 - \\theta)^{\\beta_{E}-1}}\n  {B(\\beta_{C},\\beta_{E})}\n\\end{equation*}\nwhere $\\beta_{C}$ and $\\beta_{E}$ are respectively the number of\ncorrect genotypes and errors according to a prior expectation and\n$B(\\beta_{C},\\beta_{E})$ is the binomial distribution | therefore\n$P(\\theta)$ is distributed as a Beta distribution:\n$P(\\theta) \\sim \\betadist(\\beta_{C},\\beta_{E})$.\n\nSince the conjugate prior of a binomial is a Beta distribution and\nwith some algebraic interpolation, whose details I will leave out\nhere, we have that\n$P(\\theta | D) \\sim \\betadist(\\beta_{C} + \\alpha_{C},\\beta_{E} +\n\\alpha_{E})$ where $\\alpha$ according to the number of observations\nand the $\\beta$ is according to the number expected given a prior.\nIn particular the mode of the MAP distribution is then:\n\\begin{equation}\n  \\theta_{MAP} = \\dfrac{\\beta_{C} + \\alpha_{C} - 1}\n  {\\beta_{C} + \\alpha_{C} + \\beta_{E} + \\alpha_{E} - 2}\n  \\label{eq:MAP}\n\\end{equation}\n\n\\subsection{Genotype quality measure}\nOnce we have acquired $\\theta_{MAP}$ we have some option to compute\nthe quality of the genotype.  To obtain a quality of the genotype we\nuse a Z-test to measure the fitness of the sample according to our\nnull hypothesis.  The Z-test is used to evaluate a distribution that\ncan be approximated by a normal distribution.\n\nWe consider the null hypothesis $H_0$ as the hypothesis that the reads\ncome from a binomial distribution with probability $(1-\\epsilon)$ of\nbeing correct and $\\epsilon$ of being errors.  We assume that this\nprobability is not fixed and can be modeled as a normal distribution\ncentered in $(1-\\epsilon)$ with standard deviation $\\sigma$, thus\n$H_0 \\sim \\mathcal{N}(1-\\epsilon, \\sigma)$.  The meaning of this\napproximation is that in a perfect world we should have exactly\n$(1-\\epsilon)$ probability of getting a correct read, but since the\nworld is not perfect this probability is not fixed and there is a\ndeviation of the error rate in different loci; while maintaining an\n$\\epsilon$ rate over all the genome.\n\nWe can then consider our sample at a given locus, with a probability\nof having a correct read equal to $\\theta_{MAP}$.  The z-score will be\ncalculated as follows, where $n$ is the coverage at the locus:\n\\begin{equation*}\n  \\mbox{z-score} = \\dfrac{1-\\epsilon - \\theta_{MAP}}{\\sigma / \\sqrt{n}}\n\\end{equation*}\n        \nThe quality measure would then be the corresponding p-value of the\nz-score of the fitting of the observations to $H_0$.  In particular\nthis would mean that values that have a large amount of errors would\nhave a low quality, while loci with a smaller amount of errors than\nexpected would not be heavily penalized since this low expectation\nwould be mitigated by the prior probability.  Such p-value is denoted\nas $G_{l_1}$ in the following.\n\n\\paragraph{Obtaining distribution values for the hypothesis}\n\nTo complete the definition we would need to obtain the values of the\nstandard deviation for $H_0$ and $H_1$.  Considering $H_0$ first we\ncan compute the standard deviation $\\sigma_i$ of the Binomial\ndistribution for each locus $i$ by exploring the whole genome.  The\nstandard deviation would be calculated as\n$\\sigma_i = \\sqrt{n_i (1-\\epsilon) \\epsilon}$ where $n_i$ is the\ncoverage at locus $i$; the standard deviation $\\sigma$ of $H_0$ would\nthen be the mode or average of all the $\\sigma_i$.  A similar\nprinciple can be applied to obtain $\\hat{\\sigma}$ for each hypothesis\n$H_1$ computed at each locus.\n\nIt is clear that $\\sigma_i$ does not depend on the genotype but only\non the coverage, for this reason it is possible to compute it much\nfaster using a simulation, in fact we can generate $M$ samples, with\ncoverage $n_i \\sim \\mathcal{N}(\\mu_c, \\sigma_c)$, meaning that the\ncoverage of a simulation is drawn from a normal distribution with\nstandard deviation $\\sigma_c$ and with mean equal to the average\ncoverage $\\mu_c$ of the technology used.  In this way, it is not\nnecessary to scan the entire genome to obtain the coverage of every\nlocus, but they can be estimated using a prior assumption on the\ntechnology used.\n\n\\paragraph{Obtaining prior values for the genotypes}\n\nThe most sensitive part would be to define the prior values for the\ngenotypes, \\ie, values of $\\beta_C$ and $\\beta_E$ of\nequation~\\ref{eq:MAP}, since low values could be too heavily weighted\nby the observations and, conversely, high values could overweigh the\nobservations.  One way to overcome this issue is to simulate a drawing\nfrom $H_0$ of a total of $m$ samples, where $m$ is a user-defined\nparameter.  According to this method $\\beta_C$ and $\\beta_E$ would be\nthe number of correct and errors, respectively, obtained in the\nsimulation over the total of $m$ samples from $H_0$.\n\n% phasing quaility\n%----------------------------------------------------------------------\n\\section{Phasing quality}\n\nWe consider two genomic loci $l_1$ and $l_2$ and their proposed\nphasing $Q_{l_1,l_2}$; let $n$ be the number of reads that bridge the\ntwo loci and $k$ the number of reads that support the phasing.  We\ndenote as $O$ the observations, \\ie, the $n$ reads bridging $l_1$ and\n$l_2$.  If we assume that $Q_{l_1,l_2}$ is correct that would mean\nthat the $k$ reads supporting the phasing are correct and the $(n-k)$\nthat oppose the phasing contain an error at $l_1$ or $l_2$ or both.\n\nTo obtain the probability that there is no error in the $k$ reads we\ncan start by calculating the probability that a read contains an error\nin $l_1$ or $l_2$ or both as follows:\n\n\\begin{equation*}\n  \\begin{split}\n    P(\\mbox{error in read}) &= P(\\mbox{error in }l_1  \\vee \\mbox{error in }l_2) \\\\\n    &= P(\\mbox{error in }l_1) + P(\\mbox{error in }l_2) - P(\\mbox{error in }l_1  \\wedge \\mbox{error in }l_2)\\\\\n    &= \\epsilon + \\epsilon - \\epsilon^2 = \\epsilon(2-\\epsilon)\n  \\end{split}\n\\end{equation*}\n\nIf we consider the whole set of reads that bridge both $l_1$ and\n$l_2$, then the probability that there is no error in the $k$ reads\nwill be equal to $(1 - \\epsilon(2-\\epsilon))^k$.  To compute the\nprobability that there is an error in the other $n-k$ reads it will\nsimply be $(\\epsilon(2-\\epsilon))^{n-k}$, therefore:\n\n\\begin{equation}\n  P(Q_{l_1,l_2}|O) = (1 - \\epsilon(2-\\epsilon))^k \n  (\\epsilon(2-\\epsilon))^{n-k}\n  \\label{eq:phasing-epsilon}\n\\end{equation}\n\nIt is possible to sophisticate the model by using the values computed\nfor the MAPs --- in fact we denote as $\\theta_{MAP}(l_i)$ the MAP\ncomputed for locus $i$ thus we can rewrite\nequation~\\ref{eq:phasing-epsilon}:\n\n\\begin{equation}\n  P(Q_{l_1,l_2}|O) = (\\theta_{MAP}(l_1)\\theta_{MAP}(l_2))^k\n  (1- \\theta_{MAP}(l_1)\\theta_{MAP}(l_2))^{n-k}\n\\end{equation}\n\n% haplotyping quality\n%----------------------------------------------------------------------\n\\section{Haplotyping quality}\n\nTo obtain the quality of the entire haplotyping we can combine the two\nprevious probabilities.  In particular we use the genotype\nprobabilities to weigh the phasing probabilities.  In detail it is the\nprobability of the genotype of $l_1$ and the probability of the\ngenotype of $l_2$ that function as weight for the probability of the\nphasing, informally:\n\n\\begin{equation*}\n  \\begin{split}\n    &\\prod_{\\forall l_1, l_2} P(\\mbox{genotype } l_1 \\wedge \\mbox{ genotype } l_2) \n    P(\\mbox{phasing of } l_1, l_2) = \\\\\n    &\\prod_{\\forall l_1, l_2} P(\\mbox{genotype } l_1) P(\\mbox{ genotype } l_2) \n    P(\\mbox{phasing of } l_1, l_2)\n  \\end{split}\n\\end{equation*}\n\nWhich will formally be equal to:\n\n\\begin{equation}\n  \\prod_{\\forall l_1, l_2} G_{l_1} G_{l_2} P(Q_{l_1,l_2}|O)\n\\end{equation}\n\n\\end{document}\n  \n%  LocalWords:  Genotype genotype posteriori MLE genotypes MAPs\n%  LocalWords:  overweigh\n", "meta": {"hexsha": "4be541660a791d546f95c99d33b66f07069db8b1", "size": 10413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/quality-measures.tex", "max_stars_repo_name": "AlgoLab/HapQual", "max_stars_repo_head_hexsha": "63fcde81efcc72d9ab8a049bf35d753866a233cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-30T06:10:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-30T06:10:33.000Z", "max_issues_repo_path": "documents/quality-measures.tex", "max_issues_repo_name": "AlgoLab/HapQual", "max_issues_repo_head_hexsha": "63fcde81efcc72d9ab8a049bf35d753866a233cb", "max_issues_repo_licenses": ["MIT"], "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/quality-measures.tex", "max_forks_repo_name": "AlgoLab/HapQual", "max_forks_repo_head_hexsha": "63fcde81efcc72d9ab8a049bf35d753866a233cb", "max_forks_repo_licenses": ["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.1228813559, "max_line_length": 109, "alphanum_fraction": 0.7195812926, "num_tokens": 2984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6335039803641829}}
{"text": "\\documentclass[paper=A4, pagesize, 12pt]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[pdftex]{hyperref}\n\\hypersetup{colorlinks=true,\n  urlcolor=blue}\n\\parindent0mm\n\n\\usepackage{amsfonts,amsmath,amssymb}\n\\usepackage{mathtools}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern}\n\\usepackage{a4wide}\n\\usepackage[charter]{mathdesign}\n\n\\newcommand{\\sd}{\\sqrt{d^2 - 1}}\n\\newcommand{\\sdm}{\\sqrt{1-d^2}}\n\n\\title{Spring Equations}\n\\author{K. Jünemann}\n\n\\begin{document}\n\\maketitle\n\n\\section{The differential equation}\nA mass $m$ attached to a spring with spring constant $k$, friction constant\n$r$ and external force $F(t)$ is described by the equation\n\\[\nm \\ddot{y}(t) + r \\dot{y} (t) + k y(t) = F(t).\n\\]\n$y(t)$ is the deviation of the pendulum mass from its rest position.\n\nIt is useful to introduce the eigen-frequency\n\\[\n\\omega_0 = \\sqrt{\\frac{k}{m}}\n\\]\nand the dimensionless friction constant\n\\[\nd = \\frac{r}{2\\sqrt{km}}.\n\\]\n$d>1$ means strong friction (no oscillations) and $d<1$ means low friction.\nThe equation then reads after dividing by $m$:\n\\[\n\\ddot{y}(t) + 2 d \\omega_0 \\dot{y} (t) + \\omega_0^2 y(t) = \\frac{1}{m} F(t)\n\\]\nIf the external force is exerted by moving the upper suspension point of the\nspring by some deviation $u(t)$ out of its rest position the force is $F(t) =\nk\\cdot u(t)$ leading to the main equation\n\\begin{equation}\n  \\label{eq:main}\n  \\ddot{y}(t) + 2 d \\omega_0 \\dot{y} (t) + \\omega_0^2 y(t) = \\omega_0^2 u(t)\n\\end{equation}\n\n\\section{Step- and Impulse response}\nThis section assumes vanishing initial conditions, $y(0) =0\\, , \\dot{y}(0) = 0$.\n\nThe impulse response is\n\\begin{itemize}\n  \\item for $d>1$:\n  \\[\n  h(t) =\n  \\sigma(t) \\frac{\\omega_0}{2\\sqrt{d^2 - 1}}\n  \\mathrm{e}^{- d\\, t\\, \\mathrm{\\omega_0}}\\,\n  \\left(\n    \\mathrm{e}^{t\\,\n      \\mathrm{\\omega_0}\\, \\sqrt{d^2 - 1}} - \\mathrm{e}^{- t\\,\n      \\mathrm{\\omega_0}\\, \\sqrt{d^2 - 1}}\n  \\right)\n  \\]\n  \\item for $d=1$:\n  \\[\n  h(t) = \\sigma(t) \\cdot \\omega_0^2 t e^{-\\omega_0 t}\n  \\]\n  \\item for $0\\leq d<1$:\n  \\[\n  h(t) =\n  \\sigma(t) \\frac{\\omega_0}{\\sqrt{1 - d^2}}\n  \\mathrm{e}^{- d\\, t\\, \\mathrm{\\omega_0}}\\, \\sin\\!\\left(t\\,\n    \\mathrm{\\omega_0}\\, \\sqrt{1 - d^2}\\right)\n  \\]\n\n\\end{itemize}\n\nThe step response is\n\\begin{itemize}\n  \\item for $d>1$:\n  \\[\n  g(t) =\n  \\sigma(t) \\cdot \\left (\n    1 - \\frac{1}{2}e^{-d\\omega_0 t}\n    \\left (\n      e^{t\\omega_0 \\sqrt{d^2-1}} \\left ( 1 + \\frac{d}{\\sqrt{d^2-1}} \\right )\n      + e^{-t\\omega_0 \\sqrt{d^2-1}} \\left ( 1 - \\frac{d}{\\sqrt{d^2-1}} \\right )\n    \\right )\n  \\right )\n  \\]\n\n\n  % \\frac{\\sigma(t) - \\mathrm{e}^{- t\\, \\mathrm{\\omega_0}\\, \\left(d - \\sqrt{d^2 -\n  %   1}\\right)}\\, \\sigma(t)}{2\\, m\\, {\\mathrm{\\omega_0}}^2\\, \\left(d\\, \\sqrt{d^2\n  %   - 1} - d^2 + 1\\right)} - \\frac{\\mathrm{e}^{- t\\, \\mathrm{\\omega_0}\\, \\left(d +\n  %   \\sqrt{d - 1}\\, \\sqrt{d + 1}\\right)}\\, \\sigma(t)\\, \\left(\\mathrm{e}^{t\\,\n  %   \\mathrm{\\omega_0}\\, \\left(d + \\sqrt{d^2 - 1}\\right)} - 1\\right)}{2\\, m\\,\n  % {\\mathrm{\\omega_0}}^2\\, \\sqrt{d^2 - 1}\\, \\left(d + \\sqrt{d^2 - 1}\\right)}\n\n  \\item for $d=1$:\n  \\[\n  g(t) = \\sigma(t) \\cdot \\left (\n    1 - e^{-\\omega_0 t} (1+t\\omega_0)\n  \\right )\n  \\]\n\n  \\item for $0\\leq d<1$:\n  \\[\n  g(t) =\n  \\sigma(t) \\cdot \\left (\n    1 - e^{-d \\omega_0 t}\n    \\left (\n      \\cos(t\\omega_0 \\sqrt{1-d^2})\n      + \\frac{d}{\\sqrt{1-d^2}}\\sin(t\\omega_0 \\sqrt{1-d^2})\n    \\right )\n  \\right )\n  \\]\n\\end{itemize}\n\n\n\\section{Solution with initial conditions without external force}\nWith no external force, i.e. $F(t)=0$, but initial position $y_0$ and velocity\n$v_0$, i.e.\n\\begin{equation}\n  \\label{eq:init-cond}\n  y(0) = y_0 \\; , \\qquad \\dot{y}(0) = v_0,\n\\end{equation}\n\nthe solution of the equation is\n\\begin{itemize}\n  \\item for $d>1$:\n  \\begin{align*}\n    y_{\\text{init}}(t) &= \\frac{v_0 + y_0\\omega_0 \\sd + d \\omega_0 y_0}{2\\omega_0 \\sd }\n    \\text{e}^{\\omega_0({\\sd-d})t}  \\\\\n    &- \\frac{v_0 - y_0\\omega_0 \\sd + d \\omega_0 y_0}{2\\omega_0 \\sd }\n    \\text{e}^{-\\omega_0({\\sd-d})t}\n  \\end{align*}\n\n  \\item for $d=1$:\n    \\[\n    y_{\\text{init}}(t) = y_0 \\text{e}^{-\\omega_0 t} + (v_0 + y_0 \\omega_0) t \\text{e}^{-\\omega_0 t}\n    \\]\n\n  \\item for $0\\leq d<1$:\n  \\begin{align*}\n    y_{\\text{init}}(t) &= y_0 \\text{e}^{-\\omega_0 t}  \\cos(\\omega_0 \\sdm \\cdot t) \\\\\n    &+ \\frac{v_0 + d y_0 \\omega_0}{\\omega_0 \\sdm} \\sin(\\omega_0 \\sdm \\cdot t)\n  \\end{align*}\n\n\\end{itemize}\n\n\n\n\n\\section{Solution with harmonic external force and zero initial conditions}\nLet's assumue the motion of the upper suspension is\n\\[\nu(t) = u_0 \\cdot \\sin(\\omega_e t)\n\\]\nwith some given amplitude $u_0$, and external\nfrequency $\\omega_e$.\nAlso, the pendulum motion starts with zero initial conditions,\ni.e.\n\\[\ny(0) = 0\\; , \\qquad \\dot{y}(0) = 0.\n\\]\nThen the solution of the main equation (\\ref{eq:main}) is\n\\begin{itemize}\n  \\item for $0\\leq d<1$:\n  \\[\n  y_{\\text{ext}}(t) =\n  2\\, d\\, \\omega_0\\, \\omega_e A\n      \\mathrm{e}^{-\n        d\\, t\\, \\omega_0}\\, \\left(\\cos\\!\\left(t\\, \\omega_0\\, D \\right)\n        + \\frac{\\sin\\!\\left(t\\, \\omega_0\\, D \\right)\\, \\left(2\\, d^2\\, {\\omega_0}^2 - {\\omega_0}^2\n            + {\\omega_e}^2\\right)}{2\\, d\\, {\\omega_0}^2\\, D } \\right)\n      \\]\n      \\[\n      - A\n        \\left({\\omega_e}^2\\, \\sin\\!\\left(t\\, \\omega_e\\right) -\n          {\\omega_0}^2\\, \\sin\\!\\left(t\\, \\omega_e\\right) + 2\\, d\\,\n          \\omega_0\\, \\omega_e\\, \\cos\\!\\left(t\\,\n            \\omega_e\\right)\\right)\n      \\]\n      with\n      \\[\n      D = \\sqrt{1-d^2}\\; , \\qquad\n      A =  \\frac{u_0\\, {\\omega_0}^2}{4\\, d^2\\, {\\omega_0}^2\\, {\\omega_e}^2 +\n        {\\omega_0}^4 - 2\\, {\\omega_0}^2\\, {\\omega_e}^2 +\n        {\\omega_e}^4}\n      \\]\n      \\item for $d=1$:\n      \\[\n      y_{\\text{ext}}(t) =\n      2A \\omega_0\\, \\omega_e\\, \\mathrm{e}^{- t\\,\n          \\omega_0}\n      \\]\n      \\[\n      +\n      A {(\\omega_0}^2 - \\omega_e^2) \\sin\\!\\left(t\\,\n          \\omega_e\\right)  -2\\, A {\\omega_0}\\, \\omega_e\\,\n        \\cos\\!\\left(t\\, \\omega_e\\right)\n      \\]\n      \\[\n      + t\\, B\n        \\omega_e\\, \\mathrm{e}^{- t\\,\n          \\omega_0}\n      \\]\n      with\n      \\[\n      A = \\frac{u_0 \\omega_0^2}{({\\omega_0}^2 + {\\omega_e}^2)^2}\\; , \\qquad\n      B = \\frac{u_0 \\omega_0^2}{{\\omega_0}^2 + {\\omega_e}^2}\n      \\]\n\n\n      \\item for $d>1$:\n      \\[\n      y_{\\text{ext}}(t) =\n      2\\, d\\, A{\\omega_0}\\, \\omega_e\\, \\mathrm{e}^{-\n        d\\, t\\, \\omega_0}\\, \\left(\\cosh\\!\\left(t\\, \\omega_0\\, D \\right)\n        + \\frac{\\sinh\\!\\left(t\\, \\omega_0\\, D\\right)\\, \\left(2\\, d^2\\,\n            {\\omega_0}^2 - {\\omega_0}^2 +\n            {\\omega_e}^2\\right)}{2\\, d\\, {\\omega_0}^2\\, D}\\right)\n      \\]\n      \\[\n      - A\n        \\left({\\omega_e}^2\\, \\sin\\!\\left(t\\, \\omega_e\\right) -\n          {\\omega_0}^2\\, \\sin\\!\\left(t\\, \\omega_e\\right) + 2\\, d\\,\n          \\omega_0\\, \\omega_e\\, \\cos\\!\\left(t\\,\n            \\omega_e\\right)\\right)\n      \\]\n      with\n      \\[\n      A = \\frac{u_0\\, {\\omega_0}^2}{4\\, d^2\\, {\\omega_0}^2\\,\n        {\\omega_e}^2 + {\\omega_0}^4 - 2\\, {\\omega_0}^2\\,\n        {\\omega_e}^2 + {\\omega_e}^4}\n      \\]\n      \\[\n      D = \\sqrt{d^2 - 1}\n      \\]\n\n\n\\end{itemize}\n\n\n\\section{Solution with harmonic external force and non-zero initial conditions}\nLet's assumue the motion of the upper suspension is\n\\[\nu(t) = u_0 \\cdot \\sin(\\omega_e t)\n\\]\nwith some given amplitude $u_0$, and external\nfrequency $\\omega_e$.\nAlso, the pendulum motion starts with non-zero initial conditions\n(\\ref{eq:init-cond}). Then the solution $y(t)$ of the main equation\n(\\ref{eq:main}) splits into two pieces\n\\[\ny(t) = y_{\\text{init}}(t) + y_{\\text{ext}}(t)\n\\]\nwhere the first term is the motion due to the initial conditions and the second\nterm the motion due to the external force.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "833a501c63397239a65295a39ef7b3720b2a0300", "size": 7598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/spring_equations.tex", "max_stars_repo_name": "kjuen/SpringPendulum2D", "max_stars_repo_head_hexsha": "f134a856eb925720a12ba8ab77c7b29801621e93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-30T18:15:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-30T18:15:49.000Z", "max_issues_repo_path": "theory/spring_equations.tex", "max_issues_repo_name": "kjuen/SpringPendulum2D", "max_issues_repo_head_hexsha": "f134a856eb925720a12ba8ab77c7b29801621e93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-02-15T06:17:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-04T18:25:55.000Z", "max_forks_repo_path": "theory/spring_equations.tex", "max_forks_repo_name": "kjuen/SpringPendulum2D", "max_forks_repo_head_hexsha": "f134a856eb925720a12ba8ab77c7b29801621e93", "max_forks_repo_licenses": ["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.9338235294, "max_line_length": 99, "alphanum_fraction": 0.5511976836, "num_tokens": 3141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.633479073985444}}
{"text": "\n\\section{Expectation Maximization in the Loop}\n\n% Using a unimodal prior tends to result in predictions which look relatively similar in shape. To promote diversity among predicted 3D dog shapes, our method extends the formulation above to incorporate a mixture of Gaussians prior. We represent the mixture as a set of $M$ Gaussians, whose means are initialized by drawing samples from our existing prior:\n\n% \\begin{align}\n%     \\mu_{\\shape}^{m} &\\sim N(\\mu_{\\shape}, \\Sigma_{\\shape}) \\\\\n%     \\Sigma_{\\shape}^{m} &:= \\Sigma_{\\shape}\n% \\end{align}\n\n% We assign each training image $i$ with a set of mixture weights $\\{w_{i}^{1}, \\dots w_{i}^{M}\\}$, where initially $w_{i}^{m} := \\frac{1}{M}.$\n\n% We can then apply the following mixture shape loss:\n\n% \\begin{equation}\n%     L_{mixture}=\\sum_{m=1}^M w_{i}^{m}L_{shape}(\\shape_{i}, \\mu_{\\shape}^{m}, \\Sigma_{\\shape}^{m})\n% \\end{equation}\n\n% In order to allow our mixture prior to learn ``in-the-loop\" from the available training data, we apply expectation maximization every $k$ epochs during training. This step recomputes the means and variances for each mixture component based on the observed shapes in the training set, and updates the per-image mixture weights:\n\n% \\begin{align}\n%     \\mu_{\\shape}^{m} :=& \\mathrm{E}_{i}[\\beta_{i}W_{i}^{m}]\\\\\n%     \\Sigma_{\\shape}^{m} :=& \\mathrm{Cov}_{i}[\\beta_{i}W_{i}^{m}, \\beta_{i}W_{i}^{m}]\\\\\n%     w_{i}^{m} :=& \\frac{L_{shape}(\\shape_{i}, \\mu_{\\shape}^{m}, \\Sigma_{\\shape}^{m})}{\\sum_{m'}^{M}L_{shape}(\\shape_{i}, \\mu_{\\shape}^{m'}, \\Sigma_{\\shape}^{m'})}\n% \\end{align}\n\n\n% \\section{Attempt 2}\n\nAs previously discussed, the parameters for the mixture shape-scale prior are initialized using artist data which results in a prior that poorly represents the diverse shapes present in the real dog dataset. A key contribution presented in this chapter is the introduction of a procedure based on Expectation Maximization which gradually improves the representational power of the shape-scale prior by learning from monouclar images of in-the-wild dogs and their respective 2D training labels.\n\n% \\subsection{Assigning image weights}\n\n\\def\\imgweight#1#2{w_{#1}^{#2}}\n\nFirstly, each training image is assigned a set of latent variables $\\{\\imgweight{i}{1}, \\dots, \\imgweight{i}{M}\\}$ which encode the likelihood that the dog in image~$i$ was generated according to each shape-scale component~$m \\in \\{1,\\dots,M\\}$. \n\nExpectation Maximization (EM) is then used to regularly update these image weights, as well as the parameters for the mixture $(\\shapescalemu^{m},\\shapescalecov^{m},\\shapescalepi^{m})_{i=1}^{M}$. During the training loop of the 3D reconstruction network, these parameters are tuned according to alternating expectation (`E-') and maximization (`M-') steps which are described below:\n\n% TODO - add me!\n% Each training image $i$ is assigned a set of latent variables encoding the probability of the dog shape in image~$i$ being generated by component~$m$. \n\n% This is addressed by proposing to recover the latent variables $w_{i}^{m}$ and parameters $\\shapescalemu^{m}$, $\\shapescalecov^{m}$ and $\\shapescalepi^{m}$ ($\\mu_{\\shape}^{m}$, $\\Sigma_{\\shape}^{m}$ and $\\Pi_{\\shape}^{m}$) of our 3D shape prior by learning from monocular images of in-the-wild dogs and their 2D training labels in our training dataset.\n\n% We achieve this using Expectation Maximization (EM), which regularly updates the means and variances for each mixture component and per-image mixture weights based on the observed shapes in the training set. While training our 3D reconstruction network, we progressively update our shape mixture model with an alternating `E' step and `M' step described below:\n\n\\subsection{Expectation Maximization update steps}\n\n\\subsubsection{The `E' Step.}\nThe `E' step computes the expected value of the image weights~$w_{i}^{m}$ \nassuming fixed $(\\shapescalemu^{m},\\shapescalecov^{m},\\shapescalepi^{m})$ for all $i \\in \\{1,\\dots,N\\}, m \\in \\{1,\\dots,M\\}$.\n\nThe update equation for an image $i$ with latest scale-shape prediction $\\shapescale_{i}$ and cluster $m$ with parameters $(\\shapescalemu^{m},\\shapescalecov^{m},\\shapescalepi^{m})$ \nis given as:\n\n\\begin{align}\n    \\imgweight{i}{m}\n    :=& \n    \\frac{\n        \\mathcal{N}(\\shapescale_{i} | \\shapescalemu^{m},\\shapescalecov^{m})\\shapescalepi^{m}\n    }\n    {\n        \\sum_{m'=1}^{M}\n        \\mathcal{N}(\\shapescale_{i} | \\shapescalemu^{m'},\\shapescalecov^{m'})\\shapescalepi^{m'}\n    }\n\\end{align}\n\nTo improve numerical stability, this is formulated using the log-sum-exp trick:\n\n\\begin{align}\n    \\log{\\imgweight{i}{m}}\n    :=& \n    \\frac{\n        \\log{\n            \\left[\n            \\shapescalepi^{m} (2\\Pi)^{\\frac{d}{2}}\n            \\left[\\det{\\shapescalecov^{m}}\\right]^{-\\frac{1}{2}}\n            \\exp{\n                -\\frac{1}{2}\n                (\\shapescale_{i} - \\shapescalemu^{m})^{T}\n                (\\shapescalecov^{m})^{-1}\n                (\\shapescale_{i} - \\shapescalemu^{m})\n            }\n        \\right]\n        }\n    }\n    {\n        \\log{\n            \\left[\n            \\sum_{m'=1}^{M}\n            \\shapescalepi^{m'} (2\\Pi)^{\\frac{d}{2}}\n            \\left[\\det{\\shapescalecov^{m'}}\\right]^{-\\frac{1}{2}}\n            \\exp{\n                -\\frac{1}{2}\n                (\\shapescale_{i} - \\shapescalemu^{m'})^{T}\n                (\\shapescalecov^{m'})^{-1}\n                (\\shapescale_{i} - \\shapescalemu^{m'})\n            }\n        \\right]\n        }\n    }\n\\end{align}\nAnd this simplifies to\n\\begin{multline}\n    \\log{\\imgweight{i}{m}}\n    :=\n    \\log{\\shapescalepi^{m}} - \\frac{1}{2}\n        \\left[\n            d\\log{2\\pi} + \\log{\\det{\\left(\\shapescalecov^{m}\\right)}} + M_{i,m}\n        \\right] \\\\ -\n    \\log{\n        \\sum_{m'=1}^{M} \n        \\exp{\n            \\log{\\shapescalepi^{m'}} - \\frac{1}{2}\n            \\left[\n                d\\log{2\\pi} + \\log{\\det{\\left(\\shapescalecov^{m'}\\right)}} + M_{i,m'}\n            \\right]\n        }\n    }\n\\end{multline}\nwhere\n\\begin{align}\nM_{i,m} :=& \n    (\\shapescale_{i} - \\shapescalemu^{m})^{T}\n    (\\shapescalecov^{m})^{-1}\n    (\\shapescale_{i} - \\shapescalemu^{m})    \n\\end{align}\n\n\n\\subsubsection{The `M' Step.}\nThe `M' step computes new values for $(\\shapescalemu^{m},\\shapescalecov^{m},\\shapescalepi^{m})$, assuming fixed $\\imgweight{i}{m}$ for all $i \\in \\{1,\\dots,N\\}$ and $m \\in \\{1,\\dots,M\\}$. The update equations are given as follows:\n\n\\begin{equation}\n    \\shapescalemu^{m} := \n    \\frac{\n        \\sum_{i} \\imgweight{i}{m}\\shapescale_{i}\n    }\n    {\n        \\sum_{i} \\imgweight{i}{m}\n    }\n    \\quad\n    \\shapescalecov^{m} :=\n    \\frac{\n        \\sum_{i} \n        \\imgweight{i}{m}\n        (\\shapescale_{i} - \\shapescalecov^{m})\n        (\\shapescale_{i} - \\shapescalecov^{m})^{T}\n    }\n    {\n        \\sum_{i}\\imgweight{i}{m}\n    }\n    \\quad\n    \\shapescalepi^{m} :=\n    \\frac{1}{N}\\sum_{i} \\imgweight{i}{m}\n\\end{equation}\n", "meta": {"hexsha": "5b82a65b5927dfff07a6890fd186fcc24348f250", "size": 6851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter5/4_em-in-the-loop.tex", "max_stars_repo_name": "benjiebob/phd-thesis-template", "max_stars_repo_head_hexsha": "2fd86bb807b830c06944d9c59962939d9a95ca7a", "max_stars_repo_licenses": ["MIT"], "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/4_em-in-the-loop.tex", "max_issues_repo_name": "benjiebob/phd-thesis-template", "max_issues_repo_head_hexsha": "2fd86bb807b830c06944d9c59962939d9a95ca7a", "max_issues_repo_licenses": ["MIT"], "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/4_em-in-the-loop.tex", "max_forks_repo_name": "benjiebob/phd-thesis-template", "max_forks_repo_head_hexsha": "2fd86bb807b830c06944d9c59962939d9a95ca7a", "max_forks_repo_licenses": ["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.9166666667, "max_line_length": 493, "alphanum_fraction": 0.6239964969, "num_tokens": 2070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7090191214879992, "lm_q1q2_score": 0.6333734543254038}}
{"text": "% !TEX root = ../main.tex\n\\section{Hierarchical Variational Models}\nFor studying models with correlated random variables, such as frustrated spin systems~\\citep{zdeborova2016statistical}, unstructured variational families such as the mean field are insufficient. \\Acrfullpl{hvm} are one way to model correlated latent variables. An \\gls{hvm} is defined by placing a `variational prior' on the variational parameters $\\mbnu$ of the mean field variational family, in analogy to hierarchical probabilistic models. By leveraging neural networks to parameterize the variational prior, \\glspl{hvm} can capture complex dependencies between random variables~\\citep{ranganath2018black}.\n\n\\input{ch-hvm/fig/fig_markov_blanket_ising}\n\nFor studying a model $p(\\mbx, \\mbz)$, the variational family defined by an \\gls{hvm} is defined as\n\\begin{equation}\n  q_\\hvm(\\mbz; \\mbtheta) = \\int q(\\mbnu; \\mbtheta) \\prod_i q(\\mbz_i \\mid \\mbnu_i) d\\mbnu \\, ,\n  \\label{eq:hvm}\n\\end{equation}\nwhere $q_\\mf(\\mbz \\mid \\mbnu) = \\prod_i q(\\mbz_i \\mid \\mbnu_i)$ is the mean field `variational likelihood' with parameters $\\mbnu$, and $q(\\mbnu; \\mbtheta)$ is the variational prior with parameters $\\mbtheta$. \\Cref{fig:graphical-model} shows the graphical model for \\glspl{hvm} as compared to the mean field family graphical model.\n\nTo use an \\gls{hvm} in \\gls{vi}, the variational lower bound must be optimized. But the variational lower bound in \\Cref{eq:llbo} requires calculating the entropy of the variational distribution, and such integration in high dimensions can be intractable. As detailed in \\citet{ranganath2018black}, the entropy can be lower-bounded by introducing an auxiliary `variational posterior' distribution $r(\\mbnu \\mid \\mbz; \\mbphi)$ with parameters $\\mbphi$. This leads to the hierarchical evidence lower bound,\n\\begin{equation}\n  \\widetilde{{\\cL}}(\\mbtheta, \\mbphi) = \\E_{q(\\mbz, \\mbnu; \\mbtheta)}[ \\log p(\\mbx, \\mbz) + \\log r(\\mbnu \\mid \\mbz; \\mbphi) - \\log q(\\mbz \\mid \\mbnu) - \\log q(\\mbnu; \\mbtheta)]\\, ,\n  \\label{eq:hier-elbo}\n\\end{equation}\nand a stochastic optimization algorithm for this objective is developed in \\citep{ranganath2018black}. \\gls{vi} with an \\gls{hvm} requires specifying the variational prior $q(\\mbnu; \\mbtheta)$ and the variational posterior ${r(\\mbnu \\mid \\mbz; \\mbphi)}$, then optimizing the hierarchical \\gls{elbo} in \\Cref{eq:hier-elbo}.\n\n\\paragraph{Specifying an \\gls{hvm} with Normalizing Flows.} We study several choices of variational prior and recursive variational posterior. One choice of variational prior $q(\\mbnu; \\mbtheta)$ is an inverse autoregressive flow~\\citep{kingma2016improved}. If the variational posterior $r(\\mbnu \\mid \\mbz; \\mbphi)$ is chosen to be a masked autoregressive flow~\\citep{papamakarios2017masked}, the analytical forms of these flows are equivalent. These choices lead to a complexity of $\\cO(L)$ for sampling latent variables in a system of size $L$. (This is because the noise used to sample from the variational prior can be drawn in parallel.) \\glspl{hvm} should therefore be faster than \\gls{van} approximations in large systems: the autoregressive requirement in \\glspl{van} leads to a complexity of $\\cO(L^2)$. A research question is whether the advantage in speed of \\glspl{hvm} leads to a drop in accuracy that is too large to answer a statistical physics question.\n\\input{ch-hvm/fig/ising}\n\n\\paragraph{Scalable \\glspl{hvm} using Ising Model Structure.} Although \\glspl{hvm} with autoregressive flows scale linearly, such variational approximations do not leverage the structure about the statistical physics under study. For example, it is difficult to index random variables so that nearest neighbors are grouped together when fed to an autoregressive model. However, consider the Markov blanket of a random variable in the Ising model---it contains all the information needed to render a variable conditionally independent of the rest of the model. The Markov blanket of a node in an Ising model consists of a node's nearest neighbors and is shown in \\Cref{fig:markov-blanket-ising}. This means that an autoregressive model is overparameterized. For example, the last variable to be fed to the model depends on all the previous in an autoregressive model, whereas an efficient model might only consider nodes in a Markov blanket. A convenient way to build this structure into an \\gls{hvm} would ensure efficient use of information from nearest neighbors in the Ising model. One way to formalize this problem structure is with convolutional neural networks~\\citep{lecun2015deep}. We parameterize the variational prior and recursive posterior with \\gls{realnvp} transformations using a convolutional neural network architecture \\citep{dinh2017density}. Specifically, we parameterize the convolutional kernels to mimic the Markov blanket shown in \\Cref{fig:markov-blanket-ising}: for every node, only its nearest neighbors are conditioned on.", "meta": {"hexsha": "82b8fc409176d1b8efa6c544bf1b602e69a2bbeb", "size": 4911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch-hvm/sec_method.tex", "max_stars_repo_name": "altosaar/thesis", "max_stars_repo_head_hexsha": "287484c87db0eca46f4cdae70ff8582bd66ce5a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-05-21T18:56:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-26T12:18:53.000Z", "max_issues_repo_path": "ch-hvm/sec_method.tex", "max_issues_repo_name": "altosaar/thesis", "max_issues_repo_head_hexsha": "287484c87db0eca46f4cdae70ff8582bd66ce5a3", "max_issues_repo_licenses": ["MIT"], "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-hvm/sec_method.tex", "max_forks_repo_name": "altosaar/thesis", "max_forks_repo_head_hexsha": "287484c87db0eca46f4cdae70ff8582bd66ce5a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 204.625, "max_line_length": 1550, "alphanum_fraction": 0.7839543881, "num_tokens": 1318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6332796088312705}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\hyphenation{JTPREV}\n\\begmath 4.5 Sequential Solution of a Banded Least-Squares Problem\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nLet a linear least-squares problem be denoted by\n\\begin{equation*}\nA{\\bf x}\\simeq {\\bf b}\n\\end{equation*}\nwhere $A$ is a given $m\\times n$ matrix with $m\\geq n$, ${\\bf b}$ is a given\n$m$-vector, and it is required to find an $n$-vector, ${\\bf x}$, that is an\napproximate solution to this equation in the least-squares sense. The given\ndata for this problem can be regarded as the composite matrix, $[A:{\\bf b}].$\n\nAssume further that the matrix $A$ is {\\em banded}, in the sense that there\nis an integer, NB $\\leq n$, such that in any row of $A$ all nonzero elements\noccur within a set of NB contiguous positions. This set of subroutines is\nintended for the case in which NB is significantly smaller than $n$ so there\nis the possibility of achieving some significant saving of storage and\nexecution time by taking advantage of this band property.\n\nSubroutine SBACC can be used to preprocess the data matrix, $[A:{\\bf b}]$,\nsequentially. Subroutine SBSOL can be used to solve the problem after the\ntransformation accomplished by SBACC. Subroutine SBSOL can also be used to\ncompute a covariance matrix for the solution vector.\n\n\\subsection{Usage}\n\n\\subsubsection{Sequential processing of data}\n\nThe user must make a sequence of calls to SBACC, sending a block of rows of $%\n[A:{\\bf b}]$ with each call. On the first call the user sets NB, the\nbandwidth, which will remain unchanged after that. Also, on the first call\nthe user must set IR = 1, and JT = 1. After that IR will be updated by SBACC.\n\nAlong with each block the user sets two integers, MT and JT, indicating that\nMT new rows are being provided, within these rows of $A$ only the NB columns\nbeginning with column JT are being provided, and that the elements in all\nother columns in these rows of $A$ are zero. The user puts this block of\ndata in the array G(,), beginning with row IR of G(,). The data\ncorresponding to column JT of $A$ goes into the first column of G(,). Data\nfrom the vector ${\\bf b}$ of the problem goes into column NB + 1 of G(,).\n\nThe data blocks must be ordered so that from one call to the next, the value\nof the column index JT either remains the same or increases.\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf LDG, NB, IR, MT, JT, JTPREV, IERR2}\n\n\\item[REAL]  \\ {\\bf G}(LDG, $\\geq $NB+1)\n\\end{description}\n\nWhen starting a new problem set LDG, NB, and IR. On the initial call and all\nsubsequent calls for the same problem, set MT and JT and store MT rows of\ndata into G(,) beginning at row IR.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SBACC(G, LDG, NB, IR, MT,\\\\\nJT, JTPREV, IERR2)\\\\\n\\end{tabular}}\n\\end{center}\n\nFollowing the call the contents of G(,) will have been altered, reflecting\nthe processing of the new data. The values of JTPREV and IR may have been\nchanged. IERR2 will be set.\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[G(,)] \\ [inout] The working array.  With MT, JT, and IR defined below,\n  on each call to SBACC the user places columns JT to JT + NB $-$ 1 of MT rows\n  of $A$ into G(IR:IR+MT$-$1, 1:NB) and the corresponding elements of\n  $\\mathbf{b}$ into G(IR:IR+MT$-$1, NB+1).  It is implied that within these MT\n  rows of $A$ all elements not in columns JT through JT + NB $-$ 1 are zero.\n\n\\item[LDG]  \\ [in] The leading dimensioning parameter for G(,). LDG must be\nlarge enough so that on each call to SBACC one has $\\text{IR}+\\text{MT}-1\\leq $\nLDG.\n\nMT can be set by the user on each call. Let $MT_{\\max }$ denote the largest\nvalue the user will assign to MT. If the user keeps JT $\\leq n-\\text{NB} +\n1$ (see discussion in Section C) then the largest value of IR will be $n+2$,\nso it would suffice to set LDG $=n+1+MT_{\\max }.$\n\nIf the user permits JT to be as large as $n$, then LDG must be at least $n$\n+ NB + $MT_{\\max }.$\n\n\\item[NB]  \\ [in] Set by user on the initial call for a problem. Must not be\nchanged during the processing for one problem. NB indicates the bandwidth of\nthe data matrix $A$. In any row of $A$ all nonzero elements must appear\nin some set of NB consecutive columns.\n\n\\item[IR]  \\ [inout] Index of first row of G(,) into which the user is to\nplace new data. The variable IR must be set by the user to the value~1 on\nthe initial call to SBACC and must not be altered after that by the user on\nsuccessive calls for the same problem. IR will be updated in SBACC by\n(effectively) setting IR $=$ JT + $\\min ($NB + 1, MT + $\\max $(IR $-$ JT,~0)).\n\nLet $IR_{in}$ denote the value of IR on entry to SBACC and $IR_{out}$ denote\nits value on return. These quantities will satisfy%\n\\begin{equation*}\nIR_{in}\\leq IR_{out}\\leq \\text{JT + NB + 1}.\n\\end{equation*}\n\\item[MT]  \\ [in] Set by user to indicate the number of new rows of data\nbeing introduced by the current call to SBACC. SBACC will return immediately\nif MT $\\leq $ 0. MT will not be altered by SBACC.\n\n\\item[JT]  \\ [in] Set by user to indicate the column of the new sub-block of\n$A$ that the user is storing in the first column of the work array, G(,).\nThe user must set JT = 1 on the initial call to SBACC and must either leave\nJT the same or increase it on each successive call for the same problem. Too\nlarge an increase between successive calls can cause the problem to be\nstructurally singular. See Section E for more information on this. JT will not\nbe altered by SBACC.\n\n\\item[JTPREV]  \\ [inout] Need not be set before the first call to\nSBACC for a problem. Must not be altered by the user on later calls\nfor the same problem. JTPREV is used within SBACC to mark the row of\nG(,) at which the method of packing data changes. Quantities in G(,)\nat and below row JTPREV are subject to potential change during the\nprocessing of additional data, whereas quantities above row JTPREV\nare not.\n\nOn return, SBACC sets JTPREV = JT.  JTPREV, as set by SBACC, is needed\nas input when calling SBSOL.\n\n\\item[IERR2]  \\ [inout] Error status indicator. Need not be set before the\ninitial call for a problem. Will be set by SBACC to zero if no errors are\ndetected and to nonzero values, as described in Section E, if error\nconditions are detected.\n\\end{description}\n\n\\paragraph{Modifications for Double Precision}\n\nFor double precision usage change the REAL statement to DOUBLE PRECISION\nand change the subroutine name SBACC to DBACC.\n\n\\subsubsection{Computation of Solution Vector}\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf MODE, LDG, NB, IR, JTPREV, N, IERR3}\n\n\\item[REAL]  \\ {\\bf G}(LDG, $\\geq $NB+1){\\bf , X}($\\geq N)${\\bf , RNORM}\n\\end{description}\n\nSet MODE and N. If MODE is set to~2~or~3 then also store a vector, ${\\bf p}$%\n, into X(). G(,), NB, IR, and JTPREV should have values resulting from\nprevious calls to SBACC.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SBSOL(MODE, G, LDG, NB, IR, \\\\\nJTPREV, X, N, RNORM, IERR3)\\\\\n\\end{tabular}}\n\\end{center}\n\nOn return, X() and RNORM will contain computed results and IERR3 will be\nset. No other quantities in the argument list will be modified.\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[MODE]  \\ [in] The previous processing of data by SBACC will have left\na representation of an upper triangular matrix, $R$, and a vector, ${\\bf y}$%\n, in the array, G(,). See Section~D for the interpretation of these quantities.\nThe user selects the desired solution process by setting MODE to~1,~2, or~3.\n\n\\begin{itemize}\n\\item[=1]  Solve $R{\\bf x}={\\bf y}$, where $R$ and ${\\bf y}$ are\ncontained in G(,) as the result of previous calls to SBACC. The\nsolution vector, ${\\bf x}$, will be stored in X(). This gives the solution\nto the least-squares problem, $A{\\bf x}\\simeq {\\bf b}.$\n\n\\item[=2]  Solve $R^t{\\bf x}={\\bf p}$, where $R$ is the matrix residing in\nG(,) as the result of previous calls to SBACC, and ${\\bf p}$ is a vector\nplaced in X() by the user. The solution vector, ${\\bf x}$, will replace $%\n{\\bf p}$ in X().\n\n\\item[=3]  Solve $R{\\bf x}={\\bf p}$, where $R$ is the matrix residing in G(,)\nas the result of previous calls to SBACC, and ${\\bf p}$ is a vector placed\nin X() by the user. The solution vector, ${\\bf x}$, will replace ${\\bf p}$\nin X().\n\\end{itemize}\n\n\\item[G(,),LDG,NB,IR,JTPREV]  \\ [in] These arguments must contain values as\nthey were defined upon the return from a preceding call to SBACC.\n\n\\item[X()]  \\ [inout] On input, with MODE = 2 or 3, this array must contain\nthe N-dimensional right-side vector of the system to be solved. On return,\nwith MODE = 1, 2, or 3, this array will contain the N-dimensional solution\nvector of the appropriate system that has been solved.\n\n\\item[N]  \\ [in] Set by user to specify the dimensionality of the desired\nsolution vector. This causes the subroutine SBSOL to use only the leading N$%\n\\times $N submatrix of the triangular matrix currently represented in the\narray G(,). An error is reported if this submatrix is singular.\n\n\\item[RNORM]  \\ [out] If MODE = 1, RNORM is set by the subroutine to the\nnorm of the residual vector for the least-squares problem, $i.e.$, $\\Vert\n{\\bf b}-A{\\bf x}\\Vert $. This number is computed as%\n\\begin{equation*}\n\\left[\\, \\sum_{I=\\text{N}+1}^{\\text{IR}-1}\\text{G(}I\\text{, NB + 1})^2\\right]\n^{1/2}\n\\end{equation*}\nIf MODE = 2 or 3, RNORM is set to zero.\n\n\\item[IERR3]  \\ [out] Error status indicator set by SBSOL. Zero means no\nerrors detected. If a diagonal element of the leading N$\\times $N submatrix\nrepresented in G(,) is zero, an error message will be issued and IERR3 will\nbe set to the index of the first zero diagonal element. In this latter case\nthe solution vector X() will not be computed.\n\\end{description}\n\n\\paragraph{Changes for Double Precision}\n\nFor double precision usage change the REAL statement to DOUBLE PRECISION and\nchange the subroutine name SBSOL to DBSOL.\n\n\\subsection{Examples and Remarks}\n\n\\subsubsection{Computation of the covariance matrix for the solution vector}\n\nThe features provided by MODE = 2 and 3 are primarily intended to support\nthe computation of the unscaled covariance matrix, $C$, for the least-%\nsquares problem. This matrix, $C$, is defined by $C = (A^tA)^{-1}$. However,\nsince $R^tR = A^tA$ (See Section~D), $C$ is also given by $C = (R^tR)^{-1}$,\nand thus $C$ satisfies the equation, $R^tRC = I$, where $I$ is the $n\\times n\n$ identity matrix. It follows that the matrix, $C$, can be computed in two\nsteps, first solving\n\\begin{equation*}\nR^tZ = I\n\\end{equation*}\nfor $Z$, and then solving\n\\begin{equation*}\nRC = Z\n\\end{equation*}\nfor $C$. Using SBSOL or DBSOL the matrices $Z$ and $C$ can be computed one\ncolumn at a time.\n\nThis matrix, $C$, must be multiplied by an estimate of the variance of the\ndata error to obtain the solution covariance matrix. This variance can be\nestimated using N, MTOTAL, and RNORM as follows:\n\n\\hspace{.2in}DOF = MTOTAL $-$ N\n\n\\hspace{.2in}VAR = RNORM$**$2 / DOF\n\nwhere MTOTAL is the total number of rows of $A$ introduced into the problem.\n\n\\subsubsection{Demonstration problem}\n\nAs a demonstration problem we compute the continuous piecewise linear\nfunction that best fits a sample of 91~values of the sine function in the\nleast-squares sense. Sample values are values of the sine function at one\ndegree steps from zero to 90~degrees. The piecewise linear function will be\nparameterized by a set of ten values, $y_i$, $i = 1$, 10, which will be the\nvalues of the piecewise linear function at the arguments 0, 10, 20, ..., 90\ndegrees. The fitted function will be defined by linear interpolation between\nadjacent pairs of these points.\n\nNote that because the sine curve is concave down throughout this interval we\nexpect the knots, $y_i$, each to lie above the sine curve, with the linearly\ninterpolated segment between each adjacent pair of knots passing below the\nsine curve.\n\nProgram DRDBACC illustrates the use of DBACC and DBSOL to compute the ten\nvalues of $y_i$ for this problem. It also computes the (formal) $10\\times 10$\ncovariance matrix for these quantities. The results are shown in ODDBACC.\n\nNote from the listing of residuals that the residuals at $x = 0$, 10, 20,\n... degrees are positive, while the residuals at $x = 5$, 15, 25, ...\ndegrees are negative, as expected.\n\nThis problem is not really statistical since the given data are essentially\nexact. Thus the computed SIGFAC and covariance matrix do not really have a\nstatistical interpretation, but merely serve to illustrate how to use these\nsubroutines to compute these quantities. Note in particular that the\ncovariance matrix is symmetric (to some level of accuracy), as it should be,\neven though this method computes each column of the covariance matrix\nindependently.\n\nFor an example of more general usage of DBACC see a listing of the MATH77\nlibrary subroutine, DC2FIT, Chapter~11.4.\n\n\\subsubsection{Data blocks having fewer than NB contiguous columns of nonzeros}\n\nThis subroutine requires the value of NB to be constant throughout the\nprocessing of one problem. If the data block being sent to SBACC in one call\nhas all of its nonzeros in fewer than NB contiguous columns the user must\npad out the block to a width of NB columns by including zeros. The padding\ncolumns may be either on the left or the right or both.\n\nFor example, suppose NB = 4 and one is introducing a row, or block of rows,\nof $A$ having nonzeros only in columns 5, 6, and 7. One may either set JT =\n4 and send columns 4, 5, 6, and 7, with column~4 containing zeros; or else\none may set JT = 5 and send columns 5, 6, 7, and 8, with column~8 containing\nzeros.\n\nIn choosing between these alternatives there are two points to consider. JT\nmust be nondecreasing on successive calls to SBACC. Sending padding columns\nthat are beyond the last actual column of $A$ causes the algorithm to use\nmore rows of storage than would otherwise be necessary.\n\n\\subsection{Functional Description}\n\nSubroutine SBACC uses Householder orthogonal transformations to process the\ngiven data, producing an equivalent least-squares problem of the form%\n\\begin{equation*}\n\\left[\n\\begin{array}{c}\nR \\\\\n0\n\\end{array}\n\\right] \\simeq \\left[\n\\begin{array}{c}\n{\\bf y} \\\\ \\alpha\n\\end{array}\n\\right]\n\\end{equation*}\nwhere $R$ is an $n\\times n$ upper triangular matrix with a bandwidth of NB, $%\n{\\bf y}$ is an $n$-vector, and $\\alpha $ is a scalar quantity. These\nquantities are related to the data, $[A:{\\bf b}]$, by the relations, $%\nR^tR=A^tA$, $R^t{\\bf y}=A^t{\\bf b}$, and ${\\bf y}^t{\\bf y}+\\alpha ^2={\\bf b}%\n^t{\\bf b}.$\n\nThe solution, ${\\bf x}$, for this problem is also the solution for the given\nleast-squares problem, $A{\\bf x}\\simeq {\\bf b}$, and can be computed by\nsolving the triangular system, $R{\\bf x}={\\bf y}$. This latter system is\nsolved for ${\\bf x}$ when SBSOL is called with MODE = 1.\n\nThe residual vector for the transformed least-squares problem is\n\\begin{equation*}\n\\left[\n\\begin{array}{c}\n\\bf 0 \\\\\n\\alpha\n\\end{array}\n\\right].\n\\end{equation*}\nThe norm of this residual vector is $|\\alpha |$ and this is also equal to $%\n\\Vert {\\bf b}-A{\\bf x}\\Vert $. After $n$ linearly independent rows of $A$\nhave been accumulated, where $n$ is the number of columns of $A$, if a\nsolution is requested with N $=n$, then the value $|\\alpha |$ will be\nreturned as RNORM. If a solution is requested with N $<n$, components of $%\n{\\bf y}$ beyond $y_N$ will also be used in computing RNORM.\n\nSubroutine SBACC dynamically partitions the array G(,) into three segments\nby groups of rows. These segments are rows~1 through JTPREV $-$ 1, rows JTPREV\nthrough IR $-$ 1, and rows IR through LDG.\n\nThe first segment holds rows of $[R:{\\bf y}]$ for which processing is\ncompleted. In this segment element $r_{i,j}$ is stored in G($i,j-i+1).$\n\nThe second segment, consisting of at most NB + 1 rows, holds rows of%\n\\begin{equation*}\n\\left[\n\\begin{array}{ccc}\nR & : & {\\bf y} \\\\\n0 & : & \\alpha\n\\end{array}\n\\right]\n\\end{equation*}\nthat may be changed by data yet to be received. In this segment element $%\nr_{i,j}$ is stored in G($i,j-\\text{JTPREV}+1).$\n\nThe third segment is used to receive new rows of $[A:{\\bf b}].$\n\nThe subroutine SBSOL alters only the contents of X() and RNORM. Thus it is\npermissible to alternate between accumulating data using SBACC and obtaining\na current solution or covariance matrix using SBSOL. It is also permissible\nto use SBSOL with N $< n$. The subroutine SBSOL can compute a solution\nvector of length N whenever the portion of the $A$ matrix introduced to that\npoint has the property that its first N columns are linearly independent.\n\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIn response to detected error conditions, SBACC will set IERR2 nonzero and\nissue an error message using the error message routines of Chapter~19.2. On\nerrors numbered 1 through~4, SBACC will return. Generally the calling program\nshould abandon the problem processing in these cases. When IERR2 = 3 it is\nconceivable, but not likely, that the user might wish to continue the\nprocessing, in which case the user must reset IERR2 to zero. If SBACC is\nreentered with IERR2 $\\neq 0$, (and IR $> 1)$ it will set IERR2 = 5 and\nexecute a STOP.\n\n{\\bf IERR2 \\hspace{.2 in} Explanation}\\vspace{-10pt}\n\\begin{itemize}\n\\item[1]  MT $>$ LDG $-$ IR + 1. To correct this problem either use a\nlarger dimension LDG, or a smaller block size MT.\n\n\\item[2]  JT $<$ JTPREV. This occurs if the data blocks are out of order, in\nthe sense that the current JT is smaller than JT on the previous call.\n\n\\item[3]  JT $>\\min ($JTPREV + NB, IR). This occurs when the difference\nbetween the current JT and JT on the previous call is so large that the\nmatrix would be structurally singular. This condition does not, however,\npreclude the processing of the data to triangular form, and thus SBACC will\ndo the processing, unless there is a storage limitation, in which case IERR2\nwill be set to~4.\n\nThis condition is likely to be due to a program usage error.  If not, then\nthe problem needs either more data in preceding blocks or a mathematical\nmodel with fewer or differently defined free parameters.  Alternatively,\nsee pp.~218--219 of \\cite{Lawson:1974:SLS} for ideas on stabilizing such a\nstructurally singular problem.\n\n\\item[4]  The condition described above for IERR2 = 3 holds and there is a\nstorage limitation indicated by MT $>\\text{LDG}-\\text{JT}+1$. The storage\nproblem could be relieved by increasing LDG or decreasing MT. However, the\nmore fundamental problem indicated by IERR2 = 3 must still be dealt with.\n\n\\item[5]  SBACC has been entered with IERR2 $\\neq 0$. SBACC will execute a\nSTOP since the calling program has ignored a nonzero setting of IERR2 on the\nprevious call.\n\\end{itemize}\n\nThe following conditions are not tested in SBACC and violation will have\nunpredictable effects: IR, and JT must be set to~1 on the first call to\nSBACC. JTPREV and IR must not subsequently be altered by the user during the\nprocessing for one problem.\n\nSBACC will return immediately if MT $\\leq $ 0. This is not regarded as an\nerror condition.\n\nIf SBSOL encounters a zero diagonal term in the N$\\times $N matrix R, IERR3\nwill be set to the index of the (first) zero term and an error message will\nbe issued. The solution X() will not be computed in this case.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nThese subroutines are adaptations to the JPL MATH77 library of the\nalgorithms and subroutines BNDACC and BNDSOL that were developed by C.  L.\nLawson and R.  J.  Hanson at JPL in~1972 and described in detail in\n\\cite{Lawson:1974:SLS}.\n\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDBACC & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDBACC, DHTCC, DNRM2, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDBSOL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDBSOL, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSBACC & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SBACC, SHTCC, SNRM2\\rule[-5pt]{0pt}{8pt}}\\\\\nSBSOL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SBSOL}\\\\\n\\end{tabular}\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDBACC}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dbacc}}\n\\newpage\n\\vspace{30pt}\\centerline{\\bf \\large ODDBACC}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dbacc}}\n\n\\end{document}\n", "meta": {"hexsha": "a333f2127900e9f49067da4589f79ef3c2589cd2", "size": 20703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch04-05.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/ch04-05.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/ch04-05.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": 43.13125, "max_line_length": 98, "alphanum_fraction": 0.7374293581, "num_tokens": 5998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6332796003226034}}
{"text": "\\documentclass{article}\n\n\\usepackage[a4paper, total={6in, 10in}]{geometry}\n\\usepackage{graphicx}\n\\usepackage{enumitem}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\newcommand{\\mc}{\\mathcal}\n\\newcommand{\\mb}{\\mathbb}\n\\DeclareMathOperator{\\sialge}{\\sigma-algebra}\n\\DeclareMathOperator{\\sifin}{\\sigma-finite}\n\\DeclareMathOperator{\\pisys}{\\pi-system}\n\\DeclareMathOperator{\\picls}{\\pi-class}\n\\DeclareMathOperator{\\lamsys}{\\lambda-system}\n\\DeclareMathOperator{\\lamcls}{\\lambda-class}\n\n\\title{Notes on Measure Theory \\& Probability}\n\\author{a1trl9}\n\\date{}\n\\setlength{\\parindent}{0cm}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Measure}\n\\subsection{Classes of sets}\n\\textbf{Definition 1.1.1:} let \\(\\Omega\\) be a nonempty set and \\(\\mc{P}(\\Omega)\\) be the power set of \\(\\Omega\\).\nA collection of sets \\(\\mc{F}\\subset \\mc{P}(\\Omega)\\) is called an \\textit{algebra} if\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item \\(\\Omega \\in \\mc{F}\\).\n\\item \\(A \\in \\mc{F}\\) implies \\(A^c \\in \\mc{F}\\).\n\\item \\(A, B \\in \\mc{F}\\) implies \\(A \\cup B \\in \\mc{F}\\).\n\\end{enumerate}\n\nIt is easy to see with (b) (\\textit{symmetric}), (c) is equivalent to\n\n\\[(c)' \\quad A, B \\in \\mc{F} \\implies A \\cap B \\in \\mc{F} \\]\n\n\\textbf{Proof:} to prove (c) \\(\\implies\\) (c)', let \\(A, B \\in \\mc{F}\\), by (b), \\(A^c, B^c \\in \\mc{F}\\). By (c), \\(\nA^c \\cup B^c \\in \\mc{F}\\). By (b) again, \\(\\Omega \\setminus (A^c \\cup B^c) = (A^c \\cup B^c)\n\\in \\mc{F}\\). \\(\\Omega \\setminus (A^c \\cup B^c) = (\\Omega \\setminus A^c) \\cap (\\Omega\n\\setminus B^c) = A \\cap B\\). Proved. The converse proof follows similar steps.\n\n\\vspace{2mm}\n\\textbf{Definition 1.1.2: } a class \\(\\mc{F} \\subset \\mc{P}(\\Omega)\\) is called an \\textit{\\(\\sialge\\)} if \nit is an \\textit{algebra} and\n\n\\[A_n \\in \\mc{F} \\quad for \\quad n \\geq 1 \\implies \\bigcup_{n\\geq 1}A_n \\in \\mc{F}\\]\n\n\\textbf{Proposition 1.1.1: } a class \\(\\mc{F} \\subset \\mc{P}(\\Omega)\\) is a \\(\\sialge\\) \\textit{iff} \n\\(\\mc{F}\\) is \nan \\textit{algebra} and satisfies\n\n\\[A_n \\in \\mc{F}, A_n \\subset A_{n+1} \\quad for \\: all \\quad n \\implies \\bigcup_{n \\geq 1}A_n \\in \\mc{F} \\]\n\n\\textbf{Proof:} to prove \\textit{if}, let \\(\\{B_n\\}_{n\\geq 1} \\in \\mc{F}\\), then for all \\(n\\geq 1\\),\n\\(\\bigcup_{i=1}^nB_i \\in \\mc{F}\\) (by (c)) and obviously \\(\\bigcup_{i}^{n-1}B_n \\subset \\bigcup_{i}^{n}B_n\\).\nLet \\(A_n=\\bigcup_{i=1}^nB_i\\), easy to see \\(\\bigcup_{n\\geq 1}A_n=\\bigcup_{n\\geq 1}B_n\\). With the condition given, \n\\(\\bigcup_{n\\geq 1}B_n \\in \\mc{F}\\). Proved. The \\textit{only if} part is obvious.\n\n\\vspace{2mm}\nExamples of \\textit{algebra} or \\(\\sialge\\) (or neither):\n\n\\begin{enumerate}\n\\item \\(\\mc{F}_1=\\mc{P}(\\Omega)\\equiv\\{A: A \\subset \\Omega\\}\\) (\\(\\sialge\\)).\n\\item \\(\\mc{F}_2= \\{\\emptyset, \\Omega \\} \\) (\\(\\sialge\\), also called \\textit{trival \\(\\sialge\\)}).\n\\item \\(\\mc{F}_3= \\{A \\subset \\Omega\\: :\\: either\\: |A|\\: is\\: finite\\: or\\: |A^c|\\: is\\: finite \\} \\) (\\textit{algebra} but \n\\item \\(\\mc{F}_4= \\{A \\subset \\Omega\\: :\\: either\\: |A|\\: is\\: countable\\: or\\: |A^c|\\: is\\: countable \\} \\) ( \n\\(\\sialge\\)).\n\\end{enumerate}\n\nFor (3), if \\(\\Omega\\) is infinite, let \\({A_1, A_2, \\cdots, A_n} \\subset \\Omega\\) so that for all \\(A_i, i\\geq 1, A_i \\in \\mc{F}_3\\)\n. However both \\(A\\equiv \\bigcup_{i\\geq 1} A_{2i-1}\\) and \\(A^c\\) are infinite, so \\(A \\not\\in \\mc{F}_3\\).\n\n\\vspace{2mm}\nFor (4), suppose \\(A_1, A_2, \\cdots, A_n \\subset \\Omega\\). If at least one of \\(A_i, i\\geq 1\\) is countable, then \\(\\bigcap_{i\\geq 1}A_n\\)\nis countable and \\(\\bigcap_{i\\geq 1}A_n \\in \\mc{F}_4\\). If all \\(A_i \\geq 1\\) are uncountable, then all \\(A_i^c \\geq 1\\) are\ncountable. \\((\\bigcup_{i\\geq 1}A_n)^c=(\\bigcap_{i\\geq 1}A_i^c) \\in \\mc{F}_4\\). As (b) in definition 1.1.1 is easy to prove, \\(\\bigcup_{i\\geq 1}A_n \\in \\mc{F}_4\\),\nwhich is equivalent to \\(\\bigcap_{i\\geq 1}A_n\\in \\mc{F}_4\\). \n\n\\vspace{2mm}\n\\textbf{Definition 1.1.3: } if \\(\\mc{A}\\) is a class of subsets of \\(\\Omega\\), then the \\(\\sialge\\) generated by \\(\\mc{A}\\)\n, denoted by \\(\\sigma(\\mc{A})\\) is defined as:\n\n\\[\n\\sigma(\\mc{A}) = \\bigcap_{\\mc{F}\\in \\mc{I}(\\mc{A})}\\mc{F}   \n\\]\n\nwhere \\(\\mc{A}\\equiv \\{\\mc{F}: \\mc{A} \\subset \\mc{F}\\) and \\(\\mc{F}\\) is a \\(\\sialge\\) on  \\(\\Omega\\}\\).\n\n\\vspace{2mm}\n\\textbf{Definition 1.1.4: } The \\textit{Borel \\(\\sialge\\)} on a topological space \\(\\mb{S}\\) is defined as the \\(\\sialge\\) generated\nby the collection of open sets in \\(\\mb{S}\\).\n\n\\vspace{2mm}\n\\textbf{Definition 1.1.5: } A class \\(\\mc{C}\\) of subsets of \\(\\Omega\\) is a \\(\\pisys\\) or a \\(\\picls\\) if\n\\(A, B \\in \\mc{C} \\implies A \\cap B \\in \\mc{C}\\).\n\n\\vspace{2mm}\n\\textbf{Definition 1.1.6: } A class \\(\\mc{L}\\) of subsets of \\(\\Omega\\) is a \\(\\lamsys\\) or a \\(\\lamcls\\) if:\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item \\(\\Omega \\in \\mc{L}\\).\n\\item \\(A, B \\in \\mc{L}, A \\subset B, \\implies B\\setminus A \\in \\mc{L} \\).\n\\item \\(A_n \\in \\mc{L}, A_{n} \\subset A_{n+1}\\) for all \\(n \\geq 1 \\implies \\bigcup_{n\\geq 1}A_n \\in \\mc{L}\\).\n\\end{enumerate}\n\nIt is easy to that every \\(\\sialge\\) is a \\(\\lamsys\\). The converse is not necessarily true.\n\n\\vspace{2mm}\n\\textbf{Theorem 1.1.2: }if \\(\\mc{C}\\) is a \\(\\pisys\\), then \\(\\lambda(\\mc{C})=\\sigma(\\mc{C})\\).\n\n\\vspace{2mm}\n\\textbf{Proof: } As mentioned, every \\(\\sialge\\) of \\(\\mc{C}\\) is a \\(\\lamsys\\). Therefore, \\(\\lambda(\\mc{C}) \\subset \n\\sigma(\\mc{C})\\). Suppose the class of subsets of \\(\\mc{C}\\): \\(\\lambda_1 \\equiv \\{A: A\\in \\lambda(\\mc{C})\\; |\\; A \\cap B \\in \\lambda(\\mc{C})\n\\) for all \\(B\\in \\lambda(\\mc{C})\\}\\). It is obvious that \\(\\Omega \\in \\lambda_1(\\mc{C})\\). If \\(A_1, A_2\\in \\lambda_1(\\mc{C})\\),\n\\(A_1\\subset A_2\\), then for all \\(B\\in \\lambda(\\mc{C})\\), \\((A_2\\setminus A_1)\\cap B = (A_2\\setminus B)\\cap (A_1\\setminus B)\\).\nAs both \\(A_2\\setminus B, A_1\\setminus B \\in \\lambda(\\mc{C})\\), \\((A_2\\setminus B)\\cap (A_1\\setminus B)\\in \\lambda(\\mc{C})\\),\nindicating \\(A_2\\setminus A_1\\in \\lambda_1(\\mc{C})\\). If \\(A_1, A_2, \\cdots, A_n \\in \\lambda_1(\\mc{C})\\),\n\\(A_n\\subset A_{n+1}\\) for \\(n\\geq 1\\), then for all \\(B\\in \\lambda(\\mc{C})\\), \\((\\bigcup_{n\\geq 1}A_n)\\cap B=\\bigcup_{n\\geq 1}(A_n\\cap B)\\),\nas \\(A_n\\cap B \\in \\lambda(\\mc{C})\\), \\((A_n\\cap B)\\subset (A_{n+1}\\cap B)\\), \\(\\bigcup_{n\\geq 1}(A_n\\cap B)\\in \\lambda(\\mc{C})\\), indicating\n\\(\\bigcup_{n\\geq 1}A_n \\in \\lambda_1(\\mc{C})\\). Therefore, \\(\\lambda_1(\\mc{C})\\) is a \\(\\lamsys\\).\n\nMeanwhile, suppose \\(\\lambda_2 \\equiv \\{A: A\\in \\lambda(\\mc{C})\\: |\\: A \\cap B \\in \\lambda(\\mc{C})\\) for all \\(B\\in \\mc{C}\\}\\).\nObviously \\(\\lambda_1(\\mc{C})\\subset \\lambda_2(\\mc{C})\\).\nAs \\(\\mc{C}\\subset \\lambda(\\mc{C})\\), it is easy to prove \\(\\lambda_2\\) is also a \\(\\lamsys\\). Besides,\nas \\(\\mc{C}\\) is a \\(\\pisys\\), if \\(A_1, A_2 \\in \\mc{C}\\), \\(A_1\\cap A_2 \\in \\mc{C}\\subset \\lambda(\\mc{C})\\), indicating\n\\(\\mc{C}\\subset \\lambda_2(\\mc{C})\\). While \\(\\lambda_2(\\mc{C})\\subset \\lambda(\\mc{C})\\), \\(\\lambda_2(\\mc{C})=\\lambda(\\mc{C})\\).\nTherefore, \\(A\\cap B\\in \\lambda(\\mc{C})\\) for each pair \\(A\\in \\mc{C}, B\\in \\lambda(\\mc{C})\\), i.e. \\(\\mc{C}\\subset \\lambda_1(\\mc{C})\\).\nWhile \\(\\lambda_1(\\mc{C})\\subset \\lambda(\\mc{C})\\), \\(\\lambda_1(\\mc{C})=\\lambda(\\mc{C})\\). So \\(\\lambda(C)\\) is close under intersection.\nAs being a \\(\\lamsys\\) guanratees the other two conditions, \\(\\lambda(\\mc{C})\\) is also a \\(\\sialge\\). With \\(\\lambda(\\mc{C}\\subset\n\\sigma(\\mc{C}))\\), proved.\n\n\\subsection{Measures}\n\n\\textbf{Definition 1.2.1: } Let \\(\\Omega\\) be a nonempty set and \\(\\mc{F}\\) be an algebra on \\(\\Omega\\). Then a function\n\\(\\mu\\) on \\(\\mc{F}\\) is called a measure if:\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item \\(\\mu(A)\\in [0, \\infty]\\) for all \\(A \\in \\mc{F}\\).\n\\item \\(\\mu(\\emptyset)=0\\).\n\\item for any disjoint collection of sets \\(A_1, A_2, \\cdots, A_n \\in \\mc{F}\\) with \\(\\bigcup_{n\\geq 1}A_n\\in \\mc{F}\\),\n\\(\\mu(\\bigcup_{n\\geq 1}A_n)=\\sum_{n=1}^{\\infty}\\mu(A_n)\\).\n\\end{enumerate}\n\n\\vspace{2mm}\n\\textbf{Proposition 1.2.1: } Let \\(\\Omega\\) be a nonempty set and \\(\\mc{F}\\) be an algebra of subsets of \\(\\Omega\\)\nand \\(\\mu\\) be a set function on \\(\\mc{F}\\) with values in \\([0, \\infty]\\) and with \\(\\mu(\\emptyset)=0\\).\nThen \\(\\mu\\) is a measure \\textit{iff} \\(\\mu\\) satisfies:\n\n\\begin{enumerate}[label=(\\roman*)\\('\\)]\n\\item (finite additivity) for all \\(A_1, A_2 \\in \\mc{F}\\) with \\(A_1\\cap A_2 = \\emptyset\\), \n\\(\\mu(A_1\\cup A_2)=\\mu(A_1)+\\mu(A_2)\\).\n\\item (monotone continuity from below or, m.c.f.b, in short) for any collection \\(\\{A_n\\}_{n\\geq 1}\\)\nof sets in \\(\\mc{F}\\) such that \\(A_n\\subset A_{n+1}\\) for all \\(n\\geq 1\\) and \\(\\bigcup_{n\\geq 1}A_n\\in \\mc{F}\\),\n\\(\\mu(\\bigcup_{n\\geq 1}A_n)=\\lim_{n\\to \\infty}\\mu(A_n)\\).\n\\end{enumerate}\n\n\\vspace{2mm}\n\\textbf{Proof: } let \\(\\mu\\) be a measure on \\(\\mc{F}\\). Since \\(\\mu\\) satisfies (iii), taking\n\\(A_3, A_4, \\cdots, A_n = \\emptyset\\), \\(\\mu(A_1\\cup A_2)=\\mu(A_1)+\\mu(A_2)\\). Hence, if\n\\(A\\subset B\\) and \\(A, B \\in \\mc{F}\\), \\(\\mu(B)=\\mu(A) + \\mu(B\\setminus A)\\geq \\mu(A)\\), namely monotone. \nSo, for \\(A_1, A_2, \\cdots, A_n \\in \\mc{F}\\), if one \\(\\mu(A_n)=\\infty\\), \\(\\mu(\\bigcup_{n\\geq 1}A_n)=\\lim_{n\\to \\infty}\\mu(A_n)\n=\\infty\\). Suppose all \\(\\mu(A_n) \\neq \\infty\\), let \\(B_n=(A_n\\setminus A_{n-1})\\) (take \\(A_0=\\emptyset\\)), then\n\\(B_1, B_2, \\cdots, B_n\\) are disjoint and \\(\\bigcup_{n\\geq 1}A_n=\\bigcup_{n\\geq 1}B_n\\),\nSo \\(\\mu(\\bigcup_{n\\geq 1}A_n)=\\mu(\\bigcup_{n\\geq 1}B_n)\\), with (iii), \\(\\mu(\\bigcup_{n\\geq 1}B_n)\n=\\sum_{n=1}^{\\infty}\\mu(B_n)=\\sum_{n=1}^{\\infty}\\mu(A_n-A_{n-1})=\\lim_{n\\to \\infty}\\mu(A_n)\\). (ii)\\('\\) proved.\n\n\\vspace{1mm}\nCoversely, let \\(\\{B_n\\}\\) a disjoint collection in \\(\\mc{F}\\), take \\(A_n=\\bigcup_{n\\geq 1} B_{n}\\), then\n\\(A_n \\subset A_{n+1}\\) and\n\\(\\bigcup_{n\\geq 1}A_n=\\bigcup_{n\\geq 1}B_n\\). With (ii)\\('\\), \\(\\mu(\\bigcup_{n\\geq 1}B_n)=\\mu(\\bigcup_{n\\geq 1}A_n)\n=\\lim_{n\\to\\infty}\\mu(A_n)\\), with (i), \\(\\mu(A_n)=\\sum_{i=1}^n\\mu(B_i)\\), then \\(\\mu(\\bigcup_{n\\geq 1}B_n)\n=\\lim_{n\\to\\infty}\\sum_{i=1}^n\\mu(B_n)=\\sum_{n=1}^{\\infty}\\mu(B_n)\\). Proved.\n\n\\vspace{2mm}\n\\textbf{Definition 1.2.2: } a measure \\(\\mu\\) is called \\textit{finite} or \\textit{infinite} according as \n\\(\\mu(\\Omega)<\\infty\\) or \\(\\mu(\\Omega)=\\infty\\). A finite measure is called \\textit{probability measure} if\n\\(\\mu(\\Omega)=1\\). A measure \\(\\mu\\) is called a \\(\\sifin\\) if there exists a countable collection of sets\n\\(A_1, A_2, \\cdots \\in \\mc{F}\\), not necessarily disjoint, such that:\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item \\(\\bigcup_{n\\geq 1}A_n=\\Omega\\).\n\\item \\(\\mu(A_n)<\\infty\\) for all \\(n\\geq 1\\).\n\\end{enumerate}\n\n\\vspace{2mm}\n\\textbf{Proposition 1.2.2: } let \\(\\mu\\) be a measure on an algebra \\(\\mc{F}\\), and let \\(A, B, A_1, A_2, \\cdots, A_k\\in \\mc{F}\\),\n\\(1\\leq k < \\infty\\). Then:\n\n\\begin{enumerate}[label=(\\roman*)]\n\\item (monotonicity) \\(\\mu(A)\\leq\\mu(B)\\) if \\(A\\subset B\\).\n\\item (finite subadditivity) \\(\\mu(A_1\\cup A_2\\cup \\cdots\\cup A_k )\n\\leq \\sum_{i=1}^k\\mu(A_i)\\).\n\\item (inclusion-exclusion formula) if \\(\\mu(A_i)<\\infty\\) for all \\(i=1,\\cdots, k\\), then\n\\(\\mu(A_1\\cup A_2\\cup \\cdots\\cup A_k)=\\sum_{i=1}^k\\mu(A_k)-\\sum_{1\\leq i < j \\leq k}\n\\mu(A_i\\cap A_j)+\\cdots+(-1)^{k-1}\\mu(A_1\\cap A_2\\cap\\cdots\\cap A_k)\\).\n\\end{enumerate}\n\n\\vspace{2mm}\n\\textbf{Proof: } if \\(A\\subset B\\), \\(A\\cup (B\\setminus) A = B\\). With (iii) of \\textbf{definition 1.2.1},\n\\(\\mu(B)=\\mu(A) + \\mu(B\\setminus A)\\). As \\(\\mu(B\\setminus A)\\geq 0\\),\n\\(\\mu(B)\\geq \\mu(A)\\). Meanwhile, suppose one of \\(\\mu(A_i), \\mu(A_j) < \\infty\\),\nthen with (i), \\(\\mu(A_i\\cap A_j)<\\infty\\) and \\(\\mu(A_i\\cap A_j)-\\mu(A_i\\cap A_j)\\)\nis well defined. \n\\(\\mu(A_i\\cup A_j)=\\mu(A_i\\cup (A_j\\setminus A_i))=\\mu(A_i)+\\mu(A_j\\setminus A_i)\n=\\mu(A_i)+(\\mu(A_j\\setminus A_i) + \\mu(A_i\\cap A_j)) - \\mu(A_\\cap A_j)=\\mu(A_i)+\\mu(A_j)-\\mu(A_i\\cap A_j)\\).\ni.e. \\(\\mu(A_i\\cup A_j)\\geq \\mu(A_i)+\\mu(A_j)\\).\nFor (iii), it obviously holds when \\(k=2\\). Assuming (iii) holds for \\(n\\), then for \\(n+1\\):\n\n\\begin{equation*}\n\\begin{split}\n&\\mu(\\bigcup_{i=1}^{n+1}A_i)=\\mu(\\bigcup_{i=1}^nA_i)+\\mu(A_{n+1})\n-\\mu[(\\bigcup_{i=1}^nA_i)\\cap A_{n+1}]\\\\\n&=\\sum_{i=1}^n\\mu(A_i)-\\sum_{1\\leq i <j\\leq n}(A_i\\cap A_j) + \\cdots + \n(-1)^{n-1}\\mu(A_1\\cap A_2\\cap\\cdots\\cap A_n)\\\\\n&+\\mu(A_{n+1})-\\mu[\\bigcup_{i=1}^n(A_i\\cap A_{n+1})]\\\\\n&=\\sum_{i=1}^{n+1}\\mu(A_i)-\\sum_{1\\leq i <j\\leq n}(A_i\\cap A_j) + \\cdots + \n(-1)^{n-1}\\mu(A_1\\cap A_2\\cap\\cdots\\cap A_n)\\\\\n&-\\sum_{i=1}^n\\mu(A_i\\cap A_{n+1})+\\sum_{1\\leq i < j \\leq n}\\mu(A_i\\cap A_j\\cap A_{n+1})\n-\\cdots\\\\&-(-1)^{n-1}\\mu(A_1\\cap A_2\\cap\\cdots\\cap A_{n+1})\\\\\n&=\\sum_{i=1}^{n+1}\\mu(A_i)-\\sum_{i\\leq i < j\\leq n+1}(A_i\\cap A_j)+\\cdots+\n(-1)^k\\mu(A_1\\cap A_2\\cap\\cdots\\cap A_{n+1})\n\\end{split}\n\\end{equation*}\n\nProved.\n\n\\end{document}\n", "meta": {"hexsha": "9c5726e5d9c54d12f31c1a0cd4da1bb134e42939", "size": 12433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prob_measure.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": "prob_measure.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": "prob_measure.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": 53.1324786325, "max_line_length": 162, "alphanum_fraction": 0.6023485884, "num_tokens": 5576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6332795960682698}}
{"text": "\\chapter[Heuristics]{Heuristics}\\label{chp:heuristics}\n\n\n% Introduction\n\\chapterinitial{I}{t} is often necessary to find the most desirable choice from\na large, or indeed, infinite set of options. Sometimes this can be done using\nexact techniques but often this is not possible and finding an almost perfect\nchoice quickly is just as good. This is where the field of\nheuristics\\index{heuristics} comes in to play.\n\n\\section{Problem}\\label{sec:heuristics_problem}\n\nA delivery company needs to deliver goods to 13 different stops.\nThey need to find a route for a driver that stops at each of the stops\nonce only, then returns to the first stop, the depot.\n\nThe stops are drawn in Figure~\\ref{fig:tsp}.\n\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=.8\\textwidth]{./assets/tsp/main.pdf}\n    \\end{center}\n    \\caption{The positions of the required stops.}\n    \\label{fig:tsp}\n\\end{figure}\n\nThe relevant information is the pairwise distances between each of the stops,\nwhich is given by the distance matrix\\index{matrix} in equation (\\ref{eqn:tsp}).\n\n\\tiny{\n    \\input{./assets/tsp/main.tex}\n}\n\\normalsize\n\nThe value \\(d_{ij}\\) gives the travel distance between\nstops \\(i\\) and \\(j\\). For example, \\(d_{23}=67\\)\nindicates that the distance between the 2nd and 3rd stop in the route is 67.\n\n\nThe delivery company would like to find the route around the 13 stops that gives\nthe smallest overall travel distance.\n\n\n\\section{Theory}\\label{sec:heuristics_theory}\n\nThis problem is called a travelling salesman\nproblem\\index{travelling salesman problem}, which can often be inefficient to\nsolve using exact methods~\\cite{michalewicz2013solve}.\nHeuristics are a family of methods that can be used to find a find a\n\\emph{sufficiently good} solution, though not necessarily the optimal solution,\nwhere the emphasis is on prioritising computational efficiency.\n\nThe heuristic approach taken here will be to use a neighbourhood search algorithm.\nThis algorithm works by considering a given potential solution, evaluating it\nand then trying another potential solution \\emph{close} to it. What \\emph{close}\nmeans depends on different approaches and problems: it is referred to as the\nneighbourhood. When a new solution is considered \\emph{good}\\footnote{`Good' is\nagain a term that depends on the approach and problem.} then the search\ncontinues from the neighbourhood of this new solution.\n\nFor this problem, the steps are to first represent a possible solution, that is\na given route between all the potential stops as a \\emph{tour}. If there are 3\ntotal stops the tour must start and stop at the first one then there are two\npossible tours:\n\n\\[\n    t \\in \\{(1, 2, 3, 1), (1, 3, 2, 1)\\}\n\\]\n\nGiven a distance matrix \\(d\\) such that \\(d_{ij}\\) is the distance between stop\n\\(i\\) and \\(j\\) the total cost of a tour is given by:\n\n\\[\n    C(t)=\\sum_{i=1}^{n} d_{t_i, t_{i + 1}}\n\\]\n\nThus, with:\n\n\\[\n    d = \\begin{pmatrix}\n        0 & 1 & 3\\\\\n        1 & 0 & 15\\\\\n        3 & 3 & 7\n        \\end{pmatrix}\n\\]\n\nWe have:\n\n\\begin{eqnarray*}\n    C((1, 2, 3, 1)) &= d_{12} + d_{23} + d_{31} = 1 + 15 + 3 = 19\\\\\n    C((1, 3, 2, 1)) &= d_{13} + d_{32} + d_{21} = 3 + 3 + 1 = 7\n\\end{eqnarray*}\n\nIn general, the neighbourhood search can be written down as:\n\n\\begin{enumerate}\n    \\item Start with a given tour: \\(t\\).\n    \\item Evaluate \\(C(t)\\).\n    \\item Identify a new \\(\\tilde t\\) from \\(t\\) and accept it as a replacement\n        for \\(t\\) if \\(C(\\tilde t)< C(t)\\).\n    \\item Repeat the 3rd step until some stopping condition is met.\n\\end{enumerate}\n\nThis is shown diagrammatically in\nFigure~\\ref{fig:neighbourhood_search_flow_diagram}.\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n        \\includestandalone[width=.7\\textwidth]{./assets/neighbourhood_search_flow_diagram/main}\n    \\end{center}\n    \\caption{The general neighbourhood search algorithm. \\(N(t)\\) refers to some\n    neighbourhood of \\(t\\).}\n    \\label{fig:neighbourhood_search_flow_diagram}\n\\end{figure}\n\nA number of stopping conditions can be used including some specific\noverall cost or a number of total iterations of the algorithm.\n\nThe neighbourhood of a tour \\(t\\) is taken as some set of tours that can be\nobtained from \\(t\\) using a specific and computationally efficient\n\\textbf{neighbourhood operator}.\nTo illustrate two such neighbourhoods operators, consider the following tour on\n7 stops:\n\n\\[\n    t = (0, 1, 2, 3, 4, 5, 6, 0)\n\\]\n\nOne possible neighbourhood is to choose 2 stops at random and swap. For\nexample, the tour \\(\\tilde t^{(1)}\\in N(t)\\) is obtained by swapping the stop\nlabelled 2 and the stop labelled 5.\n\n\\[\n    \\tilde t^{(1)} = (0, 1, 5, 3, 4, 2, 6, 0)\n\\]\n\nAnother possible neighbourhood is to choose 2 stops at random and reverse the\norder of all stops between (including) those two stops. For example, the tour\n\\(\\tilde t^{(2)} \\in N(t)\\) is obtained by reversing the order of all stops between\nthe stop labelled 2 and the stop labelled 5.\n\n\\[\n    \\tilde t^{(2)} = (0, 1, 5, 4, 3, 2, 6, 0)\n\\]\n\nExamples of these tours are shown in\nFigure~\\ref{fig:tsp-effect-of-neighbourhood-operators}.\n\n\\begin{figure}[!hbtp]\n    \\begin{center}\n        \\includegraphics[width=0.8\\textwidth]{./assets/tsp-effect-of-neighbourhood-operators/main.pdf}\n    \\end{center}\n    \\caption{The effect of two neighbourhood operators on \\(t\\). \\(\\tilde t^{(1)}\\) is\n    obtained by swapping stops labelled 2 and 5. \\(\\tilde t^{(2)}\\) is obtained by reversing the\n    path between stops labelled 2 and 5.}\n    \\label{fig:tsp-effect-of-neighbourhood-operators}\n\\end{figure}\n\n\\section{Solving with Python}\\label{sec:heuristics_solving-with-python}\n\nTo solve this problem using Python, functions will be written that match the\nfirst three steps in the Section~\\ref{sec:heuristics_theory}.\nThe first step is to write the \\mintinline{python}{get_initial_candidate}\nfunction that creates an initial tour.\n\n\\begin{pyin}\nimport numpy as np\n\n\ndef get_initial_candidate(number_of_stops, seed):\n    \"\"\"Return an random initial tour.\n\n    Args:\n        number_of_stops: The number of stops\n        seed: An integer seed.\n\n    Returns:\n        A tour starting an ending at stop with index 0.\n    \"\"\"\n    internal_stops = list(range(1, number_of_stops))\n    np.random.seed(seed)\n    np.random.shuffle(internal_stops)\n    return [0] + internal_stops + [0]\n\\end{pyin}\n\nThis gives a random tour on 13 stops:\n\n\\begin{pyin}\nnumber_of_stops = 13\nseed = 0\ninitial_candidate = get_initial_candidate(\n    number_of_stops=number_of_stops,\n    seed=seed,\n)\nprint(initial_candidate)\n\\end{pyin}\n\n\\begin{pyout}\n[0, 7, 12, 5, 11, 3, 9, 2, 8, 10, 4, 1, 6, 0]\n\\end{pyout}\n\nTo be able to evaluate any given tour its cost must be found. Here\n\\mintinline{python}{get_cost} does this:\n\n\\begin{pyin}\ndef get_cost(tour, distance_matrix):\n    \"\"\"Return the cost of a tour.\n\n    Args:\n        tour: A given tuple of successive stops.\n        distance_matrix: The distance matrix of the problem.\n\n    Returns:\n        The cost\n    \"\"\"\n    return sum(\n        distance_matrix[current_stop, next_stop]\n        for current_stop, next_stop in zip(tour[:-1], tour[1:])\n    )\n\\end{pyin}\n\n\\begin{pyin}\ndistance_matrix = np.array(\n    (\n        (0, 35, 35, 29, 70, 35, 42, 27, 24, 44, 58, 71, 69),\n        (35, 0, 67, 32, 72, 40, 71, 56, 36, 11, 66, 70, 37),\n        (35, 67, 0, 63, 64, 68, 11, 12, 56, 77, 48, 67, 94),\n        (29, 32, 63, 0, 93, 8, 71, 56, 8, 33, 84, 93, 69),\n        (70, 72, 64, 93, 0, 101, 56, 56, 92, 81, 16, 5, 69),\n        (35, 40, 68, 8, 101, 0, 76, 62, 11, 39, 91, 101, 76),\n        (42, 71, 11, 71, 56, 76, 0, 15, 65, 81, 40, 60, 94),\n        (27, 56, 12, 56, 56, 62, 15, 0, 50, 66, 41, 58, 82),\n        (24, 36, 56, 8, 92, 11, 65, 50, 0, 39, 81, 91, 74),\n        (44, 11, 77, 33, 81, 39, 81, 66, 39, 0, 77, 79, 37),\n        (58, 66, 48, 84, 16, 91, 40, 41, 81, 77, 0, 20, 73),\n        (71, 70, 67, 93, 5, 101, 60, 58, 91, 79, 20, 0, 65),\n        (69, 37, 94, 69, 69, 76, 94, 82, 74, 37, 73, 65, 0),\n    )\n)\ncost = get_cost(\n    tour=initial_candidate,\n    distance_matrix=distance_matrix,\n)\nprint(cost)\n\\end{pyin}\n\n\\begin{pyout}\n827\n\\end{pyout}\n\nNow a function for neighbourhood operator will be written,\n\\mintinline{python}{swap_stops}, that swaps two stops in a given tour.\n\n\\begin{pyin}\ndef swap_stops(tour):\n    \"\"\"Return a new tour by swapping two stops.\n\n    Args:\n        tour: A given tuple of successive stops.\n\n    Returns:\n        A tour\n    \"\"\"\n    number_of_stops = len(tour) - 1\n    i, j = np.random.choice(range(1, number_of_stops), 2)\n    new_tour = list(tour)\n    new_tour[i], new_tour[j] = tour[j], tour[i]\n    return new_tour\n\\end{pyin}\n\nApplying this neighbourhood operator to the initial candidate gives:\n\n\\begin{pyin}\nprint(swap_stops(initial_candidate))\n\\end{pyin}\n\nwhich swaps the 10th and 12th stops:\n\n\\begin{pyout}\n[0, 7, 12, 5, 11, 3, 9, 2, 8, 1, 4, 10, 6, 0]\n\\end{pyout}\n\nNow all the tools are in place to build a tool to carry out the\nneighbourhood search \\mintinline{python}{run_neighbourhood_search}.\n\n\\begin{pyin}\ndef run_neighbourhood_search(\n    distance_matrix,\n    iterations,\n    seed,\n    neighbourhood_operator=swap_stops,\n):\n    \"\"\"Returns a tour by carrying out a neighbourhood search.\n\n    Args:\n        distance_matrix: the distance matrix\n        iterations: the number of iterations for which to\n                    run the algorithm\n        seed: a random seed\n        neighbourhood_operator: the neighbourhood operator\n                                (default: swap_stops)\n\n    Returns:\n        A tour\n    \"\"\"\n    number_of_stops = len(distance_matrix)\n    candidate = get_initial_candidate(\n        number_of_stops=number_of_stops,\n        seed=seed,\n    )\n    best_cost = get_cost(\n        tour=candidate,\n        distance_matrix=distance_matrix,\n    )\n    for _ in range(iterations):\n        new_candidate = neighbourhood_operator(candidate)\n        cost = get_cost(\n            tour=new_candidate,\n            distance_matrix=distance_matrix,\n        )\n        if cost <= best_cost:\n            best_cost = cost\n            candidate = new_candidate\n\n    return candidate\n\\end{pyin}\n\nNow running this for 1000 iterations:\n\n\\begin{pyin}\nnumber_of_iterations = 1000\n\nsolution_with_swap_stops = run_neighbourhood_search(\n    distance_matrix=distance_matrix,\n    iterations=number_of_iterations,\n    seed=seed,\n    neighbourhood_operator=swap_stops,\n)\nprint(solution_with_swap_stops)\n\\end{pyin}\n\ngives:\n\n\\begin{pyout}\n[0, 7, 2, 8, 5, 3, 1, 9, 12, 11, 4, 10, 6, 0]\n\\end{pyout}\n\nThis has a cost:\n\n\\begin{pyin}\ncost = get_cost(\n    tour=solution_with_swap_stops,\n    distance_matrix=distance_matrix,\n)\nprint(cost)\n\\end{pyin}\n\n\\begin{pyout}\n362\n\\end{pyout}\n\nTherefore, using this particular algorithm, a pretty good route is found, with a\ntotal distance of 362.\n\nIt is important to note that this may not be the optimal route, and different\nalgorithms may produce better solutions.\nFor example, one way to modify the algorithm is to use a different neighbourhood\noperator.\nInstead of swapping two stops, reverse the path between those two stops. This\ncorresponds to an algorithm called the ``2-opt''\nalgorithm\\index{2-opt algorithm}.\\footnote{The 2-opt algorithm was first\npublished in~\\cite{croes1958method}.}\nThe \\mintinline{python}{reverse_path} function does this:\n\n\\begin{pyin}\ndef reverse_path(tour):\n    \"\"\"Return a new tour by reversing the path between two stops.\n\n    Args:\n        tour: A given tuple of successive stops.\n\n    Returns:\n        A tour\n    \"\"\"\n    number_of_stops = len(tour) - 1\n    stops = np.random.choice(range(1, number_of_stops), 2)\n    i, j = sorted(stops)\n    new_tour = tour[:i] + tour[i : j + 1][::-1] + tour[j + 1 :]\n    return new_tour\n\\end{pyin}\n\nApplying this neighbourhood operator to the initial candidate gives:\n\n\\begin{pyin}\nprint(reverse_path(initial_candidate))\n\\end{pyin}\n\nwhich reverses the order between the 3rd and the 11th stop:\n\n\\begin{pyout}\n[0, 7, 4, 10, 8, 2, 9, 3, 11, 5, 12, 1, 6, 0]\n\\end{pyout}\n\nNow running the neighbourhood search for 1000 iterations using the\n\\mintinline{python}{reverse_path} neighbourhood operator:\n\n\\begin{pyin}\nsolution_with_reverse_path = run_neighbourhood_search(\n    distance_matrix=distance_matrix,\n    iterations=number_of_iterations,\n    seed=seed,\n    neighbourhood_operator=reverse_path,\n)\nprint(solution_with_reverse_path)\n\\end{pyin}\n\ngives:\n\n\\begin{pyout}\n[0, 8, 5, 3, 1, 9, 12, 11, 4, 10, 6, 2, 7, 0]\n\\end{pyout}\n\nThis now gives a different route.\nImportantly, the costs differ substantially:\n\n\\begin{pyin}\ncost = get_cost(\n    tour=solution_with_reverse_path,\n    distance_matrix=distance_matrix,\n)\nprint(cost)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n299\n\\end{pyout}\n\nThis improves on the solution found using the \\mintinline{python}{swap_stops}\noperator. Figure~\\ref{fig:final-tsp-tours-python} shows the final obtained\nroutes given by both approaches.\n\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=\\textwidth]{./assets/final-tsp-tours-with-python/main.pdf}\n    \\end{center}\n    \\caption{The final tours obtained by using the neighbourhood search in\n    Python.}\n    \\label{fig:final-tsp-tours-python}\n\\end{figure}\n\n\n\n\\section{Solving with R}\\label{sec:heuristics_solving-with-R}\n\nTo solve this problem using R, functions will be written that match the\nfirst three steps in the Section~\\ref{sec:heuristics_theory}.\n\nThe first step is to write the \\mintinline{R}{get_initial_candidate}\nfunction that creates an initial tour:\n\n\\begin{Rin}\n#' Return an random initial tour.\n#'\n#' @param number_of_stops The number of stops.\n#' @param seed An integer seed.\n#'\n#' @return A tour starting an ending at stop with index 0.\nget_initial_candidate <- function(number_of_stops, seed){\n  internal_stops <- 1:(number_of_stops - 1)\n  set.seed(seed)\n  internal_stops <- sample(internal_stops)\n  c(0, internal_stops, 0)\n}\n\\end{Rin}\n\nThis gives a random tour on 13 stops:\n\n\\begin{Rin}\nnumber_of_stops <- 13\nseed <- 1\ninitial_candidate <- get_initial_candidate(\n  number_of_stops = number_of_stops,\n  seed = seed)\nprint(initial_candidate)\n\\end{Rin}\n\n\\begin{Rout}\n [1]  0  9  4  7  1  2  5  3  8  6 11 12 10  0\n\\end{Rout}\n\nTo be able to evaluate any given tour its cost must be found. Here\n\\mintinline{R}{get_cost}  does this:\n\n\\begin{Rin}\n#' Return the cost of a tour\n#'\n#' @param tour A given vector of successive stops.\n#' @param seed The distance matrix of the problem.\n#'\n#' @return The cost\nget_cost <- function(tour, distance_matrix){\n  pairs <-  cbind(tour[-length(tour)], tour[-1]) + 1\n  sum(distance_matrix[pairs])\n}\n\\end{Rin}\n\n\\begin{Rin}\ndistance_matrix <- rbind(\n        c(0, 35, 35, 29, 70, 35, 42, 27, 24, 44, 58, 71, 69),\n        c(35, 0, 67, 32, 72, 40, 71, 56, 36, 11, 66, 70, 37),\n        c(35, 67, 0, 63, 64, 68, 11, 12, 56, 77, 48, 67, 94),\n        c(29, 32, 63, 0, 93, 8, 71, 56, 8, 33, 84, 93, 69),\n        c(70, 72, 64, 93, 0, 101, 56, 56, 92, 81, 16, 5, 69),\n        c(35, 40, 68, 8, 101, 0, 76, 62, 11, 39, 91, 101, 76),\n        c(42, 71, 11, 71, 56, 76, 0, 15, 65, 81, 40, 60, 94),\n        c(27, 56, 12, 56, 56, 62, 15, 0, 50, 66, 41, 58, 82),\n        c(24, 36, 56, 8, 92, 11, 65, 50, 0, 39, 81, 91, 74),\n        c(44, 11, 77, 33, 81, 39, 81, 66, 39, 0, 77, 79, 37),\n        c(58, 66, 48, 84, 16, 91, 40, 41, 81, 77, 0, 20, 73),\n        c(71, 70, 67, 93, 5, 101, 60, 58, 91, 79, 20, 0, 65),\n        c(69, 37, 94, 69, 69, 76, 94, 82, 74, 37, 73, 65, 0)\n)\ncost <- get_cost(\n  tour = initial_candidate,\n  distance_matrix = distance_matrix)\nprint(cost)\n\\end{Rin}\n\n\\begin{Rout}\n[1] 709\n\\end{Rout}\n\nNow a function for a neighbourhood operator will be written,\n\\mintinline{R}{swap_stops}: swapping two stops in a given tour.\n\n\\begin{Rin}\n#' Return a new tour by swapping two stops.\n#'\n#' @param tour A given vector of successive stops.\n#'\n#' @return A tour\nswap_stops <- function(tour){\n  number_of_stops <- length(tour) - 1\n  stops_to_swap <- sample(2:number_of_stops, 2)\n  new_tour <- replace(\n    x = tour,\n    list = stops_to_swap,\n    values = rev(tour[stops_to_swap])\n  )\n}\n\\end{Rin}\n\nApplying this neighbourhood operator to the initial candidate gives:\n\n\\begin{Rin}\nnew_tour <- swap_stops(initial_candidate)\nprint(new_tour)\n\\end{Rin}\n\nwhich swaps the 6th and 11th stops:\n\n\\begin{Rout}\n [1]  0  9  4  7  1 11  5  3  8  6  2 12 10  0\n\\end{Rout}\n\nNow all the tools are in place to build a tool to carry out the\nneighbourhood search \\mintinline{R}{run_neighbourhood_search}.\n\n\\begin{Rin}\n#' Returns a tour by carrying out a neighbourhood search\n#'\n#' @param distance_matrix: the distance matrix\n#' @param iterations: the number of iterations for\n#'                    which to run the algorithm\n#' @param seed: a random seed (default: None)\n#' @param neighbourhood_operator: the neighbourhood operation\n#'                                (default: swap_stops)\n#'\n#' @return A tour\nrun_neighbourhood_search <- function(\n  distance_matrix,\n  iterations,\n  seed = NA,\n  neighbourhood_operator = swap_stops\n){\n  number_of_stops <- nrow(distance_matrix)\n  candidate <- get_initial_candidate(\n    number_of_stops = number_of_stops,\n    seed = seed\n  )\n  best_cost <- get_cost(\n    tour = candidate,\n    distance_matrix = distance_matrix\n  )\n  for (repetition in 1:iterations) {\n    new_candidate <- neighbourhood_operator(candidate)\n    cost <- get_cost(\n        tour = new_candidate,\n        distance_matrix = distance_matrix\n    )\n    if (cost <= best_cost) {\n      best_cost <- cost\n      candidate <- new_candidate\n    }\n  }\n  candidate\n}\n\\end{Rin}\n\nNow running this for 1000 iterations:\n\n\\begin{Rin}\nnumber_of_iterations <- 1000\nsolution_with_swap_stops <- run_neighbourhood_search(\n  distance_matrix = distance_matrix,\n  iterations = number_of_iterations,\n  seed = seed,\n  neighbourhood_operator = swap_stops\n)\nprint(solution_with_swap_stops)\n\\end{Rin}\n\ngives:\n\n\\begin{Rout}\n [1]  0 11  4 10  6  2  7 12  9  1  3  5  8  0\n\\end{Rout}\n\nThis has a cost:\n\n\\begin{Rin}\ncost <- get_cost(\n  tour = solution_with_swap_stops,\n  distance_matrix = distance_matrix\n)\nprint(cost)\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n[1] 360\n\\end{Rout}\n\nTherefore, using this particular algorithm, a pretty good route is found, with a\ntotal distance of 360.\n\nIt is important to note that this may not be the optimal route, and different\nalgorithms may produce better solutions.\nFor example, one way to modify the algorithm is to use a different neighbourhood\noperator.\nInstead of swapping two stops, reverse the path between those two stops. This\ncorresponds to an algorithm called the ``2-opt''\nalgorithm\\index{2-opt algorithm}.\\footnote{The 2 opt algorithm was first\npublished in~\\cite{croes1958method}.}\nThe \\mintinline{R}{reverse_path} function does this:\n\n\n\\begin{Rin}\n#' Return a new tour by reversing the path between two stops.\n#'\n#' @param tour A given vector of successive stops.\n#'\n#' @return A tour\nreverse_path <- function(tour){\n  number_of_stops <- length(tour) - 1\n  stops_to_swap <- sample(2:number_of_stops, 2)\n  i <- min(stops_to_swap)\n  j <- max(stops_to_swap)\n  new_order <- c(c(1: (i - 1)), c(j:i), c( (j + 1): length(tour)))\n  tour[new_order]\n}\n\\end{Rin}\n\nApplying this neighbourhood operator to the initial candidate gives:\n\n\\begin{Rin}\nnew_tour <- reverse_path(initial_candidate)\nprint(new_tour)\n\\end{Rin}\n\nwhich reverses the order\nbetween the 3rd and the 13th stop:\n\n\\begin{Rout}\n [1]  0  9 10 12 11  6  8  3  5  2  1  7  4  0\n\\end{Rout}\n\nNow running the neighbourhood search for 1000 iterations using the\n\\mintinline{R}{reverse_path} neighbourhood operator:\n\n\\begin{Rin}\nnumber_of_iterations <- 1000\nsolution_with_reverse_path <- run_neighbourhood_search(\n  distance_matrix = distance_matrix,\n  iterations = number_of_iterations,\n  seed = seed,\n  neighbourhood_operator = reverse_path\n)\nprint(solution_with_reverse_path)\n\\end{Rin}\n\ngives:\n\n\\begin{Rout}\n [1]  0  7  2  6 10  4 11 12  9  1  3  5  8  0\n\\end{Rout}\n\nThis now gives a different route.\nImportantly, the costs differ substantially:\n\n\\begin{Rin}\ncost <- get_cost(\n  tour = solution_with_reverse_path,\n  distance_matrix = distance_matrix\n)\nprint(cost)\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n[1] 299\n\\end{Rout}\n\nThis is an improvement on the solution found using the \\mintinline{R}{swap_stops}\noperator. Figure~\\ref{fig:final-tsp-tours-r} shows the final obtained routes\ngiven by both approaches.\n\n\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=\\textwidth]{./assets/final-tsp-tours-with-R/main.pdf}\n    \\end{center}\n    \\caption{The final tours obtained by using the neighbourhood search in R.}\n    \\label{fig:final-tsp-tours-r}\n\\end{figure}\n\n\n\\section{Wider context}\\label{sec:heuristics_wider_context}\n\nHeuristic methods, sometimes referred to as meta-heuristics, are a whole family\nof algorithms used to find approximate solutions to combinatorial optimisation\nproblems. An overview is given in~\\cite{bozorg2017meta}. These algorithms\ninclude greedy searches, tabu searches\\index{tabu search}, simulated\nannealing\\index{simulated annealing}, genetic algorithms\\index{genetic algorithm},\nas well \\index{ant colony optimisation}. They are usually employed when the\nproblem is too large or complex to use exact methodologies.\n\nThe travelling salesman problem, described in this chapter, is a classic example\nof one of these problems, formally described first in~\\cite{menger1932},\nalthough thought to have been discussed informally centuries before.\nIt is an example of a large number of types of problems collectively known as\nvehicle routing problems, which often require heuristic methods for their\nsolutions. A survey is given in~\\cite{braekers2016vehicle}. Variations of\nthe problem include multiple, heterogeneous and/or capacitated vehicles, and\nstochastic or time-dependent travel times. A recent adaptation of the problem\nis the green vehicle routing\nproblem\\index{green vehicle routing problem}~\\cite{moghdani2021green}, where the\ncost function includes consideration of green house gas emissions and other\npollutants.\n\nFor more diverse applications of heuristic methods,\nconsider~\\cite{lewis2016creating} which describes a tabu search algorithm\nfor finding seating plans for a wedding; and \\cite{tong2013modeling} where\na genetic algorithm is used to build a prediction model for locations of\ndeep-sea wildlife habitats.\n", "meta": {"hexsha": "fa84972ebc974f11fc1616039c23405d74af6bae", "size": 22192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/chapters/09/main.tex", "max_stars_repo_name": "drvinceknight/amwoss", "max_stars_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-21T21:35:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T21:35:44.000Z", "max_issues_repo_path": "src/chapters/09/main.tex", "max_issues_repo_name": "drvinceknight/amwoss", "max_issues_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 71, "max_issues_repo_issues_event_min_datetime": "2019-11-18T11:00:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-21T22:49:40.000Z", "max_forks_repo_path": "src/chapters/09/main.tex", "max_forks_repo_name": "drvinceknight/amwoss", "max_forks_repo_head_hexsha": "8b0bf80f0a06dc5cf9bfeef4b9f9e174ccadf06d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-15T12:00:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-15T12:00:49.000Z", "avg_line_length": 28.8207792208, "max_line_length": 102, "alphanum_fraction": 0.6981795242, "num_tokens": 6851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.6331440672706129}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section*{Bayesian model choice}\n\\begin{frame}{Bayesian model selection: testing all over again}\n Model choice (or selection) is a \\textbf{major} topic within any school of inference: it is how scientists make decisions about competing theories/hypotheses in light of data.\n One can associate a set of models $\\boldsymbol{\\mathcal{M}} = \\{ \\mathcal{M}_1, \\ldots \\mathcal{M}_n \\}$ with a set of indices $I$ such that $\\mu \\in I$ we want to estimate the posterior distribution of the indicator function $\\mathbb{I}_{\\boldsymbol{\\Theta}_\\mu}(\\theta)$.\n \n Recall that estimating indicator functions over $\\boldsymbol{\\Theta}$ was the fundamental mechanic of Bayesian testing.\n In the setting of Bayesian model selection (BMS), we have something of the form\n \\begin{equation*}\n  \\mathcal{M}_i : x \\sim f_i(x \\mid \\theta_i), \\theta_i \\in \\boldsymbol{\\Theta}_i, i \\in I.\n \\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{M-completeness}\nA key step in model selection is to identify in which regime the analyst finds themselves in.\n\\begin{defn}[M-open, M-closed, M-complete]\n \\label{def:m-open}\n Model selection can be categorised in three settings:\n \\begin{itemize}\n  \\item \\textbf{M-closed}: a situation where the true data-generating model is one of $\\mathcal{M}_i \\in \\boldsymbol{\\mathcal{M}}$, even though  it is most often  unknown to the  analyst;\n  \\item \\textbf{M-complete}: a situation where the true model exists and is out of the model set $\\boldsymbol{\\mathcal{M}}$.\n  We nevertheless want to select one of the models in the set due to computational or mathematical tractability reasons.\n  \\item \\textbf{M-open}: a situation in which we know the true data-generating model is not in $\\boldsymbol{\\mathcal{M}}$ and we have no idea what it looks like.\n \\end{itemize}\n\\end{defn}\nSee~\\cite{Bernardo2000} and \\cite{Yao2018}.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{BMS: example I}\nSuppose one has $x \\in \\mathbb{N}\\cup \\{0\\}$, which measures, say, the number of eggs Balerion The Black Dread has laid in five consecutive breeding seasons.\nOne can conjure up\n\\begin{equation*}\n \\mathcal{M}_1 : x \\sim \\operatorname{Poisson}(\\lambda), \\lambda > 0,\n\\end{equation*}\nor, if feeling fancy, \n\\begin{equation*}\n \\mathcal{M}_2 : x \\sim \\operatorname{Negative-binomial}(\\lambda, \\phi), \\lambda, \\phi > 0.\n\\end{equation*}\nNotice that, under $\\mathcal{M}_2$, $E[X] = \\lambda$ and $\\vr(X) = \\lambda ( 1 + \\lambda/\\phi)$.\nWhat happens as $\\phi \\to \\infty$?\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{BMS: example II}\nTake the famous Galaxy data set:\n \\begin{center}\n \\includegraphics[scale=0.3]{figures/galaxies.pdf}\n\\end{center}\nA now classical model is a Gaussian mixture:\n\\begin{equation*}\n \\mathcal{M}_i : v_j \\sim \\sum_{l=1}^i p_{il} \\cdot \\operatorname{Normal}(v_j; \\mu_{li},\\sigma^2_{li}). \n\\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{BMS: example III}\nConsider the data:\n \\begin{center}\n \\includegraphics[scale=0.3]{figures/oranges.pdf}\n\\end{center}\nAmongst the models we can consider, \n\\begin{align*}\n\\mathcal{M}_1 :& y_{it} \\sim \\operatorname{Normal}(\\beta_{10} + b_{1i}, \\sigma_1^2), \\\\\n\\mathcal{M}_2 :& y_{it} \\sim \\operatorname{Normal}(\\beta_{20} + \\beta_{21}T_t + b_{2i}, \\sigma_2^2) , \\\\\n\\mathcal{M}_3 :& y_{it} \\sim \\operatorname{Normal}\\left(\\frac{\\beta_{30}}{1 + \\beta_{31}\\exp\\left(\\beta_{32} T_t\\right)}, \\sigma_3^2\\right), \\\\\n\\mathcal{M}_4 :& y_{it} \\sim \\operatorname{Normal}\\left(\\frac{\\beta_{40} + b_{4i}}{1 + \\beta_{41}\\exp\\left(\\beta_{42} T_t\\right)}, \\sigma_4^2\\right).\n\\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Step 0: priors}\nFirst, let us look at a convenient representation of model space:\n\\begin{equation*}\n \\boldsymbol{\\Theta} = \\bigcup_{i \\in I} \\{i\\} \\times \\boldsymbol{\\Theta}_i.\n\\end{equation*}\nNow, to each $\\mathcal{M}_i$, we associate a prior $\\pi_i(\\theta_i)$  on each subspace and, by Bayes' theorem we get\n\\begin{align*}\n \\pr(\\mathcal{M}_i \\mid x) & = \\pr( \\mu = i \\mid x), \\\\ \n &= \\frac{w_i \\int_{\\boldsymbol{\\Theta}_i} f_i(x\\mid t_i)\\pi_i(t_i)\\,dt_i}{\\sum_{j} w_j \\int_{\\boldsymbol{\\Theta}_j} f_j(x\\mid t_j)\\pi_j(t_j)\\,dt_j },\n\\end{align*}\nwhere the $w_i$ are the \\textbf{prior probabilities} for each model.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{An intuitive predictive}\nA nice consequence of the formulation we just saw is that the predictive distribution looks quite intuitive:\n\\begin{align}\n\\nonumber\n p(\\tilde{x} \\mid \\boldsymbol{x}) &= \\sum_{j} w_j \\int_{\\boldsymbol{\\Theta}_j} f_j(\\tilde{x} \\mid t_j) f_j(\\boldsymbol{x}\\mid t_j)\\pi_j(t_j)\\,dt_j,\\\\\n \\label{eq:predictive_1}\n &= \\sum_{j} \\pr(\\mathcal{M}_j \\mid \\boldsymbol{x}) m_j(\\tilde{x}).\n\\end{align}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Hello, my old friend}\nHere, Bayes factors also play a central role:\n\\begin{align*}\n \\operatorname{BF}_{12} &= \\frac{\\pr(\\mathcal{M}_1 \\mid x)}{\\pr(\\mathcal{M}_2 \\mid x)}\\bigg/\\frac{\\pr(\\mathcal{M}_1)}{\\pr(\\mathcal{M}_2)},\\\\\n  &= \\frac{w_1^\\prime \\cdot w_2}{w_2^\\prime \\cdot w_1},\n\\end{align*}\nwith $w_i^\\prime := \\pr(\\mathcal{M}_1 \\mid x)$.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Model averaging}\nWhat if we simply \\textbf{refuse} to select one model?\nWe can write\n\\begin{align}\n \\nonumber\n p(\\tilde{x} \\mid \\boldsymbol{x})  &= \\int_{\\boldsymbol{\\Theta}} f(\\tilde{x} \\mid t) f(\\boldsymbol{x}\\mid t)\\pi(t)\\,dt,\\\\\n \\nonumber\n &= \\sum_{j} \\int_{\\boldsymbol{\\Theta}_j} f_j(\\tilde{x} \\mid t_j) g(j, t_j \\mid \\boldsymbol{x})\\,dt_j,\\\\\n \\nonumber\n &= \\sum_j p (\\mathcal{M}_j \\mid \\boldsymbol{x}) \\int_{\\boldsymbol{\\Theta}_j} f_j(\\tilde{x} \\mid t_j) p(t_j \\mid \\boldsymbol{x})\\,dt_j,\\\\\n \\label{eq:predictive_2}\n  &= \\sum_j w_j^\\prime \\int_{\\boldsymbol{\\Theta}_j} f_j(\\tilde{x} \\mid t_j) p(t_j \\mid \\boldsymbol{x})\\,dt_j.\n\\end{align}\nwhich is another version of the expression in (\\ref{eq:predictive_1}).\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Model checking}\nModern Bayesian inference not only allows for, but actively encourages model interrogation and checking.\n\\begin{itemize}\n \\item The central idea of \\textbf{Leave-one-out cross-validation (LOO)} is to estimate the \\textit{expected log pointwise predictive density for a new dataset}, elpd:\n \\begin{equation*}\n  \\operatorname{elpd} = \\sum_{i=1}^n \\int m(\\tilde{x}_i)\\log p(\\tilde{x}_i \\mid \\boldsymbol{x})\\,d\\tilde{x}_i.\n \\end{equation*}\n See \\cite{Vehtari2017}.\n \\item With \\textbf{Posterior predictive checks (PPCs)} we wish to compare  functions of the observed data, $f(\\boldsymbol{x})$ with functions of the predictive distribution, $f(\\boldsymbol{\\tilde{x}})$.\n  \\begin{center}\n \\includegraphics[scale=0.5]{figures/PPC.jpg}\n\\end{center}\n See \\cite{Berkhof2000} and~\\cite{Gabry2019}.\n\\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n  \\item[\\faBook] \\cite{Robert2007}, Ch. 7.\n%  \\item \n \\item[\\faForward] Next lecture: \\cite{Schervish1995} Ch. 7.4.\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "6c4747f534efa50108092714daf137822c34f704", "size": 7090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_7.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_7.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_7.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": 51.0071942446, "max_line_length": 274, "alphanum_fraction": 0.6651622003, "num_tokens": 2319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.633144062424408}}
{"text": "\\documentclass[../thesis.tex]{subfiles}\n\n%!TeX spellcheck = en-GB\n\n% chktex-file 18\n\n\\begin{document}\n\n\\chapter{Procedure}\n\\label{chap:procedure}\n\n\\section{The Hamiltonian}\n\nIn this chapter we will describe how we obtained the numerical results.\nWe begin by computing the matrix elements of the Hamiltonian in a basis\ngiven by the eigenstates of an isotropic double harmonic oscillator.\nIn analogy with the classical case, we consider two independent\nquantum numbers \\(n_1, n_2\\) corresponding to the two orthogonal\noscillating directions. We can define two number operators \\(N_1, N_2\\) such that\n\\(N_1 \\ket{n_1, n_2} = n_1 \\ket{n_1, n_2}\\) and \\(N_2 \\ket{n_1, n_2} = n_2 \\ket{n_1, n_2}\\).\nWe consider the creation and annihilation operators \\(\\ad{1}, a_1\\) and\n\\(\\ad{2}, a_2\\)\nsuch that \\(  N_1 = \\ad{1} a_1 \\) and \\( N_2 = \\ad{2} a_2 \\).\nIn terms of the previously defined operators, the Hamiltonian of the isotropic\ndouble harmonic oscillator is given by\n\\[\n  H_0 = \\hbar \\omega_0 \\left(\\ad{1} a_1 + \\frac{1}{2} I + \\ad{2} a_2 + \\frac{1}{2} I\\right)\n      = \\hbar \\omega_0 \\left(N_1 + N_2 + I\\right)\n\\]\nand its eigenstates are given by\n\\[\n  H_0 \\ket{n_1, n_2} = \\hbar \\omega_0 \\left( n_1 + n_2 + 1 \\right) \\ket{n_1, n_2}\n\\]\n\nSince \\(n_1 + n_2 = n\\) can be obtained in \\(\\sum_{i=0}^n i = \\frac{1}{2}\\,n(n+1)\\) ways,\nthe energy levels of the isotropic double harmonic oscillator are \\(\\frac{1}{2}\\,n(n+1)\\) fold\ndegenerated.\n\nIn the fundamental state \\(\\ket{0, 0}\\), with \\(n_1=n_2=0\\), the two dimensional\noscillator has a \\emph{zero point motion} with the energy equal to \\(\\hbar \\omega_0\\).\nSince we are interested in the spacings between consecutive,\nwe can rescale the energy such that the energy of the fundamental state becomes \\(0\\).\nThus the new Hamiltonian will be given by\n\\[\n  H_0 = A \\left(N_1 + N_2\\right),\n\\]\nwhere \\(A = \\hbar \\omega_0\\).\n\nWe can construct the basis starting from the vacuum state \\(\\ket{0, 0}\\) by acting\nwith the creation operators\n\\begin{align*}\n  {\\ad{1}}^{n_1} \\ket{0, 0} &= \\sqrt{n_1!} \\ket{n_1, 0} \\\\\n  {\\ad{2}}^{n_2} \\ket{0, 0} &= \\sqrt{n_2!} \\ket{0, n_2}\n\\end{align*}\n\nThus, by applying the operator \\({\\ad{1}}^{n_1} {\\ad{2}}^{n_2}\\)\nwe generate\n% such that \\(n_1 + n_2 = n\\)\n% (in order to obtain for each \\(n\\) all the states with the\n% energy \\(n\\, \\hbar \\omega_0\\))\n% we obtain\nthe basis elements ordered as follows:\n\\[\n  \\ket{0, 0} \\ket{0, 1} \\ket{0, 2} \\cdots \\ket{0, n} \\ket{1, 0} \\ket{1, 1}\n  \\cdots \\ket{1, n - 1} \\cdots \\ket{i, 0} \\ket{i, 1} \\cdots \\ket{i, n - i} \\cdots\n  \\ket{n, 0}.\n\\]\n\nFor our investigations, the Hamiltonian is expressed as a function of the creation and annihilation\noperators up to fourth order terms as follows\n\n\\begin{equation}\n\\label{eq:hamilt}\n\\begin{split}\n  H &= A \\left( \\ad{1} a_1 + \\ad{2} a_2 \\right)\n    + \\frac{B}{4} \\bigg[ \\left( 3 \\ad{1} {\\ad{2}}^2 + 3 a_1 a_2^2\n                               - {\\ad{1}}^3 - a_1^3 \\right)   \\\\\n  &\\quad + 3 \\left( a_1 {\\ad{2}}^2 + \\ad{1} a_2^2 - \\ad{1} a_1^2 - {\\ad{1}}^2 a_1\n             + 2 a_1 \\ad{2} a_2 + 2 \\ad{1} \\ad{2} a_2\n          \\right) \\bigg]  \\\\\n  &\\quad + \\frac{D}{16} \\bigg[ 6 \\left( {\\ad{1}}^2 a_1^2 + {\\ad{2}}^2 a_2^2 \\right)\n                        + 2 \\left( a_1^2 {\\ad{2}}^2 + {\\ad{1}}^2 a_2^2 \\right)\n                        + 8 \\ad{1} a_1 \\ad{2} a_2  \\\\\n  &\\quad + 4 \\left(\\ad{1} a_1^3 + {\\ad{1}}^3 a_1 + \\ad{2} a_2^3 + {\\ad{2}}^3 a_2\n     + a_1^2 \\ad{2} a_2 + {\\ad{1}}^2 \\ad{2} a_2 + \\ad{1} a_1 a_2^2 + \\ad{1} a_1 {\\ad{2}}^2\n        \\right)  \\\\\n  &\\quad + \\left( {\\ad{1}}^4 + a_1^4 + {\\ad{2}}^4 + a_2^4\n     + 2 {\\ad{1}}^2 {\\ad{2}}^2 + 2 a_1^2 a_2^2\n      \\right)\n                        \\bigg].\n\\end{split}\n\\end{equation}\n\nThe physical origin of this Hamiltonian is related to quadrupole dynamics of\nnuclear surfaces\\cite{Baran1998, Baran1996}.\nThe operators \\(a_1\\) and \\(a_2\\) are related to the normal modes of the\nquadrupole vibrations. In the case of a deformed nucleus, one mode named \\(\\beta \\)-vibration\ncorresponds to oscillations preserving the axial symmetry.\nFor the second mode, \\(\\gamma \\)-vibrations,\nthe transversal section perpendicularly to the symmetry axis changes periodically\nfrom ellipse to circle.\n\nThe energy levels will be expressed in units of harmonic oscillator energy and therefore\nfrom here on we will consider \\(A = 1\\).\nWe can obtain the eigenvalues and eigenvectors of the Hamiltonian by a\ndiagonalisation routine based on Relatively Robust Representations from\nIntel\\textsuperscript{\\textregistered} Math Kernel Library~\\cite{intel-mkl} used via a \\texttt{Python}\nprogram~\\cite{NumPy-SciPy, scipy, matplotlib}%{\\color{red} (+ citations)}.\nAny such diagonalisation method requires a truncation of the Hilbert space\nwhich induces errors concerning the eigenvalues. This errors increase as one moves to\nthe upper limit of the energy for a fixed dimension of the Hilbert space. Indeed we\nexpect this energies to have more important contributions from the states that were\neliminated by truncation.\nWe tested the stability of the energy levels by comparing the results obtained for\ndifferent sizes of the diagonalisation basis as is detailed in the next section.\n\n\\clearpage\n\n\\section{Stability}\n\nWe consider the \\emph{stable levels} to be the eigenvalues which, at a change of\nbasis from one with a dimension of $N$ to one with dimension \\(N+ \\Delta N\\),\ndo not change with more than a chosen threshold \\(\\delta_s\\).\nIn the following figure we show the variation of the energy levels when\nthe dimension increases from \\(N = 120\\) to \\(N = 140\\).\n\n\\begin{center}\n  \\includegraphics{\"B0.2 D0.4 N120/bar_E_diff\"}\n  \\captionof{figure}{\\(B = 0.2, D = 0.4, N = 120\\)}\n\\end{center}\n\nWe can observe that the first 400--600 eigenvalues have a very good stability.\nThus we can choose the stability threshold for example at \\(\\delta_s = 10^{-9}\\).\nQualitatively the shape of this distribution does not depend on the parameters of\nthe Hamiltonian or the dimension of the Hilbert space because it reflects the nature\nof the approximation as discussed previously.\nFor example, for \\(B = 0.55, D = 0.4, N = 260\\) compared\nwith \\(N = 280\\)\n\n\\begin{center}\n  \\includegraphics{\"B0.55 D0.4 N260/bar_E_diff\"}\n  \\captionof{figure}{\\(B = 0.55, D = 0.4, N = 260\\)}\n\\end{center}\n\nAs expected, the number of stable levels increases with the\ndiagonalisation basis.\nRoughly, for a given basis size $N$, the first 7--8\\% levels differ with less\nthan \\({\\delta_s = 10^{-9}}\\) when we compare with a basis of dimension\n\\(N + \\Delta N\\), with \\(\\Delta N = 20\\).\n\n\\section{Statistics}\n\nAs mentioned in \\cref{chap:quantum-chaos}, a spectrum can be characterised through the\nprobability distribution of the nearest neighbour spacing.\nThe \\emph{spacing} is defined as the difference between two consecutive\nenergy levels. Similarly the \\emph{relative spacing} is defined as\n\\[\n  s = \\frac{E_{i+1} - E_i}{\\mean{\\Delta E}},\n\\]\nwhere \\(\\mean{\\Delta E}\\) is the average spacing \\(\\frac{E_n - E_0}{N}\\).\n\nThe \\emph{nearest neighbour spacing distributions} tell us the probability \\(P(s)\\dd{s}\\) to\nfind a relative spacing $s$ when we move in the spectrum obtained by diagonalisation.\nThis probability is defined as follows\n\\[\n  P(s)\\dd{s} = \\frac{N_{s,s+\\Delta s}}{N},\n\\]\nwhere \\(N_{s,s+\\Delta s}\\) is the number of levels with the relative spacing\nbetween \\(s\\) and \\(s+ \\Delta s\\).\nWe can also define a \\emph{cumulative probability distribution},\n\\[\n  I(s) = \\sum_{s_i=0}^s P(s_i) \\Delta s\n\\]\n\n\\subsection{Irreducible representations}\n\nIn order to analyse the distributions of the previously obtained eigenvalues\nwe must first take into account the possible symmetries of the system.\nA consistent analysis requires us to consider classes of states which transform\nwith the same \\emph{irreducible representation}.\n\nThe Hamiltonian in eq.~\\eqref{eq:hamilt} has the finite \\(\\mathcal{C}_{3v}\\)\nsymmetry group.\nThis group has 3 irreducible representations: one bi-dimensional and\ntwo unidimensional, one symmetric and one anti-symmetric, namely\n\\(\\Gamma_b, \\Gamma_s, \\Gamma_a\\).\n\n\\subsubsection{Separating the bi-dimensional representation}\n\nThe presence of the bi-dimensional representation corresponds a two-fold\ndegeneracy. These degeneracies can be identified  by scrutinising the\ndifferences between consecutive levels \\(\\Delta E = E_{i+1} - E_i\\).\nAn other option is to use directly the relative spacing, which is a rescaling\nin units of average separation.\nThe separation of the symmetric and anti-symmetric irreducible representations\nwill be detailed later.\n\nIn figure~\\ref{fig:bar_delta} we can see how \\(\\Delta E\\) varies with the index of the\nlevels.\n\n\\begin{figure}[!h]\n  \\centering\n  \\includegraphics{\"B0.2 D0.4 N60/bar_delta\"}\n  \\caption{\\(B=0.2, D=0.4, N=60\\)}%\n\\label{fig:bar_delta}\n\\end{figure}\n\nDue to of the finite precision of the numerical implementation, the\ndifference between two consecutive degenerate levels might not be exactly 0,\nits value depending on the machine precision (as it can be seen in the above figure).\nTo take this fact into account we will consider that the levels which\nhave $s$ (or \\(\\Delta E\\)) greater than a chosen \\( \\varepsilon \\) as belonging\nto one of the unidimensional representations.\nIn order to choose a suitable value for \\( \\varepsilon \\), we use a histogram\nto visualise the number of levels at different spacings\n(see figure~\\ref{fig:relsp-b0.2n120}).\n\n\\begin{figure}[h!]\n  \\centering\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N120/hist_relsp\"}\n    \\caption{\\(B=0.2, D=0.4, N=120\\)}%\n    \\label{fig:relsp-b0.2n120}  % chktex 24\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.4 D0.4 N260/hist_relsp\"}\n    \\caption{\\(B=0.4, D=0.4, N=260\\)}%\n    \\label{fig:relsp-b0.4n260}  % chktex 24\n  \\end{subfigure}\n  \\caption{The relative spacing histograms for different parameters}\n\\end{figure}\n\nThis bimodal shape of the histogram suggests clearly the presence of the degenerate\nlevels well separated from the rest.\nFor some particular values for $B$ (such as \\(B = 0.4\\)) and high values for\n$N$ (\\( N > 200 \\)), we observed a splitting of the block corresponding to\nthe degenerated levels in two blocks, namely one at exactly 0 and the other at\nvery low values. (see~\\cref{fig:relsp-b0.4n260})\n\nIf we plot the spacing as a function of the level index, we can see how\neach level is situated with respect to the chosen \\( \\varepsilon \\).\nOnce again we can observe a clear separation of the spacings corresponding to\nthe bi-dimensional representation (see~\\cref{fig:relsp}).\n\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics{\"B0.2 D0.4 N60/relsp\"}\n  \\caption{\\(B=0.2, D=0.4, N=60\\)}\n  \\label{fig:relsp}\n\\end{figure}\n\n\\FloatBarrier\n\n\\subsubsection{Separating the unidimensional representations}\n\nThe unidimensional representations can be distinguished from the properties\nof the states at reflections with respect to the \\(Ox\\) axis\n(\\(y \\rightleftarrows -y\\)).\nWe ca establish a correspondence between the symmetry of the states to\nthis operation and the values of the quantum number \\(n_2\\). The states\ncontaining dominantly oscillator ket vectors with even \\(n_2\\) will\ntransform with the symmetric representation.\n\nThe values of the quantum numbers \\(n_1\\) and \\(n_2\\) depend on the ordering of the basis.\nBecause the diagonalisation algorithm returns the eigenvalues\n(and the corresponding eigenvectors) in ascending order,\nthe initial ordering of the basis is lost.\nOne method to approximate \\(n_1\\) and \\(n_2\\) for a given eigenvector would be\nto consider that their values are given by the index of the dominant coefficient.\nThus, if we have the following eigenvector\n\\[\n\\begin{pmatrix}\n    C_{0,0} \\\\ C_{0,1} \\\\ \\vdots \\\\ C_{0,n} \\\\ C_{1,0} \\\\ \\vdots \\\\ C_{1,n-1} \\\\\n    \\vdots \\\\ C_{i,0} \\\\ \\vdots \\\\ C_{i,n-i} \\\\ \\vdots \\\\ C_{n,0}\n  \\end{pmatrix}\n\\]\nand \\(C_{i,j}\\) is the greatest coefficient, than we assign to this eigenvector\nthe quantum numbers of the \\(k\\)-th element in the basis, where \\(k\\) is the\nindex of the coefficient.\n\nFor example, for the simplified case of the isotropic double harmonic oscillator \\\n(\\(B=D=0\\)) with \\(N=3\\), the Hamiltonian is given by\n\\[\nH=\n\\begin{pmatrix}\n  0 & 0 & 0 & 0 & 0 & 0\\\\\n  0 & 1 & 0 & 0 & 0 & 0\\\\\n  0 & 0 & 2 & 0 & 0 & 0\\\\\n  0 & 0 & 0 & 1 & 0 & 0\\\\\n  0 & 0 & 0 & 0 & 2 & 0\\\\\n  0 & 0 & 0 & 0 & 0 & 2\\\\\n\\end{pmatrix}\n\\]\nThe eigenvalues will be \\(E_i = 0, 1, 1, 2, 2, 2\\) with the corresponding\neigenvectors\n\\[\n  v_1 =\n  \\begin{pmatrix}\n    1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n  \\end{pmatrix},\\\n  v_{2} =\n  \\begin{pmatrix}\n    0 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n  \\end{pmatrix},\\\n  v_{3} =\n  \\begin{pmatrix}\n    0 \\\\ 0 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 0\n  \\end{pmatrix},\\\n  v_{4} =\n  \\begin{pmatrix}\n    0 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0\n  \\end{pmatrix},\\\n  v_{5} =\n  \\begin{pmatrix}\n    0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 1\n  \\end{pmatrix},\\\n  v_{6} =\n  \\begin{pmatrix}\n    0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 1 \\\\ 0\n  \\end{pmatrix}\n\\]\n\nSince the basis is given by\n\\[\n  \\ket{0, 0} \\ket{0, 1} \\ket{0, 2} \\ket{1, 0} \\ket{1, 1} \\ket{2, 0},\n\\]\nthe quantum numbers for the eigenvectors will be assigned as follows\n\\begin{align*}\n  v_1 &\\equiv \\ket{0, 0} \\text{since}\\ k = 1 \\\\\n  v_2 &\\equiv \\ket{0, 1} \\text{since}\\ k = 2 \\\\\n  v_3 &\\equiv \\ket{1, 0} \\text{since}\\ k = 4 \\\\\n  v_4 &\\equiv \\ket{0, 2} \\text{since}\\ k = 3 \\\\\n  v_5 &\\equiv \\ket{2, 0} \\text{since}\\ k = 6 \\\\\n  v_6 &\\equiv \\ket{1, 1} \\text{since}\\ k = 5\n\\end{align*}\n\n% {\\color{red} Maximum is not unique? \\\\ \\centerline{\\dots}}\n\nIn figures~\\ref{fig:bar-rep-b0.2n120} and~\\ref{fig:hist-rep-b0.2n120},\nrespectively~\\ref{fig:bar-rep-b0.63n260} and~\\ref{fig:hist-rep-b0.63n260}\nwe can see the relative spacing for each irreducible representation as a function\nof index and as a histogram for \\(B=0.2\\) and \\(B=0.63\\).\nOnce the problem of selection of the states corresponding to a given\nirreducible representation was solved, we calculated the average spacing for\ndifferent values of $B$ (see~\\cref{fig:avgsp}).\n\n% B=0.2 N=120\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/bar_rebde\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/bar_reuna\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/bar_reuns\"}\n  \\end{subfigure}\n  \\caption{The relative spacing for each irreducible representation as a function\n  of index for \\(B=0.2, D=0.4, N=260\\)}\n  \\label{fig:bar-rep-b0.2n120}  % chktex 24\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/rebde\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/reuna\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.2 D0.4 N260/reuns\"}\n  \\end{subfigure}\n  \\caption{The relative spacing histogram for each irreducible representation for\n  \\(B=0.2, D=0.4, N=260\\)}\n\\label{fig:hist-rep-b0.2n120}\n\\end{figure}\n\n% B=0.63 N=260\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/bar_rebde\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/bar_reuna\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/bar_reuns\"}\n  \\end{subfigure}\n  \\caption{The relative spacing for each irreducible representation as a function\n  of index for \\(B=0.63, D=0.4, N=260\\)}\n  \\label{fig:bar-rep-b0.63n260}  % chktex 24\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/rebde\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/reuna\"}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.49\\textwidth}\n    \\centering\n    \\includegraphics{\"B0.63 D0.4 N260/reuns\"}\n  \\end{subfigure}\n  \\caption{The relative spacing histogram for each irreducible representation for\n  \\(B=0.63, D=0.4, N=260\\)}\n\\label{fig:hist-rep-b0.63n260}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics{\"avg_sp_N[220, 240, 260]\"}\n  \\caption{\\(\\mean{\\Delta E}\\) as a function of $B$ for each representation}\n\\label{fig:avgsp}\n\\end{figure}\n\n% {\\color{red} Selection problems?}\n\n\\FloatBarrier\n\n\\subsection{Nearest neighbour distributions}\n\nHaving separated the states with respect irreducible representations we can also build\nthe nearest neighbour distributions. These histograms show the probability\nof having a given spacing between consecutive levels as a function of $s$.\n\n\\Cref{fig:P(s)-b0.2n120,fig:I(s)-b0.2n120,fig:P(s)-b0.63n260,fig:I(s)-b0.63n260}\nshow the nearest spacing distributions \\(P(s)\\) and the cumulative\ndistributions \\(I(s)\\) for \\(B=0.2\\) and \\(B=0.63\\).\n\nTaking into account the Berry-Tabor and Bohigas-Gianoni-Schmit conjectures,\nwe compare \\(P(s)\\) with the Poisson distribution \\(P_P(s) = \\ee^{-s}\\)\nand the Wigner distribution \\(P_W(s) = \\frac{\\pi}{2} s \\exp(-\\frac{\\pi}{4}s^2)\\).\n\nSince \\(P(s)\\) is a histogram, for an easier comparisom, we also computed the\nhistograms associated with the two distributions for the same spacing.\n\n\\begin{figure}[h]\n  \\includegraphics{\"B0.2 D0.4 N260/P(s)_st_1e-09_eps_1e-08\"}  % chktex 36\n  \\caption{\\(B=0.2, D=0.4, N=120\\)}\n\\label{fig:P(s)-b0.2n120}\n\\end{figure}\n\n\\begin{figure}\n  \\includegraphics{\"B0.2 D0.4 N260/I(s)\"}  % chktex 36\n  \\caption{\\(B=0.2, D=0.4, N=120\\)}\n\\label{fig:I(s)-b0.2n120}\n\\end{figure}\n\n\\begin{figure}\n  \\includegraphics{\"B0.63 D0.4 N260/P(s)_st_1e-09_eps_1e-08\"}  % chktex 36\n  \\caption{\\(B=0.63, D=0.4, N=260\\)}\n\\label{fig:P(s)-b0.63n260}\n\\end{figure}\n\n\\begin{figure}\n  \\includegraphics{\"B0.63 D0.4 N260/I(s)\"}  % chktex 36\n  \\caption{\\(B=0.63, D=0.4, N=260\\)}\n\\label{fig:I(s)-b0.63n260}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "963107c8c086cebd660dbf76a14b17c83c0b8aec", "size": 17934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manuscript/Procedure/procedure.tex", "max_stars_repo_name": "SebastianM-C/Bachelor-Thesis", "max_stars_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-19T23:15:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-19T23:15:42.000Z", "max_issues_repo_path": "Manuscript/Procedure/procedure.tex", "max_issues_repo_name": "SebastianM-C/Bachelor-Thesis", "max_issues_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_issues_repo_licenses": ["MIT"], "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/Procedure/procedure.tex", "max_forks_repo_name": "SebastianM-C/Bachelor-Thesis", "max_forks_repo_head_hexsha": "30ced37a8638e71ff5fc53d2dd4b608f0f9f8d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-19T23:15:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-19T23:15:46.000Z", "avg_line_length": 37.3625, "max_line_length": 102, "alphanum_fraction": 0.6862384298, "num_tokens": 6191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6331440596308812}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrrpmh}\n\\section*{\\hspace*{-1.6cm} tfrrpmh}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nReassigned pseudo Margenau-Hill time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,rtfr,hat] = tfrrpmh(x) \n[tfr,rtfr,hat] = tfrrpmh(x,t) \n[tfr,rtfr,hat] = tfrrpmh(x,t,N) \n[tfr,rtfr,hat] = tfrrpmh(x,t,N,h) \n[tfr,rtfr,hat] = tfrrpmh(x,t,N,h,trace) \n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrrpmh} computes the pseudo Margenau-Hill distribution and\n        its reassigned version. The reassigned pseudo-MHD is given by the\n        following expression\\,:\n\\begin{eqnarray*}\n\\hspace*{-1cm}PMH_x^{(r)}(t',\\nu';h)=\\int_{-\\infty}^{+\\infty}\n\\int_{-\\infty}^{+\\infty} PMH_x(t,\\nu;h)\\ \\delta(t'-\\hat{t}(x;t,\\nu))\\\n\\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\ dt\\ d\\nu,\n\\end{eqnarray*}\nwhere \n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu)=t\\ \\ \\mbox{ and }\\ \\ \n\\hat{\\nu}(x;t,\\nu)=\\nu+\\Im\\left\\{\\dfrac{F_x(t,\\nu;\\ens{D}_h)\\ F_x^*(t,\\nu;h)}\n{2\\pi|F_x(t,\\nu;h)|^2}\\right\\}.    \n\\end{eqnarray*}\n$\\ens{D}_h(t)=\\frac{dh}{dt}(t)$ and $F_x(t,\\nu;h)$ is the short-time\nFourier transform of $x(t)$ with analysis window $h(t)$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)})\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty h}     & frequency smoothing window, {\\ty h(0)} being forced to {\\ty 1}\n                                         & {\\ty window(odd(N/4))}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr, rtfr} & time-frequency representation and its reassigned\n            version\\\\\n        {\\ty hat}   & complex matrix of the reassignment vectors\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrrpmh} runs {\\ty tfrqview}.\n\\end{minipage}\n\n%\\newpage\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4); \n         h=window(17,'Kaiser'); \n         tfrrpmh(sig,1:128,64,h,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and\nTime-Scale Representations by the Reassignment Method'' IEEE Transactions\non Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.\n\\end{minipage}\n\n", "meta": {"hexsha": "26b29fa8554800475e32332b55396b219005fd9d", "size": 3025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrrpmh.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrrpmh.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrrpmh.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 30.25, "max_line_length": 84, "alphanum_fraction": 0.6095867769, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6331440512503004}}
{"text": "\\documentclass{article}\n\n\\usepackage{isomath}\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#10 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\textbf{Disclaimer.} This is the reasoning I used to solve the problem; it\nmay be wrong though. This is intended just as food for thought.\n\n\\section{Perceptron Learning Algorithm as SGD}\n\nThis question presents to us a few error functions $e_n(\\mathbf{w})$ and asks\nwhich one can be used in order to implement the Perceptron Learning Algorithm\n(PLA) using Stochastic Gradient Descent (SGD).\n\n\\subsection{Similarities Between PLA And SGD}\n\nThe PLA is stochastic much like SGD in the sense that we randomly pick one\nexample at a time and adjust the weight vector $\\mathbf{w}$ a little bit towards\nthe minimum; the main difference is that, in PLA, we only pick misclassified\npoints, where in SGD the error function is evaluated on all $N$ points of the\ntraining set.\n\nThis observation alone is enough to eliminate all possible options but this one:\n\n\\begin{equation*}\n  e_n(\\mathbf{w}) = -min(0, y_n\\mathbf{w}^\\mathsf{T} \\mathbf{x}_n)\n\\end{equation*}\n\n\\subsection{Intuition}\n\nIn the context of the Gradient Descent algorithm, the signal\n$\\mathbf{w}^\\mathsf{T}\\mathbf{x}_n$ translates to a probability distribution\nthat describes how a given example $\\mathbf{x}_n$ will be classified; a largely\npositive signal means $P(y_n=1 | \\mathbf{x}_n) \\approx 1$, as a largely negative\nsignal means $P(y_n=1 | \\mathbf{x}_n) \\approx 0$ , thanks to the logistic\nfunction $\\theta$.\n\nIn this particular error measure, the signal $\\mathbf{w}^\\mathsf{T}\\mathbf{x}_n$\nis multiplied by the target label $y_n$. If both the signal and the target\nlabel agrees on the sign, i.e. both positive or negative, this means that the\nsignal classifies that example correctly, thus the result of this product is\nsome number $s \\geq 0$ which will be killed by $min(0, s)$.\n\nThis trick is used so that only the gradient of misclassified examples are\nallowed to contribute with changes in the weight vector $\\mathbf{w}$,\nwhich is exactly what PLA does.\n\n\\end{document}\n", "meta": {"hexsha": "b96abe0f380e089870275dfa48060a6f77247754", "size": 2129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q10.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/q10.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/q10.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": 37.350877193, "max_line_length": 80, "alphanum_fraction": 0.7651479568, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6331247248138049}}
{"text": "\\subsection{Method of Undetermined Coefficients}\r\n\\noindent\r\nThe type of equation we're trying to solve is a heterogeneous linear ODE with constant coefficients. These have the form\r\n\\begin{equation*}\r\n\ta_ny^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_1y' + a_0y = b(x)\r\n\\end{equation*}\r\nWe will assume that the solution has the form $y = y_h + y_p$, where $y_h$ is the general solution to the homogeneous equation ($b(x) = 0$), and $y_p$ is the particular solution.\\\\\r\n\r\n\\noindent\r\nWe know how to solve for $y_h$ exactly without guessing. However, we will make a guess for the form of $y_p$ based on the form of $b(x)$ and the form of $y_h$ using the rules described in the below examples. For each term in our guess for $y_p$, we will solve for a constant.\\\\\r\n\r\n\\ifodd\\includeHigherOrderExamples\\input{./higherOrder/nonHomeg/undeterminedCoeffs_examples.tex}\\fi", "meta": {"hexsha": "c83bba81d087e4f7e86566354726326b1a9caafc", "size": 856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/undeterminedCoeffs.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/nonHomeg/undeterminedCoeffs.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/nonHomeg/undeterminedCoeffs.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": 71.3333333333, "max_line_length": 278, "alphanum_fraction": 0.7336448598, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6331247155012252}}
{"text": "\\subsection{Comptonization of the CMB}\n\nIf we define the planck spectrum to be\n\n\\begin{equation}\nI(x) = {{2(k_B T)^3}\\over{(hc)^2}}{{x^3}\\over{e^x - 1}} = i_0\\,i(x), \n\\end{equation}\n\nthen change in intensity due to inverse-Compton scattering of a\nblackbody distribution of photons by an isotropic distribution of\nelectrons is given in the optically thin limit ($\\tau \\ll 1$) by:\n\n\\begin{equation}\n\\Delta i(x) \\equiv {\\Delta I(x)\\over{i_0}} = \\left\\{j(x) - i(x)\\right\\}\\tau\n\\label{eq:deltai}\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n\\tau = \\sigma_T\\integral{}{}{n_e}{\\ell},\n\\end{equation}\n\nis the optical depth, $i(x)\\tau$ is the flux scattered to other frequencies and\n$j(x)\\tau$ is the flux scattered from other frequencies to $x =\nh\\nu/(kT)$. \n\nIt is useful to rewrite Eq.~\\ref{eq:deltai} as\n\n\\begin{equation}\n\\Delta i(x) = \\tilde{g}(x)\\,\\tilde{y},\n\\end{equation}\n\nwhere\n\n\\begin{eqnarray}\\nonumber\n\\tilde{y} &=& {{\\sigma_T}\\over{m_e c^2}}\\integral{}{}{n_e k_B \\tilde{T}_e}{\\ell}\\\\\\nonumber\n\\end{eqnarray}\n\nand $\\tilde{T}_e$ is defined by \n\n\\begin{equation}\nk_B\\tilde{T}_e = {{P_e}\\over{n_e}}\n\\end{equation}\n\n(in the case of a thermal distribution of electrons, $\\tilde{T}_e \\equiv T_e$).  Defining \n\n\\begin{equation}\n\\left<k_B\\tilde{T}_e\\right> = {{\\integral{}{}{n_ek_B\\tilde{T}_e}{\\ell}}\\over{\\integral{}{}{n_e}{\\ell}}}\n\\end{equation}\n\nwe have\n\n\\begin{equation}\n\\tilde{g}(x) = \\left\\{j(x) - i(x)\\right\\}{{m_e c^2}\\over{\\left<k_B\\tilde{T}_e\\right>}}\n\\label{eq:ggen}\n\\end{equation}\n\nFor a thermal distribution of electrons, $\\left<k_B\\tilde{T}_e\\right>\n\\equiv k_B T_e$, and in the non-relativistic regime, we have\n\n\\begin{equation}\n\\tilde{g}(x) = {{x^4e^x}\\over{(e^x-1)^2}}\\left(x{{e^x+1}\\over{e^x-1}} - 4\\right) {{m_e c^2}\\over{k_B T_e}},\n\\label{eq:komp}\n\\end{equation}\n\ni.e., the standard non-relativistic solution to the Kompaneets\nequation.  To make contact with Eq.~\\ref{eq:ynu}, we can identify the\nfrequency dependence of the SZ temperature decrement in the\nnon-relativistic case as the central term of Eq.~\\ref{eq:komp}:\n\n\\begin{equation}\nf(x) = x{{e^x+1}\\over{e^x-1}} - 4.\n\\label{eq:fnu}\n\\end{equation}\n\nIn general, though, for an arbitrary electron momentum\ndistribution $f_e(p)$, we have:\n\n\\begin{equation}\n\\left<k_B\\tilde{T}_e\\right> = \\integral{0}{\\infty}{f_e(p) {1\\over{3}}pv(p)m_e c}{p},\n\\end{equation}\n\nwhere $p = \\beta_e\\gamma_e$ is the normalized electron momentum. The\nscattered spectrum is now given by\n\n\\begin{equation}\nj(x) = \\integral{0}{\\infty}{P(t)i(x/t)}{t},\n\\end{equation}\n\nwhere $P(t)$ is the probability that a photon is scattered to a\nfrequency $t = \\nu^\\prime/\\nu$ times its original frequency.  The\nphoton redistribution function can be written as\n\n\\begin{equation}\nP(t) = \\integral{0}{\\infty}{f_e(p)P(t;p)}{p},\n\\end{equation}\n\nwhere $P(t;p)$ is the redistribution function for a mono-energetic\nelectron distribution, which in the Thomson regime ($h\\nu \\ll \\gamma_e\nm_e c^2$) has an analytic solution\n\n\\begin{eqnarray}\\nonumber\nP(t;p) = &-& {{3|1-t|}\\over{32p^6t}} [1 + (10 + 8p^2 + 4p^4)t + t^2]\\\\\\nonumber\n         &+& {{3(1+t)}\\over{8p^5}}\\left[{{3+3p^2 + p^4}\\over{\\sqrt{1+p^2}}} - {{3+2p^2}\\over{2p}}(2{\\rm\\,arcsinh(p)} - \\left|\\ln{t}\\right|)\\right],\n\\end{eqnarray}\n\nwhere $P(t;p) = 0$ for $|\\ln{t}| > 2{\\,\\rm arcsinh(p)}$.\n\n\\begin{figure}[th]\n\\begin{center}\n\\includegraphics[scale=0.3]{figures/gx.png}\\\\\n\\end{center}\n\\caption{Comparison of the non-relativistic $\\Delta I(x)$ computed with Eq.~\\ref{eq:komp} (green) with the correct relativistic calculation using Eq.~\\ref{eq:ggen}, for $T_e = 10, 20, 30~$keV.}\n\\label{fig:gx}\n\\end{figure}\n\n", "meta": {"hexsha": "79be4a2cbc7fe51bd6b6ef41c1a4f61e0ce17c93", "size": 3578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/comptonization.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/comptonization.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/comptonization.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": 30.3220338983, "max_line_length": 193, "alphanum_fraction": 0.6743991056, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6331247125694556}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage[\\graphtype]{mfpic}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\opengraphsfile{pl11-05}\n\\hyphenation{DSFITC KORDER DSDIF DSBASD}\n\\begmath 11.5 Least-Squares Data Fitting using $K^{th}$ Order Splines\n\\hbox{with Constraints}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis package contains two subprograms, DSFIT and DSFITC, for fitting a {\\em\npolynomial spline function} to discrete data. A {\\em polynomial spline function}\nis a piecewise polynomial function having specified orders of continuity at the\nabscissae, called {\\em internal knots}, at which one polynomial piece ends and\nanother begins. Spline functions have been found to be very useful in many\ncomputational processes due to their capability of representing a wide\nvariety of shapes in a controlled way.\n\nDSFIT can be used either for a weighted least-squares fit or for\ninterpolation. DSFITC adds capabilities for the user to specify constraints\non the fit in the form of equality or inequality conditions on the value or\nderivative (of specified order), of the spline function at specified points,\nor the integral of the spline function over a specified interval. These\nconstraints can be used, for example, to assure monotonicity or convexity of\nthe fitted spline function over specified intervals. Figure~1 illustrates a\nmonotone nondecreasing least-squares spline fit to data computed using\nDSFITC.\\vspace{10pt}\n\\vspace{10pt}\n\n\\mbox{\\input pl11-05a }\n\n\\centerline{\\bf Figure 1: Constrained spline fit to data.\\rule[-8pt]{0pt}{8pt}}\n\nThe fitting subprograms return coefficients of a spline function relative\nto {\\em B-spline basis functions} using the parameterization conventions\ngiven by Carl de Boor in \\cite{deBoor:1978:APG}.  In this approach the\nspline function will be of a user-specified order, $K$, which means the\npolynomial pieces are of degree at most $K-1$.  By default the continuity\nat knots will be of order K $-$ 2, however the user can specify a lower\norder of continuity at selected internal knots to allow the curve to\nchange direction more sharply.\n\nSubprogram DSVAL can be used to evaluate a spline function represented\nrelative to the B-spline basis or any of its derivatives, at a specified\npoint, and subprogram DSQUAD can be used to evaluate the definite integral\nof the function between specified limits.\n\nThe B-spline representation has the desirable property that usual continuity\nconditions at knots are ``built-in\". This keeps down the number of\ncoefficients that must be determined in interpolation or least-squares\nfitting. A disadvantage is that evaluation of a function represented in the\nB-spline representation is more expensive than is the use of an alternative\nrepresentation using the {\\em power} basis.\n\nIf one is going to do a large number of evaluations of a spline function one\nmay choose to convert the representation of the spline function from the\nB-spline basis to the power basis to allow for more efficient evaluation.\nSubprogram DSTOP can be used to do this conversion. Then DPVAL can be used\nto evaluate the function or any of its derivatives at a specified point, and\nDPQUAD can be used to evaluate the definite integral of the function between\nspecified limits.\n\n\\subsection{Usage}\n\nDescribed below in Section B.1 to B.8, are:\n\n\\begin{tabular*}{3.3in}{ll}\nB.1 & Usage of DSFIT for fitting without\\\\\n & constraints \\dotfill \\pageref {dsfit}\\\\\nB.2 &  Usage of DSFITC for fitting with\\\\\n & constraints \\dotfill \\pageref {dsfitc}\\\\\nB.3 & Usage of DSVAL for evaluation using\\\\\n & the B-spline basis \\dotfill \\pageref{dsval}\\\\\nB.4 & Usage of DSQUAD for integration\\\\\n & using the B-spline basis \\dotfill \\pageref{dsquad}\\\\\nB.5 & Usage of DSTOP to convert from the\\\\\n & B-spline basis to the power basis \\dotfill \\pageref{dsquad}\\\\\nB.6 & Usage of DPVAL for evaluation using\\\\\n & the power basis \\dotfill \\pageref{dpval}\\\\\nB.7 & Usage of DPQUAD for integration using\\quad \\quad ~\\\\\n & the power basis \\dotfill \\pageref{dpquad}\\\\\nB.8 & Modifications for Single Precision \\dotfill \\pageref{modsp}\n\\end{tabular*}\n\\subsubsection{Usage of DSFIT for fitting without constraints\\label{dsfit}}\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NXY, KORDER, NCOEF, LDW, IERR1}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf BCOEF}($\\geq $NCOEF){\\bf ,\\\\ X}($\\geq $NXY)%\n{\\bf , Y}($\\geq $NXY){\\bf , SD}($\\geq $NXY){\\bf ,\\\\ TKNOTS}($\\geq $%\nNCOEF+KORDER){\\bf ,\\\\\nW}(LDW, $\\geq $KORDER+1){\\bf , SIGFAC}\n\\end{description}\nAssign values to X(), Y(), SD(), NXY, KORDER, NCOEF, TKNOTS(), and LDW.\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL DSFIT(X, Y, SD, NXY, KORDER,\\\\\nNCOEF, TKNOTS, BCOEF, SIGFAC,\\\\\nIERR1, LDW, W)\n\\end{tabular}}\n\\end{center}\nResults are returned in BCOEF(), SIGFAC, and IERR1. Following\nuse of DSFIT, the user may use DSVAL to compute values or specified\nderivatives of the fitted curve, DSQUAD to compute the definite integral of\nthe fitted curve over a specified interval, or DSTOP to convert the\nrepresentation to the power basis.\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[X(), Y()]  \\ [in] Data pairs (X$(i)$, Y($i)$, $i=1$, ..., NXY). Must\nbe ordered so the X($i)$'s are either nondecreasing or\nnonincreasing.\n\n\\item[SD()]  \\ [in] If SD($1)>0.$, each SD($i$) must be positive and must be\nthe user's a priori estimate of the standard deviation of the uncertainty $%\n(e.g.$, observational error) in the corresponding data value Y($i).$\n\nIf SD($1)<0.$, $|\\text{SD}(1)|$ will be used as the a priori standard\ndeviation of each data value Y(I). In this case the array SD() may be\ndimensioned as SD(1).\n\nAn error condition is reported if SD(1) = 0 or if SD(1) $>$ 0 and\nSD($i) \\leq 0$ for $1 < i \\leq \\text{NXY}.$\n\n\\item[NXY]  \\ [in] Number of data points. Require NXY $\\geq \\max ($NCOEF,\nKORDER).\n\n\\item[KORDER]  \\ [in] Order of the spline function. Each polynomial piece\nwill be of degree at most KORDER $-$ 1. The default order of continuity at\neach internal knot will be KORDER $-$ 2. The popular case of a cubic spline\nwith $C^2$ continuity at the knots is selected by setting KORDER = 4.\nRequire KORDER $\\geq 1$. Internal arrays in this package impose an upper\nlimit of $kmax=20$ on KORDER.\n\n\\item[NCOEF]  \\ [in] Number of terms in the sum representing the spline\nfunction. Require NCOEF $\\leq $ NXY.\n\n\\item[TKNOTS()]  \\ [in] The knots, $t_i$, $i=1$, ..., NCOEF + KORDER. The\ninterval $[t_{\\text{KORDER}}$, $t_{\\text{NCOEF}+1}]$ will be the {\\em proper\ninterpolation interval} for the problem. This interval should contain all the\nX($j)$ values, so it is reasonable to set $t_{\\text{KORDER}}\\leq \\min ($%\nX(1), X(NXY)) and $t_{\\text{NCOEF}+1}\\geq \\max ($X(1), X(NXY)). It is\nconvenient and reasonable to set the KORDER $-$ 1 knots with indices less\nthan KORDER equal to $t_{\\text{KORDER}}$, and the KORDER $-$ 1 knots with\nindices greater than NCOEF + 1 equal to $t_{\\text{NCOEF}+1}.$\n\nKnots indexed from KORDER + 1 through NCOEF are {\\em internal} knots. Internal\nknots specify abscissae at which one polynomial piece ends and the next\nbegins. Successively indexed internal knots may have the same value. A knot\nappearing with multiplicity $\\mu $ means the order of continuity of the\nspline at this knot will be at least $\\text{KORDER}-\\mu - 1$. Require $1\\leq\n\\mu \\leq $ KORDER.\n\nRequire $t_i\\leq t_{i+1}$ for $i=1$, ..., NCOEF + KORDER $-$ 1; $t_i<t_{i+%\n\\text{KORDER}}$ for $i=1$, ..., NCOEF; $t_{\\text{KORDER}}<t_{\\text{KORDER}%\n+1} $; and $t_{\\text{NCOEF}}<t_{\\text{NCOEF}+1}$. See Sections C and D for\nfurther discussion of knot placement.\n\n\\item[BCOEF()]  \\ [out] Coefficients $c_i$, $i=1$, NCOEF, in the sum\nrepresenting the spline function as a sum of coefficients times B-spline\nbasis functions.\n\n\\item[SIGFAC]  \\ [out] Set by the subroutine as a measure of the residual\nerror of the fit. The subroutine sets%\n\\begin{align*}\n\\text{SIGFAC}&=\\frac{\\text{RNORM}}{\\text{DOF}^{1/2}},\\quad \\text{where}\\\\\n\\text{RNORM}&=\\left[ \\sum_{i=1}^{\\text{NXY}}\\left(\\frac{\\text{yfit}_i-\\text{Y}_i}\n{\\text{SD}_i}\\right) ^2\\right] ^{1/2},\\quad \\text{and}\\\\\n\\text{DOF}&=\\max (1,\\text{NXY}-\\text{NCOEF}).\n\\end{align*}\nHere $\\text{SD}_i$ denotes SD($i$) if SD($1)>0$, and $|\\text{SD}(1)|$ otherwise.\n\n\\item[IERR1]  \\ [out] Error status indicator. Set on the basis of tests done\nin DSFIT as well as error indicators IERR2 set by DBACC and IERR3 set by\nDBSOL, both in Chapter~4.5. IERR1 is set as follows:\n\n{\\bf IERR1} \\hspace{.4in} {\\bf Meaning}\\vspace{-6pt}\n\\begin{description}\n\\item[\\rm \\phantom{100}0] \\ No errors detected.\n\\item[\\rm \\phantom{1}100] \\  NCOEF $<1$ or NCOEF $>$ NXY\n\\item[\\rm \\phantom{1}150] \\  KORDER $>kmax$ (= 20)\n\\item[\\rm \\phantom{1}200] \\  TKNOTS($i$) $>$ TKNOTS($i$+1)\n\\item[\\rm \\phantom{1}250] \\  TKNOTS($i)\\geq $TKNOTS($i$+KORDER)\n\\item[\\rm \\phantom{1}300] \\  LDW $<$ NCOEF + 2\n\\item[\\rm \\phantom{1}400] \\  The X($i)$'s are neither nondecreasing nor\nnonincreasing.\n\\item[\\rm \\phantom{1}600] \\  LDW $<$ NCOEF + 2.\n\\item[\\rm \\phantom{1}700+IERR2] \\ DBACC set IERR2 $\\neq 0$\n\\item[\\rm \\phantom{1}800+IERR2] \\ DBACC set IERR2 $\\neq 0$\n\\item[\\rm \\phantom{1}900+IERR2] \\ DBACC set IERR2 $\\neq 0$\n\\item[\\rm 1000+IERR3] \\ DBSOL set IERR3 $\\neq 0$. Indicates singularity.\n\\item[\\rm 1100] \\  SD(1) = 0.0\n\\item[\\rm 1200] \\  SD(1) $>$ 0.0, and SD($i) \\leq 0.0$ for some $i \\in $ {[2,\nNXY]}.\n\\end{description}\n\\item[LDW]  \\ [in] Leading dimension for the work array W(). Require LDW $%\n\\geq \\text{NCOEF}+2$. Let $\\alpha $ denote the maximum number of data\nabscissae, X($i)$, in any one knot interval, $i.e$. between TKNOTS$(j)$ and\nTKNOTS$(j+1)$ for some $j$. The subroutine will be more efficient if LDW is\nat least $\\text{NCOEF}+1+\\alpha .$\n\n\\item[W(,)]  \\ [scratch] Working space, dimensioned W(LDW, $\\geq $KORDER+1).\n\\end{description}\n\\subsubsection{Usage of DSFITC for fitting with constraints\\label{dsfitc}}\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf KORDER, NCOEF, ISET}(3){\\bf ,\\\\ INFO}({\\em ninfo})\n\n\\item[DOUBLE PRECISION]  \\ {\\bf X}({\\em mdim}){\\bf , Y}({\\em mdim}){\\bf ,\\\\ SD}($%\nmdim $){\\bf , TKNOTS}($\\geq $NCOEF+KORDER){\\bf ,\\\\ BCOEF}($\\geq $NCOEF){\\bf %\n, RNORM, W}({\\em nwork})\n\n\\item[CHARACTER*4]  \\ {\\bf CCODE}({\\em mdim})\n\\end{description}\nThe dimension {\\em mdim} must be large enough to provide for specification of\nall constraint and least-squares equations as described below in the\ndescription of CCODE(). See ISET() for the specifications of {\\em ninfo} and $%\nnwork $.\n\nAssign values to CCODE(), X(), Y(), SD(), KORDER, NCOEF, TKNOTS(), and\nISET().\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL DSFITC(CCODE, X, Y, SD,\\\\\nKORDER, NCOEF, TKNOTS, BCOEF,\\\\\nRNORM, ISET, INFO, W)\n\\end{tabular}}\n\\end{center}\nComputed quantities are returned in BCOEF(), RNORM, and INFO(). Following\nuse of DSFITC, the user may use DSVAL to compute values or specified\nderivatives of the fitted curve, DSQUAD to compute the definite integral of\nthe fitted curve over a specified interval, or DSTOP to convert the\nrepresentation to the power basis.\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[CCODE()]  \\ [in] CCODE(i), or in some cases CCODE(i) and\nCCODE$(i+1)$ together, give specifications for one constraint equation or\none least-squares equation. CCODE(i) is regarded as consisting of four\nsingle-character fields.\n\\begin{description}\n\\item[\\rm CCODE$(i$)(1:1) =]  $kind_i=$ $^{\\prime}$1$^{\\prime}$, $%\n^{\\prime}$2$^{\\prime}$, $^{\\prime}$3$^{\\prime}$, $^{\\prime}$4$^{\\prime}$.\n\n\\item[\\rm CCODE$(i$)(2:2) =]  $deriv_i=$ $^{\\prime}$0$^{\\prime}$, $%\n^{\\prime}$1$^{\\prime}$, ..., $^{\\prime}$9$^{\\prime}$.\n\n\\item[\\rm CCODE$(i$)(3:3) =]  $relop_i=$ $^{\\prime}${$\\sim $}$^{\\prime}$, $%\n^{\\prime }$=$^{\\prime }$, $%\n^{\\prime }${$<$}$^{\\prime }$, $^{\\prime }${$>$}$^{\\prime }.$\n\n\\item[\\rm CCODE$(i$)(4:4) =]  $active_i=$ $^{\\prime}$A$^{\\prime}$, $%\n^{\\prime }$N$^{\\prime }$, $^{\\prime}$!$^{\\prime}$.\n\\end{description}\nWhere alphabetic characters are shown, the corresponding lower case\ncharacter is also acceptable.\n\\begin{description}\n\\item[\\rm $active_i =\\,^{\\prime}$!$^{\\prime}$]  signals the end of information\nin this array. The user must provide this termination signal. The other\nfields in this array element will be ignored. $active_i=\\,^{\\prime }$A$^{\\prime\n} $ means CCODE(i) is active so CCODE(i) will be processed. $%\nactive_i=\\,^{\\prime }$N$^{\\prime }$ means CCODE(i) is inactive so processing\nwill advance to CCODE$(i+1)$. To activate or inactivate a pair [CCODE(i),\nCCODE$(i+1)]$ in which $kind_i=3$ or 4, place the same\ncode $^{\\prime }$A$^{\\prime}$ or $^{\\prime }$N$^{\\prime }$ in\nboth $active_i$ and $active_{i+1}.$\n\n\\item[\\rm $relop_i =$ $^{\\prime}{=}^{\\prime}$, $^{\\prime}{<}^{\\prime}$,\nor $^{\\prime}{>}^{\\prime}$]  denotes a constraint equation\nwith $^{\\prime }{=}^{\\prime }$ meaning equal\nto, $^{\\prime }{<}^{\\prime }$ meaning less than or equal to, and $^{\\prime\n}{>}^{\\prime }$ meaning greater than or equal to. $relop_i=$ $^{\\prime\n}{\\sim }^{\\prime }$ denotes a least-squares equation. For a least-squares\nequation the value SD($i$) (or $|\\text{SD}(1)|$) will be used as the a\npriori standard deviation.\n\n\\item[\\rm $kind_i = 1$]  specifies an equation of the form\n\\begin{equation*}\nf^{(di)}(\\text{X}(i))\\ relop_i\\ \\text{Y}(i)\n\\end{equation*}\nwhere $f^{(di)}$ denotes the derivative of order $deriv_i$ of the spline\nfunction to be determined. The zero$^{th}$ order derivative is the function\nitself.\n\n\\item[\\rm $kind_i = 2$]  specifies an equation of the form\n\\begin{equation*}\nf^{(di)}(\\text{X}(i))-f^{(di)}(\\text{Y}(i))\\ relop_i0\n\\end{equation*}\nNote that Y($i)$ is an independent variable value in this case.\n\n\\item[\\rm $kind_i = 3$]  uses items indexed by both $i$ and $i+1$ and\nspecifies an equation of the form\n\\begin{equation*}\n\\hspace{-36pt}f^{(di)}(\\text{X}(i))-\\text{Y}(i+1)\\times f^{(di+1)}\n(\\text{X}(i+1))\\ relop_i \\text{Y}(i)\n\\end{equation*}\nwhere $f^{(di+1)}$ denotes the derivative of order $deriv_{i+1}$ of the\nspline function to be determined.\n\n\\item[\\rm $kind_i = 4$]  uses items indexed by both $i$ and $i+1$ and\nspecifies an equation of the form\n\\begin{equation*}\n\\int_{\\text{X}(i)}^{\\text{X}(i+1)}f(x)\\,dx\\quad relop_i\\text{ Y}(i)\n\\end{equation*}\n\\end{description}\nSee Section C for discussion of expected applications of these different\nequation forms.\n\n\\item[X(), Y()]  \\ [in] Data for use in building constraint or fitting\nequations as specified by the contents of CCODE().\n\n\\item[SD()]  \\ [in] SD($i$) specifies the a priori standard deviation of the\nerror in the equation specified by CCODE(i) when $relop_i=$ $^{\\prime\n}{\\sim }^{\\prime }$. The weighted fitting algorithm will take account of these\nSD($i$) values. Optionally, the user may set SD(1) to a negative value. Then\nthis subroutine will use $|\\text{SD}(1)|$ as the standard deviation for the\nright-side value in each fitting equation. In this latter case the SD()\narray can be dimensioned SD(1). Note that a negative value in SD(1) will\nalways be interpreted in this way regardless of the contents of CCODE(1). An\nerror condition is reported if SD(1) = 0 or if SD(1) $>$ 0 and\nSD($i) \\leq 0$ for $1 < i \\leq \\text{NXY}.$\n\n\\item[KORDER]  \\ [in] Order of the spline function. Each polynomial piece\nwill be of degree at most KORDER $-$ 1. The default order of continuity at\neach internal knot will be KORDER $-$ 2. The popular case of a cubic spline\nwith $C^2$ continuity at the knots is selected by setting KORDER = 4.\nRequire KORDER $\\geq 1$. Internal arrays in this package impose an upper\nlimit of {\\em kmax} = 20 on KORDER.\n\n\\item[NCOEF]  \\ [in] Number of terms in the sum representing the spline\nfunction.\n\n\\item[TKNOTS()]  \\ [in] The knots, $t_i$, $i=1$, ..., NCOEF + KORDER. The\ninterval $[t_{\\text{KORDER}}$, $t_{\\text{NCOEF}+1}]$ will be the {\\em proper\ninterpolation interval} for the problem. This interval should contain all the\nabscissa values occurring in the least-squares and constraint equations, so\nit is reasonable to set $t_{\\text{KORDER}}$ less than or equal to the\nminimum of these abscissae and $t_{\\text{NCOEF}+1}$ greater than or equal to\nthe maximum. It is convenient and reasonable to set the KORDER $-$ 1 knots\nwith indices less than KORDER equal to $t_{\\text{KORDER}}$, and the KORDER $-$\n1 knots with indices greater than NCOEF + 1 equal to $t_{\\text{NCOEF}+1}.$\n\nKnots indexed from KORDER + 1 through NCOEF are {\\em internal} knots. Internal\nknots specify abscissae at which one polynomial piece ends and the next\nbegins. Successively indexed internal knots may have the same value. A knot\nappearing with multiplicity $\\mu $ means the order of continuity of the\nspline at this knot will be at least $\\text{KORDER}-\\mu -1$. Require $1\\leq \\mu\n\\leq $ KORDER.\n\nRequire $t_i\\leq t_{i+1}$ for $i=1$, ..., NCOEF + KORDER $-$ 1; $t_i<t_{i+%\n\\text{KORDER}}$ for $i=1$, ..., NCOEF; $t_{\\text{KORDER}}<t_{\\text{KORDER}+1}$;\nand $t_{\\text{NCOEF}}<t_{\\text{NCOEF}+1}$. See Sections C and D for\nfurther discussion of knot placement.\n\n\\item[BCOEF()]  \\ [out] Coefficients $c_i$, $i=1$, NCOEF, in the sum\nrepresenting the spline function as a sum of coefficients times B-spline\nbasis functions.\n\n\\item[RNORM]  \\ [out] Set by the subroutine as a measure of the residual\nerror of the fit. RNORM$=\\left[ \\sum_i \\left( \\frac{resid_i}{\\text{SD}_i}%\n\\right) ^2\\right] ^{1/2},$ where the summation is over indices for which $%\nrelop_i=\\,^{\\prime }{\\sim }^{\\prime }$, and $resid_i$ denotes the residual after the\nfit in the equation specified by CCODE(i).  Here $\\text{SD}_i$ denotes SD($i$)\nif SD($1)>0$, and $|\\text{SD}(1)|$ otherwise.\n\n\\item[ISET()]  \\ [in] Array of length~3. These specifications use the\nfollowing values:\n\\begin{description}\n\\item[\\rm $ns =$]  the number of elements in CCODE() containing $%\nrelop=\\,^{\\prime }{<}^{\\prime }$ or $^{\\prime }{>}^{\\prime }$ and $active\n=\\,^{\\prime }$A$^{\\prime }.$\n\n\\item[\\rm $m1 =$]  the number of elements in CCODE() containing $%\nrelop=\\,^{\\prime }{=}^{\\prime }$, $^{\\prime }{<}^{\\prime }$ or $^{\\prime\n}{>}^{\\prime }$ and $active =\\,^{\\prime }$A$^{\\prime }.$\n\n\\item[\\rm $mfit =$]  the number of elements in CCODE() containing $relop\n=\\,^{\\prime }{\\sim }^{\\prime }$ and $active =\\,^{\\prime }$A$^{\\prime }.$\n\n\\item[\\rm $ntot =$]  NCOEF + {\\em ns},\n\n\\item[\\rm $mtot =$]  $m1+mfit$,\n\n\\item[\\rm $minmn =$]  $\\min (mtot,ntot).$\\rule[-5pt]{0pt}{8pt}\n\n\\item[\\rm ISET(1) =]  {\\em ninfo}, the dimension of INFO(). A sufficiently large\nvalue is $7+2\\,ntot$.\n\n\\item[\\rm ISET(2) =]  {\\em nwork}, the dimension of WORK(). A sufficiently large\nvalue is $nwork=mtot\\times ntot+3\\,mtot+6\\,ntot+3\\,minmn+m1.$\n\n\\item[\\rm ISET(3) =]  {\\em kprint}, a diagnostic print flag in the range~[0,~4].\nIt is passed on to DBLSE. Zero means no printing. Larger values produce more\nprinting.\n\\end{description}\n\\item[INFO()]  \\ [out and scratch] The first 7~elements of INFO() are used\nto return information about the problem. The following $2\\times (\\text{NCOEF}%\n+ns)$ locations are used as scratch. The dimension of INFO() is {\\em ninfo}\ngiven in ISET(1).\n\\begin{description}\n\\item[\\rm INFO(1) $= ierr5$,]  a status indicator incorporating information\nfrom IERR4 issued by DBLSE. Possible values of {\\em ierr5} are as follows:\n\\begin{itemize}\n\\item[0]  No errors detected.\n\n\\item[100]  NCOEF $<1$\n\n\\item[150]  KORDER $>kmax(=20)$\n\n\\item[200]  TKNOTS$(i)>\\text{TKNOTS}(i+1)$\n\n\\item[250]  TKNOTS$(i)\\geq \\text{TKNOTS}(i+\\text{KORDER})$\n\n\\item[300]  {\\em ninfo} or {\\em nwork} is too small. Recommended values\nare returned in INFO(2) and INFO(3).\n\n\\item[500]  $deriv_i$ has bad value for some $i.$\n\n\\item[600]  $relop_i$ has bad value for some $i.$\n\n\\item[700]  $kind_i$ has bad value for some $i.$\n\n\\item[800]  $active_i$ has bad value for some $i.$\n\n\\item[1000]  + IERR4 \\quad IERR4 $\\neq 0$ due to error detected in DBLSE.\nFor the interpretation of IERR4 see Section~E.\n\n\\item[\\rm 1100] \\  SD(1) = 0.0\n\n\\item[\\rm 1200] \\  SD(1) $>$ 0.0, and SD($i) \\leq 0.0$ for some $i$\nfor which $relop_i =\\,^{\\prime}{\\sim }^{\\prime}$.\n\n\\end{itemize}\n\\item[\\rm INFO(2) $= need1$,]  the dimension needed for INFO().\n\n\\item[\\rm INFO(3) $= need2$,]  the dimension needed for WORK().\n\n\\item[\\rm INFO(4) $= m1$,]  the number of constraint rows in the matrix\nrepresentation of the problem. This will be the number of elements in\nCCODE() containing $relop=\\,^{\\prime }{=}^{\\prime }$, $^{\\prime }{<}^{\\prime }$\nor $^{\\prime }{>}^{\\prime }$ and $active =\\,^{\\prime }$A$^{\\prime }$\n\n\\item[\\rm INFO(5) $= mfit$,]  the number of least-squares equations. This\nwill be the number of elements in CCODE() containing $relop=\\,^{\\prime\n}{\\sim }^{\\prime }$ and $active=\\,^{\\prime }$A$^{\\prime }.$\n\n\\item[\\rm INFO(6) $= ns$,]  the number of slack variables. This will be the\nnumber of elements in CCODE() containing $relop=\\,^{\\prime }{<}^{\\prime }$ or $%\n^{\\prime }{>}^{\\prime }$ and $active=\\,^{\\prime }$A$^{\\prime }.$\n\n\\item[\\rm INFO(7) $= nsets$,]  the number of variables in ``Set S\" at\ntermination. These variables are at values determined by solution of a\nsystem of equations. The other $\\text{NCOEF}+ns-nsets$ variables will be at fixed\nvalues, either at one of their bounds or at zero.\n\\end{description}\n\\item[WORK()]  \\ [scratch] Work space dimensioned {\\em nwork}. See ISET(2) above.\n\\end{description}\n\\subsubsection{Usage of DSVAL for evaluation using the B-spline basis\\label\n{dsval}}\n\nDSVAL returns the value at argument X of the derivative of order IDERIV of\nthe spline function defined by the parameter sequence [KORDER, NCOEF,\nTKNOTS(), BCOEF()].\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NCOEF, KORDER, IDERIV}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf DSVAL,\\\\\nTKNOTS}($\\geq $NCOEF+KORDER){\\bf ,\\\\\nBCOEF}($\\geq $NCOEF){\\bf , X}\n\\end{description}\nAssign values to all arguments.\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nD = DSVAL(KORDER, NCOEF, TKNOTS,\\\\\nBCOEF, X, IDERIV)\n\\end{tabular}}\n\\end{center}\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[KORDER, NCOEF, TKNOTS(), BCOEF()]  \\ [in] Quantities defining a spline\nfunction relative to the B-spline basis as returned by DSFIT or DSFITC.\nInternal arrays in this subprogram impose an upper limit of $kmax=20$ on\nKORDER.\n\n\\item[X]  \\ [in] Argument at which the IDERIV order derivative of the spline\nfunction will be evaluated.\n\n\\item[IDERIV]  \\ [in] Derivative order desired. Require IDERIV $\\geq 0$.\nZero means to evaluate the spline function itself.\n\\end{description}\n\\subsubsection{Usage of DSQUAD for integration using the B-spline basis\\label\n{dsquad}}\n\nDSQUAD returns the value of the integral from X1 to X2 of the spline\nfunction defined by the parameter sequence [KORDER, NCOEF, TKNOTS(),\nBCOEF()].\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf KORDER, NCOEF}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf DSQUAD,\\\\\nTKNOTS}($\\geq $NCOEF+KORDER){\\bf ,\\\\\nBCOEF}($\\geq $NCOEF){\\bf , X1, X2}\n\\end{description}\nAssign values to all arguments.\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nD = DSQUAD(KORDER, NCOEF,\\\\\nTKNOTS, BCOEF, X1, X2)\n\\end{tabular}}\n\\end{center}\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[KORDER, NCOEF, TKNOTS(), BCOEF()]  \\ [in] Quantities defining a spline\nfunction relative to the B-spline basis as returned by DSFIT or DSFITC.\n\n\\item[X1, X2]  \\ [in] Limits of the integral to be evaluated. Permit X1 $<$\nX2 or X1 $\\geq $ X2.\n\\end{description}\n\\subsubsection{Usage of DSTOP to convert from the B-spline basis to the power\nbasis\\label{dstop}}\n\nDSTOP converts the representation of a spline function from the B-spline\nparameterization [KORDER, NCOEF, TKNOTS(), BCOEF()] to the power\nbasis form [KORDER, NPC, XI(), PCOEF()]. KORDER will not be changed.\nTypically the B-spline parameters will have come from DSFIT or DSFITC.\nThe power coefficients can be used by DPVAL and DPQUAD.\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf KORDER, NCOEF, NPC}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf TKNOTS}($\\geq $NCOEF+\\\\ KORDER){\\bf ,\nBCOEF}($\\geq $NCOEF){\\bf ,\\\\ BDIF}($\\geq \\text{NCOEF}\\times $KORDER){\\bf ,\nXI}({\\em mpc}+1){\\bf ,\\\\ PCOEF}($\\geq $KORDER$\\times mpc)$\n\\end{description}\nThe dimension {\\em mpc} must be as large as the output value NPC. In terms of\ninput quantities it suffices to set $mpc \\geq $ NCOEF $-$ KORDER + 1. Assign\nvalues to KORDER, NCOEF, TKNOTS(), and BCOEF().\\vspace{-10pt}\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL DSTOP(KORDER, NCOEF, TKNOTS,$\\negthickspace \\negthickspace$\\\\\nBCOEF, BDIF, NPC, XI, PCOEF)\n\\end{tabular}}\n\\end{center}\nResults are returned in NPC, XI(), and PCOEF().\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[KORDER, NCOEF, TKNOTS(), BCOEF()]  \\ [in] Quantities defining a spline\nfunction relative to the B-spline basis, as returned by DSFIT or DSFITC.\n\n\\item[BDIF()]  \\ [scratch] Work space of size NCOEF $\\times $ KORDER.\n\n\\item[NPC]  \\ [out] NPC + 1 will be the number of distinct values in the\nsequence [TKNOTS($i),\\ i=$ KORDER, ..., NCOEF + 1]. NPC will satisfy\nNPC $\\leq $ NCOEF $-$ KORDER + 1.\n\n\\item[XI()]  \\ [out] A strictly increasing sequence of length NPC + 1\nconsisting of all the distinct values from the sequence [TKNOTS($i),\\ i=$\nKORDER, ..., NCOEF + 1].\n\n\\item[PCOEF()]  \\ [out] PCOEF$(i+(j-1)\\times $ KORDER) will be be the\ncoefficient of $(t-\\text{XI}(j))^{(i-1)}$ in the power basis representation\nof the spline function. $(i=1$, ..., KORDER; $j=1$, ..., NPC)\n\\end{description}\n\\subsubsection{Usage of DPVAL for evaluation using the power basis\\label\n{dpval}}\n\nDPVAL returns the value at argument X of the derivative of order IDERIV of\nthe spline function defined by the parameter sequence [KORDER, NPC, XI(),\nPCOEF()].\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NPC, KORDER, IDERIV}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf DPVAL,\\\\\nXI}($\\geq $NPC+KORDER){\\bf ,\\\\\nPCOEF}($\\geq $KORDER$\\times $NPC){\\bf , X}\n\\end{description}\nAssign values to all arguments.\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nD = DPVAL(KORDER, NPC, XI,\\\\\nPCOEF, X, IDERIV)\n\\end{tabular}}\n\\end{center}\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[KORDER, NPC, XI(), PCOEF()]  \\ [in] Quantities defining a spline\nfunction relative to the power basis, as returned by DSTOP.\n\n\\item[X]  \\ [in] Argument at which the IDERIV order derivative of the spline\nfunction will be evaluated.\n\n\\item[IDERIV]  \\ [in] Derivative order desired. Require IDERIV $\\geq 0$.\nZero means to evaluate the spline function itself.\n\\end{description}\n\\subsubsection{Usage of DPQUAD for integration using the power basis\\label\n{dpquad}}\n\nDPQUAD returns the value of the integral from X1 to X2 of the spline\nfunction defined by the parameter sequence [KORDER, NPC, XI(), PCOEF()].\n\n\\paragraph{Program Prototype, Double Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf KORDER, NPC}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf DPQUAD,\\\\\nXI}($\\geq $NPC+KORDER){\\bf ,\\\\\nPCOEF}($\\geq $KORDER$\\times $NPC){\\bf , X1, X2}\n\\end{description}\nAssign values to all arguments.\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nD = DPQUAD(KORDER, NPC, XI,\\\\\nPCOEF, X1, X2)\n\\end{tabular}}\n\\end{center}\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[KORDER, NPC, XI(), PCOEF()]  \\ [in] Quantities defining a spline\nfunction relative to the power basis, as returned by DSTOP.\n\n\\item[X1, X2]  \\ [in] Limits of the integral to be evaluated. Permit X1 $<$\nX2 or X1 $\\geq $ X2.\n\\end{description}\n\\subsubsection{Modifications for Single Precision\\label{modsp}}\n\nFor single precision usage change the DOUBLE PRECISION statements to REAL\nand change the initial ``D\" in the subprogram names to ``S\".\n\n\\subsection{Examples and Remarks}\n\n\\subsubsection{Demonstration of DSFIT.}\n\nThe demonstration driver DRDSFIT sets up a curve fitting problem having 12~$%\n(x,y)$ pairs of data. It uses DSFIT to do a least-squares fit to this data\nwith an 8-parameter cubic spline function. It uses DSVAL to evaluate the\nfitted function over the given set of $x$ values. It uses DSQUAD to compute\nthe definite integral of the fitted function from~5.0 to~20.0. It uses DSTOP\nto convert the B-spline representation to the power representation. It then\nuses DPVAL and DPQUAD to repeat the function evaluation and integral\ncomputation using the power representation. The output is listed in ODDSFIT.\n\n\\subsubsection{Demonstration of DSFITC.}\n\nThe program DRDSFITC illustrates the use of DSFITC to compute a constrained\nleast-squares spline fit to data. Output from DRDSFITC is listed in ODDSFITC\nand graphs prepared using {\\tt splot} from Chapter~16-03 are shown in\nFigures~1 and~2. We have 24~data points, given in the the first 24~entries\nof the arrays XI() and YI() in the DATA statement in DRDSFITC. These points\nare shown as circles in Figure~1.\n\nSuppose these data are measurements of some phenomenon that is known to be\nmonotone nondecreasing and we wish to find a monotone nondecreasing function\nthat closely fits the data. An unconstrained least-squares fit to this data\nby a single polynomial or by a polynomial spline function will have unwanted\noscillations. There are rational functions and exponential functions with\nthree parameters that are monotone and of somewhat the desired shape, but\nthese functions do not have enough free parameters to allow the function to\nfit the data really closely. A satisfactory fit can be obtained using a\ncubic spline function having $C^2$ continuity.\n\nThe data abscissae range from~0 to~6. We shall place quadruple knots at these\ntwo points and internal knots at~1.5, 2.5, 3.3, 4.0, and~4.7. The number and\nlocations of these internal knots were selected by some trial and error.\nThese knot values are stored in TKNOTS(). Their locations are shown by\ntriangles in Figures 1 and~2. Since we have selected a total of 13~knots and\nwe have KORDER = 4 to specify a cubic spline, the number of coefficients\nwill be set to NCOEF $= 13 - 4 = 9.$\n\nWe shall require the curve to be concave up over [0,~2.5] by requiring $%\nf^{\\prime \\prime} \\geq 0$ at~0 and at the first two internal knots. These\nconstraints, along with the constraint $f^{\\prime}(0) \\geq 0$, will force$%\nf^{\\prime}$ to be nonnegative over [0,~2.5]. Similarly we require the curve\nto be concave down over [3.3,~6] by requiring $f^{\\prime \\prime} \\leq 0$ at\nthe last three internal knots and at~6. These constraints, along with the\nconstraint $f^{\\prime}(6) \\geq 0$, will force $f^{\\prime}$ to be nonnegative\nover [3.3,~6]. It follows that $f^{\\prime}\\geq 0$ over [2.5,~3.3] since in\nthis interval $f^{\\prime}$ is a quadratic polynomial that is nonnegative and\nnondecreasing at~2.5 and nonnegative and nonincreasing at~3.3.\n\nThe second derivative of a cubic spline is linear between knots. Thus\nthe conditions $f^{\\prime \\prime}(2.5) \\geq 0$ and $f^{\\prime \\prime}(3.3)\n\\leq 0$ imply that $f^{\\prime \\prime}$ can have at most one sign change in the\ninterval between the successive knots at~2.5 and~3.3.\nThis assures the only inflection point of the curve over (0,~6) will occur\nin the interval [2.5,~3.3]. See Figure~2 for graphs of the\nresulting $f^{\\prime}$ and $f^{\\prime \\prime}.$\n\nSupposing we also wish to have the fitted curve take the value 1 at~0 and\nthe value 5 at~6, we also impose these constraints.\n\nRecall that the four characters in each entry of CCODE() are interpreted as\n({\\em kind}, {\\em deriv}, {\\em relop}, {\\em active}). All but the last element of CCODE()\nhave $active =\\,^{\\prime}$a$^{\\prime}$ meaning these elements are active, while\nthe last element has $active =\\,^{\\prime}!^{\\prime}$, which is the termination\nsignal. All of the active elements have $kind =\\,^{\\prime}1^{\\prime}$,\nmeaning the specified equation is of the form\n\\begin{equation*}\nf^{(di)}(\\text{XI}(i))\\ relop_i \\text{ YI}(i).\n\\end{equation*}\nThe first 24~entries have $relop =\\,^{\\prime}{\\sim }^{\\prime}$ meaning that\neach specifies one of the least-squares equations. The ten elements of CCODE()\nbeginning with CCODE(25) specify the constraints. For example CCODE(26) has $%\nderiv =\\,^{\\prime}1^{\\prime}$ and $relop =\\,^{\\prime}{>}^{\\prime}$ meaning the\nfirst derivative at XI(26) is constrained to be $\\geq $ YI(26).\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl11-05b }\n\n\\centerline{\\bf Figure 2: First and second derivatives\\newline}\n\\centerline{\\bf of fitted function.\\rule[-8pt]{0pt}{8pt}}\n\n\\subsubsection{Using constraints to control shape.}\n\nA function with at least $C^1$ continuity is nondecreasing over $[c,~d]$ if\nits first derivative is nonnegative throughout $[c,~d]$. A function with at\nleast $C^2$ continuity is concave up over an interval $[c,~d]$ if its second\nderivative is nonnegative throughout $[c,~d]$. Although these are properties\ndefined over an interval, it is possible to impose these conditions on\nspline functions by appropriate assignment of constraints at a finite number\nof points.\n\nNote that if $f$ is a cubic spline function with $C^2$ continuity, then $%\nf^{\\prime}$ is a quadratic spline with $C^1$ continuity, and $f^{\\prime\n\\prime}$ is a linear spline function with $C^0$ continuity, $i.e.$, $%\nf^{\\prime \\prime}$ is a continuous piecewise linear function with possible\nslope changes only at knots. It follows that by requiring $f^{\\prime \\prime}\n\\geq 0$ at $c$ and $d$, and at any knots between $c$ and $d$, $f^{\\prime\n\\prime}$ will necessarily be nonnegative throughout $[c,~d]$, and therefore $%\nf $ will be concave up throughout $[c,~d].$\n\nIf one wants $f$ to be monotone nondecreasing as well as concave up over $%\n[c,~d]$ it suffices to require $f^{\\prime}(c) \\geq 0$ along with the second\nderivative conditions already discussed, since with $f^{\\prime \\prime} \\geq\n0 $ throughout $[c,~d]$, $f^{\\prime}$ cannot have a smaller value anywhere\nin $[c,~d]$ than it has at $c.$\n\nIf one wants monotonicity for $f$ without second derivative constraints, one\ncould let $f$ be a quadratic spline rather than a cubic spline. Then $%\nf^{\\prime}$ will be piecewise linear and one can control the sign of $%\nf^{\\prime}$ over an interval by constraining $f^{\\prime}$ at knots as was\ndone above for $f^{\\prime \\prime}$. If one prefers to use cubic splines, one\ncan do trial and error placement of constraints on $f^{\\prime}$ and\neventually keep $f^{\\prime}$ from changing sign.\n\n\\subsubsection{\\bf Periodicity.}\n\nWhen periodicity is desired it should be specified for the function value\nand all orders of derivatives that are continuous at the points referenced in\nthe specification. For example suppose one wants periodicity of 360~degrees.\nThe {\\em proper interpolation interval} could be set as [a,~b] = [0.0,~360.0].\nIf one uses KORDER = 4 one should specify periodicity for $f$, $f^{\\prime}$,\nand $f^{\\prime \\prime}$. This can be done by setting CCODE(1:3) $=\\,^{\\prime}$%\n20=a$^{\\prime}$, $^{\\prime}$21=a$^{\\prime}$, $^{\\prime}$22=a$^{%\n\\prime}$; X(1:3) $= 0.0$, 0.0, 0.0; and Y(1:3) $= 360.0$, 360.0, 360.0.\n\nAlthough it does not change the fit obtained, one may wish to have the\nperiodicity reflected in the coefficients. Letting $p$ denote the period, and\nassuming $p+t_{\\text{KORDER}} = p+a = b = t_{\\text{NCOEF}+1}$, this can be done\nby setting the initial knots as $t_i = -p+t_{\\text{NCOEF}+1-\\text{KORDER}+i}$,\nfor $i = 1$, ..., KORDER $-$ 1, and the final knots as $t_{\\text{NCOEF}+1+i}\n= p+t_{\\text{KORDER}+i}$, for $i = 1$, ..., KORDER $-$ 1. Then the\ncoefficients will reflect the periodicity by satisfying $c_{\\text{NCOEF}+1-%\n\\text{KORDER}+i} = c_i$, for $i = 1$, ..., KORDER $-$ 1.\n\n\\subsubsection{Differential equations.}\n\nUsing $kind = 3,$ conditions such as $f^{\\prime}(x) - c f(x) = d$, or $%\nf^{\\prime}(x) - c f(x) \\sim d$ (and slightly more general expressions) can be\nspecified for given values of $x$, $c$ and $d$. Thus DSFITC can be used to\nimplement the collocation method of computing an approximate solution to\nlinear differential equations.\n\n\\subsubsection{Assignment of knots.}\n\nMany discussions of spline interpolation are based on the assumption that\nmany, or all, of the knots will be assigned to coincide with data abscissae.\nThis is not necessary, either for interpolation or least-squares fitting.\n\nLet, $\\{B_i$: $i$ = 1, ..., NCOEF$\\}$, be a family of B-spline basis\nfunctions of order $K$. An unconstrained interpolation or least-squares\nfitting problem using this family gives rise to a full-rank matrix, and thus\nhas a unique solution if and only if there are at least NCOEF distinct data\nabscissae, and it is possible to choose NCOEF of these and relabel them, say\nas $u_i$, $i = 1$, NCOEF, so they will satisfy $B_i(u_i) \\neq 0$ for $i = 1$%\n, ..., NCOEF. This condition will be satisfied if the (possibly relabled) $%\nu_i$'s relate to the knots according to $t_i < u_i < t_{i+K}$ for $i\n= 1$, ..., NCOEF.\n\nConsider an interpolation problem with NXY data points, all data abscissae\nbeing distinct. Choose a spline order $K \\geq 2$. We must use exactly NCOEF =\nNXY B-spline basis functions. Thus NCOEF + $K$ knots must be assigned. Let $a$\nand $b$ be the minimum and maximum data abscissae respectively. Assign the\nfirst $K$ knots the value a and the last $K$ knots the value $b$. Then $\\text{%\nNCOEF} - K$ knots remain to be assigned and there are NCOEF $-$ 2 data\nabscissae distinct from $a$ and $b$. One simple approach is to use\nany $\\text{NCOEF}-K$ of these NCOEF $-$ 2 data abscissae as knots. In the\npopular case of cubic spline interpolation($K = 4$) there would be just two\ndata abscissae not used as knots. It is common to choose these to be the\nfirst one after $a$ and the last one before $b.$\n\nAnother method suggested in \\cite{deBoor:1978:APG}, pp.~218--219, for\nassigning the interior knots for interpolation is the formula\n\\begin{multline*}\nt_i = (u_{i-K+1} + ... + u_{i-1})/(K-1),\\\\\ni = K+1,\\ ...,\\ NCOEF\n\\end{multline*}\nwhere the ordered set of data abscissae is denoted by $\\{u_i$: $i = 1$, ...,\nNCOEF$\\}$.\n\nFor least-squares fitting one must choose NCOEF $<$ NXY.\n\n\\subsection{Functional Description}\n\n\\subsubsection{Representation of an individual B-spline basis function.}\n\nLet $\\{t_1$, ..., $t_{K+1}\\}$ be a sequence of strictly increasing real numbers\nthat we will call {\\em knots}. To within a multiplicative scale factor, there is\none, and only one, spline polynomial function of order $K$ $(i.e.$, having\npolynomial pieces of degree at most $K-1$), having at least $C^{K-2}$\ncontinuity at these knots, and being nonzero throughout the open interval $%\n(t_1$,\\ $t_{K+1})$, and zero outside this interval. With some convention for\nassigning the scale factor, such a function is called a B-spline basis\nfunction. The interval $\\langle t_1$, $t_{K+1}\\rangle $ will be called the\n{\\em support interval} for this B-spline basis function. We use angle\nbrackets $\\langle \\ \\rangle $ to indicate that we are not specifying whether\nthe endpoints are included or not. Graphs of B-spline basis functions of orders\n1, 2, 3, and~4 over uniformly spaced knots are given in\nFigures~3--5.\n\nFollowing \\cite{deBoor:1978:APG}, these definitions can be generalized to\nallow knots to coalesce.  This has a natural mathematical interpretation\nof reducing the order of continuity at the affected knots.  At an ordinary\nnon-multiple knot, a spline function of order $K$ has $C^{K-2}$\ncontinuity.  At a knot of multiplicity $\\mu $ a spline function of order\n$K$ has $C^{K-\\mu -1}$ continuity.  For example a B-spline basis function\nof order~4 defined over the knot set $\\{0$, 1, 1, 5, $6\\}$ consists of\nonly three nontrivial cubic pieces, and these have $C^2$ continuity at 0,\n5, and~6, but only $C^1$ continuity at~1.  This freedom to lower the order\nof continuity at specified places can be useful in allowing a curve to\nchange direction more sharply at such a point.  Graphs of B-spline basis\nfunctions of order 4 having multiple knots at the left end are given in\nFigure~6.\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl11-05c }\n\n\\centerline{\\bf Figure 3: B-spline basis functions\\newline}\n\\centerline{\\bf of orders 1 and 2.\\rule[-8pt]{0pt}{8pt}}\n\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl11-05d }\n\n\\centerline{\\bf Figure 4: B-spline basis function of order 3.\n\\rule[-8pt]{0pt}{8pt}}\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl11-05e }\n\n\\centerline{\\bf Figure 5: B-spline basis function of order 4.\n\\rule[-8pt]{0pt}{8pt}}\n\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl11-05f }\n\n\\centerline{\\bf Figure 6: Cubic B-spline basis functions}\n\\centerline{\\bf having multiple knots at the left.\\rule[-8pt]{0pt}{8pt}}\n\n\\subsubsection{Representation of a spline function using the B-spline basis.}\n\nSuppose we wish to construct a family of spline functions of order $K$, and\nhaving NCOEF degrees of freedom, over an interval $[a,~b]$, which will be\ncalled the {\\em proper interpolation interval} for this spline family. We\nrequire $a<b$ and NCOEF $\\geq K.$ Construct a {\\em knot sequence} T $=\\{t_1$,\n..., $t_{\\text{NCOEF}+K}\\}$. This sequence must be nondecreasing and have $t_K=\na$ and $t_{\\text{NCOEF}+1}=b$. The values of the knots indexed before $K$ or\nafter NCOEF + 1 do not affect the shapes that can be achieved by the family of\nsplines to be defined. A convenient way to set these knots is to set $t_1=..$%\n. $=t_K=a$, and $t_{\\text{NCOEF}+1}=..$. $=t_{\\text{NCOEF}+K}=b.$\n\nThe knots indexed from $K + 1$ through NCOEF are called {\\em internal} knots.\nInternal knots define where the different polynomial pieces meet. Their\nplacement determines the shapes that the resulting spline family can\nachieve. We require $t_K < t_{K+1}$, and $t_{\\text{NCOEF}} < t_{\\text{NCOEF}%\n+1}$, and $t_i < t_{i+K}$ for $i = 1$, ..., NCOEF. Within the limitations of\nthese constraints, successive interior knots need not be distinct. At\nan internal knot of multiplicity $\\mu $ members of this spline family will\nhave $C^{K-\\mu -1}$ continuity.\n\nFor each $i = 1$, ..., NCOEF, we define a B-spline basis function $B_i$\nhaving $\\langle t_i$, $t_{i+K}\\rangle $ as its support interval. For $i=K$,\n..., NCOEF, each interval $\\langle t_i$, $t_{i+1}\\rangle $ is in the support\ninterval of exactly $K$ basis functions, namely $\\{B_j$: $j = i-K+1$,\n..., $i\\}$. If such an interval $\\langle t_i$, $t_{i+1}\\rangle $ has nonzero\nlength, the $K$ basis functions that contain this interval in their support\nintervals form a basis for the space of all polynomials of degree $\\leq K - 1$\nover this interval. The closed union of these intervals is the\ninterval $[a,~b]$. This is the interval over which it is most reasonable to\nuse linear combinations of the $B_i$'s to fit data.\n\nAny polynomial of degree $\\leq K-1$ can be exactly represented over $[a,~b]$\nby a linear combination of the $B_i$'s, $i = 1$,\\ ...,\\ NCOEF. In\nparticular the constant function whose value is one is representable over $%\n[a,~b]$ by a linear combination of the $B_i$'s.\n\nIn this package the scaling of the $B_i$'s is determined by the\nrequirement that all the coefficients in this linear combination be ones, $%\ni.e.$, $\\sum_{i=1}^{\\text{NCOEF}} B_i(t)=1$ for all $t \\in [a,~b].$\n\nGiven coefficients, $c_i$, $i = 1$, ..., NCOEF, a spline function, $f(t)$,\nis represented for $t \\in [a,~b]$ as $f(t) = \\sum_{i=1}^{\\text{NCOEF}}\nc_i B_i(t).$\n\nAlthough this is a sum of NCOEF terms, at most $K$ of the terms are nonzero\nat any single point, $t$, due to the properties of the basis functions. For\nevaluation of $f(t)$ at a point $t \\in (a,b)$ that coincides with a knot,\nthis package uses the polynomial piece defined over the nonzero subinterval\nimmediately to the right of $t$. This package allows extrapolation outside\nthe interval $(a,b)$ using the convention that for $t \\leq a$ the package\nwill extend the polynomial that is defined over $\\langle t_K,t_{K+1}\\rangle $%\n, and for $t \\geq b$ the package will extend the polynomial that is defined\nover $\\langle t_{\\text{NCOEF}},t_{\\text{NCOEF}+1}\\rangle .$\n\nWithin this package a spline function is fully specified relative to the\nB-spline basis by two integers, KORDER and NCOEF, and two floating point\narrays, TKNOTS() and BCOEF(), containing [$t_i$:\\ $i = 1$,\\ ...,\\ NCOEF +\nKORDER] and [$c_i$: $i = 1$, ..., NCOEF].\n\n\\subsubsection{\\bf Representation of a spline function using the\npiecewise power basis.}\n\nAssume a spline function $f(t)$ has been defined relative to the B-spline\nbasis as described above. Let NPC be the number of subintervals of nonzero\nlength into which $[a,~b]$ is partitioned by the knot sequence T. Let $x_j$, $%\nj = 1$, ..., NPC be the left endpoints of these subintervals, and let $%\nx_{NPC+1} = b$. For the half-open subinterval $[x_j,x_{j+1})$ coefficients $%\np_{i,j}$ can be determined so the polynomial\n\\begin{equation*}\np_{1,j} + p_{2,j}h + p_{3,j}h^2 + ... + p_{K,j}h^{K-1}\n\\end{equation*}\nwith $h = (t-x_j)$, is identical to the polynomial spline function $f(t)$\nover this interval. If evaluation for $t$ outside $[a,b)$ is requested the\npackage will use the coefficients indexed by $j = 1$ if $t < a$, and will\nuse $j =$ NPC if $t \\geq b.$\n\nWithin this package a piecewise polynomial represented relative to the power\nbasis is specified by two integers, KORDER and NPC, and two floating point\narrays, XI() and PCOEF(), containing $\\{x_i$, $i = 1$, ..., NPC $+1\\}$ and $%\n\\{p_{i,j}$, $i = 1$, ..., KORDER; $j = 1$, ..., NPC$\\}.$\n\nThe power representation does not inherently assure any particular order of\ncontinuity at the knots, however if the coefficients are determined by\nconversion from a B-spline representation they will represent the same\nspline function and thus have the same continuity properties.\n\n\\subsubsection{Computation using B-spline basis functions}\n\nSuppose a spline function $f$ is defined relative to a B-spline basis by the\nquantities KORDER, NCOEF, T() and BCOEF() as discussed above. The {\\em %\nproper interpolation interval} for $f$ is $[a,~b]$ where $a = t_{\\text{KORDER}%\n}$, and $b = t_{\\text{NCOEF}+1}$. With any argument $x$ we associate a {\\em %\nreference index,} $j$, and {\\em reference interval} $\\langle t_j$, $%\nt_{j+1}\\rangle $ having $t_j < t_{j+1}$. If $x \\in [a,b)$, $j$ is chosen so\nthat $x \\in [t_j,t_{j+1})$, otherwise, if $x < a$ set $j =$ KORDER, and if $%\nx \\geq b$ set $j =$ NCOEF. Given $x$, subprogram DSFIND determines its\nreference index. From an initial trial value for $j$ the subprogram searches\nforward or backward, doubling the index increment for each trial, until\neither a bracketing pair of knots is found or the search reaches one end of\nthe specified search range. If a bracketing interval is found bisection is\nused, if necessary, to reduce the interval to the prescribed form.\n\nTo describe the computational algorithms we need to consider families of\nlower order basis functions over the same knot sequence T.  Let NT denote\nthe number of knots in T, $i.e.$, NT = KORDER + NCOEF.  For $k = 1$, ...,\nKORDER, let $\\{B_{i,k}$, $i = 1$, ..., $\\text{NT}-k\\}$, be the set of\nB-spline basis functions of order $k$ associated with T.  The support\ninterval for the function $B_{i,k}$ is $\\langle t_i$, $t_{i+k}\\rangle $.\nFormally one may follow \\cite{deBoor:1978:APG}, p.~118, and define\n$B_{i,k} \\equiv 0$ if $t_i = t_{i+k}$, however it happens that these\nfunctions do not occur in the algorithms we consider.\n\nA B-spline basis function of order $k$ can be expressed in terms of two\nbasis functions of order $k-1$ as\n\\begin{multline}\n\\label{O1}B_{i,k}(x)=\\frac{x-t_i}{t_{i+k-1}-t_i}B_{i,k-1}(x)\\\\\n+\\frac{t_{i+1}-x}{t_{i+k}-t_{i+1}}B_{i+1,k-1}(x).\n\\end{multline}\nThis formula was discovered and published independently by M. G. Cox and C.\nde Boor in~1972. It is a very favorable formula with regard to propagation\nof round-off error since, except when used for extrapolation, the $B$'s and\nthe factors multiplying the $B$'s are always nonnegative,\nso the central $``+\"$ always involves addition of nonnegative quantities.\n\nConsider now the problem in which we are given an $x$ and its reference\nindex $j$, and we need to compute values at $x$ of the KORDER basis\nfunctions of order KORDER that are nonzero on $\\langle t_j$, $t_{j+1}\\rangle $.\nThese functions will be $B_{j-\\text{KORDER}+1,\\text{KORDER}}$ through $%\nB_{j,\\text{KORDER}}.$\n\nAmong the basis functions of order~1, only $B_{j,1}$ is nonzero on $\\langle\nt_j$, $t_{j+1}\\rangle $ and its value is 1 throughout this interval. At\norder~2 only the two basis functions $B_{j-1,2}$ and $B_{j,2}$ are nonzero\non $\\langle t_j$, $t_{j+1}\\rangle $. These can be computed using Eq.\\,(1) and\nthe known values of $B_{j-1,1}$, $B_{j,1}$, and $B_{j+1,1}$, which are 0, 1,\nand~0, respectively. Clearly this process can be continued until the values\nof the KORDER nonzero basis functions of order KORDER are computed. This\nmethod is implemented in subprogram DSBASD. For the case of cubic splines\n(KORDER = 4), this involves nine applications of Eq.\\,(1) and in six of these\napplications one of the entering $B$'s is known to be zero.\n\nTo evaluate a spline function $f$ at a given argument $x$, one could use\nthis method to evaluate the nonzero basis functions and then form the sum of\nthese multiplied by the coefficients that define $f$. There is a more\nefficient method however. For a spline function $f$ of order $k$, its\nevaluation for a point $x$ with reference index $j$ can be expressed as $%\nf(x)=\\sum_{i=j-k+1}^jc_{i,k}B_{i,k}(x)$. Replacing each $B_{i,k}$ in this\nexpression by the right side of Eq.\\,(1) and collecting terms on the $%\nB_{i,k-1}$'s, and noting that only $k-1$ of these $(k-1)$-order\nbasis functions are nonzero on the reference interval, gives the expression $%\nf(x)=\\sum_{i=j-k+2}^jc_{i,k-1}(x)B_{i,k-1}(x)$ where\n\\begin{equation}\n\\label{O2}c_{i,k-1}(x)=\\frac{\\left( x-t_i\\right) c_{i,k}+\\left(\nt_{i+k-1}-x\\right) c_{i-1,k}}{t_{i+k-1}-t_i}.\n\\end{equation}\nOne can continue reducing the spline order and the number of terms in the\nsum in this way, finally reaching spline order~1 with only one term in the\nsum: $f(x)=c_{j,1}(x)B_{j,1}(x)\\equiv c_{j,1}(x)$, since $B_{j,1}(x)=1.$\n\nThus, as an algorithm for evaluating a spline function of order KORDER at an\nargument $x$ with reference index $j$, one initializes the process by\nsetting $c_{i,\\text{KORDER}} = c_i$, for $i = j-\\text{KORDER}+1$, ..., $j$.\nThen for $k =$ KORDER, KORDER $-$ 1, ..., 2, one computes $c_{i,k-1}$ for $i\n=j-k+2$, ..., $j$, using Eq.\\,(2). The final quantity $c_{j,1}$ is the value $%\nf(x)$. This method is implemented in subprogram DSVAL. For the case of cubic\nsplines (KORDER = 4), this involves six applications of Eq.\\,(2).\n\nThe first derivative of a spline function $f$ of order $k$ is a spline\nfunction of order $k-1$ over the same knot sequence. For an $x$ with\nreference index $j$ we have $f(x)=\\sum_{i=j-k+1}^jc_{i,k}B_{i,k}(x)$ and $%\nf^{\\prime }(x)=\\sum_{i=j-k+2}^jc_{i,k-1}^{(1)}B_{i,k-1}(x)$, where it\ncan be shown that\n\\begin{equation}\n\\label{O3}c_{i,k-1}^{(1)}=\\frac{\\left( k-1\\right) \\left(\nc_{i,k}-c_{i-1,k}\\right) }{t_{i+k-1}-t_i}.\n\\end{equation}\nTo compute the value of the $n^{th}$ derivative of a spline function, Eq.\\,(3)\ncan be applied as many times as necessary to compute coefficients of a\nB-spline representation of the $n^{th}$ derivative, and then Eq.\\,(2) can be\nused to evaluate the derivative. This algorithm is implemented in DSVAL with\nall computation being done from scratch for a given $x.$\n\nSince Eq.\\,(3) does not involve $x$, it is possible to use Eq.\\,(3) to precompute\nan array of coefficients for later use in computing derivative values for\nmany $x$ values. This approach is implemented in DSDIF and DSVALA. DSDIF\ncomputes the array of coefficients for all derivatives of orders up to a\nspecified NDERIV and DSVALA uses these coefficients in computing the values\nof all derivatives of orders up to NDERIV for a given $x$. Subprogram DSTOP\nfor the conversion from the B-spline basis to the power basis uses DSVALA,\nsince the coefficients relative to the power basis are just derivatives of\nthe spline function divided by factorials.\n\nFor an $x$ with reference index $j$, DSBASD computes the NDERIV$^{th}$\nderivative of the KORDER basis functions of order KORDER that are nonzero on\nthe reference interval. From Eq.\\,(3) we can express the first derivative of a\nsingle basis function as\n\\begin{equation}\n\\label{O4}B_{i,k}^{\\prime }=\\left( k-1\\right) \\left[ \\frac{B_{i,k-1}(x)}{%\nt_{i+k-1}-t_i}-\\frac{B_{i+1,k-1}(x)}{t_{i+k}-t_{i+1}}\\right] .\n\\end{equation}\nDSBASD first uses Eq.\\,(1) to compute the values $B_{i,\\text{KORDER}-\\text{%\nNDERIV}}(x)$, for $i=j- \\text{KORDER} + \\text{NDERIV}+1$, ..., $j$.\n\\rule{0pt}{10pt} Then for $d=1$, ..., NDERIV, DSBASD uses Eq.\\,(4) to\ncompute $B_{i,\\text{KORDER}-\\text{NDERIV}+d}^{(d)}(x)$,\nfor $i = j - \\text{KORDER} + \\text{NDERIV}-d+1$, ...,$j.$\\rule{0pt}{10pt}\n\nIt is possible to derive formulas for the exact integration of a spline\nfunction by appropriate inverse use of Eq.\\,(3).  The resulting method is\nunwieldy, and suspect with regard to propagation of round-off error.\nInstead we follow the approach of Amos, \\cite{Amos:1979:xxx}, that uses\nGaussian quadrature.  An $n$-point Gaussian quadrature formula is exact\nfor polynomials up to degree 2n-1.  The formula is applied separately to\neach polynomial piece needed to cover a specified integration interval.\nThis method is used in DSQUAD and in DSBASI.  Each of these subprograms\ncontains stored constants for 2, 6, and~10-point Gaussian formulas.  The\n2-point formula is used for KORDER from 1 to~4, the 6-point formula from~5\nto~12, and the 10-point formula from~13 to~20.\n\nThe fitting subroutine DSFIT uses DSBASD to form rows of the matrix for the\nleast-squares problem. Each row will have at most KORDER nonzeros in\nconsecutive locations giving rise to a block-banded form for the matrix.\nDSFIT uses DBACC and DBSOL (Chapter~4.5) to process and solve this system.\nThis approach takes advantage of both the band structure and sequential\nprocessing to reduce the amount of working space needed.\n\nThe constrained fitting subroutine DSFITC uses DSBASD and DSBASI, as\nappropriate to form rows of matrices representing the constraint conditions\nand the least-squares problem. Due to the general form of constraints\nallowed the overall problem is not assumed to have a banded form so the\nmatrices are formed in full. The resulting problem is linear least-squares\nwith general linear equality and inequality constraints which is solved\nusing the lower level subroutine DBLSE.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nDSFIT, DSFITC, and DSVAL each contain an internal dimensioning parameter $%\nkmax = 20.$ It is an error if KORDER $> kmax$ in any of these subprograms.\n\nDSFIT handles any detected error by setting IERR1, reporting the error to\nthe library error message processing subroutines of Chapter~19.2 with\nLEVEL = 0 and then returning. DSFITC handles errors similarly, setting the\nindicator {\\em ierr5} in INFO(1).\n\nThe only error detected in DSVAL is KORDER $> kmax$, in which case DSVAL\ncalls the library error processing subroutines with LEVEL = 2 which\nnominally causes message printing and termination of execution.\n\nAbscissae and weights for 2-point, 6-point, and 10-point Gaussian quadrature\nare stored to 40~decimal digits in DSQUAD. With infinite precision abscissae\nand weights, these formulae would be exact for splines of KORDER up to~20.\nDPQUAD does not use any inexact stored constants.\n\nThe lower level subroutine DBLSE is used by DSFITC to solve the\nconstrained least-squares problem.  If it detects error conditions it\nsets $ierr4 \\neq 0$ and DSFITC returns with INFO(1) = 1000 + $ierr4.$\nPossible nonzero values of {\\em ierr4} are:\n\\begin{itemize}\n\\item[$-$1]\\ \\ Failed to triangularize the {\\em m1} general constraint\nequations.  The subroutine attempts to complete the computation,\nomitting the constraint rows not triangularized.  User should check\nthe residuals of the constraint rows.\n\\item[+1]\\ \\ $mtot \\leq 0$ or $ntot \\leq 0$.\n\\item[+2]\\ \\ Inconsistent setting of bounds.\n\\item[+3]\\ \\ Too many iterations needed.  Nominal: $itmax = 5 \\times ntot.$\n\\end{itemize}\nFor definitions of {\\em m1}, {\\em mtot}, and {\\em ntot} see the specification of\nISET() in Section~B.2.b.\n\n\\subsection{Supporting Information}\n\nThe source language for these subroutines is ANSI Fortran 77.\n\nDSFIT and DSFITC evolved from codes originally designed by R.  J.  Hanson\nand C.  L.  Lawson at JPL in~1968.  The initial version of DSFITC,\n\\cite{Lang:1969:FC}, was called ``French Curve\" to call attention to the\nflexibility it provided for shaping a fitted curve.  Subprograms DSVAL,\nDPVAL, and DSTOP are modifications by Lawson of codes developed by C.  de\nBoor, \\cite{deBoor:1978:APG}.  Subprograms DSQUAD and DPQUAD are\nmodifications by Lawson of codes due to D.  E.  Amos,\n\\cite{Amos:1979:xxx}.\n\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDPQUAD & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDERV1, DPQUAD, DSFIND, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDERV1, DPVAL, DSFIND, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSFIT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDBACC, DBSOL, DERV1, DHTCC, DNRM2, DSBASD, DSFIT, ERFIN, ERMSG, IERM1,\nIERV1\\rule[-5pt]{0pt}{8pt}}\\\\\n\\end{tabular}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDSFITC & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDAXPY, DBLSE, DBSOL, DCOPY, DDOT, DHTCC, DERV1, DNRM2, DRANU, DROTG, DSBASD,\nDSBASI, DSFIND, DSFITC, DSWAP, ERFIN, ERMOR, ERMSG, IERM1, IERV1, RANPK1,\nRANPK2\\rule[-5pt]{0pt}{8pt}}\\\\\nDSQUAD & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDERV1, DSBASD, DSFIND, DSQUAD, DSVAL, DSVALA, ERFIN, ERMSG, IERM1,\nIERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSTOP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDERV1, DSBASD, DSDIF, DSFIND, DSTOP, DSVALA, ERFIN, ERMSG, IERM1,\nIERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDERV1, DSFIND, DSVAL, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSPQUAD & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SERV1, SPQUAD, SSFIND\\rule[-5pt]{0pt}{8pt}}\\\\\nSPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SERV1, SPVAL, SSFIND\\rule[-5pt]{0pt}{8pt}}\\\\\nSSFIT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SBACC, SBSOL, SERV1, SHTCC, SNRM2, SSBASD,\nSSFIT\\rule[-5pt]{0pt}{8pt}}\\\\\nSSFITC & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMOR, ERMSG, IERM1, IERV1, RANPK1, RANPK2, SAXPY, SBLSE, SBSOL,\nSCOPY, SDOT, SHTCC, SERV1, SNRM2, SRANU, SROTG, SSBASD, SSBASI, SSFIND,\nSSFITC, SSWAP\\rule[-5pt]{0pt}{8pt}}\\\\\nSSQUAD & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SERV1, SSBASD, SSFIND, SSQUAD, SSVA,\nSSVALA\\rule[-5pt]{0pt}{8pt}}\\\\SSTOP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SERV1, SSBASD, SSDIF, SSFIND, SSTOP,\nSSVAL\\rule[-5pt]{0pt}{8pt}}\\\\SSVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SERV1, SSFIND, SSVAL\\rule[-5pt]{0pt}{8pt}}\\\\\n\\end{tabular}\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDSFIT}\\vspace{0pt}\n\\lstinputlisting{\\codeloc{dsfit}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDSFIT}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dsfit}}\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\vspace{20pt}\n\n\\centerline{\\bf \\large DRDSFITC}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dsfitc}}\n\\newpage\n\n\\enlargethispage*{15pt}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDSFITC}\\vspace{3pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dsfitc}}\n\\closegraphsfile\n\\end{document}\n", "meta": {"hexsha": "75304e032569ca55e45bc398bf2a1dc5d4d0fc15", "size": 59797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch11-05.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/ch11-05.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/ch11-05.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": 47.9526864475, "max_line_length": 98, "alphanum_fraction": 0.7135809489, "num_tokens": 19377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143777, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6331247123970319}}
{"text": "\\documentclass{article}\n\\usepackage{amsfonts} \n\\usepackage{amsmath} \n\\usepackage{graphicx}\n\\usepackage[ruled,vlined]{algorithm2e}\n\\usepackage{xcolor}\n\n\\DeclareMathOperator*{\\argmin}{argmin} % no space, limits underneath in displays\n\\DeclareMathOperator*{\\argmax}{argmax} % no space, limits underneath in displays\n\n\\begin{document}\n\n\\section{Basic Idea}\nThe basic idea is to seperate the gridgraph into a set of pairs\n$\\mathbb{S}~=~\\{(A_i, B_i)~|~i~\\in~\\mathbb{N}\\}$\nsuch that $\\forall (A, B) \\in \\mathbb{S}: A, B \\subseteq V \\land A \\cap B = \\emptyset$\nand for each pair $u, v \\in V$ there exists a pair $(A, B) \\in \\mathbb{S}$ such that $a \\in A \\land b \\in B$ or\n$b \\in A \\land a \\in B$.\nFurthermore, given a pair $(A, B) \\in \\mathbb{S}$, it should be easy to calculate optimal distances for paths from nodes $u \\in A$\nto $v \\in B$ and the other way arround.\nSince for every pair of nodes $u, v \\in V$ there exists a pair $(A, B) \\in \\mathbb{S}$ with $a \\in A \\land b \\in B$ or\n$b \\in A \\land a \\in B$, the calculation of the optimal distance between $u$ and $v$ boils down to finding such a pair $(A, B) \\in\\mathbb{S}$\nand then reporting the optimal distance.\n\\quad\\\\\n\n\n\nThis means the challenge of finding the optimal distances for a gridgraph fast breaks down into two subchallenges:\n\\begin{itemize}\n\\item \\textbf{Preprocessing:} calculating set $\\mathbb{S}$ with the given properties and a way of reporting the optimal distances between nodes of $A$ and $B$.\n\\item \\textbf{Query:} for a given pair $u, v \\in V$, finding a set $a \\in A \\land b \\in B$ or $b \\in A \\land a \\in B$ must be fast.\n\\end{itemize}\n\nIn the following different approaches for the preprocessing and query phase are presented.\n\n\\section{Separation}\nThe idea of node separations comes from the well-separated pair decomposition, which organizes a given point set $P$\nsuch that all of $\\binom{P}{2}$ distances between points are clustered in into a linear amount of clusters,\nand that all distances in each cluster are roughly the same.\n\nIn order to achieve this a QuadTree is build for the point set $P$ and then algorithm~\\ref{alg:SeparateWSPD}\nwith the QuadTree root as input is called to calculate the well separation.\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{QuadTree Nodes $X, Y$}\n    \\KwResult{Cluster Set $\\mathbb{S}$}\n    \\If{$X = Y$}{\n      \\Return{$\\emptyset$}\n    }\n    \\If{$size(X) < size(Y)$}{\n      \\Return{$SeparateWSPD(Y, X)$}\n    }\n    \\If{$areWellSeparated(X, Y)$}{\n      \\Return{$\\{(X, Y)\\}$}\n    }\n\n    \\Return{$\\bigcup_{C \\in child(X)} SeparateWSPD(C, Y)$}\n    \\caption{SeparateWSPD}\n    \\label{alg:SeparateWSPD}\n  \\end{algorithm}\n\\end{figure}\n\nNotice how the $areWellSeparated(X, Y)$ function can be used specify when two clusters are well-separated.\nIn order to be useable for shortest path distance queries, three different $areWellSeparated$ function could be used.\n\n\\begin{enumerate}\n\\item \\textbf{Trivial Separation:} $X$ and $Y$ are well separated \\\\\n  $\\iff \\forall u \\in X: \\forall v \\in Y: d_{opt}(u, v) = |u_1 - v_1| + |u_2 - v_2|$\\\\\n  where $d_{opt}(u, v)$ is the optimal distance between $u$ and $v$.\n\\item \\textbf{Portal Separation:} $X$ and $Y$ are well separated \\\\\n  $\\iff \\exists u_{portal} \\in X: \\exists v_{portal} \\in Y: \\forall u \\in X: \\forall v \\in Y: u_{portal}~\\in~\\pi(u, v)~\\land~v_{portal}~\\in~\\pi(u, v)$\\\\\n  where $\\pi(u, v)$ is one optimal path from $u$ to $v$.\\\\\n  This means that there exists a portal node in $X$ and a portal node in $Y$ which is part of all shortest paths from $X$ to $Y$.\n\n\\item \\textbf{Barrier Separation:}\\\\\n  \\textcolor{red}{not implemented\\\\}\n  $X$ and $Y$ are well separated \\\\\n  $\\iff \\exists b \\in V: \\forall u \\in X: \\forall v \\in Y: b~\\in~\\pi(u, v)$\\\\\n  which means that there exists a barrier node $b \\in V$ that every shortest path from $X$ to $Y$ goes throught this node.\n\n\\end{enumerate}\n\n\\subsection{Trivial Separation}\nTo check wether two quadtree nodes $X$ and $Y$ are trivial separatable is easily achievable with algorithm~\\ref{alg:TrivialSeparationCheck}.\nAn example of a trivial separation in a gridgraph can be seen in figure~\\ref{pic:TrivialSeparation}.\n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=0.33\\textwidth]{TrivialSeparation.png}\n  \\caption{trivial separation example}\n  \\label{pic:TrivialSeparation}\n\\end{figure}\n\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{QuadTree Nodes $X, Y$}\n    \\KwResult{$Boolean$}\n    \\For{$x \\in X$}{\n      \\For{$y \\in Y$}{\n        $dist \\longleftarrow d(x, y)$;\\\\\n        $trivialDist \\longleftarrow |x_1 - y_1| + |x_2 - y_2|$;\\\\\n\n        \\If{$dist \\ne trivialDist$}{\n          \\Return{$FALSE$}\n        }\n      }\n    }\n    \\Return{$TRUE$}\n    \\caption{TrivialSeparationCheck}\n    \\label{alg:TrivialSeparationCheck}\n  \\end{algorithm}\n\\end{figure}\n\n\\subsubsection*{Query}\nWhen $X$ and $Y$ which are trivial separated are known for a given query $(x, y)$ the answer to the query is $|x_1 - y_1| + |x_2 - y_2|$.\n\n\\subsubsection{Lazy Path Reconstruction}\n\\textcolor{red}{not implemented\\\\}\n\n\\subsection{Portal Separation}\nTo calculate if two quadtree nodes $X$ and $Y$ are protal separatabel the two portals need to be found first.\nThe two portal candidates of a two quadtree nodes are the two nodes $x \\in X$ and $y \\in Y$ with the minimal distance.\n\n\\begin{equation}\n  (x_{portal}, y_{portal}) = \\argmin_{(x, y) \\in X \\times Y} d_{opt}(x, y)\n\\end{equation}\n\nWith those two portal candidates algorithm~\\ref{alg:PortalSeparation} can find out if two quadtree nodes are portal separated.\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{QuadTree Nodes $X, Y$, Portal Candidates $x_{portal}, y_{portal}$}\n    \\KwResult{$Boolean$}\n    \\For{$x \\in X$}{\n      \\For{$y \\in Y$}{\n        \\If{$d_{opt}(x, y) \\ne d_{opt}(x, x_{potal}) + d_{opt}(x_{portal}, y_{portal}) + d_{opt}(y, y_{potal})$}{\n          \\Return{$FALSE$}\n        }\n      }\n    }\n    \\Return{$TRUE$}\n    \\caption{PortalSeparationCheck}\n    \\label{alg:PortalSeparation}\n  \\end{algorithm}\n\\end{figure}\n\nAn example of a portal separation in a gridgraph can be seen in figure~\\ref{pic:PortalSeparation}.\n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=0.33\\textwidth]{PortalSeparation.png}\n  \\caption{portal separation example}\n  \\label{pic:PortalSeparation}\n\\end{figure}\n\n\n\\subsubsection{Query}\nIn order to answer a query, for each portal separated quadtree node pair $(X, Y)$, the two portals $x_{portal}, y_{portal}$ and the distance\nbetween them $d_{opt}(x_{portal}, y_{portal})$ needs to be stored.\nWith those things stored the algorithm~\\ref{alg:PortalQuery} can be used to answer queries.\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{QuadTree Nodes $X, Y$, Query Nodes $u \\in X, v \\in Y$, Portal Candidates $x_{portal}, y_{portal}$}\n    \\KwResult{$d_{opt}(u, v)$}\n    \\If{$u = x_{portal} \\land v = y_{portal}$}{\n      \\Return{$d_{opt}(x_{portal}, y_{portal})$}\n    }\n\n    \\If{$u = x_{portal}$}{\n      \\Return{$d_{opt}(x_{portal}, y_{portal}) + PortalQuery(y_{portal}, v)$}\n    }\n\n    \\If{$v = y_{portal}$}{\n      \\Return{$PortalQuery(x, x_{portal}) + d_{opt}(x_{portal}, y_{portal})$}\n    }\n\n    \\Return{$PortalQuery(x, x_{portal}) + d_{opt}(x_{portal}, y_{portal}) + PortalQuery(y_{portal}, v)$}\n\n    \\caption{PortalQuery}\n    \\label{alg:PortalQuery}\n  \\end{algorithm}\n\\end{figure}\n\n\\subsection{Separation Optimization}\n\\subsubsection{Avoiding Neigbours}\nSince the distance from a node to its neigbour is easly calculatable in a gridgraph, all separations $(X, Y)$ with $|X| = |Y| = 1$\nand $\\forall x \\in X: \\forall y \\in Y: x~and~y~are~neigbours$  can be omitted.\n\n\\subsubsection{Separation Weight Optimization}\nThe algorithm~\\ref{alg:SeparateWSPD} does only compare quadtree nodes with a heigh difference of at most 1.\nWhile this leads to optimal and unambiguous separations for points, it does not for nodes in a gridgraph.\nTo further optimize the separations a comparison between different separations is needed.\nin the following, the weight of a separation $(X, Y)$ is defined as:\n\n\\begin{equation*}\n  weight((X, Y)) = |\\{x~|~x \\in X~\\land~x~is~walkable\\}| \\cdot |\\{y~|~y \\in Y~\\land~y~is~walkable\\}|\n\\end{equation*}\n\nIntuitively the weight of a separation is the number of node pairs for which it is able to answer optimal distance queries.\n\n\nFurthermore domination of one separation of another is defined as:\n\\begin{equation*}\n  (X, Y) \\preceq (A, B) = (A \\subseteq X \\land B \\subseteq Y) \\lor (B \\subseteq X \\land A \\subseteq Y)\n\\end{equation*}\n\nIf one separation is dominated by another separation it can be omitted, since all node pair queries can also be answered by the\ndominating one.\\\\\n\n\\quad\\\\\n\nSeparations can be seen as blue edges between the well-separated nodes in the quadtree. Such a set of blue nodes can be optimized by\ntrying to push the blue edges higher in the quadtree. Since the original algorithm only connects two quadtree nodes with a high difference of at most\n1, often such blue edges can be pushed higher in the quadtree. In order to do this the two nodes of a separation are used as a lower bound,\nwhich means the blue edge will not be pushed below the nodes of quadtree.\nAs an upper bound the first quadtree node which both nodes of the separation are a subset of is used.\nLet $parent(A, B)$ be the set of nodes in the quadtree of which are $A$ and $B$ subsets, and $parent(A)$ all nodes which are node $A$ is a subset of.\nThen in order to push the the blue edge higher, algorithm~\\ref{alg:pushBlueEdge} can be used to push a blue edge higher.\nWhen a new separation with a better weight is found, it can be possible that one of the known separations is dominated by the newly found separation.\nIf that is the case, the dominated separation can be deleted. This leads to the optimization algorithm~\\ref{alg:OptSeparations}\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{Separation ($X, Y$)}\n    \\KwResult{Separation ($X_{new}, Y_{new}$)}\n    $bestWeight~\\longleftarrow~weight(X, Y)$;\\\\\n    $bestSeparation~\\longleftarrow~(X, Y)$;\\\\\n    \\For{$x \\in parent(X) \\setminus parent(X, Y)$}{\n      \\For{$y \\in parent(Y) \\setminus parent(X, Y)$}{\n        \\If{$weight(x, y) < bestWeight$}{\n          continue;\n        }\n\n        \\If{$isWellSeparated(x, y)$}{\n          $bestWeight~\\longleftarrow~weight(x, y)$;\\\\\n          $bestSeparation~\\longleftarrow~(x, y)$;\\\\\n        }\n\n      }\n    }\n\n    \\Return{$bestSeparation$}\n\n    \\caption{pushBlueEdge}\n    \\label{alg:pushBlueEdge}\n  \\end{algorithm}\n\\end{figure}\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{Set of Separations $S$}\n    \\KwResult{Optimized Separations $S_{new}$}\n    \\For{$(A, B) \\in S$}{\n      $(A_{new}, B_{new}) \\longleftarrow pushBlueEdge((A, B))$\n      $S \\longleftarrow S \\setminus {(x, y)~|~(x, y) \\in~S \\land (x, y) \\preceq (A_{new}, B_{new})}$\n    }\n\n    \\Return{$S$}\n\n    \\caption{optimizeSeparations}\n    \\label{alg:OptSeparations}\n  \\end{algorithm}\n\\end{figure}\n\n\\subsection{Distance Query}\nWhen given two nodes $u, v \\in V$ it should be possible to get the shortest path distance as fast as possible.\nTo do this, for every node $u$ all the separations $(A, B)$ are stored where $u \\in A \\lor u \\in B$.\nUsing this, it is trivial to access all the separations of a node which can be used to answer distance queries.\nIn order to do this the separation for which holds $u \\in A \\land v \\in B$ or $v \\in A \\land u \\in B$ needs to be found.\n\n\\subsubsection{Linear Scan}\nWhen given all separations of node $u$, the separation which can answer the query $u, v$ can be found by searching through all the\ngiven separations.\n\n\\subsubsection{Z Order Curve}\n\\textcolor{red}{not implemented\\\\}\nWhen the gridgraph has a hight and a width of $2^n$ for any $n \\in \\mathbb{N}$ a Z-Curve\ncan be used to map from a 2D point $v$ to a number in $\\mathbb{N}$ such that the prefixes of the number in binary format can be used to\nidentify the quadtree nodes which the node $v$ is a member of.\n\n\\subsubsection{Quadtree Prefix}\n\\textcolor{red}{not implemented\\\\}\nSince not all all the gridgraphs have a width and a hight of $2^n$ for any $n \\in \\mathbb{N}$,\nthe quadtree can be used to assign numbers from $n \\in \\mathbb{N}$ for every node $v \\in V$, such that the prefixes of the numbers identify the quadtree nodes a gridgraph node is a member of.\nThese prefixes can be used to build a descision tree for each set of separations such that every separation for any node pair $u, v$ can be found in $\\mathcal{O}(\\log{}n)$.\nSince only 64-bit numbers are being used, the decision tree can only be that high and the search can be considered $\\mathcal{O}(1)$\n\n\n\\section{Node Patches}\nNode selections are set of nodes $(A, B)$ such that:\n\\begin{equation*}\n  \\exists x \\in V: \\forall u \\in A: \\forall v \\in B: x \\in \\pi(u, v)\n\\end{equation*}\n\nTo find such sets, the path between two random nodes $(a_0, b_0)$ is considered and then a node in the middle of the path is used as the barrier node.\nThe sets $\\{a_0\\}$ and $\\{b_0\\}$ can then be used to grow sets of nodes. In an alternating way neigbours of nodes in set $A$ and $B$ are looked at and then\nchecked if they fullfill the property that all shortest paths from the node to the other set of nodes can go over the barrier node $x$.\nIf that is the case the node is added to the set. The random start nodes can be choosen from a set containing all $\\binom{V}{2}$ nodes, and node patches should be searched until for all node pairs $u, v \\in V$ there exists a node patch which can answer the distance query of nodes $u, v$.\nFigure~\\ref{pic:NodePatch} shows such a node patch of two sets.\n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=0.33\\textwidth]{NodePatch.png}\n  \\caption{node patch example}\n  \\label{pic:NodePatch}\n\\end{figure}\n\n\\subsection{Query}\nEach node patch stores its nodes $(A, B)$ and the barrier node $x$.\nFor each node $n$ all node patches $(A, B)$ where $n \\in A \\lor n \\in B$ are stored sorted.\nFinding a node patch which can be used to answer a query $u, v \\in V$ can be done in like it is done for HubLabels.\nWhen the node patch $(A, B)$ with ${u \\in A \\land v \\in B \\lor v \\in A \\land u \\in B}$ is found the query routine can be called\nrecursivly for nodes $u, x$ and $x, v$ where $x$ is the barrier node of the node patch $(A, B)$. This query routine can be seen in Algorithm~\\ref{alg:queryNodePatch}.\n\n\\begin{figure}[ht!]\n  \\begin{algorithm}[H]\n    \\KwData{Node Patche $(A, B, x)$, Nodes $u, v$}\n    \\KwResult{$d_{opt}(u, v)$}\n\n    \\If{$u \\in neig(v)$}{\n      \\Return{1}\n    }\n\n    \\Return{$queryNodePatch(u, x) + queryNodePatch(x, v)$}\n\n    \\caption{queryNodePatch}\n    \\label{alg:queryNodePatch}\n  \\end{algorithm}\n\\end{figure}\n\n\\subsection{Node Patch Optimization}\n\\textcolor{red}{not implemented\\\\}\nSince nodes have a common subsets of associated node patches $(A, B)$ subsets of all node patches can be stored in buckets which then are stored by the nodes, instead of lists of node patches.\nIn order to find optimal buckets $B \\subseteq \\mathcal{P}(S)$ of node patches for a set of separations $S$,\na set of nodes with associated separations ${N = \\{(n, S_n)| n \\in V, S_n \\subseteq S\\}}$, the follwowing musst be assured:\n\\begin{equation*}\n  \\forall (n, S_n) \\in N: \\exists B_n \\in B: \\forall s \\in S_n: \\exists b \\in B_n: s \\in b\n\\end{equation*}\n\nTo get a best possible result for the distance query structure $|B|$ and \\linebreak\n${\\forall (n, S_n) \\in N: |B_n|}$ musst be minimal, where $B_n$ are the buckets node $n$ stores.\n\n\n\\end{document}\n", "meta": {"hexsha": "d17753b6d1e503992323f088d00644fdc94cd515", "size": 15457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/overview/overview.tex", "max_stars_repo_name": "DarkWingMcQuack/GridGraphPathFinder", "max_stars_repo_head_hexsha": "d8f9a237f17516141bf58c8c86d468f3559af5e3", "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": "tex/overview/overview.tex", "max_issues_repo_name": "DarkWingMcQuack/GridGraphPathFinder", "max_issues_repo_head_hexsha": "d8f9a237f17516141bf58c8c86d468f3559af5e3", "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/overview/overview.tex", "max_forks_repo_name": "DarkWingMcQuack/GridGraphPathFinder", "max_forks_repo_head_hexsha": "d8f9a237f17516141bf58c8c86d468f3559af5e3", "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.4166666667, "max_line_length": 288, "alphanum_fraction": 0.6921136055, "num_tokens": 4744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835248143776, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6331247078269538}}
{"text": "\nHere we present the main methods utilized by our project.\n\n\\subsection{Learning an embedding}\n\nThe paper \\cite{self-supervised-learning} presents a way to learn a distance preserving embedding from video frames onto an n-sphere. The goal is to map frames that are close to each other in the video to vectors that are close to each other on the n-sphere as measured by the $L_2$-norm.\n\nThe embedding function is denoted $f(x)$ where $x$ is a frame from a video. We use three types of frames: an anchor frame $x_a$, a positive frame $x_p$ and a negative frame $x_n$. The anchor frame is closer to the positive frame than the negative frame.\n\nEssentially, we want the constraint \\[\n    \\norm{f(x_a) - f(x_p)}^2_2 + \\delta < \\norm{f(x_a) - f(x_n)}^2_2\n    \\] to hold. $\\delta$ is a constant margin parameter.\n\n$f$ is a convolutional neural network. The network is optimized by optimizing a triplet loss function. \\[\n    L(x_a, x_p, x_n) = \\delta + \\norm{f(x_a) - f(x_p)}^2_2 - \\\\\n    \\norm{f(x_a) - f(x_n)}^2_2\n    \\]\n\nThe triplets are either from a single or multiple viewpoints. When using multiple viewpoints, the anchor frame is a random frame sampled from the video. The positive frame is a frame from the exact same time-step but another viewpoint than the anchor frame. The negative frame is sampled from the same viewpoint as the anchor frame outside a margin range around the anchor frame. This enables the network to learn a viewpoint invariant representation of the scene. \\citep{self-supervised-learning}\n\nIn the single viewpoint case which we implement in our experiements, all frames are from the same viewpoint. The anchor frame is again a random frame of the video. The positive frame is within a small margin range of the anchor frame. The negative frame is from outside a larger margin range of the anchor frame. \\citep{self-supervised-learning}\n\n\\subsection{Learning using reinforcement learning}\n\nWe learn to imitate using reinfocement learning. The reward function is defined using the embedding function presented in the previous section.\n\nWe use a huber-style loss: \\[\n    R(\\boldsymbol{v_t}, \\boldsymbol{w_t}) = -\\alpha \\norm{\\boldsymbol{w_t} - \\boldsymbol{v_t}}^2_2 -\\beta \\sqrt{\\gamma + \\norm{\\boldsymbol{w_t} - \\boldsymbol{v_t}}^2_2}\n\\]\n\nHere $\\alpha$ and $\\beta$ are scaling parameters. $\\gamma$ is a small constant to make the equation well defined for almost zero distances. $\\boldsymbol{w_t}$ is an embedding of an image of the robot itself and $\\boldsymbol{v_t}$ is an embedding of the example video frame at timestep t.\n\nWe learn a policy that optimizes the reward function using the proximal policy optimization algorithm (PPO) \\citep{ppo}. PPO is a robust, simple, model free policy gradient algorithm. It optimizes a clipped loss function: \\[\n    L(\\theta) = \\hat{E}_t[\\min{r_t(\\theta)\\hat{A}_t, clip(r_t(\\theta), 1 - \\epsilon, 1 + \\epsilon)\\hat{A}_t})]\n\\]\n$r_t(\\theta)$ is the ratio between the probability of the action taken under the current policy and the policy before the previous update. $\\hat{A}_t$ is the advantage defined: \\[\n    \\hat{A}_t = -V(s_t) + r_t + \\gamma r_{t+1} + ... + \\gamma^{T-t+1}r_{T-1} + \\gamma^T V(s_T)\n    \\]\n\nThe policy and value functions are neural networks. This surrogate reward function can be updated using multiple epochs of minibatch updates, making it well suited for neural networks. \\citep{ppo}\n\n\n", "meta": {"hexsha": "e4e38a940d42a526b13d6046a7618f24abaa31a6", "size": 3372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/02-methods.tex", "max_stars_repo_name": "gamleksi/charlatan", "max_stars_repo_head_hexsha": "5961e539ec366cb562d0a35129e99a164c3053c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-01-08T17:39:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T07:13:00.000Z", "max_issues_repo_path": "report/02-methods.tex", "max_issues_repo_name": "gamleksi/charlatan", "max_issues_repo_head_hexsha": "5961e539ec366cb562d0a35129e99a164c3053c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-15T14:30:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-15T14:30:44.000Z", "max_forks_repo_path": "report/02-methods.tex", "max_forks_repo_name": "gamleksi/charlatan", "max_forks_repo_head_hexsha": "5961e539ec366cb562d0a35129e99a164c3053c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-09-03T12:08:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-02T05:07:06.000Z", "avg_line_length": 78.4186046512, "max_line_length": 497, "alphanum_fraction": 0.7455516014, "num_tokens": 876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.6893056104028799, "lm_q1q2_score": 0.6331135852508324}}
{"text": "\\chapter{Formulae and Identities}\n%TODO: Have header say appendix in appendix\n\nThese will not be given. You are expected to know them.\n\n\\section{Pure Mathematics}\n\\subsection{Quadratic Equations}\n\\[ax^2+bx+c=0 \\iff  x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}\\]\n\n\\subsection{Laws of Indices} \n\\begin{align*} \n    a^xa^y &\\equiv a^{x+y}\\\\\n    a^x \\div a^y &\\equiv a^{x-y}\\\\\n(a^x)^y &\\equiv a^{xy}\n\\end{align*}\n\n\\subsection{Laws of Logarithms}\n\\(\n    x = a^n \\iff n = \\log_ax\n\\) where \\(a>0\\) and \\(x>0\\)\n\\begin{align*}\n    \\log_ax + \\log_ay &\\equiv \\log_a(xy) \\\\\n    \\log_ax - \\log_ay &\\equiv \\log_a(\\frac{x}{y}) \\\\\n    k\\log_ax &\\equiv \\log_a(x^k)\n\\end{align*}\n\n\\subsection{Coordinate Geometry}\n\nA straight line graph, gradient \\(m\\) passing through \\( (x_1, y_1) \\) has equation\n\\[\n    y-y_1 = m(x-x_1)\n\\]\n\\noindent\nStraight lines with gradients \\(m_1\\) and \\(m_2\\) are perpendicular when  \\( m_1m_2=-1 \\)\n\n\\subsection{Sequences}\n\nGeneral term of an arithmetic progression: \n\\[u_n=a+(n-1)d\\]\nGeneral term of a geometric progression:\n\\[u_n=ar^{n-1}\\]\n\n\\subsection{Trigonometry}\nIn the triangle ABC:\n\\begin{align*}\n    \\frac{a}{\\sin A} &= \\frac{b}{\\sin B} = \\frac{c}{\\sin C} \\\\\n    a^2 &= b^2 + c^2 -2bc\\cos A \\\\\n    \\text{Area} &= \\frac{ab\\sin C}{2}\n\\end{align*}\n\n\\begin{align*}\n1 &\\equiv \\cos^2A+\\sin^2A \\\\\n\\sec^2A&\\equiv 1+\\tan^2A\\\\\n\\csc^2A&\\equiv 1+\\cot^2A\\\\\n\\sin 2A &\\equiv 2\\sin A \\cos A \\\\\n\\cos 2A &\\equiv \\cos^2A-\\sin^2A \\\\\n\\tan 2A &\\equiv \\frac{2\\tan A}{1-\\tan^2A}\n\\end{align*}\n\n\\subsection{Mensuration}\n\nCircumference and Area of circle, radius \\(r\\) and diameter \\(d\\)\n\\begin{align*} \nC&=2\\pi r = \\pi d \\\\\nA&=\\pi r^2 \n\\end{align*}\nPythagoras’ Theorem: In any right-angled triangle where \\(a\\), \n\\(b\\) and \\(c\\) are the lengths of the sides and \\(c\\) is the hypotenuse:\n\\[c^2=a^2+b^2\\]\n\n\\noindent\nArea of a trapezium where where \\(a\\) and \\(b\\) are the lengths of the parallel\nsides and \\(h\\) is their perpendicular separation:\n\\[\\text{Area}=\\frac{(a+b)h}{2}\\]\n\\par\n\n\\[\n    \\text{Volume of a prism} = \\text{area of cross section} \\times\n    \\text{length}\n\\]\n\n\\noindent\nFor a circle of radius \\(r\\), where an angle at the centre of \\(\\theta\\) radians\nsubtends an arc of length \\(l\\) and encloses an associated sector of area \\(a\\):\n\\begin{align*}\nl&=r\\theta\\\\\na&=\\frac{r^2\\theta}{2}\n\\end{align*}\n\\subsection{Complex Numbers}\nFor two complex numbers \\(z_1=r_1e^{i\\theta_1}\\) and \\(z_2=r_2e^{i\\theta_2}\\)\n\\begin{align*}\nz_1z_2 &= r_1r_2e^{i(\\theta_1+\\theta_2)}\\\\\n\\frac{z_1}{z_2}&= \\frac{r_1}{r_2} e^{i(\\theta_1-\\theta_2)}\n\\end{align*}\n\\subsubsection{Loci in the Argand diagram}\n\\(|z-a| = r \\) is a circle radius \\(r\\)  centred at \\(a\\)\n\\par\n\\(\\arg(z-a) = \\theta \\) is a half line drawn from \\(a\\) at angle \\(\\theta\\) to a\nline parallel to the positive real axis\n\\subsubsection{Exponential Form}\n\\[          \ne^{i\\theta}=\\cos\\theta+i\\sin\\theta\n\\]\n\\subsection{Matrices}\nFor a $2$ by $2$ matrix\n$\\begin{psmallmatrix}a & b\\\\ c & d\\end{psmallmatrix}$\nthe determinant\n$ \\Delta =  \\begin{vsmallmatrix}a & b\\\\ c & d\\end{vsmallmatrix} = ad-bc$. \nThe inverse is\n$\n\\frac{1}{\\Delta} \\begin{psmallmatrix}d & -b\\\\ -c & a\\end{psmallmatrix}\n$\n\\par\n\nThe transformation represented by matrix $\\mathbf{AB}$ is the transformation\nrepresented by matrix $\\mathbf{B}$ followed by the transformation represented by\nmatrix $\\mathbf{A}$.\n\\par\n\nFor matrices $\\mathbf{A}$, $\\mathbf{B}$: $(\\mathbf{AB})^{-1}=\\mathbf{A}^{-1}\\mathbf{B}^{-1}$\n\\subsection{Algebra}\n\\[\n    \\sum_{r=1}^nr=\\frac{n(n+1)}{2}\n\\]\nFor $ax^2+bx+c=0$ with roots $\\alpha$ and $\\beta$:\n\\begin{align*}\n\\alpha+\\beta &= \\frac{-b}{a}\\\\\n\\alpha\\beta&=\\frac{c}{a}\n\\end{align*}\nFor $ax^3+bx^2+cx+d=0$ with roots $\\alpha$, $\\beta$ and $\\gamma$:\n\\begin{align*}\n\\sum\\alpha &= \\frac{-b}{a}\\\\\n\\sum\\alpha\\beta&=\\frac{c}{a}\\\\\n\\alpha\\beta\\gamma&=\\frac{-d}{a}\n\\end{align*}\n\n\\subsection{Hyperbolic Functions}\n\\begin{align*}\n\\cosh x &\\equiv \\frac{e^x+e^{-x}}{2}\\\\\n\\sinh x &\\equiv \\frac{e^x-e^{-x}}{2}\\\\\n\\tanh x &\\equiv \\frac{\\sinh x}{\\cosh x }\n\\end{align*}\n\n\\subsection{Calculus and Differential Equations}\n\\subsubsection{Differentiation}\n\\begin{align*}\n    &\\frac{d}{dx} x^n \\equiv nx^{n-1}\\\\\n    &\\frac{d}{dx} \\sin kx   \\equiv k\\cos kx\\\\\n    &\\frac{d}{dx} \\cos kx   \\equiv -k\\sin kx\\\\\n    &\\frac{d}{dx} \\sinh kx  \\equiv k\\cosh kx\\\\\n    &\\frac{d}{dx} \\cosh kx  \\equiv k\\sinh kx \\\\\n    &\\frac{d}{dx} e^{kx}    \\equiv ke^{kx}\\\\\n    &\\frac{d}{dx} \\ln x     \\equiv \\frac{1}{x}\\\\\n    &\\frac{d}{dx} f(x)+g(x) \\equiv f'(x)+g'(x)\\\\\n    &\\frac{d}{dx} f(x)g(x)  \\equiv f'(x)g(x) + f(x)g'(x) \\\\\n    &\\frac{d}{dx} f(g(x))   \\equiv f'(g(x))g'(x)\n\\end{align*}\n\\subsubsection{Integration}\n\\begin{align*}\n    &\\int x^n           \\,dx \\equiv \\frac{x^{n+1}}{n+1} + c \\ \\text{where}\\  n\\neq -1 \\\\\n    &\\int \\cos kx       \\,dx \\equiv \\frac{\\sin kx}{k} + c\\\\\n    &\\int \\sin kx       \\,dx \\equiv \\frac{-\\cos kx}{k} + c\\\\\n    &\\int \\cosh kx      \\,dx \\equiv \\frac{\\sinh kx}{k} + c\\\\\n    &\\int \\sinh kx      \\,dx \\equiv \\frac{\\cosh kx}{k} + c\\\\\n    &\\int e^{kx}        \\,dx \\equiv \\frac{e^{kx}}{k} + c\\\\\n    &\\int \\frac{1}{x}   \\,dx \\equiv \\ln|x|+c \\,\\text{where}\\,x\\neq 0\\\\\n    &\\int f'(x)+g'(x)   \\,dx \\equiv f(x)+g(x)+c\\\\\n    &\\int f'(g(x))g'(x) \\,dx \\equiv f(g(x))+c\n\\end{align*}\n\n\\subsubsection{Area under a curve}\n\\[\n    \\int_a^b y\\,dx \\ \\text{where} \\ y\\geq 0\n\\]\n\n\\subsubsection{Volumes of revolution about the x and y axes}\n\\begin{align*}\n    V_x &= \\pi\\int_a^b y^2 \\,dx\\\\\n    V_y &= \\pi\\int_c^d x^2 \\, dy\n\\end{align*}\n\n\\subsubsection{Simple Harmonic Motion}\n\\[\\ddot{x}=-\\omega^2x\\]\n\n%TODO: Vectors\n\n%TODO: Non-pure core\n\n\\chapter{Number Sets}\n\\section{Integers}\n\\begin{itemize}\n    \\item $\\natplus$: Positive integers without $0$. $\\{\\,1,\\, 2,\\, 3\\,\\dots\\,\\}$\n    \\item $\\natzero$: Positive integers with $0$. $\\{\\,0,\\,1,\\, 2,\\, 3\\,\\dots\\,\\}$\n    \\item $\\ints$: Integers. $\\{\\, \\dots \\,-3,\\,-2,\\,-1,\\,0,\\,1,\\,2,\\,3\\,\\dots\\,\\}$\n\\end{itemize}\n\\section{Unused Integers}\nI will try to avoid these as they are ambiguous.\n\\begin{itemize}\n    \\item $\\mathbb{N}$: Natural numbers. May or may not include $0$. I will use \n            $\\natplus$ or $natzero$ to be explicit.\n\\end{itemize}\n\\section{Non-Integers}\n\\begin{itemize}\n    \\item $\\rationals$: Numbers that can be expressed as a fraction: \n        $\\rationals=\\{\\, \\frac{p}{q} \\,\\mid\\, p\\in\\ints,\\, q\\in\\natplus \\,\\}$\n    \\item $\\reals$: Real numbers. The definition gets axiomatic fast, so I will just\n                    say that they are just $1$ number (not a matrix/vector) and are\n                    not complex / imaginary.\n    \\item $\\complexs$: A number with a real part and a complex part. \n            $\\complexs = \\{\\, a+bi \\,\\mid\\, a\\in\\reals\\,b\\in\\reals\\,\\}$\n                       \n\\end{itemize}\n\n% \\begin{tikzpicture}[fill=gray]\n%     % left hand\n%     \\scope\n%     \\clip (-2,-2) rectangle (2,2)\n%           (1,0) circle (1);\n%     \\fill (0,0) circle (1);\n%     \\endscope\n%     % right hand\n%     \\scope\n%     \\clip (-2,-2) rectangle (2,2)\n%           (0,0) circle (1);\n%     \\fill (1,0) circle (1);\n%     \\endscope\n%     % outline\n%     \\draw (0,0) circle (1) (0,1)  node [text=black,above] {$A$}\n%           (1,0) circle (1) (1,1)  node [text=black,above] {$B$}\n%           (-2,-2) rectangle (3,2) node [text=black,above] {$H$};\n% \\end{tikzpicture}", "meta": {"hexsha": "670aff296ed917f8d9e8cdb8cfdf756caa603093", "size": 7215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/a-level-notes/furthermath/appendices.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/appendices.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/appendices.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.2337662338, "max_line_length": 92, "alphanum_fraction": 0.5886347886, "num_tokens": 2851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6330718179790892}}
{"text": "\\documentclass{article}\n\\usepackage[a4paper, total={6in, 9in}]{geometry}\n\\usepackage{fancyhdr}\n\\usepackage{amsmath}\n\\usepackage{algorithm}\n\\usepackage{algpseudocode}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{proof}{Proof}[section]\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{DanDoge}\n\\lhead{Notes on RSA}\n\\rfoot{Page \\thepage}\n\\cfoot{latest version: 2018/02/12}\n\n\\title{Notes on RSA}\n\\date{2018-02-12}\n\\author{DanDoge}\n\n\\begin{document}\n\\section{public-key cryptosystems}\n  \\paragraph{} each participant has a \\textit{public key} and a \\textit{secret key}. these keys specify one-to-one functions from $\\mathcal{D}$ to itself. for any participant, the public adn secret keys are a \\\"matched pair\\\", $i.e.$\n  \\begin{equation}\n    M\\ =\\ S_A(P_A(M)),\n  \\end{equation}\n  for any $M \\in \\mathcal{D}$. we require one must keep his secret key secret, and no one is able to compute the secret key function in any practical amount of time, even one can compute the public key function efficiently. the scenario for sending a message is as follows:(suppose A wants to send a message to B)\n  \\begin{itemize}\n    \\item A obtains B's public key $P_B$\n    \\item A computes the \\textit{ciphertext} $C = P_B(M)$, and send $C$ to B\n    \\item B applies his secret key $S_B$ to retrieve the original message $S_B(C) = M$\n  \\end{itemize}\n  similarly, we can implement digital signatures:\n  \\begin{itemize}\n    \\item B computes his \\textit{digital signature} $\\sigma$ = $S_B{M^{'}}$\n    \\item B sends pair $(M^{'}, \\sigma)$ to A\n    \\item A can verify that this message is from B by verify the equation $M^{'} = P_A(\\sigma)$\n  \\end{itemize}\n\n\\section{the RSA cryptosystem}\n  \\paragraph{} one creates one's public and secret keys with the following procedure:\n  \\begin{itemize}\n    \\item selete two large prime numbers $p$ and $q$ at random\n    \\item conpute $n = pq$\n    \\item selete a small odd integer $e$ that is prime to $\\phi(n)$ = $(p - 1)(q - 1)$\n    \\item compute $d$ as the inverse of $e$, modulo $\\phi(n)$\n    \\item publish $P = (e, n)$ as the $\\mathbf{RSA public key}$.\n    \\item keep pair $S = (d, n)$ as the $\\mathbf{RSA secret key}$.\n  \\end{itemize}\n  and the function that public key specifies is $P(M) = M^e$ mod $n$, and secret key, $S(C) = C^d$ mod $n$. the correctness of RSA is proved from Fremat's Theorem, and the security of RSA rests on the difficulty of factoring large integers, although this is not proven.\n\\end{document}\n", "meta": {"hexsha": "253259f7e58d944d8fcc567b5c4afec0f7ca08bd", "size": 2448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/RSA.tex", "max_stars_repo_name": "DanDoge/notes-on-algorithms", "max_stars_repo_head_hexsha": "8822e4ed1a60a4cf516f65e31637f8e3e65fd19e", "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": "src/RSA.tex", "max_issues_repo_name": "DanDoge/notes-on-algorithms", "max_issues_repo_head_hexsha": "8822e4ed1a60a4cf516f65e31637f8e3e65fd19e", "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": "src/RSA.tex", "max_forks_repo_name": "DanDoge/notes-on-algorithms", "max_forks_repo_head_hexsha": "8822e4ed1a60a4cf516f65e31637f8e3e65fd19e", "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": 45.3333333333, "max_line_length": 313, "alphanum_fraction": 0.6993464052, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6330718160514287}}
{"text": "\\section{Clean Automata}\n\nA state is $q$ \\textbf{reachable} from $p$ if there is a computation from $p$ to $q$.\nA state is \\textbf{accessible} if it is reachable from the initial state.\nA state is \\textbf{post-accessible} if a final state can be reached from it.\nA state is \\textbf{useful} if it is accessible and post-accessible.\n\nAn automaton is \\textbf{clean} if all the states are useful.\n", "meta": {"hexsha": "318fa2186ab7686ce878cad3b4d6f058d76263af", "size": 393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/clean-automata.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/clean-automata.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/clean-automata.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.6666666667, "max_line_length": 85, "alphanum_fraction": 0.7506361323, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6330718102684479}}
{"text": "\\newpage\n\\section{Second-order Differential Equations}\n\n\\subsection{General Theory of Homogeneous Linear Equations}\n  The standard form for a general second order ordinary differential equation is\n\n  \\[\n    x''(t)+p(t)x'(t)+q(t)x(t)=f(t).\n  \\]\n  \n  For us, $p(t)$ and $q(t)$ are typically going to be constants. Also, we know that if $f(t)=0$, the equation is homogeneous.\n\n  \\begin{lemma}\n    GGiven an equation in the form \n\n    \\[\n      x''(t)+p(t)x'(t)+q(t)x(t)=0,\n    \\]\n\n    if $x_1(t)$ and $x_2(t)$ are solutions to equation (3.2), then \n    \\[\\]\n\n    \\[\n      x(t)=C_1x_1(t)+C_2x_2(t)\n    \\]\n\n    is also a solution to equation (3.1) for all $C_1,C_2$'s. Equation (3.3) is the general solution to a homogeneous ODE\n  \\end{lemma}\n\n  Let's take a look at an application of lemma (3.1.1).\n\n  \\begin{eg}\n    Consider the equation\n\n    \\[\n    t^2x'''+2tx''-6x'=0.\n    \\]\n\n    This equation is a third order, linear and homogeneous, but not autonomous ordinary differential equation. Let's put this differential equation into standard form:\n\n    \\[\n    x''+\\frac{2}{t}x''+\\frac{6}{t^2}x'=0\n    \\]\n\n    As long as $t_0\\neq0$, we have a unique solution if given 3 initial conditions. The domain of this ordinary differential equation is $t>0,t<0$. Earlier, in section 3.1, we showed that $1,t^3,\\frac{1}{t^2}$ were all solutions. Because this ordinary differential equation is linear and homogeneous, we know that \n\n    \\[\n    x(t)=C_11+C_2t^3+C_3\\frac{1}{t^2},\n    \\]\n\n    is also a solution for all $C_1,C_2,C_3$. Just note, equation (3.6) is a linear combination of $1,t^3,\\frac{1}{t^2}$. So, this is a \\underline{general solution} as long as the functions, $1,t^3,\\frac{1}{t^2}$ are all “different” from each other.\n  \\end{eg}\n\n  What is “different”? Different means no one function in a set can be written as a linear combination of other functions in the set. Different means that all the functions are linearly independent. More generally, if \n\n  \\[\n    C_1f_1(t)+C_2f_2(t)+\\dots+C_nf_n(t)=0\n  \\]\n\n  \\begin{theorem}\n    We can instead test for linear independence by using the wronskian,\n\n    \\[\n      w(f_1,f_2)(t)=det\\begin{vmatrix}\n        f_1(t)&&f_2(t)\\\\f'_1(t)&&f'_2(t)\\\\\n      \\end{vmatrix}\n    \\]\n\n    \\begin{itemize}\n      \\item If $w(t)=0$ for all $t$'s, then $\\{f_1,f_2\\}$ are linearly dependent.\n      \\item If $w(t)=0$ for all $t$'s, then $\\{f_1,f_2\\}$ are linearly independent.\n    \\end{itemize}\n  \\end{theorem}\n\n  Now, if we try to use the wronskian on problem 16, we do it like so:\n\n  \\begin{align*}\n    w(t)=\n    \\begin{vmatrix}\n      1&&t^3&&\\frac{1}{t^2}\\\\\n      0&&3t^2&&-\\frac{2}{t^2}\\\\\n      0&&6t&&\\frac{6}{t^4}\\\\\n    \\end{vmatrix}\\\\\n    \\to 1\\times\n    \\begin{vmatrix}\n      3t^2&&-\\frac{2}{t^2}\\\\\n      6t&&\\frac{6}{t^4}\\\\\n    \\end{vmatrix}\\\\\n    =\\frac{18}{t^2}+\\frac{12}{t^2}=\\frac{30}{t^2}\\neq0\n  \\end{align*}\n\n  So we know that $\\{1,t^3,\\frac{1}{t^3}\\}$ are linearly independent. \n\n  Let's consider another problem where we need to show that the solutions are linearly dependent.\n\n  \\begin{eg}\n    Let's consider the equation $y''(x)=-9y$, which has the solutions $\\{\\cos(3x),\\sin(3x)\\}$ and let's show that the two solutions are linearly independent:\n\n  \\[\n    w(x)=\\begin{bmatrix} \\cos(3t)&\\sin(3t)\\\\-3\\sin(3t)&3\\cos(3t) \\end{bmatrix}\n    =3\\cos^2(3x)+3\\sin^2(3x)=3\\neq0\n  \\]\n  \n  Which means that both solutions are valid for this ordinary differential equation. We can turn our original equation into $y''(x)+9y=0$ which is a homogeneous ordinary differential equation. Our $p(x)=0$, and because we know that $w(x)=Ce^{-\\int p(x)dx}$, we know that the solution to our equation is 0.\n  \\end{eg}\n\n  \\begin{theorem}\n    What to we do when solving linear non-homogeneous ordinary differential equations?\n    \\begin{enumerate}\n      \\item Solve the associated homogeneous ODE $\\to X_h(t)$, which will have many unknown constants\n      \\item Find one solution to non-homogeneous ODE $\\to X_p(t)$\n    \\end{enumerate}\n\n    The general solution to the original non-homogeneous ODE is \n\n    \\[\n      x(t)=x_h(t)+x_p(t)\n    \\]\n  \\end{theorem}\n\n  Let's try out this new theorem on an example problem.\n\n  \\begin{eg}\n    Consider the differential equation $y''-5y'-6y=4x$. We claim that \n\n    \\[\n      y(x)=c_1e^{-x}+c_2e^{6x}-\\frac{2}{3}+\\frac{5}{9}\n    \\]\n\n    Are $\\{e^{-x},e^{6x}\\}$ linearly independent? Verify both solutions to equation (3.14).\n\n    \\begin{align*}\n      w(x)&=\\begin{bmatrix} e^{-x}&e^{6x}\\\\-e^{-x}&6e^{6x} \\end{bmatrix} \\\\\n          &=6e^{5x}+e^{5x}=7e^{5x}\n    \\end{align*}\n\n    Now we need to verify that this is a solution:\n\n    \\begin{align*}\n      y'(x)&=-C_1e^{-x}+6C_2e^{6x}-\\frac{2}{3}\\\\\n      y''(x)&=C_1e^{-x}+36C_2e^{6x}\n    \\end{align*}\n\n     Let's see if the left-hand side is equal to $4x$ like it was above.\n\n     \\begin{align*}\n       y''-5y'-6y=\\left[C_1e^{-x}+36C_2e^{6x}\\right]&-5\\left[-C_1e^{-x}+6C_2e^{6x}-\\frac{2}{3}\\right]\\\\\n                                                    &-6\\left[C_1e^{-x}+C_2e^{6x}-\\frac{2}{3}+\\frac{5}{9}\\right]\n     \\end{align*}\n     \\begin{align*}\n       &=C_1[e^{-x}+te^{-x}-6e^{-x}]+C_2[36e^{6x}-30e^{6x}-6e^{6x}]+\\left[\\frac{10}{3}+4x-\\frac{10}{3}\\right]\\\\\n       &=0+0+4x\n     .\\end{align*}\n\n  \\end{eg}\n\n\\subsection{Homogeneous Linear Equations with Constant Coefficients}\n\n  Homogeneous ordinary differential equations are ones that come in the form \n  \\[\n    ay''+by'+cy=0\n  \\]\n\n  The first method of solving homogeneous linear equations with constant coefficients is the method of lucky guess. In this method, we let $y(x)=e^{rx}$. If we take the multiple derivatives of $e^{rx}$, we can find what $y'(x)$ and $y''(x)$ equal. Now we can plug in the $e^{rx}$ into our equation to get \n\n  \\begin{align*}\n    ar^2e^{rx}+bre^{rx}+ce^{rx}=0\\\\\n    e^{rx}[ar^2+br+c]=0\n  .\\end{align*}\n  \\[\n    \\boxed{ar^2+br+c=0}\n  \\]\n  \n  There are 3 distinct cases for the roots of this equation.\n  \\begin{enumerate}\n    \\item 2 real distinct roots.\n    \\item 1 repeated root.\n    \\item 2 complex conjugate roots ($A+Bi$).\n  \\end{enumerate}\n\n  Let's take a look at an example of this method in action.\n\n  \\begin{eg}\n    Consider the equation \n    \\[\n    y''-5y'-6y=0\n    .\\] \n    We are going to let $y(x)=e^{rx}$. We can skip adding $e^{rx}$ to the beginning of each term because we can just divide that over in our minds. After going through that we get \n    \\begin{align*}\n      r^2-5r-6&=0\\\\\n      (r-6)(r+1)&=0\\\\\n      r&=6,-1\n    .\\end{align*}\n    \n    From this, we know that our two solutions are $y_1(x)=e^{6x},y_2(x)=e^{-x}$. Our general solution is \n    \\[\n      \\boxed{y(x)=C_1 e^{6x}+C_2e^{-x}}\n    \\]\n    Now all we need to do is check the wronskian $W(x)$ to make sure that $\\{e^{r_1x},e^{r_2x}\\}$ are linearly independent.\n  \\end{eg}\n\n  Let's explore a case of a real repeated root. Let's look at the equation\n  \\[\n  y''-8y'+16=0 \n  .\\] \n  We can let $y(t)=e^{rt}$, to get\n  \\[\n  r^2-8r+16=0\n  .\\] \n  Our roots for $r$ are 4 and 4. One of our solutions should be $y_1(t)=e^{4t}$, but because we have a repeated root, I claim that $y_2(t)=te^{4t}$. We can verify that this is a repeated root by putting it in a wronskian:\n    \\begin{align*}\n      w(t)&=\\left| \n      \\begin{matrix}\n        e^{4t}&te^{4t}\\\\\n        4e^{4t}&e^{4t}+4te^{4t}\n      \\end{matrix}\n      \\right|\\\\\n          &=e^{8t}+4te^{8t}-4te^{8t}\\\\\n          &=e^{8t}\\neq 0\n    .\\end{align*}\n    Because the wronskian result was not equal to zero, we know that these are two linearly independent solutions. Our general solution in this case would be\n    \\[\n      y(t)=C_1e^{4t}+C_2te^{4t}\n    .\\] \n    If we were to solve a 4th order ordinary differential equation, our general solution would look something like this:\n    \\[\n      y(t)=C_1e^{2t}+C_2e^{-3t}+C_3te^{-3t}+C_4t^2e^{-3t}\n    .\\] \n    As you can see, the main difference between the second and third order ordinary differential equations is the amount of roots you need to take. Let's take a look at the third case, having 2 complex conjugate values for $r=\\alpha\\pm i\\beta$.\\newline\\newline\n    Consider the equation\n    \\[\n    y''-2y'+5y=0\n    .\\] \n    Let $y(t)=e^{rt}$. Our previous equation will turn into $r^2-2r+5=0$, and we will need to use the quadratic formula for this case.\n\n    \\begin{align*}\n      r&=\\frac{2\\pm\\sqrt{4-20} }{2}\\\\\n       &=\\frac{2\\pm\\sqrt{-16} }{2}\\\\\n       &=1\\pm 2i\n    .\\end{align*}\n\n    Because of Euler's identity,\n    \\[\n      e^{i\\theta}=\\cos(\\theta)+i\\sin(\\theta)\n    ,\\]\n    we can determine that the general solution of this ordinary differential equation is\n    \\[\n    y(t)=C_1e^{1t}\\cos(2t)+C_2e^{1t}\\sin(2t)\n    .\\] \n    \\begin{eg}\n      Solve the homogeneous linear ordinary differential equation,\n      \\[\n      x'''+3x''-4x'-12x=0\n      .\\] \n      Let $x(t)=e^{rt}$, this means that \n      \\begin{align*}\n        x'&=re^{rt}\\\\\n        x''&=r^2e^{rt}\\\\\n        x'''=r^3e^{rt}\n      .\\end{align*}\n    Our expanded out equation is \n    \\[\n      e^{rt}[r^3+3r^2-4r-12]=0\n    .\\] \n    From this, we can see that our roots are $r=2,-2,-3$, which means that our general solution is\n    \\[\n      x(t)=C_1e^{2t}+C_2e^{-2t}+C_3e^{-3t}\n    .\\] \n    \\end{eg}\n\n\\subsection{The Spring-Mass Equation}\n\n  The spring-mass equation is a variation of Hooke's law, which states\n  \\[\n    F_{spring}=-kx(k>0)\n  .\\] \n  This tries to bring mass back to equilibrium where $x(t)$ is the distance of the mass from its equilibrium position at time $t$. The differential version of the equation is\n  \\[\n    mx''+bx'+kx=F(t)\n  .\\] \n  Where $mx''$ is the acceleration, $bx'$ is the resistance friction, $kx$ is the spring force and $F(t)$ is any extra force acting on the system. Where is gravity within this equation? It drops out because the stretching of the string due to gravity puts the block attached to the string into equilibrium.\\newline\\newline\n  When you first attach the mass and the mass stops moving,\n  \\[\n    m(0)=-k(s)-b(0)-mg\\to mg=ks\\to k\n  .\\] \n  \\begin{eg}\n    A mass weighing 10 pounds stretches a string $\\frac{1}{4}ft$. Assuming no dampening, find the amplitude period of oscillations of the mass if it is released from a point $\\frac{1}{10}ft$below it's equilibrium position with an initial upward velocity of $\\frac{1}{20}\\frac{ft}{s}$.\\newline\n    Because the mass weighs 10 pounds, $mg=10$, which means that $m=\\frac{10}{32}=\\frac{5}{16}\\frac{lbs^2}{ft}$. The first thing we need to do is find K. This can be done by setting $mg=ks$ and solving for $k$.\n    \\begin{align*}\n      10&=\\frac{1}{4}k\\\\\n      k=\\frac{10}{\\frac{1}{4}}=40\\\\\n      [k]=\\frac{10lb}{\\frac{1}{ft}}=\\left[\\frac{lb}{ft}\\right]\n    .\\end{align*}\n    Our ordinary differential equation is going to be \n    \\[\n    \\frac{5}{16}x''+40x=0\n    .\\] \n    We are given the initial values of $x'(0)=-\\frac{1}{20}$ and $x(0)=-\\frac{1}{10}$. We get the ordinary differential  equation \n    \\begin{align*}\n      \\to x''+128x=0\\\\\n    .\\end{align*}\n    Furthermore, we are going to let $x(t)=e^{rt}$. This gives us \n    \\begin{align*}\n      r^2+128&=0\\\\\n      r^2&=-128\\\\\n      r&=\\pm\\sqrt{-128}=\\pm_8\\sqrt{2i} \n    .\\end{align*}\n    The general solution to our ordinary differential equation in this situation is \n    \\[\n      x(t)=C_1\\cos\\left( 8\\sqrt{2} t \\right) +C_2\\sin\\left( 8\\sqrt{2} t \\right) \n    .\\]\n    This gives us that the angular frequency of our system, $\\beta=8\\sqrt{2} \\left[ \\frac{1}{s} \\right] $, and the period of our system, $T=\\frac{\\pi}{4\\sqrt{2} }s$.\\newline\n    NOTE: In general, the natural frequency of a spring mass system is $\\omega_0=8\\sqrt{2} $.\\newline\n    Now we need to apply our initial conditions to find $C_1,C_2 $.\n    \\begin{align*}\n      x'(t)&=-8\\sqrt{2} C_1\\sin\\left( 8\\sqrt{2} t \\right) +8\\sqrt{2} C_2\\cos\\left( 8\\sqrt{2} t \\right) \\\\\n      x(0)&=C_1=-\\frac{1}{10}\\\\\n      x'(0)&=8\\sqrt{2} C_2=\\frac{1}{10}\n    .\\end{align*}\n    This gives us that our equation of motion is \n    \\begin{align*}\n      x(t)&=-\\frac{1}{10}\\cos\\left( 8\\sqrt{2} t \\right) +\\frac{1}{160\\sqrt{2} }\\sin\\left( 8\\sqrt{t}  \\right) \\\\\n          &=R\\sin\\left( \\beta t+\\phi \\right) \\\\\n      C_1&=R\\sin\\phi\\\\\n      C_2&=R\\cos\\phi\\\\\n      C_1^2+C_2^2&=R^2\\\\\n      \\sqrt{\\left( -\\frac{1}{10} \\right) ^2+\\left( \\frac{1}{160\\sqrt{2} } \\right) ^2} &= R\\\\\n      \\sqrt{\\frac{513}{51200}} &=R\n    \\end{align*}\n    \\[\n      \\boxed{R\\approx0.100ft}\n    .\\] \n    \\begin{align*}\n      \\phi&=tan^{-1}\\left( \\frac{C_1}{C_2} \\right)+\\frac{1}{60}\\sqrt{2} \\sin(8\\sqrt{2} t) \\\\\n          &=tan^{-1}\\left( -16\\sqrt{2}  \\right) \\\\\n      \\phi&=-1.4226rad\\\\\n      x(t)&= -\\frac{1}{10}\\cos\\left( 8\\sqrt{2}t  \\right)+\\frac{1}{160\\sqrt{2} }\\sin\\left( 8\\sqrt{2}t  \\right) \\\\\n          &\\approx 0.1001\\sin\\left( 8\\sqrt{2} t-1.5266 \\right) \n    .\\end{align*}\n  \\end{eg}\n\n  $x(t)$ is the displacement of mass from equilibrium at time $t$. The following is the general formula for a mass-spring system.\n  \\[\n    mx''+bx'+kx=0 \\text{ where $mbk>0$}\n  .\\] \n  Let's consider a dampening situation. If we let $x(t)=e^{rt}$, then \n  \\begin{align*}\n  mr^2+br+k=0\\\\\n  \\to r=\\frac{-b\\pm\\sqrt{b^2-4mk} }{2m}\n  .\\end{align*}\n  \\begin{itemize}\n    \\item Repeated $r$ values.\n      For this case, we are going to get $b^2-4mk=0$, which is a critically dampened system. This would make $r=-\\frac{b}{2m},-\\frac{b}{2m}$, which would make our general solution \n      \\[\n        x(t)=C_1e^{-\\frac{b}{2m}t}+C_2te^{-\\frac{b}{2m}t}\n      .\\] \n      If we take the $\\lim_{t \\to \\infty} x(t) $, we can see that this equation goes to zero.\n    \\item 2 real distinct roots.\n      \\[\n        r_1=\\frac{-b+\\sqrt{b^2-4mk} }{2m}<b, r_2=\\frac{-b-\\sqrt{b^2-4mk} }{2m} <0 \n      .\\] \n      If $b^2-4mk > 0,$ we have an over dampened system. $r<r_1<0$. The solution to this equation would be \n      \\[\n        x(t)=C_1e^{r_1t}+C_2e^{r_2t}\n      .\\] \n      The limit as this ordinary differential equation goes to infinity is zero.\n    \\item 2 real complex conjugate roots. If \n      \\[\n      r=-\\frac{b}{2m}\\pm i \\frac{\\sqrt{4mk-b^2} }{2m}\n      .\\] \n      Our $\\alpha = -\\frac{b}{2m}$, and our $\\beta=i \\frac{\\sqrt{4mk-b^2} }{2m}$. Our general solution in this scenario would be \n      \\[\n        x(t)=C_1e^{-\\frac{b}{2m}t}\\cos\\left( i \\frac{\\sqrt{4mk-b^2} }{2m}t \\right) +C_2e^{-\\frac{b}{2m}t}\\sin\\left( i \\frac{\\sqrt{4mk-b^2} }{2m}t \\right) \n      .\\] \n      \\[\n        \\lim_{t \\to \\infty} x(t)=0\n      .\\] \n  \\end{itemize}\n\\subsection{Non-homogeneous Linear Equations}\n\n\\subsubsection{Method of Undetermined Coefficients}\n\nWhen can we use the method of undetermined coefficients? This method can be used with\n\\begin{itemize}\n  \\item Most constant coefficient ordinary differential equations\n  \\item Non-homogeneous term must be of the form:\n    \\begin{itemize}\n      \\item Polynomials.\n      \\item $e^{cx}$\n      \\item $\\sin(bx),\\cos(bx)$\n    \\end{itemize}\n\\end{itemize}\n\n\\begin{theorem}\n  After finding the homogeneous function $y_h(x):$\n  \\begin{enumerate}\n    \\item Make your first guess at the form of $y_p(x)$ with unknown constants based on $f(x)$.\n    \\item Plug $y_p(x)$ into ordinary differential equation. (Left-hand side equals right-hand side for all $x$'s).\n    \\item Solve linear system.\n    \\item Plug back into the guess $y_p(x)$.\n    \\item General solution is $y(x)=y_h(x)+y_p(x)$.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{eg}\n  Consider the following ordinary differential equation.\n  \\[\n  x''-3x'-4x=-7t\n  .\\] \n  In order to solve for $x_h(t)$, we set the right-hand side equal to zero and let $x(t)=re^{rt}$.\n  \\begin{align*}\n    r^2-3r-4&=0\\\\\n    (r-4)(r+1)&=0\\\\\n    r&=4,1\n  .\\end{align*}\n  This gives us that our general homogeneous solution is \n  \\[\n    x_h(t)=C_1e^{4t}+C_2e^{-t}\n  .\\] \n  \\begin{enumerate}\n    \\item Now we make our initial guess of $x_p(t)=At+B$. Then we need to make sure that it does not match one of the homogeneous solutions from above.\n    \\item $x_p'(t)=A$, $x_p''(t)=0$\n  \n  Now we must plug our $x_p(t)$ and $x_p''(t)$ into our original ordinary differential equation. This gives us \n  \\[\n    0-3A-4(At+B)=-7t\n  .\\] \n  Now We need to separate all the terms that have a $t$ attached to them, and all the solutions that are constant as \n  \\begin{align*}\n    t&:-4A=-7\\\\\n    1&:-3A-4B=0\n  .\\end{align*}\n  \\item Now we must simply solve for both $A$ and $B$. After solving, we get that \n  \\[\n    x_p(t)=\\frac{7}{4}t-\\frac{21}{16}\n  .\\] \n  This gives us the general solution as\n  \\[\n  C_1e^{4t}+C_2e^{-t}+\\frac{7}{4}t-\\frac{21}{16}\n  .\\] \n  \\end{enumerate}\n  Just a caution, we need to make sure that we apply our initial and boundary conditions to our general solution only.\n\\end{eg}\n\n\\begin{eg}\n  Consider the ordinary differential equation\n  \\[\n  x''-3x'-4x=6e^{-4t}\n  .\\] \n  We can see that $x_h(t)=C_1e^{4t}+C_2e^{-t} $. Our initial guess is going to be $x_p(t)=Ae^{-4t}$. Using our initial guess we can do the following \n  \\begin{align*}\n    x_p''-3x_p-4x_p=6e^{-4t}\\\\\n    16Ae^{-4t}+12Ae^{-4t}-4Ae^{-4t}=6e^{-4t}\\\\\n    24A=6\\therefore A=\\frac{1}{4}\n    x_p(t)=\\frac{1}{4}e^{-4t}\n  .\\end{align*}\n  Because our initial guess matched on of the solutions in the homogeneous equation we need to modify our equation or else we will be incorrect, but how do we know how to modify our guess? We need to add a $t$ and check again to make sure that our solution is not matching. Let's try again with $Ate^{-4t}$\n  \\begin{align*}\n    x_p'&=4e^{4t}+4Ate^{4t}\\\\\n    x_p''&=8Ae^{4t}+16Ae^{4t}\n  .\\end{align*}\n  After plugging $x_p$ and $x_p''$ into our ordinary differential equation and solving the system at the end, we get the general result as\n  \\[\n    x(t)=C_1e^{4t}+C_2e^{-t}+\\frac{6}{5}te^{4t}\n  .\\] \n\\end{eg}\n\n\\subsubsection{Variation of Parameters}\n\n  This method is more tedious and difficult than the method described in section (3.4.1), but it is more universal and will find a particular solution to any non-homogeneous linear ordinary differential equation.\n  \\begin{theorem}\n    To solve something using variation of parameters,\n    \\begin{enumerate}\n      \\item Find $y_h(x)=C_1y_1(x)+C_2y_2(x)$.\n      \\item Let $y(x)=v_1(x)y_1(x)+v_2(x)y_2(x)$, where $y_1(x),y_2(x)$ are from the homogeneous solution. Our goal is to find $v_1,v_2$.\n      \\item Solve system for $v_1',v_2'$. In order to do this, we can use the following system \n        \\begin{align*}\n          y_1'(x)v_1'(x)+y_2'(x)v_2'(x)=f(x)\\\\\n          y_1(x)v_1'(x)+y_2(x)v_2'(x)=0\n        .\\end{align*}\n        In order to do this, we need to use Cramer's rule. Cramer's rule tells us to find \n        \\begin{align*}\n          w(x)&=\\left| \\begin{matrix} y_1(x)&y_2(x)\\\\y_1'(x)&y_2'(x) \\end{matrix} \\right|\\\\\n          v_1'(x)&= \\frac{\\left| \\begin{matrix} 0&y_2\\\\f(x)&y_2' \\end{matrix} \\right|}{w(x)} \\\\\n          v_2'(x)&=\\frac{\\left| \\begin{matrix} y_1&0\\\\y_1'&f(x) \\end{matrix} \\right| }{w(x)}\n        .\\end{align*}\n      \\item Integrate to find $v_1(x)$ and $v_2(x)$. $v_1(x)=\\boxed{}+c,v_2(x)=\\boxed{}+c$.\n      \\item Simplify.\n    \\end{enumerate}\n  \\end{theorem}\n\n  \\begin{eg}\n    Solve the ordinary differential equation $x''-2x'+x=\\frac{e^{t}}{t}$. First we need to find the homogeneous ordinary differential equation by letting $x_h(t)=e^{rt}$ and solving for $r$. When all is done we end up with $x_1(t)=e^{t},x_2(t)=te^{t}$.\n    \\begin{enumerate}\n      \\item Let $x(t)=v_1(t)e^{t}+v_2(t)te^{t}$\n      \\item Set up a system of equations.\n        \\begin{align*}\n          e^{t}v_1'+te^{t}v_2'&=0\\\\\n          e^{t}v_1'+\\left( e^{t}+te^{t} \\right)v_2'=\\frac{e^{t}}{t} \n        .\\end{align*}\n        Now we can solve this to get $v_1'=-1,v_2'=\\frac{1}{t}$.\n      \\item Now we need to integrate both $v_1(t)$ and $v_2(t) $ like so\n        \\begin{align*}\n          v_1(t)&=\\int -1dt=-t+C_1\\\\\n          v_2(t)&=\\int \\frac{1}{t}dt=\\ln|t|+C_2\n        .\\end{align*}\n      \\item So,\n        \\begin{align*}\n          x(t)&=(-t+C_1)e^{t}+\\left( \\ln|t|+C_2 \\right) te^{t}\\\\\n              &=-te^{t}+te^{t}\\ln|t|+C_1e^{t}+C_2te^{t}\n        .\\end{align*}\n    \\end{enumerate}\n    Another way we can solve this is using the wronskian,\n    \\begin{align*}\n      w(t)&= \\left| \\begin{matrix} e^{t}&te^{t}\\\\e^{t}&te^{t}+e^{t} \\end{matrix} \\right| = \\ldots=e^{2t}\\\\\n      v_1'(t)&=\\frac{\\left| \\begin{matrix} 0&te^{t}\\\\\\frac{e^{t}}{t}&te^{t}+e^{t} \\end{matrix} \\right| }{w(t)}=\\ldots=-1\\\\\n      v_2'(t)&=\\frac{\\left| \\begin{matrix} e^{t}&0\\\\e^{t}&\\frac{e^{t}}{t} \\end{matrix} \\right| }{w(t)}=\\ldots=\\frac{1}{t}\n    .\\end{align*}\n  \\end{eg}\n\\subsection{The Forced Spring-Mass System}\n\nThe equations from a forced spring-mass system are in the form \n\\[\n  mx''+bx'+kx=f(x)\n.\\] \nIn this section we are going to examine the effects of $f(t)$ on the system. There are three cases for the dampening of a system, under damped, over damped, and critically dampened. We are going to be looking at the under damped case first.\n\\begin{eg}\n  Consider the equation \n  \\[\n    x''+w_0^2x=A\\cos(\\omega t) \\text{ where $\\omega_0=\\sqrt{\\frac{k}{m}} $}\n  .\\] \n  If we were to make our guess based off of this information, we should guess that $x_p(t)=B\\cos(\\omega t) + C\\sin(\\omega t)$. $x_h(t)=C_1\\cos(\\omega_0 t)+C_2\\sin(\\omega_0 t)$, which is the natural frequency of this equation. If $\\omega\\neq\\omega_0$, then we don't have to modify. Otherwise, we will need to modify our equation to \n  \\[\n    x_p(t)=Bt\\cos(\\omega_0 t)+Ct\\sin(\\omega_0 t)\n  .\\] \n  Beats happen when $\\omega$ is close, but not equal to $\\omega_0$. Through a trigonometric identity,\n  \\begin{align*}\n    x(t)&=\\frac{-2A}{\\omega_0^2-\\omega^2}\\sin\\left( \\frac{\\omega+\\omega_0}{2}\\cdot t \\right) \\sin\\left( \\frac{\\omega-\\omega_0}{2}t \\right)\n  .\\end{align*}\n\\end{eg}\n\\begin{eg}\n  A mass of $5kg$ stretches a spring $10cm$ and is acted on by an external force of $10\\sin\\left( \\frac{t}{2} \\right) N$ and moves in a viscous medium that imparts a force of 2 N when the speed is $4 \\frac{cm}{s}$. Find the initial value problem that models setting the mass in motion from its equilibrium position with an upward velocity of $3 \\frac{cm}{s}$.\\par\n  Let $t$ be time since the mass in set in motion in seconds. Let $x$ be displacement (where up is positive) of the mass from equilibrium.\n  \\begin{align*}\n    mg&=ks\\\\\n    5.98&=k(0.1m)\\\\\n    \\to k&=490 \\frac{kg}{s^2}\n  .\\end{align*}\n  \\begin{align*}\n    5x''+bx'+490x&=10\\sin\\left( \\frac{t}{2} \\right) \\\\\n    x(0)&=0\\\\\n    x'(0)=0.03\n  .\\end{align*}\n  They told us that $f_{damping}=-bx'$. We know that the force damping when at a velocity of $0.4 \\frac{m}{s^2}$, so we can solve for $b$ and see that $b=50$. This makes our ordinary differential equation \n  \\[\n  x''+10x'+98x=2\\sin\\left( \\frac{t}{2} \\right) \n  .\\] \n  We should expect to see trigonometric functions because of the value of $f(x)$. Let's try the equation\n  \\[\n    x_p(t)=A\\cos\\left( \\frac{t}{2} \\right) +B\\sin\\left( \\frac{t}{2} \\right) \n  .\\] \n  We can use $b-4mk$ to determine the numbers required for our homogeneous solution.\n\\end{eg}\n\n\\begin{theorem}\n  Here is the outline for solving these problems.\n  \\begin{enumerate}\n    \\item Find $x_h(t)=C_1e^{\\alpha t}\\cos\\left( \\beta t \\right) +C_2e^{\\alpha}\\sin\\left( \\beta t \\right) $\n    \\item Find $x_p(t)=A\\cos\\left( \\beta t \\right) +B\\sin\\left( \\beta t \\right) $\n    \\item State general solutions.\n    \\item Apply initial conditions to find $C_1,C_2$.\n    \\item Find the particular solution\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{note}\n  The maximum amplitude occurs when \n  \\begin{align*}\n    \\omega=\\sqrt{\\omega_0^2-2\\lambda}\\\\\n    \\omega_0=\\sqrt{\\frac{k}{m}} \n  .\\end{align*}\n\\end{note}\n\\subsection{Solving Cauchy Euler Ordinary Differential Equations}\n\\subsubsection{Method of Lucky Guess}\n\nIf an equation is not in the form \n\\[\nax^2y'' + bxy'+cy=0\n,\\] then we cannot use the method of lucky guess. This method is common in polar, cylindrical, and spherical coordinates. The first thing we need to do when using this method is put it in standard form,\n\\[\ny''+\\frac{b}{a}\\frac{1}{x}y'+\\frac{c}{ax^2}y=0\n.\\] \nNow, we just need to let $y(x)=x^{r}$ to find our $r$-values.\n\\begin{eg}\n  Solve the following ordinary differential equation.\n  \\[\n  x^2y'''+2xy''-6y'=0\n  .\\] \n  Let $y(x)=x^{r}$. Using this we can find that $y'=rx^{r}, y''=r(r-1)x^{r-2},y'''=r(r-1)(r-2)x^{r-3}$. Now let's plug our $y$'s into our ordinary differential equation and solve for $r$ like the following.\n  \\begin{align*}\n    x^2r(r-1)(r-2)x^{r-3}+2xr(r-1)x^{r-2}-6rx^{r-1}&=0\\\\\n    x^{r-1}\\left[ \\left( r^{3}-3r^2+2r \\right) + \\left( 2r^2-2r \\right) -6r  \\right]&=0\\\\\n    r\\left[ r^2-3r+2+2r-2-6 \\right] &=0\\\\\n    r\\left[ r^2-r-6 \\right]&=0\\\\\n    r(r-3)(r+2)&=0\\\\\n    \\to r&=0,3,-2.\n  .\\end{align*}\n  From here we can determine the following.\n  \\begin{align*}\n    y_1(x)&=x^{0}=1\\\\\n    y_2(x)&=x^{3}\\\\\n    y_3(x)&=x^{2}\n  .\\end{align*}\n  So the general solution of our ordinary differential equation is \n  \\[\n    y(x)=C_1+C_2x^{3}+\\frac{C_3}{x^2} \n  .\\] \n\\end{eg}\n  If $r$ is repeated, then $y_1(x)=x^{r},y_2=x^{r}\\ln x,y_{n}(\\ln x)^n$. If $r=\\alpha\\pm i\\beta$, then we need to set \n  \\begin{align*}\n    y_1(x)&=x^{\\alpha}\\cos(\\beta\\ln x)\\\\\n    y_2(x)&=x^{\\alpha}\\sin(\\beta\\ln x)\n  .\\end{align*}\n  This gives us two equations,\n  \\begin{align*}\n    ay''+by'+cy=0 && ax^2y''+bxy+cy=0\n  .\\end{align*}\n  Let's take a look at an example for this.\n\\begin{eg}\n  Consider the equation $4x^2y''+y=0$\n  \\begin{enumerate}\n    \\item Let $y(x)=e^{r}$, after taking the derivatives we can see that \n      \\begin{align*}\n        x^{r}[4r(r-1)+1]&=0\\text{ for all $x$'s}\\\\\n        4r^2-4r+1&=0\\\\\n        (2r-1)^2=0\\to r=\\frac{1}{2},\\frac{1}{2}\n      .\\end{align*}\n      This gives us that our general solution is \n      \\[\n      C_1x^{\\frac{1}{2}}+C_2x^{\\frac{1}{2}}\\ln x, x>0\n      .\\] \n    \\item Let's consider a different approach.\n      \\begin{align*}\n        x^{r}[4r(r-1)+17]&=0\\\\\n        4r^2-4r+17&=0\\\\\n        (2r-1)^2&=1-17\\\\\n        |2r-1|&=4i\\\\\n        2r-1&=\\pm_4i\\\\\n        r=\\frac{1}{2}\\pm 2i\n      .\\end{align*}\n      This tells us that the general solution is \n      \\[\n        y(x)=C_1x^{\\frac{1}{2}}\\cos(2\\ln x)+C_2x^{\\frac{1}{2}}(2\\ln x),x>0\n      .\\] \n  \\end{enumerate}\n\\end{eg}\nThe equation $ax^2 \\frac{d^2y}{dt^2}+bx \\frac{dy}{dt}+cy=0$ can be transformed via $x=e^{t},t=\\ln x$ to \n\\[\n  a \\frac{d^2y}{dt^2}+(b-a) \\frac{dy}{dt}+cy=0\n.\\] \nLet's take a look at another example.\n\\begin{eg}\n  Consider the following ordinary differential equation,\n  \\[\n  \\rho \\frac{d^2u}{d\\rho^2}+2 \\frac{du}{d\\rho}=0\n  .\\] \n  Let $u(a)=A,u(b)=B$. We can see that $u(\\rho)=\\rho^{r}, u'=r\\rho^{r-1}, u''=r(r-1)\\rho^{r-2}$. Now in order to solve this ordinary differential equation, we need to determine the roots of $r$, and we need to solve for both $C_1,C_2$.\n  \\begin{align*}\n    \\rho^{r-1}[r(r-1)+2r]&=0\\\\\n    r^2-r+2r&=0\\\\\n    r^2+r&=0\\\\\n    r(r+1)&=0\\\\\n    r&=0,1\n  .\\end{align*}\n  Now, we can determine that $u(\\rho)=C_1+C_2\\rho^{-1}$ as long as $\\rho>0$. We can now use the following system to solve for $C_1,C_2$,\n\\begin{align*}\n  \\begin{cases}\n    \\rho(a)=C_1+\\frac{C_2}{a}=A & C_2=\\frac{A-B}{\\frac{1}{a}-\\frac{1}{b}}=\\frac{ab(B-A)}{a-b}\\\\\n    \\rho(b)=C_1+\\frac{C_2}{b}=B & C_1=\\frac{aA-bB}{a-b}\n  \\end{cases}\n\\end{align*}\n\\end{eg}\n\nLet's take a look at another example.\n\\begin{eg}\n  Consider the ordinary differential equation \n  \\[\n    x^2y''-2xy'+2y=-x\\text{, where }x>0\n  .\\] \n  From here, we need to put our equation into standard form, so it looks like \n  \\[\n    y''-\\frac{2}{x}y'+\\frac{2}{x^2}y=-\\frac{1}{x}\\text{, where $-\\frac{1}{x}=f(x)$}\n  .\\] \n  The first thing we need to do now is solve for $y_h(x)$, which means we have to do the following\n  \\begin{align*}\n    x^2y''-2xy'+2y&=0\\\\\n    r&=2,1\\\\\n    y_1(x)=x^2\\\\\n    y_2(x)=x\\\\\n    y_h(x)=C_1x^2+C_2x\n  .\\end{align*}\n  Now we are going to use variation of parameters to solve for $C_1,C_2$. In order to do this, let $y(x)=v_1(x)x^2+v_2(x)x$. We can either use a linear system to solve this, or we can use the wronskian. Using the linear system, we end up with \n  \\begin{equation*}\n    \\begin{cases}\n      x^2v_1'+xv_2'=0\\\\\n      2xv_1'+1v_2'=-\\frac{1}{x}\n    \\end{cases}\n  \\end{equation*}\n  If we were to use the wronskian we would do the following\n  \\begin{align*}\n    w(x)&=\\left| \\begin{matrix} x^2&x\\\\2x&1 \\end{matrix} \\right| =x^2-2x^2=-x^2\\\\\n    v_1'&= \\frac{\\left| \\begin{matrix} 0&x\\\\-\\frac{1}{x}&1 \\end{matrix} \\right| }{-x^2}=-\\frac{1}{x^2}\\\\\n    v_2'&=\\frac{\\left| \\begin{matrix} x^2&0\\\\2x&-\\frac{1}{x} \\end{matrix} \\right| }{-x^2}=-\\frac{x}{x^2}=\\frac{1}{x}\\\\\n    v_1=\\int-\\frac{1}{x^2}dx=\\frac{1}{x}+C_1\\\\\n    v_2=\\int \\frac{1}{x}dx=\\ln|x|+C_2\n  .\\end{align*}\n  So $y(x)=v_1x^2+v_2x$. After simplification, we end up with \n  \\[\n    y(x)=C_1x^2+C_3x+x\\ln|x|\n  .\\] \n\\end{eg}\n\\subsubsection{Taylor and Frobenius Series Solutions to Linear Ordinary Differential Equations}\n\nThis is a backup strategy if the method of lucky guess does not work. In this strategy, the main point is to let\n\\[\n  y(x)=\\sum_{n=0}^{\\infty}C_n(x-x_0)^{n}\n.\\] \nOur goal is to use our initial conditions to solve the ordinary differential equation and find $C_n$'s. Sometimes we need a more generalized series, and that is when we are going to use the frobenius series. Here is the general pathway through one of these problems.\n\\begin{align*}\n  y(x)&=(x-x_0)^{r}\\sum_{n=0}^{\\infty} C_n(x-x_0)^{n}\\\\\n  x_0&\\to 0\\\\\n  y(x)&=\\sum_{n=0}^{\\infty} C_nx^{n+r}\n.\\end{align*}\nGiven an ordinary differential equation with initial conditions, $y(0)=y_0,y'(0)=v_0$, let \n\\begin{align*}\n  y(x)&=C_0+C_1x+C_2x^2+C_3x^3\\\\\n  y'(x)&=C_1+2C_2x+3C_3x^2\n.\\end{align*}\nNow we apply our initial conditions, which tell us the first two terms in the solution.\nThere are three main ordinary differential equations that we need to know that force us to use the Taylor or Frobenius series solutions,\n\\begin{itemize}\n  \\item Legendre's ODE\n    \\[\n      (1-t^2)x''-2tx'+\\lambda(\\lambda+1)x=0\n    .\\] \n  \\item Bessel's ODE\n    \\[\n      t^2x''+tx'+(t^2-v^2)x=0\n    .\\] \n  \\item Airy's ODE\n    \\[\n    x''-tx=0\n    .\\] \n\\end{itemize}\n\\begin{theorem}\n  Consider the equation \n  \\[\n    x''+p(t)x'+q(t)x=0\n  ,\\] where $f(x)=0$. A singular point of the ordinary differential equation is a value of $t$ where $p,q,\\text{ or }f$ is not analytic (cannot be written as Taylor series). If we attempt to solve a singular point ODE, we will end up dividing by 0. An ordinary point are non-singular points. \n\\end{theorem}\nConsider Bessel's ordinary differential equation, $x''+\\frac{1}{t}x'+\\left( 1-\\frac{2^2}{t^2} \\right) = 0 $ This equation has a singular point of $t=0$. A point is regular if $tp$ (in this case $t-t_0$) and $t^2q$ ($\\left( t-t_0 \\right) ^2$) are analytic. Otherwise, they are irregular points. In the case of Bessel's ordinary differential equation, there is a regular singular point.\n\\begin{theorem}\n  If you expect a Taylor series at $t=t_0$ (ordinary point) and the radius of convergence is at least as big as the distance to the nearest singular point (can be complex), then there exist 2 linearly independent series solutions. If $t=t_0$ is a singular point, you need to use a frobenius series.\n\\end{theorem}\n\\begin{eg}\n  Consider Airy's ordinary differential equation, $x''-t=0$. The two linearized solutions are $A_i(t)$ and $B_i(t)$. We are given the initial conditions $x(0)=1,x'(0)=-2$. From here, let $x(t)=1-2t+C_2t^3+C_4t^{4}$, this gives us that \n  \\begin{align*}\n    x'(t)&=-2+2C_2t+3C_3t^2+4C_4t^3\\\\\n    x''&=C_2+6C_3t+12C_4t^2\n  .\\end{align*}\n  If we plug the equations above into Airy's equation, we get\n  \\[\n  \\left[ 2C_2+6C_3t+12C_4t^2+\\ldots \\right]-t\\left[ 1-2t+C_2t^2+C_3t^3+C_4t ^{4}+\\ldots \\right] =0\n  .\\] \n  We can pull out specific values in order to solve for $C_2,C_3,C_4$, like the following \n  \\begin{align*}\n    1&:2C_2=0 &&\\to C_2=0\\\\\n    t&:6C_3-1=0&&\\to C_3=\\frac{1}{6}\\\\\n    t^2&:12C_4+2=0&&\\to C_3=-\\frac{1}{6}\n  .\\end{align*}\n  From here, we can determine that our general solution is \n  \\begin{equation*}\n    \\boxed{x(t)=1-2t+\\frac{1}{6}t^3-\\frac{1}{6}t ^{4}+\\ldots}\n  \\end{equation*}\n  For general initial conditions ($x(0)=C_0, x'(0)=C_1$).\n  \\begin{align*}\n    x''-tx\\\\\n    [2C_2+6C_3t+12C_4t^2+\\ldots]-t[C_0+C_1t+C_2t^2+\\ldots]\\\\\n  .\\end{align*}\n  \\begin{align*}\n    1&:2C_2=0&&\\to C_2=0\\\\\n    t&:6C_3-C_0=0&&\\to C_3=\\frac{1}{6}C_0\\\\\n    t^2&:12C_4-C_1=0&&\\to C_4=\\frac{1}{12}C_1\\\\\n  .\\end{align*}\n  This would make our particular solution \n  \\begin{align*}\n    x(t)&=C_0+C_1t+\\left( \\frac{1}{6}C_0 \\right) t^3+\\left( \\frac{1}{12}C_1 \\right) t ^{4}\\\\\n  .\\end{align*}\n\\end{eg}\n\nAnother important skill that plays in with Taylor series ordinary differential equations is re-indexing. This is basically just an u-substitution for a series. Our goal is to rewrite\n\\[\n  \\sum_{n=2}^{\\infty} n(n-1)a_nt ^{n-2}\n.\\] \nIn order to have $t ^{k}$, we need to let $k=n-2\\to n=k+2$, which gives us a series that looks like \n\\[\n  \\sum_{k=0}^{\\infty} (k+2)(k+1)a_{k+2}t ^{k}\n.\\] \nLet's take a look at re indexing  when it comes to Airy's equation.\n\\[\nx''-tx=0\n.\\] \n\\begin{eg}\n  \\begin{align*}\n    x(t)&=\\sum_{n=0}^{\\infty} C_nt^n\\\\\n    x'(t)&=\\sum_{n=1}^{\\infty} C_nnt ^{n-1}\\\\\n    x''(t)&=\\sum_{n=2}^{\\infty} C_nn(n-1)t ^{n-2}=\n  .\\end{align*}\n  We can rewrite Airy's ODE as \n  \\[\n    \\sum_{n=2}^{\\infty} C_nn(n-1)t ^{n-2}-t \\sum_{n=0}^{\\infty} C_nt ^{n}=0\n  .\\] \n  Because we have a difference of 3 in the exponents, let $n-2 = k + 1, n=k+3 \\text{ or } k=n-3$. This makes our Taylor series \n  \\[\n    \\sum_{k=-1}^{\\infty} C_{k+3}(k+3)(k+2)t ^{k+1}-\\sum_{n=0}^{\\infty} C_nt ^{n+1}=0\n  .\\] \n  Now if we choose another variable $m$ and take both $k,n$ and put them in terms of $m$, we get\n  \\[\n    C_2(2)(1)t ^{0}+\\sum_{m=0}^{\\infty} \\left[ C_{m+3}(m+3)(m+2)-C_m \\right] t ^{m+1}=0\n  .\\] \n  From here, we can solve for $C_2$ using $2C_2=0$ for the 1's values. This leaves us with \n  \\[\n    m\\ge 0:C_{m+3}(m+3)(m+2)-C_m=0\\\\\n  .\\] \n  Our general recursion relation is \n  \\[\n    C_{m+3}=\\frac{C_m}{(m+3)(m+2)}\n  .\\] \n  If we follow our recursion relationship\n  \\begin{align*}\n    m=0:&&C_3=\\frac{C_0}{3\\times2}=\\frac{1}{6}C_0\\\\\n    m=1:&&C_4=\\frac{C_1}{4\\times 3}=\\frac{1}{12}C_1\\\\\n    m=2&&C_5=\\frac{C_2}{5\\times 4}=0\\\\\n    m=3:&&C_6=\\frac{C_3}{6\\times 3}=\\frac{1}{18}C_3=\\frac{1}{18}\\times \\frac{1}{6}C_0=\\frac{1}{108}C_0\n  .\\end{align*}\n  Every third coefficient is 0, all other coefficients can be expressed in terms of $C_1,C_2$.\n  \\begin{align*}\n    x(t)&=C_0+C_1t+C_2t^2+\\ldots\\\\\n        &=C_0+C_1t+\\frac{1}{6}C_0t^3+\\frac{1}{16}c_1t ^{4}+\\ldots\\\\\n        &=C_0\\left[ 1+\\frac{1}{6}t^3+\\frac{1}{108}t ^{6}+\\ldots \\right] + C_1\\left[ t+\\frac{1}{12}t ^{4}+\\ldots \\right]  \n  .\\end{align*}\n\\end{eg}\nLet's take a look at another example to solidify understanding.\n\\begin{eg}\n  Consider the equation $(x+2)y''+3y'+4y=0$. Let $y(x)=\\sum_{n=0}^{\\infty} C_nx^{n}$. This makes our differential \n  \\[\n    (x+2)\\sum_{n=2}^{\\infty} C_nn(n-1)x^{n-2}+3 \\sum_{n=1}^{\\infty} C_nnx^{n-1}+4 \\sum_{n=0}^{\\infty} C_nx^{n}=0\n  .\\] \n  Let $n-2=k-1$, which would make $n=k+1,k=n-1$. Also let $n=j-1,j=n+1$ After changing our values, our ordinary differential equation, our equation is \n  \\[\n    \\sum_{n=2}^{\\infty} C_nn(n-1)x^{n-1}+\\sum_{k=1}^{\\infty} 2C_{k+1}(k+1)kx^{k-1}+\\sum_{n=1}^{\\infty} 3c_nnx^{n-1}+\\sum_{j=1}^{\\infty} 4C_{j-1}x^{j-1}=0\n  .\\] \n  Now rewrite $n,k,j\\to m$. Let  $k,n,j=1$. This makes our differential \n  \\begin{align*}\n    0=&2C_2\\times 2\\times 1\\times x^{0}+3C_1\\times 1\\times x^{0}+4C_0\\times x^{0}\\\\\n    +&\\sum_{m=2}^{\\infty} \\left[ C_m\\left[ m(m-1)+3m \\right] +2C_{m+1}(m+1)m+4C_m-1 \\right]x^{m} \n  .\\end{align*}\n  After simplification, we can pull out like terms to solve for $C_2$ and the recursion relation.\n  \\begin{align*}\n    1&:4C_2+3C_1+4C_0=0&&\\to C_2=\\frac{-3C_1-4C_0}{4}\\\\\n    x^{m-1}&:C_m(m^2+2m)+2C_{m+1}(m+1)m+4C_m-1 = 0\n  .\\end{align*}\n  Our general recursion relation as long as $m\\ge 2$ is \n  \\[\n    C_{m+1}=\\frac{-m(m+2)C_m-4C_m-1}{m(m+1)}\n  .\\] \n  If we set $m=2$, we can solve and get results for $C_1, C_2$. One approach to finding two linearly independent solutions is to set $y(x)=C_0+C_1x+C_2x^2$, and then use the values calculated from $C_{m+1}$ to get\n  \\begin{align*}\n    &=C_0+C_1x+\\left( -\\frac{3}{4}C_1-C_0 \\right)x^2+(\\text{from above})x^3\\\\\n    &=C_0\\left[ 1-x^2+\\boxed{}x^3+\\ldots \\right] +C_1\\left[ x-\\frac{3}{4}x^2+1 \\right] x^3\n  .\\end{align*}\n\\end{eg}\n\nAn alternative for finding two linearly independent solutions is solving with $C_0=1,C_1=0$. This makes our initial conditions $x(0)=1,x'(0)=0$. This makes our $C_2=-1,C_3=\\frac{2}{3},C_4=-\\frac{1}{4}$. We also need to solve with the initial conditions $x(0)=0,x'(0)=1$. This makes our solutions \n\\begin{align*}\n  y_1(x)&=1+0x-1x^2+\\frac{2}{3}x^3-\\frac{1}{4}x^{4}\\\\\n  y_2(x)&=0+1x-\\frac{3}{4}x^2+\\frac{1}{6}x^3+\\frac{1}{48}x^{4}\n.\\end{align*}\nThe general solution is \n\\[\n  y(x)=C_1y_1(x)+C_2y_2(x)\n,\\] \nwhere $C_1=x(0),C_2=x'(0)$. A Frobenius series is when you expand around a singular point (a point that is hard for the equation). Consider Bessel's ordinary differential equation.\n\\begin{eg}\n  \\[\n  x^2y''+xy'+\\left( x^2-\\frac{1}{4} \\right) y=0\\text{ with }\\nu=\\frac{1}{2}\n  .\\] \n  Here we are going to let $y(x)=\\sum_{n=0}^{\\infty} C_nx^{n+r}$, and our goal is to find $n$ and $c_n$. We can easily find that \n  \\begin{align*}\n    y'&=\\sum_{n=0}^{\\infty} C_n(n+r)x^{n+r-1}\\\\\n    y''&=\\sum_{n=0}^{\\infty} C_n(n+r)(n+r-1)x^{n+r-2}\n  .\\end{align*}\n  Our ordinary differential equation written out is \n  \\[\n    \\sum_{n=0}^{\\infty} C_n(n+r)(n+r-1)x^{n+r}+\\sum_{n=0}^{\\infty} C_n(n+r)x^{n+r}+\\sum_{n=0}^{\\infty} C_nx^{n+r+2}-\\sum_{n=0}^{\\infty} \\frac{1}{4}C_nx^{n}=0\n  .\\] \n  Let $k+r=n+r+2$. This gives us that\n  \\[\n    \\sum_{n=0}^{\\infty} C_n\\left[ (n+r)(n+r-1)+(n+r)-\\frac{1}{4} \\right] x^{n+r}+\\sum_{k=2}^{\\infty} C_{k-2}x^{k+r}=0\n  .\\] \n  If we transform the $k$  into an $n$ , we get that \n  \\begin{align*}\n    &\\sum_{n=2}^{\\infty} \\left( C_n\\left[ (n+r)(n+r-1+1)-\\frac{1}{4} \\right] +C_n-2 \\right) x^{n+r}+\\\\&C_0\\left( r(r-1)+r-\\frac{1}{4} \\right) x^{r}+C_1\\left[ (r+1)(r)+(r+1)-\\frac{1}{4} \\right] x^{r+1}\n  .\\end{align*}\n  Now we can pull out like terms to create a system of equations to solve for $C$ values:\n  \\begin{align*}\n    x^{r}&:&&r^2-\\frac{1}{4}=0\\text{ or }C_0=0\\\\\n    x^{r+1}&:&&(r+1)^2-\\frac{1}{4}=0\\text{ or }C_1=0\\\\\n    x^{r+h}&:&&C_n=\\frac{-C_n-2}{(n+r)^2-\\frac{1}{4}}\n  .\\end{align*}\n  If $C_0\\neq 0, r=\\pm \\frac{1}{2}$ or if $C_1\\neq 0, r+1=\\pm \\frac{1}{2}$. There are two linearly dependent solutions\n  \\begin{itemize}\n    \\item $r=\\frac{1}{2}$\n    \\item $r=-\\frac{1}{2}$\n  \\end{itemize}\n  If we take $r=\\frac{1}{2}$ and simplify $C_n$, we can see that \n  \\[\n    C_n=\\frac{-C_n-2}{n(n+1)}, n\\ge 2\n  .\\] \n  Using this, we can solve for a certain number of terms to get that\n  \\[\n    y_1(x)=x^{\\frac{1}{2}}\\left[ C_0-\\frac{1}{3!}C_0x^2+\\frac{1}{5!}x^{4}+\\ldots \\right] \n  .\\] \n  This equation simplifies down to \n  $\\frac{C_0}{\\sqrt{x} }\\sin (x)$.\n\\end{eg}\n", "meta": {"hexsha": "67e44c04c342085c4263cde9bd945cc3bc8cfe64", "size": 38689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math260/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": "math260/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": "math260/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": 41.2902881537, "max_line_length": 384, "alphanum_fraction": 0.6067099175, "num_tokens": 15280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754471, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6330634795119793}}
{"text": "\\section{Adapt the \\acrshort{nrpa} to stochastic problem}%\n\\label{sec:adapt_the_nrpa_to_stochastic_problem}\n\nAs explained in section \\ref{sec:the_nrpa}, the \\gls{nrpa} is an algorithm that obtains state of the art results on different optimization problem.\nAll these problems have in common to be non stochastic problem.\nIt means that if we apply action \\(a\\) on state \\(s\\) and we obtain the state \\(s'\\) then, when repeating the same process, we will always obtain \\(s'\\).\nIn a stochastic context, this assurance does not exist.\nMeaning that, when applying \\(a\\) on \\(s\\) we may obtain \\(s'\\) but also \\(s^{*}\\) or \\(s''\\)  or any others, depending on the problem.\n\nIn this section, we are going to present how we tried to adapt the \\gls{nrpa} to solve stochastic problem.\nWe will first discuss a bit more what a stochastic problem is by considering a small example in order to highlight the difficulty to solve one.\nThen we will explain why the \\gls{nrpa} is not well suited to solve this kind of problem by identifying the main issues.\nThen, we will present how we attended to these issues by explaining our new algorithm the \\gls{snrpa}.\n\n\\subimport{./subs/}{stochastic.tex}\n\\subimport{./subs/}{nrpa.tex}\n\\subimport{./subs/}{snrpa.tex}\n\n\n", "meta": {"hexsha": "9b85019b40b5f35b9278d79077e80924fa58cf71", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/report/src/sections/snrpa/snrpa.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/snrpa/snrpa.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/snrpa/snrpa.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": 62.15, "max_line_length": 153, "alphanum_fraction": 0.7522123894, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825655188238, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6330634776151345}}
{"text": "\\chapter{A Brief Note on Feature Engineering \\label{chapter:feateng}}\n\nAll machine learning algorithms and statistical models depend on the concept of a \\textbf{feature}. A feature is some aspect of a dataset that, the model designer believes, represents the data in a way that is relevant to the problem he/she is trying to solve. \n\nBefore any algorithm can be applied, therefore, it is necessary to decide how to represent the data: which features to include and how to extract them from the raw data. This task is called \\textbf{feature engineering}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Study Design vs. Feature Engineering}\n\nWe have seen a large number of features in Chapters~\\ref{chapter:overview}--\\ref{chapter:logreg}, but we never stopped to consider them. That's because, in many datasets, the features are chosen at the \\textbf{study design} stage. The analyst (statistician, data scientist, etc.) has no say in what the features look like or which features are included.\n\nThis paradigm is changing as data science increasingly focuses on large, observational datasets, like those from electronic medical records (EMRs). In these types of studies, the raw data were not collected for the study itself, but to fulfill some other purpose. The analyst must choose how to build features from the raw data and use them in models.\n\\vspace{4mm}\n\n\\begin{question}{}\nThe examples in Chapters~\\ref{chapter:classification} and~\\ref{chapter:regression} used the same two features. What were these features? How were they represented? What are some alternatives to this choice of features?\n\\end{question}\n\n\\begin{question}{}\nIn Chapter~\\ref{chapter:decisiontrees}, we looked at the Wisconsin Breast Cancer Dataset, which includes $30$ different imaging features relevant to predicting whether a tumor is benign or malignant. How were these features represented? What are some alternatives to this choice?\n\\end{question}\n\n\\begin{question}{}\nIn Chapters~\\ref{chapter:linreg} and~\\ref{chapter:logreg}, we looked at two datasets that were collected for the purposes of answering particular questions. Do you agree with these study designers' choice of features? What other features could potentially have been relevant to answering each research question?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Turning Data into Numbers}\n\nA model is just a tool for learning relationships among sets of numbers. The first step in any data science problem, therefore, is deciding how to represent what is often a large, complex, noisy dataset as a set of numbers. \n\n\\subsection{Numbers}\n\nSometimes you get lucky and the feature you need is already a number, such as a vital sign measurement, lab value, or other biomarker. In that case, more often than not, the feature enters into the model as its raw value.\n\nIn some cases, you may also choose to apply a \\textbf{transformation} to the feature before it enters the model. A transformation is simply the application of a deterministic mathematical function that changes the shape of the distribution of the feature. Transformations are often used to improve the interpretability of a model and/or to ensure that the model fulfills the assumptions of the statistical inference method(s) being used (e.g., a hypothesis test).\n\\vspace{4mm}\n\n\\begin{question}{}\nHere are $100$ random samples from a normal distribution with $\\mu = 3.0$ and $\\sigma = 0.5$ and five different transformations of those samples. What do you notice about the shape and position of the data under the different transformations?\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-0.png}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-1.png}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-2.png}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-3.png}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-4.png}\n\\includegraphics[width=0.4\\textwidth]{img/normal-transform-5.png}\n\\end{center}\n\\end{question}\n\n\\begin{question}{}\nHere are $100$ random samples from an exponential (see Section~\\ref{sect:exponential}) distribution with $\\lambda = 0.8$ and the same five transformations of those samples. What do you notice about the shape and position of the data under the different transformations?\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-0.png}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-1.png}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-2.png}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-3.png}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-4.png}\n\\includegraphics[width=0.4\\textwidth]{img/exp-transform-5.png}\n\\end{center}\n\\end{question}\n\nEconomics, the social sciences, and related disciplines, which are heavily dependent on the use of regression models and hypothesis tests, rely extensively on transformations. In my experience, machine learning folks spend almost no time on them because their primary concern is predictive accuracy, not model interpretation. Machine learning practitioners, however, very frequently \\textbf{scale and center} their predictors (see footnote in Section~\\ref{section:sehyp}), which is another type of transformation. We will get into more detail on transformations as we continue to learn about regression models. \n\n\\subsection{Binary Variables}\n\nFor features which are yes/no (e.g., presence/absence of a disease, symptom, physical attribute, etc.) the most common coding scheme is to use ``1'' for ``yes'' and ``0'' for ``no''. This is useful for interpretation, particularly in regression models. In a linear regression model using this coding scheme, for example, the model coefficient will be the shift in the mean of the normal distribution representing the outcome, $y$, when the feature is present. \n\n\\subsection{Categories}\n\nCategorical features with $k>2$ categories are generally represented using \\textbf{indicator variables}. If a feature, $x$, has $k$ \\textbf{levels}, we can use $k-1$ yes/no indicator variables to represent that feature. For example, assume $k = 3$ and the possible levels of our feature, $x$, are $A$, $B$, and $C$. We set:\n\\begin{align*} \nx_1 &= \\left\\{ \\begin{array}{cl} 1 & \\text{ if }x = A \\\\\n                                                0 & \\text{ otherwise} \\end{array} \\right. \\\\[2mm]\nx_2 &= \\left\\{ \\begin{array}{cl} 1 & \\text{ if }x = B \\\\\n                                                0 & \\text{ otherwise} \\end{array} \\right.\n\\end{align*}\nIf the value of $x$ is $A$, $x_1 = 1$ and $x_2 = 0$. If it's $B$, $x_1 = 0$ and $x_2 = 1$. The value $C$ is called our \\textbf{reference category} and has $x_1 = 0$ and $x_2 = 0$. In this way, information about all three categories is captured using only two variables. Creating indicator variables is just another way of transforming the value of a feature.\n\\vspace{4mm}\n\n\\begin{question}{}\nIn Section~\\ref{sect:lowbwt}, we saw an example of a model that predicts whether or not a mother will give birth to a low birthweight baby. One of the factors considered in that model is the mother's race, which was coded (crudely and probably inaccurately, I might add) as \\texttt{1 = white, 2 = Black, 3 = other}. You can tell how the feature \\texttt{RACE} was coded by examining the model output. How many indicator variables were used? Which level of the feature was used as the reference category?\n\\end{question}\n\n\n\n", "meta": {"hexsha": "dcc7921b599e6bf48844a7f608eb71d482777436", "size": 7482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-feature-engineering.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-feature-engineering.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-feature-engineering.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": 84.0674157303, "max_line_length": 611, "alphanum_fraction": 0.751269714, "num_tokens": 1771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.6330466911966853}}
{"text": "\\subsection{Checking}\n\n\\begin{frame}\n  \\frametitle{Checking (= Reachability)}\n\n  To establish if a model satisfies a safety \n  property amounts to check if some\n  {\\bf bad state is reachable} from the set\n  of initial states\n  \\vfill\n  This can be done automatically by {\\bf visiting} the\n  set of states that are {\\bf reachable} from the initial\n  state with the application of a transition\n  \\vfill\n  \\pause\n  Let $S^{(0)}$ be the set of initial states.\n  Algorithmically, it amounts to implement the following loop\n  (iteration $i$)\n  \\vfill\n  \\begin{boxedminipage}{\\textwidth}\n  \\begin{center}\n  Forward-Reachability\n  \\begin{tabular}{rcl}\n     \\\\\n       {\\bf Safety Check} & ~~ & If $S^{(i)}$ contains a bad state, return {\\bf unsafe} \\\\\n        {\\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \\cup T(S^{(i)})$ \\\\\n    {\\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \\equiv S^{(i)}$, return {\\bf safe} \n  \\end{tabular}\n  \\end{center}\n  \\end{boxedminipage}\n  \\vfill\n  $T(S^{(i)}) = $ states that can be reached from $S^{(i)}$ with a transition\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Checking - Forward Reachability - Property Verified}\n  \\begin{boxedminipage}{\\textwidth}\n  \\begin{center}\n  Forward-Reachability\n  \\begin{tabular}{rcl}\n     \\\\\n       {\\bf Safety Check} & ~~ & \\colthrat{If $S^{(i)}$ contains a bad state, return {\\bf unsafe}}{2,5,8,11|handout:0} \\\\\n        {\\bf Next States} & ~~ & \\colthrat{Compute $S^{(i+1)} := S^{(i)} \\cup T(S^{(i)})$}{3,6,9,12|handout:0} \\\\\n    {\\bf Fix-Point Check} & ~~ & \\colthrat{If $S^{(i+1)} \\equiv S^{(i)}$, return {\\bf safe}}{4,7,10,13} \n  \\end{tabular}\n  \\end{center}\n  \\end{boxedminipage}\n  \\vfill\n  \\begin{overlayarea}{\\textwidth}{4cm}\n    \\only<1,2|handout:0>{\\scalebox{.6}{\\input{forward_1.pdf_t}}}\n    \\only<3-5|handout:0>{\\scalebox{.6}{\\input{forward_2.pdf_t}}}\n    \\only<6-8|handout:0>{\\scalebox{.6}{\\input{forward_3.pdf_t}}}\n    \\only<9-11|handout:0>{\\scalebox{.6}{\\input{forward_4.pdf_t}}}\n    \\only<12,13>{\\scalebox{.6}{\\input{forward_5.pdf_t}}}\n  \\end{overlayarea}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Checking - Forward Reachability - Property Not Verified}\n  \\begin{boxedminipage}{\\textwidth}\n  \\begin{center}\n  Forward-Reachability\n  \\begin{tabular}{rcl}\n     \\\\\n       {\\bf Safety Check} & ~~ & \\colthrat{If $S^{(i)}$ contains a bad state, return {\\bf unsafe}}{1} \\\\\n        {\\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \\cup T(S^{(i)})$ \\\\\n    {\\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \\equiv S^{(i)}$, return {\\bf safe}\n  \\end{tabular}\n  \\end{center}\n  \\end{boxedminipage}\n  \\vfill\n  \\begin{overlayarea}{\\textwidth}{4cm}\n    \\only<1|handout:0>{\\scalebox{.6}{\\input{forward_6.pdf_t}}}\n    \\only<2>{\\scalebox{.6}{\\input{forward_7.pdf_t}}}\n  \\end{overlayarea}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Back to the washing machine}\n\nIteration: \\only<1|handout:0>{0}\\only<2|handout:0>{1}\\only<3|handout:0>{2}\\only<4|handout:0>{3}\\only<5>{4 - Fix Point Reached - System is SAFE}\n  \\vfill\n  \\begin{center}\n    \\only<1|handout:0>{\\input{model_4_1}}\n    \\only<2|handout:0>{\\input{model_4_2}}\n    \\only<3|handout:0>{\\input{model_4_3}}\n    \\only<4|handout:0>{\\input{model_4_4}}\n    \\only<5>{\\input{model_4_5}}\n  \\end{center}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Checking - Backward Reachability}\n  \\begin{boxedminipage}{\\textwidth}\n  \\begin{center}\n  Backward-Reachability ($S^{(0)} \\equiv$ ``bad states'')\n  \\begin{tabular}{rcl}\n     \\\\\n       {\\bf Safety Check} & ~~ & If $S^{(i)}$ contains an initial, return {\\bf unsafe} \\\\\n        {\\bf Next States} & ~~ & Compute $S^{(i+1)} := S^{(i)} \\cup T^{-1}(S^{(i)})$ \\\\\n    {\\bf Fix-Point Check} & ~~ & If $S^{(i+1)} \\equiv S^{(i)}$, return {\\bf safe}\n  \\end{tabular}\n  \\end{center}\n  \\end{boxedminipage}\n  \\vfill\n  \\begin{overlayarea}{\\textwidth}{4cm}\n    \\only<1|handout:0>{\\scalebox{.6}{\\input{backward_1.pdf_t}}}\n    \\only<2>{\\scalebox{.6}{\\input{backward_2.pdf_t}}}\n  \\end{overlayarea}\n\n\\end{frame}\n", "meta": {"hexsha": "3867b956c45e6ffced3ea368ab833bfd1fb508d5", "size": 3931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture8/checking.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/checking.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/checking.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": 33.8879310345, "max_line_length": 143, "alphanum_fraction": 0.6186720936, "num_tokens": 1471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059560743423, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.6330466855813504}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage[margin=1.25in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{caption}\n\\usepackage{physics}\n\\usepackage[shortlabels]{enumitem}\n\n\n\\setlength\\parindent{0pt}\n\\newcommand{\\code}{\\lstinline[basicstyle=\\small]}\n\\lstset{\n    language=Python,\n    basicstyle=\\scriptsize\n}\n\n\n\\title{EE2703: Applied Programming Lab \\\\ \\Large Assignment 7: Circuit Analysis using Sympy}\n\\author{Soham Roy \\\\ \\normalsize EE20B130}\n\\date{\\today}\n\\begin{document}\n\n\\maketitle % Insert the title, author and date\n\n\n\n\\section{Introduction}\nThe goal of this assignment is to understand the symbolic algebra capabilities of python and to circuits using\nthe Laplace Transform. \\\\\nThe aim is also to understand the basics of the high pass and low pass filter circuits.\n\n\n\n\\section{Subquestions}\n\\subsection{Question 1}\nTo find the transfer function of the given circuit, and then find the unit step response.\nSolving the circuit by using the basic KCL and KVL laws, we get the following solution in matrix form:\n\\[\n    \\begin{pmatrix}\n        0                                    & 0             & 1 & -1/G \\\\\n        \\frac{-1}{1+sc_2R_2}                 & 1             & 0 & 0    \\\\\n        0                                    & -G            & G & 1    \\\\\n        -\\frac{1}{R_1} -\\frac{1}{R_2} - sC_1 & \\frac{1}{R_2} & 0 & sC_1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n        V1 \\\\\n        Vp \\\\\n        Vm \\\\\n        V0\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n        0 \\\\\n        0 \\\\\n        0 \\\\\n        -\\frac{Vi(s)}{R_1}\n    \\end{pmatrix}\n\\]\n\nWe then use the \\code{sympy} library to implement this in python and also solve for the voltage vector.\nWe calculate the Voltage response for a unit input, which would thus give me the transfer function of this circuit.\nWe then plot the Frequency response of this circuit. The following is the code:\n\n\\begin{lstlisting}\n    def lowpass(Vi, R1=10000, R2=10000, C1=1e-9, C2=1e-9, G=1.586):\n        A = sym.Matrix(\n            [\n                [0, 0, 1, -1 / G],\n                [-1 / (1 + s * R2 * C2), 1, 0, 0],\n                [0, -G, G, 1],\n                [-1 / R1 - 1 / R2 - s * C1, 1 / R2, 0, s * C1],\n            ]\n        )\n        b = sym.Matrix([0, 0, 0, -Vi / R1])\n        V = A.inv() * b\n\n        return A, b, V\n\n        \n    title = \"Lowpass Filter Magnitude Response\"\n\n    A, b, V = lowpass(1)\n    V_o = V[3]\n    print(V_o)\n    ww = np.logspace(0, 8, 801)\n    ss = 1j * ww\n    H = sym.lambdify(s, V_o, \"numpy\")\n    HH = H(ss)\n    plot(title, \"$\\omega (rad/s)$\", \"$|H(j\\omega)|$\",\n         ww, [abs(HH)], plotting_fn=plt.loglog)\n\\end{lstlisting}\nThe following plot is obtained.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{0.png}\n\\end{figure}\n\nOnce we have obtained the system response in \\code{sympy} symbolic form, we need to convert it to our standard\n\\code{scipy.signal.lti} form in order to work with it further, the following function does this job.\n\n\\begin{lstlisting}\n    def to_num_den(expr):\n        num, den = expr.as_numer_denom()\n        num = [float(i) for i in sym.Poly(num, s).all_coeffs()]\n        den = [float(i) for i in sym.Poly(den, s).all_coeffs()]\n        return num, den\n\\end{lstlisting}\n\nThe unit step response of the circuit i.e the output for an input of $u(t)$ is calculated using the following code:\n\n\\begin{lstlisting}\n    title = \"Lowpass Filter Step Response\"\n\n    V_o = lowpass(1 / s)[2][3]\n    H = sp.lti(*to_num_den(V_o))\n    t = np.linspace(0, 5e-3, 10000)\n    v = sp.impulse(H, T=t)[1]\n    plot(title, \"$t (s)$\", \"$V_o (V)$\", t, [v])\n\\end{lstlisting}\n\nThe following plot is obtained:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{1.png}\n\\end{figure}\n\n\\subsection{Question 2}\nThis time, we need to obtain the output for a mixed frequency input\n\\[V_i(t) = (\\sin(2000\\pi t)+\\cos(2*10^6\\pi t))u_0(t) Volts\\]\n\nThis is done as follows:\n\\begin{lstlisting}\n    title = \"Lowpass Filter Input Response\"\n\n    V_o = lowpass(1)[2][3]\n    H = sp.lti(*to_num_den(V_o))\n    t = np.linspace(0, 5e-3, 100000)\n    input = (np.sin(2000 * np.pi * t) + np.cos(2e6 * np.pi * t)) * (t > 0)\n    v = sp.lsim(H, U=input, T=t)[1]\n    plot(title, \"$t (s)$\", \"$V (V)$\", t, [input, v], [\"Input\", \"Output\"])\n\\end{lstlisting}\n\nThe following plots are obtained:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{2.png}\n\\end{figure}\n\nThis can be explained easily, since we know that a low pass filter only allows those frequencies to pass which are less than the pole frequency, i.e in this case $10^5$, thus the $10^3$ frequency component passes, whereas the $10^6$ frequency component is filtered out. \\\\Due to the very high frequency of the $10^6$ frequency signal, it appears as if this signal oscillates about the $10^3$ frequncy signal with the latter as it's mean value, in the input.\n\n\\subsection{Question 3}\nNow, we try to do the same analysis for a high pass filter. A high-pass filter is a filter that passes signals with a frequency higher than a certain cutoff frequency and attenuates signals with frequencies lower than the cutoff frequency.\nThe code for this part is as follows:\n\\begin{lstlisting}\n    def highpass(Vi, R1=10000, R3=10000, C1=1e-9, C2=1e-9, G=1.586):\n        A = sym.Matrix(\n            [\n                [0, -1, 0, 1 / G],\n                [s * C2 * R3 / (s * C2 * R3 + 1), 0, -1, 0],\n                [0, G, -G, 1],\n                [-s * C2 - 1 / R1 - s * C1, 0, s * C2, 1 / R1],\n            ]\n        )\n        b = sym.Matrix([0, 0, 0, -Vi * s * C1])\n        V = A.inv() * b\n\n        return A, b, V\n\n\n    title = \"Highpass Filter Magnitude Response\"\n\n    A, b, V = highpass(1)\n    V_o = V[3]\n    print(V_o)\n    ww = np.logspace(0, 8, 801)\n    ss = 1j * ww\n    H = sym.lambdify(s, V_o, \"numpy\")\n    HH = H(ss)\n    plot(title, \"$\\omega (rad/s)$\", \"$|H(j\\omega)|$\",\n         ww, [abs(HH)], plotting_fn=plt.loglog)   \n\\end{lstlisting}\n\nThe following is the frequency response for the given high pass filter:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{3.png}\n\\end{figure}\n\n\\subsection{Question 4}\nNow, we try to obtain the response of this filter for a damped sinusoidal input as follows:\n\\[V_{i, hf}(t) = e^{-5 \\cdot 10^4t} cos(2\\pi \\cdot 10^8 \\cdot t) \\]\n\\[V_{i, lf}(t) = e^{-5t} cos(2\\pi \\cdot 10 \\cdot t)\\]\n\nThe code for this is as follows:\n\\begin{lstlisting}\n    title = \"Highpass Damped Response for High Frequency\"\n\n    V_o = highpass(1)[2][3]\n    H = sp.lti(*to_num_den(V_o))\n    t = np.linspace(0, 1e-4, 1000)\n    input = np.cos(2 * np.pi * 1e8 * t) * np.exp(-5e4 * t) * (t > 0)\n    v = sp.lsim(H, U=input, T=t)[1]\n    plot(title, \"$t (s)$\", \"$V (V)$\", t, [input, v], [\"Input\", \"Output\"])\n    \n    \n    title = \"Highpass Damped Response for Low Frequency\"\n    \n    t = np.linspace(0, 1, 1000)\n    input = np.cos(20 * np.pi * t) * np.exp(-5 * t) * (t > 0)\n    v = sp.lsim(H, U=input, T=t)[1]\n    plot(title, \"$t (s)$\", \"$V (V)$\", t, [input, v], [\"Input\", \"Output\"])\n\\end{lstlisting}\n\nThe following graphs are obtained for the high frequency and low frequency inputs respectively.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{4a.png}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{4b.png}\n\\end{figure}\n\nThis can be explained quite easily, we know that a high pass filter will not allow the frequency components lower than pole freuqency to pass. Thus, effectively the low frequency component is filtered and thus it is not observed in the output.\\\\\nWhereas, in the high frequency input case, we see that the output is pretty much same as the input, which indicates that our filter is working as required.\n\n\\subsection{Question 5}\nWe aim to find the unit step response of the high pass filter. For this, we pass $u(t)$ (in Laplace domain 1/s) in the \\code{highpass} function, and then compute the inverse Laplace using the \\code{scipy.signal.impulse} function.\nThe following code does this:\n\n\\begin{lstlisting}\n    title = \"Highpass Step Response\"\n\n    V_o = highpass(1 / s)[2][3]\n    H = sp.lti(*to_num_den(V_o))\n    t = np.linspace(0, 5e-3, 10000)\n    v = sp.impulse(H, T=t)[1]\n    plot(title, \"$t (s)$\", \"$V_o (V)$\", t, [v])\n\\end{lstlisting}\n\nThe following is the obtained response:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{5.png}\n\\end{figure}\n\nLet's understand this response. As soon as the voltage is applied, i.e at t $\\rightarrow0^+$, the capacitors behave as short-circuited, and thus we see a positive voltage at the output node, whereas at t $\\rightarrow\\infty$ (for practical purposes, this time is not that large), the capacitors would behave as open-circuited for DC-value of voltage and thus we would see zero volts at the output node.\n\n\\section{Conclusion}\nIn this assignment, we have understood the use of \\code{sympy} library to do symbolic algebra. We have also learnt how this can be integrated with out previous knowledge of \\code{scipy.signal} library to help solve circuits. We have also looked at some basic circuits like the high pass and the low pass filter and their responses for various inputs.\n\n\n\\end{document}\n", "meta": {"hexsha": "c70bf7c46bef81becd29a42e1c5b25e6f4f1639b", "size": 9171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_07/LaTeX/Report.tex", "max_stars_repo_name": "sohamroy19/EE2703", "max_stars_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_stars_repo_licenses": ["MIT"], "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_07/LaTeX/Report.tex", "max_issues_repo_name": "sohamroy19/EE2703", "max_issues_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_issues_repo_licenses": ["MIT"], "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_07/LaTeX/Report.tex", "max_forks_repo_name": "sohamroy19/EE2703", "max_forks_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_forks_repo_licenses": ["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.2730769231, "max_line_length": 457, "alphanum_fraction": 0.6298113619, "num_tokens": 2865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6329713170198312}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{algorithm}\n\\usepackage[noend]{algpseudocode}\n\n\\usepackage{titlesec}\n\\newcommand{\\sectionbreak}{\\clearpage}\n\n\\begin{document}\n\\title{Solving constraint satisfaction problems using arc consistency and path consistency techniques}\n\\maketitle\n\\section{Local consistency algorithms}\n\\subsection{Arc consistency}\nFor the arc consistency we use AC1 algorithm.\n\\begin{algorithm}\n    \\caption{AC1 algorithm}\n    \\begin{algorithmic}[1]\n        \\Procedure{Revise}{$v_i,v_j$}\\Comment{a network with two variables $v_i$,$v_j$, domains $D_i$ and $D_j$, and constraint $R_{ij}$ }\n            \\For {each $ a_i\\in D_i$}\n                \\If {there is no $a_j \\in D_j$ with $(a_i,a_j) \\in R_{ij}$}\n                    \\State {remove $a_i$ from $D_i$}\n                \\EndIf\n            \\EndFor\n        \\EndProcedure\n    \\end{algorithmic}\n    \\begin{algorithmic}[2]\n        \\Procedure{AC1}{$N$}\\Comment{a constraint network $N = <V,D,C>$}\n            \\Repeat\n                \\For {each arc $(v_i, v_j)$ with $R _{ij}\\in C$}\n                    \\State{Revise$(v_i,v_j)$}\n                    \\State{Revise$(v_j,v_i)$}\n                \\EndFor\n            \\Until{no domain is changed}\n        \\EndProcedure\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Path consistency}\nFor the path consistency we use PC1 algorithm.\n\\begin{algorithm}\n    \\caption{PC1 algorithm}\n    \\begin{algorithmic}[1]\n        \\Procedure{Path\\_Revise}{$\\{v_i,v_j\\},v_k$}\\Comment{a binary network $<V,D,C>$ with variables $v_i$,$v_j$,$v_k$}\n            \\For {each pair $ (a_i,a_j)\\in R_{ij}$}\n                 \\If {there is no $a_k \\in D_k$ such that $(a_i,a_k) \\in R_{ik}$ and $(a_j,a_k) \\in R_{jk}$} \\State {remove $(a_i,a_j)$ from $R_{ij}$}\n                \\EndIf\n            \\EndFor\n        \\EndProcedure\n    \\end{algorithmic}\n    \n    \\begin{algorithmic}[2]\n        \\Procedure{PC1}{$N$}\\Comment{a constraint network $N = <V,D,C>$}\n            \\Repeat\n                \\For {each (ordered) triple of variables $v_i, v_j, v_k$}\n                    \\State{Path\\_Revise$({v_i,v_j},v_k)$}\n                \\EndFor\n            \\Until{no constraint is changed}\n        \\EndProcedure\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\section{Python implementation}\nFor the implementation we use modified \\textbf{python\\_constraint} module.\n\\subsection{Installation}\n\\begin{itemize}\n    \\item Clone the repository \\newline \\texttt{git clone https://github.com/asergeenko/python-constraint.git}\n    \\item Build and setup the module \\newline \\texttt{python setup.py build}\\newline \\texttt{python setup.py install}\n\\end{itemize}\n\\subsection{Module overview}\nPython implementations of the AC1 and PC1 algorithms are located in \\texttt{consistency.py} file. There are four methods:\\\\\\\\\n\\textbf{arc\\_revise}\\textit{(var1,var2,problem,constraints\\_for\\_variable)}\\\\\n\\textit{\\#Implements REVISE procedure from AC1 algorithm}\\\\\n\n\\textbf{Input:}\n\n\\textit{var1} and \\textit{var2} - variables to revise,\n\n\\textit{problem} - \\textbf{python\\_constraint}'s \\textit{Problem} instance,\n\n\\textit{constraints\\_for\\_variable} - dictionary with constraints for variable \\textit{var1}\n\n(returned by \\textit{getArcs} function from \\textbf{constraint} module).\\\\\n\n\n\\textbf{Output:}\n\nReturns \\textit{True} if arc \\textit{(var1,var2)} is not arc-consistent\n\nand some values are removed from the domain.\\\\\\\\\n\\textbf{ac1}\\textit{(arcs, problem)}\\\\\n\\textit{\\#Implements AC1 procedure}\\\\\n \n\\textbf{Input:}\n\n\\textit{arcs} - arcs (returned by \\textit{getArcs} function from \\textbf{constraint} module),\n\n\\textit{problem} - \\textbf{python\\_constraint}'s \\textit{Problem} instance\\\\\\\\ \n\\textbf{path\\_revise}\\textit{(var1, var2, var3,problem)}\\\\\n\\textit{\\#Implements PATH\\_REVISE procedure from PC1 algorithm}\\\\\n\n\n\\textbf{Input:}\n\n\\textit{var1},\\textit{var2}.\\textit{var3} - variables to revise,\n\n\\textit{problem} - \\textbf{python\\_constraint}'s \\textit{Problem} instance\\\\\n\n\n\\textbf{Output:}\n\nReturns \\textit{True} if the pair \\textit{(var1,var2)} is not path-consistent relative to \\textit{var3}\n\nand some values are removed.\\\\\\\\\n\\textbf{pc1}\\textit{(problem)}\\\\\n\\textit{\\#Implements PC1 procedure}\\\\\n\n\n\\textbf{Input:}\n\n\\textit{problem} - \\textbf{python\\_constraint}'s \\textit{Problem} instance\\\\\n \n\\section{Problem solving examples}\n\\subsection{Examples overview}\nThese algorithms are suitable for CSP problems with binary constraints. So we have \\textit{N-Queens problem} (can be found in \\texttt{examples/queens/queens.py}) and \\textit{Map coloring problem} (can be found in \\texttt{examples/map\\_coloring/map\\_coloring.py}).\nN-queens example is the part of the original \\textbf{python\\_constraint} module and has just one parameter:\\\\\n\n\\texttt{size = 8} \\textit{\\# size of the chessboard}\\\\\\\\\nMap coloring example is new and has the following parameters:\\\\\n\n\\texttt{countries = ['A','B','C']} \\textit{\\# countries}\n\n\\texttt{num\\_colors = 2} \\textit{\\# number of colors}\n\n\\texttt{neighbors = ['AB','BC','CA']} \\textit{\\# countries that border each other}\n\\subsection{Command-line parameters}\n\n\\texttt{python queens.py [-h] [-s]\\footnote{This parameter is used only with \\texttt{queens.py} example.} [-ac] [-pc]}\\\\\n\\texttt{python map\\_coloring.py [-h] [-ac] [-pc]}\\\\\\\\\n\\texttt{-h} - show help message\\\\\n\\texttt{-s} - show solutions on the chessboard (doesn't show by default)\\\\\n\\texttt{-ac} - use arc consistency algorithm (not used by default)\\\\\n\\texttt{-pc} - use path consistency algorithm (not used by default)\\\\\n\\end{document}\n\n", "meta": {"hexsha": "3ebe0482b4ade885eef906569f62d69c2cd2ee92", "size": 5541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/csp_local_consistency.tex", "max_stars_repo_name": "asergeenko/python-constraint", "max_stars_repo_head_hexsha": "23caef12d504022bf3ec6ca2fd2348c138a3cce2", "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/csp_local_consistency.tex", "max_issues_repo_name": "asergeenko/python-constraint", "max_issues_repo_head_hexsha": "23caef12d504022bf3ec6ca2fd2348c138a3cce2", "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/csp_local_consistency.tex", "max_forks_repo_name": "asergeenko/python-constraint", "max_forks_repo_head_hexsha": "23caef12d504022bf3ec6ca2fd2348c138a3cce2", "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": 37.4391891892, "max_line_length": 263, "alphanum_fraction": 0.6776755098, "num_tokens": 1642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6329713073329236}}
{"text": "\\section{Topological division rings and fields}\n\\label{sec:topological-division-rings-fields}\n\n\\para Vector spaces with a compatible topology can not only defined for vector spaces over the ground fields \n$\\R$ and $\\C$ but also over fields $\\fldK$ carrying an absolute value\n$|\\cdot | : \\fldK \\to \\R_{\\geq 0}$. This endows the ground field with a topology which will be needed in the\ndefinition of a topological vector space. We therefore give here a brief introduction to topological division\nrings and fields first.\n\n\\begin{definition}\n  Let $R$ be a division ring. By an \\emph{absolute value} on $R$ one understands a map $ |\\cdot | : R \\to \\R_{\\geq 0}$\n  such that the following axioms hold true.\n  \\begin{axiomlist}[VDR]\n  \\item \n  \\label{axiom:field-absolute-value-multiplicativity}\n     The function $| \\cdot |$ is multiplicative that is \n     \\[ |xy| = |x|  \\, | y| \\quad \\text{for all } x,y \\in R \\ . \\]\n  \\item \n  \\label{axiom:field-absolute-value-subadditivity} \n    The triangle inequality is satisfied which means that \n    \\[ |x + y| \\leq  |x| +  | y| \\quad  \\text{for all } x,y \\in R \\ . \\]\n  \\item\n  \\label{axiom:field-absolute-value-nondegeneracy} \n  For all $x \\in R$ the relation $|x|=0$ holds true if and only if $x=0$. \n  \\end{axiomlist}\n  A division ring or field endowed with an absolute value is called a \\emph{valued division ring} \n  respectively a \\emph{valued field}. \n  An absolute value $|\\cdot|$ on a division ring $R$ and the corresponding valued\n  division ring $(R,|\\cdot|)$ are called \\emph{non-archimedean} if \n  the \\emph{strong triangle inequality} is satisfied that is if\n  \\begin{axiomlist}[VDR]\n  \\setcounter{enumi}{3}\n  \\item\\label{axiom:field-absolute-value-non-archimedean} \n    $ |x + y| \\leq  \\max \\{ |x| , | y| \\} $ for all $x,y \\in R$.\n  \\end{axiomlist}\n  Otherwise $|\\cdot|$ and $(R,|\\cdot|)$ are called \\emph{archimedean}.\n\\end{definition}\n\n\n\\begin{lemma}\n  Let $(R,|\\cdot|)$ be a valued division ring. Then\n  \\begin{romanlist}\n  \\item\\label{ite:absolute-value-one}\n     $|1|=1$,\n   \\item\\label{ite:absolute-value-negative}\n     $|-x| =|x|$ for all $x\\in R$, and\n  \\item\\label{ite:absolute-value-difference}\n     $\\big| |x| - |y| \\big| \\leq |x - y|   \\leq  |x| + |y|$ for all $x,y\\in R$.\n  \\end{romanlist}\n\\end{lemma}\n\n\\begin{proof}\n  \\ref{ite:absolute-value-one} holds true since $|1| = |1^2| = |1|^2$ and $|1| \\neq 0$ by $1 \\neq 0$.\n  To verify \\ref{ite:absolute-value-negative} it suffices to show that $|-1| =1$. But that holds true\n  since $|-1|^2 = | (-1)^2| = 1$ and $|-1| \\geq 0$.\n  The last claim follows by\n  \\[\n  - |x-y| = |x| - (|y-x| +|x|) \\leq |x| - |y| \\leq  |x-y| + |y | - |y| = |x-y| \n  \\]\n  and\n  \\[\n    |x - y|  = | x + (-y)|  \\leq  |x| + |-y| = |x| + |y| \\ .\n  \\]\n\\end{proof}\n\n\\begin{examples}\n\\begin{environmentlist}\n\\item\n  Obviously, the \\emph{standard absolute values}\n  \\[ \n    |\\cdot |_\\infty : \\Q, \\R\\to \\R_{\\geq 0}, \\: x \\mapsto\n    \\begin{cases}\n      x & \\text{if } x\\geq 0\\\\\n      -x & \\text{if } x< 0\n    \\end{cases}\n  \\quad\\text{and}\\quad\n    |\\cdot |_\\infty : \\C\\to \\R_{\\geq 0}, \\: z \\mapsto \\sqrt{z \\overline{z}}\n  \\]\n  are absolute values on the fields $\\Q$, $\\R$ and $\\C$, respectively. These absolute values are all archimedean\n  since $|1+ 1|_\\infty = 2 > 1$. Unless mentioned differently, we always assume \n  $\\Q$, $\\R$ and $\\C$ to be equipped with the standard absolute values. If no confusion can arise we usually\n  write $|\\cdot|$ instead of $|\\cdot |_\\infty$.\n\\item\n  The \\emph{standard absolute value} on the quaternions\n  \\[\n     |\\cdot |_\\infty : \\H \\to \\R_{\\geq 0} , \\: q = a + b \\quati + c\\quatj + d \\quatk \\mapsto \\sqrt{\\overline{q}q} = \\sqrt{a^2 +b^2+ c^2 + d^2} \\ , \n  \\]\n  where $a,b,c,d$ are real, is an archimedean absolute value. Usually it is briefly denoted $|\\cdot|$.   \n\\item \n  For every division ring $R$ the map \n  \\[ |\\cdot| :R \\to \\R, \\: x \\mapsto\n    \\begin{cases}\n    0 & \\text{if } x=0 ,\\\\\n    1 & \\text{else} \n  \\end{cases}\n  \\]\n  is a non-archimedean absolute value. It is called the \\emph{trivial absolute value} on $R$.\n\\item\n  An absolute value  $|\\cdot|:\\fldF \\to\\R_{\\geq 0}$ defined on a finite field $\\fldF$ has to be trivial.\n  To see this observe that for each $x\\in \\fldK^\\times$ there\n  exists an $n\\in \\N$ such that $x^n =1$. This entails  $|x|^n=1$, hence $|x|=1$\n  for all $x\\in \\fldK^\\times$. So $|\\cdot|$ is trivial.\n\\item \n  The field of formal Laurent power series $\\fldK ((X))$ over a field $\\fldK$ can be equipped\n  with an absolute value as follows. Choose $0<\\varepsilon < 1$\n  and define the absolute value $\\left| \\sum_{k\\in \\Z} a_k X^k\\right| $ of an element\n  $\\sum_{n\\in \\Z} a_n X^n\\in \\fldK ((X)) $ as $\\varepsilon^n$, where $n$ is the minimal integer such that $a_n\\neq 0$.  \n\\item\n  Let $p$ be prime number. For every integer $m\\neq 0$ let $\\nu_p(m)$ be the exponent of $p$ in the prime factor decomposition of $m$\n  that is $m = p^{\\nu_p(n)}n$ where $n$ is relatively prime to $p$.\n  For $m \\in \\Z$ and $n\\in \\gzN$ one defines the \\emph{$p$-adic absolute value} of the rational number $x = \\frac mn$ by\n  \\[\n    \\left| x \\right|_p =\n    \\begin{cases}\n      0 & \\text{if } m=0 \\ ,\\\\\n      p^{-\\nu_p(m) +\\nu_p(n)} & \\text{else}\\ . \n    \\end{cases}\n  \\]\n  Note that $ \\left| x \\right|_p$ does not depend on the particular representation of $x$ as the quotient of integers $m$ and $n$.\n  By definition it is immediately clear that the $p$-adic absolute value is an absolute value on $\\Q$ indeed. \n  It is non-archimedean.\n\\end{environmentlist}\n\\end{examples}\n\n\\begin{proposition}\n  A valued division ring $(R,|\\cdot|)$ is non-archimedean if and only if the image of $\\Z$ under\n  the canonical map  $\\Z\\to R$ is bounded. \n\\end{proposition}\n\n\\begin{proof}\n  Assume that $(R,|\\cdot|)$ is a non-archimedean valued division ring.\n  Then, $|0 \\cdot 1| = |0|= 0 $ and, under the assumption that $|(n-1)\\cdot 1|\\leq 1$ for some $n\\in \\gzN$,\n  $|n\\cdot 1| = | (n-1)\\cdot 1 + 1 | = \\max \\{ |(n-1)\\cdot 1| , 1 \\} = 1$.\n  Hence by induction and since $|-1| =1$ one obtains that $|n\\cdot 1|\\leq 1$ for all $n\\in \\Z$,\n  and the image of $\\Z$ in $R$ is bounded.\n\n  To show the converse assume that the image of $\\Z$ in $R$ is bounded by some constant $C>0$. Then, for all $x,y\\in R$\n  and $n\\in \\gzN$ by the binomial formula and the triangle inequality\n  \\[\n    |x+y|^n =\\left|\\sum_{k=0}^n {n \\choose k} x^k y^{n-k} \\right|\n    \\leq (n+1) \\,C \\max \\{|x|,|y|\\}^n \\ .\n  \\]\n  Taking the $n$-th root gives $|x+y|\\leq \\big( (n+1)C\\big)^{1/n} \\max \\{|x|,|y|\\}$ which after passing to the limit $n\\to\\infty$\n  entails  $|x+y| \\leq \\max \\{|x|,|y|\\}$ since $\\lim\\limits_{n\\to\\infty} \\big( (n+1)C\\big)^{1/n} = 1$. Hence\n  $(R,|\\cdot|)$ is non-archimedean. \n\\end{proof}\n\n\\begin{proposition}\n  Let $|\\cdot|$ be an absolute value on the division ring $R$. Then for every $\\tau>0$ with $\\tau\\leq 1$ the\n  map $|\\cdot|^\\tau: R\\to\\R_{\\geq 0}$ is an absolute value on $R$ as well.\n  It is archimedean if and only if $|\\cdot|$ is archimedean. \n\\end{proposition}\n\n\\begin{proof}\n  To prove that $|\\cdot|^\\tau$ is an absolute value it suffices to show that $(a+b)^\\tau \\leq a^\\tau + b^\\tau$\n  for all $a,b\\geq 0$. Without loss of generality we may assume $a \\geq b>0$. By dividing through $b^\\tau$\n  one sees that the claim is equivalent to $(t +1 )^\\tau \\leq t^\\tau + 1$ for all $t\\geq 1$.\n  For $t=1$ this is certainly true. The derivative of the function\n  $h :\\rightopenint{1,\\infty} \\to\\R$, $t\\mapsto (t +1 )^\\tau - t^\\tau$ now is\n  given by $h'(t) = \\tau \\big( (t +1 )^{\\tau-1} - t^{\\tau-1} \\big)$ which is negative\n  since $\\tau-1\\leq 0$ and $1+ t > t\\geq 1$. Hence $h$ is monotone decreasing\n  and $(t +1 )^\\tau - t^\\tau \\leq  1$ for all $t\\geq 1$.\n\n  Since $\\openint{0,\\infty} \\to \\R$, $t\\mapsto t^\\tau$ is strictly increasing  and unbounded,\n  the image of $\\Z$ in $R$ is unbounded with respect to    $|\\cdot|$  if and only if\n  it is with respect to $|\\cdot|^\\tau$.  \n\\end{proof}\n\n\\para An absolute value $ |\\cdot | : R \\to \\R_{\\geq 0}$ on a division ring $R$ induces the metric\n$d : R \\times R \\to \\R_{\\geq 0}$, $(x,y) \\mapsto |x-y|$ which then gives \nrise to a topology on $R$. This topology has the following properties:\n\\begin{axiomlist}[TDR]\n  \\item\\label{axiom:topological-division-ring-continuity-addition}\n     Addition $+ : R \\times R \\to R$ is continuous.\n  \\item\\label{axiom:topological-division-ring-continuity-multiplication} \n     Multiplication $\\cdot : R \\times R \\to R$ is \n     continuous. \n  \\item\\label{axiom:topological-division-ring-continuity-inversion} \n    Inversion $(\\:\\cdot\\:)^{-1}:R^\\times \\to R^\\times $ is continuous, where $R^\\times$ denotes the\n    set of units in $R$ i.e.~$R^\\times = R \\setminus \\{ 0\\}$. \n\\end{axiomlist}\n\n\\begin{proof}\n   Addition is continuous since  for all $a,b,x,y \\in R$ by the triangle inequality\n   \\[ d ( x + y , a+ b ) = | x + y -( a+ b)| \\leq | x-a| + | y-b| = d(x,a) + d(y,b)\\ .\\] \n   Actually, this even shows  that addition is Lipschitz continuous. \n   Now fix $a,b \\in R$ and let $C = \\max \\{ |a|,|b| \\} + 1$. Then for all $x,y \\in R$ \n   with $d(y,b) <  1$\n   \\[ d ( x \\cdot y , a \\cdot b ) = | (x \\cdot y - a \\cdot y) + (a \\cdot y - a \\cdot b)| \n   \\leq | x-a| \\, |y|  + |a| \\, | y-b| \\leq C \\big(  d(x,a) + d(y,b) \\big) \\ .\\] \n   Hence multiplication is continuous.\n   Finally, fix $a \\in R^\\times$ and let $x \\in R^\\times $ with $d(x,a) <  \\frac{|a|}{2}$. Then \n   $|x| \\geq |a| - d(x,a) > \\frac{|a|}{2} >0$ and\n   \\[ d \\left( x^{-1} , a^{-1} \\right) =  \\left|  x^{-1} - a^{-1} \\right| = \\left|  x^{-1} \\cdot a^{-1} \\right| \n   \\, | x-a | = \\frac{1}{|x| \\, |a|} d( x,a ) <  \\frac{2}{|a|^2} d( x,a )  \\ .\\] \n   So inversion is also continuous.\n\\end{proof}\n\n\\begin{definition}\n A division ring or field $R$ which is equipped with a topology so that \n \\ref{axiom:topological-division-ring-continuity-addition},\n \\ref{axiom:topological-division-ring-continuity-multiplication} and\n \\ref{axiom:topological-division-ring-continuity-inversion} are satisfied is called a\n \\emph{topological division ring} or a \\emph{topological field}, respectively.\n\\end{definition} \n\n\\begin{lemma}\\label{thm:zero-neighborhood-topological-division-ring-infinite}\n  If $|\\cdot|$ is a non-trivial absolute value on the division ring $R$, then there exists an element\n  $t\\in R^\\times$ such that the sequence $(t^n)_{n\\in\\N}$ converges to $0$. Furthermore in this case\n  every $0$-neighborhood in $R$ contains infinitely many elements.\n\\end{lemma}\n\\begin{proof}\n  By non-triviality of $|\\cdot|$ there exists $t\\in R^\\times$ such that $|t|\\neq 1$. By possibly\n  passing to $t^{-1}$ we can assume $|t|<1$. Since then $\\lim\\limits_{n\\to\\infty} |t|^n =0$,\n  the sequence $(t^n)_{n\\in\\N}$ converges to $0$.  This implies in particular that \n  for every $\\varepsilon >0$ the open ball $\\ball (0,\\varepsilon) =\\{t \\in R \\mid |t| < \\varepsilon \\}$\n  contains infinitely many elements. So the lemma is proved. \n\\end{proof}\n\n\n\n\\begin{definition}\n  Two absolute values $|\\cdot|$ and $|\\cdot|^\\prime$ on a division ring $R$ are called \\emph{equivalent}\n  if they induce the same topology on $R$. \n\\end{definition}\n\n\\begin{theorem}\n  Let $|\\cdot|$ and $|\\cdot|^\\prime$ be two absolute values on the division ring $R$.\n  Then they are equivalent if and only if there exists $e>0$ such that $|\\cdot|^\\prime =|\\cdot|^\\tau$.\n  In particular the trivial absolute value is the only one inducing the discrete topology on $R$. \n\\end{theorem}\n\n\\begin{proof}\n  Let us first show the following proposition.\n  \\begin{enumerate}[label={\\textup{({\\sffamily A})}},align=left,leftmargin=*]\n  \\item\\label{ite:absolute-values-preserving-unit-balls} \n    If $|\\cdot|$ and $|\\cdot|^\\prime$ are equivalent, then  the relation $|x|< 1$ holds true for $x \\in R^\\times$\n    if and only if $|x|^\\prime< 1$. \n  \\end{enumerate}\n  Since $\\left| x^{-1}\\right| =\\frac{1}{|x|}$ and $\\left| x^{-1}\\right|^\\prime =\\frac{1}{|x|^\\prime}$\n  for all $x \\in R^\\times$, \\ref{ite:absolute-values-preserving-unit-balls}\n  implies that $|x|> 1$ if and only if $|x|^\\prime> 1$ and that  $|x|= 1$ if and only if $|x|^\\prime = 1$.\n  To verify claim \\ref{ite:absolute-values-preserving-unit-balls} assume now that $0 < |x|< 1$.\n  Then  $\\lim\\limits_{n\\to\\infty}|x^n|=0$, hence $(x^n)_{n\\in\\N}$ converges to $0$. By assumption,\n  $\\lim\\limits_{n\\to\\infty}|x^n|^\\prime=0$ then holds as well which implies that $|x|^\\prime<1$.\n  By switching  $|\\cdot|$ and $|\\cdot|^\\prime$  the converse holds true, so\n  \\ref{ite:absolute-values-preserving-unit-balls} is proved.\n  \n\n  Next we show that $|\\cdot|$ is trivial  if and only if the induced topology on $R$ is discrete.\n  Namely, if  $|\\cdot|$ is non-trivial, then there exists $x\\in R^\\times$ such  that  $|x| \\neq 1$. After\n  possibly passing to $\\frac 1x$ we can achieve that  $|x| < 1$. So $\\lim\\limits_{n\\to\\infty}|x^n|=0$, which\n  means that $(x^n)_{n\\in\\N}$ is a sequence of non-zero elements of $R$ converging to $0$. But this implies that\n  the singleton $\\{ 0\\}$ is not  open in the topology induced by $|\\cdot|$, hence this topology is non-discrete. \n  Since obviously the trivial absolute value induces the discrete topology on $R$ the second claim of the theorem is\n  proved.\n  \n  Now assume that $|\\cdot|^\\prime =|\\cdot|^\\tau$ for some $\\tau>0$. Then a subset $B \\subset R$ is a metric\n  open ball with respect to $|\\cdot|$ if and only if it is one with respect to $|\\cdot|^\\prime$\n  since for $x \\in R$ and $\\varepsilon >0$\n  \\begin{equation*}\n  \\begin{split}\n    &\\big\\{ y \\in R \\bigmid |y -x| < \\varepsilon \\big\\}  = \\big\\{ y \\in R \\bigmid |y-x|^\\prime < \\varepsilon^\\tau \\big\\}\n    \\text{ and } \\\\\n    &\\big\\{ y \\in R \\bigmid |y- x|^\\prime < \\varepsilon \\big\\}  = \\big\\{ y \\in R \\bigmid |y-x| < \\varepsilon^{1/\\tau} \\big\\} \\ .\n  \\end{split}\n  \\end{equation*}\n  Hence the open sets with respect to the metric defined by $|\\cdot|$ coincide with those defined by $|\\cdot|^\\prime$ and\n  the two absolute values  are equivalent.\n\n  Let us finally show the other direction and assume that $|\\cdot|$ and $|\\cdot|^\\prime$ are equivalent.\n  By the already proven second claim of the theorem we can restrict to the case where the induced topology is non-discrete\n  which means to the case where both  $|\\cdot|$ and $|\\cdot|^\\prime$ are non-trivial.\n  We show that there exists $\\tau >0$ such that $|x|^\\prime =  |x|^\\tau $ for all $x\\in R^\\times$ with $ |x|> 1$.\n  This is sufficient, since if $ |x|= 1$, then $|x|^\\prime =  1 = |x|^\\sigma $ for any $\\sigma >0$ \n  by \\ref{ite:absolute-values-preserving-unit-balls}, and since if $x\\in R^\\times$ with $ |x|< 1$ then\n  $ |x^{-1}| > 1$ and\n  \\[\n     |x|^\\prime = \\frac{1}{\\left|x^{-1}\\right|^\\prime} = \\frac{1}{\\left|x^{-1}\\right|^\\tau} = |x|^\\tau \\ .\n  \\]\n  The existence of a $\\tau >0$ with the claimed property is equivalent to the function\n  \\[\n       R^\\times \\to \\R,\\: x \\mapsto \\frac{\\ln |x|^\\prime}{\\ln |x|}\n  \\]\n  being constant. Assume that that is not the case. Then there exist $x,y \\in R^\\times$\n  with $|x|,|y|>1$ such that\n  $\\frac{\\ln |x|^\\prime}{\\ln |x|} \\neq \\frac{\\ln |y|^\\prime}{\\ln |y|}$. By possibly switching $x$ and $y$ we\n  can assume  $\\frac{\\ln |x|^\\prime}{\\ln |x|} < \\frac{\\ln |y|^\\prime}{\\ln |y|}$.\n  But that implies $\\frac{\\ln |x|^\\prime}{\\ln |y|^\\prime} < \\frac{\\ln |x|}{\\ln |y|}$ since the logarithms are positive\n  by assumptions on $x$ and $y$ and \\ref{ite:absolute-values-preserving-unit-balls}. Hence there exists a\n  rational number $\\frac pq$ with $p,q \\in \\gzN$ such that\n  \\[\n   \\frac{\\ln |x|^\\prime}{\\ln |y|^\\prime} < \\frac pq < \\frac{\\ln |x|}{\\ln |y|} \\ . \n  \\]\n  Then $|x^q|^\\prime <  |y^p|^\\prime$ and $|y^p| <  |x^q|$ which entails\n  \\[\n    \\left| \\frac{x^q}{y^p} \\right|^\\prime < 1 \\text{ and }\n    \\left| \\frac{x^q}{y^p} \\right| > 1 \\ .\n  \\] \n  This contradicts \\ref{ite:absolute-values-preserving-unit-balls} and the theorem is proved.\n\\end{proof}\n\n\\begin{remarks}\n  \\begin{environmentlist}\n  \\item\n    By  Ostrowski's theorem \\cite[p.~276]{OstLF}, see also \\cite[Thm.~3.1.3]{GouAN}, every non-trivial absolute value\n    on the field $\\Q$ of rational numbers is either equivalent to the standard absolute value $|\\cdot|_\\infty$ or to a\n    $p$-adic absolute value $|\\cdot|_p$  for some prime number $p$. Observe that for different primes $p$ and $q$ the\n    absolute values $|\\cdot|_p$ and $|\\cdot|_q$ are not equivalent.\n  \\item\n    Another theorem of Ostrowski \\cite[p.~284]{OstLF}, sometimes called big Ostrowski's theorem, tells that for every archimedean\n    valued field $(\\fldK,|\\cdot|)$ there exists an embedding $\\iota :\\fldK \\hookrightarrow \\C$ into the field of complex numbers\n    with its standard absolute value and a positive real number $\\tau\\leq 1$ such that\n    \\[\n         |x| =|\\iota(x) |_\\infty^\\tau \\quad \\text{for all } x \\in \\fldK \\ .\n    \\]\n    In particular this means that every complete archimedean valued field is isomorphic to either $(\\R,|\\cdot|_\\infty^\\tau)$ or\n    $(\\C,|\\cdot|_\\infty^\\tau)$ for some positive $\\tau\\leq 1$.\n  \\item\n    The $p$-adic absolute values on $\\Q$  have extensions to $\\R$ by \\cite[XII, \\S4, Thm.~4.1]{LanA3rd}. \n    This is a highly non-obvious result. To prove it one has to check first that $|\\cdot|_p$ can be extended to an absolute \n    value $|\\cdot|$ on the field $\\fldk$ of real numbers algebraic over $\\Q$. This extended absolute value is, \n    and that turns out to be crucial, again non-archimedean. \n    Now one observes that $|\\cdot|$ can be extended to the polynomial ring $\\fldk [X]$ by the \\emph{Gau{\\ss} norm}\n    $|p(X)| = \\max_{0\\leq i \\leq n} \\{a_i\\}$ where $p(X)= a_n X^n + \\ldots + a_1 X + a_0 \\in\\fldk [X]$.\n    The Gau{\\ss} norm obviously extends to an absolute value on the fraction field $\\fldk(X)$.\n    Again, this extension is non-archimedean. \n    Now one recalls that $\\R$ is a purely transcendental field extension of $\\fldk$ and uses a transfinite induction type\n    argument involving the just constructed  Gau{\\ss} norm to extend $|\\cdot|$ from $\\fldK$ to $\\R$.\n    The thus obtained extension of the $p$-adic absolute value to $\\R$ is not unique. In its construction, the\n    axiom of choice is used, so one can not even give an explicit formula for such an extension. \n  \\end{environmentlist}\n\\end{remarks}\n", "meta": {"hexsha": "91b52d74a1719316e7edbe064d738dad08a8a62d", "size": 18155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/topological-division-rings-fields.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/topological-division-rings-fields.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/topological-division-rings-fields.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": 54.3562874251, "max_line_length": 147, "alphanum_fraction": 0.6345910218, "num_tokens": 6443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6329713071412333}}
{"text": "\\documentclass[answers]{exam}\n\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{amsmath}\n\\usepackage{subcaption}\n\\usepackage{framed}\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{algorithmicx}\n\\usepackage{algpseudocode}\n\\usepackage{mathtools}\n\\usepackage{tikz}\n\\newcommand\\numberthis{\\addtocounter{equation}{1}\\tag{\\theequation}}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{claim}{Claim}\n\\usepackage{etoolbox}\n\\AtBeginEnvironment{solution}{\\setcounter{claim}{0}}\n\n\\usetikzlibrary{fit}\n\\usetikzlibrary{arrows}\n\\newcommand\\addvmargin[1]{\n  \\node[fit=(current bounding box),inner ysep=#1,inner xsep=0]{};\n}\n\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\n\\newcommand{\\nl}{\\vspace{0.2cm}\\\\}\n\\newcommand{\\nln}{\\vspace{0.2cm}}\n\n% First we setup the header and footer\n\\pagestyle{headandfoot}\n\\runningheadrule\n\\runningfootrule\n\\header{COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I-2020-21)}{}{Homework-5}\n\\footer{}{\\thepage  \\, of \\numpages}{}\n \n% We want the points for each question displayed on the left\n%\\pointname{points}\n%\\pointsinmargin\n \n% Automatically total the points - make sure to compile TWICE\n\\addpoints\n \n\\begin{document}\n\n\n\\begin{center} \n\\fbox{\\parbox{5.5in}{\n\\vspace{-0.1in}\n\\begin{itemize}\n\\item \\small{The instructions are the same as in Homework-0, 1, 2.}\n\\end{itemize}\n\\vspace{-0.1in}\n}}\n\\end{center}\n\n\\vspace{0.1in}\n\n\n\\vspace{0.1in}\n% Some general text together with number of questions and total points possible\nThere are \\numquestions\\, questions for a total of \\numpoints\\, points.\n\\vspace{0.1in}\n\\hrule\n \\vspace{0.2in}\n\\begin{questions}\n \n% First question, worth 3 points\n\\question[20] Consider the network shown in the figure. Consider running the Ford-Fulkerson algorithm on this network. \n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.25]{embed/network-1}\n\\end{figure}\n\n\\begin{parts}\n\\part We start with a zero $s$-$t$ flow $f$. The algorithm then finds an augmenting path in $G_f$. Suppose the augmenting path is $s \\rightarrow b \\rightarrow c \\rightarrow t$. Give the flow $f'$ after augmenting flow along this path.\n\\begin{solution}\n\nA flow is a function from edges to non-negative real numbers, so it suffices to give the flow value for each edge.\n\n$f'((s,b))=5,$ $f'((s,a))=0,$ $f'((b,a))=0,$ $f'((a,d))=0,$ $f'((d,b))=0,$ $f'((b,c))=5,$ $f'((c,d))=0,$ $f'((c,t))=5,$ $f'((d,t))=0$\n\\end{solution}\n\n\\part Show the graph $G_{f'}$. That is, the residual graph with respect to $s$-$t$ flow $f'$.\n\\begin{solution}\n\nIn all the following parts, back edges that are not drawn should be treated to have zero weight. This has been done for the sake of a clear diagram (and as clarified on Piazza, it is valid too).\n\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[scale=0.085]{1_a.jpg}\n%\\end{figure}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (2, 2) {$a$};\n\\node[vertex](b) at (2, -2) {$b$};\n\\node[vertex](c) at (5, -2) {$c$};\n\\node[vertex](d) at (5, 2) {$d$};\n\\node[vertex](t) at (7, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway, below right] {$16$};\n\\draw[->] (s) -- (b) node[midway, above right] {$8$};\n\\draw[->] (b) -- (a) node[midway, left] {$4$};\n\\draw[->] (a) -- (d) node[midway, below] {$12$};\n\\draw[->] (d) -- (b) node[midway, left] {$8$};\n\\draw[->] (b) -- (c) node[midway, above] {$7$};\n\\draw[->] (c) -- (d) node[midway, left] {$8$};\n\\draw[->] (c) -- (t) node[midway, above left] {$0$};\n\\draw[->] (d) -- (t) node[midway, below left] {$18$};\n\\draw[->, dotted] (b) to [bend left] node[midway, below] {$5$} (s);\n\\draw[->, dotted] (c) to [bend left] node[midway, below] {$5$} (b);\n\\draw[->, dotted] (t) to [bend left] node[midway, below] {$5$} (c);\n\\end{tikzpicture}\n\\end{center}\n\n\\end{solution}\n\n\\part The algorithm then sets $f$ as $f'$ and $G_f$ as $G_{f'}$ and repeats. Suppose the augmenting path chosen in the next iteration of the while loop is $s \\rightarrow a \\rightarrow d \\rightarrow t$. Give $f'$ after augmenting flow along this path and show $G_{f'}$.\n\\begin{solution}\n$f'((s,b))=5,$ $f'((s,a))=12,$ $f'((b,a))=0,$ $f'((a,d))=12,$ $f'((d,b))=0,$ $f'((b,c))=5,$ $f'((c,d))=0,$ $f'((c,t))=5,$ $f'((d,t))=12$\n\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[scale=0.085]{1_b.jpg}\n%\\end{figure}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (2, 2) {$a$};\n\\node[vertex](b) at (2, -2) {$b$};\n\\node[vertex](c) at (5, -2) {$c$};\n\\node[vertex](d) at (5, 2) {$d$};\n\\node[vertex](t) at (7, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway, below right] {$4$};\n\\draw[->] (s) -- (b) node[midway, above right] {$8$};\n\\draw[->] (b) -- (a) node[midway, left] {$4$};\n\\draw[->] (a) -- (d) node[midway, below] {$0$};\n\\draw[->] (d) -- (b) node[midway, left] {$8$};\n\\draw[->] (b) -- (c) node[midway, above] {$7$};\n\\draw[->] (c) -- (d) node[midway, left] {$8$};\n\\draw[->] (c) -- (t) node[midway, above left] {$0$};\n\\draw[->] (d) -- (t) node[midway, below left] {$6$};\n\\draw[->, dotted] (b) to [bend left] node[midway, below] {$5$} (s);\n\\draw[->, dotted] (c) to [bend left] node[midway, below] {$5$} (b);\n\\draw[->, dotted] (t) to [bend left] node[midway, below] {$5$} (c);\n\\draw[->, dotted] (a) to [bend right] node[midway, above] {$12$} (s);\n\\draw[->, dotted] (d) to [bend right] node[midway, above] {$12$} (a);\n\\draw[->, dotted] (t) to [bend right] node[midway, above] {$12$} (d);\n\\end{tikzpicture}\n\\end{center}\n\n\n\\end{solution}\n\n\\part Let $f$ be the flow when the algorithm terminates. Give the flow $f$ and draw the residual graph $G_f$.\n\\begin{solution}\n\nThe residual graph has two augmenting paths: $s \\to b \\to d \\to t$ and $s \\to b \\to c \\to d \\to t$, and after taking either of these two, the algorithm terminates. We suppose that the second augmenting path is chosen.\n\n$f((s,b))=11,$ $f((s,a))=12,$ $f((b,a))=0,$ $f((a,d))=12,$ $f((d,b))=0,$ $f((b,c))=11,$ $f((c,d))=6,$ $f'((c,t))=5,$ $f((d,t))=18$\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[scale=0.085]{1_c.jpg}\n%\\end{figure}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (2, 2) {$a$};\n\\node[vertex](b) at (2, -2) {$b$};\n\\node[vertex](c) at (5, -2) {$c$};\n\\node[vertex](d) at (5, 2) {$d$};\n\\node[vertex](t) at (7, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway, below right] {$4$};\n\\draw[->] (s) -- (b) node[midway, above right] {$2$};\n\\draw[->] (b) -- (a) node[midway, left] {$4$};\n\\draw[->] (a) -- (d) node[midway, below] {$0$};\n\\draw[->] (d) -- (b) node[midway, left] {$8$};\n\\draw[->] (b) -- (c) node[midway, above] {$1$};\n\\draw[->] (c) -- (d) node[midway, left] {$2$};\n\\draw[->] (c) -- (t) node[midway, below right] {$0$};\n\\draw[->] (d) -- (t) node[midway, above right] {$0$};\n\\draw[->, dotted] (b) to [bend left] node[midway, below] {$11$} (s);\n\\draw[->, dotted] (c) to [bend left] node[midway, below] {$11$} (b);\n\\draw[->, dotted] (t) to [bend left, out=60, in=120] node[midway, below] {$5$} (c);\n\\draw[->, dotted] (a) to [bend right] node[midway, above] {$12$} (s);\n\\draw[->, dotted] (d) to [bend right] node[midway, above] {$12$} (a);\n\\draw[->, dotted] (t) to [bend right, out=-60, in=-120] node[midway, above] {$18$} (d);\n\\draw[->, dotted] (d) to [bend left] node[midway, right] {$6$} (c);\n\\end{tikzpicture}\n\\end{center}\n\n\\end{solution}\n\n\\part Give the value of the flow $f$ when the algorithm terminates. Let $A^*$ be the vertices reachable (using edges of positive weight) from $s$ in $G_f$ and let $B^*$ be the remaining vertices. Give $A^*$ and $B^*$. Give the capacity of the cut $(A^*, B^*)$.\n\\begin{solution}\n$v(f)=23$\n\\newline $A^*=\\{s,a,b,c,d\\}$\n\\newline $B^*=\\{t\\}$\n\\newline $C(A^*,B^*)=\\sum_{e\\text{ out of }A^{*}} c(e)=18+5=23$\n\\end{solution}\n\\end{parts}\n\n\n\n\n\n\n\\newpage\n\n\n\n\n\n\n\n\n\n\n\n\\question Answer the following:\n\n\\begin{parts}\n\\part[1] \\underline{State true or false}: For every $s$-$t$ network graph $G$, there is a unique $s$-$t$ cut with minimum capacity.\n \n\\begin{solution}\nFalse\n\\end{solution}\n\n\\part[4] Give reason for your answer to part (a).\n\n\\begin{solution}\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[height=5cm,width=10cm]{2_a.jpg}\n%\\end{figure}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (1.5, 0) {$a$};\n\\node[vertex](t) at (3, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway,above] {$10$};\n\\draw[->] (a) -- (t) node[midway,above] {$10$};\n\\end{tikzpicture}\n\\end{center}\n\nIn the above figure if we consider sets\n\\newline $A= \\{s\\}$\n\\newline $B= \\{a,t\\}$\n\\newline $A'= \\{s,a\\}$\n\\newline $B'= \\{t\\}$\n\\newline There are two cuts possible for the given flow: $(A,B)$ and $(A',B')$. We can see that both have capacity 10. So the minimum capacity for any cut in the network graph is 10, and there are two possible cuts with that capacity. Therefore the given statement is false.\n\\end{solution}\n\\part[1] \\underline{State true or false}: For every $s$-$t$ network graph $G$ and any edge $e$ in the graph $G$, increasing the capacity of $e$ increases the value of maximum flow.\n\n\\begin{solution}\nFalse\n\\end{solution}\n\n\\part[4] Give reason for your answer to part (c).\n\\begin{solution}\nTo prove that the statement is false, it is sufficient to provide a counterexample.\n \nConsider the two graphs below. In the second one, the capacity of the edge $a\\to t$ is changed from 10 to 20.\n\\newline For the first graph the maximum flow will be 10.\n\\newline For the second graph the maximum flow will also be 10.\n\\newline So despite increasing the capacity of an edge, the maximum flow remains the same, and hence this is a valid counterexample.\n\n\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[height=5cm,width=10cm]{2_a.jpg}\n%\\end{figure}\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[height=5cm,width=10cm]{2_b.jpg}\n%\\end{figure}\n\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (1.5, 0) {$a$};\n\\node[vertex](t) at (3, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway,above] {$10$};\n\\draw[->] (a) -- (t) node[midway,above] {$10$};\n\\end{tikzpicture}\n\\end{center}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}\n\\tikzset{edge/.style = {->,> = latex'}}\n\\node[vertex](s) at (0, 0) {$s$};\n\\node[vertex](a) at (1.5, 0) {$a$};\n\\node[vertex](t) at (3, 0) {$t$};\n\\draw[->] (s) -- (a) node[midway,above] {$10$};\n\\draw[->] (a) -- (t) node[midway,above] {$20$};\n\\end{tikzpicture}\n\\end{center}\n\n\n\\end{solution}\n\n\\part[1] \\underline{State true or false}: For every $s$-$t$ network graph $G$ for which an $s$-$t$ flow with non-zero value exists, there exists an edge $e$ in the graph such that decreasing the capacity of $e$ decreases the value of maximum flow.\n\n\\begin{solution}\nTrue\n\\end{solution}\n\n\\part[4] Give reason for your answer to part (e).\n\n\\begin{solution}\nLet $A^*$ be the set of vertices reachable from $s$ in the residual graph $G_f$ corresponding to the maximum flow, and let $B^*$ be the set of the remaining vertices. Then $(A^*, B^*)$ is an $s-t$ cut.\n\nNote that there must be at least one edge from $A^*$ to $B^*$ since otherwise, there would be no edge from $A^*$ to $B^*$ implying that the capacity of this cut is 0, which means that the maximum flow is 0, which is false by the problem condition.\n\nNote that the capacity of this cut equals the minimum flow as done in class, say $c$. %(TODO: IS THIS OKAY TO WRITE?)\n\nConsider any edge $e = (x, y)$ from $A^*$ to $B^*$. Reducing the capacity of this edge reduces the capacity of this cut to some $v < c$. The maximum flow value of the new graph equals the minimum cut capacity of the new graph by max-flow min-cut theorem, which can be at most $v$ since we have exhibited a cut of capacity $v$. Thus the maximum flow value of the new graph is at most $v < c$, so upon reducing the capacity of this edge, the value of the maximum flow in the graph decreases.\n\\end{solution}\n\n\\end{parts}\n\n\\newpage\n\n\n\\question Suppose you are given a bipartite graph $(L, R, E)$, where $L$ denotes the vertices on the left, $R$ denotes the vertices on the right and $E$ denote the set of edges. Furthermore it is given that degree of every vertex is exactly $d$ (you may assume that $d > 0$). \nWe will construct a flow network $G$ using this bipartite graph in the following manner: $G$ has $|L| + |R| + 2$ vertices. There is a vertex corresponding to every vertex in $L$ and $R$. There is also a source vertex $s$ and a sink vertex $t$. There are directed edges with weight $1$ from $s$ to all vertices in $L$ and directed edges of weight $1$ from all vertices in $R$ to $t$. For each edge $(u, v) \\in E$, there is a directed edge from $u$ to $v$ with weight $1$ in $G$.\n\n({\\it The figure below shows an example of a bipartite graph and the construction of the network.})\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.25]{embed/nf-3}\n\\caption{An example bipartite graph (with $d = 2$) and network construction.}\n\\end{figure}\n\n\\begin{parts}\n\\part[5] Argue that for any such bipartite graph where the degree of every vertex is equal to $d$, $|L|$ is equal to $|R|$.\n\n\\begin{solution}\nWe count the number of edges in two ways.\n\nEach edge of the graph has one endpoint in $L$ and the other endpoint in $R$.\n\nHence, the total number of edges equals the total number of edges with exactly one endpoint in $L$, and that is precisely the sum of degrees of all vertices in the $L$ (since there is no edge between vertices in $L$), which is $d|L|$.\n\nMore formally, we have:\n\n\\begin{align*}\n    \\sum_{\\{u, v\\} \\in E} 1 \n    &= \\sum_{(u, v) \\in E \\land u \\in L \\land v \\in R} 1\\\\\n    &= \\sum_{u \\in L} \\sum_{(u, v) \\in E \\land v \\in R} 1\\\\\n    &= \\sum_{u \\in L} deg(u)\\\\\n    &= \\sum_{u \\in L} d\\\\\n    &= d|L|\n\\end{align*}\n\nBy a completely analogous argument, we have\n\n\\begin{align*}\n    \\sum_{\\{u, v\\} \\in E} 1 \n    &= \\sum_{(u, v) \\in E \\land u \\in L \\land v \\in R} 1\\\\\n    &= \\sum_{v \\in R} \\sum_{(u, v) \\in E \\land u \\in L} 1\\\\\n    &= \\sum_{v \\in R} deg(v)\\\\\n    &= \\sum_{v \\in R} d\\\\\n    &= d|R|\n\\end{align*}\n\nHence, we have $d|L| = d|R|$, so since $d > 0$, we have $|L| = |R|$.\n\n\\end{solution}\n\n\\part[10] Argue that for any given bipartite graph where the degree of every vertex is the same non-zero value $d$, there is an integer $s$-$t$ flow (i,e., flow along any edge is an integer) in the corresponding network with value $|L|$.\n\n\\begin{solution}\nConsider any $s-t$ cut $(A, B)$. We claim that the capacity of this cut is at least $|L|$, and then exhibit a cut of capacity precisely $|L|$, to establish that the minimum capacity of a cut in the corresponding network is $|L|$, which by the max-flow-min-cut theorem equals the maximum value of a flow in the corresponding network.\\nl\nLet $\\ell = |L| = |R|$.\\nl\nNote that since $(A, B)$ is an $s-t$ cut, we have $s \\in A, t \\in B$.\\nl\nSuppose $A$ has $n$ vertices from $L$ and $m$ vertices from $R$. Then $B$ has $\\ell - n$ vertices from $L$ and $\\ell - m$ vertices from $R$.\\nl\nDefine $X_{IJ}$ to be the number of edges going from $L \\cap I$ to $R \\cap J$.\\nl\nThen we have $C(A, B)$ to be the number of edges from $s$ to $L \\cap B$ + the number of edges from $R \\cap A$ to $t$ + the number of edges going from $L \\cap A$ to $R \\cap B$.\\nl\nHence we have $$C(A, B) = \\ell - n + m + X_{AB}$$\nIf $n \\le m$, then we are done, since then $$C(A, B) = \\ell + (m - n) + X_{AB} \\ge \\ell + 0 + 0 = \\ell$$\nNow suppose $n > m$. We claim that $X_{AB} \\ge n - m$.\\nl\nThe total number of edges going from $A \\cap L$ to $R$ is $X_{AA} + X_{AB}$, and it is equal to the sum of degrees of vertices in $A \\cap L$, which is $dn$.\\nl\nSimilarly, the total number of edges going from $L$ to $A \\cap R$ is $X_{AA} + X_{BA}$, and it is equal to the sum of degrees of vertices in $A \\cap R$, which is $dm$.\nHence we have \n\\begin{align*}\nX_{AB} &= X_{BA} + \\left(X_{AA} + X_{AB}\\right) - \\left(X_{AA} + X_{BA}\\right)\\\\\n       &= X_{BA} + dn - dm\\\\\n       &= X_{BA} + d(n - m)\\\\\n       &\\ge 0 + n - m\\\\\n       &= n - m\n\\end{align*}\nas needed, where the inequality comes in since $d \\ge 1$ and $n > m$.\nHence in this case too, we have $C(A, B) \\ge \\ell$.\\nl\nThus we have shown that $C(A, B) \\ge \\ell$ for any $s-t$ cut.\n\nNow consider the cut where $A = \\{s\\}$, and $B$ is the set of the remaining vertices. Note that here the capacity of the cut is the sum of 1 over all edges outgoing from $s$, which is $\\ell$.\n\nHence for a particular cut, we have shown that $C(A, B) = \\ell$, which when combined with the previous bound shows that the minimum capacity of a cut in the network is $\\ell$, and by the max-flow-min-cut theorem, this is equal to the maximum flow of the network.\n\nSince the maximum flow of the network has value $|L|$, there exists a flow with value $|L|$, and since this flow is a maximum flow on a network with integer capacities, it can be computed using the Ford-Fulkerson algorithm, which always guarantees that the flow it returns is an integer flow. Hence there exists an integer $s-t$ flow in the corresponding network with value $|L|$, as desired.\n\\end{solution}\n\n\\part[5] A matching in a bipartite graph $G = (L, R, E)$ is a subset of edges $S \\subseteq E$ such that for every vertex $v \\in L \\cup R$, $v$ is present as an endpoint of at most one edge in $S$. A maximum matching is a matching of maximum cardinality. Show that the size of the maximum matching in any bipartite graph $G = (L, R, E)$ is the same as the maximum flow value in the corresponding network graph defined as above.\n\n\\begin{solution}\nWe shall \n\\begin{enumerate}\n    \\item Construct a valid flow $f$ of size $|f|$ from any valid matching of size $|f|$.\n    \\item Construct a valid matching of size $|f|$ from any valid flow $f$.\n\\end{enumerate}\n\n\\paragraph{Construction of flow from a maximum matching}\nSuppose $S$ is the set of all edges in the matching. By the bipartite-ness of the graph, each edge has exactly one endpoint in $L$ and the other one in $R$. Hence, for each edge $(u, v)$, where $u \\in L, v \\in R$, set $f((s, u)) = f((u, v)) = f((v, t)) = 1$ in the network. In the end, set $f$ of all the remaining edges in the network to $0$.\\nl\nWe need to show that this is a valid flow, and that the value of this flow is $|S|$.\\nl\nFor showing that it is a valid flow, we need to show flow conservation and the satisfaction of capacity constraints.\n\\begin{enumerate}\n    \\item Flow conservation: Consider any vertex $u \\in L$. If $f((s, u)) = 1$, then there must have been an edge in $S$ with $u$ as an endpoint (and exactly one such edge by the definition of a matching). Hence, $\\sum_{e \\text{ into } u}f(e) = 1$ and $\\sum_{e \\text{ out of } u}f(e) = 1$. For a vertex $u$ which has $f((s, u)) = 0$, it is not an endpoint of any edge in $S$, so $\\sum_{e \\text{ into } u}f(e) = 0$ and $\\sum_{e \\text{ out of } u}f(e) = 0$. Now consider any vertex $v \\in R$. If $f((v, t)) = 1$, then there must have been an edge in $S$ with $v$ as an endpoint (and exactly one such edge by the definition of a matching). Hence, $\\sum_{e \\text{ into } v}f(e) = 1$ and $\\sum_{e \\text{ out of } v}f(e) = 1$. For a vertex $v$ which has $f((v, t)) = 0$, it is not an endpoint of any edge in $S$, so $\\sum_{e \\text{ into } v}f(e) = 0$ and $\\sum_{e \\text{ out of } v}f(e) = 0$. Hence for all internal vertices, flow conservation holds.\n    \\item Capacity constraints: Since we assign either $0$ or $1$ to any edge, and the capacity of an edge is $1$, the capacity constraints hold trivially.\n\\end{enumerate}\nNow to show that the value of this flow is $|S|$, note that any edge in $S$ has exactly one endpoint in $L$, and no two edges in $S$ share an endpoint. Hence, the number of vertices with $f((s, u)) = 1$ is precisely the number of edges in $S$, which is $|S|$. However, the value of the flow is the sum of $f-$values assigned to edges emanating from $s$, which is equal to the number of edges emanating from $s$ which we assigned 1 to, and that equals $|S|$.\\nl\nHence, this is a valid flow, and the capacity of the flow is $|S|$ and we are done.\n\\paragraph{Construction of matching from a maximum flow}\nNote that in a flow network with integer capacities, the maximum value of a flow is an integer, and there exists a flow with the maximum value, such that all $f-$values of edges are integers (which can be found using the Ford-Fulkerson algorithm).\\nl\nConsider such a flow $f$, and the set of edges between internal nodes having $f-$values positive (and by combining the the discussion above and capacity constraints, the $f-$values must be $1$).\\nl\nMore formally, let $S$ be the set of edges $(u, v)$ such that $f((u, v)) > 0$, and $\\{s, t\\} \\cap \\{u, v\\} = \\emptyset$. Then $f((u, v))$ is an integer and upper bounded by $1$, so it is $1$ for all such vertices. Note that we need to make each edge undirected before including it in $S$.\\nl\nWe claim that $S$ is a matching with size equal to the value of the flow.\n\\begin{enumerate}\n    \\item $S$ is a matching: Note that $S$ has edges incident only on vertices which are in $G$. Hence, $S$ is a subset of $E$ by the construction of the network. Now suppose there exists a vertex $v \\in L \\cup R$ which is incident to at least 2 edges in $S$. We make two cases:\n    \\begin{enumerate}\n        \\item $v \\in L$: In that case, we have at least two edges emanating from $v$ which have $f(e) = 1$. Hence by flow conservation, the sum of weights of all edges into $v$ must be at least $2$, which is a contradiction, since the only edge coming into $v$ is $(s, v)$, and it has capacity $1$.\n        \\item $v \\in R$: In that case, we have at least two edges coming into $v$ which have $f(e) = 1$. Hence by flow conservation, the sum of weights of all edges emanating from $v$ must be at least $2$, which is a contradiction, since the only edge emanating from $v$ is $(v, t)$, and it has capacity $1$.\n    \\end{enumerate}\n    Hence we have shown that $S$ is a matching.\n    \\item $|S| = v(f)$: Firstly note that since $G$ is bipartite, all edges in $S$ have exactly one endpoint each in $L$ and $R$. Consider the set $T$ of all vertices in $L$ that are incident to an edge in $S$. Then, since each edge in $S$ has an $f-$value of 1, and no two edges share a common endpoint (which implies at most 1 edge from $S$ is incident on a given vertex in $L$), $\\sum_{e \\text{ out of }u} f(e) = 1$ for each $u$ in $T$. By flow conservation, for each vertex $v$ in $T$, we have $f((s, v)) = 1$. For the remaining vertices, using the same argument, we have $f((s, v)) = 0$. Summing this over all vertices in $L$, we have $v(f) = |T|$. Now since no two edges in $S$ share an endpoint, we have $|S| = |T|$, and hence we have $|S| = v(f)$, as required.\n\\end{enumerate}\n\nFrom here, we can see that we have constructed a flow $f$ with $v(f)$ being equal to the cardinality of the maximum matching, and also that we have constructed a matching with the cardinality being equal to the maximum value of any flow $f$.\\nl\nHence, the maximum value of a flow equals the cardinality of a certain valid matching, which is at most the cardinality of a maximum matching.\\nl\nAlso, the cardinality of a maximum matching equals the value of a certain valid flow, which is at most the maximum value of a flow.\\nl\nCombining these inequalities, we can see that equality holds, and thus the cardinality of a maximum matching in the graph equals the maximum value of any flow in the corresponding network, as required.\n\\end{solution}\n\n\\end{parts}\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\n\n\n\n\n\n\n\\question[20] There are $n$ stationary mobile-phones $c_1, ..., c_n$ and $n$ stationary mobile-phone towers $t_1, ..., t_n$. \nThe distances between mobile-phones and towers are given to you in an $n \\times n$ matrix $d$, where $d[i, j]$ denotes the distance between phone $c_i$ and tower $t_j$.\nIt is possible for a mobile-phone $c_i$ to connect to a tower $t_j$ if and only if the distance between $c_i$ and $t_j$ is at most $D$, where $D$ is the connecting radius. \nFurthermore, at one time, a mobile-phone can connect to at most one tower and a tower can allow at most one connection. \nYour goal as a Communications Engineer is to figure out whether all mobile-phones are usable simultaneously. \nThat is, whether it is possible for all mobile-phones to connect simultaneously to distinct towers. Answer the following questions.\n\n\\begin{parts}\n\\part Consider a simple example with 5 mobile-phones and 5 towers. Let the connecting radius be $D = 2$ miles. The distance matrix for this example is as given in Figure~\\ref{fig:1}.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.2]{embed/nf-2}\n\\caption{Distance matrix $d$ for part (a) of question 4.}\n\\label{fig:1}\n\\end{figure}\n\n\\underline{Prove or disprove}: It is possible for all 5 mobile-phones to simultaneously connect to distinct towers for this example.\n\\begin{solution}\nYes, it is possible. Here is a matching from cell-phones to towers that demonstrates how connections can be obtained.\n\\begin{align*}\n1 &\\rightarrow 2 & d[1,2]=2\\\\\n2 &\\rightarrow 3 & d[2,3]=1\\\\\n3 &\\rightarrow 4 & d[3,4]=1\\\\\n4 &\\rightarrow 5 & d[4,5]=1\\\\\n5 &\\rightarrow 1 & d[5,1]=1\\\\\n\\end{align*}\n\\end{solution}\n\n\n\\vspace{0.1in}\n\n\\part Design an algorithm that takes inputs $n$, $D$, and the distance matrix $d$, and outputs ``yes\" if it is possible for all mobile-phones to simultaneously connect to distinct towers (within the connecting radius $D$) and ``no\" otherwise. \nAnalyze the running time of the algorithm and give proof of correctness.\n\\end{parts}\n\n\\begin{solution}\nWe will show how the given problem may be reduced to the problem of determining if there exists perfect matching in a bipartite graph. This reduction will allow us to solve the given problem using any of the algorithms for the perfect matching. \n\n\\paragraph{Proof of Correctness}\nConsider the bipartite graph $G$ with 2 partitions $X$ and $Y$ of size $n$ each. There is an edge between $X[i]$ and $Y[j]$ \\emph{iff} $d[i, j] \\leq D$.\nAn illustration of a possible graph $G$ is as shown below.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.3\\textwidth]{embed/Bipartite1.pdf}\n\\end{figure}\n\n\\begin{claim}\nAll mobile phones will be usable simultaneously \\emph{iff} there exists a perfect matching, i.e. matching of size $n$, in the bipartite graph $G$ as constructed above.\n\\end{claim}\n\\begin{proof}\nWe will prove this claim by proving the implication from both the sides, as follows:\n\\begin{claim}\nSuppose that it is possible to obtain a pairing $P$ of mobile phones to the towers such that all mobile phones are usable. Then, the matching $M = \\{(X[i], Y[j]) \\mid (i, j) \\in P\\}$ is a valid matching of size $n$ in $G$.\n\\end{claim}\n\\begin{proof}\nFirst we will show that $M \\subseteq E(G)$. For this, note that if $(X[i], Y[j]) \\in M$ then $(i, j) \\in P$. And since $P$ is a valid pairing by assumption, we have that $d[i,j] \\leq D$. Therefore $(X[i], Y[j]) \\in E(G)$ by construction of $G$. Hence, $M \\subseteq E(G)$. \n\nNote that $P$ has size $n$ by definition, since each phone is used. Now since $|M| = |P|$, we have $|M| = n$. We now only need to show that $M$ is a valid matching.\n%Note that $M$ has size $n$ by definition, as $|M| = |P|$, and any valid pairing in which all mobile phones are usable must pair each mobile phone with a tower, so $|P|=n$. \n\nNow, suppose $M$ is not a valid matching. Then, there must be a vertex $v \\in G$ such that it has more than one incident edge in $M$. Now, $v \\in X$ or $v \\in Y$. If $v = X[i]$ for some $i$ then it means that mobile phone $i$ is connected to more than one tower. Similarly if $v = Y[j]$ for some $j$, then it means that tower $j$ is allowing more than one connection at a time. Both of these cases violate the problem constraints and contradict the fact that $P$ is a valid pairing. Hence we must have that no such $v \\in G$ can exist. Therefore, $M$ is a valid matching.\n\\end{proof}\n\\begin{claim}\nNow, suppose there exists a matching $M$ of size $n$ in $G$. Then, pairing $P = \\{(i, j) \\mid (X[i], Y[j]) \\in M\\}$ of mobile phones to towers is a valid pairing such that all mobile phones are usable.\n\\end{claim}\n\\begin{proof}\nNote that by definition $|P| = |M| = n$. So $P$ pairs each mobile phone to a tower. To show that $P$ is a valid pairing we need to show that if mobile phone $i$ is paired with tower $j$ then $d[i,j] \\leq D$, and, each mobile phone is paired with atmost one tower and vice versa.\n\nBy definition of $P$, $(i,j) \\in P$ iff $(X[i], Y[j]) \\in M$. Also, by construction of $G$ if there is an edge between $X[i]$ and $Y[j]$ it implies that $d[i,j] \\leq D$.\n\nNow, if possible, let $i$ be a mobile phone that is paired with more than one tower, say $j_1, j_2$ in $P$. Then we have that $(X[i], Y[j_1]), (X[i], Y[j_2]) \\in M$. But this is a contradiction because by definition a matching includes only vertex disjoint edges. \\textit{Mutatis mutandis}, we can argue that all towers $j$ in $P$ will be paired with exactly one mobile phone.\n\\end{proof}\nHence we have proved our original claim.\n\\end{proof}\nUsing the above claim we have reduced the given problem into the problem of existence of perfect-matching in a bipartite graph $G$. So, to obtain the answer to original problem we will construct the graph $G$ as defined and then calculate the size of maximum matching in $G$. The answer will be ``yes'' \\emph{iff} the size of maximum matching is $n$. The algorithm for calculating size of max-matching in a bipartite graph $G$ has already been discussed in the class using the application of network flows. So in the algorithm presented below we will assume the existence of subroutine \\textsc{MaxMatching} which takes a bipartite graph $G$ and returns size of maximum matching.\n\n\\paragraph{Pseudocode}\n\\begin{algorithmic}[1]\n\\Function{ConnectionPossible}{$n$, $D$, $d$}\n    \\State let $X \\gets $ set of $n$ nodes.\n    \\State let $Y \\gets $ set of $n$ nodes.\n    \\State let $G \\gets (X \\cup Y, \\emptyset)$\n    \\For {$i \\in [1 \\ldots n]$}\n        \\For {$j \\in [1 \\ldots n]$}\n            \\If{$d[i,j] \\leq D$}\n                \\State add edge $(X[i], Y[j])$ to $G$\n            \\EndIf\n        \\EndFor\n    \\EndFor\n    \\If {\\Call{MaxMatching}{$G$} $= n$}\n        \\State \\Return ``yes''\n    \\Else\n        \\State \\Return ``no''\n    \\EndIf\n\\EndFunction\n\\end{algorithmic}\n\n\\paragraph{Running Time Analysis}\nFirst initialization of $G$ with no edges and $2n$ nodes will take $O(n)$ time in adjacency list representation. Then, we have a nested loop with $O(n^2)$ iterations and in each iteration we potentially add an edge to $G$. In the adjacency list representation adding an edge is equivalent to appending to the end of a linked list (or two). Therefore it will only take $O(1)$ time per iteration. So $G$ will be a graph with $2n$ vertices and at most $n^2$ edges in the worst case. \\textsc{MaxMatching} algorithm routine is as discussed in the class, internally it will transform $G$ to a directed graph with $2n+2$ vertices (source and sink included) and $n^2 + 2n$ edges in the worst case. Then it will apply the ford-fulkerson algorithm to obtain the max flow in this transformed graph which will therefore take $O(n \\cdot (n + n^2)) = O(n^3)$ time (since the max flow is upper bounded by $n$, and the number of vertices + edges is in $O(n + n^2)$). So overall worst case time complexity of the algorithm is $O(n^3)$.\n\\end{solution}\n\n\\newpage\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\question[25] Town authorities of a certain town are planning for an impending virus outbreak. They want to plan for panic buying and taking cues from some other towns, they know that one of the items that the town may run out of is toilet paper. They have asked your help to figure out whether the toilet paper demand of all $n$ residents can be met. They provide you with the following information:\n\\begin{itemize}\n\\item There are $n$ residents $r_1, ..., r_n$, $m$ stores $s_1, ..., s_m$, and $p$ toilet paper suppliers $x_1, ..., x_p$.\n\\item The demand of each of the residents in terms of the number of rolls required.\n\\item The list of stores that each of the residents can visit and purchase rolls from. \nA store cannot put any restriction on the number of rolls a customer can purchase given that those many rolls are available at the store.\n\\item The number of rolls that supplier $x_j$ can supply to store $s_i$ for all $i \\in \\{1, ..., m\\}$ and $j \\in \\{1, ..., p\\}$.\n\\end{itemize}\nThe above information is provided in the following data structures:\n\\begin{itemize}\n\\item A 1-dimensional integer array $D[1...n]$ of size $n$, where $D[i]$ is the demand of resident $r_i$.\n\\item A 2-dimensional 0/1 array $V[1...n, 1...m]$ of size $n \\times m$, where $V[i, j] = 1$ if resident $r_i$ can visit store $s_j$ and $V[i, j] = 0$ otherwise.\n\\item A 2-dimensional integer array $W[1...m, 1...p]$ of size $m \\times p$, where $W[i, j]$ is the number of rolls of toilet paper that the supplier $x_j$ can supply to store $s_i$.\n\\end{itemize}\n\nDesign an algorithm to determine if the demand of all residents can be met.\nThat is, given $(n, m, p, D, V, W)$ as input, your algorithm should output ``yes'' if it is possible for all residents to obtain the required number of rolls and ``no'' otherwise. \nArgue correctness and discuss running time.\n\n\\vspace{0.1in}\n\n({\\it For example, consider that the town has two residents, one store and two suppliers. If $D = [2, 2], V = \\begin{bsmallmatrix}1 \\\\ 1\\end{bsmallmatrix}$, and $W = [2, 2]$, then the demand can be met. However, if  $D = [2, 2], V = \\begin{bsmallmatrix}1 \\\\ 1\\end{bsmallmatrix}$, and $W = [2, 1]$, then the demand cannot be met.})\n\n\\begin{solution}\n\n\\paragraph{Pseudocode}\n\\begin{algorithmic}[1]\n\\Function{IsRequirementMet}{$n, m, p, D, V, W$}\n    \\State Create source and sink vertices $s, t$\n    \\State Create vertices $S[1 \\ldots p]$ corresponding to the suppliers\n    \\State Create vertices $T[1 \\ldots m]$ corresponding to the stores\n    \\State Create vertices $R[1 \\ldots n]$ corresponding to the residents\n    \\State Let $G$ be a graph with all the above vertices\n    \\For{$i \\in [1 \\ldots p]$}\n        \\State Add an edge $(s, S[i])$ with capacity $\\sum_{j = 1}^m W[j, i]$ to $G$\n        \\For{$j \\in [1 \\ldots m]$}\n            \\State Add an edge $(S[i], T[j])$ with capacity $W[j, i]$ to $G$\n        \\EndFor\n    \\EndFor\n    \\For{$i \\in [1 \\ldots n]$}\n        \\State Add an edge $(R[i], t)$ with capacity $D[i]$ to $G$\n        \\For{$j \\in [1 \\ldots m]$}\n            \\If{$V[i, j] = 1$}\n                \\State Add an edge $(T[j], R[i])$ with capacity $D[i]$ to $G$\n            \\EndIf\n        \\EndFor\n    \\EndFor\n    \\If{\\textsc{Value}(\\Call{MaxFlow}{$G, s, t$}) $= \\sum_{i = 1}^m D[i]$}\n        \\State \\Return ``yes\"\n    \\Else\n        \\State \\Return ``no\"\n    \\EndIf\n\\EndFunction\n\\end{algorithmic}\n\n\\paragraph{Proof of Correctness}\n\nBy a flow, we shall always refer to an integer flow. The max-flow returned by the function MaxFlow is always an integer flow for a flow problem with integer capacities (if we use an algorithm like the Ford-Fulkerson algorithm).\n\nBy an \\textit{assignment}, we denote a tuple $(A', B')$ of arrays of size $m \\times p$, $n\\times m$, where $A'[i, j]$ is the number of rolls supplier $x_j$ supplies to store $s_i$, and $B'[i, j]$ is the number of rolls resident $r_i$ gets from store $s_j$, and $A', B'$ are both subject to the constraints of the problem, i.e., $0 \\le A'[i, j] \\le W[i, j]$, $B'[i, j] \\ge 0$, and $\\sum_{j = 1}^n B'[j, i] \\le \\sum_{j = 1}^p A'[i, j] \\quad \\forall i \\in [1\\ldots m]$.\n\nBy an \\textit{efficient assignment}, we denote an assignment where the following conditions are satisfied:\n\\begin{align}\n    \\sum_{j = 1}^m B'[i, j] \\le D[i] \\quad \\forall i \\in [1\\ldots n]\\\\\n    \\sum_{j = 1}^n B'[j, i] = \\sum_{j = 1}^p A'[i, j] \\quad \\forall i \\in [1\\ldots m]\n\\end{align}\n\nIn other words, an efficient assignment is one in which we have nothing left over at a store after the residents buy rolls, and all residents take no more rolls than their requirements.\n\nWe shall first show a bijection between valid flows in the graph and efficient assignments, where if flow $f$ is mapped to the assignment $a$, then $v(f) = \\sum_{i = 1}^n \\sum_{j = 1}^m B'[i, j]$ (total rolls bought by residents).\n\n\\begin{proof}\n\nConsider an efficient assignment $(A', B')$.\n\nConsider a flow defined as follows:\n\\begin{enumerate}\n    \\item For an edge $(s, S[i])$, let the flow associated to this edge be $\\sum_{j=1}^m A'[j, i]$.\n    \\item For an edge $(S[i], T[j])$, let the flow associated to this edge be $A'[j, i]$.\n    \\item For an edge $(T[j], R[i])$, let the flow associated to this edge be $B'[i, j]$.\n    \\item For an edge $(R[i], t)$, let the flow associated to this edge be $\\sum_{j = 1}^m B'[i, j]$.\n\\end{enumerate}\n\n%We note that it is possible to recover the efficient assignment from the flow uniquely too, so this mapping is an inverse.\n\nFirst we show that this is a valid flow.\n\n\\begin{enumerate}\n    \\item Flow conservation:\n        \\begin{enumerate}\n            \\item At vertex $S[i]$: Note that the only incoming edge is $(s, S[i])$, and the only outgoing edges are $(S[i], T[j])$ for $j \\in \\{1\\ldots m\\}$. From the definition of the flow values of these edges, we are done.\n            \\item At vertex $T[i]$: Note that since $(A', B')$ is an efficient assignment, we have $\\sum_{i = 1}^n B'[i, j] = \\sum_{j = 1}^p A'[i, j]$. The only incoming edges are $(S[j], T[i])$ for $j \\in \\{1\\ldots p\\}$, and the only outgoing edges are $(T[i], R[j])$ for $j in \\{1\\ldots n\\}$. By noting the definitions of $A', B'$ and the equality mentioned above, we are done.\n            \\item At vertex $R[i]$: Note that the only incoming edges are $(T[j], R[i])$ for $j \\in \\{1 \\ldots m\\}$, and the only outgoing edge is $(R[i], t)$. From the definition of the flow values of these edges, we are done.\n        \\end{enumerate}\n    \\item Capacity constraints:\n        Firstly note that all weights are non-negative integers. Now for the capacity constraints, note the following:\n        \\begin{enumerate}\n            \\item For an edge $(S[i], T[j])$, the flow associated to this edge is $A'[j, i]$. By the conditions of the problem, since an efficient assignment is a valid assignment, we have $A'[j, i] \\le W[j, i]$.\n            \\item For an edge $(s, S[i])$, the flow associated to this edge is $\\sum_{j=1}^m A'[j, i]$. By summing the result of the previous case over $j$, this is $\\le \\sum_{j = 1}^m W[j, i]$.\n            \\item For an edge $(T[j], R[i])$, the flow associated to this edge is $B'[i, j]$. Since we have $B'[i, j] \\le \\sum_{j = 1}^n \\le D[i]$ (as it is a efficient assignment), we are done for this case.\n            \\item For an edge $(R[i], t)$, the flow associated to this edge is $\\sum_{j = 1}^m B'[i, j]$. Since we have $\\sum_{j = 1}^n \\le D[i]$ (as it is a efficient assignment), we are done for this case.\n        \\end{enumerate}\n\\end{enumerate}\n\nNow we show that the value of this flow equals $\\sum_{i = 1}^n \\sum_{j = 1}^m B'[i, j]$. Note that by considering the $s-t$ cut $(A, B) = (V(G)\\setminus\\{t\\},\\{t\\})$, since there are no edges from $B$ to $A$, we have $f^{in}(A) = 0$, so the value of the flow is $f^{out}(A) = \\sum_{i = 1}^n \\sum_{j = 1}^m B'[i, j]$, as needed.\n\nHence we have shown that for any valid assignment, there exists a valid flow in the network with value being equal to the total number of rolls bought by residents.\n\nNow consider any flow $f$.\n\nConsider the following assignment:\n\n\\begin{align}\n    A'[i, j] = f((S[j], T[i]))\\\\\n    B'[i, j] = f((T[j], R[i]))\n\\end{align}\n\nNow we need to show that this is an efficient assignment.\n\n\\begin{enumerate}\n    \\item It is an assignment:\\nl\n    For this we need to show that $0 \\le A'[i, j] \\le W[i, j]$, $0 \\le B'[i, j]$ and $\\sum_{j = 1}^n B'[j, i] \\le \\sum_{j = 1}^p A'[i, j] \\quad \\forall i \\in [1\\ldots m]$.\n    However, the first of these follows from the fact that $f((S[j], T[i]))$ is flow associated to an edge with capacity $W[i, j]$ in a valid flow $f$. The second of these follows from $0 \\le B'[i, j]$ since it is flow associated to an edge and must be non-negative.\n    The third of these follows from the fact we will show below.\n    \\item It is an efficient assignment:\n        \\begin{enumerate}\n            \\item Consider flow conservation applied at vertex $R[i]$. Then the total incoming flow is $\\sum_{j = 1}^m f((T[j], R[i])) = \\sum_{j = 1}^m B'[i, j]$, which must equal the outgoing flow. And the only outgoing edge is $(R[i], t)$ which has a capacity of $D[i]$. Hence, we must have $\\sum_{j = 1}^m B'[i, j] \\le D[i]$, which verifies the first condition for an assignment to be an efficient assignment.\n            \\item Consider flow conservation applied at vertex $T[i]$. The total incoming flow is \\\\$\\sum_{j = 1}^p f((S[j], T[i])) = \\sum_{j = 1}^p A'[i, j]$. The total outgoing flow is $\\sum_{j = 1}^n f((T[i], R[j])) = \\sum_{j = 1}^n B'[j, i]$. By flow conservation, this verifies the second condition for an assignment to be an efficient assignment.\n        \\end{enumerate}\n\\end{enumerate}\n\nNow we need to show that $v(f) = \\sum_{i = 1}^n \\sum_{j = 1}^m B'[i, j]$.\n\nConsider the $s-t$ cut $(A, B) = (\\{s\\} \\cup S[1 \\ldots p] \\cup T[1 \\ldots m], R[1 \\ldots n] \\cup \\{t\\})$.\n\nNote that there is no edge from $B$ to $A$, so $f^{in}(A) = 0$, hence we have $v(f) = f^{out}(A)$. The only edges from $A$ to $B$ are the edges between vertices of the form $T[j], R[i]$. Hence we have $v(f) = f^{out}(A) = \\sum_{i = 1}^n \\sum_{j = 1}^m f((T[j], R[i])) = \\sum_{i = 1}^n \\sum_{j = 1}^m B'[i, j]$, as needed.\n\nFrom here we see that there is a bijection between efficient assignments and valid flows in the network which have the value of the flow being equal to the total number of rolls bought by the residents in the efficient assignment.\n\n\\end{proof}\n\nNow we shall show that if there exists an assignment which satisfies all the residents' needs, then there also exists an efficient assignment which satisfies all the residents' needs.\n\n\\begin{proof}\nConsider any assignment $(A', B')$ which satisfies all the residents' needs. We shall construct an efficient assignment that also satisfies all the residents' needs using the following algorithm (note that this algorithm is never run in the final algorithm, and we aim to use this as an aid in a proof of the claim above):\n\n\\begin{algorithmic}[1]\n    \\Require{$\\sum_{j = 1}^m B'[i, j] \\ge D[i] \\quad \\forall i \\in [1 \\ldots n]$}\n    \\Require{$0 \\le B'[i, j] \\quad \\forall (i, j) \\in [1 \\ldots n] \\times [1 \\ldots m]$}\n    \\Require{$0 \\le A'[i, j] \\le W[i, j]$}\n    \\Require{$\\sum_{j = 1}^n B'[j, i] \\le \\sum_{j = 1}^p A'[i, j] \\quad \\forall i \\in [1\\ldots m]$}\n    \\Function{GetEfficientAssignment}{$A', B'$}\n        \\State let $A'' \\gets A, B'' \\gets B$\n        \\For{$i \\in [1\\ldots n]$}\n            \\While{$\\sum_{j = 1}^m B''[i, j] > D[i]$}\n                \\State $j = \\argmax_{j} B''[i, j]$\n                \\State $B''[i, j] \\gets B''[i, j] - 1$\n            \\EndWhile\n        \\EndFor\n        \\For{$i \\in [1\\ldots n]$}\n            \\While{$\\sum_{j = 1}^n B''[j, i] < \\sum_{j = 1}^p A''[i, j]$}\n                \\State $j = \\argmax_{j} A''[i, j]$\n                \\State $A''[i, j] \\gets A''[i, j] - 1$\n            \\EndWhile\n        \\EndFor\n        \\State \\Return $(A'', B'')$\n    \\EndFunction\n\\end{algorithmic}\n\nWe claim that the above algorithm returns an efficient assignment that also satisfies the demands of all residents.\n\n\\begin{enumerate}\n    \\item It is an assignment\n        \\begin{enumerate}\n            \\item $B''[i, j] \\ge 0$: Note that we have $D[i] \\ge 0$, and hence we decrement some $B''[i, j]$ if the sum of $B''[i, j']$ over all $j'$ is positive. Note that the maximum $B''[i, j']$ must be always positive (if not, then the whole sum is non-positive). Hence we decrement a $B''[i, j]$ by 1 in a step only if it is positive. This implies that once we reach zero (which we reach since $B''$ is an integer matrix and the element we decrement decreases by exactly 1 at each decrement), we never decrement it further, proving this part.\n            \\item $0 \\le A''[i, j] \\le W[i, j]$: The second part follows from the fact that $A'[i, j] \\le W[i, j]$ and we either keep the value the same or decrease it. \n            For the first part, note that from the previous point, we have $\\sum_{j = 1}^n B''[j, i] \\ge 0$. By a completely analogous argument as in the previous point, we decrement $A''[i, j]$ only if it is positive, and hence we are done for this part.\n            \\item $\\sum_{j = 1}^n B''[j, i] \\le \\sum_{j = 1}^p A''[i, j]$: We claim that equality in fact holds, and that is done in the next part.\n        \\end{enumerate}\n    \\item It is an efficient assignment\n        \\begin{enumerate}\n            \\item $\\sum_{j = 1}^m B''[i, j] \\le D[i] \\quad \\forall i \\in [1\\ldots n]$:\n                There is a stronger assertion in the next point about satisfaction of all residents, and it is that equality holds, so we defer this to the next point.\n            \\item $\\sum_{j = 1}^n B''[j, i] = \\sum_{j = 1}^p A''[i, j] \\quad \\forall i \\in [1\\ldots m]$:\n                Either the loop runs, or the first condition is false. Since we never increment $B''[i, j]$, we have $\\sum_{j = 1}^n B''[j, i] \\le \\sum_{j = 1}^n B'[j, i]$. By the condition that stores can't supply more than the suppliers supply them, we have $\\sum_{j = 1}^n B''[j, i] \\le \\sum_{j = 1}^n B'[j, i] \\le \\sum_{j = 1}^p A'[i, j]$. Hence if the loop doesn't run, we have $\\sum_{j = 1}^n B''[j, i] = \\sum_{j = 1}^p A'[i, j] = \\sum_{j = 1}^p A''[i, j]$.\n                In the case that the loop runs, we keep decrementing the value of $\\sum_{j = 1}^p A''[i, j]$ by precisely $1$ in each step, till we reach a value $\\le \\sum_{j = 1}^n B''[j, i]$. Since $A'', B''$ are integer matrices, the value we reach is precisely $\\sum_{j = 1}^n B''[j, i]$, and we are done.\n        \\end{enumerate}\n    \\item It satisfies the demands of all residents, i.e., $\\sum_{j = 1}^m B''[i, j] = D[i] \\quad \\forall i \\in [1\\ldots n]$:\n    Note that by the condition that the input assignment must satisfy the demands of all the residents, the loop must either run, or we have $\\sum_{j = 1}^m B''[i, j] = D[i]$ already. If the loop runs, we keep decrementing the value of $\\sum_{j = 1}^m B''[i, j]$ by $1$ in each step, till we reach a value $\\le D[i]$. Since $B''$ is an integer matrix, the value we reach is precisely $D[i]$.\n\\end{enumerate}\nFrom the above analysis, we have proven the claim, as required.\n\\end{proof}\n\nHence from here, we get that we only need to search for an efficient assignment that satisfies the needs of all residents, and by the bijection, this is equivalent to searching for a flow which satisfies all the demands.\n\nUsing the cut $(A, B) = (V(G) \\setminus \\{t\\}, \\{t\\})$, noting that $f^{in}(A) = 0$ (since there is no edge from $B$ to $A$), the value of a flow $f$ in the network is $f^{out}(A)$. The capacity of this cut is $\\sum_{i = 1}^n D[i]$, so we have $\\textsc{Value}(\\textsc{MaxFlow}(G, s, t)) = f^{out}(A) \\le \\sum_{i = 1}^n D[i]$, where equality holds iff all the edges $(R[i], t)$ have flow through them equal to the capacity of that edge. By considering the efficient assignment corresponding to the maximum flow, we have the fact that there exists an efficient assignment that can satisfy all residents if and only if $\\textsc{Value}(\\textsc{MaxFlow}(G, s, t)) = \\sum_{i = 1}^n D[i]$.\n\nNow we argue as follows:\n\\begin{enumerate}\n    \\item If there exists an assignment satisfying all residents, then there exists an efficient assignment satisfying all residents, and such an assignment is detected by the algorithm and we return ``yes\".\n    \\item If we return ``yes\", then there is an efficient assignment satisfying all residents, and since an efficient assignment is an assignment, there is an answer to the problem.\n\\end{enumerate}\n\nHence, we return ``yes\" if and only if there is a solution to the problem, and ``no\" in the other case (i.e., when there is no solution to the problem).\n\n\\paragraph{Time Complexity Analysis}\nConsider the cuts $(\\{s\\}, V(G) \\setminus \\{s\\})$, $(V(G) \\setminus \\{t\\}, \\{t\\})$. Both of these cuts have capacities at least the maximum flow in the graph, from the max-flow-min-cut theorem.\nHence the maximum flow is upper bounded by \n\n$$C = \\min \\left(\\sum_{i = 1}^n D[i], \\sum_{i = 1}^p \\sum_{j = 1}^m W[j, i]\\right)$$\n\nThe number of vertices in the graph is $2 + p + m + n$, and the number of edges is $p + pm + mn + n$. \n\nHence the call to $\\textsc{MaxFlow}$ takes $O((1 + p + m + n + pm + mn)C)$ time, where $C$ is defined as above. The call to the value function takes $O(1 + p + m + n + pm + mn)$ time (the total number of edges and vertices in the graph).\n\nCreating the whole graph takes $O(1 + p + m + n + pm + mn)$ time as well (apart from the computations used for computing the capacities of edges $(s, S[i])$, and checking if $(T[j], R[i])$ needs to be added or not).\n\nFor computing the capacities of the edges, the sum can be computed in $O(pm)$ time and the checks for $V[i, j]$ happen in $O(mn)$ time, so the total graph construction time is again in $O(1 + p + m + n + pm + mn)$.\n\nComputing the total sum of demands takes time $O(m)$.\n\nHence the overall time complexity is $O((1 + p + m + n + pm + mn)(C + 1))$, where $C$ is defined as $C = \\min \\left(\\sum_{i = 1}^n D[i], \\sum_{i = 1}^p \\sum_{j = 1}^m W[j, i]\\right)$.\n\n\n\\end{solution}\n\n\\end{questions}\n\\end{document}\n", "meta": {"hexsha": "2cb9fdc7aec702b653674c58ccebe65172b981ed", "size": 49596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw/hw5/main.tex", "max_stars_repo_name": "NavneelSinghal/AlgorithmsCourse", "max_stars_repo_head_hexsha": "5d6d25a367228078c96662d7875cafe57775304b", "max_stars_repo_licenses": ["MIT"], "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/hw5/main.tex", "max_issues_repo_name": "NavneelSinghal/AlgorithmsCourse", "max_issues_repo_head_hexsha": "5d6d25a367228078c96662d7875cafe57775304b", "max_issues_repo_licenses": ["MIT"], "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/hw5/main.tex", "max_forks_repo_name": "NavneelSinghal/AlgorithmsCourse", "max_forks_repo_head_hexsha": "5d6d25a367228078c96662d7875cafe57775304b", "max_forks_repo_licenses": ["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.0435835351, "max_line_length": 1018, "alphanum_fraction": 0.658137753, "num_tokens": 15986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.6329358490975202}}
{"text": "\\section{Fundamental group and monodromy action}\nFix a space $X$ and a vertex $x$ on it.\n\nRecall that, a \\emph{path} $\\gamma$ in $X$ is a finite sequence of edges $e_1 e_2 e_3 \\dots e_k$, where we allow inverses, such that $d_1 e_i = d_0 e_{i+1}$ for $1 \\le i \\le k-1$.\nDenote $d_0 \\gamma = d_0 e_1$ and $d_1 \\gamma = d_1 e_k$.\n\nWe can concatenate two paths $\\gamma_1$, $\\gamma_2$ if $d_1 \\gamma_1 = d_0 \\gamma_2$ to get a path $\\gamma_1 \\cdot \\gamma_2$ from $d_0 \\gamma_1$ to $d_1 \\gamma_2$.\nFor a vertex $x \\in X$, we denote by $\\mathbb{1}_x$ the path of length 0 starting at $x$, with the property that $d_0 \\mathbb{1}_x = x = d_1 \\mathbb{1}_x$ and $\\gamma \\cdot \\mathbb{1}_x = \\gamma$ and $ \\mathbb{1}_x \\cdot \\gamma = \\gamma$ whenever the concatenations make sense.\n\nA \\emph{loop} at $x$ is a path starting and ending at $x$. Concatenation defines a product on the set of loops.\n\nThe \\emph{fundamental group} of $X$ at $x$ is essentially\n\\begin{equation*}\n  \\pi_1(X,x) = \\langle \\mbox{ loops } | \\mbox{ faces }\\rangle\n\\end{equation*}\nThere are multiple ways to make this definition precise. We will do this recursively.\n\nWe add \\emph{generators} using edges.\n\\begin{enumerate}\n  \\item Start with just the vertex $x$.\n  \\item Add edges successive (while keeping the space connected).\n  \\item Every time the newly added edge $e$ forms a loop $\\gamma$, add $\\gamma$ as a generator to $\\pi(X,x)$.\n\\end{enumerate}\n\nWe add \\emph{relations} using faces.\n\\begin{enumerate}\n  \\item Add the faces one at a time.\n  \\item For each face, let $\\gamma'$ be the boundary of the face starting at $y$.\n  \\item Add the relation $\\gamma \\cdot \\gamma' \\cdot \\gamma^{-1}$ to $\\pi_1(X,x)$ where $\\gamma$ is a path connecting $x$ to $y$.\n\\end{enumerate}\n\n\\begin{remark}\n  If you think that this definition is artificial and contrived, then you are correct. There is a very natural object called the \\emph{fundamental groupoid} associated to the space $X$ which does not depend on the basepoint $x$.\n\\end{remark}\n\n\n  \\begin{ex}\n    The fundamental group of $S^1$ has a single generator and there are no relations.\n    Hence,\n    \\begin{align*}\n      \\pi_1(S^1) = \\langle a \\rangle \\cong \\bbz\n    \\end{align*}\n    \\begin{figure}[H]\n    \\centering\n      % \\includegraphics[width=0.5\\textwidth]{example-image}\n      \\begin{tikzpicture}[scale=0.5]\n        \\input{images/circle.tex}\n      \\end{tikzpicture}\n      \\caption{Fundamental group of a circle is $\\bbz$.}\n    \\end{figure}\n  \\end{ex}\n\n  \\begin{ex}\n    The fundamental group of $S^1 \\vee S^1$ has a single generator and there are no relations.\n    Hence,\n    \\begin{align*}\n      \\pi_1(S^1 \\vee S^1) = \\langle a, b \\rangle \\cong F_2\n    \\end{align*}\n    which is the free group on two generators.\n    \\begin{figure}[H]\n    \\centering\n      % \\includegraphics[width=0.5\\textwidth]{example-image}\n      \\begin{tikzpicture}[scale=0.5]\n        \\input{images/s1s1.tex}\n      \\end{tikzpicture}\n      \\caption{Fundamental group of $S^1 \\vee S^1$ is $\\bbz$.}\n    \\end{figure}\n  \\end{ex}\n\n  \\begin{ex}\n    The fundamental group on cylinder is given by\n    \\begin{align*}\n      \\pi_1(\\mbox{cylinder})\n      &= \\langle c, a b a^{-1} \\mid  a b a^{-1} c\\rangle \\\\\n      &= \\langle c \\rangle \\\\\n      &\\cong \\bbz\n    \\end{align*}\n  \\end{ex}\n\n    \\begin{ex}\n      The fundamental group on torus is given by\n      \\begin{align*}\n        \\pi_1(\\mbox{torus})\n        &= \\langle a, b \\mid a b a^{-1} b^{-1} \\rangle \\\\\n        &\\cong \\bbz \\times \\bbz\n      \\end{align*}\n    \\end{ex}\n\n  \\begin{qbox}\n    Find the fundamental groups of\n    \\begin{enumerate}\n      \\item $S^2$\n      \\item Mobius strip\n      \\item Klein bottle\n      \\item Real projective space\n    \\end{enumerate}\n  \\end{qbox}\n\n  \\begin{proposition}\n    For any two vertices $x_1$, $x_2 \\in X$ there exists an isomorphism\n    \\begin{equation*}\n      \\pi_1(X,x_1) \\xrightarrow{\\cong} \\pi_1(X,x_2).\n    \\end{equation*}\n  Henc, the fundamental group does not depend on the basepoint upto isomorphism.\n\\end{proposition}\n  \\begin{qbox}\n    Pick a path $\\gamma \\in X$ from $x$ to $x'$.\n    Conjugate by $\\gamma$ to get an isomorphism between $\\pi_1(X,x)$ and $\\pi_1(X,x')$.\n  \\end{qbox}\n\n\\subsection{Monodromy}\n\\begin{proposition}\n  A covering map $p:Y \\rightarrow X$ induces a group homomorphism\n  \\begin{align*}\n    p_* : \\pi_1(Y,y) &\\longrightarrow \\pi_1(X,x), \\\\\n    [\\gamma] &\\longmapsto [p(\\gamma)].\n  \\end{align*}\n  where $x = p(y)$.\n  If $p$ is a non-trivial cover then $p_*$ is strictly injective i.e. $p_*\\pi_1(Y,y)$ is a proper subgroup of $\\pi_1(X,x)$.\n\\end{proposition}\n\\begin{proof}\n  The group homomorphism is evident as $p$ preserves concatenation of paths.\n\n  For injectivity, suppose $[p(\\gamma)]$ is trivial inside $\\pi_1(X,x)$.\n  This means that $p(\\gamma)$ is a product of terms of the form $\\gamma \\cdot \\gamma' \\cdot \\gamma^{-1}$ where $\\gamma'$ is the boundary of a face. Hence, $\\gamma$ is a product of the lifts $\\widetilde{\\gamma} \\cdot \\widetilde{\\gamma}' \\cdot \\widetilde{\\gamma}^{-1}$.\n  But $\\widetilde{\\gamma}'$ is also the boundary of a face as $p$ is a simplicial map.\n  Hence, $[{\\gamma}]$ is trivial $\\implies$ $p_*$ is injective.\n\n  $p_*$ is strictly injective as a path $y_1$ to $y_2$, both in the fiber over $x$, map down to a loop at $x$, say $\\gamma$.\n  By uniqueness of path lifting, there is no path that maps down to $\\gamma$.\n\\end{proof}\n\n\\begin{theorem}\n  Let $p:Y \\rightarrow X$ be a Galois cover. Let $y$ be a vertex in $Y$ in the fiber over the vertex $x$ in $X$.\n  Then there is a surjective group homomorphism\n  \\begin{align*}\n    M:\\pi_1(X,x) \\longrightarrow \\Gal(Y|X)\n  \\end{align*}\n  whose kernel is $p_*(\\pi_1(Y,y))$.\n  We say that the loops in $X$ act via ``monodromy'' on the space $Y$.\n\\end{theorem}\n\\begin{proof}\n  The map $M$ is defined as follows.\n  Let $y$ be a point $y$ in the fiber over $x$ and let $\\gamma$ be a loop in the base starting at $x$.\n  Consider the unique lift $\\widetilde{\\gamma}$ starting at $y$.\n  Because $p:Y \\rightarrow X$ is Galois, there is a unique deck transformation $\\varphi_{\\gamma} \\in \\Gal(Y|X)$ sending $y$ to $d_1 \\widetilde{\\gamma}$.\n  Then define\n  \\begin{equation*}\n    M(\\gamma) = \\varphi_{\\gamma}\n  \\end{equation*}\n  In order to show that this map descends to $\\pi_1(X,x)$ we need to show that $\\gamma \\cdot \\gamma' \\cdot \\gamma^{-1}$ gets mapped to the trivial deck transformation, where $\\gamma'$ is the boundary of a face.\n  \\begin{qbox}\n    Check this.\n  \\end{qbox}\n\n  The kernel of $M$ is the set of loops which lift to loops at $y$, which is the same as the set of loops in $X$ which are images of loops in $Y$, but this is precisely $p_*(\\pi_1(Y,y))$.\n\n  It remains to show that $M$ is a group homomorphism.\n  Let $\\gamma_1$ and $\\gamma_2$ be two loops in $\\pi_1(X,x)$. Suppose $d_1 \\widetilde{\\gamma_1} = y_1$ and $d_1 \\widetilde{\\gamma_2} = y_2$. Let $\\varphi_1 = M \\gamma_1$ and $\\varphi_2 = M \\gamma_2$ so that $ \\varphi_1(y) = y_1$ and $\\varphi_2(y) = y_2$.\n  By unique path lifting it follows that the lift of $\\widetilde{\\gamma_1 \\cdot \\gamma}$ is the path that ends in $\\varphi_1(y_2) = \\varphi_1 \\varphi_2 y$.\n  Hence, $M$ sends $\\gamma_1 \\cdot \\gamma_2$ to $\\varphi_1 \\cdot \\varphi_2$.\n\\end{proof}\n\n\n\\begin{theorem}\n  \\label{theorem:fundamentalGroupQuotient}\n  We can rewrite the above theorem as saying that if $p:Y \\rightarrow X$ is a Galois cover with $p(y) = x$, then there is a short exact sequence of groups\n  \\begin{equation*}\n    1 \\rightarrow \\pi_1(Y,y) \\xrightarrow{p_*} \\pi_1(X,x) \\rightarrow \\Gal(Y|X) \\rightarrow 1\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{qbox}\n  Verify Theorem \\ref{theorem:fundamentalGroupQuotient} for the coverings $(1)$, $(2)$, $(6)$, and $(11)$ of $S^1 \\vee S^1$ in Figure \\ref{fig:CoveringsOfS1S1}.\n\\end{qbox}\n\n\\begin{qbox}\n  Verify Theorem \\ref{theorem:fundamentalGroupQuotient} for the coverings\n  \\begin{align*}\n    \\mbox{Cylinder} &\\longrightarrow \\mbox{Mobius Strip} \\\\\n    \\mbox{Torus} &\\longrightarrow \\mbox{Klein Bottle} \\\\\n    \\mbox{Sphere } S^2 &\\longrightarrow \\mbox{Real projective space}\n  \\end{align*}\n\\end{qbox}\n\n\n\n\n\n\n\n\\begin{figure}[p]\n\\centering\n  \\includegraphics[width=\\textwidth]{coveringsOfS1S1.jpg}\n  \\caption*{Coverings of $S^1 \\vee S^1$. Image from Algebraic Topology, Allen Hatcher, Chapter 1.}\n\\end{figure}\n\n\\begin{figure}[p]\n  \\centering\n  \\includegraphics[width=0.65\\textwidth]{cylinderGluingDiagram.png}\n  \\includegraphics[width=0.65\\textwidth]{MobiusStripGluingDiagram.png}\n\n  \\includegraphics[width=0.65\\textwidth]{torusGluingDiagram.png}\n  \\includegraphics[width=0.65\\textwidth]{KleinBottleGluingDiagram.png}\n\n  \\includegraphics[width=0.65\\textwidth]{RP2GluingDiagram.png}\n  \\caption*{Gluing diagrams for cylinder, Mobius strip, torus, Klein bottle, real projective space respectively. Images from BMC Notes on Surfaces by Maia Averett.}\n\\end{figure}\n", "meta": {"hexsha": "7d510c41d51957193e66c580a5595cee49e9a588", "size": 8806, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04.tex", "max_stars_repo_name": "apurvnakade/mc2019-Galois-correspondence-of-covering-spaces", "max_stars_repo_head_hexsha": "0daace3a630f99a117be973eab11bc547dc6fb44", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "apurvnakade/mc2019-Galois-correspondence-of-covering-spaces", "max_issues_repo_head_hexsha": "0daace3a630f99a117be973eab11bc547dc6fb44", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "apurvnakade/mc2019-Galois-correspondence-of-covering-spaces", "max_forks_repo_head_hexsha": "0daace3a630f99a117be973eab11bc547dc6fb44", "max_forks_repo_licenses": ["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.1339712919, "max_line_length": 277, "alphanum_fraction": 0.6717011129, "num_tokens": 2988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8807970858005139, "lm_q1q2_score": 0.6329358468490006}}
{"text": "\\documentclass[12pt]{article}\n\\include{include}\n\n\\title{Description of matrix operator for finite-volume form of advection-diffusion equation}\n\n\\author{George J. Wilkie}\n\n\\begin{document}\n\\maketitle\n%\\tableofcontents\n\n%\\section{Introduction}\n\nWe seek to descritize an operator of the form:\n\\begin{equation} \\label{maineqn}\n   M\\left[f \\right] = \\frac{1}{J} \\pd{ }{x} \\left( J \\Gamma \\right) =  \\frac{1}{J} \\pd{ }{x} \\left[ J A f + J D  \\pd{f}{x} \\right]\n\\end{equation}\nusing a finite-volume method with piecewise constant elements. Each element has a average/constant value of $f$ and $x$ given by $f_i$ and $x_i$, respectively, for $1 \\leq i \\leq N$. The fluxes $\\Gamma_{i+1/2}$ and $\\Gamma_{i-1/2}$ are defined on the mesh faces $x_{i+1/2}$ and $x_{i-1/2}$. The Jacobian of the (arbitrary) coordinate $x$ is $J(x)$. Using the average of the adjacent cells to represent the value of $f$ at the cell boundary, we can descritize Eq. \\ref{maineqn} as:\n\\begin{align}\n   M\\left[ f_i \\right] \\approx& \\frac{1}{J_i} \\frac{1}{x_{i+1/2} - x_{i-1/2}} \\left[ \\left(JA\\right)_{i+1/2} \\frac{f_{i+1} + f_i }{2}  -  \\left(JA\\right)_{i-1/2} \\frac{ f_{i} + f_{i-1} }{2}   \\right. \\nonumber\\\\\n   & \\left. + \\left(JD \\right)_{i+1/2}\\frac{ f_{i+1} - f_i }{v_{i+1}-v_i} - \\left(JD \\right)_{i-1/2} \\frac{ f_{i} - f_{i-1} }{v_{i}-v_{i-1}}  \\right]  \\\\\n   =&  a_{i-1} f_{i-1} +  b_i f_i + c_{i+1} f_{i+1}  .\n\\end{align}\nThe tridiagonal coefficients for interior points are given by:\n\\begin{equation}\n   a_{i-1} = \\frac{1}{J_i \\left( x_{i+1/2} - x_{i-1/2} \\right)} \\left[- \\frac{1}{2}\\left(JA\\right)_{i-1/2} + \\frac{\\left(JD\\right)_{i-1/2} }{ x_{i}-x_{i-1}} \\right]\n\\end{equation}\n\\begin{equation}\n   b_{i} = \\frac{1}{J_i \\left( x_{i+1/2} - x_{i-1/2} \\right)} \\left[ \\frac{1}{2}\\left(JA\\right)_{i+1/2} - \\frac{1}{2}\\left(JA\\right)_{i-1/2} - \\frac{\\left(JD\\right)_{i+1/2} }{ x_{i+1}-x_i} - \\frac{\\left(JD\\right)_{i-1/2} }{ x_{i}-x_{i-1}} \\right]\n\\end{equation}\n\\begin{equation}\n   c_{i+1} = \\frac{1}{J_i \\left( x_{i+1/2} - x_{i-1/2} \\right)} \\left[ \\frac{1}{2}\\left(JA\\right)_{i+1/2} + \\frac{\\left(JD\\right)_{i+1/2} }{ x_{i+1}-x_i} \\right]\n\\end{equation}\n\nFor Dirichlet boundary conditions, these are replaced by unity on the diagonal element, and zeros elsewhere. For flux-specified boundary conditions at $i=1$:\n\\begin{equation}\n   M\\left[ f_1 \\right] \\approx \\frac{1}{J_1} \\frac{1}{x_{3/2} - x_{1/2}} \\left[ \\left(JA\\right)_{3/2} \\frac{f_{2} + f_1 }{2}  + \\left(JD \\right)_{3/2}\\frac{ f_{2} - f_1 }{v_{2}-v_1}   \\right]  \n\\end{equation}\nand\n\\begin{equation}\n   b_{1} = \\frac{1}{J_1 \\left( x_{3/2} - x_{1/2} \\right)} \\left[ \\frac{1}{2}\\left(JA\\right)_{3/2} - \\frac{\\left(JD\\right)_{3/2} }{ x_{2}-x_1} \\right]\n\\end{equation}\n\\begin{equation}\n   c_{2} = \\frac{1}{J_1 \\left( x_{3/2} - x_{1/2} \\right)} \\left[ \\frac{1}{2}\\left(JA\\right)_{3/2} + \\frac{\\left(JD\\right)_{3/2} }{ x_{2}-x_1} \\right],\n\\end{equation}\nwhile the incoming flux $\\Gamma_{1/2} = \\Gamma\\left(x_{1/2}\\right)$ is given and the following must be added to the source:\n\\begin{equation}\n   \\Delta S_1  = \\frac{J_{1/2} \\Gamma_{1/2}}{J_1 \\left( x_{3/2} - x_{1/2} \\right)}.\n\\end{equation}\nFor flux conditions on the right side, we have similarly:\n\\begin{equation}\n   M\\left[ f_N \\right] \\approx \\frac{1}{J_N} \\frac{1}{x_{N+1/2} - x_{N-1/2}} \\left[ -  \\left(JA\\right)_{N-1/2} \\frac{ f_{N} + f_{N-1} }{2}  - \\left(JD \\right)_{N-1/2} \\frac{ f_{N} - f_{N-1} }{v_{N}-v_{N-1}}  \\right]  \\\\\n\\end{equation}\n\\begin{equation}\n   a_{N-1} = \\frac{1}{J_N \\left( x_{N+1/2} - x_{N-1/2} \\right)} \\left[- \\frac{1}{2}\\left(JA\\right)_{N-1/2} + \\frac{\\left(JD\\right)_{N-1/2} }{ x_{N}-x_{N-1}} \\right]\n\\end{equation}\n\\begin{equation}\n   b_{N} = \\frac{1}{J_N \\left( x_{N+1/2} - x_{N-1/2} \\right)} \\left[ - \\frac{1}{2}\\left(JA\\right)_{N-1/2} - \\frac{\\left(JD\\right)_{N-1/2} }{ x_{N}-x_{N-1}} \\right]\n\\end{equation}\n\\begin{equation}\n   \\Delta S_N  = \\frac{- J_{N+1/2} \\Gamma_{N+1/2}}{J_N \\left( x_{N+1/2} - x_{N-1/2} \\right)}.\n\\end{equation}\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "d5bb41fe5363e5540daa2c97bef0695373cc0a22", "size": 3975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/operator.tex", "max_stars_repo_name": "gjwilkie/PlasmaTools", "max_stars_repo_head_hexsha": "2238eb64d0b3fa2b80498c93d6cf5b86003198db", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-19T21:04:08.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-19T21:04:08.000Z", "max_issues_repo_path": "doc/operator.tex", "max_issues_repo_name": "gjwilkie/PlasmaTools", "max_issues_repo_head_hexsha": "2238eb64d0b3fa2b80498c93d6cf5b86003198db", "max_issues_repo_licenses": ["MIT"], "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/operator.tex", "max_forks_repo_name": "gjwilkie/PlasmaTools", "max_forks_repo_head_hexsha": "2238eb64d0b3fa2b80498c93d6cf5b86003198db", "max_forks_repo_licenses": ["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.985915493, "max_line_length": 480, "alphanum_fraction": 0.6143396226, "num_tokens": 1817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.632881325594456}}
{"text": "\\documentstyle[a4wide,12pt]{article}\n\n\\begin{document}\n\n\n\n\n\\section*{From Ordinary Differential equations to Neural Networks, solving mechanics problems in a new way}\n\n\\subsection*{Introduction.}\n\nThe aim of this project is to study an oscillation problem using different methods for\nsolving ordinary differential equations. We will focus on traditional methods as well as\non solving similar equations neural networks. For solving differential equations with Neural Networks we recommend the material at\nthe \\href{{https://compphysics.github.io/MachineLearning/doc/pub/odenn/html/odenn.html}}{Machine Learning and Data Analysis course}.\n\nThe first part is a repeat of homework 5 on an oscillating block tied to a spring.\n\n\\subsection{The standard ordinary differential equation solver}\nThe relevant material with codes etc is covered by the \\href{{https://mhjensen.github.io/Physics321/doc/pub/harmonic/html/harmonic.html}}{Lecture Notes on Oscillations}. Taylor's chapter 5, in particular sections 5.1 amd 5.2. 5.4 is relevant for the bonus exercise.\nWe start now with our next numerical application with simple rewrites of our equations. The system we will look at is that of a block fastened to a spring (which in turn is tied to a wall).\nThe force acting on the block from the spring in the $x$-drection only is\n\\[\nm\\frac{d^2x(t)}{dt^2}=F(x) = -k(x-b),\n\\]\nwhere $k$ is a material specific constant and $b$ is the equilibrium position. The block has mass $m$ and $t$ is time. Define the initial time as $t_0$. We will for simplicity set the equilibrium position to zero, that is $b=0$.\n\n\\begin{itemize}\n\\item Does this force conserve energy? If so, with given initial position and velocity $x_0$ and $v_0$, respectively, find the expression for energy conservation in terms of the potential and kinetic energies.  \n\n\\item Define a constant $\\omega_0=\\sqrt{k/m}$ and show that you can write the acceleration as $a(t) = -\\omega_0^2 x(t)$. What is the dimentionality of $\\omega_0$? (it is normally called a natural frequency).  \n\n\\item Introduce now a dimensionless time $\\tau = t\\omega_0$. Show that you can rewrite the  equation for the acceleration in terms of two first-order differential equations\n\\end{itemize}\n\n\\noindent\n\\[\n\\frac{dv}{d\\tau} = -x,\n\\]\nand\n\\[\n\\frac{dx}{d\\tau} = v.\n\\]\nWhat are the dimensionalities of these two equations?\n\nThese are the equations which we will code in the next exercise.\n\n\\begin{itemize}\n\\item Find the analytical solutions for the velocity and position as function of the initial conditions. \n\n\\item Write then a program which solves the above differential equations for the sliding blook using the Euler-Cromer  method and the velocity Verlet method. Study the results for the position, velocity and energy conservation as function of time and the step size in time. Compare the numerical results with the analytical ones. Check that your results for position and velocity obey periodicity. \n\\end{itemize}\n\n\\noindent\nIs energy properly conserved? Discuss your results. \n\nNow we will add to our program a first derivative of position (the velocity) which is meant to mimick the role of friction.\nOur differential equation is now\n\\[\nm\\frac{d^2x(t)}{dt^2}+\\beta\\frac{dx}{dt}+kx=ma(t)+\\beta v(t)+kx(t)=0,\n\\]\n\nwhere $k$ is a material specific constant and $\\beta$ is a constant\nrepresenting the resitance from the plane on which the block slides.\nWe have thus assumed that friction depends on velocity in a linear\nway.\n\nWe introduce again the dimensionless time $\\tau = t\\omega_0$ with\n$\\omega_0=\\sqrt{k/m}$.\n\n\\begin{itemize}\n\\item Divide by $m$ and show that you can rewrite your equation as two first-order coupled differential equations\n\\end{itemize}\n\n\\noindent\n\\[\n\\frac{dv}{d\\tau} = -2v(t)\\gamma-x(t),\n\\]\nand\n\\[\n\\frac{dx}{d\\tau} = v(t).\n\\]\nWhat are the dimensionalities of these two equations? We have defined $\\gamma = \\beta/2m$.  \n\n\n\\begin{itemize}\n\\item Add the role of friction to your code and study the cases where (i) $\\gamma < \\omega_0$ (underdamping), (ii) $\\gamma = omega_0$ ( critical damping) and (iii) $\\gamma > omega_0$ (overdamping). Plot your resulting positions as functions of time and discuss the physical meaning of your results.\n\\item Add also a sinusoidal external force that depends only on time $F(t)=F_0\\cos{(\\omega t)}$. Scale the equations again and study your results by adding the Runge-Kutta method to fourth order.\n\\end{itemize}\n\n\\subsection{Neural Networks}\n\nFinally, with the above equations (you could start without friction and external forces), implement a Neural Network solver and compare the results from this Machine Learning algorithm with those obtained using the standard Euler-Cromer method and the fourth-order Runge-Kutta method. Discuss your results.\n\n\\end{document}\n\n\n\n\n\\paragraph{a: More text to come}\n\n\n\\end{document}\n\n\n\n\n\n", "meta": {"hexsha": "1b060419778b5d0800c0cd2d5225b43cb13ff84e", "size": 4812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Honorsprojects/NeuralNetworks.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/NeuralNetworks.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/NeuralNetworks.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": 44.1467889908, "max_line_length": 398, "alphanum_fraction": 0.7643391521, "num_tokens": 1207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6328813179070024}}
{"text": "\\section{PS Networks}\n\\label{sec:PS-Networks}\n\n\\begin{theorem} [BCMP]\n\t\\begin{equation}\n\t\\label{eqn:BCMP}\n\t\\pi_{n_{1},...,n_{m}} = \\prod_{i=1}^{m} \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\\end{equation}\n\twhere $\\varrho_{i}=\\lambda_{i}\\expected{S_{i}}$\n\\end{theorem}\n\n\\begin{corollary}\n\t\\begin{equation}\n\t\\label{eqn:BCMP-Jobs-Server}\n\t\\probability{n_{i} jobs at server i} = \\varrho_{i}^{n_{i}} (1-\\varrho_{i})\n\t\\end{equation}\n\twhere $\\varrho_{i}=\\lambda_{i}\\expected{S_{i}}$\n\\end{corollary}", "meta": {"hexsha": "e0ebfc4baa022c8df943b2d2c0333c271cf34f37", "size": 485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/p-s-networks.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/p-s-networks.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/p-s-networks.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": 26.9444444444, "max_line_length": 76, "alphanum_fraction": 0.6536082474, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.6926419704455588, "lm_q1q2_score": 0.6328507042709391}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Comparing the Maximal Updated Density (MUD) and MAP points}\\label{sec:estimation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nWe formally define the maximal updated density (MUD) point as\n\\begin{equation}\\label{eq:mudpt_inital_defn}\n\t\\mudpt := \\argmax {\\updated}(\\param).\n\\end{equation}\nWe motivate the use of the MUD point as an alternative to the MAP point for parameter estimation problems.\nIn this section, we assume linear (or affine) QoI maps with Gaussian distributions, which are often used in the UQ literature to provide a common framework for comparing methods and their solutions.\n\nThis section is structured into several subsections to help focus the interpretations and results.\nIn Section~\\ref{subsec:Motivation}, we present some useful details, notation, and terminology used for this comparison framework.\nTo build intuition, we compare both the MUD and MAP points in Section~\\ref{subsec:low-d-example} using a low-dimensional example.\nA unifying perspective is provided for affine maps in Section~\\ref{subsec:unifying-perspective} along with derivations of closed form expressions for the MUD and MAP points in this comparison framework.\nThese results are summarized in a theorem of existence and uniqueness of the MUD point in this comparison framework.\n%Subsection~\\ref{subsec:MUD-MAP-generalized-contours} provides some useful interpretations of the MUD and MAP points in terms of their connections to points on generalized contours and relationships to least-squares solutions.\n%Finally, in Subsection~\\ref{subsec:MUD-theorem}, we summarize the theory of existence and uniqueness for the MUD point.\n%along with several numerical results that compare features of the MUD point to two other point estimates: the MAP point obtained from a Bayesian formulation and the solutions to a least-squares problem.\n\n\n\\subsection{MUD and MAP points for the ``linear Gaussian'' case}\\label{subsec:Motivation}\n\n%{\\bf Regularization/deterministic optimization connections.\n%The type of problem is now different involving parameter identification under uncertainty}\n\n\nLet $\\norm{\\mathbf{x}}_C^2 := (\\mathbf{x}, \\mathbf{x})_C = \\mathbf{x}^T C \\mathbf{x} $ denote the square of the induced norm associated with a positive-definite operator $C : \\RR^n \\to \\RR^n$ and the usual (Euclidean) inner product.\nIn what follows, the inverse covariances associated with non-degenerative multivariate Gaussian distributions will play the role of $C$.\n%\n%either attached to the Gaussian initial (prior) $\\mathcal{N}(\\param_0, \\initialCov)$, observed $\\mathcal{N}(\\observedMean, \\observedCov)$, or predicted $\\mathcal{N}(Q(\\param_0), \\predictedCov)$ distributions.\n%So, $C$ will play the roles of $\\observedCov^{-1}$, $\\initialCov^{-1}$, and $\\predictedCov^{-1}$.\n\nSuppose that the initial and prior densities are both given by the same $\\mathcal{N}(\\param_0, \\initialCov)$ distribution.\nAdditionally, suppose the map $Q$ is linear and that the data-likelihood and observed densities are both given by the same $\\mathcal{N}(\\observedMean, \\observedCov)$ distribution.\n\nThe linearity of $Q$ implies that $Q(\\param)=A\\param$ for some $A\\in\\RR^{d\\times p}$, and that the predicted density follows a $\\mathcal{N}(Q(\\param_0), \\predictedCov)$ distribution where\n\\begin{equation}\\label{eq:predictCov}\n\t\\predictedCov := A\\initialCov A^\\top.\n\\end{equation}\nWhile it is not technically necessary to ensure that the predictability assumption holds (i.e, that $\\updated$ is in fact a density) in order to formally define a MUD point using~\\eqref{eq:mudpt_inital_defn}, it is useful when discussing certain theoretical results involving data-constructed QoI maps as we see in Sections~\\ref{subsec:unifying-perspective} and~\\ref{sec:data-maps}.\n%The predictability assumption holds whenever\n%\\begin{equation}\\label{eq:predict_cov_assump}\n%\t\\predictedCov \\geq \\observedCov,\n%\\end{equation}\n%where the inequality is interpreted as holding term-wise.\n%We therefore refer to the condition of~\\eqref{eq:predict_cov_assump} as the predictability assumption for the linear Gaussian case.\nConceptually, the predictability assumption holds when the predicted variance is larger in all directions than the observed variance.\nThis condition is consistent with the desired outcome of a parameter estimation problem where the incorporation of observed data produces not only an improvement to the initial point estimate but also serves to reduce the uncertainty in this point estimate (quantified in this case by the covariance).\nMathematically, this occurs when the smallest eigenvalue value of $\\predictedCov$ is larger than the largest eigenvalue value of $\\observedCov$.\n\nWhen $\\observedCov$ is non-degenerative (i.e., the smallest eigenvalue is positive), the predictability assumption can always be satisfied if $d\\leq p$ and $A$ is full rank by choosing $\\initialCov$ to have sufficiently large eigenvalues (i.e., if we choose initial variances to be sufficiently large).\nTo simplify the theoretical presentation of this section, we assume these conditions are met so that the predictability assumption holds and $\\updated$ does in fact define a density.\nHowever, in Section~\\ref{sec:high-dim-linear-example}, we still compute the formal MUD point for a high-dimensional example involving rank-deficient $A$ to demonstrate the overall usefulness of the MUD point even in situations where $\\updated$ may fail to be an actual density.\n\n\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|}\n\\hline\n  & \\\\\n  Tikhonov & $T(\\param):=\\norm{Q(\\param)-\\observedMean}_{\\observedCov^{-1}}^2 +\n      \\norm{\\param-\\initialMean}_{\\initialCov^{-1}}^2$\n  \\\\ & \\\\ \\hline & \\\\\n  Data-Consistent & $J(\\param):=T(\\param) - \\norm{Q(\\param)-Q(\\initialMean)}_{\\predictedCov^{-1}}^2$\n  \\\\ & \\\\\n  \\hline\n\\end{tabular}\n\\caption{Functionals to minimize to obtain $\\param$ that maximizes  the updated PDF (bottom) and the Bayesian posterior PDF (top).\nHere, $T(\\param)$ is the typical functional often associated with Tikhonov regularization, and the $J(\\param)$ has an additional term subtracted from $T(\\param)$ coming from the predicted density that serves as ``unregularization'' in data--informed directions.}\n  \\label{tab:func_comparisons}\n\\end{table}\n\n\nWith these assumptions, the parameters that maximize the posterior and updated densities are described as the arguments that minimize certain quadratic functionals.\nTable~\\ref{tab:func_comparisons} presents a scaling of these functionals defined by the negative logarithm of the associated posterior and updated densities.\nNote that the functional, $T(\\param)$, obtained from the posterior density is immediately identified as the typical functional used in Tikhonov regularization \\citep{Tarantola_book}.\n\nThe data-mismatch term given by\n\\begin{equation*}\n\t\\norm{Q(\\param)-\\observedMean}_{\\observedCov^{-1}}^2\n\\end{equation*}\ncomes from the data-likelihood/observed density whereas the regularization term defined by\n\\begin{equation*}\n\t \\norm{\\param-\\initialMean}_{\\initialCov^{-1}}^2\n\\end{equation*}\ncomes from the prior/initial density.\nWe refer to this term as the Tikhonov regularization term.\n\nThe functional, $J(\\param)$, obtained from the updated density is written as a modification of the $T(\\param)$ function where the subtraction of\n\\begin{equation*}\n\t \\norm{Q(\\param)-Q(\\initialMean)}_{\\predictedCov^{-1}}^2\n\\end{equation*}\ncomes from the predicted density.\n\n\\vfill\n% \\pagebreak\n\\subsection{A Low-Dimensional Example}\\label{subsec:low-d-example}\nTo build intuition around the fundamental differences of MAP and MUD points, we consider an example where the linear QoI map is defined by $A=\\mat{cc}{1 & 1}$, i.e., the parameter space is 2-dimensional while the data space is 1-dimensional.\n\nIn this example, the parameters in the initial and observed densities are given by\n\\[\n\t\\initialMean = \\mat{cc}{0.25 & 0.25}^\\top, \\initialCov = \\mat{cc}{1 & -0.25 \\\\ -0.25 & 0.5}, \\ \\observedMean=1, \\text{ and } \\observedCov = \\mat{c}{0.25}.\n\\]\n\nThe top row of Fig.~\\ref{fig:regularization} shows contour plots in the parameter space for the data-mismatch term (left), Tikhonov regularization term (middle), as well as the functional $T(\\param)$ (right).\nConceptually, the regularization term is a radially symmetric function that penalizes parameters that are far away from the initial mean.\n\n\\begin{figure}\n  \\centering\n  \\begin{tabular}{|ccc|}\n    \\hline\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/data_mismatch_contour.png}}\n      {Data Mismatch}\n    &\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/tikonov_contour.png}}\n      {Regularization}\n    &\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/classical_solution.png}}\n      {Bayesian Posterior}\n    \\\\\n    \\hline\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/data_mismatch_contour.png}}\n      {Data mismatch}\n    &\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/consistent_contour.png}}\n      {Modified Regularization}\n    &\n      \\subf{\\includegraphics[width=0.3\\linewidth]{figures/contours/consistent_solution.png}}\n       {Updated Density}\n    \\\\\n    \\hline\n  \\end{tabular}\n\n  \\caption{Gaussian data mismatch over 2-D parameter space for a 2-to-1 linear map (left plots). Gaussian initial/prior lead to different regularization terms associated with updated/Bayesian PDFs (middle plots), which lead to different optimization functions (right plots) and parameter estimates that produce maximum PDF values for update/Bayesian PDF (red dot in right plots).}\n  \\label{fig:regularization}\n\\end{figure}\n\nThe bottom row of Fig.~\\ref{fig:regularization} shows contour plots in the parameter space for the data-mismatch term (left), modified regularization term (middle), as well as the functional $J(\\param)$ (right).\nHere, we see that the modified regularization term only penalizes the movement of parameters in certain directions away from the initial parameter mean.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{A Unifying Perspective and Closed Form Solutions}\\label{subsec:unifying-perspective}\n\nAssume that the QoI map, $Q$, now takes the slightly more general form\n\\begin{equation}\\label{eq:qoi_map}\nQ(\\param) = A \\param + \\mathbf{b}\n\\end{equation}\nwhere $\\mathbf{b} \\in \\RR^d$ may be viewed as a bias in the QoI map.\nThe inclusion of this term makes is relevant for drawing conclusions involving the data-constructed QoI maps presented in Section~\\ref{sec:data-maps}.\nUsing the same Gaussian distribution assumptions as described in Section~\\ref{subsec:Motivation}, we again identify the MAP and MUD points as the values that minimize the functionals $T(\\param)$ and $J(\\param)$, respectively, shown in Table~\\ref{tab:func_comparisons}.\n\n\nThe posterior covariance is formally given by\n\\begin{equation}\\label{eq:map_cov}\n\\Sigma_\\text{post} := ( A^\\top {\\Sigma}_\\text{obs}^{-1} A + \\initialCov^{-1} )^{-1}.\n\\end{equation}\nApplying the Woodbury matrix identity and~\\eqref{eq:predictCov}, we rewrite the posterior covariance as\n\\begin{equation}\\label{eq:map_cov_analytical}\n\\Sigma_\\text{post} = \\initialCov - \\initialCov A^\\top \\left[\\predictedCov + \\observedCov\\right]^{-1} A \\initialCov,\n\\end{equation}\nwhich allows us to interpret $\\Sigma_\\text{post}$ as a rank $d$ correction (or update) of $\\initialCov$.\nNote that $\\predictedCov + \\observedCov$ is invertible because it is the sum of two symmetric positive definite matrices.\nWith either version of $\\Sigma_\\text{post}$ given above, we rewrite the closed form expression for the MAP poing given in \\cite{Tarantola_book} as\n\\begin{equation}\\label{eq:map-point-analytical}\n\\param^{\\text{MAP}} = \\param_0 + \\Sigma_\\text{post} A^\\top \\observedCov^{-1} (\\observedMean - b - A\\param_0).\n\\end{equation}\n%where the posterior covariance is given by\n%\\begin{equation}\\label{eq:map_cov}\n%\\Sigma_\\text{post} = ( A^\\top {\\Sigma}_\\text{obs}^{-1} A + \\initialCov^{-1} )^{-1},\n%\\end{equation}\n%which is\n\n\nWe now derive an alternative representation of $J(\\param)$ to draw comparisons to the posterior covariance and MAP point.\nFirst, define\n\\begin{equation}\\label{eq:eff_reg}\n\tR := \\nolinebreak \\initialCov^{-1} - \\nolinebreak A^\\top \\predictedCov^{-1} A.\n\\end{equation}\nUsing this $R$, rewrite $J(\\param)$ as\n\\begin{equation}\\label{eq:dci-objective-alt}\nJ(\\param):= \\norm{\\observedMean - Q(\\param)}_{\\observedCov^{-1}}^2 + \\norm{\\param - \\param_0}_{R}^2.\n\\end{equation}\nIn this form, we identify $R$ as the {\\em effective regularization} in $J(\\param)$ due to the formulation in the data-consistent framework.\n\n\nObserve that if $d=p$, then, by the assumption that $A$ is full-rank, $A$ is invertible.\nIn this case, $R$ is the $p\\times p$ zero matrix and~\\eqref{eq:dci-objective-alt} reduces to the data-discrepancy term so that the MUD point is recognizable as the least squares solution, i.e., the point that minimizes the data-discrepancy term.\nMoreover, in this case we can immediately identify that $\\mudpt = A^{-1}(\\observedMean-b)$.\nThis is also evident from the perspective of the densities.\nSpecifically, in this case, $\\updated$ is defined by applying a change of variables formula to $\\observed$.\n%Subsequently, the MUD point corresponds exactly to the point that maximizes $\\observed$.\n\nSuppose instead that $d<p$ so that the inverse-problem is under-determined.\nIn this case, we observe that constructing $R$ only requires specification of the initial/prior density and the QoI map, i.e., $R$ may be defined prior to any collection of data on the QoI.\nSubsequently, we can interpret $J(\\param)$ as coming from a modified Bayesian inverse problem with a prior defined by a $N(\\param_0,\\Sigma_R)$ distribution where $\\Sigma_R=R^{-1}$.\nIn other words, the MUD and MAP points can both be interpreted as solutions to different Bayesian inverse problems.\n\nHowever, $\\Sigma_R$ is in fact a degenerative covariance, i.e., $R$ is not technically invertible.\nThis implies that $\\Sigma_R$ cannot be directly substituted in for $\\initialCov$ in~\\eqref{eq:map_cov_analytical} to define a closed form expression for $\\updatedCov$.\nWe therefore first substitute  $\\Sigma_\\text{post}$ and $\\initialCov^{-1}$ in~\\eqref{eq:map_cov_analytical} with $\\updatedCov$  and $R$, respectively, to get\n\\begin{equation}\n\t\\updatedCov := \\left(A^\\top \\observedCov^{-1} A + R\\right)^{-1}.\n\\end{equation}\nSince $R$ is not invertible, Woodbury's identity cannot be applied (yet).\nUsing~\\eqref{eq:eff_reg}, we can form\n\\begin{equation}\n\t\\updatedCov = \\left(A^\\top \\observedCov^{-1} A +  \\initialCov^{-1} - \\nolinebreak A^\\top \\predictedCov^{-1} A\\right)^{-1},\n\\end{equation}\nwhich is re-arranged as\n\\begin{equation}\n\t\\updatedCov = \\left(A^\\top \\left[\\observedCov^{-1} - \\predictedCov^{-1}\\right]A + \\initialCov^{-1}\\right)^{-1}.\n\\end{equation}\nRecall from Section~\\ref{subsec:Motivation} that the predictability assumption in this case is that the smallest eigenvalue of $\\predictedCov$ is larger than the largest eigenvalue of $\\observedCov$.\nThe roles are reversed when we consider the inverses of these matrices.\nSubsequently, $\\observedCov^{-1}-\\predictedCov^{-1}$ is a symmetric positive definite matrix and thus invertible.\nApplying the Woodbury identity yields\n\\begin{equation}\\label{eq:updated_cov_almost}\n\t\\updatedCov = \\initialCov - \\initialCov A^\\top\\left( \\left[\\observedCov^{-1} - \\predictedCov^{-1}\\right]^{-1} + \\predictedCov\\right)^{-1} A\\initialCov.\n\\end{equation}\nApplying Hua's identity and simplifying gives\n\\begin{equation}\\label{eq:Hua}\n\t\\left( \\left[\\observedCov^{-1} - \\predictedCov^{-1}\\right]^{-1} + \\predictedCov\\right)^{-1} = \\predictedCov^{-1}\\left[\\predictedCov - \\observedCov\\right]\\predictedCov^{-1}.\n\\end{equation}\nSubstituting~\\eqref{eq:Hua} into~\\eqref{eq:updated_cov_almost} gives\n\\begin{equation}\\label{eq:updatedCov_final}\n\t\\updatedCov = \\initialCov - \\initialCov A^\\top \\predictedCov^{-1}\\left[\\predictedCov-\\observedCov\\right]\\predictedCov^{-1}A\\initialCov.\n\\end{equation}\nWe can now modify the expression for the MAP point given in~\\eqref{eq:map-point-analytical} by substituting $\\updatedCov$ for $\\Sigma_\\text{post}$ to write the MUD point that minimizes $J$ as\n\\begin{equation}\\label{eq:mud-point-analytical-alt}\n\\param^{\\text{MUD}} = \\param_0 + \\updatedCov A^\\top \\observedCov^{-1} (\\observedMean - b - A\\param_0).\n\\end{equation}\nSubstituting~\\eqref{eq:updatedCov_final} into~\\eqref{eq:mud-point-analytical-alt} and simplifying, we have\n\\begin{equation}\\label{eq:mud-point-analytical-final}\n\t\\mudpt = \\param_0 + \\initialCov A^\\top \\predictedCov^{-1}(\\observedMean - b - A\\param_0).\n\\end{equation}\n\nComparing~\\eqref{eq:mud-point-analytical-final} to~\\eqref{eq:map-point-analytical}, we\nsee that the MUD point does not depend on the observed covariance whereas the MAP point does.\n%Both $\\updatedCov$ and $\\Sigma_\\text{post}$ depend on $\\observedCov$.\n%Conceptually, this implies that the MUD point is not directly sensitivity to the amount of noise in observational data, but the noise directly impacts $\\updatedCov$ in the data-informed directions.\n%However, when $\\observedMean$ is estimated by noisy data, this will impact the MUD and MAP points in similar ways.\nMoreover, applying $Q$ to \\eqref{eq:mud-point-analytical-final} and substituting accordingly reveals that $Q(\\mudpt) = \\observedMean$.\n\nOverall, this motivates the MUD point as an \\emph{alternative parameter estimate} with predictive accuracy and properties directly correlated to the relationship between $\\observedMean$ and the true signal for which noisy data are generated.\n\nThese ideas are explored further in Section~\\ref{sec:high-dim-linear-example} and utilized in the analysis of QoI maps constructed from noisy measurement data associated with a true parameter value in Section~\\ref{sec:data-maps}.\nWe end this section by summarizing the above results in the following theorem stating the existence and uniqueness of a MUD point for the linear Gaussian case.\n\n\\begin{thm}\\label{thm:MUD_existence_uniqueness}\nSuppose  $Q(\\param)=A\\param+b$ for some full rank $A\\in\\RR^{d\\times p}$ with $d\\leq p$ and $b\\in\\RR^d$.\nIf $\\initial \\sim N(\\param_0,\\initialCov)$, $\\observed\\sim N(\\observedMean,\\observedCov)$, and the predictability assumption holds, then\n\\begin{enumerate}[(a)]\n\\item There exists a unique parameter, denoted by $\\mudpt$, that maximizes $\\updated$.\n\\item $Q(\\mudpt) = \\observedMean$.\n\\item If $d=p$, $\\mudpt$ is given by $A^{-1}$. If $d<p$, $\\mudpt$ is given by~\\eqref{eq:mud-point-analytical-final} and the covariance associated with this point is given by~\\eqref{eq:updatedCov_final}.\n\\end{enumerate}\n\\end{thm}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Higher-Dimensional Linear Gaussian Examples}\\label{sec:high-dim-linear-example}\n\n%For under-determined QoI maps, $\\paramref$ is un-recoverable due to the set-valued nature of the set $Q^{-1}(\\observedMean)$.\n%While the incorporation of prior beliefs through the use of an initial or prior density allows us to determine a single ``best'' estimate of $\\paramref$, this is not necessary.\n%For instance, the least squares (LS) solution produces a single point estimate of $\\paramref$ by enforcing a requirement of minimal norm.\n%The LS solution will lie at the intersection of hyper-balls centered at the origin and the set-valued hyperplanes associated with $Q^{-1}(\\observedMean)$, which is visible in Figure~\\ref{fig:regularization} in 2-dimensions.\n\n%By contrast, the Tikhonov-regularized solution selects a point that is biased by an initial covariance on $\\Lambda$.\n%The data-consistent solution is an update to the initial mean in this same direction but always lies on the contour $Q^{-1}(\\observedMean)$.\n%The trouble is, none of these regularization approaches actually guarantee that in under-determined problems, the unique solutions that are selected are close to $\\paramref$.\n\n%There may or may not be good reasons for us to impose a requirement on the norm of the solution.\n%If there are physical reasons relating to the magnitude of parameters involved, then the least-squares solution may very well be more accurate than the other two.\n%However, not every problem lends itself to such structure.\n%By contrast, if the initial beliefs are well-informed by the experience of the modeling team, it is possible that the MUD or MAP point out-perform Least-Squares.\n%In situations where the beliefs are already really good (the mean is near the true value), and the data is really bad, the MAP solution may (by design) out-perform the MUD solution.\n%If some beliefs are correct but others are not (the covariance incorporates some incorrect directions), the MUD point may dramatically out-perform the MAP point, especially in situations with few available measurements and strongly-held initial beliefs.\n\n%Below we demonstrate with a pair of complementary examples involving linear maps which leverage the analytical equations presented in the previous section.\n%We show that regardless of how well-informed your beliefs are, the convergence rate of the MUD solutions as more data is incorporated\\---either by dimension or rank)\\---will match those of the Least-Squares solutions.\n%Moreover, the MUD solutions are not sensitive to scaling of the initial covariance (how strongly initial beliefs are held), the way that the MAP solution is.\n%This provides a strong motivating factor for the consideration of the data-consistent approach within the standard set of solution methods available to scientists and modelers who seek to perform parameter-identification.\n\n%\\subsection{MUD and MAP points and generalized contours}\\label{subsec:gen_contours}\n\nWe first describe the relationship of MUD, MAP, and least squares estimates to the set-valued inverses of $Q$ in order to establish a conceptual framework for interpreting the numerical results that follow.\nWhile this discussion is somewhat abstract, we refer to Figure~\\ref{fig:regularization} to make these ideas more clear.\n\nThe MUD point exists on the generalized contour defined by $Q^{-1}(\\observedMean)$.\nWe say generalized contour in this case because if $A$ is a $p$-to-$d$ full rank linear map with $d<p$, then $Q^{-1}(\\observedMean)$ exists as a $(p-d)$-dimensional linear hyperplane in $\\pspace$.\n\nThis means that the MUD point retains the ``predictive precision'' of a least squares solution to the inverse problem (i.e., a parameter that minimizes the data-mismatch term $\\norm{\\observedMean - Q(\\param)}_{\\observedCov^{-1}}^2$) while incorporating the flexibility of prior beliefs in directions not informed by the QoI.\nThis is illustrated in the bottom right plot of Figure~\\ref{fig:regularization}.\nFor under-determined or ill-conditioned problems, this suggests that ``good'' prior beliefs may be used to produce a MUD point that is more accurate than a least squares solution.\nThis is explored in the following examples involving high-dimensional linear maps.\n\nBy contrast, the MAP point exists on a line connecting the initial mean, $\\param_0$, and the generalized contour defined by $Q^{-1}(\\observedMean)$.\nSubstituting \\eqref{eq:map_cov_analytical} into \\eqref{eq:map-point-analytical}, we see that this line is in the direction of the orthogonal nullspace of the image of $A$ under $\\initialCov$; i.e., $\\mathcal{N}(\\initialCov A)^\\perp$.\nIn fact, this line intersects the generalized contour defined by $Q^{-1}(\\observedMean)$ precisely at the MUD point.\nIf one parameterizes the line between $\\param_0$ and $\\param^{\\text{MUD}}$, then one can also identify $\\param^{\\text{MAP}}$ as a convex sum of these two points.\nThe weights of this convex sum, which determine the position of the MAP point on this line, are determined by the ``precision of data'' (i.e., on $\\observedCov$) and the ``strength of prior beliefs'' (i.e., on $\\Sigma_{\\text{init}}$).\nThis is seen by comparing the location of the MAP point in the top right plot of Figure~\\ref{fig:regularization} to the line segment connecting the initial mean to the MUD point in the bottom right plot of this same figure.\nThe impact of this is also explored in the following examples.\n\n\n\\begin{figure}[htbp]\n  \\includegraphics[width=0.475\\linewidth]{figures/lin/lin-dim-cov-convergence}\n  \\includegraphics[width=0.475\\linewidth]{figures/lin/lin-rank-cov-convergence}\n\\caption{\n\tRelative errors between $\\paramref$ and (i) the least squares solution obtained through {\\tt numpy}'s {\\tt linalg.pinv} module, (ii) the closed-form solution for the MUD point given in Eq~\\eqref{eq:mud-point-analytical-final}, and (iii) the MAP point.\n  (Left): Error for increasing dimensions of $D$ for $A$ taken to be a Gaussian Random Map.\n  (Right): Error for increasing row-rank of $A$, generated with Gaussian vectors and a SVD.\n}\n\\label{fig:lin-error}\n\\end{figure}\n\n\n\\subsection{Impact of Output Dimension}%: Random $\\RR^{k\\times 100}$ matrix for $k=1,2,\\ldots,100$}\n\n\n%Here, we demonstrate how the various estimates of a true parameter $\\paramref$ are impacted by the number of available QoI.%, especially in problems where the dimension of $\\pspace$ is high.\n%As more QoI are incorporated, the expectation is that the accuracy of $\\paramref$ improves as well.\n%In the following example, we demonstrate that the MUD point does indeed perform this way, and compare its ability to approximate $\\paramref$ against two other popular solution methods: the least-squares solution and Tikhonov-regularized solution, i.e. the MAP point.\n\nWe consider QoI defined by $A\\param+\\mathbf{b}$ for $A\\in\\RR^{k\\times 100}$ where $k=1,2,\\ldots,100$ to demonstrate how the various estimates of a true parameter $\\paramref$ are impacted by the number of available QoI.\nTo generate the matrices, we first generate $10,000$ independent identically distributed (i.i.d.) random numbers from a $N(0,1)$ distribution that are arranged into a reference $\\RR^{100\\times 100}$ matrix.\n\nThe same distribution is also used for generating the components of the 100-dimensional vectors defining a reference bias vector $\\mathbf{b}$ and reference parameter $\\paramref$.\nA multivariate Gaussian distribution is used for the initial density, with zero mean and $\\initialCov$ chosen as a diagonal covariance with random entries drawn from $U[0.5, 1.5]$ and sorted in descending order. %\\footnote{A random seed of $271$ is used so that the covariance in this example matches that in the following, where we perform a similar study but vary the row-rank of $A$ instead of the dimension.}\n%We then attempt to recover $\\paramref$ with the three solution methods: MUD, MAP, and Least Squares, leveraging analytical solutions for all three since we have posed a linear problem under Gaussian assumptions.\nThe prior density is also a zero mean multivariate Gaussian distribution.\nHowever, to demonstrate the impact of the strength of prior beliefs on the MAP point, we choose the prior covariance to be $\\alpha\\initialCov$  for $\\alpha=0.001, 0.01, 0.1, $ and $10$.\nHere, smaller values of $\\alpha$ correspond to a ``stronger'' belief in the prior since the prior density becomes more concentrated near the prior mean.\n\n\nTo study the impact of dimension on the MUD, MAP, and least squares estimates, we solve a\nsequence of inverse problems by truncating the rows of the reference matrix and bias vector.\n%\n%We scale the initial covariance $\\initialCov$ by a factor $\\alpha$ for $\\alpha = 0.01, 0.1, 1, 10 $ to simulate varying levels of attachment to the specification of the initial density.\nThe results are summarized in the left plot of Figure~\\ref{fig:lin-error}, which shows convergence towards $\\paramref$ for all the problems considered with the exception of several MAP estimates corresponding to strongly-held beliefs in the prior.\n\n\n%We demonstrate that the MUD solution retains the accuracy of least squares solutions while simultaneously offering the flexibility of specifying initial beliefs.\n%Normally in order to incorporate such beliefs, one would perform Tikhonov regularization, usually with the inclusion of a hyper-parameter which scales the additional parameter-space norm in the objective function.\n%Mathematically, this scaling factor applied to the norm is equivalent to scaling the matrix representation of the initial (prior) covariance.\n%Increasing this scaling factor is interpreted as having less confidence in these initial assumptions.\n%Conversely, decreasing it is equivalent to putting more emphasis on the prior beliefs than the evidence provided by the data, which causes MAP solutions to drift away from the solution contour (equivalence class) to which $\\paramref$ belongs.\n%The MUD point, by contrast, is not impacted by such a scaling of the initial covariance, providing \\emph{consistent} solutions which demonstrate levels of accuracy that MAP points only exhibit for larger values of scaling factors.\n\n%To illustrate this with a concrete example, we consider the problem $A\\param + b = y$ by first generating a square matrix $A$ of dimension $100$ with standard Gaussian entries.\n%The same distribution is used for the components of vector $b$ and $\\paramref$ as well.\n%A Gaussian distribution is used for the initial density, with mean at the origin (to complement the structure imposed by the least-squares framework), and a diagonal covariance with entries drawn from $U[0.5, 1.5]$ and sorted in descending order.\\footnote{A random seed of $271$ is used so that the covariance in this example matches that in the following, where we perform a similar study but vary the row-rank of $A$ instead of the dimension.}\n%We then attempt to recover $\\paramref$ with the three solution methods: MUD, MAP, and Least Squares, leveraging analytical solutions for all three since we have posed a linear problem under Gaussian assumptions.\n%To study the impact of dimension, we solve inverse problems for a sequence of maps generated by truncating the rows of $A$.\n%Finally, several scalings of the initial covariance are chosen to simulate a common procedure in the Bayesian literature: hyper-parameter optimization.\n%We scale the initial covariance $\\initialCov$ by a factor $\\alpha$ for $\\alpha = 0.01, 0.1, 1, 10 $ to simulate varying levels of attachment to the specification of the initial density.\n%The results are summarized in Figure~\\ref{fig:lin-error}, which shows convergence towards $\\paramref$ for all the problems considered with the exception of several Tikhonov solutions corresponding to strongly-held beliefs in initial assumptions about parameters.\n\nWe note that the MUD solution is the same for all choices of $\\alpha$ and corresponds to the same level of accuracy that the MAP point achieves when $\\alpha$ is chosen to be large.\nIn other words, the MUD point is not impacted by a scaling of the initial covariance, providing \\emph{consistent} solutions which demonstrate levels of accuracy that MAP points only exhibit for larger values of scaling factors.\n%The accuracy of the Tikhonov solution is highly dependent on the specification of $\\initialCov$ and in some cases leads to nearly-divergent scenarios.\n\nOf interest is also that the MUD point can sometimes out-perform the least squares estimate while generally achieving similar levels of accuracy.\nThis suggests that the MUD point has several favorable qualities.\nNot only is it robust to the specification of prior assumptions, but it manages to offer the flexibility of incorporating good prior specifications without paying the additional cost of hyper-parameter optimization (i.e., choosing an appropriate $\\alpha$) that would be required for the MAP estimates to achieve comparable results.\n\nWhile omitted in the interest of space, if $\\initialCov$ is chosen as $\\alpha I$, where $I$ denotes the identity matrix of appropriate dimensions, then the MUD point will always agree with the least squares estimate.\nTaking these results together, this implies that only a good ``relative spatial structure'' of prior beliefs is required to improve the MUD point's accuracy over both MAP and least squares estimates.\n\n\n\\subsection{Impact of Rank: One Hundred (Deficient) $\\RR^{100 \\times 100}$ matrices}\n\nHere, we investigate whether the previous dimension-dependent example extend to matrices $A$ which are of a fixed dimension but varying rank.\nThis is of interest in applications where many QoI are available to construct an operator but a great deal of redundancy may be present in the data collected, and feature-engineering new quantities is somehow prohibitive (perhaps due to gradient estimation).\n\n%The theory implies that a full-rank operator $A$ whose input and output dimensions are equal would ``turn off'' the data-consistent regularization, since the predicted covariance $\\predictedCov = A^T \\initialCov A$ is invertible.\n\nThe rank of $A$ corresponds to the number of unique directions of information present in the operator, i.e., how many directions in the parameter space are informed by the QoI map.\n%, in other words, the mutual-distinctness of the information in the Quantities of Interest.\nThe operators in the previous example were all full rank, so the dimension of each map also corresponded to the rank of $A$.\nWhen $A$ is rank-deficient, $\\predictedCov$ is non-invertible, so we must modify the form of \\eqref{eq:mud-point-analytical-final} to substitute a pseudo-inverse for the predicted covariance.\n% we are curious to see if the same behaviors are observed on this related problem which violates one of the stated assumptions in the theory presented in section [TK - section with theory in it].\n\n\nIn this example, the dimension of the data space remains fixed at $d=100$ across all experiments.\nHowever, we sequentially increase the row-rank of $A$ from $r=1, \\ldots, 100$.\nTo control the rank of $A$, we first construct a reference $\\RR^{100\\times 100}$ matrix as in the previous example using 10,000 i.i.d. $N(0,1)$ random numbers.\nWe then compute a singular value decomposition of this reference matrix of the form $USV^\\top$ and construct 100 rank-1 matrices of the form $A_i=\\mathbf{u}_i s_i \\mathbf{v}_i^\\top$ for $i=1,\\ldots,100$ where $\\mathbf{u}_i$ and $\\mathbf{v}_i$ denote the $i$th columns of $U$ and $V$, respectively and $s_i$ denotes the $i$th singular value.\nThen, we analyze the impact of $A = \\sum_i^r A_i$ for $r=1,\\ldots,100$.\n%\\footnote{We validated by alternatively generating rank-1 matrices from random Gaussian vectors $a_i \\in \\RR^100$ to form $A_i = a_i a_i^T$, and included assertion checks in code to validate correct rank with our generating functions.}.\nAside from the differing construction of $A$, the rest of the choices involved in the experiment ($\\paramref$, the reference bias vector, and the distributions involved) is identical to the previous example.\n\nIn the right plot of Figure~\\ref{fig:lin-error}, we\n%super-impose the pseudo-inverse solution in light blue and see that it matches the black line associated with the MUD error much of the time.\nagain find that the MUD point is generally as accurate as the least squares estimate, but incorporates an initial description of uncertainty, which may allow it to outperform the least squares estimate.\nAlso, we again see that the MAP estimates are impacted by the strength of prior beliefs.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Data-constructed QoI maps and MUD points}\\label{sec:data-maps}\n\nSuppose there exists $d$ measurement devices for which repeated noisy data are obtained.\nFor each $1\\leq j\\leq d$, denote by $\\mathcal{M}_j(\\paramref)$ the $j$th measurement device, and denote by $N_j$ the number of noisy data obtained for $\\mathcal{M}_j(\\paramref)$.\nLet $d_{j,i}$ denote the $i$th noisy datum obtained for the $j$th measurement where $1\\leq i\\leq N_j$.\nTo simplify the presentation and some of the resulting notation, we assume an unbiased additive error model for the measurement noise with independent identically distributed (i.i.d.) Gaussian errors so that\n\\begin{equation}\\label{eq:obs_data_error}\n\td_{j,i} = M_j(\\param^\\star) + \\xi_i, \\ \\xi_i\\sim N(0,\\sigma_j^2), \\ \\ 1\\leq i\\leq N_j.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{The Weighted Mean Error Map}\n\nWe now construct a $d$-dimensional vector-valued map from data obtained on the $d$ measurement devices.\nThe data-defined QoI map we consider in this work is referred to as the weighted mean error (WME) map, denoted by $Q_\\text{WME}(\\param)$ with $j$th component, denoted by $Q_{\\text{WME},j}(\\param)$, given by\n\\begin{equation}\\label{eq:qoi_WME}\n\tQ_{\\text{WME},j}(\\param) := \\frac{1}{\\sqrt{N_j}} \\sum_{i=1}^{N_j} \\frac{M_j(\\param)-d_{j,i}}{\\sigma_j}.\n\\end{equation}\n%%\\begin{equation}\\label{eq:qoi_WME}\n%%\tQ_{(\\param,\\xi) := \\frac{1}{\\sqrt{S}} \\sum_{j=1}^S \\frac{M_j(\\param)-d_j(\\xi_j)}{\\sigma_j}.\n%%\\end{equation}\nBy a substitution of \\eqref{eq:obs_data_error} into \\eqref{eq:qoi_WME} and rationalizing the denominator of the multiplicative factor, $Q_{\\text{WME},j}(\\paramref)$ is identified as the sample average of $N_j$ random draws from an i.i.d.~$N(0,N_j)$ distribution.\nBy assumption, the observed data are generated according to the fixed true physical parameter vector given by $\\paramref$ in \\eqref{eq:obs_data_error}.\nSubsequently, each component of $Q_\\text{WME}(\\paramref)$ is a random draw from an $N(0,1)$ distribution.\nTherefore, with this choice of data-defined QoI map, we specify $\\observed$ as a $N(\\mathbf{0}_{d\\times 1},\\mathbf{I}_{d\\times d})$ distribution.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Analysis of MUD point for the WME map}\\label{sec:MUD_analysis}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nBelow, we consider issues of existence, uniqueness, and convergence of $\\mudpt$ for the WME map under certain assumptions.\nIn~\\ref{sec:conclusions}, we provide some remarks on how we plan to generalize this analysis in future work.\n\n\nFor each $1\\leq j\\leq d$, assume that the observable maps $M_j$ are linear maps of $\\param$ (affine maps require minor modifications to the results below).\nFor notational simplicity below, assume that $M_j$ is written explicitly as a $1\\times p$ row vector and that the $d$-vectors form a linearly independent set.\nThen, it is possible to rewrite $Q_{\\text{WME}}(\\param)$ as\n\\begin{equation}\n\tQ_\\text{WME}(\\param) = A(\\mathbf{N})\\param + b(\\mathbf{N}),\n\\end{equation}\nwhere the $j$th component of $\\mathbf{N}\\in\\RR^d$ is given by $N_j$ and the $j$th row of $A(\\mathbf{N})\\in\\RR^{d\\times p}$ is given by\n\\begin{equation}\n\t\\frac{1}{\\sqrt{N_j}} \\sum_{i=1}^{N_j} \\frac{M_j}{\\sigma_j} = \\frac{\\sqrt{N_j}}{\\sigma_j}M_j,\n\\end{equation}\nand the bias vector, $\\mathbf{b}(\\mathbf{N})\\in\\RR^d$, is defined by the data, with $j$th component, denoted by $\\mathbf{b}_j$, given by\n\\begin{equation}\n\t\\mathbf{b}_j(\\mathbf{N}) = -\\frac{1}{\\sqrt{N_j}} \\sum_{i=1}^{N_j} \\frac{d_{j,i}}{\\sigma_j}.\n\\end{equation}\nSince $A(\\mathbf{N})\\initialCov A(\\mathbf{N})^\\top$ defines a predicted covariance, and the observed covariance is the identity map, the predictability assumption is immediately satisfied if each diagonal component of the predicted covariance is significantly greater than $1$.\n\nThe off-diagonal components of the predicted covariance (which are dictated in large part by the structure of the measurement operators $M_j$) dictate how much larger than $1$ each diagonal component must be to ensure the predictability assumption holds.\nHowever, we demonstrate below that this will happen once a minimum number of data points $N_\\text{min}$ are obtained for each measurement.\n\nFirst, observe that the $j$th diagonal component of the predicted covariance matrix is given by the predicted variance associated with using the scalar-valued map $Q_{\\text{WME},j}$.\nThen, the associated predicted variance is given by\n\\begin{equation}\n\t\\frac{N_j}{\\sigma_j^2} M_j\\initialCov M_j^\\top\n\\end{equation}\nSince $\\initialCov$ is assumed to be non-degenerative and $M_j$ is a non-trivial row vector, this predicted variance grows linearly with $N_j$.\nIn other words, the $j$th diagonal component of the predicted covariance has the form $\\beta_j N_j$ for some $\\beta_j>0$.\nLet $N_{\\text{min},j}$ denote the minimum $N_j$ for $1\\leq j\\leq N$ necessary to make the $j$th diagonal components sufficiently large so that the smallest eigenvalue of the predicted covariance is larger than $1$ (which is the repeated eigenvalue for the observed covariance).\n\nThe following result is now an immediate consequence of Theorem~\\ref{thm:MUD_existence_uniqueness},\n\n\\begin{corollary}\\label{cor:MUD_wme}\nIf $\\initial \\sim N(\\param_0,\\initialCov)$ and data are obtained for $d$ linearly independent measurements on $\\pspace$ with an additive noise model with i.i.d. Gaussian noise for each measurement, then there exists a minimum number of data points obtained for each of the measurements such that there exists a unique $\\mudpt$ and $Q_\\text{WME}(\\mudpt) = 0$.\n\\end{corollary}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{MUD points for nonlinear maps: Examples}\\label{sec:Parameter-identification}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nWe now use MUD points as parameter estimates for nonlinear data-constructed maps using simulated noisy temporal and spatial data associated with solutions to differential equations.\nThe previously derived closed form expressions for $\\mudpt$ do not apply in these examples.\nInstead, in each example we use a fixed set of i.i.d.~samples drawn from the initial density to approximate the updated density and subsequently choose the sample that maximizes this approximation.\nFuture work will consider how to leverage more sophisticated optimization approaches for estimating $\\mudpt$, e.g., through iterative quasi-Newton approaches based on repeated approximate linearizations that can exploit the closed form expressions for $\\mudpt$.\n%that are iteratively improved upon, e.g., by combining this work with a quasi-Newton type approach.\n\nThe two examples below have distinct points of emphasis.\nThe first example focuses on the improved accuracy and precision of scalar $\\mudpt$ estimates as more data are incorporated into the construction of $Q_\\text{WME}$.\nThe second example focuses on how the utilization of subsets of the data into different components of a vector-valued $Q_\\text{WME}$ can improve the estimates across multiple components of a $\\mudpt$ estimate for a parameter vector.\nDespite these differences, both examples share the following details.\n\\begin{itemize}\n  \\item Sets of i.i.d.~samples from the initial densities are used to both approximate the predicted density (and thus the updated density) and to form a discrete space in which to search for the MUD point.\n  \\item A reference parameter is chosen and used to establish a (noiseless) reference solution (in space or time).\n  \\item An i.i.d. additive noise model with $\\xi \\sim N(0,\\sigma^2)$ is used to perturb the reference temporal and spatial solutions.\n  \\item Since the magnitude of solutions in both examples is $\\mathcal{O}(1)$, noise variances are chosen so that $\\mathbb{P}( \\abs{\\xi} < \\tau ) = 99\\%$, with $\\tau=0.1$. In other words, we simulate an ``engineering accuracy'' by permitting measurement noise to vary by  approximately 10\\% of the signal magnitude.\n%  \\item Vertical axes on convergence plots represent the absolute error between $\\paramref$ and $\\mudpt$, with bounds chosen to be fixed across plots within a figure.\n%  \\item Errors are reported as the average over 20 sets of independently generated noisy data.\n%  \\item To estimate convergence rates, we compute first-order linear regressions for the logarithm (base 10) of the mean and variances for the absolute error. The coefficient for the mean in the regression appears as an annotation in the figures.\n\\end{itemize}\n\n\\FloatBarrier\n\n\\subsection{ODE Example}\\label{subsec:ode-example}\nConsider the exponential decay problem with uncertain decay rate $\\param$:\n$$\n\\begin{cases}\n\\frac{\\partial u}{\\partial t} & = \\param u(t), \\ 0<t\\leq 3, \\\\ u(0) &= 0.75,\n\\end{cases}\n$$\nwith solution\n\\begin{equation}\nu(t;\\param) = u_0\\exp(-\\param t), \\; u_0 = 0.75 ,\n\\end{equation}\nand measurements begin at $t=1$.\n\nThe initial uncertainty in the decay rate is given by a uniform density on $\\param \\in \\Lambda = (0, 1)$, and $10,000$ samples from this density are used to estimate the push-forward and updated densities as well as the MUD points.\nNoisy data are simulated over the interval $t \\in [1,3]$ assuming a $100$Hz measurement sensor.\nAn example of this setup is shown in Figure~\\ref{fig:ode-reference}, with the solid line representing the ``true'' signal obtained by evaluating the solution for $\\paramref = 0.5$, and a particular realization of noisy data shown as perturbed points around it.\n\n\\begin{figure}[htb]\n  \\includegraphics[width=\\linewidth]{figures/ode/ode_20_reference_solution.png}\n  \\includegraphics[width=\\linewidth]{figures/ode/ode_200_reference_solution.png}\n  \\caption{Curves for exponential decay model with various decay coefficients. Dashed curves denote 99\\% probability intervals for noise. The true signal is shown in solid black.\n Curves associated with the MUD estimates for the decay coefficient computed from 20 trials are shown in light red.\n Both sets of these curves encompass the true signal for $N=20$ (top plot) and $N=200$ (bottom plot) data points.\n The light red curves are almost indistinguishable in the bottom plot as they all lie nearly on the true signal which demonstrates the overall reduction in variance in MUD estimates around the true signal when using $N=200$ data points.\n  }\n  \\label{fig:ode-reference}\n\\end{figure}\n\nFor 20 different realizations of $N=5, 10, 15, 20, 25, 50, 100, \\text{ and } 200$ noisy measurement data, we construct $Q_\\text{WME}$ with $u(t;\\param)$ replacing $M_j(\\param)$ in~\\eqref{eq:qoi_WME}, estimate $\\mudpt$, and analyze the statistical error in these estimates of $\\paramref$.\nIn the left plot of Figure~\\ref{fig:ode-convergence}, we observe that as more data are used that the accuracy (defined by the mean error between $\\mudpt$ and $\\paramref$) decreases.\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[width=0.45\\linewidth]{figures/ode/ode_convergence_mud_obs_mean.png}\n  \\includegraphics[width=0.45\\linewidth]{figures/ode/ode_convergence_mud_obs_var.png}\n  \\caption{The mean (left) and variance (right) of absolute errors in MUD estimates as a function of the number of data points used. These statistics are computed over 20 trials.\n  }\n  \\label{fig:ode-convergence}\n\\end{figure}\n\nThe right plot demonstrates that the precision (i.e., the variance in the error) is also reduced by using more data.\nThese results are also visualized in the plots of Figure~\\ref{fig:ode-reference} where the distinct red curves in the top plot are the signals associated with the 20 $\\mudpt$ estimates associated with the 20 independent trials of $N=20$ noisy measurements.\nHowever, in the bottom plot, these $20$ red curves are fairly indistinguishable to the naked eye from the true signal when using $N=200$ noisy measurements.\nIn Appendix~\\ref{ext:ode-example}, we repeat this problem with measurement equipment that operates at double the temporal frequency and show how this change impacts the MUD solutions.\n\n% \\FloatBarrier\n\\vfill\n\\subsection{PDE Example}\\label{subsec:pde-example}\n\nIn this problem, the uncertain model parameter is now described by an unknown function defining the boundary data to a stationary PDE.\nThe focus is on demonstrating that a vector-valued QoI can be constructed from noisy data to produce a MUD point that more accurately reconstructs features of the unknown function.\nAs described below, there is an intuitive way to separate the spatial data to construct the distinct components of the vector-valued QoI map.\nWhile beyond the scope of this work, a future work will consider how to incorporate clustering analysis on the data for less obvious cases where we seek to determine which data points should be utilized to construct the various components of a vector-valued QoI map.\nIn the interest of clarity, we present representative results for a fixed finite-dimensional representation of the parameter space and forgo the more complicated convergence analysis that requires increasing both the number of data available as well as the dimension of the parameter space.\n\nConsider the Poisson problem:\n\\begin{equation}\\label{eq:pde-equation}\n\\begin{cases}\n\\hfill -\\nabla \\cdot \\nabla u &= f(x), \\quad\\text{on } x\\in \\Omega, \\\\\n\\hfill u &= 0, \\quad\\text{ on } \\Gamma_T \\cup \\Gamma_B, \\\\\n\\hfill \\frac{\\partial u}{\\partial \\mathbf{n}} &= g(x_2), \\quad\\text{ on } \\Gamma_L, \\\\\n\\hfill \\frac{\\partial u}{\\partial \\mathbf{n}} &= 0, \\quad\\text{ on } \\Gamma_R,\n\\end{cases}\n\\end{equation}\nwhere $x=(x_1, x_2) \\in \\Omega = (0,1)^2$ is the spatial domain; $\\Gamma_T$, $\\Gamma_B$, $\\Gamma_L$, and $\\Gamma_R$, denote the top, bottom, left, and right boundaries of this domain, respectively, and $\\frac{\\partial u}{\\partial \\mathbf{n}}$ denotes the usual outward normal derivative.\nThe forcing function $f$ is taken to be $10\\exp\\left ( \\norm{x - 0.5}^2 / 0.02 \\right )$.\n\nHere, we assume that $g(x_2)$ is unknown, and the goal is to use noisy data to estimate this unknown boundary data.\nIn other words, the parameter $\\param$ now represents an uncertain function.\nTo generate the noisy data, we use a reference $g(x_2)\\propto x_2^2(x_2-1)^5$ with a constant of proportionality chosen to produce a minimum of $-3$ at $x_2=\\frac{2}{7}$.\nThen, we compute a reference solution using piecewise-linear finite elements on a triangulation of a $36\\times36$ mesh.\nRandom noise is then added to every degree of freedom of this reference solution, and the spatial data are subsequently computed from a fixed set of 100 randomly placed sensors in the subdomain $(0.05, 0.95)^2 \\subset \\Omega$.\nThis process is repeated $20$ times to study the subsequent variation in MUD points due to different realizations of noisy data.\nSee the plot of Figure~\\ref{fig:pde-Q} for a representative noisy response surface and location of spatial data used across all 20 trials.\n\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=0.65\\linewidth]{figures/pde-highd/pde-highd_sensors_D2.png}\n\\caption{\nA representative noisy perturbation of the reference response surface. Locations of the randomly chosen spatial data used to construct both $Q_{1D}$ and $Q_{2D}$ are shown as black and red dots.\n}\n\\label{fig:pde-Q}\n\\end{figure}\n\n%We simulate measurement noise as described in the preamble to Sec.~\\ref{sec:Parameter-identification} and use this data to construct a QoI map with which we solve a parameter identification problem which characterizes $g$.\nTo construct a finite-dimensional parameter space describing the initial uncertainty of $g(x_2)$, we first assume that it is known that $g$ is non-positive and bounded below by $-4$.\nWe further assume that $g$ is smooth enough to be reasonably approximated by a piecewise-linear continuous spline with four knots and that $g(0)=g(1)=0$.\nThus, the uncertainty is described by the values of the splines at the two interior knot points chosen as the equispaced points $1/3$ and $2/3$.\nThis defines a finite-dimensional parameter space described by $\\pspace = [0,-4]^2$.\nWe generate $1000$ samples from an initial uniform density on $\\pspace$ to (1) generate random spline functions and compute the (noise-free) data from solutions associated with these splines; and (2) estimate the push-forward and updated densities along with the MUD estimate of $g(x_2)$.\nThe randomly generated splines are shown in the left plot of Figure~\\ref{fig:pde-MUD} along with the reference $g$ and its interpolant on these spline knots.\nThese same $1000$ samples are used across all $20$ realizations of random noisy data.\n\n\n\\begin{figure}[htbp]\n\\centering\n    \\includegraphics[width=0.325\\linewidth]{figures/pde-highd/pde-highd_init_D2.png}\n    \\includegraphics[width=0.325\\linewidth]{figures/pde-highd/pde-highd_pair_D2-1_m100.png}\n    \\includegraphics[width=0.325\\linewidth]{figures/pde-highd/pde-highd_pair_D2-2_m100.png}\n\\caption{\nIn the left plot, the reference $g(x_2)$ is shown as the solid black curve with its interpolant onto the spline basis shown as a dotted red curve.\nThe dashed blue line represents the sample from parameter space which most closely predicts noiseless data, which we refer to as the projection of $g$.\nThe purple curves in the center and right plots show the variability in MUD estimates of $g(x_2)$ for the 20 different realizations of noisy data.\nThe center plot uses $Q_{1D}$ and the right plot uses $Q_{2D}$ to construct the MUD estimates.\n}\n\\label{fig:pde-MUD}\n\\end{figure}\n\n\nTwo separate types of data-constructed $Q_\\text{WME}$ maps are constructed from the data.\nThe first map, which for simplicity we denote by $Q_{1D}$, uses all 100 spatial data points to construct a scalar-valued QoI map.\nGiven the location of the spline knots, a second map, which for simplicity we denote by $Q_{2D}$, uses the data points above (below) the mid-line of the spatial domain to form the first (second) component of the 2-dimensional vector-valued QoI map.\nThis separation of spatial data is illustrated in the top-left plot in Figure~\\ref{fig:pde-Q}.\nFor reference, the interpolant of the reference $g(x_2)$ on the spline basis is also shown in these plots.\nThe sample from $\\pspace$ which best predicts the hundred noiseless measurements (in 2-norm) is also shown, referred to as the projection of $g(x_2)$.\n\n\\begin{figure}[htbp]\n\\centering\n    \\includegraphics[width=0.45\\linewidth]{figures/pde-highd/pde-highd_convergence.png}\n\\caption{\nA plot of the variance in 2-norm of MUD solutions acquired from solving the SIP with $Q_{1D}$ and $Q_{2D}$ as more measurements are incorporated.\nThe solid black line represents $Q_{1D}$ and the dashed blue line represents $Q_{2D}$.\n}\n\\label{fig:pde-convergence}\n\\end{figure}\n\n\nThe center and right plots in Figure~\\ref{fig:pde-MUD} shows the variability in the $20$ MUD estimates of $g(x_2)$ obtained from the different realizations of noisy data using $Q_{1D}$ and $Q_{2D}$, respectively.\nA comparison of these plots suggests the MUD estimates associated with $Q_{2D}$ have less spatial variability than those associated with $Q_{1D}$, while also being better point-wise estimates for the interpolant or projection of $g(x_2)$.\nTo quantify this reduction in variability, the convergence with respect to the number of measurements incorporated is illustrated in Figure~\\ref{fig:pde-convergence}.\nThere we see that using $Q_{2D}$ for inversion results in a slow but noticeable reduction in variance while $Q_{1D}$ exhibits a slight upward trend.\nThe MUD solutions for $Q_{1D}$ appear unable to resolve which of the two parameters represents a minimum value of $g$, while $Q_{2D}$ MUD solutions concentrate around the $\\lambda_i$ which best predicts the measurements.\nThe latter solution captures more features of the solution we seek (an estimate of $g$).\n", "meta": {"hexsha": "31ee4c09be1ab343379e25664835aae15a26cf2f", "size": 55803, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "body.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": "body.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": "body.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": 86.5162790698, "max_line_length": 446, "alphanum_fraction": 0.7515904163, "num_tokens": 13923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6328456976718864}}
{"text": "\\section{Numerical Results}\n\\label{sec:numerical}\n\nIn this section, we demonstrate the analytical\nclaims above with numerical examples and\nhighlight the performance of the BIE approach\nwith demonstrations on domains of analytical\nand practical interest. The software used to\ngenerate the figures is available online\n\\footnote{\\texttt{https://doi.org/10.5281/zenodo.2641296}}.\n\n\\subsection{Numerical methods}\n\nFirst, we describe the numerical tools needed\nto compute Stokes eigenvalues in a BIE\nframework.\n\n\\subsubsection{Discretizing the BIE}\n\nIn order to turn the BIEs analyzed\nabove into discrete linear systems,\nwe require some standard techniques\nfrom the BIE literature.\n\nLet the boundary be divided into $N_p$\npanels.\n%\nWe parameterize panel $j$ as\n$\\bx_j(t)$, with $t$ ranging over the\ninterval $[-1,1]$.\n%\nEach component of $\\bx_j$ is taken to be\na polynomial interpolant over the\nstandard 16th-order Legendre nodes on\n$[-1,1]$, denoted by $t_n$, so that\nthe total number of discretization\npoints is $N=16N_p$.\n%\nSee \\cref{fig:panels} for an example\ndiscretization.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{fig/annulus_discretization.pdf}\n\\caption{Sample discretization of an annulus, where the inner\ncircle, $r=1$ is discretized using $6$ panels and the outer circle $r=1.7$\nis discretized using $10$ panels.}\n\\label{fig:panels}\n\\end{figure}\n%\nAnother important quantity below is the\narc-length density of a panel, which\nwe denote by $s_j(t) := |\\bx'_j(t)|$.\n%\nFinally, we denote the set of panels\nwhich are adjacent to panel $j$\nby $A(j)$. On a closed curve,\n$A(j)$ contains two integers.\n\nThe integral kernels of the single and\ndouble layer potentials have weak\nsingularities of the form $|\\xx-\\yy|^p\\log |\\xx-\\yy|$\nfor some $p \\in \\N_0$, which require special\nquadrature rules to achieve high-order accuracy.\n%\nIn the examples below, we use generalized\nGaussian quadrature (GGQ)~\\cite{bremer2010}.\n%\nTo demonstrate the idea, we consider\nevaluating the convolution of a kernel\n$K$ with a density $\\sigma$\nat the boundary node $\\xx_j(t_l)$.\n%\nGGQ is a Nystr\\\"{o}m-type discretization ---\nthe density is approximated \nby its values at the discretization nodes,\nwhich we denote by\n$\\sigma_{qp} := \\sigma(\\xx_q(t_p))$.\n%\nThe basis of a GGQ rule is a set of \nsupport nodes and weights for the\ncontribution to the integral from the\n``self'' panel (panel $j$) and the adjacent\npanels (with index in $A(j)$).\n%\n\nFor the self panel, there is a special set\nof nodes and weights for each interpolation\npoint. Denote the nodes and weights\nfor interpolation point $l$ by $t^{(l)}_{n}$\nand $w^{(l)}_{n}$, respectively, with\n$1\\leq l \\leq 16$ and $1\\leq n \\leq N_s$.\n%\nThe adjacent panels are handled by a single\nset of over-sampled support nodes and weights.\nWe denote these nodes and weights\nby $\\tilde{t}_n$ and $\\tilde{w}_n$, respectively,\nfor $1 \\leq n \\leq N_a$.\n%\nFor the 20th-order rule we used, $N_s = 16$ and\n$N_a = 48$. \n%\nThe contribution of other panels is assumed\nto be given to high accuracy by the standard\nGauss-Legendre weights, which we denote\nby $w_n$.\n%\nAdding these contributions together, we obtain the\nquadrature\n\n\\begin{multline}\n  \\int_\\Gamma K(\\xx_i(t_l),\\yy) \\, \\sigma(\\yy)\n  \\, dS(\\yy) \\approx \\\\\n  \\sum_{p=1}^{16} \\sum_{n=1}^{N_s}\n  w^{(l)}_{n} K(\\xx_i(t_l),\\xx_i({t}^{(l)}_{n}))\n  s_i({t}^{(l)}_{n}) B^{(l)}_{np} \\sigma_{ip} \\quad \\textrm{(self)}\n  \\\\\n  + \\sum_{q\\in A(i)} \\sum_{p=1}^{16} \\sum_{n=1}^{N_a}\n  \\tilde{w}_jK(\\xx_i(t_l),\\xx_q(\\tilde{t}_n)) s_q(\\tilde{t}_n)\n  C_{np} \\sigma_{qp}\n  \\quad \\textrm{(adjacent)} \\\\\n  + \\sum_{q\\neq i, q\\not\\in A(i)} \\sum_{p=1}^{16}\n  w_p K(\\xx_i(t_l),\\xx_q(t_p)) s_q(t_p)\n  \\sigma_{qp} \\quad \\textrm{(far)} \\nonumber \\; ,\n\\end{multline}\nwhere $\\bB^{(l)}$ and $\\bC$ are interpolation\nmatrices from the standard Legendre nodes\nto the self and adjacent panel support nodes,\nrespectively. Observe that the quadrature is\nlinear in $\\sigma_{qp}$. In practice, we pre-compute\nand store the self and adjacent matrix entries for each\ninterpolation point, which is a parallelizable\n$O(N)$ calculation. The ``far'' interactions\nare computed on-the-fly.\n\n\\begin{remark}\n  \\label{rmk:levelrestrict}\n  We ensure that ``far'' interactions\n  are handled to high precision by requiring that\n  no two adjacent panels differ in length\n  by more than a factor of 2. On a domain which does\n  not nearly self-intersect this\n  guarantees that no ``far'' interactions occur\n  which are much closer than 1/2 of a panel away\n  (assuming panels are relatively flat).\n  Because the location of the singularity is\n  bounded away from the panel and the smooth\n  rule is of high order, we obtain a quadrature\n  rule with sufficient precision.\n\n  The overall order of accuracy of the GGQ we use\n  is 20th-order, up to the precision of the ``far''\n  interactions.\n\\end{remark}\n\n\\subsubsection{Fast determinant method}\n\nOnce the discretization is set, we can form\na compressed representation of the system matrix\nusing recursive skeletonization~\\cite{ho2012fast}.\n%\nWe use the implementation of this procedure\nincluded in the fast linear algebra in\nMATLAB (\\texttt{FLAM}) package\n\\cite{hoFLAM_1253582}.\n%\nAt low-to-medium frequencies, the scaling\nof the recursive skeletonization algorithm\nis $O(N\\log N)$ in operation count and\nstorage and, by using a generalization\nof the Sylvester determinant formula,\nallows for a fast determinant\ncalculation in $O(N\\log N)$ time as a\nfollow-up step.\n%\nAt higher-frequencies,\nthe recursive skeletonization procedure,\nwhich is based on the assumption that off-diagonal\nblocks of the matrix are of low rank,\nbreaks down and does not offer a speed advantage.\n%\nThese algorithms take a precision parameter\n$\\epsflam$ which determines the\naccuracy to which any sub-blocks of the matrix\nshould be compressed. In all experiments,\nwe set $\\epsflam = 10^{-14}$.\n\nThe compressed representation also allows\nfor fast applications of the system matrix,\nits transpose, the inverse of the system\nmatrix, and the inverse transpose to\nvectors.\n%\nIn particular, this allows us to estimate the\nsmallest singular values by performing\nrandomized subspace iteration, see\n\\cite[Algorithm 4.4]{halko2011finding},\non the inverse operator.\n%\nBelow, we use the smallest singular value\nas a measure of the quality of the\neigenvalues found by approximating the\nroots of the determinant.\n%\nWe also evaluate the second smallest singular\nvalue if the root finding procedure suggests a\npossible double root. \n\n\\subsubsection{Interpolation and root-finding}\n\nTo estimate the eigenvalues, we fit a Chebyshev\ninterpolant to the discretized determinant as a\nfunction of $k$ on intervals.\n%\nThis is done adaptively so that the Chebyshev\ncoefficients of the determinant have decayed\nto the point that the ratio of the last\ncoefficient to the largest coefficient is below\nsome threshold.\n%\nIn all experiments, we set this threshold\nas $\\epscheb = 10^{-13}$.\n%\nWe perform this fit using the \\texttt{chebfun}\nutility in the package of the same name\n\\cite{driscoll2014chebfun}\nso that we can make use\nof the \\texttt{roots} utility to approximate\nthe roots of the determinant.\n\nThe \\texttt{roots} utility returns the roots\nof the polynomial in the complex plane, with\nsome minimal internal processing to remove\nspurious roots.\n%\nBecause our numerical determinant evaluation\nis somewhat noisy and we fit the function up to\nprecision $\\epscheb$, we perform some\nfurther post-processing to eliminate remaining\nspurious roots.\n%\nLet $k^{(l)}_\\cheb$ denote the roots of the interpolants.\n%\nWe ignore any of the returned roots with $|\\imag(k^{(l)}_\\cheb)|\n> \\sqrt{\\epscheb}$, as these are too far from real-valued\nto be non-spurious.\n%\nFor the remaining roots, we consider the\nproperties of $\\real(k^{(l)}_\\cheb)$.\n%\nWe inspect any pairs of roots $(k^{(p)}_\\cheb,k^{(q)}_\\cheb)$\nfor which $|\\real(k^{(p)}_\\cheb-k^{(q)}_\\cheb)| < \\sqrt{\\epscheb}$,\nas these are possibly spurious double roots.\n%\nFor these pairs, we compare the right singular\nvector of the appropriate BIE operator corresponding\nto the smallest singular value for each of $\\real(k^{(p)}_\\cheb)$\nand $\\real(k^{(q)}_\\cheb)$, which we denote by\n$\\bv_p$ and $\\bv_q$.\n%\nIf $\\|\\bv_p - \\bv_q \\bv_q^* \\bv_p \\| < 10^{-5}$, then\nwe consider the pair to be spurious.\n%\nFor these near double roots, we also check\nthat there is no two dimensional null-space\ncorresponding to the root by estimating the\nsecond smallest singular value of the BIE operator.\n%\nIf this is larger than $10^{-5}$, then we declare\nit to be a simple root.\n\nWe can obtain an a posteriori estimate of the\nerror in a computed root as follows.\n%\nLet $f$ denote an analytic function,\n$P$ be the polynomial interpolant\nof that function over some interval,\n$\\delta f = f-P$ be the difference,\nand $k_\\cheb$ denote a computed root\nof $P$ which is simple (i.e. assume\nthat $P'(k_\\cheb) \\ne 0$).\n%\nThe algorithm used by \\texttt{chebfun}\nto approximate the roots of $P$ is\nbackward stable~\\cite{noferini2017chebyshev}.\nTherefore the error in the roots will be\nsmall relative to the error of the fit and\nwe set $P(k_\\cheb) = 0$ below.\n%\nSuppose that\n$f(k_\\cheb + \\delta k) = 0$ for some\nsmall $\\delta k$. Then\n\n\\begin{align*}\n  0 &= f(k_\\cheb + \\delta k) \\\\\n  0 &= P(k_\\cheb + \\delta k) + \\delta f(k_\\cheb + \\delta k) \\\\\n  \\delta k &= -\\frac{\\delta f(k_\\cheb + \\delta k)}{P'(k_\\cheb)} + O(\\delta k^2) .\n\\end{align*}\nIn practice, we can obtain an approximate upper\nbound for $|\\delta f(k_\\cheb+\\delta k)|$\nas $\\epscheb \\|P\\|_\\infty$ so that $\\epscheb \\|P\\|_\\infty/\n|P'(k_\\cheb)|$ provides an approximate upper bound\nfor the error in the root.\n\n\\subsection{Eigenvalues of an annulus}\nWe test our numerical machinery and validate our analytical \nand numerical claims\nby comparing the results to the true eigenvalues on the annulus\nwhich are known analytically (see~\\cref{sec:annul_dir_exact}).\nIn all of the examples below, we work on the annulus $r_{1}<r<r_{2}$\nwith $r_{1} = 1$ and $r_{2} = 1.7$.\nIf the inner boundary is discretized using $N_{1}$ panels, \nthen the outer boundary is discretized using $N_{2} = \n\\lceil r_{2}/r_{1} N_{1} \\rceil +1$ panels to ensure that the\npanels are approximately the same length on both the boundaries. \nThe total number of discretization points \nis then given by $N = 16(N_{1} + N_{2})$.\nLet $D^{N}_{k}$ denote the linear system corresponding\nto the Nystr\\\"{o}m discretization of\n$-2\\cD_{k} -2\\cW$ using generalized Gaussian quadrature, \nand let $C^{N}_{k}$ denote the linear system corresponding\nto the Nystr\\\"{o}m discretization of \n$-2\\cD_{k} - 2i\\cS_{k} -2\\cW$.\nLet $f_{D}^{N}(k) = \\text{det}(I+D^{N}_{k})$, and \n$f_{C}^{N}(k) = \\text{det}(I+C^{N}_{k})$.\n\n\\subsubsection{Convergence study}\n\\label{subsec:convannulus}\nWe demonstrate that \nfor sufficiently large $N$, if $k_{0}$ is a Dirichlet \neigenvalue of the annulus, \nthen $f_{D}^{N}(k_{D}) = 0$ and $f_{C}^{N}(k_{C}) = 0$\nwhere $|k_{D} - k_{0}| \\lesssim N^{-20}$, \nand $|k_{C} - k_{0}| \\lesssim N^{-20}$.\nRecall that the GGQ we use has an expected order\nof convergence of $N^{-20}$ for evaluating convolutions\nwith such integral kernels,\nso that the error of the roots is observed to have the\nsame order as the quadrature rule.\nIn~\\cref{fig:conv}, we show this result for $k_{0} = 13.48025717955055$\nand plot the errors $|k_{D}-k_{0}|$ and $|k_{C}-k_{0}|$ as a function\nof $N$. \n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.98\\textwidth]{fig/conv-studies.pdf}\n  \\caption{Convergence studies for the Dirichlet eigenvalues\n  computed using the integral equations \n  $\\cI - 2\\cD_{k} - 2\\cW$ (left) and\n  $\\cI - 2\\cD_{k} - 2i \\cS_{k} - 2\\cW$ (right).}\n  \\label{fig:conv}\n\\end{figure}\n\n\\subsubsection{Spurious eigenvalues}\n\\label{subsec:spurannulus}\nAs noted in~\\cref{subsec:dlanalysis},\nif $k_{0}$ is a Neumann eigenvalue corresponding to the interior\ninclusion, which in our case is the disk $r\\leq r_{1}$, then\n$f_{D}^{N}(k_{D}) = 0$ with $|k_{D}-k_{0}| = O(\\varepsilon)$, even though $k_{0}$ \nis not a Dirichlet eigenvalue of the annulus, i.e.\nthe integral equation $-\\cI - 2\\cD_{k} -2\\cW$ has a spurious eigenvalue.\nIn~\\cref{fig:spur}, we demonstrate this result and also show that \n$f_{C}^{N}(k_{0}) \\neq 0$, i.e., the combined field representation is\nrobust and invertible at all values of $k$ which are not the Dirichlet\neigenvalues of the annulus.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.98\\linewidth]{fig/det_spur.pdf}\n\\caption{The values of the discretized determinants $f_{C}^{N}(k)$ (left)\nand $f_{D}^{N}(k)$ on the interval $k=[14,15]$ with $N=368$ (the \nsolid lines are the real parts of the determinant and the dashed lines\nare the imaginary parts of the determinant). The vertical\ndotted line denotes the spurious eigenvalue $k_{0} = 14.79595178235126$ \nand $f_{D}^{N}(k_{D}) = 0$ with $|k_{D}-k_{0}|=6.8\\times 10^{-12}$.\nOn the other hand $|f_{C}^{N}(k_{0})|=0.42$, and thus $\\cI-2\\cD_{k}-2i\\cS_{k} \n-2\\cW$ has no \nspurious eigenvalue in the neighborhood of $k=k_{0}$.}\n\\label{fig:spur}\n\\end{figure}\n\n\\subsubsection{Speed}\n\\label{subsec:speed}\nIn this section, we demonstrate the $O(N\\log{N})$ scaling of evaluating\n$f^{N}_{C}(k)$ as long as $N$ is large enough to resolve the interactions\nat the Helmholtz parameter $k$. \nWhen $N$ is smaller than that, we observe a worse scaling since the\nassumption that far-interactions are low-rank is no longer valid at\nthe tolerance of FLAM.\nWe plot the timing results corresponding to three different values of \n$k$ in~\\cref{fig:speed}. The times are as recorded for a laptop with\n16Gb of RAM and an Intel Core i7-6600U CPU at 2.60GHz with 4 cores.\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.5\\textwidth]{fig/speed_res.pdf}\n\\caption{Time taken $(t)$ in seconds to evaluate the determinant $f_{C}^{N}(k)$ as\na function of $N$ for three different values of $k$.}\n\\label{fig:speed}\n\\end{figure}\n\n\\subsection{Eigenvalues of a barbell-shaped domain}\n\\label{subsec:barbell}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_barbell_001_bdry}\n    \\caption{A barbell-shaped domain.}\n    \\label{subfig:barbell_bdry}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_many_holes_004_bdry}\n    \\caption{A domain with several inclusions.}\n    \\label{subfig:many_inclusions_bdry}\n  \\end{subfigure}\n  \\caption{Computational domains.}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\textwidth]{fig/barbell_gallery}\n  \\caption{Vorticity plots of the first 119 eigenfunctions\n    of the barbell-shaped domain.}\n  \\label{fig:barbell_gallery}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_barbell_001_sings_plot}\n    \\caption{Smallest singular value of the BIE operator.}\n    \\label{subfig:barbell_sings}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_barbell_001_coeffs_plot}\n    \\caption{Normalized Chebyshev coefficients of the\n      determinant on 3 intervals in $k$.}\n    \\label{subfig:barbell_coeffs}\n  \\end{subfigure}\n  \\caption{Diagnostics for the first 119 barbell eigenvalues.}\n  \\label{fig:barbell_diagnostics}\n\\end{figure}\n\nWe consider the barbell-shaped domain in \\cref{subfig:barbell_bdry}.\nThis domain is the union of a square of side-length 6,\na square of side-length 3, and a ``bridge'' connecting\nthem of height 1 and width 5/2.\n%\nFor the sake of simplicity, we round the corners of the domain\nto obtain a smooth object.\n%\nApplying the approach described in~\\cite{epstein2016smoothed},\nthe corners of the domain are rounded by convolving with\nthe Gaussian kernel\n\\begin{equation}\n  \\nonumber\n\\phi(x) = \\frac{1}{\\sqrt{2\\pi h}} e^{-x^2/(2 h^2)} \\, ,\n\\end{equation}\nwith $h\\approx 0.06$. This leaves the domain unperturbed\nto high precision outside of a radius of $0.1$ around\neach corner.\n%\nThe eigenfunctions of such a domain display the well-known\nlocalization property~\\cite{trefethen2006computed}:\nmany of the eigenfunctions are approximately supported\nwithin one of the squares.\n%\nWe compute these eigenfunctions corresponding to\neigenvalues $k^2$ with $k$ in the range\n$0.5 \\leq k \\leq 6.5$.\n\n%\nThe panels are divided adaptively so that the smallest\npanels in the rounded corners are smaller than $10^{-2}$,\nwhich keeps the panels relatively flat.\n%\nThis results in $N_p = 412$ after enforcing the\nlevel-restriction property described in\n\\cref{rmk:levelrestrict}\nand enforcing that no panel is larger than\none wavelength for the largest $k$\n(here $\\lambda=2\\pi/6.5$).\n\nAs this is a simply-connected domain,\nthe eigenvalues are estimated by finding the values\n$k$ for which $\\cI-2\\cDk-2\\cW$ is non-invertible.\n%\nLet $f^N(k) = \\det (\\cI^N-2\\cDk^N-2\\cW^N)$.\nTo find the roots of $f^N(k)$, we fit a \\texttt{chebfun}\nrepresentation of $f^N(k)$ on each of the intervals\n$[j/2,(j+1)/2]$ for $j = 1,\\ldots,12$.\n%\nWe plot the absolute value of the Chebyshev coefficients\n(normalized by the absolute value of the first coefficient)\nof $f^N(k)$ on the intervals $[0.5,1.0]$, $[3.0,3.5]$,\nand $[6.0,6.5]$ in \\cref{subfig:barbell_coeffs}.\n%\nAs expected, the coefficients decay exponentially\nto zero, with more terms required at higher\nfrequencies.\n%\n\nWe compute the roots of these Chebyshev interpolants\nand apply the post-processing described above.\n%\nThere were 135 total roots: 3 were removed because\nthe imaginary part was too large and 13 pairs were found\nwith values within $\\sqrt{\\epscheb}$ of each other.\n%\nFor these 13 pairs, none represented two distinct\neigenvalues or a double root.\n%\nThis leaves 119 roots in the range $0\\leq k \\leq 6.5$.\n%\nWe plot the smallest singular value of\n$\\cI^N-\\cDk^N-2\\cW^N$ for each of these roots in\n\\cref{subfig:barbell_sings}\nand plot the vorticity of the eigenfunctions\nin \\cref{fig:barbell_gallery}.\n%\nThe singular values suggest that the quality of the\neigenvalues is good.\nFrom the plots, we see that localization occurs\nuntil about the 100th eigenvalue.\n\n%\n\n%\\subsection{Robustness on a nearly multiply connected domain}\n%\\label{subsec:crescent}\n\n\\subsection{Eigenvalues of a domain with several inclusions}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\textwidth]{fig/many_inclusions_gallery}\n  \\caption{Vorticity plots of the eigenfunctions corresponding\n  to the first 76 eigenvalues of a domain with several inclusions.}\n  \\label{fig:many_inclusions_gallery}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_many_holes_004_sings_plot}\n    \\caption{Smallest singular value of the BIE operator\n      corresponding to the first 76 eigenvalues of a\n      domain with several inclusions.}\n    \\label{subfig:many_inclusions_sings}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_many_holes_004_coeffs_plot}\n    \\caption{Normalized Chebyshev coefficients of $f^N(k)$ on\n      3 different intervals in $k$.}\n    \\label{subfig:many_inclusions_coeffs}\n  \\end{subfigure}\n  \\caption{Diagnostics for the eigenvalues of a domain\n    with several inclusions.}\n  \\label{fig:many_inclusions_diagnostics}\n\\end{figure}\n\nWe now consider the multiply-connected domain in\n\\cref{subfig:many_inclusions_bdry}.\n% \nThe domain is defined by a smooth rectangular region\nof width 3 and height 2,\nwith an array of randomly rotated ``starfish'' shapes\nremoved. \n%\nSuch shapes are of interest in\nmaterials design, see, for instance, \\cite{overvelde2012compaction}.\n%\nWe compute the eigenfunctions corresponding to\neigenvalues $k^2$ with $k$ in the range\n$3 \\leq k \\leq 9$ (this range includes the smallest\neigenvalue).\n\n%\nFor this smooth shape, ensuring that no panel is\nlarger than one wavelength for the largest $k$\n(here $\\lambda=2\\pi/9$) is sufficient to resolve\nthe object to high precision.\n%\nAfter enforcing the\nlevel-restriction property described in\n\\cref{rmk:levelrestrict}, we end up with\n$N_p = 224$.\n\nAs this is a multiply-connected domain,\nthe eigenvalues are estimated by finding the values\n$k$ for which $\\cI-2\\cDk-2i\\cSk-2\\cW$ is non-invertible.\n%\nLet $f^N(k) = \\det (\\cI^N-2\\cDk^N-2i\\cSk^N-2\\cW^N)$.\nTo find the roots of $f^N(k)$, we fit a \\texttt{chebfun}\nrepresentation of $f^N(k)$ on each of the intervals\n$[j/2,(j+1)/2]$ for $j = 6,\\ldots,13$ and the intervals\n$[j/4,(j+1)/4]$ for $j = 28,\\ldots,35$.\n%\nIt should be noted that, due to the relative sizes\nof the domains,\nthis represents a lower frequency problem than\nthat for the barbell when measured in the number\nof wavelengths across the object.\n%\nThus, the use of a finer grid in frequency results from\nthe difficulty in resolving the Fredholm determinant\nfor this problem, which has a larger dynamical range\nthan that for the barbell.\n%\nWe plot the absolute value of the Chebyshev coefficients\nof $f^N(k)$ on the intervals $[3,3.5]$, $[6.5,7]$,\nand $[8.75,9]$ in \\cref{subfig:barbell_coeffs}.\n%\nAs expected, the coefficients decay exponentially\nto zero, with more terms required at higher\nfrequencies (note that the interval $[8.75,9]$ is\nsmaller than the others).\n%\n\nWe compute the roots of these Chebyshev interpolants\nand apply the post-processing described above.\n%\nThere were 103 total roots: 21 were removed because\nthe imaginary part was too large and 6 pairs were found\nwith values within $\\sqrt{\\epscheb}$ of each other.\n%\nFor these 6 pairs, none represented two distinct\neigenvalues or a double root.\n%\nThis leaves 76 roots in the range $0\\leq k \\leq 9$.\n%\nWe plot the smallest singular value of\n$\\cI^N-\\cDk^N-2i\\cSk^N-2\\cW^N$ for each of these roots in\n\\cref{subfig:many_inclusions_sings}\nand plot the vorticity of the eigenfunctions\nin \\cref{fig:many_inclusions_gallery}.\n%\nIn the vorticity plots, we observe a different type of\nlocalization property than that seen in the barbell,\nwith many of the eigenfunctions\napproximately supported in a small, connected subset\nof the domain. This is consistent with other studies\n\\cite{filoche2009strong,lindsay2018boundary}.\n\n%\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_many_holes_004_sings_plot_west}\n    \\caption{Smallest singular value of the BIE operator\n      for the computed roots on the original intervals (\\textbullet)\n      and an estimate of the error (dotted).}\n    \\label{subfig:many_inclusions_sings_west}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[t]{0.4\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{fig/ex_many_holes_004_sings_plot_ref}\n    \\caption{Smallest singular value of the BIE operator\n      for the computed roots on the original intervals (\\textbullet)\n      and the values obtained on the refined interval ($\\times$).}\n    \\label{subfig:many_inclusions_sings_ref}\n  \\end{subfigure}\n  \\caption{Further diagnostics for the eigenvalues of a domain\n    with several inclusions.}\n  \\label{fig:many_inclusions_diagnostics_2}\n\\end{figure}\n\nThe singular values suggest that the quality of the\neigenvalues is good, with a few outliers.\n%\nTo explain these outliers, we consider two quantities\nwhich affect the singular value at a computed root.\n%\nAs described above, we can approximate the\nerror in the computed root at $k_\\cheb$ by\n$\\epscheb \\|P\\|_\\infty/|P'(k_\\cheb)|$,\nwhere $P$ is the interpolating polynomial.\n%\nThe singular value estimate itself is affected by\nthe error incurred in applying the inverse of the\ncompressed BIE matrix, which can be hard to quantify\n\\cite{ho2012fast}.\n%\nWe approximate this error by $O(\\sqrt{N})\\epsflam$\nand assume this is the order of the error in\nthe singular value estimate.\nWe plot the maximum of these two estimates\nalong with the computed singular values in\n\\cref{subfig:many_inclusions_sings_west}.\nThere is a reasonably good correlation between\nthe maximum of the error estimates and the\nobserved smallest singular value for the BIE,\nespecially for larger errors.\n\nThe worst outliers are from the left half\nof the interval $[4.5,5]$.\n%\nBecause the determinant is much larger on the\nright half than the left half of $[4.5,5]$,\nwe can improve the estimate for the error\nin the roots by subdividing the interval. \nWe plot the smallest singular value of the\nBIE for the roots obtained by fitting a polynomial\non $[4.5,4.75]$ in \\cref{subfig:many_inclusions_sings_ref};\nthe roots on the refined interval\nare of significantly higher quality.\n\n\\begin{remark}\n  The above experience suggests that\n  the ratio $\\|P\\|_\\infty/|P'(k_\\cheb)|$\n  is a useful diagnostic for performing\n  automated eigenvalue estimation.\n  Note that at a multiple root, this ratio\n  will be more difficult to bound.\n\\end{remark}\n%\n\n\n\n%\n", "meta": {"hexsha": "6e3c928e91b62b6152a62f1108c597ac4dc0e63f", "size": 24762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01-stokes/04numerical.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-stokes/04numerical.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-stokes/04numerical.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": 33.8278688525, "max_line_length": 82, "alphanum_fraction": 0.7418625313, "num_tokens": 7421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6328456878164384}}
{"text": "\\section{Materials and methods} \\label{sec:metodos}\n    In this section we will explain in more detail the problem modeling, ie the machine learning techniques implemented in the project and how they were specified.\n    \n    \\subsection{Related Work - Deep VO}\n        The paper \\cite{wang2017deepvo} presents a novel end-to-end framework for monocular VO by using deep Recurrent Convolutional Neural Networks (RCNNs) \\cite{liang2015recurrent}. Since it is trained and deployed in an end-to-end manner, it infers poses directly from a sequence of raw RGB images (videos) without adopting any module in the conventional VO pipeline. Based on the RCNNs, it not only automatically learns effective feature representation for the VO problem through Convolutional Neural Networks, but also implicitly models sequential dynamics and relations using deep Recurrent Neural Networks. The framework has been tested under the Kitti Dataset \\footnote{\\url{http://www.cvlibs.net/datasets/kitti/eval_odometry.php}}, showing great results.\n        \n        The model is mainly composed of CNN based feature extraction, as previous presented in \\cite{chen2016deep}, and RNN based sequential modelling, as shown in \\cite{chung2015recurrent}. The architecture of the proposed VO system is shown in Figure \\ref{fig:8}, it takes a monocular image sequence as input. Two consecutive images are stacked together to form a tensor for the deep RCNN to learn how to extract motion information and estimate poses. The VO system develops over time and estimates new poses as images are captured. \n        \n        The image feature extraction of is done by a CNN, which configuration is shown at Figure \\ref{fig:9}. The CNN takes raw RGB images instead of pre-processed counterparts, such as optical flow or depth images, as input because the network is trained to learn an efficient feature representation with reduced dimensionality for the VO.\n        \n        Following the CNN, a deep RNN is designed to conduct sequential learning, i.e., to model dynamics and relations among a sequence of CNN features. Since the RNN is capable of modelling dependencies in a sequence, it is well suited to the VO problem which involves temporal model (motion model) and sequential data (image sequence). \n        \n        To learn the hyperparameters $\\theta$ of the DNNs, the Euclidean distance between the ground truth pose ($p_k$ ,$\\varphi_k$) at time $k$ and its estimated one ($\\text{\\^{p}}_k$ ,$\\hat{\\varphi_k}$) is minimised. The loss function is composed of Mean Square Error (MSE) of all positions p and orientations :\n        \\begin{equation}\n            \\theta^* = \\underset{\\theta}{\\mathrm{argmin}} \\frac{1}{N} \\sum_{i=1}^{N}\\sum_{k=1}^{t} \\left\\| \\hat{p_k} - p_k \\right\\|^{2}_2 + k \\cdot \\left\\| \\hat{\\varphi_k} - \\varphi_k \\right\\|^{2}_2\n            \\label{eq:MSE}\n        \\end{equation}\n        \n         In Figure \\ref{fig:10}, the losses results of the models are given for both training and validate datasets. As shown in the fig., the loss significantly reduces with time, and, once the training and validation losses shown a similar behavior we can also say that is free of overfiting, so, the model is well-fit.\n         \n         The Figures \\ref{fig:11} and \\ref{fig:12} show us the obtained maps for the framework for both training and test datasets. As we can see in the figures, the obtained odometry from the system is very close to the ground truth position, showing how great the system performs. The system is analysed according to the KITTI VO/SLAM evaluation metrics, i.e., averaged Root Mean Square Errors (RMSEs) of the translational and rotational errors for all subsequences of lengths ranging. The average RMSEs of the estimated VO are given in Figure \\ref{fig:13}. Al- though the result of the DeepVO is worst than that of the stereo VISO2 (VISO2\\_S), it is consistently better than the monocular VISO2 (VISO2\\_M).\n         \n         The paper presents a novel end-to-end monocular VO algorithm based on Deep Learning, that does not depend on any module in the conventional VO algorithms (even camera calibration) for pose estimation and it is trained in an end-to-end manner, there is no need to carefully tune the parameters of the VO system. Based on the KITTI VO benchmark, it is verified that it can produce accurate VO results with precise scales and work well in completely new scenarios.\n         \n         For this project, we aim to reproduce the paper approach using images and poses obtained at the AirSim, an open source simulator for autonomous vehicles built on Unreal Engine/Unity, from Microsoft AI\\&Research \\footnote{\\label{ref:note1}\\url{https://github.com/microsoft/AirSim}}.\n         \n    \\subsection{Project Dataset}\n        \\subsubsection{Data Collection}\n            In order to create our own \\emph{dataset} to perform the article model we had use the Microsoft AirSim Simulator to generate both images and poses.\n            \n            Six sequences were generated under three different scenarios: Neighborhood(Figure \\ref{fig:neig}), Africa (Figure \\ref{fig:africa}) and LandscapeMountains(Figure \\ref{fig:mountain}). \n            \n            The simulator were used at the \\emph{ComputerVision} mode and the cameras controlled via keyboard. Each sequence has around four hundred pictures, making a total of around two thousand images for the training set.\n        \n        \\subsubsection{Images Data Prerocessing}\n            The first stage of image preprocessing was eliminate all failed pictures given by the simulator, excluding them from both pictures and pose lists.\n            \n            After that, as we read the images we convert them to grayscale and normalize their pixels values, in a range that goes from -0.5 to 0.5 in order to be able to use the pretrained weight of FlowNet, all of it were done using the OpenCV library.\n            \n            At least, we concatenated the pictures two by two, once that the two images will going to work as input for our Neural Network.\n            \n        \\subsubsection{Poses Data Preprocessing}\n            The AirSim recording mode, as we further explain, give us a text file with the following informations for each image: timestamp, x\\_position, y\\_position, z\\_position, quaternions\\_x, quaternions\\_y, quaternions\\_z, quaternions\\_w and a filename of the image associated to that pose.\n            \n            As explained in \\citeonline{quat_angle}, a quaternion is a four-element vector that can be used to encode any rotation in a 3D coordinate system.  Technically, a quaternion is composed of one real element and three complex elements, and it can be used for much more than rotations. For our work, we need the angles to be at an Euler representation. Euler angles provide a way to represent the 3D orientation of an object using a combination of three rotations about different axes.\n            \n            In order to transform the given angles to an Euler representaion we need to use the following equations:\n            \n            \\begin{equation}\n                \\phi = arctan(\\frac{2(ab+cd)}{a^2 - b^2 - c^2 + d^2})\n            \\end{equation}\n            \\begin{equation}\n                \\theta = -arcsin(2(bd-ac))\n            \\end{equation}\n            \\begin{equation}\n                \\Psi = arctan(\\frac{2(ad+bc)}{a^2 + b^2 - c^2 - d^2}\n            \\end{equation}\n            \n            This can be easily done in \\emph{Python} using the \\emph{Scipy} \\footnote{\\url{https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.spatial.transform.Rotation.html}} library.\n            \n            Another thing we had to do in order to process the information was make the first pose our start point, so we subtract all the other poses from the first one value. In addition, in addition we subtract all the poses, with the except of the firts, from the previous pose value, so, the network has to predict only the dislocate between two images.\n            \n    \\subsection{Deep VO Implementation}\n        In order to simulate Wang's\\cite{wang2017deepvo} paper for our dataset, we implemented the same RCNN model showed at Figure \\ref{fig:2}.\n        \n        For implementing the model we used the PyTorch \\footnote{\\url{https://pytorch.org/}} library. All the convolutionals layers has a \\emph{Conv2d} structure, followed by a \\emph{BatchNorm2d} (batch normalization), and then a \\emph{LeakyReLU} function (a Rectified Linear Activation Function) and in the end, a \\emph{Dropout}.\n        \n        A convolution is the simple application of a filter to an input that results in an activation, the batch normalization reduces the amount by what the hidden unit values shift around (covariance shift). The activation function is responsible for transforming the summed weighted input from the node into the activation of the node or output for that input. And in the dropout stage, at each training stage, individual nodes are either dropped out of the net with probability 1-p or kept with probability p, so that a reduced network is left; incoming and outgoing edges to a dropped-out node are also removed.\n        \n        For the CNN part we tested two different configurations, which results will be further commented. We first fitted the model without any previous information and, in a second stage, we loaded pretrained weight of FlowNet network \\footnote{\\url{https://towardsdatascience.com/a-brief-review-of-flownet-dca6bd574de0}}.\n        \n        For the RNN part of the network, we had two \\emph{LSTM} layers followed by a linear output, that receives 100 features as input and outputed 6 features (our pose). The Long Short-Term Memory (LSTM) networks are a modified version of recurrent neural networks, which makes it easier to remember past data in memory.\n        \n        To define the loss function we used the Mean Square Error, same as Wang's paper and which equations is defined at Equation \\ref{eq:MSE}. The used optimizer was the Adagrad, an algorithm for gradient-based optimization that does just this: It adapts the learning rate to the parameters, performing smaller updates (i.e. low learning rates) for parameters associated with frequently occurring features, and larger updates (i.e. high learning rates) for parameters associated with infrequent features.", "meta": {"hexsha": "b764903633747c6b90683bc63616dca5e2565631", "size": 10314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project3/[MC907]project3/4-materiais-metodos.tex", "max_stars_repo_name": "luizcartolano2/mc907-mobile-robotics", "max_stars_repo_head_hexsha": "58258759fd6d750e5ec4fc1a27472b78614d5add", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-01-08T04:54:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T03:05:00.000Z", "max_issues_repo_path": "project3/[MC907]project3/4-materiais-metodos.tex", "max_issues_repo_name": "luizcartolano2/mc907-mobile-robotics", "max_issues_repo_head_hexsha": "58258759fd6d750e5ec4fc1a27472b78614d5add", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project3/[MC907]project3/4-materiais-metodos.tex", "max_forks_repo_name": "luizcartolano2/mc907-mobile-robotics", "max_forks_repo_head_hexsha": "58258759fd6d750e5ec4fc1a27472b78614d5add", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-30T20:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-11T01:27:01.000Z", "avg_line_length": 139.3783783784, "max_line_length": 763, "alphanum_fraction": 0.7348264495, "num_tokens": 2318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6328456782484697}}
{"text": "\\chapter{Inner product spaces}\n\nOne structure that we often use in $\\R^n$, but which is missing from\nabstract vector spaces, is the dot product. In\nChapter~\\ref{cha:vectors-rn}, we saw how to use dot products to\ncompute the length of a vector, the angle between two vectors, and to\ndecide when two vectors are orthogonal. We also used dot products to\ndefine the projection of one vector onto another, and to find shortest\ndistances between various objects (such as points and planes, two\nlines, etc).\n\nIn this chapter, we will consider inner product spaces. An inner\nproduct space is essentially an abstract vector spaces that has been\nequipped with an operation that works ``like'' the dot product.\n", "meta": {"hexsha": "d9206e9577753773324d65213649360721d0bbbe", "size": 700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces.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.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.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": 46.6666666667, "max_line_length": 70, "alphanum_fraction": 0.7871428571, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933183101077, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6328293352653237}}
{"text": "\\chapter{Survival analysis}\n\\section{Survivor functions for whole sample}\nIn the fourth exercise we do survival analysis with data from lung cancer patients. The three variables used here are \\texttt{PRE30}, indicating whether the patient is a smoker, \\texttt{AGE}, encoding the age at surgery, and \\texttt{Risk1Y}, indicating whether the patient died within one year after the surgery. The first observations are shown in Table \\ref{5table}. Hence, this data can be understood as interval censored survival data. In this exercise we were asked to assume failure times at \\texttt{AGE}+1, if the patient died and fit survivor functions to model $S(t)=P(T>t)$, where $T$ is a random variable encoding the failure time of an object, here the time of death of a patient. \n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{llrl}\n  \\hline\n & PRE30 & AGE & Risk1Y \\\\ \n  \\hline\n1 & TRUE &  60 & FALSE \\\\ \n  2 & TRUE &  51 & FALSE \\\\ \n  3 & TRUE &  59 & FALSE \\\\ \n  4 & FALSE &  54 & FALSE \\\\ \n  5 & TRUE &  73 & TRUE \\\\ \n  6 & FALSE &  51 & FALSE \\\\ \n   \\hline\n\\end{tabular}\n\\caption{First observations of the lung cancer patient data set.}\n\\label{5table}\n\\end{table}\n\nTo assess which parametric model is reasonable for the data, we use non-parametric estimators for the survival curve. Therefore we draw the Kaplan-Meier estimator, given by $$\\hat{S}_{KM}(t)=\\prod_{\\{j:\\tau_j<t\\}}(1-\\frac{d_j}{r_j}),$$ where $0\\leq \\tau_1<\\tau_2<...$ denote the ordered uncensored failure times (here \\texttt{AGE}+1), $r_i$ and $d_i$ the number of units still at risk and failures at $\\tau_i$ respectively. A similar estimator, especially in those areas where still many cases are at risk, is the Fleming-Harrington estimator $$\\hat{S}_{FH}(t)=\\prod_{\\{j:\\tau_j<t\\}}\\exp(-\\frac{d_j}{r_j}).$$ Both are shown in Figure \\ref{5nonpar} where we can see that they only differ obviously at ages $>80$. In the area of lower risk both seem to be identical, why we can't see the orange line. We can also see that the confidence band spreads as the survival probability decreases. Both curves are fitted using \\texttt{survfit} from the package \\textit{survival} which also computes pointwise confidence intervals using Greenwood's formula.  \n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=0.7\\textwidth, keepaspectratio]{ex4/survfits.png}\n\\caption{Nonparametric estimators for the survivor function. KM = Kaplan-Meier drawn in blue; FH=Fleming-Harrington in orange. Dashed lines show the confidence bands.}\n\\label{5nonpar}\n\\end{figure}\n\\begin{figure}[!b]\n\\centering\n\\includegraphics[width=0.7\\textwidth, keepaspectratio]{ex4/paramsurvfits.png}\n\\caption{KM estimator and parametric fits for the survivor function. Dashed lines represent the confidence band of the KM estimator. Exponential fit in orange; Weibull fit in blue.}\n\\label{5parfit}\n\\end{figure}\n\nWith the function \\texttt{survreg} we can fit parametric models to the data. Typical models are the exponential, Weibull and log-logistic models. Because we were asked to fit the first two in this exercise, I only give more details on them. The exponential model assumes a constant Hazard function, i.e. rate of failure, of $\\lambda$ over time resulting in an exponential survivor function $S_{exp}(t)=\\exp(-\\lambda t)$. With the Weibull distribution we can handle varying Hazard rates by taking $h(t)=\\alpha \\lambda ^{\\alpha} t^{\\alpha-1}$ resulting in a survivor function $S(t)=\\exp(-(\\lambda t)^\\alpha)$. At $t=1$ we have $h(1)=\\alpha\\lambda^\\alpha$, so $\\lambda$ is still the parameter of failure rate, defined for the unit time and modified by the shape parameter. Obviously we get the exponential model for $\\alpha=1$, an increasing Hazard function for $\\alpha>1$ and an decreasing Hazard or $0<\\alpha<1$. The Weibull distribution is often more appropriate when we can't assume constant Hazard rates. In clinical studies concerning relapses of psychological diseases for example a relapse, i.e. failure, gets often less probable with time since recovery. Here a decreasing Hazard function would be appropriate. But in general older living organisms have a smaller survivor probability over time than younger ones indicating the use of an increasing Hazard. In this example the fits (see Figure \\ref{5parfit}) compared to the nonparametric KM estimator suggest that an exponential model can be rejected quite obviously, since the shape does not at all represent the step function. The Weibull model on the other hand seems very good as it follows the KM estimation pretty directly. Although it lies beneath the lower confidence bound at an age around 78, the overall shape suits pretty well.  \n\n\\section{Comparison of smokers and non-smokers}\nNow we split the data set into two parts - smokers and non-smokers - according to the variable \\texttt{PRE30}. Fitting a KM estimate for each group leads to Figure \\ref{5nonpargroups}. We see very clear that the curve of smokers is stepper than the other. The curve for nonsmokers drops in the end since the only patient with age 81 in the nonsmokers group, who also was the oldest one, died. But all in all the survival probability of nonsmokers seems higher. In the plot we also see that there are more steps in the curve for the smokers. This is because of the unbalanced sample sizes. With 386 smokers and 84 nonsmokers the proportion of smokers is 82.12$\\%$. It is well known that smoking increases the probability to get cancer, so this is not a surprising observation here. An inferential comparison of the two groups to check whether the visual differences are statistically significant is done with a log-rank test. With the R function \\texttt{survdiff} in the same package we get the results $\\chi ^2=2.7$ and $p=.1$. This indicates a difference between the groups, too, which most researchers won't interpret as significant. Since I am no expert in this area, I can't finally judge it, but would emphasize that the difference may be statistically relevant in this case.\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=0.8\\textwidth, keepaspectratio]{ex4/smokers.png}\n\\caption{Kaplan-Meier estimate for smokers (red) and nonsmokers (blue) with confidence bands.}\n\\label{5nonpargroups}\n\\end{figure} \n\nNow we want to check whether the assumption of a Weibull model is still justified when we look at the groups separately. Therefore we fitted a Weibull curve for each of the groups (see Figure \\ref{5paragroups}). For the group of smokers we see like above a very good fit. For nonsmokers the Weibull fit looks quite well but is probably distorted by the sudden drop down in the end. It seems like a less steep curve would fit better to the data in the beginning. This may be solved by an extended sample where especially more older patient are included. Of course, this is sometimes hard to accomplish in practice. Still the Weibull curve of the smokers group decreases faster than the other and I would finally conclude, also because it seems quite reasonable (although a statistician should argue rather with data than with common sense), that smoking decreases the probability of surviving one year after the surgery. \n\\begin{figure}[!h]\n\\centering\n\\includegraphics[width=\\textwidth, keepaspectratio]{ex4/groupsparam}\n\\caption{Kaplan-Meier estimate with dashed confidence bands (black) and Weibull fit (blue) for patient groups of smokers (left) and nonsmokers (right).}\n\\label{5paragroups}\n\\end{figure}", "meta": {"hexsha": "b96ee7f169a1388701aca059c5857bc90085f91a", "size": 7394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex4/ex4.tex", "max_stars_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_stars_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex4/ex4.tex", "max_issues_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_issues_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex4/ex4.tex", "max_forks_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_forks_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_forks_repo_licenses": ["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.5094339623, "max_line_length": 1798, "alphanum_fraction": 0.7744116852, "num_tokens": 1855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6327018256122423}}
{"text": "\\documentclass{report}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\begin{document}\n\\section{Marginal distribution and Conditional distribution}\n\\subsection{Abstract}\nIn this section, we study the marginal probability and conditional probability of multivariate Gaussian distribution\n\\subsection{Prior Knowledge}\nIn the previous chapter, we derived the probability density function of multivariate Gaussian distribution:\n$$\nx \\backsim N(\\mu, \\Sigma) = \\frac{1}{(2\\pi)^{\\frac{p}{2}}|\\Sigma|^\\frac{1}{2}}\\exp(-\\frac{1}{2}(x-\\mu)^T \\Sigma^{-1}(x-\\mu))\n$$\nNow let's split the random variable $x$ into two parts:\n$$\nx \\in \\mathcal{R}^p \\quad x_a \\in \\mathcal{R}^m \\quad x_b \\in \\mathcal{R}^n \\quad m+n=p \\quad \n$$\n$$\nx = \n\\left (\n\\begin{matrix}\nx_a \\\\\nx_b \\\\\n\\end{matrix}\n\\right )\n\\quad \n\\mu = \n\\left (\n\\begin{matrix}\n\\mu_a \\\\\n\\mu_b \\\\\n\\end{matrix}\n\\right ) \\quad\n\\Sigma=\n\\left (\n\\begin{matrix}\n\\Sigma_{aa} & \\Sigma_{ab}\\\\\n\\Sigma_{ba} & \\Sigma_{bb}\\\\\n\\end{matrix}\n\\right )\n$$\n\\subsection{Theorem}\n$$\nX \\sim N(\\mu, \\Sigma) \\quad Y=AX+B  \\Longrightarrow Y \\sim N(A\\mu+B, A \\Sigma A^T)\n$$\n\\subsection{Derive Marginal Distribution}\n$$\nx_a = \\left (\\begin{matrix}I & 0\\end{matrix}\\right )\\left (\\begin{matrix}x_a \\\\x_b\\\\\\end{matrix}\\right ) + 0\n$$\n$$\nE[x_a] = \\left (\\begin{matrix}I & 0\\end{matrix}\\right )\\left (\\begin{matrix}\\mu_a \\\\\\mu_b \\\\\\end{matrix}\\right ) = \\mu_a\n$$\n$$\n\\begin{aligned}Var[x_a] &= \\left (\\begin{matrix}I & 0\\end{matrix}\\right )\\left (\\begin{matrix}\\Sigma_{aa} & \\Sigma_{ab} \\\\\\Sigma_{ba} & \\Sigma_{bb} \\\\\\end{matrix}\\right )\\left (\\begin{matrix}I \\\\0\\end{matrix}\\right ) \\\\&= \\left (\\begin{matrix}\\Sigma_{aa} & \\Sigma_{ab} \\end{matrix}\\right )\\left (\\begin{matrix}I \\\\0\\end{matrix}\\right )\\\\&=\\Sigma_{aa}\\end{aligned}\n$$\n$$\n\\therefore x_a \\sim N(\\mu_a, \\Sigma_{aa})\n$$\n\\subsection{Derive conditional Distribution}\nLet's set:\n$$\n\\begin{cases}\nx_{b.a}=x_b - \\Sigma_{ba} \\Sigma_{aa}^{-1} x_a \\\\\n\\mu_{b.a} = \\mu_b - \\Sigma_{b.a} \\Sigma_{aa}^{-1} \\mu_a \\\\\n\\Sigma_{bb.a}=\\Sigma_{bb} - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\Sigma_{ab}\n\\end{cases}\n$$\n$$\n\\begin{aligned}\nx_{b.a} &= x_b - \\Sigma_{ba} \\Sigma_{bb}^{-1} x_a \\\\\n&=\n\\left (\n\\begin{matrix}\n- \\Sigma_{ba} \\Sigma_{bb}^{-1} & I\\\\\n\\end{matrix}\n\\right )\n\\left (\n\\begin{matrix}\nx_a \\\\\nx_b \\\\\n\\end{matrix}\n\\right ) + 0\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nE[x_{b.a}]\n&=\n\\left (\n\\begin{matrix}\n-\\Sigma_{ba} \\Sigma_{aa}^{-1} & I\n\\end{matrix}\n\\right )\n\\left (\n\\begin{matrix}\n\\mu_a \\\\\n\\mu_b \\\\\n\\end{matrix}\n\\right )\\\\\n&=\\mu_b - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\mu_a\\\\\n&=\\mu_{b.a}\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nVar[x_{b.a}]\n&= \\left ( \\begin{matrix}\n-\\Sigma_{ba} \\Sigma_{aa}^{-1} & I\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\n\\Sigma_{aa} & \\Sigma_{ab} \\\\\n\\Sigma_{ba} & \\Sigma_{bb} \\\\\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\n-\\Sigma_{aa}^{-1} \\Sigma_{ba}^T \\\\\nI\n\\end{matrix} \\right ) \\\\\n&=\\left ( \\begin{matrix}\n0 & \\Sigma_{bb} - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\Sigma_{ab} \\\\\n\\end{matrix} \\right ) \n\\left ( \\begin{matrix}\n-\\Sigma_{aa}^{-1} \\Sigma_{ba}^T \\\\\nI\n\\end{matrix} \\right ) \\\\\n&=\\Sigma_{bb} - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\Sigma_{ab}\\\\\n&=\\Sigma_{bb.a}\n\\end{aligned}\n$$\n$$\n\\therefore x_{b.a} \\sim N(\\mu_{b.a}, \\Sigma_{bb.a})\n$$\n$$\n\\begin{cases}\n\\mu_{b.a} = \\mu_b - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\mu_a \\\\\n\\Sigma_{bb.a}=\\Sigma_{bb} - \\Sigma_{ba} \\Sigma_{aa}^{-1} \\Sigma_{ab}\n\\end{cases}\n$$\nWe slightly modify the formula:\n\n$$\n\\begin{aligned}\nx_{b.a}\n&=x_b - \\Sigma_{ba} \\Sigma_{aa}^{-1} x_a\\\\\nx_b | x_a&=x_{b.a} + \\Sigma_{ba} \\Sigma_{aa}^{-1} x_a\\\\\n&=I x_{b.a} + C\\\\\n\\end{aligned}\n$$\nHere, all parts of the covariance matrix  $\\Sigma_{ba} \\ \\Sigma_{aa}$  can be calculated, so it can be regarded as a constant.\\\\\\\\\nAnd what we're asking for here is $x_b | x_a$, so $x_a$ is also known, so the second term of the above formula can be regarded as a constant.\\\\\\\\\ntherefore:\n$$\nE[x_b|x_a]=I E[x_{b.a}] + C = \\mu_{b.a} + \\Sigma_{ba} \\Sigma_{aa}^{-1} x_a\n$$\n$$\nVar[x_b|x_a]=IVar[x_{b.a}]I^T=\\Sigma_{bb.a}\n$$\nthen we get the conditional probability of multivariate gaussian distribution:\n$$\nx_b|x_a \\sim N(\\mu_{b.a} + \\Sigma_{ba} \\Sigma_{aa}^{-1} x_a, \\Sigma_{bb.a})\n$$\n\\end{document}", "meta": {"hexsha": "055968d4b36fd6285571e8e8a981f95efdc1713b", "size": 4131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EN-TeX_files/Intro_Math/03_fundamentals-of-math_gaussian-distribution_marginal-probability&conditonal-probability.tex", "max_stars_repo_name": "btobab/Machine-Learning-notes", "max_stars_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-28T18:47:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T07:36:27.000Z", "max_issues_repo_path": "EN-TeX_files/Intro_Math/03_fundamentals-of-math_gaussian-distribution_marginal-probability&conditonal-probability.tex", "max_issues_repo_name": "btobab/Machine-Learning-notes", "max_issues_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "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": "EN-TeX_files/Intro_Math/03_fundamentals-of-math_gaussian-distribution_marginal-probability&conditonal-probability.tex", "max_forks_repo_name": "btobab/Machine-Learning-notes", "max_forks_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-28T18:47:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-28T18:47:22.000Z", "avg_line_length": 25.81875, "max_line_length": 363, "alphanum_fraction": 0.6247881869, "num_tokens": 1594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6326698750943811}}
{"text": "\n\n\\chapter{Blind Source Separation on the Sphere}\n\\label{ch_mrs_ica}\n\n\\section{Introduction}\n\\index{blind source separation}\n\\index{ICA}\n\nBlind Source Separation (BSS) is a problem that occurs in multi-dimensional data processing. The overall goal is to recover \nunobserved signals, images or sources $S$ from mixtures of these sources $X$ observed typically at the output of an \narray of sensors. The simplest mixture model takes the form:\n\\begin{equation}\\label{model0}\nX = A S\n\\end{equation}\nwhere $X$ and $S$ are random vectors of respective sizes $m \\times 1$, $n \\times 1$ and $A$ is an $m \\times n$ matrix. The \nentries of $S$ are assumed to be independent random variables. Multiplying $S$ by $A$ linearly mixes the $n$ sources into \n$m$ observed processes. \\\\ \n   \nIndependent Component Analysis methods were developed to solve the BSS problem, i.e. given a batch of $T$ observed \nsamples of $X$, estimate the mixing matrix $A$ and reconstruct the corresponding $T$ samples of the source vector $S$, relying \nmostly on the statistical independence of the source processes. Note that with the above model, the independent sources can \nonly be recovered up to a multiplication by a non-mixing matrix i.e. up to a permutation and a scaling of the \nentries of $S$. Although independence is a strong assumption, it is in many cases physically plausible. The point is that \nit goes beyond the simple second order decorrelation obtained for instance using Principal Component Analysis (PCA) : decorrelation \nis not enough to recover the source processes since any rotation of a white random vector remains a white random vector.\\\\\n\nAlgorithms for blind component separation and mixing matrix estimation depend on the model used for the probability distribution \nof the sources. In a first set of techniques, source separation is achieved in a noise-less setting, based on the \nnon-Gaussianity of all but possibly one of the components. Most mainstream Independent Component Analysis (ICA)  techniques belong to this category : JADE~\\citep{ica:jade}, \nFastICA, Infomax~\\citep{ica:icabook}. In a second set of blind techniques, the components are modeled as Gaussian processes, either \nstationary or non stationary and, in a given representation, separation requires that the sources have diverse, i.e. non \nproportional, variance profiles. The Spectral Matching ICA method (SMICA) ~\\citep{ica:Del2003}, considers in this sense the case of \nmixed stationary Gaussian components and goes further than the above model Eq.~\\eqref{model0} by taking into account additive \ninstrumental noise $N$:\n\\begin{equation}\\label{model1}\nX = A S + N\n\\end{equation}\nMoving to a Fourier representation, the idea is that colored components can be separated based on the diversity of their power spectra.\\\\ \n \nThe next  section give a short overview of two significant ICA methods mentioned above and implemented in the \\mrs package: \nJADE  and FastICA ~\\citep{ica:icabook}. \nThis is followed by a description of ways to \ncombine wavelets and ICA techniques. Some useful properties of wavelet transforms can indeed come enhance the performance of ICA  methods in several situations. \nFinally, we present the method GMCA, which performs a blind source separation using the the sparsity concept.\n    \n\\section{JADE}\n\\index{ICA!jade}\n\nThe Joint Approximate Diagonalization of Eigenmatrices method (JADE) assumes the observed data $X$ follows the noiseless mixture \nmodel~\\eqref{model0} where the independent sources $S$ are non-Gaussian i.i.d.\\footnote{The letters i.i.d. stand for \nindependently and identically distributed meaning that each entries of $X$ at a given time $t$ are independent of $X$ at any other \ntime $t'$ and that the distribution of $X$ does not depend on time.} random processes. The mixing matrix is assumed to be square \nand invertible so that (de)mixing is actually just a change of basis.\n\nAs mentioned above, second order statistics do not retain enough information for source separation in this context: finding a change of \nbasis in which the data covariance matrix is diagonal will not in general enable to identify the independent sources properly. Nevertheless, \ndecorrelation is half the job~\\citep{ica:tutorial} and one may seek the basis in which the data is represented by maximally independent \nprocesses among those bases in which the data is decorrelated. This leads to so-called orthogonal algorithms: after a proper whitening of \nthe data by multiplication with the inverse of a square root of the covariance matrix of the data $W$, one is then seeking a rotation $R$ \n(which leaves things white) so that $\\hat{ S}$ defined by\n\\begin{equation}\n\\hat{ S} = W^{-1} \\, Y =  W^{-1}\\, R \\, X_{\\textrm{white}}  = W^{-1}\\, R \\, W \\, X \n\\end{equation}\nand $\\hat{B} = \\widehat{A^{-1}} =  W^{-1}\\, R \\, W$ are estimations of the sources and of the inverse of the mixing matrix.\\\\\n\nJADE is such an orthogonal ICA method and, like most mainstream ICA techniques, it exploits higher order statistics so as to achieve some \nsort of non linear decorrelation. Precisely, in the case of JADE, statistical independence is assessed using fourth order cross cumulants : \n%\\begin{eqnarray} \\nonumber\t \n%F_{ijkl} & = & \\textrm{cum}( y_i, y_j, y_k, y_l ) \\nonumber \\\\\n%  & = & \\mathcal{E} (y_i y_j y_k y_l) - \\mathcal{E} (y_i y_j)\\mathcal{E} (y_k y_l) \\nonumber \\\\\n%  & & -\\mathcal{E} (y_iy_l)\\mathcal{E} ( y_j y_k)-\\mathcal{E} (y_iy_k)\\mathcal{E} (y_j y_k)\n%\\end{eqnarray}\n\\begin{eqnarray} \\nonumber\nF_{ijkl} & = & \\textrm{cum}( y_i, y_j, y_k, y_l ) \\nonumber \\\\\n & = & \\mathcal{E} (y_i y_j y_k y_l) - \\mathcal{E} (y_i y_j)\\mathcal{E} (y_k y_l) -\\mathcal{E} (y_iy_l)\\mathcal{E} ( y_j y_k)-\\mathcal{E} (y_iy_k)\\mathcal{E} (y_j y_k)\n\\end{eqnarray}\nwhere $\\mathcal{E}$ stands for statistical expectation and the $y_i$'s are the entries of vector $Y$ modeled as random variables, \nand the correct change of basis (i.e. rotation) is found by somehow diagonalizing the fourth order cumulant tensor. \nIndeed, if the $y_i$'s were independent, all the cumulants with at least two different indices would be zero. As a consequence of \nthe independence assumption of the source processes $S$ and of the whiteness of $Y$ for all rotations $R$, the fourth order \ntensor $F$ is well structured: JADE was precisely devised to take advantage of the algebraic properties of $F$. JADE's objective \nfunction is given by\n\\begin{eqnarray}  \\nonumber\t \n%\\mathcal{J}_{\\textrm{jade}}( R )   &=& \\sum _{ijkl \\ne ijkk}  \\textrm{cum}(  y_i, y_j, y_k, y_l )^2  \\nonumber    \\\\\n  \\mathcal{J}_{\\textrm{jade}}( R ) & =&  \\sum _{ij}   \\sum_{k \\ne l} \\textrm{cum}(  y_i, y_j, y_k, y_l )^2  \n\\end{eqnarray}\nwhich can be interpreted as a joint diagonalization criterion. Fast and robust algorithms are available for the minimization \nof $\\mathcal{J}_{\\textrm{jade}}( R )$ with respect to $R$ based on Jacobi's method for matrix diagonalization~\\citep{ica:pham2001}. \nMore details on JADE can be found in~\\citep{ica:jade,ica:tutorial,ica:icabook}.\n\n\n\\subsubsection{JADE for spherical maps}\n\nApplying JADE on multichannel data mapped to the sphere does not require any particular modification of the algorithm. Indeed, JADE estimates \nthe fourth order cumulant tensor from the available data samples assuming an i.i.d. random field. Hence, given a pixelization scheme on \nthe sphere such as provided by the Healpix package, JADE can be directly applied to the multichannel spherical data pixels.\n\n\n\\section{FastICA}\n\\index{ICA!fastica}\n\nFastICA is by now a standard technique in ICA. Like JADE, it is meant for the analysis of mixtures of independent non-Gaussian sources in \na noise-less setting. A complete description of this method can be found in \\citep{ica:icabook} and references therein\\footnote{Many papers on this \nalgorithm are available at http://www.cs.helsinki.fi/u/ahyvarin/papers/fastica.shtml}. We give here a brief and simplified account \nof the algorithm. FastICA, again like JADE, is a so-called orthogonal ICA method: the independent components are sought by maximizing a \nmeasure of non-Gaussianity under the constraint that they are decorrelated. Intuitively, one should understand that mixtures of independent \nnon-Gaussian random variables tend to look more Gaussian. An enlightening view on the relation between mutual information, which is \na natural measure of independence, decorrelation and non-Gaussianity can be found in~\\citep{ica:3easy,ica:geomindep}. Non-Gaussianity is assessed \nin FastICA using a contrast function $G$ based on a non-linear approximation to negentropy~\\citep{ica:icabook}. In practice, depending \non the application, different approximations or non-linear (non-quadratic) functions should be experimented with. In a simple deflation scheme, \nfor sphered data, the directions are found sequentially : a direction $r$ of maximal non-Gaussianity is sought by maximizing\n\\begin{equation}\nJ_G(r) = \\Big( \\mathcal{E} \\{ G(r^T x_{\\textrm{white}}  ) \\} - \\mathcal{E} \\{ G(\\nu ) \\} \\Big)^2 \n\\end{equation}\nwhere $\\nu$ stands for centered unit variance Gaussian variable, under the constraint that $r$ has unit norm and that $r$ is orthogonal \nto the directions found previously.\\\\ \\\\\nThe contrast function $G$ can for instance be chosen among the following~\\citep{ica:icabook}:\n\\begin{eqnarray}\nG_0 (u)  & = &  \\frac{1}{a} \\textrm{log}\\,\\textrm{cosh} (a u ) \\nonumber    \\\\\nG_1 (u)  & = &  -\\frac{1}{a} \\textrm{exp}(- a u^2 / 2 )   \\nonumber\t   \\\\\nG_2 (u)  & = &  \\frac{1}{4} u^4 \\nonumber    \\\\\n\\end{eqnarray}\nwhere $a$ is a constant to be determined depending on the application. It can be shown that the maxima of $J_G$ occur at certain maxima \nof $\\mathcal{E} \\{ G(r^T x_{\\textrm{white}} ) \\} $. These are obtained for $r$ solution to :\n\\begin{equation}\n\\mathcal{E} \\{ x_{\\textrm{white}} g(r^T x_{\\textrm{white}}  ) \\} - \\lambda r = 0 \n\\end{equation}\nwhere $\\lambda$ is a constant easily expressed in terms of the optimal direction $r_0$, and $g$ is the derivative of $G$. Solving this \nequation using Newton's method, and a few approximations, a fixed-point algorithm is derived which consists in repeating the \nfollowing two steps until convergence :\n\\begin{eqnarray}\nr  & \\leftarrow & \\mathcal{E} \\{ x_{\\textrm{white}} g(r^T x_{\\textrm{white}}  ) \\} - \\mathcal{E} \\{ g'(r^T x_{\\textrm{white}}  ) \\} r     \\nonumber  \\\\\nr  & \\leftarrow  &  \\frac{r}{\\| r \\|}   \\nonumber\t   \\\\\n\\end{eqnarray}\nA simple implementation of this algorithm is included in the present package. It is largely based on the $\\textbf{Matlab}^{TM}$ code \navailable at www.cis.hut.fi/projects/ica/fastica/. \n\n \n\\section{Wavelet and BSS} \n\\index{wavelet!ICA}\n\\index{ICA!wavelet}\n\n\\label{sec:wjade}\n\\index{ICA!wjade}\n\\index{jade!wavelet}\n\nWavelets come into play as a sparsifying transform. Applying a wavelet transform on both sides of~\\eqref{model0} does not affect the \nmixing matrix and the model structure is preserved. Also, moving the data to a wavelet representation does not affect its information \ncontent. However, the statistical distribution of the data coefficients in the new representation is different: wavelets are known to \nlead to sparse i.i.d. representations of structured data. Further, the local (coefficient wise) signal to noise ratio \ndepends on the choice of a representation. A wavelet transform tends to grab the informative coherence between pixels while averaging \nthe noise contributions, thus enhancing structures in the data. Although the standard ICA model~\\eqref{model0} is for a noiseless setting, \nthe derived methods can be applied to real data. Performance will depend on the detectability of significant coefficients i.e. on \nthe sparsity of the statistical distribution of the coefficients. Moving to a wavelet representation will often lead to more robustness to noise.    \n\nOnce the data has been transformed to a proper representation (e.g. wavelets but also ridgelets and curvelets in the case of strongly \nanisotropic 2D or 3D data), WJADE (resp. WFastICA) consists in applying the standard JADE (resp. FastICA) method to the new multichannel coefficients. Once the mixing matrix \nis estimated, the initial source maps are obtained using the adequate inverse transform after some non linear denoising or thresholding of \nthe coefficients if necessary.\n\n\n\\section{Sparse Blind Source Separation: the GMCA method}\n% \\section{Generalized Morphological Component Analysis on the sphere}\n\\label{sec:gmca}\n\n\\subsection{Morpho-Spectral Diversity}\n%\\label{sec:morph-spec-diversity}\nExtending the redundant representation framework to the multichannel case requires defining what a multichannel overcomplete representation is.\nLet us assume in this section that $\\A = [\\varphi_{\\nu,1}, \\cdots, \\varphi_{\\nu, N_c}] \\in \\RR^{N_c \\times N_s}$ is a \\textit{known spectral} dictionary, \nand $\\W = [ \\varphi_{1}, \\cdots, \\varphi_{T}] \\in \\RR^{N \\times T}$ is a \\textit{spatial} or \\textit{temporal} dictionary\\footnote{The adjectives \n\\textit{spectral} and \\textit{spatial} that characterize the dictionaries are not formal. Owing to the symmetry of the multichannel sparse decomposition problems, \n$\\A$ and $\\W$ have no formal difference. In practice and more particularly in multi/hyperspectral imaging, $\\A$ will refer to the dictionary of physical spectra \nand $\\W$ to the dictionary of image/signal waveforms. In the BSS problem, $\\A$ is unknown.}. We assume that each source $s_i$ can be represented as \na (sparse) linear combination of atoms in $\\W$; $s_i=\\W\\alpha_i$. Let $\\balpha$ the $N_s \\times T$ matrix whose rows are $\\alpha_i^\\Tr$.\n\nFrom Eq.~\\eqref{model0}, the multichannel noiseless data $\\bY$ can be written as\n\\be\n\\label{eq:tensor1}\n\\bY = \\A\\balpha\\W^\\Tr = \\sum_{i=1}^{N_s}\\sum_{j=1}^{T} \\parenth{\\varphi_{\\nu,i}\\varphi_{j}^\\Tr}\\alpha_i[j] ~.\n\\ee\nConsequently, each column in of $\\bY$ reads\n\\be\n\\label{eq:tensor2}\n\\bY[.,l] = \\parenth{\\A \\otimes \\W[l,.]} \\mathrm{vect}(\\balpha) ~, \\quad \\forall ~ l=1,\\cdots,N ~,\n\\ee\nand finally\n\\be\n\\label{eq:tensor3}\n\\mathrm{vect}(\\bY) = \\parenth{\\A \\otimes \\W} \\mathrm{vect}(\\balpha) ~,\n\\ee\nwhere $\\otimes$ is the tensor (Kronecker) product and the operator $\\mathrm{vect}$ stacks the columns of its argument in a long 1D vector. \nThis latter equation brings a clear and simple insight: the sparsity of the sources in $\\W$ translates into sparsity of the multichannel data \n$\\bY$ in the multichannel tensor product dictionary ${\\bf \\Psi}=\\A \\otimes \\W$. \n\nThe multichannel dictionary $\\bf \\Psi$ can also be seen as concatenation of multichannel atoms ${\\bf \\Psi}^{(ij)}=\\varphi_{\\nu,i}\\varphi_{j}^\\Tr$ \nwhich are rank-one matrices obtained from each atomic spectrum $\\varphi_{\\nu,i}$ and each spatial elementary atom $\\varphi_{j}$ (see Eq.~\\eqref{eq:tensor1}). \n\nSome of the popular recovery results in sparse component analysis algorithm rely on the mutual coherence of \nthe dictionary~\\citep{cur:elad02,miki:Gribonval-Nielsen,mca:Donoho-Elad}. In the multichannel case a quantity \nof that kind can be defined. In fact, by standard properties of the tensor product, one can easily show that \nthe Gram matrix of a tensor product is the tensor product of the Gram matrices. Thus the mutual coherence of the multichannel dictionary $\\bf \\Psi$ is:\n\\index{coherence}\n\\begin{equation}\n\\label{eq:mmc}\n0 \\le \\mu_{\\bf \\Psi}  =  \\max\\left\\{\\mu_{\\A},\\mu_{\\W}\\right\\} < 1 ~ .\n\\end{equation}\n\nThis expression of mutual coherence is instructive as it tells us that multichannel atoms can be distinguished \nbased on their spatial or spectral morphology. In other words, discriminating two multichannel atoms $\\Psi_{ij}$ and $\\Psi_{i'j'}$ may put on different faces:\n\\begin{itemize}\n\\item{Spatial or temporal (respectively spectral) diversity:} in this case $i=i'$ and $j \\neq j'$ (respectively $i \\neq i'$ and $j = j'$). \nThese atoms have the same spectrum (respectively, spatial shape) but one can discriminate between them based on their \nspatial (respectively, spectral) diversity. From \\eqref{eq:mmc}, their coherence is lower than $\\mu_{{\\W}}$ (respectively $\\mu_{{\\A}}$). \nDisentangling these multichannel atoms can equivalently be done in \\ref{ch_sca_datarest}.\n\n\\item{Both diversities:} $i \\neq i'$ and $j \\neq j'$, this seems to be a more favorable scenario to differentiate \nthe atoms as they do not share neither the same spectrum nor the same spatial (or temporal) ``shape\". Note that \nfrom \\eqref{eq:mmc}, the coherence between these atoms in this case is lower than $\\mu_{{\\A}}\\mu_{{\\W}} \\le \\max\\left\\{\\mu_{\\A},\\mu_{\\W}\\right\\}$.\n\\end{itemize}\n\n\\subsection{Multichannel Sparse Decomposition}\n\nWe embark from Eq.~\\eqref{eq:tensor1}, where the multichannel dictionary ${\\bf \\Psi}$ is supposed to be overcomplete, i.e. $NN_c < TN_s$. \nThe goal is to recover the sparsest solution $\\balpha$ from $\\bY$ which requires solving:\n\\begin{equation}\n\\label{eq:multi_l0}\n\\min_{\\balpha \\in \\RR^{N_s \\times T}} \\sum_{i=1}^{N_s}\\norm{\\alpha_i}_{0} \\st \\bY  = \\A \\balpha \\W^\\Tr.\n\\end{equation}\nAs justified in \\ref{sect_mca}, this combinatorial problem can be replaced by its convex relaxation substituting the $\\ell_1$ norm for the $\\ell_0$ pseudo-norm, hence giving:\n\\begin{equation}\n\\label{eq:multi_l1}\n\\min_{\\balpha \\in \\RR^{N_s \\times T}} \\sum_{i=1}^{N_s}\\norm{\\alpha_i}_{1} \\st \\bY  = \\A \\balpha \\W^\\Tr.\n\\end{equation}\n\nAs \\eqref{eq:tensor3} is a vectorized monochannel form of \\eqref{eq:tensor1}, what we are trying so do is actually to find \nthe sparsest solution of a monochannel underdetermined system of linear equations where the solution is sparse in an \novercomplete tensor product dictionary. Recovery properties of monochannel sparse decomposition by $\\ell_1$ minimization \nwere overviewed in chapter~\\ref{ch_sca_datarest}. Therefore, if one is able to translate those identifiability criteria \nin the language of tensor product dictionaries, then we are done.\n\nIn particular, the coherence-based sparse recovery criterion given in \\citep{DonohoHuo} is trivial to adapt owing to \\eqref{eq:mmc}. \nIndeed, if $\\bY$ is $k$-sparse in the multichannel dictionary ${\\bf \\Psi}$ with $k < C(\\mu_{{\\bf \\Psi}}^{-1}+1)$ for some $C > 0$ (typically $C=1/2$), \nand the dictionary is sufficiently incoherent (both spectrally and spatially), then the solution of Eq.~\\eqref{eq:multi_l1} is unique, \nis a point of equivalence of Eq.~\\eqref{eq:multi_l0} and Eq.~\\eqref{eq:multi_l1}, and the recovery is stable to bounded noise on $\\bY$. \n\nAbove, we addressed the multichannel sparse decomposition problem without assuming any constraint on the sparsity pattern \nof the different channels. It is worth however pointing out that sparse recovery conditions from multichannel measurements \ncan be refined if some structured sparsity is hypothesized. For instance, for structured multichannel representation \n(e.g. sources with disjoint supports) \\citep{GN05} provided coherence-based sufficient recovery conditions by solving Eq.~\\eqref{eq:multi_l1}. \nOne should note that despite apparent similarities, the multichannel sparse decomposition problem discussed here is conceptually \ndifferent from the one targeting \\textit{simultaneous} sparse recovery of multiple measurements vectors (MMV) considered by several authors, see e.g. \n\\citep{CREK05,MalioutovMMV05,TroppMMV06,ChenHuo06,ArgyriouMMVLearning08,BachMMVLearning08,GribonvalMMV08,EldarMMV08,LouniciMMVLearning09,WainwrightMMV09}. \nThe latter are not aware of any mixing process via $\\A$, and their goal is to recover $\\balpha$ from MMV $\\bY=\\balpha\\W^\\Tr$ in which \nthe vectors $\\alpha_i$, i.e. rows of $\\balpha$, have a common sparsity pattern. However the MMV model can also be written \n$\\mathrm{vect}(\\bY^\\Tr) = \\parenth{\\W \\otimes \\I} \\mathrm{vect}(\\balpha^\\Tr)$ as in Eq.~\\eqref{eq:tensor3}. The most widely used approach \nto solve the simultaneous sparse recovery problem with joint sparsity is to minimize a mixed $\\ell_p-\\ell_q$ norm of the form \n$\\sum_{j=1}^T\\parenth{\\norm{\\balpha[.,j]}_p^q}^{1/q}$ for $p \\geq 1, 0 \\leq q \\leq +\\infty$.\n\n\\subsection{Generalized Morphological Component Analysis}\n\\label{subsec:gmca}\nWe now turn to the BSS problem and highlight the role of sparsity and morphological diversity as a source of contrast to solve it. \nTowards this goal, we assume that the sources are sparse in the spatial dictionary $\\W$ that is the concatenation of $K$ orthonormal bases \n$\\parenth{{\\W}_{k}}_{k=1,\\cdots,K}$: $\\W = \\left[{\\W}_{1},\\cdots,{\\W}_{K} \\right]$. The restriction to orthonormal bases is only formal \nand the algorithms to be presented later still work in practice even with redundant sub-dictionaries $\\W_k$. \n\n\\newpage\nThe Generalized Morphological Component Analysis framework assumes a priori that each source is modeled as the linear combination \nof $K$ morphological components where each component is sparse in a specific basis:\n\\begin{eqnarray}\n\\label{eq:sourcecomponents}\n\\forall i \\in \\{1,\\cdots,N_s\\}; \\qquad s_i & = & \\sum_{k=1}^K x_{i,k} = \\sum_{k=1}^K \\W_k\\alpha_{i,k} \\\\\n& = & \\W \\alpha_i \\qquad \\mbox{ where } \\alpha_i =  \\left[\\alpha_{i,1}^\\Tr,\\cdots,\\alpha_{i,K}^\\Tr \\right]^\\Tr ~ \\nonumber\n\\end{eqnarray}\nGMCA seeks an unmixing scheme, through the estimation of $\\A$, which leads to the sparsest sources $\\bf S$ in the dictionary $\\W$. \nThis is expressed by the following optimization problem written in the augmented Lagrangian form:\n\\begin{multline}\n\\label{eq:optimgmca}\n\\min_{{\\A},\\alpha_{1,1},\\cdots,\\alpha_{N_s,K}} \\frac{1}{2}\\norm{\\bY - {\\A}\\balpha\\W^\\Tr}^2_{\\mathrm{F}} + \\lambda \\sum_{i=1}^{N_s} \\sum_{k=1}^K \\norm{\\alpha_{i,k}}_p^p \\\\ \n\\st \\norm{a_i}_2 = 1 ~ \\forall i \\in \\{1,\\cdots,N_s\\} ~\n\\end{multline} \nwhere typically $p=0$ or its relaxed convex version with $p=1$, and $\\norm{{\\bf X}}_{\\mathrm{F}}=\\parenth{\\trace({\\bf X}^\\Tr{\\bf X})}^{1/2}$ is the Frobenius norm. \nThe unit $\\ell_2$-norm constraint on the columns of $\\A$ avoids the classical scale indeterminacy of the product $\\bf AS$ in \\eqref{model1}. \nThe reader may have noticed that the MCA problem in chapter~\\ref{ch_sca_datarest} is a special case of the GMCA problem Eq.~\\eqref{eq:optimgmca} \nwhen there is only one source $N_s=1$ and one channel $N_c=1$ (no mixing). Thus GMCA is indeed a multichannel generalization of MCA. \n\nThe program \\eqref{eq:optimgmca} is a notoriously difficult non-convex optimization problem even for convex penalties when $p \\geq 1$. \nMore conveniently, following \\eqref{model0}, the product $\\bf AS$ can be split into $N_s \\cdot K$ multichannel morphological components: \n${\\bf AS} = \\sum_{i,k} a_i x_{i,k}^\\Tr = \\sum_{i,k} (a_i \\alpha_{i,k}^\\Tr) \\W_k^\\Tr$. Based on this decomposition, and inspired by \nthe block-coordinate relaxation as for MCA, GMCA yields an alternating minimization algorithm to estimate iteratively one term at a time \\citep{starck:bobin07}. \nWe will show shortly that the estimation of each morphological component $x_{i,k} = \\W_k\\alpha_{i,k}$ assuming $\\A$ and $x_{\\{i',k'\\} \\neq \\{i,k\\} }$ \nare fixed is obtained by simple hard or soft thresholding for $p=0$ and $p=1$.\n\nDefine the $(i,k)^{\\textrm{th}}$ multichannel marginal residual by:\n\\begin{equation}\n\\label{eq:gmca_resi}\n{\\bf R}_{i,k} = {\\bY} - \\sum_{i' \\neq i}   \\sum_{k'\\neq k}    a_{i'} x_{i',k'}^\\Tr ~\n\\end{equation} \nas the part of the data $\\bY$ unexplained by the multichannel morphological component $a_i x_{i,k}^\\Tr$. Estimating $x_{i,k} = \\W_{k} \\alpha_{i,k}$, \nassuming $\\A$ and the other components $x_{(i',k') \\neq (i,k)}$ are fixed, leads to the component-wise optimization problem:\n\\begin{equation}\n\\label{eq:componentwisephi}\n\\min_{x_{i,k} \\in \\RR^{N}} \\frac{1}{2}\\norm{{\\bf R}_{i,k} - (a_i \\alpha_{i,k}^\\Tr)\\W^\\Tr}_{\\mathrm{F}}^2 +  \\lambda \\norm{\\alpha_{i,k}}_p^p ~\n\\end{equation}\n\nSince here ${\\W}_k$ is an orthogonal matrix, with calculations using proximity operators, it can be shown that the unique solution \nof Eq.~\\eqref{eq:componentwisephi} is obtained by a hard ($p=0$) or soft ($p=1$) thresholding. Hence, the closed-form estimate of \nthe morphological component $x_{i,k}$ is: \n\\begin{equation}\n\\label{eq:st_update}\n\\tilde{x}_{i,k} = \\Delta_{\\W_k,\\lambda^\\prime} \\parenth{\\frac{1}{\\norm{a_i}_2^2} {\\bf R}_{i,k}^\\Tr a_i} ~\n\\end{equation}\nwhere $\\lambda^\\prime=\\lambda/\\norm{a_i}_2^2$ for soft thresholding and $\\lambda^\\prime=\\sqrt{2\\lambda}/{\\norm{a_i}_2}$ for hard thresholding. \nThe operator $\\Delta_{{\\bf D}, \\lambda}(x)$ consists of (i) computing the coefficients of $x$ in the dictionary ${\\bf D}$, (ii)\nthresholding (soft or hard) the obtained coefficients with the threshold $\\lambda$, and (iii) reconstructing from thresholded coefficients: \n\\begin{equation}\n\\Delta_{{\\bf D},\\lambda}(x) = {\\bf D} \\Thres_{\\lambda} \\left( {\\bf D}^\\Tr x \\right)\n\\end{equation}\n$\\Thres_{\\lambda}$ is either a hard or a soft thresholding. When $\\W_k$ is redundant, \\eqref{eq:st_update} is only the first iteration \nof a forward-backward splitting recursion, and which should be used when $\\W_k$ is overcomplete.\nHowever in practice \\eqref{eq:st_update} can still be used to save computation time.\n\\index{iterative!hard thresholding}\n\\index{iterative!soft thresholding}\n\nNow, considering $\\{a_{i'}\\}_{i' \\neq i}$ and all morphological components as fixed, and recalling that $N_c \\geq N_s$, updating the column $a_i$ is then just a least-squares estimate\n\\begin{equation}\n\\label{eq:a_update}\n\\tilde{a}_i = \\frac{1}{\\norm{s_i}^2_2} \\left({\\bf Y} - \\sum_{i' \\neq i} a_{i'} s_{i'}^\\Tr\\right) s_i ~\n\\end{equation}\nwhere $s_i = \\sum_{k=1}^K x_{i,k}$. This estimate is then projected onto the unit sphere to meet the unit $\\ell_2$-norm constraint in Eq.~\\eqref{eq:optimgmca}.\nThe GMCA algorithm is summarized in Algorithm~\\ref{algo_gmca}.\n\n{\\linespread{1}\n\\begin{algorithm}[htb]\n\\caption{GMCA algorithm.}\n\\label{algo_gmca}\n\\noindent{\\bf Task:} Sparse Blind Source Separation.\\\\\n\\noindent{\\bf Parameters:} The data $\\bY$, the dictionary $\\W=[\\W_1 \\cdots \\W_K]$, number of iterations $\\niter$, number of sources $N_s$ and channels $N_c$, stopping threshold $\\lambda_{\\min}$, threshold update schedule.\\\\\n\\noindent{\\bf Initialization:} $x_{i,k}^{(0)} = 0$ for all $(i,k)$, $\\A^{(0)}$ random and threshold $\\lambda_0$.\\\\\n\\noindent{\\bf Main iteration:} \\\\\n\\For{$t=1$ {\\bf to} $\\niter$}{\n    \\For{$i=1,\\cdots,N_s$ }{\n    \\For{$k=1,\\cdots,K$ }{\n       Compute the marginal residuals: $${\\bf R}_{i,k}^{(t)} = {\\bY}- \\sum_{(i',k') \\neq (i,k)} {a}_{i'}^{{(t-1)}}{x}_{i',k'}^{{(t-1)}^\\Tr}.$$\n       Estimate the current component ${x}_{i,k}^{(t)}$ via thresholding with threshold $\\lambda_t$:\\\\\n       ${x}_{i,k}^{(t)} = \\Delta_{\\W_k, \\lambda_t}\\left({\\bf R}_{i,k}^{{(t)}^\\Tr}{a}_i^{{{(t-1)}}}\\right)$.\n    }\nUpdate $i$th source $s_i^{(t)} = \\sum_{k=1}^K x_{ik}^{(t)}$. \\\\\nUpdate $a_i$ assuming $a_{i' \\neq i}^{(t)}$ and the morphological components $ {x}_{i,k}^{(t)} $ are fixed~:\\\\\n $ {a}_i^{{(t)}} = \\frac{1}{\\|{s}_i^{(t)}\\|_2^2} \\left({\\bY} - \\sum_{i' \\neq i}^{N_s} {a}_{i'}^{(t-1)} {s}_{i'}^{{(t)}^\\Tr} \\right){s}_i^{{(t)}}$ and normalize to a unit $\\ell_2$ norm.\n}\nUpdate the threshold $\\lambda_t$ according to the given schedule.\\\\\n\\lIf{$\\lambda_t \\leq \\lambda_{\\min}$} stop.\n}\n\\noindent{\\bf Output:} Estimated sources $\\big(s^{(\\niter)}_i\\big)_{i=1,\\cdots,N_s}$ and mixing matrix ${\\A}^{(\\niter)}$.\n\\end{algorithm}}\n\nFor $p=1$ and fixed threshold $\\lambda$, Algorithm~\\ref{algo_gmca} can be shown to converge to a stationary point, see \\citep{Tseng01,bobin-gmca-cmb}. \nThis point is not guaranteed to be even a local minimum of the energy, and this is even less clear for $p=0$. Thus, in the same vein as MCA, GMCA relies \non a salient-to-fine strategy using a varying threshold to mitigate the problem of sensitivity to initialization. More precisely, GMCA first computes \ncoarse versions of the morphological components for any fixed source $s_i$. These raw sources are estimated from their most significant coefficients in $\\W$. \nThen, the corresponding column $a_i$ is estimated from the most significant features of $s_i$. Each source and its corresponding column of $\\A$ are then \nalternately and progressively refined as the threshold decreases towards $\\lambda_{\\min}$. This particular iterative thresholding scheme provides robustness \nto noise and initialization by working first on the most significant features in the data and then progressively incorporating smaller details to finely \ntune the model parameters. GMCA can be used with either linear or exponential decrease of the threshold as for MCA.\n\nIf $\\A$ were known and fixed, the GMCA would be equivalent to performing an MCA sparse decomposition of $\\bY$ in the tensor product \nmultichannel dictionary ${\\A} \\otimes \\W$. But as GMCA also updates the mixing matrix at each iteration, it is able to learn the \nspectral part of the multichannel dictionary directly from the data.\n\n\\subsubsection{The Thresholding Strategy}\n\n\\index{iterative!hard thresholding}\n\\index{iterative!soft thresholding}\n\n\\paragraph*{Hard or soft thresholding?} In practice, it was observed that hard thresholding leads to better results \\citep{starck:bobin06,starck:bobin07}. \nFurthermore, if $\\A$ is known and no noise contaminates the data, GMCA with hard thresholding will enjoy the sparse recovery guarantees given in \\citep{starck:bobin_2,BobinJMIV}, \nwith the proviso that the morphological components are contrasted and sparse in a sufficiently incoherent multichannel dictionary ${\\A} \\otimes \\W$. \n%Furthermore in \\citet{starck:bobin_2}, it was shown empirically that the use of hard-thresholding is likely to provide the $\\ell_0$ sparse solution for \n%the single channel sparse decomposition problem. By analogy, the use of a hard-thresholding operator is assumed to solve the multichannel $\\ell_0$ quasi-norm \n%problem instead of \\eqref{eq:optim_l1}. Recent results give also theoretical support to iterative hard thresholding methods \\citep{blumensath08,blumensath09,maleki09,donoho09}.\n\n\\paragraph*{Handling additive Gaussian noise.}\nThe GMCA algorithm is well suited to deal with data contaminated with additive Gaussian noise (see the next section for a Bayesian interpretation). \nFor instance, assume that the noise $\\bf E$ in \\eqref{model1} is additive white Gaussian in each channel, i.e. its covariance matrix \n${\\boldsymbol \\Sigma}_{\\bf E}$ is diagonal, and let $\\sigma_{\\bf E}$ be its standard deviation supposed equal for all channels for simplicity. \nThen, Algorithm~\\ref{algo_gmca} can be applied as described above with $\\lambda_{\\min}=\\tau\\sigma_{\\bf E}$, where $\\tau$ is chosen as in denoising methods, \ntypically taking its value in the range $[3,4]$. This attribute of GMCA makes it a suitable choice for use in noisy BSS. \nGMCA not only manages to separate the sources, but also succeeds in removing additive noise as a by-product.\n\n\\subsection{The Bayesian Perspective}\nGMCA can be interpreted from a Bayesian standpoint. For instance, let us assume that the entries of the mixtures $\\parenth{y_i}_{i=1,\\cdots,N_c}$, \nthe mixing matrix $\\A$, the sources $\\parenth{s_i}_{i=1,\\cdots,N_s}$ and the noise matrix $\\bf E$ are random processes. We assume that the noise \n$\\bf E$ is zero-mean Gaussian where the noise vector $\\veps_i$ in each channel is white, but the noise between channels is possibly correlated with \nknown covariance matrix ${\\boldsymbol \\Sigma}_{\\bf E}$. This means that the log-likelihood function takes the form:\n\\begin{equation}\nLL(\\bY\\big|{\\bf S},{\\A},{\\boldsymbol \\Sigma}_{\\bf E}) = \\frac{1}{2} \\norm{{\\bY} - {\\bf{AS}}}_{{\\boldsymbol \\Sigma}_{\\bf E}}^2 ~,\\ \\text{where} \\norm{\\bf X}_{{\\boldsymbol \\Sigma}_{\\bf E}}^2 = \\trace\\big({\\bf X}^\\Tr{\\boldsymbol \\Sigma}_{\\bf E}^{-1}{\\bf X}\\big)\n\\end{equation}\n\nWe further assume that the uniform prior is imposed on entries of $\\A$. Other priors on $\\A$ could be imposed; e.g. known fixed column for example. \nAs far as the sources are concerned, they are known from \\eqref{eq:sourcecomponents} to be sparse in the dictionary $\\W$. Thus their coefficients \n$\\balpha=[\\alpha_1,\\cdots,\\alpha_{N_s}]^\\Tr$ will be assumed as drawn independently from a leptokurtic PDF with heavy tails \nsuch as the generalized Gaussian distribution form:\n\\begin{multline}\n\\label{eq:indepas}\n\\qquad \\pdf_{\\balpha}(\\alpha_{1,1},\\ldots,\\alpha_{N_s,K}) \\propto \\prod_{i=1}^{N_s}\\prod_{k=1}^{K}\\exp\\parenth{-\\lambda_{i,k}\\norm{\\alpha_{i}}_{p_{i,k}}^{p_{i,k}}} ~ \\\\\n0 \\leq p_{i,k} < 2 ~ \\forall (i,k) \\in \\{1,\\cdots,N_s\\}\\times\\{1,\\cdots,K\\} ~\n\\end{multline}\nPutting together the log-likelihood function and the priors on $\\A$ and $\\balpha$, the MAP estimator leads to the following optimization problem:\n\\begin{equation}\n\\label{eq:optim_bayes}\n\\min_{{\\A},\\alpha_{1,1},\\cdots,\\alpha_{N_s,K}} \\frac{1}{2}\\norm{\\bY - {\\A}\\balpha\\W^\\Tr}^2_{{\\boldsymbol \\Sigma}_{\\bf E}} + \\sum_{i=1}^{N_s} \\sum_{k=1}^K \\lambda_{i,k}\\norm{\\alpha_{i,k}}_{p_{i,k}}^{p_{i,k}} ~\n\\end{equation}\nThis problem has strong similarity with that of Eq.~\\eqref{eq:optimgmca}. More precisely, if the noise is homoscedastic and decorrelated between channels \n(i.e. ${\\boldsymbol \\Sigma}_{\\bf E} = \\sigma_{\\bf E}^2 {{\\bf I}}$), if the shape parameters $p_{i,k}$ of the generalized Gaussian distribution prior \nare all equal to $p$ and the scale parameters are all taken as $\\lambda_{i,k}=\\lambda/\\sigma_{\\bf E}^2$, and if the columns of $\\A$ are assumed uniform \non the unit sphere, then Eq.~\\eqref{eq:optim_bayes} is exactly Eq.~\\eqref{eq:optimgmca}. Note that in the development above, the independence assumption in \\eqref{eq:indepas} \ndoes not necessarily entail independence of the sources. Rather it means that there are no a priori assumptions that indicate any dependency between the sources. \n\n\\subsection{The Fast GMCA Algorithm}\n\\label{gmca_algo}\n\\label{fast_gmca}\nThe goal here is to speed up the GMCA algorithm. As a warm-up, assume that the dictionary ${\\W}$ is no longer redundant and reduces to a single orthobasis (i.e. $K=1$). \nLet us denote $\\Ya=\\bY\\W$ the matrix where each of its rows stores the coefficients of each channel $y_i$. The optimization problem Eq.~\\eqref{eq:optimgmca} then becomes \n(we omit the $\\ell_2$ constraint on $\\A$ to lighten the notation):\n\\begin{equation}\n\\label{eq:optim2}\n\\min_{{\\A},{\\bf \\balpha}} \\frac{1}{2}\\norm{\\Ya - {\\A} \\balpha}_\\mathrm{F}^2 + \\lambda \\sum_{i=1}^{N_s} \\norm{\\alpha_{i}}_p^p ~\n\\end{equation}\nwhere $p=0$ or $p=1$. The GMCA algorithm no longer needs to apply the analysis and synthesis operators at each iteration as only the channels $\\bY$ \nhave to be transformed once in $\\W$. Clearly, this case is computationally much cheaper. \n\nHowever, this is rigorously valid only for an orthobasis dictionary, and no orthonormal basis is able to sparsely represent large variety of signals \nand yet we would like to use very sparse signal representations which motivated the use of redundancy in the first place. Arguments supporting the \nsubstitution of \\eqref{eq:optim2} for \\eqref{eq:optimgmca} for a redundant dictionary ${\\W}$ were given in \\citep{starck:bobin07,bobin08_aiep}. The idea is to first \ncompute the sparsest representation of each channel $y_i$ in the redundant dictionary $\\W$ using an appropriate (non-linear) decomposition algorithm (e.g. BP, MCA). \nNow, $\\Ya$ denotes the matrix where each row contains the sparse decomposition of the corresponding channel. Because the channels are linear mixtures \nof the sources via the mixing matrix $\\A$, the key argument developed by \\citep{starck:bobin07} is that the sparse decomposition algorithm must preserve linear mixtures. \nDescriptively, the sparsest decomposition provided by the algorithm when applied to each channel must be equal to the linear combination of the sparsest \ndecompositions of the sources. This statement is valid if the sources and the channels are identifiable, meaning that they verify sufficient conditions \nso that their unique sparsest representation can be recovered by the decomposition algorithm. For instance, if MCA is used, then it is sufficient as in \n\\citep{starck:bobin_2,BobinJMIV} that the channels and the sources be sparse enough in an incoherent dictionary $\\W$, and their morphological components \nbe sufficiently contrasted. See \\citep{starck:bobin07,bobin08_aiep} for details.\n\nHence, under these circumstances, a fast GMCA algorithm can be designed to solve \\eqref{eq:optim2} by working in the transform domain after decomposing each \nobserved channel $y_i$ in ${\\W}$ using a sparse decomposition algorithm such as MCA. There is an additional important simplification when substituting problem \n\\eqref{eq:optim2} for \\eqref{eq:optimgmca}. Indeed, since $N_c \\geq N_s$ (i.e. overdetermined BSS), it turns out that \\eqref{eq:optim2} is a multichannel overdetermined \nleast-squares fit with $\\ell_0/\\ell_1$-sparsity penalization. We again use an alternating minimization scheme to solve for $\\A$ and $\\balpha$:\n\\index{iterative!hard thresholding}\n\\index{iterative!soft thresholding}\n\\begin{itemize}\n\\item Update the coefficients: when $\\A$ is fixed, since the quadratic term is strictly convex ($\\A$ has full column-rank), the marginal optimization problem \ncan be solved by a general form of the forward-backward splitting iteration \\citep{ChenRockafellar97}:\n\\begin{equation}\n\\balpha^{(t+1)} = \\Thres_{\\mu\\lambda} \\parenth{\\balpha^{(t)} + \\mu{\\boldsymbol \\Xi} \\A^\\Tr(\\Ya - {\\A}\\balpha^{(t)})} ~\n\\end{equation}\nwhere ${\\boldsymbol \\Xi}$ is a relaxation matrix such that the spectral radius of $({\\bf I} - \\mu{\\boldsymbol \\Xi}\\A^\\Tr\\A)$ is bounded above by 1, \nand the step-size $0 < \\mu \\leq 1/\\opnorm{{\\boldsymbol \\Xi}\\A\\A^\\Tr}$. Taking ${\\boldsymbol \\Xi} = (\\A^\\Tr\\A)^{-1}$ ($\\A^\\Tr\\A$ is non-singular \nand a kind of Newton's method ensues) yields the closed-form\n\\begin{equation}\n\\tilde{\\balpha}  =  \\Thres_{\\lambda}\\parenth{\\A^{+}\\Ya}\n\\end{equation}\nwhere $\\Thres_{\\lambda}$ is a thresholding operator (hard for $p=0$ and soft for $p=1$).\n\\item If $\\balpha$ is fixed, and since $\\balpha$ is full row-rank, the mixing matrix $\\A$ is given by the least-squares estimate: \n\\begin{equation}\n{\\bf \\tilde{A}} = \\Ya\\balpha^\\Tr\\parenth{\\balpha\\balpha^\\Tr}^{-1} = \\Ya\\balpha^+ ~\n\\end{equation}\nand the columns of ${\\bf \\tilde{A}}$ are then normalized.\n\\end{itemize}\nNote that the latter two-step estimation scheme has a flavor of the alternating sparse coding/dictionary learning algorithm presented by \\citep{ksvd:elad,fadili:peyrespie07} in a different framework.\n\nThis two-stage iterative process leads to the accelerated version of GMCA summarized in Algorithm~\\ref{algo_fast_gmca}.\n{\\linespread{1}\n\\begin{algorithm}[htb]\n\\caption{Fast GMCA algorithm.}\n\\label{algo_fast_gmca}\n\\noindent{\\bf Task:} Sparse Blind Source Separation.\\\\\n\\noindent{\\bf Parameters:} The data $\\bY$, the dictionary $\\W=[\\W_1 \\cdots \\W_K]$, number of iterations $\\niter$, number of sources $N_s$ and channels $N_c$, \nstopping threshold $\\lambda_{\\min}$, threshold update schedule.\\\\\n\\noindent{\\bf Initialization:} \n\\begin{itemize}\n\\item $\\balpha^{(0)} = 0$,  $\\A^{(0)}$ a random matrix.\n\\item Apply the MCA Algorithm~\\ref{algo_mca} with $\\W$ to each data channel $y_i$ to get $\\Ya$.\n\\item Set threshold $\\lambda_0 = \\max_{i,l}\\abs{\\Ya[i,l]}$.\n\\end{itemize}\n\\noindent{\\bf Main iteration:} \\\\\n\\For{$t=1$ {\\bf to} $\\niter$}{\n\\begin{itemize}\n\\item  Update the coefficients $\\balpha$:\n      ${\\balpha}^{(t+1)} =  \\Thres_{\\lambda_t}\\big({\\A}^{(t)^+} \\Ya\\big)$.\n\\item  Update the mixing matrix $\\A$:\n      ${\\A}^{(t+1)} =   \\Ya\\balpha^{(t+1)^+}$, normalize columns to a unit $\\ell_2$ norm.\n\\item Update  the threshold $ \\lambda_t$ according to the given schedule.\n\\end{itemize}\n\\lIf{$\\lambda_t \\leq \\lambda_{\\min}$} stop.\n}\nReconstruct the sources: $\\tilde{s}_i   =    \\sum_{k=1}^K {\\W}_{k}  \\alpha^{(\\niter)}_{i,k}, i=1,\\cdots,N_s$.\\\\\n\\noindent{\\bf Output:} Estimated sources $\\big(\\tilde{s}_i\\big)_{i=1,\\cdots,N_s}$ and mixing matrix ${\\A}^{(\\niter)}$.\n\\end{algorithm}}\n\nIn the same vein as in Section~\\ref{subsec:gmca}, the coarse-to-fine process is also at the heart of this fast version of GMCA \nwith the threshold that decreases with increasing iteration count. This again brings robustness to noise and initialization.\n\n\n%\\subsection{The GMCA model}\n%\\label{sec:model}\n%\n%The observation with detector $i$ is then a noisy linear mixture of $n$ independent sources $\\{s_j\\}_{j=1,\\cdots,n}$ : \n%$x_i = \\sum_{j=1}^n a_{ij} s_j + n_i$. The coefficient $a_{ij}$ reflects the emission law of source $s_j$ in the \n%frequency band of the $i$-th sensor; $n_i$ models instrumental noise. When $m$ sensors provide observations at \n%different frequencies, this linear mixture model can be rewritten in a more convenient matrix formulation :\n%\\begin{equation}\n%\\label{eq:lm_model}\n%{\\bf X} = {\\bf AS} + {\\bf N}\n%\\end{equation}\n%where ${\\bf X}$ is the $m \\times t$ data matrix the rows of which are the observed data maps in each channel, ${\\bf A}$ \n%is the $m \\times n$ mixing matrix, ${\\bf S}$ is the $n \\times t$ source matrix the rows of which are the sources $s_j$, \n%and ${\\bf N}$ is the $m \\times t$ noise matrix.\n%\n%We further assume that all the protagonists of the model in Equation~\\ref{eq:lm_model} are random components (variables \n%or vectors). More particularly, the entries of the noise matrix ${\\bf N}$ are assumed to be \\textit{independently} \n%distributed according to a zero mean Gaussian distribution with variance $\\sigma_i^2$ depending on the detector. \n%From physical considerations, ${\\bf N}$ models instrumental noise the level of which varies independently from one \n%detector to another. ${\\bf N}$ is thus a random Gaussian variable with zero mean and covariance matrix \n%${\\bf \\Gamma_N} = \\mbox{diag}(\\sigma_1^2,\\cdots,\\sigma_m^2)$. In practice, as the detectors are assumed to be accurately calibrated, \n%${\\bf \\Gamma_N}$ is known with high precision. The log-likelihood function is then the following one :\n%\\begin{equation}\n%\\label{eq:ll}\n%\\log P({\\bf X} \\big| {\\bf A},{\\bf S},{\\bf \\Gamma_N}) = -\\frac{1}{2} \\|{\\bf X} - {\\bf AS}\\|_{2,{\\bf \\Gamma_N}}^2 + C\n%\\end{equation}\n%where $C$ is a constant. The notation $\\| . \\|_{2,{\\bf \\Gamma_N}}^2$ stands for the Frobenius norm of ${\\bf Y}$ in the noise \n%covariance metric : $\\| Y \\|_{2,{\\bf \\Gamma_N}}^2 = \\mbox{Trace}\\left( {\\bf Y}^T {\\bf \\Gamma_N}^{-1} {\\bf Y}\\right)$. \n%From a Bayesian point of view, adding physical priors should help the separation task. We first assume no particular knowledge \n%about the emission laws of the components modeled by ${\\bf A}$. For simplicity, we consider that each entry of the mixing \n%matrix ${\\bf A}$ is \\textit{i.i.d.}\\footnote{Independently and identically distributed.} from a uniform zero mean distribution. \n%Note that it would be possible to add some physical constraint on the emission laws reflected in ${\\bf A}$.\n%\n%In the general case, source separation is merely a question of diversity and contrast between the sources (see \\citep{Cardo1}). \n%For instance, on the one hand JADE relies on non-gaussianity to distinguish between the sources. On the other, SMICA takes advantage \n%of the diversity of the mixed components' power spectra to achieve the separation task. ``Non-gaussianity\" and ``power spectra diversity\" \n%are contrasts between the sources. A combination of both characteristics, ``Non-gaussianity\" and ``power spectra diversity\", \n%was also proposed to separate CMB from kinetic SZ signal which are otherwise undistinguishable \\citep{forni}. Recent work has \n%already emphasized on sparsity as a source of diversity to improve component separation (see \\citep{Zibu} and \\citep{MMCA}). \n%In that setting, each source $\\{s_j\\}_{j=1,\\cdots,n}$ is assumed to be sparse in a representation (potentially overcomplete) $\\mathcal{D}$. \n%Formally, $\\mathcal{D}$ is a fixed dictionary of signal waveforms written as a $T \\times t$ matrix. We define the set of projection \n%coefficients $\\alpha_j$ such that : $\\forall j \\in \\{1,\\cdots,n\\}, \\quad s_j = \\alpha_j \\mathcal{D}$. Any source $s_j$ is said \n%to be sparse in $\\mathcal{D}$ if most of the entries of $\\alpha_j$ are nearly zero and only a few have ``significant\" amplitudes. \n%When $\\mathcal{D}$ is overcomplete ($T > t$), $\\mathcal{D}$ is called a dictionary. Overcomplete representations attractiveness \n%in image processing theory leans on their potential to generate very sparse representations of data based on their morphological \n%content (see e.g. \\citep{DH} and references therein).\n%\n%In the field of basic source separation we showed in \\citep{MMCA} that morphological diversity and sparsity are key properties \n%leading to better separation. We noticed that the gist of sparsity-based source separation methods leans on the rationale : \n%``\\textit{independent sources are distinctly sparse in a dictionary $\\mathcal{D}$}\". In that study, we considered the simple \n%case of morphologically different sources : components were assumed to be sparsely represented in different sub-dictionaries. \n%We illustrated that such sparsity prior provides a very effective way to distinguish between sources. In the present paper, \n%we focus on a more general setting : the sources can have similar morphologies (\\textit{i.e.} all the sources are sparsely \n%represented over the whole $\\mathcal{D}$). When the overcomplete dictionary $\\mathcal{D}$ is made of the union of $D$ orthonormal \n%bases (\\textit{i.e.} $\\mathcal{D} = \\left[\\Phi_1,\\cdots,\\Phi_D\\right]$) then each source is modeled as the linear combination \n%of $D$ so-called morphological components (see \\citep{SED} for details on Morphological Component Analysis) - each morphological \n%component being sparse in a different orthonormal basis $\\{\\Phi_1,\\cdots,\\Phi_D\\}$:\n%\\begin{eqnarray}\n%\\forall j\\in \\{1,\\cdots,n\\}, \\quad s_j & = & \\sum_{k=1}^D \\varphi_{jk} = \\sum_{k=1}^D \\alpha_{jk} \\Phi_k\n%\\end{eqnarray}\n%From a statistical viewpoint, we assume that the entries of $\\alpha_{jk} = \\varphi_{jk}\\Phi_k^T$ are \\textit{i.i.d} from \n%a Laplacian probability distribution with scale parameter $1/\\mu$:\n%\\begin{equation}\n%\\label{eq:source_prior}\n%P(\\varphi_{jk}) \\propto \\exp\\left(- \\mu \\|\\varphi_{jk}\\Phi_k^T\\|_1\\right)\n%\\end{equation}\n%where the $\\ell_1$-norm $\\|.\\|_1$ stands for $\\|x\\|_1 = \\sum_{p=1}^t |x[p]|$ in which $x[p]$ is the $p$-th entry of $x$. In practice, \n%the Laplacian prior is well adapted to model leptokurtic sparse signals. We classically assume that the morphological components are \n%statistically mutually independent : $P({\\bf S}) = \\prod_{j,k} P(\\varphi_{jk})$. Estimating the sources ${\\bf S}$ is then equivalent \n%to estimating the set of morphological components $\\{\\varphi_{jk}\\}_{j=1,\\cdots,n;k=1,\\cdots,D}$. In this Bayesian context, we propose \n%to estimate those morphological components $\\{\\varphi_{jk}\\}$ and the mixing matrix ${\\bf A}$ from a \\textit{maximum a posteriori} (MAP) \n%leading to the following optimization problem:\n%\\begin{equation}\n%\\left\\{\\{\\hat{\\varphi}_{jk}\\},{\\bf \\hat{A}}\\right\\} = {\\arg\\max}_{\\{\\varphi_{jk}\\},{\\bf A}} P({\\bf X}|{\\bf A},\\{\\varphi_{jk}\\},{\\bf \\Gamma_N}) \\prod_{j,k}P(\\varphi_{jk}) P({\\bf A})\n%\\end{equation}\n%where we further assumed that the morphological components $\\{\\varphi_{jk}\\}$ are independent of ${\\bf A}$. Owing to Equations~\\ref{eq:ll} \n%and \\ref{eq:source_prior}, the mixing matrix ${\\bf A}$ and the morphological components $\\{\\varphi_{jk}\\}$ are obtained by minimizing \n%the following negative log \\textit{a posteriori}:\n%\\begin{equation}\n%\\label{eq:optim}\n%\\left\\{\\{\\hat{\\varphi}_{jk}\\},{\\bf \\hat{A}}\\right\\} = {\\arg\\min}_{\\{\\varphi_{jk}\\},{\\bf A}}\\|{\\bf X} - {\\bf AS}\\|_{2,{\\bf \\Gamma_N}}^2 + 2 \\mu \\sum_{j=1}^n \\sum_{k=1}^D \\|\\varphi_{jk}\\Phi_k^T\\|_1\n%\\end{equation}\n%where $\\forall j \\in \\{1,\\cdots,n\\},\\quad s_j = \\sum_{k=1}^D \\varphi_{jk}$. Equation~\\ref{eq:optim} leads to the GMCA estimates \n%of the sources and the mixing matrix in a general sparse component separation context. Interestingly, in the case of CMB data, \n%the sources we look for (CMB, galactic dust and SZ) are quite sparse in the same unique orthonormal wavelet basis. The dictionary\n%$\\mathcal{D}$ then reduces to a single orthonormal basis $\\Phi$. In that case, since $\\Phi$ is unitary, Equation~\\ref{eq:optim} \n%can be rewritten as follows :\n%\\begin{eqnarray}\n%\\label{eq:foptim}\n%\\left\\{{\\bf \\hat{\\alpha}},{\\bf \\hat{A}}\\right\\} &=& {\\arg\\min}_{{\\boldsymbol \\alpha},{\\bf A}} \\|{\\bf X}\\Phi^T - {\\bf A\\alpha}\\|_{2,{\\bf \\Gamma_N}}^2 + 2 \\mu \\|{\\boldsymbol \\alpha}\\|_1 \\nonumber \\\\\n%\t\t\t\t\t\t&=& {\\arg\\min}_{{\\boldsymbol \\alpha},{\\bf A}} f_\\mu({\\boldsymbol \\alpha},{\\bf A}) = {\\arg\\min}_{{\\boldsymbol \\alpha},{\\bf A}} f_0({\\bf A}, {\\boldsymbol \\alpha}) + 2\\mu f_1({\\boldsymbol \\alpha})\n%\\end{eqnarray}\n%where ${\\boldsymbol \\alpha} = {\\bf S}\\Phi^T$. Note that the estimation is done in the sparse representation $\\Phi$ requiring a single \n%transform of the data ${\\bf X}\\Phi^T$. To remain computationally efficient, GMCA relies on practical transforms which generally involve \n%fast implicit operators (typical complexity of $\\mathcal{O}\\left(t\\right)$ or $\\mathcal{O}\\left(t \\log t \\right)$). In \\citep{Zibu}, \n%the authors also used a unique orthonormal wavelet basis. While a gradient descent is used in \\citep{Zibu}, we use a fast and efficient \n%iterative thresholding optimization scheme which we describe in the next section.\n%\n%\\subsection{Solving the optimization problem}\n%\\label{sec:algo}\n%The \\textit{maximum a posteriori} estimates of the coefficients ${\\boldsymbol \\alpha}$ and the mixing matrix in Equation~\\ref{eq:foptim} \n%lead to a non-convex minimization problem. Note that in Equation~\\ref{eq:foptim} the functional to be minimized suffers from several \n%invariances : any permutation or rescaling of the sources and the mixing matrix leaves the product $\\bf A{\\boldsymbol \\alpha}$ unaltered. \n%The scale invariance is computationally alleviated by forcing the columns of ${\\bf A}$ to have unit $\\ell_2$ norm~: $\\forall i\\in{1,\\cdots,n},\\quad a^{i^T}a^i = 1$ \n%where $a^i$ is the $i$-th column of ${\\bf A}$. \n%\n%As solutions of problem~(\\ref{eq:foptim}) have no explicit formulation, we propose solving it by means of a block-coordinate relaxation \n%iterative algorithm such that each iteration $(h)$ is decomposed into two steps : (i) estimation of the sources ${\\bf S}$ assuming the \n%mixing matrix is fixed to its current estimate ${\\bf \\hat{A}}^{(h-1)}$ and (ii) estimation of the mixing matrix assuming the sources are \n%fixed to their current estimates ${\\bf \\hat{S}}^{(h)}$. It is not difficult to see that the objective MAP functional in (\\ref{eq:foptim}) \n%is continuous on its effective domain and has compact level sets. Moreover, this objective function is convex in the source coefficient \n%vectors $(\\alpha_1,\\ldots,\\alpha_n)$, and $f_0$ has an open domain, is continuous and G\\^ateaux differentiable. Thus by \\cite[Theorem 4.1]{Tseng2001}, \n%the iterates generated by our alternating algorithm are defined and bounded, and each accumulation point is a stationary point of the MAP \n%functional. In other words, our iterative algorithm will converge. Hence, at iteration $(h)$, the sources are estimated from a \\textit{maximum a posteriori} \n%assuming ${\\bf A} = {\\bf \\hat{A}}^{(h-1)}$. By classical ideas in convex analysis, a necessary condition for ${\\boldsymbol \\alpha}$ to be \n%a minimizer is that the zero is an element of the subdifferential of the objective at ${\\boldsymbol \\alpha}$. We calculate\\footnote{For clarity, \n%we drop the upper script $(h-1)$ and write $\\hat{\\bf A} = \\hat{\\bf A}^{(h-1)}$.}:\n%\\begin{equation}\n%\\label{eq:subdiff}\n%\\partial_{\\boldsymbol \\alpha} f_\\mu({\\boldsymbol \\alpha},{\\bf A})= -2{\\bf {\\bf A}}^T{\\bf \\Gamma_N}^{-1}({\\bf X}\\Phi^T - {\\bf A}{\\boldsymbol \\alpha}) + 2\\mu \\partial_{\\boldsymbol \\alpha} \\|{\\boldsymbol \\alpha}\\|_1\n%\\end{equation}\n%where $\\partial_{\\boldsymbol \\alpha} \\|{\\boldsymbol \\alpha}\\|_1$ is defined as (owing to the separability of the prior):\n%\\[\n%\\partial_{\\boldsymbol \\alpha} \\|{\\boldsymbol \\alpha}\\|_1 = \\left\\{U \\in \\mathbb{R}^{n \\times t} \\Bigg| \n%\\begin{array}{ccc}\n%U{j,k} & = \\mbox{ sign}(\\alpha_{j,k}), & ~ \\alpha_{j,k} \\neq 0 \\\\\n%U{j,k} & \\in [-1,1], & ~ \\alpha_{j,k} = 0\n%\\end{array} \\right\\}.\n%\\]\n%Hence, Equation \\ref{eq:subdiff} can be rewritten equivalently as two conditions leading to the following (proximal) fixed point equation:\n%\\begin{equation}\n%\\label{eq:it_estim1}\n%\\begin{array}{cc}\n%\\hat{\\alpha}_{j,k} = 0, & \\text{if} ~ \\left|{\\left({\\bf A}^T{\\bf \\Gamma_N}^{-1}{\\bf X}\\Phi^T\\right)}_{j,k} \\right| \\leq \\mu \\\\\n%{\\bf {\\bf A}}^T{\\bf \\Gamma_N}^{-1}({\\bf X}\\Phi^T - {\\bf A}\\hat{\\boldsymbol \\alpha}) = \\mu \\mbox{ sign}\\left(\\hat{\\boldsymbol \\alpha}\\right), & \\text{otherwise}. \n%\\end{array}\n%\\end{equation}\n%Unfortunately, Equation~\\ref{eq:it_estim1} has no closed-form solution in general. It must be iterated and is thus computationally demanding. \n%Fortunately, it can be simplified when ${\\bf A}$ has nearly orthogonal columns in the noise covariance matrix (\\textit{i.e.} \n%${\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}} \\simeq \\mbox{diag}\\left({\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}}\\right)$). \n%Let ${\\bf C} = {\\left({\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}}\\right)}^{-1}{\\bf A}^T{\\bf \\Gamma_N}^{-1}{\\bf X}\\Phi^T$, Equation~\\ref{eq:it_estim1} \n%boils down to the following set of equations $\\forall j\\in\\{1,\\cdots,n\\}$:\n%\\begin{equation}\n%\\label{eq:it_estim}\n%\\begin{array}{ccc}\n%\\hat{\\alpha}_{j,k} & = 0, \\quad \\text{if} ~ \\left|{{\\bf C}}_{j,k} \\right| \\leq \\mu^{(h)} \\sigma_j^2 \\\\\n%\\hat{\\alpha}_j & = {\\left[{\\bf C}\\right]}_j - \\mu \\sigma_j^2  \\mbox{ sign}\\left(\\hat{\\alpha}_j\\right), \\quad \\text{otherwise}.\n%\\end{array}\n%\\end{equation}\n%where $[{\\bf Y}]_j$ is the $j$-th row of ${\\bf Y}$. In practice, even if the approximation we make is not strictly valid, such a simplification \n%leads to good computational results. These equations are known as soft-thresholding with threshold $\\mu^{(h)} \\sigma_j^2$. We define $\\mathrm{ST}_{\\delta}(.)$, \n%the soft-thresholding operator with threshold $\\delta$. At iteration $(h)$, the sources are thus estimated such that:\n%\\begin{equation}\n%\\hat{\\alpha}_j^{(h)} = \\mathrm{ST}_{\\mu^{(h)} \\sigma_j^2}\\left(\\left[{\\bf C}\\right]_j\\right)\n%\\end{equation}\n%The $j$th source is reconstructed as $\\hat{s}_j^{(h)} = \\hat{\\alpha}_j^{(h)}\\Phi$. The mixing matrix ${\\bf A}$ is then estimated by a maximum \n%likelihood estimate amounting to a simple least-squares update assuming ${\\bf S}$ is fixed. The GMCA algorithm is then described in \\ref{algo_gmca}:\n%\n%%\\begin{flushleft}\n%%\\vspace{0.15in}\n%%\\centering\n%%\\begin{tabular}{|c|} \\hline\n%%\\begin{minipage}[h]{0.95\\linewidth}\n%%\\vspace{0.025in} \\footnotesize{\\textsf{1. Set the number of iterations $I_{\\max}$ and thresholds $\\delta_j^{(0)} = \\mu^{(0)}\\sigma_j^2$\\\\} \n%%\\textsf{2. While each $\\mu^{(h)}$ is higher than a given lower bound $\\mu_{min}$ (e.g. can depend on the noise variance), \\\\}\n%%\\hspace{0.1in} \\textsf{-- Proceed with the following iteration to estimate source coefficients ${\\boldsymbol \\alpha}$ at iteration $h$ assuming ${\\bf A}$ is fixed:}\n%%\\hspace{0.2in} \\textsf{$\\hat{\\alpha}_j^{(h)} = \\mathrm{ST}_{\\mu^{(h)} \\sigma_j^2}\\left(\\left[{\\left({\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}}\\right)}^{-1}{\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf X}\\Phi^T\\right]_j\\right)$:\\\\}\n%%\\hspace{0.1in} \\textsf{-- Update $\\bf A$ assuming ${\\boldsymbol \\alpha}$ is fixed :}\n%%\\hspace{0.2in} \\textsf{${\\bf \\hat{A}}^{(h)} = {\\bf X}\\Phi^T{\\bf \\hat{\\boldsymbol \\alpha}}^T\\left({\\bf \\hat{\\boldsymbol \\alpha}}{\\bf \\hat{\\boldsymbol \\alpha}}^T\\right)^{-1}$\\\\}\n%%\\textsf{-- Decrease the threshold $\\mu^{(h)}$ following a given strategy}}\n%%\\vspace{0.05in}\n%%\\end{minipage}\n%%\\\\\\hline\n%%\\end{tabular}\n%%\\vspace{0.15in}\n%%\\end{flushleft}\n%\n%{\\linespread{1}\n%\\begin{algorithm}[h]\n%\\caption{The Generalized Morphological Component Analysis algorithm.}\n%\\label{algo_gmca}\n%\\noindent{\\bf Task:} Compute the GMCA of a discrete $X$.\\\\\n%\\noindent{\\bf Parameters:} Data samples $X$, number of estimated sources $J$, dictionnary $\\Phi$, noise covariance matrix ${\\bf \\Gamma_N}$.\\\\\n%\\noindent{\\bf Initialization:}\n%\\begin{itemize}\n%\\item Set the number of iterations $I_{\\max}$\n%\\item Set the initial thresholds $\\delta_j^{(0)} = \\mu^{(0)}\\sigma_j^2$\n%\\item Set the final thresholds $\\mu_{\\min}$, it can depend on the noise standard deviation\n%\\end{itemize}\n%\\While{ $\\mu^{(h)}_{j} > \\mu_{\\min}$ }{\n%\\begin{enumerate}[1.]\n%\\item estimate source coefficients ${\\boldsymbol \\alpha}$ at iteration $h$ assuming ${\\bf A}$ is fixed :\n%\n%\\lFor{$j = 1, \\cdots, J$}{ $\\hat{\\alpha}_j^{(h)} = \\mathrm{ST}_{\\mu^{(h)} \\sigma_j^2}\\left(\\left[{\\left({\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}}\\right)}^{-1}{\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf X}\\Phi^T\\right]_j\\right)$ }\n%\\item Update $\\bf A$ assuming ${\\boldsymbol \\alpha}$ is fixed :\n%\n%${\\bf \\hat{A}}^{(h)} = {\\bf X}\\Phi^T{\\bf \\hat{\\boldsymbol \\alpha}}^T\\left({\\bf \\hat{\\boldsymbol \\alpha}}{\\bf \\hat{\\boldsymbol \\alpha}}^T\\right)^{-1}$\n%\\item Decrease the threshold $\\mu^{(h)}$ following a given strategy\n%\\end{enumerate}\n%}\n%\\noindent{\\bf Output:} $(\\hat{\\alpha}_j^{(m)})$ $j=1,\\ldots,J$ with $m = I_{\\max}$: coefficients of the separated components.\n%\\end{algorithm}\n%}\n%\n%Note that the overall optimization scheme is based on an iterative and alternate thresholding algorithm involving a \n%\\textit{coarse to fine} estimation process. Indeed, \\textit{coarse} versions of the sources (\\textit{i.e.} containing \n%the most ``significant\" features of the sources) are first computed with high values of $\\mu^{(h)}$.\n%%\\begin{equation}\n%%\\forall j\\in\\{1,\\cdots,n\\},\\quad \\hat{s}_j = \\mathrm{ST}_{\\mu^{(h)} \\sigma_j^2}\\left({\\left({\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf \\hat{A}}\\right)}^{-1}{\\bf \\hat{A}}^T{\\bf \\Gamma_N}^{-1}{\\bf X}\\Phi^T\\right)\\Phi\n%%\\end{equation}\n%In the early stages of the algorithm, the mixing matrix is then estimated from the most ``significant\" features of the sources \n%which are less perturbed by noise. The estimation of ${\\bf A}$ and ${\\bf S}$ is then refined at each iteration as $\\mu^{(h)}$ \n%(and thus the thresholds $\\{\\mu^{(h)}\\sigma_j^2\\}_{j=1,\\cdots,n}$) decreases towards a final value $\\mu_{min}$. We already used \n%this minimization scheme in \\citep{MMCA} where this optimization process provided robustness and helped convergence even in a \n%noisy context. Experiments in Section~\\ref{sec:results} illustrate that it achieves good results with GMCA as well.\n ", "meta": {"hexsha": "17e21e51f5a7fda298e946d027ec46f8cf075775", "size": 58208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/mrs_ica.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_isap/mrs_ica.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_isap/mrs_ica.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": 80.8444444444, "max_line_length": 258, "alphanum_fraction": 0.7251924134, "num_tokens": 17531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6326698743279765}}
{"text": "\\hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1divide}{}\\section{numpp\\+:\\+:differentiation\\+:\\+:symbolic\\+:\\+:divide$<$ Left, Right $>$ Class Template Reference}\n\\label{classnumpp_1_1differentiation_1_1symbolic_1_1divide}\\index{numpp\\+::differentiation\\+::symbolic\\+::divide$<$ Left, Right $>$@{numpp\\+::differentiation\\+::symbolic\\+::divide$<$ Left, Right $>$}}\n\\subsection*{Public Types}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1divide_ac1d7c214342c5429411607c70c1eba2a}\\label{classnumpp_1_1differentiation_1_1symbolic_1_1divide_ac1d7c214342c5429411607c70c1eba2a}} \n{\\footnotesize template$<$std\\+::size\\+\\_\\+t Active$>$ }\\\\using {\\bfseries derivative} = simplify\\+\\_\\+division$<$ simplify\\+\\_\\+subtraction$<$ simplify\\+\\_\\+multiplication$<$ typename Left\\+::template derivative$<$ Active $>$, Right $>$, simplify\\+\\_\\+multiplication$<$ Left, typename Right\\+::template derivative$<$ Active $>$ $>$$>$, \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1power}{power}$<$ Right, 2 $>$ $>$\n\\end{DoxyCompactItemize}\n\\subsection*{Static Public Member Functions}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1divide_abcc37b0e5f45acc06b30bef6f1431a5e}\\label{classnumpp_1_1differentiation_1_1symbolic_1_1divide_abcc37b0e5f45acc06b30bef6f1431a5e}} \nstatic C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto {\\bfseries calculate} (auto \\&\\&values)\n\\end{DoxyCompactItemize}\n\n\nThe documentation for this class was generated from the following file\\+:\\begin{DoxyCompactItemize}\n\\item \ndifferentiation/symbolic/arithmetic.\\+hpp\\end{DoxyCompactItemize}\n", "meta": {"hexsha": "6b469a121363391e33bead69fa813a14e558f02b", "size": 1645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/classnumpp_1_1differentiation_1_1symbolic_1_1divide.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/classnumpp_1_1differentiation_1_1symbolic_1_1divide.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/classnumpp_1_1differentiation_1_1symbolic_1_1divide.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": 82.25, "max_line_length": 426, "alphanum_fraction": 0.7890577508, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145405, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.63266987142957}}
{"text": "\\section{XN: A normalization method based on ReLU1}\nThis section introduces a new kind of parameters normalization methods based on Prof. Xu's idea for ReLU1 activation function.\n\n\\subsection{XN in progress}\nSuppose we have a dataset $\\mathcal{X}\\subset\\mathbb{R}^n$, which has $N$ samples, each sample $x\\in \\mathcal{X}$ with a label $y_x=e_i,i=1,2,...,c$, where $c$ is the number of classes.\n\nConsider a one-hidden-layer neural network \n\\begin{equation}\n\t\\label{1hidden}\n\tf(x)=W_2\\text{ReLU1}(W_1x+b_1)+b_2,  \n\\end{equation}\nwhere $W_1\\in\\mathbb{R}^{n_1\\times n},\\ W_2\\in\\mathbb{R}^{c\\times n_1}$, and a loss function \\[L(X)=\\frac{1}{N}\\sum_{x\\in X}\\|f(x)-y_x\\|^2_2,\\] where $x\\in\\mathbb{R}^n$ is a sample and $y_x=e_i$ is the label. \n%\\subsubsection{Version 1}\n%\\begin{enumerate}\n%\t\\item For an full-batch input matrix $X\\in\\mathbb{R}^{n\\times N}$, where each column of $X$ is a sample, find the rows $y$ of $W_1X+b_1$ s.t. the $i$th element of $y$, denoted as $y_i$, satisfying\n%\t\\begin{equation}\n%\t\ty_i\\notin [0,1], \\quad\\forall i.\n%\t\\end{equation}\n%\tDenoted the corresponding rows of $W_1$ and $b_1$ as $\\bar W$ and $\\bar b$.\n%\t\\item Solve the optimization problem\n%\t\\begin{equation}\n%\t\t\\begin{aligned}\n%\t\t\t\\min_{W,b}&\\quad\\|WX+b - \\text{ReLU1}(\\bar WX+\\bar b)\\|_F\\\\\n%\t\t\t\\text{subject to}&\\quad (WX+b)_{ij}\\leq 0\\text{ or } \\geq 1,\\quad \\forall i,j.\n%\t\t\\end{aligned}\n%\t\\end{equation}\n%\n%\t\\item Replace $\\bar W$ and $\\bar b$ by $W$ and $b$.\n%\\end{enumerate}\n\\subsubsection{XN Version 2}\nXN is independent with the SGD training process.\n\nAfter an update of the neural network, XN can be applied to each hidden layer successively, and won't change the output of it. In this example, we have only one hidden layer. The XN algorithm can be written as follows.\n\\begin{enumerate}\n\t\\item Denote $\\Theta=(W_1\\ b_1)\\in\\mathbb{R}^{n_1\\times(n+1)}$, $\\hat X=(X;\\mathbf{1})\\in\\mathbb{R}^{(n+1)\\times m}$ and $Y=\\text{ReLU1}(W_1X+b_1)$. \n\tSplit the columns of $\\hat X$ to $X_I$, $X_J$, $X_K$, s.t. for every row $\\theta_i$ of $\\Theta$, $i=1,...,n_1$,\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\theta_i X_I\\leq 0,\\\\\n\t\\theta_i X_J\\geq 1,\\\\\n\t\\theta_i X_K\\in[0,1].\n\t\\end{aligned}\n\t\\end{equation}\n\tDenote IJ as the union of I and J. For every $\\theta_i$, the optimization problem can be rewritten as\n\t\\begin{equation}\\label{standardv2opt}\n\t\\begin{aligned}\n\t\\min_\\theta&\\quad\\|\\theta  X_{IJ}-Y_{IJ}\\|_2\\\\\n\t\\text{subject to}&\\quad\\theta X_{I}\\leq 0,\\\\\n\t&\\quad\\theta X_{J}\\geq 1,\\\\\n\t&\\quad\\theta X_{K}=Y_{K}.\n\t\\end{aligned}\n\t\\end{equation}\n\t\n\t\\paragraph{Note}\n\t\\begin{enumerate}\n\t\\item\n\tIf $X_K$ is row full-rank, the problem has only one solution, which is the original $w_1,b_1$.\n\t\\begin{proof}\n\t\tBecause $X_K$ is row full-rank, we have, by definition,\n\t\t\\begin{equation}\n\t\txX_K=0\\Rightarrow x=0.\n\t\t\\end{equation}\n\t\tIf there are $\\theta$, $\\theta'$ s.t.\n\t\t\\begin{equation}\n\t\t\\theta X_K=Y_K,\\quad \\theta' X_K=Y_K,\n\t\t\\end{equation}\n\t\tthen\n\t\t\\begin{equation}\n\t\t(\\theta-\\theta') X_K=0\\Rightarrow \\theta-\\theta'=0.\n\t\t\\end{equation}\n\t\\end{proof}\n\t\\item\n\tIn practice, the cases when the equality constraint \n\t\\begin{equation}\n\t\t\\theta X_K=Y_K\n\t\\end{equation}\n    is under-determined\tappear after several epochs of SGD training.\n\t\\item\n\t\\ref{standardv2opt} is a standard constraint optimization problem, with inequality constraints. It has no explicit solution, and can be solved by algorithms such as interior-point methods, the simplex algorithm, etc. In practice, we may turn to standard libraries to solve it.\n\n\t\\end{enumerate}\n%\t\\begin{equation}\\label{v2opt}\n%\t\t\\begin{aligned}\n%\t\t\t\\min_{W,b}&\\quad\\|(WX+b - \\text{ReLU1}(W_1X+b_1)\\|_F\\\\\n%\t\t\t\\text{subject to}&\\quad (WX+b)_{ij}<0\\text{ or } >1,\\quad \\forall (i,j)\\in Z,\\\\\n%\t\t\t&\\quad (WX+b)_{ij}=(W_1X+b_1)_{ij},\\quad \\forall (i,j)\\notin Z.\n%\t\t\\end{aligned}\n%\t\\end{equation}\n%\n%\t\\eqref{v2opt} is equivalent to solve \n%\t\\begin{equation}\\label{v2eq}\n%\t\tWX-b=Y,\\quad Y_{ij}=(W_1X+b_1)_{ij},\\quad \\forall (i,j)\\notin Z,\n%\t\\end{equation}\n%\twhich is in some sense easier to solve when $Z$ is larger. If $N<n+1$, \\eqref{v2eq} is undetermined in most cases, however this is hard to satisfy.\n\t\\item Replace $W_1$ and $b_1$ by $W$ and $b$. \n\\end{enumerate}\n\n%Consider \\eqref{v2opt}. Denote $\\Theta=(W\\ b)\\in\\mathbb{R}^{n_1\\times(n+1)}$, $\\hat X=(X;\\mathbf{1})\\in\\mathbb{R}^{(n+1)\\times m}$ and $Y=\\text{ReLU1}(W_1X+b_1)$, \n%\\begin{equation}\\label{simplifiedv2opt}\n%\t\\begin{aligned}\n%\t\t\\min_\\Theta&\\quad\\|\\Theta \\hat X-Y\\|_F\\\\\n%\t\t\\text{subject to}&\\quad(\\Theta\\hat X)_{ij}>1\\ or\\ <0,\\quad \\forall(i,j)\\in Z,\\\\\n%\t\t&\\quad(\\Theta\\hat X)_{ij}=Y_{ij},\\quad \\forall (i,j)\\notin Z.\n%\t\\end{aligned}\n%\\end{equation}\n\n\n\\subsubsection{Numerical experiments}\nOur network has two hidden layers, and XN will be applied to the first, second and both hidden layers, separately, i.e. after each update, which is SGD,\n\\begin{enumerate}\n\t\\item apply XN to the first hidden-layer, or\n\t\\item apply XN to the first and the second hidden-layer, or\n\t\\item apply XN to the second hidden-layer.\n\\end{enumerate}\n\\begin{enumerate}\n%\t\\item \\textbf{Version 1.} In \\eqref{v1}, no row $y$ of $W_1X+b_1$ satisfies $y_i\\notin[0,1],\\forall i$, no matter which layer to apply XN. In fact, there are always almost a half of $y_i\\in[0,1]$.\n\t\\item \\textbf{XN Version 2.} \n\t\n\tWhether XN is used or not depends on the equality constraints and the error.\n\t\n\tFigure \\ref{XNv2_Points} shows the loss function on point-separation problem, with XN on different layers. XN is applied only at a few time steps, as follows,\n\t\\begin{enumerate}\n\t\t\\item L, XN. \n\t\t\n\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 14, 15, 16, 17, 34, 35, 36, 101, 102, 975, 978, 982, 987, 988, 989, 1126, 1127, 1128, 1134, 1136, 1141, 1144, 1158, 1163, 1168, 1170, 1171, 1172, 1173, 11411, 11910, 11920, 11922, 11923, 17831, 17836, 17864, 17901, 17902, 17914, 17916].\n\t\t\\item XN, XN. Only second layer uses XN. \n\t\t\n\t\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 17, 18, 115, 127, 16179, 16229, 16240, 16243, 16244, 16248, 16250].\n\t\t\n\t\t\\item XN, L. No layer uses XN.\n\t\\end{enumerate}\n\t\n\t\\begin{figure}[H]\n\t\t\\center\n\t\t\\includegraphics*[width=0.8\\textwidth]{./figures/XNv2_Points.png}\n\t\t\\caption{Loss function on point-separation problem. [2, 20, 64, 9] shows the number of neurons at each layer (one input, two hidden, and one output layer). ['L', 'XN'] means hidden-layer 1 is Linear, and hidden-layer 2 applies XN.}\n\t\t\\label{XNv2_Points}\n\t\\end{figure}\n%\tIn \\eqref{standardv2opt}, if $\\theta X_{K}=Y_{K}$ is overdetermined (for MNIST, it's may be overdetermined, because $X_K\\in\\mathbb{R}^{129\\times m'}$, $m'\\approx 30000$ (the size of the full-batch is 60000)), and \n\t\\begin{figure}[H]\n\t\t\\center\n\t\t\\includegraphics*[width=0.8\\textwidth]{./figures/XNv2_mnist100.png}\n\t\t\\caption{Loss function on 100 samples of MNIST. \\emph{blank} means without XN.}\n\t\t\\label{XNv2_Points}\n\t\\end{figure}\n\t\n\t\\begin{figure}[H]\n\t\t\\center\n\t\t\\includegraphics*[width=0.8\\textwidth]{./figures/XNv2_mnist500.png}\n\t\t\\caption{Loss function on 500 samples of MNIST. \\emph{blank} means without XN. XN is applied successfully after every epoch.}\n\t\t\\label{XNv2_Points}\n\t\\end{figure}\n\n\t\\begin{figure}[H]\n\t\t\\center\n\t\t\\includegraphics*[width=0.8\\textwidth]{./figures/XNv2_mnist500_XN0.png}\n\t\t\\caption{Loss function on 500 samples of MNIST. XN is applied once before SGD.}\n\t\t\\label{XNv2_Points}\n\t\\end{figure}\n\t\n\\end{enumerate}\n\n\\subsubsection{Problems}\n\\begin{enumerate}\n\t\\item \n\tThe optimization problem is very large and the main matrix, $X_{IJ}X_{IJ}^T$, is not SPD, which means the solution is not unique. These make the solving process very time-consuming. This may be worked around by not requiring an optimal solution, but only a slightly better one.\n\t\\item\n\tXN ia not directly applicable for the full MNIST dataset, because the equality constraint is over-determined at each epoch.\n\t\\item\n\tThe generalization ability of XN on MNIST is hard to test, because the subset dataset is too small, and, as a result, both SGD with XN and blank SGD can not make good prediction with it.\n\\end{enumerate}\n\n\n\\subsection{An example of XN (mini-batch version)}\nSuppose we have a dataset $\\mathcal{X}\\subset\\mathbb{R}^n$, which has $N$ samples, each sample $x\\in \\mathcal{X}$ with a label $y_x=e_i,i=1,2,...,c$, where $c$ is the number of classes.\n\nConsider a one-hidden-layer neural network \n\\begin{equation}\n  \\label{1hidden}\nf(x)=W_2\\text{ReLU1}(W_1x+b_1)+b_2,  \n\\end{equation}\nwhere $W_1\\in\\mathbb{R}^{n_1\\times n},\\ W_2\\in\\mathbb{R}^{c\\times n_1}$, and a loss function \\[L(X)=\\frac{1}{N}\\sum_{x\\in X}\\|f(x)-y_x\\|^2_2,\\] where $x\\in\\mathbb{R}^n$ is a sample and $y_x=e_i$ is the label.\n\nTo train $f$ with XN, we have the following algorithm.\n\\begin{enumerate}\n\t\\item Choose an $m$-sample mini-batch $X\\subset\\mathcal{X}$ randomly. $X$ is represented as a matrix $X\\in\\mathbb{R}^{n\\times m}$ , where each column of $X$ is a sample.\n\t\\item Compute the value $f_1$ of the hidden layer on $X$,\n\t\\begin{equation}\n\t\tf_1(X)=\n\t\t\\begin{pmatrix}\n\t\t\tW_1 & b_1\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tX \\\\ \\mathbf{1}\n\t\t\\end{pmatrix}\n\t\t\\in\\mathbb{R}^{n_1\\times m}\n\t\\end{equation}\n\tand the value $f_2$ of the output layer,\n\t\\begin{equation}\n\t\tf_2(x)=\n\t\t\\begin{pmatrix}\n\t\tW_2 & b_2\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\\text{ReLU1}(f_1(X)) \\\\ \\mathbf{1}\n\t\t\\end{pmatrix}\n\t\t\\in\\mathbb{R}^{c\\times m}.\n\t\\end{equation}\n\t\\item (XN) Change the parameters of the hidden layer $W_1$, $b_1$ to $W$, $b$ such that\n\t\\begin{equation}\n\t\t\\begin{pmatrix}\n\t\t\tW & b\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tX \\\\ \\mathbf{1}\n\t\t\\end{pmatrix}\n\t\t=\n\t\t\\text{ReLU1}\\left(\n\t\t\\begin{pmatrix}\n\t\t\tW_1 & b_1\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix}\n\t\t\tX \\\\ \\mathbf{1}\n\t\t\\end{pmatrix}\\right)\n\t\t=\\text{ReLU1}(f_1(X)).\n\t\\end{equation}\n\tDenote $\\Theta=(W\\ b)\\in\\mathbb{R}^{n_1\\times(n+1)}$, $\\hat X=(X;\\mathbf{1})\\in\\mathbb{R}^{(n+1)\\times m}$ and $Y=\\text{ReLU1}(f_1(X))\\in\\mathbb{R}^{n_1\\times m}$, the above equation can be rewritten as \n\t\\begin{equation}\\label{XNeq}\n\t\t\\Theta \\hat X=Y.\n\t\\end{equation} \n\tThe least square problem \n\t\\begin{equation}\\label{XNlst}\n\t\t\\min_\\Theta\\|\\Theta \\hat X-Y\\|_F\n\t\\end{equation}\n\tgives a solution of \\eqref{XNeq} if the minimal value is $0$. To assure $0$ is reachable, note that \\eqref{XNeq} can be expanded as\n\t\\begin{equation}\n\t\t\\bar X\\bar\\Theta=\\bar Y,\\quad\n\t\t\\bar X\\in\\mathbb{R}^{n_1m\\times(nn_1+n_1)},\\ \\bar\\Theta\\in\\mathbb{R}^{nn_1+n_1},\\ \\bar Y\\in\\mathbb{R}^{n_1m\\times(nn_1+n_1)},\n\t\\end{equation}\n\tso we can make $\\bar X$ an underdetermined matrix by requiring $n_1m < nn_1+n_1$, or\n\t\\begin{equation}\n\t\tm < n+1.\n\t\\end{equation}\n\tThat is to say, in a layer, the number of input samples should not be larger than the dimension of a sample. \\eqref{XNlst} can then be solved by LAPACK package directly. \n\tIf \\eqref{XNlst} is not solvable, for example because of a $\\bar X$ with a zero-row, then XN is not applied, i.e. $W_1,\\ b_1$ is not changed.\n\t\n\t\\textbf{Notes}. \n\t\\begin{enumerate}\n\t\t\\item Because $\\hat X$ is not necessarily square, a plausible way to solve \\eqref{XNeq} is by pseudo-inverse,\n\t\t\\begin{align*}\n\t\t\\Theta \\hat X=Y&\\Rightarrow\\Theta \\hat X{\\hat X}^T=Y{\\hat X}^T\\\\\n\t\t&\\Leftrightarrow\\Theta =Y{\\hat X}^T(\\hat X{\\hat X}^T)^{-1}.\n\t\t\\end{align*}\n\t\tHowever, because $\\hat X\\in\\mathbb{R}^{(n+1)\\times m}$ and we require $m<n+1$, $\\hat X{\\hat X}^T$ is not invertible. Even if $\\hat X{\\hat X}^T$ is invertible, we can not get $\\Theta \\hat X=Y$ if $\\hat X$ is not invertible. If it is, we can solve the equation directly with $\\hat X^{-1}$.\n\t\t\\item Another way is to assume $\\Theta=Z\\bar X^T$, and we have\n\t\t\\begin{align*}\\\\\n\t\t\\Theta \\hat X=Y&\\Leftrightarrow Z\\bar X^T \\hat X=Y\\\\\n\t\t&\\Leftrightarrow Z =Y({\\hat X}^T\\hat X)^{-1}.\\\\\n\t\t&\\Rightarrow\n\t\t\\Theta=Y({\\hat X}^T\\hat X)^{-1}\\bar{X}^T.\n\t\t\\end{align*}\n\t\tThis is a feasible method. However, this method won't bring an obviously difference as the least square method, so we won't show the results of it.\n\t\\end{enumerate}\n\t\n\t\\item Update the parameters with gradient descent methods on the mini-batch.\n\t\\item Go to 1 until a convergence.\n\\end{enumerate}\n\nFor a fully connected neural network with several hidden layers, we just change parameters at each layer successively. The above example shows the XN algorithm on mini-batches.\n\\subsection{XN and ReLU1}\nReLU1, denoted as $\\tau$, is defined as \n\\begin{equation}\n\\tau(x) =\n\t\\begin{cases}\n\t\t0 \\quad & 0 < x, \\\\\n\t\tx \\quad &0 \\le x < 1, \\\\\n\t\t1 \\quad &1 \\le  x.\n\t\\end{cases}\n\\end{equation}\n\nThis function has two inflection points $x=0$ and $x=1$. When $x\\leq0$ or $x\\geq1$, the gradient of $\\tau$ is \n\\begin{equation}\n\t\\frac{\\D\\tau}{\\D x}=0.\n\\end{equation}\n\nIn the above example, for an input $\\mathbf{x}=\\Theta\\hat X$, $\\tau$ is applied to each element, thus does not change the dimension of $\\mathbf{x}$.\n\nThe idea of XN is to adjust $\\Theta$ so that if $\\mathbf{x}_{ij}\\notin [0,1]$, $\\mathbf{x}_{ij}$ is moved to the nearest inflection point, as shown in \\eqref{XNeq}. XN does not affect the output of each layer, thus does not change the model.\n\nRecall that a neural network is defined as $f^J$, where\n\\begin{equation}\nf^j = \\theta^j \\circ g^j \\circ f^{j-1},\\quad j=1,2,...,J.\n\\end{equation}\n\n%With XN, the function is rewritten as\n%\n%\\begin{equation}\n%\tf^j = \\theta^j \\circ \\text{ReLU1} \\circ\\text{XN}\\circ f^{j-1},\\quad j=1,2,...,J.\n%\\end{equation}\n%Note that\n%\\begin{equation}\\label{key}\n%\t\\text{XN}\\circ f^{j-1}=\\text{XN}\\circ \\theta^j \\circ g^{j-1},\n%\\end{equation}\n%the operator XN in fact changes $\\theta^{j-1}$ to $\\theta^*$, where\n%\\begin{equation}\n%\t\\theta^*\\circ g^{j-1}=\\text{ReLU1}\\circ f^{j-1}.\n%\\end{equation}\n%\n%Denote $\\text{ReLU1}\\circ f^{j-1}$ on a mini-batch $B$ as $G\\in\\mathbb{R}^{n\\times m}$, where $m$ is the size of mini-batch and $n$ is the dimension of the input, and $g^{j-1}$ on $B$ as $\\bar G$, we have\n%\\begin{equation}\n%\\theta\\circ g^{j-1}=\n%\\begin{pmatrix}\n%\t\\bar G^T & 1_m\n%\\end{pmatrix}\n%\\begin{pmatrix}\n%\tW^T\\\\b\n%\\end{pmatrix}\n%:=\\bar X\\Theta=G.\n%\\end{equation}\n%\n%The above equation can then be viewed as an optimization problem\n%\\begin{align}\\label{op_xn}\n%\t\\min_{\\Theta\\in\\mathbb{R}^{n_x}}\\|\\bar X\\Theta-G\\|_F,\n%\\end{align}\n%which may have infinite solutions, in which case we may add a constraint to it, such as $\\min \\|\\theta-\\bar\\theta\\|$ or $\\min\\|\\theta\\|$. However, any solution of \\eqref{op_xn} is adoptable.\n%\n%Another quick way to solve \\eqref{op_xn} is as follows. Assuming $\\Theta_k=\\bar X^T y,k=1,2,...,n$, we have\n%\\begin{align*}\n%\t\\bar X\\bar X^Ty&=G_k,\\\\\n%\ty&=(\\bar X\\bar X^T)^{-1}G_k,\\\\\n%\t\\Theta_k&=\\bar{X}^T(\\bar X\\bar X^T)^{-1}G_k.\n%\\end{align*}\n%\n%To guarantee $(\\bar X\\bar X^T)^{-1}$ exists, a necessary condition is $m<n$.\n%\n%One can also use a package to compute the linear square problem directly. For example, in Python, numpy.linalg.lstsq() provides such an API. This function in facts uses LAPACK library, which further uses divide and conquer methods to solve the problem.\n% \n%The algorithms are as follows. \n\n\\begin{algorithm}[htb]\n\t\\caption{Training Algorithm with XN}\n\t\\label{alg0_XN}\n\t\\begin{algorithmic}[1]\n\t\t\\Require $\\Theta_0$, learning rate $\\eta_t$\n\t\t\\For{$t = 0,1 \\cdots$}\n\t\t\\State Select a mini-bath $B_t$.\n\t\t\\State Replace $\\Theta_t$ with $\\hat{\\Theta}_t$,\n\t\t\\begin{equation}\n\t\t\t\\Theta_t\\leftarrow \\hat{\\Theta}_t = \\text{XN}(f^J, \\Theta_t, B_t).\n\t\t\\end{equation}\n\t\t\\State Compute the gradient (BP),\n\t\t\\begin{equation}\n\t\t\tg_t = \\nabla_{\\Theta} L_{B_t}(\\Theta) |_{\\Theta = \\hat{\\Theta}_t}.\n\t\t\\end{equation}\n\t\t\\State Update parameters $\\Theta$ with\n\t\t\\begin{equation}\n\t\t\t\\Theta_{t+1} = \\Theta_{t} - \\eta_t g_t.\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}[htb]\n\\caption{XN: solve $\\hat \\Theta_t$ from $\\Theta_t$ and $f^J$ on $B_t$}\n\\label{XN_solve}\n\\begin{algorithmic}[1]\n\\Require The neural network $f^J$,  current parameters $\\Theta_t$, mini-batch $B_t$\n\\For{$j = 0:J-1$}\n\\For{$k = 1:n_{j+1}$}\n\\State Compute $\\hat \\theta^j_{t,k}$ such that\n\\begin{equation}\\label{eq1:XN}\n\\hat{\\theta}_{t,k}^j \\bar{x}^j_i = g^{j+1}({\\theta}_{t,k}^j \\bar{x}^j_i),\n\\end{equation}\nwith $x^j_i = g^j(f^{j-1}(x_i))$ for $i \\in B_t$. For example, $\\theta=\\bar{X}^T(\\bar X\\bar X^T)^{-1}g$.\n\n\\State Replace $\\hat\\theta$ by $\\theta$,\n\\begin{equation}\n\t\\hat\\theta\\leftarrow\\theta.\n\\end{equation}\n%\\State If \\eqref{eq1:XN} have infinite solutions, we can add those kind of constrains:\n%\\begin{equation}\\label{eq1:constrain}\n%\\min \\|\\hat{\\theta}_{t,k}^j  - \\theta_{t,k}^j\\|^2  \\quad \\text{or} \\quad \\min  \\|\\hat{\\theta}_{t,k}^j  - \\theta_{t,k}^j\\|_{1}\n%\\end{equation}\n\\EndFor\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Implementation}\n\nXN is implemented with PyTorch as an independent layer object.\n\n\\section{Numerical Results}\n\nWe use a fully connected neural network, with two hidden layers, each has 100 neurons. Thus, the mini-batch size should be smaller than 101.\n\nWe will only do XN on the second hidden layer.\n\nWe want XN to be properly solved, so there is a parameter \\emph{xn\\_error} to control the error, i.e.\n\\begin{equation}\n\t\\|\\Theta \\hat X-Y\\|_F<\\text{xn\\_error}.\n\\end{equation}\n\nA max-norm is more convenient, because it's not sensitive to batch-size. We still use F-norm here.\n\nAlso, we have two methods to solve XN, i.e. the least square and the pseudo-inverse one. We will denote them as \\emph{lst} and \\emph{inv} respectively.\n\nWe test XN on different datasets. \n\n\\subsection{Points-separation problem}\n\\subsubsection{Introduction}\nThe samples of points-separation problem with $9$ classes are shown as follows.\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=0.5\\textwidth]{./figures/XN_Points_show.png}\n\t\\caption{The training data of 9-class points-separation problem.}\n\\end{figure}\n\nThis problem can be easily solved by plain SGD, i.e. without BN or XN, the prediction of which is as follows.\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=0.5\\textwidth]{./figures/XN_Points_SGD_pred.png}\n\t\\caption{The prediction of the neural network trained by plain SGD.}\n\\end{figure}\n\n\\subsubsection{Loss on mini-batches}\n\nThe setup is as follows. \n\n\\begin{center}\n\t\\begin{tabular}{|l|c|}\n\t\t\\hline\n\t\tBatch size & 32\\\\\n\t\t\\hline\n\t\txn\\_error & $10^{-4}$\\\\\n\t\t\\hline\n\t\tLearning rate & $0.01$\\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\nDue to the size of xn\\_error, not all training step will apply XN. Figure \\ref{fig:XN_points_1} shows the value of loss function and whether using XN at each step.\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=10cm]{./figures/XN_Points.png}\n\t\\caption{Above: loss function on mini-batch at each step; below: if using XN at each step, 1 if use XN, otherwise 0.}\n\t\\label{fig:XN_points_1}\n\\end{figure}\n\n\\textbf{Observations on Figure \\ref{fig:XN_points_1}} \n\\begin{enumerate}\n\t\\item Within the first 100 steps, XN decreases the loss function.\n\t\\item After 1000 steps, although the loss function on the current mini-batch won't change, it will increase sharply on the next mini-batch. XN will break the prediction on other mini-batches.\n\\end{enumerate}\n\nXN breaks the prediction on other mini-batches even without SGD, as Figure \\ref{fig:XN_points_onlyXN} shows.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=10cm]{./figures/XN_points_onlyXN.png}\n\t\\caption{At each step, when using XN, SGD is not used.}\n\t\\label{fig:XN_points_onlyXN}\n\\end{figure}\n\n\nWe may add a parameter xn\\_prob to control the probability of using XN. By changing the probability of XN, we can see how the loss function will change. Figure \\ref{fig:XN_points_02} shows loss function on mini-batches with xn\\_prob=0.2.\n\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=10cm]{./figures/XN_Points_02.png}\n\t\\caption{Loss function on mini-batch, with xn\\_prob=0.2.}\n\t\\label{fig:XN_points_02}\n\\end{figure}\n\n\\subsubsection{Train the full-batch and adjust on mini-batch}\nAnother way to use XN is doing gradient descent on the full-batch, and doing XN on the mini-batch.\n\nWith the same xn\\_error=$10^{-4}$ and other setups, figure \\ref{fig:XN_points_full} shows value of loss function on the whole training dataset.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=10cm]{./figures/XN5.png}\n\t\\caption{Loss on the full-batch.}\n\t\\label{fig:XN_points_full}\n\\end{figure}\n\\textbf{Observations on Figure \\ref{fig:XN_points_full}} \n\\begin{enumerate}\n\t\\item Within the first 100 steps, XN decreases the full loss function.\n\t\\item After 1000 steps, it will increase sharply after XN. XN will break the prediction on other samples.\n\\end{enumerate}\n\nWe can decrease the XN error to $10^{-5}$, so  that only the first 100 steps will use XN. The loss is shown in figure \\ref{fig:XN_points_full_100}. The first several XN speed up the training.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=10cm]{./figures/XN1.png}\n\t\\includegraphics*[width=10cm]{./figures/XN_Points_full_1e5.png}\n\t\\caption{Loss on the full-batch. Only step 8, 21 and 50 use XN.}\n\t\\label{fig:XN_points_full_100}\n\\end{figure}\n\n\\subsection{MNIST}\nWe now use the dataset MNIST. xn\\_error is $10^{-6}$.\n\n\\subsubsection{Loss function with xn\\_prob 0.2}\nFigure \\ref{fig:XN_MNIST_1} shows the loss function on mini-batches with XN-probability $0.2$.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=8cm]{./figures/XN14.png}\n\t\\caption{Loss function on mini-batches with xn\\_prob $0.2$.}\n\t\\label{fig:XN_MNIST_1}\n\\end{figure}\n\n\\subsubsection{Train the full-batch and adjust on mini-batch}\nUsing GD on the full-batch and XN on the mini-batch, Figure \\ref{fig:XN_MNIST_full} shows the loss on the full training dataset.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=8cm]{./figures/XN15.png}\n\t\\caption{Loss function on the full-batch with xn\\_prob $0.2$.}\n\t\\label{fig:XN_MNIST_full}\n\\end{figure}\nDecrease xn\\_prob to $0.001$, we have Figure \\ref{fig:XN_MNIST_full_0001} showing the loss function on the full-batch.\n\\begin{figure}[H]\n\t\\center\n\t\\includegraphics*[width=\\textwidth]{./figures/XN17.png}\n\t\\caption{Loss function on the full-batch with xn\\_prob $0.001$.}\n\t\\label{fig:XN_MNIST_full_0001}\n\\end{figure}\n\n\\textbf{Observations on Figure \\ref{fig:XN_MNIST_full_0001}}. Every XN will increase the loss on other samples.\n\n\\subsection{Conclusion}\nFrom the above results, although XN keeps the loss on the current mini-batch, it will increase on other samples.\n\nChanging batch size (e.g. 2, 8, 32, 64) or learning rate (e.g. 0.1, 0.01) won't give different results, so we omit them.\n\nTo keep the loss on the full-batch is hard. First, changing $\\Theta$ for a mini-batch will change the whole neural network, which will change the loss on other samples. Second, it's hard to do XN on the full-batch, because the number of the input samples, $m$, should not be larger than the dimension of a sample, $n$. $m$ is $50,000$ for MNIST full-batch, which is too large. \n\n\\subsection{Batch Normalization}\n\nThe model VGG11 is used to compare the performance of XN, XN as loss, BN and a blank setup. ImageNet, which has $1000$ classes, is used as dataset.\n\nVGG11 can be defined as a function $f=f_2\\circ f_1$, where $f_1$ is of convolutional layers and $f_2$ is of fully connected layers,\n\\begin{equation}\nf_2=W_3\\text{ReLU1}(W_2\\text{ReLU1}(W_1x+b_1)+b_2)+b_3.\n\\end{equation}\n\nDropout is used after each ReLU1 in $f_2$.\n\n\\begin{center}\n\t\\includegraphics*[width=\\textwidth]{./figures/BN_ImageNet.png}\n\\end{center}\n\nThe figure above compares $90$ epochs of training, with or without BN. \\emph{training top1} means the accuracy of prediction on a mini-batch, and \\emph{training top5} means the top5 accuracy, i.e. if the largest 5 predictions of a sample include the right one, then the prediction is viewed as correct.\n\n\\subsection{XN, XN as loss and BN, ImageNet}\n\\begin{center}\n\t\\includegraphics*[width=\\textwidth]{./figures/XN_ImageNet.png}\n\\end{center}\n\nThere are two hidden layers in $f_2$, but we only do XN on the first one. If do both, the solution of the least square problem has large error. The figure above compares the first $4000$ steps of training.\n\nThe batch size is $256$ on training data, and the optimizer is SGD with momentum $0.9$.\n\nDuring the training, the error of the least square problem is kept under $10^{-4}$, except for larger numbers like $0.1$ for several times.\n", "meta": {"hexsha": "1ddfddba0b68adfee7d74a1ccc48a2df5a186b56", "size": 24032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/XN.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/XN.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/XN.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.4593639576, "max_line_length": 377, "alphanum_fraction": 0.7010236352, "num_tokens": 8595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.6326698702799628}}
{"text": "\\section{The {\\variant{\\nodeitems}} problem}\n\\label{sec:nodes}\n\nIn this section, we provide the formal problem definition \nof the {\\variant{\\nodeitems}} problem variant and describe a greedy \npolynomial-time algorithm for solving it.\n\\begin{problem}[{\\variant{\\nodeitems}}]\nGiven $G=(V,E)$, transition matrix $\\transition$, initial distribution of items to nodes\n$\\initial$ and integer $k$, find\n$S\\subseteq V$ such that $|S|=k$ such that \n$\\objective_\\shortnodeitems\\left(S\\right)$ is minimized.\n\\label{problem:nodes-variant}\n\\end{problem}\nA brute-force way to solve Problem~\\ref{problem:nodes-variant}\nwould be to evaluate the objective function over all node-sets of size $k$.\nObviously such an algorithm is infeasible -- and we thus\nstudy a natural greedy algorithm for the problem, namely \\nodegreedy.\n\n\\spara{The {\\nodegreedy} algorithm:} \nThis is a greedy algorithm that performs $k$ iterations; at each iteration,\nit adds one more \nnode in the solution.\nIf $S^t$ is the solution at iteration $t$, \nthen solution $S^{t+1}$ is constructed by finding the \nnode $u\\in V\\setminus S^t$ such that:\n\\begin{equation}\\label{eq:nodegreedy}\nv^\\ast=\\argmin_{v\\in V\\setminus S^t}\\objective_\\shortnodeitems\\left(S^{t}\\cup\\{v\\}\\right).\n\\end{equation}\nAlthough in the majority of our experiments that compare the brute-force solutions with those\nof {\\nodegreedy} the two solutions were identical, we identified some contrived instances \nfor which this was not the case. Thus, {\\nodegreedy} is not an optimal algorithm for\nProblem~\\ref{problem:nodes-variant}.\n\n\n\\spara{Running time} \n{\\nodegreedy} evaluates Equation~\\eqref{eq:nodegreedy} at each iteration. \nA naive implementation of this would require computing Equation~\\eqref{eq:nodevariance}\n$O(|V|)$ times per iteration, each time using $O(|V|^2)$ numerical operations.\nAs a first improvement, we avoid the full double summation over $V$\nvia a summation over edges $E$,\n\\begin{align}\n\t\\objective_{_\\shortparentstransitions}(S) = & \\sum_{u\\in V}\\initial^{\\prime}(u)\\sum_{v\\in V\\setminus S}\\transition^{\\prime}(u,v)\\left(1-\\transition^{\\prime}(u,v)\\right) \\nonumber \\\\ \n\t= &  \\sum_{(u,v)\\in E, v\\in V\\setminus S} \n\t\\initial^{\\prime}(u)\\transition^{\\prime}(u,v)\\left(1-\\transition^{\\prime}(u,v)\\right),\n\\end{align}\nthat involves $O(k|V||E|)$ numerical operations.\n\n% Clearly, the above running time would make {\\nodegreedy}\n% infeasible to run even for small-size datasets. \nWe can further speed-up the algorithm if \nwe re-use at each step the computations \ndone in the previous one.\nTo see how, let $S_t$ (resp.\\ $S_{t+1}$) \nbe the solution we construct after\n$t$ (resp.\\ $(t+1)$) iterations and \nlet $v^\\ast$ be the node such that\n$S_{t+1}=S_t\\cup v^\\ast$. \nThen, for any $u\\in V$ we have $\n\\rho(u,S_t) = \\sum_{v\\in S_t}\\transition(u,v)\n$, and therefore\n\\begin{eqnarray}\\label{eq:rho}\n% \\rho(u,S_{t+1}) & = &\\sum_{v\\in S_{t+1}}\\transition(u,v)\\\\ \n% & = & \\sum_{v\\in S_{t}}\\transition(u,v) + \\transition(u,v^\\ast)\\nonumber\\\\\n% & = & \\rho(u,S_{t})+ \\transition(u,v^\\ast)\\nonumber\n\\rho(u,S_{t+1}) & = \\rho(u,S_{t})+ \\transition(u,v^\\ast).\n\\end{eqnarray}\nMoreover, for any $S\\subseteq V$ let\n\\begin{align}\nB(u,S) & = \\sum_{(u,v)\\in E\\ s.t.\\ v\\in V\\setminus S}\\transition^{\\prime}(u,v)\\left(1-\\transition^{\\prime}(u,v)\\right) \\\\\n& = \\sum_{v\\in V\\setminus S}\\frac{\\transition(u,v)}{1-\\rho(u,S)}\\left(1-\\frac{\\transition(u,v)}{1-\\rho(u,S)}\\right)\\nonumber .\t\n\\end{align}\nWe can then express $B(u,S_{t+1})$ in terms of\n$B(u, S_{t})$:\n\\begin{eqnarray}\\label{eq:B}\n\\lefteqn{\nB(u,S_{t+1})  =} \\nonumber \\\\\n& & B(u,S_t)-2\\transition(u,v^\\ast)\\left(1-\\rho(u,S_t)-\\transition(u,v^\\ast)\\right). \n\\end{eqnarray}\nFinally, using Equations~\\eqref{eq:rho} and~\\eqref{eq:B} \nand algebraic manipulations,\nwe can express $\\objective_{\\shortnodeitems}(S_{t+1})$ as follows:\n\\begin{eqnarray}\\label{eq:noderewrite}\n\\lefteqn{\n\\objective_{\\shortnodeitems}(S_{t+1}) = }\\\\\n&&\\sum_{u\\in V}\\initial(u)\\left(\\frac{B(u,S_t)}{1-\\rho(u,S_{t+1})}-2\\transition(u,v^\\ast)\\right)\\nonumber\n\\end{eqnarray}\nThus, if we store $B(u,S_t)$ and $\\rho(u,S_t)$ at iteration $t$, \nthen evaluating \nEquation~\\eqref{eq:noderewrite} at iteration $t+1$\ntakes only $O(|V|)$ numerical operations.\n\nFor all iterations but the first one,\nthe above sequence of rewrites enables us to achieve \na speedup from $O(|V||E|)$ to $O(|V|^2)$ numerical operations\nper iteration.\nFor the first iteration, initializing\nthe auxiliary quantities $B(u, \\emptyset)$, $u\\in V$, still takes\n$O(|E|)$.\nWith this book-keeping, the running time of {\\nodegreedy} is  reduced\nfrom $O(k|V||E|)$ to $O(|E| + k|V|^2) = O(k|V|^2|)$.\nNote also that \\nodegreedy\\ is amenable to parallelization,\nas, given the auxiliary quantities from the previous step, \nwe can compute the objective function independently for each \ncandidate node.\n\n\n\n% \\emph{Optimality proof:} Our proof for the optimality of {\\nodegreedy}, will \n% first demonstrate that if node $v_1$ is the node picked by {\\nodegreedy} \n% in its first iteration, then $v_1$ is included in the optimal solution.\n% Then, \n% we will show that the solution to our original problem \n% consists of $v_1$ plus the optimal solution to a modified problem that does \n% not contain $v_1$.\n\n% For the first part of the proof, let's assume that $S^\\ast$ is the optimal solution\n% of size $k$. Also, let $S$ be the solution of size $k$ constructed by {\\nodegreedy} and \n% let $v_1$ be the node picked by {\\nodegreedy} in its first iteration. Before setting\n% its solution in iteration $1$ {\\nodegreedy} sets its solution to $S_0=\\{\\}$ and thus\n% $B(u,S_0)$ is equal to some constant $C$, i.e., $B(u,S_0)=C$ for every $u\\in V$.\n% Therefore, from Equations~\\eqref{eq:rho},~\\eqref{eq:B} \n% and~\\eqref{eq:noderewrite} we know that \n% \\[\n% v_1=\\argmin_{v\\in V}\\sum_{u\\in V}\\initial(u)\\left(\\frac{C}{1-\\transition(u,v)}-2\\transition(u,v)\\right).\n% \\]\n% Now let's assume that $v_1\\notin S^\\ast$ and let $T^\\ast\\subset S^\\ast$ such that\n% $\\left |T^\\ast\\right|=k-1$ and $S^\\ast\\setminus T^\\ast = v'$.\n\n% From the first step of of the {\\nodegreedy} algorithm we know that \n% \\begin{eqnarray*}\n% \\sum_{u\\in V}\\initial(u)\\left(\\frac{C}{1-\\transition(u,v_1)}-2\\transition(u,v_1)\\right)& \\leq & \\\\\\sum_{u\\in V}\\initial(u)\\left(\\frac{C}{1-\\transition(u,v')}-2\\transition(u,v')\\right), & &\n% \\end{eqnarray*}\n% which means that\n% \\begin{eqnarray*}\n% \\sum_{u\\in V}\\initial(u)\\left(\\frac{C}{1-\\transition(u,v_1)}-2\\transition(u,v_1)\\right)& \\leq & \\\\\\sum_{u\\in V}\\initial(u)\\left(\\frac{C}{1-\\transition(u,v')}-2\\transition(u,v')\\right), & &\n% \\end{eqnarray*}\n\n\n", "meta": {"hexsha": "093ce583cd9f17911a26bbd9777c3f767659f268", "size": 6541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/SDM-2018/nodes.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/nodes.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/nodes.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": 47.0575539568, "max_line_length": 190, "alphanum_fraction": 0.6972939917, "num_tokens": 2164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6326698669983543}}
{"text": "\\section{Algorithms}\nDefining algorithms to find the discrete logarithm in finite fields can be done supposing that all the prime factors of $n - 1$ are small, without loss of generality. This allows to assume fast algorithms exist, using $\\mathbb{Z}^*_n$ as field.\n\nAs from today, one of the best results in computing was achieved in 2019 by a group of researchers who announced the computation of the discrete logarithm of the number (RSA-240 + 49204), composed by 795 bit. This was obtained using a 2.1GHz CPU and took approximately 4000 core-years.\n\nThere are also reports of computing a discrete logarithm within a 768-bit prime field, taking 5300 core years, using the same algorithm as the previous (Number Field Sieve).\n\n\\subsection{Silver, Pohlig and Hellman algorithm}\nThe Silver-Pohlig-Hellman algorithm exploits a possible factorization of the order of a group through the \\textbf{Chinese Remainder Theorem}. \n\nThis applies to groups whose order is either a smooth integer or a prime power, iteratively computing the digit of the discrete logarithm by shifting out all but one unknown digit in the exponent.\n\nThe prime factorization of a group with order $|G|$ can be written using its $p$-th roots as:\n$$|G| = p_1^{e_1} \\cdot p_2^{e_2} \\cdot \\dots p_l^{e_l}$$\nComputing the discrete logarithm $x = \\log_\\alpha \\beta$ in $G$ can be performed through a \\textbf{divide-and-conquer} approach, finding smaller discrete logarithms $x_i \\equiv x \\mod p_i^{e_i}$ in the subgroups of order $p_i$ through some attack such as Pollard's method.\n\nThen, all $x_i$ are used applying the Chinese Remainder Theorem, determining an unique $x$ thanks to pairwise co-prime divisors. \n\nA consequence of the properties of prime factors is that one needs to know the factorization of the group order, which is not always easy.\n\n\\subsection{Index-calculus algorithm}\nThe index-calculus \\textbf{probabilistic} algorithm has the particularity of working only under certain assumptions, such as cyclic groups $\\mathbb{Z}^*_p$ and $GF(2^m)$, and has a lot in common with integer factorization although generally uses polynomials in rings. \n\nHowever, it is one of the most efficient ways to compute discrete logarithm, due to its \\textit{high parallelism} involving operations independent from one another. \n\nHere, the term \\textbf{index} is a commonly used word to define the discrete logarithm: $x = ind(a) \\mod q$ for some base $b$, for $b^x \\equiv a \\mod m$ if $b$ is a primitive root of $q$ and $\\gcd(a, q) = 1$.\n\nIndex-calculus depends on the property that a significant fraction of elements of $G$ can be efficiently expressed as \\textbf{products of elements} of a small subset of $G$, assuming $|G|= q = p^n$ is a fairly large power of a small prime $p$. \n\nThis algorithm allows to find for any $x \\in \\mathbb{Z}^*_q$ the value of $x \\mod q - 1$ such that $y = \\alpha^x$, with $\\alpha$ generator.\n\nIt works in two phases: the first one consists in precomputation, since it does not depend on the element $x$ to decrypt, and only has to be carried once. An irreducible element $f \\in \\mathbb{Z}^*_q$ is identified, and a subset $B \\subset \\mathbb{Z}^*_q$ is chosen, which will serve as ``basis'' and usually consists of all monic irreducible polynomials of arbitrary degree. \n\nThen, all discrete logarithms f $a \\in B$ are computed, i.e.\\ a random integer $t \\in [1, q - 2]$ is chosen and then $b^t$ is computed through repeated squaring. The algorithm finds all elements $c \\in \\mathbb{Z}^*_q$ such that:\n$$c = b^t \\mod f$$\n\nNow, the index-calculus algorithm attempts to write $c$ as:\n$$c = c_0 \\prod_{a \\in B} a ^{m}$$\n$m$ is the highest power of $a$ which divides $c$. One way to determine this is to run through all $a \\in B$ and divide $c$ successively by $a^m$. If the constant $c_0$ is the only one remaining after the division, then $c$ has the above form; otherwise, a different random integer $t$ is chosen.\n\nAnother good method to compute $c$ as products of elements $a \\in B$ is using an \\textit{integer factorization algorithm}, hence the close relation between these two problems.\n\nNow, supposing some $c \\equiv b^t \\mod f$ has been found, and $c$ has the desired type of factorization, taking the discrete logarithm of both sides allows to obtain:\n$$ind(c) - ind(c_0) \\equiv \\sum_{a \\in B} m \\cdot ind(a) \\mod q - 1$$\nThe \\textbf{modulo} operation is introduced since the discrete logarithm is only defined modulo $q - 1$. The left side of the equivalence is known, since $ind(c) = t$, and discrete logarithms of constants are assumed to be known as well.\n\nThe coefficients $m$ are also known, leaving only values $ind(a)$ and $a \\in B$ to be found. \n\nAssuming $|a| = h$, unknowns can be obtained through a linear system of equations with $h$ unknowns. Supposing integers $t$ can be chosen until a large number of different $c$ which factor into a product of $a$, eventually $h$ \\textbf{independent} congruences will be found, written as:\n$$t = ind(c_0) \\equiv \\sum_{a \\in B} m \\cdot ind(a) \\mod q - 1$$\nHere, \\textit{independent} implies that the determinant of the coefficient matrix $\\{m\\}$ is prime to $q - 1$.\n\nThe system of unknowns can then be solved, completing the first stage of index-calculus. Precomputation gives a large set of all the discrete logs of $a \\in B$, from which to calculate any other discrete log.\n\nThe final stage is performed supposing $x$ is the message whose discrete logarithm should be computed, and that the previous phase has already given all values of $ind(a),\\ \\forall\\ a \\in B$.\n\nA random integer $t$ is once again chosen, and $y = xb^t$ is computed, i.e.\\ the unique element $y \\in \\mathbb{Z}^*_q$ satisfying $y \\equiv xb^t \\mod f$.\n\nAs in the first stage, $y$ has to be factored into a constant $y_0$ times the product of powers of $a$, with $a \\in B$. If not, another $t$ is picked, and so on, until an integer is obtained such that:\n$$y = y_0 \\prod_{a \\in B} a ^{m}$$\n\nAs soon as this happens, the algorithm can terminate:\n$$ind(x) = ind(y) - t \\qquad \\and \\qquad ind(y) = ind(y_0) + \\sum_{a \\in B} m \\cdot ind(a)$$\nAll the terms are known, therefore a message can be decrypted. Furthermore, advances in research have significantly sped up the process in finding discrete logs.\n\nThis algorithm allows to obtain a runtime which is not exponential in the bit length of the order, but \\textbf{subexponential}. This can once again be compared to integer factorization: the order of magnitude of time needed to solve the discrete log problem for $q = p^n$ which is $k$ bits long is the same as factoring a $k$-bit number. \n\nIn order to provide a security of 80 bits, an attacker has thus to perform $2^{80}$ steps, therefore the prime $p$ of a discrete logarithm in $\\mathbb{Z}^*_p$ should be at least 1024 bit long; for $GF(2^m)$, index-calculus is even more powerful, making these groups \\textit{unusable} in practice.\n\n\\subsection{Number Field Sieve}\nThe Number Field Sieve algorithm, based on index-calculus, is currently the fastest known algorithm for finding both discrete logarithms and \\textit{integer factoring}, and the method used to break the record on the 795-bit value previously mentioned. \n\nThe key idea of the Number Field Sieve, starting from integer factorization consists in \\textbf{iteratively finding divisors within a field}. Assuming $q$ is a composite number, the algorithm generates pairs such that:\n$$x \\equiv y \\mod q$$\n\n$\\gcd(x - y, q)$ is a non-trivial divisor of $q$ with probability 0.5, and after finding several pairs, $q$ can be factorized.\n\nThe previous equation can also be stated including prime numbers $p_i$ and their power within the factorization, i.e.:\n$$x = p_1^{n_1} \\cdot p_2^{n_2} \\cdot \\dots \\cdot p_m^{n_m}$$\n\nThis approach is used while computing discrete logarithm: when enough elements have been found, the linear system of equations is solved, and the logarithm is consecutively applied such that $\\log(p_i) = a_i$. Therefore, if some element $b$ can be expressed as $b = p_1^{n_1} \\cdot p_2^{n_2} \\cdot \\dots \\cdot p_k^{n_k}$, then its discrete logarithm consists in:\n$$\\log(b) = n_1\\log(p_1) \\cdot n_2\\log(p_2) \\cdot \\dots \\cdot n_k\\log(p_k)$$\n\nGiven integers $a$ generator of $\\mathbb{Z}^*_q$, $b$, $n$ and a prime number such that $p^q = n$, $x$ solving $a^x \\equiv b \\mod q$, the algorithm attempts to find two monic polynomials $y_1$ and $y_2$ having the property:\n$$y_1 \\equiv 0 \\mod p \\qquad \\land \\qquad y_2 \\equiv 0 \\mod p$$\n\nDenoting with $\\lambda_i \\in \\mathbb{C}$ the root of $y_i$, then holds that $y_i$ is the minimal polynomial of $\\lambda_i$ and it is possible to define fields in which it is ensured the unique factorization.\n\nHaving $y_i(\\lambda_i) = 0$, then it is again possible to express $y_i$ as a combination of powers which can be used to reduce polynomials and define their complex product within the algebraic \\textit{number complex field}. This can be mapped to the original field, while trying to compute couples of integer values which are squares of another number, to also be able to factorize in $\\mathbb{Z}^*_q$.\n\nThe system obtained with all the factors is then solved, usually using the Chinese Remainder Theorem.  \n\n\n", "meta": {"hexsha": "47c954f6ad49a44773d7ae89e834f55a0e6cdf5d", "size": 9153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/algorithms.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/algorithms.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/algorithms.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": 97.3723404255, "max_line_length": 402, "alphanum_fraction": 0.7450016388, "num_tokens": 2503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6326698666151518}}
{"text": "\\subsection{Combinatorics}\n\n\\input{combinations}\n\n\\subsection{Simplices and barycentric coordinates}\n\\label{sec:barycentric}\n\\input{barycentric}\n\n\\subsection{Domains and function spaces}\n\n\\begin{Notation}{domain}\n  By $\\domain$ we denote a \\define{domain} in $\\R^d$, that is, an\n  open, connected subset. The boundary of $\\domain$ is denoted by\n  $\\d\\domain$.\n\n  Unless stated otherwise, we will always assume that the boundary of\n  the domain consists of finitely many smooth surfaces meeting in\n  ridges. Actually, we will often assume polygonal domains, such that\n  the finite element mesh covers it exactly.\n\\end{Notation}\n\n\\begin{Notation}{vector-diff-operators}\n  Differential operators for vector fields $u:\\R^d\\to\\R^d$\n  are defined as follows:\n  \\begin{xalignat}2\n    \\nabla \\vu &=\n    \\begin{pmatrix}\n      \\d_1 u_1 & \\cdots & \\d_d u_1\\\\\n      \\vdots && \\vdots \\\\\n      \\d_1 u_d & \\cdots & \\d_d u_d\n    \\end{pmatrix}\n    &&\\text{(gradient)}\n    \\\\\n    \\div \\vu &= \\sum_{i=1}^d \\d_i u_i\n    &&\\text{(divergence)}\\\\\n    \\strain u &= \\frac{\\nabla u + (\\nabla u)^\\transpose}{2}\n    &&\\text{(symmetric gradient)}\n  \\end{xalignat}\n\n  For a tensor field $\\sigma: \\R^d\\to \\R^{d\\times d}$, the divergence\n  is a vector defined row-wise as\n  \\begin{gather}\n    \\div\\sigma = \\left(\\sum_{j=1}^d \\d_j \\sigma_{ij}\\right)_{i=1,\\dots,d}\n  \\end{gather}\n\\end{Notation}\n\n\\begin{Notation}{lebesgue-spaces}\n  For a domain $\\domain\\in\\R^d$, we denote by $L^2(\\domain)$\\index{L2@$L^2(\\domain)$} the \\define{Lebesgue-space}\n  of square integrable ``functions'' on $\\domain$ with its norm\\index{norm!L2@$\\norm{\\cdot}_{L^2}=\\norm{\\cdot}_0$}\n  \\begin{gather}\n    \\norm{u} = \\norm{u}_0 = \\norm{u}_{L^2(\\domain)}.\n  \\end{gather}\n  We denote the inner product of $L^2(\\domain)$ by\n  \\begin{gather}\n    \\scal(u,v)_{L^2(\\domain} = \\form(u,v) = \\int_\\domain u v \\dvx.\n  \\end{gather}\n\\end{Notation}\n\n\\begin{Notation}{sobolev-spaces}\n  By $H^k(\\domain)$\\index{Hk@$H^k(\\domain)$} we denote the\n  \\define{Sobolev space} of square integrable functions on $\\domain$\n  with square integrable distributional derivatives up to order\n  $k$. Its norm is\\index{norm!Hk@$\\norm{\\cdot}_{H^k}=\\norm{\\cdot}_{k}$}\n  \\begin{gather}\n    \\norm{u}_k = \\norm{u}_{H^k(\\domain)} = \\sum_{\\abs{\\alpha} \\le k}\n    \\norm{\\d^\\alpha u}_{L^2(\\domain)}.\n  \\end{gather}\n  We also use the $H^k$-seminorm\\index{seminorm!Hk@$\\abs{\\cdot}_{H^k}$}\n  \\begin{gather}\n    \\abs{u}_k = \\norm{u}_{H^k(\\domain)} = \\sum_{\\abs{\\alpha} \\le k}\n    \\norm{\\d^\\alpha u}_{L^2(\\domain)}.\n  \\end{gather}\n\\end{Notation}\n\n\\begin{Notation}{sobolev-spaces-2}\n  By $H^1_0(\\domain)$\\index{H10@$H^1_0(\\domain)$} we denote the\n  completion of $C^\\infty_0(\\domain)$ with respect to the norm\n  $\\norm{\\cdot}_{H^1(\\domain)}$. Similarly,\n  $H^1_{\\Gamma}(\\domain)$\\index{H1gamma@$H^1_\\Gamma(\\domain)$} for any\n  $\\Gamma\\subset\\d\\domain$ is the completion of all functions in\n  $C^\\infty(\\domain)$ vanishing on $\\gamma$.\n\n  By $H^{-1}(\\domain)$\\index{H1m@$H^{-1}(\\domain)$}, we denote the\n  normed dual of $H^1_0(\\domain)$, that is the space of bounded linear\n  functionals on this space.\n\\end{Notation}\n\n\\begin{Notation}{vector-valued}\n  We denote vector valued quantities by boldface letters like $\\vx$,\n  $\\vu$, $\\vv$. Lebesgue spaces of vector valued functions\n  are denoted either by $L^2(\\domain;\\R^d)$ or by $\\vL(\\domain)$. The inner product of these is\n  \\begin{gather}\n    \\form(u,v) = \\int_\\domain \\vu \\cdot \\vv \\dx.\n  \\end{gather}\n  Vector valued Sobolev spaces $\\vH^k(\\domain)$ are defined accordingly.\n\\end{Notation}\n\n\\begin{Notation}{transpose}\n  Given two Hilbert spaces $V$ and $W$ and a mapping $A\\colon V\\to W^*$,\n  we define the \\define{adjoint} of $A$ by\n  \\begin{gather}\n    \\begin{split}\n      A^\\transpose\\colon W &\\to V^* \\\\\n      \\scal(Av,w)_{W^*\\times W} &= \\scal(v,A^\\transpose w)_{V\\times V^*}\n      \\qquad \\forall v\\in V, w\\in W.\n    \\end{split}\n  \\end{gather}\n  The adjoint with respect to the Euclidean inner product is called\n  the \\define{transpose} of $A$, denoted by $A^\\transpose$ as\n  well. This notation is used consistently for real and complex\n  Hilbert spaces.\n\\end{Notation}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "10abc506dec9cc9e541522c3c1eafed44ce6e4b2", "size": 4196, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mixed/notation.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/notation.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/notation.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": 35.2605042017, "max_line_length": 114, "alphanum_fraction": 0.6589609152, "num_tokens": 1470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.6326698655491508}}
{"text": "\\section{Convolutional Neural Network}\n\\label{sec:theoretical_background:cnn}\n\n\\Acrlongpl{cnn} feature a specialized architecture to process data that has a known grid-like topology, such as images.\nThey are based on \\acrlongpl{ann} and the mathematical convolution operation \\cite[p.~326--331]{deeplearningbook}.\n\nThe main problems when working with color images is that they are high-dimensional and therefore require a lot of processing power.\nFor this reason, \\acrlongpl{cnn} use special layers to detect features and reduce the amount of data.\n\n% ------------------------------------------------------------------------------------------------------------------------------\n\\subsection{Architecture}\n\\label{subsec:theoretical_background:cnn:architecture}\n\nA \\acrlong{cnn} features a variety of different layers.\nThe three most relevant layers are described in this section.\n\n% -----------------------------\n\\paragraph{Convolutional Layer}\nConvolutional layers apply a set amount of filters to the input image.\nFilters are used to recognize certain features (e.g. edges) and consist of as many so-called kernels as there are input channels.\nA kernel is applied by sliding it along an input channel and calculating the scalar product of the overlapping region.\nThis generates new layers which are summed up to a feature maps. % feature map\nThe first convolutional layers are responsible for detecting low-level features, while following layers are responsible for detecting high-level features \\cite[p.~327--330]{deeplearningbook}.\n\nConvolutional layers require the specification of many hyperparameters:\n\\begin{enumerate}\n  \\item Number of filters\n  \\item Kernel size\n  \\item Padding\n  \\item Stride\n  \\item Activation\n  \\item Bias\n\\end{enumerate}\n\nThe number of filters corresponds to the number of convolved feature maps produced.\nThe kernel size specifies the height and the width of the convolution window used.\nPadding can be used to preserve the spatial dimensions by adding layers of zeros to the input image.\nStride specifies the amount of movement between applications of the filter.\nThe activation parameter is used to specify an activation function (typically \\acrshort{relu}).\nFinally, the bias parameter specifies whether to use a bias term.\n\n% -----------------------\n\\paragraph{Pooling Layer}\nPooling layers are used to reduce the spatial dimensions of the convolved feature maps.\nThis is done by replacing a rectangular region of the feature map with a summary of this region.\nMaximum pooling yields the maximum value and average pooling yields the average value of a specific rectangular region.\nUsually, max-pooling is used to preserve large values which correspond to detected features.\nBy doing so, the required computational power is significantly decreased and the dominant features are extracted \\cite[p.~335--339]{deeplearningbook}.\n\nMax-pooling layers mainly require two hyperparameters: the pool size and the strides value.\nThe pool size is the region over which the maximum is taken.\nThe strides value specifies how far the pooling window moves for each pooling step.\n\n% -------------------------------\n\\paragraph{Fully-Connected Layer}\nIf every artificial neuron in layer $n$ is connected to every artificial neuron in layer $n + 1$, it is referred to as a fully-connected or dense layer.\nFully-connected layers are responsible for learning the non-linear combinations of the high-level convolved feature maps.\nThey are used at the end of \\acrshortpl{cnn} to flatten the result of the convolution process into a vector of values.\nThe output layer usually contains as many artificial neurons as there are classes \\cite{cnn_fc}.\n\nThe three main hyperparameters of fully-connected layers are the number of artificial neurons, the activation function and wheter to use a bias term.\n", "meta": {"hexsha": "4efe4c8c00207163781e59709161facebefbae8c", "size": 3809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/chapters/theoretical_background/cnn.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/cnn.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/cnn.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": 61.435483871, "max_line_length": 191, "alphanum_fraction": 0.763192439, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6325294956156372}}
{"text": "\\chapter{Similarity}\r\n\\section{Eigen-\\textit{something}}\r\nThe prefix \\textit{eigen}- is adopted from the German word \\textit{eigen} for ``own-\" or ``unique to\", ``peculiar to\". We will study about some \\textit{unique} something, up to similarity.\r\n\r\n\\begin{defn}[eigenvalue, eigenvector, eigenspace] For a linear \\textit{operator} $T \\in \\mathfrak L(V,V)$, if $$Tv = \\lambda v$$ for a scalar $\\lambda\\in F$ and a \\textit{nonzero} vector $v\\in V$, we call $\\lambda$ an \\textbf{eigenvalue} and $v$ an \\textbf{eigenvector} of $T$. The \\textbf{eigenspace} of $\\lambda$ is a subspace $$E_\\lambda = \\left \\{v\\in V: ~~ Tv= \\lambda v\\right\\} = \\ker(T-\\lambda I)$$ of all vectors whose eigenvalue is $\\lambda$.\r\n\\end{defn}\r\n\\begin{ex}\r\nCheck whether $E_\\lambda$ is a subspace of $V$.\r\n\\end{ex}\r\n\\begin{prop}\r\nIf $f(t) \\in F[t]$ and $v\\in E_\\lambda$, then $f(T)v = f(\\lambda)v.$\r\n\\end{prop}\r\n\\begin{theorem}\r\nTFAE(the followings are equivalent):\r\n\\begin{enumerate}[label={(\\alph*)}]\r\n    \\item $\\lambda$ is an eigenvalue of $T$.\r\n    \\item $T-\\lambda I$ is singular, i.e., non-invertible.\r\n    \\item $\\operatorname{det} (T-\\lambda I) = 0.$\r\n\\end{enumerate}\r\n\\end{theorem}\r\n\\begin{proof}\r\nWe already(and MUST) know that (b) and (c) are equivalent. If $T-\\lambda I$ is invertible, $$Tv = \\lambda v ~~~~\\Longleftrightarrow~~~~ (T-\\lambda I)v = 0~~~~\\Longleftrightarrow~~~~v=0$$and hence $\\lambda$ is not an eigenvalue. And if $\\lambda$ is an eigenvalue, $T-\\lambda I$ is not bijective and hence singular.\r\n\\end{proof}\r\nThus, determinant of $\\lambda I - T$ is important to decide whether or not $\\lambda$ is an eigenvalue of $T$. Hence we define a \\textit{polynomial}:\r\n\\begin{defn}[characteristic polynomial] The \\textbf{characteristic polynomial} $\\phi_T(t)$ is a polynomial defined by $$\\phi_T(t) = \\operatorname{det} (tI-T).$$ We will write $\\chi\\phi$ instead of the term `characteristic polynomial' since it is so long. \\textsf{XD}\r\n\r\nHere, $t$ behaves like a \\textit{scalar} since it used instead of a scalar $\\lambda$.\r\n\\end{defn}\r\nNote that $\\lambda$ is an eigenvalue iff $\\phi_T (\\lambda) = 0.$\r\n\\begin{ex}\r\nCheck if $\\chi\\phi$ is really a polynomial.\r\n\\end{ex}\r\n\\begin{ex}\r\nCalculate the $\\chi\\phi$ of a matrix $$A = \\begin{pmatrix}3&3&-1\\\\2&2&-1\\\\2&2&0\\end{pmatrix}.$$ Find its eigenvalues and eigenspaces, and calculate $\\phi_A (A)$. Note that $$f(T) = \\sum a_n T^n$$ for a polynomial $f(t) = \\sum a_n t^n \\in F[t]$ and a linear operator $T$. \\label[ex]{ec}\r\n\\end{ex}\r\n\r\n\\section{Diagonalizability}\r\n\r\nWhy we consider it? A big \\textit{raison d'etre} of eigen-something is \\textit{diagonalization} of a linear operator. First, from its name, we can define as follows:\r\n\r\n\\begin{defn}[diagonalization]\r\nA \\textbf{diagonalization} of a linear operator $T\\in \\mathfrak L(V,V)$ is a representation $T$ as a similar operator of a diagonal operator $D = \\operatorname{diag}(d_1,\\cdots,d_n).$ If there is a diagonalization of $T$, that is $T\\sim D$ for a diagonal operator $D$, then we call $T$ is \\textbf{diagonalizable}.\r\n\\end{defn}\r\n\\begin{ex}\r\nDetermine whether the following matrices are diagonalizable, where $F=\\mathbb Q$:\r\n$$A=\\begin{pmatrix} -1 & 3 & -1 \\\\ -3 & 5 & -1 \\\\ -3 & 3 & 1 \\end{pmatrix},\\qquad B= \\begin{pmatrix} 0 & 1 \\\\ -1 & 0 \\end{pmatrix}. $$ If a matrix is not diagonalizable in given field, consider $F=\\mathbb R$ and $F=\\mathbb C$.\r\n\\end{ex}\r\n\r\nIf $T$ is diagonalizable, then $[T]_{\\mathfrak B}^{\\mathfrak B} = U^{-1}DU$ for a diagonal matrix $D$, supposing the basis $\\mathfrak B$ is given for the vector space $V$; and there is another basis $\\mathfrak C$ for $V$ such that $U = [\\operatorname{id}_V]_{\\mathfrak B}^{\\mathfrak C}$. Evaluating this, we obtain $D=[T]_{\\mathfrak C}^{\\mathfrak C}.$ Since it is diagonal, we have $$[D]^{i} = D\\mathbf e_i  = [T]_{\\mathfrak C}^{\\mathfrak C} [w_i]_{\\mathfrak C}=[T w_i]_{\\mathfrak C}$$ and $$D\\mathbf e_i = d_i\\mathbf e_i =[d_i w_i]_{\\mathfrak C},$$ where $D=\\operatorname{diag}(d_1,\\cdots,d_n)$ and $\\mathfrak C = \\{w_1, \\cdots, w_n\\}.$ Hence we have $Tw_i = d_i w_i$, i.e., new basis must consist of eigenvectors, and the diagonal matrix contains corresponding eigenvalues. It is equivalent to the original definition. Hence we can re-define diagonalizability of a linear operator without matrices:\r\n\\begin{defn}[redefine of diagonalizability] A linear operator $T\\in\\mathfrak L(V,V)$ is diagonalizable if there is a basis for $V$ whose elements are all eigenvectors of $V$.\r\n\\end{defn}\r\nSince eigenvectors span $V$, there are $n$ linearly independent eigenvectors.\r\n\\begin{prop}\r\nIf the eigenvalues of $T$ are mutually different, $T$ is diagonalizable.\r\n\\end{prop}\r\n\\begin{proof}\r\nIf $\\lambda$'s are different, eigenvectors are linearly independent.\r\n\\end{proof}\r\n\\begin{prop}\r\nIf $H$ is Hermitian, that is $H=H^\\dagger$, then $H$ can be diagonalized by a unitary operator $U$, i.e., $U^{-1} = U^\\dagger.$\r\n\\end{prop}\r\n\\begin{proof}\r\nExercise.\r\n\\end{proof}\r\n\\begin{theorem}\r\nLet $T\\in \\mathfrak L(V,V)$ and $\\lambda_i$'s are eigenvalues of $T$. Then TFAE:\r\n\\begin{enumerate}[label={(\\alph*)}]\r\n    \\item $T$ is diagonalizable,\r\n    \\item $\\phi_T(t) = \\prod (x-\\lambda_i)^{e_i}$, $e_i = \\dim E_{\\lambda_i},$\r\n    \\item $V = \\bigoplus E_{\\lambda_i},$\r\n    \\item $\\dim V = \\sum \\dim E_{\\lambda_i}.$\r\n\\end{enumerate}\r\n\\end{theorem}\r\n\\begin{proof}\r\n\\begin{description}\r\n\\item [(a)$\\Rightarrow$(b)] $\\chi\\phi$ is invariant under similarity, since $$tI - T = U^{-1}(tI - D)U,$$for example. Hence $$\\phi_T(t) = \\phi_D(t) = \\prod (t-\\lambda_i)^{e_i}.$$ A term due to a basis element appears once in the characteristic polynomial, hence the exponent of $t-\\lambda_i$ is the (maximum) number of independent vectors in $E_{\\lambda_i}$, i.e., dimension.\r\n\\item [(b)$\\Rightarrow$(c)$\\Rightarrow$(d)$\\Rightarrow$(a)] ㅎㅎ. For (b) to (c), use dimension argument. Note that $\\sum e_k = n$.\r\n\\end{description}\r\n\\end{proof}\r\n\r\n\\section{Cayley-Hamilton Theorem and Minimal Polynomial}\r\n\r\nFrom \\cref{ec}, we can know $\\phi_A (A)$ for some matrices. Is it a general result? The answer is \\textsf{YES}, and it is called \\textit{Cayley-Hamilton theorem}!\r\n\\begin{theorem}[Cayley-Hamilton] $$\\phi_T(T)=0.$$\\end{theorem}\r\nFor $n=2$, let $A = \\begin{pmatrix}a&b\\\\c&d\\end{pmatrix}.$ Then $$\\phi_A(t) = (t-a)(t-d)-bc = t^2 - (a+d)t + (ad-bc)$$ and we get a \\textit{familiar}(?) form: $$T^2 - (a+d)T + (ad-bc)=0.$$\r\n\\begin{proof}[Proof(?)] Evaluating $t=T$, $$\\phi_T(T) = \\det(TI-T) = \\det(T-T) = 0.$$\r\n\r\n(\\textbf{NOT A PROOF.}) \\renewcommand{\\qedsymbol}{$\\lightning$}\r\n\\end{proof}\r\nFirst, $t$ behaves as a scalar. And also $0$ is a zero matrix, rather than a scalar 0, in a formula $\\phi_T(T)=0.$\r\n\r\nThen how to prove it? We will consider $t^n \\phi_T(t^{-1})$.\r\n\r\n\\begin{proof} Let $\\phi_T(t) = \\sum_{i=0}^n c_i t^i,$ then\r\n  $$t^n \\phi_T(t^{-1}) = \\sum_{i=0}^n c_i t^{n-i}\r\n  = t^n \\operatorname{det}\\left( t^{-1}I-T \\right)\r\n  = \\operatorname{det}(I-tT).$$\r\nFrom $$\\operatorname{det}(A)I = A \\cdot \\operatorname{adj}A,$$\r\nwe get $$\\operatorname{det}(I-tT)I = (I-tT)\\operatorname{adj}(I-tT).$$\r\nIn order to `remove' $I-tT$ in the RHS, multiplying $\\sum_{i=0}^m(tT)^i $ left,\r\n$$\\begin{aligned}\\left(\\sum_{i=0}^m (tT)^i \\right) \\left(\\sum_{i=0}^n c_i t^{n-i}\\right) &=\r\n\\left(\\sum_{i=0}^m (tT)^i \\right) \\operatorname{det}(I-tT)I \\\\ &=\r\n \\left(\\sum_{i=0}^m (tT)^i \\right) (I-tT)\\operatorname{adj}(I-tT) \\\\ &\r\n = \\left(I-(tT)^{m+1} \\right) \\operatorname{adj}(I-tT).\\end{aligned}$$\r\nBy definition of classical adjoint, every entry of this matrix is a polynomial\r\nof degree less than $n$. Hence RHS have terms of degree less than $n$ or greater\r\nthan or equal to $m$; for big $m$, the terms of degree $d\\in [n,m)$ in LHS must\r\nbe vanished. Hence, with $m$ big enough, we obtain that the coefficient of the term of degree $n$ is zero. Now, observing the coefficient\r\nof the term of degree $n$, we get\r\n$$\\sum_{i=0}^n c_i T^i = 0.$$\r\nHence $\\phi_T(T) = 0.$\r\n\\end{proof}\r\n\r\n\\begin{defn}[annihilating ideal]\r\n$$\\mathcal I_T = \\{p(t) \\in F[t]:~~p(T) = 0\\}.$$\r\nA polynomial in $\\mathcal I_T$ is called an \\textbf{annihilating polynomial}.\r\n\\end{defn}\r\nSince $\\phi_T(t) \\in \\mathcal I_T$, by Cayley-Hamilton theorem, $\\mathcal I_T \\ne \\emptyset.$\r\n\\begin{theorem}[minimal polynomial]\r\nThere is a monic annihilating polynomial which has the smallest degree. `Monic' means that the coefficient of the highest order term is 1. We call this polynomial the \\textbf{minimal polynomial} $m_T(t).$ And also, $$m_T(t) | p(t), \\qquad p(t) \\in \\mathcal I_T;$$especially, $m_T(t) | \\phi_T(t).$\r\n\\end{theorem}\r\n\\begin{proof}\r\n  Since $\\operatorname{deg}\\mathcal I_T$ is a subset of $\\mathbb N$, there is the minimal degree $d$. If there is two different monic annihilating polynomial of degree $d$, denoting $m_1$ and $m_2$, we have $m_1 - m_2 \\in \\mathcal I_T$ which leads to a contradiction.\r\n  \r\n  If $m_T(t) \\not\\!|\\; p(t)$ for every $p(t)\\in\\mathcal I_T,$ by division algorithm, we get that the remainder $r(t) = p(t)~\\textrm{mod}~m_T(t)$ is also an annihilating polynomial which has the degree less than of $m_T(t),$ a contradiction.\r\n\\end{proof}\r\n\\begin{prop}\r\n$\\mathcal I_T$ is really an ideal. (Of a ring $F[t].$)\r\n\\end{prop}\r\n\\begin{proof}\r\n  Exercise.\r\n\\end{proof}\r\n\\begin{ex}\r\nFind the $\\chi \\phi$ and $m\\phi$ of a matrix $$A=\\begin{pmatrix}5&-6&-6\\\\-1&4&2\\\\3&-6&-4\\end{pmatrix}.$$\r\n\\end{ex}\r\n\\begin{proof}[Answer]\r\n$$\\phi_A(t) = (t-1)(t-2)^2 ,\\qquad m_A(t) = (t-1)(t-2).$$\r\n\\end{proof}\r\n\\section{Invariant and Triangularizability}\r\n\\begin{defn}[invariant subspace]\r\n  For $T\\in\\mathfrak L(V,V)$ and $W\\le V$, $W$ is called invariant under $T$ if $TW \\le W.$\r\n\\end{defn}\r\n\\begin{ex}\r\n  \\begin{itemize}\r\n    \\item $F[t]$ is invariant under $D = \\frac{\\mathrm d}{\\mathrm dt}.$\r\n    \\item Every space is invariant under a projection.\r\n    \\item Suppose there are two linear operator $T$ and $S$ on $V$, which commute, i.e., $TS = ST$. Let $W = \\operatorname{im} S$ and $N = \\ker S$, then $W$ and $N$ are invariant under $T$, since $TW = TSV = STV \\le SV = W$ and $Sn = 0 \\implies STn = TSn = 0.$\r\n  \\end{itemize}\r\n\\end{ex}\r\nLet $W\\le V$ be invariant under $T$, and $\\mathfrak C = \\{w_i\\}_{i=1}^m$ be a basis of $W$. Then, $$[T]_{\\mathfrak C}^{\\mathfrak C} = \\begin{pmatrix}[T\\upharpoonright _W]^{\\mathfrak C}_{\\mathfrak C} & * \\\\ \\mathbf 0 & *\\end{pmatrix},$$ since, letting $\\mathfrak B = \\{w_i, v_j\\}_{i=1,j=1}^{m,~n-m}\\supseteq \\mathfrak C$ be a basis of $V$, $$Tw_i = \\sum a_iw_i + \\sum 0 v_j.$$\r\n\r\n\\begin{theorem}\r\n  Let $W\\le V$ be invariant under $T$, then $$\\phi_{T\\upharpoonright _W} | \\phi_T\\qquad \\textrm{and}\\qquad m_{T\\upharpoonright W} | m_T.$$\r\n\\end{theorem}\r\n\\begin{proof}\r\nLet $W$ has a basis $\\mathfrak C$ and $\\mathfrak B$ is a basis of $V$ which is extended from $\\mathfrak C$. Then we have $$[T]^{\\mathfrak B}_{\\mathfrak B} = \\begin{pmatrix}[T\\upharpoonright _W]^{\\mathfrak C}_{\\mathfrak C}& * \\\\ \\mathbf 0 & *\\end{pmatrix}.$$ For $\\chi\\phi$, $$0 = \\phi_T \\left([T]^{\\mathfrak B}_{\\mathfrak B}\\right) = \\begin{pmatrix}\\phi_T \\left([T\\upharpoonright _W]^{\\mathfrak C}_{\\mathfrak C}\\right)& * \\\\ \\mathbf 0 & *\\end{pmatrix}.$$ And by above, we have $$\\phi_T \\left([T]^{\\mathfrak B}_{\\mathfrak B}\\right)  = 0 \\implies \\phi_T \\left([T\\upharpoonright _W]^{\\mathfrak C}_{\\mathfrak C}\\right)  = 0,$$ which completes the remained part of proof.\r\n\\end{proof}\r\n\r\n\\begin{ex}\r\n  Consider a diagonalizable transformation $T$, and let $W_i$'s be its eigenspaces, then it suits perfectly to above theorem, and it makes the `sufficient-necessary condition' of diagonalizability clear. But if $T$ is not diagonalizable, it cannot be adopted since we do not know the other components of given block matrix.\r\n\\end{ex}\r\n\r\n% conductor\r\nWe define the following as a generalization of `annihilator ideal':\r\n\\begin{defn}[conductor (ideal)] Let W be an \\textit{invariant} subspace for $T$ and let $v$ be a vector in $V$. The \\textbf{T-conductor of v into W} is the set $S_T(v; ~W)$ which consists of all polynomials $g\\in F[t]$ such that $g(T) v \\in W.$\r\n\r\nIf $W=0$, we denote it as $\\mathcal I_T(v) = S_T(v;~0)$ and call the \\textbf{T-annihilator of v}. And $\\mathcal I_T = \\bigcap_v \\mathcal I_T(v)$ is the $T$-annihilator of $V$, which annihilates all the vectors of $V$.\r\n\\end{defn}\r\n\\begin{prop}Conductor is an ideal in $F[t]$.\\end{prop}\r\n\\begin{defn}[conductor (vector)] The monic generator of the ideal $S(v;~W)$ is also called the \\textbf{conductor} of $v$ into $W$.\r\n\\end{defn}\r\n\r\nAnalogous proofs of one for uniqueness of minimal polynomial prove also for the conductors, trivially. And, since $\\mathcal I_T$ is the \\textit{strongest} polynomials, the $T$-conductors divide the minimal polynomial for $T$.\r\n\r\n\\section{Minimal Polynomials and Triangular-/Diagonal-izability}\r\n\\begin{lemma}\r\nSuppose $$m_T(t) = \\prod (t-c_i)^{r_i},\\qquad c_i \\in F,$$ and let $W\\lneq V$ be invariant under $T$. Then there exists a vector $v\\not\\in W$ such that $$\\exists \\lambda \\text{: eigenvalue of }T:~~~~(T-\\lambda I)v \\in W,$$ that is, a linear polynomial is a $T$-conductor for some $v$. \r\n\\label[lemma]{lc}\r\n\\end{lemma}\r\n\\begin{proof}Let $w\\in V\\setminus W,$ and $g$ be the $T$-conductor of $w$ into $W$. ($g(T)w = 0.$) Then $g | m_T$, and since $w \\not\\in W$, $g $ cannot be a constant. ($g(T)w = kw \\in W \\implies k = 0 = g$ which is contradict to the fact that $g$ is a generator of an nontrivial ideal.) Therefore $$g(t) = \\prod(t-c_i)^{e_i}; \\qquad \\sum e_i > 0.$$ Choose $j$ so that $e_j > 0$, then $g = (t-c_j) h$ for some $h$. Since $v=h(T)w \\not \\in W$ ($g$ is minimal in the sense of degree) and $g(T)w = (T-cI)v \\in W$, we just found $v$! Obviously, $c$ is an eigenvalue.\r\n\\end{proof}\r\n\r\nWe conclude(?) with the following necessary-sufficient condition of diagonalizability and trigonalizability(trivial meaning), in the sense of minimal polynomial:\r\n\\begin{theorem}$T$ is triangularizable iff $m_T = \\prod (t-\\lambda_i)^{e_i},$ where $\\lambda_i$'s are distinct.\r\n\\label[thm]{tt}\r\n\\end{theorem}\r\n\\begin{proof}\r\n($\\Longleftarrow$) Let $W=0$, then above lemma says $\\exists v \\exists \\lambda (T - \\lambda I) v = 0.$ Hence it forms an eigenspace, and there is a basis $\\mathfrak B$ of $V$ extending $\\{v\\}$; therefore we have $$[T]_\\mathfrak B ^ \\mathfrak B = \\begin{pmatrix} \\lambda & ** \\\\ \\mathbf 0 & * \\end{pmatrix}.$$ By an induction on the dimension of square matrix ($*$ for above), we obtain a triangularization of $T$: $$[T]_\\mathfrak B ^ \\mathfrak B = \\begin{pmatrix}\r\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\r\n      0     & a_{22} & \\cdots & a_{2n} \\\\\r\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\r\n      0     &       0     & \\cdots & a_{nn} \\\\\r\n\\end{pmatrix}.$$ \r\n($\\Longrightarrow$) Calculate it$\\sim$.\r\n\\end{proof}\r\n\\begin{coro}Every linear operator is triangularizable if the given field is algebraically closed.\\end{coro}\r\n\\begin{proof}[Another proof of Corollary: using induction]\r\nThere is an eigenvalue and an eigenvector since the field is algebraically closed. Hence let $\\lambda$ and $v$ the chosen ones, extend $v$ to a basis $\\mathfrak B$ of $V$, and denote $\\mathfrak C = \\mathfrak B - \\{v\\}$ and $W = \\langle \\mathfrak C \\rangle$. Then:\r\n$$[T]_\\mathfrak B ^ \\mathfrak B = \\begin{pmatrix}\r\n\\lambda & ** \\\\\r\n\\mathbf 0 & * \\\\\r\n\\end{pmatrix}.$$ And we know that $$* = [\\pi \\circ T]_{\\mathfrak C}^{\\mathfrak C}$$ where $\\pi$ `removes' $v$-component: $$\\pi:~V\\to W;\\qquad av + \\sum_{w_i\\in \\mathfrak C} b_i w_i \\mapsto  \\sum_{w_i\\in \\mathfrak C} b_i w_i.$$\r\n\\begin{center}\r\n\\leavevmode\r\n\\xy\r\n\\xymatrix {\r\nW\\ar[r]^{T} \\ar[dr]_{\\pi\\circ T}& TW \\ar[d]^{\\pi}\\\\ & W\r\n}\r\n\\endxy\r\n\\end{center} \r\nSince $\\pi\\circ T$ is linear, an induction completes the proof.\r\n\\end{proof}\r\n\r\n\\begin{theorem}$T$ is diagonalizable iff $m_T = \\prod (t-\\lambda_i),$ where $\\lambda_i$'s are distinct.\\end{theorem}\r\n\\begin{proof}\r\n($\\Longrightarrow$) Trivial. Think as a linear transformation each of $T-\\lambda_i I$'s.\r\n\r\n($\\Longleftarrow$) Let $W=\\bigoplus E_{\\lambda_i}$ be the space spanned by all of the eigenvectors of $T$, and suppose $W \\ne V$. By \\cref{lc}, there is a vector $v\\not \\in W$ and an eigenvalue $\\lambda_j$ such that $w = (T-\\lambda_j I)v \\in W$. Since $w\\in W$, it is represented by a linear combination of eigenvectors uniquely: $$w = \\sum_{w_i \\in  E_{\\lambda_i}} w_i,$$noting that $T w = \\sum \\lambda_i w_i.$ \r\n\r\nLet $m_T = (t-\\lambda c_j) g$ for some polynomial $g$, and $$g(t) - g(c_j) = (t - c_j)h(t)$$ for some polynomial $h$. Then we have $$g(T)v - g(c_j)v = h(T)(T-c_j I)v = h(T)w \\in W$$ and $g(T)v \\in W$ whence $g(c_j)v \\in W.$ Since $v\\not\\in W$, $g(c_j) = 0.$ It contradicts the assumption that $m_T$ has distinct roots.\r\n\\end{proof}\r\n\r\n\\section{Simultaneous Triangular-/Diagonal-ization}\r\nWe want to find a basis which triangularizes all of the transformations in a family $\\mathscr F$ \\textit{simultaneously}.\r\n\r\nThe subspace $W$ is \\textbf{invariant under} $ {\\mathscr F}$ if $W$ is invariant under each operators.\r\n\r\nSince all diagonal matrices commute, if $T$ and $S$ diagonalized simultaneously, then$$(U^{-1}TU)(U^{-1}SU) = (U^{-1}SU)(U^{-1}TU)$$ and hence $TS = ST.$ Therefore we consider only a family whose elements commute mutually, for simultaneous diagonalization.\r\n\r\nFor simultaneous triangularization, one does not have to satisfy the commutating condition; however it is a \\textit{sufficient} condition for simultaneous triangularization, as we will see.\r\n\r\n\\begin{lemma}Let $\\mathscr F$ be a commuting family of triangularizable linear operators on $V$. Let $W$ be a proper subspace of $V$ which is invariant under $\\mathscr F$, then there is a vector $v\\in V\\setminus W$ such that $$\\forall T\\in\\mathscr F, ~~~ Tv \\in \\langle v \\rangle \\oplus W.$$ \r\n\\end{lemma}\r\n\\begin{proof}It is too taxing to deal with infinitely many operators; hence we use a basis: let $\\{T_1, \\cdots, T_r\\}$ be `a'(need not to be unique) maximal linearly independent subset of $\\mathscr F$; i.e. a basis for $\\langle \\mathscr F \\rangle \\le \\mathfrak L(V,V).$ ($\\mathfrak L(V,V)$ is a f.d.v.s.) Then it is sufficient to check for these basis elements only.\r\n\r\nBy \\cref{lc}, for a single operator, we can find a vector $v_1\\in V \\setminus W$ and a scalar $\\lambda_1$ such that $(T_1 - \\lambda_1 I)v_1 \\in W.$ Since $W$ is invariant under $T_1$, $$V_1 = \\left\\{v\\in V:~~(T_1 - \\lambda_1 I)v \\in W \\right\\} \\gneq W.$$ And $V_1$ is invariant under $\\mathscr F$.\r\n\r\nNow, in order to use induction, consider $V_1$ instead of $V$. Let $W$ be a proper subspace of $V_1$, and $U_2 = T_2 \\upharpoonright _W$ instead of $T_1$ of above procedure. Since $m_{U_2} | m_{T_2}$, we may apply \\cref{lc} to new $W$ and $U_2$ and consider as of $T_2$. We obtain a vector $v_2 \\in V_1 \\setminus W$ and a scalar $\\lambda_2$ such that $(T_2 - \\lambda_2 I)v_2 \\in W.$ Note that, since $v_2 \\in V_1,$ both of $(T_1 - \\lambda_1 I)v_2$ and $(T_2 - \\lambda_1 I)v_2$ belong to $W$. And let $$V_2 =\\left\\{v\\in V_1:~~(T_2 - \\lambda_2 I)v \\in W\\right\\},$$ then $V_2$ is invariant under $\\mathscr F$.\r\n\r\nContinue this process by an induction, then we can find $v = v_r$ as the desired vector.\r\n\\end{proof}\r\n\\begin{theorem}Let $\\mathscr F$ be a commuting family of triangularizable linear operators on $V$. Then it can be triangularized simultaneously.\r\n\\end{theorem}\r\n\\begin{proof}\r\nInduction. Now it is easy. (Same with the proof of \\cref{tt}.)\r\n\\end{proof}\r\n\r\nNow, finish with diagonalization.\r\n\r\n\\begin{theorem}Let $\\mathscr F$ be a commuting family of diagonalizable linear operators on $V$. Then it can be diagonalized simultaneously.\r\n\\end{theorem}\r\n\\begin{proof}\r\nAlmost same process as for triangularization, at this point, however, it is easier to proceed by induction on dim$V$.\r\n\r\nIf $\\operatorname{dim}V = 1$, automatically proved. Let $\\operatorname{dim}V = n$ and choose any $cI \\ne T\\in\\mathscr F$. Let $\\lambda_i$'s be the distinct eigenvalues of $T$ and let $W_i = E_{\\lambda_i} = \\ker (T-c_i I).$ $W_i$ is invariant under every operator which commutes with $T$; and each operator in $$\\mathscr F_i = \\left\\{T\\upharpoonright_{W_i} : ~~~ T\\in\\mathscr F \\right\\}$$ is diagonalizable since its minimal polynomial divides the minimal polynomial for the corresponding operator in $\\mathscr F$. Operators in $\\mathscr F_i$ can be diagonalized simultaneously since $\\operatorname{dim}W_i < \\operatorname{dim}V$ by a basis $\\mathfrak B_i$. Then $\\mathfrak B = (\\mathfrak B_i)$ is a desired basis.\r\n\\end{proof}", "meta": {"hexsha": "6d3f794cf649e56232fd795c2ac941113a161893", "size": 20314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "similarity.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": "similarity.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": "similarity.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": 79.3515625, "max_line_length": 901, "alphanum_fraction": 0.6718519248, "num_tokens": 6986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.6325294905458635}}
{"text": "% Preamble.\n\\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%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{27}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-07-02}\n\n\\title{\\vspace{-2\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Solve:}\n\\begin{equation*}\n\ty^{\\prime\\prime} - 9y = 0, \\quad\n\ty(0) = 2, \\quad\n\ty^\\prime(0) = -1.\n\\end{equation*}\nThe roots of the characteristic equation are\n\\begin{equation*}\n\tr^2 - 9 = 0 \\quad \\Rightarrow \\quad r_1 = 3, \\quad r_2 = -3.\n\\end{equation*}\nWith $2$ distinct real roots, the general solution is\n\\begin{equation*}\n\ty(t) = c_1 e^{3 t} + c_2 e^{-3 t}.\n\\end{equation*}\nUsing the system of equations given by the initial conditions,\n\\begin{alignat*}{2}\n\ty(0) &=& \\quad 2 &= c_1 + c_2 \\\\\n\ty^\\prime(0) &=& \\quad -1 &= 3 c_1 - 3 c_2,\n\\end{alignat*}\nthe coefficients can be solved for as\n\\begin{equation*}\n\tc_1 = \\frac{5}{6}, \\quad\n\tc_2 = \\frac{7}{6}.\n\\end{equation*}\nThus,\n\\begin{equation*}\n\t\\boxed{\n\t\ty(t) = \\frac{5}{6} e^{3 t} + \\frac{7}{6} e^{-3 t}\n\t}.\n\\end{equation*}\n\n\\section*{2.}\n\\textit{Solve:}\n\\begin{equation*}\n\ty^{\\prime\\prime} + 6y^\\prime + 9y = 0, \\quad\n\ty(0) = 1, \\quad\n\ty(1) = 1.\n\\end{equation*}\nThe roots of the characteristic equation are\n\\begin{equation*}\n\tr^2 + 6r + 9 = 0 \\quad \\Rightarrow \\quad r_1 = -3, \\quad r_2 = -3.\n\\end{equation*}\nWith a repeated real root, the general solution is\n\\begin{equation*}\n\ty(t) = c_1 e^{-3 t} + c_2 e^{-3 t} t.\n\\end{equation*}\nUsing the system of equations given by the initial conditions,\n\\begin{alignat*}{2}\n\ty(0) &=& \\quad 1 &= c_1 \\\\\n\ty(1) &=& \\quad 1 &= c_1 e^{-3} +  c_2 e^{-3},\n\\end{alignat*}\nthe coefficients can be solved for as\n\\begin{equation*}\n\tc_1 = 1, \\quad\n\tc_2 = e^3 - 1.\n\\end{equation*}\nThus,\n\\begin{equation*}\n\t\\boxed{\n\t\ty(t) = e^{-3 t} + (e^3 - 1) e^{-3 t} t\n\t}.\n\\end{equation*}\n\n\\section*{3.}\n\\textit{Solve:}\n\\begin{equation*}\n\ty^{\\prime\\prime} + 7y^\\prime + 10y = 0, \\quad\n\ty(0) = -1, \\quad\n\ty^\\prime(0) = 0.\n\\end{equation*}\nThe roots of the characteristic equation are\n\\begin{equation*}\n\tr^2 + 7r + 10 = 0 \\quad \\Rightarrow \\quad r_1 = -2, \\quad r_2 = -5.\n\\end{equation*}\nWith $2$ distinct real roots, the general solution is\n\\begin{equation*}\n\ty(t) = c_1 e^{-2 t} + c_2 e^{-5 t}.\n\\end{equation*}\nUsing the system of equations given by the initial conditions,\n\\begin{alignat*}{2}\n\ty(0) &=& \\quad -1 &= c_1 + c_2 \\\\\n\ty^\\prime(0) &=& \\quad 0 &= -2 c_1 - 5 c_2,\n\\end{alignat*}\nthe coefficients can be solved for as\n\\begin{equation*}\n\tc_1 = -\\frac{5}{3}, \\quad\n\tc_2 = \\frac{2}{3}.\n\\end{equation*}\nThus,\n\\begin{equation*}\n\t\\boxed{\n\t\ty(t) = -\\frac{5}{3} e^{-2 t} + \\frac{2}{3} e^{-5 t}\n\t}.\n\\end{equation*}\n\n\\end{document}", "meta": {"hexsha": "1eda26a2cb08c7aa1b05c1f9e6559aefe3bfcc96", "size": 3034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw27/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/hw27/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/hw27/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": 24.272, "max_line_length": 68, "alphanum_fraction": 0.6367831246, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.6324845624535256}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[margin=0.75in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{Regularized logistic regression gradient with weighted samples}\n\n\\begin{document}\n\n\\maketitle\n\nScikit-learn's batch logistic regression (which uses LIBLINEAR) doesn't support weighted\nsamples. The SGD classifier does support weighted samples, but it can be tricky to tune.\nFor my application, solving the optimization problem in batch with L-BFGS worked best.\n\n\\section*{No regularization, no weights}\n\nIn other words, all samples have weight $1.0$. $M$ training examples and $N$ features,\none of which is a dummy feature for the intercept. \\\\\n\n$\\theta \\in \\mathbb{R}^N$ - coefficients\n\n$y \\in \\{0, 1\\}^M$ - response variable ($M x 1$ vector)\n\n$X \\in \\{0, 1\\}^{MxN}$ - $M x N$ design matrix\n\n$f(x) = \\frac{1}{1+e^{-x}}$ - logistic function\n\n$l(\\theta)$ - loss function\n\n$l(\\theta) = - e^T \\left(y \\odot \\log(p) + (1-y) \\odot \\log(1-p)\\right) $\n\nwhere $p = f(X^T \\theta)$\n\naka average log-loss\n\n$$r = f(X^T \\theta) - y$$\n\n$$\\nabla l = X^T r $$\n\n\\section*{Standard regularization}\n\nNo regularization on the intercept. $M$ training examples and $N$ features. \\\\\n\n$\\theta \\in \\mathbb{R}^N$ - coefficients\n\n$\\theta_0 \\in \\mathbb{R}$ - intercept\n\n$y \\in \\{0, 1\\}^M$ - response variable ($M x 1$ vector)\n\n$w \\in (0, \\infty)^N $ - per example weight ($N x 1$ vector)\n\n$X \\in \\{0, 1\\}^{MxN}$ - $M x N$ design matrix\n\n$f(x) = \\frac{1}{1+e^{-x}}$ - logistic function\n\n$l(\\theta)$ - loss function\n\n$l(\\theta) = -w^T \\left(y \\odot \\log(p) + (1-y) \\odot \\log(1-p)\\right) / \\sum w $\n\nwhere $p = f(X^T \\theta + \\theta_0)$\n\naka average of the usual log-loss, weighted by $w$\n\n$$r = f(X^T \\theta + \\theta_0) - y$$\n\n$$\\nabla_0 l = \\frac{r^T w}{\\sum w} $$\n\n$$\\nabla l = \\frac{X^T (w \\odot r) + \\lambda \\theta}{ \\sum w} $$\n\n\n\\end{document}", "meta": {"hexsha": "2fb319ec781df96f83ec492f322d26ef3e33665c", "size": 1836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regularized logistic regression gradient with weighted samples.tex", "max_stars_repo_name": "sharnett/logistic-regression-stuff", "max_stars_repo_head_hexsha": "6d1688818f78990b9f1c7768551bbcc07eddd784", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "regularized logistic regression gradient with weighted samples.tex", "max_issues_repo_name": "sharnett/logistic-regression-stuff", "max_issues_repo_head_hexsha": "6d1688818f78990b9f1c7768551bbcc07eddd784", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "regularized logistic regression gradient with weighted samples.tex", "max_forks_repo_name": "sharnett/logistic-regression-stuff", "max_forks_repo_head_hexsha": "6d1688818f78990b9f1c7768551bbcc07eddd784", "max_forks_repo_licenses": ["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": 88, "alphanum_fraction": 0.6465141612, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6324720331534823}}
{"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-03.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 3a The Riemann curvature tensor}\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   \\partial{#}::PartialDerivative.\n\n   \\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2});\n\n   ;::Symbol;  # Suggsted by Kasper as a way to make use of ; legal\n               # see https://cadabra.science/qa/473/is-this-legal-syntax\n               # this code works with and without this trick\n\n   # rules for the first two covariant derivs of V^a\n\n   deriv1 := V^{a}_{; b}      -> \\partial_{b}{V^{a}}\n                               + \\Gamma^{a}_{c b} V^{c}.        # cdb (ex-03.101,deriv1)\n\n   deriv2 := V^{a}_{; b ; c}  -> \\partial_{c}{V^{a}_{; b}}\n                               + \\Gamma^{a}_{d c} V^{d}_{; b}\n                               - \\Gamma^{d}_{b c} V^{a}_{; d}.  # cdb (ex-03.102,deriv2)\n\n   substitute (deriv2,deriv1)                   # cdb (ex-03.103, deriv2)\n\n   Vabc := V^{a}_{; b ; c} - V^{a}_{; c ; b}.   # cdb (ex-03.104, Vabc)\n\n   substitute (Vabc,deriv2)                     # cdb (ex-03.105, Vabc)\n\n   distribute     (Vabc)                        # cdb (ex-03.106, Vabc)\n   product_rule   (Vabc)                        # cdb (ex-03.107, Vabc)\n\n   sort_product   (Vabc)                        # cdb (ex-03.108, Vabc)\n   rename_dummies (Vabc)                        # cdb (ex-03.109, Vabc)\n   canonicalise   (Vabc)                        # cdb (ex-03.110, Vabc)\n\n   sort_sum       (Vabc)                        # cdb (ex-03.111, Vabc)\n   factor_out     (Vabc,$V^{a?}$)               # cdb (ex-03.112, Vabc)\n\n   checkpoint.append (Vabc)\n\n   # create rule for Riemann, export later (for use by lib/dgeom)\n\n   substitute (Vabc,$V^{a} -> -1$)              # cdb (ex-03.113, Vabc)\n                                                # note use of -1 to get correct\n                                                # signs when coupled with the rule\n                                                # for Rabcd (next statement)\n\n   Rabcd := R^{a}_{d b c} -> @(Vabc).           # cdb (ex-03.114, Rabcd) #\n\n   foo   := R^{a}_{b c d}.                      # cdb (ex-03.115, foo)\n   substitute (foo, Rabcd)                      # cdb (ex-03.116, foo)\n\n   # update rule to use nice indices\n\n   Rabcd := R^{a}_{b c d} -> @(foo).\n\n   checkpoint.append (Rabcd)\n\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\Cdb*{ex-03.101}}\n   \\Dmath*{\\Cdb*{ex-03.102}}\n   \\Dmath*{\\Cdb*{ex-03.103}}\n\\end{dgroup*}\n%\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-03.104} = \\Cdb*[\\V{5pt}\\hskip2.0cm\\hfill]{ex-03.105}\n                           = \\Cdb*[\\V{5pt}\\hskip2.0cm\\hfill]{ex-03.106}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.107}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.108}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.109}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.110}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.111}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.112}\n                           = - R^{a}{}_{dbc} V^d\\quad\\text{(MTW)}}\n\\end{dgroup*}\n\n\\Dmath*{\\cdb{ex-03.115} = \\cdb{ex-03.116}}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 3b The Riemann curvature tensor}\n\nThis differs from the above by not using the \\verb|::TableauSymmetry| property.\nIt gives the same results as above but it does require a little bit more\nhousekeeping.\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   \\partial{#}::PartialDerivative.\n\n   ;::Symbol;  # Suggsted by Kasper as a way to make use of ; legal\n               # see https://cadabra.science/qa/473/is-this-legal-syntax\n               # this code works with and without this trick\n\n   # rules for the first two covariant derivs of V^a\n\n   deriv1 := V^{a}_{; b}      -> \\partial_{b}{V^{a}}\n                               + \\Gamma^{a}_{c b} V^{c}.        # cdb (ex-03.301,deriv1)\n\n   deriv2 := V^{a}_{; b ; c}  -> \\partial_{c}{V^{a}_{; b}}\n                               + \\Gamma^{a}_{d c} V^{d}_{; b}\n                               - \\Gamma^{d}_{b c} V^{a}_{; d}.  # cdb (ex-03.302,deriv2)\n\n   substitute (deriv2,deriv1)                    # cdb (ex-03.303, deriv2)\n\n   Vabc := V^{a}_{; b ; c} - V^{a}_{; c ; b}.    # cdb (ex-03.304, Vabc)\n\n   substitute (Vabc,deriv2)                      # cdb (ex-03.305, Vabc)\n\n   distribute     (Vabc)                         # cdb (ex-03.306, Vabc)\n   product_rule   (Vabc)                         # cdb (ex-03.307, Vabc)\n\n   # ------------------------------------------------------\n   # trick to obtain a symmetric connection\n\n   G_{a b}::Symmetric.\n\n   substitute     (Vabc,$\\Gamma^{a}_{b c} ->  G^{a} G_{b c}$)\n   sort_product   (Vabc)                         # cdb (ex-03.308, Vabc)\n   rename_dummies (Vabc)                         # cdb (ex-03.309, Vabc)\n   canonicalise   (Vabc)                         # cdb (ex-03.310, Vabc)\n   substitute     (Vabc,$G^{a} G_{b c} -> \\Gamma^{a}_{b c}$,repeat=True)\n   # ------------------------------------------------------\n\n   sort_product   (Vabc)\n   rename_dummies (Vabc)\n   canonicalise   (Vabc)\n\n   sort_sum       (Vabc)                         # cdb (ex-03.311, Vabc)\n   factor_out     (Vabc,$V^{a?}$)                # cdb (ex-03.312, Vabc)\n\n   checkpoint.append (Vabc)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\Cdb*{ex-03.301}}\n   \\Dmath*{\\Cdb*{ex-03.302}}\n   \\Dmath*{\\Cdb*{ex-03.303}}\n\\end{dgroup*}\n%\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-03.304} = \\Cdb*[\\V{5pt}\\hskip2.0cm\\hfill]{ex-03.305}\n                           = \\Cdb*[\\V{5pt}\\hskip2.0cm\\hfill]{ex-03.306}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.307}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.308}\n                           = \\Cdb*[\\V{5pt}\\hskip2.5cm\\hfill]{ex-03.309}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.310}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.311}\n                           = \\Cdb*[\\V{5pt}\\hfill]{ex-03.312}\n                           = - R^{a}{}_{dbc} V^d\\quad\\text{(MTW)}}\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": "8327f7610a481fba87da54e54a675697a8eb14fe", "size": 7056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-03.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-03.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-03.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": 36.75, "max_line_length": 94, "alphanum_fraction": 0.4553571429, "num_tokens": 2243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861584, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6324720203122107}}
{"text": "\\section{Methodology}\n\\label{sec:Methodology}\n\nGiven an original instance $x^0$, we attempt to find a counterfactual instance $x^\\prime \\coloneqq x^0 +d^\\prime \\in \\R^n$.  \n\nWe first define the following loss function that encourages the predicted class $t$ of the perturbed instance $x^\\prime$ to be different than the predicted class $t_0$ of the\noriginal instance $x^0$.\n\n\\begin{equation}\n   f_p(x^\\prime; \\kappa) \\coloneqq \\max \\llp f(x^\\prime; t_0) - \\max_{t \\neq t_0} f(x^\\prime; t), \\kappa \\rlp, \\label{obj: prediction}\n\\end{equation}\nwhere $f(x^\\prime; t)$ is the $t$-th class prediction probability, and $\\kappa > 0$ caps the divergence between $x^0$ and $x^\\prime$. \n\nWe also define another objective term to generate a sparse counterfactual instance that is similar to current instance:\n\n\\begin{equation}\n   f_d(x^0, x^\\prime) \\coloneqq \\beta \\| x^0 - x^\\prime  \\|_1 +  \\| x^0 - x^\\prime  \\|_2, \\label{obj: distance}\n\\end{equation}\nwhere $\\beta$ is a  positive parameter that balances the trade-off between the sparsity and similarity of the counterfactual instance $x^\\prime$.\n\nTo ensure the data distribution of $x^\\prime$ lies closer to all neighboring instances in the same class, we introduce a third objective term:\n\n\\begin{equation}\n   f_d(x^0, \\llp x^j  \\mid j \\in K_t \\rlp) \\coloneqq -(1/|K_t|)  \\sum_{j \\in K_t} (x^j - x^0)^T (x^\\prime - x^0). \\label{obj: projection}\n\\end{equation}\nNote that \\eqref{obj: projection} encourages a counterfactual instance $x^\\prime$ with a larger sample variance associated with samples in $K_t$. Geometrically, it defines a direction $x^\\prime - x^0$ in feature space along which these data vary the most. \n\nTo define $K_t$, we need a representative, unlabeled sample of the training dataset. First the predictive model is called to label the dataset with the classes predicted by the model. Then\nfor each class $t$ we encode the instances belonging to that class and order them by increasing $L_2$ distance to ENC($x_0$). The $K_t$ nearest instances in the latent space are included in $K_t$.\n\nWith \\eqref{obj: prediction}--\\eqref{obj: projection}, we now formally define our optimization model:\n \n\\begin{subequations} \\label{model: main}\n\\begin{align}\n  \\min \\quad & f_p(x^\\prime; \\kappa) + c_{d} f_d(x^0, x^\\prime) - c_{p} f_p(x^\\prime, \\llp x^j  \\mid j \\in K_t \\rlp) \\\\\n  \\text{s.t.} \\quad\n       & x^\\prime = x^0 + \\sum_{j=1}^{n_k} \\lambda_j d^j, \\\\\n       & d^j = x^j - x^0, j \\in K_t  \\\\\n       & \\sum_{j=1}^{n_k} \\lambda_j \\leq \\delta, \\\\\n       & \\lambda \\geq 0.\n\\end{align}\n\\end{subequations}\n\n\n\\subsection{Trajectory towards counterfactuals}\n\\label{subsec:Trajectory towards counterfactuals}\n\nNow we present an algorithm that finds an trajectory towards the counterfactual. \n\n\\begin{algorithm}[ht!]\n\\caption{\\textit{ConeOpt}}\n\\label{algorithm:ConeOpt}\n\\begin{algorithmic}[1]\n    \\REQUIRE An instance $x^0 \\in \\mathcal{X}$ to explain, and an index set $K_t$.\n    \\ENSURE A set of instances $L$ that provides a trajectory towards the counterfactual instances.\n    \\STATE Let $L \\coloneqq \\llp \\phi \\rlp$.\n    \\WHILE {Termination criteria not met}\n        \\STATE Solve optimization problem \\eqref{model: main} to obtain a new instance $x^\\prime$.\n        \t\\STATE Update trajectory $L \\coloneqq L \\cup \\llp x^\\prime \\rlp$.\n        \t\\STATE Let $x^0 \\coloneqq x^\\prime$.\n        \\STATE Calculate the new mean of each cluster.\n    \\ENDWHILE\n\\end{algorithmic}\n\\end{algorithm}\n\n\n", "meta": {"hexsha": "9d58e9ad5409f16fcb698d8c8fe2ef9fe04ba7bb", "size": 3435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ConeOpt_Method.tex", "max_stars_repo_name": "jupiters1117/ConeOpt", "max_stars_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_stars_repo_licenses": ["MIT"], "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/ConeOpt_Method.tex", "max_issues_repo_name": "jupiters1117/ConeOpt", "max_issues_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_issues_repo_licenses": ["MIT"], "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/ConeOpt_Method.tex", "max_forks_repo_name": "jupiters1117/ConeOpt", "max_forks_repo_head_hexsha": "b380e4f4f6c1b7cbe1cf02f25b1d404eabe68325", "max_forks_repo_licenses": ["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.2686567164, "max_line_length": 256, "alphanum_fraction": 0.7021834061, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6324629251116886}}
{"text": "\\chapter{Assignment-Numerical Techniques}\n\\begin{enumerate}\n\t\\item From the Taylor's series for $y(x)$, find $y(0.05)$ correct to four decimal places if $y(x)$ satisfies $y^{\\prime \\prime}-x y^{\\prime}-y=0$ with the conditions $y(0)=1$ and $y^{\\prime}(0)=0$.\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$1.0050$\n\t\\task[\\textbf{b.}]$0.0150$\n\t\\task[\\textbf{c.}] $0.0155$\n\t\\task[\\textbf{d.}]  $0.5025$\n\\end{tasks}\t\n\t\\item The value of $I=\\int_{0}^{1} \\frac{1}{1+x} d x$ using Simpson $1 / 3$ rule with $h=0.5$ is\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$0.69$\n\t\t\\task[\\textbf{b.}]$0.59$\n\t\t\\task[\\textbf{c.}]$0.49$\n\t\t\\task[\\textbf{d.}]  $0.39$\n\t\\end{tasks}\n\t\\item The value of the integral $\\int_{0}^{8} \\frac{1}{x^{2}+5} d x$, evaluated using Simpson's $\\frac{1}{3}$ rule with $h=2$ is\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$0.59$\n\t\t\\task[\\textbf{b.}]$0.69$\n\t\t\\task[\\textbf{c.}] $0.79$\n\t\t\\task[\\textbf{d.}] $0.89$\n\t\\end{tasks}\n\t\\item Consider differential equation $y^{\\prime}=-y$ with the condition $y(0)=1$. Use $-h=0.01$. The value of $y(0.02)$\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$0.9606$\n\t\t\\task[\\textbf{b.}] $0.9703$\n\t\t\\task[\\textbf{c.}]$0.9801$\n\t\t\\task[\\textbf{d.}] $0.99$\n\t\\end{tasks}\n\t\\item Using Euler's method solve the differential equation $y^{\\prime}=-y$ with the condition $y(0)=1$ with $h=0.01$. Find $y(0.04)$\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$0.99$\n\t\t\\task[\\textbf{b.}] $0.9801$\n\t\t\\task[\\textbf{c.}]$0.9703$\n\t\t\\task[\\textbf{d.}] $0.9606$\n\t\\end{tasks}\n\t\\item Given the initial value problem $y^{(1)}(t)=1-t y(t)$ with $y(0)=1$, approximation of $y(1)$ by Runge-Kutta method with $\\mathrm{h}=1$ would be:\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$1.35$\n\t\t\\task[\\textbf{b.}]$1.31$\n\t\t\\task[\\textbf{c.}]$1.32$\n\t\t\\task[\\textbf{d.}] $1.34$\n\t\\end{tasks}\n\t\\item Using the Newton's forward interpolating polynomial, $P_{5}(x)$ for the following tabular data find interpolated value of the function at $x=0.0045$.\\\\\\\\\n\t\\begin{tabular}{|c|c|c|c|c|c|c|}\n\t\t\\hline$x$ & 0 & $0.001$ & $0.002$ & $0.003$ & $0.004$ & $0.005$ \\\\\n\t\t\\hline$y$ & $1.121$ & $1.123$ & $1.1255$ & $1.127$ & $1.128$ & $1.1285$ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$-1.12840045$\n\t\t\\task[\\textbf{b.}]$1.12840045$\n\t\t\\task[\\textbf{c.}]$1.128124$\n\t\t\\task[\\textbf{d.}] $0.12840045$\n\t\\end{tasks}\n\t\\item From the Taylor's series for $y(x)$, find $y(0.1)$ correct to four decimal places if $y(x)$ satisfies\\\\\n\t$y^{\\prime \\prime}-x y^{\\prime}-y=0$ with the conditions $y(0)=1$ and $y^{\\prime}(0)=0$.\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$1.0050$\n\t\t\\task[\\textbf{b.}]$1.0150$\n\t\t\\task[\\textbf{c.}]$1.0155$\n\t\t\\task[\\textbf{d.}]$1.0250$\n\t\\end{tasks}\n\t\\item Compute the value of $\\frac{2}{\\sqrt{\\pi}} \\int_{0}^{x} e^{-x^{2}} d x$ when $x=0 \\cdot 6538$ using Gauss's forward formula also taking origin at $0.65, h=0.01$ and $x=0.6538$, Use the given table\\\\\n\t\\begin{tabular}{|l|l|}\n\t\t\\hline \\multicolumn{1}{|c|}{$x$} & \\multicolumn{1}{c|}{$y$} \\\\\n\t\t\\hline $0.62$ & $0.6194114$ \\\\\n\t\t\\hline $0.63$ & $0.6270463$ \\\\\n\t\t\\hline $0.64$ & $0.6345857$ \\\\\n\t\t\\hline $0.65$ & $0.6420292$ \\\\\n\t\t\\hline $0.66$ & $0.6493765$ \\\\\n\t\t\\hline $0.67$ & $0.6566275$ \\\\\n\t\t\\hline $0.68$ & $0.6637820$ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$0.6448325$\n\t\t\\task[\\textbf{b.}]$0.7448325$\n\t\t\\task[\\textbf{c.}]$0.8448325$\n\t\t\\task[\\textbf{d.}]$0.5448325$\n\t\\end{tasks}\n\\end{enumerate}\n\\section{Jacobian}\n\\begin{enumerate}\n\t\\item Let $f=y^{x}$ then the value of $\\frac{\\partial^{2} f}{\\partial x \\partial y}$ at $x=2, y=1$ is\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]0\n\t\t\\task[\\textbf{b.}]$\\ln 2$\n\t\t\\task[\\textbf{c.}]1\n\t\t\\task[\\textbf{d.}]  $\\frac{1}{\\ln 2}$\n\t\\end{tasks}\n\t\\item If $z=x y \\ln (x y)$ then which of the following is correct\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$x \\frac{\\partial z}{\\partial x}+y \\frac{\\partial z}{\\partial y}=0$\n\t\t\\task[\\textbf{b.}]$y \\frac{\\partial z}{\\partial x}+x \\frac{\\partial z}{\\partial y}=0$\n\t\t\\task[\\textbf{c.}]$x \\frac{\\partial z}{\\partial x}-y \\frac{\\partial z}{\\partial y}=0$\n\t\t\\task[\\textbf{d.}]  $y \\frac{\\partial z}{\\partial x}-x \\frac{\\partial z}{\\partial y}=0$\n\t\\end{tasks}\n\t\\item Let $f(x, y)=\\sum_{K=1}^{10}\\left(x^{2}-y^{2}\\right)^{K}$ for all $(x, y)$. Then for all $(x, y)$\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$x \\frac{\\partial f}{\\partial x}(x, y)-y \\frac{\\partial f}{\\partial y}(x, y)=0$\n\t\t\\task[\\textbf{b.}]$x \\frac{\\partial f}{\\partial x}(x, y)+y \\frac{\\partial f}{\\partial y}(x, y)=0$\n\t\t\\task[\\textbf{c.}]$y \\frac{\\partial f}{\\partial x}(x, y)-x \\frac{\\partial f}{\\partial y}(x, y)=0$\n\t\t\\task[\\textbf{d.}] $y \\frac{\\partial f}{\\partial x}(x, y)+x \\frac{\\partial f}{\\partial y}(x, y)=0$\n\t\\end{tasks}\n\t\\item The value of $\\int_{z=0}^{1} \\int_{y=0}^{z} \\int_{x=0}^{y} x y^{2} z^{3} d x d y d z$ is\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{90}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{50}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{45}$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{10}$\n\t\\end{tasks}\n\t\\item In a cylindrical coordinates $x=r \\cos \\theta, y=r \\cos \\theta$ and $z=z$ then $J\\left(\\frac{\\partial(x, y, z)}{\\partial(r, \\theta, z)}\\right)$ is given by\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$r$\n\t\t\\task[\\textbf{b.}]$z$\n\t\t\\task[\\textbf{c.}]$-r$\n\t\t\\task[\\textbf{d.}] $-z$\n\t\\end{tasks}\n\t\\item If $x=u(1-v), y=u v \\quad$ then $J\\left(\\frac{\\partial(x, y)}{\\partial(u, v)}\\right)$ is given by\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$u$\n\t\t\\task[\\textbf{b.}]$v$\n\t\t\\task[\\textbf{c.}]$-u(1-2 v)$\n\t\t\\task[\\textbf{d.}] $u(1-2 v)$\n\t\\end{tasks}\n\t\\item If $u=x^{2}-2 y^{2} \\quad v=2 x^{2}-y^{2} . \\quad x=r \\cos \\theta, y=r \\sin \\theta \\quad J\\left(\\frac{\\partial(u, v)}{\\partial(r, \\theta)}\\right)$\n\t \\begin{tasks}(4)\n\t\t\\task[\\textbf{a.}]$6 r^{3} \\sin 2 \\theta$\n\t\t\\task[\\textbf{b.}]$12 r^{3} \\sin 2 \\theta$\n\t\t\\task[\\textbf{c.}]$6 r^{3} \\sin \\theta$\n\t\t\\task[\\textbf{d.}] $12 r^{3} \\sin \\theta$\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": "aa0c94f3a3ad59bb9077665d3efc5a17db3f763a", "size": 5846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Numerical Techniques.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-Numerical Techniques.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-Numerical Techniques.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": 40.5972222222, "max_line_length": 205, "alphanum_fraction": 0.5800547383, "num_tokens": 2715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.6324438957550105}}
{"text": "\\section{Long exact homology sequence, Excision, and Genealogy}\nWARNING: I've probably messed up typing some indices. Hopefully not.\n\\subsection{5-lemma}\nSuppose you have two exact sequences of abelian groups.\n\\begin{equation*}\n\\xymatrix{A_4\\ar[r]^d\\ar[d]^{f_4} & A_3\\ar[r]^d\\ar[d]^{f_3} & A_2\\ar[r]^d\\ar[d]^{f_2} & A_1\\ar[r]^r\\ar[d]^{f_1} & A_0\\ar[d]^{f_0}\\\\\nB_4\\ar[r]^d & B_3\\ar[r]^d & B_2\\ar[r]^d & B_1\\ar[r]^r & B_0}\n\\end{equation*}\nWhen can we guarantee that $f_2$ is an isomorphism? We're going to diagram chase :-(. Just follow your nose.\n\nLet $b_2\\in B_2$. We want to show that there is something in $A_2$ that can be pushed forward to $b_2$, i.e., prove surjectivity of $f_2$. We can consider $db_2\\in B_1$. Let's assume that $f_1$ is surjective. Then there's $a_1\\in A_1$ such that $f_1(a_1)=db_2$. What is $da_1$? Well, $f_0(da_1)=d(f_1(a_1))=d(db)=0$. So we want $f_0$ to be injective. Then $da_1$ is zero, so by exactness of the top sequence, there is some $a_2\\in A_2$ such that $da_2=a_1$. What is $f_2(a_2)$? What is $d(f_2(a_2))$? By commutativity, $d(f_2(a_2))=f_1(d(a_2))=f_1(a_1)=db_2$. Let's consider $b_2-f_2(a_2)$. This maps to zero under $d$. So by exactness, there is $b_3\\in B_3$ such that $d(b_3)=b_2-f_2(a_2)$. If we assume that $f_3$ is surjective, then there is $a_3\\in A_3$ such that $f_3(a_3)=b_3$. But now, $d(a_3)\\in A_2$, and $f_2(d(a_3))=d(f_3(a_3))=b_2-f_2(a_2)$. But this means that $b_2=f(a_2+d(a_3))$, which guarantees surjectivity of $f_2$. This means that if $f_1$ is surjective, $f_0$ is injective, and $f_3$ is surjective, then $f_2$ is surjective.\n\nA similar dual process says that $f_2$ is injective if $f_1$ is injective, $f_3$ is injective, and $f_4$ is surjective. If all of these conditions are satisfied, then $f_2$ is an isomorphism. This is the content of the five-lemma.\n\\subsection{Relative homology}\nI guess I didn't really define this. Suppose you have a pair of spaces $(X,A)$. Then you have an sexseq of chain complexes $0\\to S_\\ast(A)\\to S_\\ast(X)\\to S_\\ast(X,A)\\to 0$. \n\\begin{definition}\nThe relative homology of the pair $ H_\\ast(X,A):= H(S_\\ast(X,A))$.\n\\end{definition}\n\\begin{example}\n$ H_\\ast(X,\\emptyset)= H_\\ast(X)$ because $S_\\ast(\\emptyset)=0$. Another case is $ H_\\ast(X,X)=0$ because $S_\\ast(X,X)=S_\\ast(X)/S_\\ast(X)=0$.\n\\end{example}\n\\subsection{General study of homologies of sexseqs of chain complexes}\nSuppose I have three chain complexes $A_\\bullet\\to B_\\bullet\\to C_\\bullet$. By the way, this is an important announcement. Henceforth, differentials in chain complexes will be denoted $d$, no longer $\\partial$. For some reason. (It's so much easier for typing as well.) Assume that this is an exact sequence of chain complexes.\n\nIs $ H_\\ast(A)\\to H_\\ast(B)\\to H_\\ast(C)$ exact? Let's push this a little further. Suppose I have a sexseq $0\\to A_\\bullet\\to B_\\bullet\\to C_\\bullet\\to 0$. We can ask the same question as before. Let's write this out more explicitly.\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & A_{n+1}\\ar[r]^f\\ar[d]^d & B_{n+1}\\ar[r]^g\\ar[d]^d & C_{n+1}\\ar[r]\\ar[d]^d & 0\\\\\n0\\ar[r] & A_n\\ar[r]^f\\ar[d]^d & B_n\\ar[r]^g\\ar[d]^d & C_n\\ar[r]\\ar[d]^d & 0\\\\\n0\\ar[r] & A_{n-1}\\ar[r]^f & B_{n-1}\\ar[r]^g & C_{n-1}\\ar[r] & 0}\n\\end{equation*}\nLet $[b]\\in H_n(B)$ such that $g([b])=0$. It's determined by some $b\\in B_n$ such that $d(b)=0$. If $g([b])=0$, then there is some $\\overline{c}\\in C_{n+1}$ such that $d\\overline{c}=gb$. Now, $g$ is surjective, so there is some $\\overline{b}\\in B_{n+1}$ such that $g(\\overline{b})=\\overline{c}$. Then we can consider $d\\overline{b}\\in B_n$, and $g(d(\\overline{b}))=d(\\overline{c})\\in C_n$. What is $b-d\\overline{b}$? This maps to zero in $C_n$, so by exactness there is some $a\\in A_n$ such that $f(a)=b-d\\overline{b}$. Is $a$ a cycle? Well, $f(da)=d(fa)=d(b-d\\overline{b})=db-d^2\\overline{b}=db$, but we assumed that $db=0$, so $f(da)=0$. This means that $da$ is zero because $f$ is an injection by exactness. Therefore $a$ is a cycle. What is $[a]\\in H_n(A)$? Well, $f([a])=[b-d\\overline{b}]=[b]$ because $d\\overline{b}$ is a cycle. Is the composite $ H_n(A)\\to H_n(B)\\to H_n(C)$ zero? Yes, because the composite factors through zero. This proves exactness of $ H_n(A)\\to H_n(B)\\to H_n(C)$.\n\n\\begin{theorem}[lexseq in homology]\nLet $0\\to A_\\bullet\\to B_\\bullet\\to C_\\bullet\\to 0$ be a sexseq of chain complexes. Then there is a natural homomorphism $\\partial: H_n(C)\\to H_{n-1}(A)$ such that there's lexseq:\n\\begin{equation*}\n\\xymatrix{ & & \\ar[dll]^\\partial\\\\\n H_n(A)\\ar[r] & H_n(B)\\ar[r] & H_n(C)\\ar[dll]^\\partial\\\\\n H_{n-1}(A)\\ar[r] & H_{n-1}(B)\\ar[r] & H_{n-1}(C)\\ar[dll]^\\partial\\\\\n & & &}\n\\end{equation*}\n\\end{theorem}\n\\begin{proof}\nWe'll construct $\\partial$, and leave the rest as an exercise. We have our sexseq:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & A_{n+1}\\ar[r]^f\\ar[d]^d & B_{n+1}\\ar[r]^g\\ar[d]^d & C_{n+1}\\ar[r]\\ar[d]^d & 0\\\\\n0\\ar[r] & A_n\\ar[r]^f\\ar[d]^d & B_n\\ar[r]^g\\ar[d]^d & C_n\\ar[r]\\ar[d]^d & 0\\\\\n0\\ar[r] & A_{n-1}\\ar[r]^f & B_{n-1}\\ar[r]^g & C_{n-1}\\ar[r] & 0}\n\\end{equation*}\nLet $c\\in C_n$ such that $dc=0$. The map $g$ is surjective, so pick a $b\\in B_n$ such that $g(b)=c$. Then consider $db\\in B_{n-1}$. But $g(d(b))=0=d(g(b))=dc$. So by exactness, there is some $a\\in A_{n-1}$ such that $f(a)=db$. How many choices are there of picking $a$? One, because $a$ is injective. We need to check that $a$ is a cycle. What is $d(a)$? Well, $d^2b=0$, so $da$ maps to $0$ under $f$. But because $f$ is injective, $da=0$, i.e., $a$ is a cycle. This means we can define $\\partial[c]=[a]$.\n\nTo make sure that this is well-defined, let's make sure that this choice of homology class $a$ didn't depend on the $b$ that we chose. Pick some other $b^\\prime$ such that $g(b^\\prime)=c$. Then there is $a^\\prime\\in A_{n-1}$ such that $f(a^\\prime)=db^\\prime$. We want $a-a^\\prime$ to be a boundary, so that $[a]=[a^\\prime]$. We want $\\overline{a}\\in A_n$ such that $d\\overline{a}=a-a^\\prime$. Well, $g(b-b^\\prime)=0$, so by exactness, there is $\\overline{a}\\in A_n$ such that $f(\\overline{a})=b-b^\\prime$. What is $d\\overline{a}$? Well, $d\\overline{a}=d(b-b^\\prime)=db-db^\\prime$. But $f(a-a^\\prime)=b-b^\\prime$, so because $f$ is injective, $d\\overline{a}=a-a^\\prime$, i.e., $[a]=[a^\\prime]$. What else do I have to check? It's an exercise to check that $\\partial$ as defined here is a homomorphism. Also, left as an exercise to check that this doesn't depend on $c\\in[c]$, and that $\\partial$ actually makes the exact sequence above exact.\n\\end{proof}\n\\subsection{Mathematical Genealogy}\nI'm not typing in anything here. It's a rather big tree:\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{assets/math-family}\n\\caption{Mathematical genealogy, growing from Lefschetz, who was initially a chemist. The asterisks are meant to indicate that someone's at MIT.}\n\\end{figure}\n", "meta": {"hexsha": "85c79db0ffbc38e0e20fa6d668dd90b6ba70e6aa", "size": 6816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-9-lexseq.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-9-lexseq.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-9-lexseq.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": 113.6, "max_line_length": 1045, "alphanum_fraction": 0.6700410798, "num_tokens": 2610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6324438949038793}}
{"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 IX 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{Multivariable Functions $-$ 14.1}\n\nThe domain of a multivariable function, $f(x,y)$, may be found by splitting parts of the function up.\n\n\\textit{Example:}\n\n$$f(x,y)=\\ln(9-x^2-9y^2)$$\n$$D(f(x,y): 9-x^2-9y^2 \\geq 0\\Longrightarrow x^2+9y^2\\leq 9 \\Longrightarrow \\frac{x^2}{9}+y^2\\leq 1 $$\n\n\\end{document}\n", "meta": {"hexsha": "5bca7407df28deb6cfdbaa0a1fd04743c001c4ca", "size": 1735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture9.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/Lecture9.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/Lecture9.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": 26.6923076923, "max_line_length": 188, "alphanum_fraction": 0.5538904899, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6324438939462075}}
{"text": "\\section{Respiratory Sinus Arrhythmia from RR-Intervals}\n\\subsection{PSD of RRI data}\nAfter processing the ECG data to RRI data in three trails, the standard and the Bartlett averange periodograms are plotted with rectangular window length $L \\in$ [$50s$, $100s$, $150s$]. Based on the analysis in section 1.2.2, the standard periodogram has relatively large variance and less leakage. With the decreasing length of window, the periodogram is tending to be smooth, resulting in both low variance and precision.\n\\begin{figure}[htb]\n     \\centering\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a2.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a3.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a4.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a5.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15a6.eps}\n     \\end{subfigure}\n        \\caption{PSD of RRI data}\n        \\label{fig:1_5_a}\n\\end{figure}\n\\subsection{Frequency of three trails}\nThe experiment recorded the ECG data of three trails with normal, fast and slow breathing respectively. Therefore, the breaths per minute (BMP) for three trails will be different. A range of $12 \\sim 20$ BMP is considered as the reference range for the normal breath. The observed peaks for three trails are $0.192Hz$, $0.416Hz$ and $0.124Hz$, corresponding to 23.04, 49.92 and 14.88 in BMP respectively. However, the harmonics frequencies of Trail 1 are failed to be captured which is probably caused by no restriction of the breath experiment. Trail 2 illustrate one harmonic at $f=0.832Hz$ and a large response at $0.928Hz$ at the same time, reasons of which may be the noise and the resolution of window. In addition, Trail 3 detects three harmonics frequencies at $0.248Hz$, $0.372Hz$ and $0.496Hz$.\n\\subsection{AR modelling of RRI data}\nFig.\\ref{fig:1_5_c} depicts the AR model estimations with the incremental of order $p$. For Trail 1, the optimal order $p=10$ which detects the approximate peak at $f=0.192Hz$. The order of Trail 2 at $p=6$ can only detect the fundamental peak while harmonics can be detected with higher order. As to Trail 3, only when the order $p\\ge2$, the peaks can be identified whereas the harmonics are difficult to be detected even if the order is high. Hence, the under-modelling causes the failed detection of peak and the over-modelling leads to capture harmonics and noise peaks. Compared with standard and averaging periodogram methods, the AR model performs powerfully in detecting interest peak and reducing variance as long as the order is determined.\n\\begin{figure}[t]\n     \\centering\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15c1.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15c2.eps}\n     \\end{subfigure}\n     ~\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/15/15c3.eps}\n     \\end{subfigure}\n        \\caption{AR Model of RRI data}\n        \\label{fig:1_5_c}\n\\end{figure}\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "493f055a7b2a9b52098738b84cc989ac4578ce4c", "size": 3693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part1/15.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/15.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/15.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": 52.014084507, "max_line_length": 804, "alphanum_fraction": 0.7064717032, "num_tokens": 1036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140728, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.6324438875621261}}
{"text": "\\section{The Ising Model}\n\n\\subsection{The partition function of the Ising model}\n\n\\begin{frame}\n  \\begin{definition}[The Ising model]\n    Let $G = (V, E)$ be a graph. The partition function of the Ising model on $G$ is\n    \\begin{equation*}\n      Z_{\\text{Ising}}(G; y, z) = \\sum_{\\sigma \\colon V \\to \\{0,1\\}} y^{m(\\sigma)} z^{n_1(\\sigma)}.\n    \\end{equation*}\n  \\end{definition}\n  \n  \\begin{itemize}\n   \\item $m(\\sigma)$ is the number of monochromatic edges of $\\sigma$.\n   \\item $n_1(\\sigma)$ is the number of vertices $v$ with $\\sigma(v) = 1$.\n  \\item $y$ is \\emph{the edge interaction}.\n  \\item $z$ is \\emph{the external field}.\n  \\end{itemize}\n  \n  \\begin{enumerate}\n  \t\\item Setting 1: there is no external field ($z = 1$).  \\\\\n  \tWe write $Z_{\\text{Ising}}(G; y) = Z_{\\text{Ising}}(G; y, 1)$.\n  \t\\item Setting 2: there is an external field ($z \\ne 1$).  \t\n  \\end{enumerate}\n  \n  \n\\end{frame}\n\n\\subsection{Example}\n\n\\begin{frame}\n\t\\vspace{-4mm}\n  \\begin{equation*}\n    Z_{\\text{Ising}}(G; y, z) = \\sum_{\\sigma \\colon V \\to \\{0,1\\}} y^{m(\\sigma)} z^{n_1(\\sigma)}.\n  \\end{equation*}\n\t\\vspace{-4mm}\n  \\begin{example}[The Ising model]\n  \t\\vspace{2mm}\n    \\begin{columns}\n      \\column{0.2\\textwidth}\n      \\begin{tikzpicture}\n        \\begin{scope}[every node/.style={circle,thick,draw}]\n          \\node (A) at (0,0) {A}; \\node (B) at (1,0.5) {B}; \\node (C) at (2,0) {C};\n        \\end{scope}\n\n\\begin{scope}[>={Stealth[black]},\n              every edge/.style={draw=black,very thick}]\n              \\path [-] (A) edge node {} (B); \\path [-] (A) edge node {} (C); \\path [-] (B) edge\n              node {} (C);\n            \\end{scope}\n          \\end{tikzpicture}\n          \n          \\invisible<1-2>{\n          \\begin{tikzpicture}\n            \\begin{scope}[every node/.style={circle,thick,draw}]\n              \\node[fill=ChetwodeBlue] (A) at (0,0) {A}; \\node (B) at (1,0.5) {B}; \\node (C) at\n              (2,0) {C};\n            \\end{scope}\n\n\\begin{scope}[>={Stealth[black]},\n              every edge/.style={draw=black,very thick}]\n              \\path [-] (A) edge node {} (B); \\path [-] (A) edge node {} (C); \\path [-] (B) edge\n              node {} (C);\n            \\end{scope}\n          \\end{tikzpicture}}\n          \n          \\invisible<1-3>{\n          \\begin{tikzpicture}\n            \\begin{scope}[every node/.style={circle,thick,draw}]\n              \\node[fill=ChetwodeBlue] (A) at (0,0) {A}; \\node[fill=ChetwodeBlue] (B) at (1,0.5)\n              {B}; \\node (C) at (2,0) {C};\n            \\end{scope}\n\n\\begin{scope}[>={Stealth[black]},\n              every edge/.style={draw=black,very thick}]\n              \\path [-] (A) edge node {} (B); \\path [-] (A) edge node {} (C); \\path [-] (B) edge\n              node {} (C);\n            \\end{scope}\n          \\end{tikzpicture}}\n        \n          \\invisible<1-4>{                  \t\n          \\begin{tikzpicture}\n            \\begin{scope}[every node/.style={circle,thick,draw}]\n              \\node[fill=ChetwodeBlue] (A) at (0,0) {A}; \\node[fill=ChetwodeBlue] (B) at (1,0.5)\n              {B}; \\node[fill=ChetwodeBlue] (C) at (2,0) {C};\n            \\end{scope}\n\n\\begin{scope}[>={Stealth[black]},\n              every edge/.style={draw=black,very thick}]\n              \\path [-] (A) edge node {} (B); \\path [-] (A) edge node {} (C); \\path [-] (B) edge\n              node {} (C);\n            \\end{scope}\n          \\end{tikzpicture}}\n          \\vspace{5mm}\n          \\column{0.6\\textwidth}\n          \\begin{align*}\n            \\invisible<1>{Z_{\\text{Ising}}(G; y, z) & = y^3 + \\cdots} \\\\ \\\\\n            \\invisible<1-2>{Z_{\\text{Ising}}(G; y, z) & = y^3 + 3yz + \\cdots} \\\\ \\\\\n            \\invisible<1-3>{Z_{\\text{Ising}}(G; y, z) & = y^3 + 3yz + 3yz^2 + \\cdots} \\\\ \\\\\n            \\invisible<1-4>{Z_{\\text{Ising}}(G; y, z) & = y^3 + 3yz + 3yz^2 + y^3z^3} \\\\ \\\\ \n            \\invisible<1-5>{ \n        \tZ_{\\text{Ising}}(G; y) & = 2 y^3 + 6y\n           }                  \n          \\end{align*}\n        \\end{columns}\n        \\invisible<6>{}\n        \\vspace{-3mm}\n      \\end{example}\n  \n \\end{frame}\n    \\subsection{Computational problems on the Ising model}\n\n\n\\begin{frame}\n  \\begin{proposition}\n    Computing the polynomial $Z_{\\text{Ising}}(G; y)$ is $\\# \\mathsf{P}$-hard.\n  \\end{proposition}\n\n  \\begin{comproblem}[$\\textsc{Ising}(y, z)$]\n  \t\\textbf{Instance:} A (multi)graph $G$. \\\\\n  \t\\textbf{Output:} $Z_{\\text{Ising}}(G; y, z)$.\n  \\end{comproblem}\n\n  \\begin{comproblem}[$\\textsc{Factor-}K \\textsc{-NormIsing}(y, z)$]\n  \t\\textbf{Instance:} A (multi)graph $G$. \\\\\n  \t\\textbf{Output:} $\\,$ A rational number $\\hat{N}$ such that\n  \t\\begin{equation*}\n  \t\\frac{1}{K} \\hat{N} \\le \\left| Z_{\\text{Ising}}(G; y, z) \\right| \\le K \\hat{N}.\n  \t\\end{equation*}   \n  \\end{comproblem}\n\n{\\color{TurkishRose} $\\textsc{Factor-}K \\textsc{-NormIsing}(y, z) \\le_T \\textsc{Ising}(y, z)$.}\n\n\t\n\n%  \\begin{problem}\n%    \\textbf{Name:} \\ \\ \\ $\\textsc{Distance-}\\rho \\textsc{-Arg-Ising}(y, z)$. \\\\\n%    \\textbf{Instance:} A (multi)graph $G$. \\\\\n%    \\textbf{Output:} $\\,$ A rational number $\\hat{A}$ such that\n%    \\begin{equation*}\n%      \\left| \\hat{A} - \\arg \\left( Z_{\\text{Ising}}(G; y, z) \\right)\\right| \\le \\rho.\n%    \\end{equation*}   \n%  \\end{problem}\n\n\\end{frame}\n", "meta": {"hexsha": "5c6d9b20d4de68c70dce6254443f2cfec9a09077", "size": 5192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Slides/Sections/cool-section.tex", "max_stars_repo_name": "andreshp/LatexTemplates", "max_stars_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-10-14T17:46:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-22T20:02:09.000Z", "max_issues_repo_path": "Slides/Sections/cool-section.tex", "max_issues_repo_name": "andreshp/PlantillasLatex", "max_issues_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-04-11T09:14:42.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-11T09:21:16.000Z", "max_forks_repo_path": "Slides/Sections/cool-section.tex", "max_forks_repo_name": "andreshp/LatexTemplates", "max_forks_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-10-14T17:54:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-15T06:39:01.000Z", "avg_line_length": 35.5616438356, "max_line_length": 99, "alphanum_fraction": 0.5127118644, "num_tokens": 1920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6324438849021923}}
{"text": "\\chapter{Transfer Function Parameters} \n\\section{Jet Transfer Functions}\n\\section{Muon Transfer Function}\n\\begin{equation}\nW\\left(\\left( \\frac{q}{p_t}\\right)_{\\mu}, \\left( \\frac{q}{p_t}\\right)_{p}, \\eta \\right) = \n\\frac{1}{2\\pi\\sigma}\\mathrm{exp}\n\\left\\{-\\frac{\\left[\\Delta\n\\left( \\frac{q}{p_t} \\right)\\right]^2}\n{2\\sigma^2}\\right\\}\n\\end{equation}\n\nwhere the Gaussian width is defined separately for two $\\eta$ regions as shown in Eq.~\\ref{muonerrortf}. The $\\eta$~region dependence is a result of the limited $\\eta$ coverage by central fiber tracker in the forward region.\n\n\\begin{equation}\n\\sigma  =  \\left\\{ \n\\begin{array} {c@{\\quad:\\quad}l} \\alpha_{1} &\n|\\eta| \\le 1.6 \\\\\n\\sqrt{\\alpha^{2}_{1} + [\\alpha_{2}(|\\eta| - 1.6)]^2} &\n|\\eta| > 1.6 \n\\end{array} \\right\\}\n\\end{equation}\n\nThe parameters $\\alpha_{1}$ and $\\alpha_{2}$ in the transfer function parameterization contain a constant term and a term proportional to $\\frac{1}{p_{T}}$. \n\n\\begin{table}[!h!tbp]\n\\begin{center}\n\\begin{tabular}{c|cc|cc|}\n\\multicolumn{5}{c}\n{\\underline{Muon Smearing Parameters}} \\\\\n       & \\multicolumn{2}{|c|}{$<$~Dec.~2004} & \\multicolumn{2}{|c|}{$>$~Dec.~2004} \\\\\nMuon Type\t\t\t\t&\tA\t\t&\tB\t\t&\tA\t\t&\tB\t\t\\\\\n\\hline\n$>1$ SMT Hit ($\\eta<1.6$)\t&\t0.00313\t&\t-0.0563\t&\t0.00308\t&\t-0.0370\t\\\\\n$>1$ SMT Hit ($\\eta>1.6$)\t&\t0.00273\t&\t-0.0491\t&\t0.00458\t&\t-0.0550\t\\\\\n$=0$ SMT Hits\t\t\t\t&\t0.00509\t&\t-0.0916\t&\t0.00424\t&\t-0.0509\t\\\\\n\\end{tabular}\n\\vspace{-0.1 in}\n\\caption{Muon smearing parameters for the function $(A + \\frac{B}{p_{T}})$ for two different run periods.}\n\\label{muonsmearparam}\n\\end{center}\n\\end{table} \n\n\n\\section{Electron Transfer Function}", "meta": {"hexsha": "b8a89180a7e847cfe5b8fded528dadecf288e579", "size": 1617, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Old/Transfer.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": "Old/Transfer.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": "Old/Transfer.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": 36.75, "max_line_length": 224, "alphanum_fraction": 0.645021645, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.685949467848392, "lm_q1q2_score": 0.6323917964311915}}
{"text": "\\subsection{Introduction to RNNs, LSTM, and ConvLSTM}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\nFeed-forward neural networks such as traditional ANNs and CNNs cannot learn temporal features from the data and hence are not the best choice for sequential data processing.\r\nTo handle such problems, a recurrent neural network (RNN) was introduced, which was specifically developed to address sequential data~\\cite{aggarwal2018neural, Lecun2015, goodfellow2016deep}. \r\nRNNs contain loops among the different nodes in their architecture to retain information in the model for long periods.\r\nRNNs employ the current input with the previous memory state.\r\nThis ability of memory-keeping enables RNNs to predict what comes next. \r\nFurthermore, RNNs were designed to handle sequential data, which implies that updating the learnable weights must consider the extent of the time dimension. \r\nAccordingly, the backpropagation~\\cite{Rumelhart1986} algorithm responsible for updating the learnable weights needs some modification to work along with the time dimension.\r\nTo alleviate this problem, backpropagation through time (BPTT)~\\cite{aggarwal2018neural, goodfellow2016deep} was introduced. \r\nIn basic RNNs, short-term memories are only preserved, therefore it becomes unfeasible in the case of dealing with long sequences of data hence it may suffer from issues like vanishing or exploding gradients~\\cite{bengio1994learning}.\r\nTherefore, the fine-tuning of the model parameters and training of RNNs becomes very hard.\r\nTo overcome such issues, Hochreiter and Schmidhuber developed the Long-Short Term Memory networks (LSTMs~\\cite{Hochreiter1997}).\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{figure} [!h]\r\n\t\\centering\r\n\t\\begin{subfigure}[b]{1\\textwidth}\r\n\t\t\\centering\r\n\t\t\\includegraphics[scale=1]{LSTM_img.png}\r\n\t\t\\caption{LSTM}\r\n\t\t\\label{fig:LSTM}\r\n\t\\end{subfigure}\r\n\t \\\\ \r\n\t \\hfill\r\n\t\\begin{subfigure}[b]{1\\textwidth}\r\n\t\t\\centering\r\n\t\t\\includegraphics[scale=1]{convlstm_image.png}\r\n\t\t\\caption{ConvLSTM}\r\n\t\t\\label{fig:ConvLSTM}\t\r\n\t\\end{subfigure}\r\n\t\\caption{LSTM and ConvLSTM architectures.}\r\n\t\\label{fig:lstm_convlstm}\r\n\\end{figure}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\nLSTMs were developed to keep information related to long-term dependencies, and to solve the problem of vanishing/exploding gradients.\r\nFurther, LSTMs handle inputs or outputs of any length that makes LSTMs powerful for solving very complex sequential problems. \r\nBasic LSTM architecture shown in Fig.~\\ref{fig:LSTM}  consists of four units: an input gate, a cell state, a forget gate, and an output gate.\r\nThese gates help regulate the flow of information that is added to or removed from the cell state. \r\nThe hidden states in LSTM hold the short-term memory, while the cells state holds the long-term memory.  \r\n\r\nThe purpose of the forget gate is to decide what information to keep and what to neglect. \r\nThe current input \\(X_{t}\\) and the previous hidden state  \\(h_{t-1}\\) are passed through a sigmoid function which will produce values between \\(0\\) and \\(1\\).\r\nThen the outputs of the sigmoid are multiplied with the previous cell state \\(C_{t-1}\\), accordingly, (\\(0\\)) outputs are discarded.\r\nThe mathematical calculation at the forget gate ($f_t$) is depicted in Eq.~(\\ref{eq:eq1}):\r\n\\begin{equation}\r\nf_{t}=\\sigma\\left(W_{f} \\cdot\\left[h_{t-1}, X_{t}\\right]+b_{f}\\right)\r\n\\label{eq:eq1}\r\n\\end{equation}\r\nwhere \\(W\\) represents the learnable weights, and \\(b\\) represents the bias term. \r\n\r\nThe input gate \\(i_{t}\\) takes the current input \\(X_t\\) with the previous hidden state \\(h_{t-1}\\) then apply the sigmoid function to get values in a range between 0 (not important) and 1 (important), then the\r\nsame current input \\(X_t\\), and the hidden state \\(h_{t-1}\\) are passed through a \\(\\tanh\\) function at \\(\\tilde{C}_{t}\\) that will regulate the network by transferring the values into a range between \\(-1\\) and \\(1\\).\r\nThen, the outputs from the sigmoid and \\(\\tanh\\) functions are multiplied point-by-point to eliminate \\(0\\) values.  \r\nEquation~(\\ref{eq:eq2}) depicts the calculation at the input gate:\r\n\\begin{equation}\r\n\\begin{aligned}\r\ni_{t} &=\\sigma\\left(W_{i} \\cdot\\left[h_{t-1}, X_{t}\\right]+b_{i}\\right) \r\n\\\\\r\n\\tilde{C}_{t} &=\\tanh \\left(W_{s} \\cdot\\left[h_{t-1}, X_{t}\\right]+b_{c}\\right) \r\n\\end{aligned} \\label{eq:eq2}\r\n\\end{equation}\r\nAt this point, the network has sufficient information obtained from the input and forget gates. \r\nHence, the current cell state \\(C_t\\) can be calculated by multiplying the previous cell state \\(C_{t-1}\\) with the output of the forget gate, then the result is added to the calculated input values as depicted in Eq.~(\\ref{eq:eq3}): \r\n\\begin{equation}\r\nC_{t}=f_{t} * C_{t-1}+i_{t} * \\tilde{C}_{t}\r\n\\label{eq:eq3}\r\n\\end{equation}\r\nThe output gate \\(o_{t}\\) computes the next hidden state \\(h_{t}\\) which\r\nholds information related to the current inputs. \r\nAccordingly, the current input \\(X_{t}\\) and the previous hidden state \\(h_{t-1}\\) are passed through a third sigmoid function to produce values between \\(0\\) and \\(1\\).\r\nThe current cell state \\(C_{t}\\) is passed through a \\(\\tanh\\) function and multiplied point-by-point with \\(o_{t}\\) to produce the new hidden state \\(h_{t}\\) which is transferred to the next timestamp.\r\nEquation~(\\ref{eq:eq4}) illustrates the calculations at the output gate:\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{equation}\r\n\\begin{aligned}\r\no_{t} &=\\sigma\\left(W_{o}\\left[h_{t-1}, X_{t}\\right]+b_{o}\\right) \\\\\r\nh_{t} &=o_{t} * \\tanh \\left(C_{t}\\right)\r\n\\end{aligned}\r\n\\label{eq:eq4}\r\n\\end{equation} \r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\nRecently, LSTMs have been widely used for large-scale learning of language translation models, speech recognition systems, chatbots, forecasting stock markets, text data analysis, and many more~\\cite{graves2014towards, cho2014properties}. \r\nHowever, LSTMs are inefficient regarding capturing spatial information by themselves when the time series inputs are consecutive images.\r\nAccordingly, ConvLSTM layer which is a combination of CNN and LSTM unit was introduced by Shi et al.~\\cite{xingjian2015convolutional} to solve such a problem.\r\nFor ConvLSTM, the convolution operations are applied both at the input-to-state transition and at the state-to-state transitions.  \r\nConvLSTM shown in Fig.~\\ref{fig:ConvLSTM} is a variation of the LSTM cell as it performs a convolution operation within the LSTM cell.\r\nConvLSTM is a combination of a convolution operation and an LSTM cell.\r\nThus, ConvLSTM can capture the time-correlated and spatial features in a series of consecutive images. \r\nEquation~(\\ref{eq:eq5}) depicts the ConvLSTM operations as the inputs \\(X_1, \\dots, X_t\\), hidden states \\(h_1, \\dots, h_t\\), cell states \\(C_1, \\dots, C_t\\) and input, forget and output gates are represented as \\(i_t, f_t\\), and \\(o_t\\), respectively:\r\n\\begin{equation}\r\n\t\\begin{aligned}\r\n\t\ti_{t} &=\\sigma\\left(W_{x i} * X_{t}+W_{h i} * h_{t-1}+W_{c i} \\odot C_{t-1}+b_{i}\\right) \r\n\t\t\\\\\r\n\t\tf_{t} &=\\sigma\\left(W_{x f} * X_{t}+W_{h f} * h_{t-1}+W_{c f} \\odot C_{t-1}+b_{f}\\right) \\\\\r\n\t\tC_{t} &=f_{t} \\odot C_{t-1}+i_{t} \\odot \\tanh \\left(W_{x c} * X_{t}+W_{h c} * h_{t-1}+b_{c}\\right) \r\n\t\t\\\\\r\n\t\to_{t} &=\\sigma\\left(W_{x o} * X_{t}+W_{h o} * h_{t-1}+W_{c o} \\odot C_{t}+b_{o}\\right) \\\\\r\n\t\th_{t} &=o_{t} \\odot \\tanh \\left(C_{t}\\right)\r\n\t\\end{aligned}\r\n\t\\label{eq:eq5}\r\n\\end{equation}\r\nwhere \\(*\\) indicates the convolution operation, and \\(\\odot\\) represents the \r\nHadamard product. \r\nRecently, ConvLSTM has become very popular and is increasingly being used in \r\nmore and more image processing applications.", "meta": {"hexsha": "9075bdcf7d1840fb4053a7a9a553c6061b48a272", "size": 7760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/journal_papers/ConvLSTM Paper/RNNS_LSTM_and_ConvLSTM.tex", "max_stars_repo_name": "IFFM-PAS-MISD/aidd", "max_stars_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-03T05:36:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T05:36:07.000Z", "max_issues_repo_path": "reports/journal_papers/ConvLSTM Paper/RNNS_LSTM_and_ConvLSTM.tex", "max_issues_repo_name": "IFFM-PAS-MISD/aidd", "max_issues_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "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": "reports/journal_papers/ConvLSTM Paper/RNNS_LSTM_and_ConvLSTM.tex", "max_forks_repo_name": "IFFM-PAS-MISD/aidd", "max_forks_repo_head_hexsha": "9fb0ad6d5e6d94531c34778a66127e5913a3830c", "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": 72.523364486, "max_line_length": 253, "alphanum_fraction": 0.7027061856, "num_tokens": 2149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.632331871298475}}
{"text": "%!TEX root =  ../../master.tex\n\\subsection{Dispersion L\\\"uscher in 2 dimensions}\n\nThe discussion above is valid only in the continuum.\nFor a discretized lattice, an additional length scale is introduced that must be accounted for.\nAs is the case in both 3-D and 1-D, there exists a dispersion L\\\"uscher equation that is valid for the contact interaction and accounts for the discretization.\nIn \\Appref{3D dispersion} we derive this dispersion L\\\"uscher formula for 2D and only state the result here.\n\nIdentifying the lattice spacing $\\epsilon=N/L$, we have\n\\begin{align}\n    \\frac{2}{\\pi} \\log \\left(\\frac{2\\pi \\tilde a_{2}}{L}\\right)\n    &=\n    \\frac{1}{\\pi^2}\n    \\left(\n        \\sum_{n_x,n_y=-\\frac{N}{2}}^{\\frac{N}{2}-1}\\frac{1}{\\tilde{K}^N_{nn}-x^\\dispersion}\n        -2\\pi \\log \\left(\\mathcal{L}^\\dispersion_2\\frac{N}{2}\\right)\n    \\right)\n    \\nonumber\\\\\n    &\\equiv\\frac{1}{\\pi^2}S^{\\dispersion}_2\\left(x^\\dispersion\\right)\\, ,\\label{eq:2d dispersion luscher}\n\t\\qquad\n    \\mathcal{L}^\\dispersion_{2}\n    =\n    \\exp \\left(\\log (2)-G \\frac{2}{\\pi}\\right)\n    =\n    1.116306393581637659468497 \\ldots\n\\end{align}\nwhere $G$ is Catalan's constant. \n\nTo demonstrate the success of this formula we tuned lattices with $N=10$, 20, and 40 to $\\tilde a_{2}/L = {1}/{10}$, which allows for a bound state, using $S^{\\dispersion}$.\nIn \\Figref{luescher2d} the black points were analyzed through $S^\\dispersion_2$, and lie on a flat line, indicating that our dispersion \\Luscher formula has correctly accounted for discretization effects.\nOn the other hand, if we use the same energies but analyze them with the usual continuum \\Luscher function $S^{\\spherical}_2$, shown as colored points, we see induced momentum-dependence and the flat line behavior is lost.\n\n\\begin{figure}\n    \\center\n    \\scalebox{0.8}{\\input{figure/2d.pgf}}\n    \\caption{\n    \tPhase shifts and zeta functions in the spherical and dispersion scenario in two dimensions.\n\t\t\\\\\n\t\t\\textit{(top)}\n        \tFinite-spacing eigenvalues $x^\\dispersion=2\\mu E^\\dispersion L^2/4\\pi^2$ of the Schr\\\"odinger equation are inserted into respective zeta functions to obtain phase shifts.\n\t\t\tThe eigenvalues are obtained for a contact interaction analytically determined for the spherical case~\\eqref{C2} and the dispersion case~\\eqref{C2-dispersion}.\n\t\t\tBoth tunings are fixed to $\\tilde a_{2}/L=1/10$ (closed symbols) and $\\tilde a_{2}/L=0$ (open symbols).\n\t\t\tDifferent markers correspond to different discretizations: $N=4$ (triangles), 10 (squares), 12 (diamonds), and 14 (hexagons).\n        \tFor analysis, the colored points are obtained using $S^\\spherical_2(x^\\dispersion)$; corresponding to $N=4$ (red), 10 (green), 20 (blue), and 40 (purple).\n        \tThe thin colored lines are the derived induced momentum-dependent terms for each $N$ as given in \\Tabref{induced terms in 2 d}.\n        \tThe black points are obtained using the $N$-appropriate $S^{\\dispersion}_2(x^\\dispersion)$ and exhibit the correct flat-line behavior.\n        \tThe dashed gray line is $S_2^\\spherical$, as in the bottom panel.\n        \\\\\n        \\textit{(bottom)}\n        \tTwo one-dimensional zeta functions, the spherical function $S_2^{\\spherical}$ (light gray) given in \\eqref{2d luscher} and $S_2^{\\dispersion}$ (red) given in \\eqref{2d dispersion luscher} with $N=4$ and $\\nstep=\\infty$.\n        \tThe difference between the dispersion and spherical curves is responsible for moving the red triangles to the black triangles in the top panel.\n\t}\n    \\label{fig:luescher2d}\n\\end{figure}\n\nAs was done in the three- and one-dimensional cases, we can derive the functional form of the induced momentum-dependent terms.\nThe derivation is identical to those cases; for concision we show only the end result.\nExpanded around small $x^\\dispersion$ one finds\n\\begin{equation}\n    \\label{eq:2D corrections}\n    S^\\bigcirc_{2}\\left(x^\\dispersion\\right)\n    =\n    2\\pi\\log\\left(2\\pi \\frac{\\tilde a_{2}}{L}\\right)\n    + \\alpha_1(N)\n    + \\alpha_2(N) x^\\dispersion\n    + \\alpha_3(N) (x^\\dispersion)^2\n    + \\ldots\n\\end{equation}\nThe coefficients $\\alpha_i(N)$ have an implicit dependence on $N$ since the sums are restricted outside of the Brillouin zone.  Further, in 2-D the sums involved in $\\alpha_i$ converge sufficiently fast and there exist various techniques for evaluating these sums (see Appendices A of \\Ref{Fiebig:1994qi,Beane:2010ny}).\nWe provide the numerical values of $\\alpha_i(N)$ in \\Tabref{induced terms in 2 d} for the discretizations shown in \\Figref{luescher2d}.\nThese functions were also used to calculate the thin colored lines in \\Figref{luescher2d}, where we see the small-$x$ expansion lose accuracy quickly for $N=4$ (consider the bound state, for example) but hold deeper into the spectrum for larger $N$.\n\n\\begin{table}\n    \\caption{The coefficients $\\alpha_i$ of the induced momentum-dependent terms in \\eqref{2D corrections} due to a contact interaction using $S^\\bigcirc_2(x^\\dispersion)$ as a function of discretization $N$, assuming $\\nstep=\\infty$.\n    }\n    \\label{tab:induced terms in 2 d}\n    \\begin{tabular}{S[table-format=2.1]S[table-format=2.6]S[table-format=2.7]S[table-format=2.8]}\n{$N$} & {{$\\alpha_1$}} & {$\\alpha_2$} & {$\\alpha_3$} \\\\ \\midrule\n    4   &   0.20642   &   0.726184 & 0.0937105           \\\\\n    10  &   0.03402   &   0.105117 & 0.0018607           \\\\\n    20  &   0.00086   &   0.025850 & 0.0001108           \\\\\n    40  &   0.00851   &   0.006433 & 0.0000068    \\\\\n\\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "81bbe85b73f8725b040c8738cfadc15a3e016db9", "size": 5468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/two-dimensions/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/two-dimensions/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/two-dimensions/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": 64.3294117647, "max_line_length": 319, "alphanum_fraction": 0.700987564, "num_tokens": 1661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.6323318559982495}}
{"text": "\n\n\n\\chapter{Quantum Mechanics}\n\n\n\\section{Fundamentals}\n\nQuantum Mechanical systems are represented by state vectors which, together with the rules for how these vectors will evolve, tell us everything that can be predicted about a quantum system. A ''bra\" is a column vector represented as  $\\langle  \\psi| $ and is always accompanied by a row vector called a ''ket\" represented as $| \\psi \\rangle$. Looking at the combination of these two, we create a \"bracket\" $\\langle\\psi|\\psi\\rangle$ doing just normal vector multiplication. As an example, let's say our Hilbert space is just two dimensional\n\\begin{align}\n    \\langle\\psi| = (a^*,b^*) && |\\psi\\rangle = \\left(\n{\\begin{array}{c}\na\\\\\nb\\\\\n\\end{array}}\n\\right)\n\\end{align}\n\n\\subsection{Basis}\nAny state vector can be represented in another basis, as long as it also spans the same Hilbert space, with \n\\begin{align}\n|\\psi\\rangle  = \\sum_{n} |n\\rangle\\langle n|\\psi\\rangle\n\\end{align}\nThe value $\\langle n|\\psi\\rangle = c_n$ is just a (potentially complex) number. Let us pretend that $n = a,b$ thus we have\n\\begin{align}\\label{abbasis}\n|\\psi\\rangle &= |a\\rangle\\langle a |\\psi\\rangle + |b\\rangle\\langle b |\\psi\\rangle \\\\\n&= c_a|a\\rangle + c_b|b\\rangle\n\\end{align}\nDual correspondence tells us that the bra takes the roughly same form with\n\\begin{align}\n\\langle \\psi | &= c_a^*\\langle a| + c_b^*\\langle b|\n\\end{align}\n\n\nThe chance that the state $|\\psi\\rangle$ is in any of the states at a given time can be found with\n\\begin{align}\nP_n &= |\\langle n|\\psi\\rangle |^2\\\\\n&= |c_n|^2\n\\end{align}\nThis can be seen since we must have the requirement that $|\\psi\\rangle$ is found in at least one of the states (and is normalized) with\n\\begin{align}\n1 &= \\langle \\psi |\\psi \\rangle\\\\\n&= \\sum_{n} \\langle \\psi |n\\rangle\\langle n|\\psi\\rangle\\\\\n&= \\sum_n (\\langle n|\\psi\\rangle)^*\\langle n |\\psi \\rangle\\\\\n&= \\sum_n |\\langle n | \\psi \\rangle |^2\\\\\n&= \\sum_n P_n\n\\end{align}\n\n\n\n\\subsection{Measurement}\nA measurement on a Quantum Mechanical system is not at all straight forward. Firstly, all observables are real, which requires the operator associated with them to be Hermitian with\n\\begin{align}\nA = (A^T)^* = A^\\dagger\n\\end{align}\n\n\n\n Let us pretend that $A$ spans a Hilbert space given by Equation \\ref{abbasis}. Pretending that\n\\begin{align}\nA|a\\rangle = a |a\\rangle && A|b\\rangle = b|b\\rangle\n\\end{align}\nThen\n\\begin{align}\nA|\\psi\\rangle = c_a a|a\\rangle + c_b b|b\\rangle \n\\end{align}\nNow one may think that you would get some combination of the values $a$ and $b$, but in fact \\emph{you get only one}! Although the chance you get one will be weighted with probability $|c_n|^2$. Only on average will you get\n\\begin{align}\n\\langle A\\rangle = \\langle \\psi | A|\\psi\\rangle = |c_a|^2 a + |c_b|^2 b\n\\end{align}\nWhen the measurement takes place, it is said that the wave function \"instantaneously collapses\" into one of the eigenstates of the operator $A$ (with the probabilities given above).\n\\begin{align}\nA|\\psi\\rangle \\rightarrow \\rm{Measurement} &\\rightarrow a|a\\rangle  && \\textrm{with~Probability} =  |c_a|^2 \\\\\n&\\rightarrow b|b\\rangle  && \\textrm{with~Probability} =  |c_b|^2 \n\\end{align}\nOperators can also be expressed as Matrices using the following rules\n\\begin{align}\nA &= \\sum_n^N\\sum_{n'}^N |n\\rangle\\langle n| A |n'\\rangle \\langle n'|\\\\\n&=\\sum_n^N\\sum_{n'}^N\\langle n| A |n'\\rangle |n\\rangle\\langle n'|\\\\\n&= \\left(\n{\\begin{array}{ccc}\n\\langle n_1|A |n'_1\\rangle&\\hdots&\\langle n_1|A|n'_N\\rangle\\\\\n\\vdots&\\ddots&\\vdots\\\\\n\\langle n_N| A|n'_1\\rangle &\\hdots&\\langle n_N | A | n'_N\\rangle\\\\\n\\end{array}}\n\\right)\n\\end{align}\nThe placement of the off diagonals can be figured out because all operators should act on the index they are closest to from the projection operator with $n|n_1\\rangle\\langle n_1|A$.\n\n\nQuantum mechanics is strange and it turns out there are some things you can't know at the same time. An \"observation\" of some variable (i.e. position, momentum, etc) is represented by a respective operator denoting that type of obervation. Two things are said to be compatible observables if\n\\begin{align}\nAB|\\psi\\rangle  &= BA |\\psi\\rangle\n\\end{align}\nWhich tells us the order in which we make the observations have no effect on what we end up seeing. Written in a more succint way, the operators are said to \\emph{commute}, with\n\\begin{align}\nAB - BA = [A,B] = 0\n\\end{align}\nThese compatible observables can be used to break degeneracy. The basic algorithm for doing this is finding all the eigenvalues and eigenvectors for $A$ and $B$, then identifying valid combinations of the vectors that still return unique eigenvalues when operated on by the respective matrix\\cite{sakurai}. In three dimensions it is possible to have a simultaneous ket of all $x,y,z$ coordinates in Cartesian, which lets us write things like\n\\begin{align}\n\\hat{y}|\\textbf{x}\\rangle = y|\\textbf{x}\\rangle\n\\end{align}\nIf it turns out that the ordering of the operators acting on the state \\emph{does} matter, we say that\n\\begin{align}\n[A,B]\\neq 0\n\\end{align}\nA typical example is position and momentum which do not commute, with\n\\begin{align}\n[x,p] = i\\hbar\n\\end{align}\n\n\\subsection{Probability Current}\nWe can use the continuity equation in quantum mechanics for the probability current with\n\\begin{align}\n\\frac{d\\rho}{dt} = -\\nabla\\cdot\\textbf{j}\n\\end{align}\nThis probability current $\\textbf{j}$ tells us the 'probability' flowing through a given surface area per unit time per unit area.\n\\begin{align}\n\\textbf{j} = \\frac{\\hbar}{2mi}\\Big(\\psi^*\\nabla\\psi - \\psi\\nabla\\psi^*\\Big)\n\\end{align}\n\n\n\\subsection{Wave Function}\nThe wave function in relation to a ket is simply\n\\begin{align}\n\\psi(\\textbf{x}) = \\langle \\textbf{x}|\\psi\\rangle\n\\end{align}\nWith just this we can do a lot, including some tricks that use the fact that all observables are Hermitian. For instance\n\\begin{align}\n\\langle \\textbf{x}'  | \\textbf{x} | \\psi\\rangle = \\textbf{x}'\\langle \\textbf{x}'|\\psi\\rangle\n\\end{align}\n\n\n\nWe can also often write expectation values as integrals by inserting multiple sets of states\n\\begin{align}\n\\langle \\psi | y |\\psi\\rangle &= \\int d\\textbf{x} \\int d\\textbf{x}'  \\langle \\psi | \\textbf{x}\\rangle \\langle \\textbf{x} |y|\\textbf{x}'\\rangle\\langle \\textbf{x}'|\\psi\\rangle\\\\\n&= \\int d\\textbf{x} \\int d\\textbf{x}'~  \\langle \\psi | \\textbf{x}\\rangle y\\delta(\\textbf{x}-\\textbf{x}')\\langle \\textbf{x}'|\\psi\\rangle\\\\\n&= \\int d\\textbf{x}~\\psi^*(\\textbf{x}) y\\psi(\\textbf{x})\n\\end{align}\nThe transformation function from $x$ to $p$ can be obtained with\n\\begin{align}\n\\langle x |\\hat{p}|p\\rangle = -i\\hbar\\frac{\\partial}{\\partial x}\\langle x|p\\rangle\n\\end{align}\nThe operator $\\hat{p}$ acting on its eigenket simply gives back its eigenvalue $p$, so this becomes a differential equation with solution\n\\begin{align}\n\\langle x | p \\rangle = A\\exp\\Big[\\frac{i p x}{\\hbar}\\Big]\n\\end{align}\nAnalogously in three dimensions, with a normalizing factor obtained on page 55 of Sakurai.\n\\begin{align}\n\\langle \\textbf{x} |\\textbf{p}\\rangle = \\frac{1}{(2\\pi\\hbar)^{3/2}}\\exp\\Big[\\frac{i\\textbf{p}\\cdot\\textbf{x}}{\\hbar}\\Big]\n\\end{align}\n\n\n\n\\subsection{Changing Basis}\nChanging basis is easy when you are given two complete sets of eigenstates, say $|S_y;\\pm\\rangle$ and$|S_x;\\pm\\rangle$. If you want to solve for \n\n$$|S_y;+\\rangle = a|S_x;+\\rangle + b|S_x;-\\rangle$$\n\nJust get the coefficients because you can sum over each state, i.e\n\n\\begin{align}\n|S_y;+\\rangle &=\\sum|S_x;\\pm\\rangle\\langle S_x;\\pm|S_y;+\\rangle\\\\\n&= \\langle S_x;+|S_y;+\\rangle |S_x;+\\rangle + \\langle S_x;-|S_y;+\\rangle |S_x;-\\rangle\\\\\n&= a|S_x;+\\rangle + b|S_x;-\\rangle\n\\end{align}\n\\section{Quantum Dynamics}\nLet's say we want some operator $U$ that  changes the wavefunction, but still preserve it's inner product such that\n\\begin{align}\n1 = \\langle \\psi |\\psi\\rangle = (\\langle\\psi|U^\\dagger )(U|\\psi\\rangle)\n\\end{align}\nOr more clearly, we want the property\n\\begin{align}\nU^\\dagger U = UU^\\dagger = 1\n\\end{align}\nThese are called \\emph{unitary operators}. Let's pretend we have some parameter contained in the wavefunction we want to change a small amount $\\varepsilon$. We now want to find some operator that allows us to change this parameter, yet still preserve the inner product so we don't have to keep normalizing it. Because the change is small, we expect it to be linear in $\\varepsilon$, so \n\\begin{align}\nU(\\varepsilon) = I + G\\varepsilon\n\\end{align}\nWhere the $G$ is some operator to be determined, and $I$ is the identity operator and comes from the fact that if we have $\\varepsilon = 0$, the wave function shouldn't change at all. Using the definition of the unitary operator, we see that\n\\begin{align}\nI = U^\\dagger U  = (I +G^\\dagger\\varepsilon)(I + G\\varepsilon) = I + G^\\dagger\\varepsilon + G\\varepsilon + G^\\dagger G\\varepsilon^2\n\\end{align}\nBecause $\\varepsilon$ is small, we forget about the squared term, and subtracting terms, we see\n\\begin{align}\nG^\\dagger = -G\n\\end{align}\nThis is the definition of an \\emph{antihermitian} operator which are kind of gross, but we know that if we define an operator as\n\\begin{align}\nG = -iH && G^\\dagger = iH^\\dagger\n\\end{align}\nThus we see that\n\\begin{align}\nH^\\dagger = H\n\\end{align}\nAnd we now have a \\emph{Hermitian operator} which are things that describe observables in Quantum mechanics and are all over the place. These are overall much nicer to work with. So our unitary operator can be written as \n\\begin{align}\nU(\\varepsilon) = 1 -iH\\varepsilon\n\\end{align}\nThe nomenclature that goes around this is that $H$ is the \\emph{generator} of the change in $\\varepsilon$. \n\n\n\n\n\n\n\n\\subsection{Translation Operators}\nThe position translation operator is defined as \n\\begin{align}\n\\mathcal{J}(dx)|x\\rangle = |x+dx\\rangle\n\\end{align}\nTo find the mathematical representation of the operator, we let it operate on $|\\psi\\rangle$\n\\begin{align}\n\\mathcal{J}(\\Delta x)|\\psi\\rangle &= \\mathcal{J}(\\Delta x)\\int |x\\rangle \\langle x|\\psi\n\\rangle\\\\\n&=\\int dx |x+\\Delta x\\rangle \\langle x|\\psi\n\\rangle\\\\\n&=\\int dx|x\\rangle \\langle x-\\Delta x|\\psi\n\\rangle\\\\\n&= \\int dx|x\\rangle \\psi (x-\\Delta x)\n\\end{align}\nThe last step is essentially changing integration bounds. Now that we have a function and no longer a vector, we can Taylor expand\n\\begin{align}\n\\psi(x-\\Delta x) \\approx \\psi(x) -\\Delta x\\frac{\\partial\\psi(x)}{\\partial x}\n\\end{align}\nThus we have\n\\begin{align}\n\\mathcal{J}(\\Delta x)|\\psi\\rangle &= \\int dx |x\\rangle \\Big[\\psi(x) -\\Delta x\\frac{\\partial\\psi(x)}{\\partial x}\\Big]\\\\\n\\end{align}\nUsing the relation \n\\begin{align}\n\\boxed{p_x= -i\\hbar\\frac{\\partial}{\\partial x}}\n\\end{align}\nWe can rewrite\n\\begin{align}\n\\mathcal{J}(\\Delta x)|\\psi\\rangle &= \\int dx \\Big[1 -\\frac{i \\Delta x p}{\\hbar}  \\Big]\\psi(x)|x\\rangle \\\\\n&= \\Big(1-\\frac{i\\Delta xp}{\\hbar}\\Big)\\int dx |x\\rangle\\langle x|\\psi\\rangle\\\\\n&=\\Big(1- \\frac{i\\Delta x p}{\\hbar} \\Big) |\\psi\\rangle \n\\end{align}\nSo we say that momentum is the generator of translation. Intuitively, we know that if we keep acting small translations over and over again on a state, we should be able to move it some finite amount, which is roughly the basis for calculus itself. Let's pretend we want to move a total amount $d$ but divide it up into $N$ steps to make each step really small.\n\\begin{align}\n    \\mathcal{J}(d)|\\psi\\rangle = \\Big(\\mathcal{J}(d/N)\\mathcal{J}(d/N)...\\Big)|\\psi\\rangle = \\Big[\\mathcal{J}(d/N)\\Big]^N|\\psi\\rangle\n\\end{align}\nLet's look at the form of that operator\n\\begin{align}\n    \\Big[\\mathcal{J}(d/N)\\Big]^N = \\Big(1- \\frac{i d p}{N\\hbar} \\Big)^N\n\\end{align}\n\nIn the limit that $N$ goes to infinity, if you remember from precalculus, this is the definition of an exponential. Thus the finite operator, obtained by acting the infinitesimal operator many times, then becomes\n\\begin{align}\n\\mathcal{J}(x) = \\exp\\Big[ -\\frac{i x p}{\\hbar}\\Big]\n\\end{align}\n\n\n\\subsection{Time Evolution Operator}\\label{timeevolve}\nIn the same way we found the translation operator, we can find the time evolution operator as\n\n\\begin{align}\n\\mathcal{U}(dt)|\\psi\\rangle = 1 - \\frac{iHdt}{\\hbar}|\\psi\\rangle \n\\end{align}\nIf the Hamiltonian is \\textbf{not time dependent}, the finite operator becomes\n\\begin{align}\n\\mathcal{U}(t) = \\exp\\Big[-\\frac{iHt}{\\hbar}\\Big]\n\\end{align}\nWe can now look at two subsequent time translation operations\n\\begin{align}\n    \\mathcal{U}(t + dt) &= \\mathcal{U}(dt)~\\mathcal{U}(t) \\\\\n    &= \\Big(1 - \\frac{iHdt}{\\hbar}\\Big)\\mathcal{U}(t)\\\\\n    &= \\mathcal{U}(t) - \\frac{iHdt}{\\hbar}\\mathcal{U}(t)\n\\end{align}\nShifting this equation around, and since $dt$ is already infinitesimally small, we get the definition of the time derivative\n\\begin{align}\n    \\frac{\\mathcal{U}(t + dt) - \\mathcal{U}(t)}{dt} = -\\frac{iH}{\\hbar}\\mathcal{U}(t)\n\\end{align}\nOr\n\\begin{align}\\label{operatorevo}\n    i\\hbar\\frac{\\partial}{\\partial t}\\mathcal{U}(t) = H\\mathcal{U}(t)\n\\end{align}\n\n\n\n\\subsection{Schrodinger and Heisenberg}\nThere are two primary views as to how the machinery behind Quantum mechanical systems evolve, which happen to also be mathematically equivalent. The first, due to Schrodinger, treats the kets as moving in time but all operators as constant. \n\\begin{align}\n    |\\psi(t)\\rangle = \\mathcal{U}(t)|\\psi\\rangle\n\\end{align}\nThis gives us the \\textbf{Schrodinger equation} as\n\\begin{align}\ni\\hbar\\frac{\\partial\\psi }{\\partial t} = H\\psi\n\\end{align}\nThe second approach treats the operators as changing in time, but as if the basis they act on is always a constant (i.e. fixed kets). \n\n\n\\begin{align}\n    A(t)^{(H)} = \\mathcal{U}^\\dagger(t)~ A^{(S)}~\\mathcal{U}(t)\n\\end{align}\nTaking the time derivative of this, using equation \\ref{operatorevo}, we get\n\\begin{align}\n    \\frac{d}{dt} A^{(H)}(t) &= \\Big[\\frac{d}{dt}\\mathcal{U}^\\dagger(t)\\Big]A^{(S)}~\\mathcal{U}(t) + \\mathcal{U}^\\dagger(t)A^{(S)}\\Big[\\frac{d}{dt}\\mathcal{U}\\Big]\\\\\n    &= - \\frac{1}{i\\hbar}H\\mathcal{U}^\\dagger(t)~ A^{(S)}~\\mathcal{U}(t) + \\frac{1}{i\\hbar}\\mathcal{U}^\\dagger(t)~ A^{(S)}~H\\mathcal{U}(t)\n\\end{align}\n\nUsing the fact that the Hamiltonian commutes with the time translation operator, by it's definition, we get \n\\begin{align}\n\\frac{d}{dt} A^{(H)}(t) = \\frac{1}{i\\hbar}[A^{(H)},H]\n\\end{align}\nThis is the \\textbf{Heisenberg equation} analogous to the Schrodinger equation, although in my experience, used much less frequently.\n\n\\subsection{Feynman Propagator}\nIf we start with some arbitrary ket $|\\psi, t_0\\rangle$, we can first time evolve it using the time evolution operator (Section \\ref{timeevolve}), then insert two complete sets of states $|a\\rangle\\langle a|$  and $|\\textbf{x}\\rangle\\langle\\textbf{x}|$ that the Hamiltonian will act on (from the Hermiticity of the Hamiltonian), giving us\n\\begin{align}\n|\\psi, t\\rangle &= \\sum_a \\int dx^3~|a\\rangle\\langle a|\\textbf{x}\\rangle \\langle\\textbf{x}|\\psi,t_0\\rangle e^{-iE_a(t-t_0)}\\\\\n&=\\sum_a |a\\rangle \\int dx^3~a(\\textbf{x})e^{-iE_a(t-t_0)}\\psi(\\textbf{x},t_0) \n\\end{align}\nWe can then dot this with a new set of bra's $\\langle \\textbf{x}'|$, which gives us\n\\begin{align}\n\\psi(\\textbf{x}', t) &= \\sum_a a(\\textbf{x}') \\int dx^3~a(\\textbf{x})e^{-iE_a(t-t_0)}\\psi(\\textbf{x},t_0)\\\\\n&= \\int dx^3~\\sum_a a^*(\\textbf{x}') a(\\textbf{x})e^{-iE_a(t-t_0)}\\psi(\\textbf{x},t_0)\n\\end{align}\nWe can then identify something called the propagator $K(\\textbf{x}', t;\\textbf{x},t_0)$ as\n\\begin{align}\nK(\\textbf{x}', t;\\textbf{x},t_0) &= \\sum_a a^*(\\textbf{x}') a(\\textbf{x})e^{-iE_a(t-t_0)}\n\\end{align}\nWhich lets us write the wave function \"propagated\" into the future at a new position as\n\\begin{align}\n\\psi(\\textbf{x}', t) = \\int dx^3~K(\\textbf{x}', t;\\textbf{x},t_0)\\psi(\\textbf{x},t_0)\n\\end{align}\n\n\n--- Might be wrong from here ---\n\n\\begin{align}\n    K(\\textbf{x}', t;\\textbf{x},t_0) = \\langle \\textbf{x}', t| \\exp\\Big(-\\frac{i}{\\hbar}\\hat{H}(t-t_0)\\Big)|\\textbf{x},t_0\\rangle\n\\end{align}\nPath integral is an expression for this transition amplitude. We divide $t-t_0$ into $N$ steps, and make a whole bunch of integrals\n\n\\begin{align}\n    \\epsilon = (t-t_0)/N \n\\end{align}\nSo after breaking it up, we get\n\\begin{align}\n    \\int dq_1, dq_2, ... dq_{N-1} \\langle q''|(1-i\\epsilon\\hat{H})|q_{N-1}\\rangle\\langle q_{N-1}|(1-i\\epsilon\\hat{H})|q_{N-2}\\rangle  ...\n\\end{align}\n \n\n\n\n\n%TODO \\subsection{Density Matrix}\n%Can define quantum entropy with the density matrix.\n\n\n\n\n\n\\subsection{Useful Operator Tricks}\n\nThe \\emph{essential} commuation relation is\n\\begin{align}\n\\boxed{[x_i,p_j] = i\\hbar\\delta_{ij}}\n\\end{align}\n\n\n\n\n\\begin{align}\n[A,BC] = [A,B]C + B[A,C]\n\\end{align}\n\n\nA nice consequence of this relationship is known as \\textbf{Ehrenfest's Theorem} which goes as \n\\begin{align}\n[p_i,F(\\textbf{x})] = -i\\hbar\\frac{\\partial F}{\\partial x_i}\\\\\n[x_i,G(\\textbf{p})] = i\\hbar\\frac{\\partial G}{\\partial p_i}\n\\end{align}\nAnother nice one is the \\textbf{Baker-Campbell-Hausdorff} lemma can be written as\n\\begin{align}\ne^X Ye^{-X} = Y + [X,Y], + \\frac{1}{2!}[X,[X,Y]] + ...\n\\end{align}\nTypically one an exam, it is easier to just Taylor expand the exponent with \n\\begin{align}\ne^X = \\sum_{n=0}^\\infty \\frac{X^n}{n!}\n\\end{align}\nThen find some pattern in the exponent which terminates as you look at higher and higher powers of $n$. This relationship shows up often in rotation questions. Another nice one is\n\\begin{align}\n e^{AB} = e^Ae^Be^{-[A,B]/2}\n\\end{align}\n The generalized uncertainty relation is given as\n\\begin{align}\n\\sigma_A^2\\sigma_B^2 \\ge \\frac{1}{4} |\\langle [A,B]\\rangle |^2\n\\end{align}\nWhich gives us the classic Heisenberg uncertainty relation with $A=x,B=p$ as\n\\begin{align}\n\\sigma_x\\sigma_p \\ge \\frac{\\hbar}{2}\n\\end{align}\n\n\n\n\n\n\\section{Rotation}\nAlso see section \\ref{classicalrot}. We should have some generator of rotation, in the same way we have one for time and position translation. This generator happens to be the angular momentum operator with\n\\begin{align}\n\\mathcal{D}(\\hat{n},d\\phi) = 1 - i\\Big(\\frac{\\textbf{J}\\cdot\\hat{n}}{\\hbar}\\Big)d\\phi\n\\end{align}\nApplying this many, many times gives us the operator for a finite rotation\n\\begin{align}\\label{rotation}\n\\mathcal{D}(\\hat{n}, \\phi) = \\exp\\Big[\\frac{-i\\textbf{J}\\cdot\\hat{n}\\phi}{\\hbar}\\Big]\n\\end{align}\nWe act this operator on a ket to find out it's rotated form with\n\\begin{align}\n|\\alpha_R\\rangle = \\mathcal{D}(\\hat{n}, \\phi)|\\alpha\\rangle\n\\end{align}\nIntuitively, we know that a rotation won't change the size of an object, it will just reorient it. Since the determinant of a matrix corresponds to its size, we come up with another requirement for the rotation translators, with\n\\begin{align}\\label{specialunitary}\n    \\det\\Big(\\mathcal{D}\\Big) = 1\n\\end{align}\nThis defines the \\emph{special unitary group}. \n\n\n\n\\subsection{Spin 1/2}\nStarting just with $S_z$ and it's eigenvectors, we know\n\\begin{align}\n\\langle + |S_z|+\\rangle &= \\frac{\\hbar}{2}\\\\\n\\langle - |S_z|-\\rangle &= -\\frac{\\hbar}{2}\n\\end{align}\nNow we only have two things to remember, the definition of the ladder operators\n\n\\begin{align}\nS_\\pm \\equiv S_x \\pm iS_y\n\\end{align}\n\nAnd the effective \"eigenvalues\" that come out when the ladder operators act on kets\n\n\\begin{align}\\label{ladder}\nJ_+|jm\\rangle &= \\hbar\\sqrt{(j-m)(j+m+1)}|jm+1\\rangle\\\\\nJ_-|jm\\rangle &= \\hbar\\sqrt{(j+m)(j-m+1)}|jm-1\\rangle\n\\end{align}\n\nTo remember these, know that it is $(j-m + ?)(j + m + ?)$ and the kets must annihilate when the operators act on a state where $J_+|jj\\rangle = 0$, which gives us the placement of the 1. Using both of these equations, we can get the matrix representation of $S_x, S_y$. Since\n\\begin{align}\nS_+|+\\rangle &= 0 &&S_+|-\\rangle = \\hbar|+\\rangle\\\\\n\\end{align}\nIn matrix form, we get\n\\begin{align}\nS_+ &= \\hbar \\left(\n{\\begin{array}{cc}\n0&0\\\\\n1&0\n\\end{array}}\n\\right)\n\\end{align}\nSimilarly for $S_-$\n\\begin{align}\nS_- = \\hbar\\left(\n{\\begin{array}{cc}\n0&1\\\\\n0&0\n\\end{array}}\n\\right)\n\\end{align}\nBy manipulating the equations for $S_\\pm$, we can find expressions for $S_x$ and $S_y$, with\n\\begin{align}\nS_x = \\frac{1}{2}(S_+ +S_-) &= \\frac{\\hbar}{2}\\left(\n{\\begin{array}{cc}\n0&1\\\\\n1&0\n\\end{array}}\n\\right)\\\\\nS_y = -\\frac{i}{2}(S_+ - S_-) &= \\frac{\\hbar}{2}\\left(\n{\\begin{array}{cc}\n0&-i\\\\\ni&0\n\\end{array}}\n\\right)\\\\\nS_z &= \\frac{\\hbar}{2}\\left(\n{\\begin{array}{cc}\n1&0\\\\\n0&-1\n\\end{array}}\n\\right)\n\\end{align}\n\n\nWhere $S_z$ we already knew at the start from orthogonality of the states. These operators, as well as all angular momentum operators in general, obey a set of commutator relations that show up frequently in exam questions. The most important of which is likely\n\\begin{align}\n[J_x, J_y] &= i\\hbar J_z\n\\end{align}\nThis group of operators is \\textbf{non-Abelian}, which synonomous with the fact that their commutator is non-zero. They also define a \\emph{Lie group} which are super important in physics for some reason. It also turns out that the total squared angular momentum operator commutes with each direction individually\n\n\\begin{align}\n[J^2, J_i] &= 0 &&(i=1,2,3)\\\\\n\\end{align}\nSome other nice ones to speed things up, but could be derived just knowing the definitions of $J_\\pm$ are\n\\begin{align}\n[J_+,J_-] &= 2\\hbar J_z\\\\\n[J_z,J_\\pm] &= \\pm\\hbar J_\\pm\n\\end{align}\n\n\nThe matrices in each expression for $S_x,S_y,S_z$ happen to be the Pauli matrices\n\\vskip 0.2in\n\\centerline{\\begin{tabular}{c c c}\n$\\sigma_1 = \\Big(~ \\begin{matrix}\n 0 & 1 \\\\\n 1 & 0\n \\end{matrix} ~\\Big)$ &  $\\sigma_2 = \\Big(~ \\begin{matrix}\n 0 & -i \\\\\n i & 0\n \\end{matrix} ~\\Big)$  & $\\sigma_3 = \\Big(~ \\begin{matrix}\n 1 & 0 \\\\\n 0 & -1\n \\end{matrix} ~\\Big)$ \\\\\n\\end{tabular}}\n\\vskip 0.2in\nThese matrices obey another important set of properties\n\\begin{align}\n\\sigma_1^2 = \\sigma_2^2 = \\sigma_3^2 = -i\\sigma_1\\sigma_2\\sigma_3 = I\n\\end{align}\nWhere $I$ is the identity matrix. They also have no trace and determinant equal to negative one\n\\begin{align}\n\\rm{Tr}~\\sigma_i &= 0\\\\\n\\det\\sigma_i &= -1\n\\end{align}\n\nA nice way to show that these matrices must be traceless starting from the fact that rotation operator must have unit determinant (Equation \\ref{specialunitary}) is\n\\begin{align}\n    \\det\\Big(\\mathcal{D}(d\\phi)\\Big) = 1  = \\det\\Big(I -i\\sigma_i d\\phi\\Big) = \\det\n\\left(\n{\\begin{array}{ccc}\n1 -i \\sigma_i^{11}d\\phi&-i\\sigma_i^{12}d\\phi\\\\\n-i\\sigma_i^{21}d\\phi&1-i\\sigma_i^{22}d\\phi\n\\end{array}}\n\\right)\n\\end{align}\nSince $d\\phi$ is small by definition we have that, \n\\begin{align}\n    \\det(I-i\\sigma_id\\phi) \\approx (1-i\\sigma_i^{11}d\\phi)(1-\\sigma_i^{22}d\\phi) \\approx -i(\\sigma_{11}+\\sigma_{22})d\\phi\n\\end{align}\nWe see that the factor in the parentheses is identical to the trace of the matrix, and the requirement that the determinant be 1 gives us\n\\begin{align}\n    1 = 1  -i\\rm{Tr}(\\sigma_i)d\\phi\n\\end{align}\nTherefore the trace of the Pauli matrices must be zero to keep the operator of unit determinant for finite $d\\phi$.\n\n\nIn two dimensions, after working out the matrix math, we can represent any rotation from equation \\ref{rotation} as \n\n\n\n\n\\begin{align}\n\\mathcal{D}(\\hat{n},\\phi) = \\exp\\Big[\\frac{-i\\textbf{S}\\cdot\\hat{n}\\phi}{\\hbar}\\Big] = \\textbf{I}\\cos\\frac{\\phi}{2} -i\\boldsymbol{\\sigma}\\cdot\\hat{n}\\sin\\frac{\\phi}{2}\n\\end{align}\n\nTake note of the \\textbf{extra factor of 1/2}. It can also be shown that the positive eigenstate of any spinor in relation to the $z$ eigenstates is given as\n\\begin{align}\n|S_{\\theta,\\phi}; +\\rangle =\\cos\\frac{\\phi}{2}|+\\rangle +\\sin\\frac{\\phi}{2}e^{i\\theta}|-\\rangle\n\\end{align}\n\n\n\n\\subsection{Entanglement}\nPretend that somehow, you obtained a state that is composed of two spin 1/2 particles, $1$ and $2$. Both these particles live in different Hilbert spaces, meaning that each one can be expressed as a linear combination of its own eigenstates, let's choose the basis along the $z$ axis as is customary, so\n\\begin{align}\n    |\\psi_1 \\rangle &= \\sum_i c_{1i} | \\psi_{1i}\\rangle  = c_{1+} |\\uparrow_1\\rangle + c_{1-}|\\downarrow_1\\rangle\\\\\n    |\\psi_2 \\rangle &= \\sum_j c_{2j} | \\psi_{2j}\\rangle  = c_{2+} |\\uparrow_2\\rangle + c_{2-}|\\downarrow_2\\rangle\n\\end{align}\nThis is standard quantum mechanics. The interesting part happens when we look at the wavefunction of both of these particles together, we can get the form of the state with  the tensor product of these two states.\n\\begin{align}\n    |\\psi\\rangle = |\\psi_1\\rangle \\otimes |\\psi_2\\rangle\n\\end{align}\nTo save space, with spin 1/2, we often write $|\\uparrow_1\\rangle \\otimes |\\uparrow_2\\rangle  = |\\uparrow\\uparrow \\rangle$. So evaluating the full wave function by just distributing everything, we get\n\\begin{align}\n    |\\psi\\rangle = c_{++}|\\uparrow\\uparrow\\rangle + c_{+-}|\\uparrow\\downarrow\\rangle + c_{-+}|\\downarrow\\uparrow\\rangle + c_{--}|\\downarrow\\downarrow\\rangle\n\\end{align}\nThis is the generic state, where the coefficients are not necessarily the same as the product of the two on the top states. If we \\emph{did} have that \n\\begin{align}\n    |\\psi_s\\rangle &= \\Big(c_{1+} |\\uparrow_1\\rangle + c_{1-}|\\downarrow_1\\rangle\\Big) \\otimes \\Big(c_{2+} |\\uparrow_2\\rangle + c_{2-}|\\downarrow_2\\rangle\\Big)\\\\ \\label{separablewave} \n    &= c_{1+}c_{2+}  |\\uparrow\\uparrow\\rangle + c_{1+} c_{2-}|\\uparrow\\downarrow\\rangle + c_{1-}c_{2+}|\\downarrow\\uparrow\\rangle +  c_{1-}c_{2-}|\\downarrow\\downarrow\\rangle\n\\end{align}\nThen the system would behave as we would expect. To illustrate this, an observation on one of the particles is represented by \n\\begin{align}\n    I\\otimes S_z\n\\end{align}\n$I$ is the identity operator, and $S_z$ is the operator that looks at the spin in the $z$ direction. What this expression is equivalent to is acting only on the second state, and doing nothing to the first one. Let's pretend someone looks at the second particle with the $S_z$ operator, and finds it is in the $|\\uparrow\\rangle$ state. This means that the wave function has \\emph{collapsed} into an eigenstate of only  $|\\uparrow\\rangle$ for the second particle, which means we have to get rid of all of the other states and renormalize. Doing it our on equation \\ref{separablewave}, we see that the wave function is now in the state\n\\begin{align}\n    |\\psi_s\\rangle &= c_{1+}|\\uparrow\\uparrow\\rangle + c_{1-}|\\downarrow\\uparrow\\rangle \\\\\n    &= \\Big(c_{1+}|\\uparrow\\rangle + c_{1-}|\\downarrow\\rangle\\Big)\\otimes |\\uparrow\\rangle\n\\end{align}\nSo literally nothing has changed about what we know about the first particle, which is what you would expect. These states are called \\emph{separable}, since we can always act in one space without effecting the other. The generic states on the other hand are \\emph{not} always separable. One of the classic examples of these types of states is the Bell state\n\\begin{align}\n    |\\psi_B\\rangle = \\frac{1}{\\sqrt{2}} \\Big(|\\uparrow\\uparrow \\rangle + |\\downarrow\\downarrow\\rangle\\Big)\n\\end{align}\nThis term can not be written simply as the tensor product of the two spaces, since we are missing cross terms. Let's pretend that we were somehow able to make this state (in reality, most entanglement is done with the polarization of photons). \n\nRemember that we physically have two particles that together create this wavefunction, which allows us to physically separate them in space, leaving the wavefunction itself intact as long as an \"observation\" is not made on it along the way which would collapse the wave function.\\footnote{This is the exact reason why quantum communication is so attractive, because if a third party tampers with the wavefunction, it ruins the coherence of the things we are about to talk about.} Let's have that one person, Alice, measures particle 1, and Bob measures particle 2. Pretend that Alice measures the spin along the $z$ direction and finds it is up, meaning that the wave function collapsed to\n\\begin{align}\n    |\\psi_B\\rangle \\rightarrow |\\uparrow\\uparrow\\rangle\n\\end{align}\nWhere the $1/\\sqrt{2}$ is taken out to keep the wavefunction normalized to 1. What this means is the state of particle 2 is now in an eigenstate of spin up, which means that at any point, whenever Bob measures the system in the same $z$ basis, he will necessarily find his particle in spin up. \n\nThis seems to imply faster than light communication, since the other particle, at an arbitrarily far distance away necessarily changes the moment Alice completes her measurement. To quote Einstein, we have \"spooky action at a distance\". This provoked him, Poldolsky and Rosen to write a paper about it, now know as the \\textbf{EPR Paradox}. A nice way to gain statistical information about a state is with the density matrix\n\\begin{align}\\label{density}\n    \\rho \\equiv \\sum_i p_i|\\psi_i\\rangle\\langle \\psi_i|\n\\end{align}\nWhere $p_i$ is the probability of a given state. The density operator tells us the maximum statistical information that Alice can know about Bob's system, without any interaction with Bob. As soon as Bob interacts with Alice the density matrix is changed.\n\n\nThe density operator has some interesting properties, lets first look at it's trace\n\\begin{align}\n    \\textrm{tr}(\\rho) = \\sum_i p_i \\textrm{tr}(|\\psi_i \\rangle\\langle \\psi_i |) = \\sum_i p_i = 1\n\\end{align}\n\n\nThe density matrix is also related to Liouville Theorem and entropy somehow.\n\nQuantum Computing is also interesting.\\footnote{Nice lecture from MIT - \\url{https://www.youtube.com/watch?v=awpnsGl08bc}}\n\n\n\n\\subsection{Addition of Angular Momentum}\nIn general when adding two different angular momentums the math goes as a tensor product with\n\n$$|j_1\\rangle \\otimes |j_2\\rangle = |j_1+ j_2\\rangle \\oplus |j_1 + j_2 - 1\\rangle \\oplus ... ||j_1- j_2|\\rangle$$\n\nSInce $j_1$ and $j_2$ have dimensionality $2j_1+1$, $2j_2+1$ respectively (from $m_1, m_2$). So the product should have dimensionality $(2j_1+1)(2j_2+1)$. The algorithm for mathematically adding two angular momentums, first find the maximum state where all $m_i$ were maximum. From there you know what state correlates between the $|j_1,j_2,m_1,m_2\\rangle$ and $|j_1,j_2,j,m\\rangle$ bases. With that just act the ladder operator on both sides\n\n$$J_- = J_{1-} \\otimes 1 +1\\otimes J_{2-}$$\n\nThis gives you all the different $m$ values and their coefficients from equation \\ref{ladder}. To get the other $j$ values, you want to use orthogonality between the states, requiring that the level below the top one is orthogonal to one which now has $j-1$ instead of $j$, and is a linear combination of the $m_1,m_2$ states that could sum to it.\n\n\\begin{align}\n\\langle j_1,j_2, j, m|j_1,j_2,j-1,m\\rangle = 0\n\\end{align}\n\nHere you just solve for the coefficients of the ket, having them already for the bra, and also requiring normalization. Then you repeat the whole thing again until you get to $j=0$...\n\n\n\n\n\\section{Symmetries}\n\n\n\\subsection{Parity Operator}\nThe parity operator $\\pi$ flips the coordinate of a ket, so\n\\begin{align}\n\\pi|\\textbf{x}\\rangle  = |-\\textbf{x}\\rangle\n\\end{align}\nUp to a phase. Can remember that momentum also swaps sign, since it is \\emph{distance} over time\n\\begin{align}\n\\pi|\\textbf{p}\\rangle = |-\\textbf{p}\\rangle\n\\end{align}\nUp to a phase. It turns out that the angular momentum operator actually commutes with the parity operator from the definition of angular momentum as \n\\begin{align}\n\\textbf{L} = \\textbf{x}\\times\\textbf{p}\n\\end{align}\nBoth $\\textbf{x}$ and $\\textbf{p}$ would swap in sign, which would then cancel leaving us with\n\\begin{align}\n[\\textbf{L},\\pi] = 0\n\\end{align}\nAlso if the Hamiltonian commutes with the parity operator, it turns out that we get parity eigenkets.\n\n\n\n\\subsection{Time Reversal Operator}\nThe time reversal operator $\\Theta$ changes $t\\rightarrow -t$. This obviously should change the direction of the momentum with\n\\begin{align}\n\\Theta |\\textbf{p}\\rangle = |-\\textbf{p}\\rangle\n\\end{align}\nUp to a phase. But does not change the sign of the coordinate\n\\begin{align}\n\\Theta |\\textbf{x}\\rangle = |\\textbf{x}\\rangle\n\\end{align}\nUp to a phase. Similar to the previous section, this product now \\emph{will} change the sign of the angular momentum, making it \\emph{anticommute}\n\\begin{align}\n\\{\\Theta, \\textbf{J}\\} = 0\n\\end{align}\n\n\n\n\n\n\n\n\n\\textbf{Kramer's Degeneracy} happens for particles of half integer spin, which causes two unique states with the same energy, from time reversal invariance. Make's interesting things happen when you have odd-numbered or even numbered systems. This degeneracy is split from magnetic fields from $\\textbf{v}\\cdot\\textbf{A}$ in the hamiltonian, which is not time reversal invariant. \n\nAnother useful relation is\n\n\\begin{align}\n\\{\\Theta,S_i\\} = 0\n\\end{align}\n\n\n\\section{Solution's to the Schrodinger Equation}\n\n\\subsection{Free Particle}\n\\begin{align}\n    \\psi(\\textbf{r},t) = \\frac{1}{(2\\pi)^{3/2}}e^{i(\\textbf{k}\\cdot\\textbf{r} - \\omega t)}\n\\end{align}\n\n\n\\subsection{Hydrogen Atom}\nBohr developed a lot of things involving the Hydrogen atom semiclassically and serendipitously arrived at some results that happened to be more or less correct using the full machinery  of Quantum Mechanics. We first say that the Energy is given by\n\\begin{align}\nE = \\frac{1}{2}m_ev^2 - \\frac{Ze^2}{4\\pi\\epsilon_0 r}\n\\end{align}\nWhere $Z$ is there to account for if we have extra charges in the nucleus. We then say that the centripetal force is cancelled by the pull of the nucleus\n\\begin{align}\n\\frac{mv^2}{r} = \\frac{Ze^2}{4\\pi\\epsilon_0 r^2}\n\\end{align}\nWe can solve for $mv^2$ and put it back into the expression for energy and get\n\\begin{align}\nE = -\\frac{Ze^2}{2(4\\pi\\epsilon_0) r}\n\\end{align}\nThe big deal thing that Bohr did was call the angular momentum a quantized value, with\n\\begin{align}\nL = mvr = \\hbar n\n\\end{align}\nHe did this because classically, an electron spinning around a nucleus is technically accelerating. An accelerating charge gives off radiation, and thus loses energy, which would mean eventually the electron would spiral into the nucleus. Now obviously this doesn't happen, so this was the prescription that Bohr came up with. Solving for the radius and plugging in the force equation we find it is \\emph{quantized} as well with\n\\begin{align}\nr_n = \\frac{4\\pi\\epsilon_0 \\hbar^2n^2}{Ze^2m} = \\frac{n^2a_0}{Z}\n\\end{align}\nWhere $a_0$ is called the Bohr radius. Plugging this quantized radius into our expression for energy we get\n\\begin{align}\nE_n = -\\frac{Ze^2}{2(4\\pi\\epsilon_0)}\\frac{Ze^2m}{4\\pi\\epsilon_0\\hbar^2n^2} = -\\frac{Z^2e^4m}{2(4\\pi\\epsilon_0)^2\\hbar^2n^2}\n\\end{align}\nThe maximum angular momentum value for a given $n$ is\n\\begin{align}\n    0 \\le l &\\le n-1\\\\\n\\end{align}\nWhen transitioning states, we need\n\\begin{align}\n    l &= \\pm 1\\\\\n    m &= 0, \\pm 1\n\\end{align}\nWhich can be thought of as a photon leaving the hydrogen atom, which has spin $1$. The ground state quantum mechanically is given by\n\\begin{align}\n\\psi_{100}(r) = Ce^{-r/a_0}\n\\end{align}\nOther useful relations are\n\\begin{align}\nL^2\\psi = \\hbar^2l(l+1)\\psi\\\\\nL_z\\psi = \\hbar m\\psi\n\\end{align}\n\n\nThe angular portion of the Hydrogen atom is simply given by the spherical harmonic with the same $l,m$\n\n\\subsection{Coherent State}\nThe Coherent state obeys the condition\n\\begin{align}\na|\\lambda\\rangle = \\lambda |\\lambda\\rangle\n\\end{align}\nEven though the state $|\\lambda\\rangle$ is an eigenket of $a$, $a$ itself is not a Hermitian operator. The intuition behind this state is it is meant to resemble the classical harmonic oscillator, which has such a high $n$ value that it can never be annihilated (since repeated operations of $a$ leave it unchanged). It is also a Gaussian wave packet satisfying the minimum uncertainty with\n\\begin{align}\n\\sigma_x\\sigma_p = \\frac{\\hbar}{2}\n\\end{align}\nwhich remains true for all time. \n\n\n\\subsection{Infinite Square Well}\nGiven a potential\n\\begin{align}\nV(x) &= 0 && 0 \\le x\\le L\\\\\nV(x) &= \\infty && x< 0, x>L\n\\end{align}\nThe general solution to the Schrodinger equation is a superposition of sines and cosines with\n\\begin{align}\n\\psi(x) = A\\sin(kx) + B\\cos(kx)\n\\end{align}\nWe can then plug in boundary conditions to get rid of one of these if we choose a nice coordinate system, and find \n\\begin{align}\nk = \\frac{n\\pi}{L}\n\\end{align}\nWhich gives us the energy as\n\\begin{align}\nE = \\frac{\\hbar^2k^2}{2m} = \\frac{\\hbar^2\\pi^2n^2}{2mL^2}\n\\end{align}\n\n\\subsection{Harmonic Oscillator}\nThese guys are critical to success with harmonic oscillator questions\n\\begin{align}\na &= \\sqrt{\\frac{m\\omega}{2\\hbar}}\\Big(x + \\frac{i}{m\\omega}p\\Big)\\\\\na^\\dagger &= \\sqrt{\\frac{m\\omega}{2\\hbar}}\\Big(x - \\frac{i}{m\\omega}p\\Big) \\\\\nx &= \\sqrt{\\frac{\\hbar}{2m\\omega}}(a^\\dagger+a)\\\\\np &= i\\sqrt{\\frac{m\\hbar\\omega}{2}}(a^\\dagger - a)\n\\end{align}\nAs are these relations\n\n\\begin{align}\n[a,a^\\dagger] &= 1 \\\\\na|n\\rangle &= \\sqrt{n}|n-1\\rangle\\\\\na^\\dagger|n\\rangle &= \\sqrt{n+1}|n+1\\rangle\n\\end{align}\n\n\nCan simply find the wave function for a ladder system because it is required that\n\n\\begin{align}\na|0\\rangle= 0\n\\end{align}\nPlugging in $a$ in the $x$ basis, we get\n\\begin{align}\n\\langle x|a|0\\rangle = 0 = \\int dx \\langle x|a|x'\\rangle\\langle x'|0\\rangle = \\Big(x + \\frac{\\hbar}{m\\omega}\\frac{\\partial}{\\partial x}\\Big)\\psi_0(x)\n\\end{align}\nRearranging everything, we get\n\\begin{align}\\label{harmosc}\n-\\frac{m\\omega}{\\hbar}xdx = \\frac{d\\psi}{\\psi}\n\\end{align}\nIntegrating gives us the wave function as\n\\begin{align}\n\\psi_0(x) = Ce^{-\\frac{m\\omega}{2\\hbar}x^2}\n\\end{align}\nFrom here, we can just act the $a^\\dagger$ operator on the state to find all the next ones, with\n\\begin{align}\n\\psi_n(x) = A_n(a^\\dagger)^n\\psi_0(x)\n\\end{align}\n\n\n\n\n\n\\section{Particle in a Magnetic Field}\nConsidering just a particle in a magnetic field, the Hamiltonian of the system is given by\\cite{lecture5}\n\\begin{align}\nH = \\frac{1}{2m}\\boldsymbol{\\Pi}^2 = \\frac{1}{2m}\\Big(\\textbf{p}-q\\textbf{A}\\Big)^2\n\\end{align}\n\nWhere $\\textbf{p}$ is of course the canonical momentum which is the sum of the kinetic momentum $\\boldsymbol{\\Pi}$, which comes just from the physical movement of the mass, and the momentum from the field $q\\textbf{A}$. We can expand the Hamiltonian to take the form\n\\begin{align}\nH = \\frac{1}{2m}\\Big[ \\textbf{p}^2 -q\\Big(\\textbf{p}\\cdot \\textbf{A} +\\textbf{A}\\cdot\\textbf{p}\\Big) + q^2\\textbf{A}^2\\Big]\n\\end{align}\nSince $\\textbf{p} = -i\\hbar\\nabla$ and $\\nabla\\cdot\\textbf{A} = 0$, we have that $\\textbf{p}\\cdot\\textbf{A}=\\textbf{A}\\cdot\\textbf{p}$ from the product rule. For a stationary magnetic field we can write the magnetic potential as\n\\begin{align}\n\\textbf{A} =-\\frac{1}{2} \\textbf{x}\\times\\textbf{B}\n\\end{align}\nThis is the Symmetric gauge which will be covered later. This gauge lets us find an expression for the term in braces in Einstein notation with\n\\begin{align}\n2\\textbf{A}\\cdot\\textbf{p} = i\\hbar\\Big(\\textbf{x}\\times\\textbf{B}\\Big)\\cdot\\nabla &= i\\hbar \\varepsilon_{ijk} x_iB_j\\partial_k\\\\\n&= i\\hbar \\varepsilon_{ijk} x_i\\partial_k B_j\\\\\n&= -i\\hbar\\varepsilon_{ikj}x_i\\partial_kB_j\\\\\n&= -i\\hbar\\Big(\\textbf{x}\\times\\nabla\\Big)\\cdot\\textbf{B}\\\\\n&= \\textbf{L}\\cdot\\textbf{B}\n\\end{align}\nSince the field does not change in space making its derivative zero and $\\textbf{L} = \\textbf{x}\\times-i\\hbar\\nabla$. We can also simplify the last term in the Hamilonian with\n\\begin{align}\n\\textbf{A}^2 &= \\frac{1}{4}\\Big((\\textbf{x}\\times\\textbf{B})\\cdot(\\textbf{x}\\times\\textbf{B})\\Big) = \\frac{1}{4}\\Big(\\textbf{x}^2\\textbf{B}^2 - (\\textbf{x}\\cdot\\textbf{B})^2\\Big)\\\\\n\\end{align}\nIf we take the magnetic field to be $\\textbf{B} = (0,0,B)$, we have our Hamiltonian as\n\\begin{align}\nH = \\frac{\\textbf{p}^2}{2m} -\\frac{q}{2m}\\textbf{L}\\cdot\\textbf{B} +\\frac{q^2B^2}{8m}(x^2+y^2)\n\\end{align}\nThe first term with a magnetic field component is called the \\textbf{paramagnetic component}, and the last term is called the \\textbf{diamagnetic component}. We then define the gyromagnetic ratio as\n\n\\begin{align}\n\\boldsymbol{\\mu}_l = \\frac{q}{2m}\\textbf{L}\n\\end{align}\nThere is an addition analogous quantum gyromagnetic ratio given by twice this value with\n\\begin{align}\n\\boldsymbol{\\mu}_s = \\frac{q}{m}\\textbf{S}\n\\end{align}\n\n\n\n\\subsection{Landau Levels}\nA good resource is this\\cite{hitoshi}. It turns out that when a charged particle is placed in a magnetic field, it's energy becomes quantized in a way identical to the harmonic oscillator. Taking the magnetic field to be a constant in the $z$ direction\n\\begin{align}\n\\textbf{B} = (0,0,B)\n\\end{align}\n\n\n We are then free to choose a gauge that works best for the problem we have. Two typical choices are\n\n\\begin{itemize}\n\\item \\textbf{Symmetric Gauge}\n\\begin{align}\n\\textbf{A} = \\frac{B}{2}(-y,x,0)\n\\end{align}\n\nThis makes our Hamiltonian rotationally invariant\n\n\n\\item \\textbf{Landau Gauge}\n\\begin{align}\n\\textbf{A} = B(-y,0,0)\n\\end{align}\nThis makes the Hamiltonian translationally invariant\n\\end{itemize}\n\nThe Hamiltonian that is usually looked at is just the kinetic energy term, since we have no potential, which tells us that\n\\begin{align}\nH = \\frac{1}{2m}\\boldsymbol{\\Pi}^2 = \\frac{1}{2m}\\Big(\\textbf{p}-q\\textbf{A}\\Big)^2\n\\end{align}\nWith\n\\begin{align}\n\\textbf{p} = \\boldsymbol{\\Pi} + q\\textbf{A}\n\\end{align}\nWhere $\\textbf{p}$ is of course the canonical momentum, and is the sum of the kinetic momentum $\\boldsymbol{\\Pi}$, which comes just from the physical movement of the mass, and the momentum from the field $q\\textbf{A}$. Breaking up the Hamiltonian with the magnetic field only in the $z$ direction using the Landau Gauge, we have\n\\begin{align}\nH = \\frac{1}{2m}\\Big[ (p_x+qBy)^2 + p_y^2 + p_z^2\\Big]\n\\end{align}\nWe see that \n\\begin{align}\n[p_x, H] = 0\\\\\n[p_z, H] = 0\n\\end{align}\nSo we can have simultaneous eigenstates of the Hamiltonian and $p_x,p_z$ so we can rewrite these as their eigenvalues $\\hbar k_x, \\hbar k_z$. However, $p_y$ does not commute with the Hamiltonian, but we now it in the form of a Harmonic oscillator in $y$, since it has a momentum squared term and a position squared term with\n\\begin{align}\nH &= \\frac{\\hbar^2k_z^2}{2m} + \\frac{1}{2m}\\Big[\\Big(\\hbar k_x + qBy\\Big)^2 + p_y^2\\Big]\\\\\n&=\\frac{\\hbar^2k_z^2}{2m} + \\frac{1}{2m}\\Big[\\Pi_x^2 + \\Pi_y^2\\Big]\n\\end{align}\nFrom here, we make a few observations and some new notations, to get it into the regular looking form of a harmonic oscillator. First we define what are essentially the raising and lowering operators for kinetic momentum\n\\begin{align}\n    \\Pi_\\pm = \\Pi_x \\mp i\\Pi_y\n\\end{align}\nThe sign convention here is opposite the typical ladder operator, but its what they use for some reason. In a way similar to what we do with the harmonic oscillator, lets look at the term\n\\begin{align}\n    \\Pi_+\\Pi_- &= (\\Pi_x - i\\Pi_y)(\\Pi_x + i\\Pi_y)\\\\ \n    &= \\Pi_x^2 - i\\Pi_y\\Pi_x +i\\Pi_x\\Pi_y +\\Pi_y^2\\\\ \n    &= \\Pi_x^2 + \\Pi_y^2 + i[\\Pi_x,\\Pi_y]\n\\end{align}\nWe see we have a term that exactly matches the one in our Hamiltonian. Now we can evaluate the commutator term, finding in fact there is a constant commutation relation no matter what gauge we choose with\n\\begin{align}\n    [\\Pi_x,\\Pi_y] = i\\hbar qB\n\\end{align}\nPlugging in we see that\n\\begin{align}\n    \\Pi_x^2 + \\Pi_y^2 = \\Pi_+\\Pi_- + \\hbar qB\n\\end{align}\nSo our Hamiltonian looks like\n\\begin{align}\n    H = \\frac{\\hbar^2k_z^2}{2m} + \\frac{1}{2m}\\Big(\\Pi_+\\Pi_- + \\hbar qB\\Big)\n\\end{align}\nThis is the same form of a normal harmonic oscillator in $x$ and $y$, just from the placement of the operators, but now in order to get it all the way there we have to match coefficients\n\\begin{align}\n    \\frac{1}{2m}\\Big(\\Pi_+\\Pi_- + \\hbar qB\\Big) = \\hbar\\omega\\Big(a^\\dagger a + \\frac{1}{2}\\Big)\n\\end{align}\nLooking at the constant first\n\\begin{align}\n    \\frac{\\hbar qB}{2m} = \\frac{\\hbar\\omega}{2} \\rightarrow \\omega = \\frac{qB}{m}\n\\end{align}\nThis is the cyclotron frequency. We can then reverse engineer the true ladder operators knowing the constants should be the same in front of both\n\\begin{align}\n    \\frac{1}{\\sqrt{2m}}\\Pi_+ = \\sqrt{\\frac{\\hbar qB}{m}}a^\\dagger \n\\end{align}\nThis gives us\n\\begin{align}\n    a^\\dagger &= \\frac{1}{\\sqrt{2\\hbar q B}} (\\Pi_x - i\\Pi_y)\\\\\n    a &= \\frac{1}{\\sqrt{2\\hbar q B}} (\\Pi_x + i\\Pi_y)\n\\end{align}\nSo our final Hamiltonian, after being painfully manipulated is\n\\begin{align}\nH = \\frac{\\hbar^2k_z^2}{2m} + \\hbar\\omega\\Big(a^\\dagger a + \\frac{1}{2}\\Big)\n\\end{align}\nWe can find the eigenstates in the same way we find those for the harmonic oscillator (Equation \\ref{harmosc}), and using separation of variables for $z$. The corresponding state is also an eigenstate of the $L_z$ operator with\n\\begin{align}\nL_z\\psi_n = \\hbar n\\psi_n\n\\end{align}\n\nBut this quantity is in fact gauge dependent because we used canonical momentum and not kinetic momentum, which depends on gauge.\n\n%\\subsection{Aharonov-Bohm Effect}\n%TODO\n\n\\subsection{Fractional Quantum Hall Effect}\nIn the ground state Landau Level, you can show there is stability given the number of states (degeneracy) for the ground state is given by\n\n\\begin{align}\nN = \\frac{1}{k}\\frac{e\\Phi}{hc}\n\\end{align}\n\nwhere $k$ is some odd number\n\n\n\n\n\\section{WKB Approximation}\nThe WKB approximation is useful for when you have a potential that varies with position $V(x)$ or barriers that become larger than the available energy of the system. \n\\begin{enumerate}\n\\item Rewrite the Schrodinger equation\n\\begin{align}\n\\frac{\\partial^2}{\\partial x^2}\\psi &= -\\frac{p(x)^2}{\\hbar^2}\\psi\n\\end{align}\nwhere\n\\begin{align}\np(x) = \\sqrt{2m[E-V(x)]}\n\\end{align}\n\\item Guess the form\n\\begin{align}\n\\psi(x) = A(x)e^{-i\\phi(x)}\n\\end{align}\n\\item Plug it in and get some differential equations you can solve (in Griffith's) and find that\n\\begin{align}\nA = \\frac{C}{\\sqrt{p(x)}} && \\phi(x) = \\frac{1}{\\hbar}\\int_0^x p(x') dx'\n\\end{align}\n\n\n\\item Plug in and see that the general solution is given by\n\\begin{align}\n\\psi(x) &= \\frac{1}{\\sqrt{p(x)}}\\Big(C_+e^{i\\phi(x)} + C_-e^{-i\\phi(x)}\\Big)\\\\\n&= \\frac{1}{\\sqrt{p(x)}}\\Big(C_1\\sin\\phi(x) + C_2\\cos\\phi(x)\\Big)\n\\end{align}\n\n\\item From here we use boundary conditions, by requiring things like $\\psi(0) = 0$ and $\\psi(a) = 0$ if we have that $V(0) = V(a) = \\infty$ etc. This gives us conditions on the integral equation for $\\phi(x)$ like\n\\begin{align}\n\\phi(a) = \\frac{1}{\\hbar}\\int_0^a p(x) dx = n\\pi\n\\end{align}\nThere are some nasty integrals involved that I don't full understand, but reading Griffith's pg 289 could help.\n\n\\end{enumerate}\n\n\\section{Variational Method}\n\\begin{enumerate}\n\\item Guess a trial wave function $|\\phi(\\alpha)\\rangle$ of some flexible parameter $\\alpha$\n\\item Normalize that wave function\n\\item Calculate the expectation value of the energy using that wave function $\\langle \\phi(\\alpha) |H|\\phi(\\alpha)\\rangle = E(\\alpha)$\n\\item Take the derivative of the energy with respect to $\\alpha$ and set it equal to zero to solve for $\\alpha$ in terms of other constants.\n\\item Plug it back in to $E(\\alpha)$ to come up with an upper bound on the ground state energy.\n\\end{enumerate}\n\n\n\n\n\\section{Perturbation Theory}\n\nAll time-independent perturbation questions should be solved as\n\\begin{enumerate}\n\\item Are the zeroth order energies degenerate? If they aren't skip to 3\n\\item Break the degeneracy and come up with new zeroth order states\n\\item Use the time-independent perturbation using the zeroth order states to find perturbed states and energy shifts\n\\end{enumerate}\n\n\n\\subsection{Time Independent - Non Degenerate}\nAlways first check if the zeroth order energies are degenerate first before following this approach! The idea here is you can write your Hamiltonian as\n\\begin{align}\nH = H_0 + \\lambda V\n\\end{align}\nWhere $\\lambda$ is some small value, and you know all the eigenstates of $H_0$ already. With some clever math involving the projection operator and expansion in powers of $\\lambda$ one gets the first order energy shift\\cite{sakurai} as\n\n\\begin{align}\n\\Delta_n^{(1)} &= \\langle n^{(0)}|V|n^{(0)}\\rangle\n\\end{align}\nThe corresponding first order ket is\n\\begin{align}\\label{firstordertimeindependent}\n |n^{(1)}\\rangle &= \\sum_{k\\neq n}\\frac{\\langle k^{(0)} |V|n^{(0)}\\rangle}{E_n^{(0)}-E_k^{(0)}}|k^{(0)}\\rangle\n\\end{align}\nCan remember the conjugation here since its almost the projection operator $|k^{(0)}\\rangle\\langle k^{(0)}|$. The second order energy shift is given by\n\\begin{align}\n\\Delta_n^{(2)} &= \\sum_{k\\neq n} \\frac{|\\langle k^{(0)}| V| n^{(0)}\\rangle|^2}{E_n^{(0)} - E_k^{(0)}}\n\\end{align}\nAll the remaining kets and shifts become much more complicated and its best to assume you won't need to know them. One can remember the order of the minus sign in a backwards way by remembering that second order shifts to the ground state of \\emph{an}y system will always decrease its energy. \n\n\n\\subsection{Time Independent - Degenerate}\nIf it happens that there are two (or more) kets in our Hilbert space have the same energy, lets say $E_a^{(0)} = E_b^{(0)}$ then Equation \\ref{firstordertimeindependent} will go to infinity since one of the terms will divide by zero. We avoid this by also making the \\emph{numerator} also go to zero. The key here is to take clever linear combinations of the degenerate subspace (here $|a^{(0)}\\rangle, |b^{(0)}\\rangle$) that do just that. \n\\begin{align}\n|\\alpha^{(0)}\\rangle = c_1 |a^{(0)}\\rangle + c_2|b^{(0)}\\rangle\\\\\n|\\beta^{(0)}\\rangle = c_3|a^{(0)}\\rangle + c_4|b^{(0)}\\rangle\n\\end{align}\n\nWhere we want $\\langle \\alpha |V |\\beta \\rangle = \\langle \\beta |V|\\alpha\\rangle  = 0$. The way we do this is write the perturbation matrix out with the states we start with, then diagonalize it (Section \\ref{diagolize}) thus making the off-diagonal terms writen earlier zero. The eigenvalues tell us the first order shift $\\Delta_n^{(1)}$, and the eigenvectors tell us the correct linear combinations for the degenerate subspace. From here we can just use non-degenerate perturbation theory to calculate stuff like $|n^{(1)}\\rangle$ and $\\Delta_n^{(2)}$ using $|\\alpha^{(0)}\\rangle$ and $|\\beta^{(0)}\\rangle$. \nGriffith's pg 229 outlines a nice way to find the states beforehand, look for an operator $A$ that obeys \n\\begin{align}\n[A,V] = 0\n\\end{align}\nWe can use eigenstates of that operator and were good as long as both the degenerate kets have different eigenvalues of $A$. A common example would be some angular momentum operator like $S_z$\n\n\\subsection{Time Dependent}\nNow we take an almost entirely different approach and forget about the $\\lambda$ expansion, first order energy shift, etc,  and have that our Hamiltonian looks like\n\\begin{align}\nH = H_0 + V(t)\n\\end{align}\nWe always assume time separability of our kets so any state can be represented as\n\\begin{align}\n|\\alpha; t\\rangle = \\sum_n c_n(t)\\exp\\Big[-\\frac{iE_n t}{\\hbar}\\Big]|n\\rangle\n\\end{align}\nWhere we now have \\emph{time-dependent} coefficients. Now just looking at the Schrodinger equation, (Where of course $\\langle n |\\alpha;t\\rangle = c_n(t)\\exp\\Big[-\\frac{iE_n t}{\\hbar}\\Big]$),we get\n\\begin{align}\ni\\hbar \\frac{\\partial}{\\partial t} \\Big[c_n(t)e^{-\\frac{iE_n t}{\\hbar}}\\Big] &= \\langle n| H|\\alpha; t\\rangle\\\\\ni\\hbar\\Big[\\dot{c}_n(t) - \\frac{i}{\\hbar}E_nc_n(t)\\Big]e^{-\\frac{iE_n t}{\\hbar}} &= \\sum_m \\langle n| H|m\\rangle c_m(t)e^{-\\frac{iE_m t}{\\hbar}}\\\\\n\\end{align}\nSimplifying, and using the variable $\\omega_{mn} = \\frac{E_m-E_n}{\\hbar}$ we get $n$ coupled differential equations of the form \n\\begin{align}\ni\\hbar\\dot{c}_n(t) = \\sum_m \\langle n |V(t)|m\\rangle c_m(t) e^{-i\\omega_{mn}t}\n\\end{align}\nThese are rarely exactly solvable unless there are only a few kets, so the primary approach is still through perturbation. Integrating this equation gives us an expression for one of the coefficients in terms of the coefficient itself\n\\begin{align}\nc_n(t) = c_n(0)-\\frac{i}{\\hbar}\\sum_m \\int_0^t dt' \\langle n |V(t')|m\\rangle c_m(t') e^{-i\\omega_{mn}t'}\n\\end{align}\nFreeman Dyson came up with a clever way to recursively solve for $c_n(t)$ by plugging the expression into itself. More clearly, on the right side of the equation, we have the variable $c_m(t')$, but looking at the left side, we actually have an explicit expression for it, the equation itself. So plugging in for $c_m(t')$ over and over we can get closer and closer to the exact expression for $c_n(t)$ with more and more integrals. So effectively we have\n\\begin{align}\nc_n(t) = c_n^{(0)}(t) + c_n^{(1)}(t) + c_n^{(2)}(t) + ...\n\\end{align}\nTo find each coefficient, we follow the formula\n\\begin{align}\nc_n^{(i+1)} = -\\frac{i}{\\hbar}\\sum_m \\int_0^t dt' \\langle n |V(t')|m\\rangle c_m^{(i)}(t') e^{-i\\omega_{mn}t'}\n\\end{align}\nThe first two written out explicitly are\n\\begin{align}\nc_n^{(0)}(t) &= c_n(0)\\\\\nc_n^{(1)}(t) &= -\\frac{i}{\\hbar}\\sum_m \\int_0^t dt' \\langle n |V(t')|m\\rangle c_m(0) e^{-i\\omega_{mn}t'}\n\\end{align}\n\n\n\\subsection{Fermi's Golden Rule}\nWe consider all of the states $n$ that are within some small range of an energy we care about $E_i$. By considering only the first term in time dependent perturbation theory, we can do some math to find that transition rate $w$, which is the rate of change of the probability you will be in a state is given by\n\\begin{align}\n    w_{i->[n]} = \\frac{2\\pi}{\\hbar} |V_{in}|^2\\rho_n\n\\end{align}\n\n\n\\subsection{Adiabatic Theorem}\nThe Adiabatic theorem tells us that if you start with some Hamiltonian $H$, and you have a particle in the $n$th eigenstate of it, and you \\emph{slowly} change the Hamiltonian to $H'$, it will again be in the $n$th eigenstate of $H'$, as long as there is no degeneracy and the change to the Hamiltonian is small.\n\n\n\\section{Scattering}\n\nThe solution to the Schrodinger equation for a particle in free space is simply a plane wave, with \\cite{blugel}\n\\begin{align}\n\\psi_\\textbf{k}(\\textbf{r}) = \\frac{1}{(2\\pi)^{3/2}}e^{i\\textbf{k}\\cdot\\textbf{r}}&& E_\\textbf{k} = \\frac{\\hbar^2k^2}{2m}\n\\end{align}\n\nIn general, we know that if we have an eigenstate of energy, we must have\n\\begin{align}\n    E|\\psi\\rangle = H|\\psi\\rangle = \\Big(\\frac{p^2}{2m} + V\\Big)|\\psi\\rangle\n\\end{align}\nNow looking at the position space wave form\n\\begin{align}\n    E\\langle \\textbf{x} |\\psi\\rangle &=  \\langle \\textbf{x}|\\Big(\\frac{p^2}{2m} + V\\Big)|\\psi\\rangle\\\\\n    E\\psi(\\textbf{x}) &= \\frac{-\\hbar^2}{2m}\\nabla^2\\psi(\\textbf{x}) + \\langle\\textbf{x}|V|\\psi\\rangle\n\\end{align}\nThe most general form of the scattering equation including a \\emph{non-local} potential is\n\\begin{align}\n    E\\psi(\\textbf{x}) &= \\frac{-\\hbar^2}{2m}\\nabla^2\\psi(\\textbf{x}) + \\int dx'^3\\langle\\textbf{x}|V|\\textbf{x}'\\rangle\\langle\\textbf{x}'|\\psi\\rangle\n\\end{align}\nWhere the potential has off diagonal matrix elements, so we have to sum over everything. If the potential is local then we have that\n\\begin{align}\n\\Big(\\frac{\\hbar^2}{2m}\\nabla^2 + E\\Big)\\psi'(\\textbf{r}) = V(\\textbf{r})\\psi'(\\textbf{r})\n\\end{align}\nFrom here, we can notice that the left operator acting on $\\psi'(\\textbf{r})$ is a linear differential operator, so it's Kosher to look for solutions to it using Green's Functions (Section \\ref{green}). The equation we want to solve is\n\\begin{align}\n\\Big(\\frac{\\hbar^2}{2m}\\nabla^2 + E\\Big) G(\\textbf{r}, \\textbf{r}') = \\delta(\\textbf{r}-\\textbf{r}')\n\\end{align}\nWe can thus write the Schrodinger equation in integral form, with an integration constant accounting for the fact that as $V(\\textbf{r})$ goes to zero, we must recover our initial unscattered plane wave solution\n\\begin{align}\\label{lippmann}\n\\psi'(\\textbf{r}) = \\psi(\\textbf{r}) + \\int dr'^3~G(\\textbf{r}, \\textbf{r}') V(\\textbf{r}')\\psi'(\\textbf{r}')\n\\end{align}\nThis equation is called the \\textbf{Lippmann-Schwinger Equation}. To solve for the Green's function, we can use the method of eigenfunction expansion\\cite{milton}, using the fact that\n\\begin{align}\n\\int dk^3 \\psi_\\textbf{k}^*(\\textbf{r})\\psi_\\textbf{k}(\\textbf{r}') = \\delta(\\textbf{r}-\\textbf{r}')\n\\end{align}\nSince we have that\n\\begin{align}\n\\Big(\\frac{\\hbar^2}{2m}\\nabla^2 + E\\Big)\\psi_\\textbf{k}(\\textbf{r}) = \\frac{\\hbar^2}{2m}(k'^2 - k^2)\\psi_\\textbf{k}(\\textbf{r})\n\\end{align}\nWhere $E = \\frac{\\hbar^2k'^2}{2m}$. We thus have that the eigenvalue of the linear differential operator\\cite{zangwill}, needed for this expansion is given by\n\n\\begin{align}\n\\lambda_\\textbf{k} = \\frac{\\hbar^2}{2m}(k'^2-k^2)\n\\end{align}\nThus our Green's function can be written as\n\\begin{align}\nG(\\textbf{r},\\textbf{r}') &= \\frac{2m}{(2\\pi)^3\\hbar^2}\\int dk^3 ~\\frac{e^{i\\textbf{k}\\cdot(\\textbf{r}-\\textbf{r}')}}{k'^2-k^2}\n\\end{align}\nNow evaluating the easy part, written in spherical coordinates, we have\n\\begin{align}\nG(\\textbf{r},\\textbf{r}') &= \\frac{2m}{(2\\pi)^2\\hbar^2}\\int_{-1}^1 d(\\cos\\theta) \\int_0^\\infty dk k^2 ~\\frac{e^{ik|\\textbf{r}-\\textbf{r}'|\\cos\\theta}}{k'^2-k^2}\n\\end{align}\nThe rest can be evaluated using complex integration, giving us the result as\n\\begin{align}\nG(\\textbf{r},\\textbf{r}') = -\\frac{2m}{\\hbar^2}\\frac{1}{4\\pi} \\frac{e^{ik|\\textbf{r}-\\textbf{r}'|}}{|\\textbf{r}-\\textbf{r}'|}\n\\end{align}\nIt is worth noting this is also the Green's function for the Helmholtz equation. Now plugging this back into equation \\ref{lippmann}, we get\n\\begin{align}\\label{scat}\n\\boxed{\\psi'(\\textbf{r}) = \\psi(\\textbf{r})  -\\frac{m}{2\\pi\\hbar^2}\\int dr'^3~ \\frac{e^{ik|\\textbf{r}-\\textbf{r}'|}}{|\\textbf{r}-\\textbf{r}'|} V(\\textbf{r}')\\psi'(\\textbf{r}')}\n\\end{align}\nThis is the scattering equation and is completely equivalent to the Schrodinger equation in integral form for a local potential\\cite{griffiths_qm}, everything else approximates usually that observation point is far away. As a reminder $\\textbf{r}$ is the position of the wave you are considering, and $\\textbf{r}'$ will be everywhere that you have a non-zero potential, otherwise the integrand will be zero.\n\n\\subsection{Far-Field}\nIf we are observing at a point very far away from where the potential is, we have that $|\\textbf{r}| \\gg |\\textbf{r}'|$, which lets us approximate, through Taylor expansion\n\\begin{align}\n|\\textbf{r}-\\textbf{r}'| \\approx r-\\hat{\\textbf{r}}\\cdot\\textbf{r}' &&\\frac{1}{|\\textbf{r}-\\textbf{r}'|} \\approx \\frac{1}{r} + \\mathcal{O}\\Big(\\frac{1}{r^2}\\Big)\n\\end{align}\nSo after defining $\\textbf{k}' = k\\hat{\\textbf{r}}$, which is the component of the wave vector still travelling towards the observer, equation \\ref{scat} becomes\n\\begin{align}\n\\psi'(\\textbf{r}) = \\psi(\\textbf{r})  -\\frac{m}{2\\pi\\hbar^2}\\frac{e^{ikr}}{r}\\int dr'^3~ e^{-i\\textbf{k}'\\cdot\\textbf{r}' } V(\\textbf{r}')\\psi'(\\textbf{r}')\n\\end{align}\nIt is conventional to write\n\\begin{align}\nf(\\textbf{k}',\\textbf{k}) \\equiv -\\frac{m}{2\\pi\\hbar^2}\\int dr'^3~ e^{-i\\textbf{k}'\\cdot\\textbf{r}' } V(\\textbf{r}')\\psi'(\\textbf{r}')\n\\end{align}\nWhere the $\\textbf{k}$ denotes that the equation is implicitly dependent on our initial wave function $\\psi(\\textbf{r})_\\textbf{k}$. This lets the equation be read as \n\\begin{align}\n\\psi'(\\textbf{r}) = \\psi(\\textbf{r}) + \\frac{e^{ikr}}{r}f(\\hat{\\textbf{r}})\n\\end{align}\nIt also happens that the differential scattering cross-section is given by\n\\begin{align}\n\\frac{d\\sigma}{d\\Omega} = |f(\\textbf{k}',\\textbf{k})|^2\n\\end{align}\n\n\\subsection{Born Approximation}\n\nSince equation \\ref{scat} contains itself, we can use a method similar to what we did in perturbation theory to expand it in powers of the potential, with %\\todo{verify this}\n\\begin{align}\n\\psi'(\\textbf{r}) = \\psi'^{(0)}(\\textbf{r}) + \\psi'^{(1)}(\\textbf{r}) + \\psi'^{(2)}(\\textbf{r}) + ...\n\\end{align}\nThe recursive equation is given by\n\\begin{align}\n\\psi'^{(n+1)}(\\textbf{r}) = e^{i\\textbf{k}\\cdot\\textbf{r}} -\\frac{m}{2\\pi\\hbar^2}\\frac{e^{ikr}}{r}\\int dr'^3~ e^{-i\\textbf{k}'\\cdot\\textbf{r}' } V(\\textbf{r}')\\psi'^{(n)}(\\textbf{r}')\n\\end{align}\nPhysically, each term in the expansion represents the order of the scattering, i.e the first term is when the wave function has scattered once, the second order is when it has scattered twice, etc. It is often easier to just use numerical methods to do anything higher than first order, but the first order term is important, whose scattering amplitude is given by\n\\begin{align}\\label{born}\nf^{(1)}(\\textbf{k}', \\textbf{k}) = -\\frac{m}{2\\pi\\hbar^2} \\int dr'^3 e^{i(\\textbf{k}-\\textbf{k}')\\cdot\\textbf{r}'}V(\\textbf{r}')\n\\end{align}\nThere are a few cases where this equation can be reduced even further\n\n\\begin{enumerate}\n\n\\item \\textbf{Spherically Symmetric Potential}\\\\\nCentering the coordinate system at the center of the potential and choosing the direction of the vector $\\textbf{q} = \\textbf{k}-\\textbf{k}'$ to be along the $\\hat{z}$ axis, so that\n\\begin{align}\n\\textbf{q}\\cdot\\textbf{r}' = qr\\cos\\theta\n\\end{align}\nThe first order Born approximation reads as \n\\begin{align}\\label{born}\nf^{(1)}(\\textbf{k}', \\textbf{k}) &= -\\frac{m}{2\\pi\\hbar^2} \\int_0^{2\\pi}d\\phi  \\int_{-1}^1 d(\\cos\\theta) \\int_0^\\infty dr' r'^2e^{iqr\\cos\\theta}V(r')\\\\\n&= -\\frac{m}{\\hbar^2}\\frac{1}{iq}\\int_0^\\infty dr' \\frac{r'^2}{r'}V(r')\\Big(e^{iqr'} - e^{-iqr'}\\Big)\\\\\n&= -\\frac{2m}{q\\hbar^2}\\int_0^\\infty dr' r' V(r')\\sin(qr')\n\\end{align}\n\n\n\n\n\\item \\textbf{Low Energy}\\\\\nWhen we have that the wave length of $\\textbf{k}$ is very long compared to the region the potential is in, the exponential factor in equation \\ref{born} will change very slightly as we integrate over the entire potential, so it is fair to pull it out of the integral entirely, since it is effectively a constant, and set it to one. This gives us\n\\begin{align}\nf^{(1)}(\\textbf{k}',\\textbf{k}) = -\\frac{m}{2\\pi\\hbar^2} \\int dr'^3 V(\\textbf{r}')\n\\end{align}\n\n\\end{enumerate}", "meta": {"hexsha": "3f2d36808718d9aeb5978c2e861645486937f4eb", "size": 60807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics/quantumMechanics.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": "physics/quantumMechanics.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": "physics/quantumMechanics.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": 48.8017656501, "max_line_length": 689, "alphanum_fraction": 0.712237078, "num_tokens": 19786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199592797929, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6323318559411514}}
{"text": "\n\\section{CNN models}\n\n\\subsection{2020 Jan 14, Juncai seminar}\nIn the initialization phase,  the following operations are usually\ndone:\n\\begin{itemize}\n\\item Increase the channels\n\\item pooling\n\\end{itemize}\nIs this mathematically equivalent to represent a fine grid function\ninto a number of (channels) coarse grid functions.\n\nIn CIFAR models, the following is mostly used:\n$$\nf_{\\rm in}(f)=\\sigma\\circ\\theta^0\\ast f\n$$\n\nIn ImageNet, the following is mostly used:\n$$\nf_{\\rm in}(f)=\\sigma \\circ R_{\\max} \\ast_2 \\sigma \\circ \\theta^0 \\ast_2 f\n$$\n\n\\subsubsection*{Question:}  Does this mean that the resolution of the\ninput images is too hight?\n\nFor both CIFAR and ImageNet, people often use\n\\begin{equation}\n  \\label{f-out}\nf_{\\rm out}=R_{\\rm ave}:  \\mathbb R^{n_J\\times m_J\\times c_J}\\mapsto \nR^{1\\times 1\\times c_J}\\mapsto. \n\\end{equation}\n\n\\subsection{Resolution of input images}\nThe resolutions in the original ImageNet vary a lot:\n$$\n4288x2848 \\mapsto 75x56\n$$\n\nPre-process are needed to bring the different resolutions to the same\nresolution. \n\n\\subsection{Scale of CNN}\n\\begin{enumerate}\n\\item Increase the depth\n\\item increase the channels\n\\end{enumerate}\n\n\\section{EfficientNet}\n\\begin{enumerate}\n\\item Fix a baseline model, say ResNet-18:  \n$$\n\\bar v_\\ell, \\bar c_\\ell, \\bar n\n$$\nhere $\\bar n\\times\\bar n$ is the resolution of the input image. \n\\item EfficientNet:\n$$\nd\\cdot\\bar v_\\ell, w\\cdot \\bar c_\\ell, \\gamma\\cdot\\bar n\n$$\nwhich satisfies\n$$\nd=\\alpha^\\phi, w=\\beta^\\phi, r=\\gamma^\\phi\n$$\nsuch that\n$$\n\\alpha\\beta^2\\gamma^2\\approx 2.\n$$\n\\end{enumerate}\n\n\\section{Notation for hyper-parameters}\n\n\\subsubsection*{Question}\n\\begin{quote}\n  Are there some good notations for all hyper-parameters in CNN?\n\\end{quote}\n\n\n\n", "meta": {"hexsha": "2921997c3c45d4a126ac0d042b9f2e690a5f168c", "size": 1729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Questions.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/Questions.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/Questions.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": 21.8860759494, "max_line_length": 73, "alphanum_fraction": 0.7322151533, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891348788759, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6323294104179663}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\n\\author{}\n\\date{}\n\\title{Two-dimensional Filtration of Nitrogen and Pentane\n\\(\\left( C_5 H_{12} \\right) \\)}\n\n\\usepackage[margin=0.9in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{textcomp}\n\\usepackage{amsmath, amssymb}\n\\usepackage{siunitx}\n\\usepackage{subcaption}\n\\usepackage{multirow}\n\\usepackage{bm}\n\\usepackage{ulem}\n\\usepackage{xcolor}\n\n\\definecolor{grey}{HTML}{737373}\n\\definecolor{red}{HTML}{d9343f}\n\\definecolor{green}{HTML}{2e8a07}\n\n\\begin{document}\n\\maketitle\n\n\\section{Physical model}\n\nDarcy's law:\n\\begin{equation}\n    \\bm{v}_i = -\\frac{1}{\\mu_i} \\hat K \\cdot f_\\alpha (s)\n    \\cdot \\nabla P\n\\end{equation}\nwhere \\(\\hat K\\), the specific permeability.\nIt depends only on the geometry of the medium.\nWe assume isotropy of space, so K is a scalar.\n\\(\\mu\\) is the dynamic viscosity.\n\n\\(i\\) - component.\n\n\\(\\alpha\\) - phase. (If we had multiple phases, then\nit would be \\(f_\\alpha\\))\n\nAs an approximation, \\(f_\\alpha (s) = s^2\\) for the first \ncomponent, and \\(f_\\alpha (s) = (1 - s)^2\\) for the second.\n\nThe continuity equation for each component becomes:\n\\begin{equation}\n    \\varphi \\frac{\\partial \\rho_i}{\\partial t}\n    + div (\\rho_i \\bm{v}_i) = 0\n\\end{equation}\nwhere \\(\\rho_i = \\frac{m_i}{V}\\).\n\nWe use the Tait equation to relate liquid density to pressure:\n\\begin{equation}\n    \\frac{\\hat{\\rho} - \\rho_0}{\\hat{\\rho}} = C \\log_{10}\n    \\frac{B + P}{B + P_0}\n\\end{equation}\nwhere \\(C = 0.2105\\),\n\\(\\rho_0 = \\frac{1}{67.28 \\frac{m^3}{mol}}\\),\n\\(P_0 = 0.1 MPa\\), \\(B = 35MPa\\),\nin the case of \\(C_5H_{12}\\).\n\nIdeal gas equation of state:\n\n\\begin{equation}\n    P = \\frac{RT}{M} \\hat{\\rho}\n\\end{equation}\n\n\\section{Boundary and Initial Conditions}\n\nOn the first iteration, we set an initial\npressure and molar composition.\nThen, we derive the velocities from the \npressure gradient using Darcy's law and the\nsaturation from the densities\nand molar composition.\n\n% All our BC are 2-nd order (thanks to ghost\n%     cells), except for the BC on velocity on the inlet\n% and outlet, which end up 1-st order.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{img/diagram.pdf}\n    \\caption{Boundary Conditions}\n    \\label{fig:img-diagram-pdf}\n\\end{figure}\n\n\\subsection{Pressure}\n\n\\textbf{BC:}\n\n\\[\n\\begin{cases}\n    P = P_{in} &\\text{at } y = 0\n    \\text{ and } x \\in [0, 1] \\\\\n    P = P_{out} &\\text{at } y = 2 \\\\\n    \\frac{\\partial P}{\\partial x} = 0 &\\text{at }\n    x = 0, 2 \\\\\n    \\frac{\\partial P}{\\partial y} = 0 &\\text{at }\n    y = 0 \\text{ and } x \\in [1, 2]\n\\end{cases}\n\\] \n\n\\textbf{IC:}\n\n\\[\n\\begin{cases}\n    P = P_{out} &\\text{at outlet} \\\\\n    P = P_{in}  &\\text{at inlet} \\\\\n    P = P_0     &\\text{everywhere else}\n\\end{cases}\n\\] \n\n\\subsection{Velocities}\n\n\\textbf{IC:} Darcy 2-nd order.\n\n\\textbf{BC:}\n\n\\[\n\\begin{cases}\n    u = 0 &\\text{at } x = 0, 2 \\\\\n    v = 0 &\\text{at } y = 0 \\text{ and } x \\in [1, 2] \\\\\n    \\text{Darcy (2-nd Order FD)}\n          &\\text{at } y = 2 \\\\\n    \\text{Darcy (2-nd Order FD)}\n          &\\text{at } y = 0\n    \\text{ and } x \\in [0, 1]\\\\\n\\end{cases}\n\\] \n\n\\subsection{Density}\n\nWe derive the densities from the equations of state.\n\n\\subsection{Saturation}\n    Boundary condition on the inlet as the molar\n    composition \\(\\psi\\):\n    \\[\n        \\frac{m_1}{m_2} = \\frac{\\psi}{1 - \\psi}\n        \\frac{M_1}{M_2}\n    \\] \n    where \\(M_1\\) and \\(M_2\\) represent the molar mass \n    of each component.\n\n    We can derive the densities from the equations of state,\n    then we can find the saturation.\n\n    \\[\n    \\hat \\rho_1 = \\frac{m_1}{sV}, \\qquad\n    \\hat \\rho_2 = \\frac{m_2}{(1 - s)V}\n    \\] \n\n    \\[\n    \\frac{\\hat \\rho_1}{\\hat \\rho_2} = \\frac{m_1}{m_2}\n    \\frac{1 - s}{s}\n    = \\frac{\\psi M_1}{(1 - \\psi) M_2}\\frac{1 - s}{s}\n    \\] \n\n    \\[\n        s = \\left( \n        \\frac{\\hat \\rho_1 M_2(1 - \\psi) }{\\hat \\rho_2 M_1 \\psi}\n    + 1 \\right)^{-1}\n    \\] \n\n    \\subsubsection{Outlet}\n\n    \\[\n    \\frac{\\partial s}{\\partial \\bm{n}} = 0 \n    \\] \n\n    \\subsubsection{Inlet}\n\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=0.6\\textwidth]{img/inlet.pdf}\n        \\caption{Boundary Conditions on the inlet.}\n    \\end{figure}\n\n    \\[\n        \\hat{\\rho}_{\\partial \\Omega} = \\frac{\n          \\hat{\\rho}_{\\alpha, [i, 0]}\n      + \\hat{\\rho}_{\\alpha, [i, 1]}}{2}\n    \\] \n\n    \\[\n        s_{\\partial \\Omega} = \\frac{s_{[i, 0]} + s_{[i, 1]}}{2}\n    \\] \n\n    \\[\n        s_{[i, 0]} = 2 s_{\\partial \\Omega} - s_{[i, 1]}\n    \\] \n\n%     \\textbf{On outlet:}\n% \n%     \\[\n%     \\frac{\\partial \\alpha}{\\partial \\bm{n}} = 0\n%     \\] \n% \n%     Or,\n% \n\n\\section{Discretization Scheme}\n\n\\subsection{Continuity Equation}\n\n\\[\n\\varphi \\frac{\\partial \\rho}{\\partial t}\n+ \\frac{\\partial \\rho}{\\partial x} u\n+ \\frac{\\partial \\rho}{\\partial y} v\n+ \\frac{\\partial u}{\\partial x} \\rho\n+ \\frac{\\partial v}{\\partial y} \\rho = 0\n\\] \n\n\\[\n\\varphi \\frac{\\rho^{n + 1}_{i, j} - \\rho^n_{i, j}}{\\Delta t}\n+ \\frac{\\rho_{i+1, j}^n - \\rho_{i-1,j}^n}{2\\Delta x} u_{i,j}\n+ \\frac{\\rho_{i, j+1}^n - \\rho_{i,j-1}^n}{2\\Delta y} v_{i,j}\n+ \\frac{u_{i+1, j} - u_{i-1,j}^n}{2\\Delta x} \\rho_{i,j}^n\n+ \\frac{v_{i, j+1}^n - v_{i,j-1}^n}{2\\Delta y} \\rho_{ij}^n = 0\n\\] \n\\subsection{Darcy's Law}\n\n\\[\n    u_{i,j}^n = -\\frac{K}{\\mu} f_\\alpha (s_{i, j}^n)\n    \\frac{P_{i + 1, j}^n - P_{i - 1, j}^n}{2\\Delta x} \\\\\n\\] \n\n\\[\n    v_{i,j}^n = -\\frac{K}{\\mu} f_\\alpha(s_{i, j}^n)\n    \\frac{P_{i, j + 1}^n - P_{i, j - 1}^n}{2\\Delta y}\n\\] \n\n\\subsubsection{BC}\n\n\\[\n    v_{i, 1}^n = -\\frac{K}{\\mu} f_\\alpha(s_{i, 1}^n)\n    \\frac{-3 P_{i, 1}^n + 4 P_{i, 2}^n - P_{i, 3}^n }\n    {2 \\Delta x} \\qquad \\text{(Inlet)}\n\\] \n\n\\[\n    v_{i, ny}^n = -\\frac{K}{\\mu} f_\\alpha(s_{i, ny}^n)\n    \\frac{-3 P_{i, ny}^n + 4 P_{i, ny - 1}^n\n    - P_{i, ny - 2}^n }{(-2 \\Delta x)}\n    \\qquad \\text{(Outlet)}\n\\] \n\n\\subsection{Predictor-Corrector}\n\n\\begin{enumerate}\n    \\item Predictor\n        \\begin{enumerate}\n            \\item Continuity Equation\n\\begin{align*}\n    \\tilde \\rho_{i, j}^{n+1} = \\rho_{i, j}^n\n    - \\frac{\\Delta t}{\\varphi} &\\left( \n  \\frac{\\rho_{i+1, j}^n - \\rho_{i-1,j}^n}{2\\Delta x} u_{i,j}\n+ \\frac{\\rho_{i, j+1}^n - \\rho_{i,j-1}^n}{2\\Delta y} v_{i,j}\n\\right. \\\\\n                             &\\left.+\n  \\frac{u_{i+1, j} - u_{i-1,j}^n}{2\\Delta x} \\rho_{i,j}^n\n+ \\frac{v_{i, j+1}^n - v_{i,j-1}^n}{2\\Delta y} \\rho_{ij}^n\n    \\right) \\\\\n    \\tilde \\rho_{i, j}^{n + 1}\n    = \\rho_{i, j}^n + F_\\rho^n \\Delta t \n\\end{align*}\n\n            \\item Compute Pressure \\(\\tilde P^n\\)\n            \\item Enforce boundary conditions for pressure,\n                density, and saturation.\n\n            \\item Darcy's Law (???)\n\\[\n    \\tilde u_{i,j}^n = -\\frac{K}{\\mu}\n    f_\\alpha (\\tilde s_{i, j}^n)\n    \\frac{\\tilde P_{i + 1, j}^n - \\tilde P_{i - 1, j}^n}\n    {2\\Delta x} \\\\\n\\] \n\n\\[\n    \\tilde v_{i,j}^n = -\\frac{K}{\\mu}\n    f_\\alpha(\\tilde s_{i, j}^n)\n    \\frac{\\tilde P_{i, j + 1}^n\n    - \\tilde P_{i, j - 1}^n}{2\\Delta y}\n\\] \n            \\item Enforce boundary conditions for velocity.\n        \\end{enumerate}\n\n    \\item Corrector\n        \\begin{enumerate}\n            \\item Continuity Equation\n\n\\begin{align*}\n    \\tilde F^{n + 1} = -\\frac{1}{\\varphi} &\\left( \n\\frac{\\tilde \\rho_{i+1, j}^{n + 1}\n    - \\tilde \\rho_{i-1,j}^{n + 1} }{2\\Delta x} \\tilde u_{i,j}\n+ \\frac{\\tilde \\rho_{i, j+1}^{n + 1}\n    - \\tilde \\rho_{i,j-1}^{n + 1} }{2\\Delta y} \\tilde v_{i,j}\n\\right.\\\\\n                                          &\\left.\n+ \\frac{\\tilde u_{i+1, j}\n    - \\tilde u_{i-1,j}^{n + 1}}{2\n\\Delta x} \\tilde \\rho_{i,j}^{n + 1}\n+ \\frac{\\tilde v_{i, j+1}^{n + 1}\n- \\tilde v_{i,j-1}^{n + 1}}{2\\Delta y}\n\\tilde \\rho_{ij}^{n + 1}\n    \\right) \n\\end{align*}\n\n\\begin{align*}\n    \\rho_{i, j}^{n + 1} = \\rho_{i, j}^n + \\frac{F_\\rho^n\n    + \\tilde F_\\rho^{n+1} }{2} \\Delta t\n\\end{align*}\n\n            \\item Compute Pressure \\(P^n\\)\n            \\item Enforce boundary conditions for pressure,\n                density, and saturation.\n            \\item Darcy's Law\n\\[\n    u_{i,j}^n = -\\frac{K}{\\mu} f_\\alpha (s_{i, j}^n)\n    \\frac{P_{i + 1, j}^n - P_{i - 1, j}^n}{2\\Delta x} \\\\\n\\] \n\n\\[\n    v_{i,j}^n = -\\frac{K}{\\mu} f_\\alpha(s_{i, j}^n)\n    \\frac{P_{i, j + 1}^n - P_{i, j - 1}^n}{2\\Delta y}\n\\] \n        \\end{enumerate}\n\\end{enumerate}\n\n\n\\section{Finding Pressure using Binary Search}\n\nThe function \\emph{find\\_pressure} takes as arguments\n\\(\\rho_1\\) and \\(\\rho_2\\), which are defined as\n\n\\[\n\\rho_1 = \\frac{m_1}{V}, \\qquad\n\\rho_2 = \\frac{m_2}{V}\n.\\] \n\nWe try to find the zero of the following function, that\ntakes the pressure as an argument:\n\n\\begin{equation*}\n    f(P) = \\frac{\\hat{\\rho_2} - \\rho_0}{\\hat{\\rho_2}}\n    - C \\log_{10} \\frac{B + P}{B + P_0}\n.\\end{equation*}\n\nHere, \\(\\hat{\\rho_2} = \\frac{m_2}{(1 - s)V}\\).\nIn order to determine \\(\\hat{\\rho_2}\\), we first find\n\\(\\hat{\\rho_1}\\) using the EoS, and from there, we are\nable to find the saturation\n\\(s = \\frac{\\rho_1}{\\hat{\\rho_1}}\\).\nLastly, we determine \\(\\hat{\\rho_2} = \\frac{\\rho_2}{1 - s}\\).\n\n% function findPressure(; ρ̂₁::T, ρ̂₂::T, V::T,\n%         tait::TaitEoS, igas::IdealGasEoS,\n%         p::Parameters,\n%         left=1e4, right=1e7, niter=50,\n%         eps_x=1e-6) where T<:AbstractFloat\n% \n%     function f(P::AbstractFloat)\n%         ρ₁ = density(igas, P)\n%         s = ρ̂₁ / ρ₁\n%         ρ₂ = ρ̂₂ / (1 - s)\n%         return (ρ₂ - tait.ρ₀) / ρ₂ - tait.C *\n%             log10((tait.B + P) / (tait.B + tait.P₀))\n%     end\n% \n%     P = binarySearch(; f, left, right, eps_x)\n%     ρ₁ = density(igas, P)\n%     s = ρ̂₁ / ρ₁\n%     return P, s\n% end\n% \n\\section{Algorithm}\n\nEuler method for discretization with respect to time.\n\nSecond order scheme in space, with the use of ghost cells. \n\n\\begin{enumerate}\n    \\item Calculate densities for each component using EOS.\n    \\item Find the pressure and saturation with the\n        help of the Newton Raphson method.\n    \\item Use Darcy's law to calculate velocities.\n\\end{enumerate}\n\n\\section{Units and Parameters}\n\n\\begin{table}[H]\n    \\centering\n    \\caption{Parameters for our simulation.}\n    \\label{tab:label}\n    \\begin{tabular}{| c | c |}\n        \\hline\n        Temperature & 298 \\(K\\) \\\\\n        \\hline\n        \\(P_{in}\\) & \\(10^6 Pa\\) \\\\\n        \\hline\n        \\(P_{out}\\) & \\(10^5 Pa\\) \\\\\n        \\hline\n        Porosity, \\(\\varphi\\) & 0.7 \\\\\n        \\hline\n        Specific Permeability, \\(K\\) & \\(10^{-12}\\) \\\\\n        \\hline\n        Dynamic Viscosity of Ideal Gas, \\(\\mu_1\\) &\n        \\(1.8 \\cdot 10^{-5}\\) \\(Pa \\cdot s\\) \\\\\n        \\hline\n        Dynamic Viscosity of Pentane, \\(\\mu_2\\) &\n        \\(2,14 \\cdot 10^{-4}\\) \\( Pa \\cdot s\\) \\\\\n        \\hline\n        Molar Mass of Ideal Gas, \\(M_1\\) & \n        \\(0.028\\) \\(\\frac{kg}{mol}\\) \\\\\n        \\hline\n        Molar Mass of Pentane, \\(M_2\\) & \n        \\(0.07215\\) \\(\\frac{kg}{mol}\\) \\\\\n        \\hline\n        Molar Composition at Inlet, \\(\\psi\\) &\n        \\(0.3\\) \\\\\n        \\hline\n    \\end{tabular}\n\\end{table}\n\n\\section{Conventions}\n\n\\begin{enumerate}\n\n    \\item Density:\n\n        \\[\n            \\rho_i = \\frac{m_i}{V}, \\qquad\n            \\hat{\\rho_i} = \\frac{m_i}{s_i V}\n        .\\] \n\n\\end{enumerate}\n\n\\section{TODO}\n\n\\begin{enumerate}\n    \\item \\sout{Fix: \\(\\mu\\) is different for each component.}\n\n    % \\item Add boundary conditions on \\(s_{n + 1} = s_n\\)\n    %     in the borders.\n\n    \\item \\sout{Calculate the velocities in the first \n        iteration with a first order scheme. \n    Then, everything is calculated as normal.}\n\n    \\item \\sout{The boundary condition \\(\\frac{dv}{dn} = 0\\) \n            is usually used when solving the Navier-Stokes\n        equation. In the case of filtration with Darcy's\n        equation, we can either set the velocities\n        explicitly or derive them from the pressure\n        gradient on the boundaries and from the Darcy's\n    equation on the inside.}\n\n    \\item \\sout{Create boundary condition on the inlet \n            as the molar\n        composition:}\n        \\[\n            \\frac{m_1}{m_2} = \\frac{\\psi}{1 - \\psi}\n            \\frac{M_1}{M_2},\n        \\] \n        \\sout{where \\(M_1\\) and \\(M_2\\) represent \n            the molar mass of each component.\n\n        This way, we are essentially giving a boundary\n        condition on the saturation, since we can derive\n    the densities from the equations of state.}\n\n    \\item \\sout{Change order of indexing: column major\n            storage in memory.}\n\n    \\item \\sout{Use naming conventions consistent with\n            Julia base.}\n\n    \\item Use Real instead of T in functions' parameters.\n\n    \\item Create modules.\n\n    \\item \\sout{Change density convention on \n        'BC: Saturation'.}\n\n    \\item \\sout{Bug: The density functions don't\n    take into account the saturation!}\n\n\n    \\item \\sout{Fix: When initializing the system, it\n        turns out that the pressure doesn't converge\n        with the gas EoS. (Although it aligns with the\n    liquid EoS).}\n\n    \\item \\sout{Replace binary search with a more efficient\n        algorithm.}\n    \n    \\item Profile and optimize code.\n\n    \\item \\sout{Upgrade to predictor-corrector.}\n\n\\end{enumerate}\n\n% warntype\n% \n% julia> include(\"main.jl\")\n% julia> \\@code_warntype find_pressure(ρ₁=1.1, ρ₂=2.0, tait=tait_C₅H₁₂, igas=ideal_gas, p=p, right=1e4, left=1e8, niter=50, eps_x=1e-6)section{Miscellaneous}\n\n% profiling\n% julia> using ProfileVega\n% julia> include(\"main.jl\")\n% julia> @profview filtration!(p)\n\n\\end{document}\n", "meta": {"hexsha": "019787ee77a07cd2ac95cb5d3a4520ef3a9fbecf", "size": 13288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doc.tex", "max_stars_repo_name": "sofiabelen/Ideal-Gas-Compressible-Fluid", "max_stars_repo_head_hexsha": "8e16e93c56c36aa3ce3331c852dac5f8cead6a0c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-26T21:31:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T04:38:37.000Z", "max_issues_repo_path": "doc/doc.tex", "max_issues_repo_name": "sofiabelen/Ideal-Gas-Compressible-Fluid", "max_issues_repo_head_hexsha": "8e16e93c56c36aa3ce3331c852dac5f8cead6a0c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-04-05T15:50:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-06T16:41:47.000Z", "max_forks_repo_path": "doc/doc.tex", "max_forks_repo_name": "sofiabelen/Two-Phase-Filtration", "max_forks_repo_head_hexsha": "8e16e93c56c36aa3ce3331c852dac5f8cead6a0c", "max_forks_repo_licenses": ["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.6525096525, "max_line_length": 157, "alphanum_fraction": 0.5621613486, "num_tokens": 4995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6323294003654902}}
{"text": "\\chapter{Limits and series}\n\\label{ch:calc_limits}\nNow that we have developed the theory\nof metric (and topological) spaces well,\nwe give a three-chapter sequence which\nbriskly covers the theory of single-variable calculus.\n\nMuch of the work has secretly already been done,\nFor example, if $x_n$ and $y_n$ are real sequences\nwith $\\lim_n x_n = x$ and $\\lim_n y_n = y$,\nthen in fact $\\lim_n (x_n + y_n) = x+y$\nor $\\lim_n (x_n y_n) = xy$,\nbecause we showed in \\Cref{prop:arithmetic_continuous}\nthat arithmetic was continuous.\nWe will also see that completeness plays a crucial role.\n\n\\section{Completeness and inf/sup}\n\\prototype{$\\sup [0,1] = \\sup (0,1) =  1$.}\nAs $\\RR$ is a metric space,\nwe may discuss continuity and convergence.\nThere are two important facts about $\\RR$\nwhich will make most of the following sections tick.\n\nThe first fact you have already seen before:\n\\begin{theorem}\n\t[$\\RR$ is complete]\n\t\\label{thm:complete_R}\n\tAs a metric space, $\\RR$ is complete:\n\tsequences converge if and only if they are Cauchy.\n\\end{theorem}\n\nThe second one we have not seen before --- it is the\nexistence of $\\inf$ and $\\sup$.\nYour intuition should be:\n\\begin{moral}\n\t$\\sup$ is $\\max$ adjusted slightly for infinite sets.\n\t(And $\\inf$ is adjusted $\\min$.)\n\\end{moral}\nWhy the ``adjustment''?\n\\begin{example}\n\t[Why is max not good enough?]\n\tLet's say we have the open interval $S = (0,1)$.\n\tThe elements can get arbitrarily close to $1$,\n\tso we would like to think ``$1$ is the max of $S$'';\n\texcept the issue is that $1 \\notin S$.\n\tIn general, infinite sets don't necessarily \\emph{have}\n\ta maximum, and we have to talk about bounds instead.\n\n\tSo we will define $\\sup S$ in such a way that $\\sup S = 1$.\n\tThe definition is that ``$1$ is the smallest number\n\twhich is at least every element of $S$''.\n\\end{example}\nTo write it out:\n\\begin{definition}\n\tIf $S$ is a set of real numbers:\n\t\\begin{itemize}\n\t\t\\ii An \\emph{upper bound} for $S$ is a real number $M$\n\t\tsuch that $x \\le M$ for all $x \\in S$.\n\t\tIf one exists, we say $S$ is \\vocab{bounded above};\n\t\t\\ii A \\emph{lower bound} for $S$ is a real number $m$\n\t\tsuch that $m \\le x$ for all $x \\in S$.\n\t\tIf one exists, we say $S$ is \\vocab{bounded below}.\n\t\t\\ii If both upper and lower bounds exist,\n\t\twe say $S$ is \\vocab{bounded}.\n\t\\end{itemize}\n\\end{definition}\n\\begin{theorem}\n\t[$\\RR$ has inf's and sup's]\n\t\\label{thm:inf_sup}\n\tLet $S$ be a nonempty set of real numbers.\n\t\\begin{itemize}\n\t\t\\ii If $S$ is bounded above\n\t\tthen it has a \\emph{least} upper bound,\n\t\twhich we denote by $\\sup S$\n\t\tand refer to as the \\vocab{supremum} of $S$.\n\t\t\\ii If $S$ is bounded below\n\t\tthen it has a \\emph{greatest} lower bound,\n\t\twhich we denote by $\\inf S$\n\t\tand refer to as the \\vocab{infimum} of $S$.\n\t\\end{itemize}\n\\end{theorem}\n\n\\begin{definition}\n\tFor convenience, if $S$ has not bounded above, we write $\\sup S = +\\infty$.\n\tSimilarly, if $S$ has not bounded below, we write $\\inf S = -\\infty$.\n\\end{definition}\n\n\\begin{example}\n\t[Supremums]\n\tSince the examples for infimums are basically the same,\n\twe stick with supremums for now.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $S = \\left\\{ 1, 2, 3, \\dots \\right\\}$\n\t\tthen $S$ is not bounded above, so we have $\\sup S = +\\infty$.\n\t\t\\ii If $S = \\left\\{ \\dots, -2, -1 \\right\\}$\n\t\tdenotes the set of negative integers, then $\\sup S = -1$.\n\t\t\\ii Let $S = [0,1]$ be a closed interval.\n\t\tThen $\\sup S = 1$.\n\t\t\\ii Let $S = (0,1)$ be an open interval.\n\t\tThen $\\sup S = 1$ as well, even though $1$ itself\n\t\tis not an element of $S$.\n\t\t\\ii Let $S = \\QQ \\cap (0,1)$ denote the set of rational\n\t\tnumbers between $0$ and $1$.\n\t\tThen $\\sup S = 1$ still.\n\t\t\\ii If $S$ is a finite nonempty set,\n\t\tthen $\\sup S = \\max S$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\t[Porting definitions to sequences]\n\tIf $a_1$, \\dots is a sequence we will often write\n\t\\begin{align*}\n\t\t\\sup_n a_n &\\defeq \\sup \\left\\{ a_n \\mid n \\in \\NN \\right\\} \\\\\n\t\t\\inf_n a_n &\\defeq \\inf \\left\\{ a_n \\mid n \\in \\NN \\right\\}\n\t\\end{align*}\n\tfor the supremum and infimum of the set of elements of the sequence.\n\tWe also use the words ``bounded above/below'' for sequences\n\tin the same way.\n\\end{definition}\n\\begin{example}\n\t[Infimum of a sequence]\n\tThe sequence $a_n = \\frac 1n$ has infimum $\\inf a_n = 0$.\n\\end{example}\n\n\\section{Proofs of the two key completeness properties of $\\RR$}\nCareful readers will note that we have not actually\nproven either \\Cref{thm:inf_sup} or \\Cref{thm:complete_R}.\nWe will do so here.\n\nFirst, we show that the ability\nto take infimums and supremums lets you prove completeness of $\\RR$.\n\\begin{proof}\n\t[Proof that \\Cref{thm:inf_sup} implies \\Cref{thm:complete_R}]\n\tLet $a_1$, $a_2$, \\dots be a Cauchy sequence.\n\tBy discarding finitely many leading terms,\n\twe may as well assume that $|a_i - a_j| \\le 100$ for all $i$ and $j$.\n\tIn particular, the sequence is now bounded;\n\tit lies between $[a_1-100, a_1+100]$ for example.\n\n\tWe want to show this sequence converges,\n\tso we have to first describe what the limit is.\n\tWe know that to do this we are really going\n\tto have to use the fact that we live in $\\RR$.\n\t(For example we know in $\\QQ$ the limit of\n\t$1$, $1.4$, $1.41$, $1.414$, \\dots is nonexistent.)\n\n\tWe propose the following: let\n\t\\[ S = \\left\\{ x \\in \\RR \\mid a_n \\ge x \\text {\n\t\tfor infinitely many $n$ } \\right\\}.  \\]\n\tWe claim that the sequence converges to $M = \\sup S$.\n\t\\begin{exercise}\n\t\tShow that this supremum makes sense by proving\n\t\tthat $a_1 - 100 \\in S$ (so $S$ is nonempty)\n\t\twhile all elements of $S$ are at most $a_1 + 100$\n\t\t(so $S$ is bounded above).\n\t\tThus we are allowed to actually take the supremum.\n\t\\end{exercise}\n\n\tYou can think of this set $S$ with the following picture.\n\tWe have a Cauchy sequence drawn in the real line which we think converges,\n\twhich we can visualize as a bunch of dots on the real line,\n\twith some order on them.\n\tWe wish to cut the line with a knife such that\n\tonly finitely many dots are do to the left of the knife.\n\t(For example, placing the knife all the way to the left always works.)\n\tThe set $S$ represents the places where we could put the knife,\n\tand $M$ is ``as far right'' as we could go.\n\tBecause of the way supremums work,\n\t$M$ might not \\emph{itself} be a valid knife location,\n\tbut certainly anything to its left is.\n\t\\begin{center}\n\t\\begin{asy}\n\t\tsize(10cm);\n\t\tdraw( (-8,0)--(8,0), Arrows );\n\t\tlabel(\"$\\mathbb R$\", (8,0), dir(-90));\n\t\tdraw( (3.1,1)--(3.1,-1), red );\n\t\tdraw( (2.7,1.5)--(2.7,-1.5), deepgreen );\n\t\tlabel(\"$M$\", (3.1,-1), dir(-45), red);\n\t\tlabel(\"$M-\\frac12\\varepsilon$\", (2.7,1.5), dir(90), deepgreen);\n\t\tdot(\"$a_1$\", (-5, 0), dir(-90), blue);\n\t\tdot(\"$a_2$\", (-1, 0), dir(-90), blue);\n\t\tdot(\"$a_3$\", ( 6, 0), dir(-90), blue);\n\t\tdot(\"$a_4$\", ( 0, 0), dir(-90), blue);\n\t\tdot(\"$a_5$\", (4.8, 0), dir(-90), blue);\n\t\tdot(\"$a_6$\", (4.1, 0), dir(-90), blue);\n\t\tdot(\"$a_8$\", (3.5, 0), dir(-90), blue);\n\t\tdot(\"$a_7$\", (1.5, 0), dir(-90), blue);\n\t\tdot((3.3, 0), blue);\n\t\tdot((3.2, 0), blue);\n\t\tdot((3.05, 0), blue);\n\t\\end{asy}\n\t\\end{center}\n\tLet $\\eps > 0$ be given;\n\twe want to show eventually all terms are within $\\eps$ of $M$.\n\tBecause the sequence is Cauchy,\n\tthere is an $N$ such that\n\teventually $\\left\\lvert a_m - a_n \\right\\rvert < \\half\\eps$\n\tfor $m \\ge n \\ge N$.\n\n\tNow suppose we fix $n$ and vary $m$.\n\tBy the definition of $M$,\n\tit should be possible to pick the index $m$\n\tsuch that $a_m \\ge M - \\half \\eps$\n\t(there are infinitely many to choose from\n\tsince $M - \\half\\eps$ is a valid knife location,\n\tand we only need $m \\ge n$).\n\tIn that case we have\n\t\\[ \\left\\lvert a_n - M \\right\\rvert\n\t\t\\le \\left\\lvert a_n - a_m \\right\\rvert\n\t\t+ \\left\\lvert a_m - M \\right\\rvert <\n\t\t\\half\\eps + \\half\\eps = \\eps \\]\n\tby the triangle inequality.\n\tThis completes the proof.\n\\end{proof}\n\nTherefore it is enough to prove the latter \\Cref{thm:inf_sup}.\nTo do this though, we would need to actually give a rigorous definition of\nthe real numbers $\\RR$, since we have not done so yet!\n\nOne approach that makes this easy to use the so-called\n\\vocab{Dedekind cut} construction.\nSuppose we take the rational numbers $\\QQ$.\nThen one \\emph{defines} a real number to be a ``cut''\n$A \\mid B$ of the set of rational numbers:\na pair of subsets of $\\QQ$ such that\n\\begin{itemize}\n\t\\ii $\\QQ = A \\sqcup B$ is a disjoint union;\n\t\\ii $A$ and $B$ are nonempty;\n\t\\ii we have $a < b$ for every $a \\in A$ and $b \\in B$, and\n\t\\ii $A$ has no largest element (i.e.\\ $\\sup A \\notin A$).\n\\end{itemize}\nThis can again be visualized by taking what you think of\nas the real line, and slicing at some real number.\nThe subset $\\QQ \\subset \\RR$ gets cut into two halves $A$ and $B$.\nIf the knife happens to land exactly at a rational number,\nby convention we consider that number to be in the right half\n(which explains the last fourth condition that $\\sup A \\notin A$).\n\nWith this definition \\Cref{thm:inf_sup} is easy:\nto take the supremum of a set of real numbers,\nwe take the union of all the left halves.\nThe hard part is then figuring out how to define $+$, $-$, $\\times$, $\\div$\nand so on with this rather awkward construction.\nIf you want to read more about this construction in detail,\nmy favorite reference is \\cite{ref:pugh}$,$\nin which all of this is done carefully in Chapter 1.\n\n\\section{Monotonic sequences}\nHere is a great exercise.\n\\begin{exercise}\n\t[Mandatory]\n\t\\label{exer:inf_exists}\n\tProve that if $a_1 \\ge a_2 \\ge \\dots \\ge 0$\n\tthen the limit\n\t\\[ \\lim_{n \\to \\infty} a_n \\]\n\texists.\n\tHint: the idea in the proof of the previous section helps;\n\tyou can also try to use completeness of $\\RR$.\n\tSecond hint: if you are really stuck,\n\twait until after \\Cref{thm:nonneg_bounded},\n\tat which point you can use essentially copy its proof.\n\\end{exercise}\n\nThe proof here readily adapts by shifting.\n\\begin{definition}\n\tA sequence $a_n$ is \\vocab{monotonic}\n\tif either $a_1 \\ge a_2 \\ge \\dots$\n\tor $a_1 \\le a_2 \\le \\dots$.\n\\end{definition}\n\n\\begin{theorem}\n\t[Monotonic bounded sequences converge]\n\tLet $a_1$, $a_2$, \\dots be a monotonic bounded sequence.\n\tThen $\\lim_{n \\to \\infty} a_n$ exists.\n\t\\label{thm:monotonic_bounded}\n\\end{theorem}\n\n\\begin{example}\n\t[Silly example of monotonicity]\n\tConsider the sequence defined by\n\t\\begin{align*}\n\t\ta_1 &= 1.2 \\\\\n\t\ta_2 &= 1.24 \\\\\n\t\ta_3 &= 1.248 \\\\\n\t\ta_4 &= 1.24816 \\\\\n\t\ta_5 &= 1.2481632 \\\\\n\t\t&\\vdotswithin=\n\t\\end{align*}\n\tand so on, where in general we stuck\n\ton the decimal representation of the next power of $2$.\n\tThis will converge to \\emph{some} real number,\n\talthough of course this number\n\tis quite unnatural and there is probably no good description for it.\n\\end{example}\nIn general, ``infinite decimals''\ncan now be defined as the limit of the truncated finite ones.\n\n\\begin{example}\n\t[$0.9999\\dots = 1$]\n\tIn particular, I can finally make precise the notion\n\tyou argued about in elementary school that\n\t\\[ 0.9999\\dots = 1. \\]\n\tWe simply \\emph{define} a repeating decimal\n\tto be the limit of the sequence $0.9$, $0.99$, $0.999\\dots$.\n\tAnd it is obvious that the limit of this sequence is $1$.\n\\end{example}\n\nSome of you might be a little surprised since\nit seems like we really should have\n$0.9999 = 9 \\cdot 10^{-1} + 9 \\cdot 10^{-2} + \\dots$ ---\nthe limit of ``partial sums''.\nDon't worry, we're about to define those in just a moment.\n\n\\medskip\n\nHere is one other great use of monotonic sequences.\n\\begin{definition}\n\tLet $a_1$, $a_2$, \\dots be a sequence\n\t(not necessarily monotonic) which is bounded below.\n\tWe define\n\t\\[\n\t\t\\limsup_{n \\to \\infty} a_n\n\t\t\\defeq \\lim_{N \\to \\infty} \\sup_{n \\ge N} a_n\n\t\t= \\lim_{N \\to \\infty} \\sup \\left\\{ a_N, a_{N+1}, \\dots \\right\\}.\n\t\\]\n\tThis is called the \\vocab{limit supremum} of $(a_n)$.\n\tWe set $\\limsup_{n \\to \\infty} a_n$ to be $+\\infty$\n\tif $a_n$ is not bounded above.\n\n\tIf $a_n$ is bounded above,\n\tthe \\vocab{limit infimum} $\\liminf_{n \\to \\infty} a_n$\n\tis defined similarly.\n\tIn particular, $\\liminf_{n \\to \\infty} a_n = -\\infty$\n\tif $a_n$ is not bounded below.\n\\end{definition}\n\\begin{exercise}\n\tShow that these definitions make sense,\n\tby checking that the supremums are non-increasing,\n\tand bounded below.\n\\end{exercise}\nWe can think of $\\limsup_n a_n$ as\n``supremum, but allowing finitely many terms to be discarded''.\n\n\n\\section{Infinite series}\n\\prototype{$\\sum_{k \\ge 1}^\\infty \\frac{1}{k(k+1)}\n= \\lim_{n \\to \\infty} \\left( 1 - \\frac{1}{n+1} \\right) = 1$.}\n\nWe will actually begin by working with infinite series,\nsince in the previous chapters we defined limits of sequences,\nand so this is actually the next closest thing to work\nwith.\\footnote{Conceptually: discrete things are easier\n\tto be rigorous about than continuous things,\n\tso series are actually ``easier'' than derivatives!\n\tI suspect the reason that most schools teach series last in calculus\n\tis that most calculus courses do not have proofs.}\n\nThis will give you a rigorous way to think about\nstatements like\n\\[ \\sum_{n = 1}^{\\infty} \\frac{1}{n^2} = \\frac{\\pi^2}{6} \\]\nand help answer questions like\n``how can you add rational numbers and get an irrational one?''.\n\n\\begin{definition}\n\tConsider a sequence $a_1$, \\dots{} of real numbers.\n\tThe series $\\sum_k a_k$ \\vocab{converges} to a limit $L$ if\n\tthe sequence of ``partial sums''\n\t\\begin{align*}\n\t\ts_1 &= a_1 \\\\\n\t\ts_2 &= a_1 + a_2 \\\\\n\t\ts_3 &= a_1 + a_2 + a_3 \\\\\n\t\t&\\vdotswithin= \\\\\n\t\ts_n &= a_1 + \\dots + a_n\n\t\\end{align*}\n\tconverges to the limit $L$.\n\tOtherwise it \\vocab{diverges}.\n\\end{definition}\n\\begin{abuse}\n\t[Writing divergence as $+\\infty$]\n\tIt is customary, if all the $a_k$ are nonnegative,\n\tto write $\\sum_k a_k = \\infty$ to denote that the series diverges.\n\\end{abuse}\n\nYou will notice that by using the definition of sequences,\nwe have masterfully sidestepped the issue of\n``adding infinitely many numbers''\nwhich would otherwise cause all sorts of problems.\n\\begin{moral}\n\tAn ``infinite sum'' is actually the \\emph{limit} of its partial sums.\n\tThere is no infinite addition involved.\n\\end{moral}\n\nThat's why it's for example okay to have\n$\\sum_{n \\ge 1} \\frac{1}{n^2} = \\frac{\\pi^2}{6}$ be irrational;\nwe have already seen many times that sequences of rational\nnumbers can converge to irrational numbers.\nIt also means we can gladly ignore all the\nirritating posts by middle schoolers about\n$1+2+3+\\dots = -\\frac{1}{12}$;\nthe partial sums explode to $+\\infty$, end of story,\nand if you want to assign a value to that sum\nit had better be a definition.\n\n\\begin{example}\n\t[The classical telescoping series]\n\tWe can now prove the classic telescoping series\n\t\\[ \\sum_{k = 1}^\\infty \\frac{1}{k(k+1)} \\]\n\tin a way that doesn't just hand-wave the ending.\n\tNote that the $k$th partial sum is\n\t\\begin{align*}\n\t\t\\sum_{k=1}^n \\frac{1}{k(k+1)}\n\t\t&= \\frac{1}{1 \\cdot 2}\n\t\t\t+ \\frac{1}{2 \\cdot 3}\n\t\t\t+ \\dots + \\frac{1}{n(n+1)} \\\\\n\t\t&= \\left( \\frac11 - \\frac12 \\right)\n\t\t\t+ \\dots + \\left( \\frac 1n - \\frac{1}{n+1} \\right) \\\\\n\t\t&= 1 - \\frac{1}{n+1}.\n\t\\end{align*}\n\tThe limit of this partial sum as $n \\to \\infty$ is $1$.\n\\end{example}\n\n\\begin{example}\n\t[Harmonic series diverges]\n\tWe can also make sense of the statement\n\tthat $\\sum_{k=1}^\\infty \\frac 1k = \\infty$\n\t(i.e.\\ it diverges).\n\tWe may bound the $2^n$th partial sums from below:\n\t\\begin{align*}\n\t\t\\sum_{k=1}^{2^n} \\frac1k &= \\frac11 + \\frac12 + \\dots + \\frac1{2^n} \\\\\n\t\t&\\ge \\frac11 + \\frac12 + \\left( \\frac14+\\frac14 \\right)\n\t\t+ \\left( \\frac18+\\frac18+\\frac18+\\frac18 \\right) \\\\\n\t\t&+ \\dots  +\n\t\t\\underbrace{\\left( \\frac{1}{2^n} + \\dots + \\frac{1}{2^n} \\right)}_{2^{n-1} \\text{ terms}} \\\\\n\t\t&= 1 + \\half + \\half + \\dots + \\half = 1 + \\frac{n-1}{2}.\n\t\\end{align*}\n\tA sequence satisfying $s_{2^n} \\ge 1 + \\half(n-1)$\n\twill never converge to a finite number!\n\\end{example}\n\nI had better also mention that for nonnegative sums,\nconvergence is just the same as having ``finite sum''\nin the following sense.\n\n\\begin{proposition}\n\t[Partial sums of nonnegatives bounded implies convergent]\n\t\\label{thm:nonneg_bounded}\n\tLet $\\sum_k a_k$ be a series of \\emph{nonnegative} real numbers.\n\tThen $\\sum_k a_k$ converges to some limit\n\tif and only if there is a constant $M$ such that\n\t\\[ a_1 + \\dots + a_n < M \\]\n\tfor every positive integer $n$.\n\\end{proposition}\n\\begin{proof}\n\tThis is actually just \\Cref{thm:monotonic_bounded} in disguise,\n\tbut since we left the proof as an exercise back then,\n\twe'll write it out this time.\n\n\tObviously if no such $M$ exists then convergence will not happen,\n\tsince this means the sequence $s_n$ of partial sums is unbounded.\n\n\tConversely, if such $M$ exists then we have\n\t$s_1 \\le s_2 \\le \\dots < M$.\n\tThen we contend the sequence $s_n$ converges to\n\t$L \\defeq \\sup_n s_n < \\infty$.\n\t(If you read the proof that completeness implies Cauchy,\n\tthe picture is nearly the same here, but simpler.)\n\t\\begin{center}\n\t\\begin{asy}\n\t\tsize(10cm);\n\t\tdraw( (-8,0)--(8,0), Arrows );\n\t\tlabel(\"$\\mathbb R$\", (8,0), dir(-90));\n\t\tdraw( (3.1,1)--(3.1,-1), red );\n\t\tdraw( (2.4,1.5)--(2.4,-1.5), deepgreen );\n\t\tlabel(\"$L$\", (3.1,-1), dir(-45), red);\n\t\tlabel(\"$L-\\varepsilon$\", (2.4,1.5), dir(90), deepgreen);\n\t\tdot(\"$s_1$\", (-5, 0), dir(-90), blue);\n\t\tdot(\"$s_2$\", (-4, 0), dir(-90), blue);\n\t\tdot(\"$s_3$\", (-1.7, 0), dir(-90), blue);\n\t\tdot(\"$s_4$\", (-0.2, 0), dir(-90), blue);\n\t\tdot(\"$s_5$\", (0.3, 0), dir(-90), blue);\n\t\tdot(\"$s_6$\", (1.3, 0), dir(-90), blue);\n\t\tdot(\"$s_7$\", (2.2, 0), dir(-90), blue);\n\t\tdot(\"$s_8$\", (2.7, 0), dir(-90), blue);\n\t\tdot((2.8, 0), blue);\n\t\tdot((2.88, 0), blue);\n\t\tdot((2.97, 0), blue);\n\t\\end{asy}\n\t\\end{center}\n\n\tIndeed, this means for any $\\eps$ there\n\tare infinitely many terms of the sequence exceeding $L-\\eps$;\n\tbut since the sequence is monotonic, once $s_n \\ge L-\\eps$\n\tthen $s_{n'} \\ge L-\\eps$ for all $n' \\ge n$.\n\tThis implies convergence.\n\\end{proof}\n\n\\begin{abuse}\n\t[Writing $\\sum < \\infty$]\n\tFor this reason, if $a_k$ are nonnegative real numbers,\n\tit is customary to write \\[ \\sum_k a_k < \\infty \\]\n\tas a shorthand for ``$\\sum_k a_k$ converges to a finite limit'',\n\t(or perhaps shorthand for ``$\\sum_k a_k$ is bounded'' --- as\n\twe have just proved these are equivalent).\n\tWe will use this notation too.\n\\end{abuse}\n\n\\section{Series addition is not commutative: a horror story}\nOne unfortunate property of the above definition\nis that it actually depends on the order of the elements.\nIn fact, it turns out that there is an explicit way\nto describe when rearrangement is okay.\n\n\\begin{definition}\n\tA series $\\sum_k a_k$ of real numbers\n\tis said to \\vocab{converge absolutely} if\n\t\\[ \\sum_k \\left\\lvert a_k \\right\\rvert < \\infty \\]\n\ti.e.\\ the series of absolute values converges to some limit.\n\tIf the series converges, but not absolutely,\n\twe say it \\vocab{converges conditionally}.\n\\end{definition}\n\n\\begin{proposition}\n\t[Absolute convergence $\\implies$ convergence]\n\tIf a series $\\sum_k a_k$ of real numbers\n\tconverges absolutely, then it converges in the usual sense.\n\\end{proposition}\n\\begin{exercise}\n\t[Great exercise]\n\tProve this by using the Cauchy criteria:\n\tshow that if the partial sums of $\\sum_k |a_k|$ are Cauchy,\n\tthen so are the partial sums of $\\sum_k a_k$.\n\\end{exercise}\n\nThen, rearrangement works great.\n\\begin{theorem}\n\t[Permutation of terms okay for absolute convergence]\n\tConsider a series $\\sum_k a_k$ which is absolutely convergent\n\tand has limit $L$.\n\tThen any permutation of the terms will also converge to $L$.\n\\end{theorem}\n\\begin{proof}\n\tSuppose $\\sum_k a_k$ converges to $L$,\n\tand $b_n$ is a rearrangement.\n\tLet $\\eps > 0$.\n\tWe will show that the partial sums of $b_n$\n\tare eventually within $\\eps$ of $L$.\n\n\tThe hypothesis means that there is a large $N$ in terms of $\\eps$\n\tsuch that\n\t\\[ \\left\\lvert \\sum_{k=1}^N a_k - L \\right\\rvert < \\half\\eps\n\t\t\\quad\\text{and}\\quad\n\t\t\\sum_{k = N+1}^{n} \\left\\lvert a_k \\right\\rvert < \\half\\eps\n\t\\]\n\tfor every $n \\ge N$ (the former from vanilla convergence of $a_k$\n\tand the latter from the fact that $a_k$ converges absolutely,\n\thence its partial sums are Cauchy).\n\n\tNow suppose $M$ is large enough that $a_1$, \\dots, $a_N$\n\tare contained within the terms $\\{b_1, \\dots, b_M\\}$.\n\tThen\n\t\\begin{align*}\n\t\tb_1 + \\dots + b_M\n\t\t&= (a_1 + \\dots + a_N) \\\\\n\t\t&+ \\underbrace{a_{i_1} + a_{i_2} + \\dots + a_{i_{M-N}}}%\n\t\t_{\\text{$M-N$ terms with indices $\\ge N$}}\n\t\\end{align*}\n\tThe terms in the first line sum up to within $\\half\\eps$ of $L$,\n\tand the terms in the second line have sum at most $\\half\\eps$\n\tin absolute value, so the total $b_1 + \\dots + b_M$\n\tis within $\\half\\eps + \\half\\eps = \\eps$ of $L$.\n\\end{proof}\nIn particular, when you have nonnegative terms, the world is great:\n\\begin{moral}\n\tNonnegative series can be rearranged at will.\n\\end{moral}\nAnd the good news is that actually,\nin practice, most of your sums will be nonnegative.\n\nThe converse is not true,\nand in fact, it is almost the worst possible converse you can imagine.\n\\begin{theorem}\n\t[Permutation of terms meaningless for conditional convergence]\n\tConsider a series $\\sum_k a_k$ which converges \\emph{conditionally}\n\tto some real number.\n\tThen, there exists a permutation of the series\n\twhich converges conditionally to $1337$.\n\n\t(Or any constant.  You can also get it to diverge, too.)\n\\end{theorem}\nSo, permutation is as bad as possible for conditionally convergent\nseries, and hence don't even bother to try.\n\n\\section{Limits of functions at points}\n\\prototype{$\\lim_{x \\to \\infty} 1/x = 0$.}\nWe had also better define the notion\nof a limit of a real function,\nwhich (surprisingly) we haven't actually defined yet.\nThe definition will look like what we have seen before with continuity.\n\n\\begin{definition}\n\tLet $f \\colon \\RR \\to \\RR$ be a function\\footnote{Or\n\t\t$f \\colon (a,b) \\to \\RR$, or variants.\n\t\tWe just need $f$ to be defined on an open neighborhood of $p$.\n\t} and let $p \\in \\RR$ be a point in the domain.\n\tSuppose there exists a real number $L$ such that:\n\t\\begin{quote}\n\t\tFor every $\\eps > 0$, there exists $\\delta > 0$\n\t\tsuch that if $\\left\\lvert x - p \\right\\rvert < \\delta$\n\t\tand $x \\neq p$ then $\\left\\lvert f(x) - L \\right\\rvert < \\eps$.\n\t\\end{quote}\n\tThen we say $L$ is the \\vocab{limit} of $f$ as $x \\to p$, and write\n\t\\[ \\lim_{x \\to p} f(x) = L. \\]\n\\end{definition}\nThere is an important point here: in this definition\nwe \\emph{deliberately} require that $x \\ne p$.\n\\begin{moral}\n\tThe value $\\lim_{x \\to p} f(x)$ does not depend on $f(p)$,\n\tand accordingly we often do not even bother to define $f(p)$.\n\\end{moral}\n\\begin{example}\n\t[Function with a hole]\n\tDefine the function $f \\colon \\RR \\to \\RR$ by\n\t\\[ f(x) = \\begin{cases}\n\t\t\t3x & \\text{if } x \\ne 0 \\\\\n\t\t\t2019 & \\text{otherwise}.\n\t\t\\end{cases} \\]\n\tThen $\\lim_{x \\to 0} f(x) = 0$.\n\tThe value $f(0) = 2019$ does not affect the limit.\n\tObviously, because $f(0)$ was made up to be some artificial\n\tvalue that did not agree with the limit,\n\tthis function is discontinuous at $x = 0$.\n\\end{example}\n\n\\begin{ques}\n\t[Mandatory]\n\tShow that a function $f$ is continuous at $p$\n\tif and only if $\\lim_{x \\to p} f(x)$ exists and equals $f(p)$.\n\\end{ques}\n\n\\begin{example}\n\t[Less trivial example: a rational piecewise function]\n\t\\label{ex:rational_piecewise}\n\tDefine the function $f \\colon \\RR \\to \\RR$ as follows:\n\t\\[ f(x) = \\begin{cases}\n\t\t\t1 & \\text{if } x = 0 \\\\\n\t\t\t\\frac1q & \\text{if } x = \\frac pq \\text{ where } q > 0\n\t\t\t\t\\text{ and } \\gcd(p,q) = 1 \\\\\n\t\t\t0 & \\text{if } x \\notin \\QQ.\n\t\t\\end{cases} \\]\n\tFor example, $f(\\pi) = 0$, $f(2/3) = \\frac13$, $f(0.17) = \\frac{1}{100}$.\n\tThen \\[ \\lim_{x \\to 0} f(x) = 0. \\]\n\tFor example, if $|x| < 1/100$ and $x \\neq 0$\n\tthen $f(x)$ is either zero (for $x$ irrational)\n\tor else is at most $\\frac{1}{101}$ (if $x$ is rational).\n\n\tAs $f(0) = 1$, this function is also discontinuous at $x = 0$.\n\tHowever, if we change the definition so that $f(0) = 0$ instead,\n\tthen $f$ becomes continuous at $0$.\n\\end{example}\n\n\\begin{example}\n\t[Famous example]\n\tLet $f(x) = \\frac{\\sin x}{x}$, $f \\colon \\RR \\to \\RR$,\n\twhere $f(0)$ is assigned any value.\n\tThen\n\t\\[ \\lim_{x \\to 0} f(x) = 1. \\]\n\\end{example}\nWe will not prove this here,\nsince I don't want to get into trig yet.\nIn general, I will basically only use trig functions\nfor examples and not for any theory,\nso most properties of the trig functions will just be quoted.\n\\begin{abuse}\n\t[The usual notation]\n\t\\label{abuse:limit}\n\tFrom now on, the above example\n\twill usually be abbreviated to just\n\t\\[ \\lim_{x \\to 0} \\frac{\\sin x}{x} = 1. \\]\n\tThe reason there is a slight abuse here\n\tis that I'm supposed to feed a function $f$ into the limit,\n\tand instead I've written down an expression\n\twhich is defined everywhere --- except at $x=0$.\n\tBut that $f(0)$ value doesn't change anything.\n\tSo the above means: ``the limit of the function described\n\tby $f(x) = \\frac{\\sin x}{x}$,\n\texcept $f(0)$ can be whatever it wants because it doesn't matter''.\n\\end{abuse}\n\n\\begin{remark}\n\t[For metric spaces]\n\tYou might be surprised that I didn't define\n\tthe notion of $\\lim_{x \\to p} f(x)$ earlier\n\tfor $f \\colon M \\to N$ a function on metric spaces.\n\tWe can actually do so as above, but there is one nuance:\n\twhat if our metric space $M$ is discrete,\n\tso $p$ has no points nearby it?\n\t(Or even more simply, what if $M$ is a one-point space?)\n\tWe then cannot define $\\lim_{x \\to p} f(x)$ at all.\n\n\tThus if $f \\colon M \\to N$ and we want to define\n\t$\\lim_{x \\to p} f(x)$, we have the requirement that $p$\n\tshould have a point within $\\eps$ of it, for any $\\eps > 0$.\n\tIn other words, $p$ should not be an isolated point.\n\\end{remark}\n\nAs usual, there are no surprises with arithmetic,\nwe have $\\lim_{x \\to p} (f(x) \\pm g(x))\n\t= \\lim_{x \\to p} f(x) \\pm \\lim_{x \\to p} g(x)$,\nand so on and so forth.\nWe have effectively done this proof before\nso we won't repeat it again.\n\n\\section{Limits of functions at infinity}\nAnnoyingly, we actually have to make this\ndefinition separately,\neven though it will not feel any different\nfrom earlier examples.\n\\begin{definition}\n\tLet $f \\colon \\RR \\to \\RR$.\n\tSuppose there exists a real number $L$ such that:\n\t\\begin{quote}\n\t\tFor every $\\eps > 0$, there exists a constant $M$\n\t\tsuch that if $x > M$, then $\\left\\lvert f(x)-L \\right\\rvert < \\eps$.\n\t\\end{quote}\n\tThen we say $L$ is the \\vocab{limit} of $f$ as\n\t$x$ approaches $\\infty$ and write\n\t\\[ \\lim_{x \\to \\infty} f(x) = L. \\]\n\tThe limit $\\lim_{x \\to -\\infty} f(x)$ is defined similarly,\n\twith $x > M$ replaced by $x < M$.\n\\end{definition}\nFortunately, as $\\infty$ is not an element of $\\RR$,\nwe don't have to do the same antics about $f(\\infty)$\nlike we had to do with ``$f(p)$ set arbitrarily''.\nSo these examples can be more easily written down.\n\\begin{example}\n\t[Limit at infinity]\n\tThe usual:\n\t\\[ \\lim_{x \\to \\infty} \\frac 1x = 0. \\]\n\tI'll even write out the proof:\n\tfor any $\\eps > 0$, if $x > 1/\\eps$\n\tthen $\\left\\lvert \\frac 1x - 0 \\right\\rvert < \\eps$.\n\\end{example}\n\nThere are no surprises with arithmetic:\nwe have $\\lim_{x \\to \\infty} (f(x) \\pm g(x))\n\t= \\lim_{x \\to \\infty} f(x) \\pm \\lim_{x \\to p} g(x)$,\nand so on and so forth.\nThis is about the fourth time\nI've mentioned this, so I will not say more.\n\n\\section{\\problemhead}\n\n\\begin{problem}\n\tDefine the sequence\n\t\\[ a_n = (-1)^n + \\frac{n^3}{2^n} \\]\n\tfor every positive integer $n$.\n\tCompute the limit infimum and the limit supremum.\n\\end{problem}\n\n\\begin{problem}\n\tFor which bounded sequences $a_n$\n\tdoes $\\liminf_n a_n = \\limsup_n a_n$?\n\t\\begin{hint}\n\t\tIff the sequence is convergent!\n\t\\end{hint}\n\\end{problem}\n\n\\begin{dproblem}\n\t[Comparison test]\n\tLet $\\sum a_n$ and $\\sum b_n$ be two series.\n\tAssume $\\sum b_n$ is absolutely convergent,\n\tand $|a_n| \\le |b_n|$ for all integers $n$.\n\tProve that $\\sum_n a_n$ is absolutely convergent.\n\\end{dproblem}\n\n\\begin{problem}\n\t[Geometric series]\n\t\\label{prob:geometric}\n\tLet $-1 < r < 1$ be a real number.\n\tShow that the series\n\t\\[ 1 + r + r^2 + r^3 + \\dots \\]\n\tconverges absolutely and determine what it converges to.\n\t\\begin{hint}\n\t\tThe $n$th partial sum is $\\frac{1}{1-r} (1-r^{n+1})$.\n\t\\end{hint}\n\\end{problem}\n\n%\\begin{problem}\n%\t[An order-free definition for infinite nonnegative sums]\n%\tLet $a_1$, \\dots{} be a sequence of \\emph{nonnegative} real numbers.\n%\tProve that\n%\t\\[ \\sum_{k=1}^\\infty a_k = \\sup \\left\\{ \\sum_{k \\in K} a_k\n%\t\t\t\\mid K \\subseteq \\NN \\right\\} \\]\n%\twhere if the right-hand side is $+\\infty$,\n%\twe mean that the left-hand side is a divergent series.\n%\\end{problem}\n\n\\begin{problem}\n\t[Alternating series test]\n\tLet $a_0 \\ge a_1 \\ge a_2 \\ge a_3 \\ge \\dots$ be a weakly decreasing sequence\n\tof nonnegative real numbers,\n\tand assume that $\\lim_{n \\to \\infty} a_n = 0$.\n\tShow that the series $\\sum_n (-1)^n a_n$ is convergent\n\t(it need not be absolutely convergent).\n\t\\begin{sol}\n\t\tThis is an application of Cauchy convergence, since\n\t\tone can show that\n\t\t\\[ \\left\\lvert \\sum_{n=M}^N (-1)^n a_n \\right\\rvert \\le a_{\\min\\{M,N\\}}. \\]\n\t\tIndeed, if $M$ and $N$ are even\n\t\t(for simplicity; other cases identical) then\n\t\t\\begin{align*}\n\t\t\ta_M - a_{M+1} + a_{M+2} - \\dots\n\t\t\t&= a_M - (a_{M+1}-a_{M+2}) - (a_{M+3}-a_{M+4}) \\\\\n\t\t\t&\\quad- \\dots - (a_{N-1} - a_N) \\\\\n\t\t\t&\\le a_M \\\\\n\t\t\ta_M - a_{M+1} + a_{M+2} - \\dots\n\t\t\t&= a_M - a_{M+1} + (a_{M+2} - a_{M+3}) + (a_{M+4} - a_{M+5}) \\\\\n\t\t\t&\\quad+ \\dots + (a_{N-2} - a_{N+1}) + a_N \\\\\n\t\t\t&\\ge -a_{M+1}.\n\t\t\\end{align*}\n\t\tIn this way we see that the sequence of partial sums is Cauchy,\n\t\thence converges to some limit.\n\t\\end{sol}\n\\end{problem}\n\n\n\\begin{problem}\n\t[{\\cite[Chapter 3, Exercise 55]{ref:pugh}}]\n\t\\gim\n\tLet $(a_n)_{n \\ge 1}$ and $(b_n)_{n \\ge 1}$ be sequences of real numbers.\n\tAssume $a_1 \\le a_2 \\le \\dots \\le 1000$\n\tand moreover that $\\sum_n b_n$ converges.\n\tProve that $\\sum_n a_n b_n$ converges.\n\t(Note that in both the hypothesis and statement,\n\twe do not have absolute convergence.)\n\t\\begin{hint}\n\t\tThis is a very tricky algebraic manipulation.\n\t\tTry setting $a_n = x_1 + \\dots + x_n$ for $x_i \\ge 0$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tTo capture $(a_n)_n$ monotonic and bounded,\n\t\twrite $a_n = x_1 + \\dots + x_n$ for some $x_i$.\n\t\tThen $x_2$, \\dots are all the same sign and so $\\sum |x_i| = A < \\infty$\n\t\tfor some constant $A$.\n\n\t\tWe now prove that the partial sums of $\\sum a_n b_n$ are a Cauchy sequence.\n\t\tConsider any $\\varepsilon > 0$.\n\t\tLet $K$ be such that the tails of $b_n$\n\t\tstarting after $K$ have absolute value less than $\\frac{\\varepsilon}{A}$.\n\t\tThen for any $N > M \\ge K$ we have\n\t\t\\begin{align*}\n\t\t\t\\left\\lvert \\sum_{k=M}^N a_k b_k \\right\\rvert\n\t\t\t&= \\left\\lvert \\sum_{k=M}^N \\sum_{j=1}^k b_k x_j \\right\\rvert \\\\\n\t\t\t&= \\left\\lvert \\sum_{j=1}^N \\sum_{k=\\max\\{j,M\\}}^N b_k x_j \\right\\rvert \\\\\n\t\t\t&= \\left\\lvert \\sum_{j=1}^N x_j \\cdot \\sum_{k=\\max\\{j,M\\}}^N b_k\\right\\rvert \\\\\n\t\t\t&\\le \\sum_{j=1}^N |x_j| \\left\\lvert \\sum_{k=\\max\\{j,M\\}}^N b_k \\right\\rvert \\\\\n\t\t\t&< \\sum_{j=1}^N |x_j| \\cdot \\frac{\\varepsilon}{A} \\\\\n\t\t\t&< \\varepsilon\n\t\t\\end{align*}\n\t\tas desired.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Putnam 2016 B1]\n\t\\gim\n\tLet $x_0, x_1, x_2, \\dots$ be the sequence\n\tsuch that $x_0=1$ and for $n\\ge 0$,\n\t\\[ x_{n+1} = \\log(e^{x_n}-x_n) \\]\n\t(as usual, $\\log$ is the natural logarithm).\n\tProve that the infinite series $x_0 + x_1 + \\dots$\n\tconverges and determine its value.\n\t\\begin{hint}\n\t\tThis is trickier than it looks.\n\t\tWe have $x_n = e^{x_n} - e^{x_{n+1}}$\n\t\tbut it requires some care to prove convergences.\n\t\tHelpful hint: $e^t \\ge t+1$ for all real numbers $t$,\n\t\ttherefore all $x_n$'s are nonnegative.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe answer is $e-1$.\n\n\t\tWe begin by noting $x_{n+1} = \\log(e^{x_n} - x_n) \\ge \\log 1 = 0$,\n\t\towing to $e^t \\ge 1+t$.\n\t\tSo $x_n \\ge 0$ for all $n$.\n\n\t\tNext notice that\n\t\t\\[ x_{n+1} = \\log\\left( e^{x_n} - x_n \\right) < \\log e^{x_n} = x_n. \\]\n\t\tSo $(x_n)_n$ is strictly decreasing in addition to nonnegative.\n\t\tThus it must converge to some limit $L$.\n\n\t\tThird, observe that\n\t\t\\[ x_n = e^{x_n} - e^{x_{n+1}}\n\t\t\t\\implies x_0 + x_1 + \\dots + x_n\n\t\t\t= e^{x_0} - e^{x_n} = e - e^{x_n} < e. \\]\n\t\tSince the partial sums are bounded by $e$,\n\t\tand $x_i \\ge 0$, we conclude $L = 0$.\n\n\t\tFinally, the limit of the partial sums is then\n\t\t\\[ \\lim_{n \\to \\infty} e - e^{x_n} = e - e^0 = e - 1. \\]\n\t\\end{sol}\n\\end{problem}\n\n\n\\begin{problem}\n\tConsider again the function $f \\colon \\RR \\to \\RR$\n\tin \\Cref{ex:rational_piecewise} defined by\n\t\\[ f(x) = \\begin{cases}\n\t\t\t1 & \\text{if } x = 0 \\\\\n\t\t\t\\frac1q & \\text{if } x = \\frac pq\n\t\t\t\\text{ where } q > 0 \\text{ and } \\gcd(p,q) = 1 \\\\\n\t\t\t0 & \\text{if } x \\notin \\QQ.\n\t\t\\end{cases} \\]\n\tFor every real number $p$,\n\tcompute $\\lim_{x \\to p} f(x)$, if it exists.\n\tAt which points is $f$ continuous?\n\t\\begin{hint}\n\t\tThe limit always exists and equals zero.\n\t\tConsequently, $f$ is continuous exactly at irrational points.\n\t\\end{hint}\n\\end{problem}\n\n", "meta": {"hexsha": "021996a09e7273354d4af7e5edab67647d03aafc", "size": 32410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/calculus/limits.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/calculus/limits.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/calculus/limits.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.0757575758, "max_line_length": 94, "alphanum_fraction": 0.6683122493, "num_tokens": 11147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.6323107714822808}}
{"text": "\\subsection{Recursive calculation of PMW}\\label{sec:paritydelay}\n\n%The Partitioned-Growth data structure allows for prioritizing the growth of \\emph{nodes} on an odd-parity node-tree $\\dot{\\nset}$ with low PWM, instead of \\emph{vertices}. \nThe PMW can be used to prioritize the growth of vertices with low PMW. However, in order to implement this heuristic, the relevant figure of merit is not the PMW itself but the difference in PMW between the vertices. In the following we explain how to track the differences in PMW efficiently.\n\n%%%%%%%%%%%%%%%%%%%\n%We define the delay of a node $N$ which we denote by $\\delta_N$, as the difference between the PMW of $N$ and the minimum PMW in the node-tree multiplied by two. \n%\\begin{equation}\\label{eq:delayequation}\n%    \\delta_N = 2\\left(\\text{PMW}(N) - \\min_{X\\in\\nset}{\\text{PMW}(X)}\\right).\n%\\end{equation}\n%The delay of a node can be interpreted operationally as the number of times the node with minimum PMW should grow to have the same PMW as node $N$. %rowth iterations for a node to wait for all nodes in the node-tree to have equal PWM: \n\n%To grow a cluster, we loop over all nodes in $\\nset$ and grow all boundary vertices of $N$ if $\\delta_N=0$. \n%However, to find $\\delta_N$, the PMW of all nodes in $\\dot{\\nset}$ must be known, which is no trivial task as the entire tree must be considered for the calculation in every node. Furthermore, the PWM of a node changes as it and its cluster grow. Instead, we will compute for the difference in node delay between child node and its parent. \n%%%%%%%%%%%%%%%%%%%%%\n\nLet a node $R\\in \\nset$ be the root node of the node-tree. As $\\nset$ is an acyclic tree, $R$ defines implicitly the parent-child relations for all the nodes in $\\nset$, where a node has one parent, but potentially multiple children. We let $P\\geq Q$ denote that $P$ is the parent of $Q$. Abusing notation, we represent any odd-parity node-tree of $\\abs{\\dot\\nset}\\geq 3$ by the tuple $\\{\\nset_P,P-Q,\\nset_Q\\}$. In this notation, $\\nset_P$ denotes the sub-tree consisting of all ancestors of $P$, \\textcolor{cyan}{including the edge from $P$ to its parent}, and all descendant branches of $P$ excluding the branch starting from $(P,Q)$.  $\\nset_Q$ denotes the sub-tree consisting of all descendant branches of $Q$, \\textcolor{cyan}{including the edges from $Q$ to its children}. With this notation and based on the node types of $P,Q$ and the parity of $\\nset_Q$, we can deduce the parity of $\\nset_P$, since $\\dot{\\nset}$ is odd. \n\nIn the following, we derive the difference in PMW between a parent node $P$ and its child $Q$. For this, let us consider that a syndrome-node is connected to either $P$ or $Q$. \n\nWe first argue that any matching is equivalent to a matching where all nodes in the even note-tree are matched internally. If the sub-tree $\\nset_Q$ is of even parity, denoted by $\\overbar{\\nset_Q}$, it must consist of a combination of even branches and an even number odd branches, where a branch is the subtree hanging from a child node. %, where the parity of the branch refers to the parity of the number of syndrome-nodes. \nFor any even branch $\\bar{b}$, the full matching must be within $\\bar{b}$: since there is a single edge connecting $\\bar b$ with $Q$ and the branch is even, it would not be possible to support two matches out of $\\bar{b}$. \nIf an odd branch $\\dot{b}_1$ matches outside $\\overbar{\\nset_Q}$, on edge $(Q, \\dot{b}_1)$, there must exist another odd branch $\\dot{b}_2$ that also matches outside $\\overbar{\\nset_Q}$, in this case via edge $(Q, \\dot{b}_1)$. Since the matchings meet at node $Q$ there is an equivalent matching that matches $\\dot{b}_1$ and $\\dot{b}_2$. \n%If the node-tree merges with another odd tree either at $Q$ or $P$, the minimum weight matching will be equivalent to a matching where all nodes in $\\overbar{\\nset_Q}$ match internally. \nThe same argument holds for an even $\\nset_P$.\n\nIf the subtree $\\nset_Q$ is of odd parity, denoted by $\\dot{\\nset_Q}$, it must consist of a combination of even branches and an odd number of odd branches. By the same argument as before, for any matching, there exists an equivalent matching where the even branches and all odd branches except for one (which is an even number) match internally. \nThe remaining odd branch in $\\dot{\\nset_Q}$ must be connected with either $Q$, $P$, or the new syndrome-node connected. The same argument holds for an odd $\\nset_P$.\n\nUsing this argument, we can deduce the required edges for a matching during a merger on $Q$ and $P$ and find the difference in the PMW of $Q$ and $P$. For example, if both $P,Q$ are syndrome-nodes and $\\nset_Q$ is even, $\\nset_P$ must be odd. The potential matching weights on $\\dot{P},\\dot{Q}$ are thus \n\\begin{align*}\n  \\text{PMW}(\\dot{P}) &= \\rho_{\\dot{P}} + \\abs{(\\dot{\\nset_P},\\dot{P})} + \\abs{(\\dot{P}, \\dot{Q})} + C \\\\\n  \\text{PMW}(\\dot{Q}) &= \\rho_{\\dot{Q}} + \\abs{(\\dot{\\nset_P},\\dot{P})} + C,\n\\end{align*}\nwhere $C$ is a constant equal to the weight of the matching \\textcolor{cyan}{entirely within} the subtrees $\\dot{\\nset_P}$ and $\\overbar{\\nset_Q}$ and \\textcolor{cyan}{$\\abs{(\\dot{\\nset_P},\\dot{P})}$ denotes the distance between the $P$ and its pair in $\\nset_P$}. In consequence, we find that their difference is \n\\begin{equation*}\n  \\text{PMW}(\\dot{Q}) - \\text{PMW}(\\dot{P}) = \\rho_{\\dot{Q}} - \\rho_{\\dot{P}} - \\abs{(\\dot{P}, \\dot{Q})}.\n\\end{equation*}\nSimilarly, the PMW difference can be deduced for any combination of node types of $P,Q$ and parity of $\\nset_Q$ (see \\Cref{fig:nmcombi}):\n\\begin{align*}\n  \\text{PMW}({Q}) - \\text{PMW}({P}) &= \\rho_Q - \\rho_P - \\abs{(P,Q)}  &\\dot{P}, \\dot{Q}, \\overbar{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P + \\abs{(P,Q)}  &\\dot{P}, \\dot{Q}, \\dot{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P + \\abs{(P,Q)}  &\\dot{P}, \\bar{Q}, \\overbar{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P - \\abs{(P,Q)}  &\\dot{P}, \\bar{Q}, \\dot{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P - \\abs{(P,Q)}  &\\bar{P}, \\dot{Q}, \\overbar{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P + \\abs{(P,Q)}  &\\bar{P}, \\dot{Q}, \\dot{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P + \\abs{(P,Q)}  &\\bar{P}, \\bar{Q}, \\overbar{\\nset_Q} \\\\\n  &= \\rho_Q - \\rho_P - \\abs{(P,Q)}  &\\bar{P}, \\bar{Q}, \\dot{\\nset_Q} \\\\\n\\end{align*}\nwhich can be simplified to \n    %n_d = m_d + \\Big\\lfloor 2C\\big(n_r-\\rho_P - (-1)^{n_p}\\abs{(n,m)}\\big )\\Big\\rfloor\n\\begin{equation}\\label{eq:pmwdif}\n    \\text{PMW}({Q}) =  \\text{PMW}({P}) + \\rho_Q-\\rho_P + (-1)^{\\pi_Q}\\abs{(P,Q)},\n\\end{equation}\nwhere $\\pi_N$ is the \\textbf{node parity} of $N$, i.e. the number of syndrome-nodes modulo 2 \\textcolor{cyan}{in the sub-tree containing $N$ and all its descendants}. The node parity of a node can also be calculated recursively from the node parities of its children nodes, \\textcolor{cyan}{based on the chosen reference root node $R$}. In particular, they are given by the following expressions for syndrome-nodes and junction-nodes: \n\\begin{align}\n    \\pi_{\\dot{P}} = \\hspace{.6cm} \\Bigg(\\hspace{.2cm} \\sum_{\\mathclap{\\forall Q \\leq \\dot{P}}} (1-\\pi_Q) \\Bigg ) \\bmod 2 \\label{eq:snodeparity} \\\\\n    \\pi_{\\bar{P}} = \\Bigg(1 + \\hspace{.2cm}  \\sum_{\\mathclap{\\forall Q \\leq \\bar{P}}} (1-\\pi_Q) \\Bigg) \\bmod 2.  \\label{eq:jnodeparity}\n\\end{align}\n\n\\Figure[tb](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure3.pdf}{\n  Any odd-parity node-tree of $\\abs{\\dot{\\nset}}\\geq 3$ can be simplified to $\\{\\nset_P,P,Q,\\nset_Q\\}$, where $\\nset_P$ is the subtree consisting of all ancestors of $P$ and all descendant branches excluding the branch starting from $(P,Q)$, $\\nset_Q$ is the subtree consisting of all descendant branches of $Q$, and $(\\nset_P, P), (Q, \\nset_Q)$ can represent any number of edges on $\\dot{\\nset}$. The figure shows which edges are part of the matching for a hypothetical merger on either $P$ (cyan edges) or $Q$ (magenta edges), for any combination of node types of $P,Q$ and the parity of $\\nset_Q$, similarly to \\Cref{eq:pmwdif}.\n  \\label{fig:nmcombi}}\n\nThe previous relations allow to compute the difference in PMW between nodes directly connected in the node-tree. These relations can be used to obtain the difference with respect to a reference node, for instance with respect to $R$ the root of the node-tree, which can be calculated by a depth-first search from root $R$ to all descendant nodes by adding the differences between each parent and its child. \n\n\n\n% \\begin{equation}\\label{eq:pseudodelay}\n%     {\\delta}_Q = {\\delta}_P + 2\\left(\\text{PMW}(Q) - \\text{PMW}(P)\\right), \\hspace{.3cm} Q\\leq P.\n% \\end{equation}\n% where ${\\delta}_N = \\text{PMW}(N) - \\text{PMW}(R)$. \n\n% \\Cref{eq:pmwdif} can be easily explained through an example of the cluster in \\Cref{fig:pmw}. The PMW's of $A, B, C$ are respectively \n% \\begin{align}\n%     \\nonumber \\text{PMW}(A) &= \\rho_A + \\abs{(B, C)}, \\\\\n%     \\nonumber \\text{PMW}(B) &= \\rho_B + \\abs{(A, B)} + \\abs{(B, C)}, \\\\\n%     \\nonumber \\text{PMW}(C) &= \\rho_C + \\abs{(A, B)}.\n% \\end{align}\n% Take $A\\geq B\\geq C$. The differences in node delay are thus \n% \\begin{align}\n%     \\nonumber \\Delta_B &= \\delta_B - \\delta_A =& 2\\left(\\rho_B - \\rho_A + \\abs{(A, B)}\\right), \\\\\n%     \\nonumber \\Delta_C &= \\delta_C - \\delta_B =& 2\\left(\\rho_C - \\rho_B - \\abs{(B, C)}\\right).\n% \\end{align}", "meta": {"hexsha": "7e079fcc407ca8afb88fb96cb1081c259fa31d8d", "size": 9195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_algo_c_dfs.tex", "max_stars_repo_name": "watermarkhu/tqe_paper_ufbb", "max_stars_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_c_dfs.tex", "max_issues_repo_name": "watermarkhu/tqe_paper_ufbb", "max_issues_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_c_dfs.tex", "max_forks_repo_name": "watermarkhu/tqe_paper_ufbb", "max_forks_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-11T15:53:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-11T15:53:16.000Z", "avg_line_length": 109.4642857143, "max_line_length": 931, "alphanum_fraction": 0.6871125612, "num_tokens": 2919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6323107621013542}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[usenames]{color} %used for font color\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{wasysym}\n\\usepackage[utf8]{inputenc} %useful to type directly diacritic characters\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{float}\n\\usepackage{mathtools}\n\\usepackage [english]{babel}\n\\usepackage [autostyle, english = american]{csquotes}\n\\MakeOuterQuote{\"}\n\\graphicspath{ {./} }\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\\newcommand{\\prob}{\\mathbb{P}}\n\\newcommand{\\degrees}{^{\\circ}}\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\author{Tianshuang (Ethan) Qiu}\n\\begin{document}\n\\title{Math 104, HW8}\n\\maketitle\n\\newpage\n\n\\section{Q1}\nFor $x \\not = 1$, $\\frac{1}{x}$ is differentiable, and according to the inverse theorem, it is equal to $-\\frac{1}{x^2}$\n\\newline\nSince $\\sin'(x) = \\cos(x)$, and $\\sin$ is well defined on all of $\\R$ (the codomain of $\\frac{1}{x}: \\R \\setminus 0 \\to \\R$), we can apply the chain rule to the second factor: $(\\sin(\\frac{1}{x}))' = \\cos(\\frac{1}{x})(-\\frac{1}{x^2})$\n\\newline\nNow since $x^2: \\R \\to \\R$ is continuous in all its domain, we attempt to differentiate at an arbitrary point $x_0$:\n$$\\lim_{x \\to x_0}\\frac{(x^2)-(x_0^2)}{x-x_0} = \\lim_{x \\to x_0}\\frac{(x+x_0)(x-x_0)}{x-x_0} = \\lim_{x \\to x_0}(x+x_0) = 2x_0$$\nTherefore $(x^2)'=2x$\n\\newline\nFinally we use the product rule and the derivative is $$2x\\sin(\\frac{1}{x}) + x^2\\cos(\\frac{1}{x})(-\\frac{1}{x^2})= 2x\\sin(\\frac{1}{x})-\\cos(\\frac{1}{x})$$\n\\newpage\n\n\n\\section{Q2}\nWe claim that $f'(0)$ exists and is equal to $0$.\n\\newline\nConsider the definition of the derivative: $$\\lim_{x \\to 0}\\frac{x^2\\sin(\\frac{1}{x})-0}{x-0}$$\nSince this function is defined on every point but 0, we have $f': \\R \\setminus 0 \\to \\R$\nNow we can simplify to:\n$$\\lim_{x \\to 0}x \\sin(\\frac{1}{x}) $$\nNow we apply the squeeze theorem with $-1 \\leq \\sin(s) \\leq 1$, and\n$$-x \\leq x \\sin(\\frac{1}{x}) \\leq x$$\nSince $-x, x$ both converge to 0, our derivative also converges to 0.\n\\newpage\n\n\n\\section{Q3}\nWe will use the fact that the derivative at $\\R \\setminus 0$ contains $\\cos(\\frac{1}{x})$, which fluctuates rapidly when $x$ is close to 0 to show a contradiction.\n\\newline\nAssume that the derivative function $f'$ is continuous on $\\R$. So let $\\epsilon = 0.1, x_0=0$, then by our assumption there exists $\\delta$ such that $|x-x_0|<\\delta$ implies $|f'(x)-f'(0)|<\\epsilon$\n\\newline\nWe have shown above that $f'(0)=0$, so we expand $|f'(x)-f'(0)|$:\n$$=|2x\\sin(\\frac{1}{x})-\\cos(\\frac{1}{x})-0| \\leq |2x\\sin(\\frac{1}{x})|+|\\cos(\\frac{1}{x})| \\leq |\\cos(\\frac{1}{x})|$$\n\\newline\nBy the Archimedean Principle we know that there exists $n$ such that $\\frac{1}{n}<\\delta$. Set $x = \\frac{1}{2\\pi n} <\\frac{1}{n}<\\delta$. Consider $f'(x) = |\\cos(2\\pi n)| = 1 > \\epsilon$.\n\\newline\nTherefore when $\\epsilon=0.1, x_0=0$, we have found an $x$ such that for any $\\delta > 0$, though $|x-x_0|<\\delta$, $|f'(x)-f'(x_0)|>\\epsilon$\n\\newline\nThus the function is not continuous.\n$\\blacksquare$\n\\newpage\n\n\n\\section{Q4}\n\n\\subsection{a}\nBase case:\n\\newline\n$(x^1)'$ By the definition of the derivative we know that $f'(a)=\\lim_{x \\to a} \\frac{x-a}{x-a} = 1$ since the numerator and the denominator cancel.\n\\newline\nInductive step:\n\\newline\nAssume that $(x^n)' = nx^{n-1}$ for some $n \\in \\N$ Consider $x^{n+1}$\n\\newline\nWe write it as $x^nx$, now we apply can the product rule. We have shown in the base case that $x'=1$, so we have\n$$(x^{n+1})' = nx^{n-1}x + 1x^{n} = (n+1)x^{n+1}$$\nThus we have shown the inductive step. $\\blacksquare$\n\n\n\\subsection{b}\nWe rewrite $(\\frac{f}{g})' = (f\\frac{1}{g})'$ Now we attempt to apply the chain rule to $(\\frac{1}{g})'$\n\\newline\nSince $g$ has codomain of $\\R$ and is differentiable at $a$, we can use the chain rule.\n$$(\\frac{1}{g})' = -\\frac{1}{(g(a))^2}g'(a)$$\nNow we multiply $f(a)$ in with the product rule\n$$(\\frac{f}{g})' = f'(a)\\frac{1}{g(a)}-f(a)\\frac{1}{(g(a))^2}g'(a)\n= \\frac{f'(a)g(a)}{(g(a))^2}-\\frac{f(a)g'(a)}{(g(a))^2}$$\nThus it is proven.\n\\newpage\n\n\n\\section{Ross 29.5}\nMy key observation to this problem is that when $x,y$ are close to each other, $(x-y)^2$ becomes very small. So in order to be smaller than or equal to this, $|f(x)-f(y)|$ must also be able to get arbitrarily small.\n\\newline\nLet $\\epsilon > 0$, for any $a \\in \\R$, we can simply pick our delta to be $\\min\\{1, \\sqrt(\\epsilon/2)\\}$ Let $|x-a|<\\delta$, then $(x-a)^2 < \\delta ^2 = \\epsilon/2$. Now by the statement of the problem $|f(x)-f(a)|\\leq (x-a)^2 <\\epsilon/2$. Therefore $f$ is be continuous everywhere.\n\\newline\nNow consider the absolute value of the derivative of this function:\n$$|f'(a)| = \\lim_{x \\to a}\\frac{|f(x)-f(a)|}{|x-a|}$$\nWe can slightly modify the specification of the problem. Since $x^2 = (-x)^2$, we can rewrite the function assumption to be $|f(x)-f(y)|\\leq |x-y|^2$\n\\newline\nNow we have $|f'(a)| \\leq \\lim_{x \\to a}x - a = 0$. Since $|f'(a)| \\geq 0$, we have $|f'(a)| = 0$. Thus we have shown that the function has a derivative of $0$ everywhere, and it is therefore constant.\n$\\blacksquare$\n\\newpage\n\n\n\\section{Ross 29.13}\nConsider $h(x)=g(x)-f(x)$. $h(0) = g(0)-f(0)=0, h'(x)=g'(x)-f'(x)$. By the specification of the problem we know that $h'(x)\\geq 0 $ when $x \\geq 0$\n\\newline\nNow consider $h(y)$ with $y\\geq 0$. Assume that there is a point $z \\geq 0$ such that $g(z)<f(z)$, so $h(z)= g(z)-f(z) < 0$. Since $h(0)=0$, and $h$ is differentiable, by the Mean Value Theorem we know that there exists a point $p \\in (0,z)$ where $h'(z)=\\frac{h(z)-0}{z-0}<0$. However by our assumption we know that $h'(z) \\geq 0 \\forall z \\geq 0$. We have reached a contradiction.\n\\newline\nTherefore our assumption is incorrect, $g(x)\\geq f(x)$ for all $x \\geq 0$.\n\\newpage\n\n\n\\section{Ross 29.17}\n\n\\subsection{$h$ is differentiable implies equal derivative and limit}\nLet $h$ be differentiable at $a$. Then by the definition of the derivative we have $\\lim_{x \\to a} \\frac{h(x)-h(a)}{x-a}$ exists, which implies that $\\lim_{x \\to a} h(x)$ exists.\nSince the limit exists, for any $\\epsilon > 0$, $\\exists \\delta > 0$ such that $|x-a|<\\delta$ implies $|h(x)-h(a)|<\\epsilon$. $h(a)=g(a)$ When $x$ is less than $a$, $|f(x)-g(a)|<\\epsilon$. Since the difference is less than any positive number, $f(a)$ must equal $g(a)$.\n\\newline\nNow consider the fact that  $\\lim_{x \\to a} \\frac{h(x)-h(a)}{x-a}$ exists. Then we must have\n$$\\lim_{x \\to a^+} \\frac{h(x)-h(a)}{x-a} = \\lim_{x \\to a^-} \\frac{h(x)-h(a)}{x-a}$$\nBy the definition of $h$ we can now break the above statement down into:\n$$\\lim_{x \\to a^+} \\frac{f(x)-f(a)}{x-a} = \\lim_{x \\to a^-} \\frac{g(x)-g(a)}{x-a}$$\nSince $f'(a), g'(a)$ exist, then the above equation must imply $\\lim_{x \\to a^+} f'(a) = \\lim_{x \\to a^-} g'(a)$, thus $f'(a)=g'(a)$\n\n\n\\subsection{Converse}\nLet $f(a)=g(a), f'(a)=g'(a)$. Since $f(a)=g(a)$, and $f,g$ are differentiable and therefore continuous, the function $h$ is continuous at $a$.\nNow consider the derivative: $\\lim_{x \\to a} \\frac{h(x)-h(a)}{x-a}$.\n\\newline\nWe break it down into two cases: $x$ converging from the negative and the positive\n$$\\lim_{x \\to a^+} \\frac{h(x)-h(a)}{x-a} = \\lim_{x \\to a^+} \\frac{f(x)-f(a)}{x-a} = f'(a)$$\n$$\\lim_{x \\to a^-} \\frac{h(x)-h(a)}{x-a} = \\lim_{x \\to a^-} \\frac{g(x)-g(a)}{x-a} = g'(a)$$\nNow since $f'(a)=g'(a)$, we know that $\\lim_{x \\to a^+} \\frac{h(x)-h(a)}{x-a} = \\lim_{x \\to a^-} \\frac{h(x)-h(a)}{x-a}$.\nThus the limit exists, and therefore $h$ is differentiable at $a$\n\\newline\n$\\blacksquare$\n\n\n\\end{document}\n", "meta": {"hexsha": "5e6bf6bcf6c31ffa7510831502da0952e4476d5f", "size": 7607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw8/main.tex", "max_stars_repo_name": "TianshuangQiu/Math104-Homework", "max_stars_repo_head_hexsha": "87625a461e62db12905cb91bb9a7116af145ef8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw8/main.tex", "max_issues_repo_name": "TianshuangQiu/Math104-Homework", "max_issues_repo_head_hexsha": "87625a461e62db12905cb91bb9a7116af145ef8c", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "TianshuangQiu/Math104-Homework", "max_forks_repo_head_hexsha": "87625a461e62db12905cb91bb9a7116af145ef8c", "max_forks_repo_licenses": ["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.3774834437, "max_line_length": 382, "alphanum_fraction": 0.6388852373, "num_tokens": 2899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289836, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6322095124316737}}
{"text": "\\documentclass{llncs}\n\n\\usepackage{latexsym}\n\\usepackage{times}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{cite}\n\\usepackage{booktabs}\n\\usepackage{adjustbox}\n\\usepackage{marvosym}\n%% Colored hyperlink \n\\newcommand{\\cref}[2]{\\href{#1}{\\color{blue}#2}}\n%% Colored hyperlink showing link in TT font\n% \\newcommand{\\chref}[1]{\\href{#1}{\\small\\tt \\color{blue}#1}}\n\\newcommand{\\hcref}[1]{\\cref{#1}{\\small\\tt #1}}\n\n\\bibliographystyle{splncs04}\n\n\\newcommand{\\one}{\\mbox{\\bf 1}}\n\\newcommand{\\zero}{\\mbox{\\bf 0}}\n\\newcommand{\\leafone}{L_1}\n\\newcommand{\\leafzero}{L_0}\n\\newcommand{\\booland}{\\land}\n\\newcommand{\\boolor}{\\lor}\n\\newcommand{\\boolxor}{\\oplus}\n\\newcommand{\\boolnot}{\\neg}\n%\\newcommand{\\tautology}{\\top}\n%\\newcommand{\\nil}{\\bot}\n\\newcommand{\\tautology}{1}\n\\newcommand{\\nil}{0}\n\\newcommand{\\obar}[1]{\\overline{#1}}\n\\newcommand{\\ite}{\\mbox{\\it ITE}}\n\n\\newcommand{\\opname}[1]{\\mbox{\\sc #1}}\n\\newcommand{\\andop}{\\opname{And}}\n\\newcommand{\\implyop}{\\opname{Imply}}\n\n\\newcommand{\\turnstile}{\\vdash}\n\n\\newcommand{\\fname}[1]{\\mbox{\\small\\sf #1}}\n\n\\newcommand{\\lo}{\\fname{Lo}}\n\\newcommand{\\hi}{\\fname{Hi}}\n\\newcommand{\\var}{\\fname{Var}}\n\\newcommand{\\val}{\\fname{Val}}\n\n\\newcommand{\\interp}{\\sigma}\n\\newcommand{\\interpset}[1]{\\Sigma_{#1}}\n\\newcommand{\\mcount}{\\mu}\n\n\\newcommand{\\ifarg}{\\textbf{I}}\n\\newcommand{\\thenarg}{\\textbf{T}}\n\\newcommand{\\elsearg}{\\textbf{E}}\n\\newcommand{\\depend}{{\\it D}}\n\n\\newcommand{\\subs}[2]{[#2/#1]}\n\\newcommand{\\substrue}[1]{\\subs{#1}{\\tautology}}\n\\newcommand{\\subsfalse}[1]{\\subs{#1}{\\false}}\n\\newcommand{\\subsflip}[1]{\\subs{#1}{\\obar{#1}}}\n\n\\title{Notes on Validated Model Counting \\\\ Version of \\today}\n\n\\author{Randal E. Bryant}\n\n\\institute{\nComputer Science Department \\\\\nCarnegie Mellon University, Pittsburgh, PA, United States\n}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Notation}\n\nConsider Boolean formulas over a set of variables $X$.  An\nassignment $\\interp$ is a function mapping each variable to \ntruth value $\\tautology$ (true) or $\\nil$ (false).  We can extend\n$\\interp$ to Boolean formulas in the normal way, such that\n$\\interp(F)$ will be $\\tautology$ (respectively, $\\nil$) if the\nevaluation of formula $F$ yields $\\tautology$ (resp., $\\nil$) when its\nvariables are assigned values according to $\\interp$.\n\nFor Boolean formula $F$, we define its set of {\\em models} $\\interpset{F}$ as\n\\begin{eqnarray}\n\\interpset{F} & = & \\{ \\interp | \\interp(F) = \\tautology \\}\n\\end{eqnarray}\nThe task of model counting is, given formula $F$, to determine the size of its set of models\n$\\mcount(F) = |\\interpset{F}|$.  Ideally, this should be done without actually enumerating the set.\n\nFor interpretation $\\interp$ and a Boolean formula $E$ over $X$, we\nuse the notation $\\interp\\subs{x}{E}$ to denote the intepretation\n$\\interp'$, such that $\\interp'(y) = \\interp(y)$ for all $y \\not = x$\nand $\\interp'(x) = \\interp(E)$.  In particular, the notation\n$\\interp\\subsflip{x}$ indicates the interpretation in which the value\nassigned to $x$ is complemented, while others remain unchanged.\n\nA Boolean formula $F$ is said to be {\\em independent} of variable $x$\nif every $\\interp \\in \\interpset{F}$ has $\\interp\\subsflip{x} \\in\n\\interpset{F}$.\n\n\\begin{lemma}\n\\label{lemma:independent:split}\nIf Boolean formula $F$ is independent of variable $x$, then:\n\\begin{equation}\n|\\interpset{F}| \\; = \\; 2\\cdot |\\interpset{F\\land x}| = \\; 2\\cdot |\\interpset{F\\land \\obar{x}}| \\label{eqn:independent}\n\\end{equation}  \n\\end{lemma}  \nThat is, the set of models of $F$ is split evenly between\nthose assigning $\\tautology$ to $x$ and those assigning $\\nil$ to $x$.\n\n\\section{ITE Operation}\n\nWe consider a single Boolean operation, known as\n``If-Then-Else,'' or simply ``ITE.''  For Boolean values $a, b, c$,\nthe operation is defined as $\\ite(a,b,c) = (a \\land b) \\lor (\\obar{a}\n\\land c)$.  This single operation can be used to express several common Boolean operations:\n\\begin{eqnarray*}\n\\obar{a} & = & \\ite(a, \\nil, \\tautology) \\\\\na \\land b & = & \\ite(a, b, \\nil) \\\\\na \\lor b & = & \\ite(a, \\tautology, b) \\\\\na \\rightarrow b & = & \\ite(a, b, \\tautology) \\\\\n\\end{eqnarray*}  \n\nFor variable $x$ and Boolean formulas $F$ and $G$, the set of models\nfor $\\ite(x, F, G)$ is given by the formula:\n\\begin{eqnarray}\n  \\interpset{\\ite(x, F, G)} & = & \\{ \\interp \\in \\interpset{F} | \\interp(x) = \\tautology \\}\n  \\cup \\{ \\interp \\in \\interpset{G} | \\interp(x) = \\nil \\} \\label{eqn:ite:interp}\n\\end{eqnarray}\n\n\\section{ITE Graphs}\nModel counting is especially simple for a class of formulas we\ncall ``free ITE graphs.''  This representation can be obtained\ndirectly from an Ordered Binary Decision Diagram (OBDD) representation\nof a Boolean function~\\cite{Bryant:1986}.\n\nAn {\\em ITE graph} is defined to be a directed acyclic graph,\nconsisting of three node types:\n\\begin{description}\n\\item[Constant:] Corresponds to value $\\tautology$ or $\\nil$.  A constant node has no incoming arcs.\n\\item[Input:] Corresponds to one of the variables in $X$.   A variable node has no incoming arcs.\n\\item[Operator:] Represents an application of the $\\ite$ operation.  An operator node has three incoming arcs, labeled \\ifarg{}, \\thenarg{}, and \\elsearg{}, corresponding to the three arguments of the $\\ite$ operation.\n\\end{description}  \n\nAn {\\em input-controlled} ITE graph is one for which the incoming \\ifarg{} arc for every operator node is\nfrom an input node.  That is, the result of one $\\ite$ operation can\nserve as the ``then'' or ``else'' argument to another $\\ite$\noperation, but not for the ``if'' argument.\n\nWhen describing input-controlled ITE graphs, we refer to constant and input\nnodes by their associated value or variable.  An operator node is described by an expression of the form\n$\\ite(x, v_t, v_e)$, where $v_t$ and $v_e$ are the\nnodes corresponding to the \\thenarg{} and \\elsearg{} inputs, respectively.\n\nWe can define the function $\\depend$ mapping each node\n$v$ in an input-controlled ITE graph to the set of variables on which it logically depends.  This can be expressed recursively as\n\\begin{eqnarray}\n\\depend(\\tautology) & = & \\emptyset \\label{eqn:depend:true}\\\\\n\\depend(\\nil) & = & \\emptyset \\label{eqn:depend:false}\\\\\n\\depend(x) & = & \\{x \\} \\label{eqn:depend:variable}\\\\\n\\depend(\\ite(x, v_t, v_e)) & = & \\{ x \\} \\cup \\depend(v_t) \\cup \\depend(v_e) \\label{eqn:depend:ite}\n\\end{eqnarray}  \n\n\n\\begin{lemma}\n\\label{lemma:independent:dset}\nAny node $v$ in an ITE graph is independent of any variable $y \\in X$ such that $y \\not \\in \\depend(v)$.\n\\end{lemma}  \n\\noindent\n{\\em Proof:} Follows by the recursive definition of $\\depend$ (\\ref{eqn:depend:true}--\\ref{eqn:depend:ite}) and by (\\ref{eqn:ite:interp}).\n\n\nA {\\em free} ITE graph is an input-controlled ITE graph satisfying the added\nproperty that for every operator node $v = \\ite(x, v_t, v_e)$, its\nincoming \\thenarg{} and \\elsearg{} arcs must be from nodes such that\n$x \\not \\in \\depend(v_t)$ and $x \\not \\in \\depend(v_e)$.\n\nFree ITE graphs correspond directly to a class of binary decision diagrams known as {\\em free} BDDs (FBDDs)~\\cite{gergov:ieeetc:1994}.  Ordered BDDs are a subclass of FBDDs.\n\n\\section{Model Counting Free ITE Graphs}\n\nWhile model counting is a difficult problem for arbitrary\nformulas, it readily be computed when $F$ takes the form of a free\nITE graph.\n\n\\begin{theorem}\n\\label{theorem:count}\nLetting $n = |X|$, the following recursive formula holds for any node in a free ITE graph\n\\begin{eqnarray}\n\\mcount(\\tautology) & = & 2^{n} \\label{eqn:count:true}\\\\\n\\mcount(\\nil) & = & 0 \\label{eqn:count:false}\\\\\n\\mcount(x) & = & 2^{n-1} \\label{eqn:count:variable}\\\\\n\\mcount(\\ite(x, v_t, v_e)) & = & \\frac{\\mcount(v_t) + \\mcount(v_e)}{2} \\label{eqn:count:ite}\n\\end{eqnarray}  \n\\end{theorem}\n\\noindent\n{\\em Proof:} The key result here is (\\ref{eqn:count:ite}).  It follows\nfrom Lemma~\\ref{lemma:independent:split}, (\\ref{eqn:ite:interp}),\nLemma~\\ref{lemma:independent:dset}, and (\\ref{eqn:depend:ite}).  That is, both\n$v_t$ and $v_e$ are independent of $x$.  That implies that half of the\nsatisfying assignments $\\interp$ for $v_t$ have have $\\interp(x) =\n\\tautology$.  Similarly, half of the satisfying assignments $\\interp$\nfor $v_e$ have $\\interp(x) = \\nil$.  Equation (\\ref{eqn:count:ite}) then follows by (\\ref{eqn:ite:interp}).\n\n\\bibliography{references}\n\n\\end{document}\n", "meta": {"hexsha": "7b1a00867342187f4fb59a58e057e945a32a937a", "size": 8255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/mc-notes.tex", "max_stars_repo_name": "avigad/model-counting", "max_stars_repo_head_hexsha": "63942c2a23238efabc32bfbc62005828413e2ed0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:46:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T19:18:23.000Z", "max_issues_repo_path": "doc/mc-notes.tex", "max_issues_repo_name": "avigad/model-counting", "max_issues_repo_head_hexsha": "63942c2a23238efabc32bfbc62005828413e2ed0", "max_issues_repo_licenses": ["MIT"], "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/mc-notes.tex", "max_forks_repo_name": "avigad/model-counting", "max_forks_repo_head_hexsha": "63942c2a23238efabc32bfbc62005828413e2ed0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-13T16:58:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T02:56:24.000Z", "avg_line_length": 39.4976076555, "max_line_length": 218, "alphanum_fraction": 0.7017565112, "num_tokens": 2634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8311430394931457, "lm_q1q2_score": 0.6322094954586465}}
{"text": "\\section{Task C}\n\\label{sec:task-c}\n\nThe same plots as in section~\\ref{sec:task-b} were obtained for the case\nwhen the truss angle \\(\\alpha = \\operatorname{atan} (1/3)\\).\nThe plots are given in figure~\\ref{fig:plots-C} for the left truss.\n\\begin{figure}[th]\n  \\centering\n  % Force - deflection:\n  \\begin{subfigure}[t]{\\textwidth}\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        xlabel = {\\( (Y - y) / L \\), [-]},\n        ylabel = {\\( F / (E A) \\), [-]},\n        xmin = 0, \n        xmax = 2,\n        ymin = -0.15, \n        ymax = 0.2,\n        legend cell align=left,\n        legend style={anchor=south west, at={(0,0)}}\n        ]\n        \\addplot+ table[skip first n=1] {data/force_deflection_elastic_C.dat}; % + = same automatically determined styles, but in addition it uses [options]\n        \\addlegendentry{elastic}\n        \\addplot+ table[skip first n=1] {data/force_deflection_plastic_C.dat};\n        \\addlegendentry{plastic}\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Force - deflection}\n  \\end{subfigure}\n\n  % Stress - strain:\n  \\begin{subfigure}[t]{0.48\\textwidth}\n    \\begin{tikzpicture}[baseline,yscale=1.0, xscale=1.0]\n      \\begin{axis}[\n        try min ticks=5,\n        minor tick num=1,\n        grid=both,\n        xlabel = {strain, [-]},\n        ylabel = {Kirchhoff stress, [kN/mm\\textsuperscript{2}]},\n        % xmin = -0.4, \n        xmax = 0.4,\n        % xtick={-0.4, -0.2, 0, 0.2},\n        % ymin = -30, \n        % ymax = 30,\n        legend cell align=left,\n        legend style={anchor=south east, at={(1,0)}}\n        ]\n        \\addplot+ table[skip first n=1] {data/stress_strain_elastic_C.dat};\n        \\addlegendentry{elastic}\n        \\addplot+ table[skip first n=1] {data/stress_strain_plastic_C.dat};\n        \\addlegendentry{plastic}\n      \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Constitutive behaviour}\n  \\end{subfigure}\n  % Total - plastic strain:\n  \\begin{subfigure}[t]{0.48\\textwidth}\n    \\begin{tikzpicture}[baseline,yscale=1.0, xscale=1.0]\n      \\begin{axis}[\n        tick label style={/pgf/number format/fixed},\n        % try min ticks=8,\n        minor tick num=1,\n        grid=both,\n        xlabel = {total strain, [-]},\n        ylabel = {plastic strain, [-]},\n        % xmin = -0.4, \n        % xmax = 0.2,\n        % ymin = -0.1, \n        ymax = 0.01\n        ]\n        \\addplot+ [mark=none] table[skip first n=1] {data/tot_pl_strain_C.dat};\n        \\addplot+  table[skip first n=1] {data/tot_pl_strain_C.dat}; % Plot again using style of 2nd element in cycle list.\n      \\end{axis}\n    \\end{tikzpicture}  \n    \\caption{Plastic - total strain}\n  \\end{subfigure}\n  \\caption{Plots of large deflection elasto-plastic behaviour of the fist truss when \\(A_{2} = 1.05 A_{1}\\).}\n  \\label{fig:plots-C}\n\\end{figure}\n\nIn addition, the displacement of the initially upper joint is shown in\nfigure~\\ref{fig:node-displ-C}.\nIt is evident that for such small angle the solution is sensitive to the\ndifference in cross-section area between the trusses.\n\\begin{figure}[th]\n  \\centering\n  \\begin{tikzpicture}[baseline,yscale=1.0, xscale=1.0]\n    \\begin{axis}[\n      % try min ticks=8,\n      width = 0.7\\textwidth,\n      minor tick num=1,\n      grid=both,\n      xlabel = {horizontal displacement, [mm]},\n      ylabel = {vertical displacement, [mm]},\n      legend cell align=left,\n      legend style={anchor=center, at={(0.5,0.5)}},\n      every axis plot/.append style={line width=0.8pt}, % 0.4 - default\n      % xmin=-12,\n      % xmax=30,\n      % ymin=-300,\n      ymax=0\n      ]\n      \\addplot+ [mark=none] table[skip first n=1] {data/node_displ_elastic_C.dat};\n      \\addlegendentry{elastic, \\(A_{2} = 1.05 A_{1}\\)}\n      \\addplot+ [mark=none] table[skip first n=1] {data/node_displ_plastic_C.dat};\n      \\addlegendentry{plastic, \\(A_{2} = 1.05 A_{1}\\)}\n      \\addplot+ [mark=none, dashed] table[skip first n=1] {data/node_displ_plastic_C_1percent.dat};\n      \\addlegendentry{plastic, \\(A_{2} = 1.01 A_{1}\\)}\n      \\addplot+ [mark=none, densely dotted] table[skip first n=1] {data/node_displ_plastic_C_10percent.dat};\n      \\addlegendentry{plastic, \\(A_{2} = 1.1 A_{1}\\)}\n    \\end{axis}\n  \\end{tikzpicture}\n  \\caption{Displacement of the initially upper node of the first (left) truss.}\n  \\label{fig:node-displ-C}\n\\end{figure}\n\nObtaining the convergence for this task was the most problematic.\nEven in the case of elastic material response, a situation depicted\nin the figure~\\ref{fig:no-newton} was occurring, where the local\nminimum prevented the Newton-Raphson method from finding the\ncorrect solution.\nIn those situations, the false position method was used instead.\n\\begin{figure}[th]\n  \\centering\n  \\begin{tikzpicture}[baseline,yscale=1.0, xscale=1.0]\n    \\begin{axis}[\n      width = 0.7\\textwidth,\n      max space between ticks=50,\n      minor tick num=1,\n      grid=both,\n      xlabel = {displacement, [mm]},\n      ylabel = {residual, [N]},\n      ]\n      \\addplot+ table[skip first n=1] {data/residual_vs_du.dat};\n    \\end{axis}\n  \\end{tikzpicture}\n  \\caption{Example of situation, where Newton-Raphson method can fail.}\n  \\label{fig:no-newton}\n\\end{figure}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "22b629db90019438a8a3eb603190f4cea7a4ed60", "size": 5360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_c.tex", "max_stars_repo_name": "iamrosk/nonlinear-truss", "max_stars_repo_head_hexsha": "af0e0b7b5fdc6d9c14e735255f9f041a17fc9d27", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-04T01:51:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-04T01:51:17.000Z", "max_issues_repo_path": "doc/sec/task_c.tex", "max_issues_repo_name": "iamrosk/nonlinear-truss", "max_issues_repo_head_hexsha": "af0e0b7b5fdc6d9c14e735255f9f041a17fc9d27", "max_issues_repo_licenses": ["MIT"], "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/nonlinear-truss", "max_forks_repo_head_hexsha": "af0e0b7b5fdc6d9c14e735255f9f041a17fc9d27", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-04T01:51:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-04T01:51:20.000Z", "avg_line_length": 35.2631578947, "max_line_length": 156, "alphanum_fraction": 0.6195895522, "num_tokens": 1697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6322094909489908}}
{"text": "\\chapter{Differential Algebraic Equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Singular perturbed problems and differential algebraic \n\tequation of index 1}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{example}[Van der Pol equation]\n  Given is the following equation:\n\n  \\begin{equation}\\begin{split}\n    \\epsilon z'' + (z^2 - 1) z' + z & = 0 \\\\\n    z(0) & = z_0 \\\\\n  \\end{split}\\end{equation}\n\n\tIt is also called Van der Pol equation. If one now chooses $\\epsilon$ \n\tvery small, then one obtains a stiff IVP.\n\n  \\begin{equation}\n    \\epsilon z'' + (z^2 - 1) z' = \\diffq[t] \\underbrace{(\\epsilon z' + (\\frac{z^3}{3} - z))}_{=: y}\n  \\end{equation}\n\n  \\begin{equation}\\begin{split}\n    \\diffq[t] y & = -z \\\\\n    \\epsilon \\diffq[t] z & = y - (\\frac{z^3}{3} - z) \\\\\n  \\end{split}\\end{equation}\n\n  \\begin{equation}\\begin{split}\n    y' & = f(y,z) \\\\\n    \\epsilon z' & = g(y,z) \\\\\n  \\end{split}\\end{equation}\n\n\tThis is an example of a singular perturbed problem (SDP)\n\n  For $\\epsilon = 0$ we receive:\n\n  \\begin{equation}\\begin{array}{lll}\n    y' & = f(y,z) & \\leftarrow \\text{ordinary differential equation (ODE)} \\\\\n    0 & = g(y,z) & \\leftarrow \\text{algebraic equation (AE)}\\\\ \n  \\end{array}\\end{equation}\n\n\tThe upper system consists of an ordinary differential equation and an algebraic \n\tequation. Therefore one also calls this a differential algebraic equation\n\t(DAE).\n\\end{example}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End: \n", "meta": {"hexsha": "065ee9d77285746ba726a100950dceb68f890ece", "size": 1678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/dae.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/dae.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/dae.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": 30.5090909091, "max_line_length": 99, "alphanum_fraction": 0.5292014303, "num_tokens": 468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6321677915723161}}
{"text": "\\problemname{Hole in One}\n\nJanine recently went to her local game store and bought ``Hole in One'', a new mini-golf game for her computer. As indicated by the name, the objective of the game is to shoot a ball into a hole using just one shot. The game also borrows elements from brick breaker style games: in the playing field, several walls are placed that will be destroyed upon being hit by the ball.  The score of a successful shot depends on the number of destroyed walls, so Janine wonders: what is the maximum number of walls that can be hit while performing a ``Hole in One''?\n\nFor the purposes of this problem you can think of the playing field as a cartesian plane with the initial position of the ball at the origin. The walls are non-intersecting axis-parallel line segments in this plane (i.e., parallel to either the $x$ axis or the $y$ axis).  The diameter of the ball is negligible so it is represented as a single point.\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[width=0.55\\textwidth]{sample-illustration-new.png}\n\t\\begin{minipage}[c]{0.82\\textwidth}\n\t\t\\caption{Illustration of the first sample input: The ball first bounces off two walls\n\t\tat points 1 and 2. When it passes point 3 the wall has already vanished.}\n\t\\end{minipage}\n\\end{figure}\n\nWhenever the ball hits a wall, two things happen:\n\\begin{itemize}\n\\item The direction of the ball changes in the usual way: the angle of incidence equals the angle of reflection.\n\\item The wall that the ball touched is destroyed. Following common video game logic, no rubble of the wall remains; it will be as though it vanished.\n\\end{itemize}\n\nThe behaviour of the ball is also affected by the power of the\nshot.  In particular, an optimal shot may need to first roll over the\nhole, then hit some more walls, and only later drop into the hole.\n\n\\section*{Input}\n\nThe input consists of:\n\\begin{itemize}\n\\item one line with one integer $n$ ($0 \\le n \\le 8$), the number of walls;\n\\item one line with two integers $x$ and $y$, the coordinates of the hole;\n\\item $n$ lines each with four integers $x_1$, $y_1$, $x_2$, and $y_2$ (either $x_1 = x_2$, or $y_1 = y_2$, but not both), representing a wall with end points $(x_1, y_1)$ and $(x_2, y_2)$.\n\\end{itemize}\n\nThe hole is not at the origin and not on a wall.  The walls do not\ntouch or intersect each other.  No wall lies completely on the $x$\naxis or the $y$ axis.\nAll coordinates in the input are integers with absolute value at most $1\\,000$.\n\n\\section*{Output}\n\nIf there is no way to shoot the ball such that it reaches the hole, print ``\\texttt{impossible}''.\nOtherwise, print the maximum number of walls that can be destroyed in a single ``Hole in One'' shot.\n\n", "meta": {"hexsha": "808f57011d431b69889e356bf1e40ce73b4fef6e", "size": 2685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/holeinone/problem_statement/problem.en.tex", "max_stars_repo_name": "stoman/CompetitiveProgramming", "max_stars_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-22T13:21:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-12T22:26:26.000Z", "max_issues_repo_path": "problems/holeinone/problem_statement/problem.en.tex", "max_issues_repo_name": "stoman/CompetitiveProgramming", "max_issues_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_issues_repo_licenses": ["MIT"], "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/holeinone/problem_statement/problem.en.tex", "max_forks_repo_name": "stoman/CompetitiveProgramming", "max_forks_repo_head_hexsha": "0000b64369b50e31c6f48939e837bdf6cece8ce4", "max_forks_repo_licenses": ["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.0227272727, "max_line_length": 557, "alphanum_fraction": 0.7512104283, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6321677892126626}}
{"text": "\\documentclass{article}\n\n\\usepackage[colorlinks=true]{hyperref}\n\\usepackage[cmex10]{amsmath}\n\\usepackage{bbm}\n\\usepackage{graphicx}\n\\usepackage{subfig}\n\\usepackage{algorithm}\n\\usepackage{algorithmic}\n\\usepackage{comment}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{multirow}\n\n\\newcommand{\\BigO}[1]{\\ensuremath{\\operatorname{O}\\left(#1\\right)}}\n\\DeclareMathOperator*{\\argmin}{\\mathrm{argmin}}\n\n\\begin{document}\n\n\\title{SubKit: Subspace Clustering Library}\n\\author{Stephen Tierney, Yi Guo and Junbin Gao}\n\\maketitle\n\n\\tableofcontents\n\n\\newpage\n\\section{Motivation}\n\nSubKit is a library with implementations for subspace clustering learning algorithms. This library was created during the writing of the OSC journal article to ensure fair comparison between different methods. In the original OSC CVPR paper we used implementations provided by authors of SSC and LRR. However these implementations used different noise models to what we suggested with OSC. For example the original LRR implementation expects column wise noise while we expect Gaussian noise in all columns. Therefore we required new implementations with the same noise model for fair comparison in our journal article.\n\n\\section{Preliminaries}\n\nWe introduce required notation. We assume the following noise model\n\\begin{align}\n\\mathbf{X = A + N}\n\\end{align}\nwhere $\\mathbf A$ is the noise free data (column wise data samples), $\\mathbf N$ is some noise and $\\mathbf X$ is the observed data. We assume that each data sample in $\\mathbf A$ lies exactly on its corresponding subspace. In an ideal case subspace clustering uses the self expressive model with the noise free data i.e.\\\n\\begin{align}\n\\mathbf{A = AZ}\n\\end{align}\nwhere $\\mathbf Z$ is the matrix of coefficients. However this is rarely the case since we do not observe noise free data therefore the self expressive model becomes \n\\begin{align}\n\\mathbf{X = XZ + E}\n\\end{align}\nwhere $\\mathbf E$ is a fitting error. Once $\\mathbf Z$ has been estimated one performs spectral clustering to obtain the final segmentation.\n\n\\newpage\n\\section{Function Listing}\n\n\\begin{table}[!h]\n{\\small{\n\\centering\n\n\\begin{tabular}{c | c | c}\n\\hline\nObjective & Function & Section \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf Z} \\; \\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\; \\mathbf{A = AZ} \\end{array}$\n\t& ssc\\_noisefree\t& 4.1  \\\\\n\\hline\n\n\\multirow{4}{*}{$\\begin{array}{c} \\min_{\\mathbf Z} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}\\text{, diag}(\\mathbf Z) = \\mathbf 0 \\end{array}$}\n\t\t& ssc\\_relaxed\t& 4.2 \\\\\n\t\t& ssc\\_relaxed\\_lin\t& 4.3.1 \\\\\n\t\t& ssc\\_relaxed\\_lin\\_ext\t& 4.3.2 \\\\\n\t\t& ssc\\_relaxed\\_lin\\_acc\t& 4.3.3 \\\\\t\t\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\frac12\\|\\mathbf E\\|^2_F+  \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}\\text{, diag}(\\mathbf Z) = \\mathbf 0 \\end{array}$\n\t& ssc\\_exact\\_fro\t& 4.4  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\|\\mathbf E\\|_1+  \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}\\text{, diag}(\\mathbf Z) = \\mathbf 0\\end{array}$\n\t& ssc\\_exact\\_l1\t& 4.4  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\|\\mathbf E\\|_{1,2}+  \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}\\text{, diag}(\\mathbf Z) = \\mathbf 0 \\end{array}$\n\t& ssc\\_exact\\_l1l2\t& 4.4  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf Z} \\; \\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\; \\mathbf{A = AZ} \\end{array}$\n\t& lrr\\_noisefree\t& 5.1  \\\\\n\\hline\n\n\\multirow{4}{*}{$\\begin{array}{c} \\min_{\\mathbf Z} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\lambda\\|\\mathbf Z\\|_{*} \\end{array}$}\n\t\t& lrr\\_relaxed\t& 5.2 \\\\\n\t\t& lrr\\_relaxed\\_lin\t& 5.3 \\\\\n\t\t& lrr\\_relaxed\\_lin\\_ext\t& 5.3 \\\\\n\t\t& lrr\\_relaxed\\_lin\\_acc\t& 5.3 \\\\\t\t\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\frac12\\|\\mathbf E\\|^2_F+  \\lambda\\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E} \\end{array}$\n\t& lrr\\_exact\\_fro\t& 5.4  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\|\\mathbf E\\|_1+  \\lambda\\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E} \\end{array}$\n\t& lrr\\_exact\\_l1\t& 5.4  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf{Z, E}}  \\|\\mathbf E\\|_{1,2}+  \\lambda\\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E} \\end{array}$\n\t& lrr\\_exact\\_l1l2\t& 5.4  \\\\\n\\hline\n\n\\multirow{3}{*}{$\\begin{array}{c} \\min_{\\mathbf {Z, A, N}} \\; \\lambda \\|\\mathbf{N}\\|_{q} + \\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\quad \\mathbf{A = AZ, X = A + N} \\end{array}$}\n\t& r\\_lrr\\_fro\t& 5.5  \\\\\n\t& r\\_lrr\\_l1\t\t& 5.5  \\\\\n\t& r\\_lrr\\_l2\t\t& 5.5  \\\\\t\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf Z} \\frac12\\|\\mathbf{X - X Z}|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\|\\mathbf Z\\mathbf R\\|_{1} \\\\\n\\text{s.t.} \\; \\text{diag}(\\mathbf Z) = \\mathbf 0 \\end{array}$\n\t& spatsc\\_noisefree\t& 6.1  \\\\\n\\hline\n\n$\\begin{array}{c} \\min_{\\mathbf Z} \\frac12\\|\\mathbf{X - X Z}|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\|\\mathbf Z\\mathbf R\\|_{1,2} \\\\\n\\text{s.t.} \\; \\text{diag}(\\mathbf Z) = \\mathbf 0 \\end{array}$\n\t& osc\\_noisefree\t& 7.1  \\\\\n\\hline\n\n\\end{tabular}\n}}\n\\end{table}\n\n\\newpage\n\\section{Sparse Subspace Clustering}\n\n\\subsection{Noise Free}\n\n\\begin{align}\n\\min_{\\mathbf Z} \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{A = AZ} \\nonumber\n\\end{align}\nThe solution to the above objective has a fast approximate solution, given by the Shape Interaction Matrix. See the low-rank clustering section for further details. Alternatively one can calculate the sample correlation matrix $\\mathbf X^T \\mathbf X$ and select points with the maximum correlation as neighbours on the graph.\n\n\\subsection{Relaxed SSC ADMM}\n\n\\begin{align}\n\\min_{\\mathbf Z} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\lambda\\|\\mathbf Z\\|_{1}\n\\end{align}\nTo solve the relaxation via ADMM one must incorporate an auxiliary variable\n\\begin{align}\n\\min_{\\mathbf{Z, J}} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf J\\|^2_F + \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{Z = J} \\nonumber\n\\end{align}\n\\begin{align}\n\\min_{\\mathbf{Z, J}} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf J\\|^2_F + \\lambda\\|\\mathbf Z\\|_{1} + \\langle \\mathbf{Y, Z - J} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{Z - J} \\|_F^2\n\\end{align}\nThen iterate the following\n\\begin{enumerate}\n\\item Fix others and solve for $\\mathbf J$\n\\[\n\\min_{\\mathbf J} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf J\\|^2_F - \\langle \\mathbf{Y, J} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{Z - J} \\|_F^2\n\\]\n\\[\n\\min_{\\mathbf J} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf J\\|^2_F + \\frac{\\mu}{2} \\| (\\mathbf Z + \\frac{1}{\\mu} \\mathbf Y ) - \\mathbf J \\|_F^2\n\\]\n\\[\n\\mathbf X^T(\\mathbf X - \\mathbf X\\mathbf J) + \\mu ( (\\mathbf Z + \\frac{1}{\\mu} \\mathbf Y ) - \\mathbf J )\n\\]\n\\[\n\\mathbf X^T\\mathbf X\\mathbf J  + \\mu \\mathbf J = \\mathbf X^T\\mathbf X + \\mu \\mathbf Z + \\mathbf Y\n\\]\n\\[\n(\\mathbf X^T\\mathbf X + \\mu \\mathbf I )\\mathbf J = \\mathbf X^T\\mathbf X + \\mu \\mathbf Z + \\mathbf Y\n\\]\n\\[\n\\mathbf J = (\\mathbf X^T\\mathbf X + \\mu \\mathbf I )^{-1} (\\mathbf X^T\\mathbf X + \\mu \\mathbf Z + \\mathbf Y)\n\\]\n\n\\item Fix others and solve for $\\mathbf Z$\n\\[\n\\min_{\\mathbf Z} \\lambda\\|\\mathbf Z\\|_{1} + \\langle \\mathbf{Y, Z} \\rangle + \\frac{\\mu}{2} \\| \\mathbf{Z - J} \\|_F^2\n\\]\n\\[\n\\min_{\\mathbf Z} \\lambda\\|\\mathbf Z\\|_{1} + \\frac{\\mu}{2} \\| \\mathbf Z - (\\mathbf J - \\frac{1}{\\mu} \\mathbf Y) \\|_F^2\n\\]\n\n\\item Update $\\mathbf Y$\n\\[\n\\mathbf Y = \\mathbf Y + \\mu (\\mathbf{Z - J})\n\\]\n\n\\item Check stopping criteria\n\\[\n\\| \\mathbf Z - \\mathbf J \\|_F  < \\epsilon_1, \\;\n\\mu \\; \\textrm{max} ( \\| \\mathbf Z_{k+1} - \\mathbf Z_{k}  \\|_F  , \\|  \\mathbf J_{k+1} - \\mathbf J_{k} \\|_F) < \\epsilon_2\n\\]\n\n\\end{enumerate}\n\n\\subsection{Relaxed SSC Linearised}\n\nInstead of using ADMM one can linearise the Frobenius norm term instead. This removes the need to do an expensive matrix inversion.\n\\begin{align}\n\\min_{\\mathbf Z} L = \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\lambda\\|\\mathbf Z\\|_{1}\n\\end{align}\n\nLet $F = \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F$ and $\\partial F = - \\mathbf X^T \\mathbf X + \\mathbf X^T \\mathbf{X Z}$.\n\n\\subsubsection{Gradient Descent}\n\nThis version consists on iterating the following until convergence\n\n\\[\n\\min_{\\mathbf Z} \\widetilde{L}_{\\rho}(\\mathbf{Z, Z_k}) =  \\lambda\\|\\mathbf Z\\|_{1} + \\frac{\\rho}{2} \\| \\mathbf Z - ( \\mathbf Z_{k-1} - \\frac{1}{\\rho} \\partial F(\\mathbf Z_{k-1})) \\|_F^2\n\\]\n\n\\subsubsection{Extended Gradient Algorithm}\n\nIt has been shown that through the correct choice of step size $\\rho$ the gradient method can achieve a convergence rate of $\\BigO{\\frac{1}{k}}$ \\cite{ji2009accelerated}. More specifically we require that $\\rho \\geq C$ where $C$ is the Lipschitz constant. However we do not know the value of $C$ in advance. Fortunately we know that if $L(\\mathbf B) \\leq \\widetilde{L}_{\\rho}(\\mathbf B, \\mathbf Z_{k-1})$ where $\\mathbf B = \\mathcal S_{\\frac{\\lambda}{\\rho}}(\\mathbf Z_{k-1} - \\frac1{\\lambda}\\partial F(\\mathbf Z_{k-1}))$ then $\\rho \\geq C$. \n\n\\begin{algorithm}\n\\caption{Extended Gradient Descent for Robust MC}\n\\begin{algorithmic}\n\n\\REQUIRE $k = 1$, $r_0 = \\infty$, $\\mathbf Z_0 = \\mathbf 0$, $\\lambda$, $\\rho$, $\\gamma$, $\\epsilon$\n\n\\WHILE{$r_k - r_{k-1} \\geq \\epsilon$ }\n\n\t\\WHILE{$L(\\mathbf B) \\geq \\widetilde{L}_{\\rho}(\\mathbf B, \\mathbf Z_{k-1})$}\n\t\n\t\t\\STATE $\\rho = \\gamma \\rho$\t\n\t\n\t\\ENDWHILE\n\n\t\\STATE $\\mathbf Z_k = \\mathcal S_{\\frac{\\lambda}{\\rho}}(\\mathbf Z_{k-1} - \\frac1{\\rho}\\partial F(\\mathbf Z_{k-1}))$\n\t\\STATE $r_k = \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z_k\\|^2_F + \\lambda\\|\\mathbf Z_k\\|_{1}$\n\t\\STATE $k = k + 1$\n\t\n\\ENDWHILE\n\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsubsection{Accelerated Gradient Algorithm}\n\nWe can further improve our convergence rate to $\\BigO{\\frac{1}{k^2}}$ by adopting Nesterov's accelerated gradient algorithm. This is similar to the algorithm described in \\cite{ji2009accelerated}. Let $\\mathbf B = \\mathcal S_{\\frac{\\lambda}{\\rho}}(\\mathbf J_{k-1} - \\frac1{\\rho}\\partial F(\\mathbf J_{k-1}))$.\n\n\\begin{algorithm}\n\\caption{Accelerated Gradient Descent for Robust MC}\n\\begin{algorithmic}\n\n\\REQUIRE $k = 1$, $r_0 = \\infty$, $\\mathbf Z_0 = \\mathbf 0$,  $\\mathbf J_0 = \\mathbf 0$, $\\alpha_0 = 1$, $\\lambda$, $\\rho$, $\\gamma$, $\\epsilon$\n\n\\WHILE{$r_k - r_{k-1} \\geq \\epsilon$ }\n\n\t\\WHILE{$L(\\mathbf B) \\geq \\widetilde{L}_{\\rho}(\\mathbf B, \\mathbf J_{k-1})$}\n\t\n\t\t\\STATE $\\rho = \\gamma \\rho$\t\n\t\n\t\\ENDWHILE\n\n\t\\STATE $\\mathbf Z_k = \\mathcal S_{\\frac{\\lambda}{\\rho}}(\\mathbf J_{k-1} - \\frac1{\\rho}\\partial F(\\mathbf J_{k-1}))$\n\t\\STATE $\\alpha_{k} = \\frac{1 + \\sqrt{1 + 4 \\alpha_{k-1}^2)}}{2}$\n\t\\STATE $\\mathbf J_{k} = \\mathbf Z_k + \\left ( \\frac{\\alpha_{k-1} - 1}{\\alpha_{k}} \\right ) (\\mathbf Z_k - \\mathbf Z_{k-1})$\n\t\\STATE $r_k = \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z_k\\|^2_F + \\lambda\\|\\mathbf Z_k\\|_{1}$\n\t\\STATE $k = k + 1$\n\t\n\\ENDWHILE\n\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\\subsection{Exact SSC LADM}\n\nUsing LADM and exact constraints allows us to modify the noise term from Gaussian noise only to any other norm. The objective becomes\n\\begin{align}\n\\min_{\\mathbf{E, Z}} \\frac12\\|\\mathbf E \\|^2_q + \\lambda\\|\\mathbf Z\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E} \\nonumber\n\\end{align}\nwhere $q$ is a placeholder for norms such as $\\ell_1, F, \\ell_{1,2}$ etc.\n\\[\n\\min_{\\mathbf{E, Z}} \\frac12\\|\\mathbf E \\|^2_q + \\lambda\\|\\mathbf Z\\|_{1} + \\langle \\mathbf{Y, XZ - X + E } \\rangle + \\frac{\\mu}{2} \\|\\mathbf{XZ - X + E } \\|_F^2 \n\\]\n\nIterate the following\n\\begin{enumerate}\n\\item Fix others  solve for $\\mathbf Z$\n\\[\n\\min_{\\mathbf{Z}} \\lambda\\|\\mathbf Z\\|_{1} + \\langle \\mathbf{Y, XZ} \\rangle + \\frac{\\mu}{2} \\|\\mathbf{XZ - (X - E) } \\|_F^2 \n\\]\n\\[\n\\min_{\\mathbf{Z}} \\lambda\\|\\mathbf Z\\|_{1} + \\frac{\\mu}{2} \\|\\mathbf{XZ - (X - E} - \\frac{1}{\\mu} \\mathbf Y ) \\|_F^2 \n\\]\nLet $F = \\frac{\\mu}{2} \\|\\mathbf{XZ - (X - E} - \\frac{1}{\\mu} \\mathbf Y ) \\|_F^2$ and $\\partial F =  \\mu \\mathbf X^T (\\mathbf{XZ - (X - E} - \\frac{1}{\\mu} \\mathbf Y ))$\n\\[\n\\min_{\\mathbf{Z}} \\lambda\\|\\mathbf Z\\|_{1} + \\frac{\\rho}{2} \\| \\mathbf Z - (\\mathbf Z_{k} - \\frac{1}{\\rho} \\partial F(\\mathbf Z_{k}) \\|_F^2 \n\\]\n\n\n\\item Fix others and solve for $\\mathbf E$\n\\[\n\\min_{\\mathbf{E}} \\frac12\\|\\mathbf E \\|^2_q + \\langle \\mathbf{Y, E} \\rangle + \\frac{\\mu}{2} \\|\\mathbf{XZ - X + E } \\|_F^2 \n\\]\n\\[\n\\min_{\\mathbf{E}} \\frac12\\|\\mathbf E \\|^2_q + \\langle \\mathbf{Y, E} \\rangle + \\frac{\\mu}{2} \\|\\mathbf{E - (X - XZ)} \\|_F^2 \n\\]\n\\[\n\\min_{\\mathbf{E}} \\frac12\\|\\mathbf E \\|^2_q  + \\frac{\\mu}{2} \\|\\mathbf{E - (X - XZ} - \\frac{1}{\\mu} \\mathbf Y) \\|_F^2 \n\\]\n\n\n\\item Update $\\mathbf Y$\n\\begin{align*}\n\\mathbf Y =& \\mathbf Y + \\mu (\\mathbf{XZ - X + E})\n\\end{align*}\n\n\\item Update $\\mu$\n\\begin{align*}\n \\mu = \\textrm{min}( \\mu_{\\text{max}}, \\gamma \\mu)\n\\end{align*}\nwhere $\\gamma$ is defined as\n\\[\n\\gamma = \n\\begin{cases}\n\\gamma_0 & \\text{if} \\;\\; \\mu_k \\sqrt{\\rho} \\frac{\\textrm{max} (   \\| \\mathbf Z_{k+1} - \\mathbf Z_{k}  \\|_F  , \\|  \\mathbf E_{k+1} - \\mathbf E_{k} \\|_F)}{\\| \\mathbf X \\|_F} < \\epsilon \\\\\n1 & \\text{otherwise,}\n\\end{cases}\n\\]\nand $\\rho > \\| \\mathbf X \\|_F^2$,  $\\mu_{\\text{max}} >>  \\mu_0$ and $\\epsilon > 0$.\n\n\\item Check stopping criteria\n\\[\n\\frac{\\| \\mathbf X \\mathbf Z_{k+1} - \\mathbf X + \\mathbf E_{k+1}  \\|_F}{ \\| \\mathbf X \\|_F} < \\epsilon_1, \\;\n \\mu_k \\sqrt{\\rho} \\frac{\\textrm{max} ( \\| \\mathbf Z_{k+1} - \\mathbf Z_{k}  \\|_F  , \\|  \\mathbf E_{k+1} - \\mathbf E_{k} \\|_F)}{\\| \\mathbf X \\|_F} < \\epsilon_2\n\\]\n\n\\end{enumerate}\n\n\\subsection{Diagonal Constraint}\n\nIn some cases it may be desirable to enforce the constraint $\\textrm{diag}(\\mathbf Z) = \\mathbf 0$ i.e.\\ we should not allow each data point to be represented by itself. To enforce such a constraint it is not necessary to significantly alter the aforementioned optimisation schemes. This constraint only affects the step involving $\\mathbf Z$. Since this step is the soft shrinkage operator and is separable at the element level one can simply set the diagonal entries to $0$ afterwards.\n\n\\newpage\n\\section{Low-Rank Subspace Clustering}\n\n\\subsection{Noise Free}\n\n\\begin{align}\n\\min_{\\mathbf{Z}} \\;  \\| \\mathbf{Z} \\|_* \\\\\n\\text{s.t.} \\quad \\mathbf{A = AZ} \\nonumber\n\\end{align}\n\nThe solution to the above objective is given by the Shape Interaction Matrix (SIM) which is defined as $\\mathbf{V  V^T}$ where $\\mathbf V$ is the right singular vectors of $\\mathbf A$ i.e.\\\n\\[\n\\mathbf{A = U \\Sigma V^T}, \\;\\; \\mathbf \\Sigma = \\text{diag}(\\{\\sigma_i\\}_{i=1}^r)\n\\]\n\n\\subsection{Relaxed LRR ADMM}\n\n\\begin{align}\n\\min_{\\mathbf Z} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\tau \\|\\mathbf Z\\|_{*}\n\\end{align}\nThis is solved similarly to Relaxed SSC ADMM. Instead of the $\\ell_1$ shrinking operator in the update step for $\\mathbf Z$ we must use the singular value shrinking operator which is defined as \n\\begin{align}\n\\mathcal D_{\\tau}(\\mathbf Y) = \\mathbf U S_{\\tau}(\\mathbf \\Sigma) \\mathbf V^T, \\;\\; S_{\\tau}(\\mathbf \\Sigma) = \\text{diag}(\\{\\text{max}(\\sigma_i - \\tau, 0)\\}).\n\\end{align}\n\n\\subsection{Relaxed LRR Linearised}\n\nThis is solved similarly to Relaxed SSC ADMM, again replacing the $\\ell_1$ with the singular value shrinking operator.\n\n\\subsection{Exact LRR LADM}\n\nThis is solved similarly to Exact SSC LADM, again replacing the $\\ell_1$ with the singular value shrinking operator.\n\n\\subsection{Robust LRR}\n\nAn extension of LRR called Robust-LRR (R-LRR) aims to directly deal with noisy data using the previously described data generation model\n\\begin{align}\n\\min_{\\mathbf {Z, A, N}} \\; \\lambda \\|\\mathbf{N}\\|_{q} + \\|\\mathbf Z\\|_{*} \\\\\n\\text{s.t.} \\quad \\mathbf{A = AZ, X = A + N} \\nonumber\n\\end{align}\nThis objective can be decomposed into two steps. The first step solves a variant of RPCA [CITE] and the second uses the estimated $\\mathbf A$ to compute $\\mathbf Z$ using the SIM. However it is unclear as to whether such a procedure will be capable of exactly removing all noise, thus the SIM may give poor results. Fortunately further work in nuclear norm based subspace clustering by Vidal and Favaro \\cite{Vidal201447} demonstrated a number of other closed form solutions for noisy data.\n\n\\newpage\n\\section{Spatial Subspace Clustering}\n\nIn \\cite{Guo.Y;Gao.J;Li.F-2013} the following spatial subspace clustering (SpatSC) objective was proposed\n\\begin{align}\n\\label{YiGuo1}\n\\min_{\\mathbf Z, \\mathbf E} \\frac12\\|\\mathbf E|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\|\\mathbf Z\\mathbf R\\|_{1} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}\\text{, diag}(\\mathbf Z) = \\mathbf 0 \\nonumber\n\\end{align}\n\n\\subsection{Implementation}\n\nSpatSC can be implemented similarly to OSC. However the $\\ell_{1,2}$ shrinkage operator is replaced with $\\ell_1$ shrinkage operator. Please see the following section for details.\n\n\\newpage\n\\section{Ordered Subspace Clustering}\n\n\\begin{align}\n\\label{objective}\n\\min_{\\mathbf Z, \\mathbf E} \\frac12\\|\\mathbf E \\|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\|\\mathbf Z\\mathbf R\\|_{1,2} \\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E} \\nonumber\n\\end{align}\n\n\\subsection{Relaxed Constraints}\n\nFirst we remove the variable $\\mathbf E$ by using the constraint and thus the objective \\eqref{objective} can be re-written as follows,\n\\begin{align}\n\\label{objective_relaxed}\n\\min_{\\mathbf Z} \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\|\\mathbf J \\|_{1,2}\\\\\n\\text{s.t.} \\quad \\mathbf{J = ZR} \\nonumber\n\\end{align}\n\nThen the Augmented Lagrangian for the two introduced constraints is\n\\begin{align}\n\\mathcal{L}(\\mathbf Z, \\mathbf J) = & \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\lambda_1 \\|\\mathbf Z\\|_{1} + \\lambda_2\\|\\mathbf J\\|_{1,2} \\notag\\\\\n& + \\langle \\mathbf Y_1, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F \n\\label{objectiveADMM}\n\\end{align}\n\nWe can solve \\eqref{objectiveADMM} for $\\mathbf Z$ and $\\mathbf J$ in an alternative manner when fixing the others, respectively.\n\n\\begin{enumerate}\n\n\\item Set $\\mathbf J = \\mathbf J^k$, solve for $\\mathbf Z^{k+1}$ by\n\\begin{align*}\n\\lambda_1 \\|\\mathbf Z\\|_{1} + \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\langle \\mathbf Y, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F \n\\end{align*}\nwhich is equivalent to\n\\begin{align*}\n\\lambda_1 \\|\\mathbf Z\\|_{1} + \\frac12\\|\\mathbf X - \\mathbf X\\mathbf Z\\|^2_F + \\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R + \\frac{1}{\\mu} \\mathbf Y \\|^2_F\n\\end{align*}\nWe linearise the last two terms which we call $F$\n\\begin{align*}\n\\min_{\\mathbf Z} \\lambda_1 \\| \\mathbf Z \\|_1 + \\frac{\\rho}{2} \\| \\mathbf Z - (\\mathbf Z_{k-1} - \\frac{1}{\\rho} \\partial F) \\|_F^2\n\\end{align*}\nand $\\partial F = \\mathbf X^T(\\mathbf{X - XZ}) + \\mu (\\mathbf J - \\mathbf Z\\mathbf R + \\frac{1}{\\mu} \\mathbf Y)\\mathbf R^T$.\n\n\\item Set $\\mathbf Z = \\mathbf Z^k$, solve for $\\mathbf J^{k+1}$ by\n\\begin{align*}\n\\lambda_2\\|\\mathbf J\\|_{1,2} + \\langle \\mathbf Y_1, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F \n\\end{align*}\nwhich is equivalent to\n\\begin{align*}\n\\lambda_2\\|\\mathbf J\\|_{1,2} + \\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R + \\frac{1}{\\mu} \\mathbf Y \\|^2_F\n\\end{align*}\nWe linearise the last term which we call $F$\n\\begin{align*}\n\\min_{\\mathbf J} \\lambda_2\\|\\mathbf J\\|_{1,2}+ \\frac{\\rho}{2} \\| \\mathbf J - (\\mathbf J_{k-1} - \\frac{1}{\\rho} \\partial F) \\|_F^2\n\\end{align*}\nand $\\partial F = \\mu (\\mathbf J - \\mathbf Z\\mathbf R + \\frac{1}{\\mu} \\mathbf Y)$.\n\n\\item Update $\\mathbf Y$\n\\[\n\\mathbf Y = \\mathbf Y + \\mu (\\mathbf J - \\mathbf Z\\mathbf R)\n\\]\n\n\\item Update $\\mu$\n\\begin{align*}\n \\mu^{k+1} = \\textrm{min}( \\mu_{\\text{max}_1}, \\gamma \\mu^k)\\\\\n\\end{align*}\nwhere $\\gamma$ is defined as\n\\[\n\\gamma = \n\\begin{cases}\n\\gamma^0 & \\text{if} \\;\\; \\mu^k \\textrm{max} ( \\| \\mathbf Z^{k+1} - \\mathbf Z^{k}  \\|_F  , \\|  \\mathbf J^{k+1} - \\mathbf J^{k} \\|_F) < \\epsilon_2 \\\\\n1 & \\text{otherwise,}\n\\end{cases}\n\\]\n\nand $\\mu^{\\text{max}} \\gg  \\mu^0$.\n\n\\item Check stopping criteria\n\\[\n\\|\\mathbf J^{k+1} - \\mathbf Z^{k+1} \\mathbf R \\|_F < \\epsilon_1, \\;\n\\mu^k \\sqrt{\\rho} \\; \\textrm{max} ( \\| \\mathbf Z^{k+1} - \\mathbf Z^{k}  \\|_F  , \\|  \\mathbf J^{k+1} - \\mathbf J^{k} \\|) < \\epsilon_2\n\\]\n\n\\end{enumerate}\n\n\\subsection{Exact Constraints}\n\nSimilar to the relaxed version we begin by introducing auxiliary variables\n\\begin{align}\n\\label{objective_exact}\n\\min_{\\mathbf Z, \\mathbf E, \\mathbf J} \\frac12\\|\\mathbf E\\|^2_F +\\lambda_1\\|\\mathbf Z\\|_{1}+\\lambda_2\\| \\mathbf J \\|_{1,2}\\\\\n\\text{s.t.} \\quad \\mathbf{X = XZ + E}, \\mathbf{J = ZR} \\nonumber\n\\end{align}\nWe then form the Augmented Lagrangian to incorporate our constraints\n\\begin{align}\n\\mathcal{L}(\\mathbf E, \\mathbf Z, \\mathbf J) = & \\frac12\\|\\mathbf E\\|^2_F + \\lambda_1 \\|\\mathbf Z\\|_{1} + \\lambda_2\\|\\mathbf J\\|_{1,2} \\notag\\\\\n& + \\langle \\mathbf Y_1, \\mathbf{XZ} - \\mathbf X + \\mathbf E \\rangle +\\frac{\\mu}2\\|\\mathbf{XZ} - \\mathbf X + \\mathbf E\\|^2_F \\notag\\\\\n& + \\langle \\mathbf Y_2, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F\n\\end{align}\nThen we solve for $\\mathbf{E, Z, J}$ alternatively while fixing others in the following way\n\n\\begin{enumerate}\n\n\\item Set $\\mathbf E = \\mathbf E^k$ and $\\mathbf J = \\mathbf J^k$, solve for $\\mathbf Z^{k+1}$ by\n\\begin{align*}\n\\min_{\\mathbf Z} \\lambda_1 \\| \\mathbf Z \\|_1 + \\langle \\mathbf Y^k_1, \\mathbf{XZ} - \\mathbf X + \\mathbf E \\rangle +\\frac{\\mu^k}2\\|\\mathbf{XZ} - \\mathbf X + \\mathbf E\\|^2_F\\\\\n+ \\langle \\mathbf Y^k_2, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F\n\\end{align*}\n\\begin{align*}\n\\min_{\\mathbf Z} \\lambda_1 \\| \\mathbf Z \\|_1 + \\frac{\\mu^k}2\\|\\mathbf{XZ} - (\\mathbf X - \\mathbf E - \\frac{1}{\\mu^k} \\mathbf Y^k_1)\\|^2_F \\\\ + \\frac{\\mu^k}2\\| \\mathbf Z\\mathbf R - (\\mathbf J - \\frac{1}{\\mu^k} \\mathbf Y^k_2)\\|^2_F\n\\end{align*}\nWe linearise the last two terms which we call $F$\n\\begin{align*}\n\\min_{\\mathbf Z} \\lambda_1 \\| \\mathbf Z \\|_1 + \\frac{\\rho}{2} \\| \\mathbf Z - (\\mathbf Z_{k-1} - \\frac{1}{\\rho} \\partial F) \\|_F^2\n\\end{align*}\nand $\\partial F = \\mu^k \\mathbf X^T (\\mathbf{XZ_{k-1}} - (\\mathbf X - \\mathbf E - \\frac{1}{\\mu^k} \\mathbf Y^k_1)) + \\mu^k(\\mathbf{Z_{k-1}R} - (\\mathbf J - \\frac{1}{\\mu^k} \\mathbf Y^k_2))\\mathbf R^T$.\n\n\\item Set $\\mathbf Z = \\mathbf Z^k$ and $\\mathbf J = \\mathbf J^k$ solve for $\\mathbf E^{k+1}$ by\n\\begin{align*}\n\\min_{\\mathbf E} \\frac12\\|\\mathbf E\\|^2_F + \\langle \\mathbf Y^k_1, \\mathbf{XZ} - \\mathbf X + \\mathbf E \\rangle \\\\ + \\frac{\\mu^k}2\\|\\mathbf{XZ} - \\mathbf X + \\mathbf E\\|^2_F \n\\end{align*}\n\\begin{align*}\n\\min_{\\mathbf E} \\frac12\\|\\mathbf E\\|^2_F + \\frac{\\mu^k}2\\| \\mathbf E - (\\mathbf{XZ} - \\mathbf X + \\frac{1}{\\mu^k} \\mathbf Y^k_1) \\|^2_F \n\\end{align*}\n\n\n\\item Set $\\mathbf Z = \\mathbf Z^k$ and $\\mathbf E = \\mathbf E^k$ solve for $\\mathbf J^{k+1}$ by\n\\begin{align*}\n\\min_{\\mathbf J} \\lambda_2\\|\\mathbf J\\|_{1,2} + \\langle \\mathbf Y^k_2, \\mathbf J - \\mathbf Z\\mathbf R\\rangle +\\frac{\\mu^k}2\\|\\mathbf J - \\mathbf Z\\mathbf R\\|^2_F\n\\end{align*}\n\\begin{align*}\n\\min_{\\mathbf J} \\lambda_2\\|\\mathbf J\\|_{1,2} + \\frac{\\mu^k}2\\|\\mathbf J - (\\mathbf Z\\mathbf R - \\frac{1}{\\mu^k} \\mathbf Y^k_2) \\|^2_F\n\\end{align*}\n\n\\item Update $\\mathbf Y_1$ and $\\mathbf Y_2$\n\\begin{align*}\n\\mathbf Y^{k+1}_1 =& \\mathbf Y^k_1 + \\mu^k (\\mathbf{XZ - X + E})\\\\\n\\mathbf Y^{k+1}_2 =& \\mathbf Y^k_2 + \\mu^k (\\mathbf{J - ZR})\n\\end{align*}\n\n\\item Update $\\mu$\n\\begin{align*}\n \\mu^{k+1} = \\textrm{min}( \\mu_{\\text{max}_1}, \\gamma \\mu^k)\n\\end{align*}\nwhere $\\gamma$ is defined as\n\\[\n\\gamma_1 = \n\\begin{cases}\n\\gamma^0 & \\text{if} \\;\\; \\mu^k \\sqrt{\\rho} \\frac{ \\textrm{max} ( \\| \\mathbf Z^{k+1} - \\mathbf Z^{k}  \\|_F  , \\|  \\mathbf E^{k+1} - \\mathbf E^{k} \\|, \\| \\mathbf J^{k+1} - \\mathbf J^{k}  \\|_F  , \\|  \\mathbf Z^{k+1} \\mathbf R - \\mathbf Z^{k} \\mathbf R \\|_F)}{\\| \\mathbf X \\|_F}  < \\epsilon_2 \\\\\n1 & \\text{otherwise,}\n\\end{cases}\n\\]\n\nwhere $\\rho > \\|\\mathbf X\\|_F^2$ and $\\mu^{\\text{max}} \\gg  \\mu^0$.\n\n\\item Check stopping criteria\n\\[\n\\frac{\\|\\mathbf{XZ^{k+1} - X + E^{k+1}} \\|_F}{\\| \\mathbf X \\|_F} < \\epsilon_1, \\frac{\\|\\mathbf{J^{k+1} - Z^{k+1}R}\\|_F}{\\| \\mathbf X \\|_F} < \\epsilon_1\n\\]\n\\[\n\\mu^k \\sqrt{\\rho} \\frac{ \\textrm{max} ( \\| \\mathbf Z^{k+1} - \\mathbf Z^{k}  \\|_F  , \\|  \\mathbf E^{k+1} - \\mathbf E^{k} \\|, \\| \\mathbf J^{k+1} - \\mathbf J^{k}  \\|_F  , \\|  \\mathbf Z^{k+1} \\mathbf R - \\mathbf Z^{k} \\mathbf R \\|_F)}{\\| \\mathbf X \\|_F}  < \\epsilon_2\n\\]\n\n\\end{enumerate}\n\n\n\n\\newpage\n\\bibliographystyle{plain}\n\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "103385f00c9f0c822a9d3371224ed3cdc75d47e6", "size": 24204, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/SubKit.tex", "max_stars_repo_name": "sjtrny/SubKit", "max_stars_repo_head_hexsha": "d5d8cc55db2b78350f320757e2a8281cf65fcabb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2015-09-14T05:16:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T08:10:26.000Z", "max_issues_repo_path": "docs/SubKit.tex", "max_issues_repo_name": "sjtrny/SubKit", "max_issues_repo_head_hexsha": "d5d8cc55db2b78350f320757e2a8281cf65fcabb", "max_issues_repo_licenses": ["MIT"], "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/SubKit.tex", "max_forks_repo_name": "sjtrny/SubKit", "max_forks_repo_head_hexsha": "d5d8cc55db2b78350f320757e2a8281cf65fcabb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2015-02-01T07:32:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-13T16:31:05.000Z", "avg_line_length": 42.2408376963, "max_line_length": 618, "alphanum_fraction": 0.6386134523, "num_tokens": 9744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6321677832824185}}
{"text": "\\lab{Iterative Solvers}{Iterative Solvers}\n\\label{lab:iter_methods}\n\n\\objective{\nMany real-world problems of the form $A\\x =\\b$ have tens of thousands of parameters.\nSolving such systems with Gaussian elimination or matrix factorizations could require trillions of floating point operations (FLOPs), which is of course infeasible.\nSolutions of large systems must therefore be approximated iteratively.\nIn this lab, we implement three popular iterative methods for solving large systems: Jacobi, Gauss-Seidel, and Successive Over-Relaxation.}\n\n% Though finding an exact solution is either very time intensive or unstable, iterative methods give a sufficiently close approximations and take much less time.\n\nIterative methods are often useful to solve large systems of equations.\nIn this lab, let $\\x^{(k)}$ denote the $k$th iteration of the iterative method for solving the problem $A\\x=\\b$ for $\\x$.\nFurthermore, let $x_{i}$ be the $i$th component of $\\x$ so that $x_{i}^{(k)}$ is the $i$th component of $\\x$ in the $k$th iteration.\nLike other iterative methods, there are two stopping parameters: a very small $\\epsilon > 0$ and an integer $N\\in\\mathbb{N}$.\nIterations continue until either\n\\begin{equation} % Stopping Criteria.\n\\|\\x^{(k-1)}-\\x^{(k)}\\| < \\epsilon\n\\qquad \\text{or} \\qquad\nk > N.\n\\label{eq:itersolve-stopping-criteria}\n\\end{equation}\n\n\\section*{The Jacobi Method} % ================================================\n\nThe \\emph{Jacobi Method} is a simple but powerful method used for solving certain kinds of large linear systems.\nThe main idea is simple: solve for each variable in terms of the others, then use the previous values to update each approximation.\nAs a (very small) example, consider the $3 \\times 3$\n\\begin{align*}\n\\begin{array}{ccccccr}\n  2x_1 &   &      & - & x_3  & = & 3,  \\\\\n  -x_1 & + & 3x_2 & + & 2x_3 & = & 3,  \\\\\n       & + & x_2  & + & 3x_3 & = & -1. \\\\\n\\end{array}\n\\end{align*}\n\nSolving the first equation for $x_1$, the second for $x_2$, and the third for $x_3$ yields\n\\begin{align*}\n\\begin{array}{ccc}\n    x_1 & = & \\frac{1}{2}(3 + x_3), \\\\\n    x_2 & = & \\frac{1}{3}(3 + x_1 - 2x_3), \\\\\n    x_3 & = & \\frac{1}{3}(-1 - x_2).\n\\end{array}\n\\end{align*}\n\nNow begin with an initial guess $\\x^{(0)} = [x^{(0)}_1, x^{(0)}_2, x^{(0)}_3]\\trp = [0,0,0]\\trp$.\nTo compute the first approximation $\\x^{(1)}$, use the entries of $\\x^{(0)}$ as the variables on the right side of the previous equations:\n\\begin{align*}\n\\begin{array}{ccccccr}\n    x^{(1)}_1 & = & \\frac{1}{2}(3 + x^{(0)}_3) & = & \\frac{1}{2} (3 + 0) & = & \\frac{3}{2}, \\\\\n    x^{(1)}_2 & = & \\frac{1}{3}(3 + x^{(0)}_1 - 2x^{(0)}_3) & = & \\frac{1}{3} (3 + 0 - 0) & = & 1, \\\\\n    x^{(1)}_3 & = & \\frac{1}{3}(-1 - x^{(0)}_2) & = & \\frac{1}{3} (-1 - 0) & = & -\\frac{1}{3}. \\\\\n\\end{array}\n\\end{align*}\n\nThus $\\mathbf{x}^{(1)} = [\\frac{3}{2}, 1, -\\frac{1}{3}]\\trp$.\nComputing $\\mathbf{x}^{(2)}$ is similar:\n\\begin{align*}\n\\begin{array}{ccccccc}\nx^{(2)}_1 & = & \\frac{1}{2} ( 3 + x^{(1)}_3)  & = & \\frac{1}{2} (3 - \\frac{1}{3})     & = & \\frac{4}{3}, \\\\\nx^{(2)}_2 & = & \\frac{1}{3} ( 3 + x^{(1)}_1 - 2x^{(1)}_3) & = & \\frac{1}{3} (3 + \\frac{3}{2} + \\frac{2}{3}) & = &  \\frac{31}{18}, \\\\\nx^{(2)}_3 & = & \\frac{1}{3} ( -1 - x^{(1)}_2)       & = & \\frac{1}{3} (-1 - 1)    & = & -\\frac{2}{3}. \\\\\n\\end{array}\n\\end{align*}\n\nThe process is repeated until at least one of the two stopping criteria in (\\ref{eq:itersolve-stopping-criteria}) is met.\nFor this particular problem, convergence to 8 decimal places ($\\epsilon = 10^{-8}$) is reached in 29 iterations.\n\n\\begin{center}\n\\begin{tabular}{c|ccc}\n    & $x^{(k)}_1$ & $x^{(k)}_2$ & $x^{(k)}_3$ \\\\\n    \\hline\n    $\\x^{(0)}$ & $0$ & $0$ & $0$ \\\\\n    %\\hline\n    $\\x^{(1)}$ & $1.5$ & $1$ & $-0.33333333$ \\\\\n    %\\hline\n    $\\x^{(2)}$  & $1.33333333$ & $1.72222222$ & $-0.6666666$7 \\\\\n    $\\x^{(3)}$  & $1.16666667$ & $1.88888889$ & $-0.9074074$1 \\\\\n    $\\x^{(4)}$  & $1.04629630$ & $1.99382716$ & $-0.9629629$6 \\\\\n    \\vdots      & \\vdots       & \\vdots       & \\vdots      \\\\\n    $\\x^{(28)}$ & $0.99999999$ & $2.00000001$ & $-0.9999999$9 \\\\\n    $\\x^{(29)}$ & $1$          & $2$          & $-1$          \\\\\n\\end{tabular}\n\\end{center}\n\n\\subsection*{Matrix Representation} % -----------------------------------------\n\nThe iterative steps performed above can be expressed in matrix form.\nFirst, decompose $A$ into its diagonal entries, its entries below the diagonal, and its entries above the diagonal, as $A = D + L + U$.\n\\begin{align*}\n\\begin{array}{ccccc}\n    \\left[\\begin{array}{cccc}\n        a_{11} & 0 & \\ldots & 0 \\\\\n        0 & a_{22} & \\ldots & 0 \\\\\n        \\vdots & \\vdots & \\ddots & \\vdots \\\\\n        0 & 0 & \\ldots & a_{nn} \\\\\n    \\end{array}\\right]\n    & &\n    \\left[\\begin{array}{cccc}\n    0 & 0 & \\ldots & 0 \\\\\n    a_{21} &  0 & \\ldots & 0\\\\\n     \\vdots & \\ddots & \\ddots & \\vdots \\\\\n    a_{n1} & \\ldots & a_{n,n-1} & 0 \\\\\n    \\end{array}\\right]\n    & &\n    \\left[\\begin{array}{cccc}\n    0 & a_{12} & \\ldots & a_{1n} \\\\\n    0 & 0 & \\ddots & \\vdots \\\\\n     \\vdots & \\vdots & \\ddots & a_{n-1,n} \\\\\n    0 & 0 & \\ldots & 0 \\\\\n    \\end{array}\\right]\n    \\\\D & & L & & U\n\\end{array}\n\\end{align*}\n\nWith this decomposition, $\\x$ can be expressed in the following way.\n\\begin{align*}\nA\\x &= \\b\\\\\n(D + L + U)\\x &= \\b\\\\\nD\\x &= -(L+U)\\x + \\b\\\\\n\\x &= D^{-1}(-(L+U)\\x + \\b)\n\\end{align*}\n\nNow using $\\x^{(k)}$ as the variables on the right side of the equation to produce $\\x^{(k+1)}$ on the left, and noting that $L+U=A-D$, we have the following.\n\\begin{align}\n\\nonumber \\x^{(k+1)} &= D^{-1}(-(A-D)\\x^{(k)} + \\b) \\\\\n\\nonumber &= D^{-1}(D\\x^{(k)} - A\\x^{(k)}  + \\b)\\\\\n&= \\x^{(k)} + D^{-1}(\\b - A\\x^{(k)})\n\\label{eq:jacobi-method}\n\\end{align}\n\nThere is a potential problem with (\\ref{eq:jacobi-method}): calculating a matrix inverse is the cardinal sin of numerical linear algebra, yet the equation contains $D^{-1}$.\nHowever, since $D$ is a diagonal matrix, $D^{-1}$ is also diagonal, and is easy to compute.\n\n\\[\nD^{-1} =\n\\left[\\begin{array}{cccc}\n    \\frac{1}{a_{11}} & 0                & \\ldots & 0      \\\\\n    0                & \\frac{1}{a_{22}} & \\ldots & 0      \\\\\n    \\vdots           & \\vdots           & \\ddots & \\vdots \\\\\n    0                & 0                & \\ldots & \\frac{1}{a_{nn}}\n\\end{array}\\right]\n\\]\nBecause of this, the Jacobi method requires that $A$ have nonzero diagonal entries.\n\nThe diagonal $D$ can be represented by the 1-dimensional array $\\mathbf{d}$ of the diagonal entries. %(instead of as a 2-dimensional array).\nThen the matrix multiplication $D\\x$ is equivalent to the component-wise vector multiplication $\\mathbf{d}*\\x = \\x*\\mathbf{d}$.\nLikewise, the matrix multiplication $D^{-1}\\x$ is equivalent to the component-wise ``vector division'' $\\x/\\mathbf{d}$.\n\n\\begin{comment}% This didn't seem super useful so I took it out.\n\\begin{lstlisting}\n>>> import numpy as np\n\n>>> D = np.array([[2,0],[0,16]])    # Let D be a diagonal matrix.\n>>> d = np.diag(D)                  # Extract the diagonal as a 1-D array.\n>>> x = np.random.random(2)\n>>> np.allclose(D.dot(x), d*x)\n<<True>>\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{comment} % Jacobi algorithm box. Probably unnecessary.\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Jacobi Method}{$A$, $\\b$, $\\epsilon$, $N$}\n    \\State $m, n \\gets \\shape{A}$\n        \\Comment{Store the dimensions of $A$.}\n    \\State $\\mathbf{d} \\gets$ diag($A$)\n        \\Comment{Get the diagonal entries of $A$ with \\li{np.diag()}.}\n    \\State $\\x^{(0)} \\gets \\zeros{n}$\n        \\Comment{An array of $n$ zeros.}\n    \\For{$k=0 \\ldots N-1$}\n        \\State $\\x^{(k+1)} \\gets (\\b - A\\x^{(k)} + \\mathbf{d}*\\x^{(k)})/\\mathbf{d}$\n        \\If{$\\|\\mathbf{x}^{(k-1)} - \\mathbf{x}^{(k)}\\|_{\\infty} < \\epsilon$}\n            \\State \\pseudoli{break}\n        \\EndIf\n    \\EndFor\n    \\State \\pseudoli{return} $\\x^{(k)}$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{}\n\\label{alg:jacobi-method}\n\\end{algorithm}\n\\end{comment}\n\n\\begin{problem} % Implement the Jacobi Method.\nWrite a function that accepts a matrix $A$, a vector $\\b$, a convergence tolerance \\li{tol} defaulting to $10^{-8}$, and a maximum number of iterations \\li{maxiter} defaulting to $100$.\nImplement the Jacobi method using (\\ref{eq:jacobi-method}), returning the approximate solution to the equation $A\\x = \\b$.\n\nRun the iteration until $\\|\\mathbf{x}^{(k-1)} - \\mathbf{x}^{(k)}\\|_{\\infty} <$ \\li{tol}, and only iterate at most \\li{maxiter} times.\nAvoid using \\li{la.inv()} to calculate $D^{-1}$, but use \\li{la.norm()} to calculate the vector $\\infty$-norm.\n\n% \\begin{lstlisting}\n% >>> from scipy import linalg as la\n%\n% >>> x = np.random.random(10)\n% >>> la.norm(x, <<ord>>=np.inf)          # Use la.norm() for ||x||.\n% 0.74623726404168045\n% >>> np.<<max>>(np.<<abs>>(x))               # The equivalent in NumPy for ||x||.\n% 0.74623726404168045\n% \\end{lstlisting}\n\nYour function should be robust enough to accept systems of any size.\nTo test your function, generate a random $\\b$ with \\li{np.random.random()} and use the following function to generate an $n\\times n$ matrix $A$ for which the Jacobi method is guaranteed to converge.\nRun the iteration, then check that $A\\x^{(k)}$ and $\\b$ are close using \\li{np.allclose()}.\n\n\\begin{lstlisting}\ndef diag_dom(n, num_entries=None):\n    \"\"\"Generate a strictly diagonally dominant (n, n) matrix.\n    Parameters:\n        n (int): The dimension of the system.\n        num_entries (int): The number of nonzero values.\n            Defaults to n^(3/2)-n.\n    Returns:\n        A ((n,n) ndarray): A (n, n) strictly diagonally dominant matrix.\n    \"\"\"\n    if num_entries is None:\n        num_entries = int(n**1.5) - n\n    A = np.zeros((n,n))\n    rows = np.random.choice(np.arange(0,n), size=num_entries)\n    cols = np.random.choice(np.arange(0,n), size=num_entries)\n    data = np.random.randint(-4, 4, size=num_entries)\n    for i in range(num_entries):\n        A[rows[i], cols[i]] = data[i]\n    for i in range(n):\n        A[i,i] = np.<<sum>>(np.<<abs>>(A[i])) + 1\n    return A\n\\end{lstlisting}\n\nAlso test your function on random $n \\times n$ matrices.\nIf the iteration is non-convergent, the successive approximations will have increasingly large entries.\n\n\\label{prob:jacobi}\n\\end{problem}\n\n\\subsection*{Convergence} % ---------------------------------------------------\n\nMost iterative methods only converge under certain conditions.\nFor the Jacobi method, convergence mostly depends on the nature of the matrix $A$.\nIf the entries $a_{ij}$ of $A$ satisfy the property\n\\[\n|a_{ii}| > \\sum_{j \\neq i} |a_{ij}|\\quad \\text{for all}\\quad i = 1,2,\\ldots,n,\n\\]\nthen $A$ is called \\emph{strictly diagonally dominant} (\\li{diag_dom()} in Problem \\ref{prob:jacobi} generates a strictly diagonally dominant $n\\times n$ matrix).\nIf this is the case,\\footnote{Although this seems like a strong requirement, most real-world linear systems can be represented by strictly diagonally dominant matrices.} then the Jacobi method always converges, regardless of the initial guess $\\x_0$.\nThis is a very different convergence result than many other iterative methods such as Newton's method where convergence is highly sensitive to the initial guess.\n\nThere are a few ways to determine whether or not an iterative method is converging.\nFor example, since the approximation $\\x^{(k)}$ should satisfy $A\\x^{(k)} \\approx \\b$, the normed difference $\\|A\\x^{(k)} - \\b\\|_\\infty$ should be small.\nThis value is called the \\emph{absolute error} of the approximation.\nIf the iterative method converges, the absolute error should decrease to $\\epsilon$.\n\n\\begin{problem}\nModify your Jacobi method function in the following ways.\n\\begin{enumerate}\n    \\item Add a keyword argument called \\li{plot}, defaulting to \\li{False}.\n    \\item Keep track of the absolute error $\\|A\\mathbf{x}^{(k)} - \\mathbf{b}\\|_{\\infty}$ of the approximation at each iteration.\n    \\item If \\li{plot} is {True}, produce a lin-log plot (use \\li{plt.semilogy()}) of the error against iteration count.\n    Remember to still return the approximate solution $\\x$.\n\\end{enumerate}\nIf the iteration converges, your plot should resemble the following figure.\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/jacobi_convergence.pdf}\n\\end{figure}\n\n\\label{prob:plot-iterative-convergence}\n\\end{problem}\n\n\\section*{The Gauss-Seidel Method} % ==========================================\n\nThe \\emph{Gauss-Seidel method} is essentially a slight modification of the Jacobi method.\nThe main difference is that in Gauss-Seidel, new information is used immediately.\nAs an example, consider again the system from the previous section,\n\\begin{align*}\n\\begin{array}{ccccccr}\n  2x_1 &   &      & - & x_3  & = & 3,  \\\\\n  -x_1 & + & 3x_2 & + & 2x_3 & = & 3,  \\\\\n       & + & x_2  & + & 3x_3 & = & -1. \\\\\n\\end{array}\n\\end{align*}\n\nAs with the Jacobi method, solve for $x_1$ in the first equation, $x_2$ in the second equation, and $x_3$ in the third equation:\n\\begin{align*}\n\\begin{array}{ccc}\n    x_1 & = & \\frac{1}{2}(3 + x_3), \\\\\n    x_2 & = & \\frac{1}{3}(3 + x_1 - 2x_3), \\\\\n    x_3 & = & \\frac{1}{3}(-1 - x_2).\n\\end{array}\n\\end{align*}\nUsing $\\x^{(0)}$ to compute $x^{(1)}_1$ in the first equation as before,\n\\[x^{(1)}_1 = \\frac{1}{2}(3 + x^{(0)}_3) = \\frac{1}{2}(3 + 0) = \\frac{3}{2}.\\]\nNow, however, use the updated value of $x^{(1)}_1$ in the calculation of $x^{(1)}_2$:\n\\[x^{(1)}_2 = \\frac{1}{3}(3 + x^{(1)}_1 - 2x^{(0)}_3) = \\frac{1}{3}(3 + \\frac{3}{2} - 0) = \\frac{3}{2}.\\]\nLikewise, use the updated values of $x^{(1)}_1$ and $x^{(1)}_2$ to calculate $x^{(1)}_3$:\n\\[x^{(1)}_3 = \\frac{1}{3}(-1 - x^{(1)}_2) = \\frac{1}{3}(-1 - \\frac{3}{2}) = -\\frac{5}{6}.\\]\nThis process of using calculated information immediately is called \\emph{forward substitution}, and causes the algorithm to (generally) converge much faster.\n\n\\begin{center}\n\\begin{tabular}{c|ccc}\n    & $x^{(k)}_1$ & $x^{(k)}_2$ & $x^{(k)}_3$ \\\\\n    \\hline\n      $x^{(0)}$ & $0$ & $0$ & $0$ \\\\\n      %\\hline\n      $x^{(1)}$ & $1.5$ & $1.5$ & $-0.83333333$ \\\\\n      %\\hline\n      $x^{(2)}$ & $1.08333333$ & $1.91666667$ & $-0.97222222$ \\\\\n      $x^{(3)}$ & $1.01388889$ & $1.98611111$ & $-0.99537037$ \\\\\n      $x^{(4)}$ & $1.00231481$ & $1.99768519$ & $-0.99922840$ \\\\\n      \\vdots    & \\vdots       & \\vdots       & \\vdots     \\\\\n      $x^{(11)}$ & $1.00000001$ & $1.99999999$ & $-1$ \\\\\n      $x^{(12)}$ & $1$ & $2$ & $-1$ \\\\\n\\end{tabular}\n\\end{center}\nNotice that Gauss-Seidel converges in less than half as many iterations as Jacobi does for this system.\n\n\\subsection*{Implementation} % ------------------------------------------------\n\n% This matches the book (Ch. 13), but it may be confusing to the students here.\n% We begin by solving for $\\x$ in a slightly different way.\n% \\begin{align}\n% \\nonumber A\\x &= \\b\\\\\n% \\nonumber (D + L + U)\\x &= \\b\\\\\n% \\nonumber (D + L)\\x &= -U\\x + \\b\\\\\n% \\x &= -(D + L)^{-1}(U\\x + \\b)\n% \\label{eq:gauss-seidel-method}\n% \\end{align}\n\nBecause Gauss-Seidel updates only one element of the solution vector at a time, the iteration cannot be summarized by a single matrix equation.\nInstead, the process is most generally described by the equation\n\\begin{equation}\n\\label{eq:gauss-seidel-full}\nx^{(k+1)}_i = \\frac{1}{a_{ii}} \\left(b_i - \\sum_{j < i}a_{ij}x^{(k)}_j - \\sum_{j > i}a_{ij}x^{(k)}_j \\right).\n\\end{equation}\n\nLet $\\a_i$ be the $i$th \\textbf{row} of $A$.\nThe two sums closely resemble the regular vector product of $\\a_i$ and $\\x^{(k)}$ without the $i^{\\text{th}}$ term $a_{ii}x^{(k)}_i$.\nThis suggests the simplification\n\\begin{align}\n\\nonumber x^{(k+1)}_i &= \\frac{1}{a_{ii}} \\left(b_i - \\a_i\\trp\\x^{(k)} + a_{ii}x^{(k)}_i \\right)\\\\\n&= x^{(k)}_i + \\frac{1}{a_{ii}}\\left( b_i - \\a_i\\trp\\x^{(k)}\\right).\n\\label{eq:gauss_seidel}\n\\end{align}\nOne sweep through all the entries of $\\x$ completes one iteration.\n\n\\begin{problem} % Implement Gauss-Seidel.\nWrite a function that accepts a matrix $A$, a vector $\\b$, a convergence tolerance \\li{tol} defaulting to $10^{-8}$, a maximum number of iterations \\li{maxiter} defaulting to $100$, and a keyword argument \\li{plot} that defaults to \\li{False}.\nImplement the Gauss-Seidel method using (\\ref{eq:gauss_seidel}), returning the approximate solution to the equation $A\\x = \\b$.\n\nUse the same stopping criterion as in Problem \\ref{prob:jacobi}.\nAlso keep track of the absolute errors of the iteration, as in Problem \\ref{prob:plot-iterative-convergence}.\nIf \\li{plot} is \\li{True}, plot the error against iteration count.\nUse \\li{diag_dom()} to generate test cases.\n\n\\begin{warn} % Arrays are mutable!\nSince the Gauss-Seidel algorithm operates on the approximation vector in place (modifying it one entry at a time), the previous approximation $\\x^{(k-1)}$ must be stored at the beginning of the $k$th iteration in order to calculate $\\|\\x^{(k-1)} - \\x^{(k)}\\|_\\infty$.\nAdditionally, since NumPy arrays are mutable, the past iteration must be stored as a \\textbf{copy}.\n\n\\begin{lstlisting}\n>>> x0 = np.random.random(5)        # Generate a random vector.\n>>> x1 = x0                         # Attempt to make a copy.\n>>> x1[3] = 1000                    # Modify the \"copy\" in place.\n>>> np.allclose(x0, x1)             # But x0 was also changed!\n<<True>>\n\n# Instead, make a copy of x0 when creating x1.\n>>> x0 = np.copy(x1)                # Make a copy.\n>>> x1[3] = -1000\n>>> np.allclose(x0, x1)\n<<False>>\n\\end{lstlisting}\n% It is good practice in most iterative methods to record a copy of $\\x^{(k-1)}$ at the beginning of the $k$th iteration.\n\\end{warn}\n\n\\label{prob:gauss_seidel}\n\\end{problem}\n\n\\subsection*{Convergence} % ---------------------------------------------------\n\nWhether or not the Gauss-Seidel method converges depends on the nature of $A$.\nIf all of the eigenvalues of $A$ are positive, $A$ is called \\emph{positive definite}.\nIf $A$ is positive definite \\emph{or} if it is strictly diagonally dominant, then the Gauss-Seidel method converges regardless of the initial guess $\\x^{(0)}$.\n\n\\begin{comment} % This problem does not give good results.\n\\begin{problem} % Sparse implementation of Gauss Seidel.\nThe Gauss-Seidel method is faster than the standard system solver used by SciPy's \\li{la.solve()} if the system is sufficiently large and sufficiently sparse.\nFor $n=5,6,\\ldots,11$, generate a random $2^n \\times 2^n$ matrix $A$ using \\li{diag_dom()} and a random $2^n$ vector $\\b$.\nTime how long it takes to solve $A\\x = \\b$ using your Gauss-Seidel function from Problem \\ref{prob:gauss_seidel}, and how long it takes to solve using \\li{la.solve()}.\nMake a log-log plot of the times against the system size.\n\\end{problem}\n\\end{comment}\n\n\\section*{Solving Sparse Systems Iteratively} % ===============================\n\nIterative solvers are best suited for solving very large sparse systems.\nHowever, using the Gauss-Seidel method on sparse matrices requires translating code from NumPy to \\li{scipy.sparse}.\nThe algorithm is the same, but there are some functions that are named differently between these two packages.%\n\\footnote{See the lab on Linear Systems for a review of \\lif{scipy.sparse} matrices and syntax.}\n\n\\begin{problem} % Gauss-Seidel with Sparse matrices.\nWrite a new function that accepts a \\textbf{sparse} matrix $A$, a vector $\\b$, a convergence tolerance \\li{tol}, and a maximum number of iterations \\li{maxiter} (plotting the convergence is not required for this problem).\nImplement the Gauss-Seidel method using (\\ref{eq:gauss_seidel}), returning the approximate solution to the equation $A\\x = \\b$.\nUse the usual default stopping criterion.\n\nThe Gauss-Seidel method requires extracting the rows $A_i$ from the matrix $A$ and computing $A_i\\trp\\x$.\nThere are many ways to do this that cause some fairly serious runtime issues, so we provide the code for this specific portion of the algorithm.\n\n\\begin{lstlisting}\n# Get the indices of where the i-th row of A starts and ends if the\n# nonzero entries of A were flattened.\nrowstart = A.indptr[i]\nrowend = A.indptr[i+1]\n\n# Multiply only the nonzero elements of the i-th row of A with the\n# corresponding elements of x.\nAix = A.data[rowstart:rowend] @ x[A.indices[rowstart:rowend]]\n\\end{lstlisting}\n\nTo test your function, cast the result of \\li{diag_dom()} as a sparse matrix.\n\n\\begin{lstlisting}\n>>> from scipy import sparse\n\n>>> A = sparse.csr_matrix(diag_dom(50000))\n>>> b = np.random.random(50000)\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Successive Over-Relaxation} % ------------------------------------\n\nThere are many systems that meet the requirements for convergence with the Gauss-Seidel method, but for which convergence is still relatively slow.\nA slightly altered version of the Gauss-Seidel method, called \\emph{Successive Over-Relaxation} (SOR), can result in faster convergence.\nThis is achieved by introducing a \\emph{relaxation factor} $\\omega \\ge 1$ and modifying (\\ref{eq:gauss-seidel-full}) as\n\\[\nx^{(k+1)}_i = (1-\\omega)x^{(k)}_i + \\frac{\\omega}{a_{ii}} \\left(b_i - \\sum_{j < i}a_{ij}x^{(k)}_j - \\sum_{j > i}a_{ij}x^{(k)}_j \\right).\n\\]\nSimplifying the equation, we have\n\\begin{equation}\nx^{(k+1)}_i = x^{(k)}_i + \\frac{\\omega}{a_{ii}}\\left(b_i - \\a_i\\trp\\x^{(k)}\\right).\n\\label{eq:sor}\n\\end{equation}\nNote that when $\\omega = 1$, SOR reduces to Gauss-Seidel.\nThe relaxation factor $\\omega$ weights the new iteration between the current best approximation and the next approximation in a way that can sometimes dramatically improve convergence.\n\n\\begin{problem} % SOR\nWrite a function that accepts a sparse matrix $A$, a vector $\\b$, a relaxation factor $\\omega$, a convergence tolerance \\li{tol}, and a maximum number of iterations \\li{maxiter}.\nImplement SOR using (\\ref{eq:sor}), compute the approximate solution to the equation $A\\x = \\b$.\nUse the usual stopping criterion.\nReturn the approximate solution $\\x$ as well as a boolean indicating whether the function converged and the number of iterations computed.\n\\\\ (Hint: this requires changing only one line of code from the sparse Gauss-Seidel function.)\n\\label{prob:sor}\n\\end{problem}\n\n\\section*{A Finite Difference Method} % =======================================\n\n\\emph{Laplace's equation} is an important partial differential equation that arises often in both pure and applied mathematics.\nIn two dimensions, the equation has the following form.\n\\begin{equation}\n\\frac{\\partial^2 u}{\\partial x^2} + \\frac{\\partial^2 u}{\\partial y^2} = 0\n\\label{eq:laplaces-equation}\n\\end{equation}\n\nLaplace's equation can be used to model heat flow.\nConsider a square metal plate where the top and bottom borders are fixed at $0^\\circ$ Celsius and the left and right sides are fixed at $100^\\circ$ Celsius.\nGiven these boundary conditions, we want to describe how heat diffuses through the rest of the plate.\nThe solution to Laplace's equation describes the plate when it is in a \\emph{steady state}, meaning that the heat at a given part of the plate no longer changes with time.\n\nIt is possible to solve (\\ref{eq:laplaces-equation}) analytically.\nHowever, the problem can also be solved numerically using a \\emph{finite difference method}.\nTo begin, we impose a discrete, square grid on the plate with uniform spacing.\n% (see Figure \\ref{fig:itersolve-finite-difference-grid}).\nDenote the points on the grid by $(x_i,y_j)$ and the value of $u$ at these points (the heat) as $u(x_i,y_j) = U_{i,j}$.\nUsing the centered difference quotient for second derivatives to approximate the partial derivatives,\n%\n\\begin{align}\n\\nonumber 0 &= \\frac{\\partial^2 u}{\\partial x^2}+ \\frac{\\partial^2 u}{\\partial y^2}\\\\\n\\nonumber &\\approx \\frac{U_{i+1,j}-2U_{i,j}+U_{i-1,j}}{h^2} + \\frac{U_{i,j+1}-2U_{i,j}+U_{i,j-1}}{h^2}\\\\\n&= \\frac{1}{h^2}\\left(-4U_{i,j} + U_{i+1,j} + U_{i-1,j} + U_{i,j+1} +  U_{i,j-1}\\right),\n\\label{eq:laplace-finite-diff}\n\\end{align}\nwhere $h = x_{i+1} - x_i = y_{j+1} - y_j$ is the distance between the grid points in either direction.\n%\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}\n\\begin{scope}[xshift=-3cm]\n\\foreach \\x/\\y in {-1.2/0,-.4/0,.4/0,1.2/0,-1.2/-.8,-.4/-.8,.4/-.8,1.2/-.8,-1.2/-1.6,-.4/-1.6,.4/-1.6,1.2/-1.6,-1.2/-2.4,-.4/-2.4,.4/-2.4,1.2/-2.4} \\draw (\\x,\\y) circle (3pt);\n\\foreach \\x/\\y/\\c in {-1.2/.8/blue,-.4/.8/blue,.4/.8/blue,1.2/.8/blue,-1.2/-3.2/blue,-.4/-3.2/blue,.4/-3.2/blue,1.2/-3.2/blue,-2/0/red,-2/-.8/red,-2/-1.6/red,-2/-2.4/red,2/0/red,2/-.8/red,2/-1.6/red,2/-2.4/red} \\filldraw[\\c] (\\x,\\y) circle (3pt);\n\\end{scope}\n\\begin{scope}[xshift=3cm]\n\\foreach \\x/\\y in {-1.2/0,-.4/0,.4/0,1.2/0,-1.2/-.8,-.4/-.8,.4/-.8,1.2/-.8,-1.2/-1.6,-.4/-1.6,1.2/-1.6,-1.2/-2.4} \\draw (\\x,\\y) circle (3pt);\n\\foreach \\x/\\y/\\c in {-1.2/.8/blue,-.4/.8/blue,.4/.8/blue,1.2/.8/blue,-1.2/-3.2/blue,-.4/-3.2/blue,1.2/-3.2/blue,-2/0/red,-2/-.8/red,-2/-1.6/red,-2/-2.4/red,2/0/red,2/-.8/red,2/-1.6/red,2/-2.4/red} \\filldraw[\\c] (\\x,\\y) circle (3pt);\n\\foreach \\x/\\y/\\c/\\i in {.4/-1.6/green/1,-.4/-2.4/green/2,.4/-2.4/black/3,1.2/-2.4/green/4,.4/-3.2/green/5} \\node[circle,draw,fill=\\c,inner sep=2.25pt] (\\i) at (\\x,\\y) {};\n\\foreach \\a in {1,2,4,5} \\draw[->,>=stealth',thick] (\\a) -- (3);\n\\end{scope}\n\\end{tikzpicture}\n\\caption{On the left, an example of a $6\\times 6$ grid ($n=4$) where the red dots are hot boundary zones and the blue dots are cold boundary zones.\nOn the right, the green dots are the neighbors of the interior black dot that are used to approximate the heat at the black dot.}\n\\label{fig:itersolve-finite-difference-grid}\n\\end{figure}\n%\nThis problem can be formulated as a linear system.\nSuppose the grid has exactly $(n+2)\\times (n+2)$ entries.\nThen the interior of the grid (where $u(x,y)$ is unknown) is $n\\times n$, and can be flattened into an $n^2\\times 1$ vector $\\u$.\nThe entire first row goes first, then the second row, proceeding to the $n$th row.\n\\[\\u = \\begin{bmatrix}U_{1,1} & U_{1,2} & \\cdots & U_{1,n} & U_{2,1} & U_{2,2} & \\cdots & U_{2,n} & \\cdots & U_{n,n}\\end{bmatrix}\\trp\\]\nFrom (\\ref{eq:laplace-finite-diff}), for an interior point $U_{i,j}$, we have\n\\begin{equation}\n-4U_{i,j} + U_{i+1,j} + U_{i-1,j} + U_{i,j+1} +  U_{i,j-1} = 0.\n\\label{eq:hot-plate}\n\\end{equation}\nIf any of the neighbors to $U_{i,j}$ is a boundary point on the grid, its value is already determined by the boundary conditions.\nFor example, the neighbor $U_{3,0}$ of the gridpoint for $U_{3,1}$ is fixed at $U_{3,0} = 100$.\nIn this case, (\\ref{eq:hot-plate}) becomes\n\\[\n-4U_{3,1} + U_{2,1} + U_{3,2} + U_{4,1} = -100.\n\\]\nThe constants on the right side of (\\ref{eq:hot-plate}) become the $n^2\\times 1$ vector $\\b$.\nAll nonzero entries of $\\b$ correspond to interior points that touch the left or right boundaries.\n\nAs an example, writing (\\ref{eq:hot-plate}) for the $16$ interior points of the grid in Figure \\ref{fig:itersolve-finite-difference-grid} results in the following $16 \\times 16$ system $A\\u = \\b$.\nNote the block structure (empty blocks are all zeros).\n\\footnotesize\n\\begin{align*}\n\\left[\\begin{array}{cccc|cccc|cccc|cccc}\n\\arrayrulecolor{lightgray}\n-4 & 1 & 0 & 0 & 1 & 0 & 0 & 0 &   &   &   &   &   &   &   &  \\\\\n1 & -4 & 1 & 0 & 0 & 1 & 0 & 0 &   &   &   &   &   &   &   &  \\\\\n0 & 1 & -4 & 0 & 0 & 0 & 1 & 0 &   &   &   &   &   &   &   &  \\\\\n0 & 0 & 1 & -4 & 0 & 0 & 0 & 1 &   &   &   &   &   &   &   &  \\\\ \\hline\n1 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 1 & 0 & 0 & 0 &   &   &   &  \\\\\n0 & 1 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 & 0 & 0 &   &   &   &  \\\\\n0 & 0 & 1 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 & 0 &   &   &   &  \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 1 & -4 & 0 & 0 & 0 & 1 &   &   &   &  \\\\ \\hline\n  &   &   &   & 1 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 1 & 0 & 0 & 0\\\\\n  &   &   &   & 0 & 1 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 & 0 & 0\\\\\n  &   &   &   & 0 & 0 & 1 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 & 0\\\\\n  &   &   &   & 0 & 0 & 0 & 1 & 0 & 0 & 1 & -4 & 0 & 0 & 0 & 1\\\\ \\hline\n  &   &   &   &   &   &   &   & 1 & 0 & 0 & 0 & -4 & 1 & 0 & 0\\\\\n  &   &   &   &   &   &   &   & 0 & 1 & 0 & 0 & 1 & -4 & 1 & 0\\\\\n  &   &   &   &   &   &   &   & 0 & 0 & 1 & 0 & 0 & 1 & -4 & 1\\\\\n  &   &   &   &   &   &   &   & 0 & 0 & 0 & 1 & 0 & 0 & 1 & -4\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nU_{1,1} \\\\ U_{1,2} \\\\ U_{1,3} \\\\ U_{1,4}\\\\\nU_{2,1} \\\\ U_{2,2} \\\\ U_{2,3} \\\\ U_{2,4}\\\\\nU_{3,1} \\\\ U_{3,2} \\\\ U_{3,3} \\\\ U_{3,4}\\\\\nU_{4,1} \\\\ U_{4,2} \\\\ U_{4,3} \\\\ U_{4,4}\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\n\\arrayrulecolor{lightgray}\n-100 \\\\ 0 \\\\ 0 \\\\ -100 \\\\ \\hline\n-100 \\\\ 0 \\\\ 0 \\\\ -100 \\\\ \\hline\n-100 \\\\ 0 \\\\ 0 \\\\ -100 \\\\ \\hline\n-100 \\\\ 0 \\\\ 0 \\\\ -100\n\\end{array}\\right]\n\\end{align*}\n\\normalsize\nMore concisely, for any positive integer $n$, the matrix $A$ can be written as\n\\begin{align*}\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\\quad\n\\text{where}\\ B = \\left[\\begin{array}{ccccc}\n-4 &  1 &        &        &    \\\\\n 1 & -4 &  1     &        &    \\\\\n   &  1 & \\ddots & \\ddots &    \\\\\n   &    & \\ddots & \\ddots & 1  \\\\\n   &    &        &    1   & -4\n\\end{array}\\right]\n\\ \\text{is}\\ n\\times n.\n\\end{align*}\n% Each $B$ is $n\\times n$ and A is consequently $n^2 \\times n^2$.\n\n\\begin{problem}\nWrite a function that accepts an integer $n$, a relaxation factor $\\omega$, a convergence tolerance \\li{tol} that defaults to $10^{-8}$, a maximum number of iterations \\li{maxiter} that defaults to $100$, and a bool \\li{plot} that defaults to \\li{False}.\nGenerate and solve the corresponding system $A\\u = \\b$ using Problem \\ref{prob:sor}.\nAlso return a boolean indicating whether the function converged and the number of iterations computed.\n\\\\ (Hint: see Problem 5 of the Linear Systems lab for the construction of $A$.\nAlso, \\li{np.tile()} may be useful for constructing $\\b$.)\n\nIf \\li{plot=True}, visualize the solution $\\u$ with a heatmap using \\li{plt.pcolormesh()} (the colormap \\li{\"coolwarm\"} is a good choice in this case).\nThis shows the distribution of heat over the hot plate after it has reached its steady state.\nNote that the $\\u$ must be reshaped as an $n\\times n$ array to properly visualize the result.\n\\label{prob:finite-difference-setup}\n\\end{problem}\n\n\\begin{problem}\nTo demonstrate how convergence is affected by the value of the relaxation factor $\\omega$ in SOR, run your function from Problem \\ref{prob:finite-difference-setup} with $\\omega = 1,\\ 1.05,\\ 1.1,\\ \\dots , 1.9, 1.95$ and $n = 20$.\nPlot the number of computed iterations as a function of $\\omega$.\nReturn the value of $\\omega$ that results in the least number of iterations.\n\nNote that the matrix $A$ from Problem \\ref{prob:finite-difference-setup} is not strictly diagonally dominant.\nHowever, $A$ is positive definite, so the algorithm will converge.\nUnfortunately, convergence for these kinds of systems usually requires more iterations than for strictly diagonally dominant systems.\nTherefore, set \\li{tol=1e-2} and \\li{maxiter=1000}.\n\nRecall that $\\omega = 1$ corresponds to the Gauss-Seidel method.\nChoosing a more optimal relaxation factor saves a large number of iterations.\nThis could translate to saving days or weeks of computation time while solving extremely large linear systems on a supercomputer.\n\\end{problem}\n\n\\begin{comment}\nThe following code generates a heatmap to help you visualize the steady-state heat flow across the interior of the plate:\n\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\nimport numpy as np\n\nn = 100\nA,b = finite_difference(n)\nx = sparse_sor(A,b,1.9,maxiter=10000,tol=10**-2)\nU = x.reshape((n,n))\nx,y = np.linspace(0,10,n), np.linspace(0,10,n)\nX,Y = np.meshgrid(x,y)\n\nplt.pcolormesh(X,Y,U,cmap='coolwarm')\nplt.show()\n\\end{lstlisting}\n\\end{comment}\n\n%\\newpage\n\n%\\section*{Additional Material} % =============================================\n\n% END OF LAB ==================================================================\n\n\\begin{comment} % Migrated from NumPy lab. vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\\begin{algorithm} % Laplace's equation procedure.\n\\begin{algorithmic}[1]\n\\Procedure{Jacobi}{$n$, tol}\n\\State $U \\gets$ an $n\\times n$ array of zeros.\n\\State Set the boundaries of $U$.\n\\State $U^\\prime \\gets$ a copy of $U$.\n\\State diff $\\gets$ tol\n\\While {diff $\\ge$ tol}\n    \\State Set all interior points of $U^\\prime$ equal to the average of their neighbors.\n    \\State diff $\\gets$ the maximum of the absolute value of $U - U^\\prime$.\n    \\State Interior of $U \\gets$ interior of $U^\\prime $.\n\\EndWhile\n\\State \\pseudoli{return} $U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Jacobi method for solving Laplace's equation.}\n\\label{alg:jacobi}\n\\end{algorithm}\n\n\\begin{problem}\nLaplace's equation is used to model steady-state heat flow on a square plate.\nThe plate can be approximated by a matrix, where each entry of the matrix represents the average temperature over a small square portion of the plate.\nSuppose the plate starts at $0^\\circ$ Celsius everywhere except on the east and west boundaries, which are held at a constant temperature of $100^\\circ$.\nIn addition, the north and south boundaries are held constant at $0^\\circ$.\n\n\\[\nU = \\left[\\begin{array}{ccccc}\n\\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}\\cdots & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0\\\\\n\\textcolor[rgb]{1.,0.,0.}{100} & 0 & \\cdots & 0 & \\textcolor[rgb]{1.,0.,0.}{100}\\\\\n\\textcolor[rgb]{1.,0.,0.}\\vdots & \\vdots & \\ddots & \\vdots & \\textcolor[rgb]{1.,0.,0.}\\vdots \\\\\n\\textcolor[rgb]{1.,0.,0.}{100} & 0 & \\cdots & 0 & \\textcolor[rgb]{1.,0.,0.}{100}\\\\\n\\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}\\cdots & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0\\\\\n\n\\end{array}\\right]\n\\]\n\nThe non-boundary, interior portion of the matrix (with black text) can be accessed with the slice \\li{U[1:-1,1:-1]}.\nTo find the steady state of the hot plate, set each entry of the interior of $U$ equal to the average of its 4 immediate neighbors (the entries above, below, and to the left and right).\nThis step should take only \\emph{one line} and should be based entirely on array slicing.\n\nContinue updating the interior entries of $U$ until they stop changing significantly.\nThe entire procedure is summarized in Algorithm \\ref{alg:jacobi}.\n\nHint: The slice \\li{U[:-2,1:-1]} references the upper neighbors of the interior points of $U$ and \\li{U[1:-1,2:]} references the right neighbors. How can you reference the lower and left neighbors?\n\nUse the following code to visualize your results.\n%% This does 3D visualization, but it's easier (and better) as a heat map.\n% from mpl_toolkits.mplot3d import Axes 3D\n\n%     x, y = np.linspace(0, 1, n), np.linspace(0, 1, n)\n%     X, Y = np.meshgrid(x, y)\n%     fig = plt.figure()\n%     ax = fig.gca(projection='3d')\n%     ax.plot_surface(X, Y, U, rstride=5)\n%     plt.show()\n\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\n\ndef jacobi(n=100, tol=1e-8):\n\n    # Perform the algorithm, storing the result in the array 'U'.\n\n    # Visualize the results.\n    plt.imshow(U)\n    plt.show()\n\\end{lstlisting}\n\nThis Jacobi iteration is a \\emph{finite difference method}, and is similar to many of the methods that we will use to find numerical solutions to differential equations in Volume 4.\n\\end{problem}\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/jacobi_small.pdf}\n    \\caption{$10\\times 10$ approximation.}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/jacobi_big.pdf}\n    \\caption{$100\\times 100$ approximation.}\n\\end{subfigure}\n\\caption{Hot plates in steady state with different resolutions.}\n\\end{figure}\n\\end{comment} % Used to be in NumPy ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", "meta": {"hexsha": "f4961cfa7c91a6b832389159cf33c8a9e0eea1dc", "size": 35538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/IterativeSolvers/IterativeSolvers.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/IterativeSolvers/IterativeSolvers.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/IterativeSolvers/IterativeSolvers.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": 49.2898751734, "max_line_length": 267, "alphanum_fraction": 0.631943272, "num_tokens": 11994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6321510458698246}}
{"text": "% corrected VD 80\n\n\\subsubsection{Gated Recurrent Unit}~\\\\\n\nIdentical to LSTM units, the gated recurrent unit (GRU) consists of gated units\nwhich control the flow of information through the unit, although without having\na dedicated memory cell. Compared to LSTM units, GRUs don't have an output gate.\nThe output gate controls the amount of memory content seen by the other units in\nthe network. Thus GRU exposes its entire content without\ncontrol.~\\cite{DBLP:journals/corr/ChungGCB14}\\\\\n\nThe activation of a GRU unit is computed with:\n\\begin{equation}\n  h_t = (1-z_t)h_{t-1} + z_t\\tilde{h}_t\n\\end{equation}\nwith an update gate $z_t$ which decides how much the unit updates its content.\nIts content consists of the previous activation $h_{t-1}$ and the candidate\nactivation $\\tilde{h}_t$. The update gate is given by the equation:\n\\begin{equation}\n  z_t=\\sigma(W_z x_t+U_z h_{t-1}) \n\\end{equation}\nThis update gate is similar to the one used by LSTM. However, it exposes its\nstate each time step since it does not have a procedure to control how the state\nis exposed. The candidate activation is given by:\n\\begin{equation}\n  \\tilde{h}_t=\\tanh(Wx_t+U(r_t\\odot h_{t-1}))\n\\end{equation}\nwhere $r_t$ is a reset gate and is computed comparably to the update gate:\n\\begin{equation}\n  r_t=\\sigma(W_r x_t+U_r h_{t-1})\n\\end{equation}\n\nSee the illustration of a GRU unit in Figure~\\ref{grucell}.\n\n\\input{sections/scientific/fr2/grucell.tex}\n", "meta": {"hexsha": "8a1ddbc5ed1678fe33a4ff7fec651751bd832acd", "size": 1430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/scientific/fr2/gru.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/gru.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/gru.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": 39.7222222222, "max_line_length": 80, "alphanum_fraction": 0.7629370629, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6321510258066607}}
{"text": "%\r\n%\r\n\r\n\\chapter{Numerical solution of Markov models}  \\label{SEC:Numerical}\r\n\r\n\\RELEASE{This chapter is still under revision.\r\nMore information can be obtained from the examples in\r\nChapter \\ref{SEC:Examples} and from the various input files provided\r\nwith the {\\smart} distribution.}\r\n\r\n\r\nIn this chapter, we consider systems whose underlying\r\nstochastic process has a finite state space, and whose study can be carried\r\non through numerical methods.\r\nBefore describing the features implemented in {\\smart} to solve such processes,\r\nwe discuss briefly a few key background notions in stochastic processes and\r\nnumerical linear algebra.\r\n\r\n%        ===========================\r\n\\section{Discrete time Markov chains}\r\n%        ===========================\r\nA \\index{discrete-time Markov chain (DTMC)}discrete-time Markov chain (DTMC)\r\nis completely described by its transition\r\nprobability matrix $\\P$ and its initial probability vector $\\vp^{(0)}$,\r\nwhere $\\P[i,j]$ defines the probability\r\nthat a system in state $i$ will be in state $j$ at the next time step, and\r\n$\\vp^{(t)}[i]$ is the probability that the system is in state\r\n$i$ at time $t \\in \\Naturals$.\r\nOnce $\\P$ and $\\vp^{(0)}$ have been specified explicitly or constructed from a\r\nhigher-level model, the following types of analysis are possible.\r\nThe interested reader is referred to \\cite{Ross2003book} for more details.\r\n\r\n%           =========================================\r\n\\subsection{Instantaneous transient analysis of DTMCs}\\label{SEC:powerDTMC}\r\n%           =========================================\r\nThe probability of being in state $j$ at time step $t \\in \\Naturals$\r\nhaving started in state $i$ at time $0$ is the $(i,j)$-entry of\r\nthe $t\\SUPTH$ power of the transition probability matrix, $\\P^t[i,j]$.\r\nHowever, powers of matrix $\\P$ cannot be computed or stored in practice\r\ndue to the size of $\\P$.\r\nThus, we make use of the knowledge of the initial probability vector\r\nand compute instead the probability vector at time step $t$,\r\n$\\vp^{(t)} = \\vp^{(0)} \\cdot \\P^t$, using the recursive relation\r\n\\[\r\n  \\vp^{(t+1)} = \\vp^{(t)} \\cdot \\P.\r\n\\]\r\n\r\n%           ======================================\r\n\\subsection{Cumulative transient analysis of DTMCs}\r\n%           ======================================\r\nIf we are interested in the total time spent in each state during the first\r\n$t \\in \\Naturals$ time steps, we compute\r\n\\[\r\n   \\vn^{(t)} = \\sum_{y=0}^{t-1} \\vp^{(y)}\r\n\\]\r\nwhere $\\vn^{(t)}[i]$ is the expected amount of time spent in state $i$\r\nuntil time step $t$.\r\n\r\n%           ==========================================\r\n\\subsection{Instantaneous stationary analysis of DTMCs}\r\n%           ==========================================\r\nAssuming that the DTMC is aperiodic\\footnote{ The \\emph{period} of\r\na state $i$ is the greatest common divisor of all time steps $t$\r\nsuch that the probability of returning to state $i$ in $t$ time\r\nsteps, $\\P^t[i,i]$, is nonzero. If a state has period greater than\r\none, it is said to be \\index{periodic Markov chain}\\emph{periodic},\r\notherwise it is \\index{aperiodic Markov chain}\\emph{aperiodic}.\r\nThe DTMC is aperiodic if all of its states are\r\naperiodic.}, {\\smart} can compute the ``long-term'' probability of\r\nbeing in each state. The method used in practice to compute the\r\n\\index{stationary probability distribution}stationary probability vector\r\n$\\vp = \\lim_{t \\to\\infty} \\vp^{(t)}$\r\ndepends on the properties of the DTMC.\r\n\r\n\\subsubsection*{Ergodic DTMCs}\r\n\r\n\\index{ergodic Markov chain}Ergodic DTMCs converge to a\r\n\\index{stationary probability distribution}stationary (invariant) probability distribution\r\nindependent of the initial state.  This is the case when a finite-state DTMC is aperiodic and\r\n\\index{irreducible Markov chain}irreducible\\footnote{ A\r\nMarkov chain is irreducible if there is a path between every pair\r\nof states.}.  Irreducibility on a finite state space\r\nimplies positive recurrence, which is necessary for a limiting distribution to exist.\r\nThen, the stationary probability distribution (vector\r\n$\\vp$) uniquely satisfies $\\vp = \\vp \\cdot \\P$,\r\n$\\sum_{i}\\vp[i]=1$.  The solution $\\vp$ is strictly positive and\r\n$\\vp = \\lim_{t \\to\\infty} \\vp^{(t)}$.  In this case, {\\smart} computes\r\n$\\vp$ by solving the homogeneous linear system\r\n\\begin{equation}\r\n  \\vp \\cdot (\\P - \\I) = \\0 \\ \\mbox{ subject to }\\ \\sum_{i}\\vp[i]=1.\r\n  \\label{LS:ergDTMC}\r\n\\end{equation}\r\n\r\n\\subsubsection{\\index{absorbing Markov chain}Absorbing DTMCs}\r\n\r\nIf the DTMC consists exclusively of transient and absorbing\\footnote{\r\nA state $i$ is \\emph{transient} if there exists a state $j$ reachable from $i$\r\nsuch that $i$ is not reachable from $j$.\r\nA state $i$ is \\emph{absorbing} if no other state is reachable from it,\r\nthat is, $\\P[i,i] = 1$.\r\n} states, we need to compute the\r\n\\index{stationary probability distribution}stationary probabilities only\r\nfor the absorbing states, since the transient states have zero probability.\r\nHowever, these probabilities depend on the initial probability vector\r\n$\\vp^{(0)}$ in general.\r\nDenoting the sets of absorbing and transient states by\r\n$\\aset$ and $\\tset$, respectively, {\\smart} computes $\\vp$ as\r\n\\begin{eqnarray*}\r\n \\vp[\\Set{A}] \r\n & = & \r\n \\vp^{(0)}[\\Set{A}] + \\vn[\\Set{T}] \\cdot \\P[\\Set{T}, \\Set{A}]\r\n \\\\\r\n \\vp[\\Set{T}] \r\n & = &\r\n \\0\r\n\\end{eqnarray*}\r\nwhere $\\vn[\\Set{T}]$ is described in Sec.~\\ref{SEC:fundamental}.\r\n\r\n\r\n\\subsubsection{Arbitrary aperiodic DTMCs}\r\n\r\nIn the general case, we only require that all states of the DTMC are\r\n\\index{aperiodic Markov chain}aperiodic.\r\nThe DTMC can consist of transient states and classes of\r\nrecurrent (mutually reachable) states, and can be seen as an\r\n\\index{absorbing Markov chain}absorbing DTMC where\r\neach absorbing state is replaced by an \\index{ergodic Markov chain}ergodic DTMC.\r\nThe \\index{stationary probability distribution}stationary probability vector $\\vp$\r\nis then computed by first computing the stationary probability vectors of each\r\n\\index{ergodic}ergodic class in isolation,\r\nthen computing the probability of being absorbed in each ergodic class, and\r\nfinally combining the stationary probability vectors of each ergodic class\r\nusing the absorption probabilities as weights (of course, the probability\r\nof transient states is zero in this case as well).\r\n\r\n\\subsubsection{Periodic DTMCs}\r\n\r\nFor \\index{periodic Markov chain}periodic DTMCs with period $\\delta > 1$, $\\P^t[i, j]$ does not\r\nhave a limit as $t\\to\\infty$ except for $\\P^t[i, j]\\to 0$ when all\r\nstate are null.  However, the limits of $\\P^{t\\delta+u}[i, j]$\r\nexist as $t\\to\\infty$ but depend on the initial state $i$.\r\nAlthough there exists a unique solution satisfying $$\\vp = \\vp\r\n\\cdot \\P,\\quad \\sum_{i}\\vp[i]=\\delta,$$ {\\smart} does not check\r\nexplicitly that the DTMC is periodic, much less compute the\r\nperiod $\\delta$ needed to find the solution. Nevertheless,\r\nnumerical methods might still give the correct answer, but in a\r\ntime-averaged sense: the computed vector $\\vp$ satisfies $\\vp =\r\n\\lim_{t \\to\\infty} \\vn^{(t)}/t$.\r\n\r\nIf the (iterative) solution methods are unable to compute a\r\nsolution, it is simply because convergence was not obtained within\r\nthe maximum number of iterations allowed, and a warning is issued\r\nin this case.  In other words, periodicity does not lead to\r\nincorrect answers in {\\smart}.\r\n\r\n\r\n%           =======================================\r\n\\subsection{Cumulative stationary analysis of DTMCs}\\label{SEC:fundamental}\r\n%           =======================================\r\nWe can also consider the (expected) total time spent in each state\r\nby computing the vector $\\vn = \\lim_{t \\to\\infty} \\vn^{(t)}$. Of\r\ncourse, $\\vn[i] = \\infty$ for any state $i$ with a positive\r\n\\index{stationary probability distribution}stationary probability,\r\nthus the entries in $\\vn$ are meaningful\r\nonly for the transient states. In this case, $\\vn[i]$ is the\r\nexpected time spent in transient state $i$ before the DTMC reaches\r\nan absorbing state, or a class of \\index{ergodic}ergodic states. The portion of\r\n$\\vn$ corresponding to the transient states is the solution of the\r\nnon-homogeneous linear system\r\n\\begin{equation}\r\n  \\vn[\\Set{T}] \\cdot (\\P[\\Set{T}, \\Set{T}] - \\I)\r\n  = -\\vp^{(0)}[\\Set{T}]\r\n  \\label{LS:absDTMC}\r\n\\end{equation}\r\nwhere $\\P[\\Set{T}, \\Set{T}]$ is the submatrix of $\\P$\r\ncorresponding to transitions between transient states.\r\n\r\n%        =============================\r\n\\section{Continuous time Markov chains}\r\n%        =============================\r\nA \\index{continuous-time Markov chain (CTMC)}continuous-time Markov chain (CTMC)\r\nis completely described by its transition\r\nrate matrix $\\R$ and its initial probability vector\r\n$\\gvect{\\pi}^{(0)}$, where $\\R[i,j]$ defines the rate of going to state\r\n$j$ given that the chain is in state $i$, and\r\n$\\gvect{\\pi}^{(t)}[i]$ is the probability that the system is\r\nin state $i$ at time $t \\geq 0$.\r\nA transition from a state to itself is meaningless in a CTMC,\r\nthus, the diagonal elements of $\\R$ are zero.\r\nThe infinitesimal generator matrix, $\\Q$, is identical to the matrix $\\R$\r\nexcept for the diagonal elements, which are set so that each row of\r\n$\\Q$ sums to zero: $\\Q[i,i] = - \\sum_{j \\neq i} \\R[i,j]$.\r\nOnce $\\Q$ (or $\\R$) and $\\gvect{\\pi}^{(0)}$ have been specified explicitly\r\nor constructed from a higher-level model, the following types of analysis\r\nare possible.\r\nThe interested reader is referred to \\cite{1993IMA-SRNs,Stewart1994book}\r\nfor more details.\r\n\r\n%           =========================================\r\n\\subsection{Instantaneous transient analysis of CTMCs}\\label{SEC:inst-trans-anal-CTMC}\r\n%           =========================================\r\nTo compute $\\gvect{\\pi}(t)$, the probability vector at time $t$, we use a\r\ntechnique called \\index{uniformization (randomization)}\\emph{uniformization}\r\n(or \\emph{randomization})\r\n\\cite{Grassmann1991}, which constructs the ``uniformized DTMC'' defined by\r\n\\[\r\n   \\P = \\frac{\\Q}{q} + \\I, \\quad \\vp^{(0)} = \\vpi(0)\r\n\\]\r\nwhere $q$ satisfies $q \\ge \\max_i\\{-\\Q[i,i]\\}$.  Observe that with this\r\nchoice for $q$, the CTMC will be sampled at a rate sufficient to observe the\r\nfastest CTMC state transitions.  This means that the DTMC is constructed such that\r\nstates that are slower to transition to another state will have self loops.\r\nConsequently, the DTMC is guaranteed to be aperiodic.\r\nThe probability vector $\\gvect{\\pi}(t)$ can then be written as\r\n\\begin{equation}\r\n  \\gvect{\\pi}(t) = \\sum_{n=0}^{\\infty} \\frac{e^{-qt}(qt)^n}{n!}\r\n     \\cdot \\vp^{(n)}\r\n  \\label{SUM:unif-inst}\r\n\\end{equation}\r\nwhere ${e^{-qt}(qt)^n}/{n!}$ is the Poisson probability of\r\nobserving $n$ state transitions of the CTMC ($n$ jumps of the DTMC) within time $t$,\r\nand $\\vp^{(n)}$ is the probability distribution of state occupancy after $n$ jumps.\r\nGiven $\\P$, the vector $\\vp^{(n)}$ is computed using the power method as discussed\r\nin Sec.~\\ref{SEC:powerDTMC}. {\\smart} computes the Poisson probabilities using the\r\nnumerically stable Fox-Glynn algorithm \\cite{Fox1988}, \r\nwhich provides a value of $N$ such that\r\n$\\overline{p}(N) \\le \\epsilon$\r\nfor a desired absolute precision $\\epsilon>0$,\r\nwhere $\\overline{p}(N)$ is the probability that the Poisson value is larger than $N$:\r\n\\[\r\n  \\overline{p}(N) = 1 - \\sum_{n=0}^{N} \\frac{e^{-qt}(qt)^n}{n!}.\r\n\\]\r\n{\\smart} truncates the infinite sum in Eq.~\\ref{SUM:unif-inst}\r\nand computes instead the sum from 0 to $N$,\r\nwhich guarantees that the elements of $\\gvect{\\pi}(t)$\r\nsum to at least $1-\\epsilon$.\r\n\\RELEASE{At present, {\\smart} does not have an option to specify this $\\epsilon$.}\r\n\\TBD{Add an option to specify this $\\epsilon$.}\r\n\r\n\r\n\r\n%           ======================================\r\n\\subsection{Cumulative transient analysis of CTMCs}\\label{SEC:cumul-trans-anal-CTMC}\r\n%           ======================================\r\n{\\smart} uses \\index{uniformization (randomization)}uniformization also to compute $\\vsigma(t) = \\int_0^t\r\n\\vpi(u) du$, the cumulative sojourn time vector up to time $t$, or in other words,\r\nthe total amount of time spent in each state during the interval $(0,t)$.\r\nUsing integration by parts, $\\gvect{\\sigma}(t)$ can be reformulated as\r\n\\begin{eqnarray}\r\n  \\nonumber\r\n  \\vsigma(t) \r\n  & = & \\int_{0}^{t}\r\n    \\sum_{n=0}^{\\infty} \\frac{e^{-q u} (q u)^n}{n!} \\vp^{[n]} d u\r\n  ~ = ~ \\sum_{n=0}^{\\infty} \\vect{p}^{[n]}\r\n    \\int_{0}^{t} \\frac{e^{-q u} (q u)^n}{n!} d u\r\n  ~ = ~ \\frac{1}{q} \\sum_{n=0}^{\\infty} \\vp^{(n)} \\sum_{k=n+1}^{\\infty}\r\n  \\frac{e^{-q t} (q t)^k}{k!} \r\n  \\\\\r\n  & = &\r\n  \\frac{1}{q} \\sum_{n=0}^{\\infty} \\vp^{(n)} \\overline{p}(n).\r\n  \\label{SUM:unif-acc}\r\n\\end{eqnarray}\r\nSimilar to the discussion in Sec.~\\ref{SEC:inst-trans-anal-CTMC},\r\n{\\smart} computes a finite sum from $0$ to $N$\r\nwith $\\overline{p}(N) \\le \\epsilon$,\r\nwhere $\\epsilon$ is a desired absolute precision.\r\n\\TBD{\\ldots specified by option \\Code{NeedToAddThisOption}.}\r\n\r\n\r\n\r\n%           ======================\r\n\\subsection{Steady-state detection}\r\n%           ======================\r\nWhen computing the (truncated) sums in Eqs.~\\ref{SUM:unif-inst} and \\ref{SUM:unif-acc},\r\n{\\smart} checks for steady-state conditions,\r\njust in case the CTMC has a limiting distribution,\r\n$\\gvect{\\pi}=\\lim_{u\\to\\infty} \\gvect{\\pi}(u)$, which may be dependent on the initial state.\r\nIf the solution time $t$ is large enough then $\\vp^{(n)}$ may converge to a limiting distribution\r\nas $n$ becomes large and before reaching the truncation point $N$.\r\n{\\smart} assumes steady-state conditions when the relative error between successive iterates,\r\n$\\vp^{(n)}$ and $\\vp^{(n+1)}$, is less than or equal to a user-specified $\\epsilon$.\r\n\\TBD{Need an option to specify this $\\epsilon$.}\r\n\\TBD{Need an option to turn this off, for speed, e.g. if $0=\\epsilon$.}\r\n\r\n\\TBD{HERE}\r\n\r\n%           ==========================================\r\n\\subsection{Instantaneous stationary analysis of CTMCs}\r\n%           ==========================================\r\nAnalogous to the discrete case, we can consider the ``long-term'' probability\r\nof being in each state of a CTMC by computing the\r\n\\index{stationary probability distribution}stationary probability vector\r\n\\[\r\n\\gvect{\\pi} = \\lim_{t \\rightarrow \\infty} \\gvect{\\pi}(t).\r\n\\]\r\nLike DTMCs, analysis of a general CTMC requires the analysis of many\r\n\\index{ergodic Markov chain}ergodic CTMCs and an \\index{absorbing Markov chain}absorbing CTMC.\r\n\r\n\\subsubsection{Ergodic CTMCs}\r\n\r\nLike ergodic DTMCs, \\index{ergodic Markov chain}ergodic CTMCs also converge to a\r\n\\index{stationary probability distribution}stationary probability distribution\r\nindependent of the initial state.\r\nIn this case, a finite-state CTMC need only be\r\n\\index{irreducible Markov chain}irreducible since periodicity is not an issue\r\nin continuous time.  Again, irreducibility on a finite state space\r\nimplies positive recurrence, which is necessary for a limiting distribution to exist.\r\n%An ergodic CTMC has the property that for all pairs of states $i$ and $j$ in\r\n%the CTMC, $j$ is reachable from $i$.\r\nThen, the stationary probability vector, $\\gvect{\\pi}$, uniquely satisfies\r\n\\begin{equation}\r\n  \\gvect{\\pi} \\cdot \\Q = \\0 \\ \\mbox{ subject to }\\ \\sum_{i} \\gvect{\\pi}[i] = 1.\r\n  \\label{LS:ergCTMC}\r\n\\end{equation}\r\n\r\n\r\n\\MSG{New from here.}\r\nCurrently, {\\smart} supports several different numerical algorithm to calculate the steady-state solutions\r\nfor ergodic CTMCs, which is set by option \\emph{SolutionType} and \\emph{Solver}.\r\n\r\n\\emph{SolutionType} has following options:\r\n\\begin{itemize}\r\n\\item NUMERICAL\r\n\\item APPROXIMATE\\_EVMDD\r\n\\item EXACT\\_EVMDD\r\n\\item SIMULATION\r\n\\end{itemize}\r\n\r\n\\emph{Solver} has following options:\r\n\\begin{itemize}\r\n\\item POWER\r\n\\item JACOBI\r\n\\item GAUSS\\_SEIDEL\r\n\\end{itemize}\r\n\r\nFor example, {\\smart} will utilize symbolic engine and Jacobi iteration by the following options:\r\n\r\n\\begin{verbatim}\r\n# StateStorage MDD_SATURATION_LEVEL\r\n# SolutionType EXACT_EVMDD\r\n# Solver JACOBI\r\n\\end{verbatim}\r\n\r\n\r\n\\subsubsection{\\index{absorbing Markov chain}Absorbing CTMCs}\r\n\r\nIf the CTMC consists only of transient and absorbing states,\r\nwe can compute the \\index{stationary probability distribution}stationary probabilities\r\nfor the absorbing states by \\emph{embedding} the CTMC, obtaining the DTMC\r\n\\[\r\n  \\P[i,j] = \\left\\{ \\begin{array}{ll} %}\r\n             \\frac{\\Q[i,j]}{-\\Q[i,i]}\r\n             &\r\n             \\mbox{if $i\\neq j$}\r\n             \\\\\r\n             0\r\n             &\r\n             \\mbox{otherwise}\r\n                  \\end{array} \\right.\r\n\\]\r\nwith $\\vp^{(0)} = \\gvect{\\pi}(0)$.\r\nWe then compute $\\gvect{\\pi} = \\vp$ in a way analogous to the\r\ndiscrete case.\r\n\r\n%           =======================================\r\n\\subsection{Cumulative stationary analysis of CTMCs}\r\n%           =======================================\r\nAnalogous the the DTMC case, we can compute the total expected time spent in\r\neach state of a CTMC as the limit\r\n\\[\r\n\\gvect{\\sigma} = \\lim_{t \\rightarrow \\infty} \\vsigma(t).\r\n\\]\r\nFor transient states, the entries in $\\gvect{\\sigma}$ are finite,\r\nand represent the expected time spent in each transient state before\r\nthe CTMC reaches an absorbing state (or a class of \\index{ergodic}ergodic states).\r\nThe portion of $\\gvect{\\sigma}$ corresponding to the transient states is the\r\nsolution to\r\n\\begin{equation}\r\n  \\gvect{\\sigma}[\\Set{T}] \\cdot \\Q[\\Set{T}, \\Set{T}]\r\n  = -\\gvect{\\pi}(0)[\\Set{T}]\r\n  \\label{LS:absCTMC}\r\n\\end{equation}\r\nwhere $\\Q[\\Set{T}, \\Set{T}]$ is the submatrix of $\\Q$\r\ncorresponding to transitions from transient states to transient states.\r\n\r\n\\begin{developer}\r\n%        ===========================\r\n\\section{Semi-regenerative processes}\\label{SEC:semi-regen-processes}\r\n%        ===========================\r\nWhile more complex than simple Markov chains,\r\n\\index{semi-regenerative process}semi-regenerative processes may still be analyzed using\r\nthe traditional Markov chain methods discussed previously, but only under certain conditions.\r\nEssentially, given a discrete-state, discrete-event model where the events have \\emph{both}\r\ndiscrete and continuous \\index{phase-type distribution}phase-type distributed delays\r\n(\\index{ph int}\\Code{ph int} and \\index{ph real}\\Code{ph real}, respectively),\r\nthe underlying process will be semi-regenerative\r\nif the \\Code{ph int} events are always \\emph{synchronized} when active.\r\nBy \\index{synchronization property}synchronized,\r\nwe mean that the phase changes of all active \\Code{ph int} events occur at precisely the\r\nsame (discrete) time when active.\r\nThen, the regeneration times can be defined by \\Code{ph int} events\r\n(simple phase changes or other state changes triggered by the event).\r\nThe only other active events that can trigger state changes between successive regeneration times\r\nare of \\Code{ph real} type.  Consequently, the subordinate processes that evolve between\r\nregeneration times are simple CTMCs, and, as is always the case for semi-regenerative processes,\r\nthe embedded \\index{Markov renewal process}Markov renewal process gives rise to an embedded DTMC.\r\nSemi-regenerative processes encountered in this way can be decomposed into\r\nDTMC and CTMC subproblems; however, because the DTMC and CTMC ``submodels'' interact\r\nwith each other, they must be solved through a concerted effort.\r\nNote that the underlying process may still be semi-regenerative without the synchronization\r\nassumption, but without a decomposition into Markov chain subproblems, numerical solution\r\nmay not be practical.\r\n\r\nAt present, {\\smart} is capable of numerically computing the stationary probability distribution\r\nof a semi-regenerative process with the synchronization assumption when\r\nthe embedded DTMC is \\index{ergodic}ergodic with a stationary solution.\r\nSynchronization among \\Code{ph int} events is automatically checked while generating the\r\nunderlying state space.  A warning is issued to the user if the requisite synchronization\r\nassumption is not present, which precludes a numerical solution.\r\nIn what follows, we will only present the key formulas for computing stationary solutions\r\nand refer the interested reader to \\cite{Jones-NASA-00}\r\nfor a discourse on this subject and a detailed presentation of the solution algorithms.\r\n\r\nLet $\\P$ be the transition matrix of the embedded DTMC with state space $\\mathcal{E}$\r\nthat evolves at each regeneration time.\r\nThe matrix $\\P$ is computed one row at a time by exploring from each known state $i\\in\\mathcal{E}$\r\nand constructing the subordinate CTMC that evolves until the next regeneration time is reached\r\nwith new embedded states $j\\in\\mathcal{E}$ such that $\\P[i, j]>0$.\r\nActually, only values $\\P[i, j] > \\Code{Pruning}$ are stored where the\r\nuser option \\index{Pruning option}\\Code{Pruning} is\r\nconsidered ``small enough'' with a default value of $10^{-20}$.\r\nLet $\\Q_i$ be the infinitesimal generator matrix of the subordinate CTMC on the state space\r\n$\\mathcal{S}_i$ originating from embedded state $i$.  Take the basic step of all \\Code{ph int}\r\nto be unity.  Then, when both \\Code{ph int} and \\Code{ph real} events are active,\r\nthe entries of matrix $\\P$ can be computed from\r\n\\[\r\n  \\P[i, j] = \\sum_{k\\in\\mathcal{S}_i} e^{\\Q_i}[i, k] \\matr{\\Delta}[k, j]\r\n\\]\r\nwhere the matrix $e^{\\Q_i}$ is the (matrix exponential) solution of the CTMC at time one,\r\nwhich is actually computed using the \\index{uniformization (randomization)}uniformization\r\nprocedure discussed in Sections \\ref{SEC:inst-trans-anal-CTMC} and \\ref{SEC:cumul-trans-anal-CTMC}.\r\nThe matrix $\\matr{\\Delta}[k, j]$ gives the probability of jumping from state $k$ to state $j$\r\nat the regeneration time and is computed automatically from the model specification.\r\nWhen only \\Code{ph int} or only \\Code{ph real} events are active,\r\na regeneration occurs after each state transition due to the strong Markov property, and we\r\nsimply replace $e^{\\Q_i}[i, k]$ in the equation above with the indicator function $1\\{i=k\\}$.\r\nConditioned on each $i\\in\\mathcal{E}$, let the matrix $\\gvect{\\sigma}$ be the expected sojourn time\r\nin each state $k\\in\\mathcal{S}_i$ until the next regeneration time, which is computed from\r\n\\[\r\n  \\gvect{\\sigma}[i, k] =\r\n  \\begin{cases}\r\n    \\int_{0}^{1} e^{\\Q_i u}[i, k]\\,du\r\n                               & \\mbox{if both \\Code{ph int} and \\Code{ph real} are active}, \\\\\r\n    1\\{i=k\\} (-Q_i[i, i])^{-1} & \\mbox{if only \\Code{ph real} events are active}, \\\\\r\n    1\\{i=k\\}                   & \\mbox{if only \\Code{ph int} events are active},  \\\\\r\n    0                          & \\mbox{otherwise}.\r\n  \\end{cases}\r\n\\]\r\nThe computation in the first case can be performed at the same time $e^{\\Q_i}$ is computed.\r\nAfter constructing the matrix $\\P$,\r\nthe stationary solution, $\\vp$, of the embedded DTMC is computed from $\\vp \\cdot (\\P - \\I) = \\0$.\r\nThe whole state space for the semi-regenerative process is defined by\r\n$\\mathcal{S}\\equiv\\bigcup_{i\\in\\mathcal{E}} \\mathcal{S}_i$.\r\nFinally, the stationary solution, $\\gvect{\\pi}$, of the semi-regenerative process is computed by\r\nconsidering the average time spent in any state between regeneration times\r\n(conditioned on each embedded state),\r\n\\[\r\n  \\gvect{\\gamma}[k] = \\sum_{i\\in\\mathcal{E}} \\vp[i]\\cdot\\gvect{\\sigma}[i, k],\r\n\\]\r\nand then normalizing,\r\n\\[\r\n  \\gvect{\\pi}[k] = \\frac{\\gvect{\\gamma}[k]}{\\sum_{j} \\gvect{\\gamma}[j]},\r\n\\]\r\nto obtain the proportion of time spent in any state between regeneration times\r\nfor each state $k\\in\\mathcal{S}$.\r\n\r\n\\DEVELOPER{\r\n{\\smart} actually avoids having to compute and store the entire matrix\r\n$\\gvect{\\sigma}\\in\\Reals^{|\\mathcal{E}|\\times|\\mathcal{S}|}$ by being ``measure driven.''\r\nThat is, $\\gvect{\\sigma}[i, k]$ for each state $i\\in\\mathcal{E}$ in turn is used to\r\n``distill'' the user-defined reward functions $f : \\mathcal{S}\\to\\Reals$\r\n(used to compute measures) into a new reward functions $\\tilde{f} : \\mathcal{E}\\to\\Reals$,\r\n\\[\r\n  \\tilde{f}(i) = \\sum_{k\\in\\mathcal{S}_i} \\gvect{\\sigma}[i, k]\\cdot f(k),\r\n\\]\r\ndefined only on the embedded state space $\\mathcal{E}$, not the whole state space $\\mathcal{S}$.\r\nThis way, $\\gvect{\\sigma}[i, \\cdot]$ can be discarded once it is used to compute $\\tilde{f}(i)$.\r\n}\r\n\r\nWe have just described the \\index{embedding strategies}``embedding strategy'' used when the\r\noption \\index{EmbedWithElim option}\\Code{EmbedWithElim} = 0 is selected, which is the default.\r\nAlternative embedding strategies, which attempt to reduce the size of the state space $\\mathcal{E}$,\r\nare also available that exploit the fact that oftentimes more than one embedded Markov process is\r\npresent \\cite{2001PNPM-PDPN}.\r\nEssentially, embedded states can be eliminated by being selective in our choice of\r\nwhich embedded Markov process to observe.  At present, there are four possible\r\nembedding strategies to choose from:\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|c|p{4.25in}|}\r\n\\hline\r\n  \\Code{EmbedWithElim} & \\textbf{Description} \\\\\r\n  \\hline\r\n  \\hline\r\n  0 & most basic, the one described above, 0 embedded state are eliminated \\\\ \\hline\r\n  1 & eliminate embedded states that arise when only\r\n      \\Code{ph int} or only \\Code{ph real} events are active \\\\ \\hline\r\n  2 & eliminate embedded states that only record phase changes\r\n      when both \\Code{ph int} and \\Code{ph real} events are active \\\\ \\hline\r\n  3 & 1+2=3, use both 1 and 2 together \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\r\nAnother user option called\r\n\\index{Epsilon option}\\Code{Epsilon} comes into play when using embedding strategies 2 or 3.\r\nEmbedding strategy 2 (and hence 3) tries to find \\emph{all possible} regeneration times that:\r\n\\begin{itemize}\r\n  \\item comprise a single step in $\\P$,\r\n  \\item are (mostly) due to synchronized events with \\Code{ph int} delays, and\r\n  \\item it is certain that the event will trigger a state change where more than just the\r\n        phase component changes, such as a change in the marking in the case of \\Code{spn} models.\r\n\\end{itemize}\r\nBecause {\\smart} will try to consider the entire (pmf) support of active \\Code{ph int} events\r\nin search of regeneration times with all of the above properties, a truncation point must be\r\nintroduced in case the support is infinite in length, such as the infinite support of the\r\ngeometric distribution.\r\nThe user option \\index{Epsilon option}\\Code{Epsilon} $\\in$ $(0, 1)$ provides a truncation\r\npoint by stopping the search when the smallest pmf tail of any active \\Code{ph int} event\r\nbecomes less than or equal to \\Code{Epsilon}. \\Code{Epsilon} has a default value of $10^{-10}$.\r\n\r\nFinally, the following print options are provided that\r\ntake boolean values $\\{\\Code{true}, \\Code{false}\\}$,\r\nall \\Code{false} by default:\r\n\\index{ShowEMCdata, ShowEMCprob, ShowEMCsize, ShowSpecial options}\r\n\\begin{table}[h]\r\n\\centering\r\n\\begin{tabular}{|c|p{4.25in}|}\r\n\\hline\r\n  \\textbf{Option} & \\textbf{Prints the following if \\Code{true}} \\\\\r\n  \\hline\r\n  \\hline\r\n  \\Code{ShowEMCsize} & size of the embedded state space, $|\\mathcal{E}|$ \\\\\r\n  \\Code{ShowEMCdata} & all nonzero entries of the transition matrix $\\P\\in\\Reals^{|\\mathcal{E}|\\times|\\mathcal{E}|}$ \\\\\r\n  \\Code{ShowEMCprob} & $\\vp[i]$ and $\\sum_k\\gvect{\\sigma}[i, k]$ for each state $i\\in\\mathcal{E}$ \\\\\r\n  \\Code{ShowSpecial} & data about the computational effort \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\r\n\r\n% FIX AND MOVE THIS TO AN EARLIER SECTION ON \"UNDERLYING STOCHASTIC PROCESSES\"...\r\n% Perhaps the best way to describe a semi-regenerative process is by beginning from\r\n%processes that are already familiar.  The simplest stochastic process is a\r\n%sequence of independent and identically distributed (i.i.d.) random variables\r\n%referred to as a renewal process.\r\n%Markov chains generalize renewal processes somewhat by allowing a limited amount\r\n%of dependency.\r\n%Consider now a stochastic process that starts over independently and identically\r\n%at certain random times forming an increasing sequence $T=\\{T_n : n \\geq 0\\}$.\r\n%Processes that restart like this are called regenerative processes and the times $T$\r\n%are called regeneration times.\r\n%example with Markov chains at fixed state....\r\n%\r\n%So, regenerative processes generalize renewal processes,\r\n%but regenerative processes can be generalized further just like renewal processes were\r\n%generalized by Markov chains.\r\n%Semi-regenerative processes generalize regenerative processes by allowing the future\r\n%after regeneration times to depend on the state entered just after such times.\r\n%It follows that ...\r\n%Semi-regenerative There is an\r\n\\end{developer}\r\n\r\n\\DEVELOPER{\r\n%        ======================\r\n\\section{Solving linear systems}\r\n%        ======================\r\nFor many types of analysis, {\\smart} must solve a linear system of the form\r\n\\[\r\n  \\vx \\A = \\vb\r\n\\]\r\nfor the vector $\\vx$.\r\nSince the matrix $\\A$ is typically very large and\r\nquite sparse, and is not always explicitly stored, {\\smart} uses\r\nimplicit, iterative techniques \\cite{Stewart1994book} for computing\r\n$\\vx$. Since the iterative methods compute $\\vx$ as a fixpoint,\r\noptions analogous to the \\index{converge option}\\Code{converge} options are used to\r\nadjust the computation: \\Code{NumericalPrecision} defines the\r\ndesired precision $\\epsilon$, \\Code{NumericalPrecisionTest}\r\ndefines the \\emph{stopping criterion} (either element-wise\r\nrelative or element-wise absolute precision), and\r\n\\Code{MaxNumericalIters} defines the maximum number of allowed\r\niterations.\r\n\r\n\\MSG{discuss \\Code{RELAXATION}}\r\n\r\nThe type of iteration performed is specified using the\r\n\\index{Solver option}\\Code{Solver} option,\r\nwhich can be one of the following.\r\n\r\n\\begin{description}\r\n\r\n\\item{\\Code{POWER} :}  The power method.\r\nThis works for systems of the form $\\vp = \\vp \\cdot \\P$, and\r\nsimply computes $\\vp^{(n+1)} = \\vp^{(n)} \\cdot \\P$ starting\r\nwith $n=0$ and continuing until subsequent vectors are within a desired\r\nprecision.\r\n\r\n\\MSG{This can be used for transient solutions of DTMCs,...}\r\n\r\n\\MSG{Does this use relaxation?}\r\n\r\n\\item{\\Code{JACOBI} :}  The Jacobi iteration.\r\nNewly computed elements of $\\vx$ are not used until the next iteration.\r\nAs a result, an auxiliary vector $\\vx'$ is required to store the new\r\nvalues.\r\n{\\smart} is able to use the Jacobi iteration when the matrix $\\A$ is stored\r\nin a sparse format, either by rows or by columns.\r\n{\\bf This is the default.}\r\n\\MSG{Should it be GAUSS\\_SEIDEL instead?}\r\n\r\n\\DEVELOPER{\r\n\\item{\\Code{BLOCK\\_JACOBI} :}  An experimental block algorithm.\r\n  This should not be used yet, but eventually will be used with distributed\r\n  solutions.\r\n}\r\n\r\n\\item{\\Code{GAUSS\\_SEIDEL} :}  The Gauss-Seidel iteration.\r\nThis is similar to Jacobi, except the newly computed elements of $\\vx$\r\nare used right away.\r\nAs a result, the auxiliary vector required by Jacobi is not needed with\r\nGauss-Seidel.\r\nHowever, this requires the computation of one element of $\\vx$ at a time;\r\nas a result, the Gauss-Seidel iteration requires access to the columns of\r\nmatrix $\\A$.\r\nTherefore, Gauss-Seidel can only be used with data structures for $\\A$\r\nthat allow efficient access to the matrix columns.\r\n\r\n\\MSG{Discuss relative number of iterations.}\r\n\r\n\\DEVELOPER{\r\n\\item{\\Code{BLOCK\\_GAUSS} :}  An experimental block algorithm, just as\r\nexperimental and not working as block Jacobi.\r\n}\r\n\r\n\\item{\\Code{SOR} :} A Gauss-Seidel iteration which adaptively adjusts the\r\nrelaxation parameter.\r\n\\cite{1993IMA-SRNs}\r\nThe initial relaxation parameter is taken from the option\r\n\\index{RELAXATION option}\\Code{RELAXATION}.\r\n\r\n\\DEVELOPER{\r\n\\item{\\Code{BICGSTAB} :} Biconjugate Gradient Stabilizer.\r\nAlso experimental (i.e., not thoroughly tested and debugged yet).\r\n}\r\n\r\n\\end{description}\r\n\r\n%        ===========================\r\n\\section{Representing large matrices}\r\n%        ===========================\r\nSince the matrices are large, blah blah blah.\r\n\r\n{\\smart} can use a variety of methods for representing the transition matrix of a Markov chain.\r\nThe methods, described below, are selected based on the option\r\n\\index{MarkovStorage option}\\Code{MarkovStorage}.\r\n\r\n%           ==============\r\n\\subsection{Sparse storage}\r\n%           ==============\r\nMention rows vs columns.\r\nUsed for high-level formalisms and manipulation of phase-type vars.\r\nFor high level models, we do a memory-efficient, two-pass approach:\r\nfirst count the number of entries in each row or column, so that we can\r\nallocate an array of entries instead of using linked lists.\r\nThe second pass fills the array.\r\nThis is the default.\r\n\r\n%           ==========\r\n\\subsection{On the fly}\r\n%           ==========\r\nOnly high-level formalisms with expo or immediate transitions.\r\nOnly by rows.\r\n\\cite{Deavours1997onthefly}\r\n\r\n%           =========================\r\n\\subsection{Kronecker representations}\r\n%           =========================\r\nOnly high-level formalisms with expo or \\emph{local} immediate transitions.\r\nMention rows vs columns.\r\nOptions to mention: \\Code{MarkovStorage}, \\Code{UseHoldingArray},\r\n\\Code{MatrixByRows}\r\n\r\nThe consistent requirement.\r\n\r\n%           ===============\r\n\\subsection{Matrix diagrams}\r\n%           ===============\r\nOnly high-level formalisms.\r\nMention rows vs columns.\r\n\r\nKronecker \\cite{1999PNPM-MatrixDiagrams, MinerThesis2000} vs. non-Kronecker\r\n\\cite{Miner2001canonicalMDs}\r\n\r\nOptions to mention: \\Code{MarkovStorage}, \\Code{UseHoldingArray},\r\n\\Code{MergeLevel}\r\n\r\n}\r\n", "meta": {"hexsha": "30ad8db0e91b300797a0304def63a7c1a85293e2", "size": 33213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/numerical-markov.tex", "max_stars_repo_name": "asminer/smart", "max_stars_repo_head_hexsha": "269747c4578b670e5c3973f93a1e6ec71d95be78", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-05-30T23:02:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T07:30:46.000Z", "max_issues_repo_path": "manual/numerical-markov.tex", "max_issues_repo_name": "asminer/smart", "max_issues_repo_head_hexsha": "269747c4578b670e5c3973f93a1e6ec71d95be78", "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/numerical-markov.tex", "max_forks_repo_name": "asminer/smart", "max_forks_repo_head_hexsha": "269747c4578b670e5c3973f93a1e6ec71d95be78", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-07-13T18:53:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-12T17:54:02.000Z", "avg_line_length": 46.8448519041, "max_line_length": 120, "alphanum_fraction": 0.6915665553, "num_tokens": 8882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6321510258066607}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage[margin=1.25in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{physics}\n\\usepackage{mathrsfs}\n\\usepackage[shortlabels]{enumitem}\n\n\n\\setlength\\parindent{0pt}\n\\newcommand{\\code}{\\lstinline[basicstyle=\\small]}\n\\lstset{\n    language=Python,\n    basicstyle=\\scriptsize\n}\n\n\n\\title{EE2703: Applied Programming Lab \\\\ \\Large Assignment 9: Spectra of Non-Periodic Signals}\n\\author{Soham Roy \\\\ \\normalsize EE20B130}\n\\date{\\today}\n\\begin{document}\n\n\\maketitle % Insert the title, author and date\n\n\n\n\\section{Introduction}\nThis assignment continues the examination of signals using Fourier Transforms, with non-periodic functions.\nWhen these functions are periodically extended, discontinuities arise. Due to the Gibbs phenomenon, the discontinuities create\nFourier components in non-harmonic frequencies which decay as $\\frac{1}{\\omega}$. A Hamming window has been used to solve this\nproblem.\n\n\n\n\\section{Questions}\n\\subsection{Examples}\nSpectrum of $\\sin(\\sqrt{2}t)$:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{eg1.png}\n\\end{figure}\n\nGraph of $\\sin(\\sqrt{2}t)$:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{eg2.png}\n\\end{figure}\n\n$\\sin(\\sqrt{2}t)$ represented by the DFT:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{eg3.png}\n\\end{figure}\n\\pagebreak\n\nThese discontinuities lead to non-harmonic components in the FFT which decay as $\\frac{1}{\\omega}$.\nTo confirm this, the spectrum of the periodic ramp has been plotted:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.65]{eg4.png}\n\\end{figure}\n\n\n\\subsubsection{Hamming window}\nThe Hamming window removes discontinuities by attenuating the high frequency components that cause the discontinuities.\nThe Hamming window function is given by:\n\\begin{equation*}\n    x[n] = 0.54 + 0.46\\cos(\\frac{2\\pi n}{N - 1})\n\\end{equation*}\n\nWe now multiply our signal with the Hamming window and periodically extend it. We observe that the discontinuities nearly vanish:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.65]{eg5.png}\n\\end{figure}\n\nThe spectrum that is obtained with a time period $2\\pi$ is given below:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{eg6.png}\n\\end{figure}\n\nThe spectrum that is obtained with a time period $8\\pi$ has a slightly sharper peak:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{eg7.png}\n\\end{figure}\n\\pagebreak\n\n\n\\section{Questions}\n\\subsection{Helper Functions}\nWe define the following helper functions:\n\\begin{lstlisting}\n    def spectrum(f, n, lim, windowing=True, t=None):\n        \"\"\"Evaluates the DFT spectrum of a function f(t).\"\"\"\n        if t is None:\n            t, dt = np.linspace(-lim, lim, n, endpoint=False, retstep=True)\n        else:\n            dt = t[1] - t[0]\n        f_max = 1 / dt\n        w = np.linspace(-np.pi * f_max, np.pi * f_max, n, endpoint=False)\n        y = f(t)\n        if windowing:\n            y *= fftshift(0.54 + 0.46 * np.cos(2 * np.pi * np.arange(n) / n))\n        y[0] = 0  # the sample corresponding to -tmax should be set zero\n        y = fftshift(y)  # make y start with y(t=0)\n        Y = fftshift(fft(y)) / n\n\n        return w, Y\n\n\n    def plotter(w, Y, title, lim, out, xlabel, ylabels):\n        \"\"\"Plots the passed DFT spectrum.\"\"\"\n        plt.figure()\n        plt.subplot(2, 1, 1)\n        plt.title(title)\n        plt.ylabel(ylabels[0], size=16)\n        plt.plot(w, np.abs(Y), lw=2)\n        plt.xlim(-lim, lim)\n        plt.grid(True)\n\n        plt.subplot(2, 1, 2)\n        plt.xlabel(xlabel, size=16)\n        plt.ylabel(ylabels[1], size=16)\n        phase = np.angle(Y)\n        phase[np.where(np.abs(Y) < 3e-3)] = 0\n        plt.plot(w, phase, \"ro\", lw=2)\n        plt.xlim(-lim, lim)\n        plt.grid(True)\n\n        plt.savefig(\"Assignment_09/LaTeX/\" + out)\n\\end{lstlisting}\n\n\n\\subsection{Spectrum of $\\cos^3(0.86t)$}\nThe FFT with and without the Hamming window have been plotted:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q2a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q2b.png}\n\\end{figure}\nIt is observed that a large part of the energy is stored in frequencies that are not a part of the signal.\nAfter windowing, these frequencies are attenuated and hence the peaks are sharper in the windowed function.\nHowever, it is not an impulse because convolution with the Fourier transform of the windowed function smears out the peak.\n\n\n\\subsection{Estimate $\\omega_0$ and $\\delta$}\\label{ssec:estimate}\nWe need to estimate $\\omega_0$ and $\\delta$ for a signal $\\cos(\\omega_0 t + \\delta)$ for 128 samples between $[-\\pi,\\pi)$,\nand find the two peaks at $\\pm\\omega_0$, and estimate $\\omega_0$ and $\\delta$. We estimate $\\omega_0$ using a weighted average\nover $|Y(\\omega)|^2$, and $\\delta$ is the phase at the frequency nearest to $\\omega_0$.\n\\begin{lstlisting}\n    def estimate_params(w, Y):\n    \"\"\"Estimates the parameters omega and delta of cos(omega*t + delta).\"\"\"\n        ii = np.where(w > 0)\n        omega = np.sum(np.abs(Y[ii]) ** 2 * w[ii]) / np.sum(np.abs(Y[ii]) ** 2)\n        i = np.argmin(np.abs(w - omega))\n        delta = np.angle(Y[i])\n        \n        return omega, delta\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q3.png}\n\\end{figure}\n\n\n\\subsection{$\\cos^3(0.86t)$ with White Gaussian Noise}\nWe perform the same process as \\ref{ssec:estimate} but with noise added to the original signal.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q4.png}\n\\end{figure}\n\nFor the true value of $\\omega_0 = 1.5$ and $\\delta = 0.5$, the estimated values are:\n\\begin{lstlisting}\n    Estimated w_0 = 1.516318, delta = 0.506776 without noise\n    Estimated w_0 = 2.098451, delta = 0.481129 with noise\n\\end{lstlisting}\n\n\n\\subsection{DFT of Chirped Signal}\nWe analyze a chirp signal -- an FM signal where frequency is directly proportional to time:\n\\begin{equation*}\n    f(t) = \\cos(16t\\left(1.5 + \\frac{t}{2\\pi}\\right))\n\\end{equation*}\n\nWe observe that the frequency response is spread between 5 and 50 rad/s.\nA large section of this range apears due to Gibbs phenomenon.\nOn windowing, only frequencies between 16 and 32 rad/s remain.\nThe FFT of the chirp is as follows:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q5a.png}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q5b.png}\n\\end{figure}\n\n\n\\subsection{Surface Plot}\nFor the same chirped signal, the 1024 vector is broken into pieces that are 64 samples wide. Then we extract the\nDFT of each and store as a column in a 2D array. Then we plot the array as a surface plot to show how the\nfrequency of the signal varies with time:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{q6.png}\n\\end{figure}\n\n\n\\section{Conclusion}\nWe investigated the need of windowing for DFTs in the case of non-periodic signals in this assignment.\nThis is done to reduce the effect of Gibbs phenomena caused by the discontinuous nature of the series\n$\\tilde{x}[n]$ generated by a discrete fourier transform.\n\nThe final question concerns chirped signals, in which we plot fourier spectra for various time slices of a\nsignal. We took more closely spaced slices after noticing the instance of a small number of slices.\n\nThe existence of two peaks, disappearing of chirp effects in case of a windowed transform, and a\nphase plot that regularly varies with reduced phase near maximas are all visible aspects of a fourier spectra\nfor a chirped signal in time changing plots.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "dfb18e8f00e641fe1a05d2602fe2eb5a4e3f074f", "size": 7634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_09/LaTeX/Report.tex", "max_stars_repo_name": "sohamroy19/EE2703", "max_stars_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_stars_repo_licenses": ["MIT"], "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_09/LaTeX/Report.tex", "max_issues_repo_name": "sohamroy19/EE2703", "max_issues_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_issues_repo_licenses": ["MIT"], "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_09/LaTeX/Report.tex", "max_forks_repo_name": "sohamroy19/EE2703", "max_forks_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_forks_repo_licenses": ["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.9051724138, "max_line_length": 129, "alphanum_fraction": 0.6976683259, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.6320933137256224}}
{"text": "%! Author = tstreule\n\n\\section{Ultrasound Imaging \\textnormal{\\normalsize $c\\ped{sound} \\simeq \\unitfrac[1540]{m}{s}$}}\n\nFrequencies of 1-50 MHz $\\implies$ $\\lambda = 1 .... 0.03 \\unit{mm}$\n\nWave formula: $\\nabla^2 p - \\frac{1}{c^2} \\frac{\\partial^2 p}{\\partial t^2} = 0$ \\quad Max. p = compressional pressure= $p_c$, \\quad Min. p = rarefactional pressure = $p_r$\n\n$\\kappa$ = compressibility, $\\rho$ = density, $u_z$ = particle velocity\\\\\n$c = \\frac{1}{\\sqrt{\\kappa \\rho}}$, \\quad $p = \\rho c u_z$, \\quad $Z = p/u_z = \\rho c = \\sqrt{\\frac{\\rho}{\\kappa}}$, \\quad $I = p u_z / 2$\n\nPressure \\textbf{coeff.}: \\highlight{$\\displaystyle r = \\frac{Z_2 - Z_1}{Z_2 + Z_1}$} \\highlight{$\\displaystyle t = \\frac{2Z_2}{Z_2 + Z_1}$}\\\\\n\\textbf{Refraction:} $\\theta_i = \\theta_r$, \\quad $\\sin\\theta_i/\\sin\\theta_t = c_i/c_t$\n\n\\textbf{Rayleigh scattering} by structures smaller $\\lambda$ $\\to$ speckles/noise ($\\sigma_S \\propto \\lambda^{-4}$). It has a char. length of $\\lambda/2$:\n\n\\textbf{Attenuation} (due to scattering and absorption): \\\\\n\\highlight{$\\displaystyle p(z) = p_0 e^{-\\alpha z} \\approx p_0\\,10^{-\\frac{\\textrm{att}}{\\unit[20]{dB} }}$} ($[z]=\\unit{cm}$, $\\textrm{att} = \\alpha_0\\cdot z = \\textrm{const}\\cdot f\\cdot z$) \\\\\n\\textbf{Decibel notation}: $\\alpha_0 = 20 \\log \\left( \\frac{p_0}{p(z)} \\right) \\frac{1}{z} = 8.686 \\alpha [dB/cm]$\n\n\\textbf{Transducer}: Tx/Rx switch, Damping, matching layer, $f_0$\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Beam geometry}\n%\n\\textbf{Near field (Fresnel)}zone with const. beamwidth of $2r$.\\\\\n\\textbf{Far field (Fraunhofer)} zone which starts at \\highlight{$\\displaystyle \\textrm{NFB} \\approx \\frac{r^2}{\\lambda_{tissue}}$}.\\vspace{-3mm}\\\\\nBeamwidth = lateral resolution \\vspace{1mm}\n\n\\textbf{Angle} of beam: \\highlight{$\\displaystyle \\theta = 2\\arcsin\\left( \\frac{0.61 \\lambda}{r}\\right)$}\n\n\\textbf{Focusing} with acoustic lens: Focal distance, lateral resolution, aperture dimension. Depth of focus: Over which distance is it narrow.\\vspace{-1mm} \\\\\n\\textbf{Axial resolution}: \\highlight{$\\textstyle \\Delta z \\geq \\frac{\\lambda}{2} = \\frac{p_dc\\ped{sound}}{2}$} \\quad $\\lambda$: pulse length\n\n\\textcolor{gray}{ \\textbf{Range Gain}: The longer signals take to come back, the $\\downarrow$. To compensate: Amplify the late signals exponentially }\n\n\\textbf{Thermal noise}: \\fbox{$P_N = k_B \\cdot T \\cdot BW [\\unit{W}]$} \\hfill (BW: typ. 1MHz)\n\n\\textbf{SNR in dB} = Transmitted Power - power losses - $P_N$.\\\\\nPower losses: Attenuation \\& reflection coefficient (factor 20)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Transducer setups}\n%\n\\textbf{Linear Array}. \\textbf{pitch} $d \\approx \\lambda$ and \\textbf{kerf} (gap). Sweep through. Good resolution $\\implies$ small pitch $\\implies$ large $\\theta$\n\n\\begin{minipage}{0.64\\linewidth}\n    \\textbf{Phased parallel operation}:\\\\\n    \\highlight{$\\displaystyle \\Delta \\Phi = k \\Delta s = kd\\sin\\alpha \\mod 2\\pi$}. Multiple solutions for \\fbox{$d > \\lambda/2$ $\\to$} \\textbf{grating lobes} (weaker since not time aligned)\n\\end{minipage} \\hfill\n\\begin{minipage}{0.35\\linewidth}\n    \\includegraphics[width=\\linewidth]{US_PhasedParallelMode}\n\\end{minipage}\n\nReceiving analog: delay elements, then sum all up.\n\n\\textbf{Variable focusing} (with shifting) and a combination of all\n\n\\textbf{Multi-dim. arrays}: 2D or 1.5D ($1/2$ D = ``\\textbf{elevation}'').\n\n\\textbf{Curved arrays} (instead of flat): For small acoustic windows\n\n\\textbf{Annular Array} (circular sections): Simpler adjustable focus and circular symmetry = more \\textbf{isotropic depiction}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Scanning modes}\n%\n\\textbf{A-Mode} (Amplitude): time (distance) vs amplitude. \\\\\nUsage: e.g. measuring the thickness\n\n\\textbf{M-Mode} (Motion): time vs depth. Amplitude with brightness. Must be tilted manually\n\n\\textbf{B-Mode} (Brightness): 2D spacial. Amplitude with brightness\n\n\\textbf{Scanning Procedures}:\\\\\n$\\bullet$ \\textbf{Parallel scan} for large acoustic window.\n$\\bullet$ \\textbf{Sector scan} for small ac. window.\n$\\bullet$ \\textbf{Radial scan} for transd. in blood vessels (measuring the vessel wall).\n$\\bullet$ \\textbf{Compound scan} from different directions $\\to$ redundancy and reduce speckles.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Measuring the blood flow}\n%\nObserver at velocity $v$, receives $f\\ap{eff} = f \\frac{c + v}{c}$\n\nBlood vessel flows under the receiver with angle $\\theta$ rel. to the vertical to transducer:\n\\fbox{$f\\ped{rec} = f_i \\frac{2 f_i \\cos \\theta}{c} + \\frac{f_i v^2 \\cos^2 \\theta}{c^2}$}\\\\\n\\begin{minipage}{0.6\\linewidth}\n    \\highlight{$\\displaystyle f_D = f_i - f\\ped{rec} \\approx \\frac{2 f_i v \\cos \\theta}{c}$}\n\\end{minipage}\n\\begin{minipage}{0.4\\linewidth}\n    Must know $\\theta$ \\\\$\\implies$ do B-Mode scan first\n\\end{minipage}\n\nRed blood cells $\\approx 7 \\unit{\\mu m}$ wide $\\implies$ Use high freq., typ. 5MHz\n\n\\textbf{Cont. setup}: Separated receiver/transmitter. Quadr. encoder: Mult. with cos ($\\to$ real part) and sin ($\\to$ imag part) $\\to$ double sided spectrum. Neg. side is \\textit{negative flow}. Then \\textit{low-pass + high-pass} to remove (quasi) stationary echos.\n\n\\textbf{Pulsed measurement}: 1 transducer. Only receive signal during a narrow time window. Its delay = depth.\n\n\\begin{minipage}{\\linewidth}\n    \\raggedleft\n    \\vspace{2mm}\n    \\includegraphics[width = \\linewidth]{US_DopplerPulsed} \\vspace{-37mm}\\\\\n    \\highlight{$\\displaystyle -f\\ped{prf}/2 < f\\ped{D} < f\\ped{prf}/2$}\n    \\vspace{37mm}\n\\end{minipage}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Appendix}\n%\n\\begin{tabular}{ c@{$\\;\\laplace\\;$}c c c@{$\\;\\laplace\\;$}c }\n    $f(at)$\t\t\t& $\\frac{1}{\\abs{a}}F(s/a)$\t&& $f(t-a)$\t\t& $\\eu^{-as}F(s)$\\\\\n    $f(t)\\eu^{at}$\t& $F(s-a)$\t\t\t\t\t&& $f'(t)$\t\t& $sF(s) - f(0^+)$\\\\\n    $t^n$\t\t\t& $n!/s^{n+1}$\t\t\t\t&& $t^n f(t)$\t& $(-1)^n F^{(n)}(s)$\\\\\n    $\\sin(at)$\t\t& $\\frac{a}{s^2 + a^2}$\t\t&& $\\cos(at)$\t& $\\frac{s}{s^2 + a^2}$\\\\\n    $\\eu^{at}$\t\t& $\\frac{1}{s - a}$\t\t\t&& $t^n \\eu^{at}$& $\\frac{n!}{(s-a)^{n+1}}$\n\\end{tabular}\n\n\\textbf{Constants}:\\\\\n\\begin{tabular}{r@{$\\;=\\;$}l}\n    $h$\t\t\t& $\\unit[6.626\\E{-34}]{JS} = \\unit[4.135\\E{-15}]{eV\\,s}$,\\qquad $\\hbar = \\frac{h}{2\\pi}$\\\\\n    $\\epsilon_0$& $\\unitfrac[8.85\\E{-5}]{As}{Vm}$\\\\\n    $\\mu_0$\t\t& $\\unitfrac[4\\pi\\E{-7}]{N}{A^2}$\\\\\n    $k\\ped{B}$\t& $\\unitfrac[1.38\\E{-23}]{J}{K} = \\unitfrac[8.617\\E{-5}]{eV}{K}$\\\\\n    $q$\t\t\t& $\\unit[1.602\\E{-19}]{C}$, \\quad $m_e = \\unit[9.109\\E{-31}]{kg}$, \\quad $m_p = \\unit[1.672\\E{-27}]{kg}$\\\\\n    $m_ec^2$\t& $\\unit[511]{eV}$\n\\end{tabular}\n$\\unit[0]{^\\circ C} = \\unit[273.15]{K}$\n", "meta": {"hexsha": "01a51963a73088fc896dd293c4126cd452dde8a8", "size": 6620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/BMI18/sections/08_ultrasound.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/08_ultrasound.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/08_ultrasound.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": 52.96, "max_line_length": 265, "alphanum_fraction": 0.6258308157, "num_tokens": 2365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6320932991242394}}
{"text": "\\documentclass[a4paper,11pt]{book}\n\\usepackage{import}\n\\usepackage{preamb}\n\n\\makeindex\n\n\\begin{document}\n\n\\input{head}\n\\newpage\n\\input{Title}\n% \\section{Blocks and Community structure}\n\n\n\\begin{subbox}{subbox}{}\n\\centering\n\\Large{\\textbf{Networks as Matrices}}\n\\end{subbox}\n\n\n\\begin{textbox}{Matrices in short}\nMatrices are mathematical objects that can be thought as \\textit{tables} of numbers. The size of a matrix is expressed as $m \\times n$, for a matrix with $m$ rows and $n$ columns. \\textbf{The order (row/column) is important}.\n\n\\textbf{$M_{ij}$} is a notation representing the element on \\textbf{row} $i$ and \\textbf{column} $j$.\n\n%\\centering\n\n%\\includegraphics[width=0.5\\textwidth]{Matris.png}\n%\\textbf{Indices in a matrix}\n\\end{textbox}\n\n\\begin{textbox}{$A$ - Adjacency matrix}\nThe most natural way to represent a graph as a matrix is called the Adjacency matrix $A$. It is defined as a square matrix, such as the number of rows (and the number of columns) is equal to the number of nodes $N$ in the graph. Nodes of the graph are numbered from 1 to $N$, and there is an edge between nodes $i$ and $j$ if the corresponding position of the matrix $A_{ij}$ is not $0$.\n\n\\begin{itemize}\n    \\item A value on the diagonal means that the corresponding node has a \\textbf{self-loop}\n    \\item the graph is \\textbf{undirected}, the matrix is \\textbf{symmetric}: $A_{ij}=A_{ji}$ for any $i,j$.\n    \\item In an \\textbf{unweighted} network, and edge is represented by the value $1$.\n    \\item In a \\textbf{weighted} network, the value $A_{ij}$ represents the \\textbf{weight} of the edge $(i,j)$\n\n\\end{itemize}\n\\end{textbox}\n\n\n\\begin{textbox}{Typical operations on $A$}\nSome operations on Adjacency matrices have straightforward interpretations and are frequently used, such as \\textbf{Multiplying} $A$ by \\textbf{itself} and \\textbf{Multiplying} $A$ by a \\textbf{column vector}\n\\end{textbox}\n\n\n\\begin{textbox}{Multiplying $A$ by itself}\n\n\n\\textbf{Multiplying} $A$ by \\textbf{itself} allows to know the number of walks of a given length that exist between any pair of nodes: $A^2_{ij}$ corresponds to the number of walks of length 2 from node $i$ to node $j$, $A^3_{ij}$ to the number of walks of length 3, etc.\n\\end{textbox}\n\n\\begin{textbox}{Multiplying $A$ by a column vector}\n\n\\textbf{Multiplying} $A$ by a \\textbf{column vector} $W$ of length $1\\times N$ can be thought as setting the $i$ th value of the vector to the $i$th node, and each node \\textit{sending} its value to its neighbors (for undirected graphs). The result is a column vector with $N$ elements, the $i$th element corresponding to the sum of the values of its neighbors in $W$. This is convenient when working with \\textbf{random walks} or \\textbf{diffusion} phenomenon.\n\\end{textbox}\n\n\n\n\n\n\n\n\n\n\n\\begin{textbox}{Spectral properties of $A$}\n\\textbf{Spectral Graph Theory} is a whole field in itself, and beyond the scope of this class. A few elements for those with a \\textit{linear algebra} background:\n\n\\begin{itemize}\n    \\item The adjacency matrix of an undirected simple graph is symmetric, and therefore has a complete set of real eigenvalues and an orthogonal eigenvector basis.\n    \\item The set of eigenvalues of a graph is the spectrum of the graph.\n    \\item The $n$ eigenvalues are denoted as $\\lambda_0 \\leq \\lambda_1 \\leq \\lambda_2 \\leq \\dots \\lambda_{\\max}$\n    \\item The largest eigenvalue $\\lambda_{\\max}$ lies between the average and maximum degrees.\n    \\item In a large, sparse random graph, $\\lambda_{\\max}\\approx \\langle k \\rangle$\n    \\item The number of closed walks of length $k$ in $G$ equals $\\sum^n_{i=0} \\lambda^k_i$\n    \\item A graph is bipartite if and only if its spectrum is symmetric (i.e., if $\\lambda$ is an eigenvalue, then so is $-\\lambda$\n    \\item If $G$ is connected, then the diameter of $G$ is strictly less than its number of distinct eigenvalues\n\\end{itemize}\n\n\n\\end{textbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\begin{textbox}{Graph Laplacian}\nThe \\textbf{Graph Laplacian}, or \\textbf{Laplacian Matrix} of a graph is a variant of the Adjacency matrix, often used in \\textit{Spectral Graph Theory}.\n\nIt is defined as $D-A$, with $D$ the \\textit{Degree matrix} of the graph, defined as a $N \\times N$ matrix with $D_{ii}=k_i$ and zeros everywhere else.\n\\end{textbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\begin{textbox}{Matrix notation - Example}\n\\begin{multibox}{2}\n\\begin{subbox}{white}{\\textcolor{black}{Graph}}\n\\centering\n%\\includegraphics[width=\\textwidth]{CheatSheet_pic.pdf}\n\\adjustbox{width=0.8\\textwidth }{\n%\\scalebox{1}[0.5]{\n%\\rotatebox[90]{\n\\begin{tikzpicture}[scale=0.3,rotate=0][every node/.style={inner sep=0,outer sep=0}]\n\\clip (0,-0.5) rectangle (6,6.5);\n\\Vertex[x=1.781,y=1.331,size=0.3,opacity=0.8,label=1]{0}\n\\Vertex[x=3.083,y=3.151,size=0.3,opacity=0.8,label=2]{1}\n\\Vertex[x=2.831,y=0.200,size=0.3,opacity=0.8,label=6]{5}\n\\Vertex[x=4.058,y=1.136,size=0.3,opacity=0.8,label=5]{4}\n\\Vertex[x=4.219,y=5.643,size=0.3,opacity=0.8,label=3]{2}\n\\Vertex[x=2.386,y=5.800,size=0.3,opacity=0.8,label=4]{3}\n\\Edge[](0)(1)\n\\Edge[](0)(5)\n\\Edge[](0)(4)\n\\Edge[](1)(2)\n\\Edge[](1)(3)\n\\Edge[](1)(4)\n\\Edge[](1)(5)\n\\Edge[](5)(4)\n\\Edge[](4)(4)\n\\Edge[](2)(3)\n\\end{tikzpicture}\n}%\\end{resizebox}\n\\end{subbox}\n\\begin{subbox}{white}{\\textcolor{black}{$A$ - Adjacency Mat.}}\n\\centering\n\\footnotesize\n\\[\\begin{pmatrix}\n  0  &  1  &  0  &  0  &  1  &  1 \\\\\n  1  &  0  &  1  &  1  &  1  &  1 \\\\\n  0  &  1  &  0  &  1  &  0  &  0 \\\\\n  0  &  1  &  1  &  0  &  0  &  0 \\\\\n  1  &  1  &  0  &  0  &  1  &  1 \\\\\n  1  &  1  &  0  &  0  &  1  &  0 \n\\end{pmatrix}\n\\]\n\\end{subbox}\n\n\n\\begin{subbox}{white}{\\textcolor{black}{$D$ - Degree Matrix}}\n\\centering\n\\footnotesize\n\\[\\begin{pmatrix}\n  3  &  0  &  0  &  0  &  0  &  0 \\\\\n  0  &  5  &  0  &  0  &  0  &  0 \\\\\n  0  &  0  &  2  &  0  &  0  &  0 \\\\\n  0  &  0  &  0  &  2  &  0  &  0 \\\\\n  0  &  0  &  0  &  0  &  5  &  0 \\\\\n  0  &  0  &  0  &  0  &  0  &  3 \n\\end{pmatrix}\n\\]\n\\end{subbox}\n\\begin{subbox}{white}{\\textcolor{black}{$L$ - Laplacian }}\n\\centering\n\\footnotesize\n\\[\n\\setlength\\arraycolsep{1pt}\n\\begin{pmatrix}\n  3  & -1  &  0  &  0  & -1  & -1 \\\\\n -1  &  5  & -1  & -1  & -1  & -1 \\\\\n  0  & -1  &  2  & -1  &  0  &  0 \\\\\n  0  & -1  & -1  &  2  &  0  &  0 \\\\\n -1  & -1  &  0  &  0  &  4  & -1 \\\\\n -1  & -1  &  0  &  0  & -1  &  3 \n\\end{pmatrix}\n\\]\n\\end{subbox}\n\\begin{subbox}{white}{\\textcolor{black}{ $A^2$}}\n\\centering\n\\footnotesize\n\\[\\begin{pmatrix}\n  3  &  2  &  1  &  1  &  3  &  2 \\\\\n  2  &  5  &  1  &  1  &  3  &  2 \\\\\n  1  &  1  &  2  &  1  &  1  &  1 \\\\\n  1  &  1  &  1  &  2  &  1  &  1 \\\\\n  3  &  3  &  1  &  1  &  4  &  3 \\\\\n  2  &  2  &  1  &  1  &  3  &  3 \n\\end{pmatrix}\n\\]\n\\end{subbox}\n\\begin{subbox}{white}{\\textcolor{black}{ Random W. mat.}}\n\\centering\n\\footnotesize\n\\setlength\\arraycolsep{3pt}\n\\[\\begin{pmatrix}\n  0 &  \\frac{1}{5} &  0 &  0 &  \\frac{1}{4} &  \\frac{1}{3}\\\\[6pt]\n  \\frac{1}{3} &  0 &  \\frac{1}{2} &  \\frac{1}{2} &  \\frac{1}{4} &  \\frac{1}{3}\\\\[6pt]\n  0 &  \\frac{1}{5} &  0 &  \\frac{1}{2} &  0 &  0\\\\[6pt]\n  0 &  \\frac{1}{5} &  \\frac{1}{2} &  0 &  0 &  0\\\\[6pt]\n  \\frac{1}{3} & \\frac{1}{5} &  0 &  0 &  \\frac{1}{4} &  \\frac{1}{3}\\\\[6pt]\n  \\frac{1}{3} &  \\frac{1}{5} &  0 &  0 &  \\frac{1}{4} &  0\n \\end{pmatrix}\n\\]\n\\end{subbox}\n\n\n\n\\end{multibox}\n\\end{textbox}\n\n\n\n\n\n\n\n\n\n\\begin{textbox}{Laplace Operator}\n\nIntuitively, the Laplace operator is a generalization of the second derivative, and is defined in discrete situations, for each value, as the sum of differences between the value and its \"neighbors\". e.g., in time, the 2\\textsuperscript{nd} derivative \\textit{acceleration} is the difference between current speed and previous speed. In a B\\&W picture, it's the difference between the greylevel on current pixel and the greylevel of 4 or 8 closest pixels, and perform \\textit{edge detection}. On a graph, with $W$ a column vector representing values on nodes, $LW$ computes for each node the difference to neighbors. \n\\end{textbox}\n\n\n\n\n\\begin{textbox}{Spectral properties of $L$}\nEigenvalues of the Laplacian have many applications, such as \\textit{spectral clustering}, \\textit{graph matching}, \\textit{embedding}, etc. Assuming $G$ undirected with eigenvalues $\\lambda_0 \\leq \\lambda_1 \\leq \\lambda_2 \\leq \\dots \\lambda_n$, here are some interesting properties:\n\n\\begin{itemize}\n    \\item The smallest eigenvalue $\\lambda_i$ equals 0\n    \\item The number of 0 eigenvalues gives the number of connected components\n\\end{itemize}\n\n\\end{textbox}\n\n\n\\begin{textbox}{Random Walk matrix}\nAnother useful matrix of a graph is the \\textbf{Random Walk Transition Matrix} $R$. It is the column normalized version of the adjacency matrix. $R_{ij}$ can be understood as the probability for a random walker located on node $i$ to move to $j$.\n\n\\end{textbox}\n\n\n\\begin{textbox}{Going Further}\n\\begin{itemize}\n    \\item Introduction to spectral graph theory (\\cite{nica2016brief})\n    \\item Survey on Graph Spectral Theory (\\cite{spielman2012spectral})\n\n    \\item Book on Graph Spectral Theory (\\cite{chung1997spectral})\n    \\item Spectral graph Clustering (\\cite{nascimento2011spectral})\n    \\item Wavelets on graph (\\cite{hammond2011wavelets})\n\n\\end{itemize}\n\n\n\n\n\n\n\n\n\\end{textbox}\n\n\n\n\n\n\\input{tail}\n\n\\end{document}\n\n", "meta": {"hexsha": "bf90684b839d3f08ad8062c43ffd65ae5d6609b3", "size": 9158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "latex_sources/Matrices.tex", "max_stars_repo_name": "Yquetzal/NetworkScience_CheatSheets", "max_stars_repo_head_hexsha": "0e5e7680504599b1a88c0bb0043803c06e0e110b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2022-01-26T06:33:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T23:25:49.000Z", "max_issues_repo_path": "latex_sources/Matrices.tex", "max_issues_repo_name": "Yquetzal/NetworkScience_CheatSheets", "max_issues_repo_head_hexsha": "0e5e7680504599b1a88c0bb0043803c06e0e110b", "max_issues_repo_licenses": ["MIT"], "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_sources/Matrices.tex", "max_forks_repo_name": "Yquetzal/NetworkScience_CheatSheets", "max_forks_repo_head_hexsha": "0e5e7680504599b1a88c0bb0043803c06e0e110b", "max_forks_repo_licenses": ["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.4252491694, "max_line_length": 617, "alphanum_fraction": 0.65429133, "num_tokens": 3344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042765, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6318416687431789}}
{"text": "\\section{Basic probability lemmas}\n\\label{sec:probability}\n\n% ARUN: We don't need this any more.\n% \\begin{lemma}[Mean and variance of the sum of two random variables]\n% \\label{lem:combined-variance}\n%   Let $x$ and $y$ be two random variables with mean $0$, variances $\\sigma^2_x$ and $\\sigma^2_y$ and a correlation coefficient of $\\rho$.\n%   Then, the estimator $z = \\alpha x + (1-\\alpha) y$, where $0 \\le \\alpha\n%   \\le 1$ also has mean $0$ and has minimum variance $\\sigma^2_z$ when\n%   \\begin{align*}\n%   \\alpha &= \n%   \\begin{cases}\n%     0 & \\rho > \\frac{\\sigma_x}{\\sigma_y} \\\\\n%     1 & \\rho > \\frac{\\sigma_x}{\\sigma_y} \\\\\n%     \\frac{\\sigma_y (\\sigma_y - \\rho \\sigma_x)}{\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y} & \\text{otherwise},\n%   \\end{cases}\n%   &\n%   \\sigma^2_z &= \n%   \\begin{cases}\n%     \\sigma^2_y & \\rho > \\frac{\\sigma_x}{\\sigma_y} \\\\\n%     \\sigma^2_x & \\rho > \\frac{\\sigma_x}{\\sigma_y} \\\\\n%     \\frac{\\sigma_x^2 \\sigma_y^2 (1 - \\rho^2)}{\\sigma_x^2 + \\sigma_y^2 - 2 \\rho \\sigma_x \\sigma_y} & \\text{otherwise}.\n%   \\end{cases}\n%   \\end{align*}\n% \n%   In general, if $x_i$ are uncorrelated random variables, $z = \\sum_{i} \\alpha_i x_i$ where $\\sum_i \\alpha_i = 1$ has mean and optimal variance,\n%   $$\\frac{1}{\\sigma_z^2} = \\sum_i \\frac{1}{\\sigma_i^2}.$$\n% \\end{lemma}\n% \\begin{proof}\n%   \\newcommand{\\alphab}{\\bar{\\alpha}}\n%   For notational convenience, let $\\alphab \\eqdef 1 - \\alpha$.\n%   That $z$ has mean $0$ follows directly from the linearity of expectations.\n%   The variance of $z$ can be calculated as follows:\n%   \\begin{align*}\n%     \\sigma^2_z &\\eqdef \\var(z) \n%     &= \\E[z^2] - {\\E[z]}^2 \\\\\n%     &= \\E[{(\\alpha x+ \\alphab y)}^2] - 0 \\\\\n%             &= \\E[\\alpha^2 x^2 + \\alphab^2 y^2 + 2 \\alpha \\alphab x y] \\\\\n%             &= \\alpha^2 \\sigma_x^2 + \\alphab^2 \\sigma_y^2 + 2 \\alpha \\alphab \\E[x y] \\\\\n%             &= \\alpha^2 \\sigma_x^2 + \\alphab^2 \\sigma_y^2 + 2 \\alpha \\alphab \\rho \\sigma_x \\sigma_y,\n%   \\end{align*}\n%   using the fact that $\\rho \\eqdef \\frac{\\E[xy]}{\\sigma_x \\sigma_y}$.\n% \n%   We introduce Lagrange multipliers $\\lambda_1, \\lambda_2 \\ge 0$ to handle the constraint that $0 \\le \\alpha \\le 1$,\n%   \\begin{align*}\n%     \\sL &= \n%     \\alpha^2 \\sigma_x^2 + \\alphab^2 \\sigma_y^2 + 2 \\alpha \\alphab \\rho \\sigma_x \\sigma_y\n%     + \\lambda_1 \\alpha + \\lambda_2 \\alphab \\\\\n%     \\frac{d}{d\\alpha} \\sL &= \n%     2 \\alpha \\sigma_x^2 - 2(1 - \\alpha) \\sigma_y^2 + 2 (1 - 2\\alpha) \\rho \\sigma_x \\sigma_y + \\lambda_1 - \\lambda_2\n% &= \n%     2 (\\alpha (\\sigma_x^2 + \\sigma_y^2 - 2 \\rho \\sigma_x\\sigma_y) - \\sigma_y^2 + \\rho \\sigma_x \\sigma_y + \\lambda'_1 - \\lambda'_2),\n%   \\end{align*}\n%   where $\\lambda'_1$ and $\\lambda'_2$ are suitably redefined to absorb the constant.\n% \n%   This quantity is minimized when the gradient with respect $\\alpha$ is $0$,\n%   \\begin{align*}\n%     \\alpha (\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y) &= \\sigma_y^2 - \\rho \\sigma_x \\sigma_y + \\lambda'_2 - \\lambda'_1 \\\\\n%     \\alpha &= \\frac{\\sigma_y^2 - \\rho \\sigma_x \\sigma_y + \\lambda'_2 - \\lambda'_1}{\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y} \\\\\n%     \\alphab &= \\frac{\\sigma_x^2 - \\rho \\sigma_x \\sigma_y - \\lambda'_2 + \\lambda'_1}{\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y}.\n%   \\end{align*}\n% \n%   The KKT conditions give us that $\\lambda'_1 \\alpha = 0$ and $\\lambda'_2 (1-\\alpha) = 0$, which implies that only one of $\\lambda'_1$ or $\\lambda'_2$ are non-zero.\n%   We can see that $\\alpha = 0$ when $\\sigma_y^2 - \\rho \\sigma_x \\sigma_y < 0$, or when $\\rho \\ge \\frac{\\sigma_y}{\\sigma_x}$.\n%   Likewise, $\\alpha = 1$ when $\\sigma_x^2 - \\rho \\sigma_x \\sigma_y < 0$, or when $\\rho \\ge \\frac{\\sigma_x}{\\sigma_y}$.\n%   This gives us the result on $\\alpha$.\n% \n%   The value of $\\sigma_z^2$ when $\\alpha = 0$ or $\\alpha=1$ is simply $\\sigma_y^2$ or $\\sigma_x^2$.\n%   When $0 < \\alpha < 1$, it is,\n%   \\begin{align*}\n%     \\sigma_z^2\n%             &= \\frac{%\n%             \\sigma_x^2 \\sigma_y^2 {(\\sigma_y - \\rho \\sigma_x)}^2\n%             + \\sigma_x^2 \\sigma_y^2 {(\\sigma_x - \\rho \\sigma_y)}^2\n%             + 2 \\rho \\sigma_x^2 \\sigma_y^2 (\\sigma_y - \\rho \\sigma_x) (\\sigma_x - \\rho \\sigma_y)}{%\n%             {(\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y)}^2\n%             }\\\\\n%             &= \\sigma_x^2 \\sigma_y^2 \n%             \\frac{%\n%              \\sigma_y^2 + \\rho^2 \\sigma_x^2 - 2 \\rho \\sigma_x \\sigma_y \n%             + \\sigma_x^2 + \\rho^2 \\sigma_y^2 - 2 \\rho \\sigma_x \\sigma_y \n%             + 2 \\rho (\\sigma_x \\sigma_y - \\rho \\sigma_y^2 - \\rho \\sigma_x^2 + \\rho^2 \\sigma_x \\sigma_y)}{%\n%             {(\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y)}^2\n%             }\\\\\n%             &= \\sigma_x^2 \\sigma_y^2 \n%             \\frac{%\n%              (1 - \\rho^2) (\\sigma_x^2 + \\sigma_y^2 - 2 \\rho \\sigma_x \\sigma_y)}{%\n%              {(\\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y)}^2\n%             }\\\\\n%             &= \n%             \\frac{(1 - \\rho^2) \\sigma_x^2 \\sigma_y^2}{%\n%               \\sigma_x^2 + \\sigma_y^2 - 2\\rho \\sigma_x \\sigma_y\n%             }\\\\\n%   \\end{align*}\n% \\end{proof}\n\n\\begin{lemma}[Mean and variance of the product of two random variables]\n\\label{lem:variance-product}\n  Let $x$ and $y$ be two independent random variables with means $\\mu_x$ and $\\mu_y$, and variances $\\sigma^2_x$ and $\\sigma^2_y$.\n  Then, the estimator $z = x y$ has mean $\\mu_x \\mu_y$ and variance\n  $$\\sigma^2_z = \\sigma_x^2 \\sigma_y^2 + \\mu_x^2 \\sigma_y^2 + \\sigma_x^2 \\mu_y^2.$$\n\\end{lemma}\n\\begin{proof}\n  If $x$ and $y$ are independent, $\\E[xy] = \\E[x]\\E[y]$. Thus $\\E[z] = \\mu_x \\mu_y$.\n\n  The variance of $z$ can be calculated as follows:\n  \\begin{align*}\n    \\var(z) &= \\E[z^2] - {\\E[z]}^2 \\\\\n    &= \\E[{(xy)}^2] - {\\E[xy]}^2 \\\\\n            &= \\E[x^2] \\E[y^2] - {\\E[x]}^2 {\\E[y]}^2 \\\\\n            &= (\\sigma^2_x + \\mu_x^2)(\\sigma^2_y + \\mu_y^2) - \\mu_x^2 \\mu_y^2 \\\\\n            &= \\sigma_x^2 \\sigma_y^2 + \\mu_x^2 \\sigma_y^2 + \\sigma_x^2 \\mu_y^2 + \\mu_x^2 \\mu_y^2 - \\mu_x^2 \\mu_y^2 \\\\\n            &= \\sigma_x^2 \\sigma_y^2 + \\mu_x^2 \\sigma_y^2 + \\sigma_x^2 \\mu_y^2.\n  \\end{align*}\n\\end{proof}\n\n\\begin{lemma}[Mean and variance of the ratio of two random variables]\n\\label{lem:variance-ratio}\n  Let $x$ and $y$ be two random variables such that $y$ is strictly positive (i.e.\\ $y > 0$) with means $\\mu_x$ and $\\mu_y$, variances $\\sigma^2_x$ and $\\sigma^2_y$. % and correlation $\\rho$.\n  %Furthermore, $y$ has positive support (i.e.\\ $y > 0$). \n  Then, the first-order Taylor approximation of $z = x / y$ has mean $\\mu_x / \\mu_y$.\n  %and variance\n  %$$\\sigma^2_z \\approx \\frac{\\mu^2_x}{\\mu_y^2} \\left(\\frac{\\sigma_x^2}{\\mu_x^2} \n  %  + 2\\rho \\frac{\\sigma_x \\sigma_y}{\\mu_x \\mu_y}\n  %  + \\frac{\\sigma_y^2}{\\mu_y^2} \\right).$$\nFurthermore, if $x$ and $y$ are the mean of a $n_x$ and $n_y$ independent random variables, \nthe approximation error of using the first-order approximation goes to 0 as $n_x, n_y \\to \\infty$.\n\\end{lemma}\n\\begin{proof}\n  This is a standard result in statistics. For completeness, we provide a proof below. \n\n  Let $f(x,y) = \\frac{x}{y}$.\n  Even if $x$ and $y$ are independent, $\\E[f(x,y)]$ is not necessarily equal to $f(\\E[x],\\E[y])$.\n  However, taking a first-order Taylor expansion around $(\\mu_x, \\mu_y)$, we get\n  \\begin{align*}\n    \\E[f(x,y)] \n     &\\approx f(\\mu_x,\\mu_y) + f_x'(\\mu_x, \\mu_y) \\E[x - \\mu_x] + f'_y(\\mu_x, \\mu_y) \\E[y - \\mu_y] \\\\\n     &= \\frac{\\mu_x}{\\mu_y}.\n  \\end{align*}\n\n % Taking a similar approach to calculate variance, we get,\n % \\begin{align*}\n %   \\var(f(x,y)) \n %   &\\approx \\E[{(f(x,y) - \\E[f(x,y)])}^2] \\\\\n %            &= \\E[{(f(\\mu_x,\\mu_y) + f'_x(\\mu_x, \\mu_y) (x - \\mu_x) + f'_y(\\mu_x, \\mu_y) (y - \\mu_y) - f(\\mu_x, \\mu_y))}^2] \\\\\n %            &= {f'_x(\\mu_x, \\mu_y)}^2 \\E[{(x - \\mu_x)}^2] + {f'_y(\\mu_x, \\mu_y)}^2 \\E[{(y - \\mu_y)}^2] \n %             + 2 f'_x(\\mu_x, \\mu_y)f'_y(\\mu_x, \\mu_y) \\E[(x - \\mu_x)(y - \\mu_y)]\\\\\n %             &= {f'_x(\\mu_x, \\mu_y)}^2 \\sigma_x^2 + {f'_y(\\mu_x, \\mu_y)}^2 \\sigma_y^2\n %             + 2 f'_x(\\mu_x, \\mu_y)f'_y(\\mu_x, \\mu_y) \\rho \\sigma_x \\sigma_y.\n % \\end{align*}\n % Noting that $f'_x(\\mu_x, \\mu_y) = \\frac{1}{\\mu_y}$ and that $f'_y(\\mu_x, \\mu_y) = -\\frac{\\mu_x}{\\mu_y^2}$, we get,\n % \\begin{align*}\n %   \\var(f(x,y)) \n %   &\\approx \\frac{\\sigma_x^2}{\\mu_y^2} + \\frac{\\sigma_y^2 \\mu_x^2}{\\mu_y^4}\n %   + 2 \\frac{\\mu_x}{\\mu_y^3} \\rho \\sigma_x \\sigma_y \\\\\n %   &= \\frac{\\mu^2_x}{\\mu_y^2} \\left(\\frac{\\sigma_x^2}{\\mu_x^2} \n %   + 2\\rho \\frac{\\sigma_x \\sigma_y}{\\mu_x \\mu_y}\n %   + \\frac{\\sigma_y^2}{\\mu_y^2} \\right).\n %\\end{align*}\n\n  We note that if $x$ and $y$ are the sum of independent random variables, then by the central limit theorem all moments of $x$ and $y$ greater than $1$ go to $0$ as $n_x, n_y \\to \\infty$.\n\n\\end{proof}\n\n%\\begin{lemma}[Mean and variance of a importance-weighted estimate.]\n%\\label{lem:variance-ratio-average}\n%  Let $p_i$ and $q_i$ be two sets of independent random variables with means $\\mu$ and $\\xi$ and variances $\\sigma^2$ and $\\pi^2$ respectively.\n%  Then, $z = \\frac{\\sum_{i=1}^n p^2_i q_i}{\\sum_{i=1}^n p_i}$ has mean $\\xi$ and variance,\n%  $$\\sigma^2_z \\approx\n%  \\frac{\\mu^2 \\xi^2}{n} {\\left( 1 + \\frac{\\sigma^2}{\\mu^2} \\right)}^2\n%             \\left(\n%                9 \\frac{\\sigma^2}{\\mu^2} + 4 \\frac{\\pi^2}{\\xi^2}\n%                \\right).$$\n%\\end{lemma}\n%\\begin{proof}\n%  From \\reflem{variance-ratio} we have that\n%  $$\\sigma^2_z \\approx \\frac{\\mu^2_x}{\\mu_y^2} \\left(\\frac{\\sigma_x^2}{\\mu_x^2} \n%    + 2\\rho \\frac{\\sigma_x \\sigma_y}{\\mu_x \\mu_y}\n%    + \\frac{\\sigma_y^2}{\\mu_y^2} \\right),$$\n%    where $x = \\frac{1}{n}\\sum_{i=1}^n p_i^2 q_i$ and $y = \\frac{1}{n}\\sum_{i=1}^n p_i$.\n%\n%  In the following, we will make Gaussian assumptions on any moments $>3$ and ignore variance squared terms, e.g. $\\sigma^4 \\approx 0$.\n%  Thus,\n%  \\begin{align*}\n%    \\E[x^3] &\\approx 3\\sigma_x^2 \\mu_x + \\mu_x^3 \\\\\n%    \\E[x^4] &\\approx 6\\sigma_x^2 \\mu_x^2 + \\mu_x^4 \\\\\n%    \\var[x^2] &= \\E[x^4] - {\\E[x^2]}^2 \\\\\n%              &\\approx 6\\sigma_x^2 \\mu_x^2 + \\mu_x^4 - {(\\mu_x^2 + \\sigma_x^2)}^2 \\\\\n%              &= 4\\sigma_x^2 \\mu_x^2 \n%  \\end{align*}\n%  \n%  Let us solve for each term independently,\n%  \\begin{align*}\n%    \\mu_x &= (\\sigma^2 + \\mu^2) \\xi \\\\\n%          &= \\mu^2 \\xi (1 + \\frac{\\sigma^2}{\\mu^2}) \\\\\n%    \\mu_y &= \\mu \\\\\n%    \\sigma_x^2 &\\approx \\frac{1}{n} (\\var[{p_i^2}] \\xi^2 + {(\\sigma^2 + \\mu^2)}^2 \\pi^2) \\\\\n%               &<  \\frac{1}{n} (4 \\mu^2 \\sigma^2 \\xi^2 + 4 \\mu^4 \\pi^2) \\\\\n%               &= \\frac{4}{n} \\mu^4 \\xi^2 \\left( \\frac{\\sigma^2}{\\mu^2}  + \\frac{\\pi^2}{\\xi^2} \\right) \\\\\n%    \\sigma_y^2 &= \\frac{1}{n} \\sigma^2.\n%  \\end{align*}\n%\n%  Finally, for $\\rho \\sigma_x \\sigma_y = \\E[x y] - \\mu_x \\mu_y$, we get,\n%  \\begin{align*}\n%      \\rho \\sigma_x \\sigma_y &\\eqdef \\E[(\\sum_{i=1}^n p^2_i q_i)(\\sum_{j=1}^n p_j)] -  \\E[(\\sum_{i=1}^n p^2_i q_i)]\\E[(\\sum_{j=1}^n p_j)]\\\\\n%           &= \\sum_{i=1}^n \\E[p^3_i] \\E[q_i] - \\E[p^2_i] \\E[q_i] \\E[p_i] \\\\\n%           &= \\sum_{i=1}^n (\\E[p^3_i] - \\E[p^2_i] \\E[p_i]) \\E[q_i] \\\\\n%           &= \\frac{1}{n} (3\\sigma^2 \\mu + \\mu^3 - (\\sigma^2 + \\mu^2) \\mu) \\xi \\\\\n%           &= \\frac{2}{n} \\sigma^2 \\mu \\xi.\n%  \\end{align*}\n%  noting that all other terms are 0.\n%\n%  Putting all of these together, we get,\n%  \\begin{align*}\n%    \\sigma_z^2 &< \n%    \\mu^2 \\xi^2 {(1 + \\frac{\\sigma^2}{\\mu^2})}^2\n%           \\left(\n%           \\frac{4}{n} (\\frac{\\sigma^2}{\\mu^2} + \\frac{\\pi^2}{\\xi^2})\n%              +\n%              \\frac{4}{n} \\frac{\\sigma^2 \\mu \\xi}{\\mu^2 \\xi \\mu}\n%              +\n%              \\frac{1}{n} \\frac{\\sigma^2}{\\mu^2}\n%              \\right) \\\\\n%           &=\n%           \\frac{\\mu^2 \\xi^2}{n} {\\left( 1 + \\frac{\\sigma^2}{\\mu^2} \\right)}^2\n%             \\left(\n%                9 \\frac{\\sigma^2}{\\mu^2} + 4 \\frac{\\pi^2}{\\xi^2}\n%                \\right).\n%  \\end{align*}\n%\n%\n%\n%\\end{proof}\n", "meta": {"hexsha": "b7577832c5fc11e610f1efc8417584430c044dfd", "size": 11792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/emnlp2017/basic-lemmas.tex", "max_stars_repo_name": "arunchaganty/kbp-online", "max_stars_repo_head_hexsha": "9f8763d8f4bfb1fb8a01f1f4f506f56625dd38d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-09T14:05:48.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-25T01:34:23.000Z", "max_issues_repo_path": "doc/emnlp2017/basic-lemmas.tex", "max_issues_repo_name": "arunchaganty/kbp-online", "max_issues_repo_head_hexsha": "9f8763d8f4bfb1fb8a01f1f4f506f56625dd38d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-01-19T23:18:18.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-23T18:57:54.000Z", "max_forks_repo_path": "doc/emnlp2017/basic-lemmas.tex", "max_forks_repo_name": "arunchaganty/kbp-online", "max_forks_repo_head_hexsha": "9f8763d8f4bfb1fb8a01f1f4f506f56625dd38d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-08-08T09:48:20.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-09T09:12:43.000Z", "avg_line_length": 50.3931623932, "max_line_length": 191, "alphanum_fraction": 0.5437584803, "num_tokens": 4759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6318416533085893}}
{"text": "% !TEX root = index.tex\n\n\\section{Gluing it Back Together}\n\\epigraph{The only way to learn mathematics is to do mathematics.}{Paul Halmos}\n\\begin{align*}\n \\xymatrix@R-2pc{\n\\U \\ar@{~>}[r] & \\L^\\bullet(\\U) \\ar@{~>}[r] & \\check H^*(X)\\\\\n \\mbox{Good cover of } X & \\mbox{Cech Complex of } \\U & \\mbox{Cech Cohomology of } X\n }\n\\end{align*}\nWe'll now associate to any cover $\\U$ a cochain complex called the \\textbf{Cech complex} $\\L^{\\bullet}(\\U)$. To define the complex we need two things:\n\\begin{alignat*}{4}\n\t&\\mbox{the spaces: } &&& \\L^i(\\U)\\\\\n\t&\\mbox{the maps: } &&& d^i: \\L^i(\\U) \\rightarrow \\L^{i+1}(\\U)\n\\end{alignat*}\n\n\\begin{definition}\n\tThe \\textbf{direct sum} $V \\oplus V'$ of vector spaces $V$ and $V'$ with basis $\\B$ and $\\B'$ is a vector with basis the disjoint union $\\B \\sqcup \\B'$.\n\\end{definition}\n\\noindent \\textbf{Caution:} The disjoint union $\\{1,2 \\} \\sqcup \\{1,3\\}$ equals $\\{1, 2, 1', 3 \\}$ and is different from the union $\\{1, 2, 3 \\}$. We keep both the copies of 1. Hence, ${\\dim (V \\oplus V') = \\dim V  + \\dim V'}$.\n\n\\begin{ques} $ $\n\t\\begin{enumerate}\n\t\t\\item What is $V \\oplus 0$? Is $V \\oplus V \\cong V$?\n\t\t\\item What is the relationship between $\\dim V$, $\\dim V'$ and $\\dim (V \\oplus V')$?\n\t\t\\item Does the set of all vector spaces form a group under $\\oplus$?\n\t\t\\item Construct $\\R^n$ using direct sums.\n\t\\end{enumerate}\n\\end{ques}\n\n\\subsection{The Spaces}\nRecall that to every subset $ I \\subseteq [n]$ we can associate an open set $U_I $ defined as\n\\begin{align*}\n\tU_I := \\bigcap_{i \\in I} U_i\n\\end{align*}\nFor good covers, the connected components of $U_I$ are contractible.\n\n\\begin{definition}\n\tFor $ 0 \\le k < n$, let $(U_{I_1}, U_{I_2}, \\dots, U_{I_m})$ denote the non-empty sets $U_I$ with $|I| = k+1$. Define\n\t\\begin{align*}\n\t\t\\L^k(\\U) := \\L(U_{I_1}) \\oplus \\L(U_{I_2}) \\oplus \\dots \\oplus \\L(U_{I_m})\n\t\\end{align*}\n\\end{definition}\n\\begin{example}\n  \\label{ex:triangle_2}\n\tFor the triangle with cover the three sides $U_1, U_2, U_3$\n  \\begin{align*}\n\t\t|I| = 0 &  & U_1, U_2, U_3                         \\\\\n\t\t|I| = 1 &  & U_{\\{1,2\\}}, U_{\\{2,3\\}}, U_{\\{1,3\\}}\n\t\\end{align*}\n\t\\begin{center}\n\t\t\\begin{tabular}{l c l c l }\n\t\t\t$\\L^0(\\U)$ & : & $\\L(U_1) \\oplus \\L(U_2) \\oplus \\L(U_3)$ & = & $\\F^3$\\\\\n\t\t\t$\\L^1(\\U)$ & : & $\\L(U_{\\{1,2\\}}) \\oplus \\L(U_{\\{1,3\\}}) \\oplus \\L(U_{\\{2,3\\}})$ & = & $\\F^3$\\\\\n\t\t\t$\\L^2(\\U)$ & : & $\\L(U_{\\{1,2,3\\}})$ & = & 0\\\\\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.6]\n\t\t\t%% vertices\n\t\t\t\\draw[fill=black] (0,0) circle (3pt);\n\t\t\t\\draw[fill=black] (4,0) circle (3pt);\n\t\t\t\\draw[fill=black] (2,3) circle (3pt);\n\t\t\t%% vertex labels\n\t\t\t\\node at (2,-0.5) {$U_1$};\n\t\t\t\\node at (0.5,1.75) {$U_2$};\n\t\t\t\\node at (3.5,1.75) {$U_3$};\n\t\t\t\\node at (2,-0.5) {$U_1$};\n\t\t\t\\node at (-1,0) {$U_{\\{1,2\\}}$};\n\t\t\t\\node at (5,0) {$U_{\\{1,3\\}}$};\n\t\t\t\\node at (2,3.5) {$U_{\\{2,3\\}}$};\n\t\t\t%%% edges\n\t\t\t\\draw[thick] (0,0) -- (4,0) -- (2,3) -- (0,0);\n\t\t\\end{tikzpicture}\n\t\t\\caption{$\\U = \\{U_1, U_2, U_3\\}$ is a good cover of the triangle, $U_{\\{1,2\\}}, U_{\\{2,3\\}}, U_{\\{1,3\\}}$ are the vertices, and $U_{\\{1,2,3\\}}$ is empty.}\n\t\t\\label{fig:triangle_cech}\n\t\\end{figure}\n\tSo that the cochain complex (without the differentials) looks like\n\t\\begin{align*}\n\t\t\\L^\\bullet(\\U) = \\xymatrix{ 0 \\ar[r] & \\F^3 \\ar[r] & \\F^3 \\ar[r] & 0 }\n\t\\end{align*}\n\\end{example}\n\n\\begin{ques}\n\tFind the Cech complex $\\L^\\bullet(\\U)$ (without the differentials) for each of the following spaces using your favorite good cover $\\U$. Compute the Euler characteristic $\\chi$ of each of the spaces. (Note that you don't need to know the differentials $d^i$ to compute $\\chi$.)\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\R^n$\n\t\t\t\\item $ S^1$ (= the circle)\n\t\t\t\\item A Tree\n\t\t\t\\item The bipartite graph $ K_{2,3}$\n\t\t\t\\item $ \\R^2 \\setminus \\{(0,0) \\}$\n\t\t\t\\item $ \\R^2 \\setminus \\{(0,0), (1,0), \\dots, (k,0) \\}$\n\t\t\t\\item $S^1 \\sqcup S^1$ (disjoint union of 2 circles)\n\t\t\t\\item $S^1 \\vee S^1$\n\t\t\t\\item $ S^2 $ minus a point\n\t\t\t\\item $ S^2 $ minus 2 points\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{ques}\n\n\n\\subsection{The Maps $d^i$}\nThe maps $d^i$ are simply the restriction maps $\\res$ as defined in Question \\ref{q:restrictions}.\n\\begin{ques}**\n  Describe $d^i$ as a matrix in the canonical bases without looking at the next page (which has the answer). Find the differential $d^i$ in Example \\ref{ex:triangle_2}.\n\\end{ques}\n\\newpage\n\n\\noindent In the canonical bases $d^i: \\L^i(\\U) \\rightarrow \\L^{i+1}(\\U)$ is a matrix whose\n\\begin{enumerate}\n  \\item Rows correspond to the number of connected components of $U_I$ for all $|I|=i+2$\n  \\item Columns correspond to the number of connected components of $U_J$ for all $|J| = i+1$\n  \\item The $(i,j)^{th}$ entry is 1 if and only if the $i^{th}$ connected component of $U_I$ contains the $j^{th}$ connected component of $U_J$.\n\\end{enumerate}\n\\begin{example}\n  \\label{ex:triangle_cech}\n\tFor a triangle in Figure \\ref{fig:triangle_cech} we have inclusions $U_{\\{1,2\\}} \\subseteq U_1$ etc., hence the differential $d^0$ looks like\n\t\\begin{center}\n\t\t\\begin{tabular}{ l | c c c  }\n\t\t\t& $U_1$ & $U_2$ & $U_3$ \\\\\\hline\n\t\t\t$U_{\\{1,2\\}}$ & 1 & 1 & 0 \\\\\n\t\t\t$U_{\\{2,3\\}}$ & 0 & 1 & 1 \\\\\n\t\t\t$U_{\\{1,3\\}}$ & 1 & 0 & 1\n\t\t\\end{tabular} $ = d^0$\n\t\\end{center}\n  So that\n    \\begin{align*}\n  \t\t\\L^\\bullet(\\U)\n      &=\n      0 \\rightarrow \\F^3 \\xrightarrow{\\begin{bmatrix}1 & 1 & 0 \\\\0 & 1 & 1 \\\\ 1 & 0 & 1 \\end{bmatrix}} \\F^3 \\rightarrow 0\n  \t\\end{align*}\n  \\end{example}\n\n  \\begin{example}\n    For the circle $S^1$ we can find a good cover consisting of two (slightly overlapping) semicircles.\n    \\label{ex:circle_cech}\n    \\begin{figure}[H]\n  \t\t\\centering\n  \t\t\\begin{tikzpicture}[scale=0.6]\n  \t\t\t%% vertices\n        \\draw (2,2) circle (2cm);\n  \t\t\t\\draw[fill=black] (0,2) circle (3pt);\n        \\draw[fill=black] (4,2) circle (3pt);\n        \\node at (2,4.5) {$U_1$};\n        \\node at (2,-0.5) {$U_2$};\n        \\node at (-0.5,1.5) {$a$};\n        \\node at (4.5,1.5) {$b$};\n  \t\t\\end{tikzpicture}\n  \t\t\\caption{$\\{U_1, U_2\\}$ is a good cover of the circle with $U_{\\{1,2\\}} = \\{ a, b \\}$}\n  \t\t\\label{fig:triangle_cech}\n  \t\\end{figure}\n    \\begin{align*}\n  \t\t|I| = 0 &  & U_1, U_2                         \\\\\n  \t\t|I| = 1 &  & U_{\\{1,2\\}}\n  \t\\end{align*}\n  \t\\begin{center}\n  \t\t\\begin{tabular}{l c l c l }\n  \t\t\t$\\L^0(\\U)$ & : & $\\L(U_1) \\oplus \\L(U_2)$ & = & $\\F^2$\\\\\n  \t\t\t$\\L^1(\\U)$ & : & $\\L(U_{\\{1,2\\}})$ & = & $\\F^2$\n  \t\t\\end{tabular}\n  \t\\end{center}\n\n    \\end{example}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\iffalse\n\\begin{example}\n  \\label{ex:triangle_cech}\n\tFor a triangle in Figure \\ref{fig:triangle_cech} we have the following non-empty sets\n\t\\begin{align*}\n\t\t|I| = 0 &  & U_1, U_2, U_3                         \\\\\n\t\t|I| = 1 &  & U_{\\{1,2\\}}, U_{\\{2,3\\}}, U_{\\{1,3\\}}\n\t\\end{align*}\n\tHence the spaces in the chain complex are\n\t\\begin{align*}\n\t\t0 \\rightarrow \\F^3 \\rightarrow \\F^3 \\rightarrow 0\n\t\\end{align*}\n\tBecause of the non-empty inclusions $U_{\\{1,2\\}} \\subseteq U_1$ etc. the differential looks like\n\t\\begin{center}\n\t\t\\begin{tabular}{ l | c c c  }\n\t\t\t& $U_1$ & $U_2$ & $U_3$ \\\\\\hline\n\t\t\t$U_{\\{1,2\\}}$ & 1 & 1 & 0 \\\\\n\t\t\t$U_{\\{2,3\\}}$ & 0 & 1 & 1 \\\\\n\t\t\t$U_{\\{1,3\\}}$ & 1 & 0 & 1\n\t\t\\end{tabular}\n\t\\end{center}\n  So that\n    \\begin{align*}\n  \t\t\\L^\\bullet(\\U)\n      &=\n      0 \\rightarrow \\F^3 \\xrightarrow{\\begin{bmatrix}1 & 1 & 0 \\\\0 & 1 & 1 \\\\ 1 & 0 & 1 \\end{bmatrix}} \\F^3 \\rightarrow 0\n  \t\\end{align*}\n  \\end{example}\n\n\\begin{ques}\nCompute the cohomology of the Cech Complex found in Example \\ref{ex:triangle_cech}.\n\\end{ques}\n\n\\begin{ques}\n  Find $\\check H(-)$ for the following spaces.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $ \\R^m$\n      \\item $ S^1 = $ the circle\n      \\item A Tree\n      % \\item The bipartite graph $ K_{2,3}$\n      \\item $ \\R^2 \\setminus \\{(0,0) \\}$\n      % \\item $ \\R^2 \\setminus \\{(0,0), (1,0), \\dots, (k,0) \\}$ for some positive integer $ k$\n      \\item $ S^2 $ minus a point\n      \\item $ S^2 $ minus 2 points\n    \\end{enumerate}\n  \\end{multicols}\n\\end{ques}\n\n\\begin{ques}\n  Find the cohomology of a finite planar graph (thought of as a subset of $\\R^2$).\n\\end{ques}\n\\fi\n", "meta": {"hexsha": "1bb0c0b0e186171f5b33853222bb4b4d3215ad71", "size": 8090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03_old.tex", "max_stars_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_stars_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_stars_repo_licenses": ["MIT"], "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_old.tex", "max_issues_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_issues_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_issues_repo_licenses": ["MIT"], "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_old.tex", "max_forks_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_forks_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_forks_repo_licenses": ["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.135021097, "max_line_length": 278, "alphanum_fraction": 0.5726823239, "num_tokens": 3385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.631841650454563}}
{"text": "\\subsection{Interaction Objective}\n\\label{text:approach/objective/interactive}\nThe interaction between robot and pedestrian itself is an abstract quantity and can thus hardly be used for optimization itself. In the following, we consider a scene with the robot facing only one pedestrian to approach this problem, then to generalize the developed concept to interactions with multiple pedestrians.  \n\\newline\nWhile it is hard to find a measure for the interaction between the robot and the pedestrian in the scene when regarding the problem in general, it can be simplified when a) focussing on one of the interacting agents and b) define the measure to vanish its value. Under these conditions, the problem can be re-formulated as decreasing the impact the robot induces on the pedestrian, which is a lot simpler to quantify than the abstract concept of interaction. To do so the un-conditioned\\footnote{For brevity the term \"un-conditioned\" means, not depending on the robot's state. However, the pedestrians trajectories predictions are of course still conditioned on its state history as well as the states and state history of the other pedestrians in the scene, as described in Section \\ref{text:approach/formulation}.} pedestrian's trajectory distribution $\\distwo[]$ is computed, i.e., the distribution that would occur if no robot would be in the scene, and then compared to its actual conditioned trajectory distribution $\\dist[]$.\\footnote{When the prediction model requires the input of a robot trajectory, e.g. as an \"input format\" requirement of a neural network-based model, predicting the un-conditioned trajectory distribution might not be straight-forward. Using a re-trained un-conditioned model is not an option since factors causing a different distribution independent from the robot's trajectory might come into play. Thus, within the project a \"pseudo\"-robot is used which is located very far away from any pedestrian, hence minimizing its effect on the pedestrian's behavior.} With some general distance measure $\\Delta(\\cdot, \\cdot)$ the interactive objective function given the robot's trajectory $\\x_{0:T}$ is defined as:\n\n\\begin{equation}\nJ_{int}^k(\\x_{0:T}) = \\sum_{t=0}^T \\Delta(\\dist[k]_t, \\distwo[k]_t)\n\\label{eq:objective_interaction}\n\\end{equation}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tikzpicture}\n\n    \\node[inner sep=0pt] (pedwo) at (-3,1)\n    {\\includegraphics[width=.05\\textwidth]{images/walking.png}};    \n    \\draw [dotted, ultra thick, name path=A] (pedwo) to[out=180, in=0] node[above] {$\\xpedwo[k]$} (-8, 1);\n    \n    \\node[inner sep=0pt] (pedw) at (-3,-1)\n    {\\includegraphics[width=.05\\textwidth]{images/walking.png}};\n    \\node[inner sep=0pt] (robot) at (-7,-1)\n    {\\includegraphics[width=.05\\textwidth]{images/robot.png}};\n    \\draw [ultra thick, name path=B] (pedw) to[out=180, in=10] node[below, sloped] {$\\xped[k]$}(-8,-3);\n    \n    \\draw[thick, decorate, decoration={brace, amplitude=20pt}] (-1.5,2) -- (-1.5,-2);\n\n    \\node[inner sep=0pt] (ped) at (5,0.5)\n    {\\includegraphics[width=.05\\textwidth]{images/walking.png}};\n    \n    \\draw [dotted, ultra thick, name path=A] (ped) to[out=180, in=0] node[above] {$\\xpedwo[k]$} (0, 0.5);\n    \\draw [ultra thick, name path=B] (ped) to[out=180, in=10] node[below, sloped] {$\\xped[k]$}(0,-1.5);\n        \n    \\tikzfillbetween[of=A and B]{blue, opacity=0.2};\n    \\node[] (D) at (1, -0.3){$D_{int}$};\n    \n\\end{tikzpicture}\n\\end{center}\n\\caption{Interactive measure in case of deterministic and uni-modal pedestrian trajectory predictions, which trivially is the area enclosed by the un-conditioned (upper) and the conditioned (middle) trajectory.}\n\\label{img:ado_w_wo_distance_trajectory}\n\\end{figure}\n\nIf the pedestrian's trajectory prediction would be deterministic and unimodal, this measure simply breaks down to the distance between both trajectories, which is the area enclosed by both trajectories in continuous time, as shown in Figure \\ref{img:ado_w_wo_distance_trajectory}, or a sum of distance per time-step in discrete time. For probabilistic and multimodal predictions, computing the distance between both distributions is more difficult, especially when demands such as computational cost and differentiability (to be used in an optimization) have to be factored in. \n\n%\\begin{figure}[!ht]\n%\\begin{center}\n%\\begin{tikzpicture}\n%\n%    \\node[inner sep=0pt] (ped) at (5,0)\n%    {\\includegraphics[width=.05\\textwidth]{images/walking.png}};\n%    \\node[inner sep=0pt] (robot) at (0,0)\n%    {\\includegraphics[width=.05\\textwidth]{images/robot.png}};\n%       \n%    \\draw [dotted, ultra thick, name path=A] (ped) to[out=180, in=0] (0, 2) node[above, sloped] {$\\xpedwo[k]$}  to[out=180, in=0] (-4, 0);\n%    \n%    \\draw [ultra thick, name path=B] (ped) to[out=180, in=10] (0,-2) node[below, sloped] {$\\xped[k]$} to[out=180, in=0] (-4, 0);\n%    \n%\\end{tikzpicture}\n%\\end{center}\n%\\caption{Interactive measure in case of deterministic and uni-modal pedestrian trajectory predictions, which trivially is the area enclosed by the un-conditioned (upper left) and the conditioned (upper right) trajectory.}\n%\\label{img:int_acceleration_reason}\n%\\end{figure}\n\nThe correlation between the acceleration carried out on a passenger and its comfort is widely known, e.g., for the driving use case \\cite{Hoberock1976}. Therefore, assuming that the same measure applies for correlation between the acceleration the pedestrian itself has to exert (e.g., to evade a dynamic obstacle) and its comfort is likely. \n\n% Therefore, instead of contrasting the position distributions, it might be valuable to use the velocity or acceleration distributions. Figure \\ref{img:int_acceleration_reason} shows a possible scenario in which the robot's presence affects the pedestrian such that the trajectory prediction is mirrored. When the robot is static, and when no other pedestrian is close, both trajectories are equally safe  and \"comfortable\" for the pedestrian. Also they are equal in length, so that there is no reason to chose one above the other. However, due to the large enclosed area, a purely position-based distance metric would be non-zero by far, while an acceleration-based distance metric would be zero since the velocities of the pedestrian-only change their sign, not their absolute value.\n\n\\subsubsection{Kullback-Leibler Divergence}\nA commonly used metric for expressing the distance between two distributions is the Kullback-Leibler Divergence $D_{KL}$, which determines the distance between  some distribution $q$ and another distribution $p$ as:\n\n\\begin{equation}\nD_{KL} = \\int_x q(x) log \\frac{q(x)}{p(x)} dx    \n\\end{equation}\n\n$D_{KL}$ is a well-defined loss term and commonly used in many applications, such as generative deep learning models \\cite{Goodfellow2014}\\cite{Salzmann2020} (similarly the Jenson-Shannon Divergence). However, it is not analytically defined for some \"complex\" distributions such as \\ac{GMM}s, the output distribution of Trajectron \\cite{Ivanovic2018}. Methods to approximate the KL-Divergence for \\ac{GMM}s have been discussed in \\cite{Cui2015} and embrace Monte Carlo sampling, signature quadratic form distance \\cite{Beecks2011}, and several more. All of these methods are not computationally feasible for an online application, especially when gradients have to be computed. Other methods simplify the real \\ac{GMM} to a single Gaussian, by a weighted average over its parameters, which is not guaranteed to be a meaningful distribution and loses the advantages of predicting multimodal distributions in the first place.\n\\newline\nRegarding the Trajectron \\cite{Ivanovic2018} as a prediction model, some intermediate distribution might be used for comparison instead of the output distribution, such as the categorical distribution in its latent space\\footnote{In fact, the Trajectron's latent space could not be used as a basis for the interactive objective function anyway, since it does not depend on the robot's trajectory. However, it might be used to assess the similarity between scenarios, which will be discussed in Section \\ref{text:approach/runtime/warm_starting}.}. Although this approach might give rise to using standard distance measures such as $D_{KL}$, it would impede interpretability and generality of the overall framework, as it would have to be redefined for every other prediction model.\n\n\\subsubsection{Trajectory Projection}\nCombining computational efficiency and the capability of representing a measure based on the full distribution is hard, as demonstrated in the examples above. However, by exploiting that the predicted distribution $\\xped[]_t \\sim \\dist[]_t$ is a continuous, well-defined distribution with infinite support \\footnote{Although not all distributions have infinite support, these properties surely hold for the most commonly used ones in the area of pedestrian prediction such as Gaussians, \\ac{GMM}s \\cite{Salzmann2020} or non-closed form distribution such as SGAN \\cite{Gupta2018}.}, \\ref{eq:objective_interaction} can be redefined as the probability of the unconditioned distribution $\\distwo[]_t$ with respect to the conditioned distribution $\\dist[]_t$ which is equivalent to the integral over the product distribution $\\int \\int \\distwo[]_t \\cdot \\dist[]_t \\, dxdy$.\n\\newline\nFor two \\ac{GMM}s, the distribution product is not analytically defined though and would involve numerically solving an \\ac{ODE} \\cite{Schrempf2005} or multi-scale sampling \\cite{Ihler2003}. Therefore as simplification, not the full un-conditioned distribution is taken into account but only its mean value $\\mathbb{E}[\\distwo[]_t]$ and weighted by the conditioned mode importance vector:\\footnote{A derivation of the exact objective formulation for a \\ac{GMM} as underlying distribution can be found in the appendix.}\n\n\\begin{equation}\nJ_{int}^k = - \\sum_{t=0}^T \\mathbb{E}_{\\dxped[k] \\sim \\dist[k]} \\log p(\\, \\mathbb{E}[\\distwo[k]_t] \\, | \\, \\dxped[k]_t, \\dx_t)\n\\label{eq:objective_interact_prob}\n\\end{equation}\n\nTo deal with reasonable large values, compared to the other objective functions, and for the independence of gradients (sum not product), instead of the \\ac{PDF} $p = pdf(x, y)$, its logarithmic value $\\log p$ probability is used. Since the product probability should be maximized while the optimization stated in Problem \\ref{problem:general} seeks the minimum, the expectation value's negative value is used. Note, that $\\dist[]$ and $\\distwo[]$ denote the distribution over velocities, not positions. This makes the objective independent from translational deviations along the trajectories.\n\\newline\nEquation \\ref{eq:objective_interact_prob} is efficient to compute as it can be batched over the full length of the trajectory and all modes. Also, it uses the full distribution and has a unique global minimum when the means of both distributions are identical (at least for Gaussian-like distributions such as \\ac{GMM}s). In fact, \\ref{eq:objective_interact_prob} is similar to the \\ac{ELBO} loss of the Trajectron loss function (compare Equation \\ref{eq:trajectron_loss}), which shows that the term is suitable for general optimization, especially concerning the Trajectron model itself. However, $J_{int}$ is generally applicable to all prediction models, that output a probabilistic distribution, independent from multi-modality.\n", "meta": {"hexsha": "e96fb2c1a49a487209f1287ff18addd386e8cee5", "size": 11315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/objective_interaction.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/objective_interaction.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/objective_interaction.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": 122.9891304348, "max_line_length": 1740, "alphanum_fraction": 0.7710119311, "num_tokens": 2796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6318416420675207}}
{"text": "\\documentclass[letterpaper,10pt]{article}\n\n\\usepackage{fullpage}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{braket}\n\n%We would like cardinality of a set to require one (not four) commands\n\\newcommand{\\card}[1]{\\left\\vert{#1}\\right\\vert}\n\n\\title{Set Notation Help}\n\\author{Craig Kelly}\n\n\\begin{document}\n\n% Force pdflatex to properly use letter as page size (instead\n% of defaulting to A4)\n\\special{papersize=8.5in,11in}\n\\setlength{\\pdfpageheight}{\\paperheight}\n\\setlength{\\pdfpagewidth}{\\paperwidth}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{6pt}\n\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Some set notation}\n\nLet $ Z $ be the set of integer $ \\geq 0 $.\nShow $ Z \\times Z \\times Z $ is countable by constructing the bijection\n$ f:  Z \\times Z \\times Z \\rightarrow \\mathbb{N} $\n\nI am assuming that $0 \\notin \\mathbb{N}$, \nso $\\mathbb{N} = (1,2,3, \\cdots)$ \n\n\n\\begin{proof}\n\nFirst we show that there is a bijection \n$ g: Z \\times Z \\rightarrow \\mathbb{N} $.\n\nblah, blah, blah\n\n$ g: Z \\times Z \\rightarrow \\mathbb{N} $\nis a bijection and therefore $Z \\times Z$ is countable.\n\nWe may now construct $ f:  Z \\times Z \\times Z \\rightarrow \\mathbb{N} $\nvia composition:\n\n$ f(Z_{1}, Z_{2}, Z_{3}) = h(g(Z_{1}, Z_{2}), Z_{3}) $\n\n\\end{proof}\n\n\n\\begin{proof}\n\n$ L1 = \\set{M | \\text{M accepts w if w contains the substring 10} } $\nis undecidable\n\nBlah, blah, blah\n\nIf M(w) accepts, then L(HWAMw) = $\\set{w | \\text{w contains the substring 10} }$\n\nIf M(w) rejects or fails to halt, then L(HWAMw) = $\\emptyset$\n\nThus, we know\n$(M,w) \\in A_{TM} \\Leftrightarrow HWAMw \\in L1$\n\n\\end{proof}\n\n\\pagebreak\n\n\n\\begin{proof}\n$ L2 = \\set{M | \\text{M accepts an odd number of strings} } $ is undecidable\n\n$P(M)$ if $\\card{L(M)}$ is odd.\n\n$x \\in \\set{000, 111, 101}$\n\nBlah, blah, blah\n\nIf M(w) accepts, then L(HWBMw) = $\\set{000, 111, 101}$.  Note that \n$\\card{L(HWBMw)} = 3$, which is odd.\n\nIf M(w) rejects or fails to halt, then L(HWBMw) = $\\emptyset$, so\n$\\card{L(HWBMw)} = 0$\n\nThus, we know\n$(M,w) \\in A_{TM} \\Leftrightarrow HWBMw \\in L2$\n\n\\end{proof}\n\n\n\\end{document}\n", "meta": {"hexsha": "ff3909c58db64409c76fea6307a129bdeb22b54f", "size": 2220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sets/sets.tex", "max_stars_repo_name": "CraigKelly/latex-samples", "max_stars_repo_head_hexsha": "48330f4b91ce2bf721441f27f2f0950cabcde1e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-08-09T08:11:58.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-09T08:11:58.000Z", "max_issues_repo_path": "sets/sets.tex", "max_issues_repo_name": "CraigKelly/latex-samples", "max_issues_repo_head_hexsha": "48330f4b91ce2bf721441f27f2f0950cabcde1e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sets/sets.tex", "max_forks_repo_name": "CraigKelly/latex-samples", "max_forks_repo_head_hexsha": "48330f4b91ce2bf721441f27f2f0950cabcde1e3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-09T08:11:59.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-09T08:11:59.000Z", "avg_line_length": 21.9801980198, "max_line_length": 80, "alphanum_fraction": 0.622972973, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6317799265385301}}
{"text": "%% State Space Modelling of Dynamic Systems\r\n%% Lecture 21: State Observers\r\n\\def\\FileDate{10/04/02}\r\n\\def\\FileVersion{1.0}\r\n% ----------------------------------------------------------------\r\n% Notes pages *********************************************************\r\n% ----------------------------------------------------------------\r\n\r\nIn many practical cases it is not possible to measure all the states of a system.\r\nThat is  we cannot form  $u=r-\\mathbf{Kx}$  for the purposes of feedback control because we do not have access to $\\mathbf{x}$\\footnote{Or some states in $\\mathbf{x}$, either because the states are not \\emph{physical states} and hence cannot be measured, or because they \\emph{are} physical states but we do not have suitable sensors for the physical quantity that is represented by the state.}\r\n\r\nIf the structure of the system is known  (i.e. $\\mathbf{A}$, $\\mathbf{B}$, $\\mathbf{C}$, and $\\mathbf{D}$) then it may be possible to reconstruct the states from one or more of the system outputs by means of an observer. It is necessary that the system states be observable from the output(s).\r\n\r\n\\ifslidesonly\r\n\\begin{slide}\r\n   \\heading{State Observers}\r\n   \\begin{itemize}\r\n   \t\\item In many practical cases it is not possible to measure all the states of a system.\r\n   \t\\item That is  we cannot form  $u=r-\\mathbf{Kx}$  for the purposes of feedback control because we do not have access to $\\mathbf{x}$.\r\n   \t\\item If we know $\\mathbf{A}$, $\\mathbf{B}$, $\\mathbf{C}$, and $\\mathbf{D}$ then it may be possible to reconstruct the states from one or more of the system outputs by means of an \\textbf{observer}. \r\n   \t\\item It is necessary that the system states be observable from the output(s).\r\n   \\end{itemize}\r\n\\end{slide}\r\n\\fi\r\n\r\n\\begin{slide}\r\n   \\heading{State Observer}\r\nThe main idea is to construct a model of the system and subject it to the same input:\r\n\\begin{center}\r\n\t\\resizebox{200pt}{!}{\\includegraphics{pictures/observer1.pdf}}\r\n\\end{center}\r\n\\end{slide}\r\n\r\nSevere differences occur between $\\mathbf{x}$  and  $\\hat{\\mathbf{x}}$ due to disturbances and parameter errors. Solution:-  Employ feedback !\r\n\r\n\\begin{slide}\r\n   \\heading{State Observer with Feedback}\r\n\\begin{center}\r\n\t\\resizebox{280pt}{!}{\\includegraphics{pictures/observer2.pdf}}\r\n\\end{center}\r\n\\end{slide}\r\n\\textbf{NB} To simplify treatment, we take $\\mathbf{D}=0$.\r\n\r\n\\input{frag1}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Observer State Equations}\r\n   \\input{frag1}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\\input{frag2}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Observed State Errors}\r\n   \\input{frag2}\r\n\\end{slide}\r\n\\fi\r\n \r\n\\input{frag3}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Properties of the Observed Error State Equations}\r\n   \\input{frag3}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\\section*{Design of the $\\mathbf{L}$ Matrix} % (fold)\r\n\\label{sec:design_of_the_l_matrix}\r\n\r\n\\input{frag4}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Design of the $\\mathbf{L}$ Matrix (1)}\r\n   \\input{frag4}\r\n\\end{slide}\r\n\\fi\r\n\r\n\\input{frag5}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Design of the $\\mathbf{L}$ Matrix (2)}\r\n   \\input{frag5}\r\n\\end{slide}\r\n\\fi\r\n\r\n\\input{frag6}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Design of the $\\mathbf{L}$ Matrix (3)}\r\n   \\input{frag6}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\\subsection*{Example 1} % (fold)\r\n\\label{sub:example_1}\r\n\r\n\\textbf{Problem}: Design an observer with poles or eigen values $\\lambda_{1,2} = -20,\\ -20$ using the observer canonical form for the system with a TF:\r\n\\[\r\n\\frac{Y(s)}{U(s)}=\\frac{7}{s^2+15s+44}.\r\n\\]\r\n \r\n\\textbf{SOLUTION}:\r\nThe observer canonical form gives:\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCyqaiabg2da9maadmaabaqbamqabi\r\n% GaaaqaaiabgkHiTiaaigdacaaI1aaabaGaaGymaaqaaiabgkHiTiaa\r\n% isdacaaI0aaabaGaaGimaaaaaiaawUfacaGLDbaacaGG7aGaaGjbVl\r\n% aahkeacqGH9aqpdaWadaqaauaadeqaceaaaeaacaaIWaaabaGaaG4n\r\n% aaaaaiaawUfacaGLDbaacaGG7aGaaGjbVlaahoeacqGH9aqpdaWada\r\n% qaauaadeqabiaaaeaacaaIXaaabaGaaGimaaaaaiaawUfacaGLDbaa\r\n% caGG7aGaaGjbVlaahseacqGH9aqpcaaIWaaaaa!4C31!\r\n\\[\r\n{\\bf{A}} = \\left[ {\\begin{array}{*{20}c}\r\n   { - 15} & 1  \\\\\r\n   { - 44} & 0  \\\\\r\n\\end{array}} \\right];\\;{\\bf{B}} = \\left[ {\\begin{array}{*{20}c}\r\n   0  \\\\\r\n   7  \\\\\r\n\\end{array}} \\right];\\;{\\bf{C}} = \\left[ {\\begin{array}{*{20}c}\r\n   1 & 0  \\\\\r\n\\end{array}} \\right];\\;{\\bf{D}} = 0\r\n\\]\r\nwith $\\mathbf{L}=[l_1,\\ l_2]^T$  we have observer poles at the roots of:\r\n\\[\r\ns^2+(15+l_1)s+(44+l_2)=0.\r\n\\]\r\n \r\n\r\nThe desired CE is:\r\n\\[\r\n\\alpha_e(s)=(s + 20)(s + 20)=s^2+40s+400=0\r\n\\]\r\n\r\nComparing coefficients gives:\r\n\\begin{eqnarray*}\r\n\ts^1:\\ 15 + l_1 & = & 40 \\to l_1=25 \\\\\r\n\ts^0:\\ 44 + l_2 & = & 400 \\to l_2=356 \\\\\t\r\n\\end{eqnarray*}\r\n \r\n\r\nSo the observer states are given by:\r\n\\[\r\n\\frac{d\\hat{\\mathbf{x}}}{dt}=\\mathbf{A}\\hat{\\mathbf{x}}+\\mathbf{B}u-\\mathbf{L}(\\mathbf{C}\\hat{\\mathbf{x}}-y)\r\n\\]\r\nwhere $\\mathbf{L}=[25\\ 356]^T.$\r\n\r\n\\begin{slide}\r\n   \\heading{Block Diagram of the Observer}\r\n\\begin{center}\r\n\t\\resizebox{250pt}{!}{\\includegraphics{pictures/observer3.pdf}}\r\n\\end{center}\r\n\\end{slide}\r\n\r\n% subsection example_1 (end)\r\n\r\n% section design_of_the_l_matrix (end)\r\n\r\n\r\n\\section*{Design of $\\mathbf{L}$ Matrix for Other Forms of State Equation} % (fold)\r\n\\label{sec:design_of_l_matrix_for_other_forms_of_state_equation}\r\n\r\n\r\n\\input{frag7}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Design of $\\mathbf{L}$ Matrix for Other Forms of State Equation}\r\n   \\input{frag7}\r\n\\end{slide}\r\n\\fi\r\n\r\nIn MATLAB we could evaluate the $\\mathbf{L}$ matrix using:\r\n\\begin{verbatim}\r\n\tL=(acker(A',C',p))'\r\n\\end{verbatim}  where  \\verb|p|  is a vector of desired observer poles.\r\n \r\n\r\n\r\n% section design_of_l_matrix_for_other_forms_of_state_equation (end)\r\n\r\n \r\n\\section*{Choice of Observer Poles} % (fold)\r\n\\label{sec:choice_of_observer_poles}\r\n\r\n\r\n\\input{frag8}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Choice of Observer Poles (1)}\r\n   \\input{frag8}\r\n\\end{slide}\r\n\\fi\r\n\r\n\\input{frag9}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Choice of Observer Poles (2)}\r\n   \\input{frag9}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\r\n% section choice_of_observer_poles (end)\r\n\r\n\r\n\r\n%----------------------------------------------------------------\r\n% The end of notes\r\n% ----------------------------------------------------------------\r\n\\endinput\r\n\r\n%%% Local Variables: \r\n%%% mode: latex\r\n%%% TeX-master: t\r\n%%% End: \r\n", "meta": {"hexsha": "65ead7bde40bd705e3d2af42645386a1a2ad7c26", "size": 6485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "StateSpaceDesign/Lecture21/notes.tex", "max_stars_repo_name": "cpjobling/EGLM03-Resources", "max_stars_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "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": "StateSpaceDesign/Lecture21/notes.tex", "max_issues_repo_name": "cpjobling/EGLM03-Resources", "max_issues_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "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": "StateSpaceDesign/Lecture21/notes.tex", "max_forks_repo_name": "cpjobling/EGLM03-Resources", "max_forks_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "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": 28.9508928571, "max_line_length": 395, "alphanum_fraction": 0.6564379337, "num_tokens": 2169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.63177992653853}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 2.15  Procedures to Avoid Loss of Precision: $\\ln (1+x)$, etc.\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThese procedures compute expressions involving logarithm, exponential, sine,\ncosine, hyperbolic sine, hyperbolic cosine, and the gamma function, some\nhaving arguments that are expressions, more accurately than is possible\nusing the Fortran intrinsic functions, or the gamma function described in\nChapter~2.3. See also discussion of the function SRCVAL in Section C\nof Chapter~2.9.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\ln (1+x)$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SLNREL}\n\n\\item[EXTERNAL] \\ {\\bf  SLNREL}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\ln (1+\\text{X})$ by using\n$$\n\\fbox{\\bf U = SLNREL(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline $x - \\ln (1+x)$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SRLOG1}\n\n\\item[EXTERNAL] \\ {\\bf  SRLOG1}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\text{X} - \\ln (1+\\text{X})$ by using\n$$\n\\fbox{\\bf U = SRLOG1(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline $x - 1 - \\ln (x)$}\n\n{\\bf REAL \\ X, U, SRLOG}\n\n{\\bf EXTERNAL \\ SRLOG}\n\nAssign a value to X and obtain U $= \\text{X} - 1 - \\ln (\\text{X})$ by using\n$$\n\\fbox{\\bf U = SRLOG(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\exp (x) - 1$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf X, U, SREXP}\n\n\\item[EXTERNAL] \\ {\\bf SREXP}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\exp (\\text{X}) - 1$ by using\n$$\n\\fbox{\\bf U = SREXP(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\sin (\\pi x)$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SSINPX}\n\n\\item[EXTERNAL] \\ {\\bf  SSINPX}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\sin (\\pi \\text{X})$ by using\n$$\n\\fbox{\\bf U = SSINPX(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\cos (\\pi x)$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SCOSPX}\n\n\\item[EXTERNAL] \\ {\\bf  SCOSPX}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\cos (\\pi \\text{X})$ by using\n$$\n\\fbox{\\bf U = SCOSPX(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $(x-\\sin (x))/x^3$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SSIN1}\n\n\\item[EXTERNAL] \\ {\\bf  SSIN1}\n\n\\end{description}\n\nAssign a value to X and obtain U $= (\\text{X}-\\sin (\\text{X}))/\\text{X}^3$ by using\n$$\n\\fbox{\\bf U = SSIN1(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $(1-\\cos (x))/x^2$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SCOS1}\n\n\\item[EXTERNAL] \\ {\\bf  SCOS1}\n\n\\end{description}\n\nAssign a value to X and obtain U $= (1-\\cos (\\text{X}))/\\text{X}^2$ by using\n$$\n\\fbox{\\bf U = SCOS1(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\sinh(x) - x$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SSINHM}\n\n\\item[EXTERNAL] \\ {\\bf  SSINHM}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\sinh(\\text{X}) - \\text{X}$ by using\n$$\n\\fbox{\\bf U = SSINHM(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\cosh(x) - 1$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SCOSHM}\n\n\\item[EXTERNAL] \\ {\\bf  SCOSHM}\n\n\\end{description}\n\nAssign a value to X and obtain U $= \\cosh(\\text{X}) - 1$ by using\n$$\n\\fbox{\\bf U = SCOSHM(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $\\cosh(x) -\n 1 - \\frac 12 x^2$}\n\n{\\bf REAL X, U, SCSHMM}\n\n{\\bf EXTERNAL SCSHMM}\n\nAssign a value to X and obtain U $= \\cosh(\\text{X}) - 1 - \\frac{1}{2} \\text{X}^2$ by using\n$$\n\\fbox{\\bf U = SCSHMM(X)}\n$$\n\\subsubsection{Program Prototype, Single Precision,\\newline  $1/\\Gamma (x+1) - 1$}\n\n\\begin{description}\n\n\\item[REAL] \\ {\\bf  X, U, SGAM1}\n\n\\item[EXTERNAL] \\ {\\bf  SGAM1}\n\n\\end{description}\n\nAssign a value to X and obtain U $= 1/\\Gamma (1+\\text{X}) - 1$ by\nusing\n$$\n\\fbox{\\bf U = SGAM1(X)}\n$$\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\n\\item[X] \\ [in] Argument of functions. Argument values may be constrained as\ndescribed in Section E below.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double precision computation, change the REAL type statement to DOUBLE\nPRECISION and change the initial letter of the function name to D. Since\nthese functions are not generic intrinsic functions, it is important to\ndeclare them explicitly to be DOUBLE PRECISION, because the default implicit\ntype would be REAL. The approximations used in SSINHM, SCOSHM and SCSHMM are\naccurate to~14 decimal digits, so the REAL versions of these procedures\ncould be used to advantage on some platforms by changing the function type\nand all internal variable types, constants, and arithmetic to double\nprecision.\n\n\\subsection{Example and Remarks}\n\nSee DRDLNREL and ODDLNREL for an example of the usage of these subprograms.\n\nMATH77 does not include a special procedure to compute $\\sin (x)/x$. On all\nmachines tested, $\\sin (x)/x$ could be computed with good relative accuracy,\neven for very small $x$, by using the Fortran intrinsic SIN function. The\nonly difficulty is that the user must test whether $x$ is exactly zero, and\nuse 1.0 for the result. The procedure SSIN1, described above, can be used to\ncompute $1-\\sin (x)/x$ without loss of precision.\n\n\\subsection{Functional Description}\n\n\\subsubsection{Method}\n\\begin{description}\n\\item[For xLNREL,] when $1/\\sqrt 2 < 1+x < \\sqrt 2$, use approximation~2707 from\nHart, et. al., \\cite{Hart:1968:CA}. Otherwise, use the Fortran intrinsic logarithm\nfunction.\n\n\\item[For xRLOG1,] when $-0.39 \\leq  x \\leq  0.57$, use\nrational approximations due to Alfred H. Morris, Jr., \\cite{ahm:lib}. Otherwise,\nuse the Fortran intrinsic logarithm function.\n\n\\item[For xRLOG,] when $0.61 \\leq  x \\leq  1.57$, use rational\napproximations due to Alfred H. Morris, Jr., \\cite{ahm:lib}. Otherwise, use the\nFortran intrinsic logarithm function.\n\n\\item[For xREXP,] when $|x| \\leq  0.15$, use rational approximations due\nto Alfred H. Morris, Jr., \\cite{ahm:lib}. Otherwise, use the Fortran intrinsic\nexponential function.\n\n\\item[For xSINPX and xCOSPX,] for all values of $x$, use rational approximations\ndue to Alfred H. Morris, Jr., \\cite{ahm:lib}.\n\n\\item[For xSIN1,] use Taylor's series for $|x| < 0.25$. Otherwise, use the Fortran\nintrinsic sine function.\n\n\\item[For xCOS1,] when $\\cos (x) \\geq 0$ use $1-\\cos (x) = \\sin ^2(x) / (1+\\cos (x))$%\n. Otherwise, use $1-\\cos (x)$. In both cases, use the Fortran intrinsic\nfunctions.\n\n\\item[For SSINHM,] when $|x| < 1.65$, use rational approximations due to A. K.\nCline and R. J. Renka, \\cite{ahm:lib}. Otherwise, use the Fortran intrinsic SINH\nfunction.\n\n\\item[For SCOSHM,] when $|x| < 1.2$, use rational approximations due to A. K. Cline\nand R. J. Renka, \\cite{ahm:lib}. Otherwise, use the Fortran intrinsic COSH function.\n\n\\item[For SCSHMM,] when $|x| < 2.7$, use rational approximations due to A. K. Cline\nand R. J. Renka, \\cite{ahm:lib}. Otherwise, use the Fortran intrinsic COSH function.\n\n\\item[For xGAM1,] when $-0.5 \\leq  x \\leq  1.5$,\nuse rational approximations due to Alfred H. Morris, Jr., \\cite{ahm:lib}.\nOtherwise, use the xGAMMA routine from Chapter~2.3.\n\\end{description}\n\\subsubsection{Accuracy Tests}\n\nThe single precision subprograms were tested on an IBM PC/AT using IEEE\narithmetic, by comparison with the double precision Fortran intrinsic\nfunctions (except the reference value for SGAM1 used DGAMMA from Chapter\n2.3) at 2000~points. For each function except SSINPX and SCOSPX, the points\nwere chosen to cover the entire domain over which a special approximation is\nused. For SSINPX and SCOSPX, 2000~points were chosen randomly in the region $%\n0<x<2$, and SSINPX($10^x$), $\\sin (10^x\\pi )$, SCOSPX($10^x$) and $\\cos\n(10^x\\pi )$ were then computed. For SSIN1 and SCOS1, 2000~points were chosen\nrandomly in the region $-8<x<-1$, then $y=10^x$,\nSSIN1($y)$, $(y-\\sin (y))/y^3$, SCOS1($y)$ and $(1-\\cos (y))/y^2$ were\ncomputed. The results of these tests may be summarized as follows:\n\\begin{table*}\n\\begin{center}\n\\begin{tabular}{l*{11}{r}}\n & \\multicolumn{11}{c}{\\bf Percentage of samples with specified number of\nbits wrong\\rule[-8pt]{0pt}{8pt}}\\\\\n{\\bf Function} & {\\bf 0} & {\\bf 1} & {\\bf 2} & {\\bf 3} & {\\bf 4} &\n{\\bf 5} & {\\bf 6} & {\\bf 7} & {\\bf 8} & {\\bf 9} & {\\bf $\\geq 10$}\\\\\nSLNREL & 100.0\\\\\n$\\ln (x+1)$ & 61.7 & 24.6 & 13.8\\\\\nSRLOG1 & 57.3 & 23.7 & 10.9 & 6.7 & 1.5\\\\\n$x-\\ln (x+1)$ & 3.9 & 4.6 & 9.0 & 11.9 & 17.9 & 16.9 & 11.0 & 7.0 & 5.3 &\n4.1 & 8.5\\\\\nSRLOG & 56.7 & 23.9 & 10.9 & 6.9 & 1.6\\\\\n$x-1-\\ln (x)$ & 4.2 & 3.9 & 7.3 & 12.1 & 19.4 & 15.9 & 11.4 & 8.6 & 5.6 &\n3.4 & 8.5\\\\\nSREXP & 71.7 & 26.5 & 1.9\\\\\n$\\exp (x)-1$ & 8.2 & 8.8 & 16.9 & 26.0 & 18.8 & 10.8 & 5.2 & 2.8 & 1.6 &\n0.4 & 0.6\\\\\nSSINPX & 10.6 & 7.6 & 9.9 & 11.9 & 13.0 & 12.1 & 12.1 & 8.7 & 5.8 & 3.3 & 5.2\\\\\n$\\sin (\\pi x)$ & 4.9 & 4.8 & 8.8 & 11.8 & 12.9 & 13.2 & 13.6 & 11.4 &\n8.2 & 5.2 & 5.4\\\\\nSCOSPX & 11.4 & 7.1 & 11.4 & 11.8 & 11.4 & 12.2 & 11.1 & 10.1 & 6.0 &\n3.9 & 3.9\\\\\n$\\cos (\\pi x)$ & 5.1 & 4.3 & 9.4 & 10.9 & 12.7 & 13.7 & 13.4 & 11.9 &\n7.8 & 5.3 & 5.6\\\\\nSSIN1 & 91.1 & 8.9\\\\\n$(x-\\sin (x))/x^3$ & 54.2 & 20.1 & 2.0 & 2.3 & 2.0 & 2.2 & 2.1 & 1.5 &\n1.6 & 1.8 & 9.8\\\\\nSCOS1 & 76.5 & 15.8 & 7.7 & 0.1\\\\\n$(1-\\cos (x))/x^2$ & 57.5 & 18.6 & 4.3 & 2.0 & 1.7 & 2.4 & 1.6 & 2.2 &\n2.1 & 1.8 & 6.1\\\\\nSSINHM & 66.3 & 29.4 & 4.3\\\\\n$\\sinh(x)-x$ & 13.4 & 12.3 & 23.6 & 17.0 & 8.5 & 7.7 & 5.0 & 3.7 & 2.5 &\n2.0 & 4.3\\\\\nSCOSHM & 68.7 & 28.3 & 3.0\\\\\n$\\cosh(x)-1$ & 18.8 & 19.1 & 17.5 & 13.7 & 8.5 & 6.0 & 5.0 & 3.5 & 2.8 &\n1.6 & 3.7\\\\\nSCSHMM & 46.5 & 32.9 & 19.8 & 0.8\\\\\n$\\cosh(x)-1-x^2/2$ & 12.0 & 11.4 & 16.9 & 13.7 & 10.4 & 5.7 & 5.0 & 4.0 &\n3.0 & 3.3 & 14.7\\\\\nSGAM1 & 63.3 & 27.5 & 8.9\\\\\n$1/\\Gamma (1+x)-1$ & 8.2 & 8.7 & 13.9 & 20.7 & 22.1 & 14.7 & 5.4 & 3.7 &\n1.5 & 0.6 & 0.7\\\\\n\\end{tabular}\n\\end{center}\\vspace{-10pt}\n\\end{table*}\n\n\\begin{tabular}{@{}l@{}rrr}\n{\\bf Function} & {\\bf avg $|\\text{E}|$} &\n{\\bf $\\max |\\text{E}|$} & {\\bf std. dev.}\\\\\nSLNREL & 0.25 & 0.50 & 0.14\\\\\n$\\ln (x+1)$ & 0.50 & 1.49 & 1.49\\\\\nSRLOG1 & 0.46 & 3.28 & 0.43\\\\\n$x-\\ln (x+1)$ & 8075.58 & $\\approx 7.9\\times 10^6$ & $\\approx 1.9\\times 10^5$\\\\\nSRLOG & 0.47 & 3.10 & 0.43\\\\\n$x-1-\\ln (x)$ & 3341.24 & $\\approx 2.9\\times 10^6$ & $\\approx 7.3\\times 10^4$\\\\\nSREXP & 0.37 & 1.39 & 0.26\\\\\n$\\exp (x)-1$ & 16.51 & 7402.74 & 190.13\\\\\nSSINPX & 58.32 & 5795.79 & 253.07\\\\\n$\\sin (\\pi x)$ & 119.20 & 48061.18 & 1193.09\\\\\nSCOSPX & 84.64 & 35894.27 & 965.42\\\\\n$\\cos (\\pi x)$ & 94.27 & 19712.38 & 588.76\\\\\nSSIN1 & 0.32 & 0.97 & 0.13\\\\\n$(x-\\sin (x))/x^3$ & 407.81 & 28944.33 & 2091.66\\\\\nSCOS1 & 0.25 & 2.02 & 0.38\\\\\n$(x-\\cos (x))/x^2$ & 102.36 & 7931.0 & 525.75\\\\\nSSINHM & 0.35 & 1.36 & 0.35\\\\\n$\\sinh(x)-x$ & 2584.93 & $\\approx 2.6\\times 10^6$ & $\\approx 6.7\\times 10^4$\\\\\nSCOSHM & 0.39 & 1.35 & 0.27\\\\\n$\\cosh(x)-1$ & 2302.36 & $\\approx 3.7\\times 10^6$ & $\\approx 8.3\\times 10^4$\\\\\nSCSHMM & 0.65 & 23.00 & 0.68\\\\\n\\multicolumn{2}{@{}l}{$\\cosh(x)-1-x^2/2$}\\\\\n & $\\approx 1.9\\times 10^5$ & $>10^7$ & $\\approx 1.6\\times\n10^6$\\\\\nSGAM1 & 0.46 & 2.44 & 0.37\\\\\n$1/\\Gamma (1+x)-1$ & 32.94 & 28016.70 & 686.03\\\\\n\\end{tabular}\n\nFor the functions SLNREL, SRLOG1, SRLOG, SREXP, SSINHM, SCOSHM and SGAM1 the\nerror in units of the least significant digit was approximately constant over\nthe entire region. For SSINPX and SCOSPX the error in units of the least\nsignificant digit and the absolute error both increased as the argument\nincreased. For SCSHMM the error in units of the least significant digit was\nnearly constant over the entire region, except that one sample had 5 wrong\nbits near the zero of the function.\n\nWhen $\\ln (1+x)$, $x-\\ln (1+x)$, $x-1-\\ln (x)$, $(x-\\sin (x))/x^3$, $%\n(1-\\cos (x))/x^2$, $\\sinh (x)-x$, $\\cosh(x)-1$, $\\cosh (x)-1-x^2/2$\nand $1/\\Gamma (1+x)-1$ were computed\nusing single precision intrinsic functions and single precision\narithmetic, there was substantial increase in the error in units of the least\nsignificant digit near the zeros of the functions, even though the absolute\nerror approached zero. For $\\sin (\\pi x)$ and $\\cos (\\pi x)$ the error\nin units of\nthe least significant digit and the absolute error increased as the argument\nincreased. The average, maximum and standard deviation of the errors in\nunits of the\nleast significant digit are summarized in the table at left, in units of $%\n\\rho = 2^{-23} \\approx 1.192 \\times 10^{-7}$, the relative precision of IEEE\nsingle precision arithmetic.\n\nFor arguments in the range $0<x<1$, SSINPX and SCOSPX commit approximately\nthe same error as equivalent expressions constructed from the intrinsic SIN\nand COS functions.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIf the argument of xLNREL or xRLOG1 $\\leq  -1.0$ or the argument of\nxRLOG $\\leq $ 0.0, the Fortran intrinsic logarithm function will\nproduce an error message. If the argument of xGAM1 $\\leq -1.0$ the\nxGAMMA function will produce an error message. If the magnitude of\nthe argument of SSINPX, DSINPX, SCOSPX or DCOSPX $> 1 / \\rho $, where\n$\\rho $ is the smallest number that can be added to one and give a\nresult different from one, these routines will issue an error message\nusing the error message processor, described in Chapter~19.2, at\nlevel~2. If error termination is suppressed by using ERMSET, SSINPX\nand DSINPX return 0.0, while SCOSPX and DCOSPX return~1.0.\n\n\\subsection{Supporting Information}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in}\\bf Required Files\\vspace{2pt}\\\\\nDCOS1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCOS1\\rule[-5pt]{0pt}{8pt}}\\\\\nDCOSHM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DCOSHM\\rule[-5pt]{0pt}{8pt}}\\\\\nDCOSPX & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, DCOSPX, DERM1, DERV1\\rule[-5pt]{0pt}{8pt}}\\\\\n\\end{tabular}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in}\\bf Required Files\\vspace{2pt}\\\\\nDCSHMM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DCSHMM\\rule[-5pt]{0pt}{8pt}}\\\\\nDGAM1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERM1, DERV1, DGAM1, DGAMMA, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\\nDLNREL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDLNREL\\rule[-5pt]{0pt}{8pt}}\\\\\nDREXP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDREXP\\rule[-5pt]{0pt}{8pt}}\\\\\nDRLOG & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRLOG\\rule[-5pt]{0pt}{8pt}}\\\\\nDRLOG1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRLOG\\rule[-5pt]{0pt}{8pt}}\\\\\nDSIN1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DSIN1\\rule[-5pt]{0pt}{8pt}}\\\\\nDSINHM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DSINHM\\rule[-5pt]{0pt}{8pt}}\\\\\nDSINPX & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, DERM1, DERV1, DSINPX\\rule[-5pt]{0pt}{8pt}}\\\\\nSCOS1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSCOS1\\rule[-5pt]{0pt}{8pt}}\\\\\nSCOSHM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSCOSHM\\rule[-5pt]{0pt}{8pt}}\\\\\nSCOSPX & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SCOSPX, SERM1, SERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSCSHMM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSCSHMM\\rule[-5pt]{0pt}{8pt}}\\\\\nSGAM1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERM1, SERV1, SGAM1, SGAMMA\\rule[-5pt]{0pt}{8pt}}\\\\\nSLNREL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSLNREL\\rule[-5pt]{0pt}{8pt}}\\\\\nSREXP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSREXP\\rule[-5pt]{0pt}{8pt}}\\\\\nSRLOG & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSRLOG\\rule[-5pt]{0pt}{8pt}}\\\\\nSRLOG1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSRLOG\\rule[-5pt]{0pt}{8pt}}\\\\\nSSIN1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, SSIN1\\rule[-5pt]{0pt}{8pt}}\\\\\nSSINHM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSSINHM\\rule[-5pt]{0pt}{8pt}}\\\\\nSSINPX & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERM1, SERV1, SSINPX\\rule[-5pt]{0pt}{8pt}}\\\\\n\\end{tabular}\n\nDesigned and programmed by W. V. Snyder, JPL 1991 and 1993.\n\n\n\\begcode\n\n\\medskip\\\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRDLNREL}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{dlnrel}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODDLNREL}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{dlnrel}}\n\\end{document}\n\n", "meta": {"hexsha": "50c5f1dfe7c3a4f1a67d5afecae6047ee0cd2266", "size": 16581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch02-15.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/ch02-15.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/ch02-15.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": 35.4294871795, "max_line_length": 98, "alphanum_fraction": 0.6670285266, "num_tokens": 6621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6317799243480858}}
{"text": "\\section{xODE: Ordinary Differential Equations}\n\n[Simon Hood prepared the code.  We do not yet have extensive\ndocumentation.  See modules for discussion.  This matrixerial come from\nthe ode interface.\n\nThis code is not yet folded into the general m3na library architecture.\nSee the ``hood'' subdirectory.]\n\nThis is a Library of numerical integrators to\nordinary differential equations of arbitrary order, linear or nonlinear.\nBoth initial value problems and\n  boundary value problems are catered for:\n\n\\subsection*{IVPs}\nAt present only one routine is supplied;  this is based on a \n      Runge-Kutta Order Four scheme.  This is usually good enough.  I will\n      be adding a Runge-Kutta Order Six scheme, simply because I have an\n      implementation I did years ago knocking around, though I don't expect\n      it to be significantly better very often.  More significant might be\n      the addition of a predictor-corrector scheme or something specifically\n      for ``stiff'' differential equations.\n\n\\subsection*{BVPs}\nTwo routines are/will be supplied:  \n      a ``relaxation/finite-difference''\n      routine and a second based on a ``shooting'' algorithm.  The latter\n      is not yet implemented --- though it solves, in principle at least, \n      the same problems as the former.  In practice, one routine may converge\n      when the other does not;  furthermore, one can provide an \n      independent check of the other (assuming both converge!);  finally,\n      rest assured that the shooting algorithm {\\it will\\/} be implemented\n      in the not too distant future as I need it for my research!\n\n\n", "meta": {"hexsha": "934297e2da5772dac4b90085c8a5d791855a2f57", "size": 1610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/ode.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/ode.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/ode.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": 44.7222222222, "max_line_length": 77, "alphanum_fraction": 0.7447204969, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6317499328283855}}
{"text": "\\chapter{Introduction to Hypothesis Testing \\label{chapter:hypothesistesting}}\n\nHypothesis testing is a central idea underpinning much of the analysis in the clinical and biomedical research literature\\footnote{I should state that there is still a lot of controversy around the whole idea of hypothesis testing and whether $p$-values should be used at all, etc.}. There are multiple approaches to hypothesis testing, but the most common is \\textbf{null hypothesis testing}, which was developed by the statistician R.A. Fisher. In null hypothesis testing, one creates a model of how the data should look under default conditions and then quantifies the observed data's deviation from that model using a \\textbf{test statistic}. If the test statistic is large enough, it means there is evidence that the default position is incorrect. \n\nThe statisticians Jerzy Neyman and Karl Pearson developed a different approach to hypothesis testing based on the idea of \\textbf{model comparison}. In their approach, one sets up different models and then quantifies each model's fit to the data; the hypothesis test is used to see whether one model's fit to the data is significantly better than another's. We see the Neyman-Pearson philosophy reflected in techniques such as power calculations and likelihood ratio tests. \n\nMost of the basic hypothesis tests we learn in introductory biostatistics courses (T-tests, chi-squared tests, etc.) follow Fisher's approach. We will focus on null hypothesis testing in this chapter and explore other ideas in subsequent chapters. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Basic Steps of a Hypothesis Test}\n\n\\begin{enumerate}\n\\item \\textit{State the \\textbf{null hypothesis}}. The null hypothesis corresponds to the default, or baseline, position; for our example, the null hypothesis might be, ``The events `has mutation' and `has cancer' are statistically independent.'' The \\textbf{alternative hypothesis} is the hypothesis that is contrary to the null; for our example, it might be, ``The events `has mutation' and `has cancer' are not statistically independent.''\n\\item \\textit{List statistical {assumptions}}. All hypothesis tests make one or more assumptions about the data, and it's important to state them clearly. For example, \\textbf{parametric} hypothesis tests assume the data follow a particular probability distribution under the null, while \\textbf{nonparametric} tests do not make this assumption.\n\\item \\textit{Decide on an appropriate test and test statistic}. The \\textbf{test statistic} quantifies the degree of deviation of the observed data from what one would expect under the null hypothesis\\footnote{Some definitions: A \\textbf{statistic} is just some quantity that summarizes a set of data, or gives some information about the value of a parameter. A \\textbf{sufficient statistic} is a statistic that gives the maximum amount of information about a parameter that can possibly be obtained from the sample data.}. \n\\item \\textit{Derive the distribution of the test statistic under the null}. This is called the \\textbf{null distribution}.\n\\item \\textit{Select a {significance level} under which you'll reject the null}. The \\textbf{significance level}, usually written as $\\alpha$, is the probability of a type I error. A type I error is committed when one rejects the null even though it is true (false positive result). \n\\item \\textit{Compute the observed value of the test statistic from the data.}\n\\item \\textit{Decide whether or not to reject the null hypothesis.}\n\\end{enumerate}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{The Z-Test}\n\nA \\textbf{Z-test} is a hypothesis test for which the null distribution is normal with known mean and standard deviation (i.e. known parameters $\\mu$ and $\\sigma$). It is most commonly used to compare the mean of a set of samples, $\\overline{x}$, with a known population mean. It also appears in other contexts, such as significance tests of regression coefficients in generalized linear models (Chapter~\\ref{chapter:glms}). \n\n\\paragraph{Example: SBP in an Appalachian Town} The distribution of systolic blood pressure (SBP) among Caucasian males ages 55-64 in the United States is roughly normal with mean 139.75 mmHg and standard deviation 21.40 mmHg (Source: Int. J. Epidemiol. 2: 294-301, 1973). The following graph shows a normal distribution with those parameters.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-00.png}\n\\end{center}\n\nHere is a histogram of 10,000 data samples drawn independently from that distribution (i.e., what we would expect if we sampled the SBPs of 10,000 men from the United States at large):\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-0.png}\n\\end{center}\n\nNow, assume some researchers find a small community in rural Appalachia and measure the SBP of 20 Caucasian males ages 55-64 there. Their mean SBP is 125.45 mmHg, illustrated by the red dashed line in the graph below.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-1.png}\n\\end{center}\n\nAt first glance, this may not appear that unusual. After all, the red line is sort of near the center of the gray distribution, right? This analysis is flawed, however, because our 125.45 mmHg value isn't for one man - it's an average over 20 men. The distribution of the \\textbf{sample mean}, $\\overline{x}$, is different from that of each individual sample. \n\nTo see this, imagine taking 20 samples from the gray distribution, taking their mean, and recording that value. Now repeat that process 10,000 times. If you do that, you get the \\textbf{distribution of the sample mean},  which is skinnier than the gray distribution:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-2.png}\n\\end{center}\nIt turns out that the distribution of the sample mean will have the same mean, $\\mu_0$, as the population distribution, but its standard deviation will be $\\sigma/\\sqrt{n}$, where $n$ is the number of samples over which the mean is taken.\n\n\\begin{question}{}\nIf $n=1$, what is the standard deviation of the sample mean? If $n=\\infty$, what is the standard deviation of the sample mean?\n\\end{question}\n\n\\begin{question}{}\nThe sample mean for our $20$ sampled Appalachian men is shown as a vertical red dashed line in the figure above. Now that you know what the distribution of the sample mean looks like, do you think the observation from your Appalachian town is ``weird''?\n\\end{question}\n\n\\noindent Let's conduct a hypothesis test to evaluate whether we have evidence that the mean SBP among men in this town is different from that of the general U.S. population.\n\n\\begin{enumerate}\n\\item \\textit{State the \\textbf{null hypothesis}}. Here the null hypothesis is going to be our default position: that there is no difference. Let $\\mu_c$ be the true mean SBP for men in the community and $\\mu_0$ be the mean for the general population. \n\\begin{align*}\nH_0: &~\\mu_c = \\mu_0 \\\\\nH_a: &~\\mu_c \\neq \\mu_0\n\\end{align*}\n\\item \\textit{List statistical {assumptions}}. We make two assumptions. First, we assume that the SBPs of the different men in the sample are statistically independent. Second, we assume that under the null, SBP will follow a normal distribution with mean 139.75 and standard deviation 21.40, the same as the general population of men aged 55-64.\n\\item \\textit{Decide on an appropriate test and test statistic}. Our test statistic in this case is going to be the \\textbf{Z-statistic}, which measures the deviation of the sample mean from the population mean in units of the standard deviation of the sample mean, $\\sigma/\\sqrt{n}$:\n$$ Z = \\frac{\\overline{x} - \\mu_0}{\\sigma / \\sqrt{n}} \\qquad \\text{where} \\qquad \\overline{x} = \\frac{1}{n} \\sum_{i=1}^n x^{(i)}$$\nIn our case, $n = 20$ because $\\overline{x}$, our sample mean, is an average of 20 samples.  \n\\item \\textit{Derive the distribution of the test statistic under the null}. The Z-statistic follows a \\textbf{standard normal} distribution under the null, which is a normal distribution with $\\mu=0$ and $\\sigma=1$. To see this, remember that the distribution of $\\overline{x}$ under the null is $\\mathcal{N}(\\mu_0, \\sigma/\\sqrt{n})$. When you calculate the Z-statistic, you shift that distribution by a distance $\\mu_0$ so it is centered at zero, then adjust its width (standard deviation) to 1.0 by dividing by $\\sigma/\\sqrt{n}$.\n\\item \\textit{Select a {significance level} under which you'll reject the null}. For the purposes of this example, we will choose $\\alpha = 0.05$ (5\\% chance of a type I error). The null distribution of the Z-statistic is shown below. The vertical dotted black lines are situated at the \\textbf{critical values} that produce $\\alpha = 0.05$ (the area under the null distribution that is outside those lines is 0.05). \n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-3-z.png} \n\\end{center}\n\n\\item \\textit{Compute the observed value of the test statistic from the data.} The observed value of the test statistic is:\n$$ Z = \\frac{\\overline{x} - \\mu_0}{\\sigma / \\sqrt{n}} = \\frac{125.45 - 139.75}{21.40/\\sqrt{20}} = -2.99. $$\n\\item \\textit{Decide whether or not to reject the null hypothesis.} The value of our test statistic falls outside the region contained by the critical values (the \\textbf{acceptance region}), so we reject the null at this value of $\\alpha$.\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-z-test-example-4-z.png} \n\\end{center}\n\\end{enumerate}\n\n\\begin{question}{}\nAs $\\alpha$ gets smaller, are you more or less likely to reject the null for the same value of the test statistic? Hint: What does making $\\alpha$ smaller do to the positions of the two black dotted lines in the figure, above?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Definitions}\n\n\\begin{itemize}\n\\item \\textbf{Type I Error:} When a hypothesis test rejects the null even though the null is true (also called a \\textbf{false positive}). The type I error rate is usually denoted by $\\alpha$.\n\\item \\textbf{Type II Error:} When a hypothesis test fails to reject the null even though it is false (also called a \\textbf{false negative}). The type II error rate is usually denoted by $\\beta$.\n\\item \\textbf{P-value:} The probability of obtaining a test statistic at least as extreme as the one that was actually obtained, assuming the null is true. A $p$-value can be \\textbf{one-sided} or \\textbf{two-sided}. The difference lies in the definition of ``extreme''. In a one-sided test, we find the probability that the test statistic is at least as extreme \\emph{in the same direction} as the one we observed. In a two-sided test, we find the probability that the test statistic is at least as extreme \\emph{in either direction} (positive or negative deviation). In most cases, this has the practical effect of doubling the $p$-value.\n\\item \\textbf{Power:} The probability that a hypothesis test will reject the null when the null is false (that the test will detect a true effect if the effect is there). Usually denoted $1 - \\beta$.\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Pearson's Chi-Squared Test}\n\nImagine you have data on two discrete variables for $n$ different subjects. You want to test whether the value of one covariate is independent of the value of the other. To do this, you can arrange your data in a \\textbf{contingency table} where the rows and columns correspond to the values of the two variables. \\textbf{Pearson's chi-squared test} can then be used to assess the independence of row and column values.\n\n\\paragraph{Example: Association of Genotype and Disease} Imagine you want to test whether a person's genotype at a particular locus is associated with whether or not he/she has Disease X. You find 100 people with the disease and 100 healthy controls ($n=200$) and genotype them:\n\n\\begin{center}\n\\includegraphics[width=0.55\\textwidth]{img/pearson-chisq-fig-1.png}\n\\end{center}\n\n\\noindent \\noindent Let's conduct a hypothesis test to examine this result. \n\n\\newcommand{\\indep}{\\perp \\!\\!\\! \\perp}\n\\newcommand{\\independent}{\\perp\\mkern-9.5mu\\perp}\n\\newcommand{\\notindependent}{\\centernot{\\independent}}\n\n\\begin{enumerate}\n\\item \\textit{State the \\textbf{null hypothesis}}. We consider the genotype at this locus, $G$, to be a random variable (see Chapter~\\ref{chapter:probabilitydistributions}) with three possible outcomes: \\emph{AA}, \\emph{Aa}, and \\emph{aa}. We likewise consider the patient's disease status, $D$, to be a random variable with two possible outcomes: disease or no disease. We state our null hypothesis mathematically as: \n\\begin{align*}\nH_0: &~ G \\independent D \\\\\nH_a: &~ G \\notindependent D\n\\end{align*}\nwhere the symbol $\\independent$ refers to statistical independence of $G$ and $D$. We encountered statistical independence in our discussion of maximum likelihood in Chapter~\\ref{chapter:mlebasics}. Mathematically, statistical independence means that the joint probability of observing a particular value for $G$ and a particular value for $D$ is simply equal to the product of their individual probabilities:\n$$ P(G=g, D=d) = P(G=g) P(D=d) $$\nUnder these conditions, the expected values of the cells of our table are:\n\\begin{center}\n\\includegraphics[width=0.55\\textwidth]{img/pearson-chisq-fig-2.png}\n\\end{center}\nFor example, consider the cell $G = AA, D = X$. Assuming the total number of patients is fixed at $n=200$ and $G$ and $D$ are independent, the expected number of people in that cell is: \n\\begin{align*} P(G=AA, D=X) \\cdot n &= \\left(\\frac{119}{200}\\right) \\left(\\frac{100}{200}\\right) \\cdot 200 \\\\\n&= \\mathbf{59.5} \\end{align*}\nOur task now is to decide whether our observed table counts are different enough from what we expect under the null to cause us to reject the null. \n\n\\item \\textit{List statistical {assumptions}}. We assume that the data are sampled randomly and independently from a fixed population where each member of the population has an equal probability of selection\\footnote{A further assumption of the chi-squared test is that expected counts for each cell must be sufficiently high. A common rule is 5 or more in all cells of a $2\\times 2$ table, and 5 or more in 80\\% of cells in larger tables, but no cells with zero counts.}. \n\n\\item \\textit{Decide on an appropriate test and test statistic}. The chi-squared test works by calculating expected counts in all $r \\times c$ cells of the table ($r$ = number of rows, $c$ = number of columns) and then measuring the data's deviation from those expected counts. The \\textbf{chi-squared test statistic} has the form\n$$ X^2 = \\sum_{i=1}^r \\sum_{j=1}^c \\frac{(O_{ij} - E_{ij})^2}{E_{ij}} $$\nwhere $O$ refers to ``observed count'' and $E$ to ``expected count''. The expected counts are those that assume statistical independence of rows and columns (blue table, above).\n\n\\item \\textit{Derive the distribution of the test statistic under the null}. Under the null, the $X^2$ test statistic follows a chi-squared distribution (Section~\\ref{sect:chisqdist}) with $(r-1)(c-1)$ degrees of freedom. In the case of our genotype example, there are $r=2$ rows and $c=3$ columns, thus $2$ degrees of freedom.\n\n\\item \\textit{Select a {significance level} under which you'll reject the null}. The $\\chi^2$ distribution with $2$ degrees of freedom is shown below. Two vertical lines are shown at different significance levels: $\\alpha = 0.05$ and $\\alpha = 0.1$.\n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/hyp-chisq-test-example-2.png} \n\\end{center}\n\n\\item \\textit{Compute the observed value of the test statistic from the data.}\n\n\\begin{question}{}\nUsing the formula in step~$4$, above, compute the actual value of the chi-squared test statistic for this example. Hint: You should end up with a value that corresponds to the position of the red dashed line in the figure below. \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/hyp-chisq-test-example-3.png} \n\\end{center}\n\\end{question}\n\n\\item \\textit{Decide whether or not to reject the null hypothesis.} Based on our calculated value of the test statistic, we will reject the null at $\\alpha = 0.1$ and fail to reject the null at $\\alpha = 0.05$.\n\\end{enumerate}\n\nAlthough it looks much different from the Z-test, the chi-squared test follows the same formalism: defining a null hypothesis, figuring out what the data should look like under the null, quantifying the deviation of the observed data from what's expected using a test statistic, and deciding if that test statistic presents strong enough evidence to cause us to reject the null.  \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Student's T-tests}\n\nThe final example we will look at today is the \\textbf{T-test}. Like the $Z$-test, the $T$-test (actually a family of tests) deals with situations where you have data that are assumed to be normally distributed under the null hypothesis. However, in this scenario, the population standard deviation, $\\sigma$ is not known and must be estimated from the data itself.\n\n\\subsection{One Sample T-test}\n\nAssume you have a dataset $x^{(1)}, \\dots, x^{(n)}$, of real numbers that you can plausibly assume are normally distributed. You want to test whether the mean of your data is equal to a fixed value, $\\mu_0$. Under the null hypothesis that the means are the same, the test statistic\n$$ T = \\frac{\\overline{x} - \\mu_0}{s/\\sqrt{n}} $$\nwhich we call a ``T statistic'', follows a T-distribution (Section~\\ref{sect:tdist}) with $n-1$ degrees of freedom\\footnote{A one-sample T-test looks a lot like a Z-test. However, because we use $s$ to estimate the population standard deviation from data, we must account for variation in our estimate. It turns out that the sample variance, $s^2$, follows a chi-squared distribution with $n-1$ degrees of freedom, where $n$ is the sample size. In this case, by the definition of the $T$-distribution (Section~\\ref{sect:tdist}), the T statistic follows a Student's T-distribution with $n-1$ degrees of freedom. As the number of samples, $n$, grows, the sample standard deviation approaches the population standard deviation and the T-test becomes a Z-test. But when $n$ is small, the T-test is quite a bit more conservative.}. Here $\\overline{x}$ refers to the sample mean, and $s$ refers to the \\textbf{sample standard deviation}:\n$$ s = \\sqrt{\\frac{1}{n-1} \\sum_{i=1}^n (x^{(i)} - \\overline{x})^2} $$\n\n\\begin{question}{}\nCompare the formula for the sample standard deviation to the maximum likelihood estimate of the parameter, $\\sigma$, of a normal distribution (Section~\\ref{sect:mlenormal}). What is the same/different? Note in particular the use of $n-1$ in the denominator, rather than $n$. This arises because the MLE for $\\sigma$, $\\hat{\\sigma}$, is a \\textbf{biased} estimate of the population standard deviation (more on this later). For large $n$, however, the two are nearly identical. \n\\end{question}\n\n\\subsection{Two Independent Samples, Equal Variance}\n\nAssume you have a dataset $x^{(1)}, \\dots, x^{(n)}$ and another dataset $y^{(1)}, \\dots, y^{(m)}$. You assume that both are drawn from normal distributions with equal variance but potentially different means. You want to test whether the means are equal. \n\nThe same basic machinery for the one-sample T-test can be deployed in this context with a slightly different test statistic. The test statistic\n$$ T = \\frac{\\overline{x} - \\overline{y}}{s_p \\sqrt{\\cfrac{1}{n} + \\cfrac{1}{m}}} $$\nwhere\n\\begin{align*} s_p^2 &= \\frac{(n-1) s_x^2 + (m-1) s_y^2}{m + n - 2} \\\\\ns_x^2 &= \\frac{1}{n-1} \\sum_{i=1}^n (x^{(i)} - \\overline{x})^2 \\\\\ns_y^2 &= \\frac{1}{m-1} \\sum_{i=1}^m (y^{(i)} - \\overline{y})^2 \\end{align*}\nfollows a $t$-distribution with $m + n - 2$ degrees of freedom.\n\n\\subsection{Two Independent Samples, Unequal Variance}\n\nSometimes you have two independent samples but cannot assume the variances are equal. Again, similar machinery can be deployed. In this case, you can use \\textbf{Welch's T-test}, which uses the test statistic\n$$ T = \\frac{\\overline{x} - \\overline{y}}{s_{xy}} $$\nwhere \n$$ s_{xy} = \\sqrt{\\frac{s_x^2}{n} + \\frac{s_y^2}{m}}. $$\nThis test statistic approximately follows a $t$-distribution with degrees of freedom given by the {Welch-Sattherwaite Equation}\n$$ \\text{d.f.} = \\frac{\\left(\\cfrac{s_x^2}{n} + \\cfrac{s_y^2}{m} \\right)^2}{\\cfrac{(s_x^2/n)^2}{n-1} + \\cfrac{(s_y^2/m)^2}{m-1}} $$ \n\n\\subsection{Matched Pairs}\n\nAssume you have a data set of matched pairs. This could be a set of measurements of the same individuals taken at two different points in time, for example, or paired measurements taken from individuals with similar characteristics. You want to test whether the second set of values have changed relative to the first set of values.\n\nTo do this, you can use a one-sample T-test on the \\emph{differences} of the individual pairs. If no change has occurred, you would expect the mean of those differences to be zero. If we define $x^{(i)}$ as the difference of the paired observations for sample $i$ and $\\overline{x}$ as $\\frac{1}{n}\\sum_{i=1}^n x^{(i)}$, the sample mean of those differences, then\n\n$$ T = \\frac{\\overline{x}}{s/\\sqrt{n}}$$\n\n\\noindent follows a T-distribution with $n-1$ degrees of freedom. \n\n\\begin{question}{}\nHere are some sample data. They come from a study that looked at the effect of ozone, a component of smog, on the weight gain of rats. (Original source: Biometrika 63: 421-434, 1976, reproduced in Rice's \\emph{Mathematical Statistics and Data Analysis}, p. 465.) A group of 22 seventy-day-old rats were kept in an environment containing ozone for $7$ days, and their weight gains were recorded. Another group of 23 rats of a similar age were kept in an ozone-free environment for a similar time and their weight gains were also recorded. Here are the data for the control group:\n\n{\\footnotesize \\tt\n\\begin{center}\n\\begin{tabular}{rlrr}\n  \\toprule\n  & group & original\\_weight & weight\\_gain \\\\ \n  \\midrule\n  1 & control & 340.8 & 41.0 \\\\ \n  2 & control & 389.1 & 25.9 \\\\ \n  3 & control & 355.2 & 13.1 \\\\ \n  4 & control & 421.8 & -16.9 \\\\ \n  5 & control & 377.1 & 15.4 \\\\ \n  6 & control & 404.3 & 22.4 \\\\ \n  7 & control & 321.2 & 29.4 \\\\ \n  8 & control & 447.5 & 26.0 \\\\ \n  9 & control & 305.9 & 38.4 \\\\ \n  10 & control & 335.9 & 21.9 \\\\ \n  11 & control & 386.3 & 27.3 \\\\ \n  12 & control & 377.0 & 17.4 \\\\ \n  13 & control & 357.2 & 27.4 \\\\ \n  14 & control & 441.7 & 17.7 \\\\ \n  15 & control & 383.7 & 21.4 \\\\ \n  16 & control & 373.7 & 26.6 \\\\ \n  17 & control & 336.0 & 24.9 \\\\ \n  18 & control & 419.4 & 18.3 \\\\ \n  19 & control & 287.1 & 28.5 \\\\ \n  20 & control & 602.8 & 21.8 \\\\ \n  21 & control & 325.4 & 19.2 \\\\ \n  22 & control & 452.4 & 26.0 \\\\ \n  23 & control & 398.9 & 22.7 \\\\ \n  \\midrule\n  Mean & control & 384.4 & 22.4 \\\\\n  St.Dev. & control & 65.5 & 10.8 \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\n\\noindent And here are the data for the ozone group:\n\n{\\footnotesize \\tt\n\\begin{center}\n\\begin{tabular}{rlrr}\n  \\toprule\n  & group & original\\_weight & weight\\_gain \\\\ \n  \\midrule\n  1 & ozone & 437.4 & 10.1 \\\\ \n  2 & ozone & 275.9 & 7.3 \\\\ \n  3 & ozone & 296.3 & -9.9 \\\\ \n  4 & ozone & 295.9 & 17.9 \\\\ \n  5 & ozone & 379.7 & 6.6 \\\\ \n  6 & ozone & 274.1 & 39.9 \\\\ \n  7 & ozone & 360.0 & -14.7 \\\\ \n  8 & ozone & 331.9 & -9.0 \\\\ \n  9 & ozone & 531.8 & 6.1 \\\\ \n  10 & ozone & 350.5 & 14.3 \\\\ \n  11 & ozone & 345.7 & 6.8 \\\\ \n  12 & ozone & 268.1 & -12.9 \\\\ \n  13 & ozone & 339.9 & 12.1 \\\\ \n  14 & ozone & 352.4 & -15.9 \\\\ \n  15 & ozone & 435.8 & 44.1 \\\\ \n  16 & ozone & 476.9 & 20.4 \\\\ \n  17 & ozone & 462.5 & 15.5 \\\\ \n  18 & ozone & 368.0 & 28.2 \\\\ \n  19 & ozone & 504.3 & 14.0 \\\\ \n  20 & ozone & 188.0 & 15.7 \\\\ \n  21 & ozone & 466.9 & 54.6 \\\\ \n  22 & ozone & 288.8 & -9.0 \\\\ \n  \\midrule\n  Mean & ozone & 365.0 & 11.0 \\\\\n  St.Dev. & ozone & 88.6 & 19.0 \\\\\n  \\bottomrule\n\\end{tabular}\n\\end{center}\n}\n\n\\begin{enumerate}\n\\item[(a)] Imagine that the population weight distribution of rats is known to be normal with $\\mu = 350$ (grams) and unknown $\\sigma$. How would you test the hypothesis that the mean of the control group is equal to the population mean? How would you test the hypothesis that the mean of the ozone group is equal to the population mean?\n\\item[(b)] How would you test the hypothesis that the mean original weights of the ozone and control groups are equal? Do not assume equal variance. \n\\item[(c)] How would you test the hypothesis that the mean weight gain in the ozone group is equal to the mean weight gain in the control group? Do not assume equal variance.\n\\item[(d)] How would your approach in part (c) change if you assumed the weight gains in the two groups had equal variance?\n\\end{enumerate}\n\n\\noindent Plug in the relevant numbers from the tables above to perform each hypothesis test with $\\alpha = 0.05$. The following table of critical values for the $T$-distribution\\footnote{Borrowed with gratitude from https://www.stat.purdue.edu/~lfindsen/stat503/t-Dist.pdf} may help you:\n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{img/t-distribution-critical-values.png}\n\\end{center}\n\n\\noindent \\textbf{Answers:} (a) One-sample $T$-test of control group original weights vs. null of $\\mu_0 = 350$; $T$-statistic is 2.5165, 22 d.f., two-sided $p$-value is 0.01964, reject null at $\\alpha=0.05$. One-sample $T$-test of ozone group original weights vs. null of $\\mu_0 = 350$; $T$-statistic is 0.7961, 21 d.f., two-sided $p$-value is 0.4349, fail to reject null at $\\alpha=0.05$. (b) Welch's two-sample $T$-test of control vs. ozone group original weights; $T$-statistic is 0.8293, d.f is estimated using the Welch-Sattherwaite equation at 38.619, two-sided $p$-value is 0.4120, fail to reject null at $\\alpha=0.05$. (c) Welch's two-sample $T$-test of control vs. ozone group weight gains; $T$-statistic is 2.4629, d.f. is estimated using the Welch-Sattherwaite equation at 32.918, two-sided $p$-value is 0.01918, reject null at $\\alpha=0.05$. (d) You would use Pearson's two-sample $T$-test, which assumes equal variances; $T$-statistic is 2.4919, d.f. is 43, two-sided $p$-value is 0.01664, reject null at $\\alpha=0.05$. \n\n\\end{question}\n", "meta": {"hexsha": "3d0be24e0a6850381a94c7805eb014c9bf3334e3", "size": 26350, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-hypothesis-testing.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-hypothesis-testing.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-hypothesis-testing.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": 85.0, "max_line_length": 1034, "alphanum_fraction": 0.7240607211, "num_tokens": 7280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6316713868051841}}
{"text": "\\documentclass[]{revision-notes}\n\n\\addbibresource{QT.bib}\n\n\\title{PHYS11019: Quantum Theory}\n\\subtitle{Integrals. SO MANY INTEGRALS.}\n\\author{James Shaw}\n\\date{Spring 2018}\n\n\\begin{document}\n\\input{titlepage}\n\n\\tableofcontents % prints Table of Contents\n\n\\chapter{Back to Basics --- Quantum Mechanics Style}\n\\section{Double Slit Experiment}\n\nThe double slit experiment demonstrates some of the most important points of quantum mechanics.\nFeynman was a particular fan of it. We make $P_1 = \\abs{\\phi_1}^2$ the probability of a particle passing through the first slit and likewise for $P_2$.\nClassically, we'd expect that $$P_{1\\text{ or }2} = P_1 + P_2 = \\abs{\\phi_1}^2 + \\abs{\\phi_2}^2,$$ which is all well and good but isn't what happens when we approach the quantum world.\n\nWe define two states, $\\ket{i}$ and $\\ket{f}$, the initial and final states, and two intermediate states $\\ket{1}, \\ket{2} \\in \\mathcal{H}$ for each of the slits.\nThese are vectors in a Hilbert space, and as such are linear superposable and have dual basis vectors $\\bra{i}, \\bra{f}, \\bra{1}, \\bra{2} \\in \\mathcal{H}^\\ast$.\nThese define the normalisation ($\\braket{\\psi} = 1$) and are used to great effect elsewhere.\n\nThe probabilities in this formalism are defined by\n\\begin{align*}\n  P(i \\to f) &= \\abs{\\bra{f}\\ket{i}}^2\\\\\n   &= \\abs{\\bra{f}\\ket{1}\\bra{1}\\ket{i} + \\bra{f}\\ket{2}\\bra{2}\\ket{i}}^2\\\\\n  &= \\abs{\\bra{f}\\ket{1}\\bra{1}\\ket{i}}^2 + \\abs{\\bra{f}\\ket{2}\\bra{2}\\ket{i}} + 2 \\Re(\\bra{f}\\ket{1}\\bra{1}\\ket{i}^\\ast \\bra{f}\\ket{2}\\bra{2}\\ket{i})\n\\end{align*}\nwhere the completeness of the Hilbert space has been used.\nThis asserts that \\[ \\hat{\\mathbbm{1}} = \\sum_{\\text{states}\\, k} \\dyad{k}\\] where \\( \\ket{k}\\in\\mathcal{H} \\) are orthonormal basis vectors.\nThis is what is meant by ``inserting a complete set of states''.\nOrthonormality of discrete eigenvectors (eigenfunctions, eigenstates\\ldots) is defined by \\[ \\braket{n}{m} = \\delta_{mn}\\] and in the continuous limit is defined by \\[\\braket{x}{x^\\prime} \\delta(x-x^\\prime).\\]\n\nWe can change the basis of a set of states with \\[\\ket{\\bar{n}} = \\sum_{m} \\ket{m}\\braket{m}{\\bar{n}} \\] where \\(\\braket{m}{n} = U_{mn}\\) where $U \\in \\mathrm{SL}(n)$.\n\n\\section{Operators and Observables}\nAn observable \\(\\hat\\xi = \\sum_n \\xi_n \\op{n}\\) is an operator which satisfies the following properties:\n\\begin{enumerate}\n  \\item That there are states \\(\\ket{n}\\) which are eigenstates of $\\hat \\xi$ such that $\\xi_n \\in \\mathbb{R}$ are the eigenvalues.\n  This comes from the spectral theorem and representation.\n  \\item It is hermitian, that is to say \\[\\mel{\\phi}{\\hat\\xi^\\dagger}{\\psi} =\\mel{\\phi}{\\hat\\xi}{\\psi}\\] which requires that the eigenvalues $\\xi_n$ are real by the spectral theorem.\n  \\item It is complex-linear, such that \\[ \\hat\\xi(c_1 \\ket{\\psi_1} + c_2 \\ket{\\psi_2} ) = c_1\\hat\\xi \\ket{\\psi_1} + c_2\\hat\\xi \\ket{\\psi_2} \\] for $c_i \\in \\mathbb{C}$. This comes from the definition of the Hilbert space.\n  \\item It commutes with other observables, such that if $\\hat{\\chi}$ is an observable, then $\\commutator{\\hat\\chi}{\\hat\\xi}=0$.\n\\end{enumerate}\n\nWhen we measure an observable, we get a collapse of the quantum states.\nThis is shown through the use of the \\emph{projection} operator, \\[\\hat{P}_n = \\ketbra{n}\\] which has the effect of throwing away all other states in a composite state.\nFor example, \\[ \\hat{P}_1 (c_1\\ket{1} + c_2\\ket{2}) = c_1\\ket{1}\\braket{1} + c_2\\ket{1}\\bra{1}\\ket{2} = c_1 \\ket{1} \\] which seems nice and obvious in the maths, but the physics behind it is \\emph{weird}.\n\nDegeneracy also makes this weird, but fundamentally it's just adding in more sums until everything is nicely in one state.\n\n\\section{Squish It All Together}\nWe move to the continuous variables of position and momentum space.\nThis is equivalent to having infinite slits in your diffraction grating.\n\n\\subsection{Position}\nPosition space is defined such that \\[ \\int_a^b \\psi(x) \\ket{x} \\dd{x}\\] with the orthonormality condition \\[\\braket{x}{x^\\prime}=\\delta(x-x^\\prime). \\]\nThis means we can define the projection on to position space as a function of the position, i.e.~\\[\\braket{x}{\\psi} = \\psi(x).\\]\nThe position operator is then \\[ \\hat{x} = \\int x \\ketbra{x} \\dd{x} \\] which is also known as the spectral resolution, and we've used the continuum analogue of the identity operator\n\\[ \\hat{\\mathbbm{1}} = \\int \\ketbra{x}\\dd{x}. \\]\n\n\\subsection{Momentum}\nWe use the fourier transform to find the momentum space.\nWe define states \\(\\ket{k}\\) conventionally such that \\[ \\ket{k} = \\frac{1}{\\sqrt{2\\pi}} \\int e^{ikx} \\ket{k} \\dd{x}\\] which allows us to identify that\n\\begin{align*}\n  \\braket{x}{k} &= \\frac{1}{\\sqrt{2\\pi}}e^{ikx} & \\braket{k}{x} &= \\frac{1}{\\sqrt{2\\pi}}e^{-ikx},\n\\end{align*}\nin turn showing that it is a unitary transformation between bases.\n\nIt's worth noting that \\[ \\tilde\\psi(k) = \\mathcal{F}\\qty[\\psi(x)].\\]\n\n\\subsection{Working Between The Two}\nWe use Feynman's trick to find the action of the momentum operator on the position basis, given by\n\\begin{align*}\n  \\hat{k} \\ket{x} &= \\frac{1}{\\sqrt{2\\pi}} \\int k e^{-ikx} \\ket{k} \\dd{k}\\\\\n  &= \\frac{i}{\\sqrt{2\\pi}} \\pdv{x} \\int e^{-ikx} \\ket{k} \\dd{k}\\\\\n  &= i \\pdv{x} \\ket{x}\n\\end{align*}\nwhich gives us the final results\n\\begin{align*}\n  \\mel{x}{\\hat{k}}{\\psi} &= -i\\pdv{x} \\psi & \\mel{k}{\\hat{x}}{\\tilde\\psi} &= i\\pdv{k}\\tilde\\psi.\n\\end{align*}\n\n\\subsection{Canonical Commutation Relation}\nThe fundamental result of quantum mechanics is given by the canonical commutation relation, \\[ \\commutator{\\hat{x}}{\\hat{k}} = i \\] which more practically is used as \\[\\commutator{\\hat{x}}{\\hat{p}} = i\\hbar. \\]\n\n\\section{Time is a Continuum. Lunchtime, doubly so}\nWe now increase the number of gratings, and take it to its continuum limit.\nFirstly, we define a system with \\(N\\) gratings arranged one after another.\nThis gives us states \\( \\ket{x_i, t_i} \\) where the \\(i\\) labels the grating, so \\(t_i\\) is the time the \\(i\\)-th grating is passed.\nUsing the Hilbert completeness relation, this gives us \\[\\braket{f}{i} = \\int \\braket{f}{x_1,t_1} \\braket{x_1,t_1}{i}\\dd{x_1}\\] for \\(N=1\\).\nIncreasing \\(N\\) further gives us \\[\\braket{f}{i} = \\idotsint \\braket{f}{x_1,t_1} \\braket{x_1,t_1}{x_2,t_2} \\bra{x_2, t_2}\\cdots\\ket{x_n,t_n}\\braket{x_n, t_n}{f}\\dd{x_1}\\cdots\\dd{x_n}\\] where the increasing number of integrals increases the precision, but makes actual calculations difficult.\n\nDefining \\(\\ket{i} = \\ket{x_0, t_0} \\) and \\( \\ket{f} = \\ket{x_{N+1}, t_{N+1}} \\) allows us to evenly space the gratings a distance \\( \\varepsilon \\) from each other with\n\\begin{alignat*}{3}\n  t_n &= t_0 + n\\varepsilon & \\qquad \\text{where}&\\qquad& \\varepsilon &= \\frac{t_{N+1} - t_0}{N+1}\n\\end{alignat*}\nwhich then allows us to write the transition amplitude as\n\\begin{align*}\n  \\braket{x_b, t_b}{x_a, t_a} &= \\qty(\\prod_{n=1}^{N}\\int\\dd{x_n})\\qty(\\prod_{n=1}^{N+1}\\braket{x_{n}, t_{n}}{x_{n-1}, t_{n-1}}).\n\\end{align*}\n\nTo make the maths neater, we define a new measure which compactifies this notation for the \\(N \\to \\infty \\) limit.\nThis is \\[ \\braket{x_b, t_b}{x_a, t_a} =  \\eval{\\int_{x_a}^{x_b}\\DD{x}\\braket{x_b, t_b}{x_a, t_a}}_{x(t)}. \\]\n\n\\chapter{Tiny Little Things Sort Of Moving Around Not Actually That Fast\\ldots{} Maybe}\n\\section{Classically Speaking, Actions Are Awkward}\nThe Lagrangian definition of the action is \\[ S[x(t)] = \\int_{t_a}^{t_b} L(x, \\dot{x}, t) \\dd{t} \\]\nwhere \\(L = T-V \\) is the classical Lagrangian (of a point particle in some generalised co-ordinate) and \\(S[x(t)]\\) is a functional of the position. We also have canonical momenta \\[ p = \\pdv{L}{\\dot{x}} \\] which coincide with regular momenta in most cases, rather like the energy function.\n\nWe define the functional derivative\n\\[ \\eval{\\frac{\\delta S}{\\delta x}}_{x = \\bar x} = 0 \\] which is a statement of Hamilton's principle, defining the classical trajectory where the endpoints are fixed. What it actually \\emph{means} is that we vary the action along a path by an infinitesimal using \\[ \\delta S = S[x + \\delta x] - S[x] \\] and Taylor expand. This leads to the Euler-Lagrange equation for the classical trajectory, \\[ \\dv{t}(\\pdv{L}{\\dot x}) - \\pdv{L}{x} = 0 \\] which defines the classical trajectory \\(\\bar{x} \\) on which the \\emph{classical action}\n\\(S_{\\mathrm{cl}} = S[\\bar x(t)]\\) is defined. This will come back later.\n\n\\section{Here Come The Irish With Their Principle Functions}\nIf we don't fix the later-in-time endpoint in space, we derive Hamilton's principle function.\nThe variation of \\( (x_b, t_b) \\mapsto (x_b, t_b) + (\\delta x_b, \\delta t_b)\\) (where we then take \\(\\variation{t_b} = 0\\)) gives us that this variation is \\begin{align*}\n  \\variation{S_{\\mathrm{cl}}} &= \\eval{\\pdv{L}{\\dot{x}}\\variation{x}}^{t_b}\\\\\n  &= p(t_b)\\variation{x}\\\\\n  \\implies \\pdv{S_{\\mathrm{cl}}}{x} &= p_b.\n\\end{align*}\n\nDoing the equivalent variation for variation-in-time for the endpoint in space, we get the Hamilton-Jacobi equation for the Hamiltonian, \\[\\variation{S_{\\mathrm{cl}} = - E_b \\variation{t_b}}\\] or otherwise written,\n\\[E(x_b, \\pdv{S_{\\mathrm{cl}}}{x_b}, t_b) + \\pdv{S_{\\mathrm{cl}}}{t_b} = 0\\] which \\emph{defines} Hamilton's principle function, which we've suspiciously also named \\(S_{\\mathrm{cl}}\\).\n\n\\section{Just how probable are these paths, then?}\nWe go back to the transition amplitudes.\nThrough some slightly iffy arguments involving ``intuition'', we define the path amplitudes as\n\\begin{align*}\n  \\eval{\\braket{x_a, t_a}{x_b, t_b}}_{x(t)} &\\sim \\exp[i\\int_{t_a}^{t_b} \\!\\!\\!\\phi(x, \\dot x, t) \\dd{t}]\\\\\n  &= e^{\\nicefrac{i}{\\hbar} S[x(t)]}.\n\\end{align*}\nwhich we can get an expression for the full transition with\n\\begin{align*}\n  \\braket{x_b, t_b}{x_a, t_a} &= \\int_{x_a}^{x_b}\\!\\DD{x} e^{\\nicefrac{i}{\\hbar} S[x(t)]}.\n\\end{align*}\n\nNow, this still has the funny \\(\\DD{x}\\) thing, which is defined as\n\\[\\int_{x_a}^{x_b}\\!\\DD{x} = \\lim_{N\\to \\infty} A_N \\prod_{n=1}^N \\int_{-\\infty}^{\\infty} \\dd{x_{n}} \\] where \\(A_N = (\\nu(\\varepsilon))^{N+1}\\) is a normalisation factor equal across each discrete step.\nIdeally, it should make the entire thing converge, but we now need to find what \\(\\nu(\\varepsilon)\\) is.\n\n\\section{Where's a potential when you need one?}\nWe take a discrete time approximation for the Lagrangian of a free particle, that is to say\n\\[ L = T = \\frac{1}{2} m \\dot{x}^2 \\approx \\frac{1}{2} m \\qty(\\frac{x_1 - x_0}{\\varepsilon})^2.\\]\nTurning this into a transition amplitude gives us (remembering that we've discretized time again)\n\\begin{align*}\n \\braket{x_b, t_b}{x_a, t_a} &= \\lim_{N\\to \\infty} A_N \\prod_{n=1}^N \\int_{-\\infty}^{\\infty} \\dd{x_{n}} \\exp[\\frac{i\\varepsilon}{\\hbar} \\frac{m}{2} \\sum_{n=1}^{N+1}\\qty(\\frac{x_n - x_{n-1}}{\\varepsilon})^2] \\intertext{which, using results from \\autoref{sec:nested-gaussians}, gives us}\n \\braket{x_b, t_b}{x_a, t_a} &= \\lim_{N\\to \\infty} A_N \\qty(\\frac{2 \\varepsilon \\hbar}{m})^{\\nicefrac{N}{2}} \\prod_{n=1}^N \\int_{-\\infty}^{\\infty} \\dd{x^\\prime_{n}} \\exp[i \\sum_{n=1}^{N+1}\\qty(\\frac{x^\\prime_n - x^\\prime_{n-1}}{\\varepsilon})^2]\\\\\n &= \\lim_{N\\to \\infty} A_N \\qty(\\frac{2\\pi i \\varepsilon \\hbar}{m})^{\\nicefrac{N}{2}} \\frac{1}{\\sqrt{N+1}}\\exp[\\frac{i\\qty(x^\\prime_b - x^\\prime_{a})^2}{\\varepsilon(N+1)}]\\\\\n &= \\lim_{N\\to\\infty}  A_N \\qty(\\frac{2\\pi i \\varepsilon \\hbar}{m})^{\\nicefrac{N+1}{2}} \\sqrt{\\frac{m}{2\\pi i \\hbar (N+1)\\varepsilon}}\\exp[\\frac{im}{2\\hbar}\\frac{\\qty(x_b - x_{a})^2}{\\varepsilon(N+1)}].\n\\end{align*}\nNow we must remember what we were trying to do --- find the normalisation \\(\\nu(\\varepsilon)\\) for the period \\(T = t_b - t_a = (N+1)\\varepsilon \\).\nTo do this, we impose the requirement that\n\\[ A_N \\qty(\\frac{2\\pi i \\varepsilon \\hbar}{m})^{\\nicefrac{N+1}{2}} = 1\\]\n which is equivalent to\n \\[\\nu(\\varepsilon) = \\sqrt{\\frac{2\\pi i \\varepsilon \\hbar}{m}},\\]\n  allowing us to simplify the above result into\n\\begin{equation}\\label{eqn:free-particle}\n  \\braket{x_b, t_b}{x_a, t_a} = \\sqrt{\\frac{m}{2\\pi i \\hbar T}}\\exp[i\\frac{m}{2\\hbar}\\frac{\\qty(x_b - x_{a})^2}{T}].\n\\end{equation}\n\nNow, it can be worked out easily that for a free particle,\n\\[ S_{\\mathrm{cl}} = \\frac{m}{2} \\frac{(x_b - x_a)^2}{T}\\] which is suspiciously similar to \\autoref{eqn:free-particle}, so we make an identification that\n\\begin{alignat*}{3}\n  \\braket{x_b, t_b}{x_a, t_a} &= F_0(T)e^{i\\nicefrac{S_{\\mathrm{cl}}}{\\hbar}} & \\qq{where} && F_0(T) &= \\sqrt{\\frac{m}{2\\pi i \\hbar T}}\n\\end{alignat*}\nwhich is a \\emph{very} helpful notation, since the prefactor is now independent of the endpoints.\n\nYou may notice that \\( \\nu(\\varepsilon) \\) diverges for infinitesimal \\(\\varepsilon \\), which is a little inconvenient, but we basically ignore it, as that choice of \\(\\nu\\) is only the first order term.\n\n\\section{Oscillation of its own accord}\nFor a harmonic oscillator, the ``discretize time'' method becomes awkward to do; however, there's another thing we can try.\nFirstly, the Lagrangian for the harmonic oscillator is\n\\[ L = \\frac{1}{2} m \\dot{x}^2 - \\frac{1}{2}m \\omega x^2\\] from which we can calculate the classical action,\n\\[ S_{\\mathrm{cl}} = \\frac{m\\omega}{2\\sin(\\omega T)} \\qty[(x_a^2 + x_b^2)\\cos(\\omega T) - 2x_a x_b]\\]\nand the Newtonian equation of motion, \\[ \\ddot{x} + \\omega^2 x = 0. \\]\n\nWe will write \\( x = \\bar{x} + \\eta \\) where \\(\\eta(t_a) = \\eta(t_b) = 0\\) is the deviation from the classical path (allowing us to use the variational principle).\nWe find that\n\\begin{align*}\n  S[x] = S[\\bar{x} + \\eta] &= \\frac{m}{2}\\int_{t_a}^{t_b} \\qty[ \\qty(\\dot{\\bar{x}} + \\dot\\eta)^2 - \\omega^2(\\bar{x} + \\eta)^2] \\dd{t}\\\\\n                    &= S[\\bar{x}] + S[\\eta] + m\\int_{t_a}^{t_b} \\dot{\\bar{x}}\\dot\\eta - \\omega^2\\bar{x}\\eta\\dd{t}\\\\\n                    &= S[\\bar{x}] + S[\\eta] + \\cancel{m[\\eta \\dot{\\bar{x}}]_{t_a}^{t_b}} - m \\int_{t_a}^{t_b}\\eta \\cancel{(\\ddot{\\bar{x}} + \\omega^2 \\bar{x}) }\\dd{t}\\\\\n                    &= S[\\bar{x}] + S[\\eta]\n\\end{align*}\nwhich is, in fact, true for any Lagrangian quadratic in \\(x\\).\nWe can also argue that \\[ \\int_{x_a}^{x_b} \\DD{x} = \\int_{0}^{0} \\DD{\\eta}\\] since \\(\\dd{x} = \\dd{\\eta} \\), which looks a bit weird, but it's a useful statement.\nThis gives us our transition amplitude\n\\begin{align*}\n  \\braket{x_b, t_b}{x_a, t_a} &= \\int_{x_a}^{x_b} e^{\\nicefrac{i}{\\hbar} S[x(t)]} \\DD{x}\\\\\n  &= e^{\\nicefrac{i}{\\hbar} S_{\\mathrm{cl}}} \\int_{0}^{0} e^{\\nicefrac{i}{\\hbar} S[\\eta]} \\DD{\\eta}\\\\\n  &\\equiv F_\\omega(T)e^{\\nicefrac{i}{\\hbar} S_{\\mathrm{cl}}}\n\\end{align*}\nwhich people solve in various ways, such as in \\cite{feynman2010quantum}. Apparently the easiest is to do it by inspection, where we notice that since \\( F_\\omega (T) \\) has no position dependence, we can also write it as\n\\begin{align*}\n  F_\\omega(T) &= \\braket{0, T}{0, 0}\\\\\n              &= \\int_\\mathbb{R} \\bra{0,T}\\ket{x,t}\\bra{x,t}\\ket{0,0} \\dd{x}\\\\\n              &= \\int_\\mathbb{R} \\dd{x} F_\\omega(T - t)e^{\\nicefrac{i}{\\hbar} S_{\\mathrm{cl}}(T-t)}\\,F_\\omega(t)e^{\\nicefrac{i}{\\hbar} S_{\\mathrm{cl}}(t)}\\\\\n              &= F_\\omega(T - t)\\, F_\\omega(t) \\int_\\mathbb{R} \\dd{x} e^{\\nicefrac{i}{\\hbar} (S_{\\mathrm{cl}}(T-t) + S_{\\mathrm{cl}}(t))}\n\\end{align*}\nat which point we use the definition of the classical action from earlier, notice that it's quadratic in \\(x \\) making it all a Fresnel integral, and abuse the nested Gaussians formula from \\autoref{sec:nested-gaussians}.\nThis gives us\n\\begin{equation*}\n  F_\\omega(T) = F_\\omega(T - t)\\, F_\\omega(t) \\sqrt{\\frac{2\\pi i \\hbar}{m\\omega} \\frac{\\sin\\omega(T-t) \\sin\\omega t}{\\sin \\omega T}}\n\\end{equation*}\nwhich we can look at and notice that \\( F_\\omega (T) \\) should probably be\n\\[ F_\\omega (T) = \\sqrt{\\frac{m\\omega}{2\\pi i \\hbar} \\frac{1}{\\sin \\omega T}} \\] if we want the two other terms to cancel out. There's no systematic way of doing this really, though taking the \\( T \\gg t \\) limit should result in the same.\n\n\\section{Driven to Distraction}\nThe forced harmonic oscillator has the Lagrangian\n\\[ L = \\frac{1}{2} m (\\dot{x}^2 - \\omega^2 x^2) + J(t)x \\]\nand equation of motion for the classical path\n\\[ \\ddot{\\bar{x}} + \\omega^2 \\bar{x} = \\frac{J}{m}. \\]\n\nThis leaves the classical action \\(S_\\mathrm{cl}[\\bar{x} + \\eta]_{J} \\), which helfully splits into independent terms like the unforced case, so it all works out rather nicely and we get\n\\begin{equation*}\n  \\braket{x_b, t_b}{x_a, t_a} = F_\\omega(T)e^{\\frac{i}{\\hbar} S_\\mathrm{cl}[\\bar{x}]_{J}}\n\\end{equation*}\nwhere we must calculate \\(S_\\mathrm{cl}\\).\n\n\\section{Shiftying Everything in Time on Our Terms}\nWe look at a generic Lagrangian, \\[ L= \\frac{1}{2} m \\dot{x}^2 - V(x, t) \\] which we can Legendre transform into the Hamiltonian formalism and do the path integral to get\n\\[ \\braket{x_b, t_b}{x_a, t_a} = \\int \\DD{x} \\int \\DD{p} \\exp[\\frac{i}{\\hbar} \\int_{t_a}^{t_b} \\dd{t} (p\\dot{x} - H(x, p, t))] \\]\nwhich comes from the infinitesimal amplitude\n\\begin{align*}\n  \\braket{x_{n+1}, t_{n+1}}{x_n, t_n} &= \\sqrt{\\frac{m}{2\\pi i \\varepsilon\\hbar}} \\exp[\\frac{i\\varepsilon}{\\hbar}\\qty{\\frac{m}{2}\\qty(\\frac{x_{n+1} - x_n}{\\varepsilon})^2 - V(x_n, t_n)}] \\\\\n  &= \\int_{-\\infty}^\\infty \\frac{1}{2\\pi\\hbar}\\exp[\\frac{ip_n}{\\hbar}(x_{n+1} - x_n) - \\frac{i\\varepsilon}{2m\\hbar}p_n^2 - \\frac{i\\varepsilon}{\\hbar}V(x_n, t_n)]\\dd{p}\\\\\n  &= \\int_{-\\infty}^\\infty \\mel{x_{n+1}}{\\exp[-\\frac{i\\varepsilon}{2m\\hbar}p_n^2]}{p_n} \\mel{p_n}{\\exp[ -\\frac{i\\varepsilon}{\\hbar}V(x_n, t_n)]}{x_{n}}\\dd{p}\\\\\n  &=\\mel{x_{n+1}}{\\exp[-\\frac{i\\varepsilon}{2m\\hbar}\\hat{p}_n^2]\\exp[ -\\frac{i\\varepsilon}{\\hbar}V(\\hat{x}_n, t_n)]}{x_{n}}\n\\end{align*}\nwhich has successfully been moved into an operators form, and looks rather suggestive.\nWe can use the Baker-Campbell-Hausdorff formula \\[ e^{\\hat{A}}e^{\\hat{B}} = e^{\\hat{A} + \\hat{B} + \\frac{1}{2}\\commutator{\\hat{A}}{\\hat{B}}} + \\cdots \\]\nto first order to turn this into the infinitesimal time evolution operator \\[\\braket{x_{n+1}, t_{n+1}}{x_{n}, t_{n}} = \\mel{x_{n+1}}{e^{-\\frac{i\\varepsilon}{\\hbar{}} \\hat{H}(t_n)}}{x_{n}}.\\]\nThis \\emph{defines} the time evolution operator for finite time for a time independent Hamiltonian,\n\\[ \\ket{x, t} = \\hat{U}(t, t_0)\\ket{x} = e^{-\\frac{i}{\\hbar{}} (t - t_0) \\hat{H}(t)}\\ket{x}.\\]\n\nFor time dependent Hamiltonians, we have (by the chain rule) that\n\\[ i\\hbar \\pdv{t}\\hat{H}(t, t_0) = \\hat{H}(t)\\hat{U}(t, t_0). \\]\n\\(\\hat{U}\\) is fundamentally changes in basis.\n\n\\section{Herren Schr\\\"odinger und Heisenberg kommen}\nUsing the time evolution operator, we can find derive the time-dependent Schr\\\"odinger equation, \\[ i\\hbar\\pdv{t}\\psi(x, t) = \\hat{H}\\psi(x, t) .\\]\n\nBy defining a time dependent state vector \\[ \\ket{\\psi, t} = \\hat{U}(t, t_0) \\ket{\\psi} \\] we introduce the Schr\\\"odinger picture of quantum mechanics where the bases are fixed and the states change, in opposition to the Heisenberg picture of fixed states and changing bases.\nThe choice of picture is a choice of where we put the time dependence, and does not change the physics of the problem.\n\nIn the Schr\\\"odinger picture, operators are time independent, so all evolution is done in-state. Contrastingly, in the Heisenberg picture, the operators are time \\emph{dependent}, and are given by \\[ \\hat{x}(t) = \\hat{U}^\\dagger(t, t_0)\\, \\hat{x}\\, \\hat{U}(t, t_0) \\] which is clearly the same if applied to a state. This time dependence gives the Heisenberg equation of motion almost immediately, which is\n\\begin{align*}\n  i\\hbar \\pdv{t}\\hat{O}(t) &= \\commutator{\\hat{O}(t)}{\\hat{H}(t)}.\n\\end{align*}\n\nWe say that an operator is conserved if \\(\\pdv{\\hat{O}}{t} = \\commutator{\\hat{O}(t)}{\\hat{H}(t)} = 0 \\).\n\n\\section{A British Miller (who happened to be really good at Maths) Cometh}\nMoments of recognition might've triggered at some point that \\( \\braket{x_a, t_a}{x_b, t_b} \\) is actually a Green's function of the Sch\\\"odinger equation, i.e.~\n\\begin{align*}\n  \\qty(\\hat{H} - i\\hbar\\pdv{t}) \\braket{x, t}{x^\\prime, t^\\prime} &= -i\\hbar \\delta(t- t^\\prime) \\delta(x - x^\\prime)\n\\end{align*}\nalthough this isn't quite true, as the time parameter isn't fixed automatically.\nSpecifically, this is the retarded Green's function, where we must impose causality, giving us\n\\begin{equation*}\n  G(x-x^\\prime, t - t^\\prime) =\n  \\begin{cases}\n    \\braket{x, t}{x^\\prime, t^\\prime} & t > t^\\prime \\\\\n    0 & t < t^\\prime\n  \\end{cases}\n\\end{equation*}\nwhich is kind of useful, since we can now use Green's function methods for finding states.\n\n\\section{Energy Eigenbasis}\nWe can use the eigenstates of the Hamiltonian as a pretty nifty basis, since the discretized energy levels means that everything is nicely sums. Specifically, if\n\\begin{align*}\n  \\hat{H}\\ket{n} &= E_n\\ket{n}\\\\\n  u_n(x) &= \\braket{x}{n}\n\\end{align*}\nthe practical upshot is that for \\(t > 0 \\), the colourful function is\n\\begin{align*}\n  G(x-y, t) \\equiv \\braket{x, t}{y, 0} &= \\mel{x}{e^{-\\nicefrac{i}{\\hbar}\\,t \\hat{H}}}{y}\\\\\n  &= \\sum_n e^{-\\nicefrac{i}{\\hbar}\\,t E_n} u_n(x)\\,u_n^\\ast(y).\n\\end{align*}\n\nThe trace of the energy eigenbasis gives us \\[ \\int_{-\\infty}^{\\infty} \\braket{x,t}{x,0} \\dd{x} = \\sum_n e^{-\\nicefrac{itE_n}{\\hbar}} \\] which is really somewhat useful.\\footnote{In the notes, at this point, there follows a good few examples which I simply cannot be bothered to type out, more's the pity. They don't actually seem to be that illuminating, though the Aharonov-Bohm effect is an interesting thing --- a magnetic field which by rights shouldn't effect the path of the particle does because integration.}\n\n\\section{Transition Elements}\nThe transition amplitude discovered several times now leads us to ask ``what is the weighted average of the paths on an operator?''.\nWe discover that it is\n\\begin{align*}\n  \\ev{x(t)}_S &\\equiv \\int_{x_a}^{x_b} x(t) \\, e^{\\frac{i}{\\hbar} S[x]} \\DD{x}\\\\\n  &= \\int_{-\\infty}^\\infty x \\int_x^{x_b} \\exp[\\frac{i}{\\hbar} \\int_t^{t_b} L \\dd{t^{\\prime\\prime}}]\\DD{x^{\\prime\\prime}} \\int^x_{x_a}\\exp[\\frac{i}{\\hbar} \\int^t_{t_a} L \\dd{t^{\\prime}}]\\DD{x^{\\prime}}\\dd{x}\\\\\n  &= \\mel{x_b, t_b}{\\hat{x}(t)}{x_a, t_b}\n\\end{align*}\nwhich connects the path integrals to the traditional operator version.\n\nSimilarly, \\[ \\ev{f(x(t))}_S \\equiv \\int_{x_a}^{x_b} f(x(t))\\, e^{\\frac{i}{\\hbar} S[x]} \\DD{x} = \\mel{x_b, t_b}{f(\\hat{x}(t))}{x_a, t_b}\\]\nwhich is going to come in handy.\n\n\\section{Time Ordered Products}\nIt's worth noting, as it hasn't been stated previously, that positions at different times do not commute in the Heisenberg (or any) picture, that is to say \\( \\commutator{\\hat{x}(t)}{\\hat{x}(t^\\prime)} \\neq 0 \\) for \\( t \\neq t^\\prime \\).\nThis motivates us to write\n\\[ \\ev{x(t) x(t^\\prime)}_S = \\mel{x_b, t_b}{T(\\hat{x}(t), \\hat{x}(t^\\prime))}{x_a, t_b} \\]\nwhere we define the \\emph{time ordered product} as \\[ T(\\hat{x}(t), \\hat{x}(t^\\prime)) \\equiv \\theta(t - t^\\prime)\\hat{x}(t)\\hat{x}(t^\\prime) + \\theta(t^\\prime - t)\\hat{x}(t^\\prime)\\hat{x}(t) \\] which has the operators ordered from latest to earliest.\n\nWe can apply this to more general states \\( \\ket{\\phi} \\& \\ket{\\psi} \\), giving\n\\begin{align*}\n  \\mel{\\psi}{T(\\hat{x}(t_1)) \\cdots \\hat{x}(t_2))}{\\phi} &= \\int \\dd{x_a} \\int \\dd{x_b} \\psi^\\ast (x_b, t_b) \\phi(x_a, t_a)  \\ev{x(t_1)\\cdots x(t_n)}_S\n\\end{align*}\nwhich are also known as correlation functions.\n\n\\section{Another Austrian, Another Theorem, Classical Physics?}\nBy considering the spatial derivatives of the transition elements, we derive Ehrenfest's theorem,\n\\begin{equation*}\n  \\ev{\\ddot{x}}_S = - \\frac{1}{m} \\ev{\\pdv{V}{x}}_S\n\\end{equation*}\nwhich looks a lot like Newton's 2nd law, and handily works like it too.\n\n\\chapter{Making It All A Bit Less Accurate}\n\\section{Perturbation Theory from Path Integrals}\nFinding exact solutions is tricky (or impossible), and usually not worth it.\nHowever, we can usually use perturbation theory by splitting the action into a solvable part and a perturbation, such as\n\\begin{align*}\n  S[x(t)] &= S_0[x(t)] + S_1[x(t)]\n\\end{align*}\nand then we can then consider (for slowly varying potentials), we can write\n\\begin{alignat*}{3}\n  S_0[x(t)] &= \\int_{t_a}^{t_b} \\frac{1}{2}m\\dot{x}^2 \\dd{t} & \\qq{and} &&  S_1[x(t)] &= -\\int_{t_a}^{t_b} V(x(t), t) \\dd{t}\\intertext{or}\n  S_0[x(t)] &= \\int_{t_a}^{t_b} \\frac{1}{2}m\\dot{x}^2 - U(x) \\dd{t} & \\qq{and} &&  S_1[x(t)] &= -\\int_{t_a}^{t_b} \\tilde{V}(x(t), t) \\dd{t}\n\\end{alignat*}\nwhere we split \\(V(x,t) = U(x) + \\tilde{V}(x,t)\\) where \\(U\\) is a solvable, time independent potential, often that of the Harmonic oscillator.\n\nSubstituting this separation into the transition amplitude gives\n\\begin{align*}\n  \\braket{x_b, t_b}{x_a, t_a} &= \\int_{x_a}^{x_b} \\exp[\\frac{i}{\\hbar}(S_0[x(t)] + S_1[x(t)])] \\DD{x}\\\\\n  &=  \\int_{x_a}^{x_b} e^{\\frac{i}{\\hbar}S_0[x(t)]}\\sum_{n=0}^\\infty \\frac{1}{n!}\\qty(\\frac{i}{\\hbar}S_1[x(t)])^2 \\DD{x}\\\\\n  &= \\braket{x_b, t_b}{x_a, t_a}_0 + \\sum_{n=1}^\\infty  \\frac{1}{n!}\\qty(\\frac{i}{\\hbar})^2 \\prod_{k=1}^{n} \\int_{t_a}^{t_b} \\dd{t_n} \\int_{x_a}^{x_b} \\DD{x} \\prod_{m=1}^{n}V(x(t_m), t_m) e^{\\frac{i}{\\hbar} S_0[x(t)] }\n\\end{align*}\nwhere the last one uses the time ordered product.\nInterpreting the last of those units is interesting, as\n\\begin{align*}\n  \\int_{x_a}^{x_b} \\DD{x} \\prod_{m=1}^{n}V(x(t_m), t_m) e^{\\frac{i}{\\hbar} S_0[x(t)] } = \\int \\dd{x_1} \\cdots \\int \\dd{x_n} &\\braket{x_b, t_b}{x_{n}, t_{n}}_0 V(x_n, t_n)  \\\\\n  &\\times \\braket{x_{n}, t_{n}}{x_{n-1}, t_{n-1}}_0 \\\\\n  & \\times \\cdots \\times V(x_1, t_1) \\braket{x_{2}, t_{2}}{x_{1}, t_{1}}_0\n\\end{align*}\nwhich means that the perturbation can be thought of as the sum of situations where the particle is scattered through interaction with the potential an increasing number of times with each unit.\n\nThe \\(x\\) and \\(t\\) integrals are needed to sum over all paths (as is the basic conceit of the path integral) and the \\( \\frac{1}{n!}\\) unit ensures that we don't overcount for each of the time ordered units.\nThere's an identity\\footnote{which I genuinely don't see the use of} which is that\n\\begin{equation*}\n  \\frac{1}{n!}\\int_{t_a}^{t_b} \\dd{t_n} \\cdots \\int_{t_a}^{t_b} \\dd{t_1} V(t_1) \\cdots V(t_n) = \\int_{t_a}^{t_b} \\dd{t_n} \\int_{t_a}^{t_n} \\dd{t_{n-1}} \\cdots \\int_{t_a}^{t_2} \\dd{t_1} V(t_1) \\cdots V(t_n)\n\\end{equation*}\nfor\\ldots reasons\\ldots\nUsing this identity, we can get rid of the factorials and find that\n\\begin{align*}\n    \\braket{x_b, t_b}{x_a, t_a} &= \\braket{x_b, t_b}{x_a, t_a}_0 + \\sum_{n=1}^\\infty \\qty(-\\frac{i}{\\hbar})^n \\prod_{k=1}^{n} \\int_{t_a}^{t_{n+1}} \\dd{t_n} \\int_{x_a}^{x_b} \\DD{x} \\prod_{m=1}^{n}V(x(t_m), t_m) e^{\\frac{i}{\\hbar} S_0[x(t)] }.\n\\end{align*}\n\nSome rewriting can occur, it all makes a meal out of getting to a statement which feels sort of intuitive, \\begin{equation*}\n  \\braket{x_b, t_b}{x_a, t_a} = \\braket{x_b, t_b}{x_a, t_a}_0  - \\frac{i}{\\hbar} \\int_{-\\infty}^\\infty \\dd{x} \\int_{t_a}^{t_b} \\dd{t} \\braket{x_b, t_b}{x, t}_0 V(x, t) \\braket{x, t}{x_a, t_a}.\n\\end{equation*}\nThis looks a little funky, but it's fine really; look at it as a weird application of the Green's function at different times.\nIt's worth noting that the last term (the \\( \\braket{x, t}{x_a, t_a}\\)) is in relation to the full action, not just the unperturbed, so this is actually a hugely telescoping thing, which we can choose to use as many or as few terms of it as wanted.\n\nWe can apply this for a general wavefunction as\n\\begin{align*}\n  \\braket{x, t}{\\psi} &= \\braket{x, t}{\\psi}_0 - \\frac{i}{\\hbar}\\int_{-\\infty}^\\infty \\dd{x^\\prime} \\int_{t_0}^t \\dd{t} \\braket{x, t}{x^\\prime, t^\\prime}_0 V(x^\\prime, t^\\prime) \\braket{x^\\prime, t^\\prime}{\\psi}\n\\end{align*}\nwhich really emphasises the Green's function nature.\n\n\\section{Shooting Things At A Target Which Doesn't Move}\nWe invent a scattering operator, the \\(S\\) matrix, defined by\n\\begin{align*}\n  \\lim_{t_b \\to \\infty} \\lim_{t_a \\to -\\infty} \\braket{\\vec{r}_b, t_b}{\\vec{r}_a, t_a} &=   \\lim_{t_b \\to \\infty} \\lim_{t_a \\to -\\infty} \\mel{\\vec{r}_b}{\\hat{U}(t_b, t_a)}{\\vec{r}_a}\\\\\n  &\\equiv \\mel{\\vec{r}_b}{\\hat{S}}{\\vec{r}_a}\\\\\n  &= \\lim_{T \\to \\infty} \\braket{\\vec{r}_b, T}{\\vec{r}_a, 0}\n\\end{align*}\nwhich means we define in (at \\( r_a \\)) and out (at \\( r_b \\)) states at infinite time, but have the choice to start our internal clock whenever.\n\nIn the region outside the potential, we assume that the incident particle is a free particle with Lagrangian \\[L_0 (\\vec{r}) = \\frac{m}{2} \\qty(\\dot{x}_1^2 + \\dot{x}_2^2 + \\dot{x}_3^2).\\]\n\nWe then calculate to increasing orders in perturbation theory, the first order of which is\n\\begin{align*}\n  A_1 &= - \\frac{i}{\\hbar} \\int_{-\\infty}^\\infty \\dd[3]{r} \\int_{0}^{T} \\dd{t} \\braket{\\vec{r}_b, t_b}{\\vec{r}, t}_0 V(x, t) \\braket{\\vec{r}, t}{\\vec{r}_a, t_a}\\\\\n      &= - \\frac{i}{\\hbar} \\int_{-\\infty}^{\\infty} \\dd[3]{r} \\int^T_0 \\dd{t} \\qty(\\frac{m}{2\\pi i \\hbar (T-t)})^{\\nicefrac{3}{2}}\\exp{\\frac{im\\abs{\\vec{r}_b - \\vec{r}}^2}{2\\hbar (T - t)}} V(\\vec{r})\\\\\n      &\\mspace{300mu}\\times\\qty(\\frac{m}{2\\pi i \\hbar t})^{\\nicefrac{3}{2}}\\exp{\\frac{im\\abs{\\vec{r} - \\vec{r}_a}^2}{2\\hbar (T - t)}}.\n\\end{align*}\nSolving that integral is a little tricky.\nIt requires a pretty complicated statement which you can probably just look up.\nWe set \\( R_a = \\abs{\\vec{r}_a - \\vec{r}} \\) and \\( R_b = \\abs{\\vec{r}_b - \\vec{r}} \\) and thus get\n\\begin{equation*}\nA_1 = -\\frac{i}{\\hbar}\\qty(\\frac{m}{2\\pi i\\hbar{}})^{\\nicefrac{5}{2}} \\frac{1}{T^{\\nicefrac{3}{2}}} \\int^\\infty_{-\\infty} \\qty(\\frac{1}{R_a} + \\frac{1}{R_b}) V(\\vec{r}) \\exp[\\frac{im}{2\\hbar T}(R_a + R_b)^2] \\dd[3]{r}\n\\end{equation*}\n\nWe continue our quest to rewrite this ever less accurately by assuming that the potential is short range and thus expanding the statements\n\\[ R_i = \\abs{\\vec{r}_i - \\vec{r}} \\approx r_i - \\vec{n}_i \\vdot \\vec{r} \\]\nwhich, with substitution and expansion, gives\n\\begin{multline*}\n  A_1 = -\\frac{i}{\\hbar}\\qty(\\frac{m}{2\\pi i\\hbar{}})^{\\nicefrac{5}{2}} \\frac{1}{T^{\\nicefrac{3}{2}}} \\qty(\\frac{1}{r_a} + \\frac{1}{r_b}) \\exp[\\frac{im}{2\\hbar T}(r_a + r_b)^2] \\\\\n  \\times\\int^\\infty_{-\\infty}  V(\\vec{r}) \\exp[\\frac{im}{\\hbar T}(r_a + r_b)(\\vec{n}_a + \\vec{n}_b)\\vdot{\\vec{r}}] \\dd[3]{r}\n\\end{multline*}\n\n\\subsection{Transfers}\nBy assuming that most of the time the particle is a free particle, we can assume its speed is \\[ u = \\frac{r_a + r_b}{T} \\] which then makes\n\\begin{align*}\n  p &= m\\frac{r_a + r_b}{T} & E &= \\frac{1}{2} m \\qty(\\frac{r_a + r_b}{T})^2\n\\end{align*}\nand the vector momentum is thus \\[ \\vec{p}_i = -p \\vec{n}_i \\qq{for} i \\in \\{a, b\\}. \\]\nThe momentum transfer (i.e.~the change in momentum due to the interactions) is\n\\begin{align*}\n  \\vec{p}_a - \\vec{p}_b &= -m\\frac{r_a + r_b}{T} (\\vec{n}_a + \\vec{n}_b)\\\\\n  &\\equiv \\hbar \\vec{k}\n\\end{align*}\n\nThis gives us \\emph{YET ANOTHER} rewriting,\n\\begin{align*}\n  A_1 &= -\\frac{i}{\\hbar}\\qty(\\frac{m}{2\\pi i\\hbar{}})^{\\nicefrac{5}{2}} \\frac{1}{T^{\\nicefrac{3}{2}}} \\qty(\\frac{r_a + r_b}{r_a r_b}) \\exp[\\frac{i}{\\hbar}ET] \\int^\\infty_{-\\infty}  V(\\vec{r}) \\exp[i\\vec{k}\\vdot{\\vec{r}}] \\dd[3]{r}\n\\end{align*}\nand we define (for the sake of easier writing later)\n\\begin{align*}\n  \\tilde{V}(\\vec{k}) &= \\int^\\infty_{-\\infty}  V(\\vec{r}) \\exp[i\\vec{k}\\vdot{\\vec{r}}] \\dd[3]{r}\n\\end{align*}\nwhich also emphasises that this is just the Fourier transform of the potential --- wave-particle duality is becoming a thing.\n\n\\subsection{Transition Probability}\nThe transition probability (from the starting position to a specific endpoint)\n\\begin{equation*}\n  P(a \\to b) = \\abs{A_1}^2 = \\frac{1}{\\hbar^2} \\qty(\\frac{m}{2\\pi\\hbar})^5 \\frac{1}{T^3} \\qty(\\frac{r_a + r_b}{r_a r_b})^2 \\abs{\\tilde{V}(\\vec{k})}^2.\n\\end{equation*}\n\nFor a no-scatter situation --- where the particle doesn't interact with the potential --- we use the free particle transition amplitudes\n\\begin{align*}\n  A_0 = \\braket{\\vec{r}_c, T}{\\vec{r}_a, 0}_0 &= \\qty(\\frac{m}{2\\pi i \\hbar T})^{\\nicefrac{3}{2}} \\exp[i\\frac{m}{2\\hbar T}(\\vec{r}_c - \\vec{r}_a)^2]\\\\\n  \\implies P(a \\to c) = \\abs{A_0}^2 &= \\qty(\\frac{m}{2\\pi i \\hbar T})^{3}.\n\\end{align*}\n\nPutting these together to get the transition ratio gives\n\\begin{align*}\n  \\frac{P(a \\to b)}{P(a \\to c)} &= \\qty(\\frac{m}{2\\pi\\hbar^2})^2 \\qty(\\frac{r_a + r_b}{r_a r_b})^2 \\abs{\\tilde{V}(\\vec{k})}^2.\n\\end{align*}\n\n\\subsection{Cross Section}\nThe differential cross section (in the Born approximation) is the rate of scattering against an infinitesimal area \\( \\dd{\\sigma}\\) into an infinitesimal solid angle \\( \\dd{\\Omega} \\).\nThis gives us the statement that\n\\begin{align*}\n  \\frac{P(a \\to b)}{P(a \\to c)} &= \\qty(\\frac{r_a + r_b}{r_a r_b})^2 \\dv{\\sigma}{\\Omega}\\\\\n  \\implies\\qquad \\dv{\\sigma}{\\Omega} &= \\qty(\\frac{m}{2\\pi\\hbar^2})^2 \\abs{\\tilde{V}(\\vec{k})}^2.\n\\end{align*}\n\nIf \\(V(\\vec{r}) \\) only depends on r (i.e.~is a central potential), then\n\\begin{align*}\n  \\tilde{V}(\\vec{k}) &= \\int_{-\\infty}^{\\infty} V(r) \\exp i \\vec{k}\\vdot\\vec{r} \\\\\n  &= \\frac{4\\pi}{k}\\int_0^\\infty r\\,V(r) \\,\\sin(kr)\\dd{r}.\n\\end{align*}\nIn order to get this to converge, we will sometimes have to modify this to\n\\begin{align*}\n  \\tilde{V}(\\vec{k}) &= \\lim_{\\mu \\to 0} \\int_0^\\infty r\\,V(r) \\,\\sin(kr) e^{-\\mu r}\\dd{r}\n\\end{align*}\nwhere \\( k = \\frac{1}{\\hbar} \\abs{\\vec{p}_a - \\vec{p}_b} = \\frac{2p}{\\hbar}\\sin(\\nicefrac{\\theta}{2}) \\).\n\n\\begin{example}\n  For any \\(V(r) \\propto -\\frac{1}{r}\\), we can use the forced-convergence trick to find that\n  \\begin{align*}\n    \\int_0^\\infty r\\,V(r)\\,\\sin(kr) \\dd{r} &\\propto -\\frac{1}{k}\n  \\end{align*}\n  and hence\n  \\begin{align*}\n    \\dv{\\sigma}{\\Omega} &\\propto \\frac{1}{16E^2}\\frac{1}{\\sin^4(\\nicefrac{\\theta}{2})}\n  \\end{align*}\n  which, in the case of the Coulomb potential, happens to coincide with the Rutherford cross section.\n\\end{example}\n\n\\section{Shooting Beams at Each Other}\nTwo particles with masses \\(m_1\\) and \\(m_2 \\) interact with each other with a potential from either (effectivley pairwise).\nThe system has a two-variable Lagrangian\n\\[ L = \\frac{1}{2}m_1 \\abs{\\pdv{\\vec{r}_1}{t}}^2 + \\frac{1}{2}m_2 \\abs{\\pdv{\\vec{r}_2}{t}}^2 - V(\\vec{r}_1 - \\vec{r}_2). \\]\nWe shuffle this into the centre-of-mass frame, defining the postition of the centre of mass,\n\\begin{align*}\n  \\vec{R} &= \\frac{m_1 \\vec{r}_1 + m_2 \\vec{r}_2}{M} & M &= m_1 + m_2 \\intertext{and relative motion within the system}\n  \\vec{r} &= \\vec{r}_1 - \\vec{r}_2 & \\mu &= \\frac{ m_1 m_2 }{m_1 + m_2}\n\\end{align*}\nto give us a new Lagrangian\n\\[ L = \\frac{1}{2} M \\abs{\\pdv{\\vec{R}}{t}}^2 + \\frac{1}{2}\\mu \\abs{\\pdv{\\vec{r}}{t}}^2 - V(\\vec{r}). \\]\nIn the centre-of-mass frame, \\(\\vec{R} = 0\\), and \\(L = \\frac{1}{2}\\mu \\abs{\\pdv{\\vec{r}}{t}}^2 - V(\\vec{r})\\) which is the same as for the fixed-target, so we can use the same result as earlier, but define a new function\n\\begin{align*}\n  \\dv{\\sigma}{\\Omega} &= \\qty(\\frac{\\mu}{2\\pi\\hbar^2})^2 \\abs{\\tilde{V}(\\vec{k})}^2\\\\\n  &\\equiv \\abs{f(\\theta, \\phi)}^2\n\\end{align*}\nwhich we call the scattering amplitude.\n\nWe use the Born-Oppenheimer approximation where we assume one particle much more massive than the other, and this recovers the fixed-particle result.\n\nIf we have two indistinguishable particles, then there are two indistinguishable outcomes of the collision, resulting in\n\\begin{align*}\n  \\dv{\\sigma}{\\Omega} &= \\abs{f(\\theta) + f(\\pi - \\theta)}^2.\n\\end{align*}\nThis allows us to distinguish between fermions and bosons, since the result will be different due to the spin statistics theorem (fermions are antisymmetric).\n\n\\section{Operator?}\nWe can develop perturbation with the time evolution operator.\nWe define a new picture, the Dirac picture, which is the same as the Heisenberg picture but is done with respect to \\( S_0 \\) instead of \\(S\\), such that\n\\begin{equation*}\n  i\\hbar \\pdv{t} \\hat{U}_0 = \\hat{H}_0 \\hat{U}_0\n\\end{equation*}\nfor a time dependent Hamiltonian, and\n\\begin{equation*}\n  \\hat{U}_0 = \\exp[\\frac{i}{\\hbar} (t - t_0) \\hat{H}_0].\n\\end{equation*}\nThis allows us to define a new set of Heisenberg operators, for example\n\\[ \\hat{x}_0 (t) = \\hat{U}_0^\\dagger (t, t_0) \\, \\hat{x} \\,  \\hat{U}_0(t, t_0)\\]\n\n\\section{Time Dependent Transition}\nGoing all of the way back to the statement for the perturbative transition amplitude series, we can put the whole thing into the operator formalism, such that\n\\begin{align*}\n  \\hat{U}(t_a, t_b) &= \\hat{U}_0 (t_b, t_a) + \\sum_{n=1}^\\infty (-\\frac{i}{\\hbar})^n \\int^{t_b}_{t_a} \\dd{t_n} \\cdots \\int^{t_2}_{t_a} \\dd{t_1}\\\\\n  &\\mspace{100mu}\\times \\hat{U}_0(t_b, t_n) V(\\hat{x}, t_n) \\hat{U}_0(t_n, t_{n-1}) \\cdots V(\\hat{x}, t_1) \\hat{U}_0(t_1, t_a)\\\\\n  &= \\hat{U}_0 (t_b, t_a) -\\frac{i}{\\hbar} \\int^{t_b}_{t_a} \\dd{t_n} \\hat{U}_0(t_b, t) V(\\hat{x}, t) \\hat{U}(t, t_{a})\\\\\n\\end{align*}\n\nNow we remember that in the energy basis, \\(\\hat{H}_0\\) is a diagonal operator, which is useful, since \\[ \\braket{m,t}{n^\\prime, t^\\prime} = e^{-\\frac{i}{\\hbar}(t - t^\\prime)E_n} \\delta_{mn}.\\]\n\nUsing this for the transition gives\n\\begin{align*}\n  \\braket{b, t_b}{a, t_a} &= \\mel{b}{\\hat{U}(t_b, t_a)}{a}\\\\\n  &= \\mel{b}{\\hat{U}_0(t_b, t_a)}{a} - \\frac{i}{\\hbar} \\int_{t_a}^{t_b} \\mel{b}{\\hat{U}(t_b, t)V(\\hat{x}, t)\\hat{U}(t, t_a)}{a} \\dd{t} + \\cdots\\\\\n  &= e^{-\\frac{i}{\\hbar}(t_b - t_a)E_a}\\delta_{ab} - e^{-\\frac{i}{\\hbar}(E_bt_b - E_at_a)} \\int_{t_a}^{t_b} \\dd{t} e^{\\frac{i}{\\hbar}t (E_b - E_a)}V_{ba}(t)+ \\cdots\n\\end{align*}\nwhich corresponds to more and more interactions you add more potential interactions at different times (as number of terms increases).\n\nUsing this statement, we can see the first order interaction probability is\n\\begin{align*}\n   P(a \\to b) &= \\frac{1}{\\hbar^2} \\abs{\\tilde{V}_{ba}}^2\\intertext{where}\n   \\tilde{V}_{ba}(t) &= \\int_{t_a}^{t_b} \\dd{t}V_{ba}(t)\n\\end{align*}\nwhere we have defined, by convention, that\n\\begin{align*}\n V_{ab} &\\equiv \\mel{a}{V(\\hat{x}, t)}{b} = \\int_{-\\infty}^\\infty u_m^\\ast(x) V(x, t) u_n(x).\n\\end{align*}\n\nIf the perturbation is time independent, we derive Fermi's golden rule for the transition rate, \\[ R = \\frac{2\\pi}{\\hbar}\\abs{V_{ba}}^2 \\rho(E_b) \\] which is covered extensively elsewhere.\n\n\\chapter{Richard Feynman Sticks His Boot In}\nWe go back to classical mechanics for a bit, in order to motivate the point of the exercise.\nA forced \\emph{an}harmonic oscillator has an action \\(S = S_0[x]_J\\footnote{I'm not certain about this notation, but I know for sure and certain I don't like the one in the notes.} + S_1[x]\\) with Lagrangian \\[L = L_{\\text{Driven SHO}} - \\frac{\\lambda}{4}x^4 \\] and\n\\[ \\qty(\\pdv[2]{t} + \\omega^2)x = \\frac{J}{x} - \\frac{\\lambda}{m}x^3.\\]\n\n\n\\section{GREEEEEEEN *waves fist*}\nWe have the homogeneous equation \\[ \\qty(\\pdv[2]{t} + \\omega^2) \\bar{x}_0 = 0 \\] with logical (Neumann) boundary conditions.\nWith this in mind, we build a Green's function \\(\\Delta(t, t^\\prime)\\) such that \\[\\qty(\\pdv[2]{t} + \\omega^2) \\Delta(t, t^\\prime) = -\\delta(t - t^\\prime) \\] with boundary conditions \\( \\Delta(t_a, t^\\prime) = \\Delta(t_b, t^\\prime) = 0 \\).\n\nWe call \\(\\Delta\\) the Feynman Propagator, and solve it as\n\\begin{multline*}\n  \\Delta(t, t^\\prime) = \\frac{1}{\\omega \\sin\\omega T}\\big[\\theta(t - t^\\prime)\\sin\\omega(t_b - t)\\,\\sin\\omega(t^\\prime-t_a) \\\\+ \\theta(t^\\prime - t)\\sin\\omega(t_b - t^\\prime)\\,\\sin\\omega(t-t_a)\\big]\n\\end{multline*}\nwhich means that (as usual) the full solution for the classical solution is\n\\begin{align*}\n  \\bar{x}(t) = \\bar{x}_0(t) + \\frac{1}{m}\\int_{t_a}^{t_b} \\Delta(t, t^\\prime) \\qty(-J(t^\\prime) + \\lambda \\bar{x}(t^\\prime)^3) \\dd{t^\\prime}.\n\\end{align*}\nYou may notice the similarities between this and the previously derived quantum perturbation theories.\nThis is intentional.\nThe equation maps out ``trees of four-point interactions'' somehow.\n\n\\section{And again, it all becomes wibbly and weird}\nWe take our forced harmonic oscillator and sort it out so that\n\\begin{align*}\n  S_0[x]_J &= \\int_{t_a}^{t_a} \\qty(\\frac{m}{2} (\\dot{x}^2 - \\omega^2 x^2) + Jx)\\dd{t} & S_1[x] &= -\\frac{\\lambda}{4} \\int_{t_a}^{t_b} x^4 \\dd{\\tau}.\n\\end{align*}\nThis makes our transition (using functional derivatives)\n\\begin{align*}\n  \\mel{x_b, t_b}{T(\\hat{x}(t_1)\\cdots\\hat{x}(t_m))}{x_a, t_a}_J &= \\int x(t_1)\\cdots x(t_m)\\,e^{\\frac{i}{\\hbar}S[x]_J} \\DD{x}\\\\\n  &= \\int x(t_1)\\cdots x(t_m)\\,e^{\\frac{i}{\\hbar}S[x]_0 + \\int_{t_a}^{t_b} J(t) x(t) \\dd{t}} \\DD{x}\\\\\n  &= \\qty(\\frac{\\hbar}{i})^m \\frac{\\delta^m}{\\delta J(t_1)\\,\\cdots\\,\\delta J(t_m)} \\braket{x_b, t_b}{x_a, t_a}_J.\n\\end{align*}\n\n\\subsection{Wibblier and Weirder}\nWe expand \\(\\exp[\\frac{i}{\\hbar} S_1[x]] = \\exp[-\\frac{i}{\\hbar} \\frac{ \\lambda }{4}\\int_{t_a}^{t_b} \\dd{\\tau} x(\\tau)^4]\\) to get a perturbation expansion for the anharmonic oscillator\n\\begin{align*}\n  \\braket{x_b, t_b}{x_a, t_a}_J &= \\int_{x_a}^{x_b} \\DD{x} \\exp[\\frac{i}{\\hbar}(S_0[x]_J + S_1[x])]\\\\\n  &= \\sum_{n=0}^{\\infty} \\frac{1}{n!} \\qty(-\\frac{i\\lambda}{4\\hbar})^n \\int_{t_a}^{t_b} \\dd{\\tau_1} \\cdots \\int_{t_a}^{t_b} \\dd{\\tau_n}  \\int_{x_a}^{x_b} \\DD{x} x(\\tau_1)^4 \\cdots x(\\tau_2)^4 e^{\\frac{i}{\\hbar} S_0[x]_J} \\\\\n  &= \\sum_{n=0}^{\\infty} \\frac{1}{n!} \\qty(-\\frac{i\\lambda}{4\\hbar})^n \\qty[\\prod_{k=1}^n \\int_{t_a}^{t_b} \\dd{\\tau_k} \\qty{\\frac{\\hbar}{i}\\fdv[k]{J(\\tau_k)}}^4] \\int_{x_a}^{x_b} \\DD{x}  e^{\\frac{i}{\\hbar} S[x]_J}\\\\\n  &= \\exp[-\\frac{i\\lambda}{4\\hbar} \\int_{t_a}^{t_b} \\dd{\\tau} \\qty(\\frac{\\hbar}{i}\\fdv{J(\\tau)})^4] F_\\omega(T) \\exp[\\frac{i}{\\hbar} S[\\bar{x}]_J].\n\\end{align*}\n\nIf we make the assumptions required to use the Feynman Propagator, we can find a general expression for the correlation functions\n\\begin{multline*}\n  \\frac{1}{F_\\omega(T)} \\mel{0, t_b}{T(\\hat{x}(t_1)\\cdots\\hat{x}(t_n))}{0, t_a} \\\\= \\qty(\\frac{\\hbar}{i})^m \\frac{\\delta^m}{\\delta J(t_1)\\,\\cdots\\,\\delta J(t_m)} \\exp[-\\frac{i\\lambda}{4\\hbar} \\int_{t_a}^{t_b} \\dd{\\tau} \\qty(\\frac{\\hbar}{i}\\fdv{J(\\tau)})^4]\\\\\n  \\times \\exp[\\frac{i}{\\hbar} \\int_{t_a}^{t_b}\\int_{t_a}^{t_b}J(t)\\Delta(t, t^\\prime)J(t^\\prime)\\dd{t^\\prime}\\dd{t}].\n\\end{multline*}\n\n\\section{Special Results}\nWe have Wick's Theorem for the \\( n\\)-point correlation function (time ordered product of \\(n\\) position operators) which is that for a pure forced simple harmonic oscillator,\n\\begin{align*}\n  \\frac{1}{F_\\omega (T)} \\mel{0, t_b}{T(\\hat{x}(t_1) \\cdots \\hat{x}(t_n))}{0, t_a}_{J=0} &= \\qty(\\frac{i\\hbar}{m})^{\\nicefrac{m}{2}} \\sum_{\\text{all pairings}}\\Delta(t_{i_1}, t_{i_2})\\cdots \\Delta(t_{i_{m-1}}, t_{i_m}).\n\\end{align*}\n\nBy considering the first order of the first exponential (the anharmonic term), we can derive the first of the Feynman rules.\nIt's worth noting that in the integrals, we only care about terms which keep a \\( J(\\tau) \\) after functional differentiation, so the entire thing reduces to \\[\\frac{1}{F_\\omega(T)} \\mel{0, t_b}{T(\\hat{x}(t_1) \\hat{x}(t_2) \\hat{x}(t_3) \\hat{x}(t_4)) }{0, t_a}_{J=0} = -i \\frac{3!\\, \\lambda}{\\hbar}\\int_{t_a}^{t_b} \\dd{t} \\prod_{i=1}^{4}(\\frac{i\\hbar}{m}\\Delta(t, t_i))\\]\nwhich represents an interaction (or a crossing point on a Feynman diagram) since they all four propagators go terminate or start at \\(t\\).\n\n\\section{Doing It Over All Time}\nNone of these integrals converge for all times, since \\(\\Delta(t, t^\\prime)\\) doesn't have a limit and oscillates \\emph{wildly}.\nWe have three choices in this case, which are all roughly equivalent:\n\\begin{enumerate}\n  \\item Take \\( t = -i\\tau \\) as is the case in Statistical Mechanics\\footnote{which is one of the examples which were skipped earlier}\n  \\item Rotate \\(t\\) in the complex plane, such that \\( t \\mapsto t - i\\epsilon \\)\n  \\item Dampen the path integral by mapping \\[ S^\\prime = S + i\\epsilon \\int_{-\\infty}^\\infty x^2 \\dd{t} \\] which is called the `\\(i\\epsilon\\) prescription'. In this prescription we have \\( (\\omega^\\prime)^2 = \\omega^2 - i \\epsilon \\).\n\\end{enumerate}\n\nFor the propagator over all time, we define a new, cooler version which does everything the old one does and converges.\nWith all of the rewriting we've done, this feels like an anticlimax, but we find that\n\\begin{align*}\n  \\lim_{t_b\\to \\infty}\\lim_{t_a\\to -\\infty}\\Delta(t, t^\\prime) &= \\frac{1}{2i\\omega}\\qty(e^{-i\\omega(t-t^\\prime)} \\theta(t-t^\\prime) + e^{i\\omega(t-t^\\prime)} \\theta(t^\\prime - t))\\\\\n  &= \\Delta_F(t- t^\\prime).\n\\end{align*}\n\n\\chapter{Lots of Little Things Moving Around Really Rather Quickly\\ldots{} Maybe}\n\\section{The Klein-Gordon equation}\nIn special relativity\\footnote{I've skipped the four-vector stuff}, we know that the energy of a particle is given by\n\\[ E^2 = p^2 c^2 + m^2 c^4 \\]\nwhich mean that if we use the standard substitutions (\\(E \\mapsto i\\hbar \\pdv{t}\\) and \\(\\vec{p}\\mapsto i\\hbar\\grad\\)) which allows us to derive\n\\begin{align*}\n  m^2 c^4 \\phi(\\vec{r}, t) - \\hbar^2 c^2 \\laplacian \\phi(\\vec{r}, t) &= -\\hbar^2 \\pdv[2]{t}\\phi(\\vec{r}, t)\\\\\n  \\implies \\qquad (\\hbar^2\\partial^2 + m^2 c^2)\\phi(\\vec{r}, t) &= 0\n\\end{align*}\nwhich is the Klein-Gordon equation for the free particle. This is solvable with a 4-vector plane wave expression \\[\\phi(x) = e^{-ik\\vdot x} \\equiv e^{-i\\frac{p}{\\hbar}\\vdot x}.\\]\n\nThis has a couple of problems.\nFirstly, our basic idea that \\(\\hbar^2( \\omega^2 - c^2 \\vec{k}^2 ) = m^2 c^4\\) implies that there are negative energy particles; we'll deal with that later.\n\nSecondly, we can derive the probability current for the Schr\\\"odinger equation \\[0 = \\psi^\\ast (\\text{SE})  - \\psi (\\text{SE})^\\ast \\] which expands to\n\\[\\pdv{\\rho}{t} + \\div\\vec{j} = 0\\]\nwhere we find that\n\\begin{align*}\n  \\rho &= \\psi^\\ast \\psi & \\vec{j} &= -\\frac{i\\hbar}{2m}\\qty(\\psi^\\ast \\grad\\psi - \\psi \\grad\\psi^\\ast)\n\\end{align*}\nand for the Klein Gordon equation,\n\\begin{align*}\n  \\rho &= \\frac{i\\hbar}{2mc^2}\\qty(\\phi^\\ast \\pdv{t}\\phi - \\phi \\pdv{t}\\phi^\\ast) & \\vec{j} &= -\\frac{i\\hbar}{2m}\\qty(\\phi^\\ast \\grad\\phi - \\phi \\grad\\phi^\\ast)\n\\end{align*}\nwhich has the issue that \\(\\rho\\), the probability density, is not positive definite, so we can't interpret it \\emph{as} a probability density.\n\n\\section{Yet another thing named after Dirac}\nTo combat the two negative things, we try to find a different relativistic wave equation which is linear in \\( \\pdv{t}\\).\nWe start with the Schr\\\"odinger equation again, in the form\n\\[ i\\hbar\\pdv{t}\\psi(x) = \\hat{H}\\psi(x) \\]\nwhich we make a reasonably radical ansatz for, and get\n\\begin{align*}\n  i\\hbar\\pdv{t}\\psi(\\vec{r}, t) &= \\qty[c \\vec{\\alpha}\\vdot \\vec{\\hat{p}} + \\beta m c^2]\\psi(\\vec{r}, t) \\\\\n  &= \\hat{H}\\psi(\\vec{r}, t)\n\\end{align*}\nwhere \\(\\vec{\\alpha}\\) and \\(\\beta\\) are independent of all derivatives, so commute with all terms except each other.\nWe also require that\n\\[ \\hat{H}^2 \\psi = (c^2\\vec{\\hat{p}}^2 + m^2 c^4)\\psi\\]\nwhich after rearranging to compare with the previous ansatz gives us the anticommutator relations\n\\begin{align*}\n  \\anticommutator{\\alpha^i}{\\alpha^j} &= \\delta^{ij} & \\anticommutator{\\alpha^i}{\\beta} &= 0\n\\end{align*}\nand note that \\(\\beta^2 = 1\\).\nFrom these requirements, we guess that \\(\\alpha\\) and \\(\\beta\\) must actually be hermitian \\(n \\times n\\) matrices. We also note that they must be traceless, and have eigenvalues of \\(\\pm 1\\).\nWe use the smallest representation of \\(\\alpha\\) and \\(\\beta\\) which is in four dimensional matrices,\n\\begin{align*}\n  \\beta &= \\mqty(I&0\\\\0&-I) & \\vec{\\alpha}^i &= \\mqty(0 & \\sigma^i \\\\ \\sigma^i & 0)\n\\end{align*}\nwhere \\(\\sigma^i\\) are the Pauli matrices,\n\\begin{align*}\n  \\sigma^1 &= \\mqty(\\pmat{1}) & \\sigma^2 &= \\mqty(\\pmat{2}) & \\sigma^3 &= \\mqty(\\pmat{3})\n\\end{align*}\n which are unitary, hermitian and satisfy the anti-commutation relation required.\n\n The Hamiltonian is now a 4D matrix, so we must make a wavefunction to match. We give it a \\emph{spinor}\\footnote{pronounced ``spinner''} which is simply a four component column matrix (not a vector) in the format\n \\begin{align*}\n   \\psi(\\vec{r}, t) &= \\mqty(\\psi_1(\\vec{r},t)\\\\ \\psi_2(\\vec{r},t)\\\\ \\psi_3(\\vec{r},t)\\\\ \\psi_4(\\vec{r},t)).\n \\end{align*}\n\n\\subsection{Continuity}\nWe go back to the continuity equation, and doing the same thing with the Dirac equation as we did with the others, we find that\n\\begin{align*}\n  \\rho &= \\psi^\\dagger \\psi & \\vec{j} &= \\psi^\\dagger \\vec{\\alpha} \\psi & j^\\mu &= \\mqty(\\rho, \\vec{j})\n\\end{align*}\nwhich gives the covariant form of the continuity equation as \\[\\partial_\\mu j^\\mu = 0. \\]\nThis is now perfectly well defined for the probability density (huzzah!).\n\n\\section{Just Leave It Alone. It's The Only Thing To Do}\nFree particle \\(\\implies \\) plane wave, as always.\nHowever, we need a spinor version, so we invent a new spinor, \\(w(p)\\) which gives us\n\\begin{align*}\n  \\psi(\\vec{r}, t) &= \\exp(-\\frac{i}{\\hbar}p\\vdot x)\\,w(p)\\\\\n  &= \\exp(-\\frac{i}{\\hbar}(cp^0 t - \\vec{p}\\vdot\\vec{r}))\\,w(p).\n\\end{align*}\nThis leads us to a slightly different form of the Dirac equation,\n\\begin{align}\n  p^0 w (p) &= (\\vec{\\alpha} \\vdot \\vec{p} + \\beta m c)\\, w(p)\\label{eqn:pspace}\n\\end{align}\n called the \\(p\\)-space Dirac equation.\n\n This can be solved elegantly using a slightly funky formalism where\n \\[ w(p) = \\mqty(\\phi(p)\\\\\\chi(p))\\] which is a four-component spinor in terms of two two-component spinors.\n This makes \\autoref{eqn:pspace}\n \\begin{align*}\n   p^0 \\mqty(\\phi\\\\\\chi) &= \\mqty(mc & \\vec{\\sigma}\\vdot \\vec{p} \\\\ \\vec{\\sigma}\\vdot \\vec{p} & -mc ) \\mqty(\\phi\\\\\\chi)\n \\end{align*}\n which shows this off as an eigenvalue equation, which is nice, because we know how to solve them.\n Whatever your method of choice, you can find that\n \\begin{align*}\n   \\chi &= \\frac{\\vec{\\sigma}\\vdot\\vec{p}}{p^0 + mc}\\phi\\\\\n   p_0 \\phi &= \\qty(mc + \\frac{(\\vec{\\sigma}\\vdot \\vec{p})^2}{p^0 + mc})\\phi\n \\end{align*}\nwhich apparently shows that\n\\[(p^0)^2 = m^2c^2 + \\vec{p}^2\\]\nbut I'm unconvinced.\n\n\\subsection{Can a particle have Feng Shui?}\nAs usual, we identify \\(p^0 = \\nicefrac{E}{c}\\) with the energy of the particle.\nWe thus write the positive energy solutions as\n\\begin{align*}\n  w^{(i)}(p) &= \\mqty(\\phi^{(i)}\\\\\\frac{c \\vec{\\sigma}\\vdot\\vec{p} }{E + mc^2}\\phi^{(i)}) & \\phi^{(1)} &= \\mqty(1\\\\0) & \\phi^{(2)} &= \\mqty(0\\\\1)&  i \\in { 1, 2 }\n\\end{align*}\nwhere we have conventionally chosen the spinors (which have to be linearly independent, and preferably orthogonal).\n\nThis gives us that\n\\begin{align*}\n  w^{(1)}(p) &= \\begin{pmatrix}\n    1 \\\\ 0\\\\\n    \\frac{cp^3}{E+mc^2} \\\\ \\frac{c(p^1 + i p^2)}{E+mc^2}\n  \\end{pmatrix} &\n  w^{(2)}(p) &= \\begin{pmatrix}\n    0\\\\ 1\\\\\n    \\frac{c(p^1 + i p^2)}{E+mc^2} \\\\ \\frac{-cp^3}{E+mc^2}\n  \\end{pmatrix}\n\\end{align*}\nwhere it's worth noticing that \\( \\vec{\\sigma}\\vdot \\vec{p} \\) is not a scalar, since \\(\\vec{\\sigma}\\) is a horrible abuse of notation for the three Pauli matrices.\n\n\\subsection{Negative Energy}\nThe negative energy solutions (\\(p^0 = - \\nicefrac{E}{C}\\)) are written in terms of \\(\\chi\\), and conventionally we find that\n\\begin{align*}\n  w^{(i)}(-p) &= \\mqty(\\frac{c \\vec{\\sigma}\\vdot\\vec{p} }{E + mc^2}\\chi^{(i-2)}\\\\\\chi^{(i-2)}) & \\chi^{(1)} &= \\mqty(0\\\\1) & \\chi^{(2)} &= \\mqty(1\\\\0) &  i \\in { 3, 4 }.\n\\end{align*}\nWe choose the negative energy states to have negative momentum because of the Dirac Sea interpretation of particle physics in a faintly vector like object which can be iterated over.\n\nThis gives us that\n\\begin{align*}\n  w^{(3)}(-p) &= \\begin{pmatrix}\n    \\frac{c(p^1 + i p^2)}{E+mc^2} \\\\ \\frac{-cp^3}{E+mc^2}\\\\\n    0\\\\ 1\n  \\end{pmatrix} &\n  w^{(4)}(-p) &= \\begin{pmatrix}\n    \\frac{cp^3}{E+mc^2} \\\\ \\frac{c(p^1 + i p^2)}{E+mc^2}\\\\\n    1 \\\\ 0\n  \\end{pmatrix}\n\\end{align*}\nwhich represent the negative energy states of a spin-\\(\\nicefrac{1}{2}\\) particle.\n\n\\section{Let's stop it all moving around, just to keep track}\nWhen \\(\\vec{p} = 0\\), the \\(w\\) spinors become orthonormal, and we conventionally write them as\n\\begin{align*}\n  w^{(1)} &= \\mqty(1\\\\0\\\\0\\\\0) &\n  w^{(2)} &= \\mqty(0\\\\1\\\\0\\\\0) &\n  w^{(3)} &= \\mqty(0\\\\0\\\\0\\\\1) &\n  w^{(4)} &= \\mqty(0\\\\0\\\\1\\\\0)\n\\end{align*}\nand the positive-energy solutions become\n\\begin{align*}\n  \\psi^{(i)} &= e^{-i\\frac{mc^2}{\\hbar}t}\\, w^{(i)}\n\\end{align*}\nwhich means that they are degenerate, and there must be some other operator in the good quantum numbers for the rest frame.\n\nWe call this new operator \\[\\hat{\\Sigma}^3 = \\smqty(\\dmat{1,-1,1,-1}) \\] of which the four \\(w\\) spinors are all eigenvectors\\footnote{Eigenspinors? What \\emph{is} a spinor? How is it special? This entire section has some very questionable notation.} with values \\(\\pm 1\\).\nThat this is in fact part of a wider definition that\n\\begin{align}\n  \\hat{\\Sigma}^i &\\equiv \\mqty(\\dmat{\\sigma^i,\\sigma^i})\n\\end{align}\nis what leads us to believe that these are spin-\\(\\nicefrac{1}{2}\\) particles.\nThis comes from us defining \\(\\hat{s}^i = \\nicefrac{1}{2} \\hbar \\hat{\\Sigma}^i \\) which is exactly the spin operator.\nThis only commutes in the rest frame, as does the angular momentum \\(\\hat{\\vec{L}} = \\hat{\\vec{r}}\\times \\hat{\\vec{p}} \\), so neither of these are conserved, or good quantum numbers.\nHowever, the total angular momentum \\( \\hat{\\vec{J}} \\) commutes with the Dirac Hamiltonian in all frames.\n\n\\subsection{Helicity}\nWe can define a different operator which also commutes with the Hamiltonian, the Helicity operator\n\\begin{align*}\n  \\hat{h}(\\vec{p}) &= \\mqty(\\frac{\\vec{\\sigma}\\vdot \\vec{p}}{\\abs{\\vec{p}}} & 0 \\\\ 0 & \\frac{\\vec{\\sigma}\\vdot \\vec{p}}{\\abs{\\vec{p}}}) \\\\\n  &\\propto \\hat{\\vec{\\Sigma}} \\vdot \\frac{\\vec{p}}{\\abs{\\vec{p}}}\n\\end{align*}\nwhich has eigenvalues \\(\\pm 1 \\) --- this is the particle's spin along the direction of motion.\n\n\\section{The Dirac Sea}\nDirac proposed that all negative energy states are filled, with each energy level holding two electrons --- a spin up and a spin down.\nThe Pauli exclusion principle means that positive energy electrons can't just transition into a negative energy state without that state already being empty.\nThe negative energy states are unobservable, and are completely full in a complete vaccuum.\n\nThis is also a model for pair production.\nThe negative energy electron takes \\(2(E+mc^2)\\) in energy to jump up into its relative positive energy state, leaving behind a `hole' in the sea, which in this model is the positron (discovered after the model).\n\nQuantum field theory fixes the issue that this model doesn't work for bosons.\n\n\\section{Covariant Dirac Equation}\nThe Dirac Equation can be rewritten from\n\\begin{align*}\n  i\\hbar \\pdv{t} \\psi(\\vec{r}, t) &= \\qty(-i\\hbar c \\vec{\\alpha}\\vdot\\grad{} + \\beta{} mc^2)\\,\\psi(\\vec{r}, t)\\intertext{to}\n  0 &= \\qty[i\\hbar\\qty(\\gamma^0 \\pdv{x^0} + \\gamma^i \\pdv{x^i}) - mc] \\psi(\\vec{r}, t)\n\\end{align*}\nwhere we have defined\n\\begin{align*}\n  \\gamma &\\equiv (\\beta, \\beta\\vec{\\alpha}).\n\\end{align*}\n\nWe also now define the Feynman Slash notation, \\[\\slashed{a} \\equiv \\gamma^\\mu a_\\mu \\] which is the contraction with the \\(\\gamma\\) spinor.\nThis allows us to reduce this expression to \\[ (i \\hbar \\slashed{\\partial}- mc) \\psi(x) = 0\\] which is really very simple.\n\nThe plane wave solutions reduce to \\[ \\psi(x) = e^{-\\nicefrac{i}{\\hbar}p\\vdot x} u(p, s) \\] where this satisfies\n\\[ (\\slashed{p} - mc)\\, u(p, s) = 0 \\]\nand we've made new, less awkward to write, positive energy spinors \\[ u(p, s) \\equiv w^{(s)}(p).\\]\n\nThe negative energy states are the same, with \\[ \\psi(x) = e^{\\nicefrac{i}{\\hbar}p\\vdot x} v(p, s) \\] where this satisfies\n\\[ (\\slashed{p} + mc)\\, v(p, s) = 0 \\] and we've defined \\[v(p, s) \\equiv w^{(s + 2)}(-p).\\]\n\nThe \\(\\gamma\\) matrices satisfy the same anticommutation relations as we required earlier for \\(\\alpha\\) and \\(\\beta\\),\n\\[ \\anticommutator{\\gamma^\\mu}{\\gamma^\\nu} = 2 \\eta^{\\mu\\nu} \\]\nwhich is the requirements for a `Clifford Algebra'.\n\nWe can see from\n\\begin{align*}\n  \\gamma^i &= \\mqty(0 & \\sigma^i\\\\ - \\sigma^i & 0) & \\gamma^0 &= \\mqty(I&0\\\\0&-I)\n\\end{align*} that \\(\\gamma^0\\) is hermitian and \\(\\gamma^i \\) is anti-hermitian, which we need.\n\nWe also define\n\\begin{align*}\n  \\bar{\\psi} &= \\psi^\\dagger \\gamma^0\n\\end{align*}\nwhich new notation is called the covariant formulation.\n\nWe finally get to \\[ j^\\mu = \\bar{\\psi} \\gamma^\\mu \\psi\\] which conveniently transforms as a 4-vector.\n\n\\begin{note}\nAnd from here, it's the Pauli equation for electromagnetic interactions, which is just more Spinors. It's all a bit of a nightmare, but isn't too bad to work through.\n\\end{note}\n\n\n\\include{includes/appendices}\n\\printbibliography\n\\end{document}\n", "meta": {"hexsha": "40697c73b219bc27cea39f8a39c5703db35ef3e0", "size": 55758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Quantum_Revision.tex", "max_stars_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_stars_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Quantum_Revision.tex", "max_issues_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_issues_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_issues_repo_licenses": ["MIT"], "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_Revision.tex", "max_forks_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_forks_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_forks_repo_licenses": ["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.2209026128, "max_line_length": 529, "alphanum_fraction": 0.6571075003, "num_tokens": 20494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563824, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6316713775184479}}
{"text": "\\lab{Profiling and Optimizing Python Code}{Profiling}\n\\objective{Identify which portions of the code are most time consuming using a\nprofiler. Optimize Python code using good coding practices and just-in-time compilation with Numba.}\n\\label{lab:ProfilingCode}\n\nThe best code goes through multiple drafts.\nIn a first draft, you should focus on writing code that does what it is supposed\nto and is easy to read. After writing a first draft, you may find that your code\ndoes not run as quickly as you need it to. Then it is time to \\emph{optimize}\nthe most time consuming parts of your code so that they run as quickly as possible.\n\nIn this lab we will optimize the function \\li{qr1()} that computes the QR\ndecomposition of a matrix via the modified Gram-Schmidt algorithm\n(see Lab \\ref{lab:QRdecomp}).\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import linalg as la\n\ndef qr1(A):\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = la.norm(Q[:, i])\n        Q[:, i] = Q[:, i]/la.norm(Q[:, i])\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-Q[:, j].dot(Q[:, i])*Q[:,i]\n    return Q, R\n\\end{lstlisting}\n\n\\section*{What to Optimize}\nPython provides a \\emph{profiler} that can identify where code spends most of\nits runtime. The output of the profiler will tell you where to begin your\noptimization efforts.\n\nIn IPython\\footnote{If you are not using IPython, you will need to use the\n\\li{cProfile} module documented here: \\url{https://docs.python.org/2/library/profile.html}.},\nyou can profile a function with \\li{\\%prun}.\nHere we profile \\li{qr1()} on a random $300 \\times 300$ array.\n\n\\begin{lstlisting}\nIn [1]: A = np.random.rand(300, 300)\nIn [2]: %prun qr1(A)\n\\end{lstlisting}\n\nOn the author's computer, we get the following output.\n\n{\\scriptsize\n\\begin{verbatim}\n         97206 function calls in 1.343 seconds\n\n   Ordered by: internal time\n\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.998    0.998    1.342    1.342 profiling_hw.py:4(qr1)\n    89700    0.319    0.000    0.319    0.000 {method 'dot' of 'numpy.ndarray' objects}\n      600    0.006    0.000    0.012    0.000 function_base.py:526(asarray_chkfinite)\n      600    0.006    0.000    0.009    0.000 linalg.py:1840(norm)\n     1200    0.005    0.000    0.005    0.000 {method 'any' of 'numpy.ndarray' objects}\n      600    0.002    0.000    0.002    0.000 {method 'reduce' of 'numpy.ufunc' objects}\n     1200    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}\n     1200    0.001    0.000    0.002    0.000 numeric.py:167(asarray)\n        1    0.001    0.001    0.001    0.001 {method 'copy' of 'numpy.ndarray' objects}\n      600    0.001    0.000    0.022    0.000 misc.py:7(norm)\n      301    0.001    0.000    0.001    0.000 {range}\n        1    0.001    0.001    0.001    0.001 {numpy.core.multiarray.zeros}\n      600    0.001    0.000    0.001    0.000 {method 'ravel' of 'numpy.ndarray' objects}\n      600    0.000    0.000    0.000    0.000 {method 'conj' of 'numpy.ndarray' objects}\n        1    0.000    0.000    1.343    1.343 <string>:1(<module>)\n        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n\\end{verbatim}\n}\n\n\nThe first line of the output tells us that executing \\li{qr1(A)} results in\nalmost 100,000 function calls. Then we see a table listing these functions along\nwith data telling us how much time each takes. Here, \\li{ncalls} is the number\nof calls to the function, \\li{tottime} is the total time spent in the function,\nand \\li{cumtime} is the amount of time spent in the function including calls\nto other functions.\n\nFor example, the first line of the table is the function \\li{qr1(A)} itself.\nThis function was called once, it took 1.342s to run, and 0.344s of that was\nspent in calls to other functions. Of that 0.344s, there were 0.319s spent on\n89,700 calls to \\li{np.dot()}.\n\nWith this output, we see that most time is spent in multiplying matrices.\nSince we cannot write a faster method to do this multiplication, we may want to\ntry to reduce the number of matrix multiplications we perform.\n\n\\section*{How to Optimize}\nOnce you have identified those parts of your code that take the most time,\nhow do you make them run faster?\nHere are some of the techniques we will address in this lab:\n\n\\begin{itemize}\n\\item Avoid recomputing values\n\\item Avoid nested loops\n\\item Use existing functions instead of writing your own\n\\item Use generators when possible\n\\item Avoid excessive function calls\n\\item Write Pythonic code\n\\item Compiling Using Numba\n\\item Use a more efficient algorithm\n\\end{itemize}\n\nYou should always use the profiling and timing functions to help you decide\nwhen an optimization is actually useful.\n\n\\begin{problem}\nIn this lab, we will perform many comparisons between the runtimes of various\nfunctions. To help with these comparisions, implement the following function:\n\n\\begin{lstlisting}\ndef compare_timings(f, g, *args):\n    \"\"\"Compares the timings of 'f' and 'g' with arguments '*args'.\n\n    Inputs:\n        f (callable): first function to compare.\n        g (callable): second function to compare.\n        *args (any type): arguments to use when callings functions\n            'f' and 'g'\n    Returns:\n        comparison (string): The comparison of the runtimes of functions\n            'f' and 'g' in the following format :\n                Timing for <f>: <time>\n                Timing for <g>: <time>\n            where the values inside <> vary depending on the inputs)\n\\end{lstlisting}\nHint: You can gain access to the name of many functions by using its\n\\li{func_name} method. However, this method does not exist for all functions\nwe will be interested in timing. Therefore, even though it is not as clean, use\n\\li{str(f)} to print a string representation of f.\n\\end{problem}\n\n\\subsection*{Avoid Recomputing Values}\nIn our function \\li{qr1()}, we can avoid recomputing \\li{R[i,i]} in the outer\nloop and \\li{R[i,j]} in the inner loop.\nThe rewritten function is as follows:\n\\begin{lstlisting}\ndef qr2(A):\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = la.norm(Q[:, i])\n        Q[:, i] = Q[:, i]/R[i, i] # this line changed\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-R[i, j]*Q[:,i] # this line changed\n    return Q, R\n\\end{lstlisting}\n\nProfiling \\li{qr2()} on a $300 \\times 300$ matrix produces the following output.\n\n{\\scriptsize\n\\begin{verbatim}\n         48756 function calls in 1.047 seconds\n\n   Ordered by: internal time\n\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.863    0.863    1.047    1.047 profiling_hw.py:16(qr2)\n    44850    0.171    0.000    0.171    0.000 {method 'dot' of 'numpy.ndarray' objects}\n      300    0.003    0.000    0.006    0.000 function_base.py:526(asarray_chkfinite)\n      300    0.003    0.000    0.005    0.000 linalg.py:1840(norm)\n      600    0.002    0.000    0.002    0.000 {method 'any' of 'numpy.ndarray' objects}\n      300    0.001    0.000    0.001    0.000 {method 'reduce' of 'numpy.ufunc' objects}\n      301    0.001    0.000    0.001    0.000 {range}\n      600    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}\n      600    0.001    0.000    0.001    0.000 numeric.py:167(asarray)\n      300    0.000    0.000    0.012    0.000 misc.py:7(norm)\n        1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}\n      300    0.000    0.000    0.000    0.000 {method 'ravel' of 'numpy.ndarray' objects}\n        1    0.000    0.000    1.047    1.047 <string>:1(<module>)\n      300    0.000    0.000    0.000    0.000 {method 'conj' of 'numpy.ndarray' objects}\n        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}\n        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n\\end{verbatim}\n}\n\nOur optimization reduced almost every kind of function call by half, and reduced the total run time by 0.295s.\n\nSome less obvious ways to eliminate excess computations include moving computations out of loops, not copying large data structures, and simplifying mathematical expressions.\n\n\\subsection*{Avoid Nested Loops}\nFor many algorithms, the temporal complexity of an algorithm is determined by its loops. Nested loops quickly increase the temporal complexity.\nThe best way to avoid nested loops is to use NumPy array operations instead of iterating through arrays.\nIf you must use nested loops, focus your optimization efforts on the innermost loop, which gets called the most times.\n\n\\begin{problem}\nThe code below is an inefficient implementation of the LU\nalgorithm. Write a function \\li{LU_opt()} that is an optimized\nversion of \\li{LU()}. Look for ways to avoid recomputing values\nand avoid nested loops by using array slicing instead.\nPrint a comparison of the timing of the\noriginal function and your optimized function using your\n\\li{compare_timings} function.\n\\begin{lstlisting}\ndef LU(A):\n    \"\"\"Returns the LU decomposition of a square matrix.\"\"\"\n    n = A.shape[0]\n    U = np.array(np.copy(A), dtype=float)\n    L = np.eye(n)\n    for i in range(1,n):\n        for j in range(i):\n            L[i,j] = U[i,j]/U[j,j]\n            for k in range(j,n):\n                U[i,k] -= L[i,j] * U[j,k]\n    return L,U\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Use Existing Functions Instead of Writing Your Own}\nIf there is an intuitive operation you would like to perform on an array, chances are that NumPy or another library already has a function that does it.\nPython and NumPy functions have already been optimized, and are usually many times faster than the equivalent you might write.\nWe saw an example of this in Lab \\ref{lab:NumPyArrays} where we compared NumPy array multiplication with our own matrix multiplication implemented in Python.\n\n\\begin{problem} \\label{prob:add}\nWithout using any builtin functions, implement that following function:\n\\begin{lstlisting}\ndef mysum(X):\n    \"\"\" Return the sum of the elements of X.\n    Inputs:\n        X (array) - a 1-D array\n    \"\"\"\n\\end{lstlisting}\nPerform a comparision of \\li{mysum} to Python's builtin \\li{<<sum>>} function and\nNumPy's \\li{<<np.sum>>} using your \\li{compare_timings} function.\n\\end{problem}\n\n\\subsection*{Use Generators When Possible}\nWhen you are iterating through a list, you can often replace the list with a \\emph{generator}.\nInstead of storing the entire list in memory, a generator computes each item as it is needed.\nFor example, the code\n\\begin{lstlisting}\n>>> for i in range(100):\n...     print i\n\\end{lstlisting}\nstores the numbers 0 to 99 in memory, looks up each one in turn, and prints it.\nOn the other hand, the code\n\\begin{lstlisting}\n>>> for i in xrange(100):\n...     print i\n\\end{lstlisting}\nuses a generator instead of a list.\nThis code computes the first number in the specified range (which is 0), and prints it.\nThen it computes the next number (which is 1) and prints that.\n\nIn our example, replacing each \\li{range} with \\li{xrange} does not speed up \\li{qr2()} by a noticeable amount.\n\nThough the example below is contrived, it demonstrates the benefits of using generators.\n\\begin{lstlisting}\n# both these functions will return the first iterate of a loop of length 10^8.\ndef list_iter():\n    for i in range(10**8):\n        return i\n\ndef generator_iter():\n    for i in xrange(10**8):\n        return i\n\n>>> compare_timings(list_iter,generator_iter)\nTiming for <function list_iter at 0x7f3deb5a4488>: 1.93316888809\nTiming for <function generator_iter at 0x7f3deb5a4500>: 1.19209289551e-05\n\\end{lstlisting}\n\nIt is also possible to write your own generators.\nSay we have a function that returns an array. And say we want to iterate through this array later in our code. In situations like these, it is valuable to consider turning your function into a generator instead of returning the whole list. The benefits of this approach mirror the benefits of using \\li{xrange} instead of {range}. The only thing that needs to be adjusted is to change the \\li{return} statement to a \\li{yield} statement. Here is a quick example:\n\\begin{lstlisting}\ndef return_squares(n):\n    squares = []\n    for i in xrange(1,n+1):\n        squares.append(i**2)\n    return squares\n\ndef yield_squares(n):\n    for i in xrange(1,n+1):\n        yield i**2\n\\end{lstlisting}\nWhen yield is called, the single value is returned and all the local variables for the function are stored away until the next iteration. To iterate step-by-step through a generator, use the generator's \\li{<<next>>} method.\n\\begin{lstlisting}\n>>> squares = yield_squares(3)\n>>> squarees.next()\n1\n>>> squares.next()\n4\n>>> squares.next()\n9\n\\end{lstlisting}\n\nWe can also easily iterate through a generator using a for loop.\n\\begin{lstlisting}\n>>> for s in squares:\n...    print s,\n...\n1 4 9\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a generator that yields the first \\li{n} Fibonacci numbers.\n\\end{problem}\n\nIf you are interested in learning more about writing your own generators, see \\url{https://docs.python.org/2/tutorial/classes.html#generators} and \\url{https://wiki.python.org/moin/Generators}.\n\n\\subsection*{Avoid Excessive Function Calls}\nFunction calls take time.\nMoreover, looking up methods associated with objects takes time.\nRemoving ``dots'' can significantly speed up execution time.\n\nFor example, we could rewrite our function to reduce the number of times we need to look up the function \\li{la.norm()}.\n\n\\begin{lstlisting}\ndef qr2(A):\n    norm = la.norm # this reduces the number of function look ups.\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = norm(Q[:, i])\n        Q[:, i] = Q[:, i]/R[i, i]\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-R[i, j]*Q[:,i]\n    return Q, R\n\\end{lstlisting}\nOnce again, an analysis with \\li{\\%prun} reveals that this optimization does not help significantly in this case.\n\n\n\\subsection*{Write Pythonic Code}\nSeveral special features of Python allow you to write fast code easily.\nFirst, list comprehensions are much faster than for loops. These are particularly useful when building lists inside a loop.\nFor example, replace\n\\begin{lstlisting}\n>>> mylist = []\n>>> for i in xrange(100):\n...     mylist.append(math.sqrt(i))\n\\end{lstlisting}\nwith\n\\begin{lstlisting}\n>>> mylist = [math.sqrt(i) for i in xrange(100)]\n\\end{lstlisting}\nWe can accomplish the same thing using the \\li{map()} function, which is even faster.\n\\begin{lstlisting}\n>>> mylist = map(math.sqrt, xrange(100))\n\\end{lstlisting}\nThe analog of a list comprehension also exists for generators, dictionaries, and sets.\n\nSecond, swap values with a single assignment.\n\\begin{lstlisting}\n>>> a, b = 1, 2\n>>> a, b = b, a\n>>> print a, b\n2 1\n\\end{lstlisting}\n\nThird, many non-Boolean objects in Python have truth values.\nFor example, numbers are \\li{False} when equal to zero and \\li{True} otherwise.\nSimilarly, lists and strings are \\li{False} when they are empty and \\li{True} otherwise.\nSo when \\li{a} is a number, instead of\n\\begin{lstlisting}\n>>> if a != 0:\n\\end{lstlisting}\nuse\n\\begin{lstlisting}\n>>> if a:\n\\end{lstlisting}\n\nLastly, it is more efficient to iterate through lists by iterating over the elements instead of iterating over the indices.\n\\begin{lstlisting}\n# Bad\nfor i in xrange(len(my_list)):\n    print my_list[i],\n\n# Good\nfor x in my_list:\n    print x,\n\\end{lstlisting}\n\nHowever, there are situations where you will need to know the indices of the elements over which you are iterating. In these situations, use \\li{enumerate}.\n\n\\begin{problem}\nUsing \\li{\\%prun}, find out which portions of the code below require the most runtime. Then, rewrite the function using some of the optimization techniques we have discussed thus far.\n\\begin{lstlisting}\ndef foo(n):\n    my_list = []\n    for i in range(n):\n        num = np.random.randint(-9,9)\n        my_list.append(num)\n    evens = 0\n    for j in range(n):\n        if j%2 == 0:\n            evens += my_list[j]\n    return my_list, evens\n\\end{lstlisting}\n\nHint: If you are unsure where to begin optimizing, walk through the code line by line to determine what the code is accomplishing. Then, write your own function to perform the same task in a more efficient way using the optimization techniques we have discuessed.\n\\end{problem}\n\n\\subsection*{Compiling Using Numba}\nThough it is much easier to write simple, readable code in Python, it is also much slower than compiled languages such as C. Compiled languages, in general, are much faster.\nNumba is a tool that you can use to optimize your code. Numba uses \\emph{just-in-time} (JIT) compilation.\n\nThis means that the code is compiled right before it is executed. We will discuss this process a bit later in this section.\nThe API for using Numba is incredibly simple. All one has to do is import Numba and add the \\li{@jit} function decorator to your function. The following code would be a Numba equivalent to Problem \\ref{prob:add}.\n\\begin{lstlisting}\nfrom numba import jit\n@jit\ndef numba_sum(A):\n    total = 0\n    for x in A:\n        total += x\n    return total\n\\end{lstlisting}\n\nThough this code looks very simple, a lot is going on behind the scenes. Without getting into too many details, one of the reasons compiled languages like C are so much faster than Python is because they have explicitly defined datatypes. The main strategy used by Numba is to speed up the Python code by assigning datatypes to all the variables. Rather than requiring us to define the datatypes explicitly as we would need to in any compiled language, Numba attempts to \\emph{infer} the correct datatypes based on the datatypes of the input.\n\nIn the code above, for example, say that our array \\li{A} was an array of integers. Though we have not explicitly defined a datatype for the variable \\li{total}, Numba will infer that the datatype for total should also be an integer.\n\nOnce all the datatypes have been inferred and assigned, the code is translated to machine code by the LLVM library. Numba will then cache this compiled version of our code. This means that we can bypass this whole inference and compilation process the next time we run our function.\n\n\\subsubsection*{More Control Within Numba}\nThough the inference engine within Numba does a good job, it's not always perfect. There are times that Numba is unable to infer all the datatypes correctly.\n\nIf you add the keyword argument, \\li{nopython=True} to the \\li{jit} decorator, an error will be raised if Numba was unable to convert everything to explicit datatypes.\n\nIf your function is running slower than you would expect, you can find out what is going on under the hood by calling the \\li{inspect_types()} method of the function. Using this, you can see if all the datatypes are being assigned as you would expect.\n\n\\begin{lstlisting}\n# Due to the length of the output, we will leave it out of the lab text.\n>>> numba_sum.inspect_types()\n\\end{lstlisting}\n\nIf you would like to have more control, you may specify datatypes explicity as demonstrated in the code below.\n\nIn this example, we will assume that the input will be doubles. Note that is necessary to import the desired datatype from the Numba module.\n\n\\begin{lstlisting}\nfrom numba import double\n# The values inside 'dict' will be specific to your function.\n@jit(nopython=True, locals=dict(A=double[:], total=double))\ndef numba_sum(A):\n    total = 0\n    for i in xrange(len(A)):\n        total += A[i]\n    return total\n\\end{lstlisting}\nNotice that the jit function decorator is the only thing that changed. Note also that this means that we will not be allowed to pass an array of integers to this function. If we had not specified datatypes, the inference engine would allow us to pass arrays of any numerical datatype. In the case that our function sees a datatype that it has not seen before, the inference and compilation process would have to be repeated. As before, the new version will also be cached.\n\n\\begin{problem}\n% TODO Change this problem to something more compelling.\nThe code below defines a Python function which takes a matrix to the $n$th power.\n\\begin{lstlisting}\ndef pymatpow(X, power):\n    \"\"\" Return X^{power}.\n\n    Inputs:\n        X (array) - A square 2-D NumPy array\n        power (int) - The power to which we are taking the matrix X.\n    Returns:\n        prod (array) - X^{power}\n    \"\"\"\n    prod = X.copy()\n    temparr = np.empty_like(X[0])\n    size = X.shape[0]\n    for n in xrange(1, power):\n        for i in xrange(size):\n            for j in xrange(size):\n                tot = 0.\n                for k in xrange(size):\n                    tot += prod[i,k] * X[k,j]\n                temparr[j] = tot\n            prod[i] = temparr\n    return prod\n\\end{lstlisting}\n\n\\begin{enumerate}\n\\item Create a function \\li{numba_matpow} that is the compiled version of \\li{pymatpow} using Numba.\n\\item Write a function \\li{numpy_matpow} that performs the same task as \\li{pymatpow} but uses \\li{np.dot()}. Compile this function using Numba.\n\\item Compare the speed of \\li{pymatpow},  \\li{numba_matpow} and the \\li{numpy_matpow} function. Remember to time \\li{numba_matpow} and \\li{numpy_matpow} on the second pass so the compilation process is not part of your timing. Perform your comparisons using your \\li{compare_timings} function.\n\\end{enumerate}\n\nNumPy takes products of matrices by calling BLAS and LAPACK, which are heavily optimized linear algebra libraries written in C, assembly, and Fortran.\n\\end{problem}\n\n\\begin{warn}\nNumPy's array methods are often faster than a Numba equivalent you could code yourself.\nIf you are unsure which method is fastest, time them.\n\\end{warn}\n\n\n\n\\subsection*{Use a More Efficient Algorithm}\n\nThe optimizations discussed thus far will speed up your code at most by a constant.\nThey will not change the complexity of your code.\nIn order to reduce the complexity (say from $O(n^2)$ to $O(n \\log(n))$), you typically need to change your algorithm.\nWe will address the benefits of using more efficient algorithms in Problem \\ref{prob:tridiag}.\n\nA good algorithm written with a slow language (like Python) is faster than a bad algorithm written in a fast language (like C).\nHence, focus on writing fast algorithms with good Python code, and only Numba when and where it is necessary. In other words, Numba will not always save you from a poor algorithm design.\n\n\n\\begin{comment}\n\\begin{problem}\nOptimize the following function using techniques described in this lab:\n\\begin{lstlisting}\n# TODO: COME UP WITH SOME ALGORITHM TO DO HERE!!\n\\end{lstlisting}\nIt should also include a list of changes, the reasoning behind the changes, and the effect of the changes on runtime. On the author's computer, computing the LU-decomposition on a 1000x1000 matrix took over 2 and a half minutes. The optimized version took a little over a second.\n\nHint: The best way to approach this problem is to analyze what each piece of code is actually doing. Then, determine if there is a more efficient way to accomplish the same task. Specifically, look for ways to use array operations instead of for loops, ways to replace blocks of code with built-in Python functions, and ways to avoid recomputing values.\n\\end{problem}\n\\end{comment}\n\nThe correct choice of algorithm is more important than a fast implementation.\nFor example, suppose you wish to solve the following tridiagonal system.\n\\[\\begin{bmatrix}\nb_1 & c_1 & 0 & 0 & \\cdots & \\cdots & 0 \\\\\na_2 & b_2 & c_2 & 0 & \\cdots & \\cdots & 0 \\\\\n0 & a_3 & b_3 & c_3 & \\cdots & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\ddots & \\vdots \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\ddots & c_{n-1} \\\\\n0 & 0 & 0 & 0 & \\cdots & a_n & b_n\n\\end{bmatrix}\n\\begin{bmatrix}\nx_1\\\\\nx_2\\\\\nx_3\\\\\n\\vdots\\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\n=\n\\begin{bmatrix}\nd_1\\\\\nd_2\\\\\nd_3\\\\\n\\vdots\\\\\n\\vdots\\\\\nd_n\n\\end{bmatrix}\\]\nOne way to do this is with the general \\li{solve} method in SciPy's \\li{linalg} module.\nAlternatively, you could use an algorithm optimized for tridiagonal matrices.\nThe code below implements one such algorithm in Python. This is called the Thomas algorithm.\n\n\\begin{lstlisting}\ndef pytridiag(a,b,c,d):\n    \"\"\"Solve the tridiagonal system Ax = d where A has diagonals a, b, and c.\n\n    Inputs:\n        a, b, c, d (array) - All 1-D NumPy arrays of equal length.\n    Returns:\n        x (array) - solution to the tridiagonal system.\n    \"\"\"\n    n = len(a)\n\n    # Make copies so the original arrays remain unchanged\n    aa = np.copy(a)\n    bb = np.copy(b)\n    cc = np.copy(c)\n    dd = np.copy(d)\n\n    # Forward sweep\n    for i in xrange(1, n):\n        temp = aa[i]/bb[i-1]\n        bb[i] = bb[i] - temp*cc[i-1]\n        dd[i] = dd[i] - temp*dd[i-1]\n\n    # Back substitution\n    x = np.zeros_like(a)\n    x[-1] = dd[-1]/bb[-1]\n    for i in xrange(n-2, -1, -1):\n        x[i] = (dd[i]-cc[i]*x[i+1])/bb[i]\n\n    return x\n\\end{lstlisting}\n\n\\begin{problem} \\label{prob:tridiag}\n\\leavevmode\n\\begin{enumerate}\n\\item Write a function \\li{numba_tridiag} that is a compiled version of \\li{pytridiag}.\n\\item Compare the speed of your new function with \\li{pytridiag} and \\li{scipy.linalg.solve}.\nWhen comparing \\li{numba_tridiag} and \\li{pytridiag}, use a $1000000 \\times 1000000$ sized systems.\nWhen comparing \\li{numba_tridiag} and the SciPy algorithm, use a $1000 \\times 1000$ systems. You may use the code below to generate the arrays, \\li{a}, \\li{b}, and \\li{c}, along with the corresponding tridiagonal matrix \\li{A}.\n\\end{enumerate}\n\\begin{lstlisting}\ndef init_tridiag(n):\n    \"\"\"Initializes a random nxn tridiagonal matrix A.\n\n    Inputs:\n        n (int) : size of array\n\n    Returns:\n        a (1-D array) : (-1)-th diagonal of A\n        b (1-D array) : main diagonal of A\n        c (1-D array) : (1)-th diagonal of A\n        A (2-D array) : nxn tridiagonal matrix defined by a,b,c.\n    \"\"\"\n    a = np.random.random_integers(-9,9,n).astype(\"float\")\n    b = np.random.random_integers(-9,9,n).astype(\"float\")\n    c = np.random.random_integers(-9,9,n).astype(\"float\")\n\n    # Check for and change 0 values in arrays\n    a[a==0] = 1\n    b[b==0] = 1\n    c[c==0] = 1\n\n    # Create tridiagonal matrix A from a,b,c\n    A = np.zeros((b.size,b.size))\n    np.fill_diagonal(A,b)\n    np.fill_diagonal(A[1:,:-1],a[1:])\n    np.fill_diagonal(A[:-1,1:],c)\n    return a,b,c,A\n\\end{lstlisting}\nNote that an efficient tridiagonal matrix solver is implemented by \\li{scipy.sparse.linalg.spsolve()}.\n\\end{problem}\n\n\\section*{When to Stop Optimizing}\nYou don't need to apply every possible optimization to your code.\nWhen your code runs acceptably fast, stop optimizing. There is no need spending valuable time making optimizations once the speed is sufficient.\n\nMoreover, remember not to prematurely optimize your functions. Make sure the function does exactly what you want it to before worrying about any kind of optimization.\n\n% TODO: get these lab references correct and replace.\n\\begin{problem}\nOptimize a function you wrote in a previous lab using the techniques discussed in this lab. Consider optimizing one of the following:\n\\begin{enumerate}\n\\item Householder triangularization or Hessenburg decomposition % (Lab \\ref{lab:QRdecomp}).\n\\item Givens triangularization % (Lab \\ref{lab:qr-applications})\n\\item Image Segmentation % (Lab \\ref{lab:ImgSeg_eigenvalues})\n\\item Eigenvalue Solvers % (Lab \\ref{lab:EigSolve})\n\\end{enumerate}\n Compare the timings of the function before and after optimization using your \\li{compare_timings} function. Write a short paragraph describing what you did to optimize your function.\n\\end{problem}\n", "meta": {"hexsha": "eef596da58ad54df01370baac8bb577ea38bd4a3", "size": 27751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Profiling/Profiling.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/Profiling/Profiling.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/Profiling/Profiling.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": 43.4968652038, "max_line_length": 542, "alphanum_fraction": 0.7039025621, "num_tokens": 7635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.8991213806488609, "lm_q1q2_score": 0.6316597951525006}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{The Markov and Chebyshev inequalities}\\label{sec:conc}\n\n%-----------------------------\n\\subsection{Markov's inequality}\n\nIf the distribution of a random variable is not known, probabilities can be estimated using the moments of the distribution. A simple upper bound on the tail probabilities of non-negative random variables is provided by \\emph{Markov's inequality}.\n\n% theorem: markov inequality\n\\begin{theorem}[Markov's inequality]\nLet $X$ be a non-negative random variable. Then for every $a>0$,\n\\[\n\\prob(X\\geq a) \\leq \\frac{\\expe(X)}{a}.\n\\]\n\\end{theorem}\n\n% proof\n\\begin{proof}\nLet $I_A$ be the indicator function of event $A = \\{\\omega: X(\\omega)\\geq a\\}$. \n\\[\nI_A(\\omega) = \\left\\{\\begin{array}{ll} 0 & \\text{if}\\ X(\\omega) < a, \\\\ 1 & \\text{if}\\ X(\\omega)\\geq a. \\end{array}\\right.\n\\]\n\\bit\n\\it If $\\omega\\in A$ then $X(\\omega)   \\geq a = a I_A(\\omega)$.\n\\it If $\\omega\\notin A$ then $X(\\omega)\\geq 0 = a I_A(\\omega)$.\n\\eit\nIn either case we have $X(\\omega)\\geq a I_A(\\omega)$ so by the monotonicity of expectation,\n\\[\n\\expe(X) \\geq a\\expe(I_A) = a\\prob(A) \\equiv a\\prob(X\\geq a).\n\\]\nHence $\\prob(X\\geq a) \\leq \\expe(X)/a$ as required.\n\\end{proof}\n\n% example\n\\begin{example}\nA fair die is rolled once. Use Markov's inequality to find an upper bound on the probability that we observe a score of at least $5$.\n\\end{example}\n\n\\begin{solution}\nLet $X$ be the number shown on the die. Then $X$ is a non-negative random variable with expectation $\\expe(X) = 7/2$.\nMarkov's inequality yields the upper bound \n\\[\n\\prob(X\\geq 5) \\leq \\frac{\\expe(X)}{5} = \\frac{7}{10}.\n\\]\nIn this example we know that $\\prob(X\\geq 5)=1/3$, which illustrates that Markov's inequality provides only crude bounds on tail probabilites. Indeed, for the probability $\\prob(X\\geq 3)$ Markov's inequality yields\n\\[\n\\prob(X\\geq 3) \\leq \\frac{\\expe(X)}{3} = \\frac{7}{6}.\n\\]\nThis tells us nothing useful, because we know that $\\prob(X\\geq 3)\\leq 1$. \n\\end{solution}\n%-----------------------------\n\\subsection{Chebyshev's inequality}\n\nAn upper bound on the absolute deviation of a random variable from its mean is provided by \\emph{Chebyshev's inequality}.\n\n\\begin{corollary}[Chebyshev's inequality]\nLet $X$ be any random varible with finite expectation. Then for all $\\epsilon>0$,\n\\[\n\\prob(|X-\\expe(X)|\\geq \\epsilon) \\leq \\frac{\\var(X)}{\\epsilon^2}.\n\\]\n\\end{corollary}\n\\begin{proof}\nTake the non-negative random variable $\\big[X-\\expe(X)\\big]^2$ in Markov's inequality with $a=\\epsilon^2$:\n\\begin{align*}\n\\prob(|X-\\expe(X)|\\geq \\epsilon) \n\t& = \\prob\\big[\\big(X-\\expe(X)\\big)^2\\geq \\epsilon^2\\big] \n\t\\leq\t\\frac{\\expe\\big[\\big(X-\\expe(X)\\big)^2\\big]}{\\epsilon^2} \n\t= \\frac{\\var(X)}{\\epsilon^2},\n\\end{align*}\t\nas required.\n\\end{proof}\n\n\\begin{example}\nSuppose that $\\expe(X) = 0$ and $\\var(X) = 1$. Find an integer value $k$ such that $\\prob(|X|\\geq k) \\leq 0.01$.\n\\begin{solution}\n$X$ is not non-negative, so we can not use Markov's inequality here. By Chebyshev's inequality,\n\\[\n\\prob(|X|\\geq k) = \\prob(|X-\\expe X|\\geq k) \\leq \\frac{\\var(X)}{k^2} = \\frac{1}{k^2} %\\leq \\frac{1}{100}\n\\]\nso can take any $k\\geq 10$.\n\\end{solution}\n\\end{example}\n\n% example\n\\begin{example}\nLet $X$ be a continuous random variable with expected value $3.6$ and standard deviation $1.2$. \n\\par Show that $\\prob(1.2\\leq X\\leq 6.0) \\geq 0.75$.\n\\begin{solution} % <<<\n\\par\nThe event $\\{1.2 \\leq X \\leq 6.0\\}$ can be written as $\\{|X-3.6| \\leq 2.4\\}$, and by Chebyshev's inequality,\n\\[\n\\prob(|X-3.6|> 2.4) \\leq \\frac{\\var(X)}{2.4^2} = \\frac{1.2^2}{2.4^2} = \\frac{1}{4},\n\\]\nso $\\prob(1.2 \\leq X \\leq 6.0) \\geq 0.75$, as required.\n\\end{solution}\n\\end{example}\n\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nWhat does Chebyshev's inequality tell us about the probability that the value taken by a random variable deviates from its expectation by five or more standard deviations?\n\\begin{answer}\nFor any random variable $X$ with finite variance $\\sigma^2$,\n\\[\n\\prob(|X-\\mu|\\geq 5\\sigma) \\leq \\frac{\\sigma^2}{(5\\sigma)^2} = \\frac{1}{25} = 0.04.\n\\]\nThus for any distribution, we are very unlikely to observe values that are more than 5 standard deviations away from the mean.\n\\end{answer}\n\n\\question\nA fair coin is tossed $n$ times. Does Chebyshev's inequality ensure that the observed number of heads will not deviate from $n/2$ by more than $100$ with a probability of at least $0.99$, provided that $n$ is sufficiently large?\n\\begin{answer}\nNo. Let $X_i=1$ if a head occurs on the $i$th toss and $X_i=0$ otherwise, and let $S_n = \\sum_{i=1}^n X_i$ be the total number of heads after $n$ tosses. Because the coin is fair, $\\expe(S_n)=n/2$ and $\\var(S_n)=n/4$. Applying Chebyshev's inequality to $S_n$ with $\\epsilon=100$:\n\\[\n\\prob(|S_n - n/2| > 100) \\leq \\var(S_n)/100^2\n\\]\nBut $\\var(S_n)\\to\\infty$ as $n\\to\\infty$, so the probability that $S_n$ deviates from $n/2$ by a fixed amount cannot be bounded using Chebyshev's inequality.\n\\end{answer}\n\n\n\\question\nLet $X$ be a random variable with mean $\\mu\\neq 0$ and variance $\\sigma^2$. The \\emph{relative deviation} of $X$ from its mean is defined by $\\displaystyle D  = \\left|\\frac{X-\\mu}{\\mu}\\right|$. Use Chebyshev's inequality to show that \n$\n\\displaystyle \\prob(D \\geq \\epsilon) \\leq \\left(\\frac{\\sigma}{\\mu\\epsilon}\\right)^2.\n$\n\\begin{answer} \nBy Chebyshev's inequality,\n\\[\n\\prob(D\\geq \\epsilon) \n\t= \\prob\\left(\\left|\\frac{X-\\mu}{\\mu}\\right|\\geq \\epsilon\\right)\n\t= \\prob\\big(|X-\\mu|\\geq |\\mu|\\epsilon)\n\t\\leq \\frac{\\sigma^2}{\\mu^2 \\epsilon^2}\n\\]\n\\end{answer}\n\n\\question\n\\begin{parts}\n\\part\\label{qu:pt:cheb_bern}\nLet $X_1,X_2,\\ldots,X_n$ be independent with each $X_i\\sim\\text{Bernoulli}(p)$. Using the fact that $p(1-p)\\leq 1/4$ for all $0<p<1$, show that for any $\\epsilon > 0$, \n\\[\n\\prob\\left(\\left|\\frac{1}{n}\\sum_{i=1}^n X_i - p\\right|\\geq\\epsilon\\right) \\leq \\frac{1}{4n\\epsilon^2}.\n\\]\n\\begin{answer} % <<<\nFor the $\\text{Binomial}(n,p)$ distribution, Chebyshev's inequality yields\n\\[\n\\prob\\left(\\left|\\frac{S_n}{n}-p\\right|\\geq\\epsilon\\right) \\leq \\frac{p(1-p)}{n\\epsilon^2}\n\\]\nand the result follows because $p(1-p)\\leq 1/4$.\n\\end{answer}\n\\part\nLet $A$ be an event associated with a random experiment. Suppose that the experiment is repeated $n$ times. Let $X_i$ be the indicator variable of the event that $A$ occurs during the $i$th trial. Then $X_i\\sim\\text{Bernoulli}(p)$ where $p=\\prob(A)$, and the sample mean $\\frac{1}{n}\\sum_{i=1}^n X_i$ is the \\emph{relative frequency} of $A$ over these $n$ trials. What does the upper bound derived in part \\ref{qu:pt:cheb_bern} say about the relative frequency of event $A$ as $n\\to\\infty$.\n\\begin{answer} % <<<\nThe probability that the relative frequency $\\displaystyle\\frac{1}{n}\\sum_{i=1}^n X_i$ of $A$ differs from its true probability $p=\\prob(A)$ by more than a fixed amount (however small), tends to zero as the number of trials increases to infinity.\n\\end{answer}\n\\end{parts}\n\n\n\\end{questions}\n\\end{exercise}\n", "meta": {"hexsha": "491e0aae007d5be35915455911e5da43efa20793", "size": 6949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/04E_inequalities.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/04E_inequalities.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/04E_inequalities.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": 42.3719512195, "max_line_length": 490, "alphanum_fraction": 0.6753489711, "num_tokens": 2423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.899121377945727, "lm_q1q2_score": 0.6316597932534677}}
{"text": "%\t\\includegraphics[scale=0.95]{competences}\n\t\n\t\\section{Calculer}\n\t\n\tCalculer astucieusement en détaillant les calculs\n\t\\begin{questions}\n\t\t\n\t\n%\t\t\\question[2]  $\\num{5.5} + 4 + \\num{2.5} + 8$\n%\t\t\\fillwithdottedlines{2cm}\n%\t\t%\n%\t\t\\begin{solution}\n%\t\t\t\n%\t\t\\end{solution}\n\t\t\t\n\t\t\n\t\t\\question[2]  $\\num{3.3} + \\num{7.4} + \\num{2.7} + \\num{2.6} + 8 $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\n\t\t\\end{solution}\n\t\t\n\t\t\\question[2]  $\\num{3.2} + \\num{7.5} + \\num{2.8} + \\num{5.5} + 15 $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\n\t\t\\question[2]  $\\num{5} \\times 25 \\times 11 \\times \\num{4} \\times 2$\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\t\\question[2]  $\\num{2.5} \\times 4 \\times 3 \\times 7$\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\n\t\t\n\t\n\t\t\\question[2]  $\\num{12.5} \\times 25 \\times \\num{8} \\times 4$\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\\newpage\n\t\n\t\n\t\t\\question[2]  $\\num{5} \\times 50  \\times \\num{4} \\times 2$\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\t\n\t\n\t\n\t\t\\question[2]  $\\num{3} \\times 45 \\times 20 \\times \\num{5} $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\n\t\t\\question[2]  $(2 + 5) \\times (7 + 2) $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\n\t\t\\end{solution}\n\t\n\t\t\\question[2]  $2 + 8 \\times 7 + 2 $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\t\n\t\t\\end{solution}\n\t\n\t\t\\question[2]  $(2 + 8 \\times 7) \\times 2 $\n\t\t\\fillwithdottedlines{2cm}\n\t\t\\begin{solution}\n\t\t\n\t\t\\end{solution}\n\t\t\n\t\\end{questions}\n\t\n\t\n", "meta": {"hexsha": "b90d1562b713beba04f0b6a285e28d78fcde206c", "size": 1601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "college/6e/3_addition/interros/interro3/v1.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/6e/3_addition/interros/interro3/v1.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/6e/3_addition/interros/interro3/v1.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": 17.5934065934, "max_line_length": 69, "alphanum_fraction": 0.5965021861, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.7520125737597971, "lm_q1q2_score": 0.6314905113512909}}
{"text": "\\section{Other attacks}\nAttacks against discrete logarithm involve finding the integer $x$ for a given $\\alpha$ and $\\beta$ in $G$ such that:\n$$\\beta = \\alpha \\circ \\alpha \\circ \\dots \\circ \\ alpha = \\alpha^x$$\n\nIn 1997, a lower bound for discrete logarithms was given: any generic algorithm that solves with high probability the problem must perform at least $\\Omega(p^{1/2})$ group operations, where $p$ is the largest prime dividing the cardinality of the group. The same result holds for non cyclic groups and Diffie-Hellman protocol.\n\nThe exact difficulty of computing this is still unknown: despite the existence of algorithms, there could be better or more powerful ones which still are undiscovered (similarly to integer factorization). \n\nGeneric algorithms are methods which only rely on the group operation $\\circ$, without needing further algebraic structure. This property makes them applicable in any cyclic group.\n\n\\subsection{Brute force search}\nBrute-force is the most naive and costly generic algorithm to obtain the discrete logarithm $\\log_\\alpha\\beta$: all powers of the generator $\\alpha$ are computed \\textbf{successively}, until the result equals $\\beta$.\n\nFor a random logarithm $x$, on average the correct solution is expected to be found after checking \\textit{half of the possible values}. This gives a complexity of $O(|G|)$, linear in the cardinality of the group.\n\nTo avoid this kind of attack to be successful, therefore, the cardinality of groups must be sufficiently large, without any other particular measure. \n\nIn the case of $\\mathbb{Z}^*_p$ with $p$ prime, approximately $\\frac{p-1}{2}$ tests are required to compute the discrete logarithm, meaning that $|G| = p - 1$ should be in the order of at least $2^{80}$ to make a brute force infeasible using the modern hardware.\n\n\\subsection{Shank's method}\nShank's method is another generic algorithm which allows to reduce the time of a brute force search, at the trade off of occupying more storage. It is a meet-in-the-middle attack, storing intermediate values by trying to successively crack the multiple steps of discrete logarithm encryption.\n\nThe procedure is based on rewriting the discrete logarithm in a two-digit representation:\n$$x = x_gm = x_b \\qquad 0 \\leq x_g, x_b < m$$\nThe value $m$ is chosen to be approximately the square root of the cardinality of the set, i.e.\\ $m = \\lceil{\\sqrt{|G|}}\\rceil$. Discrete logarithm can then be stated as $\\beta = \\alpha^x = \\alpha^{x_gm + x_b}$ which leads to:\n$$\\beta \\cdot (\\alpha^{-m})^{x_g} = \\alpha^{x_b}$$ \nThe core idea of the algorithm is using a divide-and-conquer approach to find $x_a$ and $x_b$ separately, in two phases:\n\\begin{enumerate}\n\t\\item Baby-step, where all the values $\\alpha^{x_b}$ with $0 \\leq x_b < m$ are computed and stored with approximately $m \\approx \\sqrt{|G|}$ operations;\n\t\\item Giant-step, in which the program checks for all $x_g$ in $0 \\leq x_g < m$ whether this condition is fulfilled: \n\t$\\beta \\cdot (\\alpha^{-m})^g \\stackrel{?}{=} \\alpha^{x_b}$ for some stored entry $\\alpha^{x_b}$ that was computed during the previous step.\n\\end{enumerate}\nIn case of a match, i.e.\\ $\\beta \\cdot (\\alpha^{-m})^{x_g, 0} = \\alpha^{x_b, 0}$ for some pair $(x_{g, 0}, x_{b, 0})$ the discrete logarithm is:\n$$x = x_{g, 0}m + x_{b, 0}$$\nFurther speed up the method can be obtained using efficient lookup schemes, such as \\textbf{hash tables} which allow constant time search.\n\nThis algorithm has a total computational time and space of $O(\\sqrt{|G|})$, which means that in a group of order $2^{80}$ an attacker would approximately need $2^{40}$ operations, easily obtainable with modern hardware.\n\nDirect consequence of this is that groups need to have a cardinality of at least $|G| \\geq 2^{160}$, to make Shank's method have a complexity of $2^{80}$ and therefore be infeasible. In case of prime groups $G = \\mathbb{Z}^*_p$, $p$ must have a length of at least 160 bit; using prime groups is advised since otherwise Shank's method would have an even smaller complexity. \n\n\\subsection{Pollard's Rho method}\nPollard's Rho method has the same computational time as Shank's algorithm, yet constant space requirements. It is based on the \\textbf{birthday paradox}, concept related to the higher likelihood of collisions found between random attack attempts and a fixed degree of permutations.\n\nThe basic idea consists in pseudo-randomly generate ($\\rho$ represents randomness) group elements of the form $\\alpha^i \\cdot \\beta^j$, keeping track of values $i$ and $j$, to then continue until obtaining a collision:\n$$\\alpha^{i_1} \\cdot \\beta^{j_1} = \\alpha^{i_2} \\cdot \\beta^{j_2}$$\nSubstituting $\\beta = \\alpha^x$ and comparing the exponents on both sides of the equation, the collision leads to the following formula:\n$$i_1 + xj_1 \\equiv i_2 + jx_2 \\mod |G| \\qquad \\rightarrow \\qquad x \\equiv \\frac{i_2 - i_1}{j_1 - j_2} \\mod |G|$$ \nThe second part allows to find the discrete logarithm. Furthermore, additional methods to speed up computations such as the Extended Euclidean Algorithm and Floyd's cycle-finding algorithm.\n\nIts computational time is approximately $O(\\sqrt{n})$, while used together with Silver-Pohlig-Hellman it can achieve $O(\\sqrt{p})$ where $p$ is the largest prime factor of $n$.\n\nThe practical importance of Rho's method is it being the best-known algorithm in \\textit{elliptic curve group}s, making 160 bit operands very popular within this cryptography; however, it is not the most powerful attack for discrete logarithm and it does not work well in a distributed environment.\n\n\n", "meta": {"hexsha": "9b3b12fba9098ba66441527a0e20a11ebc4b6b53", "size": 5553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/attacks.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/attacks.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/attacks.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": 100.9636363636, "max_line_length": 373, "alphanum_fraction": 0.7518458491, "num_tokens": 1427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.6314904974928198}}
{"text": "\\subsection{A neural algorithm of artistic style}\n\\label{sec:gatys}\n\\textit{A neural algorithm of artistic style} is a paper written by Gatys et al. \\cite{Gatys:1}. This paper goes in depth about how to use a feature space from a convolutional neural network to generate images with a given style. To generate an image with a given style can be framed as an optimization problem, where we want to make the generated image look like the content image, but with the style of the style image. This optimization is done by using the gradient descent algorithm.\n\\subsubsection{The VGG-network}\n\\label{sec:vgg}\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.20]{report/Background/images/vgg19.png}\n\\caption{The VGG-19 network}\n\\label{fig:rotasjon}\n\\end{center}\n\\end{figure}\nThe VGG-network is responsible for producing the feature space that gives filter responses for the content image and the style image. The filters get more complex with the position of the layer in the network, thus generating a more higher-dimensional representation of the image. Gatys et. al used 16 convolutional and 5 pooling layers of the 19 layer VGG-network. They replaced the max-pooling layers in the network with average-pooling layers since they gave more appealing results. \\newline\\newline\nLet $\\vec{p}$ be the content image (the image we want to style), and the $\\vec{x}$ be the generated image. Then their feature representations in a layer $l$ can be described by the matrices $P^l$ and $F^l$, where $P^l, F^l\\in\\mathbb{R}^{N_l\\times M_l}$. Here, $N_l$ are the distinct filters in layer $l$, each with feature maps of size $M_l$. \n\\subsubsection{Loss functions}\nSince one of the goals of the optimization is to make $P^l$ similar to $F^l$, i.e. making the generated image like the original content image, Gatys et. al defined the following loss function, the content loss, between the two feature representations described above:\n\\begin{equation}\n\\label{eq:content_loss}\n    \\mathcal{L}_\\text{content}(\\vec{p},\\vec{x},l)=\\frac{1}{2}\\sum_{i,j}{(F_{ij}^l-P_{ij}^l)^2},\n\\end{equation}\nwhere $F_{i,j}$ and $P_{i,j}$ are the activations of the $i$th filter at position $j$ in layer $l$. This loss function is the squared-error loss function. Similarly, they defined the style loss as follows:\n\\begin{equation}\n\\label{eq:style_loss}\n    \\mathcal{L}_\\text{style}(\\vec{a},\\vec{x})=\\sum_{l=0}^L{w_lE_l},\n\\end{equation}\nwhere\n\\begin{equation}\n    E_l=\\frac{1}{4N_l^2M_l^2}\\sum_{i,j}{(G_{ij}^l-A_{ij}^l)^2}.\n\\end{equation}\nHere $A^l$ is the is the style representation of the style image in layer $l$, and $G^l$ is the style representation of the the generated image. $\\vec{a}$ is the style image, and $w_l$ are the weighting factors for how much each layer should contribute to the total loss. $G^l$ is also known as the Gram matrix. This matrix will be discussed in Section \\ref{section:gram}. Now, the total loss can be written as:\n\\begin{equation}\n\\label{eq:total_loss}\n    \\mathcal{L}_\\text{total}(\\vec{p}, \\vec{a}, \\vec{x})=\\alpha\\mathcal{L}_\\text{content}(\\vec{p},\\vec{x})+\\beta\\mathcal{L}_\\text{style}(\\vec{a},\\vec{x})\n\\end{equation}\nHere, $\\alpha$ and $\\beta$ are weights for the content image and the style image. The higher the weight, the more that loss is minimized, resulting in the stylized image to either be more equal to the content image, or the style image.\n\\subsubsection{Gram Matrix}\n\\label{section:gram}\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.30]{report/Background/images/featuremap.png}\n\\caption{Feature map with three channels}\n\\label{fig:featuremap}\n\\end{center}\n\\end{figure}\nThe Gram matrix is a style representation built on top of the CNN. This matrix gives the feature correlations between the vectorised features maps $i$ and $j$ in layer $l$. This correlation is calculated by taking the inner product between the feature maps. Gatys et al. give the following formula for the Gram matrix:\n\\begin{equation}\n    G_{ij}^l=\\sum_k{F_{ik}^lF_{jk}^l}\n\\end{equation}\nTo understand the Gram matrix, we can reduce the feature maps to 2D vectors. If we have two vectors, say $\\vec{a}$ and $\\vec{b}$, the closer they are to each other, the more correlated they are. Then the angle between these two vectors will be small, resulting in a large cosine value, giving a large dot product. So the larger the dot product is, the more correlated $\\vec{a}$ and $\\vec{b}$ are. \nThis idea is similar for feature maps. Consider a feature map consisting of three channels, like the one in Figure \\ref{fig:featuremap}. The red channel represents the feature of horizontal lines, the yellow represents the feature of vertical lines, and the green represents the features of the color green. If the red channel and the yellow channel have high activation values, then we can say that we have an image of for example a chess board. These two channels will have a higher correlation than that between the yellow channel and the green channel. In a sense, this correlation describes the style of the generated image.\n\\subsubsection{Gradient descent}\nThe derivative of the content loss is given by\n\\begin{equation}\n    \\frac{\\partial\\mathcal{L}_\\text{content}}{\\partial F_{ij}^l}=\\begin{cases}\n    (F^l-P^l)_{ij}\\,&\\text{ if }\\,F_{ij}^l>0\\\\\n    0\\,&\\text{ if }\\,F_{ij}^l<0.\n    \\end{cases}\n\\end{equation}\nThe derivative of $E_l$ is given by\n\\begin{equation}\n    \\frac{\\partial E_l}{\\partial F_{ij}^l}=\\begin{cases}\n    \\frac{1}{N_l^2M_l^2}\\left((F^l)^T(G^l-A^l)\\right)_{ji}\\,&\\text{ if }\\,F_{ij}^l>0\\\\\n    0\\,&\\text{ if }\\,F_{ij}^l<0.\n    \\end{cases}\n\\end{equation}\nThe gradients can be calculated by using standard-error back-propagation, as described by Gatys et al.", "meta": {"hexsha": "60ff1d27959b40e24402627304384b0aa4876079", "size": 5676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Background/gatys.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/gatys.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/gatys.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": 86.0, "max_line_length": 629, "alphanum_fraction": 0.746124031, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6314887094359166}}
{"text": "\\chapter{The \\texorpdfstring{\\Coq}{Coq} Proof Assistant}\\label{chap:coq}\n\n\\Coq \\citep{coq-refman-09} is based on the formal\nlanguage \\emph{Calculus of Inductive Constructions}\n\\citep{coquand-huet-88,mohring-93}, which is essentially a typed\n$\\lambda$-calculus with inductive types. In this language, logical\npropositions are represented as types and proofs of such propositions\nare $\\lambda$-terms, motivated by the Curry--Howard--de Bruijn\ncorrespondence \\citep{girard-89}. The core of the \\Coq system is its type\nchecking algorithm.\n\nWe present a very short introduction to \\Coq and refer to\n\\citet{bertot-casteran-04} and \\citet{chlipala-09} for further\nreading. Sections~\\ref{sec:guardedness} and \\ref{sec:positivity} discuss two\ntechnicallities related to the \\Coq development described in\nChapter~\\ref{chap:implementation}.\n%The seasoned \\Coq user can skip to Section~\\ref{sec:ordimp}.\n\n\n\\section{Types and Propositions}\n\nEvery term in \\Coq has a type and every type is also a\nterm. The type of a type is called a \\emph{sort} and the sorts\nin \\Coq are\n\\begin{compactitem}\n\\item \\coqdockw{Prop}, the sort of logical propositions,\n\\item \\coqdockw{Set}, the sort of program specifications and datatypes,\n\\item \\coqdockw{Type}$_0$, the sort of \\coqdockw{Prop} and\n  \\coqdockw{Set}, and\n\\item \\coqdockw{Type}$_{i+1}$, the sort of\n  \\coqdockw{Type}$_i$.\\footnote{The subscripts $i$ of the sorts\n    \\coqdockw{Type}$_i$ are invisible to the user and only used\n    internally.}\n\\end{compactitem}\nFor example,\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\nis the datatype of the natural numbers. It lives in \\coqdockw{Set} and\nis defined inductively.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n:\n\\coqdockw{Set} :=\\coqdoceol\n\\coqdocindent{1.0em}\n\\ensuremath{|} \\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{O}{\\coqdocconstructor{O}}\n:\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\\coqdoceol\n\\coqdocindent{1.0em}\n\\ensuremath{|} \\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n:\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}} $\\rightarrow$\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThe logical proposition that for every natural number $n$, there\nexists a natural number $m$ larger than $n$, can be stated as a term\nof sort \\coqdockw{Prop}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n(\\ensuremath{\\forall} \\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}},\n\\ensuremath{\\exists} \\coqdocvar{m} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}},\n\\coqdocvariable{n} < \\coqdocvariable{m}) : \\coqdockw{Prop}\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nUsing the vocabulary of types and terms, the universal quantifier\n$\\forall$ is called the \\emph{product type constructor}. A product\ntype \\begin{coqdoccode}$\\forall$ \\coqdocvar{x} : $T$,\n  $U$\\end{coqdoccode} is called \\emph{dependent} if \\coqdocvar{x} occurs free\nin $U$, otherwise it is written $T \\rightarrow U$. The type of the\nconstructor symbol \\coqdocconstructor{S} defined above, for example,\nis that of functions from\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\nto\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\nand is not dependent. The non-dependent function space notation $T \\rightarrow\nU$ is also used for logical implication, justified by the Curry--Howard--de\nBruijn correspondence.\n\n\n\\section{Terms and Proofs}\n\nProofs of logical propositions can be defined in two ways. First, we\ncan write a proof term directly. The only requirement is that this\nterm has as type the logical proposition that we want to\nprove (again, justified by the Curry--Howard--de Bruijn\ncorrespondence). Second, we can use \\emph{tactics} to construct a proof term\ninteractively, in a way mimicking natural deduction.\n\nAs an example of the use of tactics, we prove the proposition from the\nprevious section. This is done by stating the proposition, after which\nthe system enters a goal-directed proof mode. In this mode, we are\npresented with a goal, consisting of\n\\begin{inparaenum}[(i)]\n\\item a context of local variables that are available\n\\item a proposition denoting what remains to be proven.\n\\end{inparaenum}\nTactics can now be applied to progressively transform the goal into a\nsimpler goal. When the goal is simple enough to be solved directly by\napplying a tactic, we are done proving the proposition.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Lemma}\n\\coqdef{CoqIntro.ltserial}{lt\\_serial}{\\coqdoclemma{lt\\_serial}} :\n\\ensuremath{\\forall} \\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}},\n\\ensuremath{\\exists} \\coqdocvar{m} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}},\n\\coqdocvariable{n} < \\coqdocvariable{m}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Proof}.\\coqdoceol\n\\coqdocindent{1.0em}\n\\coqdoctac{intro} \\coqdocvar{n}. $\\,$\n\\coqdoctac{exists}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvar{n}). $\\,$\n\\coqdoctac{auto}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Qed}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nIn this example, we use the tactic \\coqdoctac{intro} to introduce the\nvariable \\coqdocvariable{n} to the context. With \\coqdoctac{exists},\nwe supply a witness for the existential quantification. At this point,\nthe goal is simple enough to be solved directly by the\n\\coqdoctac{auto} tactic.\n\nRecursive functions are defined using the \\coqdockw{Fixpoint}\nkeyword. The function must have an argument of an inductive type that is\nstructurally decreasing with each recursive call. Consider for example the\ndefinition of\nthe factorial function, which also shows how a case analysis on values\nof inductive types can be done with the \\coqdockw{match} keyword.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Fixpoint}\n\\coqdef{CoqIntro.factorial}{factorial}{\\coqdocdefinition{factorial}}\n(\\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}})\n:\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n:=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{n} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{O}{\\coqdocconstructor{O}}\n\\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{O}{\\coqdocconstructor{O}}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvar{n} \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvariable{n} \\ensuremath{\\times}\n(\\coqref{CoqIntro.factorial}{\\coqdocdefinition{factorial}}\n\\coqdocvariable{n})\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\n\n%\\chapter{Two Syntactical Criteria in \\texorpdfstring{\\Coq}{Coq}}\\label{chap:appendix}\n%\n%We include a short discussion of two \\Coq technicalities.\n\n\n\\section{The Positivity Condition}\\label{sec:positivity}\n\n\\Coq restricts inductive definitions to those that satisfy the\n\\emph{positivity condition}. The reason for this is that definitions\nthat fail this (syntactic) criterion may lead to an inconsistent\n  system. For a precise definition of positivity, consult\n  \\citetalias[Section 4.5.3]{coq-refman-09}.\n\nConsider again the definition of rewrite sequences from\nSection~\\ref{sec:seq}. A more natural way to define the type of the\n\\coqref{Rewriting.Lim}{\\coqdocconstructor{Lim}} constructor might be\nby using a $\\Sigma$-type instead of a separate function for the target\nterms of the branches.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdocconstructor{Lim} :\n\\ensuremath{\\forall} \\coqdocvar{s} \\coqdocvar{t}\n(\\coqdocvar{f} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\{ \\coqdocvar{t'} : \\coqref{Term.term}{\\coqdocinductive{term}}\n\\& \\coqdocvar{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t'} \\}),\\coqdoceol\n\\coqdocindent{5.00em}\n\\coqref{Rewriting.converges}{\\coqdocdefinition{converges}}\n(\\coqdockw{fun} \\coqdocvar{n} \\ensuremath{\\Rightarrow}\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Specif}{projT1}{\\coqdocdefinition{projT1}}\n(\\coqdocvariable{f} \\coqdocvariable{n})) \\coqdocvariable{t}\n$\\rightarrow$ (\\coqdocvariable{s}\n\\coqref{Rewriting.sequence}{$\\rewrites_\\mathcal{R}$}\n\\coqdocvariable{t})\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nHowever, this type definition does not satisfy the positivity\ncondition and therefore we cannot use it. We feel that the definition\nfrom Section~\\ref{sec:seq}, which does satisfy the condition, models\nour intentions adequately.\n\n\n\\section{Guardedness in Corecursive Definitions}\\label{sec:guardedness}\n\nIn \\Coq, coinductive types can be defined using the\n\\coqdockw{CoInductive} keyword \\citep{gimenez-casteran-07}. No\ninduction principles are defined for these types, because they are not\nnecessarily well-founded.\\footnote{\\Coq automatically derives induction\n  principles for inductive definitions.}\nObjects in a coinductive type may be infinite (i.e.\\ contain an infinite\namount of constructors). However, in order to guarantee productivity,\ndefinitions of such objects are required by \\Coq to be in \\emph{guarded}\nform \\citep{gimenez-94}. A corecursive definition in guarded form\nsatisfies two (syntactical) conditions. First, every corecursive call\nmust occur inside at least one constructor (of the same coinductive\ntype). Second, every corecursive call may only occur inside\nabstractions or constructors (of the same coinductive\ntype).\\footnote{To be more precise, the corecursive call is also\n  allowed to occur inside \\coqdockw{match} constructs and other\n  corecursive definitions.}\n\nIn the \\coqref{Term.term}{\\coqdocinductive{term}} definition, we use a vector\ntype, parameterised by the type of its element and its size. Naturally, one\nwould implement a vector type in \\Coq inductively, as for example has been\ndone in the standard library.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqdef{Bvector.vector}{vector}{\\coqdocinductive{vector}}\n(\\coqdocvar{A} : \\coqdockw{Type}) :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Bvector.Vnil}{Vnil}{\\coqdocconstructor{Vnil}}  :\n\\coqref{Bvector.vector}{\\coqdocinductive{vector}} \\coqdocvariable{A} 0\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Bvector.Vcons}{Vcons}{\\coqdocconstructor{Vcons}} :\n\\coqdocvariable{A} \\ensuremath{\\rightarrow} \\ensuremath{\\forall} \\coqdocvar{n},\n\\coqref{Bvector.vector}{\\coqdocinductive{vector}} \\coqdocvariable{A}\n\\coqdocvariable{n} \\ensuremath{\\rightarrow}\n\\coqref{Bvector.vector}{\\coqdocinductive{vector}} \\coqdocvariable{A}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvariable{n}).\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n\nNow consider the following trivial example of a basic operation on terms by\ncorecursive traversal.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{CoFixpoint} \\coqdef{Term.id}{id}{\\coqdocdefinition{id}}\n(\\coqdocvar{t} : \\coqref{Term.term}{\\coqdocinductive{term}}) :\n\\coqref{Term.term}{\\coqdocinductive{term}} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{match} \\coqdocvariable{t} \\coqdockw{with}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Term.Var}{\\coqdocconstructor{Var}} \\coqdocvar{x}\n\\ensuremath{\\Rightarrow} \\coqref{Term.Var}{\\coqdocconstructor{Var}}\n\\coqdocvariable{x}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvar{f}\n\\coqdocvar{args} \\ensuremath{\\Rightarrow}\n\\coqref{Term.Fun}{\\coqdocconstructor{Fun}} \\coqdocvariable{f}\n(\\coqdocdefinition{vmap} \\coqref{Term.id}{\\coqdocdefinition{id}}\n\\coqdocvariable{args})\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{end}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\nThis definition is ill-formed, since the corecursive call to\n\\coqref{Term.id}{\\coqdocdefinition{id}} is not guarded.\\footnote{The call to\n  \\coqref{Term.id}{\\coqdocdefinition{id}} is hidden inside\n  \\coqdocdefinition{vmap}, which is defined by recursion on the vector\n  \\coqdocvariable{args}.}\nWe define a recursive type of vectors as an alternative to the\ninductive type.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqdef{Vector.Fin}{Fin}{\\coqdocinductive{Fin}} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}}\n\\ensuremath{\\rightarrow} \\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Vector.First}{First}{\\coqdocconstructor{First}} :\n\\ensuremath{\\forall} \\coqdocvar{n}, \\coqref{Vector.Fin}{\\coqdocinductive{Fin}}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvariable{n})\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqdef{Vector.Next}{Next}{\\coqdocconstructor{Next}}  :\n\\ensuremath{\\forall} \\coqdocvar{n}, \\coqref{Vector.Fin}{\\coqdocinductive{Fin}}\n\\coqdocvariable{n} \\ensuremath{\\rightarrow}\n\\coqref{Vector.Fin}{\\coqdocinductive{Fin}}\n(\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{S}{\\coqdocconstructor{S}}\n\\coqdocvariable{n}).\\coqdoceol\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition}\n\\coqdef{Vector.vector}{vector}{\\coqdocdefinition{vector}} (\\coqdocvar{A} :\n\\coqdockw{Type}) (\\coqdocvar{n} :\n\\coqexternalref{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{nat}{\\coqdocinductive{nat}})\n:= \\coqref{Vector.Fin}{\\coqdocinductive{Fin}} \\coqdocvariable{n}\n\\ensuremath{\\rightarrow} \\coqdocvariable{A}.\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n% further explain this vector type?\nThis makes for a definition of \\coqref{Vector.vmap}{\\coqdocdefinition{vmap}}\nthat is just an abstraction, and therefore solves the guardedness problem in\n\\coqref{Term.id}{\\coqdocdefinition{id}}.\n\\begin{singlespace}\n\\begin{coqdoccode}\n\\coqdocnoindent\n\\coqdockw{Definition} \\coqdef{Vector.vmap}{vmap}{\\coqdocdefinition{vmap}}\n\\coqdocvar{A} \\coqdocvar{B} (\\coqdocvar{f} :\n\\coqdocvariable{A} \\ensuremath{\\rightarrow} \\coqdocvariable{B}) \\coqdocvar{n}\n: \\coqref{Vector.vector}{\\coqdocdefinition{vector}} \\coqdocvariable{A}\n\\coqdocvariable{n} \\ensuremath{\\rightarrow}\n\\coqref{Vector.vector}{\\coqdocdefinition{vector}} \\coqdocvariable{B}\n\\coqdocvariable{n} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdockw{fun} \\coqdocvar{v} \\coqdocvar{i} \\ensuremath{\\Rightarrow}\n\\coqdocvariable{f} (\\coqdocvariable{v} \\coqdocvariable{i}).\\coqdoceol\n\\end{coqdoccode}\n\\end{singlespace}\n", "meta": {"hexsha": "df73e08147c39e7976d8d37a77257911b70feebe", "size": 15409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vu/master-project/coq.tex", "max_stars_repo_name": "martijnvermaat/documents", "max_stars_repo_head_hexsha": "42483b7c4bf94ed708e2893c3ea961d025a10b5e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-28T14:38:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-28T14:38:06.000Z", "max_issues_repo_path": "vu/master-project/coq.tex", "max_issues_repo_name": "martijnvermaat/documents", "max_issues_repo_head_hexsha": "42483b7c4bf94ed708e2893c3ea961d025a10b5e", "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": "vu/master-project/coq.tex", "max_forks_repo_name": "martijnvermaat/documents", "max_forks_repo_head_hexsha": "42483b7c4bf94ed708e2893c3ea961d025a10b5e", "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.7240356083, "max_line_length": 111, "alphanum_fraction": 0.7764293595, "num_tokens": 5194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6314886971825768}}
{"text": " \n\n\\chapter{\\proj Multiresolution}\n\\label{ch_wave}\n% \\chapterhead{Programs}\n\\markright{Programs}\n\n\\section{Multiscale Transform}\n\\index{Multiscale}\n\\subsection{Introduction}\nThe Morlet-Grossmann definition \\cite{wave:grossmann89}   \nof the continuous wavelet\ntransform for a 1-dimensional signal $f(x)\\in L^2(R)$, the space of all\nsquare integrable functions, is:\n\\index{wavelet transform, continuous}\n\\index{continuous wavelet transform}\n\\index{wavelet transform, Morlet-Grossman}\n\\begin{eqnarray}\nW(a,b)=\\frac{1}{\\sqrt a}\\int_{-\\infty}^{+\\infty}f(x) \\psi^* \\left( \n\\frac{x-b}{a} \\right) dx\n\\label{eqn_wave}\n\\end{eqnarray}\nwhere:\n\\begin{itemize}\n\\item $W(a,b)$ is the wavelet coefficient of the function $f(x)$\n\\item $\\psi(x)$ is the analyzing wavelet\n\\item $a$ ($>0$) is the scale parameter\n\\item $b$ is the position parameter\n\\end{itemize}\nMany discrete wavelet transform algorithms have been described \n\\cite{starck:book98}. The most widely-known one  \nis certainly the orthogonal one, \nproposed by Mallat \\cite{wave:mallat89} and its bi-orthogonal version.\nUsing the orthogonal wavelet transform (OWT), a signal $s$ can\nbe decomposed by:\n\\begin{eqnarray}\n s(l) = \\sum_{k} c_{J,k} \\phi_{J,l}(k) \n       +  \\sum_{k} \\sum_{j=1}^J \\psi_{j,l}(k) w_{j,k}\n\\end{eqnarray}\nwith $\\phi_{j,l}(x) = 2^{-j} \\phi(2^{-j}x-l)$ and  $\\psi_{j,l}(x) = 2^{-j} \\psi(2^{-j}x-l)$,\nwhere $\\phi$ and $\\psi$ are respectively \nthe scaling function and the wavelet function. \n$J$ is the number of resolutions used in the decomposition, \n$w_{j}$ the wavelet (or details) coefficients at scale $j$, and\n$c_{J}$ is a coarse or smooth version of the original signal $s$.\nThus, the algorithm outputs $J+1$ subband arrays.\nThe indexing is such that,\nhere, $j = 1$ corresponds to the finest scale (high frequencies).\nCoefficients $c_{j,k}$ and $w_{j,k}$ are obtained by means of the filters\n$h$ and $g$:\n\\begin{eqnarray}\nc_{j+1,l} & = & \\sum_k h(k-2l) c_{j,k} \\nonumber \\\\\nw_{j+1,l} & = & \\sum_k g(k-2l) c_{j,k}\n\\end{eqnarray}\nwhere $h$ and $g$ verify:\n\\begin{eqnarray}\n\\frac{1}{2} \\phi(\\frac{x}{2}) & = &  \\sum_k h(k) \\phi(x-k) \\nonumber \\\\\n\\frac{1}{2} \\psi(\\frac{x}{2}) & = & \\sum_k g(k) \\phi(x-k)\n\\end{eqnarray}\nand the reconstruction of the signal is performed with:\n\\begin{eqnarray}\nc_{j,l} = 2 \\sum_k [ \\tilde h(k+2l) c_{j+1,k}  + \\tilde g(k+2l) w_{j+1,k}  ]\n\\end{eqnarray}\nwhere the filters $\\tilde h$ and $\\tilde g$ must verify the conditions of\ndealiasing and exact reconstruction:\n\\begin{eqnarray}\n\\hat{h}(\\nu+\\frac{1}{2}) \\hat{\\tilde h}(\\nu) + \\hat{g}(\\nu+\\frac{1}{2}) \\hat{\\tilde g}(\\nu)  & = & 0 \\nonumber \\\\\n\\hat{h}(\\nu) \\hat{\\tilde h} + \\hat{g}(\\nu) \\hat{\\tilde g}(\\nu)  & = & 1  \n\\end{eqnarray}\nBy this algorithm, the transformation of an image is an image. \n\n\n\\subsection{Methods}\nThe application of the OWT to image compression and filtering\nhas lead to impressive results compared to previous methods.\nHowever some problems related to the OWT may impact on their \nuse in some applications, and include the following.\n\\begin{enumerate}\n\\item Edge representation: If the OWT performs better than\nthe FFT at representing edges in an image, it is still not optimal.\nThere is only a fixed number of directional elements independent of scale,\nand there is no highly anisotropic element \\cite{cur:candes99_1}. \nFor instance, the Haar 2D \nwavelet transform is optimal for finding features with a  \nratio $length/width = 2$, and a horizontal, vertical, or diagonal \norientation.\n\\item Isotropic feature representation:\nthe 2D OWT \\cite{wave:mallat89} leads to a wavelet\ntransform with three wavelet functions (at each scale there are\nthree wavelet coefficient sub-images) which does not simplify the analysis and\nthe interpretation of the wavelet coefficients. An isotropic transform\nseems more appropriate for images containing features or objects with \nno favored orientation (such as astronomical or medical images).\n\\item Negative values:\nBy definition, the wavelet coefficient mean is zero. Every time we have\na positive structure at a scale, we have negative values surrounding it. These\nnegative values often create artifacts during the restoration process, or\ncomplicate the analysis.\n\\item Point artifacts: For example, cosmic ray hits in optical astronomy\ncan ``pollute'' all\nthe scales of the wavelet transform. The wavelet transform is non-robust\nrelative to such real or detector faults. \n\\item Integer values: The OWT produce floating values which are not \neasy to handle for lossless image compression. \n\\end{enumerate}\nThese problems have lead to the development of other multiscale \nrepresentations. Some of the other algorithms do not produce an image, \nbut a pyramid, or cube.\nSo we separate the different multiscale transform algorithms into classes, \ndepending on the output data type. Other multiscale methods, which are\nnonlinear can also be categorized in this way. We distinguish between\nfives classes of multiscale transform: \n\\bn\n\\item transforms which produce {\\em cubes}\n\\item transforms which produce  {\\em pyramids}\n\\item transforms which produce  {\\em half pyramids}\n\\item transforms which produce {\\em images} (non-redundant transforms)\n\\item transforms which produce directional {\\em cubes}\n\\en\nThe first three, and the last,  are redundant \n(i.e.\\ there are more pixels in the transformation\nthan in the input data).\n\n\\subsection*{Cube transform}\nFor the first class, the input image $I$ can be expressed\nas \\cite{starck:bij94_1,starck:mur95_1,starck:mur95_3}:\n\\begin{eqnarray}\nI(x,y) =  c_p (x,y) + \\sum_{j=1}^{p} w_j(x,y)\n\\end{eqnarray}\n$w_j$ (for $j=1 \\dots p$) and $c_p$ represent the transformation of $I$.\n$c_p$ is a very smoothed version of the image $I$, and $w_j$ is\nthe image which contains information at scale $j$. The transformation\nis defined by $n=p+1$ images ($n = $ number of scales). The $p$\nimages have zero mean (or approximately zero, for nonlinear transforms).\nEach of them corresponds to the information at a given scale, i.e.\\\nstructure of a given size in the input image. Compact structures\n(with size of one or two pixels) will be found at the first scale ($j=1$).\nFor this class of transformation, which is very redundant, the amount \nof data is multiplied by the number of scales $n$. Therefore this\ntakes a lot of memory, but the multiresolution coefficients ($w_j(x,y)$)\nare easy to interpret. \n\n\\subsection*{Pyramidal transform}\n\nThe second class of transformation is \nless redundant. The first scale has the same size as the image, but\nfor the other scales, the number of pixels is reduced by four at\neach resolution. Thus, if $N^2$ is the number of pixels of $I$, the \nnumber of pixels of the transformation is $4/3N^2$. \n\n\\subsection*{Half-pyramidal transform}\nThis transform \\cite{wave:bijaoui97} is relatively close to the previous one, but the two first\nscales are not decimated (i.e.\\ they have the same size as the input image).\nSee Appendix~D for more details.\n\n\n\\subsection*{Non-redundant transform}\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_mallat.ps,bbllx=5.5cm,bblly=9.5cm,bburx=16cm,bbury=20cm,height=10cm,width=10cm,clip=}\n}}\n\\caption{Mallat wavelet transform representation of an image.}\n\\index{Mallat's multiresolution}\n\\label{fig_mallat}\n\\end{figure}\n\nThe last class is completely non-redundant, and the number of pixels\n is the same as in the input image. This means that it is an image. \nFigure~\\ref{fig_mallat}\nshows the representation of an image using the Mallat transform \\cite{wave:mallat89,wave:antonini92,wave:daube88}. At a \ngiven resolution, the image is shared between four parts. Three subimages\ncorrespond to details of the image in the horizontal, vertical, and \ndiagonal directions, and the last part corresponds to the image at a lower\nresolution. The process can then be repeated on the image at the\nlower resolution. The Haar wavelet transform, lifting scheme transform,\nand the G transform (which is a nonlinear transform based on the minimum and \nthe maximum) produce the same kind of representation.  \n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_feauveau.ps,bbllx=5.5cm,bblly=9.5cm,bburx=16cm,bbury=20cm,height=12cm,width=12cm,clip=}\n}}\n\\caption{Feauveau wavelet transform representation of an image.}\n\\label{fig_feauveau}\n\\end{figure}\nThe Feauveau transform \\cite{wave:feauveau} (see Figure~\\ref{fig_feauveau}) is not redundant, \nbut the representation is different.\nThere is no prioritized direction, and we have an intermediate \nresolution (half resolution). \n\n\\subsection*{Directional cube transform}\nIn this case, just as for the orthogonal Mallat transform, the \nanalysis is directional, but there\nis no decimation. This means that the number of output bands is equal to\nthe number of scales multiplied by the number of directions, and each band\nhas the same number \nof pixels as the input image. The dyadic wavelet transform\nuses two directions (vertical and horizontal), and the undecimated \nwavelet transform uses three directions (vertical, horizontal, and diagonal).\n\n\\subsection*{Algorithms}\nSince the output differs following the chosen algorithm, we will define\nthe term {\\em band} as a subimage included in a given dyadic scale.\nFor the cube and pyramid transforms, the number of bands is equal to the \nnumber of scales. For the Mallat algorithm and the undecimated \nbi-orthogonal wavelet transform, we have three bands per scale.\nFor the Feauveau and the dyadic wavelet transform, we have two bands\nper scale. Table~\\ref{tab_algo} indicates for each \\proj \\ algorithm its\nclass, the number of bands per scale, and if it is redundant and linear.\n\n\\begin{table}\n{\\centering \\begin{tabular}{|l|c|c|c|c|}\n\\hline \nMultiscale algorithm & Class & Redund- &  Bands  & Linear\\\\\n                     &       & ant         & per scale  &  \\\\\n\\hline \n\\hline \n1: linear WT & Cube & Yes & 1 & Yes \\\\ \\hline \n2: B-spline WT & Cube & Yes & 1 & Yes \\\\ \\hline \n3: wavelet transform in Fourier space & Cube & Yes & 1 & Yes \\\\ \\hline\n4: morphological median transform (MT) & Cube & Yes & 1 & No \\\\ \\hline\n5: morphological minmax transform & Cube & Yes & 1 & No \\\\ \\hline\n6: pyramidal linear WT & Pyramid & Yes & 1 & Yes \\\\ \\hline\n7: pyramidal B-spline WT & Pyramid & Yes & 1 & Yes \\\\ \\hline\n8: pyramidal WT in Fourier space: alg.\\ 1  & Pyramid & Yes & 1 & Yes \\\\ \\hline\n9: pyramidal WT in Fourier space: alg.\\ 2   & Pyramid & Yes & 1 & Yes \\\\ \\hline\n10: pyramidal median transform  & Pyramid & Yes & 1 & No \\\\ \\hline\n11: pyramidal Laplacian  & Pyramid & Yes & 1 & No \\\\ \\hline\n12: morph.\\ pyramidal minmax transform  & Pyramid & Yes & 1 & No \\\\ \\hline\n13: decomposition on scaling function & Pyramid & Yes & 1 & No \\\\ \\hline\n14: (bi-) orthogonal wavelet transform & Image & No & 3 & Yes \\\\ \n14-1: Antonini 7/9 filter             &        &     &   &    \\\\\n14-2: Daubechies filter 4             &        &     &   &    \\\\\n14-3: Biorthogonal 2/6 Haar filters   &        &     &   &    \\\\\n14-4: Biorthogonal 2/10 Haar filters  &        &     &   &     \\\\\n14-5: Odegard 7/9 filters             &        &     &   &     \\\\\n14-6: User's filters                  &        &     &   &     \\\\ \\hline\n15: Feauveau WT & Image & No & 2 & Yes \\\\ \\hline\n16: Feauveau WT without undersampling & Cube & Yes & 2 & Yes \\\\ \\hline\n17: G transform (morph.\\ min-max alg.)  & Image & No & 3 & No \\\\ \\hline\n18: Haar wavelet transform & Image & No & 3 & Yes \\\\ \\hline\n19: Half-pyramidal transform & Half-Pyramid & Yes & 1 & Yes \\\\ \\hline\n20: Mixed Half-pyramidal and MT  &  Half-Pyramid & Yes & 1 & No  \\\\ \\hline\n21: Dyadic wavelet transform   &  Dir. Cube & Yes & 2 & Yes  \\\\ \\hline\n22: Mixed WT and PMT method  & Pyramid & Yes & 1 & No \\\\ \\hline\n23: Undecimated Haar transform  & Dir. Cube & Yes & 1 & Yes \\\\ \\hline\n24: Undecimated bi-orthog. wavelet trans. & Dir. Cube & Yes & 3 & Yes \\\\ \n\\ \\ \\ \\ (filters 14-1 to 14-6 are available) &           &     &    &  \\\\ \\hline\n25: Wavelet transform via lifting scheme & Image & No & 3 &    \\\\ \n25-1: CDF WT                             &       &    &   &  Yes \\\\\n25-2: Median prediction                  &       &    &   &  No \\\\\n25-3: integer Haar WT                    &       &    &   &  No \\\\ \n25-4: integer CDF WT                     &       &    &   &  No \\\\ \n25-5: integer (4,2) interpolating transform &       &    &   &  No \\\\  \n25-6: Antonini 7/9 filter                &       &    &   &  Yes \\\\  \n25-7: integer  Antonini 7/9 filter       &       &    &   &  No \\\\ \\hline\n\\hline \n\\end{tabular}\\par}\n\\caption{Multiscale transform algorithms.}\n\\label{tab_algo}\n\\end{table}\n\\vspace{0.3cm}\n\n\\section{Multiresolution object}\n\n\\subsection{Multiresolution transform of image: mr\\_transform}\n\\label{sect_trans}\n\\index{mr\\_transform}\nThe program \n{\\em mr\\_transform} computes the multiresolution transform of an image.\nThis transform can be a linear transform (wavelet transform) or\na morphological transform (based on the median, or the minimum \nand the maximum).  \nThe output file which contains the transformation has a \nsuffix, .mr. If the output file name\ngiven by the user does not contain this suffix, it is automatically\nadded. The ``.mr'' file is a FITS format file, and can be manipulated by\nany package dealing with FITS format, or using the \n{\\em mr\\_extract} program.\n{\\bf\n\\begin{center}\n USAGE: mr\\_transform option image\\_in multiresolution\\_transform\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]}\n{\\small \n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item linear wavelet transform: \\`a trous algorithm \n\\item B-spline wavelet transform: \\`a trous algorithm \n\\item wavelet transform in Fourier space \n\\item morphological median transform \n\\item morphological minmax transform \n\\item pyramidal linear wavelet transform \n\\item pyramidal B-spline wavelet transform \n\\item pyramidal wavelet transform in Fourier space: \n                     wavelet =  between two resolutions \n\\item  pyramidal wavelet transform in Fourier space: \n                     wavelet = difference between the square of two resolutions\n\\item  pyramidal median transform \n\\item  pyramidal Laplacian \n\\item  morphological pyramidal minmax transform \n\\item  decomposition on scaling function \n\\item  (bi-) orthogonal wavelet transform. \\\\ \nAntonini 7/9 filters ~\\cite{wave:antonini92} are used by default, with an \n$L_1$ normalization. The filters can be changed using the ``-T'' option, and\nan $L_2$ normalization is obtained by ``-L'' option.\n\\item  Feauveau wavelet transform \n\\item  Feauveau wavelet transform without undersampling \n\\item  G transform (non-redundant morphological min-max algorithm)\n\\item Haar wavelet transform (L2 normalization).\n\\item Half-pyramidal wavelet transform (HPWT)\n\\item Mixed HPWT and Median method\n\\item dyadic wavelet transform \n\\item Mixed WT and PMT method (WT-PMT) \n\\item Undecimated Haar transform: \\`a trous algorithm\n\\item Undecimated (bi-) orthogonal wavelet transform. \\\\\nAntonini 7/9 filters ~\\cite{wave:antonini92} are used by default, with an \n$L_1$ normalization. The filters can be changed using the ``-T'' option, and\nan $L_2$ normalization is obtained by ``-L'' option.\n\\item Wavelet transform via lifting scheme \n\\end{enumerate}}\nDefault is 2.\n\\item {\\bf [-T type\\_of\\_filters]}  \n{\\small\n\\begin{enumerate}\n\\item Antonini 7/9 filters. \n\\item Daubechies filter 4. \n\\item Biorthogonal 2/6 Haar filters.\n\\item Biorthogonal 2/10 Haar filters.\n\\item Odegard 7/9 filters.\n\\item User's filters.\n\\end{enumerate}}\nDefault is Antonini 7/9 filters. \\\\\n This option is only available if the chosen transform method is\n the (bi-) orthogonal transform (-t 14 or -t 24).\n\\item {\\bf [-L]} \\\\\nUse an $L_2$ normalization. Default is $L_1$.\n\\item {\\bf [-u]} \\\\\nNumber of undecimated scales used in the undecimated wavelet transform.\nDefault is all scales.\n\\item {\\bf [-l type\\_of\\_lifting\\_transform]}  \n{\\small \n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\item Lifting scheme: CDF WT. \n\\item Lifting scheme: median prediction.\n\\item Lifting scheme: integer Haar WT. \n\\item Lifting scheme: integer CDF WT. \n\\item Lifting scheme: integer (4,2) interpolating transform. \n\\item Lifting scheme:  Antonini 7/9 filters.\n\\item Lifting scheme: integer Antonini 7/9 filters. \n\\end{enumerate}}\n Default is Lifting scheme: integer Haar WT. \\\\\n This option is only available if the chosen transform method is\n the lifing scheme (-t 24).\n\\item {\\bf [-n number\\_of\\_scales]} \\\\\n Number of scales used in the multiresolution transform.\n Default is 4.\n\\item {\\bf [-x]} \\\\\n Write all bands separately as images with prefix ``band\\_j'', j=1,..,NbrBand\n (j being the band number). Note also that $j=1$ corresponds to \n the smallest scale (highest frequency band), and j increases for larger\n scales.\n\\item {\\bf [-B]} \\\\\n Same as x option, but interpolate the bands by block in order to\n have the same size as the original image.\n% \\item {\\bf [-i]} \\\\\n% Same as x option, but interpolate the bands by a B$_3$-spline.\n% This option is valid only if the chosen multiresolution \n%  transform belongs to the pyramidal class.\n\\item {\\bf [-c iter]} \\\\\nAn exact reconstruction cannot be achieved from all \npyramidal transformations, and a few iterations may be necessary to refine\nthe result. \nTherefore, for transformations (6,7,8,9,10,12), this option\nis valid, and {\\em iter} sets the  number of iterations. Generally,\nthree is enough. Default is no iteration.\n\\item {\\bf [-u number\\_of\\_undecimated\\_scales]} \\\\\nNumber of undecimated scales used in the undecimated wavelet \ntransform (-t 24).\nBy default, all scales are undecimated.\n\\end{itemize}\n\nThe distribution of the transforms into classes is the following:\n\\bn\n\\item cube: transform 1 to 5, and 16, and 23.\n\\item pyramid: transforms 6 to 13, 22.\n\\item half-pyramid: transform 19,20.\n\\item image: 14, 15, 17, 18, 25.\n\\item directional cube: 21,24.\n\\en\n\nOptions ``-x'' and ``-B'' are mutually\nexclusive. If one of these\noptions is set, the second parameter is used also as prefix for the \ncreation of the band-images.  \\\\\nOption ``-u'' is only valid if the undecimated wavelet transform (-t 24)\nis selected. \\\\\nWavelet transforms using the Fourier transform require the input\nimage to be a square image, with a number of pixels which is an integer \npower of 2. \\\\\nThe result is stored in a file (suffix ``.mr\"),\nand images (or bands) of the transformation can be extracted\nby using the {\\em mr\\_extract} program. \\\\\n\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mr\\_transform -t 10 image.d pyr\\_trans.mr \\\\\nApply the pyramidal median transform to an image, and store the\nresult in pyr\\_trans.mr. \n\\item mr\\_transform -t 10 -x image.d pyr\\_trans.mr \\\\\nSame as before, but write all scales separately\nin files: \\\\\n (band\\_1\\_pyr\\_trans.d, band\\_2\\_pyr\\_trans.d, etc.).\n\\item mr\\_transform -t 8 -B image.d pyr\\_wave.mr \\\\\nApply a pyramidal wavelet transform, and each scale is interpolated\nto the input image size before being saved in a file of name \n``band\\_j\\_pyr\\_wave.d'', where j is the scale number.\n\\item mr\\_transform -t 14 -T 4 image.d bio\\_wave.mr \\\\\nBi-orthogonal wavelet transform using Odegard 7/9 filters.\n\\item mr\\_transform -t 25 -l 3 image.d bio\\_wave.mr \\\\\nInteger Haar wavelet transform.\n\\end{itemize}\nFigure~\\ref{fig_ngc} shows the galaxy NGC2997, and \nFigure~\\ref{pl_pave_gala} its\nwavelet transform using the \\`a trous algorithm with four scales (three \nwavelet scales, and the last smooth array). Each scale has the same size\nas the original image.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_ngc.ps,bbllx=1.9cm,bblly=12.6cm,bburx=14.6cm,bbury=25.4cm,width=11cm,height=11cm,clip=}\n}}\n\\caption{Galaxy NGC2997.}\n\\label{fig_ngc}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=ch1_pave_gala.ps,bbllx=2cm,bblly=9.5cm,bburx=19cm,bbury=27cm,height=11cm,width=11cm,clip=}\n}}\n\\caption{Wavelet transform of NGC 2997 by the \\`a trous algorithm.}\n\\label{pl_pave_gala}\n\\end{figure}\n\n\n\\subsection{How to select a filter bank?}\nThe (bi-) orthogonal wavelet transform (OWT) and the \nundecimated wavelet transform (UWT) allow the user to select between\nfive different filter banks (see Table~\\ref{tab_algo}, from 14-1 to 14-5), \nor to use one's own filter bank. In this case, a file must contain the \ncoefficient values of the filters $h$ and $\\tilde h$. \nThe file format is the Bath Wavelet Warehouse file format \n(see \\\\\nhttp://dmsun4.bath.ac.uk/wavelets/warehouse.html \\\\\nfor more information).\nThe file is an ASCII file, with the ``.wvf'' extension, \nand the general format for describing wavelet filter coefficients is \nthe following:\n\\begin{verbatim}\n[Range low] [Range high]\n[Analysis LP filter coefficients]\n.\n.\n.\n[Range low] [Range high]\n[Synthesis LP filter coefficients]\n.\n.\n.\n\\end{verbatim}\nFor example, the Daubechies filter 4 is (the filename is dau4.wvf):\n\\begin{verbatim}\n0 3\n0.4829629131445341\n0.8365163037378079\n0.2241438680420134\n-0.1294095225512604\n0 3\n0.4829629131445341\n0.8365163037378079\n0.2241438680420134\n-0.1294095225512604\n\\end{verbatim}\nMore than thirty different filters are available at the  \nBath Wavelet Warehouse.\nIn the \\proj programs, when the option ``-t 14'' (for the OWT) or ``-t 24''\n(for the UWT) are chosen, the option ``-T 6'' or  ``-T 6,filename'' is used \nfor defining a user filter. If no file is given, the \\proj programs first\ncheck if the default filename {\\bf ``mr1.wvf''} exits in the current \ndirectory, and if it does not exist,\nthe environment variable {\\bf CEA\\_FILTER} \\index{CEA\\_FILTER} is tested. \nExamples of command line syntax for the wavelet transform program are:\n\\begin{itemize}\n\\item mr\\_transform -t 14 -T 6,dau4 image.d dwt\\_trans.mr \\\\\nBi-orthogonal wavelet transform, using the filters defined in\nthe file ``dau4.wvf''.  \n\\item mr\\_transform -t 24 -T 6 image.d uwt\\_trans.mr\\\\\nUndecimated wavelet transform, using the file {\\bf ``mr1.wvf''} if it\nexists, otherwise using the file name contained in the environment \nvariable {\\bf CEA\\_FILTER}.\n\\end{itemize}\n\n\n\\clearpage\n\n\\subsection{Extraction of a scale: mr\\_extract}\n\\label{sect_extr}\n\\index{mr\\_extract}\nThe program {\\em mr\\_extract} allows the user to extract a scale or a band from\na multiresolution transform file (suffix ``.mr\").\n{\\bf\n\\begin{center}\n USAGE: mr\\_extract options multiresolution\\_file  output\\_image\n\\end{center}}\nwhere options are:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf  [-b band\\_number] } \\\\\n Band number to extract. Default is 1.\n\\item {\\bf  [-s scale\\_number] } \\\\\n Scale number to extract. Default is 1.\n\\item {\\bf  [-x]} \\\\\nExtract all the bands. The second parameter is used\nas a prefix. If this option is set, the second parameter {\\bf must} only\ncontain the file name, and not the complete path of the file.\n\\item {\\bf   [-B]} \\\\\nInterpolate the scale by block, in order to have the same\nsize as the original image. For scale extraction, \nthis option is valid only if the \n multiresolution transform is pyramidal, and is always valid for\n band extraction.\n%  \\item {\\bf   [-i]} \\\\  \n% Interpolate the scale with a B$_3$-spline, in order to have the same\n% size as the original image.  This option is valid only if\n%  the multiresolution transform is pyramidal.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_extract -s 1 mr\\_file.mr scale\\_1.d \\\\\nExtract the first scale of the wavelet transform, and write as a .d\nimage of name ``scale\\_1.d''. If the transform is an orthogonal transform,\nit will contain all of the transform.\n\\item mr\\_extract -b 1 mr\\_file.mr band\\_1.d \\\\\nExtract the first band of the wavelet transform, and write as a .d\nimage of name ``band\\_1.d''. If the transform is an orthogonal transform,\nit will contain only the first band (in one single direction)\nof the transform.\n\\item mr\\_extract -x  mr\\_file.mr toto.d\\\\\nCreates the files ``toto\\_band\\_1.d'', ..., ``toto\\_band\\_j.d''. \n\\end{itemize}\n\n\\subsection{Insertion of an image: mr\\_insert}\n\\index{mr\\_insert}\nThe program\n{\\em mr\\_insert} replaces a scale or a band by some image, by inserting it\nin the multiresolution transform file. The scale (or the band) and the image\nmust have the same size. \n\n{\\bf \\begin{center}\n USAGE: mr\\_insert options multiresolution\\_file input\\_image\n\\end{center}}\nwhere options are:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item  {\\bf  [-b band\\_number] } \\\\\n Band number to insert. Default is 1.\n\\item  {\\bf  [-s scale\\_number] } \\\\\n Scale number to insert. Default is 1.\n\\end{itemize}\n {\\em multiresolution\\_file} is the file (.mr) which contains \nthe multiresolution transformation. \\\\\n {\\em input\\_image} is the image\nwhich must replace the band image. \\\\\n {\\em band\\_number} specifies\nthe band number to be replaced. Default is 1.  \nThe multiresolution transform is updated. \\\\\n\\subsubsection*{Example:}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_insert -b 3 mr\\_file.mr image.d \\\\\nInsert an image at the third scale of the multiresolution file. \n\\end{itemize}\n\n\\subsection{Reconstruction: mr\\_recons}\n\\index{mr\\_recons}\nThe program \n{\\em mr\\_recons}  reconstructs an image from its multiresolution\ntransform.\n{\\bf \n\\begin{center}\n USAGE: mr\\_recons  multiresolution\\_file  image\\_out\n\\end{center}}\n{\\em multiresolution\\_file} is the file (.mr) which contains \nthe multiresolution transformation, {\\em output\\_image} is  the\noutput reconstructed image.\n\n\\section{Multiresolution tools}\n\\subsection{Visualization: mr\\_visu}\n\\index{mr\\_visu}\nAll scales of the multiresolution transform are normalized to 1, and inserted\nin one image, which can be\nvisualized by a graphics tool  (xv, IDL, etc.). \nThe input\nfile can either be an image or a multiresolution file. In the second case \noptions ``-t, -n\", which define the type of transformation and the number of\nscales, are not used. By default the output image is represented in graylevel,\nwith each scale normalized to 255. The normalization can be avoided using \nthe ``-c\"\noption. Two other representations are also available, the perspective one\n(all scales are represented in a 3-dimensional way), and the contour one.\nIn the contour representation, one contour is plotted per scale. The contour\nlevel is determined from the standard deviation of the first scale and the {\\em nsigma}\nparameter (which can be modified by the ``-s\" option). Non-isotropic \ntransforms cannot be used for perspective or contour representation. \n\n%The output can\n%be also saved in a Postscript file by the \"-w\" option.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=ch1_wave_3D.ps,bbllx=1.7cm,bblly=5.3cm,bburx=19.3cm,bbury=23.3cm,height=18cm,width=15cm,clip=}\n}}\n\\caption{3D perspective view of NGC 2997 wavelet scales.}\n\\index{wavelet transform}\n\\label{fig_wave_3D}\n\\end{figure}\nFigure~\\ref{fig_wave_3D} shows the wavelet transform of the galaxy NGC2997,\nwith five scales, and using a perspective representation.\n\n{\\bf\n\\begin{center}\n USAGE: mr\\_visu image\\_in\\_or\\_MRfile  image\\_out\n\\end{center}}\nwhere options are:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-T type\\_of\\_filters]}  \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-L]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-n number\\_of\\_scales]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-V Type\\_Visu]}\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\item Graylevel\n\\item Contour\n\\item Perspective\n\\end{enumerate}\n Default is 1.\n\\item {\\bf [-b]} \\\\\n Save output image as bi-level.  Only used if {\\em Type\\_Visu} is \nequal to 2 or 3.\n Default is not to save.\n\\item {\\bf [-c]} \\\\\n Do not apply a normalization on the multiresolution coefficient.\nOnly used if {\\em Type\\_Visu} is equal to 1.\n% \\item {\\bf [-w PS\\_FileName]} \\\\\n% Save also the result in a Postscript file.\n \\item {\\bf [-i Increment]} \\\\\n Number of lines of the image which will be used. \\\\\n If Increment = 3, only one line out of 3 is used. \\\\\n Only used if  {\\em Type\\_Visu} is equal to 3. \\\\\nThe default value is 1.\n\\item {\\bf [-s nsigma]} \\\\\nPlot contour at {\\em nsigma}$*$Sigma if  {\\em Type\\_Visu} equal to 2. \\\\\nThreshold value upper nsigma$*$Sigma if  {\\em Type\\_Visu} equal to 3. \\\\\nDefault is 3. \n\\end{itemize}\n\n\n\\subsection{Multiresolution support creation: mr\\_support}\n\\label{sect_support}\n\\index{mr\\_support}\n\\index{multiresolution support}\nThe multiresolution support of an image describes in a\nlogical or boolean way if an image $I$ contains information at a \ngiven scale $j$ and at a given position $(x,y)$ \\cite{starck:sta95_1,starck:mur95_2,starck:mur93}.\nIf $M^{(I)}(j,x,y) = 1$ (or {\\it true}), then $I$ contains information at \nscale $j$ and at the position $(x,y)$.\n$M$ depends on several parameters:\n\\begin{itemize}\n\\item The input image.\n\\item The algorithm used for the multiresolution decomposition.\n\\item The noise.\n\\item All constraints we additionally want the support to satisfy.\n\\end{itemize}\nSuch a support results from the data, the treatment (noise\nestimation, etc.), and from knowledge on our part of the objects contained\nin the data (size of objects, linearity, etc.). In the most general case, \na priori information is not available to us.\n\nThe multiresolution support of an image is computed in several steps:\n\\begin{itemize}\n\\item Step 1 is to compute the wavelet transform of the image.\n\\item Binarization of each scale leads to the multiresolution support.\n\\item A priori knowledge can be introduced by modifying the support.\n\\end{itemize}\n \nThe last step depends on the knowledge we have of our images.\nFor instance, if we know there is no interesting object smaller or larger \nthan a\ngiven size in our image, we can suppress, in the support, anything which is\ndue to that kind of object. This can often be done conveniently by  the use of \nmathematical morphology. Negative detections can sometimes be suppressed too.\nIn the most general setting, we naturally have\nno information to add to the multiresolution support.\n\nA complete description of how to derive the multiresolution support from\nthe multiresolution coefficients is given in \\cite{starck:sta95_1,starck:book98}. Several types\nof noise are taken into account:\n\\begin{enumerate}\n\\item Gaussian noise (default case).\n\\item Poisson noise.\n\\item Poisson and Gaussian noise\n\\end{enumerate}\nFor the last two transforms, a variance stabilization transform is applied\nto the input image, which allows us to obtain a transformed image which\ncontains  Gaussian noise with a standard deviation equal to one. After\ntransformation of the image (or the variance stabilized image), each\nwavelet coefficient $w_j(x,y)$ is compared to the standard deviation at \nthe scale $j$, $\\sigma_j$ multiplied by a coefficient $N_\\sigma$. \nThis coefficient specifies \nthe confidence interval we want. If $\\mid w_j(x,y) \\mid \\ \n> N_\\sigma \\sigma_j$, the\nprobability that $w_j(x,y)$ is due to noise is less than 1\\%.\n\n\\begin{center}\n USAGE: mr\\_support options image\\_in multiresolution\\_file\\_out\n\\end{center}\n where options are:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-T type\\_of\\_filters]}  \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-L]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-u]} \\\\\n  see \\ref{sect_trans}.\n\\item {\\bf [-g sigma]} \\\\\n The image contains Gaussian noise, and the standard deviation is\ngiven by {\\em sigma }. The option should be set only if the user\nknows the standard deviation of the noise. \n\\item {\\bf [-p]} \\\\\n If this option is set, the image is assumed to contain Poisson noise.\n The default is Gaussian noise, and its standard \n deviation is automatically estimated. \n\\item {\\bf [-c gain,sigma,mean]} \\\\\nThe noise is composed of a Gaussian and Poisson component.  This is the \ncase for a CCD detector. \\\\\nnoise = Poisson noise and read-out noise \\\\\ngain = inverse of the CCD gain (unit: $DN/e^{-}$) \\\\\nsigma = standard deviation of the read-out noise (unit: DN) = CCD RON / CCD Gain\\\\\nmean = mean of the read-out noise \\\\\nIf this option is set, \\\\\nNoise = Poisson and Gaussian read-out noise \\\\\nThis is generally the case with a CCD. \\\\\nNote: these parameters must be separated by a comma without spaces. \\\\\nExample: -c 0.133,1.733,0. \\\\\nIf the mean, or sigma and the mean, are omitted, default values are 0. \\\\\nThe gain cannot be omitted if parameter -c is used.\n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nNumber of scales used in the multiresolution transform. Default is 4.\n\\item {\\bf [-s NSigma]} \\\\\nThe detection level at each scale is determined by the product\nof the standard deviation of the noise by the {\\em NSigma}.\n{\\em NSigma} fixes the confidence interval we want. By default,\n{\\em NSigma} is equal to 3.\n\\item {\\bf [-k]} \\\\\nIf this option is set, isolated pixels in the multiresolution support\nare suppressed. If the PSF is large, then isolated pixels are \ncertainly residual noise, or spurious impulse noise objects,  \nor artifacts. Then\nwe can suppress these pixels in the support. This option\ncan only be used with transformations of class 1 and 2 (which\nproduce cubes and pyramids). Default is not to do this.\n\\item {\\bf [-l]} \\\\\nIf this option is set, the morphological dilation operator is\napplied on each scale of the multiresolution support. This option\ncan only be used with transformations of class 1 and 2 (which\nproduce cubes and pyramids). Default is not to do this.\n\\item {\\bf [-w support\\_file\\_name]} \\\\\n If this option is set, a synthetic image is created from the \nmultiresolution support. Default is not to do this.\n\\end{itemize}                 \n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mr\\_support -w support.d -t 14 image.d  mr\\_file.mr  \\\\\nCreates the multiresolution support of an image, assuming the noise is\nGaussian (its standard deviation is automatically estimated). A .d image\nis created from the support.\n\\item mr\\_support -w support.d -p image.d  mr\\_file.mr  \\\\\nCreates the multiresolution support  of an image, assuming the noise follows\na Poisson distribution. The chosen multiresolution transform \nis the default one \n(\\`a trous algorithm). A~.d image is created from the support. This is not\na boolean image as in the previous example, because it is obtained by\naddition of all boolean scales of the multiresolution support.\n\\end{itemize}\n\n\n\\subsection{Statistical information: mr\\_info}\n\\index{mr\\_info}\nProgram \n{\\em mr\\_info} gives statistical multiresolution information for an image\n(min, max, sigma, mean, skewness and kurtosis at each scale). \nIf the transform belongs to \nclass 1 or 2\n(output is a cube or a pyramid), then additional options allow the \nsignificant coefficients to be analyzed, and furnish \n\\begin{itemize}\n\\item the percentage of significant coefficients at each scale,\n\\item the number of maxima at each scale,\n\\item the number of structures detected at each scale,\n\\item the size in pixels of the largest  detected structure at each scale.\n\\end{itemize}\nIf an output file name is given, a 2D array containing statistical information\nis saved on the disk in the FITS format. The output file is a \nfits file containing a two dimensional array $T[J-1,5]$ ($J$ being the\nnumber of bands), with the following the syntax:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\item $T[j,0] = $ standard deviation of the jth ridgelet band.\n\\item $T[j,1] = $ skewness of the jth ridgelet band.\n\\item $T[j,2] = $ kurtosis of the jth ridgelet band.\n\\item $T[j,3] = $ minimum of the jth ridgelet band.\n\\item $T[j,4] = $ maximum of the jth ridgelet band.\n\\end{itemize}\n\n{\\bf \n\\begin{center}\n USAGE: mr\\_info option image\\_in [out\\_statfile]\n\\end{center}}\n where options are \n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \n\\item {\\bf [-T type\\_of\\_filters]}  \n\\item {\\bf [-L]} \n\\item {\\bf [-u]} \n\\item {\\bf [-p]} \n\\item {\\bf [-g sigma]} \n\\item {\\bf [-c gain,sigma,mean]} \n\\item {\\bf [-n number\\_of\\_scales]} \n\\item {\\bf [-s NSigma]} \n\\item {\\bf [-k]} \n\\item {\\bf [-l]}\n\\item {\\bf [-a]} \\\\\nSignificant structures analysis. Default is not to do this.\n\\end{itemize}\nOptions [t,T,L,u,p,g,c,n,s,k,l] are the same as those described in \nsection~\\ref{sect_support}. \\\\\nOptions [a,p,g,c,s,k,l] are not\nallowed for transforms producing images (class 4). \\\\\nIf any of\nthe options [a,p,g,c,s,k,l] is set, a significant structures\nanalysis is performed.\n\\subsubsection{Examples:}\n\\begin{itemize}\n\\item mr\\_info image.d  \\\\\nWrites on the standard output the minimum value, the maximum value,\nthe mean value, and the standard deviation of each scale.\n\\item mr\\_info -a  image.d \\\\\nSame as before, but computes also the percentage of significant\npixels per scale, and the number of maxima, the number of\nstructures, and the size (in pixels) of the bigger structures.\n\\end{itemize}\n\n\\subsection{Multiresolution segmentation: mr\\_segment}\n\\index{mr\\_segment}\nProgram \n{\\em mr\\_segment} binarizes all the scales of the wavelet \ntransform of an image, and applies tp each one \na segmentation procedure. \nEach scale of the output multiresolution file contains \nan image in which values are ranged between 0 and $R_j$,\nwhere $R_j$ is the number of regions found at this scale.\n{\\bf\n\\begin{center}\n USAGE: mr\\_segment option image\\_in mr\\_file\\_out\n\\end{center}}\nwhere {\\em mr\\_file\\_out} is the multiresolution file (``.mr\")\nwhich contains the segmented scales. Options are \n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \n\\item {\\bf [-T type\\_of\\_filters]}  \n\\item {\\bf [-L]} \n\\item {\\bf [-u]} \n\\item {\\bf [-p]} \n\\item {\\bf [-g sigma]} \n\\item {\\bf [-c gain,sigma,mean]} \n\\item {\\bf [-n number\\_of\\_scales]} \n\\item {\\bf [-s NSigma]} \n\\item {\\bf [-k]} \n\\item {\\bf [-l]}\n\\end{itemize}\nThese options are the same as those described in \nsection \\ref{sect_support}.\n\\subsubsection*{Example:}\n\\begin{itemize}\n\\item mr\\_segment -g 1. image.d  mr\\_file\\\\\nApplies the default multiresolution transform (\\`a trous algorithm)\nto the input image, thresholds the scale assuming Gaussian noise\nwith a standard deviation equal to 1, and applies a segmentation\non each scale.\n\\end{itemize}\n\n\\subsection{Noise analysis: mr\\_sigma}\n\\index{mr\\_sigma}\nProgram \n{\\em mr\\_sigma} estimates the standard deviation of  Gaussian \nnoise in an image \\cite{starck:sta98_3}. Several methods can \nbe used. One of them \n(Multiresolution support) is based on the multiresolution.\nIf the option ``-p\" is set, the noise is considered to be \na combination of both Gaussian and Poisson noise. In this \ncase, the program seeks the standard deviation of the Gaussian\ncomponent of the noise using the generalized Anscombe transform.\n{\\bf\n\\begin{center}\n USAGE: mr\\_sigma options image \n\\end{center}}\nwhere options are:\n \\begin{itemize}\n \\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-m type\\_of\\_methods]}\n{\\small \n\\begin{enumerate}\n \\item 3\\_sigma\\_clipping \n \\item Median + 3\\_sigma\\_clipping  \n \\item Bspline + 3\\_sigma\\_clipping \n \\item Multiresolution support \n \\item Block method \n \\item MAD method (Median of Absolute Deviation) \n\\end{enumerate}\n}\nDefault is 2.\n\\item {\\bf [-n number\\_of\\_scales]}\nNumber of scales used in the multiresolution transform.\nDefault is 4.\n\\item {\\bf [-p gain]} \\\\\nComputes the standard deviation of the Gaussian part of the \nnoise (RON), knowing the gain, in the case where the noise is\ncomposed of Poisson and Gaussian noise.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mr\\_sigma image.d  \\\\\nComputes the standard deviation of the Gaussian noise contained in the\ninput image, using the default method.\n\\item mr\\_sigma -p 1 image.d  \\\\\nComputes the standard deviation of the read-out noise, assuming a gain\nequal to 1.\n\\end{itemize}\n\n\\subsection{Background subtraction: mr\\_background}\n\\index{mr\\_background}\n\n\\label{sect_bgr}\n Program \n{\\em mr\\_background} subtracts the background from an image. The\nbackground is considered as being the last scale of the pyramidal\nmedian transform. The number of scales is automatically calculated in order\nto have the last scale with a size lower than or equal to 16 $\\times$ \n16 pixels. \nThis value of 16 can \nbe modified by the ``-n\" option.\n{\\bf\n\\begin{center}\n USAGE: mr\\_background option image\\_in image\\_out\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-n number\\_of\\_pixels]} \\\\\nNumber of pixels used for background estimation. Default is 16.\n\\item {\\bf [-w background\\_file\\_name]} \\\\\nCreates the background image and writes it on disk.\n\\item {\\bf [-W MedianWindowSize]} \\\\\nMedian window size using in the Pyramidal Median Transform.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_background image.d  im\\_bgr\\_free.d\\\\\nComputes the pyramidal median transform of the input image, \ninterpolates the last scale to the image, and subtracts it from\nthe input image.\n\\item mr\\_background -n 32 -w bgr.d image.d  \\\\\nThe number of scales is calculated so that the last scale\nwill have less than 32 pixels in at least one dimension.\n\\end{itemize}\n\n\\subsection{Image comparison: mr\\_compare}\n\\index{mr\\_compare}\nProgram \n{\\em mr\\_compare} compares a set of images to a reference image.\nThese comparisons are performed both in the direct space and in the\nwavelet space. By default, only structures above the noise are considered\nfor the comparison. If the {\\em NSigma} parameter is set to zero, then\nall wavelet coefficients are taken into account. If the {\\em number\\_of\\_scales}\nparameter is set to 1, then the comparison is only done in the direct space.\nFor all images, the minimum, the maximum, the mean and standard deviation are\nprinted. For each image {\\em ima\\_i}, the wavelet transform of {\\em ima\\_i} and\n{\\em ima\\_error (= ref\\_image -- ima\\_i)} is calculated. For each scale, \nseveral results are given:\n\\begin{itemize}\n\\item the percentage of significant wavelet coefficients of {\\em ima\\_i}.\n\\item the correlation between the wavelet coefficients of {\\em ima\\_i}\nand {\\em ref\\_image}.\n\\item the standard deviation of absolute values of the wavelet coefficients of {\\em ima\\_error}.\n\\item the root mean square (RMS) of the wavelet coefficients of {\\em ima\\_error}.\n\\item the minimum value of the wavelet coefficients of {\\em ima\\_error}.\n\\item the maximum value of the wavelet coefficients of {\\em ima\\_error}.\n\\item the signal-to-noise ratio (SNR) using the wavelet coefficients of the\nreference image and those of the error image: \n\\[ SNR = \\frac{\\sigma^2(W_{ImaRef})}{\\sigma^2(W_{Error})}  \\]\n\\item the signal-to-noise ratio in dB (SNRb)\n\\[ SNRb = 10 log_{10}(SNR) \\]\n\\end{itemize}\n{\\bf\n\\begin{center}\nUSAGE: mr\\_compare option ref\\_ima ima1 [ima2, [ima3, ...]]\n\\end{center}}\nwhere options are \n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\nSee \\ref{sect_trans}. But only transforms 1 to 13 \n(isotropic transforms) are available.\n\\item {\\bf [-p]} \\\\\n\\item {\\bf [-g sigma]} \\\\\n\\item {\\bf [-c gain,sigma,mean]} \\\\\n\\item {\\bf [-n number\\_of\\_scales]} \n\\item {\\bf [-s NSigma]} \n\\end{itemize}\nThese options are the same as those described in \nsection \\ref{sect_support}.\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item mr\\_compare -n 1 image\\_ref.d ima\\_1.d ima\\_2.d \\\\\nComputes the images {\\em ima\\_1} and {\\em ima\\_2} to {\\em image\\_ref}\n\\  in the direct space only.\n\\item mr\\_compare -s 0. image\\_ref.d ima\\_1.d ima\\_2.d  \\\\\nComputes the images {\\em ima\\_1} and {\\em ima\\_2} to {\\em image\\_ref}\n\\ taking into account all wavelet coefficients.\n\\end{itemize}\n\n\n \n\n", "meta": {"hexsha": "8c62794b6ebc3fc50fc604dfe7e393aa509c9272", "size": 43594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/ch4_wave.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_mr1/ch4_wave.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_mr1/ch4_wave.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": 40.3648148148, "max_line_length": 120, "alphanum_fraction": 0.7320273432, "num_tokens": 12466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544825, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6314886843414947}}
{"text": "\\section{Risk-Neutral Policy Gradient Theorem}\nIn the previous sections, we saw that the core of a policy gradient algorithm consist in the approximation of the objective function gradient. In this section we present the \\emph{policy gradient theorem} \\cite{sutton1999policy}, which shows that the gradient can be rewritten in a form suitable for estimation from experience aided by an approximate action-value or advantage function. First, we will prove the theorem in the risk-neutral setting for which it was originally proposed. In particular, we will see how the GPOMDP algorithm can be easily derived by this result via a Monte Carlo approximation. Moreover, we will illustrate a class of actor-critic algorithms \\cite{konda1999actor} that, in addition to a parametric approximation of the policy, also exploit an approximation of the action-value function or of an advantage function to reduce the variance of the gradient estimate. In particular, we review the powerful idea of compatible function approximation \\cite{sutton1999policy} which assures the convergence to a local optimum of the objective function. Finally, we discuss the natural policy gradient idea \\cite{kakade2001natural}, which forms the basis of many state-of-the-art algorithms. The extension to the risk-sensitive setting will be done in the next chapter. \n\n\\subsection{Theorem Statement and Proof}\n\\begin{theorem}[Risk-Neutral 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}\n\\begin{proof}\n\tWe first prove the result for the average-reward formulation and then for the start state formulation. From the basic relation between state-value function and action-value function, we have\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta V_\\theta(s) &= \\nabla_\\theta \\int_{\\A} \\pi_\\theta(s,a) Q_\\theta(s,a) da\\\\\n\t\t\t\t&= \\int_{\\A} \\left[ \\nabla_\\theta \\pi_\\theta(s,a) Q_\\theta(s,a) + \\pi_\\theta(s,a) \\nabla_\\theta Q_\\theta(s,a)\\right] da\n\t\t\\end{split}\n\t\\end{equation*} \n\tUsing the Bellman expectation equation for $Q_\\theta$ \n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta Q_\\theta(s,a) &= \\nabla_\\theta \\left[ \\calR(s,a) - \\rho_\\theta + \\int_{\\S} \\calP(s,a,s') V_\\theta(s') ds' \\right]\\\\\n\t\t\t&= -\\nabla_\\theta \\rho_\\theta + \\int_{\\S} \\calP(s,a,s') \\nabla_\\theta V_\\theta(s') ds'\n\t\t\\end{split}\n\t\\end{equation*}\n\tHence, plugging in the first equation \n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta V_\\theta(s) &= \\int_{\\A} \\nabla_\\theta \\pi_\\theta(s,a) Q_\\theta(s,a) da - \\nabla_\\theta \\rho_\\theta + \\int_\\A \\pi_\\theta(s,a) \\int_{\\S} \\calP(s,a,s') \\nabla_\\theta V_\\theta(s') ds' \n\t\t\\end{split}\n\t\\end{equation*} \t\n\tIntegrating both sides with respect to the stationary distribution $d^\\theta$ and noting that, because of stationarity,  \n\t\\begin{equation*}\n\t\t\\int_{\\S} d^\\theta(s) \\int_{\\A} \\pi(s,a) \\int_{\\S} \\calP(s,a,s') \\nabla_\\theta V(s') ds' da ds = \\int_{\\S} d^\\theta(s) \\nabla_\\theta V_\\theta(s) ds\n\t\\end{equation*}\n\twe obtain the result \n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\\nabla_\\theta \\rho_\\theta &= \\int_{\\S} d^\\theta(s) \\int_{\\A} \\nabla_\\theta \\pi_\\theta(s,a) Q_\\theta(s,a) da ds\\\\\n\t\t&= \\int_{\\S} d^\\theta(s) \\int_{\\A} \\pi_\\theta(s,a) \\nabla_\\theta \\log\\pi_\\theta(s,a) Q_\\theta(s,a) da ds\\\\\n\t\t&= \\E[\\substack{S \\sim d^\\theta\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\t\t\t\\pi_\\theta(S,A) Q_{\\theta}(S, A)} \n\t\t\\end{split}\n\t\\end{equation*}\n\tLet us now prove the theorem for the start state formulation. The first step is exactly the same. Hence, using the Bellman expectation equation for $Q_\\theta$ \n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta Q_\\theta(s,a) &= \\nabla_\\theta \\left[ \\calR(s,a) + \\gamma \\int_{\\S} \\calP(s,a,s') V_\\theta(s') ds' \\right]\\\\ \n\t\t\t&= \\gamma \\int_{\\S} \\calP(s,a,s') \\nabla_\\theta V_\\theta(s') ds'\n\t\t\\end{split}\n\t\\end{equation*}\n\twe obtain\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta V_\\theta(s) &= \\int_{\\A} \\left[ \\nabla_\\theta \\pi_\\theta(s,a) Q_\\theta(s,a) + \\gamma \\int_{\\S} \\calP(s,a,s') \\nabla_\\theta V_\\theta(s') ds' \\right] da\\\\\n\t\t\t&= \\int_\\S  \\sum_{k=0}^{\\infty} \\gamma^k \\calP_\\theta^{(k)}(s, x) \\int_{\\A} \\nabla_\\theta \\pi_\\theta(x,a) Q_\\theta(x,a) da dx \n\t\t\\end{split}\n\t\\end{equation*} \n\tafter unrolling $\\nabla_\\theta V_\\theta$ infinite times and denoting by $\\calP_\\theta^{(k)}(s, x)$ the probability of going from state $s$ to state $x$ in $k$ steps under policy $\\pi_\\theta$.\n\tDefining the $\\gamma$-discounted visiting distribution of state $x$ starting from state $s$ as\n\t\\begin{equation*}\n\t\td_\\gamma^\\theta(s, x) = \\sum_{k=0}^{\\infty} \\gamma^k \\calP_\\theta^{(k)}(s, x)\n\t\\end{equation*}\n\twe have the result\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\nabla_\\theta V_\\theta(s) &= \\int_\\S d_\\gamma^\\theta(s, x) \\int_{\\A} \\nabla_\\theta \\pi_\\theta(x,a) Q_\\theta(x,a) da dx\\\\\n\t\t\t&= \\E[\\substack{S \\sim d_\\gamma^\\theta(s_0, \\cdot)\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log \\pi_\\theta(S,A) Q_{\\pi_\\theta}(S, A)}\n\t\t\\end{split}\n\t\\end{equation*} \n\\end{proof}\nThe action-value function is typically unknown and needs to be approximated. \nAs for the REINFORCE algorithm, 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, we can rewrite the policy gradient for the average reward formulation 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}\nand similarly for the start state formulation. This result can be used as the starting point to derive several policy gradient methods that use different approximation of the action-value function. \n\n\\subsection{GPOMDP}\nFor an episodic \\gls{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 \\gls{GPOMDP} gradient estimate (\\ref{eq:GPOMDP}). Therefore, the \\gls{GPOMDP} algorithm is a simple application of the policy gradient algorithm, which is much more general than the likelihood ratio technique used to derive the algorithm in the previous sections. In the next subsections we present other ways to exploit the policy gradient theorem to design efficient learning algorithms.\n\n\\subsection{Actor-Critic Policy Gradient}\nA baseline should ideally measure the typical return obtained by an agent in a certain state when following a certain policy. Therefore, it becomes natural to use the state-value function as a benchmark for the action-value function \\cite{grondman2012survey}. Eq. (\\ref{eq:pg_theorem_baseline}) thus becomes\n\\begin{equation}\n\\label{eq:actor_critic_pg}\n\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) A_\\theta(S,A)}\n\\end{equation} \nwhere we introduced the advantage function\n\\begin{equation}\n\tA_\\theta(s,a) = Q_\\theta(s,a) - V_\\theta(s)\n\\end{equation}\nwhich measures how good is to take action $a$ in state $s$ compared to simply following the policy $\\pi_\\theta$. The advantage function is unknown and should be estimated from samples of the \\gls{MDP}. \\emph{Actor-Critic} algorithms consist in all those methods that employ an approximation of the advantage function or of the value function, also known as critic, to estimate the policy gradient. These methods thus maintain two sets of parameters: a \\emph{critic} that updates the action-value function parameters $\\psi$ and an \\emph{actor} that updates the policy parameters $\\theta$ in the direction suggested by the critic. The general structure for an online actor-critic algorithm is reported in Algorithm \\ref{algo:actor_critic}.\\\\\n\\begin{algorithm}[t]\n\t\\caption{Generic structure for an online actor-critic algorithm}\n\t\\label{algo:actor_critic}\n\t\\begin{algorithmic}[0]\n\t\t\\Require{\\\\\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Initial actor parameters $\\theta_0$, \n\t\t\t\t\\item Initial critic parameters $\\psi_0$, \n\t\t\t\t\\item Learning rate $\\{\\alpha_k\\}$\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\\Repeat\n\t\t\t\\State Observe tuple $<s_k, a_k, r_{k+1}, s_{k+1}>$ sampled from the MDP.\n\t\t\t\\State Update critic parameters $\\psi_{k+1}$ using a value-based method. \n\t\t\t\\State Estimate policy gradient as $\\widehat{g}_k^\\text{AC} = \\nabla_\\theta \\log \\pi_{\\theta_k}(s_k, a_k) \\widehat{A}_{\\psi_{k+1}}(s_k, a_k)$\n\t\t\t\\State Update actor by gradient ascent $\\theta_{k+1} = \\theta_k + \\alpha_k \\widehat{g}_k^\\text{AC}$. \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}\nThere are two possible approaches to estimate the advantage function: the first one is to estimate both the state-value function $\\widehat{V}_\\psi \\approx V_\\theta$ and the action-value function $\\widehat{Q}_\\xi \\approx Q_\\theta$ and derive an estimate for the advantage function $\\widehat{A}_{\\psi, \\xi} = \\widehat{Q}_\\xi - \\widehat{V}_\\psi \\approx A_\\theta$. The second approach directly approximates the advantage function $\\widehat{A}_\\psi \\approx A_\\theta$ and is usually preferred, since it allows us to maintain only one critic. Actor-critic algorithms typically use a \\gls{TD} algorithm to update an approximation of the value function $\\widehat{V}_\\psi \\approx V_\\theta$, from which we can derive an approximation for the advantage function. Assume that the true state-value function $V_\\theta$ is given. Then the \\gls{TD} error \n\\begin{equation}\n\t\\delta_\\theta = R - \\rho_\\theta + V_\\theta(S') - V_\\theta(S)\n\\end{equation}\nis an unbiased estimate of the advantage function. Indeed \n\\begin{equation*}\n\t\\begin{split}\n\t\t\\E{\\delta_\\theta | S = s, A = a} &= \\E{R - \\rho_\\theta + V_\\theta(S') | S = s, A = a} - V_\\theta(s)\\\\\n\t\t&= Q_\\theta(s,a) - V_\\theta(s)\\\\\n\t\t&= A_\\theta(s,a)  \n\t\\end{split}\n\\end{equation*}\nBy a simple conditioning argument, the policy gradient can be rewritten as\n\\begin{equation}\n\t\\nabla_\\theta \\rho(\\theta) =\n\t\t\t\\E[\\substack{S \\sim d^\\theta\\\\A \\sim \\pi_\\theta}]{\\nabla_\\theta\\log\n\t\t\t\\pi_\\theta(S,A) \\delta_\\theta}\n\\end{equation} \nIn practice, we can use an approximate \\gls{TD} error \n\\begin{equation}\n\\label{eq:td_error}\n\t\\widehat{\\delta}_k = r_{k+1} - \\widehat{\\rho}_k + \\widehat{V}_{\\psi_k}(s_{k+1}) - \\widehat{V}_{\\psi_k}(s_k) \n\\end{equation}\nwhere $\\widehat{\\rho}_k$ is an estimate of the average reward. Hence, we can easily obtain an approximation of the policy gradient by\n\\begin{equation}\n\t\\widehat{g}_\\text{TD(0)}^k = \\nabla_\\theta\\log \\pi_\\theta(s_k,a_k) \\widehat{\\delta}_k\n\\end{equation}\nwhich can be used to update the critic parameter in the gradient ascent direction. \nOn the other hand, the critic parameters can be updated using a TD(0) temporal difference scheme\n\\begin{equation}\n\t\\psi_{k+1} = \\psi_k + \\alpha_k \\widehat{\\delta}_k \\nabla_\\psi \\widehat{V}_{\\psi_k}(s_k)\n\\end{equation}\nThe discussion can be easily extended to more complex value-based methods for estimating the critic, such as the backward-view TD($\\lambda$). This method employs eligibility traces to assign credit for the rewards obtained by the agent to all previous states and actions. More formally, the policy parameters update rule becomes\n\\begin{equation}\n\t\\theta_{k+1} = \\theta_k + \\alpha_k \\widehat{\\delta}_k e_k\n\\end{equation}\nwhere the eligibility trace $e_k$ is defined by the following recursive equation \n\\begin{equation}\n\te_{k+1} = \\lambda e_k + \\nabla_\\theta\\log \\pi_{\\theta_k}(s_k,a_k) \n\\end{equation} \n$0 \\leq \\lambda \\leq 1$ is a parameter that manages the amount of bootstrap: for $\\lambda = 0$ the method is the standard temporal difference scheme while for $\\lambda = 1$ the method is equivalent to Monte Carlo. In the rest of the thesis we will refer to this algorithm as \\gls{ARAC} and its pseudocode is reported in Algorithm \\ref{algo:actor_critic_td}. \n\\begin{algorithm}[t!]\n\t\\caption{Average-Reward Actor Critic}\n\t\\label{algo:actor_critic_td}\n\t\\begin{algorithmic}[0]\n\t\t\\Require{\\\\\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Initial actor parameters $\\theta_0$, \n\t\t\t\t\\item Initial critic parameters $\\psi_0$, \n\t\t\t\t\\item Learning rate $\\{\\alpha_k\\}$\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$ and the eligibility trace $e_{-1} = 0$\n\t\t\\Repeat\n\t\t\t\\State Observe tuple $<s_k, a_k, r_{k+1}, s_{k+1}>$ sampled from the MDP.\n\t\t\t\\State Compute TD error $\\widehat{\\delta}_k = r_{k+1} - \\widehat{\\rho}_k + \\widehat{V}_{\\psi_k}(s_{k+1}) - \\widehat{V}_{\\psi_k}(s_k) $\n\t\t\t\\State Update critic parameters $\t\\psi_{k+1} = \\psi_k + \\alpha_k \\widehat{\\delta}_k \\nabla_\\psi \\widehat{V}_{\\psi_k}(s_k)$ \n\t\t\t\\State Update eligibility trace $e_{k+1} = \\lambda e_k + \\nabla_\\theta\\log \\pi_{\\theta_k}(s_k,a_k)$\n\t\t\t\\State Update actor parameters $\\theta_{k+1} = \\theta_k + \\alpha_k \\widehat{\\delta}_k e_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\n\\subsection{Compatible Function Approximation}\nIn the previous sections we saw that a critic may reduce the variance of thew policy gradient estimate. However, this is achieved at the cost of introducing a bias in the approximation which, in certain cases, may endanger the convergence of the method to a good solution. Luckily, the \\emph{compatible function approximation}  \\cite{sutton1999policy} avoids introducing any bias by a careful choice of the critic. This technique consists in estimating the advantage function with a linear regression on a family of suitable basis functions consisting of the gradient of the likelihood score\n\\begin{equation}\n\t\\widehat{A}_\\theta (s,a) = \\psi^T \\nabla_\\theta \\log \\pi_\\theta(s,a)\n\\end{equation}\nThe power of these basis functions becomes apparent in the following theorem\n\\begin{theorem}[Compatible Function Approximation]\n\tIf \n\t\\begin{enumerate}[label={\\roman*)}]\n\t\t\\item the advantage function approximator is compatible to the policy\n\t\t\\begin{equation}\n\t\t\t\\nabla_\\psi A_\\psi(s,a) = \\nabla_\\theta \\log \\pi_\\theta(s,a)\n\t\t\\end{equation}\n\t\t\\item the advantage function parameters $\\psi$ minimize the mean square error \n\t\t\\begin{equation}\n\t\t\t\\theta = \\argmin_\\psi \\E[\\pi_\\theta]{\\left( A_{\\pi_\\theta}(S,A) - \\widehat{A}_\\psi(S,A)\\right)^2}\n\t\t\\end{equation}\n\t\\end{enumerate}\n\tThen the policy gradient is exact\n\t\\begin{equation}\n\t\t\\nabla_\\theta J(\\theta) = \\E[\\pi_\\theta]{\\nabla_\\theta \\log \\pi_\\theta(S,A) \\widehat{A}_\\psi(S,A)}\n\t\\end{equation}\n\\end{theorem} \nHence, the true advantage function in the policy gradient formula can be replaced by the compatible function approximation without changing the policy gradient value. A linear regression may seem a too simple representation of the advantage function. However, one must bear in mind that this approximation is only used to reduce the variance of the policy gradient estimate and should not be expected to provide an accurate representation of the true-value function. This technique has proved useful in many application. \n\n\\subsection{Natural Policy Gradient}\nDespite all the advances in the variance reduction techniques, these methods still tend to perform surprisingly poorly. Even when applied to simple examples with rather few states, where the gradient can be determined very accurately, they turn out to be quite inefficient. Typically, one of the reasons of this behavior is the presence of large plateaus in the expected return landscape where the gradients are small and often do not point directly towards the optimal solution. In this context, the steepest ascent with respect to the Fisher information metric, called the \\emph{natural policy gradient}, turns out to be significantly more efficient than normal gradients for such\nplateaus. This technique was first proposed in the reinforcement learning setting in \\cite{kakade2001natural} and later applied to actor-critic algorithms in in \\cite{peters2008reinforcement}. The following properties of natural policy gradient make it one of the more reliable policy-based methods,\n\\begin{enumerate}[label={\\roman*)}]\n\t\\item Convergence to a local minimum is guaranteed.\n\t\\item By choosing a more direct path to the optimal solution in parameter space, the natural gradient typically has faster convergence and avoids premature convergence of ``vanilla gradients''.\n\t\\item  The natural policy gradient can be shown to be covariant, or equivalently independent of the coordinate frame chosen for expressing the policy parameters.\n\t\\item As the natural gradient analytically averages out the influence of the stochastic policy (including the baseline of the function approximator), it requires fewer data points for a good gradient estimate than ``vanilla gradients’'.\n\\end{enumerate}\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=1\\linewidth]{Images/4_0_euclidean_vs_natural}\n\t\\caption[``Vanilla'' policy gradient vs. natural policy gradient.]{``Vanilla'' policy gradient (left) vs. natural policy gradient (right). The main difference is how the two approaches punish the change in parameters. This distance is \tindicated by the blue ellipses in the contour plot while the dashed lines show the expected return. Obtaining a gradient then corresponds to finding a vector pointing from the center of the ellipses to the location with maximum expected return on the ellipse. A vanilla policy gradient (a) considers a change in all parameters as equally distant, thus, it is a search for a maximum on a circle while the natural gradient (b) uses scales determined by the Fisher information which results in a reduction in exploration. The slower reduction in exploration results into a faster convergence to the optimal policy \\cite{peters2008reinforcement}.}\n\\end{figure}\n\n\\subsubsection{Formalism of Natural Policy Gradients}\nPolicy gradient methods improve the policy $\\pi_\\theta$ by iteratively applying ``small'' changes $\\Delta \\theta$ to the policy parameters $\\theta$. However, the meaning of ``small'' is ambiguous. For instance, when working with an Euclidean metric, the size of this update $\\norm{\\Delta \\theta} = \\sqrt{\\Delta\\theta^T \\Delta\\theta}$ and therefore the update size depends on the parameterization of the policy, which often results in unnaturally slow learning even if higher-order gradient methods were employed. This problem poses the question whether we can achieve a covariant gradient descent, meaning a gradient descent with respect to an invariant measure of the closeness between the current policy and the updated policy based upon the distribution of the paths generated by each of these. Standard measures of distance between probability distributions are the Kullbach-Leibler divergence $d_{\\text{KL}}(p_\\theta(h)\\ ||\\ p_{\\theta + \\Delta \\theta}(h))$ and the Hellinger distance. These two distances can be approximation in first instance by a second-order Taylor expansion\n\\begin{equation*}\n\td_{\\text{KL}}(p_\\theta(h)\\ ||\\ p_{\\theta + \\Delta \\theta}(h)) \\approx \\frac{1}{2} \\Delta\\theta^T F_\\theta \\Delta\\theta\n\\end{equation*} \nwhere $F_\\theta$ is the Fischer information matrix\n\\begin{equation}\n\t\\begin{split}\n\tF_\\theta &= \\int_{\\H} p_\\theta(h) \\nabla_\\theta\\log p_\\theta(h) \\nabla_\\theta\\log p_\\theta(h)^T dh\\\\\n\t\t&= \\E[H\\sim p_\\theta]{\\nabla_\\theta\\log p_\\theta(H) \\nabla_\\theta\\log p_\\theta(H)^T}\n\t\\end{split}\n\\end{equation}\nThe goal is to find the optimal update $\\Delta \\theta$ for the policy parameters so as to maximize the objective function, under the constraint that the new policy must be in a radius $\\epsilon$ from the previous policy with respect to the Kullbach-Leibler divergence\n\\begin{equation*}\n\t\\begin{cases}\n\t\t\\max_{\\Delta\\theta} J(\\theta + \\Delta \\theta) \\approx J(\\theta) + \\Delta \\theta^T \\nabla_\\theta J(\\theta)\\\\\n\t\t\\text{s.t.}\\ d_{\\text{KL}}(p_\\theta(h)\\ ||\\ p_{\\theta + \\Delta \\theta}(h)) \\approx \\frac{1}{2} \\Delta\\theta^T F_\\theta \\Delta\\theta < \\epsilon\\\\  \t\n\t\\end{cases}\n\\end{equation*}\nThe optimal solution is given by \n\\begin{equation*}\n\t\\Delta \\theta = \\alpha_n F_\\theta^{-1} \\nabla_\\theta J(\\theta)\n\\end{equation*}\nwith \n\\begin{equation*}\n\t\\alpha_n = \\sqrt{\\frac{\\epsilon}{\\nabla_\\theta J(\\theta)^T F_\\theta^{-1} \\nabla_\\theta J(\\theta)} }\n\\end{equation*}\nThe direction $\\widetilde{\\nabla}_\\theta J(\\theta) = \\Delta \\theta / \\alpha_n$ is called the natural gradient and learning algorithms that use this gradient instead of the standard one are called natural policy gradient algorithms. The strongest theoretical advantage of this approach is that its performance no longer depends on the parameterization of the policy and it is therefore safe to use for arbitrary policies. In practice, the learning process converges significantly faster in most practical cases and requires less manual parameter tuning of the learning algorithm. The only remaining point to discuss is how to compute the inverse of the Fischer information matrix. This is not an easy task and the matrix will usually need to be estimated from sample trajectories. However, we will see that this matrix can be computed analytically after reformulating the policy gradient theorem for the parameter-based search methods such as \\gls{PGPE}. The formal derivation will be presented in Chapter \\ref{ch:parameter_based_policy_gradient} and this result will lead to the \\gls{NPGPE} algorithm \\cite{miyamae2010natural}.  ", "meta": {"hexsha": "b8651df337406ff835961223bb5afcb6ee721840", "size": 22813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Chapters/4_3_Risk_Neutral_Policy_Gradient.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/4_3_Risk_Neutral_Policy_Gradient.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/4_3_Risk_Neutral_Policy_Gradient.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": 79.7657342657, "max_line_length": 1289, "alphanum_fraction": 0.7401481611, "num_tokens": 6721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6314655524449259}}
{"text": "\\documentclass[\n  xhtml,%\n  use filename%\n]{internet}\n\n\\usepackage{tutorial}\n\\usepackage{hyperref}\n\n\\title{Points and Lines}\n\\date{\\today}\n\\begin{document}\n\\maketitle\n\n\\section{Getting Started}\n\n\\begin{enumerate}\n\\item Log on to the computer and launch a web browser\n\\item Navigate to \\href{http://luacanvas.mathforge.org?project=Grid}{http://luacanvas.mathforge.org?project=Grid}\n\\item The big area in the centre of the screen is where you can type code (we call this the \\emph{editor} region).\nClicking on the box labelled \\verb+Execute+ will run your code.\nWhen your code is running, clicking on the box labelled \\verb+Edit+ will get you back to the editor.\n\n\\item There should be some code already in the editor.\nTry running it, you should see a coordinate grid drawn on the screen.\n\\end{enumerate}\n\n\\section{Adding Coordinates}\n\nAs in the \\href{Coordinates.xhtml}{Coordinates} tutorial, we will make considerable use of the \\verb+point+ command, so let's make the same alias.\nThat is, put \\verb+p=point+ in the \\verb+setup+ function (i.e.\\ after the line \\verb+function setup()+ and before the first \\verb+end+).\n\nWe'll also be adding some points, so we'll make a \\emph{table} to put them in and draw them on the grid, just as in the \\href{Coordinates.xhtml}{Coordinates} tutorial.\n\nYour code should be (I've put in one point just to check that it is working):\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={\n    p(1,2)\n  }\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    ellipse(v,.5)\n  end\nend\n\\end{verbatim}\n\nWe can now add points to our list and the program will display them on the screen.\nFeel free to change the colour.\nIf you want to change the size of the circle, you can do that as well; you shouldn't make it any bigger than \\(.5\\).\n\n\\section{Points on a Line}\n\nLet's pick a line and draw some points on that line.\nWe'll start with something simple to get the idea.\nLet's start with the line of points whose \\(y\\)--coordinate is \\(7\\).\nRemember that we write this line as ``\\(y = 7\\)''.\n\nThink up some points on that line and put them in the \\verb+points+ table.\nSo that line might read:\n\n\\begin{verbatim}\npoints={\n  p(1,7), p(2,7), p(7,7)\n}\n\\end{verbatim}\n\nNote the commas \\emph{between} the points.\nIt won't work if you forget them.\n\nIt's easy to see that these points all lie on the same line (assuming that you have typed in the coordinates of the points correctly).\nLet's be more ambitious.\nLet's now draw some points on the line ``\\(y = x + 1\\)''.\nRemember that this means ``The line of points whose \\(y\\)--coordinate is one more than their \\(x\\)--coordinate.''.\nAs a start, the point \\((2,3)\\) lies on this line.\nReplace your existing list by a list of points on this new line.\n\nYour code should look something like this, but with different points.\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={\n    p(2,3), p(4,5), p(7,8)\n  }\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    ellipse(v,.5)\n  end\nend\n\\end{verbatim}\n\nIf you are feeling confident, try doing this for the line \\(2 y = 3 x + 2\\).\nThink first how we interpret this equation as a description of the line and then think of some points that lie on it.\n\n\\section{Drawing a Line}\n\nIt is possible that in your list you made a mistake; when you run the code then you should be able to tell if one of the points is off the line or not.\nTry making a deliberate mistake to see the effect.\n\nWhen making a deliberate mistake, you probably made the difference very big.\nFor example, the point \\((2,-5)\\) does not lie on the line \\(y = x + 1\\) and very obviously so.\nBut mistakes don't have to be big to be mistakes, and because small ones can be harder to spot, their effect can be larger than it should be.\nFor the line \\(y = x + 1\\), try the points:\n\\((-18,-16)\\), \\((2,3)\\), \\((4,5)\\), and \\((7,8)\\).\nIs it really obvious that \\((-18,-16)\\) is off the line?\n\nOne way to resolve the matter is to draw the actual line.\nWe need two points to draw a line (when drawing on paper it is good to have a third point as a ``check'' but the computer is more reliable and only needs two).\nUnfortunately, while we are able to extend a line beyond the points, the computer will only draw the part of the line between the given points.\nSo we need to make sure that our points are wide apart.\nIt is allowed for the points to be ``off screen'', only the part on the screen will be drawn.\n\nTo draw the line \\(y = x + 1\\), we need a point off the bottom left of the screen.\nThe grid is set up so that the short direction goes from  \\(-20\\) to \\(20\\).\nTherefore, the point \\((-22,-21)\\), which lies on the line, is definitely off the bottom left of the screen.\nSimilarly, \\((21,22)\\), which is also on the line, is definitely off the top right.\nSo we can use these two points to draw our line.\nTo do this, we use the command \\verb+line(-22,-21,21,22)+.\nIf we put this \\emph{after} the loop which draws our points then it will be easier to see whether or not our points are on the line.\nWe need to decide on its colour and width\\begin{marginpar}The \\emph{width} is in pixels and is not affected by the grid scale.\\end{marginpar}.\nTo set the width, we write \\verb+strokeWidth(2)+, and for the colour we write \\verb+stroke(\"yellow\")+ (we can change the \\verb+2+ and \\verb+yellow+ if we want).\nThese need to go before the \\verb+line+ command but after the loop which draws our points.\n\nYour code should now look something like the following:\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={\n    p(2,3), p(4,5), p(7,8), p(-18,-16)\n  }\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    ellipse(v,.5)\n  end\n  strokeWidth(2)\n  stroke(\"yellow\")\n  line(-22,-21,21,22)\nend\n\\end{verbatim}\n\nIf you are feeling confident, try doing this for the line \\(2 y = 3 x + 2\\).\nYou might have to do a bit of thinking to find the right coordinates for the end points of your line.\n\n\\section{The Online Test}\n\nNow that we've drawn the line, it is obvious that the point \\((-18,-16)\\) does not lie on the line.\nBut if we changed it to \\((-18,-17.1)\\) then it's not so obvious.\nAnd if you think that it \\emph{is} obvious, try \\((-18,-17.01)\\).\n\nWhat we need is a \\emph{test} to decide whether or not a given point is on our line.\nThe equation of the line is exactly that.\nRemember that ``the line \\(y = x + 1\\)'' means ``the line of points whose \\(y\\)--coordinate is one more than their \\(x\\)--coordinate''.\nSo to test if a point is on the line we simply ask ``Is its \\(y\\)--coordinate equal to one more than its \\(x\\)--coordinate?''.\nIf the answer is yes, it is on the line; if no, it isn't.\n\nSo we want to translate the question ``Is its \\(y\\)--coordinate equal to one more than its \\(x\\)--coordinate?'' into something that a computer can understand.\nComputers don't think\\begin{marginpar}Computers don't think at all.  But it's a useful turn of phrase.\\end{marginpar} in terms of questions.\nThey think in terms of \\emph{tests}.\nWe run a test on a point and either the test is \\emph{true} or \\emph{false}.\n\nThe test we want is to see if the \\(y\\)--coordinate is equal to the \\(x\\)--coordinate plus one.\nThis is a slightly different meaning of ``equals'' than when we say ``let \\(b = 3\\)''.\nIn Lua, an equality \\emph{test} is written with a double equals sign \\verb+==+ (that's two equals signs next to each other).\nSo to test if the point \\verb+v+ is on the line we would write:\n\n\\begin{verbatim}\nif v.y == v.x + 1 then\n\\end{verbatim}\n\nNote that to get at the \\(y\\)--coordinate of the point \\verb+v+ we write \\verb+v.y+ and to get at the \\(x\\)--coordinate we write \\verb+v.x+. \n\nThis is the start of the test, what we write next is what to do if the test is \\emph{true}.\nFor example, we could change the colour of the dot:\n\n\\begin{verbatim}\nif v.y == v.x + 1 then\n  fill(\"yellow\")\nend\n\\end{verbatim}\n\nThe trouble with this is that once the condition is true for one point, the colour gets changed and stays changed.\nWe need to set it to something else if the test fails.\nTo do that we use the word \\verb+else+.\n\n\\begin{verbatim}\nif v.y == v.x + 1 then\n  fill(\"yellow\")\nelse\n  fill(\"cyan\")\nend\n\\end{verbatim}\n\nThe meaning of this is as follows.\nThe test is checked, if it is true then the colour is set to yellow; if it is false then it is set to cyan.\n\nWe put this inside our loop before the ellipse command.\nThus our code will look something like the following.\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={\n    p(2,3), p(4,5), p(7,8), p(-18,-17.01)\n  }\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    if v.y == v.x + 1 then\n      fill(\"cyan\")\n    else\n      fill(\"fuchsia\")\n    end\n    ellipse(v,.5)\n  end\n  strokeWidth(2)\n  stroke(\"yellow\")\n  line(-22,-21,21,22)\nend\n\\end{verbatim}\n\nYou can try this for other lines as well.\n\n\\section{The Line Challenge}\n\nIt's a bit tedious to be typing in the set of points each time.\nOne way to make that a bit easier is to use the mouse to click on the grid and assemble the points that way.\nWhen you click on the screen, the information about the click is passed to the program in a very special way.\nTo get the click coordinates we need to type a new block of code at the very end of what we have so far:\n\n\\begin{verbatim}\nfunction touched(t)\n  if t.state == ENDED then\n    table.insert(points,p(t))\n  end\nend\n\\end{verbatim}\n\nThis won't work.\nThe problem is that the information about the mouse click uses coordinates relative to the screen and measured in pixels.\nIt doesn't know about our grid.\nFortunately, we do and our grid knows how to convert the coordinates.\nSo what we actually want is:\n\n\\begin{verbatim}\nfunction touched(t)\n  if t.state == ENDED then\n    table.insert(points,g:invtransform(t))\n  end\nend\n\\end{verbatim}\n\nThis rounds to the nearest grid square.\nIf you want to allow more precision, replace \\verb+g:invtransform(t)+ with \\verb+g:invtransform(t,1)+.\n\nOur complete code is now:\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={\n    p(2,3), p(4,5), p(7,8), p(-18,-17.01)\n  }\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    if v.y == v.x + 1 then\n      fill(\"cyan\")\n    else\n      fill(\"fuchsia\")\n    end\n    ellipse(v,.5)\n  end\n  strokeWidth(2)\n  stroke(\"yellow\")\n  line(-22,-21,21,22)\nend\n\nfunction touched(t)\n  if t.state == ENDED then\n    table.insert(points,g:invtransform(t,1))\n  end\nend\n\\end{verbatim}\n\nWhat you can do now is make a challenge for a friend.\nChoose a new equation of a line\n(don't make it too complicated first time round).\nClear out the points from the \\verb+points+ table, remove the code that actually draws the line, and change the test so that it matches your line not \\(y = x + 1\\) (remember to use the double equals sign).\n\nSo your code should look like the following, only with a different test:\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  p=point\n  points={}\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  fill(\"cyan\")\n  noStroke()\n  for k,v in ipairs(points) do\n    if v.y == v.x + 1 then\n      fill(\"cyan\")\n    else\n      fill(\"fuchsia\")\n    end\n    ellipse(v,.5)\n  end\nend\n\nfunction touched(t)\n  if t.state == ENDED then\n    table.insert(points,g:invtransform(t))\n  end\nend\n\\end{verbatim}\n\nNow start the code and challenge a friend to discover the equation of your line by finding points on it.\n\n\\section{Some Extras}\n\nHere are some ideas on how to take things further.\n\n\\begin{itemize}\n\\item In the challenge game, have a button that if pressed draws the line.\nTo create such a button, put the following in the \\verb+setup+ function:\n\n\\begin{verbatim}\nparameter.boolean(\"Draw line\",\"doline\",false)\n\\end{verbatim}\n\nThis creates a \\emph{boolean} called \\verb+doline+.\nA boolean is a special variable that is either \\emph{true} or \\emph{false}.\nIt can be used in a test, so you can write:\n\n\\begin{verbatim}\nif doline then\n  ...\nend\n\\end{verbatim}\n\nThe code in the middle is used if \\verb+doline+ is true, but is ignored if not.\n\n\\item You might also want to be able to clear the table of points.\nYou can create a button that does this.\nIn the \\verb+setup+ function write:\n\n\\begin{verbatim}\nparameter.action(\"Clear points\",function() points = {} end) \n\\end{verbatim}\n\n\\item If you want to draw more than one line, you could make a table of lines.\nFor each line, you might want some points on it, a colour, the end points for drawing it, and even a test function for whether a point is on the line.\nYou might have something like:\n\n\\begin{verbatim}\nlines = {\n  {\n    colour = colour(\"yellow\"),\n    points = {p(1,2), p(3,4), p(7,8)},\n    ends = {p(-22,-21),p(21,22)},\n    test = function(c) return c.y == c.x + 1 end\n  },\n  {\n    colour = colour(\"cyan\"),\n    points = {p(2,4), p(4,7), p(0,1)},\n    ends = {p(-20,-29),p(20,31)},\n    test = function(c) return 2*c.y == 3*c.x + 2 end\n  },\n}\n\\end{verbatim}\n\nThen in the \\verb+draw+ function, we need to iterate over the lines first.\n\n\\begin{verbatim}\nfor l,u in ipairs(lines) do\n  noStroke()\n  fill(u.colour)\n  for k,v in ipairs(u.points) do\n    ellipse(v,.5)\n  end\n  stroke(u.colour)\n  strokeWidth(2)\n  line(u.ends[1],u.ends[2])\nend\n\\end{verbatim}\n\nFor testing points from the mouse, we could do:\n\n\\begin{verbatim}\nfor k,v in ipairs(points) do\n  fill(\"green\")\n  for l,u in ipairs(lines) do\n    if u.test(v) then\n      fill(u.colour)\n    end\n  end\n  ellipse(v,.5)\nend\n\\end{verbatim}\n\\end{itemize}\n\nPutting all that together, our full code looks like:\n\n\\begin{verbatim}\nfunction setup()\n  g=Grid(20,5)\n  parameter.action(\"Clear points\",function() points = {} end)\n  parameter.boolean(\"Draw lines\",\"doline\",false)\n  p=point\n  lines = {\n    {\n      colour = colour(\"yellow\"),\n      points = {p(1,2), p(3,4), p(7,8)},\n    \tends = {p(-22,-21),p(21,22)},\n      test = function(c) return c.y == c.x + 1 end\n    },\n    {\n      colour = colour(\"cyan\"),\n      points = {p(2,4), p(4,7), p(0,1)},\n      ends = {p(-20,-29),p(20,31)},\n      test = function(c) return 2*c.y == 3*c.x + 2 end\n    },\n\t}\n  points={}\nend\n\nfunction draw()\n  background(40,40,50)\n  g:draw()\n  for l,u in ipairs(lines) do\n    noStroke()\n    fill(u.colour)\n    for k,v in ipairs(u.points) do\n      ellipse(v,.5)\n    end\n    if doline then\n      stroke(u.colour)\n      strokeWidth(2)\n      line(u.ends[1],u.ends[2])\n    end\n  end\n  noStroke()\n  for k,v in ipairs(points) do\n    fill(\"green\")\n    for l,u in ipairs(lines) do\n      if u.test(v) then\n        fill(u.colour)\n      end\n    end\n    ellipse(v,.5)\n  end\nend\n\nfunction touched(t)\n  if t.state == ENDED then\n    table.insert(points,g:invtransform(t))\n  end\nend\n\\end{verbatim}\n\n\\end{document}\n", "meta": {"hexsha": "ccf2bff6b299a2b6ab9982b1ceafff05398acc5c", "size": 14854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lines.tex", "max_stars_repo_name": "loopspace/jsCanvas-Tutorials", "max_stars_repo_head_hexsha": "7bff26820a9fd3aa3b5abcb7584dd3ca37577054", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lines.tex", "max_issues_repo_name": "loopspace/jsCanvas-Tutorials", "max_issues_repo_head_hexsha": "7bff26820a9fd3aa3b5abcb7584dd3ca37577054", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lines.tex", "max_forks_repo_name": "loopspace/jsCanvas-Tutorials", "max_forks_repo_head_hexsha": "7bff26820a9fd3aa3b5abcb7584dd3ca37577054", "max_forks_repo_licenses": ["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.5896414343, "max_line_length": 205, "alphanum_fraction": 0.6883667699, "num_tokens": 4261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6314655377712823}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} \\label{exer-linear-transf2}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & -1 & 2 \\\\\n1 & -2 & 1 \\\\\n3 & -4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-3\\hat{t} \\\\\n-\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} ,\\hat{t}_{3}\\in \\R$ . A basis for the solution space is $\n\\begin{mymatrix}{r}\n-3 \\\\\n-1 \\\\\n1\n\\end{mymatrix}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf2} find the general solution to the following\nlinear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & -1 & 2 \\\\\n1 & -2 & 1 \\\\\n3 & -4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n4\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nNote that this has the same matrix as the above problem. Solution is: $%\n\\begin{mymatrix}{r}\n-3\\hat{t}_{3} \\\\\n-\\hat{t}_{3} \\\\\n\\hat{t}_{3}\n\\end{mymatrix} +\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n0\n\\end{mymatrix}$, $\\hat{t}_{3}\\in \\R$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf3}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & -1 & 2 \\\\\n1 & -2 & 1 \\\\\n1 & -4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{c}\n3\\hat{t} \\\\\n2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix}$, A basis is $\\begin{mymatrix}{c}\n3 \\\\\n2 \\\\\n1\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf3} find the general solution to the following\nlinear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & -1 & 2 \\\\\n1 & -2 & 1 \\\\\n1 & -4 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{c}\n3\\hat{t} \\\\\n2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} +\\begin{mymatrix}{r}\n-3 \\\\\n-1 \\\\\n0\n\\end{mymatrix}$, $\\hat{t}\\in \\R$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf4}Write the solution set of the following system as a linear combination of vectors.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & -1 & 2 \\\\\n1 & -2 & 0 \\\\\n3 & -4 & 4\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-4\\hat{t} \\\\\n-2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix}$. A basis is $\\begin{mymatrix}{r}\n-4 \\\\\n-2 \\\\\n1\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf4} find the general solution to the\nfollowing linear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n1 & -1 & 2 \\\\\n1 & -2 & 0 \\\\\n3 & -4 & 4\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n4\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-4\\hat{t} \\\\\n-2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} +\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n0\n\\end{mymatrix}$, $\\hat{t}\\in \\R$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf5}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & -1 & 2 \\\\\n1 & 0 & 1 \\\\\n1 & -2 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-\\hat{t} \\\\\n2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} ,\\hat{t}\\in \\R$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf5} find the general solution to the\nfollowing linear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & -1 & 2 \\\\\n1 & 0 & 1 \\\\\n1 & -2 & 5\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n-1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-\\hat{t} \\\\\n2\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} +\\begin{mymatrix}{r}\n-1 \\\\\n-1 \\\\\n0\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf6}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 0 & 1 & 1 \\\\\n1 & -1 & 1 & 0 \\\\\n3 & -1 & 3 & 2 \\\\\n3 & 3 & 0 & 3\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n0 \\\\\n-\\hat{t} \\\\\n-\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix}$, $\\hat{t}\\in \\R$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf6} find the general solution to the\nfollowing linear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 0 & 1 & 1 \\\\\n1 & -1 & 1 & 0 \\\\\n3 & -1 & 3 & 2 \\\\\n3 & 3 & 0 & 3\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n4 \\\\\n3\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n0 \\\\\n-\\hat{t} \\\\\n-\\hat{t} \\\\\n\\hat{t}\n\\end{mymatrix} +\\begin{mymatrix}{r}\n2 \\\\\n-1 \\\\\n-1 \\\\\n0\n\\end{mymatrix} $\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf7}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n2 & 1 & 1 & 2 \\\\\n1 & 0 & 1 & 1 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{c}\n-s-t \\\\\ns \\\\\ns \\\\\nt\n\\end{mymatrix} ,s,t\\in \\R$. A basis is\n\\[\n\\set{\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{r}\n-1 \\\\\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} }\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf7} find the general solution to the\nfollowing linear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n2 & 1 & 1 & 2 \\\\\n1 & 0 & 1 & 1 \\\\\n0 & -1 & 1 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{array}r\n} =\\begin{mymatrix}{r}\n2 \\\\\n-1 \\\\\n-3 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is:\n\\[\n\\begin{mymatrix}{r}\n-\\hat{t} \\\\\n\\hat{t} \\\\\n\\hat{t} \\\\\n0\n\\end{mymatrix} +\\begin{mymatrix}{r}\n-8 \\\\\n5 \\\\\n0 \\\\\n5\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf8}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n1 & -1 & 1 & 0 \\\\\n3 & 1 & 1 & 2 \\\\\n3 & 3 & 0 & 3\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is:\n\\[\n\\begin{mymatrix}{c}\n-\\frac{1}{2}s-\\frac{1}{2}t \\\\\n\\frac{1}{2}s-\\frac{1}{2}t \\\\\ns \\\\\nt\n\\end{mymatrix}\n\\]\nfor $s,t\\in \\R$. A basis is\n\\[\n\\set{\\begin{mymatrix}{r}\n-1 \\\\\n1 \\\\\n2 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n-1 \\\\\n1 \\\\\n0 \\\\\n1\n\\end{mymatrix} }\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf8} find the general solution to the following\nlinear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n1 & -1 & 1 & 0 \\\\\n3 & 1 & 1 & 2 \\\\\n3 & 3 & 0 & 3\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n4 \\\\\n3\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is:\n\\[\n\\begin{mymatrix}{r}\n\\frac{3}{2} \\\\\n-\\frac{1}{2} \\\\\n0 \\\\\n0\n\\end{mymatrix} +\\begin{mymatrix}{c}\n-\\frac{1}{2}s-\\frac{1}{2}t \\\\\n\\frac{1}{2}s-\\frac{1}{2}t \\\\\ns \\\\\nt\n\\end{mymatrix}\n\\]\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} \\label{exer-linear-transf9}Write the solution set of the following system as a linear combination of vectors\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n2 & 1 & 1 & 2 \\\\\n1 & 0 & 1 & 1 \\\\\n0 & -1 & 1 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n0 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-\\hat{t} \\\\\n\\hat{t} \\\\\n\\hat{t} \\\\\n0\n\\end{mymatrix}$, a basis is $\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix}$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Using Problem~\\ref{exer-linear-transf9} find the general solution to the following\nlinear system.\n\\begin{equation*}\n\\begin{mymatrix}{rrrr}\n1 & 1 & 0 & 1 \\\\\n2 & 1 & 1 & 2 \\\\\n1 & 0 & 1 & 1 \\\\\n0 & -1 & 1 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\nx \\\\\ny \\\\\nz \\\\\nw\n\\end{mymatrix} =\\begin{mymatrix}{r}\n2 \\\\\n-1 \\\\\n-3 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\\begin{sol}\nSolution is: $\\begin{mymatrix}{r}\n-\\hat{t} \\\\\n\\hat{t} \\\\\n\\hat{t} \\\\\n0\n\\end{mymatrix} +\\begin{mymatrix}{r}\n-9 \\\\\n5 \\\\\n0 \\\\\n6\n\\end{mymatrix} ,t\\in \\R$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $A\\vect{x}=\\vect{b}$ has a solution. Explain why the solution is\nunique precisely when $A\\vect{x}=\\vect{0}$ has only the trivial solution.\n\\vspace{1mm}\n\\begin{sol}\nIf not, then there would be a infinitely many solutions to $A\\vect{x}=\\vect{0}$\nand each of these added to a solution to $A\\vect{x}=\\vect{b}$ would be a solution\nto $A\\vect{x}=\\vect{b}$.\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "e1cdc42576427a482f2b9e1cc3aedc324c759662", "size": 8952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/LinearTransformations-GeneralSolution.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-GeneralSolution.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-GeneralSolution.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": 16.4256880734, "max_line_length": 120, "alphanum_fraction": 0.6089142091, "num_tokens": 3867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6314655319991733}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrrspwv}\n\\section*{\\hspace*{-1.6cm} tfrrspwv}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nReassigned smoothed pseudo Wigner-Ville distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,rtfr,hat] = tfrrspwv(x) \n[tfr,rtfr,hat] = tfrrspwv(x,t) \n[tfr,rtfr,hat] = tfrrspwv(x,t,N) \n[tfr,rtfr,hat] = tfrrspwv(x,t,N,g) \n[tfr,rtfr,hat] = tfrrspwv(x,t,N,g,h) \n[tfr,rtfr,hat] = tfrrspwv(x,t,N,g,h,trace) \n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrrspwv} computes the smoothed pseudo Wigner-Ville\n        distribution and its reassigned version. These distributions are\n        given by the following expressions\\,:\n\\begin{eqnarray*}\n\\hspace*{-2cm}SPWV_x(t,\\nu;g,h)&=&\\int_{-\\infty}^{+\\infty} h(\\tau)\\\n\\int_{-\\infty}^{+\\infty} g(s-t)\\ x(s+\\tau/2)\\ x^*(s-\\tau/2)\\ ds\\ e^{-j2\\pi\n\\nu \\tau}\\ d\\tau\\\\\n\\hspace*{-2cm}SPWV_x^{(r)}(t',\\nu';g,h)&=&\\iint_{-\\infty}^{+\\infty}\nSPWV_x(t,\\nu;g,h)\\ \\delta(t'-\\hat{t}(x;t,\\nu))\\\n\\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\ dt\\ d\\nu,\n\\end{eqnarray*}\nwhere \n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu)= t-\\dfrac{SPWV_x(t,\\nu;\\ens{T}_g,h)}\n{2\\pi\\ SPWV_x(t,\\nu;g,h)}\\\\ \n\\hat{\\nu}(x;t,\\nu)=\\nu+j\\dfrac{SPWV_x(t,\\nu;g,\\ens{D}_h)}\n{2\\pi\\ SPWV_x(t,\\nu;g,h)}\n\\end{eqnarray*}\nwith $\\ens{D}_h(t)=\\frac{dh}{dt}(t)$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)}) \\\\\n        {\\ty t}     & the time instant(s)      & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty g}     & time smoothing window, {\\ty G(0)} being forced to {\\ty 1}, where {\\ty G(f)} is the Fourier transform of {\\ty g(t)}\n                                         & {\\ty window(odd(N/10))}\\\\ \n        {\\ty h}     & frequency smoothing window, {\\ty h(0)} being forced to {\\ty 1}\n                                         & {\\ty window(odd(N/4))}\\\\\n\\hline \\end{tabular*} \\end{minipage}\n\n\\newpage\n\n\\hspace*{1.5cm} \\begin{minipage}[t]{13.5cm}\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\ \\hline\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n\\hline  {\\ty tfr, rtfr} & time-frequency representation and its reassigned\n               version. \\\\\n        {\\ty hat}   & complex matrix of the reassignment vectors\\\\\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrrspwv} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.05,0.15)+fmlin(128,0.3,0.4); \n         g=window(15,'Kaiser'); h=window(63,'Kaiser');  \n         tfrrspwv(sig,1:128,64,g,h,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and\nTime-Scale Representations by the Reassignment Method'' IEEE Transactions\non Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.\n\\end{minipage}\n", "meta": {"hexsha": "4400a5264ae99090786f22bc6647047b0eaa6109", "size": 3597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrrspwv.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrrspwv.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrrspwv.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 32.1160714286, "max_line_length": 136, "alphanum_fraction": 0.6018904643, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7154240018510025, "lm_q1q2_score": 0.6313100821998988}}
{"text": "\\chapter{Physics}\r\n\\section{Basic Laws}\r\n{\\bf Classical Physics:}\r\n${\\vec F}= {\\frac {d{\\vec p}} {dt}}$, \r\n${\\vec p}= m{\\vec v}$,\r\n$m= {\\frac {m_{0}} {\\sqrt {1 - ({\\frac {v}{c}})^{2}}}}$,\r\n$F= -G {\\frac {m_{1} m_{2} } {{r_{12} }^{2} }}$.  For conservative\r\nforces, there is a potential function $U(x,y,z)$ and the force in $w$ direction is\r\n$F= - {\\frac {\\partial U} {\\partial w}}$.\r\n${\\vec F}= q ( {\\vec E} + {\\vec v} \\times {\\vec B} )$.  $E= - \\nabla V$ ($V$ corresponds\r\nto work done by $E$ per unit charge or $U/q$).\r\n\\\\\r\n\\\\\r\n{\\bf Special Relativity:}\r\nPrimed (') coordinate system is moving at constant velocity $u$ in the $x$ \r\ndirection with respect to the unprimed system; put $\\gamma= {\\frac 1\r\n{\\sqrt {1-{\\frac {u^2} {c^2}}}}}$. The \\emph{Lorentz transform} is\r\n$x'= \\gamma (x-ut)$,\r\n$y'= y$, $z'= z$, $t'= \\gamma (t-{\\frac {ux} {c^2}})$. Newton's law, $F= {\\frac {dp} {dt}}$, \r\nremains invariant under the Lorentz transform, that is,\r\n${\\frac {dp} {dt}}= {\\frac {dp'} {dt'}}$.\r\nMaxwell's equations are also invariant under\r\nthe Lorentz transform.\r\nThe energy-momentum four-vector is\r\n$(cp_x, cp_y, cp_z, E) $ and its squared\r\nlength is $(cp_x)^2+(cp_y)^2+(cp_z)^2-E^2$.  It transforms like\r\n$p_x'= \\gamma (p_x-E \\beta/c)$,\r\n$p_y'= p_y$,\r\n$p_z'= p_z$,\r\n$E'= \\gamma (E-\\beta c p_x)$, where $\\beta= {\\frac {u} {c}}$.\r\nThe length of the energy-momentum four-vector\r\nis invariant under the Lorentz transform.\r\n$E^{2} - (p c)^{2} = { (m_0 c^{2} ) }^{2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Maxwell's Equations (MKS):}\r\n$\\nabla \\cdot {\\vec j} = - {\\frac {\\partial \\rho} {\\partial t}}$,\r\n$\\nabla \\cdot {\\vec E} = {\\frac {\\rho} {\\epsilon_{0}}}$,\r\n$\\nabla \\times {\\vec E} = - {\\frac {\\partial {\\vec B}}{\\partial t}}$,\r\n$\\nabla \\cdot {\\vec B} = 0$,\r\n${c^{2}} \\nabla \\times {\\vec B} = {\\frac {j} {\\epsilon_{0}}} +\r\n{\\frac {\\partial {\\vec E}} {\\partial t}}$, $c= {\\frac 1 {\\sqrt { \\mu_0 \\epsilon_0}}}$.\r\n$S= \\epsilon_0 c^2 E \\times B$.\r\n\\\\\r\nIn \\emph{non-dispersive media}, ${\\vec D} = \\epsilon {\\vec B} $ and ${\\vec H} = \\mu {\\vec B}$.\r\n\\\\\r\n\\\\\r\n{\\bf Maxwell solution outline:} \r\nMaxwell's equations give $\\nabla \\times (E+{\\frac {\\partial A} {\\partial t}})= 0$, choosing\r\ngauge \r\n$\\nabla \\cdot A= -{\\frac 1 {c^2}} {\\frac {\\partial \\phi} {\\partial t}}$, we get\r\n$\\nabla^2 \\phi - {\\frac 1 {c^2}} {\\frac {\\partial^2 \\phi} {{\\partial t}^2}} = - {\\frac\r\n{\\rho} {\\epsilon_0}}$.  We obtain a similar equation in terms of $A$ and $j$ .  Both are of\r\nthe form\r\n$$\\nabla^2 \\psi(r,t)- {\\frac 1 {c^2}} {\\frac {\\partial^2 \\psi} {{\\partial t}^2}}= -s$$\r\nLet $r^2=x^2+y^2+z^2$. $\\nabla^2 \\psi(r) = \\psi''(r) + {\\frac 2 r} \\psi'(r)$ or\r\n$\\nabla^2 \\psi = {\\frac 1 r} {\\frac {d^2} {dt^2}} (r \\psi)$.  If $s=0$,\r\n${\\frac {d^2} {dr^2}} (r \\psi) - {\\frac 1 {c^2}} {\\frac {\\partial^2}{{\\partial t}^2}} (r \\psi) = 0$\r\nand the solution is $\\psi(r,t)= {\\frac {f(t-{\\frac r c})} r}$.  Recall electrostatic\r\nanalogy: $\\nabla^2 \\phi= -{\\frac {\\rho} {\\epsilon_0}}$, then $\\phi= {\\frac 1 {4 \\pi \\epsilon_0}}\r\n{\\frac q r}$ where $q= \\int \\rho dV$.  \r\nThus $\\psi(r,t)= {\\frac {f(t)} r}$ as $r \\rightarrow 0$.\r\nIf $S(t) = \\int s(t) dV$ and $\\psi$ satisfies $\\nabla^2 \\psi= -s$ as $r \\rightarrow 0$ then\r\n$\\psi$ satisfies $\\nabla^2 \\psi - {\\frac 1 {c^2}} {\\frac {\\partial^2} {{\\partial t}^2}} \\psi= -s$.\r\nWe have $\\psi(x,y,z,t)= {\\frac 1 {4 \\pi}} {\\frac {S(t-r/c)} r}$.  So for a small\r\nlump of charge, $d \\psi(r,t) = {\\frac 1 {4 \\pi \\epsilon_0}} {\\frac {\\rho(2,t-r_{12}/c)}\r\n{r_{12}}} dV_2$.  For small charges travelling at velocity $v$,\r\n$\\psi(r,t)= {\\frac 1 {4 \\pi \\epsilon_0}} {\\frac q {r_{12}'}} {\\frac 1 {1- v_{r'}/c}}$.\r\nSolving gives Feynman's solution,\r\n$E= {\\frac {-q} {4 \\pi \\epsilon_{0}}} ({\\frac {e_{r'}} {r'^2}}+\r\n{\\frac {r'} {c}} {\\frac {d} {dt}}{\\frac {e_{r'}} {r'^2}} +\r\n{\\frac {1} {c^{2}}} {\\frac {d^{2}} {{dt}{^2}}}(e_{r'}))$,\r\n$E=cB$.\r\n$A'= A + \\nabla \\psi$ $\\phi'= \\phi - {\\frac {\\partial \\psi} {\\partial t}}$\r\nis a \\emph{gauge transformation}.  Solving equations produces\r\n$\\phi (1,t) = \\int {\\frac {\\rho (2,t - (r/c))}{4 \\pi \\epsilon_{0} r_{12}}} dV$, and\r\n$A(1,t) = \\int {\\frac {j(2,t - (r/c))}{ 4 \\pi \\epsilon_{0} c^{2} r_{12}}} dV $.\r\n$\\phi(1,t)= {\\frac q {4 \\pi \\epsilon_0 r' (1- {\\frac {v_{\\small{ret}}} c})}}$\r\n(\\emph{Lenart-Weichart}) at high velocities.\r\n\\\\\r\n\\\\\r\n{\\bf Waves in conductor:}  For a conductor, $\\rho= 0$ and $J= \\sigma E$.\r\n$\\nabla \\times (\\nabla \\times {\\vec E}) = \r\n- {\\frac {\\partial ({\\nabla \\times \\vec B})}{\\partial t}}$. \r\n$\\nabla \\times (\\nabla \\times {E}) = \\nabla (\\nabla \\cdot E) - \\nabla^2 E$, and\r\n$- {\\frac {\\partial {(\\nabla \\times \\vec B)}}{\\partial t}}=\r\n-{\\frac 1 {c^2}} (\r\n{\\frac {\\sigma}{\\epsilon}}\r\n{\\frac {\\partial E} {\\partial t}} +\r\n{\\frac {\\partial^2 E} {\\partial t^2}})$.  Apply trial solution\r\n$E= E_0 e^{i(\\omega t - k \\cdot r)}$ and get \r\n$-k^2 - i \\omega \\mu \\sigma + \\omega^2 \\mu \\epsilon = 0$.  \r\nPutting $k= \\alpha- i \\beta$,\r\nwe get $\\alpha = \\omega \\sqrt{\\mu \\epsilon} ( {\\frac 1 2} +\r\n{\\frac 1 2} \\sqrt{1+ {\\frac {\\sigma^2} {\\omega^2 \\epsilon^2}}})$ and\r\n$\\beta= {\\frac {\\omega \\mu \\sigma} {2 \\alpha}}$. So,\r\n$E= E_0 e^{i(\\omega t - \\alpha \\cdot r)} e^{- \\beta \\cdot r}$.  For copper,\r\n$\\sigma \\approx 5.76 \\times 10^7 (\\Omega-m)^{-1})$.\r\n\\\\\r\n\\\\\r\n{\\bf Radiation from point charge:}  For a, charge $q$, accelerating at ${\\vec a}(t')$,\r\n$t'= t- r/c$, at low velocity,\r\n$E_{\\small{rad}}({\\vec r}, t)= \r\n-{\\frac 1 {4 \\pi \\epsilon_0 c^2}} {\\frac {q} {r}} {\\vec a}_{\\perp}(t')$.\r\n$cB=E$ and $|S|= {\\frac 1 {\\mu_0}} |E \\times B|$ so\r\n$|S|= {\\frac 1 {16 \\pi^2 \\epsilon_0 c^3}} \r\n{\\frac {q^2} {r^2}} |{\\vec a}(t')|^2 sin^2(\\theta(t'))$.  Since\r\n$dP(r,t)= |S| dA$, the total radiated power is\r\n$P(t)= {\\frac {a^2(t') q^2} {4 \\pi \\epsilon_0 c^3}} \\int_{\\small{sphere}}\r\n{\\frac 1 {4 \\pi r^2}} sin^2(\\theta(t')) dA$.\r\n${\\frac {dA}{4 \\pi r^2}} = sin(\\theta) d \\theta d \\phi$ in polar coordinates.\r\nSo $P(t)= \r\n{\\frac 1 {4 \\pi \\epsilon_0 c^3}} q^2 a^2(t') {\\overline {sin^2(\\theta(t'))}}$ where\r\n${\\overline {sin^2(\\theta(t'))}}= \\int_{\\small {sphere}} sin^2(\\theta) {\\frac {dA}\r\n{4 \\pi r^2}}$.  $\\int_{\\small{sphere}} |sin(\\theta)|^3 d\\theta d \\phi= {\\frac 2 3}$ so\r\n$P(t)= {\\frac 2 3} {\\frac {\\mu_0} {4 \\pi c}} q^2 a^2(t')$.\r\n\\\\\r\n\\\\\r\n{\\bf Oscilating dipole:} ${\\vec p} = q {\\vec d}$.  The dipole consists of a charge $+q$ and\r\na charge $-q$ separated by a distance, $d$ where $d$ is much smaller than the wavelength.\r\nAt low speed, $A(1,t) = {\\frac 1 {4 \\pi \\epsilon_0 c^2}} {\\frac 1 r} \\int v\r\n\\rho(2, t-r/c)dV_2 = {\\frac {vq} r}= {\\frac {{\\dot p}(t-r/c)} {4 \\pi \\epsilon_0 c^2 r}}$.\r\n$\\nabla \\times A = B$,  \r\n$B_x = {\\frac {\\partial A_z} {\\partial y}}$ and\r\n$B_y = -{\\frac {\\partial A_z} {\\partial x}}$.\r\n$B_x = {\\frac 1 {4 \\pi \\epsilon_0 c^2}}[{\\dot p} {\\frac {\\partial {\\frac 1 r}} {\\partial y}}\r\n+  {\\frac 1 r} {\\frac {\\partial {\\dot p}} {\\partial y}}] = \r\n-{\\frac 1 {4 \\pi \\epsilon_0 c^2}} [{\\frac y {r^3}} {\\dot p} + {\\frac y {c r^2}} {\\ddot p}]$.\r\nUse $\\nabla \\cdot A = - {\\frac 1 {c^2}} {\\frac {\\partial \\psi} {\\partial t}} $.\r\nThen ${\\frac {\\partial \\psi} {\\partial t}} = c^2 \\nabla \\cdot A =\r\n{\\frac d r} {\\frac 1 {4 \\pi \\epsilon_0 }} -[{\\frac 1 {r^2}} I(t-r/c) + {\\frac 1 {rc}}\r\nI'(t-r/c)] {\\frac {\\partial r} {\\partial z}}$, $r^2 = x^2 + y^2 +z^2$.\r\n$\\psi = {\\frac {dz} {4 \\pi \\epsilon_0}} [{\\frac {q(t-r/c)} {r^3}} + {\\frac {I(t-r/c)} {r^2c}}]$.\r\n\\\\\r\n\\\\\r\n{\\bf Poynting:} $dW = F \\cdot ds = \\int_{Q} dq (E + v \\times B) \\cdot v dt$.\r\n${\\frac {dW} {dt}} = \\int_{V_0} (E \\cdot v) \\rho dV = \\int_{V_0} E \\cdot j dV$.\r\nSubstitute $j = \\epsilon_0 (c^2 \\nabla \\times B - {\\frac {\\partial E} {\\partial t}})$ and use\r\n$A \\cdot \\nabla \\times B = B \\cdot \\nabla \\times A - \\nabla \\cdot (A \\times B)$ to get\r\n${\\frac {dW} {dt}} = - \\int_{v_0} \\epsilon_0 c^2 \\nabla \\cdot (E \\times B) -\r\n{\\frac 1 2} \\epsilon_0 {\\frac {\\partial} {\\partial t}} \\int_{V_0} E^2 dV\r\n- {\\frac 1 2} \\epsilon_0 c^2 {\\frac {\\partial} {\\partial t}} \\int_{V_0} B^2 dV$.\r\n\\\\\r\n\\\\\r\n{\\bf Fundamental constants:}\r\n$G= 6.671 \\times 10^{-11} {\\frac {N m^{2}} {kg^{2}}}$, \r\n$c= 2.99725 \\times 10^{10} {\\frac {cm}{s}} $,\r\n$k_B = 1.38 \\times 10^{-16} {\\frac  {ergs}{deg}}$,\r\n$h= 6.6262 \\times 10^{-27} erg-sec$,\r\n$q_{e} = 1.60219 \\times 10^{-19} C$,\r\n$\\epsilon_{0} = 8.854 \\times 10^{-12} {\\frac {C^2} {N-m^2}}$,\r\nSTP: $22.4 \\times 10^{3} {\\frac {cm^{3}} {mol}}$,\r\n$R=8.3143 {\\frac {J}{mol-deg}}$,\r\n$N_{0} = 6.022 \\times 10^{23} mol^{-1}$.\r\n\\\\\r\n\\\\\r\n{\\bf Some consequences of Maxwell:} \r\n\\emph{EMF} is the total accumulated force through wire,\r\n(${\\cal E}= -{\\frac {d \\phi_B} {dt}}$).\\\\\r\nFor conservative electric field:\r\n$\\Delta \\phi = - \\int_a^b q E ds$, $\\Delta V= {\\frac {\\Delta \\phi} q}$.\r\n\\emph{Coulomb:} $F= {\\frac 1 {4 \\pi \\epsilon_0}} {\\frac {q_1 q_2} {r^2}} {\\hat r}$.\r\n\\emph{Gauss (always):} $\\Phi_E = \\int_S E \\cdot dA= {\\frac {q_{in}} {\\epsilon_0}}$,\r\n$S$, closed.  $\\Phi_B= \\int_S B \\cdot dA=0$, $S$, closed.  \r\n\\emph{Biot-Savart (steady currents):}\r\n$B= {\\frac {\\mu_0} {2 \\pi}} {\\frac {qv \\times e_r} {r^2}}$.\r\n\\emph{Ampere:} $\\int_C B \\cdot dl = \\mu_0 (I_{enclosed}+\\epsilon_0 {\\frac {d \\Phi_E}{dt}})$.\r\n\\emph{B for wire (steady currents only):} $B= {\\frac {\\mu_0 I} {2 \\pi r}}$.  \r\n\\emph{Faraday:} ${\\cal E}= \\int_C E \\cdot dl= - {\\frac {d \\Phi_B} {dt}}$.\r\n$E= 0$ for conductor in \\emph{electrostatics}.\r\n$C=\\kappa_0 C_0$.  Steady current in conductor: $J= nqV_d= \\sigma E$, $E=\\rho J$.\\\\\r\n\\emph{AC:} $V=IZ$. \\emph{Induced currents} gives rise to induced \r\nEMF (${\\cal E}= -{\\frac {d \\Phi_B} {dt}}$).\r\n\\emph{Pointing vector} describes energy flow \r\n$S= {\\frac 1 {\\mu_0}} E \\times B$; transmitted power\r\nis $P= \\int S \\cdot dA$.  ${\\frac S c}$ is the \\emph{radiation pressure}.  \r\n\\emph{Displacement currents},\r\nlike the initial current to charge a capacitor, also gives rise to fields.  \r\n\\emph{Energy density} is\r\n$u= {\\frac 1 2} \\epsilon_0 E^2 + {\\frac 1 {2 \\mu_0}} B^2$.\r\n\\emph{Rayleigh-Jeans:} $B_{\\nu}(T)= {\\frac {2kT \\nu^2}{c^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Antennas and Propagation}\r\n$L_S = 32.4 + 20 log(f_{MHz}) + 20 log(d_{km})$.  \\emph{Friis Formula}:\r\n$P_R = {\\frac {P_T G_T G_R \\lambda^2} {(4 \\pi R)^2}}$.  \\emph{Effective aperture:} \r\n$A_e = {\\frac {\\lambda^2} {4 \\pi}}G$.\r\n\\\\\r\n\\emph{Oscillating Dipole (Antenna):}\r\n$E= {\\frac {p_0 k^2} {4 \\pi \\epsilon_0}}\r\n{\\frac {sin( \\theta )} {r}} sin(\\omega t - k r)$, $E=cB$.  \r\n\\\\\r\n\\\\\r\n{\\bf Magnetism and relativity:}  Let $S(x,y,z,t)$ be the reference frame of a stationary\r\nwire with center line along the $y$ axis and cross section $A$.  Suppose there is a\r\nnegative charge, $q$ at a distance, $r$, in the $z$ direction moving at a velocity $v_0$ parallel to the $y$\r\naxis. Suppose the wire has \r\nheavy positively charged particles of density $\\rho_{+}$ which are stationary and\r\nfree electrons of density $\\rho_{-}$ moving in the positive $y$ direction with velocity, \r\n$v$, giving rise to a current, $I$ in the\r\n$-y$ direction.  Overall, the wire is electrically neutral, so, $\\rho_{+}= \\rho_{-}$.\r\nThe current generates a $B= {\\frac {\\mu_0 I} {2 \\pi r}}$ and the charge, $q$ thus experiences a force\r\n$F= q v_0 \\times B\r\n=  {\\frac 1 {4 \\pi \\epsilon_0 c^2}} {\\frac {2q v v_0} {r}}\r\n=  {\\frac 1 {4 \\pi \\epsilon_0 c^2}} {\\frac {2 \\rho_- A q v v_0} {r}}$.  Now let $v_0=v$ and we get\r\n$F= {\\frac q {2 \\pi \\epsilon_0 c^2}} {\\frac {\\rho_- A} {r}} {\\frac {v^2}{c^2}}$. \r\nNow let $S'(x', y', z',t')$ be the reference frame moving in the positive $y$ direction with velocity $v$.  In\r\nthis frame, $q$ is not moving (so there is not force due to the magnetic field) and the heavy positive\r\ncharges are moving to the left with velocity $v$ (so again there is a current $I$ to the left).  However,\r\nthe wire is forshortened: $L'= L\r\n{\\sqrt {1- {\\frac {v^2}{c^2}}}}$ so the charge density\r\n$\\rho_+ ' = {\\frac {\\rho_+ } {\\sqrt {1- {\\frac {v^2}{c^2}}}}}$ and, since the electrons are now ``at rest'', they\r\nhave their rest density, so\r\n$\\rho_- ' = \\rho {\\sqrt {1- {\\frac {v^2}{c^2}}}}$.  So\r\n$\\rho'= \\rho_+ + \\rho_- = (\\rho_+) ({\\frac {v^2}{c^2}}) {\\frac 1 \r\n{\\sqrt {1- {\\frac {v^2}{c^2}}}}}$ and $q$ experiences an electric field \r\n$E'= {\\frac 1 {2 \\pi \\epsilon_0}} {\\frac {A \\rho_+ ({\\frac {v^2}{c^2}})}\r\n{r {\\sqrt {1- {\\frac {v^2}{c^2}}}}}}$ towards the wire.  Thus $F'= F {\\frac {1}\r\n{\\sqrt {1- {\\frac {v^2}{c^2}}}} }$ which is exactly how $F$ would transform under the Lorentz transformation.\r\nIn other words, the magnetic force, $F$, in $S$, transforms to a corresponding electric force, $F'$, in $S'$ \r\nwith same value as $F$, relativistically corrected.\r\n\\\\\r\n\\\\\r\n{\\bf Magnetic substances:}  Some materials have microscopic current loops that give rise to magnetic\r\nfields in substances. \r\n\\emph{Diamagnetic} materials have no microscopic loops but external field causes loops, these materials make\r\nfields a little weaker.\r\n\\emph{Paramagnetic} \r\nmaterials make fields a little stronger (some aligned loops).\r\n\\emph{Ferromagnetic} \r\nmaterials make fields a lot stronger (aligned loops).\r\n\\\\\r\n\\\\\r\n{\\bf Devices:}\r\n$\\Phi_B= Li$,\r\n${\\cal E} = -L {\\frac {d i} {dt}}$.  \r\n$U= {\\frac 1 2} C V^2$.\r\n$U= {\\frac 1 2} L I^2$.\r\n$Iz=V$. $Z_C= {\\frac  1 {i \\omega C}}$, $Z_L= i \\omega L$, $Z_R= R$. \\\\\r\n\\emph{Mutual Inductance:}\r\n${\\cal E}_2 = -M {\\frac {d i_1} {dt}}$,  \r\n${\\cal E}_1 = -M {\\frac {d i_2} {dt}}$.  \r\n$U_L= {\\frac 1 2} L I^2$,\r\n$U_C= {\\frac 1 2} C V^2$.\r\n\\\\\r\n\\emph{Kirchoff:}\r\n$\\sum_{k} v_k=0$, $k$ covers loop; \r\n$\\sum_{k} i_k=0$, $k$ covers node. \\\\\r\n\\emph{Thevinen equivalence:}\r\nTwo terminal linear network is equivalent to voltage source $V_{Th}$ and\r\nimpedance in series.  \\\\\r\n\\emph{Norton equivalence:} Two terminal linear network is equivalent to current \r\nsource $V_{N}$ and conductance $G_N$ in parallel. \\\\\r\n\\emph{Resistor:} $R= {\\frac {\\rho L} A}$, $\\rho= \\rho_0(1+ \\alpha \\Delta T)$.\r\n\\emph{Battery:} ${\\cal E} - Ir_{internal}= V_{ab}$. \\\\\r\n$S/N= 1- log_{10}({\\frac {P_S} {P_N}})$.  $60 dB$ is hi-fi, $90 dB$ for CD, Ear\r\ndetects $120 dB$. \\\\\r\n\\emph{Johnson noise:} $N=kTB$, $B=$ bandwidth.\r\n\\emph{Phasor:} $v=a+bi$, $|v|= \\sqrt{a^2+b^2}, tan(\\phi)= {\\frac b a}$. \\\\\r\n\\emph{Low-pass} (Inductance in series, capacitance across EMF), \r\nfor \\emph{high-pass} switch capacitance and inductance. \r\n\\emph{Low pass transfer:} ${\\frac {V_{out}} {V_{in}}} = {\\frac 1 {\\sqrt{1+ \\omega^2 R^2 C^2}}}$.\r\n\\emph{High pass transfer:} \r\n${\\frac {V_{out}} {V_{in}}} = {\\frac 1 {\\sqrt{1+ {\\frac {R^2} {\\omega^2 C^2}}}}}$. \\\\\r\n\\emph{Reactive:} no real term;\r\n\\emph{dissipative:} real term $>0$.  \\\\\r\n\\emph{Transmission line:}\r\n${\\frac {\\partial^2 I} {{\\partial x}^2}} = L_0 C_0 {\\frac {\\partial^2 I} {{\\partial t}^2}}$;\r\nimpedance is $z_0 = {\\sqrt {\\frac {L_0} {C_0}}}$.\r\n\\emph{Propagation factor:}\r\n$\\alpha= {\\frac {V_{n+1}} {V_n}}$.  \\\\\r\n\\emph{Channel Capacity:} $C= B lg(1+S/N) \\rightarrow {\\frac {B (S/N)} {kT}}$. \\\\\r\n\\emph{Antenna:} ${\\frac {P_R} {P_T}}= {\\frac {A_T A_R} {\\lambda^2 L^2}}$.\r\n\\emph{Antenna efficiency} $= {\\frac {R_R} {R_R+R}}$.\r\n$ERP= TPO \\times gain$.\\\\\r\n\\emph{Bipolar transistor} $i_c= \\beta i_b$, $i_b = {\\frac {v_b}{(\\beta + 1)r_e}}$. \r\n$V_t= {\\frac {kT}q} \\approx 25mA$.  $r_e= {\\frac {kT}{q i_c}}$.\r\n$i_c= i_{cs} (e^{\\frac {qv_{be}} {kT}} -1)$.\r\n\\\\\r\n\\emph{FET transistor} $g_m = {\\frac {\\Delta i_{DS}} {\\Delta v_{gs}}}$.  $i_D = i_{DSS} (1-{\\frac {V_{sg}} {V_P}})^2$.\r\n\\\\\r\n\\emph{Impedance matching and power transfer:}\r\n$\\rho={\\frac {Z_L-Z_0} {Z_L+Z_0}}$, \r\n$SWR= {\\frac {1+\\rho} {1-\\rho}}= {\\frac {Z_L}{Z_0}}$,\r\n${\\frac {P_{ref}} {P_{trans}}}= ({\\frac {Z_L-Z_0} {Z_L+Z_0}})^2$,\r\n$\\rho= {\\sqrt {\\frac {P_{reflected}} {P_{transmitted}}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Op Amp:} $ v_o= A_{OL}v_d$.  Transfer and two terminal input and output.\r\nOp amp rules: (1) No current into op amp and\r\n(2) with negative feedback $V_+ = V_-$.\r\n$R_i \\approx 10^4 \\Omega$, $A \\approx 10^5$, $R_L \\approx 10^3 \\Omega$.    \r\n\\\\\r\n\\\\\r\n\\emph{Channel capacity:} $C= B lg(1+{\\frac S N}) b/s$.\r\n\\\\\r\n{\\bf Circuits:}\r\n$X_C= -{\\frac j {\\omega C}}$, $V_C= X_C I_C$,\r\n$X_L=  j \\omega L$, $V_L= X_L I_L$,\r\n$Q= {\\frac X R}$, $BW= {\\frac {f_0} {Q_u}} =\r\n{\\frac {f_0} {\\Delta f}}$. \\\\\r\n\\emph{Capacitor:} $q(t)= C V_{max} (1-e^{- {\\frac t {RC}}})$. \\\\\r\n\\emph{Inductor:} $i(t)= i_{max} (1-e^{- {\\frac t {LR}}})$. \\\\\r\n$R_{Th}= {\\frac {v_{oc}} {i_{sc}}}$.\r\nFor RLC with $R=.09 \\Omega$, $L= 5 \\mu F$, $C= 6.693 nF$,\r\n$\\omega_0 = {\\frac 1 {\\sqrt {LC}}}= 5.4 \\times 10^6 /sec$, $f= 870$ kHz, $\\Delta f= 2.9$ kHz,\r\n$Q= 300$.   \\\\\r\n\\emph{Transformer:} ${\\frac {V_S}{V_P}}= {\\frac {N_S}{N_P}}$. \\\\\r\n\\emph{Integrator:} $v_o= - {\\frac 1 {R_1+R_L}} \\int_0^t v_i dt$. \\\\\r\n\\emph{Bipolar model: }\r\n$r_{\\pi} = {\\frac {kT}{qI_B}} \\approx 5.4 k \\Omega$, $i_c= \\beta i_b$, $v_{be}= i_b r_{\\pi}$,\r\n$i_c= - \\alpha i_E$, ${\\frac {d i_B}{dv_{bc}}}= {\\frac 1 {r_{\\pi}}}$,\r\n$I_e= I_C + I_B= (h_{FE}+1)I_B$.\r\n$i_b= {\\frac {I_{ES} } {\\beta + 1}} exp({\\frac {qv_{BE}} {kT}})$, $v_{be} \\approx .7V$ for Si.\r\nAt $300K$, ${\\frac {kT}{q}} \\approx .026V$.  Saturation for Si \r\n$|v_{CE}| \\approx 0.2V$, $|v_{BC}| \\approx 0.5V$. \r\n\\emph{Parameters:} $h_{ie}= {\\frac {\\partial v_{BE}} {\\partial i_B}}$,\r\n$h_{fc}= {\\frac {\\partial i_C} {\\partial i_B}}$.\r\nFor simple amp, ${\\frac {v_0 - v_A} {R_L}} - {\\frac {v_A} {R_2}} - \\beta i_1 = 0$ and\r\n$A_{oc}= {\\frac {- \\beta R_C} {r_{\\pi}}}$, \r\n$R_1= 3 M \\Omega$, $R_C = 10 k \\Omega$. $v_{CC} \\approx 15v$,\r\n$G_v= {\\frac {A R_L} {R_0 + R_L}}$.  $|A_{max}|= {\\frac {V_{cc}} {\\frac {kT} {q}}}$,\r\nfrequency response is $- \\beta R_C v_s {\\frac {1+j \\omega C_1 R_C}\r\n{[r_{\\pi}+ (1+\\beta)R_E]+j \\omega C_1 r_{\\pi} R_E}}$.  \r\n\\emph{FET:} $g_m= {\\frac {\\Delta i_{DS}} {\\Delta V_{GS}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Common emitter:} \r\n$A_V = {\\frac {R_c} {R_e}}$.\r\nDesign: (1) Choose $v_{cc}$ (say $12V$), and $A_V= 5$, \r\n(2) choose $Q$ point $i_{ceq} = 4 mA$, $v_{be}=.7V$, $v_{ceq}=5V$ (guide is ${\\frac {V_{cc}} 2}$). Finally,\r\nsuppose $\\beta = 150$.\r\nCalculate $R_c + R_e = {\\frac {v_{cc} - v_{ceq}} {i_{ceq}}} = 1.75 k \\Omega$.\r\nSince $R_c = 5 R_e$, $R_e = 270 \\Omega$ and\r\n$R_c = 1.5 \\times 10^3 \\Omega$.  $i_b = {\\frac {v_{ceq}} {\\beta}} = 27 \\mu A$.\r\nPick current through $R_1$ and $R_2$ (guide is $10 i_b$) of $270 \\mu A$.\r\n$V_{R_2} = .7 + i_{ceq}R_e = 1.8V$ and $V_{R_1} = 10.2V$,\r\n$R_2 = {\\frac {1.8V} {270 \\mu A}}= 6.7 k \\Omega$,\r\n$R_1 = {\\frac {5.3V} {270 \\mu A}}= \r\n38 \\times 10^3 \\Omega$.\r\n$Z_{in}= R_1 || R_2 || (\\beta+1) r_e \\approx(\\beta+1)r_e$, $Z_{out} \\approx R_c$.  $r_3 \\approx 1K\\Omega$.\r\n\\\\\r\n\\\\\r\n{\\bf Common collector (emitter follower):} \r\nDesign: $\\beta = 150$ as before, $A_V = 1$.\r\n(1) Choose $v_{cc}$ (say $12V$), (2) choose $Q$-point:\r\n$i_{ceq}= 5 mA$, $v_{ceq}= 6V$  (guide is ${\\frac {v_{cc}} 2}$), $v_{be}=.7V$,\r\nand $i_{R_1-R_2} = 10 i_b$.\r\n$v_{cc} = v_{be} + i_{ceq} R_e$, $R_e= 1.2 k \\Omega$.\r\n$i_b = {\\frac {i_{ceq}} {\\beta}} = 33 \\mu A$.\r\n$i_{R_1-R_2}= 10 i_b = 330 \\mu A$.\r\n$v_{R_2} = v_{be} + i_c R_e = .7 + 5 mA (1.2 \\times 10^3 \\Omega) = 6.7V$,\r\n$v_{R_1}= 5.3V$.\r\n$R_2 = {\\frac {6.7} {330 \\mu A}} = 20 \\times 10^3 \\Omega$,\r\n$R_1 = {\\frac {5.3} {330 \\mu A}} = 16k \\Omega$.\r\n${\\frac 1 {Z_{in}}} = {\\frac 1 {R_{1}}} +\r\n{\\frac 1 {R_{2}}} + {\\frac 1 {R_{e} ( \\beta + 1)}}$.\r\n$Z_{in} = R_1 || R_2 || (\\beta+1)r_e$, $Z_{out} = R_e || r_e$.\r\n$R_{in} = 50$ and $Z_{out} = 5 \\Omega$.\r\n\\\\\r\n\\\\\r\n{\\bf Common base:}\r\n$A_V= {\\frac {R_C ||R_L} {r_e}}$.\r\nDesign: Select $V_{cc} = 12V$ and $R_e= 50 \\Omega$,$V_{be}=.7V$,\r\n$R_L=10^3 \\Omega$, $i_{ceq} = 5 mA$, $v_{ceq}= 6V$.\r\n$i_b={\\frac {i_{ceq}} {\\beta}}=33 \\mu A$.  Current through\r\n$R_1, R_2$ is $10 i_b= 330 \\mu A$.  $v_{R_2}= v_{be} + i_c R_e = 6.7V$, $V_{R_1}= 5.3V$.\r\n$R_2 = 20 \\times 10^3 \\Omega$, $R_1 = 16 \\times 10^3 \\Omega$.\r\n$v_{R_c}= {\\frac {(v_{ceq}- i_{cq} R_e -v_{ceq})} {i_{ceq}}}$,\r\n$R_c = {\\frac {v_{R_c}} {i_{ceq}}} \\approx 1.35 \\times 10^3 \\Omega$.\r\n$A_V= {\\frac {1.5 \\times 10^3 || 10^3} {r_e}}=118$\r\n$Z_{in} = R_e || (\\beta+1)r_e$, $Z_{out} \\approx R_c$.\r\n\\\\\r\n\\\\\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit1.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit2.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit3.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit4.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit5.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit6.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit7.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit8.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit9.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit10.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit11.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit12.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit13.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit14.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit15.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit16.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit17.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit18.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit19.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit20.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit21.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit22.pdf}\r\n\\end{figure}\r\n\\begin{figure} \r\n\\center\r\n\\includegraphics[width=0.8\\textwidth,natwidth=642,natheight=610, height=80mm, width=88mm]{circuit23.pdf}\r\n\\end{figure}\r\n\\\\\r\n$\\pi$\\emph{-network:} $X_{C_1} = {\\frac {R_{in}} {Q}}$,\r\n$X_{L} = {\\frac {QR_{in} + {\\frac {R_{in}R_{out}} {X_{C_2}}}}\r\n{Q^2+1}}$.\r\n$R_{in} = 300$, $R_{out}= 50$, $F_C= \\sqrt{7.7 \\times 6.6}$,\r\n$BW= 1.1$ MHz, $Q= {\\frac {7.13}{1.1}}=6.48$,\r\n$Q^2+1=43 > {\\frac {300} {50}}$,\r\n$X_{C_1} = 46.3 \\Omega$,\r\n$X_{C_2} = 20.1 \\Omega$,\r\n$X_{L} = 62.5 \\Omega$.\r\n\\\\\r\n\\\\\r\n{\\bf Signal processing:} $h_n$ is impulse response to $\\delta(0)$ at time step $n$.\r\n$X( \\omega ) = \\sum_{n=-\\infty}^{\\infty} x(n) e^{-j \\omega n}$; \r\n$x_n = {\\frac 1 {2 \\pi}} \\int_{- \\pi}^{\\pi} X( \\omega ) e^{j \\omega n} d \\omega$.\r\n\\emph{Frequency response:} $H( \\omega ) = \\sum h_n e^{-j \\omega n}$.\r\n$X(z)= \\sum x_n z^{-n}$; $x_n = {\\frac 1 {2 \\pi j}} \\int_S X(z) z^{n-1} dz$.\r\n\\\\\r\n\\\\\r\n{\\bf Real components:}\r\n\\emph{Real amp:}\r\n$A= {\\frac {I_C R_C} {\\frac {kT} {q}}}$ and $I_C= {\\frac {V_{BB}-V_{BE}} {R_E}}$,\r\n$i_{c} \\approx {\\frac {v_{BB}-v_{BE}} {R_E}}, v_{BB}= v_{CC} {\\frac {R_{B2}} {R_{B1}+R_{B2}}}$,\r\nfrequency response is ${\\frac {1+j \\omega C_1 R_2 }\r\n{\\sqrt{1+ \\omega^2(r_1^2C_1^2+R_2^2C_2^2)+\\omega^4(R_1C_1R_2C_2)^2}}}$.\r\n\\\\\r\n\\emph{Air coil (solenoid):} $L=  {\\frac {\\mu n^2 A}{l}}$.\r\n\\\\\r\n\\emph{Air coil:} $L(\\mu H)= {\\frac {d^2 n^2}{18d+40l}}$ (length in inches).\r\n\\\\\r\n\\emph{Torodal coil, powdered iron:} $L(\\mu H)= {\\frac {A_L n^2}{10^3}}$ (length in inches).\r\n\\\\\r\n\\emph{Torodal coil, ferrite:} $L(\\mu H)= {\\frac {A_L n^2}{10^6}}$ (length in inches). \r\n\\\\\r\n\\emph{Wire gauge\r\ndiameter:} 22 - 25 mil, 20 - 32 mil, 12 - 80 mil.  1 mil= .0254 mm.\r\n\\\\\r\n\\\\\r\n{\\bf Fourier representation:} $V(t)= {\\frac {a_0}{2}} + \\sum_{n=1}^{\\infty} (\r\na_n cos(n \\omega t) + b_n cos(n \\omega t))$, \r\n$a_n= \\int_{T/2}^{T/2} V(t) cos(n \\omega t)$,\r\n$b_n= \\int_{T/2}^{T/2} V(t) sin(n \\omega t)$.\r\n\\\\\r\n\\\\\r\n{\\bf Reflection on string:}\r\n$ {\\frac {\\partial^2 \\psi} {\\partial t^2}} =\r\n{\\frac T {\\rho}} {\\frac {\\partial^2 \\psi} {\\partial x^2}}$,\r\n$v_{\\phi}={\\frac \\omega k}$,\r\n$v_{g}={\\frac {d\\omega} {dk}}$, $Z= {\\sqrt {T \\rho}}$.\r\n\\emph{Power:} $P(t)= F {\\frac {\\partial \\psi} {\\partial t}}$,\r\nFor travelling wave:\r\n$P(t)= Z({\\frac {\\partial \\psi} {\\partial t}})^2$.\r\nConsider a wave train on a string from the left ($L$) with a change\r\nat $x=0$ of medium (i.e. a denser string) to a string on the right ($R$).\r\nDispersion caused by variation of wave velocity by frequency\r\nrelation $\\omega= f(k)$.  Consider string of density $\\mu_1$ connected\r\nto string of density $\\mu_2$ at $0$.  $f_1(x-{\\frac {x} {v_1}}) + g(x+{\\frac {x} {v_1}})\r\n= f_2 (x- {\\frac {x} {v_2}})$.  At $0$: $f_1(t)+g(t)=f_2(t)$ and\r\n${\\frac {f_1'(t)} {v_1}}-{\\frac {g'(t)} {v_1}} = {\\frac {f_2'(t)} {v_2}}$;\r\nsolve to get $g(t)= {\\frac {v_2 - v_1} {v_2+v_1}} f_1(t)$ and\r\n$f_2(t)= {\\frac {2v_2} {v_2+v_1}} f_1(t)$.  \\emph{Mach angle:}\r\n$sin( \\theta)= {\\frac u v}$.\r\nFor perfect termination:\r\n$F_{\\small {term}} (\\textnormal{``R on L''})= -\r\nZ_L {\\frac {\\partial \\psi_{inc}} {\\partial t}} (0,t)$.\r\nFor excess force:\r\n$F_{\\small{term}} (\\textnormal{``R on L''})= Z_L \r\n{\\frac {\\partial \\psi_{ref}} {\\partial t}} (0,t)$.\r\n$-Z_L {\\frac {\\partial \\psi_{inc}} {\\partial t}} (0,t)+\r\nZ_L {\\frac {\\partial \\psi_{ref}} {\\partial t}} (0,t) =\r\n-Z_R ({\\frac {\\partial \\psi_{inc}} {\\partial t}} (0,t)+\r\n{\\frac {\\partial \\psi_{ref}} {\\partial t}} (0,t))$.  So,\r\n${\\frac {\\partial \\psi_{ref}} {\\partial t}} (0,t)=\r\n{\\frac {Z_L - Z_R} {Z_L + Z_R}}\r\n{\\frac {\\partial \\psi_{inc}} {\\partial t}} (0,t)$.\r\n$R= {\\frac {Z_L - Z_R} {Z_L + Z_R}}$ is called the reflection coefficient.\r\n\\\\\r\n\\\\\r\n{\\bf Transmission boundary:} Let \r\n$v_I({\\frac {x}{v_1}}-t), x < 0$,\r\n$v_R({\\frac {x}{v_1}}+t), x < 0$,\r\n$v_T({\\frac {x}{v_2}}-t), x > 0$ be respectively the incidence,\r\nreflection and transmission voltages of a transmission line with boundary\r\nat $x=0$.  Put $x=0$ to get \r\n$v_I(t)+v_R(t)=v_T(t)$. Expressing the current\r\nflow at the boundary in terms of the voltages and the impedences ($Z_L, x<0$ and\r\n$Z_R, x>0$), we get\r\n${\\frac {v_I(t)} {Z_L}}-{\\frac {v_R(t)} {Z_L}}={\\frac {v_T(t)} {Z_R}}$.\r\nSolving we get, $v_R(t)= {\\frac {Z_L-Z_R}{Z_L+Z_R}}v_I(t)$ and\r\n$v_T(t)= {\\frac {2Z_R}{Z_L+Z_R}}v_I(t)$.\r\n\\\\\r\n\\\\\r\n{\\bf Wave Transmission:}\r\n\\emph{String:} $v= {\\sqrt {\\frac F \\mu}}$.\r\n\\emph{Fluid:} $v= {\\sqrt {\\frac B \\rho}}$.\r\n\\emph{Solid:} $v= {\\sqrt {\\frac Y \\rho}}$.\r\n\\emph{Adiabatic Gas:} $v= {\\sqrt {\\frac {\\gamma p } \\rho}}$.\\\\\r\n\\emph{Diffraction:} $I = I_0 ({\\frac {sin({\\frac {\\beta} {2}})} {\\frac {\\beta}{2}}})^2$,\r\n$\\beta = {\\frac {2 \\pi a sin( \\theta )} {\\lambda}}$.\r\n\\\\\r\nStanding wave transmits no energy.\r\n\\\\\r\n\\\\\r\n{\\bf Early Quantum Mechanics:} $\\Delta p \\Delta x \\geq {\\frac {h} {4 \\pi}}$,\r\n$\\hbar = {\\frac {h}{2 \\pi}}$,\r\n$\\lambda = {\\frac {h}{p}}$,\r\n$\\nu = {\\frac {E}{h}}$,\r\n$p = {\\frac { h k }{ 2 \\pi }} = {\\frac {p}{\\lambda}}$,\r\n$E = {\\frac {h \\omega}{2 \\pi}}$,\r\n$p_{av} = n k T$. \\emph{Blackbody radiation:}\r\n$E(\\lambda , T ) = {\\frac {8 \\pi h c} {(\\lambda^{5})}} (e^{{(h c)} /\r\n{(\\lambda k T )}}- 1)^{-1}$.  \r\n\\emph{Photoelectric Effect:} $hf= KE+ \\phi$.\r\n\\emph{Bohr hydrogen atom:} $E_n = -{\\frac {13.6 ev} {n^2}}$, $r_n=n^2a_0$,\r\n$a_0= {\\frac {h^2} {2 \\pi k m c^2}}= .0529 nm$.\r\n\\emph{Time Independent Schrodinger:}\r\n${\\frac {d^2 \\psi} {dt^2}}+{\\frac {4 \\pi m} {h}}(E-U(x)) \\psi = 0$.\r\n\\emph{Schrodinger:}\r\n${\\frac {ih} {2 \\pi}} {\\frac {\\partial \\psi} {\\partial t}} =\r\n-{\\frac {h^2} {8 \\pi^2 m}} \\nabla^2 \\psi + V \\psi$.\r\n\\\\\r\n\\\\\r\n{\\bf General Relativity:}\r\nThe \\emph{proper interval} is $I(x,y,z,t)= c^2 t^2 - (x^2 + y^2 +z^2 )$, \r\n$I(x,y,z,t)=I(x',y',z',t')$.\r\n$ds^{2}= g_{ij} dx^{i} dx^{j}$, $g_{ij} = g_{ji}$, $\\delta \\int {ds} = 0$.\r\nThe \\emph{action} is $S= \\int_{t_1}^{t_2} L(x, x', t) dt$, $\\delta S=0 \\rightarrow \r\n{\\frac {\\partial L} {\\partial x}}- {\\frac d {dt}} {\\frac {\\partial L} {\\partial x'}}=0$.\r\n$L(x,x',t)= {\\frac {-m_0 c^2} {\\sqrt {1-{\\frac {v^2} {c^2}}}}} - q(\\phi + v \\cdot A)$.  \r\n$R_{excess}= {\\sqrt {\\frac {A} {4 \\pi}}} - r_{meas}= {\\frac {G} {3 c^2}}M$,\r\n${\\frac {G} {3 c^2}}= 2.5 \\times 10^{-29} {\\frac {cm} {gm}}$.  From principle of\r\nequivalence, $\\omega= \\omega_0 (1+ {\\frac {gH} {c^2}})$ - doppler shift measured by \r\nPound and Rebka. $\\tau = {\\frac L c}$ and $L = \\int_0^t ||\\dot{X}(t)|| dt$.\r\n\\emph{Equation of motion:} ${\\frac {d^2 X} {{d \\tau}^2}} = - {{\\Gamma}^i}_{kl}\r\n{\\frac {d X^k} {d \\tau}} {\\frac {d X^l} {d \\tau}}$; this corresponds to Newtonian\r\n$\\ddot{x}^{\\alpha} = - {\\frac {\\partial \\Phi} {\\partial x^{\\alpha}}}$.  \r\n\\\\\r\n\\\\\r\n{\\bf Maxwell's equations (CGS):}\r\n$\\nabla \\cdot {\\vec j} = - {\\frac {\\partial \\rho} {\\partial t}}$,\r\n$\\nabla \\cdot {\\vec E} =  4 \\pi {\\rho}$, \r\n$\\nabla \\times {\\vec E} = - {\\frac 1 c} {\\frac {\\partial {\\vec B}}{\\partial t}}$,\r\n$\\nabla \\cdot {\\vec B} = 0$,\r\n$\\nabla \\times {\\vec B} = {\\frac {4 \\pi} c} {\\vec j} +\r\n{\\frac 1 c} {\\frac {\\partial {\\vec E}} {\\partial t}}$.\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|l|}\r\n\\hline\r\n{\\bf CGS Units:} $k=1$.  $F= q(E + {\\frac v c} \\times B)$.  \r\n$1$ statvolt$=$ $300$ volts\\\\\r\n$1$ statvolt/cm $=$ $3 \\times 10^4$ volts/m\\\\\r\n$1$ T $=$ $10^4$ G\\\\\r\n$1$ C $=$ $3 \\times 10^9$ esu\\\\\r\n$1$ ohm $=$ $1.139 \\times 10^{-12}$ sec/cm\\\\\r\n$1$ weber $=$ $10^{8}$ G-cm\\\\\r\n$1$ J $=$ $10^{7}$ ergs\\\\\r\n$1$ N $=$ $10^{5}$ dynes\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{figure}\r\n\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|r|r|r|}\r\n\\hline\r\n{\\bf System} & $\\epsilon_0$ & $\\mu_0$ & ${\\vec D}, {\\vec H}$ & {\\bf Maxwell's equations} & {\\bf Lorentz Force} \\\\\r\n\\hline\r\n & & & ${\\vec D}= {\\vec E} + 4 \\pi {\\vec P}$ & \r\n$\\nabla \\cdot {\\vec D}= 4 \\pi \\rho$ & \\\\\r\n & & & & \r\n$\\nabla \\times {\\vec H} = {\\frac {4 \\pi {\\vec j}} {c}} + {\\frac 1 c} {\\frac {\\partial {\\vec D}} {\\partial t}}$ & $q ({\\vec E} + {\\frac {\\vec v} {c}} \\times {\\vec B})$ \\\\\r\nGaussian & $1$ & $1$ & & \r\n$\\nabla \\cdot {\\vec B} = 0$ & \\\\\r\n & & & ${\\vec H}= {\\vec B} - 4 \\pi {\\vec M}$ & \r\n$\\nabla \\times {\\vec E} + {\\frac 1 c} {\\frac {\\partial {\\vec B}} {\\partial t}}= 0$ & \\\\\r\n\\hline\r\n & & & ${\\vec D}= \\epsilon_0 {\\vec E} + {\\vec P}$ & \r\n$\\nabla \\cdot {\\vec D}= \\rho$ & \\\\\r\n & & & &\r\n$\\nabla \\times {\\vec H} = {\\vec j} + {\\frac {\\partial {\\vec D}} {\\partial t}}$ & \r\n$q( {\\vec E} + {\\vec v} \\times {\\vec B} )$ \\\\\r\nMKS & ${\\frac {10^{-9}} {36 \\pi}}$ & $4 \\pi \\times 10^{-7}$ & & \r\n$\\nabla \\cdot {\\vec B} = 0$ & \\\\\r\n & & & ${\\vec H}= {\\frac {\\vec B} {\\mu_0}} - {\\vec M}$ & \r\n$\\nabla \\times {\\vec E} + {\\frac {\\partial {\\vec B}} {\\partial t}}= 0$ & \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Maxwell's Equations in MKS and CGS}\r\n\\end{figure}\r\n\\section{Physical Constants}\r\n{\\bf Conversion factors:}\r\n$1 \\; in= 2.54 \\; cm$.\r\n$1 \\; meter= 39.370 \\; in$.\r\n$1 \\; AU= 1.496 \\times 10^{11}\\; m$.\r\n$1 \\; lb= 4.448 \\; N$.\r\n$1 \\; Pa= 1 \\; {\\frac {N} {m^2}}$.\r\n$1 \\; Atm= 1.013 \\times 10^{5}\\; Pa$.\r\n$1 \\; hp= 745.7 \\; W$.\r\n$1 \\; J= 10^{7}\\; erg$.\r\n$1 \\; ev= 1.602 \\times 10^{-19}\\; J$.\r\n$1 \\; BTU= 1055 \\; J$.\r\n$1 \\; cal= 4.186\\; J$.\r\n$1 \\; L= 1000 \\; cm^3$.\r\n$1 \\; Gal= 3.785 \\times 10^{-3}\\; m^3$.\r\n$1 \\; kg = 2.2046 \\; lbs$, $1 \\; fluid-oz = 0.0338 \\; ml$, \r\n$1 \\; gal = 3.3785 \\; liters$.\r\n\\\\\r\n\\\\\r\n{\\bf Atomic constants:} $M_{e} = .510998 \\textnormal{Mev}= 9.10939 \\times 10^{-31} kg$,\r\n$M_{p} = 938.256 \\textnormal{Mev} (=1836 M_{e})= 1.67262 \\times 10^{-27}kg$,\r\n$M_{n} = 939.55 \\textnormal{Mev} = 1.67493 \\times 10^{-27} kg$,\r\n$\\sigma_{SB} = 5.67 \\times 10^{-8} W m^{-2} K^{-4}$,\r\n$1 ev = 1.6 \\times 10^{-12} erg = 1.6 \\times 10^{-19} J$,\r\n$1 curie = 3.7 \\times 10^{12} decays$, $c_{s} = 3.32 \\times 10^{4} cm/s$,\r\n$1 kg TNT= 4.2 MJ$,\r\n$1A = 10^{-8} cm$.  \\emph{HDNA:} 2,900,000 kilobases.\r\n\\\\\r\n\\\\\r\n{\\bf Astronomical constants:} $H_{0} = 100 \\textnormal{km{(s-Mpc)}}^{-1}$,\r\n$1 \\textnormal{ pc}= 3.26 l-y$,\r\n$10^{80} \\textnormal {nucleons}$, $10^{28} \\textnormal{cm-diam}$, $10^{11} \\textnormal{galaxies}$.\r\n\\\\\r\n\\emph{Milky Way:} $\\epsilon_{\\small{ecliptic/MW}}= 62.5$,\r\n$1.6 \\times 10^{11} \\textnormal{stars}$, $10^{23} \\textnormal{cm-diam}$, $8 \\times 10^{44} \r\n\\textnormal{gm}.$ \\\\ \\emph{Sun:} $E_{\\small{sun}} = 4 \\times 10^{33} \r\n\\textnormal{ergs/sec}$,\r\n$R_{\\small{Su}n}= 3.5 \\times 10^{10} cm$, $1.99 \\times 10^{33} \\textnormal{gm}$,\r\n$\\lambda_{\\small{sun}} = 30 days.$ \\\\ \\emph{Earth:} $\\epsilon_{earth} =23.5$,\r\n50\\% clouds, $R_{\r\n\\small{moon}} = 2160 mi$, $\\epsilon_{\\small{moon}} = 5$, \r\n$\\lambda_{\\small{sider}} =  27d7h43m12s$, $\\lambda_{\r\n\\small{synod}} = 29d12h44m3s$, $D_{moon}= 363,300 - 405,500 km$.\r\n$RA_{\\small{Greenwich}}  (1986.0): 6.6245$,\r\n$ 0 \\; Jan \\; 1986= 2,446,430.5JD$.\r\n\\\\\r\n\\\\\r\n{\\bf Geological:}\r\nFor seismic wave,\r\n$v_P= {\\sqrt {\\frac {(k+{\\frac 4 3} \\mu)} {\\rho}}}$,\r\n$v_S= {\\sqrt {\\frac {\\mu} {\\rho}}}$. \\\\\r\n$\\mu_{granite}= 1.6 \\times 10^{10} dynes/cm$,\r\n$k_{granite}= 27 \\times 10^{10} dynes/cm$,\r\n$k_{water}= 2.0 \\times 10^{10} dynes/cm$,\r\n$\\mu_{water}= 0$.\r\n$v_{P-granite}= 5.5 km/sec$,\r\n$v_{S-granite}= 3.0 km/sec$,\r\n$v_{P-water}= 1.5 km/sec$,\r\n$v_{S-water}= 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Materials: }\r\n\\emph{Young's Modulus:} ${\\frac F A} = Y {\\frac {\\Delta L} {L}}$.\\\\\r\n\\emph{Bulk Modulus:} ${\\frac F A} = B {\\frac {\\Delta V} {V}}$.\\\\\r\n\\emph{Shear Modulus:} ${\\frac F A} = G {\\frac {\\Delta x} {L}}$.\\\\\r\n\\emph{Viscosity:} $\\eta = {\\frac {\\frac F A}  {\\frac {\\Delta v} {h}}}$.\\\\\r\n\\emph{Surface tension:} $\\gamma_{H_2O}= 72.8 \\times 10^{-4} N/m$.\\\\\r\n\\emph{Reynold's number:} $Re = {\\frac {\\rho {\\overline v} L} {\\eta}}$;\r\nturbulent flow if $Re>4000$, laminar if $Re<2000$.\\\\\r\nDry (static, sliding) Friction:  Steel (.78,.42), Teflon; (.04,-).\\\\\r\n\\emph{Expansion:}\r\n$\\alpha_{l} = l^{-1} {\\frac {\\partial l} {\\partial t}} \\times 10^{6}$,\r\nC: (Al, 24), (Cu, 17), (Granite, 8.3), (Ice, 50), (Fe, 12), (Water, 207).\\\\\r\n\\emph{Heat Capacity:}\r\n$c_{v} =  m^{-1} {\\frac {\\partial Q } {\\partial T}}:$ [${\\frac {J}{mol-\\thinspace^oK}}$]\r\n(He, 12.5), ($O_{2}$, 21.1), ($N_{2}$, 20.6),\r\n($C_{2}H_{6}$ , 39.3), MFP $N_{2}= 10^{-5}$ cm,\r\n$C_{v,solid} = 3 R$.\\\\\r\n$c_{v,air} \\approx 700 {\\frac {J} {kg-\\thinspace^oK}}$.\r\n\\emph{Melting/Boiling:}\r\nMP/BP (K): Au, 1336, 3081; $O_{2}$, 54, 90; Cu, 1356, 2839.\\\\\r\n\\emph{Heat Conduction:}\r\n$Q' = - \\kappa A  {\\frac {\\partial T} {\\partial l}} W{(cmK)^{-1}}: $\r\n(Cu, 4), (Fe, 0.80), (Si, 1.5), ($H_{2}$,.00024-.0018),\r\n(Rock, 2.8 kc/mhK).\\\\\r\n\\emph{Dielectric:}\r\n$\\epsilon = K \\epsilon_{0}$: (Glass, 6.7), (Water, 78), (Nylon, 3.6).\r\n\\\\\r\n\\emph{Resistivity:}\r\n$R= \\rho {\\frac {L}{A}}  \\times 10^{-8}$: (Ag, 1.4), (Cu, 1.7), (Al, 2.8),\r\n(Fe, 9.8).\r\n\\\\\r\n\\emph{Density:}\r\n$\\rho / \\rho_{water}$: Al, 2.7; Cu, 8.9; Rock, 5.5; Au, 19; Fe, 7.8; Gas, .68 ($g/cm^3$);\r\nair, .0012; wood, .75.  \\\\\r\n\\emph{Moduli:}\r\n$B= {\\frac {\\Delta P} {\\frac {\\Delta V} {V}}}:$ Al, 70;\r\nCu, 140; Fe, 100; Water, 2.2 ($GPa$).  \\\\\r\n$Y= {\\frac {\\frac {\\Delta F}{A}} {\\frac {\\Delta l}{l}}} \\times\r\n10^{12} dy/cm^{2}$: Al, 70; Cu, 110; Fe, 190.  \\\\\r\n$M_{s} = {\\frac {\\frac {\\Delta F} {A}} {\\frac {\\Delta x} {l}}}:$\r\nAl, 30; Cu, 42; Fe, 100.\\\\\r\nEnergy content of one gallon of heating oil: $140,000 kJ/gallon$.\r\n\\\\\r\n\\\\\r\n{\\bf Air:} 28.96 m-w, $c_{p}$ = 1005 J/kg-K, $c_{v} = 718 J/kg-K$.\r\n$1\\; atm= 1.013 \\times 10^{5} Pa$, $Pa= 10^{6} dyne/cm^{2}= 1N/m^2=760 mm-Hg$.\r\n$\\rho: 1.293 mg/cm^{3}$, $\\kappa :  2.4 \\times 10^{-2} W/m-K$, $visc@20: .00018 g/cm-s.$\r\n\\\\\r\n\\\\\r\n{\\bf Water:} 273.15K, 18 m-w, 540 cal/gm (vaporization), 80 cal/gm (fusion),\r\n$\\rho_{ice} = 917 kg / m^{3}$,\r\n$\\rho_{water} = 1 g / cm^{3}$,\r\n$\\kappa:  .19 W/m-K, visc@20: .01gm/cm-s, ST: @20: 73d/cm.$  Specific\r\nheat of water: $1 cal/K-gm= 4.186 J/K-gm$.\r\n\\\\\r\n\\\\\r\n{\\bf Sound:}\r\n\\emph{Sound strength:} $g= 10 log({\\frac {I} {I_0}})$ in db.  $I_0 = 10^{-12}\r\nW/m^2$. Normal Conversation: 60 db, Jet: 130 db.\r\n\\emph{Speed of Sound:}\r\n$\\approx 330 m/s$ at normal conditions,\r\n$v_{av} = {\\sqrt { {3 k T } / m }}$.\r\n\\\\\r\n\\\\\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|lllll|lllll|}\r\n\\hline\r\n{\\bf Name} & {\\bf RA} & {\\bf Dec} & {\\bf Vmag} & {\\bf Dist} & {\\bf Name} & {\\bf RA} & {\\bf Dec} & {\\bf Vmag} & {\\bf Dist} \\\\\r\n\\hline\r\nPolaris & 01 23 & 88 46 & 2.06 & 200 & Mizar & 13 20 & 55 27 & 2.12 & 26 \\\\\r\n\\hline\r\nAldeberan & 04 30 & 16 19 & .8 & 21 & Capella & 05 09 & 45 54 & .09 & 14 \\\\\r\n\\hline\r\nRigel & 05 10 & -08 19 & .11 & 270 & Bellatrix & 05 20 & 06 16 & 1.63 & 140 \\\\\r\n\\hline\r\nBetelgeuse & 05 50 & 07 23 & .4 & 180 & Sirius & 06 41 & -16 35 & -1.44 & 2.7 \\\\\r\n\\hline\r\nCanopus & 06 22 & -52 38 & -.72 & ? & Castor & 07 28 & 32 06 & 1.56 & 14 \\\\\r\n\\hline\r\nProcyon & 07 34 & 05 29 & .36 & 3.5 & Pollux & 07 39 & 28 16 & 1.15 & 10.7 \\\\\r\n\\hline\r\nRegulus & 10 03 & 12 27 & 1.34 & 26 & Merak & 10 56 & 56 55 & 2.36 & 23 \\\\\r\n\\hline\r\nSpica & 13 20 & -10 38 & .97 & 65 & Arcturus & 14 11 & 19 42 & -.05 & 11 \\\\\r\n\\hline\r\nAntares & 16 23 & -26 13 & .94 & 130 & Vega & 18 34 & 38 41 & .03 & 8.1 \\\\\r\n\\hline\r\nAltair & 19 46 & 08 36 & .77 & 4.9 & Deneb & 20 38 & 44 55 & 1.25 & 500\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Stars}\r\n\\end{figure}\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|lllllllllll|}\r\n\\hline\r\n{\\bf Planet} & $\\mathbf {D_{av}(km \\times 10^6)}$ & $\\mathbf {\\lambda(rev)}$ & \r\n$\\mathbf {e}$ & $\\mathbf {i}$  & $\\mathbf {L_{node}}$ & $\\mathbf {L_{Per}}$ &\r\n$\\mathbf {P_{epoch}}$ & {\\bf M(gm)} & {\\bf R(km)} & {\\bf Rot}\\\\\r\n\\hline\r\nMercury & 57.9 & 87.97d & .2 & 7 & 47.9 & 76.8 & 222.6 & 3.3e26 & 2439 & 58.7d\\\\\r\n\\hline\r\nVenus & 108.2 & 224.7d & .007 & 3.4 & 76.3 & 131.0 & 174.3 & 4.9e27 & 6050 & 243d\\\\\r\n\\hline\r\nEarth & 149.6 & 365.26 & .017 & 0 & 0 & 102.3 & 100.2 & 6e27 & 6378 & 23h56m\\\\\r\n\\hline\r\nMars & 227.9 & 686.98 & .093 & 1.8 & 49.2 & 335.3 & 258.8 & 6.4e26 & 3394 & 24h37m\\\\\r\n\\hline\r\nJupiter & 778.3 & 11.8yr & .048 & 1.3 & 100.0 & 13,7 & 259.8 & 1.9e30 & 71880 & 9.8h\\\\\r\n\\hline\r\nSaturn & 1427.0 & 29.46 & .056 & 2.5 & 113.3 & 92.3 & 280.7 & 5.7e29 & 60400 & 10.66h\\\\\r\n\\hline\r\nUranus & 2869 & 84 & .047 & .8 & 73.8 & 170.0 & 141.3 & 8.8e28  & 23540 & 17.24h\\\\\r\n\\hline\r\nNeptune & 4496 & 164.79 & .009 & 1.8 & 131.3 & 44.3 & 216.9 & 1e29 & 24600 & 16h\\\\\r\n\\hline\r\nPluto & 5900 & 247.7 & .250 & 17.2 & 109.9 & 224.2 & 181.6 & - & - & - \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Planetary data - Epoch: 1960 Jan 1.5UT,\r\nOrbit:  $a = b {\\sqrt {1 - e^{2}}}$.}\r\n\\end{figure}\r\n\\begin{figure} [h]\r\n\\begin{center}\r\n\\begin{tabular} {|lrr|lrr|lrr|}\r\n\\hline\r\n{\\bf Place} & {\\bf Lat} & {\\bf Long} & {\\bf Place} & {\\bf Lat} & {\\bf Long} & {\\bf Place} & {\\bf Lat} & {\\bf Long} \\\\\r\n\\hline\r\nBeijing & 40.1 & 116.33 & SF & 37.45 & -122.33 & NY & 41.44 & -73.8 \\\\\r\n\\hline\r\nBoston & 42.35 & -71.05  & Chicago & 41.87 & -87.63 & Dallas & 32.78 & -96.78  \\\\\r\n\\hline\r\nMadison, Wi & 43.07 & -89.38 & Santa Fe & 35.68 & -105.93  & Seattle & 47.61 & -122.33 \\\\\r\n\\hline\r\nTucson & 32.22 & -110.97  & DC & 38.88 & -77.0 & Denver & 39.75 & -104.99  \\\\\r\n\\hline\r\nAtlanta & 33.75 & -84.39 & London & 51.5 & 0.0 & Paris & 48.83 & 2.3 \\\\\r\n\\hline\r\nBerlin & 52.5 & 13.42  & Rome & 41.88 & 12.5 & Moscow & 55.75 & 37.7 \\\\\r\n\\hline\r\nAthens & 37.97 & 23.75 & Jerusalem & 31.75 & 35.22  & Tokyo & 35.75 & 139.75 \\\\\r\n\\hline\r\nSidney & -33.87 & 151.2 & MKea & 19.826 & -155.47 & CTlo & -70.82 & -30.17  \\\\\r\n\\hline\r\nNew Orleans & 29.93 & -90.07 & Redmond,OR & 44.27 & -121.15 & Portland & 45.52 & -122.68 \\\\\r\n\\hline\r\nLA, CA & 34.05 & -118.24  & San Diego & 32.7 & -117.15 & Orlando & 28.52 & -81.38  \\\\\r\n\\hline\r\nMilan & 45.45 & 9.28 & Amsterdam & 52.3 & 4.77  & Auckland & -36.92 & 138.58 \\\\\r\n\\hline\r\nBombay & 18.93 & 74.58  & Delhi & 28.67 & 77.23 & Perth & -31.93 & -115.83  \\\\\r\n\\hline\r\nToronto & 43.65 & -79.38 & Bagdad & 33.3 & 44.43 & Cairo & 30.03 & 31.35 \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Places on Earth}\r\n\\end{figure}\r\n\\\\\r\n\\\\\r\n{\\bf Stellar Evolution} ($'$: means differentiate wrt $r$):\r\n$P'= - \\rho {\\frac {G M(r)} {r^{2}}}$, $M'= 4 \\pi r^{2}\\rho$,\r\n$L'= 4 \\pi r^{2} \\epsilon$,\\\\\r\n$L'= {\\frac {(-3 \\chi \\rho)}  {(4 a c T^{3} (4 \\pi r^{2})) }}$ (rad),\r\n$L'= (1 - \\gamma^{-1}) T  \\rho^{-1} P'$ (conv),\r\n$P=RT {\\frac {\\rho} {\\mu}}$,\r\n$\\chi = C \\rho T^{-3.5}$, $\\alpha = {\\frac {10^{6}} {T^{1/3}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Optics:} $n_{glass}= 1.52$, $n_{water}= 1.33$, $n_{diamond}=2.42$.  \r\n\\emph{Lensmaker's law (air to glass, one surface):}\r\n${\\frac 1 s} + {\\frac n {s'}}= {\\frac 1 f}$.\r\n\\emph{Lensmaker's law (double surface):}\r\n${\\frac {n_1} s} + {\\frac {n_2} {s'}}= {\\frac 1 f}$,\r\n${\\frac 1 f}= (n_2 - n_1 ){\\frac 1 {R_1}}-{\\frac 1 {R_2}}$.\r\n${\\frac {h_i} {h_o}}= {\\frac {d_i} {f}}={\\frac {f} {d_o}}$.\r\n\\emph{Resolving Power:}  4.54/$D_{\\small {inches}}$ arc-seconds,\r\n$f_{\\small{ratio}} = {\\frac {L_{\\small {focus}}}  {R_{\\small {diameter}}}}$,\r\n$3 \\leq f_{\\small {ratio}} \\leq 6$,\r\n$Mag= {\\frac {L_{\\small {focus-objective}}} {L_{\\small {focus-eyepiece}}}}.$\r\n\\emph{Lens:}  Original object $PA$ of height $y$ with ray intersecting focus at $S$ hitting \r\nlens at $U$ to\r\n(inverted) image $BR$ of height\r\n$y'$.  Similarly, ray from $P$ parallel to axis hitting lens at $Q$ intersecting\r\nfocus at $T$.  $x$ is distance from $A$ to $S$ and $x'$ from $T$ to $B$; finally, $f$ is the\r\ndistance from the focus to the lens.\r\n$ {\\frac {PA}{AS}}= {\\frac {QU}{PQ}} $ and\r\n$ {\\frac {BR}{TB}}= {\\frac {QU}{UR}} $.  Thus,\r\n$ {\\frac {y}{x}}= {\\frac {y+y'}{x+f}} $ and\r\n$ {\\frac {y'}{x'}}= {\\frac {y+y'}{x'+f}} $.  $f^2 = x x'$.  \r\n\\emph{Magnification:}\r\n${\\frac {y}{y'}}= {\\frac {x'} {f}}= {\\frac {f}{x}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Chemical bonds:}\r\n\\emph{Covalent:} 80-200  kcal/mole (C=C is 200), \r\n\\emph{Ionic:} 4-7 kcal/mole,\r\n\\emph{Hydrogen:} 5kcal/mole, \r\n\\emph{VanderWaal:} $<1kcal/mole$ (methane).\r\n\\emph{Thermal:} ~.6 kcal/mole.\r\nAcid added to $H_{2}O$ increases $H^{+}, pH= -log[H^+]$, acid $< 7$.\r\n\\\\\r\n\\\\\r\n{\\bf Fluids:}  $P + \\phi + {\\frac {1}{2}} \\rho v^{2} = const$,\r\n$\\nabla \\rho v = - \\rho '$,\r\n$\\nabla v = 0$,\r\n$\\nabla \\times v=0.$\\\\\r\n\\\\\r\n{\\bf Interference:} $R=A[\r\ncos(\\omega t) + cos(\\omega t + \\phi) + \\ldots + cos(\\omega t + (n-1)\\phi)]$.\r\n$A_R= A {\\frac {sin({\\frac {n \\phi} {2}})} {sin({\\frac {\\phi} {2}})}}$.\r\n$I= I_0 \r\n{\\frac {sin^2({\\frac {n \\phi} {2}})} {sin^2({\\frac {\\phi} {2}})}\r\n}$.  For \r\n$f(t)= A_1 e^{i \\omega_1 t} + A_2 e^{i \\omega_2 t}$,\r\n$I= A_1^2 + A_2^2 + 2 cos((\\omega_1 - \\omega_2)t)$.  Group velocity and modulation.\r\n\\\\\r\n\\\\\r\n{\\bf Damped and driven simple harmonic oscillators:}  \r\nSolution of $m\\ddot{x} +kx=0$ \r\nis $Acos(\\omega t)+Bsin(\\omega t)$ where $\\omega= {\\sqrt {\\frac k m}}$.\r\nSolution of $m\\ddot{x} +b \\dot{x} +kx=0$\r\nis $e^{- \\omega_0 t} (Acos(\\omega t)+Bsin(\\omega t))$ where \r\n$\\omega= {\\frac {\\sqrt {b^2-4 k m}} {2m}}$ and\r\n$\\omega_0= {\\frac b {2m}}$.\r\nSolution of $m\\ddot{x} +b \\dot{x} +kx= F cos(\\gamma t)$ is\r\n$e^{- \\omega_0 t} (Acos(\\omega t)+Bsin(\\omega t)) +\r\n\\alpha cos(\\gamma t)+ \\beta sin (\\gamma t)$ where \r\n$\\alpha= F{\\frac {k- m \\gamma^2} {(b \\gamma)^2 + (k - m \\gamma^2)^2}}$ and\r\n$\\beta= F{\\frac {b \\gamma} {(b \\gamma)^2 + (k - m \\gamma^2)^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Spectrum:}  \r\n30cps audio 30K 500K AM 1500K 3M HF 30M 88M FM VHF 210M 400M UHF 800M 1.5G \r\n$H_{2}$ S-band 3G 7600A IR 6300 Visible 3900A UV 100A X-ray .1A gamma\r\n67 Mev. \r\n\\\\\r\n{\\bf IEEE:} HF ($.003 - .03$ G), VHF ($.03 - .3$ G), UHF ($.3 - 1$ G), L ($1 - 2$ G),\r\nS ($2 - .4$ G), C ( $4 - 8$ G), X ( $8 - 12$ G),\r\nKu ($12 - 18$ G), K ($18 - .27$ G), Ka ($27  - 40$ G),\r\nV ($40 - 75$ G), W ($75 - 110$ G), G ($110 - 300$ G).\r\n\\\\\r\nRed: 650nm, Yellow: 580 nm, Green: 500nm, Blue: 475nm, Violet: 400Nm.  \r\n\\\\\r\n\\\\\r\n{\\bf Fris and dB:} dBm- relative to 1 mW, dBc - relative to carrier.\r\n$P_r = {\\frac { P_t G_t G_r \\lambda^2} { (4 \\pi)^2 d^2}}$. 120 dB at 433MHz,\r\n$d= 2km$.\r\n\\\\\r\n\\\\\r\n{\\bf Radar range equation:} $R^4= {\\frac {P_{tx} G^2 \\sigma \\lambda^2}\r\n{(4 \\pi)^3 P_{rx, min)}} }$, $P_{rx, min} = k T B F (SNR)_{min}$.\r\n\\\\\r\n\\\\\r\n{\\bf Middle C:}  256Hz. Octave has 12 notes in uniformly divided log scale.\r\nOctave is factor of 2.\r\n\\\\\r\n\\\\\r\n{\\bf Central Forces:} $\\vec{a}(r)=f(r) \\hat{r}$.  \r\n$(\\ddot{r}-r{\\dot{\\theta}}^2)=f(r)$ and (conservation of angular momentum),\r\n$(r \\ddot{\\theta} + 2 \\dot{r} \\dot{\\theta})=0$. $r^2 \\dot{\\theta}=h$.\r\n$u= {\\frac {1} {r}}$ implies ${\\frac {d^2 u}{d \\theta^2}} + u = {\\frac k {h^2}}$,\r\n$k= GM$, $h$ is angular momentum.  \r\nThen $r= {\\frac {h^2}{k(1+e cos( \\theta ))}}$.  If \r\n$V(r)= - \\int f(r) dr$, ${\\frac 1 2} m({\\dot {r}}^2 +r^2 {\\dot{\\theta}}^2)+V(r)= E$;\r\nellipse if $E<0$, parabola if $E=0$, hyperbola if $E>0$.\r\n\\\\\r\n\\\\\r\n{\\bf Rotating frames:}\r\nSuppose $XYZ (F)$ is inertial system and $xyz (M)$ is rotating frame with\r\na common origin $O$.\r\n$({\\frac {d{\\vec A}} {dt}})_{|F} =({\\frac {dA} {dt}})_{|M} + \\omega \\times \\vec {A}$.\r\n$ {D_F}^2 \\vec{r}= {D_M}^2 \\vec{r} + {D_M} (\\vec{ \\omega} ) \\times \\vec {r}+\r\n2 \\vec{ \\omega} \\times {D_M} \\vec{r}+\r\n\\vec{\\omega} \\times (\\vec{\\omega} \\times \\vec{r})$.  Last two terms are coriolis and\r\ncentripetal.  If $O$ is moving too,\r\n$D_F (\\vec{r})= \\dot{R} +D_M  \\vec{r} + \\vec { \\omega} \\times \\vec{r}$ and\r\n$ {D_F}^2 \\vec{r}= \\ddot{R} + {D_M}^2 \\vec{r} + {D_M} (\\vec{ \\omega}) \\times \\vec {r}+\r\n2 \\vec{ \\omega} \\times {D_M} \\vec{r}+\r\n\\vec{\\omega} \\times (\\vec{\\omega} \\times \\vec{r})$.  Object dropped from rotating sphere from\r\na height $h$ is\r\ndeflected by ${\\frac 1 3} \\omega g t^3 sin( \\lambda)$, \r\nwhere $\\lambda$ is the colatitude.\r\n\\\\\r\n\\\\\r\n{\\bf Foucault} (constrained to horizontal plane):\r\n$m \\ddot{x} = -T ({\\frac x l}) + 2m \\omega \\dot {y} cos ( \\lambda )$,\r\n$m \\ddot{y} = -T ({\\frac y l}) - 2m \\omega (\\dot{x} cos (\\lambda )- \\dot{z} sin (\\lambda ))$,\r\n$m \\ddot{z} = -T ({\\frac {l-z} l}) -mg + 2m \\omega \\dot {y} sin ( \\lambda )$,\r\n$\\hat{n}= i sin(\\omega cos ( \\lambda ) t) + j cos(\\omega cos ( \\lambda ) t)$.\r\n\\\\\r\n\\\\\r\n{\\bf Navigation and accelerometers:}\r\nRoll is $R_x(\\phi)=\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0 \\\\\r\n0 & cos(\\phi) & -sin(\\phi) \\\\\r\n0 & sin(\\phi) & cos(\\phi) \\\\\r\n\\end{array}\r\n\\right)$. \\\\\r\nPitch is $R_y(\\theta)=\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos(\\theta) & 0 & -sin(\\theta) \\\\\r\n0 & 1 & 0 \\\\\r\nsin(\\theta) & 0 & cos(\\theta) \\\\\r\n\\end{array}\r\n\\right)$.\r\nYaw is $R_z(\\psi)=\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos(\\psi) & -sin(\\psi) & 0\\\\\r\nsin(\\psi) & cos(\\psi) & 0\\\\\r\n0 & 0 & 1 \\\\\r\n\\end{array}\r\n\\right)$.\r\nEarth orientation to body orientation is done by $R_{xyz}= R_x(\\phi)R_y(\\theta)R_z(\\psi)$.\r\nSo accelerometer reading is $G_p = R_{xyz} (0, 0, 1)^T$ and $h = {\\frac {G_p} {||G_p||}} =\r\n\\left(\r\n\\begin{array}{c}\r\n-sin(\\theta) \\\\\r\ncos(\\theta) sin(\\psi) \\\\\r\ncos(\\theta) cos(\\psi) \\\\\r\n\\end{array}\r\n\\right)$. For tilt orientation,\r\n$tan(\\psi_{xyz}) = {\\frac {h_y} {h_z}}$.\r\n$tan(\\theta_{xyz}) = {\\frac {-h_x} {\\sqrt{{h_y}^2 + h_z^2}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Rotation in plane:}\r\n$I= \\int r^2 dm$.  $\\vec{\\Omega}=I \\vec{\\omega}$, $T={\\frac 1 2} I \\omega^2$\r\n$\\vec{\\Lambda}= I \\dot{\\vec{\\omega}}$.\r\n\\emph{Parallel axis theorem:} $I_A =  I_{CM} +mb^2$.\r\n\\emph{Perpendicular axis theorem:} $I_x= I_y + I_z$.  \r\n$I_{\\small{sphere}}= {\\frac 2 5} m a^2$.\r\n$I_{\\small{cylinder}}= {\\frac 1 2} m a^2$.\r\n$I_{\\small{plate}}= {\\frac 1 {12}} m (a^2 + b^2)$.\r\n$I_{\\small{rod}}= {\\frac 1 {12}} m L^2$ (center of mass).\r\n\\\\\r\n\\\\\r\n{\\bf Rotation in space:}\r\n$\\Omega= \\sum m_{\\mu} (r_{\\mu} \\times (\\omega \\times r_{\\mu}))$,\r\n$[(r_{\\mu} \\times (\\omega \\times r_{\\mu})]_x= \r\n{\\omega_x}^2({y_{\\mu}}^2 + {z_{\\mu}}^2) -\\omega_y x_{\\mu} y_{\\mu} - \\omega_z x_{\\mu} z_{\\mu}\r\n$,\r\n$I_{xx}= \\int (y^2 + z^2) dm$,\r\n$I_{xy}= - \\int (xy) dm$, ${\\cal I}= \r\n\\left(\r\n\\begin{array}{ccc}\r\nI_{xx} &  I_{xy} &  I_{xz} \\\\\r\nI_{yx} &  I_{yy} &  I_{yz} \\\\\r\nI_{zx} &  I_{zy} &  I_{zz} \r\n\\end{array}\r\n\\right)$ is the \\emph{inertia tensor}.  $T= {\\frac 1 2} \\omega \\cdot \\Omega$ is kinetic energy.\r\n\\emph{Principal Axis Theorem:} If \r\n$\\omega_1, \\omega_2, \\omega_3$ and $\\Omega_1, \\Omega_2, \\Omega_3$ \r\nare the angular velocities\r\nand momenta about the principal axis,\r\n$\\Omega_i = I_i \\omega_i$ and \r\n$T= {\\frac 1 2} ( I_1 \\omega_1^2 + I_2 \\omega_2^2 + I_3 \\omega_1^3) $.\r\n\\emph{Ellipsoid of rotation:} \r\nLet $\\hat{n}$ be a unit vector in the direction of $\\hat{\\omega}$,\r\n$\\vec{\\omega}= \\hat{n} \\omega = \\omega (i cos(\\alpha ) + j cos (\\beta ) + k cos (\\gamma ))$.\r\n$T= {\\frac 1 2} I \\omega^2$ where\r\n$I= \r\nI_{xx} cos^2 ( \\alpha) +\r\nI_{yy} cos^2 ( \\beta ) +\r\nI_{zz} cos^2 ( \\gamma ) \r\n+2 I_{xy} cos( \\alpha) cos( \\beta ) + 2 I_{xz} cos(\\alpha) cos( \\gamma )\r\n+2 I_{yz} cos( \\beta ) cos( \\gamma )$. $\\rho= {\\frac {\\hat{n}} {\\sqrt {I}}}$ \r\nis ellipsoid of revolution.\r\n\\emph{Rotational symmetry about $s=z$ axis:}  $I_s=I_z$, $I=I_x=I_y$.\r\n$I {\\dot {\\omega}}_x + \\omega_y \\omega_z (I_s-I)=0$,\r\n$I {\\dot {\\omega}}_y + \\omega_x \\omega_z (I- I_s)=0$, $I_s {\\dot {\\omega}}_z=0$.\r\n${\\vec J}_s= const$,  put $\\gamma = {\\frac {I_s-I} {I}} \\omega_s$; then\r\n${\\dot {\\omega}}_x + \\gamma \\omega_y=$,\r\n${\\dot {\\omega}}_y - \\gamma \\omega_x=$, so\r\n${\\ddot {\\omega}}_x + \\gamma^2 \\omega_x=0$ and $T_p= {\\frac {2 \\pi} {\\gamma}}$.\r\n\\emph{Precession of Earth:}\r\n$T_p= {\\frac {2 \\pi I} {\\omega_z (I_s-I)}} \\approx 305 days$.\r\n\\emph{Precession of Disc:}\r\n$T_p= {\\frac {2 \\pi} {\\omega_z }}$.\r\n\\\\\r\n\\\\\r\n{\\bf Gyroscope: }\r\n$J_{x'}= I_{x'} \\omega_{x'}= I {\\dot {\\theta}}$,\r\n$J_{y'}= I \\varphi sin ( \\theta )$,\r\n$J_{z'}= I_s S$.\r\n$S= {\\dot {\\varphi}} cos( \\theta ) + {\\dot {\\phi}}$,\r\n$I_s {\\dot S}=0$.\r\n\\\\\r\n\\\\\r\n{\\bf Euler's equations:} Let $O$ be a principal axis coordinate system fixed\r\nin a body, the external torque is $\\vec {\\Lambda}$.\r\n$I_1 {\\dot{\\omega}}_1 + (I_3 - I_2) \\omega_2 \\omega_3 = \\Lambda_1$,\r\n$I_2 {\\dot{\\omega}}_2 + (I_1 - I_3) \\omega_1 \\omega_3 = \\Lambda_2$,\r\n$I_3 {\\dot{\\omega}}_3 + (I_2 - I_1) \\omega_1 \\omega_2 = \\Lambda_3$ along\r\nthe principal axes.\r\n$\\omega \\cdot \\Omega=c$ is invariant plane. The angular velocity and momentum in\r\nterms of the Euler angles $\\phi,\\theta, \\psi$, from $O_{xyz}$ fixed in space\r\nto $O_{x'y'z'}$ is:\r\n$\\omega_{x'}= \\dot{\\phi} sin( \\theta ) sin ( \\psi ) + \\dot { \\theta} sin ( \\psi )$,\r\n$\\omega_{y'}= \\dot{\\phi} sin( \\theta ) cos ( \\psi ) - \\dot { \\theta} sin ( \\psi )$,\r\n$\\omega_{z'}= \\dot{\\phi} cos( \\theta ) + \\dot { \\psi }$, $\\phi$ is from $x$ to line of\r\nnodes, \r\n$\\theta$ is from $z$ to $z'$ axis, and, \r\n$\\psi$ is from line of nodes to $x'$;\r\n$T= {\\frac 1 2}(I_1 {\\omega_1}^2+ I_2 {\\omega_2}^2 + I_3 {\\omega_3}^2)$.\r\n\\emph{Top:}  Suppose $\\vec{e}_3$ is the axis of top's line of symmetry.\r\n$\\vec{s}= s\\vec{e_3}= \\dot {\\psi} \\vec{e_3}$.\r\n$\\Omega= I_1 \\omega_1 e_1 + I_2 \\omega_2 e_2 + I_3 (\\omega_3 +s) e_3$, \r\n$\\Lambda= l e_3 \\times mg= ({\\frac {d \\Omega} {dt}})_F, I_1=I_2$.\r\n$ ({\\frac {d \\Omega} {dt}})_F= ({\\frac {d \\Omega} {dt}})_B + \\omega \\times \\Omega$.\r\n$I_1 {\\dot{\\omega}}_1 + (I_3 - I_2) \\omega_2 \\omega_3 = mgl sin ( \\theta )$, \r\n$I_2 {\\dot{\\omega}}_2 + (I_1 - I_3) \\omega_1 \\omega_3 - I_3 \\omega_1 s= 0$,\r\n$I_3 (\\dot{\\omega_3} + \\dot{s})= 0$. In Euler angles, with $\\psi=0$, this is\r\n$\\omega_1= \\dot{\\theta}$, $\\omega_2= \\dot{\\psi} sin (\\theta )$,\r\n$\\omega_3= \\dot{\\psi} cos ( \\theta )$. $\\dot{\\theta},\\dot{\\psi}, s$ are angular velocity\r\nof precession, nutation and spin.\r\n\\\\\r\n\\\\\r\n{\\bf Hamilton-Lagrange and variational methods:}\r\n\\emph{Holonomic constraint:} $\\phi(q_1 , q_2 , ... ,q_n , t)=0$.  \\emph{Generalized\r\ncoordinates:}\r\n$\\delta W= \\sum_{\\alpha} \\Phi_{\\alpha} \\delta q_{\\alpha}$,\r\n$\\Phi_{\\alpha} =\r\n\\sum \\vec{f} \\cdot {\\frac {\\partial r} {\\partial q_{\\alpha}}}$.  \r\n\\emph{Lagrange equations:} $({\\frac d {dt}})\r\n{\\frac {\\partial T} {\\partial {\\dot {q}}_{\\alpha}}}-\r\n{\\frac {\\partial T} {\\partial q_{\\alpha}}}= \\Phi_{\\alpha}$.  \r\nIf the forces are all conservative and $L=T-V$ then\r\n$({\\frac d {dt}})\r\n{\\frac {\\partial L} {\\partial {\\dot {q}}_{\\alpha}}}-\r\n{\\frac {\\partial L} {\\partial q_{\\alpha}}}= 0$.  \\emph{Generalized momentum:}\r\n$p_{\\alpha}= {\\frac {\\partial T} {\\partial {\\dot q}_{\\alpha}}}$.\r\n\\emph{Hamilton:}\r\n$H(p_1 , ..., p_, q_1 , ..., q_n , t)= \\sum p_{\\alpha} \\dot{q_{\\alpha}} - L$.\r\n$\\dot{p_{\\alpha}}= -{\\frac {\\partial H} {\\partial q_{\\alpha}}}$,\r\n$\\dot{q_{\\alpha}}= {\\frac {\\partial H} {\\partial p_{\\alpha}}}$.\r\n\\emph{Hamilton Principal:} For conservative forces ($H=T+V$),\r\n$L=T-V$, $\\delta \\int_{t_1}^{t_2} L dt = 0$.  \r\nNote: $H= \\sum p_{\\alpha} \\dot{q_{\\alpha}} - L$.\r\n\\emph{Modern setting:} $S= \\int_{t_1}^{t_2} L(q_i, {\\dot {q}}_i) \\thinspace dt$.\r\n$L(x_i, {\\dot x}_i)= {\\frac m 2} {\\dot x}_i^2-V(x_i)$.  If $L$ is independent of $q_i$,\r\n$p_i= {\\frac {\\partial L}{\\partial {\\dot q}_i}}$ is conserved.  $H(q_i, p_i)= p_i{\\dot q}_i -L(q_i {\\dot q}_i)$,\r\nthis can be expressed in terms of $q_i, {\\dot q}_i$ \r\nprovided $[{\\frac {\\partial^2 L} {\\partial {\\dot q}_i \\partial {\\dot q}_j}}]_{ij}$ is invertible.\r\n$dH= {\\dot q}_i dp_i - {\\frac {\\partial L}{\\partial q_i}} d q_i$.  On Euler trajectory,\r\n${\\frac {\\partial H}{\\partial p_i}} = {\\dot q}_i$ and\r\n${\\frac {\\partial H}{\\partial q_i}} = -{\\dot p}_i$, $H$ is conserved.  Let $A(q,p)$ be a function.\r\n${\\frac {dA}{dt}}=\r\n{\\frac {\\partial A}{\\partial q}} {\\frac {\\partial H}{\\partial p}}\r\n-{\\frac {\\partial A}{\\partial p}} {\\frac {\\partial H}{\\partial q}}= [A,H]$.  This is the\r\n\\emph{Poisson bracket}; $[q_i, q_j]=[p_i, p_j]=0$ and $[p_i,q_j]= \\delta_{ij}$.  Under\r\n$T: q_i \\mapsto q_i + \\epsilon f_i(q)$, $Q= p_i f_i(q)$ is conserved and\r\n$[q_j, Q]= f_j(q)$, $\\delta q_j= \\epsilon [q_j, Q]$; the conserved quantity is a generator of the\r\nsymmetry.\r\n\\section{Thermodynamics and Statistical Mechanics}\r\n{\\bf Rubric for Statistical Mechanics:}  Consider a system with total energy \r\n$E^*$ consisting of two subsystems $A$ and $A'$ in thermal\r\nequilibrium.  Suppose $A$ has energy $E$ and $A'$ has energy $E'= E^*-E$.  \r\nLet $\\Omega^*(E)$ be the number of\r\nstates accessible to the system when $A$ has energy $E$ then\r\n$\\Omega^*(E)= \\Omega(E) \\Omega(E')$.  If $P(E)$ is the probability of having $A$ in energy state $E$,\r\n$P(E)= C \\Omega^*(E)= C \\Omega(E) \\Omega'(E')$.  Thermal equilibrium favors the\r\nlargest number of accessible\r\nstates.  This happens when $P(E)$ and hence $ln(P(E))$ is maximum or when\r\n${\\frac {\\partial ln(P(E))} {\\partial E}} = 0$ or equivalently when\r\n$ {\\frac {\\partial {ln(\\Omega(E))}} {\\partial E}}+\r\n{\\frac {\\partial {ln(\\Omega'(E'))}} {\\partial E}}= 0$.  This occurs when\r\n$\\beta(E)= {\\frac 1 {\\Omega(E)}} {\\frac {\\partial {\\Omega(E)}} {\\partial E}}=\r\n{\\frac 1 {\\Omega'(E')}} {\\frac {\\partial {\\Omega(E')}} {\\partial E'}}= \\beta'(E')$.\r\n$\\beta(E)$ characterizes the temperature and we define $\\beta(E)= {\\frac 1 {kT}}$.  Putting $S= k ln(\\Omega)$,\r\n${\\frac 1 {kT}}= {\\frac {\\partial S} {\\partial E}}$.  For distribution of states, imagine\r\n$A$ is in start $r$ with energy $E_r$.  $P(E_r) \r\n\\Omega'(E^*-E_r)$.  By Taylor, $ln(\\Omega(E^* - E_r))= ln(\\Omega(E^*))- {\\frac {\\partial \\Omega} {\\partial E}} E_r$\r\nand we get the familiar $P(E_r)= C e^{- {\\frac {E_r} {kT}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Basic pattern:}\r\nIn canonical ensemble, $\\langle E \\rangle$ and the number of particles, $N$, is fixed.\r\nIn \\emph{grand canonical ensemble}, $\\langle E \\rangle$ and $\\langle N \\rangle$ are fixed.\r\nLet $| i \\rangle$ be the microstates; $\\sum a_i = A$, $\\sum_i a_i E_i = AE$; the number\r\nof configurations is \r\n$W({\\vec a})= {\\frac {A!} {\\prod_i a_i!}}$ and $P_i= {\\frac {a_i} A}$.  To find\r\n$\\langle {\\overline {a_i}} \\rangle$, maximize $ln(W({\\vec a}))$, we use Lagrange \r\nmultipliers and the two constraints, namely, solve\r\n$L({\\vec a})= ln(W({\\vec a})) + \\alpha (A- \\sum_i a_i) + \\beta (AE- \\sum_i a_i E_i)= 0$\r\nand ${\\frac {\\partial L({\\vec a})} {\\partial a_j}} =0$.  \r\nSystems in thermal equilibrium have same $\\beta= {\\frac 1 {kT}}$.  \r\n$Z= \\sum_i e^{-\\beta E_i}$ and\r\n$\\langle E \\rangle = {\\frac {\\partial Z}{\\partial \\beta}}$.  \r\n$dE= TdS - P dV$.  $\\beta \\mu= - \\gamma$ is the\r\nchemical potential.  \r\n\\\\\r\n\\\\\r\n{\\bf First law:} $\\Delta Q$: heat into system,\r\nIf $\\Delta W$: work on system,\r\n$\\Delta E$: increase in energy of system then\r\n$\\Delta Q + \\Delta W= \\Delta E $.  \r\nFor ideal gas, $PV= E= \r\n{\\frac 2 3}N \\langle {\\frac {mv^2} 2} \\rangle = nRT= NkT$.\r\nIn general, $PV= (\\gamma - 1) U$ ($\\gamma = {\\frac 5 3}$ for ideal gas).\r\n$ ({\\frac {\\partial U} {\\partial T}})_V= C_v= {\\frac 3 2} R$, $\r\n({\\frac {\\partial U} {\\partial T}})_p= C_p= C_v + R$, for adiabatic process: $pV^{\\gamma}=c$,\r\n$\\gamma= {\\frac {C_P} {C_V}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Second Law:} It is impossible to build a cyclic engine that converts thermal\r\nenergy completely into mechanical work.  \r\n\\\\\r\n\\\\\r\n{\\bf Carnot Process:}\r\n$1 \\rightarrow 2$: gas placed on hot reservoir at $T_H$ adding $Q_H$, isothermally;\r\n$2 \\rightarrow 3$: gas expands and does work adiabatically;\r\n$3 \\rightarrow 4$: gas placed on cold reservoir at $T_C$, removing heat $Q_C$ isothermally;\r\n$4 \\rightarrow 1$: work done on gas adiabatically. $e= 1- {\\frac {T_C} {T_H}}$.\r\nFor reversible process,\r\n$S= \\int {\\frac {dQ} {T}} \\geq 0$. $S= Nk_B ln(\\Omega)$.  In irreversible process,\r\nentropy increases, at $T=0$, $S=0$.  For reversible process, $S = {\\frac {Q_1} {T_1}}\r\n= {\\frac {Q_2} {T_2}}$, $W= Q_1 - Q_2= Q_1 (1 - {\\frac {T_2} {T_1}})$; \r\n$\\textnormal{eff}={\\frac W {Q_1}}= {\\frac {T_2 - T_1} {T_1}}$. $S=k ln(W)$.\r\n$e= 1- {\\frac {T_C}{T_H}}$.\r\n$(c_v)_{\\textnormal{monatomic}}= {\\frac 3 2} R$,\r\n$(c_v)_{\\textnormal{diatomic}}= {\\frac 5 2} R$,\r\n$(c_p)_{\\textnormal{monatomic}}= {\\frac 5 2} R$.\r\n\\\\\r\n\\\\\r\n{\\bf Statistical Mechanics:}\r\nFor \\emph{monatomic gas}, \r\n$P= {\\frac 2 3} U= (\\gamma -1) U = {\\frac 2 3} \\langle m v^2 \\rangle=\r\n{\\frac 3 2} kT$. In a mixture at constant temperature\r\nwith two species $1$ and $2$, \r\n$n_1 \\langle m_1 {v_1}^2 \\rangle = n_2 \\langle m_2 {v_2}^2 \\rangle$ \r\nbut considering two particles with\r\nrelative velocity $w$ with  velocity of enter of mass $v_{CM}$ we can argue at equilibrium\r\nthat $\\langle w \\cdot V_{CM} \\rangle = 0$ so $n_1=n_2$ (Avogadro's hypothesis).\r\n$v_{\\textnormal{rms}}= \\sqrt{{\\frac {3RT} {M}}}$.\r\nFor \\emph{photon gas},\r\n$PV= N \\langle p \\cdot v \\rangle /3$ so $\\gamma = {\\frac 4 3}$.  \r\nFor a \\emph{diatomic gas} $\\gamma= {\\frac 9 7}$.\r\n$S= k ln(W)$, $\\Delta S = k ln({\\frac {W_f} {W_i}})$ and \r\n${\\frac {\\partial S} {\\partial E}}= {\\frac 1 T}$ and $\\Delta S = \\int_i^f {\\frac {dQ} T}$.\r\n$N_M(E_n)= N A e^{-E_n / kT}$ and $D(E)= {\\frac {dn} {dE}}$.  $dN = N \\times D dE$.\r\nFor Bosons:\r\n$D_B(E)= {\\frac {8 \\pi V} {h^3 c^3}} E^2$.  For\r\n$E_{\\small{internal}}= \\int_0^{\\infty} E {\\frac 1 {e^{E/kt} -1}} {\\frac {8 \\pi V} {h^3 c^3}}\r\nE^2 dE = {\\frac {8 \\pi k } {15 h^3 c^3}} V T^4$.\r\n$C_v = {\\frac {\\partial E_{\\small{internal}}} {\\partial T}}$.\r\nFor insulators, $C_v= 3R$ and\r\nfor conductors, $C_v= {\\frac 9 2}R$.  $F= E-TS$.\r\nFor ideal gas, $C_v= {\\frac {3}{2}}R$.\r\n$Z= \\sum_j e^{\\beta E_j}$ and $\\langle E \\rangle = -{\\frac {\\partial ln(Z)} {\\partial \\beta}}$.\r\nIf $I_n= \\int_{0}^{\\infty} e^{-\\alpha x^2} x^2 dx$ then $I_n= {\\frac {n-1} {2 \\alpha}} I_{n-2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Atmosphere:}\r\n${\\frac {dn} {dh}}= -{\\frac {mg} {kT}}n$, $n= n_0 e^{-PE/kT}$ and\r\n${\\frac {n_{>u}} {n<u}} = e^{-KE/kT}$.  \\emph{Evaporation model:} \r\n$W$ is binding energy of \r\nliquid, $n$ is density of vapor, $1/V_a$ is density of liquid then $nV_a = e^{-W/kT}$.\r\n\\emph{Chemical kinetics:} ${\\frac {n_A n_B} {n_{AB}}}= ce^{W/kT}$.  \r\n\\emph{Diffusion:} Average time to collision is \r\n${\\frac 1 {n_0}} \\int_0^{\\infty} t {\\frac {N(t) dt} {\\tau}}$, $N=N_0 e^{t/ \\tau}$.\r\n\\emph{Mean Free Path:}\r\n$l= \\tau v= {\\frac 1 {n \\sigma}}$; for dilute gas, \r\n$l= {\\frac {RT}{{\\sqrt 2} \\pi d^2 N_A P}}$.\r\n\\emph{Thermal conductivity:} ${\\frac 1 A} {\\frac {dQ} {dt}} = - \\kappa \r\n{\\frac {dT} {dz}}$, $\\kappa = {\\frac {knlv} {\\gamma-1}}$ if $MFP<<$ container.\r\n\\\\\r\n\\\\\r\n\\emph{Maxwell Distribution:}\r\n$F_{MB}= N ({\\frac {m} {2 \\pi k T}})^{\\frac 3 2} e^{-m (v_x^2+v_y^2+v_z^2)/(2kT)}$, the frequency\r\nof a particle around $v$;  $dn_{\\nu}= F_{MB} g(q) dq$.\r\n$v_{rms}= {\\sqrt {\\frac {3kT} {m}}}$.\r\n\\\\\r\n\\emph{Bose-Einstein Distribution (Bosons):}\r\n$F_{BE}= (e^{\\alpha} e^{E_i/kT} - 1)^{-1}$, $\\alpha$ is type specific $0$ for photon.\r\n\\\\\r\n\\emph{Fermi-Dirac Distributions (Fermions):}\r\n$F_{FD}= (e^{(E_i-E_f)/kT} + 1)^{-1}$, $E_f$ is the \\emph{Fermi energy}. \r\n$C_V= {\\frac 1 N} ({\\frac {\\partial E} {\\partial T}})_V$ approximately $3R$ for\r\nmany solids.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n\\emph{Conductor:} half filled conduction band.  \r\n\\emph{Insulator:} filled conduction band large gap $\\approx 5 ev$.\r\n\\emph{Semiconductor:} filled conduction band small gap $\\approx 1 ev$ which can \r\nbe overcome by thermal excitation.  \r\n\\emph{Electron mobility:} $\\mu={\\frac {v_d} {E}}$, $v_d$ is drift velocity.  \r\n\\emph{Fine constant:} ${\\frac {ke^2} {\\hbar c}} \\approx {\\frac 1 {137}}$.  \r\n\\emph{Josephson junction} is\r\ntwo superconductors separated by thin $\\approx 1 nm$ insulator; if there is no potential\r\ndifference, electrons tunnel and we get dc, if dc potential is applied, we get ac with\r\n$f \\approx {\\frac {2eV}{h}}$.\r\n\\section{Quantum Mechanics}\r\n{\\bf Schrodinger and its discontents:}\r\n$-{\\frac {\\hbar^2} {2m}} {\\frac {\\partial^2 \\Psi (x, t)} {\\partial x^2}} +\r\nU \\Psi(x,t)= i \\hbar {\\frac {\\partial \\Psi(x,t)} {\\partial t}}$, $\\int_S |\\Psi|^2 =1$.  \r\n$\\langle Q(x,p)\\rangle= \r\n\\int \\Psi^* Q(x,{\\frac {\\hbar} {i}}{\\frac {\\partial}{\\partial x}}) \\Psi dx$.\r\n$\\hat{H}= -{\\frac {\\hbar^2} {2m}} {\\frac {\\partial^2} {{\\partial x}^2}} + V(x)$.\r\nSeparation of variables (for well defined\r\nenergy): $\\Psi(x,t)= \\varphi(x) \\phi(t)$. \r\n$-{\\frac {\\hbar^2} {2m}} \\varphi''(x) \\phi(t) + \r\nU \\varphi(x) \\phi(t)= i \\hbar \\varphi(x) {\\dot \\phi}(t)$. \r\nSo $-{\\frac {\\hbar^2} {2m}} {\\frac {\\varphi''(x)} {\\varphi(x)}} + U = E=\r\ni \\hbar {\\frac {{\\dot \\phi}(t)} {\\phi(t)}}$. $\\phi(t)= A e^{-i(E/\\hbar)t}$,\r\n$E= \\hbar \\omega$.  $E=K+U$; system is \\emph{bound} if $K_0<U_0$.  The\r\nremaining time-independent equation is\r\n$\\varphi'(x)= k^2 (V-E) \\varphi(x), k^2= {\\frac {2m(V-E)} {\\hbar^2}}$.  \r\nIf $V-E>0$ (bound states), the solution is \r\n$\\varphi(x)= A e^{kx}+ B e^{-kx}$.\r\nIf $V-E<0$ (scattering), the solution is \r\n$\\varphi(x)= A e^{ikx}+ B e^{-ikx}$ or\r\n$\\varphi(x)= A cos(kx)+ B sin(kx)$.\r\nNote that for solution when separation of variables is possible, $|\\Psi|^2$ is time \r\nindependent.  \r\nIf $Q(x,p)$ is an operator,\r\n$\\langle Q \\rangle = {\\frac {i} {\\hbar}} [H, Q] + \\langle {\\frac {\\partial Q} {\\partial t}} \\rangle$.\r\nConsider the usual harmonic potential $V(x) = {\\frac 1 2} m \\omega^2 x^2$ in Schroedinger's equation:\r\n${\\frac {1} {2m}}[{\\frac {\\hbar} {i}} {\\frac {d^2 \\Psi}{dx^2}} + {\\frac 1 2} m^2 \\omega^2 x^2 \\Psi]= E \\Psi$.\r\nDefine $a_{\\pm} = {\\frac 1 {\\sqrt {2m}}} ({\\frac {\\hbar} {i}} {\\frac d {dx}} \\pm i m \\omega x)$.\r\n$a_+ a_- = {\\frac {1} {2m}}[{\\frac {\\hbar} {i}} {\\frac {d^2 \\Psi}{dx^2}} + {\\frac 1 2} m^2 \\omega^2 x^2 \\Psi] - \r\n{\\frac 1 2} \\hbar \\omega$.  If $\\Psi$ solves the Schroedinger equation with energy $E$, $a_+ \\Psi$  solves\r\nthe Schroedinger equation with energy $E + \\hbar \\omega$.\r\n\\\\\r\n\\\\\r\n{\\bf Potential well:}  \r\nRegion $1$: $x<0, U=U_0$; \r\nRegion $2$: $0 \\le x \\le L, U=0$; \r\nRegion $3$: $x > L, U=U_0$.  \r\nFor infinite potential, applying\r\n$\\varphi_1(0)= \\varphi_2(0)=0$,\r\n$\\varphi_2(L)= \\varphi_3(L)=0$ leads to quantization, \r\n${\\sqrt {\\frac {2mE}{\\hbar^2}}} = n \\pi$, $E_n= {\\frac {n^2 \\pi^2 \\hbar^2} {2mL^2}}$,  \r\n$\\varphi_n(x)= {\\sqrt {\\frac 2 L}} sin({\\frac {n \\pi x} 2})$.  $E_0$ is the ground state.\r\nFor finite potential with bound states ($V>E$),\r\n$\\varphi_1(x)= A_1 e^{k_1 x} +B_1 e^{-k_1 x}$,\r\n$\\varphi_2(x)= A_2 cos(k_2 x) +B_2 sin(k_2 x)$,\r\n$\\varphi_3(x)= A_3 e^{k_3 x} +B_3 e^{-k_3 x}$\r\nwith $\\varphi_1(0)= \\varphi_2(0)$, $\\varphi_2(L)= \\varphi_3(L)$ and\r\n$\\varphi_2'(0)= \\varphi_3'(0)$, $\\varphi_2'(L)= \\varphi_3'(L)$.  Due to square integrable\r\ncondition, $B_1=A_3=0$. \r\n$k_1^2= {\\frac {2m(V-E)}{\\hbar^2}}= k_3^2=k$ and\r\n$k_2^2= {\\frac {2m(E)}{\\hbar^2}}= \\kappa^2$.  Solutions are even or odd.  For even\r\nsolutions, $B_2=0$.\r\nApplying boundary condition, \r\n$B_3 e^{-kL}=A_3 cos(\\kappa L)$ and\r\n$-k B_3 e^{-kL}= - \\kappa A_3 sin(\\kappa L)$.  Dividing the two equations gives\r\n$k= \\kappa tan(\\kappa L)$.\r\n\\\\\r\n\\\\\r\n{\\bf Free Particle:} \r\n$\\varphi''(x)= - k^2 \\varphi$, $k^2= {\\frac {2mE} {\\hbar^2}}$.\r\n$\\varphi(x)= A e^{i(kx+{\\frac {\\hbar k^2}{2m}}t)}\r\nB e^{i(kx-{\\frac {\\hbar k^2}{2m}}t)}$.  There is no solution for free particle with \r\ndefinite energy $E$ but $\\Psi(x,t)= {\\frac 1 {\\sqrt {2m}}} \\int_{\\infty}^{\\infty} \\psi(k)\r\ne^{i(kx- \\omega t)} dk$, $\\omega= {\\frac {\\hbar k^2}{2m}}$.\r\n\\\\\r\n\\\\\r\n\\emph{Dispersion} is the relationship between frequency ($\\omega$)\r\nand wave number ($k$).  Examples:\r\n$v_{\\small {phase}} = {\\frac {\\omega} {k}}$ for EM waves,\r\n$v_{\\small {phase}} = \r\n{\\frac {\\omega} {k}} = {\\frac {mc^2} { \\hbar k}} + {\\frac {\\hbar k} {2m}} $ for matter waves.\r\n$v_{\\small {group}} = {\\frac {d} {dk}} (ck)= c$ for EM waves,\r\n$v_{\\small {group}} = \r\n{\\frac {d} {dk}} ({\\frac {mc^2} { \\hbar k}} + {\\frac {\\hbar k} {2m}} )\r\n= {\\frac {\\hbar k_0} {m}}$ for matter waves.\r\nTransmission rate for matter waves through potential barrier is\r\n${\\frac { sinh^2( \\alpha L)}\r\n{sinh^2( \\alpha L) + {\\frac {\\alpha^2 k^k} {(k^2 + \\alpha^2)^2}}} }$.\r\nReflection rate for matter waves through potential barrier is\r\n${\\frac {(k^2 + \\alpha^2)^2} {sinh^2( \\alpha L) + \r\n{\\frac {\\alpha^2 k^k} {(k^2 + \\alpha^2)^2} }} }$.\r\n\\\\\r\n{\\bf Resonant transmission:} $E = U_0 + {\\frac {n^2 \\pi^2 \\hbar^2} {2 m L^2}}$.\r\n$n_{plasma}= {\\sqrt {1- {\\frac {\\omega_p^2} {\\omega \\omega_m}}}}, \\omega_m= {\\frac {e B_0}{m}}$.\r\n$v_p v_g= c^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Hydrogen atom:}  In polar coordinates,\r\n$\\nabla^2 = {\\frac 1 {r^2}} [\r\n{\\frac {\\partial} {\\partial r}} (r^2 {\\frac {\\partial} {\\partial r}}) +\r\ncsc(\\theta) {\\frac {\\partial} {\\partial \\theta}} (sin(\\theta) {\\frac {\\partial} {\\partial \\theta}})+\r\ncsc^2(\\phi) {\\frac {\\partial^2} {\\partial \\theta^2}}]$.   For H,\r\n$\\phi(r, \\theta, \\phi)= R(r) \\Theta(\\theta) \\Phi(\\phi)$.\r\nSchroedinger becomes\r\n${\\frac 1 {R}} {\\frac {\\partial} {\\partial r}} (r^2 {\\frac {\\partial R} {\\partial r}}) +\r\n{\\frac 1 {\\Theta}} csc(\\theta) {\\frac {\\partial} {\\partial \\theta}} (sin(\\theta) \r\n{\\frac {\\partial \\Theta} {\\partial \\theta}})+\r\ncsc^2(\\phi) [ {\\frac 1 {\\Phi}} {\\frac {\\partial^2 \\Phi} {\\partial \\theta^2}}] \r\n= -r^2 {\\frac {2m(E-U(r))} {\\hbar^2}}$.\r\nTo solve, note that\r\n${\\frac 1 {\\Phi}} {\\frac {\\partial^2 \\Phi} {\\partial \\theta^2}} = c_{\\phi}$ whose solution is\r\n$\\Phi(\\phi)= e^{i m_l \\phi}, m_l 0, \\pm 1, \\ldots$ and $c_{\\phi}= - (m_l)^2$.\r\n$m_l$ is the \\emph{magnetic quantum number}.\r\nAfter substitution, this becomes\r\n${\\frac 1 {R}} {\\frac {\\partial} {\\partial r}} (r^2 {\\frac {\\partial R} {\\partial r}}) +\r\n{\\frac 1 {\\Theta}} csc(\\theta) {\\frac {\\partial} {\\partial \\theta}} (sin(\\theta) \r\n{\\frac {\\partial \\Theta} {\\partial \\theta}})+\r\ncsc^2(\\phi) (-m_l^2) = -r^2 {\\frac {2m(E-U(r))} {\\hbar^2}}$ and\r\n$ {\\frac 1 {\\Theta}} csc(\\theta) {\\frac {\\partial} {\\partial \\theta}} (sin(\\theta) \r\n{\\frac {\\partial \\Theta} {\\partial \\theta}}) = c_{\\theta}$ leads to\r\n$c_{\\theta}= -l(l+1), |m_l| \\le l$ and\r\n$\\Theta_{l, m_l}(\\theta) = P_{l, m_l}(cos(\\theta))$, $|L|= \\hbar \\sqrt{l(l+1)}$.\r\n$l$ is the \\emph{orbital quantum number}.\r\n$L_z = m_l \\hbar$. \r\nFinally, we must solve\r\n${\\frac 1 {R}} {\\frac {\\partial} {\\partial r}} (r^2 {\\frac {\\partial R} {\\partial r}}) - l(l+1)\r\n= -r^2 {\\frac {2m(E-U(r))} {\\hbar^2}}$  and \r\n$E= {\\frac {-m e^4} {2(4 \\pi \\epsilon_0)^2 \\hbar^2}} {\\frac 1 {n^2}}$, $0 \\le l < n$.\r\n$n$ is the \\emph{principal quantum number}.  $E_n= {\\frac {-13.6 \\textnormal{ ev}} {n^2}}$.\r\n$r \\approx n^2 a_0, a_0 = {\\frac {4 \\pi \\epsilon_0 \\hbar^2} {m_l^2}}$.  Some of the solutions\r\nare:\r\n\\begin{center}\r\n\\begin{tabular} {| r | r |}\r\n\\hline\r\n$n, l$ & $R_{n, l}(r)$ \\\\\r\n\\hline\r\n$1,0$ & ${\\frac 1 {(a_0)^{\\frac 3 2}}} e^{-r/a_0}$ \\\\\r\n\\hline\r\n$2,0$ & ${\\frac 1 {2(a_0)^{\\frac 3 2}}} 2(1- {\\frac r {2 a_0}}) e^{-r/(2a_0)}$ \\\\\r\n\\hline\r\n$2,1$ & ${\\frac 1 {2(a_0)^{\\frac 3 2}}} ({\\frac  {4 \\sqrt{2}r} {9 a_0}}) e^{-r/(2a_0)}$ \\\\\r\n\\hline\r\n$3,0$ & ${\\frac 1 {3(a_0)^{\\frac 3 2}}} (2 - {\\frac {4r} {3 a_0}} +\r\n{\\frac {4r^2} {27  a_0^2}}) e^{-r/(3a_0)}$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nand correspondingly,\r\n\\begin{center}\r\n\\begin{tabular} {|r r|}\r\n\\hline\r\n$l, m_l$ & $\\Theta_{l, m_l}(\\theta) \\Phi_{m_l}(\\phi)$ \\\\\r\n\\hline\r\n$0,0$ & ${\\frac {3} {4 \\pi}}$ \\\\\r\n\\hline\r\n$1,0$ & ${\\frac {4} {4 \\pi}} cos(\\theta)$ \\\\\r\n\\hline\r\n$1,\\pm 1$ & ${\\frac {3} {8 \\pi}} sin(\\theta) e^{\\pm i \\phi}$ \\\\\r\n\\hline\r\n$2,0$ & ${\\frac {5} {16 \\pi}} (3 cos^2(\\theta) -1)$ \\\\\r\n\\hline\r\n$2,\\pm 1$ & ${\\frac {15} {8 \\pi}} cos(\\theta) sin(\\theta) e^{\\pm i \\phi}$ \\\\\r\n\\hline\r\n\\end{tabular}.\r\n\\end{center}\r\n\\emph{Spin} adds intrinsic angular momentum: $S= \\sqrt{s(s+1)} \\hbar$.  Electron has spin\r\n$s= \\pm {\\frac 1 2}$.  Spin state is $m_s$.  \\emph{Stern Gerlach:}\r\n$F= \\mu_z {\\frac {\\partial B_z} {\\partial z}} \\hat{z}$, $\\mu_z= -{\\frac e {2m_l}} L_z$.\r\n$S_z = S \\hbar$. \r\n\\\\\r\n\\\\\r\n{\\bf Multiparticle systems:}\r\n${\\frac {- \\hbar^2} {2m}} ( {\\frac {\\partial^2 \\phi(x_1, x_2)} {\\partial x_1^2}}\r\n+ {\\frac {\\partial^2 \\phi(x_1, x_2)} {\\partial x_2^2}}) + U\\phi(x_1, x_2)= E \\phi(x_1, x_2)$.\r\nFirst problem is interparticle force but even without that, \r\nsay two identical particles react only to external forces, we have\r\n${\\frac {- \\hbar^2} {2m}} ( {\\frac {\\partial^2 \\phi_1(x_1)} {\\partial x_1^2}} + \r\nU(x_1) \\phi_1(x_1)+ {\\frac {\\partial^2 \\phi_2(x_2)} {\\partial x_2^2}}) + \r\nU\\phi(x_2)= E_1\\phi_1(x_1)+ E_2 \\phi_2(x_2)$.\r\nThen $C_1= {\\frac {n_1^2 \\pi^2 \\hbar^2} {2mL}}$ and\r\n$C_2= {\\frac {n_2^2 \\pi^2 \\hbar^2} {2mL}}$.  The combined wave function is\r\n$\\phi(x_1, x_2)= \\phi_1(x_1) \\phi_2(x_2)$.  Depending on $n_1$ and $n_2$, one particle\r\ncould have probability $0$ at a location and the other non-zero probability.  But then\r\nparticles can be distinguished which violates \r\n\\emph{exchange symmetry}.  Thus the wave function must be\r\n``symmetrized'' as either\r\n(a)  $\\phi_S(x_1 , x_2) = \\phi_{1}(x_1) \\phi_2(x_2) + \\phi_2(x_1) \\phi_1(x_2)$, or\r\n(b)  $\\phi_A(x_1 , x_2) = \\phi_{1}(x_1) \\phi_2(x_2) - \\phi_2(x_1) \\phi_1(x_2)$.\r\nThe general multiparticle Schroedinger becomes\r\n${\\frac {- \\hbar^2} {2m}} \\sum_i \\nabla_i^2 \\phi(r_1, \\ldots, r_n) +\r\n\\sum_{i<j} U(|r_i - r_j|) +\r\n\\sum_{i} U_i(|r_i - r_j|) = E \\phi(r_1 , \\ldots , r_n)$.  \\emph{Hartree Model:}\r\n$Z(r)= 1 + (Z-1) e^{-br}$.\r\n\\\\\r\n\\\\\r\n{\\bf Spin orbit interaction:} $U= {\\vec {\\mu}}_S \\cdot {\\vec B}_L =\r\n(-g_e {\\frac {e} {2 m_e}} {\\vec S}) \\cdot {\\frac {\\mu_0 e} {4 \\pi m_e r^3}}$.\r\n${\\vec J}= {\\vec L} + {\\vec S}$.  Spin is a relativistic effect,\r\n$L= \\sqrt{l(l+1)} \\hbar$ and\r\n$S= \\sqrt{s(s+1)} \\hbar$.  $\\alpha = {\\frac {e^2} {(4 \\pi \\epsilon_0) \\hbar c}} = {\\frac 1 {137}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Formalism:}\r\nLet $|i \\rangle $ denote base states $ \\langle i|j \\rangle = \\delta_{ij}$.\r\n$|\\psi \\rangle  = \\sum_i |i \\rangle  \\langle i | \\psi \\rangle $,\r\n$\\langle \\psi | \\phi \\rangle  = \\sum_i  \\langle \\phi|i \\rangle   \\langle i | \\psi \\rangle $.\r\n$| \\psi \\rangle  = \\sum_i |i \\rangle   \\langle i|\\psi \\rangle $ evolves under $\\hat {A}$ so\r\n$|\\phi \\rangle  = \\hat{A} |\\psi \\rangle $ and $ \\langle i | \\phi \\rangle  = \\sum_j  \\langle i| \\hat{A} | j \\rangle   \\langle j| \\psi \\rangle $,\r\n$A_{ij}=  \\langle i | \\hat {A} |j \\rangle $.\r\n\\\\\r\n\\\\\r\n{\\bf Observables:}  \r\nSuppose\r\n${\\hat Q} f = \\lambda f$, then $\\Delta Q= 0$ iff ${\\hat Q} \\Psi= {\\overline Q} \\Psi$.  For\r\nmomentum, \r\n${\\hat p} e^{ikx} = - i \\hbar {\\frac {\\partial} {\\partial x}} e^{ikx}= \\hbar k e^{ikx}$;\r\nnote that the eigenvalues are $p= \\hbar k$.\r\nThe observable with eigenvalue $a_n$ has \r\n$P(a_n) = \\sum_{i=1}^{g_n} | \\langle u_n^i | \\Psi \\rangle|^2$.\r\nDensity operator is $\\rho= | \\Psi \\rangle  \\langle \\Psi|$.\r\n\\\\\r\n\\\\\r\n{\\bf Quantum mechanical operators:}\r\n$\\int_{{\\mathbb R}^3} |\\psi({\\vec x})| d{\\vec x}= 1$.\r\n\\emph{Spatial operators:}\r\n$X \\psi= x \\psi$,\r\n$Y \\psi= y \\psi$,\r\n$Z \\psi= z \\psi$, ${\\vec R}= (X,Y,Z)$.\r\n\\emph{Momentum operators:}\r\n$p_x \\psi= -{\\frac {\\hbar} {i}} {\\frac {\\partial} {\\partial x}} \\psi$,\r\n$p_y \\psi= -{\\frac {\\hbar} {i}} {\\frac {\\partial} {\\partial y}} \\psi$,\r\n$p_y \\psi= -{\\frac {\\hbar} {i}} {\\frac {\\partial} {\\partial z}} \\psi$,\r\n${\\vec P}= (p_x, p_y, p_z)$.\r\n\\emph{Angular Momentum:} $L_x=yp_z-zp_y$, etc.\r\n$ \\langle A \\rangle = \\int \\psi^*({\\vec r}) A \\psi({\\vec r}) d {\\vec r}$,\r\n$\\Delta A= {\\sqrt { \\langle A^2 \\rangle - \\langle A \\rangle ^2}}$.\r\n\\emph{Time:} \r\n$T \\psi = t \\psi $.\r\n\\emph{Energy:}\r\n$E \\psi= {\\frac {\\hbar} {i}} {\\frac {\\partial} {\\partial t}} \\psi$.\r\n\\\\\r\n\\\\\r\n{\\bf Axiomatics for Quantum Mechanics:}\r\nElements of state space are denoted: $|\\varphi \\rangle $ and \r\n$(\\phi, \\psi)=  \\langle \\phi | \\psi \\rangle =\r\n{\\overline {\\langle \\psi | \\phi \\rangle }} $,\r\nphysically observable quantities are described by hermitian operators acting on state space:\r\n$A | \\psi \\rangle $, each observable quantity is an eigenvalue of the hermitian operator. \r\n\\begin{quote}\r\n\\emph{Postulate 1:} Associated with any \\emph {isolated}  physical system is a complex\r\nvector space, $V$ with an inner product called a state space.  The system is completely\r\ndescribed by $v \\in V$.\r\n\\\\\r\n\\\\\r\n\\emph{Postulate 2:} The evolution of a closed quantum system is described by a unitary\r\ntransformation on the state: $|\\psi(t_2) \\rangle  = U |\\psi(t_1) \\rangle $.\r\n\\emph{Postulate 2':} \r\nThe non-relativistic evolution of a closed quantum system is described by Schroedinger's\r\nequation $i \\hbar {\\frac {\\partial |\\psi \\rangle } {\\partial t}}= H |\\psi \\rangle $.\r\n\\\\\r\n\\\\\r\n\\emph{Postulate 3:} Quantum measurements are described by a collection of \r\nmeasurement operators,\r\n$\\{ M_m \\}$ that act on the state space.  If $|\\psi \\rangle $\r\nis the state immediately before the measurement, the probability that the event $m$ occurs\r\nis \r\n$ \\langle \\psi | M_m^{\\dagger} M_m | \\psi \\rangle $ \r\nand the state after the measurement is given by\r\n${\\frac {M_m |\\psi \\rangle } {\\sqrt { \\langle \\psi | M_m^{\\dagger} M_m | \\psi \\rangle }}}$ and $M_m$ satisfies\r\n$\\sum_m M_m^{\\dagger}M_m = I$.  A projective measurement on an observable\r\nwith spectral decomposition, $M= \\sum_m mP_m$, results in one of the $m$ values as possible\r\noutcomes.  $\\Delta(C) \\Delta(D) \\ge {\\frac { \\langle \\psi|[C,D]|\\psi \\rangle } {2}}$.\r\n\\\\\r\n\\\\\r\n\\emph{Postulate 4:} The state space of a composite system is the tensor\r\nproduct of the state spaces of the component systems.  If we number the systems\r\n$1, 2, \\ldots, n$, and system $i$ is in the prepared state $|\\psi_i \\rangle $ then the joint state\r\nis $|\\psi_1 \\rangle  \\otimes |\\psi_2 \\rangle  \\otimes \\ldots \\otimes |\\psi_n \\rangle $.\r\n\\end{quote}\r\n{\\bf Simple quasi-classical operators:}\r\n\\emph{Harmonic oscillator:}\r\n$H= {\\frac {p^2} {2m}} + k {\\frac {x^2} 2}$.  \\emph{EM Hamiltonian:}\r\n$H= {\\frac 1 {2m}} (p- {\\frac q c} A)^2 + V(R)+ q \\phi - {\\frac q {mc}} S \\cdot B,\r\nB= \\nabla \\times A$.\r\nSimultaneously observable quantities commute.  \\emph{Independence and uncertainty:}\r\n$[R_j, P_k]= i \\hbar \\delta_{jk}, [R_j, R_k]=0$.\r\n\\\\\r\n\\\\\r\n{\\bf Feynman Postulates:}  If there is no spin or polarization:\r\n(1) $ \\langle x|s \\rangle = a+bi$.  $Pr($ particle arrives at $x | $ particle leaves $s)= | \\langle x|s \\rangle |^2$.\r\n(2) $ \\langle x|s \\rangle_{both}=  \\langle x|s \\rangle_{1} +  \\langle x|s \\rangle_{2}$.\r\n(3) $ \\langle x|s \\rangle_{via \\; 1}=  \\langle x|1 \\rangle   \\langle 1|s \\rangle $. $a$ is probability light scattered at $1$ arrives at\r\n$D_1$ and $b$ that it arrives at $D_2$ ($a>>b$).  \r\n$ \\langle {\\vec {r_2}} | {\\vec {r_1}} \\rangle \r\n= {\\frac A {r_{12}}} e^{i {\\frac {{\\vec p} \\cdot {\\vec {r_{12}}}} {\\hbar}}}$; get $p$\r\nrelativistically by  $(pc)^2=E^2-(m_0 c^2)^2$ or non-relativistically as $E={\\frac {p^2} {2m}}$.\r\nRules for outcomes: (1)If final states are distinguishable, add probabilities \\emph {not amplitudes}\r\nfor indistiguisible processes leading to the same final state add \\emph {amplitudes};\r\n(2) use complete description of isolates system.  Outcome of scattering with indistinuishable\r\nparticles always exhibit interference: \r\nadd amplitudes for \\emph{Bosons,} subtract for \\emph{Fermions}.\r\n$P_n(Bose)= n!P_n(\\textnormal{different})$.  \r\nTreat metal conduction as noninteracting Fermion gas.\r\n\\section{More Quantum}\r\n{\\bf Polar Decomposition:} Let $A$ be a linear operator on $V$.  Then there is a\r\nunitary operator $U$ and positive operators $J, K$: $A=UJ=KU$.  \r\n$J={\\sqrt {A^TA}}$,\r\n$K={\\sqrt {AA^T}}$.\r\n{\\bf Singular Value Decomposition:} Let $A$ be a square matrix the $\\exists U, V$ and a diagonal\r\nmatrix $D$ with non-negative entries such that $A=UDV$.  Entries of $D$ are called singular values.\r\n{\\bf Schmidt decomposition:}  If $|\\Psi \\rangle $ is a \r\nvector in the tensor product ${\\mathcal H}_A \\otimes {\\mathcal H}_B$ there are orthonormal bases \r\n$\\{ \\varphi_i^A \\}$ and\r\n$\\{ \\varphi_i^B \\}$ such that $\\Psi= \\sum {\\sqrt {p_i}} |\\varphi_i^A \\rangle |\\varphi_i^B \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Standard Model:} Quantized force fields materialize as particles.\r\nMatter particles: \\emph{Fermions} (half-integral spins).  Force particles: \r\n\\emph{Bosons} (integral spins).\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\begin{tabular} {|l||l|l|l|}\r\n\\hline\r\nType & Family 1 & Family 2 & Family 3\\\\\r\n\\hline\r\nQuark  & Up ($u$) & Charm ($c$) & Top ($t$)\\\\\r\nQuark & Down ($d$) & Strange ($s$) & Bottom ($b$)\\\\\r\n\\hline\r\nLepton & electron neutrino ($\\nu_e$) & muon neutrino ($\\nu_{\\mu}$) & Tau neutrino ($\\nu_{\\tau}$)\\\\\r\nLepton & electron ($e$) & muon ($\\mu$) & Tau ($\\tau$)\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\caption{Matter Particles - Fermions - not including antiparticles}\r\n\\end{figure}\r\n$u$: $q= +{\\frac 2 3}$, $m= 2 Mev$;\r\n$d$: $q= -{\\frac 1 3}$, $m= 5 Mev$;\r\n$c$: $q= +{\\frac 2 3}$, $m= 1.25 Gev$;\r\n$s$: $q= -{\\frac 1 3}$, $m= 95 Mev$;\r\n$t$: $q= +{\\frac 2 3}$, $m= 171 Mev$;\r\n$b$: $q= -{\\frac 1 3}$, $m= 4.2 Gev$.\r\n\\\\\r\n$\\nu_e$: $q= 0$;\r\n$\\nu_{\\mu}$: $q= 0$;\r\n$\\nu_{\\tau}$: $q= 0$.\r\n$e$: $-1$, $m=.511 Mev$;\r\n$\\mu$: $-1$, $m=106 Mev$;\r\n$\\tau$: $0$, $m= 1.78 Gev$.\r\nBosons: \r\nPhoton $\\gamma$ - EM Force: $q=0$, $m=0$; \r\nGluons - Strong Force: $q=0$, $m=0$; \r\nZ - weak force: $q=0$, $m=91 Gev$; \r\n$W^+, W^-$ - weak force: $q=0$, $m=80.4 Gev$; \r\nHiggs ($H$): $q=0$, $114 Gev<m< 192 Gev$; \r\nGraviton - gravity: $q=0$, $m=0$. \r\n\\\\\r\n\\\\\r\n{\\bf Hall Effect:}  In metal or semiconductor, imagine a thin ($2D$)\r\nslab, $z$-up, $x$-across, $y$-back,\r\nwith an electric field, ${\\vec E}_y$, back, current ${\\vec j}_x$ across.  Turn on\r\na magnetic field ${\\vec B}_z$, and the charges move to the back until equilibrium caused\r\nby electrostatic build-up when $B_z v_x = E_y$, then Hall resistance\r\nis $R_H= {\\frac {E_y} {B_z}} j_x$, $j_x= v_x N_q$.  At low temperature ($<30 mK$), a quantum\r\neffect appears:  $R_H$ grows monotonically with $B_z$ and is quantized by \r\n${\\frac 1 n} {\\frac h {e^2}}$; this IQHE is evident in a GaAs-GaAlAs hetero-juncture.\r\nThe magnetic field shifts the Landau Levels.\r\nThe diagonal resistance $R_{xx}$ is at times $0$ when the \r\n\\emph{Fermi energy} of the electrons\r\nlies between the \r\n\\emph{Landau Levels} freezing out scattering.  (The Fermi energy, $E_F$,\r\nis the energy of the fermion composite at $0K$.)  When the mobility of the electrons is high, \r\nadditional plateaus (corresponding to $R_{xx}=0$) appear; this is due to electron interaction\r\ngiving rise to fractional charge like quasi-particles; this is the FQHE.  Unlike IQHE, the\r\nFQHE gives rise to non-Abelian statistics in the gapped degenerate states.\r\n\\\\\r\n\\\\\r\n{\\bf Fractional Quantum Hall Physics:}\r\n\\emph{Laughlin wave function:} \r\n$\\Phi^m (z_1, \\ldots, z_n)= \\prod_{i<j} (z_i-z_j)^m e^{-{\\frac 1 {4l^2}} \\sum |z_i|^2}$.\r\n\\emph{Moore-Reed:} \r\n$\\Phi^m(z_1, \\ldots, z_n)= \\prod_{i<j} (z_i-z_j)^m e^{-{\\frac 1 {4l^2}} \\sum |z_i|^2}\r\nPf({\\frac 1 {z_i - z_j}})$.\r\nEnergy spectrum of 2DEG breaks into allowed states \r\n$E_n= (n+{\\frac 1 2}) \\hbar \\omega_c$ in $B$ field (Landau levels).  When chemical potential\r\nlies in Landau bands, material is metallic.  Otherwise localized states materialize adding\r\nelectrons only add and subtract localized states, no currents flow and system is\r\n\\emph{incompressible}.\r\n\\emph{Magnetic length:} $l_B= {\\sqrt {\\frac \\hbar {eB}}}$; within $l_B$ of the edge,\r\nthey form quasi-1D channels.  Because there is no back-scattering, $R_{xx}=0$.\r\n\\emph{Hidden subgroup:} $G^{abelian} \\ge H$, $f: G \\rightarrow X$ hides $H$ if\r\n$f: G/H \\leftrightarrow X$.\r\n\\emph{Filling factor:}  Ratio of electrons to magnetic flux quanta.\r\n$\\nu= {\\frac 1 {R_H}} {\\frac h {e^2}}$\r\nor $\\sigma_H= \\nu {\\frac {e^2} h}$.  For composite fermions with $p$-filled Landau\r\nlevels, $\\nu= {\\frac p {2p+1}}$.\r\n${\\frac 1 3}$ state is fully spin polarized.\r\nA \\emph{Luttinger liquid:} is composed of interacting electrons in a one dimensional conductor.\r\nThe \\emph{Fermi energy} is the energy of the highest occupied quantum state \r\nin a system of fermions at absolute zero temperature.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nA \\emph{quantum dot}\r\nis a semiconductor whose excitons are confined in all three spatial dimensions. \r\nA \\emph{quantum well}\r\nis a semiconductor whose excitons are confined in two spatial dimensions. \r\nA \\emph{quantum wire}\r\nis a semiconductor whose excitons are confined in one spatial dimension. \r\n\\emph{Spin Polarization}\r\nis the degree to which the intrinsic angular momentum of elementary particles, \r\nis aligned with a given direction. \r\n\\\\\r\n\\\\\r\n{\\bf Some effects:}\r\nThe \\emph{Aharonov-Bohm}\r\neffect is a quantum mechanical phenomenon by which a charged particle \r\nis affected by electromagnetic fields in regions from which the particle is excluded. \r\nIn the case of the Aharonov-Bohm solenoid effect, \r\nthe wave function of a charged particle passing around a long solenoid experiences a \r\nphase shift as a result of the enclosed magnetic field, \r\ndespite the magnetic field being zero \r\nin the region through which the particle passes. \r\nThe \\emph{Coulomb blockade} is the increased resistance at small bias voltages of an \r\nelectronic device comprising at least one low-capacitance tunnel junction.\r\n\\emph{Magnetic quantization:} $\\Phi_0={\\frac {h} {2e}} \\approx 2 \\times 10^{-15} Wb$; \r\nmeasured by Josephson effect.\r\n\\emph{Berry Phase:}  Phase acquired in cyclic adiabatic process; \r\nmeasured through interference experiment.\r\n\\emph{Ising Model:} Spin coupling: $E= - \\sum_{i,j} J_{ij} S_i S_j$.  \r\nOne dimensional: $E= \\sum_i S_i S_{i+1}$.\r\nTwo dimensional: $E= - \\sum_{i,j} S_{i,j} S_{i, j+1} + S_{i,j} S_{i+1,j}$.  Magnetic field\r\nbreaks the symmetry.  Computational model: (1) Pick random site, \r\n(2) flip spin and calculate\r\n$\\Delta E$, (3) if $\\Delta E <0$, accept, (4) if $\\Delta E>0$ accept with probability\r\n$e^{- \\beta \\Delta E}$.\r\n\\\\\r\n\\\\\r\n{\\bf Aharonov-Bohm calculation for two slit experiment with small solenoid:}\r\n$F= e(E+v \\times B), E= -\\nabla \\times A-{\\frac {\\partial A}{\\partial t}}, B= \\nabla \\times A$.\r\nConsider usual two slit set-up with electrons of wavelength $\\lambda$, distance between slits $d$,\r\nsecond screen at distance $L$ from first, $a$ is leg of triangle with hypotheneuse $d$, and $x$ is\r\nthe distance from the center of the observation on the second screen.\r\nWithout solenoid $\\delta = {\\frac {2 \\pi a}{\\lambda}}$; if $x<<L$, $\\delta= {\\frac x L}{\\frac {2 \\pi d}{\\lambda}}$.\r\nThe field of the solenoid (in cylindrical coordinates) is \r\n$A_r=A_{z}=0$ and\r\n$A_{\\phi}= {\\frac {Br}{2}}$ inside and\r\n$A_r=A_{z}=0$ and\r\n$A_{\\phi}= {\\frac {BR^2}{2r}}$ outside where $R$ is the radius of the solenoid.\r\n$B_z= {\\frac 1 r}{\\frac {\\partial A_{\\phi}}{\\partial r}} - {\\frac {\\partial A_r}{\\partial \\phi}}$.\r\nWave function of $e^-$ is $\\psi(p,r)=  |\\psi| exp(i p \\cdot r)= |\\psi| e^{i \\alpha}$.  The EM field changes\r\n$p \\rightarrow p-eA$ so $\\alpha \\rightarrow \\alpha - {\\frac e {\\hbar}} A \\cdot r$.\r\n$\\Delta \\alpha = - {\\frac e {\\hbar}} \\int_{path} A \\cdot dr$ and thus\r\n$\\Delta \\delta= \\Delta \\alpha_1 - \\Delta \\alpha_2 \r\n= {\\frac e {\\hbar}} \\int_{loop} A \\cdot dr\r\n= {\\frac e {\\hbar}} \\int_{loop} B \\cdot dS\r\n= {\\frac e {\\hbar}} \\Phi_B $.\r\n\\\\\r\n\\\\\r\n{\\bf Quantum computing:}\r\nA \\emph{qubit} is a two dimensional space $|\\psi>= a|0>+b|1>$ over ${\\mathbb C}$\r\nsuch that $|a|^2+|b|^2=1$.\r\nA set of gates is said to be a set of \\emph{universal quantum gates} if any unitary operator\r\ncan be approximated to arbitrary accuracy by a quantum circuit involving only those gates.\r\nThe Hadamard, CNOT, phase and ${\\frac {\\pi} 8}$ gates form a universal set.\r\n\\emph{A universal gate set:} $CNOT= \\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\n0 & 1 & 0 & 0 \\\\\r\n0 & 0 & 0 & 1 \\\\\r\n0 & 0 & 1 & 0 \\\\\r\n\\end{array}\r\n\\right)$,\r\n$H= {\\frac 1 {\\sqrt 2}} \\left(\r\n\\begin{array}{cc}\r\n1 & 1 \\\\\r\n1 & -1\\\\\r\n\\end{array}\r\n\\right)$,\r\n$T= \\left(\r\n\\begin{array}{cc}\r\ne^{-i{\\frac {\\pi} 8}} & 0 \\\\\r\n0 & e^{i{\\frac {\\pi} 8}}\\\\\r\n\\end{array}\r\n\\right)$.\r\n\\emph{Pauli transformations:}\r\n${\\vec {\\sigma}}= (\\sigma_x, \\sigma_y, \\sigma_z)$.\r\n$\\sigma_x = \\left(\r\n\\begin{array}{cc}\r\n0 & 1 \\\\\r\n1 & 0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\sigma_y = \\left(\r\n\\begin{array}{cc}\r\n0 & -i \\\\\r\n-i & 0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\sigma_z = \\left(\r\n\\begin{array}{cc}\r\n1 & 0 \\\\\r\n0 & -1\\\\\r\n\\end{array}\r\n\\right)$.\r\n\\\\\r\n\\\\\r\n{\\bf Hamiltonian for EM:}\r\n$H= {\\frac 1 {2m}} \r\n({\\vec p} - {\\frac q c} {\\vec A}) \\cdot\r\n({\\vec p} - {\\frac q c} {\\vec A}) + q \\phi$.\r\n\\emph{Bennet's rules:} $X \\ge Y$ means $X$ can do the job of $Y$:\r\n(1) $1$-qubit $\\ge 1$-bit,\r\n(2) $1$-qubit $\\ge 1$-ebit,\r\n(3) $1$-ebit $+ 1$-qubit $\\ge 1$-bit (dense coding),\r\n(4) $1$-ebit $+ 2$-bits $\\ge 1$-qubit (teleportation).\r\n\\\\\r\n\\\\\r\n$S^2 | \\alpha>= S(S+1) \\hbar^2 | \\alpha >$, $S^2= S_x^2 + S_y^2 + S_z^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Projective measurements:}\r\n$P_m= \\sum_{i=1}^m | \\phi_i \\rangle   \\langle \\phi_i|$.  \r\n(1) State of system at $t=0$ is $\\psi_0$.\r\n(2) A measureable quantity, $A$, is described by an observable, $A$, acting on the state space.\r\n(3) Possible results are eigenvalues.\r\n(4) When $A$ is measured, $P(a_n)= \\sum_{i=1}^{g_n} | \\langle u_n^i| \\psi \\rangle |^2$.\r\n(5) If the measurement of $A$ in the state $| \\psi \\rangle $ gives $a_n$ then immediately after\r\nthe state is ${\\frac 1 {\\sqrt {\\langle \\psi |  P | \\psi \\rangle }}} P_n |\\psi \\rangle $.\r\n$ \\langle A \\rangle_{\\psi} =  \\langle \\psi | A | \\psi \\rangle $,\r\n\\\\\r\n\\\\\r\n{\\bf Quantum Ion Trap Systems:}  The qubits are representations of the hyperfine nuclear\r\nspin states at the lowest vibrational modes (phonons) of trapped atoms.  \r\nArbitrary transforms are constructed with laser pulses using Jaynes Cummings.\r\nQubits interact via shared phonon state.  Initial state preparation involves cooling\r\natoms by trapping and optical pumping to their lowest motional ground and hyperfine state.\r\nThe measurement is the measurement of the population of hyperfine states.  \r\n\\\\\r\n\\\\\r\n{\\bf Spintronics:} Spintronics exploits the intrinsic spin of electrons and their associated \r\nmagnetic moment in solid-state devices.  \r\nElectrons are spin-1/2 fermions and constitute a two-state system with spin ``up'' and \r\nspin ``down''.  \r\n\\\\\r\n\\\\\r\n{\\bf Quantum error correcting conditions:} Suppose $C$ is a quantum code and \r\n$P$ is a projection\r\noperator onto $C$.  Suppose ${\\cal E}$ is a quantum operator with measurements $E_i$.  A\r\nnecessary and sufficient condition for the existence of an error\r\ncorrection operator ${\\cal R}$ is $P E_i^{\\dagger}+E_jP= \\alpha_{ij}$.\r\n\\\\\r\n\\\\\r\n{\\bf Non-abelian statistics:}\r\nLet $R_1, R_2, \\ldots, R_N$ be trajectories in $3+1$ dimensional space from $t_i$ to\r\n$t_f$.  $\\psi({\\vec {r_1}}, {\\vec {r_2}}) \\rightarrow e^{i \\theta}$.  Normally, $\\theta$ can\r\neither be $0$ or $\\pi$, if $\\theta$ is arbitrary, this describes an \\emph{anyon}.\r\nNon-abelian anyons are associated with higher dimensional representations of the braid group.\r\nThis can occur when there is a set of $g$ degenerate states with particles are\r\nfixed $R_1, \\ldots, R_N$.  If $\\{ \\psi_{\\alpha} \\}$ is an orthonormal basis and\r\n$\\psi_{\\alpha} \\rightarrow [\\rho(\\sigma_1)]_{\\alpha \\beta} \\psi_{\\beta}$.  It is non-abelian\r\nif $ [\\rho(\\sigma_1)]_{\\alpha \\beta} [\\rho(\\sigma_2)]_{\\beta \\gamma} \\ne\r\n[\\rho(\\sigma_2)]_{\\alpha \\beta} [\\rho(\\sigma_1)]_{\\beta \\gamma}$.\r\n\\\\\r\n\\\\\r\n{\\bf Cauchy-Schwartz:} $ \\langle \\phi | \\psi \\rangle  \\le  \\langle \\phi | \\phi \\rangle   \\langle \\psi|\\psi \\rangle $.   $T_{ij}=  \\langle u_i|T|u_j \\rangle $ then\r\n$T= \\sum_{ij} T_{ij} |u_i \\rangle  \\langle u_j|$.\r\n\\emph{Continuous version of inner product:} \r\n$ \\langle \\phi | \\psi \\rangle  = \\int \\phi^* \\psi dx $.\r\nIf $|\\phi \\rangle = \\sum_i c_i |u_i \\rangle $ then $\\psi \\rangle  \\rightarrow\r\n\\left(\r\n\\begin{array}{c}\r\nc_1 \\\\\r\nc_2 \\\\\r\n\\ldots \\\\\r\nc_n \\\\\r\n\\end{array} \r\n\\right)\r\n=\r\n\\left(\r\n\\begin{array}{c}\r\n \\langle u_1 | \\psi \\rangle  \\\\\r\n \\langle u_2 | \\psi \\rangle  \\\\\r\n\\ldots \\\\\r\n \\langle u_n | \\psi \\rangle  \\\\\r\n\\end{array} \r\n\\right) $.\r\nIf $|\\psi \\rangle = \\alpha |0 \\rangle  + \\beta |1 \\rangle $ then $| \\langle 0|\\psi \\rangle |^2= |\\alpha|^2$.\r\n\\emph{Projection operator:} $P_m = \\sum_{i=1}^m |u_i \\rangle \\langle u_i|$.  \r\n\\emph{Observables:} Hermitian operators on\r\nstate vectors.  \r\nObservables $A, B$ commute iff there is a basis of eigenvalues that commute.\r\n\\\\\r\n\\\\\r\n$|\\psi(t) \\rangle= (\\alpha(t), \\beta(t))^T$.\r\n$H |\\psi \\rangle= \r\n\\left(\r\n\\begin{array}{cc}\r\n\\omega_1 & \\omega_2 \\\\\r\n\\omega_2 & \\omega_1 \\\\\r\n\\end{array} \r\n\\right)\r\n\\left(\r\n\\begin{array}{c}\r\n\\alpha(t) \\\\\r\n\\beta(t) \\\\\r\n\\end{array} \r\n\\right)=\r\ni \\hbar {\\frac {\\partial |\\psi \\rangle} {\\partial t}} = \r\n\\left(\r\n\\begin{array}{c}\r\n{\\frac {d\\alpha(t)} {dt}} \\\\\r\n{\\frac {d\\beta(t)} {dt}} \\\\\r\n\\end{array} \r\n\\right)$, \r\n$ \\alpha(t)= e^{i{\\frac {\\omega_1 t} {\\hbar}}} cos({i{\\frac {\\omega_2 t} {\\hbar}})})$.\r\n\\\\\r\n\\\\\r\n$ \\langle w | T^{\\dagger} | v \\rangle=  \\langle v|T|w \\rangle^*$, $[X,P]=i \\hbar$.  Finding similarity:  \r\n(1) find eigenvalues/eigenvectors, (2) normalize eigenvectors, $v_i$, \r\n(3) $S^{-1}= (v_1, \\ldots, v_n)$.\r\n\\\\\r\n\\\\\r\n{\\bf Hadamard Gate: }\r\n$\r\n{\\frac 1 {\\sqrt 2}}\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 1 \\\\\r\n1 & -1 \\\\\r\n\\end{array} \r\n\\right)$.\r\n{\\bf Pauli matricies:}\r\n$X=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & 1 \\\\\r\n1 & 0 \\\\\r\n\\end{array} \r\n\\right)$,\r\n$Y=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -i \\\\\r\ni & 0 \\\\\r\n\\end{array} \r\n\\right)\r\n$ and\r\n$Z=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0 \\\\\r\n0 & -1 \\\\\r\n\\end{array} \r\n\\right)\r\n$.\r\n$\r\n{\\vec L}=\r\n{\\vec r} \\times\r\n{\\vec p}\r\n$, $L_x= yp_z-zp_y$, $[L_x , L_y]= i \\hbar L_z$.  \r\n$ (\\Delta A)^2\r\n(\\Delta B)^2\r\n\\ge\r\n({\\frac { \\langle A,B \\rangle} {2i}})^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Degeneracy (duplicate eigenvalues):}  Suppose $A$ has $g_m$ degenerate states then\r\n$Prob(\\lambda_m)= \\sum_{i=1}^{g_m} | \\langle a_m^i|\\psi \\rangle |^2$.\r\n\\\\\r\n{\\bf Tensor:}  \r\n$ \\left(\r\n\\begin{array}{c}\r\na \\\\\r\nb \\\\\r\n\\end{array} \r\n\\right)\r\n\\otimes\r\n\\left(\r\n\\begin{array}{c}\r\nc \\\\\r\nd \\\\\r\n\\end{array} \r\n\\right)\r\n=\r\n\\left(\r\n\\begin{array}{c}\r\nac \\\\\r\nad \\\\\r\nbc \\\\\r\nbd \\\\\r\n\\end{array} \r\n\\right)$.\r\n\\\\\r\n\\\\\r\n{\\bf Density Operator:}  $\\rho= \\sum_i p_i |\\psi_i \\rangle \\langle \\psi_i|$.  If system is in a pure stare\r\n$Tr(\\rho)=1$; if system is in a mixed state $Tr(\\rho)<1$.\r\n\\\\\r\n\\\\\r\n{\\bf Spin:}  \r\nBosons: $swap(|AB \\rangle )= |BA \\rangle $, if $2$ bosons are distributed in $3$ boxes,\r\nthe probability two are in the same box is ${\\frac 1 2}$.\r\nFermions: $swap(|AB \\rangle )= -|BA \\rangle $, if $2$ fermions are distributed in $3$ boxes,\r\nthe probability two are in the same box is ${\\frac 1 3}$.  Feynman's QED:\r\n$P(A \\rightarrow B) = \\sum_{\\gamma_i} |A^{\\gamma_i}_{A \\rightarrow B}|^2$ where the\r\n$\\{\\gamma_i \\}$ are the paths from $A \\rightarrow B$.\r\n\\\\\r\n\\\\\r\n{\\bf Ladder operators:}  Remember\r\n$-{\\frac {\\hbar^2} {2m}} {\\frac {\\partial^2 \\Psi (x, t)} {\\partial x^2}} +\r\nU \\Psi(x,t)= i \\hbar \\Psi(x,t)$, $\\int |\\Psi|^2 =1$.  Define $a_{\\pm}= {\\frac 1 {\\sqrt {2m}}}\r\n({\\frac {\\hbar}{i}} {\\frac {\\partial} {\\partial x}} \\pm i \\omega x)$, $[a_+ , a_- ]= \\hbar \\omega$.\r\n$\\Psi_{EPR}= {\\frac {|01 \\rangle + |10 \\rangle} {\\sqrt 2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Mach-Zender interferometer:}  Input state is $|U \\rangle$.  \r\nAlong upper path state is ${\\frac 1 {\\sqrt 2}} (|U\\rangle + |L\\rangle)$.\r\nAlong lower path state is \r\n${\\frac 1 {\\sqrt 2}} (|U\\rangle - |L\\rangle)$.\r\nAt detector 1, state is \r\n${\\frac 1 {\\sqrt 2}} {\\frac 1 {\\sqrt 2}} [ (|U\\rangle + |L\\rangle) + (|U\\rangle - |L\\rangle)] = |U\\rangle$. \r\nAt detector 0, state is $0$.\r\n\\\\\r\n\\\\\r\n{\\bf Bell's Argument against hidden variables:}\r\nConsider two entangled total spin zero particles particles $\\# 1, \\#2$, \r\n$A$ and $B$ are measurements on $\\#1$.\r\n$C$ and $D$ are measurements on $\\#2$.\r\n$\\Psi= {\\frac 1 {\\sqrt 2}} ( |\\uparrow \\downarrow\\rangle - | \\downarrow \\uparrow\\rangle )$.\r\nEPR argument is that entanglement and locality mean hidden variables.  Assuming\r\nlocality, any measurement on $\\#1$ does not effect $C$ or $D$ measurements.\r\nIf $P(A=C)=P(B=D)= 0.85$ and $P(B=C)=1$ then $P(A=D) \\ge .7$.\r\nPrepare axis so that \r\n(1) the angle between $A$ and $C$ is $135$,\r\n(2) the angle between $B$ and $C$ is $180$,\r\n(3) the angle between $B$ and $D$ is $135$,\r\n(4) the angle between $A$ and $D$ is $45$.  Quantum mechanics gives\r\n$P(A=C)= =P(B=C)= .85$ and $P(B=C)=1$ but $P(A=D)= .5 < .7$.  Thus entanglement, locality\r\nand quantum mechanics are inconsistent.  Locality loses.\r\n\\\\\r\n\\\\\r\n{\\bf The braid calculation:}\r\n$|\\Psi_1 \\rangle= U(t) |\\Psi_0 \\rangle$; a phase error $\\theta$ is introduced when\r\n$a |0 \\rangle + b |1 \\rangle \\rightarrow a |0 \\rangle + b e^{i \\theta} |1 \\rangle$.  \r\nA system has a topological phase if its\r\nlow energy, long distance effective field theory is a topological field theory, \r\nthat is, physical\r\ncorrelations are topologically invariant up to a correlation of order $e^{\\Delta/T}$.\r\n\\emph {Anyon}: Any phase factor $e^{\\i \\phi}$ can result from a counter-clockwise exchange\r\nof two particles.  Feynman: Paths are weighted by $e^{i S/\\hbar}$, $S$ is classical action.\r\nSuppose there are $g$ degenerate states $\\Psi_a$, $a= 1, 2, \\ldots,`g$ of particles\r\nat positions $x_1 , x_2 , \\ldots , x_n$.  Exchange rotates states according to (say)\r\n$\\Psi_a \\rightarrow M_{ab} \\Psi_b$ for $1,2$ exchange and\r\n$\\Psi_a \\rightarrow N_{ab} \\Psi_b$ for $2,3$ exchange.  Exchange statistics are\r\n\\emph {non-abelian} if $M_{ab} N_{ab} \\ne N_{ab} M_{ab}$.  We can read the state by using the\r\nnon-abelian A-B effect:  Send a non-abelian anyon test quasi-particle around hall bar\r\nedge, interference effect determines state.  $\\sigma_{xx} \\varpropto |t_1 + i t_2|^2$\r\n\\\\\r\n\\\\\r\n{\\bf Symmetries:} EM ($U(2)$), Weak ($SU(2)$), Strong ($SU(3)$). A \\emph{Lie group} \r\n(1) depends on parameters $\\theta_1, \\ldots, \\theta_n$ and \r\n(2) derivatives with respect to group parameters\r\nexist. The diffeomorphism group of a Lie group acts transitively on the Lie group.\r\n$g(\\theta)_{\\theta=0}=e$, \r\n${\\frac {\\partial g(\\theta_1 , \\ldots, \\theta_n)} {\\partial \\theta_i}}_{\\theta_j=0} = i X_j$ are the\r\ngenerators.  $[X_i , X_j]= i f_{ijk} X_k$ is group algebra.  Consider\r\n$R_x(\\zeta)= \\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0 \\\\\r\n0 & cos(\\zeta) & sin(\\zeta) \\\\\r\n0 & -sin(\\zeta) & cos(\\zeta) \\\\\r\n\\end{array} \r\n\\right)$,\r\n$R_y(\\phi)= \\left(\r\n\\begin{array}{ccc}\r\ncos(\\phi) & 0 & sin(\\phi) \\\\\r\n0 & 1 & 0 \\\\\r\n-sin(\\phi) & 0 & cos(\\phi) \\\\\r\n\\end{array} \r\n\\right)$, and\r\n$R_z(\\theta)= \\left(\r\n\\begin{array}{ccc}\r\ncos(\\theta) & sin(\\theta) & 0\\\\\r\n-sin(\\theta) & cos(\\theta) & 0 \\\\\r\n0 & 0 & 1 \\\\\r\n\\end{array} \r\n\\right)$.\r\nUnitary: $[U, H]=0$.  $SU(2)$ has 3 generators and $SU(3)$ has 8.\r\n{\\bf Noether:}  If $T(s)$ is a transformation $T(s): q \\mapsto q(s)$ and\r\n${\\frac {\\partial L(q(s)} {{\\dot q}(s)}} =0$, then $C= p{\\frac {\\partial q(s)} {\\partial s}}$\r\nis a conserved quantity.\r\n\\\\\r\n\\\\\r\n{\\bf Model for electron flow in crystal:}  Let $C_n$ be the wave function at site $n$ in a linear\r\narray of molecules in a lattice each separated by a distance $b$.  \r\n$i \\hbar {\\frac {\\partial C_{n-1}} {\\partial t}}=\r\nE_0 C_{n-1} -A C_{n} -A C_{n-2}$.  $C_n= a_n(x) e^{-i (e/ \\hbar)t}$ and $a_n(x)= e^{ikx}$.\r\nSubstituting,$E= E_0 + A(e^{-ikx} + e^{ikx})$.  Using $E_0= 2A$ and $cos(t) \\approx 1 -t^2/2$ for\r\nsmall $t$, we get $E= \\hbar \\omega = {\\frac {A b^2 k^2} 2}$ so \r\n${\\frac {d \\omega} {dk}}={\\frac {2Ab^2}{\\hbar}}k$.  If $E$ is different, say $E_0+F$ at site $0$,\r\nwe get backscattering or trapping depending on the sign of $F$.\r\n\\\\\r\n\\\\\r\n{\\bf Semiconductor junctions:}\r\n${\\frac {N_p(p-side)} {N_p(n-side)}} = e^{-{\\frac {q_p V} {kT}}}$.\r\nThe energy in conduction band $\\approx E_0 + \\alpha k^2$.\r\n$N_n N_p= c e^{E_{gap}/(kT)}$.\r\n$E_{gap, Ger} \\approx .72 ev$,\r\n$E_{gap, Si} \\approx 1.1 ev$; at room temperature, $kT \\approx {\\frac 1 {40}} ev$.\r\n$v_{drift}= {\\frac {q_n {\\cal E} \\tau_n} {m_n}}$, yielding the Ohm law: \r\n${\\vec j}= {\\frac {N q_n^2 \\tau_n} {m_n}} {\\vec {\\cal E}}$.\r\nFor Hall effect, ${\\vec {E_{tr}}}= -{\\vec v}_{drift} \\times {\\vec B}= -{\\frac 1 {qN}}B{\\vec j}$,\r\n$R_H= {\\frac 1 {qN}}$.\r\n\\section{Background for Quantum Field Theory}\r\n{\\bf Compton Scattering:}\r\nPhoton of wavelength $\\lambda$ scatters off stationary electron of mass $m$ resulting in photon of wavelength $\\lambda'$ at an angle $\\theta$\r\nand $m$ acquiring momentum $p$.  $\\lambda'= \\lambda + {\\frac {h}{mc}}(1-cos(\\theta))$.\r\n\\\\\r\n\\\\\r\n{\\bf Spin:}\r\nIt is impossible to measure all components of $L= (L_x , L_y , L_z )$ simultaneously.  We can measure $L^2$ and $L_z$ simultaneously.\r\n$L^2 | \\psi \\rangle = \\hbar^2 l(l+1) |\\psi \\rangle$ and $L_z | \\psi \\rangle= \\hbar m_l | \\psi \\rangle$, $-l \\leq m_l \\leq l$ ($2l+1$-dimensional\r\nHilbert space).  Same for spin; namely, \r\n$S^2 | \\psi \\rangle = \\hbar^2 s(s+1) |\\psi \\rangle$ and $S_z | \\psi \\rangle= \\hbar m_s | \\psi \\rangle$, $-s \\leq m_s \\leq s$.  The states\r\nare sometimes denoted $|l, m_l \\rangle$ and $|s, m_s \\rangle$ respectively.  \\emph{Clebsh-Gordon}: \r\n$| j_1 , m_1 \\rangle | j_2 , m_2 \\rangle = \\sum_j C^{j,j_1, j_2}_{m, m_1, m_2} |j, m \\rangle$.\r\nOrbital state $|3, -1 \\rangle$, spin state \r\n$|{\\frac 1 2}, {\\frac 1 2} \\rangle =\r\n\\left(\r\n\\begin{array}{c}\r\n1 \\\\\r\n0 \\\\\r\n\\end{array}\r\n\\right)$ and\r\n$|{\\frac 1 2}, -{\\frac 1 2} \\rangle =\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n1 \\\\\r\n\\end{array}\r\n\\right)$.\r\n$\\hat{S}_x= {\\frac {\\hbar} 2}\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & 1 \\\\\r\n1 & 0 \\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\hat{S}_y= {\\frac {\\hbar} 2}\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -i \\\\\r\ni & 0 \\\\\r\n\\end{array}\r\n\\right)$ and\r\n$\\hat{S}_z= {\\frac {\\hbar} 2}\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0 \\\\\r\n0 & -1 \\\\\r\n\\end{array}\r\n\\right)$.\r\nThe $\\chi_t\r\n=\r\n\\left(\r\n\\begin{array}{c}\r\n{\\frac 1 {\\sqrt 2}} \\\\\r\n\\pm {\\frac 1 {\\sqrt 2}} \\\\\r\n\\end{array}\r\n\\right)$.  For spinor, \r\n$\\left(\r\n\\begin{array}{c}\r\n\\alpha'\\\\\r\n\\beta'\\\\\r\n\\end{array}\r\n\\right)= U(\\theta)\r\n\\left(\r\n\\begin{array}{c}\r\n\\alpha\\\\\r\n\\beta\\\\\r\n\\end{array}\r\n\\right)=\r\n$, $U(\\theta)= e^{i (\\theta \\cdot \\sigma)/2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Parity, charge conjugation and time reversal:}\r\nTCP Theorem.\r\n\\\\\r\n\\\\\r\n{\\bf Bound states:} $e^-, p^+$ (hydrogen), $e^+, e^-$ (positronium), $c, {\\overline c}$ (charmonium).\r\nCentral force, $\\psi(r, \\theta, \\phi)=\r\n{\\frac {u(r)} r} Y^{m_l}_l(\\theta, \\phi) $  where $u(r)$ satisfies\r\n$- \r\n{\\frac {\\hbar^2}{2m}} {\\frac {d^2} {dr^2}} + [V(r)\r\n{\\frac {\\hbar^2}{2m}} {\\frac {l(l+1)} {r^2}}]u = Eu $.\r\n\\\\\r\n\\\\\r\n{\\bf Calculating decay and scattering with Feynman diagrams:}\r\n\\emph{Lifetime} is denoted by $\\Gamma$ and $dN= \\Gamma N dt$.  Each branching has lifetime $\\Gamma_i$ and $\\Gamma_{tot}= \\sum_i \\Gamma_i$.\r\n\\emph{Cross section} is denoted $\\sigma$ and $\\sigma_{tot}= \\sum_i \\sigma_i$.  Scattering angle depends on the impact parameter, $b$.\r\nFor hard scattering on a sphere of radius, $R$, $b= R sin(\\alpha), 2 \\alpha + \\theta = 2 \\pi$, $b= R cos( {\\frac {\\theta} 2})$.\r\n${\\frac {db} {d \\theta}}= - {\\frac {R} 2} sin({\\frac {\\theta} 2})$.  $\\sigma= \\int {\\frac {R^2} 4} d \\Omega$.\r\nTo calculate $\\Gamma_i, \\sigma_i$, we neet the amplitude ${\\cal M}$ and apply the ``golden rule'' in phase space.  For\r\n$1 \\rightarrow 2+3+ \\ldots + n$, the golden rule is\r\n$\\Gamma=\r\n{\\frac S {2 \\hbar m_1}}\r\n\\int {\\cal M}^2 (2 \\pi)^4 \\delta(p_1-p_2-p_3 - \\ldots - p_n) \\times\r\n\\prod_{j=2}^n 2 \\pi \\delta(p_j^2 -m_2^2 c^2) \\theta(p^{(0)}_j) {\\frac {d^4 p_j} {(2 \\pi )^4}}$.\r\nFor Feynman diagram, \r\n(1) label incoming edges and outgoing edges with four vectors $p_1, \\ldots , p_n$ and note direction, label internal edges with\r\n$q_1, \\ldots, q_m$,(2) for each vertex label coupling constant (e.g.- $ig$),\r\n(3) get propagators for internal edges by writing factor ${\\frac i {q_j^2- m_j^2 c^2}}$,\r\n(4) for each vertex write $\\delta$ function (e.g. - $\\delta(k_1+k_2+k_3)$, $+$ for out edges, $-$ for in edges (Kirchoff applies),\r\n(5) for each internal edge, write ${\\frac 1 {(2 \\pi)^4}} d^4 q_i$ and (5) cancel the deltas and nultiply by ${\\cal M}$.  For example,\r\n$\\Gamma= {\\frac {g^2 |p|} {8 \\pi \\hbar m_A c}}$,\r\n$p= {\\frac {c} {2 m_A}} ({\\sqrt {\r\nm_A^4+\r\nm_B^4+\r\nm_C^4 -2m_A^2m_B^2 -2m_B^2m_C^2 -2m_A^2m_C^2 }})$.\r\n\\\\\r\n\\\\\r\n{\\bf Quasi-particles and Fermions:}  Quasi-particles are composite particles.  One analogy is a positive ion\r\nwith a retinue of negative ions.  A simple example is two masses, $m_1, m_2$ connected by a strong spring.  One\r\nquasi-particle is the center of mass, the second the reduced mass system ${\\frac {m_1 m_2}{m_1+m_2}}$.\r\nThe highest filled particle level of a collection of fermions in the ground state is the \\emph{Fermi level},\r\n$\\epsilon_F$ with momentum $k_F= {\\sqrt {2m \\epsilon_F}}$.  The energy sphere filled by the particles is called the\r\n\\emph{Fermi sea} and the surface of the sphere is the \\emph{Fermi surface}.  A total single particle\r\npropagator is the sum of the amplitudes for all possible ways a particle can propagate through a system.\r\n\\\\\r\n\\\\\r\n{\\bf Three pictures of quantum mechanics:}\r\nThe \\emph{Schroedinger picture} gives $i \\hbar {\\frac {d}{dt}} |A,t\\rangle_S= H|A,t\\rangle_S$; solve for\r\n$|A, t_0\\rangle$ evolve via $|A,t\\rangle = U |A, t_0\\rangle_S$, $U= e^{iH(t-t_0 )/ \\hbar}$.\r\nIn the \\emph{Heisenberg model}, $|A,t\\rangle_H = U^{\\dagger} |A, t\\rangle_S$; time dependance is captured\r\nby the operator $O^H(t)= U^T O^S U$ and $[O^S, P^s]= C = [O^H(t), P^H(t)]$ while\r\n$i \\hbar {\\frac {d} {dt}}O^H(t)= [O^H(t), H]$.  For the \\emph{interaction picture},\r\n$H= H_0 +H_I$ where $H_0$ describes the independent fields and $H_I$ describes the interaction of the fields.\r\nHere, $U_0(t, t_0)= e^{-iH_0(t-t_0)/\\hbar}$, $|A,t\\rangle_I = U_0^{\\dagger} |A,t\\rangle_S$ and\r\n$O^I(t)= U_0^{\\dagger} O^S U_0$.\r\n\\\\\r\n\\\\\r\n{\\bf Classical radiation:}\r\n$\\nabla \\cdot A = 0$, $A(x,t)= A_0 e^{i(k \\cdot x - \\omega t)}$ and $k \\cdot A=0$.  \r\n$H_{rad}= {\\frac 1 2} \\int E^2 +B^2 \\thinspace d^3 x$.  For periodic boundary $A(0,y,z,t)=A(L,y,z,t)$,\r\n${\\frac a {\\sqrt V}} \\epsilon_r(K) e^{i k \\cdot x}$ is a complete set of \r\nfields and $k= {\\frac {2 \\pi} L} (n_1, n_2, n_3)$.  $\\epsilon_r(k) \\cdot \\epsilon_s(k) = \\delta_{rs}$ and\r\n$\\epsilon_r(k) \\cdot k=0$.  The vector potential can be written as \r\n$A(x,t)= \\sum_k \\sum_r ({\\frac {\\hbar c^2}{2 V \\omega_k}})^{1/2} \\epsilon_r(k)\r\n[a_r(k,t) e^{ik\\cdot x} + a_r^*(k)e^{-ik \\cdot x}]$ where $\\omega_k= c |k|$.  Substituting into\r\n$\\Box A= 0$ gives ${\\frac {\\partial a_r(k,t)} {\\partial t}}= -\\omega_k^2 a_r(k,t)$ and we set\r\n$a_r(k,t)= a_r(k)e^{-1 \\omega_k t}$ and $H_{rad}= \\sum_k \\sum_r \\hbar \\omega_k a_r^*(k) a_r(k)$.\r\n\\\\\r\n\\\\\r\n{\\bf Harmonic Oscillator:} $H_{osc}= {\\frac {p^2} {2m}}+ {\\frac 1 2} m \\omega^2 q^2$ with $[p,q]= i \\hbar$.\r\nput \r\n$a= ({\\frac 1 {2 \\hbar m \\omega}})^{1/2} (m \\omega q +ip)$ and\r\n$a^{\\dagger}= ({\\frac 1 {2 \\hbar m \\omega}})^{1/2} (m \\omega q -ip)$ with $[a, a^{\\dagger}]=1$.\r\n$H_{osc}= \\hbar \\omega (a^{\\dagger}a + {\\frac 1 2})$ and we put $N= a^{\\dagger}a$.  Note that\r\n$\\langle \\Phi |N| \\Phi \\rangle= \\langle a\\Phi | a\\Phi\\rangle \\geq 0$ and the lowest eigenvalue of $N$ is $0$.\r\nFurther $Na |\\alpha\\rangle = (\\alpha-1) a |\\alpha\\rangle$ and\r\n$Na^{\\dagger} |\\alpha\\rangle = (\\alpha+1) a^{\\dagger} |\\alpha\\rangle$ while $|n\\rangle= {\\frac {(a^{\\dagger})^n}\r\n{\\sqrt {n!}}} |0\\rangle$.  These are eigenvalues of $H_{osc}$ so $E_n= \\hbar \\omega (n+{\\frac 1 2})$.  Finally,\r\nsince $i \\hbar {\\frac {d a(t)}{dt}} = [a(t), H_{osc}]$, $a(t)= ae^{-i \\omega t}$.\r\n\\\\\r\n\\\\\r\n{\\bf Quantized radiation field:}\r\n$[a_r(k),a_s^{\\dagger}(k')]=\\delta_{rs} \\delta_{k k'}$ and\r\n$[a_r(k),a_s(k')]= [a_r^{\\dagger}(k),a_s^{\\dagger}(k')]= 0$ so\r\n$H_{rad}= \\sum_r \\sum_k \\hbar \\omega [a_r(k)^{\\dagger}a_r(k) +{\\frac 1 2}]$.\r\n$N_r(k)= a_r(k)^{\\dagger}a_r(k) $ have eigenvalues $ 0,1,2, \\ldots$ and eigenfunctions\r\n$|n_r(k)\\rangle = {\\frac {(a_r^{\\dagger})^{n_r(k)}} {\\sqrt {n_r(k)}}} |0\\rangle $.  $P= \\sum_k \\sum_r\r\n\\hbar k (N_r(k)+{\\frac 1 2})$.  The lowest energy state has all $0$ occupancy numbers and\r\n$E_0= {\\frac 1 2} \\int d^k \\hbar \\omega_k $ which is \\emph{infinite} and must be removed.  In the \r\nHeisenberg picture, we write \r\n$ A(x,t)= A(x,t)^+ + A(x,t)^- $\r\nwith\r\n$A(x,t)^+ = \\sum_k \\sum_r ({\\frac {\\hbar c^2}{1 V \\omega_k}})^{1/2} \\epsilon_r(k) a_r(k) e^{i(k \\cdot x - \\omega_k t)}$ \r\n(the absorption operators)\r\nand\r\n$ A(x,t)^- = \\sum_k \\sum_r ({\\frac {\\hbar c^2}{1 V \\omega_k}})^{1/2} \r\n\\epsilon_r(k) a_r^{\\dagger}(k) e^{-i(k \\cdot x - \\omega_k t)}$ (the emission operators).\r\nSince $[H,\r\na_r(k)]= [H, a_r^{\\dagger}(k') ]=0$, the $n_r(k)$ are constants.\r\n\\\\\r\n\\\\\r\n{\\bf Interaction with dipole field:}  Suppose $H_I= -D \\cdot E_T(0,t)$ where $D= \\sum_i e_i r_i$, generally we can\r\nignore the magnetic dipoles.  For intial state $A$ and final state $B$, we have\r\n$|A, n_r(k)\\rangle= |A\\rangle|n_r(k)\\rangle$ and\r\n$|B, n_r(k)\\pm 1\\rangle= |B\\rangle|n_r(k) \\pm 1 \\rangle$ and\r\n$E_T(0,t)=\r\ni \\sum_k \\sum_r ({\\frac {\\hbar \\omega_k}{2 V}})^{1/2} \\epsilon_r(k) [\r\na_r(k) e^{-i\\omega_k t} a_r^{\\dagger}(k) e^{i\\omega_k t} ] $ .\r\nFor emission,\r\n$\\langle B, n_r(k) +1 | H_I | A, n_r(k)\\rangle=\r\ni ({\\frac {\\hbar \\omega_k}{2 V}})^{1/2} \\langle n_r(k)+1 | a_r^{\\dagger}|n_r(k)\\rangle\r\n\\langle B | \\epsilon_r(k) \\cdot D|A\\rangle e^{i\\omega_k t} =\r\ni ({\\frac {\\hbar \\omega_k}{2 V}})^{1/2} \\langle {\\sqrt {n_r(k)+1}}\r\n\\langle B | \\epsilon_r(k) \\cdot D|A\\rangle e^{i\\omega_k t} $.  The transition probability \r\nbetween initial and final states per unit time\r\ncan be solved with  perturbation theory to give\r\n$w= {\\frac {2 \\pi} {\\hbar}} |\\langle B,n_r(k)+1|H_I|A, n_r(k)\\rangle|^2 \\delta(E_A-E_B-\\hbar \\omega_k)$.\r\nSo $w_{tot}(A \\rightarrow B)= {\\frac {e^2 \\omega^3}{3 \\pi \\hbar c^3}} |x_{BA}|^2$ and the lifetime $\\tau$ of\r\nthe excited state is ${\\frac 1 {\\tau}}= \\sum_n w_{tot}(A \\rightarrow B_n)$.  The total angular momentum and its\r\n$z$-component, $J$ and $M$ must satisfy the selection rule $\\Delta J, \\Delta M= (0, \\pm 1)$.\r\n\\\\\r\n\\\\\r\n{\\bf Order parameters:}\r\nWater is more symmetric than ice on average.  Transition to ice is a \\emph{broken symmetry}.  \r\nThe order parameter is related\r\nto bond formation.  For magnets, the order parameter is a sphere representing orientation.  For a crystal with\r\nperiodic structure, it is the distance from a reference atoms and the space is a square with identified edges,\r\ni.e.- a torus.  In $He^4$, it is the condensate wave function.  Superfluids have broken gauge symmetries.\r\n\r\n\r\n\r\n", "meta": {"hexsha": "7698d3a03197f34006e62231659cb58e6daf433d", "size": 106954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/physics.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/physics.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/physics.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": 46.0215146299, "max_line_length": 170, "alphanum_fraction": 0.5812592329, "num_tokens": 43575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6313100733516525}}
{"text": "\\lab{Algorithms}{Speeding up Python Functions: Vectorization}{Vectorization}\n\n\\objective{Demonstrates the importance of vectorization.}\n\nThis lab introduces two applied topics (Information Entropy and Chebyshev Polynomials) to explore how we can make functions faster through vectorization.  There are two primary motivations behind vectorizing code.  First, vectorized code is often much clearer and more concise than non-vectorized code.  The second, much larger motivation is performance.  Vectorized code is often magnitudes faster than non-vectorized code.  \n\nThe concept behind vectorizing code is move away from operating on one element at a time to operating on entire collections of elements at once.  This section will focus specifically on reducing the number of for loops in our program.  Let us look at two examples of functions that would be really useful if could vectorize them to make them execute faster.\n\n\\section*{Information Entropy}\n\nInformation entropy is loosely defined as the amount of information that is encoded in each bit of a signal. It is directly related to amount of compression that a signal can undergo without loss.\n\nFor example, suppose that our signal is an infinite string ``AAAAAAA...\" Since the signal never changes, each bit additional bit after the first add no new information. Thus the entropy in this case is zero.\n\nOn the other hand, we assign a truly random uniform binary source an entropy of one (such a source may be related to radioactive decay). This is since we have absolutely no clue what the next symbol we read will be.\n\nWe can empirically calculate the entropy of a given signal by the following:\n\\[\nH = -\\sum_k{p_k log_2(p_k)}\n\\]\nwhere $p_k$ is the probability of the kth symbol. Note that this fits the two conventions we set above since\n\\[\n-(1log_2(1) + 0 log_2(0)) = 0\n\\]\n\\[\n-(1/2log_2(1/2) + 1/2log_2(1/2)) = 1\n\\]\n\n\\begin{problem}\nWrite a function that finds the entropy of a array (you will need to flatten multidimensional arrays to a single dimension). You will also need to empirically calculate the probability of a given symbol (start by letting your symbols be integers). To find the probability of a symbol, you need to find the number of times it occurs in the sequence and divide it by the length of the sequence (watch out for integer division).\n\\end{problem}\n\nWe can test the entropy function that you just wrote against bit sources to see how ``random\" they are. For example, we can read an image into Python and view it using the following code:\n\\begin{lstlisting}[style=python]\n: from scipy import misc\n: img = misc.imread('cameraman.tif'); img\n\\end{lstlisting}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics{./Figures/CameramanClean.pdf}\n\\end{center}\n\\caption{The MIT camerman, a classic image used in image processing}\n\\label{fig:cameramanclean}\n\\end{figure}\nYou should see the image shown in Figure \\ref{fig:cameramanclean}. Now pass this image to our entropy function to calculate the entropy of the image data. We get a value of $7.009$. If this image were uniformily random, the entropy would be $8$, since each pixel is an $8$ bit number, and a uniform distribution of integers between $1$ and $128 = 2^8$ will have an entropy of $8$ (you can verify this fairly easily using the equation we defined above). This implies that the image has potential for compression.\n\n\\begin{problem}\nNow rewrite your function without using loops. This is an example of using vectorization to speed up algorithms. Use the cameraman image to test how much faster this function is than your original.\n\\end{problem}\n\n\\section*{Chebyshev Polynomials}\n\nOne special type of polynomials are the Chebyshev Polynomials. They are useful in a variety of applications including:\n\\begin{itemize}\n\\item Evaluating integrals using Gaussian quadrature\n\\item Solving PDE's\n\\item Speeding up iterative matrix methods (finding eigenvalues and solving large systems)\n\\item minimizing interpolation error\n\\end{itemize}\n\nWe will explain many of the these applications in subsequent chapters. The purpose of this example is primarily to give you a real opportunity to investigate ways to speed a process up on your own.\n\nThe value of the n-th Chebyshev Polynomials can be described by the following mathematical formulae\\footnotemark :\n\\[\nT_n(x) = cos(n cos^{-1}(x))\n\\]\n\n\\[\nT_n(x) = 2xT_{n-1}(x) - T_{n-2}(x), T_0(x) = 1, T_1(x) = x\n\\]\n\n\\footnotetext{Technically the first formula only works on the interval $[-1,1]$. There are more general formulae, piecewise defined using $\\cosh$ outside of $[-1,1]$, but for this exercise we'll stick to the above definition.}\n\n\\begin{problem}\nWrite a function that accepts a vector $x_0$ of values in $[-1,1]$ and a degree $n$.  The function should return an array evaluting each entry of $x_0$ at every chebeshev polynomial of degree $n$ or less. Essentially, the n-th column of the output should contain the $n-1$ Chebyshev Polynomial evaluated at $x_0$. \n\nYou will be writing four slightly different versions of this function.\n\\begin{enumerate}\n\\item Use only for loops and Python's \\li{math} library (you will need two for loops).\n\\item Same as previous, but replacing one for loop with a list comprehension.\n\\item Use \\li{sp.vectorize} to vectorize Python's \\li{math} functions.  Keep the list comprehension from previous part.\n\\item Use SciPy's optimized $\\cos$ and $\\arccos$ functions.\n\\end{enumerate}\n\nMake this function as fast as possible (this is the point of the exercise, writing a function solving this problem shouldn't be too difficult anymore). You should investigate both mathematical definitions, and how the number of {\\tt for} loops affects the speed. Explain how you optimized your function, and why other implementations would be slower.\n\\end{problem}\n", "meta": {"hexsha": "2e5fbb4f6515ef203c6fea5f5cf4afce94a465f3", "size": 5764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Vectorization/Vectorization_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/Vectorization/Vectorization_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/Vectorization/Vectorization_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": 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": 65.5, "max_line_length": 511, "alphanum_fraction": 0.7774115198, "num_tokens": 1387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.6313100657854338}}
{"text": "\\subsection{Gaussian Process Regression}\n\\label{gp}\n\nEvaluating the production curve for a specific kind of facility using\nfull fuel cycle simulations is relatively expensive, even in the\ncomputationally cheapest case of low-fidelity simulations. This is because a\nfuel cycle realization\ntypically computes many features that, though coupled to the production\ncurve, are not directly the production curve. For example, the mass balance of\nthe fuel cycle is physically bound the electricity production. However,\nin the particular once-through demonstration case used throughout this paper,\nthe mass balances are not explicitly taken into account when trying to meet\na power demand curve.\n\nAlternatively, surrogate models that predict the production curve directly\nhave many orders-of-magnitude fewer operations by virtue of not computing\nimplicit physical characteristics. This is not to say that the surrogate\nmodels are correct.  Rather, they are simply good enough to drive a demand\ncurve\noptimization. Surrogate models are used here inform a simulator about where\nin the parameter space to look next. Truth about production curves should\nstill be derived from the fuel cycle simulator and not the surrogate model.\nIn the WORG algorithm, Gaussian processes are used to form the model.\n\nGaussian processes are more fully covered elsewhere\n\\cite{rasmussen2006gaussian}. Using Gaussian process for optimization has\nalso been previously explored \\cite{osborne2009gaussian}, though such studies\ntend not to\ninvestigate the integral problems posed by facility deployment. As with\ndynamic time warping, a minimal but sufficient introduction to GP regression\nis presented\nfor the purposes of the deployment optimization.\nConsider the case of $Z$ simulations indexed by $z$ that each have a\n$\\Theta_z$ deployment schedule and $g_z(t, \\Theta_z)$ production curve.\n\nA Gaussian process of these $Z$ simulations is set by its mean and\ncovariance functions. The mean function is denoted as $\\mu(t, \\Theta)$ and\nis the expectation value $\\E$ of\nthe series of $G$ inputs:\n\\begin{equation}\n\\label{G}\nG = \\left\\{g_1(t, \\Theta_1), g_2(t, \\Theta_2), \\ldots,\n           g_Z(t, \\Theta_Z)\\right\\}\n\\end{equation}\nThe covariance function is denoted $k(t, \\Theta, t^\\prime, \\Theta^\\prime)$\nand is the expected value of the input to the mean. The mean and\ncovariance can be expressed as\nin Equations \\ref{mean-func} \\& \\ref{covar-func} respectively.\n\\begin{equation}\n\\label{mean-func}\n\\mu(t, \\Theta) = \\E G\n\\end{equation}\n\\begin{equation}\n\\label{covar-func}\nk(t, \\Theta, t^\\prime, \\Theta^\\prime) =\n    \\E\\left[(g_z(t, \\Theta) - \\mu(t, \\Theta))\n            (g_z(t^\\prime, \\Theta^\\prime) - \\mu(t^\\prime, \\Theta^\\prime))\n      \\right]\n\\end{equation}\nNote that in the above, the Gaussian process is itself $P+1$ dimensional,\nsince the means and covariance are a function of both the deployment\nschedule ($P$) and time ($+1$).\n\nThe Gaussian process $\\GP$ approximates the production curve\ngiven $Z$ simulations. Allow $*$ to indicate that the a quantity comes from\nthe model as opposed to coming from the results of the simulator. A model\nproduction curve can then be written using either functional or operator\nnotation, as appropriate:\n\\begin{equation}\n\\label{gp-def-approx}\ng_*(t, \\Theta) \\approx \\GP\\left(\\mu(t, \\Theta),\n                                 k(t, \\Theta, t^\\prime, \\Theta^\\prime)\\right)\n                \\equiv \\GP G\n\\end{equation}\nIn machine learning terminology, $G$ serves as the training set for the\nGP model. Furthermore, if the individual $g_z$ return a\nmultivariate result, then the model $g_*$ will also compute a result of\nthe same rank.\n\nNow, when performing a regression on Gaussian processes,\nthe nominal functional form for the covariance must be given.\nSuch a functional form is also known as the the kernel function.\nThe kernel contains the \\emph{hyperparameters} that are solved for to\nobtained a best-fit Gaussian process. The hyperparameters themselves are\ndefined based on the definition of the kernel function. Hyperparameter\nvalues are found via a regression of the maximal likelihood of\nthe production curve. Any functional form could potentially serve as a kernel\nfunction. However, a generally useful form is the is the exponential\nsquared. This kernel can be seen in Equation \\ref{exp2-kernel} with\nhyperparameters $\\ell$ and $\\sigma^2$ for a vector of parameters $r$:\n\\begin{equation}\n\\label{exp2-kernel}\nk(r, r^\\prime) = \\sigma^2 \\exp\\left[-\\frac{1}{2\\ell}(r - r^\\prime)^2 \\right]\n\\end{equation}\nHowever, other kernels such as the Mat\\'ern $3/2$ kernel and Mat\\'ern $5/2$\nkernel \\cite{paciorek2004nonstationary} were observed to be more robust for\nthe WORG method. These can be seen in Equations \\ref{matern-32} and\n\\ref{matern-52} respectively.\n\\begin{equation}\n\\label{matern-32}\nk(r, r^\\prime) = \\sigma^2\n                 \\left(1 + \\frac{\\sqrt{3}}{\\ell}|r - r^\\prime|\\right)\n                 \\exp\\left(-\\frac{\\sqrt{3}}{\\ell}|r - r^\\prime|\\right)\n\\end{equation}\n\\begin{equation}\n\\label{matern-52}\nk(r, r^\\prime) = \\sigma^2\n                 \\left(1 + \\frac{\\sqrt{5}}{\\ell}|r - r^\\prime|\n                         + \\frac{5}{3\\ell^2}|r - r^\\prime|^2\\right)\n                 \\exp\\left(-\\frac{\\sqrt{5}}{\\ell}|r - r^\\prime|\\right)\n\\end{equation}\n\nFrom here, say that $\\K$ is a covariance matrix\nsuch that the element at the $r$-th row and $r^\\prime$-th column is\ngiven by whichever kernel is chosen from\nEquations \\ref{exp2-kernel}-\\ref{matern-52}. Then the\nlog likelihood $\\log q$ of obtaining the training set production curves\n$G$ for a given time grid $\\mathbf{t}$ and deployment schedule is as\nseen in Equation \\ref{log-q}.\n\\begin{equation}\n\\label{log-q}\n\\log q(G|\\mathbf{t}, \\Theta)\n    = -\\frac{1}{2}G^\\top\\left(\\K + \\tau^2\\I\\right)^{-1}G\n      -\\frac{1}{2}\\log\\left|\\K + \\tau^2\\I\\right|\n      -\\frac{ZTP}{2}\\log 2\\pi\n\\end{equation}\nHere, $\\tau$ is the uncertainty in the production curves coming from the\nsimulations themselves. As most simulators do not report such uncertainties,\n$\\tau$ may be set to floating point precision. $\\I$ is the usual identity\nmatrix. The hyperparameters $\\ell$ and $\\sigma^2$ are then adjusted via\nstandard real-valued optimization methods such that Equation \\ref{log-q} is\nas close to zero as possible.\nThis regression of the Gaussian process itself yields the most likely\nmodel of the production curve knowing only a limited number of simulations.\n\nHowever, the purpose of such a Gaussian process regression is to evaluate\nthe production curve at points in time and for deployment schedules that\nhave not been simulated. Take a time grid $\\mathbf{t_*}$ and a hypothetical\ndeployment schedule $\\Theta_*$. Now call the covariance vector between\nthe training set and the model evaluation\n$\\mathbf{k}_* = \\mathbf{k}(\\mathbf{t_*}, \\Theta_*)$.\nThe production curve predicted by this Gaussian process is then given by\nthe following:\n\\begin{equation}\n\\label{metric-model}\n\\mathbf{g}_*(\\mathbf{t}_*, \\Theta_*) =\n    \\mathbf{k}_*^\\top \\left(\\K + \\tau^2\\I\\right)^{-1}G\n\\end{equation}\nEquations \\ref{mean-func}-\\ref{metric-model} are derived and discussed fully\nin \\cite{rasmussen2006gaussian}.\n\nImplementing the above Gaussian process mathematics for the specific\ncase of the WORG algorithm\nis not needed.  Free and open source Gaussian process modeling software\nlibraries already exist and are applicable to the regression problem here.\nScikit-learn v0.17 \\cite{scikit-learn} and George v0.2.1 \\cite{hodlr}\nimplement such a method and have a Python interface. George is specialized\naround Gaussian processes, and thus is preferred for WORG over scikit-learn,\nwhich is a general purpose machine learning library.\n\nAs an example, consider a Gaussian process between two power production\ncurves similar to the example used in \\S\\ref{dtw}. The first is a nominal 1\\% growth\nin GWe for 50 years starting at\n90 GWe in 2016. The second curve under-produces the first curve by 10\\%\nfor the first 25 years and over-produces by 10\\% for the last 25 years.\nAdditionally, assume that there is a 10\\% error on the training set data.\nThis will produce a model of the mean and covariance that splits the\ndifference between these two curves. This example may be seen graphically\nin Figure \\ref{gwe-model-}.\n\n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{gwe-model-.eps}\n\\caption{The Gaussian process model of a 1\\% growth curve along with the\nan initial 10\\% under production followed by a 10\\% under production.\nThe model is represented by the black line that runs between the red\ntraining points. Two standard deviations form the model are displayed as the\ngray region.}\n\\label{gwe-model-}\n\\end{figure}\n\nThe simple example above does not take advantage of an important\nfeature of Gaussian processes. Namely, it is not limited to two production\ncurves in the training set.  As many as desirable may be used.  This will\nallow the WORG algorithm to dynamically adjust the number of $Z$ simulations\nwhich are used to predict the next deployment schedule. WORG is thus capable\nof\neffortlessly expanding $Z$ when new and useful simulations yield valuable production\ncurves.  However, it also enables $Z$ to contract to discard production\ncurves that would drive the deployment schedule away from an optimum.\n\nNow that the Gaussian process regression and dynamic time warping tools have\nbeen added to the toolbox, the architecture of the WORG algorithm can\nitself be described.\n\n\\clearpage\n", "meta": {"hexsha": "39d599e6e82facf3e887effde7ac8182945e3bea", "size": 9429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gp.tex", "max_stars_repo_name": "scopatz/fc-deploy-opt", "max_stars_repo_head_hexsha": "dfc3a93f1eb8981317a4f332bc76bd6f4bedd6b7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-02-01T16:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-05T11:58:31.000Z", "max_issues_repo_path": "gp.tex", "max_issues_repo_name": "scopatz/fc-deploy-opt", "max_issues_repo_head_hexsha": "dfc3a93f1eb8981317a4f332bc76bd6f4bedd6b7", "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": "gp.tex", "max_forks_repo_name": "scopatz/fc-deploy-opt", "max_forks_repo_head_hexsha": "dfc3a93f1eb8981317a4f332bc76bd6f4bedd6b7", "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.8629441624, "max_line_length": 84, "alphanum_fraction": 0.7533142433, "num_tokens": 2452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6312356341985123}}
{"text": "\\section{Types}\nTypes in Amulet are composed of functions, tuples and primitives. You can store multiple types together in a tagged union (or sum type). A tagged union with one entry is a useful way of boxing a type to ensure that it cannot be accidentally used as an object of the same type but different semantics.\n\nTypes can also be generic over one or more parameters. When inferring the type for an expression, the most generic type will always be used. Constraints can be put on generic parameters by specifying type class implementations that must exist for this set of parameters. There can be multiple constraints, each applying to multiple parameters.\n\nThere is no subtyping in Amulet, \\textit{however} type constraints can be loosened through the upcast operator: this converts an existing value to a more general type: for instance \\texttt{[a]} can be upcast to \\texttt{Show b}.\n\n\\subsection{Types and kinds}\n\\begin{quote}\nA kind is the type of a type constructor or, less commonly, the type of a higher-order type operator. A kind system is essentially a simply typed lambda calculus \"one level up\", endowed with a primitive type, denoted $*$ and called \\texttt{Type}, which is the kind of any data type which does not need any type parameters.\\cite{kindsWikipedia}\n\\end{quote}\n\nThe base lambda calculus in Amulet is that which operates on values, namely the input program. Every value must have a corresponding type. 0 might have type \\texttt{int} and the empty list type \\texttt{[a]}. These have kinds $*$ and $* \\to *$ respectively, where $*$ is a shorthand notation for \\texttt{Type}.\n\nHowever $*$ is not the only kind in Amulet. Constraints, such as \\texttt{Show Int}, also have a kind called, imaginatively, \\texttt{Constraint}.  However type classes generally take one or more parameters and so have kind  $* \\to \\mathtt{Constraint}$.\n\n\\subsubsection{Unions and rows}\nIn order to build more complex types Amulet adds row and union kinds. These are polymorphic over kinds and so have the signature $\\square \\to \\square$. Here the $\\square$ symbol represents all kinds such as types, constraints, rows and unions. These can then be used to create a compound type: $\\mathtt{Row} \\to *$\n\nUnion kinds represent a unique, unordered set of a given kind. They are denoted by \\texttt{Union} or $\\%$. Unions are written using basic set notation: $\\left \\{  \\mathtt{Int}, \\mathtt{Bool} \\right \\}$ is a set containing the \\texttt{Int} and \\texttt{Boolean} types.\n\nRow kinds represent a map of string keys to kinds (like a disjoint union but with strings). This is denoted by \\texttt{Row} or $\\#$. Rows are written with the key value pairs within parenthesis: $\\left ( \\mathtt{name : String}, \\mathtt{age : Int} \\right )$.\n\nUnions and rows share similar semantics as they allow being combined with another object of the same kind. For instance you can add \\texttt{String} to the union \\texttt{a} with  $\\left \\{ \\mathtt{String} | \\mathtt{a} \\right \\}$. This also highlights the fact that unions and rows can be polymorphic (this case is $\\mathtt{Row} \\to \\mathtt{Row}$). This simple fact allows emulating subtyping of these kinds. When creating a union of row objects where both sides have the same key the value must be unifiable.\n\nIt is also possible to take the union of two polymorphic kinds such as $\\left \\{ { a | b }\\right \\}$ (however, type inference is not guaranteed).\n\n\\subsection{Universal quantification}\nUniversal quantification, or $\\forall$ is a way of marking a type that can exists for all types matching its criteria. For instance the identity function would be universally quantified as any type can be applied to it. \n\n\\subsubsection{Constraints}\nFor universal quantification to be useful, constraints must be added to the type. Constraints come in two forms: a type class constraint, or a unification requirement. \n\nThe former requires that a particular type class instance exists: $\\forall a . \\mathtt{Num}\\ a \\Rightarrow a \\rightarrow a$ states that $\\mathtt{Num}\\ a$ must exist. It is worth noting that any number of variables (or constant types) can be give\nn to the type class: $\\forall a. \\mathtt{Num\\ Int} \\Rightarrow a \\rightarrow a$ is equally valid, though meaningless as the only valid implementation would be the identity function.\n\nA unification requirement states that two types must unify for this type to exist. An simple example might be $\\forall a. a \\sim \\mathtt{Int} \\Rightarrow a$. This type is pointless as the only value of $a$ which will satisfy this requirement is \\texttt{Int}. However, this can be useful with more complex types such as rows or unions.\n\n\\subsection{Record types}\nRecord types express a way of handling key-value pairs where the keys are known at compile time. Records are implemented using rows, with a hidden polymorphic argument, allowing for converting records with many fields to records with less. Strictly records are defined as:\n\n\\begin{minted}{haskell}\ndata Record p = forall a . Record ( a |  p )\n\\end{minted}\n\n\\subsection{Tagged unions}\nTagged unions, also known as \\textit{sum-of-product types} or \\textit{Algebraic Data Types}, are data structures that can take on several variations. Only one of these variants may be in use at once, and a tag field explicitly indicates so.\n\nTagged unions are represented using a row, where each entry is the type of the corresponding entry. For example:\n\n\\begin{minted}{haskell}\ndata Expr = Var Name\n          | Abs Name Expr\n          | App Expr Expr\n\\end{minted}\ncould be represented as\n\\begin{minted}{haskell}\ntype ExprTotal = (\n    Var : Name -> Expr, \n    Abs : Name -> Expr -> Expr, \n    App : Expr -> Expr -> Expr,\n)\n\ndata Expr = Expr (Union ExprTotal)\n\\end{minted}\n\n\\texttt{Union} is an internal Amulet type which is understood by the compiler to form a union type.\n\n\\paragraph{Using the union kind}\nIt would be nice to replace this with a union as it doesn't \\textit{need} to have the types of the constructor. However this is hard as the union is over types rather than strings.\n\n\\subsubsection{Narrowed functions}\nThe main benefit of using rows to represent ADTs is that we can define functions which only take a subset of the values: for instance `head` could only accept non-nil lists.\n\nFor example, require a function which accepts \\texttt{Abs} or \\texttt{App} but not \\texttt{Var}. Lets us consider the type $\\mathtt{ExprPartial}\\ p$ which represents a subset of \\texttt{Expr}. We can define these requirements for this function:\n\nYou should be able to pass in anything of the form:\n\\begin{itemize}\n\\item \\texttt{ExprPartial (App : _, Abs : _)}\n\\item \\texttt{ExprPartial (App : _)}\n\\item \\texttt{ExprPartial (Abs : _)}\n\\end{itemize}\n\nBut not of types:\n\n\\begin{itemize}\n\\item \\texttt{ExprPartial ()}\n\\item \\texttt{ExprPartial (Var : _ | p)}\n\\end{itemize}\n \nNamely the arguments passed to this required function must be a subset of \\texttt{(App : _, Abs : _)} and not an empty list. The first is trivial to solve: we can define a constraint $\\mathtt{RowSubset}\\ p a$ which requires that $a \\subset p$.\n\n\\begin{minted}{haskell}\ntype RowSubset p a = (a | p) ~ p\n\\end{minted}\n\nMore difficult is defining a type which refuses the empty row. This could either be done with a non-empty-row constraint, or a more general \"does not unify\" requirement. For now we will consider the former and call it $\\mathtt{NonEmpty}\\ a$.\n\nWe can then give the definition of $\\mathtt{ExprPartial}\\ p$ and of our function:\n\n\\begin{minted}{haskell}\ndata ExprPartial a = ExprPartial (RowSubset ExprTotal a)\n\ntype Partial p = forall a . NonEmpty a => RowSubset p a => p\nfunc : ExprPartial (Partial (App : _, Abs : _))\n\\end{minted}\n\nOf course \\texttt{Expr} can now be generalized to:\n\n\\begin{minted}{haskell}\ntype Expr = ExprPartial ExprTotal\n\\end{minted}\n\n\\subsubsection{Pattern matching}\nThis form of narrowing can also be used in pattern matching. Each case can remove one of the possible values of `p` from `ExprPartial`:\n\n\\begin{minted}{haskell}\ncase (x : Expr) of\n| Abs name _ = name\n| y = ... -- y : ExprPartial (Var : _, App : _) as it cannot be Abs if you hit this point\n\\end{minted}\n\n\\subsubsection{GADTs}\nIt is also possible to define GADTs in the same way, though obviously the resulting type is not just \\texttt{Expr}. For instance, the GADT\n\n\\begin{minted}{haskell}\ndata Expr a where\n    I   : Int  -> Expr Int\n    B   : Bool -> Expr Bool\n    Add : Expr Int -> Expr Int -> Expr Int\n\\end{minted}\n\nwould be represented:\n\n\\begin{minted}{haskell}\ntype ExprTotal a = (\n    I   : Int -> Expr Int\n    B   : Bool -> Expr Bool\n    Add : Expr Int -> Expr Int -> Expr Int\n)\n\\end{minted}\n\n\\subsection{Type classes}\nType classes are a way to ensure different types have a consistent interface, and to constrain polymorphic types on having an instance of a type class. A fully instantiated type class resolves to a type of \\texttt{Constraint}.\n\nA constraint section on a type is given as a fat-arrow behind the type. For example, the following snippet says that ``for all types for which there is an instance of \\texttt{a}, there is a function \\texttt{show} transforming it into a \\texttt{string}.''\n\n\\begin{minted}{haskell}\nshow : forall a. Show a => a -> String\n\\end{minted}\n\nThe type-class mechanism poses a way to do name overloading based on types. In contrast to, say, Java interfaces, type classes allow the user to be parametric on the return type, not only the parameter types.\n\n\\begin{minted}{haskell}\nclass Read a where\n  read : String -> a\n\\end{minted}\n\nWhen resolving type classes the type checking algorithm will unify the current type across all instances. If more than one instance matches then an error will be created.\n\nType classes can also be named and a specific implementation can be used at compile time. Implementations are passed in to the type lambda. For instance using the above show definitions we get:\n\n$$\n\\mathtt{show} = \\Lambda (a : \\mathtt{Type})\\ (x : \\mathtt{Num}\\ a) \\to \\lambda (x : a)\\ (y : a) \\to function\\ body\n$$\n\nType classes can take have multiple parameters. In the case where some parameters define others, functional dependencies\\cite{funcDeps} can be used to prevent conflicting definitions.\n\nSome type classes will be auto-generated by the compiler (such as \\texttt{Eq} or \\texttt{Show}) if the criteria are matched (for instance all child types also implement \\texttt{Show}). Auto-generated instances can safely be overridden or masked: there will not be a compile error if both a auto-generated and normal instance match.\n\n\\paragraph{Named implementations}\nAll type class instances require an explicit name. This allows us to explicitly specific implementations to functions.\n\n\\paragraph{Type families}\nType classes can also include type definitions\\cite{typeFams}, allowing for type aliases and data definitions to exist and be instantiated within a type class.\n", "meta": {"hexsha": "878251f736f138bdcae93fa69adc14ce83389082", "size": 10819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "design/semantics/types.tex", "max_stars_repo_name": "SquidDev/amulet", "max_stars_repo_head_hexsha": "1b1fea8188f67e6e338f8040a770f11acf179cfb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-05-31T23:41:37.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-17T23:11:24.000Z", "max_issues_repo_path": "design/semantics/types.tex", "max_issues_repo_name": "SquidDev/amulet", "max_issues_repo_head_hexsha": "1b1fea8188f67e6e338f8040a770f11acf179cfb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-05-31T15:22:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-21T19:03:04.000Z", "max_forks_repo_path": "design/semantics/types.tex", "max_forks_repo_name": "SquidDev/amulet", "max_forks_repo_head_hexsha": "1b1fea8188f67e6e338f8040a770f11acf179cfb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-10-16T19:41:13.000Z", "max_forks_repo_forks_event_max_datetime": "2016-10-16T19:41:13.000Z", "avg_line_length": 61.4715909091, "max_line_length": 507, "alphanum_fraction": 0.7540438118, "num_tokens": 2666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6312356300708791}}
{"text": "%---------------------------Area-----------------------------\n\\section{Area\\label{s:quad-area}}\n\nSigned area, defined as\n\\[\nq = \\frac {1} {4} \\sum_{i=0}^3 \\alpha_i\n\\]\nis useful for two purposes: first, the sign can indicate elements\nthat have vertices ordered incorrectly or arranged in a concave\npattern; and second, the magnitude can be used to identify\nelements that are too small for accurate analysis.\nFigure~\\ref{f:quad-areas} shows how each vertex area contributes to\nthe total area of a quadrilateral.\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[width=2in]{quad-areas}\n  \\caption{The areas associated with each vertex may be summed and\n           weighted to get the area of the entire quadrilateral.%\n                                                                  \\label{f:quad-areas}}\n\\end{figure}\n\n\\quadmetrictable{area}%\n{$L^2$}%                                    Dimension\n{$[0,DBL\\_MAX]$}%                           Acceptable range\n{$[0,DBL\\_MAX]$}%                           Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                   Full range\n{$1$}%                                      Unit square\n{--}%                                       Citation\n{v\\_quad\\_area}%                            Verdict function name\n\n", "meta": {"hexsha": "725be85044e31c8446cfe4d5919bf6a1948a0b5e", "size": 1248, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadArea.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/QuadArea.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/QuadArea.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": 87, "alphanum_fraction": 0.5344551282, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6311906507840547}}
{"text": "\\subsection{Topology of Euclidean spaces}\\label{subsec:topology_of_euclidean_spaces}\n\n\\begin{definition}\\label{def:euclidean_space}\n  \\todo{Define euclidean spaces}.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:real_metric_and_order_topologies_coincide}\n  For the real numbers, the \\hyperref[def:metric_topology]{metric} and \\hyperref[def:order_topology]{order topologies} coincide.\n\\end{theorem}\n\\begin{proof}\n  The metric topology \\( \\mscrT_M \\) is generated by the \\hyperref[def:topological_base]{base}\n  \\begin{equation*}\n    \\mathcal{B} \\coloneqq \\{ B(x, r) \\colon x \\in \\BbbR, r \\in \\BbbR_{>0} \\}\n  \\end{equation*}\n  and the order topology \\( \\mscrT_O \\) is generated by the \\hyperref[def:topological_subbase]{subbase}\n  \\begin{equation*}\n    \\mathcal{P} \\coloneqq \\{ (a, \\infty) \\colon a \\in \\BbbR \\} \\cup \\{ (\\infty, b) \\colon b \\in \\BbbR \\}.\n  \\end{equation*}\n\n  The inclusion \\( \\mathcal{B} \\subseteq FI(\\mathcal{P}) \\) is obvious since any ball \\( B(x, r) \\) is the intersection of the two rays\n  \\begin{equation*}\n    B(x, r) = (x - r, \\infty) \\cap (-\\infty, x + r).\n  \\end{equation*}\n\n  Thus, \\( \\mscrT_M \\subseteq T_O \\). We now only need to show that \\( \\mathcal{B} \\) is a base for \\( \\mscrT_O \\).\n\n  Let \\( U \\in T_O \\). Since \\( FI(\\mathcal{P}) \\) is a base for \\( \\mscrT_O \\), there \\hyperref[def:topological_base/union]{exists} a family \\( \\{ U_i \\}_{i \\in I} \\subseteq FI(\\mathcal{P}) \\) such that\n  \\begin{equation*}\n    U = \\bigcup_{i \\in I} U_i.\n  \\end{equation*}\n\n  We only need to express every \\( U_i \\) as a union of balls from \\( \\mathcal{B} \\). There are several possibilities:\n  \\begin{itemize}\n    \\item if \\( U_i \\) is the open interval \\( (a, \\infty) \\),\n          \\begin{equation*}\n            (a, \\infty) = \\bigcup_{i=1}^\\infty B(a + i, 1).\n          \\end{equation*}\n\n    \\item if \\( U_i \\) is the open interval \\( (-\\infty, b) \\),\n          \\begin{equation*}\n            (-\\infty, b) = \\bigcup_{i=1}^\\infty B(b - i, 1).\n          \\end{equation*}\n\n    \\item if \\( U_i \\) is the intersection \\( (a, \\infty) \\cap (-\\infty, b), a < b \\),\n          \\begin{equation*}\n            (a, \\infty) \\cap (-\\infty, b) = B(\\tfrac {a + b} 2, \\tfrac {b - a} 2)\n          \\end{equation*}\n\n    \\item if \\( U_i \\) is the empty set,\n          \\begin{equation*}\n            \\varnothing = \\bigcup \\varnothing \\text{ (see \\fullref{def:basic_set_operations/union})}.\n          \\end{equation*}\n  \\end{itemize}\n\n  Thus, \\( U_i \\) is the union of an at most countable amount of balls. The countable union of countable sets is again countable, hence by \\fullref{def:topological_base/union}, \\( \\mathcal{B} \\) is a base for \\( \\mscrT_O \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:rn_bounded_iff_totally_bounded}\n  A set in \\( \\BbbR^n \\) is totally \\hyperref[def:totally_bounded_set]{bounded} if and only if it is \\hyperref[def:metric_space/bounded_set]{bounded}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Follows from \\fullref{thm:totally_bounded_sets_are_bounded}.\n  \\NecessitySubProof Let \\( A \\) be a bounded set in \\( \\BbbR^n \\) and let \\( B(x, r) \\) be a ball containing \\( A \\). Fix \\( \\varepsilon > 0 \\).\n\n  Denote by \\( e_1, \\ldots, e_n \\) the \\hyperref[def:hamel_basis]{basis} of \\( \\BbbR^n \\). Denote by \\( m \\) the smallest integer such that \\( m \\varepsilon \\geq r \\).\n\n  We can create a grid around \\( B(x, r) \\) as follows:\n\n  Define the set\n  \\begin{equation*}\n    \\left\\{ x + \\sum_{i=1}^n [k_i \\varepsilon] e_i \\colon \\forall i = 1, \\ldots, n: k_i = 1, \\ldots, m \\right\\}.\n  \\end{equation*}\n\n  is finite. Furthermore, it is an \\( \\varepsilon \\)-net of \\( A \\). Indeed, let \\( y \\in A \\). Denote its coordinates along \\( e_1, \\ldots, e_n \\) by \\( y_1, \\ldots, y_n \\). Then \\( y \\) is contained in the ball\n  \\begin{equation*}\n    B\\left(x + \\sum_{i=1}^n [\\ceil(y_i) \\varepsilon] e_i, \\varepsilon \\right).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[Heine-Borel theorem]\\label{thm:heine_borel}\n  A set in \\( \\BbbR^n \\) is compact in the sense of \\fullref{def:compact_space} if and only if it is closed and bounded.\n\\end{theorem}\n\\begin{proof}\n  Follows from \\fullref{thm:rn_bounded_iff_totally_bounded} and \\fullref{thm:complete_metric_space_compact_conditions/closed_totally_bounded}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:real_supremum_of_closure}\n  The supremum (resp. infimum) of a set \\( A \\subseteq \\BbbR \\), if it exists, is equal to the supremum (resp. infimum) of \\( \\cl A \\).\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Denote by \\( M \\) the supremum of \\( A \\). Assume that it is not a supremum of \\( \\cl A \\), that is, there exists an upper bound \\( M' \\) of \\( \\cl A \\) such that \\( M' < M \\). But this is impossible because \\( A \\subseteq \\cl A \\).\n\n  Therefore, \\( M \\) is a supremum of \\( \\cl A \\).\n\n  \\NecessitySubProof Denote by \\( M \\) the supremum of \\( \\cl A \\). Assume that it is not a supremum of \\( A \\), that is, there exists an upper bound \\( M' \\) of \\( A \\) such that \\( M' < M \\).\n\n  Let \\( \\{ x_i \\}_{i=1}^\\infty \\subseteq A \\) be a sequence that converges to \\( M \\). Then\n  \\begin{equation*}\n    x_i < M' < M.\n  \\end{equation*}\n\n  By \\fullref{thm:squeeze_lemma/sequences}, we have \\( M' = M \\), which contradicts our choice of \\( M' \\). Thus, \\( M \\) is the supremum of \\( A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:real_bounded_set_has_supremum}\n  Every nonempty \\hyperref[def:metric_space/bounded_set]{bounded set} in \\( \\BbbR \\) has a supremum and infimum.\n\\end{proposition}\n\\begin{proof}\n  Let \\( A \\subseteq \\BbbR \\) be a nonempty bounded set. By \\fullref{thm:heine_borel}, the set \\( \\cl A \\) is compact. By \\fullref{thm:weierstrass_extreme_value_theorem}, the identity function \\( \\id: \\BbbR \\to \\BbbR \\) attains its minimum \\( m \\) and maximum \\( M \\) on \\( \\cl A \\). Note that both \\( m \\) and \\( M \\) do not have to belong to \\( A \\), but \\( m \\) is a lower bound and \\( M \\) is an upper bound of the set \\( A \\).\n\n  If we take any other upper bound \\( M' \\) of \\( A \\), then by \\fullref{thm:real_supremum_of_closure},\n  \\begin{equation*}\n    M' \\geq \\sup A = \\sup \\cl A = M.\n  \\end{equation*}\n\n  Hence, \\( M \\) is the least upper bound of \\( A \\).\n\n  We can analogously prove that \\( m \\) is the greatest lower bound of \\( A \\).\n\\end{proof}\n", "meta": {"hexsha": "c5c0733666f409484c9a5d64d71e85c31a56a4c7", "size": 6245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topology_of_euclidean_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/topology_of_euclidean_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/topology_of_euclidean_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": 52.0416666667, "max_line_length": 431, "alphanum_fraction": 0.6382706165, "num_tokens": 2177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.6311906449881174}}
{"text": "\\section{Universes}\n\n\\index{universe|(}\n\\index{universal family|(}\nTo complete our specification of dependent type theory, we introduce type theoretic \\emph{universes}. Universes are types that consist of types. In other words, a universe is a type $\\UU$ that comes equipped with a type family $\\Ty$ over $\\UU$, and for any $X:\\UU$ we think of $X$ as an \\emph{encoding}\\index{encoding of a type in a universe} of the type $\\Ty(X)$. We call this type family the \\emph{universal type family}.\n\nThere are several reasons to equip type theory with universes. One reason is that it enables us to define new type families over inductive types, using their induction principle. For example, since the universe is itself a type, we can use the induction principle of $\\bool$ to obtain a map $P:\\bool\\to\\UU$ from any two terms $X_0,X_1:\\UU$. Then we obtain a type family over $\\bool$ by substituting $P$ into the universal type family:\n\\begin{equation*}\n  x:\\bool\\vdash \\Ty(P(x))~\\type\n\\end{equation*}\nsatisfying $\\Ty(P(0_\\bool))\\jdeq \\Ty(X_0)$ and $\\Ty(P(1_\\bool))\\jdeq \\Ty(X_1)$.\n\nWe use this way of defining type families to define many familiar relations over $\\N$, such as $\\leq$ and $<$. We also introduce a relation called \\emph{observational equality} $\\EqN$ on $\\N$, which we can think of as equality of $\\N$. This relation is reflexive, symmetric, and transitive, and moreover it is the least reflexive relation. Furthermore, one of the most important aspects of observational equality $\\EqN$ on $\\N$ is that $\\EqN(m,n)$ is a type for every $m,n:\\N$, unlike judgmental equality. Therefore we can use type theory to reason about observational equality on $\\N$. Indeed, in the exercises we show that some very elementary mathematics can already be done at this early stage in our development of type theory.\n\nA second reason to introduce universes is that it allows us to define many types of types equipped with structure. One of the most important examples is the type of groups\\index{group}, which is the type of types equipped with the group operations satisfying the group laws, and for which the underlying type is a set\\index{set}. We won't discuss the condition for a type to be a set until \\cref{chap:hierarchy}, so the definition of groups in type theory will be given much later. Therefore we illustrate this use of the universe by giving simpler examples: pointed types, graphs, and reflexive graphs.\n\nOne of the aspects that make universes useful is that they are postulated to be closed under all the type constructors. For example, if we are given $X:\\UU$ and $P:\\Ty(X)\\to \\UU$, then the universe is equipped with a term\n\\begin{equation*}\n  \\check{\\Sigma}(X,P):\\UU\n\\end{equation*}\nsatisfying the judgmental equality $\\Ty(\\check{\\Sigma}(X,P)\\jdeq\\sm{x:\\Ty(X)}\\Ty(P(x))$. We will similarly assume that any universe is closed under $\\Pi$-types and the other ways of forming types. However, there is an important restriction: it would be inconsistent to assume that the universe is contained in itself. One way of thinking about this is that universes are types of \\emph{small} types, and it cannot be the case that the universe is small with respect to itself. We address this problem by assuming that there are many universes: enough universes so that any type family can be obtained by substituting into the universal type family of some universe.\n\n\\subsection{Specification of type theoretic universes}\n\nIn the following definition we already state that universes are closed under identity types. Identity types will be introduced in \\cref{chap:identity}.\n\n\\begin{defn}\n  A \\define{universe} in type theory is a closed type $\\UU$\\index{U, V, W@{$\\UU$, $\\mathcal{V}$, $\\mathcal{W}$}|see {universe}} equipped with a type family $\\Ty$\\index{T@{$\\Ty$}|see {universal family}} over $\\UU$ called the \\define{universal family}\\index{family!universal family}, equipped with the following structure:\n  \\begin{enumerate}\n  \\item $\\UU$ is closed under $\\Pi$, in the sense that it comes equipped with a function\n    \\begin{equation*}\n      \\check{\\Pi} :\\prd{X:\\UU}(\\Ty(X)\\to\\UU)\\to\\UU\n    \\end{equation*}\n    for which the judgmental equality\n    \\begin{equation*}\n      \\Ty\\big(\\check{\\Pi}(X,P)\\big)\\jdeq \\prd{x:\\Ty(X)}\\Ty(P(x)).\n    \\end{equation*}\n    holds, for every $X:\\UU$ and $P:\\Ty(X)\\to\\UU$.\n  \\item $\\UU$ is closed under $\\Sigma$ in the sense that it comes equipped with a function\n    \\begin{equation*}\n      \\check{\\Sigma} :\\prd{X:\\UU}(\\Ty(X)\\to\\UU)\\to\\UU\n    \\end{equation*}\n    for which the judgmental equality\n    \\begin{equation*}\n      \\Ty\\big(\\check{\\Sigma}(X,P)\\big) \\jdeq \\sm{x:\\Ty(X)}\\Ty(P(x))\n    \\end{equation*}\n    holds, for every $X:\\UU$ and $P:\\Ty(X)\\to\\UU$.\n  \\item $\\UU$ is closed under identity types, in the sense that it comes equipped with a function\n    \\begin{equation*}\n      \\check{\\mathrm{I}} : \\prd{X:\\UU}\\Ty(X)\\to(\\Ty(X)\\to\\UU)\n    \\end{equation*}\n    for which the judgmental equality\n    \\begin{equation*}\n      \\Ty\\big(\\check{\\mathrm{I}}(X,x,y)\\big)\\jdeq (\\id{x}{y})\n    \\end{equation*}\n    holds, for every $X:\\UU$ and $x,y:\\Ty(X)$.\n  \\item $\\UU$ is closed under coproducts, in the sense that it comes equipped with a function\n    \\begin{equation*}\n      \\check{+}:\\UU\\to (\\UU\\to\\UU)\n    \\end{equation*}\n    that satisfies $\\Ty\\big(X\\check{+}Y\\big)\\jdeq \\Ty(X)+\\Ty(Y)$.\n  \\item $\\UU$ contains terms $\\check{\\emptyt},\\check{\\unit},\\check{\\N}:\\UU$\n    that satisfy the judgmental equalities\n    \\begin{align*}\n      \\Ty\\big(\\check{\\emptyt}\\big) & \\jdeq \\emptyt \\\\\n      \\Ty\\big(\\check{\\unit}\\big) & \\jdeq \\unit \\\\\n      \\Ty(\\check{\\N}) & \\jdeq \\N.\n    \\end{align*}\n  \\end{enumerate}\n  Given a universe $\\UU$, we say that a type $A$ in context $\\Gamma$ is \\define{small}\\index{small type}\\index{universe!small types} with respect to $\\UU$ if it occurs in the universe, i.e., if it comes equipped with a term $\\check{A}:\\UU$ in context $\\Gamma$, for which the judgment\n  \\begin{equation*}\n    \\Gamma\\vdash\\Ty\\big(\\check{A}\\big)\\jdeq A~\\type\n  \\end{equation*}\n  holds. If $A$ is small with respect to $\\UU$, we usually write simply $A$ for $\\check{A}$ and also $A$ for $\\Ty(\\check{A})$. In other words, by $A:\\UU$ we mean that $A$ is a small type. \n\\end{defn}\n\n\\begin{rmk}\n  Since ordinary function types are defined as a special case of dependent function types, we don't have to assume that universes are closed under ordinary function types. Similarly, it follows from the assumption that universes are closed under dependent pair types that universes are closed under cartesian product types.\n\\end{rmk}\n\n\\subsection{Assuming enough universes}\n\n\\index{enough universes|(}\n\\index{universe!enough universes|(}\n  Most of the time we will get by with assuming one universe $\\UU$, and indeed we recommend on a first reading of this text to simply assume that there is one universe $\\UU$. However, sometimes we might need a second universe $\\mathcal{V}$ that contains $\\UU$ as well as all the types in $\\UU$. In such situations we cannot get by with a single universe, because the assumption that $\\UU$ is a term of itself would lead to inconsistencies like the Russel's paradox.\n\n  Russel's paradox is the famous argument that there cannot be a set of all sets. If there were such a set $S$, then we could consider Russel's subset\n  \\begin{equation*}\n    R:=\\{x\\in S\\mid x\\notin x\\}.\n  \\end{equation*}\n  Russell then observed that $R\\in R$ if and only if $R\\notin R$, so we reach a contradiction. A variant of this argument reaches a similar contradiction when we assume that $\\UU$ is a universe that contains a term $\\check{\\UU}:\\UU$ such that $\\mathcal{T}\\big(\\check{\\UU}\\big)\\jdeq \\UU$. In order to avoid such paradoxes, Russell and Whitehead formulated the \\emph{ramified theory of types} in their book \\emph{Principia Mathematica}. The ramified theory of types is a precursor of Martin L\\\"of's type theory that we are studying in this course.  \n\n  Even though the universe is not a term of itself, it is still convenient if every type, including any universe, is small with respect to \\emph{some} universe. Therefore we will assume that there are sufficiently many universes: we will assume that for every finite list of types\n\\begin{align*}\n  \\Gamma_1 & \\vdash A_1~\\type \\\\\n  & ~\\vdots \\\\\n  \\Gamma_n & \\vdash A_n~\\type,\n\\end{align*}\nthere is a universe $\\UU$ that contains each $A_i$ in the sense that $\\UU$ comes equipped with a term\n\\begin{align*}\n  \\Gamma_i\\vdash \\check{A}_i:\\UU\n\\end{align*}\nfor which the judgment\n\\begin{equation*}\n  \\Gamma_i\\vdash \\Ty\\big(\\check{A}_i\\big)\\jdeq A_i~\\type\n\\end{equation*}\nholds. With this assumption it will rarely be necessary to work with more than one universe at the same time.\n\n\\begin{rmk}\\label{rmk:universe-constructions}\n  Using the assumption that for any finite list of types in context there is a universe that contains those types, we obtain many specific universes:\n  \\begin{enumerate}\n  \\item There is a \\emph{base universe} $\\UU_0$ that we obtain using the empty list of types in context. This is a universe, but it isn't specified to contain any further types.\n  \\item Given a finite list\n    \\begin{align*}\n      \\Gamma_1 & \\vdash A_1~\\type \\\\\n      & ~\\vdots \\\\\n      \\Gamma_n & \\vdash A_n~\\type,\n    \\end{align*}\n    of types in context, and a universe $\\UU$ that contains them, there is a universe $\\UU^+$ that contains all the types in $\\UU$ as well as $\\UU$. More precisely, it is specified by the finite list\n    \\begin{align*}\n      & \\vdash \\UU~\\type \\\\\n      X:\\UU & \\vdash \\mathcal{T}(X)~\\type.\n    \\end{align*}\n    The universe $\\UU^+$ therefore contains the type $\\UU$ as well as every type in $\\UU$, in the following sense\n    \\begin{align*}\n      & \\vdash \\check{\\UU}:\\UU^+ & & \\vdash \\mathcal{T}^+(\\check{\\UU})\\jdeq\\UU~\\type \\\\\n      X:\\UU & \\vdash \\check{\\mathcal{T}}(X) :\\UU^+ & X:\\UU & \\vdash \\mathcal{T}^+(\\check{\\mathcal{T}}(X))\\jdeq \\mathcal{T}(X)~\\type.\n    \\end{align*}\n    In particular, we obtain a function $i:\\UU\\to\\UU^+$ that includes the $\\UU$-small types into $\\UU^+$.\n    \n    Note that since the universe $\\UU^+$ contains all the types in $\\UU$, it also contains the types $A_1,\\ldots,A_n$. To see this, we derive that there is a code for $A_i$ in $\\UU^+$.\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma_i\\vdash\\check{A}_i:\\UU$}\n      \\AxiomC{$X:\\UU\\vdash\\check{\\mathcal{T}}(X):\\UU^+$}\n      \\UnaryInfC{$\\Gamma_i,X:\\UU\\vdash\\check{\\mathcal{T}}(X):\\UU^+$}\n      \\BinaryInfC{$\\Gamma_i\\vdash\\check{\\mathcal{T}}(\\check{A}_i):\\UU^+$}\n    \\end{prooftree}\n    We leave it as an exercise to derive the judgmental equality\n    \\begin{equation*}\n      \\mathcal{T}^+(\\check{\\mathcal{T}}(\\check{A}_i))\\jdeq A_i.\n    \\end{equation*}\n  \\item Given two finite lists\n    \\begin{align*}\n      \\Gamma_1 & \\vdash A_1~\\type & \\Delta_1 & \\vdash B_1~\\type \\\\\n      & ~\\vdots & & ~\\vdots \\\\\n      \\Gamma_n & \\vdash A_n~\\type & \\Delta_m & \\vdash B_m~\\type\n    \\end{align*}\n    of types in context, and two universes $\\mathcal{U}$ and $\\mathcal{V}$ that contain $A_1,\\ldots,A_n$ and $B_1,\\ldots,B_m$ respectively, there is a universe $\\UU\\sqcup\\mathcal{V}$ that contains the types of both $\\UU$ and $\\mathcal{V}$. The universe $\\UU\\sqcup\\mathcal{V}$ is specified by the finite list\n    \\begin{align*}\n      X:\\UU & \\vdash \\mathcal{T}_{\\mathcal{U}}(X)~\\type \\\\\n      Y:\\mathcal{V} & \\vdash \\mathcal{T}_{\\mathcal{V}}(Y) ~\\type.\n    \\end{align*}\n    With an argument similar to the previous construction of a universe, we see that the universe $\\UU\\sqcup\\mathcal{V}$ contains the types $A_1,\\ldots,A_n$ as well as the types $B_1,\\ldots,B_m$.\n\n    Note that we could also directly obtain a universe $\\mathcal{W}$ that contains the types $A_1,\\ldots,A_n$ and $B_1,\\ldots,B_m$. However, this universe might not contain all the types in $\\UU$ or all the types in $\\mathcal{V}$.\n  \\end{enumerate}\n  Since we don't postulate any relations between the universes, there are indeed very few of them. For example, the base universe $\\UU_0$ might contain many more types than it is postulated to contain. Nevertheless, there are some relations between the universes. For instance, there is a function $\\UU\\to\\UU^+$, since we can simply derive\n  \\begin{prooftree}\n    \\AxiomC{$X:\\UU\\vdash \\check{\\mathcal{T}}(X):\\UU^+$}\n    \\UnaryInfC{$\\vdash \\lam{X}\\check{\\mathcal{T}}(X) : \\UU\\to\\UU^+$}\n  \\end{prooftree}\n  Similarly, there are functions $\\UU\\to \\UU\\sqcup\\mathcal{V}$ and $\\mathcal{V}\\to \\UU\\sqcup\\mathcal{V}$ for any two universes $\\UU$ and $\\mathcal{V}$.\n\\end{rmk}\n\\index{enough universes|)}\n\\index{universe!enough universes|)}\n\n\\subsection{Pointed types}\n\n\\index{pointed type|(}\n\\begin{defn}\n  A \\define{pointed type} is a pair $(A,a)$ consisting of a type $A$ and a term $a:A$. The type of all pointed types in a universe $\\UU$ is defined to be\\index{UU*@{$\\UU_\\ast$}}\n  \\begin{equation*}\n    \\UU_\\ast \\defeq \\sm{X:\\UU}X.\n  \\end{equation*}\n\\end{defn}\n\n\\begin{defn}\n  Consider two pointed types $(A,a)$ and $(B,b)$. A \\define{pointed map}\\index{pointed map} from $(A,a)$ to $(B,b)$ is a pair $(f,p)$ consisting of a function $f:A\\to B$ and an identification $p:f(a)=b$. We write\n  \\begin{equation*}\n    A\\to_\\ast B \\defeq \\sm{f:A\\to B}f(a)=b\n  \\end{equation*}\n  for the type of all pointed maps from $(A,a)$ to $(B,b)$, leaving the base point implicit.\n\\end{defn}\n\nSince we have a type $\\UU_\\ast$ of \\emph{all} pointed types in a universe $\\UU$, we can start defining operations on $\\UU_\\ast$. An important example of such an operation is to take the loop space of a pointed type.\n\n\\begin{defn}\n  We define the \\define{loop space}\\index{loop space}\\index{Omega@{$\\Omega$}|see {loop space}} operation $\\Omega : \\UU_\\ast \\to \\UU_\\ast$\n  \\begin{equation*}\n    \\Omega(A,a)\\defeq \\big((a=a),\\refl{a}\\big).\n  \\end{equation*}\n\\end{defn}\n\nWe can even go further and define the \\emph{iterated loop space} of a pointed type. Note that this definition could not be given in type theory if we didn't have universes.\n\n\\begin{defn}\n  Given a pointed type $(A,a)$ and a natural number $n$, we define the $n$-th loop space $\\Omega^n(A,a)$ by induction on $n:\\N$, taking\\index{iterated loop space}\\index{Omega^n@{$\\Omega^n$}|see {iterated loop space}}\n  \\begin{align*}\n    \\Omega^0(A,a) & \\defeq (A,a) \\\\\n    \\Omega^{n+1}(A,a) & \\defeq \\Omega(\\Omega^n(A,a)).\n  \\end{align*}\n\\end{defn}\n\\index{pointed type|)}\n\n\\subsection{Families and relations on the natural numbers}\n\nAs we have already seen in the case of the iterated loop space, we can use the universe to define a type family over $\\N$ by induction on $\\N$. For example, we can define the finite types in this way.\n\n\\begin{defn}\\label{defn:fin}\nWe define the type family $\\Fin:\\N\\to\\UU$ of finite types\\index{Fin@{$\\Fin$}}\\index{finite types} by induction on $\\N$\\index{family!of finite types}, taking\n\\begin{align*}\n\\Fin(\\zeroN) & \\defeq \\emptyt \\\\\n\\Fin(\\succN(n)) & \\defeq \\Fin(n)+\\unit\n\\end{align*}\n\\end{defn}\n\nSimilarly, we can define many relations on the natural numbers using a universe. We give here the example of \\emph{observational equality} on $\\N$. This inductively defined equivalence relation is very important, as it can be used to show that equality on the natural numbers is \\emph{decidable}, i.e., there is a program that decides for any two natural numbers $m$ and $n$ whether they are equal or not.\n\n\\begin{defn}\\label{defn:obs_nat}\nWe define the \\define{observational equality}\\index{observational equality!on N@{on $\\N$}}\\index{natural numbers!observational equality} on $\\N$ as binary relation $\\EqN:\\N\\to(\\N\\to\\UU)$\\index{Eq N@{$\\EqN$}} satisfying\n\\begin{align*}\n\\EqN(\\zeroN,\\zeroN) & \\jdeq \\unit & \\EqN(\\succN(n),\\zeroN) & \\jdeq \\emptyt \\\\\n\\EqN(\\zeroN,\\succN(n)) & \\jdeq \\emptyt & \\EqN(\\succN(n),\\succN(m)) & \\jdeq \\EqN(n,m).\n\\end{align*}\n\\end{defn}\n\n\\begin{constr}\nWe define $\\EqN$ by double induction on $\\N$. By the first application of induction it suffices to provide\n\\begin{align*}\nE_0 & : \\N\\to\\UU \\\\\nE_S & : \\N\\to (\\N\\to\\UU)\\to(\\N\\to\\UU)\n\\end{align*}\nWe define $E_0$ by induction, taking $E_{00}\\defeq \\unit$ and $E_{0S}(n,X,m)\\defeq \\emptyt$. The resulting family $E_0$ satisfies\n\\begin{align*}\nE_0(\\zeroN) & \\jdeq \\unit \\\\\nE_0(\\succN(n)) & \\jdeq \\emptyt.\n\\end{align*} \nWe define $E_S$ by induction, taking $E_{S0}\\defeq \\emptyt$ and $E_{S0}(n,X,m)\\defeq X(m)$. The resulting family $E_S$ satisfies\n\\begin{align*}\nE_S(n,X,\\zeroN) & \\jdeq \\emptyt \\\\\nE_S(n,X,\\succN(m)) & \\jdeq X(m) \n\\end{align*}\nTherefore we have by the computation rule for the first induction that the judgmental equality\n\\begin{align*}\n\\EqN(\\zeroN,m) & \\jdeq E_0(m) \\\\\n\\EqN(\\succN(n),m) & \\jdeq E_S(n,\\EqN(n),m)\n\\end{align*}\nholds, from which the judgmental equalities in the statement of the definition follow.\n\\end{constr}\n\n\\begin{lem}\\label{ex:obs_nat_least}\\index{observational equality!on N@{on $\\N$}!is least reflexive relation}\n  Suppose $R:\\N\\to(\\N\\to\\UU)$ is a reflexive relation on $\\N$\\index{reflexive relation}\\index{relation!reflexive}, i.e., $R$ comes equipped with\n  \\begin{equation*}\n    \\rho : \\prd{n:\\N}R(n,n).\n  \\end{equation*}\n  Then there is a family of maps\n  \\begin{equation*}\n    \\prd{m,n:\\N}\\EqN(m,n)\\to R(m,n).\n  \\end{equation*}\n\\end{lem}\n\n\\begin{proof}\n  We will prove by induction on $m,n:\\N$ that there is a term of type\n  \\begin{equation*}\n    f_{m,n}:\\prd{e:\\EqN(m,n)}\\prd{R:\\N\\to(\\N\\to\\UU)}\\Big(\\prd{x:\\N}R(x,x)\\Big)\\to R(m,n)\n  \\end{equation*}\n  The dependent function $f_{m,n}$ is defined by\n  \\begin{align*}\n    f_{\\zeroN,\\zeroN} & \\defeq \\lam{\\ttt}\\lam{r}\\lam{\\rho}\\rho(\\zeroN) \\\\\n    f_{\\zeroN,\\succN(n)} & \\defeq \\indempty \\\\\n    f_{\\succN(m),\\zeroN} & \\defeq \\indempty \\\\\n    f_{\\succN(m),\\succN(n)} & \\defeq \\lam{e}\\lam{R}\\lam{\\rho}f_{m,n}(e,R',\\rho'),\n  \\end{align*}\n  where $R'$ and $\\rho'$ are given by\n  \\begin{align*}\n    R'(m,n) & \\defeq R(\\succN(m),\\succN(n)) \\\\\n    \\rho'(n) & \\defeq \\rho(\\succN(n)).\\qedhere\n  \\end{align*}\n\\end{proof}\n\nWe can also define observational equality for many other kinds of types, such as $\\bool$ or $\\Z$. In each of these cases, what sets the observational equality apart from other relations is that it is the \\emph{least} reflexive relation. \n\n\\begin{exercises}\n\\exercise \\label{ex:obs_nat_eqrel}Show that observational equality on $\\N$\\index{observational equality!on N@{on $\\N$}!is an equivalence relation} is an equivalence relation\\index{equivalence relation!observational equality on N@{observational equality on $\\N$}}, i.e., construct terms of the following types:\n  \\begin{align*}\n    & \\prd{n:\\N} \\EqN(n,n) \\\\\n    & \\prd{n,m:\\N} \\EqN(n,m)\\to \\EqN(m,n) \\\\\n    & \\prd{n,m,l:\\N} \\EqN(n,m)\\to (\\EqN(m,l)\\to \\EqN(n,l)).\n  \\end{align*}\n\\exercise \\index{observational equality!on N@{on $\\N$}!is preserved by functions}Show that every function $f:\\N\\to \\N$ preserves observational equality in the sense that\n  \\begin{equation*}\n    \\prd{n,m:\\N} \\EqN(n,m)\\to \\EqN(f(n),f(m)).\n  \\end{equation*}\n\\exercise \\label{ex:order_N}\n  \\begin{subexenum}\n  \\item Define the \\define{order relations}\\index{relation!order}\\index{order relation!leq on N@{$\\leq$ on $\\N$}}\\index{order relation!le on N@{$<$ on $\\N$}}\\index{leq@{$\\leq$}!on N@{on $\\N$}}\\index{le@{$<$}!on N@{on $\\N$}} $\\leq$ and $<$ on $\\N$.\n  \\item Show that $\\leq$ is reflexive\\index{reflexive!leq on N@{$\\leq$ on $\\N$}} and that $<$ is \\define{irreflexive}\\index{irreflexive}\\index{relation!irreflexive}, i.e., show that\n    \\begin{equation*}\n      (n\\leq n)\\qquad\\text{and}\\qquad (n\\nless n).\n    \\end{equation*}\n  \\item Show that $n\\leq\\succN(n)$ and $n<\\succN(n)$.\n  \\item Show that both $\\leq$ and $<$ are transitive.\n  \\item Show that $\\leq$ is \\define{antisymmetric}, i.e., show that $m=n$ whenever both $m\\leq n$ and $n\\leq m$ hold. Also show that if $m<n$, then $n\\nless m$.\n  \\item Show that\n    \\begin{equation*}\n      (m\\leq n)\\leftrightarrow (m=n)+(m<n)\n    \\end{equation*}\n    holds for all $m,n$.\n  \\item Show that\n    \\begin{equation*}\n      (m\\leq n)+(n<m)\n    \\end{equation*}\n    holds for all $m,n$.\n  \\item Show that $k\\leq \\min(m,n)$ holds if and only if both $k\\leq m$ and $k\\leq n$ hold, and show that $\\max(m,n)\\leq k$ holds if and only if both $m\\leq k$ and $n\\leq k$ hold.\n  \\end{subexenum}\n\\exercise \\label{ex:obs_bool}\\index{observational equality!on 2@{on $\\bool$}}\n  \\begin{subexenum}\n  \\item Define observational equality $\\EqBool$\\index{Eq 2@{$\\EqBool$}} on the booleans.\n  \\item Show that $\\EqBool$ is reflexive.\\index{observational equality!on 2@{on $\\bool$}!is reflexive}\n  \\item Show that for any reflexive relation $R:\\bool\\to(\\bool\\to \\UU)$ one has\\index{observational equality!on 2@{on $\\bool$}!is least reflexive relation}\n    \\begin{equation*}\n      \\prd{x,y:\\bool} \\EqBool(x,y)\\to R(x,y).\n    \\end{equation*}\n  \\end{subexenum}\n\\exercise \\label{ex:int_order}\n  \\begin{subexenum}\n  \\item Define the order relations\\index{relation!order}\\index{order relation} $\\leq$ and $<$ on and $\\Z$.\n  \\item Show that $\\leq$ is reflexive, transitive, and antisymmetric.\n  \\item Show that $<$ is irreflexive and transitive.\n  \\end{subexenum}\n\\begin{comment}\n\\item\n  \\begin{subexenum}\n  \\item For each $i:\\Fin(\\succN(n))$, define a function\n    \\begin{equation*}\n      \\skipFin_i : \\Fin(n)\\to\\Fin(\\succN(n))\n    \\end{equation*}\n    that includes $\\Fin(n)$ in $\\Fin(\\succN(n))$ by skipping $i$.\n  \\item For each $i:\\Fin(n)$, define a function\n    \\begin{equation*}\n      \\doubleFin_i : \\Fin(\\succN(n))\\to\\Fin(n)\n    \\end{equation*}\n    that projects $\\Fin(\\succN(n))$ onto $\\Fin(n)$ by doubling at $i$. \n  \\end{subexenum}\n\\end{comment}\n\\end{exercises}\n\\index{universe|)}\n\\index{universal family|)}\n\n", "meta": {"hexsha": "edc9810ee0193a670793ada70002d6b61be74635", "size": 21492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/universes-relations.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/universes-relations.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/universes-relations.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": 61.4057142857, "max_line_length": 732, "alphanum_fraction": 0.6860227061, "num_tokens": 6902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245617, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6311906402127515}}
{"text": "%\\chapter{Higher homotopy pushouts}\n\n\\section{$2$-spans and $2$-pushouts}\n\n\\section{Applications}\n\n\\begin{thm}\nThe join is an associative operation.\n\\end{thm}\n\n\\begin{thm}\nthe 3-by-3-lemma\n\\end{thm}\n\n\\begin{exercises}\n\\item In this exercise we study the \\define{reflexive coequalizer}. Let $R:A\\to A\\to\\UU$ be a relation, and $\\rho:\\prd{x:A}R(x,x)$ be a witness of reflexivity.  \n\\begin{subexenum}\n\\item Formulate the induction principle and computation rules for the higher inductive type $\\mathsf{rcoeq}(A,R,\\rho)$ with constructors\n\\begin{align*}\n\\pts{\\eta} &: A \\to \\mathsf{rcoeq}(A,R,\\rho) \\\\\n\\edg{\\eta} &: \\prd*{x,y:A} R(x,y)\\to \\id{\\pts{\\eta}(x)}{\\pts{\\eta}(y)} \\\\\n\\rfx{\\eta} &: \\prd{x:A} \\edg{\\eta}(\\rho(x))=\\refl{\\pts{\\eta}(x)}.\n\\end{align*}\n\\item Show that\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{x,y:A} R(x,y) \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & A \\arrow[d,\"\\pts{\\eta}\"] \\\\\nA \\arrow[r,swap,\"\\pts{\\eta}\"] & \\mathsf{rcoeq}(A,R,\\rho)\n\\end{tikzcd}\n\\end{equation*}\ncommutes, and is a pushout square.\n\\item Compute $\\mathsf{rcoeq}(A,\\idtypevar{A},\\refl{})$ and $\\mathsf{rcoeq}(A,(\\lam{x}{y}\\unit),(\\lam{x}\\ttt))$. Furthermore, consider a pointed type $\\pairr{X,x_0}$ as a reflexive relation on the unit type, and compute $\\mathsf{rcoeq}(\\unit,X,x_0)$.\n\\end{subexenum}\n\\end{exercises}\n", "meta": {"hexsha": "146bbca81ab708c400190a49101a7367784105da", "size": 1293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/higher_pushouts.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": 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/higher_pushouts.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": 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/higher_pushouts.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": 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": 36.9428571429, "max_line_length": 250, "alphanum_fraction": 0.6643464811, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6311898484083864}}
{"text": "\\chapter{Intuition for the Damping Terms in the Stiff String PDE}\\label{app:intuitionSigma1}\nThis appendix will delve deeper into the damping terms in the PDE of the stiff string presented in Chapter \\ref{ch:stiffString}, especially the frequency-dependent damping term $2\\sigma_1\\pt\\pxx u$. Recalling the compact version of the PDE of the stiff string in Eq. \\eqref{eq:stiffStringPDECompact}:\n\\begin{equation}\n    \\ptt u = c^2 \\pxx u - \\kappa^2 \\pxxxx u - 2 \\sz \\pt u + 2 \\so \\pt \\pxx u\n\\end{equation}\nConsider first the frequency-independent damping term $-2\\sz\\pt u$. The more positive the velocity $\\partial_tu$ is, i.e., the string is moving upwards the more this term applies a negative, or downwards force (/effect) on the string. Vice versa, a more negative velocity will make this term apply a more positive force on the string. \n\nAs for the frequency-dependent damping term, apart from the obvious $\\sigma_1$, the effect of the term increases with an increase of $\\partial_t\\partial_x^2u$ which literally describes the `rate of change of the curvature' of the string.\n\nLet's first talk about positive and negative curvature, i.e., when $\\partial_x^2u > 0$ or $\\partial_x^2u < 0$. Counterintuitively, in the positive case, the curve points downwards. Think about the function $f(x) = x^2$. It has a positive curvature (at any point), but has a minimum. This can be proven by taking $x=0$ and setting grid spacing $h=1$.\n\\begin{equation}\n  \\begin{aligned}\n  \\delta_{xx}f(x) &= \\frac{1}{h^2} \\left(f(-1)-2f(0)+f(1)\\right), \\\\\n  &= \\frac{1}{1^2} \\left((-1)^2-2\\cdot0^2+1^2\\right),\\\\\n  &= \\left(1-0+1\\right) = 2.\n  \\end{aligned}\n\\end{equation}\nIn other words, the second derivative of the function $f(x)=x^2$ around $x=0$ is positive.\n\nAs the term does not only include a second-order spatial derivative but also a first-order time derivative, this is referred to as a a positive or negative \\textit{rate of change} of the curvature, i.e., when $\\partial_t\\partial_x^2u>0$ or $\\partial_t\\partial_x^2u<0$. A positive rate of change of curvature means that the string either has a positive curvature and is getting more positive, i.e., the string gets more curved over time, or that the string has a negative curvature and is getting less negative, i.e., the string gets less curved or 'loosens up' over time.  In the same way, a negative rate of change of curvature means that the string either has a negative curvature and is getting more negative, or that the string has a positive curvature and is getting less positive. \n\nLet's see some examples. Take the same function described before, but now $f$ changes over time, fx. $f(x, t)=tx^2$. When $t$ increases over time, the curvature gets bigger. Repeating the above with $x=0$ and grid spacing $h = 1$, but now with $t=2$ and step size $k=1$, but now with a backwards time derivative yields:\n  \\begin{alignat*}{3}\n    \\delta_{t-}\\delta_{xx}f(x,t) &= \\frac{1}{kh^2}\\bigg(&&f(-1, 2) - 2f(0, 2) + f(1, 2) \\\\\n    & &&- \\Big(f(-1, 1) - 2f(0, 1) + f(1, 1)\\Big)\\bigg),\\\\\n    & = \\frac{1}{1\\cdot 1^2}\\bigg(&&2\\cdot(-1)^2-2\\cdot2\\cdot(0)^2+2\\cdot1^2\\\\\n    & &&-\\Big(1\\cdot(-1)^2-2\\cdot1\\cdot(0)+1\\cdot(1^2)\\Big)\\Bigg),\\\\\n    &=2+2-&&(1+1)=2.\n  \\end{alignat*}\nSo the rate of change of the curvature is positive, i.e., the already positively curved function $x^2$ gets more curved over time.\n\nIf the curvature around a point along a string gets more positive (or less negative) over time, the force applied to that point will be positive, effectively `trying' to reduce the curvature. Vice versa, if the curvature around a point along a string gets more negative (or less positive) over time, the force applied will be negative, again `trying' to reduce the curvature. \n\nFrom an auditory point of view, higher curvature generally means higher frequency. As the frequency-dependent damping term reduces curvature along the string it effectively damps higher frequencies.\n \n% The fact the frequency dependent term to be added rather than subtracted, is caused by the fact that a location along the string with a positive curvature implies that its neighbouring locations have relatively more positive displacement than itself. This translated to the force/effect this term has on the scheme means...\n", "meta": {"hexsha": "68a67fb5756770391fdd938e83aa9a59fb1a08aa", "size": 4245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/appendices/intuitionSigma.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/appendices/intuitionSigma.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/appendices/intuitionSigma.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": 114.7297297297, "max_line_length": 787, "alphanum_fraction": 0.7347467609, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110202, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.6311898369250253}}
{"text": "\n\\chapter{The Language}\n\n\\par The MalbolgeLISP implements a Lisp dialect which is described in this chapter. The main differences from Lisp is emphasis on functional programming, immutability and minimisation of the state (MalbolgeLISP doesn't implement \\verb|setcar!| or \\verb|setcdr!|). MalbolgeLISP borrows it's core features from Scheme, Haskell and APL, while using Lisp as a foundation or framework for constructing a language.\n\n\\section{Arithmetic}\n\n\\par MalbolgeLISP supports the following arithmetic operations:\n\n\\begin{itemize}\n    \\item \\verb|+|, \\verb|+'| - unsigned bounded addition\\footnote{obeying to the laws of modular arithmetic; the result is truncated to 26 bits} and unbounded addition\\footnote{on standards-compliant interpreters}\n    \\item \\verb|-|. \\verb|-'| - unsigned bounded subtraction and unbounded subtraction.\n    \\item \\verb|*|, \\verb|/|, \\verb|%| - unsigned bounded multiplication, division and modulus.\n    \\item \\verb|~| - boolean negation - $f(x) = 0$ for $x > 0$ and $f(x) = 1$ otherwise.\n    \\item \\verb|!| - factorial function - $f(x) = x!$ computed using a lookup table for $x \\leq 11$ and $f(x) = 0$ otherwise, since $!12$ exceeds the word size.\n    \\item \\verb|^| - $n$-th power function assuming $0^0=1$.\n    \\item \\verb|&| - logical AND function - $f(x, y) = 1$ for $x > 0 \\wedge y > 0$, $f(x, y) = 0$ otherwise.\n    \\item \\verb=|= - logical AND function - $f(x, y) = 0$ for $x = 0 \\wedge y = 0$, $f(x, y) = 1$ otherwise.\n    \\item \\verb|=|, \\verb|/=| - equality and inequality.\n    \\item \\verb|<|, \\verb|>|, \\verb|<=|, \\verb|>=| - correspondingly: lesser than, greater than, lesser or equal to, greater or equal to.\n    \\item \\verb|gcd|, \\verb|lcm| - greatest common divisor and least common multiple.\n    \\item \\verb|min|, \\verb|max| - pick the smaller or larger value (\\textit{minimum} or \\textit{maximum}).\n\\end{itemize}\n\n\\par Demonstration of the arithmetic functions follows:\n\n\\begin{verbatim}\n% (+ 2 1)\n..............|.....\n3\n% (* 3 3)\n..............|.....\n9\n% (% 5 2)\n..............|.....\n1\n% (> 5 6)\n..............|.....\n0\n% (< 5 6)\n..............|.....\n1\n% (= 6 6)\n..............|......\n1\n% (= (~ (= 6 7)) (/= 6 7))\n......................|.........\n1\n% (/ 25 5)\n..............|.....\n5\n% (- 4 3)\n..............|.....\n1\n% (& (= 2 2) (= 3 3))\n....................................|...............\n1\n% (| (= 2 3) (= 3 2))\n................|..........\n0\n% (lcm 14 29)\n......|....\n406\n% (max 5 (max 8 10))\n...........|.......\n10\n% (^ 2 8)\n......|....\n256\n% (! 6)\n.....|...\n720\n\\end{verbatim}\n\n\\section{Conditional execution}\n\n\\par In MalbolgeLISP, conditional evaluation is accomplished using \\verb|if| and \\verb|cond|\\footnote{also \\verb|iterate|, \\verb|iterateN|, etc..., but these functions weren't designed for conditional evaluation and it only happened so that they can be used for this purpose, so they won't be covered in this section.}. \\verb|&| and \\verb=|= don't short-circuit, meaning that their operands are always evaluated. \\verb|if| is very similar in it's structure to \\verb|if..else| statements\\footnote{or ternary operator expressions} known from languages like C++ or Java - \\verb|(if condition valueIfTrue valueIfFalse)|. The short-circuiting aspect of \\verb|if| can be demonstrated - If both cases of the \\verb|if| condition were evaluated, the interpreter would print \\verb|yes| and \\verb|no| before yielding the correct result:\n\n\\begin{verbatim}\n% (def noisy_eq (dyad (if (= x y) (print yes) (print no))))\n.............................|..\n(lambda (x y) (if (= x y) (print yes) (print no)))\n% (noisy_eq 5 6)\n......|............\nno\n\nno\n% (noisy_eq 6 6)\n......|............\nyes\n\nyes\n\\end{verbatim}\n\n\\par The \\verb|cond| function is essentially a chain of \\verb|if| expressions. To demonstrate the convenience of using \\verb|cond| over multiple \\verb|if| expressions, two implementations of three-way comparison are given:\n\n\\begin{verbatim}\n; An implementation that uses if.\n% (def <=> (dyad (\n    if (= x y) eq (\n        if (> x y) gt (\n            if (< x y) lt unreachable)))))\n...........................................|..\n(lambda (x y) (if (= x y) eq (if (> x y) gt (if (< x y) lt unreachable))))\n% (<=> 5 5)\n......|..........\neq\n% (<=> 6 7)\n......|....................\nlt\n% (<=> 7 6)\n......|...............\ngt\n\n; An implementation that uses cond.\n% (def <=> (dyad (cond\n    ((= x y) eq)\n    ((> x y) gt)\n    ((< x y) lt)\n    (unreachable))))\n...............................................|..\n(lambda (x y) (cond ((= x y) eq) ((> x y) gt) ((< x y) lt) (unreachable)))\n% (<=> 6 6)\n......|...........\neq\n% (<=> 6 7)\n......|...................\nlt\n% (<=> 7 6)\n......|...............\n\\end{verbatim}\n\n\\par It's worth mentioning that an \\verb|if| expression must include a truthy and falsy clause (since the expression must evaluate to something and it's impossible to guarantee that the condition is always true). This isn't the case with the \\verb|cond| expression. If one is certain that a \\verb|cond| expression is already exhaustive, it doesn't have to provide a default case. The interpreter will error if the \\verb|cond| expression isn't exhaustive and no default case was provided, though.\n\n\\section{Let bindings and the scope}\n\n\\par In MalbolgeLISP, there is a single way to bind variables without scope (via macros), and two ways of binding lexically scoped variables. Variables are usually bound using \\verb|lambda| and all the covers over it (\\verb|dyad|, \\verb|monad|, \\verb|defun|), but there is a way to bind variables without explicitly using a lambda expression - \\verb|let| bindings. \\verb|let| accepts a list of atoms to be bound interleaved with their values and the code to execute in the freshly created scope. The main difference from \\verb|let| present in other lisps is that the binding list is flattened:\n\n\\begin{verbatim}\n% (let (x 5 y 6) (print [x + y]))\n.....................|............\n11\n\n11\n\\end{verbatim}\n\n\\par When evaluated, \\verb|let| is desugared to a lambda expression with reversed parameters. The conversion schema follows:\n\n\\begin{verbatim}\n(let (x x0 y y0 z z0 ...) (...)) => ((lambda (z y x ...) (...)) z0 y0 x0 ...)\n\\end{verbatim}\n\n\\par The real parameter order is reversed, since the interpreter (for the sake of simplicity) iterates over the input list and uses \\verb|cons| to create the resulting desugared expression. Single-variable \\verb|let| bindings could illustratively also be implemented as a macro:\n\n\\begin{verbatim}\n% (defmacro let' (x y c) ((lambda (x) (eval c)) y)))\n............................|.\nmacro/syn\n% (let' x 5 (print x))\n...........|...........\n5\n\n5\n\\end{verbatim}\n\n\\par The current scope is bound to the lambda expression at the time of it's creation. Since lazily evaluated values utilise closures which are lexically scoped, this property applies to them as well. Consequently, everything inside the lazily evaluated expression has access to the lexical ancestor's bound variables. Generally speaking, the global scope can be modified using \\verb|def|, \\verb|defun| and \\verb|defmacro|, regardless of where these functions appear. Modifying the local scope is possible using only lambda expressions and the \\verb|let| function. It's discouraged to use \\verb|def|, \\verb|defun| and \\verb|defmacro| outside of the top-level code scope (i.e. inside lambda expressions, iterated callables, etc...), since it introduces global and mutable state.\n\n\\section{Lisp-style list processing}\n\n\\par MalbolgeLISP supports Lisp-style list processing (usually distinguished by extensive use of primitives mentioned below and recursion), even though the more sophisticated and concise Haskell and APL-like functionality is also supported.\n\n\\par \\verb|car| is used to query a list's head (\\verb|1∘↑|). It doesn't perform any copies and returns the atom the list's head points to. \\verb|car| of an empty list is \\textit{NULL}. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/x1.png}\n\\caption{The result of car invocation}\n\\end{figure}\n\n\\par \\verb|cdr| is used to query a list's tail (\\verb|1∘↓|), i.e. everything besides it's head, which is why it's sometimes called \\textit{beheading}. \\verb|cdr| of a single-element or empty list is \\textit{NULL}.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.3\\textwidth]{figures/x2.png}\n\\caption{The result of car invocation}\n\\end{figure}\n\n\\par \\verb|cons| is used to prepend a node (head and a tail) to a list. The tail of the newly created node with given head is set to the provided list. For instance, the list demonstrated in previous examples could be made using \\verb|(cons A (cons B null))|. A more concise version of this expression is \\verb|(tie A B)|. \\verb|tie| behaves like a chain of \\verb|cons| invocation, where the last invocation prepends to a \\textit{NULL} list. A parallel could be drawn between \\verb|cons & tie| and \\verb|if & cond|.\n\n\\section{Functional list processing}\n\n\\par In MalbolgeLISP, the preferred way to process data involves functional devices introduced with MalbolgeLISP v1.2. Most of them were borrowed from Haskell\\footnote{\\verb|intersperse|, \\verb|filter|, \\verb|zipwidth|, etc..} and APL\\footnote{to name a few: \\verb|where|, \\verb|take|, \\verb|drop|, \\verb|map|, \\verb|replicate|, \\verb|rev|}.\n\n\\subsection{iota}\n\n\\par The \\verb|iota| function exhibits the same behavior as it's C++ counterpart\\footnote{\\url{https://en.cppreference.com/w/cpp/algorithm/iota}}, although the concept of an index generator has been introduced by APL. \\verb|iota| assumes the index origin of 0, so it generates indices in range $[0, n)$. Unlike in APL, \\verb|iota| isn't ambivalent nor doesn't support taking a list as it's only argument:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (iota 5)\n.....|...\n(0 1 2 3 4)\n% (iota '(3 3))\n..........|...E030\n% (iota '(1 2 3) '(4 5 6))\n..................|..E029\n\n\n      ⍝ APL\n      ⎕io←0\n      ⍳ 3 3\n┌───┬───┬───┐\n│0 0│0 1│0 2│\n├───┼───┼───┤\n│1 0│1 1│1 2│\n├───┼───┼───┤\n│2 0│2 1│2 2│\n└───┴───┴───┘\n      ⍳ 5\n0 1 2 3 4\n      'ABCDEF'⍳'ACF'\n0 2 5\n\\end{verbatim}\n\n\\subsection{size}\n\n\\par The \\verb|size| functions yields the length of a list (in $O(n)$ time complexity). It traverses the list shallowly and doesn't account for it's depth. For instance, a very inefficient identity function on numbers could be implemented to demonstrate it's behavior:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (def f (atop size iota))\n...........|......\nbind/syn\n% (f 6)\n.....|.........\n6\n% (f 3)\n.....|.........\n3\n\n\n      ⍝ APL\n      f←≢⍳\n      f 6\n6\n      f 3\n3\n\\end{verbatim}\n\n\\subsection{n-th}\n\n\\par Picking arbitrary elements from a list is done using \\verb|nth|, or a constant $n$-th (the \\verb|#| prefix). For example, to pick $n$-th element from the end of a list, the following function might be used:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (def nl (dyad (nth [(size y) - [x + 1]] y)))\n.............................|..\n(lambda (x y) (nth (- (size y) (+ x 1)) y))\n% (nl '(1 2 3 4 5) 2)\n..............|................\n3\n\n\n      ⍝ APL\n      nl←⊃⌽\n      2 nl 1 2 3 4 5\n3\n\\end{verbatim}\n\n\\par \\textit{Constant n-th} is an alternative way to query the $n$-th (where $n$ is constant) element of a list. \\verb|#N| is equivalent to \\verb|(bind nth N)|. \\textit{constant n-th} is in many ways similar to a tack - it could even be implemented using a tack and \\verb|lift|. For instance:\n\n\\begin{verbatim}\n; Demonstration of constant n-th\n% (print ((atop #1 map) (bind lazy ~) '(0 1 1 1 1 0)))\n.............................|................................................\n0\n\n0\n\n; Correspondence between constant n-th and tack/lift:\n#N <=> (bind lift $N)\n\\end{verbatim}\n\n\\subsection{map}\n\n\\par \\verb|map| is an ubiquitous higher-order function originating from functional languages present in C++\\footnote{\\url{https://en.cppreference.com/w/cpp/algorithm/transform}}, APL\\footnote{\\url{https://help.dyalog.com/latest/index.htm#Language/Primitive\\%20Operators/Each\\%20with\\%20Monadic\\%20Operand.htm}} or Java\\footnote{\\url{https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#map-java.util.function.Function-}}. \\verb|map| is reponsible for transforming (\\textit{mapping}) one list into another of equal length, by calling a functor on every element of the original list. It takes any callable first argument, and a list second argument. For example:\n\n\\begin{verbatim}\n% (map (bind selfie *) (iota 6))\n...............|..........................................................\n(0 1 4 9 16 25)\n% (map ~ '(1 0))\n...........|..........\n(0 1)\n% (map ~ null)\n......|....\nnull\n\\end{verbatim}\n\n\\subsection{filter}\n\n\\par \\verb|filter| is a higher order function that conditionally removes elements of a list. First, the list is mapped, and then the elements that correspond to falsy values in the list obtained by mapping are removed, and truthy values are kept. \\par \\verb|filter| behaves in the same way as \\verb|map| when the second argument is \\textit{NULL}. To demonstrate:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (filter (bind' % 2) (iota 10))\n...............|......................................................\n(1 3 5 7 9)\n% (filter (bind' % 2) null)\n...........|..\nnull\n\n\n      ⍝ APL\n      filter←{⍵/⍨⍺⍺¨⍵}\n      2∘| filter ⍳10\n┌→────────┐\n│1 3 5 7 9│\n└~────────┘\n      2∘| filter ⍬\n┌⊖┐\n│0│\n└~┘\n\\end{verbatim}\n\n\\subsection{rev}\n\n\\par \\verb|rev| is an ambivalent built-in function inspired by APL's \\textit{reverse/rotate}\\footnote{\\url{https://aplwiki.com/wiki/Reverse} and \\url{https://aplwiki.com/wiki/Rotate}}. The monadic case simply reverses a list, while the dyadic case rotates it. Since MalbolgeLISP doesn't support rotation with a negative argument, but the dyadic rotation with negative parameter can be defined in an alternative way.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (rev (iota 5))\n.........|.....\n(4 3 2 1 0)\n% (rev 3 (iota 6))\n..........|......\n(3 4 5 0 1 2)\n% (def rev' (dyad (rev [(size y) - x] y)))\n........................|..\n(lambda (x y) (rev (- (size y) x) y))\n% (rev' 2 (iota 6))\n..........|...............\n(4 5 0 1 2 3)\n\n\n      ⍝ APL\n      ⌽⍳5\n┌→────────┐\n│4 3 2 1 0│\n└~────────┘\n      3⌽⍳6\n┌→──────────┐\n│3 4 5 0 1 2│\n└~──────────┘\n      ¯2⌽⍳6\n┌→──────────┐\n│4 5 0 1 2 3│\n└~──────────┘\n\\end{verbatim}\n\n\\subsection{any, every}\n\n\\par \\verb|any| and \\verb|every| are closely tied to each other. \\verb|any| returns \\verb|1| if its functor returned a truthy value for \\textbf{any} element (and \\verb|0| otherwise), and \\verb|every| returns \\verb|1| if its functor returned a truthy value for \\textbf{every} element (and \\verb|0| otherwise). \\verb|any| and \\verb|every| short-circuit (otherwise, they would be easy to implement using \\verb|filter|). To demonstrate:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (every (bind = 2) '(2 2 2 2))\n..................|................................\n1\n% (any (bind = 2) '(2 2 2 2))\n..................|................................\n1\n% (every (bind = 3) '(3 3 2))\n.................|..............\n0\n% (any (bind = 3) '(0 1 2))\n.................|..............\n0\n\n\n      ⍝ APL\n      ⍝ Note: This implementation doesn't short-circuit\n      any←{∨/⍺⍺¨⍵}\n      every←{∧/⍺⍺¨⍵}\n      2∘= every 2 2 2\n1\n      2∘= any 1 2 3\n1\n      3∘= every 3 3 2\n0\n      3∘= any 1 2 2\n0\n\\end{verbatim}\n\n\\subsection{zip, zipwith}\n\n\\par \\verb|zip| juxtaposes elements from two lists to form a list of pairs of corresponding elements from them. The pairs can be further processed to produce a flat result if \\verb|zipwith| is used. \\verb|zip| and \\verb|zipwith| will return a list of size \\verb|⌊⍥≢|\\footnote{when end of list is encountered when the pairs are formed, the operation finishes}.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% [zip selfie (iota 3)]\n..........|..........\n((0 0) (1 1) (2 2))\n% [+ zipwith (iota 3) (iota 3)]\n...............|.....................\n(0 2 4)\n\n\n      ⍝ APL\n      zip←,¨\n      zipwith←{⍺⍺/¨⍺,¨⍵}\n      zip⍨ ⍳3\n┌→──────────────────┐\n│ ┌→──┐ ┌→──┐ ┌→──┐ │\n│ │0 0│ │1 1│ │2 2│ │\n│ └~──┘ └~──┘ └~──┘ │\n└∊──────────────────┘\n      (⍳ 3) (+ zipwith) (⍳ 3)\n┌→────┐\n│0 2 4│\n└~────┘\n\\end{verbatim}\n\n\\subsection{flatten, flatmap}\n\n\\par \\verb|flatten| and \\verb|flatmap|'s mutual relations somewhat resemble \\verb|zip| and \\verb|zipwith|. While the first operation is a function that simply flattens a list, the second function is a \\verb|map| which result is flattened afterwards. List flattening isn't deep:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (flatten '((1 2) (3 4)))\n..................|...\n(1 2 3 4)\n% (flatten '(((1 2) (3 4)) (3 4)))\n..........................|...\n((1 2) (3 4) 3 4)\n; Simple deep flattening\n% (def deepf (bind iterate = flatten))\n............|........\nbind/syn\n% (deepf '(((1 2) (3 4)) (3 4)))\n..........................|............................\n(1 2 3 4 3 4)\n; Successor and predecessor of a number\n% (def sp (monad (tie [x + 1] [x - 1])))\n.........................|..\n(lambda (x) (tie (+ x 1) (- x 1)))\n% (flatmap sp '(1 2 3 4))\n.............|........................................................\n(2 0 3 1 4 2 5 3)\n; As opposed to...\n% (map sp '(1 2 3 4))\n.............|........................................................\n((2 0) (3 1) (4 2) (5 3))\n\n      ⍝ APL\n      f←⊃,/\n      f ((1 2) (3 4))\n1 2 3 4\n      f (((1 2) (3 4)) (3 4))\n┌───┬───┬─┬─┐\n│1 2│3 4│3│4│\n└───┴───┴─┴─┘\n      ⍝ two choices for deep flattening\n      ⍝ MalbolgeLISP port:\n      g←f⍣≡\n      ⍝ Idiomatic APL:\n      h←∊\n      g (((1 2) (3 4)) (3 4))\n1 2 3 4 3 4\n      h (((1 2) (3 4)) (3 4))\n1 2 3 4 3 4\n      sp←(+,-)∘1\n      fm←{⊃,/⍺⍺¨⍵}\n      sp fm 1 2 3 4\n2 0 3 1 4 2 5 3\n      sp¨ 1 2 3 4\n┌───┬───┬───┬───┐\n│2 0│3 1│4 2│5 3│\n└───┴───┴───┴───┘\n\\end{verbatim}\n\nIllustratively, flattening a list alters it in the following way:\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/beforeFlatten.png}\n\\caption{A list before flattening}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/afterFlattening.png}\n\\caption{A list after flattening}\n\\end{figure}\n\n\\subsection{folds}\n\n\\par Folding is a way to transform an entire list by putting a binary operation between each element of it. Since folding must yield a result, and the list might be empty, \\verb|fold| takes an additional argument which specifies the identity element, which semantically means that the value is left unchanged\\footnote{for instance, the identity element of $+$ is \\verb|0|, since $x + 0 = x$ and the identity element of $\\times$ is \\verb|1|, since $x \\times 1 = x$}. Since APL supports only reductions, the comparison between MalbolgeLISP and APL is not demonstrated in this example.\n\n\\begin{verbatim}\n% (fold 0 + '(1 2 3 4 5))\n...............|.........................\n15\n% [[[[[0 + 1] + 2] + 3] + 4] + 5]\n..........................|................\n15\n% (fold 0 + null)\n.......|.....\n0\n\\end{verbatim}\n\n\\par If it is known that the list contains at least one element, \\verb|fold'| can be used, which is equivalent to APL's reductions:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (fold' + '(1 2 3 4 5))\n...............|.........................\n15\n\n\n      ⍝ APL\n      +/ 1 2 3 4 5\n15\n\\end{verbatim}\n\n\\subsection{where}\n\n\\par \\verb|where| is a function borrowed from APL - \\verb|⍸|\\footnote{\\url{http://help.dyalog.com/16.0/Content/Language/Primitive\\%20Functions/Where.htm}}. It returns the indices on which the input array contains truthy values. If the truthy value is greater than one, it's repeated that amount of times. For example:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (where '(1 0 1 0 1 1 1 0))\n................|...\n(0 2 4 5 6)\n% (where '(1 2 3 4))\n............|...\n(0 1 1 2 2 2 3 3 3 3)\n\n\n      ⍝ APL\n      ⍸1 0 1 0 1 1 1 0\n0 2 4 5 6\n      ⍸1 2 3 4\n0 1 1 2 2 2 3 3 3 3\n\\end{verbatim}\n\n\\subsection{count}\n\n\\par \\verb|count| counts the amount of times it's functor returned a truthy value for each element of a list. It can be trivially expressed as a \\verb|fold| and \\verb|map|. An example of \\verb|count| usage follows.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (count (bind = 2) '(2 2 3 2 2 3))\n....................|............................................\n4\n% (def count' (dyad (fold 0 + (map [[< bind 0] atop x] y))))\n...............................|..\n(lambda (x y) (fold 0 + (map (atop (bind < 0) x) y)))\n% (count' (bind = 2) '(2 3 2 3))\n..................|..............................................\n..........................................................\n2\n\n\n      ⍝ APL\n      count←{+/(0<⍺⍺)¨⍵}\n      2∘= count 2 3 2 3 2 2\n4\n\\end{verbatim}\n\n\\subsection{replicate}\n\n\\par \\verb|replicate| is one of the most overloaded functions in MalbolgeLISP. It takes three different forms depending on the argument types:\n\\begin{itemize}\n    \\item \\verb|replicate list list| - copy elements from list 2 according to the masks in list 1. comparable to \\verb|filter|\\footnote{a filter-like function is implemented in APL using replicate}, but it takes a pre-mapped array instead of a functor.\n    \\item \\verb|replicate num list| - duplicate the list specified amount of times\n    \\item \\verb|replicate num any| - make a list out of any atom repeated specified amount of times\n\\end{itemize}\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (replicate 5 hello)\n......|....\n(hello hello hello hello hello)\n% (replicate 5 '(1 2))\n...........|....\n(1 2 1 2 1 2 1 2 1 2)\n% (replicate '(1 0 2) '(1 2 3))\n..................|....\n(1 3 3)\n\n\n      ⍝ APL\n      replicate1←⍴∘⊂\n      5 replicate1 'hello'\n┌─────┬─────┬─────┬─────┬─────┐\n│hello│hello│hello│hello│hello│\n└─────┴─────┴─────┴─────┴─────┘\n      replicate2←{↑,/⍺⍴⊂⍵}\n      5 replicate2 1 2\n1 2 1 2 1 2 1 2 1 2\n      1 0 2/1 2 3\n1 3 3\n\\end{verbatim}\n\n\\subsection{scan}\n\n\\par \\verb|scan| performs a \\verb|fold| with partial results. The standard behavior diverges from APL (since the identity element is excluded), but it can be accomplished using \\verb|scan'|, which assumes that the input list has at least a single element.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (scan' * '(1 2 3 4 5))\n..............|....................\n(1 2 6 24 120)\n% (scan * 1 '(1 2 3 4 5))\n..............|........................\n(1 1 2 6 24 120)\n\n\n      ⍝ APL\n      ×\\1 2 3 4 5\n1 2 6 24 120\n\\end{verbatim}\n\n\\subsection{uniq}\n\n\\par \\verb|uniq| returns unique elements of a list using the \\textit{formal definition of equality}. It uses an algorithm which makes $O(n^2)$ equality checks in the pessimistic case. To demonstrate:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (uniq '(1 6 2 5 2 6 2 3))\n................|...\n(1 6 2 5 3)\n% (uniq '((1 2) (1 2) (1 2 3) (4 5) 6 (4 5)))\n...................................|...\n((1 2) (1 2 3) (4 5) 6)\n\n      ⍝ APL\n      ∪ 1 6 2 5 2 5 6 2 3\n1 6 2 5 3\n      ∪ ((1 2) (1 2) (1 2 3) (4 5) 6 (4 5))\n┌───┬─────┬───┬─┐\n│1 2│1 2 3│4 5│6│\n└───┴─────┴───┴─┘\n\\end{verbatim}\n\n\\subsection{sort}\n\n\\par \\verb|sort| is a function that sorts a list with an arbitrary comparator (or assumes a default comparator for sorting numeric lists, if none was provided). MalbolgeLISP utilises the insertion sort algorithm\\footnote{because of it's simplicity and performance on small lists, which are going to realistically be the main use case for it in MalbolgeLISP}. It has a time complexity of $O(n^2)$ and auxiliary space requirement of $O(1)$. It takes maximum time to sort a list if elements are sorted in reverse order, and it takes minimum time when the elements are already sorted. For example:\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (sort '(1 9 5 8 2 3 9 5))\n................|...\n(1 2 3 5 5 8 9 9)\n% (sort '(1 9 5 8 2 3 9 5))\n................|...\n(1 2 3 5 5 8 9 9)\n% (sort > '(1 9 5 8 2 3 9 5))\n.................|......................................\n........................................................\n......................\n(1 2 3 5 5 8 9 9)\n\n\n      ⍝ APL\n      ⍝ Implementation of an insertion sort.\n      sortn←((≥⊢⍤/⊢),⊣,<⊢⍤/⊢)/\n      sortn 32 4 1 34 95 3 2 120 ¯38\n┌────────────────────────┐\n│¯38 1 2 3 4 32 34 95 120│\n└────────────────────────┘\n      ⍝ A more idiomatic way of solving the problem:\n      sortn1←{⍵[⍋⍵]}\n      sortn1 32 4 1 34 95 3 2 120 ¯38\n¯38 1 2 3 4 32 34 95 120\n      ⍝ Sorting with a comparator\n      sortc←{p←⍺⍺⋄{r←/∘⍵⋄c←⍺p⍵⋄(r c),⍺,r ~c}/⍵}\n      > sortc 32 4 1 34 95 3 2 120 ¯38\n┌────────────────────────┐\n│¯38 1 2 3 4 32 34 95 120│\n└────────────────────────┘\n\\end{verbatim}\n\n\\subsection{take, take', drop, drop'}\n\n\\par \\verb|take| and \\verb|take'| extract $n$ elements from the front (\\verb|take|) or from the back (\\verb|take'|) of a list. They correspond to \\verb|↑| and \\verb|((-⊣)↑⊢)| in APL. \\verb|take| triggers a copy, while \\verb|take'| doesn't:\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/take.png}\n\\caption{Taking the first three elements from a list}\n\\end{figure}\n\n\\par The list must be cloned, since setting the tail of the list node which holds \\verb|C| to \\textit{NULL} (to yield a new list) would invalidate existing references. This doesn't apply to \\verb|take'|, since it doesn't have to modify the memory it's operating on.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (take 3 '(1 2 3 4 5))\n..............|....\n(1 2 3)\n% (take' 3 '(1 2 3 4 5))\n..............|....\n(3 4 5)\n\n\n      ⍝ APL\n      3↑1 2 3 4 5\n1 2 3\n      ¯3↑1 2 3 4 5\n3 4 5\n\\end{verbatim}\n\n\\par \\verb|drop| and \\verb|drop'| exhibit the same behavior. They drop $n$ elements from the front (\\verb|drop|) or the back (\\verb|drop'|) of a list. Dropping elements from the back requires a copy, while dropping them from the front does, for the reasons outlined above.\n\n\\begin{verbatim}\n; MalbolgeLISP\n% (drop 3 '(1 2 3 4 5))\n..............|....\n(4 5)\n% (drop' 3 '(1 2 3 4 5))\n..............|....\n(1 2)\n\n\n      ⍝ APL\n      3↓1 2 3 4 5\n4 5\n      ¯3↓1 2 3 4 5\n1 2\n\\end{verbatim}\n\n\\section{Iteration and recursion}\n\n\\par This section is intended to demonstrate various implementations of the Fibonacci series in MalbolgeLISP\\footnote{in comparison to APL} using iteration and recursion. Then, the approaches will be judged by cleaniness, conciseness and performance.\n\n\\par The naive, doubly recursive attempt timed at 1m 19s follows:\n\n\\begin{minted}{lisp}\n(defun fib1 (n) (\n    if [n < 2]\n        n\n        [(fib1 [n - 1]) + (fib1 [n - 2])]))\n(fib1 6) ; => 8\n; APL: {1≥⍵:⍵ ⋄ (∇⍵-2)+∇⍵-1} 6\n\\end{minted}\n\n\\par A singly-recursive attempt which keeps track of the accumulator tuple. There exist two versions of it - a port of the APL solution and the idiomatic MalbolgeLISP attempt, which is much faster than the port, since it takes advantage of MalbolgeLISP's support of functions of arity 3 or higher.\n\n\\begin{minted}{lisp}\n; APL version: {⍺←0 1 ⋄ 0=⍵:⊃⍺ ⋄ (1↓⍺,+/⍺)∇⍵-1} 6\n; Direct port at 1m 6s:\n(defun fib2 (n) ((lambda (a w) (\n    if [w = 0]\n        (#0 a)\n        ((bruijn 0) (tie (#1 a) (lift + a)) [w - 1]))) '(0 1) n))\n; A more idiomatic solution at 54s:\n(defun fib2 (n) ((lambda (x y w) (\n    if [w = 0]\n        x\n        ((bruijn 0) y [x + y] [w - 1]))) 0 1 n))\n\\end{minted}\n\n\\par An iterative attempt timed at 43s:\n\n\\begin{minted}{lisp}\n; APL version: {⊃+\\∘⌽⍣⍵⍳2} 6\n(defun fib3 (n) (#0 (\n    iterateN n (lambda (x) (\n        tie (#1 x) [(#0 x) + (#1 x)])) '(0 1))))\n\\end{minted}\n\n\\par It should be noted that even though the second approach is generally faster, it's not as clean as the first or third one. The first approach is the slowest, while the second and third approaches are faster. Generally, the most concise, clean and the fastest attempt is the iterative attempt.\n", "meta": {"hexsha": "efbfa2327d8e7b94674f51578aab9fb92922c273", "size": 27231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual-src/content/chapter3.tex", "max_stars_repo_name": "kspalaiologos/malbolge-lisp", "max_stars_repo_head_hexsha": "c00a078b2c6dc4b3a46309f6839c9ade1d16466c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 261, "max_stars_repo_stars_event_min_datetime": "2020-10-01T11:00:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T14:40:55.000Z", "max_issues_repo_path": "manual-src/content/chapter3.tex", "max_issues_repo_name": "kspalaiologos/malbolge-lisp", "max_issues_repo_head_hexsha": "c00a078b2c6dc4b3a46309f6839c9ade1d16466c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-10-01T11:03:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-06T09:46:16.000Z", "max_forks_repo_path": "manual-src/content/chapter3.tex", "max_forks_repo_name": "kspalaiologos/malbolge-lisp", "max_forks_repo_head_hexsha": "c00a078b2c6dc4b3a46309f6839c9ade1d16466c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-01-15T09:25:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T23:18:56.000Z", "avg_line_length": 35.1821705426, "max_line_length": 825, "alphanum_fraction": 0.59281701, "num_tokens": 9228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6311898354793135}}
{"text": " \n\n\\documentclass[12pt]{article}\n\\usepackage{times}\n\\usepackage{indentfirst}\n\\usepackage{graphicx}\n\\usepackage{multirow}\n\\usepackage{float}\n\\usepackage{amsmath}\n\\graphicspath{ {./img/} }\n%Setup the layout of the pages\n\\topmargin 0.0cm\n\\oddsidemargin 0.2cm\n\\textwidth 16cm \n\\textheight 21cm\n\\footskip 1.0cm\n\n\n\\title{\n    Data Science\\\\\n}\n\\author{Molin Liu}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Introduction}\n\nThis is a review work for the Data Science course in\n\\textit{Univeristy of Glasgow}.\n\n\\section{Linear Algebra}\n\n\\subsection{Vector}\nVectors can be composed (via addition),\ncompared (via norms/inner products)\nand weighted (by scaling).\n\n\\subsubsection{Basic Vector Operations}\n(Ommited)\n\\subsubsection{Inner Product}\n$$\\cos \\theta=\\frac{\\mathbf{x} \\bullet \\mathbf{y}}{\\|\\mathbf{x}\\|\\|\\mathbf{y}\\|}$$\n - The inner product of two orthogonal vectors is 0;\n\n\\subsubsection{Norm}\n\n- Norm 0: Count of non-zero values;\n\n- Norm 1: Sum of absolute values;\n\n- Norm 2: Euclidean distance;   \n\n\\subsubsection{High Dimensional Vector Space}\n\n\\subsection{Matrix}\n\n\\subsubsection{Operations}\n(Ommited)\n\n\\subsubsection{Anatomy of Matrix}\n\n\\subsection{Polynomial Regression}\n\nThe \\textbf{Polynomial Regression} can be written as:\n$$\nt=w_{0}+w_{1} x+w_{2} x^{2}+w_{3} x^{2}+\\ldots+w_{K} x^{K}=\\sum_{k=0}^{\\kappa} w_{k} x^{k}\n$$\n\nDefine the loss funcion:\n$$\n\\mathcal{L}=\\frac{1}{N}(\\mathbf{t}-\\mathbf{X} \\mathbf{w})^{\\top}(\\mathbf{t}-\\mathbf{X} \\mathbf{w})\n$$\n\\subsubsection{Generalization \\& Overfitting}\n\nWe can find out that the \\textbf{loss} will always decrease\nas the model is made more complex.\n\nHow to choose the right model complexity?\n\\textbf{Cross-validation}\n\n\\subsubsection{Cross-Validation}\n\n\\section{Classification}\n\nThe \\textbf{Classification} task is to classify\na set of \\textit{N} objects $x_i$ with attributes.\nEach object has an associated label $t_i$\n\n\\textbf{Probabilistic classifier} produce a probability of class membership:\n\n$P(t_{\\text {new}}=k | \\mathbf{x}_{\\text {new }}, \\mathbf{X}, \\mathbf{t})$\n\n\\textbf{non-Probabilistic classifier} produce a hard assignment:\n\n$t_{new}=1$ or $t_{new}=0$\n\n\\subsection{KNN}\n\nK-Nearest Neighbours(KNN)\n\n- Non-probabilistic classifier;\n\n- Supervised trainning;\n\n- Fast;\n\n- We can use CV to find the right $K$;\n\n\\subsubsection{Problem}\n- As $K$ increases, the small classes will disppear.\n\n\\subsection{Logistic Regression}\n\n\\subsection{SVM}\n\\subsubsection{Hard Margin}\nIf the training data is linearly seperable,\nwe can select two parallel hyperplanes that separate the two classes of data,\nso that the distance between them is as large as possible.\n\nThese hyperplanes can be described by the equations:\n$$\n\\vec{w} \\cdot \\vec{x}_{i}-b \\geq 1, \\text { if } y_{i}=1\n$$\nor\n$$\n\\vec{w} \\cdot \\vec{x}_{i}-b \\leq-1, \\text { if } y_{i}=-1\n$$\n\nWe can easily infer that \n$$\ny_{i}\\left(\\vec{w} \\cdot \\vec{x}_{i}-b\\right) \\geq 1, \\quad \\text { for all } 1 \\leq i \\leq n\n$$\n\nWe want to maximise $\\gamma=\\frac{1}{\\|\\mathbf{w}\\|}$,\nequivalent to minimising $\\|\\mathbf{w}\\|$\n\nNote: $y_i$ is the label in the data, which is in $\\{-1, 1\\}$,\nrather than vertical axis value of the data.\n\\subsubsection{Soft Margin}\nSoft-margin function for the data are not linearly seperable.\n\n\\subsubsection{Inner Product}\n\n\\section{ROC}\nSensitivity/Recall\n\n$$\nS_{e}=\\frac{T P}{T P+F N}\n$$\n\nSpecificity\n\n$$\nS_{p}=\\frac{T N}{T N+F P}\n$$\n\n\\section{Unsupervised Learning}\n\\subsection{K-Means}\n\n\\subsection{Gaussion Mixture Model}\n\\end{document}\n\n", "meta": {"hexsha": "ee99889b1a54f74d6a9aed3d86b04c811f75a4df", "size": 3463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Data Science/Review.tex", "max_stars_repo_name": "Molin-L/UoG_DataScience", "max_stars_repo_head_hexsha": "819bce5f9f4ab107f1844bea63c57ddaee9e89da", "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": "Data Science/Review.tex", "max_issues_repo_name": "Molin-L/UoG_DataScience", "max_issues_repo_head_hexsha": "819bce5f9f4ab107f1844bea63c57ddaee9e89da", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-03T17:07:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-03T17:07:30.000Z", "max_forks_repo_path": "Data Science/Review.tex", "max_forks_repo_name": "Molin-L/UoG_DataScience", "max_forks_repo_head_hexsha": "819bce5f9f4ab107f1844bea63c57ddaee9e89da", "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": 21.1158536585, "max_line_length": 98, "alphanum_fraction": 0.7146982385, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.6311810424396849}}
{"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{gensymb}\n \n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\n\\newcommand{\\nspace}{\\vspace*{.5cm}}\n\\newcommand{\\nline}{\\nspace \\noindent}\n\n\\newcommand{\\expected}[1]{\\text{E}(#1)}\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 % 7.2 3.b, 13, 14, 21\n \n\\begin{document}\n\\title{Math 487 Homework 6}\n\\author{Jacob Shiohira}\n\\maketitle\n\n\\subsection*{Section 7.2}\n\\noindent\n\\textbf{Ch 7.2 Q3} Suppose again that $Z = X + Y$ . Find $f_Z$ if\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item \n\n\\[ f_X(x) = f_Y(x) = \\begin{cases} \n      \\frac{x}{2} & \\text{ if } 0 < x < 2, \\\\\n      0 & \\text{ otherwise}.\n      \\end{cases} \\]\n\n\\noindent\nGiven $Z = X + Y$, $0 < X < 2$, and $0 < Y < 2$, we know that $f_Z$ will take on the following,\n\n\\begin{equation*}\n\\int_{- \\infty}^{\\infty} f_X(z-y) f_Y(y) dy \\enspace \\text{ or } \\enspace \\int_{- \\infty}^{\\infty} f_Y(z-x) f_X(x) dx.\n\\end{equation*}\n\n\\noindent\nWe will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $y < z < 2+y$ and $z-2 < y < z$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $0 < z < 2$ and $2 < z < 4$. So, we will go ahead and calculate those,\n\n\\begin{align*}\nf_Z(x) &= \\int_{0}^{z} \\frac{z-2}{2} - \\frac{y}{2} \\text{ } dy = \\int_{0}^{z} \\frac{zy}{4} - \\frac{y^2}{4} \\text{ } dy = \\Bigg [ \\frac{zy^2}{8} - \\frac{y^3}{12} \\Bigg ]_{0}^{z} = \\frac{z^3}{8} - \\frac{z^3}{12} = \\frac{z^3}{24},\n\\end{align*}\n\n\\begin{align*}\nf_Z(x) &= \\int_{z-2}^{2} \\frac{z-2}{2} - \\frac{y}{2} \\text{ } dy \\\\\n&= \\int_{z-2}^{2} \\frac{zy}{4} - \\frac{y^2}{4} \\text{ } dy \\\\\n&= \\Bigg [ \\frac{zy^2}{8} - \\frac{y^3}{12} \\Bigg ]_{z-2}^{2} \\\\\n&= \\frac{4}{8}z - \\frac{8}{12} - \\Big [ \\frac{z(z-2)^2}{8} - \\frac{(z-2)^3}{12} \\Big ] \\\\\n&= \\frac{4}{8}z - \\frac{8}{12} - \\Big [ \\frac{z^3 - 4z^2 + 4z}{8} - \\frac{z^3-6z^2+12z-8}{12} \\Big ] \\\\\n&= \\frac{4}{8}z - \\frac{8}{12} - \\frac{3z^3 - 12z^2 + 12z - 2z^3 +12z^2 - 24z + 16}{24} \\\\\n&= z - \\frac{z^3}{24} - \\frac{4}{3}.\n\\end{align*}\n\n\\noindent\nThus, \n\n\\[ f_Z(x) = \\begin{cases} \n      \\frac{x^3}{24} & \\text{ if } 0 \\leq x \\leq 2, \\\\\n      x - \\frac{x^3}{24} - \\frac{4}{3} & \\text{ if } 2 \\leq z \\leq 4.\n      \\end{cases} \\]\n\n\\item \n\\[ f_X(x) = f_Y(x) = \\begin{cases} \n     \\frac{1}{2}(x-3) & \\text{ if } 3 < x < 5, \\\\\n      0 & \\text{ otherwise}.\n      \\end{cases} \\]\n\n% TODO: 3.b\nGiven $Z = X + Y$, $3 < X, Y < 5$, we know that $f_Z$ will take on the following,\n\n\\begin{equation*}\n\\int_{- \\infty}^{\\infty} f_X(z-y) f_Y(y) dy \\enspace \\text{ or } \\enspace \\int_{- \\infty}^{\\infty} f_Y(z-x) f_X(x) dx.\n\\end{equation*}\n\n\\noindent\nWe will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $3 + y < z < 5+y$ and $z-5 < y < z-3$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $6 < z < 8$ and $6 < z < 8$. So, we will go ahead and calculate those,\n\n\\begin{align*}\nf_Z(x) &= \\int_{3}^{z-3} \\dfrac{y^2+z\\left(3-y\\right)-9}{4} \\text{ } dy \\\\\n&= \\frac{1}{4} \\Bigg [ \\dfrac{y^3}{3}-\\dfrac{zy^2}{2}+\\left(3z - 9 \\right)y \\Bigg ]_{3}^{z-3} \\\\\n&= - \\frac{z^3-18z^2+81z-108}{24}-\\frac{9z-36}{8} \\\\\n&= \\dfrac{z^3-18z^2+108z-216}{24}\n\\end{align*}\n\n\\begin{align*}\nf_Z(x) &= \\int_{z-5}^{5} \\dfrac{y^2+z\\left(3-y\\right)-9}{4} \\text{ } dy \\\\\n&= \\frac{1}{4} \\Bigg [ \\dfrac{y^3}{3}-\\dfrac{zy^2}{2}+\\left(3z - 9 \\right)y \\Bigg ]_{z-5}^{5} \\\\\n&= \\frac{z^3-18z^2+69z-20}{24}+\\frac{15z-20}{24} \\\\\n&= \\dfrac{z^3-18z^2+84z-40}{24}\n\\end{align*}\n\n\\noindent\nThus, \n\n\\[ f_Z(x) = \\begin{cases} \n      \\dfrac{z^3-18z^2+108z-216}{24} & \\text{ if } 6 \\leq x \\leq 8, \\\\\n      \\dfrac{z^3-18z^2+84z-40}{24} & \\text{ if } 8 \\leq x \\leq 10.\n      \\end{cases} \\]\n\n\\item \n\\[ f_X(x) = \\begin{cases} \n      \\frac{1}{2} & \\text{ if } 0 < x < 2, \\\\\n      0 & \\text{ otherwise}.\n      \\end{cases} \\]\n      \n \\[ f_Y(x) = \\begin{cases} \n      \\frac{x}{2} & \\text{ if } 0 < x < 2, \\\\\n      0 & \\text{ otherwise}.\n      \\end{cases} \\]\n      \n\\noindent\nGiven $Z = X + Y$, $0 < X < 2$, and $0 < Y < 2$, we know that $f_Z$ will take on the following,\n\n\\begin{equation*}\n\\int_{- \\infty}^{\\infty} f_X(z-y) f_Y(y) dy \\enspace \\text{ or } \\enspace \\int_{- \\infty}^{\\infty} f_Y(z-x) f_X(x) dx.\n\\end{equation*}\n\n\\noindent\nWe will use the former. From the restrictions on $X$ and $Y$, we can derive the following, $y < z < 2+y$ and $z-2 < y < z$. These will help us calculate our bounds of integration and ranges of the $Z$ random variable. The $Z$ ranges over which $f_Z$ will have a value is $0 < z < 2$ and $2 < z < 4$. So, we will go ahead and calculate those,\n\n\\begin{align*}\nf_Z(x) &= \\int_{0}^{z} \\frac{y}{4} \\text{ } dy = \\Bigg [ \\frac{y^2}{8} \\Bigg ]_{0}^{z} = \\frac{z^2}{8},\n\\end{align*}\n\n\\begin{align*}\nf_Z(x) &= \\int_{z-2}^{2} \\frac{y}{4} \\text{ } dy = \\Bigg [ \\frac{y^2}{8} \\Bigg ]_{z-2}^{2} = \\frac{1}{2} - \\frac{(z-2)^2}{8}.\n\\end{align*}\n\n\\noindent\nThus, \n\n\\[ f_Z(x) = \\begin{cases} \n      \\frac{z^2}{8} & \\text{ if } 0 \\leq x \\leq 2, \\\\\n      \\frac{1}{2} - \\frac{(z-2)^2}{8} & \\text{ if } 2 \\leq z \\leq 4.\n      \\end{cases} \\]\n\n% \\item What can you say about the set $E = { z : f_Z(z) > 0 }$ in each case?\n\\end{enumerate}\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q9} Assume that the service time for a customer at a bank is exponentially distributed with mean service time $2$ minutes. Let $X$ be the total service time for $10$ customers. Estimate the probability that $X > 22$ minutes.\n\n\\vspace*{.5cm}\n\\noindent\nWe can view $X$ as the sum of $10$ independent, exponentially distributed random variables with mean service time of $2$ minutes. Let $X_i$ with $i = 0, \\ldots, 10$ be these independent random variables. Then,\n\n\\begin{equation*}\nX = X_1 + X_2 + \\cdots + X_{10}.\n\\end{equation*}\n\n\\noindent\nSince all the $X_i$ are exponentially distributed with mean $\\frac{1}{\\lambda}$, then \n\n\\begin{equation*}\nX = \\frac{\\lambda e^{- \\lambda x} (\\lambda x)^{n-1}}{(n-1)!}.\n\\end{equation*}\n\n\\noindent\nThus,\n\n\\begin{equation*}\n\\mathbb{P}(X > 22) = 1 - \\int_{0}^{22} \\frac{.5 e^{- .5 x} (.5 x)^{9}}{9!} dx = .341.\n\\end{equation*}\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q10} Let $X_1, X_2, \\ldots , X_n$ be $n$ independent random variables each of which has an exponential density with mean $\\mu$. Let $M$ be the \\textit{minimum value} of the $X_j$ . Show that the density for $M$ is exponential with mean $\\mu / n$. Hint: Use cumulative distribution functions.\n\n\\vspace*{.5cm}\n\\noindent\nSince $X_1, X_2, \\ldots , X_n$ are $n$ independent random variables with exponential density and mean $\\mu$, the probability distribution of $X_j$ for $j = 1, 2, \\ldots, n$ is\n\n\\begin{equation*}\nf(x) = \\frac{1}{\\mu} e^{-\\frac{x}{\\mu}}.\n\\end{equation*}\n\n\\noindent\nIt follows that the cumulative distribution function can be calculated from the integral of $f(x)$,\n\n\\begin{equation*}\nF(x) = \\int \\frac{1}{\\mu} e^{-\\frac{x}{\\mu}} = e^{-\\frac{x}{\\mu}} + C.\n\\end{equation*}\n\n\\noindent\nWe can plug in $F(0) = 0$ to find that $C = -1$ and $F(x) = 1 - e^{-\\frac{x}{\\mu}}$. Then, if $M$  is the minimum value of $X_j$ for $j = 1, 2, \\ldots, n$, we can find $F_M(x)$, \n\n \\begin{equation*}\nP( \\text{min}(X_1, \\ldots, X_n) > M ) = \\big [ P(X_1 > x) \\big ]^n = \\big [ 1 - F(x) \\big ]^n =  \\big [ 1 - (1 - e^{- x / \\mu }) \\big ]^n = 1 - e^{ - \\frac{n}{\\mu} x }.\n\\end{equation*}\n\n\\noindent\nThen, we can find $f_M(X)$ by differentiating $F_M(x)$ to get \n\n\\begin{equation*}\nf_M(x) = \\frac{n}{\\mu} e^{- \\frac{n}{\\mu} x }.\n\\end{equation*}\n\n\\noindent\nThis then satisfies that the minimum value of $X_j$ for $j = 1, 2, \\ldots, n$ has exponential distribution with mean $n / \\mu$.\n\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q11} A company buys $100$ light bulbs, each of which has an exponential lifetime of $1000$ hours. What is the expected time for the first of these bulbs to burn out? (See Exercise $10$.)\n\n\\vspace*{.5cm}\n\\noindent\nSince we are looking for the first bulb to burn out, we can refer to the result of the last problem. Let $X_1$ denote the first bulb to burn out. Then, E$(X_1) = \\mu / n = 1000 / 100 = 10$ hours. \n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q13} Particles are subject to collisions that cause them to split into two parts with each part a fraction of the parent. Suppose that this fraction is uniformly distributed between 0 and 1. Following a single particle through several splittings we obtain a fraction of the original particle $Z_n = X_1 \\cdot X_2 \\cdot \\ldots \\cdot X_n$ where each $X_j$ is uniformly distributed between $0$ and $1$. Show that the density for the random variable $Z_n$ is\n\n\\begin{equation*}\nf_n(z) = \\frac{1}{(n-1)!} (- \\text{log} z)^{n-1}.\n\\end{equation*}\n\n\\noindent\nHint: Show that $Y_k = - \\text{log} X_k$ is exponentially distributed. Use this to find the density function for $S_n = Y_1 + Y_2+ \\cdots + Y_n$, and from this the cumulative distribution and density of $Z_n = e^{−S_n}$.\n\n\\vspace*{.5cm}\n\\noindent\nSince $Y_k = - \\text{log} X_k$, we see that \n\n\\begin{equation*}\nP(Y_k \\leq y_k) = P(- \\text{log} X_k \\leq y_k) = P(X_k \\geq e^{- y_k}) = 1 - P(X_k \\leq e^{- y_k}) = 1 - e^{- y_k}.\n\\end{equation*}\n\n\\noindent\nThus, $Y_k$ is exponentially distributed. Then, it follows that $Y_k \\sim \\text{exp}(1)$ for all $k = 1, 2, \\ldots, n$. So, $S_n$ is distributed according to the gamma function,\n\n\\begin{equation*}\nf_{S_n}(x) = \\frac{e^{- x } x^{n-1}}{\\left(n-1\\right)!}.\n\\end{equation*} \n\n\\noindent\nThen, per the hint, $Z_n = e^{−S_n}$ can be used to yield the cumulative distribution of $f_A$. So, we will start with \n\n\\begin{equation*}\nF_{Z_n}(z) = P(Z_n \\leq z) = P(e^{- S_n} \\leq z) = P(S_n \\geq - \\text{ln} z) = 1 - P(Z_n \\leq - \\text{ln} z) = 1 - F_s(- \\text{ln} z).\n\\end{equation*}\n\n\\noindent\nBy the properties of probability density functions, we can differentiate $F_{Z_n}(z)$ with respect to $z$ to get,\n\n\\begin{equation*}\nf_{Z_n}(z) = \\frac{d}{dz} 1 - F_s(- \\text{ln} z) = \\frac{(- \\text{ln} z)^{n-1}}{ \\left(n-1\\right)!}.\n\\end{equation*}\n\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q14} Assume that $X_1$ and $X_2$ are independent random variables, each having an exponential density with parameter $\\lambda$. Show that $Z = X_1 - X_2$ has density\n\n\\begin{equation*}\nf_Z(z) = \\frac{1}{2} \\lambda e^{- \\lambda \\lvert z \\rvert}.\n\\end{equation*}\n\n\\noindent\nWe can think of $Z = X_1 - X_2$ as $Z = X_1 + (-X_2)$. Then, it is easily seen that $X_1$ and $X_2$ have probability density functions\n\n\\begin{equation*}\nf_{X_1}(x) = \\begin{cases}\n             0  & \\text{ for } x < 0, \\\\\n             \\lambda e^{- \\lambda x}  & \\text{ for } x > 0.\n       \\end{cases} \\quad\nf_{X_2}(x) = \\begin{cases}\n\t\t      \\lambda e^{- \\lambda x}  & \\text{ for } x < 0, \\\\\n             0  & \\text{ for } x > 0.\n       \\end{cases}\n\\end{equation*}\n\n\\noindent\nThe convolution of $Z = X_1 + (-X_2)$ is therefore\n\n\\begin{equation*}\nf_Z(z) = (f_1 \\cdot f_2)(z) = \\int_{- \\infty}^{\\infty} f_1(z - x)f_2(x) \\text{ } dx.\n\\end{equation*}\n\n\\noindent\nAs a result of the ranges of $X_1$ and $X_2$, the analysis on $Z$ can be broken down into the two cases: $z > 0$ and $z < 0$,\n\n\\begin{align*}\nf_Z(z) &= \\int_{- \\infty}^{z} f_1(z - x)f_2(x) \\text{ } dx \\\\\n&= \\lambda^2 e^{- \\lambda z} \\int_{- \\infty}^{z} e^{2 \\lambda x} \\text{ } dx  \\\\\n&= \\lambda^2 e^{- \\lambda z} \\frac{e^{2 \\lambda x}}{2 \\lambda}  \\text{ } dx  \\\\\n&= \\frac{\\lambda}{2} e^{- \\lambda z} \\\\\n\\end{align*}\n\n\\begin{align*}\nf_Z(z) &= \\int_{- \\infty}^{0} f_1(z - x)f_2(x) \\text{ } dx \\\\\n&= \\lambda^2 e^{- \\lambda z} \\int_{- \\infty}^{0} e^{2 \\lambda x} \\text{ } dx  \\\\\n&= \\lambda^2 e^{- \\lambda z} \\frac{1}{2 \\lambda}  \\\\\n&= \\frac{\\lambda}{2} e^{- \\lambda z}  \\\\\n\\end{align*}\n\n\\noindent\nSince $f_Z(z)$ has the same definition when $z < 0$ and $z > 0$, we can \n\n\\begin{equation*}\nf_Z(z) = \\frac{\\lambda}{2} e^{- \\lambda \\lvert z \\rvert }.\n\\end{equation*}\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q20} Let $X_1, X_2, \\ldots , X_n$ be a sequence of independent random variables, all having a common density function $f_X$ with support $[a, b]$ (see Exercise $19$). Let $S_n = X_1 + X_2 + \\cdots + X_n$, with density function $f_{S_n}$. Show that the support of $f_{S_n}$ is the interval $[na, nb]$. Hint: Write $f_{S_n} = f_{S_n-1} \\cdot f_X$. Now use Exercise $19$ to establish the desired result by induction.\n\n\\vspace*{.5cm}\n\\noindent\nSuppose that $n=1$. Then, $f_{S_n} = f_{S_1} = f_{X_1}$ has support in the interval $[na, nb] = [a,b]$ because $f_X$ is defined to have support $[a, b]$. \n\n\\vspace*{.5cm}\n\\noindent\nNext, suppose that for some $k \\geq n$, $f_{S_k}$ has support on $[ka, kb]$. Then, since we know $f_{S_n} = f_{S_n-1} \\cdot f_X$, we can say that $f_{S_{k+1}} = f_{S_k} \\cdot f_X$. $f_{S_{k+1}}$ then has support on $\\big [ ka  + a, kb + b \\big ] = \\big [(k+1) a, (k+1) b \\big ]$. \n\n\\vspace*{.5cm}\n\\noindent\nThus, by induction, we have shown that the support of $f_{S_n}$ is the interval $[na, nb]$ for all $n$.\n\n\\vspace*{.5cm}\n\\noindent\n\\textbf{Ch 7.2 Q21} Let $X_1, X_2, . . . , X_n$ be a sequence of independent random variables, all having a common density function $f_X$. Let $A = S_n/n$ be their average. Find $f_A$ if\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $f_X(x) = (1 / \\sqrt{2 \\pi}) e^{- \\frac{x^2}{2}}$ (normal density).\n\n\\noindent\nSince we know that $A = S_n/n$, $\\text{E}(A) = \\text{E}(S_n / n) = \\frac{1}{n} \\text{E}(S_n)$. Then, since $X_1, X_2, . . . , X_n$ is a sequence of independent random variables, the expected value of the sums is the sum of the expected values of each $X_i$ for $i = 1, 2, \\ldots $. So, $\\text{E}(S_n) = n \\cdot \\text{E}(X_i) = n \\mu$. By plugging in $\\text{E}(X_i)$, we can see that $\\text{E}(A) = \\mu_{X_i} = 0$.\n\n\\noindent\nA similar approach can be taken with the variance such that $\\text{V}(A) = \\text{V}(S_n / n) = \\frac{1}{n^2} \\text{V}(S_n) = \\frac{1}{n^2} n = \\frac{1}{n}$.\n\n\\noindent\nThen, we use the fact that the sum of independent normally distributed random variables is normally distributed to plug in our values of $\\mu$ and $\\lambda$ for $A$,\n\n\\begin{equation*}\nf_A(x) = \\frac{1}{\\sqrt{\\frac{n}{2 \\pi}}} e^{\\frac{-n x^2}{2}}.\n\\end{equation*}\n\n\\item $f_X(x) = e^{- x}$ (exponential density). \\textit{Hint}: Write $f_A(x)$ in terms of $f_{S_n}(x)$.\n\n\\noindent\nWe know that the sum of exponentially distributed random variables is gamma distributed. So, we need to find parameters $\\alpha$ and $\\beta$ that satisfy $f_A(x)$ based on the distribution of $f_X(x) = e^{- x}$. This is clearly exponentially distributed with parameter $\\lambda = 1$. The resulting expected value is $\\text{E}(x) = \\frac{1}{\\lambda}$ and the resulting variance is $\\text{E}(x) = \\frac{1}{\\lambda^2}$. \n\n\\noindent\nThe resulting distributions of the sums of random variables, $S_n = \\frac{e^{-x} x^{n-1}}{(n-1)!}$. The parameters of this distribution are thus $\\alpha = n$ and $\\beta = 1$. Since we know that $A = S_n/n$, $\\text{E}(A) = \\text{E}(S_n / n) = \\frac{1}{n} \\text{E}(S_n) = \\frac{1}{n} \\frac{\\alpha}{\\beta} = \\frac{1}{n} \\frac{n}{1} = 1$.\n\n\\noindent\nA similar approach can be taken with the variance such that $\\text{V}(A) = \\text{V}(S_n / n) = \\frac{1}{n^2} \\text{V}(S_n) = \\frac{1}{n^2} n = \\frac{1}{n} = \\frac{\\alpha}{\\beta^2}$. Since $\\text{E}(A) = \\frac{\\alpha}{\\beta} = 1$, it is seen that that $\\alpha = \\beta$. By plugging this into our variance equation, we can solve for both $\\alpha$ and $\\beta$ such that $\\alpha = \\beta = n$.\n\n\\noindent\nThen, we use the fact that the sum of independent exponentially distributed random variables is gamma distributed to plug in our values of $\\alpha$ and $\\beta$ for $A$,\n\n\\begin{equation*}\nf_A(x) = \\frac{n^n x^{n-1} e^{-xn}}{(n-1)!}.\n\\end{equation*}\n\n\\end{enumerate}\n\\end{document} ", "meta": {"hexsha": "b7fcadc5411e6b2cdbd0ecf07c424cb8144c4626", "size": 15970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/homework-6/HOMEWORK6.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/homework-6/HOMEWORK6.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/homework-6/HOMEWORK6.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": 42.8150134048, "max_line_length": 469, "alphanum_fraction": 0.6111458986, "num_tokens": 6368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.63118103843113}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Various Forms}\n\n\\objective{Find attributes and graphs of parabolas from equations and/or geometric criteria.}\n\n\nYou should have a fair amount of experience graphing, factoring, and describing\nparabola and quadratic equations.  The principles of algebra one learns dealing with quadratics\napply generally to the rest of mathematics and will serve you well for the rest of your life.\nThe slope of lines tangent to parabola are easy to calculate.\nFind the difference quotient of $f(x)=x^2+6x+5$ for any $x$.\n\n\nThe spread out for of $ax^2+bx+c$ has three advantages.  \nIt can be easily differentiated\nIt shows the y-intercept plainly\nIt can be plugged into the quadratic formula as is\n\nHowever, for graphing, it can be a little obtuse.  We might start by factoring, and see that it is\n$(x+5)(x+1)$.  This form --- called intercept form --- \\index{quadratic!intercept form}\nhas only one advantage: it is immediately obvious what the zeros of the function are.\n\n\\index{quadratic!vertex form}\nLastly, it is a bit more work, but completing the square and writing in the form $a(x-h)^2+k$\nis the easiest to graph from, its one advantage:\nthe vertex is immediately obvious\n\n\\subsection{Angles of Incidence}\nNot usually taught in an Algebra class, parabolas have many geometric properties.  The most\nphysically useful is that every incoming line has an angle of incidence that will take them all\nthrough the same place, called the focus.  This is why headlights and telescopes are paraboloids,\n3D parabolas.  A corollary to this property is that every parabola is the set of points equidistant \nfrom a point and a line.  The distance from the vertex to this focus (and directrix) is $p$, in the\nformula\\index{quadratic!parabolic form}\n\n$$\ny-k = \\frac{1}{4p}(x-h)^2\n$$\n\n~\\vfill", "meta": {"hexsha": "f3678c126a4c1e298fe8e665e13f0a0243d41fe1", "size": 1804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/0303.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": "ch03/0303.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": "ch03/0303.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.0, "max_line_length": 100, "alphanum_fraction": 0.7699556541, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6311810253924676}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrzam}\n\\section*{\\hspace*{-1.6cm} tfrzam}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nZhao-Atlas-Marks time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrzam(x)\n[tfr,t,f] = tfrzam(x,t)\n[tfr,t,f] = tfrzam(x,t,N)\n[tfr,t,f] = tfrzam(x,t,N,g)\n[tfr,t,f] = tfrzam(x,t,N,g,h)\n[tfr,t,f] = tfrzam(x,t,N,g,h,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrzam} computes the Zhao-Atlas-Marks distribution of a\n        discrete-time signal {\\ty x}, or the cross Zhao-Atlas-Marks\n        representation between two signals. This distribution writes\n\\[ZAM_x(t,\\nu)=\\int_{-\\infty}^{+\\infty} \\left[\\ h(\\tau)\\\n\\int_{t-|\\tau|/2}^{t+|\\tau|/2} x(s+\\tau/2)\\ x^*(s-\\tau/2)\\ ds\\right]\\\ne^{-j2\\pi \\nu \\tau}\\ d\\tau. \\] \n  It is also known as the {\\it Cone-Shaped Kernel distribution}. \\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & signal if auto-ZAM, or {\\ty [x1,x2]} if cross-ZAM {\\ty\n\t\t\t(Nx=length(x))}\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty g}     & time smoothing window, {\\ty G(0)} being forced to {\\ty 1}, where {\\ty G(f)} is the Fourier transform of {\\ty g(t)} \n                                         & {\\ty window(odd(N/10))}\\\\ \n        {\\ty h}     & frequency smoothing window, {\\ty h(0)} being forced to {\\ty 1}\n                                         & {\\ty window(odd(N/4))}\\\\ \n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation\\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without outpout arguments, {\\ty tfrzam} runs {\\ty tfrqview}.\n\\end{minipage}\n\n\\newpage\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.05,0.3)+fmlin(128,0.15,0.4);  \n         g=window(9,'Kaiser'); h=window(27,'Kaiser'); \n         tfrzam(sig,1:128,128,g,h,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] Y. Zhao, L. Atlas, R. Marks ``The Use of the Cone-Shaped Kernels for\nGeneralized Time-Frequency Representations of Nonstationary Signals'' IEEE\nTrans. on Acoust., Speech and Signal Proc., Vol. 38, No. 7, pp. 1084-91,\n1990. \n\\end{minipage}\n", "meta": {"hexsha": "bc957c93a4e623525bef7b4aab8485eed1b2232d", "size": 2987, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrzam.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrzam.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrzam.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 31.4421052632, "max_line_length": 137, "alphanum_fraction": 0.59390693, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6311807565787677}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\author{a1trl9}\n\\title{Algebra 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\n\\section{System of Linear Equations}\n\\textbf{Proposition 1:} for a homogeneous system of linear equations on\n\\(K\\), if the number of equations \\(m\\) is fewer than the number of\nvariables \\(n\\), then it must have a non-trival solution.\n\n\\vspace{2mm}\n\\textbf{Mathematical Induction}\n\nWhen \\(m=1, n>m\\), if one coefficient \\(a_{1k}=0\\), then one\nsolution is \\(x_k=1\\) and\nall other variables are equal to \\(0\\). If no\ncoefficient is equal to \\(0\\). Then one solution is\n\\(x_k = -\\frac{a_{1k+1}}{a_{k}},\nx_{k+1}=1\\), all other variables are equal to \\(0\\).\n\n\\vspace{1mm}\nConsidering when \\(m > 1\\) while for \\(m-1\\) the proposition holds.\n\nIf all coefficients for \\(x_1\\) are equal to zero, then one solution is\n\\(x_1=1, x_2=0, \\cdots, x_n=0\\).\n\nIf not, then change the order of equations so that \\(\\alpha_{11} \\neq 0\\).\nNow repeat the step \\(eq(k) - \\frac{a_{11}}{a_{k1}}eq(1)\\) where \\(eq(t)\\)\npresents the equation \\(t\\) and \\(k=2,3,\\cdots,n\\). Finally, the system\nof equations are transformed to:\n\\begin{equation}\n\\left\\{\n\\begin{split}\n    &a_{11}x_1+a_{12}x_2+\\cdots+a_{1n}x_n=0 \\\\\n    &a'_{22}x_2 + \\cdots + a'_{2n}x_n=0 \\\\\n    &\\vdots\\\\\n    &a'_{m2}x_2 + \\cdots + a'_{mn}x_n=0 \\\\\n\\end{split}\n\\right.\n\\end{equation}\n\nNow the second to last equations construct a new homogeneous system\nof equations with \\(m-1\\) equations and \\(n-1\\) variables:\n\\begin{equation}\n\\left\\{\n\\begin{split}\n    &a'_{22}x_2 + \\cdots + a'_{2n}x_n=0 \\\\\n    &a'_{32}x_2 + \\cdots + a'_{3n}x_n=0 \\\\\n    &\\vdots\\\\\n    &a'_{m2}x_2 + \\cdots + a'_{mn}x_n=0 \\\\\n\\end{split}\n\\right.\n\\end{equation}\n\nSince \\(n>m\\), \\(n-1>m-1\\). And the proposition hold for \\(m-1\\). There\nexists one non-trival solution \\(x_2=k_2, \\cdots, x_n=k_n\\).\n\nBack to (1). Since \\(a_{11} \\neq 0\\), with\n\\(x_2=k_2, \\cdots, x_n=k_n\\), there must be one solution \\(x_1=k_1\\)\nletting \\(a_{11}k_1+a_{12}k_2+\\cdots+a_{1n}k_n=0\\).\n\n\\section{Vector space \\& Matrix \\& System of Linear Equations}\n\n\\subsection{Vector space}\n\n\\textbf{Proposition 2.1.4:} Given two sets of vectors:\n\n\\begin{equation}\n\\begin{split}\n    \\alpha_1, \\alpha_2, \\cdots, \\alpha_r, \\quad\\quad (\\mathbf{I}) \\\\\n    \\beta_1, \\beta, \\cdots, \\beta_s, \\quad\\quad (\\mathbf{II})\n\\end{split}\n\\end{equation}\n\nIf each vector in \\((\\mathbf{I})\\) can be defined as a linear combination\nof \\((\\mathbf{II})\\), and \\(r>s\\). Then \\((\\mathbf{I})\\) are linearly dependent.\n\n\\vspace{2mm}\n\\textbf{Proof}\n\nAs each vector in \\((\\mathbf{I})\\) can be defined as a linear combination\nof \\((\\mathbf{II})\\):\n\n\\begin{equation}\n\\begin{split}\n&\\alpha_1 = x_{11}\\beta_1 + x_{12}\\beta_2 + \\cdots + x_{1s}\\beta_s \\\\\n&\\alpha_2 = x_{21}\\beta_1 + x_{22}\\beta_2 + \\cdots + x_{2s}\\beta_s \\\\\n&\\vdots\\\\\n&\\alpha_r = x_{r1}\\beta_1 + x_{r2}\\beta_2 + \\cdots + x_{rs}\\beta_s \\\\\n\\end{split}\n\\end{equation}\n\nThen given \\(k_1, k_2, \\cdots, k_s\\):\n\n\\begin{equation}\n\\sum_{i=1}^{r}k_i\\alpha_i=\n\\sum_{j=1}^{s}x_{j1}k_j\\beta_1\n+\\sum_{j=1}^{s}x_{j2}k_j\\beta_2\n+\\cdots\n+\\sum_{j=1}^{s}x_{jr}k_j\\beta_r\n\\end{equation}\n\nIn which, since \\(r>s\\), for:\n\n\\begin{equation}\n\\left\n\\{\n\\begin{split}\n&x_{11}k_1 + x_{21}k_2 + \\cdots + x_{s1}k_s = 0 \\\\\n&x_{12}k_1 + x_{22}k_2 + \\cdots + x_{s2}k_s = 0 \\\\\n&\\vdots\\\\\n&x_{1r}k_1 + x_{2r}k_2 + \\cdots + x_{sr}k_s = 0 \\\\\n\\end{split}\n\\right.\n\\end{equation}\n\nAccording to proposition 1 in section 1, there\nmust be a non-trival solution. That is, there exists \\(k_1, k_2, \\cdots, k_s\\),\nin which at least one \\(k_n \\neq 0\\), for \\(i = 1, 2, \\cdots, r\\), \\(\\sum_{j=1}^s\nx_{ji}k_j=0\\), in which case \\(\\sum_{i=1}^rk_i\\alpha_i=0\\) as well.\n. So, \\(\\alpha_1, \\alpha_2,\n\\cdots, \\alpha_r\\) are linearly dependent.\n\n\\subsection{Matrix operations}\n\n\\subsubsection{Operations and rank}\n\n\\textbf{Proposition 2.2.4:}: \\(r(AB)\\leq min(r(A), r(B))\\).\n\n\\vspace{2mm}\n\\textit{Lemma 1:}\nFor two matrics:\n\n\\begin{equation}\n\\begin{split}\n    &A=\\begin{bmatrix}\n    \\alpha_1, \\alpha_2, \\cdots, \\alpha_r \\\\\n    \\end{bmatrix}\\\\\n    &B=\\begin{bmatrix}\n    \\beta_1, \\beta_2, \\cdots, \\beta_s\n    \\end{bmatrix}\n\\end{split}\n\\end{equation}\n\nif each column vector of \\(A\\) could be defined as a linear combination\nof column vectors in \\(B\\), then \\(r(A)\\leq r(B)\\).\n\n\\vspace{2mm}\n\\textbf{Proof}\n\nSince each column vector of \\(A\\) could be defined as a linear combination\nof column vectors in \\(B\\), the maximally linearly independent set\nof \\(A\\): \\(\\alpha_{i_1}, \\alpha_{i_2}, \\cdots, \\alpha_{i_k}\\)\ncould be defined as a linear combination of\nthe maximally linearly independent set of \\(B\\):\n\\(\\beta_{j_1}, \\beta_{j_2}, \\cdots, \\beta_{j_m}\\) as well.\n\nSince \\(\\alpha_{i_1}, \\alpha_{i_2}, \\cdots, \\alpha_{i_k}\\) must be\nlinearly independent, according to proposition 2.1.4,\n\\(i_k \\leq j_m \\), that is \\(r(A)\\leq r(B)\\).\n\n\\vspace{2mm}\n\\textbf{Proof for proposition 2.2.4}\n\nLet \\(C=AB=\\begin{bmatrix}c_1,c_2,\\cdots,c_n\\end{bmatrix}\\). Then\nfor \\(c_i, i = 1, 2, \\cdots, n\\):\n\n\\begin{equation}\n\\begin{split}\nc_i &= \\begin{bmatrix}\na_{11}b_{i1}+a_{12}b_{i2}+\\cdots+a_{1m}b_{im}\\\\\na_{21}b_{i1}+a_{22}b_{i2}+\\cdots+a_{2m}b_{im}\\\\\na_{k1}b_{i1}+a_{k2}b_{i2}+\\cdots+a_{km}b_{im}\\\\\n\\end{bmatrix}\\\\\n&=\\alpha_1b_{i1}+\\alpha_2b_{i2}+\\cdots+\\alpha_mb_{im}\n\\end{split}\n\\end{equation}\n\nThat is, each column vector of \\(C\\) could be presented as\na combination of column vectors of \\(A\\). So according\nto the lemma, \\(r(C)\\leq r(A)\\). Similarly, \\(r(C)\\leq r(B)\\)\n(using transpose). Therefore, \\(r(AB)\\leq min(r(A), r(B))\\).\n\n\\subsection{Square matrix}\n\n\\textbf{Proposition 2.3.3:} for a \\(n\\) square matrix \\(A\\) in the number\nfield \\(K\\), the sufficient and necessary condition for \\(A\\) is\ninvertable is \\(A\\) has full rank.\n\n\\vspace{2mm}\n\\textbf{Proof}\n\n\\vspace{2mm}\n\\textit{Sufficiency}\n\nWhen \\(A\\) has full rank, there exist elementary matrics\n\\(P_i, Q_j, i = 1, 2, \\cdots, n, j=1,2,\\cdots,m\\), such that:\n\n\\begin{equation}\n    P_1P_2\\cdots P_nA = E\n\\end{equation}\n\nAnd:\n\n\\begin{equation}\n    AQ_1Q_2\\cdots Q_m = E\n\\end{equation}\n\nLet \\(P=P_1P_2\\cdots P_n\\), and \\(Q=Q_1Q_2\\cdots Q_m\\).\n\nThen:\n\n\\begin{equation}\nP=PE=PAQ=(PA)Q=EQ=Q\n\\end{equation}\n\nSo \\(AP=PA=E\\), A is invertable.\n\n\\vspace{2mm}\n\n\\textit{Necessity}\n\nSince \\(A\\) is invertable, there exists \\(P\\), \\(AP=E\\).\nAccording to proposition 2.2.4, \\(r(E)=n\\leq min(r(A), r(P))\\leq r(A)\\).\nTherefore \\(r(A)=n\\) and has full rank.\n\n\\vspace{2mm}\n\\textbf{Proposition 2.3.5}: For a \\(n \\times n\\) square matrix \\(\\mathbf{X}\\),\n\\(X\"X\\) is a positive semi-definite matrix.\n\n\\vspace{2mm}\n\\textbf{Proof}\nIf we present \\(X=[X_1, X_2, \\cdots, X_n]'\\) and\n\\(X'=[X_1, X_2, \\cdots, X_n]\\)\nIt can be shown \\(\\mathbf{A}=\\mathbf{X}'\\mathbf{X}\\) is symmetric as\n\\begin{equation}\n   a_{ij}=X_i \\cdot X_j =a_{ji}\n\\end{equation}\n\nWhere \\(a_{kl}\\) presents the element located in the \\(k\\)th row and \\(l\\)th column\nof \\(A\\).\n\nThen for any non-zero vector \\(\\V{v}\\):\n\\begin{equation}\n\\V{v}'A\\V{v}=\\V{v}'\\mathbf{X}'\\mathbf{X}\\V{v}=(\\mathbf{X}\\V{v})'\\mathbf{X}\\V{v}\n=||\\mathbf{X}\\V{v}||^2\\geq 0\n\\end{equation}\n\n\\section{Determinant}\n\n\\subsection{Definition}\n\n\\subsubsection{Linearity and Antisymmetry}\n\nConsidering the set consisting of all \n\\(n \\times n\\) matrix \\(M_n(K)\\) in the number field \\(K\\) and\na function \\(f\\) in the domain,\nthe linearity by row embodies as:\n\nFor matrix:\n\n\\begin{equation*}\nA=\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\alpha_2 \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}\n\\end{equation*}\n\nIf for \\(i \\in [1, n]\\):\n\n\\begin{equation*}\n    \\alpha_i=k\\alpha+l\\beta\n\\end{equation*}\n\nThen:\n\n\\begin{equation}\nf(A)=\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix} =\nkf(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) + lf(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\beta \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}\n)\n\\end{equation}\n\nSimilarly, the linearity by column embodies as:\n\n\\begin{equation}\n\\begin{split}\n\\begin{bmatrix}\n    \\alpha_1 &\n    \\cdots &\n    \\alpha_i &\n    \\cdots &\n    \\alpha_n\n\\end{bmatrix} & =\nkf(\n\\begin{bmatrix}\n    \\alpha_1 &\n    \\cdots &\n    \\alpha &\n    \\cdots &\n    \\alpha_n\n\\end{bmatrix}) \\\\\n& + lf(\n\\begin{bmatrix}\n    \\alpha_1 &\n    \\cdots &\n    \\beta &\n    \\cdots &\n    \\alpha_n\n\\end{bmatrix}\n)\n\\end{split}\n\\end{equation}\n\nMoreover, the function \\(f\\) holding the characteristic above is\nsaid antisymmetric if\n\\(f(A)=0\\) when any two rows/columns of \\(A\\) are identical. \n\n\\vspace{2mm}\n\\textbf{Proposition 3.1.1:}\n\nif function \\(f\\) holds all characteristics above (i.e. linear\nby row/column, antisymmetric), then:\n\n\\begin{itemize}\n    \\item Swap two rows/coloums of matrix \\(A\\) to matrix \\(B\\),\n    \\(f(A)=-f(B)\\).\n    \\item Add \\(\\lambda\\alpha_j\\) to \\(\\alpha_i\\) to get matrix \\(B\\),\n    \\(f(A)=f(B)\\).\n\\end{itemize}\n\n\\vspace{2mm}\n\\textbf{Proof:}\n\nAssuming \\(f\\) holds linearity by row, then:\n\\begin{equation}\n\\begin{split}\nf(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) + \nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})\n=\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i + \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_j + \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})=0\n\\end{split}\n\\end{equation}\n\nTherefore:\n\\begin{equation}\nf(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) = \n-f(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})\n\\end{equation}\n\nBesides:\n\n\\begin{equation}\nf(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i + \\lambda\\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) = \nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) +\n\\lambda f(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) =\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}) + 0 =\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_j \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})\n\\end{equation}\n\nFor \\(f\\) holding the linearity by column, the proof is similar.\n\n\\vspace{2mm}\n\\textbf{Inference 1}\n\nTogether with the rule indicated in (1), namely:\n\n\\begin{equation}\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\lambda\\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})=\n\\lambda f(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})\n\\end{equation}\n\nAnd:\n\n\\begin{equation}\nf(\\begin{bmatrix}\n    \\alpha_1 &\n    \\cdots &\n    \\lambda\\alpha_i &\n    \\cdots &\n    \\alpha_n\n\\end{bmatrix})=\n\\lambda f(\\begin{bmatrix}\n    \\alpha_1 &\n    \\cdots &\n    \\alpha_i &\n    \\cdots &\n    \\alpha_n\n\\end{bmatrix})\n\\end{equation}\n\nThese three rules correspond to three types of elementary transformations\nby row/column. Therefore, it is obvious that for two functions \\(f,g\\) holding\nantisymmetry and linearity, if \\(f(A)=g(A)\\) and \\(B=AP_1P_2\\cdots P_n\\)\nwhere \\(P_1, P_2, \\cdots, P_n\\) are all elementary matrics, then\n\\(f(B)=g(B)\\).\n\n\\vspace{2mm}\n\\textbf{Inference 2}\n\nThe necessary and sufficient condition for a function \\(f\\) holding\nlinearity by row/column to be antisymmetric is for each matrix\n\\(A\\) that is rank deficient, \\(f(A)=0\\).\n\n\\vspace{2mm}\n\\textbf{Proof:}\n\n\\vspace{1mm}\n\\textit{Sufficient:}\n\nSince for each matrix \\(A\\) that is rank deficient, \\(f(A)=0\\),\nand obviously if \\(A\\) has two identical rows/columns, \\(A\\) is\nrank deficient. So \\(f(A)=0\\) when \\(A\\) has two identical rows/columns.\n\n\\vspace{2mm}\n\\textit{Necessary:}\n\nAssuming \\(f\\) holds linearity by row. Then for \\(\\lambda \\neq 0\\):\n\n\\begin{equation}\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\mathbf{0} \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix} = \n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\lambda \\mathbf{0} \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix} = \n\\lambda\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\mathbf{0} \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix}\n\\end{equation}\n\nTherefore:\n\n\\begin{equation}\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\mathbf{0} \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix} = 0\n\\end{equation}\n\nBesides, if \\(A\\) is rank deficient, with \\(\\alpha_i = k_1\\alpha_1 + \\cdots +\nk_{i-1}\\alpha_{i-1} + k_{i+1}\\alpha_{i+1} + \\cdots + k_n\\alpha_n\\),\nrepeat the step that \\(\\alpha'_i=\\alpha_i - k_j \\alpha_{j}\\) for\n\\(k = 1, 2, \\cdots, i-1, i+1, \\cdots, n\\). Finally, \\(\\alpha'_i=\\mathbf{0}\\).\nConsidering \\(f\\) holds the linearity:\n\n\\begin{equation}\nf(A)=f(\n\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})=\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\alpha'_i \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})=\nf(\\begin{bmatrix}\n    \\alpha_1 \\\\\n    \\vdots \\\\\n    \\mathbf{0} \\\\\n    \\vdots \\\\\n    \\alpha_n\n\\end{bmatrix})=0\n\\end{equation}\n\nFor \\(f\\) holding the linearity by column, the proof is similar.\n\n\\subsubsection{Definition}\n\nThere are three characteristics that a determinant function holds:\n\n\\begin{itemize}\n    \\item If matrix \\(A\\) is rank deficient, \\(f(A)=0\\).\n    \\item For identity matrix \\(E\\), \\(f(E)=1\\).\n    \\item Linearity by column.\n\\end{itemize}\n\n\\vspace{2mm}\n\\textbf{Proposition 3.1.2:} The determinant function is unique.\n\n\\vspace{2mm}\n\\textbf{Proof:}\n\nAssuming there are two determinant functions: \\(f, g\\). \n\nFor matrix \\(A\\), When \\(r(A)<n\\), according to the three characteristics,\n\\(f(A)=g(A)=0\\).\n\nWhen \\(r(A)=n\\), \\(A\\) can be presented as \\(EP_1P_2\\cdots P_m\\) where\n\\(E\\) is an identity matrix and \\(P_1, P_2, \\cdots, P_m\\) are elementary\nmatrics. As \\(f(E)=g(E)\\), together with \\textbf{Inference 1}, \n\\(f(A)=g(A)\\).\n\nSo \\(f, g\\) are identical.\n\n\\vspace{2mm}\n\\textbf{Proposition 3.1.3:}\nFor a determinant function \\(f\\), \\(f(A)=f(A')\\) where \\(A'\\) is\nthe transpose of matrix \\(A\\).\n\n\\vspace{2mm}\n\\textbf{Proof:}\n\nWhen \\(r(A)<n\\), then \\(f(A)=f(A')=0\\).\n\nWhen \\(r(A)=n\\), \\(A\\) can be presented as \\(EP_1P_2\\cdots P_m\\) where\n\\(E\\) is an identity matrix and \\(P_1, P_2, \\cdots, P_m\\) are elementary\nmatrics. \\(f(A)=(-1)^r\\lambda_1\\lambda_2\\cdots \\lambda_s\\) where \\(r,s\\)\nare numbers of the type I \\& type II elementary matrics (i.e. \\(P_i=P_n(j,k)\\) or\n\\(P_i=P_n(\\lambda\\cdot k)\\)) respectively. \nSimilarly, \\(A'=EP'_mP'_{m-1}\\cdots P'_1\\). \n\\(f(A')=(-1)^{r'}\\lambda_1\\lambda_2\\cdots \\lambda_{s'}\\).\n\nWhen \\(P_i\\) is the\nfirst or second type of elementary, matrics , \\(P_i=P'_i\\). So \\(P_1P_2\\cdots P_m\\)\nand \\(P'_mP'_{m-1}\\cdots P'_1\\) contain the same number of type I and type\nII elementary matrics.\nWhen \\(P_i\\) is the\nthird type (i.e. \\(P_i=P_n(\\lambda\\cdot j, k)\\)), \\(P'_i\\) is also the\nthird type, therefore \\(f(XP_i)=f(X)\\) and \\(f(XP'_i)=f(X)\\) (\\(P_i,\nP'_i\\) will not change the output of \\(f\\)).\n\nSo \\(f(A)=f(EP_1P_2\\cdots P_m)=f(EP'_mP'_{m-1}\\cdots P'_1)=f(A')\\).\n\n\n\\end{document}", "meta": {"hexsha": "851fa70526585943d8e7274f8228e52faeabca47", "size": 15325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alge.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": "alge.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": "alge.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": 22.7037037037, "max_line_length": 83, "alphanum_fraction": 0.6218597064, "num_tokens": 5838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.6311807389560881}}
{"text": "\\chapter{Overview}\n\\section{Summary}\nWe start by taking a quick look at finite-precision arithmetic. We then discuss how to solve ordinary differential equations (ODE) and partial differential equations (PDE) using the technique of separation of variables. We then introduce numerical time-stepping schemes that can be used to solve ODEs and PDEs. Next we introduce pseudo spectral methods by giving an overview of the discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT) algorithm that is used to quickly calculate the DFT. Finally we will combine all of this to solve a couple of different PDEs first in a serial setting and then in a parallel setting. The programs will use Matlab\\footnote{\\url{http://www.mathworks.com/products/matlab/index.html} -- if this is not available, we suggest modifying the Matlab programs to use Octave which can be freely downloaded at {\\url{http://www.gnu.org/software/octave/}}.} and Fortran. A Python{\\footnote{\\url{http://python.org/}} implementation of some of the Matlab programs is also provided. \n\n\\section{Prerequisites}\nWe assume that the reader has introductory programming experience, for example using C, C++, Fortran, Matlab, Octave, Python or equivalent. Since detailed programming examples have been provided, we do not expect a significant programming background, but hope the required knowledge will be acquired as one works through the examples. We also assume the level of mathematical maturity obtained in a demanding calculus course, for example at the level of Courant and Johns ``Introduction to Calculus and Analysis''. A course in differential equations would also be helpful, but for many scientists or engineers, their fields of interest will provide numerous examples of these. More programming experience or mathematical background will make the material easier to understand. Checking whether the simulations are correct may also be easier for those with knowledge of the behavior of solutions of the partial differential equations that are being approximated, however we have tried to choose representative differential equations that will make it easy for one to use the programs and then adapt them to the use being considered.  \n\n\\section{Using the Programs}\n\nThe programs have been tested on several different computers. The programs are located in program directories which correspond to the chapter in which the programs first appear. While they are not explicitly hyperlinked, one can find their locations either by reading the LaTeX source code or by searching the appropriate directory.\n\nThe Matlab programs are guaranteed to work with Matlab R2011b, but should also work with other recent versions of Matlab. They should also be easy to modify so that they work with Octave. The Fortran programs have been tested primarily with the GCC 4.6.2 compiler suite, although they should work with most other recent compilers. If using an implementation of MPI that depends on a particular compiler, we suggest also using the GCC compiler. We expect that the programs should work with minor modifications with other compilers, but cannot guarantee this.  For simplicity and to allow checking of program correctness, we have chosen to use a low compiler optimization level. We encourage users to increase the compiler optimization level and compiler flags once they have checked that the programs are working correctly on their systems. FFTW, a free Fast Fourier transform library, is also required to run the programs. This can be downloaded from \\url{http://fftw.org/}. The MPI programs make use of the library 2DECOMP\\&FFT which can be downloaded from \\url{http://www.2decomp.org}. Finally, the last part of the tutorial requires the use of the free and open source VisIt parallel visualization program, which can be obtained from \\url{https://wci.llnl.gov/codes/visit/home.html}. If you expect to do large parallel simulations (A guide for large at present is 20\\% of the system for systems larger than 10,000 cores), it may be worth learning the most efficient system settings for performing output and for parallelization. We do not address this in this tutorial, but suggest that you contact your computing center for suggestions.\n\n\\section{Course Outlines / Assessment Rubric}\n\nThe material in these notes can form the basis of a short course. The most important portions are chapters 1 to  11.  A selection can then be made from chapters 12, 13 and 14. A selection of the problems can be used to assess student learning. Note that problems in chapters 8.  12, 13 and 14 can develop into extensive research projects, so only a sample of these should be given to any students if they only have a limited time to solve them. A student will have successfully understood the material if they can run the example Matlab/Python, serial Fortran, OpenMP Fortran and MPI Fortran programs, and can also modify them to solve related problems. Successful completion of problems which test these abilities will be enough to indicate that students have understood the fundamental concepts.", "meta": {"hexsha": "8205b691e61423eab6baf1b263ab4aac33370869", "size": 5065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Overview/Overview.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "Overview/Overview.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "Overview/Overview.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 316.5625, "max_line_length": 1640, "alphanum_fraction": 0.8100691017, "num_tokens": 1014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.631180737705516}}
{"text": "\\chapter{Properties of Cheby\\-shev-Vander\\-monde Ma\\-trices}\n\\label{chap:CV_Prop}\n\nIn this chapter we discuss properties of Chebyshev polynomials\nand Chebyshev-Vander\\-monde (C\\-/V) matrices that we will\nuse in later chapters to develop fast algorithms for\nsolving interpolation and differential equations.\n\n", "meta": {"hexsha": "c64951f5ba10314b79766fa732451d10b55f2ac6", "size": 308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/cv_properties.tex", "max_stars_repo_name": "chgorman/UCSB-Dissertation-Template", "max_stars_repo_head_hexsha": "c57b9e5209e93ecb79abb364dbad29037a2aed03", "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/cv_properties.tex", "max_issues_repo_name": "chgorman/UCSB-Dissertation-Template", "max_issues_repo_head_hexsha": "c57b9e5209e93ecb79abb364dbad29037a2aed03", "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/cv_properties.tex", "max_forks_repo_name": "chgorman/UCSB-Dissertation-Template", "max_forks_repo_head_hexsha": "c57b9e5209e93ecb79abb364dbad29037a2aed03", "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": 34.2222222222, "max_line_length": 62, "alphanum_fraction": 0.8051948052, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6310959563754235}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{September 3, 2014}\n\\maketitle\n\\section*{1.1 \\#11}\nif $a>0$ then $(ab,ac)=a(b,c)$\n\nassume $a,b,c\\in\\mathbb{Z}, a>0$\n\\begin{align*}\n  d&=(ab,ac)\\\\\n  d&=mab+mac\\text{ theorem 1.1.6}\\\\\n  &=a(mb+nc)\\text{ this is a linear combination of gcd for }a,b\\\\\n  mb+nc&\\in\\gcd(b,c)\\mathbb{Z}\\\\\n  d&=ad_1\n\\end{align*}\nnow prove that $d|ad_1$.\n\\begin{align*}\n  d_1&=m'b+n'c\\text{ for some }m',n'\\in\\mathbb{Z}\\\\\n  ad_1&=m'ab+n'ac\\\\\n  d&=(ab,ac)\\rightarrow d|m'ab+n'ac\\rightarrow d|ad_1\n\\end{align*}\n\\section*{$3x+7$ divisible by 11 (problem 22)}\n$x=11+5k,k\\in\\mathbb{Z}$, note there are infinitely many solutions, and the difference between any two solutions is 11\n\nif $x=5+11k$ for $k\\in\\mathbb{Z}$ then $3x+7=3(5+11k)+7$\n\nassume $3x+7$ is divisible by 11. $11q+r=x, 0\\le r<10$ then $3x+7=3(11q+r)+7=33q+3r+7$ so $3r+7$ is divisible by 11. we know that $0\\le r<11$ so $7\\le 3r+7\\le37$, $3r+7\\in\\{11,22,33\\}\\rightarrow r=5$ \n\\section*{fundamental  theorem of arithmetic}\nany integer $a>1$ can be factored uniquely as a product of prime numbers. $a=p_1^{\\alpha_1}p_2^{\\alpha_2}...p_n^{\\alpha_n}...$ with $p_1<p_2<...<p_n$ and $\\alpha_1,\\alpha_2,...\\alpha_n$ positive integers\n\\section*{least common multiple}\ngiven $a,b\\in\\mathbb{Z}^+$, we say that the positive integer $m$ is the lcm of $a$ and $b$ if\n\\begin{enumerate}\n\\item\n$a|m$ and $b|m$\n\\item\nif $a|c$ and $b|c$ then $m|c$\n\\end{enumerate}\n\\subsubsection*{fact}\n$a=p_1^{\\alpha_1}p_2^{\\alpha_2}...p_n^{\\alpha_n}$\n\n$b=p_1^{\\beta_1}p_2^{\\beta_2}...p_n^{\\beta_n}$\n\n$p_1<p_2<...<p_n, \\alpha_i,\\beta_i\\ge 0$\n\nthen $(a,b)=p_1^{\\min\\{\\alpha_1,\\beta_1\\}}...p_n^{\\min\\{\\alpha_n,\\beta_n\\}}$\n\nthen $[a,b]=p_1^{\\max\\{\\alpha_1,\\beta_1\\}}...p_n^{\\max\\{\\alpha_n,\\beta_n\\}}$\n\\subsubsection*{example}\n\\begin{align*}\n  6&=2^13^15^0\\\\\n  15&=2^03^15^1\\\\\n  (6,15)&=2^03^15^0=3\\\\\n  [6,15]&=2^13^15^1=30\n\\end{align*}\n\\subsubsection*{observe}\n$(a,b)[a,b]=ab$\n\nleast common multiple of $a,b$ is $ab$\n\\section*{congruences}\n\\subsection*{definition}\ngiven $a,b\\in\\mathbb{Z}$ and $n\\in\\mathbb{Z}, n>0$ we say that $a\\equiv b \\mod n$ if $a$ and $b$ give the same remainder when divided by $n$ \n\nexercise from last time showed $a\\equiv b \\mod n\\Leftrightarrow n|(a-b)$\n\\subsubsection*{properties}\n\\begin{enumerate}\n\\item\n\\begin{align*}\n  a\\equiv b \\mod n\\\\\n  c\\equiv d \\mod n\\\\\n  \\intertext{implies}\n  a\\pm c\\equiv b\\pm d \\mod n\\\\\n  \\intertext{and}\n  ac\\equiv bd \\mod n\\\\\n\\end{align*}\n\\subsubsection*{proof}\nwe prove that $ac\\equiv bd \\mod n$\n\nwe know that $n|(a-b)$ and $n|(c-d)$. write that $a-b=n\\alpha, \\alpha\\in\\mathbb{Z}$ and $c-a=n\\beta, \\beta\\in\\mathbb{Z}$ then $ac-bd=(b+n\\alpha)(d+m\\beta)-bd=$multiple of $n \\Box$\n\n\\item\n$a\\in\\mathbb{Z}, n>1, n\\in\\mathbb{Z}$ then there exist $b\\in\\mathbb{Z}$ such that $ab\\equiv 1 \\mod n$ if and only if $(a,n)=1$ \n\n\\emph{note} $3x+7$ divisible by 11 is like saying $3x\\equiv -7\\equiv4 \\mod 11$. $12x\\equiv-28 \\mod 11$\n\\subsubsection*{proof}\n$\\Rightarrow$\n\nassume $ab\\equiv1\\mod n$ for some $b\\in\\mathbb{Z}$. Then $ab-1=n\\alpha$ for some $\\alpha\\in\\mathbb{Z}$ and $ab+n\\alpha=1\\rightarrow d=(a,b)$ so $d|1\\rightarrow d=1$ \n\n$\\Leftarrow$\n\nassume $(a,n)=1$. there exist $\\alpha,\\beta\\in\\mathbb{Z}$ such that $a\\alpha+n\\beta=1$ and then $a\\alpha\\equiv1\\mod n$\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "329427bf7f31821646699544e168066d089a4b71", "size": 3471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-09-03.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": "abstract algebra/abstract-notes-2014-09-03.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": "abstract algebra/abstract-notes-2014-09-03.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": 33.375, "max_line_length": 203, "alphanum_fraction": 0.6534140017, "num_tokens": 1496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.6310959418583846}}
{"text": "\\subsection{Integers}\n\n\\begin{frame}\n  \\frametitle{Solving \\Lia with \\Lra}\n\n  The Simplex can be used also to reason (in a complete way) about the integers (\\Lia),\n  e.g., using known techniques in linear programming\n  \\vfill\n  Given a set of \\Lia constraints $S$\n  \\begin{itemize}\n    \\item If $S$ is unsatisfiable \n          on \\Lra\\footnote{This means that we allow variables to assume values in \\Rat instead of \\Int.}\n\t  then it is also unsatisfiable on \\Lia\n    \\item If $S$ is satisfiable on \\Lra, then we have to check if there is an integer solution\n  \\end{itemize}\n  \\vfill\\pause\n  For the latter case the convex polytope on \\Rat is explored sistematically. \n  However, in general, search is necessary: \\Lia is NP-Complete, like SAT\n  \\begin{itemize}\n    \\item in SAT we split $a$ and $\\neg a$, in \\Lia we split $x \\leq c$ and $x \\geq c+1$\n    \\item in SAT we learn clauses, in \\Lia we learn new tableau rows (new constraints)\n  \\end{itemize}\n  \\vfill\\pause\n  When on the integers, $\\delta$ is set to $1$ ($\\Rat_\\delta$ numbers are not used)\n\n\\end{frame}\n", "meta": {"hexsha": "cf45f470fbd62949b1d131f32fb46a77cbfed626", "size": 1064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture6/integers.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": "lecture6/integers.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": "lecture6/integers.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": 39.4074074074, "max_line_length": 104, "alphanum_fraction": 0.6973684211, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6310700699143266}}
{"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\\title{Real 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 real numbers, $\\R$, and some related objects.\nIt has been type checked by \\fuzz.\n\\end{abstract}\n\n\\section{Introduction}\n\nThe real numbers, $\\R$, 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 $\\R$ 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{Real Numbers}\n\nZ notation does not predefine the set of real numbers, so we define it here.\n\n\\subsection{\\zcmd{R}}\n\nLet $\\R$ denote the set of real numbers.\nWe define it to be simply a given set.\nWe'll add further axioms as needed below.\n\n\\begin{zed}\n[\\R]\n\\end{zed}\n\n\\subsection{\\zcmd{addR}, \\zcmd{zeroR}, \\zcmd{negR}, and \\zcmd{subR}}\n\nLet $x$ and $y$ be real numbers.\nLet $x \\addR y$ denote addition,\nlet $\\zeroR$ denote zero,\nlet $\\negR x$ denote negation,\nand let $x \\subR y$ denote subtraction.\n\n\\begin{axdef}\n\t\\_ \\addR \\_: \\R \\cross \\R \\fun \\R \\\\\n\t\\zeroR: \\R \\\\\n\t\\negR: \\R \\fun \\R\n\\end{axdef}\n\nAlthough these real number objects are displayed using the same symbols as the corresponding integer objects,\nthey represent 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 objects will, as a rule, be clear from the context.\nVisually distinct symbols will be used in cases where confusion is possible.\n\nThe real numbers form an Abelian group under addition.\n\n\\begin{zed}\n(\\_ \\addR \\_) \\in \\abgroup \\R\n\\also\n\\zeroR = identity\\_element(\\_ \\addR \\_)\n\\also\n\\negR = inverse\\_operation(\\_ \\addR \\_)\n\\end{zed}\n\nSubtraction is defined in terms of addition and negative.\n\n\\begin{axdef}\n\t\\_ \\subR \\_: \\R \\cross \\R \\fun \\R\n\t\\where\n\t\\forall x, y: \\R @ x \\subR y = x \\addR (\\negR y)\n\\end{axdef}\n\n\\subsection{\\zcmd{Rnz}}\n\nLet $\\Rnz$ denote the set of non-zero real numbers,\nalso referred to as the {\\it punctured real number line}.\n\n\\begin{zed}\n\t\\Rnz == \\R \\setminus \\{ \\zeroR \\}\n\\end{zed}\n\n\\subsection{\\zcmd{mulR}}\n\nLet $x$ and $y$ be real numbers.\nLet $x \\mulR y$ denote multiplication.\n\n\\begin{axdef}\n\t\\_ \\mulR \\_: \\R \\cross \\R \\fun \\R\n\\end{axdef}\n\n\\subsection{\\zcmd{mulRnz}, \\zcmd{oneR}, \\zcmd{invRnz}, and \\zcmd{divR}}\n\nLet $(\\_ \\mulRnz \\_)$ denote the restriction of $(\\_ \\mulR \\_)$ to $\\Rnz$.\n\n\\begin{axdef}\n\t\\_ \\mulRnz \\_: \\Rnz \\cross \\Rnz \\fun \\Rnz\n\t\\where\n\t(\\_ \\mulRnz \\_) = (\\lambda x, y: \\Rnz @ x \\mulR y)\n\\end{axdef}\n\nLet $x$ be real number and let $y$ be a non-zero real number.\nlet $\\oneR$ denote one,\nlet $y \\invRnz$ denote inverse,\nand let $x \\divR y$ denote division.\n\n\\begin{axdef}\n\t\\oneR: \\Rnz \\\\\n\t\\_ \\invRnz: \\Rnz \\fun \\Rnz\n\\end{axdef}\n\nThe non-negative real numbers form an Abelian group under multiplication.\n\n\\begin{zed}\n(\\_ \\mulRnz \\_) \\in \\abgroup \\Rnz\n\\also\n\\oneR = identity\\_element(\\_ \\mulRnz \\_)\n\\also\n(\\_ \\invRnz) = inverse\\_operation(\\_ \\mulRnz \\_)\n\\end{zed}\n\nDivision is defined in terms of multiplicative inverse.\n\n\\begin{axdef}\n\t\\_ \\divR \\_: \\R \\cross \\Rnz \\fun \\R\n\t\\where\n\t\\forall x: \\R; y: \\Rnz @ x \\divR y = x \\mulR (y \\invRnz)\n\\end{axdef}\n\nAddition is distributive over multiplication.\n\n\\begin{zed}\n\t\\forall x, y, z: \\R @ (x \\addR y) \\mulR z = x \\mulR z \\addR y \\mulR z\n\\end{zed}\n\n\\subsection{\\zcmd{ltR}, \\zcmd{leR}, \\zcmd{gtR}, and \\zcmd{geR}}\n\nLet $x \\ltR y$, $x \\leR y$, $x \\gtR y$, and $x \\geR y$ denote the usual comparison relations.\n\n\\begin{axdef}\n\t\\_ \\ltR \\_: \\R \\rel \\R \\\\\n\t\\_ \\leR \\_: \\R \\rel \\R \\\\\n\t\\_ \\gtR \\_: \\R \\rel \\R \\\\\n\t\\_ \\geR \\_: \\R \\rel \\R\n\\end{axdef}\n\n\\subsection{\\zcmd{absR}}\n\nLet $\\absR(x)$ denote $\\abs{x}$, the absolute value of $x$.\n\n\\begin{axdef}\n\t\\absR: \\R \\fun \\R\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\absR(x) = \\IF x \\geR \\zeroR \\THEN x \\ELSE \\negR~x\n\\end{axdef}\n\n\\subsection{\\zcmd{Rpos}}\n\nLet $\\Rpos$ denote the set of positive real numbers.\n\n\\begin{zed}\n\t\\Rpos == \\{~ x: \\R | x \\gtR \\zeroR ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{sqrtR}}\n\nFor non-negative $x$, let $\\sqrtR(x)$ denote $\\sqrt{x}$, the non-negative square root of $x$.\n\n\\begin{axdef}\n\t\\sqrtR: \\R \\pfun \\R\n\\where\n\t\\sqrtR = \\{~ x: \\R | x \\geR \\zeroR @ x \\mulR x \\mapsto x ~\\}\n\\end{axdef}\n\n\\section{Open Sets}\n\n\\subsection{\\zcmd{intervalR}}\n\nFor any real numbers $a$ and $b$, let $\\intervalR(a,b)$ denote $(a,b)$, the open interval bounded by $a$ and $b$.\n\n\\begin{axdef}\n\t\\intervalR: \\R \\cross \\R \\fun \\power \\R\n\\where\n\t\\forall a, b: \\R @ \\\\\n\t\\t1\t\\intervalR(a,b) = \\{~ x: \\R | a \\ltR x \\ltR b ~\\}\n\\end{axdef}\n\n\\begin{remark}\nIf $a \\geR b$ then $\\intervalR(a,b) = \\emptyset$.\n\\end{remark}\n\n\\subsection{\\zcmd{ballR}}\n\nFor any real numbers $x$ and $r$, let $\\ballR(x,r)$ denote the set of all real numbers within distance $r$ of $x$.\n\n\\begin{axdef}\n\t\\ballR: \\R \\cross \\R \\fun \\power \\R\n\\where\n\t\\forall x, r: \\R @ \\\\\n\t\\t1\t\\ballR(x,r) = \\{~ x': \\R | \\absR(x' \\subR x) \\ltR r ~\\}\n\\end{axdef}\n\n\\begin{remark}\nBalls are intervals.\n\n\\begin{zed}\n\t\\forall x, r: \\R @ \\\\\n\t\\t1\t\\ballR(x,r) = \\intervalR(x \\subR r, x \\addR r)\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nIf $r \\gtR 0$ then $x$ is in $\\ballR(x, r)$. \n\n\\begin{zed}\n\t\\forall x: \\R; r: \\Rpos @ \\\\\n\t\\t1\tx \\in \\ballR(x,r)\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nIf $r \\leR 0$ then $\\ballR(x,r)$ is empty.\n\n\\begin{zed}\n\t\\forall x, r: \\R | r \\leR \\zeroR @ \\\\\n\t\\t1\t\\ballR(x,r) = \\emptyset\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{\\zcmd{ballsR}}\n\nLet $\\ballsR$ denote the set of all open balls in $\\R$.\n\n\\begin{axdef}\n\t\\ballsR: \\family~\\R\n\\where\n\t\\ballsR = \\{~ x, r: \\R @ \\ballR(x,r) ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{openR}}\n\nA subset $U$ of $\\R$ is said to be {\\it open} if every point $x \\in U$ is surrounded by some open ball $B \\subset U$ that lies\nstrictly within $U$.\nLet $\\openR$ denote the set of all open subsets of $\\R$.\n\n\\begin{axdef}\n\t\\openR: \\family~\\R\n\\where\n\t\\openR = \\\\\n\t\\t1\t\\{~ U:  \\power \\R | \\\\\n\t\\t2\t\t\\forall x: U @ \\\\\n\t\\t3\t\t\t\\exists B: \\ballsR @ x \\in B \\subset U ~\\}\n\\end{axdef}\n\n\\begin{remark}\nAll balls are open.\n\n\\begin{zed}\n\t\\ballsR \\subset \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe empty set is open.\n\n\\begin{zed}\n\t\\emptyset \\in \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe set of all real numbers is open.\n\n\\begin{zed}\n\t\\R \\in \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{\\zcmd{tauR}}\n\nThe topology generated by the open balls of $\\R$ is referred to as the {\\it usual} or {\\it standard} topology on $\\R$ .\nLet $\\tauR$ denote the usual topology on $\\R$.\n\n\\begin{axdef}\n\t\\tauR: top[\\R]\n\\where\n\t\\tauR = topGen[\\R] \\ballsR\n\\end{axdef}\n\n\\begin{remark}\n\n\\begin{zed}\n\t\\tauR = \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{\\zcmd{Rtau}}\n\nLet $\\Rtau$ denote the topological space defined by $\\R$ with the usual topology.\n\n\\begin{axdef}\n\t\\Rtau: topSpaces[\\R]\n\\where\n\t\\Rtau = (\\R, \\tauR)\n\\end{axdef}\n\n\\begin{example}\n\n\\begin{zed}\n\t\\Rtau \\in topSpace[\\R]\n\\end{zed}\n\n\\end{example}\n\n\\subsection{\\zcmd{neighR}}\n\nLet $x$ be a real number.\nAny open set that contains $x$ is called a {\\it neighbourhood} of it.\nLet $\\neighR(x)$ denote the set of all neighbourhoods of $x$.\n\n\\begin{axdef}\n\t\\neighR: \\R \\fun \\family~\\R\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\neighR(x) = \\{~ U: \\openR | x \\in U~\\}\n\\end{axdef}\n\nClearly, every real number has an infinity of neighbourhoods.\n\n\\begin{remark}\nAny open ball that contains $x$ is a neighbourhood of $x$.\n\n\\begin{zed}\n\t\\forall x: \\R; B: \\ballsR | \\\\\n\t\\t1\tx \\in B @ \\\\\n\t\\t2\t\tB \\in \\neighR(x)\n\\end{zed}\n\n\\end{remark}\n\n\\section{Functions}\n\nThe following sections define continuity, limits, and differentiability, which are point-wise properties of functions.\nThese properties are {\\it local} in the sense that in order to determine if they hold at a given point it is sufficient to\nconsider the restriction of the function to an arbitrarily small neighbourhood of the point.\nIt is therefore useful to first introduce the set of {\\it locally defined} functions, \nnamely those functions that are defined in some neighbourhood of each point of  their domains.\n\n\\subsection{\\zcmd{FunR}}\n\nFor $x$ a real number,\nlet $\\FunR(x)$ denote the set of all real-valued, partial functions on $\\R$ that are locally defined at $x$.\n\n\\begin{axdef}\n\t\\FunR: \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\FunR(x) = \\{~ f: \\R \\pfun \\R | \\exists U: \\neighR(x) @ U \\subseteq \\dom f ~\\}\n\\end{axdef}\n\n\\begin{remark}\nThe function $\\sqrtR$ is not locally defined at $0$ because it's defined only for non-negative numbers,\nbut every neighbourhood of $0$ contains some negative numbers.\n\n\\begin{zed}\n\t\\sqrtR \\notin \\FunR(\\zeroR)\n\\end{zed}\n\n\\end{remark}\n\n\\subsection{\\zcmd{FunPR}}\n\nFor $U$ a subset of $\\R$,\nlet $\\FunPR(U)$ denote the set of all real-valued functions on $U$ that are locally defined at each point of $U$.\n\n\\begin{axdef}\n\t\\FunPR: \\power \\R \\fun \\power (\\R \\pfun \\R)\n\\where\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\FunPR(U) = \\{~ f: U \\fun \\R | \\forall x: U @ f \\in \\FunR(x) ~\\}\n\\end{axdef}\n\n\\begin{remark}\nIf $f \\in \\FunPR(U)$ then $U \\in \\openR$.\n\n\\begin{zed}\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\FunPR(U) \\neq \\emptyset \\implies U \\in \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\section{Continuity}\n\nLet $f$ be a real-valued partial function on $\\R$ \nthat is locally defined at $x$ and let $U$ be a neighbourhood of $x$\ncontained within the domain of $f$.\nThe function $f$ is said to be {\\it continuous} at $x$ if \nfor any $\\epsilon > 0$ there is some $\\delta > 0$ for which \n$f(x')$ is always within $\\epsilon$ of $f(x)$\nwhen $x' \\in U$ is within $\\delta$ of $x$.\n\\begin{argue}\n\\forall \\epsilon > 0 @ \\exists \\delta > 0 @ \\forall x' \\in U @ \\\\\n\\t1\t\\abs{x' - x} < \\delta \\implies \\abs{f(x') - f(x)} < \\epsilon\n\\end{argue}\n\n\\begin{schema}{RealContinuous}\n\tf: \\R \\pfun \\R \\\\\n\tx: \\R\n\\where\n\tf \\in \\FunR(x)\n\\also\n\t\\forall \\epsilon: \\Rpos @ \\exists \\delta: \\Rpos@ \\forall x': \\dom f @ \\\\\n\t\\t1\t\\absR(x' \\subR x) \\ltR \\delta \\implies \\absR(f(x') \\subR f(x)) \\ltR \\epsilon\n\\end{schema}\n\n\\subsection{\\zcmd{CzeroR}}\n\nLet $\\CzeroR(x)$ denote the set of all real-valued partial functions on $\\R$ that are continuous at $x$.\n\\begin{axdef}\n\t\\CzeroR: \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\CzeroR(x) = \\{~ f: \\FunR(x) | RealContinuous ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{CzeroPR}}\n\nLet $U$ be any subset of $\\R$. \nDefine $\\CzeroPR(U)$ to be the set of all real-valued functions on $U$ that are continuous at each point in $U$.\n\n\\begin{axdef}\n\t\\CzeroPR: \\power \\R \\fun \\power (\\R \\pfun \\R)\n\\where\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\CzeroPR(U) = \\{~ f: \\FunPR(U) | \\forall x: U @ f \\in   \\CzeroR(x) ~\\}\n\\end{axdef}\n\n\\begin{remark}\nIf $f \\in \\CzeroPR(U)$ then $U$ is open.\n\n\\begin{zed}\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\CzeroPR(U) \\neq \\emptyset \\implies U \\in \\openR\n\\end{zed}\n\n\\end{remark}\n\n\\begin{remark}\nThe $\\epsilon-\\delta$ definition of continuity given above is compatible with the definition\nof continuity for mappings between topological spaces when we consider $\\Rtau$, the usual topology on $\\R$,\nand $\\Rtau \\inducedTopSp U$, the topology induced on the subset $U$.\n\n\\begin{zed}\n\t\\forall U: \\openR @ \\\\\n\t\\t1\t\\CzeroPR(U) = \\CzeroTT(\\Rtau \\inducedTopSp U, \\Rtau)\n\\end{zed}\n\n\\end{remark}\n\n\\section{Limits}\n\nLet $x$ and $l$ be real numbers and\nlet $f$ be a real-valued partial function on $\\R$ that is defined everywhere in some\nneighbourhood $U$ of $x$, except possibly at $x$.\nThe function $f$ is said to approach the limit $l$ at $x$ if $f \\oplus \\{ x \\mapsto l \\}$ is continuous at $x$.\n$$\n\t\\lim_{x' \\to x}{f(x')} = l\n$$\n\n\\begin{schema}{Limit}\n\tf: \\R \\pfun \\R \\\\\n\tx, l: \\R\n\\where\n\tf \\oplus \\{x \\mapsto l\\} \\in \\CzeroR(x)\n\\end{schema}\n\n\\subsection{\\zcmd{limRR}}\n\nLet $\\limRR(x,l)$ denote the set of all real-valued partial functions on $\\R$ that approach the limit $l$ at $x$.\n\n\\begin{axdef}\n\t\\limRR: \\R \\cross \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x, l: \\R @ \\\\\n\t\\t1\t\\limRR(x,l) = \\{~ f: \\R \\pfun \\R | Limit ~\\}\n\\end{axdef}\n\n\\begin{theorem}\nIf a function $f$ approaches some limit at $x$ then that limit is unique.\n\\begin{zed}\n\t\\forall x, l, l': \\R @ \\\\\n\t\\t1\t\\forall f : \\limRR(x,l) \\cap \\limRR(x,l') @ \\\\\n\t\\t2\t\tl = l'\n\\end{zed}\n\\end{theorem}\n\n\\begin{proof}\nSuppose we are given real numbers\n\\begin{argue}\n\tx, l, l' \\in \\R \n\\end{argue}\nand a function\n\\begin{argue}\n\tf \\in \\limRR(x,l) \\cap \\limRR(x,l')\n\\end{argue}\nLet $\\epsilon$ be any positive real number\n\\begin{argue}\n\t\\epsilon > 0\n\\end{argue}\nSince $f$ approaches limits $l$ and $l'$ at $x$ there exists a real number $\\delta > 0$ such that\n\\begin{argue}\n\t\\forall x' \\in \\R |  \\\\\n\t\\t1\t\\zeroR \\ltR \\abs{x' \\subR x}< \\delta @ \\\\\n\t\\t2\t\t \\abs{f(x') - l} < \\epsilon \\land \\abs{f(x') - l'} < \\epsilon\n\\end{argue}\nFor any such real number $x'$ we have\n\\begin{argue}\n\t\\abs{l' - l} \\\\\n\t\\t1\t= \\abs{(f(x') - l) - (f(x') - l')} \t\t\t& add and subtract $f(x')$ \\\\\n\t\\t1\t\\leq \\abs{f(x') - l} + \\abs{f(x') - l'} \t& triangle inequality \\\\\n\t\\t1\t= 2\\epsilon\t\t\t\t\t& definition of limits\n\\end{argue}\nSince the above holds for any $\\epsilon > 0$ we must have\n\\begin{argue}\n\tl = l'\n\\end{argue}\n\n\\end{proof}\n\n\\subsection{\\zcmd{limFR}}\n\nIf $f$ approaches the limit $l$ at $x$ then let $\\limFR(f,x)$ denote $l$.\nBy the preceding theorem, $\\limFR(f,x)$ is well-defined when it exists.\n\n\\begin{axdef}\n\t\\limFR: (\\R \\pfun \\R) \\cross \\R \\pfun \\R\n\\where\n\t\\limFR = \\{~ Limit @ (f, x) \\mapsto l ~\\}\n\\end{axdef}\n\n\\section{Differentiability}\n\nLet $f$ be a real-valued partial function on $\\R$, let $x$ be a real number,\nand let $f$ be defined on some neighbourhood $U$ of $x$.\n\nThe function $f$ is said to be {\\it differentiable} at $x$ if the following limit holds for some number denoted by $f'(x)$.\n$$\n\\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h} = f'(x)\n$$\n\n\\begin{remark}\nIf $f$ is differentiable at $x$ then $f$ is continuous at $x$.\n\\end{remark}\n\nThe geometric intuition behind the concept of differentiability is that $f$ is differentiable at $x$\nwhen, very near $x$, the graph of $f$ is approximately a straight line through the point $(x, f(x))$ with slope $f'(x)$.\n$$\nf(x + h) \\approx f(x) + f'(x) h \\quad \\text{when} \\quad \\abs{h} \\approx 0\n$$\nThe slope $f'(x)$ is called the {\\it derivative} of $f$ at $x$\nand $f'$ is called the {\\it derived function}.\n\nWe can read this definition as saying that the approximate slope function $m(h)$ defined for \nsmall enough, non-zero values of $h$ by\n$$\n\tm(h) = \\frac{f(x + h) - f(x)}{h}\n$$\napproaches the limit $l = f'(x)$ as $h \\to 0$.\n$$\n\t\\lim_{h\\to 0}{m(h)} = l = f'(x)\n$$\n\n\\begin{schema}{Differentiable}\n\tf: \\R \\pfun \\R \\\\\n\tx, l: \\R\n\\where\n\tf \\in \\CzeroR(x)\n\\also\n\t\\LET m == (\\lambda h: \\Rnz | x \\addR h \\in \\dom f @ (f(x \\addR h) \\subR f(x)) \\divR h) @ \\\\\n\t\\t1\t\\limFR(m, \\zeroR) = l\n\\end{schema}\n\n\\begin{remark}\nIf $f$ is differentiable at $x$ then the limit $l$ is unique.\n\\end{remark}\n\n\\subsection{\\zcmd{diffRR}}\n\nLet $\\diffRR(x,l)$ denote the set of all functions $f$ that are differentiable at $x$ with $f'(x) = l$.\n\n\\begin{axdef}\n\t\\diffRR: \\R \\cross \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x, l: \\R @ \\\\\n\t\\t1\t\\diffRR(x, l) = \\{~ f: \\R \\pfun \\R | Differentiable ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{diffR}}\n\nLet $\\diffR(x)$ denote the set of all functions that are differentiable at $x$.\n\n\\begin{axdef}\n\t\\diffR: \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\diffR(x) = \\bigcup \\{~ l: \\R @ \\diffRR(x,l) ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{diffPR}}\n\nLet $U$ be any subset of $\\R$. \nLet $\\diffPR(U)$ denote the set of all functions on $U$\nthat are differentiable at each point of $U$.\n\n\\begin{axdef}\n\t\\diffPR: \\power \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\diffPR(U) = \\{~ f: \\CzeroPR(U) | \\forall x: U @ f \\in \\diffR(x) ~\\}\n\\end{axdef}\n\n\\section{Derivatives}\n\n\\subsection{\\zcmd{derivFR}}\n\nLet $\\derivFR(f,x)$ denote $f'(x)$, the derivative of $f$ at $x$.\n\n\\begin{axdef}\n\t\\derivFR: (\\R \\pfun \\R) \\cross \\R \\pfun \\R\n\\where\n\t\\derivFR = \\{~ Differentiable @ (f,x) \\mapsto l ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{derivF}}\n\nLet $\\derivF(f)$ denote $f'$, the derived function.\n\n\\begin{axdef}\n\t\\derivF: (\\R \\pfun \\R) \\fun (\\R \\pfun \\R)\n\\where\n\t\\forall f: \\R \\pfun \\R @ \\\\\n\t\t\\t1\t\\derivF f = (\\lambda x: \\R | f \\in \\diffR(x) @ \\derivFR(f,x)) \n\\end{axdef}\n\n\\begin{remark}\nIf $f$ is differentiable on $U$ then $f'$ is not necessarily continuous on $U$.\nCounterexamples exist.\n\\end{remark}\n\n\\begin{remark}\nIf $f$ is uniformly differentiable on $U$ then $f'$ is continuous on $U$.\nA further discussion of uniform differentiability is beyond the scope of this article.\n\\end{remark}\n\n\\section{Higher Order Derivatives}\n\nLet $n$ be a natural number and let $x$ be a real number.\nIn differential geometry we normally deal with $C^n(x)$, the set of functions\nthat possess continuous derivatives of order $0, \\ldots, n$ at $x$.\n\n\\subsection{\\zcmd{CnR}}\n\nLet $\\CnR(n,x)$ denote the set of all functions that have continuous derivatives of order $0, \\ldots, n$ at $x$.\n\n\\begin{axdef}\n\t\\CnR: \\nat \\cross \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\CnR(0,x) = \\CzeroR(x)\n\\also\n\t\\forall n: \\nat; x: \\R @ \\\\\n\t\\t1\t\\CnR(n + 1, x) = \\{~ f: \\diffR(x) | \\derivF f \\in \\CnR(n,x) ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{CnPR}}\n\nLet $n$ be a natural number and let $U$ be a subset of $\\R$.\nLet $\\CnPR(n,U)$ denote the set of all functions on $U$ that have continuous derivatives of order $0, \\ldots, n$\nat every point of $U$.\n\n\\begin{axdef}\n\t\\CnPR: \\nat \\cross \\power \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall n: \\nat; U: \\power \\R @ \\\\\n\t\\t1\t\\CnPR(n,U) = \\{~ f: \\FunPR(U) | \\forall x: U @ f \\in \\CnR(n,x) ~\\}\n\\end{axdef}\n\n\\section{Smoothness}\n\n\\subsection{\\zcmd{smoothR}}\n\nA function is said to be {\\it smooth} if it possesses continuous derivatives of all orders.\nLet $x$ be a real number.\nLet $\\smoothR(x)$ denote the set of all functions that are smooth at $x$.\n\n\\begin{axdef}\n\t\\smoothR: \\R \\fun \\power(\\R \\pfun \\R)\n\\where\n\t\\forall x: \\R @ \\\\\n\t\\t1\t\\smoothR(x) = \\{~ f: \\FunR(x) | \\forall n: \\nat @ f \\in \\CnR(n, x) ~\\}\n\\end{axdef}\n\n\\subsection{\\zcmd{smoothPR}}\n\nLet $\\smoothPR(U)$ denote the set of all functions on $U$ that are smooth at every point of $U$.\n\n\\begin{axdef}\n\t\\smoothPR: \\power \\R \\fun \\power (\\R \\pfun \\R)\n\\where\n\t\\forall U: \\power \\R @ \\\\\n\t\\t1\t\\smoothPR(U) = \\{~ f: \\FunPR(U) | \\forall x: U @ f \\in \\smoothR(x) ~\\}\n\\end{axdef}\n\n\\section{Important Constants and Functions}\n\nThis section defines several important constants and functions.\n\n\\subsection{$integer\\_as\\_real$}\n\nThe real numbers contains a natural copy of the integers.\nLet $integer\\_as\\_real$ denote this embedding.\n\n\\begin{axdef}\n\tinteger\\_as\\_real : \\num \\inj \\R\n\\end{axdef}\n\n\\subsection{\\zcmd{realZ}}\n\nWe introduce the notation $\\realZ x = integer\\_as\\_real~x$ for this embedding.\n\n\\begin{zed}\n\t\\realZ == integer\\_as\\_real\n\\end{zed}\n\nThe real numbers $\\zeroR$ and $\\oneR$ are the images of the corresponding integers under this\nembedding.\n\n\\begin{zed}\n\t\\realZ 0 = \\zeroR\n\\also\n\t\\realZ 1 = \\oneR\n\\end{zed}\n\n\\subsection{$IntegerTimesReal$}\n\nWe can use the embedding to define the product $y = n * x$ where $n$ is an integer\nand $x$ and $y$ are real numbers.\n\n\\begin{schema}{IntegerTimesReal}\n\tn : \\num \\\\\n\tx, y : \\R\n\\where\n\ty = (\\realZ n) \\mulR x\n\\end{schema}\n\n\\subsection{$integer\\_times\\_real$}\n\nLet $y = integer\\_times\\_real(n, y)$ denote this multiplication operation.\n\n\\begin{zed}\n\tinteger\\_times\\_real == \\{~ IntegerTimesReal @ (n, x) \\mapsto y ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{mulZR}}\n\nWe introduce the notation $n \\mulZR x = integer\\_times\\_real(n, x)$.\n\n\\begin{zed}\n\t(\\_ \\mulZR \\_) == integer\\_times\\_real\n\\end{zed}\n\n\\subsection{$RealDivInteger$}\n\nSimilarly, we can define division of a real number $x$ by a nonzero integer $n$\nto give the quotient $y = x / n$.\n\n\\begin{schema}{RealDivInteger}\n\tn : \\num \\\\\n\tx, y : \\R\n\\where\n\tn \\neq 0\n\\also\n\ty = x \\divR (\\realZ n)\n\\end{schema}\n\n\\subsection{$real\\_div\\_integer$}\n\nLet $y = real\\_div\\_integer(x, n)$ denote this division operation.\n\n\\begin{zed}\n\treal\\_div\\_integer == \\{~ RealDivInteger @ (x, n) \\mapsto y ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{divRZ}}\n\nWe introduce the notation $y = x \\divRZ n$.\n\n\\begin{zed}\n\t(\\_ \\divRZ \\_) == real\\_div\\_integer\n\\end{zed}\n\n\\subsection{\\zcmd{sinR}}\n\nLet $\\sinR(x)$ denote the usual trigonometric sine function of the real number $x$.\n\n\\begin{axdef}\n\t\\sinR : \\R \\fun \\R\n\\end{axdef}\n\n\\subsection{\\zcmd{cosR}}\n\nLet $\\cosR(x)$ denote the usual trigonometric cosine function of the real number $x$.\n\n\\begin{axdef}\n\t\\cosR : \\R \\fun \\R\n\\end{axdef}\n\n\\subsection{\\zcmd{piR}}\n\nLet $\\piR$ denote the usual ratio of the perimeter of a circle to its diameter.\n\n\\begin{axdef}\n\t\\piR : \\R\n\\end{axdef}\n\n\\section{The Real Plane}\n\nIn order to define what it means for an arrangement of test tubes to be balanced,\nwe need to use some concepts from Euclidean geometry and classical mechanics.\nClassical mechanics is phrased in terms of real coordinate systems.\nWe therefore start by defining the usual real plane and its coordinates.\n\n\\subsection{\\zcmd{Rtwo}}\n\nWe model the real plane as pairs of real numbers.\nLet $\\Rtwo$ denote the real plane.\n\n\\begin{zed}\n\t\\Rtwo == \\R \\cross \\R\n\\end{zed}\n\n\\subsection{$zero\\_real\\_plane$}\n\nLet the point $zero\\_real\\_plane \\in \\Rtwo$ denote the origin of the real plane.\n\n\\begin{zed}\n\tzero\\_real\\_plane == (\\zeroR, \\zeroR)\n\\end{zed}\n\n\\subsection{\\zcmd{zeroRtwo}}\n\nWe introduce the usual notation $\\zeroRtwo = zero\\_real\\_plane$ for the origin of the real plane.\n\n\\begin{zed}\n\t\\zeroRtwo == zero\\_real\\_plane\n\\end{zed}\n\n\\subsection{$RealPlane$}\n\nLet $point \\in \\Rtwo$ be a point in the real plane.\nIts Cartesian coordinates are denoted by $x$ and $y$.\nLet the schema $RealPlane$ denote this situation.\n\n\\begin{schema}{RealPlane}\n\tpoint: \\Rtwo \\\\\n\tx, y : \\R\n\\where\n\tpoint = (x, y)\n\\end{schema}\n\n\\subsection{$ScaleRealPlane$}\n\nLet $a \\in \\R$ be a scaling factor and let $point \\in \\Rtwo$ be a point.\nLet $point' = a * point$ be  $point$ scaled by $a$.\nLet the schema $ScaleRealPlane$ denote this situation.\n\n\\begin{schema}{ScaleRealPlane}\n\ta : \\R \\\\\n\tRealPlane \\\\\n\tRealPlane'\n\\where\n\tx' = a \\mulR x\n\\also\n\ty' = a \\mulR x\n\\end{schema}\n\n\\subsection{$scale\\_real\\_plane$}\n\nLet $point' = scale\\_real\\_plane(a, point)$ denote the operation of scalar multiplication.\n\n\\begin{zed}\n\tscale\\_real\\_plane == \\{~ ScaleRealPlane @ (a, point) \\mapsto point' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{smulRtwo}}\n\nWe introduce the notation $a \\smulRtwo point = scale\\_real\\_plane(a, point)$\nfor scalar multiplication.\n\n\\begin{zed}\n\t(\\_ \\smulRtwo \\_) == scale\\_real\\_plane\n\\end{zed}\n\n\\subsection{$ScaleIntRealPlane$}\n\nIt is convenient to allow scaling of points in the real plane by integers.\nLet $n \\in \\num$ be a scaling factor and let $point \\in \\Rtwo$ be a point.\nLet $point' = n * point$ be  $point$ scaled by $n$.\nLet the schema $ScaleIntRealPlane$ denote this situation.\n\n\\begin{schema}{ScaleIntRealPlane}\n\tn : \\num \\\\\n\tRealPlane \\\\\n\tRealPlane'\n\\where\n\tx' = n \\mulZR x\n\\also\n\ty' = n \\mulZR x\n\\end{schema}\n\n\\subsection{$scale\\_int\\_real\\_plane$}\n\nLet $point' = scale\\_int\\_real\\_plane(n, point)$ denote the operation of scalar multiplication\nby an integer.\n\n\\begin{zed}\n\tscale\\_int\\_real\\_plane == \\{~ ScaleIntRealPlane @ (n, point) \\mapsto point' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{smulZRtwo}}\n\nWe introduce the notation $n \\smulZRtwo point = scale\\_int\\_real\\_plane(n, point)$\nfor scalar multiplication.\n\n\\begin{zed}\n\t(\\_ \\smulZRtwo \\_) == scale\\_int\\_real\\_plane\n\\end{zed}\n\n\\subsection{$AddRealPlane$}\n\nLet $point_1$ and $point_2$ be points.\nWe can define their sum $point' = point_1 + point_2$ by component-wise addition.\nLet the schema $AddRealPlane$ denote this situation.\n\n\\begin{schema}{AddRealPlane}\n\tRealPlane_1 \\\\\n\tRealPlane_2 \\\\\n\tRealPlane'\n\\where\n\tx' = x_1 \\addR x_2\n\\also\n\ty' = y_1 \\addR y_2\n\\end{schema}\n\n\\subsection{$add\\_real\\_plane$}\n\nLet $add\\_real\\_plane(point_1, point_2) = point_1 + point_2$ denote addition of points in the\nreal plane.\n\n\\begin{zed}\n\tadd\\_real\\_plane == \\{~ AddRealPlane @ (point_1, point_2) \\mapsto point' ~\\}\n\\end{zed}\n\n\\subsection{\\zcmd{addRtwo}}\n\nWe introduce the usual notation $point_1 \\addRtwo point_2 = add\\_real\\_plane(point_1, point_2)$\nto denote addition of points in the real plane.\n\n\\begin{zed}\n\t(\\_ \\addRtwo \\_) == add\\_real\\_plane\n\\end{zed}\n\n\\subsection{$sum\\_real\\_plane$}\n\nGiven a sequence $a$ of zero or more points in the real plane,\nwe define its sum $sum\\_real\\_plane(a)$ recursively as follows.\n\n\\begin{axdef}\n\tsum\\_real\\_plane : \\seq \\Rtwo \\fun \\Rtwo\n\\where\n\tsum\\_real\\_plane(\\langle \\rangle) = \\zeroRtwo\n\\also\n\t\\forall point : \\Rtwo; a : \\seq \\Rtwo @ \\\\\n\t\\t1\tsum\\_real\\_plane(\\langle point \\rangle \\cat a) = point \\addRtwo sum\\_real\\_plane(a)\n\\end{axdef}\n\n\\subsection{\\zcmd{sumRtwo}}\n\nWe introduce the notation $\\sumRtwo(a) = sum\\_real\\_plane(a)$.\n\n\\begin{zed}\n\t\\sumRtwo == sum\\_real\\_plane\n\\end{zed}\n\n\\subsection{\\zcmd{addFRtwo}}\n\nLet $\\genT$ be any set and let $f$ and $g$ be partial functions from $\\genT$ to $\\Rtwo$.\nLet $h(x) = f(x) + g(x)$ denote their pointwise sum on their common domain of definition.\nLet the schema $AddFunctionsRealPlane$ denote this situation.\n\n\\begin{schema}{AddFunctionsRealPlane}[\\genT]\n\tf, g, h : \\genT \\pfun \\Rtwo\n\\where\n\th = (\\lambda x : \\dom f \\cap \\dom g @ f~x \\addRtwo g~x)\n\\end{schema}\n\nLet the function $add\\_functions\\_real\\_plane(f, g) = h$ map two functions with values in $\\Rtwo$ to their pointwise sum.\n\n\\begin{gendef}[\\genT]\n\tadd\\_functions\\_real\\_plane : (\\genT \\pfun \\Rtwo) \\cross (\\genT \\pfun \\Rtwo) \\fun (\\genT \\pfun \\Rtwo)\n\\where\n\tadd\\_functions\\_real\\_plane = \\\\\n\t\\t1\t\\{~ AddFunctionsRealPlane[\\genT] @ (f, g) \\mapsto h ~\\}\n\\end{gendef}\n\nWe introduce the notation $f \\addFRtwo g = add\\_functions\\_real\\_plane(f, g)$.\n\n\\begin{zed}\n\t(\\_ \\addFRtwo \\_)[\\genT] == add\\_functions\\_real\\_plane[\\genT]\n\\end{zed}\n\n\n\\subsection{$PolarRealPlane$}\n\nLet $(x, y)$ be the Cartesian coordinates of a point in the plane.\nLet $r$ denote the distance of the point from the origin and\nlet $a$ denote the counter-clockwise angle of the point from the $x$-axis.\nThe pair $(r, a)$ is called the \\textit{polar coordinates} of the point.\nConversely, given an pair $(r, a)$ we can compute the corresponding\nCartesian coordinates.\nLet the schema $PolarRealPlane$ denote this situation.\n\n\\begin{schema}{PolarRealPlane}\n\tRealPlane \\\\\n\tr, a : \\R\n\\where\n\tx = r \\mulR \\cosR a\n\\also\n\ty = r \\mulR \\sinR a\n\\end{schema}\n\n\\subsection{$polar\\_to\\_cartesian$}\n\nLet the function $polar\\_to\\_cartesian(r, a) = (x, y)$ denote the mapping from\npolar to Cartesian coordinates.\n\n\\begin{zed}\n\tpolar\\_to\\_cartesian == \\{~ PolarRealPlane @ (r, a) \\mapsto (x, y) ~\\}\n\\end{zed}\n\nNote that this function is not one-to-one for the following reasons.\n\\begin{itemize}\n\t\\item The pairs $(r, a + 2k\\pi)$ for any $k \\in \\num$ map to the same points.\n\t\\item The pairs $(r, a)$ and $(-r, a + \\pi)$ map to the same points.\n\t\\item The pairs $(0, a)$ and $(0, a')$ map to the same points.\n\\end{itemize}\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "fe1a7e59147ad738d65344e3f51641fb4fe2ddc9", "size": 27382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "articles/real-numbers/real-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/real-numbers/real-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/real-numbers/real-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": 25.3302497687, "max_line_length": 140, "alphanum_fraction": 0.6637206924, "num_tokens": 9600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6310411838993156}}
{"text": "%\n% CMPT 379: Principles of Compiler Design - A Course Overview\n% Section: Syntax Analysis (Parsing)\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Syntax Analysis (Parsing)}\n\t\\label{sec:syntax-analysis}\n\\begin{easylist}\n\n& \\textbf{Syntax analysis (parsing):} Translation of a set of strings into a valid structure using a grammar\n\t&& \\textbf{Language:} Description of a valid string of tokens\n\n& Symbols and rules:\n\t&& \\textbf{Terminal symbol:} Token or base symbol which does not represent any other symbols\n\t&& \\textbf{Non-terminal symbol:} Set of strings potentially consisting of one or more terminal or non-terminal symbols\n\t&& \\textbf{Production/Rule/Production rule:} Function on a non-terminal symbol which generates a sequence of terminal and/or non-terminal symbols\n\t\t&&& \\textbf{Expansion:} Sequence of symbols resulting from the application of a production rule\n\n\\end{easylist}\n\\subsection{Context-Free Grammars}\n\t\\label{subsec:syntax-analysis:context-free-grammars}\n\\begin{easylist}\n\n& \\textbf{Context-Free Grammar (CFG):} Recursive notation for the structure of a valid syntax; subset of regular grammars\n\t&& Generates a \\textit{Context-Free Language (CFL)}\n\t&& Defined by a set of non-terminal states $N$, a start state $S \\in N$, a set of terminal states $T$, and a set of productions to create a set of states\n\t\t&&& Each state is a string consisting of non-terminal and/or terminal symbols\n\t\t&&& If multiple productions exist from the start state, then in order to backtrack from a terminal state to the start state, create a new start state $S'$ which has a single production to the original state state\n\t\t&&& Productions can be implemented using a transition matrix\n\t&& E.g. Given grammar $\\bigg\\{ (^i)^i | i \\geq 0 \\bigg\\}$ (i.e. The number of opening brackets must match the number of closing brackets) the productions are:\n\t\t&&& $S \\rightarrow \\epsilon$\n\t\t&&& $S \\rightarrow (S)$\n\t\t&&& $N = \\{ S \\}$\n\t\t&&& $T = \\big\\{ (, ) \\big\\}$\n\t&& E.g. Given language $\\bigg\\{ wcw^R | w \\in (a|b)* \\bigg\\}$, a CFG which produces this language is $S \\rightarrow aSa | bSb | c$\n\t&& E.g. Given language $\\bigg\\{ a^n b^m c^m d^n | n \\geq 1, m \\geq 1 \\bigg\\}$, a CFG which produces this language is $S \\rightarrow aSd | aAd; A \\rightarrow bAc | bc$\n\t&& \\textbf{Ambiguous:} CFG which can produce multiple unique parse trees\n\t\t&&& Unacceptable for programming languages\n\t\t&&& Prevention techniques:\n\t\t\t&&&& Rewriting grammar unambiguously\n\t\t\t&&&& Separating non-terminal states by different precedence levels\n\t\t\t\t&&&&& E.g. $E \\rightarrow E - E; E \\rightarrow T; T \\rightarrow T / T$\n\t\t\t\t&&&&& E.g. $A \\rightarrow A - B; A \\rightarrow B$\n\t\t\t&&&& \\textbf{Left/Right associative:} Property of an operator specifying which of multiple operations with the same precedence should be evaluated first\n\t&& \\textbf{Recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols including $X$\n\t\t&&& \\textbf{Left recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols which begins with $X$\n\t\t&&& \\textbf{Right recursive in non-terminal $X$:} CFG where, in one or more productions, $X$ can derive a sequence of symbols which ends with $X$\n\n\\end{easylist}\n\\subsection{Parsing}\n\t\\label{subsec:syntax-analysis:parsing}\n\\begin{easylist}\n\n& \\textbf{Parse tree:} Tree-shaped sequence of CFG productions used to generate a valid derivation of symbols, with the root being the start symbol and children being productions of the parent (i.e. for a given production $X \\rightarrow Y_1 \\dotsc Y_n$, the children of $X$ are $Y_1 \\dotsc Y_n$)\n\t&& \\textbf{Leftmost derivation:} Sequence of CFG productions to create a parse tree by continually processing the leftmost non-terminal state\n\t&& \\textbf{Rightmost derivation:} Sequence of CFG productions to create a parse tree by continually processing the rightmost non-terminal state\n\t&& E.g. For the production rules in table~\\ref{tab:parse-tree-example-1-prod-rules}, the parse tree of $id + id * id$ is shown in figure~\\ref{fig:parse-tree-example-1}\n\t&& E.g. For the production rules in table~\\ref{tab:parse-tree-example-2-prod-rules}, the parse tree of $id + id * id$ is shown in figure~\\ref{fig:parse-tree-example-2}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Parse Tree Example 1: Production Rules}\n\t\\label{tab:parse-tree-example-1-prod-rules}\n\t\\begin{center}\n\t\t\\begin{tabular}{ l }\n\t\t\t$E \\rightarrow E + E$ \\\\\n\t\t\t$E \\rightarrow E * E$ \\\\\n\t\t\t$E \\rightarrow id$\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{figure}\n\\begin{easylist}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Parse Tree Example 1}\n\t\\label{fig:parse-tree-example-1}\n\t\\begin{center}\n\t\tString: $id + id * id$ \\\\[1em]\n\t\t\\begin{forest}\n\t\t\t[$E$\n\t\t\t\t[$E$\n\t\t\t\t\t[$E$[$id$]]\n\t\t\t\t\t[$+$]\n\t\t\t\t\t[$E$[$id$]]\n\t\t\t\t]\n\t\t\t\t[$*$]\n\t\t\t\t[$E$\n\t\t\t\t\t[$id$]\n\t\t\t\t]\n\t\t\t]\n\t\t\\end{forest}\n\t\\end{center}\n\\end{figure}\n\\begin{easylist}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Parse Tree Example 2: Production Rules}\n\t\\label{tab:parse-tree-example-2-prod-rules}\n\t\\begin{center}\n\t\t\\begin{tabular}{ l }\n\t\t\t$E \\rightarrow T + E$ \\\\\n\t\t\t$E \\rightarrow T$ \\\\\n\t\t\t$T \\rightarrow int$ \\\\\n\t\t\t$T \\rightarrow int * T$ \\\\\n\t\t\t$T \\rightarrow (E)$\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{figure}\n\\begin{easylist}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Parse Tree Example 2}\n\t\\label{fig:parse-tree-example-2}\n\t\\begin{center}\n\t\tString: $int * int + int$ \\\\[1em]\n\t\t\\begin{forest}\n\t\t\t[$E$\n\t\t\t\t[$T$\n\t\t\t\t\t[$int$]\n\t\t\t\t\t[$*$]\n\t\t\t\t\t[$T$[$int$]]\n\t\t\t\t]\n\t\t\t\t[$+$]\n\t\t\t\t[$E$[$T$[$int$]]]\n\t\t\t]\n\t\t\\end{forest}\n\t\\end{center}\n\\end{figure}\n\\begin{easylist}\n\n& \\textbf{Pushdown automaton (PDA):} \\hyperref[subsec:finite-state-automata]{Finite State Automata} system which utilizes a stack to parse a CFL\n\t&& Notations:\n\t\t&&& Finite set of states: $S$\n\t\t&&& Start state: Outlined\n\t\t&&& Final/accepting state: Double-outlined\n\t\t&&& Production rules: $P$\n\t&& Uses a stack structure to hold symbols\n\t&& For each CFG, there exists an equivalent PDA\n\n& \\textbf{Shift-reduce parsing:} Method of bottom-up parsing which reduces a string to a start symbol, using reversed production rules\n\t&& Uses a left substring containing terminal or non-terminal symbols, and a right substring containing as-of-yet unprocessed symbols\n\t&& Starts with the entire string in the right substring\n\t&& Right substring utilizes a stack with the following options:\n\t\t&&& \\textbf{Shift:} Retrieving a symbol from the stack (right substring) and placing it on the left substring\n\t\t&&& \\textbf{Reduce:} Removing one or more symbols from the stack (right substring), processing them with a reversed production rule, and returning the result to the stack\n\t&& Example:\n\t\\end{easylist}\n\t\\begin{align*}\n\t\t\\textrm{Stack} & | \\textrm{Input} & \\textrm{Action} \\\\\n\t\t\\hline\n\t\t& | x_1 x_2 x_3 x_4 & \\textrm{Begin}\\\\\n\t\tx_1 & | x_2 x_3 x_4 & \\textrm{Shift } x_1 \\\\\n\t\tx_1 & | y_1 x_4 & \\textrm{Reduce } x_2 x_3 \\textrm{ to } y_1 \\\\\n\t\tx_1 y_1 & | x_4 & \\textrm{Shift } y_1 1\\\\\n\t\tx_1 y_1 & | y_2 & \\textrm{Reduce } x_4 \\textrm{ to } y_2 \\\\\n\t\tx_1 y_1 y_2 & | & \\textrm{Shift } y_2\n\t\\end{align*}\n\t\\begin{easylist}\n\n\t&& \\textbf{Shift-reduce conflict:} Situation in shift-reduce parsing where either a shift or reduce can create valid parses\n\t\t&&& Solution: Precedence/associativity declarations\n\t&& \\textbf{Reduce-reduce conflict:} Situation in shift-reduce parsing where multiple different reduces can create valid parses\n\t\t&&& Solution: Rewrite grammar to no longer be ambiguous\n\t&& \\textbf{Handle:} Sequence of symbol(s) at the top of the stack which is a valid reduction allowing further reductions towards the start symbol\n\t\t&&& \\textbf{Prune:} Action of reducing a handle and pushing the result onto the stack\n\t\t&&& To find a handle, heuristics are used; no efficient algorithms exist\n\n\\end{easylist}\n\\clearpage\n", "meta": {"hexsha": "95b7f6ec0b26e724904ea03d1a63fd34ba604162", "size": 7787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-379-principles-of-compiler-design/tex/syntax-analysis.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-379-principles-of-compiler-design/tex/syntax-analysis.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-379-principles-of-compiler-design/tex/syntax-analysis.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": 44.4971428571, "max_line_length": 295, "alphanum_fraction": 0.7006549377, "num_tokens": 2377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.6310411780628884}}
{"text": "\\documentclass[40pt,letterpaper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{cancel}\n\\usepackage{datetime}\n\\usepackage{fullpage}\n\\usepackage{verbatim}\n\\DeclareGraphicsExtensions{.pdf,.png,.jpg} \n\\author{Dmitri Priimak}\n\\title{Josephson Junctions Array}\n\\def\\spvec#1{\\left(\\vcenter{\\halign{\\hfil$##$\\hfil\\cr \\spvecA#1;;}}\\right)}\n\\def\\spvecA#1;{\\if;#1;\\else #1\\cr \\expandafter \\spvecA \\fi}\n\\begin{document}\n \\begin{center}\n  \\underline{Array of Josephson Junctions in the periodic a/c field.}\n \\end{center}\n  \\begin{center}\n    \\underline{Rev. 1}\n  \\end{center}\n   \t\\section{Many Josephson Junctions}\n  \t\\begin{eqnarray}\n  \t\\frac{\\text{d}q}{\\text{d}t} &=& q_1 \\\\\n  \t\\frac{\\text{d}\\phi_k}{\\text{d}t} &=& i_{dc} \n  \t\t+ i_1 \\cos(\\Omega_{1}t) - \\sin(\\phi_k) \n  \t\t- q_1 \\\\\n  \t\\frac{\\text{d}q_1}{\\text{d}t} &=&\n  \t\\frac{1}{l}\\left[N \\left( i_{dc} \n  \t\t+ i_1 \\cos(\\Omega_1 t) - q_1\\right)\n  \t\t- \\sum_{k=0}^{N-1} \\sin(\\phi_k) \n  \t\t\\right]\n  \t\t-\\frac{r}{l}q_1 - \\Omega_0^2 q\n  \t\\end{eqnarray}\n  \tLet us introduce new vector $\\mathbf{r} = \\spvec{q;\\{\\phi_k\\};q_1}$ and a vector function $\\mathbf{f}$ corresponding to the functions on\n  \tthe right of the equal sign in the equations above.\n\t\\begin{equation}\n  \t\t\\mathbf{f}(t, \\mathbf{r})=\\spvec{q;\n  \t\ti_{dc} \n  \t\t  \t\t+ i_1 \\cos(\\Omega_{1}t) - \\sin(\\phi_k) \n  \t\t  \t\t- q_1;\n  \t\t\\frac{1}{l}\\left[N \\left( i_{dc} \n  \t\t  \t\t+ i_1 \\cos(\\Omega_1 t) - q_1\\right)\n  \t\t  \t\t- \\sum_{k=0}^{N-1} \\sin(\\phi_k) \n  \t\t  \t\t\\right]\n  \t\t  \t\t-\\frac{r}{l}q_1 - \\Omega_0^2 q}\n  \t\\end{equation}\n  \tThen set of differenetial equations can be written simply as:\n  \t\\begin{equation}\n  \t\\frac{\\text{d}\\mathbf{r}}{\\text{d}t}=\\mathbf{f}(t, \\mathbf{r})\n  \t\\end{equation}\n\n \t\\begin{comment}\n  \tWe use forth order Runge-Kutta method to solve this equation. To than end we step over time with step $\\Delta t$. And introduce time step supperscript to $\\mathbf{r}$. Thus $\\mathbf{r}^t$ and \\mathbf{r}^{t+1}$ are values of $\\mathbf{r}$ for two consequetive time steps.\n  \t\\begin{eqnarray}\n  \t\\mathbf{k}_1 &=& \\mathbf{f}(t, \\mathbf{r}^t) \\\\\n  \t\\mathbf{\\tilde{r}} &=& \\mathbf{r}^t + \\frac{\\Delta t}{2}\\mathbf{k}_1 \\\\\n  \t\\mathbf{k}_2 &=& \\mathbf{f} \\left(t + \\frac{\\Delta t}{2}, \\mathbf{\\tilde{r}}\\right) \\\\\n  \t\\mathbf{\\tilde{r}} &=& \\mathbf{r}^t + \\frac{\\Delta t}{2}\\mathbf{k}_2 \\\\\n  \t\\mathbf{k}_3 &=& \\mathbf{f} \\left(t + \\frac{\\Delta t}{2}, \\mathbf{\\tilde{r}}\\right) \\\\  \t\n  \t\\mathbf{\\tilde{r}} &=& \\mathbf{r}^t + \\Delta t\\mathbf{k}_3 \\\\\n  \t\\mathbf{k}_4 &=& \\mathbf{f} \\left(t + \\Delta t, \\mathbf{\\tilde{r}}\\right)\t\n  \t\\end{eqnarray}\n  \t\\begin{equation}\n  \t\\mathbf{r}^{t+1} = \\mathbf{r}^t + \\frac{\\Delta t}{6}\\left(\\mathbf{k}_1 + 2 \\mathbf{k}_2 + 2 \\mathbf{k}_3 + \\mathbf{k}_4\\right)\n  \t\\end{equation}\n  \t\\newpage\n    \\end{comment}\n  \t\\section{One Josephson Junction}\n  \t\\begin{eqnarray}\n  \t\\frac{\\text{d}q}{\\text{d}t} &=& q_1 \\\\\n  \t\\frac{\\text{d}\\phi}{\\text{d}t} &=& i_{dc} \n  \t\t+ i_1 \\cos(\\Omega_{1}t) - \\sin(\\phi) \n  \t\t- q_1 \\\\\n  \t\\frac{\\text{d}q_1}{\\text{d}t} &=&\n\t\\frac{i_{dc}}{l} + \n\t\\frac{i_1}{l}\\cos(\\Omega_1 t) \n\t- \\frac{1 + r}{l}q_1 - \\frac{1}{l}\\sin(\\phi) \n\t- \\Omega_0^2 q\n  \t\\end{eqnarray}\n  \tFree parameters $i_{dc}, i_1, r, l, \\Omega_0, \\Omega_1$. And this is the equation we solve, to which end we use \n  \tthree different methods: First Order Euler, Midpoint Method and Fourth Order Runge–Kutta and compare \n\tit with c++ code provided by Olesia Pozdniakova, which uses Fourth Order Runge–Kutta. Our program, written in \n\tC, is called \\textbf{1jja\\_c} and C++ program by Olesia is called \\textbf{jja\\_cpp\\_time\\_eval}.\n\tFirst we compare results produced by both programs. \n\t\\begin{figure}[h]\n\t\\includegraphics{figures/experiments_001_and_002.pdf}\n\t\\caption{Here we are using \\textbf{1jja\\_c} to compute average voltage $\\overline{v}$ across the junction while varying $i_{dc}$. Input parameters are $\\Omega_{1}=0.4$, \n\t$i_1=0.3$, \n\t$\\phi=0.0$, $\\Omega_{0}=0.4$, $b=0.01$, $r=0.0$. Time step $\\Delta t=0.001$. Averaging of voltage starts from $t=40$, which is more than sufficient to for the system to settle \n\tdown. External period of driving system is determined by parameter $\\Omega_1$ and is $T=2\\pi/\\Omega_1$. Thus original assumption was that we can perform averaging \n\tover just one such period. That turned out not to be the case. Number of periods used for voltage averaging is denoted as $N_{av}$. Red line shows voltage averaged \n\tover time $3T$, while black one over just one period $T$. You can see that for sufficiently large values of $i_{dc}$ there is a difference between these values \n\tof $\\overline{v}$. Blue line shows that difference. First there is a long region for $i_{dc}$ from $0$ to about $0.8$ where both averaging techniques give the same \n\t$\\overline{v}$. Oddly, however is the presence of two more regions where they match. These two regions are marked by light gray rectangles named $a$ and $b$.}\n\t\\end{figure}\n\n\\begin{comment}\n  \t\\subsection{First Order Euler}\n  \t\\begin{eqnarray}\n  \tq^{t+\\Delta t} &=& q^t + q_1 \\Delta t \\\\\n  \t\\phi^{t+\\Delta t} &=& \\phi^t + \\Delta t\n  \t\\left[\n  \ti_{dc} + i_1 \\cos(\\Omega_{1}t) - \\sin(\\phi) \n  \t- q^{t}_1\n  \t\\right] \\\\\n  \tq^{t+\\Delta t}_1 &=& q^t_1 + \\Delta t\n  \t\\left[\n\t\\frac{i_{dc}}{l} + \n\t\\frac{i_1}{l}\\cos(\\Omega_1 t) \n\t- \\frac{1 + r}{l}q^t_1 - \\frac{1}{l}\\sin(\\phi^t) \n\t- \\Omega_0^2 q^t  \t\n  \t\\right]\n  \t\\end{eqnarray}\n\\end{comment}  \t\n\\end{document}\n", "meta": {"hexsha": "92994695f7254c279fba1338e0bb03b3672de2f7", "size": 5449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/jja_note01.tex", "max_stars_repo_name": "priimak/jja", "max_stars_repo_head_hexsha": "4d227b23547a2df3ac2837842e8c74975702756e", "max_stars_repo_licenses": ["MIT"], "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/jja_note01.tex", "max_issues_repo_name": "priimak/jja", "max_issues_repo_head_hexsha": "4d227b23547a2df3ac2837842e8c74975702756e", "max_issues_repo_licenses": ["MIT"], "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/jja_note01.tex", "max_forks_repo_name": "priimak/jja", "max_forks_repo_head_hexsha": "4d227b23547a2df3ac2837842e8c74975702756e", "max_forks_repo_licenses": ["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.7899159664, "max_line_length": 272, "alphanum_fraction": 0.6419526519, "num_tokens": 2134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.631039548590727}}
{"text": "\\section{Introduction}\nSchroedinger's equation for two electrons in a three-dimensional harmonic osillator well\n\n\n\\section{Task 02a}\nMathematical intermezzo: A unitary transformation preserves the orthogonality of the obtained eigenvectors. We assume the basis is orthogonal:\n$\\mathbf{v_j^Tv_i} = \\delta_{ij}$\n\nShow that an orthogonal or unitary transformation $\\mathbf{w_i} = \\mathbf{Uv_i}$ preserves the dot product and orthogonality, where U is a matrix.\n\nSay $\\mathbf{w_j} = \\mathbf{Uv_j}$\\\\\n\\\\\n$\\mathbf{w_j^T} = \\mathbf{Uv_j}^T = \\mathbf{v_j^TU^T}$\\\\\n\\\\\n$\\mathbf{w_j^Tw_i} = \\mathbf{v_j}^T \\mathbf{U^TUv_i} $\\\\\n\\\\\n$U^TU = I \\implies \\mathbf{w_j^Tw_i} = \\mathbf{v_j^Tv_i} = \\delta_{ij}$\n\n\n\n\\section{Task 02b}\nWrite a function which implements Jacobi's rotation algorithm to solve the tridiagonal matrix eigenvalue problem:\n\nThe function test\\_rho\\_max\\_jacobi in the source code of project 2 plots the three lowest eigenvalues for n = 80, 160, 320, as shown in figure ~\\ref{fig:Eigenvalue_states_n_80}, ~\\ref{fig:Eigenvalue_states_n_160} and ~\\ref{fig:Eigenvalue_states_n_320}. The wanted error of approximately four leading digits was obtained after increasing n to 320. I tried several values for $\\rho_{max}$ and found that the normalized energy became very small for $\\rho_{max}>5$. $\\rho_{max} = 5$ was chosen because it gave the desired error for the eigenvalues as shown in figure ~\\ref{fig:Eigenvalue_states_n_320}.\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho49n80.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=80}\n\\label{fig:Eigenvalue_states_n_80}\n\\end{figure}\n\\FloatBarrier\n\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho49n160.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=160}\n\\label{fig:Eigenvalue_states_n_160}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho49n320.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for a system with no repulsive Coulomb interaction with n=320}\n\\label{fig:Eigenvalue_states_n_320}\n\\end{figure}\n\\FloatBarrier\n\n\nThe function jacobi\\_method finds the eigenvalues and eigenvectors for a symmetric matrix A through rotational transformations.\nIf the non-diagonal matrix elements are exactly 0, the diagonal elements are the eigenvalues. How many similarity transformations are needed to reach the accepted error tolerance for a given n is shown with different scalings in figure ~\\ref{fig:Similarity_transformations_threshold_logy} and ~\\ref{fig:Similarity_transformations_threshold_loglog}. The reference plot of $3n^2-5n$ is the theoretical value given in the lecture notes on the Jacobi method (Ch. 7.4, 23.10.17).\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{num_iterations512n8logy.png}\n\n\\caption{Number of similarity transformations needed to reach the accepted error tolerance of $10^{-8}$ for the non-diagonal matrix elements, plotted with a logarithmic y-axis}\n\\label{fig:Similarity_transformations_threshold_logy}\n\\end{figure}\n\\FloatBarrier\n\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{num_iterations512n8loglog.png}\n\n\\caption{Number of similarity transformations needed to reach the accepted error tolerance of $10^{-8}$ for the non-diagonal matrix elements, plotted with a logarithmic x- and y-axis}\n\\label{fig:Similarity_transformations_threshold_loglog}\n\\end{figure}\n\\FloatBarrier\n\n\nThe convergence rate of the Jacobi method is poor. According to the lecture notes, one typically needs $3n^2-5n$. My calculations gave $1.7n^2-3.98n$, which is marginally better than the text book.\n\n\n\n\\section{Task 02c}\nThis section is about testing the code.\n\nI set up three tests for the code, implemented with the program test\\_project\\_2.py given in my list of files to be found at my Github.\n\nThe tests are: \\\\\n\\begin{itemize}\n\n\\item test\\_three\\_first\\_eigenvalues tests that the three first eigenvalues are correct within a tolerance of $10^{-4}$\n\\item test\\_jacobi\\_eigenvectors\\_are\\_orthogonal makes sure the eigenvectors are orthogonal\n\\item test\\_jacobi\\_solves\\_eigen\\_value\\_eq makes sure the jacobi method solves the eigenvalue equation.\n\n\\end{itemize}\n\n\n\\section{Task 02d}\nSchroedingers equation rewritten with a different potential to make it more general, allowing for a system with repulsive Coulomb interaction.\\\\\n\n\nFor figure ~\\ref{fig:Eigenvalue_states_n_320_omega_100} the normalized energies are very similar compared to the non-interactive case from figure ~\\ref{fig:Eigenvalue_states_n_320}. This is because the potential is very similar: Noninteractive case has potential $\\rho^2$, whereas the interactive case has potential $\\omega_r^2\\rho^2+1/\\rho$. For $\\omega_r = 1$ the difference is only a term $1/\\rho$, which is a small deviation for sufficiently large $\\rho$. \\\\\n\nThe varying $\\omega_r$ from figure ~\\ref{fig:Eigenvalue_states_n_128_omega_1} to figure ~\\ref{fig:Eigenvalue_states_n_320_omega_500} shows that the spikes of the energy increases with increasing $\\omega_r$, which was expected since the potential is dependent on $\\omega_r^2$. This means that the uncertainty for where the electrons are positioned is lower for larger $\\omega_r$. At low values of $\\omega_r$ the potential is spread over a wider range, giving the term $1/\\rho$ more importance. To compensate for $\\omega_r = 0.01$, I had to increase $\\rho_{max}$ to 60  to fully capture the most probable position of the electrons. The theoretical approximate groundstate wavefunction is given right after equation 16a in the article by M.Taut 1993;  \"Two electrons in an external oscillator potential\", is plotted as reference with a dashed line.\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho595n128omega1}\n\n\\caption{Normalized energy for the three lowest eigenvalues for a system with repulsive Coulomb interaction with n=128 and $\\omega_r$=0.01}\n\\label{fig:Eigenvalue_states_n_128_omega_1}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho99n128omega50.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\\omega_r$=0.5}\n\\label{fig:Eigenvalue_states_n_128_omega_50}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho59n128omega100.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\\omega_r$=1}\n\\label{fig:Eigenvalue_states_n_320_omega_100}\n\\end{figure}\n\\FloatBarrier\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{eigenvector_rho29n128omega500.png}\n\n\\caption{Normalized energy for the three lowest eigenvalues for repulsive Coulomb interaction with n=128 and $\\omega_r$=5}\n\\label{fig:Eigenvalue_states_n_320_omega_500}\n\\end{figure}\n\\FloatBarrier\n\n\n\\subsection{Comments}\nI realize that I probably should have plotted only the lowest ground state for the four last plots. ", "meta": {"hexsha": "de712fc1b3e5729ef4495e900c2df94914443b5d", "size": 7469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project_2/1.tex", "max_stars_repo_name": "larsjbro/FYS4150", "max_stars_repo_head_hexsha": "95ac4e09b5aad133b29c9aabb5be1302abdd8e65", "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": "Project_2/1.tex", "max_issues_repo_name": "larsjbro/FYS4150", "max_issues_repo_head_hexsha": "95ac4e09b5aad133b29c9aabb5be1302abdd8e65", "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": "Project_2/1.tex", "max_forks_repo_name": "larsjbro/FYS4150", "max_forks_repo_head_hexsha": "95ac4e09b5aad133b29c9aabb5be1302abdd8e65", "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.4583333333, "max_line_length": 845, "alphanum_fraction": 0.7966260544, "num_tokens": 2036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434925908525, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.631039542589214}}
{"text": "\\subsection*{Introduction}\n\nThe problem consists of a dataset containing significant wave-heights recorded 14 times a month during several winter months in the north Atlantic. This is could for example be used to predict the probability of high waves in the north atlantic to warn oil platforms. One can estimate the extreme value of this dataset by assuming that the data has a \\textit{Gumpel Distribution} with distribution function\n\\[ F(x; \\mu, \\beta)=\\exp\\left(-\\exp\\left(-\\frac{x-\\mu}{\\beta}\\right)\\right), \\quad x\\in\\mathbb{R}, \\]\nwhere $\\mu\\in\\mathbb{R}$ and $\\beta>0$. The paramaters of this distribution for an arbitrary dataset was estimated using the matlab function \\texttt{est\\_gumbel.m}. \\\\\n\nDuring a 100 year interval, one can calculate a estimate of the likelihood of an 100--year return period event. It is a statistical measurement typically based on historic data denoting the average recurrence interval over an extended period of time. The analysis assumes that the probability does not vary in time and is independant of past events. \\\\\n\nThe expected 100-year return value of the data gives the largest expected wave-height during a 100-year period. The $T$:th return value is denoted by $F^{-1}(1-1/T;\\mu,\\beta)$. Since the data has been observed during 14 times a month and assuming we have three winter months during a year, $T$ is $T=3\\cdot14\\cdot100$. The investigated dataset is shown below in figure \\ref{fig:waves}. \\\\\n\n\\begin{figure}[H]\n\\centering\n\t\\includegraphics[scale=0.26]{./Figures/waves.png}\n\\caption{A figure, showing the data of the significant observed wave-heights}\n\\label{fig:waves}\n\n\\end{figure}\n\nTo perform a statistical test on the dataset, we use a parametric bootstrap approach. The bootstrap technique evaluates the uncertainty of an unknown distribution or data. The bootstrap replaces the unknown statistic by data-based approximations and analyzes the variation using MC simulation from the approximation. The approximations are done using a \\textbf{empirical distribution} (ED) associated with the data and gives equal weights to each observed value. Below we will present a brief description of a general bootstrap method.\n\n\\begin{itemize}\n\\item{For a given statistic y, we replace $\\mathbb{P}_0$ by $\\hat{\\mathbb{P}}_0$.}\n\\item{Approximation can be done by plugging $\\hat{\\mathbb{P}}_0$ into the quantity, i.e.\n\\[ \\tau=\\tau(\\mathbb{P}_0)\\approx \\hat{\\tau}=\\tau(\\hat{\\mathbb{P}}_0) \\].}\n\\item{Uncertainty of $t(y)$ is analyzed by looking at the variation of $\\Delta(Y^*)=t(Y^*)-\\hat{\\tau}$ by drawing repeatedly $Y^*\\sim \\hat{\\mathbb{P}_0}$.}\n\\end{itemize}\n\nIn our case, we have done a parametric bootstrap, where we assume that the data comes from a distribution $\\mathbb{P}_0=\\mathbb{P}_{\\theta_0}\\in\\{\\mathbb{P}_\\theta;\\theta \\in \\Theta\\}$ belonging to some parametric family. Instead of using the ED, we find an estimate $\\hat{\\theta}=\\hat{\\theta}(y)$ of $\\theta_0$ from the observations and\n\\begin{enumerate}\n\\item{generate new bootstrapped samples $Y_b^*,b\\in \\{1,2,\\dots,B\\}$, from $\\hat{\\mathbb{P}_0}=\\mathbb{P}_{\\hat{\\theta}}$.}\n\\item{then we form bootstrap estimates $\\hat{\\theta}(Y_b^*)$ and errors $\\Delta_b^*=\\hat{\\theta}(Y_b^*)-\\hat{\\theta},b\\in\\{1,2,\\dots,B\\}$}.\n\\end{enumerate}\n\nFor this assigment we approximated the data as being that of \\textit{Gumpel distributed} data points. In the figure \\ref{fig:waveshist} we have plotted the histogram of the atlantic wave-heights, indicating that the data has a a \\textit{Gumpel} distribution.\n\n\\begin{figure}[H]\n\\centering\n\t\\includegraphics[scale=0.26]{./Figures/waveshist.png}\n\\caption{A figure, showing the data of the significant observed wave-heightsdata, in \\texttt{atlantic.mat}}\n\\label{fig:waveshist}\n\n\\end{figure}\n", "meta": {"hexsha": "7b0aa599c18ff7b49b18469691f5fdc73babef7f", "size": 3737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/Report/intro2.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/intro2.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/intro2.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": 86.9069767442, "max_line_length": 535, "alphanum_fraction": 0.7556863794, "num_tokens": 1018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6309908382046931}}
{"text": "\\subsection{Multi-class Object Classification}\n% Describe here the CNN architecture.\nWe use for classification of point cloud data Convolutional Neural Network (CNN).\nOur neural network architecture is represented in Figure \\ref{fig:cnn}.\nThe network model is designed for multi-class classification of \npoint cloud objects.\n% Convolutional neural network provides a promising result of object model with spatial data.\nCNN effectively learns the feature recognition of planes, corners, and the edges of the object model.\nOur network model is designed with 4 convolutional layers where each layer filter is expected to\nrecognize planes, corners, edges, and distribution of the objects per orientation.\nOther layers learn the global label for the input grid from the knowledge passed by each layer.\n\n\\textbf{Input preparation:}\nThe 3D points \\textit{(x,y,z)} of the object are projected into 2D points \\textit{(x,y) or (x',y')} (Sec 3.2).\nThese projected object points are placed on a grid of height 7 and length 10.\nThis grid is divided into cells of 0.1x0.1 resulting in 70x100 cells and the information about the number of points in each cell is the input to the model.\nThis input on plotting as pixels will result in the object.\n\n\\textbf{Input layer:}\nThe network model takes a fixed-size input of NxM point counts in grid-cells. We have\nused $N=70$ and $M=100$ for our model requirements. The input layer forwards each object input to the 1st layer\nof convolutional.\n\n\n\\textbf{Convolutional Layer (input,f,s):}\nThere are 4 convolutional layers in our architecture to learn features on each orientation.\nThe first convolutional layer feed on two-dimensional input of size $N \\times  M$ from\nthe input layer, a filter size=f and number of filters=s to be applied.\n\nThe filter-size provided to convolutional layer is $5 \\times 5$ with 16 such filters to be applied on the input.\nThe convolutional layer uses filter f to apply convolution operation on input to create a feature map as output.\nThe convolutional layer learns about the spatial planes, edges, and distribution in the object,\nthe convolutional layer passes the output to the rectified linear unit (ReLU) before feeding\nit forwards to next layers.\n\n\\textbf{Max Pooling layer:}\nThe pooling layer is added to reduce the dimension of the data by a factor of d. \nThe size of pooling layer is  $d \\times  d$, in our model d = 2. \nThe max pooling layer is applied after each alternative convolutional\nlayer, it reduces the dimension of the feature map with their maximums.\n\n\\textbf{Dropout Layer:}\nDropout layer is used for reducing overfitting. As the network is executed on the iterative model with a feed forward network.\nThe model network tends to overfit on the data. Dropout layer drops random samples from the feature\nmap while training.\n\n\\textbf{Fully Connected Layer:}\nAs fully connected layers contain n output neurons. Each neuron of the output is a learned linear\ncombination of all the outputs from the previous layer, passed through a nonlinearity.\nWe use ReLUs to save the final output layer, where the number of outputs corresponds\nto the number of class labels and a softmax nonlinearity is used to provide a probabilistic output.\n\n\n% Our Network model starts with an input layer feeding to convolution layer with ReLu then\n% another convolutional layer with ReLu and max pool layer then passing input to another batch of convolutional layers\n% with Relu and convolutional layer with Relu and max pool, then the feature map is flattened to be feed-forwarded to\n% fully connected layer with ReLu, then random samples are dropped with dropout layers\n% and finally fed to a fully connected layer and softmax to classify the object into multiclass.\n\nThe combination of the above layers is used by some of the state-of-the-art models which have high accuracy on 2-D image inputs.\nIn order to build the model for this challenge, we have used the above layers, because the input to the model is in the form of pixels.\n% Different configurations had different resulted in different models.\n%To come up with the state-of-the-art architecture,\n\n\\textbf{Model:}\nSingle objects data is used as input for training the model and it predicts the object out of 28 classes. We started implementing a simple 2 layered convolutional neural network,\nwhich uses two convolutional layers with rectified linear unit and a max pool layer,\ndrop out and a couple of fully connected layers to classify point cloud objects based upon classes.\nThis architecture was effective but \ndid not give acceptable results. \n%%%%%decide%%%%%% the test accuracy on single objects is low\nFurther experimenting with layers explained the learning of pixel input by convolutional layer.\n\nThe experiment with 4 layered convolutional network has better performance, as they were able to learn planes, edges, and distribution of the point cloud object.\nA couple of 2 convolutional layers with alternative ReLU added before output and max-pooling layer between them shows the best results while training and testing on individual objects.\n\nThe architecture was added with 2 fully connected layers with a single drop out layer to reduce overfitting.\nThis experimented architecture showed the best result with the training set and the evaluation platform.\n\n\\begin{figure*}[!h]\n     \\begin{center}\n       \\includegraphics[width=0.8\\textwidth]{./images/object_net.pdf}\n       \\caption{Overview of Convolutional Neural Network Layers with 4 Convolutional Layers}\n       \\label{fig:cnn}\n     \\end{center}\n\\end{figure*}\n\n\\subsection{CNN with 3D point cloud Input Data}\nWe experimented with 3D CNN as \n% dataset could be transformed into the input of 3D CNN being a 3D point cloud dataset.\n3D point cloud could be transformed into the input of 3D CNN.\nOur approach was to convert point clouds into a set of voxels by voxelization. \nVoxelization is the process of conversion of a geometric object from its continuous geometric representation into a set of voxels that best approximates the continuous\nobject. We used the process to fit a bounding box voxel around the point cloud to form a voxel grid.\n\nWe designed for 4 layered 3D CNN architecture with 2 fully connected layers, a dropout layer, and a softmax layer at the end.\nThe voxel-grid is feed into the network as input and network predict the object out the 28 classes on which network is trained.\nThe 3D CNN model gave the best performance when trained on a minimal number of class attributes but failed to perform when trained on all the class.\nThe major reason we tracked for low performance of 3D CNN with a large number of output classes was the density of the object and its distribution.\n\nThe performance could be improved by experimenting with lower voxel size to increase more voxels for input.\nThis method is high resources dependent as the input size grows from several megabytes to several gigabytes, making harder to work on a standard system.\nReviewing the performance between 2D CNN and 3D CNN, the 2D CNN model was providing better performance and precision.\n", "meta": {"hexsha": "26af93cbe1c519968984602ae32bddf787cfa9c9", "size": 7049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/architecture2.tex", "max_stars_repo_name": "kiat/debs2019", "max_stars_repo_head_hexsha": "b1231a0995a154f8549ef23a00f635b81cc3c689", "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": "paper/architecture2.tex", "max_issues_repo_name": "kiat/debs2019", "max_issues_repo_head_hexsha": "b1231a0995a154f8549ef23a00f635b81cc3c689", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-11T23:19:14.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T06:39:53.000Z", "max_forks_repo_path": "paper/architecture2.tex", "max_forks_repo_name": "kiat/debs2019", "max_forks_repo_head_hexsha": "b1231a0995a154f8549ef23a00f635b81cc3c689", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-06T21:54:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T21:54:47.000Z", "avg_line_length": 67.7788461538, "max_line_length": 184, "alphanum_fraction": 0.7986948503, "num_tokens": 1525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6308976589820361}}
{"text": "\\vssub\n\\subsection{~Wave crest and height space-time extremes} \\label{sub:space_time_ext}\n\\conthead{\\ws (ISMAR, NCEP)}{Barbariol, F., Benetazzo, A., Alves, J.H.G.M.}\n\nSpace-Time (ST) extreme waves are modeled in WAVEWATCH III based on the Euler Characteristics (EC) approach, which states that for a given multi-dimensional (2-D space + time), statistically homogeneous and stationary Gaussian random wave field, the probability of exceedance of the maximal sea surface elevation is approximated by means of the mean value of the EC \\citep{Fed12eu}. The ST extreme elevation model used here was formulated by \\cite{Fed12sp} for Gaussian sea waves, and extended to second-order nonlinear spatial wave fields by \\cite{Fed13} and spatio-temporal fields by \\cite{Beet15}. The proposed ST extreme linear model was assessed with numerical simulations \\citep{Baet15,Baet16}, while the extension to second-order nonlinear waves was verified using stereo imaging \\citep{Fed13,Beet15}. According to those models, the probability of exceedance of the second-order nonlinear ST maximal crest height $\\eta_{2ST_m}$ is approximated (for large threshold $z_2$ with respect to the standard deviation of the surface elevation $\\sigma$) as:\n\\begin{equation}\nP(\\eta_{2ST_m} > z_2) \\approx \\left[N_{3D} \\left( \\frac{z_1}{\\sigma} \\right)^{2} + N_{2D} \\left( \\frac{z_1}{\\sigma} \\right) + N_{1D} \\right] \\exp{ \\left( -\\frac{z_1^2}{2 \\sigma^2} \\right)},\n\\label{eq_STE1}\n\\end{equation}\nwhere the nonlinear threshold $z_2$ is related to its linear approximation $z_1$ via the Tayfun quadratic equation using the steepness parameter $\\mu$, strictly valid in deep waters, which accounts for bandwidth effects. Parameters $N_{3D}$, $N_{2D}$, and $N_{1D}$ express the average number of 3D, 2D, and 1D waves within the ST region, respectively, and are determined from the moments $m_{ijl}$ of the directional wave spectrum $S(k, \\theta)$ defined as follows:\n\\begin{equation}\nm_{ijl}=\\int k_{x}^{i}k_{y}^{j}\\omega^{l}S(k,\\theta)dkd\\theta.\n\\label{eq_STE2}\n\\end{equation}\n\nThe average number of waves in Eq. (\\ref{eq_STE1}) also depends on the size of the spatio-temporal domain, namely the spatial dimension $X$ along the mean direction of wave propagation, the spatial dimension $Y$ orthogonal to the mean direction of wave propagation, and the duration $D$. The expected value $\\bar{\\eta}_{2ST_m}$ (output parameter \\textbf{STMAXE}, in meters) of the random variable $\\eta_{2ST_m}$ is given by\n\\begin{multline}\n\\bar{\\eta}_{2ST_m}=\\mathbb{E}\\left\\{\\eta_{2ST_m} \\right\\} = \\\\ \n\t\\sigma \\left[(h_1+\\frac{\\mu}{2}h_1^{2})+\n\\gamma \\left( h_1-\\frac{2N_{3D}h_1+N_{2D}}{N_{3D} h_1^{2}+N_{2D} h_1+N_{1D}}\\right)^{-1} (1+\\mu h_1) \\right],\n\\label{eq_STE3}\n\\end{multline}\nwhere $\\gamma \\approx 0.5772$ is the Euler-Mascheroni constant, and $h_1$ is the dimensionless (with respect to the standard deviation $\\sigma$) most probable (mode) extreme value, which is the largest solution of the implicit equation in $h$\n\\begin{equation}\n\\left[N_{3D} h^{2} + N_{2D} h + N_{1D} \\right] \\exp{ \\left( -\\frac{h^2}{2} \\right)}=1.\n\\label{eq_STE4}\n\\end{equation}\n\nThe standard deviation $\\sigma_{2_m}$ (output parameter \\textbf{STMAXD}, in meters) of the crest height $\\eta_{2ST_m}$ is given by:\n\\begin{equation}\n\\sigma_{2_m}=std(\\eta_{2ST_m})=\\sigma \\frac{\\pi}{\\sqrt{6}} \\left( h_1-\\frac{2N_{3D}h_1+N_{2D}}{N_{3D} h_1^{2}+N_{2D} h_1+N_{1D}}\\right)^{-1} (1+\\mu h_1) .\n\\label{eq_STE5}\n\\end{equation}\n\nThe expected value of the ST extreme crest-to-trough wave height is obtained using the Quasi-Determinism (QD) model, which predicts the mean shape of ST wave groups close to the apex of their development. According to the QD model the expected value of the crest-to-trough height $\\bar{H}_{1_{cm}}$ (output parameter \\textbf{HCMAXE}, in meters) of the wave with linear extreme crest height $\\bar{\\eta}_{1ST_m}$ is expressed as\n\\begin{equation}\n\\bar{H}_{1_{cm}}=\\mathbb{E}\\left\\{H_{1_{cm}} \\right\\} = \\bar{\\eta}_{1ST_m}(1-\\psi_1^* / \\sigma^2),\n\\label{eq_STE6}\n\\end{equation}\nwhere $\\psi_1^* < 0$ is the value of the first minimum of the temporal autocovariance function computed from the spectrum as\n\\begin{equation}\n\\psi_1(\\tau) = \\int S(\\omega) \\cos{(\\omega \\tau)} d \\omega,\n\\label{eq_STE7}\n\\end{equation}\nand $\\bar{\\eta}_{1ST_m}  \\psi_1^*/\\sigma^2 < 0$ is the expected displacement of the wave trough preceding or following the expected linear extreme crest height $\\bar{\\eta}_{1ST_m}$, which is computed using Eq. (\\ref{eq_STE3}) after letting the wave steepness $\\mu=0$. For a given linear group, the height $\\bar{H}_{1_{cm}}$ is generally smaller than the maximum expected wave height $\\bar{H}_{1_m}$ (output parameter \\textbf{HMAXE}, in meters), which is computed as\n\\begin{equation}\n\\bar{H}_{1_m}=\\mathbb{E}\\left\\{H_{1_m} \\right\\} = \\bar{\\eta}_{1ST_m}\\sqrt{2(1-\\psi_1^* / \\sigma^2)}.\n\\label{eq_STE8}\n\\end{equation}\n\nThe effect on wave heights of second-order nonlinearities is generally small, particularly in narrow band seas, and it will be neglected in the present implementation to reduce the computational cost. Uncertainty of estimates of $\\bar{H}_{1_{cm}}$ (output parameter \\textbf{HCMAXD}, in meters) and $\\bar{H}_{1_m}$ (output parameter \\textbf{HMAXD}, in meters) are determined using the standard deviation of $\\eta_{1ST_m}$ ($\\sigma_{1_m}$, which is computed using Eq. (\\ref{eq_STE5}) after letting the wave steepness $\\mu=0$) as follows:\n\\begin{eqnarray}\nstd({H}_{1_m})&=&\\sigma_{1_m}\\sqrt{2(1-\\psi_1^* / \\sigma^2)}, \\nonumber \\\\\nstd({H}_{1_{cm}})&=&\\sigma_{1_m}(1-\\psi_1^* / \\sigma^2).\n\\label{eq_STE9}\n\\end{eqnarray}\n\nTo activate the computation of wave crest and height space-time extremes in WAVEWATCH III, the user has to specify values of the {\\F MISC} namelist parameters {\\code STDX}, {\\code STDY} and {\\code STDT} in {\\file ww3\\_grid.inp} different to -1 (the latter is a default value that avoids computer overheads when these parameters are not wanted). {\\code STDX} and {\\code STDY} are spatial dimensions over which extremes are calculated. {\\code STDT} is the time length over which extremes are calculated. If {\\code STDX} and {\\code STDY} are left at default values (-1), but {\\code STDT} has a namelist value different to default (e.g., greater than 0), then extreme values are provided over time, for a point. Conversely, if {\\code STDT} is kept at default (-1) and {\\code STDX} and {\\code STDY} are greater than zero, instantaneous extreme values are computed over space. When all three parameters are greater than zero, space-time probabilities and values are computed.\n\nWave crest and height space-time extremes outputs follow the standard WAVEWATCH III parameter framework, and have to be specified as namelists or flags in {\\file ww3\\_shel.inp} or {\\file ww3\\_multi.inp}, in which case they are included in the standard gridded binary output files during a model run. Consequently, they also have to be specified in gridded output post-processors for obtaining a final human-readable form. Space-time extremes output parameters available in WAVEWATCH III are provided in Table \\ref{tab:ste_parm}.\n\n\\begin{table}[h]\n\\begin{center} \\begin{tabular}{|l|c|c|} \\hline \\hline\nInternal Label & User-Interface Label & Description \\\\ \\hline\nSTMAXE  &   MXE   & Max surface elev (STE) \\\\\nSTMAXD  &   MXES  & STD of max crest (STE) \\\\\nHMAXE   &   MXH   & Max wave height (STE) \\\\\nHCMAXE  &   MXHC  & Max wvhgt from crest (STE) \\\\\nHMAXD   &   SDMH  & STD of MXH (STE) \\\\\nHCMAXD  &   SDMHC & STD of MXHC (STE) \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\caption{User-defined parameters in the computation of wave crest and height space-time extremes.}\n\\label{tab:ste_parm} \\botline \\end{table}\n\n\n", "meta": {"hexsha": "78993a73540ee4db31f35012a033023d515e3f1e", "size": 7661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/num/space_time_ext.tex", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "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": "WW3/manual/num/space_time_ext.tex", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-31T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:17:45.000Z", "max_forks_repo_path": "WW3/manual/num/space_time_ext.tex", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-01T09:29:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-01T09:29:46.000Z", "avg_line_length": 99.4935064935, "max_line_length": 1055, "alphanum_fraction": 0.7342383501, "num_tokens": 2353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6308976481407647}}
{"text": "\\section{Examples of convolution filters and performance}\nIn this section, we will give a brief description how convolution operations are used for image processing.\nOne useful description can be found in the following link:\n\n\\href{http://aishack.in/tutorials/image-convolution-examples/}{http://aishack.in/tutorials/image-convolution-examples/}\n\nConvolutions is a technique for general signal processing. People studying electrical/electronics will tell you the near-infinite sleepless nights these convolutions have given them. Entire books have been written on this topic. And the questions and theorems that need to be proved are insurmountable. But for computer vision, we'll just deal with some simple things.\n\nA convolution lets you do a very wide variety of things, like calculating derivatives, detecting edges, apply ing blurs, etc. And all of this is done with a \"convolution kernel\".\n\n\\subsection{Calculation with convolutions}\nThe most direct way to compute a convolution would be to use multiple for loops. But that causes a lot of repeated calculations. And as the size of the image and kernel increases, the time to compute the convolution increases quite drastically.\n\nTechniques haves been developed to calculate convolutions rapidly. One such technique is using the Discrete Fourier Transform. It converts the entire convolution operation into a simple multiplication. Fortunately, you don't need to know the math to do this in OpenCV. It automatically decides whether to do it in frequency domain (after the DFT) or not.\n\n\\subsection{Image convolution examples}\nA convolution is very useful for signal processing in general. There is a lot of complex mathematical theory available for convolutions. For digital image processing, you don't have to understand all of that. You can use a simple matrix as an image convolution kernel and do some interesting things!\n\n\n\\subsection{Line detection by 1D Laplacian}\nWith image convolutions, you can easily detect lines. Figure \\ref{line:detect1} represents the  four convolutions to detect horizontal, vertical and lines at 45 and 135 degrees:\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[width=.4\\textwidth]{6DL/figures/line}\n\t\\caption{Four convolutions to detect horizontal, vertical and lines at degrees 0,90,45,135.}\n\t\\label{line:detect1}\n\\end{figure}\nFigure \\ref{line:detect2}, \\ref{line:detect4}, \\ref{line:detect6} and \\ref{line:detect8} plot the  0,90,45,135 lines detection that I got on an image.\n%I looked for horizontal lines on the house image. The result I got for this image convolution was: \n\\begin{figure}[!ht]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/line-detection-0-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/line-detection-0.png}\n\t} \n\t\\caption{~~A horizontal line detection done with convolutions.}\n\t\\label{line:detect2}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\subfigure[image]{\n%\t\t%\\label{fig:subfig:a} %% label for first subfigure\n%\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n%\t}\n%\t%\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t%\t\\includegraphics[width=1in]{xu-0401/line-detection-0-k.png}\n%\t%}\n%\t\\subfigure[result]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_line_0.png}\n%\t}\n%\t\\caption{~~A horizontal line detection for Lena.}\n%\t\\label{line:detect3}\n%\t%\\label{fig:subfig} %% label for entire figure\n%\\end{figure}\nIn Figure \\ref{line:detect4}, the black background is the original result, the white background is obtained by subtracting the original result from 255, the same below.\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/line-detection-90-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/line-detection-90.png}\n\t}\n\t\\caption{~~A vertical line detection done with convolutions.}\n\t\\label{line:detect4}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\subfigure[image]{\n%\t\t%\\label{fig:subfig:a} %% label for first subfigure\n%\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n%\t}\n%\t%\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t%\t\\includegraphics[width=1.0in]{xu-0401/line-detection-90-k.png}\n%\t%}\n%\t\\subfigure[result]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_line_90.png}\n%\t} \n%\t\\caption{~~A vertical line detection for Lena.}\n%\t\\label{line:detect5}\n%\t%\\label{fig:subfig} %% label for entire figure\n%\\end{figure}\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/line-detection-45-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/line-detection-45.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\t\\caption{~~A 45 degree line detection done with convolutions.}\n\t\\label{line:detect6}\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\subfigure[image]{\n%\t\t%\\label{fig:subfig:a} %% label for first subfigure\n%\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n%\t}\n%\t%\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t%\t\\includegraphics[width=1.0in]{xu-0401/line-detection-45-k.png}\n%\t%}\n%\t\\subfigure[result]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_line_45.png}\n%\t}\n%\t\\caption{~~A 45 degree line detection done with convolutions} \n%\t\\label{line:detect7}\n%\t%\\label{fig:subfig} %% label for entire figure\n%\t\n%\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/line-detection-135-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/line-detection-135.png}\n\t}\n\t\\caption{~~A 135 degree line detection done with convolutions.}\n\t\\label{line:detect8}\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\subfigure[image]{\n%\t\t%\\label{fig:subfig:a} %% label for first subfigure\n%\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n%\t}\n%\t%\\subfigure[filter]{\n%%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%%\t\t\\includegraphics[width=1.0in]{xu-0401/line-detection-135-k.png}\n%\t%}\n%\t\\subfigure[result]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_line_135.png}\n%\t}\n%\t\\caption{~~A 135 degree line detection done with convolutions.} \n%\t\\label{line:detect9}\n%\t%\\label{fig:subfig} %% label for entire figure\n%\\end{figure}\n\n\n\\subsection{Edge detection by 2D Laplacian operator}\nThe laplacian is the second derivative of the image. It is extremely sensitive to noise, so it isn't used as much as other operators. Unless, of course you have specific requirements.\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=.5\\textwidth]{6DL/figures/conv-laplacian.jpg}\\\\\n\\end{figure}\n\nHere's the result of the convolution kernel without diagonals:\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/laplace-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/laplace.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n\t%\t\\subfigure[filter]{\n\t%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t%\t\t\\includegraphics[width=1.0in]{xu-0401/laplace-k.png}\n\t%\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_laplace.png}\n\t}\n\t\\caption{~~A laplace operator done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\nBelow is the result of the convolution kernel with diagonals.\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/laplace-diag-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/laplace-diag.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n\t%\t\\subfigure[filter]{\n\t%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t%\t\t\\includegraphics[width=1.0in]{xu-0401/laplace-diag-k.png}\n\t%\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_laplace_diag.png}\n\t}\n\t\\caption{~~A laplace operator including diagonals are done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\subsection{The Laplacian of Gaussian}\nThe laplacian alone has the disadvantage of being extremely sensitive to noise. So, smoothing the image before a laplacian improves the results we get. This is done with a 5x5 image convolution kernel.\n\\begin{table}[!htbp]\n\t\\centering\n\t\\begin{tabular}{|l|l|l|l|l|}\n\t\t\\hline\n\t\t0  & 0  & -1 & 0  & 0  \\\\ \\hline\n\t\t0  & -1 & -2 & -1 & 0  \\\\ \\hline\n\t\t-1 & -2 & 16 & -2 & -1 \\\\ \\hline\n\t\t0  & -1 & -2 & -1 & 0  \\\\ \\hline\n\t\t0  & 0  & -1 & 0  & 0  \\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\nBelow is the result by applying this image convolution.\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/Laplacian-of-Gaussian-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/Laplacian-of-Gaussian.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n\t%\t\\subfigure[filter]{\n\t%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t%\t\t\\includegraphics[width=1.0in]{xu-0401/Laplacian-of-Gaussian-k.png}\n\t%\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_laplace_gaussian.png}\n\t}\n\t\\caption{~~A Laplacian of Gaussian operator done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\subsection{Other examples with ReLU activation}\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[input image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/obama.png}\n\t}\n\t\\quad \n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/Laplacian-of-Gaussian-k.png}\n\t}\n\t\\quad\n\t\\subfigure[convolution result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/o_conv.png}\n\t}\n\t\\\\\n\t\\subfigure[result after ReLU]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/o_relu.png}\n\t}\n\t\\quad\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/blur--.png}\n\t}\n\t\\quad\n\t\\subfigure[result after average]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/o_avg.png}\n\t}\n\t%\\caption{~~A Laplacian of Gaussian operator done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n%\\begin{figure}[H]\n%\t\\centering\n%\t\\subfigure[image]{\n%\t\t%\\label{fig:subfig:a} %% label for first subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/trump.png}\n%\t}\n%\t\\quad \n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/Laplacian-of-Gaussian-k.png}\n%\t}\n%\t\\quad\n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/t_conv.png}\n%\t}\\\\\n%\t\\subfigure[ReLU]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/t_relu.png}\n%\t}\n%\t\\quad\n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/blur--.png}\n%\t}\n%\t\\quad\n%\t\\subfigure[average]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=.25\\textwidth]{6DL/figures/xu-0401/t_avg.png}\n%\t}\n%\t%\\caption{~~A Laplacian of Gaussian operator done with convolutions}\n%\t%\\label{fig:subfig} %% label for entire figure\n%\\end{figure}\n\n\n\\iffalse\n\\subsection{Some other examples}\n\n\\subsubsection{Edge detection}\nThe above kernels are in a way edge detectors. Only difference between the kernels is that they have separate components for horizontal and vertical lines. A way to \"combine\" the results is to merge the convolution kernels. The new image convolution kernel looks like this:\n\\begin{table}[!htbp]\n\t\\centering\n\t\\begin{tabular}{|l|l|l|}\n\t\t\\hline\n\t\t-1 & -1 & -1 \\\\ \\hline\n\t\t-1 & 8  & -1 \\\\ \\hline\n\t\t-1 & -1 & -1 \\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\nBelow result I got with edge detection:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/edge-detection-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/edge-detection.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=1.0in]{xu-0401/edge-detection-k.png}\n\t%}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_edge_detection.png}\n\t}\n\t\\caption{~~A edge detection done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\n\\subsubsection{The Sobel Edge Operator}\nThe above operators are very prone to noise. The Sobel edge operators have a smoothing effect, so they're less affected to noise. Again, there's a horizontal component and a vertical component.\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=.4\\textwidth]{6DL/figures/sobel}\\\\\n\\end{figure}\n\nOn applying horizontal component in image , the result was:\\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/sobel-detection-0-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/sobel-detection-0.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=1.0in]{xu-0401/sobel-detection-0-k.png}\n\t%}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_sobel_0.png}\n\t}\n\t\\caption{~~A horizontal sobel edge operator done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\nOn applying vertical component in image , the result was:\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/sobel-detection-90-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/sobel-detection-90.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n%\t\\subfigure[filter]{\n%\t\t%\\label{fig:subfig:b} %% label for second subfigure\n%\t\t\\includegraphics[width=1.0in]{xu-0401/sobel-detection-90-k.png}\n\t%}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=2.6in]{6DL/figures/xu-0401/lena_sobel_90.png}\n\t}\n\t\\caption{~~A vertical sobel edge operator done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\n\n\n\n\n\n\\subsubsection{Simple box blur}\\footnote{The following examples are from the website, http://aishack.in/tutorials/image-convolution-examples/ }\nHere's a first and simplest example. This convolution kernel has an averaging effect. So you end up with a slight blur. The image convolution kernel is:\n\\begin{table}[!htbp]\n\t\\centering\n\t\\begin{tabular}{|l|l|l|}\n\t\t\\hline\n\t\t1/9 & 1/9 & 1/9 \\\\ \\hline\n\t\t1/9 & 1/9 & 1/9 \\\\ \\hline\n\t\t1/9 & 1/9 & 1/9 \\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\nNote that the sum of all elements of this matrix is 1.0. This is important. If the sum is not exactly one, the resultant image will be brighter or darker.\n\nHere's a blur that I got on an image:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/blur--.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/blur.png}\n\t}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/blur--.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena_blur.png}\n\t}\n\t\\caption{~~A simple blur done with convolutions}\n\t%\\label{fig:subfig} %% label for entire figure\n\\end{figure}\n\n\\subsubsection{Gaussian blur}\nGaussian blur has certain mathematical properties that makes it important for computer vision. And you can approximate it with an image convolution. The image convolution kernel for a Gaussian blur is in Table \\ref{Gaussianblur}. The result in shown in Figure \\ref{lena:Gaussian}.\n\\begin{table}[!ht]\n\t\\centering\n\t\\begin{tabular}{|l|l|l|l|l|l|l|}\n\t\t\\hline\n\t\t0 & 0  & 0   & 5   & 0   & 0  & 0 \\\\ \\hline\n\t\t0 & 5  & 18  & 32  & 18  & 5  & 0 \\\\ \\hline\n\t\t0 & 18 & 64  & 100 & 64  & 18 & 0 \\\\ \\hline\n\t\t5 & 32 & 100 & 100 & 100 & 32 & 5 \\\\ \\hline\n\t\t0 & 18 & 64  & 100 & 64  & 18 & 0 \\\\ \\hline\n\t\t0 & 5  & 18  & 32  & 18  & 5  & 0 \\\\ \\hline\n\t\t0 & 0  & 0   & 5   & 0   & 0  & 0 \\\\ \\hline\n\t\\end{tabular}\n\t\\caption{The image convolution kernel for a Gaussian blur.}\n\t\\label{Gaussianblur}\n\\end{table}\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/image.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/g-blut-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/Gaussian-blur.png}\n\t}\n\t%\\caption{A Gaussian blur done with convolutions}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\subfigure[image]{\n\t\t%\\label{fig:subfig:a} %% label for first subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena.png}\n\t}\n\t\\subfigure[filter]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.0in]{6DL/figures/xu-0401/g-blut-k.png}\n\t}\n\t\\subfigure[result]{\n\t\t%\\label{fig:subfig:b} %% label for second subfigure\n\t\t\\includegraphics[width=1.3in]{6DL/figures/xu-0401/lena_G_blur.png}\n\t}\n\t\\caption{~~A Gaussian blur done with convolutions}\n\t\\label{lena:Gaussian}\n\\end{figure}\n\n\\fi\n\n\\subsection{Summary}\nThese examples show  how different convolution kernels modify an image in different ways. Note that the filter plays an important role in detecting edges on an image.\n", "meta": {"hexsha": "8ca6f0f4f545ea523e1c2b60b804b23447f44553", "size": 22718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/convolution-filter.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/convolution-filter.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/convolution-filter.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.1751592357, "max_line_length": 368, "alphanum_fraction": 0.721850515, "num_tokens": 7826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6308902164014946}}
{"text": "\\chapter[Bonus: A hint of p-adic numbers]{Bonus: A hint of $p$-adic numbers}\nThis is a bonus chapter meant for those\nwho have also read about \\textbf{rings and fields}:\nit's a nice tidbit at the intersection of algebra and analysis.\n\n\nIn this chapter, we are going to redo most of the previous chapter\nwith the absolute value $\\left\\lvert - \\right\\rvert$\nreplaced by the $p$-adic one.\nThis will give us the $p$-adic integers $\\ZZ_p$,\nand the $p$-adic numbers $\\QQ_p$.\nThe one-sentence description is that these are\n``integers/rationals carrying full mod $p^e$ information''\n(and only that information).\n\nIn everything that follows $p$ is always assumed to denote a prime.\nThe first four sections will cover the founding definitions\nculminating in a short solution to a USA TST problem.\nWe will then state (mostly without proof) some more\nsurprising results about continuous functions $f \\colon \\ZZ_p \\to \\QQ_p$;\nfinally we close with the famous proof of the Skolem-Mahler-Lech theorem\nusing $p$-adic analysis.\n\n%In this whole post, $p$ is always a prime.\n%Much of this is based off of Chapter 3A from\n%\\emph{Straight from the Book}.\n\n\\section{Motivation}\nBefore really telling you what $\\ZZ_p$ and $\\QQ_p$ are,\nlet me tell you what you might expect them to do.\n\nIn elementary/olympiad number theory,\nwe're already well-familiar with the following two ideas:\n\\begin{itemize}\n\t\\ii Taking modulo a prime $p$ or prime $p^e$, and\n\t\\ii Looking at the exponent $\\nu_p$.\n\\end{itemize}\n\nLet me expand on the first point.\nSuppose we have some Diophantine equation.\nIn olympiad contexts, one can take an equation modulo $p$\nto gain something else to work with.\nUnfortunately, taking modulo $p$ loses some information:\nthe reduction $\\ZZ \\surjto \\ZZ/p$ is far from injective.\n\nIf we want finer control, we could consider instead\ntaking modulo $p^2$, rather than taking modulo $p$.\nThis can also give some new information (cubes modulo $9$, anyone?),\nbut it has the disadvantage that $\\ZZ/p^2$ isn't a field,\nso we lose a lot of the nice algebraic properties that we\ngot if we take modulo $p$.\n\nOne of the goals of $p$-adic numbers is that we can get around\nthese two issues I described.\nThe $p$-adic numbers we introduce is going to have the following properties:\n\\begin{enumerate}\n\t\\ii \\textbf{You can ``take modulo $p^e$ for all $e$ at once''.}\n\tIn olympiad contexts, we are used to picking a particular modulus and then\n\tseeing what happens if we take that modulus.\n\tBut with $p$-adic numbers, we won't have to make that choice.\n\tAn equation of $p$-adic numbers carries enough information\n\tto take modulo $p^e$.\n\t\\ii \\textbf{The numbers $\\QQ_p$ form a field},\n\tthe nicest possible algebraic structure:\n\t$1/p$ makes sense.\n\tContrast this with $\\ZZ/p^2$, which is not even an integral domain.\n\t\\ii \\textbf{It doesn't lose as much information}\n\tas taking modulo $p$ does:\n\trather than the surjective $\\ZZ \\surjto \\ZZ/p$ we have an\n\t\\emph{injective} map $\\ZZ \\injto \\ZZ_p$.\n\t\\ii \\textbf{Despite this, you ``ignore'' some ``irrelevant'' data}.\n\tJust like taking modulo $p$, you want to zoom-in on\n\ta particular type of algebraic information,\n\tand this means necessarily\n\tlosing sight of other things.\\footnote{To draw an analogy: the equation\n\t$ a^2 + b^2 + c^2 + d^2 = -1$\n\thas no integer solutions, because, well, squares are nonnegative.\n\tBut you will find that this equation has solutions modulo any prime $p$,\n\tbecause once you take modulo $p$ you stop being able to\n\ttalk about numbers being nonnegative.\n\tThe same thing will happen if we work in $p$-adics:\n\tthe above equation has a solution in $\\ZZ_p$ for every prime $p$.}\n\\end{enumerate}\nSo, you can think of $p$-adic numbers as the right tool to use\nif you only really care about modulo $p^e$ information,\nbut normal $\\ZZ/p^e$ isn't quite powerful enough.\n\nTo be more concrete, I'll give a poster example now:\n\\begin{example}\n\t[USA TST 2002/2]\n\tFor a prime $p$, show the value of\n\t\\[ f_p(x) = \\sum_{k=1}^{p-1} \\frac{1}{(px+k)^2} \\pmod{p^3} \\]\n\tdoes not depend on $x$.\n\t\\label{ex:token}\n\\end{example}\nHere is a problem where we \\emph{clearly} only care\nabout $p^e$-type information.\nYet it's a nontrivial challenge to do the\nnecessary manipulations mod $p^3$ (try it!).\nThe basic issue is that there is no good way to deal with\nthe denominators modulo $p^3$\n(in part $\\ZZ/p^3$ is not even an integral domain).\n\nHowever, with $p$-adic analysis we're going to be able\nto overcome these limitations and give a ``straightforward'' proof\nby using the identity\n\\[\n\t\\left( 1 + \\frac{px}{k} \\right)^{-2}\n\t= \\sum_{n \\ge 0} \\binom{-2}{n} \\left( \\frac{px}{k} \\right)^n.\n\\]\nSuch an identity makes no sense over $\\QQ$ or $\\RR$\nfor convergence reasons,\nbut it will work fine over the $\\QQ_p$, which is all we need.\n\n\n\\section{Algebraic perspective}\n\\prototype{$-1/2 = 1 + 3 + 3^2 + 3^3 + \\dots \\in \\ZZ_3$.}\nWe now construct $\\ZZ_p$ and $\\QQ_p$.\nI promised earlier that a $p$-adic integer will let you look at\n``all residues modulo $p^e$'' at once.\nThis definition will formalize this.\n\n\\subsection{Definition of $\\ZZ_p$}\n\\begin{definition}\n\t[Introducing $\\ZZ_p$]\n\tA \\vocab{$p$-adic integer} is a sequence\n\t\\[ x = (x_1 \\bmod p, \\; x_2 \\bmod{p^2}, \\; x_3 \\bmod{p^3}, \\; \\dots) \\]\n\tof residues $x_e$ modulo $p^e$ for each integer $e$,\n\tsatisfying the compatibility relations\n\t$x_i \\equiv x_j \\pmod{p^i}$ for $i < j$.\n\n\tThe set $\\ZZ_p$ of $p$-adic integers forms a ring\n\tunder component-wise addition and multiplication.\n\\end{definition}\n\n\\begin{example}\n\t[Some $3$-adic integers]\n\tLet $p=3$.\n\tEvery usual integer $n$ generates\n\ta (compatible) sequence of residues modulo $p^e$ for each $e$,\n\tso we can view each ordinary integer as $p$-adic one:\n\t\\[ 50 = \\left( 2 \\bmod 3, \\; 5 \\bmod 9, \\;\n\t\t23 \\bmod{27}, \\; 50 \\bmod{81}, \\; 50 \\bmod{243}, \\; \\dots \\right). \\]\n\tOn the other hand, there are sequences of residues\n\twhich do not correspond to any usual integer despite\n\tsatisfying compatibility relations, such as\n\t\\[ \\left( 1 \\bmod 3, \\; 4 \\bmod 9, \\;\n\t\t13 \\bmod{27}, \\; 40 \\bmod{81}, \\; \\dots \\right) \\]\n\twhich can be thought of as $x = 1 + p + p^2 + \\dots$.\n\\end{example}\nIn this way we get an injective map\n\\[ \\ZZ \\injto \\ZZ_p \\qquad\n\tn \\mapsto \\left( n \\bmod p, n \\bmod{p^2}, n \\bmod{p^3}, \\dots \\right) \\]\nwhich is not surjective.\nSo there are more $p$-adic integers than usual integers.\n\n(Remark for experts:\nthose of you familiar with category theory might recognize\nthat this definition can be written concisely as\n\\[ \\ZZ_p \\defeq \\varprojlim \\ZZ/p^e \\ZZ \\]\nwhere the inverse limit is taken across $e \\ge 1$.)\n\n\\begin{exercise}\n\tCheck that $\\ZZ_p$ is an integral domain.\n\\end{exercise}\n\n\\subsection{Base $p$ expansion}\nHere is another way to think about $p$-adic integers using ``base $p$''.\nAs in the example earlier, every usual integer can be written in base $p$,\nfor example\n\\[ 50 = \\ol{1212}_3 = 2 \\cdot 3^0 + 1 \\cdot 3^1 + 2 \\cdot 3^2 + 1 \\cdot 3^3. \\]\nMore generally, given any $x = (x_1, \\dots) \\in \\ZZ_p$,\nwe can write down a ``base $p$'' expansion in the sense\nthat there are exactly $p$ choices of $x_k$ given $x_{k-1}$.\nContinuing the example earlier, we would write\n\\begin{align*}\n\t\\left( 1 \\bmod 3, \\; 4 \\bmod 9, \\;\n\t13 \\bmod{27}, \\; 40 \\bmod{81}, \\; \\dots \\right)\n\t&= 1 + 3 + 3^2 + \\dots \\\\\n\t&= \\ol{\\dots1111}_3\n\\end{align*}\nand in general we can write\n\\[ x = \\sum_{k \\ge 0} a_k p^k = \\ol{\\dots a_2 a_1 a_0}_p \\]\nwhere $a_k \\in \\{0, \\dots, p-1\\}$,\nsuch that the equation holds modulo $p^e$ for each $e$.\nNote the expansion is infinite to the \\emph{left},\nwhich is different from what you're used to.\n\n(Amusingly, negative integers also have infinite base $p$ expansions:\n$-4 = \\ol{\\dots222212}_3$, corresponding to\n$(2 \\bmod 3, \\; 5 \\bmod 9, \\; 23 \\bmod{27}, \\; 77 \\bmod{81} \\dots)$.)\n\nThus you may often hear the advertisement that a $p$-adic integer\nis an ``possibly infinite base $p$ expansion''.\nThis is correct, but later on we'll be thinking of $\\ZZ_p$ in\na more and more ``analytic'' way,\nand so I prefer to think of this as\n\\begin{moral}\n\t$p$-adic integers are Taylor series with base $p$.\n\\end{moral}\nIndeed, much of your intuition from generating functions $K[[X]]$\n(where $K$ is a field) will carry over to $\\ZZ_p$.\n\n\\subsection{Constructing $\\QQ_p$}\nHere is one way in which your intuition from generating functions carries over:\n\\begin{proposition}\n\t[Non-multiples of $p$ are all invertible]\n\tThe number $x \\in \\ZZ_p$ is invertible if and only if $x_1 \\ne 0$.\n\tIn symbols,\n\t\\[ x \\in \\ZZ_p^\\times \\iff x \\not\\equiv 0 \\pmod p. \\]\n\\end{proposition}\nContrast this with the corresponding statement for $K[ [ X ] ]$:\na generating function $F \\in K[ [ X ] ]$ is invertible iff $F(0) \\neq 0$.\n\n\\begin{proof}\n\tIf $x \\equiv 0 \\pmod p$ then $x_1 = 0$,\n\tso clearly not invertible.\n\tOtherwise, $x_e \\not\\equiv 0 \\pmod p$ for all $e$,\n\tso we can take an inverse $y_e$ modulo $p^e$,\n\twith $x_e y_e \\equiv 1 \\pmod{p^e}$.\n\tAs the $y_e$ are themselves compatible,\n\tthe element $(y_1, y_2, \\dots)$ is an inverse.\n\\end{proof}\n\\begin{example}\n\t[We have $-\\half = \\ol{\\dots1111}_3 \\in \\ZZ_3$]\n\tWe claim the earlier example is actually\n\t\\begin{align*}\n\t-\\half = \\left( 1 \\bmod 3, \\; 4 \\bmod 9, \\;\n\t13 \\bmod{27}, \\; 40 \\bmod{81}, \\; \\dots \\right)\n\t&= 1 + 3 + 3^2 + \\dots \\\\\n\t&= \\ol{\\dots1111}_3.\n\t\\end{align*}\n\tIndeed, multiplying it by $-2$ gives\n\t\\[ \\left( -2 \\bmod 3, \\; -8 \\bmod 9, \\;\n\t\t-26 \\bmod{27}, \\; -80 \\bmod{81}, \\; \\dots \\right)\n\t\t= 1. \\]\n\t(Compare this with the ``geometric series''\n\t$1 + 3 + 3^2 + \\dots = \\frac{1}{1-3}$.\n\tWe'll actually be able to formalize this later, but not yet.)\n\\end{example}\n\\begin{remark}\n\t[$\\half$ is an integer for $p > 2$]\n\tThe earlier proposition implies that $\\half \\in \\ZZ_3$\n\t(among other things);\n\tyour intuition about what is an ``integer'' is different here!\n\tIn olympiad terms, we already knew $\\half \\pmod 3$ made sense,\n\twhich is why calling $\\half$ an ``integer''\n\tin the $3$-adics is correct,\n\teven though it doesn't correspond to any element of $\\ZZ$.\n\\end{remark}\n\\begin{exercise}\n\t[Unimportant but tricky]\n\tRational numbers correspond exactly to\n\teventually periodic base $p$ expansions.\n\\end{exercise}\n\nWith this observation, here is now the definition of $\\QQ_p$.\n\\begin{definition}\n\t[Introducing $\\QQ_p$]\n\tSince $\\ZZ_p$ is an integral domain,\n\twe let $\\QQ_p$ denote its field of fractions.\n\tThese are the \\vocab{$p$-adic numbers}.\n\\end{definition}\nContinuing our generating functions analogy:\n\\[ \\ZZ_p \\text{ is to } \\QQ_p\n\t\\quad\\text{as}\\quad\n\tK[[X]] \\text{ is to } K((X)). \\]\nThis means\n\\begin{moral}\n\t$\\QQ_p$ can be thought of as Laurent series with base $p$.\n\\end{moral}\nand in particular according to the earlier proposition we deduce:\n\\begin{proposition}\n\t[$\\QQ_p$ looks like formal Laurent series]\n\tEvery nonzero element of $\\QQ_p$ is uniquely of the form\n\t\\[ p^k u \\qquad \\text{ where } k \\in \\ZZ, \\; u \\in \\ZZ_p^\\times. \\]\n\\end{proposition}\nThus, continuing our base $p$ analogy,\nelements of $\\QQ_p$ are in bijection with ``Laurent series''\n\\[ \\sum_{k \\ge -n} a_k p^k\n\t= \\ol{\\dots a_2 a_1 a_0 . a_{-1} a_{-2} \\dots a_{-n}}_p \\]\nfor $a_k \\in \\left\\{ 0, \\dots, p-1 \\right\\}$.\nSo the base $p$ representations of elements of $\\QQ_p$\ncan be thought of as the same as usual,\nbut extending infinitely far to the left\n(rather than to the right).\n\n\\begin{remark}\n\t[Warning]\n\tThe field $\\QQ_p$ has characteristic \\emph{zero}, not $p$.\n\\end{remark}\n\\begin{remark}\n\t[Warning on fraction field]\n\tThis result implies that you shouldn't think about elements of $\\QQ_p$\n\tas $x/y$ (for $x,y \\in \\ZZ_p$) in practice,\n\teven though this is the official definition\n\t(and what you'd expect from the name $\\QQ_p$).\n\tThe only denominators you need are powers of $p$.\n\n\tTo keep pushing the formal Laurent series analogy,\n\t$K((X))$ is usually not thought of as quotient of generating functions\n\tbut rather as ``formal series with some negative exponents''.\n\tYou should apply the same intuition on $\\QQ_p$.\n\\end{remark}\n\n\\begin{remark}\nAt this point I want to make a remark about the fact $1/p \\in \\QQ_p$,\nconnecting it to the wish-list of properties I had before.\nIn elementary number theory you can take equations modulo $p$,\nbut if you do the quantity $n/p \\bmod{p}$ doesn't make sense\nunless you know $n \\bmod{p^2}$.\nYou can't fix this by just taking modulo $p^2$\nsince then you need $n \\bmod{p^3}$ to get $n/p \\bmod{p^2}$, ad infinitum.\nYou can work around issues like this,\nbut the nice feature of $\\ZZ_p$ and $\\QQ_p$\nis that you have modulo $p^e$ information for ``all $e$ at once'':\nthe information of $x \\in \\QQ_p$ packages all the modulo $p^e$\ninformation simultaneously.\nSo you can divide by $p$ with no repercussions.\n\\end{remark}\n\n\n\\section{Analytic perspective}\n\\subsection{Definition}\nUp until now we've been thinking about things mostly algebraically,\nbut moving forward it will be helpful to start using the language of analysis.\nUsually, two real numbers are considered ``close'' if\nthey are close on the number of line,\nbut for $p$-adic purposes we only care about modulo $p^e$ information.\nSo, we'll instead think of two elements of $\\ZZ_p$ or $\\QQ_p$\nas ``close'' if they differ by a large multiple of $p^e$.\n\nFor this we'll borrow the familiar $\\nu_p$ from elementary number theory.\n\\begin{definition}\n\t[$p$-adic valuation and absolute value]\n\tWe define the \\vocab{$p$-adic valuation} $\\nu_p : \\QQ_p^\\times \\to \\ZZ$\n\tin the following two equivalent ways:\n\t\\begin{itemize}\n\t\t\\ii For $x = (x_1, x_2, \\dots) \\in \\ZZ_p$ we let\n\t\t$\\nu_p(x)$ be the largest $e$ such that\n\t\t$x_e \\equiv 0 \\pmod{p^e}$ (or $e=0$ if $x \\in \\ZZ_p^\\times$).\n\t\tThen extend to all of $\\QQ_p^\\times$\n\t\tby $\\nu_p(xy) = \\nu_p(x) + \\nu_p(y)$.\n\t\t\\ii Each $x \\in \\QQ_p^\\times$ can be written\n\t\tuniquely as $p^k u$ for $u \\in \\ZZ_p^\\times$, $k \\in \\ZZ$.\n\t\tWe let $\\nu_p(x) = k$.\n\t\\end{itemize}\n\tBy convention we set $\\nu_p(0) = +\\infty$.\n\tFinally, define the \\vocab{$p$-adic absolute value}\n\t$\\left\\lvert \\bullet \\right\\rvert_p$ by\n\t\\[ \\left\\lvert x \\right\\rvert_p = p^{-\\nu_p(x)}. \\]\n\tIn particular $\\left\\lvert 0 \\right\\rvert_p = 0$.\n\\end{definition}\nThis fulfills the promise that $x$ and $y$ are close\nif they look the same modulo $p^e$ for large $e$;\nin that case $\\nu_p(x-y)$ is large\nand accordingly $\\left\\lvert x-y \\right\\rvert_p$ is small.\n\n\\subsection{Ultrametric space}\nIn this way, $\\QQ_p$ and $\\ZZ_p$ becomes a metric space\nwith metric given by $\\left\\lvert x-y \\right\\rvert_p$.\n\n\\begin{exercise}\n\t\\label{exer:alternating}\n\tSuppose $f \\colon \\ZZ_p \\to \\QQ_p$ is continuous\n\tand $f(n) = (-1)^n$ for every $n \\in \\ZZ_{\\ge 0}$.\n\tProve that $p = 2$.\n\\end{exercise}\n\nIn fact, these spaces satisfy a stronger\nform of the triangle inequality than you are used to from $\\RR$.\n\\begin{proposition}\n\t[$\\left\\lvert \\bullet \\right\\rvert_p$ is an ultrametric]\n\tFor any $x,y \\in \\ZZ_p$, we have the \\vocab{strong triangle inequality}\n\t\\[ \\left\\lvert x+y \\right\\rvert_p\n\t\t\\le \\max \\left\\{ \\left\\lvert x \\right\\rvert_p,\n\t\t\\left\\lvert y \\right\\rvert_p \\right\\}.\n\t\\]\n\tEquality holds if (but not only if)\n\t$\\left\\lvert x \\right\\rvert_p \\neq \\left\\lvert y \\right\\rvert_p$.\n\\end{proposition}\n\nHowever, $\\QQ_p$ is more than just a metric space:\nit is a field, with its own addition and multiplication.\nThis means we can do analysis just like in $\\RR$ or $\\CC$:\nbasically, any notion such as ``continuous function'',\n``convergent series'', et cetera has a $p$-adic analog.\nIn particular, we can define what it means for an infinite sum to converge:\n\\begin{definition}\n\t[Convergence notions]\n\tHere are some examples of $p$-adic analogs of ``real-world'' notions.\n\t\\begin{itemize}\n\t\t\\ii A sequence $s_1$, \\dots converges to a limit $L$\n\t\tif $\\lim_{n \\to \\infty} \\left\\lvert s_n - L \\right\\rvert_p = 0$.\n\t\t\\ii The infinite series $\\sum_k x_k$ converges\n\t\tif the sequence of partial sums $s_1 = x_1$,\n\t\t$s_2 = x_1 + x_2$, \\dots, converges to some limit.\n\t\t\\ii \\dots et cetera \\dots\n\t\\end{itemize}\n\\end{definition}\nWith this definition in place,\nthe ``base $p$'' discussion we had earlier is now true\nin the analytic sense: if $x = \\ol{\\dots a_2 a_1 a_0}_p \\in \\ZZ_p$ then\n\\[ \\sum_{k=0}^\\infty a_k p^k \\quad\\text{converges to } x. \\]\nIndeed, the difference between $x$ and the $n$th partial sum is divisible by $p^n$,\nhence the partial sums approach $x$ as $n \\to \\infty$.\n\nWhile the definitions are all the same,\nthere are some changes in properties that should be true.\nFor example, in $\\QQ_p$ convergence of partial sums is simpler:\n\\begin{proposition}\n\t[$|x_k|_p \\to 0$ iff convergence of series]\n\tA series $\\sum_{k=1}^\\infty x_k$ in $\\QQ_p$\n\tconverges to some limit if and only if\n\t$\\lim_{k \\to \\infty} |x_k|_p = 0$.\n\t\\label{noharmonic}\n\\end{proposition}\nContrast this with $\\sum \\frac1n = \\infty$ in $\\RR$.\nYou can think of this as a consequence of strong triangle inequality.\n\\begin{proof}\n\tBy multiplying by a large enough power of $p$,\n\twe may assume $x_k \\in \\ZZ_p$.\n\t(This isn't actually necessary, but makes the notation nicer.)\n\n\tObserve that $x_k \\pmod p$ must eventually stabilize,\n\tsince for large enough $n$ we have\n\t$\\left\\lvert x_n \\right\\rvert_p < 1 \\iff \\nu_p(x_n) \\ge 1$.\n\tSo let $a_1$ be the eventual residue modulo $p$\n\tof $\\sum_{k=0}^N x_k \\pmod p$ for large $N$.\n\tIn the same way let $a_2$ be the eventual residue modulo $p^2$, and so on.\n\tThen one can check we approach the limit $a = (a_1, a_2, \\dots)$.\n\\end{proof}\n\n\\subsection{More fun with geometric series}\nLet's finally state the $p$-adic analog of the geometric series formula.\n\n\\begin{proposition}\n\t[Geometric series]\n\tLet $x \\in \\ZZ_p$ with $\\left\\lvert x \\right\\rvert_p < 1$.\n\tThen \\[ \\frac{1}{1-x} = 1 + x + x^2 + x^3 + \\dots. \\]\n\\end{proposition}\n\\begin{proof}\n\tNote that the partial sums satisfy\n\t$1 + x + x^2 + \\dots + x^n = \\frac{1-x^n}{1-x}$,\n\tand $x^n \\to 0$ as $n \\to \\infty$ since\n\t$\\left\\lvert x \\right\\rvert_p < 1$.\n\\end{proof}\n\nSo, $1 + 3 + 3^2 + \\dots = -\\half$ is really a correct convergence\nin $\\ZZ_3$.\nAnd so on.\n\nIf you buy the analogy that $\\ZZ_p$ is generating functions\nwith base $p$, then all the olympiad generating functions\nyou might be used to have $p$-adic analogs.\nFor example, you can prove more generally that:\n\\begin{theorem}\n\t[Generalized binomial theorem]\n\tIf $x \\in \\ZZ_p$ and $\\left\\lvert x \\right\\rvert_p < 1$,\n\tthen for any $r \\in \\QQ$ we have the series convergence\n\t\\[ \\sum_{n \\ge 0} \\binom rn x^n = (1+x)^r. \\]\n\\end{theorem}\n(I haven't defined $(1+x)^r$, but it has the properties you expect.)\n\n\\subsection{Completeness}\nNote that the definition of $\\left\\lvert \\bullet \\right\\rvert_p$\ncould have been given for $\\QQ$ as well;\nwe didn't need $\\QQ_p$ to introduce it\n(after all, we have $\\nu_p$ in olympiads already).\nThe big important theorem I must state now is:\n\\begin{theorem}\n\t[$\\QQ_p$ is complete]\n\tThe space $\\QQ_p$ is the completion of $\\QQ$\n\twith respect to $\\left\\lvert \\bullet \\right\\rvert_p$.\n\\end{theorem}\nThis is the definition of $\\QQ_p$ you'll see more frequently;\none then defines $\\ZZ_p$ in terms of $\\QQ_p$\n(rather than vice-versa) according to\n\\[ \\ZZ_p = \\left\\{ x \\in \\QQ_p :\n\t\\left\\lvert x \\right\\rvert_p \\le 1 \\right\\}. \\]\n\n\\subsection{Philosophical notes}\nLet me justify why this definition is philosophically nice.\nSuppose you are an ancient Greek mathematician who is given:\n\\begin{quote}\n\t\\textbf{Problem for Ancient Greeks.}\n\tEstimate the value of the sum\n\t\\[ S = \\frac{1}{1^2} + \\frac{1}{2^2} + \\dots + \\frac{1}{10000^2} \\]\n\tto within $0.001$.\n\\end{quote}\nThe sum $S$ consists entirely of rational numbers,\nso the problem statement would be fair game for ancient Greece.\nBut it turns out that in order to get a good estimate,\nit \\emph{really helps} if you know about the real numbers:\nbecause then you can construct the infinite series\n$\\sum_{n \\ge 1} n^{-2} = \\frac16 \\pi^2$,\nand deduce that $S \\approx \\frac{\\pi^2}{6}$,\nup to some small error term from the terms past $\\frac{1}{10001^2}$,\nwhich can be bounded.\n\nOf course, in order to have access to enough theory\nto prove that $S = \\pi^2/6$, you need to have the real numbers;\nit's impossible to do calculus in $\\QQ$\n(the sequence $1$, $1.4$, $1.41$, $1.414$,\nis considered ``not convergent''!)\n\nNow fast-forward to 2002, and suppose you are given\n\\begin{quote}\n\t\\textbf{Problem from USA TST 2002.}\n\tEstimate the sum\n\t\\[ f_p(x) = \\sum_{k=1}^{p-1} \\frac{1}{(px+k)^2} \\]\n\tto within mod $p^3$.\n\\end{quote}\n% (i.e.\\ to within $p^{-3}$ in $\\left\\lvert \\bullet \\right\\rvert_p$).\nEven though $f_p(x)$ is a rational number,\nit still helps to be able to do analysis with infinite sums,\nand then bound the error term (i.e.\\ take mod $p^3$).\nBut the space $\\QQ$ is not complete with respect\nto $\\left\\lvert \\bullet \\right\\rvert_p$ either,\nand thus it makes sense to work in the completion of $\\QQ$\nwith respect to $\\left\\lvert \\bullet \\right\\rvert_p$.\nThis is exactly $\\QQ_p$.\n\nIn any case, let's finally solve \\Cref{ex:token}.\n\\begin{example}\n[USA TST 2002]\nWe will now compute\n\\[ f_p(x) = \\sum_{k=1}^{p-1} \\frac{1}{(px+k)^2} \\pmod{p^3}. \\]\nArmed with the generalized binomial theorem,\nthis becomes straightforward.\n\\begin{align*}\n\tf_p(x) &= \\sum_{k=1}^{p-1} \\frac{1}{(px+k)^2}\n\t= \\sum_{k=1}^{p-1} \\frac{1}{k^2}\n\t\\left( 1 + \\frac{px}{k} \\right)^{-2} \\\\\n\t&= \\sum_{k=1}^{p-1} \\frac{1}{k^2} \\sum_{n \\ge 0}\n\t\\binom{-2}{n} \\left( \\frac{px}{k} \\right)^{n} \\\\\n\t&= \\sum_{n \\ge 0} \\binom{-2}{n}\n\t\\sum_{k=1}^{p-1} \\frac{1}{k^2} \\left( \\frac{x}{k} \\right)^{n} p^n \\\\\n\t&\\equiv \\sum_{k=1}^{p-1} \\frac{1}{k^2}\n\t - 2x \\left( \\sum_{k=1}^{p-1} \\frac{1}{k^3} \\right) p\n\t + 3x^2 \\left( \\sum_{k=1}^{p-1} \\frac{1}{k^4} \\right) p^2 \\pmod{p^3}.\n\\end{align*}\nUsing the elementary facts that\n$p^2 \\mid \\sum_k k^{-3}$ and $p \\mid \\sum_k k^{-4}$,\nthis solves the problem.\n\\end{example}\n\n\n%\\section{Digression on $\\CC_p$}\n%Before I go on, I want to mention that $\\QQ_p$\n%is not algebraically closed.\n%So, we can take its algebraic closure $\\ol{\\QQ_p}$ --- but this\n%field is now no longer complete (in the topological sense).\n%However, we can then take the completion of this space\n%to obtain $\\CC_p$.\n%In general, completing an algebraically closed field\n%remains algebraically closed,\n%and so there is a larger space $\\CC_p$ which\n%is algebraically closed \\emph{and} complete.\n%This space is called the $p$-adic complex numbers.\n%\n%We won't need $\\CC_p$ at all in what follows,\n%so you can forget everything you just read.\n\n\\section{Mahler coefficients}\nOne of the big surprises of $p$-adic analysis is that:\n\\begin{moral}\n\tWe can basically describe all continuous functions $\\ZZ_p \\to \\QQ_p$.\n\\end{moral}\nThey are given by a basis of functions\n\\[ \\binom xn \\defeq \\frac{x(x-1) \\dots (x-(n-1))}{n!} \\]\nin the following way.\n\\begin{theorem}\n\t[Mahler; see {\\cite[Theorem 51.1, Exercise 51.b]{ref:schikof}}]\n\tLet $f \\colon \\ZZ_p \\to \\QQ_p$ be continuous, and define\n\t\\begin{equation}\n\t\ta_n = \\sum_{k=0}^n \\binom nk (-1)^{n-k} f(k).\n\t\t\\label{eq:mahler}\n\t\\end{equation}\n\tThen $\\lim_n a_n = 0$ and \\[ f(x) = \\sum_{n \\ge 0} a_n \\binom xn. \\]\n\n\tConversely, if $a_n$ is any sequence converging to zero,\n\tthen $f(x) = \\sum_{n \\ge 0} a_n \\binom xn$\n\tdefines a continuous function satisfying \\eqref{eq:mahler}.\n\t% true for C_p too\n\\end{theorem}\nThe $a_i$ are called the \\emph{Mahler coefficients} of $f$.\n\\begin{exercise}\n\tLast post we proved that if $f \\colon \\ZZ_p \\to \\QQ_p$ is continuous\n\tand $f(n) = (-1)^n$ for every $n \\in \\ZZ_{\\ge 0}$ then $p = 2$.\n\tRe-prove this using Mahler's theorem,\n\tand this time show conversely that a unique such $f$ exists when $p=2$.\n\\end{exercise}\n\nYou'll note that these are the same finite differences that one\nuses on polynomials in high school math contests,\nwhich is why they are also called ``Mahler differences''.\n\\begin{align*}\n\ta_0 &= f(0) \\\\\n\ta_1 &= f(1) - f(0) \\\\\n\ta_2 &= f(2) - 2f(1) + f(0) \\\\\n\ta_3 &= f(3) - 3f(2) + 3f(1) - f(0).\n\\end{align*}\nThus one can think of $a_n \\to 0$ as saying that\nthe values of $f(0)$, $f(1)$, \\dots behave like a polynomial modulo $p^e$\nfor every $e \\ge 0$.\n\nThe notion ``analytic'' also has a Mahler interpretation.\nFirst, the definition.\n\\begin{definition}\nWe say that a function $f \\colon \\ZZ_p \\to \\QQ_p$ is \\vocab{analytic}\nif it has a power series expansion\n\\[ \\sum_{n \\ge 0} c_n x^n \\quad c_n \\in \\QQ_p\n\t\\qquad\\text{ converging for } x \\in \\ZZ_p. \\]\n\\end{definition}\n\\begin{theorem}\n\t[{\\cite[Theorem 54.4]{ref:schikof}}]\n\tThe function $f(x) = \\sum_{n \\ge 0} a_n \\binom xn$ is analytic\n\tif and only if\n\t\\[ \\lim_{n \\to \\infty} \\frac{a_n}{n!} = 0. \\]\n\t% true for Q_p too\n\\end{theorem}\nAnalytic functions also satisfy the following niceness result:\n\\begin{theorem}\n\t[Strassmann's theorem]\n\tLet $f \\colon \\ZZ_p \\to \\QQ_p$ be analytic.\n\tThen $f$ has finitely many zeros.\n\t% should be true for \\CC_p? gdi\n\\end{theorem}\n\nTe give an application of these results,\nwe will prove the following result,\nwhich was interesting even before $p$-adics came along!\n\\begin{theorem}\n\t[Skolem-Mahler-Lech]\n\tLet $(x_i)_{i \\ge 0}$ be an integral linear recurrence,\n\tmeaning $(x_i)_{i \\ge 0}$ is a sequence of integers\n\t\\[ x_n = c_1 x_{n-1} + c_2 x_{n-2} + \\dots + c_k x_{n-k}\n\t\t\\qquad n = 1, 2, \\dots \\]\n\tholds for some choice of integers $c_1$, \\dots, $c_k$.\n\tThen the set of indices $\\{ i \\mid x_i = 0 \\}$\n\tis eventually periodic.\n\\end{theorem}\n\n\\begin{proof}\n\tAccording to the theory of linear recurrences,\n\tthere exists a matrix $A$ such that we can write\n\t$x_i$ as a dot product\n\t\\[ x_i = \\left< A^i u, v \\right>. \\]\n\tLet $p$ be a prime not dividing $\\det A$.\n\tLet $T$ be an integer such that $A^T \\equiv \\id \\pmod p$\n\t(with $\\id$ denoting the identity matrix).\n\n\tFix any $0 \\le r < N$.\n\tWe will prove that either all the terms\n\t\\[ f(n) = x_{nT+r} \\qquad n = 0, 1, \\dots \\]\n\tare zero, or at most finitely many of them are.\n\tThis will conclude the proof.\n\n\tLet $A^T = \\id + pB$ for some integer matrix $B$.\n\tWe have\n\t\\begin{align*}\n\t\tf(n) &= \\left< A^{nT+r} u, v \\right>\n\t\t= \\left< (\\id + pB)^n A^r u, v \\right> \\\\\n\t\t&= \\sum_{k \\ge 0} \\binom nk \\cdot p^n \\left< B^n A^r u, v \\right> \\\\\n\t\t&= \\sum_{k \\ge 0} a_n \\binom nk \\qquad \\text{ where }\n\t\t\ta_n = p^n \\left< B^n A^r u, v \\right> \\in p^n \\ZZ.\n\t\\end{align*}\n\tThus we have written $f$ in Mahler form.\n\tInitially, we define $f \\colon \\ZZ_{\\ge 0} \\to \\ZZ$,\n\tbut by Mahler's theorem (since $\\lim_n a_n = 0$)\n\tit follows that $f$ extends to a function $f \\colon \\ZZ_p \\to \\QQ_p$.\n\tAlso, we can check that $\\lim_n \\frac{a_n}{n!} = 0$\n\thence $f$ is even analytic.\n\n\tThus by Strassman's theorem, $f$ is either identically zero,\n\tor else it has finitely many zeros, as desired.\n\\end{proof}\n\n\\section{\\problemhead}\n\\begin{dproblem}\n\t[$\\ZZ_p$ is compact]\n\tShow that $\\QQ_p$ is not compact, but $\\ZZ_p$ is.\n\t(For the latter, I recommend using sequential continuity.)\n\\end{dproblem}\n\\begin{dproblem}\n\t[Totally disconnected]\n\tShow that both $\\ZZ_p$ and $\\QQ_p$ are \\emph{totally disconnected}:\n\tthere are no connected sets other than the empty set and singleton sets.\n\\end{dproblem}\n\n\\begin{problem}\n\t[USA TST 2011]\n\tLet $p$ be a prime.\n\tWe say that a sequence of integers $\\{z_n\\}_{n=0}^\\infty$\n\tis a \\emph{$p$-pod} if for each $e \\geq 0$,\n\tthere is an $N \\geq 0$ such that whenever $m \\geq N$,\n\t$p^e$ divides the sum\n\t\\[ \\sum_{k=0}^m (-1)^k \\binom mk z_k. \\]\n\tProve that if both sequences $\\{x_n\\}_{n=0}^\\infty$\n\tand $\\{y_n\\}_{n=0}^\\infty$ are $p$-pods,\n\tthen the sequence $\\{x_n y_n\\}_{n=0}^\\infty$ is a $p$-pod.\n\\end{problem}\n", "meta": {"hexsha": "69d1df6fef07858e948e2ff16aa8e3c8fb49fb1e", "size": 27245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/calculus/p-adic.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/calculus/p-adic.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/calculus/p-adic.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.7002840909, "max_line_length": 83, "alphanum_fraction": 0.6869150303, "num_tokens": 9181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6308902162815304}}
{"text": "\\section{Introduction}\n\nMatrix factorization is listed as one of the most influential set\nof techniques during the 20th century ~\\cite{dongarra2000guest}, among\nthe Fast Fourier Transform, MCMC sampling methods and others.\nAs Stewart ~\\cite{stewart2000decompositional} argues, the principle of the\ndecompositional approach aims to construct computational platforms from\nwhich a variety of problems can be solved.\n\nAlthough the decompositional approach to matrix computation remains\nfundamental, nowadays in the era of big data, most of the classical algorithms\nare inadequate to tackle most of the problems.\n\nData matrices are now incredibly\nbig, making most of the classical approaches too expensive in terms\nof computation. Moreover, it is common in information sciences to have\ndata which is missing or innaccurate. This gives the opportunity to sacrify\nsome accuracy on the algorithm to gain on computation, which classical \nalgorithms are not able to do. Another important aspect is the role\nof data transfer in the computational cost of a given algorithm, i.e, \ntechniques that may perform fewer passes over the data may be substantially\nfaster in practice. \n\nIn this review, we present, analyse and test \\textit{randomized} algorithms\nfor matrix factorizations. This set of novel techniques addresses the issues\nstated above, i.e, can trade-off computation and accuracy to an arbitrary\nprecision, gain on robustness, and reduce the number of passes on big datasets\nwhen data transfer is expensive.\n\nThe purpose of approximated low-rank matrix factorization is to factorize\na given matrix $\\mtx{A}\\in\\Rspace{m\\times n}$ into a product of\ntwo smaller matrices $\\mtx{B}\\in\\Rspace{m\\times k}$ and\n$\\mtx{C}\\in\\Rspace{k\\times n}$. \n\n\\begin{equation}\n\\label{eq:lowrank}\n\\begin{array}{ccccccccccc}\n\\mtx{A} &\\approx& \\mtx{B} & \\mtx{C},\\\\\nm\\times n && m \\times k & k\\times n.\n\\end{array}\n\\end{equation}\n\nThe matrix $\\mtx{B}\\times\\mtx{C}$ in \\ref{eq:lowrank} is called a rank-$k$ approximation of the\nmatrix $\\mtx{A}$.\n\nThe inner dimension $k$ is called the \\textit{numerical rank}\nof the matrix. This\nquantity differs from the \\textit{algebraic rank}, which is defined as the \ndimension of the image. The numerical rank is commonly defined as follows\n\n\\begin{equation}\\label{eq:num-rank}\nr(\\mtx{A})\\defeq\\frac{\\|\\mtx{A}\\|_F^2}{\\|\\mtx{A}\\|^2}\n= \\sum_{j=1}^{\\min(m,n)}\\left(\\frac{\\sigma_j}{\\sigma_1}\\right)^2\n\\end{equation}\n\nand it gives a better understanding of how accurate a rank-$k$ approximation\ncan be. Note that we always have $r(\\mtx{A})\\leq\\text{rank}(\\mtx{A})$. The notion\nof numerical rank appears in ~\\cite{vershynin2016high} and has been studied at the Theory Reading Group\ncourse of the master in depth\n\\footnote{The comparison between both notions of rank can be better understood\nthrough the following caracterization. \n$\\text{rank}(\\mtx{A})=\\dim(\\textbf{A}B_2^n)$ and $r(\\mtx{A})=d(\\mtx{A}B_2^n)$\nwhere $B_2^n$ is the euclidean ball, hence, $\\mtx{A}B_2^n$ is the ellipsoid with\nthe axis of magnitude the singular values $\\sigma_j$'s.\nHere, $\\dim(\\cdot)$ denotes the algebraic dimension and\n$d(\\cdot)$ denotes the \\textit{statistical dimension}.\nThe statistical dimension is defined as $d(T)\\defeq \\frac{h(T-T)^2}{\\text{diam}(T)^2}\n\\sim \\frac{w(T)^2}{\\text{diam}(T)^2}$ where $h(T)^2=\\Expect\\sup_{t\\in T}\\la g, t\\ra^2$\nand $w(T)=\\Expect\\sup_{t\\in T}\\la g, t\\ra$ is the gaussian width.\nAs discussed in ~\\cite{vershynin2016high}, the statistical dimension is a more stable notion\nof dimension, in the same way that the numerical rank is more stable than the\nalgebraic rank.\n}.\n\nThe task of computing a low-rank approximation to a given matrix can be split into\ntwo computational stages. The first is to construct a low dimensional subspace that\ncan capture the action of the matrix. The second is to restrict the matrix to the\nlow dimensional subspace and then compute a standard factorization (QR, SVD, etc)\nof the reduced matrix.\n\n\\begin{itemize}\n  \\item\\textbf{Stage 1:} Compute an approximate basis for the range of the input\n  matrix $\\mtx{A}$. We want to find a matrix $\\mtx{Q}$ with a small\n  number of orthonormal columns such that\n\n  \\begin{equation}\\label{eq:app-basis}\n    \\mtx{A}\\approx \\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}\n  \\end{equation}\n\n  The main idea is to approximate the range of the matrix via a randomized\n  method. This can be accomplised by iteratively computing the image of\n  random vectors from the input space and then orthogonalizing.\n  All the randomness of these methods will belong to this first stage.\n\n  \\item\\textbf{Stage 2:} Given a matrix $\\mtx{Q}$ that satisfies \\ref{eq:app-basis},\n  compute a standard factorization (QR, SVD, etc.) of $\\mtx{A}$.  Note that\n  taking $\\mtx{B}=\\mtx{Q}$ and $\\mtx{C}=\\mtx{Q}^\\adj\\mtx{A}$ we already have\n  a low rank approximation of the matrix.\n   There is no randomness at this stage and only classical linear algebra computations are\n  incolved.\n\\end{itemize}\n\nDuring the rest of the introduction, we will review some basics about matrix approximation\nand we will provide to the reader the basic aspects and insights of both stages, \nwhich will be further studied in depth in the main body.\n\n\n\\subsection{Approximating the range of a matrix via randomness}\n\nThe problem of finding the best $\\epsilon$-approximation of a given matrix $\\mtx{A}$\n is called the \\textit{fixed-precision approximation problem}. More concretely, we are given\n a tolerance $\\epsilon$ and the goal is to find a matrix $\\mtx{Q}$\n with $k=k(\\epsilon)$ columns such that\n\n\\begin{equation}\\label{eq:fixed-precision}\n\\|\\mtx{A} - \\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}\\|\\leq\\epsilon\n\\end{equation}\n\nThe goal here is to find a $\\mtx{Q}$ with the smaller number of columns\npossible.\n\nAnother closely related problem is the so-called \\textit{fixed-rank approximation problem}, \nwhich seeks to find the best rank-$k$ approximation of the matrix.\n\n\\begin{equation}\n\\label{eq:fixed-rank}\n\\min_{{\\rm rank}(\\mtx{X}) \\leq j}\\norm{ \\mtx{A} - \\mtx{X} }.\n\\end{equation}\n\nThe Singular Value Decomposition (SVD)\n\\footnote{The Singular Value Decomposition is a central tool for a data scientist.\nIt is the algorithmic tool used to perform \\textit{Principal Component Analysis} (PCA) on a dataset\n$\\mtx{X}\\in\\Rspace{N\\times d}$ of size $N$ and dimensionality $d$. PCA finds\nlinear hidden linear structure in the data by looking at the eigenvectors with largest\neigenvalues of the empirical covariance matrix of the data\n$\\hat{\\mtx{\\Sigma}}_N = \\mtx{X}^\\transp\\mtx{X}=\\frac{1}{N}\\sum_{j=1}^N\\mtx{x}_j\\mtx{x}_j^\\transp$.\nThese eigenvectors and eigenvalues can also be found by computing the SVD of the data matrix\n$\\mtx{X}=\\mtx{U}\\mtx{D}\\mtx{V}^\\transp$, because $\\hat{\\mtx{\\Sigma}}_N = \\mtx{V}\\mtx{D}^2\\mtx{V}^\\transp$.\nOne important remark is that PCA does not suffer from the curse of dimensionality. For example,\nif we assume sub-gaussianity on the random variable $X$, then we have\n$\\Expect\\| \\hat{\\mtx{\\Sigma}}_N - \\mtx{\\Sigma} \\|\\leq \\varepsilon \\|\\mtx{\\Sigma}\\|$\nif we take a sample size of $N\\sim\\varepsilon^{-2}d$, i.e, the number of samples\nscales linearly with the dimensionality of the dataset. If instead of sub-gaussianity,\nwe relax it to $\\|X\\|_2\\leq K(\\Expect\\|X\\|_2^2)^{1/2}$ we only get an extra log-term.\nThis is one of the main reasons why PCA works!}\nis key to analyze this problem. Recall that\nthe SVD of a matrix $\\mtx{A}$ is the following decomposition\n\n\\begin{equation}\\label{eq:svd}\n\\mtx{A} = \\mtx{U}\\mtx{\\Sigma}\\mtx{V}^\\adj\n= \\sum_{j=1}^{\\text{rank}(\\mtx{A})}\\sigma_j\\mtx{u}_j\\mtx{v}_j^\\adj\n\\end{equation}\n\nwhere $\\{\\mtx{u}_k\\}_k, \\{\\mtx{v}_k\\}_k$ are orthonormal basis on the output and input\nspace respectively, $\\sigma_1\\geq\\sigma_2,\\ldots,\\sigma_{\\text{rank}(\\mtx{A})}\\geq 0$\nare the ordered singular values.\n\n The SVD provides an optimal answer to the\n \\textit{fixed-rank approximation problem} ~\\cite{mirsky1960symmetric} through the following\n important observation\n\n\\begin{equation}\n\\label{eqn:mirsky}\n\\min_{{\\rm rank}(\\mtx{X}) \\leq k}\\norm{ \\mtx{A} - \\mtx{X} } = \\sigma_{k+1}.\n\\end{equation}\n\nIt is straightforward to check that the optimum is attained at\n $\\mtx{X}_{*} = \\sum_{j=1}^k\\sigma_j\\mtx{u}_j\\mtx{v}_j^\\adj$, namely, the $k$-truncated\n SVD (k-SVD) of the matrix $\\mtx{A}$. More precisely, we have that\n$\\mtx{B}=\\mtx{U}\\mtx{\\Sigma}_{[k]}^{1/2}$ and $\\mtx{C} = \\mtx{\\Sigma}_{[k]}^{1/2}\\mtx{V}^\\adj$\nare the best solutions \\ref{eq:lowrank} when the rank is fixed.\n\nLet's suppose now that we know the desired rank $k$ in advance. The goal is \nto find a matrix $\\mtx{Q}$ with $k+p$ orthonormal columns such that\n\n\\begin{equation}\\label{eq:fixed-rank-app}\n\\|\\mtx{A}-\\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}\\| \\approx\n\\min_{{\\rm rank}(\\mtx{X}) \\leq k}\\norm{ \\mtx{A} - \\mtx{X} }\n\\end{equation}\n\nwhere $p$ is called the \\textit{oversampling parameter}.\n\n% EXPLICACIO\n\n\\subsection{Intuition of the randomized method to find Q} \\label{alg:proto-algorithm}\n\nThe key observation that leverage these methods is the fact that the matrix\n$\\mtx{Q}$ can be found by sampling, and now the reader will obtain intuition\non how this can be done.\n\nSuppose we seek a basis for the range of a matrix $\\mtx{A}$ with algebraic rank\n$k$. Random elements $\\mtx{y}^{(i)}$ from the range can be computed by computing the image\nof random vectors $\\mtx{w}^{(i)}$ from the input space. Let us repeat this\nprocess $k$ times:\n\n\\begin{equation}\\label{eq:iter-range}\n\\mtx{y}^{(i)} = \\mtx{A}\\mtx{w}^{(i)}, \\hspace{0.5cm}i=1,\\ldots,k\n\\end{equation} \n\nThanks to the randomness, the set $\\{\\mtx{w}^{(i)}\\}_{i=1}^k$ is likely to be\nin general linear position and no vector will fall in $\\ker\\mtx{A}$\nif this is a set of measure zero under the probability measure we sampled from.\nTherefore, an orthogonalization procedure gives the desired orthonormal basis.\n\nWhat happens if the matrix $\\mtx{A}$ has not exact algebraic rank equal to $k$\n\\footnote{In practice this is always the case.}?\nWrite $\\mtx{A} = \\mtx{B} + \\mtx{E}$ where $\\mtx{B}$ is a rank-$k$ matrix containing\nthe information we seek and $\\mtx{E}$ a small perturbation.\nWe want a basis that covers the range of $\\mtx{B}$, however, if we repeat\nprocedure \\ref{eq:iter-range}, the vectors will be affected by the perturbation\nand the $\\{\\mtx{y}^{(i)}\\}_{i=1}^k$ will have small components that will make\nthem fall outside the desired space.\n\nTo overcome this issue, the idea is to take $p$ more samples:\n\n\\begin{equation}\\label{eq:iter-range}\n\\mtx{y}^{(i)} = \\mtx{A}\\mtx{w}^{(i)} = \\mtx{B}\\mtx{w}^{(i)}\n+ \\mtx{E}\\mtx{w}^{(i)}, \\hspace{0.5cm}i=1,\\ldots,k+p\n\\end{equation}\n\nThe enriched set $\\{\\mtx{y}^{(i)}\\}_{i=1}^{k+p}$ has much more chance\nof spanning the desired subspace, and this is grounded with some\ntheoretical results; see for example Theorem \\ref{thm:avg-frob-error-gauss}.\nThe theory also shows that\n$p$ can be quite small. In practice, $p=5$ is enough.\n\nHere in the box below, we illustrate the basic prodecure to\nfind $\\mtx{Q}$ that approximates the range of $\\mtx{A}$ through randomization.\nWe call it Proto-Algorithm.\n\\begin{figure}[ht]\n\\begin{center}\n\\framebox{\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Proto-Algorithm: Solving the Fixed-Rank Problem}\n\\end{center}\n\\begin{tabbing}\n\\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\kill\n\\anum{1} \\>Draw a random $n \\times (k + p)$ test matrix $\\mtx{\\Omega}$.\\\\\n\\anum{2} \\>Form the matrix product $\\mtx{Y} = \\mtx{A\\Omega}$.\\\\\n\\anum{3} \\>Construct a matrix $\\mtx{Q}$ whose columns form an orthonormal basis for \\\\\n         \\>the range of $\\mtx{Y}$.\n\\end{tabbing}\n\\end{minipage}}\n\\end{center}\n% \\caption{}\n\\end{figure}\n\n\\subsection{Construction of standard matrix factorizations from Q}\n\nThis corresponds to \\textbf{Stage 2} of the algorithm. Once we have $\\mtx{Q}$\nsuch that $\\mtx{A}\\approx\\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}$, taking \n$\\mtx{B}=\\mtx{Q}$ and $\\mtx{C}=\\mtx{Q}^\\adj\\mtx{A}$ we directly produce a low rank\nmatrix decomposition $\\mtx{A}\\approx\\mtx{B}\\mtx{C}$. However, \nthere are more involved methods to produce a decomposition from $\\mtx{Q}$ with\ncomputational advantadges compared to the direct method. \n\nOne we have $\\mtx{A}\\approx\\mtx{B}\\mtx{C}$, standard matrix decompositions \n(e.g. SVD, QR) can be easily derived as we show in \\ref{itm:SVD-from-C}. \\\\\n\n\n\nA lot of questions need to be addressed in order to turn these methods into\na technology or \\textit{off-the-shelf} algorithms. The following \nsections will we devoted to this.\n", "meta": {"hexsha": "488de35d36e285dbc45ab2b65ba0616435215a80", "size": 12394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/introduction.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/introduction.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/introduction.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": 46.7698113208, "max_line_length": 106, "alphanum_fraction": 0.729627239, "num_tokens": 3776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311906630568, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6308902063132397}}
{"text": "% Full title as you would like it to appear on the page\n\\chapter{Interpolating The Global Wavefront with Least Squares}\n\\label{chap:interp}\n\\chaptermark{Interpolating The Global Wavefront}\n\n\\epigraph{In questions of science, the authority of a thousand is not worth the humble reasoning of a single individual.}{Galileo Galilei}\n% \\epigraph{The first principle is that you must not fool yourself and you are the easiest person to fool.}{Richard P. Feynman}\n\n\\section{The Interpolation Geometry}\n\nIn the second step, we interpolate the global wavefront from the local wavefront predictions from the first step. We interpolate the global wavefront coefficients $\\beta_{jk}$ based on the predictions $\\alpha$ from the previous step. More explicitly, we use ordinary least squares (LS) to solve\n\n\\begin{equation*}\n\\text{LS}(\\alpha(x_1,y_1), \\dots, \\alpha(x_n,y_n)) \\to \\beta_{jk} \\text{ such that } W(u,v,x,y) = \\sum_{j=4}^{21}\\sum_{k=1}^3\\beta_{jk}Z_j(u,v)Z_k(x,y)\n\\end{equation*}\n\nIn the previous step, the 18 predictions $\\{\\alpha_4(x_i, y_i), \\dots, \\alpha_{21}(x_i,y_i)\\}$ for a source image $D$ at position $(x_i,y_i)$. In this step, we start by aggregating the predictions for a single coefficient $j$ for all $n$ donuts in the field of view of the observation, or $\\{\\alpha_j(x_1, y_1), \\dots, \\alpha_{j}(x_n,y_n)\\}$. Then the problem reduces to minimizing the distance between the $\\alpha_j$ estimates and $\\sum_{k=1}^3\\beta_{jk}Z_k(x,y)$ for each index separately. Figure \\ref{fig:rafts} shows the true and predicted $\\alpha_4$ values on the four wavefront sensors. \n\n\\begin{figure}[!htbp]\n\\begin{center}\n\\begin{tabular}{c}\n\\includegraphics[width=\\textwidth]{figs/interp/rafts.png}\n\\end{tabular}\n\\end{center}\n\\caption[Local Wavefront Predictions Across Four Wavefront Sensors]{The two rows correspond to the true ($\\alpha_4^{\\text{true}}$) and predicted ($\\alpha_4^{\\text{predicted}}$) $Z_4$ coefficients. The four columns correspond to the four corner wavefront sensors. The colormap is in units of waves.\\label{fig:rafts}}\n\\end{figure}\n\nThe first three Zernike coefficients establish a plane. Thus we are effectively fitting a plane by the three coefficients along the $k$ index, for each local wavefront Zernike coefficient, or $j$ index. Figure \\ref{fig:fieldols} shows how $\\beta_{41}, \\beta_{42}, \\beta_{43}$ are fit from the local $\\alpha_4$ predictions.\n\n\\begin{figure}[!htbp]\n\\begin{center}\n\\begin{tabular}{c}\n\\includegraphics[width=\\textwidth]{figs/interp/fieldols.png}\n\\end{tabular}\n\\end{center}\n\\caption[Fitting Global $\\beta_{41}, \\beta_{42}, \\beta_{43}$ From Local $\\alpha_4$ Predictions]{\\textit{Left:} the predicted coefficients $\\alpha_4^{\\text{pred}}$ from Figure \\ref{fig:rafts} shown at their corresponding field locations within the field of view. \\textit{Right:} the plane characterized by the three fit double Zernike coefficients $\\beta^{\\text{pred}}_{41},\\beta^{\\text{pred}}_{42}, \\beta^{\\text{pred}}_{43}$. The two circles represent the field of view of the Rubin Observatory. \\label{fig:ls-intuition}}\n\\end{figure}\n\nThe explicit minimization is \n\n\\begin{equation*}\n\\label{eq:objective}\n\\text{min}_{\\beta}\\left|\\left| \\begin{bmatrix}\\alpha_j(x_1,y_1) \\\\ \\vdots \\\\ \\alpha_j(x_n,y_n) \\end{bmatrix} - \\begin{bmatrix}Z_1(x_1,y_1) & Z_2(x_1,y_1) & Z_3(x_1,y_1) \\\\ \\vdots & \\vdots & \\vdots\\\\  Z_1(x_n,y_n) & Z_2(x_n,y_n) & Z_3(x_n,y_n)\\end{bmatrix} \\begin{bmatrix}\\beta_{j1} \\\\ \\beta_{j2} \\\\ \\beta_{j3} \\end{bmatrix}\\right|\\right|_2\n\\end{equation*}\n\n\\noindent which we solve with ordinary least squares. Letting $\\alpha_j, Z, \\beta_j$ be the vectors and matrices from the equation above, we have the analytic solution $\\beta_j = (Z^TZ)^{-1}Z^T\\alpha_j$. After solving this equation for each $j$, we have $\\beta_{jk}$ for $4 \\leq j \\leq 21$ and $1 \\leq k \\leq 3$. In the next section we describe a few variations to this basic framework.\n\n\\section{Evaluating Different Interpolation Strategies}\n\nThe interpolation is comprised of three steps that are reminiscent of a standard data query: select, reduce, and fit. The \\textit{select} step decides which donuts and corresponding local estimates to use in the interpolation. The \\textit{reduce} step, which is typically skipped, reduces these estimates across a wavefront sensor. The \\textit{fit} step fits the local coefficients to a global Zernike basis based on the provided loss function.\n\nWe examine multiple variations in each of these steps to find which combination works best. We explore selecting donuts from all the sources (stars and blends), from only the non-blended stars (stars), the non-blended 10 brightest stars per chip (brightest stars), and using the true labels (labels). The results on the true labels provide a sanity check and bound the performance we can expect to achieve with alternatives. \n\nWe also analyze two variations in the reduce step. Either we make no changes to estimates and effectively skip this step, or we take the median of the estimates on each chip. In the median case, we would then fit against the four points corresponding to the four sensors in the fit step. \n\nWe explore three different fitting strategies. The $\\ell_1$, or absolute loss, is convex and can be found with an iterative optimization algorithm. The $\\ell_2$, or least squares loss, has an analytic solution. This has the added benefit of making error propagation analytic as well. Finally, the Huber loss $\\ell_h$ is similar to the $\\ell_2$ for samples with small error but scales like $\\ell_1$ for large error. Thus it is similar to $\\ell_2$ but less sensitive to outliers.\n\nThe results of these variations, applied to the local wavefront estimates from the neural network, applied to the full visit dataset, are shown in Table \\ref{tab:variations}. We compare the true global wavefront and the residual global wavefront, where the residual is the true wavefront minus the interpolated optics wavefront. The residual wavefront is smaller than the original wavefront for all the samples in the majority of select-reduce-fit variations. The consistency of the improvements makes our method an attractive candidate for deployment.\n\n\\begin{table}\n{\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|r|}\n\\hline\n & Median &  & \\multicolumn{1}{|c|}{\\% Samples} & \\multicolumn{1}{|c|}{Relative}  \\\\\nSelect & Reduce & Fit & \\multicolumn{1}{|c|}{Improved} & \\multicolumn{1}{|c|}{Residual} \\\\\n\\hline\n &  & $\\ell_1$ & $ 99.6$ & $ 0.48 \\pm  0.13$\\\\\nStars & & $\\ell_2$ &  $ 99.8$ & $ 0.49 \\pm  0.12$\\\\\nand&  & $\\ell_{\\text{h}}$ &  $ 100.0$ & $ 0.48 \\pm  0.12$\\\\\nBlends& \\checkmark & $\\ell_{1}$ &  $ 97.8$ & $ 0.67 \\pm  0.14$\\\\\n& \\checkmark & $\\ell_{2}$ &  $ 100.0$ & $ 0.46 \\pm  0.12$\\\\ \n\\hline\n&   & $\\ell_1$ &  $ 99.8$ & $ 0.44 \\pm  0.11$\\\\ \n&   & $\\ell_2$ &  $ 100.0$ & $ 0.43 \\pm  0.10$\\\\ \nStars&  & $\\ell_{\\text{h}}$ &  $ 100.0$ & $ 0.43 \\pm  0.10$\\\\\n& \\checkmark  & $\\ell_{1}$ &  $ 97.2$ & $ 0.64 \\pm  0.14$\\\\\n& \\checkmark  & $\\ell_{2}$ &  $ 99.8$ & $ 0.41 \\pm  0.11$\\\\\n\\hline\n& & $\\ell_1$ &  $ 99.6$ & $ 0.37 \\pm  0.13$\\\\ \nBrightest& & \\textcolor{blue}{$\\ell_2$} & \\textcolor{blue}{$ 100.0$} & \\textcolor{blue}{$ 0.34 \\pm  0.12$}\\\\ \nStars& & $\\ell_{\\text{h}}$ &  $100.0$ & $ 0.34 \\pm  0.12$\\\\ \n& \\checkmark & $\\ell_{1}$ &  $97.2$ & $ 0.60 \\pm  0.16$\\\\ \n& \\checkmark & $\\ell_{2}$ &  $100.0$ & $ 0.35 \\pm  0.12$\\\\\n\\hline\n& & $\\ell_1$ &  $ 100.0$ & $ 0.13 \\pm  0.05$\\\\ \nLabels & & \\textcolor{red}{$\\ell_2$} & \\textcolor{red}{$ 100.0$} & \\textcolor{red}{$ 0.06 \\pm  0.02$}\\\\\n& & $\\ell_{\\text{h}}$ &  $ 100.0$ & $ 0.08 \\pm  0.04$\\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n}\n\\caption[Select-Reduce-Fit Results]{Each row contains the results for a different combination of select, reduce, and fit steps. The penultimate column contains the percentage of the number of samples where the residual improved. The final column contains the relative residual: the total magnitude of the residual divided by the total magnitude of the true wavefront. The best variation on neural network estimates is highlighted in \\textcolor{blue}{blue}. The best variation on the true label estimates is highlighted in \\textcolor{red}{red}.}\n\\label{tab:variations}\n\\end{table}\n\nThis experiment also taught us that more data is not always better. Ignoring the blended donuts leads to a clear improvement in performance. So does ignoring all but the brightest stars. This suggests that we should prioritize making accurate predictions on the best donuts, perhaps at the expense of making consistent estimates on all the donuts. It also may have consequences for wavefront sensing in crowded fields where almost all of the donuts are blended.\n\nWe can also draw conclusions about the variations. Taking the median and fitting with the $\\ell_1$ norm appears to discard too much information. We also see that the benefit of using median with the $\\ell_2$ norm goes away as the select becomes more selective. This is likely because the outliers, which the median reduce suppresses, get filtered and are no longer an issue. The $\\ell_{h}$ norm also seems to do comparatively well on stars and blends, but loses this advantage on the more selective brightest stars selection. We conclude using the $\\ell_2$ norm, with no median reduce, to fit the brightest stars, is the best variation.\n\nWe used this variation to explore how our framework performs in five scenarios. We used the relative residual $|\\beta^{\\text{res}}| / |\\beta^{\\text{true}}| = \\sum_{jk}|\\beta^{\\text{true}}_{jk} - \\beta^{\\text{pred}}_{jk}| / \\sum_{jk}|\\beta^{\\text{true}}_{jk}|$ to measure our algorithm's capability to reproduce the true global wavefront. A value close to zero means the predictions match the true global wavefront almost perfectly; a value close to one means the predictions capture almost none of the true global wavefront. Figure \\ref{fig:beta-results} shows the results.\n\n\\begin{figure}[!htbp]\n\\begin{center}\n\\begin{tabular}{c}\n\\includegraphics[width=\\textwidth]{figs/interp/dist_defense2.png}\n\\end{tabular}\n\\end{center}\n\\caption[Relative Residuals In Different Scenarios]{The distributions of relative residuals in four different scenarios. The distributions from performing the interpolation over the labels with and without noise are shown in black. The distributions from performing the interpolation over the local wavefront predictions from the neural network with and without noise are shown in blue. \\label{fig:beta-results}}\n\\end{figure} \n\nIn the first scenario, we evaluated the second step of our algorithm on the true local wavefront labels from the first step. The relative residual is 6\\%, which validates that our simulations are consistent and there are no sources of catastrophic numerical error. In the second scenario, we added uncorrelated Gaussian noise to each local wavefront coefficient. The variance of the noise for each coefficient was equal to the variance of the neural network error on that coefficient in the test data. Despite this noise, the relative residual remained very low at 10\\%. This shows that our approach is not overly sensitive to uncorrelated noise.\n\nIn the third scenario, we fed the local wavefront predictions from the neural network to the second step. These have significant correlated error due to the atmosphere. The relative residual is 34\\%, extremely promising, with a tight 12\\% standard deviation. Furthermore, the right tail decays rapidly. Not a single relative residual is greater than one. Our framework improves the global wavefront on every observation in the full visit dataset!\n\nIn the fourth scenario we add noise as in the second scenario, effectively doubling the error. The relative residual increases slightly to 38\\%. This suggests that the network is fairly robust to uncorrelated noise.\n\n\\section{Combined Runtime}\n\nThe run-time is another key advantage of our approach. It takes just under 4 seconds to process 811 donut images on a 2.4 GHz Intel Xeon CPU with a single Nvidia V100 GPU. It takes an additional 5 milliseconds to run the least squares optimization. The total processing time per donut image is 5 milliseconds; the total processing time per donut of the Rubin Observatory AOS under development is around 10 seconds\\cite{2015Xin,2014Overiew}. Our scheme can process donuts 2,000 times faster, and is capable of processing 7,800 donuts in a single 39 second Rubin visit. The low latency allows it to process all the donuts in most observations.\n\n\\section{Image Quality Results}\n\nThe next step is to take this model and measure the repercussions of subtracting its estimate from the true wavefront on both the PSF FWHM and Strehl ratio \\cite{strehl1895aplanatische}. We compute these by calculating the local wavefronts at the center and one corner of the focal plane. Then we take the fourier transform of the resulting pupil plane aberration to get the point spread function. The results for the original and corrected wavefronts are shown in Table \\ref{tab:corrections}. \n\n\\begin{table}\n{\n    \\begin{center}\n    \\begin{tabular}{|l|l|c|c|}\n    \\hline\n    State & Position & FWHM & Strehl\\\\\n    \\hline\n    Before & Center & $0.288 \\pm 0.034$ & $0.093 \\pm 0.39$ \\\\\n    After & Center & $0.211 \\pm 0.005$ &  $0.555 \\pm 0.207$\\\\\n    \\hline\n    Before & Corner & $0.314 \\pm 0.045$ & $0.074 \\pm 0.32$\\\\\n    After & Corner & $0.215 \\pm 0.009$ & $0.400 \\pm 0.184$\\\\\n    \\hline\n    \\end{tabular}\n    \\end{center}\n}\n\\caption[Improvements To The Optics PSF FWHM And Strehl Ratio]{We measure the optics PSF FWHM and Strehl ratio on the original optics wavefront from the observation (Before), and the residual wavefront resulting from subtracting our wavefront estimate from the original optics wavefront (After). The Center position is at the center of the Rubin focal plane; the Corner position is at the center of the $R00$ wavefront sensor in the corner of the focal plane.}\n\\label{tab:corrections}\n\\end{table}\n\nThe optics PSF FWHM decreases considerably, especially when compared to the standard deviation of the original. The Strehl ratio increases in an even more extreme manner. Figure \\ref{fig:vision} provides an illustrative example of how the improvements to the optics PSF from our method can improve image quality. We apply the Rubin optics PSF, before and after subtracting the optics wavefront estimated by our framework, to six classic Hubble Telescope images in the absence of other significant PSF contributions.\n\n\\begin{figure}[!htbp]\n\\begin{center}\n\\begin{tabular}{c}\n\\includegraphics[width=\\textwidth]{figs/interp/results.png}\n\\end{tabular}\n\\end{center}\n\\caption[Illustrative Hubble Telescope Images After Correction From Our Framework]{An illustration of the effect of wavefront correction using our techniques on image resolution.  We use actual Hubble Space Telescope images to show the effect.  The Before images are degraded by the wavefront aberrations we have simulated.  The After images show their reconstruction after wavefront estimation and correction using the technique we describe in this paper. On the bottom two rows, we show the effective PSF, both before and after wavefront correction. The images have an angular extent of 3 arcseconds and the PSFs are displayed on a $0.16 \\times 0.16$ arcsecond grid. \\label{fig:results}}\n\\end{figure}\n\nFor the Rubin Observatory however, the PSF is dominated by the atmosphere, which as indicated cannot be corrected. For the Rubin observatory the assumed PSF width is of order 0.71 arcseconds, of which 0.65 is contributed by the atmosphere. Therefore, the improvement in the Strehl and image quality is not as dramatic. Nevertheless, this improvement is still important for use on nights with unusually good atmospheric seeing and also for applications that are especially sensitive to the PSF width.\n", "meta": {"hexsha": "4310b67cc1545b18ec79996989b773777c7c3b9c", "size": 15676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/interpolating_wavefront/interp.tex", "max_stars_repo_name": "davidthomas5412/Thesis", "max_stars_repo_head_hexsha": "fccbf9244196333f55bbd95676077537979ba183", "max_stars_repo_licenses": ["MIT"], "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/interpolating_wavefront/interp.tex", "max_issues_repo_name": "davidthomas5412/Thesis", "max_issues_repo_head_hexsha": "fccbf9244196333f55bbd95676077537979ba183", "max_issues_repo_licenses": ["MIT"], "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/interpolating_wavefront/interp.tex", "max_forks_repo_name": "davidthomas5412/Thesis", "max_forks_repo_head_hexsha": "fccbf9244196333f55bbd95676077537979ba183", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 99.2151898734, "max_line_length": 689, "alphanum_fraction": 0.7508292932, "num_tokens": 4294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6308902060733108}}
{"text": "\\documentclass[]{article}\n\n\\usepackage{graphicx}\n\n\\usepackage[margin=1in]{geometry}\n\n\\setlength\\parindent{0pt}\n\n\\usepackage{physics}\n\\usepackage{amsmath, amsfonts, amssymb, amsthm}\n\n\\usepackage{listings}\n\n\\usepackage{enumitem}\n\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\renewcommand*{\\thesection}{Problem \\arabic{section}}\n\\renewcommand*{\\thesubsection}{\\alph{subsection})}\n\\renewcommand*{\\thesubsubsection}{\\quad \\quad \\roman{subsubsection})}\n\n%Custom Commands\n\\newcommand{\\Rel}{\\mathcal{R}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\C}{\\mathbb{C}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\n\\newcommand{\\toI}{\\xrightarrow{\\textsf{\\tiny I}}}\n\\newcommand{\\toS}{\\xrightarrow{\\textsf{\\tiny S}}}\n\\newcommand{\\toB}{\\xrightarrow{\\textsf{\\tiny B}}}\n\n\\newcommand{\\divisible}{ \\ \\vdots \\ }\n\\newcommand{\\st}{ \\ \\vline \\ }\n\n\n% Theorem Definition\n\\newtheorem{definition}{Definition}\n\\newtheorem{assumption}{Assumption}\n\\newtheorem{theorem}{Theorem}\n\n\n%opening\n\n\\title{MATH 5301 Elementary Analysis - Midterm Exam}\n\n\\author{Jonas Wagner}\n\n\\date{2021, October 8}\n\n\\begin{document}\n\n\\maketitle\n\n% Problem 1\n\\section{}\n\\textbf{Problem:} 100 soldiers stayed in a rank in front of the corporal. \nThe corporal ordered all of them to turn left, but the soldiers were newbies, \nso they were not certain was it left from their perspective or from the corporal’s \npoint of view. So, some of them turned left and some turned right. After that \nat every second if two neighboring soldiers find themselves facing each other,\nthey rotate by 180 degrees. Show that this process will not last forever.\n\n\\subsection*{Problem Formulation}\nThe state of the 100 soldiers represented as arrows pointed to the right or left \nfor each time step, $n$, is visualized by the following drawing:\\\\\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{MidExam1_pblm1_a.png}\n\\end{figure}\n\nFor each time step all of the individual pairs of soldiers facing each other \nflip and it progresses until all soldiers on the left face left and soldiers \non the right face right.\\\\\n\nThis can be similarly described as a sequence of binary states and a simplistic update \noperation.\\\\\nLet $1$ denote $\\rightarrow$.\\\\\nLet $0$ denote $\\leftarrow$.\\\\\nDefine and randomly populate sequence \n$$\\qty{x_n \\st x_n \\in \\{0,1\\} }_{n \\in [1,100]}^{(k)}, k \\in \\N$$\nThe dependent update operation can be defined as \n$$\\qty{x_n}^{(k+1)} \n    := \\qty{x_n \\st x_n = \n    \\begin{cases}\n        1   & (x_n \\land x_{n+1}) \\lor (\\lnot x_n \\land x_{n-1})\\\\\n        0   & (\\lnot x_n \\land \\lnot x_{n-1}) \\lor (x_n \\land \\lnot x_{n+1})\n    \\end{cases}\n    \\\n    }\n$$\nwhere $x_0 = 0$ and $x_{101} = 1$ get referenced.\\\\\n\n\\newpage\n\\subsection*{Stopping Demonstration}\nAn example demonstrating this progression on the left is shown in the following drawing: \n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[width = 0.7 \\textwidth]{MidExam1_pblm1_b.png}\n\\end{figure*}\n\nIt is clear that after each update, the system will begin to converge so that \n$$\\exists_{a \\in [1,100]} : \\forall_{i < a} x_i = 0$$ and \n$$\\exists_{b \\in [1,100]} : \\forall_{i > b} x_i = 1$$\n\nTherefore, and since $\\qty{x_n}^{(k)}$ is a finite set, the following must be true:\n$$\\exists_{n \\in \\N} \\forall_{k > n} \\implies \\qty{X_n}^{(k)} = \\qty{X_n}^{(k+1)}$$\n\nWhich means that the dependent operation will no longer change the state of the system.\n\n% Problem 2\n\\newpage\n\\section{}\nLet $\\R^\\infty$ be the set of all sequences of real numbers\n$$\\R^\\infty = \\qty{a_1,a_2,\\cdots \\ | \\ a_j \\in \\R}$$\nDefine the relation $\\Rel$ on $\\R^\\infty$ as follows:\n$a\\Rel b$ if for some $j \\in \\N : a_j > b_j$ and for all $k < j \\implies a_k = b_k$.\n\nProve that such a relation is an order relation on $R^\\infty$. Is it a total order?\n\n\\begin{definition}\n    Define the relation $\\Rel$ as\n    $$\\Rel \\subset \\R^\\infty \\cross \\R^\\infty \\qty{(a,b) \\st \n        \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ a_k = b_k) \\land (a_j > b_j)}$$\n\\end{definition}\n\n\\begin{theorem}\n    The relation $a \\Rel b$ is a strict total order relation over $\\R^\\infty$\n    \\begin{proof}\n        Over $\\R^\\infty$ the ordered relation $a \\Rel_1 b$ \n        satisfies the 3 strict order properties:\n\n        \\subsubsection{Irreflective: $\\lnot x \\Rel x$}\n        \\begin{align*}\n            \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ a_k = b_k) \\land (a_j > b_j) &\\implies a \\Rel b\\\\\n            \\lnot  \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = x_k) \\land (x_j > x_j) &\\implies \\lnot  (x \\Rel x)\\\\\n            \\forall_{j\\in\\N} \\qty(\\lnot \\qty(\\forall_{k < j} \\ x_k = x_k) \\lor \\lnot (x_j > x_j)) &\\implies \\lnot  (x \\Rel x)\\\\\n            \\forall_{j\\in\\N} \\qty(\\qty(\\exists_{k < j} \\ x_k \\neq x_k) \\lor (x_j \\geq x_j)) &\\implies \\lnot  (x \\Rel x)\\\\\n        \\end{align*}\n        Since $(x_j \\geq x_j)$ is always true, $\\lnot x \\Rel x$.\n        \n        \\subsubsection{Transivity: $x \\Rel y \\land y \\Rel z \\implies x \\Rel z$}\n        \\begin{align*}\n            x \\Rel y \\land y \\Rel z \n                &\\implies x \\Rel z\\\\\n        \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = y_k) \\land (x_j > y_j)\\land&\\\\\n            \\land \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ y_k = z_k) \\land (y_j > z_j)\n            &\\implies \\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = z_k) \\land (x_j >z_j)\\\\\n        \\exists_{j_1\\in\\N} : \\qty(\\forall_{k < j_1} \\ x_k = y_k) \\land (x_{j_1} > y_{j_1})\\land&\\\\\n            \\land \\exists_{j_2\\in\\N} : \\qty(\\forall_{k < j_2} \\ y_k = z_k) \\land (y_{j_2} > z_{j_2})\n            &\\implies \\exists_{j_3\\in\\N} : \\qty(\\forall_{k < j_3} \\ x_k = z_k) \\land (x_{j_3} >z_{j_3})\\\\\n        \\end{align*}\n        Clearly, for $j_3 \\leq \\min\\qty{j_1,j_2}$ this is always true.\n\n        \\subsubsection{Connectivity: $x \\neq y \\implies x \\Rel y \\lor y \\Rel x$}\n        \\begin{align*}\n            x \\neq y &\\implies x \\Rel y \\lor y \\Rel x\\\\\n            x \\neq y &\\implies \\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = y_k) \\land (x_j > y_j))\n                \\lor \\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ y_k = x_k) \\land (y_j > x_j))\\\\\n            \\lnot(x \\neq y)\n                &\\implies \\lnot \\qty(\\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = y_k) \\land (x_j > y_j))\n                \\lor \\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ y_k = x_k) \\land (y_j > x_j)))\\\\\n            x = y &\\implies \\lnot \\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ x_k = y_k) \\land (x_j > y_j))\n                \\land \\lnot \\qty(\\exists_{j\\in\\N} : \\qty(\\forall_{k < j} \\ y_k = x_k) \\land (y_j > x_j)))\\\\\n            x = y &\\implies \\qty(\\forall_{j\\in\\N} : \\lnot \\qty(\\forall_{k < j} \\ x_k = y_k) \\lor \\lnot (x_j > y_j))\n                \\land \\qty(\\forall_{j\\in\\N} : \\lnot \\qty(\\forall_{k < j} \\ y_k = x_k) \\lor \\lnot (y_j > x_j)))\\\\\n            x = y &\\implies \\qty(\\forall_{j\\in\\N} : \\qty(\\exists_{k < j} \\ x_k \\neq y_k) \\lor (x_j \\geq y_j))\n                \\land \\qty(\\forall_{j\\in\\N} : \\qty(\\exists_{k < j} \\ y_k \\neq x_k) \\lor (y_j \\geq x_j)))\\\\\n            x = y &\\implies (x_j \\geq y_j) \\land (y_j \\geq x_j)\\\\\n        \\end{align*}\n        Therefore, $\\Rel$ has connectivity.\n    \\end{proof}\n\\end{theorem}\n\n\n% Problem 3\n\\newpage\n\\section{}\nAlice wrote some finite sequence of zeros and ones on the paper (e.g. 010010). \nBob is allowed to replace any pair ``10'' by ``00···01'' with any (but finite) \namount of zeros in front of 1. Bob can repeat this procedure as many times as \nhe wants (if he will find ``10'' in the resulting sequence). \nProve that Bob can perform such operation only finitely many times.\n\n\\textbf{Solution:}\n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{MidExam1_pblm3_e.png}\n\\end{figure*}\n\nThe proof of this follows a similar structure to that of problem 1.\n\n\n\n\n\n\n\n\n\n% Problem 4\n\\newpage\n\\section{}\nPresent two essentially different total orderings of the field \n$\\Q(\\sqrt{2}) := \\qty{a + b \\sqrt{2} \\st a,b \\in \\Q}$.\n\\subsection*{Problem Formulation}\n\\begin{definition}\n    The field $\\mathbb{F} = \\langle\\Q(\\sqrt{2}),+,0,\\cdot,1\\rangle$ is defined with the set\n    $$\\Q(\\sqrt{2}) := \\qty{a + b \\sqrt{2} \\st a,b \\in \\Q}$$\n    and the operators\n    \\begin{align*}\n        + : \\Q(\\sqrt{2}) \\cross \\Q(\\sqrt{2}) \\to \\Q(\\sqrt{2}) \n            &:= (a_1,a_2) + (b_1,b_2) = (a_1 + b_1, a_2 + b_2)\\\\\n        \\cdot : \\Q(\\sqrt{2}) \\cross \\Q(\\sqrt{2}) \\to \\Q(\\sqrt{2}) \n            &:= (a_1,a_2) \\cdot (b_1,b_2) = (a_1 b_1 + 2 a_2 b_2, a_1 b_2 + a_2 b_1)\n    \\end{align*}\n    It is also assumed that the standard field properties all apply.\n\\end{definition}\n\n% Part 1\n\\subsection{Ordering 1: $\\Rel_1$}\n\\begin{definition}\n    An relation $a \\Rel_1 b$ %$(a,b) \\Rel_1 (b_1,b_2)$ can be defined as\n    $$\\Rel \\subset \\Q(\\sqrt{2}) \\cross \\Q(\\sqrt{2}) \n        := \\qty{(a,b) \\st a_1^2 + 2 a_2^2 \\leq b_1 + 2 b_2^2}$$\n\\end{definition}\n\\begin{theorem}\n    The relation $a \\Rel_1 b$ is an ordered relation over $\\mathbb{F}$\n    \\begin{proof}\n        Over $\\mathbb{F}$ the ordered relation $(a_1,a_2) \\Rel_1 (b_1,b_2)$ can be defined by \n        $$(a, b) \\Rel_1 (b_1,b_2) \n            := \\qty{((a_1,a_2),(b_1,b_2)) \\st (a_1 \\cdot a_1 + 2 \\cdot a_2 \\cdot a_2) \n                \\leq (b_1 \\cdot b_1 + 2 \\cdot b_2 \\cdot b_2)}\n        $$\n        $(a_1, a_2) \\Rel_1 (b_1,b_2)$ satisfies the 3 ordered properties:\n        \\subsubsection{Reflective: $x \\Rel_1 x$}\n        \\begin{align*}\n            (a_1 \\cdot a_1 + 2 \\cdot a_2 \\cdot a_2) \n                \\leq (b_1 \\cdot b_1 + 2 \\cdot b_2 \\cdot b_2)\n                &\\implies a \\Rel_1 b\\\\\n            (x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2) \n                \\leq (x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                &\\implies x \\Rel_1 x\\\\\n            x_1^2 + 2 x_2^2 \\leq x_1^2 + 2 x_2^2 &\\implies x \\Rel_1 x\n        \\end{align*}\n        \n        \\subsubsection{Anti-Symmetry: $x \\Rel_1 y \\land y \\Rel_1 x \\implies x = y$}\n        \\begin{align*}\n            x \\Rel_1 y \\land y \\Rel_1 x &\\implies x = y\\\\\n            (x_1,x_2) \\Rel_1 (y_1,y_2) \\land (y_1,y_2) \\Rel_1 (x_1,x_2) \n                &\\implies (x_1,x_2)=(y_1,y_2)\\\\\n            \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2))\n            &\\land\\\\\n                \\land \\qty((y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2)\n                    \\leq (x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2))\n                &\\implies (x_1,x_2) = (y_1,y_2)\\\\\n            \\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n                \\land \\qty(y_1^2 + 2 y_2^2 \\leq x_1^2 + 2 x_2^2)\n                &\\implies (x_1,x_2) = (y_1,y_2)\\\\\n            % (x \\cdot x \\leq y \\cdot y) \\land (y \\cdot y \\leq x \\cdot x)\n            %     &\\implies x = y\n        \\end{align*}\n        \n        \\subsubsection{Transivity: $x \\Rel_1 y \\land y \\Rel_1 z \\implies x \\Rel_1 z$}\n        \\begin{align*}\n            x \\Rel_1 y \\land y \\Rel_1 z \n                &\\implies x \\Rel_1 z\\\\\n            (x_1,x_2) \\Rel_1 (y_1,y_2) \\land (y_1,y_2) \\Rel_1 (z_1,z_2)\n                &\\implies (x_1,x_2) \\Rel_1 (z_1,z_2)\\\\\n            \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2)) \n                \\land&\\\\\n                \\land \\qty((y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2)\n                    \\leq (z_1 \\cdot z_1 + 2 \\cdot z_2 \\cdot z_2)) \n                &\\implies \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (z_1 \\cdot z_1 + 2 \\cdot z_2 \\cdot z_2))\\\\\n            \\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n                    \\land \\qty(y_1^2 + 2 y_2^2 \\leq z_1^2 + 2 z_2^2)\n                &\\implies \\qty(x_1^2 + 2 x_2^2 \\leq z_1^2 + 2 z_2^2)\\\\\n            x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_1^2 \\leq z_1^2 + 2 z_2^2\n                &\\implies x \\Rel_1 z\n        \\end{align*}\n    \\end{proof}\n\\end{theorem}\n\\begin{theorem}\n    The ordered relation $x \\Rel_1 y$ forms a total order over $\\mathbb{F}$.\n    \\begin{proof}\n        $x \\Rel_1 y$ satisfies the totality condition:\n        \\subsubsection{Totality: \n        $\\forall x,y \\in \\mathbb{F} \\implies x \\Rel_1 y \\lor y \\Rel_1 x$}\n        \\begin{align*}\n            \\forall x,y \\in \\mathbb{F} &\\implies x \\Rel_1 y \\lor y \\Rel_1 x\\\\\n            \\forall_{x \\in \\Q(\\sqrt{2})}\n                    \\forall_{y \\in \\Q(\\sqrt{2})}\n                &\\implies \\qty(x \\cdot x \\leq y \\cdot y)\n                    \\lor \\qty(y \\cdot y \\leq x \\cdot x)\\\\\n            \\forall_{(x_1,x_2) \\in \\Q(\\sqrt{2}))}\n                    \\forall_{(y_1,y_2) \\in \\Q(\\sqrt{2})}\n                &\\implies \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2)) \\lor\\\\\n                &\\qquad \\lor \\qty((y_1 \\cdot y_1 + 2 \\cdot y_2 \\cdot y_2)\n                    \\leq (x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2))\\\\\n            % \\forall_{x_1 \\in \\N} \\forall_{x_2\\in \\N}\n            %         \\forall_{y_1 \\in \\N} \\forall_{y_2 \\in \\N}\n            \\forall_{x_1, x_2, y_1, y_2 \\in \\Q}\n                &\\qty(\\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n                    \\lor \\qty(y_1^2 + 2 y_2^2 \\leq x_1^2 + 2 x_2^2))\\\\\n            % \\forall_{x_1, x_2, y_1, y_2 \\in \\Q(\\sqrt{2})}\n            %     &\\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n            %         \\lor \\qty(y_1^2 + 2 y_2^2 \\leq x_1^2 + 2 x_2^2)\n        \\end{align*}\n    \\end{proof}\n\\end{theorem}\n\n% Part 2\n\\subsection{Ordering 2: $\\Rel_2$}\n\\begin{definition}\n    An relation $a \\Rel_2 b$\n    $$\\Rel \\subset \\Q(\\sqrt{2}) \\cross \\Q(\\sqrt{2}) \n        := \\qty{(a,b) \\st a \\cdot a \\leq b \\cdot b}$$\n\\end{definition}\n\n\n% not done yet\n\\begin{theorem}\n    The relation $a \\Rel_2 b$ is an ordered relation over $\\mathbb{F}$\n    \\begin{proof}\n        Over $\\mathbb{F}$ the ordered relation $(a_1,a_2) \\Rel_2 (b_1,b_2)$ can be defined by \n        $$(a, b) \\Rel_2 (b_1,b_2) \n            := \\qty{((a_1,a_2),(b_1,b_2)) \\st (a_1 \\cdot a_1 + \\cdot a_2 \\cdot a_2) \n                \\leq (b_1 \\cdot b_1 + \\cdot b_2 \\cdot b_2)}\n        $$\n        $(a_1, a_2) \\Rel_2 (b_1,b_2)$ satisfies the 3 ordered properties:\n        \\subsubsection{Reflective: $x \\Rel_2 x$}\n        \\begin{align*}\n            (a_1 \\cdot a_1 + 2 \\cdot a_2 \\cdot a_2) \n                \\leq (b_1 \\cdot b_1 + \\cdot b_2 \\cdot b_2)\n                &\\implies a \\Rel_2 b\\\\\n            (x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2) \n                \\leq (x_1 \\cdot x_1 + \\cdot x_2 \\cdot x_2)\n                &\\implies x \\Rel_2 x\\\\\n            x_1^2 + x_2^2 \\leq x_1^2 + x_2^2 &\\implies x \\Rel_2 x\n        \\end{align*}\n        \n        \\subsubsection{Anti-Symmetry: $x \\Rel_2 y \\land y \\Rel_2 x$}\n        \\begin{align*}\n            x \\Rel_2 y \\land y \\Rel_2 x &\\implies x = y\\\\\n            (x_1,x_2) \\Rel_2 (y_1,y_2) \\land (y_1,y_2) \\Rel_2 (x_1,x_2) \n                &\\implies (x_1,x_2)=(y_1,y_2)\\\\\n            \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2))\n            &\\land\\\\\n                \\land \\qty((y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2)\n                    \\leq (x_1 \\cdot x_1 + \\cdot x_2 \\cdot x_2))\n                &\\implies (x_1,x_2) = (y_1,y_2)\\\\\n            \\qty(x_1^2 + x_2^2 \\leq y_1^2 + y_2^2)\n                \\land \\qty(y_1^2 + y_2^2 \\leq x_1^2 + x_2^2)\n                &\\implies (x_1,x_2) = (y_1,y_2)\\\\\n            % (x \\cdot x \\leq y \\cdot y) \\land (y \\cdot y \\leq x \\cdot x)\n            %     &\\implies x = y\n        \\end{align*}\n        \n        \\subsubsection{Transivity: $x \\Rel_2 y \\land y \\Rel_2 z \\implies x \\Rel_2 z$}\n        \\begin{align*}\n            x \\Rel_2 y \\land y \\Rel_2 z \n                &\\implies x \\Rel_2 z\\\\\n            (x_1,x_2) \\Rel_2 (y_1,y_2) \\land (y_1,y_2) \\Rel_2 (z_1,z_2)\n                &\\implies (x_1,x_2) \\Rel_2 (z_1,z_2)\\\\\n            \\qty((x_1 \\cdot x_1 + 2 \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2)) \n                \\land&\\\\\n                \\land \\qty((y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2)\n                    \\leq (z_1 \\cdot z_1 + \\cdot z_2 \\cdot z_2)) \n                &\\implies \\qty((x_1 \\cdot x_1 + \\cdot x_2 \\cdot x_2)\n                    \\leq (z_1 \\cdot z_1 + \\cdot z_2 \\cdot z_2))\\\\\n            \\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n                    \\land \\qty(y_1^2 + y_2^2 \\leq z_1^2 + z_2^2)\n                &\\implies \\qty(x_1^2 + x_2^2 \\leq z_1^2 + z_2^2)\\\\\n            x_1^2 + x_2^2 \\leq y_1^2 + y_1^2 \\leq z_1^2 + z_2^2\n                &\\implies x \\cdot x \\leq y \\cdot y \\leq z \\cdot z\n        \\end{align*}\n    \\end{proof}\n\\end{theorem}\n\n\\begin{theorem}\n    The ordered relation $x \\Rel_1 y$ forms a total order over $\\mathbb{F}$.\n    \\begin{proof}\n        $x \\Rel_2 y$ satisfies the totality condition:\n        \\subsubsection{Totality: \n        $\\forall x,y \\in \\mathbb{F} \\implies x \\Rel_2 y \\lor y \\Rel_2 x$}\n        \\begin{align*}\n            \\forall x,y \\in \\mathbb{F} &\\implies x \\Rel_2 y \\lor y \\Rel_2 x\\\\\n            \\forall_{x \\in \\Q(\\sqrt{2})}\n                    \\forall_{y \\in \\Q(\\sqrt{2})}\n                &\\implies \\qty(x \\cdot x \\leq y \\cdot y)\n                    \\lor \\qty(y \\cdot y \\leq x \\cdot x)\\\\\n            \\forall_{(x_1,x_2) \\in \\Q(\\sqrt{2}))}\n                    \\forall_{(y_1,y_2) \\in \\Q(\\sqrt{2})}\n                &\\implies \\qty((x_1 \\cdot x_1 + \\cdot x_2 \\cdot x_2)\n                    \\leq (y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2)) \\lor\\\\\n                &\\qquad \\lor \\qty((y_1 \\cdot y_1 + \\cdot y_2 \\cdot y_2)\n                    \\leq (x_1 \\cdot x_1 + \\cdot x_2 \\cdot x_2))\\\\\n            % \\forall_{x_1 \\in \\N} \\forall_{x_2\\in \\N}\n            %         \\forall_{y_1 \\in \\N} \\forall_{y_2 \\in \\N}\n            \\forall_{x_1, x_2, y_1, y_2 \\in \\N}\n                &\\qty(\\qty(x_1^2 + x_2^2 \\leq y_1^2 + y_2^2)\n                    \\lor \\qty(y_1^2 + y_2^2 \\leq x_1^2 + x_2^2))\\\\\n            % \\forall_{x_1, x_2, y_1, y_2 \\in \\Q(\\sqrt{2})}\n            %     &\\qty(x_1^2 + 2 x_2^2 \\leq y_1^2 + 2 y_2^2)\n            %         \\lor \\qty(y_1^2 + 2 y_2^2 \\leq x_1^2 + 2 x_2^2)\n        \\end{align*}\n    \\end{proof}\n\\end{theorem}\n\n% Problem 5\n\\newpage\n\\section{}\nInfinitely many wizards $W_1, W_2,\\dots$ stay in the line.\nEach wizard wears a hat of one the three colors: Red, Yellow or Green. \nEvery wizard $W_n$ can see the hats of all the next wizards in line, $W_{n+1}, W_{n+2}, \\dots$,\nStarting  with  the  wizard $W_1$ every one has to guess the color of his own hat. \nIf the wizard guesses correctly, he can go free. Otherwise he got dematerialized. \nWizards  discussed  their  strategy  before  this  event. \nShow that if the wizards were smart enough, then only finitely many of them will disappear.\n\n\\subsection*{Assumptions}\n\\begin{assumption}\\label{asmp:selfless}\n    It is assumed that the Wizards are not only all smart, but also selfless to attempt to \n    save the most number of wizards instead of just themselves.\n\\end{assumption}\n\\begin{assumption}\n    Although it is not stated in the problem, it is assumed that the Wizards \n    are unable to directly communicate the color of the hats to someone else, \n    but it is also assumed that an infinite memory of past guesses exists.\n\\end{assumption}\n\n\\subsection*{Sequence Definitions}\n\\begin{definition}\n    Let the sequence $\\qty{W_n}$ be defined as\n    $$\\qty{W_n} := \\qty{W_n \\st W_n \\in \\{1,2,3\\}}$$\n    with index $n$ related to each of the wizards in order and \n    $1,2,3$ represent `Red', `Yellow', and `Green' respectively.\n\\end{definition}\n\\begin{definition}\n    Let the updating sequence $\\qty{G_n}$ be defined as the guess that each Wizard makes.\n\\end{definition}\n\\begin{definition}\n    An updating sequence $\\qty{Q_n}$ is defined as a queue of causal memory that each wizard \n    maintains according to the same set of rules.\n\\end{definition}\n\\subsection*{Decision Procedure}\nThe procedure described is one of many potential decision criterion that can be used to \nmake guesses and minimize the number of incorrect hat color guesses. The basic idea \nis that following the initialization of the procedure, each Wizard will maintain their own \nqueue based on what previous Wizards guessed and what they perceive from the following \nWizards hat colors. This queue will be long enough that when a wizard is reached it should \nknow what color their own hat is along with future hat colors. They then make a decision based \non the queue and the wizard following the end of the queue as to what hat to guess in order \nto either share information to the future Wizards or to save themselves. The procedure is \ndesigned so that repeated colors are used to expand the length of the queue and allow \nfor wizards to use the information to save themselves without creating a deficit.\nBy Assumption , the decision will always be according to the procedure \nthat will do the best for everyone and not just save themselves.\n\n\\newpage\nThe following pseudo-code outlines the decision procedure that all the wizards will use. \nLet $N=\\infty$, time index $n$, queue length $k$, and arbitrarily set minimum queue length $K = 20$.\n\\begin{lstlisting}\n% Initialization\nfor i = 5:N % min start is 5\n    if W(i+1) == W(i) % First set of same color hat\n        k = i;\n        break\n    end\nend\n% Initialize Queue\nfor n = 1:k\n    G(n) = W(n + k);\n    Q(n + k) = G(n);\nend\n% Standard Decision Procedure\nwhile n < N\n    if Q(n) == Q(n+1)\n        G(n) = Q(n);\n    else if k > K && G(n) \\lnot = W(n+k)\n        G(n) = Q(n);\n    else\n        G(n) = W(n + k)\n        Q(n + k) = G(n);\n    end\n    while W(n + k) == W(n + k + 1)\n        Q(n + k + 1) = W(n + k + 1);\n        k = k + 1;\n    end\n    n = n + 1;\nend\n\\end{lstlisting}\n% look at that else if statement again... and make sure it'll still work\n\n\n\\subsection*{Effectiveness of Procedure}\nA proof of Effectiveness is probably easily demonstrated through mathematical induction. \nEssentially, the finite loss of Wizards can be demonstrated using the size of $k$ \nbeing bounded from below and increasing regardless of the color of the next hat. \nAlthough I'm not proving this method is the optimal way to minimize the loss of wizards, \nit is clear that the expanding queue-based method will eventually, within a finite number of \niterations, ensure that the queue is large and robust enough to prevent the continued \ndematerialization of wizards.\n\n% Problem 6\n\\newpage\n\\section{}\nShow that $A$ is an infinite set if and only if $A$ has a proper subset \n$B \\ : \\ (B \\subsetneq A)$ with the same cardinality $(\\abs{A} = \\abs{B})$.\\\\\n\n\\begin{theorem}\n    $$\\abs{A} \\geq \\aleph_0 \\iff \\exists {B\\subsetneq A} : \\abs{A} = \\abs{B}$$\n    \\begin{proof}\n        Proof by contradition.\\\\\n        Assume $\\abs{A} < \\aleph_0$,\n        \\begin{align*}\n            \\abs{A} < \\aleph_0 &\\iff \\exists {B\\subsetneq A} : \\abs{A} = \\abs{B}\\\\\n            &\\iff \\exists {B\\subsetneq A} : \\abs{A} = \\abs{B}\\\\\n        \\end{align*}\n    \\end{proof}\n\\end{theorem}\n\n\n\\includegraphics[width=\\textwidth]{MidExam1_pblm6.png}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "11519f0511b5dbe566458719a2e545f3e7bc9432", "size": 22823, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/Exam1/MATH5301-MidExam1.tex", "max_stars_repo_name": "jonaswagner2826/MATH5301", "max_stars_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-01T05:26:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-01T05:26:53.000Z", "max_issues_repo_path": "Exams/Exam1/MATH5301-MidExam1.tex", "max_issues_repo_name": "jonaswagner2826/MATH5301", "max_issues_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exams/Exam1/MATH5301-MidExam1.tex", "max_forks_repo_name": "jonaswagner2826/MATH5301", "max_forks_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_forks_repo_licenses": ["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.6598130841, "max_line_length": 127, "alphanum_fraction": 0.5739385707, "num_tokens": 8429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.630859301524665}}
{"text": "\\chapter{Kalman Filter}\n\\label{chp:kalman}\n\nThe Kalman filter algorithm for localization is a spacial case of Markov localization already described in chapter \\ref{chp:local}.\nThe Kalman filter is different in the sense that instead of calculating the probability discrete for every tile on the map, the position is modelled with a continuous Gaussian distribution.\nA Gaussian is a well known and often used distribution in probability theory.\nThe Gaussian function is shown in equation \\ref{eq:Gaussian}, and is defined by two values, the mean \\emph{$\\mu$} that describe the middle of the distribution, and the variance \\emph{$\\sigma^2$} that describe spread of the distribution.\n\n\\begin{equation}\n\\label{eq:Gaussian}\nf(x) = \\frac{1}{\\sqrt{2*\\pi*\\sigma^2}} * exp^{-\\frac{1}{2}*\\frac{(x-\\mu)^2}{\\sigma^2}}\n\\end{equation}\n\nWhen having a multivariate Gaussian distribution in more dimensions the mean becomes a vector \\emph{$\\vec{\\mu}$}, and the variance becomes a covariance matrix \\emph{$\\Sigma$} defining the spread in all dimensions.\nFigure \\ref{fig:Gaussian} show a multivariate Gaussian distribution, this could be an example of the probability of a robot being in different positions in a x,y plane.\n\n\\myFigure{Theory/KalmanFilter/Gaussian}{Multivariate Gaussian distribution in two dimensions.}{fig:Gaussian}{0.6}\n\nThe Kalman filter is based on a state space model, example seen on figure \\fref{fig:StateSpaceModel}, that is used to describe and predict the behaviour of linear systems.\nThe state space model describe how a system transform some input/movement \\emph{$\\vec{u}$} to a hidden state \\emph{$\\vec{x}$}, and generate an output/measurement \\emph{$\\vec{y}$}, with the use of matrices. The most impotent is the input matrix \\emph{$G$} that transform the input to the hidden state, the state transmission matrix \\emph{$F$} that predict the next hidden state from the present and the output matrix \\emph{$H$} that transform the hidden state to the output. Noise is added on both input and output of the system.\n\nAn example of a state space model could be a robot that apply an acceleration as input, measure a noisy position, and tries to estimate its velocity and true position.\n\n\\myFigure{Theory/KalmanFilter/StateSpaceModel}{An example of a state space model, that is used describe linear system with a set of matrices. This model describe how a system transform some input \\emph{$\\vec{u}$} to a hidden state \\emph{$\\vec{x}$}, and generate an output \\emph{$\\vec{y}$}.}{fig:StateSpaceModel}{0.8}\n\n\\pagebreak\n\nJust as the Markov localization the Kalman filter is separated in two steps.\nThe prediction step is trying to predict the robots next position based on some movement, and the update step is estimating the robot position based on the prediction and a number of measurements.\nThe system continuously switch between predicting and updating to localize the robot.\n\nEquation \\ref{eq:KalmanPrediction1} and \\ref{eq:KalmanPrediction2} show the Kalman filter prediction step.\nThe basic principle of the prediction step is to move the Gaussian distribution of the estimated position to a new location based on some movement.\nThere will always be noise in the movement procedure, this mean the Gaussian distribution of the hidden state will always have a bigger spread after movement that before, do to the loss of information.\nThe first equation \\ref{eq:KalmanPrediction1} is predicting the hidden state \\emph{$\\vec{x'}$} from the previous state and the movement \\emph{$\\vec{u}$}.\nThe second equation \\ref{eq:KalmanPrediction2} is predicting the covariance matrix of the hidden state from the previous covariance matrix and the system noise from the movement.\n\n\\begin{equation}\n\\label{eq:KalmanPrediction1}\n\\vec{x}'_{k} = \\boldsymbol{F} * \\vec{x}_{k-1} + \\boldsymbol{G} * \\vec{u}_{k}\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:KalmanPrediction2}\n\\boldsymbol{P}'_{k} = \\boldsymbol{F} * \\boldsymbol{P}_{k-1} * \\boldsymbol{F}^T + \\boldsymbol{G} * \\boldsymbol{Q} * \\boldsymbol{G}^T\n\\end{equation}\n\nEquation \\ref{eq:KalmanUpdate1} to \\ref{eq:KalmanUpdate4} show the Kalman filter update step.\nThe basic principle of the update step is to combine one or more Gaussian distributions from the state estimate and sensor measurements, to get a new more precise estimate.\nWhen combining two Gaussian distributions, the result distribution will always have a smaller spread than any of the two original distributions, this is do to information gain in the system.\nThe first equation \\ref{eq:KalmanUpdate1} is calculating the error $ \\varepsilon_{k} $ of the predicted state and the true measurement.\nEquation \\ref{eq:KalmanUpdate2} is the Kalman gain $ \\boldsymbol{G}_{k} $, this is a factor determining how big impact the measurement has on the state prediction, depending on the ratio of the state covariance matrix $\\boldsymbol{P}'_{k}$ and the sensor noise $\\boldsymbol{R}$.\nIn case of relative small sensor noise, meaning that the measurements are accurate, the state estimate depends mostly on the measurements, and in case of relative high sensor noise, meaning that the measurements are inaccurate, the state estimate instead depends mostly on the previous state.\nIn the end equation \\ref{eq:KalmanUpdate3} and \\ref{eq:KalmanUpdate4} calculate the new state estimate and covariance matrix, based on the sensor error, Kalman gain and predicted covariance matrix.\n\n\\begin{equation}\n\\label{eq:KalmanUpdate1}\n\\varepsilon_{k} = \\vec{z}_{k} - \\boldsymbol{H} * \\vec{x}'_{k}\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:KalmanUpdate2}\n\\boldsymbol{G}_{k} = \\boldsymbol{P}'_{k} * \\boldsymbol{H}^T * (\\boldsymbol{H} * \\boldsymbol{P}'_{k} * \\boldsymbol{H}^T + \\boldsymbol{R})^-1\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:KalmanUpdate3}\n\\vec{x}_{k} = \\vec{x}'_{k} + \\boldsymbol{G}_{k} * \\varepsilon_{k}\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:KalmanUpdate4}\n\\boldsymbol{P}_{k} = (\\boldsymbol{I} - \\boldsymbol{K}_{k} * \\boldsymbol{H}) * \\boldsymbol{P}'_{k}\n\\end{equation}\n\nThe Kalman filter is a very useful tool in the field of localization and autonomous robots.\nIt is often used to estimate characteristics in the surrounding environment of a robot, as predicting the speed of another car, without being able to measure speed directly.\n\nThe Kalman filter have some drawbacks though.\nAs the state estimate is modelled with a Gaussian distributions, with only one peak, is it not possible to model a scenario where there is a probability of the robot being in two different positions.\nThe system also have to be linear to be able to make the state space model that is necessary for the Kalman filter to work.\nThe term Extended Kalman filter originates from this problem, in the sense that Extended Kalman filters is about ways of transforming nonlinear systems to linear systems so that Kalman filters can be used.", "meta": {"hexsha": "6bf0c9a1d5963ecb2c7e5641a42dc6bbda91e1d6", "size": 6812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/KalmanFilter.tex", "max_stars_repo_name": "Rotvig/AI-Robotics-Project", "max_stars_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_stars_repo_licenses": ["MIT"], "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/KalmanFilter.tex", "max_issues_repo_name": "Rotvig/AI-Robotics-Project", "max_issues_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_issues_repo_licenses": ["MIT"], "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/KalmanFilter.tex", "max_forks_repo_name": "Rotvig/AI-Robotics-Project", "max_forks_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_forks_repo_licenses": ["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.0731707317, "max_line_length": 528, "alphanum_fraction": 0.7756899589, "num_tokens": 1727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6308593015246649}}
{"text": "\\chapter{Dynamics Modelling}\r\n\r\nIn this chapter, we\r\npresent the mathematical forumulation of the orbit and attitude dynamcis models in GMAT.\r\nOne of the fundamental capabilities of GMAT is to model the motion\r\nof spacecraft in different flight regimes.  The flight regime,\r\nsuch as low Earth, libration point, or lunar, are determined by the\r\nforces and perturbations that dominate the dynamics.\r\nThe chapter begins with an overview of\r\nthe orbital equations of motion and their variational equations.  Next, we\r\ndiscuss the formulation for orbital perturbations and the equations used to model\r\nspacecraft thrust.  The second half of the chapter is devoted to attitude modeling and\r\nwe present the specifications for  attitude conversions and kinematic attitude models.\r\n\r\n\r\n\\section{Orbit Dynamics}\r\n\r\n\\subsection{Orbital Equations of Motion}\r\n\r\nThe orbital equations of motion come from an application of Newton's laws of motion to a spacecraft in orbit.  From Newton's Second Law we know that\r\n%\r\n\\begin{equation}\r\n     \\frac{d (m\\mathbf{v})}{d t} = \\sum F_{ext}\r\n\\end{equation}\r\n%\r\nwhere $m$ is the total mass of the spacecraft, $\\mathbf{r}$ is the position vector of the spacecraft, $t$ is time, and the right hand side of the equation represents the total sum of external forces.  Solving for the acceleration gives us the\r\nsecond order differential equation\r\n%\r\n\\begin{equation}\r\n   \\frac{d^2 \\mathbf{r}}{d^2 t} = \\sum \\frac{F_{ext}}{m} - \\frac{\\dot{m}}{m}\\frac{\\partial \\mathbf{r}}{\\partial t}\r\n   \\label{Eq:SCAcc}\r\n\\end{equation}\r\n%\r\n\r\nThe terms included in the RHS of the equations of motion can be selected by the user, and the form of several terms (and whether they appear at all) are dependent upon the coordinate system of integration.    If we include\r\nall of the possible forces GMAT can model in the summation on the\r\nRHS of Eq.~(\\ref{Eq:SCAcc}), and we assume the origin of integration is a celestial body (the barycentric form is slightly different), then the orbital equations of motion are\r\n%\r\n\\begin{equation} \\begin{split}\r\n    \\frac{d^2\\mathbf{r}}{dt^2}\r\n    =  &-\\frac{\\mu}{r^3}\\mathbf{r} +  \\nabla \\phi_{sj}^o +\r\n    %\r\n    G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}m_k \\left(\\frac{\\mathbf{r}_{ks}}{r_{ks}^3} -\r\n     \\frac{\\mathbf{r}_{kj} }{r_{kj}^3}   \\right)\r\n     %\r\n    + %\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left( \\nabla\r\n    %\\phi_{ks}^o +\r\n     %\\nabla\\phi_{kj}^o\r\n     %\\right)+\r\n     \\frac{\\dot{m}_s }{m}\\frac{d\\mathbf{r}}{dt}- \\frac{1}{2}\\rho v_{rel}^2 \\frac{C_d A}{m_s}\\hat{\\mathbf{v}}_{rel}\r\n     +\\frac{   P_{SR}C_R A_{\\odot}   }{m_s}\\hat{\\mathbf{r}}_{s\\odot} + \\\\ &\r\n         \\frac{\\mu}{c^2 r^3}\\left(  \\left( 4\\frac{\\mu}{r} - v^2\\right)\\mathbf{r} +   4(\\mathbf{r}\\cdot\\mathbf{v})\\mathbf{v}\\right) + 2 (\\boldsymbol{\\Omega} \\times \\mathbf{v}) + 2 \\frac{\\mu}{c^2 r^3}\r\n    \\left( \\frac{3}{r^2}(\\mathbf{r} \\times \\mathbf{v})(\\mathbf{r} \\cdot \\mathbf{J}) +(\\mathbf{v}\\times\\mathbf{J}) \\right)\r\n     \\label{Eq:CompleteEOM}\r\n     \\end{split}\r\n\\end{equation}\r\n%\r\nTable \\ref{Eq:AllForces} below describes each force in the equation above.\r\n%\r\n\\begin{table}[h]\r\n\\centering \\caption{ Force Models Available in GMAT } \\label{Eq:AllForces}\r\n\\begin{tabular}{p{2.0 in} p{2.75 in} }\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n  Description & Term \\\\\r\n  \\hline\r\n  Central Body Point Mass & $ -\\displaystyle\\frac{\\mu}{r^3}\\mathbf{r}$ \\\\\r\n  & \\\\\r\n  Central Body Direct Nonspherical &  $\\nabla \\phi_{sj}^o$  \\\\\r\n  & \\\\\r\n  Direct Third Body Point Mass & $G\\displaystyle\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}m_k \\left(\\frac{\\mathbf{r}_{ks}}{r_{ks}^3}\\right)$ \\\\\r\n   & \\\\\r\n  Indirect Third Body Point Mass &  $G\\displaystyle\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}m_k \\left( -\r\n     \\frac{\\mathbf{r}_{kj} }{r_{kj}^3}   \\right)$ \\\\\r\n      & \\\\\r\n   %Third Body Direct Nonspherical & $\\displaystyle\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left( \\nabla\r\n   % \\phi_{ks}^o\\right)$  \\\\\r\n   % &\\\\\r\n   % Third Body Indirect Nonspherical &  $\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(\r\n   %  \\nabla\\phi_{kj}^o \\right)$\\\\\r\n   % & \\\\\r\n   Spacecraft Thrust &$\\displaystyle\\frac{\\dot{m}_s }{m}\\frac{d\\mathbf{r}}{dt}$\\\\\r\n   &\\\\\r\n   Atmospheric Drag & $- \\displaystyle\\frac{1}{2}\\rho v_{rel}^2 \\displaystyle\\frac{C_d\r\n   A}{m_s}\\hat{\\mathbf{v}}_{rel}$\\\\\r\n   &\\\\\r\n   Solar Radiation Pressure & $\\displaystyle\\frac{   P_{SR}C_R A_{\\odot}   }{m_s}\\hat{\\mathbf{r}}_{s\\odot}$\\\\\r\n   &\\\\\r\n   Schwarzschild solution & $\\displaystyle\\frac{\\mu}{c^2 r^3}\\left(  \\left( 4\\frac{\\mu}{r} - v^2\\right)\\mathbf{r} +            4(\\mathbf{r}\\cdot\\mathbf{v})\\mathbf{v}\\right) + 2 (\\boldsymbol{\\Omega} \\times \\mathbf{v})$\\\\\r\n      &\\\\\r\n   Geodesic Precession & $2 (\\boldsymbol{\\Omega} \\times \\mathbf{v}) $\\\\\r\n         &\\\\\r\n   Lense-Thirring Precession & $2 \\displaystyle\\frac{\\mu}{c^2 r^3}\r\n    \\left( \\frac{3}{r^2}(\\mathbf{r} \\times \\mathbf{v})(\\mathbf{r} \\cdot \\mathbf{J}) +(\\mathbf{v}\\times\\mathbf{J}) \\right)$\\\\\r\n  \\hline\\hline\r\n\\end{tabular}\r\n\\end{table}\r\n%\r\n\\subsection{Coordinate Systems for Integration of the Equations of Motion}\r\n\r\n\\subsection{Orbit Variational Equations and the State Transition Matrix}\r\n\r\nEstimation and optimization problems require first derivatives of the solution\r\nto the orbit final value problem with respect to orbital initial conditions.  Those\r\nderivatives are provided by the orbit variational equations.  The variatial equations are\r\nobtained by expanding the orbital equations of motion in a Taylor series and retaining\r\nonly the linear terms.\r\n%\r\nAssume the nonlinear dynamics have the following form\r\n%\r\n\\begin{equation}\r\n    \\dot{\\mathbf{x}} = \\mathbf{f}(\\mathbf{x},t)\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n    \\mathbf{x} = \\left[\\mbr^T \\hspace{.2 in} \\mbv^T  \\right]^T = \\left[x \\hspace{.2 in} y \\hspace{.2 in} z \\hspace{.2 in} \\dot{x} \\hspace{.2 in}\r\n    \\dot{y} \\hspace{.2 in} \\dot{z}  \\right]^T\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation}\r\n    \\dot{\\mathbf{x}} = \\left[\\dot{\\mbr}^T \\hspace{.2 in} \\dot{\\mbv}^T  \\right]^T = \\left[\\dot{x} \\hspace{.2 in}\r\n    \\dot{y}\r\n    \\hspace{.2 in} \\dot{z} \\hspace{.2 in} \\ddot{x} \\hspace{.2 in}\r\n    \\ddot{y} \\hspace{.2 in} \\ddot{z}  \\right]^T\r\n\\end{equation}\r\n%\r\nExpanding the dynamics equations and retaining only the first order terms yields\r\n%\r\n\\begin{equation}\r\n    \\dot{\\mathbf{x}} \\approx  \\dot{\\mathbf{x}}|_{ref} + \\frac{\\partial \\mathbf{f}}\r\n    {\\partial \\mathbf{x}}\\left( \\mathbf{x} - \\mathbf{x}|_{ref} \\right)\\label{Eq:VarTaylorSeries}\r\n\\end{equation}\r\n%\r\n%\r\nWe can rewrite Eq.~(\\ref{Eq:VarTaylorSeries}) by defining $\\delta \\mathbf{x} = \\dot{\\mathbf{x}} - \\dot{\\mathbf{x}}|_{ref}$ as follows.\r\n%\r\n\\begin{equation}\r\n    \\delta \\dot{\\mathbf{x}} = \\mathbf{A}\\delta \\mathbf{x}\\label{Eq:LinearizedOEM}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\nthe Jacobian of the state equations is defined as the ``A\" matrix as follows:\r\n%\r\n\\begin{equation}\r\n    \\mathbf{A} = \\frac{\\partial \\mathbf{f}}{\\partial \\mathbf{x}}\r\n\\end{equation}\r\n\r\nFrom linear systems theory, the solution to Eq.~(\\ref{Eq:LinearizedOEM}) has the form\r\n%\r\n\\begin{equation}\r\n     \\delta \\mathbf{x}(t_f) = \\boldsymbol{\\Phi}(t,t_o)\\delta \\mathbf{x}(t_o)\r\n\\end{equation}\r\n%\r\nwhere $\\dot{\\boldsymbol{\\Phi}}$ is governed by the following set of 36 differential equations:\r\n%\r\n\\begin{equation}\r\n     \\dot{\\boldsymbol{\\Phi}} = \\mathbf{A}\\boldsymbol{\\Phi}\r\n\\end{equation}\r\n%\r\nGMAT simultaneously integrates the variational equations along with the non-linear state equations from $t_o$ to $t_f$ to obtain the State Transition Matrix (STM):\r\n%\r\n\\begin{equation}\r\n     \\boldsymbol{\\Phi}(t_o,t_f) = \\int_{t_o}^{t_f}\\mathbf{A}\\boldsymbol{\\Phi} dt \\label{Eq:STMSolution}\r\n\\end{equation}\r\n%\r\nsubject to the initial conditions\r\n%\r\n\\begin{equation}\r\n     \\boldsymbol{\\Phi}(t_o,t_o) = \\mathbf{I}_{6\\times6}\r\n\\end{equation}\r\n%\r\nTo perform the integration in Eq.~(\\ref{Eq:STMSolution}) we require the partial derivatives contained in the matrix $\\mathbf{A}$:\r\n%\r\n\\begin{equation}\r\n     \\mathbf{A} = \\frac{\\partial \\dot{\\mathbf{x}}}{\\partial\r\n     \\mathbf{x}}=\r\n     \\left(\\begin{array}{ccc}\r\n              \\displaystyle\\frac{\\partial \\mathbf{v}}{\\partial \\mathbf{r}} & \\displaystyle\\frac{\\partial \\mathbf{v}}{\\partial\r\n              \\mathbf{v}}\\vspace{.1 in}\\\\\r\n              %\r\n              \\displaystyle\\frac{\\partial \\mathbf{a}}{\\partial \\mathbf{r}} & \\displaystyle\\frac{\\partial \\mathbf{a}}{\\partial\r\n              \\mathbf{v}}\r\n     \\end{array}\\right)\r\n\\end{equation}\r\n%\r\nTwo of the derivatives are trivial:\r\n%\r\n\\begin{equation}\r\n     \\displaystyle\\frac{\\partial \\mathbf{v}}{\\partial \\mathbf{r}} = \\mathbf{0}_{3x3}\r\n\\end{equation}\r\n%\r\n%\r\n\\begin{equation}\r\n     \\displaystyle\\frac{\\partial \\mathbf{v}}{\\partial \\mathbf{v}} = \\mathbf{I}_{3x3}\r\n\\end{equation}\r\n%\r\nThe remaining two terms, $\\partial\\mathbf{a}/\\partial\\mathbf{r}$\r\nand $\\partial \\mathbf{a}/\\partial \\mathbf{v}$, are dependent upon the specific perturbations included in the force model.  The partial derivatives of perturbations are provided in the sections containing the specific formulation of the perturbing force.\r\n\r\n\\subsection{Multiple Spacecraft Propgation and Coupled Propagation of the Equations of Motion}\r\n\r\n\\section{Force Modelling}\r\n\r\n\\subsection{$n$-Body Point Mass Gravity}\r\n\r\nThe gravitational perturbation due to $n$ point masses is well know.\r\nHowever, we will derive the governing differential equation here, as\r\nwell as the componenents of the sensitivity matrix.\r\n Let's begin by defining some notation referring to\r\nFig.\\ref{fig:NBody}. Assume the $j^{\\mbox{th}}$ body is the central\r\nbody of the integration.\r\n%\r\n\\begin{figure}[h!]\r\n\\centerline{\r\n\\begin{picture}(100,500)\r\n\\special{psfile= Images/NBodyDiagram.eps hoffset= -135 voffset= -45\r\nhscale=85 vscale=85} \\makebox(-20,585){$\\hat{\\mathbf{x}}_{I}$}\r\n\\makebox(270,700){$\\hat{\\mathbf{y}}_{I}$} \\makebox(-330,770){$\r\n\\tilde{\\mathbf{r}}_{s}$} \\makebox(-330,877){$\\mathbf{r}$}\r\n\\makebox(-270,900){$\\mathbf{r}_{sk}$}\r\n\\makebox(-390,964){$\\mathbf{r}_{k}$}\r\n\\makebox(-500,814){$\\tilde{\\mathbf{r}}_{j}$}\r\n\\makebox(-500,980){Central Body} \\makebox(-320,995){$k^{th}$ Body}\r\n\\end{picture}}\\vskip -4.0 in  \\caption{ N-Body Illustration} \\label{fig:NBody}\r\n\\end{figure}\r\n%\r\n%\r\n\\begin{itemize}\r\n   %\r\n   \\item  $\\tilde{\\mathbf{r}}_s$ is the position of the spacecraft with respect\r\n   a hypothesized inertial frame.\r\n   %\r\n   \\item  $\\tilde{\\mathbf{r}}_j$ is the position of the central body with respect\r\n   a hypothesized inertial frame.\r\n   %\r\n   \\item  $\\tilde{\\mathbf{r}}_k$ is the position of the $k^{th}$ gravitational body with respect\r\n   a hypothesized inertial frame.\r\n   %\r\n   \\item  $\\mathbf{r}$ is the position of the spacecraft with respect\r\n   to the central body of integration ($j^{th}$ body).\r\n   %\r\n   \\item  $\\mathbf{r}_k$ is the position of the $k^{th}$ gravitational body with respect\r\n   to the central body.\r\n   %\r\n\\end{itemize}\r\n\r\nWe need the governing differential equation that describes the\r\nmotion of the spacecraft with respect to the central body.  However,\r\nwe know that we must apply Newton's 2nd Law in an inertial frame.\r\nSo, we begin by defining the relative position of the spacecraft\r\nwith respect to the central body.  From inspection of\r\nFig.\\ref{fig:NBody} we see that\r\n%\r\n\\begin{equation}\r\n     \\tilde{\\mathbf{r}}_j +  \\mathbf{r} = \\tilde{\\mathbf{r}}_s\r\n\\end{equation}\r\n%\r\nBy reordering and taking the second derivative with respect to time\r\nwe obtain\r\n%\r\n\\begin{equation}\r\n     \\ddot{\\mathbf{r}} = \\ddot{\\tilde{\\mathbf{r}}}_s - \\ddot{\\tilde{\\mathbf{r}}}_j\r\n     \\label{Eq:SCRelativeODE}\r\n\\end{equation}\r\n%\r\nWe can apply Newton's 2nd Law to the spacecraft and obtain\r\n%\r\n\\begin{equation}\r\n     m_s \\ddot{\\tilde{\\mathbf{r}}}_s = \\sum_{k=1}^n F_k =\r\n     G\\sum_{k=1}^n \\frac{m_s m_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3} \\left(\\mathbf{r}_{k} -\r\n     \\mathbf{r}\\right)\r\n\\end{equation}\r\n%\r\nwhere $\\left(\\mathbf{r}_{k} - \\mathbf{r}\\right)$ is a vector from\r\nthe spacecraft to the $k^{th}$ body, $m_s$ is the mass of the\r\nspacecraft, and $m_k$ is the mass of the $k^{th}$ body.  We can\r\nwrite $\\ddot{\\tilde{\\mathbf{r}}}_s$ as simply\r\n%\r\n\\begin{equation}\r\n    \\ddot{\\tilde{\\mathbf{r}}}_s =\r\n     G\\sum_{k=1}^n \\frac{m_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3} \\left(\\mathbf{r}_{k} -\r\n     \\mathbf{r}\\right) \\label{Eq:SCInertialODE}\r\n\\end{equation}\r\n%\r\nWe can apply Newton's 2nd Law to the $j^{th}$ body and obtain\r\n%\r\n\\begin{equation}\r\n     m_j \\ddot{\\tilde{\\mathbf{r}}}_j = \\frac{G m_s\r\n     m_j}{r^3}\\mathbf{r} +\r\n     G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n} \\frac{m_j m_k}{\\| \\mathbf{r}_{k}\\|^3}\\mathbf{r}_{k}\r\n\\end{equation}\r\n%\r\nwhere the first term is the influence of the spacecraft on the\r\ncentral body, and the second term is the influence of the $k$ point\r\nmass gravitational bodies.  We can write\r\n$\\ddot{\\tilde{\\mathbf{r}}}_j$ as simply\r\n%\r\n\\begin{equation}\r\n     \\ddot{\\tilde{\\mathbf{r}}}_j = \\frac{G m_s\r\n     }{r^3}\\mathbf{r} +\r\n     G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n} \\frac{ m_k}{\\|\r\n     \\mathbf{r}_{k}\\|^3}\\mathbf{r}_{k} \\label{Eq:CentalBodyInertialODE}\r\n\\end{equation}\r\n%\r\nSubstituting Eq.~(\\ref{Eq:SCInertialODE}) and\r\n(\\ref{Eq:CentalBodyInertialODE}) into (\\ref{Eq:SCRelativeODE}) we\r\nget\r\n%\r\n\\begin{equation}\r\n     \\ddot{\\mathbf{r}} =      G\\sum_{k=1}^n \\frac{m_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3} \\left(\\mathbf{r}_{k} -\r\n     \\mathbf{r}\\right) - \\frac{G m_s\r\n     }{r^3}\\mathbf{r} -\r\n     G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n} \\frac{ m_k}{\\|\r\n     \\mathbf{r}_{k}\\|^3}\\mathbf{r}_{k}\r\n\\end{equation}\r\n%\r\nFinally, collecting terms yields\r\n%\r\n\\begin{equation}\r\n     \\mathbf{a}_{pm} = \\ddot{\\mathbf{r}} =   \\underbrace{- \\frac{\\mu_j\r\n     }{r^3}\\mathbf{r}}_1  +  G \\sum_{\\stackrel{k=1}{k \\neq j}}^{n} m_k\\left( \\underbrace{\\frac{\\mathbf{r}_{k} -\r\n     \\mathbf{r}}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3}}_2  -\r\n     \\underbrace{\r\n      \\frac{ \\mathbf{r}_{k}}{\\|\r\n     \\mathbf{r}_{k}\\|^3}}_3\\right)\r\n\\end{equation}\r\n%\r\nWe can break down the acceleration in the equation above into three\r\nphysical categories.   The first term is the acceleration on the\r\nspacecraft due to a point mass central body.   The second type of\r\nterms are called direct terms.  They account for the force of the\r\n$k^{th}$ body on the spacecraft.  The third type of terms are called\r\nindirect.  They account for the force of the $k^{th}$ body on the\r\ncentral body.\r\n\r\nLet's look at the contributions to the sensitivity matrix due to\r\npoint mass perturbations.  We notice that $\\mathbf{a}_{pm}$ is not a\r\nfunction of velocity.  So,\r\n%\r\n\\begin{equation}\r\n    \\mathbf{A}_{pm} = \\mathbf{D}_{pm}  = \\mathbf{0}_{3\\times3}\r\n\\end{equation}\r\n%\r\nWe also know that\r\n%\r\n\\begin{equation}\r\n    \\mathbf{B}_{pm} = \\mathbf{I}_{3\\times3}\r\n\\end{equation}\r\n%\r\nThis leaves $\\mathbf{C}_{pm}$ as the only non-trivial term for point\r\nmass gravitational effects.  Let's look first at the derivatives of\r\nthe point mass term.  We can use the vector identity in\r\nEq.~(\\ref{Eq:vecIDaveca3}) to arrive at\r\n%\r\n\\begin{equation}\r\n     \\frac{\\partial }{\\partial \\mathbf{r}} \\left(- \\frac{\\mu_j\r\n     }{r^3}\\mathbf{r}\\right) =  -\\frac{\\mu_j}{r^3} \\mathbf{I}_3\r\n     + 3\\mu_j\\frac{\\mathbf{r}\\mathbf{r}^T}{r^5}\r\n\\end{equation}\r\n\r\nSimilarly, applying Eq.~(\\ref{Eq:vecIDaveca3}) to the direct terms\r\nwe see that\r\n%\r\n\\begin{equation}\r\n     \\frac{\\partial }{\\partial \\mathbf{r}} \\left( \\sum_{\\stackrel{k=1}{k \\neq j}}^{n} \\mu_k \\frac{\\mathbf{r}_{k} -\r\n     \\mathbf{r}}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3}\\right) =  -\\sum_{\\stackrel{k=1}{k \\neq j}}^{n}\r\n     \\frac{\\mu_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3}\\mathbf{I}_3 + 3\\sum_{\\stackrel{k=1}{k \\neq\r\n     j}}^{n}\\mu_k \\left( \\frac{\\left( \\mathbf{r}_{k} - \\mathbf{r} \\right)\\left( \\mathbf{r}_{k} -\r\n     \\mathbf{r} \\right)^T}{\\left( \\|\\mathbf{r}_{k} - \\mathbf{r} \\right)\\|^5}  \\right)\r\n\\end{equation}\r\n%\r\nFinally, the derivative of the indirect terms are zero and we have\r\n%\r\n\\begin{equation}\r\n   \\mathbf{C}_{pm} =  \\underbrace{-\\frac{\\mu_j}{r^3} \\mathbf{I}_3\r\n     + 3\\mu_j\\frac{\\mathbf{r}\\mathbf{r}^T}{r^5}}_{ 1 }\r\n     \\underbrace{\r\n     %\r\n     -  \\sum_{\\stackrel{k=1}{k \\neq j}}^{n}\r\n     \\frac{\\mu_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3}\\mathbf{I}_3 + 3\\sum_{\\stackrel{k=1}{k \\neq\r\n     j}}^{n} \\mu_k \\left( \\frac{\\left( \\mathbf{r}_{k} - \\mathbf{r} \\right)\\left( \\mathbf{r}_{k} -\r\n     \\mathbf{r} \\right)^T}{\\left( \\|\\mathbf{r}_{k} - \\mathbf{r} \\right)\\|^5}  \\right)\r\n       }_{2}\r\n     %\r\n\\end{equation}\r\n%\r\nCombining similar terms we can express the result as\r\n%\r\n\\begin{equation}\r\n   \\mathbf{C}_{pm} =  -  \\left( \\frac{\\mu_j}{r^3} + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n}\r\n     \\frac{\\mu_k}{\\| \\mathbf{r}_{k} - \\mathbf{r}\\|^3} \\right)\\mathbf{I}_3\r\n     %\r\n     + 3 \\left( \\mu_j\\frac{\\mathbf{r}\\mathbf{r}^T}{r^5}\r\n       + \\sum_{\\stackrel{k=1}{k \\neq\r\n     j}}^{n} \\mu_k \\left( \\frac{\\left( \\mathbf{r}_{k} - \\mathbf{r} \\right)\\left( \\mathbf{r}_{k} -\r\n     \\mathbf{r} \\right)^T}{\\left( \\|\\mathbf{r}_{k} - \\mathbf{r} \\right)\\|^5}\r\n     \\right) \\right)\r\n\\end{equation}\r\n\r\n\\subsection{Non-Spherical Gravity }\r\n\r\nGMAT integrates all spacecraft equations of motion using the\r\nEarth's Mean J2000 axis system. However, the user can choose\r\ncentral bodies other than the Earth as the origin of the\r\ncoordinate system of integration.  Gravitational forces are\r\nconservative and only a function of position.  To calculate the\r\ngravitational force due to a non-spherical body, we need to\r\ndetermine the position of the spacecraft in the body fixed frame\r\n$\\mathcal{F}_F$.  However, the equations of motion are expressed\r\nin terms of the position of the spacecraft in the inertial frame.\r\n\r\nWe know from dynamics that the acceleration in an inertial frame\r\ncan be calculated using\r\n%\r\n\\begin{equation}\r\n   \\mathbf{a}_{cb} = \\nabla U \\label{Eq:a_cb}\r\n\\end{equation}\r\n%\r\nwhere $U$ is the gravitational potential.  The potential for a\r\nnonspherical body comes from the solution to Laplace's equation:\r\n%\r\n\\begin{equation}\r\n     \\nabla^2 U= 0\r\n\\end{equation}\r\n%\r\nThe solution to this equation is most easily expressed in spherical,\r\nbody-fixed coordinates because it allows for a convenient separation\r\nof variables.\r\n\r\nIn spherical coordinates the gradient of the gravitational potential\r\nis\r\n%\r\n\\begin{equation}\r\n   \\nabla U = \\frac{\\partial U}{\\partial r}\\mathbf{u}_r +\r\n   \\frac{1}{r}\\frac{\\partial U}{\\partial \\phi} \\mathbf{u}_\\phi\r\n   + \\frac{1}{r \\cos{\\phi}}\\frac{\\partial U}{\\partial\r\n   \\lambda}\\mathbf{u}_\\lambda \\label{Eq:SphericalGradient}\r\n\\end{equation}\r\n%\r\nWe see that there are two singularities in\r\nEq.~(\\ref{Eq:SphericalGradient}).  The first is when $r = 0$, which\r\nis a nonphysical case and we will not discuss it further.  The\r\nsecond singularity occurs when $ \\phi = \\pm 90^\\circ$.  Pines\r\n\\cite{Pines:73} developed a uniform expression of the gravitational\r\npotential that avoids the singularity at the poles:\r\n%\r\n\\begin{equation}\\begin{split}\r\n    U = & \\frac{\\mu}{r}  \\biggl[   1 + \\sum_{n=1}^\\infty \\left(\\frac{R_{\\otimes}}{r}\\right)^n\r\n    \\sum_{m=0}^{n} A_{nm}(u)[C_{nm} cos{(m \\lambda)} \\cos^m{\\phi} \\\\\r\n    %\r\n    & +S_{nm}sin{(m \\lambda)} \\cos^m{\\phi} ]    \\biggr]\\end{split}\r\n    \\label{Eq:Pines1}\r\n\\end{equation}\r\n%\r\nExamining this form of the potential it is easy to see that there is\r\nnot a singularity at the poles when taking the gradient in spherical\r\ncoordinates.  Pines rewrites Eq.~(\\ref{Eq:Pines1}) as\r\n%\r\n\\begin{equation}\\begin{split}\r\n    U = & \\frac{\\mu}{r}  \\biggl[   1 + \\sum_{n=1}^\\infty \\left(\\frac{R_{\\otimes}}{r}\\right)^n\r\n    \\sum_{m=0}^{n} A_{nm}(u)[C_{nm} r_m(s,t) \\\\\r\n    %\r\n    & +S_{nm} i_m(s,t) ]    \\biggr]\\end{split}\r\n    \\label{Eq:PinesPotential}\r\n\\end{equation}\r\n%\r\nwhere $C_{nm}$ and $S_{nm}$ are the gravitational coefficients, $s$,\r\n$t$, and $u$ are given by\r\n%\r\n\\begin{equation}\r\n     s = x/r, \\hspace{.2 in} t = y/r, \\hspace{.2 in} u = z/r =\r\n     \\sin{\\phi} \\nonumber\r\n\\end{equation}\r\n%\r\nand $r_m(s,t)$ and $i_m(s,t)$ are calculated using the recursive\r\nrelationships\r\n%\r\n\\begin{equation}\r\n    \\begin{split}\r\n        r_0 = 1, \\hspace{.2 in} r_1 = s, \\hspace{.2 in} i_0 = 0,\r\n        \\hspace{.2 in} i_1 = t \\nonumber\\\\\r\n        %\r\n        r_m = sr_{m-1} - ti_{m-1}, \\hspace{ .2 in} i_m = si_{m-1} +\r\n        tr_{m-1} \\nonumber\r\n    \\end{split}\r\n\\end{equation}\r\n\r\n\r\nThe coefficients $A_{nm}(u)$ are called ``derived\" Legendre\r\nfunctions and are given by\r\n%\r\n\\begin{equation}\r\n    A_{nm}(u) = \\frac{d^m}{du^m}(P_n(u))\r\n\\end{equation}\r\n%\r\nwhere we know from Rodrigues' \\cite{Lundberg:88} formula that\r\n%\r\n\\begin{equation}\r\n    P_{n0}(u) = P_n(u) = \\frac{1}{2^n n!}\\frac{d^n}{du^n}(u^2 - 1)^n\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation}\r\n    P_{nm}(u) = (1 - u^2)^{m/2}\\frac{d^m}{du^m}P_n(u)\r\n\\end{equation}\r\n%\r\n\r\nFor numerical reasons it is useful to normalize some of the terms in\r\nthe potential function, $U$.  By normalizing the spherical\r\ncoefficients and the derived Legendre polynomials we can improve the\r\nstability of recursive algorithms used to calculate the Legendre\r\npolynomials and improved numerical problems.  We use the\r\nnondimensionalization approach and described by\r\nLundberg\\cite{Lundberg:88}.  Lundberg chooses the normalization\r\nfactor so that the normalized spherical harmonics $\\bar{C}_{nm}$ and\r\n$\\bar{S}_{nm}$ will have a mean square value of one on the unit\r\nsphere.  The normalized Legendre functions, $\\bar{P}_{nm}$, are\r\ndefined so that the product of the spherical harmonic coefficients\r\nand the corresponding Legendre functions remain constant, or\r\n%\r\n\\begin{equation}\r\n   \\bar{P}_{nm}\\bar{C}_{nm} = P_{nm}C_{nm}  \\hspace{.5 in}  \\bar{P}_{nm}\\bar{S}_{nm} = P_{nm}S_{nm}\r\n\\end{equation}\r\n%\r\nGMAT uses the normalization factor $N_{nm}$ given by\r\n%\r\n\\begin{equation}\r\n    N_{nm} =  \\left[ \\frac{(n-m)!(2n+1)!}{(n+m)!} \\right]^{1/2}\r\n\\end{equation}\r\n%\r\nThe non-dimensional spherical harmonic coefficients and Legendre\r\nfunctions are\r\n%\r\n\\begin{equation}\r\n     \\bar{P}_{nm} = N_{nm}P_{nm} \\hspace{.25 in} \\bar{C}_{nm} =\r\n     \\frac{C_{nm}}{N_{nm}} \\hspace{.25 in} \\bar{S}_{nm} =\r\n     \\frac{S_{nm}}{N_{nm}}\r\n\\end{equation}\r\n%\r\nThe derived Legendre polynomials are normalized using\r\n%\r\n\\begin{equation}\r\n    \\bar{A}_{nm} = N_{nm} A_{nm} \\label{Eq:LegendreNormalization}\r\n\\end{equation}\r\n%\r\nwhere $\\bar{A}_{nm}$ are the normalized Legendre polynomials.\r\nLundberg\\cite{Lundberg:88} showed that there are several recursive\r\nalgorithms to compute $\\bar{A}_{nm}$  but that only two are stable.\r\nGMAT uses the following algorithm to recursively calculate the\r\nderived Legendre polynomicals\r\n%\r\n\\begin{equation}\r\n     \\begin{split}\r\n     \\bar{A}_{nm} = & u\\left[ \\frac{(2n+1)(2n-1)}{(n-m)(n+m)}\r\n     \\right]^{1/2}\\bar{A}_{n-1,m}  \\\\\r\n     %\r\n     & - \\left[ \\frac{(2n+1)(n-m-1)(n+m-1)}{(2n-3)(n+m)(n-m)}\r\n     \\right]^{1/2}\\bar{A}_{n-2,m}\r\n     \\end{split}\r\n\\end{equation}\r\n%\r\nThe recursive algorithm is started using\r\n%\r\n\\begin{eqnarray}\r\n     \\bar{A}_{11} & = & \\sqrt{3} \\cos{\\phi}\\\\\r\n     \\bar{A}_{nn} & = & \\cos{\\phi}\\sqrt{\\frac{2n+1}{2n}}\\bar{A}_{n-1,n-1}\r\n\\end{eqnarray}\r\n%\r\nThe above equations are normalized using\r\nEq.~(\\ref{Eq:LegendreNormalization}) and used in\r\n\r\n\r\nThe acceleration due to nonspherical gravity can be written as\r\n%\r\n\\begin{equation}\r\n   \\begin{split}\r\n   \\mathbf{a}_g = & \\left( \\frac{\\partial U}{\\partial r} - \\frac{s}{r}\\frac{\\partial U}{\\partial s}\r\n    -\\frac{t}{r}\\frac{\\partial U}{\\partial t} -\\frac{u}{r}\\frac{\\partial U}{\\partial u}\r\n    \\right) \\hat{\\mathbf{r}}\\\\\r\n    %\r\n    & + \\left( \\frac{1}{r}\\frac{\\partial U}{\\partial s} \\hspace{.1\r\n    in} \\frac{1}{r}\\frac{\\partial U}{\\partial t}  \\hspace{.1\r\n    in} \\frac{1}{r}\\frac{\\partial U}{\\partial u}\\right)^T\r\n    \\end{split} \\label{Eq:NonSphericalAcc}\r\n\\end{equation}\r\n%\r\n\r\n\r\nTo simplify the partial derivatives in\r\nEq.~(\\ref{Eq:NonSphericalAcc}), Pines defines some intermediate\r\nvariables as follows\r\n%\r\n\\begin{eqnarray}\r\n     \\rho   & = & a/r \\\\\r\n     \\rho_0 & = & \\mu/r \\nonumber \\\\\r\n     \\rho_1 & = & \\rho \\rho_0 \\\\\r\n     \\rho_n & = & \\rho \\rho_{n-1} \\hspace{.2 in} \\mbox{for $n>1$}\\nonumber\r\n\\end{eqnarray}\r\n%\r\nUsing Lundberg's nondimensionalization approach, we can write\r\n%\r\n\\begin{eqnarray}\r\n     \\bar{D}_{nm}(s,t) & = & \\bar{C}_{nm}r_m(s,t) + \\bar{S}_{nm}i_m(s,t) \\nonumber\\\\\r\n     \\bar{E}_{nm}(s,t) & = & \\bar{C}_{nm}r_{m-1}(s,t) + \\bar{S}_{nm}i_{m-1}(s,t) \\nonumber\\\\\r\n     \\bar{F}_{nm}(s,t) & = & \\bar{S}_{nm}r_{m-1}(s,t) - \\bar{C}_{nm}i_{m-1}(s,t) \\nonumber\\\\\r\n     \\bar{G}_{nm}(s,t) & = & \\bar{C}_{nm}r_{m-2}(s,t) + \\bar{S}_{nm}i_{m-2}(s,t) \\nonumber\\\\\r\n     \\bar{H}_{nm}(s,t) & = & \\bar{S}_{nm}r_{m-2}(s,t) - \\bar{C}_{nm}i_{m-2}(s,t) \\nonumber\\\\\r\n\\end{eqnarray}\r\n%\r\nThe partial derivatives in Eq.~(\\ref{Eq:NonSphericalAcc}) can be\r\nwritten as\r\n%\r\n\\begin{equation}\r\n    \\begin{split}\r\n   &\\frac{\\partial U}{\\partial r} - \\frac{s}{r}\\frac{\\partial U}{\\partial s}\r\n    -\\frac{t}{r}\\frac{\\partial U}{\\partial t} -\\frac{u}{r}\\frac{\\partial U}{\\partial u}\r\n     =\\\\\r\n     -\\sum_{n=0}^{\\infty}&\\frac{\\rho_{n+1}}{R_\\otimes}\\sum_{m=0}^{n}c_{n+1,m+1}\\bar{A}_{n+1,m+1}\\bar{D}_{nm}\r\n    \\end{split} \\label{Eq:a4}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\frac{1}{r}\\frac{\\partial U}{\\partial s} =\r\n    \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+1}}{R_\\otimes}\\sum_{m=0}^{n}\\bar{A}_{nm}(u) m \\bar{E}_{nm}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\frac{1}{r}\\frac{\\partial U}{\\partial t} =\r\n    \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+1}}{R_\\otimes}\\sum_{m=0}^{n}\\bar{A}_{nm}(u) m \\bar{F}_{nm}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\frac{1}{r}\\frac{\\partial U}{\\partial s} =\r\n    \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+1}}{R_\\otimes}\\sum_{m=0}^{n}c_{n,m+1}\\bar{A}_{n,m+1}(u)\\bar{D}_{nm}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{eqnarray}\r\n    c_{n,m+1}   & = & \\left[(n-m)(n+m+1) \\right]^{1/2}  \\nonumber\\\\\r\n    c_{n+1,m+1} & = & \\left[\\frac{( n + m + 2) (n + m + 1 )}{(2n+3)(2n+2)}\r\n    \\right]^{1/2}  \\nonumber\r\n\\end{eqnarray}\r\n\r\n\r\nTo calculate the nonzero portion of the sensitivity matrix, we begin\r\nby calcluting the following 9 terms:\r\n%\r\n\\begin{eqnarray}\r\n    a_{11} & = & \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}m(m-1)\\bar{A}_{nm}\\bar{G}_{nm}\\\\\r\n    %\r\n    a_{12} & = & \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}m(m-1)\\bar{A}_{nm}\\bar{H}_{nm}\\\\\r\n    %\r\n    a_{13} & = & \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}mc_{n,m+1}\\bar{A}_{n,m+1}\\bar{E}_{nm}\\\\\r\n    %\r\n    a_{14} & = & -\\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}mc_{n+1,m+1}\\bar{A}_{n+1,m+1}\\bar{E}_{nm}\\\\\r\n    %\r\n    a_{23} & = & \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}mc_{n,m+1}\\bar{A}_{n,m+1}\\bar{F}_{nm}\\\\\r\n    %\r\n    a_{24} & = & -\\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}mc_{n+1,m+1}\\bar{A}_{n+1,m+1}\\bar{F}_{nm}\\\\\r\n    %\r\n    a_{33} & = & \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}c_{n,m+2}\\bar{A}_{n,m+2}\\bar{D}_{nm}\\\\\r\n    %\r\n    a_{34} & = & -\\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}c_{n+1,m+2}\\bar{A}_{n+1,m+2}\\bar{D}_{nm}\\\\\r\n    %\r\n    a_{44} & = &\r\n    \\sum_{n=0}^{\\infty}\\frac{\\rho_{n+2}}{R_\\otimes^2}\\sum_{m=0}^{n}c_{n+2,m+2}\\bar{A}_{n+2,m+2}\\bar{D}_{nm}\r\n\\end{eqnarray}\r\n%\r\nwhere\r\n%\r\n\\begin{eqnarray}\r\n    c_{n+1,m+2} &=& c_{n+1,m+1}  \\left[(n-m)( n + m + 3)\r\n    \\right]^{1/2} \\nonumber\\\\\r\n    %\r\n    c_{n,m+2} &=& c_{n,m+1} \\left[( n - m - 1)(n + m +2 )\r\n    \\right]^{1/2} \\nonumber\\\\\r\n    %\r\n    c_{n+2,m+2} &=&\r\n    c_{n+1,m+1}\\left[\\frac{(n+m+4)(n+m+3)}{(2n+5)(2n+4)}\\right]^{1/2} \\nonumber\r\n\\end{eqnarray}\r\n\r\nFinally,\r\n%\r\n\\begin{equation}\r\n   \\mathbf{C}_g = \\frac{\\partial \\mathbf{a}_g}{\\partial \\mathbf{r}}\r\n\\end{equation}\r\n%\r\nwhere $\\mathbf{C}_g$ is a symmetric matrix with components given by\r\n%\r\n\\begin{eqnarray}\r\n   c_{11} & = & a_{11} + s^2a_{44} + a_4/r + 2sa_{14} \\\\\r\n%\r\n   c_{12} & = & c_{21} = a_{12}+ sta_{44} + sa_{24} + ta_{14}\\\\\r\n%\r\n   c_{13} & = & c_{31} = a_{13}+ sua_{44} + sa_{34} + ua_{14}\\\\\r\n%\r\n   c_{22} & = & -a_{11} +t^2a_{44} + a_4/r +2ta_{24}\\\\\r\n%\r\n   c_{23} & = & c_{32} = a_{23} + tua_{44} + ua_{24} + ta_{34}\\\\\r\n%\r\n   c_{33} & = & a_{33} + u^2a_{44} + a_4/r + 2*u*a_{34}\r\n\\end{eqnarray}\r\n%\r\nNote that\r\n%\r\n\\begin{equation}\r\n    a_4 = \\frac{\\partial U}{\\partial r} - \\frac{s}{r}\\frac{\\partial U}{\\partial s}\r\n    -\\frac{t}{r}\\frac{\\partial U}{\\partial t} -\\frac{u}{r}\\frac{\\partial U}{\\partial u}\r\n\\end{equation}\r\n%\r\nand is given in Eq.~(\\ref{Eq:a4}).\r\n\r\n\r\n\r\n\\subsection{Atmospheric Drag}\r\n\r\nThe acceleration due to drag is given by\r\n%\r\n\\begin{equation}\r\n  \\mathbf{a}_d = - \\displaystyle\\frac{1}{2}\\rho v_{rel}^2 \\displaystyle\\frac{C_d\r\n   A}{m_s}\\hat{\\mathbf{v}}_{rel}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n    \\mathbf{v}_{rel} = \\mathbf{v} - \\boldsymbol{\\omega}_\\otimes \\times\r\n    \\mathbf{r} + \\mathbf{v}_w\r\n\\end{equation}\r\n%\r\nand $\\boldsymbol{\\omega}_\\otimes$ is the central bodies angular velocity vector, $\\mathbf{v}_w$ is the local wind velocity, $C_d$ is the drag coefficient,\r\n$A$ is the cross sectional area normal to $\\mathbf{v}_{rel}$, $\\rho$ is the atmospheric\r\ndensity, and $m_s$ is the\r\nspacecraft mass.\r\n\r\nThe partial derivatives of the drag force with respect to position and velocity are:\r\n%\r\n\\begin{equation}\r\n   \\frac{\\partial \\mathbf{a}_d }{\\partial \\mathbf{r}} = -\\frac{1}{2}\\frac{C_d A}{m_s}\\left( v_{rel}\\mathbf{v}_{rel}\\frac{\\partial \\rho}{\\partial \\mathbf{r}} + \\rho \\mathbf{v}_{rel}\\hat{\\mathbf{v}}_{rel}^T \\left(\\frac{\\partial \\mathbf{v}_{w}}{\\partial \\mathbf{r}}  - \\boldsymbol{\\omega}_B^{x}\\right) +\r\n   \\rho v_{rel} \\left( \\frac{ \\partial \\mathbf{v}_w}{\\partial \\mathbf{r}} - \\boldsymbol{\\omega}_B^{x} \\right)\\right)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\frac{\\partial \\mathbf{a}_d }{\\partial \\mathbf{v}} = -\\frac{1}{2}\\frac{\\rho C_d A}{m_s}\\left(  \\mathbf{v}_{rel}\\hat{\\mathbf{v}}_{rel}^T + v_{rel}\\mathbf{I}_3\\right)\r\n\\end{equation}\r\n%\r\n%where\r\n%\r\n%\\begin{equation}\r\n%    \\frac{\\partial \\mathbf{v}_{rel} }{\\partial \\mathbf{r}} = \\frac{\\partial \\mathbf{v}_w}{\\partial \\mathbf{r}} - %\\boldsymbol{\\omega}_B^{I_x}\r\n%\\end{equation}\r\n\r\n%\\begin{equation}\r\n%    \\frac{\\partial \\mathbf{v}_{rel} }{\\partial \\mathbf{v}} = \\mathbf{I}_3\r\n%\\end{equation}\r\n\r\n\\subsection{Solar Radiation Pressure}\r\n\r\n\\begin{equation}\r\n     \\mathbf{a}_s = -P_{SR}\\displaystyle\\frac{   C_R A    }{m_s}\\hat{\\mathbf{s}}\r\n\\end{equation}\r\n%\r\nwhere $\\hat{\\mathbf{s}}$ is a unitized vector pointing from the\r\nspacecraft to the sun\r\n%\r\n\\begin{equation}\r\n    \\mathbf{s} = \\mathbf{r}_s - \\mathbf{r}\r\n\\end{equation}\r\n%\r\nwhere $\\mathbf{r}_s$ is the Sun's position vector and $\\mathbf{r}$\r\nis the spacecrafts position vector.\r\n\r\n\r\n\r\n\\begin{equation}\r\n    \\mathbf{A}_{s} = \\mathbf{D}_{s}  = \\mathbf{0}_{3\\times3}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\mathbf{B}_{s} = \\mathbf{I}_{3\\times3}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\mathbf{C}_{s} = P_{SR}\\displaystyle\\frac{   C_R A\r\n    }{m_s}\\left( \\frac{1}{s^3}\\mathbf{I}_3 - 3 \\frac{ \\mathbf{s}\\mathbf{s}^T}{s^5}\\right)\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n    s = \\| \\mathbf{s} \\|\r\n\\end{equation}\r\n\r\n\\subsection{Relativistic Corrections}\r\n\r\nThe form of the relativitic correction to the Newtonian equations of motion depends upon the coordinate system in which they are expressed.  The treatment in GMAT follows Huang\\cite{Huang:90} \\emph{et. al.}. For celestial-body-centered motion (not sun or solarsystem barycenter) expressed in the local J2000 axis system, the relativistic correction takes the following form:\r\n%\r\n\\begin{equation}\r\n    \\mathbf{a}_r = \\frac{\\mu}{c^2 r^3}\\left(  \\left( 4\\frac{\\mu}{r} - v^2\\right)\\mathbf{r} +   4(\\mathbf{r}\\cdot\\mathbf{v})\\mathbf{v}\\right) + 2 (\\boldsymbol{\\Omega} \\times \\mathbf{v}) + 2 \\frac{\\mu}{c^2 r^3}\r\n    \\left( \\frac{3}{r^2}(\\mathbf{r} \\times \\mathbf{v})(\\mathbf{r} \\cdot \\mathbf{J}) +(\\mathbf{v}\\times\\mathbf{J}) \\right)\r\n    \\label{Eq:RelativisticCorrection}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n   \\boldsymbol{\\Omega} = \\frac{3}{2} \\mathbf{v}_{B/S} \\times \\left( \\frac{-\\mu \\mathbf{r}_{B/S}}{c^2r_{B/S}^3} \\right)\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{itemize}\r\n   \\item  $\\mu$ is the gravitational parameter of the central body expressed in the local celestial body J2000 frame\r\n   \\item  $c$ is the speed of light\r\n   \\item  $\\mathbf{J}$ is the central body's angular momentum per unit mass.\r\n   \\item  $\\mathbf{r}$ is the vehicle's position in the local J000 system.\r\n   \\item  $\\mathbf{v}$ is the vehicle's velocity in the local J000 system.\r\n   \\item  $\\mathbf{r}_{B/S}$ is the central body's position with respect to the Sun.\r\n   \\item  $\\mathbf{v}_{B/S}$ is the central body's velocity with respect to the Sun.\r\n\\end{itemize}\r\n%\r\nThe first term in Eq.~\\ref{Eq:RelativisticCorrection} is the Schwarzschild solution, the second term is geodesic precesion, and the third term is Lense-Thirring precession.  The vector $J$ is computed using\r\n%\r\n\\begin{equation}\r\n    \\mathbf{J} = \\mathbf{R}_B^{I/F}\\left[ 0   \\hspace{0.15 in} 0  \\hspace{0.15 in}   \\frac{2}{5}R_B^2 \\omega_B \\right]^T\r\n\\end{equation}\r\n%\r\nwhere $R_B$ is the central body's mean equatorial radius,$\\omega_B$ is the spin rate, and $\\mathbf{R}_B^{I/F}$ is the\r\nbody's fixed to inertial rotation matrix.\r\n\r\nEq.~{\\ref{Eq:RelativisticCorrection}} is used for all bodies except the sun.  In the case that the sun is the central body, the geodesic precesion term is omitted from the correction.\r\n\r\n\r\n\r\n\\subsection{Spacecraft Thrust}\r\n\r\n\\begin{footnotesize}\r\n\r\n\\begin{equation}\r\n\\begin{split}\r\n    F_T(T,P) = C_1 + C_2 P +  (C_3 + C_4 P + C_5 P^2 + C_6 P^{C_7}\\\\ +  C_8P^{C_9}\r\n     + C_{10}P^{C_{11}}\r\n    + C_{12}(C_{13})^{C_{14}P})\\left(\\frac{T}{T_{ref}}\\right)^{1 + C_{15} + C_{16}P }\r\n    \\label{Eq:ThrustPolynomial}\r\n     \\end{split}\r\n\\end{equation}\r\n\r\n%\r\n\\begin{equation}\r\n\\begin{split}\r\n    I_{sp}(T,P) = K_1 + K_2 P + (K_3 + K_4 P + K_5 P^2 + K_6 P^{K_7} \\\\ + K_8P^{K_9} + K_{10}P^{K_{11}}\r\n    + K_{12}(K_{13})^{K_{14}P})\\left(\\frac{T}{T_{ref}}\\right)^{1 + K_{15} + K_{16}P }\r\n         \\end{split}\r\n\\end{equation}\r\n\\end{footnotesize}\r\n\r\n\\begin{equation}\r\n    \\dot{m} =  f_d\\frac{F_T(T,P)}{I_{sp}(T,P)g}\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n    \\mathbf{T} = f_s f_d F_T(T,P) \\mathbf{R}_{iT}\\hat{\\mathbf{T}}_d\r\n\\end{equation}\r\n%\r\nwhere $F_T(T,P)$ is given in equation \\ref{Eq:ThrustPolynomial},\r\n$f_s$ and $f_d$ are the thrust scale factor and duty cycle\r\nrespectively, $\\mathbf{R}_{iT}$ is the rotation matrix from the\r\nthruster coordinate system to the EarthMJ2000 equatorial system, and\r\n$\\hat{\\mathbf{T}_d}$ is the unitized thrust direction in the\r\nthruster coordinate system.\r\n\r\n\\begin{table}[h!]\r\n\\centering \\caption{ Thrust and Isp Coefficient Units }\r\n      \\begin{tabular}{llll}\r\n      \\hline\\hline\r\n         Coeff. & Unit \\\\\r\n         \\hline\r\n         %---New Row---%\r\n         $C_1$ & N & $K_1$ & s \\\\\r\n         %---New Row---%\r\n         $C_2$ & N/kPa & $K_2$ & s/kPa\\\\\r\n         %---New Row---%\r\n         $C_3$ & N  & $K_3$ & s  \\\\\r\n         %---New Row---%\r\n         $C_4$ & N/kPa & $K_4$ & s/kPa \\\\\r\n         %---New Row---%\r\n         $C_5$ & N/kPa$^2$ & $K_5$ & s/kPa$^2$ \\\\\r\n         %---New Row---%\r\n         $C_6$ & N/kPa$^{C_7}$ & $K_6$ & s/kPa$^{C_7}$ \\\\\r\n         %---New Row---%\r\n         $C_7$ & None & $K_7$ & None  \\\\\r\n         %---New Row---%\r\n         $C_8$ & N/kPa$^{C_9}$ & $K_8$ & s/kPa$^{C_9}$ \\\\\r\n         %---New Row---%\r\n         $C_9$ & None & $K_9$ & None \\\\\r\n         %---New Row---%\r\n         $C_{10}$ & N/kPa$^{C_{11}}$  & $K_{10}$ & s/kPa$^{C_{11}}$  \\\\\r\n         %---New Row---%\r\n         $C_{11}$ & None & $K_{11}$ & None \\\\\r\n         %---New Row---%\r\n         $C_{12}$ & N & $K_{12}$ & s\\\\\r\n         %---New Row---%\r\n         $C_{13}$ & None & $K_{13}$ & None \\\\\r\n         %---New Row---%\r\n         $C_{14}$ & 1/kPa  & $K_{14}$ & 1/kPa  \\\\\r\n         %---New Row---%\r\n         $C_{15}$ & None & $K_{15}$ & None \\\\\r\n         %---New Row---%\r\n         $C_{16}$ & 1/kPa & $K_{16}$ & 1/kPa  \\\\\r\n      \\hline\\hline\r\n      \\label{Table:OE_RigorouslyJ2Inv}\r\n\\end{tabular} \\normalsize\r\n\\end{table}\r\n\r\n\\textbf{VNB Thruster System}\r\n\r\nIt is possible to specify thrust with respect to rotating\r\ncoordinates systems.  Then, during integration of the equations of\r\nmotion, GMAT uses the coordinate system definition to determine the\r\nthrust in the inertial system being used for numerical integration\r\nof the equations of motion.    One of the coordinate systems useful\r\nin mission analysis is the Velocity-Normal-Binormal (VNB) system\r\nbased on the motion of a spacecraft with respect to a reference\r\norigin. One way to configure a thruster to use a local VNB system is\r\nto set \\st{CoordinateSystem} to local.  Internally, GMAT creates a\r\ncoordinate system based on the \\st{Axes} and \\st{Origin} specified\r\nchosen for the thruster. We illustrate this below by example. The\r\nthruster named \\st{Thruster1} is configured to use a local VNB\r\ncoordinate system based on the motion of the owner-spacecraft and\r\nthe Earth.\r\n\r\n\\noindent\\st{Create Thruster Thruster1}\\\\\r\n\\st{Thruster1.CoordinateSystem = Local;}\\\\\r\n\\st{Thruster1.Origin = Earth;}\\\\\r\n\\st{Thruster1.Axes   = VNB;}\\\\\r\n\r\nTo convert the thrust from the requested local VNB system to the\r\ninertial system, GMAT creates a coordinate system configured as\r\nshown below. The \\st{Origin} field on the thruster is used in two\r\nplaces on the coordinate system: as both the \\st{Origin} and the\r\n\\st{Primary}. The axes are set to ObjectReferenced, and the $x$-axis\r\nand $y$-axis are respectively set to ``V'' and ``N''.\r\n\r\n\\noindent\\st{ Create CoordinateSystem SATVNB;}\\\\\r\n\\st{ GMAT SATVNB.Origin = DefaultSC; }\\\\\r\n\\st{ GMAT SATVNB.Axes = ObjectReferenced;}\\\\\r\n\\st{ GMAT SATVNB.Primary = Earth;}\\\\\r\n\\st{ GMAT SATVNB.Secondary = DefaultSC;}\\\\\r\n\\st{ GMAT SATVNB.XAxis = V; }\\\\\r\n\\st{ GMAT SATVNB.YAxis = N; }\\\\\r\n\r\nUsing this system, the $x$-axis is in the velocity direction, the\r\n$n$-axis is in the velocity direction, and the $z$-axis completes\r\nthe right-handed set. Note, the secondary body is not set until the\r\nthruster is assigned to a spacecraft, and then, the secondary is set\r\nto be the owner- spacecraft.  The script snippet above shows the\r\nconfiguration after the thruster has been attached to spacecraft\r\n``DefaultSC'', using, for example, the script line\r\n%\r\n\\st{DefaultSC.Thrusters = \\{Thruster1\\}};\r\n\r\n\\noindent \\textbf{LVLH Thruster System}\\\\\r\n\r\nThe LVLH system, similarly to the VNB system, is a local system that\r\nis constructed based on the motion of the owner spacecraft with\r\nrespect to an origin and axes system chosen by the user.  As an\r\nexample, below the thruster named \\st{Thruster1} is configured to\r\nuse a local LVLH coordinate system based on the motion of the owner\r\nspacecraft ``MySat'' and the moon.\r\n\r\n\\noindent\\st{Create Thruster Thruster1}\\\\\r\n\\st{Thruster1.CoordinateSystem = Local;}\\\\\r\n\\st{Thruster1.Origin = Luna;}\\\\\r\n\\st{Thruster1.Axes   = LVLH;}\\\\\r\n\r\nInternally, GMAT creates a coordinate system configured as shown\r\nbelow.  The \\st{Origin} field on the thruster is used in two places\r\non the coordinate system, as both the \\st{Origin} and the\r\n\\st{Primary}.  The axes are set to  \\st{ObjectReferenced}.\r\n\r\n\\noindent\\st{ Create CoordinateSystem SATLVLH;}\\\\\r\n\\st{ GMAT SATLVLH.Origin = MySat; }\\\\\r\n\\st{ GMAT SATLVLH.Axes = ObjectReferenced;}\\\\\r\n\\st{ GMAT SATLVLH.Primary = Luna;}\\\\\r\n\\st{ GMAT SATLVLH.Secondary = MySat;}\\\\\r\n\\st{ GMAT SATLVLH.XAxis = -R; }\\\\\r\n\\st{ GMAT SATLVLH.YAxis = -N; }\\\\\r\n\r\nUsing this system, the $y$-axis is opposite of orbit normal, the\r\n$z$-axis points towards the origin, and the $x$-axis completes the\r\nright-handed set.\r\n\r\n\r\n\\newpage\r\n\\input{AttitudeD5}\r\n\\input{SpacecraftModel}\r\n\\input{EnvironmentModels}\r\n\r\n\r\n%\\section{Appendix 1:  Derivation of the Orbital Equations of\r\n%Motion}\r\n%\r\n%\r\n%\r\n%\\section{Notation}\r\n%\r\n%\r\n%%\\begin{tabbing}\r\n%%12345678 \\= Reynolds number based on length $s$ \\kill\r\n%%$\\mathbf{r}$        \\> Position vector \\\\\r\n%%$\\mathbf{v}$        \\> Velocity vector \\\\\r\n%%$m$              \\> Number of spacecraft in formation \\\\\r\n%%$n_k$              \\> Number of maneuvers along $k^{th}$ trajectory \\\\\r\n%%$t$                 \\> Time \\\\\r\n%%$\\boldsymbol\\Phi$   \\> State transition matrix \\\\\r\n%%$\\mathbf{A}$   \\> Upper left 3x3 partition of $\\boldsymbol\\Phi$ \\\\\r\n%%$\\mathbf{B}$   \\> Upper right 3x3 partition of $\\boldsymbol\\Phi$ \\\\\r\n%%$\\mathbf{C}$   \\> Lower left 3x3 partition of $\\boldsymbol\\Phi$\\\\\r\n%%$\\mathbf{D}$   \\> Lower right 3x3 partition of $\\boldsymbol\\Phi$\r\n%%\\\\\r\n%%$\\Delta\\mathbf{v}_{jk}$   \\> $j^{th}$ impulsive maneuver on $k^{th}$ trajectory\\\\\r\n%%$\\Delta v_{jk}$   \\> Magnitude of $j^{th}$  maneuver on $k^{th}$ trajectory\\\\\r\n%%$\\mathcal{P}_{ok}$  \\>  Initial trajectory of $k^{th}$ spacecraft\\\\\r\n%%$\\mathcal{P}_{fk}$  \\>  Final trajectory of $k^{th}$ spacecraft\\\\\r\n%%$N$                  \\>  Number of Boundary Value Problems\\\\\r\n%%$\\mathbf{X}$     \\>  Vector of independent variables\\\\\r\n%%$\\mathbf{C}$     \\>  Vector of constants\\\\\r\n%%\\end{tabbing}\r\n%%\r\n%%\\subsection{Subscripts}\r\n%%\\begin{tabbing}\r\n%%12345678 \\= \\kill\r\n%%$i$   \\> Maneuver location index , ($2 \\leq i \\leq n_k-1$) \\\\\r\n%%$j$   \\> Maneuver epoch index, ($1 \\leq j \\leq n_k$) \\\\\r\n%%$k$   \\> Trajectory index , ($1 \\leq k \\leq m$) \\\\\r\n%%$o$   \\> Initial conditions \\\\\r\n%%$f$   \\> Final conditions \\\\\r\n%%$I$  \\>  Inertial Frame\r\n%%\\end{tabbing}\r\n%%\r\n%%\\subsection{Superscripts}\r\n%%\\begin{tabbing}\r\n%%12345678  \\= \\kill\r\n%%$r$       \\> Position solution \\\\\r\n%%$v$       \\> Velocity solution \\\\\r\n%%$+$       \\> Post-maneuver condition\\\\\r\n%%$-$       \\> Pre-maneuver condition\r\n%%\\end{tabbing}\r\n%\r\n%\\section{Spacecraft Equations of Motion}\r\n%\r\n%\r\n%%\r\n%\\begin{figure}[!]\r\n%\\centerline{\r\n%\\begin{picture}(100,500)\r\n%\\special{psfile= NBodyDiagram.eps hoffset= -135 voffset= -45\r\n%hscale=85 vscale=85} \\makebox(-20,585){$\\hat{\\mathbf{x}}_{I}$}\r\n%\\makebox(270,700){$\\hat{\\mathbf{y}}_{I}$}\r\n%\\makebox(-330,770){$\\mathbf{r}_{s}$}\r\n%\\makebox(-330,877){$\\mathbf{r}$}\r\n%\\makebox(-270,900){$\\mathbf{r}_k$}\r\n%\\makebox(-390,964){$\\mathbf{r}_{kj}$}\r\n%\\makebox(-500,814){$\\mathbf{r}_{j}$} \\makebox(-500,980){Central\r\n%Body} \\makebox(-320,995){$k^{th}$ Body}\r\n%\\end{picture}}\\vskip -4.0 in  \\caption{ N Body Illustration} \\label{fig:NBody}\r\n%\\end{figure}\r\n%\r\n%\\section{General Form}\r\n%\r\n%\r\n%\r\n%In general, the equations of motion can be written as\r\n%%\r\n%\\begin{equation}\r\n%  \\frac{d}{dt}\\left( m_s \\displaystyle\\frac{d \\mathbf{r}_s}{dt}\\right) = \\sum\r\n%  \\mathbf{F}_k\r\n%\\end{equation}\r\n%%\r\n%where $\\mathbf{r}_s$ is the spacecraft's position with respect to\r\n%an inertial frame, and $m_s$ is the spacecraft mass.  Expanding\r\n%the left hand side we get\r\n%%\r\n%\\begin{equation}\r\n%  \\dot{m}_s\\displaystyle\\frac{d \\mathbf{r}_s}{dt} + m_s \\frac{d^2\r\n%  \\mathbf{r}_s}{dt^2}= \\mathbf{F}_G + \\mathbf{F}_T + \\mathbf{F}_D\r\n%  + \\mathbf{F}_S + \\mathbf{F}_O\\label{Eq:EOMLHSExp}\r\n%\\end{equation}\r\n%%\r\n%where $\\mathbf{F}_g$ is the force due to gravity, $\\mathbf{F}_T$\r\n%is the force due to thrust, $\\mathbf{F}_D$ is the force due to\r\n%drag, $\\mathbf{F}_S$ is the force due to solar radiation pressure,\r\n%and $\\mathbf{F}_O$ are other forces. We usually want the equations\r\n%of motion of the spacecraft expressed with respect to a central\r\n%body. So, we note that\r\n%%\r\n%\\begin{equation}\r\n%     \\mathbf{r}_s = \\mathbf{r}_j + \\mathbf{r}\r\n%\\end{equation}\r\n%%\r\n%Taking the first and second time derivatives gives us\r\n%%\r\n%%\\begin{equation}\r\n%%     \\frac{d\\mathbf{r}_s}{dt} = \\frac{d\\mathbf{r}_j}{dt} +\r\n%%     \\frac{d\\mathbf{r}}{dt} \\label{Eq:InertDeriv1}\r\n%%\\end{equation}\r\n%%\r\n%\\begin{equation}\r\n%     \\frac{d^2\\mathbf{r}_s}{dt^2} = \\frac{d^2\\mathbf{r}_j}{dt^2} +\r\n%     \\frac{d^2\\mathbf{r}}{dt^2} \\label{Eq:InertDeriv2}\r\n%\\end{equation}\r\n%%\r\n%We can substitute Eq.~(\\ref{Eq:InertDeriv2}) into\r\n%Eq.~(\\ref{Eq:EOMLHSExp}) to get\r\n%%\r\n%\\begin{equation}\r\n%       \\dot{m}_s\\displaystyle\\frac{d \\mathbf{r}_s}{dt} + m_s \\left( \\frac{d^2\\mathbf{r}_j}{dt^2} +\r\n%     \\frac{d^2\\mathbf{r}}{dt^2}\\right)= \\mathbf{F}_G + \\mathbf{F}_T + \\mathbf{F}_D\r\n%  + \\mathbf{F}_S + \\mathbf{F}_O \\label{Eq:EOMAllExpanded}\r\n%\\end{equation}\r\n%%\r\n%The term that contains $\\dot{m}_s$ appears to be problematic.\r\n%However, if $\\dot{m}_s \\neq 0$, then we have a force due to\r\n%thrust, $\\mathbf{F}_T$, acting on the spacecraft.  In an inertial\r\n%frame, this thrust is written as\r\n%%\r\n%\\begin{equation}\r\n%     \\mathbf{F}_T = \\dot{m}_s \\left(\\frac{d \\mathbf{r}_s}{dt} +\r\n%     \\mathbf{v}_e\\right)\\label{Eq:InertialFt}\r\n%\\end{equation}\r\n%%\r\n%where $\\mathbf{v}_e$ is the velocity of the exhaust with respect\r\n%to the spacecraft.  Substituting Eq.~(\\ref{Eq:InertialFt}) into\r\n%Eq.~(\\ref{Eq:EOMAllExpanded}) we arrive at.\r\n%%\r\n%\\begin{equation}\r\n%          \\frac{d^2\\mathbf{r}}{dt^2} =\r\n%      \\underbrace{\\frac{\\mathbf{F}_G}{m_s}-\\frac{d^2\\mathbf{r}_j}{dt^2}}_{gravity terms} +\r\n%      \\frac{\\mathbf{F}_D}{m_s}\r\n%  + \\frac{\\mathbf{F}_S}{m_s} + \\frac{\\mathbf{F}_O}{m_s}  +\r\n%  \\frac{\\dot{m}_s}{m_s}\\mathbf{v}_e\\label{Eq:EOMGeneral}\r\n%\\end{equation}\r\n%\r\n%\\subsection{Gravitational Acceleration}\r\n%\r\n%\\begin{itemize}\r\n%     \\item  $\\mathbf{r}_{j}$ = Position vector of central body\r\n%     in inertial frame\r\n%     %\r\n%     \\item  $ m_s $ =  Spacecraft mass\r\n%     %\r\n%     \\item  $\\mathbf{r}_{s}$ =  Spacecraft position w/r/t inertial\r\n%     frame\r\n%     %\r\n%     \\item $\\mathbf{r}$ = Spacecraft position vector w/r/t central\r\n%     body\r\n%     %\r\n%     \\item $\\mathbf{r}_{kj}$ = Position vector from central body to  $k^{th}$ body\r\n%     %\r\n%     \\item $\\mathbf{r}_sk$ = Vector from the $k^{th}$ body to\r\n%     the spacecraft\r\n%     %\r\n%     \\item $\\mathbf{F}_k$ = Force of $k^{th}$ body on s/c\r\n%     %\r\n%     \\item $n_b$ = Number of secondary bodies\r\n%\\end{itemize}\r\n%\r\n%Let's take a look at the gravitational terms in\r\n%Eq.~(\\ref{Eq:EOMGeneral})\r\n%%\r\n%\\begin{equation}\r\n%          \\frac{d^2\\mathbf{r}}{dt^2}\r\n%          =\\frac{\\mathbf{F}_G}{m_s}-\\frac{d^2\\mathbf{r}_j}{dt^2}\\label{Eq:GravEOM}\r\n%\\end{equation}\r\n%%\r\n%$\\mathbf{F}_g$ is the force on the spacecraft due to gravity.  It\r\n%is useful to start by assuming that the Earth and spacecraft are\r\n%point masses.  Then we know from Newton's Law of Gravitation that\r\n%%\r\n%\\begin{equation}\r\n%     \\mathbf{F}_G = -\\frac{G m_s m_j}{r^3}\\mathbf{r}\r\n%\\end{equation}\r\n%%\r\n%and\r\n%%\r\n%\\begin{equation}\r\n%    \\frac{d^2\\mathbf{r}_j}{dt^2} = \\frac{G m_s }{r^3}\\mathbf{r}\r\n%\\end{equation}\r\n%%\r\n%Substituting these equations into Eq.~(\\ref{Eq:GravEOM}) yields\r\n%%\r\n%\\begin{equation}\r\n%   \\frac{d^2\\mathbf{r}}{dt^2} = -\\frac{G m_s }{r^3}\\mathbf{r} -\r\n%   \\frac{G m_j }{r^3}\\mathbf{r} = -\\frac{G \\left(m_s +m_j\r\n%     \\right)}{r^3}\\mathbf{r}\r\n%\\end{equation}\r\n%%\r\n%This is the well known two-body orbital equation of motion\r\n%%\r\n%\\begin{equation}\r\n%        \\frac{d^2\\mathbf{r}}{dt^2} = -\\frac{\\mu}{r^3}\\mathbf{r}\r\n%        \\label{Eq:TwoBodyEOM}\r\n%\\end{equation}\r\n%%\r\n%where $\\mu = G \\left(m_s +m_j \\right)$\r\n%\r\n%Now lets consider the case when there are other gravitational\r\n%bodies in the system and that all of the gravitational bodies are\r\n%non-spherical.  However, we'll assume the mass distribution of the\r\n%spacecraft is negligible.  In this case we can write the forces on\r\n%the spacecraft that are in addition to the central body force as\r\n%%\r\n%\\begin{equation}\r\n%   \\frac{ \\mathbf{F}_G}{m_s} = \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b} \\nabla \\left(\\phi_{sk}^s + \\phi_{sk}^o\r\n%    \\right)\r\n%\\end{equation}\r\n%%\r\n%where $\\nabla$ is the gradient operator, $\\phi$ a bodies\r\n%gravitational potential, a superscript ``$s$\" denotes the\r\n%spherical portion of gravitational potential, and a superscript\r\n%``$o$\" denotes the oblate portion the gravitational potential.\r\n%From physics we know that\r\n%%\r\n%\\begin{equation}\r\n%    \\frac{d^2 \\mathbf{r}}{dt^2} = \\nabla \\phi\r\n%\\end{equation}\r\n%%\r\n%where we choose to define the potential $\\phi$ according to\r\n%%\r\n%\\begin{equation}\r\n%     \\phi = \\frac{\\mu}{r}\r\n%\\end{equation}\r\n%%\r\n%Then, for the spherical terms, we know that\r\n%%\r\n%\\begin{equation}\r\n%    \\nabla \\phi_{sk}^s = -\\frac{G m_k }{r_{sk}^3}\\mathbf{r}_{sk} =\r\n%    \\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}\r\n%\\end{equation}\r\n%%\r\n%%\r\n%\\begin{equation}\r\n%    \\frac{\\mathbf{F}_G}{m_s} =  \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(\\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}   + \\nabla\r\n%    \\phi_{k}^o\\right)      \\label{Eq:FG}\r\n%\\end{equation}\r\n%\r\n%\r\n%We can apply Newton's laws to the central body to arrive at\r\n%%\r\n%\\begin{equation}\r\n%     \\frac{d^2\\mathbf{r}_j}{dt^2} = \\frac{1}{m_j}\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\nabla\\left(\r\n%     \\phi_{kj}^s + \\phi_{kj}^o\r\n%     \\right) = \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(-\r\n%     \\frac{G m_k}{r_{kj}^3}\\mathbf{r}_{kj} +\r\n%     \\frac{\\nabla\\phi_{kj}^o}{m_j}\r\n%     \\right) \\label{Eq:CBEOM}\r\n%\\end{equation}\r\n%%\r\n%Eqs.~(\\ref{Eq:FG}) and(\\ref{Eq:CBEOM}) represent the forces in\r\n%addition to the two-body point mass force in the equations of\r\n%motion.  Augmenting Eq.~(\\ref{Eq:TwoBodyEOM}) with\r\n%Eqs.~(\\ref{Eq:FG}) and(\\ref{Eq:CBEOM}) we arrive at\r\n%%\r\n%\\begin{equation}\\begin{split}\r\n%    \\frac{d^2\\mathbf{r}}{dt^2}\r\n%    = &-\\frac{\\mu}{r^3}\\mathbf{r} +\r\n%    %\r\n%    \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(\\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}   + \\nabla\r\n%    \\phi_{ks}^o\\right)\\\\\r\n%     &+\r\n%     %\r\n%    \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(-\r\n%     \\frac{G m_k}{r_{kj}^3}\\mathbf{r}_{kj} +\r\n%     \\nabla\\phi_{kj}^o\r\n%     \\right)\r\n%\\end{split}\\end{equation}\r\n%%\r\n%Grouping similar terms we arrive at\r\n%%\r\n%\\begin{equation}\\begin{split}\r\n%    \\frac{d^2\\mathbf{r}}{dt^2}\r\n%    =  &-\\frac{\\mu}{r^3}\\mathbf{r} +  \\nabla \\phi_{sj}^o +\r\n%    %\r\n%    G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}m_k \\left(\\frac{\\mathbf{r}_{ks}}{r_{ks}^3} -\r\n%     \\frac{\\mathbf{r}_{kj} }{r_{kj}^3}   \\right)\\\\\r\n%     %\r\n%   & + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left( \\nabla\r\n%    \\phi_{ks}^o +\r\n%     \\nabla\\phi_{kj}^o\r\n%     \\right)\r\n%\\end{split} \\end{equation}\r\n%\r\n%\r\n%%\\section{Spacecraft Equations of Motion}\r\n%%\r\n%%\r\n%%%\r\n%%\\begin{figure}[!]\r\n%%\\centerline{\r\n%%\\begin{picture}(100,500)\r\n%%\\special{psfile= NBodyDiagram.eps hoffset= -155 voffset= -45\r\n%%hscale=85 vscale=85} \\makebox(-20,585){$\\hat{\\mathbf{x}}_{I}$}\r\n%%\\makebox(270,700){$\\hat{\\mathbf{y}}_{I}$}\r\n%%\\makebox(-330,770){$\\mathbf{r}_{s}$}\r\n%%\\makebox(-330,877){$\\mathbf{r}$}\r\n%%\\makebox(-270,900){$\\mathbf{r}_k$}\r\n%%\\makebox(-390,964){$\\mathbf{r}_{kj}$}\r\n%%\\makebox(-500,814){$\\mathbf{r}_{j}$} \\makebox(-500,980){Central\r\n%%Body} \\makebox(-320,995){$k^{th}$ Body}\r\n%%\\end{picture}}\\vskip -4.0 in  \\caption{ N Body Illustration} \\label{fig:NBody}\r\n%%\\end{figure}\r\n%%\r\n%%\\section{General Form}\r\n%%\r\n%%\r\n%%\r\n%%In general, the equations of motion can be written as\r\n%%%\r\n%%\\begin{equation}\r\n%%  \\frac{d}{dt}\\left( m_s \\displaystyle\\frac{d \\mathbf{r}_s}{dt}\\right) = \\sum\r\n%%  \\mathbf{F}_k\r\n%%\\end{equation}\r\n%%%\r\n%%where $\\mathbf{r}_s$ is the spacecraft's position with respect to\r\n%%an inertial frame, and $m_s$ is the spacecraft mass.  Expanding\r\n%%the left hand side we get\r\n%%%\r\n%%\\begin{equation}\r\n%%  \\dot{m}_s\\displaystyle\\frac{d \\mathbf{r}_s}{dt} + m_s \\frac{d^2\r\n%%  \\mathbf{r}_s}{dt^2}= \\mathbf{F}_G + \\mathbf{F}_T + \\mathbf{F}_D\r\n%%  + \\mathbf{F}_S + \\mathbf{F}_O\\label{Eq:EOMLHSExp}\r\n%%\\end{equation}\r\n%%%\r\n%%where $\\mathbf{F}_g$ is the force due to gravity, $\\mathbf{F}_T$\r\n%%is the force due to thrust, $\\mathbf{F}_D$ is the force due to\r\n%%drag, $\\mathbf{F}_S$ is the force due to solar radiation pressure,\r\n%%and $\\mathbf{F}_O$ are other forces. We usually want the equations\r\n%%of motion of the spacecraft expressed with respect to a central\r\n%%body. So, we note that\r\n%%%\r\n%%\\begin{equation}\r\n%%     \\mathbf{r}_s = \\mathbf{r}_j + \\mathbf{r}\r\n%%\\end{equation}\r\n%%%\r\n%%Taking the first and second time derivatives gives us\r\n%%%\r\n%%%\\begin{equation}\r\n%%%     \\frac{d\\mathbf{r}_s}{dt} = \\frac{d\\mathbf{r}_j}{dt} +\r\n%%%     \\frac{d\\mathbf{r}}{dt} \\label{Eq:InertDeriv1}\r\n%%%\\end{equation}\r\n%%%\r\n%%\\begin{equation}\r\n%%     \\frac{d^2\\mathbf{r}_s}{dt^2} = \\frac{d^2\\mathbf{r}_j}{dt^2} +\r\n%%     \\frac{d^2\\mathbf{r}}{dt^2} \\label{Eq:InertDeriv2}\r\n%%\\end{equation}\r\n%%%\r\n%%We can substitute Eq.~(\\ref{Eq:InertDeriv2}) into\r\n%%Eq.~(\\ref{Eq:EOMLHSExp}) to get\r\n%%%\r\n%%\\begin{equation}\r\n%%       \\dot{m}_s\\displaystyle\\frac{d \\mathbf{r}_s}{dt} + m_s \\left( \\frac{d^2\\mathbf{r}_j}{dt^2} +\r\n%%     \\frac{d^2\\mathbf{r}}{dt^2}\\right)= \\mathbf{F}_G + \\mathbf{F}_T + \\mathbf{F}_D\r\n%%  + \\mathbf{F}_S + \\mathbf{F}_O \\label{Eq:EOMAllExpanded}\r\n%%\\end{equation}\r\n%%%\r\n%%The term that contains $\\dot{m}_s$ appears to be problematic.\r\n%%However, if $\\dot{m}_s \\neq 0$, then we have a force due to\r\n%%thrust, $\\mathbf{F}_T$, acting on the spacecraft.  In an inertial\r\n%%frame, this thrust is written as\r\n%%%\r\n%%\\begin{equation}\r\n%%     \\mathbf{F}_T = \\dot{m}_s \\left(\\frac{d \\mathbf{r}_s}{dt} +\r\n%%     \\mathbf{v}_e\\right)\\label{Eq:InertialFt}\r\n%%\\end{equation}\r\n%%%\r\n%%where $\\mathbf{v}_e$ is the velocity of the exhaust with respect\r\n%%to the spacecraft.  Substituting Eq.~(\\ref{Eq:InertialFt}) into\r\n%%Eq.~(\\ref{Eq:EOMAllExpanded}) we arrive at.\r\n%%%\r\n%%\\begin{equation}\r\n%%          \\frac{d^2\\mathbf{r}}{dt^2} =\r\n%%      \\underbrace{\\frac{\\mathbf{F}_G}{m_s}-\\frac{d^2\\mathbf{r}_j}{dt^2}}_{gravity terms} +\r\n%%      \\frac{\\mathbf{F}_D}{m_s}\r\n%%  + \\frac{\\mathbf{F}_S}{m_s} + \\frac{\\mathbf{F}_O}{m_s}  +\r\n%%  \\frac{\\dot{m}_s}{m_s}\\mathbf{v}_e\\label{Eq:EOMGeneral}\r\n%%\\end{equation}\r\n%%\r\n%%\\subsection{Gravitational Acceleration}\r\n%%\r\n%%\\begin{itemize}\r\n%%     \\item  $\\mathbf{r}_{j}$ = Position vector of central body\r\n%%     in inertial frame\r\n%%     %\r\n%%     \\item  $ m_s $ =  Spacecraft mass\r\n%%     %\r\n%%     \\item  $\\mathbf{r}_{s}$ =  Spacecraft position w/r/t inertial\r\n%%     frame\r\n%%     %\r\n%%     \\item $\\mathbf{r}$ = Spacecraft position vector w/r/t central\r\n%%     body\r\n%%     %\r\n%%     \\item $\\mathbf{r}_{kj}$ = Position vector from central body to  $k^{th}$ body\r\n%%     %\r\n%%     \\item $\\mathbf{r}_{sk}$ = Vector from the $k^{th}$ body to\r\n%%     the spacecraft\r\n%%     %\r\n%%     \\item $\\mathbf{F}_k$ = Force of $k^{th}$ body on s/c\r\n%%     %\r\n%%     \\item $n_b$ = Number of secondary bodies\r\n%%\\end{itemize}\r\n%%\r\n%%Let's take a look at the gravitational terms in\r\n%%Eq.~(\\ref{Eq:EOMGeneral})\r\n%%%\r\n%%\\begin{equation}\r\n%%          \\frac{d^2\\mathbf{r}}{dt^2}\r\n%%          =\\frac{\\mathbf{F}_G}{m_s}-\\frac{d^2\\mathbf{r}_j}{dt^2}\\label{Eq:GravEOM}\r\n%%\\end{equation}\r\n%%%\r\n%%$\\mathbf{F}_g$ is the force on the spacecraft due to gravity.  It\r\n%%is useful to start by assuming that the Earth and spacecraft are\r\n%%point masses.  Then we know from Newton's Law of Gravitation that\r\n%%%\r\n%%\\begin{equation}\r\n%%     \\mathbf{F}_G = -\\frac{G m_s m_j}{r^3}\\mathbf{r}\r\n%%\\end{equation}\r\n%%%\r\n%%and\r\n%%%\r\n%%\\begin{equation}\r\n%%    \\frac{d^2\\mathbf{r}_j}{dt^2} = \\frac{G m_s }{r^3}\\mathbf{r}\r\n%%\\end{equation}\r\n%%%\r\n%%Substituting these equations into Eq.~(\\ref{Eq:GravEOM}) yields\r\n%%%\r\n%%\\begin{equation}\r\n%%   \\frac{d^2\\mathbf{r}}{dt^2} = -\\frac{G m_s }{r^3}\\mathbf{r} -\r\n%%   \\frac{G m_j }{r^3}\\mathbf{r} = -\\frac{G \\left(m_s +m_j\r\n%%     \\right)}{r^3}\\mathbf{r}\r\n%%\\end{equation}\r\n%%%\r\n%%This is the well known two-body orbital equation of motion\r\n%%%\r\n%%\\begin{equation}\r\n%%        \\frac{d^2\\mathbf{r}}{dt^2} = -\\frac{\\mu}{r^3}\\mathbf{r}\r\n%%        \\label{Eq:TwoBodyEOM}\r\n%%\\end{equation}\r\n%%%\r\n%%where $\\mu = G \\left(m_s +m_j \\right)$\r\n%%\r\n%%Now lets consider the case when there are other gravitational\r\n%%bodies in the system and that all of the gravitational bodies are\r\n%%non-spherical.  However, we'll assume the mass distribution of the\r\n%%spacecraft is negligible.  In this case we can write the forces on\r\n%%the spacecraft that are in addition to the central body force as\r\n%%%\r\n%%\\begin{equation}\r\n%%   \\frac{ \\mathbf{F}_G}{m_s} = \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b} \\nabla \\left(\\phi_{sk}^s + \\phi_{sk}^o\r\n%%    \\right)\r\n%%\\end{equation}\r\n%%%\r\n%%where $\\nabla$ is the gradient operator, $\\phi$ a bodies\r\n%%gravitational potential, a superscript ``$s$\" denotes the\r\n%%spherical portion of gravitational potential, and a superscript\r\n%%``$o$\" denotes the oblate portion the gravitational potential.\r\n%%From physics we know that\r\n%%%\r\n%%\\begin{equation}\r\n%%    \\frac{d^2 \\mathbf{r}}{dt^2} = \\nabla \\phi\r\n%%\\end{equation}\r\n%%%\r\n%%where we choose to define the potential $\\phi$ according to\r\n%%%\r\n%%\\begin{equation}\r\n%%     \\phi = \\frac{\\mu}{r}\r\n%%\\end{equation}\r\n%%%\r\n%%Then, for the spherical terms, we know that\r\n%%%\r\n%%\\begin{equation}\r\n%%    \\nabla \\phi_{sk}^s = -\\frac{G m_k }{r_{sk}^3}\\mathbf{r}_{sk} =\r\n%%    \\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}\r\n%%\\end{equation}\r\n%%%\r\n%%%\r\n%%\\begin{equation}\r\n%%    \\frac{\\mathbf{F}_G}{m_s} =  \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(\\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}   + \\nabla\r\n%%    \\phi_{k}^o\\right)      \\label{Eq:FG}\r\n%%\\end{equation}\r\n%%\r\n%%\r\n%%We can apply Newton's laws to the central body to arrive at\r\n%%%\r\n%%\\begin{equation}\\begin{split}\r\n%%     \\frac{d^2\\mathbf{r}_j}{dt^2} = \\frac{1}{m_j}\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\nabla\\left(\r\n%%     \\phi_{kj}^s + \\phi_{kj}^o\r\n%%     \\right) = \\\\\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(-\r\n%%     \\frac{G m_k}{r_{kj}^3}\\mathbf{r}_{kj} +\r\n%%     \\frac{\\nabla\\phi_{kj}^o}{m_j}\r\n%%     \\right) \\label{Eq:CBEOM}\r\n%%     \\end{split}\r\n%%\\end{equation}\r\n%%%\r\n%%Eqs.~(\\ref{Eq:FG}) and(\\ref{Eq:CBEOM}) represent the forces in\r\n%%addition to the two-body point mass force in the equations of\r\n%%motion.  Augmenting Eq.~(\\ref{Eq:TwoBodyEOM}) with\r\n%%Eqs.~(\\ref{Eq:FG}) and(\\ref{Eq:CBEOM}) we arrive at\r\n%%%\r\n%%\\begin{equation}\\begin{split}\r\n%%    \\frac{d^2\\mathbf{r}}{dt^2}\r\n%%    = -\\frac{\\mu}{r^3}\\mathbf{r} +\r\n%%    %\r\n%%    \\nabla \\phi_{sj}^o + \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(\\frac{G m_k }{r_{ks}^3}\\mathbf{r}_{ks}   + \\nabla\r\n%%    \\phi_{ks}^o\\right) +\\\\\r\n%%     %\r\n%%    \\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left(-\r\n%%     \\frac{G m_k}{r_{kj}^3}\\mathbf{r}_{kj} +\r\n%%     \\nabla\\phi_{kj}^o\r\n%%     \\right)\\end{split}\r\n%%\\end{equation}\r\n%%%\r\n%%Grouping similar terms we arrive at\r\n%%%%\r\n%%%\\begin{equation}\\begin{split}\r\n%%%    \\frac{d^2\\mathbf{r}}{dt^2}\r\n%%%    =  -\\frac{\\mu}{r^3}\\mathbf{r} +  \\nabla \\phi_{sj}^o +\r\n%%%    %\r\n%%%    G\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}m_k \\left(\\frac{\\mathbf{r}_{ks}}{r_{ks}^3} -\r\n%%%     \\frac{\\mathbf{r}_{kj} }{r_{kj}^3}   \\right)\r\n%%%     %\r\n%%%   + \\\\\\sum_{\\stackrel{k=1}{k \\neq j}}^{n_b}\\left( \\nabla\r\n%%%    \\phi_{ks}^o +\r\n%%%     \\nabla\\phi_{kj}^o\r\n%%%     \\right)\\end{split}\r\n%%%\\end{equation}\r\n%%\r\n%%\r\n%%\r\n%% Let's\r\n%%return to equation Eq.~(\\ref{Eq:a_cb}). We need to calculate\r\n%%$\\mba_{cb}$ in cartesian coordinates.  However, we know the\r\n%%potential in spherical coordinates.  So, we need to use the chain\r\n%%rule to take the derivative and we see that\r\n%%%\r\n%%\\begin{equation}\\begin{split}\r\n%%   \\{\\mathbf{a}_{cb}\\}_F = \\nabla U(r,\\phi,\\lambda)  = \\frac{\\partial U(r,\\phi,\\lambda)}{\\partial \\mbr_F}\r\n%%   =\\\\\\frac{\\partial U}{\\partial r}\\frac{\\partial r}{\\partial \\mbr_F} +\r\n%%   \\frac{\\partial U}{\\partial \\phi}\\frac{\\partial \\phi}{\\partial\r\n%%   \\mbr_F}+ \\frac{\\partial U}{\\partial \\lambda}\\frac{\\partial \\lambda}{\\partial \\mbr_F}\r\n%%   \\label{Eq:a_cb2}\\end{split}\r\n%%\\end{equation}\r\n%%%\r\n%%The six partial derivatives in Eq.~(\\ref{Eq:a_cb2}) are given in the\r\n%%GTDS\\cite{GTDS} math spec as\r\n%%%\r\n%%\\begin{equation}\\begin{split}\r\n%%     \\frac{\\partial U}{\\partial r} = &-\\frac{\\mu}{r^2}\\sum_{\\ell =\r\n%%     2}^{\\infty}\\sum_{m=0}^{\\ell}\\left(\r\n%%     \\frac{R_{\\otimes}}{r}\\right)^\\ell(\\ell + 1)P_{\\ell m} \\left[sin{\\phi}  \\right]\\\\\r\n%%    %\r\n%%      &\\left( C_{\\ell m}\\cos{m \\lambda}+ S_{\\ell m}\\sin{m \\lambda}  \\right)\r\n%%\\end{split}\\end{equation}\r\n%%%\r\n%%\\begin{equation}\\begin{split}\r\n%%     \\frac{\\partial U}{\\partial \\phi} = &\\frac{\\mu}{r}\\sum_{\\ell =\r\n%%     2}^{\\infty}\\sum_{m=0}^{\\ell}\\left(\r\n%%     \\frac{R_{\\otimes}}{r}\\right)^\\ell\\left( P_{\\ell, m+1} \\left[sin{\\phi}  \\right] - m \\tan{\\phi}P_{\\ell m}\\left[\\sin{\\phi}\\right]\\right)\\\\ &\r\n%%    %\r\n%%      \\left( C_{\\ell m}\\cos{m \\lambda}+ S_{\\ell m}\\sin{m \\lambda}\r\n%%     \\right)\r\n%%\\end{split}\\end{equation}\r\n%%\\begin{equation}\\begin{split}\r\n%%     \\frac{\\partial U}{\\partial \\lambda} = & \\frac{\\mu}{r}\\sum_{\\ell =\r\n%%     2}^{\\infty}\\sum_{m=0}^{\\ell}\\left(\r\n%%     \\frac{R_{\\otimes}}{r}\\right)^\\ell m  P_{\\ell, m} \\left[sin{\\phi}  \\right]\r\n%%     \\\\\r\n%%     %\r\n%%     &  \\left( S_{\\ell m}\\cos{m \\lambda}+ C_{\\ell m}\\sin{m \\lambda}\r\n%%     \\right)\r\n%%\\end{split}\\end{equation}\r\n%%\r\n", "meta": {"hexsha": "14d71e9b97928c8eac2274ea094257e8301bb5f3", "size": 60166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/DynamicsModelling.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/DynamicsModelling.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/DynamicsModelling.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": 37.86406545, "max_line_length": 375, "alphanum_fraction": 0.615846159, "num_tokens": 22350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.6859494421679929, "lm_q1q2_score": 0.630828276723171}}
{"text": "% =============================================================================\n\n% -----------------------------------------------------------------------------\n\n\\paragraph{Syntax.}\n\nAs a block cipher, AES defines two algorithms\n\\[\n\\begin{array}{lcl}\n\\ALG{Enc} &:& \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nk} \\times \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nb} \\rightarrow \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nb} \\\\\n\\ALG{Dec} &:& \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nk} \\times \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nb} \\rightarrow \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nb} \\\\\n\\end{array}\n\\]\nsuch that\n$\nm = \\ALG{Dec}( k, c = \\ALG{Enc}( k, m ) ) .\n$\nThat is, given a plaintext $m$ and cipher key $k$, \\ALG{Enc} encrypts $m$ \nunder $k$; given the same $k$, \\ALG{Dec} will invert \\ALG{Enc} and so the\n{\\em same} $m$ can be recovered from the associated ciphertext $c$.  \nIn addition, it defines an algorithm\n\\ALG{KeyExp}\nthat expands~\\cite[Section 5.2]{FIPS:197} the cipher key into a sequence \nof round keys then used by\n\\ALG{Enc}\nor\n\\ALG{Dec};\nwhere appropriate, we use\n\\[\n\\begin{array}{lcl}\n\\ALG{Enc-KeyExp} &:& \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nk} \\rightarrow \\SET{ 0, 1 }^{( 8 \\cdot 4 \\cdot Nb ) \\times ( Nr + 1 )} \\\\\n\\ALG{Dec-KeyExp} &:& \\SET{ 0, 1 }^{8 \\cdot 4 \\cdot Nk} \\rightarrow \\SET{ 0, 1 }^{( 8 \\cdot 4 \\cdot Nb ) \\times ( Nr + 1 )} \\\\\n\\end{array}\n\\]\nto denote said algorithm as specialised to suit\n\\ALG{Enc}\nand\n\\ALG{Dec}\nrespectively.\n\n% -----------------------------------------------------------------------------\n\n\\paragraph{Parameterisation.}\n\nAn AES parameter set~\\cite[Figure 4]{FIPS:197}\nis a triple\n$\n\\TUPLE{ Nk, Nb, Nr }\n$\nwhere \n$Nk$ dictates the number of $32$-bit words in $k$,\n$Nb$ dictates the number of $32$-bit words in $m$ or $c$ (i.e., a block),\nand\n$Nr$ dictates the number of rounds.  The standard AES parameter sets are\n\\[\n\\begin{array}{lcl}\n\\mbox{AES-128} &\\mapsto& \\TUPLE{ 4, 4, 10 } \\\\\n\\mbox{AES-192} &\\mapsto& \\TUPLE{ 6, 4, 12 } \\\\\n\\mbox{AES-256} &\\mapsto& \\TUPLE{ 8, 4, 14 } \\\\\n\\end{array}\n\\]\nsuch that the number of bits in a plaintext (resp. ciphertext) block is fixed to \n$\n8 \\cdot 4 \\cdot Nb = 128 .\n$\nFrom here on, we focus wlog. on encryption using AES-128 (other parameter \nsets are catered for naturally, and decryption with minor differences) so\nuse the terms AES and AES-128 synonymously.\n\n% -----------------------------------------------------------------------------\n\n\\paragraph{Design.}\n\nThe mathematics underpinning AES are described in ~\\cite[Section 4]{FIPS:197}.\nIn particular, it can be defined in terms of \noperations in the finite field $\\F_{2^{  8}}$ constructed as\n$\n\\F_{2}[\\IND{x}] / ( \\IND{x}^{8} + \\IND{x}^{4} + \\IND{x}^{3} + \\IND{x} + 1 ) .\n$\nA hexadecimal short-hand~\\cite[Section 3.2]{FIPS:197} is used to represent \nfield literals, e.g.,\n$\n\\AESCONST{13} ~\\mapsto~ \\RADIX{13}{16} ~\\equiv~ \\RADIX{00010011}{2} ~\\mapsto~ \\IND{x}^4 + \\IND{x} + 1 .\n$\nField \n      addition, \nmultiplication, \nand  \n      division\nare denoted by\n$\\AESADD$,\n$\\AESMUL$,\nand\n$\\AESINV$\nrespectively,\nwith the multiplication-by-$\\IND{x}$ operation~\\cite[Section 4.2.1]{FIPS:197} \ndenoted \\AESFUNC{xtime}.\nElements of $\\F_{2^8}$ are collected into $( 4 \\times 4 )$-element state\nand round key matrices; the $i$-th row and $j$-th column of such a matrix \nrelating to round $r$ is denoted\n$\\AESRND {s}{r}_{i,j}$\nand\n$\\AESRND{rk}{r}_{i,j}$\nrespectively, with super- and/or subscripts omitted whenever irrelevant.\n\nAES is an iterative block cipher, based on a substitution-permutation network.\nThis means encryption using AES can be described~\\cite[Section 5.2]{FIPS:197}\nas follows:\n1)    the  input  plaintext is pre-whitened to yield\n      $\\AESRND {s}{  0} = m \\AESADD \\AESRND{rk}{0} = m \\AESADD k$,\n2)    each $r$-th round, for $1 \\leq r \\leq Nr$, demands computation of\n      $\\AESRND {s}{r+1} = \\ALG{P-layer}( \\ALG{S-layer}( \\AESRND{s}{r}                        ) ) \\AESADD \\AESRND{rk}{r}$,\n      and therefore use of round key\n      $\\AESRND{rk}{r  }$,\n3)    the output ciphertext is\n      $c = \\AESRND{s}{Nr}$.\nNote that an alternative round definition, namely\n      $\\AESRND {s}{r+1} = \\ALG{P-layer}( \\ALG{S-layer}( \\AESRND{s}{r} \\AESADD \\AESRND{rk}{r} ) )                       $ ,\nis plausible: this shifts the \n pre-whitening step {\\em before} 2) \ninto an analogous \npost-whitening step {\\em  after} 2)\nto yield an equivalent result.\nAt a  low(er) level,\nthe computation of each round is specified via four round functions (each of \nwhich has an inverse, to support decryption):\n\n\\begin{itemize}\n\n\\item \\AESFUNC{SubBytes}\n      ~\\cite[Section 5.1.1]{FIPS:197}\n      operates element-wise,\n      computing\n      $\\AESRND{s}{r+1}_{i,j} = \\ALG{S-box}( \\AESRND{s}{r}_{i,j} )$\n      via application of the S-box:\n      given an element $x$, this component can be described as\n      \\[\n      \\begin{array}{lcl}\n      \\ALG{S-Box} &:& \\left\\{\\begin{array}{ccc}\n                             \\F_{2^8} &\\rightarrow& \\F_{2^8} \\\\\n                             x        &\\mapsto    & f(g(x))  \\\\\n                             \\end{array}\n                      \\right.\n      \\end{array}\n      \\]\n      where \n      $g$ is an inversion, \n      and \n      $f$ is a specially selected affine transformation.\n      Where appropriate,\n      we overload \\AESFUNC{SubBytes} by allowing it to denote application \n      of the S-box to {\\em any} collection, \n      e.g., a row, column, or, more generally, a sequence, \n      of elements.\n\n\\item \\AESFUNC{ShiftRows}\n      ~\\cite[Section 5.1.2]{FIPS:197}\n      operates     row-wise,\n      rotating each \n      $i$-th row \n      of \n      $\\AESRND{s}{r  }$\n      by $i$ elements\n      to form \n      the associated row    of\n      $\\AESRND{s}{r+1}$,\n      i.e.,\n      $\\AESRND{s}{r+1}_{i,j} = \\AESRND{s}{r}_{i,j + i \\pmod{Nb}}$.\n      Where appropriate,\n      we use\n      \\AESFUNC{ShiftRow}\n      to denote\n      the operation applied to a single \n      row\n      within \\AESFUNC{ShiftRows}.\n\n\\item \\AESFUNC{MixColumns}\n      ~\\cite[Section 5.1.3]{FIPS:197}\n      operates  column-wise,\n      multiplying each \n      $j$-th column\n      of \n      $\\AESRND{s}{r  }$\n      with a constant MDS matrix\n      to form \n      the associated column of\n      $\\AESRND{s}{r+1}$.\n      Where appropriate,\n      we use\n      \\AESFUNC{MixColumn}\n      to denote\n      the operation applied to a single \n      column \n      within \\AESFUNC{MixColumns}, i.e., multiplication of a $4$-element \n      column vector by the constant MDS matrix.\n      \n\\item \\AESFUNC{AddRoundKey}\n      ~\\cite[Section 5.1.4]{FIPS:197}\n      operates element-wise,\n      computing\n      $\\AESRND{s}{r+1}_{i,j} = \\AESRND{s}{r}_{i,j} \\AESADD \\AESRND{rk}{r}_{i,j}$ \n      and thereby mixing a round key into the state.\n\n\\end{itemize}\n\n\\noindent\nNote that\n$\n\\ALG{S-layer} = \\AESFUNC{SubBytes} ,\n$\nand\n\\[\n\\ALG{P-layer} = \\left\\{\\begin{array}{l@{\\;}c@{\\;}l lr}\n                       \\AESFUNC{MixColumns} &\\circ& \\AESFUNC{ShiftRows} & \\mbox{in rounds} & 1 \\leq r < Nr \\\\\n                                            &     & \\AESFUNC{ShiftRows} & \\mbox{in round } &            Nr \\\\\n                       \\end{array}\n                \\right.\n\\]\ni.e., the last, $Nr$-th round differs from the initial $Nr - 1$ rounds.  As\nsuch, a round as defined above is constructed via\n$\n\\AESFUNC{AddRoundKey} \\circ \\AESFUNC{MixColumns} \\circ \\AESFUNC{ShiftRows} \\circ \\AESFUNC{SubBytes} \n$\nor\n$\n\\AESFUNC{AddRoundKey} \\circ                            \\AESFUNC{ShiftRows} \\circ \\AESFUNC{SubBytes}\n$\nrespectively, where, because \\AESFUNC{ShiftRows} and \\AESFUNC{SubBytes}\ncommute, the order they are applied in can be selected to suit.\n\n", "meta": {"hexsha": "441e307f7b6bcc62412ac971217ef7c2a3fb79ed", "size": 7594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/bg-aes_spec.tex", "max_stars_repo_name": "mfkiwl/aes-risc-pipeline", "max_stars_repo_head_hexsha": "9ebf788db1465cd5959fb23fbbcefdd60a5e0a34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-12T15:41:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T15:41:59.000Z", "max_issues_repo_path": "doc/tex/bg-aes_spec.tex", "max_issues_repo_name": "mfkiwl/aes-risc-pipeline", "max_issues_repo_head_hexsha": "9ebf788db1465cd5959fb23fbbcefdd60a5e0a34", "max_issues_repo_licenses": ["MIT"], "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/bg-aes_spec.tex", "max_forks_repo_name": "mfkiwl/aes-risc-pipeline", "max_forks_repo_head_hexsha": "9ebf788db1465cd5959fb23fbbcefdd60a5e0a34", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-08-26T17:16:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-05T05:07:42.000Z", "avg_line_length": 32.8744588745, "max_line_length": 137, "alphanum_fraction": 0.5776929155, "num_tokens": 2477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6307752379880145}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\n\\subsection{Rate Of}\nThe Operation $rateOf$ calculates the number of times something occurs\nwithin an interval of time given a unit of time.\n$$rateOf(nOccurances, start, end, unit)$$\nWhere the output translates to: the rate of occurrence per unit within interval\n\\begin{itemize}\n\\item $nOccurances$ is the number of times something happened and should be an Integer (called $nO?$ bellow)\n\\item $start$ is an ISO 8601 timestamp which serves as the first timestamp within the interval\n\\item $end$ is an ISO 8601 timestamp which servers as the last timestamp within the interval\n\\item $unit$ is a String Enum representing the unit of time\n\\end{itemize}\nThis can be seen in the definition of $rateOf$ bellow.\n\\begin{schema}{RateOf[\\nat, TIMESTAMP, TIMESTAMP, TIMEUNIT]}\n  nO? : \\nat \\\\\n  rate! : \\num \\\\\n  start?, end? : TIMESTAMP \\\\\n  unit? : TIMEUNIT \\\\\n  rateOf~\\_ : \\nat \\cross TIMESTAMP \\cross TIMESTAMP \\cross TIMEUNIT \\fun \\num\n  \\where\n  rate! = rateOf(nO?, start?, end?, unit?) @ \\\\\n  \\t1 let \\ \\ ~~ interval == isoToUnix(end) - isoToUnix(start) \\\\\n  \\t2 unitS == toSeconds(unit?) \\\\\n  \\t1 \\ = nO? \\div (interval \\div units)\n\\end{schema}\nThe only other functionality required by $rateOf$ is supplied via basic arithmetic\n\\begin{argue}\n  start = 2015-11-18T12:17:00Z \\\\\n  end = 2015-11-18T14:17:00Z \\\\\n  unit = second \\\\\n  nO? = 10 \\\\\n  \\t1 startN = isoToUnix(start) = 1447849020 \\\\\n  \\t1 endN = isoToUnix(end) = 1447856220 \\\\\n  \\t1 interval = endN - StartN = 7200\\\\\n  \\t1 unitN = toSeconds(unit) = 60 \\\\\n  0.001389 = rateOf(nO?, start, end, unit) \\implies 10 \\div (7200 \\div 60) \\\\\n  5 = rateOf(nO?, start, end, hour) \\implies 10 \\div (7200 \\div 3600)\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "ecc885a3ea847b01fe8b8a12355a377c6b449546", "size": 1743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/util/rateOf.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/util/rateOf.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/util/rateOf.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 41.5, "max_line_length": 108, "alphanum_fraction": 0.6924842226, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6307752379880144}}
{"text": "\n\\subsection{Equations}\n\\begin{frame}\n\\frametitle{$P_3$ equations}\n\n\\begin{itemize}\n  \\item $P_N$ expands the angular dependence in spherical harmonics.\n  \\item For N=3, steady-state, and one-dimension \\cite{davidson_neutron_1957}:\n\\end{itemize}\n% \\vspace{0.7cm}\n\n\\begin{align}\n    & \\frac{d}{dx} \\phi_{1,g} + \\Sigma_{t,g} \\phi_{0,g} = \\sum_{g'=1}^G \\Sigma_{s0,g' \\rightarrow g} \\phi_{0,g'} + \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\phi_{0,g'} + Q_{0,g}  \\label{eq:SP3-0} \\\\\n    & \\frac{1}{3} \\frac{d}{dx} \\phi_{0,g} + \\frac{2}{3}\\frac{d}{dx}\\phi_{2,g} + \\Sigma_{t,g} \\phi_{1,g} = \\sum_{g'=1}^G \\Sigma_{s1,g' \\rightarrow g} \\phi_{1,g'} + Q_{1,g} \\label{eq:SP3-1} \\\\\n    & \\frac{2}{5} \\frac{d}{dx}\\phi_{1,g} + \\frac{3}{5}\\frac{d}{dx}\\phi_{3,g} + \\Sigma_{t,g} \\phi_{2,g} = \\sum_{g'=1}^G \\Sigma_{s2,g' \\rightarrow g} \\phi_{2,g'} + Q_{2,g} \\label{eq:SP3-2} \\\\\n    & \\frac{3}{7}\\frac{d}{dx}\\phi_{2,g} + \\Sigma_{t,g} \\phi_{3,g} = \\sum_{g'=1}^G \\Sigma_{s3,g' \\rightarrow g} \\phi_{3,g'} + Q_{3,g}. \\label{eq:P3-3}\n\\end{align}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{$P_3$ equations (2)}\n\nAssumptions \\cite{brantley_simplifiedP3_2000}:\n\\begin{itemize}\n\t\\item isotropic external source\n\t\\item negligible anisotropic group-to-group scattering\n\\end{itemize}\n% \\vspace{0.7cm}\n\n\\begin{align}\n    & \\frac{d}{dx} \\phi_{1,g} + \\Sigma_{0,g} \\phi_{0,g} = \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\phi_{0,g'} + \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\phi_{0,g'} + Q_{0,g}  \\label{eq:SP3-0b} \\\\\n    & \\frac{1}{3} \\frac{d}{dx} \\phi_{0,g} + \\frac{2}{3}\\frac{d}{dx}\\phi_{2,g} + \\Sigma_{1,g} \\phi_{1,g} = 0  \\label{eq:SP3-1b} \\\\\n    & \\frac{2}{5} \\frac{d}{dx}\\phi_{1,g} + \\frac{3}{5}\\frac{d}{dx}\\phi_{3,g} + \\Sigma_{2,g} \\phi_{2,g} = 0  \\label{eq:SP3-2b} \\\\\n    & \\frac{3}{7}\\frac{d}{dx}\\phi_{2,g} + \\Sigma_{3,g} \\phi_{3,g} = 0. \\label{eq:SP3-3b}\n\\end{align}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{$P_3$ equations (3)}\n\nWith the following definitions:\n\\begin{align}\n    & D_{0,g} = \\frac{1}{3 \\Sigma_{1,g}}, \\quad D_{2,g} = \\frac{9}{35 \\Sigma_{3,g}} \\notag \\\\\n    & \\Phi_{0,g} = \\phi_{0,g} + 2 \\phi_{2,g}, \\quad \\Phi_{2,g} = \\phi_{2,g} \\notag\n\\end{align}\n% \\vspace{0.7cm}\n\nthe equations become:\n\\begin{align}\n    & - D_{0,g} \\frac{d^2}{dx^2} \\Phi_{0,g} + \\Sigma_{0,g} \\Phi_{0,g} - 2 \\Sigma_{0,g} \\Phi_{2,g} = S_{0,g} \\label{eq:SP3-0d} \\\\\n    & - D_{2,g} \\frac{d^2}{dx^2} \\Phi_{2,g} + \\left( \\Sigma_{2,g} + \\frac{4}{5} \\Sigma_{0,g} \\right) \\Phi_{2,g} - \\frac{2}{5} \\Sigma_{0,g} \\Phi_{0,g} = -\\frac{2}{5} S_{0,g} \\label{eq:SP3-2d}\n    \\intertext{where}\n    & S_{0,g} = \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right) + \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right) + Q_{0,g}. \\notag\n\\end{align}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{$SP_3$ approximation}\n    \\begin{itemize}\n        \\item $P_N$: yields the exact transport solution as $N \\rightarrow \\infty$.\n        \\item 3D: $(N+1)^2$ equations.\n        \\item 1D: $(N+1)$ equations yield $(N+1)/2$.\n        \\item $SP_N$ approximation replaces $\\frac{d^2}{dx^2}$ by $\\Delta$.\n    \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{$SP_3$ equations}\n\n\\begin{align}\n    & - D_{0,g} \\Delta \\Phi_{0,g} + \\Sigma_{0,g} \\Phi_{0,g} - 2 \\Sigma_{0,g} \\Phi_{2,g} = S_{0,g} \\label{eq:SP3-0e} \\\\\n    & - D_{2,g} \\Delta \\Phi_{2,g} + \\left( \\Sigma_{2,g} + \\frac{4}{5} \\Sigma_{0,g} \\right) \\Phi_{2,g} - \\frac{2}{5} \\Sigma_{0,g} \\Phi_{0,g} = -\\frac{2}{5} S_{0,g}. \\label{eq:SP3-2e}\n\\end{align}\n\nWith the Marshak vacuum BCs \\cite{beckert_development_2007}\n\n\\begin{align}\n    & \\frac{1}{4} \\Phi_{0,g} \\pm \\frac{1}{2} \\hat{n} \\cdot J_{0,g} - \\frac{3}{16} \\Phi_{2,g} = 0 \\label{eq:SP3-BC1a} \\\\\n    & - \\frac{3}{80} \\Phi_{0,g} \\pm \\frac{1}{2} \\hat{n} \\cdot J_{2,g} + \\frac{21}{80} \\Phi_{2,g} = 0 \\label{eq:SP3-BC2a}\n    \\intertext{where}\n    & J_{n,g} = -D_{n,g} \\nabla \\Phi_{n,g}. \\notag\n\\end{align}\n\\end{frame}\n\n\n\\subsection{Implementation}\n\n\\begin{frame}\n\\frametitle{MOOSE}\n\\begin{columns}\n    \\column[t]{5cm}\n  \\begin{itemize}\n      \\item Computational framework for solving coupled equation systems.\n      \\item Input are the equation weak forms.\n      \\item MOOSE and LibMesh translate them into residual and Jacobian functions.\n      \\item PetSc solution routines solve the equations.\n    \\end{itemize}\n\n  \\column[t]{5cm}\n  \\begin{figure}[htbp!]\n    \\begin{center}\n      \\includegraphics[width=5cm]{figures/moose}\n    \\end{center}\n    \\caption{MOOSE framework. Image reproduced from \\cite{inl_workshop_2020}.}\n  \\end{figure}\n\\end{columns}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Weak form}\n\n\\begin{figure}[htbp!]\n    \\begin{center}\n        \\includegraphics[width=8cm]{figures/moose2}\n    \\end{center}\n    \\caption{Translation into MOOSE kernels procedure \\cite{inl_workshop_2020}.}\n\\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{Weak form: Equation 1}\n\n\\begin{align}\n    & \\left< D_{0,g} \\nabla \\Phi_{0,g}, \\nabla \\Psi \\right> - \\left< D_{0,g} \\nabla \\Phi_{0,g}, \\Psi \\right>_{BC} + \\left< \\Sigma_{0,g} \\Phi_{0,g}, \\Psi \\right> + \\left< - 2 \\Sigma_{0,g} \\Phi_{2,g}, \\Psi \\right> \\notag \\\\ &+ \\left< - \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right> \\notag \\\\ &+ \\left< - \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right> + \\left< - Q_{0,g}, \\Psi \\right> = 0 \\label{eq:SP3-0g}\n    \\intertext{with the boundary condition}\n    & \\left< D_{0,g} \\nabla \\Phi_{0,g}, \\Psi \\right>_{BC} = \\left< \\frac{1}{2} \\Phi_{0,g} - \\frac{3}{4} \\Phi_{2,g}, \\Psi \\right>_{BC}.\n\\end{align}\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Weak form: Equation 2}\n\n\\begin{align}\n    & \\left< D_{2,g} \\nabla \\Phi_{2,g}, \\nabla \\Psi \\right> - \\left< D_{2,g} \\nabla \\Phi_{2,g}, \\Psi \\right>_{BC} + \\left< \\left( \\Sigma_{2,g} + \\frac{4}{5} \\Sigma_{0,g} \\right) \\Phi_{2,g}, \\Psi \\right> \\notag \\\\ &+ \\left< - \\frac{2}{5} \\Sigma_{0,g} \\Phi_{0,g}, \\Psi \\right> + \\left< \\frac{2}{5} \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right> \\notag \\\\ &+ \\left< \\frac{2}{5} \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right> + \\left< \\frac{2}{5} Q_{0,g}, \\Psi \\right> = 0. \\label{eq:SP3-2g}\n    \\intertext{with the boundary condition}\n    & \\left< D_{2,g} \\nabla \\Phi_{2,g}, \\Psi \\right>_{BC} = \\left< -\\frac{3}{40} \\Phi_{0,g} + \\frac{21}{40} \\Phi_{2,g}, \\Psi \\right>_{BC}.\n\\end{align}\n\\end{frame}\n\n\n\\subsection{Kernels}\n\\begin{frame}\n\\frametitle{SP3 Kernels: Equation 1}\n\n\\begin{table}[htbp!]\n  \\centering\n  \\caption{$SP_3$ kernels.}\n  \\begin{tabular}{lc}\n  \\toprule\n  Kernel name           & Equation 1 \\\\\n  \\midrule\n  SP3Diffusion           & $\\left< D_{0,g} \\nabla \\Phi_{0,g}, \\nabla \\Psi \\right>$ \\\\\n  SP3SigmaR              & $\\left< \\Sigma_{0,g} \\Phi_{0,g}, \\Psi \\right>$ \\\\\n  SP3SigmaCoupled        & $\\left< - 2 \\Sigma_{0,g} \\Phi_{2,g}, \\Psi \\right>$ \\\\\n  SP3InScatter           & $\\left< - \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right>$ \\\\\n  SP3FissionEigenKernel  & $\\left< - \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right>$ \\\\\n  BodyForce (MOOSE)      & $\\left< - Q_{0,g}, \\Psi \\right>$ \\\\\n  \\midrule\n  BC Kernel name & \\\\\n  \\midrule\n  SP3Vacuum          & $\\left< \\frac{1}{2} \\Phi_{0,g} - \\frac{3}{4} \\Phi_{2,g}, \\Psi \\right>_{BC}$ \\\\\n  \\bottomrule\n  \\end{tabular}\n\\end{table}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitle{SP3 Kernels: Equation 2}\n\n\\begin{table}[htbp!]\n  \\centering\n  \\caption{$SP_3$ kernels.}\n  \\begin{tabular}{lc}\n  \\toprule\n  Kernel name           & Equation 2 \\\\\n  \\midrule\n  SP3Diffusion           & $\\left< D_{2,g} \\nabla \\Phi_{2,g}, \\nabla \\Psi \\right>$ \\\\\n  SP3SigmaR              & $\\left< \\left( \\Sigma_{2,g} + \\frac{4}{5} \\Sigma_{0,g} \\right) \\Phi_{2,g}, \\Psi \\right>$ \\\\\n  SP3SigmaCoupled        & $\\left< - \\frac{2}{5} \\Sigma_{0,g} \\Phi_{0,g}, \\Psi \\right>$ \\\\\n  SP3InScatter           & $\\left< \\frac{2}{5} \\sum_{g'\\ne g}^G \\Sigma_{s0,g' \\rightarrow g} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right>$ \\\\\n  SP3FissionEigenKernel  & $\\left< \\frac{2}{5} \\frac{\\chi_g}{k_{eff}} \\sum_{g'=1}^G \\nu\\Sigma_{f,g'} \\left( \\Phi_{0,g'} - 2 \\Phi_{2,g'} \\right), \\Psi \\right>$ \\\\\n  BodyForce (MOOSE)      & $\\left< \\frac{2}{5} Q_{0,g}, \\Psi \\right>$ \\\\\n  \\midrule\n  BC Kernel name & \\\\\n  \\midrule\n  SP3Vacuum                & $\\left< - \\frac{3}{40} \\Phi_{0,g} + \\frac{21}{40} \\Phi_{2,g}, \\Psi \\right>_{BC}$ \\\\\n  \\bottomrule\n  \\end{tabular}\n\\end{table}\n\\end{frame}\n", "meta": {"hexsha": "41b58b30840e27ff4d4d4d5e72ff27b8baa7c4c8", "size": 8643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pubs/presentation-ans-studentconf-2021/methodology.tex", "max_stars_repo_name": "robfairh/npre555-cp03", "max_stars_repo_head_hexsha": "2aea7ae2df4a720c5d09003f98192f8986a6d107", "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": "pubs/presentation-ans-studentconf-2021/methodology.tex", "max_issues_repo_name": "robfairh/npre555-cp03", "max_issues_repo_head_hexsha": "2aea7ae2df4a720c5d09003f98192f8986a6d107", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-04T12:29:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-01T11:13:45.000Z", "max_forks_repo_path": "pubs/presentation-ans-studentconf-2021/methodology.tex", "max_forks_repo_name": "robfairh/npre555-cp03", "max_forks_repo_head_hexsha": "2aea7ae2df4a720c5d09003f98192f8986a6d107", "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": 43.6515151515, "max_line_length": 607, "alphanum_fraction": 0.580816846, "num_tokens": 3684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6307752347283565}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\\chapter{Decrease and Conquer}\nWant to do even better than  linear complexity? Decrease and conquer reduces one problem into one smaller subproblem only, and the most common case is to reduce the state space into half of its original size. If the combining step takes only constant time, we get an elegant recurrence relation as:\n\\begin{equation}\n    T(n) = T(n/2) + O(1),\n\\end{equation}\nwhich gives us logarithmic time complexity!\n\nWe introduce three classical algorithms--binary search in array, binary search tree, and segment tree to enforce our understanding of decrease and conquer. Importantly, binary search and binary search tree consists \\textbf{10\\%} of the total interview questions. \n\\section{Introduction}\nAll the searching we have discussed before never assumed any ordering between the items, and searching an item in an unordered space is doomed to have a time complexity linear to the space size. This case is about to change in this chapter. \n\nThink about these two questions: What if we have a sorted list instead of an arbitrary one? What if the parent and children nodes within a tree are ordered in some way? With such special ordering between items in a data structures, can we increase its searching efficiency and be better than the blind one by one search in the state space? The answer is YES.\n\nLet's take advantage of the ordering and the decrease and conquer methodology. To find a target in a space of size $n$, we first divide it into two subspaces and each of size $n/2$, say from the middle of the array. If the array is increasingly ordered, all items in the left subspace are smaller than all items in the right subspace. If we compare our target with the item in the middle, we will know if this target is on the left or right side. With just one step, we reduced our state space by half size. We further repeat this process on the reduced space until we find the target. This process is called \\textbf{Binary Search}. Binary search has recurrence relation:\n\\begin{equation}\n   T(n) = T(n/2) + O(1) ,\n\\end{equation}\nwhich decreases the time complexity from $O(n)$ to $O(\\log n)$.\n\n  \n%%%%%%%%%Binary search%%%%%%%%%\n\\section{Binary Search}\nBinary search can be easily applied in sorted array or string. \n\\begin{lstlisting}[numbers=none]\nFor example, given a sorted and distinct array\nnums = [1, 3, 4, 6, 7, 8, 10, 13, 14, 18, 19, 21, 24, 37, 40, 45, 71]\nFind target t = 7.\n\\end{lstlisting}\n\\paragraph{Find the Exact Target}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]{fig/Binary_Search_Depiction.png}\n    \\caption{Example of Binary Search}\n    \\label{fig:binary_search_eg_1}\n\\end{figure}\n\nThis is the most basic application of binary search. We can set two pointers, \\texttt{l} and \\texttt{r}, which points to the first and last position, respectively. Each time we compute the middle position \\texttt{m = (l+r)//2}, and check if the item $num[m]$ is equal to the target \\texttt{t}. \n\\begin{itemize}\n\\item If it equals, target found and return the position. \n\\item If it is smaller than the target, move to the left half by setting the right pointer to the position right before the middle position, $r = m - 1$. \n\\item If it is larger than the target, move to the right half by setting the left pointer to the position right after the middle position, $l = m + 1$. \n\\end{itemize}\nRepeat the process until we find the target or we have searched the whole space. The criterion of finishing the whole space is when \\texttt{l} starts to be larger than $r$. Therefore, in the implementation we use a \\texttt{while} loop with condition \\texttt{l$\\leq$ r} to make sure we only scan once of the searching space. The process of applying binary search on our exemplary array is depicted in Fig.~\\ref{fig:binary_search_eg_1} and the Python code is given as:\n\\begin{lstlisting}[language=Python]\ndef standard_binary_search(lst, target):\n    l, r = 0, len(lst) - 1\n    while l <= r:\n        mid = l + (r - l) // 2\n        if lst[mid] == target:\n            return mid\n        elif lst[mid] < target:\n            l = mid + 1\n        else:\n            r = mid - 1\n    return -1 # target is not found \n\\end{lstlisting}\nIn the code, we compute the middle position with \\texttt{mid = l + (r - l) // 2} instead of just \\texttt{mid = (l + r) //2} because these two always give the same computational result but the later is more likely to lead to overflow with its addition operator.\n\n\\subsection{Lower Bound and Upper Bound}\n\\paragraph{Duplicates and Target Missing} What if there are duplicates in the array:\n\\begin{lstlisting}[numbers=none]\nFor example, \nnums = [1, 3, 4, 4, 4, 4, 6, 7, 8]\nFind target t = 4\n\\end{lstlisting}\nApplying the first standard binary search will return \\texttt{3} as the target position, which is the second $4$ in the array. This does not seem like a problem at first. However, what if you want to know the predecessor or successor (3 or 5) of this target? In a distinct array, the predecessor and successor would be adjacent to the target. However, when the target has duplicates, the predecessor is  before the first target and the successor is next to the last target. Therefore, returning an arbitrary one will not be helpful. \n\nAnother case, what if our target is 6, and we first want to see if it exists in the array. If it does not, we would like to insert it into the array and still keep the array sorted. The above implementation simply returns $-1$, which is not helpful at all. \n\nThe \\textbf{lower and upper bound} of a binary search are the lowest and highest position where the value could be inserted without breaking the ordering. \n% However, if we design our algorithm to find (1) find the first position that has value larger or equals to the target, and (2) find the last position that has value smaller or equals to the target. This might be bit confusing, let us see it through examples. \n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.9\\columnwidth, height=4cm]{fig/binary_search_lower_bound.png}\n        \\caption{Binary Search: Lower  Bound of target 4.}\n            \\label{fig:binary_search_eg_lower_bound}\n    \\includegraphics[width=0.9\\columnwidth, height=4cm]{fig/binary_search_upper_bound.png}\n    \\caption{Binary Search: Upper Bound of target 4.}\n    \\label{fig:binary_search_eg_upper_bound}\n\\end{figure} \nFor example, if our $t=4$, the first position it can insert is at index 2 and the last position is at index 6.\n\\begin{itemize}\n    \\item \nWith index 2 as the lower bound, \nitems in $i \\in [0, l-1], a[i]<t$, $a[l] = t$, and $i\\in[l, n), a[i] \\geq t$. A lower bound is also the first position that has a value \\texttt{v $\\geq$ t}.  This case is shown in Fig.~\\ref{fig:binary_search_eg_lower_bound}.\n\\item With the upper bound, items in $i \\in [0, u-1], a[i]\\leq t$, $a[u] = t$, and $i\\in[u, n), a[i] > t$. An upper bound is also the first position that has a value \\texttt{v > t}.  This case is shown in Fig.~\\ref{fig:binary_search_eg_upper_bound}.\n\\end{itemize}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.9\\columnwidth, height=4cm]{fig/binary_search_lower_upper.png}\n        \\caption{Binary Search: Lower and Upper  Bound of target 5 is the same.}\n   \n    \\label{fig:binary_search_lower_upper}\n\\end{figure} \n\n\nIf $t=5$, the only position it can insert is at index 6, which indicates $l = u$. We show this case in Fig.~\\ref{fig:binary_search_lower_upper}.\n\nNow that we know the meaning of the upper and lower bound, here comes to the question, ``How to implement them?''\n\n\\paragraph{Implement Lower Bound} Because if the target equals to the value at the middle index, we have to move to the left half to find its leftmost position of the same value. Therefore, the logic is that we move as left as possible until it can't  further. When it stops,  $l>r$, and \\texttt{l} points to the first position that the value $v$ be $v\\geq t$. Another way to think about the return value is with assumption: Assume the middle pointer $m$ is at the first position that equals to the target in the case of target 4, which is index 2. According to the searching rule, it goes to the left search space and changes the right pointer as  $r=m-1$. At this point, in the valid search space, there will never be a value that can be larger or equals to the target, pointing out that it will only moving to the right side, increasing the \\texttt{l} pointer and leave the \\texttt{r} pointer untouched until  $l > r$ and the search stops. When the first time that $l > r$, the left pointer will be $l = r + 1 = m$, which is the first position that its value equals to the target. \n\nThe search process for target 4 and 5 is described as follows:\n\\begin{lstlisting}[numbers=none]\n0:  l = 0, r = 8, mid = 4\n1:  mid = 4, 4==4, l = 0, r = 3\n2:  mid = 1, 4>3, l = 2, r = 3\n3:  mid = 2, 4==4, l = 2, r = 1\nreturn l=2\n\\end{lstlisting}\nSimilarly, we run the case for target 5. \n\\begin{lstlisting}[numbers=none]\n0:  l = 0, r = 8, mid = 4\n1:  mid = 4, 5>4, l = 5, r = 8\n2:  mid = 6, 5<6, l = 5, r = 5\n3:  mid = 5, 5>4, l = 6, r = 5\nreturn l=6\n\\end{lstlisting}\nThe Python code is as follows:\n\\begin{lstlisting}[language=Python]\ndef lower_bound_bs(nums, t):\n  l, r = 0, len(nums) - 1\n  while l <= r:\n    mid = l + (r - l) // 2\n    if t <= nums[mid]: # move as left as possible\n      r = mid - 1\n    else:\n      l = mid + 1\n  return l\n\\end{lstlisting}\n\\paragraph{Implement Upper Bound} To be able to find the upper bound, we need to move the left pointer to the right as much as possible. Assume we have the middle index at 5, with target as 4. The binary search moves  to the right side of the state space, making $l=mid+1=6$. Now, in the right state space, the middle pointer will always have values larger than 4, thus it will only moves to the left side of the space, which only changes the right pointer \\texttt{r} and leaves the left pointer \\texttt{l} touched when the program ends. Therefore, \\texttt{l} will still return our final upper bound index.  The Python code is as follows:\n\\begin{lstlisting}[language=Python]\ndef upper_bound_bs(nums, t):\n  l, r = 0, len(nums) - 1\n  while l <= r:\n    mid = l + (r - l) // 2\n    if t >= nums[mid]: # move as right as possible\n      l = mid + 1\n    else:\n      r = mid - 1\n  return l\n\\end{lstlisting}\n\n\n\\paragraph{Python Module \\texttt{bisect}}\n% Binary search is usually carried out on a Static sorted array or 2D matrix. There are three basic cases: (1) find the exact target that value = target; If there are duplicates, we are more likely to be asked to (2) find the first position that has value >= target; (3) find the first position that has value <= target. Here, we use two example array: one without duplicates and the other has duplicates.\n% \\begin{lstlisting}[language=Python]\n% a = [2, 4, 5, 9]\n% b = [0, 1, 1, 1, 1, 1]\n% \\end{lstlisting}\n\n\n% From the example, we can see that multiple \\textbf{duplicates} of the target exist, it can possibly return any one of them. And for the case when the target does not exist, it simply returns -1. In reality, we might need to find a position where we can potentially insert the target to keep the sorted array sorted. There are two cases: (1) the first position that we can insert, which is the first position that has value>= target (2) and the last position we can insert, which is the first position that has value > target. For example, if we try to insert 3 in a, and 1 in b, the first position should be 1 and 1 in each array, and the last position is 1 and 6 instead.  \nConveniently, we have a Python built-in Module \\texttt{bisect} that offers two methods: \\texttt{bisect\\_left()} for obtaining the lower bound and \\texttt{bisect\\_right()} to obtain the upper bound. For example, we can use it as:\n\\begin{lstlisting}[language=Python]\nfrom bisect import bisect_left,bisect_right, bisect\nl1 = bisect_left(nums, 4)\nr1 = bisect_right(nums, 5)\nl2 = bisect_right(nums, 4)\nr2 = bisect_right(nums, 5)\n\\end{lstlisting}\nIt offers six methods as shown in Table~\\ref{tab:method_bisect}. \n\\begin{table}[h]\n\\begin{small}\n\\centering\n\\noindent\\captionof{table}{ Methods of \\textbf{bisect}}\n \\noindent \\begin{tabular}{|p{0.25\\columnwidth}|p{0.75\\columnwidth}| }\n  \\hline\nMethod & Description   \\\\ \\hline\n\\texttt{bisect\\_left(a, x, lo=0, hi=len(a)}  &  The parameters lo and hi may be used to specify a subset of the list; the function is the same as bisect\\_left\\_raw  \\\\\\hline\n\\texttt{bisect\\_right(a, x, lo=0, hi=len(a)}  &  The parameters lo and hi may be used to specify a subset of the list; the function is the same as bisect\\_right\\_raw  \\\\\\hline\n\\texttt{bisect(a, x, lo=0, hi=len(a))}  &Similar to bisect\\_left(), but returns an insertion point which comes after (to the right of) any existing entries of x in a.\\\\ \\hline\n\\texttt{insort\\_left(a, x, lo=0, hi=len(a))}  &This is equivalent to a.insert(bisect.bisect\\_left(a, x, lo, hi), x).\\\\ \\hline\n\\texttt{insort\\_right(a, x, lo=0, hi=len(a))} & This is equivalent to a.insert(bisect.bisect\\_right(a, x, lo, hi), x).\\\\ \\hline\n\\texttt{insort(a, x, lo=0, hi=len(a))} & Similar to insort\\_left(), but inserting x in a after any existing entries of x.\\\\ \\hline\n\\end{tabular}\n  \\label{tab:method_bisect}\n  \\end{small}\n\\end{table} \n\n\\paragraph{Bonus} For the lower bound, if we return the position as l-1, then we get the last position that \\texttt{value < target}. Similarily, for the upper bound, we get  the last position \\texttt{value <= target}.\n\n% \\paragraph{Python Built-in Module bisect} This module provides support for maintaining a list in sorted order without having to sort the list after each insertion. I\n% Let's see come examplary code:\n% \\begin{lstlisting}[language=Python]\n% from bisect import bisect_left,bisect_right, bisect\n% print(\"bisect left: find 3 in a :\", bisect_left(a,3), 'find 1 in b: ', bisect_left(b, 1)) # lower_bound, the first position that value>= target\n% print(\"bisect right: find 3 in a :\", bisect_right(a, 3), 'find 1 in b: ', bisect_right(b, 1)) # upper_bound, the last position that value <= target\n% \\end{lstlisting}\n% The print out is:\n% \\begin{lstlisting}\n% bisect left: find 3 in a : 1 find 1 in b:  1\n% bisect right: find 3 in a : 1 find 1 in b:  6\n% \\end{lstlisting}\n\\subsection{Applications}\n\\label{concept_binary_search_in_array}\nBinary Search is a powerful problem solving tool. Let's go beyond the sorted array: How about when the array is sorted in a way that  is not as monotonic as what we are familiar with, or how about solving math functions with binary search, whether they are continuous or discrete, equations or inequations?\n\\paragraph{First Bad Version(L278)} You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.\n\nSuppose you have $n$ versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad. You are given an API \\texttt{bool isBadVersion(version)} which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.\n\\begin{lstlisting}[numbers=none]\nGiven n = 5, and version = 4 is the first bad version.\n\ncall isBadVersion(3) -> false\ncall isBadVersion(5) -> true\ncall isBadVersion(4) -> true\n\nThen 4 is the first bad version.\n\\end{lstlisting}\n\\paragraph{Analysis and Design} In this case, we have a search space in range $[1, n]$. Think the value at each position is the result from function \\texttt{isBadVersion(i)}. Assume the first bad version is at position $b$, then the values from the positions are of such pattern: [F,..., F, ..., F, T, ..., T]. We can totally apply the binary search in the search space $[1, n]$: to find the first bad version is the same as finding the first position that we can insert a value \\texttt{True}--the lower bound of value \\texttt{True}. Therefore, whenever the value we find is \\texttt{True}, we move to the left space to try to get its first location. The Python code is given below:\n\\begin{lstlisting}[language = Python]\ndef firstBadVersion(n):\n    l, r = 1, n\n    while l <= r:\n        mid = l + (r - l) // 2\n        if isBadVersion(mid):\n            r = mid - 1\n        else:\n            l = mid + 1           \n    return l\n\\end{lstlisting}\n\\subsubsection{Search in Rotated Sorted Array}\n``How about we rotate the sorted array?''\n\\paragraph{Problem Definition(L33, medium)} Suppose an array (without duplicates) is first sorted in ascending order, but later is rotated at some pivot unknown to you beforehand--it takes all items before the pivot to the end of the array. For example, an array [0, 1, 2, 4, 5, 6, 7] be rotated at pivot 4, will become [4, 5, 6, 7, 0, 1, 2]. If the pivot is at 0, nothing will be changed. If it is at the end of the array, say 7, it becomes [7, 0, 1, 2, 4, 5, 6]. You are given a target value to search. If found in the array return its index, otherwise return -1. \n\\begin{lstlisting}[numbers=none]\nExample 1:\nInput: nums = [3,4,5,6,7,0,1,2], target = 0\nOutput: 5\n\ntarget = 8\nOutput: -1\n\\end{lstlisting}\n\\paragraph{Analysis and Design}\nIn the rotated sorted array, the array is not purely monotonic. Instead, there will be at most  one drop in the array because of the rotation, which we denote the high and the low item as $a_h, a_l$ respectively. This drop  cuts the array into two parts: $a[0:h+1]$ and $a[l:n]$, and both parts are ascending sorted. If the middle point falls within the left part, the left side of the state space will be sorted, and if it falls within the right part, the right side of the state space will be sorted.  Therefore, at any situation, there will always be one side of the state space that is sorted. To check which side is sorted, simply compare the value of middle pointer with that of left pointer. \n\\begin{itemize}\n    \\item If \\texttt{nums[l] < nums[mid]}, then the left part is sorted.\n    \\item If \\texttt{nums[l] > nums[mid]}, then the right part is sorted.\n    \\item Otherwise when they equal to each other, which is only possible that there is no left part left, we have to move to the right part. For example, when \\texttt{nums=[1, 3]}, we move to the right part.\n\\end{itemize}\n\nWith a sorted half of state space, we can check if our target is within the sorted half: if it is, we switch the state space to the sorted space; otherwise, we have to move to the other half that is unknown. The Python code is shown as:\n\\begin{lstlisting}[language=Python]\ndef RotatedBinarySearch(nums, t):   \n      l, r = 0, len(nums)-1\n      while l <= r:\n          mid = l + (r-l)//2\n          if nums[mid] == t:\n              return mid\n          # Left is sorted\n          if nums[l] < nums[mid]: \n              if nums[l] <= t < nums[mid]:\n                  r = mid - 1\n              else:\n                  l = mid + 1\n          # Right is sorted\n          elif nums[l] > nums[mid]: \n              if nums[mid] < t <= nums[r]:\n                  l = mid + 1\n              else:\n                  r = mid - 1\n          # Left and middle index is the same, move to the right\n          else: \n              l = mid + 1\n      return -1\n\\end{lstlisting}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{What happens if there are duplicates in the rotated sorted array? } In fact, the same comparison rule applies, with one minor change. When \\texttt{nums=[1, 3, 1, 1, 1]}, the middle pointer and the left pointer has the same value, and in this case, the right side will only consist of a single value, making us to move to the left side instead. However, if \\texttt{nums=[1,1,3]}, we need to move to the right side instead.  Moreover, for \\texttt{nums=[1, 3]}, it is because there is no left side we have to search the the right side. Therefore, in this case, it is impossible for us to decide which way to go, a simple strategy is to just move the left pointer forward by one position and retreat to the linear search. \n\\begin{lstlisting}[language=Python]\n# The left half is sorted\nif nums[mid] > nums[l]: \n# The right half is sorted\nelif nums[mid] < nums[l]: \n# For third case\nelse: \n   l +=1 \n\\end{lstlisting}\n\\end{bclogo}\n\n\n\n\n%%%%%%%%%%%%%%binary search on result space%%%%%%%\n\\subsubsection{Binary Search to Solve Functions}\nNow, let's see how it can be applied to solve equations or inequations. Assume, our function is $y = f(x)$, and this function is monotonic, such as $y = x, y = x^2+1, y = \\sqrt{x}$. To solve this function is the same as finding a solution $x_t$ to a given target $y_t$. We generally have three steps to solve such problems: % If the question gives us the context: the target is in the range [left, right], we need to search the first or last position that satisfy a condition function. We can apply the concept of standard binary search and bisect\\_left and bisect\\_right and its mutant. Where we use the condition function to replace the value comparison between target and element at middle position. The steps we need:\n\\begin{enumerate}\n    \\item Set a search space for $x$, say it is $[x_l, x_r]$. \n    \\item If the function is equation, we find a $x_t$ that either equals to $y_t$ or close enough such as $|y_t - y| <= 1e-6$ using standard binary search. \n    \\item If the function is inequation, we see if it wants the first or the last $x_t$ that satisfy the constraints on $y$. It is the same as of finding the lower bound or upper bound. \n\\end{enumerate}\n\n\\paragraph{Arranging Coins (L441, easy)} You have a total of n coins that you want to form in a staircase shape, where every $k$-th row must have exactly $k$ coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of a 32-bit signed integer.\n\\begin{lstlisting}[numbers=none]\nExample 1:\nn = 5\nThe coins can form the following rows:\n*\n* *\n* *\n\nBecause the 3rd row is incomplete, we return 2.\n\\end{lstlisting}\n\n\\paragraph{Analysis and Design} Each row $x$ has $x$ coins, summing it up, we get $1+2+...+x= \\frac{x(x+1)}{2}$. The problem is equvalent to find the last integer $x$ that makes $\\frac{x(x+1)}{2}\\leq n$. Of course, this is just a quadratic equation which can be easily solved if you remember the formula, such as the following Python code:\n\\begin{lstlisting}[language=Python]\nimport math\ndef arrangeCoins(n: int) -> int:\n    return int((math.sqrt(1+8*n)-1) // 2)\n\\end{lstlisting}\nHowever, if in the case where we do not know a direct closed-form solution, we solicit binary search. First, the function of $x$ is monotonically increasing, which indicates that binary search applies. We set the range of $x$ to $[1, n]$, what we need is to find the last position that the condition of  $\\frac{x(x+1)}{2}\\leq n$ satisfies, which is the position right before the upper bound. The Python code is given as:\n\\begin{lstlisting}[language=Python]\ndef arrangeCoins(n):\n    def isValid(row):\n        return (row * (row + 1)) // 2 <= n\n    \n    def bisect_right():\n        l, r = 1, n\n        while l <= r:\n            mid = l + (r-l) // 2\n            # Move as right as possible\n            if isValid(mid): \n                l = mid + 1\n            else:\n                r = mid - 1\n        return l\n    return bisect_right() - 1\n\\end{lstlisting}\n\n% \\subsection{Bisection Method} (second edition)\n% The binary search principle can be used to find the root of a function that may be difficult to compute mathematically. We have not seen any problems that require this method on LeetCode yet. Thus we define the problem as:\n\n% Find the monthly payment for a loan: You want to buy a car using loan and want to pay in monthly installment of d d\n% \\subsection{Python Library}\n% Python has \\textbf{bisect} module for binary search. \n% \\begin{lstlisting}[numbers=none]\n% bisect.bisect_left(a,    x):  Return the leftmost index where we can  insert x into a to maintain sorted order! Leftmost rl that satisfy: x<=a[rl]\n\n% bisect.bisect_right(a,    x):  Return the rightmost index where we can  insert x into a to maintain sorted order! Right most rr that satisfy: x>=a[rr]\n% \\end{lstlisting}\n% For example:\n% \\begin{lstlisting}[language=Python]\n% from bisect import bisect_left,bisect_right\n% a = [1,    2,    3,    3,    3,    4,    5]\n% p1, p2= bisect_left(a,3), bisect_right(a, 3)\n% print(p1, p2)\n% # output\n% # 2, 5\n% \\end{lstlisting}\n\n\n%%%%%%%%%%%%%%%%%%%%%binary search tree%%%%%%%%%%%%%%%%%%%%%%\n\\section{Binary Search Tree}\n\\label{sec_binary_search_tree}\n\nA sorted array supports logarithmic query time with binary search, however it still takes linear time to update--delete or insert items. Binary search tree (BSTs), a type of binary tree designed for fast access and updates to items,  on the other hand, only takes $O(\\log n)$ time to update. How does it work?\n\nIn the array data structure, we simply sort the items, but how to apply sorting in a binary tree?  Review the min-heap data structure, which recursively defining a node to have the largest value among the nodes that belong to the subtree of that node, will give us a clue. In the binary search tree, we define that for any given node \\texttt{x}, all nodes in the left subtree of \\texttt{x} have keys smaller than \\texttt{x} while all nodes in the right subtree of \\texttt{x} have keys larger than \\texttt{x}. An example is shown in Fig.~\\ref{fig:bst}. With this definition, simply comparing a search target with the root can point us to half of the search space, given the tree is balanced enough. Moreover, if we do in-order traversal of nodes in the tree from the root, we end up with a nice and sorted keys in ascending order, making binary search tree one member of the sorting algorithms. \n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width = 0.6\\columnwidth]{fig/bst_example.png}\n    \\caption{Example of Binary search tree of depth 3 and 8 nodes.}\n    \\label{fig:bst}\n\\end{figure}\n\n\n\n\n% The advantage of search trees is their efficient search time ( $O(\\log n)$) given the tree is reasonably balanced, which is to say the leaves at either end are of comparable depths as we introduced the \\textbf{balanced binary tree}. \nBinary search tree needs to support many operations, including searching for a given key, the minimum and maximum key, and a  predecessor or successor of a given key, inserting and deleting items while maintaining the binary search tree property. Because of its efficiency of these operations compared with other data structures,  binary search tree is often used as a dictionary or a priority queue.\n\n\n% Search trees are often used to implement an associative array. The search tree algorithm uses the key from the key-value pair to find a location, and then the application stores the entire key–value pair at that location. \n\n% In this section, we will introduce the most commonly used two types of searching trees: binary searching tree (BST) and Trie where the keys are usually numeric numbers and strings respectively. \n\n% \\subsection{Binary Searching Tree}\n% \\label{concept_binary_search_tree}\nWith $l$ and $r$ to represent the left and right child of node $x$,  there are two other definitions other than the binary search tree definition we just introduced:  (1)$l.key \\leq x.key < r.key$ and (2) $l.key  < x.key \\leq r.key$. In these two cases, our resulting BSTs allows us to have duplicates. The exemplary implementation follow the definition that does not allow duplicates.\n\n% an organized searching tree structure in binary tree, as the name suggests. Binary search trees whose internal nodes each store a key (and optionally, an associated value), each node have two distinguished sub-trees (if only one sub-tree the other is None). \n\n% BST keep their keys in sorted order, so that lookup and other operations can use the \\textit{principle of binary search tree}: \n\n% \\indent Let $x$ be a node in a binary search tree, if $y$ is a node in the left subtree of x, them $y.key \\leq x.key$. If $y$ is a node in the right subtree of $x$, then $y.key \\geq x.key$. \n\n\n\n\\subsection{Operations}\n% When looking for a key in a tree (or a place to insert a new key), we traverse the tree from root to leaf, making comparisons to keys stored in the nodes of the tree and deciding, on the basis of the comparison, to continue searching in the left or right subtrees. On average, this means that each comparison allows the operations to skip about half of the tree, so that each SEARCH, INSERT or DELETE takes time proportional to the logarithm of the number of items stored in the tree. This is much better than the linear time required to find items by key in an (unsorted) array, but slower than the corresponding operations on hash tables. \n\n% \\textbf{Definition} A binary search tree is a rooted binary tree, whose internal nodes each store a key (and optionally, an associated value) and each have two distinguished sub-trees, commonly denoted left and right. The tree additionally satisfies the binary search property, which states that the key in each node must be greater than or equal to any key stored in the left sub-tree, and less than or equal to any key stored in the right sub-tree.[1]:287 The leaves (final nodes) of the tree contain no key and have no structure to distinguish them from one another. \n\nIn order to build a BST, we need to insert a series of items in the tree organized by the search tree property. And in order to insert, we need to search for a proper position first and then insert the new item while sustaining the search tree property. Thus, we introduce these operations in the order of search, insert and generate. \n\n\\paragraph{Search}\n\nThe search is highly similar to the binary search in the array. It starts from the root. Unless the node's value equals to the target, the search proceeds to either the left or right child depending upon the comparison result. The search process terminates when either the target is found or when an empty node is reached. It can be implemented either recursively or iteratively with a time complexity $O(h)$, where $h$ is the height of the tree, which is roughly $\\log n$ is the tree is balanced enough. The recursive search is shown as:\n\\begin{lstlisting}[language = Python]\ndef search(root, t):\n  if not root:\n    return None\n  if root.val == t:\n    return root\n  elif t < root.val:\n    return search(root.left, t)\n  else:\n    return search(root.right, t)\n\\end{lstlisting}\nBecause this is a tail recursion, it can easily be converted to iteration,  which helps us save the heap space. The iterative code is given as:\n\\begin{lstlisting}[language = Python]\n# iterative searching\ndef iterative_search(root,key):\n    while root is not None and root.val != key:\n        if root.val < key:\n            root = root.right\n        else:\n            root = root.left\n    return root\n\\end{lstlisting}\n\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Write code to find the minimum and maximum key in the BST. } The minimum key locates at the leftmost of the BST, while the maximum key locates at the rightmost of the tree. \n\\end{bclogo}\n\n%%%%%%%%%%%%Insertion%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Insert}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/bst_insert_9.png}\n    \\caption{The red colored path  from the root down to the position where the key 9 is inserted. The dashed line indicates the link in the tree that is added to insert the item. }\n    \\label{fig:bst_insert}\n\\end{figure}\nAssuming we are inserting a node with key 9 into the tree shown in Fig~\\ref{fig:bst}. We start from the root, compare 9 with 8, and goes to node 10. Next, the search process will lead us to the left child of node 10, and this is where we should put node 9. The process is shown in Fig.~\\ref{fig:bst_insert}. \n\nThe process itself is easy and clean. Here comes to the implementation. We treat each node as a subtree: whenever the search goes into that node, then the algorithm hands over the insertion task totally to that node, and assume it has inserted the new node and return its updated node. The main program will just simply reset its left or right child with the return value from its children. The insertion of new node happens when the search hits an empty node, it returns a new node with the target value. The implementation is given as:\n\\begin{lstlisting}[language = Python]\ndef insert(root, t):\n  if not root:\n    return BiNode(t)\n  if root.val == t:\n    return root\n  elif t < root.val:\n    root.left = insert(root.left, t)\n    return root\n  else:\n    root.right = insert(root.right, t) \n    return root\n\\end{lstlisting}\nIn the notebook, I offered a variant of implementation, check it out if you are interested. To insert iteratively, we need to track the parent node while searching. The \\texttt{while} loop stops when it hit at an empty node.  There will be three cases in the case of the parent node:\n\\begin{enumerate}\n    \\item When the parent node is \\texttt{None}, which means the tree is empty. We assign the root node with the a new node of the target value.\n\\item When the target's value is larger than the parent node's, the put a new node as the right child of the parent node.  \n\\item When the target's value is smaller than the parent node's, the put a new node as the left child of the parent node. \n\\end{enumerate}\nThe iterative code is given as:\n\\begin{lstlisting}[language = Python]\ndef insertItr(root, t):\n  p = None\n  node = root #Keep the root node\n  while node:\n    # Node exists already\n    if node.val == t:\n      return root\n    if t > node.val:\n      p = node\n      node = node.right\n    else:\n      p = node\n      node = node.left\n  # Assign new node\n  if not p:\n    root = BiNode(t)\n  elif t > p.val:\n    p.right = BiNode(t)\n  else:\n    p.left = BiNode(t)\n  return root\n\\end{lstlisting}\n\\paragraph{BST Generation}\nTo generate our exemplary BST shown in Fig.~\\ref{fig:bst}, we set \\texttt{keys = [8, 3, 10, 1, 6, 14, 4, 7, 13]}, then we call \\texttt{insert} function we implemented for each key to generate the same tree. The time complexity will be $O(n\\log n)$.\n\\begin{lstlisting}[language=Python]\nkeys = [8, 3, 10, 1, 6, 14, 4, 7, 13]\nroot = None\nfor k in keys:\n  root = insert(root, k)\n\\end{lstlisting}\n\\paragraph{Find the Minimum and Maximum Key} Because the minimum key is the leftmost node within the tree, the search process will always traverse to the left subtree and return the last non-empty node, which is our minimum node.  The time complexity is the same as of searching any key, which is $O(\\log n)$.\n\\begin{lstlisting}[language=Python]\ndef minimum(root):\n  if not root:\n    return None\n  if not root.left:\n    return root\n  return minimum(root.left)\n\\end{lstlisting}\nIt can easily be converted to iterative:\n\\begin{lstlisting}[language=Python]\ndef minimumIter(root):\n  while root:\n    if not root.left:\n      return root\n    root = root.left\n  return None\n\\end{lstlisting}\nTo find the maximum node, replacing \\texttt{left} with \\texttt{right} will do. \n%%%%%%%%%%%Predecessor and Successor\nAlso, sometimes we need to search two additional items related to a given node:  successor and predecessor. The structure of a binary search tree allows us to determine the successor or the predecessor of a tree without ever comparing keys. \n\n\\paragraph{Successor}  A successor of node $x$ is the smallest node in BST that is strictly greater than $x$. It is also called \\textbf{in-order successor}, which is the node next to node $x$ in the inorder traversal ordering--sorted ordering. Other than the maximum node in BST, all other nodes will have a successor. The simplest implementation is to return the next node within inorder traversal. This will have a linear time complexity, which is not great. The code is shown as:\n\\begin{lstlisting}[language=Python]\ndef successorInorder(root, node):\n  if not node:\n    return None\n  if node.right is not None:\n    return minimum(node.right)\n  # Inorder traversal\n  succ = None\n  while root:      \n    if node.val > root.val:\n      root = root.right\n    elif node.val < root.val:\n      succ = root\n      root = root.left\n    else:\n      break\n  return succ\n\\end{lstlisting}\n\nLet us try something else. In the BST shown in Fig.~\\ref{fig:bst_insert}, the node 3's successor will be node 4. For node 4, its successor will be node 6. For node 7, its successor is node 8. What are the cases here?\n\\begin{itemize}\n    \\item An easy case is when a node has right subtree, its successor is the minimum node within its right subtree.\n    \\item However, if a node does not have a right subtree, there are two more cases: \n    \\begin{itemize}\n        \\item If it is a left child of its parent, such as node 4 and 9, its direct parent is its successor.\n        \\item However, if it is a right child of its parent, such as node 7 and 14, we traverse backwards to check its parents. If a parent node is the left chid of its parent, then that parent will be the successor. For example, for node 7, we traverse through 6, 3, and 3 is a left child of node 8, making node 8 the successor for node 7.  \n    \\end{itemize}\n    The above two rules can be merged as: starting from the target node, traverse backward to check its parent, find the first two  nodes which are in left child--parent relation. The parent node in that relation will be our targeting successor. Because the left subtree is always smaller than a node, when we backward, if a node is smaller than its parent, it tells us that the current node is smaller than that parent node too. \n\\end{itemize}\nWe write three functions to implement the successor: \n\\begin{itemize}\n    \\item Function \\texttt{findNodeAddParent} will find the target node and add a \\texttt{parent} node to each node along the searching that points to their parents. The Code is as:\n\\begin{lstlisting}[language=Python]\ndef findNodeAddParent(root, t):\n  if not root:\n    return None\n  if t == root.val: \n    return root\n  elif t < root.val:\n    root.left.p = root\n    return findNodeAddParent(root.left, t)\n  else:\n    root.right.p = root\n    return findNodeAddParent(root.right, t)\n\\end{lstlisting}\n\\item Function \\texttt{reverse} will find the first left-parent relation when traverse backward from a node to its parent.\n\\begin{lstlisting}[language=Python]\ndef reverse(node):\n  if not node or not node.p:\n    return None\n  # node is a left child\n  if node.val < node.p.val:\n    return node.p\n  return reverse(node.p)\n\\end{lstlisting}\n\\item Function \\texttt{successor} takes a node as input, and return its sccessor.\n\\begin{lstlisting}[language=Python]\ndef successor(root):\n  if not root:\n    return None\n  if root.right:\n    return minimum(root.right)\n  else:\n    return reverse(root) \n\\end{lstlisting}\n\\end{itemize}\nTo find a successor for a given key, we use the following code:\n\\begin{lstlisting}[language=Python]\nroot.p = None\nnode = findNodeAddParent(root, 4)\nsuc = successor(node)\n\\end{lstlisting}\nThis approach will gives us $O(\\log n)$ time complexity. \n% \\parabutbut if is only possible with parent nodes. For BST that has no parent nodes designed, we can add parent nodes along searching the target node. After the target node is found, we stop and check different cases. The code is given as:\n% \\begin{lstlisting}[language=Python]\n% def successor(root, t):\n%   # Traverse backward and see if a node is a left child\n%   def reverse(node):\n%     if not node or not node.p:\n%       return None\n%     # node is a left child\n%     if node.val < node.p.val:\n%       return node.p\n%     return reverse(node.p)\n  \n%   # Find the target and set its parent while searching\n%   def helper(root, t):\n%     # t is not found\n%     if not root:\n%       return None\n%     if t == root.val: \n%       if root.right:\n%         return minimum(root.right)\n%       else:\n%         return reverse(root)\n%     elif t < root.val:\n%       root.left.p = root\n%       return helper(root.left, t)\n%     else:\n%       root.right.p = root\n%       return helper(root.right, t)\n    \n%   root.p = None\n%   return helper(root, t)\n% \\end{lstlisting}\n\n% Use parent node: the algorihtm has two cases on the basis of the right subtree of the input node. \n% \\begin{lstlisting}[numbers=none]\n% For the right subtree of the node:\n% 1) If it is not None, then the successor is the minimum node in the right subtree. e.g. for node 12, successor(12) = 13 = min(12.right)\n% 2) If it is None, then the successor is one of its ancestors. We traverse up using the parent node until we find a node which is the left child of its parent. Then the parent node here is the successor. e.g.  successor(2)=5\n% \\end{lstlisting}\n%  The Python code is provided:\n% \\begin{lstlisting}[language = Python]\n% def Successor(root, n):\n% # Step 1 of the above algorithm\n%     if n.right is not None:\n%         return get_minimum(n.right)\n% # Step 2 of the above algorithm\n% p = n.parent\n% while p is not None:\n%     if n == p.left :# if current node is the left child node, then we found the successor, p\n%         return p\n%     n = p\n%     p = p.parent\n% return p\n% \\end{lstlisting}\n\n\n\\paragraph{Predecessor}  A predecessor of node $x$ on the other side, is the largest item in BST that is strictly smaller than $x$. It is also called \\textbf{in-order predecessor}, which denotes the previous node in Inorder traversal of BST. For example, for node 6, the predecessor is node 4, which is the maximum node within its left subtree. For node 4, its predecessor is node 3, which is the parent node in a right child--parent relation while tracing back through parents. Now, assume we find the targeting node with function \\texttt{findNodeAddParent}, we first write \\texttt{reverse} function as \\texttt{reverse\\_right}. \n\\begin{lstlisting}[language=Python]\ndef reverse_right(node):\n  if not node or not node.p:\n    return None\n  # node is a right child\n  if node.val > node.p.val:\n    return node.p\n  return reverse_right(node.p)\n\\end{lstlisting}\nNext, we implement the above rules to find predecessor of a given node. \n\\begin{lstlisting}[language = Python]\ndef predecessor(root):\n  if not root:\n    return None\n  if root.left:\n    return maximum(root.left)\n  else:\n    return reverse_right(root) \n\\end{lstlisting}\n The expected time complexity is $O(\\log n)$. And the worst is when the tree line up and has no branch, which makes it $O(n)$. \n Similarily, we can use inorder traversal:\n\\begin{lstlisting}[language=Python]\ndef predecessorInorder(root, node):\n  if not node:\n    return None\n  if node.left is not None:\n    return maximum(node.left)\n  # Inorder traversal\n  pred = None\n  while root:      \n    if node.val > root.val:\n        pred = root\n        root = root.right\n    elif node.val < root.val:\n      root = root.left\n    else:\n      break\n  return pred\n\\end{lstlisting}\n\\paragraph{Delete} \nWhen we delete a node, we need to restructure the subtree of that node to make sure the BST property is maintained. There are different cases:\n\\begin{enumerate}\n    \\item Node to be deleted is leaf: Simply remove from the tree. For example, node 1, 4, 7, and 13.\n    \\item Node to be deleted has only one child: Copy the child to the node and delete the child. For example, to delete node 14, we need to copy node 13 to node 14. \n    \\item Node to be deleted has two children, for example, to delete node 3, we have its left and right subtree. We need to get a value, which can either be its predecessor-node 1 or successor--node 4, and copy that value to the position about to be deleted. \n\\end{enumerate}\nTo support the delete operation, we write a function \\texttt{deleteMinimum} to obtain the minimum node in that subtree and return a subtree that has that node deleted.\n\\begin{lstlisting}[language=Python]\ndef deleteMinimum(root):\n  if not root:\n    return None, None\n  if root.left:\n    mini, left = deleteMinimum(root.left)\n    root.left = left\n    return mini, root\n  # the minimum node\n  if not root.left: \n    return root, None \n\\end{lstlisting}\nNext, we implement the above three cases in function \\texttt{\\_delete}  when a deleting node is given,  which will return a processed subtree deleting its root node. \n\\begin{lstlisting}[language=Python]\ndef _delete(root):\n  if not root:\n    return None\n  # No chidren: Delete it\n  if not root.left and not root.right:\n    return None \n  # Two children: Copy the value of successor\n  elif all([root.left, root.right]):\n    succ, right = deleteMinimum(root.right)\n    root.val = succ.val\n    root.right = right\n    return root\n  # One Child: Copy the value\n  else:\n    if root.left:\n      root.val = root.left.val\n      root.left = None\n    else:\n      root.val = root.right.val\n      root.right = None\n    return root\n\\end{lstlisting}\nFinally, we call the above two function to delete a node with a target key.\n\\begin{lstlisting}[language=Python]\ndef delete(root, t):\n  if not root:\n    return\n  if root.val == t:\n    root = _delete(root)\n    return root \n  elif t > root.val:\n    root.right = delete(root.right, t)\n    return root\n  else:\n    root.left = delete(root.left, t)\n    return root\n\\end{lstlisting}\n% \\paragraph{Summary}\n% Now  we put a table here to summarize the space and time complexity for each operation.\n% \\begin{table}[h]\n% \\begin{small}\n% \\centering\n% \\noindent\\captionof{table}{ Time complexity of operations for BST in big O notation }\n%  \\noindent \\begin{tabular}{|p{0.33\\columnwidth}|p{0.33\\columnwidth}| p{0.33\\columnwidth}|}\n%   \\hline\n%  Algorithm & Average & Worst Case  \\\\ \\hline\n% Space  & $O(n)$& $O(n)$ \\\\\n% Search   & $O(\\log n)$ & $O(n)$ \\\\ \\hline\n\n% Insert & $O(\\log n)$ & $O(n)$ \\\\ \n% Delete & $O(\\log n)$ & $O(n)$ \\\\ \\hline\n% \\end{tabular}\n%   \\label{tab:msrc_precession}\n%   \\end{small}\n% \\end{table}\n\n% \\paragraph{Advanced Features}\n% For a BST, the left subtree all have smaller values than the current node, and the right subtree are all bigger than the current node. This concept is useful in trimming BST, see example, $669$. Trim a Binary Search Tree. \n\n\n% \\section{Augmented Tree}\n% According to \\textit{Introduction to Algorithms}, augmenting data stuctures are defined as a textbook data structure augmented by storing additional information in it. In this Section, we introduce two types of augmented tree: Trie for pattern matching in static String and Segment Tree for Range Query. \n\n%https://www.mimuw.edu.pl/~szczurek/TSG2/04_suffix_arrays.pdf\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Binary Search Tree with Duplicates}\nIf we use any of the other two definitions we introduced that allows duplicates, things can be more complicated. For example, if we  use the definition $x.left.key <= x.key < x.right.key$, we will end up with a tree looks like Fig.~\\ref{fig:bst_duplicate}: \n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.3\\columnwidth]{fig/bst_duplicate.png}\n    \\caption{A BST with nodes 3 duplicated twice.}\n    \\label{fig:bst_duplicate}\n\\end{figure}\nNote that the duplicates are not in contiguous levels. This is a big issue when allowing duplicates in a BST representation as, because  duplicates may be separated by any number of levels, making the detection of duplicates difficult.\n\nAn option to avoid this issue is to not represent duplicates structurally (as separate nodes) but instead use a \\texttt{counter} that counts the number of occurrences of the key. The previous example will be represented as in Fig.~\\ref{fig:bst_duplicate_counter}:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.3\\columnwidth]{fig/bst_duplicate_counter.png}\n    \\caption{A BST with nodes 3 marked with two occurrence.}\n    \\label{fig:bst_duplicate_counter}\n\\end{figure}\n\nThis simplifies the related operations at the expense of some extra bytes and counter operations. Since a heap is a complete binary tree, it has a smallest possible height - a heap with N nodes always has O(log N) height. \n\n\n\n%%%%%%%%%%%%%%Segment Tree%%%%%%%%%%%%%%%\n\\section{Segment Tree}\n\\label{sec_segment_tree}\nTo answer queries over an array is called a \\textit{range query problem}, e.g. finding the sum of consecutive subarray $a[l:r]$, or finding the minimum item in such a range. A direct and linear solution is to compute the required query on the subarray on the fly each time. When the array is large, and the update is frequent, even this linear approach will be too slow. Let's try to solve this problem faster than linear. How about computing the query for a range in advance and save it in a dictionary? If we can, the query time is constant. However, because there are $n^2$ subarray, making the space cost polynomial, which is definitely not good.  Another problem, ``what if we need to change the value of an item'', we have to update $n$ nodes in the dictionary which includes the node in its range. \n\nWe can balance the search, update, and space from the dictionary approach to a logarithmic time with the technique of decrease and conquer. In the binary search, we keep dividing our search space into halves recursively until a search space can no longer be divided. We can apply the dividing process here, and construct a binary tree, and each node has \\texttt{l} and \\texttt{r} to indicate the range of that node represents. For example, if our array has index range $[0, 5]$,  its left subtree will be [0, mid], and right subtree will be [mid+1, 5]. a binary tree built with binary search manner is shown in Fig.~\\ref{fig:segment_tree_range}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/segment_tree_range.png}\n    \\caption{A Segment Tree }\n    \\label{fig:segment_tree_range}\n\\end{figure}\nTo get the answer for range query $[0, 5]$, we just return the value at root node. If the range is $[0, 1]$, which is on the left side of the tree, we go to the left branch, and cutting half of the search space. For a range that happens to be between two nodes, such as $[1, 3]$, which needs node \\texttt{[0, 1]} and \\texttt{[2-5]}, we search [0, 1] in the left subtree and [2, 3] in the right subtree and combine them together. Any searching will be within $O(\\log n)$, relating to the height of the tree. \\textcolor{red}{needs better complexity analysis} \n\n\\paragraph{Segment tree} The above binary tree is called \\textbf{segment tree}. From our analysis, we can see a segment tree is a static full binary trees. 'Static` here means once the data structure is built, it can not be modified or extended.  However, it can still update the value in the original array into the segment tree. Segment tree is applied widely to efficiently answer numerous \\textit{dynamic range queries} problems \n(in logarithmic time), such as finding minimum, maximum, sum, greatest common divisor, and least common denominator in array.\n\n\nConsider an array $A$ of size $n$ and a corresponding segment tree $T$:\n\\begin{enumerate}\n    \\item The root of $T$ represents the whole array $A[0:n]$. \n    \\item Each internal node in $T$ represents the interval of $A[i:j]$ where $0 < i < j <= n$. \n    \\item Each leaf in $T$ represents a single element A[i], where $0 \\leq i<n$. \n    \\item If the parent node is in range [i, j], then we separate this range at the middle position $m = (i+j)//2$; the left child takes range $[i, m]$, and the right child take the interval of $[m+1, j]$.\n\\end{enumerate}\n\nBecause in each step of building the segment tree, the interval is divided into two halves, so the height of the segment tree will be $\\log n$. And there will be totally $n$ leaves and $n-1$ number of internal nodes, which makes the total number of nodes in segment tree to be $2n-1$, which indicates a linear space cost. Except of an explicit tree can be used to implement segment tree, an implicit tree implemented with  array can be used too, similar to the case of heap data structure. \n\n\\subsection{Implementation}\nImplementation of a functional segment tree consists of three core operations: tree construction, range query, and value update, named as as \\texttt{\\_buildSegmentTree()}, \\texttt{RangeQuery()}, and \\texttt{update()}, respectively. We demonstrate the implementation with Range Sum Query (RSQ) problem, but we try to generalize the process so that the template can be easily reused to other range query problems. In our implementation, we use explicit tree data structure for both convenience and easier to understand. We define a general tree node data structure as:\n\\begin{lstlisting}[language=Python]\nclass TreeNode:\n  def __init__(self, val, s, e):\n    self.val = val\n    self.s = s\n    self.e = e\n    self.left = None\n    self.right = None\n\\end{lstlisting}\n\n%\\begin{examples}[resume]\n\\paragraph{Range Sum Query(L307, medium)} Given an integer array, find the sum of the elements between indices i and j, range $[i, j], i\\leq j$. \n\\begin{lstlisting}[numbers=none]\nExample:\n\nGiven nums = [2, 9, 4, 5, 8, 7]\n\nsumRange(0, 2) -> 15\nupdate(1, 3)\nsumRange(0, 2) -> 9\n\\end{lstlisting}\n\n\\paragraph{Tree Construction}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]{fig/segment_tree_construction.png}\n    \\caption{Illustration of Segment Tree for Sum Range Query. }\n    \\label{fig:segment_tree_construction}\n\\end{figure}\nThe function \\texttt{\\_buildSegmentTree()} takes three arguments: \\texttt{nums}, \\texttt{s} as the start index, and \\texttt{e} as the end index. Because there are totally $2n-1$ nodes, which makes the time and space complexity both be $O(n)$.\n\\begin{lstlisting}[language=Python]\ndef _buildSegmentTree(nums, s, e):\n  '''\n   s, e: start index and end index\n  '''\n  if s > e:\n      return None\n  if s == e:\n      return TreeNode(nums[s], s, e)\n  \n  m = (s + e)//2\n  # Divide: return a subtree \n  left = _buildSegmentTree(nums, s, m)\n  right = _buildSegmentTree(nums, m+1, e)\n  \n  # Conquer: merge two subtree\n  node = TreeNode(left.val + right.val, s, e)\n  node.left = left\n  node.right = right\n  return node\n\\end{lstlisting}\nBuilding a segment tree for our example as:\n\\begin{lstlisting}[language=Python]\nnums = [2, 9, 4, 5, 8, 7]\nroot = _buildSegmentTree(nums, 0, len(nums) - 1)\n\\end{lstlisting}\nIt will generate a tree shown in Fig.~\\ref{fig:segment_tree_construction}. \n\\paragraph{Range  Query}  Each query within range $[i, j], i < j, i\\geq s, j \\leq e$, will be found on a node or by combining multiple node. In the query process,  check the following cases:\n\\begin{itemize}\n    \\item \n    If range $[i, j]$ matches the range $[s, e]$, if it matches, return the value of the node, otherwise, processed to other cases.\n    \\item  Compute middle index $m = (s + e) // 2$. Check if range $[i, j]$ is within the left state space $[s, m]$ if $j\\leq m$, or within the right state space $[m+1, e]$ if $i\\geq m+1$, or is cross two spaces if otherwise. \n    \\begin{itemize}\n    \\item For the first two cases, a recursive call on that branch will return our result.\n    \\item For the third case, where the range crosses two space, two recursive calls on both children of our current node are needed: the left one handles range $[i, m]$, and the right one handles range $[m+1, j]$. The final result will be a combination of these two. \n    \\end{itemize}\n\\end{itemize}\nThe code is as follows: \n\\begin{lstlisting}[language=Python]\ndef _rangeQuery(root, i, j, s, e): \n  if s == i and j == e:\n    return root.val if root else 0 \n  m = (s + e)//2\n  if j <= m:\n    return _rangeQuery(root.left, i, j, s, m)\n  elif i > m:\n    return _rangeQuery(root.right, i, j, m+1, e)\n  else:\n    return _rangeQuery(root.left, i, m, s, m) + _rangeQuery(root.right, m+1, j, m+1, e)\n\\end{lstlisting}\n% The complete code is given: \n% \\begin{lstlisting}[language=Python]\n% class NumArray:\n%     class TreeNode:\n%         def __init__(self, val):\n%             self.val = val\n%             self.left = None\n%             self.right = None\n\n%     def __init__(self, nums):\n%         self.n = 0\n%         self.st = None\n%         if nums:\n%             self.n = len(nums)\n%             self.st = self._buildSegmentTree(nums, 0, self.n-1)    \n            \n%     def update(self, i, val):\n%         self._updateNode(i, val, self.st, 0, self.n -1)       \n\n%     def sumRange(self, i, j):\n%         return self._rangeQuery(self.st, i, j, 0, self.n-1)\n% \\end{lstlisting}\n\\paragraph{Update} To update \\texttt{nums[1]=3}, all nodes on the path from root to the leaf node will be affected and needed to be updated with to incorporate the change at the leaf node. We search through the tree with a range $[1, 1]$ just like we did within \\texttt{\\_rangeQuery} except that we no longer need the case of crossing two ranges. Once we reach to the leaf node, we update that node's value to the new value, and it backtracks to its parents where we recompute the parent node's value according to the result of its children.   This operation takes $O(\\log n)$ time complexity, and we can do it inplace since the structure of the tree is not changed. \n\\begin{lstlisting}[language=Python]\ndef _update(root, s, e, i, val):\n  if s == e == i:\n    root.val = val\n    return \n  m = (s + e) // 2\n  if i <= m:\n    _update(root.left, s, m, i, val)\n  else:\n    _update(root.right, m + 1, e, i, val)\n  root.val = root.left.val + root.right.val\n  return \n\\end{lstlisting}\n\n\\paragraph{Minimum and Maximum Range Query} To get the minimum or maximum value within a given range, we just need to modify how to value is computed. For example, to update, we just need to change the line 10 of the above code to \\texttt{root.val = min(root.left.val, root.right.val)}. \n\nThere are way more other variants of segment tree, check it out if you are into knowing more at \\url{https://cp-algorithms.com/data_structures/segment_tree.html}.\n\n% \\paragraph{Dynamic Programming for Static Array}\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%Exercise%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Exercises}\n\n\\begin{enumerate}\n    \\item 144. Binary Tree Preorder Traversal\n    \\item 94. Binary Tree Inorder Traversal\n    \\item 145. Binary Tree Postorder Traversal\n    \\item 589. N-ary Tree Preorder Traversal\n    \\item 590. N-ary Tree Postorder Traversal\n    \\item 429. N-ary Tree Level Order Traversal\n    \\item 103. Binary Tree Zigzag Level Order Traversal(medium)\n    \\item 105. Construct Binary Tree from Preorder and Inorder Traversal\n\\end{enumerate}\n\n938. Range Sum of BST (Medium)\n\nGiven the root node of a \\textbf{binary search tree}, return the sum of values of all nodes with value between L and R (inclusive).\n\nThe binary search tree is guaranteed to have unique values.\n\\begin{lstlisting}\nExample 1:\n\nInput: root = [10,5,15,3,7,null,18], L = 7, R = 15\nOutput: 32\n\nExample 2:\n\nInput: root = [10,5,15,3,7,13,18,1,null,6], L = 6, R = 10\nOutput: 23\n\\end{lstlisting}\n\\textbf{Tree Traversal+Divide and Conquer}. We need at most $O(n)$ time complexity. For each node, there are three cases: 1) L <= val <= R, 2)val < L, 3)val > R. For the first case it needs to obtain results for both its subtrees and merge with its own val. For the others two, because of the property of BST, only the result of one subtree is needed. \n\\begin{lstlisting}[language=Python]\ndef rangeSumBST(self, root, L, R):\n    if not root:\n        return 0\n    if L <= root.val <= R:\n        return self.rangeSumBST(root.left, L, R) + self.rangeSumBST(root.right, L, R) + root.val\n    elif root.val < L: #left is not needed\n        return self.rangeSumBST(root.right, L, R)\n    else: # right subtree is not needed\n        return self.rangeSumBST(root.left, L, R)\n\\end{lstlisting}\n\n\\subsection{Exercises}\n\\begin{examples}\n\\item \\textbf{35. Search Insert Position (easy).} Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.\n\nYou can assume that there are no duplicates in the array.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: [1,3,5,6], 5\nOutput: 2\n\nExample 2:\nInput: [1,3,5,6], 2\nOutput: 1\n\nExample 3:\nInput: [1,3,5,6], 7\nOutput: 4\n\nExample 4:\nInput: [1,3,5,6], 0\nOutput: 0\n\\end{lstlisting}\n\n\\textbf{Solution: Standard Binary Search Implementation.} For this problem, we just standardize the Python code of binary search, which takes $O(logn)$ time complexity and O(1) space complexity without using recursion function. In the following code, we use exclusive right index with len(nums), therefore it stops if l == r; it can be as small as 0 or as large as n of the array length for numbers that are either smaller or equal to the nums[0] or larger or equal to nums[-1]. We can also make the right index inclusive. \n\\begin{lstlisting}[language = Python]\n# exclusive version\ndef searchInsert(self, nums, target):\n    l, r = 0, len(nums) #start from 0, end to the len (exclusive)\n    while l < r:\n        mid = (l+r)//2\n        if nums[mid] < target: #move to the right side\n            l = mid+1\n        elif nums[mid] > target: #move to the left side, not mid-1\n             r= mid\n        else: #found the traget\n            return mid\n    #where the position should go\n    return l\n\\end{lstlisting}\n\n\\begin{lstlisting}[language = Python]\n# inclusive version\ndef searchInsert(self, nums, target):\n   l = 0\n    r = len(nums)-1\n    while l <= r:\n        m = (l+r)//2\n        if target > nums[m]: #search the right half\n            l = m+1\n        elif target < nums[m]: # search for the left half\n            r = m-1\n        else:\n            return m\n    return l\n\\end{lstlisting}\n\\end{examples}\nStandard binary search\n\\begin{enumerate}\n    \\item 611. Valid Triangle Number (medium)\n    \\item 704. Binary Search (easy)\n    \n\\item  74. Search a 2D Matrix) Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:\n\\begin{enumerate}\n    \\item Integers in each row are sorted from left to right.\n    \\item The first integer of each row is greater than the last integer of the previous row.\n    \\end{enumerate}\n\\begin{lstlisting}[numbers=none]\nFor example,\nConsider the following matrix:\n\n[\n  [1,   3,  5,  7],\n  [10, 11, 16, 20],\n  [23, 30, 34, 50]\n]\n\nGiven target = 3, return true.\n\\end{lstlisting}\n\n% Solution: 2D matrix search, time complexity from $O(n^2)$ to $O(lgm+lgn)$.\n% \\begin{lstlisting}[language = Python]\n% def searchMatrix(self, matrix, target):\n%         \"\"\"\n%         :type matrix: List[List[int]]\n%         :type target: int\n%         :rtype: bool\n%         \"\"\"\n        \n%         if not matrix:\n%             return False\n%         row, col = len(matrix), len(matrix[0])\n%         if row==0 or col==0: #for [[]]\n%             return False\n%         sr, er = 0, row-1\n%         #fisrst search the mid row\n%         while sr<=er:\n%             mid = sr+(er-sr)//2\n%             if target>matrix[mid][-1]: #go to the right side\n%                 sr=mid+1\n%             elif target < matrix[mid][0]: #go the the left side\n%                 er = mid-1\n%             else: #value might be in this row\n%                 #search in this row\n%                 lc, rc = 0, col-1\n%                 while lc<=rc:\n%                     midc = lc+(rc-lc)//2\n%                     if matrix[mid][midc]==target:\n%                         return True\n%                     elif target<matrix[mid][midc]: #go to left\n%                         rc=midc-1\n%                     else:\n%                         lc=midc+1\n%                 return False\n%         return False\n% \\end{lstlisting}\n\nAlso, we can treat is as one dimensional, and the time complexity is $O(lg(m*n))$, which is the same as $O(log(m)+log(n))$.\n\\begin{lstlisting}[language = Python]\nclass Solution:\n    def searchMatrix(self, matrix, target):\n        if not matrix or target is None:\n            return False\n\n        rows, cols = len(matrix), len(matrix[0])\n        low, high = 0, rows * cols - 1\n        \n        while low <= high:\n            mid = (low + high) / 2\n            num = matrix[mid / cols][mid % cols]\n\n            if num == target:\n                return True\n            elif num < target:\n                low = mid + 1\n            else:\n                high = mid - 1\n        \n        return False\n\\end{lstlisting}\n\\end{enumerate}\n\nCheck \\url{http://www.cnblogs.com/grandyang/p/6854825.html} to get more examples.\n\nSearch on rotated and 2d matrix:\n\\begin{enumerate}\n    \\item 81. Search in Rotated Sorted Array II (medium) \n    \\item 153. Find Minimum in Rotated Sorted Array (medium) The key here is to compare the mid with left side, if mid-1 has a larger value, then that is the minimum \n    \\item 154. Find Minimum in Rotated Sorted Array II (hard)\n\\end{enumerate}\nSearch on Result Space:\n\\begin{enumerate}\n    \\item 367. Valid Perfect Square (easy) (standard search)\n    \\item 363. Max Sum of Rectangle No Larger Than K (hard)\n    \\item 354. Russian Doll Envelopes (hard)\n    \\item 69. Sqrt(x) (easy)\n\\end{enumerate}\n\n\n% \\subfile{chapters/chapter_9_linear_searching}\n%  \\subfile{chapters/chapter_13_tree_algorithm}\n \\end{document}", "meta": {"hexsha": "e8719f5888850d8c6a4d802939e9135037f5f634", "size": 64759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_decrease_and_conquer.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_decrease_and_conquer.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_decrease_and_conquer.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": 56.3611836379, "max_line_length": 1084, "alphanum_fraction": 0.7061257895, "num_tokens": 17436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6307392760731914}}
{"text": "\\subsubsection{Combining stratum-level risk limits}\\label{sec:stratumRisk}\nWe audit to test the two hypotheses $\\{\\omega_{w\\ell,s} \\ge \\lambda_s V_{w\\ell}\\}_{s=1}^2$, \nindependently for the two strata.\nIf we reject \\emph{both} hypotheses, we conclude that the contest outcome is correct;\notherwise, we manually re-tabulate the contest in one or both strata, depending on the\naudit rules.\nThose rules matter:\nthe two audits might need to be conducted to smaller risk limits individually than the desired\nrisk limit for the contest as a whole.\n\nRecall that the samples are drawn independently from the two strata.\nPick $\\alpha_1, \\alpha_2 \\in (0,\\alpha)$.\n(Below we discuss the choice further.)\nWe audit each stratum $s$ to test the hypothesis $\\omega_{w\\ell,s} \\ge \\lambda_s V_{w\\ell}$ \n(the overstatement exceeds the tolerable overstatement) \nat risk limit $\\alpha_s$,\nas if it were its own election.\nThe audits can be conducted at the same time or sequentially; there is no coordination\nbetween the audits unless one of them leads to a full hand count but the other does not:\nsee below.\n\nHow do these two stratum-level ``risk limits'' $\\alpha_1$ and\n$\\alpha_2$ determine the \noverall risk that the audit will not correct the outcome if the outcome is wrong?\nThe overall risk depends on the rule for what we do if the audit in one stratum leads \nto a full manual tally of that stratum.\n\nHere are the possibilities. Bear in mind that for the outcome to be wrong, \nat least one stratum must have a net overstatement\ngreater its tolerable overstatement: \nThat is, if $\\omega_{w\\ell,1} + \\omega_{w\\ell,2} \\ge V_{w\\ell}$, then $\\omega_{w\\ell,1}\\ge \\lambda_1V_{w\\ell}$\nor $\\omega_{w\\ell,2}\\ge \\lambda_2V_{w\\ell}$, or both.\nIf the tolerable overstatement is exceeded in only one stratum, $h$, then the chance that the \nstratum will be fully hand counted is at least $1-\\alpha_h \\ge 1- \\alpha$.\n\nIf both $\\omega_{w\\ell,1} \\ge \\lambda_1V_{w\\ell}$\nand $\\omega_{w\\ell,2} \\ge \\lambda_2V_{w\\ell}$, then the chance both \nare completely tabulated by hand is at least\n$(1-\\alpha_1)(1-\\alpha_2)$, since the audit samples in the two strata are independent.\n\nWhat should we do if the audit leads to a full tally in one stratum, $h$,\nthat reveals that indeed its tolerable overstatement has been exceeded, \nbut the other audit has not led to a full tabulation, because it \nhas not started, because it is still underway, or because it terminated without\na full hand tally?\nWe consider two options.\nThe simpler is to automatically require a full hand count of the other stratum. \nIf the audit uses this rule, then we can take $\\alpha_1 = \\alpha_2 = \\alpha$, \nand the procedure will have risk limit~$\\alpha$. However, this rule creates the\npossibility of requiring a full hand count in circumstances where it may seem\nsubstantively superfluous. For instance, one can imagine an audit of a statewide\ncontest in which the tolerable overstatement in no-CVR counties is exceeded, \nyet the outcome still could be verified without a full hand count in the CVR counties.\n\nThe second approach is to adjust the tolerable overstatement in the other\nstratum in light of the known manual tally $A_{w\\ell,h}$\nin the stratum $h$ that has been fully hand tallied:\nwe will test against the threshold \n$V_{w\\ell} - A_{w\\ell,h} \\equiv \\lambda_t' V_{w\\ell}$, rather than \nthe original value $\\lambda_t V_{w\\ell}$. (Because the overstatement\nin stratum $h$ exceeded the tolerable overstatement, the updated tolerable\noverstatement in stratum $t$ will be smaller than the original value.) \nThen to reject the new null hypothesis in stratum $t$ is to conclude that the \noverall outcome is correct.\n\nIf and when the hypothesis in stratum $t$ changes, the audit\nin that stratum might be able to stop on the basis of the data already observed;\nit might need to continue; or---if it had stopped based on the original threshold\n$\\lambda_t V_{w\\ell}$---it might need to examine more ballots, possibly\ncontinuing to a full hand tally.\n\nWe will now show in detail that this rule allows the contest to be audited at \nrisk limit~$\\alpha$ by selecting values of~$\\alpha_1$ and~$\\alpha_2$ that sum to\na bit more than~$\\alpha$: specifically, such that $(1-\\alpha_1)(1-\\alpha_2) < 1-\\alpha$.\nFor instance, suppose we want the overall risk limit to be 5\\%. \nIf we use a risk limit of 4\\% in the no-CVR stratum and a risk limit of 1.04\\% in the CVR stratum,\nthe overall risk limit is not larger than $1 - (1-\\alpha_1)(1-\\alpha_2) \\equiv 1 - 0.96\\times 0.9896 < 0.05$.\n\nThe statistical wrinkle is that adjusting for the manual tally in the hand-counted \nstratum $h$\nchanges the hypothesis being tested in the other stratum $t$\nin a way that is itself random:\nwhether the original null $\\omega_{w\\ell,s} \\ge \\lambda_t V_{w\\ell}$ is tested\nor the new null $\\omega_{w\\ell,s} \\ge \\lambda_t' V_{w\\ell}$ is tested depends on what the \nsample reveals in stratum $h$.\nIf the hypothesis does change, there is only one value possible for $\\lambda_t'$---which\ndepends on the reported margin $V_{w\\ell}$ and the count $A_{w\\ell,h}$ in \nstratum $h$---but $\\lambda_t'$ is unknown until $A_{w\\ell,h}$ is known.\n\nWe assume that before any data are collected, the audit specifies two families of tests:\nfor each stratum $s$, a family of level-$\\alpha_s$ tests of the null hypothesis that \nthe overstatement in the stratum is greater than or equal to $c$, for all feasible values of $c$.\nThat is,\n\\beq\n    \\Pr \\{ \\mbox{reject hypothesis that } \\omega_{w\\ell,s} \\ge \n    c_s || \\omega_{w\\ell,s} \\ge c_s \\} \\le \\alpha_s,\n\\eeq\nfor $s = 1, 2$, and all feasible $c_s$.\nMoreover, we insist that the test depend on data only from ballots selected from its stratum.\nBecause the samples in the two strata are independent, for all feasible pairs $c_1, c_2$,\n\\begin{align} \\label{eq:stratum_families}\n    \\Pr\\{&\\mbox{reject neither hypothesis } \\omega_{w\\ell,s} \\ge c_s, \\;\\; s=1, 2 ||\n       \\omega_{w\\ell,s} \\ge c_s  \\mbox{ for both } s=1, 2 \\} \\nonumber \\\\ \n       &= \\prod_{s=1}^2 1 - \\Pr \\{ \\mbox{reject hypothesis that } \\omega_{w\\ell,s} \\ge c_s || \\omega_{w\\ell,s} \\ge c_s \\} \\nonumber \\\\\n       & \\ge (1-\\alpha_1)(1-\\alpha_2).\n\\end{align}\n\nWhat is the chance that the audit leads to a full hand tabulation if the outcome is incorrect?\nOne way the audit can lead to a full hand tally is if it leads to a full count in one stratum, \nthe null hypothesis in the other stratum is changed, and the audit in the second \nstratum then proceeds to a full manual tally.\n(There are other ways the audit can lead to a full hand tally, for instance, if neither\nnull hypothesis is rejected, but this is one way.)\n\nIf the outcome is wrong, there is at least one stratum in which the overstatement \n$\\omega_{w\\ell,s}$ \nexceeds the threshold $\\lambda_s V_{w\\ell}$.\nLet $h$ be one such stratum. \nThen the chance the audit in stratum $h$ leads to a full manual tally in that stratum\nis at least $(1-\\alpha_h)$.\nIf the audit leads to a full manual tally in stratum~$h$ and the overall outcome is wrong,\nthen the (new) null hypothesis in the other stratum, $t$, must be true.\nIf we started to audit that new hypothesis \\emph{ab initio}, the chance that we would reject it\nwould be at most $\\alpha_t$, so the chance the audit would lead to a full hand count \nof stratum $t$ is at least $1-\\alpha_t$.\nThe question is whether ``changing hypotheses'' could make that chance smaller.\nThe inequality \\ref{eq:stratum_families} shows that it cannot: for any feasible pair of\noverstatements, $c = (c_1, c_2)$, if $\\omega_{w\\ell,1} \\ge c_1$ and $\\omega_{w\\ell,2} \\ge c_2$,\nthe chance that neither the hypothesis $\\omega_{w\\ell,1} \\ge c_1$ nor the hypothesis \n$\\omega_{w\\ell,2} \\ge c_2$ will be rejected is at least $(1-\\alpha_1)(1-\\alpha_2)$.\n\nAnd therefore, for this procedure, the chance that there will be a full hand count in both strata is at least \n$(1-\\alpha_1)(1-\\alpha_2)$ if the outcome is incorrect,\neven if the probability were zero that both of the original audits would proceed to a full hand count.\nThe overall risk limit is thus not larger than $1 - (1-\\alpha_1)(1-\\alpha_2)$\n.\n", "meta": {"hexsha": "5e3ac18bfe18d0c199fe8bf0985b9c0a9709a3ff", "size": 8079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stratumRisk.tex", "max_stars_repo_name": "zwt16300180060/CORLA18", "max_stars_repo_head_hexsha": "9e5826245f80aeb8923c84550b8f8e39ed0325c5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-10T08:15:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-04T08:35:06.000Z", "max_issues_repo_path": "stratumRisk.tex", "max_issues_repo_name": "ElectionAuditWare/CORLA18", "max_issues_repo_head_hexsha": "f03af7a7b514746f40426bb204c531fabcd10baf", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-08-14T16:43:48.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-27T22:23:38.000Z", "max_forks_repo_path": "stratumRisk.tex", "max_forks_repo_name": "ElectionAuditWare/CORLA18", "max_forks_repo_head_hexsha": "f03af7a7b514746f40426bb204c531fabcd10baf", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-09-12T03:06:12.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-01T13:43:19.000Z", "avg_line_length": 58.9708029197, "max_line_length": 134, "alphanum_fraction": 0.7422948385, "num_tokens": 2285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6307392742232715}}
{"text": "\\documentclass[11pt,a4paper]{article}\n\\usepackage{times}\n\\usepackage{natbib}\n\\setcitestyle{round, authoryear}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\newcommand*\\diff{\\mathop{}\\!\\mathrm{d}}\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\usepackage{subfig}\n\n\\title{Optimizing Discrete Units in Stochastic Computation Graphs}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\n\\begin{document}\n\n\\maketitle\n\n\nConsider a stochastic computation graph (SCG), where $X$ is a hidden stochastic layer (backpropagation covers the rest). We can interpret the forward pass in the graph as first sampling $x$ from the conditional distribution $p_\\phi(x)$ of $X$ given its parent layers, then evaluate a deterministic function $f_\\theta(x)$ at $X$. We can think of $f_\\theta(x)$ as a noisy objective, so we are interested in optimizing its expected value $L(\\theta, \\phi) = \\mathbb{E}_{x\\sim p_\\phi(x)}[f_\\theta(x)]$ w.r.t. parameters $\\theta, \\phi$.\n\nIn general, the gradient w.r.t. the parameters $\\theta$ is given as:\n\\begin{equation}\n    \\nabla_\\theta L(\\theta, \\phi) = \\nabla_\\theta \\mathbb{E}_{x\\sim p_\\phi(x)}[f_\\theta(x)] = \\mathbb{E}_{x\\sim p_\\phi(x)}[\\nabla_\\theta f_\\theta(x)]\n\\end{equation}\nand can be estimated by Monte Carlo sampling:\n\\begin{equation}\n    \\nabla_\\theta L(\\theta, \\phi) \\simeq \\frac{1}{S} \\sum_{s=1}^{S} \\nabla_\\theta f_\\theta(x^{s})\n\\end{equation}\nwhere $x^{s} \\sim p_\\phi(x)$ i.i.d. \n\nThe challenging task is to compute the gradient w.r.t. the parameters $\\phi$ of $p_\\phi(x)$.\nThe expression\n\\begin{equation}\n\\label{grad}\n    \\nabla_\\phi L(\\theta, \\phi) = \\nabla_\\phi \\int p_\\phi(x) f_\\theta(x) \\diff x = \\int f_\\theta(x) \\nabla_\\phi p_\\phi(x) \\diff x \n\\end{equation}\ndoes not have the form of an expectation w.r.t. $x$ and consequently does not lead to a Monte Carlo gradient estimator. However, there are two ways of tackling this problem.\n\n\n\\section{Score Function Estimators}\n\n\nThe score function estimator (SFE, \\cite{fu2006gradient}), also known as the REINFORCE \\citep{williams1992simple} or likelihood-ratio estimator \\citep{glynn1990likelihood}, is based on the identity \n\\begin{equation}\n    \\nabla_\\phi p_\\phi(x) = p_\\phi(x) \\nabla_\\phi \\log p_\\phi(x) ,\n\\end{equation}\nwhich allows the gradient in Equation (\\ref{grad}) to be written as \n\\begin{align}\n\\begin{split}\n    \\nabla_\\phi L(\\theta, \\phi) & = \\nabla_\\phi \\int f_\\theta(x) p_\\phi(x) \\diff x \\\\\n    & = \\int f_\\theta(x) \\nabla_\\phi p_\\phi(x) \\diff x \\\\\n    & = \\int f_\\theta(x) p_\\phi(x) \\nabla_\\phi \\log p_\\phi(x) \\diff x \\\\\n    & = \\mathbb{E}_{x\\sim p_\\phi(x)}[f_\\theta(x) \\nabla_\\phi \\log p_\\phi(x)]\n\\end{split}\n\\end{align}\nWe can then estimate this gradient via Monte Carlo sampling\n\\begin{equation}\n    \\nabla_\\phi L(\\theta, \\phi) \\simeq \\frac{1}{S} \\sum_{s=1}^{S} f_\\theta(x^{s}) \\nabla_\\phi \\log p_\\phi(x^{s})\n\\end{equation}\nwhere $x^{s} \\sim p_\\phi(x)$ i.i.d. As it does not require $f_\\theta(x)$ to be differentiable or even continuous as a function of $x$, the SFE can be used for both continuous and discrete random variables.\n\nThough the basic version of the estimator suffers from high variance, various variance reduction techniques are used to make the estimator much more effective. Baselines are the most important and widely used of these techniques \\citep{williams1992simple}. Specifically, a control variate $b(x)$ can be subtracted from the learning signal $f_\\theta(x)$ and its analytical expectation $\\mu_b = \\mathbb{E}_{x\\sim p_\\phi(x)}[b(x)\\nabla_\\phi \\log p_\\phi(x)] $ should also be added back to keep the estimator unbiased:\n\\begin{equation}\n    \\nabla_\\phi L(\\theta, \\phi) = \\mathbb{E}_{x\\sim p_\\phi(x)}[(f_\\theta(x) - b(x))\\nabla_\\phi \\log p_\\phi(x)] + \\mu_b \n\\end{equation}\n\nHere we briefly summarize recent stochastic gradient estimators that utilize control variates.\n\n\\paragraph{NVIL \\citep{mnih2014neural}} uses two baselines: (1) a moving average $\\bar{f}$ of $f$ to center the learning signal, and (2) an input-dependent baseline computed by a neural network (a control variate for the centered learning signal itself). Finally, variance normalization divides the learning signal by $\\max(1,\\sigma_f)$, where $\\sigma_f^2$ is a moving average of $\\text{Var}[f]$. We will discuss more about NVIL in the context of variational inference.\n\n\\paragraph{DARN \\citep{gregor2013deep}} uses $b = f(\\bar{x}) + f'(\\bar{x})(x - \\bar{x})$, where the baseline corresponds to the first-order Taylor approximation of $f(x)$ from $f(\\bar{x})$. $x$ is chosen to be 1/2 for Bernoulli variables, which makes the estimator biased for non-quadratic $f$, since it ignores the correction term $\\mu_b$ in the estimator expression.\n\n\\paragraph{MuProp \\citep{gu2015muprop}} also models the baseline as a first-order Taylor expansion: $b = f(\\bar{x}) + f'(\\bar{x})(x - \\bar{x})$ and $\\mu_b = f'(\\bar{x})\\nabla\\phi \\mathbb{E}_{x\\sim p_\\phi(x)} [x]$. To overcome backpropagation through discrete sampling, a mean-field approximation $f_{MF} (\\mu_\\phi(x))$ is used in place of $f(x)$ to compute the baseline and derive the relevant gradients.\n\n\\paragraph{VIMCO \\citep{mnih2016variational}} is a gradient estimator for multi-sample objectives that uses the mean of other samples $b = \\frac{1}{m}\\sum_{j\\neq i} f(x_j)$ to construct a baseline for each sample $x_i \\in x_{1:m}$.\n\n\\section{Reparameterization Trick}\n\nIn many cases we can sample from $p_\\phi(x)$ by first sampling $z$ from some fixed distribution $q(z)$ and then transforming the sample using some function $g_\\phi(z)$. For example, a sample from $\\text{Normal}(\\mu,\\sigma^2)$ can be obtained by sampling $z$ from the standard form of the distribution $\\text{Normal}(0, 1)$ and then transforming it using $g_{\\mu,\\sigma}(z) = \\mu + \\sigma z$. This two-stage reformulation of the sampling process, called the reparameterization trick, allows us to transfer the dependence on $\\phi$ from $p$ into $f$ by writing $f_\\theta(x) = f_\\theta(g_\\phi(z))$ for $x = g_\\phi(z)$, making it possible to reduce the problem of estimating the gradient w.r.t. parameters of a distribution to the simpler problem of estimating the gradient w.r.t. parameters of a deterministic function.\n\nHaving reparameterized $p_\\theta(x)$, we can now express the objective as an expectation w.r.t. $q(z)$\n\\begin{equation}\n   L(\\theta, \\phi) = \\mathbb{E}_{x \\sim p_\\phi(x)}[f_\\theta(x)] = \\mathbb{E}_{z \\sim q_\\phi(z)}[f_\\theta(g(z))]\n\\end{equation}\nAs $q(z)$ does not depend on $\\phi$, we can estimate the gradient w.r.t. $\\phi$ in exactly the same way we estimated the gradient w.r.t. $\\theta$.\n\n\n\\subsection{Gumbel-Softmax}\nIn the case of categorical variables, reparameterization trick cannot be applied directly. \\citet{maddison2016concrete, jang2016categorical} proposed Gumbel-Softmax (also known as Concrete distribution) to replace the non-differentiable samples from a categorical distribution with differentiable samples from a Gumbel-Softmax distribution.\n\nThe Gumbel-Softmax distribution is motivated from the Gumbel-Max trick. Consider an unnormalized parameterization $(\\alpha_1,...,\\alpha_n)$ where $\\alpha_k \\in (0,\\infty)$ of a discrete distribution $D \\sim \\text{Discrete}(\\alpha)$. We assume that states with 0 probability are excluded. The Gumbel-Max trick proceeds as follows: sample $u_k \\sim \\text{Uniform}(0, 1)$ i.i.d. for each $k$, find $k$ that maximizes ${\\log\\alpha_k -\\log(-\\log u_k)}$, set $D_k = 1$ and the remaining $D_i = 0$ for $i \\neq k$. Then\n\\begin{equation}\n    \\mathbb{P}(D_k = 1) = \\frac{\\alpha_k}{\\sum_{i=1}^{n}\\alpha_i}\n\\end{equation}\n\nIn other words, the sampling of a discrete random variable can be refactored into a deterministic  function---componentwise addition followed by $\\argmax$ of the parameters $\\log \\alpha_k$ and fixed distribution $-\\log(-\\log U_k)$. See Figure \\ref{fig:gm} for a visualization.\n\n\\begin{figure}[htbp]\n\\centering\n\\subfloat[Gumbel-Max.\\label{fig:gm}]\n    {\\includegraphics[width=0.46\\textwidth]{Gumbel_max.pdf}}\\hfill\n\\subfloat[Gumbel-Softmax.\\label{fig:gs}]\n    {\\includegraphics[width=0.46\\textwidth]{Gumbel_softmax.pdf}}\n    \\caption{From \\citet{maddison2016concrete}.}\n\\end{figure}\n\nThe $\\argmax$ computation returns states on the vertices of the simplex $\\Delta^{n-1} = \\{ x \\in \\mathbb{R}^n | x_k \\in [0, 1],\\sum_{k=1}^{n} x_k = 1 \\} $. Then the state of a discrete variable can be relaxed from the vertices into the interior where it is a random probability vector using Softmax. To sample a Gumbel-Softmax random variable $x \\in \\Delta^{n-1}$ at temperature $\\lambda \\in (0,\\infty)$ with parameters $\\alpha_k \\in (0,\\infty)$, sample $G_k \\sim \\text{Gumbel}$ i.i.d. and set\n\\begin{equation}\n\\label{Gumbel-Softmax}\n    x_k = \\frac{\\exp{((\\log \\alpha_k + G_k) / \\lambda})}{\\sum_{i=1}^{n} \\exp{((\\log \\alpha_k + G_k) / \\lambda})}\n\\end{equation}\n\nThe Gumbel-Softmax computation of Equation (\\ref{Gumbel-Softmax}) smoothly approaches the discrete $\\argmax$ computation as $\\lambda \\to 0$ while preserving the relative order of the Gumbels $\\log \\alpha_k + G_k$.\n\nWhile Gumbel-Softmax samples are differentiable, they are not identical to samples from the corresponding categorical distribution for non-zero temperature. For learning, there is a tradeoff between small temperatures, where samples are close to one-hot but the variance of the gradients is large, and large temperatures, where samples are smooth but the variance of the gradients is small. In practice, the temperature can be set high initially and is annealed to small but non-zero as the training proceeds. If $\\lambda$ is a learned parameter (rather than annealed via a fixed schedule), this scheme can be interpreted as entropy regularization , where the Gumbel-Softmax distribution can adaptively adjust the ``confidence'' of proposed samples during the training process.\n\nFor scenarios in which we are constrained to sampling discrete values, we discretize $x$ using $\\argmax$ in the forward pass but use the continuous approximation in the backward pass. It is called the Straight-Through (ST) Gumbel Estimator.\n\n\n\\section{Application on Variational Training of Categorical Latent Variable Models}\n\n\nHidden variable models assume that each observation $x$ is obtained by first sampling a vector of categorical latent variables $z$ and then generating the observation itself by sampling from $p_\\theta(x|z)$ or a deterministic decoder $f_\\theta(z)$. \\footnote{One can also model the joint distribution $p(x,z)$ directly if the factorization into $p(z)$ and $p(x|z)$ is infeasible, although this model  } \n\nThe data log likelihood can be written as \n\\begin{align}\n    \\begin{split}\n        L(\\theta) & = \\log \\mathbb{E}_{z \\sim p_\\theta(z)} [p_\\theta(x|z)] \\\\\n        & = \\log \\sum_z p_\\theta(x,z).\n    \\end{split}\n\\end{align}\nThis is typically intractable and does not fit into the previous SCG framework due to the expectation being inside the $\\log$. Alternatively, it is widely used to optimize evidence lower bound (ELBO) on data log likelihood\n\\begin{equation}\n    \\begin{split}\n        L(\\theta) & = \\log \\sum_z p_\\theta(x,z) \\\\\n        & = \\sum_z Q_\\phi(z|x) \\log \\frac{p_\\theta(x,z)}{Q_\\phi(z|x)} + KL[Q_\\phi(z|x), p(z|x)].\n    \\end{split}\n\\end{equation}\nThe ELBO can be written as \n\\begin{align}\n\\label{ELBO}\n    \\begin{split}\n        \\mathcal{L}(x, \\theta, \\phi) = & \\sum_z Q_\\phi(z|x) \\log \\frac{p_\\theta(x,z)}{Q_\\phi(z|x)} \\\\\n            & = \\mathbb{E}_{z \\sim Q_\\phi(z|x)} [\\log p_\\theta(x,z) - \\log Q_\\phi(z|x)].\n    \\end{split}\n\\end{align}\n\n\n\\subsection{Revisiting NVIL}\n\n\nNVIL proposed a baseline based variance reduction technique for neural variational inference on categorical variables. \n$\\log p_\\theta(x,z) - \\log Q_\\phi(z|x)$ in Equation (\\ref{ELBO}) can viewed as the learning signal from the perspective of reinforcement learning, especially policy gradient. \n\nIn SFE, the gradient of the parameters $\\phi$ can be estimated as\n\n\\begin{align}\n\\label{signal}\n    \\begin{split}\n        \\nabla_\\phi \\mathcal{L} & = \\nabla_\\phi \\sum_z  Q_\\phi(z|x) ( \\log p_\\theta(x,z) - \\log Q_\\phi(z|x) ) \\\\\n        & = \\sum_z \\log p_\\theta(x,z) \\nabla_\\phi Q_\\phi(z|x) - \\nabla_\\phi \\sum_z Q_\\phi(z|x) \\log Q_\\phi(z|x) \\\\\n        & = \\sum_z \\log p_\\theta(x,z) \\nabla_\\phi Q_\\phi(z|x) - \\sum_z ( \\log Q_\\phi(z|x) \\nabla_\\phi Q_\\phi(z|x) + \\nabla_\\phi Q_\\phi(z|x) ) \\\\\n        & = \\sum_z ( \\log p_\\theta(x,z) - \\log Q_\\phi(z|x) ) \\nabla_\\phi Q_\\phi(z|x) \\\\\n        & = \\sum_z ( \\log p_\\theta(x,z) - \\log Q_\\phi(z|x) ) Q_\\phi(z|x) \\nabla_\\phi \\log Q_\\phi(z|x)\\\\\n        & = \\mathbb{E}_{z \\sim Q_\\phi(z|x)} [(\\log p_\\theta(x,z) - \\log Q_\\phi(z|x))  \\nabla_\\phi \\log Q_\\phi(z|x)]\n    \\end{split}\n\\end{align}\n\nIt might be surprising that this learning signal will fit $Q_\\phi(z|x)$ to $p_\\theta(x,z)$ other than the true posterior $p(z|x)$.\n\nAnd since\n\\begin{align}\n    \\begin{split}\n        \\mathbb{E}_{z \\sim Q_\\phi(z|x)} \\nabla_\\phi \\log Q_\\phi(z|x) & = \\mathbb{E}_{z \\sim Q_\\phi(z|x)} \\frac{\\nabla_\\phi Q_\\phi(z|x)}{Q_\\phi(z|x)}\\\\\n        & = \\sum_z \\nabla_\\phi Q_\\phi(z|x) \\\\\n        & = \\nabla_\\phi \\sum_z  Q_\\phi(z|x) \\\\\n        & = 0 \n    \\end{split}\n\\end{align}\nwe can subtract any $c$ that does not depend on $z$ from the learning signal in Equation (\\ref{signal}).  However, $c$ will not be able capture the systematic differences in the learning signal for different observation $x$. Thus we can reduce the gradient variance further by subtracting an observation-dependent term $c_\\psi(x)$ to minimize those differences. Note that, doing this will not affect the expectation in Equation (\\ref{signal}), because $c_\\psi(x)$ is independent on $z$. $c_\\psi(x)$ can be implemented using a neural network and train it to minimize the expected square of the centered learning signal $\\mathbb{E}_{z \\sim Q_\\phi(z|x)} [(\\log p_\\theta(x,z) - \\log Q_\\phi(z|x) - c_\\psi(x) - c)^2]$.\n\nIn practice, using $\\log p_\\theta(x,z) - \\log Q_\\phi(z|x)$ as the learning signal is non-trivial as its average magnitude can change dramatically. NVIL addresses this issue by dividing the centered learning signal by a running estimate of its standard deviation in a mini-batch. This normalization ensures that the signal is approximately unit variance, and can be seen as a simple and efficient way of adapting the learning rate. To ensure that training will be stopped when the magnitude of the signal approaches zero, variance normalization will only be applied when the estimate of the standard deviation is greater than 1.\n\n\\bibliographystyle{abbrvnat}\n\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "e4b73eec38037dfae2e4ea90dd1e93803995a5bd", "size": 14442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Optimizing_Discrete_Units_in_Stochastic_Computation_Graphs.tex", "max_stars_repo_name": "yumoxu/INF3.34-GEAR", "max_stars_repo_head_hexsha": "b5fb3fd5e8393aff374ced73bdd9ed36ae02fbc5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-20T13:43:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-20T13:43:52.000Z", "max_issues_repo_path": "Optimizing_Discrete_Units_in_Stochastic_Computation_Graphs.tex", "max_issues_repo_name": "yumoxu/INF3.34-GEAR", "max_issues_repo_head_hexsha": "b5fb3fd5e8393aff374ced73bdd9ed36ae02fbc5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Optimizing_Discrete_Units_in_Stochastic_Computation_Graphs.tex", "max_forks_repo_name": "yumoxu/INF3.34-GEAR", "max_forks_repo_head_hexsha": "b5fb3fd5e8393aff374ced73bdd9ed36ae02fbc5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-09T14:50:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-09T14:50:32.000Z", "avg_line_length": 76.4126984127, "max_line_length": 816, "alphanum_fraction": 0.7167289849, "num_tokens": 4300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384735, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6307392680018692}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{Generating functions and counting problems}\n\\author{Dave Neary}\n\\date{October 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problem}\n\nHow many solutions are there to the equation $n = a + b + c + d$, where $a \\leq b \\leq c \\leq d$ and $a, b, c, d, n \\in \\mathbb{N}$?\n\n\\section{Solution}\n\nThe natural numbers $\\mathbb{N} = \\{1,2,3,\\cdots\\}$ — that is, the positive integers (not 0). It will be easier to work on this problem if our solutions are in the non-negative integer, including 0.\n\nWe can rewrite the equation as:\n\\[ x_1= a'+b'+c'+d' \\]\nwhere: $x_1=x-4, a'=a-1, b'=b-1, c' = c-1, d' = d-1$, and the inequality for $a,b,c,d$ still holds for $a',b',c',d'$.\n\nWe can go one step further, and remove this inequality, by focusing on the\ndifferences between the variables. Since we know that $a'\\leq b'\\leq c'\\leq d'$ we can rewrite \n$a_1 = a', b_1 = b' - a', c_1 = c' - b', d_1 = d' - c'$, and substituting these in to the equation, \nwe get:\n\n\\[ x_1= 4a_1 + 3b_1 + 2c_1 + d_1 \\]\n\nwhere each of $a_1,b_1,c_1,d_1 \\geq 0$.\n\nThere's a nice method of calculating this using generating functions. Consider:\n\n\\[P(x) = (1+x^4+x^8+\\cdots)(1+x^3+x^6+\\cdots)(1+x^2+x^4+\\cdots)(1+x+x^2+\\cdots)\\]\n\nThis expands to an infinite series:\n\\[P(x) = a_0 + a_1x + a_2x^2 + a_3x^3 + \\cdots\\]\n\nwhere each coefficient corresponds to the number of solutions for $x_1 = n, x = n+4$.\n\nTo get the coefficient in the expansion for $x^{12}$ for example, we need to look at all\nthe ways that you can combine multiples of 1,2,3, and 4 to add to 12. We can quickly find\nthat the possible solutions are:\n\n\\[(a_1,b_1,c_1,d_1) \\in \\{(3,0,0,0),(2,1,0,1),(2,0,2,0),(2,0,1,2),(2,0,0,4), \\cdots\\} \\]\n\nwhere the solution $(2,1,0,1)$ for example corresponds to taking an $x^8$ term from\n$(1+x^4+x^8+\\cdots)$, an $x^3$ from $(1+x^3+x^6+\\cdots)$, a 1 from $(1+x^2+x^4+\\cdots)$,\nand an $x$ from $(1+x+x^2+\\cdots)$.\n\nThen we can sum these geometric series to get:\n\n\\[P(x) = \\frac{1}{(1-x^4)(1-x^3)(1-x^2)(1-x)} \\]\n\nWe can use partial fraction decomposition on this to get a closed form for $a_n$.\n\nOur denominator can be factored:\n\\begin{align*}\n P(x) &= \\frac{1}{(1-x^4)(1-x^3)(1-x^2)(1-x)} \\\\\n      &= \\frac{1}{(1-x)^4(1+x)^2(1+x^2)(1+x+x^2)} \\\\\n      &= \\frac{1}{(1-x)^4(1+x)^2(1+ix)(1-ix)(1-\\omega x)(1 - \\omega^2 x)}\n\\end{align*}\n\nwhere $\\omega = \\frac{1}{2}(-1+\\sqrt{3}i)$, a primitive cube root of unity.\n\nThen we can write this as:\n\\begin{multline*}\n    P(x) = \\frac{A_1}{1 - x} + \\frac{A_2}{(1 - x)^2} + \\frac{A_3}{(1 - x)^3} + \\frac{A_4}{(1 - x)^4} \\\\\n    + \\frac{A_5}{1 + x} + \\frac{A_6}{(1 + x)^2} \\\\\n    + \\frac{A_7}{1 + ix} + \\frac{A_8}{1 - ix} + \\frac{A_9}{1 - \\omega x} + \\frac{A_{10}}{1 - \\omega^2 x}\n\\end{multline*}\n\nCalculating the $A_i$ values is tedious but straightforward using the Heaviside cover-up\nmethod. Clearing denominators, we get:\n\\begin{align*}\n\t1 &= A_1(1-x)^3(1+x)^2(1+x^2)(1+x+x^2) \\\\\n\t&+ A_2(1-x)^2(1+x)^2(1+x^2)(1+x+x^2) \\\\\n\t&+ A_3(1-x)(1+x)^2(1+x^2)(1+x+x^2) \\\\\n\t&+ A_4(1+x)^2(1+x^2)(1+x+x^2) \\\\\n    \t&+ A_5(1-x)^4(1+x)(1+x^2)(1+x+x^2) \\\\\n\t&+ A_6(1-x)^4(1+x^2)(1+x+x^2) \\\\\n   \t&+ A_7(1-x)^4(1+x)^2(1-ix)(1+x+x^2) \\\\\n\t&+ A_8(1-x)^4(1+x)^2(1+ix)(1+x+x^2) \\\\\n    \t&+ A_9(1-x)^4(1+x)^2(1+x^2)(1-\\omega^2 x) \\\\\n\t&+ A_{10}(1-x)^4(1+x)^2(1+x^2)(1 - \\omega x)\n\\end{align*}\n\nNow we can set $x$ to various values to isolate and calculate the coefficients (since the equation\nabove must hold for all values of $x$).\n\nSetting $x=1, x=-1, x=i, x=-i, x=\\omega^2, x=\\omega$ in order we get \n\\[\nA_4 = \\frac{1}{24}, A_6 = \\frac{1}{32}, A_7 = \\frac{1}{16}, A_8 = \\frac{1}{16}, A_9 = \\frac{1-\\omega}{27}, A_{10} = \\frac{1-\\omega^2}{27}\n\\]\n\nThen I set $x=2, -2, 0, 3$ respectively to get four simultaneous equations in $A_1, A_2, A_3, A_5$. When all is said and done, I get:\n\n\\begin{multline*}\n\tP(x) = \\frac{17}{72(1-x)} + \\frac{59}{288(1-x)^2} + \\frac{1}{8(1-x)^3} \\\\\n\t+ \\frac{1}{24(1-x)^4} + \\frac{1}{8(1+x)} + \\frac{1}{32(1+x)^2} + \\frac{1}{16(1-ix)} \\\\\n\t+ \\frac{1}{16(1+ix)} + \\frac{1-\\omega}{27(1-\\omega x)} + \\frac{1-\\omega^2}{27(1-\\omega^2 x)}\n\\end{multline*}\n\nAnd if I haven’t made a mistake, after turning each of these simple fractions into its own\ninfinite series as follows:\n\n\\begin{align*}\n\\frac{1}{1-x} &= 1 + x + x^2 + \\cdots \\\\\n\\frac{1}{(1-x)^2} &= 1 + 2x + 3x^2 + 4x^3 + \\cdots \\\\\n\\frac{1}{(1-x)^3} &= 1 + \\binom{3}{2}x + \\binom{4}{2}x^2 + \\binom{5}{2}x^3 + \\cdots \\\\\n\\frac{1}{(1-x)^4} &= 1 + \\binom{4}{3}x + \\binom{5}{3}x^2 + \\binom{6}{3}x^3 + \\cdots \\\\\n\\frac{1}{1+x} &= 1 - x + x^2 - \\cdots \\\\\n\\frac{1}{(1+x)^2} &= 1 - 2x + 3x^2 - 4x^3 + \\cdots \\\\\n\\frac{1}{1+ix} &= 1 + ix - x^2 - ix^3 + x^4 + \\cdots \\\\\n\\frac{1}{1-ix} &= 1 - ix - x^2 + ix^3 + x^4 - \\cdots \\\\\n\\frac{1}{1-\\omega^2 x} &= 1 + \\omega^2 x + \\omega x^2 + x^3 + \\omega^2 x^4 + \\omega x^5 + x^6 + \\cdots \\\\\n\\frac{1}{1-\\omega x} &= 1 + \\omega x + \\omega^2 x^2 + x^3 + \\omega x^4 + \\omega^2 x^5 + x^6 + \\cdots\n\\end{align*}\n\nAnd when we plug everything in, we get a coefficient for $a_n$ (reminder, this is the number of\nsolutions for partitions in four ordered natural numbers for $x=n+4$) of:\n\\begin{multline*}\na_n = \\frac{17}{72} + \\frac{59}{288}\\binom{n+1}{1} + \\frac{1}{8}\\binom{n+2}{2} + \\frac{1}{24}\\binom{n+3}{3} \\\\\n+ \\frac{1}{8}(-1)^n + \\frac{1}{32}\\binom{n+1}{1}(-1)^n + \\frac{1}{16}(i^n + (-i)^n) \\\\\n+ \\frac{1}{27}\\left(\\omega^{n} + \\omega^{2n} - \\omega^{n+1} - \\omega^{2n+2}\\right)\n\\end{multline*}\n\nThe $\\frac{1}{16}(i^n + (-i)^n)$ terms equal 0 for odd terms, $\\frac{1}{8}$ for terms\nwhere $n$ is divisible by 4, and $-\\frac{1}{8}$ for other even terms.\n\nSimilarly, the $\\frac{1}{27}\\left(\\omega^{n} + \\omega^{2n} - \\omega^{n+1} - \\omega^{2n+2}\\right)$\nterms equal zero, $-\\frac{1}{9}$, or $\\frac{1}{9}$, depending on whether $n$ has a remainder of\n0, 1, or 2 when divided by 3.\n\nLet’s check our closed form solution for $n=8$ - that is, for $x=12$. By inspection, we can see\nthat the solutions are:\n\n\\begin{multline*}\n(a_1,b_1,c_1,d_1) \\in \\{(2,0,0,0), (1,1,0,1), (1,0,2,0), (1,0,1,2),\\\\\n(1,0,0,4), (0,2,1,0), (0,2,0,2), (0,1,2,1),(0,1,1,3), (0,1,0,5),\\\\\n(0,0,4,0), (0,0,3,2), (0,0,2,4), (0,0,1,6), (0,0,0,8)\\}\n\\end{multline*}\n\nwhich gives 15 solutions. Again, the solution $(0,1,2,1)$ (for example) corresponds to\n$a_1 = 0, b_1=1, c_1=2, d_1=1$, which translates to $a'=0, b'=1, c'=3, d'=4$, or $a=1, b=2, c=4, d=5$.\n\nUsing our formula, we get:\n\\begin{multline*}\n\ta_8 = \\frac{17}{72} + \\frac{59}{288}\\binom{9}{1} + \\frac{1}{8}\\binom{10}{2} + \\frac{1}{24}\\binom{11}{3} \\\\\n\t+ \\frac{1}{8}(-1)^8 + \\frac{1}{32}\\binom{9}{1}(-1)^8 + \\frac{1}{16}(i^8 + (-i)^8) \\\\\n\t+ \\frac{1}{27}\\left(\\omega^{8} + \\omega^{16} - \\omega^{9} - \\omega^{18}\\right)\n\\end{multline*}\n\n\\[a_8 = \\frac{17}{72} + \\frac{59}{32} + \\frac{45}{8} + \\frac{55}{8} + \\frac{1}{8} + \\frac{9}{32} + \\frac{1}{8} - \\frac{1}{9} = 15 \\]\n\nIt’s pretty amazing that this complicated fractional expression including binomial\ncoefficients works, but it does!\n\nWe can also expand the binomial coefficients and simplify further to get the formula:\n\\begin{multline*}\n\ta_n = \\frac{1}{288}(2n^3 + 30n^2 + 133n + 175) + (-1)^n(\\frac{n+5}{32}) \\\\\n\t+ \\frac{1}{16}(i^n + (-i)^n) + \\frac{1}{27}\\left(\\omega^{n} + \\omega^{2n} - \\omega^{n+1} - \\omega^{2n+2}\\right)\n\\end{multline*}\nand we can notice that:\n\\[\n\t-\\frac{17}{72} \\leq\n\t\\frac{1}{16}(i^n + (-i)^n) + \\frac{1}{27}\\left(\\omega^{n} + \\omega^{2n} - \\omega^{n+1} - \\omega^{2n+2}\\right)\n\t\\leq \\frac{17}{72}\n\\]\n\nso we can take $a_n$ to be the positive integer closest to $\\frac{1}{288}(2n^3 + 30n^2 + 133n + 175) + (-1)^n(\\frac{n+5}{32})$\n\n\\[\n\ta_n = \n\t\\begin{cases}\n\t\t\\frac{1}{144} (n^3 + 15 n^2 + 62 n + 65) & x \\text{ odd} \\\\\n\t\t\\frac{1}{144} (n^3 + 15 n^2 + 71 n + 110) & x \\text{ even}\n\t\\end{cases}\n\\]\n\n\\section{Recurrence relation}\n\nIt is possible to calculate the number of partitions also using a recurrence relation. If we define:\n$P_k(n)$ to be the number of ordered partitions of the number $n$ into exactly $k$ non-zero partitions, we can deduce the following:\n\\begin{itemize}\n    \\item $P_0(0) = 1$ (by definition - similar to defining $0! = 1$, this ensures the recurrence relationship below terminates in all cases).\n    \\item $P_k(n) = 0$ if $k\\leq 0, n\\leq 0$ and $k,n$ are not both $0$.\n    \\item $P_k(n) = P_k(n-k) + P_{k-1}(n-1)$ - that is, we have a choice to increment the size of all partitions by 1 and leave $n-k$ items to distribute across exactly $k$ buckets, or we can fix one bucket, and we have $n-1$ items to distribute across the other $k-1$ buckets.\n\\end{itemize}\n\nWe can come up with some quick short-cuts for $P_k(n)$ for small values of $k$:\n\\begin{itemize}\n    \\item $P_1(n) = 1$ for all $n \\geq 0$ - that is, with exactly 1 partition, there is only one possible representation.\n    \\item $P_n(n) = 1$ is the transposed equivalent - with $n$ buckets and $n$ items, there is only one way to distribute the items so that no bucket is empty.\n    \\item $P_k(n) = 0$ if $k > 0, n< k$.\n    \\item $P_2(n) = \\lfloor \\frac{n}{2} \\rfloor$\n    \\item $P_3(n) = \\lfloor \\frac{n-1}{2} \\rfloor + \\lfloor \\frac{n-4}{2} \\rfloor + \\lfloor \\frac{n-7}{2} \\rfloor  + \\cdots $\n\\end{itemize}\n\nFrom this, we can reproduce the result above, albeit a little awkwardly:\n\\begin{align*}\n    P_4(12) &= P_4(8) + P_3(11) \\\\\n    &= P_4(4) + P_3(7) + P_3(8) + P_2(10) \\\\\n    &= 1 + \\lfloor \\frac{6}{2} \\rfloor + \\lfloor \\frac{3}{2} \\rfloor + \\lfloor \\frac{7}{2} \\rfloor + \\lfloor \\frac{4}{2} \\rfloor + \\lfloor \\frac{10}{2} \\rfloor \\\\\n    &= 1 + 3 + 1 + 3 + 2 + 5 = 15    \n\\end{align*}\n\nas before. I have not found any nice closed form solution to this recurrence relation, however, and the recurrence relation, while easy to calculate by computer, becomes very unwieldy when calculating by hand.\n\n\\end{document}\n", "meta": {"hexsha": "951c197dda794ad8389e07094679ae918a7ff7c0", "size": 9765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "generating_functions.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": "generating_functions.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": "generating_functions.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": 45.6308411215, "max_line_length": 277, "alphanum_fraction": 0.5953917051, "num_tokens": 4175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6307190480473972}}
{"text": "\\section{Tensor and Tor}\nOffice hours are: for Hood, today from 1:30 to 3:30 in 2-390, and for me on Tuesday from 1 to 3 in 2-478. Point-set topology is the hardest part of this course, sorry for messing up the question on this week's pset. I like to emphasize the algebraic part.\n\\subsection{Properties over $\\otimes_R$}\n\\begin{enumerate}\n\\setcounter{enumi}{5}\n\\item A ring is precisely specified by a map $R\\otimes_\\Z R\\xrightarrow{\\mu}R\\xleftarrow{\\eta}\\Z$. You can define a\nring purely diagrammatically. Associativity is commutativity of the following diagram:\n\\begin{equation*}\n\\xymatrix{R\\otimes R\\otimes R\\ar[r]^{\\mu\\otimes 1}\\ar[d]^{1\\otimes \\mu} & R\\otimes R\\ar[d]^{\\mu}\\\\\nR\\otimes R\\ar[r]^{\\mu} & R}\n\\end{equation*}\nThe identity map is commutativity of the following diagram.\n\\begin{equation*}\n\\xymatrix{\\Z\\otimes R\\ar[r]^{\\eta\\otimes 1}\\ar[dr]_{\\cong} & R\\otimes R\\ar[d]^{\\mu} & R\\otimes \\Z\\ar[l]^{1\\otimes\\eta}\\ar[dl]_{\\cong}\\\\\n& R & }\n\\end{equation*}\nIn fact, an $R$-module is an abelian group with a map $R\\otimes M\\xrightarrow{\\varphi}M$ such that the following diagram commutes.\n\\begin{equation*}\n\\xymatrix{R\\otimes R\\otimes M\\ar[r]^{\\mu\\otimes 1}\\ar[d]^{1\\otimes \\eta} & R\\otimes M\\ar[d]^{\\varphi}\\\\\nR\\otimes M\\ar[r]^{\\varphi} & R}\n\\end{equation*}\nIf $A$ is an abelian group, then $R\\otimes A$ is an $R$-module, where the multiplication is: $R\\otimes(R\\otimes A)\\to (R\\otimes R)\\otimes A\\xrightarrow{\\mu\\otimes 1}R\\otimes A$. If $A$ is an abelian group, then $A\\to R\\otimes A$ sending $a\\mapsto 1\\otimes a$ is universal for maps from $A$ to an $R$-module. We say that it's ``initial''. This means that if $M$ is an $R$-module, there is a factorization:\n\\begin{equation*}\n\\xymatrix{A\\ar[r]\\ar[d]^f & R\\otimes A\\ar@{-->}[dl]\\\\\nM}\n\\end{equation*}\nWhere the map $R\\otimes A\\to M$ is an $R$-module homomorphism and the map $A\\to M$ is an abelian group homomorphism. Why is this true? We have a map $R\\otimes A\\xrightarrow{1\\otimes f}R\\otimes M$, so the multiplication $\\varphi:R\\otimes M\\to M$ is what we want. I.e., the extension is the composition:\n\\begin{equation*}\n\\xymatrix{A\\ar[r]\\ar[d]_f & R\\otimes A\\ar[d]^{1\\otimes f}\\ar[dl]|{\\varphi\\circ(1\\otimes f)}\\\\\nM & R\\otimes M\\ar[l]^{\\varphi}}\n\\end{equation*}\n\\begin{example}\nWhat if we let $A=\\Z/n\\Z$? Then if $B$ is an abelian group (i.e., a $\\Z$-module), $B\\otimes \\Z/n\\Z\\cong B/nB$.\n\\end{example}\n\\item Consider $0\\to \\Z\\xrightarrow{2}\\Z\\to \\Z/2\\Z\\to 0$. Let's tensor with $\\Z/2\\Z$, to get $0\\to \\Z/2\\Z\\to\\Z/2\\Z\\to\\Z/2\\Z\\to 0$. This cannot be a sexseq! But it's clear that the surjection $\\Z\\to\\Z/2\\Z$ gives an isomorphism $\\Z/2\\Z\\to\\Z/2\\Z$, i.e., $0\\to \\Z/2\\Z\\xrightarrow{0}\\Z/2\\Z\\xrightarrow{\\cong}\\Z/2\\Z\\to 0$. This is one of the major tragedies, that tensoring isn't exact. Exact means preserves exact sequences. The moral is that tensoring isn't generally exact, but preserves cokernels. More precisely:\n\\begin{prop}\nThe functor $N\\otimes M\\otimes_R N$ preserves cokernels. What do I mean? This means that this functor is \\emph{right exact}, i.e., if $N^\\prime\\xrightarrow{i} N\\xrightarrow{p} N^{\\prime\\prime}\\to 0$ is exact, then so is $M\\otimes_R N^\\prime\\to M\\otimes_R N\\to M\\otimes_R N^{\\prime\\prime}\\to 0$.\n\\end{prop}\n\\begin{proof}\nWe have:\n\\begin{equation*}\n\\xymatrix{M\\otimes_R N^\\prime\\ar[r]^{1\\otimes i} & M\\otimes_R N\\ar[r]\\ar[d] & M\\otimes_R N^{\\prime\\prime}\\\\\n & M\\otimes_R N/(\\img(1\\otimes i))=M\\otimes_R N/I\\ar@{-->}[ur]_{\\overline{\\phi}}}\n\\end{equation*}\nAt least we know that the composite $M\\otimes_R N^\\prime\\to M\\otimes_R N\\to M\\otimes_R N^{\\prime\\prime}$ is zero. But this means that the dotted map exists, because the image $I$ has to be sent to zero. The claim is that $\\overline{\\phi}$ is an isomorphism. We can construct an inverse to $\\overline{\\phi}$. It's easy to construct maps \\emph{out} of tensor products. This inverse will be a map $M\\otimes_R N^{\\prime\\prime}\\xrightarrow{q}M\\otimes_R N/I$. How do we construct maps out of a tensor product? Consider:\n\\begin{equation*}\n\\xymatrix{M\\otimes_R N^{\\prime\\prime}\\ar@{-->}[r]^{\\overline{q}} & M\\otimes_R N/I\\\\\nM\\times N^{\\prime\\prime}\\ar[u]\\ar[ur]^q}\n\\end{equation*}\nWhere will $x\\otimes y$ be sent? Let's pick $\\overline{y}\\in N$ such that $p\\overline{y}=y$. I can do that because I supposed that $p$ was surjective in the first place. Maybe I'm using the axiom of choice. (By the way, if I had a split exact sequence, tensoring will preserve split exact sequences, but not general exact sequences.) Anyway, map $x\\otimes y\\mapsto x\\otimes\\overline{y}+I$. That's the only thing I can think of doing, and so we pray and hope that it works. Let's check that this is well-defined first.\n\nWe know that $\\overline{y}$ is only well-defined up to the image of something from $N^\\prime$. So consider $\\overline{y}^\\prime=\\overline{y}+iz$ for $z\\in N^\\prime$. These are the only possible lifts. Then we get $x\\otimes\\overline{y}^\\prime=x\\otimes(\\overline{y}+iz)+x\\otimes\\overline{y}+x\\otimes i(z)=x\\otimes\\overline{y}+(1\\otimes i)(x\\otimes z)\\in x\\otimes\\overline{y}+I$. Luckily, we divided out by $I$. There's \\emph{four} other things I have to check. I have to check that this is linear in each variable. This is just fussing around with the formula. Let's assume we've done that.\n\nPretty much by construction, $\\overline{q}$ is the inverse for $\\overline{p}$. This is because $p$ takes $x\\otimes\\overline{y}+I$ to $x\\otimes y$ because that's what $\\overline{p}$ does -- it just applies $p$ to the second factor. \n\\end{proof}\n\\end{enumerate}\nHow about this failure of exactness? What can we do about that? Failure of exactness is bad, so let's try to repair it.\n\nThink of a sexseq of chain complexes (that are bounded below by $0$ and are nonnegatively graded) $0\\to N^\\prime_\\bullet\\to N_\\bullet\\to N^{\\prime\\prime}_\\bullet\\to 0$. We get an exact sequence $ H_0 N^\\prime\\to H_0 N\\to H_0 N^\\prime\\prime\\to 0$. We already know that this isn't exact on the left because we have a lexseq in homology (because $ H_1 N^\\prime\\prime$ need not be trivial). Let's imagine $M\\otimes_R-$ as analogous to $ H_0$. We already have an example of a functor that is right exact but not left exact (namely $ H_0$), so this isn't unreasonable. I think I'll write down a theorem and finish the proof on Wednesday.\n\\begin{theorem}\nThere are functors $\\Tor^R_n(M,-):\\mathbf{Mod}_R\\to\\mathbf{Mod}_R$ for $n\\geq 0$, where I have a fixed ring $R$ and a fixed $R$-module $M$, and natural transformations sending a sexseq $0\\to N^\\prime\\to N\\to N^{\\prime\\prime}\\to 0$ to $\\partial:\\Tor^R_n(M,N^{\\prime\\prime})\\to \\Tor^R_{n-1}(M,N^\\prime)$ such that you get a lexseq:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & \\Tor^R_n(M,N)\\ar[r] & \\Tor^R_n(M,N^{\\prime\\prime})\\ar[dll]\\\\\n\\Tor^R_{n-1}(M,N^\\prime)\\ar[r] & \\Tor^R_{n-1}(M,N)\\ar[r] & \\cdots}\n\\end{equation*}\nsuch that $\\Tor^R_0(M,N)=M\\otimes_R N$. Basically, $\\Tor$ fulfills the same role as homology.\n\\end{theorem}\nSome properties are as follows.\n\\begin{itemize}\n\\item $\\Tor^R_q(M,N)=0$ for $q>1$ is $R$ is a PID.\n\\item $\\Tor^R_q(M,F)=0$ for $q>0$ if $F$ is a free $R$-module.\n\\end{itemize}\nLet's explore what this gives us before we construct it.\n\\begin{example}\nLet $R=\\Z$, and consider the sexseq $0\\to \\Z\\xrightarrow{n}\\Z\\to\\Z/n\\Z\\to 0$. Because $\\Z$ is free, you have:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & 0\\ar[r] & \\Tor^\\Z_n(C_\\bullet)(M,\\Z/n\\Z)\\ar[dll]\\\\\n\\Tor^\\Z_{0}(M,\\Z)=M\\otimes\\Z\\ar[r]^{\\times n} & \\Tor^\\Z_{0}(M,\\Z)=M\\otimes\\Z\\ar[r] & \\Tor^\\Z_0(M,\\Z/n\\Z)=M/nM\\ar[r] & 0}\n\\end{equation*}\nSo $\\Tor^\\Z_1(M,\\Z/n\\Z)=\\ker(M\\xrightarrow{n}M)$. This is the \\emph{$n$-torsion} of $M$. That's the origin of $\\Tor$. This is the key example to keep in mind. He said something like ``In general, $\\Tor$ isn't free, but it is here because $\\Z$ is a PID.''\n\\end{example}\nTake a general $R$-module $N$. You can always take a free module $F_0$ that surjects onto $N$, i.e., $F_0\\to N\\to 0$. For example, you can let $F_0$ be the free $R$-module on the underlying set of $N$. Form a sexseq $0\\to K_0\\to F_0\\to N\\to 0$. You have an exact sequence for $n>1$:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & 0\\ar[r] & \\Tor^R_n(M,N)\\ar[dll]\\\\\n\\Tor^R_{n-1}(M,K_0)\\ar[r] & 0\\ar[r] & \\cdots}\n\\end{equation*}\nSo for $n>1$, $\\Tor^R_n(M,N)\\to \\Tor^R_{n-1}(M,K_0)$ is an isomorphism. If $n=1$, then:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & 0\\ar[r] & \\Tor^R_1(M,N)\\ar[dll]\\\\\nM\\otimes_R K_0\\ar[r] & M\\otimes_R F_0\\ar[r] & M\\otimes_R N\\ar[r] & 0}\n\\end{equation*}\nThe maps between the tensors might be hard to compute, but you can compute this as a kernel.\n\nBut I've not constructed the functors yet. I just said to assume that it exists. This was so much fun, taking a free module and surjecting it onto $N$. What I'm trying to do is:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar@{-->}[rr] & & F_2\\ar[dr]\\ar@{-->}[rr]^d & & F_1\\ar[dr]\\ar@{-->}[rr]^d & & F_0\\ar[dr]\\\\\n& K_2\\ar[ur]\\ar[dr] & & K_1\\ar[ur]\\ar[dr] & & K_0\\ar[ur]\\ar[dr] & & N\\ar[dr]\\\\\n0\\ar[ur] & & 0\\ar[ur] & & 0\\ar[ur] & & 0\\ar[ur] & & 0}\n\\end{equation*}\nWhere $F_{i+1}$ surjects onto $K_i$ and the $F_i$ are free $R$-modules. Splicing these exact sequences gives you a exact sequence in the top row. This is what's called a \\emph{free resolution of $N$}. You can actually write this as:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & F_2\\ar[r] & F_1\\ar[r] & F_0\\ar[r]\\ar[d] & 0\\\\\n & & & N & }\n\\end{equation*}\nThe $F_0$ are generators of $N$, the $F_1$ are relations, the $F_2$ are relations between relations, and so on. We say that these are syzygies. The singular term is syzygy.\n", "meta": {"hexsha": "2c5e7688c0a6c55e122184efa8a8fa0e8d2c3e15", "size": 9481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-21-tensor-and-tor.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-21-tensor-and-tor.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-21-tensor-and-tor.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": 89.4433962264, "max_line_length": 631, "alphanum_fraction": 0.6875856977, "num_tokens": 3539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.6307190449867598}}
{"text": "\\documentclass[9pt,twocolumn]{extarticle}\n\n\\usepackage[hmargin=0.5in,tmargin=0.5in]{geometry}\n\\usepackage{amsmath,amssymb}\n\\usepackage{times}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\n\\usepackage{cleveref}\n\\usepackage{color}\n\\newcommand{\\TODO}[1]{\\textcolor{red}{#1}}\n\n\\newcommand{\\FPP}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand{\\argmin}{\\operatornamewithlimits{arg\\ min}}\n\\author{Siwang Li}\n\n\\title{Solve LCP with Extened MPRGP}\n\n%% document begin here\n\\begin{document}\n\\maketitle\n\n\\setlength{\\parskip}{0.5ex}\n\n\\section{LCP}\n\\begin{equation}\n  A x = b \\quad \\mbox{ s.t. } \\quad J x \\ge c\n\\end{equation}\n\n\\section{MPRGP Extension}\n\\subsection{Projection}\nThe projection process is to find an vector $y$ which satisfies the constraints while is cloest to the un-projected vector $x$:\n\\begin{equation}\n  P_{\\Omega}(x) = \\min_{y}\\frac{1}{2}\\|y-x\\|_2^2 \\quad \\mbox{ s.t. } \\quad J y \\ge c\n\\end{equation}\nConsidering its KKT condition, we have\n\\begin{equation}\n  y = x + J^T\\lambda  \\quad \\mbox{ s.t. } \\quad 0 \\le \\lambda \\perp J y \\ge c\n\\end{equation}\nWe can solve the following LCP sub problem to obtain $\\lambda$, \n\\begin{equation}\n   0 \\le \\lambda \\perp (JJ^T)\\lambda \\ge c - Jx\n\\end{equation}\n\\TODO{which is equal to solving (why?)}\n\\begin{equation}\n  (JJ^T)\\lambda=c - Jx \\quad \\mbox{s.t.} \\quad \\lambda \\ge 0\n\\end{equation}\nAs $J^TJ$ is a \\TODO{SPD matrix (why?)}, we can use traditional MPRGP solver to solve it. Further more, as $J$ is sparse and constant, we can use Incomplete Cholesky Factorization as a pre-conditioner. \\TODO{(But how to combine it with MPRGP?)}\n\n\\subsection{Step Limit}\nGiven a feasible point $x$ and a direction $p$, the step limit $\\alpha$ is a positive scalar which satisfies\n\\begin{equation}\n  J(x-\\alpha p) \\ge c\n\\end{equation}\nThus we can compute $\\alpha$ by using\n\\begin{equation} \n \\alpha = \\min_{\\alpha} \\alpha_i \n\\end{equation}\nwhere\n\\begin{equation}\n  \\alpha_i = \\left\\{\n  \\begin{array}{l l}\n    +\\infty & \\quad \\text{if $-J_ip \\ge 0$}\\\\\n    \\frac{J_ix-c_i}{J_ip} & \\quad \\text{if $-J_ip < 0$}\n  \\end{array} \\right  \n\\end{equation}\nHere, $J_i$ is the $i$-th row of matrix $J$.\n\n\\subsection{Free gradient}\nWe suppose the constraints active constraints is given by $\\hat{J}x = c$, then the free gradient $\\phi(x)$ is in the NULL space of $\\hat{J}$ and should be as close to the gradient $g = Ax-b$ as possible, and we further require $g^T\\phi \\ge \\epsilon$ to ensure $-\\phi$ is a decrease direction:\n\\begin{equation}\n  \\phi = \\min_\\phi \\frac{1}{2} \\|\\phi - g\\|_2^2  \\quad \\mbox{ s.t. } \\quad g^T\\phi \\ge 0, \\quad \\hat{J} \\phi = 0\n\\end{equation}\nThe KKT condition for this problem is\n\\begin{equation}\n  \\phi = g + g\\lambda_1 + \\hat{J}^T \\lambda_2 \\quad \\mbox{ s.t. } \\quad \\epsilon \\le \\lambda_1 \\perp g^T\\phi = 0, \\quad \\hat{J}\\phi = 0\n\\end{equation}\nwe can obtain $\\lambda$ by solving\n\\begin{equation}\\label{}\n  \\left\\{ \\begin{array}{rl}\n    g^Tg \\lambda_1 + (\\hat{J}g)^T\\lambda_2 = -g^Tg+\\epsilon, \\quad \\mbox{s.t.} \\quad \\lambda_1 \\ge 0\\\\\n    (\\hat{J}g)\\lambda_1+(\\hat{J}\\hat{J}^T) \\lambda_2 = -\\hat{J}g\n  \\end{array} \\right.\n\\end{equation}\nLet $\\xi$ be the solution of\n\\begin{equation}\n  (\\hat{J}\\hat{J}^T) \\xi = -\\hat{J}g\n\\end{equation}\nThen we have $\\lambda_2 = (1+\\lambda_1)\\xi$, and we can obtain $\\lambda_1$ through\n\\begin{equation}\n  \\lambda_1 = \\max(0,\\frac{\\epsilon}{\\sigma} - 1)\n\\end{equation}\nwhere $\\sigma = g^Tg-(Jg)^T\\xi$.\n\nAs $\\hat{J}\\hat{J}^T$ is a SPD matrix, we can use Conjugate Gradient method to solve this problem. However, as $\\hat{J}^T\\hat{J}$ is not constant, we need a more cheap preconditioner rather than Incomplete Cholesky Factorization, such as $SOR$ preconditioner. (\\TODO{Any more efficient method?})\n\n\\subsection{Chopped gradient}\nThe chopped gradient $\\beta(x)$ should be as close to the gradient $g$ as possible, and it is required that $x-\\alpha \\beta$ should always satisfies the constraints for any $\\alpha > 0$. Thus we compute $\\phi(x)$ by solving\n\\begin{equation}\n  \\beta = \\min_\\beta \\frac{1}{2} \\|\\beta - g_\\beta\\|_2^2  \\quad \\mbox{ s.t. } \\quad -\\hat{J} \\beta \\ge 0\n\\end{equation}\nwhere $g_\\beta = g-\\phi$. The KKT condition of this problem is\n\\begin{equation}\n  \\beta = g_\\beta - \\hat{J}^T\\lambda  \\quad \\mbox{ s.t. } \\quad 0 \\le \\lambda \\perp -\\hat{J} \\beta \\ge 0\n\\end{equation}\nBy replacing $\\beta$ with $\\lambda$ in the constraints, we obtain\n\\begin{equation}\n  \\hat{J}\\hat{J}^T\\lambda = \\hat{J}g_\\beta \\quad \\mbox{s.t.} \\quad \\lambda \\ge 0\n\\end{equation}\nAs $\\hat{J}^T\\hat{J}$ is a \\TODO{SPD matrix (why?)}, we can use traditional MPRGP solver to solve for $\\lambda$, and \\TODO{use SOR as preconditioner}.\n\n\\subsection{Precondition}\nWe suppose the preconditioning matrix is $M = LL^T$, then we convert the original LCP problem into\n\\begin{equation}\n  \\tilde{A} \\tilde{x} = \\tilde{b} \\quad {s.t.} \\quad \\tilde{J}\\tilde{x} \\ge c\n\\end{equation}\nwhere $\\tilde{A} = L^{-1}AL^{-T}$, $\\tilde{b} = L^{-1}b$, $\\tilde{x} = L^{T}x$ and $\\tilde{J} = JL^{-T}$. The corresponding free gradient is obtained by solving\n\\begin{equation}\n  \\tilde{\\phi} = \\tilde{g} + \\hat{\\tilde{J}}^T\\lambda \\quad {s.t.} \\quad \\hat{\\tilde{J}}\\tilde{\\phi} = 0\n\\end{equation}\ne.g.\n\\begin{equation}\n  \\tilde{\\phi} = L^{-1}g + L^{-1}\\hat{J}^T\\lambda \\quad {s.t.} \\quad \\hat{J}L^{-T}\\tilde{\\phi} = 0\n\\end{equation}\nThus we can solve the following equation for $\\lambda$\n\\begin{equation}\n  (\\hat{J}M^{-1}\\hat{J}^T)\\lambda = -\\hat{J}M^{-1}g\n\\end{equation}\nThen the pesudoresidual for PCG is \n\\begin{equation}\n  z = L^{-T}\\tilde{\\phi} = M^{-1}(g + \\hat{J}^T\\lambda)\n\\end{equation}\nIf $J = I$, we have \n\\begin{equation}\n  z = M^{-1} \\phi\n\\end{equation}\n\n%% references\n% \\begin{thebibliography}{99}\n% \\bibitem{sig2011} Fast simulation of skeleton-driven deformable body\n%   characters.\n% \\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "797ae8a3a7d076bd9d6ce143477c2f5bac7e1110", "size": 5781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/MPRGP_LCP.tex", "max_stars_repo_name": "simba518/MPRGPSolver", "max_stars_repo_head_hexsha": "4e86d5af462eb6ca4e98397af8984239b5e5c844", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-07-20T21:09:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T02:48:58.000Z", "max_issues_repo_path": "doc/MPRGP_LCP.tex", "max_issues_repo_name": "simba518/MPRGPSolver", "max_issues_repo_head_hexsha": "4e86d5af462eb6ca4e98397af8984239b5e5c844", "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/MPRGP_LCP.tex", "max_forks_repo_name": "simba518/MPRGPSolver", "max_forks_repo_head_hexsha": "4e86d5af462eb6ca4e98397af8984239b5e5c844", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-10-10T06:03:44.000Z", "max_forks_repo_forks_event_max_datetime": "2015-10-10T06:03:44.000Z", "avg_line_length": 39.8689655172, "max_line_length": 295, "alphanum_fraction": 0.6730669434, "num_tokens": 2152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6307190403481624}}
{"text": "\\section{Principal bundles, associated bundles}\n\\subsection{$I$-invariance}\nWe will denote by $\\Vect(B)$ the set of isomorphism classes of vector bundles\nover $B$. (Justify the use of the word ``set''!)\n\nConsider a vector bundle $\\xi\\downarrow B$. If $f:B^\\prime\\to B$, taking the\npullback gives a vector bundle denoted $f^\\ast\\xi$. This operation descends to\na map $f^\\ast:\\Vect(B)\\to \\Vect(B^\\prime)$; we therefore obtain a functor\n$\\Vect:\\Top^{op}\\to \\Set$. One might expect this functor to give some\ninteresting invariants of topological spaces.\n%\\begin{warning}\n%    In order to say anything meaningful about vector bundles, you've to assume\n%    that the vector bundles are numerable. If $B$ is paracompact (eg a\n%    CW-complex), this is automatic.\n%\\end{warning}\n\\begin{theorem}\\label{Iinvariance}\n    Let $I = \\Delta^1$. Then $\\Vect$ is $I$-invariant. In other words, the\n    projection $X\\times I\\to X$ induces an isomorphism $\\Vect(X)\\to\n    \\Vect(X\\times I)$.\n\\end{theorem}\nOne important corollary of this result is:\n\\begin{corollary}\n    $\\Vect$ is a homotopy functor.\n\\end{corollary}\n\\begin{proof}\n    Consider two homotopic maps $f,g:B\\to B^\\prime$, so there exists a homotopy\n    $H:B^\\prime\\times I\\to B$. If $\\xi\\downarrow B$, we need to prove that\n    $f^\\ast_0\\xi\\simeq f_1^\\ast\\xi$. This is far from obvious.\n\n    Consider the following diagram.\n    \\begin{equation*}\n\t\\xymatrix{\n\t    B^\\prime\\times I\\ar[r]^H\\ar[d]_{\\pr} & B\\\\\n\t    B^\\prime & \n\t    }\n    \\end{equation*}\n    The leftmost map is an isomorphism under $\\Vect$, by Theorem\n    \\ref{Iinvariance}. Let $\\eta\\downarrow B$ be a vector bundle such that\n    $\\pr^\\ast\\eta \\simeq f^\\ast\\xi$. For any $t\\in I$, define a map\n    $\\in_t:B^\\prime\\to B^\\prime\\times I$ sends $x\\mapsto(x,t)$. We then have\n    isomorphisms:\n    $$f_t^\\ast\\xi \\simeq \\in_t^\\ast f^\\ast\\xi \\simeq \\in_t^\\ast \\pr^\\ast\\eta\n    \\simeq (\\pr\\circ \\in_t)^\\ast\\eta \\simeq \\eta,$$\n    as desired.\n\\end{proof}\nIt is easy to see that $\\Vect(X)\\to \\Vect(X\\times I)$ is injective. In the next\nlecture, we will prove surjectivity, allowing us to conclude Theorem\n\\ref{Iinvariance}.\n\\subsection{Principal bundles}\n%There's a famous video of J.-P.~Serre talking about mathematics. He says you have to know the difference between ``principle'' and ``principal''. He contemplated ``bundles of principles'' (like politics, or society, or something).\n\\begin{definition}\\label{principaldefn}\n    Let $G$ be a topological group\\footnote{We will only care about discrete\n    groups and Lie groups.}. A \\emph{principal $G$-bundle} is a right action of\n    $G$ on $P$ such that:\n    \\begin{itemize}\n\t\\item $G$ acts freely.\n\t\\item The orbit projection $P\\to P/G$ is a fiber bundle.\n    \\end{itemize}\n\\end{definition}\nThese are not unfamiliar objects, as the next example shows.\n\\begin{example}\\label{principalcovering}\n    Suppose $G$ is discrete. Then the fibers of the orbit projection $P\\to P/G$\n    are all discrete. Therefore, the condition that $P\\to P/G$ is a fiber\n    bundle is simply that it's a covering projection (the action is ``properly\n    discontinuous'').\n\n    As a special case, let $X$ be a space with universal cover\n    $\\widetilde{X}\\downarrow X$. Then $\\pi_1(X)$ acts freely on\n    $\\widetilde{X}$, and $\\widetilde{X}\\downarrow X$ is the orbit projection.\n    It follows from our discussion above that this is a principal bundle.\n    Explicit examples include the principal $\\Z/2$-bundle\n    $S^{n-1}\\downarrow\\RP^{n-1}$, and the Hopf fibration $S^{2n-1}\\downarrow\n    \\CP^{n-1}$, whcih is a principle $S^1$-bundle.\n\\end{example}\nBy looking at the universal cover, we can classify covering spaces of $X$.\nRemember how that goes: if $F$ is a set with left $\\pi_1(X)$-action, the dotted\nmap in the diagram below is the desired covering space.\n\\begin{equation*}\n    \\xymatrix{\n\t\\widetilde{X}\\times F\\ar[r]\\ar[d]_{p\\circ \\pr_1} & \\widetilde{X}\\times\n\tF/\\sim\\ar[dl]^q\\\\\n\tX & \n    }\n\\end{equation*}\nHere, we say that $(y,gz)\\sim (yg,z)$, for elements $y\\in\\widetilde{X}$, $z\\in\nF$, and $g\\in\\pi_1(X)$.\n\nFix $y_0\\in\\widetilde{X}$ over $\\ast\\in X$. Then it is easy to see that\n$F\\xrightarrow{\\sim}q^{-1}(\\ast)$, via the map $z\\mapsto (y_0,z)$. This is all\nneatly summarized in the following theorem from point-set topology.\n\\begin{theorem}[Covering space theory]\n    There is an equivalence of categories:\n    $$\\{\\text{Left $\\pi_1(X)$-sets}\\}\\xrightarrow{\\simeq}\\{\\text{Covering\n    spaces of }X\\},$$\n    with inverse functor given by taking the fiber over the basepoint and\n    lifting a loop in $X$ to get a map from the fiber to itself.\n\\end{theorem}\nExample \\ref{principalcovering} shows that covering spaces are special examples\nof principal bundles. The above theorem therefore motivates finding a more\ngeneral picture.\n\\begin{construction}\n    Let $P\\downarrow B$ is a principal $G$-bundle. If $F$ is a left $G$-space,\n    we can define a new fiber bundle, exactly as above:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    P\\times F\\ar[r]\\ar[d] & P\\times F/\\sim\\ar[dl]^q\\\\\n\t    B & \n\t    }\n    \\end{equation*}\n    This is called an \\emph{associated bundle}, and is denoted $P\\times_G F$.\n\\end{construction}\nWe must still justify that the resulting space over $B$ is indeed a new fiber\nbundle with fiber $F$. Let $x\\in B$, and let $y\\in P$ over $x$. As above, we\nhave a map $F\\to q^{-1}(\\ast)$ via the map $z\\mapsto[y,z]$. We claim that this\nis a homeomorphism. Indeed, define a map $q^{-1}(\\ast)\\to F$ via\n$$[y^\\prime,z^\\prime]=[y,gz^\\prime]\\mapsto gz^\\prime,$$\nwhere $y^\\prime = yg$ for some $g$ (which is necessarily unique).\n\\begin{exercise}\n    Check that these two maps are inverse homeomorphisms.\n\\end{exercise}\n\\begin{definition}\n    A vector bundle $\\xi\\downarrow B$ is said to be an $n$-plane bundle if the\n    dimensions of all the fibers are $n$.\n\\end{definition}\nLet $\\xi\\downarrow B$ be an $n$-plane bundle. Construct a principal\n$\\GL_n(\\RR)$-bundle $P(\\xi)$ by defining\n$$P(\\xi)_b = \\{\\text{bases for }E(\\xi)_b = \\mathrm{Iso}(\\RR^n, E(\\xi)_b)\\}.$$\nTo define the topology, note that (topologically) we have\n$$P(B\\times \\RR^n) = B\\times \\mathrm{Iso}(\\RR^n,\\RR^n),$$\nwhere $\\mathrm{Iso}(\\RR^n,\\RR^n) = \\GL_n(\\RR)$ is given the usual topology as a\nsubspace of $\\RR^{n^2}$.\n\nThere is a right action of $\\GL_n(\\RR)$ on $P(\\xi)\\downarrow B$, given by\nprecomposition. It is easy to see that this action is free and simply\ntransitive. One therefore has a {principal action} of $\\GL_n(\\RR)$ on $P(\\xi)$.\nThe bundle $P(\\xi)$ is called the \\emph{principalization} of $\\xi$. \n\nGiven the principalization $P(\\xi)$, we can recover the total space $E(\\xi)$.\nConsider the associated bundle $P(\\xi)\\times_{\\GL_n(\\RR)}\\RR^n$ with fiber $F =\n\\RR^n$, with $\\GL_n(\\RR)$ acting on $\\RR^n$ from the left. Because this is a\nlinear action, $P(\\xi)\\times_{\\GL_n(\\RR)}\\RR^n$ is a vector bundle. One can\nshow that\n$$P(\\xi)\\times_{\\GL_n(\\RR)}\\RR^n\\simeq E(\\xi).$$\n\nFix a topological group $G$. Define $\\Bun_G(B)$ as the set of isomorphism\nclasses of $G$-bundles over $B$. An isomorphism is a $G$-equivariant\nhomeomorphism over the base. Again, arguing as above, this begets a functor\n$\\Bun_G:\\Top\\to\\Set$. The above discussion gives a natural isomorphism of\nfunctors:\n$$\\Bun_{\\GL_n(\\RR)}(B) \\simeq \\Vect(B).$$\nThe $I$-invariance theorem will therefore follow immediately from:\n\\begin{theorem}\n    $\\Bun_G$ is $I$-invariant.\n\\end{theorem}\n\\begin{remark}\n    Principal bundles allow a description of ``geometric structures on $\\xi$''.\n    Suppose, for instance, that we have a metric on $\\xi$. Instead of looking\n    at all ordered bases, we can attempt to understand all ordered orthonormal\n    bases in each fiber. This give the \\emph{frame bundle}\n    $$\\mathrm{Fr}(B) = \\{\\text{ordered orthonormal bases of }E(\\xi)_b\\};$$\n    these are isometric isomorphisms $\\RR^n\\to E(\\xi)_b$. Again, there is an\n    action of the orthogonal group on $\\mathrm{Fr}(B)$: in fact, this begets a\n    principal $O(n)$-bundle. Such examples are in abundance: consistent\n    orientations give an $SO(n)$-bundle. Trivializations of the vector bundle\n    also give principal bundles. This is called ``reduction of the structure\n    group''.\n\\end{remark}\n% This wasn't proven in the lectures, but is extremely important.\nOne useful fact about principal $G$-bundles (which should not be too\nsurprising) is the following statement.\n\\begin{theorem}\\label{morphismiso}\n    Every morphism of principal $G$-bundles is an isomorphism.\n\\end{theorem}\n\\begin{proof}\n    Let $p:P\\to B$ and $p^\\prime:P^\\prime\\to B$ be two principal $G$-bundles\n    over $B$, and let $f:P\\to P^\\prime$ be a morphism of principal $G$-bundles.\n    For surjectivity of $f$, let $y\\in P^\\prime$. Consider $x\\in P$ such that\n    $p(x) = p^\\prime(y)$. Since $p(x) = p^\\prime f(x)$ we conclude that $y =\n    f(x)g$ for some $g\\in G$. But $f(x)g = f(xg)$, so $xg$ maps to $y$, as\n    desired.  To see that $f$ is injective, suppose $f(x) = f(y)$. Now $p(x) =\n    p^\\prime f(x) = p(y)$, so there is some $g\\in G$ such that $xg = y$. But\n    $f(y) = f(xg) = f(x)g$, so $g=1$, as desired.  We will leave the continuity\n    of $f^{-1}$ as an exercise to the reader.\n\\end{proof}\nTheorem \\ref{morphismiso} says that if we view $\\Bun_G(B)$ as a category where\nthe morphisms are given by morphisms of principal $G$-bundles, then it is a\ngroupoid.\n", "meta": {"hexsha": "7c376b2c3e530536bda5d9b1b1367c3e86d7e01c", "size": 9306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-53-principal-bundles.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-53-principal-bundles.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-53-principal-bundles.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": 49.5, "max_line_length": 231, "alphanum_fraction": 0.6856866538, "num_tokens": 2968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6307190388019632}}
{"text": "\\subsection{Practice Problems}\n\\begin{enumerate}\n\\item If we think back to the ideal gas law, a term that we could add to make it more general (applicable to non-ideal gases) is to add a term correcting for molecular interactions. Doing so, we get the equation:\n\\begin{equation}\n    \\label{eqn:(33)}\n    \\left(P+a\\frac{n^2}{V^2}\\right)V = nRT\n\\end{equation}  \nwhere $a\\frac{n^2}{V^2}$ is the interaction term. Note that if we also add an $-nb$ term to the volume to account for the size of the molecules, we end up with the very general Van der Waals equation:\n\\begin{equation}\n    \\left(P+a \\frac{n^{2}}{V^{2}}\\right)\\left(V-n b\\right)=n R T\n\\end{equation}\nBut for the purposes of this question, let's assume $b=0$ to make our lives easier.\n\\begin{enumerate}\n    \\item Manipulate the equation \\ref{eqn:(33)} to obtain pressure as a function of temperature, volume, and amount of gas.\n    \\item Suppose that I isothermally compress the gas given in equation \\ref{eqn:(33)} from $V_1$ to $V_2$. How much work do I do on the gas?\n\\end{enumerate}\n\n\\item For each of the 4 (8) processes of isochoric heating, isochoric cooling, isobaric expansion, isobaric compression, isothermal expansion, isothermal compression, adiabatic expansion, and adiabatic compression, consider:\n    \\begin{enumerate}\n        \\item Is work done on/done by the gas, or is it zero?\n        \\item Does heat flow into or out of the gas, or is it zero?\n        \\item Does the temperature of the gas increase, decrease, or stay the same?\n    \\end{enumerate}\n\\item Consider the following heat engine, composed of 10 moles of monoatomic gas, below:\n\\begin{center}\n    \\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=bottom,\n        axis y line=left,\n        xmin=0, xmax=10,\n        ymin=0, ymax=10,\n%        % (made labels more common)\n%        % (because of the \"sketch\" type of the plot these should not be needed)\n%        xlabel={Volume $(\\mathrm{m}^3)$},\n%        ylabel={Pressure (Pa)},\n        % (changed ticks + labels to normal ticks instead of extra ticks)\n        xtick={3,6},\n        xticklabels={$2$,$4$},\n        ytick={1.5,6},\n        yticklabels={$5$,$15$},  % <-- (changed order of entries)\n    ]\n        % fill the area below the curve\n        % (draw it first, so it is below everything else)\n\n\n        % draw the dashed lines\n        % (using two different approaches)\n        \\addplot [dashed,domain=0:3,samples=2] {6};\n        \\addplot [dashed,domain=0:3,samples=2] {1.5};\n\n        \\draw [dashed,thin] (axis cs:6,1.5) -- (axis cs:6,0);\n        \\draw [dashed,thin] (axis cs:3,1.5)   -- (axis cs:3,0);\n\n        % now draw the curve\n        \\draw [\n            fleche={0.55:black}              % <-- added\n        ] (axis cs:3,6) to\n            % store start and end coordinates\n            coordinate [pos=1] (start)\n            coordinate [pos=0] (end)\n        (axis cs:6,1.5);\n        \\draw[fleche={0.55:black}] (axis cs:6,1.5) to (axis cs:3,1.5);\n        \\draw[fleche={0.5:black}] (axis cs:3,1.5) to (axis cs:3,6);\n\n        % draw start and end point\n        \\fill [radius=2pt]\n            (start) circle[]\n            (end)   circle[];\n        \\filldraw[fill=black] (axis cs: 3,1.5) circle (2pt);\n    \\end{axis}\n        \\node[below] at (6.5,0) {$V (m^3)$};\n        \\node[left] at (0,5.5) {$P (kPa)$};\n        \\node[above] at (2.05,3.5) {$3$};\n        \\node[right] at (4.25,0.9) {$1$};\n        \\node[left] at (2.1,1.15) {$2$};\n\\end{tikzpicture}\n\\end{center}\n\\begin{enumerate}\n    \\item What is the net change in the internal energy of the heat engine after one cycle?\n    \\item What is the work done by the heat engine in one cycle? (in kiloJoules... note that $1\\textrm{Pa}*1\\textrm{m}^3 = 1\\textrm{J}$)\n    \\item What is the net heat flow of the heat engine in one cycle? (in kiloJoules)\n    \\item Solve for the temperature (in Kelvin) at each of the three points.\n    \\item For each step, determine the work done by the engine, and how much heat flows into/out of the engine. \n\\end{enumerate}\n\\item Consider the following heat engine, composed of monoatomic gas. Treat the process $3 \\rightarrow 1$ as isothermal.\n\\begin{center}\n    \\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=bottom,\n        axis y line=left,\n        xmin=0, xmax=10,\n        ymin=0, ymax=10,\n%        % (made labels more common)\n%        % (because of the \"sketch\" type of the plot these should not be needed)\n%        xlabel={Volume $(\\mathrm{m}^3)$},\n%        ylabel={Pressure (Pa)},\n        % (changed ticks + labels to normal ticks instead of extra ticks)\n        xtick={3,6},\n        xticklabels={$V_0/2$,$V_0$},\n        ytick={1.5},\n        yticklabels={$P_0$},  % <-- (changed order of entries)\n    ]\n        % fill the area below the curve\n        % (draw it first, so it is below everything else)\n\n\n        % draw the dashed lines\n        % (using two different approaches)\n        \\addplot [dashed,domain=0:3,samples=2] {1.5};\n\n        \\draw [dashed,thin] (axis cs:6,1.5) -- (axis cs:6,0);\n        \\draw [dashed,thin] (axis cs:3,1.5)   -- (axis cs:3,0);\n\n        % now draw the curve\n        \\draw [\n            fleche={0.55:black}              % <-- added\n        ] (axis cs:3,6) to [bend right = 30]\n            % store start and end coordinates\n            coordinate [pos=1] (start)\n            coordinate [pos=0] (end)\n        (axis cs:6,1.5);\n        \\draw[fleche={0.55:black}] (axis cs:6,1.5) to (axis cs:3,1.5);\n        \\draw[fleche={0.5:black}] (axis cs:3,1.5) to (axis cs:3,6);\n\n        % draw start and end point\n        \\fill [radius=2pt]\n            (start) circle[]\n            (end)   circle[];\n        \\filldraw[fill=black] (axis cs: 3,1.5) circle (2pt);\n    \\end{axis}\n        \\node[below] at (6.5,0) {$V$};\n        \\node[left] at (0,5.5) {$P$};\n        \\node[above] at (2.05,3.5) {$3$};\n        \\node[right] at (4.25,0.9) {$1$};\n        \\node[left] at (2.1,1.15) {$2$};\n\\end{tikzpicture}\n\\begin{enumerate}\n    \\item What is the ratio of the temperatures between point $3$ and point $1$?\n    \\item Solve for the pressure at point $3$ in terms of $P_0$ and $V_0$\n    \\item Mark the highest temperature $T_H$ and the lowest temperature $T_C$ on the graph. \n    \\item Solve for the efficiency of the heat engine. Your answer should not depend on $P_0$, $V_0$, or the amount of gas in the heat engine. (Note: Solving for the efficiency is quite a bit more difficult than the other parts; a partial solution of the work and heat done during certain steps would be a good partial solution.)\n\\end{enumerate}\n\\end{center}\n\\item Question 4 again, except this time treat process $3 \\rightarrow 1$ as adiabatic (Note that part (d) is \\textit{quite} difficult).\n\\item Use what you know of adiabatic and isothermal processes to finish deriving the Carnot efficiency.\n\n\\end{enumerate}", "meta": {"hexsha": "dbf319fa218838a5314635d50e08e4b895988a00", "size": 6783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/questions.tex", "max_stars_repo_name": "RioWeil/SCIE001-thermo-notes", "max_stars_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "OneLaw/questions.tex", "max_issues_repo_name": "RioWeil/SCIE001-thermo-notes", "max_issues_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OneLaw/questions.tex", "max_forks_repo_name": "RioWeil/SCIE001-thermo-notes", "max_forks_repo_head_hexsha": "8578248f8f79f5704319dc6cd4ec679ce12b949c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-30T05:36:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-30T05:36:50.000Z", "avg_line_length": 46.1428571429, "max_line_length": 329, "alphanum_fraction": 0.6125608138, "num_tokens": 2091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.6307190311344891}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\setlength\\parindent{0pt}\n\\thispagestyle{empty}\n\n\\begin{document}\n\n\\setcounter{secnumdepth}{0}\n\\section{Back Propagation}\n\n$w_{ji}^l$ Weight from the i neuron in the l-1 layer to the j neuron in the l layer. \\\\\n$b_j^l$ Bias from the j neuron in the l layer. \\\\\n\n$a_j^l$ Activation from the j neuron in the l layer. \\\\\n$a_j^l = \\sum_{i} w_{ji}^l a_i^{l-1} + b_j^l = \\sigma(z_j^l)$ \\\\\n$a^l = w^l a^{l-1} + b^l = \\sigma(z^l)$ \\\\\n\n\nCost function : $C = \\frac{1}{2n} \\sum_{i} (target_i - a_i^L)^2$ \\\\\nCost function derivative : $\\frac{\\partial C}{\\partial a_i^L} = (a_i^L - target_i)$ \\\\\n\n\n$\\frac{\\partial C}{\\partial w}$ and $\\frac{\\partial C}{\\partial b}$ represent how quickly Cost function changes with respect to weight w and bias b. Back Propagation is to relate $\\delta^l_i$ to $\\frac{\\partial C}{\\partial w}$ and $\\frac{\\partial C}{\\partial b}$. \\\\\n\n$delta^l_i$ Error in the i neuron in the l layer. \\\\\n\nBP1 : $\\delta _i^L = \\frac{\\partial C}{\\partial a_i^L} \\sigma'(z_i^L) = (a_i^L - target_i) \\sigma'(z_i^L)$ \\\\\nMatrix : $\\delta ^L = \\nabla _a C \\odot \\sigma'(z^L) = (a^L - target) \\odot \\sigma'(z^L)$ \\\\\n\nBP2 : $\\delta _i^l = \\frac{\\partial C}{\\partial z_i^l} = \\sum_{j} \\frac{\\partial C}{\\partial z_j^{l+1}} \\frac{\\partial z_j^{l+1}}{\\partial z_i^l} = \\sum_{j} \\delta _j^{l+1} \\frac{\\partial z_j^{l+1}}{\\partial z_i^l} = \\sum_{j} \\delta _j^{l+1} w_{ji}^{l+1} \\sigma '(z_i^l)$ \\\\\n$( \\frac{\\partial z_j^{l+1}}{\\partial z_i^l} = w_{ji}^{l+1} \\sigma '(z_j^l) )$ \\\\\n\nBP1 compute the error in L layer, then apply BP2 to compute the layers back through. \\\\\n\n\nBP3 : $\\frac{\\partial C}{\\partial b_i^l} = \\delta _i^l$ \\\\\nMatrix : $\\frac{\\partial C}{\\partial b} = \\delta$ \\\\\n\nBP4 : $\\frac{\\partial C}{\\partial w_{ji}^l} = a_i^{l-1} \\delta _j^l$ \\\\\nMatrix : $\\frac{\\partial C}{\\partial w} = a_{in} \\delta _{out}$ \\\\\n$a_{in}$ is the activation of the neuron input to the weight, and $\\delta _{out}$ is the error of the neuron output from the weight. \\\\\n\n\nupdate weights according to $w^l = w^l - \\frac{\\partial C}{\\partial w_i_j^l}$. \\\\\nupdate biases according to $b^l = b^l - \\frac{\\partial C}{\\partial b_i^l}$. \\\\\n\n\\end{document}\n", "meta": {"hexsha": "6d30732e5cd7a08b967ded40dd4056b16da1ac2f", "size": 2164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro/backPropagationProof.tex", "max_stars_repo_name": "hmeng22/NNNotes", "max_stars_repo_head_hexsha": "444e6da2b7c962476714126be516727c2a75cb1f", "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": "intro/backPropagationProof.tex", "max_issues_repo_name": "hmeng22/NNNotes", "max_issues_repo_head_hexsha": "444e6da2b7c962476714126be516727c2a75cb1f", "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": "intro/backPropagationProof.tex", "max_forks_repo_name": "hmeng22/NNNotes", "max_forks_repo_head_hexsha": "444e6da2b7c962476714126be516727c2a75cb1f", "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": 46.0425531915, "max_line_length": 274, "alphanum_fraction": 0.6303142329, "num_tokens": 811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6306579158284669}}
{"text": "%\\documentclass{article}\n%\\usepackage[utf8]{inputenc}\n%\\usepackage{amsmath}\n\n%\\title{Toda Lattice, Role of $N$ and $y_k$}\n%\\author{Lusa Zhan}\n%\\date{November 2016}\n\n%\\begin{document}\n\n%\\maketitle\n\n\\subsubsection{Role of $N$}\nThe choice of $N = \\text{diag} (n, n-1, \\dots, 1)$ for analog sorting is clarified by Theorem 1.5 in~\\cite{helmke}. To summarize, the theorem states the following: \n\nFor each $N$,  $\\dot{H}(t) = [H,[H,N]]$ converges to an equilibrium $H_\\infty$ as $t\\rightarrow \\infty$. If $N=\\text{diag} (\\mu_1 , \\dots , \\mu_n)$ where $\\mu_1 > \\dots > \\mu_n$, then the Hessian of $f_N(H) = \\frac{1}{2}\\|N-H\\|^2$ is nonsingular and negative definite. \n\nThe linearization of the double bracket flow at an equilibrium point $H_\\infty = \\text{diag}(\\lambda_{\\pi(1)},\\dots,\\lambda_{\\pi(n)})$ is \n\\[\\dot \\xi_{ij} = -(\\lambda_{\\pi(i)}-\\lambda_{\\pi(j)})(\\mu_i-\\mu_j)\\xi_{ij}\\]\nwhere $\\xi = [H_\\infty, N]$. Since the Hessian is negative definite, $\\xi$ must be at its maximum. If $N = \\text{diag} (n, n-1, \\dots, 1)$, then $\\xi$ will only reach its maximum if the diagonal entries of $H_\\infty$ are sorted in descending order as well.\n\nThus the diagonal matrix $N$ determines the order of the diagonal entries in $H_\\infty$. Letting $N = \\text{diag}(n, ,n-1, \\dots, 1)$, we will result in $x_1 \\geq x_2 \\geq \\cdots \\geq x_n$ in $H_\\infty$.\n\n\\subsubsection{Role of off-diagonals $y_k$}\nThe choice of initial values for the off-diagonal $y_k$ values affects the results of analog sorting as well. \n\nFirst of all, as mentioned previously, $y_0=y_n=0$.\nTo analyze the initial values of $y_k$, consider the relation to $\\dot x_k$\n\\begin{align*}\n    \\dot{x_k} &=  2y^2_k-2y^2_{k-1} \\\\\n    \\dot{y_k} &= y_k(x_{k+1}-x_k) \n\\end{align*}\n\nIf $y_k=0$, then $\\dot x_k=0$, meaning $x_k(t) = x_k(0)$ for all $t$. This means that the values along the diagonal of $H$ will remain constant and never get sorted. So, $y_k$ should be non-zero.\n\nIn addition, the $y_k$ values should be small (but still positive). Recall that the eigenvalues will be the values along the diagonal of $H$ as $t\\rightarrow \\infty$. Consider the determinant $f_n = \\det (H-\\lambda I)$, where $n$ is the size of the matrix. Since $H$ is a tridiagonal matrix, this determinant can be formulated using a recurrence relation on the size of the matrix $n$.\n\n\\begin{align*}\nf_n &= (x_n-\\lambda)f_{n-1}-y_{n-1}^2f_{n-2} \\\\\nf_1 &= x_1-\\lambda\n\\end{align*}\n\nWe can use this to calculate the first few $f_n$ and set them to $0$ (what we would do to calculate the eigenvalues):\n\\begin{align*}\nf_1 &= x_1-\\lambda = 0\\\\\nf_2 &= (x_2-\\lambda)(x_1-\\lambda)-y_1^2 = 0\\\\\nf_3 &= (x_3-\\lambda)(x_2-\\lambda)(x_1-\\lambda)-(x_3-\\lambda)y_1^2-(x_1-\\lambda)y^2_2 = 0\n\\end{align*}\n\nIntuitively, the eigenvalues will be closest to $x_k$ if the $y_k$ values are smaller. When setting up the analog sorter, we want the off-diagonals to be nonzero, but small enough to not significantly change the values to be sorted. \n\n\n\n%\\section{Related work}\n%Below is a list of articles that are related to this topic: \n%\\begin{itemize}\n\n%\\item{\n%    Brockett, R.w. ``Dynamical Systems That Sort Lists, Diagonalize Matrices, and Solve Linear Programming Problems.'' Linear Algebra and Its Applications 146 (1991): 79-91. }\n%\\item{\n%    Helmke, Uwe, and John B. Moore. ``Double Bracket Isospectral Flows.'' Optimization and Dynamical Systems. London: Springer-Verlag, 1994. 43-80. Print.}\n%\\end{itemize}\n\n\n%\\end{document}\n", "meta": {"hexsha": "d18a291fba1de4e2e87766e8b9069befaef3f3e3", "size": 3440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/TodaYN.tex", "max_stars_repo_name": "yipenghuang0302/sorting", "max_stars_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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": "reports/TodaYN.tex", "max_issues_repo_name": "yipenghuang0302/sorting", "max_issues_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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": "reports/TodaYN.tex", "max_forks_repo_name": "yipenghuang0302/sorting", "max_forks_repo_head_hexsha": "7181d83d331e4f0f5df5961843e5e98c6ad0566e", "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": 52.1212121212, "max_line_length": 385, "alphanum_fraction": 0.6938953488, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177517, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.6306008419181156}}
{"text": "\\section{Noetherian Rings}\r\nWe have seen in the proof of PID implying UFD that PIDs has the ascending chain condition:\r\n\\begin{definition}\r\n    A ring $R$ is said to satisfy the ascending chain condition (ACC) if any ascending chain of ideals $I_1\\subset I_2\\subset\\cdots$ eventually terminates.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    A ring $R$ satisfies ACC iff all ideals $I\\in R$ are finitely generated.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A ring $R$ is called Noetherian if it satisfies ACC.\r\n\\end{definition}\r\n\\begin{theorem}[Hilbert's Basis Theorem]\r\n    If $R$ is Noetherian, then $R[X]$ is also Noetherian.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Start with an ideal $J\\unlhd R[X]$.\r\n    Pick $f_1\\in J$ with minimal degree.\r\n    If $J=(f_1)$, we are done.\r\n    Otherwise we can pick $f_2\\in J\\setminus (f_1)$ with minimal degree.\r\n    Continuing this, if $J$ is not finitely generated, then there is a nested sequence\r\n    $$(f_1)\\subsetneq (f_1,f_2)\\subsetneq\\cdots, \\deg f_1\\le\\deg f_2\\le\\cdots$$\r\n    Let $a_i$ be the leading coefficient of $f_i$, then consider a chain of ideals $(a_1)\\subset (a_1,a_2)\\subset\\cdots$.\r\n    $R$ is Noetherian, so this sequence must eventually terminates, so in particular there is some $m\\in\\mathbb N$ such that $a_{m+1}\\in(a_1,\\ldots,a_m)$.\r\n    So $a_{m+1}=\\lambda_1a_1+\\cdots+\\lambda_ma_m$.\r\n    Now consider\r\n    $$g(X)=\\sum_{i=1}^m\\lambda_iX^{\\deg f_{m+1}-\\deg f_i}f_i$$\r\n    So $g,f_{m+1}$ has the same degree and leading coefficient, so $\\deg (f_{m+1}-g)<\\deg f_{m+1}$.\r\n    But $f_{m+1}-g\\in J$, so since we chose $f_{m+1}$ to have the minimal degree in $J\\setminus(f_1,\\ldots,f_m)$, $f_{m+1}-g\\in (f_1.\\ldots,f_m)$, so $f_{m+1}\\in (f_1,\\ldots,f_m)$, contradiction.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $R[X_1,\\ldots,X_n]$ is Noetherian whenever $R$ is.\r\n\\end{corollary}\r\nIn particular, $\\mathbb Z[X_1,\\ldots,X_n],\\mathbb F[X_1,\\ldots,X_n]$ are Noetherian (where $\\mathbb F$ is a field).\r\n\\begin{proof}\r\n    Apply the preceding theorem recursively.\r\n\\end{proof}\r\n\\begin{example}\r\n    Let $R=\\mathbb C[X_1,\\ldots,X_n]$.\r\n    Let $V\\subset\\mathbb C^n$ be of the form\r\n    $$V(\\mathcal F)=\\{(a_1,\\ldots,a_n)\\in\\mathbb C^n:f(a_1,\\ldots,a_n)=0,\\forall f\\in\\mathcal F\\}$$\r\n    for some (possibly infinite) subset $\\mathcal F\\subset R$.\r\n    Let\r\n    $$I=\\left\\{\\sum_{i=1}^m\\lambda_if_i:m\\in\\mathbb N,\\lambda_i\\in R,f_i\\in\\mathcal F\\right\\}$$\r\n    Then $I\\unlhd R$ and $V(I)=V(\\mathcal F)$, but $R$ is Noetherian by the preceding corollary, so $I$ is finitely generated and thus $V(\\mathcal F)$ can be defined by only finitely many polynomials.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Any quotient ring of a Noetherian ring is again Noetherian.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $R$ is Noetherian and $I\\unlhd R$ is an ideal.\r\n    Consider a chain of ideals $J_1\\subset J_2\\subset\\cdots$ in $R/I$.\r\n    But we know the correspondence between the ideals in $R/I$ and the ideals of $R$ containing $I$, so there are ideals $I_1,I_2,\\ldots$ all containing $I$ with $J_i=I_i/I$.\r\n    But then $I_1\\subset I_2\\subset\\ldots$, so there is $N\\in\\mathbb N$ such that for any $m>N$, $I_m=I_N$, hence $J_m=I_m/I=I_N/I=J_N$, hence the sequence eventually terminates, thus $R/I$ is Noetherian.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The Gaussian integers can be written as $\\mathbb Z[i]\\cong\\mathbb Z[X]/(X^2+1)$ hence is Noetherian.\\\\\r\n    2. If $R[X]$ is Noetherian, then $R$ is Noetherian since $R\\cong R[X]/(X)$, so Hilbert's Basis Theorem is actually an ``if and only if''.\r\n\\end{example}\r\n\\begin{example}[Non-example]\r\n    We shall give examples of a non-Noetherian rings.\\\\\r\n    1. We consider the ring as the upper limit\r\n    $$R=\\mathbb Z[X_1,X_2,\\ldots]=\\bigcup_{n\\in\\mathbb N}\\mathbb Z[X_1,\\ldots,X_n]$$\r\n    Then $(X_1)\\subsetneq (X_1,X_2)\\subsetneq\\cdots$, so $R$ is not Noetherian.\\\\\r\n    2. Consider the ring $R\\le \\mathbb Q[X]$ by collecting $R=\\{f\\in\\mathbb Q[X]:f(0)\\in\\mathbb Z\\}$, then $R$ is obviously a ring with\r\n    $$(X)\\subsetneq (2^{-1}X)\\subsetneq (2^{-2}X)\\subsetneq\\cdots$$\r\n    3. Consider the ring $R$ of infinitely differentiable functions $[-1,1]\\to\\mathbb R$ under pointwise operations, this is also not Noetherian (exercise).\r\n\\end{example}\r\n", "meta": {"hexsha": "459c411695ee2c92d31b638cf4a96cd020627930", "size": 4250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/noether.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": "13/noether.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": "13/noether.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": 59.8591549296, "max_line_length": 205, "alphanum_fraction": 0.6743529412, "num_tokens": 1512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.630600831000808}}
{"text": "\\section{Preliminaries}\n\n\\subsection{The Probabilistic Model}\n\nWe are given a sequence $\\cbr{x_t = (c_t, \\mu_t)}_{t=1}^l$, where at each position $t$, $c_t \\in \\cbr{0,1,\\ldots,N}$ is called the coverage and $\\mu_t \\in \\cbr{0,1,\\ldots,c_t}$ is called the methylation count. We model the data using a binomial hidden Markov model, that is, there are underlying hidden states $h_t$ in $[m]$ generating the observations $x_t$. In addition, The dynamics of $h_t$'s is modeled by a Markov chain. Each hidden state $h \\in [m]$ is associated with a methylation probability $p_h \\in [0,1]$.\nIn our model, $c_t$'s' are not modeled probablistically  but are observed and measure how hard it is to sample from location $t$ in the genome.\nGiven $c_t$ and $h_t$, $\\mu_t$ is drawn from a binomial distribution, with the mean parameter $p = p_{h_t}$.\nFormally,\n\\[ \\mu_t | c_t, h_t \\sim \\bin(c_t, p_{h_t}) \\]\n\nTo summarize, the binomial HMM model can be represented by parameters $(\\pi, T, p)$, where $\\pi \\in \\R^m$ is the initial probability distribution (that is, $\\pi_i = \\P(h_1 = i)$), $T \\in \\R^{m \\times m}$ is the transition matrix of the Markov chain (that is, $T_{i,j} = \\P(h_{t+1} = i | h_t = j)$), and $p \\in \\R^m$ is the methylation probability vector (that is, given $h_t = i$ and $c_t$, $\\mu_t$ is drawn from $\\bin(c_t, p_i)$).\n\n\\subsection{Matrix and Tensor Notations}\nA $3$-dimensional array $T \\in \\R^{n_1 \\times n_2 \\times n_3}$ is called a 3rd-order tensor, and we use $T_{i_1, i_2, i_3}$ to denote its $(i_1, i_2, i_3)$-th entry. The tensor product of vectors $v_i$, $i = 1, 2, 3$ is denoted by $v_1 \\otimes v_2 \\otimes v_3$, where its\n$(i_1, i_2, i_3)$-th entry is $(v_1)_{i_1} (v_2)_{i_2} (v_3)_{i_3}$. We say a tensor has rank $1$ if it can be\nwritten as a tensor product of vectors. A tensor $T$ is called symmetric if $T_{i_1, i_2, i_3} = T_{\\pi(i_1), \\pi(i_2), \\pi(i_3)}$ for any permutation $\\pi: \\cbr{1,2,3} \\to \\cbr{1,2,3}$.\n\nWe define tensor-matrix multiplication as follows. Given tensor $T \\in \\R^{n_1 \\times n_2 \\times n_3}$ and matrices $V_i \\in \\R^{n_i \\times m_i}$, $i = 1,2,3$, $T(V_1, V_2, V_3)$ is a tensor of size $m_1 \\times m_2 \\times m_3$, whose $(i_1, i_2, i_3)$-th entry is computed by the formula $T(V_1, V_2, V_3)_{i_1, i_2, i_3} = \\sum_{j_1, j_2, j_3} T_{j_1, j_2, j_3} (V_1)_{j_1,i_1} (V_2)_{j_2, i_2} (V_3)_{j_3,i_3}$.\n\n\n\\subsection{Basic Spectral Method for Categorical HMMs}\n\\cite{AGHKT12} proposes a spectral algorithm for parameter recovery for hidden Markov models. Its main idea is to reduce the learning problem to tensor decompositon, which is well-studied in the numerical linear algebra literature. First, the algorithm construct a co-occurence tensor for thee consecutive observations. Then, it make a series of transformations over the tensor to make it symmetric and orthogonal. Finally, it applies tensor power method to recover the columns of the observation matrix.\n\nIn the setting of~\\cite{AGHKT12}, HMMs with categorical observations are considered. In this model, the hidden states $h_t$ are still drawn from a Markov chain, whereas given the hidden state $h_t$ in $[m]$, the observation $x_t$ is drawn from a categorical distribution on $[n]$ represented by $O_{h_t}$, where $O$ is a matrix in $\\R^{n \\times m}$.\nNote that the model is not the same as our binomial HMM, and hence the results of~\\cite{AGHKT12} does not directly apply to our setting. Nevertheless, as we show in Section 3, they can be adapted to our setting after a few novel modifications. We give a brief step-by-step overview of~\\cite{AGHKT12}'s algorithm, abbreviated as \\TD.\n\n\\paragraph{Step 1: Construct Matrices and Tensors.} In the hidden Markov model, for any $t$, observations $(x_{t-1}, x_t, x_{t+1})$ are conditionally independent given the hidden state $h_t$. We compute\n$P_{i,j} := \\E[x_i \\otimes x_j]$~\\footnote{Since we only have a finite sample, in practice, expecations are replaced by empirical averages over the data.} (where $i,j$ are distinct elements from $\\cbr{1,2,3}$~\\footnote{Although only the first three observations are used, the algorithm can be generalized to use all three consecutive observations in the sequences.}) and $T := \\E[x_1 \\otimes x_2 \\otimes x_3]$. If we use matrix $C_l$ to denote a matrix where $(C_l)_{i,j} = \\E[x_l = i | h_2 = j] \\in \\R^{n \\times m}$ for $l \\in \\cbr{1,2,3}$, and use vector $w \\in \\R^m$ to denote a vector where $w_i = \\P[h_2 = i]$,\nthen we can represent matrices $P_{i,j}$ and the tensor $T$ as follows:\n\\begin{equation}\n  P_{i,j} = C_i \\diag(w) C_j^T = \\sum_{l=1}^m w_l (C_i)_l \\otimes (C_j)_l\n  \\label{eqn:pij}\n\\end{equation}\nand\n\\begin{equation}\n  T = \\sum_{l=1}^m w_l (C_1)_l \\otimes (C_2)_l \\otimes (C_3)_l\n  \\label{eqn:t}\n\\end{equation}\n\n\\paragraph{Step 2: Symmetrization.} Observe that the tensor $T$ is neither symmetric nor\northogonal. We will symmetrize $T$ as follows.\nCompute symmetrization matrices $S_1 := P_{2,3} P_{1,3}^\\dagger$ and $S_3 := P_{2,1} P_{3,1}^\\dagger$. It can be shown that $S_1 = C_2 C_1^\\dagger$, and\n$S_3 = C_2 C_3^\\dagger$. Now we compute a trilinear transformation of $T$ using $S_1$ and $S_3$:\n\\[ G := T(S_1, I, S_3) = \\sum_{l=1}^m w_l (C_2)_l \\otimes (C_2)_l \\otimes (C_2)_l = \\sum_{l=1}^m w_l (C_2)_l^{\\otimes 3} \\]\nObserve that $G$ is a symmetric tensor.\n\n\\paragraph{Step 3: Orthogonalization.} To orthogonalize $G$, we compute matrix $M := S_3 P_{3,2}$. It can be shown that $M = \\sum_{l=1}^m w_l (C_2)_l \\otimes (C_2)_l$.\nNow, compute an SVD and take the top $m$ singular vectors $U_m$, and singular values in diagnoal matrix $S_m$, getting orthogonalization matrix $W = U_m S_m^{-1/2}$. It can be seen that $W^T M W = I$, that is, $v_l = W^T (C_2)_l w_l^{\\frac 1 2}$ are orthogonal unit vectors.\nNow we perform a trilinear transformation over $G$ using $M$, getting tensor $H = G(M, M, M) = \\sum_{l=1}^m w_l^{-\\frac 1 2} v_l^{\\otimes 3}$.\nThis form is called a {\\em symmetric orthogonal} decomposition, because $H$ is symmetric and $v_l$'s are orthogonal.\n\n\\paragraph{Step 4: Tensor Power Method.} The next step is to perform symmetric orthogonal decomposition to tensor $H$, to recover the vector $v_l$'s.\nStarting with a random vector $v_0$, we perform tensor power iteration $v_{t+1} = H(v_t, v_t, I)$ until $\\cbr{v_t}$ converges. After extracting a component $v_l$, a deflation step is performed, where we subtract the extracted rank-1 component ($H_l \\gets H_{l-1} - \\hat{w}_l \\hat{v}_l \\otimes \\hat{v}_l \\otimes \\hat{v}_l$), and the algorithm recurses on the remaining tensor $H_l$. The detailed procedure is presented in Algorithm~\\ref{alg:tpm}.\n\n\\begin{algorithm}\n\\caption{Tensor Power Method}\n\\begin{algorithmic}\n\\STATE input: tensor $H = \\sum_{l=1}^m \\lambda_l v_l \\otimes v_l \\otimes v_l$, number of components $m$, number of iterations per component $k$.\n\\STATE output: estimated factors $\\cbr{\\hat{v}_l}_{l=1}^m$, estimated coefficients $\\cbr{\\hat{w}_l}_{l=1}^m$.\n\\STATE $T_0 \\gets T$\n\\FOR{$l=1,2,\\ldots,m$}\n    \\STATE $v_l^0 \\gets$ a vector drawn uniformly at random from $n$-dimensional unit sphere.\n    \\FOR{$t=1,2,\\ldots,k$}\n        \\STATE $\\tilde{v}_l^t \\gets \\frac{H_{l-1}(v_l^{t-1}, v_l^{t-1}, I)}{\\|H_{l-1}(v_l^{t-1}, v_l^{t-1}, I)\\|}$.\n    \\ENDFOR\n    \\STATE $\\hat{v}_l \\gets v_l^k$.\n    \\STATE $\\hat{\\lambda}_l \\gets H_{l-1}(\\hat{v}_l, \\hat{v}_l, \\hat{v}_l)$.\n    \\STATE Deflation: $H_l \\gets H_{l-1} - \\hat{\\lambda}_l \\hat{v}_l \\otimes \\hat{v}_l \\otimes \\hat{v}_l$.\n\\ENDFOR\n\\end{algorithmic}\n\\label{alg:tpm}\n\\end{algorithm}\n\n\\paragraph{Step 5: Observation Matrix Recovery.} Recall that $C_2$ is the observation matrix $O$.\nThe columns of $O$ can now be estimated by formula $\\hat{O}_l = (W^T)^{\\dagger} \\hat\\lambda_l \\hat{v}_l$, for $l=1,2,\\ldots,m$. %We remark that as the order of columns can be arbitrary, we cannot hope to recover matrix $C_2$ with correct column permutations.\nNow we compute our estimate of the joint probablity of $h_2$ and $h_1$: $H_{21}:=\\hat{O}^{T\\dagger} P_21 \\hat{O}^\\dagger$. Then we compute our estimate of initial probability and trasition matrix by $\\hat\\pi := (\\one^T H_{21}^T$ and $\\hat{T} := H_21 \\diag(\\hat \\pi)^{-1}$.\n\nThe above algorithm has two advantages over other algorithms such as EM: First, it only needs to make one pass over the data, and is thus computationally efficient if the size of the observation space is not too large. In contrast, EM proceeds iteratively and needs to make one pass over the data per iteration. Second, it achieves statistical consistency if the data is indeed generated from an HMM (see Theorem 1). In contrast, methods such as EM do not guarantee statistical consistency.\n\n\\begin{theorem}[Statistical Consistency~\\cite{AGHKT12}]\nSuppose the algorithm receives $m$ iid samples $(x_1, x_2, x_3)$ as input, which are drawn from the hidden Markov model represented by parameters $(\\pi, T, O)$. Then, given parameters $\\epsilon$ and $\\delta$ in $(0,1)$, if the number of samples $m$ is at least $\\poly( \\frac{1}{\\min_i \\pi_i}, \\frac{1}{\\sigma_\\mi(O)}, \\frac{1}{\\sigma_\\mi(T)}, \\frac{1}{\\epsilon}, \\ln \\frac{1}{\\delta})$,\nthen with probability $1-\\delta$, the output $\\hat{O}$, $\\hat{T}$ and $\\hat{\\pi}$ satisfies that\n\\[ \\| O - \\hat{O} \\Pi \\|_F \\leq \\epsilon \\]\n\\[ \\| T - \\Pi^\\dagger \\hat{T} \\Pi \\|_F \\leq \\epsilon \\]\n\\[ \\| \\pi - \\Pi^\\dagger \\hat  \\pi \\|_2 \\leq \\epsilon \\]\nfor some permutation matrix $\\Pi$, where $\\sigma_\\mi(M)$ is the minimum singular value of matrix $M$.\n\\end{theorem}\n", "meta": {"hexsha": "2e18bb743b618af57b25bea62118c46748a4c11f", "size": 9413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kernelbin/paper/prelim.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/prelim.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/prelim.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": 106.9659090909, "max_line_length": 615, "alphanum_fraction": 0.6983958355, "num_tokens": 3268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6306008096792984}}
{"text": "\\section{Methods for intractable Gibbs distr.}\n\n% Problem: How to sample from $p(c) = \\frac{1}{\\textcolor{red}{Z}} f(c)$?\n\n% ===\n\\subsection{Sampling and SA}\n\n\\textit{Well behaving} \\emph{Markov Chains} are\n\\begin{itemize}\n    \\item \\textbf{irreducible:} can go from/to any state, and\n    \\item \\textbf{aperiodic:} doesn't go ``back\\&forth'' forever.\n\\end{itemize}\n\n$\\implies$ \\textbf{Stationary dist.} \\highlight{$p(c') = \\sum_c \\pi(c\\mid c') p(c)$}\n\n$\\iff$ \\textbf{det. balance} \\highlight*{$\\pi(c'\\mid c) p(c) = \\pi(c\\mid c') p(c')$}\n\n\\emph{Metropolis-Hastings:}\nAssume $p(c) \\propto f(c)$.\n\n$\\pi(c'\\mid c) \\coloneqq\n\\begin{cases}\n    q(c'\\mid c) \\: A(c,c') & c\\neq c'\\\\\n    1 - \\sum_{c'\\neq c} q(c'\\mid c) \\: A(c,c') & \\text{otw.}\n\\end{cases}$\n\nwhere\\enskip\n$q(c'\\mid c) :$ prob. to propose the move $c \\to c'$,\\\\\nand\\enskip\n$A(c,c') \\coloneqq \\min\\brace*{ 1, \\frac{q(c\\mid c') \\: f(c') \\: / \\: \\cancel{Z}}{q(c'\\mid c) \\: f(c) \\: / \\: \\cancel{Z}} }$ prob. accept move\n\n\\emph{Metropolis Algorithm:}\\enspace\nAssume $p(c) \\propto f(c)$ and $q(c'\\mid c) = q(c\\mid c')$, i.e. symmetric.\n\n\\begin{highlightbox}\n\\begin{enumerate}\n    \\item Define symmetric $\\brace{ q(\\cdot\\mid c) }_{c\\in\\mathcal C}$ s.t. graph $G_q$ is connected and every vertex in $G_q$ has edge to itself.\n    \\item $c_0 \\leftarrow \\$$\n        \\qquad Then, for $t=1,2,\\ldots$, do:\n    \\begin{itemize}\n        \\item $\\tilde c \\leftarrow q(\\cdot\\mid c_{t-1})$ \\quad // sample\n        \\item $b \\leftarrow \\mathrm{Bern}\\paren*{\\min\\brace*{ 1, \\eu^{-\\frac1T [R(\\tilde c, X) - R(c_{t-1}, X)]} }}$ % A(c_{t-1}, c)\n        \\item If $b=1$ then $c_t \\leftarrow \\tilde c$ else $c_t \\leftarrow c_{t-1}$.\n    \\end{itemize}\n\\end{enumerate}\n\\end{highlightbox}\n\n$\\pi(c'\\mid c) = \\{ \\substack{\\cdots\\\\\\cdots} \\enskip\\color{gray} \\leftarrow \\text{c.f. scr. (2.7)}$\n\n\\iffalse\n    % ===\n    \\subsection{Sampling Gibbs distributions}\n    \n    \\emph{Markov Chains:}\n    \\textit{``Well behaving''} MC's are\\\\\n    \\textbf{irreducible}: can go from/to any state, and\n    \\textbf{aperiodic}: chain doesn't go ``back\\&forth'' forever.% $\\to p(c\\vert c) > 0.5$.\n    %\\:\\:$\\Rightarrow$\\:\\:\n    \\\\$\\Rightarrow$\n    \\textbf{Stationary dist.} \\highlight{$\\sum_c \\pi(c ) p(c\\vert c') = \\pi(c')$}\\\\ %$\\pi P {=} \\pi$\n    iff. \\textbf{det. balance:} \\highlight{$\\pi(c) p(c'\\mid c) = \\pi(c') p(c\\mid c')$} %, $\\forall c, c' {\\in} \\mathcal C$.\n    \n    \\emph{Metroplolis Scheme:}\n    $P(i,j) = q(i,j) A(i,j)$ for $i\\neq j$ where $q(i,j)$ is the probability to propose move $i\\to j$ and $A(i,j)$ is the probability to accept the move.\n    \n    \\emph{Metropolis-Hastings (MCMC):}\\\\\n    $\\to$ disadvantage: is only fast when $T$ is high\\\\\n    \\begin{minipage}{\\linewidth}\n        \\algobox{\n            \\begin{enumerate}\n                \\item Define $\\brace{ q(\\cdot\\mid c) }_{c\\in\\mathcal C}$ s.t. $G_q$ is connected, and $q(c\\mid c) > 0$, for $c \\in \\mathcal C$.\n                \\item\n                    \\begin{itemize}\n                        \\item $c_0 \\leftarrow \\$$\n                        \\item \\texttt{for t=1,2,\\ldots}\n                        \\begin{itemize}\n                            \\item $\\tilde c \\leftarrow q(\\cdot\\mid c_{t-1})$\n                            \\item $b \\leftarrow \\mathrm{Bern}\\paren*{\\min\\brace*{1, \\frac{q(c_{t-1}\\,\\vert\\,\\tilde c) \\;\\cdot\\; f(\\tilde c)}{q(\\tilde c\\,\\vert\\, c_{t-1}) \\;\\cdot\\; f(c_{t-1})}}}$\n                            \\item if $b=1$ then $c_t \\leftarrow \\tilde c$ else $c_t \\leftarrow c_{t-1}$\n                        \\end{itemize}\n                    \\end{itemize}\n            \\end{enumerate}\n        }\n        % ===\n        \\begin{minipage}{\\linewidth}\n            \\vspace{-75pt}\n            \\hspace*{58pt}\n            $\\overbrace{\n                \\phantom{a\\qquad\\qquad\\!\\! a)}\n            }^{\n                \\substack{\n                    \\text{acceptance}\\\\\n                    \\hspace{30pt}\n                    A(c,\\tilde c) \\,=\\, \\exp(-\\frac1T \\brack{ R(\\tilde c, X) - R(c,X)})\n                }\n                %A(c,\\tilde c) \\,\\triangleq\\, \\text{acceptance}\n            }$\n        \\end{minipage}\n    \\end{minipage}\n\\fi\n\n\\emph{Simulated annealing:}\nGradually decrease temp. $T$ to escape bad local minima.\n$\\to$ MH-sampling from Gibbs (DA does not sample!).\n\n% ===\n\\subsection{Laplace's Method \\quad\\normalfont\\sffamily (Least angle clust.)}\n\n\\begin{enumerate}\n    \\item \\textit{Square the cost:}\\quad\n        $\\eu^{-\\frac1T R(c,X)} = \\mathit{const} \\cdot \\eu^{g(c)^\\top g(c)}$\n    \\item \\textit{Complete the square:}\\quad\n        \\highlight{$\\int \\eu^{-\\frac1T (y - g(c))^2} \\diff y = (\\pi T)^{d/2}$}\\\\\n        $\\Rightarrow$ $\\eu^{g(c)^\\top g(c)} = (\\pi T)^{-d/2} \\int \\exp^{-y^\\top y + 2 y^\\top g(c)} \\diff y$\n    \\item \\textit{Rewrite normalisation constant:}\\\\\n        $Z = \\sum_c \\eu^{-\\frac1T R(c,X)} = \\ldots = \\mathit{const} \\int \\eu^{-\\frac1T f(y)} \\diff y$\n    \\item \\textit{Apply Laplace's method:}\\\\\\vspace{-2pt}\n        If $f$ has unique min. $y_0$ and Hessian $H\\coloneqq \\pderiv[2]{f}{y}\\big\\vert_{y_0}$\\\\\\vspace{-2pt}\n        \\highlight*{$\\int \\eu^{-\\frac1T f(y)}\\diff y \\overset{\\scriptstyle(T\\to0)}{\\approx} \\eu^{-\\frac1T f(y_0)} \\abs*{\\frac{H}{2\\pi T}}^{-1/2}$}\n\\end{enumerate}\n\n% \\todo{\\texttt{slt21\\_lecture05\\_1.pdf}}\n\n% ===\n\\subsection{Mean-field Approximation}\n\n\\textbf{Idea:}\\enskip\nApproximate $p_\\beta$ (Gibbs) with a ``simple'', \\\\\\phantom{\\textbf{Idea:}}\\enskip\nfactorisable distribution $p = p_1 \\cdots p_N$.\n\n\\textbf{Approach:}\\enskip\nMinimise $D\\ped{KL}(p\\parallel p_\\beta)$\\\\\n$\\iff$ Minimise \\emph{Gibbs free energy:}\\\\\n\\hfill \\highlight*{$G(p) = \\frac1\\beta D\\ped{KL} (p\\parallel p_\\beta) + F(\\beta) = \\E[c\\sim p]{R(c)} - \\frac1\\beta H[p]$}\n\n\\quad \\textit{Note:}\\enskip\n\\highlight{$H[p] = \\sum_{i=1}^N H[p_i]$} \\enskip \\textit{and} \\enskip \\highlight{$F(\\beta) \\leq G(p)$}\n\n\\emph{Ising model:}\\enskip\n$R(c\\mid J) = -\\frac12 \\sum_{i,j} J_{ij} c_i c_j - \\sum_i h_i c_i$\n\\\\\nwhere $J_{ij}$:\\, interaction between particles,\\\\\\phantom{where}\n$h_i$:\\, noisy image,\\enskip\n$\\sigma_i$:\\, denoised image\n\n\\textbf{Problem:} \\quad $\\pderiv{G(p)}{p_{i\\ell}} = 0$ \\enspace s.t.\\enspace $\\sum_{\\ell'} p_{i\\ell'} = 1 \\: \\forall i$\n\n\\textbf{Solution:}\\quad\nwith the \\textit{mean field} $h_i = [\\cdots h_{i\\ell} \\cdots]^\\top$\n\\\\\n\\highlight*{$h_{i\\ell} \\coloneqq \\pderiv{\\E{R(c)}}{p_{i\\ell}} = \\E[c\\sim p_{\\mid i\\to\\ell}]{R(c)}$} $\\leftarrow \\substack{\\text{object }i\\text{ chooses}\\\\\\text{class } \\ell}$\n\\\\\n\\highlight*{$p_{i\\ell} = \\eu^{-\\beta h_{i\\ell}} / Z_i$}\n\n\\textbf{EM-like Algo:}\\enspace\nIteratively \\enspace\n1.~Pick~random $i$ \\enspace\n2.~$h_i^{\\mathrm{new}} {\\leftarrow} p_j^{\\mathrm{old}}$ \\enspace\n3.~$p_i^{\\mathrm{new}} {\\leftarrow} h_i^{\\mathrm{new}}$ \\enspace\nuntil converged.\n\n\\subsubsection{Smooth \\textit{\\rmfamily k}-means\n\\qquad\\normalfont\\sffamily\\color{gray}scr.20 (p. 39)}\n\n$R(c\\mid X) =\n{\\color{Green} \\sum_i \\lVert x_i - y_{c_i} \\rVert^2}\n+\n{\\color{OrangeRed} \\frac\\lambda2 \\sum_i \\sum_{j\\in N(i)} \\mathbb I_{\\{c_i \\neq c_j\\}}}$\n\\\\\nwhere the second term measures {\\color{OrangeRed} \\#violations} of these neighbourhood constraints.\n\n$\\implies h_{i\\ell} = \\norm{x_i - y_\\ell}^2 + \\lambda \\sum_{j\\in N(i)} p_{j\\ell} + \\mathit{const}_i$\n\n% ===\n", "meta": {"hexsha": "281327b44a99d5097f88c6e344ba53771c61c7d5", "size": 7167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/04_methods_for_gibbs.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/04_methods_for_gibbs.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/04_methods_for_gibbs.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.9542857143, "max_line_length": 194, "alphanum_fraction": 0.5688572625, "num_tokens": 2726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6305936370146809}}
{"text": "\\chapter{Foundations of Binary Mathematics}\\label{ch02}\n\\section{Introduction to Number Systems}\n\\subsection{Background}\n\nThe expression of numerical quantities is often taken for granted, which is both a good and a bad thing in the study of electronics. It is good since the use and manipulation of numbers is familiar for many calculations used in analyzing electronic circuits. On the other hand, the particular system of notation that has been taught from primary school onward is not the system used internally in modern electronic computing devices and learning any different system of notation requires some re-examination of assumptions.\n\nIt is important to distinguish the difference between numbers and the symbols used to represent numbers. A number is a mathematical quantity, usually correlated in electronics to a physical quantity such as voltage, current, or resistance. There are many different types of numbers, for example:\n\n\\begin{itemize}\n  \\item Whole Numbers: $ 1, 2, 3, 4, 5, 6, 7, 8, 9 ... $\n  \\item Integers: $ -4, -3, -2, -1, 0, 1, 2, 3, 4 ...  $\n  \\item Rational Numbers: $ -5.3, 0, \\frac{1}{3}, 6.7 $\n  \\item Irrational Numbers: $\\pi $ (approx. $ 3.1416 $), e (approx. $ 2.7183 $), and the square root of any prime number \n  \\item Real Numbers: (combination of all rational and irrational numbers) \n  \\item Complex Numbers: $ 3 - j4 $\n\\end{itemize}\n\nDifferent types of numbers are used for different applications in electronics. As examples:\n\n\\begin{itemize}\n  \\item Whole numbers work well for counting discrete objects, such as the number of resistors in a circuit. \n  \\item Integers are needed to express a negative voltage or current. \n  \\item Irrational numbers are used to describe the charge/discharge cycle of electronic objects like capacitors.\n  \\item Real numbers, in either fractional or decimal form, are used to express the non-integer quantities of voltage, current, and resistance in circuits.\n  \\item Complex numbers, in either rectangular or polar form, must be used rather than real numbers to capture the dual essence of the magnitude and phase angle of the current and voltage in alternating current circuits.\n\\end{itemize}\n\nThere is a difference between the concept of a ``number'' as a measure of some quantity and ``number'' as a means used to express that quantity in spoken or written communication. A way to symbolically denote numbers had to be developed in order to use them to describe processes in the physical world, make scientific predictions, or balance a checkbook. The written symbol that represents some number, like how many apples there are in a bin, is called a \\emph{cipher} and in western mathematics, the commonly-used ciphers are $ 0, 1, 2, 3, 4, 5, 6, 7, 8, $ and $ 9 $.\n\n\\subsection{Binary Mathematics}\n\\label{MF:sub:binary_mathematics}\nBinary mathematics is a specialized branch of mathematics that concerns itself with a number system that contains only two ciphers: zero and one. It would seem to be very limiting to use only two ciphers; however, it is much easier to create electronic devices that can differentiate between two voltage levels rather than the ten that would be needed for a decimal system.\n\n\\subsection{Systems Without Place Value}\n\\label{MF:sub:sysems_without_place_value}\n\\paragraph{Hash Marks.} One of the earliest cipher systems was to simply use a hash mark to represent each quantity. For example, three apples could be represented like this: \\textbar \\textbar \\textbar. Often, five hash marks were ``bundled'' to aid in the counting of large quantities, so eight apples would be represented like this: \\sout{\\textbar \\textbar \\textbar \\textbar} \\textbar \\textbar \\textbar. \n\n\\paragraph{Roman Numerals.} The Romans devised a system that was a substantial improvement over hash marks, because it used a variety of ciphers to represent increasingly large quantities. The notation for one is the capital letter \\emph{I}. The notation for $ 5 $ is the capital letter \\emph{V}. Other ciphers, as listed in Table \\ref{MF:tab:roman}, possess increasing values:\n\n\\begin{table}[H]\n  \\rowcolors{1}{gray!10}{white}\n  \\begin{center}\n    \\begin{tabular}{ c r } \\hline\n      I & 1 \\\\\n      V & 5 \\\\\n      X & 10 \\\\\n      L & 50 \\\\\n      C & 100 \\\\\n      D & 500 \\\\\n      M & 1000 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Roman Numerals}\n  \\label{MF:tab:roman}\n\\end{table}\n\nIf a cipher is accompanied by a second cipher of equal or lesser value to its immediate right, with no ciphers greater than that second cipher to its right, the second cipher's value is added to the total quantity. Thus, \\emph{VIII} symbolizes the number $ 8 $, and \\emph{CLVII} symbolizes the number $ 157 $. On the other hand, if a cipher is accompanied by another cipher of lesser value to its immediate left, that other cipher's value is subtracted from the first. In that way, \\emph{IV} symbolizes the number $ 4 $ (\\emph{V} minus \\emph{I}), and \\emph{CM} symbolizes the number $ 900 $ (\\emph{M} minus \\emph{C}). The ending credit sequences for most motion pictures contain the date of production, often in Roman numerals. For the year $ 1987 $, it would read: \\emph{MCMLXXXVII}. To break this numeral down into its constituent parts, from left to right:\n\n\\begin{center}\n  $ (M = 1000) + (CM = 900) + (LXXX = 80) + (VII = 7) $\n\\end{center}\n\nLarge numbers are very difficult to denote with Roman numerals; and the left vs. right (or subtraction vs. addition) of values can be very confusing. Adding and subtracting two Roman numerals is also very challenging, to say the least. Finally, one other major problem with this system is that there is no provision for representing the number zero or negative numbers, and both are very important concepts in mathematics. Roman culture, however, was more pragmatic with respect to mathematics than most, choosing only to develop their numeration system as far as it was necessary for use in daily life.\n\n\\subsection{Systems With Place Value}\n\\label{MF:sub:systems_with_place_value}\n\\paragraph{Decimal Numeration.} The Babylonians developed one of the most important ideas in numeration: cipher position, or place value, to represent larger numbers. Instead of inventing new ciphers to represent larger numbers, as the Romans had done, they re-used the same ciphers, placing them in different positions from right to left to represent increasing values. This system also required a cipher that represents zero value, and the inclusion of zero in a numeric system was one of the most important inventions in all of mathematics (many would argue zero was the single most important human invention, period). The decimal numeration system uses the concept of place value, with only ten ciphers ($ 0, 1, 2, 3, 4, 5, 6, 7, 8, $ and $ 9 $) used in ``weighted'' positions to symbolize numbers.\n\nEach cipher represents an integer quantity, and each place from right to left in the notation is a multiplying constant, or weight, for the integer quantity. For example, the decimal notation ``$ 1206 $'' may be broken down into its constituent weight-products as such:\n\n\\begin{center}\n  $ 1206 = (1 X 1000) + (2 X 100) + (0 X 10) + (6 X 1) $\n\\end{center}\n\nEach cipher is called a ``digit'' in the decimal numeration system, and each weight, or place value, is ten times that of the place to the immediate right. So, working from right to left is a ``ones'' place, a ``tens'' place, a ``hundreds'' place, a ``thousands'' place, and so on.\n\nWhile the decimal numeration system uses ten ciphers, and place-weights that are multiples of ten, it is possible to make a different numeration system using the same strategy, except with fewer or more ciphers.\n\n\\paragraph{Binary Numeration.} The binary numeration system uses only two ciphers and the weight for each place in a binary number is two times as much as the place to its right. Contrast this to the decimal numeration system that has ten different ciphers and the weight for each place is ten times the place to its right. The two ciphers for the binary system are zero and one, and these ciphers are arranged right-to-left in a binary number, each place doubling the weight of the previous place. The rightmost place is the ``ones'' place; and, moving to the left, is the ``twos'' place, the ``fours'' place, the ``eights'' place, the ``sixteens'' place, and so forth. For example, the binary number $ 11010 $ can be expressed as a sum of each cipher value times its respective weight:\n\n\\begin{center}\n  $ 11010 = (1 X 16) + (1 X 8) + (0 X 4) + (1 X 2) + (0 X 1) $\n\\end{center}\n\nThe primary reason that the binary system is popular in modern electronics is because it is easy to represent the two cipher states (zero and one) electronically; if no current is flowing in the circuit it represents a binary zero while flowing current represents a binary one. Binary numeration also lends itself to the storage and retrieval of numerical information: as examples, magnetic tapes have spots of iron oxide that are magnetized for a binary one or demagnetized for a binary zero and optical disks have a laser-burned pit in the aluminum substrate representing a binary one and an unburned spot representing a binary zero.\n\nDigital numbers require so many bits to represent relatively small numbers that programming or analyzing electronic circuitry can be a tedious task. However, anyone working with digital devices soon learns to quickly count in binary to at least $ 11111 $ (that is decimal $ 31 $). Any time spent practicing counting both up and down between zero and $ 11111 $ will be rewarded while studying binary mathematics, codes, and other digital logic topics. Table \\ref{MF:tab:bin_dec_conversion} will help in memorizing binary numbers:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\n  \\begin{center}\n    \\begin{tabular}{|cc|cc|cc|cc|} \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Bin} & \\head{Dec} & \\head{Bin} & \\head{Dec} & \\head{Bin} & \n      \\head{Dec} & \\head{Bin} & \\head{Dec} \\\\\n      \\hline \n      0   & 0 & 1000 & 8  & 10000 & 16 & 11000 & 24 \\\\ \n      1   & 1 & 1001 & 9  & 10001 & 17 & 11001 & 25 \\\\ \n      10  & 2 & 1010 & 10 & 10010 & 18 & 11010 & 26 \\\\ \n      11  & 3 & 1011 & 11 & 10011 & 19 & 11011 & 27 \\\\ \n      100 & 4 & 1100 & 12 & 10100 & 20 & 11100 & 28 \\\\ \n      101 & 5 & 1101 & 13 & 10101 & 21 & 11101 & 29 \\\\ \n      110 & 6 & 1110 & 14 & 10110 & 22 & 11110 & 30 \\\\ \n      111 & 7 & 1111 & 15 & 10111 & 23 & 11111 & 31 \\\\ \n      \\hline\n    \\end{tabular} \n  \\end{center}\n  \\caption{Binary-Decimal Conversion}\n  \\label{MF:tab:bin_dec_conversion}\n\\end{table}\n\n\\paragraph{Octal Numeration.} The octal numeration system is place-weighted with a base of eight. Valid ciphers include the symbols $ 0, 1, 2, 3, 4, 5, 6, $ and $ 7 $. These ciphers are arranged right-to-left in an octal number, each place being eight times the weight of the previous place. For example, the octal number $ 4270 $ can be expressed, just like a decimal number, as a sum of each cipher value times its respective weight:\n\n\\begin{center}\n  $4270 = (4 X 512) + (2 X 64) + (7 X 8) + (0 X 1)$\n\\end{center}\n\n\\paragraph{Hexadecimal Numeration.} The hexadecimal numeration system is place-weighted with a base of sixteen.\\marginpar{The word ``hexadecimal'' is a combination of ``hex'' for six and ``decimal'' for ten} There needs to be ciphers for numbers greater than nine so English letters are used for those values. Table \\ref{MF:tab:hexadecimal_numbers} lists hexadecimal numbers up to decimal 15:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}  \n  \\begin{center}\n    \\begin{tabular}{|cc|cc|} \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Hex} & \\head{Dec} & \\head{Hex} & \\head{Dec} \\\\ \n      \\hline\n      0 & 0 & 8 & 8  \\\\ \n      1 & 1 & 9 & 9  \\\\ \n      2 & 2 & A & 10 \\\\ \n      3 & 3 & B & 11 \\\\ \n      4 & 4 & C & 12 \\\\ \n      5 & 5 & D & 13 \\\\ \n      6 & 6 & E & 14 \\\\ \n      7 & 7 & F & 15 \\\\ \n      \\hline\n    \\end{tabular} \n  \\end{center}\n  \\caption{Hexadecimal Numbers}\n  \\label{MF:tab:hexadecimal_numbers}  \n\\end{table}\n\nHexadecimal ciphers are arranged right-to-left, each place being $ 16 $ times the weight of the previous place. For example, the hexadecimal number $ 13A2 $ can be expressed, just like a decimal number, as a sum of each cipher value times its respective weight:\n\n\\begin{center}\n  $13A2 = (1 X 4096) + (3 X 256) + (A X 16) + (2 X 1)$\n\\end{center}\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{Maximum Number Size}}\n  % Lower half of the box: the content\n  \\tcblower\n  It is important to know the largest number that can be represented with a given number of cipher positions. For example, if only four cipher positions are available then what is the largest number that can be represented in each of the numeration systems? With the crude hash-mark system, the number of places IS the largest number that can be represented, since one hash mark ``place'' is required for every integer step. For place-weighted systems, however, the answer is found by taking the number base of the numeration system ($ 10 $ for decimal, $ 2 $ for binary) and raising that number to the power of the number of desired places. For example, in the decimal system, a five-place number can represent $ 10^{5} $, or $ 100,000 $, with values from zero to $ 99,999 $. Eight places in a binary numeration system, or $ 2^{8} $, can represent $ 256 $ different values, $ 0 - 255 $.\n\\end{tcolorbox}\n% End Sidebar Box\n\n\\subsection{Summary of Numeration Systems}\n\\label{MF:sub:summary_of_numeration_systems}\nTable \\ref{MF:tab:counting_to_twenty} counts from zero to twenty using several different numeration systems:\n\n\\begin{table}[H]\n  \\sffamily\n  \\newcommand{\\head}[1]{\\textcolor{white}{\\textbf{#1}}}\n  \\begin{center}\n    \\rowcolors{2}{gray!10}{white}\n    \\begin{tabular}{lcccccc} \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Text} & \\head{Hash Marks} & \\head{Roman} & \\head{Dec} & \\head{Bin} \n      & \\head{Oct} & \\head{Hex} \\\\ \n      \\hline\n      Zero      & n/a                           & n/a   & 0  & 0     & 0  & 0 \\\\ \n      One       & $\\mid$                        & I     & 1  & 1     & 1  & 1 \\\\ \n      Two       & $\\mid\\mid$                    & II    & 2  & 10    & 2  & 2 \\\\ \n      Three     & $\\mid\\mid\\mid$                & III   & 3  & 11    & 3  & 3 \\\\ \n      Four      & $\\mid\\mid\\mid\\mid$            & IV    & 4  & 100   & 4  & 4 \\\\ \n      Five      & \\sout{$\\mid\\mid\\mid\\mid$} & V     & 5  & 101   & 5  & 5 \\\\ \n      Six       & \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid$                                    & VI    & 6  & 110   & 6  & 6 \\\\ \n      Seven     & \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid$                                & VII   & 7  & 111   & 7  & 7 \\\\ \n      Eight     & \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid$                            & VIII  & 8  & 1000  & 10 & 8 \\\\ \n      Nine      & \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid\\mid$                        & IX    & 9  & 1001  & 11 & 9 \\\\ \n      Ten       & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}             & X     & 10 & 1010  & 12 & A \\\\ \n      Eleven    & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid$                                    & XI    & 11 & 1011  & 13 & B \\\\ \n      Twelve    & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid$                                & XII   & 12 & 1100  & 14 & C \\\\ \n      Thirteen  & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid$                            & XIII  & 13 & 1101  & 15 & D \\\\ \n      Fourteen  & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid\\mid$                        & XIV   & 14 & 1110  & 16 & E \\\\ \n      Fifteen   & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}             & XV    & 15 & 1111  & 17 & F \\\\ \n      Sixteen   & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid$                                    & XVI   & 16 & 10000 & 20 & 10 \\\\ \n      Seventeen & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid$                                & XVII  & 17 & 10001 & 21 & 11 \\\\ \n      Eighteen  & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid$                            & XVIII & 18 & 10010 & 22 & 12 \\\\ \n      Nineteen  & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      $\\mid\\mid\\mid\\mid$                        & XIX   & 19 & 10011 & 23 & 13 \\\\ \n      Twenty    & \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}\n      \\sout{$\\mid\\mid\\mid\\mid$}             & XX    & 20 & 10100 & 24 & 14 \\\\ \n      \\hline\n    \\end{tabular} \n  \\end{center}\n  \\caption{Counting To Twenty}\n  \\label{MF:tab:counting_to_twenty}\n\\end{table}\n\n% Begin Sidebar Box\n\\medskip % Add a bit of space above the box\n\\begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black]\n  % Upper half of box: my \"title\" area\n  \\textcolor{blue}{\\textbf{Numbers for Computer Systems}}\n  % Lower half of the box: the content\n  \\tcblower\n  An interesting footnote for this topic concerns one of the first electronic digital computers: ENIAC. The designers of the ENIAC chose to work with decimal numbers rather than binary in order to emulate a mechanical adding machine; unfortunately, this approach turned out to be counter-productive and required more circuitry (and maintenance nightmares) than if they had they used binary numbers. ``ENIAC contained $ 17,468 $ vacuum tubes, $ 7,200 $ crystal diodes, $ 1,500 $ relays, $ 70,000 $ resistors, $ 10,000 $ capacitors and around $ 5 $ million hand-soldered joints''\\footnote{\\url{http://en.wikipedia.org/wiki/Eniac}}. Today, all digital devices use binary numbers for internal calculation and storage and then convert those numbers to/from decimal only when necessary to interface with human operators.\n\\end{tcolorbox}\n% End Sidebar Box\n\n\\subsection{Conventions}\n\\label{MF:sub:conventions}\nUsing different numeration systems can get confusing since many ciphers, like ``$ 1 $,'' are used in several different numeration systems. Therefore, the numeration system being used is typically indicated with a subscript following a number, like $ 11010_{2} $ for a binary number or $ 26_{10} $ for a decimal number. The subscripts are not mathematical operation symbols like superscripts, which are exponents; all they do is indicate the system of numeration being used. By convention, if no subscript is shown then the number is assumed to be decimal.\\marginpar{In this book, subscripts are normally used to make it clear whether the number is binary or some other system.}\n\nAnother method used to represent hexadecimal numbers is the prefix $ 0x $. This has been used for many years by programmers who work with any of the languages descended from C, like C++, C\\#, Java, JavaScript, and certain shell scripts. Thus, $ 0x1A $ would be the hexadecimal number $ 1A $.\n\nOne other commonly used convention for hexadecimal numbers is to add an \\emph{h} (for \\emph{hexadecimal}) after the number. This is used because that is easier to enter with a keyboard than to use a subscript and is more intuitive than using a $ 0x $ prefix. Thus, $ 1A_{16} $ would be written $ 1Ah $. In this case, the \\emph{h} only indicates that the number $ 1A $ is hexadecimal; it is not some sort of mathematical operator.\n\nOccasionally binary numbers are written with a $ 0b $ prefix; thus $ 0b1010 $ would be $ 1010_{2} $, but this is a programmer's convention not often found elsewhere.\n\n\\section{Converting Between Radices}\n\\label{MF:sec:converting_between_bases}\n\n\\subsection{Introduction}\n\\label{MF:sub:introduction_converting_between_bases}\n\n\\marginpar{The radix of a system is also commonly called its ``base.''}The number of ciphers used by a number system (and therefore, the place-value multiplier for that system) is called the \\emph{radix} for the system. The binary system, with two ciphers (zero and one), is radix two numeration, and each position in a binary number is a \\emph{b}inary dig\\emph{it} (or \\emph{bit}). The decimal system, with ten ciphers, is radix-ten numeration, and each position in a decimal number is a \\emph{digit}. When working with various digital logic processes it is desirable to be able to convert between binary/octal/decimal/hexadecimal radices.\n\n\\subsection{Expanded Positional Notation}\n\\label{MF:sub:expanded_positional_notation}\n\\textsc{Expanded Positional Notation} is a method of representing a number in such a way that each position is identified with both its cipher symbol and its place-value multiplier. For example, consider the number $ 347_{10} $:\n\n\\begin{equation}\n347_{10}=(3X10^2)+(4X10^1)+(7X10^0)\n\\end{equation}\n\nThe steps to use to expand a decimal number like $ 347 $ are found in Table \\ref{MF:tab:expand_347}.\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}{ p{7cm} l } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Step} & \\head{Result} \\\\ \n      \\hline \n      Count the number of digits in the number. & Three Digits  \\\\ \n      Create a series of $ (\\_ X\\_) $ connected by plus signs such that there is one set for each of the digits in the original number. & $ ( \\_X\\_ ) + ( \\_X\\_ ) + ( \\_X\\_ ) $  \\\\ \\hline\n      Fill in the digits of the original number on the left side of each set of parenthesis. & $ ( 3X\\_ ) + ( 4X\\_ ) + ( 7X\\_ ) $  \\\\ \n      Fill in the radix (or base number) on the right side of each parenthesis. & $ ( 3X10 ) + ( 4X10 ) + ( 7X10 ) $  \\\\ \n      Starting on the far right side of the expression, add an exponent (power) for each of the base numbers. The powers start at zero and increase to the left. & $ ( 3X10^2 ) + ( 4X10^1 ) + ( 7X10^0 ) $ \\\\\n      \\hline\n    \\end{tabular} \n  \\end{center}\n  \\caption{Expanding a Decimal Number}\n  \\label{MF:tab:expand_347}\n\\end{table}\n\nAdditional examples of expanded positional notation are: \n\n\\begin{equation}\n2413_{10}=(2x10^3)+(4X10^2)+(1X10^1)+(3X10^0)\n\\end{equation} \n\n\\begin{equation}\n1052_8=(1X8^3)+(0X8^2)+(5X8^1)+(2X8^0)  \n\\end{equation}\n\n\\begin{equation}\n139_{16}=(1X16^2)+(3X16^1)+(9X16^0)\n\\end{equation}\n\nThe above examples are for positive decimal integers; but a number with any radix can also have a fractional part. In that case, the number's integer component is to the left of the radix point (called the ``decimal point'' in the decimal system), while the fractional part is to the right of the radix point. For example, in the number $ 139.25_{10} $, $ 139 $ is the integer component while $ 25 $ is the fractional component. If a number includes a fractional component, then the expanded positional notation uses increasingly negative powers of the radix for numbers to the right of the radix point. Consider this binary example: $ 101.011_2 $. The expanded positional notation for this number is:\n\n\\begin{equation}\n101.011_2=(1X2^2)+(0X2^1)+(1X2^0)+(0X2^{-1})+(1X2^{-2})+(1X2^{-3})\n\\end{equation}\n\nOther examples are:\n\n\\begin{equation}\n526.14_{10}=(5X10^2)+(2X10^1)+(6X10^0)+(1X10^{-1})+(4X10^{-2})\n\\end{equation}\n\n\\begin{equation}\n65.147_8=(6X8^1)+(5X8^0)+(1X8^{-1})+(4X8^{-2})+(7X8^{-3})\n\\end{equation}\n\n\\begin{equation}\nD5.3A_{16}=(13X16^1)+(5X16^0)+(3X16^{-1})+(10X16^{-2})\n\\end{equation}\n\nWhen a number in expanded positional notation includes one or more negative radix powers, the radix point is assumed to be to the immediate right of the ``zero'' exponent term, but it is not actually written into the notation. Expanded positional notation is useful in converting a number from one base to another. \n\n\\subsection{Binary to Decimal}\n\\label{MF:sub:binary_to_decimal}\nTo convert a number in binary form to decimal, start by writing the binary number in expanded positional notation, calculate the values for each of the sets of parenthesis in decimal, and then add all of the values. For example, convert $ 1101_2 $ to decimal:\n\n\\begin{align}\n  1101_2 &= (1X2^3)+(1X2^2)+(0X2^1)+(1X2^0) \\\\\n  \\nonumber\n  &= (8)+(4)+(0)+(1) \\\\\n  \\nonumber\n  &= 13_{10}\n\\end{align}\n\nBinary numbers with a fractional component are converted to decimal in exactly the same way, but the fractional parts use negative powers of two. Convert binary $ 10.11_2 $ to decimal: \n\n\\begin{align}\n  10.11_2 &= (1X2^1)+(0X2^0)+(1X2^{-1})+(1X2^{-2}) \\\\\n  \\nonumber\n  &= (2)+(0)+(\\frac{1}{2})+(\\frac{1}{4}) \\\\\n  \\nonumber\n  &= 2+.5+.25 \\\\\n  \\nonumber\n  &= 2.75_{10}\n\\end{align}\n\nMost technicians who work with digital circuits learn to quickly convert simple binary integers to decimal in their heads. However, for longer numbers, it may be useful to write down the various place weights and add them up; in other words, a shortcut way of writing expanded positional notation. For example, convert the binary number $ 11001101_2 $ to decimal: \n\n\\begin{verbatim}\n     Binary Number:  1 1 0 0 1 1 0 1\n                     - - - - - - - - \n        (Read Down)  1 6 3 1 8 4 2 1 \n                     2 4 2 6     \n                     8 \n\\end{verbatim}\n\nA bit value of one in the original number means that the respective place weight gets added to the total value, while a bit value of zero means that the respective place weight does not get added to the total value. Thus, using the example above this paragraph, the binary number $ 11001101_2 $ is converted to: $ 128+64+8+4+1 $, or $ 205_{10} $.\n\n\\bigskip\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{Naming Conventions}}\n  % Lower half of the box: the content\n  \\tcblower\n  The bit on the right end of any binary number is the \\ac{LSB} because it has the least weight (the ones place) while the bit on the left end is the \\ac{MSB} because it has the greatest weight. Also, groups of bits are normally referred to as \\emph{words}, so engineers would speak of $ 16 $-bit or $ 32 $-bit words. As exceptions, an eight-bit group is commonly called a \\emph{byte} and a four-bit group is called a \\emph{nibble} (occasionally spelled \\emph{nybble}).\n\\end{tcolorbox}\n% End Sidebar Box\n\n\\subsection{Binary to Octal}\n\\label{MF:sub:binary_to_octal}\nThe octal numeration system serves as a ``shorthand'' method of denoting a large binary number. Technicians find it easier to discuss a number like $ 57_8 $ rather than $ 101111_2 $.\\marginpar{``Five Seven Octal'' is not pronounced ``Fifty Seven'' since ``fifty'' is a decimal number.}\n\nBecause octal is a base eight system, and eight is $ 2^3 $, binary numbers can be converted to octal by creating groups of three and then simplifying each group. As an example, convert $ 101111_2 $ to octal: \n\n% Verbatim uses spaces, not tabs, for alignment. It renders in fixed-width font.\n\\begin{verbatim}\n     101 111\n      5   7 \n\\end{verbatim}\n\nThus, $ 101111_2 $ is equal to $ 57_8 $.\n\nIf a binary integer cannot be grouped into an even grouping of three, it is padded on the left with zeros. For example, to convert $ 11011101_2 $ to octal, the most significant bit must be padded with a zero:\n\n\\begin{verbatim}\n     011 011 101\n      3   3   5 \n\\end{verbatim}\n\nThus, $ 11011101_2 $ is equal to $ 335_8 $. \n\nA binary fraction may need to be padded on the right with zeros in order to create even groups of three before it is converted into octal. For example, convert $ 0.1101101_2 $ to octal: \n\n\\begin{verbatim}\n     0 . 110 110 100\n     0 .  6   6   4 \n\\end{verbatim}\n\nThus, $ 0.1101101_2 $ is equal to $ .664_8 $. \n\nA binary mixed number may need to be padded on both the left and right with zeros in order to create even groups of three before it can be converted into octal. For example, convert $ 10101.00101_2 $ to octal: \n\n\\begin{verbatim}\n     010 101 . 001 010\n      2   5  .  1   2 \n\\end{verbatim}\n\nThus, $ 10101.00101_2 $ is equal to $ 25.12_8 $. \n\nTable \\ref{MF:tab:Bin_Oct_conversion_example} lists additional examples of binary/octal conversion:\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}{ S S } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Binary} & \\head{Octal} \\\\ \n      \\hline\n      100101.011 & 45.3 \\\\ \n      1100010.1101 &  142.64 \\\\ \n      100101011.1101001 & 453.644 \\\\ \n      1110010011101.00011010 & 16235.064 \\\\ \n      110011010100111.011101 & 63247.35 \\\\\n      \\hline \n    \\end{tabular} \n  \\end{center}\n  \\caption{Binary-Octal Conversion Examples}\n  \\label{MF:tab:Bin_Oct_conversion_example}\n\\end{table}\n\nWhile it is easy to convert between binary and octal, the octal system is not frequently used in electronics since computers store and transmit binary numbers in words of 16, 32, or 64 bits, which are multiples of four rather than three. \n\n\\subsection{Binary to Hexadecimal}\n\\label{MF:sub:binary_to_hexadecimal}\nThe hexadecimal numeration system serves as a ``shorthand'' method of denoting a large binary number. Technicians find it easier to discuss a number like $ 2F_{16} $ rather than $ 101111_2 $. Because hexadecimal is a base $ 16 $ system, and $ 16 $ is $ 2^4 $; binary numbers can be converted to hexadecimal by creating groups of four and then simplifying each group. As an example, convert $ 10010111_2 $ to hexadecimal: \n\n\\begin{verbatim}\n     1001 0111\n      9    7 \n\\end{verbatim}\n\nThus, $ 10010111_2 $ is equal to $ 97_{16} $.\\marginpar{``Nine Seven Hexadecimal,'' or, commonly, ``Nine Seven Hex,'' is not pronounced ``Ninety Seven'' since ``ninety'' is a decimal number.}\n\nA binary integer may need to be padded on the left with zeros in order to create even groups of four before it can be converted into hexadecimal. For example, convert $ 1001010110_2 $ to hexadecimal: \n\n\\begin{verbatim}\n     0010 0101 0110\n      2    5    6 \n\\end{verbatim}\n\nThus, $ 1001010110_2 $ is equal to $ 256_{16} $. \n\nA binary fraction may need to be padded on the right with zeros in order to create even groups of four before it can be converted into hexadecimal. For example, convert $ 0.1001010110_2 $ to hexadecimal: \n\n\\begin{verbatim}\n     0 . 1001 0101 1000\n       .  9    5    8 \n\\end{verbatim}\n\nThus, $ 0.1001010110_2 $ is equal to $ 0.958_{16} $. \n\nA binary mixed number may need to be padded on both the left and right with zeros in order to create even groups of four before it can be converted into hexadecimal. For example, convert $ 11101.10101_2 $ to hexadecimal: \n\n\\begin{verbatim}\n     0001 1101 . 1010 1000\n      1    D   .  A    8 \n\\end{verbatim}\n\nThus, $ 11101.10101_2 $ is equal to $ 1D.A8_{16} $. \n\nTable \\ref{MF:tab:bin_hex_conversion_example} lists additional examples of binary/hexadecimal conversion:\n\n\\begin{table}[H]\n  \\sisetup{input-digits={0123456789ABCDEF}}\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}{ S S } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Binary} & \\head{Hexadecimal} \\\\\n      \\hline\n      100101.011 & 25.6 \\\\ \n      1100010.1101 & 62.D \\\\ \n      100101011.1101001 & 12B.D2 \\\\ \n      1110010011101.00011010 & 1C9D.1A \\\\ \n      110011010100111.011101 & 66A7.74 \\\\\n      \\hline\n    \\end{tabular} \n  \\end{center}\n  \\caption{Binary-Hexadecimal Conversion Examples}\n  \\label{MF:tab:bin_hex_conversion_example}  \n\\end{table}\n\n\\subsection{Octal to Decimal}\n\\label{MF:sub:octal_to_decimal}\nThe simplest way to convert an octal number to decimal is to write the octal number in expanded positional notation, calculate the values for each of the sets of parenthesis, and then add all of the values. For example, to convert $ 245_8 $ to decimal:\n\n\\begin{align}\n  245_8 &= (2X8^2)+(4X8^1)+(5X8^0) \\\\\n  \\nonumber\n  &= (2X64)+(4X8)+(5X1) \\\\\n  \\nonumber\n  &= (128)+(32)+(5) \\\\\n  \\nonumber\n  &= 165_{10}\n\\end{align}\n\nIf the octal number has a fractional component, then that part would be converted using negative powers of eight. As an example, convert $ 25.71_8 $ to decimal: \n\n\\begin{align}\n  25.71_8 &= (2X8^1)+(5X8^0)+(7X8^{-1})+(1X8^{-2}) \\\\\n  \\nonumber\n  &= (2X8)+(5X1)+(7X0.125)+(1X0.015625) \\\\\n  \\nonumber\n  &= (16)+(5)+(0.875)+(0.015625) \\\\\n  \\nonumber\n  &= 21.890625_{10}\n\\end{align}\n\nOther examples are:\n\n\\begin{align}\n  42.6_8 &= (4X8^1)+(2X8^0)+(6X8^{-1}) \\\\\n  \\nonumber\n  &= (4X8)+(2X1)+(6X0.125) \\\\\n  \\nonumber\n  &= (32)+(2)+(0.75) \\\\\n  \\nonumber\n  &= 34.75_{10}\n\\end{align}\n\n\\begin{align}\n  32.54_8 &= (3X8^1)+(2X8^0)+(5X8^{-1})+(4X8^{-2}) \\\\\n  \\nonumber\n  &= (3X8)+(2X1)+(5X0.125)+(4X0.015625) \\\\\n  \\nonumber\n  &= (24)+(2)+(0.625)+(0.0625) \\\\\n  \\nonumber\n  &= 26.6875_{10}\n\\end{align}\n\n\\begin{align}\n  436.27_8 &= (4X8^2)+(3X8^1)+(6X8^0)+(2X8^{-1})+(7X8^{-2}) \\\\\n  \\nonumber\n  &= (4X64)+(3X8)+(6X1)+(2X0.125)+(7X0.015625) \\\\\n  \\nonumber\n  &= (256)+(24)+(6)+(0.25)+(0.109375) \\\\\n  \\nonumber\n  &= 286.359375_{10}\n\\end{align}\n\n\\subsection{Hexadecimal to Decimal} \n\\label{MF:sub:hexadecimal_to_decimal}\nThe simplest way to convert a hexadecimal number to decimal is to write the hexadecimal number in expanded positional notation, calculate the values for each of the sets of parenthesis, and then add all of the values. For example, to convert $ 2A6_{16} $ to decimal:\n\n\\begin{align}\n  2A6_{16} &= (2X16^2)+(AX16^1)+(6X16^0) \\\\\n  \\nonumber\n  &= (2X256)+(10X16)+(6X1) \\\\\n  \\nonumber\n  &= (512)+(160)+(6) \\\\\n  \\nonumber\n  &= 678_{10}\n\\end{align}\n\n\nIf the hexadecimal number has a fractional component, then that part would be converted using negative powers of $ 16 $. As an example, convert $ 1B.36_{16} $ to decimal:\n\n\\begin{align}\n  1B.36_{16} &= (1X16^1)+(11X16^0)+(3X16^{-1})+(6X16^{-2}) \\\\\n  \\nonumber\n  &= (16)+(11)+(3X\\frac{1}{16})+(6X\\frac{1}{256}) \\\\\n  \\nonumber\n  &= 16+11+0.1875+0.0234375 \\\\\n  \\nonumber\n  &= 27.2109375_{10}\n\\end{align}\n\nOther examples are:\n\n\\begin{align}\n  A32.1C_{16} &= (AX16^2)+(3X16^1)+(2X16^0)+(1X16^{-1})+(CX16^{-2}) \\\\\n  \\nonumber\n  &= (10X256)+(3X16)+(2X1)+(1X\\frac{1}{16})+(12X\\frac{1}{256}) \\\\\n  \\nonumber\n  &= 2560+48+2+0.0625+0.046875 \\\\\n  \\nonumber\n  &= 6300.109375_{10}\n\\end{align}\n\n\\begin{align}\n  439.A_{16} &= (4X16^2)+(3X16^1)+(9X16^0)+(AX16^{-1}) \\\\\n  \\nonumber\n  &= (4X256)+(3X16)+(9X1)+(10X\\frac{1}{16}) \\\\\n  \\nonumber\n  &= 1024+48+9+0.625 \\\\\n  \\nonumber\n  &= 1081.625_{10}\n\\end{align}\n\n\\subsection{Decimal to Binary} \n\\label{MF:sub:decimal_to_binary}\n\\subsubsection{Integers} \n\\label{MF:subsub:decimal_to_binary_integers}\n\n\\marginpar{Note: Converting decimal fractions is a bit different and is covered on page \\pageref{MF:subsub:decimal_to_binary_fractions}.} Converting decimal integers to binary (indeed, any other radix) involves repeated cycles of division. In the first cycle of division, the original decimal integer is divided by the base of the target numeration system (binary=$ 2 $, octal=$ 8 $, hex=$ 16 $), and then the whole-number portion of the quotient is divided by the base value again. This process continues until the quotient is less than one. Finally, the binary, octal, or hexadecimal digits are determined by the ``remainders'' left over at each division step. \\marginpar{After a decimal number is converted to binary it can be easily converted to either octal or hexadecimal.}\n\nTable \\ref{MF:tab:dec_to_bin_integer} shows how to convert $ 87_{10} $ to binary by repeatedly dividing $ 87 $ by $ 2 $ (the radix for binary) until reaching zero. The number in column one is divided by two and that quotient is placed on the next row in column one with the remainder in column two. For example, when $ 87 $ is divided by $ 2 $, the quotient is $ 43 $ with a remainder of one. This division process is continued until the quotient is less than one. When the division process is completed, the binary number is found by using the remainders, \\emph{reading from the bottom to top}. Thus $ 87_{10} $ is $ 1010111_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}{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n      87 &  \\\\\n      43 & 1 \\\\\n      21 & 1 \\\\\n      10 & 1 \\\\\n      5 & 0 \\\\\n      2 & 1 \\\\\n      1 & 0 \\\\\n      0 & 1 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Binary}\n  \\label{MF:tab:dec_to_bin_integer}\n\\end{table}\n\nThis repeat-division technique will also work for numeration systems other than binary. To convert a decimal integer to octal, for example, divide each line by $ 8 $; but follow the process as described above. As an example, Table \\ref{MF:tab:dec_to_oct} shows how to convert $ 87_{10} $ to $ 127_8 $.\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}{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n      87 &  \\\\\n      10 & 7 \\\\\n      1 & 2 \\\\\n      0 & 1 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Octal}\n  \\label{MF:tab:dec_to_oct}\n\\end{table}\n\nThe same process can be used to convert a decimal integer to hexadecimal; except, of course, the divisor would be $ 16 $. Also, some of the remainders could be greater than $ 10 $, so these are written as letters. For example, to convert $ 678_{10} $ to $ 2A6_{16} $ use the process illustrated in Table \\ref{MF:tab:dec_to_hex}.\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}{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n      678 &  \\\\\n      42 & 6 \\\\\n      2 & A \\\\\n      0 & 2 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Hexadecimal}\n  \\label{MF:tab:dec_to_hex}\n\\end{table}\n\n\\subsubsection{Fractions}\n\\label{MF:subsub:decimal_to_binary_fractions}\nConverting decimal fractions to binary is a repeating operation similar to converting decimal integers, but each step repeats multiplication rather than division. To convert $ 0.8215_{10} $ to binary, repeatedly multiply the fractional part of the number by two until the fractional part is zero (or whatever degree of precision is desired). As an example, in Table \\ref{MF:tab:dec_to_bin_fraction}, the number in column two, $ 8215 $, is multiplied by two and the integer part of the product is placed in column one on the next row while the fractional part in column two. Keep in mind that the ``Remainder'' is a decimal fraction with an assumed leading decimal point. That process continues until the fractional part reaches zero.\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}{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n        & 8125 \\\\\n      1 & 625 \\\\\n      1 & 25 \\\\\n      0 & 5 \\\\\n      1 & 0 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Binary Fraction}\n  \\label{MF:tab:dec_to_bin_fraction}\n\\end{table}\n\nWhen the multiplication process is completed, the binary number is found by using the integer parts and \\emph{reading from the top to the bottom}. Thus $ 0.8125_{10} $ is $ 0.1101_2 $.\n\nAs another example, Table \\ref{MF:tab:dec_to_bin_fraction_example_2} converts $ 0.78125_{10} $ to $ 0.11001_2 $. The solution was carried out to full precision (that is, the last multiplication yielded a fractional part of zero).\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}[htb]{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n        & 78125 \\\\\n      1 & 5625 \\\\\n      1 & 125 \\\\\n      0 & 25 \\\\\n      0 & 5 \\\\\n      1 & 0 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Binary Fraction Example}\n  \\label{MF:tab:dec_to_bin_fraction_example_2}\n\\end{table}\n\nOften, a decimal fraction will create a huge binary fraction. In that case, continue the multiplication until the desired number of binary places are achieved. As an example, in Table \\ref{MF:tab:dec_to_bin_long_fraction}, the fraction $ 0.1437_{10} $ was converted to binary, but the process stopped after $ 10 $ bits.\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}{ c c } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n      & 1437 \\\\\n      0 & 2874 \\\\\n      0 & 5748 \\\\\n      1 & 1496 \\\\\n      0 & 2992 \\\\\n      0 & 5984 \\\\\n      1 & 1968 \\\\\n      0 & 3936 \\\\\n      0 & 7872 \\\\\n      1 & 5744 \\\\\n      1 & 1488 \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Decimal to Long Binary Fraction}\n  \\label{MF:tab:dec_to_bin_long_fraction}\n\\end{table}\n\nThus, $ 0.1437_{10} = 0.0010010011_2 $ (with $ 10 $ bits of precision). \\marginpar{To calculate this to full precision requires $ 6617 $ bits; thus, it is normally wise to specify the desired precision.}\n\nConverting decimal fractions to any other base would involve the same process, but the base is used as a multiplier. Thus, to convert a decimal fraction to hexadecimal multiply each line by $ 16 $ rather than $ 2 $. \n\n \\subsubsection{Mixed Numbers}\n \\label{MF:subsub:decimal_to_binary_mixednumbers}\n To convert a mixed decimal number (one that contains both an integer and fraction part) to binary, treat each component as a separate problem and then combine the result. As an example, Table \\ref{MF:tab:dec_to_bin_mixed_integer_part} and Table \\ref{MF:tab:dec_to_bin_mixed_fraction_part} show how to convert $ 375.125_{10} $ to $ 1 0111 0111.001_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}{ c c } \n       \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n       375 &  \\\\\n       187 & 1 \\\\\n       93 & 1 \\\\\n       46 & 1 \\\\\n       23 & 0 \\\\\n       11 & 1 \\\\\n       5 & 1 \\\\\n       2 & 1 \\\\\n       1 & 0 \\\\\n       0 & 1 \\\\ \\hline\n     \\end{tabular}\n   \\end{center}\n   \\caption{Decimal to Binary Mixed Integer}\n   \\label{MF:tab:dec_to_bin_mixed_integer_part}\n \\end{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}{ c c } \n       \\hline\n      \\rowcolor{black!75}\n      \\head{Integer} & \\head{Remainder} \\\\\n       & 125 \\\\\n       0 & 25 \\\\\n       0 & 5 \\\\\n       1 & 0 \\\\ \\hline\n     \\end{tabular}\n   \\end{center}\n    \\caption{Decimal to Binary Mixed Fraction}\n    \\label{MF:tab:dec_to_bin_mixed_fraction_part}\n    \\end{table} \n \n A similar process could be used to convert decimal numbers into octal or hexadecimal, but those radix numbers would be used instead of two.\n \n \\subsection{Calculators}\n \\label{MF:sub:calculators}\n For the most part, converting numbers between the various ``computer'' bases (binary, octal, or hexadecimal) is done with a calculator. Using a calculator is quick and error-free. However, for the sake of applying digital logic to a mathematical problem, it is essential to understand the theory behind converting bases. It will not be possible to construct a digital circuit where one step is ``calculate the next answer on a hand-held calculator.'' Conversion circuits (like all circuits) need to be designed with simple gate logic, and an understanding of the theory behind the conversion process is important for that type of problem. \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{Online Conversion Tool}}\n   % Lower half of the box: the content\n   \\tcblower\n   Excel will convert between decimal/binary/octal/hexadecimal integers (including negative integers), but cannot handle fractions; however, the following website has a conversion tool that can convert between common bases, both integer and fraction: \\url{http://baseconvert.com/}. An added benefit for this site is conversion with twos complement, which is how negative binary numbers are represented and is covered on page \\pageref{MO:subsub:signed_complement}.\n \\end{tcolorbox}\n % End Sidebar Box\n \n \\subsection{Practice Problems}\n \\label{MF:sub:practice_problems_convert_dec_bin_oct_hex}\n Table \\ref{MF:tab:practice_problems_convert_dec_bin_oct_hex} lists several numbers in decimal, binary, octal, and hexadecimal form. To practice converting between numbers, select a number on any row and then covert it to the other bases.\n \n \\begin{footnotesize}\n \\begin{table}[H]\n   \\sisetup{input-digits={0123456789ABCDEF}}\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}{ S S S S } \n       \\hline\n       \\rowcolor{black!75}\n       \\head{Decimal} & \\head{Binary} & \\head{Octal} & \\head{Hexadecimal} \\\\\n       \\hline\n       13.        & 1101.         & 15.    & D.    \\\\\n       1872.      & 11101010000.  & 3520.  & 750.  \\\\\n       0.0625     & 0.0001        & 0.04   & 0.1   \\\\\n       0.45703125 & 0.01110101    & 0.352  & 0.75  \\\\\n       43.125     & 101011.001    & 53.1   & 2B.2  \\\\\n       108.71875  & 1101100.10111 & 154.56 & 6C.B8 \\\\\n       \\hline\n     \\end{tabular}\n   \\end{center}\n   \\caption{Practice Problems}\n  \\label{MF:tab:practice_problems_convert_dec_bin_oct_hex}\n \\end{table} \n \\end{footnotesize}\n \n\\section{Floating Point Numbers}\n\\label{MF:sec:floating_point_numbers}\n\nNumbers can take two forms: Fixed Point and Floating Point. A fixed point number generally has no fractional component and is used for integer operations (though it is possible to design a system with a fixed fractional width). On the other hand, a floating point number has a fractional component with a variable number of places.\n\nBefore considering how floating point numbers are stored in memory and manipulated, it is important to recall that any number can be represented using \\emph{scientific notation}. Thus, $ 123.45_{10} $ can be represented as $ 1.2345 X 10^2 $ and $ 0.0012345_{10} $ can be represented as $ 1.2345 X 10^{-3} $. Numbers in scientific notation with one place to the left of the radix point, as illustrated in the previous sentence, are considered \\emph{normalized}. While most people are familiar with normalized decimal numbers, the same process can be used for any other base, including binary. Thus, $ 1101.101_2 $ can be written as $ 1.101101 X 2^3 $. Notice that for normalized binary numbers the radix is two rather than ten since binary is a radix two system, also there is only one bit to the left of the radix point.\n\n\\marginpar{\\ac{IEEE} Standard 754 defines Floating Point Numbers} By definition, floating point numbers are stored and manipulated in a computer using a 32-bit word (64 bits for ``double precision'' numbers). For this discussion, imagine that the number $ 10010011.0010_2 $ is to be stored as a floating point number. That number would first be normalized to $ 1.00100110010 X 2^7 $ and then placed into the floating point format:\n\n\\begin{verbatim}\n     x    xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx\n     sign exponent mantissa\n\\end{verbatim}\n\n\\begin{itemize}\n  \\item \\textsc{Sign}: The sign field is a single bit that is zero for a positive number and one for a negative number. Since the example number is positive the sign bit is zero.\n\n  \\item \\textsc{Exponent}: This is an eight-bit field containing the radix’s exponent, or $ 7 $ in the example. However, the field must be able to contain both positive and negative exponents, so it is offset by $ 127 $. The exponent of the example, $ 7 $, is stored as $ 7 + 127 $, or $ 134 $; therefore, the exponent field contains $ 10000110 $. \n\n  \\item \\textsc{Mantissa} (sometimes called \\emph{significand}): This 23-bit field contains the number that is being stored, or $ 100100110010 $ in the example. While it is tempting to just place that entire number in the mantissa field, it is possible to squeeze one more bit of precision from this number with a simple adjustment. A normalized binary number will always have a one to the left of the radix point since in scientific notation a significant bit must appear in that position and one is the only possible significant bit in a binary number. Since the first bit of the stored number is assumed to be one it is dropped. Thus, the mantissa for the example number is $ 00100110010000000000000 $.\n\n\\end{itemize}\n\nHere is the example floating point number (the spaces have been added for clarity):\n\n\\begin{verbatim}\n     10010011.0010 = 0 10000110 00100110010000000000000\n\\end{verbatim}\n\nA few floating point special cases have been defined:\n\n\\begin{itemize}\n  \\item \\textsc{zero}: The exponent and mantissa are both zero and it does not matter whether the sign bit is one or zero. \n  \\item \\textsc{infinity}: The exponent is all ones and the mantissa is all zeros. The sign bit is used to represent either positive or negative infinity. \n  \\item \\textsc{\\ac{NaN}}: The exponent is all ones and the mantissa has at least one one (it does not matter how many or where). \\ac{NaN} is returned as the result of an illegal operation, like an attempted division by zero.\n\\end{itemize}\n\nTwo specific problems may show up with floating point calculations: \n\n\\begin{itemize}\n  \\item \\textsc{Overflow}. If the result of a floating point operation creates a positive number that is greater than $ (2-2^{-23})X 2^{127} $ it is a positive overflow or a negative number less than $ -(2-2^{-23})X 2^{127} $ it is a negative overflow. These types of numbers cannot be contained in a 32-bit floating point number; however, the designer could opt to increase the circuit to 64-bit numbers (called ``double precision'' floating point) in order to work with these large numbers.\n  \\item \\textsc{Underflow}. If the result of a floating point operation creates a positive number that is less than $ 2^{-149} $ it is a positive underflow or a negative number greater than $ -2^{-149} $ it is a negative underflow. These numbers are vanishingly small and are sometimes simply rounded to zero. However, in certain applications, such as multiplication problems, even a tiny fraction is important and there are ways to use ``denormalized numbers'' that will sacrifice precision in order to permit smaller numbers. Of course, the circuit designer can always opt to use 64-bit (``double precision'') floating point numbers which would permit negative exponents about twice as large as 32-bit numbers.\n\n\\end{itemize}\nTable \\ref{MF:tab:floating_point_example} contains a few example floating point numbers.\n\n\\begin{table}[H]\n  \\small\n  \\sffamily\n  {\\footnotesize }\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}{ S S l l } \n      \\hline\n      \\rowcolor{black!75}\n      \\head{{\\footnotesize Decimal}} & \\head{{\\footnotesize Binary}} & \\head{{\\footnotesize Normalized}} & \\head{{\\footnotesize Floating Point}} \\\\\n      \\hline\n      {\\footnotesize 34.5}    & {\\footnotesize 100010.1} & {\\footnotesize $ 1.000101 X 2^5 $} &\n      {\\footnotesize 0 10000100 00010100000000000000000} \\\\\n      {\\footnotesize 324.75}  & {\\footnotesize 101000100.11} & {\\footnotesize $ 1.0100010011 X 2^8 $} &\n      {\\footnotesize 0 10000111 01000100010000111101100} \\\\\n      {\\footnotesize -147.25} & {\\footnotesize 10010011.01} & {\\footnotesize $ 1.001001101 X 2^7 $} &\n      {\\footnotesize 1 10000110 00100110100000000000000} \\\\\n      {\\footnotesize 0.0625}  & {\\footnotesize 0.0001} & {\\footnotesize $ 1.0 X 2^{-4} $} &\n      {\\footnotesize 0 01111011 00000000000000000000000} \\\\ \\hline\n    \\end{tabular}\n  \\end{center}\n  \\caption{Floating Point Examples}\n  \\label{MF:tab:floating_point_example}\n\\end{table} \n", "meta": {"hexsha": "77bf929951a77178dda1d3926481bbb77e107abb", "size": 52684, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/02_Math_Foundations.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/02_Math_Foundations.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/02_Math_Foundations.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": 56.2262540021, "max_line_length": 887, "alphanum_fraction": 0.6869258219, "num_tokens": 15779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7401743735019595, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.630593634232407}}
{"text": "\\subsection{Totally bounded sets}\\label{subsec:totally_bounded_sets}\n\nLet \\( (X, \\rho) \\) be a \\hyperref[def:metric_space]{metric space}.\n\n\\begin{definition}\\label{def:epsilon_net}\n  We say that \\( E \\subseteq X \\) is an \\( \\varepsilon \\)-\\term{net} for the set \\( A \\subseteq X \\) if\n  \\begin{equation}\n    A \\subseteq \\bigcup_{x \\in E} B(x, \\varepsilon).\n  \\end{equation}\n\\end{definition}\n\n\\begin{definition}\\label{def:totally_bounded_set}\n  The space \\( A \\subseteq X \\) is called \\term{totally bounded} if any of the following equivalent conditions hold:\n\n  \\begin{thmenum}\n    \\thmitem{def:totally_bounded_set/sets} For every \\( \\varepsilon > 0 \\) there exists a finite cover of \\( A \\) with sets with diameter at most \\( \\varepsilon \\).\n    \\thmitem{def:totally_bounded_set/epsilon_net} For every \\( \\varepsilon > 0 \\) there exists a finite \\hyperref[def:epsilon_net]{\\( \\varepsilon \\)-net} of \\( A \\).\n    \\thmitem{def:totally_bounded_set/zero_noncompactness/sets} \\hyperref[def:noncompactness_measures/sets]{Kuratowski's noncompactness measure} \\( \\alpha(A) \\) is zero.\n    \\thmitem{def:totally_bounded_set/zero_noncompactness/balls} The \\hyperref[def:noncompactness_measures/balls]{ball noncompactness measure} \\( \\beta(A) \\) is zero.\n    \\thmitem{def:totally_bounded_set/fundamental_subsequences} Every sequence in \\( A \\) admits a \\hyperref[def:fundamental_net]{fundamental subsequence}.\n  \\end{thmenum}\n\n  Totally bounded sets are sometimes called \\term{\\hyperref[def:compact_space]{precompact}} because of \\fullref{thm:metric_compact_iff_sequentially_compact}. This equivalence requires the metric space to be complete, however.\n\\end{definition}\n\\begin{proof}\n  \\EquivalenceSubProof{def:totally_bounded_set/sets}{def:totally_bounded_set/zero_noncompactness/sets} Straightforward.\n\n  \\EquivalenceSubProof{def:totally_bounded_set/epsilon_net}{def:totally_bounded_set/zero_noncompactness/balls} Straightforward.\n\n  \\ImplicationSubProof{def:totally_bounded_set/epsilon_net}{def:totally_bounded_set/sets} Given \\( \\varepsilon > 0 \\), any cover of \\( A \\) with balls of radius \\( \\frac \\varepsilon 2 \\) is a cover with sets of diameter \\( \\varepsilon \\).\n\n  \\ImplicationSubProof{def:totally_bounded_set/sets}{def:totally_bounded_set/epsilon_net} Fix \\( \\varepsilon > 0 \\) and \\( \\rho \\in (0, \\varepsilon) \\) and let \\( A_1, \\ldots, A_n \\subseteq \\pow X \\) be a finite cover of \\( A \\) with sets of diameter at most \\( \\rho \\).\n\n  Choose a point \\( x_k \\) from every \\( A_k \\), \\( k = 1, \\ldots, n \\). We then have that for every \\( k = 1, \\ldots, n \\),\n  \\begin{balign*}\n    A_k \\subseteq \\cl B(x_k, \\rho) \\subsetneq B(x_k, \\varepsilon)\n    \\\\\n    \\implies A \\subseteq \\bigcup_{k=1}^n A_k \\subseteq \\bigcup_{k=1}^n B(x_k, \\rho) \\subsetneq \\bigcup_{k=1}^n B(x_k, \\varepsilon),\n  \\end{balign*}\n  hence \\( x_1, \\ldots, x_n \\) are centers of \\( \\varepsilon \\)-balls that cover \\( A \\).\n\n  \\ImplicationSubProof{def:totally_bounded_set/epsilon_net}{def:totally_bounded_set/fundamental_subsequences} Let \\( \\{ x_n \\} \\subseteq A \\) be any sequence.\n\n  If we assume that \\( \\{ x_n \\} \\) has no fundamental subsequence, then there exists \\( \\varepsilon_0 > 0 \\) such that \\( \\rho(x_k, x_m) > \\varepsilon_0 \\) for any \\( n, m \\in \\BbbZ_{>0} \\).\n\n  Consider a finite cover of \\( A \\) with \\( \\varepsilon_0 \\)-balls. By the pigeonhole principle, at least one of the balls contains more than one element of the sequence, which contradicts the assumption that all elements of the sequence have a distance of at least \\( \\varepsilon_0 \\).\n\n  Hence, an arbitrary sequence in \\( A \\) has a fundamental subsequence.\n\n  \\ImplicationSubProof{def:totally_bounded_set/fundamental_subsequences}{def:totally_bounded_set/epsilon_net} Assume that there exists \\( \\varepsilon_0 > 0 \\), such that \\( A \\) admits no finite cover by \\( \\varepsilon_0 \\)-balls.\n\n  Define \\( x_1 \\in X, x_2 \\in X \\setminus B(x_1, \\varepsilon_0), \\ldots \\), so that every two elements of the sequence \\( \\{ x_n \\} \\) have a distance of at least \\( \\varepsilon_0 \\). But then the sequence is does not admit a fundamental subsequence, which contradicts our assumption.\n\n  This contradiction proves that \\( A \\) admits a finite cover by \\( \\varepsilon \\)-balls for every \\( \\varepsilon > 0 \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:metric_space_compact_iff_closed_totally_bounded}\n  Assume that \\( X \\) is complete. The set \\( A \\subseteq X \\) is sequentially compact if and only if it is closed and totally bounded.\n\\end{corollary}\n\\begin{proof}\n  The property that every sequence has a fundamental subsequence is equivalent to sequential compactness for a closed set in a complete metric space.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:totally_bounded_sets_are_bounded}\n  Totally bounded sets are bounded.\n\\end{proposition}\n\\begin{proof}\n  Fix a totally bounded set \\( A \\subseteq X \\). Let \\( \\varepsilon > 0 \\) and let \\( x_1, x_2, \\ldots, x_n \\) be a finite \\hyperref[def:totally_bounded_set/epsilon_net]{\\( \\varepsilon \\)-net} of \\( A \\). The distance between two points of the \\( \\varepsilon \\)-net is at most \\( 2\\varepsilon \\). Then\n  \\begin{equation*}\n    A \\subseteq \\bigcup_{i=1}^n B(x_i, \\varepsilon) \\subseteq B(x_i, 2 n \\varepsilon).\n  \\end{equation*}\n\n  Hence, \\( A \\) is \\hyperref[def:metric_space/bounded_set]{bounded}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:closure_of_totally_bounded_is_totally_bounded}\n  If a set \\( A \\subseteq X \\) is totally bounded, then, so is its closure \\( \\cl A \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\varepsilon > 0 \\) and \\( \\rho \\in (0, \\varepsilon) \\) and let \\( x_1, \\ldots, x_n \\in X \\) be the centers of a cover of \\( A \\) with \\( \\rho \\)-balls.\n\n  If \\( y \\) is a point in \\( \\cl A \\setminus A \\), there exists a point \\( z \\in A \\) with \\( \\rho(y, z) < \\varepsilon - \\rho \\). Let \\( x_k \\in A \\) be one of the centers whose \\( \\rho \\)-balls contain \\( z \\). We then have that \\( y \\in B(x_k, \\varepsilon) \\) since\n  \\begin{equation*}\n    \\rho(x_k, z) \\leq \\rho(x_k, y) + \\rho(y, z) < \\rho + \\varepsilon - \\rho = \\varepsilon.\n  \\end{equation*}\n\n  Hence, the balls \\( \\cl B(x_k, \\varepsilon) \\) cover \\( \\cl A \\), i.e.\n  \\begin{equation*}\n    \\cl A \\subseteq \\bigcup_{k=1}^n B(x_k, \\varepsilon).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{lemma}[Lebesgue's covering lemma]\\label{thm:lebesgues_covering_lemma}\n  Assume that \\( X \\) is complete. Let \\( A \\subseteq X \\) be sequentially compact. Given an open cover \\( \\mathcal{F} \\subseteq \\pow A \\), there exists a number \\( \\delta > 0 \\) such that every \\( \\delta \\)-ball with a center in \\( A \\) is contained in some set of the cover \\( \\mathcal{F} \\).\n\\end{lemma}\n\\begin{proof}\n  Assume that no such number \\( \\delta > 0 \\) exists. Then for any natural number \\( n \\in \\BbbZ_{>0} \\), there exists an element \\( x_n \\in A \\) such that the ball \\( B(x_n, \\frac 1 n) \\) is not contained in any set of the cover \\( \\mathcal{F} \\). Since \\( A \\) is sequentially compact, the sequence \\( \\{ x_n \\}_n \\) contains a convergent subsequence \\( \\{ x_{n_k} \\}_k \\).\n\n  Define\n  \\begin{equation*}\n    x \\coloneqq \\lim_{k \\to \\infty} x_{n_k}.\n  \\end{equation*}\n\n  Let \\( E \\) be a set in \\( \\mathcal{F} \\) that contains \\( x \\). Since \\( E \\) is open, there exists some radius \\( r > 0 \\) such that \\( B(x, r) \\subseteq E \\).\n\n  Choose any \\( k_0 > \\frac 2 r \\) such that \\( \\rho(x_{n_{k_0}}, x) < \\frac r 2 \\). By the triangle inequality,\n  \\begin{equation*}\n    B \\left(x_{n_k}, \\frac 1 k \\right) \\subsetneq B \\left(x_k, \\frac r 2 \\right) \\subseteq B(x, r) \\subseteq E,\n  \\end{equation*}\n  which contradicts the choice of the sequence \\( \\{ x_n \\}_n \\).\n\n  Hence, there exists a \\( \\delta > 0 \\) such that for every \\( x \\in A \\), the ball \\( B(x, \\delta) \\) is contained in some element \\( E \\) of the cover \\( \\mathcal{F} \\).\n\\end{proof}\n\n\\begin{theorem}\\label{thm:metric_compact_iff_sequentially_compact}\n  Assume that \\( X \\) is complete. The set \\( A \\subseteq X \\) is compact if and only if it is sequentially compact.\n\\end{theorem}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( \\mathcal{F} \\subseteq \\pow X \\) be an open cover of \\( A \\).\n\n  By \\fullref{thm:lebesgues_covering_lemma}, there exists \\( \\delta > 0 \\) such that for every \\( x \\in A \\), the ball \\( B(x, \\delta) \\) is contained in some set of the cover \\( \\mathcal{F} \\). Let \\( x_1, \\ldots, x_n \\) be a cover of \\( A \\) with \\( \\delta \\)-balls.\n\n  For each \\( k = 1, \\ldots, n \\) we have that the ball \\( B(x_k, \\delta) \\) is contained in some set \\( E_k \\in \\mathcal{F} \\). Hence, \\( E_1, \\ldots, E_n \\) is a finite subcover of \\( A \\), because\n  \\begin{equation*}\n    A \\subseteq \\bigcup_{k=1}^\\infty B(x_k, \\delta) \\subseteq \\bigcup_{k=1}^\\infty E_k.\n  \\end{equation*}\n\n  Thus, \\( A \\) is compact.\n\n  \\NecessitySubProof Let \\( A \\) be compact. Fix \\( \\varepsilon > 0 \\) and take the cover\n  \\begin{equation*}\n    \\mathcal{F} \\coloneqq \\{ B(a, \\varepsilon) \\colon a \\in A \\}.\n  \\end{equation*}\n\n  By compactness of \\( A \\), there exists a finite subcover. Thus, a finite cover of \\( A \\) with \\( \\varepsilon \\)-balls exists for every \\( \\varepsilon > 0 \\). \\Fullref{def:totally_bounded_set} then implies that total boundedness is equivalent to sequential compactness because \\( X \\) is complete and \\( A \\) is closed.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:complete_metric_space_compact_conditions}\n  The following are equivalent for a set \\( A \\) in complete metric space:\n  \\begin{thmenum}\n    \\thmitem{thm:complete_metric_space_compact_conditions/compact} \\( A \\) is \\hyperref[def:compact_space]{compact}\n    \\thmitem{thm:complete_metric_space_compact_conditions/sequentially_compact} \\( A \\) is sequentially \\hyperref[def:compact_space/convergent_nets]{compact}.\n    \\thmitem{thm:complete_metric_space_compact_conditions/closed_totally_bounded} \\( A \\) is closed and totally \\hyperref[def:totally_bounded_set]{bounded}.\n  \\end{thmenum}\n\\end{corollary}\n\\begin{proof}\n  \\EquivalenceSubProof{thm:complete_metric_space_compact_conditions/compact}{thm:complete_metric_space_compact_conditions/sequentially_compact} The equivalence is given by \\fullref{thm:metric_compact_iff_sequentially_compact}.\n\n  \\ImplicationSubProof{thm:complete_metric_space_compact_conditions/sequentially_compact}{thm:complete_metric_space_compact_conditions/closed_totally_bounded} The equivalence is given by \\fullref{thm:metric_space_compact_iff_closed_totally_bounded}.\n\\end{proof}\n", "meta": {"hexsha": "b2b4b6431d862bb17a70d0efdf18de43f66554ef", "size": 10390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/totally_bounded_sets.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/totally_bounded_sets.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/totally_bounded_sets.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.8079470199, "max_line_length": 375, "alphanum_fraction": 0.6992300289, "num_tokens": 3346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6305936258576573}}
{"text": "% -----------------------------------------------\n% chktex-file 44\n\\documentclass[../index.tex]{subfiles}\n\n% -----------------------------------------------\n\n\\begin{document}\n\n% -----------------------------------------------\n\\renewcommand{\\sectiontitle}{A memory refresher}\n\\section{\\sectiontitle}\n% Before we get into how computers handle text, we need to talk about memory.\n\n% ---------------------------\n\\renewcommand{\\currenttitle}{Bits and bytes}\n\\begin{frame}{\\currenttitle}\n% Computers store information bits, a portmanteau of \"binary digit\", which represent an \"on\"\n% and an \"off\" state in the abstract sense.\n%\n% In the physical device, this might be two stable states of a flip-flop, two positions of an\n% electrical switch, two distinct voltage or current levels allowed by a circuit, two distinct\n% levels of light intensity.\n  Computers store information in \\textbf{bits} (0 or 1 / \\texttt{TRUE} or \\texttt{FALSE})\n  \\vspace*{2em}\n\n  \\begin{table}\n    \\centering\n    \\begin{tabular}{c|c|c|c|c|c|c|c|c|c}\n      \\hline\n      \\dots & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 0 & \\dots \\\\\n      \\hline\n    \\end{tabular}\n    \\caption{Memory sketch}\n  \\end{table}\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}{\\currenttitle}\n% We can do binary logic operations on bits, which are the basis for other operations such as\n% addition and subtraction.\n  \\newcommand{\\false}{\\texttt{0}}\n  \\newcommand{\\true}{\\texttt{1}}\n\n  We can do binary logic and arithmetic with these:\n\n  \\begin{table}\n    \\begin{tabular}{c c c c}\n      a       & b       & op    & result  \\\\ \\hline\n      \\false  & \\true   & AND   & \\false  \\\\ % chktex 1\n      \\false  & \\true   & OR    & \\true   \\\\ % chktex 1\n      \\true   & \\true   & NAND  & \\false  \\\\ % chktex 1\n      \\false  & \\false  & NOR   & \\true   \\\\ % chktex 1\n      \\true   & \\true   & XOR   & \\false     % chktex 1\n    \\end{tabular}\n    \\caption{Logic binop inputs and results}\n  \\end{table}\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}{\\currenttitle}\n% Anyway, that's not really relevant to us at the moment.\n% As you probably know, a byte is equal to 8 bits.\n% This means there are 2^8 possible values contained in a single byte of data.\n%\n% In modern computers, memory is indexed by bytes. So while the bit is the smallest unit,\n% you're typically going to be concerned mostly with bytes.\n%\n% We can, and we will, use hexadecimal instead of binary. If you don't remember, hexadecimal\n% is base 16. The digits are 0 - 9, and then A - F representing 10 - 15. Since a byte is 8\n% binary digits, we can easily convert it into 2 hex digits by splitting it into 2 groups of\n% 4 binary digits and converting to hex.\n  A \\textbf{byte} is equal to 8 bits \\\\\n\n  This means possible values are in the interval [$0_{10}$, $255_{10}$] \\\\\n\n  \\begin{table}\n    \\centering\n    \\begin{tabular}{c|c|c|c|c|c|c|c}\n      \\hline\n      1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n      \\hline\n    \\end{tabular}\n    \\caption{A byte representing the value of 154\\textsubscript{10}, or \\hex{9A}}\n  \\end{table}\n\n  We can (and will) use 2 hexadecimal (base 16) numbers to represent a single byte\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}{\\currenttitle}\n% Think of some data types that you've used in your code.\n% This table has some of the sizes of Java primitives.\n%\n% An int in Java is a 32-bit integer, so it can store values from -2^31 to 2^31 - 1.\n% Because Java doesn't distinguish between unsigned and signed number values like C, Rust,\n% or other langauges do, the first bit is dedicated to indicating the sign.\n%\n% I'm not really going to get into how floating-point number types like float or double.\n%\n% Booleans, which are just a true/false value, should theoretically take up a single bit,\n% but note that JVM stores booleans to take up a byte. That's because memory is usually\n% indexed by bytes, increasing speed at the cost of a little bit of storage overhead.\n  \\begin{table}\n    \\begin{tabular}{c c c c}\n      type & description & bits & bytes \\\\\n      \\hline\n      boolean & true / false flag & 1 & 1\\footnotemark{} \\\\\n      char & 16-bit character & 16 & 2 \\\\\n      short & 16-bit integer & 16 & 2 \\\\\n      int & 32-bit integer & 32 & 4 \\\\\n      long & 64-bit integer & 64 & 8 \\\\\n      float & 32-bit floating-point & 32 & 4 \\\\\n      double & 64-bit floating-point & 64 & 8\n    \\end{tabular}\n    \\caption{Sizes of Java data types}\n  \\end{table}\n\n  \\footnotetext{In Java, booleans usually take up a byte for speed}\n\\end{frame}\n\n% ---------------------------\n\\renewcommand{\\currenttitle}{Big and little endianness}\n\\begin{frame}{\\currenttitle}\n% A type like Java's short, which is 32-bits, is going to take up 4 bytes of memory space.\n% Because of historical reasons, this can pose problems.\n%\n% Let's say you have the decimal integer 168496141. In binary, this is a long value.\n% We'll instead refer to it by its hexadecimal form: 0A0B0C0D. The largest byte is 0A,\n% then 0B, then 0C, and the smallest byte is 0D.\n%\n% We call 0A the most significant byte. It has the most significant value.\n% 0D is called the least significant byte.\n  \\textbf{MSB} \\textrightarrow{} Most Significant Byte \\\\\n  \\textbf{LSB} \\textrightarrow{} Least Significant Byte\n\n  \\vspace*{1em}\n\n  \\begin{figure}\n    \\begin{bytefield}{32}\n      \\bitboxes{8}{{MSB} {\\dots} {\\dots} {LSB}}\n    \\end{bytefield}\n    \\caption{Most and least significant bytes in a 4-byte word}\n  \\end{figure}\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}{\\currenttitle}\n% If you have a number like 168-million blah blah blah, which is 0A0B0C0D in hex,\n% 0A is the most significant byte, and 0D is the least significant byte.\n  \\(168496141_{10}\\) = \\hex{0A0B0C0D}\n\n  \\vspace*{1em}\n\n  \\begin{figure}\n    \\begin{bytefield}{32}\n      \\bitboxes{8}{{0A (MSB)} {0B} {0C} {0D (LSB)}}\n    \\end{bytefield}\n    \\caption{Most and least significant bytes in a \\hex{0A0B0C0D}}\n  \\end{figure}\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}[fragile]{\\currenttitle}\n% Different CPU architectures will read data differently.\n% Certain architectures, such IBM's z/Architecture and OpenRISC, read data starts from the\n% most significant byte to the least significant byte.\n% They would read 0A first, then 0B, then 0C, then 0D.\n%\n% Other architectures do the opposite.\n% Your computer, which likely has an AMD64 / Intel x86-64 architecture CPU, reads data from\n% the least significant byte to the most significant byte.\n% That means it reads 0D, then 0C, then 0B, then 0A.\n%\n% There are other architectures, like ARM64, which is growing in popularity, that are\n% bi-endian.\n%\n% Of course, this is how it would write to memory as well.\n  \\(168496141_{10}\\) = \\hex{0A0B0C0D}\n\n  \\vspace{0.5em}\n\n  \\newcommand{\\intbytefield}[5]{%\n    \\begin{figure}\n      \\begin{bytefield}{32}\n        \\bitheader{0-31} \\\\ % chktex 8\n        \\bitboxes{8}{{\\colorbox{black!20}{\\textbf{#2}}} {#3} {#4} {#5}}%\n      \\end{bytefield}\n      \\caption{#1}\n    \\end{figure}\n  }\n\n  \\intbytefield{Big endian memory layout}{0A (MSB)}{0B}{0C}{0D}\n\n  \\intbytefield{Little endian memory layout}{0D (LSB)}{0C}{0B}{0A}\n\\end{frame}\n\n% ---------------------------\n\\begin{frame}{\\currenttitle}\n% If you're curious about the etymology of 'endian', it comes from the 1762 satirical novel\n% Gulliver's Travels, by Jonathan Swift.\n% In one of Gulliver's journeys, he encounters a land of beings named Lilliputians.\n% The Lilliputians have divided into two sects, one that holds the belief that the shell of\n% a boiled egg should be broken from the big end, and the other from the little end.\n% They're called big-endian and little-endian, and computer scientists took those terms.\n% Lilliputian has also made it into the English dictionary and has the meaning tiny or trivial.\n  \\begin{itemize}[leftmargin=*]\n    \\item[] \\textbf{Endianness} \\textendash{} the order in which memory is written and read \\\\\n    \\item[] \\textbf{Big endianness} \\textendash{} most significant byte to least significant byte \\\\\n    \\item[] \\textbf{Little endianness} \\textendash{} least significant byte to most significant byte\n  \\end{itemize}\n\\end{frame}\n\n% ---------------------------\n\\renewcommand{\\currenttitle}{So what about text?}\n\\begin{frame}{\\currenttitle}\n% So we've talked a little bit about how something like an integer is stored in memory.\n% But what about text?\n% Everything is stored in 0's and 1's, so to store text, we'll need to basically convert text\n% into numbers or sequences of numbers.\n%\n% The conversion process is called text encoding.\n%\n% Now that we've got the necessary background to talk about text encoding, we'll start looking\n% at two text encoding standards, ASCII and Unicode.\n  We need to convert strings of text into numbers or sequences of numbers\n\n  \\vspace*{2em}\n\n  \\tikzstyle{block} = [rectangle, draw, text width=5em,%\n                       text centered, rounded corners, minimum height=4em]\n  \\tikzstyle{cloud} = [draw, ellipse, node distance=3cm, minimum height=2em]\n  \\tikzstyle{line} = [draw, -latex']\n  \\begin{center}\n    \\begin{figure}\n      \\begin{tikzpicture}[node distance=2cm, auto]\n        \\node [cloud, align=left] (input) {\"Hello \\\\ World\"};\n        \\node [block, right of=input, node distance=3cm] (process) {Conversion};\n        \\node [cloud, right of=process] (output) {\\dots011101\\dots};\n\n        \\path [line] (input) -- (process);\n        \\path [line] (process) -- (output);\n      \\end{tikzpicture}\n      \\caption{Sketch of text memory storage}\n    \\end{figure}\n  \\end{center}\n\\end{frame}\n\n\n% -----------------------------------------------\n\n\\end{document}\n", "meta": {"hexsha": "97de60a9290a522680324ab633998dc2ef0c25da", "size": 9546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/10-memory.tex", "max_stars_repo_name": "Dophin2009/textenc", "max_stars_repo_head_hexsha": "a317a942cd98313468daddf1c1d3c2c5ce7628b9", "max_stars_repo_licenses": ["MIT"], "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/10-memory.tex", "max_issues_repo_name": "Dophin2009/textenc", "max_issues_repo_head_hexsha": "a317a942cd98313468daddf1c1d3c2c5ce7628b9", "max_issues_repo_licenses": ["MIT"], "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/10-memory.tex", "max_forks_repo_name": "Dophin2009/textenc", "max_forks_repo_head_hexsha": "a317a942cd98313468daddf1c1d3c2c5ce7628b9", "max_forks_repo_licenses": ["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.880952381, "max_line_length": 100, "alphanum_fraction": 0.6514770585, "num_tokens": 2786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6305936133374248}}
{"text": "\\documentclass[a4paper,12pt]{article}\n%\\documentclass[a4paper,12pt]{scrartcl}\n\n\\usepackage{xltxtra}\n\n\\input{../preamble.tex}\n\n% \\usepackage[spanish]{babel}\n\n% \\setromanfont[Mapping=tex-text]{Linux Libertine O}\n% \\setsansfont[Mapping=tex-text]{DejaVu Sans}\n% \\setmonofont[Mapping=tex-text]{DejaVu Sans Mono}\n\n\\title{Homework \\#06: Multivariate distribution}\n\\author{Isaac Ayala Lozano}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\textbf{Problem 1.}\nPlot the Probability Density Function of a Multivariate Normal Distribution.\nConsider $x$ and $y$ as the random variables, $\\mu_x = 0, \\/ \\sigma_x^2 = 1$ and $\\mu_y = 1, \\/ \\sigma_y^2 = 2$.\\\\\n\nFrom \\cite{mathworld2020BivariateNormal}, the Bivariate Normal Distribution\n\\footnote{a multivariate distribution of two variables is known as a bivariate distribution}\nis defined as\n\n\\begin{equation}\n P(x_1, x_2) = \\frac{1}{2 \\pi \\sigma_1 \\sigma_2 \\sqrt{1-\\rho^2}} \\exp \\left [ - \\frac{z}{2 (1-\\rho^2)} \\right]\n \\label{eq: multi pdf}\n\\end{equation}\n\n\nwhere\n\n\\begin{align}\n\\label{eq: pdf z}\n z & \\equiv \\frac{(x_1-\\mu_1)^2}{\\sigma_1^2} - \\frac{2 \\rho (x_1 - \\mu_1)(x_2 - \\mu_2)}{\\sigma_1 \\sigma_2} + \\frac{(x_2-\\mu_2)^2}{\\sigma_2^2}\\\\\n  \\rho & \\equiv cor(x_1, x_2) = \\frac{V_{12}}{\\sigma_1 \\sigma_2} = \\frac{\\sigma_{11}\\sigma_{21} + \\sigma_{12}\\sigma_{22}}{\\sigma_1 \\sigma_2}\n\\end{align}\n\nGiven that $\\sigma_{i\\/j} = 0, \\/ i \\neq j $, then $\\rho = 0$ and \\eqref{eq: multi pdf} can be rewritten as\n\n\\begin{equation}\n P(x_1, x_2) = \\frac{1}{2\\pi \\sigma_1 \\sigma_2} \\exp \\left[- \\frac{z}{2}  \\right]\n\\end{equation}\n\nIn a similar fashion, \\ref{eq: pdf z} can be rewritten as\n\n\\begin{equation}\n z = \\frac{(x_1-\\mu_1)^2}{\\sigma_1^2} + \\frac{(x_2-\\mu_2)^2}{\\sigma_2^2}\n\\end{equation}\n\n\nFigure \\ref{fig: multi} presents the PDF for the given values, employing the built-in function \\emph{mvnpdf} and an implementation of the equations developed previously.\n\n\\begin{figure}[htb!]\n\\centering\n\\import{./img/}{hw06_multi.tex}\n\\caption{Multivariate Normal Distribution.}\n\\label{fig: multi}\n\\end{figure}\n\n\\pagebreak\n\n\\textbf{Problem 2}\nPlot the distributions $F_X$ and $F_Y$ of the function in problem 1.\\\\\n\nGiven that $x$ and $y$ are independent random variables with a normal distribution, both $F_X$ and $F_Y$ are obtained evaluating the normal pdf with their respective values.\nFigure \\ref{fig: normal} shows the plots for both of them.\n\n\\begin{figure}[htb!]\n\\centering\n\\import{./img/}{hw06_normal.tex}\n\\caption{Distributions $F_X$ and $F_Y$.}\n\\label{fig: normal}\n\\end{figure}\n\n\\pagebreak\n\\textbf{Problem 3}\nWhat would the plot of Multivariate Normal Distribution of 3 variables look like?\\\\\n\nA 3D plot would be insufficient to visualize the distribution, given that it would be in 4D.\nAn approximation in 3D would be slices of the volume with a colormap on its surface to express the values of $P(x, y, z)$ at every coordinate, as shown in figure \\ref{fig: slice}.\n\n\\begin{figure}[htb!]\n\\centering\n\\import{./img/}{hw06_slice.tex}\n\\caption{Slice visualization of $P(x, y, z)$ at $x, y, z = 0$.}\n\\label{fig: slice}\n\\end{figure}\n\n\n\\pagebreak\n\n\\printbibliography\n\n\\pagebreak\n\\appendix\n\\section{Octave Code}\n\\lstinputlisting[language=Matlab]{hw06_plots.m}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "977652549887e20166e88831b04da25b7dea3cbf", "size": 3196, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw06_IsaacAyala.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": "hw06_IsaacAyala.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": "hw06_IsaacAyala.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": 29.8691588785, "max_line_length": 179, "alphanum_fraction": 0.7124530663, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.6305936105272228}}
{"text": "\\documentclass[en,12pt]{elegantpaper}\n\n\\begin{document}\n    \\section*{5}\n    \\noindent When $\\eta=1$, \n    \\[\n        f(\\mathbf{x})=1\\Big/\\prod(x_i)\\exp\\left(\\log\\theta\\sum_{i=1}^nx_i-n\\theta\\right), \n    \\]\n    for $\\mathbf{y}\\neq\\mathbf{x}$, \n    \\[\n        \\frac{f(\\mathbf{x})}{f(\\mathbf{y})}=\\frac{\\prod y_i}{\\prod x_i}\\exp\\left(\\log\\theta \\left(\\sum_{i=1}^nx_i-\\sum_{i=1}^ny_i\\right)\\right). \n    \\]\n    So, $T_1(X)=\\sum_{i=1}^nX_i$ is the minimal sufficient statistic for $\\theta$. \n    \n    \\, \n\n    \\noindent When $\\eta=2$, \n    \\[\n        f(\\mathbf(x))=\\theta^{\\sum x_i}(1-\\theta)^{n-\\sum x_i}, \n    \\]\n    for $\\mathbf{y}\\neq\\mathbf{x}$, \n    \\[\n        \\frac{f(\\mathbf{x})}{f(\\mathbf{y})}=\\theta^{\\sum x_i-\\sum y_i}(1-\\theta)^{\\sum y_i-\\sum x_i}. \n    \\]\n    So, $T_2(X)=\\sum_{i=1}^nX_i$ is a minimal sufficient statistic for $\\theta$. \n\n    \\,\n\n    \\noindent Overall, $T(X)=\\sum_{i=1}^{n}X_i$ is the minimal sufficient statistic for $(\\theta, \\eta)$. \n\n\\end{document}", "meta": {"hexsha": "ddbef0b961484cc5030d3993f5497847ed58b766", "size": 979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/midterm1/5.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/5.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/5.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": 31.5806451613, "max_line_length": 145, "alphanum_fraction": 0.5526046987, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6305637766053269}}
{"text": "\\section{Recurrence and Transience}\r\n\\begin{definition}\r\n    Let $(X_n)$ be a Markov chain.\r\n    A state $i\\in I$ is recurrent if\r\n    $$\\mathbb P_i[X_n=i\\text{ infinitely often}]=1$$\r\n    It is transient if\r\n    $$\\mathbb P_i[X_n=i\\text{ infinitely often}]=0$$\r\n\\end{definition}\r\nRecall the first passage time to $j$ is $T_j=\\inf\\{n\\ge 1:X_n=j\\}$.\r\n\\begin{theorem}\\label{recur_trans}\r\n    If $\\mathbb P_i[T_i<\\infty]=1$, then $i$ is recurrent and\r\n    $$\\sum_{n=0}^\\infty p_{ii}^{(n)}=\\infty$$\r\n    Otherwise, $i$ is transient and\r\n    $$\\sum_{n=0}^\\infty p_{ii}^{(n)}<\\infty$$\r\n\\end{theorem}\r\n\\begin{corollary}\r\n    Any state is either recurrent or transient, but not both.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from the theorem.\r\n\\end{proof}\r\nTo prove the theorem, we need to do some ground work.\r\nInductively, we define the $r^{th}$ passage time to $j$ to be $T_j^{(0)}=0$ and\r\n$$T_j^{(r+1)}=\\inf\\{n\\ge T_j^{(r)}+1:X_n=j\\}$$\r\nEasily $T_j^{(1)}=T_j$.\r\nThe length of the $r^{th}$ excursion is defined by\r\n$$S_i^{(r)}=\\begin{cases}\r\n    T_i^{(r)}-T_i^{(r-1)}\\text{, if $T_i^{(r-1)}<\\infty$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\n\\begin{lemma}\\label{tisi}\r\n    For $r=2,3,\\ldots$, conditional on $T_i^{(r-1)}<\\infty$, the length of the $r^{th}$ excursion $S_i^{(r)}$ is independent of $\\{X_m:m<T_i^{(r-1)}\\}$ and\r\n    $$\\mathbb P[S_i^{(r)}=n|T_i^{(r-1)}<\\infty]=\\mathbb P_i[T_i=n]$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Quite obvious, but let's write it.\r\n    Conditional on $T_i^{(r-1)}<\\infty$, by Theorem \\ref{strong_markov}, we have\r\n    $$(X_{T_i^{(r-1)}+n})_{n\\ge 0}\\sim\\operatorname{Markov}(\\delta_i,P)$$\r\n    and is independent of $X_0,\\ldots,X_{T_i^{(r-1)}}$.\r\n    Now we can rewrite\r\n    $$S_i^{(r)}=\\inf\\{n\\ge 1:X_{T_i^{(r-1)}+n}=i\\}$$\r\n    which makes it the first passage time of $(X_{T_i^{(r-1)}+n})_{n\\ge 0}$.\r\n    We are essentially done.\r\n\\end{proof}\r\nNow let $V_i$ denote the number of visits to $i$, that is\r\n$$V_i=\\sum_{n=0}^\\infty 1_{X_n=i}\\implies \\mathbb E_i[V_i]=\\mathbb E_i\\left[ \\sum_{n=0}^\\infty 1_{X_n=i} \\right]=\\sum_{n=0}^\\infty\\mathbb P_i[X_n=i]=\\sum_{n=0}^\\infty p_{ii}^{(n)}$$\r\nLet $f_i$ be the return probability to $i$, that is $f_i=\\mathbb P_i[T_i<\\infty]$.\r\n\\begin{lemma}\\label{vifi}\r\n    For $r=0,1,2,\\ldots$, we have $\\mathbb P_i[V_i>r]=f_i^r$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Note that $\\{V_i>r\\}=\\{T_i^{(r)}<\\infty\\}$ if $X_0=i$.\r\n    Also note that $\\mathbb P_i[V_i>0]=1$.\r\n    If $\\mathbb P_i[V_i>r]=f_i^r$ for some $r$, then by Lemma \\ref{tisi},\r\n    \\begin{align*}\r\n        \\mathbb P_i[V_i>r+1]&=\\mathbb P_i[T_i^{(r+1)}<\\infty]\\\\\r\n        &=\\mathbb P_i[T_i^{(r)}<\\infty,S_i^{(r+1)}<\\infty]\\\\\r\n        &=\\mathbb P_i[T_i^{(r)}<\\infty]\\mathbb P[S_i^{(r+1)}<\\infty|T_i^{(r)}<\\infty]\\\\\r\n        &=f_i^rf_i=f_i^{r+1}\r\n    \\end{align*}\r\n    We conclude this by induction.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{recur_trans}]\r\n    If $\\mathbb P_i[T_i<\\infty]=1$, then by Lemma \\ref{vifi},\r\n    $$\\mathbb P_i[V_i=\\infty]=\\lim_{r\\to\\infty}\\mathbb P_i[V_i>r]=1$$\r\n    So $i$ is recurrent and $\\sum_{n}p_{ii}^{(n)}=\\mathbb E_iV_i=\\infty$.\\\\\r\n    Otherwise, $\\mathbb P_i[T_i<\\infty]<1$, then\r\n    $$\\sum_{n=0}^\\infty p_{ii}^{(n)}=\\mathbb E_iV_i=\\sum_{r=0}^\\infty\\mathbb P_i[V_i>r]=\\sum_{i=0}^\\infty f_i^r=\\frac{1}{1-f_i}<\\infty$$\r\n    In particular $\\mathbb P_i[V_i=\\infty]=0$, hence $i$ is transient.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Recurrence and transience are class properties.\r\n    That is, in any communicating class, either all states there is recurrent or all are transient.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $i,j\\in C$ and assume that $i$ is transient.\r\n    Since $i,j$ communicate, there is some $n,m$ such that $p_{ij}^{(n)}>0,p_{ji}^{(m)}>0$.\r\n    Then, for all $r\\ge 0$ we have $p_{ii}^{(n+m+r)}\\ge p_{ij}^{(n)}p_{jj}^{(r)}p_{ji}^{(m)}$.\r\n    Assuming the transience of $i$, then\r\n    $$\\sum_{r=0}^\\infty p_{jj}^{(r)}\\le\\frac{1}{p_{ij}^{(n)}p_{ji}^{(m)}}\\sum_{r=0}^\\infty p_{ii}^{(n+m+r)}<\\infty$$\r\n    So $j$ is transient.\r\n    This is sufficient to imply the theorem.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A recurrent class is a communicating class which contains a recurrent state.\r\n\\end{definition}\r\nBy the preceding theorem, any state in a recurrent class is recurrent.\r\n\\begin{theorem}\\label{recur_closed}\r\n    Every recurrent class is closed.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $C$ be a class that is not closed, then there is $i\\in C,j\\notin C$ and $m\\ge 1$ such that $\\mathbb P_i[X_m=j]>0$.\r\n    Since $C$ is a communicating class and $j\\notin C$,\r\n    $$\\mathbb P_i[\\{X_m=j\\}\\cap\\{X_n=i\\text{ infinitely often}\\}]=0$$\r\n    So\r\n    \\begin{align*}\r\n        \\mathbb P_i[X_n=i\\text{ infinitely often}]&=\\sum_{j\\in I}\\mathbb P_i[\\{X_m=j\\}\\cap\\{X_n=i\\text{ infinitely often}\\}]\\\\\r\n        &<\\sum_{j\\in I}\\mathbb P_i[X_m=j]\\\\\r\n        &=1\r\n    \\end{align*}\r\n    So $i$ is transient, therefore not recurrent, as desired.\r\n\\end{proof}\r\n\\begin{theorem}\\label{fin_closed_recur}\r\n    Every finite closed class is recurrent.\r\n\\end{theorem}\r\nNote that infinite closed classes can be transient.\r\n\\begin{proof}\r\n    Start with any finite closed class $C$ and suppose $X_0\\in C$.\r\n    Then for some $i\\in C$,\r\n    \\begin{align*}\r\n        0&<\\mathbb P[X_n=i\\text{ infinitely often}]\\\\\r\n        &=\\mathbb P[X_n=i\\text{ for some $n$}]\\mathbb P_i[X_n=i\\text{ infinitely often}]\r\n    \\end{align*}\r\n    by Theorem \\ref{strong_markov}.\r\n    Hence\r\n    $$\\mathbb P_i[X_n=i\\text{ infinitelty often}]>0$$\r\n    Hence $i$ is not transient, so $i$ is recurrent, therefore $C$ is recurrent.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Finite classes are recurrent if and only if they are closed.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Combine Theorem \\ref{recur_closed} and Theorem \\ref{fin_closed_recur}.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Suppose a Markov chain $P$ is irreducible and recurrent.\r\n    Then for all $j\\in I$, $\\mathbb P[T_j<\\infty]=1$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It suffices to show that $\\mathbb P_i[T_j<\\infty]=1$ for all $i\\in I$ since that would imply\r\n    $$\\mathbb P[T_j<\\infty]=\\sum_{i\\in I}\\mathbb P[X_0=i]\\mathbb P_i[T_j<\\infty]=1$$\r\n    As $P$ is irreducible, there is $m$ such that $p_{ji}^{(m)}>0$.\r\n    Since $P$ is recurrent,\r\n    $$1=\\mathbb P_j[X_n=j\\text{ infinitely often}]\\le \\mathbb P_j[X_n=j\\text{ for some $n\\ge m+1$}]$$\r\n    So it implies the right hand side is $1$.\r\n    Expanding it gives\r\n    \\begin{align*}\r\n        1&=\\sum_{k\\in I}\\mathbb P[X_n=j\\text{ for some $n\\ge m+1$}|X_m=k]\\mathbb P_j[X_m=k]\\\\\r\n        &=\\sum_{k\\in I}\\mathbb P_k[X_n=j\\text{ for some $n\\ge 1$}]p_{jk}^{(m)}\\\\\r\n        &=\\sum_{k\\in I}\\mathbb P_k[T_j<\\infty]p_{jk}^{(m)}\r\n    \\end{align*}\r\n    Consequently $\\mathbb P_k[T_j<\\infty]=1$ for any $k\\in I$.\r\n    This completes the proof.\r\n\\end{proof}", "meta": {"hexsha": "2b2b04908a3faba2f6b22ef3584c4193d090d7aa", "size": 6770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/recur.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": "5/recur.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": "5/recur.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": 47.0138888889, "max_line_length": 182, "alphanum_fraction": 0.6138847858, "num_tokens": 2580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.769080247656264, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6305637698361028}}
{"text": "%---------------------------Maximum Edge Ratio-----------------------------\n\\section{Maximum Edge Ratio}\n\n\\[\nq = \\max \\left\\{  \\normvec{ X_1 } / \\normvec{ X_2 }, \n                  \\normvec{ X_2 } / \\normvec{ X_1 } \\right\\} \n\\]\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\quadmetrictable{maximum edge ratio}%\n{$1$}%                                      Dimension\n{$[1,1.3]$}%                                Acceptable range\n{$[1,DBL\\_MAX]$}%                           Normal range\n{$[1,DBL\\_MAX]$}%                           Full range\n{$1$}%                                      Unit square\n{\\cite{rob:87}}%                            Citation\n{v\\_quad\\_max\\_edge\\_ratio}%                Verdict function name\n\n", "meta": {"hexsha": "014cb006addd5b6f5b496c3318507eee3cbe5b9a", "size": 754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadMaximumEdgeRatio.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/QuadMaximumEdgeRatio.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/QuadMaximumEdgeRatio.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.7, "max_line_length": 82, "alphanum_fraction": 0.4071618037, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6305498977290263}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\begin{document}\n\n\\title{Notes on the Trotter Breakup for Jaynes-Cummings Hamiltonians}\n\\author{Matthew Otten}\n\n\\maketitle\n\n\\begin{abstract}\n  Basic notes on utilizing the trotter breakup for the Jaynes-Cummings Hamiltonian.\n\\end{abstract}\n\n\\section{Hamiltonian}\nThe Jaynes-Cummings model describeds the dynamics of\na two level system coupled to an oscillator mode (be it a mechanical resonator, a\nplasmonic system, or an electromagnetic field):\n\\begin{equation}\\label{jc_ham}\n  H =  \\omega_a a^\\dagger a +  \\omega_\\sigma \\sigma^\\dagger \\sigma +\n   g (\\sigma + \\sigma^\\dagger ) ( a + a^\\dagger),\n\\end{equation}\nwhere $a^\\dagger$ is the creation operator of the oscillator, $\\omega_s$ is the frequency\nof the oscillator, $\\sigma^\\dagger$ is the creation operator of the two level system,\n$\\omega_\\sigma$ is the transition frequency of the two level sistem, and $g$ is the\ncoupling strength between the two systems. We are using units such that $\\hbar = 1$.\nThis Hamiltonian can be extended to many two level systems, which is sometimes\ncalled the Tavis-Cummings Hamiltonian:\n\\begin{equation}\\label{tc_ham}\n  H =  \\omega_a a^\\dagger a +  \\sum_i^{N_{tls}}\\omega_i \\sigma_i^\\dagger \\sigma_i +\n   g_i ( \\sigma_i + \\sigma_i^\\dagger) ( a + a^\\dagger),\n\\end{equation}\nwhich is just equation~\\ref{jc_ham}, but with multiple two level systems,\n$\\sigma_i$. Using either of these Hamiltonians, we can solve for the time\ndynamics of the system using the time-dependent Schrodinger equation,\n\n\\begin{equation}\\label{schrod}\n  \\dot{\\psi} = -i H \\psi,\n\\end{equation}\nwhich has the solution\n\n\\begin{equation}\\label{solution}\n  \\psi (t) = \\exp(-i H t) \\psi (0).\n\\end{equation}\nIf the exponential of $H$ can be calculated efficiently, then the problem is\nsolved.\n\n\\section{Trotter Breakup}\nTaking the exponential of a matrix is, generally, difficult. One avenue is using\nthe symmetric Trotter breakup to split $H$ into two parts: the diagonal\noscillator terms ($A = \\omega_a a^\\dagger a + \\sum_i^{N_{tls}}\\omega_i\n\\sigma_i^\\dagger \\sigma_i$) and the off diagonal coupling terms ($B =\n\\sum_i^{N_{tls}} g_i ( \\sigma_i \\sigma_i^\\dagger) ( a + a^\\dagger),$). The\nsymmetric Trotter breakup states that\n\\begin{equation} \\label{trotter}\n  \\exp(-i(A+B)\\Delta t) \\approx \\exp(-i A \\Delta t/2) \\exp(-i B \\Delta t) \\exp(-i A \\Delta t/2) + \\mathcal{O} (\\Delta t ^3).\n\\end{equation}\nThe exponential of a diagonal matrix, such as $A$, is trivially the exponential\nof the diagonal elements. If the exponential of $B$ can be found with similar\nease, the explicit propagator can be constructed and time stepping becomes a\nmatrix vector product with $2^{nd}$ order accuracy. One way of finding the\nexponential of a matrix is by diagonalizing that matrix.\n\n\\section{Eigenvectors of Kronecker Products}\nLuckily, $B$ is a matrix of high structure. In the one two level system case,\nexplicitly including the tensor products\n\\begin{equation}\\label{explicit_b}\n  B = (a + a^\\dagger) \\otimes (\\sigma + \\sigma^\\dagger ).\n\\end{equation}\nIn the multiple two level system case, there are additional Kronecker products.\nThe eigenvectors of the Kronecker product of two matrices turns\nout to be the Kronecker product of the eigenvectors of the two matrices, and the\neigenvalues of the Kronecker product are the product of the eigenvalues of the\ntwo matrices. This can be simply shown,\n\\begin{equation}\\label{kron_ev}\n  (C\\otimes D) (v_c \\otimes v_d) = (C v_c ) \\otimes (D v_d) = (\\lambda_c v_c) \\otimes (\\lambda_d v_d) = \\lambda_c \\lambda_d (v_c \\otimes v_d).\n\\end{equation}\n\nSince our $B$ deals with the tensor product of many small matrices,\nequation~\\ref{kron_ev} shows that we can build the eigensystems\nof huge matrices ($2^{30}$) using the eigensystems of the small matrices ($<\\mathcal{O}\n(10)$). One issue is that if $C = D$, the eigenvectors obtained via\nequation~\\ref{kron_ev} are actually a linear combination of the basic\neigenvectors (at least in the case where $C = \\sigma + \\sigma^\\dagger$). I am\nnot sure exactly how to deal with this in the general case, but I found an\nempirical way of getting the eigenvectors of $C \\otimes C \\otimes C \\otimes ...\n\\otimes C$ when $C = \\sigma + \\sigma^\\dagger$, which is good enough for now.\nThen, by construction, I can get the eigenvectors and eigenvalues of $B$\n(without any need to do explicit diagonalization). Using this, and the Trotter\nbreakup of equation~\\ref{trotter}, we can create the explicit propagator:\n\\begin{equation}\\label{propagator}\n  P = \\exp(-i A \\Delta t/2) U \\exp(-i V \\Delta t) U^\\dagger \\exp(-i A \\Delta t/2),\n\\end{equation}\nwhere $U$ is the matrix of eigenvectors of $B$ and $V$ is the diagonal matrix of\neigenvalues of $B$. With $P$, we can do the time propagation efficiently - each\ntimestep is a single matrix - vector product, and the method is stable with any\ntimestep, with second order accuracy.\n\n\\end{document}\n", "meta": {"hexsha": "c886456e49738fe9d6e942600aca3f24693bf110", "size": 4915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/trotter_propagation.tex", "max_stars_repo_name": "sgulania/QuaC", "max_stars_repo_head_hexsha": "2b47b378c6b5b823a094e9af79f7cb8eb39dd337", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2017-06-18T02:11:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T10:27:57.000Z", "max_issues_repo_path": "doc/trotter_propagation.tex", "max_issues_repo_name": "sgulania/QuaC", "max_issues_repo_head_hexsha": "2b47b378c6b5b823a094e9af79f7cb8eb39dd337", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-17T15:16:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-03T14:21:56.000Z", "max_forks_repo_path": "doc/trotter_propagation.tex", "max_forks_repo_name": "sgulania/QuaC", "max_forks_repo_head_hexsha": "2b47b378c6b5b823a094e9af79f7cb8eb39dd337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2017-03-13T15:03:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T20:07:22.000Z", "avg_line_length": 49.15, "max_line_length": 142, "alphanum_fraction": 0.7434384537, "num_tokens": 1433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6305381016254715}}
{"text": "\\chapter{Concepts in Spin Conductance Models}\n\n\\section{Converting from $\\Pi$-model to T-model}\n\nDepending on the situation, it might be easier to work with the $\\Pi$-model or the T-model. However, the derivation of the conductance matrix is straightforward using the $\\Pi$-model, as described earlier. Hence, we need to derive the equivalent conductances in the T-model from the $\\Pi$-model conductances. Before we begin, note that in the spin conductance model, the conductances are tensors instead of scalars. Hence, it is important to preserve the order of multiplication.\n\nLet us begin by looking at the $\\Pi$-model as shown in Fig.~\\ref{fig:modelDiagrams}. We can first write the following equations:\n\\begin{IEEEeqnarray}{rCl}\nI_{out}&=&I_{p}+I_{2} \\label{eq:piIout}\\\\\nI_{in}&=&I_{p}-I_{1} \\label{eq:piIin}\\\\\nI_{1}&=&G_{sf\\pi}V_{1} \\label{eq:piI1}\\\\\nI_{2}&=&G_{sf\\pi}V_{2} \\label{eq:piI2} \\\\\nI_{p}&=&G_{se\\pi}(V_{2}-V_{1}) \\label{eq:piIp}\n\\end{IEEEeqnarray}Then, we add Eqs.~(\\ref{eq:piIout}) and (\\ref{eq:piIin}) to get \\begin{IEEEeqnarray}{rCl}\nI_{out}+I_{in}&=&2I_{p}+I_{2}-I_{1} \\label{eq:piCurrSum}\n\\end{IEEEeqnarray}Substituting Eqs.~(\\ref{eq:piI1}), (\\ref{eq:piI2}) and (\\ref{eq:piIp}) into Eq.~(\\ref{eq:piCurrSum}), we obtain \\begin{IEEEeqnarray}{rCl}\nI_{out}+I_{in}&=&2G_{se\\pi}(V_{2}-V_{1})+G_{sf\\pi}V_{2}-G_{sf\\pi}V_{1} \\nonumber \\\\\n&=& 2G_{se\\pi}(V_{2}-V_{1})+G_{sf\\pi}(V_{2}-V_{1}) \\label{eq:piCurrSum2} \\\\\n&=& (2G_{se\\pi}+G_{sf\\pi})(V_{2}-V_{1}) \\nonumber\n\\end{IEEEeqnarray}Next, we subtract Eq.~(\\ref{eq:piIin}) from Eq.~(\\ref{eq:piIout}) to get \\begin{IEEEeqnarray}{rCl}\nI_{out}-I_{in}&=&I_{2}+I_{1} \\label{eq:piCurrDiff}\n\\end{IEEEeqnarray}Substituting Eqs.~(\\ref{eq:piI1}) and (\\ref{eq:piI2}) into Eq.~\\ref{eq:piCurrDiff}, we get \\begin{IEEEeqnarray}{rCl}\nI_{out}-I_{in}&=&G_{sf\\pi}(V_{2}+V_{1}) \\label{eq:piCurrDiff2}\n\\end{IEEEeqnarray}\n\nNow, let us look at the T-model in Fig.~\\ref{fig:modelDiagrams}. The objective is to write $I_{out}+I_{in}$ and $I_{out}-I_{in}$, and compare them to the equations for the $\\Pi$-model so that we can obtain equations for $G_{seT}$ and $G_{sfT}$ in terms of $G_{se\\pi}$ and $G_{sf\\pi}$. First, we can write the following equations for the T-model:\\begin{IEEEeqnarray}{rCl}\nI_{out}&=&G_{seT}(V_{2}-V_{m}) \\label{eq:tIout}\\\\\nI_{in}&=&G_{seT}(V_{m}-V_{1}) \\label{eq:tIin}\\\\\nI_{m}&=&G_{sfT}V_{m} \\label{eq:tIm}\\\\\nI_{out}&=&I_{in}+I_{m} \\label{eq:tKCL1}\n\\end{IEEEeqnarray}Adding Eqs.~(\\ref{eq:tIout}) and (\\ref{eq:tIin}), we get \\begin{IEEEeqnarray}{rCl}\nI_{out}+I_{in}&=&G_{seT}(V_{2}-V_{1}) \\label{eq:tCurrSum}\n\\end{IEEEeqnarray}\\begin{figure}\n\\centering\n\\includegraphics[scale=1.75]{ResearchNotes_SpinConductanceModels/figs/2Ports}\n\\caption{These circuit diagrams show how conductances are arranged in the $\\Pi$-model and the T-model.}\n\\label{fig:modelDiagrams}\n\\end{figure}Subtracting Eq.~(\\ref{eq:tIin}) from Eq.~(\\ref{eq:tIout}), we get \\begin{IEEEeqnarray}{rCl}\nI_{out}-I_{in}&=&G_{seT}(V_{2}+V_{1}-2V_{m}) \\label{eq:tCurrDiff}\n\\end{IEEEeqnarray}Then, we rearrange Eq.~(\\ref{eq:tKCL1}) and substituting into Eq.~(\\ref{eq:tIm}):\\begin{IEEEeqnarray}{rCl}\nI_{out}-I_{in}&=&G_{sfT}V_{m} \\label{eq:tCurrDiff2}\n\\end{IEEEeqnarray}Pre-multiplying both sides of Eq.~(\\ref{eq:tCurrDiff2}) with $G^{-1}_{sfT}$:\\begin{IEEEeqnarray}{rCl}\nV_{m}&=&G^{-1}_{sfT}(I_{out}-I_{in}) \\label{eq:tVm}\n\\end{IEEEeqnarray}Substituting Eq.~(\\ref{eq:tVm}) into Eq.~(\\ref{eq:tCurrDiff}):\\begin{IEEEeqnarray}{rCl}\nI_{out}-I_{in}&=&G_{seT}(V_{2}+V_{1})-2G_{seT}G^{-1}_{sfT}(I_{out}-I_{in}) \\label{eq:tCurrDiff3}\n\\end{IEEEeqnarray}Rearranging Eq.~(\\ref{eq:tCurrDiff3}):\\begin{IEEEeqnarray}{rCl}\nG_{seT}(V_{2}+V_{1})&=&(I+2G_{seT}G^{-1}_{sfT})(I_{out}-I_{in}) \\label{eq:tCurrDiff4}\n\\end{IEEEeqnarray}where $I$ is the identity matrix.\n\nComparing Eqs.~(\\ref{eq:piCurrSum2}) and (\\ref{eq:tCurrSum}), we get \\begin{IEEEeqnarray}{rCl}\nG_{seT}&=&2G_{se\\pi}+G_{sf\\pi} \\label{eq:gset}\n\\end{IEEEeqnarray}Next, we compare Eqs.~(\\ref{eq:piCurrDiff2}) and (\\ref{eq:tCurrDiff4}) and obtain \\begin{IEEEeqnarray}{rCl}\n(I+2G_{seT}G^{-1}_{sfT})G_{sf\\pi}&=&G_{seT} \\label{eq:gset2}\n\\end{IEEEeqnarray}Substituting Eq.~(\\ref{eq:gset}) into the right-hand side of (\\ref{eq:gset2}): \\begin{IEEEeqnarray}{rCl}\n(I+2G_{seT}G^{-1}_{sfT})G_{sf\\pi}&=&2G_{se\\pi}+G_{sf\\pi} \\\\\nG_{sf\\pi}+2G_{seT}G^{-1}_{sfT}G_{sf\\pi}&=&2G_{se\\pi}+G_{sf\\pi} \\\\\n2G_{seT}G^{-1}_{sfT}G_{sf\\pi}&=&2G_{se\\pi} \\label{eq:gsePiA}\n\\end{IEEEeqnarray}Post-multiplying both sides of Eq.~(\\ref{eq:gsePiA}) by $\\frac{G^{-1}_{sf\\pi}}{2}$, we obtain \\begin{IEEEeqnarray}{rCl}\nG_{seT}G^{-1}_{sfT}&=&G_{se\\pi}G^{-1}_{sf\\pi} \\label{eq:gProd}\n\\end{IEEEeqnarray}Post-multiplying both sides of Eq.~(\\ref{eq:gProd}) by $G_{sfT}$:\\begin{IEEEeqnarray}{rCl}\nG_{seT}&=&G_{se\\pi}G^{-1}_{sf\\pi}G_{sfT} \\label{eq:gset3}\n\\end{IEEEeqnarray}Substitute Eq.~(\\ref{eq:gset}) into Eq.~(\\ref{eq:gset3}), we get:\\begin{IEEEeqnarray}{rCl}\nG_{se\\pi}G^{-1}_{sf\\pi}G_{sfT}&=&2G_{se\\pi}+G_{sf\\pi} \\label{eq:gsft}\n\\end{IEEEeqnarray}Pre-multiplying both sides of Eq.~(\\ref{eq:gsft}) by $G^{-1}_{se\\pi}$: \\begin{IEEEeqnarray}{rCl}\nG^{-1}_{sf\\pi}G_{sfT}&=&2I+G^{-1}_{se\\pi}G_{sf\\pi} \\label{eq:gsft2}\n\\end{IEEEeqnarray}Finally, pre-multiply both sides of Eq.~(\\ref{eq:gsft2}) by $G_{sf\\pi}$: \\begin{IEEEeqnarray}{rCl}\nG_{sfT}&=&G_{sf\\pi}G^{-1}_{se\\pi}G_{sf\\pi}+2G_{sf\\pi} \\label{eq:gsft3}\n\\end{IEEEeqnarray}\n\nThus, we can convert from the $\\Pi$-model to the T-model using \\begin{IEEEeqnarray}{rCl}\nG_{seT}&=&2G_{se\\pi}+G_{sf\\pi} \\\\\nG_{sfT}&=&G_{sf\\pi}G^{-1}_{se\\pi}G_{sf\\pi}+2G_{sf\\pi}\n\\end{IEEEeqnarray}\n", "meta": {"hexsha": "ed29f70467f88a4cba3c39c5f8b427c85af7164f", "size": 5536, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpinConductanceModels.tex", "max_stars_repo_name": "seeder-research/ResearchNotes_SpinConductanceModels", "max_stars_repo_head_hexsha": "0fd6020ced2432166a72c1df5f774a8b5ed7fbe1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpinConductanceModels.tex", "max_issues_repo_name": "seeder-research/ResearchNotes_SpinConductanceModels", "max_issues_repo_head_hexsha": "0fd6020ced2432166a72c1df5f774a8b5ed7fbe1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpinConductanceModels.tex", "max_forks_repo_name": "seeder-research/ResearchNotes_SpinConductanceModels", "max_forks_repo_head_hexsha": "0fd6020ced2432166a72c1df5f774a8b5ed7fbe1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-14T02:57:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T02:57:32.000Z", "avg_line_length": 74.8108108108, "max_line_length": 479, "alphanum_fraction": 0.6842485549, "num_tokens": 2391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6305380997992401}}
{"text": "\\documentclass{aastex6}\n\n\\usepackage{graphicx}\n\\usepackage[suffix=]{epstopdf}\n\\usepackage{natbib}\n\\usepackage{amsmath}\n\\usepackage{url}\n\\usepackage{xspace}\n\\usepackage{color}\n\n\\makeatletter\n\\def\\env@matrix{\\hskip -\\arraycolsep % taken from amsmath.sty lines 895ff\n  \\let\\@ifnextchar\\new@ifnextchar\n  \\array{*{\\c@MaxMatrixCols}c}}\n\\makeatother\n\n\\usepackage{geometry}\n\\geometry{\n\ttmargin=4.5cm,\n\tbmargin=0.5cm,\n\tlmargin=2.0cm,\n\trmargin=0.5cm\n}\n\\linespread{1} % c\n\n\\newcommand{\\ie}{{\\textit{i.e.,}~}}\n\\newcommand{\\eg}{{\\textit{e.g.,}~}}\n\\newcommand{\\EE}{\\mathbb{E}}\n\\newcommand{\\equref}[1]{{\\xspace}Eq.~(\\ref{#1})}\n\\newcommand{\\figref}[1]{{\\xspace}Fig.~\\ref{#1}}\n\\newcommand{\\figrefs}[2]{{\\xspace}Figs.~\\ref{#1}~and ~\\ref{#2}}\n\\newcommand{\\equrefbegin}[1]{{\\xspace}Equation~(\\ref{#1})}\n\\newcommand{\\figrefbegin}[1]{{\\xspace}Figure~\\ref{#1}}\n\\newcommand{\\secref}[1]{{\\xspace}Sec.~\\ref{#1}}\n\\newcommand{\\appref}[1]{{\\xspace}Appendix.~\\ref{#1}}\n\\renewcommand{\\d}{{\\mathrm{d}}}\n\\newcommand{\\equ}[1]{\\begin{equation}#1\\end{equation}}\n\\newcommand{\\eqn}[1]{\\begin{eqnarray}#1\\end{eqnarray}}\n\\renewcommand{\\vec}[1]{\\boldsymbol{#1}}\n\\newcommand{\\negsp}[1]{\\hspace*{-#1mm}}\n\\newcommand{\\ntypes}{{\\mathrm{N}_\\mathrm{types}}}\n\\newcommand{\\nobj}{{\\mathrm{N}_\\mathrm{obj}}}\n\n\n\\newcommand{\\todo}[1]{\\textcolor{blue}{[TODO: #1]}}\n\n\n\\begin{document}\n\n \n\\title{Optimized simulation-based estimators for power spectra and covariance matrices} \n\\author{Boris Leistedt \\textit{(send comments and add your name here!)}}\n\\date{\\today}\n\\maketitle\n\n\\vspace*{-3mm}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\textit{Monte-Carlo (MC) estimators} are widely used in cosmology to compute the mean and covariance of observables such as 3D or 2D tomographic auto and cross power spectra of the matter density field.\nHowever, the variance of the simplest MC estimators badly scale as $N^{-1}$ with $N$ the number of simulations, and are proportional to the power spectrum, assuming the draws are uncorrelated.\nWe show how state-of-the-art \\textit{Monte-Carlo variance reduction techniques} such as \\textit{antithetic} and \\textit{stratified estimators}, as well as \\textit{control variates}, can be applied in the cosmological context to drastically reduce the variance of all simulation-based estimates of interest.\nWe also show how those relate to the recent proposals of using  \\textit{paired} and \\textit{constrained} simulations.\nEven though most of our discussion will be about the 3D power spectrum and its covariance, we will make explicit how our results apply to other observables and their covariances, such as tomographic power spectra, bispectra, etc.\nIntermediate conclusions and take-away messages are highlighted in \\textbf{bold} and summarized at the end (so go and read those if you only have a limited amount of time!).\n\nNote that we will *not* discuss how to incorporate the uncertainties of the estimated quantities (model power spectra, covariance matrices, etc) into cosmological analyses. We only aim to reduce those uncertaintes. There are lots of techniques to deal with subsequent steps and include those uncertainties in cosmological likelihoods, or even compress observables of interest \\citep[\\eg][]{SellentinHeavens2015, FriedrichEifler2017, Heavensetal2017}. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Monte-Carlo covariance estimator with uncorrelated samples}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Introduction}\n\nIn what follows, we will use the notation $\\mathcal{N}(\\mu, \\Sigma)$ for a uni- or multi-variate Gaussian of mean $\\mu$ and (co)variance $\\Sigma$.\n\nLet us first consider a very simple example: we have a random variable $X \\sim \\mathcal{N}(\\mu, \\Sigma)$, and we want to estimate the mean $\\mu$ with an estimator $\\hat{\\mu}$ based on $N$ realizations $X_i$ with $i=1, \\cdots, N$. \nOur choice by default is obviously the sample mean $\\hat{\\mu} =  N^{-1} \\sum_i X_i$.\nUnfortunately, the variance of this estimator is $\\mathrm{Var}[\\hat{\\mu}] = N^{-1}  \\sigma^2 $, which scales badly. \n\nThere is a standard trick in the field of statistics: take $X_i = Y_i + Z_i$ with  $Y_i$ and $Z_i$ two realizations of $\\mathcal{N}(\\mu, \\Sigma)$ with a non-zero cross-correlation $\\mathrm{Corr}[Y_i, Z_i] = \\beta$.\nIn this case, we can show that  $\\mathrm{Var}[\\hat{\\mu}] = N^{-1}  \\sigma^2 (1+\\beta) $. \n\nFrom this trivial example we conclude that we can reduce the variance of our sample mean estimator by applying it to averaged anti-correlated draws instead of un-correlated draws. \nAlthough this is fairly trivial for Gaussian random variables, this property is generally very powerful, and extends to other distributions and estimators.\nIn this document we will apply this type of trick to the problem of estimating 2-pt and 4-pt correlations in cosmology.\nIn particular, we will apply this property at various levels, when $X$ will sometimes be the density field, its power spectrum, or its covariance.\nWe will investigate the effect of introducing correlations and how they reduce the variance of sample estimators.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Generalities}\n\nLet's consider $\\delta_k = \\delta(k)$ a complex-valued Gaussian random field with zero mean and diagonal covariance kernel $P_{k}$, also called the power spectrum. In other words,\n\\equ{\n\t\\mathrm{Real}[\\delta_k] \\sim \\mathcal{N}(0, P_k/2) \\quad \\quad \\mathrm{Imag}[\\delta_k] \\sim \\mathcal{N}(0, P_k/2) \\label{eq:p_delta}\n}\n\nNote that the modulus $|\\delta_k|^2 = \\delta_k \\delta_k^*$ follows a zero-mean Gaussian distribution of variance $P_k$.\n\nThe $k$ index/variable will implicitly refer to the $k$th Fourier mode, since we want to identify $\\delta$ to the (initial) cosmological matter density field. Despite having cosmology in mind, we remain fairly general in most of this discussion.\n\nBy construction, we set $\\mathrm{Cov}[\\delta_k, \\delta_{k'}] = 0$ for $k\\neq k'$. We also introduce a convenient reduced complex-valued random variable $x_k = \\frac{\\delta_k}{\\sqrt{P_k/2}}$, the real and imaginary parts of which follow standard Gaussian distributions $\\mathcal{N}(0, 1)$.\n\nLet us write down Monte Carlo estimators of the power spectrum and its covariance, i.e., estimators based on random draws of $\\delta$ (the random draws are assumed to be in our control, not from an existing or predefined set). The simplest estimator will involve $N_k$ independent draws of the $k$th mode, $\\delta_{k,p}$ with $p=1, \\cdots, N_k$ from \\equref{eq:p_delta}. \n\nThe unbiased estimator for the power spectrum (assuming we know the mean is zero) is\n\\eqn{\n\t\\hat{P}_{k} = \\frac{1}{N_k} \\sum_{p=1}^{N_k} |\\delta_{k,p}|^2 =\\frac{P_k}{N_k } \\underbrace{\\sum_{p=1}^{N_k} |x_{k,p}|^2 }_{\\hat{\\sigma}_k}\n}\nSince the $x_k$'s are standard normal random variables, $\\hat{\\sigma}_k$ follows a chi-squared distribution with $N_k$ degrees of freedom, $\\hat{\\sigma}_k \\sim \\chi^2(N_k)$. \nThus, $\\hat{P}_{k} \\sim \\frac{P_k}{N_k }  \\chi^2(N_k)$, with the mean value being $P_k$, demonstrating that the previous estimator is unbiased.\n\nWe are interested in the covariance of this estimator:\n\\eqn{\n\tC_{kk'} = \\mathrm{Cov}[\\hat{P}_{k}, \\hat{P}_{k'}]\n}\nIn our simple setup, we know that the $k$ modes are uncorrelated, so we have\n\\eqn{\n\tC_{kk'} = \\frac{2{P}^2_{k}}{N_k} \\delta^D(k-k')\n}\nwhere $ \\delta^D$ is the Dirac delta. Yet, we want to estimate this covariance via Monte Carlo.\nA concrete example is the estimation of the covariance of the power spectrum in a density field evolved from Gaussian initial conditions, which is a fairly standard setup in cosmology.\nHence, we introduce another set of draws: we repeat our experiment (drawing $N_k$ modes) $N$ times. The estimator from the $i$th draw is denoted by $\\hat{P}_{k, i}$. \nAt this stage, we assume they are uncorrelated, \\ie $\\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k, j}] = 0$ if $i\\neq j$.\n\nIn the case of galaxy survey analyses in cosmology, we would generate $N$ random Gaussian initial conditions and evolve them in an $N$-body fashion. Each 3D Fourier mode is estimated from $N_k$ modes. In what follows we will assume that $N_k=1$ for simplicity.\n\nWe turn our attention to the sample covariance estimator\n\\eqn{\n\t\\hat{C}_{kk'} = \\frac{1}{\\nu}  \\sum_{i=1}^{N} (\\hat{P}_{k, i} - \\bar{P}_{k})(\\hat{P}_{k', i} - \\bar{P}_{k'})\n}\nWe can either assume that the mean is know and set $\\bar{P}_{k}=P_k$, in which case $\\nu=N$, or directly estimate it with\n\\eqn{\n\t\\bar{P}_{k} = \\frac{1}{N}  \\sum_{i=1}^{N} \\hat{P}_{k, i}\n}\nin which case we must set $\\nu=N-1$. In what follows, we will consider the latter. \n\nWe also know that if each $\\hat{P}_{k, i}$ were Gaussian, $\\hat{C}_{kk'} (N-1)$ would follow a Wishard distribution. It is unbiased, so the mean is the true covariance $C_{kk'}$, and its variance is\n\\eqn{\n\t\\mathrm{Cov}[\\hat{C}_{ij} \\hat{C}_{kl}] = \\frac{C_{ij}C_{kl} + C_{ik}C_{jl}}{N-1}\n}\nThis assumption is pretty accurate as soon as $N_k>50$, because the chi-squared distribution is then very well approximated by a Gaussian (but still assuming that $\\delta$ is Gaussian!). \nWe will make that assumption for the derivations below.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Three problems}\n\nFirst, we see that the scaling of the standard MC covariance estimator is $(N-1)^{-1}$.\nThis is a fairly standard result in statistics, and there are numerous strategies to decrease this scaling. \nWe will go through some of those below.\n\nSecond, we see that our covariance of interest is exceedingly simple in the case of a Gaussian random field. We don't really need the MC estimator. \nIn the case of the cosmological matter power spectrum or its covariance, there are a number of theoretical models that are satisfactory over some range of scales and redshifts. \nWe absolutely want to make use of that and focus on estimating the residuals (unmodelled) part with Monte-Carlo, since this significantly reduces the number of simulations required. \nIn other words, let's not use large number of simulations just to estimate the components that we already know how to model analytically.\nAgain, there are standard techniques for including incomplete theoretical models in MC estimators, and we will explore those.\n\nThird, there are various other considerations that we may need to consider in our estimators. A good example is the effect of box size and resolution on N-body simulations and power spectrum or covariance estimators. \nWe will briefly discuss those issues below. Standard techniques exist to deal with them, and they don't affect our main results.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Monte-Carlo covariance estimator correlated samples}\n\n\nLet us relax one of the previous assumptions and introduce correlated draws, \\ie\n\\eqn{\n\t\\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', j}] \\ = \\ \\mathbb{E}[\\hat{P}_{k, i}\\hat{P}_{k', j}] - \\mathbb{E}[\\hat{P}_{k, i}]\\mathbb{E}[\\hat{P}_{k', j}]  \\ =  \\ C_{kk'} \\left( \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij} \\right)\n}\nwhere $\\delta^K$ is Kronecker's delta. This slightly complicated expression is to recover $C_{kk'}$ at $i=j$ and $\\beta_{ij}C_{kk'}$ at $i\\neq j$. In other words, the correlation coefficient is simply $\\beta_{ij}$. The only condition we must impose is that the full correlation matrix (constructed with the $\\beta_{ij}$s) is symmetric positive definite. In particular, we note that if we take $\\beta_{ij}=\\beta$, we must have $\\beta > -1/(N-1)$. This condition will be obvious when we study the estimators below.\n\nWe will now compute the covariance of the sample estimator, on the diagonal only (we only consider $\\mathrm{Cov}[\\hat{C}_{kk'}\\hat{C}_{lm}]$ for $l=k, k'=m$):\n\\eqn{\n\t\\mathrm{Var}[\\hat{C}_{kk'}] \\ =\\    \\frac{1}{(N-1)^2}\\sum_{i=1}^{N}\\sum_{j=1}^{N} \\mathrm{Cov}[\\hat{C}_{kk',i} , \\hat{C}_{kk',j} ]\n}\nAfter a rather long derivation presented in \\appref{sec:samplecovariancecorrelateddraws}, we obtain\n\\eqn{\n\t&&  \\ \\mathrm{Var}[\\hat{C}_{kk'}] \\ =    \\bigl(C_{kk}C_{k'k'} + C_{kk'}^2 \\bigr) \\times s_N\n}\nwith the scaling term \n\\eqn{\n\ts_N = \\frac{ \\sum_{ij} B_{ij}^2  - \\frac{(\\sum_{ij} B_{ij})^2}{N^2}}{(N-1)^2}\n}\n\t with $B_{ij} =  \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij} $ and $\\beta_{ij} \\in [-1, 1]$ the correlation coefficient between the $i$th and the $j$th samples $\\hat{P}_{k, i}$ and $\\hat{P}_{k, j}$. \n\nUsing the same ingredients of \\appref{sec:samplecovariancecorrelateddraws}, we can compute the expectation of the estimator,\n\n\\eqn{\n\t\\mathbb{E}(\\hat{C}_{kk'}) = C_{kk'} b_N\n}\nwith the bias\n\\eqn{\n\tb_N = \\frac{\\sum_i B_{ii} - \\frac{B}{N}}{N-1}\n}\n\nIf $b_N\\neq 1$, the estimator is biased, so we must apply a correction factor to $\\hat{C}_{kk'}$.\nThe variance of the de-biased estimator is\n\\eqn{\n\t \\mathrm{Var}\\left[ \\frac{\\hat{C}_{kk'}}{b_N}\\right]  = \\bigl(C_{kk}C_{k'k'} + C_{kk'}^2 \\bigr) \\times s_N^\\prime  \\label{ref:samplecovariancevariance}\n}\nwith \n\\eqn{\n\ts_N^\\prime  = \\frac{s_N}{b^2_N} =  \\frac{ \\sum_{ij} B_{ij}^2  - \\frac{B^2}{N^2}}{ \\left(\\sum_i B_{ii} - \\frac{B}{N}\\right)^2 }\n\t}\n\nFinally, we check that the sample mean estimator is unbiased, $\\mathbb{E}(\\bar{P}_k) = P_k$, and that its covariance is\n\\eqn{\n\t\\mathrm{Cov}[\\bar{P}_k, \\bar{P}_{k'}] = C_{kk'} \\underbrace{ \\frac{B}{N^2} }_{v_N}\n}\n\n\\begin{table}\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n\t\\hline\tName\t& $B_{ij}$\t&\t$B_{i}$\t&\t$B$\t&\t$v_N$\t&\t$s_N $ \t&\t$b_N$\t&\t$s_N^\\prime$\t\\\\\\hline\n\tUncorrelated\t&$ \\delta^K_{ij}$\t\t&\t1\t&\t$1/N$\t&\t$N$\t&\t$1/(N-1)$\t&\t$1$\t&\t$1/(N-1)$\t\\\\\n\tCorrelated\t&$\\delta^K_{ij}(1-\\beta) + \\beta$\t\t&\t$1 + (N-1)\\beta$\t&\t$N + (N^2-N)\\beta$\t&\t$\\frac{1 + (N-1)\\beta}{N}$\t&\t$(1-\\beta)^2/(N-1)$\t&\t$1-\\beta$\t&\t$1/(N-1)$\t\\\\\n\tFully correlated\t&$ 1$\t\t&\t$N$\t&\t$N^2$\t&\t$1$\t&\t$0$\t&$0$\t\t&\t$0$\t\\\\\n\tFully anticorrelated\t&$2 \\delta^K_{ij} - 1$\t\t&\t$2-N$\t&\t$N(2-N)$\t&\t$(2-N)/N$\t&\t$4/(N-1)$\t&\t$2$\t&\t$1/(N-1)$\t\\\\\n\t\\hline\n\\end{tabular}\t\n\\caption{Summary of our results for the mean and variance of the sample mean and sample variance estimators. We define $B_{ij} =  \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij}$, $B_i=\\sum_{j=1}^NB_{ij}$, $B=\\sum_{i=1}^NB_{i}$. As defined in the text, $v_N$ and $s_N^\\prime$ characterize the scaling of the variance of the \\textit{unbiased} sample mean and sample covariance estimators (the constant terms in those are $C_{kk'}$ and $C_{kk}C_{k'k'} + C_{kk'}^2$, respectively). \n}\n\\label{table:correlateddrawbiasesandvariances}\n\\end{table}\n \nOur findings are summarized in Table~\\ref{table:correlateddrawbiasesandvariances}. \\textbf{We conclude that that 1) we can easily reduce the variance of the sample mean by adopting correlated samples, 2) this unfortunately doesn't work for the sample covariance. Unlike for the sample mean, adjusting the correlations cannot cancel or even reduce the variance of the estimator.}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Stratified sampling}\n\nLet us now take a step back from the $P_k$ and $C_{kk'}$ notation, and introduce an important concept. \nWe will assume that we have a set of correlated samples $X_{ij}$. \nWe group them in packets of size $M$, and for each packet, we compute a statistic with a MC estimator $f$. \nWe then compute a final statistic with another MC estimator $g$. \n\\eqn{\n\t\\hat{X}_i &=& f\\bigl(\\{X_{ij} | j=1, \\cdots, N\\}\\bigr) \\quad i=1, \\cdots M \\\\\n\t\\hat{X} &=& g\\bigl(\\{\\hat{X}_i | i=1, \\cdots M\\}\\bigr)\n}\nHaving multiple layers of MC estimators is known as \\textbf{stratified sampling}. It is a powerful variance reduction technique.\nLet us study a few cases of interest, where we can simply use the results of the previous section on both $f$ and $g$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Stratified estimator for the mean}\n\nFirst, let us consider both estimators to be the sample mean,\n\\equ{\n\t\\hat{X}_i = \\frac{1}{N}\\sum_{j=1}^N X_{ij}  \\quad\\quad \\hat{X} =  \\frac{1}{M}\\sum_{i=1}^M \\hat{X}_i \n\t}\nAll of the samples have a mean $\\mu$ and a variance $V$. It is pretty obvious that $\\mathbb{E}[\\hat{X}] = \\mu$.\nThe samples within each of the packets $i=1, \\cdots M$ are correlated with a correlation coefficient $\\beta$. \nThere are no correlations between packets. Thus,\n\\eqn{\n\t\\mathrm{Cov}[X_{ij}, X_{ml}] &=& \\delta^K_{im} V \\bigl(\\delta^K_{jl}(1-\\beta) + \\beta\\bigr) \\ \n}\nUsing the expressions derived above, we find\n\\eqn{\n\t% \\mathrm{Var}[\\hat{X}_i] &=& V \\times \\frac{1 + (N-1)\\beta}{N}\\\\ \n\t\\mathbb{E}[\\hat{X}] &=& \\mu\\quad\\quad\n\t\\mathrm{Var}[\\hat{X}] =  V \\times \\frac{1 + (N-1)\\beta}{N M}\n}\n\nWe see that the variance is cancelled if \n\\eqn{\n\t\\beta^\\mathrm{VC} \\rightarrow^{>} - \\ \\frac{1}{N-1}\n}\nwith VC as in Variance Cancellation. The arrow means that we cannot actually take $- \\ \\frac{1}{N-1}$ because the correlation matrix wouldn't be semi-positive definite, hence valid. However, we can approach this value as much as we want.\n\nThe specific case of $N=2$ is known as the \\textbf{antithetic estimator for the sample mean}. In this case, the optimal choice for cancelling the variance is $\\beta^\\mathrm{RC}=-1$, \\ie perfectly anti-correlated variables. \n\nConversely, imagining the correlation $\\beta$ and the number of simulations $MN$ are fixed, one can infer $N$ to obtain the minimum-variance stratified estimator. \n\n%Note that in the case of Gaussian random variables, the Gaussian covariance matrix is singular when $\\beta \\pm 1$, and perfectly anti-correlated samples are obtained by flipping the sign of the variable. There is only one problem: in this case, we cancel out the variable because there is indeed no variability whatsoever in the sampling. So one may  want to set $\\beta$ close but not exactly $\\pm1$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Two-layer stratified estimators for the covariance}\n\nThere are two estimators for the covariance: taking $f$ as the sample covariance and $g$ as the sample mean estimator, or conversely. We will go through both. Again, we only consider correlations within (not between) packets:\n\\eqn{\n\t\\mathrm{Cov}[X_{ij}, X_{ml}] &=& \\delta^K_{im} V \\bigl(\\delta^K_{jl}(1-\\beta) + \\beta\\bigr) \\ \n}\nThe first stratified estimator is\n\\eqn{\n\t\\hat{X}_i &=& \\frac{1}{N-1}\\sum_{j=1}^N \\frac{(X_{ij} - \\bar{X}_{i})^2}{1-\\beta}\t\\quad\\quad \\bar{X}_{i}\t=  \\frac{1}{N}\\sum_{j=1}^N X_{ij}\t\\quad\\quad \\hat{X} =  \\frac{1}{M}\\sum_{i=1}^M \\hat{X}_i \n}\nand its mean and the variance are\n\\eqn{\n\t\\mathbb{E}[\\hat{X}] \t&=&\tV \t\\quad \\quad\\mathrm{Var}[\\hat{X}] = \\frac{2V^2}{M(N-1)} \n}\nThe extra $ (1-\\beta)$ in the definition of $\\hat{X}_i$ was to make the estimator unbiased.\nThe second estimator reads\n\\eqn{\n\t\\hat{X}_i &=& \\frac{1}{N}\\sum_{j=1}^N X_{ij}\t\\quad\\quad\n\t\\hat{X} =   \\frac{N}{(1 + (N-1)\\beta)} \\frac{1}{M-1}\\sum_{i=1}^M (\\hat{X}_i  - \\bar{X})^2 \\quad\\quad\n\t\\bar{X} =  \\frac{1}{M}\\sum_{i=1}^M \\hat{X}_i\n}\n\nand its mean and the variance are\n\\eqn{\n\t\\mathbb{E}[\\hat{X}] &=& V \\quad\\quad\n\t \\mathrm{Var}[\\hat{X}] = \\frac{2V^2}{(M-1)N} \n}\nAgain, the extra $\\beta$ term in the definitions is to make the variance estimator unbiased. \n\nBecause of the terms at the denominator of the scaling of those two covariance estimators ($(N-1)M $ and $(M-1)N$) and the absence of a $\\beta$ term, it is actually. better to \\textbf{not} bin them into groups (straightforward to prove), and use the standard (unstratified) sample variance estimator. \n\n\\textbf{In conclusion, we can use correlations to reduce the variance of the sample mean, but not that of the variance. }\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Connection to cosmology}\n\nReconnecting to the previous section, should we identify $X$ to $\\delta_{k, i}$, or to $\\hat{P}_{k,i}$? Again, we assume that we will do $i=1, \\cdots, N$ draws, potentially grouped into packets and correlated.\n\nThe setup is fairly clear: we want to generate Gaussian initial conditions for $\\delta$, then evolve them via a N-body code, and estimate the power spectrum and the covariance matrix of the evolved field. \n\nIf we identify $X$ to $\\delta_{k, i}$, then we need to add another layer of estimation on top of our formalism to get the covariance matrix. \nIf we identify $X$ to $\\hat{P}_{k,i}$, we immediately face the question of controlling the correlation properties of $\\hat{P}_{k,i}$ given that we generate $\\delta_{k, i}$.\n\nWe should immediately note that the latter case might be easily achievable: if we generate anti-correlated density fields, any residual anti-correlation in the power spectrum will decrease the variance of the stratified sample estimators described above. So the real question is quantitative: how can we generate anti-correlated power spectra when drawing density fields ?\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Can we generate anti-correlated power spectra from (anti-)correlated density? No.}\n\nWe consider correlated Gaussian draws of the density field, such that\n\\eqn{\n\t\\mathrm{Cov}\\bigl[\\mathrm{Real}[\\delta_{k, p, i}], \\mathrm{Real}[\\delta_{k', q, j}]\\bigr] &=& \\delta^D(k-k') \\ \\delta^K_{pq}\\  \\frac{P_k}{2}\\ \\underbrace{( \\delta^K_{ij}(1+\\beta_{ij}) + \\beta_{ij})}_{B_{ij}}\t\\\\\n\t\\mathrm{Cov}\\bigl[\\mathrm{Imag}[\\delta_{k, p, i}], \\mathrm{Imag}[\\delta_{k', q, j}] \\bigr] &=& \\delta^D(k-k') \\ \\delta^K_{pq}\\  \\frac{P_k}{2}\\ \\underbrace{( \\delta^K_{ij}(1+\\gamma_{ij}) + \\gamma_{ij})}_{G_{ij}}\\\\\n\t\\mathrm{Cov}\\bigl[\\mathrm{Real}[\\delta_{k, p, i}], \\mathrm{Imag}[\\delta_{k', q, j}] \\bigr] &=& \\delta^D(k-k') \\ \\delta^K_{pq}\\  \\frac{P_k}{2}\\ \\underbrace{( \\delta^K_{ij}(1+h_{ij}) + h_{ij})}_{H_{ij}}\n}\n\\ie without mixing the $k$ or $p-q$ modes.\nSince the mean value is zero, we have $\\mathrm{Cov}[...] = \\mathbb{E}[...]$ for all expression involving pairs of densities.\nLike before, we will use the notation $B_{ij}$ (and $G_{ij}$ and $H_{ij}$) for the elements of the correlation matrices, which must be symmetric semi-positive definite.\n\n\\eqn{\n\t\\mathrm{Cov}[\\hat{P}_{k, i}, \\hat{P}_{k', j}] &=& \\frac{1}{N_k^2} \\sum_{p=1}^{N_k}\\sum_{q=1}^{N_k} \\mathrm{Cov}\\Bigl[ \\delta_{k, p, i} \\delta_{k, p, i}^*, \\delta_{k', q, j}\\delta_{k', q, j}^* \\Bigr] \\\\\n\t&=&  \\frac{1}{N_k^2} \\sum_{p=1}^{N_k}\\sum_{q=1}^{N_k}   \\mathbb{E}[\\delta_{k, p, i} \\delta_{k', q, j}]\\mathbb{E}[ \\delta_{k, p, i}^* \\delta_{k', q, j}^*] + \\mathbb{E}[\\delta_{k, p, i} \\delta_{k', q, j}^*]\\mathbb{E}[ \\delta_{k, p, i}^* \\delta_{k', q, j}]\n}\nwhere we have used Wick's theorem, \\equref{eq:wickstheorem}. Unfortunately, to simply this expression we must split the real and imaginary part s of the complex numbers. Luckily, many of the cross-terms vanish since all the real and imaginary parts are independent. \n\\eqn{\n\t\\mathrm{Cov}[\\hat{P}_{k, i}, \\hat{P}_{k', j}] &=&  \\frac{1}{N_k^2} \\sum_{p=1}^{N_k}\\sum_{q=1}^{N_k}\\\\\n\t&&  \n\t\\mathbb{E}[\\mathrm{Real}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] +i\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] +i\\mathrm{Imag}[\\delta_{k',q,j}] \\mathrm{Real}[\\delta_{k, p, i}]  - \\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Imag}[\\delta_{k',q,j}] ] \\nonumber\\\\\n\t&& \\times\\mathbb{E}[ \\mathrm{Real}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] -i\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] -i\\mathrm{Imag}[\\delta_{k',q,j}] \\mathrm{Real}[\\delta_{k, p, i}] -\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Imag}[\\delta_{k',q,j}] ]\\nonumber \\\\ \n\t&&+ \\  \\mathbb{E}[\\mathrm{Real}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] +i\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] -i\\mathrm{Real}[\\delta_{k, p, i}] \\mathrm{Imag}[\\delta_{k',q,j}] +\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Imag}[\\delta_{k',q,j}] ] \\nonumber\\\\\n\t&& \\times \\mathbb{E}[ \\mathrm{Real}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] -i\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Real}[\\delta_{k',q,j}] +i\\mathrm{Imag}[\\delta_{k',q,j}]  \\mathrm{Real}[\\delta_{k, p, i}]+\\mathrm{Imag}[\\delta_{k, p, i}] \\mathrm{Imag}[\\delta_{k',q,j}] ] \\nonumber \\\\\n\t%&=& \\delta^D(k-k')   \\frac{P^2_k}{4} \\frac{1}{N_k} \\left[ \\left(B_{ij} + 2iH_{ij} - G_{ij}\\right)  \\left(B_{ij} - 2iH_{ij} - G_{ij}\\right) + \\left(B_{ij} + G_{ij}\\right)  \\left(B_{ij} + G_{ij}\\right) \\right]\t\\\\\n\t%&=& \\delta^D(k-k')   \\frac{P^2_k}{4} \\frac{1}{N_k} \\left[  (B_{ij} - G_{ij})^2 + 4H^2_{ij} + \\left(B_{ij} + G_{ij}\\right)^2 \\right] \\\\\n\t&=& \\delta^D(k-k')   P^2_k \\frac{1}{N_k} \\left[  \\frac{B^2_{ij} + G^2_{ij}}{2}  + H^2_{ij} \\right]\n}\n\n%\\eqn{\n%\t&&\\mathbb{E}[(a_1+ib_1)(a_3+ib_3)]\\mathbb{E}[ (a_1-ib_1)(a_3-ib_3)] + \\mathbb{E}[(a_1+ib_1)(a_3-ib_3)]\\mathbb{E}[ (a_1-ib_1)(a_3+ib_3)] \t\\\\\n%\t&&\\quad = \\ \\mathbb{E}[a_1a_3+ib_1a_3+ib_3a_1 - b_1b_3]\\ \\mathbb{E}[ a_1a_3-ib_1a_3-ib_3a_1-b_1b_3] \\\\ \n%\t&&\\quad \\quad + \\  \\mathbb{E}[a_1a_3+ib_1a_3-ia_1b_3+b_1b_3]\\ \\mathbb{E}[ a_1a_3-ib_1a_3+ib_3a_2+b_1b_3]  \n%}\n \n\nThe correlation coefficient is $\\left[  \\frac{B^2_{ij} + G^2_{ij}}{2}  + H^2_{ij}\\right]$ and is strictly positive regardless of the correlations we introduce between $\\delta_{k, p, i}$ and $\\delta_{k', q, j}$.\n\\textbf{We conclude that unfortunately we cannot generate anti-correlated power spectra from correlated density field draws. We could have seen this from our previous findings too.}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Drawing the density field from anti-correlated power spectra.}\n\nLet us explore another strategy: rather than drawing the density field from the theory power spectrum, let's generate the density field from anti-correlated draws of the theory power spectrum. \nIn other words, we now construct power spectra such that $Q_{k, i}$ for $i=1, \\cdots, N$ from the mean $P_{k}$ and with the covariance structure $\\mathrm{Cov}[{Q}_{k, i}, {Q}_{k', j}] \\ = \\ C_{kk'} \\left( \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij} \\right)$\nWe use $Q$ instead of $P$ or even $\\hat{P}$ to emphasize the fundamental difference of the scheme proposed here.\n\nWe now draw the corresponding density field $\\delta_{k, p, i}$ from $Q_{k, i}$. Importantly, we want it to be a Gaussian random field of mean $P_{k}$, in order to have Gaussian initial conditions for an N-body simulation. \nSince we have drawn $Q_{k, i}$ already, we cannot construct $\\delta_{k, p, i}$ from a naive Gaussian draw.\nLuckily, as described in \\cite{AnguloPontzen2016} (see also \\citealt{Schmittfull2015, PradaEtAl2016, DingEtAl2017}), this can be achieved by setting \n$\\delta_{k, p, i} = \\sqrt{Q_{k, i}} \\exp(i\\theta_{k, p, i})$\nwhere the complex phase $\\theta_{k, p, i}$ is drawn uniformly between $0$ and $2\\pi$.\nAgain, we perform $N_k$ independent random draws for the $k$-th mode in the $i$-th simulation.\n\nThe resulting density fields $\\delta_{k, p, i} $ are indeed Gaussian random fields in $P_k$, but constructed with anti-correlated power spectra $Q_{k, i}$.\nConcretely, the probability distribution of the modulus is no longer\n\\eqn{\n\tp\\bigl(|\\delta_{k, p, i}|, \\theta_{k, p, i}\\bigr) = \\frac{|\\delta_{k, p, i}|}{2\\pi P_{k, i}} \\exp\\left( -\\frac{|\\delta_{k, p, i}|^2}{P_{k, i}}\\right)\n}\nit is now\n\\eqn{\n\tp\\bigl(|\\delta_{k, p, i}|, \\theta_{k, p, i}\\bigr) = \\frac{1}{2\\pi} \\delta^D\\left(|\\delta_{k, p, i}| - \\sqrt{Q_{k, i}}\\right)\n}\n\\todo{How well does this procedure work for Gaussian random fields?}\n\nWe can check that the measured power spectra are indeed anticorrelated:\n\\eqn{\n\t\\mathrm{Cov}[\\hat{P}_{k, i}, \\hat{P}_{k', j}] \\ = \\ \\frac{1}{N_k^2} \\sum_{p=1}^{N_k}\\sum_{q=1}^{N_k} \\mathrm{Cov}\\Bigl[ |\\delta_{k, p, i}|^2, |\\delta_{k', q, j}|^2 \\Bigr] \n\t\\ =\\  \\frac{1}{N_k^2} \\sum_{p=1}^{N_k}\\sum_{q=1}^{N_k}   \\mathrm{Cov}[{Q}_{k, i}, {Q}_{k', j}]  \n\t\\ = \\ C_{kk'} \\left( \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij} \\right)\n}\nwhich is the desired property.\n\n\\textbf{We conclude that by using this trick we can draw density fields that have anti-correlated power spectra, and therefore use the previous stratified estimators.}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Non-Gaussian random variables}\n\nSo far we have assumed that most variables are Gaussian distributed. In practice, there are two sources of non-Gaussianity: in $P_k$ since it is calculated from $\\delta$, and in $\\delta$ itself.\n\nWe have assumed that the estimated power spectra $\\hat{P}_{k, i}$ are Gaussian distributed. This is not true even if $\\delta_k$ is a Gaussian random field: we showed that $\\hat{P}_{k, i}$ follows a chi-squared distribution. As a consequence, our application of Wick's theorem at \\equref{eq:wickstheorem} does not hold. However, we expect it to be relatively accurate given the small deviations between the variances of the chi-squared and Gaussian distributions. For most observables it will be the case: we usually average out enough modes in each bins so that the statistical uncertainties are close to Gaussian.\n\nThe real non-Gaussianity is in the \\textit{evolved} density field itself, and the impossibility to model the covariance matrix $C_{kk'}$ accurately (which is why we needed simulations in the first place).  Schematically, we can write\n\\eqn{\n\t\\delta^\\mathrm{ini}_k \\ &\\longrightarrow& \\ \\delta^\\mathrm{fin}_k\t\\nonumber\\\\\n\tP^\\mathrm{ini}_k \\ &\\longrightarrow& \\ P^\\mathrm{fin}_k\t\\nonumber\\\\\n\tC_{kk'}^\\mathrm{ini}  \\ &\\longrightarrow& \\ C_{kk'}^\\mathrm{fin} \\nonumber\\\\\n\t\\mathrm{Corr}[\\hat{P}^\\mathrm{ini}_{k, i}, \\hat{P}^\\mathrm{ini}_{k', j}]  \\ &\\longrightarrow& \\ \\mathrm{Corr}[\\hat{P}^\\mathrm{fin}_{k, i}, \\hat{P}^\\mathrm{fin}_{k', j}]   \\nonumber\n}\nwhere the arrows denote cosmological evolution, for example evolving the initial density field in an N-body fashion. \nWe are truly interested in $P^\\mathrm{fin}_k$ and $C_{kk'}^\\mathrm{fin}$.\nEven if we generate anti-correlated initial power spectra and the corresponding density fields, there is no guarantee that those anti-correlations persist in the evolved field, especially in $\\mathrm{Corr}[\\hat{P}^\\mathrm{fin}_{k, i}, \\hat{P}^\\mathrm{fin}_{k', j}]$. \nYet, those are essential to achieve variance reduction.\nLuckily, we can intuitively guess that most of the anti-correlation should be reduced by not totally cancelled, especially on large scales, which is where we care about variance cancellation the most due to the fewer number of modes.\n\\todo{Can we write down first order analytic predictions for $\\mathrm{Corr}[\\hat{P}^\\mathrm{fin}_{k, i}, \\hat{P}^\\mathrm{fin}_{k', j}] / \\mathrm{Corr}[\\hat{P}^\\mathrm{ini}_{k, i}, \\hat{P}^\\mathrm{ini}_{k', j}]$ ?}\n\\todo{Run simulations and make experiments to quantify this!}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Including theoretical predictions in the estimators}\n\nWe are interested in $P^\\mathrm{fin}_k$ and $C_{kk'}^\\mathrm{fin}$ but only have partial models, that are accurate only in certain limited regimes, such as large scales, high redshift, etc. \nCan we make use of those in the previous MC estimators?\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Setup and naive approach}\n\nIn a first attempt, let's suppose we have models for $P^\\mathrm{fin}_k$ and $C_{kk'}^\\mathrm{fin}$, denoted by $\\tilde{P}^\\mathrm{fin}_k$ and $\\tilde{C}_{kk'}^\\mathrm{fin}$, that are imperfect.\nWe now seek to estimate the deviations from those models to the target, true power spectrum and its covariance matrix:\n\\eqn{\n\t{D}_k &=&P^\\mathrm{fin}_k - \\tilde{P}^\\mathrm{fin}_k\t\t \\quad \\quad\\quad\n\t\\Delta_{kk'} = C_{kk'}^\\mathrm{fin}  - \\tilde{C}_{kk'}^\\mathrm{fin}\n}\nLet us write down the classic sample estimators first:\n\\eqn{\n\t\\bar{D}_k &=&\t\\frac{1}{N} \\sum_{i} \\hat{D}_{k, i}\t \\quad \\quad\\quad\n\t\\hat{\\Delta}_{kk'} = \\frac{1}{N-1} \\sum_{i} \\left( \\hat{D}_{k, i} - \\bar{D}_{k} \\right) \\left( \\hat{D}_{k', i} - \\bar{D}_{k'} \\right)\n}\nwith $\\hat{D}_{k, i} = \\hat{P}^\\mathrm{fin}_{k, i} - \\tilde{P}^\\mathrm{fin}_k$.\n\nLet's remember that \\textit{in the Gaussian case}, the constant term in all of our sample mean estimators was $C_{kk'}$, and the constant in the sample covariance estimators was ${C}_{kk}{C}_{k'k'} + {C}_{kk'}^2$. \n\n\nSo we immediately conclude that if the power spectrum estimates $P^\\mathrm{fin}_{k, i}$ are Gaussian distributed (potentially correlated), we have\n\\eqn{\n\t\\mathrm{Cov}[\\bar{D}_k, \\bar{D}_{k'}] = \\Delta_{kk'} v_N \\quad \\quad\\quad\n\t \\mathrm{Var}\\left[ \\frac{\\hat{\\Delta}_{kk'}}{b_N}\\right]  = \\bigl(\\Delta_{kk}\\Delta_{k'k'} + \\Delta_{kk'}^2 \\bigr) s_N^\\prime  \n}\nanalogous to \\equref{ref:samplecovariancevariance}. Again, the $b_N$ term is to debias the estimator in the case of correlated power spectra.\n\nThe scalings $v_N$ and $s_N^\\prime$ have not changed - only the constant terms did. The variances of the estimators now depend on the deviations from the model. \nIf those are small, then we have indeed improved!\nNeedless to say we can use the previous stratified estimators in this case too. \n\n\\textbf{In conclusion, including theoretical predictions when MC estimating the power spectra and covariances reduces the variances of the estimators, but not their scaling with the number of simulations.} \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Control variates}\n\nWhat if we wanted to further decrease the scaling of the estimators by including theoretical predictions? \nThis can be achieved with \\textbf{control variates}.\nThe idea is again to exploit (anti-)correlation, but this time not between our samples (previously the power spectra), but with \\textit{auxiliary variables}.\nSpecifically, we want the auxiliary variables to have a known target statistic. \n\nIn the context of cosmological N-body simulations, an obvious choice is to run an auxiliary set of simulations where we can actually accurately model the power spectra and covariance matrices. \nFor example, we could run LPT simulations.\n\nLike before, we will look at differences between the estimated power spectra of our full complicated simulation $\\hat{P}^\\mathrm{fin}_{k, i} $ and those of our simplified simulation, denoted $\\hat{S}^\\mathrm{fin}_{k, i}$. \nThe significant difference between those is that  we do have exact (or very accurate models) of the power spectrum and covariance matrix for the latter, which we write $\\tilde{P}^\\mathrm{fin}_k$ and $\\tilde{C}_{kk'}^\\mathrm{fin}$.\n\nWe will not discuss how the auxiliary simulations are constructed now - let us first write the sample estimators\n\\eqn{\n\t\\hat{D}_{k, i} &=&  \\hat{P}_{k, i} + \\alpha (\\hat{S}_{k, i} - \\tilde{P}^\\mathrm{fin}_k)  \\quad \\quad\\quad\n\t\\bar{D}_k =\t\\frac{1}{N} \\sum_{i=1}^N\t\\hat{D}_{k, i}\t\\quad \\quad\\quad\n\t\\hat{\\Delta}_{kk'} = \\frac{1}{N-1} \\sum_{i=1}^N \\left( \\hat{D}_{k, i} - \\bar{D}_{k} \\right) \\left( \\hat{D}_{k', i} - \\bar{D}_{k'} \\right)\n}\nWe have \n\\eqn{\n\t\\mathbb{E}[\\hat{D}_{k, i}] &=& {P}^\\mathrm{fin}_k \t\\\\\t\n\t\\mathrm{Covar}[\\hat{D}_{k, i}, \\hat{D}_{k', j}] &=& \\underbrace{\\mathrm{Covar}[\\hat{P}_{k, i}, \\hat{P}_{k', j}]}_{C_{kk'} B_{ij}}  + \\alpha^2 \\underbrace{\\mathrm{Covar}[\\hat{S}_{k, i}, \\hat{S}_{k', j}] }_{\\tilde{C}_{kk'}^\\mathrm{fin} G_{ij}} + \\alpha \\underbrace{\\mathrm{Covar}[\\hat{P}_{k, i}, \\hat{S}_{k', j}]}_{ R_{kk'} S_{ij}} + \\alpha \\underbrace{\\mathrm{Covar}[\\hat{S}_{k, i}, \\hat{P}_{k', j}]}_{ R_{kk'} S_{ij}} \n}\nwhere we have defined the relevant covariances as before. In particular, the auxiliary simulations are correlated with $G_{ij}$ (subject to the same constraints as $B_{ij}$ as before), and $ R_{kk'} S_{ij}$ characterizes the covariance between the main and the auxiliary simulations. \nThose might need to be estimated from the simulations themselves, but may be partially estimated analytically.\nWe will discuss that below.\n\nThe mean and variance of the sample mean (power spectrum) estimator are\n\\eqn{\n\t\\mathbb{E}[\\bar{D}_{k}] &=& {P}^\\mathrm{fin}_k \t\\\\\t\n\t\\mathrm{Covar}[\\bar{D}_{k}, \\bar{D}_{k'}] &=& \\frac{1}{N^2}\\sum_{i=1}^N\\sum_{j=1}^N \\left( C_{kk'} B_{ij} + \\alpha^2  \\tilde{C}_{kk'}^\\mathrm{fin} G_{ij} + 2 \\alpha  R_{kk'} S_{ij}  \\right)\n}\nBy differentiating, we find that the value minimizing the variance is\n\\eqn{\n\t{\\alpha^\\mathrm{opt}_{kk'}} = \\ - \\ \\frac{ \\sum_{i=1}^N\\sum_{j=1}^N  R_{kk'} S_{ij} }{ \\sum_{i=1}^N\\sum_{j=1}^N \\tilde{C}_{kk'}^\\mathrm{fin} G_{ij} }\n}\nOf course those covariances/correlations might not be known and may need to be estimated directly from the data, especially because $R_{kk'} S_{ij}$ is a covariance and depends on the unknown target\t covariance ${C}_{kk'}^\\mathrm{fin}$.\n\\todo{Discuss how to estimate unbiased $ R_{kk'} S_{ij}$ from data.}\n\nLet's derive the mean and variance of the sample covariance, using a short-cut notation $F_{kk',ij} = \\mathrm{Covar}[\\hat{D}_{k, i}, \\hat{D}_{k', j}]$,\n\\eqn{\n\t\\mathbb{E}[\\hat{\\Delta}_{kk'}] &=&  \\frac{ \\sum_{i}F_{kk',ii} - \\frac{\\sum_{ij} F_{kk',ij}}{N} } {N-1}\t \\\\\t\n\t \\mathrm{Var}\\left[ \\hat{\\Delta}_{kk'}\\right]  &=&\t\\frac{\\sum_{ij} \\bigl(F_{kk,ij}F_{k'k',ij} + F_{kk',ij}^2 \\bigr) - \\frac{1}{N^2}\\bigl( \\sum_{ij}F_{kk,ij}F_{k'k',ij}\\bigr) - \\frac{1}{N^2}\\bigl(  F^2_{kk',ij} \\bigr)^2 }{(N-1)^2}\t\n\t}\n\t\\todo{Double check!!}\n\tNote that this estimator, in this current form, is biased since  $F_{kk',ij}$ contains the target unknown covariance ${C}_{kk'}^\\mathrm{fin}$ and also the known auxiliary covariance $\\tilde{C}_{kk'}^\\mathrm{fin}$.\n\t\nIt would be good to understand this estimator, even in a simpler setting. For this purpose, we assume that the known covariance is close to the true one $\\tilde{C}_{kk'} \\approx {C}_{kk'}$, and that the cross-correlations with the auxiliary simulations are such that $R_{kk',ij} \\approx {C}_{kk'} \\rho_{ij}$.\nThen, we can write $F_{kk',ij} ={C}_{kk'}  \\mathcal{B}_{ij}$ with $\\mathcal{B}_{ij} = B_{ij} + 2 \\alpha \\rho_{ij} + \\alpha^2 G_{ij}$. \nWith those assumptions, we find\n\\eqn{\n\t \\mathrm{Var}\\left[ \\frac{\\hat{\\Delta}_{kk'}}{\\mathbb{E}[\\hat{\\Delta}_{kk'}] /{C}_{kk'} }\\right]  &=&  \\frac{ \\sum_{ij} \\mathcal{B}_{ij}^2  - \\frac{\\left(\\sum_{ij}\\mathcal{B}_{ij}\\right)^2}{N^2}}{ \\left(\\sum_i \\mathcal{B}_{ii} - \\frac{\\sum_{ij}\\mathcal{B}_{ij}}{N}\\right)^2 }\n\t}\nwhere I haven't written out the bias explicitely for conciseness. \t\nWe see that the scaling takes unsurprisingly the same form as in our original investigations. However, there is a major difference: the coefficients $\\mathcal{B}_{ij}$ depend on $\\alpha$, which we can adjust to minimize the variance just like we did for the sample mean a few line above.\nBy differentiating, we find that the value(s) minimizing the variance, ${\\alpha^\\mathrm{opt}_{kk'}}$ is (are) the zero(s) of a third order polynomial\n\\eqn{\n\t \\alpha^3  \\times 2 \\left(  \\sum_{ij} G_{ij}^2 - \\frac{(\\sum_{ij} G_{ij})^2}{N}\\right) + \n\t  \\alpha^2 \\times 6 \\left(  \\sum_{ij} G_{ij} \\rho_{ij} - \\frac{\\sum_{ij} G_{ij} \\sum_{ij} \\rho_{ij}}{N} \\right) + \\\\ \n\t  \\alpha^1 \\times 2 \\left(  \\sum_{ij} G_{ij} B_{ij} - \\frac{\\sum_{ij} G_{ij} \\sum_{ij} B_{ij}}{N}  + 2 \\sum_{ij} \\rho^2_{ij} - 2\\frac{(\\sum_{ij}  \\rho_{ij})^2}{N}  \\right) + \n\t    2 \\left(  \\sum_{ij} B_{ij} \\rho_{ij} - \\frac{\\sum_{ij} B_{ij} \\sum_{ij} \\rho_{ij}}{N}  \\right)\n}\nNote that this is again for each pair of mode $kk'$. \nThis can be simplified further by adopting $G_{ij}=B_{ij}$ or $G_{ij} = 0$, but it is probably best to study this system numerically.\n\n\nLet's understand another version of this estimator, more connected to what we are probably going to run in practice. Let's assume the only correlation is between pairs of original-auxiliary simulations, not between original-original or auxiliary-auxiliary.  So we take $B_{ij} = G_{ij} = \\delta_{ij}$ and $R_{kk'} S_{ij} = R_{kk'}  \\delta_{ij}$.\nIn this case $F_{kk',ij} = \\delta_{ij}  \\left( {C}_{kk'} + \\alpha^2 \\tilde{C}_{kk'}^\\mathrm{fin}  + 2\\alpha R_{kk'} \\right) = F_{kk'}$.\n\\eqn{\n\t\\mathbb{E}[\\hat{\\Delta}_{kk'}] &=&  F_{kk'} \t \\\\\t\n\t \\mathrm{Var}\\left[ \\hat{\\Delta}_{kk'}\\right]  &=&  \\frac{F_{kk}F_{k'k'} + F_{kk'}^2 }{N-1}\t\\\\\n\t \t&=& \\frac{1}{N-1} \\Bigl[ \\left( {C}_{kk}{C}_{k'k'} + {C}_{kk'}^2 \\right)  + \\alpha \\left( 2R_{kk} {C}_{k'k'} + 2 R_{k'k'} C_{kk} + 4 {C}_{kk'}{R}_{kk'}\\right) \\\\\n\t\t&&  +  \\alpha^2 \\left( \\tilde{C}_{kk}^\\mathrm{fin} {C}_{k'k'} +  \\tilde{C}_{k'k'}^\\mathrm{fin}{C}_{kk} + {R}_{kk'}^2 + 4{R}_{kk}R_{k'k'} + 2  \\tilde{C}_{kk'}^\\mathrm{fin}{C}_{kk'} \\right)  \\\\\n\t\t&&  + \\alpha^3 \\left( 2R_{kk}\\tilde{C}_{k'k'}^\\mathrm{fin}  +R_{k'k'} \\tilde{C}_{kk}^\\mathrm{fin}  + 4R_{k'k'} \\tilde{C}_{kk'}^\\mathrm{fin}  \\right)  + \\alpha^4 \\left( \\tilde{C}_{kk}^\\mathrm{fin}   \\tilde{C}_{k'k'}^\\mathrm{fin} + (\\tilde{C}_{kk'}^\\mathrm{fin})^2    \\right)  \\Bigr]\n\t}\n\nThe estimator is easily debiased by considering $\\hat{\\Delta}_{kk'} -   \\alpha^2 \\tilde{C}_{kk'}^\\mathrm{fin}  - 2\\alpha R_{kk'} $ which does not change its variance. Again, we cannot reduce the scaling of the estimator with $N$, but we can reduce the constant term. Compared to the theoretical prediction setup, we have  extra degrees of freedom: the choice of $\\alpha$ for each $kk'$ pair. By solving the system $\\partial  \\mathrm{Var}[ \\hat{\\Delta}_{kk'}] /  \\partial \\alpha = 0$ numerically we could find the optimal $\\alpha$ that reduces the variance of the \nAgain, we can only reduce the constant term of the variance of the sample covariance. However, there is a big difference: the reduction does not rely on our ability to model the unknown covariance, but rather to correlate simulations. It doesn't matter what the covariance is for the auxiliary simulations as long as we know it. The more we correlate the simulations the small will the variance of our the mean and covariance estimators be. This is not true for the previous section on theoretical predictions.\n\nOf course we may not know $R_{kk'}$. Often we will have to estimate it from the simulations themselves, but of course not re-use the same set for the mean and covariance estimators of interest. This may require splitting the full set of simulations.\n\\todo{How to estimate that in practice?}.\n\n\n\\textbf{The main conclusion is that the variance of the sample covariance estimator can indeed be reduced by using control variates, especially an auxiliary set of simulations. However, this must be studied numerically.}\n\n\\todo{What is the actual reduction of the variance? What if $G_{ij}=B_{ij}$ or $G_{ij} = 0$? Can we actually study this system analytically, or should we just solve it numerically with real simulations? This would be reasonable given that all the correlation coefficients are pretty much unknown in reality.}\n\n\n\\todo{Compute product and ratio control variates for comparison.}\n\\todo{Discuss how to construct the auxiliary simulations with the right correlations}.\n\\todo{Discuss how to extend this to multiple simulations and control variates.}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Summary}\n\nWe have introduced three concepts that can be used to decrease the variance of simulation-based estimates in general: stratified sampling, theory proxy, and control variates. \nLet us briefly summarise them, for a random variable $X$.\n\\textbf{Stratified sampling} consists of performing correlated draws/simulations of $X$, and averaging them out in packets before (or somewhere in) the estimator of interest. \nThe \\textbf{theory proxy} simply consists of using an approximate analytical solution for the observable of interest, and only using the simulations to estimate the difference with the truth. \nThe use of \\textbf{control variates} consists of running an auxiliary set of simulations correlated with out main draws of $X$.\nThe three techniques exploit extra sources of information and can reduce the variance of any MC estimate. \n\n\\cite{PontzenEtAl2016} introduced the use of paired simulations, identifying $X$ to the initial density field, drawing two fully anti-correlated Gaussian initial conditions (thus simply flipping the sign), then evolving them before looking at the auto- and cross-power spectra.\nThey showed that the two evolved simulations are still significantly correlated, and that averaging their power spectra leads to a cancellation of some of the noise terms, which can be explained by perturbation theory to some extent. \nIn light of our findings, this is a case of stratified sampling, in fact antithetic estimators, where we exploit the anti-correlation that propagated from initial to evolved density field. \n\\cite{PontzenEtAl2016} just didn't run multiple pairs of simulations, but they did demonstrate the variance reduction with analytical arguments.\nThe true stratified sampling for the mean power spectrum would indeed rely on multiple groups of anti-correlated simulations. To obtain the maximum variance reduction, one should indeed run pairs of simulations with flipped signs.\n\n\\cite{AnguloPontzen2016} explored an extension: fixing the amplitude of the power spectrum to the theory, and only drawing the phases. Again, this leads to the cancellation of a few noise terms,  and it isn't surprising that this would further reduce the variance of the mean power spectrum.\nWhat is more interesting is that this trick is exactly what we need to use to design a stratified estimator for the covariance matrix. \nIndeed, we have seen that we cannot identify $X$ to the density field because anti-correlations in the density will not translate into variance reduction of the covariance matrix.\nWhat we need to do is generate density fields that have anti-correlated power spectra. As discussed above, by using the trick of \\cite{AnguloPontzen2016} we can design a good stratified estimator for the covariance matrix.\n\nWe also conclude that we cannot generate anti-correlated N-body simulations in a way that optimizes both the 2-pt and 4-pt estimators (the power spectrum and its covariance).\n\nOur findings should be generally applicable to 2-pt and 4-pt functions (thus to tomographic density and shear power spectra, covariance matrices, etc). We should even be able to design simulation strategies optimized to reduce the variance of higher-order estimates such as bi- and tri-spectra.\n\nIn other words, we have shown that:\n\\begin{itemize}\n\t\\item If we can run simulations that have anti-correlated observables (\\eg 3D power spectra), we can significantly reduce the variance of the sample mean and covariance estimators (estimating $P_k$ and its covariance). This is a generalization of the techniques described in \\cite{PontzenEtAl2016} and \\cite{AnguloPontzen2016}, which were partially exploiting the so-called antithetic estimator of the mean.\n\t\\item This variance reduction can be improved even further by considering stratified estimators, \\ie running groups of correlated simulations. In the specific case of antithetic \"paired\" simulations as explored in \\cite{PontzenEtAl2016} and \\cite{AnguloPontzen2016}, we have derived a new estimator for the covariance matrix.\n\t\\item Many of our derivations assumed Gaussian random variables, but our conclusions, and in particular the variance reduction, hold for non-Gaussian random variables. Those must be studied numerically, but it is very likely (and it has been found in other studies) that the anti-correlations introduced in the initial fields remain fairly conserved as it is evolved in an N-body simulation.\n\tThus, we should be able to significantly reduce the variance of the mean and covariance estimators applied to the evolved density field (in other words, we'll need fewer simulations).\n\t\\item We have only discussed the 3D power spectrum and its covariance, but our conclusions will also apply to any 2-pt estimators of the initial or evolved density field, and their covariances (tomographic power spectra, etc). They should also extend to n-pt correlations, such as the bispectrum, although the estimators will have to be modified.\n\t\\item Very concretely, we only need to tweak the correlations in the initial conditions of N-body simulations and adopt the previous stratified estimators. In particular, we must construct density fields (initial conditions for N-body simulations) which have anti-correlated observed power spectra. Inspired by \\cite{AnguloPontzen2016}, we have shown a simple way to achieve that. \n\\end{itemize}\n\nAll of those improvements require no changes in the way the simulations are run. We only need to generate the initial conditions differently, and adopt more complex estimators to compute the final power spectra and covariances.\n\nFurthermore, we have shown that including extra information such as (imperfect) theoretical modeling can also significantly reduce the number of simulations needed. In a naive approach, one can simply focus on estimating differences between the simulation and the imperfect model. In a much better approach, one can run an auxiliary set of simulations, where the analytic form of the target power spectrum or covariance is known, and exploit anti-correlations with the primary set of simulations to significantly reduce the variance of the estimators.\nFor this latter technique, one could in fact use an existing set of uncorrelated N-body simulations with a new set of simpler correlated simulations (\\eg  LPT) to reduce the variance.\n\n\\todo{Write down the final expressions combining stratified estimators with theoretical predictions and control variates!}\n\n\\todo{Check Weinberg and Coles papers}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Extensions}\n\n\\todo{Write down the estimators for the mean bispectrum and its covariance! All of the previous methods should work too.}\n\n\\todo{Sections about partial averaging, conditioning, Rao-Blackwellization, or importance sampling? Are those useful in this context? I don't think so but I'll check.}\n\n\\todo{Discuss what changes and does not change if we consider other observables, their mean and covariance.}\n\n\\todo{Precision matrices!}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\bibliography{bib}\n\n\\newpage\n\\appendix\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Derivation of the variance of the sample covariance estimator with correlated draws}\\label{sec:samplecovariancecorrelateddraws}\n\nWe first write\n\\eqn{\n\t\\hat{C}_{kk',i} \\ = \\ (\\hat{P}_{k, i} - \\bar{P}_{k})(\\hat{P}_{k', i} - \\bar{P}_{k'}) \n\t\\ = \\  \\hat{P}_{k, i}\\hat{P}_{k', i} - \\bar{P}_{k}\\hat{P}_{k', i} - \\hat{P}_{k, i}\\bar{P}_{k'}  + \\bar{P}_{k}\\bar{P}_{k'}\n} \nOur derivation requires unraveling the various components and going though some long expressions,\n\\eqn{\n\t && \\mathrm{Cov}[\\hat{C}_{kk',i} , \\hat{C}_{kk',j} ] \\\\\n\t &=& \n\t  \\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', i}, \\hat{P}_{k, j}\\hat{P}_{k', j} ] - \\mathrm{Cov}[ \\bar{P}_{k}\\hat{P}_{k', i}, \\hat{P}_{k, j}\\hat{P}_{k', j} ] - \\mathrm{Cov}[ \\hat{P}_{k, i}\\bar{P}_{k'} ,\\hat{P}_{k, j}\\hat{P}_{k', j} ] + \\mathrm{Cov}[\\bar{P}_{k}\\bar{P}_{k'}, \\hat{P}_{k, j}\\hat{P}_{k', j} ]\t\\\\\n\t &-& \\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', i} ,\\bar{P}_{k}\\hat{P}_{k', j} ] + \\mathrm{Cov}[ \\bar{P}_{k}\\hat{P}_{k', i}, \\bar{P}_{k}\\hat{P}_{k', j} ] + \\mathrm{Cov}[\\hat{P}_{k, i}\\bar{P}_{k'}, \\bar{P}_{k}\\hat{P}_{k', j} ] - \\mathrm{Cov}[\\bar{P}_{k}\\bar{P}_{k'}, \\bar{P}_{k}\\hat{P}_{k', j} ]\\\\\n\t &-& \\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', i}, \\hat{P}_{k, j}\\bar{P}_{k'}] + \\mathrm{Cov}[ \\bar{P}_{k}\\hat{P}_{k', i} ,\\hat{P}_{k, j}\\bar{P}_{k'}] + \\mathrm{Cov}[\\hat{P}_{k, i}\\bar{P}_{k'} ,\\hat{P}_{k, j}\\bar{P}_{k'}] -\\mathrm{Cov}[\\bar{P}_{k}\\bar{P}_{k'}, \\hat{P}_{k, j}\\bar{P}_{k'}]\\\\\n\t&+&  \\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', i}, \\bar{P}_{k}\\bar{P}_{k'}] - \\mathrm{Cov}[ \\bar{P}_{k}\\hat{P}_{k', i} , \\bar{P}_{k}\\bar{P}_{k'} ] - \\mathrm{Cov}[\\hat{P}_{k, i}\\bar{P}_{k'} , \\bar{P}_{k}\\bar{P}_{k'}] + \\mathrm{Cov}[\\bar{P}_{k}\\bar{P}_{k'} , \\bar{P}_{k}\\bar{P}_{k'}]\n}\n\n\nThanks to Isserlis' \\& Wick's theorem, we can use the following identity for any quadruplet of Gaussian random variables ABCD: \n\\eqn{\n\t\\mathrm{Cov}[AB,CD] &=& \\mathbb{E}[ABCD] - \\mathbb{E}[AB]\\mathbb{E}[CD] \\\\\n\t&=& \\mathbb{E}[AB]\\mathbb{E}[CD] + \\mathbb{E}[AC]\\mathbb{E}[BD] + \\mathbb{E}[AD]\\mathbb{E}[BC] - \\mathbb{E}[AB]\\mathbb{E}[CD] \\\\\n\t&=& \\mathbb{E}[AC]\\mathbb{E}[BD] + \\mathbb{E}[AD]\\mathbb{E}[BC] \\label{eq:wickstheorem}\n}\n\nWe can expand the covariances into expectations,\n\\eqn{\n\t && \\mathrm{Cov}[\\hat{C}_{kk',i} , \\hat{C}_{kk',j} ] =  \\\\\n\t && \n\t  \\EE[\\hat{P}_{k, i}\\hat{P}_{k, j}] \\EE[\\hat{P}_{k', i}\\hat{P}_{k', j} ] \n\t+\t  \\EE[\\hat{P}_{k, i}\\hat{P}_{k', j} ] \\EE[\\hat{P}_{k', i} \\hat{P}_{k, j}] \n\t  - \\EE[ \\bar{P}_{k}\\hat{P}_{k, j}] \\EE[\\hat{P}_{k', i} \\hat{P}_{k', j} ] \n\t  -  \\EE[ \\bar{P}_{k} \\hat{P}_{k', j} ] \\EE[\\hat{P}_{k', i} \\hat{P}_{k, j}] \\\\\n\t&&\t  - \\EE[ \\hat{P}_{k, i}\\hat{P}_{k, j}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ] \n\t  - \\EE[ \\hat{P}_{k, i}\\hat{P}_{k', j}]  \\EE[  \\bar{P}_{k'} \\hat{P}_{k, j}] \n\t + \\EE[\\bar{P}_{k}\\hat{P}_{k, j}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ]\t\n\t  + \\EE[\\bar{P}_{k} \\hat{P}_{k', j} ]  \\EE[\\bar{P}_{k'} \\hat{P}_{k, j} ]\t\\\\\n\t&& - \\EE[\\hat{P}_{k, i} \\bar{P}_{k}]  \\EE[ \\hat{P}_{k', i} \\hat{P}_{k', j} ] \n\t - \\EE[\\hat{P}_{k, i} \\hat{P}_{k', j} ]  \\EE[\\hat{P}_{k', i} \\bar{P}_{k} ] \n\t+ \\EE[ \\bar{P}_{k} \\bar{P}_{k}] \\EE[ \\hat{P}_{k', i} \\hat{P}_{k', j} ] \n\t + \\EE[ \\bar{P}_{k} \\hat{P}_{k', j}]  \\EE[  \\hat{P}_{k', i} \\bar{P}_{k}] \\\\\n\t&& + \\EE[\\hat{P}_{k, i} \\bar{P}_{k}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ] \n\t + \\EE[\\hat{P}_{k, i} \\hat{P}_{k', j}]  \\EE[  \\bar{P}_{k'} \\bar{P}_{k}] \n\t - \\EE[\\bar{P}_{k} \\bar{P}_{k}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ]\n\t - \\EE[\\bar{P}_{k} \\hat{P}_{k', j} ]  \\EE[\\bar{P}_{k'} \\bar{P}_{k} ] \\\\\n\t&& - \\EE[\\hat{P}_{k, i} \\hat{P}_{k, j}]  \\EE[ \\hat{P}_{k', i} \\bar{P}_{k'}] \n\t - \\EE[\\hat{P}_{k, i} \\bar{P}_{k'} ]  \\EE[\\hat{P}_{k', i} \\hat{P}_{k, j}] \n\t + \\EE[ \\bar{P}_{k} \\hat{P}_{k, j}]  \\EE[ \\hat{P}_{k', i} \\bar{P}_{k'}] \n\t + \\EE[ \\bar{P}_{k} \\bar{P}_{k'}] \\EE[ \\hat{P}_{k', i} \\hat{P}_{k, j}] \\\\\n\t&& + \\EE[\\hat{P}_{k, i}  \\hat{P}_{k, j} ]  \\EE[\\bar{P}_{k'}\\bar{P}_{k'}] \n\t + \\EE[\\hat{P}_{k, i} \\bar{P}_{k'}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k, j}] \n\t -\\EE[\\bar{P}_{k} \\hat{P}_{k, j}]  \\EE[ \\bar{P}_{k'} \\bar{P}_{k'}]\n\t -\\EE[\\bar{P}_{k} \\bar{P}_{k'}] \\EE[ \\bar{P}_{k'} \\hat{P}_{k, j}]\\\\\n\t&& +  \\EE[\\hat{P}_{k, i} \\bar{P}_{k} ]  \\EE[\\hat{P}_{k', i} \\bar{P}_{k'}] \n\t+  \\EE[\\hat{P}_{k, i} \\bar{P}_{k'} ]  \\EE[\\hat{P}_{k', i} \\bar{P}_{k}] \n\t- \\EE[ \\bar{P}_{k} \\bar{P}_{k} ] \\EE[\\hat{P}_{k', i}  \\bar{P}_{k'} ] \n\t- \\EE[ \\bar{P}_{k} \\bar{P}_{k'} ]  \\EE[\\hat{P}_{k', i}  \\bar{P}_{k} ] \\\\\n\t&&- \\EE[\\hat{P}_{k, i} \\bar{P}_{k} ]  \\EE[\\bar{P}_{k'}  \\bar{P}_{k'}] \n\t- \\EE[\\hat{P}_{k, i} \\bar{P}_{k'} ]  \\EE[\\bar{P}_{k'} \\bar{P}_{k}] \n\t+ \\EE[\\bar{P}_{k}  \\bar{P}_{k} ]  \\EE[\\bar{P}_{k'} \\bar{P}_{k'}]\n\t+ \\EE[\\bar{P}_{k} \\bar{P}_{k'} ]  \\EE[\\bar{P}_{k'}  \\bar{P}_{k}]\n\t  }\n\nThanks to commutativity of the terms within the expectations and also of the indices ($i, j, k, k'$), the only three terms we need to compute are:\\\n\\eqn{\n\t \\EE[\\hat{P}_{k, i}\\hat{P}_{k', j}] \\ &=& \\  \\mathrm{Cov}[\\hat{P}_{k, i}\\hat{P}_{k', j}] + \\mathbb{E}[\\hat{P}_{k, i}]\\mathbb{E}[\\hat{P}_{k', j}]  \\ =  \\ C_{kk'} \\underbrace{\\left( \\delta^K_{ij}(1-\\beta_{ij}) + \\beta_{ij} \\right)}_{B_{ij}} + P_k P_{k'} \\\\\n\t \\EE[\\bar{P}_{k}\\hat{P}_{k', j}] \\ &=&\\   \\frac{1}{N}  \\sum_{l=1}^{N}\\EE[\\hat{P}_{k, l}\\hat{P}_{k', j}]  \\ = \\ P_k P_{k'} + \\frac{C_{kk'} }{N}  \\underbrace{ \\sum_{l=1}^{N} \\left( \\delta^K_{lj}(1-\\beta_{lj}) + \\beta_{lj} \\right)}_{B_j} \\\\\n\t \\EE[\\bar{P}_{k}\\bar{P}_{k'}] \\ &=& \\ \\frac{1}{N^2}  \\sum_{l=1}^{N}  \\sum_{m=1}^{N} \\EE[\\hat{P}_{k, l}\\hat{P}_{k', m}]  \\  = \\ P_k P_{k'} + \\frac{C_{kk'}}{N^2} \\underbrace{ \\sum_{l=1}^{N}  \\sum_{m=1}^{N}   \\left( \\delta^K_{lm}(1-\\beta_{lm}) + \\beta_{lm} \\right)}_{B}\n}\nwhere we have assumed that we estimate the mean too, using the sample estimator. Obviously, we have $B=\\sum_{l=1}^{N}  B_{l}$ and $B_l=\\sum_{m=1}^{N}  B_{lm}$. \nWithout off-diagonal correlations, we have $B_{ij} = \\delta^K_{ij}$,  $B_l = 1$, and $B=N$. In this case, we recover the standard results\n\\eqn{\n\t \\EE[\\hat{P}_{k, i}\\hat{P}_{k', j}] \\ = \\  C_{kk'} \\delta^K_{ij} + P_k P_{k'} \\quad\\quad\\quad \\EE[\\bar{P}_{k}\\hat{P}_{k', j}] \\ =  \\  \\EE[\\bar{P}_{k}\\bar{P}_{k'}]  \\ =\\ P_k P_{k'} + \\frac{C_{kk'} }{N}  \n}\n\nThanks to the symmetry in $kk'$, there are only six unique terms in $\\mathrm{Cov}[\\hat{C}_{kk',i} , \\hat{C}_{kk',j} ] $:\n\\eqn{\n\tA_0 = &&  \\sum_{ij} \\EE[\\hat{P}_{k, i}\\hat{P}_{k, j}] \\EE[\\hat{P}_{k', i}\\hat{P}_{k', j} ]  \\ = \\ C_{kk}C_{k'k'}  \\sum_{ij} B_{ij}^2 + (C_{kk}P^2_{k'} + P_k^2C_{k'k'}) B  + N^2 P^2_{k}P^2_{k'} \\\\\n\tA_0^\\prime = &&  \\sum_{ij}  \\EE[\\hat{P}_{k, i}\\hat{P}_{k', j}] \\EE[\\hat{P}_{k', i}\\hat{P}_{k, j} ]  \\ = \\  C^2_{kk'}  \\sum_{ij} B^2_{ij} +  2 C_{kk'} B P_k P_{k'} +  N^2P_k^2 P_{k'}^2 \\\\\n\tA_1 = &&  \\sum_{ij}  \\EE[ \\bar{P}_{k}\\hat{P}_{k, j}] \\EE[\\hat{P}_{k', i} \\hat{P}_{k', j} ] \\ = \\   N^2 P^2_{k}P^2_{k'} + B \\Bigl( P^2_{k}C_{k'k'} + P^2_{k'} C_{kk} \\Bigr) + \\frac{C_{kk} C_{k'k'}  }{N} \\sum_{j}  B^2_j\t\\\\\n\tA_1^\\prime = &&  \\sum_{ij} \\EE[ \\bar{P}_{k} \\hat{P}_{k', j} ] \\EE[\\hat{P}_{k', i} \\hat{P}_{k, j}] \\ = \\ N^2 P^2_k P^2_{k'} + 2 BP_k P_{k'}C_{kk'}  +  \\frac{C^2_{kk'} }{N}  \\sum_{j} B^2_j\t\\\\\n\t&& \\sum_{ij} \t \\EE[\\bar{P}_{k}\\hat{P}_{k, j}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ]\t= A_1\t\\\\\n\t && \\sum_{ij} \t\\EE[\\bar{P}_{k} \\hat{P}_{k', j} ]  \\EE[\\bar{P}_{k'} \\hat{P}_{k, j} ]\t= A_1^\\prime \\\\ \n\tA_2 = && \\sum_{ij}   \\EE[ \\bar{P}_{k} \\bar{P}_{k}] \\EE[ \\hat{P}_{k', i} \\hat{P}_{k', j} ] =\t\tN^2P^2_kP^2_{k'} + B (P^2_k C_{k'k'}  + P^2_{k'} C_{kk} ) +\t \\frac{C_{kk}C_{k'k'}}{N^2}  B^2\\\\ \n\tA_2^\\prime = && \\sum_{ij}   \\EE[ \\bar{P}_{k} \\bar{P}_{k'}] \\EE[ \\hat{P}_{k, i} \\hat{P}_{k', j} ] =\t\tN^2 P^2_k P^2_{k'} + 2BC_{kk'}P_k P_{k'} +\\frac{C^2_{kk'}}{N^2} B^2 \\\\\n\t && \\sum_{ij}  \\EE[\\bar{P}_{k}  \\bar{P}_{k} ]  \\EE[\\bar{P}_{k'} \\bar{P}_{k'}]\t=   \\sum_{ij}  \\EE[\\bar{P}_{k} \\bar{P}_{k}]  \\EE[ \\bar{P}_{k'} \\hat{P}_{k', j} ] = A_2\\\\\n\t&& \\sum_{ij}  \\EE[\\bar{P}_{k} \\bar{P}_{k'} ]  \\EE[\\bar{P}_{k'}  \\bar{P}_{k}]\t=  \\sum_{ij} \\EE[\\bar{P}_{k} \\hat{P}_{k', j} ]  \\EE[\\bar{P}_{k'} \\bar{P}_{k} ] = A_2^\\prime\t\n}\nWe can then reduce the giant summation to\n\\eqn{\n\t&&  \\ \\mathrm{Var}[\\hat{C}_{kk'}] \\ = \\frac{\n\t A_0   +\t  A_0^\\prime  - A_2 - A_2^\\prime}{(N-1)^2}  =    \\bigl(C_{kk}C_{k'k'} + C_{kk'}^2 \\bigr) \\times \\frac{ \\sum_{ij} B_{ij}^2  - \\frac{(\\sum_{ij} B_{ij})^2}{N^2}}{(N-1)^2}\n}\n\n \n\n\n\n%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\end{document}\n%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "b49252154b095a3f9e34143a5b9a5fb35d9ddfbf", "size": 57389, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/variancereduction.tex", "max_stars_repo_name": "ixkael/VarianceReductionMethods", "max_stars_repo_head_hexsha": "b3ad66b17ae0353d880b32ed3061a9826025f173", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-04T22:27:50.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-04T22:27:50.000Z", "max_issues_repo_path": "paper/variancereduction.tex", "max_issues_repo_name": "ixkael/VarianceReductionMethods", "max_issues_repo_head_hexsha": "b3ad66b17ae0353d880b32ed3061a9826025f173", "max_issues_repo_licenses": ["MIT"], "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/variancereduction.tex", "max_forks_repo_name": "ixkael/VarianceReductionMethods", "max_forks_repo_head_hexsha": "b3ad66b17ae0353d880b32ed3061a9826025f173", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.7069444444, "max_line_length": 614, "alphanum_fraction": 0.6672184565, "num_tokens": 19520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6305380902364486}}
{"text": "\\section{Conclusion}\n\\label{sec:conclusion}\n\nWe have proven mathematically that the total-field anomaly data caused by a set of magnetic sources\nwith uniform magnetization direction can be exactly reproduced by a continuous and planar layer of \ndipoles having an all-positive magnetic-moment distribution. \nThis theoretical property holds true for the case in which a layer has the same\nmagnetization direction as that of the true sources, regardless of whether they have \na purely induced magnetization or not.\nBy using this generalized positivity constraint, we presented a new iterative method for \nestimating the total magnetization direction of 3D magnetic sources based on the equivalent-layer technique. \nAt each iteration, we impose a positivity constraint on the estimated magnetic-moment distribution of the layer \nand solve a non-linear inverse problem for estimating the magnetization direction of the equivalent sources. \nPrior knowledge about the shape and depth of magnetic sources is not required, neither the use of an evenly spaced \ndata set. This methodology can be applied for determining the magnetization direction of multiple sources, \nconsidering all of them with the same magnetization direction. \nResults obtained with synthetic data produced by multiple sources show that the estimated magnetization direction \nobtained by our iterative method successfully retrieves the true one.\nTests with synthetic data illustrate how the presence of a relatively shallow-seated source affects the \nresult obtained by our method for the cases in which it has a magnetization direction equal to and different from \nthe other sources. In both cases, the equivalent layer yielded large data misfits above the shallow source;\nhowever, we cannot distinguish whether the shallow source has a magnetization direction equal to or different from the other sources. \nMoreover, our method produces the most poorly estimated magnetization direction when shallow-seated source is magnetized in a \ndirection that differs from the other sources.\nAn application to field data over the Goi{\\' a}s alkaline province, center of Brazil, has confirmed that our method can \nbe a reliable tool for interpreting complex geological scenarios. The result over the Montes Claros complex suggests the presence \nof a strong remanent magnetization component and corroborates a previous study conducted independently at the same area. \nThe estimated magnetic-moment distribution over the layer has led to a very acceptable reduction to the pole, but also \nproduced large data-misfits at some isolated regions. We presume that these locally large data-misfits are due to shallow sources, \nhowever we cannot infer if they have the same magnetization direction of the other bodies.   \n", "meta": {"hexsha": "6d70bcb9e0e93076d82512504772c3b0f4790f1e", "size": 2765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/conclusions.tex", "max_stars_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_stars_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-09-03T03:00:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T10:33:08.000Z", "max_issues_repo_path": "manuscript/conclusions.tex", "max_issues_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_issues_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "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": "manuscript/conclusions.tex", "max_forks_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_forks_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-17T15:32:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T15:32:29.000Z", "avg_line_length": 89.1935483871, "max_line_length": 134, "alphanum_fraction": 0.827124774, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6305380861523509}}
{"text": "\\documentclass{article}\n\\usepackage[a4paper, left=25.4mm, top=25.4mm, right=25.4mm, bottom=25.4mm]{geometry}\n\\usepackage[shortlabels]{enumitem}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{authoraftertitle}\n\\usepackage{blindtext}\n\\usepackage{bussproofs}\n\\usepackage{color}\n\\usepackage{graphicx}\n\\usepackage{newpxtext}\n%\\usepackage{newpxmath}\n\\usepackage{ragged2e}\n\\usepackage{textcomp}\n\\usepackage{textgreek}\n\\renewcommand{\\thesubsection}{\\arabic{subsection}}\n\\newcommand\\tab[1][1cm]{\\hspace*{#1}}\n\\newcommand\\pfun{\\mathrel{\\ooalign{\\hfil$\\mapstochar\\mkern5mu$\\hfil\\cr$\\to$\\cr}}}\n\\newcommand\\lowermidtilde{\\raisebox{-0.8ex}{\\textasciitilde}}\n\\newcommand\\midtilde{\\raisebox{-0.6ex}{\\textasciitilde}}\n\\newcommand{\\partfarrow}{\\rightharpoonup}\n\\newcommand{\\partf}{\\rightharpoonup\\!\\!\\!\\!\\!\\!\\!\\!\\!\\raisebox{2.5pt}{$\\rightharpoonup$}}\n\n\\author{Victor Zhao\\\\xz398@cam.ac.uk}\n\n\\begin{document}\n\\centering\n\\section*{Discrete Mathematics\\\\CST Part IA Paper 2}\n\\MyAuthor\n\n\\justifying\n\\subsection{Proof}\n\\begin{enumerate}\n    \\item Some mathematical jargon:\n        \\begin{itemize}[topsep=0pt]\n            \\item \\textbf{Statement}: A sentence that is either true or false — but not both. \n            \\item \\textbf{Predicate}: A statement whose truth depends on the value of one or more variables.\n            \\item \\textbf{Theorem}: A very important true statement.\n            \\item \\textbf{Proposition}: A less important but nonetheless interesting true statement.\n            \\item \\textbf{Lemma}: A true statement used in proving other true statements.\n            \\item \\textbf{Corollary}: A true statement that is a simple deduction from a theorem or proposition.\n            \\item \\textbf{Conjecture}: A statement believed to be true, but for which we have no proof.\n            \\item \\textbf{Proof}: Logical explanation of why a statement is true; a method for establishing truth.\n            \\item \\textbf{Logic}: The study of methods and principles used to distinguish good (correct) from bad (incorrect) reasoning.\n            \\item \\textbf{Axiom}: A basic assumption about a mathematical situation. Axioms can be considered facts that do not need to be proved (just to get us going in a subject) or they can be used in definitions.\n            \\item \\textbf{Definition}: An explanation of the mathematical meaning of a word (or phrase). The word (or phrase) is generally defined in terms of properties.\n            \\item A statement is \\textit{simple} (or \\textit{atomic}) when it cannot be broken into other statements, and it is \\textit{composite} when it is built by using several (simple or composite statements) connected by logical expressions\n        \\end{itemize}\n    \\item Contraposition:\\\\\n        The contrapositive of $P\\implies Q$ is $\\neg Q\\implies\\neg P$.\n    \\item Modus Ponens:\n        If $P$ and $P\\implies Q$ holds then so does $Q$.\n        \\begin{prooftree}\n            \\AxiomC{$P$}\n            \\AxiomC{$P\\implies Q$}\n            \\BinaryInfC{$Q$}\n        \\end{prooftree}\n    \\item Some notations:\n        \\begin{itemize}[topsep=0pt]\n            \\item Implication: $\\implies$\n            \\item Bi-implication: $\\Longleftrightarrow$\n            \\item Universal quantification: $\\forall x.P(x)$\n            \\item Existential quantification: $\\exists x.P(x)$\n            \\item Unique existence: $\\exists!x.P(x)$\n                $$\\exists!x.P(x)\\Longleftrightarrow\\exists x.P(x)\\wedge\\Big(\\forall y.\\forall z.\\big(P(y)\\wedge P(z)\\big)\\implies y=z\\Big)$$\n            \\item Conjunction: $\\wedge$\n            \\item Disjunction: $\\vee$\n            \\item Negation: $\\neg$\n        \\end{itemize}\n    \\item Equality axioms:\n        \\begin{itemize}[topsep=0pt]\n            \\item Every individual is equal to itself.\n                $$\\forall x.x=x$$\n            \\item (Leibniz equality) For any pair of equal individuals, if a property holds for one of them, then ait also holds for the other one.\n                $$\\forall x.\\;\\forall y.\\;x=y\\implies (P(x)\\implies P(y))$$\n        \\end{itemize}\n\\end{enumerate}\n\\subsection{Numbers}\n\\begin{enumerate}\n    \\item Definitions of real numbers. A real number is:\n        \\begin{itemize}[topsep=0pt]\n            \\item \\textbf{rational} if it is of the form $\\frac{m}{n}$ for a pair of integers $m$ and $n$; otherwise it is \\textbf{irrational};\n            \\item \\textbf{positive} if it is greater than 0, and \\textbf{negative} if it is smaller than 0;\n            \\item \\textbf{nonnegative}~if~it~is~greater~than~or~equal~to~0,~and~\\textbf{nonpositive}~if~it~is~smaller~than~or~equal~to~0;\n            \\item \\textbf{natural} if it is a nonnegative integer.\n        \\end{itemize}\n    \\item Additive structure $(\\mathbb{N},0,+)$ of natural numbers with zero and addition is a commutative monoid\\\\(a \\textit{monoid} is a semigroup with an identity element; a \\textit{semigroup} preserves closure and associativity):\n        \\begin{itemize}[topsep=0pt]\n            \\item Monoid laws:\n                $$\\begin{aligned}\n                \t0+n&=n+0=n&&\\text{(identity)} \\\\\n                \t(l+m)+n&=l+(m+n)&&\\text{(associativity)}\n                \\end{aligned}$$\n            \\item Commutativity law:\n                $$m+n=n+m$$\n        \\end{itemize}\n    \\item Multiplicative structure $(\\mathbb{N},1,\\cdot)$ of natural numbers with one and multiplication is a commutative monoid:\n        \\begin{itemize}[topsep=0pt]\n            \\item Monoid laws:\n                $$1\\cdot n=n\\cdot 1=n$$\n                $$(l\\cdot m)\\cdot n=l\\cdot(m\\cdot n)$$\n            \\item Commutativity law:\n                $$m\\cdot n=n\\cdot m$$\n        \\end{itemize}\n    \\item The overall structure $(\\mathbb{N},0,+,1,\\cdot)$ is a commutative semiring:\n        \\begin{itemize}[topsep=0pt]\n            \\item $(\\mathbb{N},0,+)$ is a commutative monoid;\n            \\item $(\\mathbb{N},1,\\cdot)$ is a monoid;\n            \\item Multiplication is distributive over addition:\n                $$l\\cdot(m+n)=l\\cdot m+l\\cdot n$$\n            \\item Multiplication by 0 annihilates $\\mathbb{N}$:\n                $$0\\cdot n=n\\cdot 0=0$$\n        \\end{itemize}\n    \\item Cancellation:\n        \\begin{itemize}[topsep=0pt]\n            \\item Additive cancellation: for all natural numbers $k$, $m$, $n$,\n                $$k+m=k+n\\implies m=n$$\n            \\item Multiplicative cancellation: for all natural numbers $k$, $m$, $n$,\n                $$\\text{if }k\\neq0\\text{ then }k\\cdot m=k\\cdot n\\implies m=n$$\n        \\end{itemize}\n    \\item Inverses:\n        \\begin{itemize}[topsep=0pt]\n            \\item A number $x$ is said to admit an \\textbf{additive inverse} whenever there exists a number $y$ such that $x+y=0$;\n            \\item A number $x$ is said to admit an \\textbf{multiplicative inverse} whenever there exists a number $y$ such that $x\\cdot y=1$. \n        \\end{itemize}\n    \\item The integers $\\mathbb{Z}$ form a commutative ring, and the rationals $\\mathbb{Q}$ form a field:\n        \\begin{itemize}[topsep=0pt]\n            \\item A \\textit{group} is a monoid in which every element has an inverse;\n            \\item A \\textit{ring} is a semiring $(0,+)$, $(1,\\cdot)$ where $(0,+)$ is a commutative group. It is commutative if $(1,\\cdot)$ is also commutative;\n            \\item A \\textit{field} is a ring where every non-zero element has a multiplicative inverse.\n        \\end{itemize}\n    \\item Divisibility and congruence:\n        \\begin{itemize}[topsep=0pt]\n            \\item Let $d$ and $n$ be integers. We say that $d$ \\textit{devides} $n$, and write $d|n$, whenever there exists an integer $k$ such that $n=k\\cdot d$;\n            \\item Fix a positive integer $m$. For integers $a$ and $b$, we say that $a$ \\textit{is congruent to} $b$ \\textit{modulo} $m$, and write $a\\equiv b\\;(\\text{mod } m)$, whenever $m|(a-b)$.\n        \\end{itemize}\n    \\item For all prime numbers $p$ and integers $0\\leq m\\leq p$, either $\\binom{p}{m}\\equiv 0\\;(\\text{mod } p)$ or $\\binom{p}{m}\\equiv 1\\;(\\text{mod } p)$.\\\\\n        For $0<m<p$, $p|\\binom{p}{m}$ and $(p-m)|\\binom{p-1}{m}$.\n    \\item The Freshman's Dream: For all natural numbers $m$, $n$ and primes $p$, \n        $$(m+n)^p\\equiv m^p+n^p\\;(\\text{mod } p)$$\n    \\item The Dropout Lemma: For all natural numbers $m$ and primes $p$, \n        $$(m+1)^p\\equiv m^p+1\\;(\\text{mod } p)$$\n    \\item The Many Dropout Lemma: For all natural numbers $m$ and $i$, and primes $p$,\n        $$(m+i)^p\\equiv m^p+i\\;(\\text{mod } p)$$\n    \\item Fermat's Little Theorem: For all natural numbers $i$ and primes $p$, \n        \\begin{itemize}[topsep=0pt]\n            \\item $i^p\\equiv i\\;(\\text{mod } p)$, and\n            \\item $i^{p-1}\\equiv 1\\;(\\text{mod } p)$ whenever $i$ is not a multiple of $p$.\n        \\end{itemize}\n    \\item The Division Theorem: For every natural number $m$ and positive natural number $n$, there exists a unique pair of integers $q$ and $r$ such that $q\\geq0$, $0\\leq r\\leq n$, and $m=q\\cdot n+r$.\n    \\item Modular arithmetic: For all natural numbers $m>1$, the modular-arithmetic structure \n        $$(\\mathbb{Z}_m,0,+_m,1,\\cdot_m)$$\n        is a commutative ring.\\\\\n        For prime $p$, $\\mathbb{Z}_p$ is a field.\n    \\item Greatest Common Divisor: For all positive integers $m$ and $n$,\n        $$\\text{gcd}(m,n)=\\begin{cases}\n            n &, \\text{if }n|m\\\\\n            \\text{gcd}\\big(n,\\text{rem}(m,n)\\big) &, \\text{otherwise}\n        \\end{cases}$$\n    \\item Some fundamental properties of gcds:\n        \\begin{itemize}[topsep=0pt]\n            \\item Commutativity: $\\text{gcd}(m,n)=\\gcd(n,m)$,\n            \\item Associativity: $\\text{gcd}\\big(l,\\gcd(m,n)\\big)=\\text{gcd}\\big(\\gcd(l,m),n\\big)$,\n            \\item Distributivity: $\\text{gcd}(l\\cdot m,l\\cdot n)=l\\cdot\\text{gcd}(m,n)$.\n        \\end{itemize}\n    \\item Theorem: For positive integers $k$, $m$, and $n$, if $k|(m\\cdot n)$ and $\\text{gcd}(k,m)=1$ then $k|n$.\\\\\n        Corollary (Euclid's Theorem): For positive integers $m$, $n$, and prime $p$, if $p|(m\\cdot n)$ then $p|m$ or $p|n$.\n    \\item For all positive integers $m$ and $n$,\n        \\begin{itemize}[topsep=0pt]\n            \\item $n\\cdot\\text{lc}_2(m,n)\\equiv\\text{gcd}(m,n)\\;(\\text{mod }m)$, and\n            \\item whenever $\\text{gcd}(m,n)=1$,\\\\\n                $[\\text{lc}_2(m,n)]_m$ is the multiplicative inverse of $[n]_m$ in $\\mathbb{Z}_m$.\n        \\end{itemize}\n\\newpage\n    \\item Principle of Induction:\\\\\n        Let $P(m)$ be a statement for $m$ ranging over the natural numbers greater than or equal to a fixed natural number $l$. If \n        \\begin{itemize}[topsep=0pt]\n            \\item $P(l)$ holds, and \n            \\item $\\forall n\\geq l\\text{ in }\\mathbb{N}.\\big(P(n)\\implies P(n+1)\\big)$ also holds,\n        \\end{itemize}\n        then\n        \\begin{itemize}[topsep=0pt]\n            \\item $\\forall m\\geq l\\text{ in }\\mathbb{N}.P(m)$ holds.\n        \\end{itemize}\n    \\item Principle of Strong Induction:\\\\\n        Let $P(m)$ be a statement for $m$ ranging over the natural numbers greater than or equal to a fixed natural number $l$. If \n        \\begin{itemize}[topsep=0pt]\n            \\item $P(l)$ holds, and \n            \\item $\\forall n\\geq l\\text{ in }\\mathbb{N}.\\Big(\\big(\\forall k\\in[l..n].P(k)\\big)\\implies P(n+1)\\Big)$ also holds,\n        \\end{itemize}\n        then\n        \\begin{itemize}[topsep=0pt]\n            \\item $\\forall m\\geq l\\text{ in }\\mathbb{N}.P(m)$ holds.\n        \\end{itemize}\n    \\item Well-Founded Induction:\\\\\n        \\textbf{Definition:} a \\textit{well-founded relation} is a binary relation $\\prec$ on a set $A$ such that there are no infinite descending chains $\\cdots\\prec a_i\\prec\\cdots\\prec a_1\\prec a_0$. When $a\\prec b$ we say $a$ is a \\textit{predecessor} of $b$.\\\\\n        \\textbf{Principle of Well-Founded Induction:} Let $\\prec$ be a well-founded relation on a set $A$. if\n        \\begin{itemize}[topsep=0pt]\n            \\item $\\forall a\\in A.\\Big(\\big(\\forall b\\prec a.P(b)\\big)\\implies P(a)\\Big)$ holds,\n        \\end{itemize}\n        then\n        \\begin{itemize}[topsep=0pt]\n            \\item $\\forall a\\in A.P(a)$ holds.\n        \\end{itemize}\n    \\item Fundamental Theorem of Arithmetic: For every positive integer $n$ there is a unique finite ordered sequence of primes $(p_1\\leq\\cdots\\leq p_l)$ with $l\\in\\mathbb{N}$ such that\n        $$n=\\displaystyle\\prod_{i=1}^{l}p_i.$$\n\\end{enumerate}\n\\newpage\n\\subsection{Sets}\n\\begin{enumerate}\n    \\item Axioms:\n        \\begin{itemize}[topsep=0pt]\n            \\item Extensionality axiom: Two sets are equal if they have the same elements.\n                $$\\forall\\text{ sets }A, B\\;.\\;A=B\\Longleftrightarrow(\\forall x.x\\in A\\Longleftrightarrow x\\in B)$$\n            \\item Powerset axiom: For any set, there is a set consisting of all its subsets.\n            \\item Pairing axiom: For every $a$ and $b$, there is a set with $a$ and $b$ as its only elements.\n            \\item Union axiom: Every collection of sets has a union.\n            \\item Infinity axiom: There is an infinite set, containing $\\emptyset$ and closed under successor. \\\\($\\text{Succ}(x)=_\\text{def}x\\cup\\{x\\}$)\n            \\item Axiom of choice: Every surjection has a section (right inverse).\n            \\item Replacement axiom: The direct image of every definable functional property on a set is a set.\n        \\end{itemize}\n    \\item Cardinality:\n        \\begin{itemize}[topsep=0pt]\n            \\item $\\forall\\text{ finite set }U.\\#\\mathcal{P}(U)=2^{\\#U}$\n            \\item $\\forall\\text{ sets }A,B.\\#(A\\times B)=\\#A\\times\\#B$\n            \\item $\\forall\\text{ sets }A,B.\\#(A\\uplus B)=\\#A+\\#B$\n        \\end{itemize}\n    \\item Subsets:\n        $$A\\subseteq B\\Longleftrightarrow(\\forall x.x\\in A\\implies x\\in B)$$\n        $$A\\subset B\\Longleftrightarrow(A\\subseteq B\\wedge A\\neq B)$$\n        Reflexivity: $\\forall\\text{ set }A\\;.\\;A\\subseteq A$\\\\\n        Transitivity: $\\forall\\text{ set }A,B,C\\;.\\;(A\\subseteq B\\wedge B\\subseteq C)\\implies A\\subseteq C$\\\\\n        Antisymmetry: $\\forall\\text{ set }A,B\\;.\\;(A\\subseteq B\\wedge B\\subseteq A)\\implies A=B$\n    \\item Separation principle: For any set $A$ and any definable property $P$, there is a set containing precisely those elements of $A$ for which the property $P$ holds.\n        $$\\{x\\in A\\;|\\;P(x)\\}$$\n    \\item The powerset Boolean algebra: $\\big(\\mathcal{P}(U), \\emptyset, U, \\cup, \\cap, (\\cdot)^c\\big)$\n        \\begin{itemize}[topsep=0pt]\n            \\item For all $A, B\\in\\mathcal{P}(U)$,\n                $$A\\cup B=\\{x\\in U\\;|\\;x\\in A\\vee x\\in B\\}\\in\\mathcal{P}(U)$$\n                $$A\\cap B=\\{x\\in U\\;|\\;x\\in A\\wedge x\\in B\\}\\in\\mathcal{P}(U)$$\n                $$A^c=\\{x\\in U\\;|\\;\\neg(x\\in A)\\}\\in\\mathcal{P}(U)$$\n            \\item The union operateion $\\cup$ and the intersection operation $\\cap$ are associative, commutative, and idempotent:\n                $$(A\\cup B)\\cup C=A\\cup(B\\cup C),\\;A\\cup B=B\\cup A,\\;A\\cup A=A$$\n                $$(A\\cap B)\\cap C=A\\cap(B\\cap C),\\;A\\cap B=B\\cap A,\\;A\\cap A=A$$\n            \\item The \\textit{empty set} $\\emptyset$ is a neutral element for $\\cup$ and the \\textit{universal set} $U$ is a neutral element for $\\cap$:\n                $$\\emptyset\\cup A=U\\cap A=A$$\n            \\item The empty set $\\emptyset$ is an annihilator for $\\cap$ and the universal set $U$ is an annihilator for $\\cup$:\n                $$\\emptyset\\cap A=\\emptyset$$\n                $$U\\cup A=U$$\n            \\item With respect to each other, the union operation $\\cup$ and the intersection operation $\\cap$ are distributive and absorptive:\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                $$A\\cup(A\\cap B)=A\\cap(A\\cup B)=A$$\n            \\item The complement operation $(\\cdot)^c$ satisfies complementation laws:\n                $$A\\cup A^c=U,\\;A\\cap A^c=\\emptyset$$\n        \\end{itemize}\n    \\item Ordered pair: $\\langle a, b\\rangle=_{\\text{def}}\\big\\{\\{a\\},\\{a, b\\}\\big\\}$\\\\\n    Fundamental property or ordered pairing: \n        $$\\forall a,b,x,y\\;.\\;\\langle a,b\\rangle=\\langle x,y\\rangle\\Longleftrightarrow(a=x\\wedge b=y)$$\n    \\item Big Unions: Let $U$ be a set. For a collection of sets $\\mathcal{F}\\in\\mathcal{P}(\\mathcal{P}(U))\\;(\\text{i.e. }\\mathcal{F}\\subseteq\\mathcal{P}(U))$, \n        $$\\bigcup\\mathcal{F}=_{\\text{def}}\\{x\\in U\\;|\\;\\exists A\\in\\mathcal{F}.x\\in A\\}\\in\\mathcal{P}(U)$$\n    Idea: \n        $$\\bigcup\\{A_1, A_2, \\cdots\\}=(A_1\\cup A_2\\cup\\cdots)\\subseteq U$$\n    \\item Big Intersections: Let $U$ be a set. For a collection of sets $\\mathcal{F}\\in\\mathcal{P}(\\mathcal{P}(U))\\;(\\text{i.e. }\\mathcal{F}\\subseteq\\mathcal{P}(U))$, \n        $$\\bigcap\\mathcal{F}=_{\\text{def}}\\{x\\in U\\;|\\;\\forall A\\in\\mathcal{F}.x\\in A\\}\\in\\mathcal{P}(U)$$\n    Idea: \n        $$\\bigcap\\{A_1, A_2, \\cdots\\}=(A_1\\cap A_2\\cap\\cdots)\\subseteq U$$\n    \\item Tagging: $\\{l\\}\\times A$\n    \\item Disjoint Unions: $A\\uplus B=_\\text{def}\\big(\\{1\\}\\times A\\big)\\cup\\big(\\{2\\}\\times B\\big)$\n        $$\\forall x.x\\in(A\\uplus B)\\Longleftrightarrow\\big(\\exists a\\in A.x=(1,a)\\big)\\vee\\big(\\exists b\\in B.x=(2,b)\\big)$$\n\\end{enumerate}\n\\newpage\n\\subsection{Relations}\n\\begin{enumerate}\n    \\item Some notations and definitions:\n        \\begin{itemize}[topsep=0pt]\n            \\item Relation: $\\pfun$\\\\\n                For all finite sets $A$ and $B$, $\\#\\text{Rel}(A, B)=2^{\\#A\\cdot\\#B}$\n            \\item Partial function: $\\rightharpoonup$\\\\\n                Set of partial functions: $\\partf$\\\\\n                Every partial function $f:A\\rightharpoonup B$ satisfies that: for each element $a$ of $A$ there is at most one element $b$ of $B$ such that $a\\;f\\;b$.\n                $$\\forall f\\in\\text{Rel}(A, B).\\;f\\in(A\\partf\\;B)\\Longleftrightarrow\\forall a\\in A.\\forall b_1,b_2\\in B.\\;a\\;f\\;b_1\\wedge a\\;f\\;b_2\\implies b_1=b_2$$\n                For all finite sets $A$ and $B$, $\\#(A\\partf\\;B) = (\\#B+1)^{\\#A}$\n            \\item Mapping: $\\mapsto$\n            \\item Function: $\\rightarrow$\\\\\n                Set of functions: $\\Rightarrow$\\\\\n                A partial function is total if its domain of definition coincides with its source.\n                $$\\forall f\\in(A\\partf\\;B).\\;f\\in(A\\Rightarrow B)\\Longleftrightarrow\\forall a\\in A.\\;\\exists b\\in B.\\;a\\;f\\;b$$\n                $$\\forall f\\in\\text{Rel}(A, B).\\;f\\in(A\\Rightarrow B)\\Longleftrightarrow\\forall a\\in A.\\;\\exists!b\\in B.\\;a\\;f\\;b$$\n                For all finite sets $A$ and $B$, $\\#(A\\Rightarrow B) = \\#B^{\\#A}$\n            \\item Injection: $\\rightarrowtail$\\\\\n                A function $f:A\\rightarrow B$ is injective whenever \n                $$\\forall a_1,\\;a_2\\in A.\\;f(a_1)=f(a_2)\\implies a_1=a_2$$\n            \\item Surjection: $\\twoheadrightarrow$\\\\\n                A function $f:A\\rightarrow B$ is surjective whenever \n                $$\\forall b\\in B.\\;\\exists a\\in A.\\;f(a)=b$$\n                For all finite sets $A$ and $B$, $\\#\\text{Sur}(A,B)=$\n            \\item Bijection: A function $f:A\\rightarrow B$ is bijective whenever there exists a (necessarily unique) function $g:B\\rightarrow A$ (referred to as the inverse of $f$) such that\n                $$g\\circ f=\\text{id}_A\\quad\\text{and}\\quad f\\circ g=\\text{id}_B$$\n                For all finite sets $A$ and $B$,\n                $$\\#\\text{Bij}(A,B)=\\begin{cases}\n                    0 &, \\text{if }\\#A\\neq\\#B\\\\\n                    n! &, \\text{if }\\#A=\\#B=n\n                \\end{cases}$$\n        \\end{itemize}\n    \\item Composition:\\\\\n        Composition of two relations $R:A\\pfun B$ and $S:B\\pfun C$: \n            $$S\\circ R:A\\pfun C$$\n        Relational composition is associative and has the identity relation as neutral element:\n            $$\\forall R:A\\pfun B,\\;S:B\\pfun C,\\;T:C\\pfun D\\;.\\;(T\\circ S)\\circ R=T\\circ(S\\circ R)$$\n            $$\\forall R:A\\pfun B\\;.\\;R\\circ\\text{id}_A=\\text{id}_B\\circ R=R$$\n        $R^{\\circ n}$: $R$ composed with itself $n$ times.\\\\\n        $R^{\\circ*}=\\bigcup_{n\\in\\mathbb{N}}R^{\\circ n}$\n    \\newpage\n    \\item Preorders:\\\\\n        A preorder $(P,\\sqsubseteq)$ consists of a set $P$ and a relation $\\sqsubseteq$ on $P$ satisfying the following two axioms:\n        \\begin{itemize}[topsep=0pt]\n            \\item Reflexivity: $\\forall x\\in P.x\\sqsubseteq x$\n            \\item Transitivity: $\\forall x,y,z\\in P.(x\\sqsubseteq y\\wedge y\\sqsubseteq z)\\implies x\\sqsubseteq z$\n        \\end{itemize}\n        $R^{\\circ*}$ is the reflexive-transitive closure of $R$\\\\\n        $R^{\\circ*}$ is the least preorder containing $R$\\\\\n        $R^{\\circ*}$ is the preorder freely generated by $R$\n    \\item Isomorphism: $\\cong$\\\\\n        Two sets $A$ and $B$ are isomorphic (and have the same cardinality) whenever there is a bijection between them,\n    \\item Equivalence relations:\\\\\n        A relation $E$ on a set $A$ is an equivalence relation whenever it is:\n        \\begin{itemize}[topsep=0pt]\n            \\item Reflexive: $\\forall x\\in A.\\;x\\;E\\;x$\n            \\item Symmetric: $\\forall x, y\\in A.\\; x\\;E\\;y\\implies y\\;E\\;x$\n            \\item Transitive: $\\forall x, y, z\\in A.\\;(x\\;E\\;y\\wedge y\\;E\\;z)\\implies x\\;E\\;z$\n        \\end{itemize}\n    \\item Set partitions:\\\\\n        A partition $P$ of a set $A$ is a set of non-empty subsets of $A$ (that is, $P\\subseteq\\mathcal{P}(A)$ and $\\emptyset\\notin P$), whose elements are typically referred to as blocks, such that\n        \\begin{itemize}[topsep=0pt]\n            \\item The union of all blocks yields $A$: $\\bigcup P=A$, and\n            \\item All blocks are pairwise disjoint: $\\forall B_1, B_2\\in P.\\;B_1\\neq B_2\\implies B_1\\cap B_2=\\emptyset$\n        \\end{itemize}\n        For every set $A$: $\\text{EqRel}(A)\\cong\\text{Part}(A)$\n    \\item Enumerability:\\\\\n        A set $A$ is enumerable whenever there exists a surjection ($\\mathbb{N}\\twoheadrightarrow A$), or a injection ($A\\rightarrowtail\\mathbb{N}$), referred to as an enumeration.\\\\\n        A countable set is one that is either empty or enumerable.\n    \\item Relational images and functional images:\\\\\n        Let $R:A\\pfun B$ be a relation.\n        \\begin{itemize}[topsep=0pt]\n            \\item The direct image of $X\\subseteq A$ under $R$ is the set $\\overrightarrow{R}(X)\\subseteq B$:\n                $$\\overrightarrow{R}(X)=\\{b\\in B|\\exists x\\in X\\;.\\;x\\;R\\;b\\}$$\n                This construction yields a function $\\overrightarrow{R}:\\mathcal{P}(A)\\to\\mathcal{P}(B)$.\n            \\item The inverse image of $Y\\subseteq B$ under $R$ is the set $\\overleftarrow{R}(X)\\subseteq A$:\n                $$\\overleftarrow{R}(Y)=\\{a\\in A|\\forall b\\in B\\;.\\;a\\;R\\;b\\implies b\\in Y\\}$$\n                This construction yields a function $\\overleftarrow{R}(Y):\\mathcal{P}(B)\\to\\mathcal{P}(A)$.\n        \\end{itemize}\n        Let $f:A\\to B$ be a function.\n        \\begin{itemize}[topsep=0pt]\n            \\item For all $X\\subseteq A$, $\\overrightarrow{f}(X)=\\{b\\in B|\\exists a\\in X\\;.\\;f(a)=b\\}$;\n            \\item For all $Y\\subseteq B$, $\\overleftarrow{f}(Y)=\\{a\\in A|f(a)\\in Y\\}$.\n        \\end{itemize}\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "36c1a20730b31a608aff463a7a0e7c9cffa1c1b9", "size": 22814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DiscMath Notes.tex", "max_stars_repo_name": "VictorZXY/cst-part-ia-discmath-notes", "max_stars_repo_head_hexsha": "b218be6f8fa27ca9741421292b5c88534e59e589", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DiscMath Notes.tex", "max_issues_repo_name": "VictorZXY/cst-part-ia-discmath-notes", "max_issues_repo_head_hexsha": "b218be6f8fa27ca9741421292b5c88534e59e589", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DiscMath Notes.tex", "max_forks_repo_name": "VictorZXY/cst-part-ia-discmath-notes", "max_forks_repo_head_hexsha": "b218be6f8fa27ca9741421292b5c88534e59e589", "max_forks_repo_licenses": ["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.3722222222, "max_line_length": 264, "alphanum_fraction": 0.5980099939, "num_tokens": 7398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6305380852890797}}
{"text": "\\subsection{Implementation of temporal constraint with Huang style transfer}\nIn this implementation we have used the idea that style is a distribution of features described in Section \\ref{sec:Style is a distribution of features}. We have utilized the Wasserstein metric in order to change the style loss of our previous implementation for style transfer for videos described in \\ref{sec:Ruder style transfer}. This implementation is one of our own experiments with style transfer for video, as we combine the Ruder implementation with temporal constraint and change up the style loss to the one proposed in the paper by Huang et al. \\cite{Huang:1}. \n\\newline\\newline\nSince calculating the Wasserstein distance is computationally heavy, we have simplified this calculation. We characterize the distribution of features with simply the mean value and co-variance of the distributions, then using these to calculate the Wasserstein distance between them. For these calculations we have used TensorFlow, so we can more easily run the computations on a GPU for faster calculations.\\newline\\newline\nThe loss function for this implementation uses the same layers in the VGG-19 CNN as our implementation from Section \\ref{sec:Ruder style transfer}, but the weights are different as the style loss is a lot smaller. The weight for the style loss here is 400 times larger than for our Ruder implementation. The results for this implementation can be found in Section \\ref{sec:Results with wasserstein metric}.\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.12]{report/Method/images/shrek_comparison.png}\n\\caption{Leftmost we see a frame from the first Shrek movie. The middle image is styled with the Gram Matrices from Gatys paper. The rightmost image is styled with Wasserstein as loss function. Both were styled with La Muse (Picasso) as style reference.}\n\\label{fig:architecture}\n\\end{center}\n\\end{figure}", "meta": {"hexsha": "a1511327bfea2501a7e148f13354fd043fbfc3fe", "size": 1913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Method/huang.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/Method/huang.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/Method/huang.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": 159.4166666667, "max_line_length": 573, "alphanum_fraction": 0.8139048615, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6305380806736568}}
{"text": "\\section{Abstract Convergence}\n\\label{sect.abstract.convergence}\n\nStrong eventual consistency (SEC) requires \\emph{convergence} of all copies of the shared state: whenever two nodes have received the same set of updates, they must be in the same state.\nThis definition constrains the values that read operations may return at any time, making SEC a stronger property than eventual consistency.\nBy accessing only their local copy of the shared state, nodes can execute read and write operations without waiting for network communication.\nNodes exchange updates asynchronously when a network connection is available.  \n\nWe now use Isabelle to formalise the notion of strong eventual consistency.\nIn this section we do not make any assumptions about networks or data structures; instead, we use an abstract model of operations that may be reordered, and we reason about the properties that those operations must satisfy.\nWe then provide concrete implementations of that abstract model in later sections.\n\n\\subsection{The Happens-before Relation and Causality}\\label{sect.happens.before}\n\nThe simplest way of achieving convergence is to require all operations to be commutative, but this definition is too strong to be useful for many datatypes.\nFor example, in a set, an element may first be added and then subsequently removed again.\nAlthough it is possible to make such additions and removals unconditionally commutative, doing so yields counter-intuitive semantics \\cite{Bieniusa:2012wu,Bieniusa:2012gt}.\nInstead, a better approach is to require only \\emph{concurrent} operations to commute with each other.\nTwo operations are concurrent if neither ``knew about'' the other at the time when they were generated.\nIf one operation happened before another---for example, if the removal of an element from a set knew about the prior addition of that element from the set---then it is reasonable to assume that all nodes will apply the operations in that order (first the addition, then the removal).\n\nThe \\emph{happens-before} relation, as introduced by \\citet{Lamport:1978jq}, captures such causal dependencies between operations.\nIt can be defined in terms of sending and receiving messages on a network, and we give such a definition in Section~\\ref{sect.network}.\nHowever, for now, we keep it abstract, writing $\\isa{x} \\prec \\isa{y}$ to indicate that operation $\\isa{x}$ happened before $\\isa{y}$, where $\\prec$ is a predicate of type $\\isacharprime\\isa{oper} \\mathbin{\\isasymRightarrow} \\isacharprime\\isa{oper} \\mathbin{\\isasymRightarrow} \\isa{bool}$.\nIn words, $\\prec$ can be applied to two operations of some abstract type $\\isacharprime\\isa{oper}$, returning either $\\isa{True}$ or $\\isa{False}$.%\n\\footnote{Note that in the distributed systems literature it is conventional to write the happens-before relation as $\\isa{x} \\rightarrow \\isa{y}$, but we reserve the arrow operator to denote logical implication.}\nOur only restriction on the happens-before relation $\\prec$ is that it must be a \\emph{strict partial order}, that is, it must be irreflexive and transitive, which implies that it is also antisymmetric.\nWe say that two operations $\\isa{x}$ and $\\isa{y}$ are \\emph{concurrent}, written $\\isa{x} \\mathbin{\\isasymparallel} \\isa{y}$, whenever one does not happen before the other:\n$\\neg (\\isa{x} \\prec \\isa{y})$ and $\\neg (\\isa{y} \\prec \\isa{x})$.\nThus, given any two operations $\\isa{x}$ and $\\isa{y}$, there are three mutually exclusive ways in which they can be related: either $\\isa{x} \\prec \\isa{y}$, or $\\isa{y} \\prec \\isa{x}$, or $\\isa{x} \\mathbin{\\isasymparallel} \\isa{y}$.\n\nAs discussed above, the purpose of the happens-before relation is to require that some operations must be applied in a particular order, while allowing concurrent operations to be reordered with respect to each other.\nWe assume that each node applies operations in some sequential order (a standard assumption for distributed algorithms), and so we can model the execution history of a node as a list of operations.\nWe can then inductively define a list of operations as being \\emph{consistent with the happens-before relation}, or simply \\emph{hb-consistent}, as follows:\n\\begin{isabelle}\n\\isacommand{inductive} hb{\\isacharunderscore}consistent\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ list\\ {\\isasymRightarrow}\\ bool{\\isachardoublequoteclose}\\ \\isakeyword{where}\\\\\n~~~~{\\isachardoublequoteopen}hb{\\isacharunderscore}consistent\\ {\\isacharbrackleft}{\\isacharbrackright}{\\isachardoublequoteclose}\\ {\\isacharbar}\\\\\n~~~~{\\isachardoublequoteopen}{\\isasymlbrakk}\\ hb{\\isacharunderscore}consistent\\ xs{\\isacharsemicolon}\\ {\\isasymforall}x\\ {\\isasymin}\\ set\\ xs{\\isachardot}\\ {\\isasymnot}\\ y\\ {\\isasymprec}\\ x\\ {\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ hb{\\isacharunderscore}consistent\\ {\\isacharparenleft}xs\\ {\\isacharat}\\ {\\isacharbrackleft}y{\\isacharbrackright}{\\isacharparenright}{\\isachardoublequoteclose}\n\\end{isabelle}\nIn words: the empty list is hb-consistent; furthermore, given an hb-consistent list $\\isa{xs}$, we can append an operation $\\isa{y}$ to the end of the list to obtain another hb-consistent list, provided that $\\isa{y}$ does not happen-before any existing operation $\\isa{x}$ in $\\isa{xs}$. As a result, whenever two operations $\\isa{x}$ and $\\isa{y}$ appear in a hb-consistent list, and $\\isa{x}\\prec\\isa{y}$, then $\\isa{x}$ must appear before $\\isa{y}$ in the list. However, if $\\isa{x}\\mathbin{\\isasymparallel}\\isa{y}$, the operations can appear in the list in either order.\n\n\\subsection{Interpretation of Operations}\\label{sect.ops.interpretation}\n\nWe describe the state of a node using an abstract type variable $\\isacharprime\\isa{state}$.\nTo model state changes, we assume the existence of an \\emph{interpretation} function of type $\\isa{interp} \\mathbin{\\isacharcolon\\isacharcolon} \\isacharprime\\isa{oper} \\mathbin{\\isasymRightarrow} \\isacharprime\\isa{state} \\mathbin{\\isasymRightarrow} \\isacharprime\\isa{state}\\ \\isa{option}$, which lifts an operation into a \\emph{state transformer}---a function that either maps an old state to a new state, or fails by returning $\\isa{None}$.\nIf $\\isa{x}$ is an operation, we also write $\\langle\\isa{x}\\rangle$ for the state transformer obtained by applying $\\isa{x}$ to the interpretation function.\n\nConcretely, these definitions are captured in Isabelle with the following locale declaration:\n\\begin{isabelle}\n~~~~\\isakeyword{fixes}\\ \\=hb{\\isacharunderscore}weak\\ \\=\\kill\n\\isacommand{locale} happens{\\isacharunderscore}before\\ {\\isacharequal}\\ preorder\\ hb{\\isacharunderscore}weak\\ hb\\\\\n~~~~\\isakeyword{for}\\>hb{\\isacharunderscore}weak\\>{\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ {\\isasymRightarrow}\\ {\\isacharprime}oper\\ {\\isasymRightarrow}\\ bool{\\isachardoublequoteclose}\\\\\n~~~~\\isakeyword{and}\\>hb\\>{\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ {\\isasymRightarrow}\\ {\\isacharprime}oper\\ {\\isasymRightarrow}\\ bool{\\isachardoublequoteclose}\\ {\\isacharplus}\\\\\n~~~~\\isakeyword{fixes}\\>interp\\>{\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ {\\isasymRightarrow}\\ {\\isacharprime}state\\ {\\isasymRightarrow}\\ {\\isacharprime}state\\ option{\\isachardoublequoteclose}\n\\end{isabelle}\nThe $\\isa{happens-before}$ locale extends the $\\isa{preorder}$ locale, which is part of Isabelle's standard library and includes various useful lemmas.\nIt fixes two constants: a preorder that we call $\\isa{hb-weak}$ or $\\preceq$, and a strict partial order that we call $\\isa{hb}$ or $\\prec$.\nWe are only interested in the strict partial order and define $\\isa{x}\\preceq\\isa{y}$ to be $\\isa{x}\\prec\\isa{y} \\vee \\isa{x}=\\isa{y}$.\nMoreover, the locale fixes the interpretation function $\\isa{interp}$ as described above, which means that we assume the existence of a function with the given type signature without specifying an implementation.\n\nGiven two operations $\\isa{x}$ and $\\isa{y}$, we can now define the composition of state transformers: we write $\\langle\\isa{x}\\rangle \\mathbin{\\isasymrhd} \\langle\\isa{y}\\rangle$ to denote the state transformer that first applies the effect of $\\isa{x}$ to some state, and then applies the effect of $\\isa{y}$ to the result.\nIf either $\\langle\\isa{x}\\rangle$ or $\\langle\\isa{y}\\rangle$ fails, the combined state transformer also fails.\nThe operator $\\isasymrhd$ is a specialised form of the \\emph{Kleisli arrow composition}, which we define as:\n\\begin{isabelle}\n\\isacommand{definition} kleisli\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharparenleft}{\\isacharprime}a\\ {\\isasymRightarrow}\\ {\\isacharprime}a\\ option{\\isacharparenright}\\ {\\isasymRightarrow}\\ {\\isacharparenleft}{\\isacharprime}a\\ {\\isasymRightarrow}\\ {\\isacharprime}a\\ option{\\isacharparenright}\\ {\\isasymRightarrow}\\ {\\isacharparenleft}{\\isacharprime}a\\ {\\isasymRightarrow}\\ {\\isacharprime}a\\ option{\\isacharparenright}{\\isachardoublequoteclose}\\ \\isakeyword{where}\\\\\n~~~~{\\isachardoublequoteopen}f\\ {\\isasymrhd}\\ g\\ {\\isasymequiv}\\ {\\isasymlambda}x{\\isachardot}\\ f\\ x\\ {\\isasymbind}\\ {\\isacharparenleft}{\\isasymlambda}y{\\isachardot}\\ g\\ y{\\isacharparenright}{\\isachardoublequoteclose}\n\\end{isabelle}\n\\noindent Here, $\\isasymbind$ is the \\emph{monadic bind} operation, defined on the option type that we are using to implement partial functions.\nWe can now define a function $\\isa{apply-operations}$ that composes an arbitrary list of operations into a state transformer.\nWe first map $\\isa{interp}$ across the list to obtain a state transformer for each operation, and then collectively compose them using the Kleisli arrow composition combinator:\n\\begin{isabelle}\n\\isacommand{definition} apply{\\isacharunderscore}operations\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ list\\ {\\isasymRightarrow}\\ {\\isacharprime}state\\ {\\isasymRightarrow}\\ {\\isacharprime}state\\ option{\\isachardoublequoteclose}\\ \\isakeyword{where}\\\\\n~~~~{\\isachardoublequoteopen}apply{\\isacharunderscore}operations\\ ops\\ {\\isasymequiv}\\ foldl\\ {\\isacharparenleft}op\\ {\\isasymrhd}{\\isacharparenright}\\ Some\\ {\\isacharparenleft}map\\ interp\\ ops{\\isacharparenright}{\\isachardoublequoteclose}\n\\end{isabelle}\n\\noindent The result is a state transformer that applies the interpretation of each of the operations in the list, in left-to-right order, to some initial state.\nIf any of the operations fails, the entire composition returns $\\isa{None}$.\n\n\\subsection{Commutativity and Convergence}\\label{sect.ops.commute}\n\nWe say that two operations $\\isa{x}$ and $\\isa{y}$ \\emph{commute} whenever $\\langle\\isa{x}\\rangle \\mathbin{\\isasymrhd} \\langle\\isa{y}\\rangle = \\langle\\isa{y}\\rangle \\mathbin{\\isasymrhd} \\langle\\isa{x}\\rangle$, i.e. when we can swap the order of the composition of their interpretations without changing the resulting state transformer.\nFor our purposes, requiring that this property holds for \\emph{all} pairs of operations is too strong.\nRather, the commutation property is only required to hold for operations that are concurrent, as captured in the next definition:\n\\begin{isabelle}\n\\isacommand{definition} concurrent{\\isacharunderscore}ops{\\isacharunderscore}commute\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ list\\ {\\isasymRightarrow}\\ bool{\\isachardoublequoteclose}\\ \\isakeyword{where}\\\\\n~~~~{\\isachardoublequoteopen}concurrent{\\isacharunderscore}ops{\\isacharunderscore}commute\\ xs\\ {\\isasymequiv} {\\isasymforall}x\\ y{\\isachardot}\\ {\\isacharbraceleft}x{\\isacharcomma}\\ y{\\isacharbraceright}\\ {\\isasymsubseteq}\\ set\\ xs\\ {\\isasymlongrightarrow}\\ x\\ {\\isasymparallel}\\ y\\ {\\isasymlongrightarrow}\\ {\\isasymlangle}x{\\isasymrangle}{\\isasymrhd}{\\isasymlangle}y{\\isasymrangle}\\ {\\isacharequal}\\ {\\isasymlangle}y{\\isasymrangle}{\\isasymrhd}{\\isasymlangle}x{\\isasymrangle}{\\isachardoublequoteclose}\n\\end{isabelle}\nGiven this definition, we can now state and prove our main theorem, $\\isa{convergence}$.\nThis theorem states that two hb-consistent lists of distinct operations, which are permutations of each other and in which concurrent operations commute, have the same interpretation:\n\\begin{isabelle}\n\\isacommand{theorem} convergence{\\isacharcolon}\\\\\n~~~~\\isakeyword{assumes}\\ {\\isachardoublequoteopen}set\\ xs\\ {\\isacharequal}\\ set\\ ys{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}concurrent{\\isacharunderscore}ops{\\isacharunderscore}commute\\ xs{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}concurrent{\\isacharunderscore}ops{\\isacharunderscore}commute\\ ys{\\isachardoublequoteclose}\\\\\n~~~~~~~~\\isakeyword{and}\\ {\\isachardoublequoteopen}distinct\\ xs{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}distinct\\ ys{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}hb{\\isacharunderscore}consistent\\ xs{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}hb{\\isacharunderscore}consistent\\ ys{\\isachardoublequoteclose}\\\\\n~~~~\\isakeyword{shows}\\ {\\isachardoublequoteopen}apply{\\isacharunderscore}operations\\ xs\\ {\\isacharequal}\\ apply{\\isacharunderscore}operations\\ ys{\\isachardoublequoteclose}\n\\end{isabelle}\n\\noindent\nA fully mechanised proof of this theorem can be found in our submission to the Archive of Formal Proofs \\cite{CRDT-AFP}.\nAlthough this theorem may seem ``obvious'' at first glance---commutativity allows the operation order to be permuted---it is more subtle than it seems.\nThe difficulty arises because operations may succeed when applied to some state, but fail when applied to another state (for example, attempting to delete an element that does not exist in the state).\nWe find it interesting that it is nevertheless sufficient for the definition of $\\isa{concurrent-ops-commute}$ to be expressed only in terms of the Kleisli arrow composition, and without explicitly referring to the state.\n\n\\subsection{Formalising Strong Eventual Consistency}\\label{sect.abstract.sec.spec}\n\nBesides convergence, another required property of SEC is \\emph{progress}: if one node issues a valid operation, and another node applies that operation, then it must not become stuck in an error state.\nAlthough the type signature of the interpretation function allows operations to fail, we need to prove that such a failure never occurs in any $\\isa{hb-consistent}$ network behaviour.\nWe capture this requirement in the $\\isa{strong-eventual-consistency}$ locale:\n\\begin{isabelle}\n~~~~\\isakeyword{assumes}\\ \\=commutativity{\\isacharcolon}\\ \\={\\isasymlbrakk}\\ \\=op{\\isacharunderscore}history{\\isacharparenleft}xs{\\isacharat}{\\isacharbrackleft}x{\\isacharbrackright}{\\isacharparenright}\\ \\={\\isasymrbrakk}\\ \\=\\kill\n\\isacommand{locale}\\ strong{\\isacharunderscore}eventual{\\isacharunderscore}consistency\\ {\\isacharequal}\\ happens{\\isacharunderscore}before\\ {\\isacharplus}\\\\\n~~~~\\isakeyword{fixes}\\ op{\\isacharunderscore}history\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}oper\\ list\\ {\\isasymRightarrow}\\ bool{\\isachardoublequoteclose}\\ \\ \\isakeyword{and}\\ initial{\\isacharunderscore}state\\ {\\isacharcolon}{\\isacharcolon}\\ {\\isachardoublequoteopen}{\\isacharprime}state{\\isachardoublequoteclose}\\\\\n~~~~\\isakeyword{assumes}\\>causality{\\isacharcolon}\\ \\>{\\isasymlbrakk}\\>{\\isachardoublequoteopen}op{\\isacharunderscore}history\\ xs\\ \\>{\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ hb{\\isacharunderscore}consistent\\ xs{\\isachardoublequoteclose}\\\\\n~~~~~~~~\\isakeyword{and}\\>distinctness{\\isacharcolon}\\ \\>{\\isasymlbrakk}\\>{\\isachardoublequoteopen}op{\\isacharunderscore}history\\ xs\\ \\>{\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ distinct\\ xs{\\isachardoublequoteclose}\\\\\n~~~~~~~~\\isakeyword{and}\\>trunc{\\isacharunderscore}history{\\isacharcolon}\\ \\>{\\isasymlbrakk}\\>{\\isachardoublequoteopen}op{\\isacharunderscore}history{\\isacharparenleft}xs{\\isacharat}{\\isacharbrackleft}x{\\isacharbrackright}{\\isacharparenright}\\ \\>{\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ op{\\isacharunderscore}history\\ xs{\\isachardoublequoteclose}\\\\\n~~~~~~~~\\isakeyword{and}\\>commutativity{\\isacharcolon}\\ \\>{\\isasymlbrakk}\\>{\\isachardoublequoteopen}op{\\isacharunderscore}history\\ xs\\ \\>{\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ concurrent{\\isacharunderscore}ops{\\isacharunderscore}commute\\ xs{\\isachardoublequoteclose}\\\\\n~~~~~~~~\\isakeyword{and}\\>no{\\isacharunderscore}failure{\\isacharcolon}\\ \\>{\\isasymlbrakk}\\>{\\isachardoublequoteopen}op{\\isacharunderscore}history{\\isacharparenleft}xs{\\isacharat}{\\isacharbrackleft}x{\\isacharbrackright}{\\isacharparenright};\\\\\n\\>\\>\\>apply{\\isacharunderscore}operations\\ xs\\ initial{\\isacharunderscore}state\\ {\\isacharequal}\\ Some\\ state\\\\\n\\>\\>\\>\\>{\\isasymrbrakk}\\>{\\isasymLongrightarrow}\\ {\\isasymlangle}x{\\isasymrangle}\\ state\\ {\\isasymnoteq}\\ None{\\isachardoublequoteclose}\n\\end{isabelle}\n\\noindent Here, $\\isa{op-history}$ is an abstract predicate describing any valid operation history of some replication algorithm, encapsulating the assumptions of the $\\isa{convergence}$ theorem ($\\isa{concurrent-ops-commute}$, $\\isa{distinct}$, and $\\isa{hb-consistent}$).\nThis locale serves as a concise summary of the properties that we require in order to achieve SEC, and from these assumptions and the theorem above we easily obtain the two safety properties of SEC as theorems:\n\\begin{isabelle}\n~~~~\\isakeyword{assumes}\\ \\=\\kill\n\\isacommand{theorem}\\ sec{\\isacharunderscore}convergence{\\isacharcolon}\\\\\n~~~~\\isakeyword{assumes}\\ \\>{\\isachardoublequoteopen}set\\ xs\\ {\\isacharequal}\\ set\\ ys{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}op{\\isacharunderscore}history\\ xs{\\isachardoublequoteclose}\\ \\isakeyword{and}\\ {\\isachardoublequoteopen}op{\\isacharunderscore}history\\ ys{\\isachardoublequoteclose}\\\\\n~~~~\\isakeyword{shows}\\ \\>{\\isachardoublequoteopen}apply{\\isacharunderscore}operations\\ xs\\ {\\isacharequal}\\ apply{\\isacharunderscore}operations\\ ys{\\isachardoublequoteclose}\\\\[4pt]\n\\isacommand{theorem}\\ sec{\\isacharunderscore}progress{\\isacharcolon}\\\\\n~~~~\\isakeyword{assumes} \\>{\\isachardoublequoteopen}op{\\isacharunderscore}history\\ xs{\\isachardoublequoteclose}\\\\\n~~~~\\isakeyword{shows} \\>{\\isachardoublequoteopen}apply{\\isacharunderscore}operations\\ xs\\ initial{\\isacharunderscore}state\\ {\\isasymnoteq}\\ None{\\isachardoublequoteclose}\n\\end{isabelle}\n\nThus, in order to prove SEC for some replication algorithm, we only need to show that the five assumptions of the $\\isa{strong-eventual-consistency}$ locale are satisfied.\nAs we shall see in Section~\\ref{sect.network}, the first three assumptions are satisfied by our network model, and do not require any algorithm-specific proofs.\nFor individual algorithms we only need to prove the $\\isa{commutativity}$ and $\\isa{no-failure}$ properties, and we show how to do this in Sections~\\ref{sect.rga} and~\\ref{sect.simple.crdts}.\n\nNote that the $\\isa{trunc-history}$ assumption requires that every prefix of a valid operation history is also valid.\nThis means that the convergence theorem holds at every step of the execution, not only at some unspecified time in the future (``eventually''), making SEC stronger than eventual consistency.\n", "meta": {"hexsha": "9c295bc5c787c58e4d5ce1d4dda30c7f7028773a", "size": 19077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/convergence.tex", "max_stars_repo_name": "trvedata/crdt-isabelle", "max_stars_repo_head_hexsha": "8fde89bfb5e88acce000ac26e45f3f1cfe334e6e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2017-07-09T22:49:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-28T07:18:10.000Z", "max_issues_repo_path": "paper/convergence.tex", "max_issues_repo_name": "trvedata/crdt-isabelle", "max_issues_repo_head_hexsha": "8fde89bfb5e88acce000ac26e45f3f1cfe334e6e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T14:33:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-17T09:22:42.000Z", "max_forks_repo_path": "paper/convergence.tex", "max_forks_repo_name": "trvedata/crdt-isabelle", "max_forks_repo_head_hexsha": "8fde89bfb5e88acce000ac26e45f3f1cfe334e6e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-03-03T00:36:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T02:18:48.000Z", "avg_line_length": 140.2720588235, "max_line_length": 575, "alphanum_fraction": 0.781150076, "num_tokens": 5309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6305328500769141}}
{"text": "\\chapter{Quantum Key Distribution}\n\\label{chap:bb84}\n\n% Talk about quantum key distribution\nQuantum computers have been shown to solve the underlying mathematical problems, such as the DLP and prime factorization that keep our encryption secure.\nAlthough symmetric encryption is much less effected by this, it is not commonly used due to the key distribution problem \\cite{cryptography}.\nOne potential solution is Quantum Key Distribution (QKD), which applies quantum mechanics and quantum computing properties to a key distribution protocol that is provably secure \\cite{MikeAndIke}.\nIt allows for two parties to securely generate a symmetric key.\nIn this chapter, we look at the BB84 quantum key exchange protocol to exchange encryption keys between two parties, Alice and Bob.\nThe encryption key is exchanged through a quantum channel in the form of qubits.\nAn eavesdropper listening in on this communication cannot obtain any information without disturbing the qubits and measuring them, which introduces noise to the signal since the basis used to encode information is unknown. \nWe show that such an eavesdropper can be detected by Alice and Bob due to a spike in the error rate of transmitted qubits.\n\n% Introduce protocol\n\\section{The BB84 Protocol}\n\n\\begin{figure}[htp]\n\t\\centering\n\t\\fbox{\\begin{minipage}{41em}\n\t\\begin{center}\n\t\t\\textbf{BB84}\n\t\\end{center}\n\t\\begin{enumerate}\n\t\\item  Alice and Bob connect via a quantum communication channel.\n    \\item  Alice generates $N$ random bits, where $N \\geq 4l$, $l$ = desired key length.\n    \\item  Alice encodes the bits into qubits, randomly choosing to encode using one of two orthonormal bases -- the standard and the Hadamard basis.\n    \\item  Alice sends the qubits to Bob.\n    \\item  Bob measures each qubit, choosing to use one of the two selected bases at random.\n    \\item  Bob sends a bitvector of his chosen bases to Alice over a classical channel.\n    \\item  Alice responds with a bitvector showing which of Bob's bases were correct.\n    \\item  Alice and Bob discard all qubits that were measured in the wrong basis.\n    \\item  Bob sends Alice some number of the measured values to ensure the key was received without any interference.\n    \\item Alice responds with whether or not the exchanged values were correct.\n    \\item If there were no errors in the compared bits, the bits that were exchanged are discarded by both parties, and the rest of the bits are used as the key.\n    \\end{enumerate}\n\t\\end{minipage}}\n\\caption{AThe BB84 Quantum Key Distribution Protocol.}\n\t\\label{fig:BB84}\n\\end{figure}\n\nIn 1984 Charles Bennett and Gilles Brassard proposed the first quantum key distribution protocol, the BB84 \\cite{qc:agi}.\nThe protocol allows two parties communicating over a public classical channel, such as the internet, and a public quantum channel to securely generate a shared encryption key for symmetric encryption.\n\nTo start the quantum key exchange, Alice randomly generates two bit sequences, $a$ and $b$, of length at least $N = 4l$ bits each, where $l$ is the intended key length.\nWhile $N$ does not necessarily need to be $4l$, it allows for $l$ bits to be used to verify the keys integrity, since half of the bits are discarded during the key exchange, on average \\cite{MikeAndIke}.\nAlice then encodes $a$ into a block of $N$ qubits, $\\ket{\\psi}$.\nThis is done using two bases; in our case, the standard basis and Hadamard basis.\nThe basis chosen for encoding each bit in $a$ is determined by the corresponding bit in $b$, with $b_i = \\{0 \\textrm{ or } 1\\}$ where $0$ refers to the standard basis and $1$  refers to the Hadamard basis.\nThus, each qubit is in either the standard basis or the Hadamard basis, and is in one of four states shown in Figure ~\\ref{fig:possible_states}.\n\\begin{figure}[htp]\n\\centering\n\\begin{tabular}{|c|c|c|}\n\\hline\n$a_i$ & $b_i$ & $\\ket{\\psi_i}$ \\\\ \\hline\n0 & 0 & $\\ket{0}$ \\\\ \\hline\n1 & 0 & $\\ket{1}$ \\\\ \\hline\n0 & 1 & $\\ket{+}$ \\\\ \\hline\n1 & 1 & $\\ket{-}$ \\\\ \\hline\n\\end{tabular}\n\\caption{The four possible states of a qubit in a BB84 encoded string.}\n\\label{fig:possible_states}\n\\end{figure}\nNext, Alice sends each qubit to Bob using a public quantum channel.\nWhen Bob has received each qubit he can assemble the full qubit block $\\ket{\\psi}^\\prime$.\nAssuming a perfect quantum channel and no eavesdropping, there should not be any disturbance or noise in the communication; therefore $\\ket{\\psi}^\\prime = \\ket{\\psi}$.\nOnce Bob has received all qubits, he measures each qubit in $\\ket{\\psi}^\\prime$ into a bit sequence $a^\\prime$ by randomly choosing a basis of measurement for each bit.\nThe bases chosen are stored in a bit sequence $b^\\prime$.\nBob then informs Alice that he has measured all the received qubits.\nBecause there is a 50\\% chance that Bob will choose an incorrect basis for measurement for each qubit, and a 50\\% probability of measuring the correct value using the wrong basis, Bob has measured 75\\% of the qubits correctly, on average (see Figure ~\\ref{fig:possible_measurements_no_eve}).\n\\begin{figure}[htp]\n\t\\centering\n\t\\begin{tabular}{|r|c|c|c|c|c|c|c|c|}\n\t\t\\hline\n\t\tEncoded value  & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\\\ \\hline\n\t\tEncoded basis  & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\\\ \\hline\n\t\tMeasured basis  & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\\\ \\hline\n\t\tMeasured value & 0 & $\\nicefrac{0}{1}$& $\\nicefrac{0}{1}$ & 0 & 1 & $\\nicefrac{0}{1}$ & $\\nicefrac{0}{1}$ & 1\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Exhaustive list of encoding and measurement of a single qubit between Alice and Bob.}\n\t\\label{fig:possible_measurements_no_eve}\n\\end{figure}\nWhile 75\\% of the bits are measured correct on average, an average of 50\\% are measured in the correct basis; those qubits are  guaranteed to be measured correctly.\nNote that Alice has ($a$, $b$) and Bob has($a^\\prime$ $b^\\prime$), but they each do not know the others $a$ and $a^\\prime$.\nAlice and Bob now exchange the bases they each used, $b$ and $b^\\prime$, respectively.\nAlice and Bob both discard every bit that was encoded and measured using different bases: bit $i$ is discarded from $a$ and $a^\\prime$ if $b_i \\neq b^\\prime_i$.\nThey store the remaining bits from $a$ and $a^\\prime$ into a new bit sequence, $k$ and $k^\\prime$, respectively.\nAlice and Bob now each have the same key, $k = k^\\prime$.\nThey each exchange some number of bits from $k$ to verify there was no error in their key generation.\nIf the exchanged bits are identical, then Alice and Bob can confirm with high probability that there was no eavesdropper, and that their key is secure \\cite{MikeAndIke}.\nThey can now use the key for symmetrically encrypted communication, or even as a OTP on a classical channel.\n\n% Discuss eavesdropping\nIf an eavesdropper, Eve, were to attempt to listen in on the conversation, she would not be able to gain any useful information from the qubits, since she does not know the basis in which the qubits are encoded, nor could she duplicate the qubits. \nTherefore the only strategy she has is to perform a ``man-in-the-middle\" attack, in which Eve impersonates Bob to Alice and Alice to Bob \\cite{qc:agi}.\n\nTo eavesdrop on the communication, Eve listens on the quantum channel and waits for Alice to transmit qubits.\nAs Alice sends Bob the qubits over the quantum channel Eve intercepts each qubit, forming her own qubit block $\\ket{\\psi}^\\prime$.\nWith the qubits now in Eve's possession, she attempt to measure the qubits or clone them on either of the two bases randomly.\nShe then re-encodes them using the same bases, into $\\ket{\\psi}^{\\prime\\prime}$, and forwards the qubits to Bob.\nHowever, as previously shown, this would introduce noise to the signal, reducing Bob's correct average measurement.\nSince the average percentage of correctness is $\\frac{2 * 100\\% + 6 * 50\\%}{8} = 62.5\\%$, the average percentage that a bit is measured correctly drops from 75\\% to 62.5\\%, leaving only 25\\% of the qubits measured in the same basis used during encoding.\n\\begin{figure}[htp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t% Table headers\n\t\t\\hline\n\t\t$\\textrm{Basis}_{Alice}$ & $\\textrm{Basis}_{Eve}$ &$\\textrm{Basis}_{Bob}$ & Percent Correct & Bit Kept in Key\\\\ \\hline\n\t%\tAb  Eb  Bb  c       a       \n    \t0 & 0 & 0 & 100\\% & Kept \\\\ \\hline\t\t\n    \t0 & 0 & 1 &  50\\% & Discarded \\\\ \\hline\t\t\n    \t0 & 1 & 0 &  50\\% & Kept \\\\ \\hline\t\t\n    \t0 & 1 & 1 &  50\\% & Discarded \\\\ \\hline\t\t\n    \t1 & 0 & 0 &  50\\% & Discarded \\\\ \\hline\t\t\n    \t1 & 0 & 1 &  50\\% & Kept \\\\ \\hline\t\t\n    \t1 & 1 & 0 &  50\\% & Discarded \\\\ \\hline\t\t\n    \t1 & 1 & 1 & 100\\% & Kept \\\\ \\hline\t\t\n\t\\end{tabular}\n\t\\caption{Exhaustive list of encoding and measurement of a single qubit between Alice and Bob with an eavesdropper}\n\t\\label{fig:possible_measurements_eve}\n\\end{figure}\nAs can be seen in figure~\\ref{fig:possible_measurements_eve}, when there is an eavesdropper, half of the bits kept in the generated key are measured in an incorrect basis by at least one party.\nOnce the bits that Bob measured in a different basis than Alice are discarded, there is still only a $\\frac{2 * 100\\% + 2 * 50\\%}{4} = 75\\%$ chance of any qubit being measured by Bob as the same value encoded by Alice.\nThis means, on average, 25\\% of the bits in $k^\\prime$ are incorrect.\nWhen Alice and Bob exchange some bits to verify their correctness, even if only four bits are compared they both will, on average, detect that the qubits were maliciously measured during transmission, at which point Alice and Bob can abort communication \\cite{MikeAndIke}. \n\nIn practice this protocol can be implemented using polarized photons as qubits, which can be sent between Alice and Bob using fiber optics.\nThe data is encoded into the photons using the angle of the polarization since photons can act as a qubit \\cite{qc:agi}.\nIn this case the bases for encoding data are the standard basis, $(\\ket{0}, \\ket{1}) = (\\ket{\\rightarrow}, \\ket{\\uparrow})$, and the Hadamard basis, $(\\ket{+}, \\ket{-}) = (\\ket{\\nearrow}, \\ket{\\nwarrow})$.\nHowever all that is required to perform any QKD protocol is the ability to communicate qubits over a public channel with a very low error rate \\cite{MikeAndIke}.\n", "meta": {"hexsha": "b29f66621ab552bf6ff60dab70809da603db8bcf", "size": 10102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04_bb84.tex", "max_stars_repo_name": "aThorp96/undergraduate_thesis", "max_stars_repo_head_hexsha": "165962b69bf74babe1273e136e33c497b3a449f0", "max_stars_repo_licenses": ["MIT"], "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_bb84.tex", "max_issues_repo_name": "aThorp96/undergraduate_thesis", "max_issues_repo_head_hexsha": "165962b69bf74babe1273e136e33c497b3a449f0", "max_issues_repo_licenses": ["MIT"], "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_bb84.tex", "max_forks_repo_name": "aThorp96/undergraduate_thesis", "max_forks_repo_head_hexsha": "165962b69bf74babe1273e136e33c497b3a449f0", "max_forks_repo_licenses": ["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.1145038168, "max_line_length": 291, "alphanum_fraction": 0.7342110473, "num_tokens": 2801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6305328487936879}}
{"text": "\\section{PageRank Algorithm}\n\nHere we use the Wikipedia Vote Network dataset \\cite{wikipedia} as our processing source. The requested PageRank algorithm is similar to the \\emph{Connected Component} one, and after checking the spark source code, we're sure that the \\texttt{GraphLoader} can also be used to process the wiki votes.\n\nPageRank algorithm is named after both the term \"web page\" and Google co-founder Larry Page. The key to the ranking is a probabilistic balance between nodes. At the beginning of the computational process the pagerank for each node is randomized, and for each iteration, the rank is computed as:\n\n\\begin{equation}\nPR(p_i) =\\frac{1-d}{N} + d\\sum_{p_j\\in M(p_i)}\\frac{PR(p_j)}{L(p_j)}\n\\end{equation}\n\nAn approximation of real page rank value can be calculated with several iterations.\n\nAfter researching on GraphX Programming Guide \\cite{pagerank}, the graph build with GraphLoader has implemented PageRank algorithm. In our implementation, it is called by\n\n\\begin{verbatim}\nval ranksGraph = graph.pageRank(0.0001)\n\\end{verbatim}\n\nThe original source file does not contain name information, but we want to form a more intuitive result as \\emph{Connected Component}, which adds an additional user--node linkage. We used \\texttt{sed} scripts to pre-process the original vote data from \\cite{wiki-elec}, and generate the user--node list as in \\texttt{users.txt}.\n\n{\\small\n\\begin{verbatim}\nsed '/^[\\s]*#/d; \n/^\\s*$/d;\n/^[ET].*/d; \n/^N\\t-1\\tUNKNOWN.*/d;\ns/^[UN]\\t\\(.*\\)\\t\\(.*\\)$/\\1,\\2/g;\ns/^V\\t.*\\t\\(.*\\)\\t.*\\t\\(.*\\)$/\\1,\\2/g' \\\noriginal.txt | sort -g | uniq > users.txt\n\\end{verbatim}\n}\n\nThe user--node list generated would be like:\n\n{\\small\n\\begin{verbatim}\n3,ludraman\n4,gzornenplatz\n5,orthogonal\n6,andrevan\n7,texture\n8,lst27\n9,mirv\n...\n\\end{verbatim}\n}\n\nAfter compiling and submitting like we've done in the \\emph{Connected Component} part, the results are shown below and as figure \\ref{fig:PR-result}:\n\n{\\small\n\\begin{verbatim}\nPR: 32.78, ID:4037, Name:elonka\nPR: 26.18, ID:  15, Name:danny\nPR: 25.52, ID:6634, Name:tenpoundhammer\nPR: 23.36, ID:2625, Name:_clown_will_eat_me\nPR: 18.56, ID:2398, Name:werdna\nPR: 17.96, ID:2470, Name:alex_bakharev\nPR: 17.76, ID:2237, Name:khoikhoi\nPR: 16.14, ID:4191, Name:ryulong\nPR: 15.44, ID:7553, Name:dihydrogen_monoxide\nPR: 15.30, ID:5254, Name:gracenotes\nPR: 14.51, ID:2328, Name:phaedriel\nPR: 14.48, ID:1186, Name:william_m._connolley\nPR: 13.84, ID:1297, Name:robchurch\nPR: 13.78, ID:4335, Name:mer-c\nPR: 13.75, ID:7620, Name:cobi\nPR: 13.65, ID:5412, Name:protectionbot\nPR: 13.57, ID:7632, Name:redirectcleanupbot\nPR: 13.33, ID:4875, Name:earle_martin\nPR: 12.87, ID:6946, Name:useight\nPR: 12.69, ID:3352, Name:crzrussian\n\\end{verbatim}\n}\n\nAlthough we do not know how Wikipedia administrators are selected, after checking their usernames, those we checked were all engaged in Wikipedia administration during 2008. This shows that distributed computing is not just an airy idea in papers or academics, but can also work well in solving practical problems.\n\nAll necessary files and source code are put in the \\texttt{PageRank} folder.", "meta": {"hexsha": "2db1fea3cd67b6002a1b99617a21a59940bf3977", "size": 3099, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/pagerank.tex", "max_stars_repo_name": "Victrid/CS236-Cloud-Experiment", "max_stars_repo_head_hexsha": "2b6ebc487f9f20ed2ea4b8e15f91304d782a87b7", "max_stars_repo_licenses": ["MIT"], "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/pagerank.tex", "max_issues_repo_name": "Victrid/CS236-Cloud-Experiment", "max_issues_repo_head_hexsha": "2b6ebc487f9f20ed2ea4b8e15f91304d782a87b7", "max_issues_repo_licenses": ["MIT"], "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/pagerank.tex", "max_forks_repo_name": "Victrid/CS236-Cloud-Experiment", "max_forks_repo_head_hexsha": "2b6ebc487f9f20ed2ea4b8e15f91304d782a87b7", "max_forks_repo_licenses": ["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.2467532468, "max_line_length": 328, "alphanum_fraction": 0.7454017425, "num_tokens": 994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6305328475104616}}
{"text": "% \\chapauthor{J. P. Balthasar Mueller}\n\\chapter{Combinatorics}\n\n\\begin{multicols}{2}[\\subsubsection*{Contents of this chapter}]\n   \\printcontents{}{1}{\\setcounter{tocdepth}{2}}\n\\end{multicols}\n\n\n\n\\section{Combinatorial Identities and Expansions}\n\n% binomial coefficients\n\\subsection{Binomial Coefficients and Binomial Expansions}\n\nFor two positive integers $n$ and $k$, the binomial coefficient \"$n$ choose $k$\" is:\n\n\\begin{equation}\n{n \\choose k} = \\left\\{ \\begin{array}{c} \n\\frac{n!}{k!(n-k)!}\\ \\ \\mathrm{for\\ }n\\geq k\\\\\n\\\\\n0 \\ \\ \\mathrm{otherwise}\n\\end{array}\\right.\n\\end{equation}\n\nThe term can be defined for negative arguments, which is comes up often when working with generating functions.\n\n\\begin{equation}\n{-n \\choose k} = \\left\\{\\begin{array}{c}\n(-1)^k { n+k-1 \\choose k}\\ \\ \\mathrm{for\\ }n\\geq k\\\\\n\\\\\n0 \\ \\ \\mathrm{otherwise}\n\\end{array}\\right.\n\\end{equation}\n\n\n\\begin{equation}\n{-n \\choose -k} = \\left\\{\\begin{array}{c}\n(-1)^{k-n} {k-1 \\choose k-n}\\ \\ \\mathrm{for\\ }n\\geq k\\\\\n\\\\\n0 \\ \\ \\mathrm{otherwise}\n\\end{array}\\right.\n\\end{equation}\n\nThe generalizations can, for example, be derived using symmetry arguments and the Gamma function, which is the generalization of the factorial to non-integers (cf.  \\citeasnoun{kronenburg2011binomial}).\n\n\n% Binomial Expansion\nThe binomial expansion can be proven either by expanding the polynomial or by creating the Taylor series for the polynomial.\n\n\\begin{equation}\n(x + y)^n = \\sum_{k=0}^n {n \\choose k} x^k y^{n-k}\n\\end{equation}\n\nThis holds also for negative integer exponents $n$, in which case:\n\n\\begin{equation}\n\\frac{1}{(y+x)^n} = \\sum_{k=0}^\\infty {-n \\choose k} x^k y^{-n-k} = (-1)^k { n+k-1 \\choose k} x^k y^{-(n+k)}\n\\end{equation}\n\n\\subsubsection{Derivation of the Binomial Theorem for a Negative Exponent}\n\nLet $f(x) = \\frac{1}{(y+x)^n} = (y+x)^{-n}$. The Taylor expansion about the point $x=0$ is:\n\n\\begin{equation}\nf(x) = \\sum_{k=0}^\\infty \\frac{f^{(k)}(x=0)}{k!} x^k\n\\label{eq:taylor}\n\\end{equation}\n\nThe derivatives of $f$ are:\n\n\\begin{equation}\n\\begin{array}{ll}\nf^{(0)}(x) &= (y+x)^{-n}\\\\\nf^{(1)}(x) &= (y+x)^{-(n+1)}(-1)n\\\\\nf^{(2)}(x) &= (y+x)^{-(n+2)}(-1)^2 n(n+1)\\\\\n&\\vdots\\\\\nf^{(k)}(x) &= (y+x)^{-(n+k)}(-1)^k n(n+1)\\hdots\t(n+k-1)\\\\\n&=  (y+x)^{-(n+k)}(-1)^k \\frac{(n+k-1)!}{(n-1)!}\n\\end{array}\n\\label{eq:derivatives}\n\\end{equation} \n\nCombining Eqns. \\ref{eq:taylor} and \\ref{eq:derivatives} gives:\n\n\\begin{equation}\nf(x) = \\sum_{k=0}^\\infty (-1)^k {n+k-1 \\choose k} x^k y^{-(n+k)}\n\\end{equation}\n\n\n\\subsubsection{Derivation of the Binomial Theorem for a Fractional Exponent}\n\nFollowing much the same logic as for a negative exponent, for a fractional exponent the Taylor series is also infinite. \n\nLet $f(x) = (y+x)^{m}$ with $m\\notin \\mathbb{Z}$. \n\nThe derivatives of $f$ are:\n\n\\begin{equation}\n\\begin{array}{ll}\nf^{(0)}(x) &= (y+x)^{m}\\\\\nf^{(1)}(x) &= (y+x)^{m-1}m\\\\\nf^{(2)}(x) &= (y+x)^{m-2}m(m-1)\\\\\n&\\vdots\\\\\nf^{(k)}(x) &= (y+x)^{n-k}m(m-1)\\hdots\t(m-k+1)\\\\\n\\end{array}\n\\label{eq:derivatives2}\n\\end{equation} \n\nCombining Eqns. \\ref{eq:taylor} and \\ref{eq:derivatives2} gives:\n\n\\begin{equation}\nf(x) = \\sum_{k=0}^\\infty { m \\choose k } x^k y^{m-k}\n\\end{equation}\n\nWhere, boldly, I defined ${ m \\choose k}$ to mean:\n\n\\begin{equation}\n{m \\choose k} = \\frac{m(m-1)(m-2)\\hdots(m-k+2)(m-k+1)}{k!}\n\\end{equation}\n\n\n% Multinomial Expansion\n\\subsection{Multinomial Expansion}\n\n\\begin{equation}\n(x_1 + x_2 + x_3 + \\hdots + x_k)^n = \\sum_{\\begin{array}{c} i_1,i_2,i_3,\\hdots,i_k \\\\ \\sum_j i_j = n\\end{array}} {n \\choose i_1,i_2,\\hdots i_k}x^{i_1}x^{i_2}x^{i_3}\\hdots x^{i_k}\n\\end{equation}\n\nwith:\n\n\\begin{equation}\n{n \\choose i_1,i_2,\\hdots i_k} = \\frac{n!}{i_1!i_2!,i_3!\\hdots i_k!}\n\\end{equation}\n\nWhere the sum over all possible exponents $i_j$ so that $\\sum_j i_j = n$ has ${n+k-1 \\choose n}$ terms. \n\n\\subsection{Unnamed Polynomial Identity}\nI don't know what this is called, but it's useful.\n\n\\begin{equation}\n\\prod_i^n (1-x_i) = \\sum_{s=0}^{n} (-1)^s \\sum_{0\\leq \\underbrace{i_1,i_2,...,i_s }_{\\{i\\}_s} \\leq n} \\prod_{i \\in \\{i\\}_s} x_i\n\\end{equation}\n\nWhere $\\{i\\}_s$ is a set of $s$ indices that range between $0$ and $n$, and the sum is over all possible such sets, of which there are ${n \\choose s}$.  \n\n\n% Factorial Expansion\n\\subsection{Factorial Expansion}\n\n\\begin{equation}\nx^{\\underline{n}} = \\frac{x!}{(x-n)!} = \\sum_{k=0}^n s(n,k)x^k\n\\end{equation}\n\nwhere\n\n\\begin{equation}\ns(n,k) = (-1)^{n-k}\\left[\\begin{array}{c} n\\\\k \\end{array}\\right]\n\\end{equation}\n\nare the stirling numbers of the first kind.\n\n\n\n% Stirling Numbers of the second kinds\n\\subsection{Stirling Numbers of the Second Kind}\n\\label{sec:stirling2}\n\nStirling numbers of the second kind $S(k,n)$ measure the amount of ways in which $k$ objects can be divided into $n$ non-empty groups. They give the number of onto functions from a set of $k$ distinct objects to $n$ indistinct recipients. For example: how many ways can a set of $k$ pool balls be put into $n$ bags, so that there is at least one ball in each bag. All the pool balls have numbers on them and have different colors, so that $n=2$ bags containing $[(1,2,3), (4)] $ and $[(1,2,4),(3)]$ count as different. This sort of problem is discussed at length in section \\ref{twentyfoldway}\n\nThey are given by an explicit formula:\n\n\\begin{equation}\nS(k,n) = \\frac{1}{n!}\\sum_{i=1}^n (-1)^{n-j} {n \\choose j}j^k\n\\end{equation}\n\nThey can also be generated via the recurrence relation:\n\n\\begin{equation}\n\\left\\{\\begin{array}{c}k+1\\\\n\\end{array}\\right\\} = n\\left\\{\\begin{array}{c}k\\\\n\\end{array}\\right\\} + \\left\\{\\begin{array}{c}k\\\\n-1\\end{array}\\right\\}\n\\end{equation}\n\nThe recurrence relation is explained by adding the combinations corresponding to two cases. If the $k+1$st object is added to one of the $n$ existing subsets with $k$ objects, then that corresponds to:\n\n\\begin{equation}\nn\\left\\{\\begin{array}{c}k\\\\n\\end{array}\\right\\} = 1\n\\end{equation}\n\nPossbilities. If the $k+1$st object is in a set by itself (a singleton), then the remaining objects are distributed over $n-1$ set. The combinations arising from this are:\n\n\\begin{equation}\n\\left\\{\\begin{array}{c}k\\\\n-1\\end{array}\\right\\} = 1\n\\end{equation}\n\nFurthermore, the following holds:\n\n\\begin{equation}\n\\left\\{\\begin{array}{c}0\\\\0\\end{array}\\right\\} = 1\n\\end{equation}\n\n\\begin{equation}\n\\left\\{\\begin{array}{c}k\\\\0\\end{array}\\right\\} = \\left\\{\\begin{array}{c}0\\\\n\\end{array}\\right\\} = 0\n\\end{equation}\n\nAnd $S(k,n) = 0$ if $n>k$.\n\n\n\\input{./chapters/sections/comb_twentyfoldway.tex}\n\\input{./chapters/sections/comb_generatingfuncs.tex}\n\n", "meta": {"hexsha": "bc5e2819985649a0348b7cd406e2593f257f7b6b", "size": 6504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/combinatorics.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/combinatorics.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/combinatorics.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": 30.9714285714, "max_line_length": 593, "alphanum_fraction": 0.6655904059, "num_tokens": 2406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6305328423647487}}
{"text": "\\chapter{Python Classes}\n\nThe built-in types, like strings have functions associated with\nthem. So, for example, if you needed a string converted to uppercase,\nyou would call it's \\pyfunction{upper()} function:\n-\n\\begin{Verbatim}\nmy_string = \"houston, we have a problem!\"\nlouder_string = my_string.upper()\n\\end{Verbatim}\nThis would set \\pyvar{louder\\_string} to \"HOUSTON, WE HAVE A PROBLEM!\"\nWhen a function is associated with a datatype like this, it called a\n\\emph{method}. A datatype with methods is known as a \\emph{class}. The\ndata of that type is known as \\emph{instance} of that class. For\nexample, in the example, we would say ``\\pyvar{my\\_string} is an instance of\nthe class \\pytype{str}. \\pytype{str} has a method called \\pyfunction{upper}''\n\nThe function \\pyfunction{type} will tell you the type of any data:\n\\begin{Verbatim}\n  print(type(my_string))\n\\end{Verbatim}\nThis will output\n\\begin{Verbatim}\n<class 'str'>\n\\end{Verbatim}\n\nA class can also define operators.  \\pyfunction{+}, for example, is\nredefined by \\pytype{str} to concatenate strings together:\n\\begin{Verbatim}\nlong_string = \"I saw \" + \"15 people\"\n\\end{Verbatim}\n\n\\section{Making a Polynomial class}\n\nYou have created a bunch of useful python functions for dealing with\npolynomials. Notice how each one has the word ``polynomial'' in the\nfunction name like \\pyfunction{derivative\\_of\\_polynomial}.  Wouldn't it\nbe more elegant if you had a Polynomial class with a\n\\pyfunction{derivative} method? Then you could use your polynomial\nlike this:\\index{class in python}\n\\begin{Verbatim}\na = Polynomial([9.0, 0.0, 2.3])\nb = Polynomial([-2.0, 4.5, 0.0, 2.1])\n\nprint(a, \"plus\", b , \"is\", a+b)\nprint(a, \"times\", b , \"is\", a*b)\nprint(a, \"times\", 3 , \"is\", a*3)\nprint(a, \"minus\", b , \"is\", a-b)\n\nc = b.derivative()\n\nprint(\"Derivative of\", b ,\"is\", c)\n\\end{Verbatim}\n\nAnd it would output:\n\\begin{Verbatim}\n2.30x^2 + 9.00 plus 2.10x^3 + 4.50x + -2.00 is 2.10x^3 + 2.30x^2 + 4.50x + 7.00\n2.30x^2 + 9.00 times 2.10x^3 + 4.50x + -2.00 is 4.83x^5 + 29.25x^3 + -4.60x^2 + 40.50x + -18.00\n2.30x^2 + 9.00 times 3 is 6.90x^2 + 27.00\n2.30x^2 + 9.00 minus 2.10x^3 + 4.50x + -2.00 is -2.10x^3 + 2.30x^2 + -4.50x + 11.00\nDerivative of 2.10x^3 + 4.50x + -2.00 is 6.30x^2 + 4.50  \n\\end{Verbatim}\n\nCreate a file for your class definition called \\filename{Polynomial.py}. Enter the following:\n\\begin{Verbatim}\nclass Polynomial:\n    def __init__(self, coeffs):\n        self.coefficients = coeffs.copy()\n\n    def __repr__(self):\n        # Make a list of the monomial strings\n        monomial_strings = []\n\n        # For standard form we start at the largest degree\n        degree = len(self.coefficients) - 1\n\n        # Go through the list backwards\n        while degree >= 0:\n            coefficient = self.coefficients[degree]\n\n            if coefficient != 0.0:\n                # Describe the monomial\n                if degree == 0:\n                    monomial_string = \"{:.2f}\".format(coefficient)\n                elif degree == 1:\n                    monomial_string = \"{:.2f}x\".format(coefficient)\n                else:\n                    monomial_string = \"{:.2f}x^{}\".format(coefficient, degree)\n                \n                # Add it to the list\n                monomial_strings.append(monomial_string)\n        \n            # Move to the previous term\n            degree = degree - 1\n\n        # Deal with the zero polynomial\n        if len(monomial_strings) == 0:\n            monomial_strings.append(\"0.0\")\n    \n        # Separate the terms with a plus sign\n        return \" + \".join(monomial_strings)\n\n    def __call__(self, x):\n        sum = 0.0  \n        for degree, coefficient in enumerate(self.coefficients):\n            sum = sum + coefficient * x ** degree\n        return sum\n\n    def __add__(self, b):\n        result_length = max(len(self.coefficients), len(b.coefficients))\n        result = []\n        for i in range(result_length):\n            if i < len(self.coefficients):\n                coefficient_a = self.coefficients[i]\n            else:\n                coefficient_a = 0.0\n\n            if i < len(b.coefficients):\n                coefficient_b = b.coefficients[i]\n            else:\n                coefficient_b = 0.0\n            result.append(coefficient_a + coefficient_b)\n            \n        return Polynomial(result)\n\n    def __mul__(self, other):\n\n        # Not a polynomial?\n        if not isinstance(other, Polynomial):\n            # Try to make it a constant polynomial\n            other = Polynomial([other])\n        \n        # What is the degree of the resulting polynomial?\n        result_degree = (len(self.coefficients) - 1) + (len(other.coefficients) - 1)\n\n        # Make a list of zeros to hold the coefficents\n        result = [0.0] * (result_degree + 1)\n\n        # Iterate over the indices and values of a\n        for a_degree, a_coefficient in enumerate(self.coefficients):\n\n            # Iterate over the indices and values of b\n            for b_degree, b_coefficient in enumerate(other.coefficients):\n\n                # Calculate the resulting monomial\n                coefficient = a_coefficient * b_coefficient\n                degree = a_degree + b_degree\n            \n                # Add it to the right bucket\n                result[degree] = result[degree] + coefficient\n            \n        return Polynomial(result)\n\n    __rmul__ = __mul__\n\n    def __sub__(self, other):\n        return self + other * -1.0\n    \n    def derivative(self):\n\n        # What is the degree of the resulting polynomial?\n        original_degree = len(self.coefficients) - 1\n        if original_degree > 0:\n            degree_of_derivative = original_degree - 1\n        else:\n            degree_of_derivative = 0\n\n        # We can ignore the constant term (skip the first coefficient)\n        current_degree = 1\n        result = []\n\n        # Differentiate each monomial\n        while current_degree < len(self.coefficients):\n            coefficient = self.coefficients[current_degree]\n            result.append(coefficient * current_degree)\n            current_degree = current_degree + 1\n\n        # No terms? Make it the zero polynomial\n        if len(result) == 0:\n            result.append(0.0)\n\n        return Polynomial(result)\n\\end{Verbatim}\n\nCreate a second file called \\filename{test\\_polynomial.py} to test it:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nfrom Polynomial import Polynomial\n\na = Polynomial([9.0, 0.0, 2.3])\nb = Polynomial([-2.0, 4.5, 0.0, 2.1])\n\nprint(a, \"plus\", b , \"is\", a+b)\nprint(a, \"times\", b , \"is\", a*b)\nprint(a, \"times\", 3 , \"is\", a*3)\nprint(a, \"minus\", b , \"is\", a-b)\n\nc = b.derivative()\n\nprint(\"Derivative of\", b ,\"is\", c)\n\nslope = c(3)\nprint(\"Value of the derivative at 3 is\", slope)\n\n\\end{Verbatim}\n\nRun the test code:\n\\begin{Verbatim}\npython3 test_polynomial.py\n\\end{Verbatim}\n", "meta": {"hexsha": "c909c48be7c15dc983f9b3487e7b74e1634fee86", "size": 6792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/classes-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/classes-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/classes-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.3428571429, "max_line_length": 95, "alphanum_fraction": 0.6176383981, "num_tokens": 1860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.6305328391502792}}
{"text": "\\section{Supervised classification}\n\nAs discussed in section \\vref{uns-class}, text classification is the \nproblem of associating texts to classes, that are identified by labels.\n\n\\paragraph{Training data set}\nA set of data examples are provided to the classifier to learn \nthe mapping between data and labels. The goal is then to \npredict unlabeled data.\n\n\\paragraph{Unsupervised vs Supervised}\nIn the first case we don't have any information about \nclassification criterions, while in the second we have classes \nassociated to features, represented by the data points associated with \nlabels.\n\n\\subsection{Models}\n\n\\paragraph{Decision trees}\nThe application of this model to text classification is rather \neasy. \nOne could compute a vectorization of the text, in one of the many ways\nseen and apply the tree learning algorithm.\nThis means imposing constraints on the presence and relevance \nof a certain word in a document.\n\nOne of the pros of having a decision tree is quick and easy visualization.\nThis means being able to see how the model computes a classification, \nto potentially avoid unethical decisions.\n\n\\paragraph{Rule-based classifiers}\nThese classifiers are based on rules, they are similar to \ndecision trees, basically the antecedent of \nthe rule is a subset of words and the consequent is a label.\n\n\\paragraph{Naive Bayes Classifiers}\nThe idea is that data has been generated by a mixture of $k$ components, \nwhere $k$ is the number of classes.\nThe goal is to estimate the probability \n\\begin{equation}\n    \\begin{aligned}\n        P(\\mathit{class} \\;|\\;\\mathit{features} ) &= \n        \\frac{P(\\mathit{class}) \n        P(\\mathit{features}\\;|\\;\\mathit{class})}{P(\\mathit{features})}\n        \\\\&= P(\\mathit{class}) \n        P(\\mathit{features}\\;|\\;\\mathit{class})\n    \\end{aligned}\n\\end{equation}\nwhere the probability of a class is the size of the class over the size \nof the corpus.\nAlso, the probability of features given the class, is simply \nthe product of the count of a given words over the total count of the words in \nthe class.\n\n\\paragraph{K-NN classifiers}\nThe application of the model to text is straight forward after \ntext vectorization.\n\n\\paragraph{Linear classifiers}\nThe idea is to learn an hyperplane separating data, again, this is \nnot different to any linear classifier task.\n\nThe main idea is to minimize a loss function plus \na regularizer term.\n\n\\paragraph{Support Vector Machines}\nA linear classifier is the Support Vector Machine, \nthe goal is to find the optimal hyperplane separating data, \ni.e. the one with greater margin between the two classes.\n\nTo accommodate non linearly separable data one could use the kernel \ntrick. Basically we perform a transformation of the dataset \nto map it in a high dimensional space where data point could be \nlinearly separable.  There are many possible kernels.\n\n\\subsection{Classification strategies}\nWhen the system is efficient in performing binary classification\nwe can apply it to multi-class classification by transforming the \nproblem in a binary task.\n\n\\paragraph{One vs Rest}\nThe goal here is to learn a binary classifier between a class and all \nthe others.\n\n\\paragraph{One vs One}\nThe idea here is to train a classifier between every pair of classes.\n\n\\subsection{Multi-label classification}\nTo assign multiple labels to data point we need to exploit \nsomething in the previous classifiers. \n\nFor instance, we could use the distance of the many one vs one classifiers \nas confidence measures for labels. \n\nAnother way is to take the power set of classes and train many classifiers \nas before. We are left with a multi-class classification \nwhere each class is a combination of labels.\n\n\\subsection{Hyperparameters tuning  and evaluation}\n\n\\paragraph{Model selection}\nThe activity of tuning hyperparameters to find the \nbest model instance to solve a task.\n\n\\paragraph{Cross Validation}\nThe idea is to split the dataset in $k$ folds and consider \n$k-1$ folds as training and the last one as test set.\nWe iterate over the possible training sets and average the error.\n\n\\paragraph{Confusion matrix}\nWe can arrange the errors in a confusion matrix to see \nhow many elements of class $i$ are classified as class $j$. \nObviously the goal is to have positive values only on the \ndiagonal.\n", "meta": {"hexsha": "f3591d914d6c0fc8e4a22ba99c4cc5b9d9d77e2a", "size": 4273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-courses/information-retrieval/chapters/supervised_classification.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/supervised_classification.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/supervised_classification.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": 37.1565217391, "max_line_length": 79, "alphanum_fraction": 0.7781418207, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954684, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6305328333693574}}
{"text": "\\section{Introduction}\n\\label{sec:Introduction}\n\nTEAL (Tool for Economic AnaLysis) is a RAVEN plug-in that leverages Uncertainty Quantification, Probabilistic Risk Assessment, Parameter Optimization\nand Data Analysis framework in RAVEN to perform basic cash flow analyses.\n\nTEAL enables computation of the \\textbf{NPV (Net Present Value)}, \\textbf{IRR (Internal Rate of Return)}, and the \\textbf{PI (Profitability Index)} with RAVEN.\nFurthermore, it allows NPV, IRR, or PI search (i.e. TEAL will compute a multiplicative value such as the production cost) so that the NPV, IRR or PI has a desired value.\nThe plugin allows for a generic definition of cash flows, which are driven by variables provided by RAVEN. Furthermore, TEAL includes flexible options to deal with taxes, inflation, and discounting, and\noffers capabilities to compute a combined cash flow for components with different component lifetimes.\n\n\\textbf{NPV}: computes the Net Present Value according to Eq. \\ref{eq:NPV}.\n\\begin{equation}\\label{eq:NPV}\nNPV=\\sum_{y=0}^{N}\\frac{CF_{y}}{(1+DiscountRate)^{y}}\n\\end{equation}\n\nThe sum runs over the years $y=0$ to $N$. The net cash flows $CF_{y}$ are the sum of all cash flows defined in the indicator block (discussed later).\n$N$ is the least common multiple (LCM) of all component lifetimes involved. This guarantees that the NPV is computed for a time span so that all components reach their end of life in the same year.\nThe individual component cash flows are repeated until the LCM is reached.\n\nFor example, let's assume the calculation involves two components, \\textit{Component1} and \\textit{Component2},\n with life times of 60 years and 40 years respectively. $N$ will be 120 years where two successive \\textit{Component1} and three successive \\textit{Component2} will be built. For every \"building year,\"\nthe cash flow will be summed for the last year (of the old component) and the year zero (for the newly built component). Table \\ref{tbl:cashflows} shows an example.\nTEAL computes the the cash flows and the NPV, and sends the variable `NPV' back to RAVEN to be added to the output data object.\n\n\\begin{table}[]\n\\centering\n\\caption{Example cash flows for NPV calculation.}\n\\label{tbl:cashflows}\n\\begin{tabular}{ll|l|l|l|l|l|ll}\n\\cline{3-4} \\cline{6-7}\n                           &  & \\multicolumn{2}{l|}{Compo. 1}                                                                                                   &  & \\multicolumn{2}{l|}{Compo. 2}                                                                                                     &                       &                                                                                                       \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{Year} &  & \\begin{tabular}[c]{@{}l@{}}Comp. \\\\ lifetime\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}Cash Flow\\\\ (year)\\end{tabular}         &  & \\begin{tabular}[c]{@{}l@{}}Compo. \\\\ Lifetime\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}  Cash Flow \\\\ (year) \\end{tabular}      & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{\\begin{tabular}[c]{@{}l@{}}Total Net Cash flow \\\\ ($CF_{y}$)         \\end{tabular}}   \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{0}    &  & 0                                                         & $CF^{comp1}_{0}$                                                          &  & 0                                                          & $CF^{comp2}_{0}$                                                           & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{0} + CF^{comp2}_{0}$ }                                     \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{1}    &  & 1                                                         & $CF^{comp1}_{1}$                                                          &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{1} + CF^{comp2}_{1}$ }                                     \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{}                                                                                 \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{39}   &  & 39                                                        & $CF^{comp1}_{39}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{39} + CF^{comp2}_{39}$ }                                   \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{40}   &  & 40                                                        & $CF^{comp1}_{40}$                                                         &  & 40 and 0                                                   & \\begin{tabular}[c]{@{}l@{}}$CF^{comp2}_{40}$  \\\\ $+ CF^{comp2}_{0}$ \\end{tabular} & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{\\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{40} + CF^{comp2}_{40}$ \\\\  $+ CF^{comp2}_{0}$ \\end{tabular}} \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{41}   &  & 41                                                        & $CF^{comp1}_{41}$                                                         &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{41} + CF^{comp2}_{1}$ }                                  \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{}                                                                                 \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{59}   &  & 59                                                        & $CF^{comp1}_{59}$                                                         &  & 19                                                         & $CF^{comp2}_{19}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{59} + CF^{comp2}_{19}$ }                                 \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{60}   &  & 60 and 0                                                  & \\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{60}$ \\\\ $+ CF^{comp1}_{0}$ \\end{tabular} &  & 20                                                         & $CF^{comp2}_{20}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{\\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{60} + CF^{comp1}_{0}$ \\\\ $+ CF^{comp2}_{20}$ \\end{tabular}} \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{61}   &  & 1                                                         & $CF^{comp1}_{1}$                                                          &  & 21                                                         & $CF^{comp2}_{21}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{1} + CF^{comp2}_{21}$ }                                                          \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{}                                                                                 \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{79}   &  & 19                                                        & $CF^{comp1}_{19}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{19} + CF^{comp2}_{39}$ }                                                         \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{80}   &  & 20                                                        & $CF^{comp1}_{20}$                                                         &  & 40 and 0                                                   & \\begin{tabular}[c]{@{}l@{}}$CF^{comp2}_{40}$ \\\\  $+ CF^{comp2}_{0}$ \\end{tabular} & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{\\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{20} + CF^{comp2}_{40}$ \\\\ $+ CF^{comp2}_{0}$ \\end{tabular}}  \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{81}   &  & 21                                                        & $CF^{comp1}_{21}$                                                         &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{21} + CF^{comp2}_{1}$ }                                                          \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{}                                                                                 \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{119}  &  & 59                                                        & $CF^{comp1}_{59}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{59} + CF^{comp2}_{39}$ }                                                         \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\multicolumn{1}{|l|}{120}  &  & 60                                                        & $CF^{comp1}_{60}$                                                         &  & 40                                                         & $CF^{comp2}_{40}$                                                          & \\multicolumn{1}{l|}{} & \\multicolumn{1}{l|}{$CF^{comp1}_{60} + CF^{comp2}_{40}$}                                                         \\\\ \\cline{1-1} \\cline{3-4} \\cline{6-7} \\cline{9-9}\n\\end{tabular}\n\\end{table}\n\n\\textbf{PI}: computes the Profitability Index according to Eq. \\ref{eq:PI}.\n\\begin{equation}\\label{eq:PI}\nPI=\\frac{NPV}{Initial\\_investment}\n\\end{equation}\nNPV is calculated as explained above and the $Initial\\_investment$ is the Total Net Cash flow at year zero ($CF_{0}$ in the example above).\nTEAL computes the the cash flows and the PI, and sends the variable`'PI' back to RAVEN to be added to the output data object.\n\n\\textbf{IRR}: computes the Internal Rate of Return according to Eq. \\ref{eq:IRR}.\n\\begin{equation}\\label{eq:IRR}\n0=\\sum_{y=0}^{N}\\frac{CF_{y}}{(1+IRR)^{y}}\n\\end{equation}\nSimilar to the NPV, the sum runs over the years $y=0$ to $N$. The net cash flows $CF_{y}$ are the sum of all cash flows defined in the indicator block\n(see explanation of NPV above for details). $N$ is the LCM of all component life times involved.\nTEAL computes the cash flows and the IRR, and sends the variable `IRR' back to RAVEN to be added to the output data object.\n\n\\textbf{NPV\\_search}: The NPV search finds a multiplier `$x$' that multiplies some of the cash flows, so that the NPV has a desired value (defined by the \\xmlAttr{target} attribute). The equation solved is shown in Eq. \\ref{eq:NPV_search}.\n\\label{subsec:NPV_search}\n\\begin{equation}\\label{eq:NPV_search}\n'target'=\\sum_{y=0}^{N}\\frac{CF^{dep\\_on\\_x}_{y}}{(1+DiscountRate)^{y}}x + \\sum_{y=0}^{N}\\frac{CF^{not\\_dep\\_on\\_x}_{y}}{(1+DiscountRate)^{y}}\n\\end{equation}", "meta": {"hexsha": "91e96bc1663e41230c53fdf9cadee9eb1f71b3f6", "size": 12969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/src/introduction.tex", "max_stars_repo_name": "wanghy-anl/TEAL", "max_stars_repo_head_hexsha": "500f1ac6fa3a308fbee328abc6a165205019df70", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-28T21:37:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-28T22:46:32.000Z", "max_issues_repo_path": "doc/src/introduction.tex", "max_issues_repo_name": "wanghy-anl/TEAL", "max_issues_repo_head_hexsha": "500f1ac6fa3a308fbee328abc6a165205019df70", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2020-07-31T15:15:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T17:34:36.000Z", "max_forks_repo_path": "doc/src/introduction.tex", "max_forks_repo_name": "wanghy-anl/TEAL", "max_forks_repo_head_hexsha": "500f1ac6fa3a308fbee328abc6a165205019df70", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2020-07-31T14:49:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T22:59:38.000Z", "avg_line_length": 177.6575342466, "max_line_length": 511, "alphanum_fraction": 0.3918575064, "num_tokens": 3343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6304844045049791}}
{"text": "% This is part of the TFTB Tutorial.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file tutorial.tex for copying conditions.\n\n\\section{The reassignment method}\n%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\\index{reassignment} \n\\subsection{Introduction}\n%''''''''''''''''''''''''\n\n  Bilinear time-frequency distributions, presented in the previous two\nsections, offer a wide range of methods designed for the analyze of non\nstationary signals. Nevertheless, a critical point of these methods is\ntheir readability, which means both a good concentration of the signal\ncomponents and no misleading interference terms. Some efforts have been\nmade recently in that direction, and in particular a general methodology\nreferred to as {\\it reassignment}. The purpose of this section is to\npresent this methodology, to illustrate it on different examples, and to\nmake the link with connected approaches (see \\cite{AUG94}, \\cite{KOD76} and\n\\cite{AUG95} for more details on reassignment).\n\n\n\\subsection{The reassignment of the spectrogram}\n%'''''''''''''''''''''''''''''''''''''''''''''''\n\n  The original idea of reassignment was introduced in an attempt to\nimprove the spectrogram. Indeed, as any other bilinear energy\ndistribution, the spectrogram is faced with an unavoidable trade-off\nbetween the reduction of misleading interference terms and a sharp\nlocalization of the signal components.\n\n  Let us recall the expression of the spectrogram as a 2D-convolution\nof the Wigner-Ville distribution of the signal by the WVD of the\nanalysis window :\n\\begin{eqnarray}\n\\label{spectro2}\nS_x(t,\\nu;h)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} W_x(s,\\xi)\\\nW_h(t-s,\\nu-\\xi)\\ ds\\ d\\xi.\t \n\\end{eqnarray}\nTherefore, this distribution reduces the interference terms of the signal's\nWVD, but at the expense of opposed time and frequency resolutions, and of\nbiased marginals and first order moments. However, a closer look at\nexpression (\\ref{spectro2}) shows that $W_h(t-s,\\nu-\\xi)$ delimits a\ntime-frequency domain at the vicinity of the $(t,\\nu)$ point, inside which\na weighted average of the signal's WVD values is performed. The key point\nof the reassignment principle is that these values have no reason to be\nsymmetrically distributed around $(t,\\nu)$, which is the geometrical center\nof this domain. Therefore, their average should not be assigned at this\npoint, but rather at the center of gravity of this domain, which is much\nmore representative of the local energetic distribution of the\nsignal. Reasoning with a mechanical analogy, the local energy distribution\n$W_h(t-s,\\nu-\\xi) W_x(s,\\xi)$ (as a function of $s$ and $\\xi$) can be\nconsidered as a mass distribution, and it is much more accurate to assign\nthe total mass (i.e. the spectrogram value) to the center of\ngravity of the domain rather than to its geometrical center.\n\n  This is exactly how the reassignment method proceeds : it moves each\nvalue of the spectrogram computed at any point $(t,\\nu)$ to another point\n$(\\hat{t},\\hat{\\nu})$ which is the center of gravity of the signal energy\ndistribution around $(t,\\nu)$ :\n\\begin{eqnarray}\n\\label{hatt}\n\\hat{t}(x;t,\\nu)={\n\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} s\\ \nW_h(t-s,\\nu-\\xi)\\ W_x(s,\\xi)\\ ds\\ d\\xi\n\\over\n\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} W_h(t-s,\\nu-\\xi)\\\nW_x(s,\\xi)\\ ds\\ d\\xi}\\\\ \n\\label{hatnu}\n\\hat{\\nu}(x;t,\\nu)=\\frac{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\n\\xi\\ W_h(t-s,\\nu-\\xi)\\ W_x(s,\\xi)\\ ds\\ d\\xi} \n {\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} W_h(t-s,\\nu-\\xi)\\\nW_x(s,\\xi)\\ ds\\ d\\xi}\t         \n\\end{eqnarray}\nand thus leads to a reassigned spectrogram, whose value at any point\n$(t',\\nu')$ is the sum of all the spectrogram values reassigned to this\npoint :\n\\begin{eqnarray}\n\\label{reasspectro}\n S_x^{(r)}(t',\\nu';h)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\nS_x(t,\\nu;h)\\ \\delta(t'-\\hat{t}(x;t,\\nu))\\ \\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\\ndt\\ d\\nu \\ \\  \n\\end{eqnarray}\nOne of the mostly interesting properties of this new\ndistribution is that it also uses the phase information of the\nshort-time Fourier transform, and not only its squared modulus as in\nthe spectrogram. This can be seen from the following expressions of\nthe reassignment operators : \n\\begin{eqnarray*}\n\t\\hat{t}(x;t,\\nu)  = -\\frac{d\\Phi_x(t,\\nu;h)}{d\\nu}\\\\\n\t\\hat{\\nu}(x;t,\\nu) = \\nu+\\frac{d\\Phi_x(t,\\nu;h)}{dt}\n\\end{eqnarray*}\nwhere $\\Phi_x(t,\\nu;h)$ is the phase of the STFT of $x$ :\n$\\Phi_x(t,\\nu;h)=\\arg(F_x(t,\\nu;h))$. However, these expressions do not\nlead to an efficient implementation, and have to be replaced by the\nfollowing ones :\n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu)=t-\\Re\\left\\{\\frac{F_x(t,\\nu;T_h)\\\n F_x^*(t,\\nu;h)}{|F_x(t,\\nu;h)|^2}\\right\\}\\\\ \n\\hat{\\nu}(x;t,\\nu)=\\nu-\\Im\\left\\{\\frac{F_x(t,\\nu;D_h)\\\n F_x^*(t,\\nu;h)}{|F_x(t,\\nu;h)|^2}\\right\\} \n\\end{eqnarray*}\nwhere $T_h(t)=t\\times h(t)$ and $D_h(t)=\\frac{dh}{dt}(t)$. Reassigned\nspectrograms are therefore very easy to implement, and do not require a\ndrastic increase in computational complexity.\n\n  Finally, it should also be underlined that the reassigned spectrogram,\nthough no longer bilinear, satisfies the time and frequency shifts\ncovariance, the energy conservation (provided that $h(t)$ is of unit\nenergy), and the non-negativity property. It cans also be shown that, since\nthe WVD is perfectly localized on linear chirp signals and impulses, any\nreassigned spectrogram also satisfies this property :\n\\begin{eqnarray*}\nx(t)=A\\ \\exp\\left\\{j\\{\\nu_0 t+\\alpha\nt^2/2\\}\\right\\}&\\Rightarrow&\\hat{\\nu}=\\nu_0+\\alpha\\hat{t}\\\\ \nx(t)=A\\ \\delta(t-t_0)&\\Rightarrow&\\hat{t}=t_0.\n\\end{eqnarray*}\n  Before presenting the generalization of this method to the Cohen's class\nand to the affine class, let us have a look at the readability improvement\nobtained by the reassigned spectrogram on an example of multi-component\nsignal. The reassigned spectrogram is available thanks to the M-file\n\\index{\\ttfamily tfrrsp}{\\ttfamily tfrrsp.m}. The result is compared to the\nspectrogram and to the \"ideal\" representation \\index{\\ttfamily\ntfrideal}({\\ttfamily tfrideal.m}) based on the knowledge of the\ninstantaneous frequency law of each component :\n\\begin{verbatim}\n     >> N=128; [sig1 ifl1]=fmsin(N,0.15,0.45,100,1,0.4,-1);\n     >> [sig2 ifl2]=fmhyp(N,[1 .5],[32 0.05]);\n     >> sig=sig1+sig2;\n     >> tfrideal([ifl1 ifl2]);\n     >> figure; tfrrsp(sig);\n\\end{verbatim}\n\\begin{figure}[htb]\n\\epsfxsize=12cm\n\\epsfysize=8cm\n\\centerline{\\epsfbox{figure/re1fig1.eps}}\n\\caption{\\label{Re1fig1}Reassignment of the spectrogram on a synthetic\nsignal composed of a sinusoidal frequency modulation simultaneously with a\nhyperbolic frequency modulation : comparison with the ``ideal''\ntime-frequency representation and with the spectrogram}\n\\end{figure}\n\nThe file \\index{\\ttfamily tfrrsp}{\\ttfamily tfrrsp.m} allows you to display\nthe spectrogram itself or its reassigned version. The improvement given by\nthe reassignment method is obvious : the two components are much better\nlocalized and almost perfectly concentrated, and there are very few\ncross-terms.\n\n\n\\subsection{Reassignment of the Cohen's class representations}\n%'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\n  The presentation of the reassignment principle done above allows a\nstraightforward extension of its use to other distributions. Indeed,\nif we consider the general expression of a distribution of the Cohen's\nclass as a 2D-convolution of the WVD, \n\\begin{eqnarray*}\nC_x(t,\\nu;\\Pi)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\n\\Pi(t-s,\\nu-\\xi)\\ W_x(s,\\xi)\\ ds\\ d\\xi, \n\\end{eqnarray*}\nreplacing the particular smoothing kernel $W_h(u,\\xi)$ in expressions\n(\\ref{hatt}), (\\ref{hatnu}) and (\\ref{reasspectro}) by an arbitrary kernel\n$\\Pi(s,\\xi)$ simply defines the reassignment of any member of the Cohen's\nclass :\n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu) &=&\n\\frac{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} s\\\n\\Pi(t-s,\\nu-\\xi)\\ W_x(s,\\xi)\\ ds\\ d\\xi} \n {\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\Pi(t-s,\\nu-\\xi)\\\nW_x(s,\\xi)\\ ds\\ d\\xi}\\\\ \n\\hat{\\nu}(x;t,\\nu)&=&\n\\frac{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\xi\\\n\\Pi(t-s,\\nu-\\xi)\\ W_x(s,\\xi)\\ ds\\ d\\xi} \n {\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\Pi(t-s,\\nu-\\xi)\\\nW_x(s,\\xi)\\ ds\\ d\\xi}\\\\ \nC_x^{(r)}(t',\\nu';\\Pi)&=&\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\nC_x(t,\\nu;\\Pi)\\ \\delta(t'-\\hat{t}(x;t,\\nu))\\\n\\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\ dt\\ d\\nu.\t       \n\\end{eqnarray*}\nThe resulting reassigned distributions efficiently combine a reduction of\nthe interference terms provided by a well adapted smoothing kernel and an\nincreased concentration of the signal components achieved by the\nreassignment. From a theoretical point of view, these distributions are\ncovariant by time and frequency shifts, and are perfectly localized for\nlinear chirp signals and impulses. Finally, for the most common cases, such\nas the SPWVD and the Reduced Interference Distributions (see section\n\\ref{SPWVD} and \\ref{RID}), the reassignment operators $\\hat{t}(x;t,\\nu)$ and\n$\\hat{\\nu}(x;t,\\nu)$ are almost as easy to compute as for the spectrogram.\n\n\n\\subsection{Reassignment of the affine class representations}  \n%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n  Similarly, the reassignment method can also be applied to the\ntime-scale energy distributions. Starting from the general \nexpression :\n\\begin{eqnarray*}\n\\Omega_x(t,a;\\Pi)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\n\\Pi(s/a,\\nu_0-a \\xi)\\ W_x(t-s,\\xi)\\ ds\\ d\\xi \n\\end{eqnarray*}\nwe can see that the representation value at any point $(t,a=\\nu_0/\\nu)$ is\nthe average of the weighted WVD values on the points $(t-s,\\xi)$ located in\na domain centered on $(t,\\nu)$ and bounded by the essential support of\n$\\Pi$. In order to avoid the resultant signal components broadening while\npreserving the cross-terms attenuation, it seems once again appropriate to\nassign this average to the center of gravity of these energy measures,\nwhose coordinates are :\n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu) &=&\nt-\\frac{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} s\\\n\\Pi(s/a,\\nu_0-a \\xi)\\ W_x(t-s,\\xi)\\ ds\\ d\\xi} \n {\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\Pi(s/a,\\nu_0-a \\xi)\\\nW_x(t-s,\\xi)\\ ds\\ d\\xi}\t\\\\ \n\\hat{\\nu}(x;t,\\nu) &=& \\frac{\\nu_0}{\\hat{a}(x;t,\\nu)}\\\\\n &=& \\frac{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\xi\\\n\\Pi(s/a,\\nu_0-a \\xi)\\ W_x(t-s,\\xi)\\ ds\\ d\\xi} \n   {\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\Pi(s/a,\\nu_0-a \\xi)\\\nW_x(t-s,\\xi)\\ ds\\ d\\xi}\t \n\\end{eqnarray*}\nrather than to the point $(t,a=\\nu_0/\\nu)$ where it is computed. The value\nof the resulting modified time-scale representation on any point\n$(t',a')$ is then the sum of all the representation values moved to this\npoint :\n\\begin{eqnarray*}\n\\Omega_x^{(r)}(t',a';\\Pi)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\n{a'}^2\\ \\Omega_x(t,a;\\Pi)\\  \n \\delta(t'-\\hat{t}(x;t,a))\\ \\delta(a'-\\hat{a}(x;t,a))\\ dt\\ \\frac{da}{a^2}.\n\\end{eqnarray*}\nAs for the Cohen's class, it can be shown that these modified\ndistributions are no longer bilinear, but are covariant by time shifts\nand time scalings, distribute the energy of the signal on the whole\ntime-scale plane, and are also perfectly localized for chirps and\nimpulses. \n\n\n\\subsection{Numerical examples}\n%''''''''''''''''''''''''''''''\n  In order to evaluate the benefits of the reassignment method in practical\napplications, a comparison of the experimental results provided by some\ntime-frequency representations and their modified versions is shown in this\nsection. The analyzed signal is a 128-points signal made up of a sinusoidal\nfrequency modulation followed by a pure tone simultaneously with a chirp\ncomponent :\n\\begin{verbatim}\n     >> [sig1 ifl1]=fmsin(60,0.15,0.35,50,1,0.35,1);\n     >> [sig2 ifl2]=fmlin(60,0.3,0.1);\n     >> [sig3 ifl3]=fmconst(60,0.4);\n     >> sig=[sig1;zeros(8,1);sig2+sig3];\n     >> iflaw=zeros(128,2);\n     >> iflaw(:,1)=[ifl1;NaN*ones(8,1);ifl2];\n     >> iflaw(:,2)=[NaN*ones(68,1);ifl3];\n\\end{verbatim}\nWe first plot the instantaneous frequency laws (obtained by {\\ttfamily\ntfrideal}), to which the proposed solutions should be as near as possible,\nand the WVD of this signal (see the first two plots of figure\n\\ref{Re1fig2})\\,:\n\\begin{verbatim}\n     >> tfrideal(iflaw);\n     >> figure; tfrwv(sig);\n\\end{verbatim}\nWith the WVD, the signal components are well localized, but the numerous\ncross-terms make the figure hardly readable. If we now consider the\nsmoothed pseudo-WVD and its reassigned version (see the third and fourth\nplots of fig. \\ref{Re1fig2}),\n\\begin{verbatim}\n     >> tfrrspwv(sig);\n\\end{verbatim}\nwe can see that the smoothing done by the SPWVD almost completely suppress\nthe cross terms, but the signal components localization becomes\ncoarser. The improvement given by the reassignment method is obvious : all\ncomponents are much better localized, leading to a nearly ideal\nrepresentation.\n\\begin{figure}[htb]\n\\epsfxsize=12cm\n\\epsfysize=12cm\n\\centerline{\\epsfbox{figure/re1fig2.eps}}\n\\caption{\\label{Re1fig2}Comparison of different time-frequency\ndistributions and their reassigned version (1/3) : the analyzed signal is\ncomposed of three components, as can be clearly seen on the first plot\nrepresenting the instantaneous frequency laws of the components. The other\nplots are the Wigner-Ville distribution, the smoothed pseudo Wigner-Ville\ndistribution and its reassigned version}\n\\end{figure}\nThe next distributions we consider are the spectrogram (see the first two\nplots of fig. \\ref{Re1fig3}) and the Morlet scalogram (see the third and\nfourth plots of fig. \\ref{Re1fig3})\\,:\n\\begin{verbatim}\n     >> figure(1); tfrrsp(sig);\n     >> figure(2); tfrrmsc(sig);\n\\end{verbatim}\n\\begin{figure}[htb]\n\\epsfxsize=12cm\n\\epsfysize=12cm\n\\centerline{\\epsfbox{figure/re1fig3.eps}}\n\\caption{\\label{Re1fig3}Comparison of different time-frequency\ndistributions and their reassigned version (2/3) : the spectrogram and the\nMorlet scalogram}\n\\end{figure}\nThese two distributions present nearly no cross terms, except at\nthe bottom of the sinusoid and around time $t=64$. But the time and\nfrequency resolutions are not good, especially at low frequencies in the\ncase of the scalogram. The reassignment method improves considerably these\nlocalizations, and the reassigned spectrogram is even perfectly\nconcentrated for the chirp components. The result obtained with the\nmodified scalogram is less good, especially at low frequencies where the\ntime-resolution is really inadequate. \n\nFinally, we represent the pseudo-Page and the pseudo Margenau-Hill\ndistributions with their reassigned version (see fig. \\ref{Re1fig4})\\,:  \n\\begin{verbatim}\n     >> figure(1); tfrrppag(sig);\n     >> figure(2); tfrrpmh(sig);\n\\end{verbatim}\n\\begin{figure}[htb]\n\\epsfxsize=12cm\n\\epsfysize=12cm\n\\centerline{\\epsfbox{figure/re1fig4.eps}}\n\\caption{\\label{Re1fig4}Comparison of different time-frequency\ndistributions and their reassigned version (3/3) : the pseudo Page\ndistribution and the pseudo Margenau-Hill distribution}\n\\end{figure}\nThese representations (before reassignment) are hardly readable since some\ncross-terms are superimposed on the signal components. Their modified\nversions give much better localized signal components, but less\nconcentrated than in the case of the spectrogram or the SPWVD.\n\n\n\\subsection{Connected approaches}\n%''''''''''''''''''''''''''''''''\n  Connections of the reassignment method has been found with other\ntechniques which extract relevant information from the time-frequency\nplane. \n\n\\subsubsection{Friedman's instantaneous frequency density}\n\\index{instantaneous frequency density}\nA first example is the instantaneous frequency density : so as to take\nadvantage of the phase structure of the short-time Fourier transform\n(STFT), Friedman simply computed at each time $t$ the histogram of the\nfrequency displacements $\\hat{\\nu}(x;t,\\nu)$ of the spectrogram. The\nresulting time-frequency representation is no more an energy\ndistribution, and could be derived as well from any other reassigned\ndistribution.\n\nHere is an example of this instantaneous frequency density, obtained with\nthe M-file \\index{\\ttfamily friedman}{\\ttfamily friedman.m} on the\npseudo-WVD of the previous signal (see fig. \\ref{Re1fig5})\\,:\n\\begin{verbatim}\n     >> t=1:2:127; [tfr,rtfr,hat]=tfrrpwv(sig,t);\n     >> friedman(tfr,hat,t,'tfrrsp',1);\n\\end{verbatim}\n\\begin{figure}[htb]\n\\epsfxsize=10cm\n\\epsfysize=10cm\n\\centerline{\\epsfbox{figure/re1fig5.eps}}\n\\caption{\\label{Re1fig5}Instantaneous frequency density defined by\nFriedman, computed from the frequency displacements $\\hat{\\nu}(x;t,\\nu)$ of\nthe pseudo-WVD}\n\\end{figure}\nAlthough some cross terms are still present, the localization of the\ncomponents is quite good, especially for the chirp components.\n\n\n\\subsubsection{Extraction of ridges and skeleton}\n\\index{ridges}\\index{skeleton} Another related approach is the extraction\nof {\\it ridges} and {\\it skeleton}. This method extracts from either the\nSTFT or the continuous wavelet transform (CWT) some particular sets of\ncurves deduced from the stationary points of their phase (see \\cite{FLA93}\nfor more information about the stationary phase principle). Indeed,\napplying the stationary phase theorem to the signal reconstruction formula\nof the CWT $T_x(t,a;\\Psi)$ expressed in the frequency domain :\n\\[X(\\nu)=\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\sqrt{a}\\ H(a\n\\nu)\\ T_x(t,a;\\Psi)\\ e^{-j2\\pi \\nu t}\\ dt\\ \n\\frac{da}{a^2}\\] \nleads to particular points such that \n\\begin{eqnarray}\n\\label{hatt1}\n\\hat{t}(x;t,a)=t-\\Phi'_h(\\nu_0)\\ \\ \\mbox{ and }\\ \\ \\hat{a}(x;t,a)=a,\t\n\\end{eqnarray}\nwith $\\Phi_h(\\nu)=\\arg\\{H(\\nu)\\}$, and which constitute a set of curves\ncalled the {\\it horizontal ridges} of the representation. \n\nSimilarly, applying the stationary phase principle to the signal\nreconstruction formula of the CWT expressed in the time domain leads to\nparticular points such that\n\\begin{eqnarray}\n\\label{hatt2}\n\\hat{t}(x;t,a)=t\\ \\ \\mbox{ and }\\ \\ \\hat{a}(x;t,a)=a\\\n\\frac{\\nu_0}{\\phi'_h(0)},  \n\\end{eqnarray}\nwith $\\phi_h(t)=\\arg\\{h(t)\\}$, and which constitute a set of curves called\nthe {\\it vertical ridges} of the representation. These relations between\nthe ridges and the reassignment operators suggest to extract the ridges of\nany reassigned distribution by a straightforward generalization of\nexpressions (\\ref{hatt1}), (\\ref{hatt2}).\n\nFor example, let us extract the ridges from the spectrogram of the previous\nsignal (see fig. \\ref{Re1fig6})\\,:\\index{\\ttfamily ridges}\n\\begin{verbatim}\n     >> [tfr,rtfr,hat]=tfrrsp(sig); \n     >> ridges(tfr,hat);\n\\end{verbatim}\n\\begin{figure}[htb]\n\\epsfxsize=10cm\n\\epsfysize=10cm\n\\centerline{\\epsfbox{figure/re1fig6.eps}}\n\\caption{\\label{Re1fig6}Extraction of ridges from the spectrogram} \n\\end{figure}\nThe result is interesting : apart from some ``gaps'' present in particular\non the sinusoidal frequency modulation, this method concentrates and\nlocalizes nearly ideally the signal in the time-frequency plane, even when\nthere are two components present at the same time (or at the same\nfrequency).\n\n\n\\subsection{Conclusion}\n%''''''''''''''''''''''\n\n  The reassignment method creates a modified version of a\ntime-frequency representation by moving the representation values away\nfrom where they are computed. These displacements depend on the signal\nand on the representation, forcing the bilinearity to be lost, but\nthey are still consistent with many of the representation\nproperties. The principle of reassignment exploits the local\nstructures of a distribution in both time and frequency\ndirections. The experimental results show that this method provides a\nhigher concentration in the time-frequency plane, but of course does\nnot remove all the cross terms.\n", "meta": {"hexsha": "4f4a2208b0e6ab4e1cd4cc225a69bfce6fa2b84a", "size": 19666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/tutorial/reassign.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/tutorial/reassign.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/tutorial/reassign.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 46.056206089, "max_line_length": 77, "alphanum_fraction": 0.7262280077, "num_tokens": 5833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6302867008424229}}
{"text": "\\subsection{Connected spaces}\\label{subsec:connected_sets}\n\n\\begin{definition}\\label{def:connected_space}\\mcite[thm. 6.1.1]{Engelking1989}\n  We say that the topological space \\( X \\) is \\term{connected} if it satisfies any of the following equivalent conditions:\n  \\begin{thmenum}\n    \\thmitem{def:connected_space/open_union} If \\( X = X_1 \\cup X_2 \\) and \\( X_1, X_2 \\) are disjoint open sets, either \\( X_1 \\) or \\( X_2 \\) is empty.\n\n    \\thmitem{def:connected_space/closed_union} If \\( X = X_1 \\cup X_2 \\) and \\( X_1, X_2 \\) are disjoint closed sets, either \\( X_1 \\) or \\( X_2 \\) is empty.\n\n    \\thmitem{def:connected_space/separated_union} If \\( X = X_1 \\cup X_2 \\) and \\( X_1, X_2 \\) are \\hyperref[def:topological_space_separation]{separated}, either \\( X_1 \\) or \\( X_2 \\) is empty.\n\n    \\thmitem{def:connected_space/clopen} The only subsets of \\( X \\) that are both open and closed are \\( \\varnothing \\) and \\( X \\).\n\n    \\thmitem{def:connected_space/discrete_mapping} Every continuous mapping \\( f: X \\to \\{ 0, 1 \\} \\) into the two-point discrete space is constant.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:locally_connected}\\mcite[exer. 6.3.3]{Engelking1989}\n  We say that \\( X \\) is \\term{locally connected} if for every point \\( x \\in X \\) and every neighborhood \\( U \\) of \\( x \\) there exists a connected set \\( C \\subseteq U \\) such that \\( x \\in \\Int(C) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:path_connected}\\mcite[exer. 6.3.9]{Engelking1989}\n  We say that a topological space is \\term{path connected} if every two points can be connected via a \\hyperref[def:parametric_curve]{path}.\n\\end{definition}\n\n\\begin{definition}\\label{def:locally_path_connected}\\mcite[exer. 6.3.10]{Engelking1989}\n  We say that \\( X \\) is \\term{locally path connected} if for every point \\( x \\in X \\) and every neighborhood \\( U \\) of \\( x \\) there exists a neighborhood \\( V \\) of \\( x \\) such that for any \\( y \\in V \\) there exists a path \\( \\gamma: [0, 1] \\to U \\) connecting \\( x \\) with \\( y \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:homomorphism_preserves_connectedness}\n  If \\( X \\) is connected and \\( f: X \\to Y \\) is a homeomorphism, then \\( Y \\) is also connected.\n\\end{proposition}\n\\begin{proof}\n  Let \\( Y = Y_1 \\cup Y_2 \\), where \\( Y_1 \\) and \\( Y_2 \\) are disjoint and open.\n\n  Note that the preimages \\( \\gamma^{-1}(Y_1) \\) and \\( \\gamma^{-1}(Y_2) \\) are open and disjoint, hence \\( X = \\gamma^{-1}(Y_1) \\cup \\gamma^{-1}(Y_2) \\). But \\( X \\) is connected and by \\fullref{def:connected_space/open_union}, either \\( \\gamma^{-1}(Y_1) \\) or \\( \\gamma^{-1}(Y_2) \\) is the null set. Thus, either \\( Y_1 \\) and \\( Y_2 \\) is the null set and, again, by \\fullref{def:connected_space/open_union}, \\( Y \\) is connected.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:path_connected_implies_connected}\n  Any path connected space is connected.\n\\end{proposition}\n\\begin{proof}\n  Let \\( X = X_1 \\cup X_2 \\), where \\( X_1 \\) and \\( X_2 \\) are disjoint and open.\n\n  Assume that both are nonzero and take \\( x_1 \\in X_1, x_2 \\in X_2 \\). Then there exists a path \\( \\gamma: I \\to X \\) with endpoints \\( x_1 \\) and \\( x_2 \\). Note that the preimages \\( \\gamma^{-1}(X_1) \\) and \\( \\gamma^{-1}(X_2) \\) are nonempty and open, hence cannot be separated by \\fullref{def:connected_space/separated_union}. But this contradicts the disjointedness of \\( X_1 \\) and \\( X_2 \\).\n\n  The obtained contradiction proves that \\( X \\) is connected.\n\\end{proof}\n", "meta": {"hexsha": "8e705a73f0a5ce186c98aa5991aea1c1f866bc08", "size": 3474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/connected_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/connected_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/connected_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": 70.8979591837, "max_line_length": 433, "alphanum_fraction": 0.67472654, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6302866977645043}}
{"text": "\\newpage\n\\section{Regular Expression $\\rarr$ Automaton}\n\n\\subsection{Thompson method}\nResult nondeterministic with $\\epsilon$-moves. Map every portion of the r.e. to a piece of the automaton. Every piece of the automaton must have a unique and final state.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{automata/thompson.png}\n\\end{figure}\n\n\\subsection{Berry-Sethi method}\n\nResult deterministic but can be non-minimal.\n\n\\subsubsection{Locally Testable Languages (LOC)}\n\nProper subfamily of REG. Assuming $a,b \\in \\Sigma$, $x, y \\in \\Sigma^*$, define $Ini(L) = \\{a | ax \\in L\\}$, $Fin(L) = \\{b | xb \\in L\\}$, $Dig(L) = \\{ab | xaby \\in L\\}$.\n\n\\begin{align*}\n    L \\in \\text{LOC} &\\iff \\\\\n    L \\setminus \\{\\epsilon\\} = \\{&x | Ini(x) \\in Ini(L) \\land \\\\\n    &Dig(x) \\subseteq Dig(L) \\land \\\\\n    &Fin(x) \\in Fin(L) \\}\n\\end{align*}\n\nTo prove that a language is not local provide a string $x\\notin L$ s.t. $Ini(x) \\in Ini(L) \\land Dig(x) \\subseteq Dig(L) \\land Fin(x) \\in Fin(L)$.\n\n\\subsubsection{Recognizer for Local Languages}\n\nA unique initial state $q_0$, a state for each terminal, the finals are the $Fin$. If $\\epsilon \\in L$ then also $q_0$ is final. $q_0$ is connected to the $Ini$, and the states are connected if the pair is in $Dig$.\n\n\\subsubsection{Local Automaton Condition}\nA deterministic automaton is \\emph{local} if it satisfies\n\\begin{equation*}\n    \\forall a \\in \\Sigma, | \\left\\{ \\delta(q, a) | q \\in Q \\right\\} | \\le 1\n\\end{equation*}\nInformally, each arc with the same terminal character ends in the same state.\n\nIf a language is recognized by a local automaton, the language is LOC.\n\n\\subsubsection{Berry-Sethi method}\n\nGiven $e$ the initial r.e., $e'$ is the numbered version over alphabet $\\Sigma_N$. Conside expression $e' \\dashv$. Define for each symbol $a$ of $e'$ the set $Fol(a) = \\{b | ab \\in Dig(e'\\dashv)\\}$.\n\nEvery state is a subset of $\\Sigma_N \\cup \\{\\dashv\\}$, containing all the symbols that may follow in the input. The initial state contains $Ini(e'\\dashv)$. The states are generated adding transitions until a fixed point is reached. The final states are the ones containing $\\dashv$.\n\n\\begin{algorithm*}[H]\n    \\caption{Berry-Sethi}\n    \\SetAlgoLined\n    $q_0 = Ini(e'\\dashv)$;\n    $Q = \\{q_0\\}$;\n    $\\delta=\\emptyset$\\;\n    \\While{$\\exists q \\in Q$ not visited}{\n        mark $q$ as visited\\;\n        \\For{$b \\in \\Sigma$}{\n            $q' = \\cup_{\\forall b_i \\in q} Fol(b_i)$\\;\n            \\If{$q' \\notin Q$}{\n                mark $q'$ as not visited\\;\n                $Q = Q \\cup \\{q'\\}$\n            }\n            $\\delta = \\delta \\cup \\{q \\xrightarrow{b} q'\\}$\n        }\n    }\n\\end{algorithm*}\n", "meta": {"hexsha": "49ad326936572981557586113d616fe9ba733fc0", "size": 2662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/reg-to-automaton.tex", "max_stars_repo_name": "Kakasinho/FLC-cheatsheet", "max_stars_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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/reg-to-automaton.tex", "max_issues_repo_name": "Kakasinho/FLC-cheatsheet", "max_issues_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "max_issues_repo_licenses": ["MIT"], "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/reg-to-automaton.tex", "max_forks_repo_name": "Kakasinho/FLC-cheatsheet", "max_forks_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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": 40.3333333333, "max_line_length": 282, "alphanum_fraction": 0.639744553, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6302866977645043}}
{"text": "% !TEX root = thesis.tex\n\\documentclass[thesis]{subfiles}\n\n\\begin{document}\n%*******************************************************************************\n%*********************************** Conclusion *****************************\n%*******************************************************************************\n\n\\chapter{Conclusion and Future Work}\n\\label{conclusion}\n%********************************** %First Section  **************************************\nIn this dissertation, we have proposed that carefully designing networks in consideration of our prior knowledge of the task can improve the memory and computational efficiency of state-of-the art networks, and even increase accuracy through structurally induced regularization. While this philosophy defines our approach, deep neural networks\\index{neural network} have a large number of degrees of freedom, and there are many facets of deep neural networks\\index{neural network} that warrant such analysis. We have attempted to present each of these in isolation:\n\n\\Cref{lowrankfilters} proposed to exploit our knowledge of the low-rank nature of most filters learned for natural images by structuring a deep network to learn a collection of mostly small 1$\\times$h and w$\\times$1 basis filters, while only learning a few full w$\\times$h filters. Our results showed similar or higher accuracy than conventional \\glspl{cnn}\\index{CNN} requiring much less computation. Applying our method to an improved version of VGG-11 network using \\gls{gmp}, we achieve comparable validation accuracy using 41\\% less computation and only 24\\% of the original VGG-11 model parameters; another variant of our method gives a 1 percentage point {\\em increase} in accuracy over our improved VGG-11 model, giving a top-5 \\emph{center-crop} validation accuracy of 89.7\\% while reducing computation by 16\\% relative to the original VGG-11 model. Applying our method to the GoogLeNet architecture for \\gls{ilsvrc}, we achieved comparable accuracy with 26\\% less computation and 41\\% fewer model parameters. Applying our method to a near state-of-the-art network for \\gls{cifar10}, we achieved comparable accuracy with 46\\% less computation and 55\\% fewer parameters. \n\t\n\\Cref{deeproots} addresses the filter/channel extents of convolutional filters, by learning filters with limited channel extents. When followed by a 1$\\times$1 convolution, these can also be interpreted as learning a set of basis filters, but in the channel extents. \nUnlike in \\cref{lowrankfilters}, the size of these channel-wise basis filters increased with the depth of the model, giving a novel sparse connection structure that resembles a tree root. This allows a significant reduction in computational cost and number of parameters of state-of-the-art deep \\glspl{cnn}\\index{CNN} without compromising accuracy. Our results showed similar or higher accuracy than the baseline architectures with much less computation, as measured by \\gls{cpu} and \\gls{gpu} timings. For example, for \\gls{resnet}\\index{ResNet} 50, our model has 40\\% fewer parameters, 45\\% fewer floating point operations, and is 31\\% (12\\%) faster on a \\gls{cpu} (\\gls{gpu}). For the deeper \\gls{resnet} 200 our model has 25\\% fewer floating point operations and 44\\% fewer parameters, while maintaining state-of-the-art accuracy. For GoogLeNet, our model has 7\\% fewer parameters and is 21\\% (16\\%) faster on a \\gls{cpu} (\\gls{gpu}).\n\n\\Cref{lowrankfilters,deeproots} proposed similar methods for reducing the computation and number of parameters in the spatial and channel (filter-wise) extents of convolutional filters respectively. Rather than approximating filters in previously-trained networks with more efficient versions, we learn a set of smaller basis filters from scratch; during training, the network learns to combine these basis filters into more complex filters that are discriminative for image classification. This means that at both training and test time our models are more efficient. Overall, the approach of learning a set of basis filters was not only effective for reducing both computation and model complexity (parameters), but in many of the results in both \\cref{lowrankfilters,deeproots}, the models trained with this approach generalized better than the original state-of-the-art models they were based on.\n\n\\Cref{conditionalnetworks} presented work towards conditional computation in deep neural networks\\index{neural network}. We proposed a new discriminative learning model, \\emph{conditional networks}, \nthat jointly exploits the accurate \\emph{representation learning} capabilities of deep neural networks\\index{neural network} with the efficient \\emph{conditional computation} of decision trees and directed acyclic graphs (DAGs). In addition to allowing for faster inference, conditional networks yield smaller models, and offer test-time flexibility in the trade-off of computation \\vs accuracy.\n\n%*******************************************************************************\n%*********************************** Future Work *****************************\n%*******************************************************************************\n\n\\section{Future Work}  %Title of the First Chapter\n\\label{futurework}\n\n%********************************** %First Section  **************************************\n\nResearch outcomes are often better evaluated by the questions borne rather than the questions answered. In this section we'll address the main research questions that this dissertation has highlighted, and propose future directions for research which we believe would have the most impact on the field.\n\n\\subsection{Learning Structural Priors}\nThe move towards ``end-to-end'' learning has made great strides in making learning more automatic, notably in learning complex representations rather than experts designing inferior representations themselves. There still exists however, a significant amount of hand design and manual tuning that is key to the success of any deep learning approach. We hope our work will motivate the field towards a research direction that aims to minimize this further, by working on methods of automatically structuring neural networks\\index{neural network}, in a move towards a truly ``end-to-end'' learning of \\gls{dnn} structure itself.\n\nThe lack of understanding or concrete rules for structuring \\glspl{dnn}\\index{DNN} means that in practical applications deep learning is often restricted to experts in the field, who have an intuition in network design formed from years of experience, and know which structural priors to use. The effect on deep learning research is no less profound, with a lack of understanding of the basic interplay between structure and learning in \\glspl{dnn}\\index{DNN}, we have little chance of understanding the limitations of deep learning or the representations learned by the networks. \n\nThe benefits of automatically structuring \\glspl{dnn}\\index{DNN} go further than these considerations even, as the research presented in this dissertation has shown, better structured \\glspl{dnn}\\index{DNN} are more computationally efficient (use fewer parameters and are faster to compute), and generalize better. Currently, training state-of-the-art \\glspl{dnn}\\index{DNN} for image classification requires a prohibitive amount of time and computational resources --- 3 weeks of training on 8 high-end and expensive \\glspl{gpu} --- and yet we know that trained \\glspl{dnn}\\index{DNN} are very sparse representations and have been shown to be highly compressible. It is because we cannot appropriately understand this sparse structure well enough to fully exploit it that our current \\glspl{dnn}\\index{DNN} are so inefficient.\n\nWith automatic methods of learning the structure, \\glspl{dnn}\\index{DNN} will become markedly more efficient to train, leading to faster experimental results for research, and also allow easier deployment to embedded devices, such as mobile phones, drones and robots. It would also allow for research strides in learning networks for multiple modalities, for example a self-driving car needs to process input data from normal camera sensors, along with depth maps or point clouds, and even radar. One of the stumbling blocks in doing this is understanding how to best structure a network to deal with multiple inputs which require different structural priors.\n\nResearch on finding automatic methods of structuring neural networks\\index{neural network} is not a completely new avenue of research, with a substantial effort put towards it 30 years ago when neural networks\\index{neural network}, and datasets, were much smaller. This is covered in \\cref{motivation}, but suffice to state that there were two main approaches:\n\\begin{enumerate*}[label= (\\textbf{\\roman*})]\n\t\\item greedily building networks from scratch, and \n\t\\item pruning (removing parameters) large networks\n\\end{enumerate*}. The proposals made for both building networks from scratch , such as that of \\citet{Fahlman1989}, and pruning full networks, such as that of \\citet{lecun1989optimal}, suffer drawbacks which make them unsuitable in the modern deep network of hundreds of millions of parameters. Even in neural networks\\index{neural network} of contemporary size, the greedy approach of \\citet{Fahlman1989} meant that learned networks were suboptimal. This proposal should also not be confused with `universal learning', or violating the no free lunch theorem (\\cref{nofreelunch}), since we are interested in learning methods for the specific set of problems we as humans are interested in solving, rather than all possible input patterns.\n\nAt least three factors prevented this line of research from being successful historically, that we believe have now been overcome. Recent breakthroughs in training \\glspl{dnn}\\index{DNN} have given us a better understanding of how to train very large, arbitrarily structured networks, notably avoiding the so-called `vanishing gradient'~\\citep{Ioffe2015,He2016}, and a better understanding of initialization~\\citep{He2015b}. Extremely large and diverse datasets are now prevalent, such as ImageNet~\\citep{ILSVRC2015}, whereas historically datasets were prohibitively small to be useful for automatically structuring \\glspl{dnn}\\index{DNN}. And finally computational resources have increased dramatically. In fact these are most of the reasons the field of deep learning itself has been more successful now than neural networks\\index{neural network} were 30 years ago.\n\n\\subsection[Jointly Learning a Basis for Spatial and Channel Extents of Filters]{Jointly Learning a Basis for Spatial and\\texorpdfstring{\\\\}{ }Channel Extents of Filters}\n\\label{journalplan}\nIn the shorter term, there is an obvious question arising from the work presented in \\cref{lowrankfilters,deeproots} that explore learning more efficiently by reducing the learned parameters in the spatial and channel extents of convolutional filters respectively. These naturally lend themselves to being merged into a single effective method for training with low-rank basis filters. We plan to submit a journal article in which both methods are merged and explored in new results on state-of-the-art \\glspl{dnn}\\index{DNN}.\n\n\\subsection{Optimization and Structural Priors}\\label{optimizationlink}\nIt is notable that many structural priors can be viewed as enforcing sparsity on fully-connected networks. For example, in the case of a \\gls{cnn}, any learned \\gls{cnn} is representable in a fully-connected network, since a \\gls{cnn} can be viewed as a fully-connected network with a specific arrangement of zeroed connect weights, and some duplicated weights (shared weights) as illustrated in \\cref{fig:sparseconn}. \n\nThe question arises then, why can we not learn these in fully-connected networks? Structural priors give lower training loss, and yet when we optimize fully-connected networks with an appropriate structure and capacity to learn the sparse structural priors, they do not. Another, more recent example, is that of \\glspl{resnet}, as explained in \\cref{residualnetworks}, these are motivated by the observation that in very deep networks the optimization fails to learn even the identity function, when it can be shown to give a lower loss.\n\nIn many ways the need for structural priors can be seen as the result of a problem with the current methods of optimization of \\glspl{dnn}. As discussed in \\cref{pathological}, higher order optimization might help solve this, but is not practical given the size of contemporary \\glspl{dnn}. \n\n\\subsection{Parting Note}\nIn my PhD, I have focused on experiments which I believed would shed light on the representations being learned in \\glspl{dnn}\\index{DNN}. Although the overt motivation of much of the work in its publication has been efficiency, my personal motivation has always been to better understand the learned internal representation of state-of-the-art \\glspl{dnn}\\index{DNN} for image classification, and explain why they are so over-parameterized. Structural priors, such as those demonstrated in this dissertation do not only improve the effectiveness of a deep network, but are \\emph{necessary} for good generalization.\n\\end{document}\n", "meta": {"hexsha": "dd7e28175f8127908d552d92377593fdb73be7fa", "size": 13194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conclusion.tex", "max_stars_repo_name": "yanii/phd-thesis", "max_stars_repo_head_hexsha": "8d21690458f77c0cfefcb6ba528d421a83408b0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-02-16T21:51:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T08:47:40.000Z", "max_issues_repo_path": "conclusion.tex", "max_issues_repo_name": "yanii/phd-thesis", "max_issues_repo_head_hexsha": "8d21690458f77c0cfefcb6ba528d421a83408b0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conclusion.tex", "max_forks_repo_name": "yanii/phd-thesis", "max_forks_repo_head_hexsha": "8d21690458f77c0cfefcb6ba528d421a83408b0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-02-16T21:52:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-03T09:19:46.000Z", "avg_line_length": 199.9090909091, "max_line_length": 1179, "alphanum_fraction": 0.7722449598, "num_tokens": 2752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6302866822887406}}
{"text": "\\subsection{Derivatives of Inverse Trigonometric Functions}\n\nWe can apply the technique used to find the derivative of $f^{-1}$ above to find the derivatives of the inverse trigonometric functions.\n\nIn the following examples we will derive the formulae for the derivative of the inverse sine, inverse cosine and inverse tangent. The other three inverse trigonometric functions have been left as exercises at the end of this section.\n\n\\begin{example}{Derivative of Inverse Sine}{DerInvSine}\nFind the derivative of $\\sin^{-1}(x)$.\n\\end{example}\n\\begin{solution}\n Adopting the notation in Theorem \\ref{thm:deriv_inverse_functions}, let $g(x) = \\arcsin x$ and $f(x) = \\sin x$. Thus $\\fp(x) = \\cos x$. Applying the theorem, we have \n\t\t\t\\begin{align*}\n\t\t\tg\\primeskip'(x) &= \\frac{1}{\\fp(g(x))} \\\\\n\t\t\t\t\t\t&= \\frac{1}{\\cos(\\arcsin x)}.\n\t\t\t\\end{align*}\n\t\t\t\nAlternatively, we could use the technique in the justification of Theorem \\ref{thm:deriv_inverse_functions}. Write $y=\\sin^{-1}(x)$, so $x=\\sin(y)$ and $-\\pi/2\\leq y\\leq \\pi/2$, and differentiate both sides with respect to $x$ using the chain rule.\n\\begin{align*}\n\\ds\\frac{d}{dx}x&=\\frac{d}{dx}\\sin(y)\t\\\\\n1&=\\cos(y)\\frac{dy}{dx}\t\\\\\n1&=\\cos\\left(\\sin^{-1}(x)\\right)\\frac{dy}{dx}\t\\\\\n\\frac{dy}{dx}&=\\frac{1}{\\cos\\left(\\sin^{-1}(x)\\right)}\n\\end{align*}\n\nAlthough correct, this formula is cumbersome to use, and hardly enlightening. It can be simplified significantly with a bit of trigonometry. We have   $y =\\sin^{-1}(x)$, so $\\sin(\\theta)=x$, and we wish to find $ \\cos(y) $ in order to simplify our expression above. Construct a right angle triangle with angle $y$, opposite side length $x$ and hypotenuse $ 1 $.  The Pythagorean  Theorem gives an adjacent side length of $\\sqrt{1-x^2}$.\n\n\n\\begin{figure}\n\\centering\n\\begin{tikzpicture}[thick]\n\\draw(0,0) -- (90:2cm) node[midway,left]{$x$} -- (0:4cm) node[midway,above right]{{$1$}} -- (0,0);\n\n\\node at (2,-.5) {{$\\sqrt{1-x^2}$}};\n\n%\\draw[fill=lightgray, thick] (0,0) -- (0:0.8cm) arc (0:90:0.8cm) node at (45:0.5cm) {$\\gamma$} -- cycle;\n\\draw[fill=lightgray, thick] (4,0) -- ++(180:0.8cm) arc (180:180-atan2(4,2):0.8cm) node at ($(167:0.6cm)+(4,0)$) {$y$} -- cycle;\n%\\draw[fill=lightgray, thick] (0,2) -- ++(-90:0.8cm) arc (-90:-90+atan2(2,4):0.8cm) node at ($(-60:0.5cm)+(0,2)$) {$\\beta$} -- cycle;\n\\end{tikzpicture}\n\n\\caption{\\label{fig:inverse3}A right triangle defined by $y=\\sin ^{-1}(\\frac{x}{1})$ with the length of the third leg found using the Pythagorean Theorem.}\n\\end{figure}\n\n\nSo, reading from the triangle we have $\\cos\\left(\\sin^{-1}(x)\\right)=\\cos(y)=\\sqrt{1-x^2}$. Note that we choose the non-negative square root $\\sqrt{1-x^2}$ since $\\cos(\\theta)\\geq 0$ when $-\\pi/2\\leq\\theta\\leq\\pi/2$ (the range of $ \\arcsin(x) $).\n\nFinally, the derivative of inverse sine is\n\\[\\left(\\sin^{-1}(x)\\right)'=\\frac{1}{\\sqrt{1-x^2}}\\]\n\\end{solution}\n\n\\begin{example}{Derivative of Inverse Cosine}{DerInvCosine}\nFind the derivative of $\\cos^{-1}(x)$.\n\\end{example}\n\\begin{solution}\nLet $y=\\cos^{-1}(x)$, so $\\cos(y)=x$ and $0\\leq y\\leq \\pi$. Next we differentiate implicitly:\n\\begin{align*}\n\\frac{d}{dx}\\left(\\cos y\\right)&=\\frac{d}{dx}\\left(x\\right)\t\\\\\n-\\sin y\\cdot\\frac{dy}{dx}&=1\t\\\\\n\\frac{dy}{dx}&=-\\frac{1}{\\sin y}\n\\end{align*}\n\n Since $\\cos y=x$, we construct a triangle with angle $y$, adjacent side length $x$ and hypotenuse $1$. \n \n \\begin{figure}\n \\centering\n \\begin{tikzpicture}[thick]\n \\draw(0,0) -- (90:2cm) node[midway,left]{$\\sqrt{1-x^2}$} -- (0:4cm) node[midway,above right]{{$1$}} -- (0,0);\n \n \\node at (2,-.5){$x$} ;\n \n %\\draw[fill=lightgray, thick] (0,0) -- (0:0.8cm) arc (0:90:0.8cm) node at (45:0.5cm) {$\\gamma$} -- cycle;\n \\draw[fill=lightgray, thick] (4,0) -- ++(180:0.8cm) arc (180:180-atan2(4,2):0.8cm) node at ($(167:0.6cm)+(4,0)$) {$y$} -- cycle;\n %\\draw[fill=lightgray, thick] (0,2) -- ++(-90:0.8cm) arc (-90:-90+atan2(2,4):0.8cm) node at ($(-60:0.5cm)+(0,2)$) {$\\beta$} -- cycle;\n \\end{tikzpicture}\n \n \\caption{\\label{fig:inverse3}A right triangle defined by $y=\\cos ^{-1}(\\frac{x}{1})$ with the length of the third leg found using the Pythagorean Theorem.}\n \\end{figure}\n \n \n Solving for the opposite side length using Pythagorean Theorem we obtain $\\sqrt{1-x^2}$. Using this triangle we can see that $\\sin y=\\sqrt{1-x^2}$ ($0\\leq y\\leq \\pi$). Substituting this into the equation for $dy/dx$, we find that\n\\[\\frac{d}{dx}\\left(y\\right)=\\frac{d}{dx}\\left(\\cos^{-1}(x)\\right)=\\frac{-1}{\\sqrt{1-x^2}}\\].\n\\end{solution}\n\nIn the following example we explore an alternate method of finding the derivative.\n\n\\begin{example}{Derivative of Inverse Tangent}{DerInvTangent}\nFind the derivative of $\\tan^{-1}(x)$.\n\\end{example}\n\\begin{solution}\nWe begin with $\\tan\\left(\\tan^{-1}(x)\\right)=x$. Taking the derivative using the Chain Rule we obtain\n\\[\\sec^2\\left(\\tan^{-1}(x)\\right)\\cdot\\frac{d}{dx}\\left(\\tan^{-1}(x)\\right)=1,\\]\nwhich we rearrange to obtain\n\\[\\frac{d}{dx}\\left(\\tan^{-1}(x)\\right)=\\frac{1}{\\sec^2\\left(\\tan^{-1}(x)\\right)}.\\]\n\nLet $\\tan^{-1}(x)=\\theta$, then $\\tan(\\theta)=x$. We construct a triangle with angle $\\theta$, adjacent side $1$ and opposite side $x$. The hypotenuse is $\\sqrt{1+x^2}$ using Pythagorean theorem.\n\n \\begin{figure}\n \\centering\n \\begin{tikzpicture}[thick]\n \\draw(0,0) -- (90:2cm) node[midway,left]{$x$} -- (0:4cm) node[midway,above right]{{$\\sqrt{1+x^2}$}} -- (0,0);\n \n \\node at (2,-.5){$1$} ;\n \n %\\draw[fill=lightgray, thick] (0,0) -- (0:0.8cm) arc (0:90:0.8cm) node at (45:0.5cm) {$\\gamma$} -- cycle;\n \\draw[fill=lightgray, thick] (4,0) -- ++(180:0.8cm) arc (180:180-atan2(4,2):0.8cm) node at ($(167:0.6cm)+(4,0)$) {$\\theta$} -- cycle;\n %\\draw[fill=lightgray, thick] (0,2) -- ++(-90:0.8cm) arc (-90:-90+atan2(2,4):0.8cm) node at ($(-60:0.5cm)+(0,2)$) {$\\beta$} -- cycle;\n \\end{tikzpicture}\n \n \\caption{\\label{fig:inverse3}A right triangle defined by $\\theta=\\tan ^{-1}(\\frac{x}{1})$ with the length of the third leg found using the Pythagorean Theorem.}\n \\end{figure}\n\n Then $\\sec^2\\left(\\tan^{-1}(x)\\right)=\\sec^2(\\theta)=\\left(\\sec(\\theta)\\right)^2=\\left(\\sqrt{1+x^2}\\right)^2=1+x^2$. Recall that $\\sec(x)=1/\\cos(x)$. Finally, the derivative is\n\\[\\frac{d}{dx}\\left(\\tan^{-1}(x)\\right)=\\frac{1}{1+x^2}.\\]\n\\end{solution}\n\n\n\n\nUsing similar techniques, we can find the derivatives of the remaining inverse trigonometric functions.\\\\\n\n\\begin{theorem}{Derivatives of Inverse Trigonometric Functions}{deriv_inverse_trig}\n{The inverse trigonometric functions are differentiable on all open sets contained in their domains (as listed in Figure \\ref{fig:domain_trig}) and their derivatives are as follows:\\\\\n\n\\noindent\t\\begin{minipage}{.5\\textwidth}\\small\n\t\\begin{enumerate}\n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\sin^{-1}(x)\\big) = \\frac{1}{\\sqrt{1-x^2}}$ \n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\sec^{-1}(x)\\big) = \\frac{1}{ x \\sqrt{x^2-1}}$\n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\tan^{-1}(x)\\big) = \\frac{1}{1+x^2}$\n\t\\end{enumerate}\n\t\\end{minipage}\n\t\\begin{minipage}{.5\\textwidth}\\small\n\t\\begin{enumerate}\\addtocounter{enumi}{3}\n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\cos^{-1}(x)\\big) = -\\frac{1}{\\sqrt{1-x^2}}$ \n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\csc^{-1}(x)\\big) = -\\frac{1}{ x \\sqrt{x^2-1}}$\n\t\\item\t\t$\\ds \\frac{d}{dx}\\big(\\cot^{-1}(x)\\big) = -\\frac{1}{1+x^2}$\n\t\\end{enumerate}\\index{derivative!inverse trig.}\n\t\\normalsize\n\t\\end{minipage}\n}\t\t\t\n\n\n\\end{theorem}\n\nNote how the last three derivatives are merely the opposites of the first three, respectively. Because of this, the first three are used almost exclusively throughout this text.\\\\\n\n\n\\subsection{Glossary of Derivatives of Elementary Functions}\n\nIn this chapter we have defined the derivative, given rules to facilitate its computation, and given the derivatives of a number of standard functions. We restate the most important of these in the following theorem, intended to be a reference for further work.\n\n\\begin{theorem}{Glossary of Derivatives of Elementary Functions}{deriv_glossary}\nLet $u$ and $v$ be differentiable functions, and let $a$, $c$ and $n$ be real numbers, $a>0$, $n\\neq 0$. \\\\\n\\noindent%\n\n\t\\begin{minipage}{.5\\textwidth}\n\t\\begin{enumerate}\n\t\\item\t\t$\\frac{d}{dx}\\big(cu\\big) = cu'$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(u\\cdot v\\big) = uv'+u'v$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(u(v)\\big) = u'(v)v'$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(x\\big) = 1$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(e^x\\big) = e^x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\ln x\\big) = \\frac{1}{x}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\sin x\\big) = \\cos x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\csc x\\big) = -\\csc x\\cot x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\tan x\\big) = \\sec^2x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\sin^{-1}x\\big) = \\frac{1}{\\sqrt{1-x^2}}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\csc^{-1}x\\big) = -\\frac{1}{|x|\\sqrt{x^2-1}}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\tan^{-1}x\\big) = \\frac{1}{1+x^2}$\\addtocounter{enumi}{1}\n\t\\end{enumerate}\n%\\normalsize\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\t\\begin{enumerate}\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(u\\pm v\\big) = u'\\pm v'$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\frac uv\\big) = \\frac{u'v-uv'}{v^2}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(c\\big) = 0$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(x^n\\big) = nx^{n-1}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(a^x\\big) = \\ln a\\cdot a^x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\log_a x\\big) = \\frac{1}{\\ln a}\\cdot\\frac{1}{x}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\cos x\\big) = -\\sin x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\sec x\\big) = \\sec x\\tan x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\cot x\\big) = -\\csc^2x$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\cos^{-1}x\\big) = -\\frac{1}{\\sqrt{1-x^2}}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\sec^{-1}x\\big) = \\frac{1}{|x|\\sqrt{x^2-1}}$\\addtocounter{enumi}{1}\n\t\\item\t\t$\\frac{d}{dx}\\big(\\cot^{-1}x\\big) = -\\frac{1}{1+x^2}$\n\t\\end{enumerate}\n\\normalsize\n\\end{minipage}\n\n\\end{theorem}\n", "meta": {"hexsha": "3203d5ed861d2074c92906266e5842520660b0ec", "size": 10044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-9-1-der-inv-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-9-1-der-inv-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-9-1-der-inv-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": 52.8631578947, "max_line_length": 436, "alphanum_fraction": 0.6479490243, "num_tokens": 3898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.6301825160718436}}
{"text": "\\section*{Rotations and Transformations in 2D Space}\n\nA typical undergraduate linear algebra course will discuss the concept of\nlinear transformations. Usually rotations are referenced as one of many kinds\nof linear transformations. When dealing with physical reference frames in\npractical engineering, reference frames \\textit{only} undergo rotational\ntransformations (usually). It's tempting, then, to think of the terms\n``rotation' and ``transformation'' as being synonymous. However, when dealing\nwith physical objects rotating in space, especially in aerospace engineering,\nthese terms are \\textit{not} usually synonymous. Here's the short of it:\n\n\\begin{itemize}\n\\item \\textbf{Rotation} refers to rotating a vector within a single stationary\n  frame. This is also referred to as the ``active'' or ``alibi'' interpretation\n  of rotations.\n\n\\item \\textbf{Transformation} refers to transforming one reference frame\n  \\textit{into} another frame. Any physical vectors in space \\textit{do not}\n  move with this ``passive'' or ``alias'' interpretation. Instead, the numbers\n  denoting the vectors' components change to reflect the vectors' positions in\n  the new frame.\n\\end{itemize}\n\nLet's use the figure below for a visual example. We have two 2-dimensional\nframes, labeled A and B. Each frame has two orthonormal basis vectors (that\nmeans the two vectors are orthogonal to each other and have a length of 1,\nand that every vector in the 2-dimensional plane can be defined as a sum\nof some multiple of those two vectors) labeled $\\hat{\\bm{e}}_1$ and\n$\\hat{\\bm{e}}_2$.\n\n\\begin{figure*}[h!]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{img/Two_2D_Frames.png}\n\\end{figure*}\n\nThere is also a vector, labeled $\\bm{v}$. Looking between the two\nframes, we see that $\\bm{v}$ isn't moving in space. So the vector\n$\\bm{v}$ itself is some object in space with a magnitude and direction\nthat is independent of any reference frames. But the \\textit{components} of\n$\\bm{v}$, which \\textit{measure} its magnitude and direction with respect to\nsome set of basis vectors, \\textit{are} dependent on the set of basis vectors.\n\nConsider the components of $\\bm{v}$ ``resolved'' in Frame A versus Frame B:\n\\begin{equation*}\n    \\bm{v}_A = \\begin{bmatrix}\n        -1 \\\\\n        0\n    \\end{bmatrix}\n    \\quad\\quad\\quad\\quad\n    \\bm{v}_B = \\begin{bmatrix}\n        -\\cos(\\pi/4) \\\\\n        \\sin(\\pi/4)\n    \\end{bmatrix}\n\\end{equation*}\n\nThe components of $\\bm{v}$ change when resolved (measured) with respect to\ndifferent basis vectors (different frames), but the \\textit{actual} vector\nis stationary in space.\n\nConsider the matrix that rotates Frame A into Frame B (i.e. it rotates the\nbasis vectors of Frame A by $45^\\circ$ anti-clockwise):\n\\begin{equation*}\n    R_{A \\to B} = \\begin{bmatrix}\n        \\cos(\\pi/4) & -\\sin(\\pi/4) \\\\\n        \\sin(\\pi/4) & \\cos(\\pi/4)\n    \\end{bmatrix}\n\\end{equation*}\n\n\\textit{However}, applying this matrix to the vector $\\bm{v}_A$, we do not\nget $\\bm{v}_B$:\n\\begin{equation*}\n    \\begin{bmatrix}\n        \\cos(\\pi/4) & -\\sin(\\pi/4) \\\\\n        \\sin(\\pi/4) & \\cos(\\pi/4)\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        -1 \\\\\n        0\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        -\\cos(\\pi/4) \\\\\n        -\\sin(\\pi/4)\n    \\end{bmatrix}\n    \\neq\n    \\bm{v}_B\n\\end{equation*}\n\nThis disparity is because we applied a \\textit{rotation} matrix to $\\bm{v}_A$,\nwhich one can think of as a function which takes as input the components of\na vector in some reference frame, rotates the vector, and outputs the components\nof the rotated vector within that same frame. Effectively, applying\n$R_{A \\to B}$ to $\\bm{v}_A$ is the equivalent of computing\n\n\\begin{figure*}[h!]\n    \\centering\n    \\includegraphics[width=\\textwidth]{img/Incorrect Rotation of v.png}\n\\end{figure*}\n\nYou might have noticed, though, that the position of $\\bm{v}$ relative to the\nbasis vectors of Frame B is identical to the position of $\\bm{v}$ relative to\nthe basis vectors of Frame A \\textit{had the opposite of $R_{A \\to B}$ been\napplied to it}. Visually:\n\n\\begin{figure*}[h!]\n    \\centering\n    \\includegraphics[width=0.75\\textwidth]{img/Opposite Relative Rotation.png}\n\\end{figure*}\n\nTherefore, if we want to find the components of $\\bm{v}$ in Frame B, given\nits components in Frame A ($\\bm{b}_A$) and the rotation matrix from Frame A\nto Frame B ($R_{A \\to B}$), we must apply the opposite of the rotation matrix:\n$\\bm{v}_B = -R_{A \\to B} \\, \\bm{v}_A$. However, this notation seems strange,\nsince we are applying a matrix designed to represent a rotation of a vector\nwithin a frame to a situation in which a vector is not moving in space.\nConventionally, we tend to define a \\textit{transformation} matrix which\ntransforms the components of a vector from one frame to another. In our case,\nwe can define the matrix $T_A^B = -R_{A \\to B}$. The difference in the notation\nbetween rotation and transformation matrix symbols doesn't appear to be\nuniversally used, but it is useful for distinguishing the two when defined.\n\nIn summary,\n\\begin{itemize}\n    \\item Frames in 2D space require two basis vectors. Conventionally these\n          basis vectors are orthonormal.\n    \\item Vectors are physical objects with a direction and magnitude.\n    \\item A vector's direction and magnitude can be \\textit{measured}\n          (or ``resolved'') with respect to the basis vectors of a frame,\n          giving numerical values to its components.\n    \\item In applications where a physical object represented by a vector is\n          moving within a single frame (e.g. a robotic arm on a factory line\n          moving through a single frame), a rotation matrix aptly describes\n          the motion.\n    \\item In applications where a physical object represented by a vector is\n          \\textit{not} moving, but rather the engineer wants to know its\n          components in with respect to multiple frames, a transformation\n          matrix aptly converts the components from one frame to another.\n    \\item Given the rotation matrix which rotates the basis vectors of one\n          frame to another, the transformation matrix which transforms a\n          vector's components from the first frame to the second is the\n          negative of said rotation matrix.\n\\end{itemize}", "meta": {"hexsha": "9be543778ef3727799339a4b38706be957fd3252", "size": 6249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper_src/src/rotations_versus_transformations.tex", "max_stars_repo_name": "mdbernard/quaternions", "max_stars_repo_head_hexsha": "8ac3efac315359c6d0e89f7bd765939ee6c98292", "max_stars_repo_licenses": ["MIT"], "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_src/src/rotations_versus_transformations.tex", "max_issues_repo_name": "mdbernard/quaternions", "max_issues_repo_head_hexsha": "8ac3efac315359c6d0e89f7bd765939ee6c98292", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2021-08-05T01:21:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-05T01:43:33.000Z", "max_forks_repo_path": "paper_src/src/rotations_versus_transformations.tex", "max_forks_repo_name": "mdbernard/quaternions", "max_forks_repo_head_hexsha": "8ac3efac315359c6d0e89f7bd765939ee6c98292", "max_forks_repo_licenses": ["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.0070422535, "max_line_length": 80, "alphanum_fraction": 0.7162746039, "num_tokens": 1655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.6301825103612383}}
{"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 5: Parametric Equations}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Equations of Lines in Space}\n\nFrom previous lecture, we see that a line can be represented as the intersection \nof two planes. However, as equations it is not so easy to use because we need to \nsolve it first.\n\nAnother representation is to treat a line as the trajectory of a moving point, \nand include a parameter in the equation to describe different positions in the \nline. Such representation is called \\textbf{parametric equations}.\n\n\\begin{example}\n  Find the parametric equation of the line through $Q_0 = (-1, 2, 2)$ and \n  $Q_1 = (1, 3, -1)$.\n\n  Given that the line can be the trajectory of a moving point, the parameter in \n  the equation could be the time $t$. Suppose that at $t = 0$, the moving point \n  is in $Q_0$, and at $t = 1$, the moving point is in $Q_1$, and suppose the \n  point moves at a constant speed.\n\n  With parametric equations, the coordinates of the point $Q$ in the line are \n  functions of the parameter. Therefore, $Q = (x(t), y(t), z(t))$. The point $Q$ \n  in the line also satisfies the following equation:\n  \\[\n    \\vec{Q_0Q} = t \\cdot \\vec{Q_0Q_1}\n  \\]\n  \\[\n    <x + 1, y - 2, z - 2> = t \\cdot <2, 1, -3>\n  \\]\n  \\[\n    \\left\\{ \\begin{array}{ll}\n    x(t) = 2t - 1 \\\\\n    y(t) = t + 2 \\\\\n    z(t) = -3t + 2 \\\\\n    \\end{array} \\right.\n  \\]\n  That is the parametric equation of the described line.\n\\end{example}\n\nNotice that the coefficients of the parameter are components of a vector with \nthe same direction as the line (either one of the two directions a line has). \nThe constant terms in the parametric equation are coordinates of the point when \nthe parameter is equal to 0.\n\nA line can have infinite different parametric equations. With different time \nassumption and speed, the coefficients can be different, but they all express \nthe same line.\n\nThe reason why the parametric equation of a line only has one parameter is that \nthe points on a line only have one dimension (degree of freedom). It doesn't \nmatter whether it is a line or a curve.\n\n\\begin{example}\n  Consider the plane $x + 2y + 4z = 7$, and two points $Q_0 = (-1, 2, 2)$ and \n  $Q_1 = (1, 3, -1)$.\n\n  1) Whether $Q_0$ and $Q_1$ are \\underline{B}. \\\\\n  A. on the same side. \\\\\n  B. on the opposite sides. \\\\\n  C. on the plane. \\\\\n  D. cannot be decided.\n\n  Reasons: \\\\\n  For $Q_0 = (-1, 2, 2)$, $x + 2y + 4z = 11$. Therefore, $Q_0$ is in the plane \n  $P_0$ whose equation is $x + 2y + 4z = 11$. \\\\\n  For $Q_1 = (1, 3, -1)$, $x + 2y + 4z = 3$. Therefore, $Q_1$ is in the plane \n  $P_1$ whose equation is $x + 2y + 4z = 3$. \\\\\n  Assume the plane with the equation $x + 2y + 4z = 7$ is called $P$. \\\\\n  The intersection point of these three planes with the $z$ axis are \n  $(0, 0, \\frac{11}{4})$, $(0, 0, \\frac{3}{4})$, and $(0, 0, \\frac{7}{4})$ \n  respectively, among which the intersection point of the plane $P$ are in \n  between the ones of other two planes. \\\\\n  Since the planes $P$, $P_0$, and $P_1$ are all parallel to each other, $P$ is \n  in between other two planes. Hence, $P$ is in between $Q_0$ and $Q_1$. \n  Therefore, $Q_0$ and $Q_1$ are on the opposite sides of the plane \n  $x + 2y + 4z = 7$.\n\n  \\bigskip\n\n  2) Does the line through $Q_0$ and $Q_1$ pass through the plane? If so, what \n  is the intersection point?\n\n  According to the previous example, we know that the parametric equation of the \n  line is:\n  \\[\n    \\left\\{ \\begin{array}{ll}\n    x(t) = 2t - 1 \\\\\n    y(t) = t + 2 \\\\\n    z(t) = -3t + 2 \\\\\n    \\end{array} \\right.\n  \\]\n  For the intersection point, the following equation holds:\n  \\[\n    x(t) + 2y(t) + 4z(t) = 7\n  \\]\n  \\[\n    (2t - 1) + 2(t + 2) + 4(-3t + 2) = 7\n  \\]\n  \\[\n    -8t + 11 = 7\n  \\]\n  \\[\n    t = \\frac{1}{2}\n  \\]\n  Therefore, the intersection point $Q = (0, \\frac{5}{2}, \\frac{1}{2})$.\n\n  Notice that the coefficient of the parameter for the intersection point is \n  the dot product of the direction of the line and the normal vector of the \n  plane. If the coefficient is 0, from geometric point of view it means the \n  direction of the line is perpendicular to the normal vector of the plane, \n  which means the line is parallel to the plane; from algebraic point of view, \n  the equation of the intersection point either always holds or has no \n  solution, which also means the line is parallel to the plane.\n\n\\end{example}\n\n\\section{General Usage of Parametric Equations}\n\nMore generally, we can use parametric equations for arbitrary trajectory in \nthe plane or space.\n\n\\begin{example}\n  Find the parametric equation of a cycloid, which is the curve traced by a \n  fixed point on a circle as it rolls along a straight line without slipping.\n\n  Solution:\n\n  In this case, there is a natural parameter which is the angle $\\theta$ the \n  circle has rolled, because the position of the fixed point is solely decided \n  by the angle. Suppose the start point of the circle is when the intersection \n  between the circle and the $x$ axis is the origin $O$, which is also the \n  tracing point. After rolling an angle $\\theta$, the fix point is at position \n  $B$, and the current intersection point is $A$. The center of the circle is \n  $C$, and its radius is $a$.\n\n  To find the parametric equation of the cycloid, we need to find the \n  parametric equation of $\\vec{OB}$.\n  \\[\n    \\vec{OB} = \\vec{OA} + \\vec{AC} + \\vec{CB}\n  \\]\n  Since the circle rolls along the $x$ axis without slipping,\n  \\[\n    \\vec{OA} = <a\\theta, 0>\n  \\]\n  Since $\\vec{AC}$ is always perpendicular to the $x$ axis and the magnitude \n  is the radius of the circle,\n  \\[\n    \\vec{AC} = <0, a>\n  \\]\n  We can decompose $\\vec{CB}$ into horizontal and vertical directions,\n  \\[\n    \\vec{CB} = <-a\\sin\\theta, -a\\cos\\theta>\n  \\]\n  Notice that we can verify that the equations of the three vectors hold for \n  any $\\theta$, not only in $[0, 2\\pi]$. Therefore,\n  \\[\n    \\begin{split}\n    \\vec{OB} &= \\vec{OA} + \\vec{AC} + \\vec{CB} \\\\\n             &= <a\\theta - a\\sin\\theta, a - a\\cos\\theta> \\\\\n    \\end{split}\n  \\]\n  Therefore, the parametric equation of a cycloid is\n  \\[\n    \\left\\{ \\begin{array}{ll}\n    x(t) = a\\theta - a\\sin\\theta \\\\\n    y(t) = a - a\\cos\\theta \\\\\n    \\end{array} \\right.\n  \\]\n\n  \\bigskip\n\n  Following: What does the curve look like between two humps, i.e. around \n  $\\theta = 2n\\pi$?\n\n  To figure it out, we need to look at the derivative $\\frac{dy}{dx}$ around \n  $\\theta = 2n\\pi$.\n  \\[\n    \\begin{split}\n      \\frac{dy}{dx}|_{\\theta = 2n\\pi} &= (\\frac{dy}{d\\theta} / \\frac{dx}{d\\theta})|_{\\theta = 2n\\pi} \\\\\n                                      &= (\\frac{d(a - a\\cos\\theta)}{d\\theta} / \\frac{d(a\\theta - a\\sin\\theta)}{d\\theta})|_{\\theta = 2n\\pi} \\\\\n                                      &= \\frac{a\\sin\\theta}{a - a\\cos\\theta}|_{\\theta = 2n\\pi} \\\\\n                                      &= \\frac{0}{0} \\\\\n    \\end{split}\n  \\]\n  According to L'Hospital rule,\n  \\[\n    \\begin{split}\n      \\frac{dy}{dx}|_{\\theta = 2n\\pi} &= \\frac{a\\sin\\theta}{a - a\\cos\\theta}|_{\\theta = 2n\\pi} \\\\\n                                      &= (\\frac{d(a\\sin\\theta)}{d\\theta} / \\frac{d(a - a\\cos\\theta)}{d\\theta})|_{\\theta = 2n\\pi} \\\\\n                                      &= \\frac{a\\cos\\theta}{a\\sin\\theta}|_{\\theta = 2n\\pi} \\\\\n                                      &= \\frac{a}{0} \\\\\n                                      &= \\infty\n    \\end{split}\n  \\]\n  Therefore, the slope of a cycloid between two humps, i.e. around \n  $\\theta = 2n\\pi$, is infinity, which means the tangent line in the \n  intersection of two humps is vertical, perpendicular to the $x$ axis.\n\\end{example}\n \n\\end{document}", "meta": {"hexsha": "a8072c14d3b847fe2e531561e9125d2e8e4fcfb2", "size": 7992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture5.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": "lecture5.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": "lecture5.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": 35.8385650224, "max_line_length": 141, "alphanum_fraction": 0.6283783784, "num_tokens": 2556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.6300383108107117}}
{"text": "\\section{Refinement \\& Verification}\n\n\\begin{itemize}\n\t\n\t\\item Specification statement: $ w : [P, Q] $\n\t\n\t\\item $ P $ is the precondition, $ Q $ is the postcondition, $ w $ is the `frame' of variables that may be modified\n\t\n\t\\item A program $ C $ satisfies $ w : [P, Q] $ if and only if\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ \\hoare{P}{C}{Q} $\n\t\t\n\t\t\\item $ C $ only changes variables in $ w $\n\t\t\n\t\\end{itemize}\n\n\t\\item If $ P $ is not true when $ C $ is executed it may do anything, and it need not terminate\n\t\n\t\\item Mixing specification statements with GCL forms a `wide-spectrum language'\n\t\n\t\\item Refinement ($ \\refsto $) -- a partial ordering on programs (similar to $ \\le $ for reals)\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ S \\refsto S' $ means a user expecting program $ S $ would be satisfied with $ S' $\n\t\t\n\t\t\\item $ S \\refsto S' \\iff \\forall Q \\cdot wp(S, Q) \\entails wp(S', Q) $\n\t\t\n\t\t\\item For a specification: $ wp(x : [P, Q], Q') \\defeq P \\land (\\forall x \\cdot Q \\implies Q')[v_0 \\backslash v] $\n\t\t\n\t\\end{itemize}\n\n\t\\item General approach to refining a program\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Start with a specification $ S = w : [P, Q] $\n\t\t\n\t\t\\item Use rules to replace $ S $ with $ S' $ mixing specifications with GCL\n\t\t\n\t\t\\item Each rule must preserve correctness -- i.e. every program $ C $ that satisfies $ S' $ must satisfy $ S $\n\t\t\n\t\t\\item Eventually arrive at a pure GCL program $ C $ such that $ \\hoare{P}{C}{Q} \\equiv \\true $\n\t\t\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n\\newpage\n\n\\subsection{Refinement Rules}\n\n\\begin{itemize}\n\t\n\t\\item Rule 1: \\textbf{Strengthen Postcondition}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P[w \\backslash w_0] \\land Q' \\entails Q $ then $ w : [P, Q] \\refsto w : [P, Q'] $ ($ P[w \\backslash w_0] $ usually not needed)\n\t\t\n\t\\end{itemize}\n\t\n\t\\item Rule 2: \\textbf{Weaken Precondition}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P \\entails P' $ then $ w : [P, Q] \\refsto w : [P', Q] $\n\t\t\n\t\\end{itemize}\n\n\t\\item Rule 3: \\textbf{Skip}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P \\entails Q $ then $ w : [P, Q] \\refsto \\Skip $\n\t\t\n\t\\end{itemize}\n\n\t\\item Rule 4: \\textbf{Assignment}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P \\entails Q[x \\backslash E] $ then $ x : [P, Q] \\refsto x := E $\n\t\t\n\t\\end{itemize}\n\t\n\t\\item Rule 5: \\textbf{Composition}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ w : [P, Q] \\refsto w : [P, M]; w : [M, Q] $ (no side condition)\n\t\t\n\t\\end{itemize}\n\n\t\\item Rule 6: \\textbf{Following Assignment} (combined assignment and composition)\n\t\n\t\\begin{itemize}\n\t\n\t\\item $ w, x : [P, Q] \\refsto w, x : [P, Q[x \\backslash E]]; x := E $\n\t\n\t\\end{itemize}\n\n\t\\item Rule 7: \\textbf{Selection}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ P \\entails \\bigvee_{i=1}^{n} G_i $ then $ w : [P, Q] \\refsto $\\\\\n\t\t$ ~~~~ \\If ~ G_1 \\rightarrow w : [G_1 \\land P, Q] $\\\\\n%\t\t$ ~~~~ \\Choice ~ G_2 \\rightarrow w: [G_2 \\land P, Q] $\\\\\n\t\t$ ~~~~ \\dots $\\\\\n\t\t$ ~~~~ \\Choice ~ G_n \\rightarrow w: [G_n \\land P, Q] $\\\\\n\t\t$ ~~~~ \\Fi $\n\t\t\n\t\\end{itemize}\n\n\t\\item Rule 8: \\textbf{Repetition}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item For repetition, a loop invariant $ I $ and loop variant (an integer expression) $ V $ are required\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\n\t\t\t\\item Let $ V_0 $ be the value of $ V $ at the start of each iteration\n\t\t\t\n\t\t\t\\item Then $ 0 \\le V < V_0 $ is $ \\true $ at the end of each iteration\n\t\t\t\n\t\t\t\\item (i.e. $ V $ is \\textit{strictly decreasing} on every iteration, and won't be negative before loop termination)\n\t\t\t\n\t\t\\end{itemize}\n\t\n\t\\item To apply the repetition rule\n\t\n\t\t\\begin{enumerate}\n\t\t\t\n\t\t\t\\item Strengthen postcondition to $ I \\land \\lnot G $ (side condition: $ I \\land \\lnot G \\entails Q $)\n\t\t\t\n\t\t\t\\item Use composition to perform $ w : [P, I \\land \\lnot G] \\refsto w : [P, I]; w : [I, I \\land \\lnot G] $\n\t\t\t\n\t\t\t\\item Refine the first half into initialisation (e.g. an assignment)\n\t\t\t\n\t\t\t\\item Refine the second half using the repetition rule (no side conditions!)\n\t\t\t\n\t\t\\end{enumerate}\n\t\n\t\\item Rule: Let $ G \\defeq \\bigvee_{i=1}^{n} G_i $, then $ w : [I, I \\land \\lnot G] \\refsto$\\\\\n\t$ ~~~~ \\Do ~ G_1 \\rightarrow w : [I \\land G_1, I \\land (0 \\le V < V_0)] $\\\\\n%\t$ ~~~~ \\Choice ~ G_2 \\rightarrow w : [I \\land G_2, I \\land (0 \\le V < V_0)] $\\\\\n\t$ ~~~~ \\dots $\\\\\n\t$ ~~~~ \\Choice ~ G_n \\rightarrow w : [I \\land G_n, I \\land (0 \\le V < V_0)] $\\\\\n\t$ ~~~~ \\Od $\n\t\n\t\\end{itemize}\n\n\t\\item Rule 9: \\textbf{Contract frame}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ w, x : [P, Q] \\refsto w : [P, Q[x_0 \\backslash x]] $\n\t\t\n\t\\end{itemize}\n\n\t\\item Rule 10: \\textbf{Remove invariant}\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item If $ w $ does not occur in $ I $ then $ w : [P \\land I, Q \\land I] \\refsto w : [P, Q] $\n\t\t\n\t\\end{itemize}\n\t\n\\end{itemize}", "meta": {"hexsha": "7838a24862599bf83516952255de2defadd910fd", "size": 4582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSSE3100/refinement.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": "CSSE3100/refinement.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": "CSSE3100/refinement.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": 26.4855491329, "max_line_length": 139, "alphanum_fraction": 0.5951549542, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650247, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6300382964064466}}
{"text": "\\subsection{Stability}\nAs touched on in section \\ref{sec:choice_of_cont}, the controller needs to be stable for the range in which the robot operates. The stability analysis will be preformed on the kinematic equation shown in \\eqref{eq:base_system_eq2}. Since the robot has two controllers, for turning left and right, the kinematic function can be rewritten as.\n\n\\begin{equation}\n    \\Dot{\\theta} = \\frac{\\Delta v}{2r_b} \n    \\label{eq:stab1}\n\\end{equation}\n\n\\subsubsection{Continuous Time}\n\nThe $\\Delta v$ will be seen as a constant and will be ignored in future equations. Using \\eqref{eq:stab1}, the open-loop and closed-loop equation becomes.\n\n\\begin{equation}\n    G_{ol}(s)=\\frac{1}{2 r_b s}\n\\end{equation}\n\n\\begin{equation}\n    G_{cl}(s)=\\frac{G_{ol}(s)}{1+G_{ol}(s)}=\\frac{(2r_b s)}{(2r_b s)*(2r_b s + 1)}\n    \\label{eq:stab12}\n\\end{equation}\n\n\\noindent The function \\eqref{eq:stab12} has a pole and zero cancellation at origo. In Fig.\\ref{fig:step1} the step response, poles and zeros are plotted for the closed loop system. Since all the poles appeare on the negative real plane, the system is stable.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{img/closed_loop_step.eps}\n    \\caption{The closed loop system without a controller.}\n    \\label{fig:step1}\n\\end{figure}\n\n\\noindent The \\textbf{PD}-controller discussed in previous sections only need to improve the system response, since the overall system is already stable. Introducing the controller to the system gives us the closed loop function.\n\n\\begin{equation}\n    G_{clPD} = \\frac{2r_b s(k_p + k_d s)}{2r_b s(s(2r_b+k_d)+k_p)}\n\\end{equation}\n\n\\noindent From this it's easy to see that the system will remain stables for $k_d > - 2 r_b$ and that the value of $k_d$ won't have any effect on the stability of the system in continuous time.\\\\\n\\indent The values for $k_p$ and $k_d$ is therefore chosen in such a manner that $ 0 > k_d > -2 r_b$ and $k_p$ so that the greatest error input from the \\textbf{MV}-node will not saturate the actuators. The result of these are shown in Fig.\\ref{fig:step2} and a comparison was made, represented in table \\ref{tab:with_without}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width= 0.7\\textwidth]{img/closed_loop_step_PD.eps}\n    \\caption{The closed loop system with a controller.}\n    \\label{fig:step2}\n\\end{figure}\n\n\\begin{table}[H]\n    \\centering\n    \\caption{Comparison between the closed loop systems.}\n    \\begin{tabular}{|c|ccc|}\n        \\hline & Without controller & \\textbf{PD}-controller & Discrete Time \\textbf{PD}-controller \\\\\n        \\hline Rise Time & 0.8788$s$ & 0.0879$s$ & 0.1000$s$ \\\\ \n        Settling Time & 1.5648$s$ & 0.1565$s$ & 0.2500$s$ \\\\\n        \\hline\n    \\end{tabular}\n    \\label{tab:with_without}\n\\end{table}\n\n\n\\subsubsection{Discrete Time}\nUsing MATLAB to move from continuous time to discrete time with a update frequency of 20 Hz\\footnote{The update frequency of the camera} and an input delay of $1/30s$\\footnote{Estimated input delay to the actuators}. In Fig.\\ref{fig:stepD} it's clear that the pole is within the unit circle on the discrete time plane and that the responds follows the step input. In conclusion, the system is stable using the $k_p$ and $k_d$ values proposed above, even in discrete time \\cite{torkel_ljung}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width= 0.7\\textwidth]{img/closed_loop_step_D.eps}\n    \\caption{The continuous step response, discrete step response and the poles and zeros of the discrete transfer function.}\n    \\label{fig:stepD}\n\\end{figure}\n", "meta": {"hexsha": "11b73368b952084401892262fe37cbcf7f09e6aa", "size": 3572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/finished/chapters/BASE_stability.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/BASE_stability.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/BASE_stability.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": 51.768115942, "max_line_length": 491, "alphanum_fraction": 0.7292833147, "num_tokens": 1048, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.629985154492181}}
{"text": "\\section{Random Variable}\n\n\\subsection{Events}\n\n\\begin{definition}[sample space]\n    The set of all possible outcome of an experiment is defined as \\cindex{sample space} $S$.\n\\end{definition}\n\n\\begin{definition}[event]\n    Any subset $E$ of sample space $S$ is defined as \\cindex{event}.\n\\end{definition}\n\nIt is conventional to designate $E \\cup F$ as $EF$.\n\n\n\\begin{definition}[mutually exclusive]\n    If $EF = \\emptyset $, $E$ and $F$ are said to be \\cindex{mutually exclusive}.\n\\end{definition}\n\n\\begin{definition}\n    The probabilty $P$ is defined on event $E$ of sample space $S$ which follow the following condition:\n    \\begin{enumerate}\n        \\item $0 \\leq P(E) \\leq 1$.\n        \\item $P(S) = 1$.\n        \\item for any sequence of mutually exclusive event $E_1, E_2, \\dots$,\n            \\begin{equation*}\n                P \\left(\\bigcup_{n=1}^\\infty E_n \\right) = \\sum_{n=1}^\\infty P(E_n)\n            \\end{equation*}\n        \n    \\end{enumerate}\n    \\qed\n\\end{definition}\n\nIf the experiment is repeated over and over again, with probability $1$ the proportion of time that event $E$ will occur is $P(E)$.\n\n\\begin{theorem}[inclusion-exclusion identity]\n    \\begin{equation}\n        \\begin{aligned}\n            P(\\bigcup_{i=1}^n E_i) &= \\sum_i P(E_i) - \\sum_{i < j}P(E_i E_j) + \\sum_{i < j < k} P(E_i E_j E_k) + \\dots + (-1)^{n+1} P(E_1 E_2 \\dots E_n)\n        \\end{aligned}\n    \\end{equation}\n\\end{theorem}\n\n\\begin{definition}[conditional probability]\n    The \\cindex{conditional probability} that $E$ occurs given that $F$ occurs is denoted by $P(E|F)$ and defined as:\n    \\begin{equation}\n        P(E|F) = \\frac{P(EF)}{P(F)}\n    \\end{equation}\n    \n    For conditional probability the sample space is changed.\n    \n    \\qed\n\\end{definition}\n\n\\begin{definition}[independent]\n    Two event $E$ and $F$ are \\cindex{independent} if $P(EF) = P(E) P(F)$.\n\\end{definition}\n\n\\begin{theorem}\n    $E$ and $F$ are independent if $P(E/F) = P(E)$.    \n\\end{theorem}\n\n\\begin{definition}\n    The events $\\{ E_i \\}$ are independent if for every subset $E_{i_j}$ ($ \\forall j, 1 \\leq j \\leq n$), that\n    \\begin{equation}\n        P(E_{i_1} E_{i_2} \\dots E_{i_j}) = P(E_{i_1}) P(E_{i_2}) \\cdots P(E_{i_j})\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}\n    For mutually exclusive event $F_i$ that $\\displaystyle \\bigcup_{i=1}^n F_i = S$ .The \\cindex{Bayes' formula} is defined as:\n    \\begin{equation}\n    \\displaystyle P(F_j | F) = \\frac{\\probability{EF_j}}{\\sum\\limits_{i=1}^n \\probability{EF_i}} = \\frac{\\probability{E|F_j} \\probability{F_j}}{\\sum\\limits_{i=1}^n \\probability{E|F_i} \\probability{F_i}}\n    \\end{equation}\n\\end{definition}\n\n\n\n\n\\subsection{Random Variable Definition}\n\n\\begin{definition}[random variable]\n    A real value function defined on sample space is called \\cindex{random variable}.\n\\end{definition}\n\n\\begin{definition}[discrete random variable]\n    A random variable that can takes at most a countable values is said to be \\cindex{discrete random variable}.\n\\end{definition}\n\n\\begin{definition}[probability mass function]\n    The \\cindex{probability mass function} $p(a)$ of discrete random variable $X$ is defined as $p(a) = \\probability{X = a}$.\n\\end{definition}\n\n\n\\begin{definition}[cdf]\n    The \\cindex{cumulative distribution function (cdf)} of random variable $X$ for any $- \\infty < b < \\infty$ is defined as $F(b) = \\probability{ X \\leq b }$\n\\end{definition}\n\n\\begin{theorem}\n    Some properties of cdf are:\n    \\begin{enumerate}\n        \\item $F(b)$ is nondecreasing function of $b$.\n        \\item $F(b)$ is continuous from the right.\n        \\item $\\displaystyle \\lim_{b \\rightarrow \\infty} F(b) = F(\\infty) = 1$.\n        \\item $\\displaystyle \\lim_{b \\rightarrow -\\infty} F(b) = F(- \\infty) = 0$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{definition}\n    $\\probability{X < b}$ is defined as $\\probability{ X < b } = \\displaystyle \\lim_{h \\rightarrow 0^+} \\probability{ X \\leq b - h } = \\lim_{h \\rightarrow 0^+} F(b-h)$.\n\\end{definition}\n\n$\\probability{X < b} \\neq F(b)$ because $F(b)$ also include the probability that $X$ equals $b$.\n\n\n\n\nPoisson random variable is a approximate of binomial random variable when $n$ is large and $p$ is small. Let $\\lambda = np$, then:\n\\begin{equation*}\n    \\begin{aligned}\n        \\binom{n}{i}p^i (1-p)^{n-i} &= \\frac{n!}{(n-i)! i!} \\left(\\frac{\\lambda}{n} \\right)^i \\left(1-\\frac{\\lambda}{n} \\right)^{n-i} \\\\\n        &= \\frac{n (n-1) \\cdots (n - i + 1)}{n^i} \\frac{\\lambda^i}{i!} \\frac{(1- \\frac{\\lambda}{n})^n}{(1- \\frac{\\lambda}{n})^i} \\\\\n        & \\approx 1 \\times \\frac{\\lambda^i}{i!} \\times \\frac{e^{- \\lambda}}{1} = e^{- \\lambda} \\frac{\\lambda^i}{ i !}\n    \\end{aligned}\n\\end{equation*}\n\n\\begin{definition}\n    $f(x)$ is called \\cindex{probability density function} if $\\probability{X \\in B} = {\\displaystyle \\int_B f(x) \\dif{x}} $. \\qed\n\\end{definition}\n\nBecause $\\probability{ a - \\frac{\\varepsilon}{2} \\leq X \\leq a + \\frac{\\varepsilon}{2} } =\\displaystyle \\int_{a - \\frac{\\varepsilon}{2}}^{a + \\frac{\\varepsilon}{2}} f(x) \\dif{x} \\approx \\varepsilon f(a)  $, $f(a)$ is a measure of how likely it is that the random variable will be near $a$ within interval $\\varepsilon$.\n\n\nSometimes when calculating the probability $\\probability{X=a}$, we can first calculate $F(a)$ and then calculate $\\probability{X=a} = \\dod{F(a)}{a}$.\n\n\\begin{definition}[expectation]\n    The \\cindex{expectation} of $X$ is defined as:\n    \\begin{equation}\n        \\expect{X} = \\begin{cases}\n            \\displaystyle \\sum x p(x) & \\text{for discrete case} \\\\\n            \\displaystyle \\int_{-\\infty}^{\\infty} x f(x) \\dif{x} & \\text{for continuous case}\n        \\end{cases}\n    \\end{equation}\n\\end{definition}\n\n\n\n\n\\begin{theorem}\n    The expectation of a function $g$  of a random variable $X$ is:\n    \\begin{equation}\n        \\expect{g(X)} = \\begin{cases}\n            \\displaystyle \\sum g(x) p(x) & \\text{for discrete case} \\\\\n            \\displaystyle \\int_{-\\infty}^{\\infty} g(x) f(x) \\dif{x} & \\text{for continuous case}\n        \\end{cases}\n    \\end{equation}\n\\end{theorem}\n\n\n\\begin{theorem}\n    \\begin{equation}\n        \\expect{aX + b} = a \\expect{X} + b\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\expect{aX + bY} = a \\expect{X} + b \\expect{Y}\n    \\end{equation}    \n\\end{theorem}\n\n\n\n\\begin{definition}[variance]\n    The \\cindex{variance} of $X$ is defined as\n    \\begin{equation}\n        \\variance{X} = \\expect{(X - \\expect{X})^2}\n    \\end{equation}\n\\end{definition}\n\n\n\\begin{theorem}\n    \\begin{equation}\n        \\variance{X} = \\expect{X^2} - \\expect{X}^2\n    \\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n    Let $X_i$ be identically independent random variable. We need to notice that \n    \\begin{equation*}\n        \\variance{\\sum_{i=1}^n X_i} = n \\variance{X} \\neq \\variance{n \\times X_i} = n^2 \\variance{X}\n    \\end{equation*}    \n\\end{theorem}\n\n\n\n\\subsection{Common Distributions}\n\n\n\\begin{center} \n   \\begin{tabular}{|c|c|c|c|c|}\n  \\hline\n  name & density & $\\phi(t)$ & mean & var \\\\\n  \\hline\n  \\cindex{binomial} & $\\displaystyle \\binom{n}{x} p^x (1-p)^{n-x}$  &$(p e^t + q)^n$ & np & npq \\\\\n  \\hline\n  \\cindex{poisson} & $\\displaystyle e^{-\\lambda} \\frac{\\lambda^x}{x!}$  & $\\displaystyle e^{\\lambda (e^t -1)}$& $\\lambda$ & $\\lambda$ \\\\\n  \\hline\n  \\cindex{geometric} & $p (1-p)^{x-1}$& $\\displaystyle \\frac{pe^t}{1-(1-p)e^t}$ & $\\displaystyle \\frac{1}{p}$ & $\\displaystyle \\frac{1-p}{p^2}$ \\\\\n  \\hline\n  \\cindex{uniform} &$\\displaystyle \\frac{1}{b-a}$ & $\\displaystyle \\frac{e^{tb} - e^{ta}}{t(b-a)}$ & $\\displaystyle \\frac{a + b}{2}$ & $\\displaystyle \\frac{(b-a)^2}{12}$ \\\\\n  \\hline\n  \\cindex{exponential} & $\\lambda e^{-\\lambda x}$ & $\\displaystyle \\frac{\\lambda}{\\lambda - t}$ & $\\displaystyle \\frac{1}{\\lambda}$ & $\\displaystyle \\frac{1}{\\lambda^2}$ \\\\\n  \\hline\n  \\cindex{gamma} & $\\displaystyle \\frac{\\lambda e^{-\\lambda x} (\\lambda x)^{n - 1}}{(n-1)!}$ & $\\displaystyle \\left(\\frac{\\lambda }{\\lambda - t} \\right)^n$ & $\\displaystyle \\frac{n}{\\lambda}$ & $\\displaystyle \\frac{n}{\\lambda^2}$ \\\\\n  \\hline\n  \\cindex{normal} & $\\displaystyle \\frac{1}{\\sqrt{2 \\pi} \\sigma} e^{\\displaystyle - \\frac{(x - \\mu)^2}{2 \\sigma^2}}$ & $e^{\\displaystyle \\mu t + \\frac{\\sigma^2 t^2}{2}}$&$\\mu$& $\\sigma^2$ \\\\\n  \\hline\n\\end{tabular} \n\\end{center}\n\n\n\\begin{theorem}\n    If $X$ is normally distributed with $\\mu$ and $\\rho^2$, then $Y = aX + b$ is a normal distribution with $a\\mu + b$ and $(a\\rho)^2$. So $Y =\\displaystyle \\frac{X - \\mu}{\\rho}$ is normally distributed with $0$ and $1$, which is called \\cindex{standard normal distribution}.\n\\end{theorem}\n\n\\begin{definition}\n    A random variable $X$ has \\cindex{gamma distribution} with parameter $\\alpha$ and $\\beta$ if the pdf is:\n    \\begin{equation*}\n        f(x|\\alpha, \\beta) = \\frac{\\beta e^{-\\beta x} (\\beta x)^{\\alpha - 1}}{\\Gamma(\\alpha)}\n    \\end{equation*}\n    while $\\Gamma(\\alpha)$  is defined as:\n    \\begin{equation}\n        \\Gamma(\\alpha) = \\int_0^\\infty e^{-x} x^{\\alpha - 1} \\dif{x}\n    \\end{equation}\n    exponential distribution is gamma distribution with $\\alpha = 1$.\n    \n    \\qed\n\\end{definition}\n\n\\begin{theorem}\n    If $X_i$ are independent gamma distribution with $\\alpha_i$ and $\\beta$, then the sum $\\displaystyle \\sum_{i=1}^n X_i$ has gamma distribution with $\\displaystyle \\sum \\alpha_i$ and $\\beta$.\n\\end{theorem}\n\n\n\\begin{theorem}\n    \\begin{equation}\n        \\Gamma \\left(\\frac{1}{1} \\right) = \\sqrt{\\pi}\n    \\end{equation}\n    \n    \\begin{equation}\n        \\Gamma (a + 1) = a \\Gamma(a)\n    \\end{equation}\n    \\begin{equation}\n        \\Gamma (n) = (n-1)!\n    \\end{equation}\n    \\qed\n\\end{theorem}\n\n\n\\begin{definition}\n    $X$ is a \\cindex{beta distribution} if the pdf is:\n    \\begin{equation}\n        f(x|\\alpha, \\beta) = \\frac{\\Gamma(\\alpha + \\beta)}{\\Gamma(\\alpha) \\Gamma(\\beta)} x^{\\alpha - 1} (1-x)^{\\beta - 1}\n    \\end{equation}\n\\end{definition}\n\n\n\n% joint distribution\n\\subsection{Joint Distribution}\n\n\\begin{definition}\n    The \\cindex{joint cumulative probability distribution function} of two discrete random variable $X$ and $Y$ is defined as\n    \\begin{equation}\n        F(a,b) = \\probability{ X \\leq a, Y \\leq b }\n    \\end{equation}\n    \n    The cumulative distribution of $Y$ is defined as\n    \\begin{equation}\n        F_X(a) = \\probability{X \\leq a } =\\probability{X \\leq a, Y < \\infty } = F(a, \\infty)\n    \\end{equation}\n    \n    The \\cindex{joint probability mass function} is defined as \n    \\begin{equation}\n        p(x,y) =\\probability{X = x, Y = y}\n    \\end{equation}\n    \n    The probability mass function of $X$ from $p(x,y)$ is defined as\n    \\begin{equation}\n        p_X(x) = \\displaystyle \\sum_{y: p(x,y) > 0} p(x,y)\n    \\end{equation}\n    \\qed\n\\end{definition}\n\n\n\\begin{definition}\n    for continuous case, $X$ and $Y$ are \\cindex{jointly continuous} if there is a function $f(x,y)$ that for all sets $A$ and $B$ we have \n\\begin{equation}\n    \\probability{X \\in A, Y \\in B} = \\int_B \\int_A f(x,y) \\dif{x} \\dif{y}\n\\end{equation}\n\n$f(x,y)$ is called \\cindex{joint probability density function} of $X$ and $Y$. The probability density function of $X$ can be obtained as\n\\begin{equation}\n    \\begin{aligned}\n        \\probability{X \\in A} &= \\int_A \\int_{-\\infty}^\\infty f(x,y) \\dif{x} \\dif{y} \\\\\n        &= \\int_A f_X (x) \\dif{x}\n    \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation}\n     f_X(x) = \\int_{-\\infty}^\\infty f(x,y) \\dif{y}\n\\end{equation}\n\nWe have \n\\begin{equation}\n    \\dmd{F(a,b)}{2}{a}{1}{b}{1} = f(a,b)\n\\end{equation}\n\\qed\n\\end{definition}\n\nFor $n$ random variable $X_i$, we could construct $Y_i$ that\n\\begin{equation}\\label{jointdenityequation}\n    \\begin{aligned}\n        Y_1 &= g_1 (X_1, X_2, \\cdots, X_n) \\\\\n        Y_2 &= g_2 (X_1, X_2, \\cdots, X_n) \\\\\n        & \\vdots \\\\\n        Y_n &= g_n (X_1, X_2, \\cdots, X_n) \\\\\n    \\end{aligned}\n\\end{equation}\n\nAssume its \\cindex{Jacobian} determinant $J(x_1, \\dots, x_n) \\neq 0$ for all $x_i$. Then the probability density function of $Y_i$ is \n\\begin{equation}\n    f_{Y_1, \\cdots, Y_n}(y_1, \\cdots, y_n) = \\frac{1}{\\absolutevalue{J(x_1, \\cdots, x_n)}} f_{X_1, \\cdots, X_n}(x_1, \\cdots , x_n)\n\\end{equation}\n\nSo the process of calculating $f_{Y_i}$ are:\n\\begin{enumerate}\n    \\item solve $X_i = h(Y_i)$ from equation (\\ref{jointdenityequation} ).\n    \\item calculate $J(X_i)$.\n    \\item replace $x_i$ by $y_i$ in $f(x_i)$ and multiplicate by $\\displaystyle \\frac{1}{\\absolutevalue{J}}$.\n\\end{enumerate}\n\n\n\\subsection{Independence}\n\n\\begin{definition}\n    Two random variable $X$ and $Y$ are \\cindex{independent} if $\\forall a,b \\in \\mathbf{R}$,\n    \\begin{equation}\n        \\probability{ X \\leq a , Y \\leq b } = \\probability{ X \\leq a } \\probability{ X \\leq b }\n    \\end{equation}\n    It means\n    \\begin{equation}\n        F(a,b) = F_X(a) F_Y(b)\n    \\end{equation}\n    When $X$ and $Y$ are discrete, it reduces to\n    \\begin{equation}\n        p(x,y) = p_X(x) p_Y(y)\n    \\end{equation}\n    \n    When they are continuous, it reduces to\n    \\begin{equation}\n        f(x,y)=f_X(x) f_Y(y)\n    \\end{equation}\n    \\qed\n\\end{definition}\n\n\\begin{theorem}\n    If $X$ and $Y$ are indepent, for any function $h$ and $g$, we have\n    \\begin{equation}\n        \\expect{g(X) h(Y)} = \\expect{g(X)} \\expect{h(Y)}\n    \\end{equation}    \n\\end{theorem}\n\n\\subsection{Covariance}\n\n\\begin{definition}[covariance]\n    The \\cindex{covariance} for $X$ and $Y$ is defined as \n    \\begin{equation}\n    \\begin{aligned}\n        \\covariance{X}{Y} &= \\expect{(X - \\expect{X})(Y - \\expect{Y})} \\\\\n        &= \\expect{XY} - \\expect{X} \\expect{Y}\n    \\end{aligned}\n    \\end{equation}\n    In general covariance means $Y$ tends to move in the same direction of $X$.\n    \\qed\n\\end{definition}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\covariance{X}{Y} = \\variance{X}\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\covariance{X}{Y} = \\covariance{Y}{X}\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\covariance{cX}{Y} = c \\covariance{X}{Y}\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\covariance{X}{Y + Z} = \\covariance{X}{Y} + \\covariance{X}{Z}\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n        \\mathhilight{Cov} \\left(\\sum_{i=1}^n X_i, \\sum_{j=1}^m Y_j \\right) = \\sum_{i=1}^n \\sum_{j=1}^m \\mathhilight{Cov}(X_i, Y_j)\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n    \\begin{equation}\n    \\begin{aligned}\n        \\mathhilight{Var} \\left( \\sum_{i=1}^n X_i \\right) &= \\mathhilight{Cov}\\left( \\sum_{i=1}^n X_i, \\sum_{j=1}^n X_j \\right) \\\\\n        &= \\sum_{i=1}^n \\variance{X_i} + 2 \\sum_{i=1}^n \\sum_{j < i} \\covariance{X_i}{X_j} \\\\\n        &= \\sum_{i=1}^n \\variance{X_i} \\text{ (if } X_i \\text{,} X_j \\text{ are independent)}\n    \\end{aligned}\n    \\end{equation}\n    This theorem is often used to calculate the variance. \\qed\n\\end{theorem}\n\n\\begin{definition}[sample mean]\n    If $X_i$ are independent and identically distributed, then the random variable $\\bar{X} =\\displaystyle \\frac{\\sum_{i=1}^n X_i}{n}$ is called the \\cindex{sample mean}.\n\\end{definition}\n\n\\begin{theorem}\n\\begin{equation}\n    \\expect{\\bar{X}} = \\mu\n\\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\n\\begin{equation}\n    \\variance{\\bar{X}} = \\frac{\\sigma^2}{n}\n\\end{equation}    \n\\end{theorem}\n\\begin{theorem}\n\\begin{equation}\n    \\covariance{\\bar{X}}{X_i - \\bar{X}} = 0\n\\end{equation}    \n\\end{theorem}\n\n\\begin{definition}\n    Function $F_{X+Y}$ is called the \\cindex{convolution} of the distribution of $F_X$ and $F_Y$, which is\n    \\begin{equation}\n        \\begin{aligned}\n            F_{X+Y}(a) &= \\probability{X + Y \\leq a} \\\\\n            &= \\iint_{x+y \\leq a} f(x) g(y) \\dif{x} \\dif{y} \\\\\n            &= \\int_{-\\infty}^\\infty \\left( \\int_{-\\infty}^{a - y} f(x) \\dif{x} \\right) g(y) \\dif{y} \\\\\n            &= \\int_{-\\infty}^\\infty F_X (a-y)g(y) \\dif{y}\n        \\end{aligned}\n    \\end{equation}\n    \n    The probability density function $f_{X+Y}(a)$ is given by \n    \\begin{equation}\n        \\begin{aligned}\n            f_{X+Y}(a) &= \\dod{F_{X+Y}(a)}{a} \\\\\n            &= \\dod{\\displaystyle \\int_{-\\infty}^\\infty F_X (a-y)g(y) \\dif{y}}{a} \\\\\n            &= \\int_{-\\infty}^{\\infty} f(a-y) g(y) \\dif{y}\n        \\end{aligned}\n    \\end{equation} \\qed\n\\end{definition}\n\n\n\n% moment generating function\n\n\\begin{definition}\n    The \\cindex{moment generating function} $\\phi(t)$ of the random variable $X$ is defined by\n    \\begin{equation}\n        \\begin{aligned}\n            \\phi(x) &= \\expect{e^{tX}} \\\\\n            &= \\begin{cases}\n                 \\displaystyle \\sum_x e^{tx} p(x)\\\\\n                 \\displaystyle \\int_{-\\infty}^\\infty e^{tx} f(x) \\dif{x}\n            \\end{cases}\n        \\end{aligned}\n    \\end{equation}\n    \n    For any $n$ random variable $X_i$, the \\cindex{joint moment generating function} $\\phi(t_i)$ is defined by $\\phi(t_1, \\dots, t_n) = \\expect{ e^{ \\sum_{i=1}^n t_i X_i}}$.\n    \\qed\n\\end{definition}\n\nBecause $\\phi^n (t) = \\expect{X^n e^{tX}}$, we have $\\phi^n(0) = \\expect{X^n}$.\n\n\\begin{theorem}\n    \\begin{equation}\n        \\phi_{X+Y}(t) = \\phi_X(t) \\phi_Y(t)\n    \\end{equation}    \n\\end{theorem}\n\n\\begin{theorem}\nThe moment generating function uniquely determine the distribution.    \n\\end{theorem}\n\n\n\n% sample mean and sample variance\n\n\\subsection{Sample Mean and Sample Variance}\n\n\\begin{definition}[sample mean]\n    The \\cindex{sample mean} is defined as $\\displaystyle \\bar{X} = \\frac{\\sum X_i}{n}$.\n    \\qed\n\\end{definition}\n\n\\begin{definition}[sample variance]\n    Let $X_i$ be independent and identically distributed random variable with mean $\\mu$ and variance $\\sigma^2$, the \\cindex{sample variance} $S^2$ is defined by \n\\begin{equation}\n    S^2 = \\sum_{i=1}^n \\displaystyle \\frac{(X_i - \\bar{X})^2}{n - 1}\n\\end{equation} \n\\qed\n\\end{definition}\n\n\\begin{theorem}\n\\begin{equation}\n    \\expect{S^2} = \\sigma^2\n\\end{equation}    \n\\end{theorem}\n\n\n\\begin{definition}[chi-squared]\n    If $Z_i$ are $n$ independent standard normal random variables, the random variable $\\displaystyle \\sum_{i=1}^n Z_i^2$ is called \\cindex{chi-squared} random variable with $n$ degrees of freedom.\n\\end{definition}\n\n\\begin{theorem}\nIf $X_i$ are independent and identically distributed normal random variable with mean $\\mu$ and variance $\\sigma^2$, then:\n    \\begin{enumerate}\n        \\item the sample mean $\\bar{X}$ and sample variance $S^2$ are independent.\n        \\item $\\bar{X}$ is a normal random variable with mean $\\mu$ and variance $\\displaystyle \\frac{\\sigma^2}{n}$.\n        \\item $\\displaystyle \\frac{(n-1)S^2}{\\sigma^2}$ is a chi-squared random variable with $n-1$ degrees of freedom.\n    \\end{enumerate}   \n\\end{theorem}\n\n\\begin{proof}\n    Because $X_1$ are normal random varialbe, $\\bar{X}$ is also a normal random variable. Since $\\covariance{\\bar{X}}{X_i - \\bar{X}} = 0$, normal random variable $\\bar{X}$ and $X_i - \\bar{X}$ are independent. Since $S^2 = \\displaystyle \\sum_{i=1}^n \\frac{(X_i - \\bar{X})^2}{n -1}$ is a function of $X_i - \\bar{X}$ which is independ from $\\bar{X}$, $S^2$ is independent from $\\bar{X}$.\n    \n    Because \n    \\begin{equation*}\n        \\frac{(n-1)S^2}{\\sigma^2} + \\left(\\frac{\\bar{X} - \\mu}{\\frac{\\sigma}{\\sqrt{n}}}\\right)^2 = \\sum_{i=1}^n \\frac{(X_i - \\mu)^2}{\\sigma^2}\n    \\end{equation*}\n    generate the moment generating function of $\\displaystyle \\frac{(n-1)S^2}{\\sigma^2}$ from above formula and we have $\\expect{e^{t \\frac{(n-1)S^2}{\\sigma^2}}} = \\left(1-2t \\right)^{- \\frac{n-1}{2}}$ which is an chi-squared distribution with freedom $n-1$.\n\\end{proof}\n\n\n% inequality\n\n\\subsection{Inequality}\n\n\\begin{theorem}[\\cindex{Markov's Inequality}]\nIf $X$ is a random variable that is non-negative. Then for any $a > 0$ we have \n\\begin{equation}\n    \\probability{X \\geq a} \\leq \\frac{\\expect{X}}{a}\n\\end{equation}    \n\\end{theorem}\n\\begin{proof}\n    \\begin{equation*}\n        \\begin{aligned}\n            \\expect{X} &= \\int_0^\\infty x f(x) \\dif{x} \\\\\n            &= \\int_0^a x f(x) \\dif{x} + \\int_a^\\infty x f(x) \\dif{x} \\\\\n            & \\geq \\int_a^\\infty x f(x) \\dif{x} \\\\\n            & \\geq \\int_a^\\infty a f(x) \\dif{x} \\\\\n            &= a \\int_a^\\infty f(x) \\dif{x} \\\\\n            &= \\probability{X \\geq a}\n        \\end{aligned}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[\\cindex{Chebyshev's Inequality}]\n    If $X$ is a random variable with mean $\\mu$ and variance $\\sigma^2$. Then for any $k > 0$ we have\n    \\begin{equation}\n        \\probability{\\absolutevalue{X - \\mu} \\geq k } \\leq \\frac{\\sigma^2}{k^2}\n    \\end{equation}\n\\end{theorem}\n\\begin{proof}\n    Since $(X - \\mu)^2$ is nonnegative, using Markov's Inequality we have\n    \\begin{equation*}\n        \\probability{\\absolutevalue{(X - \\mu)} \\geq k} = \\probability{(X - \\mu)^2 \\geq k^2} \\leq \\frac{\\expect{(X-\\mu)^2}}{k^2}\n    \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[\\cindex{Strong Law of Large Numbers}]\n    Let $X_i$ be a sequence of independent random variables having a common distribution. With probability 1\n    \\begin{equation}\n        \\frac{X_1 + X_2 + \\dots + X_n}{n} \\rightarrow \\mu \\text{ as } n \\rightarrow \\infty\n    \\end{equation}\n\\end{theorem}\n\n\\begin{theorem}[\\cindex{Central Limit Theorem}]\n    Let $X_i$ be a sequence of independent identical random variables with mean $\\mu$ and variance $\\sigma^2$, the distribution $\\displaystyle \\frac{X_1 + X_2 + \\dots + X_n - n \\mu}{\\sigma \\sqrt{n}}$ tends to be standard normal distribution as $n \\rightarrow \\infty$.\n\\end{theorem}\n\n\n\n\n\n\n% examples\n\\subsection{Examples}\n\n\\begin{example}\n    Suppose $m$ coupons are selected from $n$ different types of coupons. Each coupon is equally likely to be selected. What is the expected number of different types?\n\\end{example}\n\n\\begin{proof}\n    Let $X$ denote the number of types in $m$ selection. We have $X = X_1 + ... + X_n$ where\n    \\begin{equation*}\n        X_i = \\begin{cases}\n            1 & \\text{ , if } i \\text{ occurs in selection} \\\\\n            0 & \\text{ , otherwise}\n        \\end{cases}\n    \\end{equation*}\n    We have \n    \\begin{equation*}\n        \\expect{X_i} = 1 - \\left(\\frac{n - 1}{n} \\right)^m\n    \\end{equation*}\n    So $\\expect{X} = \\expect{X_1} + \\dots + \\expect{X_n} = \\displaystyle n \\left(1 - \\left(\\frac{n - 1}{n} \\right)^m \\right)$\n\\end{proof}\n\n\\begin{example}\n    Let $X_i$ be independent and identically distributed continuous random variable. Let $X_{(i)}$ denote the $i$th smallest of these random variables. Then $X_{(i)}$ is called \\cindex{order statistics}. Note that $X_{(i)} \\leq x$ if and only if at least $i$ of $X_j$ are not larger than $x$, so\n    \\begin{equation*}\n        \\probability{X_{(i)} \\leq x} = \\sum_{k=i}^n \\binom{n}{k} \\left(F(x) \\right)^k \\left(1 - F(x) \\right)^{n-k}\n    \\end{equation*}\n    \n    So\n    \\begin{equation*}\n        \\begin{aligned}\n            f_{X_{(i)}} (x) &= \\dod{\\probability{X_{(i)} \\leq x}}{x} \\\\\n            &= \\frac{n!}{(n-i)!(i-1)!} f(x) \\left( F(x) \\right)^{i-1} \\left(1-F(x) \\right)^{n-i}\n        \\end{aligned}\n    \\end{equation*}\n    The result could be read as there are $\\left( F(x) \\right)^{i-1}$ which are less than $x$, $\\left(1-F(x) \\right)^{n-i}$ which are larger than $x$, and $f(x)$ which equals $x$. \\qed\n\\end{example}\n\n\\begin{example}\nA particle moves along a circle of $m+1$ nodes. Each time it has equality of moving clockwise or counterclockwise. What is the probability that node $i$ is the last visited node?    \n\\end{example}\n\\begin{proof}\n    Suppose $i$ is the last visited nodes and consider 2 nodes $i-1$ and $i+1$ around it. If $i-1$ is visited before $i+1$, the probability is the same as gambling without losing money when it reaches $i+1$, so the probability is the same for every nodes. So the result is $\\displaystyle \\frac{1}{m}$.\n\\end{proof}\n\n\n", "meta": {"hexsha": "ac415cab161d9bbe192e1b66bb07863f426dadaa", "size": 23650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/probability/p.1.random_variable.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.1.random_variable.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.1.random_variable.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.273006135, "max_line_length": 384, "alphanum_fraction": 0.616744186, "num_tokens": 8134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.629985151556856}}
{"text": "\\section*{Ex.34.2-6}\n\\subsection*{Show that HAM-PATH $\\in$ NP}\n\nIf we can verify a certificate in polynomial time, then HAM-PATH $\\in$ NP.\n\nA certificate could be a path from $u$ to $v$ in $G$:\n\\\\\n- Check that all edges on the path is in $E$, where $G=(V,E)$.\n\\\\\n- Check that that the vertices on the path covers all vertices in $V$.\n\\\\\nThis can be done in polynomial time.", "meta": {"hexsha": "772e37417f2cdec1f8021e7111ce53e693cfe452", "size": 373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.2-6.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-6.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-6.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": 31.0833333333, "max_line_length": 74, "alphanum_fraction": 0.6809651475, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6299851402591315}}
{"text": "The key building block of the solutions that we develop in the subsequent\nsections is the uncertainty-quantification technique presented in this section.\nThe task of this technique is to propagate uncertainty through the system, from\na set of inputs to a set of outputs. The inputs are the uncertain parameters\n\\vu, and the outputs are the quantities that the designer is interested in\nstudying. The former could be, for instance, the effective channel length, gate\noxide thickness, and threshold voltage, and the latter could be, for instance,\nthe temperature profile, energy consumption, and maximum temperature of the\nsystem.\n\n\\inputfigure{chaos-overview}\nThe major stages of our general approach are depicted in \\fref{chaos-overview}.\nAt Stage~1, the quantity of interest \\g and the uncertain parameters \\vu are\nspecified. The quantity is given as a ``black-box'' function that operates on a\nparticular outcome of the parameters. In order to evaluate \\g, the designer is\nimplicitly required to specify the system model being considered, which also\nincludes a power model and a temperature model. At Stage~2, the uncertain\nparameters \\vu are to be transformed into independent random variables \\vz,\nsince independence is a prerequisite of the subsequent calculations. At Stage~3,\na surrogate for \\g is constructed by means of the \\ac{PC} decomposition. At\nStage~4, the computed expansion is processed in order to obtain the desired\nstatistics about \\g.\n\n\\subsection{\\problemtitle}\n\\slab{chaos-formulation}\n\nThe problem formulation is problem specific. Thus, in this general section, we\noperate on unspecified \\g and \\vu; more concrete discussions about Stage~1 are\npostponed to later sections where we start to apply the proposed methodology to\nparticular problems. In addition, for convenience, \\g is assumed to take values\nin $\\real$ here, which is generalized to $\\real^n$ later on. Lastly, there is\none recurring aspect about \\vu that is worth discussing before going any\nfurther.\n\nA description of \\vu that is supplied by the designer is an input to our\nprobabilistic analysis. A proper way to describe a set of random variables is to\nspecify their joint distribution function; see \\xref{probability-theory}. In\npractice, however, such exhaustive information is often unavailable, which is\ndue mainly to the high dimensionality and intricate dependencies inherent in\nreal-life problems.\n\nA more realistic assumption is the knowledge of the marginal distributions\n$\\set{F_i}_{i = 1}^\\nu$ and correlation matrix $\\correlation{\\vu}$ of \\vu.\nHowever, these are not sufficient to reconstruct the joint distribution of \\vu\nin general. Nevertheless, it can be approximated well by accompanying the\navailable marginals with a carefully constructed copula \\cite{nelsen2006}, which\nmakes \\vu fully specified; see \\xref{probability-theory}. Specifically, one\nconstructs a Gaussian copula based on $\\set{F_i}_{i = 1}^\\nu$ and\n$\\correlation{\\vu}$ as a part of the Nataf transformation \\cite{liu1986}, which\nis introduced in \\xref{probability-transformation}. This Gaussian copula is\ndefined in terms of an auxiliary correlation matrix.\n\nWithout loss of generality, we target the above practical scenario in our\nexperiments in this section and the next one. However, it should be understood\nthat, even though the marginal distributions and the above copula prescribe a\njoint distribution for \\vu, this distribution is an approximation rather than\nthe true one. If the joint distribution is available, it should be used instead.\n\n\\subsection{Probability Transformation}\n\\slab{chaos-transformation}\n\nMutual independence of random variables is required by \\ac{PC} expansions. In\ngeneral, however, the individual variables in $\\vu: \\Omega \\to \\real^\\nu$ are\ndependent. Therefore, our foremost task is to transform \\vu into a vector with\nindependent components in order to fulfill the requirement; see Stage~2 in\n\\fref{chaos-overview}. To this end, an adequate transformation should be\nperformed, depending on the available information \\cite{eldred2008}. Denote such\na transformation by\n\\begin{equation} \\elab{chaos-transformation}\n  \\vu = \\transform{\\vz}\n\\end{equation}\nwhere $\\vz: \\Omega \\to \\real^\\nz$ is a random vector with \\nz independent\ncomponents, and $\\transform: \\real^\\nz \\to \\real^\\nu$. The quantity of interest\n\\g can now be computed as\n\\[\n  \\g(\\vu) = (\\g \\circ \\transform)(\\vz) = \\g(\\transform(\\vz)).\n\\]\n\nCorrelated random variables can be transformed into linearly uncorrelated ones\nvia the \\ac{KL} decomposition described in \\xref{probability-transformation} and\nshown in \\eref{karhunen-loeve}. In addition, if the correlated variables form a\nGaussian vector, the uncorrelated variables are mutually independent. In the\ngeneral case (non-Gaussian), the most prominent solutions for attaining\nindependence are the Rosenblatt transformation \\cite{rosenblatt1952} and the\nNataf transformation mentioned earlier. Rosenblatt's approach is suitable when\nthe joint distribution of \\vu is known. However, as emphasized in\n\\sref{chaos-formulation}, such information is rarely available. Marginal\ndistributions and a correlation matrix are more likely to be given, which are\nsufficient for the Nataf transformation; see \\xref{probability-transformation}.\n\nApart from the extraction of the independent variables \\vz, an essential\noperation at this stage is model order reduction, since the number of stochastic\ndimensions---that is, the dimensionality of \\vz---directly impacts the\ncomplexity of the rest of the computations. This operation is frequently treated\nas a part of the \\ac{KL} decomposition, and it is also elaborated on in\n\\xref{probability-transformation}.\n\n\\subsection{Surrogate Construction}\n\\slab{chaos-construction}\n\nIn order to obtain a computationally efficient and convenient characterization\nof \\g, we utilize the \\ac{PC} decomposition with nonintrusive spectral\nprojections \\cite{xiu2010}. The corresponding mathematical foundation is given\nin \\xref{polynomial-chaos}.\n\nAssume that \\g as a function of \\vz belongs to $\\L{2}{\\Omega, \\F,\n\\probability}$; see \\xref{probability-theory}. Then \\g is expanded into the\nfollowing series at Stage~3 in \\fref{chaos-overview}:\n\\begin{equation} \\elab{chaos-expansion}\n  \\g \\approx \\chaos{\\nz}{\\lc}{\\g}\n  = \\sum_{\\vi \\in \\sparseindex{\\nz}{\\lc}} \\hat{\\g}_{\\vi} \\psi_{\\vi}\n\\end{equation}\nwhere $\\lc \\in \\natural$ is the level of the expansion, $\\vi = (i_k) \\in\n\\natural^\\nz$ is an index, $\\sparseindex{\\nz}{\\lc}$ is an index set, and\n$\\set{\\psi_{\\vi}}{\\vi \\in \\sparseindex{\\nz}{\\lc}}$ are orthonormal polynomials\nin \\nz variables whose orders are specified by the corresponding elements of\n\\vi.\n\nIt is clear that the first step toward a polynomial expansion is the choice of a\nsuitable polynomial basis, which is typically made based on the Askey scheme of\northogonal polynomials \\cite{xiu2010}. This step is crucial, as the rate of\nconvergence of \\ac{PC} expansions depends on it. Although there are no rules\nthat guarantee the optimal choice \\cite{knio2006}, there are best practices\nsuggesting that one should be guided by the probability distributions of the\nrandom variables that drive the stochastic system at hand. For instance, when a\nrandom variable follows a beta distribution, it is worth trying the Jacobi basis\nfirst; on the other hand, the Hermite basis is preferable for Gaussian\ndistributions.\n\nAs shown in \\eref{chaos-inner-product} and \\eref{chaos-projection}, each\ncoefficient $\\hat{\\g}_{\\vi}$ is an \\nz-dimensional integral of the product of \\g\nand $\\psi_{\\vi}$. In general, this integral should be computed numerically as\ndescribed in \\xref{numerical-integration}. Specifically, an adequate\n\\nz-dimensional quadrature $\\quadrature{\\nz}{\\lq}$, which is a set of\n\\nz-dimensional points accompanied by a set of scalar weights, is utilized. The\nresult is\n\\begin{equation} \\elab{chaos-coefficient}\n  \\hat{\\g}_{\\vi} \\approx \\quadrature{\\nz}{\\lq}{\\g \\psi_{\\vi}}\n  = \\sum_{j \\in \\tensorindex{\\nz}{\\lq}} (\\g \\circ \\transform)(\\vz_j) \\psi_{\\vi}(\\vz_j) w_j\n\\end{equation}\nwhere $\\lq \\in \\natural$ is the quadrature's level, and $\\set{\\vz_j} \\subset\n\\real^\\nz$ and $\\set{w_j} \\subset \\real$ are the corresponding points and\nweights, respectively, indexed by $\\tensorindex{\\nz}{\\lq} \\subset \\natural$. The\noperator $\\quadrature{\\nz}{\\lq}$ is constructed via the Smolyak algorithm\n\\cite{smolyak1963} as shown in \\eref{quadrature-sparse}. An important aspect to\nnote about this construction is that it is a combination of a number of\ncherry-picked operators identified by a certain index set denoted by\n$\\sparseindex{\\nz}{\\lq} \\subset \\natural^n$. Let us discuss the content of\n$\\sparseindex{\\nz}{\\lc}$ and $\\sparseindex{\\nz}{\\lq}$.\n\nThe standard choice of $\\sparseindex{\\nz}{\\lc}$ in \\eref{chaos-expansion} is the\nisotropic total-order index set, which can be seen in\n\\eref{index-total-order-isotropic}. \\emph{Isotropic} refers to constraining all\ndimensions identically, and \\emph{total-order} to the criterion used for\nconstraining each dimension. Since $\\psi_{\\vi}$ is a polynomial of total order\nat most \\lc, and \\g is approximated by such a polynomial, the integrand in\n\\eref{chaos-coefficient} can be assumed to be a polynomial of total order at\nleast $2 \\lc$. With this in mind, one typically constructs such a quadrature\nthat is exact for polynomials of total order up to at least $2 \\lc$\n\\cite{eldred2008}. More generally, the index set $\\sparseindex{\\nz}{\\lc}$, which\nis used in \\eref{chaos-expansion}, and the index set $\\sparseindex{\\nz}{\\lq}$,\nwhich implicitly determines the content of the index set\n$\\tensorindex{\\nz}{\\lq}$ used in \\eref{chaos-coefficient}, should be related as\n$\\sparseindex{\\nz}{\\lc} \\subseteq \\sparseindex{\\nz}{\\lq}$.\n\nIn the case of Gaussian quadratures, which is a broad and potent class of\nquadratures introduced in \\xref{numerical-integration}, a quadrature of level\n\\lq is exact for polynomials of total order up to $2 \\lq + 1$ \\cite{heiss2008}.\nTherefore, in this very common case, an adequate quadrature can be constructed\nby ensuring that $\\lq \\geq \\lc$.\n\nAn important generalization of the isotropic Smolyak algorithm in\n\\eref{quadrature-sparse} is the anisotropic Smolyak algorithm \\cite{nobile2008}.\nThe difference between the isotropic and anisotropic versions lies in the\ncontent of $\\sparseindex{\\nz}{\\lq}$. In particular, the anisotropic total-order\nindex set is defined as follows:\n\\begin{equation} \\elab{index-total-order-anisotropic}\n  \\sparseindex{\\nz}{\\lq} = \\set{\\vi}{\\vi \\in \\natural^\\nz, \\innerproduct{\\v{c}}{\\vi} \\leq \\lq \\, \\min_{i = 1}^\\nz c_i}\n\\end{equation}\nwhere $\\v{c} = (c_i) \\in \\real^\\nz$ with $c_i \\geq 0$ for $i = \\range{1}{\\nz}$\nis a vector assigning importance weights to the dimensions, and\n$\\innerproduct{\\cdot}{\\cdot}$ is the standard inner product in $\\real^\\nz$.\n\\eref{index-total-order-anisotropic} plugged into \\eref{quadrature-sparse}\nresults in a sparse grid that is exact for the polynomial subspace that is\nobtained using the same index set.\n\nThe above approach allows one to exploit anisotropic behaviors that are present\nin many practical problems \\cite{nobile2008}. It provides fine control over the\ncomputational cost associated with the construction of \\ac{PC} expansions: a\ncarefully chosen importance vector $\\v{c}$ in\n\\eref{index-total-order-anisotropic} can significantly reduce the number of\npolynomial terms in \\eref{chaos-expansion} and the number of quadrature points\nin \\eref{chaos-coefficient}, which are needed for calculating the coefficients\nof those polynomial terms. The question, then, is in the choice of $\\v{c}$. When\nthe \\ac{KL} decomposition is utilized as a part of $\\transform$ in\n\\eref{chaos-transformation}, a viable option in this regard is to rely on the\nvariance contributions of the dimensions given by $\\set{\\lambda_i}_{i = 1}^\\nu$\nin \\eref{karhunen-loeve}. Specifically, we let\n\\begin{equation} \\elab{chaos-anisotropic-weight}\n  c_i = \\left(\\frac{\\lambda_i}{\\sum_{j = 1}^\\nu \\lambda_j}\\right)^\\gamma\n\\end{equation}\nfor $i = \\range{1}{\\nz}$ where $\\gamma \\in [0, 1]$ is a tuning parameter. The\nisotropic scenario can be recovered by setting $\\gamma = 0$; other values of\n$\\gamma$ correspond to various levels of anisotropy with the maximum attained by\nsetting $\\gamma = 1$.\n\nOnce \\vz has been identified, and \\lc, \\lq, and $\\v{c}$ have been chosen, the\ncorresponding polynomial basis and quadrature stay the same for all quantities\nthat one might be interested in studying. This observation is very important, as\na lot of preparatory work can and should be done only once and then reused as\nneeded. In particular, the construction in \\eref{chaos-expansion} can be reduced\nto one matrix multiplication with a precomputed matrix, which we show next.\n\n\\inputalgorithm{chaos-construction}\nLet $\\nc = \\cardinality{\\sparseindex{\\nz}{\\lc}}$ be the cardinality of\n$\\sparseindex{\\nz}{\\lc}$, which is the number of polynomial terms and\ncoefficients in \\eref{chaos-expansion}. Let also $\\nq =\n\\cardinality{\\tensorindex{\\nz}{\\lq}}$ be the cardinality of\n$\\tensorindex{\\nz}{\\lq}$, which is the number of quadrature points and weights\nin \\eref{chaos-coefficient}. Furthermore, assume that the index sets\n$\\sparseindex{\\nz}{\\lc}$ and $\\tensorindex{\\nz}{\\lq}$ are given certain\norderings so that one is able to refer to their elements using one-dimensional\nindices $i = \\range{1}{\\nc}$ and $j = \\range{1}{\\nq}$, respectively. Now, let\n\\begin{equation} \\elab{chaos-projection-matrix}\n  \\Pi = (\\psi_i(\\vz_j) w_j)_{i = 1, j = 1}^{i = \\nc, j = \\nq}.\n\\end{equation}\nThe element of $\\Pi$ on row~$i$ and column~$j$ is polynomial~$i$ evaluated at\nquadrature point~$j$ and multiplied by quadrature weight~$j$. The matrix $\\Pi$\nis referred to as the projection matrix. Using $\\Pi$, the coefficients\n$\\set{\\hat{g}_{\\vi}}{\\vi \\in \\sparseindex{\\nz}{\\lc}}$ in \\eref{chaos-expansion}\ncan now be trivially computed as follows:\n\\begin{equation} \\elab{chaos-coefficients}\n  \\hat{\\vg} = \\Pi \\vg\n\\end{equation}\nwhere\n\\begin{align*}\n  & \\hat{\\vg} = (\\hat{\\g}_i)_{i = 1}^\\nc \\text{ and} \\\\\n  & \\vg = ((\\g \\circ \\transform)(\\vz_i))_{i = 1}^\\nq.\n\\end{align*}\nIt can be seen that this formula is a matrix version of\n\\eref{chaos-coefficient}. The matrix $\\Pi$ is the one that should be precomputed\nand stored for future use.\n\nThe pseudocode for a procedure that computes \\ac{PC} expansions by leveraging\nthe projection matrix $\\Pi$ is given in \\aref{chaos-construction} where\nAlgorithm~G stands for a subroutine that calculates $\\g \\circ \\transform$ for a\ngiven \\vz, which is problem specific.\n\nLet us summarize this subsection. In order to give a probabilistic\ncharacterization of the quantity of interest \\g, we construct a polynomial\nexpansion of this quantity as shown in \\eref{chaos-expansion}. The coefficients\nof this expansion are found by means of a suitable multivariate quadrature as\nshown in \\eref{chaos-coefficient}. The quadrature is constructed via the Smolyak\nformula given in \\eref{quadrature-sparse}. The index set used in both\n\\eref{chaos-expansion} and \\eref{quadrature-sparse} is the one given in\n\\eref{index-total-order-anisotropic} where the anisotropic weights are set\naccording to \\eref{chaos-anisotropic-weight}. For computational efficiency, the\nprojection matrix defined in \\eref{chaos-projection-matrix} is to be calculated,\nstored, and used as illustrated in \\aref{chaos-construction}.\n\n\\subsection{Post-Processing}\n\\slab{chaos-processing}\n\nDue to the properties of the \\ac{PC} decomposition---in particular, the\northogonality of the basis discussed in \\xref{polynomial-chaos}---the obtained\npolynomial representation in \\eref{chaos-expansion} allows various statistics\nabout \\g to be estimated with little effort, which is the subject of Stage~4 in\n\\fref{chaos-overview}. The reason that this estimation is straightforward is\nthat the function given in \\eref{chaos-expansion} is nothing more than a\npolynomial; hence, it is easy to interpret and easy to evaluate.\n\nLet us find, for example, the expectation and variance of \\g. Since the first\npolynomial $\\psi_{\\v{0}}$ in a normalized polynomial basis is unity by\ndefinition \\cite{xiu2010},\n\\[\n  \\expectation{\\psi_{\\v{0}}} = 1.\n\\]\nHence, using the orthogonality property in \\eref{chaos-orthogonality}, we\nconclude that\n\\[\n  \\expectation{\\psi_{\\vi}} = 0\n\\]\nfor $\\vi \\in \\sparseindex{\\nz}{\\lc} \\setminus \\set{\\v{0}}$. Consequently, the\nexpected value and variance of \\g have the following straightforward\nexpressions:\n\\begin{equation} \\elab{chaos-moments}\n  \\begin{split}\n    & \\expectation{\\g} = \\hat{\\g}_{\\v{0}} \\text{ and} \\\\\n    & \\variance{\\g} = \\sum_{\\vi \\in \\sparseindex{\\nz}{\\lc} \\setminus \\set{\\v{0}}} \\hat{\\g}_{\\vi}^2,\n  \\end{split}\n\\end{equation}\nrespectively. It can be seen that the \\ac{PC} decomposition provides analytical\nformulae, based solely on the coefficients, for these probabilistic moments.\n\nThe \\ac{CDF} and \\ac{PDF} of \\g can be estimated by a sampling method applied to\n\\eref{chaos-expansion}, which is typically followed by kernel density estimation\n\\cite{hastie2013} or a similar technique. The sampling in this context can be\nbetter understood by rewriting \\eref{chaos-expansion}, which is given in terms\nof operators, as follows:\n\\[\n  (\\g \\circ \\transform)(\\vz) \\approx \\chaos{\\nz}{\\lc}{\\g}(\\vz)\n  = \\sum_{\\vi \\in \\sparseindex{\\nz}{\\lc}} \\hat{\\g}_{\\vi} \\psi_{\\vi}(\\vz).\n\\]\nHere the aforementioned operators are applied to an outcome of \\vz drawn from\nthe corresponding distribution. Consequently, each sample is a trivial\nevaluation of a polynomial; therefore, sampling methods are computationally\ncheap in this case. Furthermore, probabilities of various events can be\nestimated in a similar way, and global and local sensitivity analysis of\ndeterministic and stochastic quantities can be readily conducted on the\nexpansion.\n\n\\begin{remark} \\rlab{chaos-multidimensional-output}\nThe development given in this section remains valid even when \\g is a\nmultidimensional quantity from the standpoint of the number of outputs. In this\ncase, it is convenient to consider \\g as a row vector with an appropriate number\nof elements. All the operations that involve \\g---such as those given in\n\\eref{chaos-expansion}, \\eref{chaos-coefficient}, and\n\\eref{chaos-moments}---should then be performed elementwise. In\n\\eref{chaos-coefficients} and \\aref{chaos-construction}, \\vg and $\\hat{\\vg}$ are\ntreated as matrices with \\nc rows, and $\\g_i$ as a row vector. The output of\nAlgorithm~G in \\aref{chaos-construction} is assumed to be automatically reshaped\ninto a row vector.\n\\end{remark}\n\nIn the following, we apply the uncertainty analysis presented here to a number\nof concrete problems, namely transient and dynamic steady-state power and\ntemperature analysis as well as reliability analysis and optimization.\n", "meta": {"hexsha": "f5f863a85425dd7313b2243bb06aeb5f4f8f2fde", "size": 18741, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/uncertainty/process/development/uncertainty-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/uncertainty/process/development/uncertainty-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/uncertainty/process/development/uncertainty-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": 57.137195122, "max_line_length": 118, "alphanum_fraction": 0.767461715, "num_tokens": 5004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199795472731, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6299007566519735}}
{"text": "%!TEX root =  ../main.tex\n\n\\objective{Use derivative and integrals to calculate mean, max, and min}\n\n\\subsection{Extrema}\nMost often, real-life models of continuously changing outputs (which graph as curved lines)\nare useful to find maximums and minimum.  Zeros are important --- all the more so when\nthey appear in the denominator --- but extrema are typically more.  (Extrema is collective\nterm for both maximum and minimums.)  Calculus is extremely useful in finding these moments.\n\n\\index{derivative!test}\nThis about the some continuous, smooth curve.  What is the derivative measuring?  It is the\nslope of the function at every point.  If it is positive, the function is increasing.  If it is\nnegative, the function is decreasing.  If it is constant, the function is level.  Even if this happens\nonly for an instant, it is noteworthy.  But there are three things which might be happening\n\\begin{enumerate}\n\\item the function might have been decreasing and is switching to increasing\n\\item the function might have been increasing and is switching to decreasing\n\\item the function may be pausing in its ascend or descend, but will resume forthwith\n\\end{enumerate}\n\nConsider $x^3$ vs. $x^2$.  Both functions have a derivative of 0 at $x=0$.  Only one has\nan extremity, while the other has a saddle point.  The key to telling the difference numerically\nis to see what the rate of change of the rate of change is doing, i.e. the second derivative.\nJust as the first derivative tells us about the slope of a function, the second derivative tells us about\nconcavity or convexity.  A concave region of a smooth, continuous function will have a minimum,\nwhile a convex region will have a maximum.  So, unless we know the shape beforehand,\nit is necessary to determine the second derivative too --- not just the first --- in order to know\nwhere the extrema are.\n\n\\personfeature[-3in]{\\chapdir/pics/GodfreyKneller-IsaacNewton-1689}{Isaac Newton}{1642-1726}{\nwas an English mathematician, astronomer, and physicist who is widely recognized as \none of the most influential scientists of all time and a key figure in the scientific revolution.\nThe second fundamental theorem of calculus is also called the Newton–Leibniz axiom.\n\\href{https://en.wikipedia.org/wiki/Isaac_Newton}{Wikipedia}}\n\n\\subsection{Average Value}\nThe anti-derivative of a function tells us the area under the curve.  When done over an open\ninterval (called a definite integral) this has a remarkable side effect: it also tells us the average\nvalue of function, no matter how curvy.  Normally we think of averages as adding up a finite set \nof values, and dividing by the number of quantities just added.  Strangely, this intuition works,\neven over an infinite number of heights.\n\nConsider the function $f(x)=-12(x^3-2x^2-11x+12)$.  If we are interested in the extrema, they \noccur when the derivative is 0.  The derivative is $-36x^2-48x-11$, which requires the Q.F. to\nsolve.  It's zeros are $\\frac{2\\pm\\sqrt{37}}{3}$, or approximate .  The heights of the function\nare $\\frac{8}{9}(37\\sqrt{37}\\mp55)$ respectively.  But what about the area between each \n``hump'' and the $x$-axis?  For that we need the integral, which is $-3x^4+8x^3+66x^2+144x+C$.\nPlugging in the zero, we find that $\\int_1^4 f(x) = 297$ and $\\int_{-3}^1 f(x) = -640$.\n\nIf we look at this right area, we see that we know its minimum height, it's maximum height, and\nit's area.  There must exist some average height of the function, because we can imagine a rectangle\nwith a base of 3 and that height, which has an area of 297.  By simple division, that height must be\n99.  The average value of the continuous curve $f(x)$ from 1 to 4, is 99.\n\n\n\\begin{figure}[h]\n\\begin{centering}\n\\includegraphics[scale=0.5]{\\chapdir/pics/averageintegral}\\index{integral!to the average}\n\\caption[Integrals and Averages]{A rectangle with height at the function's average value has the same area as the integral over the same width.}\n\\end{centering}\n\\end{figure}\n\nHow can this be?  Imagine if we cut the region up into finitely many pieces.  The average height\nis equal to the sum of the heights at every point in our sample group, divided by the number of\nsamples, $n$, that we have cut the width up into.  \nIn this case, let us write this sum using the integral sign.\n\n$$\n\\cfrac{\\text{The sum of the heights of} f(x) \\text{every} \\frac{4-1}{n}}{\\frac{4-1}{n}}\n$$\n\nBut we really ought to use the integral sign, because we don't actually want to cut up the region into\na finite number ($n$) of slices, but an infinite number, with each step being no more than $dx$ wide.\nThis means we should've written\n\n$$\n\\cfrac{\\int_1^4 f(x)}{\\frac{4-1}{dx}} = \\frac{\\int_1^4 f(x)dx}{4-1}\n$$\n\nBecause dividing twice is the same as multiplying, our infinitely many additions in the numerator\nhas suddenly because an infinite number of areas, with infinitely many rectangles being brought\ntogether and summed up --- integrated, each one the height of the function times the infinitely\nnarrow width $dx$.  In other words, the definite integral over a region, divided by the width of\nthe region equals the average height of the region.\n\n$$\n\\frac{\\int_a^b f(x)}{b-a} = \\frac{F(b)-F(a)}{b-a} = \\text{average height}\n$$\n\nThis is also known as the Fundamental Theorem of Calculus.\\index{Fundamental Theorem of Calculus}", "meta": {"hexsha": "489a9af651b13cddf7b7f6276fff6af7c4543448", "size": 5309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch06/0603.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/0603.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/0603.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": 58.3406593407, "max_line_length": 144, "alphanum_fraction": 0.758334903, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.6299007490312738}}
{"text": "\\section{Permutations}\n\n    \\subsection{What are Permutations?}\n    Permutations are the arrangements of objects in a set order. \n    For instance, how many ways can you rearrange the letters in the word \"APPLE\",\n    or how many ways can you bring 4 people out of 20 friends to a party?\n\n    \\subsection{Factorial Notation}\n    Often in permutations, we need to multiply descending consecutive numbers.\n    Since these numbers are descending and not ascending, we can safely assume that \\textbf{every factorial must be positive}. \n    For instance,  $5\\cdot4\\cdot3\\cdot2\\cdot1$ can often be simplified and written as \\textbf{5!}, or 5 factorial.\\\\\n    The general rule for factorial notation is: \n    \\begin{equation*}%Factorial Equation\n        n! = n\\cdot(n-1)\\cdot(n-2)\\cdots3\\cdot2\\cdot1\n    \\end{equation*}\n    The exception to this rule is 0!, which in this case would be $0! = 1$, which would follow the same thinking as $n^0=0$.\n    \n    \\subsection{Rule of Product and Rule of Sum}\n    How many different results can one get from flipping a coin 3 times?\n    You have 2 possibilities, heads or tails, and you flip it 3 times.\n    Essentially, you have three groups of two, or $2\\cdot3$ different results, which turns out to be $6$ different possible results.\n    This is called the \\emph{Fundamental Rule of Product} or the \\emph{Counting Principle}\n    \\begin{definition}\n        The Rule of Product states that if the $1^{st}$ action can be performed in n ways, and the $2^{nd}$ action can be performed in m ways.\n        They can be performed together in $n\\cdot m$ ways. \n    \\end{definition}\n    What happens if the actions cannot be performed together? Such as which car to buy? In that case we have another rule, known as the \\emph{Rule of Sum}.\n    \\begin{definition}\n        The Rule of Sum states that if the $1^{st}$ action can be performed in n ways, and the $2^{nd}$ action can be performed in m ways, and these actions cannot occur together, then there are $n+m$ ways for either of the actions to occur.\n    \\end{definition}\n    \n    \\subsection{N-Arrangements}\n    Let's say you have 5 people, and you need to arrange them in a line.\n    You put one person in the first spot, and now you have 4 left. Repeat this until you are left with one person, which fits into the last spot.\n    You can express this mathematically by writing out $5!$ .\\\\\n    This is quite similar to the Rule of Product as:\n    \\begin{enumerate}\n        \\item Each placement is a choice\n        \\item The number of choices is reduced with each previous action. \n    \\end{enumerate}\n    A permutation of \\emph{n} objects is an arrangement of the objects in a \\textbf{definite order}.\n    This can be expressed with permutation notation, shown below where P(n,n) equals the number of ways to permute n objects.\n    \\begin{equation*}\n        P(n,n) = n!\n    \\end{equation*}\n    This equation will only work when the number of spaces to occupy and the number of objects are equal.\n    In other cases we'll have to use an r-arrangement.\n    \n    \\subsection{R-Arrangements}\n    If you have more objects than places you can put the objects into, then we can use something called an r-arrangement.\n    An r-arrangement is a permutation of \\emph{n} objects taken \\emph{r} at a time, as is shown below.\n    \\begin{equation*}\n       P(n,r) = \\frac{n!}{(n-r)!} \n    \\end{equation*}\n    Where $P(n,r)$ equals the total number of arrangements you have, divided by the number of unused objects.\n    This is most commonly displayed on calculators as \\emph{nPr}.\n    For example you have 4 subjects, but you can only study two at a time.\n    The equation for that would be $\\frac{4!}{(4-2)!}=12\\mbox{ combinations.}$ \n    \n    \\subsection{Permutations with Repeating Elements}\n    All previous examples will ONLY work with non-repeating elements, such as the letters in the word \"MONTREAL\", or 5 different books.\n    They will definitely NOT work for questions with repeating elements, such as the word \"FIJI\".\n    For all repeating elements we'll have to follow another rule shown below.\n    \\begin{definition}\n        In general, the number of arrangements of \\emph{n} objects of which \\emph{a} of one kind are alike, and \\emph{b} of one kind are alike and so forth is given by the expression below, Where the number of permutations can be found by dividing the total number of possible combinations by the repeating elements.\n        \\begin{equation*}\n            \\frac{n!}{a!b!c!\\cdots}\n        \\end{equation*}\n    \\end{definition}\n    \n    \\subsection{Problem Solving with Permutations}\n    There are 3 methods for solving problems with permutations. They are called: the Indirect Method, the Case Method, and Circular Arrangements.\n    \n        \\subsubsection{Indirect Method}\n        The indirect method involves taking all possibilities and subtracting those which are not wanted.\n        For instance, say you have 3 people that need to sit at a table, but 2 of them don't want to sit beside each other.\n        There is a step-by-step process that you can use for this question that is explained below.\n        \\begin{enumerate}\n                \\item Find all possible permutations (ex. P(3,3) ),\n                \\item Find all unwanted permutations (in this case when they are together),\n                \\item Subtract the unwanted permutations from the wanted permutations.\n            \\end{enumerate}\n        This can be written as:\n        \\begin{equation*}\n            \\mbox{\\textbf{Wanted Outcomes}} = \\mbox{Total Outcomes}-\\mbox{Unwanted Outcomes}\n        \\end{equation*}\n    \n        \\subsubsection{Case Method}\n        The Case Method involves breaking down the equation into manageable parts, then adding them to get the final solution.\n        There is a step-by-step example problem in Section 1 of the appendix, along with an explanation of why, and how you manage the \"breaking into parts\" aspect.\n    \n        \\subsubsection{Circular Arrangements}\n        Circular arrangements are no longer a part of the curriculum, and as such they will not be tested on, but they are still quite useful to know in niche cases.\n        If you have seven people seated at a table, and they all move to their rights, their positions may have moved, but their order remains the same, like a circle.\n        Keep in mind that if there is some fixed point, the question just ends into a typical linear arrangement, with the equation simplifying to $1 \\cdot (n-1)!$.", "meta": {"hexsha": "d4b44f920af3ef61c40b8d26ffe122d8c55d7989", "size": 6452, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "highschool-projects/MDM4UI/Permutations.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/Permutations.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/Permutations.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": 67.9157894737, "max_line_length": 316, "alphanum_fraction": 0.7078425294, "num_tokens": 1577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6298618950245528}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{pgfplots}\n\\usepackage{mathtools}\n\\usepackage{booktabs}\n\\usepackage{indentfirst}\n\n\\usetikzlibrary{angles, quotes}\n\n\\pgfplotsset{compat=newest}\n\n\\title{Multivariable Calculus}\n\\author{Linxuan Ma}\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*\\diff{\\mathop{}\\!\\mathrm{d}}\n\n\\theoremstyle{definition}\n\\newtheorem{defn}{Definition}[section]\n\\newtheorem{ex}{Exercise}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\abstract{Multivariable calculus is a useful concept in mathematical analysis. This document focuses on the differential and integral for multivariable calculus. The following notes are taken from MIT OCW $18.02$ Multivariable Calculus.}\n\t\n\t\\section{Vectors}\n\t\n\tA vector $\\vec{v}$ is a mathematical structure that has represents a tuple of direction and magnitude; its elements correspond to the cartesian coordinates of the represented point. A vector $\\vec{v} \\in \\RR^n$ represents a point in n-dimension.\n\t\n\tThe length $\\mov{v}$ of $\\vec{v} \\in \\RR^n$ is a scalar that represents its magnitude: $$\\mov{v} = \\sqrt{\\sum_{i=0}^{n}(\\vec{v}_i)^2}$$\n\t\n\tNote that a vector does not necessarily have a starting and ending point;  it merely represents an offset in a direction.\n\t\n\t\\subsection{Vector Arithmetic}\n\t\n\tMultiplying a vector by a scalar scales the individual elements by the scalar:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\ta \\\\ b\n\t\t\\end{bmatrix} * c = \n\t\t\\begin{bmatrix}\n\t\t\tac \\\\ bc\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tAddition of vectors is element-wise:\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\t\ta \\\\ b\n\t\\end{bmatrix} +\n\t\\begin{bmatrix}\n\t\tc \\\\ d\n\t\\end{bmatrix} =\n\t\\begin{bmatrix}\n\t\ta + c \\\\ b + d\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\t\\subsection{Dot Product}\n\t\n\t\\begin{defn}\n\t\tThe dot product of $\\vec{a}$ and $\\vec{b}$ is the sum of their element-wise product: $$\\vec{a} * \\vec{b} = \\sum_{i=0}^n \\vec{a}_i \\vec{b}_i$$\n\t\\end{defn}\n\t\n\tGeometrically, the product of two vector is the product of their magnitude and the $\\cos$ of their angle: $$\\vec{a} * \\vec{b} = \\mo{\\vec{a}} \\mo{\\vec{b}} \\cos \\theta$$\n\t\n\tConsider vector $\\vec{a} * \\vec{a}$, the resulting product should be   $\\mov{a}^2$, as $\\cos 0$ is $1$. Considering a triangle with angles $a$, $b$ and $c$ with angle $\\theta$ opposing side $c$, the above can be deduced from the law of $\\cos$: $$\\mov{c}^2 = \\mov{a}^2 + \\mov{b}^2 - 2\\mo{a}\\mo{b}\\cos \\theta$$\n\t\n\tSince $\\vec{c} = \\vec{a} - \\vec{b}$, it can be deduced that:\n\t\\begin{align*}\n\t\t\\mov{c}^2 = \\vec{c} * \\vec{c} &= (\\vec{a} - \\vec{b})*(\\vec{a} - \\vec{b}) \\\\\n\t\t&= \\vec{a} * \\vec{a} - \\vec{a} * \\vec{b} - \\vec{b} * \\vec{a} + \\vec{b} * \\vec{b}\\\\\n\t\t&= \\mov{a}^2 + \\mov{b}^2 - 2\\vec{a}\\vec{b}\n\t\\end{align*}\n\t\n\tAs shown in the last line of the transformation of $\\mov{c}^2$, $-2\\vec{a}\\vec{b} = -2\\mov{a}\\mov{b} \\cos \\theta$.\n\t\n\t\\subsection{Applications of Dot Product}\n\t\n\tDot product can be used to compute lengths and angles. Consider a $\\RR^3$ space with $P = (1, 0, 0)$, $Q = (0, 1, 0)$ and $R = (0, 0, 2)$, the angle $\\angle RPQ$ can be found with dot product:\n\t\\begin{align*}\n\t\t\\overrightarrow{PR} * \\overrightarrow{PQ} &= \\mo{\\overrightarrow{PR}} \\mo{\\overrightarrow{PQ}} \\cos \\theta \\\\\n\t\t\\cos \\theta &= \\frac{\\overrightarrow{PQ} * \\overrightarrow{PR}}{\\mo{\\overrightarrow{PQ}}\\mo{\\overrightarrow{PR}}}\n\t\\end{align*}\n\t\n\tBy plugging in our example, we obtain:\n\t\\begin{gather*}\n\t\t\\cos \\theta = \\frac{1 + 0 + 0}{\\sqrt{2} * \\sqrt{5}} = \\frac{1}{\\sqrt{10}}\n\t\\end{gather*}\n\t\n\tAnother application of dot product is to determine the orthogonality of two vectors, i.e. when are two vectors $a$ and $b$ perpendicular. Note that the sign of a dot product denotes the directional relation of the two vectors $a$ and $b$ with angle $\\theta$:\n\t\\begin{itemize}\n\t\t\\item $\\vec{a} * \\vec{b} > 0$ if $\\theta < 90$\n\t\t\\item $\\vec{a} * \\vec{b} = 0$ if $\\theta = 90$\n\t\t\\item $\\vec{a} * \\vec{b} > 0$ if $\\theta > 90$\n\t\\end{itemize}\n\t\n\tConsider the linear equation $x + 2y + 3z = 0$. The above equation can be written in the form of a dot product:\n\t\\begin{gather*}\n\t\t\\begin{bmatrix}\n\t\t\t1 \\\\ 2 \\\\ 3\n\t\t\\end{bmatrix} *\n\t\t\\begin{bmatrix}\n\t\t\tx \\\\ y \\\\ z\n\t\t\\end{bmatrix} = 0\n\t\\end{gather*}\n\tTherefore, the vector $\\iv{x, y, z}$ is perpendicular to $\\iv{1, 2, 3}$, making the former a plane, as $\\cos \\theta = 0$ where $\\theta$ is the angle between the two vectors.\n\t\n\t\\section{Cross Product}\n\t\n\tTo get the component $a_u$ of $\\vec{a}$ along unit vector $\\vec{u}$:\n\t\\begin{align*}\n\t\ta_u &= \\mov{a}\\cos{\\theta} \\\\\n\t\t&= \\mov{a}\\mov{u}\\cos{\\theta} \\\\\n\t\t&= \\vec{a} * \\vec{u}\n\t\\end{align*}\n\t\n\t\\subsection{Geometric Interpretation of Determinants}\n\t\n\tTo get the area of triangle $A$ with two edges denoted as vector $\\vec{a}$ and $\\vec{b}$ originating from point $O$, the area of $A$ is:\n\t\\begin{gather*}\n\t\t\\text{Area}(A) = \\frac{1}{2} \\mov{a}\\mov{b} \\sin \\theta\n\t\\end{gather*}\n\t\n\tThe above could be obtained with dot product considering the complement angle and $\\vec{a'}$ as $\\vec{a}$ after $90^\\circ$ rotation. $\\angle a'Oa = \\theta'$:\n\t\\begin{align*}\n\t\t\\text{Area}(A) &= \\frac{1}{2} \\mov{a}\\mov{b} \\sin \\theta \\\\\n\t\t&= \\vec{a'} * \\vec{b} \\\\\n\t\t&= \\iv{-a_2, a_1} * \\iv{b_1, b_2} \\\\\n\t\t&= a_1 b_2 - a_2 b_2\n\t\\end{align*}\n\t\n\tNote that the result of the above transformation is equivalent to the determinant of the matrix:\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\t\ta_1 & a_2 \\\\ b_1 & b_2\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\t\\subsection{Determinant in $R^3$}\n\t\n\tThe determinant of matrix $A = \\iv{\\vec{A}, \\vec{B}, \\vec{C}}^\\top$ is:\n\t\\begin{align*}\n\t\t\\mo{A} = a_1\n\t\t\\begin{vmatrix}\n\t\t\tb_2 & b_3 \\\\ c_2 & c_3\n\t\t\\end{vmatrix} - a_2\n\t\t\\begin{vmatrix}\n\t\t\tb_1 & b_3 \\\\ c_1 & c_3\n\t\t\\end{vmatrix} + a_3\n\t\t\\begin{vmatrix} \n\t\t\tb_1 & b_2 \\\\ c_1 & c_2\n\t\t\\end{vmatrix} \n\t\\end{align*}\n\t\n\tThe determinant of matrix $\\iv{\\vec{a}, \\vec{b}, \\vec{c}}$ is the volume of the parallelepiped formed by edges $\\vec{a}$, $\\vec{b}$ and $\\vec{c}$.\n\t\n\t\\subsection{Rotation of Vectors}\n\t\n\tVector $\\vec{v} = \\iv{a, b}$ after $90^\\circ$ rotation gives $\\iv{-b, a}$. Similarly, a clockwise rotation of $\\vec{v}$ in the clockwise direction gives $\\iv{b, -a}$.\n\t\n\t\\subsection{Cross Product's Geometric Interpretation}\n\t\n\tThe cross product of $\\vec{a}$ and $\\vec{b}$ is a vector $\\vec{a} \\times \\vec{b}$. The above cross product can be represented via the \"determinant\" of the matrix:\n\t\\begin{equation*}\n\t\\begin{bmatrix}\n\t\ti & j & k \\\\ a_1 & a_2 & a_3 \\\\ b_1 & b_2 & b_3\n\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tThe coefficients of $i$, $j$ and $k$ are the $x$, $y$ and $z$ component of the resulting vector respectively.\n\t\n\tConsider the parallelepiped $A$ formed by edges $\\vec{a}$, $\\vec{b}$ and $\\vec{c}$. Its volume is the area of the base scaled by the height $h_A$. We obtain:\n\t\\begin{align*}\n\t\t\\text{Area}(A) &= h_A * \\mo{\\vec{b} \\times \\vec{c}} \\\\\n\t\t&= \\left(\\vec{a} * \\frac{\\vec{b} \\times \\vec{c}}{\\mo{\\vec{b} \\times \\vec{c}}}\\right) * \\mo{\\vec{b} \\times \\vec{c}} \\\\\n\t\t&= \\vec{a} * (\\vec{b} \\times \\vec{c})\n\t\\end{align*}\n\t\n\tThe above equation can be expanded via the definition of cross product to display its equality with the determinant of $\\iv{\\vec{a}, \\vec{b}, \\vec{c}}^\\top$.\n\t\n\t\\subsubsection{Right Hand Rule}\n\t\n\tThe right hand rule is stupid. It doesn't work on people who can't tell left from right, like me. Soooooo basically given the cross product $\\vec{e} = \\vec{a} \\times \\vec{b}$ where $\\vec{e}$ is in the position of poking your eyes out, $\\vec{a}$ and $\\vec{b}$ are positioned in a counter-clockwise manner.\n\t\n\t\\section{Matrices}\n\t\n\tFirst, trivially: $$\\vec{a} \\times \\vec{b} = -\\vec{b} \\times \\vec{a}$$\n\t\n\t\\subsection{Application of Cross Product}\n\t\n\tGive $p_1$, $p_2$ and $p_3$ in $\\RR^3$ aligned along a hyperplane, the equation for the hyperplane $P(x, y, z)$ denotes the condition for $x$, $y$ and $z$ of a new given point $p$ for it to be contained in the hyperplane.\n\t\n\tOne approach is to consider if the vectors $\\overrightarrow{p_1p_3}$, $\\overrightarrow{p_1p_2}$ and $\\overrightarrow{p_1p}$ are in the same plane. In order words: $$\\det(\\iv{\\overrightarrow{p_1p}, \\overrightarrow{p_1p_2}, \\overrightarrow{p_1p_3}}) = 0$$.\n\t\n\tAnother approach is to obtain the cross product of $\\overrightarrow{p_1p_2}$ and $\\overrightarrow{p_1p_3}$, and see if the direction of the resultant vector (normal vector) is perpendicular to $\\overrightarrow{p_1p}$. In other words: $$\\overrightarrow{p_1p} * (\\overrightarrow{p_1p_2} \\times \\overrightarrow{p_1p_3}) =  0$$\n\t\n\t\\subsection{Linear Relations}\n\t\n\tMatrices encapsulate linear transformations. This is useful in scenarios such as change of basis, etc.\n\t\n\tConsider a change of basis from $\\iv{x_1, x_2, x_3}$ to $\\iv{u_1, u_2, u_3}$:\n\t\\begin{align*}\n\t\tu_1 &= 2x_1 + 3x_2 + 3x_3 \\\\\n\t\tu_2 &= 2x_1 + 4x_2 + 5x_3 \\\\\n\t\tu_3 &= x_1 + x_2 + 2x_3\n\t\\end{align*}\n\t\n\tThe above transformation can be represented via a matrix:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t2 & 3 & 3 \\\\ 2 & 4 & 5 \\\\ 1 & 1 & 2\n\t\t\\end{bmatrix} * \\begin{bmatrix}\n\t\t\tx_1 \\\\ x_2 \\\\ x_3\n\t\t\\end{bmatrix} = \\begin{bmatrix}\n\t\t\tu_1 \\\\ u_2 \\\\ u_3\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tThe product of two matrices $A * X$ is the combinations of dot products between the rows of $A$ and the columns of $X$. Therefore, for dimension $A \\in \\RR^{m*n}$ and $X \\in \\RR^{n*o}$, $A*X \\in \\RR^{m*o}$. Trivially, two matrices are only multiplicable if the width of $A$ equals the height of $X$ in $A*X$.\n\t\n\t\\subsection{Intuition of Matrix Multiplication}\n\t\n\tThe transformation $AB$ (as matrix product) represents applying transformation $B$ then applying transformation $A$:\n\t$$(AB)x = A(Bx)$$\n\t\n\tIn addition, matrix multiplication are not commutative, namely:\n\t$$AB \\neq BA$$\n\t\n\tIn other words, matrices form a semigroup under multiplication from what we've been currently given (actually a monoid, but identities are covered yet in lecture 3).\n\t\n\t(As I'm writing the last sentence the prof literally started to talk about identity matrices\\dots Screw it monoid it is.)\n\t\n\tAn identity matrix $I$ is a matrix that does nothing; it does not impose any linear transformation, and therefore for any matrix $A$:\n\t\\begin{align*}\n\t\tAI &= A \\\\\n\t\tIA &= A\n\t\\end{align*}\n\t\n\tAn identity matrix has $1$s on the diagonal, and $0$s elsewhere. An $\\RR^3$ identity matrix:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\t\\subsection{Linear Transformation}\n\t\n\tFor the linear transformation of rotation by $90^\\circ$ counter-clockwise, the corresponding matrix is:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\t0 & -1 \\\\ 1 & 0\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tThe above matrix performs the transformation:\n\t\\begin{equation*}\n\t\t\\begin{bmatrix}\n\t\t\tx \\\\ y\n\t\t\\end{bmatrix} \\to \\begin{bmatrix}\n\t\t\t-y \\\\ x\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\t\\subsubsection{Inverting Matrices}\n\t\n\tLinear transformations can be inverted (unless in certain scenarios). Similarly, matrices can be inverted, and their inverse represents the inverted linear transformation. Due to this, it is trivial that:\n\t$$AA^{-1} = I$$\n\t\n\tWith this property, the equation $AX = B$ (solving for $X$) can be rewritten as $X = A^{-1}B$ as $A^{-1}A = I$ on the LHS.\n\t\n\tGenerally, the inverse of matrix $A$ is:\n\t\\begin{gather*}\n\t\tA^{-1} = \\frac{1}{\\det(A)} \\adj(A)\n\t\\end{gather*}\n\t\n\t$\\adj(A)$ denotes the adjoint of $A$. To obtain the adjoint matrix we first calculate the minors, which has the same dimension as $A$, and each entry is the determinant of $A$ after removing the row and column that the entry belongs to. Consider:\n\t\\begin{equation*}\n\t\tA = \\begin{bmatrix}\n\t\t\t2 & 3 & 3 \\\\ 2 & 4 & 5 \\\\ 1 & 1 & 2\n\t\t\\end{bmatrix}\n\t\\end{equation*}\n\t\n\tFollowing the above steps, we obtain:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t3 & -1 & -2 \\\\ 3 & 1 & -1 \\\\ 3 & 4 & 2\n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\t\n\tThe cofactors is identical to the minors except for certain inversion in sign (signs are flipped in a checkerboard pattern) ($-$ denotes a flip in sign):\n\t\\begin{equation*}\n\t\t\\begin{matrix}\n\t\t\t+ & - & + \\\\ - & + & - \\\\ + & - & +\n\t\t\\end{matrix}\n\t\\end{equation*}\n\t\n\tLastly, the matrix is transposed to obtain the adjoint matrix. The adjoint matrix for the above $A$ is:\n\t\\begin{equation*}\n\t\t\\begin{pmatrix}\n\t\t\t3 & -3 & 3 \\\\ 1 & 1 & -4 \\\\ -2 & 1 & 2\n\t\t\\end{pmatrix}\n\t\\end{equation*}\n\t\n\t\\section{Equations of Planes}\n\t\n\tRecall that an equation for a plane is of the form (where $a$, $b$, $c$ and $d$ are constants):\n\t\\begin{gather*}\n\t\tax + by + cz = d\n\t\\end{gather*}\n\t\n\tTo illustrate, consider the equation for a plane through the origin with normal vector $\\vec{N} = \\iv{1, 5, 10}$. Trivially, for any point $\\vec{p}$ to be in the plane of interest, $\\vec{N} * \\vec{p} = 0$.\n\t\n\tSimilarly, consider the equation for a plane through $P_0 = \\iv{2, 1, -1}$ and normal vector $\\vec{N} = \\iv{1, 5, 10}$, $\\overrightarrow{P_0P} * \\vec{N} = 0$. In the above case:\n\t\\begin{align*}\n\t\t& \\overrightarrow{P_0P} * \\vec{N} = 0 \\\\\n\t\t\\iff & \\iv{x - 2, y - 1, z + 1} * \\iv{1, 5, 10} = 0 \\\\\n\t\t\\iff & (x - 2) + 5(y - 1) + 10(z + 1) = 0 \\\\\n\t\t\\iff & x + 5y + 10z = -3\n\t\\end{align*}\n\t\n\tAn easier method to obtain $-3$ is just to plug $P_0 = \\iv{2, 1, -1}$ into $x + 5y + 10z$, as $P_0$ acts as the \"origin\" of the plane.\n\t\n\tTo generalize, in equation $ax + by + cz = d$, $\\vec{N} = \\iv{a, b, c}$ is a normal vector to the plane described by the above equation.\n\t\n\tAs an example, consider $\\vec{v} = \\iv{1, 2, -1}$ and the plane described by $x + y + 3z = 5$. One normal vector of the plane is $\\vec{N} = \\iv{1, 1, 3}$. It is obvious that $\\vec{v}$ is not perpendicular to the plane. $\\vec{v}$ is perpendicular to $\\vec{N}$ since $\\vec{N} * \\vec{v} = 0$, thus $\\vec{v}$ is parallel to the plane.\n\t\n\t\\subsection{Linear Systems}\n\t\n\tA linear system is essentially a bunch of linear equations:\n\t\\begin{align*}\n\t\tx + z &= 1 \\\\\n\t\tx + y &= 2 \\\\\n\t\tx + 2y + 3z &= 3\n\t\\end{align*}\n\t\n\tTo find the common solution to the above system is to find a point $p$ that is contained in all three planes described by the above equations.\n\t\n\tThe solution is not as trivial when a plane contains the line formed by the other two planes, then there are infinitely many answers, as there are no constraints restricting the line. Similarly, if all three planes are parallel and overlapping, the result is a plane.\n\t\n\tThere is no solution for a linear system if the planes never intersects.\n\t\n\tAs a result of the above phenomenon, $AX = B \\iff X = A^{-1}B$ might not be always viable depending on the invertibility of the matrix $A$. A matrix $A$ is only invertible if the determinant of it is not $0$, i.e. $\\det(A) \\neq 0$, as $$\\det(A) = 0 \\iff \\text{one plane is parallel to the intersection line}$$.\n\t\n\t\\subsection{Homogeneous Case}\n\t\n\tA homogeneous case of the linear is when $AX = 0$, i.e. each equation is of the form $ax + by + cz = 0$. An obvious solution is $\\iv{0, 0, 0}$, referred to as the \\emph{trivial solution}. In other words, all the planes passes through the origin, making the origin a solution to the system.\n\t\n\tIf $\\det{A} \\neq 0$, then the inverse of $A$ can be used to solve for $X$. However, this is not very helpful:\n\t\\begin{gather*}\n\t\tAX = 0 \\iff X = A^{-1}0 \\Rightarrow X = \\iv{0, 0, 0}\n\t\\end{gather*}\n\t\n\tIn the case that $\\det(A) = 0$, recall that the coefficients of an equation is a normal vector to the plane:\n\t\\begin{align*}\n\t\t&\\det(A) = 0 \\\\\n\t\t\\iff &\\det(\\vec{N_1}, \\vec{N_2}, \\vec{N_3}) = 0 \\\\\n\t\t\\iff &\\text{$\\vec{N_1}$, $\\vec{N_2}$ and $\\vec{N_3}$ are coplanar}\n\t\\end{align*}\n\t\n\tRecall that $\\det(\\vec{N_1}, \\vec{N_2}, \\vec{N_3}) = 0$ means the volume of the parallelepiped formed by the three vectors is $0$.\n\t\n\tTherefore, the solution is the line through $0$ that is perpendicular to $\\vec{N_1}$, $\\vec{N_2}$ and $\\vec{N_3}$ (can be obtained via a simple cross product of the normal vectors). The solution in this case is non-trivial.\n\t\n\t\\subsection{General Case}\n\t\n\tFor linear system $AX = B$, if $\\det(A) \\neq 0$, then a unique solution exists: $X = A^{-1}B$. If $\\det(A) = 0$, then either no solutions or infinitely many solutions. We are not yet able to distinguish between the two cases with what the course has currently covered.\n\t\n\t\n\t\\section{Equation of Lines}\n\t\n\tDeriving from the previous lecture, we can see a line as the intersection of 2 planes. A more convenient representation of a line is by considering it as a trajectory of a moving point. This is referred to as a \\emph{parametric equation}.\n\t\n\tAs an example, consider points $Q_0$ and $Q_1$:\n\t\\begin{align*}\n\t\tQ_0 &= \\iv{-1, 2, 2} \\\\\n\t\tQ_1 &= \\iv{1, 3, -1}\n\t\\end{align*}\n\t\n\tThe line can be described as a trajectory (originating from $Q_0$) between the two points, namely:\n\t\\begin{align*}\n\t\tQ(t) &= Q_0 + t * (Q_1 - Q_0) \\\\\n\t\t&= Q_0 + t * \\iv{2, 1, -3}\n\t\\end{align*}\n\t\n\tTreating $Q$ as $Q(t) = \\iv{x(t), y(t), z(t)}$ and considering point $Q_0$, we obtain that:\n\t\\begin{align*}\n\t\tx(t) + 1 &= 2t \\\\\n\t\ty(t) - 2 &= t \\\\\n\t\tz(t ) - 2 &= -3t\n\t\\end{align*}\n\t\n\tReorder and we obtain:\n\t\\begin{align*}\n\t\tx(t) &= 2t - 1 \\\\\n\t\ty(t) &= t + 2\\\\\n\t\tz(t ) &= -3t + 2\n\t\\end{align*}\n\t\n\tIn other words, we've just shown that $Q(t) = Q_0 + t * \\overrightarrow{Q_0Q_1}$\n\t\n\t\\subsection{Applications}\n\t\n\tThe equation of a line can be used to check if it intersects with a plane and where. Consider the plane $x + 2y + 4z = 7$, what orientation do $Q_0$ and $Q_1$ have in respect to the plane?\n\t\n\tBy plugging $Q_0$ and $Q_1$ into the plane equation, we obtain:\n\t\\begin{align*}\n\t\tx + 2y + 4z &= -1 + 2*2 + 4*2 = 11 > 7 \\\\\n\t\tx + 2y + 4z &= 1 + 2*3 + 4*(-1) = 3 < 7\n\t\\end{align*}\n\t\n\tThus, neither $Q_0$ or $Q_1$ lies in the plane. However, by observing how the result of plugging in the points lie on different subspaces (as denoted by $>7$ and $<7$), $Q_0$ and $Q_1$ are on different side of the plane.\n\t\n\tTo obtain the intersection of the plane with the line, we plug in $t$ into the line equation:\n\t\\begin{align*}\n\t\t&x(t) + 2y(t) + 4z(t) \\\\\n\t\t= &(-1 + 2t) + 2(2 + t) + 4(2 - 3t) \\\\\n\t\t= &-8t + 11\n\t\\end{align*}\n\t\n\tThis is compared to plane equation: the line intersects at the point where $-8t + 11 = 7$.\n\t\n\tThe specific point can be obtained via:\n\t\\begin{align*}\n\t\tQ(\\frac{1}{2}) = \\iv{0, \\frac{5}{2}, \\frac{1}{2}}\n\t\\end{align*}\n\t\n\t\\subsection{Parametric Equations}\n\t\n\tParametric Equations are excellent at representing a curve/trajectory in space. In general, parametric equations can represent arbitrary motions in a given space.\n\t\n\t\\begin{defn}\n\t\tA \\emph{cycloid} is formed as the trajectory of a point on a rolling wheel with radius $r$.\n\t\\end{defn}\n\t\n\tThis poses the problem of determining the position of the given point, $p \\in \\RR^2$, after rotation $\\theta$:\n\t\\begin{gather*}\n\t\tp(\\theta) = \\iv{x(\\theta), y(\\theta)}\n\t\\end{gather*}\n\t\n\tFor a circle centered around $B$ on the horizontal axis (with point $A$ intersecting with the axis on the circumference), the vector $\\overrightarrow{OP}$ (where $P$ is another point on the circumference) can be obtained via:\n\t\\begin{gather*}\n\t\t\\overrightarrow{OP} = \\overrightarrow{OA} + \\overrightarrow{AB} + \\overrightarrow{BP}\n\t\\end{gather*}\n\t\n\tSince the wheel is rolling, the arc length on the circumference from $A$ to $P$ is equal to $\\mo{\\overrightarrow{OA}}$:\n\t\\begin{gather*}\n\t\t\\overrightarrow{OA} = \\iv{a \\theta, 0}\n\t\\end{gather*}\n\t\n\t$\\mo{\\overrightarrow{AB}}$ is trivial, as its magnitude is simply the radius of the wheel. With regard to the angle $\\theta$, we obtain that:\n\t\\begin{gather*}\n\t\t\\overrightarrow{BP} = \\iv{-a \\sin \\theta, -a \\cos \\theta}\n\t\\end{gather*}\n\t\n\tTherefore, we obtain that:\n\t\\begin{gather*}\n\t\t\\overrightarrow{OP} = \\iv{a\\theta - a \\sin \\theta, a - a \\cos \\theta}\n \t\\end{gather*}\n \t\n \t\\subsection{Taylor Expansion Approximation}\n \t\n \tIn order to explore the shape of the trajectory of $P$ (from the above section) around $\\theta = 0$, we can utilize the Taylor expansion to estimate the ratio of $\\frac{\\Delta y}{\\Delta x}$. Consider a wheel with radius $1$:\n \t\\begin{align*}\n \t\tx(\\theta) &= \\theta - \\sin \\theta \\\\\n \t\ty(\\theta) &= 1 - \\cos \\theta\n \t\\end{align*}\n \t\n \tRecall the Taylor approximation:\n \t\\begin{gather*}\n \t\t\\lim_{t \\to 0} = f(0) + tf'(0) + \\frac{t^2}{2!}f''(0) + \\frac{t^3}{3!}f'''(0) + \\dots\n \t\\end{gather*}\n \t\n \tIn our case, we obtain that:\n \t\\begin{align*}\n \t\t\\sin \\theta &= \\theta - \\frac{\\theta^3}{6} \\\\\n \t\t\\cos \\theta &= 1 - \\frac{\\theta^2}{2}\n \t\\end{align*}\n \t\n \tPlugging back into the original formula, we obtain:\n \t\\begin{align*}\n \t\tx(\\theta) &\\approx \\theta - (\\theta - \\frac{\\theta^3}{6}) \\approx \\frac{\\theta^3}{6} \\\\\n \t\ty(\\theta) &\\approx 1 - (1 - \\frac{\\theta^2}{2}) \\approx \\frac{\\theta^2}{2}\n \t\\end{align*}\n \t\n \tCalculating $y/x$ yields:\n \t\\begin{gather*}\n \t\t\\frac{y}{x} \\approx \\frac{\\theta^2 / 2}{\\theta^3 / 6} \\approx \\frac{3}{\\theta}\n \t\\end{gather*}\n \t\n \tThe above value approaches $\\infty$ as $\\theta \\to 0$.\n \t\n \t\\section{Velocity and Kepler's Second Law}\n\t\n\t\\begin{defn}\n\t\t\\emph{Velocity} is the derivative of displacement in respect of time:\n\t\t\\begin{gather*}\n\t\t\t\\vec{v} = \\frac{\\diff \\vec{r}}{\\diff t} = \\iv{\\frac{\\diff x}{\\diff t}, \\frac{\\diff y}{\\diff t}, \\frac{\\diff z}{\\diff t}}\n\t\t\\end{gather*}\n\t\\end{defn}\n\t\n\t\\subsection{Velocity}\n\t\n\tIn the case of the cycloid (from the previous section), recall that the displacement of point $p$ on the circumference of the wheel ($p = \\vec{0}$ initially, when $\\theta = 0$) is obtained via:\n\t\\begin{gather*}\n\t\t\\vec{r}(t) = \\iv{t - \\sin t, 1 - \\cos t}\n\t\\end{gather*}\n\t\n\tIts velocity vector is obtained by differentiating the function of each axis:\n\t\\begin{gather*}\n\t\t\\vec{v} = \\iv{1 - \\cos t, \\sin t}\n\t\\end{gather*}\n\t\n\tNotice that when $t=0$, $\\vec{v} = \\iv{0, 0}$. This is trivial, as $p$ indeed isn't moving at that instant.\n\t\n\tTo obtain the magnitude of $\\vec{v}$, we use Pythagoras theorem:\n\t\\begin{align*}\n\t\t\\mo{\\vec{v}} &= \\sqrt{(1 - \\cos t)^2 + \\sin^2 t} \\\\\n\t\t&= \\sqrt{1 - 2 \\cos t + \\cos^2 t + \\sin^2 t} \\\\\n\t\t&= \\sqrt{2 - 2 \\cos t}\n\t\\end{align*}\n\t\n\t\\subsection{Acceleration}\n\t\n\t\\begin{defn}\n\t\t\\emph{Acceleration} is the derivative of the velocity vector:\n\t\t\\begin{gather*}\n\t\t\t\\vec{a} = \\frac{\\diff \\vec{v}}{\\diff \\vec{t}}\n\t\t\\end{gather*}\n\t\\end{defn}\n\t\n\tStill considering the above example of cycloid, we notice that the acceleration of $p$ is $\\vec{a} = \\iv{\\sin t, \\cos t}$. At point $t = 0$, notice that the acceleration of $p$ is $\\vec{0, 1}$, which agrees with the result that we obtained via Taylor approximation.\n\t\n\t\\subsection{Arc Length}\n\t\\begin{defn}\n\t\tThe \\emph{arc length} is the distance traveled along the curve. In the example above (cycloid), the arc length is simply the portion of the circumference which $p$ has traveled.\n\t\\end{defn}\n\t\n\tTo relate arc length $s$ to time $t$, notice the relation that the rate of change of arc length is the speed at which the point is moving. Therefore, to obtain the arc length (circumference) of the trajectory of point $p$ with a given function describing $p$'s displacement, we simple integrate the magnitude of the speed (which is equivalent to $\\vec{v}$'s magnitude):\n\t\\begin{gather*}\n\t\t\\int_0^{2\\pi}\\sqrt{2 - 2 \\cos t}\\ \\diff t\n\t\\end{gather*}\n\t\n\t\\subsection{Unit Tangent Vector}\n\t\n\t\\begin{defn}\n\t\tA \\emph{unit tangent ventor} $\\hat{T}$ is the normalized tangent at a given point on the function:\n\t\t\\begin{gather*}\n\t\t\t\\hat{T} = \\frac{\\vec{v}}{\\mo{\\vec{v}}}\n\t\t\\end{gather*}\n\t\\end{defn}\n\t\n\tNotice that (where $s$ denotes the speed of $p$):\n\t\\begin{gather*}\n\t\t\\vec{v} = \\frac{\\diff \\vec{r}}{\\diff t} = \\frac{\\diff \\vec{r}}{\\diff s}\\frac{\\diff s}{\\diff t}\n\t\\end{gather*}\n\t\n\tTherefore, it is trivial that:\n\t\\begin{align*}\n\t\t\\mo{\\vec{v}} &= \\frac{\\diff s}{\\diff t} \\\\\n\t\t\\hat{T} &= \\frac{\\diff s}{\\diff t}\n\t\\end{align*}\n\t\n\t\\subsection{Kepler's Second Law}\n\t\n\tKepler's second law is a good example for exploring the motivation for analyzing motions with vectors. Kepler's laws are about generalizing the motion of planets orbiting a central sun in an ellipse.\n\t\n\t\\begin{defn}\n\t\t\\emph{Kepler's second law} states that the planar motion of an orbiting planet satisfies that the rate of the area swept out by the line from the sun to the planet as the planet orbits is constant. \n\t\\end{defn}\n\t\n\tIn terms of vectors, consider the position vector $\\vec{r}$ originating from the sun to the planet. $\\Delta r$ is the planet's change in displacement over $\\Delta t$.\n\t\n\tSince $\\Delta r$ is sufficiently small, we can consider the area of the sector as a triangle enclosed by $\\vec{r_1}$, $\\vec{r_2}$ and $\\Delta \\vec{r}$. The area of the sector is then given by (recall that $\\Delta \\vec{r} = \\vec{v} \\Delta t$):\n\t\\begin{align*}\n\t\t\\text{Area} &\\approx \\frac{1}{2} \\mo{\\vec{r} \\times \\Delta \\vec{r}} \\\\\n\t\t& \\approx \\frac{1}{2} \\mo{\\vec{r} \\times \\vec{v}} \\Delta t\n\t\\end{align*}\n\t\n\tTherefore, Kepler's second law is equivalent to stating that $\\vec{r} \\times \\vec{v}$ is constant, and therefore has a derivative of $0$ in respect to $t$:\n\t\\begin{align*}\n\t\t&\\frac{\\diff}{\\diff t} (\\vec{r} \\times \\vec{v}) = 0 \\\\\n\t\t\\iff &\\frac{\\diff \\vec{r}}{\\diff t} \\times \\vec{v} + \\vec{r} \\times \\frac{\\diff v}{\\diff t} = 0 \\\\\n\t\t\\iff &\\vec{v} \\times \\vec{v} + \\vec{r} \\times \\vec{a} = 0 \\\\\n\t\t\\iff &0 + \\vec{r} \\times \\vec{a} = 0 \\\\\n\t\t\\iff &\\vec{r} \\times \\vec{a} = 0\n\t\\end{align*}\n\t\n\tTherefore, Kepler's second law is stating that the acceleration vector is parallel to the change of position in the orbit.\n\t\n\t\\section{Multivariable Functions}\n\t\n\tA multivariable function is a function that takes in multiple parameters. An example would be $f(x, y) = x^2 + y^2$.\n\t\n\tSimilar to a regular function, a multivariable function can have a domain:\n\t\\begin{align*}\n\t\tf(x, y) &= \\sqrt{y},\\ y \\geq 0 \\\\\n\t\tf(x, y) &= \\frac{1}{x + y},\\ x + y \\neq 0\n\t\\end{align*}\n\t\n\tThe visualization of such functions can be a bit tricky. Consider the case of a 2-variable function, its graph can be plotted in an $\\RR^3$ space where the height at $(x, y)$ is $f(x, y)$.\n\t\n\tConsider the function $f(x, y) = 1 - x^2 - y^2$. To plot a graph for this function, consider the graph on the individual xz-plane and yz-plane (i.e. when the other axis is at $0$). This will result in $z = 1 - x^2$ and $z = 1 - y^2$ respectively.\n\t\n\tNote that the shape of the intersection of function $f(x, y) = 1 - x^2 - y^2$ on the xy-plane can be obtained via setting the value on the z-axis to $0$, i.e.:\n\t\\begin{align*}\n\t\t&1 - x^2 - y^2 = 0 \\\\\n\t\t\\iff &x^2 + y^2 = 0\n\t\\end{align*}\n\t\n\tThus, the intersection is a unit circle.\n\t\n\t\\subsection{Contour Graph}\n\t\n\tA contour graph is a slice of the graph of a 2-variable function by a horizontal plane. Each section in a contour map represents ab area of (approximately) same height.\n\t\n\tConsider the contour plot for function $f(x, y) = 1 - x^2 - x^2$, its contour plot consists of various circles around the origin. The density of circles increases the further away from the origin, indicating an increase in the slope of the function (as less distance for a change of $1$ in height).\n\t\n\t\\subsection{Derivatives}\n\t\n\tIn a regular function $f(x)$, the derivative of $f(x)$ is its change in respect to $x$, namely:\n\t\\begin{equation*}\n\t\t\\lim_{h \\to 0} \\frac{f(x + h) - f(x)}{h}\n\t\\end{equation*}\n\t\n\tIn other words, the derivative of a function is a function of its slope.\n\t\n\t\\subsection{Linear Approximation Formula}\n\t\n\tTo approximate $f(x)$ when given $f(x_0)$ where $x_0$ is a value close to $x$, the value $f(x)$ can be approximated via $f(x)$'s first derivative:\n\t\\begin{equation*}\n\t\tf(x) = f(x_0) + f'(x_0) * (x - x_0)\n\t\\end{equation*}\n\t\n\t\\subsection{Partial Derivatives}\n\t\n\tWith a function with more than one parameter, a derivative can be taken with respect to any one parameter. This can be interpreted as the change in the output value in respect to a change in one of its parameter.\n\t\n\tFor example, consider a 2-variable function $f(x, y)$. Its partial derivative in respect to $x$ is defined as:\n\t\\begin{gather*}\n\t\t\\frac{\\partial f}{\\partial x}(x, y) = \\lim_{h \\to 0} \\frac{f(x + h, y) - f(x, y)}{h}\n\t\\end{gather*}\n\t\n\tThis can be interpreted similar to the \"slice by a plane\" analogy used previously when describing contour graphs. To differentiate in respect to $x$ is to consider the change in the hyperplane of all other axis when $x$ changes (e.g. the change in the yz-plane when $x$ moves in $f(x, y)$).\n\t\n\t\\section{Partial Derivatives and Tangents}\n\t\n\tAs mentioned previously, a 2-variable function $f(x, y)$ has two derivatives each in the direction of an axis.\n\t\n\tConsider its tangent line $L_x$; if $\\frac{\\partial f}{\\partial x}(x_0, y_0) = a$, then the line is described by $y = y_0$ and $z = z_0 + a(x - x_0)$.\n\t\n\tSimilarly, the tangent line $L_y$ being described by $\\frac{\\partial f}{\\partial y}(x_0, y_0) = b$ is the line specified by $x = x_0$ and $z = z_0 + b(y - y_0)$.\n\t\n\t$L_x$ and $L_y$ are both tangent to the graph $f(x, y)$, and determines the plane\n\t\\begin{gather*}\n\t\tz = z_0 + a(x - x_0) + b(y - y_0)\n\t\\end{gather*}\n\t\n\tNote that by fixing either $x$ or $y$ in the above equation, the tangent for $y$ and $x$ is obtained respectively. The above plane is the tangent plane of $f$ at a given point $(x, y)$.\n\t\n\t\\subsection{Minima and Maxima}\n\t\n\tIf a given point $(x, y)$ is the local minimum or maximum, then its derivative in either direction is $0$. This is equivalent to stating that the tangent plane at a minimum/maximum is a horizontal plane.\n\t\n\tNote that having $0$ as all partial derivatives is a necessary but insufficient condition for a minimum/maximum.\n\t\n\tSuch a point $(x_0, y_0)$ is referred to as a \\emph{critical point} of $f$, given that $f_x(x_0, y_0) = 0$ and $f_y(x_0, y_0) = 0$ (note the partial derivative notation of $f$).\n\t\n\tConsider the function $f(x, y) = x^2 - 2xy + 3y^2 + 2x - 2y$. To identify the critical points of $f$, its partial derivatives can be taken:\n\t\\begin{align*}\n\t\t\\frac{\\partial f}{\\partial x}(x, y) &= 2x - 2y + 2 \\\\\n\t\t\\frac{\\partial f}{\\partial y}(x, y) &= -2x + 6y - 2\n\t\\end{align*}\n\t\n\tThe critical point can thus be obtained by solving the system:\n\t\\begin{align*}\n\t\t2x - 2y + 2 &= 0 \\\\\n\t\t-2x + 6y - 2 &= 0\n\t\\end{align*}\n\t\n\tThus, the only critical point of $f$ is $(-1, 0)$; however, identifying the critical point is insufficient to identify whether it is a maximum or minimum; a critical point can be a minimum (positive second derivatives in all axes), a maximum (negative second derivatives in all axes), or a saddle point (differently signed second derivative in different directions, i.e. anything that is not an extremum).\n\t\n\tNote that the above $f$ can be rewritten by completing the square:\n\t\\begin{align*}\n\t\tf(x, y) &= (x - y)^2 + 2y^2 + 2x - 2y \\\\\n\t\t&= ((x - y) + 1)^2 + 2y^2 - 1\n\t\\end{align*}\n\t\n\tIn this form, it is trivial to identify the minimum of $f$. Since both $((x - y) + 1)^2$ and $y^2$ are squares, their minimum value is $0$, thus the minimum of $f$ is $0 - 1 = -1$. However such an approach is obviously not feasible for all functions.\n\t\n\t\\subsection{Application of Minimum/Maximum}\n\t\n\tLeast-square interpolation is to find the best fit line given a set of data. The following example considers a 2D dataset of points $(x, y)$ and fits the line $y = mx + b$.\n\t\n\tThe loss function can be interpreted as how bad a line fits the data, and the aim of least-square interpolation is to minimize the loss function. This is simply a sum of the square of deviations for each point in the dataset:\n\t\\begin{gather*}\n\t\t\\min_{m, b} \\sum^n_{i=1} [y_i - (mx_i + b)]^2\n\t\\end{gather*}\n\t\n\tTo minimize such a function, we can identify its critical point by taking the function's partial derivatives in respect to $m$ and $b$ (where $L$ is the loss function):\n\t\\begin{align*}\n\t\t\\frac{\\partial L}{\\partial m} &= \\sum^n_{i=1} [2 * (y_i - (mx_i + b)) * (-x_i)] \\\\\n\t\t\\frac{\\partial L}{\\partial b} &= \\sum^n_{i=1} [2 * (y_i - (mx_i + b)) * (-1)]\n\t\\end{align*}\n\t\n\tTo obtain the critical point of the loss function, we find $m$ and $b$ such that both derivatives is zero. With some reordering:\n\t\\begin{align*}\n\t\t\\sum^n_{i=1} \\left(mx^2_i + bx_i - x_iy_i \\right) = 0 &\\iff \\left(\\sum^n_{i=1}x^2_i \\right)m + \\left(\\sum^n_{i=1}x_i \\right) b = \\sum^n_{i=1}x_iy_i\\\\\n\t\t\\sum^n_{i=1} (mx_i + b - y_i) = 0 &\\iff \\left(\\sum^n_{i=1} x_i\\right)m + nb = \\sum^n_{i=1} y_i\n\t\\end{align*}\n\t\n\tThe above is simply a linear system.\n\t\n\t\\section{Global Maximum/Minimum}\n\t\n\tRecall that a critical point is a point where the tangent plane is horizontal. This could be a local minimum, local maximum, or saddle point.\n\t\n\tTo obtain the global min/max, however, requires more information about the function, such as how it behaves at $\\infty$ (or its boundary). Note that the global min/max can only occur at either a critical point or on the function's boundary (or $\\infty$ for an unbounded function).\n\t\n\tSimilar to a single variable function, the second derivative can be used to gain more observations of the behaviors of the function.\n\t\n\t\\subsection{Second Derivative Test}\n\t\n\tConsider the function $w = a^2 + bxy + cy^2$. This function has a critical point at the origin. With a linear approximation by plugging in a sufficiently small $x$ or $y$ value, it can be observed that the tangent plane at the origin is indeed horizontal.\n\t\n\tRecall the example from last lecture $w = x^2 + 2xy + 3y^2$. This can be rewritten as $w = (x + y)^2 + 2y^2$. Being the sum of two squares, the origin would be a minimum as both terms are non-negative.\n\t\n\tSimilarly, such a method can be applied to the generalized $w = a^2 + bxy + cy^2$ (where $a \\neq 0$):\n\t\\begin{align*}\n\t\tw &= a(x^2 + \\frac{b}{a}xy) + cy^2 \\\\\n\t\t&= a(x + \\frac{b}{2a}y)^2 + (c - \\frac{b^2}{4a})y^2 \\\\\n\t\t&= \\frac{1}{4a}[4a^2(x+\\frac{b}{2a}y)^2 + (4ac-b^2)y^2]\n\t\\end{align*}\n\t\n\tThis is yet another a sum of two squares, and therefore it can be observed that going in any direction from the origin results in an increase in height, thus concluding that the origin is the minimum.\n\t\n\t\\subsection{Cases of Quadratics}\n\t\n\tConsidering the above form of sum of two squares for quadratics, there are three cases of quadratic functions:\n\t\\begin{enumerate}\n\t\t\\item $4ac - b^2 < 0$: The first term would be $\\geq 0$, while the second term would be $\\leq 0$. Therefore, the critical point of this quadratic is a saddle point.\n\t\t\\item $4ac - b^2 = 0$: The second term would be $0$, thus the height along a certain direction would be $0$. In other words, the entire axis would be critical points. This is referred to as the degenerate critical point.\n\t\t\\item $4ac - b^2 > 0$: The equation would simply be the sum of two squares, and therefore the behavior of the function is dependent on the sign of $a$ as it dictates the sign of the function. If $a > 0$, the function would be increasing in all directions from the origin, thereby making it a minimum. Dually, if $a < 0$, the origin would be a maximum.\n\t\\end{enumerate}\n\t\n\tNote the resemblance of $4ac - b^2$ to the discriminant $\\Delta = b^2 - 4ac$. Recall the $w$ function $w = ax^2 + bxy + cy^2$. It can be reordered as:\n\t\\begin{gather*}\n\t\tw = y^2 [a(\\frac{x}{y})^2 + b(\\frac{x}{y})+ c]\n\t\\end{gather*}\n\t\n\tIf $\\Delta > 0$, then there exists multiple solutions, thereby the result of $w$ spans both the $> 0$ space and the $< 0$ space (as the function crosses w = 0). Therefore, the critical point of $w$ is a saddle point.\n\t\n\tIf $\\Delta < 0$, then there is no intersection of the function with the $w = 0$ plane. In this case, the function is either always positive or always negative depending on the sign of $a$. Therefore, the critical point is either a maximum or a minimum.\n\t\n\t\\subsection{Generalized Case}\n\t\n\tFor a generic function, a similar analysis method can be incorporated by observing its second derivatives.\n\t\n\tFor simplicity, another symbol for the second derivative of a function $f$ is:\n\t\\begin{gather*}\n\t\tf_{xy} = \\frac{\\partial^2 f}{\\partial x \\partial y}\n\t\\end{gather*}\n\t\n\tNote that the order of taking the derivatives does not matter. In other words, $f_{xy} = f_{yx}$.\n\t\n\tThus, we can conclude that for a two-variable function, there are three second derivatives: $f_{xx}$, $f_{xy}$ (= $f_{yx}$), and $f_{yy}$.\n\t\n\t\\begin{defn}\n\t\tThe \\emph{second derivative test} states that at a critical point $p = (x_0, y_0)$ of function $f$, then there are four cases to consider:\n\t\t\\begin{enumerate}\n\t\t\t\\item $f_{xx}(p) * f_{yy}(p) - f_{xy}(p)^2 > 0$ and $f_{xx}(p) > 0$: The critical point is a local minimum.\n\t\t\t\\item $f_{xx}(p) * f_{yy}(p) - f_{xy}(p)^2 > 0$ and $f_{xx}(p) < 0$: The critical point is a local maximum.\n\t\t\t\\item $f_{xx}(p) * f_{yy}(p) - f_{xy}(p)^2 < 0$: The critical point is a saddle point.\n\t\t\t\\item $f_{xx}(p) * f_{yy}(p) - f_{xy}(p)^2 = 0$: Cannot conclude.\n\t\t\\end{enumerate}\n\t\\end{defn}\n\t\n\tTo verify, consider the special case $w = ax^2 + bxy + cy^2$ mentioned above. Its first order derivatives are:\n\t\\begin{align*}\n\t\tw_x &= 2ax + by \\\\\n\t\tw_y &= bx + 2cy\n\t\\end{align*}\n\t\n\tBy further differentiation, we obtain:\n\t\\begin{align*}\n\t\tw_{xx} &= 2a \\\\\n\t\tw_{xy} &= b\\\\\n\t\tw_{yy} &= 2c\n\t\\end{align*}\n\t\n\tThus, $f_{xx}(p) * f_{yy}(p) - f_{xy}(p)^2$ is $4ac - b^2$ in this case. By considering the different cases above, it can be observed that this special case indeed satisfies the rules described above.\n\t\n\t\\subsection{Quadratic Approximation}\n\t\n\tConsider the function $f(x, y)$, the change in $f$ as $x$ or $y$ changes a little bit should be able to be approximated by:\n\t\\begin{gather*}\n\t\t\\Delta f \\approx f_x * (x - x_0) + f_y * (y - y_0)\n\t\\end{gather*}\n\t\n\tHowever, note that $\\Delta f = 0$ at critical points. To better approximate the function, its second derivative can be considered:\n\t\\begin{align*}\n\t\tf &\\approx f_x * (x - x_0) + f_y * (y - y_0) \\\\\n\t\t&+ \\frac{1}{2} f_{xx} * (x - x_0)^2 + f_{xy} (x - x_0)(y - y_0) \\\\\n\t\t&+ \\frac{1}{2} f_{yy} * (y - y_0)^2\n\t\\end{align*}\n\t\n\tTo acquire a more accurate approximation, the function's higher order derivatives can be considered. However, the current second order approximation reduces the generalized $f$ to a quadratic function. Note that the coefficients of the quadratic terms correspond to the $a$, $b$ and $c$ terms in a quadratic as mentioned before, yet scaled by $\\frac{1}{2}$.\n\t\n\tIn the degenerate case, however, the above approximation formula is only reasonable only if the higher order terms are negligible. Since in a non-degenerate case, the shape of the formula is determined by the quadratic terms, yet in the degenerate case, a small shift in the critical point axis can alter the shape of the function such that the critical point is a minimum/maximum, thus not qualifying as the degenerate case. In other words, what happens in the degenerate case depends on higher order derivatives (this will not be covered in this class, so we refer to it as \"cannot conclude\" at the moment).\n\t\n\tFor example, consider the function where $x, y > 0$:\n\t\\begin{gather*}\n\t\tf(x, y) = x + y + \\frac{1}{xy}\n\t\\end{gather*}\n\t\n\tTo obtain the critical points for the above function, we compute the first derivative:\n\t\\begin{align*}\n\t\tf_x &= 1 - \\frac{1}{x^2y} \\\\\n\t\tf_y &= 1 - \\frac{1}{xy^2}\n\t\\end{align*}\n\t\n\tThe equation for the critical point(s) become:\n\t\\begin{align*}\n\t\tx^2y = 1 \\\\\n\t\txy^2 = 1\n\t\\end{align*}\n\t\n\tThus $x=1$ and $y=1$, at which point the second derivatives of $f$ is:\n\t\\begin{align*}\n\t\tf_{xx} &= \\frac{2}{x^3y} \\\\\n\t\tf_{xy} &= \\frac{1}{x^2y^2} \\\\\n\t\tf_{yy} &= \\frac{2}{xy^3}\n\t\\end{align*}\n\t\n\tBy computing $AC - B^2$, we obtain that $(1, 1)$ is either a local minimum or maximum. Since $A > 0$ (or $f_{xx} > 0$), the value of the function as $x$ approaches $\\infty$ is $\\infty$, thus $f(1, 1)$ is a local minimum.\n\t\n\t\\section{Differentials and Chain Rule}\n\t\n\tConsider $y = \\sin^{-1}(x)$. When written in terms of $y$ we obtain $x = \\sin(y)$. From implicit differentiation, it can be obtained that $\\diff x = cos(y) \\diff y$, and via algebra we obtain that:\n\t\\begin{gather*}\n\t\t\\frac{\\diff y}{\\diff x} = \\frac{1}{\\cos(y)} = \\frac{1}{\\sqrt{1 - x^2}}\n\t\\end{gather*}\n\t\n\tThis concept can be extended to functions with multiple parameters.\n\t\n\t\\subsection{Total Differentials}\n\t\n\tConsider the function $f(x, y, z)$, then $\\diff f = f_x \\diff x + f_y \\diff y + f_z \\diff z$. Note that $\\diff f$ is NOT $\\Delta f$. $\\diff f$ is like a placeholder for input, and when saturated, returns an approximation (linear) of $\\diff f$.\n\t\n\tThe uses of total differentials are as follows:\n\t\\begin{enumerate}\n\t\t\\item encodes how changes in the parameter affect $f$\n\t\t\\item acts as a placeholder to get an approximation formula $\\Delta f \\approx f_x \\Delta x + f_y \\Delta y + f_z \\Delta z$\n\t\t\\item divide by something to get a rate of change: such as \n\t\t\\begin{gather*}\n\t\t\t\\frac{\\diff f}{\\diff t} = f_x \\frac{\\diff f}{\\diff x} + f_y \\frac{\\diff f}{\\diff y} + f_z \\frac{\\diff f}{\\diff z}\n\t\t\\end{gather*}\n\t\\end{enumerate}\n\t\n\t\\subsubsection{Justification for Division by Differentials}\n\t\n\tTo justify the third use case, consider $\\diff f = f_x \\diff x + f_y \\diff y + f_z \\diff z$. The differential for each component is:\n\t\\begin{align*}\n\t\t\\diff x &= x'(t) \\diff t \\\\\n\t\t\\diff y &= y'(t) \\diff t \\\\\n\t\t\\diff z &= z'(t) \\diff t\n\t\\end{align*}\n\tTherefore $\\diff f = f_x * x'(t) \\diff t + f_y * y'(t) \\diff t + f_z * z'(t) \\diff t$. Division by $\\diff t$ yields the chain rule.\n\t\n\tAnother approach for proving the formula is by considering the approximation $\\Delta f \\approx f_x \\Delta x + f_y \\Delta y + f_z \\Delta z$. Division by $\\Delta t$ yields:\n\t\\begin{gather*}\n\t\t\\frac{\\Delta f}{\\Delta t} \\approx \\frac{f_x \\Delta x + f_y \\Delta y + f_z \\Delta z}{\\Delta t}\n\t\\end{gather*}\n\t\n\tThis is much more trivial to understand, as $\\Delta t$ is simply a scalar value, unlike the differential division in the previous justification method.\n\t\n\tAs $\\Delta t$ approaches $0$, $\\frac{\\Delta f}{\\Delta t} \\to \\frac{\\diff f}{\\diff t}$, $\\frac{\\Delta x}{\\Delta t} \\to \\frac{\\diff x}{\\diff t}$, $\\dots$\n\t\n\tTherefore, the above approximation is reasonable as $\\Delta t \\to 0$.\n\t\n\t\\subsubsection{Example}\n\t\n\tConsider the function $w = x^2 y + z$ where $x, y, z \\in \\RR \\to \\RR$ are functions of $t$:\n\t\\begin{align*}\n\t\tx &= t \\\\\n\t\ty &= e^t \\\\\n\t\tz &= \\sin t\n\t\\end{align*}\n\t\n\tThe chain rule suggests that:\n\t\\begin{align*}\n\t\t\\frac{\\diff w}{\\diff t} &= 2xy \\frac{\\diff x}{\\diff t} + x^2 \\frac{\\diff y}{\\diff t} + 1 \\frac{\\diff z}{\\diff t} \\\\\n\t\t&= 2 * (t * e^t) + t^2 * e^t + \\cos t\n\t\\end{align*}\n\t\n\t\n\t\n\t\n\t\\end{document}\n", "meta": {"hexsha": "996c8cbc670d67819ac701e1d052a14a5d7be939", "size": 42262, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multivar-calculus/multivar-calculus.tex", "max_stars_repo_name": "davidmaamoaix/lecture-notes", "max_stars_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-18T20:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T20:40:45.000Z", "max_issues_repo_path": "multivar-calculus/multivar-calculus.tex", "max_issues_repo_name": "davidmaamoaix/lecture-notes", "max_issues_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multivar-calculus/multivar-calculus.tex", "max_forks_repo_name": "davidmaamoaix/lecture-notes", "max_forks_repo_head_hexsha": "441449bdd8a46a2cc25c8034af28b73aba451ea6", "max_forks_repo_licenses": ["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.4417582418, "max_line_length": 610, "alphanum_fraction": 0.6626993517, "num_tokens": 14464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.6298618835934716}}
{"text": "\\documentclass[main.tex]{subfiles}\n\n\\begin{document}\n%We will study flows along a network using the tools of linear algebra, revealing interesting parallels with the field of graph theory. In particular, the \\emph{Flow Response Transformation}, mapping line flows to the\n%We conclude this chapter by deducing a\n\n%\\section{Graph}\nThe power grid forms an interconnected \\emph{network} of transmission lines, which makes graph theory a logical choice for modelling it.\nIn fact, most electrical systems are modelled using graphs. In circuit theory, \\emph{lines} represent individual electrical components (resistors, voltage sources) and \\emph{nodes} represent the conductive material between them.\\footnote{This simplification is only true for components with 2 terminals. A transistor has 3 terminals, for example.}\n%More formally, circuit components can be defined as restrictions (boundary conditions) on the \\emph{phase space} of the circuit. \n%When we want to create an electric connection between two points, the most obvious way to so is using a \\emph{wire}. This has the nice property that \nWe will study the electrical properties of the transmission network in Chapter~\\ref{chap:model}, but for now, we will simply accept that the transmission network consists of \\emph{nodes} and \\emph{lines}, and that the lines can transfer power between nodes in a straightforward (linear) way. Physically, the power flows are determined by the amount of power injected at each node, which in turn is determined by the devices that we connect to the transmission network. In this chapter, we will study the \\emph{converse}:\n\\[\n\\text{\\textit{What does the flow of power tell us about the power injection at the nodes?}}\n\\]\nTo do so, we will build upon the tools of linear algebra and graph theory, as covered in most elementary textbooks on these subjects.\n\nIn this section, we will use, without proof:\n\\begin{itemize}\n\\item \\emph{Every connected graph contains a minimum spanning tree.}\n\\item \\emph{A connected (di)graph is a \\emph{tree} if and only if the number of lines is one fewer than the number of nodes.}\n\\item \\emph{By removing a leaf from a tree, we obtain a new tree.}\n\\item \\emph{Given two nodes in a tree, there is a unique path between these nodes that crosses any line at most once.}\n\\end{itemize}\n\\section{Directed graph}\nWhen studying the flow of current in a network, it is necessary to fix a direction for each line, relative to which the flow along that line can be expressed. We do so using a \\emph{digraph}, where lines are not defined as two-element sets (like they are in a classical \\emph{graph}), but as \\emph{ordered pairs}.\n\n\\begin{definition}\nA \\emph{directed graph}\\index{graph!directed} is a pair $(\\mathcal{N},\\mathcal{L})$ such that the set of \\emph{nodes} $\\mathcal{N}$ is finite, and the set of \\emph{lines} $\\mathcal{L}\\subseteq \\mathcal{N} \\times \\mathcal{N}$ satisfies:\n\\begin{itemize}\n    \\item If $(i,j) \\in \\mathcal{L}$, then $(j,i) \\notin \\mathcal{L}$. (\\ie there are no 'loops' between two nodes.)\n    \\item For each $i \\in \\mathcal{N}$: $(i,i) \\notin \\mathcal{L}$. (\\ie no node is directly connected to itself.)\n\\end{itemize}\n\\end{definition}\n\nA classical graph can be converted to a \\emph{digraph} by (arbitrarily) choosing a direction for each line. Some authors prefer to use a classical graph, combined with an \\emph{incidence function}: a function that maps an unordered pair of nodes $\\{i,j\\}$ to an ordered pair, $(i,j)$ or $(j,i)$.\\footnote{\\cite{Slepian1968} takes this one step further by \\emph{only} considering the incidence function: the set of lines can be retrieved as the \\emph{domain} of the incidence function, and the set of nodes is the \\emph{union} of the set of lines.}\n\n\\section{Flow}\nFor the remainder of this section, assume that $G=(\\mathcal{N},\\mathcal{L})$ is a directed graph, where the nodes are labelled $\\mathcal{N}=\\{1,2,\\dots,n\\}=\\range{n}$ for some $n \\in \\mathbb{N}$.\nThe $m = \\# \\mathcal{L}$ lines of the network are labelled $\\mathcal{L}=\\{\\mathcal{L}_1,\\mathcal{L}_2,\\dots,\\mathcal{L}_m\\}$.\n\nWe also fix a field $\\mathbb{K}$, which we will use to define \\emph{injections} and \\emph{flows} on $G$. When studying \\emph{real power flows}, we will take $\\mathbb{K}=\\mathbb{R}$.\n\n\\begin{definition}\\label{def:injectionandflow}\nAn \\define{injection on $G$} is an element of $\\mathbb{K}^n$; a \\define{flow on $G$} is an element of $\\mathbb{K}^m$.\n\\end{definition}\n\nOne should view an injection $\\mat{p} \\in \\mathbb{K}^n$ as the vector that encodes how much power is being put into the network at each node. When $\\mel{p}_i$ is negative, this means that power is being \\emph{consumed} at node $i$. Similarly, a flow $\\mat{f} \\in \\mathbb{K}^m$ represents the amount of power transmitted along each line. For a line $\\mathcal{L}_k=(i,j) \\in \\mathcal{L}$, $\\mel{f}_k$ expressed the amount of power being transmitted along the line, from node $i$ to node $j$.\n\nOf course, the notions \\emph{positive} and \\emph{negative} only exist when $\\mathbb{K}$ is a totally ordered set. Otherwise, we simply have to be satisfied with the meaning provided by Definition~ \\ref{def:inducedinjection}.\n\nWhen $\\mathbb{K}=\\mathbb{F}_2$, a flow can be seen as a subset of the collection of lines $\\mathcal{L}$, since any flow entry is either $1$ or $0$.\n\n\\begin{definition}\\label{def:inducedinjection}\nAn injection $\\mat{p} \\in \\mathbb{K}^n$ is \\emph{induced}\\index{induced injection} by a flow $\\mat{f} \\in \\mathbb{K}^m$ if:\n\\begin{gather}\n    \\mel{p}_i =\n    \\sum_{\\mathcal{L}_k=(i,j) \\in \\mathcal{L}} f_k -\n    \\sum_{\\mathcal{L}_k=(j,i) \\in \\mathcal{L}} f_k \\label{eq:inducedflow}\n\\end{gather}\nfor each node $i \\in \\mathcal{N}$. ($\\mel{p}_i = 0$ for isolated nodes.)\n\\end{definition}\nNote that $\\mat{p}$ is uniquely defined for every choice of $\\mat{f}$. This allows us to define a function:\n\\begin{definition}\nSuppose $G$ has no isolated nodes. We define the \\define{Flow Response Transformation} ($\\FRT$) as the function\n\\begin{gather*}\n    \\FRT: \\mathbb{K}^m \\rightarrow \\mathbb{K}^n\n\\end{gather*}\nthat maps a flow $\\mat{f} \\in \\mathbb{K}^m$ to the unique injection $\\mat{p} \\in \\mathbb{K}^n$ that it induces.\n\\end{definition}\n\nFrom (\\ref{eq:inducedflow}), it follows that $\\FRT$ is a linear map, which means that we can write $\\FRT$ as a matrix: $\\mat{K}$. We can find an explicit expression for the entries $\\mel{K}_{i,k}$, noting that its \\emph{rows} are determined by (\\ref{eq:inducedflow}), and that there are no `double' lines in the digraph.\n\n\\begin{align*}\n    \\mel{K}_{i,k} =\n    \\begin{cases}\n         1 & \\text{if } \\mathcal{L}_k=(i,j) \\text{ for some } j \\in \\range{n}, \\\\\n        -1 & \\text{if } \\mathcal{L}_k=(j,i) \\text{ for some } j \\in \\range{n}, \\\\\n         0 & \\text{otherwise}.\n    \\end{cases}\n\\end{align*}\n\nThis matrix can be seen as the familiar \\emph{incidence matrix} of a classical graph, adapted to digraphs. For this reason, $\\mat{K}$ is often called the \\emph{vertex-edge incidence matrix of $G$}.\nThe ordered set of lines is uniquely defined by the vertex-edge incidence matrix.\n\n\\begin{figure}\n    \\centering\n    \\input{\"fig/two nodes.tex\"}\n    \\caption{The simple \\emph{two-node}\\index{network!two-node} network of two nodes and one line.}\n    \\label{fig:twonodes}\n\\end{figure}\n\\begin{example}[Two-node network]\\label{exa:twonodenetwork}\nA very simple digraph is one with just two nodes, and a single line connecting them. This \\emph{two-node network}\\index{network!two-node} is drawn in Figure \\ref{fig:twonodes}.\nAlthough real networks are much bigger, this example is useful to illustrate some of the concepts introduced in Chapter~\\ref{chap:model}.\n\\begin{align*}\n    \\intertext{We have:}\n    \\mathcal{N}&=\\{1,2\\} \\text{ and}\\\\\n    \\mathcal{L}&=\\{\\mathcal{L}_1\\}\\text{ with }\\mathcal{L}_1=(1,2). \\\\\n    \\intertext{Since $n=2$ and $m=1$, $\\mat{K}$ is a $2\\times 1$ matrix:}\n    \\mat{K} &= \\begin{pmatrix}\n    1 \\\\\n    -1\n    \\end{pmatrix}.\n\\end{align*}\n\\end{example}\n\n\\begin{figure}[h]\n    \\centering\n    \\input{\"fig/nloop.tex\"}\n    \\caption{The \\emph{$n$-loop}\\index{network!$n$-loop} network with $n$ nodes and $n$ lines.}\n    \\label{fig:nloopnetwork}\n\\end{figure}\n\n\\begin{example}[Loop network]\\label{exa:nloopnetwork}\nA less trivial digraph is the \\emph{$n$-loop network}\\index{network!$n$-loop}, shown in Figure~\\ref{fig:nloopnetwork}. It consists of $n$ nodes, connected in a circular fashion (using $n$ lines).\n\nNote that this network is 2-edge connected, meaning that the network remains connected when any edge is removed. (Although removing \\emph{any} two lines will disconnect the network.)\n\\begin{align*}\n    \\intertext{We have:}\n    \\mathcal{N}&=\\{1,\\dots,n\\}=\\range{n} \\text{ and}\\\\\n    \\mathcal{L}&=\\{\\mathcal{L}_1,\\dots,\\mathcal{L}_n\\}\\text{ with }\\mathcal{L}_i=(i,i+1)\\text{ for }1 \\leq i < n\\text{ and }\\mathcal{L}_n=(n,1). \\\\\n    \\intertext{Since $m=n$, $\\mat{K}$ is an $n\\times n$ matrix:}\n    \\mat{K} &= \\begin{pmatrix}\n    1 &  & &  & &  -1 \\\\\n    -1 &  1 &  &   &   &   \\\\\n      & -1 &  1 &  &       & \\\\\n      &   &  \\ddots & \\ddots  &   &   \\\\\n      &   &   & & 1 &    \\\\\n      &   &  &  & -1 &      1  \\\\\n    \\end{pmatrix}.\n\\end{align*}\n\\emph{(All unspecified elements are 0).}\n\nNote that the \\emph{columns} of $\\mat{K}$ correspond to the lines of the network.\n\\end{example}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{img/scigrid_boring.pdf}\n    \\caption{The $n=489$ buses and $m=695$ lines of the SciGRID network. A description of this dataset is given in Part II.}\n    \\label{fig:scigrid}\n\\end{figure}\n\\begin{example}[SciGRID Germany]\\label{exa:scigridnetwork}\nIn Part II, we will apply our theory to the SciGRID dataset, which contains the network shown in Figure~\\ref{fig:scigrid}. This network is much more realistic than the previous examples, as it is based on the real-world structure of the transmission network in Germany. \n\nIt is common for transmission networks to have a well-connected `core', with some branches out of the core towards the outer regions of the network. This means that in general, $m>n$.\n\nIndeed, in this network we have $n=489$ and $m=695$. The vertex-edge incidence matrix $\\mat{K}$ has dimensions $489 \\times 695$, and it is \\emph{sparse}: most entries are zero.\n\nIt is important to note that this is only a \\emph{section} of the actual transmission network of continental Europe, which is highly connected among different countries. As we will discuss in Section \\ref{sec:constructingdataset}, accurate datasets of continental Europe do exist, but they are hard to obtain and analyse.\n%Because the laws of physics have no notion of national borders, we would \n%As far as the laws of physics are concerned, taking the subset of lines within Germany is almost as arbitrary as, say, the subset of lines above a certain latitude.\n\\end{example}\n\nThe fact that $\\FRT$ is a linear map raises an interesting question: how can the image and kernel of $\\FRT$ be interpreted in the context of digraph flows?\nThe reader is invited to revisit Example \\ref{exa:nloopnetwork} to visualise these sets.\n\nOne can interpret the image of $\\FRT$ as the set of injections that can be redistributed along the network. Because a flow only serves to redistribute injections from one node to another, nothing is lost or gained in the network. This imposes the condition that an injection vector must have \\emph{zero sum}. Moreover, when $G$ is connected, \\emph{all} zero sum injections can be induced by a flow.\n\nThe kernel can be interpreted as the set of all flows that result in zero injections. Besides the trivial case of zero flow, any constant flow along a loop induces zero injection. We will find that these \\emph{loop flows} generate \\emph{all} flows in the kernel of $\\FRT$.\n\nWhen $G$ is a planar graph, loops around the faces of $G$ actually form a \\emph{basis} for the kernel. In the more general case that $G$ is connected, but not necessarily planar, such a basis can also be constructed by fixing a \\emph{minimum spanning tree} of $G$.\n\nAs an added bonus, applying the Rank-Nullity theorem to $\\FRT$ when $G$ is planar provides us with an alternative demonstration of Euler's Formula.\n\nThese statements will be made more precise in the next sections, when we study the image and kernel of $\\FRT$ in more detail.\n\n\\section{Image of $\\mathbf{\\FRT}$}\nWe start with the following definition:\n\\begin{definition}\nThe function $\\sigma : \\mathbb{K}^n \\rightarrow \\mathbb{K}$ defined by\n\\begin{gather*}\n    \\sigma : \\mat{p} \\mapsto \\sum_{i=1}^n \\mel{p}_i\n\\end{gather*}\nis the linear map from an injection vector $\\mat{p}$ to the \\define{net injection} of $\\mat{p}$.\n\\end{definition}\nThe kernel of $\\sigma$ is the set of zero-sum injections:\n$$\\ker \\sigma = \\left\\{ \\mat{p} \\in \\mathbb{K}^n \\, \\mid \\, \\sum_{i=1}^n \\mel{p}_i = 0 \\right\\}.$$\nWhen $G$ is connected, this is exactly the set of injections that can be induced by a flow on $G$:\n\n\\begin{theorem}\\label{thm:imageLPF}\nSuppose that $G$ is connected. Then\n\\begin{empheq}[box=\\fbox]{gather}\n    \\Ima \\FRT = \\left\\{ \\mat{p} \\in \\mathbb{K}^n \\, \\mid \\, \\sum_{i=1}^n \\mel{p}_i = 0 \\right\\} \\cong \\mathbb{K}^{n-1}\n\\end{empheq}\n\\end{theorem}\n\nWe will prove this equality by considering the two inclusions $\\subseteq$ and $\\supseteq$ separately. The first inclusion follows from the observation that $\\mat{K}$ is the vertex-edge incidence matrix of $G$.\n\\begin{lemma}\\label{lem:imlpfsubsetkersigma}\nSuppose that $G$ is connected.\n\\begin{gather}\n\\Ima \\FRT \\subseteq \\ker \\sigma\\label{eq:LPFfin}\n\\end{gather}\n\\end{lemma}\n\\begin{proof}\nWe write $\\mat{e}^1, \\dots, \\mat{e}^m$ for the standard basis of $\\mathbb{K}^m$.\n\nSince $\\FRT$ is linear, one only needs to verify that $\\FRT(\\mat{f}) \\in \\ker \\sigma$ for each $\\mat{f}=\\mat{e}^k$ in the basis.\nThe vectors $\\FRT(\\mat{e}^1), \\dots, \\FRT(\\mat{e}^m)$ are exactly the columns of the matrix $\\mat{K}$, which all have zero sum: a column corresponds to a line in $G$, and has exactly two non-zero entries: $1$ for the entering node, and $-1$ for the leaving node.\n\\end{proof}\n\nTo prove the inclusion $\\supseteq$ implied by Theorem \\ref{thm:imageLPF}, we first consider the special case that $G$ is a \\emph{tree}.\n\n\\begin{lemma}\\label{lem:connectedtree}\nSuppose that $G$ is a (connected) tree.\n\\begin{gather}\n\\Ima \\FRT \\supseteq \\ker \\sigma\n\\end{gather}\n\\end{lemma}\n\n\\begin{proof}%\\todo{This proof could benefit from an illustration.}\n$G$ is a tree, so $m=n-1$. Because $\\mathbb{K}^m$ and $\\ker \\sigma$ both have dimension $n-1$, we only need to prove that $\\FRT$ is injective: when $\\FRT$ has nullity $0$, it must have rank $n-1$.\n\nIf $n=1$, then the digraph consist of a single node, and no lines. It then follows from (\\ref{eq:inducedflow}) that the only injection that can be induced is $\\mat{p}=(0) \\in \\mathbb{K}^1$, so $\\FRT$ can only be injective.\n\nIf $n>1$, we will use the fact that the statement holds for any tree with fewer than $n$ nodes. \\emph{(Proof by induction.)}\n\nSuppose that $f \\in \\mathbb{K}^{m}$, such that $\\mat{p}=\\FRT(\\mat{f})=\\mat{0}$. Because $G$ is a tree, we can\\footnote{Write $\\gr(i)$ for the number of lines connected to $i$. $G$ is connected, so $\\gr(i)\\geq1$ for each $i \\in \\mathcal{N}$. \\emph{If no $i$ exists with $\\gr(i)=1$}, then $\\gr(i)\\geq 2$ for each $i \\in \\mathcal{N}$, giving $\\sum_{i = 1}^n \\gr(i) \\geq 2n$. On the other hand, each of the $n-1$ lines connects exactly two nodes, so $\\sum_{i = 1}^n \\gr(i) = 2(n-1) < 2n$, a contradiction.} pick a \\emph{leaf} $i \\in \\mathcal{N}$, which has a unique line $\\mathcal{L}_k$ connecting $i$ to some $j \\in \\mathcal{N}$. (We have either $\\mathcal{L}_k = (i,j)$ or $\\mathcal{L}_k=(j,i)$.)\n\nOnly one line is connected to $i$, so (\\ref{eq:inducedflow}) gives: $\\mel{p}_i = \\pm \\mel{f}_k$. (The sign depends on the orientation of $\\mathcal{L}_k$.) We assumed $\\mel{p}_i=0$, so we must have $f_k = 0$.\n\nBy removing node $i$ and line $\\mathcal{L}_k$, we obtain a smaller tree, for which the statement already holds. The Flow Response Transformation of this subtree is essentially the restriction of $\\FRT$ to the set $\\left\\{\\mat{f} \\in \\mathbb{K}^m \\, \\mid \\, \\mel{f}_k = 0\\right\\}$. Because the restriction is injective, all other coefficients of $\\mat{p}$ are also zero. This shows that $\\FRT$ is injective, and the result follows.\n\\end{proof}\n\n\\begin{proof}[Proof of Theorem \\ref{thm:imageLPF}]\nTo prove $\\Ima \\FRT = \\ker \\sigma$, it remains to show that\n\\begin{gather}\n\\Ima \\FRT \\supseteq \\ker \\sigma\n\\end{gather}\nholds for \\emph{any} connected $G$, not just for trees.\n\nSince $G$ is connected, we can choose a minimum spanning tree: choose $T \\subseteq \\range{m}$ with $\\# T = n-1$ such that $G_T=(\\mathcal{N}, \\{\\mathcal{L}_k\\}_{k \\in T})$ is such a connected subdigraph.\n\nDefine $F_T = \\linspan \\{\\mat{e}^k\\}_{k \\in T} \\subseteq \\mathbb{K}^m$ as the subset of flows on $G$ that are zero outside of $G_T$. Because $F_T$ is a linear subspace of $\\mathbb{K}^m$, we have\n$$\\Ima \\FRT = \\FRT (\\mathbb{K}^m) \\supseteq \\FRT(F_T),$$\nwhich reduces the problem to $\\FRT(F_T) \\supseteq \\ker \\sigma$, which follows from Lemma \\ref{lem:connectedtree}.\n\nThis shows that\n\\begin{gather*}\n    \\Ima \\FRT = \\ker \\sigma.\n\\end{gather*}\nBecause $\\sigma : \\mathbb{K}^n \\rightarrow \\mathbb{K}$ is surjective, it has rank $1$. It therefore has nullity $n-1$, or equivalently, $\\ker \\sigma \\cong \\mathbb{K}^{n-1}$.\n\\end{proof}\n\n\n\n\n\n\n\n\n\n\\section{Kernel of $\\mathbf{\\FRT}$}\nAgain, let us assume that $G$ is connected. In Theorem \\ref{thm:imageLPF}, we derived an explicit formulation for the image of $\\FRT$, showing that $\\rank \\FRT = n-1$.\n\nConcerning the kernel of $\\FRT$, we already know that $\\mat{0} \\in \\ker \\FRT$, reflecting the fact that zero flow induces zero injection. In the special case that $G$ is a tree, this is the only such flow. In general, however, the kernel of $\\FRT$ is much bigger.\n\n\\begin{proposition}\\label{prop:nullityLPF}\nSuppose that $G$ is connected. The dimension of $\\ker \\FRT$ equals\n\\begin{gather*}\n    \\nullity \\FRT = m - (n - 1).\n\\end{gather*}\n\\end{proposition}\n\\begin{proof}\nThis follows directly from the Rank-Nullity theorem, applied to Theorem \\ref{thm:imageLPF}.\n\\end{proof}\n\n\n\\begin{corollary}\nIf $G$ is a tree, then $\\ker \\FRT = \\{\\mat{0}\\}$, and $\\FRT$ is an isomorphism between $\\mathbb{K}^m$ and $\\ker \\sigma$.\n\\end{corollary}\n\\begin{proof}\nApplying Proposition \\ref{prop:nullityLPF} with $m = n-1$, we find that $\\nullity \\FRT = 0$, so that ${\\ker \\FRT = \\{\\mat{0}\\}}$. Together with Theorem \\ref{thm:imageLPF}, we find the result.\n\\end{proof}\n\n\\subsection{Loop flows}\nWhat do the elements of $\\ker \\FRT$ look like? As we will see, any flow along a \\emph{loop}\\footnote{We define a \\emph{path} by the ordered sequence of nodes that it visits, including the initial and final node. Although we are studying directed graphs, lines can be traversed in either direction by a path. A \\emph{loop} is a path where the initial and final node coincide.} results in zero power injection. When interpreting a loop as an element $\\mat{f}$ of $\\mathbb{K}^m$, we must be careful to \\emph{flip the sign of $\\mel{f}_k$ if the line $\\mathcal{L}_k$ is traversed in reverse.}\n\n\\begin{theorem}\\label{thm:loopflowkernel}\nSuppose that $G$ is connected and that $(i_1, i_2, \\dots, i_p)$ is a loop that visits each line at most once. Then the \\define{loop flow} $\\mat{f} \\in \\mathbb{K}^m$ defined by:\n\\begin{gather}\n    \\mel{f}_k = \\begin{cases}\n    \\hphantom{-}1 & \\text{if } (i_s\\hphantom{_{+1}}, i_{s+1})=\\mathcal{L}_k \\text{ for any } 1 \\leq s < p,\\\\\n    -1 & \\text{if } (i_{s+1}, i_s\\hphantom{_{+1}})=\\mathcal{L}_k \\text{ for any } 1 \\leq s < p,\\\\\n    \\hphantom{-}0 & \\text{otherwise,}\n    \\end{cases}\\label{eq:loopflowdef}\n\\end{gather}\nfor each line $\\mathcal{L}_k$, is an element of the kernel of $\\FRT$.\n\\end{theorem}\n\\begin{proof}\nWe will verify that $\\mat{p}=\\FRT(\\mat{f})$ is zero.\nChoose any $i \\in \\mathcal{N}$.\n\nBecause the loop is closed, there is an \\emph{even} number (possibly zero) of lines with non-zero flow that connect to $i$. This means that the sums in (\\ref{eq:inducedflow}) cancel each other (note the negative sign for reversed lines in (\\ref{eq:loopflowdef})), resulting in $\\mel{p}_i=0$.\n\\end{proof}\n\n\\begin{remark}\nBecause $\\FRT$ is linear, multiplying a loop flow with a scalar $\\gamma \\in \\mathbb{K}$, or adding two loop flows, creates a new flow that induces zero injection. (The result of addition is a flow, but in general not a \\emph{loop} flow.)\n\\end{remark}\n\nNow that we know the dimension of $\\ker \\FRT$, a natural next step is to look for a \\emph{basis} that generates the kernel. Motivated by the previous theorem, we will look for a basis consisting of \\emph{loop flows}.\n\nA logical choice for this basis would be the set of all flows in \\emph{loops surrounding the faces contained in the graph}. This approach, which only works for \\emph{planar graphs}, will be discussed in the next section.\n\nFor now, we would like to find a basis of loop flows for the more general case that $G$ is connected, but not necessarily planar. We proceed as follows:\n\n\\begin{definition}\\label{def:spiderwebbasis}\nSuppose that $G$ is connected, and that $T \\subseteq \\range{m}$ is a minimum spanning tree. For each remaining line $\\mathcal{L}_k = (i,j) \\in \\left\\lbrace \\mathcal{L}_k \\in \\mathcal{L} \\, \\mid \\, k \\notin  T \\right\\rbrace $, there exists a \\emph{unique path along the tree} from $j$ to $i$ that crossed any line at most once, say \n\\[\n(i_1, i_2, \\dots, i_p),\\quad\\text{ where $i_1=j$ and $i_p=i$.}\n\\]\nBy adding the chosen line $\\mathcal{L}_k$ to this path, we find a loop in $G$: $(i_1, i_2, \\dots, i_p, j)$, which defines a loop flow $\\mat{f}^k$. \n\nWe define the \\define{spider web basis on $T$} as the set of loop flows defined this way: $\\{ \\mat{f}^k \\}_{k \\in \\range{m} \\setminus T}$. (If $T$ were to represent a physical tree, a spider could spin a web from $i$ to $j$ by attaching a strand to $j$ and then walking the path to $i$.\\footnote{It turns out that this is not how most spiders cover large distances: instead, they produce a long thread, and let it drift in the wind until it sticks to another surface. Clever!})\n\\end{definition}\n\n\\begin{theorem}\nThe \\emph{spider web basis on $T$} constructed in Definition \\ref{def:spiderwebbasis} is a basis for $\\ker \\FRT$.\n\\end{theorem}\n\\begin{proof}\nBecause $T$ is a minimum spanning tree, it has $n-1$ elements, and so the spider web basis consists of $m - (n-1)$ loop flows.\nBecause the number of elements in the basis equals the dimension of $\\ker \\FRT$, one only needs to prove that they are linearly independent. Indeed, for each $k \\in \\range{m}\\setminus T$, the loop flow $\\mat{f}^k$ is the only element for which the $k^{\\text{th}}$ entry is non-zero. Therefore, $\\mat{f}^k$ cannot be written as linear combination of the other fundamental loops.\n\\end{proof}\n\n\\subsection{Planar Graphs}\nThe spider web basis can be constructed for any connected graph. When the graph is also \\emph{planar}, a more intuitive basis exists. Without providing a rigorous definition, we simply say that a graph is \\define{planar} if it can be `drawn on a piece of paper without any crossing lines'. Such a drawing creates \\emph{faces}: areas enclosed by lines.\\footnote{We do not consider the infinite enclosing area as one of the faces.} Different drawings can produce different collections of faces.\n\nIf we fix a collection of faces for a planar graph, then each face is enclosed by some of the lines, which form a loop in the graph. We define the \\emph{planar basis on this drawing} as the set of loop flows defined by those loops: each face becomes an element in the basis. Rewriting Theorem~\\ref{prop:nullityLPF}, we find:\n%\n%\\towrite{th: in a planar embedding of a planar graph, the loops surrounding faces form a basis.\n%proof: (in F2): \n%\n%linearly independent: these loops are all loops with the property that exactly one face is contained in the loop.\n%\n%complete: start with a spider web basis.\n%choose a loop f in the spider web basis.\n%this loop f contains a number of faces. f is equal to the sum of the loops around these faces.\n%this shows that f can be written as linear combination of planar loops. QED}\n\n\\begin{corollary}[Euler's Formula]\nIn a planar, connected graph, we have:\n$$v + f - e = 1$$\nwhere $v$ is the number of vertices, $e$ is the number of edges, and $f$ is the number of faces enclosed by edges, excluding the 'exterior face'.\n\\end{corollary}\n\\end{document}\n", "meta": {"hexsha": "70e27d5f5a5a35b37c160c48dbaa1391570810d7", "size": 24402, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/graph.tex", "max_stars_repo_name": "fons-/grid-failures", "max_stars_repo_head_hexsha": "947ccefe4ced7aa45b7b77339a6f28d7b0881c44", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-07-15T21:43:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T08:14:11.000Z", "max_issues_repo_path": "doc/thesis/graph.tex", "max_issues_repo_name": "fons-/grid-analysis", "max_issues_repo_head_hexsha": "947ccefe4ced7aa45b7b77339a6f28d7b0881c44", "max_issues_repo_licenses": ["MIT"], "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/graph.tex", "max_forks_repo_name": "fons-/grid-analysis", "max_forks_repo_head_hexsha": "947ccefe4ced7aa45b7b77339a6f28d7b0881c44", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-23T17:12:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-05T22:22:44.000Z", "avg_line_length": 70.5260115607, "max_line_length": 693, "alphanum_fraction": 0.711253176, "num_tokens": 7471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6298618822356763}}
{"text": "%!TEX root =  ../main.tex\n\n\\mychapters{Probabilities}{probability}{\\chapdir/pics/1280px-13-02-27-spielbank-wiesbaden-by-RalfR-093} \nWhat are the chances?\n\n\\newpage\n\\chapterminitoc\n\n%\t\t\t\t\t\t\t\t\t14 - 1\n\\newpage\n\\section{Chances}\n\\subsection{Two Dice}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch14/1401p.pdf}}\n\\subsection{Rule of Product}\n\\personfeature{\\chapdir/pics/Pierre_de_Fermat.jpg}{Pierre de Fermat}{1607-1665}{was a French mathematician who is given credit for early developments that led to infinitesimal calculus,  analytic geometry, probability, and optics. \\href{https://en.wikipedia.org/wiki/Pierre_de_Fermat}{Wikipedia}}\n\\subsection{Combinatorics}\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t14 - 2\n\\newpage\n\\section{Counting Principle}\n\\subsection{Clusivity}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch14/1402p.pdf}}\n\\subsection{Logical AND and OR}\n\\subsection{Factorial}\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t14 - 3\n\\newpage\n\\section{Permutation}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch14/1403p.pdf}}\n\\subsection{$_nP_r$}\n\\subsection{Circular Arrangements}\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t14 - 4\n\\newpage\n\\section{Combination}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch14/1404p.pdf}}\n\\subsection{$_nC_r$}\n\\subsection{n Choose r}\n\\subsection{Pascal's Triangle}\n\n\\personfeature[-0in]{\\chapdir/pics/Yanghui_triangle.png}{Zhūshìjié}{1249–1314}{was \none of the greatest Chinese mathematicians living during the Yuan Dynasty.  Zhu's \nsecond book, \\textit{Jade Mirror of the Four Unknowns} (Sì yuán yù jiàn), solved square \nand cube roots problems by solving quadratic and cubic equations, and added to \nthe understanding of series and progressions, classifying them according to the \ncoefficients of the Pascal triangle.\\href{https://en.wikipedia.org/wiki/Zhu_Shijie}{Wikipedia}}\n\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t14 - 5\n\\newpage\n\\section{Binomial Series}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch14/1405p.pdf}}\n\\subsection{Sigma Notation}\n\\subsection{Binomial Probability}\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t14 - 6\n\\newpage\n\\section{Review}\n\\subsection{Chapter Review}\n\\subsection{Chapter Test}\n\n", "meta": {"hexsha": "82119b1ce9aaf6a1bb4ebaec9f2199bf4835b941", "size": 2223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch14/1400.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": "ch14/1400.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": "ch14/1400.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": 33.1791044776, "max_line_length": 296, "alphanum_fraction": 0.7678812416, "num_tokens": 655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.629835531106957}}
{"text": "\\documentclass[11pt,letterpaper]{article}\n\n\\usepackage[pdftex]{graphicx}\n\\usepackage{natbib}\n\\usepackage{fullpage}\n\\usepackage{lineno}\n\\usepackage{multirow}\n\\usepackage{wrapfig}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{sidecap}\n\\usepackage{hyperref}\n\n\\begin{document}\n\n\\setlength{\\parindent}{0mm}\n\\setlength{\\parskip}{0.4cm}\n\n\\bibliographystyle{apalike}\n\n%\\modulolinenumbers[5]\n%\\linenumbers\n\n\\title{PDE test descriptions}\n%\\author{Matthew D. Zettergren, PhD\\\\ Associate Professor of Engineering Physics\\\\ Center for Space and Atmospheric Physics\\\\ Physical Sciences Department \\\\Embry-Riddle Aeronautical University\\\\mattzett@gmail.com\\\\zettergm@erau.edu}\n\\maketitle\n\n\\tableofcontents\n\n\\pagebreak\n\n\n\\section{Parabolic solver test problem}\n\nA PDE test parabolic problem that is useful is a simple heat equation describing the evolution of temperature $T(z,t)$ in space and time subject to uniform thermal conduction:\n\\begin{equation}\n\\frac{\\partial T}{\\partial t} - \\lambda \\frac{\\partial^2 T}{\\partial z^2} = 0.\n\\end{equation}\nFor purposes of testing we solve this equation on the \\emph{bounded} domain $0 \\le x \\le 1$.  Invoking separation of variables we presume $T(z,t)=Z(z) \\mathcal{T}(t)$ and substitute back into the original equation:  \n\\begin{equation}\n\\frac{1}{\\lambda \\mathcal{T}} \\frac{\\partial \\mathcal{T}}{\\partial t} - \\frac{1}{Z} \\frac{\\partial^2 Z}{\\partial z^2} = 0.\n\\end{equation}\nEach term depends solely on one of the independent variables $x,t$, which implies that for this relation to be valid for all $x,t$ then each term must be equal to a constant.  \n\\begin{eqnarray}\n\\frac{1}{\\lambda \\mathcal{T}} \\frac{d \\mathcal{T}}{d t} &=& -k^2 \\\\\n- \\frac{1}{Z} \\frac{d^2 Z}{d z^2} &=& k^2.\n\\end{eqnarray}\nNote also that since we have dependence on only one variable that we have converted the derivatives into \\emph{ordinary} derivatives.  The solutions to these ODEs read:\n\\begin{eqnarray}\n\\mathcal{T}(t) &=& A e^{-k^2 \\lambda t} \\\\\nZ(z) &=& A' \\sin kz + B' \\cos kz\n\\end{eqnarray}\nThe elemental solution ($k$ arbitrary) is given by: \n\\begin{equation}\n\\tilde{T}(z,t)=Z(z) \\mathcal{T}(t) = e^{-k^2 \\lambda t} \\left( A'' \\sin kz + B'' \\cos kz \\right)\n\\end{equation}\nFrom this equation it is seen that the time scale for decay of a mode with wavenumber $k$ is given by \n\\begin{equation}\n\\tau = \\frac{1}{k^2 \\lambda}\n\\end{equation}\n\nFurther progress toward a general solution requires specific initial and boundary conditions.  For our test problem we assume that the temperature goes to zero on the boundaries ($z \\in \\{0,1\\}$).  Let us also assume that the initial temperature of the system is given by:  $T(z,0) = f(z)$.  First employing the condition $T(0,t)=0$, we find that $B''=0$.  The other boundary condition $T(1,t)=0$ sets restrictions on the argument/eigenvalues of the sine function, namely that $k=n \\pi, n \\in \\mathbb{Z}^+$ is a set of roots for the sine function.  The elemental solution is then:\n\\begin{equation}\n\\tilde{T}_n(z,t)= A_n e^{-n^2 \\pi^2 \\lambda t} \\sin \\left( n \\pi z \\right)\n\\end{equation}\nAny integer value chosen for $n$ results in a legitimate solution for the original partial differential equation; therefore, the general solution is a linear superposition of all such solutions.  \n\\begin{equation}\nT(z,t)= \\sum_{n=1}^{\\infty} A_n ~ e^{-n^2 \\pi^2 \\lambda t} \\sin \\left( n \\pi z \\right).\n\\end{equation}\nThe initial condition can now be applied to solve for the coefficients $A_n$ by leveraging orthogonality of the sine functions.  That is by making use of the fact that:\n\\begin{equation}\n\\left< \\sin(n \\pi z) | \\sin (n' \\pi z) \\right> = \\int_0^1 \\sin(n \\pi z) \\sin (n' \\pi z) dz = \\frac{1}{2} \\delta_{nn'},\n\\end{equation}\nwe may produce a solution for $A_n$ from the series solution.  The initial condition is represented in summation form (a Fourer sine series) as:  \n\\begin{equation}\nT(z,0) = f(z) = \\sum_{n=1}^{\\infty} A_n ~ \\sin \\left( n \\pi z \\right).\n\\end{equation}\nTaking the scalar product of both sides with $\\sin (n' \\pi z)$ gives:\n\\begin{equation}\n\\left< f(z) | \\sin (n' \\pi z) \\right> = \\sum_{n=1}^{\\infty} A_n ~ \\left< \\sin(n \\pi z) | \\sin (n' \\pi z) \\right> = \\sum_n = \\frac{A_n}{2} \\delta_{nn'} = \\frac{A_{n'}}{2}\n\\end{equation}\nThus the coefficients are:  \n\\begin{equation}\nA_{n'} = 2 \\left< f(z) | \\sin (n' \\pi z) \\right> = 2 \\int_0^1 f(z) \\sin (n' \\pi z) dz\n\\end{equation}\n\nFor purposes of testing it is easiest to pick a test problem with boundary conditions that are represented by a finite sum - one way this can be accomplished is by choosing a boundary condition that is an eigenfunction for this particular problem.  Additionally to fully test the algorithms we should should several different modes in order to illustrate different decay times, for example:  \n\\begin{equation}\n f(z) = \\sin(2 \\pi z) + \\sin(8 \\pi z).\n\\end{equation}\nFrom this, and orthogonality of the sine function it follows that:\n\\begin{equation}\nA_{n'} = \\left\\{ \\begin{array}{cc} 2 & n \\in \\{2,8\\} \\\\ 0 & \\mathrm{otherwise}  \\end{array} \\right. ,\n\\end{equation}\nand that the general solution for this specific set of boundary and initial conditions is:  \n\\begin{equation}\nT(z,t) = e^{-4 \\pi^2 \\lambda t} \\sin \\left( 2 \\pi z \\right)+e^{-64 \\pi^2 \\lambda t} \\sin \\left( 8 \\pi z \\right)\n\\end{equation}\n\n\n\n\\section{Elliptic solver test problem}\n\nThe elliptic potential solver can tested using a simplified 2D test problem, Laplace's equation:\n\\begin{equation}\n\\frac{\\partial^2 \\Phi}{\\partial x^2} + \\frac{\\partial^2 \\Phi}{\\partial y^2} = 0, \n\\end{equation}\non the domain $0 \\le x \\le 1, 0 \\le y \\le 1$ with the boundary conditions $\\Phi(x,0)-=\\Phi(0,y)=\\Phi(1,y)=0, \\Phi(x,1)=f(x)$.  Exploying separation of variables $\\Phi(x,y)=X(x)Y(y)$ we find the ODE solutions for $X(x)$ and $Y(y)$ to be:\n\\begin{eqnarray}\nX(x) &=& A \\sin kx + B \\cos kx \\\\\nY(y) &=& A' \\sinh ky + B' \\cosh ky\n\\end{eqnarray}\nThe boundary conditions dictate the following constraints:  $\\Phi(0,y)=0 \\implies B=0, \\Phi(x,0) \\implies B'=0, \\Phi(1,y)=0 \\implies k=n \\pi$.  Thus we have the general solution:\n\\begin{equation}\n\\Phi(x,y) = \\sum_n A_n \\sinh (n \\pi y) \\sin (n \\pi x)\n\\end{equation}\nAgain choosing our boundary conditions for this test problem so that only one term in the series survives we may choose:\n\\begin{equation}\nf(x) = \\sin(2 \\pi x).\n\\end{equation}\nWhich gives:\n\\begin{equation}\nf(x) = \\sum_n A_n \\sinh (n \\pi) \\sin (n \\pi x),\n\\end{equation}\nfor the potential evaluated at the non-grounded boundary.  By orthogonality the coefficients are:  \n\\begin{equation}\nA_n = \\frac{2}{\\sinh (n \\pi)} \\left< f(x) | \\sin (n \\pi x) \\right>; \n\\end{equation}\nhowever the only nonzero coefficient occurs for $n=2$:\n\\begin{equation}\nA_2 = \\frac{2}{\\sinh (2 \\pi)} \\left< \\sin(2 \\pi x) | \\sin (2 \\pi x) \\right> = \\frac{1}{\\sinh(2 \\pi)}; \n\\end{equation}\nThe solution for this set of boundary conditions is, thus: \n\\begin{equation}\n\\Phi(x,y) = \\frac{\\sinh (2 \\pi y)}{\\sinh(2 \\pi)} \\sin (2 \\pi x)\n\\end{equation}\n\nAll potential solutions currently in GEMINI are two-dimensional so this particular test problem is representative of each.  \n\n\n\\section{Hyperbolic solver test problem}\n\nThe advection (hyperbolic) solver deals with problems of the form:\n\\begin{equation}\n\\frac{\\partial \\rho}{\\partial t} + \\frac{\\partial}{\\partial z} \\left( \\rho v \\right) = 0,  \n\\end{equation}\nand higher dimensional equivalents (implemented through directional splitting).  For constant velocity (assumed to be given) a simpler equation, which can be solved analytically, results.  \n\\begin{equation}\n\\frac{\\partial \\rho}{\\partial t} + v \\frac{\\partial \\rho}{\\partial z} = 0,  \n\\end{equation}\nThis equation can be seen to be equivalent to the wave equation by differentiating with respect to time and space respectively giving:  \n\\begin{eqnarray}\n\\frac{\\partial^2 \\rho}{\\partial t^2} + v \\frac{\\partial^2 \\rho}{\\partial t \\partial z} &=& 0 \\\\\n\\frac{\\partial^2 \\rho}{\\partial z \\partial t} + v \\frac{\\partial^2 \\rho}{\\partial z^2} &=& 0\n\\end{eqnarray}\nEliminating the cross partial derivatives from these equations gives the familiar wave equation.  \n\\begin{equation}\n\\frac{\\partial^2 \\rho}{\\partial t^2} - v^2 \\frac{\\partial^2 \\rho}{\\partial z^2} = 0,  \n\\end{equation}\nThe solution to this particular equation is a wave of the form:\n\\begin{equation}\n\\rho(z,t)=f(z-vt),\n\\end{equation}\nwhere the function $f$ is arbitrary, generally speaking, but dictated by the specific initial conditions of the problem of interest.  This solution can be verified by direct substitution, or derived by separation of variables - analogous to the test problems above.  For an initial condition given by:\n\\begin{equation}\n\\rho(z,0)=e^{-\\frac{z^2}{2 \\sigma_z^2}}\n\\end{equation}\nThe solution at later times is:\n\\begin{equation}\n\\rho(z,t)=e^{-\\frac{(z-vt)^2}{2 \\sigma_z^2}}\n\\end{equation}\nFor testing purposes it is useful to numerical solve this on a periodic domain, e.g. $0 \\le x \\le 1$.\n\nGEMINI advects mass, momentum, and energy in all three dimensions, representative of the equation:  \n\\begin{eqnarray}\n\\frac{\\partial \\rho}{\\partial t} + v_x \\frac{\\partial \\rho}{\\partial x} + v_y \\frac{\\partial \\rho}{\\partial y} + v_z \\frac{\\partial \\rho}{\\partial z} &=& 0 %\\\\  \n%\\frac{\\partial \\rho}{\\partial t} + \\mathbf{v} \\cdot \\nabla \\rho &=& 0 \\\\  \n\\end{eqnarray}\nFor initial conditions given by:\n\\begin{equation}\n\\rho(z,0)=e^{-\\frac{x^2}{2 \\sigma_x^2}}e^{-\\frac{y^2}{2 \\sigma_y^2}}e^{-\\frac{z^2}{2 \\sigma_z^2}}\n\\end{equation}\nthe solution at later time is:\n\\begin{equation}\n\\rho(z,t)=e^{-\\frac{(x-v_x t)^2}{2 \\sigma_x^2}}e^{-\\frac{(y - v_y t)^2}{2 \\sigma_y^2}}e^{-\\frac{(z-v_z t)^2}{2 \\sigma_z^2}}\n\\end{equation}\n\n\n\\pagebreak\n%\\setcounter{page}{1}\n\n%\\bibliography{GEMINI.bib}\n\n\n\\end{document}\n", "meta": {"hexsha": "d6264ee90098a389dd4af1bae64afc8f7420f3a1", "size": 9664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDEs/test_problems/PDEtests.tex", "max_stars_repo_name": "microckey/EP501_matlab", "max_stars_repo_head_hexsha": "909ab601922b5773a44c778af8f889be0bbe9966", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PDEs/test_problems/PDEtests.tex", "max_issues_repo_name": "microckey/EP501_matlab", "max_issues_repo_head_hexsha": "909ab601922b5773a44c778af8f889be0bbe9966", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-27T14:23:25.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-27T14:24:06.000Z", "max_forks_repo_path": "PDEs/test_problems/PDEtests.tex", "max_forks_repo_name": "microckey/EP501_matlab", "max_forks_repo_head_hexsha": "909ab601922b5773a44c778af8f889be0bbe9966", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-09-03T13:52:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-13T21:10:41.000Z", "avg_line_length": 49.306122449, "max_line_length": 580, "alphanum_fraction": 0.7012624172, "num_tokens": 3155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.6298355293142129}}
{"text": "%!TEX root = noBSguideMathMechCalc.tex\n\n%\\input{99.sympy_tutorial.tex}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n\\ifthenelse{\\boolean{TUTORIAL}}{}{\n\n\\vspace*{-5mm}\n\n\tComputers can be very useful for dealing with complicated math expressions\n\tor when slogging through tedious calculations.\t\n\tThroughout this book we used \\texttt{SymPy} to illustrate several concepts from math and physics.\n\t%\tto illustrate how computers can help us manipulate math and physics objects \n\tWe'll now review all the math and physics tools available through the \\texttt{SymPy} command line.\n\tDon't worry if you're not a computer person;\n\twe'll only discuss concepts we covered in the book,\n\tand the computer commands we'll learn are very similar to the math operations you're already familiar with.\n\tThis section also serves as a final review of the material covered in the book.\n} \n\n\n%=======================================================================  introduction\n\\section*{Introduction}\n\\label{sec:sympytut_introduction}\n\nYou can use a computer algebra system (CAS)\nto compute complicated math expressions, \nsolve equations, \nperform calculus procedures, \nand simulate physics systems.\n\nAll computer algebra systems offer essentially the same functionality,\nso it doesn't matter which system you use: \nthere are free systems like \\texttt{SymPy}, \\texttt{Magma}, or \\texttt{Octave}, \nand commercial systems like \\texttt{Maple}, \\texttt{MATLAB}, and \\texttt{Mathematica}.\nThis tutorial is an introduction to \\texttt{SymPy},\nwhich is a \\emph{symbolic} computer algebra system written in the programming language \\texttt{Python}. \nIn a symbolic CAS, \nnumbers and operations are represented symbolically, so the answers obtained are exact.\nFor example, the number $\\sqrt{2}$ is represented in \\texttt{SymPy} as the object \\texttt{Pow(2,1/2)},\nwhereas in \\emph{numerical} computer algebra systems like \\texttt{Octave}, the number $\\sqrt{2}$ is \nrepresented as the approximation $1.41421356237310$ (a \\texttt{float}).\nFor most purposes the approximation is okay,\nbut sometimes approximations can lead to problems:\n\\texttt{float(sqrt(2))*float(sqrt(2)) = 2.00000000000000044} $\\neq 2$.\nBecause \\texttt{SymPy} uses exact representations, \nyou'll never run into such problems: \\texttt{Pow(2,1/2)*Pow(2,1/2)}$ = 2$.\n\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\nThis tutorial is organized as follows.\nWe'll begin by introducing the \\texttt{SymPy} basics and the bread-and-butter functions\nused for manipulating expressions and solving equations.\nAfterward, we'll discuss the \\texttt{SymPy} functions that implement calculus operations like differentiation and integration.\nWe'll also introduce the functions used to deal with vectors and complex numbers.\nLater we'll see how to use vectors and integrals to understand Newtonian mechanics.\n\\ifthenelse{\\boolean{FORLA}}\n\t{In the last section, we'll introduce the linear algebra functions available in \\texttt{SymPy}.}\n\t{}\n}{}\n\n\nThis tutorial presents many explanations as blocks of code. \nBe sure to try the code examples on your own by typing the commands into \\texttt{SymPy}.\nIt's always important to verify for yourself!\n%Don't be a passive reader: \n%type out the commands presented. \n\n\n%\\vspace{1cm}\t% to push REPL at top of col2\n\n%=======================================================================  using_sympy\n\\section*{Using SymPy}\n\\label{sec:sympytut_using_sympy}\n\nThe easiest way to use \\texttt{SymPy},\nprovided you're connected to the Internet,\nis to visit \\href{http://live.sympy.org}{\\texttt{http://live.sympy.org}}.\nYou'll be presented with an interactive prompt into which\nyou can enter your commands---right in your browser. \n\nIf you want to use \\texttt{SymPy} on your own computer,\nyou must install \\texttt{Python} and the python package \\texttt{sympy}.\nYou can then open a command prompt and start a \\texttt{SymPy} session using:\n\n\n\n\\small\n\\begin{verbatimtab}\nyou@host$ python\nPython X.Y.Z \n[GCC a.b.c (Build Info)] on platform\nType \"help\", \"copyright\", or \"license\" for more information.\n>>> from sympy import *\n>>> \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe \\texttt{>{}>{}>} prompt indicates you're in the \\texttt{Python} shell which accepts \\texttt{Python} commands.\nThe command \\texttt{from sympy import *}$\\;$ imports all the \\texttt{SymPy} functions into the current namespace. \nAll \\texttt{SymPy} functions are now available to you.\n%\nTo exit the python shell press \\texttt{CTRL+D}. \n%\n%\\small\n%\\begin{verbatimtab}\n%>>>  ( press CTRL + D )\n%you@host$  \n%\\end{verbatimtab}\n%\\normalsize\n\nI highly recommend you also install \\texttt{ipython}, \nwhich is an improved interactive python shell.\nIf you have \\texttt{ipython} and \\texttt{SymPy} installed, \nyou can start an \\texttt{ipython} shell with \\texttt{SymPy} pre-imported using the command \\texttt{isympy}.\nFor an even better experience, \nyou can try \\texttt{ipython notebook}, which is a web frontend for the \\texttt{ipython} shell.\n\nEach section \\ifthenelse{\\boolean{TUTORIAL}}{of this tutorial}{in this appendix} begins with a python \\texttt{import} statement\nfor the functions used in that section.\nIf you use the statement \\texttt{from sympy import *}\\,\\, in the beginning of your code,\nyou don't need to run these individual import statements,\nbut I've included them so you'll know which \n\\texttt{SymPy} vocabulary is covered in each section.\n\n\n\n\n\n%\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\\def\\lesection{\\section}\n}{\n\\def\\lesection{\\section*}\n}\n\n%=======================================================================  basics\n\\lesection{Fundamentals of mathematics}\n\\label{sec:sympytut_fundamentals_of_mathematics}\n\nLet's begin by learning about the basic \\texttt{SymPy} objects and the operations we can carry out on them. \nWe'll learn the \\texttt{SymPy} equivalents of \n\\ifthenelse{\\boolean{TUTORIAL}}{many math verbs like}{the math verbs we used in Chapter~1:} \n``to solve'' (an equation),  \n%``to simplify'' (an expression), \n``to expand'' (an expression), \n``to factor'' (a polynomial). \n\n\\subsection{Numbers}\n\\label{basics:numbers}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import  sympify, S,  evalf, N\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIn \\texttt{Python}, there are two types of number objects: \\texttt{int}s and \\texttt{float}s.%\n\n\\small\n\\begin{verbatimtab}\n>>> 3\n3                             # an int\n>>> 3.0\n3.0                           # a float \n\\end{verbatimtab}\n\\normalsize\nInteger objects in \\texttt{Python} are a faithful representation of the set of integers $\\mathbb{Z}=\\{\\ldots,-2,-1,0,1,2,\\ldots\\}$.\nFloating point numbers are approximate representations of the reals $\\mathbb{R}$.\n%The name ``floating point'' comes from the fact that \\texttt{float}s can represent very small numbers \n%and very large numbers (by moving the decimal point).\nRegardless of its absolute size, \na floating point number is only accurate to 16 decimals.\n% you can think of floats as rational numbers of the form $\\frac{m}{10^n}$ where $m<10^{16}$ and $< n <$.\n\n%We won't go any further into the implementation details of how numbers are represented;\n%I just wanted to point out the difference between \\texttt{int}s, \\texttt{float}s, \n%and the set of real numbers $\\mathbb{R}$. \n%Sandy said: these lines could be more fitting for a teacher's guide, but I think for students it is TMI, since the differences are explained concisely and neatly above.\n\n\n% Floats are only approximations, but if you want to do calculations with floats you can use the GPU\n \nSpecial care is required when specifying rational numbers,\nbecause integer division might not produce the answer you want.\nIn other words, \n\\texttt{Python} will not automatically convert the answer to a floating point number,\nbut instead round the answer to the closest integer:\n\\small\n\\begin{verbatimtab}\n>>> 1/7\n0                             # int/int gives int \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nTo avoid this problem, you can force \\texttt{float} division by using the number \\texttt{1.0} instead of \\texttt{1}:\n\\small\n\\begin{verbatimtab}\n>>> 1.0/7\n0.14285714285714285           # float/int gives float\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThis result is better, but it's still only an approximation of the exact number $\\frac{1}{7} \\in \\mathbb{Q}$, \nsince a \\texttt{float} has 16 decimals while the decimal expansion of $\\frac{1}{7}$ is infinitely long. \nTo obtain an \\emph{exact} representation of $\\frac{1}{7}$ you need to create a \\texttt{SymPy} expression.\nYou can \\texttt{sympify} any expression using the shortcut function \\texttt{S()}:\n\\small\n\\begin{verbatimtab}\nS('1/7')\n1/7                           # = Rational(1,7)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote the input to \\texttt{S()} is specified as a text string delimited by quotes.\nWe could have achieved the same result using \\texttt{S('1')/7} since\na \\texttt{SymPy} object divided by an \\texttt{int} is a \\texttt{SymPy} object.\n\nExcept for the tricky \\texttt{Python} division operator, \nother math operators like addition \\texttt{+}, subtraction \\texttt{-}, \nand multiplication \\texttt{*} work as you would expect.\nThe syntax \\texttt{**} is used in \\texttt{Python} to denote exponentiation:\n\\small\n\\begin{verbatimtab}\n>>> 2**10                    # same as S('2^10')\n1024\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWhen solving math problems, \nit's best to work with \\texttt{SymPy} objects,\nand wait to compute the numeric answer in the end.\nTo obtain a numeric approximation of a \\texttt{SymPy} object as a  \\texttt{float}, \ncall  its \\texttt{.evalf()} method: %Sandy said: what do you mean by 'call'?\n\n\\small\n\\begin{verbatimtab}\n>>> pi\npi\n>>> pi.evalf()\n3.14159265358979\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe method \\texttt{.n()} is equivalent to \\texttt{.evalf()}.\nThe global \\texttt{SymPy} function \\texttt{N()} can also be used to to compute numerical values.\n%\nYou can easily change the number of digits of precision of the approximation.\nEnter \\texttt{pi.n(400)} to obtain an approximation of $\\pi$ to 400 decimals.\n\n\\subsection{Symbols}\n\\label{basics:symbols}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import Symbol, symbols\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nPython is a civilized language so there's no need to define variables before assigning values to them.\nWhen you write \\texttt{a = 3}, you define a new name \\texttt{a} and set it to the value \\texttt{3}.\nYou can now use the name \\texttt{a} in  subsequent calculations.\n\nMost interesting \\texttt{SymPy} calculations require us to define \\texttt{symbols}, \nwhich are the \\texttt{SymPy} objects for representing variables and unknowns.\nFor your convenience, when \\href{http://live.sympy.org}{\\texttt{live.sympy.org}} starts,\nit runs the following commands automatically:\n\n\\small\n\\begin{verbatimtab}\n>>> from __future__ import division\n>>> from sympy import *\n>>> x, y, z, t = symbols('x y z t')\n>>> k, m, n = symbols('k m n', integer=True)\n>>> f, g, h = symbols('f g h', cls=Function)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe first statement instructs python to convert \\texttt{1/7} to \\texttt{1.0/7} when dividing,\npotentially saving you from any \\texttt{int} division confusion.\nThe second statement imports all the \\texttt{SymPy} functions.\nThe remaining statements define some generic symbols \\texttt{x}, \\texttt{y}, \\texttt{z}, and \\texttt{t},\nand several other symbols with special properties.\n\nNote the difference between the following two statements:\n\n\\small\n\\begin{verbatimtab}\n>>> x + 2           \nx + 2                 # an Add expression\n>>> p + 2 \nNameError: name 'p' is not defined\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe name \\texttt{x} is defined as a symbol, so \\texttt{SymPy} knows that \\texttt{x + 2} is an expression;\nbut the variable \\texttt{p} is not defined, so \\texttt{SymPy} doesn't know what to make of \\texttt{p + 2}.\nTo use \\texttt{p} in expressions, \nyou must first define it as a symbol:\n\n\\small\n\\begin{verbatimtab}\n>>> p = Symbol('p')   # the same as p = symbols('p')\n>>> p + 2\np + 2                 # = Add(Symbol('p'), Integer(2))\n\\end{verbatimtab}\n\\normalsize\n\n\n\\printcp\n\n\\noindent\nYou can define a sequence of variables using the following notation:\n\\small\n\\begin{verbatimtab}\n>>> a0, a1, a2, a3 = symbols('a0:4')\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nYou can use any name you want for a variable,\nbut it's best if you avoid the letters \\texttt{Q,C,O,S,I,N} and \\texttt{E} because they have special uses in \\texttt{SymPy}:\n\\texttt{I} is the unit imaginary number $i\\equiv\\sqrt{-1}$, \n\\texttt{E} is the base of the natural logarithm,\n\\texttt{S()} is the \\texttt{sympify} function,\n\\texttt{N()} is used to obtain numeric approximations, and\n\\texttt{O} is used for big-\\texttt{O} notation.\n\nThe underscore symbol \\texttt{\\char`_} is a special variable that contains the result of the last printed value.\nThe variable \\texttt{\\char`_} is analogous to the \\texttt{ans} button on certain calculators,\nand is useful in multi-step calculations:\n\n\\small\n\\begin{verbatimtab}\n>>> 3+3\n6\n>>> _*2\n12\n\\end{verbatimtab}\n\\normalsize\n\n\n\\subsection{Expressions}\n\\label{basics:expressions}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import simplify, factor, expand, collect\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nYou define \\texttt{SymPy} expressions by combining symbols\nwith basic math operations and other functions: \n\n\\small\n\\begin{verbatimtab}\n>>> expr = 2*x + 3*x - sin(x) - 3*x + 42\n>>> simplify(expr)\n2*x - sin(x) + 42\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe function \\texttt{simplify} can be used on any expression to simplify it.\nThe examples below illustrate other useful \\texttt{SymPy} functions\nthat correspond to common mathematical operations on expressions: \n%COMMENT: do you mean 'or' expressions? @SANDY: no, operations like factor, expand, etc, act  on math expressions\n\n\\small\n\\begin{verbatimtab}\n>>> factor( x**2-2*x-8 )\n(x - 4)*(x + 2)\n>>> expand( (x-4)*(x+2) )\nx**2 - 2*x - 8\n>>> collect(x**2 + x*b + a*x + a*b, x)\nx**2 + (a+b)*x + a*b     # collect terms for diff. pows of x \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nTo substitute a given value into an expression,\ncall the \\texttt{.subs()} method, passing in a python dictionary object \\texttt{\\{ key:val, ... \\}} \nwith the symbol--value substitutions you want to make:\n\n\\small\n\\begin{verbatimtab}\n>>> expr  = sin(x) + cos(y)\n>>> expr\nsin(x) + cos(y)\n>>> expr.subs({x:1, y:2})\nsin(1) + cos(2)\n>>> expr.subs({x:1, y:2}).n()\n0.425324148260754\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote how we used \\texttt{.n()} to obtain the expression's numeric value.\n\n\\subsection{Solving equations}\n\\label{basics:solving_equations}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import solve\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe function \\texttt{solve} is the main workhorse in \\texttt{SymPy}. \nThis incredibly powerful function knows how to solve all kinds of equations.\nIn fact \\texttt{solve} can solve pretty much \\emph{any} equation!\nWhen high school students learn about this function, they get really angry---why \ndid they spend five years of their life learning to solve various equations by hand,\nwhen all along there was this \\texttt{solve} thing that could do all the math for them?\n%Computers are nice like that.\nDon't worry, learning math is \\emph{never} a waste of time.\n\n\nThe function \\texttt{solve} takes two arguments.\nUse \\texttt{solve(expr,var)} to solve the equation \\texttt{expr==0} for the variable \\texttt{var}.\n%you want to solve assuming the form \n%The first argument specifies an expression which is equal to zero, \nYou can rewrite any equation in the form \\texttt{expr==0} by moving all the terms to one side of the equation;\nthe solutions to $A(x)=B(x)$ are the same as the solutions to $A(x)-B(x)=0$.\n\nFor example, \nto solve the quadratic equation $x^2+2x-8=0$, use\n\n\\small\n\\begin{verbatimtab}\n>>> solve( x**2 + 2*x - 8, x)\n[2, -4]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIn this case the equation has two solutions so \\texttt{solve} returns a list.\nCheck that $x=2$ and $x=-4$ satisfy the equation $x^2+2x-8=0$.\n\nThe best part about \\texttt{solve} and \\texttt{SymPy} is that you can obtain symbolic answers when solving equations. \nInstead of solving one specific quadratic equation,\nwe can solve all possible equations of the form $ax^2 + bx+c=0$ using the following steps:\n\n\\small\n\\begin{verbatimtab}\n>>> a, b, c = symbols('a b c')\n>>> solve( a*x**2 + b*x + c, x)\n[(-b + sqrt(b**2 - 4*a*c))/(2*a), (-b-sqrt(b**2-4*a*c))/(2*a)]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIn this case \\texttt{solve} calculated the solution in terms of the symbols \\texttt{a}, \\texttt{b}, and \\texttt{c}.\nYou should be able to recognize the expressions in the solution---it's the quadratic formula $x_{1,2} = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$.\n\n\\ifthenelse{\\boolean{TUTORIAL}}{  \n\t\\input{99.quadratic_eqn_subsitution_example.tex}\n}{} \n\n\n\\bigskip\n\n\\noindent\nTo solve a \\emph{system of equations}, you can feed \\texttt{solve} with the list of equations\nas the first argument, and specify the list of unknowns you want to solve for as the second argument.\nFor example, to solve for $x$ and $y$ in the system of equations $x+y =3$ and $3x-2y=0$, use\n\n\\small\n\\begin{verbatimtab}\n>>> solve([x + y - 3, 3*x - 2*y], [x, y])\n{x: 6/5, y: 9/5}\n\\end{verbatimtab}\n\\normalsize\n\n\\bigskip\n\n\\noindent\nThe function \\texttt{solve} is like a Swiss Army knife you can use to solve all kind of problems.\nSuppose you want to \\emph{complete the square} in the expression $x^2-4x+7$,\nthat is, you want to find constants $h$ and $k$ such that $x^2-4x+7 = (x-h)^2 +k$.\nThere is no special ``complete the square'' function in \\texttt{SymPy},\nbut you can call \\texttt{solve} on the equation $(x-h)^2 +k \\ - \\  (x^2-4x+7) = 0$\nto find the unknowns $h$ and $k$:\n\n\\small\n\\begin{verbatimtab}\n>>> h, k = symbols('h k')\n>>> solve( (x-h)**2 + k  - (x**2-4*x+7), [h,k] )\n[(2, 3)]                               # so h = 2 and k = 3\n>>> ((x-2)**2+3).expand()              # verify...\nx**2 - 4*x + 7\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nLearn the basic \\texttt{SymPy} commands \nand you'll never need to suffer another tedious arithmetic calculation painstakingly performed by hand again!\n\n\n\n\\subsection{Rational functions}\n\\label{basics:rational_functions}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import together, apart\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nBy default, \\texttt{SymPy} will not combine or split rational expressions.\nYou need to use \\texttt{together} to symbolically calculate the addition of fractions:\n\n\\small\n\\begin{verbatimtab}\n>>> a, b, c, d = symbols('a b c d')\n>>> a/b + c/d\na/b + c/d\n>>> together(a/b + c/d)\n(a*d + b*c)/(b*d)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nAlternately, if you have a rational expression and want to divide the numerator by the denominator,\nuse the \\texttt{apart} function:\n\n\\small\n\\begin{verbatimtab}\n>>> apart( (x**2+x+4)/(x+2)  )\nx - 1  +  6/(x + 2)\n\\end{verbatimtab}\n\\normalsize\n\n\n\\subsection{Exponentials and logarithms}\n\\label{basics:exponentials_and_logarithms}\n\nEuler's constant $e=2.71828\\ldots$ is defined one of several ways,\n\\[\n  e \\equiv \\lim_{n\\to \\infty} \\left( 1 + \\frac{1}{n}\\right)^{n}\n    \\equiv \\lim_{\\epsilon \\to 0} \\left( 1 + \\epsilon\\right)^{1/\\epsilon}\n    \\equiv \\sum_{n=0}^\\infty \\frac{1}{n!},\n\\]\nand is denoted \\texttt{E} in \\texttt{SymPy}. \nUsing \\texttt{exp(x)} is equivalent to \\texttt{E**x}.\n\nThe functions \\texttt{log} and \\texttt{ln} both compute the logarithm base $e$:\n\n\\small\n\\begin{verbatimtab}\n>>> log(E**3)    # same as ln(E**3)\n3\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nBy default, \\texttt{SymPy} assumes the inputs to functions like \\texttt{exp} and \\texttt{log} are complex numbers,\nso it will not expand certain logarithmic expressions. \nHowever, indicating to \\texttt{SymPy} that the inputs are positive real numbers will make the expansions work:\n\n\\small\n\\begin{verbatimtab}\n>>> x, y = symbols('x y')\n>>> log(x*y).expand()\nlog(x*y)\n>>> a, b = symbols('a b', positive=True)\n>>> log(a*b).expand()\nlog(a) + log(b)\n\\end{verbatimtab}\n\\normalsize\n\\subsection{Polynomials}\n\\label{basics:polynomials}\n\nLet's define a polynomial $P$ with roots at $x=1$, $x=2$, and $x=3$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> P = (x-1)*(x-2)*(x-3)\n>>> P\n(x - 1)*(x - 2)*(x - 3)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nTo see the expanded version of the polynomial, \ncall its \\texttt{expand} method:\n\n\\small\n\\begin{verbatimtab}\n>>> P.expand()\nx**3 - 6*x**2 + 11*x - 6\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWhen the polynomial is expressed in it's expanded form $P(x)=x^3-6^2 + 11x - 6$,\nwe can't immediately identify its roots. \nThis is why the factored form $P(x)=(x-1)(x-2)(x-3)$ is preferable.\nTo factor a polynomial, \ncall its \\texttt{factor} method or \\texttt{simplify} it:\n\n\\small\n\\begin{verbatimtab}\n>>> P.factor()\n(x - 1)*(x - 2)*(x - 3)\n>>> P.simplify()\n(x - 1)*(x - 2)*(x - 3)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nRecall that the roots of the polynomial $P(x)$ are defined as the solutions to the equation $P(x)=0$.\nWe can use the \\texttt{solve} function to find the roots of the polynomial:\n\n\\small\n\\begin{verbatimtab}\n>>> roots = solve(P,x)\n>>> roots\n[1, 2, 3]\n# let's check if P equals (x-1)(x-2)(x-3)\n>>> simplify( P  -  (x-roots[0])*(x-roots[1])*(x-roots[2]) )   \n0  \n\\end{verbatimtab}\n\\normalsize\n\n\n\\subsection{Equality checking}\n\\label{basics:equality_checking}\n\nIn the last example, we used the \\texttt{simplify} function to check whether two expressions were equal.\nThis way of checking equality works because $P=Q$ if and only if $P-Q=0$.\nThis is the best way to check if two expressions are equal in \\texttt{SymPy}\nbecause it attempts all possible simplifications when comparing the expressions.\nBelow is a list of other ways to check whether two quantities are equal\nwith example cases where they fail:\n\n\\small\n\\begin{verbatimtab}\n>>> p = (x-5)*(x+5)\n>>> q = x**2 - 25\n>>> p == q                                      # fail\nFalse\n>>> p - q == 0                                  # fail \nFalse\n>>> simplify(p - q) == 0          \nTrue\n>>> sin(x)**2 + cos(x)**2  == 1                 # fail\nFalse\n>>> simplify( sin(x)**2 + cos(x)**2  - 1) == 0\nTrue\n\\end{verbatimtab}\n\\normalsize\n\n\n\\subsection{Trigonometry}\n\\label{basics:trigonometry}\n\n\\small\n\\begin{verbatimtab}\nfrom sympy import sin, cos, tan, trigsimp, expand_trig\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe trigonometric functions \\texttt{sin} and \\texttt{cos} take inputs in radians: \n\n\n\n\\small\n\\begin{verbatimtab}\n>>> sin(pi/6)\n1/2\n>>> cos(pi/6)\nsqrt(3)/2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nFor angles in degrees, \nyou need a conversion factor of $\\frac{\\pi}{180}$[rad/$^\\circ$]:\n\n\\small\n\\begin{verbatimtab}\n>>> sin(30*pi/180)                 # 30 deg = pi/6 rads \n1/2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe inverse trigonometric functions $\\sin^{-1}(x)\\equiv \\arcsin(x)$\nand $\\cos^{-1}(x)\\equiv \\arccos(x)$ are used as follows:\n\n\\small\n\\begin{verbatimtab}\n>>> asin(1/2)\npi/6\n>>> acos(sqrt(3)/2)\npi/6\n\\end{verbatimtab}\n\\normalsize\nRecall that $\\tan(x) \\equiv \\frac{\\sin(x)}{\\cos(x)}$.\nThe inverse function of $\\tan(x)$ is $\\tan^{-1}(x)\\equiv \\arctan(x)\\equiv$ \\texttt{atan(x)}\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> tan(pi/6)\n1/sqrt(3)                          # = ( 1/2 )/( sqrt(3)/2 )\n>>> atan( 1/sqrt(3) )\npi/6\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe function \\texttt{acos} returns angles in the range $[0,\\pi]$,\nwhile \\texttt{asin} and \\texttt{atan} return angles in the range $[-\\frac{\\pi}{2},\\frac{\\pi}{2}]$.\n\n\nHere are some trigonometric identities that \\texttt{SymPy} knows:\n\n\\small\n\\begin{verbatimtab}\n>>> sin(x) == cos(x - pi/2)      \nTrue\n>>> simplify( sin(x)*cos(y)+cos(x)*sin(y) )\nsin(x + y)\n>>> e = 2*sin(x)**2 + 2*cos(x)**2\n>>> trigsimp(e)\n2\n>>> trigsimp(log(e))\nlog(2*sin(x)**2 + 2*cos(x)**2)\n>>> trigsimp(log(e), deep=True)\nlog(2)\n\\end{verbatimtab}\n\\normalsize\n\n\\small\n\\begin{verbatimtab}\n>>> simplify(sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4)\ncos(4*x)/2 + 1/2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe function \\texttt{trigsimp} does essentially the same job as \\texttt{simplify}.\n\nIf instead of simplifying you want to expand a trig expression,\nyou should use \\texttt{expand\\_trig}, because the default \\texttt{expand} won't touch trig functions:\n\n\\small\n\\begin{verbatimtab}\n>>> expand(sin(2*x))        # = (sin(2*x)).expand()\nsin(2*x)\n>>> expand_trig(sin(2*x))   # = (sin(2*x)).expand(trig=True)\n2*sin(x)*cos(x)\n\\end{verbatimtab}\n\\normalsize\n\n\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\t\\input{99.hyperbolic_functions_sympy_tutorial.tex}\n\n}{}\n\n\n\n%=======================================================================  complex_numbers\n\\lesection{Complex numbers}\n\\label{sec:sympytut_complex_numbers}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import I, re, im, Abs, arg, conjugate\n\\end{verbatimtab}\n\\normalsize\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\tEver since Newton,\n\tthe word ``number'' has been used to refer to one of the following types of math objects:\n\tthe naturals $\\mathbb{N}$, \n\tthe integers $\\mathbb{Z}$, \n\tthe rationals $\\mathbb{Q}$, \n\tand the real numbers $\\mathbb{R}$.\n\tEach set of numbers is associated with a different class of equations.\n\tThe natural numbers $\\mathbb{N}$ appear as solutions of the equation $m+n=x$, \n\twhere $m$ and $n$ are natural numbers (denoted $m,n \\in \\mathbb{N}$).\n\tThe integers $\\mathbb{Z}$ are the solutions to equations of the form $x+m=~n$, where $m,n \\in \\mathbb{N}$.\n\tThe rational numbers $\\mathbb{Q}$ are necessary to solve for $x$ in $mx=n$, with $m,n \\in \\mathbb{Z}$.\n\tThe solutions to $x^2=2$ are irrational (so $\\notin \\mathbb{Q}$) so we need an even larger set that \n\tcontains \\emph{all} possible numbers: real set of numbers $\\mathbb{R}$.\n\tA pattern emerges where more complicated equations require the invention of new types of numbers.\n\n}{\\noindent}% \nConsider the quadratic equation $x^2=-1$.\nThere are no real solutions to this equation,\nbut we can define an imaginary number $i =\\sqrt{-1}$ (denoted \\texttt{I} in \\texttt{SymPy}) that satisfies this equation:\n\n\\small\n\\begin{verbatimtab}\n>>> I*I\n-1\n>>> solve( x**2 + 1 , x)\n[I, -I]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe solutions are $x=i$ and $x=-i$,\nand indeed we can verify that $i^2+1=0$ and $(-i)^2+1=0$\nsince $i^2=-1$.\n\nThe complex numbers $\\mathbb{C}$ are defined as $\\{ a+bi \\,|\\, a,b \\in \\mathbb{R} \\}$.\nComplex numbers contain a real part and an imaginary part:\n\n\\small\n\\begin{verbatimtab}\n>>> z = 4 + 3*I\n>>> z \n4 + 3*I\n>>> re(z)\n4\n>>> im(z)\n3 \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe \\emph{polar} representation of a complex number is $z\\!\\equiv\\!|z|\\angle\\theta\\!\\equiv \\!|z|e^{i\\theta}$.\nFor a complex number $z=a+bi$, \nthe quantity $|z|=\\sqrt{a^2+b^2}$ is known as the absolute value of $z$,\nand $\\theta$ is its \\emph{phase} or its \\emph{argument}:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> Abs(z)\n5\n>>> arg(z)\natan(3/4)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe complex conjugate of $z=a+bi$ is the number $\\bar{z} = a-bi$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> conjugate( z )\n4 - 3*I\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nComplex conjugation is important for computing the absolute value of $z$\n($|z|\\equiv\\sqrt{ z\\bar{z} }$) and for division by $z$ ($\\frac{1}{z} \\equiv \\frac{\\bar{z}}{|z|^2}$).\n\n\\subsection{Euler's formula}\n\\label{complex_numbers:euler_s_formula}\n\n\\small\n\\begin{verbatimtab}\n>>> from sympy import expand, rewrite\n\\end{verbatimtab}\n\\normalsize\n\\href{https://en.wikipedia.org/wiki/Euler's_formula}{Euler's formula} shows an important relation \nbetween the exponential function $e^x$ and the trigonometric functions $\\sin(x)$ and $\\cos(x)$:  \n\\[\n  e^{ix} = \\cos x + i \\sin x.\n\\]\nTo obtain this result in \\texttt{SymPy}, you must specify that the number $x$ is real\nand also tell \\texttt{expand} that you're interested in complex expansions:\n\n\\small\n\\begin{verbatimtab}\n>>> x = symbols('x', real=True)\n>>> exp(I*x).expand(complex=True)\ncos(x) + I*sin(x) \n>>> re( exp(I*x) ) \ncos(x)\n>>> im( exp(I*x) ) \nsin(x)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nBasically, $\\cos(x)$ is the real part of $e^{ix}$,\nand $\\sin(x)$ is the imaginary part of $e^{ix}$.\nWhaaat? \nI know it's weird,\nbut weird things are bound to happen when you input imaginary numbers to functions.\n\n%\t\\href{https://en.wikipedia.org/wiki/Euler's_identity}{Euler's identity} is Euler's formula with $x=\\pi$:  \n%\t$e^{i\\pi} = \\cos \\pi + i\\sin \\pi = - 1$,\n%\twhich we can rewrite as $e^{i\\pi} + 1=0$.\n%\tLet's check that \\texttt{SymPy} knows about Euler's identity:\n%\t\\small\n%\t\\begin{verbatimtab}\n%\t>>> (exp(I*pi) + 1).expand(complex=True)\n%\t0\n%\t\\end{verbatimtab}\n%\t\\normalsize\n\nEuler's formula is often used to rewrite the functions $\\sin$ and $\\cos$ in terms of complex exponentials.\nFor example,\n\n\\small\n\\begin{verbatimtab}\n>>> (cos(x)).rewrite(exp)\nexp(I*x)/2 + exp(-I*x)/2\n\\end{verbatimtab} \n\\normalsize\n\n\\noindent\nCompare this expression with the definition of hyperbolic cosine. \n%function $\\cosh(x) \\equiv \\frac{1}{2}(e^x+e^{-x})$.\n%Funky stuff, I know...\n\n%=======================================================================  calculus\n\\lesection{Calculus}\n\\label{sec:sympytut_calculus}\n\nCalculus is the study of the properties of functions.\nThe operations of calculus are used to describe the limit behaviour of functions,\ncalculate their rates of change,\nand calculate the areas under their graphs.\nIn this section we'll learn about the \\texttt{SymPy} functions for calculating\nlimits, derivatives, integrals, and summations.\n\n\\subsection{Infinity}\n\\label{calculus:infinity}\n\n\\small\n\\begin{verbatimtab}\nfrom sympy import oo\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe infinity symbol is denoted \\texttt{oo} (two lowercase \\texttt{o}s) in \\texttt{SymPy}.\nInfinity is not a number but a process: the process of counting forever.\nThus, $\\infty + 1 = \\infty$, \n$\\infty$ is greater than any finite number,\nand $1/\\infty$ is an infinitely small number.\nSympy knows how to correctly treat infinity in expressions:\n\n\\small\n\\begin{verbatimtab}\n>>> oo+1\noo\n>>> 5000 < oo \nTrue\n>>> 1/oo\n0\n\\end{verbatimtab}\n\\normalsize\n\n\\subsection{Limits}\n\\label{calculus:limits}\n\\small\n\\begin{verbatimtab}\nfrom sympy import limit\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWe use limits to describe, with mathematical precision, infinitely large quantities,\ninfinitely small quantities, and procedures with infinitely many steps.\n\nThe number $e$ is defined as the limit\n$\\displaystyle e \\equiv \\lim_{n\\to \\infty} \\left( 1 + \\frac{1}{n}\\right)^{n}$:\n\\small\n\\begin{verbatimtab}\n>>> limit( (1+1/n)**n, n, oo)\nE          # = 2.71828182845905\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThis limit expression describes the annual growth rate of a loan with \na nominal interest rate of $100\\%$ and infinitely frequent compounding.\n%If you \nBorrow $\\$1000$ in such a scheme, and \n % on January 1\\textsuperscript{st},\nyou'll owe $\\$2718.28$ after one~year.\n\n\nLimits are also useful to describe the behaviour of functions.\nConsider the function $f(x)=\\frac{1}{x}$.\nThe \\texttt{limit} command shows us what happens to $f(x)$ near $x=0$ and as $x$ goes to infinity:\n\n\\small\n\\begin{verbatimtab}\n>>> limit( 1/x, x, 0, dir=\"+\")\noo\n>>> limit( 1/x, x, 0, dir=\"-\")\n-oo\n>>> limit( 1/x, x, oo)\n0\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nAs $x$ becomes larger and larger, the fraction $\\frac{1}{x}$ becomes smaller and smaller.\nIn the limit where $x$ goes to infinity, $\\frac{1}{x}$ approaches zero: $\\lim_{x\\to \\infty} \\frac{1}{x} = 0$. \nOn the other hand, when $x$ takes on smaller and smaller positive values,\nthe expression $\\frac{1}{x}$ becomes infinite: $\\lim_{x \\to 0^+} \\frac{1}{x} = \\infty$.\nWhen $x$ approaches $0$ from the left, we have $\\lim_{x \\to 0^-} \\frac{1}{x} = -\\infty$.\nIf these calculations are not clear to you,\nstudy the graph of $f(x)=\\frac{1}{x}$.\n\n\nHere are some other examples of limits:\n\n\\small\n\\begin{verbatimtab}\n>>> limit(sin(x)/x, x, 0)\n1\n>>> limit(sin(x)**2/x, x, 0)\n0\n>>> limit(exp(x)/x**100,x,oo) # which is bigger e^x or x^100 ?\noo                            # exp f >> all poly f for big x  \n\\end{verbatimtab}\n\\normalsize\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\\noindent\nLimits are used to define the derivative and the integral operations.\n}{}\n\n\\subsection{Derivatives}\n\\label{calculus:derivatives}\nThe derivative function, denoted $f'(x)$, $\\frac{d}{dx}f(x)$, $\\frac{df}{dx}$, or $\\frac{dy}{dx}$, \ndescribes the \\emph{rate of change} of the function $f(x)$.\nThe \\texttt{SymPy} function \\texttt{diff} computes the derivative of any expression:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> diff(x**3, x)\n3*x**2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe differentiation operation knows about the product rule $[f(x)g(x)]^\\prime=f^\\prime(x)g(x)+f(x)g^\\prime(x)$, \nthe chain rule $f(g(x))' = f'(g(x))g'(x)$, \nand the quotient rule $\\left[\\frac{f(x)}{g(x)}\\right]^\\prime = \\frac{f'(x)g(x) - f(x)g'(x)}{g(x)^2}$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> diff( x**2*sin(x), x )\n2*x*sin(x) + x**2*cos(x)\n>>> diff( sin(x**2),   x )\ncos(x**2)*2*x\n>>> diff( x**2/sin(x), x )\n(2*x*sin(x) - x**2*cos(x))/sin(x)**2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe second derivative of a function \\texttt{f} is \\texttt{diff(f,x,2)}:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> diff(x**3, x, 2)       # same as diff(diff(x**3, x), x)\n6*x\n\\end{verbatimtab}\n\\normalsize\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\n\t\\input{99.simle_ode_example.tex}\n}{}\n\n\n\\subsection{Tangent lines}\n\\label{calculus:tangent_lines}\n\nThe \\emph{tangent line} to the function $f(x)$ at $x=x_0$ is \nthe line that passes through the point $(x_0, f(x_0))$ and has \nthe same slope as the function at that point.\nThe tangent line to the function $f(x)$ at the point $x=x_0$ is described by the equation\n\\[\n   T_1(x) =  f(x_0) \\ + \\  f'(x_0)(x-x_0).\n\\]\nWhat is the equation of the tangent line to $f(x)=\\frac{1}{2}x^2$ at $x_0=1$?\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> f = S('1/2')*x**2\n>>> f\nx**2/2\n>>> df = diff(f,x)\n>>> df\nx\n>>> T_1 = f.subs({x:1}) + df.subs({x:1})*(x - 1)\n>>> T_1\nx - 1/2           #  y = x - 1/2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe tangent line $T_1(x)$ has the same value and slope as the function $f(x)$ at $x=1$:\n\\small\n\\begin{verbatimtab}\n>>> T_1.subs({x:1}) == f.subs({x:1})\nTrue\n>>> diff(T_1,x).subs({x:1}) == diff(f,x).subs({x:1})\nTrue\n\\end{verbatimtab}\n\\normalsize\n\n\\ifthenelse{\\boolean{TUTORIAL}}{}{\n\t\\noindent\n\tSee Figure~\\ref{fig:derivative_and_tangent_line_bis} on page~\\pageref{fig:derivative_and_tangent_line_bis}.\n}\n\n\\subsection{Optimization}\n\\label{calculus:optimization}\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\n\tOptimization is about choosing an input for a function $f(x)$ that results in the best value for $f(x)$.\n\tThe best value usually means the \\emph{maximum} value \n\t(if the function represents something desirable like profits) \n\tor the \\emph{minimum} value \n\t(if the function represents something undesirable like costs).\n\n\tThe derivative $f'(x)$ encodes the information about the \\emph{slope} of $f(x)$.\n\tPositive slope $f'(x)>0$ means $f(x)$ is increasing,\n\tnegative slope $f'(x)<0$ means $f(x)$ is decreasing, \n\tand zero slope $f'(x)=0$ means the graph of the function is horizontal.\n\tThe \\emph{critical points} of a function $f(x)$ are the solutions to the equation $f'(x)=0$.\n\tEach critical point is a candidate to be either a maximum or a minimum of the function.\n\n\tThe second derivative $f^{\\prime\\prime}(x)$ encodes the information about the \\emph{curvature} of $f(x)$.\n\tPositive curvature means the function looks like~$x^2$,\n\tnegative curvature means the function looks like $-x^2$.\n\n}{\n\n\tRecall the \\emph{second derivative test} for finding the maxima and minima of a function,\n\twhich we learned on page~\\pageref{optimization_algorithm:alternate_algorithm}.\n\t\n}\n\nLet's find the critical points of the function $f(x)=x^3-2x^2+x$ \nand use the information from its second derivative \nto find the maximum of the function \non the interval $x \\in [0,1]$.\n\n\\small\n\\begin{verbatimtab}\n>>> x = Symbol('x')\n>>> f = x**3-2*x**2+x\n>>> diff(f, x)\n3*x**2 - 4*x + 1\n>>> sols = solve( diff(f,x),  x)\n>>> sols\n[1/3, 1]\n>>> diff(diff(f,x), x).subs( {x:sols[0]} )\n-2\n>>> diff(diff(f,x), x).subs( {x:sols[1]} )\n2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\n\\href{https://www.google.ca/\\#q=plot+x**3-2*x**2++\\%2B+x&safe=off}{It will help to look at the graph of this function.}\nThe point $x=\\frac{1}{3}$ is a local maximum because it is a critical point of $f(x)$\nwhere the curvature is negative, meaning $f(x)$ looks like the peak of a mountain at $x=\\frac{1}{3}$.\nThe maximum value of $f(x)$ on the interval $x\\in [0,1]$ is $f\\!\\left(\\frac{1}{3}\\right)=\\frac{4}{27}$.\nThe point $x=1$ is a local minimum because it is a critical point\nwith positive curvature, meaning $f(x)$ looks like the bottom of a valley at $x=1$.\n\n\n\n\n\\subsection{Integrals}\n\\label{calculus:integrals}\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\nThe \\emph{integral} of $f(x)$ corresponds to the computation of the area under the graph of $f(x)$.\nThe area under $f(x)$ between the points $x=a$ and $x=b$ is denoted as follows:\n\\[\n A(a,b) = \\int_a^b f(x) \\: dx.\n\\]\nThe \\emph{integral function} $F$ corresponds to the area calculation as a function \nof the upper limit of integration:\n\\[\n  F(c) \\equiv \\int_0^c \\! f(x)\\:dx\\,.\n\\]\nThe area under $f(x)$ between $x=a$ and $x=b$ is obtained by \ncalculating the \\emph{change} in the integral function:\n\\[\n   A(a,b) = \\int_a^b \\! f(x)\\:dx  =  F(b)-F(a).\n\\]\n\n}{}\n\nIn \\texttt{SymPy} we use \\texttt{integrate(f, x)} to obtain the integral function $F(x)$ of any function $f(x)$:\n$F(x) = \\int_0^x f(u)\\,du$.\n\n\\small\n\\begin{verbatimtab}\n>>> integrate(x**3, x)\nx**4/4\n>>> integrate(sin(x), x)\n-cos(x)\n>>> integrate(ln(x), x)\nx*log(x) - x\n\\end{verbatimtab}\n\\normalsize\nThis is known as an \\emph{indefinite integral} since the limits of integration are not defined. \n\nIn contrast, \na \\emph{definite integral} computes the area under $f(x)$ between $x=a$ and $x=b$.\nUse \\texttt{integrate(f, (x,a,b))} to compute the definite integrals of the form $A(a,b)=\\int_a^b f(x) \\, dx$:\n\n\\small\n\\begin{verbatimtab}\n>>> integrate(x**3, (x,0,1))    \n1/4              # the area under x^3 from x=0 to x=1\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWe can obtain the same area by first calculating the indefinite integral $F(c)=\\int_0^c \\!f(x)\\,dx$,\nthen using $A(a,b) = F(x)\\big\\vert_a^b \\equiv F(b) - F(a)$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> F = integrate(x**3, x)\n>>> F.subs({x:1}) - F.subs({x:0})   \n1/4\n\\end{verbatimtab}\n\\normalsize\nIntegrals correspond to \\emph{signed} area calculations:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> integrate(sin(x), (x,0,pi))\n2\n>>> integrate(sin(x), (x,pi,2*pi))\n-2\n>>> integrate(sin(x), (x,0,2*pi))\n0\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nDuring the first half of its $2\\pi$-cycle,\nthe graph of $\\sin(x)$ is above the $x$-axis, so it has a positive contribution to the area under the curve.\nDuring the second half of its cycle (from $x=\\pi$ to $x=2\\pi$),\n$\\sin(x)$ is below the $x$-axis, so it contributes negative area.\nDraw a graph of $\\sin(x)$ to see what is going on. \n\n\\subsection{Fundamental theorem of calculus}\n\\label{calculus:fundamental_theorem_of_calculus}\n\nThe integral is the ``inverse operation'' of the derivative.\nIf you perform the integral operation followed by the derivative operation on some function, \nyou'll obtain the same function:\n\\[\n  \\left(\\frac{d}{dx} \\circ \\int dx \\right) f(x) \\equiv \\frac{d}{dx} \\int_c^x f(u)\\:du = f(x).\n\\]\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> f = x**2\n>>> F = integrate(f, x)\n>>> F\nx**3/3           # + C\n>>> diff(F,x)\nx**2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nAlternately, if you compute the derivative of a function followed by the integral,\nyou will obtain the original function $f(x)$ (up to a constant):\n\\[\n  \\left( \\int dx \\circ \\frac{d}{dx}\\right) f(x) \\equiv \\int_c^x f'(u)\\;du = f(x) + C.\n\\]\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> f = x**2\n>>> df = diff(f,x)\n>>> df\n2*x\n>>> integrate(df, x)\nx**2    # + C\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe fundamental theorem of calculus is important because it tells us how to solve differential equations.\nIf we have to solve for $f(x)$ in the differential equation $\\frac{d}{dx}f(x) = g(x)$,\nwe can take the integral on both sides of the equation to obtain the answer $f(x) = \\int g(x)\\,dx + C$.\n\n\\subsection{Sequences}\n\\label{calculus:sequences}\n\nSequences are functions that take whole numbers as inputs.\nInstead of continuous inputs $x\\in \\mathbb{R}$,\nsequences take natural numbers $n\\in\\mathbb{N}$ as inputs.\nWe denote sequences as $a_n$ instead of the usual function notation $a(n)$.\n\nWe define a sequence by specifying an expression for its $n$\\textsuperscript{th} term:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> a_n = 1/n\n>>> b_n = 1/factorial(n)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nSubstitute the desired value of $n$ to see the value of the $n$\\textsuperscript{th} term:\n\n\\small\n\\begin{verbatimtab}\n>>> a_n.subs({n:5})\n1/5\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\n%We can use \nThe \\texttt{Python} list comprehension syntax \\texttt{[item for item in list]}\ncan be used to print the sequence values for some range of indices:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> [ a_n.subs({n:i}) for i in range(0,8) ]\n[oo, 1, 1/2, 1/3, 1/4,  1/5,   1/6,   1/7]  \n>>> [ b_n.subs({n:i}) for i in range(0,8) ]\n[1,  1, 1/2, 1/6, 1/24, 1/120, 1/720, 1/5040]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nObserve that $a_n$ is not properly defined for $n=0$ since $\\frac{1}{0}$ is a division-by-zero error.\nTo be precise, we should say $a_n$'s domain is the positive naturals $a_n:\\mathbb{N}^+ \\to \\mathbb{R}$.\nObserve how quickly the \\texttt{factorial} function $n!=1\\cdot2\\cdot3\\cdots(n-1)\\cdot n$ grows:\n$7!= 5040$, $10!=3628800$, $20! > 10^{18}$.\n\n\n\nWe're often interested in calculating the limits of sequences as $n\\to \\infty$.\nWhat happens to the terms in the sequence when $n$ becomes large?\n\n\\small\n\\begin{verbatimtab}\n>>> limit(a_n, n, oo)\n0\n>>> limit(b_n, n, oo)\n0\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nBoth $a_n=\\frac{1}{n}$ and $b_n = \\frac{1}{n!}$ \\emph{converge} to $0$ as $n\\to\\infty$. \n\n\\medskip\n\nMany important math quantities are defined as limit expressions.\nAn interesting example to consider is the number $\\pi$, \nwhich is defined as the area of a circle of radius $1$.\nWe can approximate the area of the unit circle by drawing a many-sided regular polygon around the circle.\nSplitting the $n$-sided regular polygon into identical triangular splices,\nwe can obtain a formula for its area $A_n$\\ifthenelse{\\boolean{TUTORIAL}}{}{ (see solution to \\textbf{P\\ref{mathprob:octagon-approx-to-circle}})}.\nIn the limit as $n\\to \\infty$, \nthe $n$-sided-polygon approximation to the area of the unit-circle becomes exact:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> A_n = n*tan(2*pi/(2*n))\n>>> limit(A_n, n, oo)\npi\n\\end{verbatimtab}\n\\normalsize\n\\subsection{Series}\n\\label{calculus:series}\n\nSuppose we're given a sequence $a_n$ and we want to compute the sum of all the values in this sequence $\\sum_{n}^\\infty a_n$.\nSeries are sums of sequences.\nSumming the values of a sequence $a_n:\\mathbb{N}\\to \\mathbb{R}$\nis analogous to taking the integral of a function $f:\\mathbb{R}\\to \\mathbb{R}$.\n\nTo work with series in \\texttt{SymPy},\nuse the \\texttt{summation} function whose syntax is analogous to the \\texttt{integrate} function: \n\n\\small\n\\begin{verbatimtab}\n>>> a_n = 1/n\n>>> b_n = 1/factorial(n)\n>>> summation(a_n, [n, 1, oo])\noo\n>>> summation(b_n, [n, 0, oo])\nE\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWe say the series $\\sum a_n$ \\emph{diverges} to infinity (or \\emph{is divergent}) while the series $\\sum b_n$ converges (or \\emph{is convergent}).\nAs we sum together more and more terms of the sequence $b_n$, the total becomes closer and closer to some finite number.\nIn this case, the infinite sum $\\sum_{n=0}^\\infty \\frac{1}{n!}$ converges to the number $e=2.71828\\ldots$.\n\n\nThe \\texttt{summation} command is useful because it allows us to compute \\emph{infinite} sums,\nbut for most practical applications we don't need to take an infinite number of terms in a series to obtain a good approximation. \nThis is why series are so neat: they represent a great way to obtain approximations.\n\nUsing standard \\texttt{Python} commands,  \nwe can obtain an approximation to $e$ that is accurate to six decimals by summing 10 terms in the series: \n\n\\small\n\\begin{verbatimtab}\n>>> import math\n>>> def b_nf(n): \n        return 1.0/math.factorial(n)\n>>> sum( [b_nf(n) for n in range(0,10)] )\n2.718281 52557319\n>>> E.evalf()\n2.718281 82845905       # true value\n\\end{verbatimtab}\n\\normalsize\n\\subsection{Taylor series}\n\\label{calculus:taylor_series}\n\nWait, there's more! \nNot only can we use series to approximate numbers,\nwe can also use them to approximate functions.\n\nA \\emph{power series} is a series whose terms contain different powers of the variable $x$.\nThe $n$\\textsuperscript{th} term in a power series is a function of both the sequence index $n$ and the input variable $x$.\n\nFor example, the power series of the function $\\exp(x)=e^x$ is \n\\[\n \\exp(x) \\equiv  1 + x + \\frac{x^2}{2} + \\frac{x^3}{3!} + \\frac{x^4}{4!} + \\frac{x^5}{5!} + \\cdots         \n  =       \\sum_{n=0}^\\infty \\frac{x^n}{n!}.\n\\]\nThis is, IMHO, one of the most important ideas in calculus:\nyou can compute the value of $\\exp(5)$ by taking the infinite sum of the terms in the power series with $x=5$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> exp_xn = x**n/factorial(n)\n>>> summation( exp_xn.subs({x:5}), [n, 0, oo] ).evalf()\n148.413159102577\n>>> exp(5).evalf()\n148.413159102577        # the true value\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote that \\texttt{SymPy} is actually smart enough to recognize that the infinite series\nyou're computing corresponds to the closed-form expression $e^5$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> summation( exp_xn.subs({x:5}), [n, 0, oo])\nexp(5)\n\\end{verbatimtab}\n\\normalsize\nTaking as few as 35 terms in the series is sufficient to obtain an approximation to $e$\nthat is accurate to $16$ decimals:\n%so series are not some abstract thing for mathematicians but a practical trick you can when you code:\n\n\\small\n\\begin{verbatimtab}\n>>> import math                    # redo using only python \n>>> def exp_xnf(x,n): \n        return x**n/math.factorial(n)\n>>> sum( [exp_xnf(5.0,i) for i in range(0,35)] )\n148.413159102577\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe coefficients in the power series of a function (also known as the \\emph{Taylor series}) % or \\emph{Maclaurin series}) \ndepend on the value of the higher derivatives of the function. \nThe formula for the $n$\\textsuperscript{th} term in the Taylor series of $f(x)$ expanded at $x=c$ is $a_n(x) = \\frac{f^{(n)}(c)}{n!}(x-c)^n$,\nwhere $f^{(n)}(c)$ is the value of the $n$\\textsuperscript{th} derivative of $f(x)$ evaluated at $x=c$.\n%The term \\emph{Taylor series} applies to all series expansions of functions.\nThe term \\emph{Maclaurin series} refers to Taylor series expansions at $x=0$.\n\nThe \\texttt{SymPy} function \\texttt{series} is a convenient way to obtain the series of any function.\nCalling \\texttt{series(expr,var,at,nmax)} \nwill show you the series expansion of \\texttt{expr} \nnear \\texttt{var}=\\texttt{at} \nup to power \\texttt{nmax}:\n\n\\small\n\\begin{verbatimtab}\n>>> series( sin(x), x, 0, 8)\nx - x**3/6 + x**5/120 - x**7/5040 + O(x**8)\n>>> series( cos(x), x, 0, 8)\n1 - x**2/2 + x**4/24 - x**6/720 + O(x**8)\n>>> series( sinh(x), x, 0, 8)\nx + x**3/6 + x**5/120 + x**7/5040 + O(x**8)\n>>> series( cosh(x), x, 0, 8)\n1 + x**2/2 + x**4/24 + x**6/720 + O(x**8)\n\\end{verbatimtab}\n\\normalsize\n\n%Note the power series of $\\sin$ and $\\sinh$ contain only odd powers of $x$\n%while the power series of $\\cos$ and $\\cosh$ contain only even powers.\n\n\\noindent\nSome functions are not defined at $x=0$, so we expand them at a different value of $x$.\nFor example, the power series of $\\ln(x)$ expanded at $x=1$ is\n\n\\small\n\\begin{verbatimtab}\n>>> series(ln(x), x, 1, 6)     # Taylor series of ln(x) at x=1\nx - x**2/2 + x**3/3 - x**4/4 + x**5/5  + O(x**6)    \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nHere, the result \\texttt{SymPy} returns is misleading.\nThe Taylor series of $\\ln(x)$ expanded at $x=1$ has terms of the form $(x-1)^n$:\n\\[\n  \\ln(x) = (x-1) - \\frac{(x-1)^2}{2} + \\frac{(x-1)^3}{3} - \\frac{(x-1)^4}{4} + \\frac{(x-1)^5}{5} + \\cdots.\n\\]\nVerify this is the correct formula by substituting $x=1$.\n\\texttt{SymPy} returns an answer in terms of coordinates \\emph{relative} to $x=1$.\n%That's okay, \n%because when dealing with series in general we're mostly interested in the coefficients.\n\nInstead of expanding $\\ln(x)$ around $x=1$,\nwe can obtain an equivalent expression if we expand $\\ln(x+1)$ around $x=0$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> series(ln(x+1), x, 0, 6)   # Maclaurin series of ln(x+1)\nx - x**2/2 + x**3/3 - x**4/4 + x**5/5 + O(x**6)\n\\end{verbatimtab}\n\\normalsize\n\n\n\n\n%=======================================================================  vectors\n\\lesection{Vectors}\n\\label{sec:sympytut_vectors}\n\nA vector $\\vec{v} \\in \\mathbb{R}^n$ is an $n$-tuple of real numbers. \nFor example, consider a vector that has three components:  \n\\[\n \\vec{v} = (v_1,v_2,v_3) \\  \\in \\  (\\mathbb{R},\\mathbb{R},\\mathbb{R}) \\equiv \\mathbb{R}^3.\n\\]\nTo specify the vector $\\vec{v}$, \nwe specify the values for its three components $v_1$, $v_2$, and $v_3$. \n\nA matrix $A \\in \\mathbb{R}^{m\\times n}$ is a rectangular array of real numbers with $m$ rows and $n$ columns.\nA vector is a special type of matrix; we can think of a vector $\\vec{v}\\in \\mathbb{R}^n$\neither as a row vector ($1\\times n$ matrix) or a column vector ($n \\times 1$ matrix).\nBecause of this equivalence between vectors and matrices,\nthere is no need for a special vector object in \\texttt{SymPy}, \nand \\texttt{Matrix} objects are used for vectors as well.\n\nThis is how we define vectors %in \\texttt{SymPy} \nand compute their properties:\n\n\\small\n\\begin{verbatimtab}\n>>> u = Matrix([[4,5,6]]) # a row vector = 1x3 matrix\n>>> v = Matrix([[7],\n                [8],      # a col vector = 3x1 matrix \n                [9]])\n>>> v.T                   # use the transpose operation to \nMatrix([[7, 8, 9]])       # convert a col vec to a row vec\n\n>>> u[0]                  # 0-based indexing for entries \n4\n>>> u.norm()              # length of u \nsqrt(77)\n>>> uhat = u/u.norm()     # unit-length vec in same dir as u\n>>> uhat\n[4/sqrt(77), 5/sqrt(77), 6/sqrt(77)]\n>>> uhat.norm()\n1\n\\end{verbatimtab}\n\\normalsize\n\n\n\n\n\\subsection{Dot product}\n\\label{vectors:dot_product}\n\nThe dot product of the $3$-vectors $\\vec{u}$ and $\\vec{v}$ can be defined two ways:\n\\[\n  \\vec{u}\\cdot\\vec{v}\n  \t\\equiv \n\t\\underbrace{u_xv_x+u_yv_y+u_zv_z}_{\\textrm{algebraic def.}} \n\t\\equiv \n\t\\underbrace{\\|\\vec{u}\\|\\|\\vec{v}\\|\\cos(\\varphi)}_{\\textrm{geometric def.}} \n\t\\quad \\in \\mathbb{R},\n\\]\nwhere $\\varphi$ is the angle between the vectors $\\vec{u}$ and $\\vec{v}$.\nIn \\texttt{SymPy},\n\n\\small\n\\begin{verbatimtab}\n>>> u = Matrix([ 4,5,6])\n>>> v = Matrix([-1,1,2])\n>>> u.dot(v)\n13\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nWe can combine the algebraic and geometric formulas for the dot product\nto obtain the cosine of the angle between the vectors \n\\[\n    \\cos(\\varphi)\n        = \\frac{ \\vec{u}\\cdot\\vec{v} }{  \\|\\vec{u}\\|\\|\\vec{v}\\| }\n        = \\frac{ u_xv_x+u_yv_y+u_zv_z  }{  \\|\\vec{u}\\|\\|\\vec{v}\\| },\n\\]\nand use the \\texttt{acos} function to find the angle measure:\n\n\\small\n\\begin{verbatimtab}\n>>> acos(u.dot(v)/(u.norm()*v.norm())).evalf()\n0.921263115666387      # in radians  =  52.76 degrees\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nJust by looking at the coordinates of the vectors $\\vec{u}$ and $\\vec{v}$,\nit's difficult to determine their relative direction. \nThanks to the dot product, however,\nwe know the angle between the vectors is $52.76^\\circ$,\nwhich means they \\emph{kind of} point in the same direction.\nVectors that are at an angle $\\varphi=90^\\circ$ are called \\emph{orthogonal}, meaning at right angles with each other.\nThe dot product of vectors for which $\\varphi > 90^\\circ$ is negative because they point \\emph{mostly} in opposite directions.\n\nThe notion of the ``angle between vectors'' applies more generally to vectors with any number of dimensions.\nThe dot product for $n$-dimensional vectors is $\\vec{u}\\cdot\\vec{v}=\\sum_{i=1}^n u_iv_i$.\nThis means we can talk about ``the angle between'' 1000-dimensional vectors.\nThat's pretty crazy if you think about it---there is no way we could possibly ``visualize'' 1000-dimensional vectors,\nyet given two such vectors we can tell if they point mostly in the same direction,\nin perpendicular directions, or mostly in opposite directions. \n\nThe dot product is a commutative operation $\\vec{u}\\cdot\\vec{v} = \\vec{v}\\cdot\\vec{u}$:\n\n\n\n\\small\n\\begin{verbatimtab}\n>>> u.dot(v) == v.dot(u)\nTrue\n\\end{verbatimtab}\n\\normalsize\n\n\n\\ifthenelse{\\boolean{FORLA}}{\n\t\\input{99.vectors_projectsions_FORLA.tex}\n}{}\n\n\n\n\\subsection{Cross product}\n\\label{vectors:cross_product}\n\nThe \\emph{cross product}, denoted $\\times$, takes two vectors as inputs and produces a vector as output.\nThe cross products of individual basis elements are defined as follows:\n\\[\n \\hat{\\imath}\\times\\hat{\\jmath} =\\hat{k}, \\qquad\n \\hat{\\jmath}\\times\\hat{k} =\\hat{\\imath}, \\qquad\n \\hat{k}\\times \\hat{\\imath}= \\hat{\\jmath}.\n\\]\n\n\\noindent\nHere is how to compute the cross product of two vectors in \\texttt{SymPy}:\n\\small\n\\begin{verbatimtab}\n>>> u = Matrix([ 4,5,6])\n>>> v = Matrix([-1,1,2])\n>>> u.cross(v)\n[4, -14, 9]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe vector $\\vec{u}\\times \\vec{v}$ is orthogonal to both $\\vec{u}$ and $\\vec{v}$.\nThe norm of the cross product  $\\|\\vec{u}\\times \\vec{v}\\|$ is proportional to the lengths of the vectors \nand the sine of the angle between them:\n\\small\n\\begin{verbatimtab}\n(u.cross(v).norm()/(u.norm()*v.norm())).n()\n0.796366206088088    # = sin(0.921..) \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe name ``cross product'' is well-suited for this operation\nsince it is calculated by ``cross-multiplying'' the coefficients of the vectors:\n\\[\n   \\vec{u}\\times\\vec{v}=\n   \\left( \n     u_yv_z-u_zv_y, \\ u_zv_x-u_xv_z, \\ u_xv_y-u_yv_x \n    \\right).\n\\]\n\n\\noindent\nBy defining individual symbols for the entries of two vectors,\nwe can make \\texttt{SymPy} show us the cross-product formula:\n\\small\n\\begin{verbatimtab}\n>>> u1,u2,u3 = symbols('u1:4')\n>>> v1,v2,v3 = symbols('v1:4')\n>>> Matrix([u1,u2,u3]).cross(Matrix([v1,v2,v3]))\n[ (u2*v3 - u3*v2), (-u1*v3 + u3*v1), (u1*v2 - u2*v1) ]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe dot product is anti-commutative $\\vec{u}\\times\\vec{v} = -\\vec{v}\\times\\vec{u}$:\n\\small\n\\begin{verbatimtab}\n>>> u.cross(v)\n[4, -14, 9]\n>>> v.cross(u)\n[-4, 14,-9]\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe product of two numbers and the dot product of two vectors are commutative operations.\nThe cross product, however, is not commutative: $\\vec{u}\\times\\vec{v} \\neq \\vec{v}\\times\\vec{u}$.\n\n\n\n\n%=======================================================================  mechanics\n\\lesection{Mechanics}\n\\label{sec:sympytut_mechanics}\n\nThe module called \\href{http://pyvideo.org/video/2653/dynamics-and-control-with-python}{\\texttt{sympy.physics.mechanics}} \ncontains elaborate tools for describing mechanical systems,\nmanipulating reference frames, forces, and torques.\nThese specialized functions are not necessary for a first-year mechanics course.\nThe basic \\texttt{SymPy} functions like \\texttt{solve},\nand the vector operations you learned in the previous sections are powerful enough for basic Newtonian mechanics.\n%Let's look into this.\n\n\\subsection{Dynamics}\n\\label{mechanics:dynamics}\n\nThe net force acting on an object is the sum of all the external forces acting on it $\\vec{F}_{\\textrm{net}} = \\sum \\vec{F}$.\nSince forces are vectors, \nwe need to use vector addition to compute the net force.\n\nCompute %the net force \n$\\vec{F}_{\\textrm{net}}=\\vec{F}_1 + \\vec{F}_2$,\nwhere $\\vec{F}_1=4\\hat{\\imath}$[N] and $\\vec{F}_2 = 5\\angle 30^\\circ$[N]:\n\\small\n\\begin{verbatimtab}\n>>> F_1 =  Matrix( [4,0] ) \n>>> F_2 =  Matrix( [5*cos(30*pi/180), 5*sin(30*pi/180) ] )\n>>> F_net = F_1 + F_2\n>>> F_net \n[4 + 5*sqrt(3)/2,   5/2]          # in Newtons \n>>> F_net.evalf()\n[8.33012701892219,  2.5]          # in Newtons \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nTo express the answer in length-and-direction notation,\nuse \\texttt{norm} to find the length of $\\vec{F}_{\\textrm{net}}$\nand \\texttt{atan2}\\footnote{The function \\texttt{atan2(y,x)} computes the correct direction \nfor all vectors $(x,y)$, unlike \\texttt{atan(y/x)} which requires corrections for angles in the range $[\\frac{\\pi}{2}, \\frac{3\\pi}{2}]$.}\nto find its direction:\n\\small\n\\begin{verbatimtab}\n>>> F_net.norm().evalf()\n8.69718438067042                  # |F_net| in [N] \n>>> (atan2( F_net[1],F_net[0] )*180/pi).n()\n16.7053138060100                  # angle in degrees\n\\end{verbatimtab}\n\\normalsize\nThe net force on the object is $\\vec{F}_{\\textrm{net}}= 8.697\\angle 16.7^\\circ$[N].\n\n\n\\subsection{Kinematics}\n\\label{mechanics:kinematics}\n\nLet $x(t)$ denote the position of an object,\n$v(t)$ denote its velocity,\nand $a(t)$ denote its acceleration.\nTogether $x(t)$, $v(t)$, and $a(t)$ are known as the \\emph{equations of motion} of the object.\n\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\n\t\n\tThe equations of motion are related by the derivative operation:\n\t\\[\n\t  a(t) \\overset{\\frac{d}{dt} }{\\longleftarrow} v(t) \\overset{\\frac{d}{dt} }{\\longleftarrow} x(t).\n\t\\]\n\tAssume we know the initial position $x_i\\equiv x(0)$ and the initial velocity $v_i\\equiv v(0)$ of the object \n\tand we want to find $x(t)$ for all later times.\n\tWe can do this starting from the dynamics of the problem---the forces acting on the object.\n\n\tNewton's second law $\\vec{F}_{\\textrm{net}} = m\\vec{a}$ states that a net force $\\vec{F}_{\\textrm{net}}$\n\tapplied on an object of mass $m$ produces acceleration $\\vec{a}$.\n\tThus, we can obtain an objects acceleration if we know the net force acting on it.\n\tStarting from the knowledge of $a(t)$, we can obtain $v(t)$ by integrating\n\tthen find $x(t)$ by integrating $v(t)$:\n\t\\[\n\ta(t) \\ \\ \\ \\overset{v_i+ \\int\\!dt }{\\longrightarrow} \\ \\ \\ v(t) \\ \\ \\ \\overset{x_i+ \\int\\!dt }{\\longrightarrow} \\ \\ \\ x(t).\n\t\\]\n\tThe reasoning follows from the fundamental theorem of calculus:\n\tif $a(t)$ represents the change in $v(t)$, \n\tthen the total of $a(t)$ accumulated between $t=t_1$ and $t=t_2$\n\tis equal to the total change in $v(t)$ between these times: $\\Delta v = v(t_2) - v(t_1)$.\n\tSimilarly, the integral of $v(t)$ from $t=0$ until $t=\\tau$ is equal to $x(\\tau) - x(0)$.\n\n}{\n\n\tStarting from the knowledge of $\\vec{F}_{\\textrm{net}}$,\n\twe can compute $a(t)=\\frac{ \\vec{F}_{\\textrm{net}} }{ m }$, \n\tthen obtain $v(t)$ by integrating $a(t)$, and finally obtain $x(t)$ by integrating $v(t)$:\n\t\\[\n\t\\underbrace{\\frac{ \\vec{F}_{\\textrm{net}} }{ m }  = a(t)}_{\\textrm{Newton's 2\\textsuperscript{nd} law}} \n\t\\underbrace{ \\overset{v_i+ \\int\\!dt }{\\longrightarrow} \\ \\ \\ v(t) \\ \\ \\ \\overset{x_i+ \\int\\!dt }{\\longrightarrow} \\ \\ \\ x(t).}_{\\textrm{kinematics}}\n\t\\]\n\n}\n\n\n\\subsection{Uniform acceleration motion (UAM)}\n\\label{mechanics:UAM}\n\nLet's analyze the case where the net force on the object is constant.\nA constant force causes a constant acceleration $a = \\frac{F}{m} = \\textrm{constant}$.\nIf the acceleration function is constant over time $a(t)=a$.\nWe find $v(t)$ and $x(t)$ as follows:\n\\small\n\\begin{verbatimtab}\n>>> t, a, v_i, x_i = symbols('t v_i x_i a')\n>>> v = v_i + integrate(a, (t, 0,t) )\n>>> v\na*t + v_i\n>>> x = x_i + integrate(v, (t, 0,t) )\n>>> x\na*t**2/2 + v_i*t + x_i\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nYou may remember these equations from \n\\ifthenelse{\\boolean{TUTORIAL}}{your high school physics class.}{Section~\\ref{sec:kinematics_with_calculus} (page~\\pageref{sec:kinematics_with_calculus}).}\nThey are the \\emph{uniform accelerated motion} (UAM) equations:\n\\begin{align*}\n a(t) &= a,                                  \\\\ \n v(t) &= v_i  + at,                          \\\\[-2mm] \n x(t) &= x_i + v_it + \\frac{1}{2}at^2.\n\\end{align*}\nIn high school, you probably had to memorize these equations.\nNow you know how to derive them yourself starting from first principles.\n\nFor the sake of completeness, we'll now derive the fourth UAM equation,\nwhich relates the object's final velocity to the initial velocity,\nthe displacement, and the acceleration, without reference to time:\n\\small\n\\begin{verbatimtab}\n>>> (v*v).expand()\na**2*t**2 + 2*a*t*v_i + v_i**2\n>>> ((v*v).expand() - 2*a*x).simplify()\n-2*a*x_i + v_i**2\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe above calculation shows $v_f^2 - 2ax_f = -2ax_i + v_i^2$.\nAfter moving the term $2ax_f$ to the other side of the equation, we obtain\n\\begin{align*}\n (v(t))^2 \\ = \\ v_f^2 =  v_i^2  + 2a\\Delta x \\ = \\  v_i^2  + 2a(x_f-x_i).\n\\end{align*}  \nThe fourth equation is important for practical purposes\nbecause it allows us to solve physics problems in a time-less manner. %COMMENT: a timeless manner? %TODO: explain \"without using the time variable\" \n%It's also important for theoretical purposes\n%since it resembles an \\emph{energy calculation}.\n%Indeed, if you multiply the fourth equation by $\\frac{1}{2}m$,\n%you'll obtain conservation of energy equation: $K_f = K_i + mg\\Delta h$.\n\n\n\\subsubsection{Example}\n\nFind the position function of an object at time $t =3$[s], \nif it starts from $x_i=20$[m] with $v_i=10$[m/s] and undergoes \na constant acceleration of $a=5$[m/s$^2$].\nWhat is the object's velocity at $t=3$[s]?\n\n\\small\n\\begin{verbatimtab}\n>>> x_i = 20   # initial position\n>>> v_i = 10   # initial velocity\n>>> a   = 5    # acceleration (constant during motion)\n>>> x = x_i + integrate(  v_i+integrate(a,(t,0,t)),  (t,0,t) )   \n>>> x\n5*t**2/2 + 10*t + 20\n>>> x.subs({t:3}).n()           # x(3) in [m]\n72.5           \n>>> diff(x,t).subs({t:3}).n()   # v(3) in [m/s]\n25                              # = sqrt( v_i**2 + 2*a*52.5 )\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIf you think about it,\nphysics knowledge combined with computer skills is like a superpower!\n\n\n\\subsection{General equations of motion}\n\\label{mechanics:general_eqns_of_motion}\n\nThe procedure \n$a(t) \\ \\overset{v_i+ \\int\\!dt }{\\longrightarrow} \\ v(t) \\ \\overset{x_i+ \\int\\!dt }{\\longrightarrow} \\ x(t)$\ncan be used to obtain the position function $x(t)$ even when the acceleration is not constant.\nSuppose the acceleration of an object is $a(t)=\\sqrt{k t}$; \nwhat is its $x(t)$?\n%then its %velocity and its \n%position function is:\n\n\\small\n\\begin{verbatimtab}\n>>> t, v_i, x_i, k = symbols('t v_i x_i k')\n>>> a = sqrt(k*t)\n>>> x = x_i + integrate( v_i+integrate(a,(t,0,t)), (t, 0,t) )\n>>> x\nx_i + v_i*t + (4/15)*(k*t)**(5/2)/k**2 \n\\end{verbatimtab}\n\\normalsize\n\n%>>> v = v_i + integrate(a, (t, 0,t) )\n%>>> v\n%v_i + 2*(k*t)**(3/2)/(3*k)\n\n\n\n\n\\subsection{Potential energy}\n\\label{mechanics:potential_energy}\n\n\\ifthenelse{\\boolean{TUTORIAL}}{\nInstead of working with the kinematic equations of motion $x(t)$, $v(t)$, and $a(t)$ which depend on time,\nwe can solve physics problems using \\emph{energy} calculations.\nA key connection between the world of forces and the world of energy is the concept of \\emph{potential energy}.\nIf you move an object against a conservative force (think raising a ball in the air against the force of gravity),\nyou can think of the work you do agains the force as being stored in the potential energy of the object.\n}{}\n\nFor each force $\\vec{F}(x)$ there is a corresponding potential energy $U_F(x)$.\nThe change in potential energy associated with the force $\\vec{F}(x)$ and displacement $\\vec{d}$\nis defined as the negative of the work done by the force during the displacement: $U_F(x) = - W = - \\int_{\\vec{d}} \\vec{F}(x)\\cdot d\\vec{x}$.\n\nThe potential energies associated with gravity $\\vec{F}_g = -mg\\hat{\\jmath}$\nand the force of a spring $\\vec{F}_s = -k\\vec{x}$ are calculated as follows:\n\n\\small\n\\begin{verbatimtab}\n>>> x, y = symbols('x y')\n>>> m, g, k, h = symbols('m g k h')\n>>> F_g = -m*g             # Force of gravity on mass m \n>>> U_g = - integrate( F_g, (y,0,h) )\n>>> U_g\nm*g*h                      # Grav. potential energy \n>>> F_s = -k*x             # Spring force for displacement x \n>>> U_s = - integrate( F_s, (x,0,x) )\n>>> U_s\nk*x**2/2                   # Spring potential energy \n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote the negative sign in the formula defining the potential energy.\nThis negative is canceled by the negative sign of the dot product $\\vec{F}\\cdot d\\vec{x}$:\nwhen the force acts in the direction opposite to the displacement, \nthe work done by the force is negative.\n\n\\subsection{Simple harmonic motion}\n\\label{mechanics:simple_harmonic_motion}\n\n\\small\n\\begin{verbatimtab}\nfrom sympy import Function, dsolve\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nThe force exerted by a spring is given by the formula $F=-kx$.\nIf the only force acting on a mass $m$ is the force of a spring,\nwe can use Newton's second law to obtain the following equation:\n\\[\n  F=ma  \n  \\quad \\Rightarrow \\quad\n  -kx = ma   \n  \\quad \\Rightarrow \\quad\n  -kx(t) = m\\frac{d^2}{dt^2}\\Big[x(t)\\Big].\n\\]\nThe motion of a mass-spring system is described by the \\emph{differential equation} $\\frac{d^2}{dt^2}x(t) + \\omega^2 x(t)=0$,\nwhere the constant $\\omega = \\sqrt{\\frac{k}{m}}$ is called the angular frequency.\nWe can find the position function $x(t)$ using the \\texttt{dsolve} method:\n\n\\small\n\\begin{verbatimtab}\n>>> t = Symbol('t')                   # time            t\n>>> x = Function('x')                 # position function x(t)\n>>> w = Symbol('w', positive=True)    # angular frequency w\n>>> sol = dsolve( diff(x(t),t,t) + w**2*x(t), x(t) )\n>>> sol\nx(t) == C1*sin(w*t) + C2*cos(w*t)  \n>>> x = sol.rhs           \n>>> x \nC1*sin(w*t) + C2*cos(w*t)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nNote the solution $x(t)=C_1\\sin(\\omega t)+C_2 \\cos(\\omega t)$ is equivalent to $x(t) = A\\cos(\\omega t + \\phi)$, \nwhich is more commonly used to describe simple harmonic motion. \nWe can use the \\texttt{expand} function with the argument \\texttt{trig=True} to convince ourselves of this equivalence:\n\n\\small\n\\begin{verbatimtab}\n>>> A, phi = symbols(\"A phi\")\n>>> (A*cos(w*t - phi)).expand(trig=True)\nA*sin(phi)*sin(w*t) + A*cos(phi)*cos(w*t)\n\\end{verbatimtab}\n\\normalsize\n\n\\noindent\nIf we define $C_1=A\\sin(\\phi)$ and $C_2=A\\cos(\\phi)$, \nwe obtain the form $x(t)=C_1\\sin(\\omega t)+C_2 \\cos(\\omega t)$ that \\texttt{SymPy} found.\n\n\n\\subsubsection{Conservation of energy}\n\nWe can verify that the total energy of the mass-spring system is conserved by showing \n$E_T(t) = U_s(t) + K(t) = \\textrm{constant}$: \n\n\\small\n\\begin{verbatimtab}\n>>> x = sol.rhs.subs({\"C1\":0,\"C2\":A}) \n>>> x\nA*cos(t*w)\n>>> v = diff(x, t)\n-A*w*sin(t*w)\n>>> E_T = (0.5*k*x**2 + 0.5*m*v**2).simplify()\n>>> E_T\n0.5*A**2*(k*cos(w*t)**2 + m*w**2*sin(w*t)**2)\n>>> E_T.subs({k:m*w**2}).simplify()\n0.5*m*(w*A)**2                            # = K_max\n>>> E_T.subs({w:sqrt(k/m)}).simplify()\n0.5*k*A**2                                # = U_max \n\\end{verbatimtab}\n\\normalsize\n\n\n\n\\ifthenelse{\\boolean{TUTORIAL}}{}{\n\n\\printcp\n\\vspace{-2mm}\n\n%=======================================================================  conclusion\n\\section*{Conclusion}\n\\label{sec:sympytut_conclusion}\n\n\tI'll conclude with some words of caution about computer overuse.\n\tComputer technology is very powerful and is everywhere around us,\n\tbut we must not forget that computers are actually very dumb.\n\tComputers are merely calculators, and they depend on your knowledge to direct them.\n\tIt's important you learn how to perform complicated math by hand in order to be able to \n\tinstruct computers to execute math for you, and so you can check the results of your computer calculations.\n\tI don't want you to use the tricks you learned in this tutorial to avoid math problems\n\tand blindly rely on \\texttt{SymPy} for all your math needs. That won't work!\n\tThe idea is for both you and the computer to be math powerhouses.\n\t%The computer will help you with tedious calculations (they're good at that)\n\t%and you'll help the computer by guiding it when it gets  stuck (humans are good at that).\n\t\n\tMost math discoveries were made using pen and paper.\n\tWhen solving a math problem, if you clearly define each variable,\n\tdraw a diagram, and clearly set up the problem's equations in terms of the variables you defined,\n\tthen half the work of solving the problem is done.\n\t%\n\tComputers can't help with these important, initial modelling and problem-specific tasks---only humans are good at this stuff.\n\t%\tThe British like to call this ``wrapping one's head around the problem.''\n\tOnce you \\emph{set up} the problem, \n\t\\texttt{SymPy} can help you breeze through tedious calculations.\n\t%\n\tThe combination of pen and paper for thinking and \\texttt{SymPy} for calculating is indeed quite powerful.\n\tGo out there and do some science!\n\t\n\t% ---- using sympy shoulders of giants, but understanding the equations  makes you a math giant!\n\t\n\n%=======================================================================  links\n\\section*{Links}\n\\label{sec:sympytut_links}\n\n[ Installation instructions for \\texttt{ipython notebook} ] \\\\ \n\\href{http://ipython.org/install.html}{\\texttt{http://ipython.org/install.html}}\n\n\\medskip\n\\noindent\n[ The official \\texttt{SymPy} tutorial ] \\\\ \n\\href{http://docs.sympy.org/latest/tutorial/intro.html}{\\texttt{http://docs.sympy.org/latest/tutorial/intro.html}}\n\n\\medskip\n\\noindent\n[ A list of \\texttt{SymPy} gotchas ] \\\\ \n\\href{http://docs.sympy.org/dev/gotchas.html}{\\texttt{http://docs.sympy.org/dev/gotchas.html}}\n\n\n\n}\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "3a798ebd8257e8b27c6862250638ff0f1e8aa71a", "size": 69216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/99.sympy_tutorial.tex", "max_stars_repo_name": "minireference/sympytut_notebooks", "max_stars_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-08-29T12:04:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-23T05:14:52.000Z", "max_issues_repo_path": "tex/99.sympy_tutorial.tex", "max_issues_repo_name": "minireference/sympytut_notebooks", "max_issues_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "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/99.sympy_tutorial.tex", "max_forks_repo_name": "minireference/sympytut_notebooks", "max_forks_repo_head_hexsha": "6669e7bfccef9e70ae029ac5cbb54cb6cbc31652", "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.634369287, "max_line_length": 169, "alphanum_fraction": 0.6827178687, "num_tokens": 21626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6298355281453912}}
{"text": "\\chapter{Lattice Systems}\n\n\\section{Lattice Spins}\n\n\\subsection{The Ising Model}\nThe Ising model on the Euclidean space is described by the action\n\\begin{equation}\n\tS[\\{s_k\\}] = -K \\sum_{\\langle ij\\rangle} s_i s_j,\\quad s_k = \\pm 1.\n\\end{equation}\nwhere $\\langle ij \\rangle$ is the nearest-neighbor sites and the coupling is\n\\begin{equation}\n\tK = \\beta J = \\frac{J}{T}.\n\\end{equation}\nThe phase of the Ising model can be revealed by considering the correlation function:\n\\begin{equation}\n\tG_{ij} \\equiv \\langle \\sigma_i^z \\sigma_j^z\\rangle\n\t= \\frac{1}{Z} \\sum_{\\{s_k\\}} e^{-S[\\{s_k\\}]} s_i s_j,\n\\end{equation}\nwhere the partition function is\n\\begin{equation}\n\tZ = \\sum_{\\{s_k\\}} e^{-S[\\{s_k\\}]}\n\\end{equation}\n\n\n\\subsubsection{Series Expansion}\nThe behavior of correlation in the high- and low- temperature limit can be seen using the series expansion.\nConsider first the high-temperature limit where $K \\rightarrow 0$, the partition function can be expanded in different order of $K$:\n\\begin{equation}\n\\begin{aligned}\n\tZ &= \\sum_{\\{s_k\\}} \\prod_{\\langle ij\\rangle} \\cosh K (1 + s_i s_j \\tanh K) \\\\\n\t&\\sim \\sum_{\\{s_k\\}} \\prod_{\\langle ij\\rangle} (1 + s_i s_j K).\n\\end{aligned}\n\\end{equation}\nThe only terms that survive the averaging form a non-crossing path from site $i$ to site $j$.\nIn the small $K$ limit, the main contribution comes from the shortest path, i.e.,\n\\begin{equation}\n\tG_{ij} \\propto K^{-r_{ij}},\n\\end{equation}\nwhere $r_{ij}$ is the distance (Manhattan metric) from $i$ to $j$.\nWe see in high temperature the correlation is exponentially decaying, indicating a disorder phase.\nNote that for $d=1$ case, there is only one path from $i$ to $j$, and the exact result is\n\\begin{equation}\n\tG_{ij} = \\frac{(2\\cosh K \\tanh K)^{|i-j|}}{(2 \\cosh K)^{|i-j|}}\n\t= \\left(\\tanh K\\right)^{|i-j|},\n\\end{equation}\nindependent of the temperature, so the 1d Ising model has only one phase.\n\nFor $d\\ge 2$ case, in the lower temperature limit, the dominant contribution to the partition function comes from the ferromagnetic configuration.\nThe excitations are the spin domains, whose energy is proportional to their perimeters.\nFor higher dimensional system, the creation of the domain is suppressed, leading to an ordered phase.\n\n\n\n\\section{Lattice Fermions}\nIn this section, we consider the system whose Hamiltonian composed of quadratic fermionic operators, i.e.,\n\\begin{equation}\n\t\\hat H_{\\mathrm{free}} = \\sum_{i,j=1}^N A_{ij} c_i^\\dagger c_j + \\frac{1}{2}\\sum_{i,j=1}^N B_{ij} c_i c_j + \\frac{1}{2}\\sum_{i,j=1}^N B_{ij}^* c_j^\\dagger c_i^\\dagger, \\label{eq:lattice-free-fermion-hamiltonian}\n\\end{equation}\nwhere $A$ is a Hermitian matrix, and matrix $B$ is anti-symmetric.\nWithout loss of generality, in the following we always assume that the sum of chemical potential is zero, i.e., $\\mathrm{Tr} A=0$.\nIn the Nambu basis \n\\begin{equation}\n\t\\Psi = (c_1,\\dots,c_N,c_1^\\dagger,\\dots,c_N^\\dagger)^T,\n\\end{equation}\nthe Hamiltonian has the BdG form:\n\\begin{equation}\n\t\\hat H_{\\mathrm{free}} = \\frac{1}{2} \\sum_{i,j=1}^{2N} \\Psi^\\dagger_i H_{ij}^{\\Psi} \\Psi_j + \\frac{1}{2}\\mathrm{Tr}A,\n\\end{equation}\nwhere the single-body matrix $H^{\\Psi}$ is a $2N\\times 2N$ Hermitian matrix\n\\begin{equation}\n\tH^{\\Psi} = \\left[\\begin{array}{cc} \n\t\tA & B \\\\\n\t\t-B^* & -A^* \n\t\\end{array}\\right].\n\\end{equation}\nNote that in the Nambu basis, the single-body Hamiltonian matrix has the particle-hole symmetry\n\\begin{equation}\n\tP = \\sigma_x \\mathcal K, \n\t\\quad \\Longrightarrow \\quad\n\tP H^{\\Psi} P = -H^{\\Psi}.\n\\end{equation}\nThis means the spectrum of the BdG Hamiltonian is symmetric with respect to zero.\n\n\n\\subsection{Majorana Representation}\n\nThe Majorana operators are defined as:\n\\begin{equation}\n\t\\left[\\begin{array}{c} \\omega_{i} \\\\ \\omega_{i+N} \\end{array}\\right]\n\t= \\left[\\begin{array}{cc} \n\t\t1 & 1 \\\\ \n\t\ti & -i \n\t\\end{array}\\right] \\left[\\begin{array}{c} \n\t\tc_i \\\\ c_i^\\dagger \n\t\\end{array}\\right], \\quad \n\t\\left[\\begin{array}{c} c_i \\\\ c_i^\\dagger \\end{array}\\right]\n\t= \\frac{1}{2} \\left[\\begin{array}{cc} \n\t\t1 & -i \\\\ \n\t\t1 & i \n\t\\end{array}\\right] \\left[\\begin{array}{c} \n\t\t\\omega_{i} \\\\ \\omega_{i+N}\n\t\\end{array}\\right].\n\\end{equation}\nThe Majorana operator satisfies the Fermion-like commutation relation\n\\begin{equation}\n\t\\{\\omega_i, \\omega_j\\} = 2\\delta_{ij}.\n\\end{equation}\nThe fermionic bilinear in the Majorana basis has the form\n\\begin{equation}\n\t\\hat H = -\\frac{i}{4} \\sum_{i,j=1}^{2N} H_{ij} \\omega_i \\omega_j\n\\end{equation}\nwhere the single-body matrix $H$ is a $2N \\times 2N$ real anti-symmetric matrix:\n\\begin{equation}\n\tH = \\left[\\begin{array}{cc} \n\t\t-A^I - B^I & A^R - B^R \\\\\n    \t-A^R - B^R &  -A^I + B^I \n\t\\end{array}\\right].\n\\end{equation}\nwhere we have define $A^{R/I} = \\mathrm{Re} A / \\mathrm{Im} A$ and $B^{R/I} = \\mathrm{Re} B / \\mathrm{Im} B$.\nConversely, if we have a Majorana bilinear \n\\begin{equation}\n\t\\frac{i}{2} \\sum_{i,j=1}^{2N} M_{ij}\\omega_i \\omega_j, \\quad\n\tM = \\left[\\begin{array}{cc}\n\t\tM^{11} & M^{12} \\\\ M^{21} & M^{22}\n\t\\end{array} \\right],\n\\end{equation}\nit can be transformed back to ordinary fermionic bilinear (\\ref{eq:lattice-free-fermion-hamiltonian}) where\n\\begin{equation}\n\\begin{aligned}\n\tA &= M^{21} - M^{12} + i M^{11} + i M^{22}, \\\\\n\tB &= M^{21} + M^{12} + i M^{11} - i M^{22}.\n\t\\label{eq:lattice-majorana-bilinear-to-fermion}\n\\end{aligned}\n\\end{equation}\nA real anti-symmetric matrix can be transformed to standard form by an orthogonal transformation $O$:\n\\begin{equation}\n\\begin{aligned}\n\tH &= O \\cdot \\Sigma(\\bm \\lambda) \\cdot O^T, \\\\\n\t\\Sigma(\\bm \\lambda) &= i\\sigma_y \\otimes \\mathrm{diag}(\\lambda_1,\\cdots,\\lambda_n).\n\\end{aligned}\n\\end{equation}\nMake the basis transformation\n\\begin{equation}\n\t\\gamma_n = \\sum_{j=1}^{2N} O_{jn} \\omega_j,\n\\end{equation}\nthe Hamiltonian becomes the standard form:\n\\begin{equation}\n\\begin{aligned}\n\tH &= -\\frac{i}{4} \\sum_{i=1}^N \\lambda_i (\\gamma_i \\gamma_{i+N}-\\gamma_{i+N} \\gamma_i) \\\\\n\t&= -\\frac{i}{2} \\sum_{i=1}^N \\lambda_i \\gamma_i \\gamma_{i+N}.\n\\end{aligned}\n\\end{equation}\nEach $\\gamma_i \\gamma_{i+N}$ pair can then transforms to independent fermion mode:\n\\begin{equation}\n\\begin{aligned}\n\t-\\frac{i}{2}\\gamma_i \\gamma_{i+N} \n\t&= -\\frac{i}{2}(d_i + d_i^\\dagger)(id_i-id_i^\\dagger) \\\\ \n\t&= d_i^\\dagger d_i-\\frac{1}{2}.\n\\end{aligned}\n\\end{equation}\n\n\n\n\\subsection{Gaussian States}\nThe Fermionic Gaussian states are those states with Gaussian form density operator:\n\\begin{equation}\n\t\\hat \\rho \\propto \\exp \\left(\\frac{i}{2}\\sum_{i,j=1}^{2N}M_{ij}\\omega_i \\omega_j \\right),\n\\end{equation}\nwhere the matrix $M$ is real and anti-symmetric.\\footnote{In particular, any thermal state has this form, with $M = \\beta H/2$. The ground state of the free fermion system, though being pure state, can be regarded as the Gaussian state in the limit $M = \\lim_{\\beta \\rightarrow \\infty} \\beta H$.}\nIf we expand the Gaussian form, the density operator becomes a Majorana polynomial:\\footnote{Note that the coefficient $\\Gamma$ in each order is not the direct expansion of the matrix $M$, since the direct expansion contains identical Majorana operators. That is, the $n$-th order expansion of the Majorana Gaussian form may contribute to the ($n-2m$)-th order term in the Majorana polynomial.}\n\\begin{equation}\n\t\\hat{\\rho} = \\frac{\\mathbb{I}}{2^N} + \\sum_{n=1}^{N}\\frac{i^n}{2^N}\\sum_{1\\le i_{1}<\\cdots<i_{2n} \\le 2N}\\Gamma_{i_{1}\\cdots i_{2n}} \\omega_{i_1}\\cdots\\omega_{i_{2n}},\n\\end{equation}\nwhere the coefficient $\\Gamma_{i_1 \\cdots i_{2n}}$ is the $2n$-point correlation function:\n\\begin{equation}\n\t\\Gamma_{i_1 \\cdots i_{2n}} = i^n \\langle \\omega_{i_1} \\cdots \\omega_{i_{2n}}\\rangle, \\quad i_m \\ne i_n.\n\\end{equation}\nIn particular, the 2-point function \n\\begin{equation}\n\t\\Gamma_{ij} = i\\langle \\omega_i \\omega_j\\rangle - i\\delta_{ij} = \\frac{i}{2}\\langle [\\omega_i, \\omega_j]\\rangle\n\\end{equation}\nis also called the \\textit{covariance matrix}. \nFor Gaussian state all $2n$-point correlation is determined by the covariance matrix by the Wick theorem.\n\\begin{framedrmk}[Two-point Correlation Function]\nWe are usually more familiar with the ordinary fermionic two-point correlation function $\\langle c^\\dagger_i c_j\\rangle$ or $\\langle c_i c_j\\rangle$, which is related to the Majorana covariance matrix by:\n\\begin{equation}\n\\begin{aligned}\n\t\\langle c_i^\\dagger c_j\\rangle &= \\frac{1}{4}(\n\t\t\\Gamma^{21}_{ij} - \\Gamma^{12}_{ij} + \n\t\ti \\Gamma^{11}_{ij} + i \\Gamma^{22}_{ij})\n\t\t+\\frac{1}{2}\\mathbb \\delta_{ij}, \\\\\n\t\\langle c_i c_j\\rangle &= \\frac{1}{4}(\n\t\t\\Gamma^{21}_{ij} + \\Gamma^{12}_{ij} + \n\t\ti \\Gamma^{11}_{ij} - i \\Gamma^{22}_{ij}), \\\\\n\t\\langle c_i^\\dagger c_j^\\dagger\\rangle &= \\frac{1}{4}(\n\t\t-\\Gamma^{21}_{ij} - \\Gamma^{12}_{ij} + \n\t\ti \\Gamma^{11}_{ij} - i \\Gamma^{22}_{ij}).\n\\end{aligned}\n\\end{equation}\n\\end{framedrmk}\n\nThe relation of the correlation in each order can be neatly captured by the Grassmannian Gaussian form:\n\\begin{equation}\n\\begin{aligned}\n\t\\omega(\\hat \\rho, \\theta) \n\t&= \\frac{1}{2^N} \\exp \\left(\\frac{i}{2} \\sum_{i,j=1}^{2N}\\Gamma_{ij}\\theta_i \\theta_j \\right) \\\\\n\t&=\\frac{1}{2^N} + \\sum_{n=1}^{N}\\frac{i^n}{2^N}\\sum_{1\\le i_{1}<\\cdots<i_{2n} \\le 2N}\\Gamma_{i_{1}\\cdots i_{2n}} \\theta_{i_1} \\cdots \\theta_{i_{2n}}.\n\\end{aligned}\n\\end{equation}\nWhen the covariance matrix is obtained, we can use the same routine to canonicalize the skew-symmetric matrix $\\Gamma$:\n\\begin{equation*}\n\t\\Gamma = O \\cdot \\Sigma(\\bm \\lambda) \\cdot O^T, \\quad\n\t\\tilde\\theta_n = \\sum_i O_{in} \\theta_i,\n\\end{equation*}\nand the density matrix in the Grassmann representation is\n\\begin{equation}\n\t\\omega(\\hat \\rho, \\theta) \n\t= \\prod_{n=1}^N \\left(\\frac{1}{2} e^{i \\lambda_n \\tilde\\theta_n \\tilde\\theta_{n+N}} \\right)\n\t= \\prod_{n=1}^N \\left(\\frac{1+i\\lambda_n \\tilde\\theta_n\\tilde\\theta_{n+N}}{2}  \\right).\n\\end{equation}\nThis state correspond to a product state $\\rho = \\otimes_n \\rho_n$ where\n\\begin{equation}\n\t\\rho_n = \\frac{1}{2} \\left[\\begin{array}{cc}\n\t\t1 + \\lambda_n & 0 \\\\\n\t\t0 & 1 - \\lambda_n\n\t\\end{array} \\right].\n\\end{equation}\nThe entanglement entropy is then\n\\begin{equation}\n\tS=\\sum_n S_n = -\\sum_n \\left[\n\t\\left(\\frac{1+\\lambda_n}{2}\\right)\\ln\\left(\\frac{1+\\lambda_n}{2}\\right)\n\t+ \\left(\\frac{1-\\lambda_n}{2}\\right)\\ln\\left(\\frac{1-\\lambda_n}{2}\\right)\\right].\n\\end{equation}\n\n\n\\subsection{Jordan-Wigner Transformation}\nSome lattice spin model can be mapped to fermion one by the Jordan-Wigner (J-W) transformation, which defines the isomorphism between the fermion and spin Hilbert space.\nOne a single site, we map the \n\n\n\n\n\\section{Lattice Gauges}\n\n\n\n", "meta": {"hexsha": "180d1ec2299c0fd12b7bf824bf8a6fa16a28fee4", "size": 10444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/LatticeFieldTheory.tex", "max_stars_repo_name": "jayren3996/Notes_on_QFT", "max_stars_repo_head_hexsha": "f4a9590b7fda5f4d2f2f230eb6cb5e31e2c40954", "max_stars_repo_licenses": ["MIT"], "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/LatticeFieldTheory.tex", "max_issues_repo_name": "jayren3996/Notes_on_QFT", "max_issues_repo_head_hexsha": "f4a9590b7fda5f4d2f2f230eb6cb5e31e2c40954", "max_issues_repo_licenses": ["MIT"], "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/LatticeFieldTheory.tex", "max_forks_repo_name": "jayren3996/Notes_on_QFT", "max_forks_repo_head_hexsha": "f4a9590b7fda5f4d2f2f230eb6cb5e31e2c40954", "max_forks_repo_licenses": ["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.2834008097, "max_line_length": 394, "alphanum_fraction": 0.6908272692, "num_tokens": 3647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6298355279374173}}
{"text": "\\section{Floquet Fermi Goldern Rule}\n\nIn this section we are going to derive the Floquet Fermi goldern rule for above derived quantum Floquet states using $t-t'$ formalism.\n\n\\vspace{5mm}\n\\noindent\nThe Floquet states \\eqref{3.17} fullfills the $t-t'$ Schrödinger equation [*Ref:myReport] as follows\n\\begin{equation} \\label{4.1}\n  i \\hbar \\pdv{t}\\ket{\\psi_{\\alpha}(t,t')} =\n  H_F(t') \\ket{\\psi_{\\alpha}(t,t')}\n\\end{equation}\nwhere Floquet Hamiltonian given by\n\\begin{equation} \\label{4.2}\n  H_F(t') \\equiv\n  H_e(t) - i\\hbar \\dv{t}\n\\end{equation}\nand\n\\begin{equation} \\label{4.3}\n  \\ket{\\psi_{\\alpha}(t,t')} =\n  \\exp(-\\frac{i}{\\hbar}\\varepsilon_{\\alpha} t)\\ket{\\phi_{\\alpha}(t')}\n\\end{equation}\nNow for the Eq. \\eqref{4.1} corresponding time evolution operator satisfy the Schrödinger equation\n\\begin{equation} \\label{4.4}\n  U_0(t,t_0;t') = \\exp(-\\frac{i}{\\hbar}H_F(t')\\qty[t-t_0])\n\\end{equation}\nConsider a time-independent total perturbation $V(\\mb{r})$ switched on at the reference time $t=t_0$, then Schrödinger equation becomes\n\\begin{equation} \\label{4.5}\n  i \\hbar \\pdv{t}\\ket{\\Psi_{\\alpha}(t,t')} =\n  \\qty[H_F(t') + V(\\mb{r})]\\ket{\\Psi_{\\alpha}(t,t')}\n\\end{equation}\nand when $t\\leq t_0$ both solutions of the Schrödinger equation coincide\n\\begin{equation} \\label{4.6}\n  \\ket{\\psi_{\\alpha}(t,t')} =\\ket{\\Psi_{\\alpha}(t,t')} \\quad\n  \\text{when} \\quad\n  t \\leq t_0\n\\end{equation}\nNow, we can introduce the interaction picture representation of the $t-t'$ Floquet state as\n\\begin{equation} \\label{4.7}\n  \\ket{\\Psi_{\\alpha}(t,t')}_I = U_0^{\\dagger}(t,t_0;t')\n  \\ket{\\Psi_{\\alpha}(t,t')}\n\\end{equation}\nand the perturbation in the interaction picture will be\n\\begin{equation} \\label{4.8}\n  V_I(\\mb{r}) = U_0^{\\dagger}(t,t_0;t')V(\\mb{r})U_0(t,t_0;t') =\n  V(\\mb{r}).\n\\end{equation}\nThis leads to the Schrödinger  eqution in the interction picture\n\\begin{equation} \\label{4.9}\n  i \\hbar \\pdv{t}\\ket{\\Psi_{\\alpha}(t,t')}_I =\n  V_I(\\mb{r})\\ket{\\Psi_{\\alpha}(t,t')}_I\n\\end{equation}\nwith the recursive solution\n\\begin{equation} \\label{4.10}\n  \\ket{\\Psi_{\\alpha}(t,t')}_I = \\ket{\\Psi_{\\alpha}(t_0,t')}_I +\n  \\frac{1}{i\\hbar}\n  \\int_{t_0}^t dt_1 \\;\n  V_I(\\mb{r}) \\ket{\\Psi_{\\alpha}(t_1,t')}_I\n\\end{equation}\nIterating the solution only upto first order (Born approximation) this leads to\n\\begin{equation} \\label{4.11}\n  \\ket{\\Psi_{\\alpha}(t,t')}_I \\approx \\ket{\\psi_{\\alpha}(t_0,t')} +\n  \\frac{1}{i\\hbar}\n  \\int_{t_0}^t dt_1 \\;\n  V_I(\\mb{r}) \\ket{\\psi_{\\alpha}(t_0,t')}\n\\end{equation}\nand multiply it by $\\bra{\\psi_{\\beta}(t_0,t')}$ and we will get\n\\begin{equation} \\label{4.12}\n  \\braket{\\psi_{\\beta}(t_0,t')}{\\Psi_{\\alpha}(t,t')}_I = \\braket{\\psi_{\\beta}(t_0,t')}{\\psi_{\\alpha}(t_0,t')} +\n  \\frac{1}{i\\hbar}\n  \\int_{t_0}^t dt_1 \\;\n  \\bra{\\psi_{\\beta}(t_0,t')}\n  V_I(\\mb{r}) \\ket{\\psi_{\\alpha}(t_0,t')}.\n\\end{equation}\nThen introdusing unitory operator $U_0$ we can re-write this as\n\\begin{equation} \\label{4.13}\n  \\begin{aligned}\n    \\mel{\\psi_{\\beta}(t_0,t')}{U_0^{\\dagger}(t,t_0;t')}{\\Psi_{\\alpha}(t,t')} & = \\mel{\\psi_{\\beta}(t_0,t')}{U_0^{\\dagger}(t,t_0;t')U_0(t,t_0;t')}{\\psi_{\\alpha}(t_0,t')} \\\\\n    & +\n    \\frac{1}{i\\hbar}\n    \\int_{t_0}^t dt_1 \\;\n    \\bra{\\psi_{\\beta}(t_0,t')}\n    U_0^{\\dagger}(t_1,t_0;t')\n    V(\\mb{r})\n    U_0(t_1,t_0;t')\n    \\ket{\\psi_{\\alpha}(t_0,t')}\n  \\end{aligned}\n\\end{equation}\nand this can be simplied as\n\\begin{equation} \\label{4.14}\n  \\begin{aligned}\n    \\braket{\\psi_{\\beta}(t,t')}{\\Psi_{\\alpha}(t,t')} = \\braket{\\psi_{\\beta}(t,t')}{\\psi_{\\alpha}(t,t')} +\n    \\frac{1}{i\\hbar}\n    \\int_{t_0}^t dt_1 \\;\n    \\bra{\\psi_{\\beta}(t_1,t')}\n    V(\\mb{r}) \\ket{\\psi_{\\alpha}(t_1,t')}.\n  \\end{aligned}\n\\end{equation}\nSince our $t-t'$ Floquet states are orthonormal [*Ref:myReport- t-t' formalism] we can derive that\n\\begin{equation} \\label{4.15}\n  \\begin{aligned}\n    \\braket{\\psi_{\\beta}(t,t')}{\\Psi_{\\alpha}(t,t')} =\n    \\delta_{\\alpha\\beta}\\exp(i\\omega\\qty[t'-t]) +\n    \\frac{1}{i\\hbar}\n    \\int_{t_0}^t dt_1 \\;\n    \\bra{\\psi_{\\beta}(t_1,t')}\n    V(\\mb{r}) \\ket{\\psi_{\\alpha}(t_1,t')}.\n  \\end{aligned}\n\\end{equation}\nNow, set $t_0 = 0$ and for a case $\\alpha \\neq \\beta$ where we can represent $\\alpha = (n_{\\alpha},m_{\\alpha})$ and $\\beta = (n_{\\beta},m_{\\beta})$ and this will simplied to\n\\begin{equation} \\label{4.16}\n  \\begin{aligned}\n    \\braket{\\psi_{\\beta}(t,t')}{\\Psi_{\\alpha}(t,t')} =\n    -\n    \\frac{i}{\\hbar}\n    \\int_{0}^t dt_1 \\;\n    \\bra{\\psi_{\\beta}(t_1,t')}\n    V(\\mb{r}) \\ket{\\psi_{\\alpha}(t_1,t')}.\n  \\end{aligned}\n\\end{equation}\nIn addition, since our Floquet states create a basis for composite space we can represent any solution using our Floquet states\n\\begin{equation} \\label{4.17}\n  \\ket{\\Psi_{\\alpha}(t,t')} = \\sum_{\\beta} a_{\\alpha\\beta}(t,t')\n  \\ket{\\psi_{\\beta}(t,t')}.\n\\end{equation}\nTherefore we can derive a equation for this \\textit{scattering amplitude} as\n\\begin{equation} \\label{4.18}\n  a_{\\alpha\\beta}(t,t') =\n  \\braket{\\psi_{\\beta}(t,t')}{\\Psi_{\\alpha}(t,t')} =\n  -\n  \\frac{i}{\\hbar}\n  \\int_{0}^t dt_1 \\;\n  \\bra{\\psi_{\\beta}(t_1,t')}\n  V(\\mb{r}) \\ket{\\psi_{\\alpha}(t_1,t')}.\n\\end{equation}\n\n\\vspace{5mm}\n\\noindent\nNow lets assume a scattering event from a $t-t'$ Floquet state $\\ket{\\psi_{\\beta}(t,t')}$ into another $t-t'$ Floquet state $\\ket{\\Psi_{\\alpha}(t,t')}$ with constant quansienergy $\\varepsilon$ given as follows\n\\begin{equation} \\label{4.19}\n  \\ket{\\Psi_{\\alpha}(t,t')} =\n  \\exp(-\\frac{i}{\\hbar}\\varepsilon t)\n  \\ket{\\Phi_{\\alpha}(t')}\n\\end{equation}\nNow consider a scattering event\n\\begin{equation} \\label{4.20}\n  \\psi_{\\beta}(\\mb{k'},t,t') = \\exp(-\\frac{i}{\\hbar}\\varepsilon_{\\beta} t)\n  \\phi_{\\beta}(\\mb{k'},t')\n  \\longrightarrow\n  \\Psi_{\\alpha}(\\mb{k},t,t') = \\exp(-\\frac{i}{\\hbar}\\varepsilon t)\n  \\Phi_{\\alpha}(\\mb{k},t')\n\\end{equation}\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=1.0]{figures/fig2.pdf}\n  \\caption{Scattering from $\\ket{\\psi_{\\beta}(t,t')}$ to constant energy state $\\ket{\\Psi_{\\alpha}(t,t')}$ due to scattering potential created by impurities.}\n  \\label{fig:2}\n\\end{figure}\n\n\\noindent\nHere we need to undestand a state of this considering system only be represented by two independent quantum numbers which are $n$ energy eigen\nstates and $m$ quantum number which represents the qunatized momentum in $x$ direction values. Lets calculate the scattering amplitutde of the above mentioned scattering scenario using the equation derived in \\eqref{4.18}.\n\\begin{equation} \\label{4.21}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t,t') & =\n    -\n    \\frac{i}{\\hbar}\n    \\int_{0}^t dt_1 \\;\n    \\bra{\\psi_{\\beta,\\mb{k'}}(t_1,t')}\n    V(\\mb{r}) \\ket{\\psi_{\\alpha,\\mb{k}}(t_1,t')} \\\\\n    & =\n    -\n    \\frac{i}{\\hbar}\n    \\int_{0}^t dt_1 \\;\n    e^{\\frac{i}{\\hbar}\\qty(\\varepsilon_{\\beta} - \\varepsilon)t_1}\n    \\bra{\\phi_{\\beta,\\mb{k'}}(t')}\n    V(\\mb{r}) \\ket{\\phi_{\\alpha,\\mb{k}}(t')}\n  \\end{aligned}\n\\end{equation}\nNext assuimg this scenario for long time $t \\rightarrow \\infty$ we can turn this integral into a delta distrubution as follows\n\\begin{equation} \\label{4.22}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(\\mb{k'},\\mb{k},t,t') & =\n    -\n    \\frac{i}{\\hbar}\n    \\lim_{t \\rightarrow \\infty}\\qty[\n      \\int_{-t/2}^{t/2} dt_1 \\;\n      e^{\\frac{i}{\\hbar}\\qty(\\varepsilon_{\\beta} - \\varepsilon)t_1}\n      \\bra{\\phi_{\\beta,\\mb{k'}}(t')}\n      V(\\mb{r}) \\ket{\\phi_{\\alpha,\\mb{k}}(t')}\n    ] \\\\\n    & =\n    -2\\pi i \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\bra{\\phi_{\\beta,\\mb{k'}}(t')}\n    V(\\mb{r}) \\ket{\\phi_{\\alpha,\\mb{k}}(t')}\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nNow lets consider about the inner product of the above derivation. Using completeness properties we can write that as follows\n\\begin{equation} \\label{4.23}\n  \\begin{aligned}\n    Q & \\equiv\n    \\bra{\\phi_{\\beta,\\mb{k'}}(t')}\n    V(\\mb{r}) \\ket{\\phi_{\\alpha,\\mb{k}}(t')} \\\\\n    & =\n    \\sum_{\\mb{k}}\\sum_{\\mb{k'}}\n    \\braket{\\phi_{\\beta,\\mb{k'}}(t')}{\\mb{k'}}\n    \\mel{\\mb{k'}}{V(\\mb{r})}{\\mb{k}}\n    \\braket{\\mb{k}}{\\phi_{\\alpha,\\mb{k}}(t')}\n  \\end{aligned}\n\\end{equation}\nand seperating $x$ and $y$ directional momentums we can modify this as follows (Assuming $L_y \\rightarrow \\infty$) and since we assumed that $L_y \\rightarrow \\infty$\n\\begin{equation} \\label{4.24}\n  \\begin{aligned}\n    Q & \\equiv\n    \\bra{\\phi_{\\beta,\\mb{k'}}(t')}\n    V(\\mb{r}) \\ket{\\phi_{\\alpha,\\mb{k}}(t')} \\\\\n    & =\n    \\sum_{k_x}\\sum_{{k'}_x}\n    \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dk_y d{k'}_y \\;\n    \\phi_{\\beta}^{\\dagger}(\\mb{k'},t')\n    \\mel{\\mb{k'}}{V(\\mb{r})}{\\mb{k}}\n    \\phi_{\\alpha}(\\mb{k},t').\n  \\end{aligned}\n\\end{equation}\nFor a random white scattering potential we can represent the inner product of scattering potential with momentum as a constant value as\n\\begin{equation} \\label{4.25}\n  V_{\\mb{k'},\\mb{k}} \\equiv \\mel{\\mb{k'}}{V(\\mb{r})}{\\mb{k}}.\n\\end{equation}\n\n\\noindent\nIn this study, the perturbation potential is assumed to be formed by an ensemble of randomly distributed impurities, since randomimpurities in a disorded metal is a better approximation for experimental results.\n\n\\noindent\nConsider $N_{imp}$ identical impurities positioned at the randomly distributed but fixed potions $\\mb{r}_i$. The elastic scattering potential $V(\\mb{r})$ is then given by the sum over uncorrelated single impurity potentials $\\upsilon(\\mb{r})$\n\\begin{equation} \\label{4.26}\n  V(\\mb{r}) \\equiv\n  \\sum_{i=1}^{N_{imp}}\n  \\upsilon (\\mb{r}-\\mb{r}_i).\n\\end{equation}\nNow assume that the perturbation $V(\\mb{r})$ is a Gaussian random potential where one can choose the zero of enerrgy such that the potential is zero on average. This model characterized by [*Ref: e.Akkermans G. Montambaux]\n\\begin{equation} \\label{4.27}\n  \\expval{\\upsilon(\\mb{r})}_{imp} =0\n\\end{equation}\n\\begin{equation} \\label{4.28}\n  \\expval{\\upsilon(\\mb{r})\\upsilon(\\mb{r'})}_{imp} = \\Upsilon(\\mb{r}-\\mb{r'})\n\\end{equation}\nwhere $\\expval{\\cdot}_{imp}$ denoted the average over realizations of the impurity disorder. In addition, this model assume that $\\upsilon (\\mb{r}-\\mb{r'})$ only dependes on the position difference $|\\mb{r}-\\mb{r'}|$ and it decays with a characteristic leangth $r_c$. Since the study considers the case where the waveleagth of radiation or scattering electrons is much faster than $r_c$, it is good approximation to make two-point correlation function to be\n\\begin{equation} \\label{4.29}\n  \\expval{\\upsilon(\\mb{r})\\upsilon(\\mb{r'})}_{imp} = \\Upsilon_{imp}^2\\delta(\\mb{r}-\\mb{r'})\n\\end{equation}\nand a random potential $V(\\mb{r})$ with this property is called white noise [*Ref: e.Akkermans G. Montambaux]. Then we can choose approximately total scattering potential as\n\\begin{equation} \\label{4.30}\n  V(\\mb{r}) =\n  \\sum_{i=1}^{N_{imp}}\n  \\Upsilon_{imp} \\delta(\\mb{r}-\\mb{r}_i).\n\\end{equation}\n\n\\noindent\nSince $\\braket{\\mb{r}}{\\mb{k}} = \\frac{1}{\\sqrt{L_xL_y}} \\exp(-i[k_xx + k_yy]),$ we can calculate the Eq. \\eqref{4.25} using this assumption as follows\n\\begin{equation} \\label{4.31}\n  \\begin{aligned}\n    V_{\\mb{k'},\\mb{k}}\n    & = \\mel{\\mb{k'}}{V(\\mb{r})}{\\mb{k}} \\\\\n    & = \\mel**{\\mb{k'}}{\\sum_{i=1}^{N_{imp}}\n    \\Upsilon_{imp} \\delta(\\mb{r}-\\mb{r}_i)}{\\mb{k}} \\\\\n    & = \\mel**{\\mb{k'}}{\\sum_{i=1}^{N_{imp}}\n    \\Upsilon_{imp} \\delta(x-x_i)\\delta(y-y_i)}{\\mb{k}} \\\\\n    & =\n    \\sum_{i=1}^{N_{imp}}\n    \\int_{-\\infty}^{\\infty} dy\\;\n    \\frac{1}{\\sqrt{L_xL_y}} e^{ik'_y y} \\delta(y-y_i) \\frac{1}{\\sqrt{L_xL_y}} e^{-i{k}_y y}\n    \\mel**{k'_x}{\\Upsilon_{imp} \\delta(x-x_i)}{k_x} \\\\\n    &=\n    \\sum_{i=1}^{N_{imp}} \\frac{1}{{L_xL_y}}\n    e^{i(k'_y - k_y )y}\n    \\mel**{k'_x}{\\Upsilon_{imp} \\delta(x-x_i)}{k_x}\n  \\end{aligned}\n\\end{equation}\nAssuming the total  umber of scatterers $N_{imp}$ is macroscopically large and for each impurity will produce same impurity potential($V_{k'_x,k_x}$) (\\textcolor{red}{this is not sure and we need to prove this somehonw or we need to bring the $V_{\\mb{k},\\mb{k'}}$ without calculations})for every $x$-directional momentum pairs. Because $\\upsilon (\\mb{r})$ in momentum space is a constant value. Then we can achieve following expression\n\\begin{equation} \\label{4.32}\n  \\begin{aligned}\n    V_{\\mb{k'},\\mb{k}}\n    & =\n    V_{k'_x,k_x}\n    \\frac{N_{imp}}{L_y L_x} \\int_{-\\infty}^{\\infty} dy_i\\;\n    e^{i\\qty({k'}_y - k_y)y_i} \\\\\n    & =\n    \\eta_{imp} V_{k'_x,k_x} \\delta(k'_y - k_y)\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{4.33}\n  V_{{k'}_x,k_x} \\equiv\n  \\mel**{k'_x}{\\Upsilon_{imp} \\delta(x-x_i)}{k_x}\n\\end{equation}\nis constant value for every $i$ impurity and $\\eta_{imp}$ is number of impurities in a unit area. It is important to notice that $\\ket{k_x} = e^{-ik_xx}$.\\\\\n\n\\noindent\nTherefore, using the Eq. \\eqref{3.36}, the Eq. \\eqref{4.24} modified to (we can change varable $t' \\rightarrow t$)\n\\begin{equation} \\label{4.34}\n  \\begin{aligned}\n    Q & =\n    \\sum_{k_x}\\sum_{{k'}_x}\n    {\\eta_{imp} V_{{k'}_x,k_x}}\n    \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} dk_y d{k'}_y \\;\n    \\delta({k'}_y - k_y)\n    \\\\\n    & \\times\n    \\sqrt{L_x}\n    \\exp(\n      -ib\\sin(2\\omega t)\n    )\n    \\exp(\n      i{k'}_y  \\qty[d\\sin(\\omega t) + {y'}_0]\n    )\n    \\tilde{\\chi}_{n_{\\beta}}\\qty({k'}_y -g\\cos(\\omega t))\n    \\\\\n    & \\times\n    \\sqrt{L_x}\n    \\exp(\n      ib\\sin(2\\omega t)\n    )\n    \\exp(\n      -ik_y  \\qty[d\\sin(\\omega t) + y_0]\n    )\n    \\tilde{\\chi}_{n_{\\alpha}}\\qty(k_y -g\\cos(\\omega t))\n  \\end{aligned}\n\\end{equation}\nand we can simplify this as\n\\begin{equation} \\label{4.35}\n  \\begin{aligned}\n    Q =\n    \\sum_{k_x}\\sum_{{k'}_x} &\n    {\\eta_{imp} L_x V_{{k'}_x,k_x}}\n    \\int_{-\\infty}^{\\infty} dk_y \\;\n    \\\\\n    & \\times\n    \\exp(\n      i{k}_y {y'}_0\n    )\n    \\tilde{\\chi}_{n_{\\beta}}\\qty({k}_y -g\\cos(\\omega t))\n    \\exp(\n      -ik_y y_0\n    )\n    \\tilde{\\chi}_{n_{\\alpha}}\\qty(k_y -g\\cos(\\omega t))\n  \\end{aligned}\n\\end{equation}\nand this can re-write as\n\\begin{equation} \\label{4.36}\n  \\begin{aligned}\n    Q =\n    \\sum_{k_x}\\sum_{{k'}_x}\n    {\\eta_{imp} L_x V_{{k'}_x,k_x}} I\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{4.37}\n  \\begin{aligned}\n    I \\equiv\n    \\int_{-\\infty}^{\\infty} dk_y \\;\n    \\tilde{\\chi}_{n_{\\beta}}\\qty(k_y -g\\cos(\\omega t))\n    \\tilde{\\chi}_{n_{\\alpha}}\\qty(k_y -g\\cos(\\omega t))\n    \\exp(\n      -ik_y  \\qty[y_0 - {y'}_0  ]\n    ).\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nTo avoid the energy tramision from external high-frequency field and electrons in the system, the applied radiation should be purely dressing field. Therefore, the only effect of the dressing field on 2DEG is the renormalization of the probability of elastic electron scattering within same Landau level $(n_{\\alpha} = n_{\\beta})$. Therefore Eq. \\eqref{4.37} can be modified to\n\\begin{equation} \\label{4.38}\n  \\begin{aligned}\n    I \\equiv\n    \\int_{-\\infty}^{\\infty} dk_y \\;\n    \\tilde{\\chi}_{n_{\\beta}}^2 \\qty(k_y -g\\cos(\\omega t))\n    \\exp(\n      -ik_y  \\qty[y_0 - {y'}_0  ]\n    ).\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nLets consider about this integral and we can calculate it as using the following subtitution. Let\n\\begin{equation} \\label{4.39}\n  {k}_y -g\\cos(\\omega t) = \\bar{k}_y \\longrightarrow d{k}_y = d\\bar{k}_y\n\\end{equation}\nand this leads to\n\\begin{equation} \\label{4.40}\n    I \\equiv\n    2\\pi \\times \\frac{1}{2\\pi}\n    \\int_{-\\infty}^{\\infty} d\\bar{k}_y \\;\n    \\tilde{\\chi}_{n_{\\alpha}}^2 \\qty(\\bar{k}_y)\n    \\exp(\n      -i\\qty(\\bar{k}_y + g\\cos(\\omega t)) \\qty(y_0 - {y'}_0)\n    ).\n\\end{equation}\nUsing Fourier transform of Gauss-Hermite functions and convolution theorem we can write this as\n\\begin{equation} \\label{4.41}\n    I \\equiv\n    {2\\pi}\n    \\exp(g[{y'}_0 - y_0]\\cos(\\omega t))\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y).\n\\end{equation}\nTherefore the scatterng amplitude \\eqref{4.22} will modified to\n\\begin{equation} \\label{4.42}\n  \\begin{aligned}\n    a_{\\alpha\\beta}({k'}_x,k_x,t)  =\n    -2\\pi i\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\sum_{k_x}\\sum_{{k'}_x}\n    {\\eta_{imp} L_x V_{{k'}_x,k_x}} I\n  \\end{aligned}\n\\end{equation}\nConsideirng qunatized momentum given in $x$ direction derived in Eq. \\eqref{1.53}, we can identify the non-zero values for scattering amplitude using following conditions\n\\begin{equation} \\label{4.43}\n    {k'}_x = \\frac{p_{x_{\\beta}}}{\\hbar} = m' \\frac{2\\pi}{L_x}\n    \\quad \\text{and} \\quad\n    k_x = \\frac{p_{x_{\\alpha}}}{\\hbar} = m \\frac{2\\pi}{L_x}.\n\\end{equation}\nThen we can simplfied scattering amplitude for given ${k'}_x$ and $k_x$ as (details of $k_x$ and $k'_x$ are included $\\alpha$ and $\\beta$ quantum numbers.)\n\\begin{equation} \\label{4.44}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t)  =\n    -2\\pi i\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\eta_{imp} L_x V_{{k'}_x,k_x}&\n    \\exp(g[{y'}_0 - y_0]\\cos(\\omega t)) \\\\\n    & \\times\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)\n  \\end{aligned}\n\\end{equation}\nSince this scattering amplitude is time-periodic we can write this as a Fourier series expansion\n\\begin{equation} \\label{4.45}\n    a_{\\alpha\\beta}(t) =\n    \\sum_{l=-\\infty}^{\\infty} a^l_{\\alpha\\beta} e^{-il\\omega t}.\n\\end{equation}\nIn addition, using Jacobi-Anger expansion\n\\begin{equation} \\label{4.46}\n    e^{iz\\cos(\\theta)} = \\sum_{l=-\\infty}^{\\infty} i^l J_l\\qty(z) e^{-il\\theta}\n\\end{equation}\nwe can re-write the Eq.\\eqref{4.44} as folllows\n\\begin{equation} \\label{4.47}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t)  =\n    -2\\pi i\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\eta_{imp} L_x V_{{k'}_x,k_x}&\n    \\sum_{l=-\\infty}^{\\infty} i^l J_l\\qty(g[{y'}_0 - y_0]) e^{-il\\omega t}\\\\\n    & \\times\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{4.48}\n  \\begin{aligned}\n    a_{\\alpha\\beta}(t)  =\n    \\sum_{l=-\\infty}^{\\infty}\n    -2\\pi i^{l+1} &\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\eta_{imp} L_x V_{{k'}_x,k_x}\n    J_l\\qty(g[{y'}_0 - y_0]) \\\\\n    & \\times\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y) e^{-il\\omega t}\n  \\end{aligned}\n\\end{equation}\nThen we can identified the Fourier series component as\n\\begin{equation} \\label{4.49}\n    a^l_{\\alpha\\beta} =\n    -2\\pi i^{l+1}\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\eta_{imp} L_x V_{{k'}_x,k_x}\n    J_l\\qty(g[{y'}_0 - y_0])\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)\n\\end{equation}\nNow one can introduce the definition of the \\textit{transition probability matrix} as\n\\begin{equation} \\label{4.50}\n    \\qty(A_{\\alpha\\beta})_{l,l'} \\equiv\n    a^l_{\\alpha\\beta}\\qty[a^{l'}_{\\alpha\\beta}]^{*}\n\\end{equation}\nand this becomes\n\\begin{equation} \\label{4.51}\n  \\begin{aligned}\n      \\qty(A_{\\alpha\\beta})_{l,l'} & =\n      \\qty[{ 2 \\pi \\eta_{imp} L_x |V_{{k'}_x,k_x}|}]^2\n      J_l\\qty(g[{y'}_0 - y_0]) J_{l'}\\qty(g[{y'}_0 - y_0])\n      \\delta^2(\\varepsilon_{\\beta} - \\varepsilon) \\\\\n      & \\times\n      \\int_{-\\infty}^{\\infty} dy \\;\n      {\\chi}_{n_{\\beta}}\\qty(y)\n      {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)\n      \\int_{-\\infty}^{\\infty} d\\bar{y} \\;\n      {\\chi}_{n_{\\beta}}\\qty(\\bar{y})\n      {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - \\bar{y}).\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nWe can reduce these intragal into one variable and derive\n\\begin{equation} \\label{4.52}\n  \\begin{aligned}\n      \\qty(A_{\\alpha\\beta})_{l,l'} =\n      \\qty[{ 2 \\pi \\eta_{imp} L_x |V_{{k'}_x,k_x}|}]^2 &\n      J_l\\qty(g[{y'}_0 - y_0]) J_{l'}\\qty(g[{y'}_0 - y_0])\n      \\delta^2(\\varepsilon_{\\beta} - \\varepsilon) \\\\\n      & \\times\n      \\qty|\n      \\int_{-\\infty}^{\\infty} dy \\;\n      {\\chi}_{n_{\\beta}}\\qty(y)\n      {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)|^2.\n  \\end{aligned}\n\\end{equation}\nThen desribing the square of the delta distribution using following procedure\n\\begin{equation} \\label{4.53}\n    \\delta^2(\\varepsilon) =\n    \\delta(\\varepsilon)\\delta(0) =\n    \\frac{\\delta(\\varepsilon)}{2\\pi \\hbar}\n    \\int_{-t/2}^{t/2} e^{i0\\times t'/\\hbar} dt'\\; =\n    \\frac{\\delta(\\varepsilon)t}{2\\pi \\hbar}\n\\end{equation}\none can modify our derivation in Eq. \\eqref{4.51} as\n\\begin{equation} \\label{4.54}\n  \\begin{aligned}\n      \\qty(A_{\\alpha\\beta})_{l,l'} =\n      \\qty[{ 2 \\pi \\eta_{imp} L_x |V_{{k'}_x,k_x}|}]^2 &\n      J_l\\qty(g[{y'}_0 - y_0]) J_{l'}\\qty(g[{y'}_0 - y_0])\n      \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n      \\frac{t}{2\\pi \\hbar}\\\\\n      & \\times\n      \\qty|\n      \\int_{-\\infty}^{\\infty} dy \\;\n      {\\chi}_{n_{\\beta}}\\qty(y)\n      {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)|^2.\n  \\end{aligned}\n\\end{equation}\nThen performing thetime derivation of each matrix element yeild the \\textit{transition amplitude matrix} as folllows\n\\begin{equation} \\label{4.55}\n  \\begin{aligned}\n    \\Gamma_{\\alpha\\beta}^{ll'} &  \\equiv\n    \\frac{d \\qty(A_{\\alpha\\beta})_{l,l'}}{dt} \\\\\n    & =\n    \\Lambda |V_{{k'}_x,k_x}|^2\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    J_l\\qty(g[{y'}_0 - y_0]) J_{l'}\\qty(g[{y'}_0 - y_0])\n    \\qty|\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(y_0 - {y'}_0 - y)|^2\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{4.56}\n    \\Lambda \\equiv\n    \\frac { 2\\pi \\eta_{imp}^2 L_x^2}{ \\hbar}\n\\end{equation}\n\n\\noindent\nNow using defintion of $y_0$ given in Eq. \\eqref{1.11} we can write that\n\\begin{equation} \\label{4.57}\n    y_0 - {y'}_0 =\n    - \\frac{p_{x_{\\alpha}}}{eB} + \\frac{p_{x_{\\beta}}}{eB} =\n    \\frac{\\hbar {k'}_x}{eB} - \\frac{\\hbar {k}_x}{eB} =\n    \\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x]\n\\end{equation}\nand this leads Eq. \\eqref{4.56} to\n\\begin{equation} \\label{4.58}\n  \\begin{aligned}\n    \\Gamma_{\\alpha\\beta}^{ll'}({k'}_x,k_x) =\n    \\Lambda |V_{{k'}_x,k_x}|^2\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon) &\n    J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n    J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n    & \\times\n    \\qty|\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x] - y)|^2\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nAn impurity average of white noise potential allows to identify $\\expval{|V_{{k'}_x,k_x}|^2} = V_{imp}$ and the inverse scattering time matrix is the sum over all momentum over the transition probability matrix\n\\begin{equation} \\label{4.59}\n    \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})^{ll'}_{\\alpha\\beta} \\equiv\n    \\frac{1}{L_x} \\sum_{{k'}_x}\n    \\expval**{\\Gamma_{\\alpha\\beta}^{ll'}({k'}_x,k_x)}_{imp}\n\\end{equation}\nand this implies\n\\begin{equation} \\label{4.60}\n  \\begin{aligned}\n    \\Gamma_{\\alpha\\beta}^{ll'}({k'}_x,k_x) =\n    \\frac{\\Lambda V_{imp}}{L_x} \\sum_{{k'}_x}\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon) &\n    J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n    J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n    & \\times\n    \\qty|\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x] - y)|^2\n  \\end{aligned}\n\\end{equation}\nFor the 1-dimentional case introduce the momentum continuum limit as folllows\n\\begin{equation} \\label{4.61}\n    \\frac{1}{L_x} \\sum_{{k'}_x} \\longrightarrow\n    \\frac{1}{2\\pi}\\int d {k'}_x\n\\end{equation}\nand this leads to\n\\begin{equation} \\label{4.62}\n  \\begin{aligned}\n    \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})^{ll'}_{\\alpha\\beta} =\n    \\frac{\\Lambda V_{imp}}{2\\pi}\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\int_{-\\infty}^{\\infty} d {k'}_x\n    &\n    J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n    J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n    & \\times\n    \\qty|\n    \\int_{-\\infty}^{\\infty} dy \\;\n    {\\chi}_{n_{\\beta}}\\qty(y)\n    {\\chi}_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x] - y)|^2\n  \\end{aligned}\n\\end{equation}\nUsing following subtitution\n\\begin{equation} \\label{4.63}\n    y = \\frac{\\hbar \\bar{k}}{eB} \\longrightarrow\n    dy = \\frac{\\hbar }{eB} d\\bar{k}\n\\end{equation}\nwe can modify above derivation as\n\\begin{equation} \\label{4.64}\n  \\begin{aligned}\n    \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})^{ll'}_{\\alpha\\beta} =\n    \\frac{\\Lambda V_{imp}}{2\\pi}\n    \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n    \\int_{-\\infty}^{\\infty} d {k'}_x\n    &\n    J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n    J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n    & \\times\n    \\qty(\\frac{\\hbar }{eB})^2\n    \\qty|\n    \\int_{-\\infty}^{\\infty} d\\bar{k} \\;\n    {\\chi}_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB}\\bar{k})\n    {\\chi}_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x - \\bar{k}])|^2,\n  \\end{aligned}\n\\end{equation}\n% Since squared Guess-Hermite functions are even function around zero we can re-write above derived expression as\n% \\begin{equation} \\label{4.65}\n%   \\begin{aligned}\n%     \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})^{ll'}_{\\alpha\\beta} =\n%     \\frac{\\Lambda V_{imp}}{2\\pi}\n%     \\delta(\\varepsilon_{\\beta} - \\varepsilon)\n%     \\int_{-\\infty}^{\\infty} d {k'}_x\n%     &\n%     J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n%     J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n%     & \\times\n%     \\frac{\\hbar }{eB}\n%     \\int_{-\\infty}^{\\infty} d\\bar{k} \\;\n%     \\tilde{\\chi}^2_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB}\\bar{k})\n%     \\tilde{\\chi}^2_{n_{\\beta}}\\qty(\\frac{\\hbar}{eB}\n%     \\qty[\\bar{k} - ({k}_x  - {k'}_x)])\n%   \\end{aligned}\n% \\end{equation}\nand finally we can derive our expression for the \\textit{inverse\nscattering time matrix} for $N$th Landau level (let $n_{\\alpha} = n_{\\beta} = N$)\n\\begin{equation} \\label{4.65}\n  \\begin{aligned}\n    \\qty(\\frac{1}{\\tau(\\varepsilon,k_x)})^{ll'}_{N} =\n    \\frac { \\eta_{imp}^2 L_x^2 \\hbar V_{imp}}{\\qty(eB)^2}\n    \\delta(\\varepsilon - \\varepsilon_{N})\n    \\int_{-\\infty}^{\\infty} d {k'}_x\n    &\n    J_l\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x])\n    J_{l'}\\qty(\\frac{g\\hbar}{eB}[{k}_x - {k'}_x]) \\\\\n    & \\times\n    \\qty|\n    \\int_{-\\infty}^{\\infty} d\\bar{k} \\;\n    {\\chi}_{N}\\qty(\\frac{\\hbar}{eB}\\bar{k})\n    {\\chi}_{N}\\qty(\\frac{\\hbar}{eB} \\qty[{k'}_x - {k}_x - \\bar{k}])|^2.\n  \\end{aligned}\n\\end{equation}\n\\hfill$\\blacksquare$\n", "meta": {"hexsha": "a453620ca4740990431c8b7e12a2c6c129f51ebf", "size": 25896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_04.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/sec_04.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/sec_04.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.3141210375, "max_line_length": 457, "alphanum_fraction": 0.6053058387, "num_tokens": 10389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6298355233910817}}
{"text": "%% LyX 2.1.1 created this file.  For more info, see http://www.lyx.org/.\r\n%% Do not edit unless you really know what you are doing.\r\n\\documentclass[english]{article}\r\n\\usepackage[T1]{fontenc}\r\n\\usepackage[utf8]{luainputenc}\r\n\\usepackage{amsmath}\r\n\\usepackage{esint}\r\n\\usepackage{babel}\r\n\\begin{document}\r\n\r\n\\title{Calculus 2}\r\n\r\n\r\n\\author{Professor Glaser}\r\n\r\n\\maketitle\r\n\r\n\\part{Review}\r\n\r\n\r\n\\section{Basic Antiderivatives}\r\n\r\nBelow are some antiderivatives you should be able to list at the drop\r\nof a hat. These are fundamental to any serious problem solving.\r\n\r\n\r\n\\subsection{Exponents}\r\n\r\n\\[\r\n\\int x^{n}dx=\\frac{x^{n+1}}{x+1}+C\\, n\\neq-1\\qquad\\int\\frac{1}{x}dx=\\ln|x|+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int e^{x}dx=e^{x}+C\\qquad\\int a^{x}dx=\\frac{a^{x}}{\\ln a}+C\\,\\left(a>0,a\\neq1\\right)\r\n\\]\r\n\r\n\r\n\r\n\\subsection{Trig Functions}\r\n\r\n\\[\r\n\\int\\cos xdx=\\sin x+C\\qquad\\int\\sin xdx=-\\cos x+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\sec^{2}xdx=\\tan x+C\\qquad\\int\\csc^{2}xdx=-\\cot x+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\sec x\\tan xdx=\\sec x+C\\qquad\\int\\csc x\\cot xdx=-\\csc x+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\tan xdx=\\ln|\\sec x|+C\\quad\\left(=\\ln|\\cos x|+C\\right)\\qquad\\int\\cot xdx=\\ln|\\sin x|+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\sec xdx=\\ln|\\sec x+\\tan x|+C\\qquad\\int\\csc xdx=-\\ln|\\csc x+\\cot x|+C\r\n\\]\r\n\r\n\r\n\r\n\\subsection{Fractions}\r\n\r\n\\[\r\n\\int\\frac{dx}{\\sqrt{1-x^{2}}}=\\sin^{-1}x+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\frac{dx}{1+x^{2}}=\\tan^{-1}x+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\frac{dx}{a^{2}+x^{2}}=\\frac{1}{a}\\tan^{-1}\\frac{x}{a}+C\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\frac{1}{2\\sqrt{x}}dx=\\sqrt{x}+C\\qquad\\int\\frac{dx}{x^{2}}=-\\frac{1}{x}+C\r\n\\]\r\n\r\n\r\n\r\n\\section{U-Substitution}\r\n\r\nAgain, you should know this stuff. Like, you should be able to do\r\nall of this without thinking. These problems are designed to be simple.\r\n\r\n\r\n\\subsection{Basic U-Sub}\r\n\r\n\\[\r\n\\int2x\\left(x^{2}+10\\right)^{98}dx\r\n\\]\r\nWe assign $u$ to the pain in the ass, so $u=x^{2}+10$ and $du=2xdx$.\r\nRewrite the equation so it's blantantly obvious and solve:\r\n\r\n\\[\r\n\\int2xdx\\left(x^{2}+10\\right)^{98}=\\int u^{98}du=\\frac{u^{99}}{99}+C\r\n\\]\r\nThen you substitute in the original like so:\r\n\r\n\\[\r\n\\boxed{\\frac{\\left(x^{2}+10\\right)^{99}}{99}+C}\r\n\\]\r\nNot so bad, right?\r\n\r\n\r\n\\subsection{A bit harder}\r\n\r\nAll right, what if the answer isn't glaringly obvious?\r\n\r\n\\[\r\n\\int2x\\left(x^{2}+10\\right)^{98}dx\r\n\\]\r\n\r\n\r\nThis is also really easy. $u=x^{2}+10$ and $du=2xdx$, so just divide\r\nuntil $dx$ fits in nicely. Since $\\frac{1}{2}du=xdx$, we can do\r\nthe exct same thing, but with a new constant.\r\n\r\n\\[\r\n\\int xdx\\left(x^{2}+10\\right)^{98}=\\int\\frac{1}{2}u^{98}du=\\frac{1}{2}*\\frac{u^{99}}{99}+C\r\n\\]\r\n\r\n\r\nSubstitute again:\r\n\r\n\\[\r\n\\boxed{\\frac{\\left(x^{2}+10\\right)^{99}}{198}+C}\r\n\\]\r\n\r\n\r\nAgain, not hard at all.\r\n\r\n\r\n\\subsection{Bounded Integrals}\r\n\r\nWhat is there are bounds on the integral? This isn't hard, just more\r\ntedious.\r\n\r\n\\[\r\n\\int_{0}^{1}2x\\left(x^{2}+2\\right)^{5}dx\r\n\\]\r\n\r\n\r\nDo the same thing with $u$:\r\n\r\n\\[\r\nu=x^{2}+2\\quad du=2xdx\r\n\\]\r\n\r\n\r\n\\[\r\n\\int_{?}^{?}u^{5}du\r\n\\]\r\n\r\n\r\nGreat. Now that the equation is in terms of $u$, we have to recalculate\r\nthe bounds. Since we already know the equation for $u$, shoudln't\r\nbe that bad. Plug in 0 and 1 in this case and solve it out:\r\n\r\n\\[\r\n\\int_{2}^{3}u^{5}du=\\boxed{\\frac{3^{6}}{6}-\\frac{2^{6}}{6}}\r\n\\]\r\n\r\n\r\nBoom. Done.\r\n\r\n\r\n\\subsection{Fractions}\r\n\r\n\\[\r\n\\int\\frac{2xdx}{x^{2}+34}\r\n\\]\r\n\r\n\r\nIf you set $u=x^{2}+34$ and $du=2xdx$, this problem is actually\r\nstupidly simple. But you have to remember some log rules.\r\n\r\n\\[\r\n\\int\\frac{du}{u}=\\ln|u|+C=\\boxed{\\ln|x^{2}+34|+C}\r\n\\]\r\n\r\n\r\n...Let's keep going.\r\n\r\n\r\n\\subsection{$e$ and Friends}\r\n\r\n\\[\r\n\\int xe^{x^{2}}dx\r\n\\]\r\n\r\n\r\nRemember, $u$ handles the pain in the ass part. $u=x^{2}$and $\\frac{1}{2}du=xdx$.\r\n\r\n\\[\r\n\\frac{1}{2}\\int e^{u}du=\\frac{1}{2}e^{u}+C=\\boxed{\\frac{1}{2}e^{x^{2}}+C}\r\n\\]\r\n\r\n\r\n\r\n\\subsection{Trig}\r\n\r\nI'm too lazy to write commentary for this:\r\n\r\n\\[\r\n\\int\\frac{\\cos x}{\\sqrt{\\sin x}}\r\n\\]\r\n\r\n\r\n\\[\r\nu=\\sin x\\quad u=\\cos xdx\r\n\\]\r\n\r\n\r\n\\[\r\n\\int\\frac{du}{\\sqrt{u}}=\\int u^{-\\frac{1}{2}}du=2u^{\\frac{1}{2}}=\\boxed{2\\sqrt{\\sin x}+C}\r\n\\]\r\n\r\n\r\n\r\n\\section{Final Words}\r\n\r\nI swear, Alex, if you don't remember any part of this after learning\r\nit 4 times in your life, I want you to call Miguel and Carrie and\r\nAlexandra so they can yell at you. A lot.\r\n\\end{document}\r\n", "meta": {"hexsha": "e83b10ec369b76ee40b79d0cfef2b422a22f4b95", "size": 4189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Notes/Review.tex", "max_stars_repo_name": "lyra833/Stufts", "max_stars_repo_head_hexsha": "0a58c6793286e5cb206bba64eba649938c3e6292", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-06-24T17:48:51.000Z", "max_stars_repo_stars_event_max_datetime": "2015-06-24T17:48:51.000Z", "max_issues_repo_path": "Calculus/Notes/Review.tex", "max_issues_repo_name": "lyra833/Stufts", "max_issues_repo_head_hexsha": "0a58c6793286e5cb206bba64eba649938c3e6292", "max_issues_repo_licenses": ["MIT"], "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/Notes/Review.tex", "max_forks_repo_name": "lyra833/Stufts", "max_forks_repo_head_hexsha": "0a58c6793286e5cb206bba64eba649938c3e6292", "max_forks_repo_licenses": ["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.6751054852, "max_line_length": 91, "alphanum_fraction": 0.5944139413, "num_tokens": 1632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430311279739, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6298355152592574}}
{"text": "%\n% STAT 100: Chance and Data Analysis - A Course Overview\n% Section: Analysis of Multi-Variable Data\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Analysis of Multi-Variable Data}\n\t\\label{sec:analysis-of-multi-variable-data}\n\\subsection{Relationships between Two Quantitative Variables}\n\t\\label{subsec:analysis-of-multi-variable-data:relationships-between-two-quantitative-variables}\n\\begin{easylist}\n\n\t& Relationships between two quantitative variables:\n\t& \\emph{Dependent/respondent variable:} Variable to be predicted\n\t\t&& Placed on the vertical (y) axis\n\t& \\emph{Independent variable/predictor:} Variable used to predict the dependent variable\n\t\t&& Placed on the horizontal (x) axis\n\t& \\emph{Scatterplot:} Visual comparisons of the values of two quantitative variables (see figure %TODO in bullet point?\n\t\n\t& \\emph{positive/negative:}\n\t\n\t& Forms and strength of a relationship:\n\t\t&& \\emph{Linear:} Approximate change in values can be summarized in a single 2-d direction\n\t\t\t&&& I.e. Points which follow a straight line\n\t\t&& \\emph{Non-linear:} Values change in multiple 2-d directions\n\t\t\t&&& E.g. Exponential functions, trigonometric functions\n\t\t\t\n\t\t&& \\emph{Strength:} Denseness of distribution which shows a clear form/relation\n\t\t\t&& \n\t\t\n\t& \\emph{Correlation coefficient:} Value which denotes the strength of the data\n\t\t\t&&& Denoted by $r$\n\t\t\t&&& Formula: $r = $\n\t\t\t&&& Value:\n\t\t\t\t&&&& $-1 \\leq r \\leq 1$\n\t\t\t\t&&&& Closer to -1, the data is more negatively related\n\t\t\t\t&&&& Closer to 0, the data is more weakly related \n\t\t\t\t&&&& Closer to 1, the data is more positively related\n\t\t\t&&& Interpretation: The closer to 1 $r$ is, the stronger the correlation\n\t\t\t&&& Only applies to linear data\n\t\t\t\t&&&& 0 for non-linear data\n\t\t\t&&& Outliers may need to be removed before calculation\n\t\t\t&&& E.g. The correlation coefficient of a midterm grade and a final grade was found to be 0.8747. The relationship between the two grades is positive, strong, and linear.\n\t\t\t\n\t\t&& For an interpretation of the magnitude, see table~\\ref{tab:strength-of-a-correlation-coefficient}\n\t\t\n\t\t\\Deactivate\n\t\t\\begin{table}[!htb]\n\t\t\t\\centering\n\t\t\t\\caption{Strength of a Correlation Coefficient}\n\t\t\t\\label{tab:strength-of-a-correlation-coefficient}\n\t\t\t\\begin{tabular}{ c l }\n\t\t\t\tMagnitude of the Correlation Coefficient & Strength \\\\\n\t\t\t\t\\hline\n\t\t\t\t$0 < |r| < 0.4$ & Weak \\\\\n\t\t\t\t$0.4 \\leq |r| < 0.6$ & Moderately weak \\\\\n\t\t\t\t$0.6 \\leq |r| < 0.8$ & Moderately strong \\\\\n\t\t\t\t$0.8 \\leq |r| < 1.0$ & Strong \\\\\n\t\t\t\t$|r| = 1$ & Perfect\n\t\t\t\\end{tabular}\n\t\t\\end{table}\n\t\t\\Activate\n\t\t\n\t\t%TODO incomplete\n\t\t\t\t\n\t\t\t\n\t& Correlation:\n\t\t&& Declares an association between two variables\n\t\t&& Does not imply causation - i.e. an existing linear relationship does not mean a change in the independent variable causes a change in the dependent variable (see figure~\\ref{fig:xkcd-552})\n\t\n\t\\begin{figure}[!htb]\n\t\t\\centering\n\t\t\\caption{XKCD Webcomic - 552: Correlation}\n\t\t\\label{fig:xkcd-552}\n\t\t\\href{https://xkcd.com/552/}{\\includegraphics[scale=.75]{xkcd-552-correlation}}\n\t\\end{figure}\n\t\t\n\t\t\n\t& \\emph{Lurking variable:} Variable outside of the tested variables which explains an association between the two tested variables\n\t\t\n\t& \\emph{Regression analysis:}\n\t\t&& \\emph{Regression line:} Best-fit line\n\t\t\t&&& Before using the regression line to predict data, check data ranges\n\t\t&& %TODO\n\t\t&& \\emph{Regression equation:} Mathematical equation of a regression line\n\t\t\t&&& May have multiple $x$ variables\n\t\t\t&&& Formula: $y = slope_1 \\cdot x_1 + slope_2 \\cdot x_2 + \\ldots + slope_n \\cdot x_n + y_{intercept}$\n\t\t\t\t&&&& Where $y =$ dependent variable, and $x_1, x_2, \\ldots, x_n =$ independent variables\n\t\t\t\t&&&& Use a scientific calculator to determine the intercept and slope %TODO how\n\t\t\t&&& Cannot be used to predict data less than the minimum or greater than the maximum because there is no data to support the analysis\n\t\t\t&&& Slope of a regression equation: $\\frac{y_{2} - y_{1}}{x_{2} - x_{1}}$\n\t\t\t\t&&&& Per 1 unit change in $x$, $y$ should change by the value of the slope\n\t\t\t\t&&&& Example of interp: For every 1 additional $x$, we predict $y$ will change by $slope$.\n\t\t&& \\emph{Coefficient of determination:}\n\t\t\t&& Denoted by $R^{2}$\n\t\t\t&& Value:\n\t\t\t\t&&& $R^{2} = r^2$ where $r =$ the correltion coefficient\n\t\t\t\t&& $0 \\leq R^{2} \\leq 1$\n\t\t\t&& Interpretation: $R^{2}$ represents the variability in percent which can be explained by the regression line.\n\t\t\t%TODO notes\n\t\t\n\t& Multiple regression:\n\t\t&& See video\n\t\t&& Use excel\n\t\t\n\t\n\t\t\n\\end{easylist}\n\\clearpage", "meta": {"hexsha": "e609de1436b79d2736d58c4d74da96693d77c648", "size": 4506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stat-100-chance-and-data-analysis/tex/analysis-of-multi-variable-data.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": "stat-100-chance-and-data-analysis/tex/analysis-of-multi-variable-data.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": "stat-100-chance-and-data-analysis/tex/analysis-of-multi-variable-data.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": 40.9636363636, "max_line_length": 193, "alphanum_fraction": 0.6913004882, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585903489892, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6298349102179467}}
{"text": "% !TEX root = ./Basilisk-MRPROTATION-20180522.tex\n\n\n\\begin{figure}[htb]\n\t\\centerline{\n\t\\includegraphics[]{Figures/moduleIO}\n\t}\n\t\\caption{Illustration of the mrpRotation() input and output messages.  Required messages are shown with a solid line, while optional message have a dashed line.}\n\t\\label{fig:moduleIO}\n\\end{figure}\n\n\\section{Model Description}\nThe purpose of this {\\tt mrpRotation} module is to add a constant rotation relative to the input frame $\\mathcal{R}_{0}$.  The output reference frame is called $\\mathcal{R}$.  The initial orientation is specified through an MRP\\cite{schaub} set $\\bm\\sigma_{R/R0}$, while the  $\\mathcal{R}$-frame angular velocity vector $\\leftexp{R}{\\bm\\omega}_{R/R0}$ is held constant in this module.  \n\nAssume that the input reference frame $\\mathcal{R}_{0}$ is given through an attitude state input message containing $\\bm\\sigma_{R_{0}/N}$, $\\leftexp{N}{\\bm\\omega}_{R_{0}/N}$ and $\\leftexp{N}{\\dot{\\bm\\omega}}_{R_{0}/N}$ as illustrated in Figure~\\ref{fig:moduleIO}.  The MRP set is mapped into the corresponding Direction Cosine Matrix or DCM\\cite{schaub} using\n\\begin{equation}\n\t[R_{0}N] = [R_{0}N ( \\bm\\sigma_{R_{0}/N})]\n\\end{equation}\n\n\nThe goal of the motion is to compute the attitude of $\\mathcal{R}$ relative to input frame $\\mathcal{R}_{0}$ such that\n\\begin{align}\n\t\\label{eq:mRot1}\n\t\\dot{\\bm\\sigma}_{R/R_{0}} &= \\frac{1}{4} [B(\\bm\\sigma_{R/R_{0}})] \\leftexp{R}{\\bm\\omega}_{R/R_{0}}\n\t\\\\\n\t\\label{eq:mRot2}\n\t\\frac{\\leftexp{R}{\\D} {\\bm\\omega}_{R/R_{0}}}{\\D t} &= \\bm 0\n\\end{align}\nAssume the initial $\\bm\\sigma_{R/R_{0}}(t_{0})$ set and the $\\mathcal{R}$-frame relative invariant $\\leftexp{R}{\\bm\\omega}_{R/R_{0}}$ vector are provided to the module.  The current $\\bm\\sigma_{R/R_{0}}(t_{0})$ value is then obtained by Eq.~\\eqref{eq:mRot1}.  The current DCM of the $\\mathcal{R}$-frame is thus\n\\begin{equation}\n\t\\label{eq:mRot3}\n\t[RN] = [RR_{0}(\\bm\\sigma_{R/R_{0}}(t) ] [R_{0}N]\n\\end{equation}\n\nNext, the angular velocity vector is transformed to inertial frame $\\mathcal{N}$-frame components using\n\\begin{equation}\n\t\\label{eq:mRot4}\n\t\\leftexp{N}{\\bm\\omega}_{R/R_{0}} = [RN]^{T}\\ \\leftexp{R}{\\bm\\omega}_{R/R_{0}}\n\\end{equation}\nto find the inertial angular velocity of the output reference frame:\n\\begin{equation}\n\t\\label{eq:mRot5}\n\t\\leftexp{N}{\\bm\\omega}_{R/N} = \\leftexp{N}{\\bm\\omega}_{R/R_{0}} + \\leftexp{N}{\\bm\\omega}_{R_{0}/N}\n\\end{equation}\n\nFinally, the inertial angular acceleration of the output reference frame is found using the transport theorem:\n\\begin{equation}\n\t\\label{eq:mRot6}\n\t\\dot{\\bm\\omega}_{R/N} = \n\t\\frac{\\leftexp{R}{\\D} {\\bm\\omega}_{R/R_{0}}}{\\D t} \n\t + \\bm\\omega_{R/N} \\times {\\bm\\omega}_{R/R_{0}}\n\t+ \\dot{\\bm\\omega}_{R_{0}/N}\n\t= \\bm\\omega_{R_{0}/N} \\times {\\bm\\omega}_{R/R_{0}}\n\t+ \\dot{\\bm\\omega}_{R_{0}/N}\n\\end{equation}\nwhere $\\bm\\omega_{R/N} \\times {\\bm\\omega}_{R/R_{0}} = (\\bm\\omega_{R/R_{0}} +\\bm\\omega_{R_{0}/N}) \\times {\\bm\\omega}_{R/R_{0}} = \\bm\\omega_{R_{0}/N} \\times {\\bm\\omega}_{R/R_{0}}$ is used.  Expressed in $\\mathcal{N}$ frame components, this vector equation is numerically evaluated using:\n\\begin{equation}\n\t\\label{eq:mRot7}\n\t\\leftexp{N}{\\dot{\\bm\\omega}}_{R/N} = \\leftexp{N}{\\bm\\omega}_{R_{0}/N} \\times \\leftexp{N}{\\bm\\omega}_{R/R_{0}}\n\t+ \\leftexp{N}{\\dot{\\bm\\omega}}_{R_{0}/N}\n\\end{equation}\n\n\n\n\n", "meta": {"hexsha": "0e9aaa6990e63d0de0d722b5fb0533dd6e992924", "size": 3283, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/fswAlgorithms/attGuidance/mrpRotation/_Documentation/secModuleDescription.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/attGuidance/mrpRotation/_Documentation/secModuleDescription.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/attGuidance/mrpRotation/_Documentation/secModuleDescription.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": 49.7424242424, "max_line_length": 386, "alphanum_fraction": 0.6798659762, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6298349040200982}}
{"text": "\\section{Bandits}\nThe \\emph{multi-armed bandits problem} is a simplified setting of RL where actions do not affect the world state. In other words, the current state does not depend on previous actions, and the reward is immediate. Like any RL problem with unknown MDP, a successful agent should solve the \\emph{exploration-exploitation dilemma}, i.e. find a balance between exploiting what it has already learned to improve the reward and exploring in order to find the best actions.\n\n\\paragraph{Setting}\nBandits problems can be stationary or non-stationary, and the setting can be stochastic or adversarial. Agents typically learn in an online setting and, in the case of a non-associative task (no need to associate different actions with different situations), they try to find a single best action out of a finite number of actions (also called “arms”). For associative tasks, \\emph{contextual bandits} make use of additional information which can be global or individual context (i.e. per arm). Context can be fixed (e.g. $x\\in \\mathbb{R}^d$) or variable (e.g. $x_t\\in \\mathbb{R}^d, \\forall t$).\n\nThe objective is to find a policy $\\pi$ that maximizes the cumulated reward:\n\\[\n    \\pi^* = \\argmax_\\pi \\sum_{t=0}^T r_{\\pi_t, t}\n\\]\nWhere $\\pi_t \\in \\{1, \\dots, K\\}$ is the arm selected by $\\pi$ at time $t$, and $r_{i,t}$ is the reward obtained at time $t$ after selecting the arm $i \\in \\{1, \\dots, K\\}$. At any point $t$, the expected reward of an arm $i \\in \\{1, \\dots, K\\}$ is:\n\\[\n    \\hat{\\mu}_{i,t} = \\E[r_{i,t}] = \\frac{1}{T_i} \\sum_{\\substack{s=0 \\\\ \\pi_s=i}}^t r_{i,s}\n\\]\nWhere $T_i = \\sum_{s=0}^t \\mathbbm{1}_{\\pi_s=i}$ is the number of times arm $i$ was played up to time $t$.\n\n\\paragraph{$\\epsilon$-greedy}\nThe greedy strategy simply consists in selecting the arm that has given the best rewards and therefore has the best expected reward:\n\\[\n    \\forall t, \\pi_t^\\text{greedy} = \\argmax_i \\hat{mu}_{i,t}\n\\]\nThe $\\epsilon$-greedy sometimes acts greedily, and sometimes selects a random action to improve exploration:\n\\[\n    \\forall t, \\pi_t^\\text{$\\epsilon$-greedy} = \\begin{cases}\n        \\argmax_i \\hat{mu}_{i,t} & \\text{with probability $1-\\epsilon$} \\\\\n        i \\sim \\mathcal{U}\\{1,K\\} & \\text{with probability $\\epsilon$}\n    \\end{cases}\n\\]\n\n\\paragraph{Upper Confidence Bounds (UCB)}\nUCB \\cite{auer2002using} follows an optimistic strategy and selects the best arm in the best case scenario, i.e. according to the upper bounds $B_t(i)$ on the arms value estimates:\n$$\n\\pi_t = \\argmax_i B_t(i)\n\\quad \\text{with} \\quad\nB_t(i) = \\hat{\\mu}_{i,t} + \\sqrt{\\frac{2 \\log t}{T_i}}\n$$\nLinUCB \\cite{li2010contextual} follows the UCB strategy but considers a linear and individual context $x_{i,t}$. We have $\\mathbb{E}[r_{i,t} \\mid x_{i,t}] = \\theta_i^T x_{i,t}$ and parameters $\\theta_i$ are estimated with Ridge Regression on previously observed contexts and rewards.\n\n\\paragraph{Thompson Sampling}\nThompson Sampling \\cite{kaufmann2012thompson} follows a Bayesian approach and considers a parametric model $P(\\mathcal{D} \\mid \\theta)$ with a prior $P(\\theta)$. For instance, in the linear case \\cite{agrawal2013thompson}: $P(r_{i,t} \\mid \\theta) = \\mathcal{N}(\\theta^T x_{i,t}, v^2)$ and $P(\\theta) = \\mathcal{N}(0, \\sigma^2)$. Then, at each iteration $t$, we sample $\\theta$ from $P(\\theta \\mid \\mathcal{D}) \\propto P(\\mathcal{D}\\mid\\theta) P(\\theta)$ and select the arm $\\pi_t = \\argmax_i \\mathbb{E}[r_{i,t} \\mid x_{i,t}, \\theta]$.", "meta": {"hexsha": "d937938d3c63f7e1a712090f01f32f746e22d6fc", "size": 3446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/1_bandits.tex", "max_stars_repo_name": "alexandrethm/rl-cheatseet", "max_stars_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-06-18T23:54:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T11:54:02.000Z", "max_issues_repo_path": "sections/1_bandits.tex", "max_issues_repo_name": "alexandrethm/rl-cheatsheet", "max_issues_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_issues_repo_licenses": ["MIT"], "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/1_bandits.tex", "max_forks_repo_name": "alexandrethm/rl-cheatsheet", "max_forks_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_forks_repo_licenses": ["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.15, "max_line_length": 595, "alphanum_fraction": 0.708357516, "num_tokens": 1061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6298349012712658}}
{"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\\usepackage{graphicx}\n\n\\newcommand{\\prob}[1]{\\mathbb{P}(#1)}\n\\newcommand{\\condprob}[2]{\\mathbb{P}(#1 \\text{ } \\lvert \\text{ } #2)}\n\\newcommand{\\expected}[1]{\\text{E}(#1)}\n\\newcommand{\\variance}[1]{\\text{V}(#1)}\n\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\field}{\\mathcal{F}}\n\n\\begin{document}\n% ===================================================================================\n% ===================================================================================\n\n\\section*{CHAPTER 8: Law of Large Numbers}\n% ================ SECTION 8.1 ================\n\\subsection*{Law of Large Numbers for Discrete Random Variables}\n\\noindent\nWe have also defined probability mathematically as a value of a distribution function for the random variable representing the experiment. The Law of Large Numbers, which is a theorem proved about the mathematical model of probability, shows that this model is consistent with the frequency interpretation of  probability.\n\n\\subsubsection*{ChebyShev Inequality}\n\\noindent\n\\textbf{Theorem 8.1 (ChebyShev Inequality)} Let $X$ be a discrete random variable with expected value $\\mu \\expected{X}$, and let $\\epsilon > 0$ be any positive real number. Then,\n\n\\begin{equation*}\n\\prob{\\lvert X - \\mu \\rvert \\geq \\epsilon} \\leq \\frac{\\variance{X}}{\\epsilon^2}.\n\\end{equation*}\n\n\\begin{tcolorbox}\n\\noindent\nLet X by any random variable with $\\expected{X} = \\mu$ and $\\variance{X} = \\sigma^2$. Then, if $\\epsilon = k \\sigma$, Chebyshev's Inequality states that\n\n\\begin{equation*}\n\\prob{\\lvert X - \\mu \\rvert \\geq k \\sigma} \\leq \\frac{\\sigma^2}{k^2 \\sigma^2} = \\frac{1}{k^2}.\n\\end{equation*}\n\n\\noindent\nThus, for any random variable, the probability of a deviation from the mean of\nmore than k standard deviations is $\\leq \\frac{1}{k^2}$. If, for example, $k = 5$, $\\frac{1}{k^2} = .04$.\n\n\\vspace*{.5cm}\n\\noindent\nChebyshev’s Inequality is the best possible inequality in the sense that, for any\n$\\epsilon > 0$, it is possible to give an example of a random variable for which Chebyshev’s Inequality is in fact an equality. To see this, given $\\epsilon > 0$, choose X with distribution \n\n\\begin{equation*}\np_X = {- \\epsilon \\qquad  + \\epsilon \\choose 1/2 \\qquad 1/2}\n\\end{equation*}\n\nThen $\\expected{X} = 0$, $\\variance{X} = \\epsilon^2$, and \n\n\\begin{equation*}\n\\prob{\\lvert X - \\mu \\rvert \\geq \\epsilon} \\leq \\frac{\\variance{X}}{\\epsilon^2} = 1.\n\\end{equation*}\n\nWe are now prepared to state and prove the Law of Large Numbers.\n\\end{tcolorbox}\n\n% https://www.youtube.com/watch?v=uMgK000XFhA\n\\noindent\nAlternatively, Chebyshev's theorem says that the proportion of any distribution that lies within $k$ standard deviations of the mean is at least: $1-\\frac{1}{k^2}$, where $k$ is any positive number greater than $1$. This theorem applies to \\textbf{all distributions}.\n\n\\begin{tcolorbox}\nFor example, Chebyshev's theorem says that within $2$ standard deviations of the mean, you will find at least\n\n\\begin{equation*}\n1 - \\frac{1}{k^2} = 1 - \\frac{1}{2^2} = 1 - \\frac{1}{4} = \\frac{3}{4},\n\\end{equation*} \n\n\\noindent\nor at least $75\\%$ of data will lie within $2$ standard deviations from the mean.\n\\end{tcolorbox}\n\n\\vspace*{.5cm}\n\\begin{tcolorbox}\nLet $X_1, X_2, \\ldots, X_n$ be a Bernoulli trials process with probability $.3$ for success and $.7$ for failure. Then, $\\expected{X_j} = .3$ and $\\variance{X_j} = .3 \\cdot .7 = .21$. If\n\n\\begin{equation*}\nA_n = \\frac{S_n}{n} = \\frac{X_1, X_2, \\ldots, X_n}{n}\n\\end{equation*}\n\n\\noindent\nis the average of the $X_j$, then $\\expected{A_n} = .3$ and $\\variance{A_n} = \\frac{\\variance{S_n}}{n^2} = \\frac{.21}{n}$. \n\n\\vspace*{.3cm}\n\\noindent\nLet $\\epsilon = .1$. Then, Chebyshev's Inequality states that \n\n\\begin{equation*}\n\\prob{\\lvert A_n - .3 \\rvert \\geq .1 } \\leq \\frac{.21}{n(.1)^2} = \\frac{21}{n}.\n\\end{equation*}\n\n\\noindent\nIf $n = 100$, this can be rewritten as \n\n\\begin{equation*}\n\\prob{.2 <  A_{100} < .4 } \\geq \\mathbb{P}_{A_{100}}\n\\end{equation*}\n\n\\noindent\nwhere $\\mathbb{P}_{A_{100}}$ is the probability that the mean of $A_n$ lies between $.2$ and $.4$, which is $.1$ away from $\\expected{A_n} = .3$. By Chebyshev, we can calculate this by finding how many standard deviations $.1$ is. The standard deviation, $\\sigma = \\sqrt{\\frac{.21}{100}} = .0458$. Thus, $k = \\frac{.1}{.0458} = 2.182$. Thus, \n\n\\begin{equation*}\n\\mathbb{P}_{A_{100}} = 1 - \\frac{1}{2.182^2} = .79 = 79\\%.\n\\end{equation*}\n\\end{tcolorbox}\n\n\\subsubsection*{Law of Large Numbers}\n\\noindent\n\\textbf{Theorem 8.2: Law of Large Numbers} Let $X_1, X_2, \\ldots, X_n$ be an independent trial process, with finite expected value $\\mu = \\expected{X_j}$, and finite variance $\\sigma = \\variance{X_j}$. Then for any $\\epsilon > 0$,\n\n\\begin{equation*}\n\\mathbb{P} \\Bigg ( \\Bigg \\lvert \\frac{S_n}{n} - \\mu \\Bigg \\rvert \\geq \\epsilon \\Bigg ) \\rightarrow 0\n\\end{equation*}\n\n\\noindent\nas $n \\rightarrow \\infty$. Equivalently,\n\n\\begin{equation*}\n\\mathbb{P} \\Bigg ( \\Bigg \\lvert \\frac{S_n}{n} - \\mu \\Bigg \\rvert < \\epsilon \\Bigg ) \\rightarrow 1\n\\end{equation*}\n\n\\noindent\nas $n \\rightarrow \\infty$. \n\n\\begin{center}\n\\includegraphics[width=13cm, height=10cm]{LLN_proof_pic}\n\\end{center}\n\n% https://www.youtube.com/watch?v=MntX3zWNWec\n\\noindent\nThe \\textbf{Law of Large Numbers} states that as the number of observations increases, the actual or observed probability approaches the theoretical or expected probabilities. \n\n\\vspace*{.3cm}\n\\noindent\n\\textbf{Weak Law of Large Numbers} vs. \\textbf{Strong Law of Large Numbers} \\\\\n\\noindent\nThe \\textbf{WLLN} says that for a large sample, there is a very high probability that the mean of the sample will be very close to the expected value, due to \\textit{weak convergence}. However, the probability of convergence is still very high.\n\n\\vspace*{.3cm}\n\\noindent\nThe \\textbf{SLLN} says that for a large sample, the mean of the sample will almost surely be the expected value, due to \\textit{strong convergence}. The proof of the \\textbf{SLLN} is much more complex and much harder to prove.\n\n\\begin{center}\n\\includegraphics[width=13cm, height=6cm]{DIE_ROLLING_EXAMPLE}\n\\end{center}\n\n\\noindent\nThere are exercises for \\textbf{LLN} on page $312$.\n\n% ================ SECTION 8.2 ================\n\n\\subsection*{Law of Large Numbers for Discrete Random Variables}\nThis law has a natural analogue for continuous probability distributions, which we consider somewhat more briefly here.\n\n\\subsubsection*{ChebyShev Inequality}\n\\noindent\n\\textbf{Theorem 8.3 (ChebyShev Inequality)} Let $X$ be a continuous random variable with density function $f(x)$. Suppose $X$ has a finite expected value $\\mu \\expected{X}$ and finite variance $\\variance{X} = \\sigma^2$. Then, for any positive number $\\epsilon > 0$ we have\n\n\\begin{equation*}\n\\prob{\\lvert X - \\mu \\rvert \\geq \\epsilon} \\leq \\frac{\\variance{X}}{\\epsilon^2}.\n\\end{equation*}\n\n\\noindent\nNote that this theorem says nothing if $\\variance{X} = \\sigma^2$ is infinite.\n\n\\subsubsection*{Law of Large Numbers}\n\\noindent\n\\textbf{Theorem 8.4: Law of Large Numbers} Let $X_1, X_2, \\ldots, X_n$ be an independent trial process with a continuous density function $f$, finite expected value $\\mu$, and finite variance $\\sigma^2$. Let $S_n = X_1, X_2, \\ldots, X_n$ be the sum of the $X_i$. Then for any real number $\\epsilon > 0$ we have\n\n\\begin{equation*}\n\\lim_{n \\rightarrow \\infty} \\mathbb{P} \\Bigg ( \\Bigg \\lvert \\frac{S_n}{n} - \\mu \\Bigg \\rvert \\geq \\epsilon \\Bigg ) = 0,\n\\end{equation*}\n\n\\noindent\nor equivalently,\n\n\\begin{equation*}\n\\lim_{n \\rightarrow \\infty} \\mathbb{P} \\Bigg ( \\Bigg \\lvert \\frac{S_n}{n} - \\mu \\Bigg \\rvert < \\epsilon \\Bigg ) = 1.\n\\end{equation*}\n\n\\noindent\nThere are exercises for \\textbf{LLN} on page $320$.\n\n% ========================================================\n% ========================================================\n\n\\section*{CHAPTER 9: Central Limit Theorem}\n\\subsubsection*{Central Limit Theorem for Bernoulli Trials}\n\\noindent\nThe second fundamental theorem of probability is the \\textit{Central Limit Theorem}. This theorem says that if Sn is the sum of n mutually independent random variables, then the distribution function of Sn is well-approximated by a certain type of continuous function known as a normal density function, which is given by the formula\n\n\\begin{equation*}\nf_{\\mu, \\sigma} = \\frac{1}{\\sqrt{2 \\pi} \\sigma} e^{-(x - \\mu)^2 / (2 \\sigma^2)}.\n\\end{equation*}\n\nIn this section, we will deal only with the case that $\\mu = 0$ and $\\sigma = 1$. We will call this particular normal density function the standard normal density, and we will denote it by $\\phi (x)$: \n\n\\begin{equation*}\n\\phi (x) = \\frac{1}{\\sqrt{2 \\pi}} e^{-x^2 / 2}.\n\\end{equation*}\n\n\\noindent\n\\textbf{Definition 9.1} The \\textit{standardized sum} of $S_n$ is given by \n\n\\begin{equation*}\nS_n^* = \\frac{S_n - np}{\\sqrt{npq}},\n\\end{equation*}\n\n\\noindent\nwhere $S_n^*$ has expected value $0$ and variance $1$.\n\n\\vspace*{.3cm}\n\\noindent\n\\textbf{Approximating Binomial Distributions}\n\\noindent\nWe can approximate a binomial distribution function as follows\n\n\\begin{align*}\nb(n,p,j) &\\sim \\frac{\\phi(x)}{\\sqrt{npq}} \\\\\n&= \\frac{1}{\\sqrt{npq}} \\phi \\Bigg ( \\frac{j - np}{\\sqrt{npq}} \\Bigg ).\n\\end{align*}\n\n\\noindent\nAn example of a situation where this can be used is when there are $100$ flips of a fair coin and we want to know the probability of seeing exactly $55$ heads.\n\n%\\begin{tcolorbox}\n%\\end{tcolorbox}\n\\end{document} ", "meta": {"hexsha": "c22a7e02da58fe1242c3da541c1bac1afd06d560", "size": 9706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "probability-theory/exam-review/final-exam/FINAL-REVIEW-NOTES.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/final-exam/FINAL-REVIEW-NOTES.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/final-exam/FINAL-REVIEW-NOTES.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": 39.9423868313, "max_line_length": 342, "alphanum_fraction": 0.6840098908, "num_tokens": 3148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.6297867101656013}}
{"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 -- Lec08}\n\\author{UCLA, Fall 2014}\n\\date{\\formatdate{28}{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{Quick note on higher dimensional Legendre Transform}\n\nHere we will have positions $\\v{x} \\in \\R^n$ and a convex function $f : \\R^n \\rightarrow R$, convex here meaning the Hessian $H_{ij} = \\partial_i \\partial_j f$ is positive definite, i.e. has positive determinant. Then we will define the function\n\\begin{eqn}\nF(\\v p, \\v x) = \\v{p} \\cdot \\v{x} - f(\\v x)\n\\end{eqn}\nand define the Legendre transform as\n\\begin{eqn}\n\\mathcal{L}f (\\v p) = \\sup_{\\v{x} \\in \\R^n} F(\\v p, \\v x).\n\\end{eqn}\nAgain we can write this as \n\\begin{eqn}\n\\mathcal{L}f(\\v p) = F(\\v p, \\v{x}(\\v p)),\n\\end{eqn}\nwhere $p_i = \\pd{f}{x_i}$ determines $\\v{x}(\\v p)$. \n\n\\begin{example}\nConsider the function \n\\begin{eqn}\nf(\\v x) = \\frac{1}{2} \\v{x}^\\top M \\v{x}\n\\end{eqn}\nwhere $M$ is a symmetric matrix. Then $\\v{x}(\\v p)$ is determined by \n\\begin{eqn}\n\\v p = M \\v{x} \\quad \\implies \\quad \\v{x}(\\v p) = M^{-1} \\v{p}.\n\\end{eqn}\nThen we find the Legendre transform\n\\begin{align}\n\\mathcal{L}f (\\v p) &= F(\\v p, \\v{x}(\\v p)) \\\\\n\t&= \\v{p} \\cdot \\v{x} - \\frac{1}{2} \\v{p}^\\top (M^\\top)^{-1} M M^{-1} \\v{p} \\\\\n\t&= \\frac{1}{2} \\v{p}^\\top M^{-1} \\v{p}.\n\\end{align}\n\\end{example}\n\n\n\\section{Hamiltonian formulation}\n\nEuler-Lagrange formulation gives us $n$ 2nd order differential equations, which can be a bit of a mess. In the Hamiltonian formulation, they are replaced by $2n$ 1st order differential equations,\n\\begin{eqn}\n\\dot{p}_i = -\\pd{H}{q_i}, \\qquad \\dot{q}_i = \\pd{H}{p_i},\n\\end{eqn}\nwhere\n\\begin{eqn}\nH(\\v q, \\v p, t) = \\sum_i p_i \\dot{q}_i - L(\\v q, \\vd q, t)\n\\end{eqn}\nis the Legendre transform of $L$ with respect to $\\dot{q}_i$, i.e. $\\dot{q}_i(p)$ is determined by $p_i = \\pd{L}{\\dot{q}_i}$. \n\n\\begin{proof}\nLooking at the differential of $H$, we have\n\\begin{align}\n\\dif H &= \\sum_i \\pd{H}{p_i} \\dif{p_i} + \\sum_i \\pd{H}{q_i} \\dif{q_i} + \\pd{H}{t} \\dif{t} \\\\\n\t&= \\dot{q}_i \\dif{p_i} + \\cancel{p_i \\dif{\\dot{q}_i}} - \\pd{L}{q_i} \\dif{q_i} - \\cancel{\\pd{L}{q_i} \\dif{q_i}} - \\pd{L}{t} \\dif{t},\n\\end{align}\nso equating the differentials, we see that \n\\begin{eqn}\n\\dot{p}_i = -\\pd{H}{q_i}, \\qquad \\dot{q}_i = \\pd{H}{p_i}, \\qquad \\pd{H}{t} = -\\pd{L}{t}.\n\\end{eqn}\nThe last term of course is only important when there is explicit time dependence, but it is trivially true by definition. \n\\end{proof}\n\n\\begin{example}[1-dim. particle in potential]\nConsider the Lagrangian\n\\begin{eqn}\nL = \\frac{1}{2} m \\dot{q}^2 - V(q),\n\\end{eqn}\nthen we find $p = m \\dot{q}$, so that \n\\begin{align}\nH = p \\dot{q} - L &= \\frac{p^2}{m} - \\frac{1}{2m} p^2 + V(q) \\\\\n\t&= \\frac{p^2}{2m} + V(q).\n\\end{align}\nThus $H$ is just the energy. \n\\end{example}\n\n\\begin{example}[System of particles]\nConsider the Lagrangian\n\\begin{eqn}\nL = \\frac{1}{2} \\sum_{ij} M_{ij}(q) \\dot{q}^i \\dot{q}^j - V(q),\n\\end{eqn}\nthen we have momentum $p_i = \\sum_j M_{ij} \\dot{q}^j$ and\n\\begin{eqn}\nH(p,q) = \\frac{1}{2} \\sum_{ij} M_{ij}^{-1} p^i p^j + V(q).\n\\end{eqn}\n\\end{example}\n\nThis is simple for diagonal $M$s, for example given Lagrangian\n\\begin{eqn}\nL = \\frac{1}{2} m (r^2 + r^2 \\theta^2 + r^2 \\sin^2 \\theta \\, \\dot{\\phi}^2 ) - V(r,\\theta,\\phi),\n\\end{eqn}\nwe have\n\\begin{eqn}\nH = \\frac{1}{2m} \\left( p_r^2 + \\frac{1}{r^2} p_\\theta^2 + \\frac{1}{r^2 \\sin^2 \\theta} p_\\phi^2 \\right) + V(r,\\theta,\\phi).\n\\end{eqn}\nWe must be more careful if there are terms like $N_i (q) \\dot{q}^i$ in the Lagrangian, because then $p_i = \\pd{L}{\\dot{q}_i}$ will pick up a $N_i(q)$ term. \n\n\\begin{example}[particle in EM field]\nConsider the Lagrangian\n\\begin{eqn}\nL = \\frac{1}{2} m \\vd{x}^2 - e \\phi(\\v x) + e \\vd{x} \\cdot \\v{A}(\\v x).\n\\end{eqn}\nThen \n\\begin{eqn}\n\\v p = m \\vd{x} + e \\v{A}(\\v x) \\qquad \\implies \\qquad \\vd{x} = \\frac{1}{m} (\\v{p} - e \\v{A}),\n\\end{eqn}\nwhich results in a Hamiltonian (check this)\n\\begin{eqn}\nH = \\frac{1}{2m} (\\v{p} - e \\v{A})^2 + e \\phi(\\v x).\n\\end{eqn}\nThis is interesting because we have a first order term in the Lagrangian ending up squared in the Hamiltonian.\n\\end{example}\n\n\n\\subsection{Why Hamiltonian formalism?}\n\nWe will see that the classical Hamiltonian formalism gives us a close correspondence to quantum mechanics. It turns out that many interesting calculations are the same or almost the same, to some order, in both quantum and classical mechanics when we use the Hamiltonian formulation along with the appropriate language. \n\nIn the Lagrangian formalism, our canonical variables are the coordinates $\\v{q}(t)$. The trajectory in $q$-space can intersect itself because the trajectory also depends on $\\vd{q}(t)$. On the other hand, in the Hamiltonian formalism, our canonical variables are the coordinates $\\v q, \\v p$ and in $qp$-space trajectories cannot intersect themselves because the flow is uniquely determined by $\\v q(t), \\v p(t)$. \n\nThe space of all $\\set{\\v q, \\v p}$ is called the \\textit{phase space} of the Hamiltonian system. This gives us a special kind of geometry called \\textit{symplectic geometry}. In quantum mechanics, we will see that, crudely speaking, the phase space has fundamental cells of volume $\\hbar^3$. The phase space here is analogous to the phase space in kinetic theory, where a system of $N$ particles in $\\R^3$ is $6N$-dimensional. \n\nWe can also make more general coordinate changes in phase space---these are called \\textit{canonical transformations}. Furthermore, Hamiltonian systems have the nice property of \\textit{integrability} (i.e. action angle variable). Later, the Hamiltonian formulation will lead us to the \\textit{Hamilton-Jacobi} formulation, which is very nice. \n\n\n\\subsection{Variational principle for Hamilton equations}\n\nLooking at the action in the Hamiltonian formalism, we have\n\\begin{eqn}\nS[q(t), p(t)] = \\int \\dif{t} \\left[ \\dot{q} p - H(q,p) \\right],\n\\end{eqn}\nand taking the variation we find\n\\begin{align}\n\\delta{S} &= \\int \\dif{t} \\left[ p \\delta{\\dot q} + \\dot{q} \\delta{p} - \\pd{H}{q} \\delta{q} - \\pd{H}{p} \\delta{p} \\right] \\\\\n\t&= \\int \\dif{t} \\left[ (-\\dot{p} - \\pd{H}{q}) \\delta{q} + (\\dot{q} - \\pd{H}{p}) \\delta{p} \\right] + \\eval[3]{(p \\delta{q})}_{t_1}^{t_2}.\n\\end{align}\nWe see that the boundary term vanishes under the action principle assumption that $\\delta{q}(t_1) = \\delta{q}(t_2) = 0$, and furthermore demanding that the variation vanishes gives us Hamilton's equations. \n\n\n\\subsection{Conservation and preservation}\n\n\\begin{remark}[Simple conservation laws]\nTaking the total time derivative we have\n\\begin{eqn}\n\\od{H}{t} = \\pd{H}{q} \\dot{q} + \\pd{H}{p} \\dot{p} + \\pd{H}{t} = -\\cancel{\\dot{p} \\dot{q}} + \\cancel{\\dot{q} \\dot{p}} + \\pd{H}{t}\n\\end{eqn}\n[???] where $\\pd{H}{t} = -\\pd{L}{t}$ so if there is no time dependence then $H$ is conserved. \n\nFurthermore, if $q_i$ is a cyclic variable then the canonical momentum $p_i$ is conserved, since\n\\begin{eqn}\n\\pd{L}{q_i} = 0 \\qquad \\implies \\qquad \\dot{p}_i = \\pd{H}{q_i} = 0.\n\\end{eqn}\n\\end{remark}\n\nNext we'll look at Liouville's theorem. We can motivate this by looking at a harmonic oscillator. If we plot trajectories of the SHO in phase space, i.e. a plot of $p$ vs $q$, the trajectories are ALL simply circles around the origin. In this case it is easy to see that if we take a volume in phase space and flow it along the Hamiltonian trajectories, the volume is simply rotated about the origin---thus the volume is preserved. It turns out that this is true for all Hamiltonian systems.\n\n\\begin{theorem}[Liouville's theorem]\nThe Hamiltonian flow is volume-preserving. In other words, if we denote the flow on phase space $\\Phi_t(\\v q, \\v p) = (\\v{q}(t), \\v{p}(t))$, and we have a volume $V \\subseteq \\set{\\text{phase space}}$ then \n\\begin{eqn}\n\\od{\\Phi_t(V)}{t} = 0 \\qquad \\implies \\qquad \\Phi_t(V) = V \\quad \\text{for all $t$}.\n\\end{eqn}\n\\end{theorem}\n\n\\begin{proof}\n\n[continued in next lecture]\n\\end{proof}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "e9f59ad51d1afc117363e783ee956f2545154dfc", "size": 8185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classical/lec08.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/lec08.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/lec08.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": 44.2432432432, "max_line_length": 491, "alphanum_fraction": 0.6690287111, "num_tokens": 2927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6297043310919525}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\chapter{Introduction to Combinatorics}\n\nIn discrete optimization, some or all of the variables in a model are required to belong to a discrete set; \nthis is in contrast to continuous optimization in which the variables are allowed to take on any value within a range of values. \nThere are two branches of discrete optimization: integer programming and  combinatorial optimization where the discrete set is a set of objects, \nor combinatorial structures, such as assignments, combinations, routes, schedules, or sequences. \nCombinatorial optimization is the process of searching for maxima (or minima) of an objective function $F$ whose domain is a discrete but \nlarge configuration space (as opposed to an N-dimensional continuous space).  Typical combinatorial optimization problems are the travelling \nsalesman problem (``TSP''), the minimum spanning tree problem (``MST''), and the knapsack problem.  \nWe start with basic combinatorics which is able to enumerate the all solutions exhaustively. \nLater on, other chapters we will dive into different combinatorial/disrete optimization problems.\n\n%https://www.cs.cmu.edu/afs/cs.cmu.edu/project/learn-43/lib/photoz/.g/web/glossary/comb.html\n%https://en.wikipedia.org/wiki/Combinatorial_optimization\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%Combinatorics%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nCombinatorics, as a branch in mathematics that  mainly concerns with counting and enumerating, is a means in obtaining results, and certain properties of finite structures. Combinatorics is used frequently in computer science to obtain formulas and estimates in both the design and analysis of algorithms.  It is a broad and thus seemingly hard to define topic that can solve the following types of questions:\n\\begin{itemize}\n    \\item  The counting or enumerating  of specified structures, sometimes referred to as arrangements or \n    configurations in a very general sense, associated with finite systems,\n    \\item the existence of such structures that satisfy certain given criteria, \n    this is usually called Contraint Restricted Problems (CSPs).\n    \\item optimization, finding the ``best'' structure or solution among several possibilities, \n    be it the ``largest'',``smallest'' or satisfying some other optimality criterion.\n\\end{itemize}\nIn this section, we introduce common combinatorics that can help us come up with the simplest which potentially be quite large state space. At least, this is the first step, and solving a small problem in this way might offer us more insights on continuing finding a better solution.  \n\nWhen the situation is easy, we can mostly figure out the counting with some logic and get a closed-form solution; when the situation is more complex such as in the \\textit{partition} section, we detour by using recurrence relation and math induction. \n\\section{Permutation}\nGiven a list of integer $[1,2,3]$, how many way can we order these three numbers? Imagine that we have three positions for these three integers.  For the first position, it can choose 3 integers, leaving the second position with 2 options. Further, when it reaches to the last position, it can only choose whatever that is left, we have 1. The total count will be $3\\times2\\times1$. \n\nSimilarly, for $n$ distinct numbers,  we will get the number of permutation  easily as $n\\times(n-1)\\times...\\times1$. A factorial, denoted as as $n!$, is used to abbreviate it. Worth to notice, the factorial sequence grows even quicker than the exponential sequence, such as $2^n$. \n\n\\subsection{$n$ Things in $m$ positions}  Permutation of $n$ things on $n$ positions is denoted as $p(n,n)$. Think about what if we have $m\\in[1, n-1]$ positions instead? How to get a closed-form function for  $p(n,m)$.  The process is the same: we fix each position and consider the number of choice of things each one has. \n\\begin{align}\n   p(n,m) &= n\\times(n-1)\\times...\\times (n-(m-1)) \\\\\n   &=\\frac{n\\times(n-1)\\times...\\times (n-m+1)\\times (n-m)\\times...\\times 1}{(n-m)\\times...\\times 1}\\\\\n   &=\\frac{n!}{(n-m)!}\n\\end{align}\nIf we want $p(n,n)$ to follow the same form, it would require us to define $0!=1$.\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{What if there are repeated things, that things are not distinct? } \n\\end{bclogo}\n% \\paragraph{What if things are not distinct?} For example, how to get the permutation of [1,2,2,3]. \n\n\\subsection{Recurrence Relation and Math Induction} The number or the full set of permuations can be generated incrementally. We demonstrate how with recurrence relation and math induction. We start from $P(0,0)=1$. Easily, we get $P(i, 0)=1, i\\in[1, n]$. With math induction, now assume we know $P(n-1, m-1)$, for the m-th position, what choice does it have? First, we need to pick this thing from the $n-(m-1)$ things. Then,  we have $m-1$ things lined up linearly, there are $m$ positions to insert the m-th item, resulting $P(n, m) = (n-m+1)*mP(n-1, m-1)$.\n\nNow, we can use iterative method to obtain the closed-form solution:\n\\begin{align}\n    P(n, m) &= (n-m+1)*m*P(n-1, m-1)\\\\\n    &=(n-m+1)*m*(P(n-2, m-2) \\\\\n    &...\\\\\n    &=m!P(n-m+1, 1\n\\end{align}\n\n\\subsection{See Permutation in Problems} Suppose we want to sort an array of integers incrementally, say the array is $A=[4,8,2]$. The right order is $[2,4,8]$, which is trivial to obtain in this case. If we are about to form it as a search problem, we need to define a \\textit{search space}. Using our knowledge in combinatorics, we know all possible ordering of these numbers are [4,8,2],[4,2,8],[2,4,8],[2,8,4],[8,2,4],[8,4,2]. Generating all possible ordering and save it in an array maybe. Then this sorting problem is converted into checking which array is incrementally sorted. However, it comes with large price on space usage, since for $n$ numbers there, the number of possible orderings are $n!$. A smarter way to do it is to check the ordering as we are generating the ordering set.\n\n% Another problem is the one we mentioned, the subarray sum problem. The subarray if be represented as $a_{i,j}$, it is like we need to select two $n$ items and put them at two positions: $i$ and $j$. For position $i$ we have $n$ options, for $j$, there is only\n\\section{Combination}\n%\\paragraph{Problem Definition}\nSame as before, we have to choose $m$ things out of $n$ but with one difference--the order does not matter, how many ways we have?  This problem is called \\textbf{combination}, and it is denoted as $C(n,m)$. For example, for [1,2,3], $C(3, 2)=[1, 2], [2, 3], [1, 3]$. Comparatively, P(3, 2) = [1, 2], [2, 1], [2, 3], [3, 2], [1, 3], [3, 1]. \n\nTo get combination, we can leverage and apply permutation first. However, this results over-counting. As shown in our example, when there are two things in the combination, a permutation would double count it. If there are $m$ things, we over count by $m!$ times. Therefore, if we  divide the permutation by all permutation of $m$ things, we get out formula for combination:\n\\begin{align}\n    C(n,m)&=\\frac{P(n,m)}{P(m,m)}\\\\\n    &=\\frac{n!}{(n-m)!m!}\n\\end{align}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Back to the last question, when there are repeats in the permutation. We can use the same idea. Assume we have $n,m$ that $n$ things in total but only $m$ types and $a_i, i\\in[1,m]$ to denote the number of each type, this means $a_1+ a_2+ ... + a_m= n$. The number of ways to linearly order these objects is $\\frac{n!}{a_1!a_2!...a_m!}$. } \n\\end{bclogo}\n\n\nThe combination of k things out of n, will be the same as choosing (n-k) things.\n    \\begin{align}\n        C(n,k)=C(n, n-k)\n    \\end{align}\n\n\\subsection{Recurrence Relation and Math Induction} We also show how the combination can be generated incrementally. We start from $C(0,0)=1$, and easily we get $C(n, 0)=1$. Assume we know $C(n-1, k-1)$, now we need to add the k-th item into the combination? :\n\\begin{itemize}\n    \\item Use k-th item, then we just need to put the the k-th item into any sets in $C(n-1,k-1)$, resulting $C(n-1,k-1)$.\n    \\item Not use k-th item, this means we need to pick $k$ items from the other $n-1$ items, resulting $C(n-1,k)$. \n\\end{itemize}\nThus, we have $C(n, k) = C(n-1, k-1) + C(n-1, k)$, this is called \\textbf{Pascal's Identity}. \n\n\\paragraph{What if things are not distinct?}\n\n%%%%%%%%%%%%%%%%%%Partition%%%%%%%%%%%%%%%\n\\section{Partition}\nWe discuss three types of partitions: (1) integer partition, (2) set partition, and (3) array partition. In this section, counting becomes less obvious compared with combination and permutation, this is where we rely more on \\textbf{recurrence relation} and \\textbf{math induction}. \n\n% {14, 23},{1, 234},{1, 23, 4},{14,2,3},{1,24,3},{1,2,34}, and {1,2,3,4} for parts from 1 to 4. Vetex or edge coloring, and connected components are one of the set partition examples. Set partition is actually a combination problem. We will show how we can do set parititon with backtrack and dynamic programming sometimes.\n\n\\subsection{Integer Partition}\n\\paragraph{Integer Partition Definition} Integer partitions is to partition a given integer $n$ into distinct subsets that add up to $n$. \n\\begin{lstlisting}[numbers=none]\nFor example, given n=5, the resulting partitioned subsets are these 7 subsets: \n{5}\n{4, 1},\n{3, 2}\n{3, 1, 1},\n{2, 2, 1},  \n{2, 1, 1, 1}, \n{1, 1, 1, 1, 1}\n\\end{lstlisting}\n\n\\paragraph{Analysis} Let us assume the resulting sequence is $(a_1, a_2, ..., a_k)$, and $ a_1\\geq a_2\\geq...\\geq a_k\\geq 1$, and  $a_1+ a_2+ ... + a_k= n$. The ordering is simply to help us to track the sequence.  We use \n\nThe easiest way to generate integer partition is to construct them incrementally. We first start from the partition of {n}. For n=5, we get {5} first. Then we subtract one from the largest item that is larger than 1, and add it to the smallest item if it exists and that the resulting s+1 < l, s < l-1 , and other option is to put it aside.  For {5}, there is no other item, so that it becomes {4, 1}. For {4,1}, following the same rule, we get {3, 2},  for {3, 2}, we get {3,1,1}.\n\\begin{lstlisting}\n{5}, no other smaller item, put it aside\n{4, 1}, satisfy s<l-1, become{3,2}\n{3, 2}, not satisfy s<l-1, put it aside\n{3, 1, 1}, satisfy s<l-1, add it to\n    {2, 2, 1}, not satisfy, put it aside\n    {2, 1, 1, 1}, not satisfy, put it aside\n{1, 1, 1, 1, 1}\n\\end{lstlisting}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{Try to generate the partition when n=6.} \n\\end{bclogo}\nIf we draw out the transfer graph, we can see a lot of overlapping of some state. Therefore, we add one more limitation on the condition, s>1. \n\n\n\n\\subsection{Set Partition}\n\\paragraph{Set Partition Problem Definition} How many ways exist to partition a set of $n$ distinct items ${a_1, a_2, ..., a_n}$ into $k$ nonempty subsets, $k<=n$.\n\\begin{lstlisting}[numbers=none]\nHere are 7 ways that we can partition the set {a1, a2, a3,a4} into 2 nonempty subsets. They are\n{a1}, {a2,a3,a4}; \n{a2}, {a1,a3,a4}; \n{a3}, {a1, a2, a4};  \n{a4}, {a1, a2, a3}\n{a1, a2}, {a3, a4}; \n{a1, a3}, {a2, a4}; \n{a1, a4}, {a2, a3};\n\\end{lstlisting}\nLet us denote the total ways as $s(n,k)$. As seen in the example, given 2 groups and 4 items, there are two combination of each group's size: 1+3 and 2+2. For combination {1,3}, this is equivalent to choose one item from the set to put at the first subset $C(n,1)$, and then choose 3  items for the other subset $C(3, 3)$. For combination {2, 2}, we have $C(4,2)$ for one subset and $C(2,2)$ for the other subset. However, because the ordering of the subsets does not matter, we need to divide it by $2!$. The set partition problem thus consists of two steps:\n\\begin{itemize}\n    \\item Partition $n$ into $k$ integers: This subrountine can be solved with integer partition we just learned. We have $b_1+b_2+...+b_k = n$.\n    \\item For each combination of integer partition, we compute the number of ways choosing  $b_i$ items for that set, we get $C(n, b_1)\\times C(n-b_1, b_2)\\times C(n-b_1-b_2, b_3)\\times...\\times C(b_k, b_k)$. Now, we find the distinct $b_i$ and its number of appearance in the sequence. If we have $m$ distinct number denoted as $b_i$, and its  count $c_i$, then we divide the above ways by $c_1!c_2!...c_m!$.\n\\end{itemize}\n\nFrom this solution, it is hard to get a closed form for $s(n,k)$.\n\n\n\n\n\n\\paragraph{Find Recurrence Relation} There is just one way to handle this problem, let us try the incremental method--find a recurrence relation. We first start with $s(0, 0)=0$, and we can also easily get $s(n,0)=0$. Now, with the mathematical induction, we assume we solved a subproblem, say $s(n-1, k-1)$, can we induce $s(n,k)$? What do we need? \n\nNow we have n-1 items in k-1 groups, now there is one addition group and one additional item. There are two ways:\n\\begin{itemize}\n    \\item put the additional item into the additional group. In this way, $s(n,k)$ is simply the same as of $s(n-1,k-1)$.\n    \\item spread the n-1 items from the original k-1 groups into k groups, that is $s(n-1, k)$ and our additional item has k options now, making $k\\times s(n-1,k)$ in total\n\\end{itemize}\nCombing together the count of these two ways, we get a recurrence relation that\n\\begin{align}\n    s(n,k)=s(n-1,k-1)+k s(n-1,k)\n\\end{align}\n\n\\section{Array Partition}\n\\paragraph{Problem Definition} How many ways exist to partition an array of $n$ items ${a_1, a_2, ..., a_n}$ into subarrays. There are different subtypes depending on the number of subarrays, say $m$:\n\\begin{enumerate}\n    \\item When the number $m$ is as flexible as $m\\in[1, n-1]$.\n    \\item When the number $m$ is fixed as a number in range $[2, n-1]$.\n\\end{enumerate}\n\n\\paragraph{When the number of subarray is fixed} For example, it is common to partition an array into 2 or 3 subarrays. First, we find an item $a_i$ as a  partition point,  getting the last subarray $a[i:n]$ and left an array to further consider $a[0:i]$. If $m=2$, $a[0:i]$ results the first subarray and the partition process is done. This gives out $n$ ways of parition. When $m=3$, we need to further partition $a[0:i]$ into two parts. This can be represented with recurrence relation:\n\\begin{align}\n    d(n, m) = (d(i, m-1), a[i:n]), i \\in[0, n-1]\n\\end{align}\nFurther, for $d(i, m-1)$:\n\\begin{align}\n    d(i, m-1) = (d(j, m-2), a[j:n]), j \\in[0, i-1]\n\\end{align}\nThis can be done recursively: we will have a recursive function with depth $m$.\n\n\\paragraph{When the number of subarray is flexible} The process is the same other than $m$ can be as large as $n-1$. If we are about to use dynamic programming, for all these states, we need to come up with an ordering of the state $(i, j)$, where $i$ is the subproblem $a[0:i]$, and $j$ is the number of partitions. We imagine it as a matrix with $i, j$ as row and column respectively:\n\\begin{lstlisting}[numbers=none]\n   0  1  2     n-1: partition\n0  X  -  -    - \n1  X  X  -   -\n2  X  X  X \n\nn-1\nn X  X  X   X  X \n\\end{lstlisting}\nDoes the ordering of the \\texttt{for} loop matter? Actually it does not. \n\n\\paragraph{Applications} There are many applications that involve splitting an array/string or cutting a rod.  This relates to spliting type of dynamic programming.\n\n\\section{Merge}\n\n\n\\section{More Combinatorics}\nCombinatorics is about enuemrating specified structures, there are some structures are of our main interests through this book and often appears in the interviews, they are: \\textit{subarray}, \\textit{subsequence}, and \\textit{subsets}.\n\\paragraph{Subarray} We have solved one example with subarray. Subarray is defined as a contigious sequence in the array, which can be represented as $a[i,...,j]$. The number of subarray exist in an array of size $n$ will be:\n\\begin{align}\n    sa=\\sum_{i=1}^{i=n} i = n*(n+1)/2\n\\end{align}\nA substring is a contiguous sequence of characters within a string. For instance, \"the best of\" is a substring of \"It was the best of times\". This is not to be confused with subsequence, which is a generalization of substring. For example, \"Itwastimes\" is a subsequence of \"It was the best of times\", but not a substring.\n\nPrefix and suffix are special cases of substring. A prefix of a string S S is a substring of S that occurs at the beginning of  S. A suffix of a string S is a substring that occurs at the end of S. \n\\paragraph{Subsequence} For a subsequence means any sequence we can find the array, which is not required to be contiguous, but the ordering still matters. For example, in the array of [ABCD], the subsequence will be\n\\begin{lstlisting}\n               [],\n[A],    [B], [C],[D],\n[AB],[AC],[AD],  [BC],[BD],  [CD],\n[ABC],[ABD], [ACD],  [BCD],\n[ABCD]\n\\end{lstlisting}\nYou would actually see for $n=4$, there are 16 possible subsequence, which is $2^4$. This is not coincidence. Imagine for each item in the array, they have two options, either be chosen into the possible sequence or not chosen, which make it to $2^n$. \n\\begin{align}\n    ss=2^n\n\\end{align}\n\\paragraph{Subset} The Subset B of a set A is defined as a set within all elements of this subset are from set A. In other words, the subset B is contained inside the set A, $B \\in A$. There are two kinds of subsets: if the order of the subset does'nt matter, it is a combination problem, otherwise, it is a permutation problem. \n\nIf it is the case that ordering does not matter, for $n$ distinct things, the number of possible subsets, also called \\textit{the power set} will be:\n\\begin{align}\n    power_set = C(n,0)+C(n,1)+...+C(n,n)\n\\end{align}\n\n\n\n\n\\end{document}", "meta": {"hexsha": "4fa4b940eeb60a1abc158e0ca06bed95899abf29", "size": 17533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/chapter_combinatorics.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_combinatorics.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_combinatorics.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": 77.5796460177, "max_line_length": 794, "alphanum_fraction": 0.7139109109, "num_tokens": 5144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.6297043214009488}}
{"text": "\\section{Cylindrical Coordinates}\r\n\\noindent\r\nCylindrical coordinates are the expansion of polar coordinates by including a third term that represents the height from the xy-plane, $z$. All cylindrical coordinates have the form $(r, \\theta, z)$. This system is called cylindrical because it’s easy to describe shapes with cylindrical symmetry because integrations have constant, independent bounds.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\input{./curvilinearCoordinates/conversions_cylindrical}\r\n\\input{./curvilinearCoordinates/integration_cylindrical}", "meta": {"hexsha": "c50167aabef1178fdbc4be001df7769663e8022c", "size": 534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/curvilinearCoordinates/cylindricalCoordinates.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/cylindricalCoordinates.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/cylindricalCoordinates.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.75, "max_line_length": 353, "alphanum_fraction": 0.8146067416, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6297043047485357}}
{"text": "\\chapter{Data Sets}\n\\label{appendix:data_sets}\n\nAll of the data sets used are defined such that the dependent variable is the output of a particular mathematical function for a given set of inputs.  They are taken from a paper entitled \\textit{Genetic Programming Needs Better Benchmarks} by McDermott et al. \\cite{benchmarks}  All of the inputs are taken to form a grid on some interval.  Let $E[a, b, c]$ denote $c$ samples equally spaced in the interval $[a,b]$. (Note that McDermott et al. defines $E[a, b, c]$ slightly differently.)  Below is a list of all of the data sets that are used:\n\n\\begin{enumerate}[noitemsep]\n\\item \\textbf{Keijzer1}: $0.3x \\sin(2 \\pi x);$ $x \\in E[-1,1,20]$\n\\item \\textbf{Keijzer11}: $x y+\\sin((x-1)(y-1));$ $x, y \\in E[-3,3,5]$\n\\item \\textbf{Keijzer12}: $x^{4}-x^{3}+\\frac{y^{2}}{2}-y;$ $x, y \\in E[-3,3,5]$\n\\item \\textbf{Keijzer13}: $6 \\sin(x) \\cos(y);$ $x, y \\in E[-3,3,5]$\n\\item \\textbf{Keijzer14}: $\\frac{8}{2 + x^{2} + y^{2}};$ $x,y \\in E[-3,3,5]$\n\\item \\textbf{Keijzer15}: $\\frac{x^{3}}{5} - \\frac{y^{3}}{2} - y - x;$ $x, y \\in E[-3,3,5]$\n\\item \\textbf{Keijzer4}: $x^{3} e^{-x} \\cos(x) \\sin(x) (\\sin^{2}(x) \\cos(x) - 1);$ $x \\in E[0,10,20]$\n\\item \\textbf{Keijzer5}: $\\frac{3 x z}{(x - 10) y^{2}};$ $x,y \\in E[-1,1,4]; z \\in E[1,2,4]$\n\\item \\textbf{Nguyen10}: $2 \\sin(x) \\cos(y);$ $x,y \\in E[0,1,5]$\n\\item \\textbf{Nguyen12}: $x^{4} - x^{3} + \\frac{y^{2}}{2} - y;$ $x,y \\in E[0,1,5]$\n\\item \\textbf{Nguyen3}: $x^{5} + x^{4} + x^{3} + x^{2} + x;$ $x \\in E[-1,1,20]$\n\\item \\textbf{Nguyen4}: $x^{6} + x^{5} + x^{4} + x^{3} + x^{2} + x;$ $x \\in E[-1,1,20]$\n\\item \\textbf{Nguyen5}: $\\sin(x^{2}) \\cos(x) - 1;$ $x \\in E[-1,1,20]$\n\\item \\textbf{Nguyen6}: $\\sin(x) + \\sin(x + x^{2});$ $x \\in E[-1,1,20]$\n\\item \\textbf{Nguyen7}: $\\ln(x + 1) + \\ln(x^{2} + 1);$ $x \\in E[0,2,20]$\n\\item \\textbf{Nguyen9}: $\\sin(x) + \\sin(y^{2});$ $x,y \\in E[0,1,5]$\n\\item \\textbf{Sext}: $x^{6} - 2 x^{4} + x^{2};$ $x \\in E[-1,1,20]$\n\\end{enumerate}", "meta": {"hexsha": "626856bf9350755e2335b808d6730ff0b77024c2", "size": 1954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/thesis/data_sets.tex", "max_stars_repo_name": "flexgp/BehavioralGP", "max_stars_repo_head_hexsha": "14cdb7dc2c1343a6405289ca2b046f01b4746d9b", "max_stars_repo_licenses": ["MIT"], "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/thesis/data_sets.tex", "max_issues_repo_name": "flexgp/BehavioralGP", "max_issues_repo_head_hexsha": "14cdb7dc2c1343a6405289ca2b046f01b4746d9b", "max_issues_repo_licenses": ["MIT"], "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/data_sets.tex", "max_forks_repo_name": "flexgp/BehavioralGP", "max_forks_repo_head_hexsha": "14cdb7dc2c1343a6405289ca2b046f01b4746d9b", "max_forks_repo_licenses": ["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.4166666667, "max_line_length": 545, "alphanum_fraction": 0.5716479017, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6296412318149277}}
{"text": "\\section{Optimization of Surrogates on Sparse Grids}\n\\label{sec:52method}\n\n\\minitoc{72mm}{5}\n\n\\noindent\nThe methods presented in the last section can be combined to a\n``meta-method'' for surrogate optimization.\nThe surrogates are constructed as interpolants on spatially adaptive\nsparse grids, which we explain in the following.\n\n\n\n\\subsection{Novak--Ritter Adaptivity Criterion}\n\\label{sec:521novakRitter}\n\nThe classic surplus-based refinement strategy for\nspatially adaptive sparse grids is not tailored to optimization,\nas this refinement strategy aims to minimize the overall $\\Ltwo$ error.\nHowever, in optimization, it is reasonable to generate more\npoints in regions where we suspect the global minimum to be\nto increase the interpolant's accuracy in these regions.\nHence, we employ an adaptivity criterion proposed by\nNovak and Ritter \\cite{Novak96Global} for hyperbolic cross points.\nThe Novak--Ritter criterion has also been applied to sparse grids\n\\multicite{Ferenczi05Globale,Valentin14Hierarchische,Valentin16Hierarchical}.\n\n\\paragraph{$m$-th order children}\n\nAs usual, the criterion works iteratively:\nStarting with an initial regular sparse grid of a very coarse level,\nthe criterion selects a specific point $\\gp{\\*l,\\*i}$ in each iteration\nand inserts all its children into the grid.\nThis process is repeated until a given number $\\ngpMax$ of grid points is\nreached,\nsince we evaluate $\\objfun$ at every grid point once, and we assume that\nfunction evaluations dominate the overall complexity.\nThe difference to common refinement criteria is that\na point may be selected multiple times, in which case\n\\term{higher-order children} are inserted.\nThe $m$-th order children $\\gp{\\*l',\\*i'}$ of a grid point $\\gp{\\*l,\\*i}$\nsatisfy\n\\begin{equation}\n  \\label{eq:indirectChild}\n  \\*l'_{-t} = \\*l^{}_{-t},\\;\\,\n  \\*i'_{-t} = \\*i^{}_{-t},\\;\\,\n  l'_t = l^{}_t + m,\\;\\,\n  i'_t \\in\n  \\begin{cases}\n    \\{1\\},&(l_t = 0) \\land (i_t = 0),\\\\\n    \\{2^m - 1\\},&(l_t = 0) \\land (i_t = 1),\\\\\n    \\{2^m i_t - 1,\\, 2^m i_t + 1\\},&\\hphantom{(}l_t > 0,\n  \\end{cases}\n\\end{equation}\nwhere $m \\in \\nat$ and $t \\in \\{1, \\dotsc, d\\}$\n(cf.\\ \\cref{eq:directAncestor} for $m = 1$).\nThe order is chosen individually for each child point to be inserted\nas the lowest number $m$ such that $\\gp{\\*l',\\*i'}$ does not yet exist\nin the grid.\n\n%\\todo{add figure for m-th order children?}\n\n\\paragraph{Criterion}\n\nThe Novak--Ritter refinement criterion \\cite{Novak96Global}\nrefines the grid point $\\gp{\\*l,\\*i}$ that minimizes the product%\n\\footnote{%\n  Compared to \\cite{Novak96Global},\n  we added one in the base of each factor to avoid ambiguities\n  for $0^0$.\n  In addition, we swapped $\\gamma$ with $1-\\gamma$\n  to make $\\gamma$ more consistent with its name as adaptivity.%\n}\n\\begin{equation}\n  (r_{\\*l,\\*i} + 1)^\\gamma \\cdot\n  (\\normone{\\*l} + d_{\\*l,\\*i} + 1)^{1 - \\gamma}.\n\\end{equation}\nHere, $r_{\\*l,\\*i} \\ceq \\setsize{\n  \\{(\\*l',\\*i') \\in \\liset \\mid\n  \\objfun(\\gp{\\*l',\\*i'}) \\le \\objfun(\\gp{\\*l,\\*i})\\}\n} \\in \\{1, \\dotsc, \\setsize{\\liset}\\}$ is the \\term{rank} of $\\gp{\\*l,\\*i}$\n(where $\\liset$ is the current set of level-index pairs of the grid), i.e.,\nthe place of the function value at $\\gp{\\*l,\\*i}$\nin the ascending order of the function values at all points\nof the current grid.\nWe denote the \\term{degree} $d_{\\*l,\\*i} \\in \\natz$ of $\\gp{\\*l,\\*i}$\nas the number of previous refinements of this point.\nFinally, $\\gamma \\in \\clint{0, 1}$ is the \\term{adaptivity parameter.}\n%By choosing $\\gamma = 0$, the function values become irrelevant and the\n%criterion produces regular-like sparse grids.\n%If we choose $\\gamma = 1$, then the criterion always refines the point with\n%the lowest function value, which means that the criterion is easily stuck\n%in local minima.\nWe have to choose a suitable compromise between exploration ($\\gamma = 0$)\nand exploitation ($\\gamma = 1$).\nThe best choice of course depends on the objective function $\\objfun$ at hand,\nbut for our purposes, we choose a priori a value of $\\gamma = 0.15$.\nHowever, it may be an option to adapt the value of $\\gamma$ automatically\nduring the grid generation phase.\n\n\n\n\\subsection{Global Optimization of Sparse Grid Surrogates}\n\\label{sec:522method}\n\n\\paragraph{Global, local, and globalized optimization methods}\n\nIn \\cref{sec:51algorithms}, we presented various optimization methods\nfor the unconstrained case,\ndivided into global gradient-free methods such as differential evolution and\nlocal gradient-based methods, for example, gradient descent.\nA subset of these methods has been implemented in \\sgpp{}\n\\cite{Pflueger10Spatially}, see \\cref{tbl:optimizationMethod}.\nThe gradient-based methods need an initial point, and\nthey may get stuck in local minima.\nHence, we additionally implemented globalized versions\nof the gradient-based methods\nvia a multi-start Monte Carlo approach with $m \\ceq \\min(10d, 100)$\nuniformly distributed pseudo-random initial points.%\n\\footnote{%\n  We split the number of permitted function evaluations evenly\n  among the $m$ parallel calls.%\n  %of the gradient-based method%\n}\nThis means there are three types of methods:\n\n\\begin{enumerate}[label=T\\arabic*.,ref=T\\arabic*,leftmargin=2.7em]\n  \\item\n  \\label{item:globalMethods}\n  Global gradient-free methods listed as implemented in\n  \\cref{tbl:optimizationMethod}\n  \n  \\item\n  \\label{item:localMethods}\n  Local gradient-based methods listed as implemented in\n  \\cref{tbl:optimizationMethod}%\n  %(need an initial point)%\n  \\footnote{%\n     Excluding Levenberg--Marquardt, which is only applicable\n     to least-squares problems.%\n  }\n  \n  \\item\n  \\label{item:globalizedMethods}\n  Globalized versions of the methods of type \\ref{item:localMethods}\n  %(do not need an initial point)\n\\end{enumerate}\n\n\\paragraph{Unconstrained optimization of sparse grid surrogates}\n\nGiven the objective function $\\objfun\\colon \\clint{\\*0, \\*1} \\to \\real$,\nthe maximal number $\\ngpMax \\in \\nat$ of evaluations of $f$, and\nthe adaptivity parameter $\\gamma \\in \\clint{0, 1}$,\nwe determine an approximation $\\xoptappr \\in \\clint{\\*0, \\*1}$\nof the global minimum $\\xopt$ of $\\objfun$ as follows:\n\n\\begin{enumerate}\n  \\item\n  Generate a spatially adaptive sparse grid $\\sgset$\n  with the Novak--Ritter refinement criterion\n  for $\\objfun$, $\\ngpMax$, and $\\gamma$.\n  \n  \\item\n  Determine the sparse grid interpolant $\\sgintp$ of $\\objfun$\n  by solving the linear system \\eqref{eq:hierarchizationProblem}.\n  \n  \\item\n  Optimize the interpolant:\n  First, find the best grid point\n  $\\*x^{(0)} \\ceq \\vecargmin_{\\gp{\\*l,\\*i} \\in \\sgset} \\objfun(\\*x_{\\*l,\\*i})$.\n  Second, apply the local methods of type \\ref{item:localMethods}\n  to the interpolant $\\sgintp$ with $\\*x^{(0)}$ as initial point.\n  Let $\\*x^{(1)}$ be the resulting point with minimal objective function value.\n  Third, we apply the global and globalized methods\n  of types \\ref{item:globalMethods} and \\ref{item:globalizedMethods}\n  to the interpolant $\\sgintp$.\n  Again, let $\\*x^{(2)}$ be the point with\n  minimal $\\objfun$ value.\n  Finally, determine the point of $\\{\\*x^{(0)}, \\*x^{(1)}, \\*x^{(2)}\\}$\n  with minimal $\\objfun$ value and return it as $\\xoptappr$.\n\\end{enumerate}\n\n\\noindent\nNote that the third step requires a fixed number of additional\nevaluations of the objective function,\nwhich can be neglected compared to $\\ngpMax$.\nBy default, we use the cubic modified hierarchical not-a-knot B-spline basis\n$\\bspl[\\nak,\\modified]{\\*l,\\*i}{p}$ ($p = 3$)\nfor the construction of the sparse grid surrogate.\nHowever, we could apply any of the hierarchical (B-)spline bases presented in\n\\cref{chap:30BSplines,chap:40algorithms}.\n\n\\paragraph{Comparison methods}\n\nWe use two comparison methods.\nFirst, we apply the gradient-free methods\n(type \\ref{item:globalMethods}) to the sparse grid interpolant\nusing modified piecewise linear hierarchical basis functions\n(i.e., $p = 1$) on the same sparse grid as the cubic B-splines.\nWe cannot employ gradient-based optimization as the objective function\nshould be continuously differentiable and\ndiscontinuous derivatives are usually numerically problematic\nfor gradient-based optimization methods\n(see, e.g., \\cite{Huebner14Mehrdimensionale}).\nSecond, we apply the gradient-free methods\n(type \\ref{item:globalMethods}) directly to the objective function.\nWe cannot use the gradient-based methods here as the gradient of the\nobjective function is assumed to be unknown.\nFor both of the comparison methods,\nwe make sure that the objective function is evaluated at most $\\ngpMax$ times\nby splitting the $\\ngpMax$ evaluations\nevenly among all employed optimization methods.\n\n\\paragraph{Constrained optimization}\n\nFor optimization problems with constraints,\nwe proceed exactly as for unconstrained optimization,\nexcept that for optimizing the interpolant, we use the\nconstrained optimization algorithms implemented in \\sgpp\nas listed in \\cref{tbl:optimizationMethod}.\nWe only replace the objective function $\\objfun$ with a sparse grid\nsurrogate $\\sgintp$, and we assume that the constraint function\n$\\ineqconfun$ can be evaluated fast.\nHowever, it would also be possible to replace $\\ineqconfun$\nwith a sparse grid surrogate.\nIn this case, it cannot be guaranteed that the resulting optimal point\n$\\xoptappr$ is feasible, i.e., we could have\n$\\lnot(\\ineqconfun(\\xoptappr) \\le \\*0)$.\n", "meta": {"hexsha": "da5127add45f8c5182046a405b9ece52bf43ccd1", "size": 9300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/52method.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/52method.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/52method.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": 40.6113537118, "max_line_length": 79, "alphanum_fraction": 0.7384946237, "num_tokens": 2639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673223709251, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6296335256689902}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,amsfonts}\n\\usepackage{listings}\n \n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n \n\\newenvironment{problem}[2][Problem]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}\\hskip \\labelsep {\\bfseries #2.}]}{\\end{trivlist}}\n%If you want to title your bold things something different just make another thing exactly like this but replace \"problem\" with the name of the thing you want, like theorem or lemma or whatever\n \n\\begin{document}\n \n%\\renewcommand{\\qedsymbol}{\\filledbox}\n%Good resources for looking up how to do stuff:\n%Binary operators: http://www.access2science.com/latex/Binary.html\n%General help: http://en.wikibooks.org/wiki/LaTeX/Mathematics\n%Or just google stuff\n \n\\title{Assignment 2\\\\ MEEN 357}\n\\author{Jacob Hartzer}\n\\maketitle\n \n\\section*{Task 7}\n\\begin{problem}{i} Taylor series of $tan^{-1}(x)$\n\\begin{center}\n$f(x) = tan^{-1}(x)$\\\\\n$f(tan\\theta{}) = \\theta{}$\\\\$\nf'(tan\\theta{})sec^2\\theta{}=1$\\\\$\nsec^2\\theta{} =tan^2\\theta+1$\\\\$\nx = tan\\theta{} \\,\\to\\, sec^2 \\theta{}=1+x^2$\\\\$\nf'(x)=1/(1+x^2 )$\\\\$\nf^{(1)} (c)=\\frac{1}{1+x^2}$\\\\$\nf^{(2)} (c)=\\frac{-2x}{1+x^2)^2}$\\\\$\nf^{(3)} (c)=\\frac{8x^2}{(1+x^2)^3} \\frac{-2}{(1+x^2)^2} $\\\\$\nf^{(4)} (c)=\\frac{-48x^3}{(1+x^2)^4}+\\frac{24x}{(1+x^2)^3} $\\\\$\nf^{(5)} (c)=\\frac{384x^4}{1+x^2)^5}-\\frac{288x^2}{1+x^2 )^4}+\\frac{24}{(1+x^2)^3} $\\\\$\nf^{(6)} (c)=\\frac{-3840x^5}{1+x^2)^6} + \\frac{3840x^3}{(1+x^2)^5} -\\frac{720x}{(1+x^2)^4} $\n\\end{center}\nContinuing, one finds that \n\\begin{center}\n$tan^{-1} (x)=f^{(0)} (c)+\\frac{f^{(1)} (c)}{1!}x^1+\\frac{f^{(2)} (c)}{2!}x^2+\\dots{}+\\frac{f^{(n)} (c)}{n!} x^n$\\\\\n$=x-\\frac{x^3}{3}+\\frac{x^5}{3}-\\frac{x^7}{7'}+\\frac{x^9}{9}-\\dots{}$\\\\ \n$=\\sum^{\\inf}_{n=1}-1^{n-1}  \\frac{x^{2n-1}}{2n-1}$\n\\end{center}\n\\end{problem}\n\n\\begin{problem}{ii} Find $R_5$\n\\begin{center}\n$R_5 \\leq \\frac{Max|f^{5+`}(c)|}{(5+1)!}x^{5-1}=Max\\Big[\\frac{-16c^5}{3(1+x^2 )^6}+\\frac{16c^3}{3(1+x^2)^5}-\\frac{c}{1+x^2 )^4}  \\Big]\\big( \\frac{\\pi}{6} \\big)^4$\\\\\n$c = 0.2274$\\\\\n$R_5 = 0.0105$\n\\end{center}\n\\end{problem}\n\n\\begin{problem}{iii} Find the number of terms requried to limit the truncation error.\n\\begin{lstlisting}\n\nclc; clear all; close all;\n\nsyms x;\nfun(x) = atan(x);\n\nn = 1;\nwhile true\n    fun_diff = diff(fun,n+1);\n    \n    remainder = max(abs(double(fun_diff(linspace(0,pi/4,500)))))/...\n        factorial(n+1)*power((pi/6),n-1);\n    \n    if remainder < power(10,-5) || n >= 50\n        break\n    end\n    \n    n = n + 1 ;\nend   \ndisp(n); disp(remainder);\n\n\\end{lstlisting}\n$n=15$\\\\\n$remainder = 6.7654e-06$\n\\end{problem}\n\n\n\\end{document}", "meta": {"hexsha": "ee45c0122fee4a34689792391947d78ec7571ec7", "size": 2630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "A2/a2task7.tex", "max_stars_repo_name": "JHartzer/MEEN_345", "max_stars_repo_head_hexsha": "794890ee37ada10d97280c794508e4c7a4d61337", "max_stars_repo_licenses": ["MIT"], "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/a2task7.tex", "max_issues_repo_name": "JHartzer/MEEN_345", "max_issues_repo_head_hexsha": "794890ee37ada10d97280c794508e4c7a4d61337", "max_issues_repo_licenses": ["MIT"], "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/a2task7.tex", "max_forks_repo_name": "JHartzer/MEEN_345", "max_forks_repo_head_hexsha": "794890ee37ada10d97280c794508e4c7a4d61337", "max_forks_repo_licenses": ["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.5813953488, "max_line_length": 193, "alphanum_fraction": 0.5961977186, "num_tokens": 1131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6296335129794719}}
{"text": "\n\n    \\filetitle{min}{Define loss function for optimal policy}{modellang/min}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\nmin(Disc) Expr;\n\\end{verbatim}\n\n\\paragraph{Syntax for exact non-linear\nsimulations}\\label{syntax-for-exact-non-linear-simulations}\n\n\\begin{verbatim}\nmin#(Disc) Expr;\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nThe loss function must be types as one of the transition equations. The\n\\texttt{Disc} is a parameter or an expression defining the discount\nfactor (applied to future dates), and the expression \\texttt{Expr}\ndefines the loss fuction. The \\texttt{Disc} expression must not contain\na comma.\n\nIf you use the \\texttt{min\\#(Disc)} syntax, all equations created by\ndifferentiating the lagrangian w.r.t. individual variables will be\nearmarked for exact nonlinear simulations provided the respective\nderivative is nonzero. This only makes sense if the loss function is\nother than quadratic, and hence its derivatives are nonlinear.\n\nThere are two types of optimal policy that can be calculated:\ntime-consistent discretionary policy, and time-inconsistent optimal\npolicy with commitment. Use the option \\texttt{'optimal='} in the\nfunction \\href{model/model}{\\texttt{model}} at the time of loading the\nmodel file to switch between these two types of policy; the option can\nbe either \\texttt{'discretion'} (default) or \\texttt{'commitment'}.\n\n\\paragraph{Example}\\label{example}\n\nThis is a simple model file with a Phillips curve and a quadratic loss\nfunction.\n\n\\begin{verbatim}\n!transition_variables\n    x, pi\n\n!transition_shocks\n    u\n\n!parameters\n    alpha, beta, gamma\n\n!transition_equations\n    min(beta) pi^2 + lambda*x^2;\n    pi = alpha*pi{-1} + (1-alpha)*pi{1} + gamma*y + u;\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "1e50c21bac704379ab66cf1c7bf3427c05afc005", "size": 1745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/min.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/min.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/min.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": 29.0833333333, "max_line_length": 75, "alphanum_fraction": 0.7673352436, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6296107920668613}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{August 27, 2014}\n\\maketitle\nchapters 1-5 in 420, chapter 6 in 421.\nchapter 1 should be review.\none of the hardest, if not the hardest course. much new material.\nnot necessary to solve all problems, but try and be able to discuss.\nwill need to present solutions at least 3 times.\nassignments to be turned in will probably be selected from the group of problems that were assigned and discussed.\n\n\\section*{notation review}\nintegers: $\\mathbb{Z}=\\{...,-3,-2,-1,0,1,2,3,...\\}$\n\nnatural numbers:$\\mathbb{N}=\\{0,1,2,3,...\\}$ note this includes 0\n\ndivisibility $a,b\\in\\mathbb{Z}, b \\vert a$ (b divides a) means $a=bc$ for some integer $c$\n\n\\subsection*{division algorithm}\ngiven two integers $a,b\\in\\mathbb{Z}$ where $b>0$ there exists unique integers $q$ and $r$ such that $a=bq+r$ with $0\\le r<b$\n\nnote that this is trivial without constraints on $r$ because one can set $q=0$ and $r=b$\n\\subsubsection*{proof}\ntake $\\mathcal{C}=\\{a-bq\\mid q\\in\\mathbb{Z}\\}$\n\n$\\mathcal{C}^+=\\mathcal{C}\\cap\\mathbb{N}$\n\\subsubsection*{claim}\n$\\mathcal{C}^+$ is non-empty. why?\n\nif $a\\ge 0,$ then $a-b\\cdot0\\in\\mathcal{C}^+$\n\nif $a<0,$ then $a-b\\cdot a=a(1-b)$. $b>0$ so $1-b\\le0$ so $a-ba\\ge0$\n\nnow take the \\emph{well ordering principle} (you can always find a smallest or least element of a subset of natural numbers)\n\nlet $r$ be the smallest element of $\\mathcal{C}^+$\n\\[r=a-bq\\]\nclaim is that $r<b$\n\\subsubsection*{contradiction}\nassume $r\\ge b$. then $r-b\\ge0$\n\\begin{align*}\n  r-b&=(a-bq)-b\\\\\n  &=a-b(q+1)\\in\\mathcal{C}\n\\end{align*}\nthis means $r-b\\in\\mathcal{C}^+$ which is a contradiction because it is smaller than $r$ which is supposed to be the smalled element in $\\mathcal{C}^+$\n\nwe know that $r<b$ so there exists $q,r$ with $a=bg+r$, $0\\le r<b$.\n\nto prove uniqueness, assume $a=bq_1+r_1$ with $0\\le r_1<b$ and $a=bq_2+r_2$ with $0\\le r_2<b$\n\nprove 1 and 2 are the same, prove q get remainder for free.\n\nsubtract the two quantities\n\\begin{align*}\n  0&=b(q_1-q_2)+(r_1-r_2)\\\\\n\\end{align*}\nlets talk about $r_1$ and $r_2$. distance between $r_1$ and $r_2$ is at most b. draw it on a number line with r's between 0 and b to be convinced\n\\begin{align*}\n  r_2-r_1&=b(q_1-q_2)\\\\\n  \\left\\lvert r_2-r_1\\right\\rvert&=b\\left\\lvert q_1-q_2\\right\\rvert\\\\\n\\end{align*}\nsince $\\left\\lvert r_1-r_2\\right\\rvert<b$ the difference is zero and $r_1=r_2$\n\n\\section*{gcd}\ngreatest common divisor\n\\subsection*{definition}\nlet $a,b\\in\\mathbb{Z}$ not both 0. we say that the positive integer $d$ is the greatest common divisor of $a$ and $b$ if\n\\begin{enumerate}\n\\item\n$d\\vert a$ and $d\\vert b$ (always at least have one)\n\\item\nany other common divisor of $a$ and $b$ is also a divisor of $d$\n\nin other words, if $c\\vert a$ and $c\\vert b$ then $c\\vert d$\n\\end{enumerate}\nuniqueness is implied by saying \\emph{the} greatest common divisor\n\\end{document}\n", "meta": {"hexsha": "568fddba4a113cb4e60eea6e4de578f8373e887d", "size": 3052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-08-27.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": "abstract algebra/abstract-notes-2014-08-27.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": "abstract algebra/abstract-notes-2014-08-27.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": 34.6818181818, "max_line_length": 151, "alphanum_fraction": 0.6998689384, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.6296107876126581}}
{"text": "\\section{Modular Arithmatic}\n\n\\theo{http://services.artofproblemsolving.com/download.php?id=YXR0YWNobWVudHMvMy8yL2QzYjEzOGM0ODE3YzYwZGU4NGFmOTEwZDc0ZGNhODRjOGMyMzZlLnBkZg==&rn=dGh1ZS12NC5wZGY=}\n{Thue's Lemma}{\n    Let $n>1$ be an integer and a be an integer co-prime to $n$. Then there\n    are integers $x, y$ with $0<|x|,|y|<\\sqrt{n}$ so that\n    \\[ x \\equiv a y \\ (\\mod\\ n) \\]\n    Such a solution $(x, y)$ is called a ``small solution'' sometimes.\n}\n\n\\begin{prooof}\n    Let $r=\\lfloor\\sqrt{n}\\rfloor$ i.e. $r$ is the unique integer for which\n    $r^{2} \\leq n<(r+1)^{2}$ The number of pairs $(x, y)$ so that $0 \\leq x, y\n    \\leq r$ is $(r+1)^{2}$ which is greater than $n .$ Then there must be two\n    different pairs $\\left(x_{1}, y_{1}\\right)$ and $\\left(x_{2},\n    y_{2}\\right)$ so that\n    \\[\\begin{aligned}\n        x_{1}-a y_{1} &\\equiv x_{2}-a y_{2} &(\\mod\\ n) \\\\\n        x_{1}-x_{2} &\\equiv a\\left(y_{1}-y_{2}\\right) &(\\mod\\ n) \\\\\n    \\end{aligned}\\]\n\n    Let $x=x_{1}-x_{2}$ and $y=y_{1}-y_{2},$ and we get $x \\equiv a y\\ (\\mod\\ n)$.\n    Now, we need to show that $0<|x|,|y|<r$ and $x, y \\neq 0 .$ Certainly, if\n    one of $x, y$ is zero, the other is zero as well. If both $x$ and $y$ are\n    zero, that would mean that two pairs $\\left(x_{1}, y_{1}\\right)$ and\n    $\\left(x_{2}, y_{2}\\right)$ are actually same. That is not the case, and so\n    both $x, y$ can not be $0 .$ Therefore, none of $x$ or $y$ is $0,$ and we are\n    done.\n\\end{prooof}\n\n\\theo{}\n{Generalization of Thue's Lemma}{\n    Let $\\alpha$ and $\\beta$ are two real numbers so that $\\alpha \\beta \\geq p$. \n    Then for an integer $x,$ there are integers $a, b$ with $0<|a|<\\alpha$\n    and $0<|b|<\\beta$ so that\n    \\[a \\equiv x b \\quad(\\mod\\ p) \\]\n    And we can even make this lemma a two dimensional one.\n}\n\n\n\\thmbox{}\n{Fermat's 4n+1 Theorem}{\n    Every prime of the form $4n+1$ can be written as the sum of squares of two\n    coprime integers.\n}\n\n\\begin{prooof}\n    We know that there is an $x$ such that \n    \\[x^2 \\equiv -1 \\ (\\mod\\ p)\\] \n    And by \\autoref{theorem:Thue's Lemma}, there are $a, b$ with\n    $0<\\left|a\\right|, \\left|b\\right|< \\sqrt{n}$ for which\n    \\[\\begin{aligned}\n        a &\\equiv xb \\ &(\\mod\\ p)\\\\\n        a^2 &\\equiv x^2b^2 \\ &(\\mod\\ p)\\\\\n        a^2 + b^2 &\\equiv 0 \\ &(\\mod\\ p)\n    \\end{aligned}\\] \n    Since $a^2+ b^2 < 2p$, we are done.\n\\end{prooof}\n\n\\theo{}\n{General Fermat's 4n+1 Theorem}{\n    Let $n\\in \\left\\{1, 2, 3\\right\\}$. If $-n$ is a quadratic residue modulo\n    $p$, then there exists $a, b$ such that $a^2 + nb^2 = p$\n}\n\n\\thmbox{}\n{Factors are of the same form}{\n    If $D\\in \\left\\{1, 2, 3\\right\\}$ and $n = x^2 + Dy^2$ for some $x\\perp y$,\n    then all of the factors of $n$ are of the form $a^2 + Db^2$.\n}\n\n\\begin{prooof}\n    This is because the product of two numbers of such form is the same form\n    as them:\n    \\[\\begin{aligned}\n        \\left(a^2+Db^2\\right)\\left(c^2 + Dd^2\\right) &=\\left(ac-Dbd\\right)^2 +\n        D\\left(ad+bc\\right)^2\\\\\n        &=\\left(ac+Dbd\\right)^2 + D\\left(ad-bc\\right)^2\n    \\end{aligned}\\] \n    And by \\autoref{theorem:General Fermat's 4n+1 Theorem} the prime factors\n    of $n$ are of the same form. And so all factors of $n$ are of the same form.\n\\end{prooof}\n\n\n\\thmbox{}\n{Quadratic Residue -3}{\n    $-3$ is a quadratic residue of modulo $p$ iff $p$ is of the form $3k+1$.\n}\n\\begin{prooof}\n    The only if part is easy with Thue's Lemma. For the if part, we have\n    \\[\\begin{aligned}\n        \\left(\\frac{p}{3}\\right)\\left(\\frac{3}{p}\\right) &=\n        (-1)^{\\left(\\frac{p-1}{2}\\right) \\left(\\frac{3-1}{2}\\right)}=\n        (-1)^{\\left(\\frac{p-1}{2}\\right) }\n    \\end{aligned}\\] \n    Then we casework on $p\\equiv 1, -1 \\ (\\mod\\ 4)$ to show that in either\n    case, \\[\\left(\\frac{-3}{p}\\right) = 1\\]\n\\end{prooof}\n\n\n\n\\prob{}\n{Thue's Lemma Note}{}{\n    Let $p$ be prime number, prove that there exists $x, y$ such that\n    $p=2x^2+3y^3$ iff $p\\equiv 5, 11 \\ (\\mod\\ 24)$.   \n}\n\n\\begin{solution}\n    We need to show that $\\frac{-3}{2}$ is a quadratic residue mod $p$, and\n    the rest will follow from Thue's Lemma. We do that using the quadratic\n    residue rules for $2$ and $-3$.\n\\end{solution}\n", "meta": {"hexsha": "46a8d5a307f09e0058988ba5d074ca9af4b0fa7e", "size": 4151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nt/sec6_modular_arithmatic.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": "nt/sec6_modular_arithmatic.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": "nt/sec6_modular_arithmatic.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": 36.7345132743, "max_line_length": 163, "alphanum_fraction": 0.5923873765, "num_tokens": 1617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.6294687546408078}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 8, 2022}\n\\subsection{Legendre Symbol \\emph{continued}}\n\\begin{example}\\label{example:legendre-symbol}\n    Determine if $219$ is a quadratic residue mod $383$ (we note that $383$ is a prime).\n    \\begin{align*}\n        \\lege{219}{383} & = \\lege{3}{383}\\cdot\\lege{73}{383}    \\\\\n        \\intertext{We now flip the Legendre Symbols using quadratic reciprocity:}\n                        & = -\\lege{383}{3} \\cdot \\lege{383}{73} \\\\\n                        & = -\\lege{2}{3} \\cdot \\lege{18}{73}    \\\\\n                        & = 1\\cdot \\lege{18}{73}                \\\\\n                        & = \\lege{2}{73}\\cdot\\lege{9}{73}       \\\\\n                        & = \\lege{2}{73} = \\boxed{1}\n    \\end{align*}\n\\end{example}\n\\begin{remark*}\n    We must factor the top argument before beginning to flip using quadratic reciprocity.\n\\end{remark*}\n\n\\subsection{Proof of Quadratic Reciprocity}\n\nRecall \\cref{thm:qr}:\n\\begin{theorem*}[Law of Quadratic Reciprocity]\n    Let $p, q\\in\\ZZ_+$ be distinct odd positive primes. Then\n    \\begin{equation*}\n        \\lege{p}{q}\\lege{q}{p} = (-1)^{\\frac{p-1}{2}\\frac{q-1}{2}}\n    \\end{equation*}\n    In other words,\n    \\[\\lege{p}{q} = \\lege{q}{p}\\]\n    if and only if at least one of $p, q$ is congruent to $1$ mod $4$.\n\\end{theorem*}\n\n\\begin{proof}[Proof of Quadratic Reciprocity (\\cref{thm:qr}), using Gauss's Lemma (\\cref{lemma:gauss-lemma})]\n    \\textsc{wlog}, let\n    \\begin{align*}\n        P & = \\left\\{1, 2, \\dots, \\frac{p-1}{2}\\right\\},\\quad N=-P, \\\\\n        Q & = \\left\\{1, 2, \\dots, \\frac{q-1}{2}\\right\\}\n    \\end{align*}\n    We write $\\tilde P, \\tilde N$ for $P\\pmod{p}$ and $N\\pmod{p}$ respectively, so that Gauss's lemma gives\n    \\[\\lege{q}{p} = (-1)^\\mu, \\quad\\text{where }\\mu = |q\\tilde P\\cap\\tilde N|\\]\n    In other words, $\\mu$ is exactly the number of $x\\in P$ such that $qx\\equiv n\\pmod{p}$ for some $n\\in N$, and hence the number of $x\\in P$ such that for $y\\in \\ZZ$, \\[-\\frac{p}{2} < qx - py < 0.\\]\n    We now specify more precisely which $y$ can possibly satisfy this condition. Solving these inequalities for $y$ gives\n    \\begin{align*}\n        \\frac{qx}{p} < y < \\frac{qx}{p}+\\frac{1}{2}.\n    \\end{align*}\n    \\otoh, since $x\\leq \\frac{p-1}{2}$ $\\forall x\\in P$, this gives\n    \\begin{align*}\n        y < \\frac{qx}{p}+\\frac{1}{2} & \\leq \\frac{q(p-1)}{2p}+\\frac{1}{2} \\\\\n                                     & < \\frac{q+1}{2}.\n    \\end{align*}\n    Thus $0 < y < \\frac{q+1}{2}$, which means that\n    \\[y\\in Q = \\left\\{1, 2, \\dots, \\frac{q-1}{2}\\right\\}.\\]\n    We've shown that $\\mu$ is the number of points $(x, y)\\in P\\times Q$ such that\n    \\[\\frac{p}{2} < qx - py < 0.\\]\n\n    Switching $p$ and $q$, we also have\n    \\[\\lege{p}{q} = (-1)^\\eta\\]\n    where $\\eta$ is the number of pairs\n    \\[(y, x)\\in Q\\times P\\]\n    such that\n    \\[-\\frac{q}{2} < py - qx < 0\\]\n    which is exactly the number of pairs\n    \\[(x, y)\\in P\\times Q\\]\n    satisfying\n    \\[0 < qx - py < \\frac{q}{2}\\]\n    (reflecting the inequality over $0$).\n\n    We note that\n    \\[\\lege{p}{q}\\lege{q}{p} = (-1)^\\mu (-1)^\\eta = (-1)^{\\mu+\\eta}\\]\n    so all that remains is counting $\\mu$ and $\\eta$. And we have that $\\mu + \\eta$ is the number of ordered pairs $(x, y)\\in P\\times Q$ such that either\n    \\[-\\frac{p}{2} < qx - py < 0 \\text{ or } 0 < qx - py < \\frac{q}{2}\\]\n    Noting that $qx - py\\neq 0$ since $x$ and $y$ are from $P$ and $Q$ respectively, hence we can reduce this to\n    \\[-\\frac{p}{2} < qx - py < \\frac{q}{2}.\\]\n    Graphically, we are looking at:\n    \\begin{center}\n        \\includegraphics[width=0.8\\textwidth]{images/qr-diagram.png}\n    \\end{center}\n\n    where $\\mu + \\eta$ is the number of lattice points in the shaded region.\n\n    If $\\alpha$ is the number of lattice points in $A$ and $\\beta$ the number of lattice points in $B$. Then\n    \\[\\mu + \\eta = \\frac{p-1}{2}\\frac{q-1}{2} - (\\alpha + \\beta)\\]\n    We show that $\\alpha = \\beta$ so that $\\alpha + \\beta \\equiv 0\\pmod{2}$.\n\n    Let $\\rho$ be the rotation given by rotating the rectangle about its center leaves it invariant.\n    \\[\\rho(x, y) = \\left(\\frac{p+1}{2}-x, \\frac{q+1}{2} - y\\right)\\]\n    Quick check that\n    \\[qx - py < \\frac{-p}{2} \\Leftrightarrow qx' - py' > \\frac{q}{2}\\]\n\n    Since $\\rho$ maps lattice points to lattice points, then $\\alpha = \\beta$ which concludes the proof with a little extra handiwork.\n\\end{proof}\n\n\\subsection{Jacobi Symbol}\nThe Jacobi symbol generalizes the Legendre symbol.\n\\begin{definition}[Jacobi Symbol]\n    Let $b$ be an odd positive integer and let $a\\in\\ZZ$. Write\n    $b = p_1p_2\\cdots p_m$, where $p_i$ are (not necessarily distinct) primes. Then we write\n    \\[\\lege{a}{b} = \\lege{a}{p_1}\\lege{a}{p_2}\\cdots \\lege{a}{p_m}\\]\n    is called the \\ul{Jacobi symbol}.\n\\end{definition}\nWe note some basic properties that the Jacobi symbol is totally multiplicative (on top and bottom!):\n\\begin{align*}\n    \\lege{a_1a_2}{b} & = \\lege{a_1}{b}\\lege{a_2}{b} \\\\\n    \\lege{a}{b_1b_2} & = \\lege{a}{b_1}\\lege{a}{b_2}\n\\end{align*}\n\\begin{remark*}\n    Note that they're multiplicative \\emph{fixing} either top or bottom. That is, they don't multiply like fractions.\n\\end{remark*}\n\n\\textbf{Warning!} $\\lege{a}{b} = 1$ does not imply that $a$ is a quadratic residue modulo $b$ (since we could have $-1$'s from the factorization cancel out).\n\nHowever, $\\lege{a}{b} = -1$ \\emph{does} imply that $a$ is a non-residue modulo $b$. (it is a non-residue mod at least one of prime factors of $b$).\n\n\\begin{example}\n    \\[\\lege{2}{15} = \\lege{2}{3}\\lege{2}{5} = (-1)(-1) = 1\\]\n    but $2$ is not a quadratic residue modulo $15$.\n\\end{example}\n\\begin{proposition}[5.2.2 of Text]\\label{prop:5.2.2}\n    We have the following properties about the Jacobi symbol:\n    \\begin{enumerate}[(a)]\n        \\item \\[\\lege{-1}{b} = (-1)^{\\frac{b-1}{2}}\\]\n        \\item \\[\\lege{2}{b} = (-1)^{\\frac{b^2 - 1}{8}}\\]\n        \\item If $a, b\\in\\ZZ_+$, then\n              \\[\\lege{a}{b}\\lege{b}{a} = (-1)^{\\frac{a-1}{2}\\frac{b-1}{2}}\\]\n    \\end{enumerate}\n\\end{proposition}", "meta": {"hexsha": "8324c78c83631bd787a38d32622f2365fb3c5ab7", "size": 6003, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-08.tex", "max_stars_repo_name": "jchen/math1560-notes", "max_stars_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-02T15:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T20:28:48.000Z", "max_issues_repo_path": "lectures/2022-03-08.tex", "max_issues_repo_name": "jchen/math1560-notes", "max_issues_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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-08.tex", "max_forks_repo_name": "jchen/math1560-notes", "max_forks_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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": 47.6428571429, "max_line_length": 200, "alphanum_fraction": 0.5798767283, "num_tokens": 2170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.6294687519002649}}
{"text": "%  -----------------------------------------------------------------------------\n%  Author         : Bimalka Piyaruwan Thalagala\n%  GitHub         : https://github.com/bimalka98\n%  Date Created   : 01.09.2020\n%  Last Modified  : 06.03.2020\n%  -----------------------------------------------------------------------------\n\n\\documentclass[a4paper,11pt]{article}%,twocolumn\n\\input{settings/packages}\n\\input{settings/page}\n\\input{settings/macros}\n\\usepackage[ framed, numbered]{matlab-prettifier}%framed,%\n\\usepackage{listings}\n\\usepackage{physics}\n\\usepackage{pdfpages}\n\\usepackage[toc,page]{appendix}\n\n\\begin{document}\n\\input{content/title_page}\n\n\n\\pagebreak\n\n\\tableofcontents\n\\listoffigures\n\\vfill\n\\begin{center}\n\t\\textbf{\\textit{*PDF is clickable}}\n\\end{center}\n\n\\textit{\\textbf{Note:}}\\\\\n\\textit{All the materials and executable {\\tt MATLAB R2018a} Live Script related to the project can also be found at \\url{https://github.com/bimalka98/Digital-Signal-Processing}}\n\\pagebreak\n\n\\section{Question 1 and Question 2}\nRefer the Appendix for the Code. For the generation of the AWGN, MATLAB's {\\tt normrnd($\\mu$,$\\sigma$,[1, samples])} function which returns random samples from a normal distribution with mean $\\mu$ and standard deviation $\\sigma$ was used.\\\\\n\n\\vspace{10cm}\n\\begin{center}\n\t\\textit{this page was intentionally left blank}\n\\end{center}\n\n\\pagebreak\n\n\\section{Question 3}\nPlot of the sequence of Received signal and observations of the impact of the variance of noise on it by varying $\\sigma^2=1$.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q3f1}\n\t\\caption{Sequence of the Received signal when $\\sigma^2 = 1$}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q3f2}\n\t\\caption{Impact of the variance of noise on the Received signal}\n\\end{figure}\n\nAs illustrated in the above figure when the variance of the noise increases the range of the values the received sample can  be in increases (observe the change in the range of Y axis). This essentially increases the bit errors at the receiving end.\n\n\\pagebreak\n\\section{Question 4}\nSketching and comparing the sequence of Y(signal recovered through threshold) with the transmitted signal.\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.4]{figures/q4f1}\n\t\\caption{Sequence of Y when the number of samples is 1000}\n\\end{figure}\n\nMost of the transmitted bits have been identified correctly by the receiver after the thresholding(perfectly aligned curves). But some of the bits have been identified incorrectly after the thresholding. Change of signal levels due to the unwanted noise added during the process of transmission is the reason.\n\n\\section{Question 5}\nRepeating the above steps for a sequence of length L = 100,000.\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.4]{figures/q5f1}\n\t\\caption{Sequence of Y when the number of samples is 100,000}\n\\end{figure}\n\nThe same observations made regarding the previous figure is applicable to this scenario as well. But probability of error has a significant reduction when transmitting a huge number of bits. \n\n\\pagebreak\n\\subsection{Histogram of the received sequence taking\tthe no of bins as 10}\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f2}\n\t\\caption{Histogram of the received sequence using the user defined function: bins = 10}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f3}\n\t\\caption{Histogram of the received sequence using the MATLAB's built-in {\\tt hist()} fucntion: bins = 10}\n\\end{figure}\n\n\\textbf{Comparison} : Histograms generated using the custom user defined function and the built-in function are almost the same. The reason for the difference in frequencies can be identified as the range differences of bins considered in the two algorithms. Code of the user defined fucntion can be found at the end of the Appendix.\n\n\\pagebreak\n\\subsection{Impact when the number of bins is changed from 10 to 100}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f4}\n\t\\caption{Histogram of the received sequence using the user defined function: bins =100}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f5}\n\t\\caption{Histogram of the received sequence using the MATLAB's built-in {\\tt hist()} fucntion: bins = 100}\n\\end{figure}\n\\textbf{Impact}: When the number of bins is changed from 10 to 100, shape of the normal distribution becomes clearly visible and differences between two histograms become negligible as the ranges of the bins become more similar.\n\n\\pagebreak\n\\subsection{Conditional PDFs when number of bins = 100 and A = 1}\n\nDependent axis represents the normalized frequencies calculated as follows. And therefore following figures illustrates the approximation for the required Probability Density Functions.\n\\[\nNormalized ~Freq = \\frac{Frequency}{Total~Number~of~Samples \\times Width~of~a~Bin}\n\\] \n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f6}\n\t\\caption{$f_{R|S}(r|S=A)$ when A = 1: Mean $\\approx$ 1}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f7}\n\t\\caption{$f_{R|S}(r|S= -A)$ when A =1: Mean $\\approx$ -1}\n\\end{figure}\n\nObserve that when the distribution is conditioned on S, the mean of the distribution shifts along the amplitude axis towards the S.\n\n\\pagebreak\n\\subsection{Impact of A on the Conditional PDFs}\n\nAs illustrated in the following figures, when the distribution is conditioned on S =A , the mean of the distribution shifts along the amplitude axis towards the S = A.  But the variance of the distribution remains the same as it is only affected by the AWGN.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f8}\n\t\\caption{Impact of A on the Conditional PDFs}\n\\end{figure}\n\n\\subsection{Expected Values of the distributions when A = 1}\n\nThe expected value of a continuous Random variable $X$ which has a PDF of $f_X(x)$ is given as,\n\\[\nE[X] = \\int_{-\\infty}^{+\\infty} x.f_X(x) ~dx\n\\]\nThe same formula can be redefined for discrete case as follows where $\\Delta x$ represents the width of a bin which is equal in our cases.\n\\[\nE[X] = \\sum_{i = 1}^{N} x_i.P(x_i).\\Delta x\n\\]\n\nTherefore the requires expected values can be easily found using the {\\tt Expected(x, px, bin\\_width)} function defined in the appendix. The required parameters of that function can be found using the {\\tt myHistogram(valueArray,numberOfBins, Normalized)} function. \\\\\n\n\\begin{tabular}[!h]{l c r}\n\tExpected value $E[R]$& = & -0.00073493\\\\\nExpected value $E[R|S=A]$ &=& 1.0004\\\\\nExpected value $E[R|S=-A]$& =& -1.0011\\\\\n\n\\end{tabular}\n\n\\pagebreak\n\\subsection{Marginal PDF of R $f_R(r)$}\nDependent axis represents the normalized frequencies calculated as follows as mentioned previously. Therefore, the following figure illustrates the approximation for the required Marginal Probability Density Functions of the continuous Random Variable R.\n\\[\nNormalized ~Freq = \\frac{Frequency}{Total~Number~of~Samples \\times Width~of~a~Bin}\n\\] \n\nExpected value of the Random Variable  ($E[R]$ = -0.00073493) reaches zero as the probabilities Pr(D = 0) = Pr(D = 1) = 1/2 are equal.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q5f9}\n\t\\caption{Marginal PDF of R $f_R(r)$}\n\\end{figure}\n\n\n\\pagebreak\n\\section{Question 6: Effect of Interference}\n\nInterference does nothing other than increasing the variance of the  distribution. When comparing the following figures with the figures of the previous section it is clearly visible. As the variance increases, to keep the area under the graph  a constant, the peak of the graph lowers. Therefore following two observations can be made when additional interference is added to the transmitted signal.\n\\begin{itemize}\n\t\\item Variance of the distribution increases. Which eventually increases the probability of error.\n\t\\item Peak value of the distribution decreases to keep the area under the curve constant.\n\\end{itemize}\n\nThese observations are common to all the figures and subsections of this section.\n\n\\subsection{Conditional PDFs when number of bins = 100, A = 1 and under additional interference}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.38]{figures/q6f1}\n\t\\caption{$f_{R|S}(r|S=A)$ when interference is added}\n\\end{figure}\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.38]{figures/q6f2}\n\t\\caption{$f_{R|S}(r|S= -A)$  when interference is added}\n\\end{figure}\n\n\\pagebreak\n\\subsection{Impact of A on the Conditional PDFs under additional interference}\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q6f3}\n\t\\caption{Impact of A on the Conditional PDFs under additional interference}\n\\end{figure}\n\n\\subsection{Expected Values of the distributions and under additional interference}\n\nAs previously described interference affects only to the variance of the distribution. Therefore the Expected Values remains almost the same.\\\\\n\n\\begin{tabular}[!h]{l c r}\n\tExpected value $E[R]$& = & -0.0012806\\\\\n\tExpected value $E[R|S=A]$ &=& 0.99798\\\\\n\tExpected value $E[R|S=-A]$& =& -0.99949\\\\\n\t\n\\end{tabular}\n\n\\subsection{Marginal PDF of R $f_R(r)$ and under additional interference}\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.38]{figures/q6f4}\n\t\\caption{Marginal PDF of R $f_R(r)$ under additional interference}\n\\end{figure}\n\n\\section{Question 7: Effect of Scaling when the number of bins = 100 and A = 1 and $\\sigma^2 = 1$}\n\nEffect of scaling of the pulse sequence(S), on the conditional probability distributions has the same effect as changing the signal level `A'. Therefore the figures and the subsections will be the same as that of Question 5.\\\\\n\nTherefore only the behavior of Marginal distribution of R(received signal) is illustrated here. As it was not considered in earlier sections.\n\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[scale=0.45]{figures/q7f1}\n\t\\caption{Effect of Scaling on the Marginal PDF of R $f_R(r)$}\n\\end{figure}\n\nThe first sub-figure of the above figure shows the instance without any scaling. when the scale is increased, the distribution tends to divide in to two separate peaks centered around $+\\alpha$ and $-\\alpha$ as expected due to the lower variance than the scaling factor.\n\n\\begin{appendices}\n\t\\section{Matlab Code for the Simulation}\n\t\\includepdf[pages=-]{code/code.pdf}\n\\end{appendices}\n\n\n\n%---------------------------------------------------------------------------\n\\end{document}\n-\n", "meta": {"hexsha": "3eaeb1e99b8e506813d627bf09472ccc1a8c6616", "size": 10458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RSP Simulation Assignment/EN2040_SA_180631J.tex", "max_stars_repo_name": "bimalka98/Digital-Signal-Processing", "max_stars_repo_head_hexsha": "54a36b5602b00264a2a5fa1272f9d3834bbf3fb7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-21T07:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T07:51:34.000Z", "max_issues_repo_path": "RSP Simulation Assignment/EN2040_SA_180631J.tex", "max_issues_repo_name": "bimalka98/Digital-Signal-Processing", "max_issues_repo_head_hexsha": "54a36b5602b00264a2a5fa1272f9d3834bbf3fb7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RSP Simulation Assignment/EN2040_SA_180631J.tex", "max_forks_repo_name": "bimalka98/Digital-Signal-Processing", "max_forks_repo_head_hexsha": "54a36b5602b00264a2a5fa1272f9d3834bbf3fb7", "max_forks_repo_licenses": ["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.3783783784, "max_line_length": 400, "alphanum_fraction": 0.7427806464, "num_tokens": 2781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.6294687505299934}}
{"text": "\\subsection{Summary of Curve Sketching}\\label{subsec:SummaryCurveSketching}\n\nThe following is a guideline for sketching a curve $y=f(x)$ by hand. Each item may not be relevant to the function in question, but utilizing this guideline will provide all information needed to make a detailed sketch of the function.\n\n\\begin{formulabox}[Guideline for Curve Sketching]\n\\begin{enumerate}\n\t\\item\tDomain of the function\n\t\\item\t$x$- and $y$-Intercepts\n\t\\item\tSymmetry\n\t\\item\tVertical and Horizontal Asymptotes\n\t\\item\tIntervals of Increase/Decrease, and Local Extrema\n\t\\item\tConcavity and Points of Inflection\n\t\\item\tSketch the Graph\n\\end{enumerate}\n\\end{formulabox}\n\n\\begin{example}{Graph Sketching}{graphsketching}\nSketch the graph of $y=f(x)$ where $\\ds{f(x)=\\frac{2x^2}{x^2-1}}$\n\\end{example}\n\n\\begin{solution} \n\\begin{enumerate}\n\\item  The domain is $\\{x: x^2-1 \\neq 0\\}= \\{x: x \\neq \\pm 1\\}=(- \\infty,-1) \\cup (-1,1) \\cup (1, \\infty)$\n\\item  There is an $x$-intercept at $x=0$. The $y$ intercept is $y=0$.\n\\item  $f(-x)=f(x)$, so $f$ is an even function (symmetric about $y$-axis)\n\\item  $\\ds{ \\lim_{x \\to \\pm \\infty} \\frac{2x^2}{x^2-1} =\\lim_{x \\to \\pm \\infty} \\frac{2}{1-1/x^2} = 2 }$, so $y=2$ is a horizontal asymptote.\n\nNow the denominator is 0 at $x =\\pm1$, so we compute:\n\\[\\lim_{x \\to 1^+} \\frac{2x^2}{x^2-1} = + \\infty, \\;   \\lim_{x \\to 1^-} \\frac{2x^2}{x^2-1} = - \\infty, \\;\n\\lim_{x \\to -1^+} \\frac{2x^2}{x^2-1} = - \\infty, \\;   \\lim_{x \\to -1^-} \\frac{2x^2}{x^2-1} = + \\infty.  \\]\nSo the lines $x=1$ and $x=-1$ are vertical asymptotes. \n\n\\item  For critical values we take the derivative:\n$$f'(x) = \\frac{4x(x^2-1)-2x^2 \\cdot 2x}{(x^2-1)^2} = \\frac{-4x}{(x^2-1)^2}.$$\nNote that $f'(x)=0$ when $x=0$ (the top is zero).\nAlso, $f'(x)=DNE$ when $x=\\pm 1$ (the bottom is zero).\nAs $x=\\pm 1$ is \\ifont{not} in the domain of $f(x)$, the only critical number is $x=0$ (recall that to be a critical number we need it to be in the domain of the original function).\n\nDrawing a number line and including \\ifont{all} of the split points of $f'(x)$ we have:\n$$\\includegraphics[width=3.5in]{images/graphex1}$$\nThus $f$ is increasing on $(-\\infty, -1)\\cup(-1,0)$ and decreasing on $(0,1)\\cup(1, \\infty)$.\n\nBy the first derivative test, $x=0$ is a local max.\n\n\\item  For possible inflection points we take the second derivative:\n$$f''(x)= \\frac{12x^2+4}{(x^2-1)^3}$$\nThe top is never zero.\nAlso, the bottom is only zero when $x=\\pm 1$ (neither of which are in the domain of $f(x)$).\nThus, there are no possible inflection points to consider.\n\nDrawing a number line and including \\ifont{all} of the split points of $f''(x)$ we have:\n$$\\includegraphics[width=2.25in]{images/graphex2}$$\nHence $f$ is concave up on $(- \\infty,-1)\\cup(1, \\infty)$, concave down on $(-1,1)$.\n\n\\item  We put this information together and sketch the graph.\n\nWe combine some of this information on a single number line to see what \\ifont{shape} the graph has on certain intervals:\n$$\\includegraphics[width=3.0in]{images/graphex3}$$\nNote that there is a horizontal asymptote at $y=2$ and that the curve has $x$-int of $x=0$ and $y$-int of $y=0$.\nTherefore, a sketch of $f(x)$ is as follows:\n$$\\includegraphics[width=3.5in]{images/graphex4}$$\n\\end{enumerate}\n\\end{solution}", "meta": {"hexsha": "75abdabc31d12335b00436c772cac35315087b0a", "size": 3235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-6-5-summary.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-5-summary.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-5-summary.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.3492063492, "max_line_length": 235, "alphanum_fraction": 0.6754250386, "num_tokens": 1185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799253, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.6294687406683618}}
{"text": "\\newpage\n\\section{Decision Trees}\\label{s:decision-trees}\n\nDecision trees are tree-like structures in which each internal node represents a ``test\" on an attribute, each branch represents the outcome of the specific test, and each leaf node represents a class label (decision taken after computing all attributes).\nMore specifically, decision trees depict models of decisions and their possible results.\nThey are also a simple way to display an algorithm that only contains conditional control statements.\nStarting from the root node and following the paths to leaves, each path represents classification rules.\n\nFor instance, the attribute ``Gender\" would have two edges leaving it, one for ``Male\" and\none for ``Female\".\nEach edge could point to a new attribute (for example ``Age Groups\"), and so on.\nThe leaves of the tree contain the expected class value for transactions matching the path from the root to that leaf.\nGiven a decision tree, one can predict the class of a new transaction just by following the ``correct\" path, which will result in a class label.\nHe\\myslash She can predict the class of a transaction by viewing only the non-class attributes (\\textit{i.e.} the ``constructed\" decision tree).\n\nFor instance, two friends wish to decide if they will go to play tennis outside, depending the weather conditions.\nThey also remember the previous days that some weather conditions did not allow them to play.\nThus, they decide to create a decision tree to assist them.\nFirst they define the class attribute to be ``Play Tennis\", and three more attributes that will help them decide: ``Outlook\" (``Sunny\", ``Overcast\", ``Rainy\"), ``Windy\" (``High\", ``Low\") and ``Humidity\" (``High\", ``Low\").\nThen they construct a decision tree like figure \\ref{f:outlook} that corresponds to the data that the have collect from the past days.\n\n\\begin{figure}[th]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{figures/outlook.pdf}\n  \\caption{Play-Tennis decision tree example}\\label{f:outlook}\n\\end{figure}\n\nFrom figure \\ref{f:outlook}, the two friends are able to extract a set of rules, listed in Code \\ref{sc:outlook-rules}, that will help them decide if they should go play tennis given the weather conditions.\n\n{\n\\begin{minted}[xleftmargin=21pt, framesep=3mm, frame=single, linenos, tabsize=2, breaklines, breaksymbolleft=, fontsize=\\footnotesize]{bash}\nIF (Outlook = Sunny) AND (Windy = Low) THEN Play=Yes\n\nIF (Outlook = Sunny) AND (Windy = High) THEN Play=No\n\nIF (Outlook = Overcast) THEN Play=Yes\n\nIF (Outlook = Rainy) AND (Humidity = High) THEN Play=No\n\nIF (Outlook = Rainy) AND (Humidity = Low) THEN Play=Yes\n\\end{minted}\n\\captionof{lstlisting}{Rules for decision tree from figure \\ref{f:outlook}}\n\\label{sc:outlook-rules}\n}\n\nOf course, remembering the weather conditions of more days in the past and if they had played tennis those days -- having an extended dataset -- could probably result to more specific rules.\nDecision tree rules, help covering all possible future decisions\\hyp transactions and can be used to classify them.\nThere are many useful examples and it has become evident why this type of learning has become so popular.\nThe algorithms according to which those tress are generated vary and lead to possible different trees.\n\nOne famous algorithm for decision tree construction is ID3 (Iterative Dichotomiser 3).\nID3 is the precursor to the C4.5 algorithm, and is typically used in the machine learning and natural language processing domains.\nBoth algorithms build decision trees from a set of training data, using the concept of information entropy, however, C4.5 results in better classification utilizing a more efficient splitting criterion.\n\n\n\n\n\\subsection{Textbook ID3}\\label{s:id3}\n\nThe ID3 algorithm was first introduced in \\cite{quinlan1986induction} and assumes that each attribute is categorical, such as the aforementioned attribute ``Age Groups\" which is separated in four disjoint categories; ``Infant\", ``Adolescent\", ``Child\" and ``Adult\".\n\nID3 algorithm constructs the classification tree top-down in a recursive fashion.\nThe idea is to find the \\textit{best} attribute that classifies the transactions.\nAt start, the algorithm searches and chooses the best attribute for the root node, and consecutively the remaining transactions are partitioned by it.\nOn each partition, ID3 is then recursively called.\n\nThe \\textit{best} attribute is defined as the attribute that has the smallest entropy -- or in other words, the best information gain.\nLet $T$ be a set of transactions, $C$ the class attribute and $A$ some non-class attribute.\nOn each iteration, ID3 iterates through every unused attribute $A$ of the dataset and calculates the entropy $H_C(T)$ (equation \\ref{eq:entropy} and algorithm \\ref{a:id3-entropy-simple}) for every subset $T$ that results from splitting the dataset on attribute $A$.\n\n\\import{./}{algorithms/entropy_textbook.tex}\n\n\\begin{equation}\\label{eq:entropy}\n  H_C(T) = \\sum_{i=1}^{l} - \\frac{\\mid T(c_i) \\mid}{\\mid T \\mid} log{\\frac{\\mid T(c_i) \\mid}{\\mid T \\mid}}\n\\end{equation}\n\nThe idea is to identify the class of a transaction $t$, given that the value of $A$ has been obtained.\nLet $A$ obtain values $a_1, \\dots, a_m$ and let $T(a_j)$ be the transactions obtaining value $a_j$ for $A$.\nThen, the conditional information of $T$ given $A$, is given from equation \\ref{eq:TgivenA}.\n\n\\import{./}{algorithms/gain_textbook.tex}\n\n\\import{./}{algorithms/best_textbook.tex}\n\n\\begin{equation}\\label{eq:TgivenA}\n  H_C(T \\mid A) = \\sum_{j=1}^{m} - \\frac{\\mid T(a_j) \\mid}{\\mid T \\mid} H_C(T(a_j))\n\\end{equation}\n\n\\begin{equation}\\label{eq:gain}\n  Gain(A) = H_C(T) - H_C(T \\mid A)\n\\end{equation}\n\n\nFinally, the set $T$ is then split by the selected attribute $A$ (best-attribute algorithm \\ref{a:id3-best-simple}) that has the maximum gain (equation \\ref{eq:gain} and algorithm \\ref{a:id3-gain-simple}) -- or equivalently minimum $H_C(T \\mid A)$ -- to produce subsets of the data.\nThe algorithm continues to recurse on each subset, considering only attributes never selected before.\n\nThe \\f{AllExamplesSame} (see algorithm \\ref{a:id3-same-simple}) procedure is used to determine if all transactions are of the same class, by checking the value of $classAttribute$ for each transaction.\nIt returns $true$ if they are, $false$ otherwise.\n\n\\import{./}{algorithms/allsame_textbook.tex}\n\nThe \\f{MostCommonLabel} (algorithm \\ref{a:id3-most-common-label-simple}) procedure returns the class label that is most common in all available transactions.\n\n\\import{./}{algorithms/most_common_label_textbook.tex}\n\nThe recursive \\f{ID3} algorithm (see algorithm \\ref{a:id3-simple} shown below) has the following structure with three halting conditions.\n\\begin{enumerate}\n  \\item If the set of remaining attributes is empty, then the algorithm returns the label that is most common in all transactions as a leaf (lines 2-3).\n  \\item If all transactions are of the same class, then the algorithm returns this class as a leaf (lines 4-5).\n  \\item If none of the above conditions hold, then the algorithm finds the best splitting attribute (using algorithm \\ref{a:id3-best-simple}) and makes a branch for every possible value of that attribute (lines 7-19).\n\\end{enumerate}\n\n\\import{./}{algorithms/id3_textbook.tex}\n\n\n\n\\subsection{Privacy Preserving ID3}\\label{s:pp-id3}\n\nIn the previous subsection we described the ID3 algorithm which operates on public data.\nWe should now describe the privacy\\hyp preserving version of the same algorithm, where all the transactions (\\textit{examples}) from which the algorithm builds the tree are private data.\n\nFirst of all, a key difference from the textbook algorithm is the lack of ability to maintain subsets of the transactions based on private conditions.\nIn particular, as you can see in line 11 of algorithm \\ref{a:id3-simple}, we wish to keep a subset of all $examples$ that have a certain value in the $bestAttribute$\n column.\n\nAs we cannot have conditional statements on private data, the only thing we can do is to apply the oblivious selection technique described in section \\ref{s:secrec}.\nThus, we are not able to keep only the subset of rows that satisfy our condition.\nA solution to this problem is to define $subset$ as a copy of the $examples$ array.\nWe keep a vector $eq$ (see line 17 of algorithm \\ref{a:id3-pp}) of equal length with $examples$.\nThe value of $eq[i]$ is $\\enc{1}$ if $examples[bestAttribute]$ is equal to $v_i$, or $\\enc{0}$ otherwise.\nSince the values of $eq$ are encrypted, we perform a vector multiplication between $eq$ and $examples$ so the result will be identical to $examples$ for ever row $i$ that the condition holds ($eq[i]$ is equal to $\\enc{1}$), and $\\enc{0}$ otherwise.\nThen we add a dummy row $[\\enc{-1}, \\enc{-1}, \\dots, \\enc{-1}]$ (a row of all $\\enc{-1}$, denoted as just $\\enc{-1}$ for simplicity) to all rows that don't satisfy the condition (using multiplication with $\\enc{1} - eq$).\nThe resulting array has all rows from $examples$ that satisfy the condition, and rows full of $\\enc{-1}$ wherever the condition does not hold.\n\nFor that reason, all the algorithms listed below operate on these kinds of ``sets''.\nIn algorithm \\ref{a:id3-count-positives-pp} we describe the \\f{CountPositives} procedure which returns the (encrypted) number of rows that are not the dummy $[\\enc{-1}, \\enc{-1}, \\dots, \\enc{-1}]$ row.\nThe \\f{CountPositives} procedure is equivalent to the call of $Length$ on sets with public data.\n\n\n\\import{./}{algorithms/count_positives.tex}\n\nThe \\f{AllExamplesSame} procedure described in algorithm \\ref{a:id3-same-pp} returns the same result as that in algorithm \\ref{a:id3-same-simple}.\nThe way this is achieved is by counting the number of examples\\myslash transactions that are of class $c_i$, for each possible class $c_i$.\nThe private variable $res$ is initialized to $\\enc{0}$, and gets increased if any of those counts is equal to the total number of examples, \\textit{i.e.} all examples are of that class.\nIf $res$ is greater than $\\enc{0}$ (equal to $\\enc{1}$) then all the examples have the same class.\n\n\\import{./}{algorithms/allsame_pp.tex}\n\nSimilarly to the \\f{AllExamplesSame} procedure, the \\f{MostCommonLabel} procedure also maintains the transaction counts for each possible class $c_i$.\nUsing the technique described in algorithm \\ref{a:max}, we obliviously keep the maximum count and the class label corresponding to that count, which is returned.\n\n\\import{./}{algorithms/most_common_label_pp.tex}\n\nThe \\f{Best} procedure obliviously chooses the attribute that has the greatest information gain.\nThis attribute is considered to be the best to split the dataset on an will be included in an output tree node.\nThat is why this attribute can be handled as public data (note the usage of the \\f{Declassify} operator in line 10) after it has been privately computed.\n\n\n\\import{./}{algorithms/best_pp.tex}\n\nAs in algorithms \\ref{a:id3-entropy-simple} and \\ref{a:id3-gain-simple}, procedures \\f{Entropy} and \\f{InformationGain} (algorithms \\ref{a:id3-entropy-pp}, \\ref{a:id3-gain-pp}) compute the entropy of a set of transactions, and an attribute's information gain respectively.\nThe key differences with the previously described textbook algorithms include the usage of \\f{CountPositives} procedure instead of \\f{Length}, due to the difference in the sets involved in the computation, and the modified $log_2$ function that handles zero input.\nAlso, note that the subsets (algorithm \\ref{a:id3-gain-pp}, line 5) are also constructed with the technique described in the beginning of this section.\n\n\n\\import{./}{algorithms/entropy_pp.tex}\n\\import{./}{algorithms/gain_pp.tex}\n\nThe complete \\f{ID3} procedure is described in algorithm \\ref{a:id3-pp}.\nIn lines 6-11 of the algorithm we retrieve class label that is same to all examples ad return it.\nIn order to do that, we cannot just take a random's example value in the $classAttribute$ column.\nWe should make sure that this is not a dummy ($\\enc{-1}$) example (line 8).\nThe rest of the algorithm is quite similar to the textbook one.\nThe differences mainly include the subsets handling. (creation, counting, etc.)\n\n\n\\import{./}{algorithms/id3_pp.tex}\n\n\n\\subsubsection{Privacy Assessment}\\label{s:id3-privacy-assessment}\n\nIn privacy-preserving algorithms, all intermediate values should remain private.\nIn many cases, intermediate values may reveal some patterns, and in general sensitive information about the private inputs.\n\nHowever, in the case of ID3, some of these intermediate values are part of the output and eventually will be revealed.\nFor instance, the attributes chosen in each node of the tree will be revealed in the final results.\nThus, there is no reason to trying to protect them during the protocol execution.\nIn the privacy\\hyp preserving ID3, as in all algorithms in this thesis, we explicitly define which values are private (and thus encrypted), and which are public.\n\nAs stated in \\cite{lindell2000privacy}, although the name of the attribute with the highest information gain is revealed, nothing is learned of the actual $H_C(T \\mid A)$ values themselves.\nThis observation holds true for all such cases, since neither the information gain nor any other intermediate values which are not explicitly denoted as public can be leaked.\n\nFor an algorithm to remain private, the requirement is that any information is learned by the algorithm, can also be learned directly from the public input and output \\cite{lindell2000privacy}.\n\nAs mentioned in section \\ref{s:secrec} the \\f{Declassify} operator publishes a private value.\nConsecutively, we reason about the selection of public and private data in the described algorithms and also about the usage of the \\f{Declassify} operator.\n\nFirst of all, we consider the case that all involved parties have the same schema for their data.\nThus, attribute names are known to all parties an should not be considered private information.\n\nLindell and Pinkas have constructed a protocol in \\cite{lindell2000privacy} for privately computing ID3 that works in the two\\hyp party setting.\nThis two\\hyp party protocol is proven to be private.\nHowever that algorithm does not consider the case in where the set of transactions $T$ is empty. Algorithm \\ref{a:id3-pp} is a generalization to the multi\\hyp party setting from the 2\\hyp party protocol that is described in \\cite{lindell2000privacy}.\nThe algorithm also addresses the empty transaction set case.\n\nThe ID3 algorithm (see algorithm \\ref{a:id3-pp}) can terminate (\\textit{i.e.} return a value) in three different cases.\nEach time, the algorithm's output is a node of the resulting tree.\nThat is why, everything that the algorithm returns in any of the three cases should be considered as public data (see \\f{Declassify} operator in lines 9, 11 and public $branches$ variable in line 14).\n\n\\textbf{Empty attribute set:}\nThe first termination channel of the algorithm is when the set of remaining attributes is empty, \\textit{i.e.} when there are no attributes left for the algorithm to check..\nThis information is publicly known since the remaining attributes can be derived from the output tree.\nIn this case, the algorithm returns the most common label of the remaining transactions.\nHere, we use the \\f{Declassify} operator to publish that label and add it as a leaf to the tree.\n\n\\textbf{All examples same:}\nThe second way that algorithm \\ref{a:id3-pp} can terminate, is when all transactions of the dataset are of the same class.\nWe use the \\f{Declassify} operator to determine that information (\\textit{i.e.} if all the dataset is of the same class).\n\n\\textbf{After recursive calls:}\nFinally, if none of the above cases terminate the execution of ID3, the algorithm will recursively add either a leaf or a sub\\hyp tree for each possible value of the selected attribute, and then return.\nIn order to determine whether to add a leaf or a sub\\hyp tree, we publish the information that there are no transactions left in the subset of the dataset that corresponds to a particular value of the selected attribute.\n\nBy observing the output tree, as well as the public input, one can make the following observations.\nWherever there is a leaf node with class $c_i$, one can tell if the set of remaining attributes is empty, simply by observing the path from the root of the tree.\nIf all attributes have been used then the set is empty, otherwise it is not.\nIf the attribute set is not empty, we can deduce that one of two things holds.\nEither all transactions that belong to the current path are of the same class ($c_i$), or that there are no transactions at all in that path.\nThese exact information is also published by algorithm \\ref{a:id3-pp}, with the only difference being that the information published by the algorithm distinguishes between when all transactions are of the same class and the corner case of having no transactions for a particular path of the tree.\n\n\n", "meta": {"hexsha": "2d5413da78376b247459cf1f943daefb85ff753a", "size": 16906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "id3.tex", "max_stars_repo_name": "jimouris/master-thesis", "max_stars_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-08-29T07:51:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-09T12:09:24.000Z", "max_issues_repo_path": "id3.tex", "max_issues_repo_name": "jimouris/master-thesis", "max_issues_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "id3.tex", "max_forks_repo_name": "jimouris/master-thesis", "max_forks_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-08-28T14:33:15.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-28T17:09:24.000Z", "avg_line_length": 72.8706896552, "max_line_length": 296, "alphanum_fraction": 0.7738672661, "num_tokens": 4042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6294633082705449}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[margin=1in]{geometry}\n% Math packages.\n\\usepackage{amsmath,amssymb,amstext,amsfonts}\n% Add figures.\n\\usepackage{graphicx}\n\n% Metadata\n\\author{FCM Student}\n\\title{Example Solution Report for Example Assignment}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Executive Summary}\n\nIn this report, we consider the big-$O$ order of accuracy for the forward, backward, and central finite difference approximations to the derivative of a function. Analytic derivations are confirmed empirically by a method of best-fit line under logarithmic transformation of the absolute error. Results are obtained and discussed for two functions, $f_1(x) = \\sin(x)$ and $f_2(x) = \\exp(-0.5x^2)$.\n\n\\section{Statement of the Problem}\n\nThe numerical approximation of derivatives is important in scientific- and mathematical-computing applications, e.g., in the numerical approximations to ODEs. Finite difference methods, which often depend on some parameter, $h$, can be used for these approximations, and the accuracy and convergence properties of the approximation often depends on the value of this parameter. We analyze these properties for the forward, backward, and central difference approximations, respectively:\n\n\\begin{enumerate}\n    \\item $\\displaystyle F_h[f](x) = \\frac{f(x+h) - f(x)}{h}$\n    \\item $\\displaystyle B_h[f](x) = \\frac{f(x) - f(x-h)}{h}$\n    \\item $\\displaystyle C_h[f](x) = \\frac{f(x+h) - f(x-h)}{2h}$\n\\end{enumerate}\n\n\\section{Description of the Mathematics}\n\n\\subsection{Determining the Order of Accuracy}\n\nA finite difference approximation to the true derivative at some point, $x$, is often $O(h^p)$ for some positive integer, $p$, i.e., the approximation is within $Ch^p$ to the true derivative whenever $0 < h < \\delta$ for some $C$ and appropriately chosen $\\delta$. We derive the value, $p$, for forward, backward, and central difference methods in this section. Throughout, we assume that the function, $f(x)$, can be expanded as necessary using Taylor's theorem.\n\n\\subsubsection{Analytic Derivation of Accuracy Order}\n\\label{subsection:accuracy-order-derivation}\nFirst, \n$$\n    f(t) = f(x) + f'(x)(t-x) + \\frac{f''(\\xi)}{2}(x-h)^2\n$$\nby Taylor expansion to second-order, so that\n$$\n    f(x+h) = f(x) + f'(x)h + \\frac{f''(\\xi)}{2}h^2\n$$\nand finally,\n$$\n    \\frac{f(x+h)-f(x)}{h} = f'(x) + \\frac{f''(\\xi)}{2}h = f'(x) + O(h)\n$$\nThus, $F_h[f](x)$ is $O(h)$. Similarly, evaluating the second-order expansion at $x-h$, we obtain, \n$$\n    \\frac{f(x)-f(x-h)}{h} = f'(x) - \\frac{f''(\\xi)}{2}h = f'(x) + O(h)\n$$\nThus, $B_h[f](x)$ is $O(h)$. Finally, by taking Taylor expansion to third-order,\n$$\n    f(t) = f(x) + f'(x)(t-x) + \\frac{f''(x)}{2}(t-x)^2 + \\frac{f^{(3)}(\\mu)}{6}(t-x)^3\n$$\nwe then obtain,\n$$\n    f(x+h)-f(x-h) = 2f'(x)h  + \\frac{f^{(3)}(\\mu)}{3}h^3\n$$\nThus, $C_h[f](x)$ is $O(h^2)$.\n\n\\subsubsection{Method for Empirical Estimation of Accuracy Order\\protect\\footnote{The method described in this section is equivalent to the ``normal equation\" approach. Ideally, a more numerically stable method should be used to solve this linear least-squares problem, e.g., the $QR$ decomposition.}}\n\n\\label{subsection:accuracy-estimate}\n\nIn this section, we describe a method for estimating the order of the accuracy of a numerical approximation by finding the slope of the best-fit line in log-space. Suppose we use some difference method, $D_h[f](x)$, for approximating the derivative, $f'(x)$.\n\nWe consider some fixed number of $h$ values, say $h_1, h_2, \\ldots, h_m$, and for each, we measure the absolute error,\n$$\n    a_i := |D_{h_i}[f](x)-f'(x)|\n$$\nAssuming $a \\approx Ch^p$ for some $C$ and $p$, we have that $\\log(a) \\approx \\log(C) + p\\log(h)$. We make the transformations, $u_i = \\log(h_i)$, $v_i = \\log(a_i)$, and denote $b=\\log(C)$. The best parameters for the line, $a = b + pu$, are determined in the least-squares sense, i.e., those that minimize:\n$$\n    L(b,p) := \\sum_{i=1}^m \\left(b+pu_i - v_i\\right)^2\n$$\nBy taking partial derivatives, and setting to zero, we obtain a linear system:\n$$\n    \\begin{bmatrix}\n        m          & \\sum_i u_i \\\\\n        \\sum_i u_i & \\sum_i u_i^2\n    \\end{bmatrix}\n    \\begin{bmatrix} b \\\\ p \\end{bmatrix}\n    =\n    \\begin{bmatrix} \\sum_i v_i \\\\ \\sum_i u_iv_i \\end{bmatrix}\n$$\nSolving the system for $b$ and $p$, yields the parameters of the best-fit line,\n$$\n    \\hat{b} = \\frac{\\left(\\sum_i u_i^2\\right) \\left(\\sum_i v_i\\right) - \\left(\\sum_i u_i\\right)\\left(\\sum_i u_iv_i\\right)}{m\\sum_i u_i^2 - \\left(\\sum_i u_i \\right)^2}\n$$\nand\n$$\n    \\hat{p} = \\frac{m\\left(\\sum_i u_iv_i\\right) - \\left(\\sum_i u_i\\right)\\left(\\sum_i v_i\\right)}{m\\sum_i u_i^2 - \\left(\\sum_i u_i \\right)^2}\n$$\nTherefore, $\\hat{p}$, yields an empirical estimate of the order of the accuracy of the finite difference approximation to the derivative.\n\n\\section{Description of the Algorithms and Implementation}\n\nThe finite difference methods each are translated directly into respective functions in \\texttt{C++}, which accept three arguments: (1) a function, $f$, (2) a value, $x$, and (3) a value, $h$. For example, if a function, \\texttt{func}, is previously defined, then \\texttt{fdiff::forward(func, 1.2, 1e-3)} returns the forward difference approximation to the derivative of \\texttt{func} at $x=1.2$ with $h=10^{-3}$.\n\n\\section{Description of the Experimental Design and Results}\n\nFor each finite difference method, function, and $x$-value, the order of the accuracy is first estimated by plotting, in logscale, the obtained absolute error against increasing values of $h$, and visually estimate the slope of the resulting line. We also quantify the slope, employing the method described in Section~\\ref{subsection:accuracy-estimate}. Specifically, we choose $h_i = 10^{-1-6(i-1)/(m-1)}$, $i=1,\\ldots, m$. This yields $m$ values of $h$ that are equally spaced after a $\\log_{10}$ transformation, such that $h_1 = 10^{-1}$ and $h_m = 10^{-7}$. We choose $m=25$.\n\nIn Figures~\\ref{fig:func1-results}~and~\\ref{fig:func2-results}, the absolute error for both required functions, $f_1$ and $f_2$, and the required values of $x$, is plotted against increasing values of $h$. For both functions, we visually estimate in Figures~\\ref{fig:func1-results}~and~\\ref{fig:func2-results} that the forward and backward difference methods yield a slope of approximately 1. We observe, however, that for the central difference method, for both functions and for values of $h$ less than approximately $10^{-5}$ that the absolute error begins to increase and behave more erratically due to floating-point rounding error.\n\nIn Tables~\\ref{tab:order-estimates-f1}~and~\\ref{tab:order-estimates-f2}, the visually estimated slopes match the estimated values from the method of Section~\\ref{subsection:accuracy-estimate}. We find values of approximately 1 (the expected analytic slope) for the forward and backward difference methods for both functions, $f_1$ and $f_2$, and each $x$-value tested, which agrees with the analytic order derived. We find that the estimated order of accuracy for the central difference method is skewed away from $2$ (the expected analytic slope for this method) when values of $h$ below $10^{-5}$. We observe (also in Tables~\\ref{tab:order-estimates-f1}~and~\\ref{tab:order-estimates-f2}) that by excluding these cases where numerical round-off becomes an issue, that we obtain order of accuracy estimates that agree with the analytically derived order of accuracy for the central difference method.\n\n\\section{Conclusions}\n\nOur results illustrate the big-$O$ accuracy of the forward, backward, and central finite difference approximations to the derivative of a function. We found that numerical rounding-error affected the accuracy of the  central difference approximation for values of $h$ below $10^{-5}$. We suspect that similar findings would be obtained for the forward and backward difference methods as well, for smaller values of $h$ than those discussed in this report. This raises the question of how the value of $h$ should be chosen for a given function and finite difference method. Ideally, $h$ would be chosen in such manner so that the difference approximation maintains some acceptable level of error against the true derivative for all desired values of $x$. Another topic not considered in this report is how boundaries should be handled. In some circumstances, it may not be possible to sample a function beyond some point (or set of points), thus rendering some finite difference unsuitable for certain points. Is it possible, for example, to use the higher-order, central difference method in interior regions, and switch to some other second-order finite difference method not discussed here on the boundaries? Answers to such questions and related ones could be studied further in the future or found perhaps in the literature.\n\n\\section{Tables and Figures}\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width=\\textwidth]{../figures/f1.pdf}\n    \\caption{Error results for $f_1(x) = \\sin(x)$ for the three difference methods, shown in log scale.}\n    \\label{fig:func1-results}\n\\end{figure}\n\n\\begin{figure}[!hb]\n    \\centering\n    \\includegraphics[width=\\textwidth]{../figures/f2.pdf}\n    \\caption{Error results for $f_2(x) = \\exp(-0.5x^2)$ for the three difference methods, shown in log scale.}\n    \\label{fig:func2-results}\n\\end{figure}\n\n\\begin{table}[!ht]\n    \\centering\n    \\begin{tabular}{|c|c|c|c|c|}\n        \\hline\n                & Forward & Backward & Central & Central ($< 10^{-5}$ excluded) \\\\\n        \\hline\n        $x=1.0$ & 1.0008  & 0.9995   & 1.3607  & 1.9944 \\\\\n        \\hline\n        $x=2.0$ & 0.9997  & 1.0006   & 1.3454  & 2.0067 \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Order of accuracy estimates ($\\hat{p}$) by method of Section~\\ref{subsection:accuracy-estimate} for $f_1(x) = \\sin(x)$.}\n    \\label{tab:order-estimates-f1}\n\n    \\vspace{0.5in}\n\n    \\begin{tabular}{|c|c|c|c|c|}\n        \\hline\n                & Forward & Backward & Central & Central ($< 10^{-5}$ excluded) \\\\\n        \\hline\n        $x=1.1$ & 1.0089 & 0.9853   & 1.3629  & 2.0021  \\\\\n        \\hline\n        $x=2.1$ & 0.9984 & 1.0014   & 1.2977  & 1.9916  \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Order of accuracy estimates ($\\hat{p}$) by method of Section~\\ref{subsection:accuracy-estimate} for $f_2(x) = \\exp(-0.5x^2)$.}\n    \\label{tab:order-estimates-f2}\n\\end{table}\n\n\\end{document}\n", "meta": {"hexsha": "652794244711752fd81298ca8f9a5264ac21951f", "size": 10393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/acm-computing-seminar/resources/prog/example-assignment/report/report.tex", "max_stars_repo_name": "notmatthancock/notmatthancock.github.io", "max_stars_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_stars_repo_licenses": ["MIT"], "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/acm-computing-seminar/resources/prog/example-assignment/report/report.tex", "max_issues_repo_name": "notmatthancock/notmatthancock.github.io", "max_issues_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "teaching/acm-computing-seminar/resources/prog/example-assignment/report/report.tex", "max_forks_repo_name": "notmatthancock/notmatthancock.github.io", "max_forks_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_forks_repo_licenses": ["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.95625, "max_line_length": 1328, "alphanum_fraction": 0.7057634947, "num_tokens": 3030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8757869997529962, "lm_q1q2_score": 0.6293356271089569}}
{"text": "\n\\subsection{Marshallian demand}\n\nWe can write a demand function:\n\n\\(x_i=f(I, \\mathbf p)\\)\n\nWe can derive this from the first-order conditions of a specific utility function.\n\n\n", "meta": {"hexsha": "ef4d8dbca3b8639ecc4b692153594f29d18da692", "size": 177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/02-02-marshall.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/02-02-marshall.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/02-02-marshall.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.0909090909, "max_line_length": 82, "alphanum_fraction": 0.7457627119, "num_tokens": 43, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6293356265626624}}
{"text": "\\section{Model and semantics}\n\n\\ralf{What also needs to be done here: Define uPred and its later function; define black later; define the resource CMRA}\n\nThe semantics closely follows the ideas laid out in~\\cite{catlogic}.\nWe just repeat some of the most important definitions here.\n\nAn \\emph{ordered family of equivalence relations} (o.f.e.\\@) is a pair\n$(X,(\\nequiv{n})_{n\\in\\mathbb{N}})$, with $X$ a set, and each $\\nequiv{n}$ \nan equivalence relation over $X$ satisfying\n\\begin{itemize}\n\t\\item $\\All x,x'. x \\nequiv{0} x',$\n\t\\item $\\All x,x',n. x \\nequiv{n+1} x' \\implies x \\nequiv{n} x',$\n\t\\item $\\All x,x'. (\\All n. x\\nequiv{n} x') \\implies x = x'.$\n\\end{itemize}\n\\a\nLet $(X,(\\nequivset{n}{X})_{n\\in\\mathbb{N}})$ and\n$(Y,(\\nequivset{n}{Y})_{n\\in\\mathbb{N}})$ be o.f.e.'s. A function $f:\nX\\to Y$ is \\emph{non-expansive} if,   for all $x$, $x'$ and $n$,\n\\[\nx \\nequivset{n}{X} x' \\implies \nfx \\nequivset{n}{Y} f x'.\n\\]\nLet $(X,(\\nequiv{n})_{n\\in\\mathbb{N}})$ be an o.f.e.\nA sequence $(x_i)_{i\\in\\mathbb{N}}$ of elements in $X$ is a\n\\emph{chain} (aka \\emph{Cauchy sequence}) if\n\\[\n\\All k. \\Exists n. \\All i,j\\geq n. x_i \\nequiv{k} x_j.\n\\]\nA \\emph{limit} of a chain $(x_i)_{i\\in\\mathbb{N}}$ is an element\n$x\\in X$ such that\n\\[\n\\All n. \\Exists k. \\All i\\geq k. x_i \\nequiv{n} x.\n\\]\nAn o.f.e.\\ $(X,(\\nequiv{n})_{n\\in\\mathbb{N}})$ is \\emph{complete} \nif all chains have a limit.\nA complete o.f.e.\\ is called a c.o.f.e.\\ (pronounced ``coffee'').\nWhen the family of equivalence relations is clear from context we\nsimply\nwrite $X$ for a c.o.f.e.\\ $(X,(\\nequiv{n})_{n\\in\\mathbb{N}})$.\n\n\nLet $\\cal U$ be the category of c.o.f.e.'s and nonexpansive maps.\n\nProducts and function spaces are defined as follows.\nFor c.o.f.e.'s $(X,(\\nequivset{n}{X})_{n\\in\\mathbb{N}})$ and\n$(Y,(\\nequivset{n}{Y})_{n\\in\\mathbb{N}})$, their product \nis \n$(X\\times Y, (\\nequiv{n})_{n\\in\\mathbb{N}}),$\nwhere\n\\[\n(x,y) \\nequiv{n} (x',y') \\iff\nx \\nequiv{n} x' \\land\ny \\nequiv{n} y'.\n\\]\nThe function space is\n\\[\n(\\{\\, f : X\\to Y \\mid f \\text{ is non-expansive}\\,\\}, (\\nequiv{n})_{n\\in\\mathbb{N}}),\n\\]\nwhere\n\\[\nf \\nequiv{n} g \\iff\n\\All x. f(x)  \\nequiv{n}  g(x).\n\\]\n\nFor a c.o.f.e.\\ $(X,(\\nequiv{n}_{n\\in\\mathbb{N}}))$, \n$\\latert (X,(\\nequiv{n}_{n\\in\\mathbb{N}}))$ is the c.o.f.e.\\@\n$(X,(\\nequivB{n}_{n\\in\\mathbb{N}}))$,  where\n\\[\nx \\nequivB{n} x' \\iff \\begin{cases}\n\\top\t&\\IF n=0 \\\\\nx \\nequiv{n-1} x' &\\IF n>0\n\\end{cases}\n\\]\n\n(Sidenote: $\\latert$ extends to a functor on $\\cal U$ by the identity\naction on morphisms).\n\n\n\\subsection{Semantic structures: propositions}\n\\ralf{This needs to be synced with the Coq development again.}\n\n\\[\n\\begin{array}[t]{rcl}\n%  \\protStatus &::=& \\enabled \\ALT \\disabled \\\\[0.4em]\n\\textdom{Res} &\\eqdef&\n\\{\\, \\rs = (\\pres, \\ghostRes) \\mid\n\\pres \\in \\textdom{State} \\uplus \\{\\munit\\} \\land \\ghostRes \\in \\mcarp{\\monoid} \\,\\} \\\\[0.5em]\n(\\pres, \\ghostRes) \\rtimes\n(\\pres', \\ghostRes') &\\eqdef&\n\\begin{cases}\n(\\pres, \\ghostRes \\mtimes \\ghostRes')  & \\mbox{if $\\pres' = \\munit$ and $\\ghostRes \\mtimes \\ghostRes' \\neq \\mzero$} \\\\\n(\\pres', \\ghostRes \\mtimes \\ghostRes') & \\mbox{if $\\pres = \\munit$ and $\\ghostRes \\mtimes \\ghostRes' \\neq \\mzero$}\n\\end{cases}\n\\\\[0.5em]\n%\n\\rs \\leq \\rs' & \\eqdef &\n\\Exists \\rs''. \\rs' = \\rs \\rtimes \\rs''\\\\[1em]\n%\n\\UPred(\\textdom{Res}) &\\eqdef& \n\\{\\, p \\subseteq \\mathbb{N} \\times \\textdom{Res} \\mid\n\\All (k,\\rs) \\in p.\n\\All j\\leq k.\n\\All \\rs' \\geq \\rs.\n(j,\\rs')\\in p \\,\\}\\\\[0.5em]\n\\restr{p}{k} &\\eqdef& \n\\{\\, (j, \\rs) \\in p \\mid j < k \\,\\}\\\\[0.5em]\np \\nequiv{n} q & \\eqdef & \\restr{p}{n} = \\restr{q}{n}\\\\[1em]\n%\n\\textdom{PreProp} & \\cong  &\n\\latert\\big( \\textdom{World} \\monra \\UPred(\\textdom{Res})\n\\big)\\\\[0.5em]\n%\n\\textdom{World} & \\eqdef &\n\\mathbb{N} \\fpfn \\textdom{PreProp}\\\\[0.5em]\n%\nw \\nequiv{n} w' & \\eqdef & \nn = 0 \\lor\n\\bigl(\\dom(w) = \\dom(w') \\land \\All i\\in\\dom(w). w(i) \\nequiv{n} w'(i)\\bigr)\n\\\\[0.5em]\n%\nw \\leq w' & \\eqdef & \n\\dom(w) \\subseteq \\dom(w') \\land \\All i \\in \\dom(w). w(i) = w'(i) \n\\\\[0.5em]\n%\n\\textdom{Prop} & \\eqdef & \\textdom{World} \\monra \\UPred(\\textdom{Res})\n\\end{array}\n\\]\n\nFor $p,q\\in\\UPred(\\textdom{Res})$ with $p \\nequiv{n} q$ defined\nas above, $\\UPred(\\textdom{Res})$ is a \nc.o.f.e.\n\n$\\textdom{Prop}$ is a c.o.f.e., which exists by America and Rutten's theorem~\\cite{America-Rutten:JCSS89}.\nWe do not need to consider how the object is constructed. \nWe only need the isomorphism, given by maps\n\\begin{align*}\n\t\\wIso &: \\latert \\bigl(World \\monra \\UPred(\\textdom{Res})\\bigr) \\to \\textdom{PreProp} \\\\\n\t\\wIso^{-1} &: \\textdom{PreProp} \\to \\latert \\bigl(World \\monra \\UPred(\\textdom{Res})\\bigr)\n\\end{align*}\nwhich are inverses to each other. \nNote: this is an isomorphism in $\\cal U$, i.e., $\\wIso$ and\n$\\wIso^{-1}$ are both non-expansive.\n\n$\\textdom{World}$ is a c.o.f.e.\\ with the family of equivalence\nrelations defined as shown above.\n\n\\subsection{Semantic structures: types and environments}\n\nFor a set $X$, write $\\Delta X$ for the discrete c.o.f.e.\\ with $x \\nequiv{n}\nx'$ iff $n = 0$ or $x = x'$\n\\[\n\\begin{array}[t]{@{}l@{\\ }c@{\\ }l@{}}\n\\Sem{\\textsort{Unit}} &\\eqdef& \\Delta \\{ \\star \\} \\\\\n\\Sem{\\textsort{InvName}} &\\eqdef& \\Delta \\mathbb{N}  \\\\\n\\Sem{\\textsort{InvMask}} &\\eqdef& \\Delta \\pset{\\mathbb{N}} \\\\\n\\Sem{\\textsort{Monoid}} &\\eqdef& \\Delta |\\monoid|\n\\end{array}\n\\qquad\\qquad\n\\begin{array}[t]{@{}l@{\\ }c@{\\ }l@{}}\n\\Sem{\\textsort{Val}} &\\eqdef& \\Delta \\textdom{Val} \\\\\n\\Sem{\\textsort{Exp}} &\\eqdef& \\Delta \\textdom{Exp} \\\\\n\\Sem{\\textsort{Ectx}} &\\eqdef& \\Delta \\textdom{Ectx} \\\\\n\\Sem{\\textsort{State}} &\\eqdef& \\Delta \\textdom{State} \\\\\n\\end{array}\n\\qquad\\qquad\n\\begin{array}[t]{@{}l@{\\ }c@{\\ }l@{}}\n\\Sem{\\sort \\times \\sort'} &\\eqdef& \\Sem{\\sort} \\times \\Sem{\\sort} \\\\\n\\Sem{\\sort \\to \\sort'} &\\eqdef& \\Sem{\\sort} \\to \\Sem{\\sort} \\\\\n\\Sem{\\Prop} &\\eqdef& \\textdom{Prop} \\\\\n\\end{array}\n\\]\n\nThe balance of our signature $\\Sig$ is interpreted as follows.\nFor each base type $\\type$ not covered by the preceding table, we pick an object $X_\\type$ in $\\cal U$ and define\n\\[\n\\Sem{\\type} \\eqdef X_\\type\n\\]\nFor each function symbol $\\sigfn : \\type_1, \\dots, \\type_n \\to \\type_{n+1} \\in \\SigFn$, we pick an arrow $\\Sem{\\sigfn} : \\Sem{\\type_1} \\times \\dots \\times \\Sem{\\type_n} \\to \\Sem{\\type_{n+1}}$ in $\\cal U$.\n\nAn environment $\\vctx$ is interpreted as the set of\nmaps $\\rho$, with $\\dom(\\rho) = \\dom(\\vctx)$ and\n$\\rho(x)\\in\\Sem{\\vctx(x)}$,\nand \n$\\rho\\nequiv{n} \\rho' \\iff n=0 \\lor \\bigl(\\dom(\\rho)=\\dom(\\rho') \\land\n\\All x\\in\\dom(\\rho). \\rho(x) \\nequiv{n} \\rho'(x)\\bigr)$.\n\n\\ralf{Re-check all the following definitions with the Coq development.}\n%\\typedsection{Validity}{valid : \\pset{\\textdom{Prop}} \\in Sets}\n%\n%\\begin{align*}\n%valid(p) &\\iff \\All n \\in \\mathbb{N}. \\All \\rs \\in \\textdom{Res}. \\All W \\in \\textdom{World}. (n, \\rs) \\in p(W)\n%\\end{align*}\n\n\\typedsection{Later modality}{\\later : \\textdom{Prop} \\to \\textdom{Prop} \\in {\\cal U}}\n\n\\begin{align*}\n\t\\later p &\\eqdef \\Lam W. \\{\\, (n + 1, r) \\mid (n, r) \\in p(W) \\,\\} \\cup \\{\\, (0, r) \\mid r \\in \\textdom{Res} \\,\\}\n\\end{align*}\n\\begin{lem}\n\t$\\later{}$ is well-defined: $\\later {p}$ is a valid proposition (this amounts to showing non-expansiveness), and $\\later{}$ itself is a \\emph{contractive} map.\n\\end{lem}\n\n\\typedsection{Always modality}{\\always{} : \\textdom{Prop} \\to \\textdom{Prop} \\in {\\cal U}}\n\n\\begin{align*}\n\t\\always{p} \\eqdef \\Lam W. \\{\\, (n, r) \\mid (n, \\munit) \\in p(W) \\,\\}\n\\end{align*}\n\\begin{lem}\n\t$\\always{}$ is well-defined: $\\always{p}$ is a valid proposition (this amounts to showing non-expansiveness), and $\\always{}$ itself is a non-expansive map.\n\\end{lem}\n\n% PDS: p \\Rightarrow q not defined.\n%\\begin{lem}\\label{lem:always-impl-valid}\n%\\begin{align*}\n%&\\forall p, q \\in \\textdom{Prop}.~\\\\\n%&\\qquad\n%  (\\forall n \\in \\mathbb{N}.~\\forall \\rs \\in \\textdom{Res}.~\\forall W \\in \\textdom{World}.~(n, \\rs) \\in p(W) \\Rightarrow (n, \\rs) \\in q(W)) \\Leftrightarrow~valid(\\always{(p \\Rightarrow q)})\n%\\end{align*}\n%\\end{lem}\n\n\\typedsection{Invariant definition}{inv : \\Delta(\\mathbb{N}) \\times \\textdom{Prop} \\to \\textdom{Prop} \\in {\\cal U}}\n\\begin{align*}\n\t\\mathit{inv}(\\iota, p) &\\eqdef \\Lam W. \\{\\, (n, r) \\mid \\iota\\in\\dom(W) \\land W(\\iota) \\nequiv{n+1}_{\\textdom{PreProp}} \\wIso(p) \\,\\}\n\\end{align*}\n\\begin{lem}\n\t$\\mathit{inv}$ is well-defined: $\\mathit{inv}(\\iota, p)$ is a valid proposition (this amounts to showing non-expansiveness), and $\\mathit{inv}$ itself is a non-expansive map.\n\\end{lem}\n\n\\typedsection{World satisfaction}{\\wsat{-}{-}{-}{-} : \n\t\\textdom{State} \\times\n\t\\pset{\\mathbb{N}} \\times\n\t\\textdom{Res} \\times\n\t\\textdom{World} \\to \\psetdown{\\mathbb{N}} \\in {\\cal U}}\n\\ralf{Make this Dave-compatible: Explicitly compose all the things in $s$}\n\\begin{align*}\n\t\\wsat{\\state}{\\mask}{\\rs}{W} &=\n\t\\begin{aligned}[t]\n\t\t\\{\\, n + 1 \\in \\mathbb{N} \\mid &\\Exists  \\rsB:\\mathbb{N} \\fpfn \\textdom{Res}. (\\rs \\rtimes \\rsB).\\pres = \\state \\land{}\\\\\n\t\t&\\quad \\All \\iota \\in \\dom(W). \\iota \\in \\dom(W) \\leftrightarrow \\iota \\in \\dom(\\rsB) \\land {}\\\\\n\t\t&\\quad\\quad \\iota \\in \\mask \\ra (n, \\rsB(\\iota)) \\in \\wIso^{-1}(W(\\iota))(W) \\,\\} \\cup \\{ 0 \\}\n\t\\end{aligned}\n\\end{align*}\n\\begin{lem}\\label{lem:fullsat-nonexpansive}\n\t$\\wsat{-}{-}{-}{-}$ is well-defined: It maps into $\\psetdown{\\mathbb{N}}$. (There is no need for it to be a non-expansive map, it doesn't itself live in $\\cal U$.)\n\\end{lem}\n\n\\begin{lem}\\label{lem:fullsat-weaken-mask}\n\t\\begin{align*}\n\t\t\\MoveEqLeft\n\t\t\\All \\state \\in \\Delta(\\textdom{State}).\n\t\t\\All \\mask_1, \\mask_2 \\in \\Delta(\\pset{\\mathbb{N}}).\n\t\t\\All \\rs, \\rsB \\in \\Delta(\\textdom{Res}).\n\t\t\\All W \\in \\textdom{World}. \\\\&\n\t\t\\mask_1 \\subseteq \\mask_2 \\implies (\\wsat{\\state}{\\mask_2}{\\rs}{W}) \\subseteq (\\wsat{\\state}{\\mask_1}{\\rs}{W})\n\t\\end{align*}\n\\end{lem}\n\n\\begin{lem}\\label{lem:nequal_ext_world}\n\t\\begin{align*}\n\t\t&\n\t\t\\All n \\in \\mathbb{N}.\n\t\t\\All W_1, W_1', W_2 \\in \\textdom{World}.\n\t\tW_1 \\nequiv{n} W_2 \\land W_1 \\leq W_1' \\implies \\Exists W_2' \\in \\textdom{World}. W_1' \\nequiv{n} W_2' \\land W_2 \\leq W_2'\n\t\\end{align*}\n\\end{lem}\n\n\\typedsection{Timeless}{\\textit{timeless} : \\textdom{Prop} \\to \\textdom{Prop}}\n\n\\begin{align*}\n\t\\textit{timeless}(p) \\eqdef \n\t\\begin{aligned}[t]\n\t\t\\Lam W.\n\t\t\\{\\, (n, r) &\\mid \\All W' \\geq W. \\All k \\leq n. \\All r' \\in \\textdom{Res}. \\\\\n\t\t&\\qquad\n\t\tk > 0 \\land (k - 1, r') \\in p(W') \\implies (k, r') \\in p(W') \\,\\}\n\t\\end{aligned}\n\\end{align*}\n\n\\begin{lem}\n\t\\textit{timeless} is well-defined: \\textit{timeless}(p) is a valid proposition, and \\textit{timeless} itself is a non-expansive map.\n\\end{lem}\n\n% PDS: \\Ra undefined.\n%\\begin{lem}\n%\\begin{align*}\n%&\n%  \\All p \\in \\textdom{Prop}.\n%  \\All \\mask \\in \\pset{\\mathbb{N}}.\n%valid(\\textit{timeless}(p) \\Ra (\\later p \\vs[\\mask][\\mask] p))\n%\\end{align*}\n%\\end{lem}\n\n\\typedsection{View-shift}{\\mathit{vs} : \\Delta(\\pset{\\mathbb{N}}) \\times \\Delta(\\pset{\\mathbb{N}}) \\times \\textdom{Prop} \\to \\textdom{Prop} \\in {\\cal U}}\n\\begin{align*}\n\t\\mathit{vs}_{\\mask_1}^{\\mask_2}(q) &= \\Lam W.\n\t\\begin{aligned}[t]\n\t\t\\{\\, (n, \\rs) &\\mid \\All W_F \\geq W. \\All \\rs_F, \\mask_F, \\state. \\All k \\leq n.\\\\\n\t\t&\\qquad \n\t\tk \\in (\\wsat{\\state}{\\mask_1 \\cup \\mask_F}{\\rs \\rtimes \\rs_F}{W_F}) \\land k > 0 \\land \\mask_F \\sep (\\mask_1 \\cup \\mask_2) \\implies{} \\\\\n\t\t&\\qquad\n\t\t\\Exists W' \\geq W_F. \\Exists \\rs'. k \\in (\\wsat{\\state}{\\mask_2 \\cup \\mask_F}{\\rs' \\rtimes \\rs_F}{W'}) \\land (k, \\rs') \\in q(W')\n\t\t\\,\\}\n\t\\end{aligned}\n\\end{align*}\n\\begin{lem}\n\t$\\mathit{vs}$ is well-defined: $\\mathit{vs}_{\\mask_1}^{\\mask_2}(q)$ is a valid proposition, and $\\mathit{vs}$ is a non-expansive map.\n\\end{lem}\n\n\n%\\begin{lem}\\label{lem:prim_view_shift_trans}\n%\\begin{align*}\n%\\MoveEqLeft\n%  \\All \\mask_1, \\mask_2, \\mask_3 \\in \\Delta(\\pset{\\mathbb{N}}).\n%  \\All p, q \\in \\textdom{Prop}. \\All W \\in \\textdom{World}.\n%  \\All n \\in \\mathbb{N}.\\\\\n%&\n%  \\mask_2 \\subseteq \\mask_1 \\cup \\mask_3 \\land\n%  \\bigl(\\All W' \\geq W. \\All r \\in \\textdom{Res}. \\All k \\leq n. (k, r) \\in p(W') \\implies (k, r) \\in vs_{\\mask_2}^{\\mask_3}(q)(W')\\bigr) \\\\\n%&\\qquad\n%  {}\\implies \\All r \\in \\textdom{Res}. (n, r) \\in vs_{\\mask_1}^{\\mask_2}(p)(W) \\implies (n, r) \\in vs_{\\mask_1}^{\\mask_3}(q)(W)\n%\\end{align*}\n%\\end{lem}\n\n% PDS: E_1 ==>> E_2 undefined.\n%\\begin{lem}\n%\\begin{align*}\n%&\n%  \\forall \\mask_1, \\mask_2, \\mask_3 \\in \\Delta(\\pset{\\mathbb{N}}).~\n%  \\forall p_1, p_2, p_3 \\in \\textdom{Prop}.~\\\\\n%&\\qquad\n%  \\mask_2 \\subseteq \\mask_1 \\cup \\mask_3 \\Rightarrow\n%  valid(((p_1 \\vs[\\mask_1][\\mask_2] p_2) \\land (p_2 \\vs[\\mask_2][\\mask_3] p_3)) \\Rightarrow (p_1 \\vs[\\mask_1][\\mask_3] p_3))\n%\\end{align*}\n%\\end{lem}\n\n%\\begin{lem}\n%\\begin{align*}\n%\\MoveEqLeft\n%  \\All \\iota \\in \\mathbb{N}.\n%  \\All p \\in \\textdom{Prop}.\n%  \\All W \\in \\textdom{World}.\n%  \\All \\rs \\in \\textdom{Res}.\n%  \\All n \\in \\mathbb{N}. \\\\\n%&\n%  (n, \\rs) \\in inv(\\iota, p)(W) \\implies (n, \\rs) \\in vs_{\\{ \\iota \\}}^{\\emptyset}(\\later p)(W)\n%\\end{align*}\n%\\end{lem}\n\n% PDS: * undefined.\n%\\begin{lem}\n%\\begin{align*}\n%&\n%  \\forall \\iota \\in \\mathbb{N}.~\n%  \\forall p \\in \\textdom{Prop}.~\n%  \\forall W \\in \\textdom{World}.~\n%  \\forall \\rs \\in \\textdom{Res}.~\n%  \\forall n \\in \\mathbb{N}.~\\\\\n%&\\qquad\n%  (n, \\rs) \\in (inv(\\iota, p) * \\later p)(W) \\Rightarrow (n, \\rs) \\in vs^{\\{ \\iota \\}}_{\\emptyset}(\\top)(W)\n%\\end{align*}\n%\\end{lem}\n\n% \\begin{lem}\n% \\begin{align*}\n% &\n%   \\forall \\mask_1, \\mask_2 \\in \\Delta(\\pset{\\mathbb{N}}).~\n%   valid(\\bot \\vs[\\mask_1][\\mask_2] \\bot)\n% \\end{align*}\n% \\end{lem}\n\n% PDS: E_1 ==>> E_2 undefined.\n%\\begin{lem}\n%\\begin{align*}\n%&\n%  \\forall p, q \\in \\textdom{Prop}.~\n%  \\forall \\mask \\in \\pset{\\mathbb{N}}.~\n%valid(\\always{(p \\Rightarrow q)} \\Rightarrow (p \\vs[\\mask][\\mask] q))\n%\\end{align*}\n%\\end{lem}\n\n% PDS: E # E' and E_1 ==>> E_2 undefined.\n%\\begin{lem}\n%\\begin{align*}\n%&\n%  \\forall p_1, p_2, p_3 \\in \\textdom{Prop}.~\n%  \\forall \\mask_1, \\mask_2, \\mask \\in \\pset{\\mathbb{N}}.~\n%valid(\\mask \\sep \\mask_1 \\Ra \\mask \\sep \\mask_2 \\Ra (p_1 \\vs[\\mask_1][\\mask_2] p_2) \\Rightarrow (p_1 * p_3 \\vs[\\mask_1 \\cup \\mask][\\mask_2 \\cup \\mask] p_2 * p_3))\n%\\end{align*}\n%\\end{lem}\n\n\\typedsection{Weakest precondition}{\\mathit{wp} : \\Delta(\\pset{\\mathbb{N}}) \\times \\Delta(\\textdom{Exp}) \\times (\\Delta(\\textdom{Val}) \\to \\textdom{Prop}) \\to \\textdom{Prop} \\in {\\cal U}}\n\n% \\begin{align*}\n% \t\\mathit{wp}_\\mask(\\expr, q) &\\eqdef \\Lam W.\n% \t\\begin{aligned}[t]\n% \t\t\\{\\, (n, \\rs) &\\mid \\All W_F \\geq W; k \\leq n; \\rs_F; \\state; \\mask_F \\sep \\mask. k > 0 \\land k \\in (\\wsat{\\state}{\\mask \\cup \\mask_F}{\\rs \\rtimes \\rs_F}{W_F}) \\implies{}\\\\\n% \t\t&\\qquad\n% \t\t(\\expr \\in \\textdom{Val} \\implies \\Exists W' \\geq W_F. \\Exists \\rs'. \\\\\n% \t\t&\\qquad\\qquad\n% \t\tk \\in (\\wsat{\\state}{\\mask \\cup \\mask_F}{\\rs' \\rtimes \\rs_F}{W'}) \\land (k, \\rs') \\in q(\\expr)(W'))~\\land \\\\\n% \t\t&\\qquad\n% \t\t(\\All\\ectx,\\expr_0,\\expr'_0,\\state'. \\expr = \\ectx[\\expr_0] \\land \\cfg{\\state}{\\expr_0} \\step \\cfg{\\state'}{\\expr'_0} \\implies \\Exists W' \\geq W_F. \\Exists \\rs'. \\\\\n% \t\t&\\qquad\\qquad\n% \t\tk - 1 \\in (\\wsat{\\state'}{\\mask \\cup \\mask_F}{\\rs' \\rtimes \\rs_F}{W'}) \\land (k-1, \\rs') \\in wp_\\mask(\\ectx[\\expr_0'], q)(W'))~\\land \\\\\n% \t\t&\\qquad\n% \t\t(\\All\\ectx,\\expr'. \\expr = \\ectx[\\fork{\\expr'}] \\implies \\Exists W' \\geq W_F. \\Exists \\rs', \\rs_1', \\rs_2'. \\\\\n% \t\t&\\qquad\\qquad\n% \t\tk - 1 \\in (\\wsat{\\state}{\\mask \\cup \\mask_F}{\\rs' \\rtimes \\rs_F}{W'}) \\land \\rs' = \\rs_1' \\rtimes \\rs_2'~\\land \\\\\n% \t\t&\\qquad\\qquad\n% \t\t(k-1, \\rs_1') \\in \\mathit{wp}_\\mask(\\ectx[\\textsf{fRet}], q)(W') \\land\n% \t\t(k-1, \\rs_2') \\in \\mathit{wp}_\\top(\\expr', \\Lam\\any. \\top)(W'))\n% \t\t\\,\\}\n% \t\\end{aligned}\n% \\end{align*}\n\\begin{lem}\n\t$\\mathit{wp}$ is well-defined: $\\mathit{wp}_{\\mask}(\\expr, q)$ is a valid proposition, and $\\mathit{wp}$ is a non-expansive map. Besides, the dependency on the recursive occurrence is contractive, so $\\mathit{wp}$ has a fixed-point.\n\\end{lem}\n\n\\begin{lem}\n\t$\\mathit{wp}$ on values and non-mask-changing $\\mathit{vs}$ agree:\n\t\\[ \\mathit{wp}_\\mask(\\val, q) = \\mathit{vs}_{\\mask}^{\\mask}(q \\: \\val)  \\]\n\\end{lem}\n\n\\typedsection{Interpretation of terms}{\\Sem{\\vctx \\proves \\term : \\sort} : \\Sem{\\vctx} \\to \\Sem{\\sort} \\in {\\cal U}}\n\n%A term $\\vctx \\proves \\term : \\sort$ is interpreted as a non-expansive map from $\\Sem{\\vctx}$ to $\\Sem{\\sort}$.\n\n\\begin{align*}\n\t\\Sem{\\vctx \\proves x : \\sort}_\\gamma &= \\gamma(x) \\\\\n\t\\Sem{\\vctx \\proves \\sigfn(\\term_1, \\dots, \\term_n) : \\type_{n+1}}_\\gamma &= \\Sem{\\sigfn}(\\Sem{\\vctx \\proves \\term_1 : \\type_1}_\\gamma, \\dots, \\Sem{\\vctx \\proves \\term_n : \\type_n}_\\gamma) \\ \\WHEN \\sigfn : \\type_1, \\dots, \\type_n \\to \\type_{n+1} \\in \\SigFn \\\\\n\t\\Sem{\\vctx \\proves \\Lam x. \\term : \\sort \\to \\sort'}_\\gamma &=\n\t\\Lam v : \\Sem{\\sort}. \\Sem{\\vctx, x : \\sort \\proves \\term : \\sort'}_{\\gamma[x \\mapsto v]} \\\\\n\t\\Sem{\\vctx \\proves \\term~\\termB : \\sort'}_\\gamma &=\n\t\\Sem{\\vctx \\proves \\term : \\sort \\to \\sort'}_\\gamma(\\Sem{\\vctx \\proves \\termB : \\sort}_\\gamma) \\\\\n\t\\Sem{\\vctx \\proves \\unitval : \\unitsort}_\\gamma &= \\star \\\\\n\t\\Sem{\\vctx \\proves (\\term_1, \\term_2) : \\sort_1 \\times \\sort_2}_\\gamma &= (\\Sem{\\vctx \\proves \\term_1 : \\sort_1}_\\gamma, \\Sem{\\vctx \\proves \\term_2 : \\sort_2}_\\gamma) \\\\\n\t\\Sem{\\vctx \\proves \\pi_i~\\term : \\sort_1}_\\gamma &= \\pi_i(\\Sem{\\vctx \\proves \\term : \\sort_1 \\times \\sort_2}_\\gamma)\n\\end{align*}\n%\n\\begin{align*}\n\t\\Sem{\\vctx \\proves \\mzero : \\textsort{Monoid}}_\\gamma &= \\mzero \\\\\n\t\\Sem{\\vctx \\proves \\munit : \\textsort{Monoid}}_\\gamma &= \\munit \\\\\n\t\\Sem{\\vctx \\proves \\melt \\mtimes \\meltB : \\textsort{Monoid}}_\\gamma &=\n\t\\Sem{\\vctx \\proves \\melt : \\textsort{Monoid}}_\\gamma \\mtimes \\Sem{\\vctx \\proves \\meltB : \\textsort{Monoid}}_\\gamma\n\\end{align*}\n%\n\\begin{align*}\n\t\\Sem{\\vctx \\proves t =_\\sort u : \\Prop}_\\gamma &=\n\t\\Lam W. \\{\\, (n, r) \\mid \\Sem{\\vctx \\proves t : \\sort}_\\gamma \\nequiv{n+1} \\Sem{\\vctx \\proves u : \\sort}_\\gamma \\,\\} \\\\\n\t\\Sem{\\vctx \\proves \\FALSE : \\Prop}_\\gamma &= \\Lam W. \\emptyset \\\\\n\t\\Sem{\\vctx \\proves \\TRUE : \\Prop}_\\gamma &= \\Lam W. \\mathbb{N} \\times \\textdom{Res} \\\\\n\t\\Sem{\\vctx \\proves P \\land Q : \\Prop}_\\gamma &=\n\t\\Lam W. \\Sem{\\vctx \\proves P : \\Prop}_\\gamma(W) \\cap \\Sem{\\vctx \\proves Q : \\Prop}_\\gamma(W) \\\\\n\t\\Sem{\\vctx \\proves P \\lor Q : \\Prop}_\\gamma &=\n\t\\Lam W. \\Sem{\\vctx \\proves P : \\Prop}_\\gamma(W) \\cup \\Sem{\\vctx \\proves Q : \\Prop}_\\gamma(W) \\\\\n\t\\Sem{\\vctx \\proves P \\Ra Q : \\Prop}_\\gamma &=\n\t\\Lam W. \\begin{aligned}[t]\n\t\t\\{\\, (n, r) &\\mid \\All n' \\leq n. \\All W' \\geq W. \\All r' \\geq r. \\\\\n\t\t&\\qquad\n\t\t(n', r') \\in \\Sem{\\vctx \\proves P : \\Prop}_\\gamma(W')~ \\\\\n\t\t&\\qquad \n\t\t\\implies (n', r') \\in \\Sem{\\vctx \\proves Q : \\Prop}_\\gamma(W') \\,\\}\n\t\\end{aligned} \\\\\n\t\\Sem{\\vctx \\proves \\All x : \\sort. P : \\Prop}_\\gamma &=\n\t\\Lam W. \\{\\, (n, r) \\mid \\All v \\in \\Sem{\\sort}. (n, r) \\in \\Sem{\\vctx, x : \\sort \\proves P : \\Prop}_{\\gamma[x \\mapsto v]}(W) \\,\\} \\\\\n\t\\Sem{\\vctx \\proves \\Exists x : \\sort. P : \\Prop}_\\gamma &=\n\t\\Lam W. \\{\\, (n, r) \\mid \\Exists v \\in \\Sem{\\sort}. (n, r) \\in \\Sem{\\vctx, x : \\sort \\proves P : \\Prop}_{\\gamma[x \\mapsto v]}(W) \\,\\}\n\\end{align*}\n%\n\\begin{align*}\n\t\\Sem{\\vctx \\proves \\always{\\prop} : \\Prop}_\\gamma &= \\always{\\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma} \\\\\n\t\\Sem{\\vctx \\proves \\later{\\prop} : \\Prop}_\\gamma &= \\later \\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma\\\\\n\t\\Sem{\\vctx \\proves \\MU x. \\pred : \\sort \\to \\Prop}_\\gamma &=\n\t\\mathit{fix}(\\Lam v : \\Sem{\\sort \\to \\Prop}. \\Sem{\\vctx, x : \\sort \\to \\Prop \\proves \\pred : \\sort \\to \\Prop}_{\\gamma[x \\mapsto v]}) \\\\\n\t\\Sem{\\vctx \\proves \\prop * \\propB : \\Prop}_\\gamma &=\n\t\\begin{aligned}[t]\n\t\t\\Lam W. \\{\\, (n, r) &\\mid \\Exists r_1, r_2. r = r_1 \\bullet r_2 \\land{} \\\\\n\t\t&\\qquad\n\t\t(n, r_1) \\in \\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma \\land{} \\\\\n\t\t&\\qquad\n\t\t(n, r_2) \\in \\Sem{\\vctx \\proves \\propB : \\Prop}_\\gamma \\,\\}\n\t\\end{aligned} \\\\\n\t\\Sem{\\vctx \\proves \\prop \\wand \\propB : \\Prop}_\\gamma &=\n\t\\begin{aligned}[t]\n\t\t\\Lam W. \\{\\, (n, r) &\\mid \\All n' \\leq n. \\All W' \\geq W. \\All r'. \\\\\n\t\t&\\qquad\n\t\t(n', r') \\in \\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma(W') \\land r \\sep r' \\\\\n\t\t&\\qquad\n\t\t\\implies (n', r \\bullet r') \\in \\Sem{\\vctx \\proves \\propB : \\Prop}_\\gamma(W')\n\t\t\\}\n\t\\end{aligned} \\\\\n\t\\Sem{\\vctx \\proves \\knowInv{\\iname}{\\prop} : \\Prop}_\\gamma &=\n\tinv(\\Sem{\\vctx \\proves \\iname : \\textsort{InvName}}_\\gamma, \\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma) \\\\\n\t\\Sem{\\vctx \\proves \\ownGGhost{\\melt} : \\Prop}_\\gamma &=\n\t\\Lam W. \\{\\, (n, \\rs) \\mid \\rs.\\ghostRes \\geq \\Sem{\\vctx \\proves \\melt : \\textsort{Monoid}}_\\gamma \\,\\} \\\\\n\t\\Sem{\\vctx \\proves \\ownPhys{\\state} : \\Prop}_\\gamma &=\n\t\\Lam W. \\{\\, (n, \\rs) \\mid \\rs.\\pres = \\Sem{\\vctx \\proves \\state : \\textsort{State}}_\\gamma \\,\\}\n\\end{align*}\n%\n\\begin{align*}\n\t\\Sem{\\vctx \\proves \\pvsA{\\prop}{\\mask_1}{\\mask_2} : \\Prop}_\\gamma &=\n\t\\textdom{vs}^{\\Sem{\\vctx \\proves \\mask_2 : \\textsort{InvMask}}_\\gamma}_{\\Sem{\\vctx \\proves \\mask_1 : \\textsort{InvMask}}_\\gamma}(\\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma) \\\\\n\t\\Sem{\\vctx \\proves \\dynA{\\expr}{\\pred}{\\mask} : \\Prop}_\\gamma &=\n\t\\textdom{wp}_{\\Sem{\\vctx \\proves \\mask : \\textsort{InvMask}}_\\gamma}(\\Sem{\\vctx \\proves \\expr : \\textsort{Exp}}_\\gamma, \\Sem{\\vctx \\proves \\pred : \\textsort{Val} \\to \\Prop}_\\gamma) \\\\\n\t\\Sem{\\vctx \\proves \\wtt{\\timeless{\\prop}}{\\Prop}}_\\gamma &=\n\t\\textdom{timeless}(\\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma)\n\\end{align*}\n\n\\typedsection{Interpretation of entailment}{\\Sem{\\vctx \\mid \\pfctx \\proves \\prop} : 2 \\in \\mathit{Sets}}\n\n\\[\n\\Sem{\\vctx \\mid \\pfctx \\proves \\propB} \\eqdef\n\\begin{aligned}[t]\n\\MoveEqLeft\n\\forall n \\in \\mathbb{N}.\\;\n\\forall W \\in \\textdom{World}.\\;\n\\forall \\rs \\in \\textdom{Res}.\\; \n\\forall \\gamma \\in \\Sem{\\vctx},\\;\n\\\\&\n\\bigl(\\All \\propB \\in \\pfctx. (n, \\rs) \\in \\Sem{\\vctx \\proves \\propB : \\Prop}_\\gamma(W)\\bigr)\n\\implies (n, \\rs) \\in \\Sem{\\vctx \\proves \\prop : \\Prop}_\\gamma(W)\n\\end{aligned}\n\\]\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"iris\"\n%%% End:\n", "meta": {"hexsha": "2a7fd7bc71354630fdc45237c9731c18a3fdf6fc", "size": 21500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/model.tex", "max_stars_repo_name": "amintimany/iris-backup", "max_stars_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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/model.tex", "max_issues_repo_name": "amintimany/iris-backup", "max_issues_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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/model.tex", "max_forks_repo_name": "amintimany/iris-backup", "max_forks_repo_head_hexsha": "9e98ff8be4b4ca516a497d328aaf31cbae186a6c", "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": 40.5660377358, "max_line_length": 259, "alphanum_fraction": 0.6040465116, "num_tokens": 9147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6293356195735702}}
{"text": "\\section{Alpha-beta search}\n\n\\begin{enumerate}\n    \\item Perform the MiniMax algorithm on the tree in Figure 1, i.e. put a value to each node. Circle the move the root player should do.\n      \\begin{figure}[!ht]\n      \\begin{framed}\n\t  \\centering\n\t  \\includegraphics[width=\\linewidth]{tree.png}\n\t  \\caption{MiniMax}\n      \\end{framed}\n      \\end{figure}\n      \\FloatBarrier\n    \\item Perform the Alpha-Beta algorithm on the tree in Figure 2. At each non terminal node, put the successive values of $\\alpha$ and $\\beta$. Cross out the arcs reaching non visited nodes. Assume a left-to-right node expansion.\n      \\begin{figure}[!ht]\n      \\begin{framed}\n\t  \\centering\n\t  \\includegraphics[width=\\linewidth]{tree.png}\n\t  \\caption{Alpha-Beta, left-to-right expansion}\n      \\end{framed}\n      \\end{figure}\n      \\FloatBarrier\n    \\item Do the same, assuming a right-to-left node expansion instead (Figure 3).\n      \\begin{figure}[!ht]\n      \\begin{framed}\n\t  \\centering\n\t  \\includegraphics[width=\\linewidth]{tree.png}\n\t  \\caption{Alpha-Beta, right-to-left expansion}\n      \\end{framed}\n      \\end{figure}\n      \\FloatBarrier\n    \\item Can the nodes be ordered in such a way that Alpha-Beta pruning can cut off more branches (in a left-to-right node expansion)? If no, explain why; if yes, give the new ordering and the resulting new pruning.\n      \\begin{figure}[!ht]\n      \\begin{framed}\n        The nodes can be ordered in such a way that Alpha-Beta pruning can\n        cut off more branches, as shown in the following tree:\n\n        \\bigskip\n        \\bigskip\n\t  \\centering\n\t  \\includegraphics[width=\\linewidth]{my_tree.png}\n      \\bigskip\n      \\bigskip\n\t  \\caption{Alpha-Beta, left-to-right expansion on ordered tree}\n      \\end{framed}\n      \\end{figure}\n      \\FloatBarrier\n\\end{enumerate}\n\n\\section{Avalam}\n    \\subsection{A basic alpha beta agent}\n    \\subsection{Comparison of two evaluation functions}\n    \\begin{enumerate}\n    \\item[6.] Launch a game where one of the agents is the basic agent described before against another agent where the basic evaluate method has been replaced such that it returns directly the result of Board.get\\_score instead of -1, 0 or 1. Watch the replay of the match. What do you observe? Does one of the agent clearly overcomes the other one? Explain why there is such a difference.\n      \\begin{framed}\n          When the new version of basic agent is Player 1, it clearly\n          overcomes the old version because even with a depth of 2, the\n          differences between the values evaluated are  much more relevant.\n          \\newline\n\n          When the new version of basic agent is Player 2, the old basic\n          agent wins because the improvement does not overcome the advantage\n          from being Player 1. The first moves aren't very good but it gets\n          better and better as the game enfolds catching back nearly all\n          its delay at the end, losing by only 1 point. \\newline\n      \\end{framed}\n\\end{enumerate}\n\n\\subsection{Evaluation function}\n\n    \\begin{enumerate}\n        \\item[7.] Describe precisely your evaluation function.\n        \\begin{framed}\n            In our evaluation fonction, we first start by separating the board positions in three types. If the position is empty we ignore it. If the position is filled a tower of height five, we add (or substract depending on the color of the tower) a fixed score X to the total score of the board. Finally for every positions that doesn't fit the two previous criteria we call the towerScore method. \\newline\n\n            In this towerScore fonction, we calculate the score that should be allowed to the tower depending to various factor. First, if the tower is isolated, we return a fixed score Y such as X > Y, allowing our algorithm to prefer state with more tower of height five than others. The difference is of course not too large so that the algorithm doesn't sacrifice two isolated tower for a tower of height five. \\newline\n\n            If the tower isn't isolated, the algorithm will then determine if the tower is in a simple snapback state wich we define as follow : If a tower of height one or two doesn't have an ally of the same color on which it could jump on and if for every ennemy it could jump on the ennemy can either form a tower of height five or an isolated tower with his next move, then the tower is in a simple snapback state. \\newline\n\n            Of course some pure snapback states are not contained in this description but it was necessary for the evaluation method to run as fast as possible so we kept only the most common and obvious definition of a snapback to speed it up. The other snapack states will still usually be found as the depth increases, but this gives us a safety margin for lower depth computation. \\newline\n\n            Finally if the tower is neither isolated nor in a snapback state, we return a given score depending on the height of the tower at hand. This score is such that a tower of height 1 is worth more than a tower of height 2 which is worth more than a tower of height three or four. Doing so allows our algorithm to reduce the opponent's possibilites if an occasion to do so arises. \\newline\n\n            When our algorithm has computed the score for each position of the board, adding or substracting it depending on the color, we simply return this score as the evaluation of the board. \\newline\n        \\end{framed}\n    \\end{enumerate}\n\n\\subsection{Successors function}\n\n\\begin{enumerate}\n    \\item[8.] Give an upper and a lower bound on the branching factor for a search tree on the Avalam game. Justify your answer.\n    \\begin{framed}\n        For an algorithm that doens't drop branches, we can easily differ that the branching factor will be lower as the game enfolds because every step consume a tower thus the number of action possible keeps decreasing. We can thus easily affirm that the branching factor will be comprised between 292 which is the branching factor of a brand new game and 2 which is the lowest branching factor that could happen for the last move when only two movable towers are left next to each other. The branching factor is thus comprised in the domain $[2, 292]$\n    \\end{framed}\n    \\item[9.] How does the branching factor evolve after a move has been performed? Explain.\n    \\begin{framed}\n        As explained in the previous answer, it will decrease at each step but the quantity by which it decreases is variable as it depends on the neighbours of the moved tower.\n    \\end{framed}\n    \\item[10.] Can you think of states that might be ignored? What do you loose if you ignore successors? Explain.\n    \\begin{framed}\n        There is quite a number of states that could potentially be ignored but doing so might not always be safe as it could drop with it potential for better states. For example, a move that can be safely dropped is when two tower which fill each other are next to each other, we can safely ignore states where the current player give a five tower to the ennemy by making an ennemy tower jump on his tower. \\newline\n\n        Similarly we can drop moves where the current player isolate a tower for the ennemy but it might not be safe as giving that tower to the ennemy may allows us to make more points later on. Dropping tower is thus a dangerous but worthy gamble.\n    \\end{framed}\n    \\item[11.] Describe your successors function.\n    \\begin{framed}\n        Our successor function is quite simple, we simply call the get\\_sorted\\_action() method which does the same as the original get\\_actions() except that it sorts the actions it returns so that the most interesting ones tend to be yield towards the beginning. It will also drops extremely useless possibilities like a one surrounded by seven or more ones other ones.\n\n        It then plays those action on a clone of the old board and yields the resulting new boards in succession\n    \\end{framed}\n\\end{enumerate}\n\n\\subsection{Cut-off function}\n\n\\begin{enumerate}\n    \\item[12.] The \\verb#cutoff# method receives an argument called depth . Explain precisely what is called the \\textit{depth} in the \\verb#minimax.py# implementation.\n    \\begin{framed}\n        The depth argument is the current depth at which the minmax function is in the search tree. Thus the root will be at depth 0, its branches will be at the two and so forth and so on.\n    \\end{framed}\n    \\item[13.] Explain why it might be useful (for the Avalam contest) to cut off the search for another reason than the depth. Would it be interesting to consider a changing cutoff function (i.e. it changes according to the advancement of the game).\n    \\begin{framed}\n        It might be usefull if our algorithm takes too much time to compute a given depth, interrupting the execution and allowing for it to recompute at a lower depth may be wiser than keep going on and wasting lots of time credit. \\newline\n\n        Changing the depth depending on the game state would be an excellent decision (which we also implemented) as the time to compute a given depth will be reduced as the game enfolds. As such a depth 2 which took 6 seconds at the beginning of the game might take only half a second at step 20. Implementing a changing cutoff function is thus a must have for the contest as seeing deeper allows an algorithm to perform better results.\n    \\end{framed}\n    \\item[14.] Describe your cut-off function.\n    \\begin{framed}\n        Our cutoff function will use a precomputed maximum depth and a precomputed maximum time to run and proceeds as follow :\n\n        \\begin{itemize}\n            \\item A computation with a \\textbf{depth lower than 3} will always wait to finish and will never be interrupted due to a lack of time as we consider that we need at least that to play a decent move.\n            \\item If the \\textbf{depth is bigger than 2 and we aren't in lack of time}, cutoff will only return true if the current depth equals the maximum allowed depth that we precomputed earlier.\n            \\item If the depth is \\textbf{bigger than 2 but we exceeded our decided time limit} for this step, our algorithm will process the rest of the tree in depth 2 to avoid wasting too much time. We infered after much reflexion that it would be better to play a good move where we have fully seen the outcome rather than playing blind and see what happens but it is also better to play blind than to play what we know is a bad move. Thus this seemed to be the best solution and this works normally well with our algorithm as we reorder the subtree in such a way that the most interesting actions will be tested toward the beginning.\n        \\end{itemize}\n    \\end{framed}\n\\end{enumerate}\n\n\\subsection{A Smart Alpha-Beta Agent}\n\n\\begin{enumerate}\n    \\item[15.] Upload your agent to the INGInious \\textit{Assignment 3 - Avalam: Super Agent} task. Your agent will play a match against a simple alpha-beta player. Each agent will have a time credit of 2 . 5 minutes. If you win against this agent, you get all the points for the question. If you succeed to perform a draw, you get half of the points and if get beaten, you don’t get any point. Don’t forget to include all the needed files inside the archive you upload.\n    \\begin{figure}[!ht]\n    \\begin{framed}\n        \\centering\n        \\includegraphics[width=\\linewidth]{test_super_agent.png}\n        \\caption{INGInious result on super agent}\n    \\end{framed}\n    \\end{figure}\n\\end{enumerate}\n\n\\subsection{Contest}\n\n\\begin{enumerate}\n    \\item[16.] Upload your agent to the INGInious \\textit{Assignment 3 - Avalam: Contest Agent} task. Your agent will play a match against a basic alpha-beta player. Each agent will have a time credit of 2 . 5 minutes (for the real contest, your agent will have a time credit of 20 minutes per match). If you win against this agent, you get all the points for the question. If you succeed to perform a draw, you get half of the points and if get beaten, you don’t get any point. Don’t forget to include all the needed files inside the archive you upload.\n        \\begin{figure}[!ht]\n        \\begin{framed}\n            \\centering\n            \\includegraphics[width=\\linewidth]{test_contest_agent.png}\n            \\caption{INGInious result on contest agent}\n        \\end{framed}\n        \\end{figure}\n    \\item[17.] Describe concisely your super tough agent in your report. \\textbf{Your description shouldn’t be longer than one A4 paper page; if it is the same agent than the one described in earlier sections, just state it, no need to re-explain.}\n    \\begin{framed}\n        Our super tough contest performs the same behaviour we described previously in this report. There is however a feature in our code that we didn't have the occasion to mention previously. \\newline\n\n        When our board execute the minimax function, it saves at each steps the combinaison of moves that lead to that given state to avoid visiting symmetric boards.\n    \\end{framed}\n\\end{enumerate}\n", "meta": {"hexsha": "2d21a4f4d51dc8746162bbdbf3281acb7c2416e4", "size": 12923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment3/LaTeX/rapport.tex", "max_stars_repo_name": "fthuin/artificial-intelligence", "max_stars_repo_head_hexsha": "2823e476dec8d704e6a92265bb9ae35f23cf7708", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment3/LaTeX/rapport.tex", "max_issues_repo_name": "fthuin/artificial-intelligence", "max_issues_repo_head_hexsha": "2823e476dec8d704e6a92265bb9ae35f23cf7708", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment3/LaTeX/rapport.tex", "max_forks_repo_name": "fthuin/artificial-intelligence", "max_forks_repo_head_hexsha": "2823e476dec8d704e6a92265bb9ae35f23cf7708", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T14:31:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T21:52:29.000Z", "avg_line_length": 76.9226190476, "max_line_length": 638, "alphanum_fraction": 0.7373674843, "num_tokens": 2977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6292318978659369}}
{"text": "\n\\section{The \\removecopyii algorithm (number of copied elements)}\n\\label{sec:removecopyii}\n\nIn this section we improve the contract of \\specref{removecopy}\nby formally specifying the number~\\inl{\\\\result} of elements copied by \\removecopy.\n\nThe number of copied elements equals of course the number of elements\nin the input range \\inl{a[0..n-1]} that are different from~\\inl{v}.\nOne can formally describe this number by relying on the logic function~\\logicref{Count}.\n\n\\begin{lstlisting}[style=acsl-block]\n\n  logic integer\n  CountNotEqual(value_type* a, integer n, value_type v) =  n - Count(a, n, v);\n\\end{lstlisting}\n\nIn fact, we have used this kind of definition in earlier version of this document.\nWe have found it, however, worthwhile to provide a separate definition of \\CountNotEqual\nand express the relationship with \\Count as a lemma.\nThis definition is shown in the Listings~\\ref{logic:CountNotEqual-1}\nand~\\ref{logic:CountNotEqual-2}.\n\n\\begin{logic}[hbt]\n\\begin{minipage}{\\textwidth}\n\\lstinputlisting[linerange={1-34}, style=acsl-block, frame=single]{Source/CountNotEqual.acsl}\n\\end{minipage}\n\\caption{\\Label{logic:CountNotEqual-1} The logic function \\CountNotEqual (1)}\n\\input{Listings/CountNotEqual.acsl.labels.tex}\n\\input{Listings/CountNotEqual.acsl.index.tex}\n\\end{logic}\n\n\n\\clearpage\n\nThe  above mentioned relationship with \\logicref{Count} is expressed as\nlemma \\logicref{CountNotEqualCount} in the following listing.\n\n\\begin{logic}[hbt]\n\\begin{minipage}{\\textwidth}\n\\lstinputlisting[linerange={35-60}, style=acsl-block, frame=single]{Source/CountNotEqual.acsl}\n\\end{minipage}\n\\caption{\\Label{logic:CountNotEqual-2} The logic function \\CountNotEqual (2)}\n\\end{logic}\n\n\\FloatBarrier\n\n\n\\subsection{Formal specification of \\removecopyii}\n\nWe extend our formal specification by using \\logicref{CountNotEqual}\nand add the new postcondition \\inl{size}, which states that the returning value\nof \\removecopyii equals \\CountNotEqual.\nThe following listing shows the formal specification of \\specref{removecopyii}.\n\n\\input{Listings/remove_copy2.h.tex}\n\n\\subsection{Implementation of \\removecopyii}\n\nThe following listing shows the implementation of our\nextended of \\removecopyii.\nHere we added the loop invariant \\inl{size} which corresponds to the \npostcondition in \\specref{removecopyii}.\nIn order to ensure that the loop invariant \\inl{size} can be verified\nwe have added the assertions \\inl{size} and \\inl{unchanged}.\n\n\\input{Listings/remove_copy2.c.tex}\n\nWhile we now can precisely speak of the number of copied elements,\nit is still not possible to say something about the exact relationship between\nthe elements of range~\\inl{a[0..n-1]} and range~\\inl{b[0..n-1]}.\nWe will address this question the contract of \\specref{removecopyiii}.\n\n\\clearpage\n\n", "meta": {"hexsha": "7c5ef1841884fee5625462c40fb0a0491b5dd7e3", "size": 2764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/mutating/remove_copy2.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/mutating/remove_copy2.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/mutating/remove_copy2.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": 36.3684210526, "max_line_length": 94, "alphanum_fraction": 0.7854558611, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435030872967, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6292318969471589}}
{"text": "\\subsection{Plots}\\label{subsec:plots}\n\t\n\\begin{figure}[H]\n\\begin{center}\n%Here begins the 3d plot\n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot3[\n    surf,\n]\n{exp(-x^2-y^2)*x};\n\\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\\caption{Eigens erstellter Plot mit dem Paket libz und pgfplots}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\begin{center}\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 - 2*x - 1};\n\\addlegendentry{$x^2 - 2x - 1$}\n%Here the blue parabloa is defined\n\\addplot [\n    domain=-10:10, \n    samples=100, \n    color=blue,\n    ]\n    {x^2 + 2*x + 1};\n\\addlegendentry{$x^2 + 2x + 1$}\n\n\\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\\caption{Eigens erstellter Plot mit dem Paket libz und pgfplots}\n\\end{figure}", "meta": {"hexsha": "effe15ab93a9f78557f1af61ae87b3f7a00d95d3", "size": 858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/sections/2_beispiele/subsections/2_8_plots.tex", "max_stars_repo_name": "devtobi/theisen-latex", "max_stars_repo_head_hexsha": "85b6f02011ac445fb83d3d7239adf2d75281438e", "max_stars_repo_licenses": ["MIT"], "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/2_beispiele/subsections/2_8_plots.tex", "max_issues_repo_name": "devtobi/theisen-latex", "max_issues_repo_head_hexsha": "85b6f02011ac445fb83d3d7239adf2d75281438e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2020-07-28T14:03:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-03T11:17:32.000Z", "max_forks_repo_path": "src/sections/2_beispiele/subsections/2_8_plots.tex", "max_forks_repo_name": "devtobi/theisen-latex", "max_forks_repo_head_hexsha": "85b6f02011ac445fb83d3d7239adf2d75281438e", "max_forks_repo_licenses": ["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": 64, "alphanum_fraction": 0.6445221445, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6292318883901166}}
{"text": "\\chapter{Python Programs}\n\nSince Matlab requires a licence, we have also included Python versions of some of the Matlab programs. These programs have been tested in Python 2.7 (which can be obtained from \\url{http://python.org/}), they also require Matlplotlib (version 1.10, which can be obtained from \\url{http://matplotlib.sourceforge.net/index.html}), Mayavi (\\url{http://github.enthought.com/mayavi/mayavi/index.html}) and numpy (\\url{http://numpy.scipy.org/}). These programs have been tested primarily with the Enthought Python distribution.\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:instability,caption={A Python program to demonstrate instability of different time-stepping methods.  Compare this to the Matlab implementation in listing \\ref{lst:MatlabInstability}.}]{./PythonPrograms/Programs/PythonCode/Simple_ODE_Example_of_Unstable_FE.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:HeatFE1dPython,caption={A Python program to solve the heat equation using forward Euler time-stepping.  Compare this to the Matlab implementation in listing \\ref{lst:HeatFE1dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Heat_Eq_1D_Spectral_FE.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:HeatBE1dPython,caption={A Python program to solve the heat equation using backward Euler time-stepping.  Compare this to the Matlab implementation in listing \\ref{lst:HeatBE1dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Heat_Eq_1D_Spectral_BE.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:AllenCahnIE2dPython,caption={A Python program to solve the 2D Allen Cahn equation using implicit explicit time-stepping.  Compare this to the Matlab implementation in listing \\ref{lst:AllenCahnIE2dMatlab}.}]{./PythonPrograms/Programs/PythonCode/Allen_Cahn_2D_Spectral_IE.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:BEFPiterPython,caption={A Python program to demonstrate fixed-point iteration. Compare this to the Matlab implementation in listing \\ref{lst:BEFPiterMatlab}.}]{./PythonPrograms/Programs/PythonCode/BackwardEulerFixedPoint.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:BENewIterPython,caption={A Python program to demonstrate Newton iteration. Compare this to the Matlab implementation in listing \\ref{lst:BENewIterMatlab}.}]{./PythonPrograms/Programs/PythonCode/BackwardEulerNewtonIteration.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:OdeStrangPython,caption={A Python program which uses Strang splitting to solve an ODE. Compare this to the Matlab implementation in listing \\ref{lst:OdeStrangMatlab}.}]{./PythonPrograms/Programs/PythonCode/ODEsplittingStrang.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit1DPython,caption={A Python program which uses Strang splitting to solve the one-dimensional nonlinear Schr\\\"{o}dinger equation. Compare this to the Matlab implementation in listing \\ref{lst:NlsSplit1DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting1D.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit2DPython,caption={A Python program which uses Strang splitting to solve the two-dimensional nonlinear Schr\\\"{o}dinger equation. Compare this to the Matlab implementation in listing \\ref{lst:NlsSplit2DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting2D.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:NlsSplit3DPython,caption={A Python program which uses Strang splitting to solve the three-dimensional nonlinear Schr\\\"{o}dinger equation. Compare this to the Matlab implementation in listing \\ref{lst:NlsSplit3DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NLSsplitting3D.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Ns2DPython,caption={A Python program which finds a numerical solution to the 2D Navier-Stokes equation. Compare this to the Matlab implementation in listing \\ref{lst:Ns2DMatlab}.}]{./PythonPrograms/Programs/PythonCode/NavierStokes2DFFTCn.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg1DPython,caption={A Python program to solve the one-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImEx}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg1D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordon1D.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg1Dimp,caption={A Python program to solve the one-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg1Dimp}.}]{./PythonPrograms/Programs/PythonCode/KleinGordon1Dimp.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg2DPython,caption={A Python program to solve the two-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImp}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg2D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp2Db.py}\n\n\\lstinputlisting[style=python_style,language=Python,label=lst:Kg3DPython,caption={A Python program to solve the three-dimensional Klein Gordon equation \\eqref{eq:KleinGordon} using the time discretization in eq.\\ \\eqref{eq:KgImEx}. Compare this to the Matlab implementation in listing \\ref{lst:MatKg3D}.}]{./PythonPrograms/Programs/PythonCode/KleinGordonImp3D.py}\n", "meta": {"hexsha": "49c7833e5224399ce8e2c487ee2b24f45e3fa6e1", "size": 6203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PythonPrograms/PythonPrograms.tex", "max_stars_repo_name": "openmichigan/PSNM", "max_stars_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "PythonPrograms/PythonPrograms.tex", "max_issues_repo_name": "openmichigan/PSNM", "max_issues_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "PythonPrograms/PythonPrograms.tex", "max_forks_repo_name": "openmichigan/PSNM", "max_forks_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 163.2368421053, "max_line_length": 521, "alphanum_fraction": 0.826374335, "num_tokens": 1678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6292318823791623}}
{"text": "\\chapter{Mathematical Background}\\label{math}\n\\section{Introduction}\nDiscontinuous Galerkin finite element method is an amalgamation of the element based Galerkin schemes and\nthe finite volume method. It is a compact, higher-order accurate scheme where the solution can be \ndiscontinuous between two elements.\nThe DG scheme requires the physical domain ($\\Omega$) discretized with $Ne$ finite elements (written as $\\Omega^k$). \nThe finite element cells are assumed to be one of the following types.\n\\begin{enumerate}\n\t\\item Hexahedral ($8$ edges, $8$ nodes, $6$ faces)\n\t\\item Tetrahedral ($6$ edges, $4$ nodes, $4$ faces)\n\t\\item Prism ($9$ edges, $6$ nodes, $5$ faces)\n\t\\item Pyramid ($8$ edges, $5$ nodes, $5$ faces)\n\\end{enumerate}\nThe solution is assumed to be continuous (along with continuous derivatives depending on the governing equations) inside \nthe element. However, the solution can be discontinuous at the edges and faces. The value of the conserved variable (and \nthe numerical fluxes) at the faces and edges are found out by solving the Riemann problem which arises because of the \ndiscontinuity. \n\nThe DG method essentially starts with the `variational' formulation of the problem. Consider a \ndifferential equation given by,\n\\begin{equation}\\label{diffeqn}\n\t\\mathbf{L}(u) = f(u),  u\\in{H^1(\\Omega)}\n\\end{equation}\n(and suitable boundary conditions, not mentioned here).\nFor example, $\\mathbf{L} = \\frac{d}{dx}$ and $f(u) = u$ results in,\n\\begin{equation}\\label{diffeqn_ex1}\n\t\\frac{du}{dx} = u\n\\end{equation}\nWe will be using the general notation given by equation \\ref{diffeqn} henceforth.\nThen, if $u^k$ is the approximate solution inside of the element, then instead of the solving equation \\ref{diffeqn}\nwith $u^k$, we solve the following variational formulation of equation \\ref{diffeqn}.\n\\begin{equation}\\label{diffeqnvr}\n\t\\int_{\\Omega_k} \\phi \\mathbf{L}(u^k) d\\Omega = \t\\int_{\\Omega_k} \\phi f(u^k) d\\Omega\n\\end{equation}\n$\\phi$ is the test function. The approximate solution $u^k$ is obtained by polynomial approximation of $u$ inside $\\Omega^k$.\nA modal interpolation (basis functions consisting of modes, i.e. frequencies) or a nodal interpolation (basis functions\nconsist of the cardinal polynomials such as the Lagrange polynomials) can be used for this. \nIn the DG methods, the basis functions serve as the test functions. \nThe integrations in equation \\ref{diffeqn_ex1} are solved numerically using quadrature formulas. \nThe resulting algebraic system is solved iteratively (or ODE is solved numerically if time dependant).\nThis process is repeated till convergence (for steady state\nproblems) or till the final time is reached (for transient problems). \nIt is easier to solve the problem on a reference cell (canonical element) and then map the solution on to the physical cell.\nThis requires a mapping to be defined between the reference cell and the physical cell.\nBased on this general process, the following mathematical concepts are revised in this chapter.\n\\begin{enumerate}\n\t\\item Mapping functions (Jacobian ($\\mathbf{J}$) of transformation, inverse Jacobian ($\\mathbf{J}^{-1}$) and ($|\\mathbf{J}|$))\n\t\\item Modal and nodal basis functions  \n\t\\item Polynomial interpolation and differentiation\n\t\\item Numerical quadrature (integration)\n\t\\item Cell matrices (Vandermonde matrix, Mass matrix, differentiation matrix and flux matrix)\n\t\\item Other mathematical functions \n\\end{enumerate}\nThe discussion is kept brief and concise and only those concepts concerned with MEAN-DG are discussed. \nThe user is encouraged to go through the references for in-depth theory of DG schemes.\n\n\\begin{note}\n\tWe use the c++ style indexing. i.e. indices start at $0$ (not $1$).\n\\end{note}\n\n\\section{Mapping on the Reference Element}\nCorresponding to each physical cell, there exists a canonical (reference) element.\nThe physical cell is expressed in terms of the physical coordinate system $(x,y,z)$. The reference coordinate system is\nwritten in terms of  $(r,s,t)$. \nThus, each of the physical coordinates can be written in terms of the $(r,s,t)$ coordinate system. In the code, we \ndescribe the physical coordinate system as $XYZ$, and the reference system as $RST$. \nThe mapping from the physical coordinate system to the reference coordinate system is characterized by the Jacobian of \ntransformation $\\mathbf{J}$. \nIn this section, we describe the Jacobian of transformation for the four types of the cells.\n\n\\subsection{Hexahedral cells}\nHexahedral, or Hex in short, cells are mapped to a cube in 3D. The Hex cell has $8$ nodes given by the array,\n$\\left((x_0,y_0,z_0), (x_1, y_1, z_1), ... ,(x_7,y_7,z_7)\\right)$.\nWe define the linear shape functions on the reference element as follows:\n\\begin{equation}\\label{shape0}\n\tN_0 = \\frac{1}{8} (1-r) (1-s) (1-t), \\hspace{5mm} \\{r,s,t \\in V | \\forall v\\in V \\subset  {\\mathbb{R}} , ~ v \\in [-1,1]\\}\n\\end{equation}\n\\begin{equation}\\label{shape1}\n\tN_1 = \\frac{1}{8} (1+r) (1-s) (1-t) \n\\end{equation}\n\\begin{equation}\\label{shape2}\n\tN_2 = \\frac{1}{8} (1+r) (1+s) (1-t) \n\\end{equation}\n\\begin{equation}\\label{shape3}\n\tN_3 = \\frac{1}{8} (1-r) (1+s) (1-t) \n\\end{equation}\n\\begin{equation}\\label{shape4}\n\tN_4 = \\frac{1}{8} (1-r) (1-s) (1+t) \n\\end{equation}\n\\begin{equation}\\label{shape5}\n\tN_5 = \\frac{1}{8} (1+r) (1-s) (1+t) \n\\end{equation}\n\\begin{equation}\\label{shape6}\n\tN_6 = \\frac{1}{8} (1+r) (1+s) (1+t) \n\\end{equation}\n\\begin{equation}\\label{shape7}\n\tN_7 = \\frac{1}{8} (1-r) (1+s) (1+t) \n\\end{equation}\n\nThe mapping then is simply given as,\n\n\\begin{equation}\\label{mapx}\n\tx(r,s,t) = \\sum_{i=0}^7 N_i x_i\n\\end{equation}\n\n\\begin{equation}\\label{mapy}\n\ty(r,s,t) = \\sum_0^7 N_i y_i\n\\end{equation}\n\n\\begin{equation}\\label{mapz}\n\tz(r,s,t) = \\sum_0^7 N_i z_i\n\\end{equation}\n\n\\begin{definition}\\label{Jacobian}\n\tThe Jacobian of transformation ($\\mathbf{J}$) is defined as :\n\t\\begin{equation}\\label{J}\n\t\t{\\setstretch{2}\n\t\t\\mathbf{J} = \\left[\\begin{array}{c c c}\n\t\t\t\\frac{\\partial x}{\\partial r} & \\frac{\\partial x}{\\partial s} &  \\frac{\\partial x}{\\partial t} \\\\\n\t\t\t\\frac{\\partial y}{\\partial r} & \\frac{\\partial y}{\\partial s} &  \\frac{\\partial y}{\\partial t} \\\\\n\t\t\t\\frac{\\partial z}{\\partial r} & \\frac{\\partial z}{\\partial s} &  \\frac{\\partial z}{\\partial t} \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t                   \\end{array} \\right]\n\t\t\t= \\left[\\begin{array}{c c c}\n\t\t\t\tJ_{00} & J_{01}  & J_{02}   \\\\\n\t\t\t\tJ_{10} & J_{11}  & J_{12}   \\\\\n\t\t\t\tJ_{20} & J_{21}  & J_{22}   \\\\\n\t\t\t\t\t\t\t\t\t\t\t\t                   \\end{array} \\right]\n\t        }\n\t\\end{equation}\n\\end{definition}\nThe partial derivatives in equation \\ref{J} can be easily computed from equations \\ref{shape0}-\\ref{shape7} and \\ref{mapx}, \\ref{mapy}, \\ref{mapz}.\nIn the code, the above implementation is found in Cell.cpp.\n\\begin{verbatim} \nCell::calculateJacobian3DTensor(double r,double s,double t) \n\\end{verbatim}\n\\begin{note}\n\tThe first name indicates the name of the class (Cell), the second symbol (::) indicates the scope (in this case, indicating\n\t'belongs to Cell' the third name is the name of the class method (calculateJacobian3DTensor) and terms in the bracket being\n\targuments passed to this function.\n\\end{note}\nIt is to be noted that the name `Tensor' in the above function indicates that the functional space for a Hex cell is \nobtained by a tensor product (outer product) of 1D functional spaces.\n\nThe inverse of the Jacobian is found out by the standard process of inversion of a matrix.\n\n\\begin{equation}\\label{JInv}\n\t{\\setstretch{2}\n\t\\mathbf{J^{-1}} = \\left[\\begin{array}{c c c}\n\t\t\\frac{\\partial r}{\\partial x} & \\frac{\\partial r}{\\partial y} &  \\frac{\\partial r}{\\partial z} \\\\\n\t\t\\frac{\\partial s}{\\partial x} & \\frac{\\partial s}{\\partial y} &  \\frac{\\partial s}{\\partial z} \\\\\n\t\t\\frac{\\partial t}{\\partial x} & \\frac{\\partial t}{\\partial y} &  \\frac{\\partial t}{\\partial z} \\\\\n\t\t\t\t\t\t\t\t\t\t\t                   \\end{array} \\right]\n        }\n\\end{equation}\nThese are given as:\n\\begin{equation}\\label{metricTerms00}\n\t\\frac{\\partial r}{\\partial x} = \\frac{1}{|{\\mathbf{J}}|} \\left( J_{22}J_{11} - J_{21}J_{12}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms01}\n\t\\frac{\\partial r}{\\partial y} = \\frac{-1}{|{\\mathbf{J}}|} \\left( J_{22}J_{01} - J_{21}J_{02}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms02}\n\t\\frac{\\partial r}{\\partial z} = \\frac{1}{|{\\mathbf{J}}|} \\left( J_{12}J_{01} - J_{11}J_{02}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms10}\n\t\\frac{\\partial s}{\\partial x} = \\frac{-1}{|{\\mathbf{J}}|} \\left( J_{22}J_{10} - J_{20}J_{12}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms11}\n\t\\frac{\\partial s}{\\partial y} = \\frac{1}{|{\\mathbf{J}}|} \\left( J_{22}J_{00} - J_{20}J_{02}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms12}\n\t\\frac{\\partial s}{\\partial z} = \\frac{-1}{|{\\mathbf{J}}|} \\left( J_{12}J_{00} - J_{10}J_{02}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms20}\n\t\\frac{\\partial t}{\\partial x} = \\frac{1}{|{\\mathbf{J}}|} \\left( J_{21}J_{10} - J_{20}J_{11}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms21}\n\t\\frac{\\partial t}{\\partial y} = \\frac{-1}{|{\\mathbf{J}}|} \\left( J_{21}J_{00} - J_{20}J_{01}\\right)\n\\end{equation}\n\\begin{equation}\\label{metricTerms22}\n\t\\frac{\\partial t}{\\partial z} = \\frac{1}{|{\\mathbf{J}}|} \\left( J_{11}J_{00} - J_{10}J_{01}\\right)\n\\end{equation}\nwhere, the determinant of the Jacobian $|{\\mathbf{J}}|$ is calculated as:\n\\begin{equation}\\label{detJ}\n\t|{\\mathbf{J}}| = J_{00} (J_{22}J_{11} - J_{21}J_{12}) - J_{01} (J_{22}J_{10} - J_{20}J_{12})  + J_{02} (J_{21}J_{10} - J_{20}J_{11}) \n\\end{equation}\nThe inverse of Jacobian is implemented in \n\\begin{verbatim} \nCell::calculateInverseJacobianMatrix3DTensor(arguments) \n\\end{verbatim}\n\n\\begin{note}\n\tThe inverse of Jacobian is called as {\\bf dRST\\_by\\_dXYZ} in the code. Each cell stores these matrices for all the quadrature\n\tpoints within that cell. The metric terms given by \\ref{metricTerms00}--\\ref{metricTerms22} \n\tare used in computations involving derivatives as seen in the subsequent sections and chapters.\n\\end{note}\nThe inverse Jacobian is stored for all the quadrature points for all the cells. It is an attribute of the cell\n(i.e. Cell::dRST\\_by\\_dXYZ) and has dimensions $nQuad \\times 3 \\times 3$.\n\n{\\bf Use of the Jacobian}\nConsider the following integration:\n\\begin{equation}\\label{J_example}\n\tI = \\int_{\\Omega^k} \\phi(x,y,z) d\\Omega^k\n\\end{equation}\nThe integration can be written as,\n\\begin{equation}\n\tI = \\int_{\\Omega^s} \\phi(r,s,t) |\\mathbf{J}| d\\Omega^s\n\\end{equation}\nwhere, $\\Omega^s$ is a reference element and $\\mathbf{J}$ is the Jacobian matrix.\nThe main benefit of performing the above conversion is that, the function $\\phi(r,s,t)$ needs to be computed only once\nfor the standard element, each cell will have its own Jacobian matrix, so number of computations reduce drastically.\n\nIn the current code, the vertices and faces are numbered in a standardized fashion as shown in Fig.\\ref{RC}.\n\n\\begin{figure}[h]\n\t\\begin{minipage}[t]{0.5 \\textwidth}\n\t\t\\begin{center}{\\includegraphics[width=0.9\\textwidth]{RefCellFace.pdf}}\n\t\t\\end{center}\n\t\\end{minipage}%\n\t\\begin{minipage}[t]{0.5 \\textwidth}\n\t\t\\begin{center}{\\includegraphics[width=0.9\\textwidth]{RefCellVertex.pdf}}\n\t\t\\end{center}\n\t\\end{minipage}%\n\t\\caption{\\label{RC}a. Reference cell and faces relative numbering \\hspace{2mm} b. Reference cell and vertices numbering}\n\\end{figure}\n\nThe corresponding implementation can be found in: \n\\begin{verbatim} \nCell::orderDefiningPoints() \n\\end{verbatim}\n\n\\section{Mapping onto the Reference Face}\nDG method involves evaluation of surface integrations in order to find the numerical flux at the cell-interface.\nThe surface integrations in turn require mapping of a given arbitrary surface on the reference surface.\nThe parameterization of a plane surface requires two parameters $r$ and $s$. \n\n\\subsection{Quadrilateral Faces}\nFor a quadrilateral faces, the parameters assume the following values: $(r,s) \\in [-1,1]$.\nHowever, the given surface can be arbitrarily oriented in the space, and thus requires $(x,y,z)$ position\nto be completely defined. \nWe thus need to orient the surface such as one of the variables becomes redundant. This means rotating \nthe surface such as to make it parallel to $xy$ plane, for example. \nThus, each surface needs to be re-oriented in space such that the face normal $\\hat{n}$ becomes\nparallel to the $z$ axis. After the we can map the rotated face onto the standard element. \nLet $\\theta_z$ be the angle made by the face normal with the $z$ axis and $\\theta_x$ be the angle made by\nthe face normal with the $x$ axis. \nThe rotation matrix rotates the face through $\\theta_x$ first (counterclockwise) and the through $\\theta_z$\ncounterclockwise. The resulting rotation matrix $R$ is given as:\n\\begin{equation}\\label{rotMat1}\n\tR = <R_z, R_x>\n\\end{equation}\nwhere,\n\\begin{equation}\\label{rotMat}\n\t{\\setstretch{1.5}\n\tR_x = \n\t \\left[\\begin{array}{c c c}\n\t\t\t\tcos(\\theta_x) & sin(\\theta_x)  & 0  \\\\\n\t\t\t       -sin(\\theta_x) & cos(\\theta_x)  & 0  \\\\\n\t\t\t\t       0      &       0        & 1  \\\\\n         \\end{array} \\right];\n\\hspace{5mm}\n\tR_z = \n\t \\left[\\begin{array}{c c c}\n\t\t\t\tcos(\\theta_z)   & 0 & -sin(\\theta_z) \\\\\n\t\t\t\t       0        & 1 &       0       \\\\\n\t\t\t        sin(\\theta_z)   & 0 & cos(\\theta_z) \\\\\n         \\end{array} \\right];\n }\n \\end{equation}\n and $<a,b>$ indicates the dot product between matrices $a$ and $b$. \n Matrix $R^{-1}$ indicates the reverse transformation.\n The rotation matrix is calculated in,\n \\begin{verbatim}\n Face::calculateRotationMatrixParallelToXY()\n \\end{verbatim}\n and the inverse matrix is computed in,\n \\begin{verbatim}\n Face::calculateInverseRotationMatrix()\n \\end{verbatim}\n In order to describe the procedure to compute the Jacobian of transformation ($|{\\mathbf{J}^f}|$) for face,\n we use the following nomencleture:\n \\begin{itemize}\n\t \\item $(x,y,z)$: physical coordinate system (actual coordinates)\n\t \\item $(x', y', z')$: Rotated coordinates such that the face is $||$ to the $xy$ plane\n\t \\item $(r,s)$: Reference coordinates such that $r,s \\in [-1,1]$\n \\end{itemize}\n There are two ways the Jacobian can be computed.\n\n \\subsubsection{Method 1}\n First, rotate each vertex of the face using $R$. \n i.e.\n \\begin{equation}\n\t {\\setstretch{1.5}\n\t \\left[\\begin{array}{c}\n\t\t\t  x'_i  \\\\\n\t\t\t  y'_i  \\\\\n\t\t\t  z'_i \\\\\n\t  \\end{array} \\right] \n\t  = \n\t  R\\left(\n\t \\left[\\begin{array}{c}\n\t\t\t  x_i  \\\\\n\t\t\t  y_i  \\\\\n\t\t\t  z_i \\\\\n\t  \\end{array} \\right]\n\t  \\right), \\hspace{5mm} i \\in \\{0,1,2,3\\}\n  }\n \\end{equation}\n Each of the rotated points is then mapped to the standard element.\n After rotation of the face, $\\frac{\\partial z'}{\\partial r} = 0, \\frac{\\partial z'}{\\partial s}=0$ since \n $z'$ remains constant. \nThe mapping from the rotated face $f'$ to the standard face $f^s$ can be defined through the shape functions. \n\\begin{equation}\\label{shape0f}\n\tN_0 = \\frac{1}{4} (1-r) (1-s) , \\hspace{5mm} \\{r,s \\in V | \\forall v \\in V \\subset {\\mathbb{R}}  , ~ v \\in [-1,1]\\}\n\\end{equation}\n\\begin{equation}\\label{shape1f}\n\tN_1 = \\frac{1}{4} (1+r) (1-s) \n\\end{equation}\n\\begin{equation}\\label{shape2f}\n\tN_2 = \\frac{1}{4} (1+r) (1+s)\n\\end{equation}\n\\begin{equation}\\label{shape3f}\n\tN_3 = \\frac{1}{4} (1-r) (1+s)\n\\end{equation}\nThen,\n\\begin{equation}\\label{faceMap}\n\tx' = \\sum_{i=0}^3 N_i x'_i, \\hspace{4mm}y' = \\sum_{i=0}^3 N_i y'_i,\n\\end{equation}\nEquation\\ref{faceMap} can be used to find partial derivatives of $x'$ and $y'$ with respect to $r$ and $s$.\nThe required face Jacobian is:\n \\begin{equation}\\label{method1J}\n\t {\\setstretch{1.5}\n\t \\mathbf{J}^f = \n\t \\left[\\begin{array}{c c}\n\t\t\t \\frac{\\partial x}{\\partial r}  & \\frac{\\partial x}{\\partial s}  \\\\\n\t\t\t \\frac{\\partial y}{\\partial r}  & \\frac{\\partial y}{\\partial s}  \\\\\n\t\t\t \\frac{\\partial z}{\\partial r}  & \\frac{\\partial z}{\\partial s}  \\\\\n         \\end{array} \\right]\n }\n \\end{equation}\n which can be written as,\n \\begin{equation}\\label{method1J}\n\t {\\setstretch{1.5}\n\t \\mathbf{J}^f = \n\t \\left[\\begin{array}{c}\n\t\t\t  x  \\\\\n\t\t\t  y  \\\\\n\t\t\t  z  \\\\\n\t  \\end{array} \\right]. \n\t  \\left[\\begin{array}{c c} \n\t\t  \\frac{\\partial}{\\partial r} &  \\frac{\\partial}{\\partial s}\\\\\n\t\t  \\end{array} \\right]\n\t\t  = R^{-1}\n\t \\left[\\begin{array}{c}\n\t\t\t  x'  \\\\\n\t\t\t  y'  \\\\\n\t\t\t  z'  \\\\\n\t  \\end{array} \\right]. \n\t  \\left[\\begin{array}{c c} \n\t\t  \\frac{\\partial}{\\partial r} &  \\frac{\\partial}{\\partial s}\\\\\n\t\t  \\end{array} \\right]\n }\n \\end{equation}\ni.e.\n\\begin{equation}\\label{method1J1}\n\t\\mathbf{J}^f = R^{-1} \\mathbf{J}^{f'}\n\\end{equation}\nwhere,\n\\begin{equation}\\label{method1J'}\n        {\\setstretch{1.5}\n\t\t\\mathbf{J}^{f'} = \n        \\left[\\begin{array}{c c}\n       \t\t \\frac{\\partial x'}{\\partial r}  & \\frac{\\partial x'}{\\partial s}  \\\\\n       \t\t \\frac{\\partial y'}{\\partial r}  & \\frac{\\partial y'}{\\partial s}  \\\\\n\t\t\t\t0\t\t &             0\t\t   \\\\\n        \\end{array} \\right]\n}\n\\end{equation}\nThe procedure is summarized as,\n\\begin{enumerate}\n        \\item Rotate the face so as to make it parallel to the $xy$ plane.\n\t\\item Find the Jacobian of transformation from the rotated face to the standard face ($\\mathbf{J}^{f'}$).\n\t\\item Find the Jacobian of the face as given by equation \\ref{method1J1}.\n\t\\item $|\\mathbf{J}^{f}|$ is given as $\\sqrt{|\\left(\\mathbf{J}^{f}\\right)^{T}\\left(\\mathbf{J}^{f}\\right)|}$\n\\end{enumerate}\n\n\\subsubsection{Method 2}\nIn this method, we parametarize the surface $x,y,z$ with parameters $r,s$.\nLet $$X = x\\hat{i} + y\\hat{j} + z\\hat{k}$$ \nWe use the standard shape functions to map the physical element to parameters $r,s$.\ni.e.\n\\begin{equation}\\label{faceMap1}\n\tx = \\sum_{i=0}^3 N_i x_i, \\hspace{4mm}y = \\sum_{i=0}^3 N_i y_i, \\hspace{4mm}z = \\sum_{i=0}^3 N_i z_i,\n\\end{equation}\nwhere same shape functions are used as earlier. \n\\begin{note}\nIn order to find the vertex mapping of a randomly oriented face with the standard\nelement, it would be advisable to first rotate the face to make it parallel to the $xy$ plane and then\nfind the vertex mapping. Then find the shape function and proceed with equation \\ref{faceMap1}. \nHowever, we do not use the coordinates of the rotated face here. \n\\end{note}\nAfter that, we find $\\frac{\\partial X}{\\partial r}$ and $\\frac{\\partial X}{\\partial s}$.\nThen $|\\mathbf{J}^{f}|$  is simply $\\left|\\left| \\frac{\\partial X}{\\partial r} \\times \\frac{\\partial X}{\\partial s}\\right|\\right|$\nBoth of these methods are implemented in \n\\begin{verbatim}\n\tFace::calculateJacobianQuadFace(double r, double s)\n\\end{verbatim}\nAny given quadrature point $(r,s)$ can be mapped into $(x,y,z)$ space using the two operations:\n\\begin{enumerate}\n\t\\item First find mapping from $(r,s)$ to $(x',y',z')$ using equations \\ref{shape0f}-\\ref{shape3f} and \n\t\t\\ref{faceMap}.\n\t\\item Then map from $(x',y',z')$ to physical coordinates using $R^{-1}$.\n\\end{enumerate}\nThe global positioning of all the quadrature points on each face is \nstored in array \n\\begin{verbatim}\n\tFace::quadPointsGlobalLocation\n\\end{verbatim}\nIndex $i$ runs over the surface quadrature points and index $j$ runs over the $x,y,z$ axes.\n\\begin{note}\n\tSome of the volume quadrature points coincide with the surface quadrature points. Function \\begin{verbatim}DG::mapFaceQuadPointsToCellQuadPoints() \\end{verbatim} performs the mapping by direct comparison of global positioning of surface and volume quadrature points.\n\\end{note}\n\\noindent\nThe mapping of surface to volume quadrature points is stored in arrays \\newline Face::mapOwnerQuadPoints[~] and Face::mapNeighbourQuadPoints[~]. \n\nThus, if we are finding a $2^{nd}$-order polynomial for a face, then it should have $9$ quadrature points (QP).\nThe corresponding cell will meanwhile have $27$  quadrature points, $9$ of which will coincide with the face QP.\nThen if \n\\begin{verbatim}\n\tFace::mapOwnerQuadPoints = [3, 2, 21, 14, ... , 7]\n\\end{verbatim}\nThen, it means the $0^{th}$ quad point on face is same as the $3^{rd}$ quad point of owner cell and so on. \n\n\n\\begin{note}\n\tIn the improved version of the code, the face-vertex numbering is standardized, such that the vertex numbering follows the right-hand rule.\n\ti.e. if the curled fingers indicate the sequence of vertices, then the stretched thumb points in the direction of hte face-normal.\n\tIn that case, the rotation matrices are not required. i.e. both method 1 and method 2 are obsolete. \n\tRefer:\n\t\\begin{verbatim}\n\tFace::orderDefiningPoints()\n\t\\end{verbatim}\n\\end{note}\n\n\n\\section{Modal and Nodal Basis Functions}\nBasis functions are the independant dimensions on which any function can be projected. In this chapter, we present a few \nmodal and nodal basis functions.\n\n\\subsection{Modal Basis Functions}\nThese are the set of basis functions, where each dimension corresponds to a `mode' or frequency. A simple example is \na set of monomials defined on the interval $[a,b]$ \n\\begin{note}\nThis is just an example, in reality $x$ could be valid over $(-\\infty, \\infty)$ \n\\end{note}\n\\begin{equation}\n\tV_{mono}^K = \\{1, x, x^2, x^3, ..., x^{K-1}\\} ,\\hspace{4mm} x\\in C^0[a,b]\n\\end{equation}\nA polynomial up to order $K-1$ can be represented exactly using $K$ modal functions. \nThus, any general polynomial can be written as\n\\begin{equation}\n\tP^K(x) = \\sum_{i=0}^{i=K-1} \\alpha_{i} x^{i}, ,\\hspace{4mm} x\\in C^0[a,b]\n\\end{equation}\nThe monomials is not a `good' choice of the basis functions as we will see later, thus we need a set of basis functions\nwhere each of the functions is `orthogonal' (or better `orthonormal') to every other functions. \nOne such important set of orthogonal functions \nis called as `Jacobi' polynomials. A special case of `Jacobi' polynomials is `Legendre' polynomials.\nIn our code, we have extensively used Legendre polynomials. \nA general $i^{th}$  modal basis function is indicated by symbol $\\psi_i$.\nOther popular example of modal basis functions is a set of Chebyshev polynomials.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.8\\textwidth]{Legendre.pdf}\n\t\t\\caption{\\label{Legendre} First $9$ Legendre polynomials}\n\t\\end{center}\n\\end{figure}\nFig.\\ref{Legendre} shows first $9$ Legendre polynomials. Observe that the `frequency' of the polynomials increases  (for increasing\ncount) indicating higher modes. Fig.\\ref{Cheb} shows Chebyshev polynomials.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.8\\textwidth]{Chebyshev.pdf}\n\t\t\\caption{\\label{Cheb} First $9$ Chebyshev polynomials}\n\t\\end{center}\n\\end{figure}\n\\noindent The $1$D modal functions are implemented in:\n\\begin{verbatim}\nFunctionalSpace::monomials1D(args),  \nFunctionalSpace::legendrePolynomial1D(args), \nFunctionalSpace::chebyshevPolynomial1D(args) and \nFunctionalSpace::jacobiPolynomial1D(args)\n\\end{verbatim}\nIt is indeed difficult to comprehend how the polynomials shown in Fig.\\ref{Legendre} and Fig.\\ref{Cheb} be `orthogonal'.\nThe main reason for this is that we try to stick to our understanding of the $3$D space and the notion of \northogonality that comes with it, however, the polynomial space is essentially $\\infty$ dimensional space. For\nthis space, the definition of orthogonality depends on the definition of the Inner-Product and `metric' of that space.\nFor $L^2$ space, the orthogonality is defined as,\n\\begin{equation}\n\t\\int_{\\Omega} \\psi_i \\psi_j d\\Omega = \\alpha \\delta_{ij}, \\hspace{4mm}\\forall \\psi_i, \\psi_j \\in L^2\\{\\Omega\\} ~\\& ~\\alpha \\in \\mathbb{R}\n\\end{equation}\nwhere, $\\delta_{ij}$ is a `Kronecker Delta' which means $\\delta_{ij} = 1 $ if $i=j$ and $0$ otherwise.\nThe functions $\\psi_i$ and $\\psi_j$ are orthonormal if $\\alpha = 1$.\n\n\n\\subsection{Nodal Basis Functions}\nThe `nodal' basis functions are the set of functions which are `Cardinal' in nature. What that means is, at the\ninterpolation point, the basis function will have value $1$ and for all other collocation points, the value of the \nbasis function will be zero. Thus, the interpolated value of the function agrees perfectly at the collocation points\nbut may have some error at other places. \nThe general symbol used for nodal basis functions is $\\phi$.\nThe interpolation itself is given as,\n\\begin{equation}\n\tf^N(x) = \\sum_{i=0}^{N-1} f(x_i) \\phi_i(x), \\hspace{4mm} x \\in C^0[a,b]\n\\end{equation}\nand, $\\phi_i(x_j) = \\delta_{ij}$.\nWe use Lagrange polynomials as the nodal basis functions. The polynomials in $1$D are give as,\n\\begin{equation}\n\t\\phi_i(x) = \\prod_{j=0 , j \\ne i}^{N-1} \\frac{(x-x_j)}{(x_i - x_j)}\n\\end{equation}\nit is clear that at $x=x_i$, $\\phi_i(x_i) = 1$.\nOne crucial point that needs to be taken care of is selection of the collocation points $\\left[x_0, x_1, ..., x_{N-1}\\right]$.\nIt is seen that the equi-spaced arrangement of collocation points gives poor interpolation for very high orders of \naccuracies. Therefore we take these points as roots of orthonormal modal polynomials.\nPopular choices for collocation points are Gauss-Legendre (LG) collocation points, Legendre-Gauss-Lobatto (LGL) points\nor Chebyshev points. An important distinction between LG and LGL points is that, LGL points include the `end-points' \nwhereas LG points include only the internal points. For DG methods, this doesn't have a significant difference since \nsolving a Riemann problem at the face remains unchanged.\n\n\\subsection{Multidimensional Interpolation}\nFor number of dimensions greater than $1$, the interpolating polynomials are obtained depending on the type of the\nelement we wish to interpolate on. For hex elements, these are obtained using tensor product of $1$D polynomials.\ni.e. \n\\begin{equation}\n\t\\phi(x,y,z) = \\phi_{1D}(x)  \\phi_{1D}(y)  \\phi_{1D}(z)\n\\end{equation}\nWhereas, for other types of elements, special multidimensional polynomials are used. However, the concept of \nmodal and nodal basis functions remains essentially the same irrespective of the number of dimensions.\n", "meta": {"hexsha": "8dab04c65e0a9b9a6909dff2e56b6d4b11cda431", "size": 25608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lab_Manual/math.tex", "max_stars_repo_name": "vachan-potluri/MEANDG", "max_stars_repo_head_hexsha": "a4a22653b5d71b186e179519b0d26a21d3faf1b5", "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": "Lab_Manual/math.tex", "max_issues_repo_name": "vachan-potluri/MEANDG", "max_issues_repo_head_hexsha": "a4a22653b5d71b186e179519b0d26a21d3faf1b5", "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": "Lab_Manual/math.tex", "max_forks_repo_name": "vachan-potluri/MEANDG", "max_forks_repo_head_hexsha": "a4a22653b5d71b186e179519b0d26a21d3faf1b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-06-12T10:01:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-21T06:27:42.000Z", "avg_line_length": 47.687150838, "max_line_length": 267, "alphanum_fraction": 0.7061465167, "num_tokens": 7919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6291268852500262}}
{"text": "\\section{Results}\n\nThe hyperparameters of the \\acrshort{ESN} used in Figure \\ref{fig:ESN1} and\nFigure \\ref{fig:ESN2} were randomly assigned and therefore not optimized. In\nspite of this, preliminary predictions track reasonably well with grid demand.\nThe current iteration shows a potentially\nmisleading relationship between accuracy and training length. By inspection,\nFigure \\ref{fig:ESN2} is more accurate but the comparison is unfair because\nthe two ESNs are predicting different time periods.\nWe also conducted a single grid search for the optimal combination of\nspectral radius ($\\rho$) and noise injection (for regularization of reservoir\nneurons), shown in Figure \\ref{fig:gridsearch}, following the recommendations from\n\\cite{lukosevicius_practical_2012}.\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=\\columnwidth]{scaled_esn_network2.png}\n  \\caption{A simple ESN with a prediction of 100 hours into the future after\n  training on 1000 hours of historical data.}\n  \\label{fig:ESN1}\n\\end{figure}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=\\columnwidth]{scaled_esn_network.png}\n  \\caption{A simple ESN with a prediction of 100 hours into the future. After\n  training on 3500 hours of historical data.}\n  \\label{fig:ESN2}\n\\end{figure}\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": "4041ddac5cb7067bb67dc444e38b8ab0b5e6400e", "size": 1531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/abstracts/reservoir-computing-abs/results.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/results.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/results.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": 42.5277777778, "max_line_length": 82, "alphanum_fraction": 0.788373612, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6291268783198115}}
{"text": "\\section{Two-Moment Model}\\label{se:Two-MomentModel}\n\n\\subsection{Transport Equations}\n\\modified{We consider neutrino transport through a static background in a non-relativistic framework.  \nFor simplicity, we only include neutrino--matter interactions due to emission, absorption, and isoenergetic scattering.  \nIt is possible to include other interactions, such as neutrino--electron scattering and pair processes, in the two-moment model.  \nHowever, these interactions result in dense coupling across neutrino energies and across neutrino species, and we have not yet considered the realizability-preserving property of our scheme in this case.\nWe leave this for future work.}\n\nAfter scaling to dimensionless units, the Boltzmann equation 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 = f(\\omega,\\varepsilon,\\vect{x},t)$ gives the number of neutrinos propagating in the direction $\\omega\\in\\bbS^{2}$, with energy $\\varepsilon\\in\\bbR^{+}$, at position $\\vect{x}\\in\\bbR^{3}$ and time $t\\in\\bbR^{+}$.  \n$\\vect{\\ell}(\\omega)\\in\\bbR^{3}$ is the unit vector parallel to the neutrino three-momentum: $\\vect{p}=\\varepsilon\\,\\vect{\\ell}$.\nOn the right-hand side, $\\tau$ is a collision time scale.  \nIn opaque regions, where neutrinos have frequent interactions with the background, $\\tau\\ll1$.  \nIn transparent regions, where neutrinos rarely interact and stream freely, $\\tau\\gg1$.\nThe collision term, $\\cC(f)$, which models emission, absorption, and isoenergetic 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_{\\Ab}  + \\sigma_{\\Scatt} )$ is the ratio of the absorption opacity $\\sigma_{\\Ab}$ to the total opacity.  \nThe scattering opacity is $\\sigma_{\\Scatt}$.  \nThe limit $\\xi = 1$, when $\\sigma_{\\Scatt} = 0$, corresponds to pure absorption, while $\\xi = 0$, when $\\sigma_{\\Ab} = 0$, corresponds to pure scattering.  \nThe equilibrium distribution function for neutrinos is given by the Fermi-Dirac distribution:\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 $\\vect{z}:=\\{\\varepsilon,\\vect{x}\\}$, $T$ is the material temperature in energy units and $\\mu$ is the neutrino chemical potential.\nBoth $T$ and $\\mu$ depend on the spatial position $\\vect{x}$.\n\n\\subsection{Two-Moment Model}\n\nApproximate solutions to the Boltzmann equation, Eq.~\\eqref{eq:boltzmann}, can be found by solving the two-moment model.\nTo this end, define the angular moments of the distribution function as follows:\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}  \nThe zeroth moment, $\\cJ$, is referred to as the particle density.  \nThe first moment, $\\bcH$, is the particle flux, and the second moment, $\\bcK$, is proportional to the stress tensor.  \nBy integrating Eq.~\\eqref{eq:boltzmann} over the momentum-space angular dimension we obtain equations for the zeroth and the first moments:\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}\nwith $\\vect{\\cM}=(\\cJ,\\vect{\\cH})^{T}$, $\\vect{\\cF}=(\\vect{\\cH},\\vect{\\cK})^{T}$, and\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}$, $\\vect{\\cD}=\\mbox{diag}(\\xi,\\vect{I})$, and\n$\\vect{I}$ is the identity matrix.\nHence, the process of solving the Boltzmann equation, Eq.~\\eqref{eq:boltzmann}, for the neutrino distribution function $f(\\omega,\\vect{z},t)$, is replaced by solving the two-moment equations for the neutrino number density, $\\cJ(\\vect{z},t)$, and flux, $\\bcH(\\vect{z},t)$.  \n\n\\subsection{Algebraic Closures}\n\nThe moment equation for $\\bcH$ involves the higher moment $\\bcK$ and the two-moment model is open.  \nTo close the two-moment model, we consider algebraic closures.  \nFor the two-moment model, algebraic closures give an approximation to $\\bcK$ using the lower moments:\n\\begin{equation}\n  \\bcK = \\vect{k} \\cJ,\n\\end{equation}\nwhere $\\vect{k}$ is the Eddington tensor.  \nBy assuming that the distribution function is symmetric about a preferred direction $\\widehat{\\vect{h}}=\\vect{\\cH}/|\\vect{\\cH}|$, Levermore~\\cite{levermore_1984} proposed a simple form for the Eddington tensor:\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.  \nThus, the two-moment model is closed by specifying the scalar $\\chi$ in terms of $\\cJ$ and $|\\vect{\\cH}|$.  \n\n\\subsection{Constraints on the Moments}\n\nNeutrinos are fermions and obey the Pauli exclusion principle.  \nBecause of this, the neutrino distribution function is bounded; i.e.~$f \\in [0,1]$.\nAs a result, the angular moments $\\cJ$ and $\\vect{\\cH}$ and the Eddington factor $\\chi$ satisfy the following bounds~\\cite{levermore_1984,lareckiBanach_2011,kershaw_1976,shohatTamarkin_1943}: \n\\begin{align}\n\\cJ \\in[0,1], \\quad &(1-\\cJ)\\cJ-|\\vect{\\cH}| \\geq 0, \\label{eq:MomentsBounds} \\\\\n  \\chi_{\\mbox{\\tiny min}}\n  =\\max\\big(1-\\f{2}{3\\cJ},h^{2}\\big)\n  \\leq & \\chi \\leq \\min\\big(1,\\f{1}{3\\cJ}-\\f{\\cJ}{1-\\cJ}h^{2}\\big)=\\chi_{\\mbox{\\tiny max}},\n  \\label{eq:eddingtonFactorBounds}\n\\end{align}\nwhere $h = |\\bcH|/\\cJ$ is the flux factor.\n\\modified{The inequalities in Eqs.~\\eqref{eq:MomentsBounds} and \\eqref{eq:eddingtonFactorBounds} hold for moments as defined in Eq.~\\eqref{eq:angularMoments} with $f\\in[0,1]$.  \nIn a relativistic model (e.g., \\cite{shibata_etal_2011,cardall_etal_2013}), the evolved quantities --- functions of the moments in Eq.~\\eqref{eq:angularMoments} --- satisfy different bounds.  \nWe are currently exploring extensions of the realizability-preserving scheme presented here to the relativistic case.}\n\nThe constraints in Eq.~\\eqref{eq:MomentsBounds} define realizable moments $\\bcM$.  \nFor fermions, realizable moments can only be constructed from a distribution satisfying the bounds $f \\in [0,1]$.  \nMoreover, the set of realizable moments is convex: let $\\cR$ be the realizability set and $\\bcM_{1}, \\bcM_{2} \\in \\cR$, then $\\lambda \\bcM_{1} + (1-\\lambda)\\bcM_{2} \\in \\cR$ for any $\\lambda \\in [0,1]$~\\cite{chu_etal_2018}.\nAs we will see later in Section~\\ref{se:SpatialDiscretization}, this convexity makes it possible to design a realizability-preserving discretization for solving the two-moment model numerically.\n\nThe inequalities in Eq.~\\eqref{eq:eddingtonFactorBounds} deserve further attention.  \nThey are as important as those in Eq.~\\eqref{eq:MomentsBounds}, in maintaining consistency of the two-moment model with respect to Fermi-Dirac statistics.  \nWhen designing a numerical scheme for the two-moment model that maintains realizable $\\bcM$, it is also necessary for the Eddington factor to satisfy the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds}.  \n\nHowever, recently reported CCSN simulations using two-moment neutrino transport with algebraic closures have employed Eddington factors that can violate the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds}.  \nAs examples, we consider the Eddington factors discussed in~\\cite{murchikova_etal_2017}, where the suitability of several algebraic closures for two-moment neutrino transport was evaluated.  \nIn Fig.~\\ref{fig:EddingtonFactorsWithDifferentClosure}, we plot the Eddington factor versus the flux factor for two occupancies: $\\cJ = 0.1$ (low occupancy) and $\\cJ = 0.9$ (high occupancy).  \nOf the algebraic closures plotted, few satisfy the bounds on the Eddington factor in Eq.~\\eqref{eq:eddingtonFactorBounds}.  \nKershaw~\\cite{kershaw_1976}, Wilson~\\cite{wilson_1975,leblancWilson_1970}, Levermore~\\cite{levermore_1984}, Minerbo~\\cite{minerbo_1978}, and Janka~2~\\cite{janka_1992} closures may work fine when the occupancy is low.  \nWhen the occupancy is high, the Eddington factor due to these closures exceeds the upper bound for Fermi-Dirac statistics.  \nThe Eddington factor of Janka~1~\\cite{janka_1991} may violate both the upper and lower bound on the Eddington factor.  \nOnly the closure due to Cernohorsky~\\&~Bludman~\\cite{cernohorskyBludman_1994} satisfies both the upper and lower bounds.  \nThis is not surprising as this is the only closure based on Fermi-Dirac statistics.  \nAlthough the Levermore and Minerbo closures do not satisfy the bounds in Eq.~\\eqref{eq:eddingtonFactorBounds}, they are widely used in simulations of neutrino transport in CCSNe and compact binary mergers; e.g., O'Connor \\& Couch~\\cite{oConnorCouch_2018}, Pan et al.~\\cite{pan_etal_2018}, Glas et al.~\\cite{glas_etal_2018}, Just et al.~\\cite{just_etal_2018}, and Foucart et al.~\\cite{foucart_etal_2015} use the Minerbo closure, while Vartanyan et al.~\\cite{vartanyan_etal_2018}, Cabezon et al.~\\cite{cabezon_etal_2018}, Kuroda et al.~\\cite{kuroda_etal_2016}, and Fujibayashi et al.~\\cite{fujibayashi_etal_2017} use the Levermore closure.  \nWhen employing these closures in conditions of high occupancy, a numerical scheme may evolve the moments outside the realizable domain of Fermi-Dirac statistics given in Eq.~\\eqref{eq:MomentsBounds}.\nIf this were to happen, the update step may give $\\cJ>1$.\nConsidering the fact that the collision term contains blocking factors --- i.e.~$(1-\\cJ)\\times$ something positive --- $\\cJ > 1$ would change the blocking factors' sign, and it would be difficult to predict the impact of the subsequent induced errors on the simulation outcome.\nBesides, even with the simplified collision term Eq~\\ref{eq:collisionTermMoments}, $\\cJ>1$ could result in information loss (such as loss to the neutrino distribution for the groups that exceed the bounds), closure failure, and other unpredictable consequences.\nIf treatments are developed to map the unrealizable moments into the realizable domain, they should be developed to conserve lepton number, energy, and momentum.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tabular}{cc}\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_10}\n    \\includegraphics[width=0.5\\textwidth]{figures/Closures0_90}\n  \\end{tabular}\n   \\caption{Plot of Eddington factors $\\chi$ versus flux factor $h$ for different values of $\\cJ$ for various algebraic closures: $\\cJ=0.1$ (left panel, low occupancy) and $\\cJ=0.9$ (right panel, high occupancy).  In each panel we plot the Eddington factors of two-moment closures due to Kershaw (red), Wilson (yellow), Levermore (green), Minerbo (light blue), Cernohorsky \\& Bludman (blue), Janka~1 (purple), and Janka~2 (pink) .  We also plot $\\chi_{\\mbox{\\tiny min}}$ and $\\chi_{\\mbox{\\tiny max}}$, defined in Eq.~\\eqref{eq:eddingtonFactorBounds} (lower and upper dashed black lines, respectively).}\n  \\label{fig:EddingtonFactorsWithDifferentClosure}\n\\end{figure}", "meta": {"hexsha": "12b54e1f2f8d3dc953f41f5a3211d2f048b00255", "size": 11190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/M1/Astronum_2018/sections/TwoMoments.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/Astronum_2018/sections/TwoMoments.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/Astronum_2018/sections/TwoMoments.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": 86.0769230769, "max_line_length": 639, "alphanum_fraction": 0.7401251117, "num_tokens": 3430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6291268755068549}}
{"text": "\\documentclass{article}\n\n\\include{stddefs}\n\\include{imodefs}\n\n\\chapterno{4}\n\n\\begin{document}\n\n\\chapter{What is optimization?}\\label{whatisopt}\n\n\nIn this chapter we will denote the set of column vectors with $d$ rows by $\\RR^d$.\nThe arithmetic\nof $d\\times 1$ matrices apply i.e., we may add vectors in $\\RR^d$ and\nmultiply them by a number in $\\RR$.\n\nIn the next chapter we will introduce them as \\emph{euclidean} vector spaces. The\nterm euclidean refers to a norm: a function measuring the size of a vector. In this\nchapter we only need the structure as column vectors.\n\n\n\\section{What is an optimization problem?}\n\nAn optimization problem consists of maximizing or minimizing a function subject\nto constraints.\n\nBelow are two classical examples related to minimizing (non-linear) functions subject to\n(non-linear) constraints. These are actually examples of\nconvex optimization problems. More about that later.\n\n\\begin{example}\n\n  A cylindrical can is supposed to have a volume of $V$ $\\text{m}^3$. The material used\n  for the top and bottom costs $T$ DKK per $\\text{m}^2$ and the material used for\n  the side costs $S$ DKK per $\\text{m}^2$. Give the dimensions $r$ and $h$ of the\n  can minimizing the price of the materials.\n  \n\\includegraphics{cylinder.svg}\n\nThe cost of the top and bottom pieces are $2 \\pi r^2 T$. The cost of the\nside material is $2\\pi r h S$. The constraint is that the volume must be\n$V$. This is expressed in the equation $\\pi r^2 h = V$. All in all\nthe optimization problem is\n\\begin{align*}\n  &\\text{Minimize} &2\\pi r^2 T + 2\\pi r h S&\\\\\n  &\\text{with constraints}\\\\\n  &&\\pi r^2 h &= V\\\\\n  &&r &\\geq 0\\\\\n  &&h &\\geq 0,\n\\end{align*}\nwhere $V, T$ and $S$ are constants.\n\n\\beginshex\nCan you see a way of solving this optimization problem by eliminating $h$ in\nthe constraint $\\pi r^2 h = V$?\n\n\\begin{hideinbutton}{Hint}\n$$\n\\pi r^2 h = V\\iff h = \\frac{V}{\\pi r^2}\n$$\nand $h$ can be inserted in $2\\pi r^2 T + 2 \\pi r h S$. Why is this helpful?\n\\end{hideinbutton}\n\\endshex\n\\end{example}\n\n\\begin{example}\n  A person is in distress $D$ meters from the beach. The life guard\n  spots the situation, but is $d$ meters from where he would naturally jump\n  in the water as indicated below. The life guard runs $8$ m/s on the\n  beach and swims $1$ m/s in the water. How far ($x$) should he run along the\n  beach before jumping into the water in order to minimize the time needed\n  to reach the person in distress?\n  \n  \\includegraphics{lifeguard.png}\n\n  The time spent moving with a speed of $v$ over a distance of $s$ is\n  $$\n  t = \\frac{s}{v}.\n  $$\n  If the life guard jumps in the water at the point $x$ he will have\n  to swim a distance of\n  $$\n  \\sqrt{D^2 + (d-x)^2}\n  $$\n  using the Pythagorean theorem. Therefore the optimization problem becomes\n\\begin{align*}\n  &\\text{Minimize} &\\frac{x}{8} + \\sqrt{D^2 + (d-x)^2}&\\\\\n  &\\text{with constraints}\\\\\n  &&x\\geq 0\\\\\n\\end{align*}\nStrictly speaking we do not need the constraint $x\\geq 0$, as the life guard is free\nto run in the other direction. So the optimization problem is simply to minimize\n$$\n\\frac{x}{8} + \\sqrt{D^2 + (d-x)^2}\n$$\nwith no strings attached i.e., $x\\in \\RR$ is just assumed to be any number.\n\n\n\\begin{sage}\nD = 200\nd = 100\nplot(x/8 + sqrt(D**2 + (d-x)**2), (x, 0, d))\n\\end{sage}\n\n\\end{example}\n\n\n\\beginshex\n  You need to build a rectangular fence in front of your house for a herb garden.\n  Your house will make up one side of the rectangle, so you only need to build three\n  sides. Suppose you have 10 m of wire. What is the maximum area of the herb garden you can\n  wall in?\n\\endshex\n\n\n\\section{General definition}\n\nAn optimization problem consists of a subset $D\\subseteq \\RR^d$ and\na function $f:D\\rightarrow \\RR$. We will consider optimization problems in the context\nof minimization. Optimize in this situation means minimize.\n\n\\begin{definition}[emph]\\label{defopt}\n  In our most general setting an optimization problem looks like\n\\begin{align*}\n  &\\text{Minimize} &f(x)&\\\\\n  &\\text{with constraint}\\\\\n  &&x\\in C,\n\\end{align*}\n     where $C$ and $D$ are subsets of $\\RR^d$ with $C\\subseteq D$ and $f: D\\rightarrow \\RR$ is a function.\nA solution to the optimization problem is a vector $x_0\\in C$, such that\n$$\nf(x_0) \\leq f(x)\n$$\nfor every $x\\in C$. Here $x_0$ is called an \\emph{optimum} and $f(x_0)$ is called the \\emph{optimal value}.\n\nWe will often write the optimization problem defined above in short form as\n\\begin{align*}\n  &\\text{min}\\, f(x)\\\\\n  &x\\in C.\n\\end{align*}\n\\end{definition}\n\n\n  The complexity of the problem depends very much on the nature of $C$ and $f$. Also,\n  we cannot even be certain that an optimization problem has a solution. Consider\n  the problem\n\n  \\begin{align*}\n    &\\text{min}\\,x\\\\\n    &x\\leq 0\n  \\end{align*}\n\n  Here $x$ can be made arbitrarily small subject to the constraint $x\\leq 0$ and\n  the problem has no solution.\n\n\n\n\n\n  \\begin{remark}[emph]\n    We have deliberately not included maximization problems in Definition \\ref{defopt}. This is\nbecause a maximization problem, such as\n\\begin{align}\\label{maxprob}\n  &\\text{Maximize} &f(x)&\\\\\n  &\\text{with constraint}\\\\\n  &&x\\in C\n\\end{align}\n\n\n\n\n\n can be formulated as the minimization problem\n\\begin{align}\n  &\\text{Minimize} &-f(x)&\\\\\n  &\\text{with constraint}\\\\\n  &&x\\in C.\n\\end{align}\n\n\n\n\nAgain, we will use the short notation\n\\begin{align*}\n  &\\text{max}\\,f(x)\\\\\n  &x\\in C\n\\end{align*}\nfor the maximization problem in \\eqref{maxprob}.\nA solution to \\eqref{maxprob} is a vector $x_0\\in C$, such that\n$$\nf(x_0) \\geq f(x)\n$$\nfor every $x\\in C$. Again, $x_0$ is called an optimum and $f(x_0)$ the\noptimal value.\n\n\\end{remark}\n\n\n\\beginshex\nSuppose that the maximization problem \n\\begin{align}\\label{maxprob1}\n  &\\text{max}\\, f(x)\\\\\n  &x\\in C\n\\end{align}\nis formulated as\nthe minimization problem\n\\begin{align}\\label{minmaxprob}\n  &\\text{min}\\, -f(x)\\\\\n  &x\\in C.\n\\end{align}\nShow that $-m$ is the optimal value \nand $x_0$ the optimum for \\eqref{maxprob1} if\n$m$ is the optimal value \nand $x_0$ the optimum for \\eqref{minmaxprob}. \n\\endshex\n\n\n    \\beginshex\\label{mothercopt}\n    Suppose that $a > 0$. Solve the optimization problem\n\\begin{align*}\n    &\\text{Minimize} &a x^2 + b x + c\\\\\n    &\\text{with constraint}\\\\\n    &&x\\in \\RR.\n  \\end{align*}\n    \n    \\endshex\n\n    \\section{Convex optimization}\n\n    Particularly well behaved optimization problems are the convex ones. These are optimization\n    problems, where $C\\subseteq \\RR^d$ is a convex subset and $f:C\\rightarrow \\RR$ a\n    convex function in Definition \\ref{defopt}. To define these concepts we first introduce\n    the notion of \n    a line in $\\RR^d$.\n\n    \\begin{definition}[emph]\\label{defline}\n      A line $L\\subseteq \\RR^d$ is a subset of the form\n      $$\n      L = \\{u + t v \\mid t\\in \\RR\\},\n      $$\n      where $u, v\\in \\RR^d$ with $v\\neq 0$.\n    \\end{definition}\n\n\\begin{example}\nA line $L$ in the plane $\\mathbb{R}^2$ is (usually) given by its equation\n\\begin{equation}\\label{lineeq}\ny = a x + b.\n\\end{equation}\nThis means that it consists of points $(x, y)\\in \\mathbb{R}^2$ satisfying $y = a x + b$.\nHere $a$ can be interpreted as the slope of the line and $b$ the intersection with the\n$y$-axis.\n\nWhat about all the points $(x, y)$ with $x = 0$? Certainly they also deserve to be called\na line. However, they do not satisfy an equation like \\eqref{lineeq}. Informally, this line\nhas infinite slope.\n\nTherefore we introduce the parametric representation of a line: a line is the\nset of points of the form\n$$\n\\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix} +\nt \\begin{pmatrix} u_0 \\\\ v_0 \\end{pmatrix},\n$$\nwhere $t\\in \\mathbb{R}$,\n$$\n\\begin{pmatrix} x_0 \\\\ y_0\\end{pmatrix}\n$$\nis any point on the line and\n$$\n\\begin{pmatrix} u_0 \\\\ v_0\\end{pmatrix}\n$$\nis a non-zero (directional) vector.\n\n\\begin{figure}\n  \\includegraphics{line.png}\n  \\begin{center}\n    Example of a line in $\\RR^2$ with (directional) vector $v\\in \\RR^2$ through the point $u\\in \\RR^2$.\n  \\end{center}\n\\end{figure}\n\n\n\\end{example}\n\n\n\n\\beginshex\nCompute the parametric representation of the line through the points $(1, 1)$ and $(2, 3)$.\n\\endshex\n\n\\beginshex\nWhat is the parametric representation of the line with the equation\n$y = a x + b$? What is the parametric representation of the\nline consisting of the points $(x, y)$ with $x=0$?\n\\endshex\n\n\n    \\beginshex\n    Show in Definition \\ref{defline} that if $L$ is given by $u$ and $v$, then\n    you might as well replace $v$ by $s v$, where $s$ is a real number and $s\\neq 0$.  It gives\n    the same line.\n    \\endshex\n    \n\n\n\\begin{exercise}[emph]\n  Show that there is a unique line passing through two distinct points\n    $x, y\\in \\RR^d$ and that it is given by $u = x$ and $v = y - x$ in Definition \\ref{defline}.\n\\end{exercise}\n\n    \\beginshex\n    Do the points\n    $$\n    \\begin{pmatrix}1\\\\ 2\\\\ 3\\end{pmatrix}, \\quad \\begin{pmatrix} 4\\\\ 5\\\\ 6\\end{pmatrix}\n    \\quad\\text{and}\\quad \\begin{pmatrix} 7\\\\ 8\\\\ 9\\end{pmatrix}\n    $$\n    lie on the same line in $\\RR^3$?\n    \\endshex\n    \n    \\beginshex\n    Show that the line through two distinct points $x, y\\in \\RR^d$ is equal to the subset\n    $$\n    \\{ (1-t) x + t y \\mid t\\in \\RR\\} \\subseteq \\RR^d.\n    $$\n    \\endshex\n    \n\n    \\begin{definition}[emph]\\label{Def:convexsubset}\n    A convex subset $C\\subseteq \\RR^d$ is a subset that contains the\n    line segment between any two of its points $x, y\\in C$ i.e.,\n    $$\n    (1 - t) x + t y\\in C\n    $$\n    for every number $t$ with $0\\leq t \\leq 1$.\n    \\end{definition}\n\n\\begin{figure}\n  \\includegraphics{nonconvex.png}\n  \\begin{center}\n    Example of non-convex subset of $\\RR^2$.\n  \\end{center}\n\\end{figure}\n\n\n\\begin{quizexercise}[showhide]\n  \\begin{quiz}\n    \\question\n    Which of the subsets below are convex?\n    \\answer{T}\n    $$C=\\{1\\}\\subseteq \\RR$$\n    \\answer{F}\n    $$C=\\{1, 2\\}\\subseteq \\RR$$\n    \\answer{T}\n    The points $C$ on a line $y = a x + b$ in $\\RR^2$.\n    \\answer{F}\n    $$\n    C=\\{(x, y)\\in \\RR^2 \\mid x y \\geq 0\\}.\n    $$\n  \\end{quiz}\n\\end{quizexercise}\n\n    \\beginshex\n      A closed interval in $\\RR$ is a subset of the form\n      $$\n      [a, b] = \\{x \\mid a \\leq x \\leq b\\}\n      $$\n      for $a \\leq b$. Prove that $[a, b]$ is a convex subset of $\\RR$.\n\n\\begin{hideinbutton}{Hint}\n\nKeep cool and just apply the definitions! First of all, $x\\in [a, b]$ if and only if\n\\begin{equation}\\label{intdef}\na\\leq x \\land x \\leq b.\n\\end{equation}\nNow pick any $t\\in [0, 1]$. We must show that if $x\\in [a, b]$ and $y\\in [a, b]$, then\n$$\n(1 - t)x + t y \\in [a, b].\n$$\nYou may also write this out as\n$$\na\\leq x \\land x \\leq b\\qquad\\land\\qquad a\\leq y \\land y \\leq b\n$$\nimplies that\n$$\na\\leq (1 - t)x + t y \\qquad \\land \\qquad (1 - t)x + t y \\leq b. \n$$\n\n\\begin{hideinbutton}{Hint}\n$$\na\\leq x\\implies (1-t) a \\leq (1-t) x\\qquad\\land\\qquad a\\leq y \\implies t a \\leq t y\n$$\nimplies that \n$$\n(1 - t) a + t a \\leq (1-t)x + t y.\n$$\nWhat is $(1-t)a + a$?\n\\end{hideinbutton}\n\n\\end{hideinbutton}\n      \n\\endshex\n\n   \n    \\beginshex\n    Let $A$ and $B$ be convex subsets of $\\RR^d$. Prove that $A\\cap B$ is a\n    convex subset of $\\RR^d$. Generalize this to show that if $A_1, \\dots, A_n$\n    are any number of convex subsets of $\\RR^d$, then their intersection\n    $$\n    A_1 \\cap \\cdots \\cap A_n\n    $$\n    is a convex subset of $\\RR^d$. Is the union of two convex subsets necessarily convex?\n    \\endshex\n    \n    \\begin{definition}[emph]\\label{Def:convexfunction}\n    A convex function is a function $f: C\\rightarrow \\RR$\n    defined on a convex subset $C\\subseteq \\RR^d$, such that\n    $$\n    f((1 - t) x + t y) \\leq (1-t) f(x) + t f(y)\n    $$\n    for every number $t$ with $0\\leq t \\leq 1$.\n    \\end{definition}\n\n\\begin{figure}\n  \\includegraphics{convexfct.png}\n  \\begin{center}\n    Graph of convex function. The line segment between $(x, f(x))$ and $(y, f(y))$\n    lies above the graph.\n  \\end{center}\n\\end{figure}\n\n\n    \n    \\beginshex\\label{exconvfct}\n    Let the function $f: \\RR \\rightarrow \\RR$ be given by\n    $f(x) = a x + b$, where $a, b\\in \\RR$. Show that $f$ is a convex\n    function.\n\n    \\begin{hideinbutton}{Hint}\n      Try the case $a = 0$ first.\n    \\end{hideinbutton}\n\n    Can you at this point prove that $f(x) = x^2$ is a convex function?\n\n    \\begin{hideinbutton}{Hint}\n      Simplify\n      $$\n      (1 - t) x^2 + t y^2 - ((1-t) x + t y)^2\n      $$\n      to an expression that has to be non-negative.\n      \n      \\begin{hideinbutton}{Hint}\n        \\begin{sage}\nfrom sympy.abc import x, y, t\nf = (1-t)*x^2 + t*y^2 - ((1-t)*x + t*y)^2\nfactor(f)\n        \\end{sage}\n    \\end{hideinbutton}\n  \\end{hideinbutton}\n\n  Using that $f(x) = x^2$ is a a convex function, prove that $g(x) = x^4$ is a convex function and in general, that $h(x) = x^m$ is a convex function, where\n  $m = 2n$ is an even natural number.\n\n\\begin{hideinbutton}{Hint}\n      $$g(x) = f(x)^2$$\n    \\end{hideinbutton}\n  \n    It is a fact that $f(x) = x^3$ is not a convex function, but can\n    you explain this using the definition of a convex function?\n\n    \\begin{hideinbutton}{Hint}\n      Try $x = -1, y = 0$ and $t =\\frac{1}{2}$.\n    \\end{hideinbutton}\n    \\endshex\n\n    \\begin{lemma}[emph]\n    Let $f: \\RR^d\\rightarrow \\RR$ be a convex function. Then the subset\n    $$\n    C = \\{x\\in \\RR^d \\mid f(x) \\leq a\\}\n    $$\n    is a convex subset of $\\RR^d$, where $a\\in \\RR$.\n    \\end{lemma}\n    \\begin{proof}\n    Suppose that $u, v\\in C$ and $t\\in [0, 1]$. Looking at Definition \\ref{Def:convexsubset}\nwe must prove that\n$$\n(1-t) u + t v \\in C.\n$$\nBy the definition of $f$ being convex (Definition \\ref{Def:convexfunction}), it follows that\n$$\nf((1-t) u + t v) \\leq (1- t) f(u) + t f(v).\n$$ \nBut, since $f(u)\\leq a$ and $f(v)\\leq a$ we have\n\\begin{align*}\n(1- t) f(u) &\\leq (1-t) a\\\\\nt f(v) &\\leq t a\n\\end{align*}\nand therefore\n$$\n(1- t) f(u) + t f(v) \\leq (1-t) a + t a = a.\n$$\nTherefore, \n$$\nf((1-t) u + t v)\\leq a \n$$\nand $(1-t) u + t v\\in C$.\n\\end{proof}\n\n\n    We do not have the tools yet to prove the crucial\n    result about convex optimization problems, but at least we can state it.\n\n\n    \\begin{remark}[emph]\n    In hunting for optimal solutions to an optimization problem one is often stuck with a\n    point $x_0\\in \\RR^d$, which is optimal locally. This means that $f(x_0)\\leq f(x)$ for\n    every $x$ that is sufficiently close to $x_0$ (we will explain what this means in the next\n    chapter). The remarkable thing that happens in a convex optimization problem is\n    that if $x_0$ is optimal locally, then it is a global optimum! It satisfies\n    $f(x_0)\\leq f(x)$ not only for $x$ close to $x_0$, but for every $x\\in C$.\n\\end{remark}\n    \n    The optimization problem in Exercise \\ref{mothercopt} is a very typical convex optimization\n    problem.\n\n    Below you see a plot of the function (press Compute)\n    $$\n    f(x) = x^3 + 2 x^2 + x + 1\n    $$\n    restricted\n    to the interval $[-1.5, 0]$. You can see that it has a local minimum around $-0.3$ and\n    also that this minimum is not a global minimum (certainly $f(-1.4)$ is smaller). So $f(x)$\n    is not a convex function on this interval (but if you look at it more locally on the\n    interval $[-0.6, 0]$ it is a convex function.\n    \n    \\begin{sage}\n      plot(x**3+2*x**2+x+1, (x, -1.5, 0))\n    \\end{sage}\n\n    \\beginshex\n    Solve the optimization problem\n    \\begin{align*}\n    &\\text{Minimize} &x^3 + 2 x^2 + x + 1\\\\\n    &\\text{with constraint}\\\\\n      &&x\\in C\n    \\end{align*}\n    for $C = [-0.6, 0]$ and $C = [-2, 0]$.\n    \\endshex\n    \n  \\section{Linear optimization}\n\n  The simplest convex optimization problems are the linear ones. Recall that a\n  linear function $f: \\RR^d\\rightarrow \\RR$ has the form\n  $$\n  f\\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix} =\n  c_1 x_1 + \\cdots + c_n x_n\n  $$\n  for $c_1, \\dots, c_n\\in \\RR$. Usually we write this with matrix notation as\n  $$\n  f(x) = c^T x,\n  $$\n  where\n  $$\n  c =\n  \\begin{pmatrix} c_1 \\\\ \\vdots \\\\ c_n \\end{pmatrix}\\qquad \\text{and} \\qquad\n  x = \\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix}.\n  $$\n\n  \\beginshex\n  Show that a linear function is convex.\n  \\endshex\n  \n  A linear optimization problem is not about minimizing a linear function over\n  an arbitrary convex subset. We choose the convex subset as an intersection of\n  subsets of the form\n  $$\n  \\{x\\in \\RR^d\\mid a^T x \\leq b\\},\n  $$\n  where $a\\in \\RR^d$ is a non-zero vector and $b\\in \\RR$ a number i.e.,\n  a linear optimization problem has the form\n  \\begin{align*}\n    &\\text{min}\\,c^T x\\\\\n    &x\\in C,\n  \\end{align*}\n  where\n  \\begin{align}\\label{linsubs}\n    C &= \\{x\\in \\RR^d \\mid a_1^T x \\leq b_1, \\dots, a_m^T x\\leq b_m\\}\\\\\n    &= \\{x\\in \\RR^d \\mid a_1^T x \\leq b_1\\} \\cap \\cdots \\cap \\{x\\in \\RR^d \\mid a_m^T x \\leq b_m\\}\n  \\end{align}\n  and $c, a_1, \\dots, a_m\\in \\RR^d$ and $b_1, \\dots, b_m\\in \\RR$.\n\n  \\beginshex\n  Use a selection of previous exercises to show that\n  the subset $C$ defined in \\eqref{linsubs} is a convex subset of $\\RR^d$.\n  \\endshex\n  \n  Using matrix notation we write $C$ as\n  $$\n  C = \\{x\\in \\RR^d \\mid A x \\leq b\\},\n  $$\n  where $A$ is the $m\\times d$ matrix with row vectors $a_1^T, \\dots, a_m^T$ and\n  $$\n  b =\n  \\begin{pmatrix}\n    b_1 \\\\ \\vdots \\\\ b_m\n  \\end{pmatrix}.\n  $$\n\n  \\begin{example}\\label{exlinopt}\n  \n     Here is a concrete example for $d = 2$. The optimization problem\n  \\begin{align*}\n    &\\text{Maximize} &x + y&\\\\\n    &\\text{with constraints}\\\\\n    &&2 x + y &\\leq 1\\\\\n    &&x + 2 y &\\leq 1\\\\\n    &&x &\\geq 0\\\\\n    &&y &\\geq 0\n  \\end{align*}\n  translates into matrix notation with the matrices\n  \\newcommand{\\mi}{\\hphantom{-}}\n  $$\n  c = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}, \\qquad\n  A = \\begin{pmatrix} \\mi 2 & \\mi 1 \\\\ \\mi 1 & \\mi 2 \\\\ -1 & \\mi 0 \\\\ \\mi 0 & - 1\\end{pmatrix}\\qquad \\text{and}\\qquad\n  b = \\begin{pmatrix} 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{pmatrix}.\n  $$\n\n  In this case it is helpful to draw the optimization problem in the plane $\\RR^2$. This is done below.\n  \n  \\includegraphics{LP.png}\n  \\begin{center}\n    Constraints pictured as shaded area above. Optimum occurs in a vertex (corner).\n    \\end{center}\n  \n  \\end{example}\n  \n\n\n  \n  We will give a general (but rather slow) algorithm below for solving\n  linear optimization problems. In fact it all boils down to solving\n  systems of linear inequalities. Sometimes linear optimization is\n  referred to as \\url{linear\n    programming}{https://en.wikipedia.org/wiki/Linear_programming}. The\n  basic theory of linear programming was pioneered, among others, by\n  one of the inventors of the modern computer, John von Neumann.\n\n  \n\\includegraphics{vonNeumann.gif}\n\\begin{center}\n  \\url{John von Neumann}{https://en.wikipedia.org/wiki/John_von_Neumann} (1903-1957). Picture from \\url{LANL}{https://en.wikipedia.org/wiki/Los_Alamos_National_Laboratory}.\n\\end{center}\n\n  Sage has much more advanced algorithms built in for solving (integer) linear optimization\n  problems. I have translated the linear optimization problem in Example \\ref{exlinopt} into\n  Sage below.\n\n\\begin{example}\\label{sageLP}\n\\begin{sage}\nLP = MixedIntegerLinearProgram(solver = \"GLPK\")\n \n# generate variables (do not require integer solution) \nx = LP.new_variable(integer=False)\n \n# Linear function to be maximized (notice maximized!)\n\nLP.set_objective(x[1] + x[2])\n    \n# Add constraints\nLP.add_constraint( 2*x[1] + x[2] <= 1 );\nLP.add_constraint( x[1] + 2*x[2] <= 1 );\nLP.add_constraint( x[1] >= 0 );\nLP.add_constraint( x[2] >= 0 );\n\n \nLP.show()\n \noval = LP.solve()\nxopt = LP.get_values(x);\n \nprint('Optimal Value:', oval)\nprint('occurs in')\nfor i, v in xopt.items():\n    print('x_%s = %f' % (i, v))\n\\end{sage}\n\\end{example}  \n\n\n\\section{Fourier-Motzkin elimination}\n\nFourier-Motzkin elimination is a classical method (dating back to 1826) for solving linear inequalities. \nIt is also a key ingredient in an algorithm for solving linear optimization problems.\n\nI am convinced that\nthe best way to explain this method is by way of an extended example. For more formalities you may\nconsult \\url{Chapter 1}{https://www.worldscientific.com/doi/suppl/10.1142/8527/suppl_file/8527_chap01.pdf} of my book \\url{Undergraduate Convexity}{https://www.worldscientific.com/worldscibooks/10.1142/8527}.\n\nConsider the linear optimization problem\n\n\\begin{equation}\\label{optfmex}\n  \\begin{array}{llrrrr}\n    \\text{Maximize} &x + y\\\\\n    \\text{with constraints}\\\\\n    &2 x &+ &y &\\leq &6\\\\\n    &x &+ &2 y &\\leq &6\\\\\n    &x &+ &2 y &\\geq &2\\\\\n    &x && &\\geq &0\\\\\n    &&&y &\\geq &0.\n  \\end{array}\n\\end{equation}\n  \nWe might as well write this as\n\n$$\n  \\begin{array}{llrrrl}\n    \\text{Maximize} &z\\\\\n    \\text{with constraints}\\\\\n    &&& z &= &x + y\\\\\n    &2 x &+ &y &\\leq &6\\\\\n    &x &+ &2 y &\\leq &6\\\\\n    &x &+ &2 y &\\geq &2\\\\\n    &x &&&\\geq &0\\\\\n    &&&y &\\geq &0\n  \\end{array}\n$$\n  \n  by adding the extra variable $z$. This enables us to reformulate the problem as follows: Find\n  the maximal value of $z$, such that there exists $(x, y)\\in \\RR^2$ with\n  $$\n  (x, y, z)\\in P,\n  $$\n  where $P\\subseteq \\RR^3$ is the set of solutions to the system\n\n\n\\begin{equation}\\label{Pset}\n\n  \\begin{array}{llrrrl}\n    &&& z &= &x + y\\\\\n    &2 x &+ &y &\\leq &6\\\\\n    &x &+ &2 y &\\leq &6\\\\\n    &x &+ &2 y &\\geq &2\\\\\n    &x &&&\\geq &0\\\\\n    &&&y &\\geq &0\n  \\end{array}\n\n\\end{equation}\n  \n\n\n  of \\footnote{inequalities}{An equality $a = b$ is logically equivalent to the two\n    inequalities $a\\leq b$ and $a \\geq b$ in the sense that $(a\\leq b) \\wedge (a\\geq b) \\iff a = b$.}.\n\n  We have the Gauss elimination method for solving systems of linear equations. How do we now solve\n  \\eqref{Pset}, where we also have inequalities?\n\n  Well, at first we can actually do a Gauss elimination step by eliminating $x$ in the equation\n  $z = x + y$ i.e., by putting $x = z - y$. This is then inserted into the inequalities in\n  \\eqref{Pset}:\n\n$$\n\\begin{array}{llrrrl}\n    &2 (z - y) &+ &y &\\leq &6\\\\\n    &(z - y) &+ &2 y &\\leq &6\\\\\n    &(z - y) &+ &2 y &\\geq &2\\\\\n    &(z - y) &  &    &\\geq &0\\\\\n    &          &  &  y &\\geq &0\n\\end{array}\n$$\n\nand we get the system \n\n$$\n  \\begin{array}{llrrrl}\n    &2 z &- &y&\\leq &6\\\\\n    &z &+ &y &\\leq &6\\\\\n    &z &+ & y &\\geq &2\\\\\n    &z &- &y &\\geq &0\\\\\n    &  &  &y   &\\geq &0\n  \\end{array}\n$$\n  of inequalities\n  in the variables $z$ and $y$. Now we only have inequalities left and we have to invent a trick for\n  eliminating $y$. Let us isolate $y$ on one side of the inequality signs $\\leq$ and $\\geq$:\n\n  $$\n    \\begin{array}{llrrrl}\n    &2 z &- &6 &\\leq &y\\\\\n    &6 &- &z &\\geq &y\\\\\n    &2 &- &z &\\leq &y\\\\\n    & & &z &\\geq &y\\\\\n    &&&0 &\\leq &y\n  \\end{array}\n$$\n  \n  Written a little differently this is the same as\n\n\\begin{equation}\\label{fmex}\n  \\begin{array}{llllllllll}\n    &2 z &- &6&\\leq &{\\color{red} y} \\\\\n    &&&&&{\\color{red} y} &\\leq &6 &- &z\\\\\n    &2&- &z&\\leq &{\\color{red} y} \\\\\n    &&&&&{\\color{red} y} &\\leq &z\\\\\n    &&&0&\\leq &{\\color{red} y}\n  \\end{array}\n\\end{equation}\n\nNow the scene is set for elimination of $y$. Listen carefully. First the inequalities in \n\\eqref{fmex} can be boiled down to the following two inequalities\n\n\\begin{equation}\\label{fmex1}\n  \\begin{array}{lllll}\n\\max(2 z - 6, 2 - z, 0) &\\leq &{\\color{red} y}\\\\\n&& {\\color{red} y} & \\leq &\\min(6 - z, z)\n  \\end{array}\n\\end{equation}\nby using (repeatedly) that  $\\max(a, b) \\leq c \\iff a\\leq c \\wedge b\\leq c$ and\n  $c\\leq \\min(a, b) \\iff c\\leq a \\wedge c\\leq b$ for three\nnumbers $a, b, c\\in \\RR$.\n\nThen, finally comes the (Fourier-Motzkin) elimination step: The existence of a solution to \\eqref{fmex1} is\nequivalent to the single inequality\n\n\\begin{equation}\\label{singleineq}\n\\max(2 z - 6, 2 - z, 0) \\leq \\min(6 - z, z).\n\\end{equation}\n\nThis single inequality can be exploded or expanded (see Exercise \\ref{explex}) into the following $6 = 3\\cdot 2$ inequalities\n\n\\begin{align*}\n2 z - 6 &\\leq 6 - z\\\\\n2 z - 6 &\\leq z\\\\\n2 - z &\\leq 6 - z\\\\\n2 - z &\\leq z\\\\\n0 &\\leq 6 - z\\\\\n0 &\\leq z.\n\\end{align*}\n\nSimilarly to \\eqref{fmex} we now isolate $z$ from the above inequalities:\n\n\\begin{equation*}\n  \\begin{array}{lllll}\n&&{\\color{red} z} &\\leq &4\\\\\n&&{\\color{red} z} &\\leq &6\\\\\n1&\\leq &{\\color{red} z}\\\\\n&&{\\color{red} z} &\\leq &6\\\\\n0&\\leq &{\\color{red} z}\n\\end{array}\n\\end{equation*}\n\nand find that\n\n\\begin{equation*}\n  \\begin{array}{lllll}\n\\max(1, 0) = 1 &\\leq &{\\color{red} z}\\\\\n&& {\\color{red} z} & \\leq &\\min(4, 6) = 4.\n  \\end{array}\n\\end{equation*}\n\n\nTherefore the maximum in the optimization problem \\eqref{optfmex} is $z = x + y = 4$. \nHow do we now find numbers $x, y\\in \\RR$ satisfying the constraints\nin the optimization problem \\eqref{optfmex} with $z = x + y = 4$?\n\nThis is simply done inserting first $z = 4$ in \\eqref{fmex1}. Here you get the two inequalities\n$2 \\leq y$ and $y\\leq 2$. Therefore $y = 2$. Since we had $x = z - y$ from the very beginning\nwe therefore get $x = 2$ and we have the unique solution to the optimization problem.\n\n\\beginshex\nWhat is the solution if we replace Maximize with Minimize in the optimization problem \\eqref{optfmex}?\n\\endshex\n\n  \n\n\\beginshex\\label{explex}\n\nProve the following:\n\n    Let $x_1, \\dots, x_m, y_1, \\dots, y_n\\in \\RR$ be $m + n$ numbers. Then\n    $$\n    \\max(x_1, \\dots, x_m) \\leq \\min(y_1, \\dots, y_n)\n    $$\n    if and only if the $m n$ inequalities\n    $$\n    \\begin{matrix}\n      &x_1 \\leq y_1 &x_1 \\leq y_2 &\\dots &x_1\\leq y_n\\\\\n      \\\\\n      &\\vdots & \\vdots &\\ddots &\\vdots\\\\\n      \\\\\n      &x_m \\leq y_1 &x_m \\leq y_2 &\\dots &x_m\\leq y_n\n    \\end{matrix}\n    $$\n    are satisfied.\n\\endshex\n\n\\beginshex\n\nThe following is Exercise 1.8 from my book \\url{Undergraduate Convexity}{https://www.worldscientific.com/worldscibooks/10.1142/8527}.\n\nA vitamin pill $P$ is produced using two ingredients $M_1$\n  and $M_2$. The pill needs to satisfy four constraints for the vital\n  vitamins $V_1$ and $V_2$. It must contain at least $6$ milligrams and\n  at most $15$ milligrams of $V_1$ and at least $5$ milligrams and at\n  most $12$ milligrams of $V_2$. The ingredient $M_1$ contains $3$\n  milligrams of $V_1$ and $2$ milligrams of $V_2$ per gram.  The\n  ingredient $M_2$ contains $2$ milligrams of $V_1$ and $3$ milligrams\n  of $V_2$ per gram:\n\n$$\n\\def\\arraystretch{1.5}\n\\begin{array}{c|cc}\n& V_1 & V_2\\\\ \\hline\nM_1 & 3 & 2\\\\\nM_2 & 2 & 3\n\\end{array}\n$$\n\n\nLet $x$ denote the amount of $M_1$ and $y$ the amount of $M_2$\n  (measured in grams) in the production of a vitamin pill. Write down\n  a system of linear inequalities in $x$ and $y$ describing the\n  constraints above.\n\n  We want a vitamin pill of minimal weight satisfying the\n  constraints. How many grams of $M_1$ and $M_2$ should we mix?\n  \nUse Fourier-Motzkin elimination to solve this\n  problem.\n\nCheck your solution by modifying the input to the Sage code in Example \\ref{sageLP}. \n\n\\endshex\n\n  \n\\section{Application in machine learning and data science}\\label{sec:mlds}\n\n\nTo start with, consider a toy example of a machine learning problem: we wish\nto tell the gender of a person based on a data point consisting of\nthe height and weight of the person.\n\nTo do this we train our model by measuring the height and weight of a\nlot of people. Each of these measured data points are labeled\nfemale or male according to the gender of the person.\n\n\\includegraphics{sephp.png}\n\nGiven a new data point, we wish to tell if the person is female or male. Here we\nconsider a very simple model for doing this. First we need to introduce some\nnew mathematical terms. We will introduce the terms generally for\ndata points in $\\RR^d$ and not just in $\\RR^2$ as above.\n\n\nA hyperplane in $\\RR^d$ is a generalization of a line $y = a x + b$ in the plane. In general\na hyperplane is defined as the set of points $x\\in \\RR^d$ satisfying\n$$\na^T x = b,\n$$\nwhere $a\\in \\RR^d$ is a non-zero vector and $b$ is a number. A hyperplane divides $\\RR^d$\ninto two subsets: the points above or on the hyperplane satisfying $a^T x \\geq b$ and the ones\nbelow the hyperplane satisfying $a^T x < b$.\n\n\nSuppose we are given a data set as a finite set of points in $\\RR^d$ and that each of\nthese points are labeled with either a blue or a red color. We wish to\nfind a hyperplane, such that the blue points are above and the red points\nare below the hyperplane.\n\n\\includegraphics{sephpWithline.png}\n\n\nWe may then use the hyperplane to predict the label of a point. This could be\ngender, if you win or lose money buying a stock, anything with\na binary classifier.\n\n\n\n  \n  \\subsection{Formulation as a linear optimization problem}\n\n  Suppose that the points labeled blue are $x_1, \\dots, x_m\\in \\RR^d$ and\n  the points labeled red are $y_1, \\dots, y_n\\in \\RR^d$. Then we wish to\n  find $a\\in \\RR^d$ and $b\\in \\RR$, such that\n  $$\n  a^T x_i > b\n  $$\n  for $i = 1, \\dots, m$ and\n  $$\n  a^T y_j < b\n  $$\n  for $j = 1, \\dots, n$. One can show that these strict inequalities may be solved \n  for $a$ and $b$ if and only if the inequalities\n  \\begin{align*}\n  a^T x_i &\\geq b + 1\\\\\n  a^T y_j &\\leq b - 1\n  \\end{align*}\n  are solvable for $a$ and $b$, where $i = 1, \\dots, m$ and $j = 1, \\dots, n$.\n  \n  It is, however, not realistic to expect data to behave this nicely. Instead one invents\n  the rather ingenious linear optimization problem\n\n  \\begin{align}\\label{linoptnice}\n    &\\text{Minimize} &\\frac{1}{m}(u_1 + \\cdots + u_m) + \\frac{1}{n}(v_1 + \\cdots + v_n)\\\\\n    &\\text{with constraints}\\\\\n    &&a^T x_i + u_i&\\geq b + 1\\\\\n    &&a^T y_j - v_j &\\leq b - 1\\\\\n    &&u_i&\\geq 0\\\\\n    &&v_j&\\geq 0\n  \\end{align}\n  \n  for $i = 1, \\dots, m$ and $j = 1, \\dots, n$. This linear optimization problem has optimal value zero\n  if and only if data can be separated strictly. Otherwise, it finds a hyperplane minimizing the mean errors\n  for the points involved.\n\n  The linear optimization problem \\eqref{linoptnice} may look untied to the real world, but it has\n  been used very successfully in the diagnosis and prognosis of breast\n  cancer. See \\url{Mangasarian et al.}{https://www.jstor.org/stable/171686}\n\n  In the sage window below we have implemented the solution of the\n  linear optimization problem \\eqref{linoptnice}, where the output is\n  a graphical illustration of the optimal line, that separates the\n  points in \\texttt{xpts} and \\texttt{ypts} with the smallest mean\n  error as defined in the function to be minimized in \\eqref{linoptnice}.\n  \n\\begin{sage}\n# Enter blue data points below\nxpts = [(3, 1), (4, 2), (4, 3), (3, 5)]\n# Enter red data points below\nypts = [(2, 2), (2.5, 4.5), (3, 2), (4, 1)]\n\nLP = MixedIntegerLinearProgram(solver = \"GLPK\", maximization=False)\n \n# generate variables (do not require integer solution) \na = LP.new_variable(integer=False)\nb = LP.new_variable(integer=False)\nu = LP.new_variable(integer=False, nonnegative=True)\nv = LP.new_variable(integer=False, nonnegative=True)\n\n\n\n# Linear function to be minimized\n\nLP.set_objective(float(1)/len(xpts)*sum(u[i] for i in range(1, len(xpts)+1)) + float(1)/len(ypts)*sum(v[i] for i in range(1, len(ypts)+1)))\n    \n# Add constraints\n\nfor i in range(1, len(xpts)+1):\n  LP.add_constraint(xpts[i-1][0]*a[1] + xpts[i-1][1]*a[2] + u[i] >= b[1] + 1)\n\nfor j in range(1, len(ypts)+1):\n  LP.add_constraint(ypts[j-1][0]*a[1] + ypts[j-1][1]*a[2] - v[j] <= b[1] - 1)\n \n# LP.show()\n \noval = LP.solve()\naopt = LP.get_values(a);\nbopt = LP.get_values(b)\n\n# Compute frame for showing separating line\n\npts = xpts + ypts\nxvals = list(map(lambda x: x[0], pts))\nyvals = list(map(lambda y: y[1], pts))\n\nxmin = min(xvals)\nxmax = max(xvals)\nymin = min(yvals)\nymax = max(yvals)\n\n\n# Intersection of separating line with frame (cumbersome!):\n\nif (aopt[2] == 0):\n  x =  bopt[1]/aopt[1]\n  p1 = (x, ymin)\n  p2 = (x, ymax)\nelse:\n  a = -aopt[1]/aopt[2]\n  b = bopt[1]/aopt[2]\n  y = a*xmin + b\n  if (y >= ymin and y <= ymax):\n    p1 = (xmin, y)\n    x = (ymax - b)/a\n    if (x > xmin and x <= xmax):\n      p2 = (x, ymax)\n    else:\n      x = (ymin - b)/a  \n      if (x >= xmin and x <= xmax):\n        p2 = (x, ymin)\n      else:\n        p2 = (xmax, a*xmax+b)\n  else:\n    x = (ymax - b)/a\n    if (x >= xmin and x <= xmax):\n      p1 = (x, ymax)\n      y = a*xmax + b\n      if (y >= ymin and y < ymax):\n        p2 = (xmax, y)\n      else:\n        x = (ymin -b)/a\n        p2 = (x, ymin)\n    else:\n      p1 = (xmax, a*xmax + b)\n      x = (ymin - b)/a\n      p2 = (x, ymin)\n      \nshow(points(xpts, rgbcolor=(0, 0, 1), pointsize=30) + points(ypts, rgbcolor=(1,0,0), pointsize=30) + line([p1, p2], rgbcolor=(100, 100, 100), linestyle='dashed')) \n\\end{sage}\n\n\n\\end{document}\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "9fceb9677f197ef65001d4dd7f28723f6511abca", "size": 32243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IMO21/whatisopt.tex", "max_stars_repo_name": "FunByJohn/QaDiL", "max_stars_repo_head_hexsha": "9e22bb061c5a2c32473c7ab3aa9b9cce4e98c963", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-05-31T08:27:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T22:05:28.000Z", "max_issues_repo_path": "Notes/IMO21/whatisopt.tex", "max_issues_repo_name": "FunByJohn/QaDiL", "max_issues_repo_head_hexsha": "9e22bb061c5a2c32473c7ab3aa9b9cce4e98c963", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2021-06-05T20:37:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-13T16:38:52.000Z", "max_forks_repo_path": "Notes/IMO21/whatisopt.tex", "max_forks_repo_name": "FunByJohn/QaDiL", "max_forks_repo_head_hexsha": "9e22bb061c5a2c32473c7ab3aa9b9cce4e98c963", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-10T08:26:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-25T02:04:32.000Z", "avg_line_length": 28.7883928571, "max_line_length": 208, "alphanum_fraction": 0.6416896691, "num_tokens": 11253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.6290892304289862}}
{"text": "\n\\subsection{Minimax}\n\\subsubsection{Games}\n\nGames are different to search. In a search algorithm we are looking for a sequence of actions. In a game we are looking for a reaction function. Unlike in seach, there are other players.\n\nWe can use iterative deepening search.\n\n\\subsubsection{Heuristics}\n\nThe search space can be too big to look through all the nodes. \n\nRather than look for win states, we evaluate a non-terminal state using heuristics.\n\n\\subsubsection{Stochastic games}\n\nCan use expectminimax\n\nFor max node, return highest expectminimax of children\n\nFor min node ---\n\nFor chance node, average of children weightted\n\nMinimax: two players, max min\n\nMax goes first, maximises results. min minimises results\n\nA node's minimax value is the best outcome against best player.\n\nTo find optimal strategy, depth first search of game tree.\n\nPropagate minimax values up tree as terminal nodes are discovered\n\nIf a state is terminal, its value is utility of state\n\nIf a state is max node, highest value of children\n\nIf a state is min node, lowest value of children\n\nMinimax is optimal, complete (for finite trees)\n\n", "meta": {"hexsha": "357e2048a124faddda6a12442b7f47b36fa0ff47", "size": 1116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/gameTheoryDeep/06-01-miniMax.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/06-01-miniMax.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/06-01-miniMax.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.9534883721, "max_line_length": 186, "alphanum_fraction": 0.7867383513, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6290892275812829}}
{"text": "\n\n\n\\textit{Combinatorics. Logic. Programming.} This dissertation is an attempt to\nexplore how each entity relates to the others. Seen as a set of rules that\ncharacterize our methodology, we apply and use them to study the topic of\n\\textit{infinite~sequences}.  Our approach is two-fold, it allows us, first, to\nprove theoretical results about them; second, to built an orbit around them\ncomposed of side-track techniques that helps our main goal, such as programming\ntechniques and logical reasoning.\n\nIn particular, the research field of interest concerns (i)~the manipulation of\na set of matrices that can be algebraically defined, which deserve interest\nboth as standalone objects and as tools to study other combinatorial\nstructures; (ii)~the \\textit{practice of programming} that exposes our way of\nthinking to its paradigms, functional and relational in particular, and\n(iii)~the rigor and power of \\textit{mechanized logic}.\n\nIn normal conditions, it is hard to tackle a problem in our context with both\nentities present at the same time; however, we sacrifice a direct approach to\nsolve the given questions to get the most out of the process that uses the\nthree tenets together. In this philosophy the constant delay, needed to sharpen\nour knowledge in each individual field, is balanced by the discovery of\nrelations among apparently unrelated subjects that when mixed together yield\nnicer, more elegant and possibly unexpected solutions.\n\nFor this reason we spread our focus over many topics of mathematics and\ncomputer science instead of composing a mono-theme discussion; pairwise,\nwe deepen into\n\\begin{description}\n\n    \\item[Combinatorics and Programming] the implementation of enumeration\n    techniques for classes of combinatorial objects from both the algebraic\n    and applicative points of view;\n\n    \\item[Programming and Logic] the study of a family of languages designed\n    for relational programming, using a general purpose inference engine to\n    perform deductions over domain specific objects;\n\n    \\item[Logic and Combinatorics] the formalization of proofs to which\n    corresponds certified enumerations of classes of objects, using an extended\n    theorem prover based on Higher Order Logic.\n\n\\end{description}\n\nEven though abstract reasoning took place most of the time, we make\nsome room for practical stuff; in particular, we would like to provide a suite\nof tools that helps interacting with the Online Encyclopedia of Integer\nSequences, to automate fetching, printing and graphing the networks they\ncompose. Moreover, some practice with bitmasking and backtracking techniques is\ndone to show some interesting tiling and enumeration problems.\n\nAnother force that drove our work is a pedagogical approach to problem solving,\nhence we preferred to refine a first, naive solution over and over to cut away\nunnecessary details and complexities; moreover, we don't seek for efficiency in\nall cases in favor of simple and beauty definitions. This methodology allows us\nto use many programming languages and environments to support theoretical\nderivations and this dissertation collects this heterogeneous pool of techniques.\n\n\n\\section*{Structure}\n\nThis dissertation has 5 main chapters that rely on the first one, which\nintroduces basic definitions needed by the following ones; so, except for the\nfirst, the others can be read in any order,\n\\begin{itemize}\n\\item Chapter \\ref{ch:backgrounds} quickly recalls the theory characterizing\nthe Riordan group and provides a set of constructors to define those matrices\nprogrammatically, after the introduction of the symbolic module Sympy\nimplemented on top of the Python programming language. Moreover, it shows our\nprogramming style which is based on consecutive manipulation of symbolic\nequations, as mush as possible close to paper and pencil derivations.\n\\item Chapter \\ref{ch:Riordan-matrices-function} presents a theoretical and\npractical framework that lifts a scalar function to a matrix function, toward\napplication to Riordan matrices. To the best of our knowledge, this is the\nfirst implementation that allows the user to perform its computations fully\nsymbolically, postponing to the end the substitution of ground values to fill\nmatrices with numbers. Moreover, the Jordan Canonical Form of Riordan matrices\nis also studied.\n\\item Chapter \\ref{ch:algebraic-gfs-languages-avoiding-Riordan-patterns}\nstudies the enumeration of languages of binary words avoiding a given pattern,\nprovided that some contraints over the structure of each word are taken into\naccount.  In particular, when the pattern to avoid is a Riordan pattern then\nthe problem can be solved using Riordan arrays, deriving new series\ndevelopments about enumerations with respect to the number of $1$-bits and to\nthe length. Finally, some combinatorial interpretations are shown, at least for\nsimpler families of languages.\n\\item Chapter \\ref{ch:OEIS:tools} implements a suite of tools that interact with\nthe Online Encyclopedia of Integer Sequences; in particular, a (i)~crawler fetches\nsequences and their cross references recursively, using asynchronous primitive\nto optimize network delays, a (ii)~(pretty) printer for the fetched sequences that\nallows the user to filter the sections to be rendered both in the terminal and in\nweb interfaces and, finally, a (iii)~grapher that draw graphs where vertices\nare sequences and edges are references among them.\n\\item Chapter \\ref{ch:queens-tilings-polyominoes} is an exercise in\nbacktracking techniques to solve tiling and placement problems; for the sake of\nefficiency, bit masking manipulation and encodings are used. Moreover, it\nprovides an implementation of a classic enumeration methodology that allows us\nto clearly show generations of combinatorial objects starting from concise and\nrecursive symbolic definitions; finally, counting all of them is a check of\nthe correctness of our implementation.\n\\item Chapter \\ref{ch:scilp} proposes an extension to the tactic mechanism\nactually present in the HOL Light theorem prover inspired by the relational\nparadigm. This prototype makes explicit use of meta-variables to support\nsubstitutions and allows backtracking facilities during the interactive proof\nprocess; nonetheless, the proposed generalization offers compositionality just\nas the current system does. So this extension is stressed against an evaluator\nfor a subset of the Lisp language to find a \\textit{quine} program.\n\\end{itemize}\n\nMoreover, a final paragraph concludes with a quick summary of our main results\nand the bibliography ends this dissertation.\n\n\\section*{Typographical and typesetting conventions}\n\nThis dissertation was typeset using the \\LaTeX\\,'s style \\verb|tufte-book|,\nwhich splits each page into two columns: the left-most is greater in width and\nholds the main body, while the right-most is lesser and holds captions,\ncontextual data and code comments; in particular, code chunks are printed in\n\\verb|verbatim| and highlighted wherever possible, while outputs that denote\nmathematical objects are printed in math style, as usual -- when their size\noverflows over the right column we prefer to allow it to take the entire\npage width for the sake of clarity.\n\n\n\n\n", "meta": {"hexsha": "8600288462ebd39dcae40d981374915a96ec1a33", "size": 7201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "introduction/introduction.tex", "max_stars_repo_name": "massimo-nocentini/PhD-thesis", "max_stars_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "introduction/introduction.tex", "max_issues_repo_name": "massimo-nocentini/PhD-thesis", "max_issues_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "introduction/introduction.tex", "max_forks_repo_name": "massimo-nocentini/PhD-thesis", "max_forks_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_forks_repo_licenses": ["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.2578125, "max_line_length": 82, "alphanum_fraction": 0.8150256909, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6290892211467282}}
{"text": "\\chapter{Method}\\label{ch:method}\n\nAs stated in the introduction, this thesis examines a way to train a machine learning classifier to predict the nominal stock price change.\nThis chapter will now introduce the classifiers that were trained, as well as the approach to represent the business reports as feature vectors using \\acs{BERT}.\n\n\\section{Overview of machine learning algorithms}\nAll these algorithms have in common, that they take a $n$-dimensional input vector to predict $m$ classes.\nMathematically this can be seen as a function $f(x)=y$ with $x\\in\\mathbb{R}^n$ and $y\\in\\{0, 1\\}$, since it is a binary classification problem.\nThe algorithms are able to find patterns in the data and can autonomously improve their prediction performance.\nThis learning process requires a training phase.\nDuring the research a Naive Bayes classifier, a \\acl{KNN} classifier, a \\acl{SVM} and a \\acl{BLSTM} was trained.\n\\subsection{Naive Bayes classifiers}\nThe idea behind the Naives Bayes classifier is, that certain input features correlate with a certain class, which means that these input features result with a high probability from this certain class.\nThe Naive Bayes classifier makes use of the assumption, that each feature of the input vector is independent to one another.\nUsing the Bayes theorem (equation \\ref{equation:bayes}), the Naive Bayes classifier can compute the probability of a class given the features of the input.\n\\begin{equation}\n    P(Y|X) = \\frac{P(X|Y)P(Y)}{P(X)}\n    \\label{equation:bayes}\n\\end{equation}\nThe probability $P(Y)$ is given by the proportion of a class in the whole training dataset.\nFor a balanced dataset with two classes this gives the probabilities $P(y_1, y_2)=\\langle0.5,0.5\\rangle$.\nDetermining $P(X|Y)$ is not as trivial:\nSince $X$ can be a vector $(x_1, x_2, ..., x_n)$ of variables, it would be necessary to determine $P(x_1 \\land x_2 \\land ... \\land x_n|Y)$ for all combinations of $x_i$, which would require $O(2^n)$ space to save the values and make it impossible to use the algorithm with high dimensional input \\cite[p. 493]{Russel2016}.\nThe assumption that $x_1, ..., x_n$ are independent, however, simplifies this problem.\n$P(x_1 \\land x_2 \\land ... \\land x_n|Y)$ can now be decomposed into $P(x_1|Y)\\cdot P(x_2|Y)\\cdot...\\cdot P(x_n|Y)$ which only requires $O(n)$ to save the conditional probabilities and allows for practical usage of the algorithm \\cite[p. 499]{Russel2016}.\nSo during training the algorithm has to determine $P(Y)$ and $P(x_1|Y), P(x_2|Y) ... P(x_n|Y)$.\nThe probability $P(X)$ is a normalization factor which is chosen so that $P(y_1|X)+P(y_2|X)=1$ \\cite[p. 493]{Russel2016}.\nDuring prediction phase $P(Y|X)$ is computed for all classes and the class with the highest probability given $X$ will be the classification result:\n\\begin{equation}\n    y_{pred} = arg max_i P(y_i|X)\n\\end{equation}\nEven though the assumption, that the features are independent to one another is generally not true, the Naive Bayes classifier often performs equally or even better than more complex methods \\cite[p. 211]{Hastie2009}.\nFor this research, the Naive Bayes implementation from scikit-learn was used.\n\n\\subsection{\\acl{KNN} classifiers}\nAs the name of this method implies, a nearest neighbor classifier makes its predictions based on the surrounding data points.\nBecause every input to this classifier can be seen as a point in a n-dimensional space, the \\ac{KNN} can compute the distances to other points.\nThe distance can be measured as Euclidean distance, however other distance metrics are also possible.\nScikit-learn's \\texttt{KNeighborsClassifier} for example, measures the distance with the Minkowski distance, which is a generalisation of the Euclidean distance\\footnote{\\url{https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html}}:\n\\begin{equation}\n    d(x_1, x_2) = \\left(\\sum_{i=1}^n \\abs{x_{1,i} - x_{2,i}} ^p \\right)^{\\frac{1}{p}}\n\\end{equation}\nThe Minkowski distance collapses to the Euclidean distance for $p=2$ and to the Manhatten distance for $p=1$ \\cite[p. 738]{Russel2016}.\nThe predicted class is then the most common class of all $k$ neighbors.\nBecause the \\ac{KNN} classifier makes use of a geometric property of the input data, it is important to scale each feature to have a mean of zero and a variance of one \\cite[p. 465]{Hastie2009}.\n\nIn this thesis the \\ac{KNN} implementation from scikit-learn was used as well as the \\texttt{StandardScaler} to scale the features.\n$k$ was determined by creating a validation curve (section \\ref{subsec:learning_validation_curve}), which shows how the accuracy changes for different values of $k$.\nIt is implemented with the code in listing \\ref{py:knn_validation_curve}.\nThe results of this finding are presented in chapter \\ref{ch:experiments}.\n\\lstinputlisting[language=Python,caption={Creates data for a validation curve},captionpos=b, label={py:knn_validation_curve}]{listings/knn_validation.py}\nThe \\texttt{knn\\_\\_n\\_neighbors} argument tells the \\texttt{validation\\_curve} function, which parameter it should test for the provided estimator.\nIn this case the estimator is a pipeline, which wraps the \\texttt{StandardScaler} and the \\texttt{KNeighborsClassifier} and executes them sequentially.\nThe \\texttt{validation\\_curve} also allows to use cross-validation, where the number of folds can be set with the \\texttt{cv} argument.\nCross-validation is explained in detail in section \\ref{subsec:cross_validation}.\n\n\\subsection{\\acl{SVM}s}\nA \\ac{SVM} tries to fit a decision boundary between the points of two classes, so that the surrounding margin is maximised.\nThis decision boundary can mathematically be seen as a hyperplane in the n dimensional space of the data points.\nFor a two dimensional space that results in a line:\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{figures/svm_decision_boundary.png}\n    \\caption{A decision boundary with its support vectors.\\protect\\footnotemark}\n    \\label{figure:svm_decision_boundary}\n\\end{figure}\n\\footnotetext{A modified version of the example on scikit-learn: \\url{https://scikit-learn.org/stable/auto_examples/svm/plot_separating_hyperplane.html}}\nThe line in figure \\ref{figure:svm_decision_boundary} represents the decision boundary and the dashed lines mark the borders of the margin with maximum width, respecting some constraints which will be discussed in this section.\nThe circled points mark the \\textit{support vectors} which are used to determine the hyperplane.\nThe decision boundary is mathematically a hyperplane defined by:\n\\begin{equation}\n    f(x)=x^T\\beta + \\beta_0=0\n    \\label{equation:svm_hyperplane}\n\\end{equation}\nwhere $\\beta$ is a unit vector, $x_i \\in \\mathbb{R}^n$ are the sample points and $y_i \\in \\{-1, 1\\}$ are the labels to these points.\nTherefore the aim is to maximise the margin between the training points and the hyperplane, which can be re-expressed as\n\\begin{align}\n    & min_{\\beta, \\beta_0}\\frac{1}{2}\\abs{\\abs{\\beta}}^2 + C\\sum_{i=1}^N\\xi_i \\\\\n\\text{subject to }\n    & \\xi_i \\geq 0, y_i(x_i^T\\beta + \\beta_0)\\geq 1 - \\xi_i \\forall i \\notag\n\\end{align}\nwhere $\\xi_i$ is a penalty term, that increases with the distance a data point $x_i$ lies on the wrong side of its margin \\cite[p. 7]{Fletcher2008}.\nSince this penalty terms are weighted by the constant $C$, the width of the margin varies with choosing the value of $C$.\nIf $C$ is set really low, a broad margin with many support vectors is used.\nIf it is set high, only points near the decision boundary are used as support vectors \\cite[p.421]{Hastie2009}.\nThis optimization problem can be solved using Lagrange multipliers and gives for $\\beta$\n\\begin{equation}\n    \\beta = \\sum_{i=1}^{N} \\alpha_i y_i x_i\n\\end{equation}\nand for $\\beta_0$\n\\begin{equation}\n    \\beta_0 = \\frac{1}{N_S} \\sum_{i=1}^{N_S}(y_i - \\sum_{j=1}^{N_S} \\alpha_j y_J x_i^T x_j)\n\\end{equation}\n$\\alpha$ is the Lagrange multiplier which is $0 < \\alpha \\leq C$ for all \\textit{support vectors} and $0$ for all other points \\cite[p. 746]{Russel2016}.\nIts exact value can be determined with the dual Lagrangian function of equation \\ref{equation:svm_hyperplane} \\cite[p. 9]{Fletcher2008}.\n\nThe \\ac{SVM} as defined so far, has the drawback, that it only creates linear decision boundaries.\nOften the classes are not linearly seperable, so a mathematical trick is used, that the \\ac{SVM} can still perform on such data.\nThis is done with a kernel function, which maps the data points to a enlarged feature space.\n% $\\xi_i$ are the \\textit{support vectors}.\n% The support vectors are the points that are used to build up the decision boundary, so that it has a maximum distance to them.\n% If the classes are linearly seperable, these are the closest points of one class to the other class.\n% If the data points of both classes overlap, the support vectors are constructed from the points of one class that lie in the decision region of the other class.\n% $C$ is the parameter which sets the width of the margin, if it is set really low, a broad margin with many support vectors is used.\n% If it is set high, only points near the decision boundary are used as support vectors.\nA way to find decision boundaries for data which is not linearly seperable is to enlarge the feature space with a kernel function.\nThus the data becomes linearly seperable in the enlarged feature spaces, which has the effect of nonlinear boundaries in the original space \\cite[p.423]{Hastie2009}.\nOne typical kernel function is the \\textit{Radial Basis Kernel} which has the following form:\n\\begin{equation}\n    K(x_i, x_j) = e^{-\\frac{\\abs{\\abs{x_i - x_j}}^2}{2\\sigma^2}}\n\\end{equation}\nThe kernel function is used in the dual Lagrangian function of equation \\ref{equation:svm_hyperplane}, which is then again optimised.\nThis has the implicit effect, that the datapoints are mapped to a higher dimensional feature space.\nFigure \\ref{figure:kernel_3d} shows this mapping to a three-dimensional space with the hyperplane, that seperates the classes, figure \\ref{figure:kernel_decision_boundary} shows the base feature space with the resulting circular decision boundary.\n\\begin{figure}[h]\n    % \\centering\n    \\subcaptionbox{Datapoints with a circular decision boundary, resulting from the kernel trick.\\label{figure:kernel_decision_boundary}}[0.5\\linewidth]{\\includegraphics[width=0.5\\textwidth]{figures/svm_circular_decision_1.png}}\n    \\subcaptionbox{When mapped to a higher dimensional space, the datapoints become linearly seperable.\\label{figure:kernel_3d}}[0.5\\linewidth]{\\includegraphics[width=0.5\\textwidth]{figures/svm_circular_decision_2.png}}\n    % \\begin{subfigure}{0.5\\textwidth}\n    %     \\centering\n    %     \\includegraphics[width=\\textwidth]{figures/svm_circular_decision_1.png}\n    %     \\caption{Datapoints with a circular decision boundary, resulting from the kernel trick.}\n    %     \\label{figure:kernel_decision_boundary}\n    % \\end{subfigure}\n    % \\begin{subfigure}{0.5\\textwidth}\n    %     \\centering\n    %     \\includegraphics[width=\\textwidth]{figures/svm_circular_decision_2.png}\n    %     \\caption{When mapped to a higher dimensional space, the datapoints become linearly seperable.}\n    %     \\label{figure:kernel_3d}\n    % \\end{subfigure}\n    \\caption{The kernel trick as visualised in \\cite[p. 747]{Russel2016}}\n    \\label{figure:svm_kernel_trick}\n\\end{figure}\n\n\\subsection{Artificial Neural Networks}\nArtificial neural networks imitate the structure of a brain, where each neuron receives input from other neurons, processes this information and passes it on to other neurons \\cite[p. 727]{Russel2016}.\nIn artificial neural networks these neurons are represented as \\textit{units}, which perform a mathematical operation on their input data.\nThis consists of first computing a weighted sum of its inputs and then applying a activation function $g$ on that sum, which determines whether the unit \"fires\" \\cite[pp. 727-728]{Russel2016}:\n\\begin{equation}\n    a_j=g\\left(\\sum_{i=0}^{n}w_{i,j}a_{i}\\right)\n    \\label{equation:nn_unit_operation}\n\\end{equation}\nWhere $w_{i,j}$ is the weight, assigned to the input $a_i$.\nA typical activation function is the sigmoid function defined by $\\sigma(x)=\\frac{1}{1+e^{-x}}$.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{figures/sigmoid.png}\n    \\caption{The sigmoid function.}\n    \\label{figure:sigmoid}\n\\end{figure}\nAs it can be seen in figure \\ref{figure:sigmoid}, the sigmoid function results in values in the range from 0 to 1, which can be interpreted as the probability that the input belongs to one class.\nThe units are then structured into layers, with the simplest possible network having only two layers, one input and one output layer.\nThese simple networks are limited in their learning capabilities, that is why usually several hidden layers are added \\cite[pp. 730-731]{Russel2016}.\n% The input $a_j$ to a unit in such a hidden layer is itself the result of the computation with the function \\ref{equation:nn_unit_operation}, therefore the whole network can mathematically be seen as a function applied to the input vector.\nThe network network predicts values by computing the output of each unit with function \\ref{equation:nn_unit_operation} starting from the input layer.\nThe nodes in the subsequent layers use the same function to compute their outputs, however the input $a_i$ is the result of the computations on the previous layer.\nThe results of this computation on the output layer is the prediction of the network.\nAt training time, the units of the output layer then compute an error between the prediction it made and the actual value it should have predicted.\nA common error metric is the squared-error loss $Loss_k$ on an output node $k$, which is defined in equation \\ref{equation:squared_error_loss} \\cite[p. 735]{Russel2016}.\n\\begin{equation}\n    Loss_k=(y_k - a_k)^2\n    \\label{equation:squared_error_loss}\n\\end{equation}\nWith $a_k$ being the predicted value on output $k$ and $y_k$ being the actual value that should be predicted.\nThe aim is to minimise this loss with respect to all weights $w_{i,j}$ in the network:\n\\begin{equation}\n    \\frac{\\partial Loss_k}{\\partial w_{i,j}}    \n\\end{equation}\nThis gives the gradient for the output node $k$.\nThe gradient can be computed with the \\textit{back-propagation} algorithm.\nThe last layer computes an error term, based on the derivative of the loss function.\nThis error term is back-propagated to the previous layer, where each node again computes its own error, by summing the weighted errors of the subsequent nodes.\nThis is again repeated until the input layer is reached, then the weights between all nodes are updated based on the determined error terms \\cite[p. 734]{Russel2016}.\n% Auf nichtlinearität eingehen\n\nA special class of neural networks are the \\acp{RNN}, which have the ability to gather information from the order of the input items.\nTherefore each input example consists of several \\textit{timesteps}.\nIn case of report classification, like it is done in this thesis, the timesteps are the sentences of the report, which have a clear order to each other.\nTo process this sequential data, the units in a \\acs{RNN} (figure \\ref{figure:rnn_unfolded}) are different to the units of a traditional feed-forward neural network.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/rnn_unfolded.png}\n    \\caption{The flow of the activations between two timesteps in an RNN as depicted in \\cite[p. 12]{Lipton2015}.}\n    \\label{figure:rnn_unfolded}\n\\end{figure}\nThey have one input from the previous layer and a second one from the previous timestep.\nOn the output side they have an output for the next timestep and optionally also an output to the next layer \\cite[p. 373]{Goodfellow2016}.\nThe training is done by computing the loss in the last timestep and propagating the loss back to the previous timestep.\nA problem that occurs in standard \\acp{RNN} is that the gradient decayes or increases exponentially while propagated back in time \\cite[p. 13]{Lipton2015}.\nA concept to avoid this problem is the \\acs{LSTM}, which was proposed by \\cite{Hochreiter1997}.\nFigure \\ref{figure:lstm_cell} shows the structure of a LSTM cell.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{figures/lstm_cell.png}\n    \\caption{A LSTM cell as depicted in \\cite[p. 17]{Lipton2015}.}\n    \\label{figure:lstm_cell}\n\\end{figure}\nEach of these units has an input gate which protects the unit against irrelevant input ($i_c$ in figure \\ref{figure:lstm_cell}) and an output gate $o_c$ which protects other units from possibly irrelevant content in the respective unit \\cite[p. 6]{Hochreiter1997}.\nBoth, the \\ac{RNN} as well as the \\ac{LSTM}, have forms that also process the input sequence in the reverse order; the \\ac{LSTM} is then called \\ac{BLSTM}.\n\nIn this research the \\ac{LSTM} implementation from Keras was used.\nAlthough different network architectures were used, the general implementation with all used layer types is shown in listing \\ref{py:lstm_implementation}.\n\\lstinputlisting[language=Python,caption={Implementation of a \\acs{LSTM} in Keras.},label={py:lstm_implementation}]{listings/lstm.py}\nThe \\texttt{LSTM} layers in listing \\ref{py:lstm_implementation} consist of the just introduced \\ac{LSTM} cells.\nWith the \\texttt{return\\_sequences} parameter the hidden states of all \\ac{LSTM} cells on the respective layer can be used and the \\texttt{go\\_backwards} parameter reverses the order in which the sequential data is processed\\footnote{\\url{https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/LSTM}}.\n\\texttt{Bidirectional} is a wrapper for a forward processing \\ac{LSTM} layer and a backward processing \\ac{LSTM} layer to create a \\ac{BLSTM}\\footnote{\\url{https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/Bidirectional}}.\nWith the \\texttt{GlobalAveragePooling1D} layer the hidden states from the previous \\ac{BLSTM} layer are averaged across the timesteps\\footnote{\\url{https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/GlobalAveragePooling1D}}.\nThe \\texttt{Dense} layer then is a layer with the regular feed forward units described at the beginning of this section \\footnote{\\url{https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/layers/Dense}}.\n\nA key aspect is the usage of \\texttt{None} in the first dimension of the \\texttt{input\\_shape} on line 11 in listing \\ref{py:lstm_implementation}.\nThis dimension defines the number of time steps each input sample has.\nSince each report has a different length, this value was set to \\texttt{None}.\nEven though the \\ac{LSTM} can handle input with a different number of time steps, on batch level it still requires the input to have a fixed number of time steps.\nTherefore the reports need to be grouped by their lengths, which was accomplished with the \\texttt{ReportSequence} class (Listing \\ref{py:lstm_report_sequence}).\n\\lstinputlisting[language=Python,caption={The \\texttt{ReportSequence} class creates batches with reports of same length.},label={py:lstm_report_sequence}]{listings/report_sequence.py}\nThis grouping is then used by calling the \\texttt{fit\\_generator} method on the model with an instance of the \\texttt{ReportSequence} class in listing \\ref{py:lstm_implementation} on line 26.\nSimilar to the previously described classifiers, a 5 fold cross-validation was used to select the best model architecture.\n\nNow that the classification algorithms are introduced, one problem still remains:\nThe classifiers require the input to be a numerical vector.\nTherefore the reports have to be converted to feature vectors.\nThis embedding step is described in the next section.\n\n\n\\section{Creating document embeddings}\n\\label{sec:creating_document_embeddings}\n\\subsection{Methods to create a document representation}\n\\label{subsec:methods_for_document_representation}\nThe task of the embedding step is to map a text of variable length to a vector of fixed length, which is necessary to train a classification algorithm.\nThe most basic approach for creating a text representation is the bag-of-words model.\nFor that, a vocabulary is created which contains each word of a text corpus.\nEach word in this vocabulary is represented by a vector with the dimensionality of the vocabulary size, having a $1$ on the entry at which the word is stored in the vocabulary and zeros on all other positions.\nTo create the representation of a document, the vectors of the words in the document are summed \\cite[p. 13]{Grzegorczyk2018}.\nSince a single document typically does not contain all words of the vocabulary this vector is sparse and an inefficient representation of the text.\nThis method also does not take into account that some words occur more frequently than others, which can be solved by mutiplying the term frequency with the inverse document frequency.\nThe resulting metric is called \\textit{TF-IDF}:\n\\begin{equation}\n    TF-IDF(t,d) = f_{t,d} \\cdot log \\frac{N}{n(t)}\n    \\label{equation:tf_idf}\n\\end{equation}\nWhere $f_{t,d}$ is the number of occurences of a term $t$ in a document $d$, $N$ the total number of documents and $n(t)$ the number of documents that contain the term $t$ \\cite[p. 13]{Grzegorczyk2018}.\n\nAnother drawback of the word vectors in the bag-of-words model is, that it is not possible to determine similarity between different words.\nSince they are all orthogonal to each other, \"powerful\", \"strong\" and \"Paris\" share the same similarity with each other \\cite[p. 1]{Mikolov2014}.\nThis problem can be solved by using distributed vector representations, which can be created with the popular \\textit{Word2Vec} implementation.\nWord2Vec is a simple neural network with one hidden layer \\cite[p. 22]{Grzegorczyk2018}.\nIt offers two algorithms to learn the word representations.\nWith the \\ac{CBOW} algorithm the network predicts a word based on its surrounding words and with the \\textit{skip-gram} algorithm the network tries to predict context words based on a center word \\cite[pp. 4-5]{Mikolov2013}.\nThe word embeddings are then a result of maximizing the probabilities of these predictions \\cite[p. 23]{Grzegorczyk2018}.\nA simple approach for creating a document representation of these word embeddings would be to average all word vectors of the document.\nSimilar to the bag-of-words model with the term frequencies, this approach also does not respect the order of the words.\nAn extension to Word2Vec that creates a document representation is the \\textit{Paragraph Vector} model \\cite[p. 1]{Mikolov2014}, which is better known as the implementation \\textit{Doc2Vec}.\nFor this model an additional paragraph representation is trained in parallel to the word representations \\cite[p. 3]{Mikolov2014}.\nThe paragraph vector is incorporated in all word prediction contexts, therefore it captures the meaning of the whole document \\cite[p. 3]{Mikolov2014}.\n\nAt the time of publication, \\textit{Paragraph Vector} created state-of-the-art results in different sentiment tasks \\cite[pp. 4-7]{Mikolov2014}, this thesis however, will use the modern language representation model \\ac{BERT} to create the document embeddings.\nIn comparison to \\textit{Paragraph Vector}, \\ac{BERT} can use distant context words to the same extend as close words to create an embedding, whereas for the \\textit{Paragraph Vector} model, distant words contribute less to the embedding of a center word \\cite[p. 4]{Mikolov2013}.\nThe ability to incorporate these long range relations is a result of the Transformer architecture, which was proposed in \\cite{Vaswani2017} and is the basis of \\ac{BERT}.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{figures/transformer_architecture.png}\n    \\caption{The Transformer architecture as proposed in \\cite[p. 3]{Vaswani2017}.}\n    \\label{figure:transformer_architecture}\n\\end{figure}\nFrom the pure application area, Transformer is really similar to \\acp{RNN} or \\acp{LSTM}, as it is also optimised for handling sequential data.\nIt uses an encoder-decoder structure with a self-attention mechanism.\nThe encoder maps an input sequence to a vector representation, which the decoder uses to create an output sequence.\nThis can be used for example for translation tasks, where a sentence from the original language is passed to the encoder and the decoder returns the translated sentence \\cite[p. 392]{Goodfellow2016}.\nTraditional encoder-decoder models use \\acp{RNN} or \\acp{LSTM} for the encoder and decoder, with the vector representation being the final hidden state of the encoder \\cite[p. 392]{Goodfellow2016}.\nEnhancing these models with Attention, the hidden states of all encoder units can be used, with the focus on the most relevant states.\nThe Transformer architecture now relies purely on Attention and the sequential information is manually encoded in the data, which is labeled as \\textit{Positional Encoding} in figure \\ref{figure:transformer_architecture}.\nAttention is accomplished by computing a weighted sum of the hidden states.\nThe weights are given by the similarity between the hidden states of the encoder, which are called the \\textit{keys} and the most recent hidden state of the decoder, called the \\textit{queries}.\nBoth, the \\textit{keys} and the \\textit{queries}, are matrices and the similarity between them is calculated as a multiplication, on which a softmax function is applied afterwards \\cite[p. 4]{Vaswani2017}.\nBetween these weights and the \\textit{values}, which are the hidden states of the encoder as well, another matrix multiplication is calculated, giving the weighted sum.\nIn the Transformer model, this Attention mechanism is combined to a \\textit{multi-head attention}.\nThe multi-head attention consists of multiple attention layers, each performing the attention on different linear projections of the query, key and value inputs and concatenating the results in the end \\cite[pp. 4-5]{Vaswani2017}.\nThe advantage of the Transformer model is a high parallelization of the computation and the already mentioned capability to capture long range relations \\cite[p. 2]{Vaswani2017}.\nFor \\ac{BERT} the Transformer blocks depicted in figure \\ref{figure:transformer_architecture} are stacked in multiple layers, with 12 layers in case of BERT\\textsubscript{BASE} and 24 layers in case of BERT\\textsubscript{LARGE} \\cite[p. 3]{Devlin2018}.\nBecause of resource limitations, the BERT\\textsubscript{BASE} model is used in this research.\n\nAnother important property of \\ac{BERT} that can't be ignored, is that it can only process input text with a maximum sequence length of 512 tokens.\n\\textit{Tokens} are the entries in the vocabulary of \\ac{BERT}.\nBefore \\ac{BERT} can process the input text, it has to be tokenized.\nIn this step, each word from the input sequence is replaced with the longest token in the \\ac{BERT} vocabulary, that matches the word.\nIf no token matches the word exactly, the word is split in multiple tokens.\nFor example, the word \\textit{discounted} is not in the vocab and the tokenizer therefore splits the word into the sub tokens \\textit{discount} and \\textit{\\#\\#ed}.\nThe restriction to a maximum sequence length of 512 tokens implies, that it is not possible to pass a whole business report to \\ac{BERT}.\nThe segmentation into sentences with spaCy, that was described in section \\ref{sec:data_preprocessing}, is part of solving this problem, however in some cases the resulting sentences are way shorter than the sequence length of 512 tokens.\nTherefore the sentences are again concatenated until the maximum sequence length is reached.\nFor most applications working with \\ac{BERT} involves two steps, a pre-training and a fine-tuning step.\nSince \\ac{BERT} is used to create the text embeddings, an additional feature extracting step was added which is described in section \\ref{subsec:extracting_feature_vectors}.\n\n\\subsection{Pre-training}\nIn the \\textit{pre-training} step, \\ac{BERT} learns the general language structure which includes the positions of different words within a sentence and the relationship between successive sentences.\nSince BERT is a language model with a deep architecture, bidirectional training of the word positions is not possible, because the network can trivially predict the target word \\cite[p. 4]{Devlin2018}. %(<- Elaborate on here)\nTherefore \\cite{Devlin2018} decided to randomly mask out a number of words in the sentence and then predict the masked words.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=1.0\\textwidth]{figures/illustration_masked_lm.png}\n    \\caption{Illustration of the \\textit{masked language model} pre-training task.}\n    \\label{figure:masked_lm}\n\\end{figure}\nThe masking of the words is also done by the already introduced tokenizer.\nFor representing the masked words, the special token \\texttt{[MASK]} is used.\nAnother special token is the \\texttt{[CLS]} token, which is prepended to each input sequence and holds the meaning of this sequence after the \\textit{fine-tuning} procedure \\cite[p. 4]{Devlin2018}.\nThe whole task of predicting masked words based on their contexts is called \\textit{masked language model} \\cite[p. 4]{Devlin2018}.\nThe second task during pre-training is the binary \\textit{next sentence prediction}.\nFor that, \\ac{BERT} has to predict whether a sentence \\textit{B} is the actual successive sentence to a sentence \\textit{A} or whether it s a randomly chosen sentence from the training corpus.\n\nBecause \\ac{BERT} is using Tensorflow as a backend, it expects the input data to be in the TFRecord file format.\nTFRecord is a binary file format, which contains the tokenized text and the tokens that are masked.\nBecause the creation of each TFRecord file takes a few seconds, the dataset is again split to optimise the processing with multiple cores, as it can be seen in Listing \\ref{py:split_data_and_spawn_processes}.\n\\lstinputlisting[language=Python,caption={The dataset is split to optimise the TFRecord creation on multicore systems.},label={py:split_data_and_spawn_processes}]{listings/split_data_and_spawn_processes.py}\nThe \\texttt{\\_handlePretrainingDataCreation()} function, which is provided as as a callback to the \\texttt{Process}, is mostly similar to the \\texttt{main()} function of \\texttt{create\\_pretraining\\_data.py} from the official \\ac{BERT} repository\\footnote{The official \\ac{BERT} repository on GitHub: \\url{https://github.com/google-research/bert}}.\nIt was modified, so it creates the TFRecord files for multiple input files at once.\n\nThe actual training of \\ac{BERT} was done with the script in listing \\ref{py:run_pretraining}.\n\\lstinputlisting[language=Python,caption={\\ac{BERT} pre-training.},label={py:run_pretraining}]{listings/run_pretraining.py}\nAgain most of the source code is similar to the \\texttt{main()} function of \\texttt{run\\_pretraining.py} from the official \\ac{BERT} repository.\nOne change that was made, was to set the number of checkpoints, that are created during training, to 30 as opposed to 5 as default.\nThese checkpoints were later used to evaluate the model.\nThe validation step was also moved to a seperate script to evaluate the model for every training checkpoint.\nThis is accomplished by iterating over the created checkpoints and calling the evaluation code from \\ac{BERT} for each of them.\nIn the original source code only the final model was evaluated.\nThe results are appended to a Pandas DataFrame, which is saved as a \\ac{CSV} file in the end.\n\n\\subsection{Fine-Tuning}\n\\label{subsec:fine_tuning}\nThe \\textit{fine-tuning} step is used to optimise \\ac{BERT} for a specific task.\nThis can be a task like question answering or sentence classification \\cite[pp. 5-7]{Devlin2018}.\nEven though the final goal is to classify the business reports and not every sentence on its own, the fine-tuning is essential so that the \\texttt{[CLS]} token holds a good representation of the sentence\\footnote{This hint was mentioned in \\texttt{extract\\_features.py} on lines 237-239 \\url{https://github.com/google-research/bert/blob/fe354751d7de010f60d362ae8d9343849ec39456/extract_features.py}}.\nSince the final aim is to classify each business report, the most similar task was selected for fine-tuning, which is the sentence classification.\nIn difference to the pre-training, the sequences for fine-tuning need a label.\nSince each input sequence to \\ac{BERT} is a part of a larger report, the sequences \"inherit\" their label from this report.\nTherefore every sentence of a \\textit{positive} report is also labeled \\textit{positive} and every sentence of a \\textit{negative} report is also labeled as \\textit{negative}.\nOf course this approach seems wrong on the first glance, since a positive report can also contain negative sentences and vice versa.\nHowever one could also re-interpret the classification task as follows:\nInstead of saying that the label indicates whether a sentence is a \\textit{positive} or \\textit{negative} sentence, it can also be interpreted as indicating whether the sentence belongs to a \\textit{positive} or \\textit{negative} report.\nThe experimental results in section \\ref{sec:fine_tuning_results} show how this approach affects fine-tuning.\n\nAs opposed to the pre-training, the creation of the TFRecord files was part of the training script for fine-tuning.\nTherefore every training run was delayed, because the TFRecord files were generated first.\nThe call to the \\texttt{file\\_based\\_convert\\_examples\\_to\\_features} function, which creates the TFRecord files was therefore moved to another script (Listing \\ref{py:convert_to_tfrecord}).\n\\lstinputlisting[language=Python,caption={Creates the TFRecord files for fine-tuning.},label={py:convert_to_tfrecord}]{listings/convert_to_tfrecord.py}\nThis allows to train the model without waiting for the creation of the TFRecord files.\nSimilar to the changes made for pre-training, the number of checkpoints to save was also increased and the validation of the model was moved to a second script.\n\n\\subsection{Extracting feature vectors}\n\\label{subsec:extracting_feature_vectors}\nAfter the fine-tuning is accomplished, the \\texttt{[CLS]} token at the start of each sequence holds information about the class of the sequence.\nThis information can be retrieved by accessing the hidden states of the Transformer blocks in the last layer of the model.\nListing \\ref{py:extract_features} shows a snippet of the \\texttt{extract\\_features.py} script.\n\\lstinputlisting[language=Python,caption={Accesses the hidden states from the transformer layers.},label={py:extract_features}]{listings/extract_features.py}\nThe official implementation allows to access the hidden states from all layers of the model, however for this thesis only the last layer is used.\nFor that, the \\texttt{layer\\_indexes} variable which is passed to the \\texttt{model\\_fn\\_builder} is set to -1.\nTherefore, the hidden states of this layer can be accessed by \\texttt{result[\"layer\\_output\\_0\"]} on line 21.\nIn theory, the \\texttt{result} dictionary also includes \\texttt{layer\\_output\\_1, layer\\_output\\_2, ...}, but the \\texttt{layer\\_indexes} limits the results.\nIn the list comprehension on line 23 \\texttt{layer\\_output[0]} only the hidden states for the first token, the \\texttt{[CLS]} token, is accessed.\nThe \\texttt{for} loop is necessary because the \\texttt{predict} method returns an iterator, where each element represents the hidden states for one line of the input file.\nAs a summary it can be said, that this implementation only takes the hidden states from the last layer for the first token, while the official implementation takes the hidden states for all tokens from possibly all layers.\n\nBecause of the limitation of \\ac{BERT} that it can only process sequences with a maximum length of 512 tokens, many embedding vectors result for each report.\nFor the \\ac{BLSTM} the single sequence embeddings give the timesteps for each sample.\nThe Naive Bayes, \\ac{KNN} and \\ac{SVM} however, need a single vector representation for each report, therefore the sequence embeddings are averaged per report.\n\n\\section{Other used techniques}\n\\subsection{Cross-Validation}\n\\label{subsec:cross_validation}\nCross-validation is a method to estimate the prediction accuracy of a model for a unknown dataset \\cite[p. 241]{Hastie2009}.\nFor that a training dataset is split in $K$ equally sized parts.\n$K-1$ of these parts are then used to train the model and the $k$th part is used to evaluate the model.\nThis is repeated for $k=1,2,...,K$ and the resulting accuracies are averaged \\cite[p. 242]{Hastie2009}.\nThe averaged accuracy is used to optimise the model:\nThe hyperparameters of the model are changed so that the averaged accuracy is maximised \\cite[p. 242]{Hastie2009}.\nOne drawback of the method is that the time to train and evaluate the model increases with a larger $K$ \\cite[p. 242]{Hastie2009}.\n\nFor this research 5-fold cross-validation was used for the Naive Bayes, \\ac{KNN}, \\ac{SVM} and the \\ac{BLSTM}.\nThe cross-validation dataset covered 80\\% of the whole dataset, therefore for the test dataset remained 20\\% of the data.\nBoth datasets were balanced so that they include the same number of positive and negative reports.\nThe hyperparameters for the \\ac{BERT} pre-training and fine-tuning were determined without cross-validation, because \\ac{BERT} itself is quite computational expensive.\nSince for \\ac{BERT} no cross-validation was used the training dataset covered 60\\%, the validation and test dataset both covered 20\\% of the data.\nAgain all datasets were balanced.\n\n\\subsection{Learning and validation curve}\n\\label{subsec:learning_validation_curve}\nThis thesis uses learning curves to visualise the learning progress of the machine learning models.\nA learning curve is a line chart that shows the accuracy of a machine learning model depending on a second variable, like the training dataset size or the number of epochs a neural network trained \\cite[pp. 702-703]{Russel2016}.\nIt can give evidence about whether the model would improve its performance if more data was available or the number of epochs was increased.\nFigure \\ref{figure:sample_learning_curve} shows a possible learning curve.\nIn this thesis, the accuracies of the Naive Bayes, \\ac{KNN} and \\ac{SVM} are indicated depending on the size of the training dataset and for the \\ac{BLSTM} the accuracies are indicated depending on the number of epochs.\nFor \\ac{BERT} the horizontal axis shows the number of training steps, which is a comparable measurement with the number of epochs (Chapter \\ref{ch:experiments}).\n\nValidation curves are used to find the best hyperparameters of a model.\nThey show the accuracy of the model depending on different values of this hyperparameter, that can be for example the number of $K$ in the case of the \\ac{KNN} or the value of $C$ for a linear \\ac{SVM}.\nThe best value is then selected by choosing the model that reached the highest validation accuracy \\cite[p. 711]{Russel2016}.\nFigure \\ref{figure:sample_validation_curve} shows a possible validation curve for a \\ac{KNN} classifier, \n\nIn this thesis both of the curves are created in combination with cross-validation.\n\\begin{figure}[h]\n    % \\begin{subfigure}{0.5\\textwidth}\n    %     \\includegraphics[width=\\textwidth]{figures/knn_sample_learning_curve.png}\n    %     \\caption{The learning curve shows the accuracy depending on the training dataset size.}\n    %     \\label{figure:sample_learning_curve}\n    % \\end{subfigure}\n    % \\begin{subfigure}{0.5\\textwidth}\n    %     \\includegraphics[width=\\textwidth]{figures/knn_sample_validation_curve.png}\n    %     \\caption{The validation curve shows how a change in the value of a hyperparameter affects the accuracy of the model.}\n    %     \\label{figure:sample_validation_curve}\n    % \\end{subfigure}\n    \\subcaptionbox{The learning curve shows the accuracy depending on the training dataset size.\\label{figure:sample_learning_curve}}[0.5\\linewidth]{\\includegraphics[width=0.5\\textwidth]{figures/knn_sample_learning_curve.png}}\n    \\subcaptionbox{The validation curve shows how a change in the value of a hyperparameter affects the accuracy of the model.\\label{figure:sample_validation_curve}}[0.5\\linewidth]{\\includegraphics[width=0.5\\textwidth]{figures/knn_sample_validation_curve.png}}\n    \\caption{Sample learning and validation curves of a \\ac{KNN} classifier.}\n    \\label{figure:sample_learning_validation_curves}\n\\end{figure}\n\n\n\\FloatBarrier\n\\subsection{\\acl{PCA}}\n\\acl{PCA} is a method to reduce the dimensionality of a dataset with loosing as little information as possible.\nIn this thesis \\ac{PCA} is used to obtain a two dimensional representation of the data, which can then be visualised.\nMathematically the \\ac{PCA} can be seen as the projection of a data matrix $X$ to a target matrix $Y$ with other basis vectors (equation \\ref{equation:pca_projection}) \\cite[p. 3]{Shlens2014}.\n\\begin{equation}\n    Y=PX\n    \\label{equation:pca_projection}\n\\end{equation}\nFor the application of this thesis $X$ is a $m\\times n$ matrix where each column contains the hidden states for the business report.\n$Y$ is a $m\\times n$ matrix as well, with the special property, that the rows are sorted by their variances, with the highest variance in the first row \\cite[p. 5]{Shlens2014}.\nTo accomplish this, the covariance matrix $C_X$ of $X$ is computed.\nIf the row entries of $X$ have a zero mean, the covariance matrix is given by $C_X=\\frac{1}{n}XX^T$ \\cite[p. 5]{Shlens2014}.\nIf the mean is not zero, each value has to be subtracted by the corresponding row mean first.\nThen the eigenvectors of $C_X$ are computed, which form the rows of the projection matrix $P$ \\cite[p. 6]{Shlens2014}.\nAnother way of solving the \\ac{PCA} is to use singular value decomposition, this is described in detail in \\cite[p. 7]{Shlens2014}.\n\n\n% This is done by fitting a hyperplane with dimension $q \\leq p$ into the featurespace with dimension $p$ that minimises the squared error to the data points.\n% For practical usage the dimension $q$ of the hyperplane is typically 2 or 3.\n% For $q=2$, the hyperplane is a twodimensional plane on which the values are projected and can then be visualised.", "meta": {"hexsha": "238f1d4b0d54e8601398feeb24d6781fe05904a6", "size": 42162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/3_method.tex", "max_stars_repo_name": "FrederikBoehm/Bachelorarbeit_Text", "max_stars_repo_head_hexsha": "caae96d4262101baf057aa1480288df27f6e9791", "max_stars_repo_licenses": ["MIT"], "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/3_method.tex", "max_issues_repo_name": "FrederikBoehm/Bachelorarbeit_Text", "max_issues_repo_head_hexsha": "caae96d4262101baf057aa1480288df27f6e9791", "max_issues_repo_licenses": ["MIT"], "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/3_method.tex", "max_forks_repo_name": "FrederikBoehm/Bachelorarbeit_Text", "max_forks_repo_head_hexsha": "caae96d4262101baf057aa1480288df27f6e9791", "max_forks_repo_licenses": ["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.2602739726, "max_line_length": 400, "alphanum_fraction": 0.7844741711, "num_tokens": 10410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.6290450388711859}}
{"text": "\\documentclass[letterpaper]{article}\n\\title{\\textbf{Tokio university's entrance exam 2016}}\n\\author{Acosta Domínguez Jorge}\n\\date{}\n\n\\usepackage{amsmath}\n\\usepackage{tabto}\n\\usepackage{tasks}\n\\usepackage{geometry} %this reduces the amount of margin\n\\newcommand{\\itab}[0]{\\hspace{2em}}\n\n\\begin{document}\n\\pagenumbering{gobble}\n\\maketitle\n\\newpage\n\\pagenumbering{arabic}\n\n\\section{Mathmatics exam}\n\\subsection{Lineal algebra}\nThe tribonacci numbers ${T_n}$ are defined for non-negative integers n as follows.\n\\begin{displaymath}\n\\begin{cases}\nT_0 &= T_1 = 0\\\\\nT_2 &= 1\\\\\nT_{n+3} &= T_{n+2} + T_{n+1} + T_{n} \\itab(n\\geq 0)\n\\end{cases}\n\\end{displaymath}\nAnswer the following questions.\n\\begin{tasks}\n\\task{\nFind the matrix $A$ that satisfies Eq. (1) for all non-negative integers $n$.\n\\begin{equation}\n\\left(\\begin{matrix}\nT_{n+3}\\\\\nT_{n+2}\\\\\nT_{n+1}\n\\end{matrix}\\right)\n=A\n\\left(\\begin{matrix}\nT_{n+2}\\\\\nT_{n+1}\\\\\nT_{n}\n\\end{matrix}\\right)\n\\end{equation}\n}\n\\end{tasks}\n\\newpage\n\\subsubsection{Resolution}\n\\begin{tasks}\n\\task{\nThe resolution for this exercise would be the below matrix $A$, since it accomplishes the equation:\n\\begin{displaymath}\nA = \\left(\\begin{matrix}\n1 & 1 & 1\\\\\n1 & 0 & 0\\\\\n0 & 0 & 0\n\\end{matrix}\\right)\n\\end{displaymath}\nBecause resolving $1$ we have:\n\\begin{displaymath}\n\\left(\\begin{matrix}\nT_{n+3}\\\\\nT_{n+2}\\\\\nT_{n+1}\n\\end{matrix}\\right) = \n\\left(\\begin{matrix}\nT_{n+2} + T_{n+1} + T_{n}\\\\\nT_{n+2}\\\\\n0\n\\end{matrix}\\right)\n\\end{displaymath}\n}\n\\end{tasks}\n\\end{document}", "meta": {"hexsha": "4ec0737f79ce39f03597f9e7adfdaa07c8214a81", "size": 1491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Math/nyuugakushiken2016.tex", "max_stars_repo_name": "syaoraang/shiken_junbi", "max_stars_repo_head_hexsha": "ee99cee25f0263f3eb91a661241413cc582ec34d", "max_stars_repo_licenses": ["MIT"], "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/nyuugakushiken2016.tex", "max_issues_repo_name": "syaoraang/shiken_junbi", "max_issues_repo_head_hexsha": "ee99cee25f0263f3eb91a661241413cc582ec34d", "max_issues_repo_licenses": ["MIT"], "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/nyuugakushiken2016.tex", "max_forks_repo_name": "syaoraang/shiken_junbi", "max_forks_repo_head_hexsha": "ee99cee25f0263f3eb91a661241413cc582ec34d", "max_forks_repo_licenses": ["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.1486486486, "max_line_length": 99, "alphanum_fraction": 0.6988598256, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.62903397420272}}
{"text": "%\n% 235\n%\n\\chapter{The Gamma Function}\n\n\\Section{12}{1}{Definitions of the Gamma- function. The Weierstrassian product.}\n\nHistorically, the Gamma-function* V z) was first defined by Euler as\nthe limit of a product \\hardsubsectionref{12}{1}{1}) from which can be derived the\ninfinite integral\n\n1 i ~ e~ dt; but in developing the theory of the function, it is more\ncon- Jo\n\nvenient to define it by means of an infinite product of Weierstrass'\ncanonical\n\nform.\n\nConsider the product ze fl -I ( 1 -H -\n\ne\n\nwhere 7= lim ]-+--f-...-l- log ?/i[ =0-5772157....\n\n[The constant y is known as Euler's or Mascheroni's constant; to\nprove that it exists we observe tliat, if\n\nu = I -. .a<= - log - -,\n\n[ dt \\ \"\n\nu IS positive and less than / -, = -,; therefore 2 w converges, and Jo\nn 'i n=l\n\n,. n 1 1, 1,. ( \"', m + l\\ *\n\nhm J- + -+...+ logwl= hm < 2 ?< + log \\= 2 .\n\nThe value of y has been calculated by J. C. Adams to 260 places of\ndecimals.]\n\nThe product under consideration represents an analytic function of z,\nfor\n\nall values of z; for, if N be an integer such that \\ z\\ \\ iV, we\nhavef, if n > N,\n\n1 2- 1 Z'\n\n1\n\n2n'-' Sn' '\"\n\n\n\nz z z n- 1 n n-\n\n-\n\nIN \\ \\ 1 1 1 1 '\n\n 4 r' 2 + 2' +---) 2 n '\n\n00\n\nSince the series 2 [N' l 2n?)] converges, it follows that, when \\ z\\ \\\nN,\n\nn = N+l\n\n* The notation V (z) was introduced by Legendre iu 1814. t Taking the\nprincipal value of log (1 + z/?().\n\n%\n% 236\n%\n\nS ]log(l + - is an absolutely and uniformly convergent series\n\nof analytic functions, and so it is an analytic function \\hardsectionref{5}{3});\ncon- sequently its exponential 11 ( l+-]e~nl is an analytic function,\nand\n\nso zey n ! ( 1 + - J e ~ [ is an analytic function when \\ z\\ \\ N,\nwhere N is any integer; that is to say, the product is analytic for\nall finite values of z. The Gamma-function was defined by Weierstrass*\nby the equation\n\n,= -T- = zey U ( l+-]e ~n[-\n\nfrom this equation it is apparent that T (z) is analytic except at the\npoints z=0, - 1, - 2, . . ., where it has simple poles.\n\nProofs have been published by Holder t, Moore J, and Bai-nes§ of a\ntheorem known to Weierstrass that the Gamma-function does not satisfy\nany differential equation with rational coefficients.\n\nExample 1. Prove that\n\nr(i) = i, r'(i)=-y,\n\nwhere y is Euler's constant.\n\n[Justify differentiating logarithmically the equation\n\n~ = zey''n ( l+ -)e~ri\\ Viz) 1 IV nJ I\n\nby \\hardsectionref{4}{7}, and put z = l after the differentiations have been\nperformed.]\n\nExample 2. Shew that\n\n,11 1 P 1\n\n2 3 n Jo\n\nt and hence that Euler's constant y is given by||\n\n-(1-\"\"*,\n\nlim\n\n[/: '-04)\" ?-/:(-r.)\"T']'\n\nExample 3. Shew that\n\ne> r(g + l)\n\nT z-x + ) '\n\nn = \\ \\ \\ Z + n) J\n\n* Journal filr Math. li. (1856). This formula for F(z) had been\nobtained from Euler's formula \\hardsubsectionref{12}{1}{1}) in 1848 by F. W. Newman,\nCambridge and Dublin Math. Journal, iii. (1848), p. 60. t Math. Ann.\nsxvm. (1887), pp. 1-13. + Math. Ann. xlviii. (1897), pp. 70-74. §\nMessenger of Math. xxix. (1900), pp. 122-128. li The reader will see\nlater \\hardsectionref{12}{2} example 4) that this limit may be written\n\n%\n% 237\n%\n\n\n\\Subsection{12}{1}{1}{Euler's TODO formula for the Gamma-function.}\n\nBy the definition of an\ninfinite product we have\n\nTODO\n\nHence T (.) = - H j(l + -j (l +,;j | .\n\nThis formula is due to Euler*; it is valid except when = 0, - 1, - 2,\n....\n\nExample. Prove that\n\n,,,. 1.2...(n-l)\n\nr (2) = hm, .,. 7- - - . n\\\n\n\\addexamplecitation{Euler.}\n\nVlVl. The difference equation satisfied by the Gamma-function.\n\nWe shall now shew that the function F (z) satisfies the difference\nequation\n\nT z -l) = zT z). For, by Euler's formula, if z is not a negative\ninteger,\n\nFU + 1)/F(.) = -\n\nlim n\n\n;h -* X = 1\n\n(1 +\n\nV n\n\nly+r\n\n1 +\n\nz+ 1\n\n1 lim n ii\n\nm-*---c ? =1\n\n1 +\n\n1 J\n\n= - lim II,\n\n  + 1, -*x = 1 I + ?i +\n\n, . m + 1\n\n= z hm = z.\n\n i x 2: + Wi + 1\n\nThis is one of the most important properties of the Gamma-function.\nSince F (1) = 1, it follows that, if 2: is a positive integer, F (2 )\n= (2 - 1) !.\n\nIt was given in 1729 in a letter to Goldbacb, printed in Fuss'\nCorresp. Math.\n\n%\n% 238\n%\n\nExample. Prove that\n\n[Consider the expression\n\n111 1\n\nz z z- ) 2(s + l)(2 + 2) z z + l)... z+m)\n\nin d\n\nIt can be expressed in partial fractions in the form 2 -, where\n\n\\ (-) / \\ \\ 1 1 ]\\ (-)\" f °° 1\n\n\"=1 e \"'( -)\"!( =\" 11\n\nNoting that 2 -,<-, itt-t, prove that 2 - .- \\ 2 -;h- 0 as\n\nr=m-ri+\\ r\\ m-n + l)\\ n=o n\\ z + n [r=m-n+irl]\n\nm- <X) when z is not a negative integer.]\n\n\\Subsection{12}{1}{3}{The evaluation of a general class of infinite products.}\n\nBy means of the Gamma-function, it is possible to evaluate the general\nclass of infinite products of the form\n\nn Un,\n\n7t = l\n\nwhere Un is any rational function of the index n.\n\nFor, resolving m into its factors, we can Avrite the product in the\nform\n\n* f (n -a )(n-a2) ...(n- ak) ]\n\nn=i[ (n-b,).: n-bi) I'\n\nand it is supposed that no factor in the denominator vanishes.\n\nIn order that this product may converge, the number of factors in the\nnumerator must clearly be the same as the number of factors in the\ndenominator, and also A 1; for, otherwise, the general factor of the\nproduct would not tend to the value unity as n tends to infinity.\n\nWe have therefore k= I, and, denoting the product by P, we may \\ vrite\n\n =i ] n-b ) ... n-bk)i ' The general term in this product can be\nwritten\n\n(- (- )(-r-(-r\n\na + a + ... +ak-b,- ...-bk . = 1 - - h Jin\n\nn\n\nwhere 4 is (h~-) when n is large.\n\nIn order that the infinite product may be absolutely convergent, it is\ntherefore necessary further \\hardsectionref{2}{7}) that\n\ntti + . . . + Ojk - 1 -   - /fc = 0.\n\n%\n% 239\n%\n\nWe can therefore introduce the factor\n\nexp /i-i ( ! + ... +ak-b,- ... - hk)\n\ninto the general factor of the product, without altering its value;\nand thus we have\n\np= n\n\n(i\\ ), (i\\ )e\"...(i- *).\"\n\n\"=N (- )--(- )-\n\nBut it is obvious from the Weierstrassian definition of the Gamma-\nfunction that\n\n,\"|('\" )''\"]\"- r(- )e-T''\n\nand so P = r(- 6,)6,r(-6 (- .) TJ l-K) . a T -CH)...akV -ak), =\nir(l-a )\n\na formula which expresses the general infinite product P in terms of\nthe Gamma-function.\n\nExample 1. Prove that\n\n \" (a-i-6 + ) \\ r(a + l)r (6-1-1) s=i (a+ ) (6-l-s) T a + b + ) '\n\nExample 2. Shew that, if a = cos (27r/n) + i sin 27r jn\\ then\n\n/ \\ / \\ - -\n\n (i- j(i-|;)... = -r(-x )r(-aa- )...r(-a\"-i:r ) -'.\n\n\\Subsection{12}{1}{4}{Connexion between the Gamma-function and the circular functions.}\n\nWe now proceed to establish another most important property of the\nGamma-function, expressed by the equation\n\nr( )r(i-. )= .- .\n\nsm TTZ We have, by the definition of Weierstrass \\hardsectionref{12}{1}),\n\nr(.)r(-.)=-in (i+i)r rnj(i-i);\"\n\nZ Sin TTZ\n\nby \\hardsectionref{7}{5} example 1. Since, by \\hardsubsectionref{12}{1}{2},\n\nr(i-z) = -zr(-z)\n\nwe have the result stated.\n\n%\n% 240\n%\n\nCorollary 1. If we assign to z the value \\, this formula gives r( ) 2\n= 7r; since, by the formula of Weierstrass, r ( ) is positive, we\nhave\n\nCorollary \"l. If r/.(s) = r'(s)/r(2), then i/ (1 -z)-- /r (0) = 7r cot\ntts.\n\n\\Subsection{12}{1}{5}{The multiplication-theorem of Gauss* and Legendre.}\nWe shall next obtain the result\n\nr(.)r(. + )r(. + )...r(. + 'i ) = (2.)n -. - -rM.\n\nn) \\ n For let ( (.) = iT;; \\ .\n\nThen we have, by Euler's formnla \\hardsubsectionref{12}{1}{1} example),\n\n - 1 .2...(m- l).m - /'*\n\nn'\"- n lim\n\n (Z)\n\n,. 1 . 2 ... (m - 1) . (nm)'*\n\nn lim\n\n\\ im - 1)! m\n\nnz (nz + 1 ) . . . (71Z + n7n - 1)\n\n n'ln - 1) ! nm)'\" i(m- 1) !j wi\" 'n\n\nm oo (wm-1)!\n\nIt is evident from this last equation that <p (z) is independent of z.\nThus (j) (z) is equal to the value which it has when z = -; and so\n\nTherefore < (z)Y = n| | T ( -) T (l -;:)|\n\ntt' -i (27r)\"-\n\n. TT . 27r . (?i- l)7r\n\nsm - sm - ... sm\n\nn n n\n\nThus, since cj) (n~ ) is positive,\n\n<,W = (2,r)4<\"-'' -*,\n\ni.e. r (.) r (. + ) . . . r (. + '-i i) = - (2,r)4 < - '> r ( .).\n\nCorollary. Taking n = 2, we have\n\n2 -ir(.)r( +i)=,r4r(24\n\nThis is called the duplication formula.\n\n* Werke, iii. p. 149. The case in which n - 2 was given by Legendre.\n\n%\n% 241\n%\n\nExample. If (, o) = EMlM\n\nshew that\n\nD(p,,)b p + \\ q)...B(p ',q) B (np, no) = a ~ i \\ n /\n\n\\Subsection{12}{1}{6}{Expansions for the logarithmic derivates of the Gamma-function.}\n\nWe have r (2+l) -J = '>' n /(\"l + -\") e~ ]- .\n\nDifiFerentiating logarithmically \\hardsectionref{4}{7}), this gives\n\nl gJ iiiLi)= \\ + !\\ + --,,\n\nrfs ''' 1 (2 + 1) '*\"2(2 + 2) \" 3(2 + 3) \"\"\n\nTherefore, since log r (s + 1 ) = log 2 + r (2), we have\n\nIogr(2)=-y--.+ 2 2\n\ndz ° ' z n=in(2 + n)'\n\nd-. \\,,. (f\n\nDifferentiating again,,logr(.+ l) = + 2 (2 + 2) + -\n\n1 1\n\n (2+l>' (2 + 2)2 \"\"\n\nThese expansions are occasionally used in ai)plications of the theory.\n\\Section{12}{2}{Elder s expression of T z) as an injinite integral.}\n\nThe infinite integral I e~H ~ dt represents an analytic function of z\nwhen*\n\nJo\n\nthe real part of z is positive \\hardsubsectionref{5}{3}{2}); it is called the Eulerian\nIntegral of the Second Kindf. It will now be shewn that, when li z)>0,\nthe integral is equal to F (z). Denoting the real part of z by x, we\nhave x > 0. Now, if J\n\nn(z,n)=j'Ul-yJ\\'- dt,\n\nwe have U (z, n) = n l (1 - TyW-'hlr,\n\nJ )\n\nif we write t= nr; it is easily shewn by repeated integrations by\nparts that, when a; > and n is a positive integer,\n\nf n 1 n; !\n\n 1 - t)\"t - dr = - T- (1 - Tf + - (I - Tf-'T'dr Jo \\ J Jo S'.\n\nn(n-l)...l fi,\n\nz(5 + l)...( + n-l)Jo '* '\n\nJ n / \\ 1 . 2 . . . ?i\n\nand so 11 (2, n) = -. - n\n\nz z ) ... z -n)\n\nHence, by the example of \\hardsubsectionref{12}{1}{1}, 11 z, n) r( ) as /i -* x .\n\n* If the real part of z is not positive the integral does not converge\non account of the singu- larity of the integrand at f = 0.\n\nt The name was given by Legendre; see \\hardsectionref{12}{4} for the Eulerian\nIntegral of the First Kind.\n\nt The many-valued function < ~i is made precise by the equation *~i =\nc(*-i)'°s', log r being purely real.\n\nW. M. A. 16'\n\n%\n% 242\n%\n\nConsequently F ( ) = lim (1 ) t-~ dt.\n\nAnd so, if T, (2) = I e-H'-'dt,\n\nJ (\\ we have\n\nri( )-r( )= lim r ie-'-(l- y\\ t'-'dt+j e-H'-'dt .\n\nNow lim I e'U'-'dt = 0,\n\nsince I e~H ~ dt converges.\n\n.'0\n\nTo shew that zero is the limit of the first of the two integrals in\nthe formula for Fj z) - F(z) we observe that\n\n[To establish these inequalities, we proceed as follows : when < y <\n1, from the series for e and (1 - 3/)\" Writing tjn for y, we have\n\n1 + - e-'\n\nn\n\nHJ-\n\nand so 0 e- -fl--\n\n71\n\n= e-Ml-eM 1\n\n<e-Ml- 1\n\n-1)1\n\nNow, if O-Sa l, (1 - a)\" l - na by induction when ?ia<l and obviously\nwhen 7ia 1; and, writing t /n for a, we get\n\nand so* 0 e-*-(l--) %e-H ln,\n\nwhich is the required result.]\n\nFrom the inequalities, it follows at once that\n\nr' - f 1 - - j ) t'-'dt ' I n-'e-ff'- 'dt\n\n<n-'j e-H' - 'dt O, Jo\n\nas n - X, since the last integral converges.\n\n* This analysis is a modification of that given by Schloinilch,\nCompendium der hoheren Analysis, ii. p. 243. A simple method of\nobtaining a less precise inequality (which is sufficient for the\nobject required) is given by Bromwich, Infinite Series, p. 459.\n\n%\n% 243\n%\n\nConsequently Fi 2)= V (z) when the integral, by which Tj (z) is\ndefined, converges; that is to say that, when the real part of z is\npositive,\n\nJ n And so, when the real part of z is positive, F (z) may be defined\neither by this integral or by the Weierstrassian product. Example 1,\nProve that, when R (z) is positive,\n\nExample 2. Prove that, if li z) > and R (s) > 0,\n\n/ e-\"=x -'cla.-= . Jo z\n\nExample 3. Prove that, if R z)>Q and R is) > 1,\n\nExample 4. From :; 12'1 example 2, by using the inequality\n\n0%e- -( X fie- ln,\n\ndeduce that\n\nl\\ e- \\ e-i/<\n\n-at.\n\n<\n\nt\n\n\\Subsection{12}{2}{1}{Extension of the infinite integral to the case\n  in which the argument of the Gamma-function is negative.}\n\nThe formula of the last article is ni> longer applicable when the real\npart of z is negative. Cauchy* and Saalschiitzt have shewn, however,\nthat, for negative arguments, an analogous theorem exists. This can be\nobtained in the following way.\n\nConsider the function\n\nr, z)=j\\'- (e-'-\\ + t-, + ... + -)>'- dt,\n\nwhere k is the integer so chosen that -k>x>-k-l, x being the real part\nof z. By partial integration we have, when s < - 1,\n\nr,(.)=[f(.-.-n.<-il + ...+(-r.,)];\n\n+.'j7''( -'-i+'--+(-''(j )*\n\nThe integrated part tends to zero at each limit, since x+k is negative\nand x + k + l is positive : so we have\n\nr, z) = lT, z+i).\n\nThe same proof applies when x lies between and -1, and leads to the\nresult\n\nr z+i)=zr2 z) (0>.r>-i).\n\nThe last equation shews that, between the values and -1 of a*,\n\nTo z) = r(z).\n\n* Exercices de Math. u. (1827), pp. 01-92.\n\nt Zeitschrift fur Math, und Phys. xxxii. (1887), xxxiii. (1888).\n\n16-2\n\n%\n% 244\n%\n\nThe preceding equation then shews that To z) is the same as T (2) for\nall negative values of Ji z) less than -1. Thus, for all negative\nvalues of R(z), we have the result of Cauchy and Saalschiitz\n\nwhere k is the integer next less than - B (z).\n\nExample. If a function P (ft) be such that for positive values of /x\nwe have\n\nJ\n\n- 1 -x\n\ne~'-' dx,\n\nand if for negative values of /x we define Pj (fi) by the equation\n\ndx.\n\nPi(;u)=|\\ i'--i(e- -l + .r-... + (-)*- + i,)\n\nwhere k is the integer next less than - ju, shew that\n\n/',W./'W-l + -... + (-)'--.-,. \\addexamplecitation{Saalschiitz.}\n\n\\Subsection{12}{2}{2}{Hankers expression of TODO as a contour integral.}\n\nThe integrals obtained for T z) in\n\\hardsectionref{12}{2}, \\hardsubsectionref{12}{2}{1} %TODO:cite multiple\nare members of a\nlarge class of definite integrals by which the Gamma-function can be\ndefined. The most general integral of the class in question is due to\nHankel*; this integral will now be investigated.\n\nLet D be a contour which starts from a point p on the real axis,\nencircles the origin once counter-clockwise and returns to p.\n\nConsider 1 (-t)~~ e~hlt, when the real part of z is positive and z is\nnot an integer.\n\nThe many-valued function (- ty~ is to be made definite by the\nconvention that (- ty~ = e' ~ ' ° '\"*' and log (- t) is purely real\nwhen t is on the negative part of the real axis, so that, on D, - ir %\narg (- t) % it.\n\nThe integrand is not analytic inside D, but, by \\hardsectionref{5}{2} corollary 1, the\npath of integration may be deformed (without affecting the value of\nthe integral) into the path of integration which starts from p,\nproceeds along the real axis to h, describes a circle of radius h\ncounter-clockwise round the origin and returns to p along the real\naxis.\n\nOn the real axis in the first part of this new path we have arg (- ) =\n- tt, so that - ty~' - e~ '' ~ H ~ (where log i is purely real); and\non the last part of the new path (- ty- = e \" ' - ' t ' .\n\nOn the circle we write - i = 8e*; then we get\n\nf -ty-'e-Ht-= \\ e-'-(--i) '-ie-'f? +f\"(8e' )--ie (cose+;sm< )gg,ej 7\n\n+ ''e' ' -' H'-' e' dt = - 2i sin -jTz) j t'-' e-hit + ih' I \" e<>e+\n(cose+tsine) \\\n\n* Zeitschrift filr Math, und Phys. ix. (1864), p. 7.\n\n%\n% 245\n%\n\nThis is true for all positive values of S p; now make S; then 8' and\nI gize+s (COS 0+isin e 0 j ize iQ [ \\ \\ q integrand tends to its limit\n\nJ - TT J -IT\n\nuniformly.\n\nWe consequently infer that\n\n[ (-ty-'e-'dt = -21 sin 7r2)[''t'-'e-*dt.\n\nJ B Jo\n\nThis is true for all positive values of p; make p x, and let C be\nthe limit of the contour D.\n\nThen f (- ty-'e- dt = - 2i sin ttz) f t'-'e- dt.\n\nJ c Jo\n\nTherefore T ( ) = - r 4 I (- tf-'e-'dt.\n\n'2i sm TTzJ c\n\nNow, since the contour C does not pass through the point t = 0, there\nis no need longer to stipulate that the real part of 2 is positive;\nand\n\nI (-ty~ e~ dt is a one-valued analytic function of z for all values of\n2.\n\nJ c\n\nHence, by \\hardsectionref{5}{5}, the equation, just proved when the real part 0/2 is\npositive, persists for all values of z with the exception of the\nvalues 0, ±1, +2\n\nConsequently, for all except integer values of,\n\nr(0) = -\\ J - I -ty-'e-'dt.\n\nThis is Hankel's formula; if we write 1 - 2 for z and make use of\n\\hardsubsectionref{12}{1}{4}, we get the further result that\n\nWe shall write / for \\, meaning thereby that the path of inte-\n\n1 re C\n\ngration starts at 'infinity' on the real axis, encircles the origin in\nthe positive direction and returns to the starting point.\n\nExample 1. Shew that, if the real part of z be positive and if a be\nany positive\n\nconstant, l - t)~ e~ dt tends to zero as p -ao, when the path of\nintegration is either of\n\nthe quadrants of circles of radius p + a with centres at - a, the end\npoints of one quadrant being p and - a + 1 (p -|- a), and of the other\np and -a - i p- a).\n\nV\n\n' (0 + )\n\n%\n% 246\n%\n\nDeduce that lim I \" ' t)-' e- dt= lim I -t)-'e- dt,\n\np-*xy-a + 'P p- y J C\n\nand hence, by writing t= -a-iu, shew that\n\n\\ \\ ['\n\n--- = -- I e \"*- \" (a + <)\"* f M- r (s) ztt y \\ x\n\n[This formula was given by Laplace, Theorie Analytique des\nProhahilites (1812), p. 134, and it is substantially equivalent to\nHankel's formula involving a contour integral.]\n\nExample 2, By taking a = 1, and putting t= -\\ + i tan B in example 1,\nshew that -J- = - ( \"\" cos (tan (9 - 2(9) cos - 2 (9c?<9.\n\nr (2) 77 Jo\n\nExample 3. By taking as contour of integration a parabola whose focus\nis the origin, shew that, if a > 0, then\n\nY z)=-. - - e- ''(l + -) -Jcos 2a + (22-l)arctani; (/i!. sin nz J\n\n\\addexamplecitation{Bourguet, Acta Math, i.}\n\nExample 4. Investigate the values of x for which the integral\n\n2 r*\n\n - sin tdt\n\nTT J\n\nconverges; for such values of x express it in terms of\nGamma-functions, and thence shew that it is equal to\n\n\\addexamplecitation{St John's, 1902.}\n\nExample 5. Prove that I (log t)\" ' dt converges when m > 0, and, bv\nmeans\n\nJot\n\nof example 4, evaluate it when m=l and when m = 2.\n\\addexamplecitation{St John's, 1902.}\n\n\\Section{12}{3}{Gauss' expression for the logarithmic derivate of the\n  Gamma-function as an infinite integral*TODO.}\n\nWe shall now express the function -7- log V (z) = as an infinite\n\nintegral when the real part of z is positive; the function in\nquestion is frequently written yjr (z). We first need a new formula\nfor 7.\n\nTake the formula \\hardsectionref{12}{2} example 4)\n\n  Jo i J\\ i 5 0 Us J t / a olJA J\\& t J'\n\nwhere A = l-e- since | - = log .- O as 8-*-0.\n\n./a l-e\"\n\n Yriting = 1 -e~\" in the first of these integrals and then replacing u\nby t we have\n\ny= lim I r,dt- r '- dt] = r \\ j~,-]] e- dt.\n\n5-*o Us l-e Js t J Jo U-e ' t)\n\nThis is the formula for y which was required.\n\n* Wtr'ke, HI, p. 159.\n\n%\n% 247\n%\n\nTo get Gauss' formula, take the equation \\hardsubsectionref{12}{1}{6})\n\nr'( ) 1 .. /I 1 \\\n\nT z) ' z acm=iVm z-vm)\n\n1 r\n\nand write = e-'( +'\">rf;\n\nz - m Jo\n\nthis is permissible when m = 0, 1, 2, ... if the real part of z is\npositive.\n\nIt follows that\n\n '=-7- I e- ? + lim S (e-\"\"-e-(' + )')f <\n\n.0 rt\\rightarrow \\inftyJowi = l\n\nr( )\n\n-7+ lim = -I dt\n\n1-\n\nV 1 - e-'\n\nW - lim 1 -e-(''+ '(/t\n\n1-e-\n\nNow, when < < 1, i is a bounded function of t whose limit as - [0 is\n6nite;\n\nI 1 - e 'I\n\nand when t 1, - | < - J- < - .\n\nTherefore we can find a number A' independent of t such that, on the\npath of integration,\n\nI 1 - ' I\n\nandso I r\\ zl~,-K ' Vdt\\ < K[ e-i\"*')' rf = /r(H + l)-' 0 as /i- -x .\n\nI jo 1-e-' ./o\n\nWe have thus proved the formula\n\nt< ) = s'\" ' *'->=.C(T-r ')'\"-\n\nwhich is Gauss' expression of - z) as an infinite integral. It may be\nremarked that this is the first integral which we have encountered\nconnected with the Gamma-function in which the integrand is a\nsingle-valued function.\n\nWriting <=log (1 -f-.i') in Gauss' result, we get, if A=(J - 1,\n\n -if=limf t'-,,U.\n\nsince < I - dt < j y =log - g- 0 as 8 0.\n\nT'(z),. / \" f 11 rf.r\n\nHence \\ = uaj |,-.\\ \\ \\ \\ |\\,\n\nsothat ''<=)=rM/J e-'-(, §',\n\nan equation due to Dirichlet*.\n\nWerke, i. p. 275.\n\n%\n% 248\n%\n\nExample 1 . Prove that, if the real part of z is positive,\n\nExample ± Shew that y=\\ l -t)-' -e- ]t-' dt. \\addexamplecitation{Dirichlet.}\n\n\\Subsection{12}{3}{1}{Binet's first expression for TODO in terms of an infinite integral.}\n\nBinet* has given two expressions for logr( ) which are of\ngreat\n\nimportance as shewing the way in which log V z) behaves as ] 2 j -* oo\n. To\n\nobtain the first of these expressions, we observe that, when the real\npart of\n\nz is positive,\n\nr' /'-r \\ L 1 \\ r* (o-t o-tz ]\n\ndt,\n\nr( + i) Jo [ e -i\n\nwriting z + \\ for 2 in \\hardsectionref{12}{3}.\n\nNow, by \\hardsubsubsectionref{6}{2}{2}{2} example 6, we have\n\nlog2=) - r~ '\n\nf\" 1 and so, since (22 )\" = e~ dt,\n\n'Jo\n\nwe have\n\ndz\n\nlogr(. + l) = l + log.-/\"g-;+ - Je-*.\n\nThe integrand in the last integral is continuous as i -; and since\n\n- - - + -f - z. is bounded as - 00, it follows without difficulty\nthat the\n\nintegral converges uniformly when the real part of z is posijiive; we\nmay consequently integrate from 1 to under the sign of integration\n(\\hardsubsectionref{4}{4}{4}) and we get-f-\n\niogr(.+i) = (. + |)iog.-.H-i+/;g- + p-- -\n\ndt.\n\nSince - - + - - i 7 continuous as i - by \\hardsectionref{7}{2}, and since\n\nlog r (z + 1) = log + log r (z),\n\nhave\n\n/ 1\\ (\" CI 1 1 ) e-*\n\niogr(.) = (.-2)iog.-. + i.-j |--- + - \\ -- |- .\n\nJ (2 t e' - l)t\n\n* Journal de I'Ecole Poly technique, xvi. (1839), pp. 123-143.\n\nt Logr(2 + l) meaus the sum of the principal values of the logarithms\nin the factors of the Weierstrassian product.\n\n%\n% 249\n%\n\nTo evaluate the second of these integrals, let*\n\nso that, taking z = in the last expression for logr(2:), we get\n\ni log 7r = i + t/-/.\n\n( + - ) - - dt, we have\n\nt\n\nr ' 1 \\ dt\n\n-jo V t e'- ) t\n\n=/:r- '-HT\n\n~jo 1 c/ V t ) t ' '2tj\n\n* - rf<\n\nt\n\n= 2 + Uogi Consequently /=1- log(27r).\n\nWe therefore have Binet's result that, when the real part of z is\npositive,\n\n3-tZ\n\n -dt.\n\nlog r( ) = [z- \\ ogz-z + \\ log(27r) + J G ~ 7 + \"'-t)\n\nli z = x- iy, we see that, if the upper bound of ( ~ 7 \" t \\ i ) 7 ' *\n' values of is K, then\n\nlogr( )-( -i)log + -|log(27r)'<i(:| \"'\"\n\nso that, when x is large, the terms (z - \\ og z - z \\ o (2'jr) furnish\nan\n\napproximate expression for log V (z).\n\nExample I. Prove that, when A' (a) > 0,\n\nlogr(.-)= r *i4.1-r+( -l) \"j 7- \\addexamplecitation{Malmsten.}\n\nExample 2. Prove that, when R (z) > 0,\n\n* This artifice is due to Priagsheim, Math. Ann. xxxi. (1888), p. 473.\n\n%\n% 250\n%\n\nExample 3. From the formula of \\hardsubsectionref{12}{1}{4}, shew that, if <;r < 1,\n\n2logrW-log.+logsin..-=/; |-' Ui=fl-'-(l-2.).-. f .\n\n\\addexamplecitation{Kummer.}\n\nExample 4. By expanding sinh (| - .v) and 1 - 2x' in Fourier sine\nseries, shew from example 3 that, if < .v < 1,\n\n00\n\nlog r (.p) = i log TT - - log sin -nx + 2 2 a,i sin 2?i7r,\n\n, / \" r 2?i7r e-n dt\n\n\" jo V + 4wV2 27rJ i! Deduce from example 2 of \\hardsubsectionref{12}{3} that\n\n\"*\" \"\" 2 \" \"*\" 2\"\" + * g ''* )\n\n(Kummer, Journal fiir Math. xxxv. (1847), p. 1.)\n\n\\Subsection{12}{3}{2}{Binet's second expression for log V z) in terms of an infinite integral.}\n\nConsider the application of example 7 of Chapter vii (p. 145) to the\nequation \\hardsubsectionref{12}{1}{6})\n\nThe conditions there stated as sufficient for the transformation of a\nseries into integrals are obviously satisfied by the function ( )= -\nr-, if the real part of z be positive; and we have\n\nSince !5'(, + /i) I is easily seen to be less than K t/n, where Ki is\ninde- pendent of t and n, it follows that the limit of the last\nintegral is 'zero.\n\nHence V;: log F ( ) = 2,- -I i - -, - -.\n\ndz 2z- z Jo z + t'f e- - 1\n\nI 2 I Since ~ - - does not exceed K (where K depends only on 8) when\nthe\n\nI I*\n\nreal part of z exceeds 8, the integral converges uniformly and we may\nintegrate under the integral sign \\hardsubsectionref{4}{4}{4}) from 1 to z.\n\nWe get\n\n-I log r (.) = -;+ log . + - 2 /; . JL,\n\nwhere C is a constant. Integrating again,\n\nlog r (.) = (. - 1) log . + (c - 1) . + c + 2/; '- dt.\n\nwhere 6\" is a constant.\n\n%\n% 251\n%\n\nNow, if z is real, arc tan tjz \\$ tlz,\n\nand so\n\nlogrW-( -i)log -(C-l).-C\"|<?/\" d(.\n\nBut it has been shewn in \\hardsubsectionref{12}{3}{1} that\n\n\\ \\ % z)-[z-- \\ ogz- z- \\ og 1'K) -0,\n\nas 2 -* X through real values. Comparing these results we see that C =\n0, 6\"=ilog(27r).\n\nHence for all values of z whose real part is positive,\n\nlogrW = (.-l)log.-. + llog(2.) + 2|; -I rf*.\n\nwhere arc tan u is defined by the equation\n\narc tan xi = |,\n\n.'o l+<-\n\nin which the path of integration is a straight line.\n\nThis is Binet's second expression for log V z).\n\nExample. Justify differentiating with regard to z under the sign of\nintegration, so as to get the equation\n\n12 33. The asymptotic expansion of the logarithm of the Gamma-\nfunction (Stirling's series).\n\nWe can now obtain an expansion which represents the function log F z)\nasymptotically \\hardsectionref{8}{2}) for large values of \\ z\\, and which is used in\nthe calculation of the Gamma-function.\n\nLet us assume that, if = x -f iy, then a-' S >; and we have, by\nBinet's second formula,\n\nlog r ( ) = ( - ) log - + - log (27r) + </) ( ),\n\nwhere (.) = 2/; c/.\n\nNow\n\n(\\ )n-i 2,1-1 (\\ y rt u n\n\narc\n\n,,,,, t It' It' (\\ )n-i 2n-i (\\ )H rt\n\nu + z' Substituting and remembering \\hardsectionref{7}{2}) that\n\nJo e' ' -l ~4w'\n\n%\n% 252\n%\n\nwhere Bi, Bo, ... are Bernoulli's numbers, we have\n\n  / X V (-)' \"' Br 2 (-)'* r \" f f U' ' du \\ dt\n\n.=1 2r (2?- - 1) '--l 271-1 j \\ [ ! () 2 2 + 2 j g2,r< \\ I\n\nLet the upper bound * of - 1 for positive values of u be K,\n\nj w + j\n\nThen\n\nftl\n\nf u' 'du] dt 1 r, I, r\" 1 r, ) (\n\nuow + ' j e-' '-li\" ' ' Jo [Jo \\ e'-'-l\n\nJi-z n+1\n\n 4(n+l)(2M+l)| |2\" Hence\n\n2(-y r ( f* u l \\ d KA+\n\nz \"-' Jo Vou' + z e -l 2 n + l) 2n + l)\\ z p +i '\n\nand it is obvious that this tends to zero uniformly as | | - oo if I\narg | tt - A, where tt > A > 0, so that K cosec 2 A.\n\nAlso it is clear that if ] arg r | Itt (so that Kz = l) the error in\ntaking the first 71 terms of the series\n\nI (-y-'Br 1\n\nrti 2r (2r - 1) z -' as an approximation to <f) (z) is numerically\nless than the (n + l)th term. Since, if | arg z\\ \\ 7r - A,\n\n-,211-1\n\n!</> ( ) - i Z ' \\ I < cosec 2 A .,\n\nr r=i 2r(2r-l)l; 2(n + l)(2,\n\n2(n + l)(2n + l)\n\n-0,\n\nas 00, it is clear that\n\nB, B, B,\n\n1.2.2 3. 4. 2=* ' 5.6.2 \"* is the asymptotic expansion f \\hardsectionref{8}{2}) of\n(2). We see therefore that the series\n\nis the asymptotic expansion of log V z) when | arg | tt - A.\n\n-Kj 18 the lower bound of -!, .j and is consequentlj' equal to\n\n4 2y2,\n\n, 9, .n o or 1 as x2<m2 or x >y . t The development is asymptotic;\nfor if it converged when | 2 | p, by \\hardsectionref{2}{6} we could find K, such that\nB <(2;i-l)2nA>2\"; and then the series 2 ~ \"~' \" \" would define an\nintegral function; this is contrary to \\hardsectionref{7}{2}.\n\n%\n% 253\n%\n\nThis is generally known as Stirling s series. In \\hardsectionref{13}{6} it will be\nestab- lished over the extended range | arg tt - A.\n\nIn particular when z is positive (= x), we have\n\nr u? du'] dt Bn+.\n\nJo Uo w + j e ' '-l\n\nw + je ' '-l 2 n + l) 2n + l)af\n\nHence, when x>0, the value of < )(oc) always lies between the sm7i of\nn terms and the sum ofn + 1 terms of the series for all values of n.\n\nD g\n\nIn particular < (f> (x) < - -, so that <f> (./) = y where < < 1.\n\nHence T x) = x'- - e'' i2'rrf e ' 'l\n\nAlso, taking the exponential of Stirling's series, we get\n\n\\ x .r-, a f 1 1 139 571 /'I\n\nr ix) = e X ~ (27r) -,1 - 288 ~ 51840 ~ 2488320 \"*\" V\n\nThis is an asymptotic formula for the Gamma-function. In conjunction\nwith the formula T x + l) = xr x), it is very useful for the purpose\nof com- puting the numerical value of the function for real values of\nx.\n\nTables of the function logioT (. ), correct to 12 decimal places, for\nvalues of .v between 1 and 2, were constructed in this way by\nLegendre, and published in his Exercices de Calcul Integral, ii. p.\n85, in 1817, and his Traite des fonctions elliptiques (1826), p. 489.\n\nIt may be observed that V (x) has one minimum for positive values of\n.>;, when .r= 1-4616321..., the value of log,or(.r) then being\n1-9472391....\n\nExample. Obtain the expansion, convergent when R z) > 0,\n\n\\ og,T z) = z-l)\\ og, z- z+ \\ og, 27r) + J (z),\n\nwhere in which\n\n- W- 5 |, + | + 2 (- +1) (. + 2) 3 (.-+1) (.- + 2) z + S) -\n\nand generally\n\nc = r (x+l) x + 2) ... x + n- ) 2x - ) xdx. \\addexamplecitation{Binet.}\n\nJ\n\n\\Section{12}{4}{The Eulenan Integral of the First Kind.}\n\nThe name Eulerian Integral of the First Kind was given by Legendre to\nthe integral\n\nB (p, q) = f xP-' (1 - x)'i-' dec,\n\nJ\n\nwhich was first studied by Euler and Legendre*. In this integral, the\nreal parts of p and q are supposed to be positive; and xp~, (1 - x) ~\nare to be understood to mean those values of e( ~ ) °°* and\ne('v-i)'°e(i- =) which correspond to the real determinations of the\nlogarithms.\n\n* Euler, Nov. Comvi. Petrop. xvi. (1772); Legendre, Exercices, i. p.\n221.\n\n%\n% 254\n%\n\nWith these stipulations, it is easily seen that B (p, q) exists, as a\n(possibly improper) integral \\hardsectionref{4}{5} example 2).\n\nWe have, on writing (1 - *) for w,\n\nB p,q) = B q,p).\n\nAlso, integrating by parts,\n\nJo L i Jo PJo\n\nso that B p,q + l) = B p+l,q).\n\nExample 1. Shew that\n\nB p,q)= £ip + l,q) + B p,q + l).\n\nExample 2. Deduce from example 1 that\n\nB P,<l + )= B p,q).\n\nExample 3. Prove that if n is a positive integei*,\n\n,,, 1 . 2 ... M\n\nB p,n + ) = -\n\np p + l)... p + n)\\ Example 4. Prove that\n\nExample 5. Prove that\n\nr (2) = lim n B z, n).\n\n\\Subsection{12}{4}{1}{Expression of the Eulerian Integral of the First\n  Kind in terms of the Gamma function.}\n\nWe shall now establish the important theorem that\n\nR/.,, x\\ r(m)r(n)\n\nFirst let the real parts of m and n exceed |; then\n\nr (m) r (n) = e-* '\"-i c a; x g-?' if'- dy. Jo Jo\n\nOn writing a;'- for .t, and y for y, this gives\n\nfR rR\n\nV (m) r (n) = 4 lim e\"*' x'-\"\"-' dx x g-?/' /-\"-i dy\n\n= 4 lim e-( '+2'') 2m-iy2n-i( ( \\\n\nNow, for the values of m and n under consideration, the integrand is\ncontinuous over the range of integration, and so the integral may be\ncon- sidered as a double integral taken over a square Sji. Calling the\nintegrand\n\n%\n% 255\n%\n\nf x, y), and calling Qg the quadrant with centre at the origin and\nradius R, we have, if Tji be the part of S, outside Qb,,\n\nI f(x, y) dxdy - f oc,y) dxdy JJsr JJqr I\n\n= 1 f(a:,y)dxdy\n\n JJ Tr\n\ni \\ f >y)ida dy-\\ \\ \\ f,y)dxdy\\\n\nJJSr JJ Sir\n\n  . ., .,\n\n- 0 as R X,\n\nsince 1 1 |/(;, y) \\ dxdy converges to a limit, namely\n\nJJ Sr\n\nTherefore\n\nImi\n\n2 I e- '-, x\"\"-' idxx2\\ e' \\ y-''-' \\ dy. Jo' Jo\n\nI f(x,y)dxdy= lim // f x,y)dxdy.\n\nChanging to polar* coordinates x = rcos 0, y = r sin 6), we have f x,\ny) dxdy = |\n\nOh\n\nHence\n\n1 1 f x, y) dxdy = ( \\ e-\"\" (r cos 0) '\"-' (r sin 0)-''-' rdrd0.\n\nJ J Or J J\n\nr (w) r ( ) = 4 e-r' r-('\"+\")-i dr cos=\" -i sin ' - c? Jo Jo\n\n= 2r ( i + ?z) cos '\"-' sin ''- <9c? .\n\nJo\n\nWriting cos- = u we at once get\n\nr (m) r (?i) = r (?u + ) . z (w, ?i).\n\nThis has only been proved when the real parts of ni and n exceed |;\nbut it can obviously be deduced when these are less than | by TODO\nexample 2.\n\nThis result, discovered by Euler, connects the Eulerian Integral of\nthe First Kind with the Gamma-function.\n\nExample 1. Shew that\n\n[' (l-f-A-)' -i(l-.r) -i( =2P + 9-i Mli2).\n\n  -I ' ' ip+q)\n\n  * It is easily proved by the methods of \\hardsubsectionref{4}{1}{1} that the areas A /x of\n  \\hardsectionref{4}{3} need not be rect- angles provided only that their greatest\ndiameters can be made arbitrarily small by taking the number of areas\nsufficiently large; so the areas may be taken to be the regions\nbounded by radii vectores and circular arcs.\n\n%\n% 256\n%\n\nExample 2. Shew that, if\n\nj\\ isj .v x + 1 2! .r + 2 3! .r + d\n\nthen\n\nf x,y)=f y + \\,x-\\ \\\n\nwhere and y have such vakies that the series are convergent. (Jesus,\n1901.)\n\nExample 3. Prove that\n\nj'J'j xy) l-xT- y> i yr- dxdy = - > 'j\n\n\\addexamplecitation{Math. Trip. 1894.}\n\n\\Subsection{12}{4}{2}{Evaluation of trigonometrical integrals in terms of the Gamma-function.}\n\nWe can now evaluate the integral cos\" ~ x sm' ~ xdx, where m and n\n\nJo\n\nare not restricted to be integers, but have their real parts positive.\nFor, writing cos o; = t, we have, as in \\hardsubsectionref{12}{4}{1},\n\nI'*\" .,, IF am) ran)\n\ncos' - cc sin\" -1 xdx = f. ' - .\n\nThe well-known elementary formulae for the cases in which m and n are\nintegers can be at once derived from this result.\n\nExample. Prove that, when \\ k\\ < .\\,\n\nfh CDS'\" e sin' edd \\ T (lm+ )T /i+ ) fh cos'\" -'\"Odd J \\ l ksm 6)i ~\nTlh-a + hi+l) 7r J (l - k sin2 )i + *\n\n\\addexamplecitation{Trinity, 1898.}\n\n\\Subsection{12}{4}{3}{Pochhammers* extension of the Ealerian Integral of the First Kind.}\n\nWe have seen in \\hardsubsectionref{12}{2}{2} that it is possible to replace the second\nEulerian integral for F(z) by a contour integral which converges for\nall values of z. A similar process has been carried out by Pochhammer\nfor Eulerian integrals of the first kind.\n\nLet P be any point on the real axis between and 1; consider the\n\nintegral\n\nr(i+,o+, 1-, 0-) e-'\"'<' + ) t - (1 - 0 -' dt = e a, /3).\n\nJ F\n\nThe notation employed is that introduced at the end of \\hardsubsectionref{12}{2}{2} and\nmeans that the path of integration starts from P, encircles the point\n1 in the positive (counter-clockwise) direction and returns to P, then\nencircles the origin in the positive direction and returns to P, and\nso on.\n\n, * Math. Ann. xxxv. (1890), p. 495.\n\n%\n% 257\n%\n\nAt the starting-point the arguments of t and - t are both zero; after\nthe circuit (1 +) they are and l-ir; after the circuit (0 +) they are\nItt and 27r; after the circuit (1 - ) they are lir and and after the\ncircuit (0 - ) they are both zero, so that the final vahie of the\nintegrand is the same as the initial value.\n\nIt is easily seen that, since the path of integration may be deformed\nin any way so long as it does not pass over the branch points 0, 1 of\nthe integrand, the path may be taken to be that shewn in the figure,\nwherein the four parallel lines are supposed to coincide with the real\naxis.\n\n>\n\n// the real parts of a. and y9 are positive the integrals round the\ncircles tend to zero as the radii of the circles tend to zero*; the\nintegrands on the paths marked a, h, c, d are\n\n a-Ig-'W(a-l) (1 \\ )3-lg2.r<(8-l) a-l g2,r.(a-]) ( \\ )fl-i\n\nrespectively, the arguments of t and 1 - nuiu being zero in each case.\n\nHence we may write e (a, ) as the sum of four (possibly improper)\nintegrals, thus :\n\ne (a, /3) = e- '(''+ )\n\nI t -' (1 - 0 \"' + I t\"-' (1 - 0 ~'e-''\n\n dt\n\nC 1 /\"\"\n\n+ t\"-' (1 - tf-' e -'t\"* ) dt + -' (1 - tf-'e- ' dt . .' 1\n\nHence\n\n€ (a, /3) = e- '(' - ) (1 - e---) (1 - e ' ) f -' (1 - tf-' dt\n\nJO\n\n, ., ., l (a)r(/9) = - -isin (a7r)sin (ott) ~\n\n- 47r* \"r(l-a)r(l-/: )r(a + )-\n\nNow e (a, /S) and this last expression are analytic functions of a and\nof /3 for all values of a and /S. So, by the theory of analytic\ncontinuation, this equality, proved when the real parts of a and are\npositive, holds for all values of a and l3. Hence for all values of a\nand /3 lue have proved that\n\n/ J -47r-\n\nr i-cc)l\\ l-id)l\\ a+id)- ' The reader ought to have uo difficulty in\nproving this.\n\nAV. M. A.\n\n17\n\n%\n% 258\n%\n\n\\Section{12}{5}{Dirichlet's integral*TODO.}\n\nWe shall now shew how the repeated integral\n\n/ = f f . . . I f t, + t,+ ...+ tn) i\"'- o\" - . . . tn' n-idt dt, . .\n. dt\n\nmay be reduced to a simple integral, where/is continuous, a > (?* = 1,\n2, ... n) and the integration is extended over all positive values of\nthe variables such that 1 + 4+ ... + tn \\$1.\n\nTo simplify p'M f\\ t + T+ ) t' -'T -'dtdT\n\nJo Jo\n\n(where we have written t, T, a, j3 for t, t, cui, Og and X for 3 + 4\n+ ... +tn), put t = T \\ - v)/v; the integral becomes (if X. 0)\n\nr~U' /(x + Tlv) l - vy-' V-''-' r-+3-i dvdT.\n\nJo J T/(l- )\n\nChanging the order of integration \\hardsubsectionref{4}{5}{1}), the integral becomes\n\n( [ V( + T/v) l- vy-'v''-' T- -'dTdv. J J\n\nPutting T = VTo, the integral becomes\n\nI i /( + \" 2) (1 - vy-' v -' r. + -' dr., dv J J\n\nr (a)r(8) r -\n\nr( + /3) Jo\n\nHence\n\n  J|... j/(T. + 3+ ... +Qt/.+ -i 3\" -i ... tn ' -'dr.dt, ... dtn,\n\nr(,)r(,) r(e\n\nthe integration being extended over all positive values of the\nvariables such that T2 + ts + ... +tn- .\n\nContinually reducing in this way we get\n\nr((x, + a,+ ...+an) Jo- ' which is Dirichlet's result. Example 1.\nReduce\n\nto a simple integral; the range of integration being extended over\nall positive values of the variables such that\n\nit being assumed that a, 6, c. a,, y, p, q, r are positive.\n\\addexamplecitation{Dirichlet.}\n\n* Werkt, I. pp. 375, 391.\n\n%\n% 259\n%\n\nExample 2. Evaluate / / x yi dxdy,\n\nm and n being positive and\n\n' >0, 2/ 0, x>\" + y \" 1 . ( Pembroke, 1 907 . )\n\nExample 3. Shew that the moment of inertia of a homogeneous ellipsoid\nof unit density, taken about the axis of z, is\n\nwhere a, 6, c are the semi-axes.\n\nExample 4. Shew that the area of the epicycloid x-' +y =P is fn-r-.\n\nREFERENCES. N. Nielsen, Handhnch der Theorie aer (Jamma-funktion*.\n(Leipzig, 1906.) 0. ScHLOMiLCH, Compendium der ho her en Analysis, ll.\n(Brun.swick, 1874,) E. L. LiNDELOF, Le Calcul des Residus, Ch. iv.\n(Paris, 1905.) A. Pringsheim, Math. Ann. xxxi. (1888), pp. 455-481.\n\nMiscellaneous Examples.\n\n1. Shew that\n\n\\addexamplecitation{Trinity, 1897.}\n\n2. Shew that\n\n.,'i\"i vr. rrp rTr.-i7i;\"\"='\"<\"+\"- '™'\"' ' ' '>\n\n3. Prove that\n\nr'(i) T' (is)\n\nf(i) ~ r(|) = S - (' ® \" ' 2-)\n\n4. Shew that\n\n r(i)! 32 52-1 72 92-1 IP . .\n\n\"16;; \" = 3  5  r T  92  i -ZTi  \\addexamplecitation{Trinity, 1891.}\n\n5. Shew that\n\n- f ( -a)(M+ + y ) a \\ \\ 1 .,, .,\\,,\n\nn \\ - - --7-7 -; - r 1+, H- = - - sm (an) B (/3, y).\n\n =o I ( +/:<) ( +y) \\ + l/j TT ' \" '\n\n\\addexamplecitation{Trinity, 1905.}\n\n6. Shew that ( ) ('Isf ' \\addexamplecitation{Peterhouse, 1906.}\n\n7. Shew that, if z = iC where is real, then\n\nl l=\\/(fSVc)- \\addexamplecitation{Trinity, 1904.}\n\n8. When x is positive, shew thatt\n\nr (x) r (h) °° 2n ! 1\n\n . ., Tx = 2 -; - - - . \\addexamplecitation{Math. Trip. 1897.}\n\n* This work contains a complete bibliography.\n\nt This and some other examples are most easily proved by the result of \\hardsubsectionref{14}{1}{1}.\n\n17-2\n\n%\n% 260\n%\n\n9. If a is positive, shew that\n\nr( )r( +i) i ( -)\" ( - 1) ((f - 2) ...(g-H) 1 r(2+ ) =o ! s+ '\n\n10. If .V > and\n\nJO\n\nshew that\n\nand\n\n11. Shew that if X > 0,,c> 0, - tt <a <\\ tt, then\n$$\nTODO\n$$\n\\addexamplecitation{Euler.}\n\n12. Prove that, if 6 > 0, then, when < s < 2,\n\n/ - 7\" dx = \\ u\\ f- cosec (J7rs)/r (s), y - and, when < s < 1,\n\n/ * cosfto; \\ J (a. .)/p (5), \\addexamplecitation{Euler.}\n\n\\ / .\n\n13. If < /i < 1, prove that\n\njj(l+.t'-cos -rf.r=r(,0 cos (f -1) - +,\n\n\\addexamplecitation{Peterhouse, 1895.}\n\n14. By taking as contour of integration a parabola with its vertex at\nthe origin, derive from the formula\n\n1 r** \"\")\n\n2 sin an \\ the result\n\n1 f\n\nr(a)= - -. / e- ''x\"--' l+:c''-) [Ziim x + a?(.YCcot(-Jc)\n\n2 sui utt J )\n\n+ sin x + a - 2) arc cot ( - x) ] dx, the arc cot denoting an obtuse\nangle.\n\n(Bourguet, Acta Math. i. p. 367.)\n\n15. Shew that, if the real part of a-n is positive and 2 l/a is\nconvergent, then\n\nn = l\n\nd' is convergent when m > 2, where \\//-( ) (2) = -r log r (z). (Math.\nTrip. 1907.)\n\n16. Prove that\n\n\"jo 1'\n\nd\\ ogr z)\\ /\"e- g-e-g'\n\n< 2\n\n= r (l+a)-i-(l+a)- ---), Jo a\n\n/ 1 .2 - 1 \\ ] = / dx-y. \\addexamplecitation{Legendre.}\n\nJo x-l\n\n%\n% 261\n%\n\n17. Prove that, when R z)>0,\n\n\\ ogr z)=r i- -xiz-l)] f- . \\addexamplecitation{Bmet.}\n\n18. Prove that, for all values of z except negative real values,\n\nlog r (2) = (3 - 1) log 2 - 2 + Uog (27r)\n\nJ 1 1 2 J; \\ 3\\ = J ]\n\n19. Prove that, when (2) > 0,\n\n-rlogr(2) = log2- / r j l-a.-+log.r .\n\ndz ° ° Jo (l-.r)log.r\n\n20. Prove that, when R (2) > 0,\n\nc/2' °\n\n21. If\n\nshew that\n\n/2+1 logr(Oo? = ?',\n\nand deduce from \\hardsubsectionref{12}{3}{3} that, for all values of 2 except negative real\nvalue.s,\n\nu = z log z - z + i log (2n-).\n\n\\addexamplecitation{Raabe, Jovnial fur Math, xxv.}\n\n22. Prove that, for all wilues of 2 except negative real values,\n\nsin 2nTrx\n\n00 f dx' logr(2) = (2-i)log2-2 + Uog(27r)+ 2 / --\n\nn=lj *+'\n\n23. Prove that\n\n(Bourguet*.\n\nBip,p)B p+h,p+h)= y \\addexamplecitation{Binet.}\n\n24. Prove that, when -(</<(,\n\nr,,,1 /\"\"\" cosh (2n*) c?M\n\n25. Prove that, when q>\\,\n\nB p, q) + Bip + \\, q) + B p + 2, q) + ...=B p, q- ) .\n\n26. Prove that, when p-a>0,\n\nB p-ci,q) aq a(a + l) g(g + l)\n\n (i, ?) ' it;4-?'*' 1. 2. (/> + (/) (io + ? + l)\n\n27. Prove that\n\nB p, q)B p q, r) = B q, r)B q+r, p). \\addexamplecitation{Euler.}\n\n28. Shew that\n\nn,,, .,, d.r r(a)r(b) 1\n\nJo \" '' (.r+?>) + '' r(a + 6) (l+jo) jo\"'\n\nif a > 0, 6 > 0, p > 0. \\addexamplecitation{Trinity, 1908.}\n\n* This result is attributed to Bourguet by Stieltjes, Journal de Math,\n(i), v. p. 432.\n\n%\n% 262\n%\n\n29. Shew that, if m > 0, n>0, then\n\nn ( i+. )2 >-i (1 - -y n-i, \\ r(m)r n)\n\nand deduce that, when a is real and not an integer multiple of ijr,\n\n'i /cos 6 + sin \\ cos 2a\n\n/'\n\n\\ i,r veos C - SUl\n\nd6=.\n\nand\n\n30. Shew that, if a > 0, > 0,\n\n/:\n\n2 sin (tt cos a) '\n\n\\addexamplecitation{St John's, 1904.}\n\n\\addexamplecitation{Kummer.}\n\n31 . Shew that, if a > 0, + 6 > 0,\n\nfr(a)r(S) r(a + b)r 8)\n\nr..r--(i- ) \\,, lrw\n\nJo I-''*'' 5-0 I (a\n\nl= / (a+6)- /'(a).\n\n' + 8) T a + b + 8) Deduce that, if in addition a + c>0, a- b + c>0,\n\n/l a-l (l\\ b)(l\\ . .c) r (t ).! ( ± \\ +\\ ' )\n\njo \"(i-.r)(-log.r) * ~ *r(a + 6)r(a+c)\" 32. Shew that, if a, b, c be\nsuch that the integral converges,\n\nfUl-x\")(l-afi)(l-x'),, T b + c+l)T c + a + l)T a+b + l) ' a.v=los\n\nJO (i-A-)(-log.r) '\" '' °r(a + ' ) r b + l)r c + l)r a + h + c+l)' 33.\nBy the substitution cos = 1-2 tan <, shew that\n\n(3-cos )5 4v/7r\n\n\\addexamplecitation{St John's, 1896.}\n\nf sinP.v\n\n34. Evaluate in terms of Gamma-functions the integral / ' dx, when /)\nis a\n\nJ '*-\"\n\nfraction greater than unity whose numerator and denominator are both\nodd integers.\n\n[Shew that the integral is h I sin'' x\\~+ 2 ( - )\" ( 1 ) [ d.v.]\n\n'- Jo l n=i \\ x+mr x-mrj)\n\n35. Shew that\n\n\\addexamplecitation{Clare, 1898.}\n\n/:\n\n93?-\n\n2\" + 2 r=o2/'!(n-r)\n\n-a-mi-\n\n36. Prove that\n\nlog Bip,g) log ( +i) 4- I ' \\: '\"\\ \\ l '\" dv. \\addexamplecitation{Euler.}\n\ns v/', -/; °\\ pq J j(, (1-V)l0g 7\n\n37. Prove that, if p>0, p + s>0, then\n\nB(p,p)\n\n '\n\ns s~l), s(s-l)(s-2)(s-3)\n\n (P>P + )=- f7 ' l+ ( ) + 2.4.(2 +\n\nfd i,-- - <--\n\n38. The curve r\"*=2'\"~i a'\"cos ??i is composed of ?n equal closed\nloops. Shew that the length of the arc of half of one of the loops is\n\ni~ a I (i cos x) ' dx, Jo\n\nand hence that the total perimeter of the curve is\n\na iV\n\nlm)\\\n\n%\n% 263\n%\n\n39. Draw the straight line joiniug the points ±i, and the semicircle\nof \\ z\\ = \\ which lies on the right of this line. Let C be the contour\nformed by indenting this figure at\n\n- ?', 0, i. By considering / 2P- -i z + z- )p \"-- dz, shew that, if p\n+ q>l, q <l,\n\nI \" cosP*i--6 cos ip-q) 6 d6 =,, \"!,, r.\n\nJo ip + q-l)2P i- B(p,q)\n\nProve that the result is true for all values of p and q such that p +\nq>'l.\n\n\\addexamplecitation{Cauchy.}\n\n40. If s is positive (not necessarily integral), and - in .r hn, shew\nthat\n\nMild draw graphs of the series and of the function cos*.i'.\n\n41. Obtain the expansion\n\ncos .f-2, r (*+i)[r(| +ia+i)r(i5- a+i) \" r(h+?,a+i)raj- a+iy-]'\n\nand find the values of x for which it is applicable. \\addexamplecitation{Cauchy.}\n\n42. Prove that, if /> > A,\n\n22p-i r 2/>\"- f 12 12.32 1 \"|2\n\n'\"'''\"=-A \"\"Wi'U + l i' 2(2yT3-) + 2.4.(2p+3)(2f+5)+ . '\n\n\\addexamplecitation{Binet.}\n\n43. Shew that, if .c < 0, ./ + -- > 0, then\n\nr(-.f) [-.f,(-..-)(l-.r) (-.r)(l- )(2-f ) 1 r(5) 1 5 - s(l+2) \" z\nl+z) 2 + z) j\n\nand deduce that, when x + r> 0,\n\n  Ina m +* ) \\ f \\ 4   -1), X '( -l)(- -2) \\ f/-' r>) z z(z +\nl) - z z + l) z + 2)\n\n44. Using the result of example 43, prove that\n\nlogr(2 + a) = logr(0 + rtlogs\n\n2z\n\nfa\n\ndt\n\na [\\ \\ { t)(2-t) ...(n-t)dt- f\" t l-t) 2-t) ...(n-t)'\n\n\\ 5 .' .'o\n\nnti n + l)z z+l) z + 2) ... z + n)\n\ninvestigating the region of convergence of the .series.\n\n(Binet, Journal de V Ecole polytechnique, xvi. (1839), p. 256.)\n\n45. Prove that, if /> > 0, > 0, then\n\n-. P-\n\nB ip, q) = V- i (2 )* * \"' '\n\n%\n% 264\n%\n\nwhere\n\nII (p, g) = 2p - - T arc tan - - -. - -, -,\n\nand p2 = 2 + q +pq-\n\n46. If 6 =2*-'7r(l-i'r), F=2 - 7r(i-iA'),\n\nand if the function F (,r) be defined by the equation\n\nshew (1) that F o:) satisfies the equation\n\nF x+ ) =xF x) +\n\nr(l-A-)'\n\n(2) that, for all positive integral values of x,\n\nF x) = rix\\\n\n(3) that F(x) is analytic for all finite values of x,\n\n1 (7 \\ 2\n\n(4) that \"- \"* '\n\n47. Expand\n\nF(x)= ~- r -r- log- 7\n\nas a series of ascending powei's of a.\n\n(Various evaluations of the coefficients in this expansion have been\ngiven by Bourguet, Bull des Set. Math. v. (1881), p. 43; Bourguet,\nActa Math. ll. (1883), p. 261; Schlomilch,' Zeitschrift fiir Math,\nund Phys. xxv. (1880), pp. 35, 351.)\n\n48. Prove that the G-function, defined by the equation\n\nG(z + ) = (2nf'e- ' + - n |(i+i)%-'+-'- /(2\")|,\n\nis an integral function which satisfies the relations\n\n0 z + ) = V z)G z), (?(1) = 1,\n\n(n !)'V6-' (n + 1) = 11 . 22 . 33 ... w\". \\addexamplecitation{Alexeiewsky.}\n\n(The most important properties of the G-function are discussed in\nBarnes' memoir, Quarterly Journal, xxxi.)\n\n49. Shew that and deduce that\n\nlog Q J = / s cot Tvzdz-z log (27r).\n\n50. Shew that\n\nlogrri + l)c <=i3log(2rr)-|3(2+i;+3logr(s + l)-logG'(s + l).\n", "meta": {"hexsha": "eb7b2162c08742999eb737e0ad930ddc25360fe1", "size": 44622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch12.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-ch12.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-ch12.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": 21.1679316888, "max_line_length": 100, "alphanum_fraction": 0.6142261665, "num_tokens": 16406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872075132152, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.6290339713953629}}
{"text": "\\chapter{Some Properties of Trees}\n\\label{sct_defining_clades}\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics{oriented_graph.png}\n % oriented_graph.png: 485x393 pixel, 300dpi, 4.11x3.33 cm, bb=0 0 116 94\n \\caption{An oriented graph (not a tree!), with edge orientation shown as arrows. Two paths are highlighted (cyan and blue). The cyan path starts at node A and ends at node E. Nodes B, C, D, and E are reachable from A. Node C is the direct successor of B in the cyan path; in the blue path the direct successor of B is F. The segment highlighted in red is \\emph{not} a path.}\n \\label{fig_oriented_graph}\n\\end{figure}\n\n\n\nIn the following, $T$ will be a rooted tree. We'll recall that a tree (rooted or not) is a connected, acyclic graph. By choosing one node to be the root (which we'll note $R$), and orienting all edges away from the root, we get an oriented graph. A \\textit{path} along such a graph is a sequence of nodes such that there is an edge between two successive nodes, and that these nodes are ordered in the sequence as they are in the edge. The first node in the path is called the \\textit{start} of the path, and the last node is its \\textit{end}. We speak of a path \\textit{from} the start \\textit{to} the end, equivalently we say that the end is \\textit{reachable} from the start. The nodes in a path are ordered: if $a$ and $b$ are in a path, then either $a$ is reachable from $b$, or $b$ is reachable from $a$, or $a = b$; furthermore if $a$ is reachable from $b$, then $b$ is \\textit{not} reachable from $a$. If an edge connects $a$ to $b$, then $b$ is the \\textit{direct successor} of $a$, and $a$ is the \\textit{direct predecessor} of $b$\nSee figure {\\ref{fig_oriented_graph}.\n\nAlthough paths are not sets, we will (somewhat abusively, perhaps) use set notation with paths, unless there is a risk of confusion. Thus is $P$ is a path and $n$ is a node, then $n \\in P$ means that $n$ is ``in'' $P$  or ``belongs to'' $P$ (strictly speaking, $n$ is reachable from the start of $P$, and the end of $P$ is reachable from $n$).\n\nNow a few definitions - these are mostly renamings of graph-theoretical concepts, to make them more intuitive for phylogenetic trees. \n\n\\begin{dfn}\n\\label{def_ancestor}\nLet $a$ and $b$ be two different nodes of $T$. We say that $a$ is an \\textit{ancestor} of $b$, or (equivalently) that $b$ is a \\textit{descendant} of $a$, if and only if there is a path from $a$ to $b$. \n\\end{dfn}\n\n\\begin{dfn}\n\\label{def_parent}\nLet $P$ be a path in $T$, and $a, b$ two nodes in $P$ such that $b$ is the direct successor of $a$. We will call $a$ the \\textit{parent} of $b$. We can say \\textit{the} parent (rather than \\textit{a} parent) of $b$ because i) $a$ lies on the path from $R$ to $b$ (which is unique), and ii) only one node on any path can be another node's direct predecessor. We also see that any node's parent is also its ancestor (which shouldn't be too surprising\\ldots), since $b$ is reachable from $a$\n\\end{dfn}\n\n\\begin{dfn}\n\\label{def_child}\nLet $P$ be a path in $T$, and $a, b$ two nodes in $P$ such that $b$ is the direct successor of $a$. We say that $b$ is a \\textit{child} of $a$.\n\\end{dfn}\n\nNote that a node has exactly one parent, except the root which has none. A node can have zero or more children, but we rarely ever encounter nodes with a single child. A node with no children is called a \\textit{leaf}.\n\n\\begin{dfn}\n\\label{def_lineage}\nA path that starts from the root we call a \\emph{lineage}. By the definition of a rooted tree, there is always a lineage to $n$ for any node $n$, and this lineage is unique. So we can unambiguously talk of \\textit{the} lineage of $n$ to mean the path from $R$ to $n$. We say that a set $L$ of nodes form a lineage if there exists $n \\in L$ such that the path from $R$ to $n$ contains all and only elements of $L$.\n\\end{dfn}\n\n\\begin{figure}[b]\n \\centering\n \\includegraphics{prop_tree.png}\n  \\caption{A rooted tree}\n \\label{fig_app_tree_prop}\n\\end{figure}\n\n\\begin{prop}\n\\label{prop_lineage_ancestors_equivalence}\nLet $n$ be a node of $T$, and $L$ its lineage. Then all ancestors of $n$ belong to $L$, and all nodes of $L$, except $n$ itself, are ancestors of $n$.\n\\end{prop}\n\n\\begin{proof}\n\n$\\Rightarrow$ Let $a$ be an ancestor of $n$. By definition \\ref{def_ancestor}, there is a path from $a$ to $n$. By tree properties, there is a path from $R$ to $a$. Hence $a$ belongs to the path from $R$ to $n$, which is the lineage of $n$.\n\\end{proof}\n\n\\noindent{}$\\Leftarrow$ Let $l \\neq n$ be a node in $L$. Since $L$ is the path from $R$ to $n$, $n$ is reachable from $a$, and hence $a$ is an ancestor of $n$ by definition \\ref{def_ancestor}.\n\n\\begin{dfn}\nIf $L$ and $M$ are lineages of $T$, then the \\textit{intersection}\nof $L$ and $M$, noted $L \\cap M$, is the set of nodes that belong to both $L$ and $M$.\n\\end{dfn} \n\n\\begin{lemma}\n\\label{lem_ancestors_in_lineage}\nLet $n$ be a node of $T$, $L$ its lineage, and $l$ a node of $L$. Then $l$'s ancestors also belong to $L$.\n\\end{lemma}\n\\begin{proof}\nIf $l = n$ then the ancestors of $l$ are those of $n$, which belong to $L$ by proposition \\ref{prop_lineage_ancestors_equivalence}. If $l \\neq n$ then let $a$ be an ancestor of $l$. By definition \\ref{def_ancestor}, $l$ is reachable from $a$. By proposition \\ref{prop_lineage_ancestors_equivalence}, $l$ is an ancestor of $n$ and again $n$ is reachable from $l$. Therefore, $n$ is reachable from $a$, so $a$ is an ancestor of $n$, and so belongs in $L$.\n\\end{proof}\n\n\\begin{lemma}\nLet $L$ and $M$ be lineages of $T$, and $q \\in L \\cap M, q \\neq R$. Then $q$'s parent also belongs to $M \\cap L$.\n\\end{lemma}\n\\begin{proof}\nCall $p$ the parent of $q$. $p$ is an ancestor of $q$, and since $q$ belongs to $L$ (by hypothesis), $p$ belongs to $L$ by lemma \\ref{lem_ancestors_in_lineage}. By the same reasoning, $p$ belongs to $M$, therefore $p \\in L \\cap M$.\n\n\\end{proof}\n\n\n\\begin{prop}\n\\label{prop_lineage_intersection}\nLet $L$ and $M$ be lineages of $T$. Then $L \\cap M$ also forms a lineage.\n\\end{prop}\n\\begin{proof}\nLet $N = L \\cap M$. Because $N$ is a subset of a lineage (in fact it is a subset of at least two lineages, $L$ and $M$), its elements are ordered, so we can pick the last one and call it $n$. Now all other elements of $N$ are ancestors of $n$, so by lemma \\ref{lem_ancestors_in_lineage} they belong in $L$ and in $M$. So far we have proven \n\\end{proof}\n\n\\begin{prop}\nIn a rooted tree, you can always define a clade by specifying a single node: the clade consists of the specified node and all its descendants.\n\\end{prop}\n\n\\begin{prop}\nIn a rooted tree $T$ with unique labels and a node $n$ in $T$, it is always possible to choose two nodes $n_1$ and $n_2$ such that lca($n_1$,$n_2$) = $n$.\n\\end{prop}", "meta": {"hexsha": "efe192da512790308ea5c93310c8263dd5b936f9", "size": 6711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tree_properties.tex", "max_stars_repo_name": "Cactusolo/newick_utils", "max_stars_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2015-01-08T22:22:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:12:51.000Z", "max_issues_repo_path": "doc/tree_properties.tex", "max_issues_repo_name": "Cactusolo/newick_utils", "max_issues_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2015-01-22T19:34:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-27T10:53:41.000Z", "max_forks_repo_path": "doc/tree_properties.tex", "max_forks_repo_name": "Cactusolo/newick_utils", "max_forks_repo_head_hexsha": "da121155a977197cab9fbb15953ca1b40b11eb87", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-05-07T09:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T02:43:50.000Z", "avg_line_length": 68.4795918367, "max_line_length": 1041, "alphanum_fraction": 0.7042169572, "num_tokens": 2124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6289918552255076}}
{"text": "\\mychapter{8}{Lesson 8} %181019\n\n\\section{Domain extension}\n\nUp until now, encryption has been dealt with messages of fixed size around a polynomial function to $\\lambda$. How to deal with messages with arbitrary size? Setting a maximum bound to message length seems impractical, both for waste reasons when messages are too short, and for practicality when messages eventually get too long. The solution takes the form of a ``block-cipher'', where a message of a given size is split into equally-sized blocks, and then encrypted using a fixed-size encryption scheme. Various instances of this technique, called \\emph{modes}, have been devised.\n\n\\subsection{Electronic Codebook mode}\n\nThe operation of \\textsc{ecb}-mode is straightforward: Given a message split into blocks $(m_1, \\dots, m_t)$, apply the scheme's encryption routine to each block, as shown in figure \\ref{fig:ecb}:\n\\[\n    c_i = F_k(r) \\oplus m_i \\quad \\forall i \\in \\{0, \\dots, t\\}\n\\]\nDecryption is trivially implemented by \\textsc{xor}-ing the ciphered blocks with $F_k(r)$.\n\n\n\\begin{figure}[ht]\n    \\centering\n    \\begin{tikzpicture}[node distance = 12mm, >=latex']\n\n        \\path[->]\n            node (m1) {$m_1$}\n            node (x1) [right of = m1] {$\\oplus$}\n            node (c1) [below of = x1] {$c_1$}\n            node (f1) [box, above of = x1] {$f_k$}\n            node (r1) [above of = f1] {$r$}\n\n            node (m2) [right of = x1] {$m_2$}\n            node (x2) [right of = m2] {$\\oplus$}\n            node (c2) [below of = x2] {$c_2$}\n            node (f2) [box, above of = x2] {$f_k$}\n            node (r2) [above of = f2] {$r$}\n\n            node (xd) [right of = x2, node distance = 15mm] {$\\dots$}\n            node (cd) [right of = c2, node distance = 15mm] {$\\dots$}\n            node (fd) [right of = f2, node distance = 15mm] {$\\dots$}\n            node (rd) [right of = r2, node distance = 15mm] {$\\dots$}\n\n            node (mt) [right of = xd] {$m_t$}\n            node (xt) [right of = mt] {$\\oplus$}\n            node (ct) [below of = xt] {$c_t$}\n            node (ft) [box, above of = xt] {$f_k$}\n            node (rt) [above of = ft] {$r$}\n\n            (r1) edge (f1)\n            (r2) edge (f2)\n            (rt) edge (ft)\n\n            (f1) edge (x1)\n            (f2) edge (x2)\n            (ft) edge (xt)\n\n            (m1) edge (x1)\n            (m2) edge (x2)\n            (mt) edge (xt)\n            \n            (x1) edge (c1)\n            (x2) edge (c2)\n            (xt) edge (ct)\n        ;\n\n    \\end{tikzpicture}\n    \\caption{\\textsc{ecb}-mode block-cipher in action, using a \\prf{} as the encryption routine}\n    \\label{fig:ecb}\n\\end{figure}\n\nThis approach has the advantage of being completely parallelizable, as each block can clearly be encrypted separately; however there is a dangerous flaw in being not \\cpa-secure, even when using a \\prf-based encryption scheme. To understand why, observe that random nonces for ciphertext randomization are chosen per-message; this means the encryption of message blocks become deterministic in the message scope, enabling an adversary to attack the scheme within a single plaintext. It is sufficient to choose an all-0 or all-1 message to realize that all its blocks would encrypt to the same ciphered block.\n\n\\subsection{Cipher block chaining mode (\\textsc{cbc})}\n\n% AP190105: The explanation anticipates PRPs, which may be a problem. Should be reviewed at later times...\nThis mode serializes block encryption by using the preceding ciphered block in the formula:\n\\[\n    c_i = P_k(r) \\oplus m_i \\quad \\forall i \\in \\{0, \\dots, t\\}\n\\]\nThis time, a \\emph{pseudorandom permutation}(\\prp) is used instead of a \\prf; they will be discussed later on. The diagram in figure \\ref{fig:cbc} shows a general view of \\textsc{cbc}-mode's operation. The decryption process is analogous but in a reversed fashion, by computing the preimage of a ciphered block and \\textsc{xor}-ing it with the preceding ciphered block:\n\\[\n    m_i = P_k^{-1}(c_i) \\oplus c_{i-1}\n\\]\n\n\\begin{figure}[ht]\n    \\centering\n    \\begin{tikzpicture}[node distance = 12mm, > = latex']\n\n        \\draw[->]\n            node (r) {$r$}\n            node (c0) [below of = r, node distance = 24mm] {$c_0$}\n\n            node (c1) [right of = c0, node distance = 24mm] {$c_1$}\n            node (p1) [box, above of = c1] {$P_k$}\n            node (x1) [above of = p1] {$\\oplus$}\n            node (m1) [above of = x1] {$m_1$}\n            \n            node (c2) [right of = c1, node distance = 24mm] {$c_2$}\n            node (p2) [box, above of = c2] {$P_k$}\n            node (x2) [above of = p2] {$\\oplus$}\n            node (m2) [above of = x2] {$m_2$}\n\n            node (cd) [right of = c2, node distance = 24mm] {$\\dots$}\n            node (pd) [above of = cd] {$\\dots$}\n            node (xd) [above of = pd] {$\\dots$}\n            node (md) [above of = xd] {$\\dots$}\n\n            node (ct) [right of = cd, node distance = 24mm] {$c_t$}\n            node (pt) [box, above of = ct] {$P_k$}\n            node (xt) [above of = pt] {$\\oplus$}\n            node (mt) [above of = xt] {$m_t$}\n            \n            (r) edge (c0)\n\n            (m1) edge (x1)\n            (m2) edge (x2)\n            (mt) edge (xt)\n\n            (x1) edge (p1)\n            (x2) edge (p2)\n            (xt) edge (pt)\n\n            (p1) edge (c1)\n            (p2) edge (c2)\n            (pt) edge (ct)\n\n            (c0) -| +(12mm, 24mm) edge (x1)\n            (c1) -| +(12mm, 24mm) edge (x2)\n            (c2) -| +(12mm, 24mm) edge (xd)\n            (cd) -| +(12mm, 24mm) -- (xt)\n        ;\n\n    \\end{tikzpicture}\n    \\caption{\\textsc{cbc}-mode block-cipher in action, using a \\prp{} as the encryption routine}\n    \\label{fig:cbc}\n\\end{figure}\n\n\\subsection{Counter mode}\n\nAlso denoted as \\textsc{ctr} in short, this mode closely resembles \\textsc{ecb}-mode but uses a ``rolling'' nonce instead of a static one, as shown in figure \\ref{fig:ctr}. At each successive block, the nonce is incremented by 1 and then used in a single block encryption. Since the nonce is in $\\binary^n$, the increment is done modulo $2^n$ so that the value will wrap around to 0 if it ever overflows. Decryption is analogous.\n\n\\begin{figure}[ht]\n    \\centering\n\n    \\begin{tikzpicture}[node distance = 12mm, > = latex']\n\n        \\draw[->]\n            node (c0) {$c_0$}\n\n            node (c1) [right of = c0, node distance = 24mm] {$c_1$}\n            node (x1) [above of = c1] {$\\oplus$}\n            node (m1) [left of = x1] {$m_1$}\n            node (f1) [box, above of = x1] {$f_k$}\n            node (r1) [above of = f1] {$r$}\n\n            node (c2) [right of = c1, node distance = 24mm] {$c_2$}\n            node (x2) [above of = c2] {$\\oplus$}\n            node (m2) [left of = x2] {$m_2$}\n            node (f2) [box, above of = x2] {$f_k$}\n            node (r2) [above of = f2] {$r + 1$}\n\n            node (cd) [right of = c2, node distance = 19mm] {$\\dots$}\n            node (xd) [above of = cd] {$\\dots$}\n            node (fd) [above of = xd] {$\\dots$}\n            node (rd) [above of = fd] {$\\dots$}\n\n            node (ct) [right of = cd, node distance = 24mm] {$c_t$}\n            node (xt) [above of = ct] {$\\oplus$}\n            node (mt) [left of = xt] {$m_t$}\n            node (ft) [box, above of = xt] {$f_k$}\n            node (rt) [above of = ft] {$r + t - 1$}\n            \n            (r1) edge (r2)\n            (r2) edge (rd)\n            (rd) edge (rt)\n\n            (r1) edge (f1)\n            (r2) edge (f2)\n            (rt) edge (ft)\n\n            (f1) edge (x1)\n            (f2) edge (x2)\n            (ft) edge (xt)\n            \n            (m1) edge (x1)\n            (m2) edge (x2)\n            (mt) edge (xt)\n\n            (x1) edge (c1)\n            (x2) edge (c2)\n            (xt) edge (ct)\n\n            (r1) -| (c0)\n        ;\n\n    \\end{tikzpicture}\n    \\caption{Counter-mode block-cipher in action, using a \\prf{} as the encryption routine}\n    \\label{fig:ctr}\n\\end{figure}\n\nThis apparently innocuous change to \\textsc{ebc} is enough to ensure \\cpa-security, at the cost of perfect parallelization.\n\n\\begin{theorem}\n    Assume $f_k$ is a \\prf, then the counter-mode block cipher is \\cpa-secure for variable length messages\\footnotemark.\n\\end{theorem}\n\\footnotetext{\\emph{Variable length messages} exactly means every message $m = (m_1, \\dots, m_t)$ is made of $t$ blocks, and $t$ can change from any message to a different one.}\n\n\\begin{proof}\n    Figure \\ref{cryptogame:ctrcpa} models a \\cpa{} attack to a counter-mode block-cipher. The proof will proceed by hybrid argument starting from this game, therefore the statement to verify will be $\\cryptog{cpa}[\\textsc{ctr}](\\lambda, 0) \\compindist \\cryptog{cpa}[\\textsc{ctr}](\\lambda, 1)$.\n\n    \\begin{cryptogame}\n        {ctrcpa}\n        {A chosen-plaintext attack to counter-mode block-cipher}\n        {cpa}\n        \n        \\cseqbeginloop\n\n        \\send{}{$m = (m_1, \\dots, m_t)$}{}\n        \\receive{\\shortstack[l]{\n            $r = c_0 \\pickUAR \\binary^n$ \\\\\n            $c_i = f_k(r + i - 1) \\oplus m_i \\quad \\forall i$\n        }}\n        {$c = (c_0, c_1, \\dots, c_t)$}{}\n\n        \\cseqendloop\n\n        \\cseqdelay\n        \n        \\send{$|\\mu_0| = |\\mu_1| \\in \\mathcal{M}$}{$\\mu_0, \\mu_1$}{}\n        \\receive{\\shortstack[l]{\n            $\\rho = \\gamma_0 \\pickUAR \\binary^n$ \\\\\n            $b \\pickUAR \\binary$ \\\\\n            $(\\gamma_b)_i = f_k(\\rho + i - 1) \\oplus (\\mu_b)_i \\quad \\forall i$\n        }}\n        {$\\gamma_b = (\\gamma_0, \\gamma_1, \\dots, \\gamma_t)$}{}\n\n        \\cseqdelay\n        \n        \\cseqbeginloop\n\n        \\send{}{$m = (m_1, \\dots, m_t)$}{}\n        \\receive{\\shortstack[l]{\n            $r = c_0 \\pickUAR \\binary^n$ \\\\\n            $c_i = f_k(r + i - 1) \\oplus m_i \\quad \\forall i$\n        }}\n        {$c = (c_0, c_1, \\dots, c_t)$}{}\n\n        \\cseqendloop\n\n        \\cseqdelay\n        \n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptogame}\n\n    Define the two hybrid games from the original \\cpa{} game as follows:\n\n    \\begin{itemize}\n        \\item $\\hybridg{1}[\\textsc{ctr}](\\lambda, b)$: A random function $R$ is chosen \\uar{} from $\\mathfrak{R}(n, n)$ at the beginning of the game, and is used in place of $F_k$ in all block encryptions;\n        \\item $\\hybridg{2}[\\textsc{ctr}](\\lambda, b)$: The challenger will pick random values from $\\binary^n$ as ciphered blocks, disregarding any encryption routine.\n    \\end{itemize}\n\n    \\begin{lemma}\n        $\\cryptog{cpa}[\\textsc{ctr}](\\lambda, b) \\compindist \\hybridg{1}[\\textsc{ctr}](\\lambda, b) \\quad \\forall b \\in \\binary$\n    \\end{lemma}\n\n    \\begin{proof} The proof is left as exercise.\n        \n        \\emph{Hint}: Since the original game and the first hybrid are very similar, we can use a distinguisher which plays the \\cpa-game; since this is a lemma, our goal in the reduction is to break the precondition contained in the theorem statement.\n    \\end{proof}\n\n    \\begin{lemma}\n        $\\hybridg{1}[\\textsc{ctr}](\\lambda, b) \\compindist \\hybridg{2}[\\textsc{ctr}](\\lambda, b) \\quad \\forall b \\in \\binary$\n    \\end{lemma}\n\n    \\begin{proof}\n    \n        Since $m_i$ doesn't affect the distribution of the result at all, for any $i$, if $R(r^{*})$ behaves like a true random extractor, then the two hybrids are indistinguishable in the general case ($R(r + i) \\oplus m_i \\approx R(r + i)$). However, there is a sneaky issue: if in both games it happens that a given nonce $r_i$ is used in both one query encryption and the challenge message encryption at any step, the subsequent encrypted blocks will be completely random in the second hybrid, whereas in the first hybrid the function's images, albeit random, become predictable, enabling a \\cpa.\n\n        Nevertheless, it can be proved that these ``collisions'' happen with negligible probability within $\\hybridg{1}[\\textsc{ctr}]$. Let:\n        \\begin{itemize}\n            \\item $q$ = number of encryption queries in a game run\n            \\item $t_i$ = number of blocks for the $i$-th query\n            \\item $\\tau$ = number of blocks for the challenge ciphertext\n            \\item \\textsc{Overlap} event: $\\exists i, j, \\iota : r_i + j = \\rho + \\iota$\n        \\end{itemize}\n\n        The \\textsc{Overlap} event exactly models our problematic scenario. Now it suffices to show that it occurs negligibly. For simplicity, assume the involved messages are of the same length, that is $t_i = \\tau =: t$. Denote with $\\textsc{Overlap}_i$ to be the event that the $i$-th query overlaps the challenge sequence as specified above.\n\n        Fix some $\\rho$. One can see that $\\textsc{Overlap}_i$ happens if:\n        \\[\n            \\rho - t + 1 \\leq r_i \\leq \\rho + t - 1\n        \\]\n        which means that $r_i$ should be chosen \\emph{at least} in a way that:\n        \\begin{itemize}\n            \\item the sequence $\\rho, \\dots, \\rho + t - 1$ comes before the sequence $r_i, \\dots, r_i + t - 1$, and they overlap just for the last element $\\rho + t - 1 = r_i$ or\n            \\item the sequence $r_i, \\dots, r_i + t - 1$ comes before the sequence the sequence $\\rho, \\dots, \\rho + t - 1$, and they overlap just for the last element $r_i + t - 1 = \\rho$.\n        \\end{itemize}\n\n        Then:\n\n        \\begin{align*}\n            \\Pr[\\textsc{Overlap}_i] &= \\frac{(\\rho + t - 1) - (\\rho - t + 1) + 1}{2^n} \\\\\n            &= \\frac{2t-1}{2^n} \\\\\n            \\Pr[\\textsc{Overlap}] &\\leq \\sum_{i = 1}^{t} \\Pr[\\textsc{Overlap}_i] \\\\\n            &\\leq 2 \\frac{t^2}{2^n} \\in \\negl{\\lambda} \n        \\end{align*}\n            \n        which proves that our collision scenario happens with negligible probability, thus the two hybrids are indistinguishable.\n\n    \\end{proof}\n    \n    Having proven the indistinguishability between the hybrids, the conclusion is reached:\n    \\[\n        \\cryptog{cpa}[\\textsc{ctr}](\\lambda, 0) \\compindist \\cryptog{cpa}[\\textsc{ctr}](\\lambda, 1)\n    \\]\n    \n\\end{proof}\n", "meta": {"hexsha": "ac91ad7f39e228e45a8478bee1ef698736a7da05", "size": 13812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_8.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_8.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_8.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": 43.9872611465, "max_line_length": 608, "alphanum_fraction": 0.5728352158, "num_tokens": 4305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6289918475645588}}
{"text": "% Preamble.\n\\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%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{21}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-06-24}\n\n\\title{\\vspace{-2\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n% Macros.\n%% Contextualized by input/output bases.\n\\newcommand{\\based}[3]{{\\{#1\\}}_{#2}^{#3}}\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\begin{equation*}\n\tA = \\begin{pmatrix} 5 & 1 \\\\ 1 & 5 \\end{pmatrix}\n\\end{equation*}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Let}\n\t\\begin{equation*}\n\t\t\\vec{a} = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}, \\quad\n\t\t\\vec{b} = \\begin{pmatrix} 2 \\\\ 2 \\end{pmatrix}, \\quad\n\t\t\\vec{c} = \\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix},\\quad\n\t\t\\vec{d} = \\begin{pmatrix} 5 \\\\ -5 \\end{pmatrix},\\quad\n\t\t\\vec{e} = \\begin{pmatrix} 10 \\\\ 0 \\end{pmatrix}.\n\t\\end{equation*}\n\t\\textit{Which are eigenvectors of $A$? Find their corresponding\n\teigenvalues.} \\\\[\\baselineskip]\n\tFor a square matrix $A$, a vector $\\vec{v}$ is an eigenvector of $A$ if\n\tthere is a scalar $\\lambda$ such that $A\\vec{v} = \\lambda \\vec{v}$.\n\t\\\\[\\baselineskip]\n\tFor $\\vec{a} = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}$,\n\t\\begin{equation*}\n\t\tA \\vec{a}\n\t\t=\n\t\t\\begin{pmatrix} 5 & 1 \\\\ 1 & 5 \\end{pmatrix}\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 6 \\\\ 6 \\end{pmatrix}\n\t\t=\n\t\t6\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t6 \\vec{a}\n\t\t.\n\t\\end{equation*}\n\tThus, $\\vec{a}$ is an eigenvector of $A$ with a corresponding eigenvalue\n\tof \\boxed{6}.\n\t\\\\[\\baselineskip]\n\tFor $\\vec{b} = \\begin{pmatrix} 2 \\\\ 2 \\end{pmatrix}$,\n\t\\begin{equation*}\n\t\t\\vec{b} = 2 \\vec{a}\n\t\t.\n\t\\end{equation*}\n\tBecause $\\vec{b}$ is a scalar multiple of $\\vec{a}$, an eigenvector of\n\t$A$, $\\vec{b}$ is also an eigenvector of $A$. Furthermore, $\\vec{b}$\n\tshares $\\vec{a}$'s corresponding eigenvalue of \\boxed{6}.\n\t\\\\[\\baselineskip]\n\tFor $\\vec{c} = \\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix}$,\n\t\\begin{equation*}\n\t\tA \\vec{c}\n\t\t=\n\t\t\\begin{pmatrix} 5 & 1 \\\\ 1 & 5 \\end{pmatrix}\n\t\t\\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} -4 \\\\ 4 \\end{pmatrix}\n\t\t=\n\t\t4\n\t\t\\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t4 \\vec{c}\n\t\t.\n\t\\end{equation*}\n\tThus, $\\vec{c}$ is an eigenvector of $A$ with a corresponding eigenvalue\n\tof \\boxed{4}.\n\t\\\\[\\baselineskip]\n\tFor $\\vec{d} = \\begin{pmatrix} 5 \\\\ -5 \\end{pmatrix}$,\n\t\\begin{equation*}\n\t\t\\vec{d} = -5 \\vec{c}\n\t\t.\n\t\\end{equation*}\n\tBecause $\\vec{d}$ is a scalar multiple of $\\vec{c}$, an eigenvector of\n\t$A$, $\\vec{d}$ is also an eigenvector of $A$. Furthermore, $\\vec{d}$\n\tshares $\\vec{c}$'s corresponding eigenvalue of \\boxed{4}.\n\t\\\\[\\baselineskip]\n\tFor $\\vec{e} = \\begin{pmatrix} 10 \\\\ 0 \\end{pmatrix}$,\n\t\\begin{equation*}\n\t\tA \\vec{e}\n\t\t=\n\t\t\\begin{pmatrix} 5 & 1 \\\\ 1 & 5 \\end{pmatrix}\n\t\t\\begin{pmatrix} 10 \\\\ 0 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 50 \\\\ 10 \\end{pmatrix}\n\t\t\\neq\n\t\t\\lambda\n\t\t\\begin{pmatrix} 10 \\\\ 0 \\end{pmatrix}\n\t\t\\text{ for any $\\lambda$.}\n\t\\end{equation*}\n\tThus, $\\vec{e}$ is not an eigenvector of $A$.\n\t\n\t\\item \\textit{Let $\\mathcal{S}$ be the standard basis, and let}\n\t\\begin{equation*}\n\t\t\\based{T}{\\mathcal{S}}{\\mathcal{S}} = A.\n\t\\end{equation*}\n\t\\textit{Find a basis $\\mathcal{B}$ made of the eigenvectors of $A$, and\n\tfind $\\based{T}{\\mathcal{B}}{\\mathcal{B}}$.} \\\\[\\baselineskip]\n\tLet\n\t\\begin{equation*}\n\t\t\\mathcal{B}\n\t\t=\n\t\t\\left\\{\n\t\t\t\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix},\n\t\t\t\\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix}\n\t\t\\right\\}\n\t\t.\n\t\\end{equation*}\n\tUsing $\\mathcal{B}$,\n\t\\begin{align*}\n\t\t\\based{T}{\\mathcal{B}}{\\mathcal{B}}\n\t\t&=\n\t\t\\based{T}{\\mathcal{S}}{\\mathcal{B}}\n\t\t\\based{T}{\\mathcal{S}}{\\mathcal{S}}\n\t\t\\based{I}{\\mathcal{B}}{\\mathcal{S}}\n\t\t\\\\\n\t\t&=\n\t\t\\begin{pmatrix}\n\t\t\t\\frac{1}{2} & \\frac{1}{2} \\\\\n\t\t\t-\\frac{1}{2} & \\frac{1}{2}\n\t\t\\end{pmatrix}\n\t\t\\begin{pmatrix} 5 & 1 \\\\ 1 & 5 \\end{pmatrix}\n\t\t\\begin{pmatrix} 1 & -1 \\\\ 1 & 1 \\end{pmatrix}\n\t\t\\\\\n\t\t&=\n\t\t\\boxed{\n\t\t\t\\begin{pmatrix} 6 & 0 \\\\ 0 & 4 \\end{pmatrix}\n\t\t}\n\t\t.\n\t\\end{align*}\n\tNote the diagonal elements of $\\based{T}{\\mathcal{B}}{\\mathcal{B}}$ are\n\tthe eigenvalues of $A$.\n\\end{enumerate}\n\\newpage\n\n\\section*{2.}\n\\textit{Suppose that $A$ is a $3 \\times 4$ matrix.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Is it possible that $\\text{dim}(\\text{nul}(A)) = 0$?}\n\t\\\\[\\baselineskip]\n\t\\boxed{\\text{No.}} By the rank-nullity theorem,\n\t\\begin{equation*}\n\t\t\\text{rank}(A) + \\text{nullity}(A) = \\text{dim}(\\text{domain}(A))\n\t\t.\n\t\\end{equation*}\n\tThe dimension of the domain of $A$ is $4$, because $A$ has $4$ columns. \\\\\n\tThe rank of $A$ is at maximum 3, because $A$ is a $3 \\times 4$ matrix. \\\\\n\tAs a result of this, the nullity of $A$ must be at least $1$.\n\t\n\t\\item \\textit{If $\\text{dim}(\\text{nul}(A)) = 1$, what can you say about\n\t$\\text{col}(A)$?} \\\\[\\baselineskip]\n\t\\boxed{\\text{dim}(\\text{col}(A)) = \\text{rank}(A) = 4 - 1 = 3.}\n\n\t\\item \\textit{If $\\text{dim}(\\text{nul}(A)) = 2$, what can you say about\n\t$\\text{col}(A)$?} \\\\[\\baselineskip]\n\t\\boxed{\\text{dim}(\\text{col}(A)) = \\text{rank}(A) = 4 - 2 = 2.}\n\t\n\t\\item \\textit{If $\\text{dim}(\\text{nul}(A)) = 3$, what can you say about\n\t$\\text{col}(A)$?} \\\\[\\baselineskip]\n\t\\boxed{\\text{dim}(\\text{col}(A)) = \\text{rank}(A) = 4 - 3 = 1.}\n\t\n\t\\item \\textit{If $\\text{dim}(\\text{nul}(A)) = 4$, what can you say about\n\t$\\text{col}(A)$?} \\\\[\\baselineskip]\n\t\\boxed{\\text{dim}(\\text{col}(A)) = \\text{rank}(A) = 4 - 4 = 0.}\n\\end{enumerate}\n\\newpage\n\n\\section*{3.}\n\\textit{Let}\n\\begin{equation*}\n\tA = \\begin{pmatrix} 8 & -10 \\\\ 5 & -7 \\end{pmatrix},\n\t\\qquad\n\t\\vec{v}_1 = \\begin{pmatrix} 2 \\\\ 1 \\end{pmatrix}, \\quad\n\t\\vec{v}_2 = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}.\n\\end{equation*}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Show that the vectors $\\vec{v}_1$ and $\\vec{v}_2$ are\n\teigenvectors of $A$ and find their associated eigenvalues.}\n\t\\begin{gather*}\n\t\tA \\vec{v}_1\n\t\t=\n\t\t\\begin{pmatrix} 8 & -10 \\\\ 5 & -7 \\end{pmatrix}\n\t\t\\begin{pmatrix} 2 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} 6 \\\\ 3 \\end{pmatrix}\n\t\t=\n\t\t3 \\begin{pmatrix} 2 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t3 \\vec{v}_1\n\t\t, \\\\\n\t\tA \\vec{v}_2\n\t\t=\n\t\t\\begin{pmatrix} 8 & -10 \\\\ 5 & -7 \\end{pmatrix}\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} -2 \\\\ -2 \\end{pmatrix}\n\t\t=\n\t\t-2 \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\n\t\t=\n\t\t-2 \\vec{v}_2\n\t\t.\n\t\\end{gather*}\n\tThus, $\\boxed{\\lambda_1 = 3}, \\boxed{\\lambda_2 = -2}$.\n\t\n\t\\item \\textit{Express the vector}\n\t\\begin{equation*}\n\t\t\\vec{x} = \\begin{pmatrix} -4 \\\\ -1 \\end{pmatrix}\n\t\\end{equation*}\n\t\\textit{as a linear combination of $\\vec{v}_1$ and $\\vec{v}_2$.}\n\t\\\\[\\baselineskip]\n\tSolving\n\t\\begin{equation*}\n\t\t\\begin{pmatrix} 2 & 1 \\\\ 1 & 1 \\end{pmatrix}\n\t\t\\begin{pmatrix} a \\\\ b \\end{pmatrix}\n\t\t=\n\t\t\\begin{pmatrix} -4 \\\\ -1 \\end{pmatrix}\n\t\t,\n\t\\end{equation*}\n\t$a = -3$, and $b = 2$. \\\\\n\tThus,\n\t\\begin{equation*}\n\t\t\\boxed{\n\t\t\t\\vec{x}\n\t\t\t=\n\t\t\t-3 \\vec{v}_1 + 2 \\vec{v}_2\n\t\t}\n\t\t.\n\t\\end{equation*}\n\\end{enumerate}\n\\newpage\n\n\\section*{Extra.}\n\\textit{Consider the Fibonacci sequence and the following:}\n\\begin{equation*}\n\t\\begin{pmatrix} 0 & 1 \\\\ 1 & 1 \\end{pmatrix}\n\t\\begin{pmatrix} 2 \\\\ 3 \\end{pmatrix}\n\t=\n\t\\begin{pmatrix} 3 \\\\ 5 \\end{pmatrix}\n\t, \\quad\n\t\\begin{pmatrix} 0 & 1 \\\\ 1 & 1 \\end{pmatrix}\n\t\\begin{pmatrix} 3 \\\\ 5 \\end{pmatrix}\n\t=\n\t\\begin{pmatrix} 5 \\\\ 8 \\end{pmatrix}\n\t.\n\\end{equation*}\n\\textit{Find the 1000th Fibonacci number.} \\\\[\\baselineskip]\nLet $0$ be the $0$th Fibonacci number.\n\\begin{equation*}\n\t\\begin{pmatrix} 0 & 1 \\\\ 1 & 1 \\end{pmatrix}^n\n\t\\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\tn\\text{th Fibonacci number} \\\\\n\t\t(n+1)\\text{th Fibonacci number}\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\nThus, let\n\\begin{equation*}\n\t\\begin{pmatrix} 0 & 1 \\\\ 1 & 1 \\end{pmatrix}^n\n\t\\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}\n\t=\n\t\\begin{pmatrix}\n\t\ta \\\\\n\t\t\\_\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n\\boxed{a} is the 1000th Fibonacci number.\n\n\n\\end{document}", "meta": {"hexsha": "10c4540ccf22455bf8e4aee865fad80aae49f493", "size": 8073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw21/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/hw21/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/hw21/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": 27.0, "max_line_length": 75, "alphanum_fraction": 0.6070853462, "num_tokens": 3512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6289918456973828}}
{"text": "\\subsection{Heuristic approach}\nA heuristic method has been developed basing on imitating the visual selection of L-shapes (see figure)\n\\begin{itemize}\n\\item Overimpose a $3\\times 3$ grid on the scatterplot.\n\\item Score points on each subgrid in such a way that\n\\begin{itemize}\n\t\\item Points in permitted regions increase score\n\t\\item Points in non-desired regions decrease score\n\t\\item Points in non-allowed regions set score to $\\-infty$.\n\\end{itemize}\n\\item Use cross-validation to tune scoring parameters.\n\\end{itemize}\n\n\\subsection{The Naive method}\n\nTraditionally selection has been based on searching for genes with negative correlation betweem expression and correlation. This ``Naïve approach\" is used to compare with other approaches.\n", "meta": {"hexsha": "1a7c22a74f4a9476e340cf13c1286aac6a2c9e34", "size": 745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/methods3.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/methods3.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/methods3.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": 43.8235294118, "max_line_length": 188, "alphanum_fraction": 0.7973154362, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6289626887611128}}
{"text": "\\documentclass[]{article}\n\n%opening\n\\title{MTH 343 Numerical Analysis: Lecture 12}\n\\author{Sheikh Abdul Raheem Ali}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Interpolation}\n\n\t\\begin{enumerate}\n\t\t\\item Solving Systems of Equations\n\t\t\\item Lagrange Polynomials\n\t\\end{enumerate}\n\n\\begin{tabular}{c c}\n\t$ x_i $ & $ f_i $ \\\\\n\t$ x_0 $ & $ f_0 $ \\\\\n\t$ x_1 $ & $ f_1 $ \\\\\n\t$ x_2 $ & $ f_2 $ \n\\end{tabular}\n\n\\[ P_2(x) = \\frac{(x-x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)}f_0 + \\frac{(x-x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)}f_1 + \\frac{(x-x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)}f_2 \\]\n\n\n\\begin{tabular}{c c}\n\t$ x_i $ & $ f_i $ \\\\\n\t$ 0 $ & $ 1 $ \\\\\n\t$ -1 $ & $ 2 $ \\\\\n\t$ 2 $ & $ 3 $ \n\\end{tabular}\n\n\\[  P_2(x) = \\frac{(x+1)(x - 2)}{(0 + 1)(0 - 2)} + \\frac{(x-0)(x - 2)}{(-1 - 0)(-1 - 2)}2 + \\frac{(x-0)(x + 1)}{(2 - 0)(2 + 1)}3 \\]\n\n$ P_n(x) = \\sum_{0}^{n}L_{n,i}f(x_i) $\n\n\\section*{Lagrange Polynomial Error Function}\n\n\\[ E(x) = |f(x) - P_n(x)| = \\frac{|(x-x_0)(x-x_1)\\dots(x-x_n)f^{n+1}(\\xi)|}{(n+1)!}  \\]\n\nWhere $ \\xi  $ is the element in the smallest interval containing $ x_0,x_1,\\dots,x_n $\n\n\\end{document}\n", "meta": {"hexsha": "944b9cbd0515f71c94d11adb9bae4ddf88441862", "size": 1096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Numerical/Lecture_12/Lecture12.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_12/Lecture12.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_12/Lecture12.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": 23.8260869565, "max_line_length": 171, "alphanum_fraction": 0.5346715328, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403177, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6289162659133477}}
{"text": "%!TEX root = main.tex\n\\section{Simulation setup}\n\\subsection{Variance reduction}\nBecause the simulation can be time consuming to run, we want to lower the variance of the estimated parameters as much as possible relative to the computational resources used.\n\n\\subsubsection{Control Variates}\nControl variates is a variance reduction technique which can be used to reduce the variance of the estimated expected value $\\hat{\\mu} = \\mathbb{E}[Y]$. It works by drawing/calculating a variable $X_i$ such that $Y_i \\approx f(X_i)$. One can then estimate $\\hat{\\mu} = \\mathbb{E}[Z]$ where $Z$ is given by:\n\\begin{align}\nZ_i = Y_i - c (X_i - \\mathbb{E}[X])\n\\end{align}\n\nChoosing $c = \\frac{Cov(X, Y)}{Var(X)}$ gives the largest variance reduction of:\n\\begin{equation}\n\\frac{Var[Z]}{Var[Y]} = \\frac{Var[Y]}{Var[Y]} - \\frac{Cov(X, Y)^2}{Var[X] Var[Y]} = 1 - \\rho_{x, y}^2 \\label{eq:variance-reduction}\n\\end{equation}\n\nIn our case there is no analytical expression for the covariance or variance of the random variables. Instead $c$ is estimated from the dataset itself. This introduces some overfitting, thus one should take care to reduce the degrees of freedom in the variance, covariance estimates:\n\\begin{equation}\n\\hat{c} = \\frac{Cov_{N-1}(X, Y)}{Var_{N-1}(X)}, \\quad \\hat{\\sigma}^2 = Var_{N-2}(Z)\n\\end{equation}\n\nThe subscript denotes the degrees of freedom, and $\\hat{\\sigma}^2$ has $N - 2$ degrees of freedom, because $\\hat{c}$ is estimated from the dataset.\n\n\\subsubsection{Estimating infection rate}\n\nFrom \\eqref{eq:variance-reduction} it seen that to get a high variance reduction, $X_i$ just need to be heavily correlated with $Y_i$. In our case we would like to estimate the infection peak time and how many people where infected at the peak. From the theoretical differential equation model those values should be correlated with the infection rate $\\beta$.\n\nAssuming the stochastic model have a behaviour somewhat similar to the differential equation model, there exists a fairly simple method for estimating $\\beta$ and $\\gamma$ \\cite{wiki-sir}.\n\\begin{equation}\n\\gamma = \\frac{R'_{max}}{I_{max}} \\text{ and } \\beta = -\\frac{\\ln(p)}{1 - p} \\gamma \\quad \\text{where: } p = \\frac{N - R_\\infty}{N} \n\\end{equation}\n\n$R'_{max}$ is the maximum removed difference, and $I_{max}$ is the maximum infected. Due to the construction of the differential equation, these are found at the same time $t$. $R_\\infty$ is how many people where removed in the end, thus $p$ is the survival rate.\n\n\\subsection{Effect of Global Events}\nWe want to estimate what effect a global event can have on a virus outbreak. We define an event $e$ as simply being a transfer of people from one or more regions $r_{i}$ to region $r_t$ at a time $t_0$, and the reverse transfer of people from $r_t$ to $r_{i}$ at time $t_1$.\n\n\\subsubsection{Motivation: Zika virus}\nRecently, a new virus has been observed in South and Latin America. The Zika virus affects pregnant women's fetuses and can cause serious birth defects. The Zika virus is primarily spread by mosquitoes, but can also spread from a man to his sex partners (and from mother to fetus). Some political discussions have been made as to whether or not the Olympic Games should be canceled to prevent the spreading of the virus.\n\nIn this report we will run a \"hypothetical\" simulation, showing how the a virus could spread assuming inter-human infections. As such this simulation is primarily an attempt of showing how such a model would work and not a realistic Zika virus predictor.\n\n\\subsubsection{Event definition: Olympic Games in Rio 2016}\nIn our simulation we define the Olympic Games to take place during $t_0=$ `2016-07-03' and $t_1=$ `2016-07-21'. According to The Gaurdian \\cite{theguardian-olympics} Rio expects to recieve 380,000 tourist. We choose to transfer people from all over the world to Rio, such that the transfer is proportional to the population size of each region:\n\n\\begin{align}\n\t\\text{Transfer}_0(i, j) &= 380000 \\cdot \\frac{\\text{population}_i}{N} \\\\\n\t\\text{Transfer}_1(j, i) &= \\text{transfer}_0(i, j)\n\\end{align}\n\nwhere $\\text{Transfer}_0(i, j)$ denotes the number of people transferred from region $i$ to region $j$ at the start of the Olympics and $ \\text{Transfer}_1(j, i) $ the people transferred from $j$ to $i$ at the end of the Olympics.\n", "meta": {"hexsha": "e183cf4895e7065f8c07bde2206f68189b825f1e", "size": 4303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/simulation.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/simulation.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/simulation.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": 82.75, "max_line_length": 420, "alphanum_fraction": 0.747153149, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403176, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6289162659133476}}
{"text": "%Note for this test case:\n%Simple water flow example using ANUGA: Water flowing down a channel.\n%It was called \"steep_slope\" in an old validation test.\n\n\n\\section{Shallow flow down a mild slope}\nThis case simulates very shallow flow running down a mild slope topography. It represents an idealisation of the rainfall-runoff problem, which will often involve very shallow flows down such a topography. This case has an analytical solution, and in particular, we consider the steady-uniform solution with the values of bed slope and friction slope are the same.   \n\nSuppose that we are given a one dimensional domain. The steady state conditions with a contant water depth everywhere make the shallow water equations to the single identity\n\\begin{equation}\nz_x = - S_f, \n\\end{equation}\nwhere $z_x$ is the bed slope, and $S_f$ is the symbol for the force of bottom friction.  We take Manning's friction\n\\begin{equation}\nS_f = n^2 \\frac{q|q|}{h^{10/3}}\n\\end{equation}\nwhere $n$ is the Manning's coefficient and $q$ is the discharge $uh$. \nIf $q$, $n$, and $z_x$ are given, then the analytical solution for $u$ and $h$ is\n\\begin{equation}\nu(x)= \\left[- n^{-2} q^{4/3} z_x\\right]^{3/10},\n\\end{equation}\n\\begin{equation}\nh(x)= \\frac{q}{u}\\,.\n\\end{equation}\n\n\\subsection{Results}\nFor our test, we consider a square dimensional domain with length and width 100. We take $q=0.2$, $n=0.03$, and $z_x=-0.1$.\nThe topography is\n\\begin{equation}\nz(x, y)= -0.1 x\\,.\n\\end{equation}\nThe initial condition is $u=v=0$ and\n\\begin{equation}\nw(x,y,0)= -0.1 x + 0.01\\,.\n\\end{equation}\n\n\nSome simulation results are as follows.\nFigures~\\ref{fig:depthdownchan} shows the steady state depth in the downstream direction. \nThere should be a good agreement with the analytical solution, at least away from the boundaries. \n\nFigures~\\ref{fig:depthacrosschan} shows the steady state depth across the slope around the line x = 50m. \nThere should be a good agreement with the analytical solution, at least away from the boundaries. \n\nFigures~\\ref{fig:xvelscrosschan} and~\\ref{fig:yvelscroschan} show the steady state $x$- and $y$-velocities, along a slice in the cross slope direction (near $x=50$). The $x$-velocities should agree well with the analytical solution, and the $y$-velocities should be zero. \n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{depth_x.png}\n\\caption{Depth in the downstream direction}\n\\label{fig:depthdownchan}\n\\end{center}\n\\end{figure}\n \n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{depth_y.png}\n\\caption{Depth across the slope around $x$ = 50m}\n\\label{fig:depthacrosschan}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{x_velocity.png}\n\\caption{$x$-velocity along the cross-section $x=50$ (i.e. a cross-section with constant bed elevation)}\n\\label{fig:xvelscrosschan}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{y_velocity.png}\n\\caption{$y$-velocity along the cross-section $x=50$ (i.e. a cross-section with constant bed elevation)}\n\\label{fig:yvelscroschan}\n\\end{center}\n\\end{figure}\n\n\n\\endinput\n", "meta": {"hexsha": "6621bb067a966f6f4b7f1b43bbc19c807f89e738", "size": 3135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/rundown_mild_slope/results.tex", "max_stars_repo_name": "samcom12/anuga_core", "max_stars_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_stars_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_stars_count": 136, "max_stars_repo_stars_event_min_datetime": "2015-05-07T05:47:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T03:07:40.000Z", "max_issues_repo_path": "validation_tests/analytical_exact/rundown_mild_slope/results.tex", "max_issues_repo_name": "samcom12/anuga_core", "max_issues_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_issues_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-05-03T09:27:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T04:22:48.000Z", "max_forks_repo_path": "validation_tests/analytical_exact/rundown_mild_slope/results.tex", "max_forks_repo_name": "samcom12/anuga_core", "max_forks_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_forks_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-03-18T07:35:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T07:07:29.000Z", "avg_line_length": 38.7037037037, "max_line_length": 367, "alphanum_fraction": 0.7499202552, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6289162640220385}}
{"text": "% !TEX root = ../thesis.tex\n\n\\chapter{Preliminaries}\n\\label{chap:preliminaries}\nThere are several topological spaces that play a key role\nwhen describing properties of the Hopf map $h : S^3 \\to S^2\\!$.\nThese include of course the domain $S^3$ and codomain $S^2\\!$,\nwhich are traditionally defined as subspaces of $\\R^4$ and $\\R^3$ respectively.\nAs we will see later,\nit is useful to consider $S^3$ and $S^2$ as quotient spaces of $\\C^2 \\setminus \\set{0}$\nor subspaces of the quaternion algebra $\\H$ instead.\nBoth $\\C^2$ and $\\H$ are isomorphic to $\\R^4$ as a real vector space,\nbut their additional structure sheds light on various properties of the Hopf map.\nWe will therefore briefly examine these spaces before defining the Hopf map.\nIn later chapters we will explore the differentiable structure of these spaces,\nbut for now we focus on their topological properties.\nFurthermore, group actions are used extensively throughout this chapter,\nso we quickly recall some of the terms involved.\n\n\\section{Definitions}\n\n\\definition\nLet $X$ be a set with additional structure,\nsuch as a vector space or a topological space.\nThe \\emph{automorphism group} of $X$,\ndenoted $\\Aut(X)$ is the group of bijections $X \\to X$\nthat preserve its structure.\nMore formally we can say that $X$ is an object in a concrete category $\\mathcal{A}$,\na category equipped with a faithful functor $\\mathcal{A} \\to \\mathbf{Sets}$,\nthe forgetful functor.\nThe automorphism group is the group of invertible morphisms $X \\to X$\nin this category.\n\n\\example\nFor a group $G$, $\\Aut(G)$ is the group of group isomorphisms $G \\to G$.\nFor a module $M$ over a ring $R$,\nor for a vector space $V$ over a field $F$,\nthe automorphism group consists of $R$-linear bijections $M \\to M$\nand $F$-linear bijections $V \\to V$ respectively.\nFor a topological space $X$,\n$\\Aut(X)$ is the group of homeomorphisms $X \\to X$.\nFor sets, the automorphism group is simply the group of bijections\nfrom the set to itself.\n\n\\definition\nLet $G$ be a group and $X$ a set with additional structure.\nA \\emph{group action} of $G$ on $X$ is a group homomorphism $\\phi : G \\to \\Aut(X)$.\nIf $X$ is an object in the category $\\mathcal{A}$ \\,(e.g. the category of vector spaces,\ntopological spaces, etc.),\nwe say $G$ acts on $X$ in this category.\nGiven an element $x \\in X$ and $g \\in G$,\nwe will often write $g \\cdot x$ for the element $\\phi(g)(x)$.\n\nIn the definition above,\nthe group $G$ acts \\emph{from the left} on $X$.\nFor $g, h \\in G$ and $x \\in X$,\nwe have $(gh) \\cdot x = g \\cdot (h \\cdot x)$.\nSometimes we encounter a natural \\emph{antihomomorphism} $G \\to \\Aut(X)$.\nIn this case,\nwe say that $G$ acts \\emph{from the right} on $X$ in the category $\\mathcal{A}$,\nand to make the notation more natural we write $x \\cdot g$ instead of $g \\cdot x$,\nso that $x \\cdot (gh) = (x \\cdot g) \\cdot h$.\n\n\\definition\nLet $G$ and $X$ be as before, and $x \\in X$.\nThe \\emph{orbit} of $x$ is the set\n\\[ Gx = \\set{ g \\cdot x \\mid g \\in G } \\]\nHaving the same orbit defines an equivalence relation on $X$,\nand the quotient with respect to this relation is called the \\emph{orbit space},\nwritten $X/G$.\n\n\\definition\nLet $G$ and $X$ be as before, and $x \\in X$.\nThe \\emph{stabiliser} of $x$ is the subgroup\n\\[ G_x = \\set{ g \\in G \\mid g \\cdot x = x } \\]\n\n\\proposition[prop:open-quotient-map]\nLet $X$ be a topological space, $G$ a group that acts on $X$.\nWhen $X/G$ is endowed with the quotient topology,\nthe quotient map $q : X \\surj X/G$ is an open map.\n\n\\proof\nLet $U \\subseteq X$ be open,\ndefine $V = q(U)$.\n$V$ is open if and only if $q^{-1}(V)$ is open\nby definition of the quotient topology.\nWe have\n\\[ q^{-1}(V)\n = \\bigcup_{g \\in G} g \\cdot U \\]\nBecause the automorphisms of the group action are homeomorphisms,\nthey are open maps,\nso $g \\cdot U$ is open for all $g \\in G$.\nHence, $q^{-1}(V)$ is the union of open sets,\nso it is open.\n\\qed\n\n\\definition\nA \\emph{topological group} is a group $G$ that is also a Hausdorff space,\nsuch that the map $G \\times G \\to G$, $(g, h) \\mapsto gh^{-1}$ is continuous\nwhen $G \\times G$ is endowed with the product topology.\nThis is equivalent to the statement that multiplication and inversion are continuous;\nsee for example \\parencite[ch.~\\textsc{iii}, \\S~1.1]{bourbaki1971} or \\parencite[p.~276]{szekeres2004}.\n\n\\definition\nLet $G$ be a topological group and $X$ a topological space,\nsuch that $G$ acts on $X$ in the category of sets.\nThe action is said to be \\emph{continuous} if\n\\[ G \\times X \\longto X,\n\\quad (g, x) \\longmapsto g \\cdot x \\]\nis a continuous map.\nIt follows immediately from this definition that\n$x \\mapsto g \\cdot x$ is a homeomorphism for all $g \\in G$ when $G$ acts continuously on $X$,\ntherefore $G$ acts on $X$ in the category of topological spaces;\nthe group homomorphism $G \\to \\Aut(X)$ is actually a group homomorphism $G \\to \\Homeo(X)$.\n\n\\theorem{Universal property of the quotient topology}[thm:universal-property-quotient-topology]\nLet $X$ and $Y$ be topological spaces and $\\sim$ an equivalence relation on $X$.\nDenote by $q : X \\surj X\\modsim$ the quotient map.\nLet $f : X \\to Y$ be a continuous map such that\nfor all $x, y \\in X$ it holds that $x \\sim y$ implies $f(x) = f(y)$.\n(Such $f$ is said to be \\emph{compatible} with the equivalence relation.)\nThen there exists a unique continuous map $g : X\\modsim \\to Y$ that makes the following diagram commute:\n\\vspace{-\\parskip}\n\\begin{center}\n\\begin{tikzcd}[column sep = small] &\nX        \\ar[dl, two heads, swap, \"q\"]\n         \\ar[dr, \"f\"] & \\\\\nX\\modsim \\ar[rr, dashed, swap, \"\\exists_! g\"] & & Y\n\\end{tikzcd}\n\\end{center}\n\n\\proof\nSee for example \\parencite[ch.~\\textsc{i}, \\S~3.4]{bourbaki1971}.\n\n\\proposition\nLet $G_1$ and $G_2$ be groups, and $X$ a set.\nSuppose that $G_1 \\times G_2$ acts on $X$ in the category of sets.\nThis implies that the subgroups $G_1$ and $G_2$ act on $X$ individually as well.\nThen the following holds:\n\\begin{enumerate}\n\\item There is a natural action of $G_1$ on $X / G_2$ in the category of sets.\n\\item If $X$ is a topological space and $G_1 \\times G_2$ acts in the category of topological spaces,\n      $G_1$ acts on $X / G_2$ in this category.\n\\item If $G_1$ and $G_2$ are topological groups such that $G_1 \\times G_2$ acts continuously on $X$,\n      then $G_1$ acts continuously on $X / G_2$.\n\\end{enumerate}\n\n\\proof\nLet $x \\in X$ such that $[x] \\in X / G_2$, and $g \\in G_1$.\nDefine $g \\cdot [x] = [g \\cdot x]$.\nWe have to show that this action is well-defined.\nSuppose that $[x] = [y]$ for some $y \\in X$.\nThen there exists an $h \\in G_2$ such that $x = h \\cdot y$.\nBecause $h$ and $g$ commute in $G_1 \\times G_2$,\nwe have\n\\[ g \\cdot x = g \\cdot (h \\cdot y) = (g, h) \\cdot y = h \\cdot (g \\cdot y) \\]\nThus, we find $[g \\cdot x] = [g \\cdot y]$.\nThat this defines a homomorphism $G_1 \\to \\Aut(X / G_2)$ follows\nfrom the fact that $G_1 \\to \\Aut(X)$ is a homomorphism.\nThis proves statement \\textbbf{i}.\n\nSuppose that $X$ is a topological space\nand $G_1 \\times G_2$ acts on $X$ in the category of topological spaces.\nLet $g \\in G_1$, then $g$ induces a homeomorphism $\\phi : X \\to X$,\nand a bijection $\\psi : X / G_2 \\to X / G_2$.\nDenote by $q : X \\surj X / G_2$ the quotient map,\nthen $q \\circ \\phi$ is a continuous map $X \\to X / G_2$\nthat satisfies $\\psi \\circ q = q \\circ \\phi$ due to statement \\textbbf{i}.\nThis means that $q \\circ \\phi$ is compatible with the quotient map,\nso by the universal property of the quotient topology (theorem \\ref{thm:universal-property-quotient-topology}),\nthere exists a unique continuous map $\\psi'$ such that $q \\circ \\phi = \\psi' \\circ q$.\nUniqueness implies that $\\psi' = \\psi$,\ntherefore $\\psi$ is continuous.\nThe same argument applies to $\\psi^{-1}$,\nhence $\\psi$ is a homeomorphism.\nThis shows that $G_1$ acts on $X / G_2$ in the category of topological spaces,\nwhich proves statement \\textbbf{ii}.\n\nTo prove statement \\textbbf{iii},\nwe will use the following diagram:\n\\begin{center}\n\\begin{tikzcd}[row sep = large]\n&\nX \\ar[dr, two heads, \"q\"] & \\\\\nG_1 \\times X           \\ar[ur, \"a\"]\n                       \\ar[r, \"f\"]\n                       \\ar[dr, two heads, swap, \"r\"] &\nG_1 \\times {(X / G_2)} \\ar[r, \"T\"] &\nX / G_2 \\\\ &\n{(G_1 \\times X)} / G_2 \\ar[u, dashed, \"\\exists_! \\phi\"]\n                       \\ar[ur, dashed, swap, \"\\exists_! \\psi\"] &\n\\end{tikzcd}\n\\end{center}\nThe map $a : G_1 \\times X \\to X$,\n$(g, x) \\mapsto g \\cdot x$\nis continuous because it is the restriction of $G_1 \\times G_2 \\times X \\to X$\nthat is continuous by assumption.\nLet $q: X \\surj X / G_2$ denote the quotient map.\nDefine $f : G_1 \\times X \\to G_1 \\times {(X / G_2)}$ as $f = (\\id, q)$.\nThis map is continuous because both of its coordinates are.\n(See proposition 1 of \\parencite[ch.~\\textsc{i}, \\S~4.1]{bourbaki1971}.)\nFurthermore $f$ is open,\nfor $\\id$ and $q$ are open. (See proposition~\\ref{prop:open-quotient-map}.)\nLet $G_2$ act on $G_1 \\times X$ by $h \\cdot (g, x) = (g, h \\cdot x)$\nwhere $g \\in G_1, h \\in G_2, x \\in X$,\nand let $r$ denote the quotient map.\n$f$ is compatible with $r$,\nso by the universal property of the quotient topology (theorem \\ref{thm:universal-property-quotient-topology}),\nthere exists a unique continuous map\n$\\phi$ that makes the bottom left triangle of the diagram commute.\nThe map is given by $[g, x] \\mapsto (g, [x])$\nand its inverse is given by $(g, [x]) \\mapsto [g, x]$.\nAn open set in $(G_1 \\times X) / G_2$\nis the image under $r$ of an open set in $G_1 \\times X$,\nso from commutativity it follows that $\\phi$ is an open map.\nHence, $\\phi$ is a homeomorphism.\n\nOn the top of the diagram, we have the map $q \\circ a : G_1 \\times X \\to X / G_2$,\ngiven by $(g, x) \\mapsto [g \\cdot x]$.\nAs the composition of continuous maps it is continuous,\nand it is compatible with $r$.\nThus, by the universal property of the quotient topology,\nthere exists a unique continuous map $\\psi$\nsuch that $\\psi \\circ r = q \\circ a$.\nComposing with $\\phi^{-1}$, we find that the map\n\\[ T : G_1 \\times {(X / G_2)} \\longto X / G_2,\n\\quad (g, [x]) \\longmapsto [g \\cdot x] \\]\nis continuous,\nwhich proves claim \\textbbf{iii}.\nFurthermore, the above diagram commutes.\n\\qed\n\n\\theorem[thm:quotient-map-factors]\nLet $G_1$ and $G_2$ be groups and $X$ a topological space\nsuch that $G_1 \\times G_2$ acts on $X$.\nThen $X / (G_1 \\times G_2)$ is canonically homeomorphic to $(X / G_1) / G_2$.\nIn particular, the quotient map $X \\surj X / (G_1 \\times G_2)$ factors over $X / G_1$.\n\n\\proof\nLet\n$q_1 : X \\surj X / G_1$,\n$q_2 : (X / G_1) \\surj (X / G_1) / G_2$,\nand $q_{12} : X \\surj X / (G_1 \\times G_2)$ denote the quotient maps.\nThen we have the following commutative diagram:\n\\begin{center}\n\\begin{tikzcd}[row sep = huge, column sep = large]\n X                    \\ar[r,  two heads, \"q_1\"]\n                      \\ar[d,  two heads, \"q_{12}\"] &\n X / G_1              \\ar[d,  two heads, \"q_2\"]\n                      \\ar[dl, dashed, bend right = 7, swap, \"\\phi_1\"] \\\\\n X / (G_1 \\times G_2) \\ar[r,  dashed, bend left = 13, \"\\phi_{12}\"] &\n(X / G_1) / G_2       \\ar[l,  dashed, bend left = 13, \"\\phi_2\"]\n\\end{tikzcd}\n\\end{center}\nThe map $q_2 \\circ q_1$ is continuous and compatible with $q_{12}$,\nso by the universal property of the quotient topology (theorem \\ref{thm:universal-property-quotient-topology})\nthere exists a unique continuous map $\\phi_{12}$ that makes the diagram commute.\nBecause $q_{12}$ is compatible with $q_1$,\nthere exists a unique continuous map $\\phi_1$ such that $q_{12} = \\phi_1 \\circ q_1$.\nIt follows that $\\phi_1$ is compatible with $q_2$,\nso there exists a unique continuous map $\\phi_2$ that makes the diagram commute.\nNow we see that $\\phi_{12}$ and $\\phi_2$ are continuous inverses of one another,\nhence $X / (G_1 \\times G_2)$ and $(X / G_1) / G_2$ are homeomorphic.\n\\qed\n\n\\subsection*{Physical interpretation}\nGroups are prevalent in mathematics.\nIn physics, groups are often encountered in the context of symmetries.\nIn that case one may think of a group as a set of transformations of a system,\ntransformations under which a certain property is invariant.\nFor instance, angular momentum is invariant under rotation of space,\nand four-momentum is invariant under Lorentz transformations.\nA \\emph{group action} generalises this idea.\nElements of the group induce a transformation of a system.\nBy applying all possible transformations to a point,\nwe obtain the \\emph{orbit} of a point.\nFor instance, when we let the Lorentz group act on Minkowski space,\nthe orbit of a timelike vector is all of the light cone (past and future).\nOften, a group encodes transformations that we are \\emph{not} interested in.\nThe \\emph{orbit space} is what remains if we consider points that differ\nby such a transformation to be equal.\nFor example, the orbit space of the Lorentz group action on Minkowski space\nconsists of four elements:\nthe origin, the class of null (or light-like) vectors,\nthe class of timelike vectors,\nand the class of spacelike vectors.\nThe \\emph{stabiliser} of a point is the subgroup of transformations under which the point is invariant.\n\nTopology is the branch of mathematics that studies abstract properties of space.\nIt gives us the tools to study properties that do not depend\non exact distances, but rather on overall shape.\nFor instance, one would like to think of a garden hose\nas a one dimensional system where water can move back and forth,\nregardless of how the hose is bent or twisted.\nTopology allows us to ignore the bending and twisting.\nVirtually all spaces that occur in physics are topological spaces:\n$\\R^3\\!$, Minkowski space, Hilbert spaces, etc.\nOften these spaces have additional structure\nsuch as a metric or inner product,\nbut many properties can be derived from the topology alone.\nAn important example of such a property\nis \\emph{continuity} of a map between topological spaces,\na notion that is prevalent throughout physics.\nMany of the groups encountered in this thesis happen to have a natural topology as well.\nIn this case, an action on another topological space can be \\emph{continuous}.\nThe definition given in this section codifies our intuition:\nif two group elements that are near act on a point,\nthe resulting points should be near as well.\n\n\\section{Projective space}\n\\label{sec:projective-space}\nIt is possible to identify $\\R^4$ and $\\C^2$ as four-dimensional real vector spaces,\nby identifying the standard basis $(e_1, e_2, e_3, e_4)$ with the basis $((1, 0), (i, 0), (0, 1), (0, i))$.\nThe space $\\C^2 \\setminus \\set{0}$ will be prevalent in the rest of this section,\nso we introduce a shorthand notation. Furthermore, we embed $S^1$ in $\\C$.\n\n\\definition\n$\\CZ = \\C^2 \\setminus \\set{0}$.\n\n\\definition\nThe \\emph{unit circle} is defined by\n\\[ S^1 = \\set{ \\, z \\in \\C \\mid 1 = |\\,z\\,| \\, } \\]\nThis is a group under multiplication.\n\n\\definition[def:s3-real]\nThe \\emph{three-sphere} is defined by\n\\[ S^3 = \\set{ \\, x \\in \\R^4 \\mid 1 = \\nsq{x} } \\]\nHere $\\|{}\\cdot{}\\|$ denotes the regular Euclidean norm.\nBy identifying $\\R^4$ with $\\C^2$ as above,\nwe can consider $S^3$ to be a subset of $\\CZ$.\n\nConsider the multiplicative group $\\Rpos$ of positive real numbers.\nIt acts continuously on $\\C^2$ (in the category of real vector spaces) by scalar multiplication,\nand this action can be restricted to $\\CZ$ (in the category of sets).\nThis allows us to give an alternative definition of $S^3$ as a quotient:\n\n\\definition[def:s3-complex]\n$\\SC$ is the orbit space of $\\CZ$ with respect to the $\\Rpos$ action.\nDenote by $r : \\CZ \\surj \\SC$ the quotient map.\n$\\C^2$ is endowed with its regular topology induced by the Euclidean metric,\nand $\\SC$ is endowed with the quotient topology.\n\nIntuitively, this definition is not that different from definition~\\ref{def:s3-real}.\nEvery point $p$ at the three-sphere defines a ray from the origin through $p$.\nThis ray, except for the origin, is the orbit of $p$ under the $\\Rpos$ action.\nIn other words, every orbit can be represented by a point at unit distance from the origin.\nThe quotient map $r$ corresponds to projection onto the sphere.\n\n\\proposition[prop:s3-equivalence]\n$S^3$ and $\\SC$ as defined in definition~\\ref{def:s3-real} and \\ref{def:s3-complex} are homeomorphic.\n\n\\proof\n\\newcommand*{\\RZ}{{\\R^4_{\\,\\circ}}}\nWrite $\\R^4 \\setminus \\set{0} = \\RZ$.\nLet $i : S^3 \\to \\RZ$ be the inclusion,\nand let $\\phi : \\R^4 \\to \\C^2$ be the vector space isomorphism\ninduced by the identification of the bases given earlier in this section.\nThe inclusion $i$ is continuous, and the restriction $\\phi|_\\RZ = \\phi_\\circ$ is a homeomorphism.\nTherefore, the composition $\\psi = r \\circ \\phi_\\circ \\circ i : S^3 \\to \\SC$ is continuous.\nConsider the map\n\\vspace{-0.3\\parskip}\n\\[ \\CZ \\longto S^3,\n\\quad x \\longmapsto \\phi_\\circ^{-1} \\left( \\frac{x}{\\|x\\|} \\right) \\vspace{0.3\\parskip} \\]\nwhich is continuous and compatible with $r$.\nBy the universal property of the quotient topology (theorem~\\ref{thm:universal-property-quotient-topology}),\nthis map induces a unique continuous map $\\psi^{-1} : \\SC \\to S^3$ that is the inverse of $\\psi$.\nThus, $\\psi$ is a homeomorphism.\n\\qed\n\nConsider the multiplicative group $\\C^*$ (the complex plane minus the origin).\nIt acts continuously on $\\C^2$ (in the category of complex vector spaces) by scalar multiplication,\nand this action can be restricted to $\\CZ$.\nThis allows us to define the projective space:\n\n\\definition[def:complex-projective-line]\nThe \\emph{complex projective line} $\\PC$ is the orbit space of $\\CZ$ with respect to the $\\C^*$ action.\nDenote by $q : \\CZ \\surj \\PC$ the quotient map.\n$\\PC$ is endowed with the quotient topology.\n\nElements of $\\PC$ are indicated by \\emph{homogeneous coordinates}:\nif $(z_1, z_2)  \\in \\C^2$ is nonzero,\nthen we write $(z_1 : z_2)$ for $q(z_1, z_2)$.\nWe can embed $\\C$ in $\\PC$ via $z \\mapsto (z : 1)$.\nThe only point that is not reached in this manner is $(1 : 0)$.\n\n\\theorem[thm:s2-homeom-p1c]\nThere exists a homeomorphism between $S^2$ and $\\PC$.\n\n\\proof\nWe will postpone the proof until section \\ref{sec:hopf-quaternionic},\nand prove this with the aid of quaternions in theorem~\\ref{thm:hopf-map-equivalence}.\nFor an alternative proof, see \\parencite[ch.~\\textsc{viii}, \\S~4.3]{bourbaki1974}.\n\nThe general linear group $\\GLC$\nof invertible complex $2 \\times 2$ matrices\nacts on $\\C^2$ by matrix multiplication.\nThis induces a group action of $\\GLC$ on $\\CZ$.\nFurthermore, the groups $\\Rpos$, $S^1$, and $\\C^*$ are isomorphic to subgroups of $\\GLC$:\ngiven an element $z \\in \\C^*\\!$,\nwe can identify it with the matrix\n\\[ \\begin{pmatrix} z & 0 \\\\ 0 & z \\end{pmatrix} \\]\nin the centre of $\\GLC$.\n$\\C^*$ is isomorphic to the direct product $\\Rpos \\times S^1$:\nthis is the decomposition of a complex number into its modulus and argument.\nIt follows that $S^1$ and $\\Rpos$ are central in $\\GLC$, because their elements correspond to scalar matrices.\nConsequently, $S^1$ and $\\Rpos$ are normal in $\\GLC$.\n\n\\subsection*{Informal summary}\nThe \\emph{projective space} $\\PC$ is a construction with several interpretations.\nFor starters, $\\PC$ can be thought of as $\\C$ with one extra point,\na point “at infinity”.\nThis allows us to talk about $z_1/z_2$ even when $z_2$ is zero.\nInstead of $z_1/z_2$, we write $(z_1 : z_2)$, called \\emph{homogeneous coordinates}.\nSecondly, theorem \\ref{thm:s2-homeom-p1c} tells us that $\\PC$ can be thought of as the unit sphere $S^2\\!$.\n(In fact, $\\PC$ is sometimes called the \\emph{Riemann sphere}.)\nA \\emph{homeomorphism} between two spaces\nis a function, both one-to-one and onto,\nthat preserves all topological properties.\nFrom a topological point of view, $\\PC$ and $S^2$ are the same space.\nThis means that when we formulate the Hopf map later on\n— a function from $S^3$ to $S^2$ —\nwe can express it as a function to $\\PC$.\nThis expression is significantly simpler than the one involving Cartesian coordinates on $S^2\\!$.\n\n\\section{Quaternions}\n\\label{sec:quaternions}\n\n\\definition\nThe \\emph{quaternion algebra} $\\H$ is\nthe real noncommutative algebra with basis $(1, i, j, k)$.\nMultiplication is given by the identities\n\\[ i^2 = j^2 = k^2 = -1,\n\\quad i\\!j =  k, \\ jk =  i, \\ ki =  j,\n\\quad j  i = -k, \\ kj = -i, \\ ik = -j \\]\nand $1$ commutes with all elements.\nIn particular, $\\H$ is a ring and a four-dimensional real vector space.\nAnalogously to complex numbers,\nthis algebra has an involution $\\overline{\\raisebox{0pt}[0.5em]{${}\\cdot{}$}}$\ncalled \\emph{conjugation}\nthat flips the sign of the $i$, $j$, and $k$ components.\n\n\\definition\nThe \\emph{trace} is the map $\\Tr : \\H \\to \\R,\\ q \\mapsto q + \\overline{q}$.\nBecause the imaginary parts cancel, the trace of a quaternion is real.\nFurthermore, the trace is $\\R$-linear.\n\nThe reals commute with all quaternions,\nso $\\Tr(q)$ commutes with $q$ for all $q \\in \\H$.\nBecause $\\overline{q} = \\Tr(q) - q$,\nit follows that $q$ and $\\overline{q}$ commute.\n\n\\definition\nThe standard inner product on $\\H$ is given by\n\\[ \\inp{{}\\cdot{}}{{}\\cdot{}} : \\H \\times \\H \\longto \\R,\n\\quad (p, q) \\longmapsto \\tfrac{1}{2} \\Tr(p\\overline{q}) = \\tfrac{1}{2}(p\\overline{q} + q \\overline{p}) \\]\nSymmetry is clear from the definition,\nand bilinearity follows from the linearity of the trace.\nFor positive definiteness,\nremark that for $q = a + bi + cj + dk$,\nwe have $q \\overline{q} = a^2 + b^2 + c^2 + d^2\\!$.\nTherefore $\\inp{q}{q} \\geq 0$,\nand $\\inp{q}{q} = 0 \\implies a = b = c = d = 0 \\implies q = 0$.\n\n\\definition\nThe \\emph{norm} of $q \\in \\H$ is given by $\\nsq{q} = q \\overline{q}$.\nBecause $q$ and $\\overline{q}$ commute,\n$q\\overline{q} = \\smallfrac{1}{2}(q \\overline{q} + \\overline{q} q)$,\nso the norm is induced by the inner product.\nThis norm coincides with the Euclidean norm on $\\H$\nas real vector space with orthonormal basis $(1, i, j, k)$.\nTherefore,\n$\\H$ with the topology induced by the norm is homeomorphic to $\\R^4\\!$.\n\nBecause conjugation reverses the order of multiplication,\nthe norm is multiplicative:\nfor $p, q \\in \\H$, we have\n\\[ \\nsq{pq}\n = (pq)\\overline{(pq)}\n = p \\, q \\overline{q} \\, \\overline{p}\n = p \\nsq{q} \\, \\overline{p}\n = \\nsq{q} p \\overline{p}\n = \\nsq{q} \\nsq{p} \\]\n\nBecause $q \\overline{q} = \\nsq{q}\\!$,\nwe have $q^{-1} = \\overline{q} \\, \\|q\\|^{-2}$ for $\\|q\\| \\neq 0$.\nTherefore, $\\H$ is a division algebra:\nevery nonzero element has an inverse.\n\n\\proposition\n$\\H^* = \\H \\setminus \\set{0}$ is a topological group.\n\n\\proof\nMultiplication is continuous,\nbecause for $p, q \\in \\H^*\\,$,\nthe components of the product $pq$\ncan be written as a polynomial in the components of $p$ and $q$.\nInversion is continuous,\nbecause the components of $q^{-1}$ are rational functions of the components of $q$,\nwhich do not vanish because $\\nsq{q} \\neq 0$.\nSee also \\parencite[ch.~\\textsc{viii}, \\S~1.4]{bourbaki1974}.\n\\qed\n\nWith this machinery,\nwe can give a quaternionic definition of $S^3$ and $S^2\\!$.\nWhereas the definitions in section \\ref{sec:projective-space} emphasise\nhow $S^3$ and $S^2$ are quotients with respect to a group action,\nthe quaternionic definitions emphasise the group structure on the three-sphere itself,\nand the action of $S^3$ on $S^2\\!$.\n\nLet us revisit the three-sphere as defined in definition~\\ref{def:s3-real}.\nBy identifying $\\H$ with $\\R^4$ as a normed real vector space\nvia the basis given earlier in this section,\nwe can consider $S^3$ to be a subset of $\\H$,\nthe set of quaternions with unit norm:\n\\[ S^3 = \\set{ q \\in \\H \\mid 1 = \\nsq{q} } \\]\nThis set is closed under multiplication due to the multiplicativity of the norm,\nand it contains $1$.\nTherefore, this is a subgroup of $\\H^*\\!$.\nWe can embed $S^2$ in $S^3\\!$,\nbut in $\\R^4$ there is no preferred way of doing so.\nFor quaternions, there is one natural choice:\n\n\\definition[def:s2-quaternion]\nThe \\emph{two-sphere} $S^2 = \\set{ q \\in S^3 \\mid \\Tr(q) = 0 }$,\nthe set of pure imaginary quaternions with unit norm.\nThis definition coincides with the conventional definition of $S^2$\nwhen $\\R^3$ is identified with the subspace of $\\H$ spanned by $i$, $j$, and $k$.\n$S^2$ may alternatively be written as $\\set{q \\in S^3 \\mid \\inp{1}{q} = 0} = 1^\\perp \\cap S^3$.\n\nThe group $\\H^*$ acts\non $\\H$ in the category of $\\R$-algebras via the following homomorphism:\n\\[ \\phi : \\H^* \\longto \\Aut(\\H),\n   \\quad\n   p \\longmapsto (q \\mapsto p q p^{-1}) \\]\nBecause quaternion multiplication is continuous,\nthis is a continuous action.\nBy restriction to the subgroup $S^3\\!$,\nwe get a continuous action of $S^3$ on $\\H$.\n\n\\proposition[prop:invariant-inner-product]\nThe inner product on $\\H$ is invariant under the action of $\\H^*\\!$.\n\n\\proof\nLet $p \\in \\H^*\\!$, $q_1, q_2 \\in \\H$,\nthen we have\n\\begin{align*}\n   2 \\, \\inp{p \\cdot q_1}{p \\cdot q_2}\n&= p q_1 p^{-1} \\overline{p q_2 p^{-1}} + p q_2 p^{-1} \\overline{p q_1 p^{-1}} \\\\\n&= p q_1 \\nsq{p^{-1}} \\overline{q_2} \\, \\overline{p} + p q_2 \\nsq{p^{-1}} \\overline{q_1} \\, \\overline{p} \\\\\n&= \\nsq{p^{-1}} p (q_1  \\overline{q_2} + q_2 \\overline{q_1}) \\overline{p} \\\\\n&= \\nsq{p^{-1}} \\, \\nsq{p} \\, 2 \\, \\inp{q_1}{q_2} \\\\\n&= 2 \\, \\inp{q_1}{q_2}\n   \\tag*{\\qed}\n\\end{align*}\n\n\\corollary[cor:s3-action]\nIdentify $\\R^3$ with the subspace of $\\H$ spanned by $i$, $j$, and $k$.\nThen $\\R^3 = 1^\\perp$ and $S^2 = 1^\\perp \\cap S^3$ are invariant under the action of $\\H^*\\!$,\nwhich means $\\H^*$ and its subgroup $S^3$ act continuously on $\\R^3$ and $S^2\\!$.\n\n$\\C$ is a commutative subring of~$\\H$.\nAs real vector spaces with bases $(1, i)$ and $(1, i, j, k)$,\n$\\C$ can be identified with the subspace of $\\H$ spanned by $1$ and $i$.\nThe stabiliser of $i \\in \\H$ consists of the nonzero elements that commute with $i$.\nThese elements are linear combinations of $1$ and $i$,\nso we have $\\H^*_i = \\C^*$ and $S^3_i = S^1\\!$.\n\n\\proposition[prop:s3-isom-su2c]\n$S^3$ is isomorphic to $\\SUC$, the group of unitary $2 \\times 2$ matrices with determinant $1$.\n\n\\proof\nDefine the unitary matrices\n\\[            I = \\begin{pmatrix}1 &  0 \\\\ 0 &  1\\end{pmatrix}\n\\qquad \\sigma_1 = \\begin{pmatrix}0 &  1 \\\\ 1 &  0\\end{pmatrix}\n\\qquad \\sigma_2 = \\begin{pmatrix}0 & -i \\\\ i &  0\\end{pmatrix}\n\\qquad \\sigma_3 = \\begin{pmatrix}1 &  0 \\\\ 0 & -1\\end{pmatrix} \\]\nThese matrices are sometimes called the \\emph{Pauli spin matrices}.\nLet $\\phi: \\H \\to \\Mat(2 \\times 2, \\C)$ be the $\\R$-linear extension of\n\\[    1 \\longmapsto I,\n\\quad i \\longmapsto i \\sigma_1,\n\\quad j \\longmapsto i \\sigma_2,\n\\quad k \\longmapsto i \\sigma_3 \\]\nLet $\\psi$ be the restriction of $\\phi$ to $S^3\\!$.\nAll matrices in the image of $\\psi$ are unitary,\nand a little computation shows that for $q \\in S^3\\!$,\n$\\det \\psi(q) = 1$.\nThe matrices $I, i\\sigma_1, i\\sigma_2, i\\sigma_3$\nsatisfy the same multiplication rules as $1, i, j, k$.\nThat is, $i\\sigma_1 i\\sigma_2 = i\\sigma_3$, etc.\nTherefore, $\\psi$ is a group homomorphism $S^3 \\to \\SUC$.\nThis homomorphism is surjective (see \\parencite[p.~173]{szekeres2004}),\nand $1$ is the only element in its kernel.\nTherefore, $\\psi$ is an isomorphism.\n\\qed\n\n\\theorem[thm:s3-surj-so3r]\nThe map\n\\[ \\phi: S^3 \\longto \\SOR,\n\\quad q \\longmapsto (x \\mapsto q \\cdot x) \\]\nis a surjective group homomorphism with kernel $\\set{\\pm 1}$.\nHere $x \\in \\R^3 \\cong \\Span(i, j, k)$.\n\n\\proof\nThe map $x \\mapsto q \\cdot x$ is linear,\nand orthogonality follows from\nthe fact that the inner product is invariant under the action,\nas shown in proposition~\\ref{prop:invariant-inner-product}.\nTo show that $x \\mapsto q \\cdot x$ is not a reflection,\nnote that $\\det : \\textup{O}_3(\\R) \\to \\R$ is a continuous map\n(see for example \\parencite[p.~281]{hatcher2002}).\nWe can express $\\phi$ as a polynomial on all coordinates\nwhen elements of $\\SOR$ are written as matrices,\nso $\\phi$ is continuous.\nBy composition we get a continuous map $S^3 \\to \\set{\\pm 1}$.\nBecause $S^3$ is connected, this map must be constant.\n% (See for instance proposition~3.4.11 of \\parencite[p.~92]{runde2005}.)\nThe determinant of $\\id$ is $1$,\nso all $q \\in S^3$ induce an orthogonal map with positive determinant.\n\nTo show that the kernel of $\\phi$ is $\\set{\\pm 1}$,\nsuppose that $q \\in S^3$ is such that $q \\cdot x = q x q^{-1} = x$ for all $x \\in \\R^3\\!$.\nThen $q$ commutes with all $x \\in \\R^3\\!$,\nso $q$ must be real.\nBecause $\\nsq{q} = 1$, it follows that $q = 1$ or $q = -1$.\n\nTo prove surjectivity,\nsuppose that $\\rho \\in \\SOR$ is an anticlockwise rotation\nof $\\alpha$ radians about an axis spanned by $u \\in \\R^3\\!$,\nwhere $\\nsq{u} = 1$.\nThen the quaternion $q = \\cos(\\smallfrac{1}{2}\\alpha) + u \\sin(\\smallfrac{1}{2}\\alpha)$\nwill map to $\\rho$.\nTo see this,\nnote that all points on the axis of rotation are fixed points,\nfor $u$ commutes with $q$.\nFurthermore, suppose that $v \\in \\R^3$ is such that $\\inp{u}{v} = 0$.\nSet $q_0 = \\cos(\\smallfrac{1}{2}\\alpha)$ and $\\vec{q} = u \\sin(\\smallfrac{1}{2}\\alpha)$.\nBy using identities from \\parencite[p.~157]{szekeres2004},\nwe find\n\\newcommand*{\\vv}{v} % Could switch to v with an arrow, but to me it is just noise.\n\\newcommand*{\\vq}{\\vec{q}}\n\\begin{align*}\nq \\cdot v &= (q_0 + \\vq) \\vv (q_0 - \\vq)\n%      \\\\ &= (q_0 + \\vq) (\\inp{v}{\\vq} + q_0 \\vec{v} - \\vec{v} \\times \\vq)\n       \\\\ &= (q_0 + \\vq) (q_0 \\vv - \\vv \\times \\vq)\n       \\\\ &= -\\inp{\\vq}{q_0 \\vv - \\vv \\times \\vq} + q_0 (q_0 \\vv - \\vv \\times \\vq) + \\vq \\times {(q_0 \\vv - \\vv \\times \\vq)}\n       \\\\ &= q_0^2 \\vv - q_0 \\vv \\times \\vq + q_0 \\vq \\times \\vv - \\vq \\times {(\\vv \\times \\vq)}\n       \\\\ &= q_0^2 \\vv - 2 q_0 \\vv \\times \\vq - \\vv \\inp{\\vq}{\\vq} + \\vq \\inp{\\vq}{\\vv}\n       \\\\ &= (\\cos^2(\\smallfrac{1}{2}\\alpha) - \\sin^2(\\smallfrac{1}{2}\\alpha)) v\n           - 2 \\cos(\\smallfrac{1}{2}\\alpha)\\sin(\\smallfrac{1}{2}\\alpha) \\, {v \\times u}\n       \\\\ &= \\cos(\\alpha) v + \\sin(\\alpha) \\, {u \\times v}\n\\end{align*}\nThis demonstrates that $q$ rotates $v$ anticlockwise by $\\alpha$ radians about $u$.\nWe saw already that $x \\mapsto q \\cdot x$ is an orthogonal map with determinant $1$.\nTherefore, $q$ maps to $\\rho$.\n\\qed\n\n\\corollary[cor:transitive-s3-action]\n$S^3$ acts transitively on $S^2\\!$,\nfor every point on $S^2$ can be mapped\ninto any other point on $S^2$ by a rotation of the sphere.\n\nThe proof of theorem~\\ref{thm:s3-surj-so3r} gives us a way to explicitly get\na $q \\in S^3$ such that $q \\cdot i = p$ for any $p \\in S^2$:\nwe rotate $i$ onto $p$ with a rotation of $\\R^3\\!$.\nIf $p = -i$, $q = j$ will suffice,\nso suppose $p \\neq -i$.\nThen an axis that we can rotate about is the one spanned by $i + p$,\nwhich bisects the angle between $i$ and $p$,\nso we need to rotate by $\\pi$ radians.\nWe find\n\\begin{equationref}\n\\label{eqn:transitive-s3-action}\nq = \\frac{i + p}{\\|i + p\\|}\n\\end{equationref}\nTo verify that this works,\nnote that for $p \\in S^2$ we have\n$p \\overline{p} = 1$ and $\\overline{p} = -p$,\nso $p^2 = -1$.\nIt then follows that\n\\[ p^2 = -1\n% \\implies pi + p^2 = -1 + pi\n\\enskip \\implies \\enskip p(i + p) = (i + p)i\n\\enskip \\implies \\enskip p(i + p)\\overline{(i + p)} = (i + p)i\\overline{(i + p)} \\]\nMultiplying by $\\|i + p\\|^{-2}$ on both sides then yields $p = q i q^{-1}$.\n\n\\subsection*{Physical interpretation}\nJust like complex numbers are an extension of the real numbers,\nquaternions are an extension of the complex numbers.\nThese extensions come at a cost:\nwhen going from $\\R$ to $\\C$, you have to give up the ordering.\nWhen going from $\\C$ to $\\H$, you have to give up commutativity.\nApart from their rich structure that is interesting in its own right,\nquaternions have many useful applications.\nBy considering $S^3$ as a subset of $\\H$,\nit inherits a group structure.\nTheorem~\\ref{thm:s3-surj-so3r} tells us that this group is in a sense\ntwice $\\SOR$: every rotation of $\\R^3$ is represented by two antipodal quaternions.\nWhen traversing a great circle through $1$ in $S^3\\!$,\nthe points $1$ and $-1$ both correspond to the identity in $\\SOR$.\nThis path in $S^3$ corresponds to a $4\\pi$ rotation of $\\R^3\\!$,\nand after a $2\\pi$ rotation we will have moved from $1 \\in S^3$ to $-1 \\in S^3\\!$.\nThis property is reminiscent of \\emph{spinors},\nand indeed proposition~\\ref{prop:s3-isom-su2c} links the unit quaternions to the Pauli spin matrices.\n", "meta": {"hexsha": "08a9bdc9e35fc3524e2723e40ab5cdf889bf1905", "size": 31817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/preliminaries.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/preliminaries.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/preliminaries.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": 45.1946022727, "max_line_length": 124, "alphanum_fraction": 0.6834082409, "num_tokens": 10564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6289162621307292}}
{"text": "\n\\chapter{Filtering}\n\\label{sec:filtering}\n\\section{Curvelet Coefficient Thresholding}\nWe now apply our digital transforms for\nremoving noise from image data. The methodology is standard and is\noutlined mainly for the sake of clarity and self-containedness.\n\nSuppose that one is given noisy data of the form\n\\[\nx_{i,j} = f(i,j) + \\sigma z_{i,j},\n\\]\nwhere $f$ is the image to be recovered and $z$ is white noise, i.e.\n$z_{i,j} \\stackrel{i.i.d.}{\\sim} N(0,1)$. Unlike FFTs or FWTs, our\ndiscrete ridgelet (resp. curvelet) transform is not norm-preserving\nand, therefore, the variance of the noisy ridgelet (resp. curvelet)\ncoefficients will depend on the ridgelet (resp. curvelet) index\n$\\lambda$.  For instance, letting $F$ denote the discrete curvelet\ntransform matrix, we have $F z \\stackrel{i.i.d.}{\\sim} N(0,F F^T)$\nwhere $T$ denotes transpose.\nBecause the computation of $F F^T$ is prohibitively expensive, we\ncalculated an approximate value $\\tilde{\\sigma}^2_\\lambda$ of the\nindividual variances using Monte Carlo simulations where the diagonal\nelements of $F F^T$ are simply estimated by evaluating the curvelet\ntransforms of a few standard white noise images.\n\nLet $y_\\lambda$ be the noisy curvelet coefficients\n($y = F x$). We use the following hard-thresholding rule\nfor estimating the unknown curvelet coefficients:\n\\begin{eqnarray}\n\\hat y_\\lambda = y_\\lambda  & \\mbox{ if }  &\n|y_\\lambda|/\\sigma \\geq k \\tilde{\\sigma}_\\lambda\\\\\n\\hat y_\\lambda = 0 &  \\mbox{ if } & |y_\\lambda|/\\sigma\n<  k \\tilde{\\sigma}_\\lambda.\n\\end{eqnarray}\nIn our experiments, we actually chose a scale-dependent value for $k$;\nwe have $k = 4$ for the first scale $(j = 1)$ while $k = 3$\nfor the others $(j > 1)$.\n\n\\subsection*{Poisson Observations}\nAssume now that we have Poisson data $x_{i,j}$ with unknown mean\n$f(i,j)$.  The Anscombe transformation \\cite{rest:anscombe48}\n\\begin{equation}\n\\tilde{x} = 2\\sqrt{x + \\frac{3}{8}}\n\\end{equation}\nstabilizes the variance and we have $\\tilde{x} = 2 \\sqrt{f} +\n\\epsilon$ where $\\epsilon$ is a vector with independent and\napproximately standard normal components. In practice, this is a good\napproximation whenever the number of counts is large enough, greater\nthan 30 per pixel, say.\n \nFor a small number of counts, a possibility is to compute the Radon\ntransform of the image, and then to apply the Anscombe transformation\nto the Radon data. The rationale is that, roughly speaking, the\nRadon transform corresponds to a summation of pixel values over lines\nand  the sum of independent Poisson random variables is a Poisson\nrandom variable with intensity equal to the sum of the individual\nintensities. Hence, the intensity of the sum may be quite large (hence\nvalidating the Gaussian approximation) even though the individual\nintensities may be small. This might be viewed as an interesting\nfeature  since,  unlike wavelet transforms, the ridgelet and curvelet\ntransforms tend to average data over elongated and rather large\nneighborhoods.\n\n\\section{Filtering Experiments}\n\n\\subsubsection{Recovery of Linear Features}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{\n\\psfig{figure=fig_line.ps,bbllx=1cm,bblly=12cm,bburx=15cm,bbury=26cm,width=7.5cm,height=7.5cm,clip=}\n\\psfig{figure=fig_line_g0p5.ps,bbllx=1cm,bblly=12cm,bburx=15cm,bbury=26cm,width=7.5cm,height=7.5cm,clip=}\n}\n\\hbox{\n\\psfig{figure=fig_f24_line_g0p5.ps,bbllx=1cm,bblly=12cm,bburx=15cm,bbury=26cm,width=7.5cm,height=7.5cm,clip=}\n\\psfig{figure=fig_cur_line_g0p5.ps,bbllx=1cm,bblly=12cm,bburx=15cm,bbury=26cm,width=7.5cm,height=7.5cm,clip=}\n}}}\n\\caption{The top panels display a geometric image and that same image\n      contaminated with Gaussian white noise. The bottom left and right\n      panels display the restored images using the undecimated wavelet\n      transform and the curvelet transform, respectively.}\n\\label{fig_cur_line}\n\\end{figure}\nThe next experiment (Figure~\\ref{fig_cur_line}) consists of an\nartificial image containing a few bars, lines and a square.  The\nintensity is constant along each individual bar; from left to right,\nthe intensities of the ten vertical bars (these are in fact thin\nrectangles which are 4 pixels wide and 170 pixels long) are equal to\n${32 \\over 2^i}$, $i = 0, \\ldots 9$.  The intensity along all the\nother lines is equal to 1, and the noise standard deviation is $1/2$.\nDisplayed images have been log-transformed in order to better see\nthe results at low signal to noise ratio.\n\nThe curvelet reconstruction of the nonvertical lines is obviously\nsharper than that obtained using wavelets.  The curvelet transform\nalso seems to go one step further as far as the reconstruction of the\nvertical lines is concerned. Roughly speaking, for those templates,\nthe wavelet transform stops detecting signal at a SNR equal to 1\n(we defined here the SNR as the intensity level of the pixels\non the line, divided by the noise standard deviation of the noise)\nwhile the cut-off value equals 0.5 for the curvelet approach.  It is\nimportant to note that the horizontal and vertical lines correspond to\nprivileged directions for the wavelet transform, because the underlying\nbasis functions are direct products of functions varying solely in\nthe horizontal\nand vertical directions.  Wavelet methods will\ngive even poorer results on lines\nof the same intensity but tilting substantially\naway from the Cartesian axes.\nCf.\\ the reconstructions of the faint diagonal\nlines in the image.\n\n\\subsubsection{Recovery of Curves}\nIn this experiment (Figure~\\ref{fig_cur_picasso}), we have added \nGaussian noise to ``War and Peace,'' a drawing from Picasso which\ncontains many curved features.  Figure \\ref{fig_cur_picasso} bottom left\nand right show respectively the restored images by the undecimated\nwavelet transform and the curvelet transform. Curves are more sharply\nrecovered with the curvelet transform.\n\nThe authors are working on new methods (some of which will be based on\nthe curvelet transform) to extract and recover curves from noisy data\nwith greater accuracy and, therefore, this example is merely to be\ntaken for illustrative purposes.\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{\n\\psfig{figure=fig_picasso.ps,bbllx=2cm,bblly=13cm,bburx=18cm,bbury=25cm,width=8cm,height=6cm,clip=}\n\\psfig{figure=fig_picasso_g50.ps,bbllx=2cm,bblly=13cm,bburx=18cm,bbury=25cm,width=8cm,height=6cm,clip=}\n}\n\\hbox{\n\\psfig{figure=fig_picasso_wt.ps,bbllx=2cm,bblly=13cm,bburx=18cm,bbury=25cm,width=8cm,height=6cm,clip=}\n\\psfig{figure=fig_picasso_cur.ps,bbllx=2cm,bblly=13cm,bburx=18cm,bbury=25cm,width=8cm,height=6cm,clip=}\n}}}\n\\caption{The top panels display a Picasso picture (War and Peace) \n      and that same image\n      contaminated with Gaussian white noise. The bottom left and right\n      panels display the restored images using the undecimated wavelet\n      transform and the curvelet transform respectively.}\n\\label{fig_cur_picasso}\n\\end{figure}\n\n\n\\subsubsection{Denoising of a Color Image}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{\n\\psfig{figure=fig_cmp_lena_rgb.ps,bbllx=2cm,bblly=13cm,bburx=20cm,bbury=25cm,width=6cm,height=4.cm,clip=}\n\\psfig{figure=fig_cmp_pepper_rgb.ps,bbllx=2cm,bblly=13cm,bburx=20cm,bbury=25cm,width=6cm,height=4.cm,clip=}\n}\n\\hbox{\n\\psfig{figure=fig_cmp_mandrill_rgb.ps,bbllx=2cm,bblly=13cm,bburx=20cm,bbury=25cm,width=6cm,height=4.cm,clip=}\n\\psfig{figure=fig_cmp_barbara_rgb.ps,bbllx=2cm,bblly=13cm,bburx=20cm,bbury=25cm,width=6cm,height=4.cm,clip=}\n}\n}}\n\\caption{PSNR versus noise standard deviation using different filtering\n      methods. YUV and curvelet, YUV and undecimated wavelet, and YUV and\n      decimated wavelet transforms are represented respectively with a\n      continuous, dashed, and dotted line.  The upper left panel\n      corresponds to {\\tt Lena} (RGB), the upper right to {\\tt pepper}\n      (RGB), the bottom left to {\\tt Baboon} (RGB), and the bottom right\n      to {\\tt Barbara} (RGB).}\n\\label{fig_exp_rgb_curv}\n\\end{figure}\n\nIn a wavelet based denoising scenario, color RGB images are generally\nmapped into the YUV space, and each YUV band is then filtered\nindependently from the others. The goal here is to see whether the\ncurvelet transform would give improved results. We used four of the\nclassical color images, namely {\\tt Lena}, {\\tt Peppers}, {\\tt\n      Baboon}, and {\\tt Barbara} (all images except perhaps {\\tt Barbara}\nare available from the USC-SIPI Image Database \\cite{SIPI}).\nWe performed\na series of experiments and\nsummarized our findings in Figure~\\ref{fig_exp_rgb_curv} which again\ndisplays the PSNR (peak signal-to-noise ratio) \nversus the noise standard deviation for the four\nimages.\n\nIn all cases, the curvelet transform outperforms the wavelet\ntransforms in terms of PSNR -- at least for moderate and large values\nof the noise level.  In addition, the curvelet transform outputs\nimages that are visually more pleasant.\n \n\\subsubsection{Saturn Rings}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{\n\\psfig{figure=SATURN/fig_sat_sub_g20.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n\\psfig{figure=SATURN/fig_sat_sub_fil_owt.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n}\n\\hbox{\n\\psfig{figure=SATURN/fig_sat_sub_fil_atrou.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n\\psfig{figure=SATURN/fig_sat_sub_fil_cur.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n}}\n}\n\\caption{Top left, part of Saturn image with Gaussian noise. Top right,\nfiltered image using the undecimated bi-orthogonal wavelet transform.\nBottom left and right, filtered image by the \\`a trous wavelet \ntransform algorithm and the curvelet transform.}\n\\label{fig_sub_saturn_cur_filter}\n\\end{figure}\n\nGaussian white noise with a standard deviation\nfixed to 20 was added to the {\\tt Saturn} image.\nWe employed several methods to filter the noisy image:\n\\begin{enumerate}\n\\item Thresholding of the Curvelet transform.\n\\item Bi-orthogonal undecimated wavelet de-noising methods using  the\n      Dau\\-che\\-chies-An\\-to\\-ni\\-ni 7/9 fil\\-ters (FWT-7/9) and hard thresholding.\n\\item A trous wavelet transform algorithm and hard thresholding.\n\\end{enumerate}\nOur experiments are reported in Figure~\\ref{fig_sub_saturn_cur_filter}.  The\ncurvelet reconstruction does not contain the quantity of disturbing artifacts\nalong edges that one sees in wavelet reconstructions. An examination\nof the details of the restored images % (Figure~\\ref{fig_sub_saturn_cur_filter})\nis instructive. One notices that the decimated wavelet transform\nexhibits distortions of the boundaries and suffers substantial loss of\nimportant detail.  The \\`a trous  wavelet transform gives better\nboundaries, but completely omits to reconstruct certain ridges. \nIn addition, it exhibits numerous small-scale embedded\nblemishes; setting higher thresholds to avoid these blemishes would\ncause even more of the intrinsic structure to be missed.\n\n% Further results are visible at the following URL: {\\tt\n%  http://www-stat.stanford.edu/$\\sim$jstarck}.\n\n\\subsubsection{Supernova with Poisson noise}\n\n\\begin{figure}[htb]\n\\centerline{  \n\\hbox{\n\\psfig{figure=fig_kepler1604.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n\\psfig{figure=fig_kepler1604_fil_rid.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=7cm,height=7cm,clip=}\n}}\n\\caption{Left, XMM/Newton image of the Kepler SN1604 supernova.\nRight, ridgelet filtered image.}\n\\label{fig_sn1604}\n\\end{figure}\nFigure~\\ref{fig_sn1604} shows an example of an X-ray image filtering by the\nridgelet transform using such an approach. Figure~\\ref{fig_sn1604} left\nand right \nshow respectively the  XMM/Newton image of the Kepler SN1604 supernova and\nthe ridgelet filtered image (using a five sigma hard thresholding). \n\n\n% \\clearpage\n% \\newpage\n", "meta": {"hexsha": "173585ec09c88d2bfc17f3b2363578e3ec91ada0", "size": 11788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr4/ch_curfilter.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_mr4/ch_curfilter.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_mr4/ch_curfilter.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": 45.8677042802, "max_line_length": 124, "alphanum_fraction": 0.7792670512, "num_tokens": 3455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6289162505906513}}
{"text": "\\BoSSSopen{tutorial9-SIP/sip}\n\\graphicspath{{tutorial9-SIP/sip.texbatch/}}\n\n\\BoSSScmd{\n/// \\section*{What's new}\n/// \\begin{itemize}\n/// \\item Symmetric Interior Penalty method (SIP)\n/// \\item investigating matrix properties\n/// \\end{itemize}\n/// \\section*{Prerequisites}\n/// \\begin{itemize}\n/// \\item basics SIP method\n/// \\item spatial operator, chapter \\ref{SpatialOperator}\n/// \\item implementing numerical fluxes and convergence study, chapter \\ref{NumFlux}\n/// \\end{itemize}\n///\n///%_______________________________________________________\n/// \\section{Problem statement}\n/// We consider the 2D Poisson problem:\n/// \\begin{equation*}\n/// \\Delta u = f(x,y)\n/// \\end{equation*}\n/// with $f(x,y)\\neq 0$ is an arbitrary function of $x$ and/or $y$ or constant.\n/// Within this exercise, we are going to investigate the Symmetric Interior Penalty discretization method (SIP) for the Laplace operator:\n/// \\begin{equation*}\n/// a_{\\text{sip}}(u,v)\n/// = \\int_{\\domain} \\underbrace{\\nabla u \\cdot \\nabla v}_{\\text{Volume\\ term}}\\dV\n///   - \\oint_{\\Gamma \\setminus \\Gamma_{N }} \\underbrace{\n///         \\mean {\\nabla u} \\cdot n_{\\Gamma}\\jump{v}\n///      }_{\\text{consistency\\ term}} + \\underbrace{\n///         \\mean{\\nabla v} \\cdot \\vec{n}_{\\Gamma} \\jump{u}\n///      }_{\\text{symmetry\\ term}} \\dA\n///   + \\oint_{\\Gamma \\setminus \\Gamma_{N}} \\underbrace{\n///        \\eta \\jump{u}\\jump{v}\n///     }_{\\text{penalty\\ term}} \\dA\n/// \\end{equation*}\n/// The use of these fluxes including a penalty term stabilizes the DG-discretization for the Laplace operator.\n///\n///%____________________________________________\n/// \\section{Solution within the \\BoSSS{} framework}\n/// First, we initialize the new worksheet:\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nrestart;\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\n/// We need the following packages:\nusing ilPSP.LinSolvers;\\newline \nusing ilPSP.Connectors.Matlab;\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// BoSSScmdSilent BoSSSexeSilent\nusing NUnit.Framework;\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\n/// \\subsection{Implementation of the SIP fluxes}\n/// We are going to implement the SIP-form\n/// \\begin{equation*}\n/// a_{\\text{sip}}(u,v)\n/// = \\int_{\\domain} \\underbrace{\\nabla u \\cdot \\nabla v}_{\\text{volume\\ term}}\\dV\n///   - \\oint_{\\Gamma \\setminus \\Gamma_{N }} \\underbrace{\n///         \\mean {\\nabla u} \\cdot n_{\\Gamma}\\jump{v}\n///      }_{\\text{consistency\\ term}} + \\underbrace{\n///         \\mean{\\nabla v} \\cdot \\vec{n}_{\\Gamma} \\jump{u}\n///      }_{\\text{symmetry\\ term}} \\dA\n///   + \\oint_{\\Gamma \\setminus \\Gamma_{N}} \\underbrace{\n///        \\eta \\jump{u}\\jump{v}\n///     }_{\\text{penalty\\ term}} \\dA\n/// \\end{equation*}\n/// First, we need a class in which the integrands are defined.\n/// This also includes some technical aspects like the \\code{TermActivationFlags}.\npublic class SipLaplace :\\newline \n\\btab \\btab BoSSS.Foundation.IEdgeForm,   // edge integrals\\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm  // volume integrals\\newline \n\\{\\newline \n    /// We do not use parameters (e.g. variable viscosity, ...)\n    /// at this point: so this can be null\n\\btab public IList<string> ParameterOrdering \\{ \\newline \n\\btab \\btab get \\{ return new string[0]; \\} \\newline \n\\btab \\} \\newline \n    /// but we have one argument variable, $u$ (our trial function)\n\\btab public IList<String> ArgumentOrdering \\{ \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"u\" \\}; \\} \\newline \n\\btab \\}\\newline \n    /// The \\code{TermActivationFlags} tell \\BoSSS\\ which kind of terms, \n    /// i.e. products of $u$, $v$, $\\nabla u$, and $\\nabla v$\n    /// the \\code{VolumeForm(...)} actually contains.\n    /// This additional information helps to improve the performance.\n\\btab public TermActivationFlags VolTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return TermActivationFlags.GradUxGradV;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n    /// activation flags for the 'InnerEdgeForm(...)'\n\\btab public TermActivationFlags InnerEdgeTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return (TermActivationFlags.AllOn);\\newline \n\\btab \\btab \\btab // if we do not care about performance, we can activate all terms.\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{\\newline \n\\btab    get \\{\\newline \n\\btab \\btab    return TermActivationFlags.AllOn;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n    /// For the computation of the penalty factor $\\eta$,\n    /// we require\n    /// some length scale for each cell and \n    /// the polynomial degree of the DG approximation.\n\\btab public MultidimensionalArray cj;\\newline \n\\btab public int PolynomialDegree;\\newline \n    /// The safety factor for the penalty factor should be in the order of 1.\n    /// A very large penalty factor increases the condition number of the \n    /// system, but without affecting stability.\n    /// A very small penalty factor yields to an unstable discretization.\n\\btab public double PenaltySafety = 2.2; \\newline \n    /// The actual computation of the penalty factor, which should be \n    /// used in the \\code{InnerEdgeForm} and \\code{BoundaryEdgeForm} functions.\n    /// Hint: for the parameters \\code{jCellIn}, \\code{jCellOut} and \\code{g},\n    /// take a look at\n    /// \\code{CommonParams} and \\code{CommonParamsBnd}.\n\\btab double PenaltyFactor(int jCellIn, int jCellOut) \\{\\newline \n\\btab \\btab double cj\\_in        = cj[jCellIn];\\newline \n\\btab \\btab double penalty\\_base = PenaltySafety*PolynomialDegree*PolynomialDegree;\\newline \n\\btab \\btab double eta          = penalty\\_base * cj\\_in;\\newline \n\\btab \\btab if(jCellOut >= 0) \\{\\newline \n\\btab \\btab \\btab double cj\\_out = cj[jCellOut];\\newline \n\\btab \\btab \\btab eta           = Math.Max(eta, penalty\\_base * cj\\_out);\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return eta;\\newline \n\\btab \\}\\newline \n    /// The following functions cover the actual math.\n    /// For any discretization of the Laplace operator, we have to specify:\n    /// \\begin{itemize}\n    /// \\item a volume integrand,\n    /// \\item an edge integrand for inner edges, i.e. on $\\Gamma_i$,\n    /// \\item an edge integrand for boundary edges, i.e. on $\\partial \\Omega$.\n    /// \\end{itemize}\n    /// The integrand for the volume integral:\n\\btab public double VolumeForm(ref CommonParamsVol cpv, \\newline \n\\btab \\btab    double[] U, double[,] GradU, // the trial-function u \\newline \n\\btab \\btab    //            (i.e. the function we search for) and its gradient\\newline \n\\btab \\btab    double V, double[] GradV     // the test function; \\newline \n\\btab \\btab    ) \\{\\newline \n \\newline \n\\btab \\btab double acc = 0;\\newline \n\\btab \\btab for(int d = 0; d < cpv.D; d++)\\newline \n\\btab \\btab \\btab acc += GradU[0, d] * GradV[d];\\newline \n\\btab \\btab return acc;\\newline \n\\btab \\}\\newline \n    /// The integrand for the integral on the inner edges,\n    /// \\[\n    ///   -( \\mean{ \\nabla u } \\jump{ v }) \\cdot \\vec{n}_{\\Gamma} \n    ///   -( \\mean{ \\nabla v } \\jump{ u }) \\cdot \\vec{n}_{\\Gamma} \n    ///   + \\eta \\jump{ u }  \\jump{v} :\n    /// \\]\n\\btab public double InnerEdgeForm(ref CommonParams inp, \\newline \n\\btab \\btab double[] U\\_IN, double[] U\\_OT, double[,] GradU\\_IN, double[,] GradU\\_OT, \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double eta = PenaltyFactor(inp.jCellIn, inp.jCellOut);\\newline \n \\newline \n\\btab \\btab double Acc = 0.0;\\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{ // loop over vector components \\newline \n\\btab \\btab \\btab // consistency term: -(\\{\\{ \\textbackslash /u \\}\\} [[ v ]])*Normale\\newline \n\\btab \\btab \\btab // index d: spatial direction\\newline \n\\btab \\btab \\btab Acc -= 0.5 * (GradU\\_IN[0, d] + GradU\\_OT[0, d])*(V\\_IN - V\\_OT)\\newline \n\\btab \\btab \\btab \\btab \\btab    * inp.Normale[d];\\newline \n \\newline \n\\btab \\btab \\btab // symmetry term: -(\\{\\{ \\textbackslash /v \\}\\} [[ u ]])*Normale\\newline \n\\btab \\btab \\btab Acc -= 0.5 * (GradV\\_IN[d] + GradV\\_OT[d])*(U\\_IN[0] - U\\_OT[0])\\newline \n\\btab \\btab \\btab \\btab \\btab    * inp.Normale[d];;\\newline \n\\btab \\btab \\}\\newline \n \\newline \n\\btab \\btab // penalty term: eta*[[u]]*[[v]]\\newline \n\\btab \\btab Acc += eta*(U\\_IN[0] - U\\_OT[0])*(V\\_IN - V\\_OT);\\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\} \\newline \n    /// The integrand on boundary edges, i.e. on $\\partial \\Omega$, is\n    /// \\[ \n    ///   -( \\mean{ \\nabla u } \\jump{ v }) \\cdot \\vec{n}_{\\Gamma} \n    ///   -( \\mean{ \\nabla v } \\jump{ u }) \\cdot \\vec{n}_{\\Gamma} \n    ///   +  \\eta \\jump{ u }  \\jump{v} .\n    /// \\]\n    /// For the boundary we have to consider the special definition for \n    /// the mean-value operator $\\mean{-}$ and the jump operator \n    /// $\\jump{-}$ on the boundary.\n\\btab public double BoundaryEdgeForm(ref CommonParamsBnd inp, \\newline \n\\btab \\btab double[] U\\_IN, double[,] GradU\\_IN, double V\\_IN, double[] GradV\\_IN) \\{\\newline \n \\newline \n\\btab \\btab double eta = PenaltyFactor(inp.jCellIn, -1);\\newline \n\\btab \\btab double Acc = 0.0;\\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{ // loop over vector components \\newline \n\\btab \\btab \\btab // consistency term: -(\\{\\{ \\textbackslash /u \\}\\} [[ v ]])*Normale\\newline \n\\btab \\btab \\btab // index d: spatial direction\\newline \n\\btab \\btab \\btab Acc -= (GradU\\_IN[0, d])*(V\\_IN) * inp.Normale[d];\\newline \n \\newline \n\\btab \\btab \\btab // symmetry term: -(\\{\\{ \\textbackslash /v \\}\\} [[ u ]])*Normale\\newline \n\\btab \\btab \\btab Acc -= (GradV\\_IN[d])*(U\\_IN[0]) * inp.Normale[d];;\\newline \n\\btab \\btab \\}\\newline \n \\newline \n\\btab \\btab // penalty term: eta*[[u]]*[[v]]\\newline \n\\btab \\btab Acc += eta*(U\\_IN[0])*(V\\_IN);\\newline \n \\newline \n \\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\}\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{Evaluation of the poisson operator in 1D}\n/// We consider the following problem:\n/// \\begin{equation*}\n/// \\Delta u = 2,\\quad -1<x<1,\\quad u(-1)=u(1)=0.\n/// \\end{equation*}\n/// The solution is $u_{ex}(x) = 1 - x^2$. Since this is quadratic, we can represent it \\emph{exactly} in a DG space of order 2.\n/// As usual, we have to set up a grid and a basis:\nvar grd1D                     = Grid1D.LineGrid(GenericBlas.Linspace(-1,1,10));\\newline \nvar gdata1D                   = new GridData(grd1D);\\newline \nvar DGBasisOn1D               = new Basis(gdata1D,2);\\newline \n/// and a right-hand-side:\nvar RHS                       = new SinglePhaseField(DGBasisOn1D, \"RHS\");\\newline \nRHS.ProjectField((double x) => 2);\\newline \n/// We have to ensure to set the \\code{PolynomialDegree} in the \\emph{SipLaplace}-object.\nvar i\\_SipLaplace              = new SipLaplace();\\newline \ni\\_SipLaplace.PolynomialDegree = DGBasisOn1D.Degree;\\newline \ni\\_SipLaplace.cj               = gdata1D.Cells.cj;\\newline \nvar Operator\\_SipLaplace       = i\\_SipLaplace.Operator();\\newline \n/// We now want to calculate the residual after inserting the exact solution as well as a wrong solution. \n/// The implementation of the exact solution:\nvar u\\_ex         = new SinglePhaseField(DGBasisOn1D, \"$u\\_\\{ex\\}$\");\\newline \nu\\_ex.ProjectField((double x) => 1.0 - x*x);\\newline \n/// The implementation of a spurious, i.e. a wrong solution; we take the exact solution and add random values in each cell:\nvar u\\_wrong      = new SinglePhaseField(DGBasisOn1D, \"$u\\_\\{wrong\\}$\");\\newline \nu\\_wrong.ProjectField((double x) => 1.0 - x*x);\\newline \nRandom R         = new Random();\\newline \nfor(int j = 0; j < gdata1D.Cells.NoOfLocalUpdatedCells; j++)\\{\\newline \n\\btab double ujMean = u\\_wrong.GetMeanValue(j);\\newline \n\\btab ujMean += R.NextDouble();\\newline \n\\btab u\\_wrong.SetMeanValue(j, ujMean);\\newline \n\\btab \\}\\newline \n/// Evaluating the Laplace operator using the different solutions:\nvar Residual     = new SinglePhaseField(DGBasisOn1D,\"Resi1\");\\newline \nvar ResidualNorm = new List<double>();\\newline \nforeach(var u in new DGField[] \\{u\\_ex, u\\_wrong\\}) \\{\\newline \n\\btab Residual.Clear();\\newline \n\\btab Operator\\_SipLaplace.Evaluate(u, Residual);  // evaluate\\newline \n\\btab Residual.Acc(-1.0, RHS);    \\newline \n\\btab double ResiNorm = Residual.L2Norm();\\newline \n\\btab ResidualNorm.Add(ResiNorm);\\newline \n\\btab Console.WriteLine(\"Residual for \" + u.Identification + \" = \" + ResiNorm);  \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// tests BoSSScmdSilent\nAssert.LessOrEqual(ResidualNorm[0], 1e-10);\\newline \nAssert.GreaterOrEqual(ResidualNorm[1], 1e-1);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\subsection{The matrix of the Poisson Operator}\n/// If we do not know the exact solution, we have to solve a linear system.\n/// Therefore, we not only need to evaluate the operator,\n/// but we need its matrix.\n/// The \\emph{Mapping} controls which degree-of-freedom of the DG approximation\n/// is mapped to which row, resp. column of the matrix.\nvar Mapping           = new UnsetteledCoordinateMapping(DGBasisOn1D);\\newline \nvar Matrix\\_SipLaplace = Operator\\_SipLaplace.ComputeMatrix(Mapping,null,Mapping);\n }\n\\BoSSSexe\n\\BoSSScmd{\nMatrix\\_SipLaplace.NoOfCols;\n }\n\\BoSSSexe\n\\BoSSScmd{\nMatrix\\_SipLaplace.NoOfRows;\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We see that the matrix has 27 rows and columns.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Matrix rank and determinant of the matrix \n///  \\code{Matrix\\_SipLaplace}:}\n/// Use the functions \\emph{rank} and \\emph{det} to analyze the matrix (warning: this can get costly \n/// for larger matrices!).\\\\\n///Interpret the results:\n/// \\begin{itemize}\n/// \\item What does it mean, when a matrix has full rank?\n/// \\item How many solutions can a linear system have?\n/// \\end{itemize}\ndouble rank = Matrix\\_SipLaplace.rank(); \\newline \nConsole.WriteLine(\"Matrix rank = \" + rank);\\newline \n \\newline \ndouble det = Matrix\\_SipLaplace.det();   \\newline \nConsole.WriteLine(\"Determinante = \" + det);\\newline \n/// So the matrix of the SIP discretization has a unique solution.\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// tests BoSSScmdSilent\nAssert.AreEqual(rank, Matrix\\_SipLaplace.NoOfCols);\\newline \nAssert.Greater(det, 1.0);\n }\n\\BoSSSexe\n\\BoSSScmd{\n % \n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\section{Advanced topics}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %========================================================\n/// %========================================================\n/// \\subsection{The penalty parameter of the SIP and stability in 2D}\n/// %========================================================\n/// %========================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We define a two-dimensional grid:\nvar grd2D       = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1,1,21), \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab  GenericBlas.Linspace(-1,1,16));\\newline \nvar gdata2D     = new GridData(grd2D);\\newline \nvar DGBasisOn2D = new Basis(gdata2D, 5);\\newline \nvar Mapping2D   = new UnsetteledCoordinateMapping(DGBasisOn2D);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We are going to choose the \\code{PenaltySafety} for the \\code{SipLaplace}\n/// from the following list\ndouble[] SFs = new double[] \\newline \n\\btab   \\{0.001, 0.002, 0.01, 0.02, 0.1, 0.2, 1, 2, 10, 20, 100\\};\\newline \n/// and compute the condition number as well as the determinate.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We consider the example \n/// \\[\n///     -\\Delta u = \\pi^2 0.5 \\cos(x/2) \\cos(y/2) \n///       \\text{ with } \n///       (x,y) \\in (-1,1)^2\n/// \\]\n/// and $u = 0$ on the boundary.\n/// The exact solution is $u_{Ex}(x,y) = \\cos(x/2) \\cos(y/2)$.\nFunc<double[], double> exSol = \\newline \n\\btab \\btab (X => Math.Cos(X[0]*Math.PI*0.5)*Math.Cos(X[1]*Math.PI*0.5));\\newline \nFunc<double[], double> exRhs = \\newline \n\\btab \\btab (X => (Math.PI*Math.PI*0.5*Math.Cos(X[0]*Math.PI*0.5)\\newline \n\\btab \\btab \\btab \\btab \\btab   *Math.Cos(X[1]*Math.PI*0.5))); // == - /\\textbackslash  exSol\\newline \nSinglePhaseField RHS = new SinglePhaseField(DGBasisOn2D, \"RHS\");\\newline \nRHS.ProjectField(exRhs);\\newline \ndouble[] RHSvec = RHS.CoordinateVector.ToArray();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We check our discretization once more in 2D; the residual should be low,\n/// but not exactly (resp. up to $10^{-12}$) since the solution is not \n/// polynomial and cannot be fulfilled exactly.\nSinglePhaseField u = new SinglePhaseField(DGBasisOn2D,\"u\");\\newline \nu.ProjectField(exSol);\\newline \ni\\_SipLaplace.PolynomialDegree = DGBasisOn2D.Degree;\\newline \ni\\_SipLaplace.cj               = gdata2D.Cells.cj;\\newline \nvar Matrix\\_SIP\\_sf     = Operator\\_SipLaplace.ComputeMatrix(Mapping2D,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   null,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   Mapping2D);\\newline \nSinglePhaseField Residual = new SinglePhaseField(DGBasisOn2D,\"Residual\");\\newline \nResidual.Acc(1.0, RHS);\\newline \nMatrix\\_SIP\\_sf.SpMV(-1.0, u.CoordinateVector, 1.0, Residual.CoordinateVector);\\newline \nConsole.WriteLine(\"Residual L2 norm: \" + Residual.L2Norm());\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We also check that the matrix is symmetric:\nvar checkMatrix = Matrix\\_SIP\\_sf - Matrix\\_SIP\\_sf.Transpose();\\newline \ncheckMatrix.InfNorm();\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// tests BoSSScmdSilent\nAssert.LessOrEqual(checkMatrix.InfNorm(), 1e-8);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Matrix properties for different penalty factors.}\n/// Now, we assemble the matrix of the SIP for different \n/// \\code{PenaltySafety}-factors. We also try to solve the linear system\n/// using an iterative method. As Matlab is called multiple times during this \n/// command, it can take some minutes until it is done.\nint cnt     = 0;\\newline \nvar Results = new List<Tuple<double,double,int,double,bool>>();\\newline \nforeach(double sf in SFs) \\{\\newline \n\\btab cnt++;\\newline \n\\btab i\\_SipLaplace.PenaltySafety    = sf;\\newline \n\\btab i\\_SipLaplace.PolynomialDegree = DGBasisOn2D.Degree;\\newline \n\\btab var Matrix\\_SIP\\_sf             = Operator\\_SipLaplace.ComputeMatrix(\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab Mapping2D,null,Mapping2D);\\newline \n\\btab double condNo1                = Matrix\\_SIP\\_sf.condest();  \\newline \n\\btab bool definite                 = Matrix\\_SIP\\_sf.IsDefinite();\\newline \n \\newline \n    /// We solve the system \n    /// \\[\n    ///    \\text{\\tt Matrix\\_SIP\\_sf} \\cdot u = \\text{\\tt RHS}\n    /// \\]\n    /// using a an iterative solver, the so-called \n    /// conjugate gradient (CG) method.\n    /// CG requires a positive definite matrix. \n    /// The function \\code{Solve\\_CG} returns the number of iterations.\n\\btab SinglePhaseField u = new SinglePhaseField(DGBasisOn2D,\"u\");\\newline \n\\btab u.InitRandom();\\newline \n\\btab int NoOfIter = Matrix\\_SIP\\_sf.Solve\\_CG(u.CoordinateVector, RHSvec);\\newline \n \\newline \n\\btab SinglePhaseField Error = new SinglePhaseField(DGBasisOn2D,\"Error\");\\newline \n\\btab Error.ProjectField(exSol);\\newline \n\\btab Error.Acc(-1.0, u);\\newline \n \\newline \n\\btab double L2err = u.L2Error(exSol);\\newline \n \\newline \n\\btab Console.WriteLine(sf + \"\\textbackslash t\" + condNo1.ToString(\"0.#E-00\") \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  + \"\\textbackslash t\" + NoOfIter \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  + \"\\textbackslash t\" + L2err.ToString(\"0.#E-00\") \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  + \"\\textbackslash t\" + definite);\\newline \n\\btab Results.Add(new Tuple<double,double,int,double,bool>(sf, condNo1, NoOfIter,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab  L2err, definite));\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// tests BoSSScmdSilent\nforeach(var r in Results) \\{\\newline \n\\btab if(r.Item1 >= 1 && r.Item1 <= 20) \\{\\newline \n\\btab \\btab Assert.LessOrEqual(r.Item2, 1e7); // cond No.\\newline \n\\btab \\btab Assert.LessOrEqual(r.Item3, 6000); // iter\\newline \n\\btab \\btab Assert.LessOrEqual(r.Item4, 1e-4); // L2 err\\newline \n\\btab \\btab Assert.IsTrue(r.Item5); // definite   \\newline \n\\btab \\}\\newline \n\\btab if(r.Item1 <= 0.1) \\{\\newline \n\\btab \\btab Assert.IsFalse(r.Item5); // indefinite   \\newline \n\\btab \\}\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Plotting:}\n/// Plot the number of conjugate gradient iterations versus the \n/// \\code{PenaltySafety}.\n/// A logarithmic scale is used for the horizontal axis.\nvar format = new PlotFormat(lineColor: LineColors.Blue, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab pointSize: 2, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab dashType: DashTypes.DotDashed, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab Style: Styles.LinesPoints, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab pointType:PointTypes.OpenCircle);\\newline \nGnuplot gp = new Gnuplot(baseLineFormat:format);\\newline \ngp.PlotLogXY(Results.Select(r => r.Item1), \\newline \n\\btab \\btab \\btab  Results.Select(r => ((double)(r.Item3))));\\newline \ngp.PlotNow();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Convergence study, indefinite vs. definite.}\n/// We are going to solve the SIP-system for different grid resolutions,\n/// comparing an insufficient penalty to a penalty which is large enough.\ndouble[] Resolution = new double[] \\{ 8, 16, 32, 64, 128, 256 \\};\\newline \nList<double> L2Error\\_indef  = new List<double>();\\newline \nList<double> L2Error\\_posdef = new List<double>();\\newline \nforeach(int Res in Resolution) \\{\\newline \n\\btab var grd2D = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1,1,(int)Res + 1), \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab    GenericBlas.Linspace(-1,1,(int)Res + 1));\\newline \n\\btab var gdata2D = new GridData(grd2D);\\newline \n\\btab var DGBasisOn2D = new Basis(gdata2D, 2);\\newline \n\\btab var Mapping2D  = new UnsetteledCoordinateMapping(DGBasisOn2D);\\newline \n \\newline \n\\btab SinglePhaseField RHS = new SinglePhaseField(DGBasisOn2D, \"RHS\");\\newline \n\\btab RHS.ProjectField(exRhs);\\newline \n\\btab SinglePhaseField uEx = new SinglePhaseField(\\newline \n\\btab \\btab    new Basis(gdata2D, DGBasisOn2D.Degree*2),\\newline \n\\btab \\btab    \"Error\");\\newline \n\\btab uEx.ProjectField(exSol);\\newline \n \\newline \n\\btab i\\_SipLaplace.PolynomialDegree = DGBasisOn2D.Degree;\\newline \n\\btab i\\_SipLaplace.cj               = gdata2D.Cells.cj;\\newline \n \\newline \n\\btab i\\_SipLaplace.PenaltySafety    = 0.01;\\newline \n\\btab var Matrix\\_SIP\\_indef          = Operator\\_SipLaplace.ComputeMatrix(\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab Mapping2D,null,Mapping2D);\\newline \n \\newline \n\\btab SinglePhaseField u\\_indef = new SinglePhaseField(DGBasisOn2D,\"u\");\\newline \n\\btab Matrix\\_SIP\\_indef.Solve\\_Direct(u\\_indef.CoordinateVector, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   RHS.CoordinateVector);\\newline \n\\btab var Error\\_indef = uEx.CloneAs();\\newline \n\\btab Error\\_indef.AccLaidBack(-1.0, u\\_indef);\\newline \n\\btab L2Error\\_indef.Add(Error\\_indef.L2Norm());\\newline \n \\newline \n    /// In order to have a positive definite system, we are\n    /// using $\\text{\\tt PenaltySafety} = 2$!\n\\btab i\\_SipLaplace.PenaltySafety = 2.0;\\newline \n\\btab var Matrix\\_SIP\\_posdef         = Operator\\_SipLaplace.ComputeMatrix(\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab Mapping2D,null,Mapping2D);\\newline \n \\newline \n\\btab SinglePhaseField u\\_posdef = new SinglePhaseField(DGBasisOn2D,\"u\");\\newline \n\\btab Matrix\\_SIP\\_posdef.Solve\\_Direct(u\\_posdef.CoordinateVector, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab    RHS.CoordinateVector);\\newline \n\\btab var Error\\_posdef = uEx.CloneAs();\\newline \n\\btab Error\\_posdef.AccLaidBack(-1.0, u\\_posdef);\\newline \n\\btab L2Error\\_posdef.Add(Error\\_posdef.L2Norm());\\newline \n \\newline \n\\btab Console.WriteLine(L2Error\\_indef.Last().ToString(\"0.#E-00\") \\newline \n\\btab \\btab \\btab \\btab \\btab   + \"\\textbackslash t\" + L2Error\\_posdef.Last().ToString(\"0.#E-00\"));\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Convergence plot:}\n/// The convergence plot unveils that there is something wrong if the\n/// penalty factor is set too low.\n/// While the solution of the indefinite system may look right at the first\n/// glance, we see that we do not obtain grid convergence for \n/// \\code{Error\\_indef}.\n/// The error of the positive definite system, \\code{Error\\_posdef}, where the \n/// penalty is chosen sufficiently large converges with the expected \n/// rate.\nvar format = new PlotFormat(lineColor: LineColors.Blue, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab pointSize: 2, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab dashType: DashTypes.DotDashed, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab Style: Styles.LinesPoints, \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab pointType:PointTypes.OpenCircle);\\newline \nGnuplot gp = new Gnuplot(baseLineFormat:format);\\newline \ngp.PlotLogXLogY(Resolution, L2Error\\_indef);\\newline \ngp.PlotLogXLogY(Resolution, L2Error\\_posdef);\\newline \ngp.PlotNow();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Finally, we are going to compute the convergence rate of the SIP\n/// discretization: we take the logarithm of the resolution and the error:\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar log\\_h   = Resolution.Select(h => Math.Log10(h)).ToArray();\\newline \nvar log\\_Err = L2Error\\_posdef.Select(h => Math.Log10(h)).ToArray();\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar LeastSquaresSys = MultidimensionalArray.Create(log\\_h.Length,2);\\newline \nLeastSquaresSys.SetColumn(0, log\\_h.Length.ForLoop(i => 1.0));\\newline \nLeastSquaresSys.SetColumn(1, log\\_h);\\newline \ndouble[] dk = new double[2]; // intercept and slope of best-fit line\\newline \nLeastSquaresSys.LeastSquareSolve(dk, log\\_Err);\n }\n\\BoSSSexe\n\\BoSSScmd{\ndk;\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// tests BoSSScmdSilent\nAssert.LessOrEqual(dk[1], -2.9);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\section{Further reading}\n/// \\begin{itemize}\n/// \\item\n/// \\bibentry{DiPietroErn2011}\n/// \\item\n/// \\bibentry{Arnold_1982} \n/// \\end{itemize}\n }\n\\BoSSSexe\n", "meta": {"hexsha": "52b1d23140c85120b54e3a362f28a040a4115701", "size": 25686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/tutorial9-SIP/sip.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/tutorial9-SIP/sip.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/tutorial9-SIP/sip.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": 44.3626943005, "max_line_length": 138, "alphanum_fraction": 0.6803316982, "num_tokens": 8188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.628838870221482}}
{"text": "\\section{Asymmetric-Key Encryption (Public-Key Encryption)}\\label{s:public-key-encryption}\nThe major problem that traditional symmetric-key algorithms face is that they require the parties to exchange keys, or more specifically to agree to a secret common private key, prior to communicating.\nThis needs a secure (physical or digital) communication channel accessible even for a short period of time, in order for the secret key to be exchanged. Such a channel could be a piece of paper delivered by hand or by a trusted courier, or a short in person communication.\n\nAn asymmetric or public-key cryptosystem is one where different keys are employed for the operations in the cryptosystem (\\textit{e.g.}, encryption and decryption), and where one of the keys can be made public without compromising the secrecy of the other key \\cite{Kaliski2011}. That way there is no need for a secure channel or prior agreement.\n\nUsually three algorithms are needed to define a public key cryptosystem. These are a \\textit{Key Generation} algorithm which produces the public and private keys (based on a security parameter $\\eta$), an \\textit{Encryption} and a \\textit{Decryption} algorithm.\n\nIn the classic model such an encryption scheme involves a \\textit{public key} which is used for encryption and a \\textit{private key} which is used for decryption.\nMore formally, given a plaintext $P$, a public key $PubKey$, and a private key $PrivKey$ we can produce a ciphertext $C$ such that:\n\\begin{equation}\n  \\label{eq:public-key-encryption}\n  \\begin{aligned}\n    C = Enc(P, PubKey)\\\\\n    P = Dec(C, PrivKey)\n  \\end{aligned}\n\\end{equation}\n\nWhere $Enc$ and $Dec$ are the \\textit{Encryption} and \\textit{Decryption} algorithms respectively.\n\nIf Alice wants to send a message to Bob, she needs Bob's public key which could be publicly available (\\textit{e.g.} on Bob's website).\nAlice encrypts her message with Bob's public key and sends the resulted ciphertext to Bob. Bob then needs his private key which is only in his possession in order to decrypt the ciphertext Alice sent and retrieve the original message.\nIf Bob wishes to reply, he needs Alice's public key etc.\nGenerally, the public (encryption) key could be shared to any party that wants to communicate with the owner of that public key, while the private (decryption) key should be kept secret and used by the recipient of the ciphertext to recover the original plaintext.\n\nThe ability for two users to establish a shared secret over an insecure communication channel, despite having no prior communication or information exchange was first proposed in 1976 by Whitfield Diffie and Martin Hellman.\nThat method is named Diffie-Hellman (DH) key exchange \\cite{diffie1976new} after its authors. The security of the algorithm is based on the difficulty of solving the Discrete Log Problem (DLP). The DLP is stated as follows: Given $g, p$ and $g^k \\pmod{p}$, find $k$.\n\nSome of the most widely used public key cryptosystems are the RSA (Rivest -- Shamir -- Adleman) \\cite{rivest1978method}, the El Gamal \\cite{elgamal1985public} and the Paillier \\cite{paillier1999public} Cryptosystems.\n\n\\subsection{RSA}\\label{s:pk-rsa}\n\nOne if the first and most widely adopted public key cryptosystem is RSA . The algorithm's difficulty reduces to the difficulty of factoring the product of two large prime numbers. Its three basic algorithms are described below.\n\n\\begin{itemize}\n  \\item \\textit{Key Generation}\n  \\begin{itemize}\n    \\item Randomly select two large primes $p$ and $q$.\n    \\item Calculate modulus $n = p \\cdot q$.\n    \\item Calculate $\\phi(n) = (p-1) \\cdot (q-1)$.\n    \\item Randomly select $e : gcd(e,\\phi(n)) = 1$.\n    \\item Calculate reverse $d  = e ^ {-1} \\pmod{\\phi(n)}$.\\\\\n    $d \\cdot e = 1 \\pmod{\\phi(n)}$.\n    \\item The public key is $(n, e)$, while the private key is $d$. $p, q$ and $\\phi(n)$ must also be kept private.\n  \\end{itemize}\n  \\item \\textit{Encryption}\n  \\begin{itemize}\n    \\item Given a plaintext message $m$, we get a ciphertext $c = m ^ e \\pmod{n}$.\n  \\end{itemize}\n  \\item \\textit{Decryption}\n  \\begin{itemize}\n    \\item Given a ciphertext $c$, we get back the plaintext $m$ as follows: $c^d \\pmod{n} = m^{ed} \\pmod{n} = m$.\n  \\end{itemize}\n\\end{itemize}\n\n\n\\subsection{ElGamal}\\label{s:pk-elgamal}\nThe ElGamal encryption system is a public-key cryptosystem based on the Diffie-Hellman key exchange. Its three basic algorithms are described below.\n\n\\begin{itemize}\n  \\item \\textit{Key Generation}\n  \\begin{itemize}\n    \\item Select two large primes $p$ and $ q : q \\mid (p - 1)$.\n    \\item Select a generator $g$ of group $\\mathbb{G}$ which is a large enough order-$q$ subgroup of the multiplicative group $\\mathbb{Z}_{p}^{*}$ of integers between $1$ and $p - 1$.\n    \\item Randomly select $ x \\in_{R} \\mathbb{Z}_{q}$.\n    \\item Calculate $y = g^{x} \\pmod{p}$.\n    \\item The public key is $y$, while the private key is $x$.\n  \\end{itemize}\n  \\item \\textit{Encryption}\n  \\begin{itemize}\n    \\item Given a plaintext message $m$, we get a ciphertext $c$ as follows.\n    \\item Randomly select $r \\in_{R} \\mathbb{Z}_{q}$.\n    \\item Calculate $G = g^{r} \\pmod{p}$.\n    \\item Calculate $M = m \\cdot y^{r} \\pmod{p}$.\n    \\item Return $c = (G,M)$\n  \\end{itemize}\n  \\item \\textit{Decryption}\n  \\begin{itemize}\n    \\item Given a ciphertext $c = (G,M)$, we get back the plaintext $m$ as follows: \\\\$m = M/G^{x}\\pmod{p}$.\n  \\end{itemize}\n\\end{itemize}\n\n\\subsection{Paillier}\\label{s:pk-paillier}\nThe Pallier cryptosystem is a public-key cryptosystem that relies its security upon the decisional composite residuosity assumption \\cite{paillier1999public}.\n\n\\begin{itemize}\n  \\item \\textit{Key Generation}\n  \\begin{itemize}\n    \\item Randomly and independently select two large primes $p$ and \\\\$ q :gcd(p-1, q-1) = 1$ If both primes have the same length this property holds.\n    \\item Calculate the RSA modulus $n = p \\cdot q$.\n    \\item Calculate $\\lambda = lcm(p-1, q-1)$.\n    \\item Select generator $g \\in \\mathbb{Z}_{n^{2}}^{*}$ such that the order of $g$ is a non zero multiple of $n$.\n    \\item Calculate $\\mu = (L(g^{\\lambda} \\pmod{n^{2}}))^{-1} \\pmod{n}$, where $L(x) = \\frac{x-1}{n}$.\n    \\item The public key is $ (n,g) $, while the private key is $ (\\lambda, \\mu) $.\n  \\end{itemize}\n  \\item \\textit{Encryption}\n  \\begin{itemize}\n    \\item Given a plaintext message $m$, we get a ciphertext $c$ as follows.\n    \\item Encode $m$ into $\\mathbb{Z}_{n}$.\n    \\item Randomly select $ r \\in_{R} \\mathbb{Z}_{n}^{*}$.\n    \\item Return $c = g^{m} \\cdot r^{n} \\pmod{n^{2}}$.\n  \\end{itemize}\n  \\item \\textit{Decryption}\n  \\begin{itemize}\n    \\item Given a ciphertext $c \\in \\mathbb{Z}_{n^{2}}$, we get back the plaintext $m$ as follows: \\\\$m = L(c^{\\lambda} \\pmod{n^{2}}) \\cdot \\mu \\pmod{n}$.\n  \\end{itemize}\n\\end{itemize}\n", "meta": {"hexsha": "71cb587e42b2739d0cb46ef6ea72291cac39f69d", "size": 6779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pk-encryption.tex", "max_stars_repo_name": "jimouris/master-thesis", "max_stars_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-08-29T07:51:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-09T12:09:24.000Z", "max_issues_repo_path": "pk-encryption.tex", "max_issues_repo_name": "jimouris/master-thesis", "max_issues_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pk-encryption.tex", "max_forks_repo_name": "jimouris/master-thesis", "max_forks_repo_head_hexsha": "e424cdd458cb7ff964bebcaaecfb7cad5b3ea525", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-08-28T14:33:15.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-28T17:09:24.000Z", "avg_line_length": 62.7685185185, "max_line_length": 346, "alphanum_fraction": 0.7110193244, "num_tokens": 1966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.628838870221482}}
{"text": "% Part: first-order-logic\n% Chapter: introduction\n% Section: formulas\n\n\\documentclass[../../../include/open-logic-section]{subfiles}\n\n\\begin{document}\n\n\\olfileid{fol}{int}{fml}\n\n\\section{\\usetoken{P}{formula}}\n\nHere is the approach we will use to rigorously specify !!{sentence}s\nof first-order logic and to deal with the issues arising from the use\nof !!{variable}s. We first define a \\emph{different} set of\nexpressions: !!{formula}s. Once we've done that, we can consider the\nrole !!{variable}s play in them---and on the basis of some other\nideas, namely those of ``free'' and ``bound'' !!{variable}s, we can\ndefine what !!a{sentence} is (namely, !!a{formula} without free\n!!{variable}s). We do this not just because it makes the definition of\n``!!{sentence}'' more manageable, but also because it will be crucial\nto the way we define the semantic notion of satisfaction.\n\nLet's define ``!!{formula}'' for a simple first-order language, one\ncontaining only a single !!{predicate}~$\\Obj P$ and a single\n!!{constant}~$\\Obj a$, and only the logical symbols $\\lnot$, $\\land$,\nand~$\\lexists$. Our full definitions will be much more general:\nwe'll allow infinitely many !!{predicate}s and !!{constant}s. In fact,\nwe will also consider !!{function}s which can be combined with\n!!{constant}s and !!{variable}s to form ``terms.'' For now, $\\Obj a$\nand the variables will be our only terms.  We do need infinitely many\n!!{variable}s.  We'll officially use the symbols $\\Obj v_0$, $\\Obj\nv_1$, \\dots, as variables.\n\n\\begin{defn}\nThe set of \\emph{!!{formula}s}~$\\Frm$ is defined as follows:\n\\begin{enumerate}\n\\item\\ollabel{fmls-atom} $\\Atom{\\Obj P}{\\Obj a}$ and $\\Atom{\\Obj\n  P}{\\Obj v_i}$ are !!{formula}s ($i \\in \\Nat$).\n\n\\tagitem{prvNot}{If $!A$ is !!a{formula}, then $\\lnot !A$ is\n  !!{formula}.}{}\n\n\\tagitem{prvAnd}{If $!A$ and $!B$ are !!{formula}s, then $(!A \\land\n  !B)$ is !!a{formula}.}{}\n\n\\tagitem{prvEx}{If $!A$ is !!a{formula} and $x$ is !!a{variable},\n  then $\\lexists[x][!A]$ is !!a{formula}.}{}\n\n\\tagitem{limitClause}{\\ollabel{fmls-limit}Nothing else is !!a{formula}.}{}\n\\end{enumerate}\n\\end{defn}\n\n\\olref{fmls-atom} tell us that $\\Atom{\\Obj P}{\\Obj a}$ and $\\Atom{\\Obj\nP}{\\Obj v_i}$ are !!{formula}s, for any $i \\in \\Nat$. These are\nthe so-called \\emph{atomic} !!{formula}s. They give us something to\nstart from.  The other clauses give us ways of forming new\n!!{formula}s from ones we have already formed. So for instance, we get\nthat $\\lnot \\Atom{\\Obj P}{\\Obj v_2}$ is !!a{formula}, since\n$\\Atom{\\Obj P}{\\Obj v_2}$ is already !!a{formula} by\n\\olref{fmls-atom}, and then we get that $\\lexists[\\Obj v_2][\\lnot\n\\Atom{\\Obj P}{\\Obj v_2}]$ is another !!{formula}, and so on.\n\\olref{fmls-limit} tells us that \\emph{only} strings we can form in\nthis way count as !!{formula}s. In particular, $\\lexists[\\Obj\nv_0][\\Atom{\\Obj P}{\\Obj a}]$ and $\\lexists[\\Obj v_0][\\lexists[\\Obj\nv_0][\\Atom{\\Obj P}{\\Obj a}]]$ \\emph{do} count as !!{formula}s, and\n$(\\lnot \\Atom{\\Obj P}{\\Obj a})$ does not.\n\nThis way of defining !!{formula}s is called an \\emph{inductive\ndefinition}, and it allows us to prove things about !!{formula}s using\na version of proof by induction called \\emph{structural induction}.\nThese are discussed in a general way in \\olref[mth][ind][idf]{sec} and\n\\olref[mth][ind][sti]{sec}, which you should review before delving\ninto the proofs later on. Basically, the idea is that if you want to\ngive a proof that something is true for all !!{formula}s you show\nfirst that it is true for the atomic !!{formula}s, and then that\n\\emph{if} it's true for any !!{formula}~$!A$ (and~$!B$), it's\n\\emph{also} true for $\\lnot !A$, $(!A \\land !B)$, and\n$\\lexists[x][!A]$. For instance, this proves that it's true for\n$\\lexists[\\Obj v_2][\\lnot \\Atom{\\Obj P}{\\Obj v_2}]$: from the first\npart you know that it's true for the atomic !!{formula}~$\\Atom{\\Obj\nP}{\\Obj v_2}$. Then you get that it's true for $\\lnot \\Atom{\\Obj\nP}{\\Obj v_2}$ by the second part, and then again that it's true for\n$\\lexists[\\Obj v_2][\\lnot \\Atom{\\Obj P}{\\Obj v_2}]$ itself. Since all\n!!{formula}s are inductively generated from atomic !!{formula}s, this\nworks for any of them.\n\n\\end{document}\n", "meta": {"hexsha": "f903d77fee15946be593bb422b674259f9d2d5cc", "size": 4153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/first-order-logic/introduction/formulas.tex", "max_stars_repo_name": "jzc/OpenLogic", "max_stars_repo_head_hexsha": "5948483c1d08c25664dc12ac8350e9ae34986b31", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 754, "max_stars_repo_stars_event_min_datetime": "2015-01-13T20:57:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:18:26.000Z", "max_issues_repo_path": "content/first-order-logic/introduction/formulas.tex", "max_issues_repo_name": "jzc/OpenLogic", "max_issues_repo_head_hexsha": "5948483c1d08c25664dc12ac8350e9ae34986b31", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 229, "max_issues_repo_issues_event_min_datetime": "2015-01-12T23:00:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T19:14:08.000Z", "max_forks_repo_path": "content/first-order-logic/introduction/formulas.tex", "max_forks_repo_name": "jzc/OpenLogic", "max_forks_repo_head_hexsha": "5948483c1d08c25664dc12ac8350e9ae34986b31", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 241, "max_forks_repo_forks_event_min_datetime": "2015-02-28T22:05:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T18:47:05.000Z", "avg_line_length": 46.6629213483, "max_line_length": 74, "alphanum_fraction": 0.6874548519, "num_tokens": 1341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506581031359, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6288388653501271}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Review of Damped \\& Driven Harmonic Oscillators}\n\\begin{p}\nAn undamped harmonic oscillator has general solution $x(t) = B_1\\cos(\\omega t) + B_2\\sin(\\omega t)$. Show this can be recast as $x(t) = A\\cos(\\omega t - \\delta)$, where $A = \\sqrt{A^2 + B^2}$.\n\\end{p}\n\\begin{s}\nConsider a right-angle triangle with side lengths $B_1$, $B_2$ and hypotenuse $A + \\sqrt{B_1^2 + B_2^2}$. Then, let $\\cos\\delta = \\frac{B_1}{A}$ and $\\sin\\delta = \\frac{B_2}{A}$. Looking at the equation for $x(t)$ above, we can multiply it by one in a clever way:\n\\[x(t) = A\\left[\\frac{B_1}{A}\\cos\\omega t + \\frac{B_2}{A}\\sin\\omega t\\right] = A\\left[\\cos\\delta\\cos\\omega t + \\sin\\delta \\sin\\omega t\\right] = A\\cos(\\omega t - \\delta)\\]\nWhere the last equality follows by a trigonometric identity.\n\\end{s}\n\n\\begin{p}\nShow that the kinetic and potential energy of a simple undamped oscillator have the same amplitude but are out of phase, such that the total energy is conserved. \n\\end{p}\n\\begin{s}\nUsing our equation for $x(t)$ above (where $x(t)$ is the displacement from equilibrium), the total energy is given by:\n\\[E = U + T = \\frac{1}{2}kx^2 + \\frac{1}{2}m\\dot{x}^2 = \\frac{1}{2}kA^2\\cos^2(\\omega t - \\delta) + \\frac{1}{2}mA^2\\omega^2\\sin^2(\\omega t - \\delta)\\]\nWe have that $\\omega^2 = \\frac{k}{m}$ so:\n\\[\\frac{k}{2}A^2\\cos^2(\\omega t - \\delta) + \\frac{k}{2}A^2\\sin^2(\\omega t - \\delta) = \\frac{kA^2}{2}\\]\nAnd hence the total energy is a constant; we can therefore see that $\\od{E}{t} = 0$ and that the total energy is conserved.\n\\end{s}\n\n\\begin{p}\nDamped oscillatons are described by the ODE $\\ddot{x} + 2\\beta\\dot{x} + \\omega_0^2x = 0$. Show that for overdamped motion, the decay \"constant\" (decay parameter) for a damped oscillator decreases with increasing friction. Sketch the decay parameters vs. $\\beta$ for the whole range of $\\beta$.\n\\end{p}\n\\begin{s}\nWe guess a solution of the form $x(t) = \\exp(rt)$. We can therefore generate a characteristic equation for $r$, by substituting in the solution into the ODE and then cancelling out the exponential terms (as these can never be zero). Hence, we have:\n\\[r^2 + 2\\beta r  + \\omega_0^2 = 0\\]\nThis is a quadratic equation with solutions:\n\\[r = -\\beta \\pm \\sqrt{\\beta^2 - \\omega_0^2}\\]\nThere are now different possibilities for the damping depending on the ratio of $\\beta$ and $\\omega_0$. For $\\beta > \\omega_0$, the oscillator is overdamped. For $\\beta < \\omega_0$, the oscillator is underdamped. For $\\beta = \\omega_0$, the oscillator is critically damped. Let us now consider the overdamped case. Then, we have that the discriminant in the equation above $\\beta^2 - \\omega_0^2$ is positive, and the general solution is the sum of decaying exponentials:\n\\[x(t) = C_1\\exp(r_1 t) + C_2\\exp(r_2 t) \\]\nwhere $r_1 = -\\beta + \\sqrt{\\beta^2 - \\omega^2}, r_2 = -\\beta - \\sqrt{\\beta^2 - \\omega^2}$. The dominant term will be the $\\exp(r_1 t)$ term as this decays more slowly. Therefore, the decay parameter is:\n\\[-\\beta + \\sqrt{\\beta^2 -\\omega_0^2}\\]\nWhich decreases with increasing $\\beta$. We will also have a decay parameter for the underdamped case. In this case, the decay parameter is just $\\beta$, as the discriminant is negative, and hence the solution $x(t)$ is composed of an oscillating part (the imaginary exponential part from the square root) and a real exponentially decaying part ($\\exp(-\\beta t)$). Hence the decay parameter increases linearly in this regime. Overall, we obtain a plot that looks like the follows:\n\nWhere the decay parameter is maximized when $\\beta = \\omega_0$, where we have critical damping.\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-9/w9-img1.png}\n\\end{center}\n\\end{s}\n\n\\begin{p}\nShow that for critical damping, the solution $x(t) = te^{rt}$ solves the ODE $\\ddot{x} + 2\\beta\\dot{x} + \\omega_0^2x = 0$. Find $r$. Write the general solution.\n\\end{p}\n\\begin{s}\nFor critical damping, we have that $\\beta = \\omega_0$ and we can calculate $r$ to be:\n\\[r = -\\beta \\pm \\sqrt{\\beta^2 - \\beta^2} = -\\beta\\]\nHence one solution is given by:\n\\[x_1(t) = C_1\\exp(-\\beta t)\\]\nAnd we check the Ansatz provided in the question to verify it as a second solution. The first time derivative is given by:\n\\[\\dot{x} = \\exp(rt) + rt\\exp(rt)\\]\nAnd the second time derivative as:\n\\[\\ddot{x} = r\\exp(rt) + r\\exp(rt) + r^2t\\exp(rt) = 2r\\exp(rt) + r^2t\\exp(rt)\\]\nSo substituting this into the ODE, with $r = -\\beta$:\n\\[-2\\beta\\exp(-\\beta t) + \\beta^2t\\exp(-\\beta t) + 2\\beta\\left(\\exp(-\\beta t) - \\beta t\\exp(-\\beta t)\\right) + \\beta^2t\\exp(-\\beta t) = 0\\]\nSo we can see that this is indeed a solution! Hence the general solution is given by:\n\\[x(t) = C_1\\exp(-\\beta t) + C_2 t\\exp(-\\beta t)\\]\n\\end{s}\n\n\\begin{p}\nFind the condition on $C$ for $z(t) = Ce^{i\\omega t}$ to be a solution to $\\ddot{z} + 2\\beta\\dot{z} + \\omega_0^2z = f_0e^{i\\omega t}$. Express the coefficient $C$ as $Ae^{-i\\delta}$ and find $A$ and $\\delta$.\n\\end{p}\n\\begin{s}\nLet us plug in $z(t)$ into the ODE:\n\\[(-\\omega^2 + 2i\\beta\\omega + \\omega_0^2)C\\exp(i\\omega t) = f_0\\exp(i\\omega t)\\]\nWe may cancel out the exponentials on both sides:\n\\[(-\\omega^2 + 2i\\beta\\omega + \\omega_0^2) =f_0\\]\nHence we find:\n\\[C = \\frac{f_0}{-\\omega^2 + 2i\\beta\\omega + \\omega_0^2} = A\\exp(i\\delta)\\]\nWe have that $A^2 = CC^*$ and so:\n\\[A^2 = \\frac{f_0}{-\\omega^2 + 2i\\beta\\omega + \\omega_0^2}\\frac{f_0}{-\\omega^2 - 2i\\beta\\omega + \\omega_0^2} = \\frac{f_0^2}{(\\omega_0^2 - \\omega^2)^2 + 4\\beta^2\\omega^2}\\]\nTo get the phase, we see that:\n\\[f_0\\exp(i\\delta) = A(\\omega_0^2 - \\omega^2 + 2i\\beta\\omega)\\]\nAnd solving (using some knowledge of complex numbers and extracting their phase) we get:\n\\[\\delta = \\arctan(\\frac{\\Im}{\\Re}) = \\arctan(\\frac{2\\beta \\omega}{\\omega_0^2 - \\omega^2})\\]\n\\end{s}\n\n\\begin{p}\nWrite the general solution to $\\ddot{x} + 2\\beta\\dot{x} + \\omega_0^2x = f_0\\cos(\\omega t)$ for the underdamped case. What are the two undetermined constants?\n\\end{p}\n\\begin{s}\nWriting the general solution, we have:\n\\[x(t) = A\\cos(\\omega t -\\delta) + C_1\\exp(r_1 t) + C_2\\exp(r_2 t)\\]\nWhere the first term is the particular solution (comes from the driving) and the exponentials come from the homogenous solution. The former is the long-term oscillatory behavior, the latter is the transient solution (the exponentials decay away with time).\n\\end{s}\n\n\\begin{p}\nShow that the Q-factor given by the ratio of the width to the mean of the resonance curve is equal to $\\pi$ times the number of oscillations in one decay time.\n\\end{p}\n\\begin{s}\nWhen $\\omega \\sim \\omega_0$ (when the driving frequency approaches the natural frequency), we notice a resonance phenomenon, where the amplitude of the driven oscillator gets very large (technically it is slightly off from $\\omega = \\omega_0$, but to good approximation it is at the natural frequency of the system). This is pictured below:\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-9/w9-img2.png}\n\\end{center}\nWe can also consider the width of the resonance peak. It is defined as:\n\\[Q = \\frac{\\omega_0}{2\\beta}\\]\nStronger damping implies a smaller quality factor and a narrower peak, and weak damping implies a larger quality factor and a broadened peak. To prove the claim provided in the question, we consider that the decay time is given by $\\tau = \\frac{1}{\\beta}$ and the period is $T = \\frac{2\\pi}{\\omega_0}$, so plugging this in we can immediately see that:\n\\[Q = \\frac{\\omega_0}{2\\beta} = \\frac{\\frac{1}{\\beta}\\pi}{\\frac{2\\pi}{\\omega_0}} = \\pi\\frac{\\tau}{T}\\]\nwhich is the desired result.\n\\end{s}\n\n\\begin{p}\nFind the phase shift at resonance when the driving frequency $\\omega$ is varied. Sketch the phase shift $\\delta$ vs. $\\omega$.\n\\end{p}\n\\begin{s}\nThe phase shift is given by $\\delta = \\frac{\\pi}{2}$ (perfectly out of phase). We can see this as the phase shift is given above by:\n\\[\\delta = \\arctan(\\frac{2\\beta\\omega}{\\omega_0^2 - \\omega^2})\\]\nAnd at resonance we have $\\omega \\sim \\omega_0$, so therefore the argument fo the arctan goes to infinity, and hence the value of $\\delta$ goes to $\\frac{\\pi}{2}$.\n\\end{s}\n\\end{document}", "meta": {"hexsha": "6333f6ae6153e5a0ca96a7d0c1f3fc9dd551fd5f", "size": 8081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-9/Worksheet-9.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-9/Worksheet-9.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-9/Worksheet-9.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.5132743363, "max_line_length": 480, "alphanum_fraction": 0.6924885534, "num_tokens": 2676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6288388632597843}}
{"text": "\\hypertarget{haskell}{%\n\\section{Haskell - Recursive Functions}\\label{haskell}}\n\nIn Haskell, functions can also be defined in terms of themselves. Such\nfunctions are called recursive.\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Some functions, such as factorial, are simpler to define in terms of\n  other functions.\n\\item\n  As we shall see, however, many functions can naturally be defined in\n  terms of themselves.\n\\item\n  Properties of functions defined using recursion can be proved using\n  the simple but powerful mathematical technique of induction.\n\\end{itemize}\n\n\\hypertarget{recursion-on-lists}{%\n\\subsection{Recursion on Lists}\\label{recursion-on-lists}}\n\n\\begin{lstlisting}[language=Haskell]\nproduct :: Num a -> [a] -> a\nproduct [] = 1\nproduct (n:ns) = n * product ns\n\nIn execution:\n\nproduct [2,3,4]\n2 * product [3,4]\n2 * (3 * product [4])\n2 * (3 * (4 * product []))\n2 * (3 * (4 * 1))\n24\n\n--or\n-- The maximum function takes a list of things that can be ordered (e.g. instances of the Ord typeclass) and returns the biggest of them.\n\nmaximum' :: (Ord a) => [a] -> a  \nmaximum' [] = error \"maximum of empty list\"  \nmaximum' [x] = x  \nmaximum' (x:xs)   \n    | x > maxTail = x  \n    | otherwise = maxTail  \n    where maxTail = maximum' xs\n\\end{lstlisting}\n\n\\hypertarget{multiple-arguments}{%\n\\subsection{Multiple Arguments}\\label{multiple-arguments}}\n\nFunctions with more than one argument can also be defined using\nrecursion.\n\n\\begin{lstlisting}[language=Haskell]\nzip :: [a] -> [b] -> [(a,b)]\nzip []    _       = []\nzip  _    []      = []\nzip (x:xs) (y:ys) = (x,y) : zip xs ys\n\\end{lstlisting}\n\n\\subsection{Some Examples}\n\n\\begin{lstlisting}[language=Haskell]\ntake' :: (Num i, Ord i) => i -> [a] -> [a]  \ntake' n _  \n    | n <= 0   = []  \ntake' _ []     = []  \ntake' n (x:xs) = x : take' (n-1) xs \n\nreverse' :: [a] -> [a]  \nreverse' [] = []  \nreverse' (x:xs) = reverse' xs ++ [x]\n\\end{lstlisting}\n\n\\clearpage\n\\subsection{Quick Sort}\n\nWe have a list of items that can be sorted. Their type is an instance of the \\textbf{Ord} typeclass. The edge condition is the empty list. Now a sorted list is a list that has all the values smaller than (or equal to) the head of the list in front (and those values are sorted), then comes the head of the list in the middle and then come all the values that are bigger than the head (they're also sorted).\n\n\\begin{lstlisting}[language=Haskell]\nquicksort :: (Ord a) => [a] -> [a]  \nquicksort [] = []  \nquicksort (x:xs) =   \n    let smallerSorted = quicksort [a | a <- xs, a <= x]  \n        biggerSorted = quicksort [a | a <- xs, a > x]  \n    in  smallerSorted ++ [x] ++ biggerSorted  \n\\end{lstlisting}\n\nSo if we have, say [5,1,9,4,6,7,3] and we want to sort it, this algorithm will first take the head, which is 5 and then put it in the middle of two lists that are smaller and bigger than it. So at one point, you'll have [1,4,3] ++ [5] ++ [9,6,7]. We know that once the list is sorted completely, the number 5 will stay in the fourth place since there are 3 numbers lower than it and 3 numbers higher than it. Now, if we sort [1,4,3] and [9,6,7], we have a sorted list! We sort the two lists using the same function. Eventually, we'll break it up so much that we reach empty lists and an empty list is already sorted in a way, by virtue of being empty.\n\n\\clearpage", "meta": {"hexsha": "edb08d3fd864c3ae3b450430ede5ed779ea80877", "size": 3299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_AdvPrPa/Summary/07_Haskell06.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/Summary/07_Haskell06.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/Summary/07_Haskell06.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": 35.8586956522, "max_line_length": 651, "alphanum_fraction": 0.6732343134, "num_tokens": 980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.628838860864515}}
{"text": "\\chapter{Dimension Reduction}\n\\emph{“你们都不是49年的国军，你们是50年的国军。”}\n\\newpage\n\n\n\\section{Principal Component Analysis}\n    \\emph{aka. Discrete Karhunen Loeve Transform; Hotelling Transform}\n\n    Let $y \\in \\mathbb{R}^K$ be a feature vector computed from $x \\in \\mathbb{R}^D$ where $K \\ll D$. PCA determines an orthogonal matrix $W \\in \\mathbb{R}^{D \\times K}$ s.t.\n    \\[ y = W^Tx \\]\n\n    Assume in this section that $x$ has a distribution with mean $\\mu=0$ and covariance matrix $\\Sigma$.\n\n    \\subsection{Objective Funtion}\n        PCA minimizes the reconstruction error between original $x$ and reconstructed $\\hat{x}$.\n\n        Notice that $W$ is orthogonal, so $x$ can be reconstructed by\n        \\[ \\hat{x} = Wy \\]\n\n        Let the reconstruction error be\n        \\[ \\epsilon = x - \\hat{x} = x - WW^Tx \\]\n\n        We want to minimize the reconstruction error\n        \\[ \\|\\epsilon\\|^2 = \\epsilon^T\\epsilon = x^Tx - x^TWW^Tx \\]\n\n        The minimization is performed over all possible $x$\n        \\[ \\int p(x)\\epsilon(x)^T\\epsilon(x)\\mathrm{d}x \\]\n\n        \\[ \\mathbb{E}[\\epsilon^T\\epsilon] = \\mathbb{E}[x^Tx] - \\mathbb{E}[x^TWW^Tx]\\]\n\n    \\subsection{Simple Case}\n        If $K=1$, $w$ is a vector and $y$ is a scalar.\n        \\[\\mathbb{E}[\\epsilon^T\\epsilon] = \\mathbb{E}[x^Tx]-w^T\\mathbb{E}[xx^T]w = \\mathbb{E}[x^Tx] - w^T \\Sigma w\\]\n        where $\\Sigma = XX^T$ (recall that $X$ is assumed to have zero mean).\n\n        We maximize the normalized second term\n        \\[ \\max_w \\quad J \\triangleq \\frac{w^TXX^Tw}{w^Tw} \\]\n\n        Or it can also be formulated as a equality constrained maximization and solved by Lagrangian.\n\n        The solution is\n        \\[ XX^Tw=Jw \\]\n\n        So the problem becomes finding the eigenvalues of $XX^T$, to maximize $J$, we find the largest eigenvalue of $XX^T$.\n\n        Other dimensions turn out to be the remaining eigenvectors.\n\n    \\subsection{Geometric Interpretation}\n        \\begin{itemize}\n            \\item PCA is a shift and rotation of axis.\n            \\item $w_1$ is the direction of greatest elongation\n            \\item $w_2$ is the second largest elongation that is orthogonal to $w_1$\n        \\end{itemize}\n\n\n\\section{Multi-Dimensional Scaling}\n    MDS aims to keep the distances of samples in the mapped space that same as the distances in the original space.\n\n    In this section we also assume the data samples have $\\mu=0$.\n\n    \\[ \\min_{\\hat{x}} \\left(\\sum_{i<j}\\left( \\|\\hat{x}_i-\\hat{x}_j\\| - d_{ij} \\right)^2\\right)^{1/2} \\]\n    where $\\hat{x}$ are mapped (instead of reconstructed) samples.\n\n    Let $X$ be the unknown \\emph{dimension-reduced} samples. Let $T=XX^T$ and $t_{ij}=\\hat{x}_i^T\\hat{x}_j$.\n\n    The distance between $\\hat{x}_i$ and $\\hat{x}_j$ is given by\n    \\[d_{ij}^2 = (\\hat{x}_i-\\hat{x}_j)^T(\\hat{x}_i-\\hat{x}_j)\\]\n\n    Solving for $t_{ij}$ yields\n    \\[ t_{ij} = -\\frac{1}{2}(d_{ij}^2\\hat{x}_i^2-\\hat{x}_j^2) \\]\n\n    We also have\n    \\[\\sum_j d_{ij}^2 = n\\hat{x}_i^2 + \\sum_j\\hat{x}_j^2 - 2\\hat{x}_i\\sum_j\\hat{x}_j = n\\hat{x}_i^2 + \\sum_j\\hat{x}_j^2\\]\n    \\[\\sum_i d_{ij}^2 = n\\hat{x}_j^2 + \\sum_i\\hat{x}_i^2 - 2\\hat{x}_j\\sum_i\\hat{x}_i = n\\hat{x}_j^2 + \\sum_i\\hat{x}_i^2\\]\n    \\[\\sum_{i}\\sum_{j}d_{ij}^2=n\\sum_i\\hat{x}_i^2 + n\\sum_j\\hat{x}_j^2 \\]\n    Again recall that the data are assumed to have zero mean so the sum over all data samples yields zero.\n\n    So we can solve for $t_{ij}$\n    \\[ t_{ij} = -\\frac{1}{2}\\left(d_{ij}^2-\\frac{1}{n}\\sum_kd_{ik}^2-\\frac{1}{n}\\sum_kd_{kj}^2-\\frac{1}{n}\\sum_{k}\\sum_{l}d_{kl}^2\\right) \\]\n    where $d_{ij}$ can be computed from the original dataset.\n\n    Since $T=XX^T$, we can solve for $X$ by decomposing $T$.\n    \\[T = U\\Lambda U^T = U\\Lambda^{1/2}\\Lambda^{1/2}U^T\\]\n\n    Therefore $X=U\\Lambda^{1/2}$\n\n\n\\section{Non-Linear Dimension Reduction}\n    \\subsection{ISOmetric feature MAPping}\n        Uses the geodesic distance (shortest distance on a plane) instead of Euclidean distance. The remaining work is similar to MDS and is pigeoned in this note.\n\n    \\subsection{Locally Linear Embedding}\n        Assumes that a data sample can be represented by some linear combination of its local neighbors\\footnote{This assumption is reasonable because the distribution can be somehow ``linearized'' in a sufficiently small area, just like derivatives.}, and that this relationship does not change after dimension reduction.\n\n        LLE can basically be divided into two steps. We first solve for the locally linear combination relationship\\footnote{Actually we will first have to find the local nearest neighbours for each data sample $x_i$.} in the original space (solve for a coefficient matrix $W$), and then reconstruct the relationship in a mapped space (solve for mapped data $Y$).\n\n        \\subsubsection{Solving Linear Combination}\n        In the original space, let $x_j$ be some neighbors of $x_i$. Let $W \\in \\mathbb{R}^{N \\times N}$.\n        \\[ \\epsilon(W) = \\sum_i \\left|x_i - \\sum_jW_{ij}x_j\\right|^2 \\]\n        \\begin{align*}\n            \\min_W &\\quad \\epsilon(W)\\\\\n            \\text{s.t.} &\\quad W_{ij} = 0 \\quad x_j \\notin \\mathcal{N}(x_i)\\\\\n            &\\quad \\sum_j W_{ij}=1\n        \\end{align*}\n\n        Can be solved by Lagrangian multipliers.\n\n        \\subsubsection{Solving Mapping}\n        In the mapped space\n        \\[ \\phi(y) = \\sum_i\\left| y_i - \\sum_j W_{ij}y_j \\right|^2 \\]\n        \\begin{align*}\n            \\min_W &\\quad \\phi(y)\\\\\n            \\text{s.t.} &\\quad \\sum_i y_i = 0\\\\\n            &\\quad \\frac{1}{N} YY^T = I\n        \\end{align*}\n        where $Y$'s columns are $y_i$.\n\n        To make the problem easier, we convert it into a quadratic form. Define an error matrix\n        \\[ \\delta = Y-YW \\triangleq [\\Delta y_1,\\Delta y_2,\\cdots,\\Delta y_N]\\]\n\n        The total error is given by\n        \\[ \\sum_{i=1}^N \\Delta y_i^T \\Delta y_i \\]\n\n        Notice that\n        \\[ \\delta^T\\delta = \\begin{bmatrix}\n            \\Delta y_1^T \\Delta y_1 & \\Delta y_1^T \\Delta y_2 & \\cdots & \\Delta y_1^T \\Delta y_N\\\\\n            \\Delta y_2^T \\Delta y_1 & \\Delta y_2^T \\Delta y_2 & \\cdots & \\Delta y_2^T \\Delta y_N\\\\\n            \\vdots & \\vdots & \\ddots & \\vdots\\\\\n            \\Delta y_N^T \\Delta y_1 & \\Delta y_N^T \\Delta y_2 & \\cdots & \\Delta y_N^T \\Delta y_N\n        \\end{bmatrix} \\]\n\n        So the error can be expressed as\n        \\[ Tr[\\delta^T\\delta] = Tr[(Y(I-W))^T(Y(I-W))] = Tr[(I-W)^TY^TY(I-W)] = Tr[Y^T(I-W)^T(I-W)Y] \\]\n\n        Let $M = (I-W)^T(I-W)$, the objective function becomes\n        \\[ \\min Tr(Y^TMY) \\]\n\n        So we can solve for $Y$ by Lagrangian multipliers.\n", "meta": {"hexsha": "8a7b0625625463f7b36a5298353a45926e93c703", "size": 6528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/DimensionReduction.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/DimensionReduction.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/DimensionReduction.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": 46.964028777, "max_line_length": 363, "alphanum_fraction": 0.6184129902, "num_tokens": 2170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.628790313542905}}
{"text": "\\documentclass{article}\n\\usepackage{eecstex}\n\\usepackage{pgfplots}\n\n\\title{EE 123 HW 02}\n\\author{Bryan Ngo}\n\\date{2022-01-29}\n\n\\begin{document}\n\n\\maketitle\n\n\\setcounter{section}{2}\n\n\\section{}\n\n\\begin{equation}\n    a^n u[n] \\iff \\frac{1}{1 - ae^{-j \\omega}}, \\ |a| < 1\n\\end{equation}\n\n\\subsection{}\n\n\\begin{equation}\n    x[n] = -b^n u[-n - 1] =\n    \\begin{cases}\n        -b^n & n \\leqslant -1 \\\\\n        0 & n \\geqslant 0\n    \\end{cases}\n\\end{equation}\nUsing the definition of the DTFT,\n\\begin{align}\n    X(e^{j \\omega}) &= \\sum_{k \\in \\Z} -b^k u[-k - 1] e^{-j \\omega k} \\\\\n    &= -\\sum_{k \\leqslant -1} b^k e^{-j \\omega k}\n\\end{align}\nLetting \\(k' = -k\\),\n\\begin{align}\n    X(e^{j \\omega}) &= \\sum_{k' \\geqslant 1} -b^{-k'} e^{j \\omega k'} \\\\\n    &= \\sum_{k \\geqslant 0} -(b^{-1} e^{j \\omega})^k - 1 \\\\\n    &= 1 - \\frac{1}{1 - b e^{j \\omega}} \\\\\n    &= \\frac{\\cancel{1} - b e^{j \\omega} - \\cancel{1}}{1 - b e^{j \\omega}} \\cdot \\frac{-b e^{-j \\omega}}{-b e^{-j \\omega}} \\\\\n    &= \\frac{1}{1 - b e^{-j \\omega}}\n\\end{align}\nwhere \\(|b^{-1}| < 1 \\implies |b| > 1\\).\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= 2e^{-j \\omega} \\frac{1}{1 - (-2) e^{-j \\omega}} \\\\\n    \\overset{\\mathcal{F}^{-1}}{\\implies} y[n] &= 2 (-(-2)^{n - 1} u[-(n - 1) - 1]) \\\\\n    &= (-2)^n u[-n]\n\\end{align}\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    H(z) = \\frac{1 - z^{-1}}{1 - 0.25z^{-2}} = \\frac{1 - z^{-1}}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})}\n\\end{equation}\n\n\\subsection{}\n\nUsing the \\(z\\)-transform multiplication property,\n\\begin{equation}\n    Y(z) = H(z) X(z) = \\frac{\\cancel{1 - z^{-1}}}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1}) \\cancel{(1 - z^{-1})}} = \\frac{1}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})}\n\\end{equation}\nThen, using partial fraction decomposition,\n\\begin{align}\n    Y(z) &= \\frac{1}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})} = \\frac{A}{1 - 0.5z^{-1}} + \\frac{B}{1 + 0.5z^{-1}} \\\\\n    &= 1 = A(1 + 0.5z^{-1}) + B(1 - 0.5z^{-1}) \\\\\n\\end{align}\nLetting \\(z = -0.5\\), we get \\(B = \\frac{1}{2}\\).\nLetting \\(z = 0.5\\), we get \\(A = \\frac{1}{2}\\).\nThen,\n\\begin{align}\n    Y(z) &= \\frac{1}{2} \\frac{1}{1 - 0.5z^{-1}} + \\frac{1}{2} \\frac{1}{1 + 0.5z^{-1}} \\\\\n    \\overset{\\mathcal{Z}^{-1}}{\\implies} y[n] &= \\frac{1}{2} \\left(\\frac{1}{2}\\right)^n u[n] + \\frac{1}{2} \\left(-\\frac{1}{2}\\right)^n u[n]\n\\end{align}\n\n\\subsection{}\n\n\\begin{equation}\n    y[n] = \\delta[n] - \\delta[n - 1] \\overset{\\mathcal{Z}}{\\implies} Y(z) = 1 - z^{-1} = H(z) X(z)\n\\end{equation}\nmeaning that \\(X(z) = 1 - 0.25z^{-2} = (1 - 0.5z^{-1}) (1 + 0.5z^{-1})\\).\nBy definition of the \\(z\\)-transform,\n\\begin{equation}\n    x[n] = \\delta[n] - \\frac{1}{4} \\delta[n - 2]\n\\end{equation}\n\n\\subsection{}\n\nTreating the input as the real part of \\(z = e^{j 0.5 \\pi}\\),\n\\begin{equation}\n    H(e^{j 0.5 \\pi}) = \\frac{1 - e^{-j 0.5 \\pi}}{1 - 0.25e^{-j\\pi}} = 0.8 \\sqrt{2} e^{j \\frac{\\pi}{4}}\n\\end{equation}\nMeaning that the final output is\n\\begin{equation}\n    y[n] = 0.8 \\sqrt{2} \\cos\\left(0.5 \\pi n + \\frac{\\pi}{4}\\right)\n\\end{equation}\n\n\\newpage\n\\section{}\n\n\\begin{align}\n    x[n] &= -\\frac{1}{3} \\left(\\frac{1}{2}\\right)^n u[n] - \\frac{4}{3} 2^n u[-n - 1] \\\\\n    Y(z) &= \\frac{1 - z^{-2}}{\\left(1 - \\frac{1}{2} z^{-1}\\right) (1 - 2z^{-1})}\n\\end{align}\n\n\\subsection{}\n\n\\begin{equation}\n    X(z) = -\\frac{1}{3} \\frac{1}{1 - \\frac{1}{2} z^{-1}} + \\frac{4}{3} \\frac{1}{1 - 2z^{-1}}\n\\end{equation}\n\n\\subsection{}\n\n\\begin{equation}\n    R_y: \\frac{1}{2} < |z| < 2\n\\end{equation}\n\n\\subsection{}\n\nSimplifiying \\(X(z)\\),\n\\begin{align}\n    X(z) &= \\frac{1}{3} \\frac{-(1 - 2z^{-1}) + 4 \\left(1 - \\frac{1}{2} z^{-1}\\right)}{\\left(1 - \\frac{1}{2} z^{-1}\\right) (1 - 2z^{-1})} \\\\\n    &= \\frac{1}{3} \\frac{-1 + \\cancel{2z^{-1}} + 4 - \\cancel{2z^{-1}}}{\\left(1 - \\frac{1}{2} z^{-1}\\right) (1 - 2z^{-1})} \\\\\n    &= \\frac{1}{\\left(1 - \\frac{1}{2} z^{-1}\\right) (1 - 2z^{-1})} \\\\\n    \\implies Y(z) &= (1 - z^{-2}) X(z) = X(z) - z^{-2} X(z) \\\\\n    \\overset{\\mathcal{Z}^{-1}}{\\implies} y[n] &= x[n] - x[n - 2]\n\\end{align}\n\n\\subsection{}\n\n\\begin{equation}\n    H(z) = \\frac{Y(z)}{X(z)} = 1 - z^{-2} \\overset{\\mathcal{Z}^{-1}}{\\implies} h[n] = \\delta[n] - \\delta[n - 2]\n\\end{equation}\n\n\\newpage\n\\section{}\n\n\\begin{align}\n    X(z) &= \\frac{z^{-2}}{1 - 2.3z^{-1} + 1.6z^{-2} - 0.3z^{-3}} = \\frac{2.04}{1 + 0.3z^{-1}} - \\frac{3.47}{1 - z^{-1}} + \\frac{1.43}{(1 - z^{-1})^2} \\\\\n    \\overset{\\mathcal{Z}^{-1}}{\\implies} x[n] &= (-0.3)^n u[n] - 3.47 u[n] + 1.43 (n + 1) u[n + 1]\n\\end{align}\n\n\\newpage\n\\section{}\n\n\\begin{enumerate}\n    \\item System A, causal, stable, ROC: \\(|z| > 0.9\\)\n    \\item System B, non-causal, stable, ROC: \\(|z| < 1.111\\)\n    \\item System A, non-causal, unstable, ROC: \\(|z| < 0.9\\)\n\\end{enumerate}\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    Z(e^{j \\omega}) = \\frac{1}{2\\pi} \\int_{-\\pi}^\\pi X(e^{j \\theta}) Y(e^{j (\\omega - \\theta)}) \\, d\\theta\n\\end{equation}\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= \\pi \\sum_{k = -\\infty}^\\infty \\delta(\\omega - \\pi + 2\\pi k) + \\delta(\\omega + \\pi + 2\\pi k) \\\\\n    X(e^{j \\omega}) \\ast Y(e^{j \\omega}) &= \\frac{1}{2} \\int_{-\\pi}^\\pi X(e^{j \\theta}) \\sum_{k \\in \\Z} \\delta((\\omega - \\theta) - \\pi + 2\\pi k) + \\delta((\\omega - \\theta) + \\pi + 2\\pi k) \\, d\\theta \\\\\n    &= \\frac{1}{2} \\sum_{k \\in \\Z} \\int_{-\\pi}^\\pi X(e^{j \\omega}) (\\delta(\\omega - \\theta - \\pi + 2\\pi k) + \\delta(\\omega + \\theta + \\pi + 2\\pi k)) \\, d\\theta \\\\\n    &= \\frac{1}{2} \\sum_{k \\in \\Z} (X(e^{j (\\omega - \\pi + 2\\pi k)}) + X(e^{j (\\omega + \\pi + 2\\pi k)}))\n\\end{align}\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel={\\(\\frac{\\omega}{\\pi}\\)}, ylabel={\\(Z(e^{j \\omega})\\)},\n            title={DTFT of Product},\n            axis lines=middle,\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=index, y=8a\n        ]{q8.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= \\pi \\sum_{k = -\\infty}^\\infty \\delta\\left(\\omega - \\frac{\\pi}{2} + 2\\pi k\\right) + \\delta\\left(\\omega + \\frac{\\pi}{2} + 2\\pi k\\right) \\\\\n    X(e^{j \\omega}) \\ast Y(e^{j \\omega}) &= \\frac{1}{2} \\sum_{k \\in \\Z} \\left(X\\left(e^{j \\left(\\omega - \\frac{\\pi}{2} + 2\\pi k\\right)}\\right) + X\\left(e^{j \\left(\\omega + \\frac{\\pi}{2} + 2\\pi k\\right)}\\right)\\right)\n\\end{align}\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel={\\(\\frac{\\omega}{\\pi}\\)}, ylabel={\\(Z(e^{j \\omega})\\)},\n            title={DTFT of Product},\n            axis lines=middle,\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=index, y=8b\n        ]{q8.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= \\pi \\sum_{k = -\\infty}^\\infty \\delta\\left(\\omega - \\frac{\\pi}{4} + 2\\pi k\\right) + \\delta\\left(\\omega + \\frac{\\pi}{4} + 2\\pi k\\right) + \\delta\\left(\\omega - \\frac{3\\pi}{4} + 2\\pi k\\right) + \\delta\\left(\\omega + \\frac{3\\pi}{4} + 2\\pi k\\right) \\\\\n    X(e^{j \\omega}) \\ast Y(e^{j \\omega}) &= \\frac{1}{2} \\sum_{k \\in \\Z} \\left(X\\left(e^{j \\left(\\omega - \\frac{\\pi}{2} + 2\\pi k\\right)}\\right) + X\\left(e^{j \\left(\\omega + \\frac{\\pi}{2} + 2\\pi k\\right)}\\right)\\right)\n\\end{align}\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel={\\(\\frac{\\omega}{\\pi}\\)}, ylabel={\\(Z(e^{j \\omega})\\)},\n            title={DTFT of Product},\n            axis lines=middle,\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=index, y=8c\n        ]{q8c.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= \\pi \\sum_{k = -\\infty}^\\infty \\cancelto{1}{e^{j \\frac{\\pi}{2}}} \\delta(\\omega - \\pi + 2\\pi k) + \\cancelto{-1}{e^{-j \\frac{\\pi}{2}}} \\delta(\\omega + \\pi + 2\\pi k) \\\\\n    X(e^{j \\omega}) \\ast Y(e^{j \\omega}) &= \\frac{1}{2} \\sum_{k \\in \\Z} (X(e^{j (\\omega - \\pi + 2\\pi k)}) - X(e^{j (\\omega + \\pi + 2\\pi k)}))\n\\end{align}\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel={\\(\\frac{\\omega}{\\pi}\\)}, ylabel={\\(Z(e^{j \\omega})\\)},\n            title={DTFT of Product},\n            axis lines=middle,\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=index, y=8d\n        ]{q8.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    H(e^{j \\omega}) =\n    \\begin{cases}\n        j & \\omega \\in (-\\pi, 0) \\\\\n        0 & \\omega = 0 \\\\\n        -j & \\omega \\in (0, \\pi)\n    \\end{cases}\n\\end{equation}\n\n\\subsection{}\n\nFrom Table 2.1 of O\\&S, the symmetry properties of the DTFT imply that the Hilbert filter impulse response is purely \\emph{real and odd}.\n\n\\subsection{}\n\n\\begin{align}\n    X(e^{j \\omega}) &= \\pi (\\delta(\\omega - \\omega_0) + \\delta(\\omega + \\omega_0)) \\\\\n    Y(e^{j \\omega}) &= -j \\pi (\\delta(\\omega - \\omega_0) - \\delta(\\omega + \\omega_0)) \\\\\n    \\overset{\\mathcal{F}^{-1}}{\\implies} y[n] &= \\sin(\\omega_0 n)\n\\end{align}\n\n\\subsection{}\n\n\\begin{align}\n    Y(e^{j \\omega}) &= H(e^{j \\omega})^2 X(e^{j \\omega}) =\n    \\begin{cases}\n        -X(e^{j \\omega}) & \\omega \\in (-\\pi, 0) \\\\\n        0 & \\omega = 0 \\\\\n        -X(e^{j \\omega}) & \\omega \\in (0, \\pi)\n    \\end{cases} \\\\\n    &= -X(e^{j \\omega}) \\overset{\\mathcal{F}^{-1}}{\\implies} y[n] = -x[n]\n\\end{align}\n\n\\subsection{}\n\n\\begin{center}\n    \\includegraphics[width=0.6\\textwidth]{q9d.png}\n\\end{center}\nwhere \\(\\mathcal{H}\\) is the Hilbert transform.\n\n\\end{document}\n", "meta": {"hexsha": "8bc71dc75904fccbfdb04e71e611a47b37c02621", "size": 9368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw02/hw02.tex", "max_stars_repo_name": "bdngo/ee-123", "max_stars_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw02/hw02.tex", "max_issues_repo_name": "bdngo/ee-123", "max_issues_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw02/hw02.tex", "max_forks_repo_name": "bdngo/ee-123", "max_forks_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_forks_repo_licenses": ["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.0821917808, "max_line_length": 267, "alphanum_fraction": 0.5042698548, "num_tokens": 3954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.628790301761609}}
{"text": "%\\section{Stabilization and Weak Formulation}\n\\label{app:stab}\n\nThis appendix details the weak formulation of the Navier Stokes\nequations instantiated in the software GRINS, and provides a\nderivation of the $\\tau$ stabilization terms shown in\nEquation~\\ref{eq:tau}.  \n\nIn brief, our process is the following: \n\n\\begin{itemize}\n \\item Cast Navier Stokes + Boussinesq equations into weak form\n \\item Prepare as an operator $L\\,{\\bf c}={\\bf f}$\n \\item Calculate Fr\\'echet derivative\n \\item Separate into differential (P) and constant (Z) components,\n       $L'[{\\bf c}] = P + Z$\n \\item Choose stabilization operator such that $S = -P^*$\n \\item Then stabilization has form, $a_h({\\bf c},{\\bf \\phi}) = a({\\bf c},{\\bf \\phi}) + \\langle\n       L{\\bf c},S{\\bf \\phi} \\rangle_\\tau$\n\\end{itemize}\n\nThis is essentially the least-squares stabilization proposed by Hughes\nand extended to natural convection by Becker and Braack. \n\n%\n% start the real work\n%\n\n\\section{Weak Formulation of the Equations of Interest}\n\nWe begin with the incompressible Navier-Stokes equations with Boussinesq\nbuoyancy,\n\\begin{align}\n \\nabla \\cdot {\\bf u} &= \\, 0 \\label{eq_cont}\\\\\n \\frac{\\partial {\\bf u}}{\\partial t} + {\\bf u} \\cdot \\nabla {\\bf u} &= -\\frac{1}{\\rho}\n \\nabla p + \\nu \\nabla^2 {\\bf u} + g \\frac{T'}{T_0} \\label{eq_mom}\\\\\n \\rho c_p \\frac{\\partial T}{\\partial t} + {\\bf u} \\cdot \\nabla T &= \\nabla\n \\cdot (k \\nabla T) \\label{eq_energy}\n\\end{align}\ne.g. the continuity, momentum and energy equations, respectively. Our \nstate vector is ${\\bf c} =  \\left[p,{\\bf u},T \\right]$. To cast these into\nweak form we multiply by appropriate test \nfunctions ${\\bf \\phi} = \\left[q,{\\bf v},w \\right] \\in H^1_0(\\Omega)$ and\nintegrate over the domain, $\\Omega \\in \\mathbb{R}^n$. Our system of\nequations now appears as, \n\\begin{align}\n  \\bigintsss_\\Omega q \\nabla \\cdot {\\bf u} \\, dx &= 0 \\\\\n \\bigintsss_\\Omega \\dot {\\bf u} \\cdot {\\bf v} \\, dx +\n \\bigintsss_\\Omega  ({\\bf u} \\cdot \\nabla) \\, {\\bf u} \\cdot {\\bf v} \\, dx &=\n \\bigintsss_\\Omega \\frac{p}{\\rho} \\nabla \\cdot {\\bf v} \\, dx -\n \\bigintsss_\\Omega \\nu \\, \\nabla {\\bf u} \\cdot \\nabla {\\bf v}\n \\,dx + \\bigintsss_\\Omega g \\frac{T'}{T_0} \\cdot {\\bf v} \\, dx \\\\ \n \\rho c_p \\bigintsss_\\Omega \\dot T \\cdot w \\, dx + \\bigintsss_\\Omega ({\\bf u}\n \\cdot \\nabla) T \\cdot w \\, dx  &= -\\bigintsss_\\Omega (k \\nabla T) \\cdot\n \\nabla w \\, dx\n\\end{align}\n%\nwhere an ``over-dot'' denotes time differentiation, e.g. $\\dot {\\bf u} =\n\\frac{\\partial {\\bf u}}{\\partial t}$. Note that both the pressure term as well\nas the viscous term were integrated by parts to reduce the required\norder of the solution on those state variables.  \n\nThe inner product is abbreviated by the shorthand notation $({\\bf u},{\\bf v}) =\n\\bigintsss_\\Omega {\\bf u}\\cdot {\\bf v}\\, dx $, giving our equations the form,  \n\\begin{align}\n (\\nabla \\cdot {\\bf u}, q) &= 0 \\\\\n (\\dot {\\bf u},{\\bf v}) + ({\\bf u} \\cdot \\nabla {\\bf u}, {\\bf v}) -\n (p,\\nabla \\cdot {\\bf v}) + (\\nu \\, \\nabla\n {\\bf u}, \\nabla {\\bf v}) &= (g \\frac{T'}{T_0},{\\bf v}) \\\\\n \\rho c_p (\\dot T,w) + ({\\bf u} \\cdot \\nabla T,w) + (k \\nabla T,\\nabla w) &= 0.\n\\end{align}\n%\nThis defines our weak form operator, $ a({\\bf c},{\\bf \\phi})$. Our full equations will\nalso include a stabilization term such that,  \n\\begin{equation}\n a_h({\\bf c},{\\bf \\phi}) = a({\\bf c},{\\bf \\phi}) +  \\langle L\\,{\\bf c},S{\\bf \\phi} \\rangle_\\tau. \n\\end{equation}\n%\nThe subsequent section will define the operators L and S, so that we\nmight then fully define the stabilization term $\\langle L\\,{\\bf c},S{\\bf \\phi}\n\\rangle_\\tau$. \n\n%\n% section\n%\n\\section{The Stabilization Operators, L and S}\n\n\nTo form the stabilization terms, \n\n\\begin{equation}\n \\langle L\\,{\\bf c},S{\\bf \\phi} \\rangle_\\tau\n\\end{equation}\n\nwe must define the operators L and S. The operator L is simply the PDEs\nin Equations \\ref{eq_cont} - \\ref{eq_energy} written in operator form. S is\ndefined as the negative adjoint of the differential terms in L, e.g.\n\\begin{align}\n L'[{\\bf c}] = P + Z \\\\\n S = -P^*. \n\\end{align}\nWhere P are the differential terms, and Z the constant terms. \n\nOur objective is now to construct the adjoint operator of L. This is\naccomplished using the Fr\\'echet derivative, which defines the\nfunctional derivative on L. In general this is accomplished by taking\nthe first variation of a function $\\Pi({\\bf u})$ around a base state, ${\\bf u}$,\n\\begin{equation}\n \\delta\\, \\Pi({\\bf u}) = \\lim_{\\epsilon \\to 0} \\frac{\\Pi({\\bf\n  u}+\\epsilon \\, \\hat {\\bf u}) -\n  \\Pi({\\bf u})}{\\epsilon} =\n  \\frac{\\partial \\Pi({\\bf u} +\\epsilon \\, \\hat {\\bf u})}{\\partial \\epsilon}\n  \\bigg|_{\\epsilon = 0}\n\\end{equation}\n$\\forall \\hat {\\bf u}, \\epsilon > 0$ with ${\\bf u} + \\epsilon \\, \\hat {\\bf u} \\in\nH^1_0(\\Omega)$. This is recognizable as the G\\^{a}teaux\nderivative of the functional. \n\nWe now consider the first variation of state for the momentum equation\nterm by term. The convective term is, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} ({\\bf u} + \\epsilon \\, \\hat {\\bf u}) &\\cdot \\nabla\n  ({\\bf u} + \\epsilon \\hat {\\bf u}) \\\\\n = \\lim_{\\epsilon \\to 0} \\, \\hat {\\bf u} &\\cdot \\nabla ({\\bf u} + \\epsilon \\,\\hat {\\bf u}) \\\\\n = \\hat {\\bf u} & \\cdot \\nabla {\\bf u} \\\\\n = - {\\bf u} &\\cdot \\nabla \\hat {\\bf u}\n\\end{align}\nand the viscous term is, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\nabla^2 ({\\bf u} + \\epsilon \\, \\hat {\\bf u}) \\\\\n = \\nabla^2 \\hat {\\bf u}\n\\end{align}\nwhile the buoyancy term is, \n\\begin{align}\n \\delta \\left(-g \\frac{T'}{T_0}\\right) &= \\delta \\left( -g\n \\frac{T-T_0}{T_0} \\right) \\\\\n &= -g \\frac{\\partial}{\\partial \\epsilon} \\left( \\frac{T-T_0+\\epsilon\n \\hat T}{T_0} \\right) \\\\\n &= -g \\left( \\frac{\\hat T}{T_0} \\right) \n\\end{align}\n%\n%\n%Lagrangian is therefore, $\\mathcal{L}$\nand thus the full adjoint equation for momentum appears as,\n\\begin{align}\n - {\\bf u} &\\cdot \\nabla \\hat {\\bf u} - \\nabla^2 \\hat {\\bf u} = -\\frac{1}{\\rho} \\nabla p. \n\\label{eq_adjmom}\n\\end{align}\n%\nThe continuity equation is straightforward, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\nabla \\cdot ({\\bf u} + \\epsilon \\,\n \\hat {\\bf u}) &= 0, \\\\\n\\nabla \\cdot \\hat {\\bf u} &= 0.\n\\label{eq_adjcont}\n\\end{align}\n%\nFinally, consider the convective term of the energy equation, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} {\\bf u} \\cdot \\nabla (T + \\epsilon\n \\, \\hat T)\n = {\\bf u} \\cdot \\nabla \\hat T\n\\end{align}\nand the thermal diffusion term, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\cdot (-k \\nabla (T + \\epsilon \\hat\n T)) = \\nabla \\cdot (-k \\nabla \\hat T).\n\\end{align}\nThe full adjoint energy equation is therefore, \n\\begin{align}\n {\\bf u} \\cdot \\nabla \\hat T + \\nabla \\cdot (k \\nabla \\hat T) = 0.\n\\label{eq_adjen}\n\\end{align}\n\nWe are now in a position to define the matrices L and S. L comes\ndirectly from the PDEs in Equations \\ref{eq_cont} - \\ref{eq_energy} and is\ndefined as thus, \n\n\\begin{equation}\n\\renewcommand\\arraystretch{2}\n L = \n  \\begin{pmatrix}\n    0 & \\nabla \\cdot () & 0   \\\\\n    \\nabla \\,() & {\\bf u} \\cdot \\nabla() - \\nu \\nabla^2() & -g \\frac{()}{T_0}  \\\\\n    0 & 0 & {\\bf u} \\cdot \\nabla() - \\nabla \\cdot (k \\nabla() \\,)\n  \\end{pmatrix}.\n\\end{equation}\n%\nWhile the S matrix is constructed from Equations~\\ref{eq_adjmom},\n\\ref{eq_adjcont}, and \\ref{eq_adjen}, and must be,  \n\\begin{equation}\n\\renewcommand\\arraystretch{2}\n S = -P^* = \n  \\begin{pmatrix}\n    0 & \\nabla \\cdot () & 0   \\\\\n    \\nabla \\,() & {\\bf u} \\cdot \\nabla() + \\nu \\nabla^2() &  -g \\frac{()}{T_0}  \\\\\n    0 & 0 & {\\bf u} \\cdot \\nabla() + \\nabla \\cdot k \\nabla()\n  \\end{pmatrix}.\n\\end{equation}\n\n%\n% tau!\n%\n\\section{Tau Stabilization Terms}\n\nFinally, we may now form the $\\tau$ stabilization terms, \n\\begin{equation}\n \\langle L\\, {\\bf c},S{\\bf \\phi} \\rangle_\\tau. \n\\end{equation}\nWhere the operator $ \\langle \\cdot,\\cdot \\rangle_\\tau. $ is shorthand \nand denotes\n\\begin{equation}\n \\langle {\\bf u},{\\bf v} \\rangle_\\tau = \\sum_K \\tau_K ({\\bf u},{\\bf v})_K.\n\\end{equation}\nWhere $K$ denotes the FEM cells. Now, through what Becker and Braack\ncontemptibly referred to as ``elementary calculus'', we arrive at our\nstabilization terms,  \n\\begin{align*}\n \\langle L\\,{\\bf c},S{\\bf \\phi} \\rangle_\\tau = \\sum_K \\{ \\quad &\\tau_p (\\nabla \\cdot {\\bf u},\n \\nabla \\cdot {\\bf v}) \\\\\n +\\quad &\\tau_u \\,(\\nabla p + {\\bf u} \\cdot \\nabla {\\bf u} - \\nu\n \\nabla^2 {\\bf u} - g \\frac{T'}{T_0},\n \\nabla q) \\\\\n +\\quad &\\tau_u \\, (\\nabla p + {\\bf u} \\cdot \\nabla {\\bf u} - \\nu \\nabla^2 {\\bf u}- g \\frac{T'}{T_0},\n \\nabla {\\bf u} \\cdot \\nabla {\\bf v} + \\nu \\nabla^2 {\\bf v}) \\\\\n +\\quad &\\tau_T \\, ({\\bf u} \\cdot T - \\nabla \\cdot (k \\nabla T), \\nabla {\\bf u} \\cdot \\nabla\n w + \\nabla \\cdot (k \\nabla w)) \\quad \\}.\n\\end{align*}\n\n", "meta": {"hexsha": "4404f10d1893501a0f7dbbb33b43f3026cb6ec18", "size": 8590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/dissertation/appendix-derivation.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/dissertation/appendix-derivation.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/dissertation/appendix-derivation.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 37.347826087, "max_line_length": 101, "alphanum_fraction": 0.6332945285, "num_tokens": 3118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6287902921360464}}
{"text": "\\documentclass{amsproc}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage[cmtip,all]{xy}\n\n\\copyrightinfo{2016}{Todd D. Vance}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}[theorem]{Definition}\n\\newtheorem{example}[theorem]{Example}\n\\newtheorem{xca}[theorem]{Exercise}\n\n\\theoremstyle{remark}\n\\newtheorem{remark}[theorem]{Remark}\n\n\\numberwithin{equation}{section}\n\n\\begin{document}\n\\title{A Geometric Algebra Primer}\n\\author[T. D. Vance]{Todd D. Vance}\n%\\address{15 Lilac Dr \\\\ Moorefield, WV 26836}\n%\\email{tdvance@gmail.com}\n\\date{\\today}\n\n\\begin{abstract}\n  A brief introduction to Geometric Algebra with an emphasis on algorithms.\n\\end{abstract}\n\n\\maketitle{}\n\n\\newcommand{\\term}[1]{\\emph{#1}}\n\n\\newcommand{\\ga}{\\ensuremath{\\mathop{\\mathrm{GA}}}}\n\n\\section{definitions}\n\n\\begin{definition}[Geometric Algebra]\n  The \\term{geometric algebra} $\\ga(n)$ of \\term{ambient rank} $n$ is\n  the quotient algebra $\\mathbf{R}\\{[1], [2], \\dots, [n]\\}/I$, where\n  $\\mathbf{R}\\{[1], [2], \\dots, [n]\\}$ is the free (unital,\n  associative, noncommutative) algebra over the real field\n  $\\mathbf{R}$ generated by noncommuting elements $[1], [2], \\dots,\n  [n]$, and $I$ is the (two-sided) ideal of $\\mathbf{R}\\{[1], [2],\n  \\dots, [n]\\}$ generated by the set of elements of the form $[i][i] -\n  1$ and of the form $[i][j] - [j][i]$ when $i\\ne{j}$.\n\\end{definition}\n\nThe multiplication operator in $\\ga(n)$ is called the \\term{geometric\n  product} and is written by juxtaposition: $ab$ is the product of $a$\nand $b$, in that order.  An (equivalence class of the) element of\n$\\ga(n)$ of the form $[i_1][i_2]\\cdots[i_m]$ is abbreviated\n$[i_1i_2\\cdots{i}_m]$ and is called a \\term{basis blade}.  As a\nspecial case, the empty basis blade $[]$ is defined to be the\nmultiplicative identity $1$.\n\n\\begin{example}\nA commonly-used geometric algebra in graphics applications is $\\ga[3]$\nof ambient rank $3$.  The algebra is generated by the elements $[1]$,\n$[2]$, and $[3]$.  Clearly $[1][1] = [] = 1$, $[1][2]=-[2][1]$, and so\non.  From this one finds that $\\ga(3)$ is an eight-dimensional vector\nspace with basis $\\{[], [1], [2], [3], [12], [13], [23], [123]\\}$.  A\ntypical element of $\\ga(3)$ is then equal to $s[] + a[1] + b[2] + c[3]\n+ A[23] + B[13] + C[12] + S[123]$ where $s, a, b, c, A, B, C,$ and $S$\nare real numbers.\n\nWe consider elements of $\\ga(3)$ of the form $a[1]+b[2]+c[3]$ to be\nvectors (or rank one elements) and this three-dimensional vector space\nis the geometric entity $\\ga(3)$ models.  Elements of the form $s[]$,\nalso just written $s$, are scalars (or rank zero elements), so in a\ngeometric algebra, one can add a scalar to a vector.  Elements of the\nform $A[23] + B[13] + C[12]$ are bivectors (rank two elements), which\nmodel oriented plane regions with an area magnitude.\n\nJust as a vector has direction and magnitude, and one considers two\nvectors having the same direction and magnitude to be equal even if\nthey have different locations in three-space, a bivector has a\ncontaining plane, one of two orientations on that plane, and an area,\nso two planar regions having the same area, contained in parallel or\nequal planes, and given the same orientation (which may be thought of\nas clockwise versus counterclockwise) are considered to be the same\nbivector.\n\nElements of the form $S[123]$ are considered volume elements (rank\nthree elements), also called pseudoscalars because they have one\ndegree of freedom in three-dimensional space.  A volume element only\nhas magnitude and orientation (positive or negative, which may be\nthought of as being a right-handed or left-handed coordinate system).\n\nAddition of two elements expressed in the linear combination form\nmentioned above is done by combining like terms.  If $x = 4 + 3[1] +\n4[2] + 5[12]$ and $y = 3 + 2[1] + 3[2] + 4[12]$, then\n$x+y = 7 +5[1] +7[2] + 9[12]$.\n\nMultiplication works like polynomial multiplication, except without\ncommutativity, and using the rules of converting products of blades\ninto the standard ones $[]=1$, $[1]$, $[2]$, $[12]$, $[3]$, $[13]$,\n$[23]$, and $[123]$.  So, using the same $x$ and $y$ as above, to find\n$xy$, one multiplies every term of $x$ by every term of $y$, then\nreduces and combines like terms:\n\\begin{alignat*}{4}\n  xy &=&&12 + 8[1] + 12[2] +16[12]\\\\\n  && +~ & 9[1] + 6[1][1] + 9[1][2] + 12[1][12]\\\\\n  && +~ & 12[2] + 8[2][1] + 12[2][2] + 16[2][12]\\\\\n  && +~ & 15[12] + 10[12][1] + 15[12][2] + 20[12][12]\\\\\n  &=&&12 + 8[1] + 12[2] + 16[12]\\\\\n  && +~ &9[1] + 6 + 9[12] + 12[2]\\\\\n  && +~ & 12[2] - 8[12] + 12 - 16[1]\\\\\n  && +~ & 15[12] - 10[2] + 15[1] - 20\\\\\n  &=&& 10 + 16[1] + 26[2] + 32[12]\n\\end{alignat*}\n\\end{example}\n\n\\subsection{Standard Basis Blades}\n\nGeneralizing from the example, we see that swapping adjacent unequal\nindices of a basis blade changes its sign and deleting pairs of\nadjacent, equal indices does not change the element.  Thus, all basis\nblades in $\\ga(n)$ are either plus or minus a \\term{standard} basis\nblade $[i_1i_2\\cdots{i}_m]$ ($m \\le n$) in which the indices are in\nincreasing order and there are no duplicate indices.  In this case,\nthe \\term{rank} of the basis blade is $m$.  Any element of $\\ga(n)$\ncan be written uniquely (up to ordering of terms) as a linear\ncombination of standard basis blades (including $[]$, the rank-zero\nempty basis blade equal to $1$ in the algebra), and the rank of that\nelement is the maximum rank among the basis blades in the linear\ncombination.  The rank of the $0$ element is defined to be $-\\infty$.\nThus, $\\ga(n)$ is an algebra filtered by rank.\n\nA nonzero element of $\\ga(n)$ that is a linear combination of standard\nbasis blades of the same rank $r$ is said to be \\term{purely} of rank\n$r$.  Rank 0 elements (that is, pure rank 0 elements along with the 0\nelement) are called \\term{scalars}.  Pure rank 1 elements (along with\n0) are called \\term{vectors}.  Pure rank two elements (along with 0)\nare called \\term{bivectors}, and so on.  All elements are called\n\\term{multivectors}. When the ambient rank is $n$, rank $n$ elements\n(along with 0) are called \\term{pseudoscalars}, rank $n-1$ elements\n(along with 0) are called \\term{pseudovectors}, and so on.\n\nThe algebra $\\ga(n)$ is generated, as a vector space, by the standard\nbasis blades $[]$, $[1]$, $[2]$, $\\dots$, $[n]$, $[12]$, $\\dots$\n$[123\\dots{n}]$, of which there are $2^n$, so as a real vector\nspace, $\\ga(n)$ has dimension $2^n$.\n\nIn addition to the geometric product, other products are defined in\n$\\ga(n)$.  The \\term{inner product} is the symmetric component of the\ngeometric product: $a\\cdot{b} = \\frac{ab+ba}{2}$.  The \\term{outer\n  product} is the antisymmetric component of the geometric product:\n$a\\wedge{b}=\\frac{ab-ba}{2}$.  As the names imply,\n$a\\cdot{b}=b\\cdot{a}$, and $a\\wedge{b} = -b\\wedge{a}$.  Then, $ab =\na\\cdot{b} + a\\wedge{b}$.\n\n\\subsection{Additional Operations}\n\nNote that for vectors, $a\\cdot{b}$ is exactly the standard dot\nproduct, using $\\{[1], [2], \\dots, [n]\\}$ as the standard ordered\nbasis.  For vectors in $\\ga(3)$, the wedge product has the same\nmagnitude as the cross product, but is a bivector (pseudovector)\nrather than a vector.  Also, the wedge product is defined in any\nnumber of dimensions, not just three, and for non-vector elements as\nwell.\n\nThe \\emph{standard pseudoscalar} $I$ of $\\ga(n)$ is defined to be the\nrank-$n$ standard basis blade $[123\\dots{n}]$.  Then, $I^2 = II$ must\neither be $-1$ or $1$, so $I^4=1$ regardless of $n$.  In particular,\nthe subalgebra of $\\ga(2)$ generated by $[]$ and $I$ is isomorphic to\nthe complex number field.  In fact $I^2=-1$ in $\\ga(2)$ and the\nisomorphism maps $1$ to $[]$ and $\\imath$ to $I$.  In addition,\n$\\ga(3)$ contains a subalgebra isomorphic to the quanternion algebra.\nThis subalgebra is generated by $[]$, $i=[23]$, $j=[13]$, and\n$k=[12]$, with $[]$ maping to 1 and $i$, $j$, and $k$ mapping to the\nsame-named elements of the quaternion ring.\n\nThe \\term{norm} $|a|$ of an element $a\\in\\ga(n)$ is defined to be the\nsquare root of the sum of the squares of the coefficients of the\nstandard basis blades making up the linear combination.  Note for\nvectors this reduces to the usual norm for vectors.\n\nThe \\term{reversion} $\\tilde{a}$ of an element $a\\in \\ga(n)$ is formed\nfrom $a$ by taking the linear combination of standard basis blades\ncomposing $a$, and then reversing the order of multiplication of the\nalgebra generators in each term: $[i_{j_1}][i_{j_2}]\\cdots[i_{j_m}]$\n$\\rightarrow$ $[i_{j_m}][i_{j_{m-1}}]\\cdots[i_{j_1}]$.  Equivalently,\neach term of $a$ of pure rank $r$, where $r$ is congruent to $2 $ or\n$3$ modulo $4$, is negated.\n\nThe \\term{grade projection} $\\mathrm{proj}_k(a)$ of an element $a\\in \\ga(n)$ is\nformed from $a$ by deleting all terms of pure rank not equal to $k$.\n\nThe \\term{left inverse} of $a\\in \\ga(n)$ is an element $b$ satisfying\n$ba=1=[]$ and the \\term{right inverse} $c$ likewise satisfies $ac=1$.\nWe use $a^{-1}$ to represent an element that is both the left and right\ninverse of $a$.  If $a{\\tilde{a}}$ is a nonzero scalar, then\n$\\frac{a}{a{\\tilde{a}}}$ is well-defined by dividing each coefficient of\n$a$ by the scalar denominator.  In such a case, $a$ does have a\ntwo-sided inverse and $a^{-1} = \\frac{a}{a{\\tilde{a}}}$.\n\nThe \\term{dual} of an element $a$ of $\\ga(n)$ is $aI^{-1}$.  Note that\n$I^{-1}$ exists and is equal to $I^3$, which is either $I$ or $-I$.\nNote that the dual of a scalar is a psuedoscalar, the dual of a vector\nis a pseudovector, and so on.  The double dual of $a$ is either $a$ or\n$-a$.\n\nNote that in $\\ga(3)$, $a\\wedge{b}I^{-1}$ is a vector, and is equal to\nthe vector space cross product $a\\times{b}$.  Thus, we define a\n\\term{generalized cross product} on any $\\ga(n)$ to be\n$a\\times{b}=a\\wedge{b}I^{-1}$, the dual of the wedge product.  In\ndimensions other than 3, the cross product of vectors is no longer a\nvector.  However, in $n$ dimensions, one can take the dual of the\nwedge product of $n-1$ vectors to give a vector which geometrically is\nsimilar to the cross product in three dimensions.\n\nThe \\term{exponential} of $a\\in{\\ga}(n)$ is computed as follows.  If\n$a=0$, $e^0=1$ by definition.  Otherwise, let $\\theta=|a|$ and\n$b=a/\\theta$.  Then use DeMoivre's formula with $b$ taking the role of\nthe imaginary unit: $e^a = \\cos\\theta + b\\sin\\theta$.  The inverse of\nthis operation, a geometric algebraic logarithm, is difficult and\nmultivalued, even more so than with complex numbers.\n\nThe main use for the exponential is in computing a \\term{rotor}.  If\n$v$ and $w$ are linearly-independent unit vectors (that is,\n$|v|=|w|=1$) in the $n$-dimensional vector space whose basis is the\nrank-one standard blades, then $vw$ is a bivector that represents an\noriented plane in the $n$-dimensional space.  A rotation about the\norigin in the direction from $v$ to $w$ along an angle $theta$ is then\nmodeled by the \\term{rotor} $r$ in $\\ga(n)$ that is $r =\ne^{\\frac12vw\\theta}$.  Then if $a$ is any element (vector or\notherwise) of $\\ga(n)$, its rotation is then $ra{\\tilde{r}}$.  If $a$\nis a vector, so is $ra{\\tilde{r}}$, and this is an ordinary vector\nrotation.  If $a$ is a bivector representing an oriented plane,\n$ra{\\tilde{r}}$ is the rotation of the plane.  And so on.\n\nThe \\term{meet} of two elements $a$ and $b$ in $\\ga(n)$ is defined by\n$aI^{-1}b$, or the product of the dual of $a$ with $b$.\n\n\\section{Algorithms}\n\\newcommand{\\n}{\\ensuremath{\\mathop{\\mathrm{N}}}} An apparent way to\nrepresent a standard basis blade $a=[i_1i_2\\dots{i}_m]$ is via the\ninteger $\\n(a)$ defined to be $\\sum_{k=1}^{m}2^{i_k}$.  Then, the\nproduct $ab$ of $a=[i_1i_2\\dots{i}_m]$ and $b=[j_1j_2\\dots{j}_r]$\ncan be computed as follows:\n\n\\begin{enumerate}\n\\item If $m=0$, let $c$ be the multivector $b$ and return $c$\n\\item If $r=0$, let $c$ be the multivector $a$ and return $c$\n\\item Let $c$ be the blade for which $\\n(c)$ is the bitwise exclusive\n  or of $\\n(a)$ and $\\n(b)$.\n\\item Let $s$ be 1.\n\\item Let $p$ be the maximum of $\\n(a)$ and $\\n(b)$.\n\\item Let $d$ be $m$\n\\item Let $e$ be $1$\n\\item while $e\\le{p}$, do the following:\n  \\begin{enumerate}\n  \\item Compute the bitwise and of $e$ and $\\n(a)$.\n  \\item If the result of the bitwise and is nonzero, then replace $d$ with $d-1$.\n  \\item If $d$ is odd, Compute the bitwise and of $e$ and $\\n(b)$.\n  \\item If $d$ is odd and the result of the bitwise and is nonzero\n    then replace $s$ with $-s$.\n  \\item Replace $e$ with $2e$.\n  \\end{enumerate}\n\\item Let $c$ be the multivector that is the real coefficient $s$\n  multiplied by the blade given by $c$, and return $c$.\n\\end{enumerate}\n\nA standard basis blade is simply a nonnegative integer in this\nrepresentation.  A choice needs to be made to represent a multivector,\na real linear combination of these blades.\n\nThe \\term{dense} representation of a multivector in $\\ga(n)$ is an\narray $A$ of dimension $2^n$, thus having elements $A_0$, $A_1$, and\nso on up to $A_{2^n-1}$.  Then, a multivector $\\sum_{i=1}^{l}c_ib_i$,\nwhere the $c_i$ are real numbrers and the $b_i$ are standard basis\nblades in $\\ga(n)$, is represented by the array $A$ in which for\n$1\\le{i}\\le{l}$, $A_{\\n(b_i)} = c_i$, and all other elements of $A$\nare zero.\n\nThe dense representation requires little computation, but uses\n$O(2^n)$ memory per element of $\\ga(n)$, so it is useful for low\ndimensionality, such as in representing the commonly-used $\\ga(3)$.\n\nFor larger dimensions, a \\term{sparse} representation is needed.  Let\n$D$ be a \\term{dictionary}, algorithmically represented by a hash\ntable in most cases, but mathematically works like the array: for any\nnonnegative integer $i$, $D_i$ is a real number.  For most $i$, this\nreal number is zero and thus $i$ has no entry in the hash table.  Only\nwhen $D_i$ is nonzero is there an entry in the hash table with key $i$\nand value $D_i$. \n  \nThen, a multivector $\\sum_{i=1}^{l}c_ib_i$, where the $c_i$ are real\nnumbrers and the $b_i$ are standard basis blades in $\\ga(n)$, is\nrepresented by the dictionary $D$ in which for $1\\le{i}\\le{l}$,\n$D_{\\n(b_i)} = c_i$, and no other entries are present in $D$ (so that\nthe dictionary returns the default value of 0 for those).\n\nThe sparse representation requires a small amount of computation for\nhashing and, sometimes, rebuilding the table, but only requires $O(l)$\nmemory for an element of $\\ga(n)$ having $l$ nonzero terms.  Thus, the\nsparse representation is most useful for large $n$ when many elements\nare such that most standard basis blades have a zero coefficient.\n\nIn both cases, the addition procedure is evident and involves adding\nthe values from one array or dictionary to the same-indexed values of\nthe other.\n\nThe geometric product, however, requires an all-to-all mapping of\narray or dictionary elements.  We illustrate the algorithm for the\narray case, with the dictionary case being nearly identical, just\niterating over keys in the hash table instead of over all integers in\nthe range from $0$ to $2^{n-1}$.\n\nSuppose $A$ and $B$ are arrays representing multivectors in $\\ga(n)$.\nWe compute a new array $C$ with $2^n$ entries representing the\ngeometric product of the multivectors $A$ and $B$.\n\n\\begin{enumerate}\n\\item Initialize $C$ to $C_0=C_1=\\cdots=c_{2^{n-1}}=0$.\n\\item For each $i$ from 0 to $2^{n-1}$ such that the coefficient $A_i$\n  is nonzero\n  \\begin{enumerate}\n  \\item For each $j$ from 0 to $2^{n-1}$ such that the coefficient\n    $B_j$ is nonzero\n    \\begin{enumerate}\n      \\item Let $k$ be the integer that is the result of multiplying\n        together the blades represented by $i$ and $j$, and let $s$ be\n        the coefficient, $1$ or $-1$, of the result.\n      \\item Let $C_k$ be $C_k + A_iB_js$, an ordinary sum and product\n        of real numbers.\n    \\end{enumerate}\n  \\end{enumerate}\n  \\item Return the multivector $C$.\n\\end{enumerate}\n\n\\bibliographystyle{amsplain}\n\n\\end{document}\n", "meta": {"hexsha": "8b2d251b5293ebab67302c4ebdc604591e0dc1b9", "size": 15849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/ga.tex", "max_stars_repo_name": "tdvance/GeometricAlgebra", "max_stars_repo_head_hexsha": "3e75c09674a817c1c1cc45a746a2089d1466ac08", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T08:09:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T02:27:49.000Z", "max_issues_repo_path": "doc/ga.tex", "max_issues_repo_name": "tdvance/GeometricAlgebra", "max_issues_repo_head_hexsha": "3e75c09674a817c1c1cc45a746a2089d1466ac08", "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/ga.tex", "max_forks_repo_name": "tdvance/GeometricAlgebra", "max_forks_repo_head_hexsha": "3e75c09674a817c1c1cc45a746a2089d1466ac08", "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.8905325444, "max_line_length": 81, "alphanum_fraction": 0.6915262793, "num_tokens": 5086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.62879029184777}}
{"text": "% !TEX root = lectures.tex\n\\section{Oscillations}\n\\bigskip\n\n\\subsection{Harmonic Oscillator}\n\nThe harmonic oscillator is omnipresent in physics. Although students think of this as being related to springs, it, or an equivalent mathematical representation, appears in just about any problem where a mode is sitting near its potential energy minimum. At that point, $\\partial_x V(x)=0$, and the first non-zero term (aside from a constant) in the potential energy is that of a harmonic oscillator. In a solid, sound modes (phonons) are built on a picture of coupled harmonic oscillators, and in relativistic field theory the fundamental interactions are also built on coupled oscillators positioned infinitesimally close to one another in space. The phenomena of a resonance of an oscillator driven at a fixed frequency plays out repeatedly in atomic, nuclear and high-energy physics, when quantum mechanically the evolution of a state oscillates according to $e^{-iEt}$ and exciting discrete quantum states has very similar mathematics as exciting discrete states of an oscillator.\n\nThe potential energy for a single particle as a function of its position $x$ can be written as a Taylor expansion about some point $x_0$\n\\begin{equation}\nV(x)=V(x_0)+(x-x_0)\\left.\\partial_xV(x)\\right|_{x_0}+\\frac{1}{2}(x-x_0)^2\\left.\\partial_x^2V(x)\\right|_{x_0}\n+\\frac{1}{3!}\\left.\\partial_x^3V(x)\\right|_{x_0}+\\cdots\n\\end{equation}\nIf the position $x_0$ is at the minimum of the resonance, the first two non-zero terms of the potential are\n\\begin{eqnarray}\nV(x)&\\approx& V(x_0)+\\frac{1}{2}(x-x_0)^2\\left.\\partial_x^2V(x)\\right|_{x_0},\\\\\n\\nonumber\n&=&V(x_0)+\\frac{1}{2}k(x-x_0)^2,~~~~k\\equiv \\left.\\partial_x^2V(x)\\right|_{x_0},\\\\\n\\nonumber\nF&=&-\\partial_xV(x)=-k(x-x_0).\n\\end{eqnarray}\n\nPut into Newton's 2nd law (assuming $x_0=0$),\n\\begin{eqnarray}\nm\\ddot{x}&=&-kx,\\\\\nx&=&A\\cos(\\omega_0 t-\\phi),~~~\\omega_0=\\sqrt{k/m}.\n\\end{eqnarray}\nHere $A$ and $\\phi$ are arbitrary. Equivalently, one could have written this as $A\\cos(\\omega_0 t)+B\\sin(\\omega_0 t)$, or as the real part of $Ae^{i\\omega_0 t}$. In this last case $A$ could be an arbitrary complex constant. Thus, there are 2 arbitrary constants (either $A$ and $B$ or $A$ and $\\phi$, or the real and imaginary part of one complex constant. This is the expectation for a second order differential equation, and also agrees with the physical expectation that if you know a particle's initial velocity and position you should be able to define its future motion, and that those two arbitrary conditions should translate to two arbitrary constants.\n\nA key feature of harmonic motion is that the system repeats itself after a time $T=1/f$, where $f$ is the frequency, and $\\omega=2\\pi f$ is the angular frequency. The period of the motion is independent of the amplitude. However, this independence is only exact when one can neglect higher terms of the potential, $x^3, x^4\\cdots$. Once can neglect these terms for sufficiently small amplitudes, and for larger amplitudes the motion is no longer purely sinusoidal, and even though the motion repeats itself, the time for repeating the motion is no longer independent of the amplitude.\n\nOne can also calculate the velocity and the kinetic energy as a function of time,\n\\begin{eqnarray}\n\\dot{x}&=&-\\omega_0A\\sin(\\omega_0 t-\\phi),\\\\\n\\nonumber\nT&=&\\frac{1}{2}m\\dot{x}^2=\\frac{m\\omega_0^2A^2}{2}\\sin^2(\\omega_0t-\\phi),\\\\\n\\nonumber\n&=&\\frac{k}{2}A^2\\sin^2(\\omega_0t-\\phi).\n\\end{eqnarray}\nThe total energy is then\n\\begin{equation}\nE=T+U=\\frac{1}{2}m\\dot{x}^2+\\frac{1}{2}kx^2=\\frac{1}{2}kA^2.\n\\end{equation}\nThe total energy then goes as the square of the amplitude.\n\n\\example\nA pendulum is an example of a harmonic oscillator. By expanding the kinetic and potential energies for small angles find the frequency for a pendulum of length $L$ with all the mass $m$ centered at the end by writing the eq.s of motion in the form of a harmonic oscillator.\n\n{\\bf Solution:} The potential energy and kinetic energies are (for $x$ being the displacement)\n\\begin{eqnarray*}\nU&=&mgL(1-\\cos\\theta)\\approx mgL\\frac{x^2}{2L^2},\\\\\nT&=&\\frac{1}{2}mL^2\\dot{\\theta}^2\\approx \\frac{m}{2}\\dot{x}^2.\n\\end{eqnarray*}\nFor small $x$ Newton's 2nd law becomes\n\\[\nm\\ddot{x}=-\\frac{mg}{L}x,\n\\]\nand the spring constant would appear to be $k=mg/L$, which makes the frequency equal to $\\omega_0=\\sqrt{g/L}$. Note that the frequency is independent of the mass.\n\n\\exampleend\n\n\\subsection{Damped Oscillators}\n\nIn this chapter we consider only the case where the damping force is proportional to the velocity. This is counter to dragging friction, where the force is proportional in strength to the normal force and independent of velocity, and is also inconsistent with wind resistance, where the magnitude of the drag force is proportional the square of the velocity. Rolling resistance does seem to be mainly proportional to the velocity. However, the main motivation for considering damping forces proportional to the velocity is that the math is more friendly. This is because the differential equation is linear, i.e. each term is of order $x$, $\\dot{x}$, $\\ddot{x}\\cdots$, or even terms with no mention of $x$, and there are no terms such as $x^2$ or $x\\ddot{x}$. The equations of motion for a spring with damping force $-b\\dot{x}$ are\n\\begin{equation}\nm\\ddot{x}+b\\dot{x}+kx=0.\n\\end{equation}\nJust to make the solution a bit less messy, we rewrite this equation as\n\\begin{equation}\n\\label{eq:dampeddiffyq}\n\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x=0,~~~~\\beta\\equiv b/2m,~\\omega_0\\equiv\\sqrt{k/m}.\n\\end{equation}\nBoth $\\beta$ and $\\omega$ have dimensions of inverse time. To find solutions (see appendix C in the text) you must make an educated guess at the form of the solution. To do this, first realize that the solution will need an arbitrary normalization $A$ because the equation is linear. Secondly, realize that if the form is\n\\begin{equation}\nx=Ae^{rt}\n\\end{equation}\nthat each derivative simply brings out an extra power of $r$. This means that the $Ae^{rt}$ factors out and one can simply solve for an equation for $r$. Plugging this form into Eq. (\\ref{eq:dampeddiffyq}),\n\\begin{equation}\nr^2+2\\beta r+\\omega_0^2=0.\n\\end{equation}\nBecause this is a quadratic equation there will be two solutions,\n\\begin{equation}\nr=-\\beta\\pm\\sqrt{\\beta^2-\\omega_0^2}.\n\\end{equation}\nWe refer to the two solutions as $r_1$ and $r_2$ corresponding to the $+$ and $-$ roots. As expected, there should be two arbitrary constants involved in the solution,\n\\begin{equation}\nx=A_1e^{r_1t}+A_2e^{r_2t},\n\\end{equation}\nwhere the coefficients $A_1$ and $A_2$ are determined by initial conditions.\n\nThe roots listed above, $\\sqrt{\\omega_0^2-\\beta_0^2}$, will be imaginary if the damping  is small and $\\beta<\\omega_0$. In that case, $r$ is complex and the factor $e{rt}$ will have some oscillatory behavior. If the roots are real, there will only be exponentially decaying solutions. There are three cases:\n\\begin{enumerate}\\itemsep 0pt\n\\item Underdamped: $\\beta<\\omega_0$\n\\begin{eqnarray}\nx&=&A_1e^{-\\beta t}e^{i\\omega't}+A_2e^{-\\beta t}e^{-i\\omega't},~~\\omega'\\equiv\\sqrt{\\omega_0^2-\\beta^2}\\\\\n\\nonumber\n&=&(A_1+A_2)e^{-\\beta t}\\cos\\omega't+i(A_1-A_2)e^{-\\beta t}\\sin\\omega't.\n\\end{eqnarray}\nHere we have made use of the identity $e^{i\\omega't}=\\cos\\omega't+i\\sin\\omega't$. Because the constants are arbitrary, and because the real and imaginary parts are both solutions individually, we can simply consider the real part of the solution alone:\n\\begin{eqnarray}\n\\label{eq:homogsolution}\nx&=&B_1e^{-\\beta t}\\cos\\omega't+B_2e^{-\\beta t}\\sin\\omega't,\\\\\n\\nonumber \n\\omega'&\\equiv&\\sqrt{\\omega_0^2-\\beta^2}.\n\\end{eqnarray}\n\n\\item Critical dampling: $\\beta=\\omega_0$\\\\\nIn this case the two terms involving $r_1$ and $r_2$ are identical because $\\omega'=0$. Because we need to arbitrary constants, there needs to be another solution. This is found by simply guessing, or by taking the limit of $\\omega'\\rightarrow 0$ from the underdamped solution. The solution is then\n\\begin{equation}\n\\label{eq:criticallydamped}\nx=Ae^{-\\beta t}+Bte^{-\\beta t}.\n\\end{equation}\nThe critically damped solution is interesting because the solution approaches zero quickly, but does not oscillate. For a problem with zero initial velocity, the solution never crosses zero. This is a good choice for designing shock absorbers or swinging doors.\n\\item Overdamped: $\\beta>\\omega_0$\n\\begin{eqnarray}\nx&=&A_1e^{-(\\beta+\\sqrt{\\beta^2-\\omega_0^2})t}+A_2e^{-(\\beta-\\sqrt{\\beta^2-\\omega_0^2})t}\n\\end{eqnarray}\nThis solution will also never pass the origin more than once, and then only if the initial velocity is strong and initially toward zero.\n\\end{enumerate}\n\n\\example\nGiven $b$, $m$ and $\\omega_0$, find $x(t)$ for a particle whose initial position is $x=0$ and has initial velocity $v_0$ (assuming an underdamped solution).\n\n{\\bf Solution:} The solution is of the form,\n\\begin{eqnarray*}\nx&=&e^{-\\beta t}\\left[A_1\\cos(\\omega' t)+A_2\\sin\\omega't\\right],\\\\\n\\dot{x}&=&-\\beta x+\\omega'e^{-\\beta t}\\left[-A_1\\sin\\omega't+A_2\\cos\\omega't\\right].\\\\\n\\omega'&\\equiv&\\sqrt{\\omega_0^2-\\beta^2},~~~\\beta\\equiv b/2m.\n\\end{eqnarray*}\nFrom the initial conditions, $A_1=0$ because $x(0)=0$ and $\\omega'A_2=v_0$. So \n\\[\nx=\\frac{v_0}{\\omega'}e^{-\\beta t}\\sin\\omega't.\n\\]\n\\exampleend\n\n\\subsection{Sinusoidally Driven Oscillators}\n\nHere, we consider the force\n\\begin{equation}\nF=-kx-b\\dot{x}+F_0\\cos\\omega t,\n\\end{equation}\nwhich leads to the differential equation\n\\begin{equation}\n\\label{eq:drivenosc}\n\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x=(F_0/m)\\cos\\omega t.\n\\end{equation}\nConsider a single solution with no arbitrary constants, which we will call a {\\it particular solution}, $x_p(t)$. It should be emphasized that this is {\\bf A} particular solution, because there exists an infinite number of such solutions because the general solution should have two arbitrary constants. Now consider solutions to the same equation without the driving term, which include two arbitrary constants. These are called either {\\it homogenous solutions} or {\\it complementary solutions}, and were given in the previous section, e.g. Eq. (\\ref{eq:homogsolution}) for the underdamped case. The homogenous solution already incorporates the two arbitrary constants, so any sum of a homogenous solution and a particular solution will represent the {\\it general solution} of the equation. The general solution incorporates the two arbitrary constants $A$ and $B$ to accommodate the two initial conditions. One could have picked a different particular solution, i.e. the original particular solution plus any homogenous solution with the arbitrary constants $A_p$ and $B_p$ chosen at will. When one adds in the homogenous solution, which has adjustable constants with arbitrary constants $A'$ and $B'$, to the new particular solution, one can get the same general solution by simply adjusting the new constants such that $A'+A_p=A$ and $B'+B_p=B$. Thus, the choice of $A_p$ and $B_p$ are irrelevant, and when choosing the particular solution it is best to make the simplest choice possible.\n\nTo find a particular solution, one first guesses at the form,\n\\begin{equation}\n\\label{eq:partform}\nx_p(t)=D\\cos(\\omega t-\\delta),\n\\end{equation}\nand rewrite the differential equation as\n\\begin{equation}\nD\\left\\{-\\omega^2\\cos(\\omega t-\\delta)-2\\beta\\omega\\sin(\\omega t-\\delta)+\\omega_0^2\\cos(\\omega t-\\delta)\\right\\}=\\frac{F_0}{m}\\cos(\\omega t).\n\\end{equation}\nOne can now use angle addition formulas to get\n\\begin{eqnarray}\nD\\left\\{(-\\omega^2\\cos\\delta+2\\beta\\omega\\sin\\delta+\\omega_0^2\\cos\\delta)\\cos(\\omega t)\\right.\\hspace*{36pt}&&\\\\\n\\nonumber\n\\left.+(-\\omega^2\\sin\\delta-2\\beta\\omega\\cos\\delta+\\omega_0^2\\sin\\delta)\\sin(\\omega t)\\right\\}\n&=&\\frac{F_0}{m}\\cos(\\omega t).\n\\end{eqnarray}\nBoth the $\\cos$ and $\\sin$ terms need to equate if the expression is to hold at all times. Thus, this becomes two equations\n\\begin{eqnarray}\nD\\left\\{-\\omega^2\\cos\\delta+2\\beta\\omega\\sin\\delta+\\omega_0^2\\cos\\delta\\right\\}&=&\\frac{F_0}{m}\\\\\n\\nonumber\n-\\omega^2\\sin\\delta-2\\beta\\omega\\cos\\delta+\\omega_0^2\\sin\\delta&=&0.\n\\end{eqnarray}\nAfter dividing by $\\cos\\delta$, the lower expression leads to\n\\begin{equation}\n\\tan\\delta=\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}.\n\\end{equation}\nUsing the identities $\\tan^2+1=\\csc^2$ and $\\sin^2+\\cos\\^2=1$, one can also express $\\sin\\delta$ and $\\cos\\delta$,\n\\begin{eqnarray}\n\\sin\\delta&=&\\frac{2\\beta\\omega}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}},\\\\\n\\nonumber\n\\cos\\delta&=&\\frac{(\\omega_0^2-\\omega^2)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}\n\\end{eqnarray}\nInserting the expressions for $\\cos\\delta$ and $\\sin\\delta$ into the expression for $D$,\n\\begin{equation}\n\\label{eq:Ddrive}\nD=\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}.\n\\end{equation}\n\nFor a given initial condition, e.g. initial displacement and velocity, one must add the homogenous solution then solve for the two arbitrary constants. However, because the homogenous solutions decay with time as $e^{-\\beta t}$, the particular solution is all that remains at large times, and is therefore the steady state solution. Because the arbitrary constants are all in the homogenous solution, all memory of the initial conditions are lost at large times, $t>>1/\\beta$.\n\nThe amplitude of the motion, $D$, is linearly proportional to the driving force ($F_0/m$), but also depends on the driving frequency $\\omega$. For small $\\beta$ the maximum will occur at $\\omega=\\omega_0$. This is referred to as a resonance. In the limit $\\beta\\rightarrow 0$ the amplitude at resonance approaches infinity. \n\n\\subsection{Alternative Derivation for Driven Oscillators}\n\nHere, we derive the same expressions as in Eq.s (\\ref{eq:partform}-\\ref{eq:Ddrive}) but express the driving forces as\n\\begin{eqnarray}\nF(t)&=&F_0e^{i\\omega t},\n\\end{eqnarray}\nrather than as $F_0\\cos\\omega t$. The real part of $F$ is the same as before. For the differential equation,\n\\begin{eqnarray}\n\\label{eq:compdrive}\n\\ddot{x}+2\\beta\\dot{x}+\\omega_0^2x&=&\\frac{F_0}{m}e^{i\\omega t},\n\\end{eqnarray}\none can treat $x(t)$ as an imaginary function. Because the operations $d^2/dt^2$ and $d/dt$ are real and thus do not mix the real and imaginary parts of $x(t)$, Eq. (\\ref{eq:compdrive}) is effectively 2 equations. Because $e^{\\omega t}=\\cos\\omega t+i\\sin\\omega t$, the real part of the solution for $x(t)$ gives the solution for a driving force $F_0\\cos\\omega t$, and the imaginary part of $x$ corresponds to the case where the driving force is $F_0\\sin\\omega t$. It is rather easy to solve for the complex $x$ in this case, and by taking the real part of the solution, one finds the answer for the $\\cos\\omega t$ driving force.\n\nWe assume a simple form for the particular solution\n\\begin{equation}\nx_p=De^{i\\omega t},\n\\end{equation}\nwhere $D$ is a complex constant.\n\nFrom Eq. (\\ref{eq:compdrive}) one inserts the form for $x_p$ above to get\n\\begin{eqnarray}\nD\\left\\{-\\omega^2+2i\\beta\\omega+\\omega_0^2\\right\\}e^{i\\omega t}=(F_0/m)e^{i\\omega t},\\\\\n\\nonumber\nD=\\frac{F_0/m}{(\\omega_0^2-\\omega^2)+2i\\beta\\omega}.\n\\end{eqnarray}\nThe norm and phase for $D=|D|e^{-i\\delta}$ can be read by inspection,\n\\begin{equation}\n|D|=\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}},~~~~\\tan\\delta=\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}.\n\\end{equation}\nThis is the same expression for $\\delta$ as before. One then finds $x_p(t)$,\n\\begin{eqnarray}\n\\label{eq:fastdriven1}\nx_p(t)&=&\\Re\\frac{(F_0/m)e^{i\\omega t-i\\delta}}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\\\\\n\\nonumber\n&=&\\frac{(F_0/m)\\cos(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n\\end{eqnarray}\nThis is the same answer as before.\nIf one wished to solve for the case where $F(t)= F_0\\sin\\omega t$, the imaginary part of the solution would work\n\\begin{eqnarray}\n\\label{eq:fastdriven2}\nx_p(t)&=&\\Im\\frac{(F_0/m)e^{i\\omega t-i\\delta}}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\\\\\n\\nonumber\n&=&\\frac{(F_0/m)\\sin(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n\\end{eqnarray}\n\n\\example\nConsider the damped and driven harmonic oscillator worked out above. Given $F_0, m,\\beta$ and $\\omega_0$, solve for the complete solution $x(t)$ for the case where $F=F_0\\sin\\omega t$ with initial conditions $x(t=0)=0$ and $v(t=0)=0$. Assume the underdamped case.\n\n{\\bf Solution:}\nThe general solution including the arbitrary constants includes both the homogenous and particular solutions,\n\\begin{eqnarray*}\nx(t)&=&\\frac{F_0}{m}\\frac{\\sin(\\omega t-\\delta)}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}\n+A\\cos\\omega't e^{-\\beta t}+B\\sin\\omega't e^{-\\beta t}.\n\\end{eqnarray*}\nThe quantities $\\delta$ and $\\omega'$ are given earlier in the section, $\\omega'=\\sqrt{\\omega_0^2-\\beta^2}, \\delta=\\tan^{-1}(2\\beta\\omega/(\\omega_0^2-\\omega^2)$. Here, solving the problem means finding the arbitrary constants $A$ and $B$. Satisfying the initial conditions for the initial position and velocity:\n\\begin{eqnarray*}\nx(t=0)=0&=&-\\eta\\sin\\delta+A,\\\\\nv(t=0)=0&=&\\omega\\eta\\cos\\delta-\\beta A+\\omega'B,\\\\\n\\eta&\\equiv&\\frac{F_0}{m}\\frac{1}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\beta^2\\omega^2}}.\n\\end{eqnarray*}\nThe problem is now reduced to 2 equations and 2 unknowns, $A$ and $B$. The solution is\n\\begin{eqnarray}\nA&=& \\eta\\sin\\delta ,~~~B=\\frac{-\\omega\\eta\\cos\\delta+\\beta\\eta\\sin\\delta}{\\omega'}.\n\\end{eqnarray}\n\n\\exampleend\n\n\\subsection{Resonance Widths; the $Q$ factor}\n\nFrom the previous two sections, the particular solution for a driving force, $F=F_0\\cos\\omega t$, is\n\\begin{eqnarray}\nx_p(t)&=&\\frac{F_0/m}{\\sqrt{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}}\\cos(\\omega_t-\\delta),\\\\\n\\nonumber\n\\delta&=&\\tan^{-1}\\left(\\frac{2\\beta\\omega}{\\omega_0^2-\\omega^2}\\right).\n\\end{eqnarray}\nIf one fixes the driving frequency $\\omega$ and adjusts the fundamental frequency $\\omega_0=\\sqrt{k/m}$, the maximum amplitude occurs when $\\omega_0=\\omega$ because that is when the term from the denominator $(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2$ is at a minimum. This is akin to dialing into a radio station. However, if one fixes $\\omega_0$ and adjusts the driving frequency one minimize with respect to $\\omega$, e.g. set \n\\begin{equation}\n\\frac{d}{d\\omega}\\left[(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2\\right]=0,\n\\end{equation}\nand one finds that the maximum amplitude occurs when $\\omega=\\sqrt{\\omega_0^2-2\\beta^2}$. If $\\beta$ is small relative to $\\omega_0$, one can simply state that the maximum amplitude is\n\\begin{equation}\nx_{\\rm max}\\approx\\frac{F_0}{2m\\beta \\omega_0}.\n\\end{equation}\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.32\\textwidth]{figs/qfactor}}\n\\caption{\\label{fig:qfactor}\nThe maximum amplitude squared of the steady-state motion of a sinusoidally driven harmonic oscillator is shown as a function of the driving frequency $\\omega$. This peaks near the fundamental frequency $\\omega_0$ and the full-width-half-maximum, $FWHM$, is given by the damping, $2\\beta$.}\n\\end{figure}\nFigure \\ref{fig:qfactor} displays the maximum amplitude squared as a function of $\\omega$, and  one can see the peak at $\\omega\\approx\\omega_0$. The squared amplitude is usually more the quantity of interest than the amplitude because the power being absorbed by the oscillator is proportional to the square of the amplitude, not the amplitude. The width of the peak is quantified by the full-width-half-maximum, sometimes called $FWHM$ and can be found by finding the frequency difference, $\\omega-\\omega_0$, such that the maximum response falls by a factor of two,\n\\begin{eqnarray}\n\\frac{4\\omega^2\\beta^2}{(\\omega_0^2-\\omega^2)^2+4\\omega^2\\beta^2}=\\frac{1}{2}.\n\\end{eqnarray}\nFor small damping this occurs when $\\omega=\\omega_0\\pm \\beta$, so the $FWHM\\approx 2\\beta$. For the purposes of tuning to a specific frequency, one wants the width to be as small as possible. The ratio of $\\omega_0$ to $FWHM$ is known as the {\\it quality} factor, or $Q$ factor,\n\\begin{equation}\nQ\\equiv \\frac{\\omega_0}{2\\beta}.\n\\end{equation}\n\n\\subsection{Principal of Superposition and Periodic Forces (Fourier Transforms)}\n\nIf one has several driving forces, $F(t)=\\sum_n F_n(t)$, one can find the particular solution to each $F_n$, $x_{pn}(t)$, and the particular solution for the entire driving force is \n\\begin{equation}\nx_p(t)=\\sum_nx_{pn}(t).\n\\end{equation}\nThis is known as the principal of superposition. It only applies when the homogenous equation is linear. If there were an anharmonic term such as $x^3$ in the homogenous equation, then when one summed various solutions, $x=(\\sum_n x_n)^2$, one would get cross terms. Superposition is especially useful when $F(t)$ can be written as a sum of sinusoidal terms, because the solutions for each sinusoidal term is analytic, and are given in the previous two subsections. \n\nDriving forces are often periodic, even when they are not sinusoidal. Periodicity implies that for some time $\\tau$\n\\begin{eqnarray}\nF(t+\\tau)=F(t). \n\\end{eqnarray}\nOne example of a non-sinusoidal periodic force is a square wave. Many components in electric circuits are non-linear, e.g. diodes, which makes many wave forms non-sinusoidal even when the circuits are being driven by purely sinusoidal sources.\n\nFor the sinusoidal example studied in the previous subsections the period is $\\tau=2\\pi/\\omega$. However, higher harmonics can also satisfy the periodicity requirement. In general, any force that satisfies the periodicity requirement can be expressed as a sum over harmonics,\n\\begin{equation}\nF(t)=\\frac{f_0}{2}+\\sum_{n>0} f_n\\cos(2n\\pi t/\\tau)+g_n\\sin(2n\\pi t/\\tau).\n\\end{equation}\nFrom the previous subsection, one can write down the answer for $x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$ into Eq.s (\\ref{eq:fastdriven1}) or (\\ref{eq:fastdriven2}) respectively. By writing each factor $2n\\pi t/\\tau$ as $n\\omega t$, with $\\omega\\equiv 2\\pi/\\tau$,\n\\begin{equation}\n\\label{eq:fourierdef1}\nF(t)=\\frac{f_0}{2}+\\sum_{n>0}f_n\\cos(n\\omega t)+g_n\\sin(n\\omega t).\n\\end{equation}\nThe solutions for $x(t)$ then come from replacing $\\omega$ with $n\\omega$ for each term in the particular solution in Eq.s (\\ref{eq:partform}-\\ref{eq:Ddrive}),\n\\begin{eqnarray}\nx_p(t)&=&\\frac{f_0}{2k}+\\sum_{n>0} \\alpha_n\\cos(n\\omega t-\\delta_n)+\\beta_n\\sin(n\\omega t-\\delta_n),\\\\\n\\nonumber\n\\alpha_n&=&\\frac{f_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n\\nonumber\n\\beta_n&=&\\frac{g_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n\\nonumber\n\\delta_n&=&\\tan^{-1}\\left(\\frac{2\\beta n\\omega}{\\omega_0^2-n^2\\omega^2}\\right).\n\\end{eqnarray}\nBecause the forces have been applied for a long time, any non-zero damping eliminates the homogenous parts of the solution, so one need only consider the particular solution for each $n$.\n\nThe problem will considered solved if one can find expressions for the coefficients $f_n$ and $g_n$, even though the solutions are expressed as an infinite sum. The coefficients can be extracted from the function $F(t)$ by\n\\begin{eqnarray}\n\\label{eq:fourierdef2}\nf_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\cos(2n\\pi t/\\tau),\\\\\n\\nonumber\ng_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\sin(2n\\pi t/\\tau).\n\\end{eqnarray}\n\nTo check the consistency of these expressions and to verify Eq. (\\ref{eq:fourierdef2}), one can insert the expansion of $F(t)$ in Eq. (\\ref{eq:fourierdef1}) into the expression for the coefficients in Eq. (\\ref{eq:fourierdef2}) and see whether\n\\begin{eqnarray}\nf_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~\\left\\{\n\\frac{f_0}{2}+\\sum_{m>0}f_m\\cos(m\\omega t)+g_m\\sin(m\\omega t)\n\\right\\}\\cos(n\\omega t).\n\\end{eqnarray}\nImmediately, one can throw away all the terms with $g_m$ because they convolute an even and an odd function. The term with $f_0/2$ disappears because $\\cos(n\\omega t)$ is equally positive and negative over the interval and will integrate to zero. For all the terms $f_m\\cos(m\\omega t)$ appearing in the sum, one can use angle addition formulas to see that $\\cos(m\\omega t)\\cos(n\\omega t)=(1/2)(\\cos[(m+n)\\omega t]+\\cos[(m-n)\\omega t]$. This will integrate to zero unless $m=n$. In that case the $m=n$ term gives\n\\begin{equation}\n\\int_{-\\tau/2}^{\\tau/2}dt~\\cos^2(m\\omega t)=\\frac{\\tau}{2},\n\\end{equation}\nand\n\\begin{eqnarray}\nf_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~f_n/2\\\\\n\\nonumber\n&=&f_n~\\checkmark.\n\\end{eqnarray}\nThe same method can be used to check for the consistency of $g_n$.\n\n\\example\nConsider the driving force:\n\\begin{equation}\nF(t)=At/\\tau,~~-\\tau/2<t<\\tau/2,~~~F(t+\\tau)=F(t).\n\\end{equation}\nFind the Fourier coefficients $f_n$ and $g_n$ for all $n$ using Eq. (\\ref{eq:fourierdef2}).\n\n{\\bf Solution:} Only the odd coefficients enter by symmetry, i.e. $f_n=0$. One can find $g_n$ integrating by parts,\n\\begin{eqnarray}\n\\label{eq:fouriersolution}\ng_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2}dt~\\sin(n\\omega t) \\frac{At}{\\tau}\\\\\n\\nonumber\nu&=&t,~dv=\\sin(n\\omega t)dt,~v=-\\cos(n\\omega t)/(n\\omega),\\\\\n\\nonumber\ng_n&=&\\frac{-2A}{n\\omega \\tau^2}\\int_{-\\tau/2}^{\\tau/2}dt~\\cos(n\\omega t)\n+\\left.2A\\frac{-t\\cos(n\\omega t)}{n\\omega\\tau^2}\\right|_{-\\tau/2}^{\\tau/2}.\n\\end{eqnarray}\nThe first term is zero because $\\cos(n\\omega t)$ will be equally positive and negative over the interval. Using the fact that $\\omega\\tau=2\\pi$,\n\\begin{eqnarray}\ng_n&=&-\\frac{2A}{2n\\pi}\\cos(n\\omega\\tau/2)\\\\\n\\nonumber\n&=&-\\frac{A}{n\\pi}\\cos(n\\pi)\\\\\n\\nonumber\n&=&\\frac{A}{n\\pi}(-1)^{n+1}.\n\\end{eqnarray}\nThe true function is compared to the expansion in Fig. \\ref{fig:triangle} where the sum is cut off at finite $n$.\n\\begin{figure}\n\\centerline{\\includegraphics[width=0.6\\textwidth]{figs/triangle}}\n\\caption{\\label{fig:triangle}\nThe periodic function $F(t)=t/\\tau, |t|<\\tau/2$ (black) is compared to the Fourier expansion described in Eq. (\\ref{eq:fouriersolution}) with 10 terms (red) or 100 terms (green).}\n\\end{figure}\n\n\\exampleend\n\n\\subsection{Response to Transient Force}\n\nConsider a particle at rest in the bottom of an underdamped harmonic oscillator, that then feels a sudden impulse, or change in momentum, $I=F\\Delta t$ at $t=0$. This increases the velocity immediately by an amount $v_0=I/m$ while not changing the position. One can then solve the trajectory by solving Eq. (\\ref{eq:homogsolution}) with initial conditions $v_0=I/m$ and $x_0=0$. This gives\n\\begin{equation}\nx(t)=\\frac{I}{m\\omega'}e^{-\\beta t}\\sin\\omega't, ~~t>0.\n\\end{equation}\nHere, $\\omega'=\\sqrt{\\omega_0^2-\\beta^2}$. For an impulse $I_i$ that occurs at time $t_i$ the trajectory would be\n\\begin{equation}\nx(t)=\\frac{I_i}{m\\omega'}e^{-\\beta (t-t_i)}\\sin[\\omega'(t-t_i)] \\Theta(t-t_i),\n\\end{equation}\nwhere $\\Theta(t-t_i)$ is a step function, i.e. $\\Theta(x)$ is zero for $x<0$ and unity for $x>0$. If there were several impulses linear superposition tells us that we can sum over each contribution,\n\\begin{equation}\nx(t)=\\sum_i\\frac{I_i}{m\\omega'}e^{-\\beta(t-t_i)}\\sin[\\omega'(t-t_i)]\\Theta(t-t_i)\n\\end{equation} \n\nNow one can consider a series of impulses at times separated by $\\Delta t$, where each impulse is given by $F_i\\Delta t$. The sum above now becomes an integral,\n\\begin{eqnarray}\\label{eq:Greeny}\nx(t)&=&\\int_{-\\infty}^\\infty dt'~F(t')\\frac{e^{-\\beta(t-t')}\\sin[\\omega'(t-t')]}{m\\omega'}\\Theta(t-t')\\\\\n\\nonumber\n&=&\\int_{-\\infty}^\\infty dt'~F(t')G(t-t'),\\\\\n\\nonumber\nG(\\Delta t)&=&\\frac{e^{-\\beta\\Delta t}\\sin[\\omega' \\Delta t]}{m\\omega'}\\Theta(\\Delta t)\n\\end{eqnarray}\nThe quantity $e^{-\\beta(t-t')}\\sin[\\omega'(t-t')]/m\\omega'\\Theta(t-t')$ is called a Green's function, $G(t-t')$. It describes the response at $t$ due to a force applied at a time $t'$, and is a function of $t-t'$. The step function ensures that the response does not occur before the force is applied. One should remember that the form for $G$ would change if the oscillator were either critically- or over-damped.\n\nWhen performing the integral in Eq. (\\ref{eq:Greeny}) one can use angle addition formulas to factor out the part with the $t'$ dependence in the integrand,\n\\begin{eqnarray}\n\\label{eq:Greeny2}\nx(t)&=&\\frac{1}{m\\omega'}e^{-\\beta t}\\left[I_c(t)\\sin(\\omega't)-I_s(t)\\cos(\\omega't)\\right],\\\\\n\\nonumber\nI_c(t)&\\equiv&\\int_{-\\infty}^t dt'~F(t')e^{\\beta t'}\\cos(\\omega't'),\\\\\n\\nonumber\nI_s(t)&\\equiv&\\int_{-\\infty}^t dt'~F(t')e^{\\beta t'}\\sin(\\omega't').\n\\end{eqnarray}\nIf the time $t$ is beyond any time at which the force acts, $F(t'>t)=0$, the coefficients $I_c$ and $I_s$ become independent of $t$. \n\n\\example\nConsider an undamped oscillator ($\\beta\\rightarrow 0$), with characteristic frequency $\\omega_0$ and mass $m$, that is at rest until it feels a force described by a Gaussian form,\n\\begin{eqnarray*}\nF(t)&=&F_0 \\exp\\left\\{\\frac{-t^2}{2\\tau^2}\\right\\}.\n\\end{eqnarray*}\nFor large times ($t>>\\tau$), where the force has died off, find $x(t)$.\\\\\n{\\bf Solution:} Solve for the coefficients $I_c$ and $I_s$ in Eq. (\\ref{eq:Greeny2}). Because the Gaussian is an even function, $I_s=0$, and one need only solve for $I_c$,\n\\begin{eqnarray*}\nI_c&=&F_0\\int_{-\\infty}^\\infty dt'~e^{-t^{\\prime 2}/(2\\tau^2)}\\cos(\\omega_0 t')\\\\\n&=&\\Re F_0 \\int_{-\\infty}^\\infty dt'~e^{-t^{\\prime 2}/(2\\tau^2)}e^{i\\omega_0 t'}\\\\\n&=&\\Re F_0 \\int_{-\\infty}^\\infty dt'~e^{-(t'-i\\omega_0\\tau^2)^2/(2\\tau^2)}e^{-\\omega_0^2\\tau^2/2}\\\\\n&=&F_0\\tau \\sqrt{2\\pi} e^{-\\omega_0^2\\tau^2/2}.\n\\end{eqnarray*}\nThe third step involved completing the square, and the final step used the fact that the integral\n\\begin{eqnarray*}\n\\int_{-\\infty}^\\infty dx~e^{-x^2/2}&=&\\sqrt{2\\pi}.\n\\end{eqnarray*}\nTo see that this integral is true, consider the square of the integral, which you can change to polar coordinates,\n\\begin{eqnarray*}\nI&=&\\int_{-\\infty}^\\infty dx~e^{-x^2/2}\\\\\nI^2&=&\\int_{-\\infty}^\\infty dxdy~e^{-(x^2+y^2)/2}\\\\\n&=&2\\pi\\int_0^\\infty rdr~e^{-r^2/2}\\\\\n&=&2\\pi.\n\\end{eqnarray*}\nFinally, the expression for $x$ from Eq. (\\ref{eq:Greeny2}) is\n\\begin{eqnarray*}\nx(t>>\\tau)&=&\\frac{F_0\\tau}{m\\omega_0} \\sqrt{2\\pi} e^{-\\omega_0^2\\tau^2/2}\\sin(\\omega_0t).\n\\end{eqnarray*}\n\n\n\\exampleend\n\n\\subsection{Solving Equations of Motion Numerically}\n%If one has a known force $F(t)$, and initial conditions $x(t=0)=x_0$ and $v(t=0)=v_0$, one can solve for the equations of motion numerically. First, one must choose a small time step $\\Delta t$, smaller than any characteristic time scale of the problem. One can then define a mesh $x_n$, where $n=0$ so some maximum number of steps $N$. We will defines these values as\n\\begin{eqnarray}\nx_n=x(n\\Delta t).\n\\end{eqnarray}\nAssume that one knows $x_n$ for all $i<\\le j$. One can express the velocities and accelerations in Newton's equations of motion for a mass $m$ as:\n\n\\begin{eqnarray}\nv_n&=&\\frac{x_{n+1}-x_{n-1}}{2\\Delta t},\\\\\n\\nonumber\na_n&=&\\frac{v_{n+1/2}-v_{n-1/2}}{\\Delta t}\\\\\n\\nonumber\n&=&\\frac{x_{n+1}-2x_n+x_{n-1}}{(\\Delta t)^2}.\n\\end{eqnarray}\nThe equations of motion at $t_n=n\\Delta t$ become\n\\begin{eqnarray}\nF(x_n)&=&ma_n.\n\\end{eqnarray}\nIf one knows $x_{n-1}$ and $x_n$ the only unknown in the equation is $x_{n+1}$. One can solve for it, then move onto the next $n$. Note that to proceed one needs to know $x$ at two points. This can be tricky depending on how the initial conditions are specified. \n\n\\example\nWrite a numerical program to solve the evolution of a particle of mass $m$ feeling a spring force, $-kx$ and a drag force, $-bv$. Assume there is also some external force, $F(t)=F_0\\sin\\omega t$. Let the initial conditions be $x(t=0)=0$ and $v(t=0)=v_0$.\n\n{\\bf Solution:} The differential equation,\n\\begin{eqnarray*}\nm\\ddot{x}+b\\dot{x}+kx&=&0,\\\\\n\\end{eqnarray*}\nbecomes\n\\begin{eqnarray*}\n\\frac{m}{(\\Delta t)^2}\\left(x_{n+1}-2x_n+x_{n-1}\\right)+\\frac{b}{2\\Delta t}\\left(x_{n+1}-x_{n-1}\\right)+kx_n&=&F(n\\Delta t).\n\\end{eqnarray*}\nSolving for $x_{n+1}$,\n\\begin{eqnarray*}\n\\left\\{\\frac{m}{(\\Delta t)^2}+\\frac{b}{2\\Delta t}\\right\\}x_{n+1}&=&\\left[\\frac{2m}{(\\Delta t)^2}-k\\right]x_n+F(n\\Delta t)\n+\\left[-\\frac{m}{(\\Delta t)^2}+\\frac{b}{2\\Delta t}\\right]x_{n-1},\\\\\nx_{n+1}&=&\\frac{\\left[\\frac{2m}{(\\Delta t)^2}-k\\right]x_n+F(n\\Delta t)\n+\\left[-\\frac{m}{(\\Delta t)^2}+\\frac{b}{2\\Delta t}\\right]x_{n-1}}{\\frac{m}{(\\Delta t)^2}+\\frac{b}{2\\Delta t}}.\n\\end{eqnarray*}\nIn order to iterate forward to find $x_{n+1}$, one must know $x_{n-1}$ and $x_n$. However, to get started, one only knows one value of $x$, along with the velocity being zero. To get $x$ at two time steps, one must can use the above two pieces of information,\n\\begin{eqnarray*}\nv_0&=&\\frac{x_1-x_{-1}}{2\\Delta t},\\\\\n-bv_0-kx_0&=&m\\frac{x_1-2x_0+x_{-1}}{\\Delta t^2},\n\\end{eqnarray*}\nthen combine the equations to eliminate $x_{-1}$ to solve for $x_1$. The fact that $x_0=0$ makes the algebra simpler,\n\\begin{eqnarray*}\nx_1&=&v_0\\Delta t-\\frac{bv_0\\Delta t^2}{2m}.\n\\end{eqnarray*}\n\n\n\nThe program might read:\n{\\tt\\begin{verbatim}\ndouble F(double t){\n   double F0=????,omega=????;\n   return F0*sin(omega*t);\n}\nvoid main(){\n   const int Ntsteps=???;\n   double x[Ntsteps+1],dt=???,k=???,m=???,b=???,v0=???;\n   x[0] = 0.0;\n   x[1] = v0*dt-0.5*b*v0/m;\n   for(int it=1;it<Ntsteps;it=it+1){\n      x[it+1]=( (2.0*m/(dt*dt)) -k)*x[it] + F(it*dt)\n      + (0.5*b/dt)*x[it-1] ) / ( (m/(dt*dt) + 0.5*b/dt );\n   }\n}\n\\end{verbatim}}\nQuestion marks would be replaced by the given parameters of the problem.\n\n\\exampleend\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\n\\item A floating body of uniform cross-sectional area $A$ and of mass density $\\rho$ and at equilibrium displaces a volume $V$. Show that the period of small oscillations about the equilibrium position is given by \n\\[\n\\tau=2\\pi\\sqrt{V/gA}\n\\]\n\n\\item Show that the critically damped solution, Eq. (\\ref{eq:criticallydamped}), is indeed the solution to the differential equation.\n\n\\item Consider an over-damped harmonic oscillator with a mass of $m=2$ kg, a damping factor $b=20$ Ns/m, and a spring constant $k=32$ N/m. If the initial position is $x=0.125$ m, and if the initial velocity is $-2.0$ m/s, find and graph the motion as a function of time. Graphically, find the time at which the mass crosses the origin.\n\n\\item Consider a particle of mass $m$ moving in a one-dimensional potential,\n\\[\nV(x)=-k\\frac{x^2}{2}+\\alpha\\frac{x^4}{4}.\n\\]\n\\begin{enumerate}\n\\item What is the angular frequency for small vibrations about the minimum of the potential? What is the effective spring constant?\n\\item If you add a small force $F=F_0\\cos(\\omega t-\\phi)$, and if the particle is initially at the minimum with zero initial velocity, find its position as a function of time.\n\\item If there is a small drag force $-bv$, repeat (b).\n\\end{enumerate}\n\n\\item Consider the periodic force, $F(t+\\tau)=F(t)$,\n\\[\nF(t)=\\left\\{\\begin{array}{rl}\n-A,&-\\tau/2<t<0\\\\\n+A,&0<t<\\tau/2\n\\end{array}\\right.\n\\]\nFind the coefficients $f_n$ and $g_n$ defined in Eq. (\\ref{eq:fourierdef2}).\n\n\\item A ``delta'' function is a function that is zero everywhere except where the argument is zero. At this point the function is infinite so that the area under the curve is unity. The delta function obeys the relations\n\\begin{eqnarray*}\n\\int_a^b dt'~ \\delta(t'-t_0)&=&1,\\\\\n\\int_a^b dt'~ f(t')\\delta(t'-t_0)&=&f(t_0),\n\\end{eqnarray*}\nas long as the time $t_0$ lies between the limits $a$ and $b$. Otherwise, the integrals are zero.\n\\begin{enumerate}\n\\item Show that the following function\n\\[\n\\left.\\frac{1}{\\pi}\\frac{\\Lambda}{\\Lambda^2+x^2}\\right|_{\\Lambda\\rightarrow 0}=\\delta(x).\n\\]\ni.e. show that it is zero everywhere except the origin and that it integrates to unity.\n\\item A step function, $\\Theta(t)$, a.k.a. the ``Theta'' function or the Heaviside function, is zero for negative arguments and is unity for positive arguments. Show that\n\\[\n\\frac{d}{dx}\\Theta(x-x_0)=\\delta(x-x_0).\n\\]\n\\item Using the definition of Fourier coefficients in Eq.s (\\ref{eq:fourierdef1}) and (\\ref{eq:fourierdef2}), show that\n\\[\n\\delta(t-t_0)=-\\frac{1}{\\tau}+\\frac{2}{\\tau}\\sum_{n=0}^{\\infty}\\cos(\\omega_n(t-t_0)),~~~\\omega_n=2n\\pi/\\tau.\n\\]\n\\end{enumerate}\n\n\\item Consider the complex function in the interval $-\\tau/2<t<\\tau/2$,\n\\[\nf(t)=-\\frac{1}{\\tau}+\\frac{2}{\\tau}\\sum_{n=0}^\\infty e^{in\\omega(t-t_0)}, ~~~\\omega=2\\pi/\\tau.\n\\]\n\\begin{enumerate}\n\\item Using the fact that if one integrates over the interval, $-\\tau/2<t<\\tau/2$, that $\\int dt ~e^{in\\omega t}=0$ for $n\\ne 0$, show that\n\\[\n\\int dt f(t)=1.\n\\]\n\\item Using the fact that $\\sum_n x^n=1/(1-x)$, show that \n\\[\nf(t)=-\\frac{1}{\\tau}+\\frac{2/\\tau}{1-e^{i\\omega(t-t_0)}}.\n\\]\n\\item From the expression in (b), show that the real part of $f(t)$ obeys\n\\[\n\\Re f(t)=0,~~{\\rm for}~t\\ne t_0\n\\]\nThis shows that $\\Re f$ is a delta function and validates the result of the previous problem.\n\\end{enumerate}\n\n\\item A particle of mass $m$ in an undamped harmonic oscillator with angular frequency $\\omega_0$ is at rest in the bottom of the well, when it experiences a force\n\\[\nF(t)=\\left\\{\\begin{array}{rl}\n0,&t<0\\\\\nG,&0<t<\\tau\\\\\n0,&t>\\tau\\end{array}\n\\right.\n\\]\nFind $x(t)$ for $t>\\tau$ using Eq. (\\ref{eq:Greeny2}).\n\n\\item Consider a particle of mass $m$ in a harmonic oscillator with angular frequency $\\omega_0$ and no damping. It experiences an external force,\n\\[\nF(t)=f_0\\Theta(t)e^{-\\gamma t}.\n\\]\nA ``Theta'' function is a step function, and is zero for negative arguments and unity for positive arguments.\n\\begin{enumerate}\n\\item Find a particular solution, $x_p(t)$, assuming it is proportional to $e^{-\\gamma t}$. \n\\item For a particle initially at rest at the origin at $t=0$, find $x(t)$ by adding in the homogenous solutions and matching the BC, determine the arbitrary constants.\n\\item Use Eq. (\\ref{eq:Greeny}) or Eq. (\\ref{eq:Greeny2}) to find $x(t)$. Check that you get the same result as (b).\n\\end{enumerate}\n\n\\end{enumerate} \n\n", "meta": {"hexsha": "54ca41583b4cb257aad3c4bbfb6fe82d4dbab8e2", "size": 37434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/AdminBackground/lectures/test.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/AdminBackground/lectures/test.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/AdminBackground/lectures/test.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": 60.4749596123, "max_line_length": 1493, "alphanum_fraction": 0.715899984, "num_tokens": 12330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6287803856479551}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\begin{document}\n\n\\title{Metric and Topological spaces}\n\\date{Easter 2016}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Introduction}\nSuppose $\\left(x_n\\right)$ is a sequence of real numbers. $\\left(x_n\\right)$ converges to $x\\in \\R$ if for every $\\varepsilon>0$, there exists some $N$ such that $|x_n-x|<\\varepsilon$ whenever $n>N$. We know that a function $f:\\R \\to \\R$ is \\emph{continuous} if $\\left(f\\left(x_n\\right)\\right)\\to f\\left(x\\right)$ whenever $\\left(x_n\\right) \\to x$. But what does it mean for a sequence $\\left(x_n\\right)$ to converge if $x_n\\in X \\neq \\R$?\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\nX=\\left\\{A\\in M_{n\\times n} \\left(\\R\\right) | A^T =A\\right\\}\n\\end{aligned}\n\\end{equation*}\nand let $f\\left(A\\right)$ be the largest eigenvalue of $A$. Is $f$ continuous?\n\\end{eg}\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\n&X=\\left\\{f:\\left[0,1\\right] \\to \\R | f  \\text{ is continuous} \\right\\} \\\\\n&F\\left(f\\right) = f\\left(\\frac{1}{2}\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\nIs $F$ continuous?\n\n\\begin{thm} (Intermediate value theorem)\\\\\nIf $f:\\left[0,1\\right]\\to \\R$ is continuous and $f\\left(0\\right)\\left<0, f\\left(1\\right)\\right>0$, then $\\exists x \\in \\left[0,1\\right]$ with $f\\left(x\\right)=0$.\n\\end{thm}\n\n\\begin{thm} (Maximum value theorem)\\\\\nIf $f:\\left[0,1\\right] \\to \\R$ is continuous, then $\\exists x \\in \\left[0,1\\right]$ such that $f\\left(x\\right) \\geq f\\left(y\\right)$ for all $y\\in\\left[0,1\\right]$.\n\\end{thm}\n\nThese are both theorems about $\\left[0,1\\right]$. However, they might not be true if we change to another domain. For example, neither of these theorems hold for $\\left[0,1\\right] \\cap \\Q$.\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\nf\\left(x\\right) = x^2-\\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nThen $f\\left(0\\right)\\left<0, f\\left(1\\right)\\right>0$, but there is no $x\\in\\left[0,1\\right] \\cap \\Q$ such that $f\\left(x\\right) = 0$.\n\\end{eg}\n\n\\newpage\n\\section{Metric spaces}\nSuppose $\\left(\\mathbf{v}_n\\right) = \\left(\\left(x_n,y_n\\right)\\right)$ is a sequence in $\\R^2$. What should it mean for $\\left(\\mathbf{v}_n\\right)$ to converge to $\\mathbf{v} = \\left(x,y\\right)$?\\\\\nA natural thought would be that the sequence ocnverges to $\\left(x,y\\right)$ if $\\left(x_n\\right) \\to x$ and $\\left(y_n\\right) \\to y$. That is then equivalent to\n\\begin{equation*}\n\\begin{aligned}\n&\\left(x_n-x\\right)^2 + \\left(y_n-y\\right)^2 \\to 0 \\iff\n&|\\mathbf{v}_n-\\mathbf{v}| \\to 0.\n\\end{aligned}\n\\end{equation*}\n\n\\begin{defi} (Metric space)\\\\\nA \\emph{metric space} is a pair $\\left(X,d\\right)$ where $X$ is a set and $d:X\\times X \\to \\R$, called the \\emph{metric}, or \\emph{distance function}, that satisfies the following properties:\n\\begin{equation*}\n\\begin{aligned}\n&\\bullet d\\left(x,y\\right) \\geq 0 \\forall x,y\\in X;\\\\\n&\\bullet d\\left(x,y\\right) = 0 \\iff x=y;\\\\\n&\\bullet d\\left(x,y\\right) = d\\left(y,x\\right);\\\\\n&\\bullet d\\left(x,z\\right) \\leq d\\left(x,y\\right) + d\\left(y,z\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{eg}(Euclidean metric)\\\\\nLet $X=\\R^n$, $d\\left(\\mathbf{x},\\mathbf{y}\\right) = |\\mathbf{x}-\\mathbf{y}|$, where\n\\begin{equation*}\n\\begin{aligned}\n|\\mathbf{v}| = \\left(\\sum_{i=1}^n v_i^2\\right)^\\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nis the \\emph{Euclidean metric} on $\\R^n$. Note that this satisfies the triangle inequality.\n\\end{eg}\n\n\\begin{eg} (Metric subspace)\\\\\nSuppose $\\left(X,d_X\\right)$ is a metric space and $Y\\subset X$. Then $\\left(Y,d_Y\\right)$ is a metric space, where $d_Y\\left(y_1,y_2\\right) = d_X\\left(y_1,y_2\\right)$, i.e. $d_Y=d_X |_{Y\\times Y}$.\\\\\nWe say $\\left(Y,d_Y\\right)$ is a \\emph{subspace} of $\\left(X,d_X\\right)$, or just say $Y$ is a subspace of $X$.\n\\end{eg}\n\n\\begin{eg}\nConsider\n\\begin{equation*}\n\\begin{aligned}\n\\left\\{A \\in M_{n\\times n} \\left(\\R\\right) | A^T = A \\right\\} \\subset \\R^{n^2}.\n\\end{aligned}\n\\end{equation*} \n\\end{eg}\n\n\\begin{defi} (Convergence)\\\\\nIf $\\left(X,d\\right)$ is a metric space and $\\left(x_n\\right)$ is a sequence in $X$, we say $\\left(x_n\\right)$ converges to $x$ if for every $\\varepsilon >0$ there exists $N$ such that $d\\left(x_n,x\\right) < \\varepsilon$ whenever $n>N$.\n\\end{defi}\n\n\\begin{prop}\nSuppose $\\left(x_n\\right)$ is a sequence in a metric space $\\left(X,d\\right)$ that $\\left(x_n\\right) \\to x$ and $\\left(x_n\\right) \\to y$. Then $x=y$.\n\\begin{proof}\nGiven $\\varepsilon>0$, pick $N_1,N_2$ with\n\\begin{equation*}\n\\begin{aligned}\n&n>N_1 \\implies d\\left(x_n,x\\right) < \\frac{\\varepsilon}{2},\\\\\n&n>N_2 \\implies d\\left(x_n,y\\right) < \\frac{\\varepsilon}{2}\n\\end{aligned}\n\\end{equation*}\nThen if $n>\\max\\left\\{N_1,N_2\\right\\}$,\n\\begin{equation*}\n\\begin{aligned}\n0\\leq d\\left(x,y\\right)\\leq d\\left(x,x_n\\right) + d\\left(x_n,y\\right) = d\\left(x,x_n\\right) + d\\left(y,x_n\\right) < \\frac{\\varepsilon}{2} + \\frac{\\varepsilon}{2} = \\varepsilon.\n\\end{aligned}\n\\end{equation*}\nSince $\\varepsilon$ is arbitrary, $d\\left(x,y\\right)=0$. So $x=y$.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi} (Continuity)\\\\\nIf $\\left(X,d_X\\right)$ and $\\left(Y,d_Y\\right)$ are metric spaces, then $f:X\\to Y$ is \\emph{continuous} if $\\left(f\\left(x_n\\right)\\right) \\to f\\left(x\\right)$ whenever $\\left(x_n\\right) \\to x$.\n\\end{defi}\n\n\\begin{prop}\nIf $\\left(X,d_X\\right), \\left(Y,d_Y\\right)$ and $\\left(Z,d_Z\\right)$ are metric spaces, and $f:X\\to Y$ and $g:Y\\to Z$ are both continuous, then $g \\circ f:X\\to Z$ is also continuous.\n\\begin{proof}\nSuppose $\\left(x_n\\right) \\to x$ in $X$. Since $f$ is continuous, \n\\begin{equation*}\n\\begin{aligned}\n\\left(f\\left(x_n\\right)\\right) \\to f\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nin $Y$. Since $g$ is also continuous,\n\\begin{equation*}\n\\begin{aligned}\n\\left(g\\left(f\\left(x_n\\right)\\right)\\right) \\to g\\left(f\\left(x\\right)\\right)\n\\end{aligned}\n\\end{equation*}\nin $Z$, i.e.\n\\begin{equation*}\n\\begin{aligned}\n\\left(g\\circ f\\left(x_n\\right)\\right) \\to g\\circ f\\left(x\\right).\n\\end{aligned}\n\\end{equation*}\nSo $g\\circ f$ is continuous.\n\\end{proof}\n\\end{prop}\n\n\\begin{eg} (Discrete metric)\\\\\nLet $X$ be any set, and let\n\\begin{equation*}\n\\begin{aligned}\nd\\left(x,y\\right) = \\left\\{\n\\begin{array}{ll}\n1 & x\\neq y\\\\\n0 & x=y\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nThis is a metric space.\n\\end{eg}\n\n\\begin{eg}\nLet $X=\\R^2$, $\\mathbf{x}=\\left(x_1,x_2\\right)$, $\\mathbf{x}'=\\left(x_1',x_2'\\right)$, and\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{x}'\\right) = |x_1-x_1'| + |x_2-x_2'|.\n\\end{aligned}\n\\end{equation*}\nTriangle inequality follows by:\n\\begin{equation*}\n\\begin{aligned}\nd\\left(x,z\\right) &= |x_1-z_1| + |x_2-x_2| \\\\\n&\\leq |x_1-y_1| + |y_1-z_1| + |x_2 - y_2| + |y_2 - z_2| \\\\\n&= d\\left(x,y\\right) + d\\left(y,z\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\begin{eg} (British Railway metric)\\\\\nLet $X=\\R^2$, and\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{y}\\right) = \\left\\{\n\\begin{array}{ll}\n|\\mathbf{x}-\\mathbf{y}| &  \\mathbf{x}=k\\mathbf{y}\\\\\n|\\mathbf{x}| + |\\mathbf{y}| & \\text{ otherwise}\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\n(Unless you, your destination and London are collinear, you always have to take a train to London first and transfer there.)\n\\end{eg}\n\n\\begin{defi}\nIf $V$ is a real vector space, a \\emph{norm} on $V$ is a map $||\\cdot|| : V \\to \\R$ satisfying\n\\begin{equation*}\n\\begin{aligned}\n&\\bullet ||\\mathbf{v}|| \\geq 0 \\forall \\mathbf{v}\\in V;\\\\\n&\\bullet ||\\mathbf{v}|| = 0 \\iff \\mathbf{v}=\\mathbf{0} \\in V;\\\\\n&\\bullet ||\\lambda \\mathbf{v}|| = |\\lambda| ||\\mathbf{v}||, \\lambda \\in \\R, \\mathbf{v} \\in V;\\\\\n&\\bullet ||\\mathbf{v}+\\mathbf{w}|| \\leq ||\\mathbf{v}|| + ||\\mathbf{w}||.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\n\\begin{eg}\nLet $V = \\R^n$,\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}|| = \\sum_{i=1}^n |v_i|\n\\end{aligned}\n\\end{equation*}\n(this is called the Manhattan norm).\n\\end{eg}\n\n\\begin{lemma}\nIf $||\\cdot||$ is a norm on $V$, then \n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{y}\\right) = ||\\mathbf{x}-\\mathbf{y}||\n\\end{aligned}\n\\end{equation*}\ndefines a metric on $V$.\n\\begin{proof}\nFirstly\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{y}\\right) = ||\\mathbf{x}-\\mathbf{y}|| \\geq 0\n\\end{aligned}\n\\end{equation*}\nby our definition of norm. The second holds by\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{y}\\right) = 0 &\\iff ||\\mathbf{x}-\\mathbf{y}|| = 0\\\\\n&\\iff \\mathbf{x}-\\mathbf{y}=0\\\\\n&\\iff \\mathbf{x} = \\mathbf{y}.\n\\end{aligned}\n\\end{equation*}\nFor the third condition,\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{y}-\\mathbf{x}\\right) &= ||\\mathbf{y}-\\mathbf{x}|| \\\\\n&= ||\\left(-1\\right)\\left(\\mathbf{x}-\\mathbf{y}\\right)||\\\\\n&= |-1| ||\\mathbf{x}-\\mathbf{y}||\\\\\n&= d\\left(\\mathbf{x},\\mathbf{y}\\right)\n\\end{aligned}\n\\end{equation*}\nLastly\n\\begin{equation*}\n\\begin{aligned}\nd\\left(\\mathbf{x},\\mathbf{y}\\right) + d\\left(\\mathbf{y},\\mathbf{z}\\right) &= ||\\mathbf{x}-\\mathbf{y}|| + ||\\mathbf{y}-\\mathbf{z}||\\\\\n&\\geq \\mathbf{x}-\\mathbf{z}\\\\\n&= d\\left(\\mathbf{x},\\mathbf{z}\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\n\nThe Manhattan metric on $\\R^2$ is induced by the Manhattan norm (exercise).\n\n\\begin{defi}\nLet $V$ be a real vector space. An \\emph{inner product} on $V$ is a map $\\left<\\cdot, \\cdot\\right>: V\\times V \\to \\R$, satisfying\n\\begin{equation*}\n\\begin{aligned}\n&\\bullet \\left<\\mathbf{v},\\mathbf{v}\\right> \\geq 0 \\forall \\mathbf{v}\\in V;\\\\\n&\\bullet \\left<\\mathbf{v},\\mathbf{v}\\right> = 0 \\iff \\mathbf{v}=\\mathbf{0};\\\\\n&\\bullet \\left<\\mathbf{v},\\mathbf{w}\\right> = \\left<\\mathbf{w},\\mathbf{v}\\right>;\\\\\n&\\bullet \\left<\\mathbf{v},\\mathbf{w_1}+\\lambda \\mathbf{w_2}\\right> = \\left<\\mathbf{v},\\mathbf{w_1}\\right> + \\lambda\\left<\\mathbf{v},\\mathbf{w_2}\\right>.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\n\nThe standard inner product on $\\R^n$ is given by\n\\begin{equation*}\n\\begin{aligned}\n\\left<\\mathbf{v},\\mathbf{w}\\right> = \\mathbf{v}\\cdot\\mathbf{w}=\\sum_{i=1}^n v_i w_i\n\\end{aligned}\n\\end{equation*}\n\n\\begin{thm} (Cauchy-Schwartz inequality)\\\\\nIf $\\left<\\cdot,\\cdot\\right>$ is an inner product on $V$, then\n\\begin{equation*}\n\\begin{aligned}\n\\left<\\mathbf{v},\\mathbf{w}\\right>^2 \\leq \\left<\\mathbf{v},\\mathbf{v}\\right>\\left<\\mathbf{w},\\mathbf{w}\\right>.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nConsider $\\left<\\mathbf{v}+\\lambda\\mathbf{w},\\mathbf{v}+\\lambda\\mathbf{w}\\right>\\geq 0$ by definition. So\n\\begin{equation*}\n\\begin{aligned}\n\\left<\\mathbf{v},\\mathbf{v}\\right> + 2\\lambda\\left<\\mathbf{v},\\mathbf{w}\\right>+\\lambda^2\\left<\\mathbf{w},\\mathbf{w}\\right> \\geq 0\n\\end{aligned}\n\\end{equation*}\nNow if $ax^2 + bx + c\\geq 0$ for all $x\\in \\R$, then $ax^2+bx+c=0$ has at most one real root. So $b^2-4ac \\leq 0$.\\\\\nNow we've just seen $a\\lambda^2+b\\lambda+c\\geq 0$ for all $\\lambda\\in\\R$, where $a=\\left<\\mathbf{w},\\mathbf{w}\\right>$, $b=2\\left<\\mathbf{v},\\mathbf{w}\\right>$, $c=\\left<\\mathbf{v},\\mathbf{v}\\right>$. So\n\\begin{equation*}\n\\begin{aligned}\n4\\left<\\mathbf{v},\\mathbf{w}\\right>^2 \\leq 4\\left<\\mathbf{w},\\mathbf{w}\\right>\\left<\\mathbf{v},\\mathbf{v}\\right>\n\\end{aligned}\n\\end{equation*}\nwhich is the desired result.\n\\end{proof}\n\\end{thm}\n\n\\begin{coro}\nIf $\\left<,\\right>$ is an inner product on $V$, then $||\\mathbf{v}|| = \\left(\\left<\\mathbf{v},\\mathbf{v}\\right>\\right)^{\\frac{1}{2}}$ is a norm on $V$.\nFor the proof we just need to verify all the conditions again. Cauchy-Schwartz inequality is required for verifying the fourth condition.\n\\end{coro}\n\nAnother exercise: The norm on $\\R^n$ induced by the standard inner product is Euclidean length:\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}|| = |\\mathbf{v}| = \\left(\\sum_{i=1}^n v_i^2\\right)^\\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nThe metric induced by the norm is the Euclidean norm.\\\\\nAnd another exercise: is the Manhattan norm induced by an inner product on $\\R^n$?\n\n\\begin{eg}\nLet $V=\\R^n$.\\\\\n1) \n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||_1=\\sum_{i=1}^n |v_i|\n\\end{aligned}\n\\end{equation*}\nThe Manhattan norm;\\\\\n2)\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||_2 = \\left(\\sum_{i=1}^n v_i^2\\right)^\\frac{1}{2}\n\\end{aligned}\n\\end{equation*}\nThe Euclidean norm;\\\\\n3)\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||_\\infty = \\max_{1\\leq i \\leq n |v_i|}\n\\end{aligned}\n\\end{equation*}\n(In example sheet:\n\\begin{equation*}\n\\begin{aligned}\n||\\mathbf{v}||_p = \\left(\\sum_{i=1}^n |v_i|^p \\right)^\\frac{1}{p}\n\\end{aligned}\n\\end{equation*}\nis a norm for all $1\\leq p < \\infty$.)\n\\end{eg}\n\n\\begin{eg}\nLet\n\\begin{equation*}\n\\begin{aligned}\nV=C\\left[0,1\\right] := \\left\\{ f:\\left[0,1\\right] \\to \\R | f \\text{ is continuous} \\right\\}\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\n&\\left(\\lambda f\\right)\\left(x\\right) = \\lambda f\\left(x\\right),\\\\\n&\\left(f+g\\right) \\left(x\\right) = f\\left(x\\right) + g\\left(x\\right)\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n1)\n\\begin{equation*}\n\\begin{aligned}\n||f||_1 = \\int_0^1 |f\\left(x\\right)| dx\n\\end{aligned}\n\\end{equation*}\n2)\n\\begin{equation*}\n\\begin{aligned}\n||f||_2 = \\left(\\int_0^1 f\\left(x\\right)^2\\right)^\\frac{1}{2} dx\n\\end{aligned}\n\\end{equation*}\n3)\n\\begin{equation*}\n\\begin{aligned}\n||f||_\\infty = \\max_{x \\in \\left[0,1\\right]} |f\\left(x\\right)|\n\\end{aligned}\n\\end{equation*}\nThis is usually called the 'sup norm'.\\\\\nHow do we know that the first two norms satisfy the second condition, i.e. the norm is zero if and only if the function is zero? This is actually a standard result in analysis:\n\n\\begin{lemma}\nSuppose $f\\left[0,1\\right]\\to\\R$ is continuous. If $f \\not\\cong 0$, then\n\\begin{equation*}\n\\begin{aligned}\n\\int_0^1 |f\\left(x\\right)|>0\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nPick $x_0\\in\\left[0,1\\right]$ with $f\\left(x_0\\right) \\neq 0.$ Since $f$ is continuous, there exists $\\delta > 0$ such that\n\\begin{equation*}\n\\begin{aligned}\n|f\\left(x\\right) - f\\left(x_0\\right)| < \\frac{|f\\left(x_0\\right)|}{2}\n\\end{aligned}\n\\end{equation*}\nwhenever $|x-x_0| < \\delta$. Then for $|x-x_0|<\\delta$, we have\n\\begin{equation*}\n\\begin{aligned}\n|f\\left(x\\right)| > |f\\left(x_0\\right)| - \\frac{|f\\left(x_0\\right)|}{2} \\geq \\frac{|f\\left(x_0\\right)|}{2}\n\\end{aligned}\n\\end{equation*}\nSo if we define\n\\begin{equation*}\n\\begin{aligned}\ng\\left(x\\right) = \\left\\{\n\\begin{array}{ll}\n\\frac{|f\\left(x_0\\right)|}{2} & |x-x_0| < \\delta\\\\\n0 & \\text{  otherwise}\n\\end{array}\n\\right.\n\\end{aligned}\n\\end{equation*}\nThen $|f\\left(x\\right)| \\geq g\\left(x\\right)$ for all $x\\in\\left[0,1\\right]$.\\\\\nSo\n\\begin{equation*}\n\\begin{aligned}\n\\int_0^1 |f\\left(x\\right)| dx \\geq \\int_0^1 |g\\left(x\\right)| dx = 2\\delta \\frac{|f\\left(x_0\\right)|}{2} = \\delta |f\\left(x_0\\right)|>0.\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\n\\end{lemma}\n\n\\begin{eg}\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*}\nThen\n\\begin{equation*}\n\\begin{aligned}\n||f_n||_1 = \\int_0^1 |f\\left(x\\right)| dx = \\frac{1}{2}\\left(\\frac{1}{n}\\right)\\cdot 1 = \\frac{1}{2n} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $n\\to \\infty$.\\\\\nSo $\\left(f_n\\right) \\to 0$ with respect to the metric induced by $|| \\cdot ||_1$.\\\\\nOn the other hand,\n\\begin{equation*}\n\\begin{aligned}\n||f_n||_\\infty = 1\n\\end{aligned}\n\\end{equation*}\nregardless of $n$, since $f\\left(0\\right)=1$.\\\\\nThis means that $\\left(f_n\\right)$ does not converge to 0 as $n\\to \\infty$ with respect to the metric induced by $||\\cdot||_\\infty$, i.e. the sup norm.\n\\end{eg}\n\nExercise: is it possible to find a sequence that converges with respect to $||\\cdot||_1$ on $\\R^2$, but not with respect to $||\\cdot||_\\infty$?\n\n\\begin{eg} (The \\emph{p-adic} norm)\\\\\nLet $p \\in \\N$ be a prime number. If $a \\in \\Z$, let $|a|_p = p^{-k}$, where $p^k | a$, but $p^{k+1} \\nmid a$.\\\\\nSo\n\\begin{equation*}\n\\begin{aligned}\n&|0|_p = 0,\\\\\n&|ab|_p = |a|_p |b|_p,\\\\\n&|a+b|_p \\leq \\max\\left\\{|a|_p, |b|_p\\right\\} \\leq |a|_p + |b|_p\n\\end{aligned}\n\\end{equation*}\n\nIf $r=\\frac{a}{b} \\in \\Q$, define\n\\begin{equation*}\n\\begin{aligned}\n|r|_p  = \\frac{|a|_p}{|b|_p}\n\\end{aligned}\n\\end{equation*}\nThen the \\emph{p-adic metric} on $\\Q$ is defined by\n\\begin{equation*}\n\\begin{aligned}\nd_p \\left(r,s\\right) = |r-s|_p\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\nExercise: 1,2,4,8,16, ... $\\to 0$ with respect to $d_2$.\n\n\\newpage\n\\section{Open and Closed Subsets}\nLet $\\left(X,d\\right)$ be a metric space.\n\n\\begin{defi}\nIf $x\\in X$ and $r\\in \\R$ with $r>0$, let\n\\begin{equation*}\n\\begin{aligned}\nB_r\\left(x\\right) = \\left\\{ y\\in X | d\\left(x,y\\right) < r \\right\\}\n\\end{aligned}\n\\end{equation*}\nis the \\emph{open ball} of radius $r$ with centre $x$,\n\\begin{equation*}\n\\begin{aligned}\n\\bar{B}_r \\left(x\\right) = \\left\\{y \\in X | d\\left(x,y\\right) \\leq r \\right\\}\n\\end{aligned}\n\\end{equation*}\nis the \\emph{closed ball} of radius $r$ with centre $x$.\n\\end{defi}\n\n\\begin{eg}\nLet $X=\\R$ with the usual metric. Then\n\\begin{equation*}\n\\begin{aligned}\n&B_r\\left(a\\right) = \\left(a-r,a+r\\right),\\\\\n&\\bar{B}_r\\left(a\\right) = \\left[a-r,a+r\\right].\n\\end{aligned}\n\\end{equation*}\nThese are just the open and closed interval respectively.\n\\end{eg}\n\n\\begin{eg}\nLet $X=\\R^3$, with the Euclidean metric. Then\n\\begin{equation*}\n\\begin{aligned}\n\\bar{B}_1\\left(0\\right) = \\left\\{ \\mathbf{v}\\in \\R^3 | |\\mathbf{v}| \\leq 1\\right\\}\n\\end{aligned}\n\\end{equation*}\nwhich is a sphere with centre 0 and radius 1.\n\\end{eg}\n\n\\begin{eg}\nLet $X=\\R^2$, with the metric induced by\\\\ 1) the Manhattan norm, $||\\cdot ||_1$;\\\\\n2) the Euclidean norm, $||\\cdot ||_2$;\\\\\n3) the sup norm, $||\\cdot ||_\\infty$.\\\\\nNow consider $\\bar{B}_1\\left(0\\right)$. For the Manhattan norm, this is a square with with centre 0 and edges parallel to the axes(so with edge length 2); for the Euclidean norm this is a disc with centre 0 and radius 1; for the sup norm this is a square with centre 0 but edges making an angle of $\\frac{\\pi}{4}$ to the axes (so with edge length $\\sqrt{2}$).\n\\end{eg}\n\n\\begin{eg}\nLet $X=\\R^2$, $d$ is induced by an inner product $\\left<,\\right>$: if $\\mathbf{v}=x\\mathbf{e}_1+y\\mathbf{e}_2$, then\n\\begin{equation*}\n\\begin{aligned}\n\\left<\\mathbf{v},\\mathbf{v}\\right> = ax^2 + 2bxy + cy^2\n\\end{aligned}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{aligned}\nB_1\\left(0\\right) = \\left\\{\\left(x,y\\right) | ax^2+2bxy+cy^2 \\leq 1\\right\\}\n\\end{aligned}\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\begin{aligned}\na=\\left<\\mathbf{e}_1,\\mathbf{e}_1\\right>,\\\\\nb=\\left<\\mathbf{e}_1,\\mathbf{e}_2\\right>,\\\\\nc=\\left<\\mathbf{e}_2,\\mathbf{e}_2\\right>.\n\\end{aligned}\n\\end{equation*}\nThis is an ellipse.\\\\\nSo we know that $||\\cdot ||_\\infty$, $||\\cdot ||_1$ are not induced from an inner product on $\\R^2$.\n\\end{eg}\n\n\\begin{notation}\nIf $A\\subset X$ is a subset, then $X\\backslash A$, or $X-A$, is defined as\n\\begin{equation*}\n\\begin{aligned}\nX-A = \\left\\{x\\in X | x\\not\\in A\\right\\}\n\\end{aligned}\n\\end{equation*}\nwhich is called the complement of $A$ (in $X$).\n\\end{notation}\n\n\\begin{defi} (Open and closed subset)\\\\\nIf $A\\subset X$, we say $A$ is an \\emph{open subset} if for every $x\\in A$, $\\exists r>0$ such that $B_r\\left(x\\right) \\subset A$.\\\\\nIf $C\\subset X$, we say $C$ is a \\emph{closed subset} if $X-C$ is an open subset of $X$.\n\\end{defi}\n\n\\begin{prop}\nIf $X$ is a metric space, then $B_r\\left(x\\right)$ is an open subset of $X$, and $\\bar{B}_r\\left(x\\right)$ is a closed subset of $X$.\n\\begin{proof}\nSuppose $b\\in B_r\\left(a\\right)$. Then $d\\left(a,b\\right) < r$. So $r_0 = r-d\\left(a,b\\right)>0$. Now if $c\\in B_{r_0}\\left(b\\right)$, then\n\\begin{equation*}\n\\begin{aligned}\nd\\left(a,c\\right) \\leq d\\left(a,b\\right)+d\\left(b,c\\right)<d\\left(a,b\\right)+r_0=r\n\\end{aligned}\n\\end{equation*}\nSo $c\\in B_r\\left(a\\right)$. Thus $B_{r_0}\\left(b\\right) \\subset B_r\\left(a\\right)$. So $B_r\\left(a\\right)$ is open.\\\\\nFor the second part, we need to show that\n\\begin{equation*}\n\\begin{aligned}\nX-\\bar{B}_r\\left(a\\right) = \\left\\{ x\\in X | d\\left(x,a\\right)>r\\right\\}\n\\end{aligned}\n\\end{equation*}\nis open. The proof is analogous to the previous proof.\n\\end{proof}\n\\end{prop}\n\n\\begin{rem}\nNote that $A\\subset X$ may be \\emph{neither} open nor closed. In fact if we take a random subset from a random metric space $X$, this is most likely the case. For example, consider $X=\\R$ with the usual metric. then an obvious example is $\\left[0,1\\right)$,which is neither open nor closed; $\\Q \\subset \\R$ is a more subtle example.\n\\end{rem}\n\n\\begin{rem}\n$A\\subset X$ can also be \\emph{both} open and closed. Consider\n\\begin{equation*}\n\\begin{aligned}\nX=\\left[-1,1\\right]-\\left\\{0\\right\\}\n\\end{aligned}\n\\end{equation*}\nas a subspace of $\\R$. Then\n\\begin{equation*}\n\\begin{aligned}\nA=\\left[-1,0\\right)=B_1\\left(-1\\right) \\subset X\n\\end{aligned}\n\\end{equation*}\nis open. On the other hand, this is also a closed ball, since it is also\n\\begin{equation*}\n\\begin{aligned}\n\\bar{B}_{\\frac{1}{2}} \\left(-\\frac{1}{2}\\right) \\subset X\n\\end{aligned}\n\\end{equation*}\nSo $A$ is both closed and open in $X$.\n\\end{rem}\n\n\\begin{rem}\nNote that being open or closed is \\emph{not} a property of a space, but a property of a subset of a space.\\\\\nWe've seen that $\\left[-1,0\\right)$ is not a closed subset of $\\R$, but it \\emph{is} a closed subset of $\\left[-1,1\\right] - \\left\\{0\\right\\}$.\n\\end{rem}\n\n\\begin{defi}\nIf $\\left(X,d\\right)$ is a metric space and $x\\in X$, then $U$ is an \\emph{open neighbourhood} of $x$ if $U\\subset X$ is open and $x\\in U$.\n\\end{defi}\n\n\\begin{prop}\nSuppose sequence $\\left(x_n\\right) \\to x$ and $U$ is an open neighbourhood of $x$. Then there exists $N$ such that $x_n\\in U$ for all $n>N$.\n\\begin{proof}\nSince $U\\subset X$ is open, $x\\in U$, $\\exists \\varepsilon > 0$ with\n\\begin{equation*}\n\\begin{aligned}\nB_\\varepsilon \\left(x\\right) \\subset U.\n\\end{aligned}\n\\end{equation*}\nSince $\\left(x_n\\right) \\to x$, $\\exists N$ such that $d\\left(x_n,x\\right) < \\varepsilon$ whenever $n>N$. This implies that\n\\begin{equation*}\n\\begin{aligned}\nx_n \\in B_\\varepsilon \\left(x\\right)\n\\end{aligned}\n\\end{equation*}\nwhenever $n>N$. So $x_n\\in U$ whenever $n>N$.\n\\end{proof}\n\\end{prop}\n\n\\begin{defi} (Limit point)\\\\\nIf $\\left(X,d\\right)$ is a metric space and $A \\subset X$, we say $x\\in X$ is a \\emph{limit point} of $A$ if there is a sequence $\\left(x_n\\right) \\to x$ with $x_n \\in A$ for all $n$.\n\\end{defi}\n\n\\begin{eg}\nIf $a\\in A$, then $a$ is a limit point of $A$. We can just take a constant sequence with value $a$, which clearly converges to $a$.\n\\end{eg}\n\n\\begin{eg}\nLet $X = \\R$ with the usual metric, $A=\\left(0,1\\right)$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\left(\\frac{1}{n}\\right) \\to 0\n\\end{aligned}\n\\end{equation*}\nand $\\frac{1}{n} \\in A$ for all $n\\geq 1$. So $0$ is a limit point of $A$.\n\\end{eg}\n\n\\begin{prop}\nSuppose $C\\subset X$ is a closed subset and $x$ is a limit point of $C$. Then $x \\in C$.\n\\begin{proof}\nSuppose $\\left(x_n\\right) \\to x$, where $x_n \\in C$, but $x\\not\\in C$.\\\\\nSince $C$ is closed, $U=X-C$ is open. So\n\\begin{equation*}\n\\begin{aligned}\nx \\not\\in C \\implies X \\in U\n\\end{aligned}\n\\end{equation*}\nSo $U$ is an open neighbourhood of $x$.\\\\\nNow $\\left(x_n\\right)$ converges to $x$ and $U$ is an open neighbourhood. So by the previous proposition, there exists an $N$ such that $x_n \\in U$ for all $n>N$. But $x_n \\in C$ for all $n$. Contradiction.\n\\end{proof}\n\\end{prop}\n\n\\begin{thm}\nSuppose $f:\\left(X,d_X\\right) \\to \\left(Y,d_Y\\right)$. Then the following conditions are equivalent:\\\\\n1) $f$ is continuous;\\\\\n2) $f^{-1}\\left(U\\right)$ is open in $X$ whenever $U$ is open in $Y$;\\\\\n3) $f^{-1}\\left(C\\right)$ is closed in $X$ whenever $U$ is closed in $Y$.\n\\end{thm}\n\n\n\\end{document}", "meta": {"hexsha": "4aa29db44ad27b93e72ddcc6a0758c680989a4d7", "size": 23390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Metric and Topological spaces.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/Metric and Topological spaces.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/Metric and Topological spaces.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": 33.2716927454, "max_line_length": 439, "alphanum_fraction": 0.6580589996, "num_tokens": 9387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6287803831382017}}
{"text": "\\hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{}\\section{numpp\\+:\\+:differentiation\\+:\\+:symbolic\\+:\\+:differentiate$<$ Function, Order $>$ Class Template Reference}\n\\label{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}\\index{numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, Order $>$@{numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, Order $>$}}\n\n\nAllows differentiation of N-\\/th order.  \n\n\n\n\n{\\ttfamily \\#include $<$functions.\\+hpp$>$}\n\n\\subsection*{Public Types}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_ac0c973a49c1b2e262edd5345c4f569a7}\\label{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_ac0c973a49c1b2e262edd5345c4f569a7}} \n{\\footnotesize template$<$std\\+::size\\+\\_\\+t Variable, std\\+::size\\+\\_\\+t... Variables$>$ }\\\\using {\\bfseries with\\+\\_\\+respect\\+\\_\\+to} = typename \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{differentiate}$<$ typename Function\\+::template derivative$<$ Variable $>$, Order-\\/1 $>$\\+::template with\\+\\_\\+respect\\+\\_\\+to$<$ Variables... $>$\n\\end{DoxyCompactItemize}\n\n\n\\subsection{Detailed Description}\n\\subsubsection*{template$<$typename Function, std\\+::size\\+\\_\\+t Order$>$\\newline\nclass numpp\\+::differentiation\\+::symbolic\\+::differentiate$<$ Function, Order $>$}\n\nAllows differentiation of N-\\/th order. \n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em Function} & Function which should be differentiated, see /ref numpp\\+\\_\\+differentiation\\+\\_\\+symbolic \\char`\\\"{}tutorial\\char`\\\"{} for more info \\\\\n\\hline\n\\end{DoxyTemplParams}\n\n\\begin{DoxyParams}{Parameters}\n{\\em Order} & order of the differentiation, e.\\+g. 3 for 3rd order\\\\\n\\hline\n\\end{DoxyParams}\n\n\\begin{DoxyCode}\n\\textcolor{preprocessor}{#include\"numpp/differentiation/symbolic.hpp\"}\n\\end{DoxyCode}\n \n\nThe documentation for this class was generated from the following file\\+:\\begin{DoxyCompactItemize}\n\\item \ndifferentiation/symbolic/functions.\\+hpp\\end{DoxyCompactItemize}\n", "meta": {"hexsha": "3ac5af7bfb6faab067e17d2de069669648257ea5", "size": 2061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/classnumpp_1_1differentiation_1_1symbolic_1_1differentiate.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/classnumpp_1_1differentiation_1_1symbolic_1_1differentiate.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/classnumpp_1_1differentiation_1_1symbolic_1_1differentiate.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": 45.8, "max_line_length": 366, "alphanum_fraction": 0.7622513343, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6287803806284479}}
{"text": "\\chapter{Mathematical Model of Vehicle Dynamics}\n\nThis chapter will detail the mathematical model that was developed to describe the motion of the uDrone. \n\n\\section{Reference Frames and State Space}\n\nConventions for creating this model will follow those laid out by Thor Fossen in the 2011 Handbook of Marine Craft Hydrodynamics and Control. The fixed world frame is defined using the North-East-Down (NED) coordinate system, represented as $\\{n\\} = (x_n, y_n, z_n)$. in this system, $x_n$ points North, $y_n$ points East, and $z_n$ points down. \n\nThe body-fixed frame $\\{b\\} = (x_b, y_b, z_b)$ is fixed its origin point, $o_b$, to the uDrone. For purposes of this model, $o_b$ is set at the point on the plane of the motors at the back of the uDrone that is along its center-line. $x_b$ runs along the center-line of the vehicle, pointing from the aft (back) of the uDrone to the fore (front). $z_b$ runs from top to bottom and, following the right-hand rule, $y_b$ runs towards the starboard (right). Further, following convention, roll is defined as rotation about $x_b$, pitch as rotation about $y_b$, and yaw as rotation about $z_b$, with counter-clockwise (CCW) being the positive direction. \n\nThis choice of body frame origin reduces the complexity of modeling the forces produced by the motors. The drawback is some added complexity caused by the moments of the center of buoyancy and center of gravity relative to the chosen origin, but this is more straight forward than the complexity of calculating motor forces about a different point.\n\nThe position of the vehicle, or the body-fixed frame $\\{b\\}$, with respect to the world frame $\\{n\\}$ is expressed as $\\bm{p} = [N, E, D]^T$. The attitude of the vehicle is expressed as $\\bm{\\Theta} = [\\phi, \\theta, \\psi]^T$ using Euler angles. Together these create the 6-dimensional position/orientation vector $\\bm{\\eta} = [\\bm{p}, \\bm{\\Theta]}^T$. The linear and angular velocities are expressed with respect to the vehicles fixed frame $\\{b\\}$. The linear velocity is $\\bm{v} = [u, v, w]^T$ and angular velocity $\\bm{\\omega} = [p, q, r]^T$. when combine, these form the combine 6-dimensional velocity vector $\\bm{\\nu}= [\\bm{v}, \\bm{\\omega]}^T$. All together, $\\boldsymbol{\\eta}$ and $\\boldsymbol{\\nu}$ represent the 12-dimensional state space describing the state of the uDrone \\parencite{thor_kin}. \n\n% \\begin{align*}\n%      \\boldsymbol{p}^{n}_{b}=\\left[\\begin{array}{c}\n%         N \\\\ E \\\\ D\n%      \\end{array}\\right]\n%      \\bm{\\Theta}^{n}_{b}=\\left[\\begin{array}{c}\n%         \\phi \\\\ \\theta \\\\ \\psi\n%      \\end{array}\\right]\n%      \\bm{\\eta}=\\left[\\begin{array}{c}\n%         \\bm{p} \\\\ \\bm{\\Theta}\n%      \\end{array}\\right]\n% \\end{align*}\n% \\begin{align*}\n%      \\boldsymbol{v}^{b}_{b}=\\left[\\begin{array}{c}\n%         u \\\\ v \\\\ w\n%      \\end{array}\\right]\n%      \\bm{\\omega}^{b}_{b}=\\left[\\begin{array}{c}\n%         p \\\\ q \\\\ r\n%      \\end{array}\\right]\n%      \\bm{\\nu}=\\left[\\begin{array}{c}\n%         \\bm{v} \\\\ \\bm{\\omega}\n%      \\end{array}\\right]\n% \\end{align*}\n\n\n\n\\section{Equations of Motions}\n\nThe general equation of motion for the uDrone can be derived as a function of the combine linear and angular velocity vector $\\boldsymbol{\\nu}$ \\parencite{thor_mod}. This is shown in equation \\ref{eqm}.\n\n\\begin{gather}\n\\underbrace{\\boldsymbol{M}_{R B} \\dot{\\boldsymbol{\\nu}}+\\boldsymbol{C}_{R B}(\\boldsymbol{\\nu}) \\boldsymbol{\\nu}}_{\\text {rigid-body forces}}+\\underbrace{\\boldsymbol{M}_{A} \\dot{\\boldsymbol{\\nu}}+\\boldsymbol{C}_{A}\\left(\\boldsymbol{\\nu}\\right) \\boldsymbol{\\nu}+\\boldsymbol{D}\\left(\\boldsymbol{\\nu}\\right) \\boldsymbol{\\nu}}_{\\text {hydrodynamic forces}}+\\underbrace{\\boldsymbol{g}(\\boldsymbol{\\eta})}_{\\text{hydrostatic forces}}=\\boldsymbol{\\tau}\n\\label{eqm}\n\\end{gather}\nWith the terms defined as:\n\\begin{align*}\n    \\boldsymbol{\\eta}&=\\text{combine position and orientation}\\\\\n    \\boldsymbol{\\nu}&=\\text{combine linear and angular velocity}\\\\\n    \\dot{\\boldsymbol{\\nu}}&=\\text{combine linear and angular acceleration}\\\\\n    \\boldsymbol{M}_{R B}&=\\text{rigid-body system inertia matrix}\\\\\n    \\boldsymbol{C}_{R B}(\\boldsymbol{\\nu})&=\\text{rigid-body Coriolis matrix}\\\\\n    \\boldsymbol{M}_{A}&=\\text{added mass system inertia matrix}\\\\\n    \\boldsymbol{C}_{A}(\\boldsymbol{\\nu})&=\\text{added mass Coriolis matrix}\\\\\n    \\boldsymbol{D}(\\boldsymbol{\\nu})&=\\text{damping matrix}\\\\\n    \\boldsymbol{g}(\\boldsymbol{\\eta})&=\\text{gravitational and buoyant forces}\\\\\n    \\boldsymbol{\\tau}&=\\text{control inputs}\n\\end{align*}\n% \\begin{align*}\n%     \\boldsymbol{\\eta}&=\\text{combine position and orientation}\\\\\n%     \\boldsymbol{\\nu}&=\\text{combine linear and angular velocity}\\\\\n%     \\dot{\\boldsymbol{\\nu}}&=\\text{combine linear and angular acceleration}\\\\\n%     \\boldsymbol{\\tau}&=\\text{control inputs}\\\\\n%     \\boldsymbol{M}&=\\text{system inertia matrix}\\\\\n%     \\boldsymbol{C}(\\boldsymbol{\\nu})&=\\text{Coriolis matrix}\\\\\n%     \\boldsymbol{D}(\\boldsymbol{\\nu})&=\\text{damping matrix}\\\\\n%     \\boldsymbol{g}(\\boldsymbol{\\eta})&=\\text{gravitational and buoyant forces}\\\\\n%     \\boldsymbol{\\tau}&=\\text{control inputs}\n% \\end{align*}\n% \\begin{align*}\n%     \\boldsymbol{M}&=\\boldsymbol{M}_{R B}+\\boldsymbol{M}_{A}\\\\\n%     \\boldsymbol{C}&=\\boldsymbol{C}_{R B}+\\boldsymbol{C}_{A}\n% \\end{align*}\n\n\\section{Rigid-Body Forces}\n\nThe exact values of the system inertia ($\\boldsymbol{M}$), Coriolis ($\\boldsymbol{C}$), and Drag ($\\boldsymbol{D}$) matrices can be determined either through intensive hydrodynamic modeling or experimentation. Due to the complexity of hydrodynamic modeling, experimentation is typically used to determine these values in underwater vehicles similar to the uDrone \\parencite{hipp_pen}. It is possible, however, to estimate the rigid body matrix values using information about the vehicle generated from the 3D model. This section details these estimations and explains how they were calculated. \n\nThe rigid body system inertia matrix about the center of origin can be calculated using equation \\ref{mrb} which is found in \\cite{thor_rb}.\n\\begin{gather}\n    \\boldsymbol{M}_{R B}^{C O}=\\left[\\begin{array}{cc}\n        m \\boldsymbol{I}_{3 \\times 3} & -m \\boldsymbol{S}\\left(\\boldsymbol{r}_{g}^{b}\\right) \\\\\n        m \\boldsymbol{S}\\left(\\boldsymbol{r}_{g}^{b}\\right) & \\boldsymbol{I}_{g}-m \\boldsymbol{S}^{2}\\left(\\boldsymbol{r}_{g}^{b}\\right)\n    \\end{array}\\right]\n    \\label{mrb}\n\\end{gather}\n% \\begin{align*}\n%     \\boldsymbol{M}_{R B}^{C O}&=\\text{rigid body system inertia matrix about the body fixed-frame origin}\\\\\n%     \\boldsymbol{I}_{3 \\times 3}&=\\text{3 by 3 identity matrix}\\\\\n%     m&=\\text{mass}\\\\\n%     \\boldsymbol{S}(\\cdot)&=\\text{cross product operator}\\\\\n%     \\boldsymbol{r}_{g}^{b}&=\\text{ vector from the body fixed-frame origin to the center of gravity}\\\\\n%     \\boldsymbol{I}_{g}&=\\text{inertia matrix}\n% \\end{align*}\n\nIn this equation, $m$ is the mass, $\\boldsymbol{I}_{3 \\times 3}$ is the three-by-three identity matrix, $\\boldsymbol{I}_{g}$ is the inertia matrix and $\\boldsymbol{r}_{g}^{b}$ is the vector from the body fixed-frame origin to the center of gravity. $\\boldsymbol{S}$ is the cross product operator matrix. Before the final vehicle was constructed, m, $\\boldsymbol{I}_{g}$, and $\\boldsymbol{r}_{g}^{b}$ were taken from the 3D model. Those estimates are shown in equation \\ref{m_matrix}.\n\n\\begin{equation}\n\\boldsymbol{M}_{R B}^{C O}=\\left[\\begin{array}{cccccc}\n9.9000 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 9.9000 & 0 & 0 & 0 & 1.4850 \\\\\n0 & 0 & 9.9000 & 0 & -1.4850 & 0 \\\\\n0 & 0 & 0 & 0.3420 & 0.0010 & -0.0001 \\\\\n0 & 0 & -1.4850 & 0.0010 & 0.5577 & -0.0015 \\\\\n0 & 1.4850 & 0 & -0.0001 & -0.0015 & 0.3167\n\\end{array}\\right]\n\\label{m_matrix}\n\\end{equation}\n\n\nWith a completed vehicle these numbers can be verified and varied if needed. For example, with no ballast, the uDrone is positively buoyant. Therefore, to maintain its depth without using power to stay underwater ballast will need to be added. By placing the ballast closer to the center of the vehicle, the moments of inertia will decrease. Conversely, by placing it further from the center the moments can be increased. Additionally, the ballast can be used to change the center of gravity relative to the center of buoyancy. This will create a moment in the vehicle that can help it stay oriented or level in specific ways. This relationship is discussed further in the section \\ref{hydrostatics}. \n\nThe Coriolis matrix is a function of the angular velocity of the vehicle and can be derived as shown in equation \\ref{crb} from \\cite{thor_rb}.\n\\begin{gather}\n    \\boldsymbol{C}_{RB}^{CO}(\\boldsymbol{\\nu})=\\left[\\begin{array}{cc}\n        m \\boldsymbol{S}\\left(\\boldsymbol{\\omega}^{b}\\right) & -m \\boldsymbol{S}\\left(\\boldsymbol{\\omega}^{b}\\right) \\boldsymbol{S}\\left(\\boldsymbol{r}_{g}^{b}\\right) \\\\\n        m \\boldsymbol{S}\\left(\\boldsymbol{r}_{g}^{b}\\right) \\boldsymbol{S}\\left(\\boldsymbol{\\omega}^{b}\\right) & -\\boldsymbol{S}\\left(\\left(\\boldsymbol{I}_{g}-m \\boldsymbol{S}^{2}\\left(\\boldsymbol{r}_{g}^{b}\\right)\\right) \\boldsymbol{\\omega}^{b}\\right)\n    \\end{array}\\right]\n    \\label{crb}\n\\end{gather}\n% \\begin{align*}\n%     \\boldsymbol{C}_{R B}^{C O}&=\\text{rigid body Coriolis matrix about the body fixed-frame origin}\\\\\n%     m&=\\text{mass}\\\\\n%     \\boldsymbol{S}(\\cdot)&=\\text{cross product operator}\\\\\n%     \\boldsymbol{\\omega}^b&=\\text{body-fixed frame angular velocity}\\\\\n%     \\boldsymbol{r}_{g}^{b}&=\\text{ vector from the body fixed-frame origin to the center of gravity}\\\\\n%     \\boldsymbol{I}_{g}&=\\text{inertia matrix}\n% \\end{align*}\n\nWhere $\\boldsymbol{\\omega}^{b}$ is the body-fixed frame angular velocity vector. Since this matrix is a function of the vehicle state, it will change with motion. The actual calculations of this matrix are handled by a MatLab program written as a companion to Thor Forson’s book \\parencite{mss}. The values based on the system inertia matrix in equation \\ref{m_matrix} along with a velocity state vector $\\bm{\\nu}= [1,0,0,0,0,0]^T$, which represents only forward motion, is shown in equation \\ref{c_matrix}.\n\n\\begin{equation}\n\\boldsymbol{C}_{RB}^{CO}(\\boldsymbol{\\nu})=\\left[\\begin{array}{cccccc}\n0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 9.9000 \\\\\n0 & 0 & 0 & 0 & -9.9000 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 9.9000 & 0 & 0 & 0 \\\\\n0 & -9.9000 & 0 & 0 & 0 & 0\n\\end{array}\\right]\n\\label{c_matrix}\n\\end{equation}\n\n\\section{Hydrostatic Forces} \\label{hydrostatics}\n\nThe hydrostatic term $\\boldsymbol{g}(\\boldsymbol{\\eta})$ accounts for the forces on the uDrone caused by gravity and buoyancy. The force of gravity, or weight ($W$) is equal to the mass of the uDrone times the acceleration due to gravity. The buoyant force ($B$) is the weight of the water displaced by the uDrone. This is calculated by multiplying the volume of the uDrone, the density of water, and the acceleration due to gravity. If the location of the center of gravity and center of buoyancy (or center of volume) of the uDrone are not in the same spot then there will be a moment on the whole vehicle. Similarly, if the two forces are not equal then there will also be a net linear force on it. This value is a function of the orientation of the vehicle and can be seen in equation \\ref{bigG} \\parencite{thor_rb}. \n\n\\begin{equation}\\label{bigG}\n\\boldsymbol{g}(\\boldsymbol{\\eta})=\\left[\\begin{array}{llll} \n& (W-B) \\sin (\\theta) \\\\\n- & (W-B) \\cos (\\theta) \\sin (\\phi) \\\\\n- & (W-B) \\cos (\\theta) \\cos (\\phi) \\\\\n- & \\left(y_{g} W-y_{b} B\\right) \\cos (\\theta) \\cos (\\phi) & + & \\left(z_{g} W-z_{b} B\\right) \\cos (\\theta) \\sin (\\phi) \\\\\n& \\left(z_{g} W-z_{b} B\\right) \\sin (\\theta) & + & \\left(x_{g} W-x_{b} B\\right) \\cos (\\theta) \\cos (\\phi) \\\\\n- & \\left(x_{g} W-x_{b} B\\right) \\cos (\\theta) \\sin (\\phi) & - & \\left(y_{g} W-y_{b} B\\right) \\sin (\\theta)\n\\end{array}\\right]\n\\end{equation}\n\n% \\begin{equation}\n%   \\boldsymbol{g}(\\boldsymbol{\\eta})=\\left[\\begin{array}{llll}  \n%   0\\\\0\\\\0\\\\0\\\\0\\\\0\n%   \\end{array}\\right]\n% \\end{equation}\n\nBallasting can be used to adjust the weight and center of mass on the uDrone. To simplify this equation the ballast is set so that the weight and buoyancy are equal and the center of mass and buoyancy are the same. This means the $\\boldsymbol{g}$ vector will be zeros for all $\\boldsymbol{\\eta}$. These forces can be seen interacting on the uDrone in figure \\ref{cord_frame}. Maintaining overlapped centers of buoyancy and gravity also makes the vehicle more nimble as there are less moments to overcome when rotating. This also has the benefit of making the uDrone more maneuverable. Equal weight and buoyancy reduces energy used as the uDrone does not need to overcome a force making it sink or float as it cruises through the water column. \n\nThere might be reasons to adjust the ballasting of the uDrone to impart other properties on it. For example, if the vehicle is slightly positively buoyant than it will float in the event of a power failure, allowing for it to be recovered more easily. Also, if the center of gravity is placed below the center of buoyancy, but still in line with it in the z body direction, then the vehicle will be self righting in roll. This could make control easier as roll, which should be at zero most of the time, can be ignored.\n\n\\section{Hydrodynamic Forces} \\label{hydrodynamics}\n\nThe added mass system inertia matrix and added mass Coriolis matrix can only be determined through experimentation or complex fluid dynamic simulation and are not calculated in the scope of this thesis. The damping matrix, however, can be estimated using drag calculations. \n\nThe vehicle is modeled as a flat-faced cylinder moving through water in a direction along its axis. This estimation neglects two factors: 1) drag from the motors, and 2) rotational damping. Both of these forces are small in comparison to the drag of the flat-faced cylinder, so for the purposes of an approximate model, they can be ignored. \n\nThe force of drag in a single direction can be calculated using the drag equation:\n\n\\begin{gather}\nF_{D}=C_{D} A \\frac{\\rho V^{2}}{2}\n\\end{gather}\n\\begin{align*}\n    F_D&=\\text{drag Force}\\\\\n    C_D&=\\text{coefficient of drag}\\\\\n    A&=\\text{cross-sectional area normal to velocity}\\\\\n    \\rho&=\\text{fluid density}\\\\\n    V&=\\text{velocity}\\\\\n\\end{align*}\n\nBased on the ratio of the diameter to the length of the main body of the uDrone, the Coefficient of drag in the direction of motion is estimated at 0.8. The density of salt water is 1024kg/m$^3$ and the surface area is calculated from the diameter of the eight inch cylinder, which is 0.037m$^2$. Putting this all together, damping force can be calculated as a function of velocity. This is:\n\n\\begin{gather}\n    \\boldsymbol{D}(\\boldsymbol{\\nu})\\boldsymbol{\\nu}=\\left[\\begin{array}{c}\n        -15.0u ^2 \\\\ \\sim 0 \\\\ \\sim 0 \\\\ D_{roll} \\\\ D_{pitch} \\\\ D_{yaw}\n     \\end{array}\\right]\n\\end{gather}\n\n$u$ is the velocity in the x body direction. The last three values which refer to the rotational damping. For the purposes of calculations in the next section these values were assumed to be zero. The second and third terms, however, will always be zero, or nearly zero, as the vehicle cannot independently move in the Y or Z direction.\n\n\\section{Control Inputs}\\label{control_inputs}\n\nThe control inputs are the forces put on the uDrone from the thrusters. The four motor of the uDrone are arranged on a plane, all facing the same direction. The center point between all the thrusters along that plane is the Center of Origin $C_O$ for the vehicle. Thrusters one and three spin in a counterclockwise direction while thrusters two and four spin clockwise for forward thrust. This ensures that the vehicle has no roll moment when moving forward. Figure \\ref{cord_frame} shows the uDrone with the $C_O$ and rotation direction of the thrusters. \n\n\\begin{figure}[h]\n\\includegraphics[width=\\maxwidth{\\textwidth}]{img/cord_frame.png}\n\\caption{uDrone Coordinate Frame and Motor Directions}\n\\label{cord_frame}\n\\end{figure}\n\nUsing this convention it is possible to determine the actuation matrix, tau, as a function of thruster inputs.\n\n\\begin{gather}\n    \\boldsymbol{\\tau}=\\left[\\begin{array}{c}\n        F_1+F_2+F_3+F_4 \\\\ 0 \\\\ 0 \\\\ M_1-M_2+M_3-M_4 \\\\ (F_2+F_3-F_1-F_4) \\frac{L}{\\sqrt{2}} \\\\ (F_1+F_2-F_3-F_4) \\frac{L}{\\sqrt{2}}\n     \\end{array}\\right]\n     \\label{tau}\n\\end{gather}\n\nIn equation \\ref{tau} $F_x$ indicates the linear force produced by the $x^{th}$ motor and $M_x$ indicates the angular momentum produced by the $x^{th}$. $L$ is 0.115m, the length from $C_O$ to the center of the motor, which is the same for each motor. Unfortunately, there is no data from Blue Robotics about the moment of the thrusters, so the relationship between control input to the roll moment will need to be determined experimentally. Data is available, however, correlating motor power and thrust force. \n\n\\begin{figure}[h]\n\\includegraphics[width=\\maxwidth{\\textwidth}]{img/force_amps.png}\n\\caption{Force Output vs. Current Draw for T200 Thruster at 14 Volts}\n\\label{force_amp}\n\\legend{\\emph{Source}: \\iftoggle{usebiblatex}{\\textcite{t200}}{\\citet{t200}}}% See: https://upload.wikimedia.org/wikipedia/commons/8/89/Antidorcas_marsupialis%2C_male_%28Etosha%2C_2012%29.jpg\n% \\legend{\\emph{Note}: Here is a note that is especially long to show what happens when it extends to more than one line.}\n\\end{figure}\n\n\nUsing the figure \\ref{force_amp}, along with data about the uDrone battery, it is possible to calculate the maximum velocity, running time at this velocity, and running time at the operational velocity of 1m/s. While the uDrone can carry two 14V, 18Ah batteries, the intent is to use one for thrusters and the other to control all electronics. Therefore, all longevity calculations are done assuming 18Ah are available for thruster actuation. \n\nIn order to calculate maximum velocity, the drag equation is set equal to the maximum thruster force. The T200 thrusters produce a maximum thrust of 41.68N each. This is 166.7N of total thrust. Setting this equal to $15u^2$ and solving yields a maximum speed of 3.33m/s. Maintaining this velocity takes 20.29A, for a total of 81.16A. The uDrone could only maintain this speed for approximately 13.3 minute with an 18Ah battery.\n\nTypically, however, the uDrone will be cruising at a speed of 1m/s. At this speed, the drag force is approximately 15N. To maintain this thrust each motor must produce about 3.75N of force. To maintain this force each motor will use approximately 0.5A, for a total of 2A. In order to stay conservative, a 50\\% safety factor will be added to this value to account for uncalculated drag forces and actuation that affect orientations, not just forward motion. With this addition, the vehicle will use 3A for actuation during normal operation. With a single 18Ah battery used for thrusters, this will yield a dive time of approximately 6 hours. \n", "meta": {"hexsha": "d677b8a40c5a21476fc7e7aa3a47ab022f745cfd", "size": 18832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "model.tex", "max_stars_repo_name": "auman66/asu-thesis", "max_stars_repo_head_hexsha": "402c17282b3e4b590539238aca405b1c071305af", "max_stars_repo_licenses": ["Info-ZIP", "Linux-OpenIB"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "model.tex", "max_issues_repo_name": "auman66/asu-thesis", "max_issues_repo_head_hexsha": "402c17282b3e4b590539238aca405b1c071305af", "max_issues_repo_licenses": ["Info-ZIP", "Linux-OpenIB"], "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.tex", "max_forks_repo_name": "auman66/asu-thesis", "max_forks_repo_head_hexsha": "402c17282b3e4b590539238aca405b1c071305af", "max_forks_repo_licenses": ["Info-ZIP", "Linux-OpenIB"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.1361702128, "max_line_length": 821, "alphanum_fraction": 0.7163870008, "num_tokens": 5493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6286773728930908}}
{"text": "\n\\section*{Motivation}\n\n\\subsection*{Why are we interested in the Ising model?}\n%\\subsection{The Ising model: a model found in statistical mechanics}\n\n\\begin{frame}\n\t  \tThe Ising model is a mathematical model of ferromagnetism in statistical mechanics.\n\n    Probability of a configuration $\\sigma$ ({\\color{TurkishRose}\\textit{Boltzmann distribution}}):\n    \\begin{align*}\n    P_\\beta(\\sigma) & = e^{-\\beta H(\\sigma)} / Z(G), \\\\ \n    Z(G) & = \\sum_{\\sigma \\colon V \\to \\{+,-\\}} e^{- \\beta H(\\sigma)}.\n    \\end{align*}\n    \n    \\begin{itemize}\n    \t\\item $Z(G)$ is \\textit{the partition function of the Ising model}.\n    \t\\item $Z(G)$ encodes information about the physical system.\n    \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n\t\t     \\begin{align*}\n\t\t     P_\\beta(\\sigma) & = e^{-\\beta H(\\sigma)} / Z(G), \\\\ \n\t\t     Z(G) & = \\sum_{\\sigma \\colon V \\to \\{+,-\\}} e^{- \\beta H(\\sigma)}.\n\t\t     \\end{align*}\n\t\t     \n\t\\begin{enumerate}\t\t\t\n\t\t\\item {\\color{TurkishRose} \\textbf{Problem:}} What is the complexity of evaluating $Z(G)$? \\\\\n\t\t%{\\color{TurkishRose}\\textbf{Answer:}}\n\t\t$\\# \\mathfs{P}$-hard in some cases.\n\t\t\n\t\t\\item For some of those cases, $Z(G)$ admits a \\textit{fully polynomial-time randomised approximation scheme} \\\\\n\t\t(Jerrum and Sinclair, 1993,  G\\\"odel prize in 1996).\n\t\t\n\t\t\\item {\\color{TurkishRose} \\textbf{Problem:}} What is the complexity of approximating $Z(G)$?\n\t\t\n\t\t\\item {\\color{TurkishRose} \\textbf{Application:}}  Strongly simulating \\textit{instantaneous quantum polynomial-time circuits} is equivalent to approximating $|Z(G)|$ for some parameters.\n\t\\end{enumerate}\n\\end{frame}\n\n", "meta": {"hexsha": "67c4e71d93f473ec00b4573e3a4fadf4feebb656", "size": 1603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Slides/Sections/motivation.tex", "max_stars_repo_name": "andreshp/LatexTemplates", "max_stars_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-10-14T17:46:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-22T20:02:09.000Z", "max_issues_repo_path": "Slides/Sections/motivation.tex", "max_issues_repo_name": "andreshp/PlantillasLatex", "max_issues_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-04-11T09:14:42.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-11T09:21:16.000Z", "max_forks_repo_path": "Slides/Sections/motivation.tex", "max_forks_repo_name": "andreshp/LatexTemplates", "max_forks_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-10-14T17:54:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-15T06:39:01.000Z", "avg_line_length": 37.2790697674, "max_line_length": 189, "alphanum_fraction": 0.6500311915, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6286773594217868}}
{"text": "\\section{Error Calculation}\n\\label{sec:Error_Calculation}\nThis section contains the error calculation of the measured values. The error calculation is done for the fitted values width $w$, diameter $d$ and grid constant $g$ (see sections \\ref{subsec:Slit} to \\ref{subsec:Cross-Grid}).\n\n\\subsection{Uncertainties}\n\\label{subsec:Uncertainties}\nAll conducted measurements in this experiment have uncertainties. Although it was possible to read the position on the y-axis to half a millimeter, the uncertainty is still one millimeter. This is due to the difficulty to find the exact center of the minima or maxima. The systematic uncertainties are shown in table \\ref{tab:equipment} ($s_x = 1$ mm and $s_y = 1$ mm).\n\n\\subsection{Uncertainty of the Angle $\\varphi$}\n\\label{subsec:Uncertainty_Angle}\nThe uncertainty $s_\\varphi$ of the angle $\\varphi$ is calculated with the following equation \\ref{eq:uncertainty_angle}:\n\n\\begin{equation}\ns_{\\varphi}=\\sqrt{\\left(\\frac{\\partial \\varphi}{\\partial x}\\Biggr|_{\\varphi}\\cdot s_{x}\\right)^2 + \\left(\\frac{\\partial \\varphi}{\\partial y}\\Biggr|_{\\varphi}\\cdot s_{y}\\right)^2}\n\\label{eq:uncertainty_angle}\n\\end{equation}\n\nwith:\n\n\\[\n\\frac{\\partial \\varphi}{\\partial x}\\Biggr|_{\\varphi}=-\\frac{y}{x^2+y^2} \\qquad , \\qquad \\frac{\\partial \\varphi}{\\partial y}\\Biggr|_{\\varphi}=\\frac{x}{x^2+y^2}\n\\]\n\nwhere:\n\\begin{conditions}\n\ts_{\\varphi} & uncertainty of $\\varphi$ \\\\\n\ts_x & uncertainty of x \\\\\n\ts_y & uncertainty of y \\\\\n\tx & distance between the aperture and the projection surface (see figure \\ref{fig:experimental_arrangement}) \\\\\n\ty & position of the maxima or the minima\n\\end{conditions}\n\n\\subsection{Uncertainty of the Width $w$}\n\\label{subsec:Uncertainty_Width}\nTo derive the total uncertainty of the width $w$ the following equations are used. The statistical uncertainty $s_{w,\\ \\text{stat}}$ is obtained from the fits (from QtiPlot).\n\n\\begin{equation}\ns_{w,\\ \\text{tot}}=\\sqrt{s_{w,\\ \\text{syst}}^2+s_{w,\\ \\text{stat}}^2}\n\\label{eq:total_uncertainty_w}\n\\end{equation}\n\nwith:\n\\begin{equation}\ns_{w,\\ \\text{syst}}=\\sqrt{\\left(\\frac{\\partial w}{\\partial \\varphi}\\Biggr|_{w}\\cdot s_{\\varphi}\\right)^2}\n\\label{eq:syst_uncertainty_w}\n\\end{equation}\n\nwhere:\n\\begin{conditions}\n\ts_{w,\\ \\text{tot}} & total uncertainty of $w$ \\\\\n\ts_{w,\\ \\text{syst}} & systematic uncertainty of $w$ \\\\\n\ts_{w,\\ \\text{stat}} & statistical uncertainty of $w$ \\\\\n\ts_{\\varphi} & uncertainty of $\\varphi$\n\\end{conditions}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\\subsubsection{Calculated Uncertainties of the Width $w$ (Slit)}\n\\label{subsubsec:Uncertainty_Width_Slit}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{3}}\nThe systematic uncertainty was calculated by using equation \\ref{eq:slit_maxima} and equation \\ref{eq:syst_uncertainty_w}. The statistical uncertainty was obtained from table \\ref{tab:Slit}. The total uncertainty was calculated by using equation \\ref{eq:total_uncertainty_w}. All calculations were done in MATLAB (see appendix \\ref{sec:MATLAB_Error_Calculation}).\n\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t& \\textbf{Systematic} ($\\mu$m) & \\textbf{Statistical} ($\\mu$m) & \\textbf{Total} ($\\mu$m) \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Slit 40 $\\mu$m} & -0.92 & 0.10 & 0.93 \\\\\n\t\t\\textbf{Slit 100 $\\mu$m} & -6.77 & 0.14 & 6.77 \\\\\n\t\\end{tabular}\n\t\\caption{Calculated Uncertainties for the Width $w$ of the Slit}\n\t\\label{tab:Calculated_Uncertainties_Width_Slit}\n\\end{table}\n\nTo calculate the uncertainty of the 40 $\\mu$m slit and the 100 $\\mu$m slit the 1st order ($m = 1$) was used. It is generally best to use a low order number (greater uncertainty).\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\\subsubsection{Calculated Uncertainties of the Width $w$ (Anti-Slit)}\n\\label{subsubsec:Uncertainty_Width_Anti-Slit}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{3}}\nThe systematic uncertainty was calculated by using equation \\ref{eq:slit_maxima} and equation \\ref{eq:syst_uncertainty_w}. The statistical uncertainty was obtained from table \\ref{tab:Anti-Slit}. The total uncertainty was calculated by using equation \\ref{eq:total_uncertainty_w}. All calculations were done in MATLAB (see appendix \\ref{sec:MATLAB_Error_Calculation}).\n\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t& \\textbf{Systematic} ($\\mu$m) & \\textbf{Statistical} ($\\mu$m) & \\textbf{Total} ($\\mu$m) \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Anti-Slit 230 $\\mu$m} & -23.33 & 0.34 & 23.34 \\\\\n\t\t\\textbf{Anti-Slit 124 $\\mu$m} & -6.80 & 0.08 & 6.80 \\\\\n\t\\end{tabular}\n\t\\caption{Calculated Uncertainties for the Width $w$ of the Anti-Slit}\n\t\\label{tab:Calculated_Uncertainties_Width_Anti-Slit}\n\\end{table}\n\nTo calculate the uncertainty of the 230 $\\mu$m anti-slit the 6th order was used. To calculate the uncertainty of the 124 $\\mu$m anti-slit the 1st order was used.It is generally best to use a low order number (greater uncertainty).\n\n\\newpage\n\n\\subsection{Uncertainty of the Diameter $d$}\n\\label{subsec:Uncertainty_Diameter}\nTo derive the total uncertainty of the diameter $d$ the following equations are used. The statistical uncertainty $s_{d,\\ \\text{stat}}$ is obtained from the fits (from QtiPlot).\n\n\\begin{equation}\ns_{d,\\ \\text{tot}}=\\sqrt{s_{d,\\ \\text{syst}}^2+s_{d,\\ \\text{stat}}^2}\n\\label{eq:total_uncertainty_d}\n\\end{equation}\n\nwith:\n\\begin{equation}\ns_{d,\\ \\text{syst}}=\\sqrt{\\left(\\frac{\\partial d}{\\partial \\varphi}\\Biggr|_{d}\\cdot s_{\\varphi}\\right)^2}\n\\label{eq:syst_uncertainty_d}\n\\end{equation}\n\nwhere:\n\\begin{conditions}\n\ts_{d,\\ \\text{tot}} & total uncertainty of $d$ \\\\\n\ts_{d,\\ \\text{syst}} & systematic uncertainty of $d$ \\\\\n\ts_{d,\\ \\text{stat}} & statistical uncertainty of $d$ \\\\\n\ts_{\\varphi} & uncertainty of $\\varphi$\n\\end{conditions}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\\subsubsection{Calculated Uncertainties of the Diameter $d$ (Circular Aperture)}\n\\label{subsubsec:Uncertainty_Diameter_Circular-Aperture}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{3}}\n\nThe systematic uncertainty was calculated by using equation \\ref{eq:circular_aperture} and equation \\ref{eq:syst_uncertainty_d}. The statistical uncertainty was obtained from table \\ref{tab:Circular_Apertures}. The total uncertainty was calculated by using equation \\ref{eq:total_uncertainty_d}. All calculations were done in MATLAB (see appendix \\ref{sec:MATLAB_Error_Calculation}).\n\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t& \\textbf{Systematic} ($\\mu$m) & \\textbf{Statistical} ($\\mu$m) & \\textbf{Total} ($\\mu$m) \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Circular Aperture 150 $\\mu$m} & -10.21 & 0.83 & 10.24 \\\\\n\t\t\\textbf{Circular Aperture 100 $\\mu$m} & -4.57 & 0.55 & 4.60 \\\\\n\t\\end{tabular}\n\t\\caption{Calculated Uncertainties for the Diameter $d$}\n\t\\label{tab:Calculated_Uncertainties_Diameter}\n\\end{table}\n\nTo calculate the uncertainty of the 150 $\\mu$m circular aperture and the 100 $\\mu$m circular aperture the 2nd Bessel coefficient ($c = 2.233$) was used (see table \\ref{eq:coeffs}). It is generally best to use a low \"order\" number (greater uncertainty).\n\n\\newpage\n\n\\subsection{Uncertainty of the Grid Constant $g$}\n\\label{subsec:Uncertainty_Grid_Constant}\nTo derive the total uncertainty of the grid constant $g$ the following equations are used. The statistical uncertainty $s_{g,\\ \\text{stat}}$ is obtained from the fits (from QtiPlot).\n\n\\begin{equation}\ns_{g,\\ \\text{tot}}=\\sqrt{s_{g,\\ \\text{syst}}^2+s_{g,\\ \\text{stat}}^2}\n\\label{eq:total_uncertainty_g}\n\\end{equation}\n\nwith:\n\\begin{equation}\ns_{g,\\ \\text{syst}}=\\sqrt{\\left(\\frac{\\partial g}{\\partial \\varphi}\\Biggr|_{g}\\cdot s_{\\varphi}\\right)^2}\n\\label{eq:syst_uncertainty_g}\n\\end{equation}\n\nwhere:\n\\begin{conditions}\n\ts_{g,\\ \\text{tot}} & total uncertainty of $g$ \\\\\n\ts_{g,\\ \\text{syst}} & systematic uncertainty of $g$ \\\\\n\ts_{g,\\ \\text{stat}} & statistical uncertainty of $g$ \\\\\n\ts_{\\varphi} & uncertainty of $\\varphi$\n\\end{conditions}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\\subsubsection{Calculated Uncertainties of the Grid Constant $g$ (Cross-Grid)}\n\\label{subsubsec:Uncertainty_Grid_Constant_Cross-Grid}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{3}}\n\nThe systematic uncertainty was calculated by using equation \\ref{eq:cross-grid} and equation \\ref{eq:syst_uncertainty_g}. The statistical uncertainty was obtained from table \\ref{tab:Cross-Grid}. The total uncertainty was calculated by using equation \\ref{eq:total_uncertainty_g}. All calculations were done in MATLAB (see appendix \\ref{sec:MATLAB_Error_Calculation}).\n\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t & \\textbf{Systematic} ($\\mu$m) & \\textbf{Statistical} ($\\mu$m) & \\textbf{Total} ($\\mu$m) \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Cross-Grid 28 $\\mu$m} & -0.36 & 0.44 & 0.57 \\\\\n\t\t\\textbf{Cross-Grid 50 $\\mu$m} & -0.30 & 0.06 & 0.30 \\\\\n\t\\end{tabular}\n\t\\caption{Calculated Uncertainties for the Grid Constant $g$}\n\t\\label{tab:Calculated_Uncertainties_Grid_Constant}\n\\end{table}\n\nTo calculate the uncertainty of the 28 $\\mu$m cross-grid and the 50 $\\mu$m cross-grid the 1st order ($m = 1$) was used. It is generally best to use a low order number (greater uncertainty).\n", "meta": {"hexsha": "913c27ea5c8af260c98302f7fb9d099c174ef83a", "size": 9210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/error_calculation.tex", "max_stars_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_stars_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/error_calculation.tex", "max_issues_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_issues_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/error_calculation.tex", "max_forks_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_forks_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_forks_repo_licenses": ["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.219895288, "max_line_length": 383, "alphanum_fraction": 0.7327904452, "num_tokens": 2919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.6286773507624984}}
{"text": "% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí\n\\setcounter{chapter}{2}\n\\chapter{Circuits in Series and Parallel}\n%\nIn this experiment you will learn about circuits connected in series or in parallel.\n%\n\\section{Preliminary}\n%\nA \\textbf{resistor} is any component in an electric circuit with \\textbf{electrical resistance}. The SI unit for resistance is the ohm:\n\\begin{equation}\n\t1 \\ \\text{ohm} = 1 \\ \\text{V/A}\n\\end{equation}\nOhm's law is a statement that relates the voltage $V$ across a resistor to the amount of current $I$ leaving (or equivalently, entering) a resistor:\n\\begin{equation}\n\tV = R I\n\\end{equation}\nHere, $R$ is the amount of electrical resistance. Solving for $R$ gives\n\\begin{equation} \\label{eq.03.ROhmLaw}\n\tR = \\frac{V}{I}\n\\end{equation}\nFor \\textbf{ohmic resistors}, the ratio of voltage and current is fixed (i.e. constant) and \\textbf{always} gives the same value. This is \\textbf{not true} for \\textbf{non-ohmic resistors}.\n\nAn electric circuit can contain many components that are connected with wires. The electric properties of the circuit will depend on \\textbf{how} these components are connected. You are going to look at two ways of connecting two components in a circuit to a battery: \\textbf{series} and \\textbf{parallel}.\n%\n\\subsection{Circuits in Series}\n%\nA collection of two resistors in \\textbf{series} can be replaced by an \\textbf{equivalent resistor} with a resistance given by the sum of the individual resistances:\n\\begin{equation} \\label{eq.03.RSeries}\n\tR_{\\text{eq}} = R_{1} + R_{2}\n\\end{equation}\nWhen two resistors are connected in \\textbf{series} to a battery, the \\textbf{current} $I_{0}$ leaving the battery is the \\textbf{same} as the \\textbf{current} $I_{1}$ leaving resistor 1, and also the same as the \\textbf{current} $I_{2}$ leaving resistor 2:\n\\begin{equation} \\label{eq.03.ISeries}\n\tI_{0} = I_{1} = I_{2}\n\\end{equation}\nWhen two resistors are connected in \\textbf{series} to a battery, the \\textbf{voltage} $V_{0}$ across the battery is \\textbf{split} between the \\textbf{voltage} $V_{1}$ across resistor 1, and the \\textbf{voltage} $V_{2}$ across resistor 2:\n\\begin{equation} \\label{eq.03.VSeries}\n\tV_{0} = \\left| V_{1} + V_{2} \\right|\n\\end{equation}\nThe absolute value is needed because the voltage across each resistor is \\textbf{negative} since it correspond to an \\textbf{electric potential drop}.\n%\n\\subsection{Circuits in Parallel}\n%\nA collection of two resistors in \\textbf{parallel} can be replaced by an \\textbf{equivalent resistor} with a resistance that satisfies the relation\n\\begin{equation}\n\t\\frac{1}{R_{\\text{eq}}} = \\frac{1}{R_{1}} + \\frac{1}{R_{2}}\n\\end{equation}\nSolving for the equivalent resistance gives\n\\begin{equation} \\label{eq.03.RParallel}\n\tR_{\\text{eq}} = \\frac{R_{1} R_{2}}{R_{1} + R_{2}}\n\\end{equation}\nWhen two resistors are connected in \\textbf{parallel} to a battery, the \\textbf{current} $I_{0}$ leaving the battery is split between the \\textbf{current} $I_{1}$ leaving resistor 1, and the \\textbf{current} $I_{2}$ leaving resistor 2:\n\\begin{equation} \\label{eq.03.IParallel}\n\tI_{0} = I_{1} + I_{2}\n\\end{equation}\nWhen two resistors are connected in \\textbf{parallel} to a battery, the \\textbf{voltage} $V_{0}$ across the battery has the same magnitude as the \\textbf{voltage} $V_{1}$ across resistor 1, and also the same magnitude as the \\textbf{voltage} $V_{2}$ across resistor 2:\n\\begin{equation} \\label{eq.03.VParallel}\n\tV_{0} = \\left| V_{1} \\right| = \\left| V_{2} \\right|\n\\end{equation}\nAgain, remember that the voltage across a resistor (measured in the direction along the current) is negative because it correspond to a drop in electric potential.\n%\n\\subsection{Power}\n%\nThe power $P$ input or output of a component in an electric circuit can be found by multiplying the voltage $V$ across that component, and the amount of current $I$ leaving that component:\n\\begin{equation}\n\tP = VI\n\\end{equation}\nThe SI unit for power is the \\textbf{watt} (W). One watt is equivalent to one joule of energy consumed or generated per second:\n\\begin{equation}\n\t1 \\ \\text{W} = 1 \\ \\text{J/s}\n\\end{equation}\nSince power equals voltage multiplied by current, you also have\n\\begin{equation}\n\t1 \\ \\text{W} = 1 \\ \\text{V {\\textperiodcentered} A}\n\\end{equation}\n%\n\\section{Experiment}\n%\nThere are four experiments. The first two experiments involve using \\textbf{two ohmic} resistors. The other two experiments use \\textbf{two non-ohmic} resistors (light bulbs).\n%\n\\subsection{Part 1: Resistors in Series}\n%\nIn this part, you connect two \\textbf{resistors} in \\textbf{series} to a battery.\n%\n\\subsection{Part 2: Resistors in Parallel}\n%\nIn this part, you connect two \\textbf{resistors} in \\textbf{parallel} to a battery.\n%\n\\subsection{Part 3: Light Bulbs in Series}\n%\nIn this part, you connect two \\textbf{light bulbs} in \\textbf{series} to a battery.\n%\n\\subsection{Part 4: Light Bulbs in Parallel}\n%\nIn this part, you connect two \\textbf{light bulbs} in \\textbf{parallel} to a battery.\n%\n\\section{Analysis}\n%\nEach run is a measurement of either \\textbf{voltage} (electric potential difference between two points) or \\textbf{current}. If the voltage and current sensors were zeroed correctly, then the measurement over time should correspond to the measurement of the desired quantity, and no offset or baseline needs to be taken into account. One way to determine a single value is to take the \\textbf{time-average}.\n\nNote that each \\textbf{voltage measurement has three decimal figures}, and each \\textbf{current measurement has four decimal figures}. You should round your time-averaged values appropriately.\n\nIn each part there are three components: one battery and two resistors (or two light bulbs). There are \\textbf{six quantities} that describe the system:\n\\begin{itemize}\n\t\\item Time-averaged voltage across the battery: $V_{0}$\n\t\\item Time-averaged voltage across resistor/bulb 1: $V_{1}$\n\t\\item Time-averaged voltage across resistor/bulb 2: $V_{2}$\n\t\\item Time-averaged current leaving the battery: $I_{0}$\n\t\\item Time-averaged current leaving resistor/bulb 1: $I_{1}$\n\t\\item Time-averaged current leaving resistor/bulb 2: $I_{2}$\n\\end{itemize}\nThese six quantities satisfy certain mathematical relations. Note that $V_{1}$ and $V_{2}$ are measured to be negative.\n%\n\\subsection{Part 1: Two Resistors in Series}\n%\nFor the two \\textbf{resistors in series}, you find the time average for all six quantities above and fill a table similar to Table \\ref{table.03.resistors.series}.\n\nYou should check that relations Equation (\\ref{eq.03.ISeries}) and Equation (\\ref{eq.03.VSeries}) hold true. The percent difference between the labeled resistance and the prediction Equation (\\ref{eq.03.ROhmLaw}) from Ohm's law should be very small. The resistance of the battery should be very close to the \\textbf{series equivalent} resistance in Equation (\\ref{eq.03.RSeries}).\n%\n\\subsection{Part 2: Two Resistors in Parallel}\n%\nFor the two \\textbf{resistors in parallel}, you find the time average for all six quantities above and fill a table similar to Table \\ref{table.03.resistors.parallel}.\n\nYou should check that relations Equation (\\ref{eq.03.IParallel}) and Equation (\\ref{eq.03.VParallel}) hold true. The percent difference between the labeled resistance and the prediction Equation (\\ref{eq.03.ROhmLaw}) from Ohm's law should be very small. The resistance of the battery should be very close to the \\textbf{parallel equivalent} resistance in Equation (\\ref{eq.03.RParallel}).\n%\n\\subsection{Part 3: Two Light Bulbs in Series}\n%\nFor two \\textbf{light bulbs in series}, you can find the time average for all six quantities mentioned above, and fill a table similar to Table \\ref{table.03.bulbs.series}. Note that the fourth column consist of the ratio of voltage and current for each component. This is a quantity with units of resistance (ohms) but it does not correspond to the actual resistance of the light bulbs. As you will find, the light bulbs are not ohmic, and thus the ratio of the voltage across the light bulb and the current leaving the light bulb is not constant. However, you should find that the relations Equation (\\ref{eq.03.ISeries}) and Equation (\\ref{eq.03.VSeries}) again hold.\n%\n\\subsection{Part 4: Two Light Bulbs in Parallel}\n%\nFor two \\textbf{light bulbs in parallel}, you can find the time average for all six quantities mentioned above, and table similar to Table \\ref{table.03.bulbs.parallel}. Note that the fourth column consist of the ratio of voltage and current for each component. You can verify that the light bulbs are not ohmic by showing that the values in the fourth column in Tables \\ref{table.03.bulbs.series} and \\ref{table.03.bulbs.parallel} are very different. However, you should find that the relations Equation (\\ref{eq.03.IParallel}) and Equation (\\ref{eq.03.VParallel}) again hold.\n%\n\\section{My Data}\n%\nFor parts 1 and 2, I used \\textbf{three} resistors, instead of two. The resistances are given by\n\\begin{align}\n\tR_{1} = 10 \\text{ ohm} && R_{2} = 51 \\text{ ohm} && R_{3} = 68 \\text{ ohm}\n\\end{align}\nThe equivalent resistance in \\textbf{series} with three resistors is given by\n\\begin{equation}\n\tR_{\\text{eq}} = R_{1} + R_{2} + R_{3}\n\\end{equation}\nIn parallel, the equivalent resistant satisfies the following relation:\n\\begin{equation}\n\t\\frac{1}{R_{\\text{eq}}} = \\frac{1}{R_{1}} + \\frac{1}{R_{2}} + \\frac{1}{R_{3}}\n\\end{equation}\nSolving for the equivalent resistance in \\textbf{parallel} gives\n\\begin{equation}\n\tR_{\\text{eq}} = \\frac{R_{1} R_{2} R_{3}}{R_{1} R_{2} + R_{1} R_{3} + R_{2} R_{3}}\n\\end{equation}\nAs you can see from my spreadsheet, the results are in good agreement with expectations.\n%\n\\subsection{Part 1: Three Resistors in Series}\n%\nTable \\ref{table.03.3resistors.series} has the results for three resistors in series. You can check that the values for the current in the third column are all very close. Indeed,\n\\begin{equation}\n\tI_{0} \\approx I_{1} \\approx I_{2} \\approx I_{3}\n\\end{equation}\nThis is the three-resistor analog of Equation (\\ref{eq.03.ISeries}). Also, you can check that\n\\begin{equation}\n\t| V_{1} + V_{2} + V_{3} | = 3.075 \\text{ V}\n\\end{equation}\nwhich is very close to the value of $V_{0}$ (the voltage across the battery). This is the three-resistor analog of Equation (\\ref{eq.03.VSeries}).\n\nThe last column in Table \\ref{table.03.3resistors.series} contains the power generated/consumed by the corresponding component. As you can see, the rate of energy generation for the battery is very close to the sum of the rate of consumption for each resistor. Note that, in \\textbf{series}, the resistor with the \\textbf{largest} resistance consumes the most energy.\n%\n\\subsection{Part 2: Three Resistors in Parallel}\n%\nTable \\ref{table.03.3resistors.parallel} has the results for three resistors in parallel. You can check that, ignoring the signs, the values for the voltage in the second column are all very close. Indeed,\n\\begin{equation}\n\tV_{0} \\approx |V_{1}| \\approx |V_{2}| \\approx |V_{3}|\n\\end{equation}\nThis is the three-resistor analog of (\\ref{eq.03.VParallel}). Also, you can check that\n\\begin{equation}\n\tI_{1} + I_{2} + I_{3}  = 0.3532 \\text{ A}\n\\end{equation}\nwhich is very close to the value of $I_{0}$ (the current leaving the battery). This is the three-resistor analog of Equation (\\ref{eq.03.IParallel}).\n\nThe last column in Table \\ref{table.03.3resistors.parallel} contains the power generated/consumed by the corresponding component. As you can see, the rate of energy generation for the battery is very close to the sum of the rate of consumption for each resistor. Note that, in \\textbf{parallel}, the resistor with the \\textbf{smallest} resistance consumes the most energy.\n\nOne last thing about resistors: proof that they \\textbf{are ohmic} (at least for the amount of voltage and current that we used) is that the values in the fourth column in Tables \\ref{table.03.3resistors.series} and \\ref{table.03.3resistors.parallel} are consistent (except for the first value, because it corresponds to the equivalent resistance). That is, it does not matter if they are connected in series or parallel, the amount of current going through the resistor is proportional to the amount of voltage across the resistor.\n%\n\\subsection{Part 3: Two Light Bulbs in Series}\n%\nThe six runs in the text file \\texttt{bulbs-serial.txt} are for two light bulbs connected in series.\n\\begin{itemize}\n\t\\item Run 1: measurement of voltage across battery ($V_{0}$).\n\t\\item Run 2: measurement of voltage across long light bulb ($V_{L}$).\n\t\\item Run 3: measurement of voltage across round light bulb ($V_{R}$).\n\t\\item Run 4: measurement of current leaving battery ($I_{0}$).\n\t\\item Run 5: measurement of current leaving long light bulb ($I_{L}$).\n\t\\item Run 6: measurement of current leaving round light bulb ($I_{R}$).\n\\end{itemize}\nThe \\textbf{long} light bulb is connected \\textbf{first}, and the \\textbf{round} light bulb is connected \\textbf{second}.\n%\n\\subsection{Part 4: Two Light Bulbs in Parallel}\n%\nThe six runs in the text file \\texttt{bulbs-parallel.txt} are for two light bulbs connected in parallel.\n\\begin{itemize}\n\t\\item Run 1: measurement of voltage across battery ($V_{0}$).\n\t\\item Run 2: measurement of voltage across long light bulb ($V_{L}$).\n\t\\item Run 3: measurement of voltage across round light bulb ($V_{R}$).\n\t\\item Run 4: measurement of current leaving battery ($I_{0}$).\n\t\\item Run 5: measurement of current leaving long light bulb ($I_{L}$).\n\t\\item Run 6: measurement of current leaving round light bulb ($I_{R}$).\n\\end{itemize}\n%\n\\section{Your Data}\n%\nIf your data for resistors in series and/or parallel is not good, let me know via email and I will make data available to you.\n%\n% \\newpage\n% \\section{Your Lab Report}\n% %\n% In your lab report you should include:\n% \\begin{enumerate}\n% \t\\item One table like Table \\ref{table.03.resistors.series} for two resistors in series.\n% \t\\item One table like Table \\ref{table.03.resistors.parallel} for two resistors in parallel.\n% \t\\item One table like Table \\ref{table.03.bulbs.series} for two light bulbs in series.\n% \t\\item One table like Table \\ref{table.03.bulbs.parallel} for two light bulbs in parallel.\n% \\end{enumerate}\n% You should also:\n% \\begin{enumerate}\n% \t\\item Verify that equations (\\ref{eq.03.ISeries}) and (\\ref{eq.03.VSeries}) hold for two resistors, and also for two light bulbs, connected in series.\n% \t\\item Verify that the voltage across the battery divided by the current leaving the battery is close to (\\ref{eq.03.RSeries}) for two resistors in series.\n% \t\\item Verify that equations (\\ref{eq.03.IParallel}) and (\\ref{eq.03.VParallel}) hold for two resistors, and also for two light bulbs, connected in parallel.\n% \t\\item Verify that the voltage across the battery divided by the current leaving the battery is close to (\\ref{eq.03.RParallel}) for two resistors in parallel.\n% \t\\item Confirm that the long light bulb is non-ohmic by comparing the ratio of the voltage and the current $V_{1} / I_{1}$ in series and in parallel.\n% \t\\item Confirm that the round light bulb is non-ohmic by comparing the ratio of the voltage and the current $V_{2} / I_{2}$ in series and in parallel.\n% \t\\item Find which resistor consumes more power when two resistors are connected in series.\n% \t\\item Find which resistor consumes more power when two resistors are connected in parallel.\n% \t\\item Find which light bulb consumes more power when two light bulbs are connected in series.\n% \t\\item Find which light bulb consumes more power when two light bulbs are connected in parallel.\n% \\end{enumerate}\n%\n\\newpage\n\\section{Tables}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r}\n            \\textbf{Quantity} & \\textbf{Battery} & \\textbf{Resistor 1} & \\textbf{Resistor 2} \\\\\n            \\hline\n            Voltage (V) & $V_{0}$ & $V_{1}$ & $V_{2}$ \\\\\n            Current (A) & $I_{0}$ & $I_{1}$ & $I_{2}$ \\\\\n            \\hline\n            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{1} / I_{1}$ & $V_{2} / I_{2}$ \\\\\n            Expected Resistance (ohm) & $R_{1} + R_{2}$ & $R_{1}$ & $R_{2}$ \\\\\n            Percent Difference (\\%) & & & \\\\\n            \\hline\n            Power (W) & $V_{0} I_{0}$ & $V_{1} I_{1}$ & $V_{2} I_{2}$ \\\\\n            \\hline\n        \\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and resistance for two resistors in series.}\n\t\\label{table.03.resistors.series}\n\\end{table}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r}\n            \\textbf{Quantity} & \\textbf{Battery} & \\textbf{Resistor 1} & \\textbf{Resistor 2} \\\\\n            \\hline\n            Voltage (V) & $V_{0}$ & $V_{1}$ & $V_{2}$ \\\\\n            Current (A) & $I_{0}$ & $I_{1}$ & $I_{2}$ \\\\\n            \\hline\n            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{1} / I_{1}$ & $V_{2} / I_{2}$ \\\\\n            Expected Resistance (ohm) & $R_{1} R_{2} / (R_{1} + R_{2})$ & $R_{1}$ & $R_{2}$ \\\\\n            Percent Difference (\\%) & & & \\\\\n            \\hline\n            Power (W) & $V_{0} I_{0}$ & $V_{1} I_{1}$ & $V_{2} I_{2}$ \\\\\n            \\hline\n        \\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and resistance for two resistors in parallel.}\n\t\\label{table.03.resistors.parallel}\n\\end{table}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r}\n            \\textbf{Quantity} & \\textbf{Battery} & \\textbf{Long bulb} & \\textbf{Round bulb} \\\\\n            \\hline\n            Voltage (V) & $V_{0}$ & $V_{L}$ & $V_{R}$ \\\\\n            Current (A) & $I_{0}$ & $I_{L}$ & $I_{R}$ \\\\\n            \\hline\n            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{L} / I_{L}$ & $V_{R} / I_{R}$ \\\\\n            Power (W) & $V_{0} I_{0}$ & $V_{L} I_{L}$ & $V_{R} I_{R}$ \\\\\n            \\hline\n        \\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and power for two light bulbs in series.}\n\t\\label{table.03.bulbs.series}\n\\end{table}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r}\n            \\textbf{Quantity} & \\textbf{Battery} & \\textbf{Long bulb} & \\textbf{Round bulb} \\\\\n            \\hline\n            Voltage (V) & $V_{0}$ & $V_{L}$ & $V_{R}$ \\\\\n            Current (A) & $I_{0}$ & $I_{L}$ & $I_{R}$ \\\\\n            \\hline\n            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{L} / I_{L}$ & $V_{R} / I_{R}$ \\\\\n            Power (W) & $V_{0} I_{0}$ & $V_{L} I_{L}$ & $V_{R} I_{R}$ \\\\\n            \\hline\n        \\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and power for two light bulbs in parallel.}\n\t\\label{table.03.bulbs.parallel}\n\\end{table}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r|r}\n\t\t\t\\textbf{Quantity} & \\textbf{Battery} & \\textbf{Resistor 1} & \\textbf{Resistor 2} & \\textbf{Resistor 3} \\\\\n\t\t\t\\hline\n\t\t\tVoltage (V) & 4.430 & \\textminus 0.338 & \\textminus 1.757 & \\textminus 2.345 \\\\\n\t\t\tCurrent (A) & 0.0346 & 0.0346 & 0.0347 & 0.0347 \\\\\n\t\t\t\\hline\n\t\t\tObserved Resistance (ohm) & 128.05 & 9.76 & 50.70 & 67.68 \\\\\n\t\t\tExpected Resistance (ohm) & 129 & 10 & 51 & 68 \\\\\n\t\t\tPercent Difference (\\%) & \\textminus 0.73 & \\textminus 2.36 & \\textminus 0.58 & \\textminus 0.46 \\\\\n\t\t\t\\hline\n\t\t\tPower (W) & 0.15 & \\textminus 0.01 & \\textminus 0.06 & \\textminus 0.08 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and resistance for three resistors in series.}\n\t\\label{table.03.3resistors.series}\n\\end{table}\n%\n\\begin{table}[ht]\n\t\\begin{center}\n\t\t\\begin{tabular}{l|r|r|r|r}\n\t\t\t\\textbf{Quantity} & \\textbf{Battery} & \\textbf{Resistor 1} & \\textbf{Resistor 2} & \\textbf{Resistor 3} \\\\\n\t\t\t\\hline\n\t\t\tVoltage (V) & 3.731 & \\textminus 3.707 & \\textminus 3.736 & \\textminus 3.734 \\\\\n\t\t\tCurrent (A) & 0.4904 & 0.3722 & 0.0739 & 0.0554 \\\\\n\t\t\t\\hline\n\t\t\tObserved Resistance (ohm) & 7.61 & 9.96 & 50.55 & 67.37 \\\\\n\t\t\tExpected Resistance (ohm) & 7.45 & 10 & 51 & 68 \\\\\n\t\t\tPercent Difference (\\%) & 2.20 & \\textminus 0.39 & \\textminus 0.88 & \\textminus 0.92 \\\\\n\t\t\t\\hline\n\t\t\tPower (W) & 1.83 & \\textminus 1.38 & \\textminus 0.28 & \\textminus 0.21 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Time-averages and resistance for three resistors in parallel.}\n\t\\label{table.03.3resistors.parallel}\n\\end{table}\n%\n\\FloatBarrier\n\\newpage\n\\section{Figures}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/03-serial-parallel/resistor-V.pdf}\n\t\\caption{Voltage across ohmic resistor}\n\t\\label{figure.03.resistor.v}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/03-serial-parallel/resistor-I.pdf}\n\t\\caption{Current through ohmic resistor}\n\t\\label{figure.03.resistor.i}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/03-serial-parallel/bulb-V.pdf}\n\t\\caption{Voltage across non-ohmic light bulb}\n\t\\label{figure.03.bulb.v}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/03-serial-parallel/bulb-I.pdf}\n\t\\caption{Current through non-ohmic light bulb}\n\t\\label{figure.03.bulb.i}\n\\end{figure}", "meta": {"hexsha": "498f7d13065ee293c8a78343062c88b603e294bf", "size": 20846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/03-serial-parallel.tex", "max_stars_repo_name": "meirizarrygelpi/phys-208L", "max_stars_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_stars_repo_licenses": ["MIT"], "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/03-serial-parallel.tex", "max_issues_repo_name": "meirizarrygelpi/phys-208L", "max_issues_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_issues_repo_licenses": ["MIT"], "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/03-serial-parallel.tex", "max_forks_repo_name": "meirizarrygelpi/phys-208L", "max_forks_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_forks_repo_licenses": ["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.4281984334, "max_line_length": 670, "alphanum_fraction": 0.7037321309, "num_tokens": 6412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624890918021, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6286140081610642}}
{"text": "\\subsection{Theoretical Results}\n\n\\hogwild's original article \\cite{2011NRRW} manages to prove that the\nasynchronous noise generated by \\hogwild, under certain sparsity assumptions of\nthe $f_i$'s, converged at the same rate as seen in the stochastic gradient\nmethod. However, a newer article from 2015 by De Sa et al. \\cite{2015SZOR}\npresented a new framework in the context of martingale theory, which drops said\nsparsity assumptions and generalizes to certain non-convex formualations. Given\nthat I just learned about martingale theory essentially two weeks ago in Basic\nProbability, and that much of my synthetic tests are on dense datasets, I feel\ncompelled to present this argument instead. \n\nThe following is a cleaned up summary of the arguments presented in the article,\nexcept I focus on just demonstrating how martingale theory can be used to\ngeneralize convergence arguments for a sequential stochastic gradient method to\nthe asynchronous case, and cut out the generalization required for the\nnon-convex situation.\n\n\\subsubsection{Initial Machinery}\n\nFirst, recall the definition of a martingale:\n\\begin{definition} \\label{def:martingale}\n  \\cite{2004JP} A sequence of random variables $(X_n)_{n \\geq 0}$ is called\n  a martingale, or an $(\\mathcal{F}_n)$-martingale, if\n  \\begin{enumerate}[(i)]\n    \\item $\\E{|X_n|} < \\infty, \\forall n$.\n    \\item $X_n$ is $\\mathcal{F}_n$ measurable, $\\forall n$.\n    \\item $\\E{X_n \\mid \\mathcal{F}_m} = X_m$ a.s., $\\forall m \\leq n$.\n  \\end{enumerate}\n  furthermore a supermartingale (submartingale) is one satisfying (i), (ii)\n  exactly, and (iii) with $\\leq\\ (\\geq)$ instead.\n\\end{definition}\nUsing this, the idea is to model our convergence with a non-negative\nsupermartingale $W_t(x_t, \\dots, x_0)$ which is a function of the previous\nstochastic gradient iterates. These $W_t$, when used in the theory later, will\nbe associated with specific stochastic algorithms, as an example below we'll see\nit applied to serial stochastic gradient. However, given such a supermartingale,\nand given a bounded stopping time $B$ (in literature known as a horizon), if our\nstochastic gradient iterates are written as $x_{t+1} = x_t - \\eta \\nabla\nf_t(x_t)$, where $\\eta$ is the learning rate, and $f_t$ denotes the random\nfunction chosen at time step $t$, then we see that condition (iii) in the above\ndefinition implies that:\n\\[\n  W_{t+1}(x_t - \\eta \\nabla f_t(x_t), x_t, \\dots, x_0)\n  \\leq\n  W_t(x_t, \\dots, x_0), \\forall t \\leq B\n\\]\nwhich certainly makes sense if our $-\\nabla f_t(x_t)$ is a sufficient search\ndirection. Furthermore, letting our success region be denoted as $S\n= B_\\e(x^*)$, where $x^*$ is the minimizer of our optimization problem, if we\nimpose that if $x_t \\not\\in S, \\forall t \\leq T$ then:\n\\[\n  W_T(x_T, \\dots, x_0) \\geq T\n\\]\nthen we call $W_t$ a {\\it rate supermartingale}. To simplify notation, let $F_t$\nbe the event where $\\nexists t \\leq T$ such that $x_t \\in S$. \n\nA good example of the power of this machinery is proving a convergence bound on\nthe serial version of stochastic gradient: using (iii) of definition\n\\ref{def:martingale}, one can see that considering $F_T$:\n\\[\n  \\E{W_0(x_0)}\n  \\underbrace{\\geq}\n  \\E{W_T}\n  =\n  \\Prob{F_t}\n  \\underbrace{\\Prob{F_T}\\E{W_T | F_T}}_{W_T \\geq T} + \n  \\underbrace{\\Prob{F_T^c}\\E{W_T | F_T^c}}_{W_T \\geq 0}\n  \\geq\n  \\Prob{F_T}T\n\\]\nwhere the first inequality is by Doob's optional sampling theorem. Thus for\na simple serial stochastic gradient method: $\\Prob{F_t} = \\E{W_0} / T$.\n\nNow that we can characterize serial stochastic gradient in this model, we need\na method to analyze asynchronous noise. Recall that since we've guaranteed in\nthe description of \\hogwild\\ that writes to the iteration variable $x_t$ are\ndone atomically, the only race condition possible is when updates to entries of\n$x_t$ are interleaved with either the other thread's updates or its reads on\n$x_t$.\n\nIndeed, when going to update the $i$th component of $x_{t+1}$, the variable used\nto compute the gradient may have long since changed, making our iteration look\nmore like $x_{t+1} = x_t - \\nabla f_t(v_t)$ where $v_t$'s entries were the\nentries of some previous iterate $x$. Let $\\tau_{i,t}$ denote the lag for the\nupdate of the $i$th component of $x_{t+1}$, i.e. $(v_t)_i = ( x_{t-\\tau_{i,t}}\n)_i$. Then we recognize that this lag for each component $i$ (supposing the\ncomputer hasn't crashed) must be bounded; let $\\tau'$ be the the maximum over\n$i$ of such bounds and let $\\tau = \\E{\\tau'}$. This is known in literature as\nthe {\\it worst-case expected delay}.\n\nFinally, we need one last definition, mainly one of convinience, to proceed\nonward. This describes the main conditions upon a rate supermartingale necessary\nto prove that the asynchronous noise error is irrelevant to the convergence\nrate.\n\\begin{definition}\n  An algorithm with associated rate supermartingale $W$ is $(H, R, \\xi)$-bounded\n  if the following conditions hold.\n  \\begin{enumerate}[(1)]\n    \\item $W$ must be Lipschitz continuous in the current iterate with parameter\n      $H$, i.e.\n      \\[\n        \\norm{W_t(u, x_{t-1}, \\dots, x_0) - W_t(v, x_{t-1}, \\dots, x_0)}\n        \\leq\n        H\\norm{u-v}, \\forall t, u, v, x_t, \\dots, x_0.\n      \\]\n    \\item $\\nabla f$ must be Lipschitz continuous in expectation with parameter\n      $R$, i.e.\n      \\[\n        \\E{||\\nabla f(x) - \\nabla f(y)||} \\leq R\\norm{u-v}\n      \\]\n    \\item The expected magnitude of the update must be bounded by $\\xi$, i.e.\n      \\[\n        \\E{||\\nabla f(x)||} \\leq \\xi\n      \\]\n  \\end{enumerate}\n  Note that these look very familiar to the conditions in the stochastic\n  gradient method convergence theorem (theorem \\ref{thm:sgd}).\n\\end{definition}\n\n\\subsubsection{Convergence of \\hogwild}\n\nFinally, now that all of the machinery has been defined, we can get to the main\nresult:\n\\begin{theorem} \\label{thm:convergence}\n  Suppose we have an asynchronous stochastic algorithm with associated rate\n  supermartingale $W$ which is $(H,R,\\xi)$ bounded with horizon $B$.\n  Furthermore, assume that $HR\\xi \\tau < 1$; then $\\forall T \\leq B$:\n  \\[\n    \\Prob{F_T} \\leq \\frac{\\E{W(0, x_0)}}{(1-HR\\xi\\tau)T}\n  \\]\n\\end{theorem}\nBefore we prove it, we briefly discuss how to use this theorem in practice.\nSuppose we have a loss function $f$ which we want to use \\hogwild\\ on to\nminimize. Then first we need to obtain a rate supermartingale proving the\nproblem%\n\\footnote{\n  In the article, De Sa et al. describes this as being no more difficult than\n  proving serial convergence, but the proof (in the convex case) doesn't seem to\n  have any similarity between it and serial convergence, so I can't validate\n  this claim.\n}, determine $H, R, \\xi$ such that $W$ is $(H,R,\\xi)$-bounded, and then apply\nthis theorem to get a proper rate of convergence. This is a very powerful\ntheorem, as we'll be able to state later, given strongly convex $f$ and with the\nother required bounds, we can blanket prove that \\hogwild\\ works on them.\nFurthermore, for nicer non-convex problems, such as the low-rank least-squared\nmatrix completion problem presented in the paper, it's easy to derive a proper\nrate supermartingale as well.\n\nNow, with respect to the proof, we only outline it because it's mainly just\na repeated application of the above bounds we have in order to lower bound away\nnoise terms, and then it follows the path outlined in the serial stochastic\ngradient method proof.\n\\begin{proof}\n  \\begin{enumerate}[(i)]\n    \\item With $W$ defined exactly as in the serial case, it's not a rate\n      supermartingale. Instead, from it we construct rate supermartingale $V_t$,\n      where $\\forall t, x$ where $x_u$ not converged $\\forall u < t$:\n      \\[\n        V_t(x_t, \\dots, x_0) = W_t(x_t, \\dots, x_0) \n        - \\underbrace{HR\\xi \\tau t}_{(1)}\n        + \\underbrace{\n          HR \\sum_{k=1}^\\infty \\norm{x_{t-k+1}-x_{t-k}} \\sum_{m=k}^\\infty\n          \\Prob{\\tau' \\geq m}\n        }_{(2)}\n      \\]\n      where (1) allows for longer iteration counts (as HOGWILD needs to allow\n      for given noise corruption), and (2) measures distance between recent\n      iterates. Otherwise if $x_u$ is converged, then we let $V_t(x_t, \\dots,\n      x_0) = V_u(x_u, \\dots, x_0)$. Basically, we've defined $V$ a stopped\n      process.\n    \\item Show $V_t$ is a rate supermartingale for \\hogwild\n    \\item Using a similar process to the serial stochastic gradient proof, show\n      that $\\E{V_T} \\leq \\E{V_0} = \\E{W_0}$, then using the law of total\n      expectation on this with $F_T$, and recalling that $\\E{W_T | F_T} \\geq T$,\n      we recieve the desired result.\n  \\end{enumerate}\n\\end{proof}\nGiven this, the general theorem for the convex case is:\n\\begin{theorem} \\label{thm:convexconv}\n  Consider trying to minimize $f$, which is:\n  \\begin{itemize}\n    \\item Strongly convex with parameter $c$.\n    \\item $\\nabla f_k$ Continuously differentiable in $||\\cdot||_1$ with\n      Lipschitz constant $L$.\n    \\item Upper bounded second moment of the gradient by $M^2$\n    \\item Success criteria $\\norm{x-x^*}^2 \\leq \\e$, for some $\\e > 0$.\n  \\end{itemize}\n  Then we can construct rate supermartingale $W_t$ such that it's $(H,R,\\xi)$\n  bounded with $H = 2\\sqrt{\\e}(2\\eta c\\e - \\eta^2 M^2)^{-1}, R = \\eta L,\n  \\xi = \\eta M$. Then choosing step size $\\eta$ (for some $\\nu \\in (0,1)$):\n  \\[\n    \\eta = \\frac{c\\e \\nu}{M^2 + 2LM\\tau\\sqrt{\\e}}\n  \\]\n  then we recieve:\n  \\[\n    \\Prob{F_T} \\leq \\frac{M^2 + 2LM\\tau\\sqrt{\\e}}{c^2\\e\\nu T} \\log\n    \\left(\n      e \\norm{x_0 -x^*}^2 \\e^{-1}\n    \\right)\n  \\]\n\\end{theorem}\n", "meta": {"hexsha": "39483b6eb998cc37bbd7d823ca700e986536932e", "size": 9503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TeXsrc/src/convergence/theory.tex", "max_stars_repo_name": "abhijit-c/HOGWILD", "max_stars_repo_head_hexsha": "1ae85888fb5c33f0cf01043064d30106e7a3de39", "max_stars_repo_licenses": ["MIT"], "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/TeXsrc/src/convergence/theory.tex", "max_issues_repo_name": "abhijit-c/HOGWILD", "max_issues_repo_head_hexsha": "1ae85888fb5c33f0cf01043064d30106e7a3de39", "max_issues_repo_licenses": ["MIT"], "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/TeXsrc/src/convergence/theory.tex", "max_forks_repo_name": "abhijit-c/HOGWILD", "max_forks_repo_head_hexsha": "1ae85888fb5c33f0cf01043064d30106e7a3de39", "max_forks_repo_licenses": ["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.8128078818, "max_line_length": 80, "alphanum_fraction": 0.7013574661, "num_tokens": 2884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6286139985583695}}
{"text": "\\chapter{Calculation Objects} \\label{Ch:CalculationObjects}\r\n\r\nGMAT has the ability to calculate numerous quantities that are\r\ndependent upon the states of objects, coordinate systems, and the\r\nmission sequence.   These calculation objects can range from the\r\nspacecraft state, to the local atmospheric density, to the\r\npositions of celestial bodies with respect to spacecraft, or other\r\ncelestial bodies.  In chapter, we present how GMAT performs these\r\ncalculations by showing the mathematical algorithms.\r\n\r\nThe chapter begins by discussing different orbit state\r\nrepresentations.  Each of the orbit state representations\r\navailable in GMAT are defined.  Next we present the algorithms\r\nused to convert between different state representations.  These\r\ninclude the Keplerian elements, modified Keplerian elements,\r\nCartesian state, spherical state, and the equinoctial elements. In\r\nthe second section we present how GMAT calculates all calculation\r\nparameters. Examples include the orbit period, percent shadow, and\r\nenergy. The algorithms to calculate all parameters are included\r\nand described in detail. We conclude this chapter with a\r\npresentation of the algorithms used to calculate libration point\r\nand barycenter locations.\r\n\r\n\\section{Spacecraft State Representations} \\index{Orbit state\r\nrepresentations}\r\n\r\nThere are several state representations that can be used in GMAT\r\nto define the state of a spacecraft object.  These include the\r\nKeplerian elements, Cartesian state, equinoctial elements,\r\nspherical elements, and the modified Keplerian elements.  In the\r\nfollowing subsections, we discuss the definitions of these states\r\ntypes, and show how GMAT converts between the different state\r\nrepresentations.\r\n\r\n\\subsection{Definitions}\r\n\r\nThe Keplerian elements are one of the most commonly used state\r\nrepresentations.  They provide a way to define the spacecraft\r\nstate in way that provides an intuitive understanding of the\r\nmotion of spacecraft in orbit.  The Keplerian elements are denoted\r\n$a$, $e$, $i$, $\\omega$, $\\Omega$, and $\\nu$. They are defined in\r\ndetail in Table \\ref{Table:KeplerianElements} and illustrated in\r\nFig. \\ref{fig:KeplerianElements}.  Sections \\ref{Sec:Cart2Kep} and\r\n\\ref{Sec:Kep2Cart} show the algorithms that GMAT uses to convert\r\nbetween the Keplerian elements and the cartesian state.\r\n\\index{Keplerian elements!definition}\r\n%\r\n\r\n\\begin{figure*}[htb]\r\n\\index{Keplerian elements} \\centerline{\r\n\\begin{picture}(100,545)\r\n\\special{psfile=Images/OrbitElements.eps hoffset= -195 voffset= 75\r\nhscale=80\r\nvscale=80}\\makebox(-78,600){$\\hat{\\mathbf{x}}_I$,$\\Upsilon$}\r\n\\makebox(40,610){$\\hat{\\mathbf{x}}_{ep}$} \\makebox(10,685){$\\Omega$}\r\n\\makebox(215,795){$\\omega$} \\makebox(-120,840){$y_I$}\r\n\\makebox(-135,968){$\\mathbf{x}_p$}\\makebox(-255,980){$\\nu$}\r\n\\makebox(-485,1083){$z_I$} \\makebox(-540,1028){$i$}\r\n    \\makebox(-610,1060){$\\mathbf{h}$, $\\hat{\\mathbf{z}}_{ep}$}\r\n    \\makebox(-340,610){$\\mathbf{N}$}\r\n\\end{picture}}\\vskip -3.95 in  \\caption{ The Keplerian Elements } \\label{fig:KeplerianElements}\r\n\\end{figure*}\r\n\r\nThe cartesian state is another common state representation and is\r\noften used in the numerical integration of the equations of\r\nmotion.  The cartesian state with respect to a given coordinate\r\nsystem is described in detail in Table\r\n\\ref{Table:CartesianStates}. \\index{Cartesian state!definition}\r\n\r\n\r\nThe equinoctial elements are a set of non-singular elements that\r\ncan be used to describe the state of a spacecraft.  Because they\r\nare nonsingular, they are useful for expressing the equations of\r\nmotion in Variation of Parameters (VOP) form.  The elements can be\r\nunintuitive to use however.  The equinoctial elements are\r\ndescribed in detail in Table \\ref{Table:EquinoctialElements}.\r\n%\r\n\r\n\\begin{figure*}[htb]\r\n\\index{Spherical elements} \\centerline{\r\n\\begin{picture}(100,420)\r\n\\special{psfile=Images/SphericalElements.eps hoffset= -100 voffset=\r\n75\r\nhscale=55 vscale=55} \\makebox(-280,360){$\\mathbf{x}$}%\r\n\\makebox(140,590){$\\mathbf{y}$}%\r\n\\makebox(-435,820){$\\mathbf{z}$}%\r\n\\makebox(-410,530){$\\lambda$}%\r\n\\makebox(-273,636){$\\delta$}%\r\n\\makebox(-330,695){$\\mathbf{r}$}%\r\n\\makebox(-250,770){$\\mathbf{v}$}%\r\n\\makebox(90,710){$\\mathbf{v}$}%\r\n\\makebox(10,675){$\\hat{\\mathbf{r}}$}%\r\n\\makebox(-350,650){North}%\r\n\\makebox(-275,635){$\\psi$}%\r\n\\makebox(-180,597){$\\alpha_f$}%\r\n\\end{picture}}\\vskip -2.5 in  \\caption{ The Spherical Elements } \\label{fig:SphericalElements}\r\n\\end{figure*}\r\n%\r\n\r\nThe modified Keplerian elements are similar to the Keplerian\r\nelements except $a$ and $e$ are replaced with the radius of\r\nperiapsis $r_p$, and the radius of apoapsis $r_a$. $r_p$ and $r_a$\r\nare often more convenient and intuitive for describing the\r\ndimensions of a Keplerian orbit than $a$ and $e$.  The modified\r\nKeplerian elements are defined in detail in Table\r\n\\ref{Table:ModKeplerianElements}. Note that both the Keplerian and\r\nmodified Keplerian elements are undefined for parabolic orbits\r\nbecause the semimajor axis is infinite.  Currently, GMAT does not\r\nsupport parabolic orbits for this reason.  Let's begin by looking\r\nat how GMAT converts from the Cartesian state to the Keplerian\r\nelements.\r\n\r\n\\index{Modified Keplerian elements!definition}\r\n%\r\n\r\n\\subsection{Cartesian State to Keplerian Elements}\\label{Sec:Cart2Kep}  \\index{Cartesian state!to\r\nKeplerian} \\index{Keplerian elements!from cartesian}\r\n\r\nThe conversion from the Cartesian state to the Keplerian elements\r\nhas four special cases:  elliptic inclined, circular inclined,\r\nelliptic equatorial, and circular equatorial.  Certain orbital\r\nelements are undefined for some of the cases.  For example, the\r\nright ascension of the ascending node, $\\Omega$, is undefined for\r\nequatorial orbits.  However, computer systems don't handle undefined\r\nvalues gracefully.  In this section, we'll see how the orbital\r\nelements are defined for each of the special cases, and how GMAT\r\ncalculates the orbital elements for each case\\cite{Vallado:02}.\r\n\r\n%\r\n\\begin{table*} \\caption{The Cartesian State}\r\n\\centering \\index{Cartesian state!definition}\r\n\\begin{tabular}{p{.5 in} p{2.0 in}}\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Symbol &  Description \\\\\r\n  \\hline\r\n  $x$ &  $x$-component of position\\\\\r\n%\r\n  $y$ &  $y$-component of position \\\\\r\n  %\r\n  $z$ &  $z$-component of position \\\\\r\n  %\r\n  $\\dot{x}$ &  $x$-component of velocity\\\\\r\n  %\r\n  $\\dot{y}$ & $y$-component of velocity\\\\\r\n  %\r\n  $\\dot{z}$ & $z$-component of velocity \\\\\r\n  \\hline\\hline \\label{Table:CartesianStates}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\n\\begin{table*} \\caption{The Keplerian Elements (also see Fig. \\ref{fig:KeplerianElements})}\r\n\\centering \\index{Keplerian elements!definition} (See Table\r\n\\ref{Table:ElementSpecialCases} for definitions of elements for near\r\ncircular and near equatorial orbits.)\r\n\\begin{tabular}{p{.5 in} p{1.5 in} p{3.5 in}}\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Symbol & Name & Description \\\\\r\n  \\hline\r\n  $a$ & semimajor axis & The semimajor contains information on the type and size of an orbit.\r\n  If $a>0$ the orbit is elliptic.  If $a < 0$ the orbit is hyperbolic. $a = \\infty$ for parabolic orbits. \\\\\r\n %\r\n  $e$ & eccentricity & The eccentricity contains information on the shape of an orbit.  If $e = 0$, then the orbit is circular. If $0 < e < 1$ the orbit is\r\n  elliptical.  If $e = 1$ the orbit is parabolic.  If $e > 1$ then the orbit is hyperbolic. \\\\\r\n  %\r\n  $i$ & inclination & The inclination is the angle between the $\\hat{\\mathbf{z}}_I$ axis and the orbit normal direction $\\mathbf{h}$.  If $i \\leq 90^{\\circ}$ then the orbit is prograde.\r\n  If $i > 90^{\\circ}$ then the orbit is retrograde.  \\\\\r\n  %\r\n  $\\omega$ & argument of periapsis & The argument of periapsis is the angle between a vector pointing at periapsis  and a vector pointing in the direction of the line of nodes. The argument of periapsis is undefined for circular orbits.\\\\\r\n  %\r\n  $\\Omega$ & right ascension of  the ascending node& $\\Omega$ is defined as the angle between $\\hat{\\mathbf{x}}_I$ and $\\mathbf{N}$ measured\r\n  counterclockwise.\r\n    $\\mathbf{N}$ is defined as the vector pointing from the center of the central body to the spacecraft, when the spacecraft crosses the bodies equatorial plane\r\n  from the southern to the northern hemisphere.  $\\Omega$ is undefined for equatorial orbits.   \\\\\r\n  %\r\n  $\\nu$ & true anomaly & The true anomaly is defined as the angle between a vector pointing at periapsis and a vector pointing at the spacecraft.\r\n  The true anomaly is undefined for circular orbits. \\\\\r\n  \\hline\\hline \\label{Table:KeplerianElements}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\n%\r\n\\begin{table*} \\caption{Keplerian Elements for Special Cases}\r\n \\centering \\index{Keplerian elements!special cases}\r\n \\label{Table:ElementSpecialCases}\r\n\\begin{tabular}{p{1.25 in} p{1.35 in} p{3.2 in}  }\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Orbit Type & Numerical Threshold & Description \\\\\r\n  \\hline \\\\\r\n  %--------------\r\n  Elliptic Inclined & $e \\geq 10^{-11}$, $i \\geq 10^{-11}$ & $\\Omega$ is the angle between the $x$-axis and the line of nodes. $\\omega$ is the angle between the line of nodes and the eccentricity vector, $\\nu$ is\r\n                                                     the angle between the eccentricity vector and the spacecraft position vector.\\\\\r\n  %--------------\r\n  Elliptic Equatorial & $e \\geq 10^{-11}$, $i < 10^{-11}$ & $\\Omega = 0$, $\\omega$ is the angle between the $x$-axis and the eccentricity vector, $\\nu$ is\r\n                                                     the angle between the eccentricity vector and the spacecraft position vector.\\\\\r\n  %--------------\r\n  Circular Inclined & $e < 10^{-11}$, $i \\geq 10^{-11}$  & $\\Omega$ is the angle between the $x$-axis and the line of nodes, $\\omega = 0$, $\\nu$ is\r\n                                                     the angle between the line of nodes and the spacecraft position vector.\\\\\r\n  %--------------\r\n  Circular Equatorial & $e < 10^{-11}$, $i < 10^{-11}$ & $\\Omega = 0$, $\\omega = 0$, $\\nu$ is the angle between the $x$-axis and the spacecraft position vector. \\\\\r\n  \\hline\\hline \\label{Table:KeplerianElementsSpecialCases}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$\\\\\r\n\r\n\\noindent Find: $a$, $e$, $i$, $\\omega$, $\\Omega$, and $\\nu$\r\n\r\nWe begin by calculating the specific angular momentum and its\r\nmagnitude.\r\n%\r\n\\begin{equation}\r\n     \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     h = \\|\\mathbf{h} \\|\r\n\\end{equation}\r\n%\r\nA vector pointing in the direction of the line of nodes is\r\n%\r\n\\begin{equation}\r\n     \\mathbf{n} = [ \\hspace{0.05 in} 0 \\hspace{0.1 in} 0 \\hspace{0.1 in} 1 \\hspace{0.05\r\n     in}]^T \\times \\mathbf{h}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     n = \\| n\\|\r\n\\end{equation}\r\n%\r\nThe orbit eccentricity and energy are calculated using\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{e} = \\displaystyle\\frac{(v^2 - \\displaystyle\\frac{\\mu}{r} )\\mathbf{r} - (\\mathbf{r}\\cdot\\mathbf{v}  )\\mathbf{v}}{\\mu}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     e = \\| \\mathbf{e} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\xi = \\frac{v^2}{2} - \\frac{\\mu}{r}\r\n\\end{equation}\r\n%\r\nFor parabolic orbits, the semimajor axis is infinite\r\nand the energy is zero. Here we check to see if the orbit is near\r\nparabolic.  If $|1 - e| < 10^{-7}$ an error message is reported\r\nand conversion is aborted.\r\n\r\nThe semimajor axis is computed using\r\n%\r\n\\begin{equation}\r\n     a = -\\frac{\\mu}{2\\xi}\r\n\\end{equation}\r\n%\r\nHere we check to see if the conic section is nearly singular.\r\nIf $|a(1-e)| < .001 (km)$ then an error message is thrown and conversion is aborted.\r\n\r\nIf the above tests pass, then we continue and calculate the inclination.\r\n%\r\n\\begin{equation}\r\n     i = \\cos^{-1}\\left(\\frac{h_z}{h}\\right)\r\n\\end{equation}\r\n\r\nThere are four special cases for $\\Omega$, $\\omega$, and $\\nu$ and\r\neach case is treated differently.\r\n\r\n\\noindent\\textit{Special Case 1:  Non-circular, Inclined Orbit  }\r\n\r\n\\noindent if $(e \\geq 10^{-11})$  and $(i \\geq 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\Omega = \\cos^{-1}\\left(\\frac{n_x}{n}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\Omega$: if $n_y < 0$, then $\\Omega = 2\\pi -\r\n\\Omega$\r\n%\r\n\\begin{equation}\r\n    \\omega = \\cos^{-1}\\left( \\frac{\\mathbf{n}\\cdot\\mathbf{e}}{ne}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\omega $:  if $e_z < 0$, then $\\omega = 2\\pi -\r\n\\omega$\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{\\mathbf{e}\\cdot\\mathbf{r}}{er}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu $:  if $\\mathbf{r} \\cdot \\mathbf{v} < 0$, then\r\n$\\nu = 2\\pi - \\nu$\r\n\r\n\\noindent\\textit{Special Case 2:  Non-circular, Equatorial Orbit\r\n}\r\n\r\n\\noindent if $(e \\geq 10^{-11})$  and $(i < 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\Omega = 0\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\omega = \\cos^{-1}{\\frac{e_x}{e}}\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\omega $: if $e_y < 0$, then $\\omega = 2\\pi -\r\n\\omega$\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{\\mathbf{e}\\cdot\\mathbf{r}}{er}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu $:  if $\\mathbf{r} \\cdot \\mathbf{v} < 0$, then\r\n$\\nu = 2\\pi - \\nu$\r\n%\r\n\r\n\\noindent\\textit{Special Case 3:  Circular, Inclined Orbit  }\r\n\r\n\\noindent if $(e < 10^{-11})$  and $(i \\geq 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\Omega = \\cos^{-1}\\left(\\frac{n_x}{n}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\Omega$: if $n_y < 0$, then $\\Omega = 2\\pi -\r\n\\Omega$\r\n\\begin{equation}\r\n     \\omega = 0\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{\\mathbf{n}\\cdot\\mathbf{r}}{nr}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu$:  if $r_z < 0$, then $\\nu = 2\\pi - \\nu$\r\n\r\n\\noindent\\textit{Special Case 4:  Circular, Equatorial Orbit  }\r\n\r\n\\noindent if $(e < 10^{-11})$  and $(i < 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n     \\Omega = 0\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\omega = 0\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{r_x}{r}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu$:  if $r_y < 0$, then $\\nu = 2\\pi - \\nu$\r\n%\r\n\r\nIn the next section, we look at how to perform the inverse\r\ntransformation and convert from Keplerian elements to the\r\nCartesian state vector.\r\n\r\n\\subsection{Keplerian Elements to Cartesian \\\\ State}\r\n\r\n\r\n\\label{Sec:Kep2Cart} \\index{Keplerian elements!to\r\ncartesian} \\index{Cartesian state!from Keplerian}\r\n\r\nThe transformation from the Keplerian elements to the Cartesian\r\nstate is one of the most common state transformations in\r\nastrodynamics.  We previously defined both state types and refer you\r\nto Tables \\ref{Table:CartesianStates} and\r\n\\ref{Table:KeplerianElements} for their definitions.  Below we show\r\nthe algorithm that GMAT uses to convert from the Keplerian elements\r\nto the Cartesian state\\cite{Vallado:02}.\r\n\r\n\\noindent Give:  $a$, $e$, $i$, $\\Omega$, $\\omega$, $\\nu$, and\r\n$\\mu$\r\n\r\n\\noindent Find:  $\\mathbf{r}$  and $\\mathbf{v}$\r\n\r\nFirst check to ensure the keplerian elements are not singular. If $|a(1-e)| < .001 (km)$ then the following error message is reported and conversion is aborted: ``Warning: A nearly singular conic section was encountered while converting from the Keplerian elements to the Cartesian state.  The radius of periapsis must be greater than 1 meter.\"\r\n\r\nNext check that the magnitude of the position vector is\r\nnot infinite.  If ($1+e\\cos{\\nu}$ $<$ 1e-30) then the following error message is reported and conversion is aborted:\r\n``Warning: A near infinite radius  was encountered while converting from the Keplerian elements to the Cartesian state. \"\r\n\r\nCheck that the orbit is not parabolic, in which case, $p$ is undefined.  If ($|1-e|< 1e-7$ then the following error message is reported and conversion is aborted:\r\n``Warning: A nearly parabolic orbit was encountered while converting from the Keplerian elements to the Cartesian state.  The Keplerian elements are undefined for a parabolic orbit.\".\r\n\r\nFinally, define $\\nu_M$ as the true anomaly placed between $-\\pi$ and $\\pi$.  If $e > 1$  and  $\\|\\nu_M\\| \\geq \\pi - acos(1/e)$ the following error message is reported and conversion is aborted:\\\\\r\n``Error: The TA value is not physically possible for a hyperbolic orbit with  the input values of SMA and ECC.\\\\\r\n The allowed values are: $-limitTA < TA < limitTA$ (degrees).\r\n or equivalently\\\\\r\n The allowed values are $TA < limitTA$ or $TA > 360 - limitTA$.\r\n\" where the text ``limitTA\"' is replaced by the numeric value computed below in degrees:\r\n%\r\n\\begin{equation}\r\n    limitTA = \\pi - acos(1/e)\r\n\\end{equation}\r\n%\r\n\r\nIf the previous tests pass, we continue  by\r\ncalculating the semilatus rectum, and the radius.\r\n%\r\n\\begin{equation}\r\n    p = a(1-e^2);\r\n\\end{equation}\r\n%\r\nIf $1+e\\cos{\\nu} < 1e-10$, then the following warning is displayed but computation proceeds. ``Warning: The orbital radius is large in  the conversion from Keplerian to Cartesian state and the state may be near a singularity causing numerical errors in the conversion.\"\r\n%\r\n\\begin{equation}\r\n     r = \\frac{p}{1+e\\cos{\\nu}}\r\n\\end{equation}\r\n%\r\nThe position components of the cartesian state vector are\r\ncalculated using the following three equations.\r\n%\r\n\\begin{equation}\r\n     x = r\\left(\\cos{(\\omega + \\nu)}\\cos{\\Omega} - \\cos{i}\\sin{(\\omega + \\nu)}\\sin{\\Omega}\\right)\r\n\\end{equation}\r\n\\begin{equation}\r\n     y = r\\left(\\cos{(\\omega + \\nu)}\\sin{\\Omega} + \\cos{i}\\sin{(\\omega + \\nu)}\\cos{\\Omega}\\right)\r\n\\end{equation}\r\n\\begin{equation}\r\n     z = r\\left(\\sin{(\\omega + \\nu)}\\sin{i}\\right)\r\n\\end{equation}\r\n%\r\n\r\nBefore calculating the velocity components we check to ensure the\r\norbit is not parabolic.  This avoids another possible division by\r\nzero.\r\n\r\n\\noindent if ($\\| p\\| < 1e-30$), then error and return: ``Warning:\r\nGMAT does not support parabolic orbits in conversion from\r\nkeplerian to cartesian elements\".\r\n\r\n\\noindent If the orbit is not parabolic, we continue and calculate\r\nthe velocity components using\r\n%\r\n\\begin{equation}\\begin{split}\r\n     \\dot{x} = \\sqrt{\\frac{\\mu}{p}} &  \\left( \\cos{\\nu} + e \\right)\r\n     \\left( -\\sin{\\omega}\\cos{\\Omega} - \\cos{i}\\sin{\\Omega}\\cos{\\omega}\r\n     \\right)- \\\\ &\\sqrt{\\frac{\\mu}{p}}  \\sin{\\nu}\\left(\\cos{\\omega}\\cos{\\Omega} - \\cos{i}\\sin{\\Omega}\\sin{\\omega} \\right)\r\n      \\end{split}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\\begin{split}\r\n     \\dot{y} =    \\sqrt{\\frac{\\mu}{p}}&  \\left( \\cos{\\nu} + e \\right)\r\n     \\left( -\\sin{\\omega}\\sin{\\Omega} + \\cos{i}\\cos{\\Omega}\\cos{\\omega}\r\n     \\right)- \\\\\\ & \\sqrt{\\frac{\\mu}{p}}\\sin{\\nu}\\left(\\cos{\\omega}\\sin{\\Omega} + \\cos{i}\\cos{\\Omega}\\sin{\\omega} \\right)\r\n     \\end{split}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\dot{z} = \\sqrt{\\frac{\\mu}{p}} \\left[ \\left( \\cos{\\nu} + e \\right)\\sin{i}\\cos{w} - \\sin{\\nu}\\sin{i}\\sin{\\omega}      \\right]\r\n\\end{equation}\r\n\r\nNow let's look at how to calculate the cartesian state given the\r\nequinoctial elements.\r\n\r\n\\subsection{Equinoctial Elements to Cartesian State}  \\index{Equinoctial elements!to\r\ncartesian}\\index{Cartesian state!from Equinotial}\r\n\\label{Sec:EquinoctialtoCartesian}\r\n\r\nThe equinoctial elements used in GMAT are defined in Table\r\n\\ref{Table:EquinoctialElements}.  The algorithm to convert from\r\nequinoctial elements to the cartesian state was taken from the\r\nGTDS Mathematical Theory \\cite{GTDS}.\r\n\r\n\\begin{table*} \\caption{The Equinoctial Elements}\r\n\\centering \\index{Equinoctial elements!definition}\r\n\\begin{tabular}{p{.5 in} p{5.0 in}}\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Symbol &  Description \\\\\r\n  \\hline\r\n  $a$ &  The semimajor contains information on the type and size of an orbit.  If $a>0$ the orbit is elliptic.  If $a < 0$ the orbit is hyperbolic. \\\\\r\n%\r\n  $h$ &  The projection of the eccentricity vector onto the $\\hat{\\mathbf{y}}_{ep}$ axis. \\\\\r\n  %\r\n  $k$ & The projection of the eccentricity vector onto the $\\hat{\\mathbf{x}}_{ep}$ axis. \\\\\r\n  %\r\n  $p$ &  The projection of $\\mathbf{N}$  onto the $\\hat{\\mathbf{y}}_{ep}$ axis.\\\\\r\n  %\r\n  $q$ & The projection of $\\mathbf{N}$  onto the $\\hat{\\mathbf{x}}_{ep}$ axis.  \\\\\r\n  %\r\n  $\\lambda$ & The mean longitude. \\\\\r\n  \\hline\\hline \\label{Table:EquinoctialElements}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\n\\noindent Given: $a$, $h$, $k$, $p$, $q$, $\\lambda$, and $\\mu$\r\n\r\n\\noindent Find: $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\nWe begin by using the mean longitude, $\\lambda$, to find the true\r\nlongitude $F$.  The equation relating the two is transcendental:\r\n\\begin{equation}\r\n     \\lambda = F + h\\cos{F} - k \\sin{F}\r\n\\end{equation}\r\n%\r\nWe use the Newton-Raphson method to solve for $F$, using $\\lambda$\r\nas the initial guess.  We iterate on the following equation until\r\n$|F(i+1) - F(i)| < 10^{-10}$.\r\n%\r\n\\begin{equation}\r\n    F(i+1) = F(i) - \\frac{f(F)}{f'(F)}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{eqnarray}\r\n    f(F) &=& F + h \\cos(F) - k\\sin(F) - \\lambda \\\\\r\n    %\r\n    f'(F) &=& 1 - h \\sin(F) - k \\cos(F)\r\n\\end{eqnarray}\r\n\r\nOnce the true longitude is calculated, we continue with\r\n%\r\n\\begin{equation}\r\n   \\beta = \\frac{1}{1 + \\sqrt{1 - h^2 - k^2}} \\label{Eq:Beta}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   n = \\sqrt{\\frac{\\mu}{a^3}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   r = a(1 - k\\cos{F} - h\\sin{f})\r\n\\end{equation}\r\n\r\nThe cartesian components expressed in the equinoctial coordinate\r\nsystem can be calculated using.\r\n%\r\n\\begin{equation}\r\n   X_1 = a\\left[ ( 1 - h^2 \\beta) \\cos{F} + h k \\beta \\sin{F} - k   \\right]\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   Y_1 = a\\left[ ( 1 - k^2 \\beta) \\sin{F} + h k \\beta \\cos{F} - h   \\right]\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n  \\dot{X}_1 = \\frac{n a^2}{r}\\left[h k \\beta \\cos{F} - (1 - h^2 \\beta)\\sin{F}   \\right]\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n  \\dot{Y}_1 = \\frac{n a^2}{r}\\left[  (1 - k^2 \\beta)\\cos{F}  -  h k \\beta \\sin{F}   \\right]\r\n\\end{equation}\r\n%\r\n\r\nThe transformation from the equinoctial system to the inertial\r\nCartesian system is given by\r\n%\r\n\\begin{equation}\r\n   \\mathbf{r} = X_1 \\hat{\\mathbf{f}} + Y_1 \\hat{\\mathbf{g}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\mathbf{v} = \\dot{X}_1 \\hat{\\mathbf{f}} + \\dot{Y}_1 \\hat{\\mathbf{g}}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n    \\left[ \\hat{\\mathbf{f}} \\hspace{.1 in} \\hat{\\mathbf{g}} \\hspace{.1 in} \\hat{\\mathbf{w}}\r\n    \\right]=  \\frac{1}{1+p^2+q^2}\\hspace{.1 in} \\mathbf{Q}\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation} \\mathbf{Q} =\r\n \\begin{pmatrix}\r\n               1 - p^2 + q^2 &\r\n               2 p q j &\r\n               2 p \\\\\r\n%\r\n               2 p q&\r\n               \\left( 1 + p^2 - q^2 \\right)j &\r\n               -2 q \\\\\r\n               %\r\n               - 2 p j&\r\n               2 q &\r\n               \\left(1 - p^2 - q^2  \\right)j \\\\\r\n               %\r\n     \\end{pmatrix}\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\noindent j = 1 for direct orbits ( $0\\leq i \\leq 90^{\\circ}$ )\\\\\r\n j = -1 for retrograde orbits ( $90 < i \\leq 180^{\\circ}$ )\\\\\r\n\r\nNow let's look at how to calculate the cartesian state given the\r\nequinoctial elements.\r\n\r\n\\subsection{Cartesian State to Equinoctial Elements}  \\index{Equinoctial elements!from cartesian}\r\n\\index{Cartesian state!to Equinotial}\r\n\\label{Sec:CartesiantoEquinoctial}\r\n\r\nThe equinoctial elements used in GMAT are defined in Table\r\n\\ref{Table:EquinoctialElements}.  The algorithm to convert from\r\nthe cartesian state to the equinoctial elements was taken from the\r\nGTDS Mathematical Theory \\cite{GTDS}.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$\r\n\r\n\\noindent Fine:  $a$, $h$, $k$, $p$, $q$, $\\lambda$, and $\\mu$\r\n\r\nThe orbit eccentricity and energy are calculated using\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{e} = \\displaystyle\\frac{(v^2 - \\displaystyle\\frac{\\mu}{r} )\\mathbf{r} - (\\mathbf{r}\\cdot\\mathbf{v}  )\\mathbf{v}}{\\mu}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     e = \\| \\mathbf{e} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\xi = \\frac{v^2}{2} - \\frac{\\mu}{r}\r\n\\end{equation}\r\n%\r\nFor parabolic orbits, the semimajor axis is infinite\r\nand the energy is zero. Here we check to see if the orbit is near\r\nparabolic.  If $|1 - e| < 10^{-7}$ an error message is reported\r\nand conversion is aborted.\r\n\r\nThe semimajor axis is computed using\r\n%\r\n\\begin{equation}\r\n     a = -\\frac{\\mu}{2\\xi}\r\n\\end{equation}\r\n%\r\nHere we check to see if the conic section is nearly singular.\r\nIf $|a(1-e)| < .001 (km)$ then an error message is thrown and conversion is aborted.\r\n\r\nThe angular momentum unit vector is\r\n%\r\n\\begin{equation}\r\n   \\hat{\\mathbf{h}} = \\frac{\\mathbf{r} \\times \\mathbf{v} }{ \\| \\mathbf{r} \\times \\mathbf{v} \\|}\r\n\\end{equation}\r\n%\r\nThe unit vectors that define the equinoctial coordinate system can\r\nbe calculated using\r\n%\r\n\\begin{equation}\r\n   f_x = 1 - \\frac{\\hat{h}_x^2}{ 1 + \\hat{h}_z^j}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   f_y = -\\frac{\\hat{h}_x \\hat{h}_y}{ 1 + \\hat{h}_z^j}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   f_z = -\\hat{h}_x^j\r\n\\end{equation}\r\n%\r\nwhere $j = 1$ if $ \\hat{h}_z > 0 $  and $j = -1$ otherwise. \\\\\r\n%\r\n\\begin{equation}\r\n    \\hat{\\mathbf{g}} = \\hat{\\mathbf{h}} \\times \\hat{\\mathbf{f}}\r\n\\end{equation}\r\n%\r\n\r\nWe now have the necessary information to calculate the elements\r\n$h$, $k$, $p$, and $q$ using the following relationships.\r\n%\r\n\\begin{equation}\r\n    h = \\mathbf{e} \\cdot \\hat{\\mathbf{g}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    k = \\mathbf{e} \\cdot \\hat{\\mathbf{f}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    p = \\frac{\\hat{h}_x}{1+\\hat{h}_z^j}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    q = - \\frac{\\hat{h}_y}{1+\\hat{h}_z^j}\r\n\\end{equation}\r\n%\r\n\r\nThe final element to calculate is the mean longitude, $\\lambda$.\r\nWe begin by computing the eccentric longitude, $F$,  using\r\n%\r\n\\begin{equation}\r\n    X_1 = \\mathbf{r} \\cdot \\hat{\\mathbf{f}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    Y_1 = \\mathbf{r} \\cdot \\hat{\\mathbf{g}}\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation}\r\n     \\cos{F} = k + \\frac{ \\left( 1 - k^2 \\beta \\right) X_1 - h k \\beta Y_1}{a\\sqrt{1 - h^2 - k^2}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\sin{F} = h + \\frac{ \\left( 1 - h^2 \\beta \\right) Y_1 - h k \\beta X_1}{a\\sqrt{1 - h^2 - k^2}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     F = \\tan^{-1}_2\\left( \\frac{\\sin{F}}{\\cos{F}}\\right)\r\n\\end{equation}\r\n%\r\nwhere $\\beta$ is given by Eq.~\\ref{Eq:Beta}.  The mean longitude\r\nis computed using the generalized Kepler equation\r\n%\r\n\\begin{equation}\r\n    \\lambda = F + h \\cos{F} - k \\sin{F}\r\n\\end{equation}\r\n\r\nNow let's look at transformations involving the spherical\r\nelements.\r\n\r\n\\subsection{Cartesian State to SphericalAZFPA State}\r\n\\label{Sec:CarttoSphericalAZFPA} \\index{Cartesian state!to\r\nSphericalAZFPA} \\index{SphericalAZFPA! from Cartesian state }\r\n\r\nThe spherical state, with azimuth, $\\alpha_f$, and flight path\r\nangle, $\\psi$, is described in Table \\ref{Table:SphericalElements}\r\nand Fig. \\ref{fig:SphericalElements}.  The algorithm below shows\r\nhow GMAT converts from the cartesian state to the spherical state\r\nwith azimuth and flight path angle.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\n\\noindent Find:  $r$, $\\lambda$, $\\delta$, $v$, $\\psi$, and\r\n$\\alpha_f$\r\n\r\n\\begin{table*} \\caption{The Spherical Elements}\r\n\\centering \\index{Spherical elements!definition}\r\n\\begin{tabular}{p{.5 in} p{1.5 in} p{3.5 in}}\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Symbol & Name & Description \\\\\r\n  \\hline\r\n  $r$ & $r$ & Magnitude of the position vector, $\\|\\mathbf{r}\\|$ \\\\\r\n    %\r\n  $\\lambda$ & Right Ascension & The angle between the projection of $\\mathbf{r}$ into the $xy$-plane and the $x$-axis measured counterclockwise.   \\\\\r\n%\r\n  $\\delta$ & Declination & The angle between $\\mathbf{r}$ and the $xy$-plane. \\\\\r\n\r\n  %\r\n  $v$ & $v$ & Magnitude of the velocity vector, $\\|\\mathbf{v}\\|$. \\\\\r\n  %\r\n  $\\psi$ & Vertical flight path angle & The angle measured from a plane normal to $\\mathbf{r}$ to the velocity vector $\\mathbf{v}$, measured in the plane formed by $\\mathbf{r}$  and $\\mathbf{v}$   \\\\\r\n  %\r\n  $\\alpha_f$ & Flight path azimuth & The angle measured from vector perpendicular  $\\mathbf{r}$ and pointing north, to the projection of $\\mathbf{v}$ into a plane normal to $\\mathbf{r}$. \\\\\r\n  %\r\n    $\\lambda_v$ & Right ascension of velocity &  The angle between the projection of $\\mathbf{v}$ into the $xy$-plane and the $x$-axis measured counterclockwise. \\\\\r\n  %\r\n  $\\delta_v$ & Declination of velocity &   The angle between the velocity vector and the $xy$-plane. \\\\\r\n    \\hline\\hline \\label{Table:SphericalElements}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\nWe begin by calculating the right ascension $\\lambda$, and the\r\ndeclination $\\delta$.\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\| \\label{Eq:Sphericalr}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\lambda= \\tan^{-1}_2(y,x) \\label{Eq:Sphericallambda}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\delta = \\sin^{-1}(\\frac{z}{r}) \\label{Eq:Sphericaldelta}\r\n\\end{equation}\r\n%\r\nThe magnitude of the velocity vector is simply\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|  \\label{Eq:Sphericalv}\r\n\\end{equation}\r\n%\r\nWe calculate the vertical flight path angle, $psi$, using\r\n%\r\n\\begin{equation}\r\n    \\psi = \\cos^{-1}\\left(  \\frac{\\mathbf{r} \\cdot \\mathbf{v} }{r v} \\right)\r\n\\end{equation}\r\n%\r\nTo calculate the azimuth angle, $\\alpha_z$, we begin by\r\ncalculating the rotation matrix from the frame in which the\r\ncartesian state is expressed in, $\\mathcal{F}_{i}$, to a local\r\nframe, $\\mathcal{F}_{\\ell}$, where $\\hat{\\mathbf{z}}$ is a unit\r\nvector that points north.  The basis vectors of\r\n$\\mathcal{F}_{\\ell}$ expressed in $\\mathcal{F}_{i}$ can be\r\ncalculated using\r\n%\r\n\\begin{equation}\r\n    \\hat{\\mathbf{x}} =\r\n    \\begin{pmatrix}\r\n        \\cos(\\delta)\\cos(\\lambda)\\\\\r\n         \\cos(\\delta)\\sin(\\lambda)\\\\\r\n          \\sin(\\delta)\r\n    \\end{pmatrix} \\label{Eq:SphericalAZFPAx}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\hat{\\mathbf{y}} =\r\n    \\begin{pmatrix}\r\n          \\cos(\\lambda + \\pi/2)\\\\\r\n          \\sin(\\lambda + \\pi/2)\\\\\r\n          0\r\n    \\end{pmatrix}  \\label{Eq:SphericalAZFPAy}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\hat{\\mathbf{z}} =\r\n    \\begin{pmatrix}\r\n          -\\sin(\\delta)\\cos(\\lambda)\\\\\r\n          -\\sin(\\delta)\\sin(\\lambda)\\\\\r\n          \\cos(\\delta)\r\n    \\end{pmatrix}  \\label{Eq:SphericalAZFPAz}\r\n\\end{equation}\r\n%\r\nWe can write the tranformation matrix that goes from\r\n$\\mathcal{F}_{i}$ to $\\mathcal{F}_{\\ell}$, $\\mathbf{R}_{\\ell i}$,\r\nas\r\n%\r\n\\begin{equation}\r\n    \\mathbf{R}_{\\ell i} = [\\hspace{.05 in} \\hat{\\mathbf{x}} \\hspace{.1 in}\r\n    \\hat{\\mathbf{y}} \\hspace{.1in} \\hat{\\mathbf{z}} \\hspace{.05 in}]^T\r\n\\end{equation}\r\n%\r\nThe velocity in the local frame,  $\\mathbf{v}'$, can be written as\r\n%\r\n\\begin{equation}\r\n    \\mathbf{v}' = \\mathbf{R}_{\\ell i}\\mathbf{v}\r\n\\end{equation}\r\n%\r\nFinally, we calculate the azimuth angle using\r\n\\begin{equation}\r\n     \\alpha_f = \\tan^{-1}_2( v'_y, v'_z )\r\n\\end{equation}\r\n\r\nNow that we have looked at how to convert from the Cartesian state\r\nto the spherical state, let's look at the inverse transformation\r\nthat converts from the spherical state (with $\\psi$ and\r\n$\\alpha_f$) to the cartesian state.\r\n\r\n\\subsection{SphericalAZFPA State to Cartesian State} \\index{Cartesian\r\nstate!from SphericalAZFPA} \\index{SphericalAZFPA! to Cartesian\r\nstate } \\label{Sec:SphericalAZFPAtoCartesian}\r\n\r\nIn this section we present the algorithm used to convert from the\r\nspherical state (with $\\psi$ and $\\alpha_f$) to the cartesian\r\nstate.\r\n\r\n\\noindent Given: $r$, $\\lambda$, $\\delta$, $v$, $\\psi$, and\r\n$\\alpha_f$\r\n\r\n\\noindent Find:  $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\nThe components of the position vector are calculated using\r\n%\r\n\\begin{eqnarray}\r\n     x &=& r\\cos{\\delta} \\cos{ \\lambda } \\label{Eq:Sphericalx}\\\\\r\n     %\r\n     y &=& r\\cos{\\delta}\\sin{\\lambda}  \\label{Eq:Sphericaly}\\\\\r\n     %\r\n     z &=& r\\sin{\\delta} \\label{Eq:Sphericalz}\r\n\\end{eqnarray}\r\n%\r\n\r\nWe can write the velocity vector in terms of $v$, $\\psi$, and\r\n$\\alpha_f$ as,\r\n%\r\n\\begin{equation}\r\n     \\mathbf{v} = v\\left[\\cos( \\psi )\\hat{\\mathbf{x}} + \\sin( \\psi )\\sin(\\alpha_f)\\hat{\\mathbf{y}} +\r\n     \\sin( \\psi )\\cos(\\alpha_f)\\hat{\\mathbf{z}}\\right]\r\n     \\label{Eq:SphericalAZFPAv}\r\n\\end{equation}\r\n%\r\nwhere, $\\hat{\\mathbf{x}}$, $\\hat{\\mathbf{y}}$, and\r\n$\\hat{\\mathbf{x}}$ are given in Eqs.~(\\ref{Eq:SphericalAZFPAx}),\r\n(\\ref{Eq:SphericalAZFPAy}), and (\\ref{Eq:SphericalAZFPAz})\r\nrespectively.  Breaking down Eq.~(\\ref{Eq:SphericalAZFPAv}) into\r\ncomponents gives us\r\n%\r\n\\begin{equation}\r\n\\begin{split}\r\n      v_x = v[ \\cos{\\psi}\\cos{\\delta}\\cos{\\lambda}- &\\sin{\\psi}(\\sin{\\alpha_f}\\sin{\\lambda}\r\n       \\\\\r\n      +  &\\cos{\\alpha_f}\\sin{\\delta}\\cos{\\lambda})]\r\n\\end{split}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n\\begin{split}\r\n      v_y = v[\r\n      \\cos{\\psi}\\cos{\\delta}\\sin{\\lambda}+&\\sin{\\psi}(\\sin{\\alpha_f}\\cos{\\lambda}\r\n      \\\\\r\n      -&\\cos{\\alpha_f}\\sin{\\delta}\\sin{\\lambda})]\r\n\\end{split}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n      v_z = v[\\cos{\\psi}\\sin{\\delta}+\\sin{\\psi}\\cos{\\alpha_f}cos{\\delta}]\r\n\\end{equation}\r\n%\r\n\r\n\\subsection{Cartesian State to SphericalRADEC State}\\index{Cartesian state! to\r\nSphericalRADEC} \\index{SphericalRADEC! from Cartesian State }\r\n\r\nThe conversion form the Cartesian state to the spherical state\r\nwith right ascension of velocity, $\\lambda_v$, and declination of\r\nvelocity, $\\delta_v$, is very similar to the transformation shown\r\nin Sec. \\ref{Sec:CarttoSphericalAZFPA}.  The algorithm to\r\ncalculate $\\lambda_v$ and $\\delta_v$ is shown below.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\n\\noindent Find:  $r$, $\\lambda$, $\\delta$, $v$, $\\lambda_v$, and\r\n$\\delta_v$\r\n\r\nTo calculate $r$, $\\lambda$, $\\delta$, and $v$ we use\r\nEqs.~(\\ref{Eq:Sphericalr}), (\\ref{Eq:Sphericallambda}),\r\n(\\ref{Eq:Sphericaldelta}), and (\\ref{Eq:Sphericalv}) respectively.\r\nThe right ascension of velocity, $\\lambda_v$, and declination of\r\nvelocity, $\\delta_v$, are calculated using\r\n%\r\n\\begin{equation}\r\n    \\lambda_v= \\tan^{-1}_2(v_y,v_x) \\label{Eq:Sphericallambdav}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\delta_v = \\sin^{-1}(\\frac{v_z}{v}) \\label{Eq:Sphericaldeltav}\r\n\\end{equation}\r\n%\r\n\r\nIn the next section, we show the the transformation from the\r\nspherical state  with right ascension of velocity, $\\lambda_v$,\r\nand declination of velocity, $\\delta_v$, to the cartesian state.\r\n\r\n\\subsection{SphericalRADEC State to Cartesian State} \\index{Cartesian state!from SphericalRADEC }\r\n\r\nThis transformation is similar to the conversion presented in Sec\r\n\\ref{Sec:SphericalAZFPAtoCartesian}.  The primary difference is\r\nhow the velocity is represented.\r\n\r\n\\noindent Given:  $r$, $\\lambda$, $\\delta$, $v$, $\\lambda_v$, and\r\n$\\delta_v$\r\n\r\n\\noindent Find:  $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\nThe position components are calculated using Eqs.\r\n(\\ref{Eq:Sphericalx}), (\\ref{Eq:Sphericaly}), and\r\n(\\ref{Eq:Sphericalz}).  The velocity components are calculated\r\nusing\r\n%\r\n\\begin{eqnarray}\r\n    v_x &=& v\\cos{\\lambda_v}\\cos{\\delta_v}\\\\\r\n    v_y &=& v_x\\tan{\\lambda_v}\\\\\r\n    v_z &=& v\\sin{\\delta_v}\r\n\\end{eqnarray}\r\n\r\nIn the last few subsections, we have looked at transformations\r\ninvolving the spherical elements.  Now let's look at\r\ntransformations involving the modified Keplerian elements.\r\n\r\n\\subsection{Keplerian or Cartesian, to Modified Keplerian Elements} \\index{Modified Keplerian elements!from Keplerian} \\index{Keplerian elements!to modified Keplerian}\r\n\r\nThe modified Keplerian elements, described in Table\r\n\\ref{Table:ModKeplerianElements}, are similar to the classical\r\nKeplerian elements.  The modified Keplerian elements use the\r\nradius of apoapsis, $r_a$, and the radius of periapsis, $r_p$, to\r\ndescribe the size and shape of an orbit.  The remaining elements,\r\n$i$, $\\Omega$, $\\omega$, and $\\nu$, are the same for both the\r\nKeplerian and modified Keplerian elements. The modified Keplerian\r\nelements, like the Keplerian elements, are undefined for parabolic\r\norbits.  Let's look at how GMAT calculates the modified\r\n\r\n\r\n\\begin{table*} \\caption{The Modified Keplerian Elements}\r\n\\centering\\index{Modified Keplerian elements!definition}\r\n\\begin{tabular}{p{.5 in} p{1.5 in} p{3.5 in}}\r\n  \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n   Symbol & Name & Description \\\\\r\n  \\hline\r\n  $r_p$ & radius of periapsis & The radius of periapsis is the radius at the spacecrafts closest approach to the central body.  The radius of periapsis must be greater than zero, parabolic orbits are not currently supported. \\\\\r\n%\r\n  $r_a$ & radius of apoapsis  &  For an elliptic orbit $r_a$ is the radius at the spacecrafts farthest distance from the central body and $r_a>r_p$.  For hyperbolic orbits, $r_a<r_p$ and $r_a < 0 $  \\\\\r\n  %\r\n  $i$ & inclination & The inclination is the angle between the $\\hat{\\mathbf{z}}_I$ axis and the orbit normal direction $\\mathbf{h}$.  If $i \\leq 90^{\\circ}$ then the orbit is prograde.\r\n  If $i > 90^{\\circ}$ then the orbit is retrograde.  \\\\\r\n  %\r\n  $\\omega$ & argument of periapsis & The argument of periapsis is the angle between a vector pointing at periapsis,\r\n  $\\mathbf{x}_p$, and a vector pointing at the spacecraft. The argument of periapsis is undefined for circular orbits.\\\\\r\n  %\r\n  $\\Omega$ & right ascension of  the ascending node& $\\Omega$ is defined as the angle between $\\hat{\\mathbf{x}}_I$ and $\\mathbf{N}$ measured\r\n  counterclockwise.\r\n    $\\mathbf{N}$ is defined as the vector pointing from the center of the central body to the spacecraft, when the spacecraft crosses the bodies equatorial plane\r\n  from the southern to the northern hemisphere.  $\\Omega$ is undefined for equatorial orbits.   \\\\\r\n  %\r\n  $\\nu$ & true anomaly & The true anomaly is defined as the angle between a vector pointing at periapsis, $\\mathbf{x}_p$, and a vector pointing at the spacecraft.\r\n  The true anomaly is undefined for circular orbits. \\\\\r\n  \\hline\\hline \\label{Table:ModKeplerianElements}\r\n\\end{tabular}\r\n\\end{table*}\r\n\r\n\r\n\\noindent Given:  $a$, $e$, $i$, $\\omega$, $\\Omega$, and $\\nu$, or\r\n$\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$\r\n\r\n\\noindent Find:  $r_p$ and $r_a$\r\n\r\nIf we are given the Cartesian state, we first calculate the\r\norbital elements using the algorithm in Sec. \\ref{Sec:Kep2Cart}.\r\nKnowing the Keplerian elements, we calculate $r_a$ and $r_p$ using\r\n%\r\n\\begin{equation}\r\n     r_a = a(1+e)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     r_p = a(1-e)\r\n\\end{equation}\r\n\r\nNow let's look at the inverse transformation.\r\n\r\n\\subsection{Modified Keplerian Elements to Keplerian Elements} \\index{Modified\r\nKeplerian elements!to Keplerian}   \\index{Keplerian elements!from\r\nmodified Keplerian}\r\n\r\nThe conversion from modified Keplerian elements to the Keplerian\r\nelements is discussed below.  To perform the conversion, we use\r\nrelationships that allow us to write the semimajor axis, $a$, and\r\nthe eccentricity, $e$, in terms of $r_a$ and $r_p$.\r\n\r\n\\noindent Given:  $r_p$, $r_a$, $i$, $\\omega$, $\\Omega$, and $\\nu$\r\n\r\n\\noindent Find:  $a$ and $e$\r\n\r\nWe begin by calculating the eccentricity using\r\n%\r\n\\begin{equation}\r\n    e = \\frac{1 - \\displaystyle\\frac{r_p}{r_a}}{1 + \\displaystyle\\frac{r_p}{r_a}}\r\n\\end{equation}\r\n%\r\nThe semimajor axis is calculated using\r\n%\r\n\\begin{equation}\r\n    a = \\displaystyle\\frac{r_p}{1 - e}\r\n\\end{equation}\r\n\r\nThis concludes our discussion of state transformations. In the\r\nlast few subsections we presented the algorithms used to convert\r\nbetween different orbit state representations used in GMAT.  These\r\ninclude the Cartesian state, the Keplerian elements, the modified\r\nKeplerian elements, and two spherical state parameterizations.  In\r\nthe next section, we present the algorithms used to calculate\r\n properties such as orbit period, beta angle, and mean motion to\r\n name a few.\r\n\r\n\\section{Simple Parameters}\r\n\r\nSimple parameters, which we will abbreviate as simply ``parameters\",\r\nare properties of spacecraft or other objects that are only\r\ndependent upon one of the following:  CoordinateSystem, CentralBody,\r\nor None.  An example of a simple parameter is the magnitude of a\r\nspacecrafts velocity vector.  The spacecrafts velocity vector is\r\ndependent upon the coordinate system in which it is expressed.  Once\r\nwe have specified a coordinate system, it is trivial to calculate\r\nthe velocity vector, and therefore its magnitude, in that coordinate\r\nsystem.\r\n\r\nIn GMAT, the syntax to specify a simple parameter is\r\n\r\n\\st{ObjectName.Dependency.ParameterName}\r\n\r\n\\noindent So, to calculate the magnitude of the velocity, of a\r\nspacecraft named \\st{Sat}, in the Earth Fixed frame, we would use\r\n\r\n\\st{Sat.EarthFixed.VMAG}\r\n\r\n\\noindent GMAT has the ability to calculate many parameters in\r\naddition to \\st{VMAG}.  In the following subsections, we present the\r\nalgorithms used to calculate all parameters in GMAT.  We begin each\r\nsubsection with a description of the parameter, and then give the\r\ntype of dependency.\r\n\r\n\\subsection{A1Gregorian} \\index{A1Gregorian}\r\n\r\n\\noindent \\textit{Description}: \\st{A1Gregorian} is the epoch of an\r\nobject, in the A1 time system, given in the Gregorian date format.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\nThe A1 date, in modified Julian date format is the current\r\nindependent variable for time in GMAT.  Therefore, it is not\r\nnecessary to convert the date to another system for this parameter.\r\nThe only calculation  required for this parameter is to use the\r\nalgorithm in Sec. \\ref{Sec:GregorianData} to convert from Modified\r\nJulian date format to Gregorian date format.\r\n\r\n\\subsection{A1ModJulian} \\index{A1ModJulian}\r\n\r\n\\noindent \\textit{Description}: \\st{A1ModJulian} is the epoch of an\r\nobject, in the A1 time system, given in the modified Julian date\r\nformat.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\nThe A1 date, in modified Julian date format is the current\r\nindependent variable for time in GMAT.  There are no calculations\r\nrequired for this parameter.\r\n\r\n\\subsection{Altitude} \\index{Altitude}\r\n\r\n\\noindent \\textit{Description}: \\st{Altitude} is the distance\r\nbetween a spacecraft and a plane tangent to the surface of the body\r\nat the sub-satellite point.  GMAT assumes the body is an ellipsoid.\r\nThe equatorial radius, and properties of the ellipsoid depend upon\r\nthe particular body chosen by the user.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ in $\\mathcal{F}_1$\r\n\r\n\\noindent Find:  $A$\r\n\r\n\\noindent Definitions:\r\n\\begin{itemize}\r\n     %\r\n     \\item $\\mathcal{F}_1$ is the coordinate system in which GMAT originally knows $\\mathbf{r}$\r\n     %\r\n     \\item $\\mathcal{F}_F$ is body fixed system of the central body selected by the user.\r\n     %\r\n     \\item $f$ is the bodies flattening coefficient\r\n     %\r\n     \\item $R$ is the bodies mean equatorial radius\r\n     %\r\n    % \\item $\\phi_{gc}$ is the geocentric latitude of the spacecraft\r\n     %in the body fixed frame.\r\n     %\r\n     \\item $\\phi_{gd}$ is the geodedic latitude of the spacecraft\r\n     in the body fixed frame.\r\n     %\r\n     \\item $h$ is the \\st{Altitude} parameter\r\n     %\r\n\\end{itemize}\r\n\r\nFirst we calculate $\\phi_{gd}$ using the algorithm in Sec.\r\n\\ref{Sec:Latitude}.  However, to calculate $h$, GMAT does not\r\nconvert to degrees, or use the modulo function.\r\n\r\nThen, with $\\mathbf{r}$ expressed in $\\mathcal{F}_F$, we perform\r\n%\r\n\\begin{equation}\r\n     r_{xy} = \\sqrt{ x^2 + y^2 }\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    e^2 = 2f-f^2\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n            h =   \\frac{ r_{xy}}{ \\cos(\\phi_{gd})} - \\frac{R} { \\sqrt{ 1 - e^2  \\sin^{2}{ \\phi_{gd} } } };\r\n\\end{equation}\r\n\r\n\\subsection{AOP} \\index{AOP}\r\n\r\n\\noindent \\textit{Description}: \\st{AOP} is the argument of\r\nperiapsis of a spacecraft.  The argument of periapsis is the angle\r\nbetween the eccentricity vector and a vector in the direction of the\r\nright ascension of the ascending node.  See below for treatment of\r\ncircular and equatorial orbits.  This algorithm is adopted from\r\nVallado\\cite{vallado2}.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ and $\\mathbf{v}$\r\n\r\n\\noindent Find:  $\\omega$\r\n\\[\r\nr = \\| \\mathbf{r} \\|\r\n\\]\r\n%\r\n\\[\r\nv = \\| \\mathbf{v} \\|\r\n\\]\r\n%\r\n\\[\r\n    \\mathbf{e} = \\displaystyle\\frac{\\left( v^2 - \\displaystyle\\frac{\\mu}{r}  \\right)\\mathbf{r} - (\\mathbf{r} \\cdot \\mathbf{v})\\mathbf{v}}{\\mu}\r\n\\]\r\n%\r\n\\[\r\n   e = \\| \\mathbf{e} \\|\r\n\\]\r\n%\r\n\\textit{Special Case:   Circular Orbit}\\\\\r\nif $ e < 10^{-11}$  then, $\\omega = 0.0$ and return.\r\n\r\n\r\n\\noindent Otherwise continue,\r\n%\r\n\\[ \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v} \\]\r\n%\r\n\\[ h = \\| \\mathbf{h} \\| \\]\r\n%\r\n\\[ i = \\cos^{-1}{\\left(\\frac{h_z}{h}  \\right)}\\]\r\n\r\n\\noindent \\textit{Special Case:  Elliptic, Equatorial Orbit}\\\\\r\nif $ i < 10^{-11}$ then,\r\n%\r\n\\begin{equation}\r\n    \\omega = \\cos^{-1}\\left(\\frac{e_x}{e}  \\right)\r\n\\end{equation}\r\n%\r\nwhere $e_x$ is the first component of the eccentricity vector.\\\\\r\nFix quadrant for $\\omega $: if $e_y < 0$, then $\\omega = 2\\pi -\r\n\\omega$\r\n\r\n\\noindent Otherwise continue\r\n\r\n\\noindent \\textit{Special Case:  Elliptic, Inclined Orbit}\\\\\r\n%\r\n\\[ \\mathbf{n} = [\\hspace{.05 in}0 \\hspace{.1 in} 0 \\hspace{.1 in} 1 \\hspace{.05 in}]^T \\times \\mathbf{h} \\]\r\n%\r\n\\[ \\omega = \\cos^{-1}\\frac{\\mathbf{n}\\cdot \\mathbf{e}}{\\| \\mathbf{n}\\|\\|\r\n\\mathbf{e}\\|}\\]\r\n%\r\nFix quadrant for $\\omega $: if $e_z < 0$, then $\\omega = 2\\pi -\r\n\\omega$. \\\\Finally, $\\omega$ is converted to degrees.\r\n%\r\n\\subsection{Apoapsis} \\index{Apoapsis}\r\n\r\n\\noindent \\textit{Description}: \\st{Apoapsis} is the parameter used\r\nin stopping conditions to allow the stopping condition algorithm to\r\nlocate the time when a spacecraft is at apoapsis. Apoapsis is\r\ndefined as a point, along an orbital path, when the component of\r\nvelocity, in the spacecraft position vector direction, changes from\r\npositive to negative.  The \\st{Apoapsis} parameter is defined as the\r\ndot product of the position and velocity vectors.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ in $\\mathcal{F}_1$\r\n\r\n\\noindent Find:  $A$\r\n\r\n\\noindent Definitions:\r\n%\r\n\\begin{itemize}\r\n     %\r\n     \\item $\\mathcal{F}_1$ is the coordinate system in which GMAT originally knows $\\mathbf{r}$ and $\\mathbf{v}$\r\n     %\r\n     \\item $\\mathcal{F}_2$ is a system with the MJ2000Eq axes, centered at the central body selected by the user.\r\n     %\r\n     \\item $A$ is the \\st{Apoapsis} parameter\r\n     %\r\n\\end{itemize}\r\n%\r\n\r\nif ($\\mathcal{F}_1 \\neq \\mathcal{F}_2)$ convert $\\mathbf{r}$ and\r\n$\\mathbf{v}$ to $\\mathcal{F}_2$.  Then,\r\n%\r\n\\begin{equation}\r\n     A = \\mathbf{r} \\cdot \\mathbf{v}\r\n\\end{equation}\r\n\r\n\\subsection{AZI} \\index{AZI}\r\n\r\n\\noindent \\textit{Description}: \\st{AZI} is the azimuth angle of a\r\nspacecraft, as shown in Fig. \\ref{fig:KeplerianElements} using the\r\nsymbol $\\alpha_f$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ and $\\mathcal{F}$\r\n\r\n\\noindent Find:  $\\alpha_f$\r\n\r\n\r\nAZI is calculated using the algorithm shown in Sec.\r\n\\ref{Sec:CarttoSphericalAZFPA}.  There is little benefit using a\r\nroutine that calculates only $\\alpha_f$ and not $\\psi$.\r\n\r\n\\subsection{BdotT and BdotR} \\index{BdotT} \\index{BdotR}\r\n\r\n\\noindent \\textit{Description}: The ``B\" vector, $\\mathbf{B}$, is\r\nonly defined for hyperbolic orbits and is the vector from the center\r\nof mass of the central body, to the incoming hyperoblic asysmptote,\r\nsuch that the length of $\\mathbf{B}$ is a minimum. Another way to\r\nsay this is that $\\mathbf{B}$ is perpendicular to the incoming\r\nasymptote.   Let's define $\\mathbf{S}$ as a unit vector in the\r\ndirection of the incoming asymptote.  Then, $\\mathbf{T}$ is a unit\r\nvector perpendicular to $\\mathbf{S}$, that lies in the $xy$-plane of\r\nthe coordinate system, $\\mathcal{F}_B$, chosen by the user.\r\n$\\mathbf{R}$ is a unit vector perpendicular to both $\\mathbf{S}$ and\r\n$\\mathbf{T}$. Finally, \\st{BdotT} is the dot product of $\\mathbf{B}$\r\nand $\\mathbf{T}$, and \\st{BdotR} is the dot product of $\\mathbf{B}$\r\nand $\\mathbf{R}$. The method below was adopted from work by\r\nKizner\\cite{Kizner:59}.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and definition of\r\n$\\mathcal{F}_B$\r\n\r\n\\noindent Find:  $B_R$ and $B_T$\r\n\r\n\\noindent Definitions:\r\n\\begin{itemize}\r\n     %\r\n     \\item $\\mathcal{F}_1$ is the coordinate system in which GMAT originally knows\r\n     $\\mathbf{r}$ and $\\mathbf{v}$\r\n     %\r\n     \\item $\\mathcal{F}_B$ is the coordinate system in which to perform B-plane\r\n     calculations.  GMAT will place $\\mathbf{T}$ in the $xy$-plane\r\n     of  $\\mathcal{F}_B$.  $\\mathcal{F}_B$ must have a gravitational\r\n     body at its origin.\r\n     %\r\n     \\item $\\mu$ is the gravitational parameter of the central body\r\n     at the origin of $\\mathcal{F}_B$\r\n     %\r\n     \\item $B_R$ is the dot product of $\\mathbf{B}$ and\r\n     $\\mathbf{R}$\r\n     %\r\n     \\item $B_T$ is the dot product of $\\mathbf{B}$ and\r\n     $\\mathbf{T}$\r\n\\end{itemize}\r\n\r\n\r\n\r\nif the selected coordinate system does not have a celestial body as\r\nits origin, then exit and throw an error message.\\\\\r\n%\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,200)(55,340)\r\n        \\includegraphics[scale=1]{Images/BPlaneGeometry1.eps}\r\n    \\makebox(-520,845){$\\theta_B$}\r\n    \\makebox(-615,820){$\\mathbf{R}$}\r\n    \\makebox(-500,810){$\\mathbf{B}$}\r\n    \\makebox(-560,890){$\\mathbf{T}$}\r\n    \\makebox(-760,920){$xy$-plane of $\\mathcal{F}_B$ }\r\n    \\makebox(-720,990){Central Body}\r\n    \\makebox(-570,1030){$z$-axis of $\\mathcal{F}_B$}\r\n    \\makebox(-580,760){$\\mathbf{B}\\cdot\\mathbf{T}$}\r\n    \\makebox(-485,830){$\\mathbf{B}\\cdot\\mathbf{R}$}\r\n    \\end{picture}\r\n    \\caption{Geometry of the B-Plane as Seen From a Viewpoint Perpendicular to the B-Plane}\r\n    \\label{fig:BPlaneGeometry1}\r\n\\end{figure}\r\n%\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,240)(125,340)\r\n        \\includegraphics[scale=1]{Images/BPlaneGeometry2.eps}\r\n    \\makebox(-420,850){$\\mathbf{B}$}\r\n    \\makebox(-580,990){Central Body}\r\n    \\makebox(-570,850){Incoming Trajectory}\r\n    \\makebox(-570,760){Incoming}\r\n    \\makebox(-570,740){Asymptote}\r\n    \\end{picture}\r\n    \\caption{The B-Vector as Seen From a Viewpoint Perpendicular to Orbit Plane}\r\n    \\label{fig:BPlaneGeometry2}\r\n\\end{figure}\r\n\r\n\\noindent if $\\mathcal{F}_1 \\neq \\mathcal{F}_B$ convert $\\mathbf{r}$\r\nand $\\mathbf{v}$ from $\\mathcal{F}_1$ to $\\mathcal{F}_B$\r\n\r\n\\[\r\nr = \\| \\mathbf{r} \\|\r\n\\]\r\n%\r\n\\[\r\nv = \\| \\mathbf{v} \\|\r\n\\]\r\n%\r\nCalculate eccentricity related information\r\n%\r\n\\[\r\n    \\mathbf{e} = \\displaystyle\\frac{\\left( v^2 - \\displaystyle\\frac{\\mu}{r}  \\right)\\mathbf{r} - (\\mathbf{r} \\cdot \\mathbf{v})\\mathbf{v}}{\\mu}\r\n\\]\r\n%\r\n\\[\r\n   e = \\| \\mathbf{e} \\|\r\n\\]\r\n%\r\n\\[\r\n\\hat{\\mathbf{e}} = \\frac{\\mathbf{e}}{e}\r\n\\]\r\n%\r\nIf $e\\leq 1$, then the method fails and returns.\r\n\r\nNow let's calculate the angular momentum and orbit normal vectors.\r\n%\r\n\\[\r\n\\mathbf{h} = \\mathbf{r}\\times \\mathbf{v}\r\n\\]\r\n%\r\n\\[\r\nh = \\| \\mathbf{r}\\times \\mathbf{v} \\|\r\n\\]\r\n%\r\n\\[\r\n\\hat{\\mathbf{h}} = \\frac{\\mathbf{h}}{h}\r\n\\]\r\n\r\nA unit vector normal to both the eccentricity vector and the orbit\r\nnormal vector is defined as:\r\n%\r\n\\[\r\n   \\hat{\\mathbf{n}} = \\hat{\\mathbf{h}} \\times \\hat{\\mathbf{e}}\r\n\\]\r\nThe following relations are only true for hyperbolic orbits: The\r\nsemiminor axis, $b$, can be calculated using\r\n%\r\n\\[\r\n   b = \\frac{h^2}{\\mu \\sqrt{e^2 - 1}}\r\n\\]\r\n%\r\nThe incoming asymptote is defined using\r\n%\r\n\\[\r\n   \\mathbf{S} =  \\frac{\\hat{\\mathbf{e}} }{e} + \\sqrt{1 - \\left(\\frac{1}{e}\\right)^2\r\n   }\\hat{\\mathbf{n}}\r\n\\]\r\n%\r\nThe B-vector, $\\mathbf{B}$, is calculated using\r\n%\r\n\\[\r\n   \\mathbf{B} = b \\left(\\sqrt{1 - \\left(\\frac{1}{e}\\right)^2 }\\hat{\\mathbf{e}}  - \\frac{1}{e} \\hat{\\mathbf{n}} \\right)\r\n\\]\r\n%\r\nThe remaining vectors, $\\mathbf{T}$ and $\\mathbf{R}$ are found using\r\n%\r\n\\[\r\n   \\mathbf{T} = \\frac{[\\hspace{.03 in} S_y \\hspace{.1 in} -S_x  \\hspace{.1 in} 0 \\hspace{.03 in}]^T }{\\sqrt{S_x^2 + S_y^2}}\r\n\\]\r\n%\r\n\\[\r\n   \\mathbf{R} = \\mathbf{S} \\times \\mathbf{T}\r\n\\]\r\n%\r\nFinally, the desired quantities are found using\r\n%\r\n\\[\r\n   B_T = \\mathbf{B} \\cdot \\mathbf{T}\r\n\\]\r\n%\r\n\\[\r\n   B_R = \\mathbf{B} \\cdot \\mathbf{R}\r\n\\]\r\n\r\n\r\n\r\n\\noindent if  $\\mathcal{F}_1 \\neq \\mathcal{F}_2$ , convert\r\n$\\mathbf{r}$ and $\\mathbf{v}$ to $\\mathcal{F}_2$\r\n%\r\n\\begin{equation}\r\n    A = \\mathbf{r}\\cdot\\mathbf{v}\r\n\\end{equation}\r\n\r\n\\subsection{BetaAngle} \\index{BetaAngle}\r\n\r\nDefinition:  The Beta angle, $\\beta$, is defined as the angle\r\nbetween the orbit normal vector, and the vector from the celestial\r\nbody to the sun.\r\n\r\n\\[\r\n   \\hat{\\mathbf{h}} = \\frac{  \\mathbf{r}_\\oplus \\times \\mathbf{v}_\\oplus  }{\\|\\mathbf{r}_\\oplus \\times \\mathbf{v}_\\oplus \\|}\r\n\\]\r\n%\r\n\\[\r\n\\hat{\\mathbf{r}}_{s \\oplus} = \\frac{\\mathbf{r}_{s \\oplus}}{\\|_{s\r\n\\oplus }  \\|}\r\n\\]\r\n%\r\n\\begin{equation}\r\n  \\beta = \\sin^{-1}\\left(\\hat{\\mathbf{h}}\\cdot \\hat{\\mathbf{r}}_{s\\oplus } \\right)\r\n\\end{equation}\r\n\r\n\\begin{itemize}\r\n     \\item $\\mathbf{r}_\\oplus$:  Position vector of spacecraft\r\n     with respect to celestial body, in the EarthMJ2000Eq system.\r\n\r\n     \\item $\\mathbf{v}_\\oplus$:  Velocity vector of spacecraft\r\n     with respect to celestial body, in the EarthMJ2000Eq system.\r\n\r\n     \\item $\\mathbf{r}_{s\\oplus}$:  Position vector from celestial\r\n     body, to the sun.\r\n\\end{itemize}\r\n\r\n\\subsection{BVectorAngle and BVectorMag} \\index{BVectorAngle}\r\n\\index{BVectorMag}\r\n\r\nTo avoid code reduplication, the magnitude and angle of the B\r\nvector, $\\|\\mathbf{B}\\|$ and  $\\theta_B$ respectively,  are\r\ncalculated from the outputs of the B-Plane coordinates algorithm.\r\nThe equations for $\\|\\mathbf{B}\\|$ and $\\theta_B$ are\r\n%\r\n\\begin{equation}\r\n    \\|\\mathbf{B}\\| = \\sqrt{ B_T^2 + B_R^2}\r\n\\end{equation}\r\n%\r\n%\r\n\\begin{equation}\r\n     \\theta_B = \\tan^{-1}{\\frac{B_R}{B_T}}\r\n\\end{equation}\r\n%\r\nwhich is implemented using $atan2( B_R , B_T )$\r\n\r\n\\subsection{C3Energy}\\index{Spacecraft properties!C3Energy}\r\n\\index{C3Energy}\r\n\r\nGiven:  $a$, and $\\mu$\r\n\r\n\\noindent Find:  $C_3$\r\n\r\n\\begin{equation}\r\n    C_3 = -\\frac{\\mu}{a}\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ is calculated from the satellite\r\ncartesian state as shown in Section \\ref{Sec:Cart2Kep}, and $\\mu$ is\r\nassociated with the specified central body.\r\n\r\n\\subsection{DEC} \\index{DEC}\r\n\r\n\\noindent \\textit{Description}: \\st{DEC} is the declination of a\r\nspacecraft, as shown in Fig. \\ref{fig:SphericalElements} using the\r\nsymbol $\\delta$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ and $\\mathcal{F}$\r\n\r\n\\noindent Find:  $\\delta$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\delta = \\sin^{-1}(\\frac{z}{r})\r\n\\end{equation}\r\n\r\n\\subsection{DECV} \\index{DECV}\r\n\r\n\\noindent \\textit{Description}: \\st{DECV} is the declination of\r\nvelocity of a spacecraft.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ and $\\mathcal{F}$\r\n\r\n\\noindent Find:  $\\delta_v$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n       \\delta_v = \\sin^{-1}(\\frac{v_z}{v})\r\n\\end{equation}\r\n\r\n\\subsection{ECC} \\index{ECC}\r\n\r\n\\noindent \\textit{Description}: \\st{ECC} is the eccentricity  of an\r\norbit and must be greater than or equal to zero. The eccentricity\r\ncontains information on the shape of an orbit. If ECC is zero then\r\nthe orbit is circular.  If ECC is greater than zero, but less than\r\none, the orbit is elliptic. If ECC equals one, the orbit is\r\nparabolic. Finally, if ECC is greater than one, the orbit is\r\nhyperbolic.  The algorithm used in GMAT to calculate SMA is adopted\r\nfrom Vallado\\cite{vallado2}.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$ (Central\r\nBody)\r\n\r\n\\noindent Find:  $e$\r\n\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{e} = \\displaystyle\\frac{(v^2 - \\displaystyle\\frac{\\mu}{r} )\\mathbf{r}\r\n     - (\\mathbf{r}\\cdot\\mathbf{v}  )\\mathbf{v}}{\\mu} \\label{Eq:EccentricityVector}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     e = \\| \\mathbf{e} \\|\r\n\\end{equation}\r\n\r\n\\subsection{FPA} \\index{FPA}\r\n\r\n\\noindent \\textit{Description}: \\st{FPA} is the orbit vertical\r\nFlight Path Angle as as shown in Fig. \\ref{fig:SphericalElements}\r\nusing the symbol $\\psi$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and coordinate system\r\n$\\mathcal{F}$.\r\n\r\n\\noindent Find:  $\\psi$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n    \\psi = \\cos^{-1}\\left(  \\frac{\\mathbf{r} \\cdot \\mathbf{v} }{r v} \\right)\r\n\\end{equation}\r\n%\r\n\r\n\\subsection{EA} \\label{sec:EccentricAnomaly}\r\n\\index{EA}\r\n\r\nGiven: $\\nu$, $e$\r\n\r\n\\noindent Find:  $E$\\\\\r\n%\r\n\r\n\\noindent If e $>$ ( 1 - $1e^{-11}$ ) then $E = 0$, return.\\\\\r\n%\r\n\r\n\r\n\\noindent Otherwise,\r\n%\r\n\\begin{eqnarray}\r\n    \\sin(E) & = & \\frac{\\sqrt{1 - e^2} \\sin(\\nu)}{1+e \\cos{\\nu}}    \\\\    %Vallado pg. 213,  Eq. 4-9\r\n    %\r\n    \\cos(E) & = & \\frac{ e + \\cos{\\nu} }{1+e \\cos{\\nu}}   \\\\     %Vallado pg. 213,  Eq. 4-9\r\n    %\r\n    E & = & \\mbox{atan2}(\\sin{E},\\cos{E})\r\n\\end{eqnarray}\r\n%\r\n\r\n\\subsection{Energy}\\index{Spacecraft properties!Energy}\r\n\\index{Energy}\r\n\r\n\\noindent \\textit{Description}: \\st{Energy} is the orbit energy.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and central body.\r\n\r\n\\noindent Find:  $\\xi$\r\n\r\nBegin by converting $\\mathbf{r}$ and $\\mathbf{v}$ to a coordinate\r\nsystem with the origin equal to the central body defined by the\r\nuser, and the MJ2000Eq axis system.  Then,\r\n%\r\n\\begin{equation}\r\n     r = \\mathbf{r}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     v = \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\xi = \\frac{v^2}{2} - \\frac{\\mu}{r}\r\n\\end{equation}\r\n\r\n\r\n\\subsection{HMAG} \\index{HMAG}\r\n\r\n\\noindent \\textit{Description}: \\st{HMAG} is the magnitude of the\r\norbit angular momentum.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and central body.\r\n\r\n\\noindent Find:  $h$\r\n\r\nBegin by converting $\\mathbf{r}$ and $\\mathbf{v}$ to a coordinate\r\nsystem with the origin equal to the central body defined by the\r\nuser, and the MJ2000Eq axis system.  Then,\r\n%\r\n\\begin{equation}\r\n    \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    h = \\| \\mathbf{h} \\|\r\n\\end{equation}\r\n\r\n\\subsection{HX,HY, and HZ} \\index{HX} \\index{HY} \\index{HZ}\r\n\r\n\\noindent \\textit{Description}: \\st{HX,HY,} and \\st{HZ} are the\r\ncomponents of the orbit angular momentum vector.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and coordinate system\r\n$\\mathcal{F}$.\r\n\r\n\\noindent Find:  $h_x$, $h_y$, and $h_z$\r\n\r\nBegin by converting $\\mathbf{r}$ and $\\mathbf{v}$ to $\\mathcal{F}$\r\nif necessary. Then,\r\n%\r\n\\begin{equation}\r\n    \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v} = [\\hspace{.05 in} h_x\r\n    \\hspace{.1 in} h_y \\hspace{.1 in} h_z \\hspace{.05 in} ]^T\r\n\\end{equation}\r\n\r\n\r\n\\subsection{HA}  \\label{sec:HyperbolicAnomaly}\r\n\\index{HA}\r\n\r\n\\noindent \\textit{Description}: \\st{HA} is the orbit Hyperbolic\r\nAnomaly and is only defined for hyperbolic orbits.  For\r\nnon-hyperbolic orbits, \\st{HA} returns a value of zero.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n Given: $\\nu$, $e$\r\n\r\n\\noindent Find:  $H$\\\\\r\n%\r\n\r\n\\noindent If e $<$ ( 1 + $1e^{-11}$ ) then $H = 0$, return.\\\\\r\n%\r\n\r\n\r\n\\noindent Otherwise,\r\n%\r\n\\begin{eqnarray}\r\n    \\sinh(H) & = & \\frac{ \\sin(\\nu) \\sqrt{e^2 - 1}}{1+e \\cos{\\nu}}    \\\\    %Vallado pg. 213,  Eq. 4-9\r\n    %\r\n    H & = & \\mbox{asinh}(\\sinh(H))\r\n\\end{eqnarray}\r\n%\r\n\r\n\\subsection{INC} \\index{INC}\r\n\r\n\\noindent \\textit{Description}: \\st{INC} is the inclination of an\r\norbit in the chosen coordinate system.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and coordinate system\r\n$mathcal{F}$.\r\n\r\n\\noindent Find:  $e$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n     \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n      h  = \\mathbf{h}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     i = \\cos^{-1}( \\frac{h_z}{h} )\r\n\\end{equation}\r\n\r\n\r\n\\subsection{Latitude} \\label{Sec:Latitude} \\index{Latitude}\r\n\r\n\\noindent \\textit{Description}: \\st{Latitude} is the geodetic\r\nlatitude of a spacecraft.  The geodedic latitude is defined as the\r\nthe angle $\\phi_{gc}$, as shown in Fig. ( ),  where the\r\nsub-satellite point is defined by the interscection of a line drawn\r\nfrom the spacecraft and perpendicular to a plane tangent to the\r\nsurface of the body. GMAT assumes the body is an ellipsoid. The\r\nequatorial radius, and properties of the ellipsoid depend upon the\r\nparticular body chosen by the user.  The algorithm in GMAT is taken\r\nfrom Vallado\\cite{vallado2}.\r\n\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,200)(75,320)\r\n        \\includegraphics[scale=1]{Images/GeodeticDiagram.eps}\r\n    \\makebox(-575,880){$h$}\r\n    \\makebox(-640,680){$\\phi_{gd}$}\r\n    \\makebox(-730,670){$\\phi_{gc}$}\r\n    \\end{picture}\r\n    \\caption{Geocentric and Geodetic Latitude}\r\n    \\label{fig:GeodeticDiagram}\r\n\\end{figure}\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ in $\\mathcal{F}_1$\r\n\r\n\\noindent Find:  $\\phi_{gc}$\r\n\r\n\\noindent Definitions:\r\n\\begin{itemize}\r\n     %\r\n     \\item $\\mathcal{F}_1$ is the coordinate system in which GMAT originally knows $\\mathbf{r}$\r\n     %\r\n     \\item $\\mathcal{F}_F$ is body fixed system of the central body selected by the user.\r\n     %\r\n     \\item $f$ is the bodies flattening coefficient\r\n     %\r\n     \\item $R$ is the bodies mean equatorial radius\r\n     %\r\n     \\item $\\phi_{gd}$ is the geodedic latitude of the spacecraft\r\n     in the body fixed frame.\r\n     %\r\n\\end{itemize}\r\n%\r\nif $\\mathcal{F}_1 \\neq \\mathcal{F}_F$ convert $\\mathbf{r}$ from\r\n$\\mathcal{F}_1$ to $\\mathcal{F}_F$. Then,\r\n%\r\n\\begin{equation}\r\n     r_{xy} = \\sqrt{ x^2 + y^2 }\r\n\\end{equation}\r\n%\r\nCalculate the geocentric latitude to use as an initial guess to find\r\nthe geodetic latitude\r\n%\r\n\\begin{equation}\r\n     \\phi_{gd}  \\approx \\mbox{atan2}(z,  r_{xy}  );\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    e^2 = 2f-f^2\r\n\\end{equation}\r\n%\r\n\r\n\\noindent Set $\\delta = 1.0$ to initialize the loop, then,\r\n\r\n\r\n\\noindent While ( $\\delta > 10^{-7}$ )\r\n%\r\n\\begin{eqnarray}\r\n   \\phi' & = & \\phi_{gd}\\\\\r\n   %c & = & \\frac{R} { \\sqrt{1 - e^2\\sin{\\phi}}    }\\\\\r\n   \\phi_{gd} & = & \\mbox{atan2}\\left(z +  \\frac{Re^2\\sin^{2}{\\phi_{gd}}} { \\sqrt{1 - e^2\\sin{\\phi_{gd}}} }, r_{xy}\r\n   \\right)\\\\\r\n   \\delta & = & | \\phi_{gd} - \\phi' |\r\n\\end{eqnarray}\r\n%\r\nEndWhile\\\\\r\n%\r\n\r\nAfter convergence, $\\phi_{gd}$ is converted to degrees, and\r\nconverted to fall between $-90^\\circ$ and   $+90^\\circ$ degrees.\r\n\r\n\\subsection{Longitude} \\label{Sec:CalcObjectLongitude}\r\n\\index{Longitude}\r\n\r\n\\noindent \\textit{Description}: \\st{Longitude} is the longitude of\r\nan object, in the body fixed frame of the central body chosen by the\r\nuser.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, central body.\r\n\r\n\\noindent Find:  $\\phi$\r\n\r\nBegin by converting $\\mathbf{r}$ to the body fixed system of the\r\ncentral body defined by the user. Then,\r\n%\r\n\\begin{equation}\r\n    \\phi = \\tan_2^{-1}(y,x);\r\n\\end{equation}\r\n%\r\nThe calculation is completed by converting to degrees and setting\r\nthe value to such that $-180 \\leq \\phi < 180$.\r\n\r\n\\subsection{LST} \\index{LST}\r\n\r\n\\noindent \\textit{Description}: \\st{LST} is the local sidereal time\r\nof an object, with respect to the selected central body.  The local\r\nsidereal time is the sum of the longitude in the bodies fixed frame,\r\nand the mean sidereal time.  This is illustrated in Fig.\r\n\\ref{fig:SiderealTimeDiagram}, where $\\mathcal{F}_I$ is the body's\r\nequatorial inertial system (as described in Sec. \\ref{Sec:Equator}),\r\n$\\mathcal{F}_F$ is the body's fixed system (as described in Sec.\r\n\\ref{Sec:Fixed}).  $\\lambda$ is the longitude of the object, in this\r\ncase a spacecraft, and $\\theta_{MST}$ is the mean sidereal time of\r\nthe prime meridian.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $t_i$ (epoch of spacecraft in\r\ninternal time system), and central body\r\n\r\n\\noindent Find:  $\\theta_{LST}$\r\n\r\n\\noindent Definitions:\r\n\\begin{itemize}\r\n     %\r\n     \\item $\\mathcal{F}_I$ equatorial inertial system (as described in Sec. \\ref{Sec:Equator}) of selected central\r\n     body.\r\n     %\r\n     \\item $\\mathcal{F}_F$ is the central body's fixed system (as described in Sec. \\ref{Sec:Fixed})\r\n     %\r\n     \\item $\\lambda$ is the longitude of the object in $\\mathcal{F}_F$\r\n     %\r\n     \\item $\\theta_{MST}$ is the mean sidereal time of the central body's  prime meridian.\r\n     %\r\n     \\item $t_i$ (epoch of spacecraft in internal time system)\r\n\\end{itemize}\r\n\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,230)(55,460)\r\n        \\includegraphics[scale=1]{Images/SiderealTimeDiagram.eps}\r\n    \\makebox(-350,1066){$\\hat{\\mathbf{x}}_I$}\r\n    \\makebox(-380,1277){$\\hat{\\mathbf{x}}_F$}\r\n    \\makebox(-617,1330){$\\hat{\\mathbf{y}}_I$}\r\n    \\makebox(-800,1240){$\\hat{\\mathbf{y}}_F$}\r\n    \\makebox(-575,1059){$\\theta_{MST}$}\r\n    \\makebox(-600,1120){$\\lambda$}\r\n    \\makebox(-580,1220){$\\theta_{LST}$}\r\n    \\makebox(-425,1125){$\\theta_{MHA}$}\r\n    \\end{picture}\r\n    \\caption{Local Sidereal Time Geometry}\r\n    \\label{fig:SiderealTimeDiagram}\r\n\\end{figure}\r\n\r\nWe begin by calculating $\\lambda$ using the algorithm described in\r\nSec. \\ref{Sec:CalcObjectLongitude}.  The mean sidereal time\r\n$\\theta_{MST}$ is calculated differently for Earth than for other\r\ncentral bodies.  If the central body is Earth, then we use the\r\nfollowing equations to calculate $\\theta_{MST}$.\r\n\r\nFirst, convert $t_i$, which is the spacecraft epoch in the interal\r\ntime system (A1 Modified Julian Date), to $T_{UT1}$, which is the\r\nnumber elapsed Julian centuries from the J2000 epoch.\r\n%\r\n\\begin{equation}\r\n    T_{UT1} = \\frac{t_{ut1} - 21544.5}{36525}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\\begin{split}\r\n    \\theta_{MST} =  & 67310.54841^s + \\\\ &( 876600^h \\left( \\frac{3600 s}{1h}\\right) + 8640184.812866)T_{UT1} + \\\\& 0.093104T_{UT1}^2 - 6.2\\times10^{-6}T_{UT1}^3\r\n    \\end{split}\r\n\\end{equation}\r\n\r\n\\subsection{MA} \\index{MA}\r\n\r\nGiven: $\\nu$, $e$\r\n\r\n\\noindent Find:  $M$\r\n\r\n\\noindent If e $<$ ( 1 - $1e^{-11}$ ) then calculate $E$ using\r\nalgorithm in Sec. \\ref{sec:EccentricAnomaly}.  Then $M$ is\r\ncalculated using\r\n%\r\n\\begin{equation}\r\n     M = E - e \\sin{E}\r\n\\end{equation}\r\n%\r\nNote: $E$ must be expressed in radians in the above equation, and\r\nresults in $M$ in radians.\r\n\r\n\\noindent If e $>$ ( 1 + $1e^{-11}$ ) then calculate $H$ using\r\nalgorithm in Sec. \\ref{sec:HyperbolicAnomaly}.  Then $M$ is\r\ncalculated using\r\n%\r\n\\begin{equation}\r\n     M =  e \\sinh{H} - H\r\n\\end{equation}\r\n%\r\nNote: $H$ must be expressed in radians in the above equation, and\r\nresults in $M$ in radians.  GMAT outputs \\st{MA} in degrees.\r\n\r\n\\noindent If neither of the above conditions are satisfied, $M = 0$,\r\nand output ``Warning:  Orbit is near parabolic in mean anomaly\r\ncalculation. Setting MA = 0\".\r\n\r\n\\subsection{MHA}\r\n\r\n\\subsection{MM}\\index{Spacecraft properties!mean motion}\r\n\\index{MM}\r\n\r\nGiven:  $a$, $e$, and $\\mu$\r\n\r\n\\noindent Find:  $n$\r\n\r\n\\noindent The orbit is considered either circular or elliptic ( both\r\norbit types use the same equation to calculate $n$) if $ e < 1 -\r\n1e^{-11}$. In this case the mean motion, $n$, is calculated using\r\n%\r\n\\begin{equation}\r\n    n = \\sqrt{\\frac{\\mu}{a^3}}\r\n\\end{equation}\r\n%\r\nThe orbit is considered hyperbolic if $ e > 1 + 1e^{-11}$.  In this\r\ncase the mean motion, $n$, is calculated using\r\n%\r\n\\begin{equation}\r\n    n =  \\sqrt{-\\frac{\\mu}{a^3}}\r\n\\end{equation}\r\n%\r\nIf neither of the above two conditions are met, the mean motion is\r\ncalculated using\r\n%\r\n%\r\n\\begin{equation}\r\n    n =  2\\sqrt{\\mu}\r\n\\end{equation}\r\n%\r\n\r\n\\noindent \\textit{Comment}:  $a$ and $e$ are calculated from the\r\nsatellite cartesian state as shown in Section \\ref{Sec:Cart2Kep},\r\nand $\\mu$ is associated with the specified central body.\r\n\r\n\r\n\\subsection{OrbitPeriod}\\index{Spacecraft properties!OrbitPeriod}\r\n\\index{OrbitPeriod}\r\n\r\nGiven:  $a$, and $\\mu$\r\n\r\n\\noindent Find:  $T$\r\n\r\n\\noindent If a $ < 0$,  then $T = 0$, return.\\\\\r\n%\r\n\r\n\r\n\\noindent Otherwise,\r\n\\begin{equation}\r\n    T = 2\\pi\\sqrt{\\frac{a^3}{\\mu}}\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ is calculated from the satellite\r\ncartesian state as shown in Section \\ref{Sec:Cart2Kep}, and $\\mu$ is\r\nassociated with the specified central body.\r\n\r\n\\subsection{PercentShadow } \\label{sec:PercentShadow}\r\n\\index{PercentShadow}\r\n\r\nThe \\st{PercentShadow} parameter calculates the percentage of the\r\napparent solar disk that is in view from the perspective of a\r\nspacecraft. The algorithm used in GMAT was adapted from\r\nMontenbruck\\cite{Montenbruck:Gill:05} pgs. 80-83.\r\n\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,220)(65,275)\r\n        \\includegraphics[scale=1]{Images/ShadowGeometry.eps}\r\n    \\makebox(-520,850){$\\mathbf{r}_B$}\r\n    \\makebox(-460,750){$\\mathbf{r}_\\odot$}\r\n    \\makebox(-690,800){$\\mathbf{r}$}\r\n     \\makebox(-620,940){$\\mathbf{s}$}\r\n     \\makebox(-450,890){$\\mathbf{s}_\\odot$}\r\n    \\end{picture}\r\n    \\caption{Shadow Geometry}\r\n    \\label{fig:ShadowGeometry}\r\n\\end{figure}\r\n%\r\n\\begin{itemize}\r\n    \\item $R_\\odot$ = Radius of the Sun\r\n    \\item $R_B$ = Radius of occulting body\r\n    \\item $R'_\\odot$ = Apparent radius of the Sun\r\n    \\item $R'_B$ = Apparent radius of occulting body\r\n    \\item $\\mathbf{r}_\\odot$ = Vector from central body to Sun\r\n    \\item $\\mathbf{r}_B$ = Vector from central body to occulting body\r\n    \\item $\\mathbf{r}$ = Vector from central body to s/c\r\n\\end{itemize}\r\n%\r\n\r\nWe begin by calculating the vector from the occulting body to the\r\nspacecraft, $\\mathbf{s}$, using\r\n%\r\n\\begin{equation}\r\n     \\mathbf{s} = \\mathbf{r} - \\mathbf{r}_B\r\n\\end{equation}\r\n%\r\nand the vector from the occulting body to the sun,\r\n$\\mathbf{s}_\\odot$, using\r\n%\r\n\\begin{equation}\r\n     \\mathbf{s}_\\odot = \\mathbf{r}_\\odot - \\mathbf{r}_B\r\n\\end{equation}\r\n%\r\n(Note that when the occulting body is the same as the central body,\r\n$\\mathbf{s} = \\mathbf{r}$, and $\\mathbf{s}_\\odot =\r\n\\mathbf{r}_\\odot$)\r\n\r\nNext we calculate the apparent radius of the Sun and occulting body\r\nusing\r\n%\r\n\\begin{eqnarray}\r\n     R'_\\odot & = & \\sin^{-1}\\frac{R_\\odot}{\\|\\mathbf{r}_\\odot - \\mathbf{r} \\|}\\\\\r\n     R'_B & = & \\sin^{-1}\\frac{R_B}{\\|\\mathbf{r}  - \\mathbf{r}_B\\|}\r\n\\end{eqnarray}\r\n%\r\nWe can calculate the apparent separation of the two bodies, $D'$,\r\nusing\r\n%\r\n\\begin{equation}\r\n    D' = \\cos^{-1}\\left(\\frac{-\\mathbf{s}^T\\left( \\mathbf{r}_\\odot - \\mathbf{r} \\right)}{s \\|\\mathbf{r}_\\odot - \\mathbf{r}\r\n    \\|}\\right)\r\n\\end{equation}\r\n%\r\n\r\nIf $ D' \\geq R'_\\odot + R'_B $, then the spacecraft is not in the\r\nbody's shadow and\r\n%\r\n\\begin{equation}\r\n    p = 0;\r\n\\end{equation}\r\n%\r\n\r\nIf $D' \\leq R'_B - R'_\\odot$, then the spacecraft is in full shadow\r\nand\r\n%\r\n\\begin{equation}\r\n    p = 100;\r\n\\end{equation}\r\n%\r\n\r\nIf neither of the above conditions are met, the spacecraft is in\r\npartial shadow.\r\n%\r\n\\begin{figure}[htb]\r\n    \\begin{picture}(100,135)(35,355)\r\n        \\includegraphics[scale=1]{Images/ShadowIllustration.ps}\r\n            \\makebox(-650,895){$R'_B$}\r\n            \\makebox(-550,870){$R'_\\odot$}\r\n            \\makebox(-670,820){$D'$}\r\n            \\makebox(-560,750){Sun}\r\n            \\makebox(-720,765){Occulting Body}\r\n    \\end{picture}\r\n    \\caption{Occultation Geometry in Calculation of PercentShadow}\r\n    \\label{fig:ShadowIllustration}\r\n\\end{figure}\r\n%\r\n\r\nIf $|R'_s - R'_B| < D' < R'_s + R'_B$, then we can calculate the\r\npercentage of shadow by calculating the area of overlap, $A$,  of\r\nthe two apparent disks as shown in Fig.\r\n\\ref{fig:ShadowIllustration}.\r\n%\r\n\\begin{equation}\r\n     A = R^{'\\mbox{} 2}_\\odot\\cos^{-1}\\left(\\frac{c_1}{R'_\\odot}\\right) +\r\n     R^{'\\mbox{} 2}_B\\cos^{-1}\\left(\\frac{D' - c_1}{R'_B}\\right) -\r\n     D'c_2\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n   c_1 = \\frac{ D^{'\\mbox{} 2} + R^{'\\mbox{} 2}_\\odot - R^{'\\mbox{} 2}_B }{2D'}\r\n\\end{equation}\r\n%\r\nand\r\n%\r\n\\begin{equation}\r\n   c_2 = \\sqrt{ R^{'\\mbox{} 2}_\\odot -  c_1^2 }\r\n\\end{equation}\r\n%\r\nThe percent  shadow can be calculated using\r\n%\r\n\\begin{equation}\r\n     p = 100 \\frac{A}{\\pi R^{'\\mbox{} 2}_\\odot}\r\n\\end{equation}\r\n\r\nIf the condition $|R'_\\odot - R'_B| < D' < R'_\\odot + R'_B$ is not\r\nsatisfied, then the eclipse is annular and we use\r\n%\r\n\\begin{equation}\r\n     p = 100   \\frac{R^{'\\mbox{} 2}_B}{R^{'\\mbox{} 2}_\\odot}\r\n\\end{equation}\r\n\r\n\r\n\\subsection{RA}\\index{RA}\r\n\r\n\\noindent \\textit{Description}: \\st{RA} is the right ascension of a\r\nspacecraft, as shown in Fig. \\ref{fig:SphericalElements} using the\r\nsymbol $\\lambda$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ and $\\mathcal{F}$\r\n\r\n\\noindent Find:  $\\lambda$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n    \\lambda= \\tan^{-1}_2(y,x)\r\n\\end{equation}\r\n\r\n\\subsection{RAV} \\index{RAV}\r\n\r\n\\noindent \\textit{Description}: \\st{RAV} is the right ascension of\r\nvelocity of a spacecraft, as shown in Fig.\r\n\\ref{fig:SphericalElements} using the symbol $\\lambda_v$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$ and $\\mathcal{F}$\r\n\r\n\\noindent Find:  $\\lambda_v$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n    \\lambda_v= \\tan^{-1}_2(v_y,v_x)\r\n\\end{equation}\r\n\r\n\r\n\\subsection{RAAN} \\index{RAAN}\r\n\r\n\\noindent \\textit{Description}: \\st{RAAN} is the right ascension of\r\nthe ascending node as shown in Fig. \\ref{fig:KeplerianElements}\r\nusing the symbol $\\Omega$.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and coordinate system\r\n$\\mathcal{F}$.\r\n\r\n\\noindent Find:  $e$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%First calculate the specific angular momentum and its magnitude.\r\n\\begin{equation}\r\n     \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     h = \\|\\mathbf{h} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{n} = [ \\hspace{0.05 in} 0 \\hspace{0.1 in} 0 \\hspace{0.1 in} 1 \\hspace{0.05\r\n     in}]^T \\times \\mathbf{h}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     n = \\| n\\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     i = \\cos^{-1}\\left(\\frac{h_z}{h}\\right)\r\n\\end{equation}\r\n%\r\n\r\n\r\n\\noindent if  $(i \\geq 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\Omega = \\cos^{-1}\\left(\\frac{n_x}{n}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\Omega$: if $n_y < 0$, then $\\Omega = 2\\pi -\r\n\\Omega$\r\n\r\n\r\n\\noindent if  $(i < 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\Omega = 0\r\n\\end{equation}\r\n\r\n\r\n\\subsection{RadApo}\\index{Spacecraft properties!RadApo}\r\n\\index{RadApo}\r\n\r\nGiven:  $a$, and $e$\r\n\r\n\\noindent Find:  $r_a$\r\n\r\n\\noindent  if $ 1 - e  < 10^{-12}$  then $r_a = 0$.  Note, this\r\nmeans that for parabolica, and hyperbolic orbits, GMAT outputs a\r\nvalue of zero for \\st{RadApo}.\r\n%\r\n\\noindent Otherwise,\r\n%\r\n\\begin{equation}\r\n    r_a = a(1+e)\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ and $e$ are calculated from the\r\nsatellite cartesian state as shown in Section \\ref{Sec:Cart2Kep}.\r\n\r\n\\subsection{RadPer}\\index{Spacecraft properties!RadPer}\r\n\\index{RadPer}\r\n\r\nGiven:  $a$, and $e$\r\n\r\n\\noindent Find:  $r_p$\r\n\r\n\\begin{equation}\r\n    r_p = a(1-e)\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ and $e$ are calculated from the\r\nsatellite cartesian state as shown in Section \\ref{Sec:Cart2Kep}.\r\n\r\n\\subsection{RLA and DLA} \\index{RLA} \\index{DLA}\r\n\r\n\\noindent \\textit{Description}: \\st{RLA} ($\\lambda_s$) is the right ascenstion of the outgoing\r\nasypmptote of a hyperbolic trajectory.  \\st{DLA} ($\\delta_s$)is the declination of the outgoing\r\nasypmptote of a hyperbolic trajectory.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ and $\\mathbf{v}$ and desired coordinate system.\r\n\r\n\\noindent Find:  $\\lambda_s$ and $\\delta_s$\r\n\r\nBegin by converting $\\mathbf{r}$ and $\\mathbf{v}$ to the desired coordinate system (an excpeption\r\nis thrown if the origin of the requested coordinate system is not a celestial body).\r\nThe eccentricity vector $\\mathbf{e}$ is computed using Eq.~(\\ref{Eq:EccentricityVector}).\r\nIf $\\|\\mathbf{e}\\| < 1 + tol$ then RLA = DLA = NaN and return. Otherwise:\r\n%\r\n\\begin{equation}\r\n    \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    h = \\| \\mathbf{h} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   C_3 = v^2 - \\frac{2\\mu}{r}\r\n\\end{equation}\r\n%\r\nwhere $\\mu$ is gravitational parameter of the central body at the origin of the given coordinate system.   The outgoing asmympote unit vector, $\\hat{\\mathbf{s}} $, is computed using\r\n%\r\n\\begin{equation}\r\n   \\hat{\\mathbf{s}} = \\frac{1}{ 1 + C_3 \\displaystyle\\left(\\frac{h}{\\mu}\\right)^2}\\left(   \\frac{\\sqrt{C_3}}{\\mu} \\left(\\mathbf{h} \\times \\mathbf{e} \\right) - \\mathbf{e} \\right)\r\n\\end{equation}\r\n%\r\nRLA and DLA are computed from\r\n%\r\n\\begin{equation}\r\n    \\lambda_s = \\tan^{-1}(s_y,s_x)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    \\delta_s = \\sin^{-1}(s_z)\r\n\\end{equation}\r\n\r\n\\subsection{RMAG} \\index{RMAG}\r\n\r\n\\noindent \\textit{Description}: \\st{RMAG} is the magnitude of the\r\nspacecraft's position vector.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$ and central body.\r\n\r\n\\noindent Find:  $r$\r\n\r\nBegin by converting $\\mathbf{r}$  to a coordinate system with the\r\norigin equal to the central body defined by the user, and the\r\nMJ2000Eq axis system.  Then,\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n\r\n\\subsection{SemilatusRectum} \\index{SemilatusRectum}\r\n\r\n\\noindent \\textit{Description}: \\st{SemilatusRectum} is the orbit\r\nsemilatus rectum, which is the magnitude of the position vector,\r\nwhen at true anomaly of $90^{\\circ}$.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$ (central\r\nbody).\r\n\r\n\\noindent Find:  $p$\r\n\r\nBegin by converting $\\mathbf{r}$ and $\\mathbf{v}$ to a coordinate\r\nsystem with the origin equal to the central body defined by the\r\nuser, and the MJ2000Eq axis system.  Then,\r\n%\r\n\\begin{equation}\r\n    \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    h = \\| \\mathbf{h} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    p = \\frac{h^2}{\\mu}\r\n\\end{equation}\r\n\r\n\r\n\\subsection{SMA} \\index{SMA}\r\n\r\n\\noindent \\textit{Description}: \\st{SMA} is the semimajor axis  of\r\nan orbit. The SMA contains information on the size and type of an\r\norbit.  If the SMA is positive, the orbit is elliptic.  If the SMA\r\nis negative the orbit is hyperbolic.  The SMA is undefined for\r\nparabolic orbits. The algorithm used in GMAT to calculate SMA is\r\nadopted from Vallado\\cite{vallado2}.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and $\\mu$ (Central\r\nBody)\r\n\r\n\\noindent Find:  $a$\r\n\r\n\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\xi = \\frac{v^2}{2} - \\frac{\\mu}{r}\r\n\\end{equation}\r\n%\r\nif $|1 - e| > 10^{-30}$, then\r\n\\begin{equation}\r\n     a = -\\frac{\\mu}{2\\xi}\r\n\\end{equation}\r\n%\r\notherwise, report  error and return.  Error: ``Warning: Orbit is\r\nnear parabolic and SMA is undefined\".\r\n\r\n\\subsection{TA} \\index{TA}\r\n\r\n\\noindent \\textit{Description}: \\st{TA} is the orbit true anomaly as\r\nshown in Fig. \\ref{fig:KeplerianElements} using the symbol $\\nu$.\r\n\r\n\\noindent \\textit{Dependency}:  Central Body.\r\n\r\n\\noindent Given:  $\\mathbf{r}$, $\\mathbf{v}$, and coordinate system\r\n$\\mathcal{F}$.\r\n\r\n\\noindent Find:  $\\nu$\r\n\r\nBegin by converting  $\\mathbf{r}$ and $\\mathbf{v}$ to  $\\mathcal{F}$\r\nif necessary.  Then,\r\n%First calculate the specific angular momentum and its magnitude.\r\n\\begin{equation}\r\n     \\mathbf{h} = \\mathbf{r} \\times \\mathbf{v}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     h = \\|\\mathbf{h} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{n} = [ \\hspace{0.05 in} 0 \\hspace{0.1 in} 0 \\hspace{0.1 in} 1 \\hspace{0.05\r\n     in}]^T \\times \\mathbf{h}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     n = \\| n\\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    r = \\| \\mathbf{r} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\mathbf{e} = \\displaystyle\\frac{(v^2 - \\displaystyle\\frac{\\mu}{r} )\\mathbf{r} - (\\mathbf{r}\\cdot\\mathbf{v}  )\\mathbf{v}}{\\mu}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     e = \\| \\mathbf{e} \\|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     i = \\cos^{-1}\\left(\\frac{h_z}{h}\\right)\r\n\\end{equation}\r\n%\r\nThere are three special cases, and they are treated differently.\r\n\r\n\\noindent\\textit{Special Case 1:  Elliptic Orbit  }\r\n\r\n\\noindent if $(e \\geq 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{\\mathbf{e}\\cdot\\mathbf{r}}{er}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu $:  if $\\mathbf{r} \\cdot \\mathbf{v} < 0$, then\r\n$\\nu = 2\\pi - \\nu$\r\n\r\n\\noindent\\textit{Special Case 2:  Circular, Inclined Orbit  }\r\n\r\n\\noindent if $(e < 10^{-11})$  and $(i \\geq 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{\\mathbf{n}\\cdot\\mathbf{r}}{nr}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu$:  if $r_z < 0$, then $\\nu = 2\\pi - \\nu$\r\n\r\n\\noindent\\textit{Special Case 3:  Circular, Equatorial Orbit  }\r\n\r\n\\noindent if $(e < 10^{-11})$  and $(i < 10^{-11})$, then\r\n%\r\n\\begin{equation}\r\n    \\nu = \\cos^{-1}\\left( \\frac{r_x}{r}\\right)\r\n\\end{equation}\r\n%\r\nFix quadrant for $\\nu$:  if $r_y < 0$, then $\\nu = 2\\pi - \\nu$\r\n%\r\n\r\n\\subsection{TAIModJulian}\\label{Sec:TAIModJulian}\\index{TAIModJulian}\r\n\r\n\\noindent \\textit{Description}: \\st{TAIModJulian} is the epoch in\r\nthe TAI time system, expressed in the modified Julian date format.\r\nSee Sec. \\ref{Sec:AtomicTime} and \\ref{Sec:JDFormat} for more\r\ndetails.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\n\\noindent Given:  $A1$ (epoch in the internal, A1 time system).\r\n\r\n\\noindent Find:  $TAI$\r\n\r\nTo convert from A1 to TAI we use the following equation\r\n%\r\n\\begin{equation}\r\n     TAI = A1 - 0.0343817 \\mbox{sec}\r\n\\end{equation}\r\n\r\n\\subsection{TTModJulian}\\label{Sec:TTModJulian}\\index{TTModJulian}\r\n\r\n\\noindent \\textit{Description}: \\st{TTModJulian} is the epoch in\r\nthe TT time system, expressed in the modified Julian date format.\r\nSee Sec. \\ref{Sec:DynamicTime} and \\ref{Sec:JDFormat} for more\r\ndetails.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\n\\noindent Given:  $A1$ (epoch in the internal, A1 time system).\r\n\r\n\\noindent Find:  $TT$\r\n\r\nTo convert from A1 to TT we use the following equation\r\n%\r\n\\begin{equation}\r\n     TT = A1 - 0.0343817 \\mbox{sec} + 32.184 \\mbox{sec}\r\n     \\label{Eq:TTModJulian}\r\n\\end{equation}\r\n\r\n\\subsection{TTGregorian}\\label{Sec:TTGregorian}\\index{TTGregorian}\r\n\r\n\\noindent \\textit{Description}: \\st{TTGregorian} is the epoch in\r\nthe TT time system, expressed in the Gregorian date format. See\r\nSec. \\ref{Sec:DynamicTime} and \\ref{Sec:GregorianDateFormat} for\r\nmore details.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\n\\noindent Given:  $A1$ (epoch in the internal, A1 time system).\r\n\r\n\\noindent Find:  $TT$\r\n\r\nTo convert from A1 to TT we use Eq.~(\\ref{Eq:TTModJulian}).  Then,\r\nknowing the epoch in the TT time system in the modified Julian\r\ndate format, we use the algorithm in Sec. \\ref{Sec:JDFormat} to\r\nobtain the Gregorian date.\r\n\r\n\r\n\\subsection{Umbra and Penumbra } \\index{Umbra} \\index{Penumbra}\r\n\r\nThe Umbra and Penumbra parameters are used to determine if a\r\nspacecraft is in the shadow of a celestial body.  The algorithm used\r\nin GMAT is adapted from Montenbruck\\cite{Montenbruck:Gill:05} pgs.\r\n80-81.  For both functions, if the value is less than 1, then the\r\nbody is in shadow, if the function is greater than 1, then the body\r\nis not in shadow.\r\n%\r\n\\begin{figure*}[htb]\r\n\\index{Shadow!Umbra}\\index{Shadow!Penumbra} \\centerline{\r\n\\begin{picture}(200,420)\r\n\\special{psfile=Images/UmbraPenumbraGeom.eps hoffset= -235 voffset=\r\n-180 hscale=105 vscale=105}\\makebox(-40,535){$\\alpha_p$}\r\n\\makebox(580,550){$\\alpha_u$} \\makebox(-640,770){Penumbra (Annular\r\nEclipse)} \\makebox(-950,800){Umbra (Total Eclipse)}\r\n\\makebox(-1140,780){ Penumbra } \\makebox(-970,590){ $s$\r\n}\\makebox(-870,610){ $d$ } \\makebox(-995,655){ $\\ell$ }\r\n\\end{picture}}\\vskip -3.25 in  \\caption{ Geometry of Umbra and Penumbra Regions} \\label{fig:UmbraPenumbraGeom}\r\n\\end{figure*}\r\n\r\nFor definitions of see Sec. \\ref{sec:PercentShadow}.\r\n%\r\n\\begin{equation}\r\n    \\ell = \\frac{-\\mathbf{s}^T\\mathbf{s}_\\odot}{s_\\odot}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n    d = \\sqrt{ s^2 - l^2 }\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\sin{\\alpha_p} = \\frac{R_\\odot + R_B}{s_\\odot}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\sin{\\alpha_u} = \\frac{R_\\odot - R_B}{s_\\odot}\r\n\\end{equation}\r\n%\r\nThe radii of the umbra and penumbra cones, $r_p$ and $r_u$, at\r\ndistance $\\ell$, are respectively\r\n%\r\n\\begin{equation}\r\n     r_p = \\tan{\\alpha_p}\\left( \\ell +\r\n     \\frac{R_B}{\\sin{\\alpha_p}}\\right)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     r_u = \\tan{\\alpha_u}\\left( \\ell -\r\n     \\frac{R_B}{\\sin{\\alpha_u}}\\right)\r\n\\end{equation}\r\n%\r\nFinally, if $\\ell \\geq 0$\r\n%\r\n\\begin{equation}\r\n     d_p = d - r_p\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     d_u = d - |r_u|\r\n\\end{equation}\r\n%\r\nIf $\\ell > 0$ $d_u < 0$ and $r_u < 0$, then the object is in the\r\ntotal umbral\r\neclipse region.\\\\\r\n%\r\nIf $\\ell > 0$ $d_u < 0$ and $r_u \\geq 0$, then the object is in the\r\nannular umbral eclipse region.\\\\\r\n%\r\nIf $\\ell < 0$, then the object is on the day side of the occulting\r\nbody and is not in shadow and\r\n%\r\n\\begin{equation}\r\n     d_p = |d - r_p|\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     d_u = |d - |r_u||\r\n\\end{equation}\r\n%\r\n\r\n\\subsection{UTCModJulian} \\label{Sec:UTCModJulian}\\index{UTCModJulian}\r\n\r\n\\noindent \\textit{Description}: \\st{UTCModJulian} is the epoch in\r\nthe UTC time system, expressed in the modified Julian date format.\r\nSee Sec. \\ref{Sec:UniversalTime} and \\ref{Sec:JDFormat} for more\r\ndetails.\r\n\r\n\\noindent \\textit{Dependency}:  None.\r\n\r\n\\noindent Given:  $A1$ (epoch in the internal, A1 time system).\r\n\r\n\\noindent Find:  $UTC$\r\n\r\nTo convert from A1 to UTC we use the following equation\r\n%\r\n\\begin{equation}\r\n     UTC = A1 - 0.0343817 \\mbox{sec} - \\Delta AT\r\n\\end{equation}\r\n%\r\nThe default is to read $\\Delta AT$ from the file named\r\n\\textit{tai-utc.dat}. $\\Delta AT$ is the accumulated leap seconds\r\nsince Jan. 1961.\r\n\r\n\r\n\\subsection{VelApoapsis}\\index{Spacecraft properties!VelApoapsis}\r\n\\index{VelApoapsis}\r\n\r\nGiven:  $a$, $e$, and $\\mu$\r\n\r\n\\noindent Find:  $v_a$\r\n\r\n\\noindent If e $>$ ( 1 - $1e^{-12}$ ) then $v_a = 0$.\r\n%\r\n\r\n\\noindent Otherwise,\r\n%\r\n\\begin{equation}\r\n    v_a = \\sqrt{ \\frac{\\mu}{a} \\left(\\frac{1-e}{1+e}\\right)}\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ and $e$ are calculated from the\r\nsatellite cartesian state as shown in Section \\ref{Sec:Cart2Kep},\r\nand $\\mu$ is associated with the specified central body.\r\n\r\n\\subsection{VelPeriapsis} \\index{Spacecraft properties!VelPeriapsis}\r\n\\index{VelPeriapsis}\r\n\r\nGiven:  $a$, $e$, and $\\mu$\r\n\r\n\\noindent Find:  $v_p$\r\n\r\n\\begin{equation}\r\n    v_p = \\sqrt{ \\frac{\\mu}{a} \\left(\\frac{1+e}{1-e}\\right)}\r\n\\end{equation}\r\n\r\n\\noindent \\textit{Comment}:  $a$ and $e$ are calculated from the\r\nsatellite cartesian state as shown in Section \\ref{Sec:Cart2Kep},\r\nand $\\mu$ is associated with the specified central body.\r\n\r\n\\subsection{VMAG} \\index{VMAG}\r\n\r\n\\noindent \\textit{Description}: \\st{VMAG} is the magnitude of the\r\nspacecraft's velocity vector, when the velocity is expressed in the\r\nchosen coordinate system.\r\n\r\n\\noindent \\textit{Dependency}:  Coordinate System.\r\n\r\n\\noindent Given:  $\\mathbf{v}$ and coordinate system $\\mathcal{F}$.\r\n\r\n\\noindent Find:  $v$\r\n\r\nBegin by converting $\\mathbf{v}$  to coordinate system $\\mathcal{F}$\r\nif necessary.  Then,\r\n%\r\n\\begin{equation}\r\n    v = \\| \\mathbf{v} \\| = \\sqrt{v_x^2 + v_y^2 + v_z^2  }\r\n\\end{equation}\r\n%\r\n\r\n\\section{  Other Calculations }\r\n\r\n\\subsection{MA to TA}\r\n\r\n\\noindent \\textit{Description}: This algorithm shows how to\r\ncalculate $\\nu$ given $M$ and $e$ and is taken from\r\nVallado\\cite{vallado2}.\r\n\r\n\\noindent Given:  $M$ and $e$.\r\n\r\n\\noindent Find:  $\\nu$\r\n\r\nThe algorithm is different for elliptic and hyperbolic orbits. Let's\r\nfirst look at what happens for elliptic orbits.\r\n\r\n\\noindent\\textit{Elliptic Orbit Case}\r\n\r\n\\noindent If  $e <= 1$ then use the following algorithm:\r\n\r\n\\noindent Determine initial guess for the Eccentric anomaly\\\\\r\n\\noindent If ( - $\\pi < M < 0$ ) or $M > \\pi$\\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} E = M - e$ \\\\\r\n%\r\nElse\\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} E = M + e$ \\\\\r\n%\r\nEnd\r\n\r\n\\noindent Iterate to determine the eccentric anomaly:\\\\\r\n\r\n\r\n \\noindent Iterate On:  $E_{n+1} = E_{n} +\r\n\\displaystyle\\frac{M - E_n + e\\sin{E_n}}{1 -\r\ne\\cos{E_n}}$ \\\\\r\nUntil:  $| E_{n+1} - E_n | < 1e^{-8}$\r\n\r\n\\noindent Finally we convert the eccentric anomaly to the true\r\nanomaly using the algorithm given in sec. \\ref{Sec:EAtoTA}\r\n\r\n\\noindent \\textit{Hyperbolic Orbit Case}\r\n\r\n\\noindent If  $e > 1$ then use the following algorithm:\r\n\r\nWe begin by choosing the initial guess for the hyperbolic anomaly.\r\nThe initial guess depends on the value of the mean anomaly and the\r\neccentricity:\r\n\r\n\\noindent If $e < 1.6$\r\n\r\n\\begin{minipage}{2.0 in}\r\n\\noindent If ( - $\\pi < M < 0$ ) or $M > \\pi$\\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} H = M - e$ \\\\\r\n%\r\nElse\\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} H = M + e$ \\\\\r\n%\r\nEnd\r\n%\r\n\\end{minipage}\\\\\r\n\r\n\\noindent Else\r\n\r\n\\begin{minipage}{2.25 in}\r\n\\noindent If ($ e < 3.6$ \\& $|M|>\\pi$ ) \\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} H = M - \\mbox{sign}(M)e$ \\\\\r\n%\r\nElse\\\\\r\n%\r\n$\\mbox{}\\hspace{ .25 in} H = \\frac{M}{e-1}$ \\\\\r\n%\r\nEnd\r\n%\r\n\\end{minipage}\r\n\r\n\\noindent End\r\n\r\n\\noindent Iterate to determine the Hyperbolic Anomaly:\r\n\r\n\\noindent Iterate On: $H_{n+1} = H_{n} + \\displaystyle\\frac{M + H_n\r\n-\r\ne\\sinh{H}_n }{e\\cosh{H_n} - 1}$ \\\\\r\nUntil:  $| H_{n+1} - H_n | < 1e^{-8}$\r\n\r\n\\noindent Convert the hyperolic anomaly to the true anomaly using\r\nthe algorithm given in sec. \\ref{Sec:HAtoTA}\r\n\r\n\r\n\\subsection{EA to TA} \\label{Sec:EAtoTA}\r\n\r\n\\noindent \\textit{Description}: This algorithm shows how to\r\ncalculate $\\nu$ given $E$ and $e$ and is taken from\r\nVallado\\cite{vallado2}.\r\n\r\n\\noindent Given:  $E$ and $e$.\r\n\r\n\\noindent Find:  $\\nu$\r\n\r\n\\begin{equation}\r\n   \\sin{\\nu} = \\frac{\\sqrt{1 - e^2}\\sin(E)}{1-e\\cos{E}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\cos{\\nu} = \\frac{\\cos{E} - e}{ 1 - e\\cos{E} }\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\nu = \\mbox{atan2}(\\sin{\\nu},\\cos{\\nu})\r\n\\end{equation}\r\n\r\n\\subsection{HA to TA} \\label{Sec:HAtoTA}\r\n\r\n\\noindent \\textit{Description}: This algorithm shows how to\r\ncalculate $\\nu$ given $H$ and $e$ and is taken from\r\nVallado\\cite{vallado2}.\r\n\r\n\\noindent Given:  $H$ and $e$.\r\n\r\n\\noindent Find:  $\\nu$\r\n\r\n\\begin{equation}\r\n   \\sin{\\nu} = -\\frac{\\sqrt{e^2 - 1}\\sinh(H)}{1-e\\cosh{H}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\cos{\\nu} = \\frac{\\cosh{H} - e}{ 1 - e\\cosh{H} }\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\nu = \\mbox{atan2}(\\sin{\\nu},\\cos{\\nu})\r\n\\end{equation}\r\n\r\n\\section{  Libration Points } \\index{Libration Points}\r\n\r\nWe begin by assuming that the planets move in circular orbits about\r\nthe sun, and the mass of a spacecraft is negligible compared to the\r\nmass of the planets.  For illustrative purposes, lets consider the\r\nEarth and its orbit about the Sun.  In this case, the libration\r\npoints are locations in space where a spacecraft will stay fixed\r\nwith respect to the Earth and Sun.  Figure\r\n\\ref{fig:LibrationPointFig1} shows a simple illustration.  We see\r\nthe Sun, the Earth's position with respect to the Sun, and the\r\nLibration points $L_1$ and $L_2$ at two different epochs.  Notice\r\nthat at $t_1$, the points $L_1$ and $L_2$ are on the Earth-Sun line.\r\nAt a later time, $t_2$, although the Earth has moved with respect to\r\nthe sun, $L_1$ and $L_2$ still lie on the Earth-Sun line.\r\n%\r\n\\begin{figure*}[htb]\r\n\\index{Libration Points!Definition} \\centerline{\r\n\\begin{picture}(100,600)\r\n\\special{psfile=Images/LibrationDescription2.eps hoffset= -295\r\nvoffset= 45 hscale=105 vscale=105}\\makebox(390,1020){$\\mbox{Earth },\r\nL_1, L_2 \\mbox{ at } t_1$}  \\makebox(-480,1130){$\\mbox{Earth }, L_1,\r\nL_2 \\mbox{ at } t_2$}\r\n\\end{picture}}\\vskip -4.5 in  \\caption{ Geometry of Libration Points } \\label{fig:LibrationPointFig1}\r\n\\end{figure*}\r\n\r\n\r\nThe preceding example gives a brief qualitative description of two\r\nof the Earth-Sun libration points.  In general, there are five\r\nlibration points for a given three body system.  To determine the\r\nlocations of the libration points, it is convenient to work in a\r\nrotating coordinate system rather than the inertial system shown in\r\nFig. \\ref{fig:LibrationPointFig1}.  The system we use is constructed\r\nas follows:\r\n\r\n\\begin{itemize}\r\n\\item  Define the primary as the heavier of the two bodies, the\r\nsecondary as the lighter.\r\n\r\n\\item   Define the coordinate system x-axis as the axis pointing\r\nfrom the primary to the secondary.\r\n\r\n\\item  Define the y-axis to be orthogonal to the x-axis in the\r\nplane of the secondary's motion about the primary, pointing in the\r\ndirection the secondary moves about the primary.\r\n\r\n\\item   Define the z-axis orthogonal to the x and y axes to form a\r\nright-handed system.\r\n\r\n\\item Place the origin at center-of-mass of the system.\r\n\r\n\\end{itemize}\r\n\\begin{figure*}[htb]\r\n\\index{Libration Points!Definition} \\centerline{\r\n\\begin{picture}(100,555)\r\n\\special{psfile=Images/LibrationPointFig.eps hoffset= -235 voffset=\r\n-125 hscale=105 vscale=105}\\makebox(-60,820){$\\mu^*$}\r\n\\makebox(157,820){$1 - \\mu^*$} \\makebox(-50,920){$\\gamma_1$}\r\n\\makebox(50,920){$\\gamma_2$} \\makebox(-630,920){$\\gamma_3$}\r\n\\makebox(-695,850){$L3$}\\makebox(-220,850){$L1$}\r\n\\makebox(-20,850){$L2$} \\makebox(-340,640){$L4$}\r\n\\makebox(-350,1073){$L5$} \\makebox(-385,890){$x$}\r\n\\makebox(-485,997){$y$} \\makebox(-670,780){Primary}\r\n\\makebox(-100,780){Secondary}\r\n\\end{picture}}\\vskip -4.5 in  \\caption{ Location of Libration Points } \\label{fig:LibrationPointFig}\r\n\\end{figure*}\r\n\r\nThis coordinates system is illustrated in Fig.\r\n\\ref{fig:LibrationPointFig}.  The locations of the libration points\r\nin the rotating coordinate system can be found by calculating the\r\nvalues of $\\gamma$ that solve the following equations:\r\n%\r\n\\begin{eqnarray}\r\n\\begin{split}\r\n\\gamma _1^5  - \\left( {3 - \\mu^*} \\right)\\gamma _1^4 & + \\left( {3 -\r\n2\\mu^*} \\right)\\gamma _1^3  - \\mu^*\\gamma _1^2  \\\\ &+ 2\\mu^*\\gamma\r\n_1 - \\mu^*  = 0 \\hspace{.1 in} \\mbox{(For L1)} \\label{Eq:L1quintic}\r\n\\end{split}\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\r\n\\begin{split}\r\n \\gamma _2^5  + \\left( {3 - \\mu^*}\r\n\\right)\\gamma _2^4  & +  \\left( {3 - 2\\mu^*} \\right)\\gamma _2^3  -\r\n\\mu^*\\gamma _2^2  \\\\ &- 2\\mu^*\\gamma _2  - \\mu^*  = 0  \\hspace{.1\r\nin} \\mbox{(For L2)} \\label{Eq:L2quintic}\r\n\\end{split}\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\r\n\\begin{split}\r\n \\gamma _3^5  + & \\left( {2 + \\mu^*} \\right)\\gamma _3^4   + \\left(\r\n{1 + 2\\mu^*} \\right)\\gamma _3^3  - \\left( {1 - \\mu^*} \\right)\\gamma\r\n_3^2  \\\\ & - 2\\left( {1 - \\mu^*} \\right)\\gamma _3  - \\left( {1 -\r\n\\mu^*} \\right)  =  0 \\hspace{.1 in} \\mbox{(For L3)}\r\n\\label{Eq:L3quintic}\r\n\\end{split}\r\n\\end{eqnarray}\r\n%equations:\r\n%\\begin{eqnarray}\r\n%\\gamma _1^5  - \\left( {3 - \\mu^*} \\right)\\gamma _1^4 + \\left( {3 -\r\n%2\\mu^*} \\right)\\gamma _1^3  - \\mu^*\\gamma\r\n%_1^2  + 2\\mu^*\\gamma _1  - \\mu^* & = 0 \\hspace{.1 in} \\mbox{(For L1)}  \\label{Eq:L1quintic} \\\\\r\n%%\r\n% \\gamma _2^5  + \\left( {3 - \\mu^*}\r\n%\\right)\\gamma _2^4  + \\left( {3 - 2\\mu^*} \\right)\\gamma _2^3  -\r\n%\\mu^*\\gamma _2^2  - 2\\mu^*\\gamma _2  - \\mu^* & = 0  \\hspace{.1 in}\r\n%\\mbox{(For L2)} \\label{Eq:L2quintic}\r\n%\\\\\r\n%%\r\n% \\gamma _3^5  + \\left( {2 + \\mu^*}\r\n%\\right)\\gamma _3^4  + \\left( {1 + 2\\mu^*} \\right)\\gamma _3^3  -\r\n%\\left( {1 - \\mu^*} \\right)\\gamma _3^2  - 2\\left( {1 - \\mu^*}\r\n%\\right)\\gamma _3  - \\left( {1 - \\mu^*} \\right) & = 0 \\hspace{.1\r\n%in} \\mbox{(For L3)} \\label{Eq:L3quintic}\r\n%\\end{eqnarray}\r\n%%\r\nwhere\r\n%\r\n\\begin{equation}\r\n\\mu^* = \\frac{{m_2 }} {{m_1 +  m_2 }}\r\n\\end{equation}\r\n%\r\n\r\nEquations~(\\ref{Eq:L1quintic})-(\\ref{Eq:L3quintic})  do not have\r\nexact analytic solutions.%\r\n% Szebehely\\cite{Szebehely67} presents series solutions for\r\n%$\\gamma_1$ and $\\gamma_2$, and $\\gamma_3$.  The expansions for\r\n%$\\gamma_1$ and $\\gamma_2$ are:\r\n%%\r\n%\\begin{equation}\r\n%    \\gamma_1 = \\left(\\frac{\\mu}{3}\\right)^{1/3}  -\r\n%    \\frac{1}{3}\\left(\\frac{\\mu}{3}\\right)^{2/3}  -\r\n%    \\frac{1}{9}\\left(\\frac{\\mu}{3}\\right)^{1}  -\r\n%    \\frac{23}{81}\\left(\\frac{\\mu}{3}\\right)^{4/3} +\r\n%    \\frac{151}{243}\\left(\\frac{\\mu}{3}\\right)^{5/3} -\r\n%    \\frac{1}{9}\\left(\\frac{\\mu}{3}\\right)^{2}\r\n%\\end{equation}\r\n%%\r\n%\\begin{equation}\r\n%    \\gamma_2 = \\left(\\frac{\\mu}{3}\\right)^{1/3} +\r\n%    \\frac{1}{3}\\left(\\frac{\\mu}{3}\\right)^{2/3} -\r\n%    \\frac{1}{9}\\left(\\frac{\\mu}{3}\\right)^{1} -\r\n%    \\frac{31}{81}\\left(\\frac{\\mu}{3}\\right)^{4/3} -\r\n%    \\frac{119}{243}\\left(\\frac{\\mu}{3}\\right)^{5/3} -\r\n%    \\frac{1}{9}\\left(\\frac{\\mu}{3}\\right)^{2}\r\n%\\end{equation}\r\n%%\r\n%However,\r\nSzebehely\\cite{Szebehely67}  notes that they are most easily solved\r\nusing an iterative method with the following as the initial guesses:\r\n%\r\n\\begin{equation}\r\n\\gamma _1  = \\gamma _2  = \\left( {\\frac{\\mu^*} {{3\\left( {1 - \\mu^*}\r\n\\right)}}} \\right)^{{\\raise0.7ex\\hbox{$1$} \\!\\mathord{\\left/\r\n {\\vphantom {1 3}}\\right.\\kern-\\nulldelimiterspace}\r\n\\!\\lower0.7ex\\hbox{$3$}}}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n\\gamma _3  = 1\r\n\\end{equation}\r\n\r\nGMAT uses the Newton-Raphson method to solve for the roots of the\r\nequations by iterating on\r\n%\r\n\\begin{equation}\r\n   \\gamma(i+1) = \\gamma(i) - \\frac{F(\\gamma(i))}{F'(\\gamma(i))}\r\n\\end{equation}\r\n%\r\nuntil the the difference $|\\gamma(i+1) - \\gamma(i)| < 10^{-8}$. The\r\nderivative $F'(\\gamma)$ for each libration point is shown below.\r\n%\r\n\\begin{eqnarray}\\begin{split}\r\nF'(\\gamma) = 5\\gamma _1^4  - 4\\left( {3 - \\mu^*} \\right)&\\gamma _1^3\r\n+ 3\\left( {3 - 2\\mu^*} \\right)\\gamma _1^2\\\\&  - 2\\mu^*\\gamma\r\n_1  + 2\\mu^*    \\hspace{.1 in} \\mbox{(For L1)}   \\label{Eq:L1Deriv} \\\\\r\n\\end{split}\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\\begin{split}\r\nF'(\\gamma) = 5\\gamma _2^4  + 4\\left( {3 - \\mu^*} \\right)&\\gamma_2^3\r\n+ 3\\left( {3 - 2\\mu^*} \\right)\\gamma _2^2\\\\& - 2\\mu^*\\gamma _2  -\r\n2\\mu^* \\hspace{.1 in} \\mbox{(For L2)}\r\n \\label{Eq:L2Deriv}\\end{split}\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\\begin{split}\r\nF'(\\gamma) = 5\\gamma _3^4  &+ 4\\left( {2 + \\mu^*} \\right)\\gamma _3^3\r\n+ 3\\left( {1 + 2\\mu^*} \\right)\\gamma _3^2\\\\&  - 2\\left( {1 - \\mu^*}\r\n\\right)\\gamma _3  - 2\\left( {1 - \\mu^*} \\right) \\hspace{.1 in}\r\n\\mbox{(For L3)} \\label{Eq:L3Deriv}\\end{split}\r\n\\end{eqnarray}\r\n\r\n\\begin{table}[htb]\r\n\\centering \\caption{Location of Libration Points in RLP Frame, with\r\nthe Origin at the Primary Body} \\index{Libration Points!Location}\r\n\\begin{tabular}{ccc}\r\n   \\hline\\hline\r\n  % after \\\\: \\hline or \\cline{col1-col2} \\cline{col3-col4} ...\r\n  Point & $x$-Position & $y$-Position \\\\\r\n  \\hline\r\n  L1 & $1 - \\gamma_1$ & 0 \\\\\r\n  L2 & $1 + \\gamma_2$ & 0 \\\\\r\n  L3 & $-\\gamma_3$ & 0 \\\\\r\n  L4 & $1/2$ & $\\sqrt{3}/2$ \\\\\r\n  L5 & $1/2$ & -$\\sqrt{3}/2$ \\\\\r\n  \\hline\r\n  \\end{tabular}\r\n\\end{table}\r\n\r\nWe now need to redimensionalize the results found in the rotating\r\nsystem, and perform the necessary transformations to obtain the\r\nresults in the MJ2000 system.  Let's assume that $\\mathbf{r}_s$ ,\r\n$\\mathbf{v}_s$, and $\\mathbf{a}_s$ are the position, velocity, and\r\nacceleration vectors respectively of the secondary body, with\r\nrespect to the primary body, expressed in the FK5 system.  Then, the\r\nposition of the $i^{th}$ libration point can be expressed in the\r\nrotating system with the origin centered on the primary body as\r\n%\r\n\\begin{equation}\r\n     \\mathbf{r}^i = r_s\\left[x_i \\hspace{.2 in} y_i \\hspace{.2 in} 0 \\right]^T\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n    r_s = \\| \\mathbf{r}_s\\|\r\n\\end{equation}\r\n%\r\nThe velocity of the $i^{th}$ libration point can be expressed in the\r\nrotating system with the origin centered on the primary body as\r\n%\r\n\\begin{equation}\r\n     \\mathbf{v}^i = \\frac{\\mathbf{v}_s\\cdot\\mathbf{r}_s}{r_s}\\left[x_i \\hspace{.2 in} y_i \\hspace{.2 in} 0 \\right]^T\r\n\\end{equation}\r\n%\r\nNow we have the redimensionalized position and velocity vectors of\r\nthe libration point in the rotating coordinate system defined by the\r\nmotion of the secondary body with respect to the primary body. To\r\ndetermine the position and velocity vectors in the FK5 system, with\r\nthe origin located at the primary body, we need to determine the\r\nrotation matrix and its derivative as follows:\r\n%\r\n\\begin{equation}\r\n         \\mathbf{R}^{Ii} = \\begin{pmatrix}\r\n               \\hat{x}_1 & \\hat{y}_1  & \\hat{z}_1  \\\\\r\n               \\hat{x}_2 & \\hat{y}_2  & \\hat{z}_2  \\\\\r\n               \\hat{x}_3 & \\hat{y}_3  & \\hat{z}_3\r\n               \\label{Eq:RObjectReferenced}\r\n     \\end{pmatrix}\r\n\\end{equation}\r\nand\r\n\\begin{equation}\r\n         \\dot{\\mathbf{R}}^{Ii} = \\begin{pmatrix}\r\n               \\dot{\\hat{x}}_1 & \\dot{\\hat{y}}_1  & \\dot{\\hat{z}}_1  \\\\\r\n               \\dot{\\hat{x}}_2 & \\dot{\\hat{y}}_2  & \\dot{\\hat{z}}_2  \\\\\r\n               \\dot{\\hat{x}}_3 & \\dot{\\hat{y}}_3  & \\dot{\\hat{z}}_3\r\n               \\label{Eq:RdotObjectReferenced}\r\n     \\end{pmatrix}\r\n\\end{equation}\r\n%\r\nwhere\r\n%\r\n\\begin{equation}\r\n     \\hat{\\mathbf{x}} = \\frac{\\mathbf{r}_s}{r_s}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\hat{\\mathbf{z}} = \\frac{\\mathbf{r}_s\\times\\mathbf{v}_s}{\\| \\mathbf{r}_s\\times\\mathbf{v}_s \\|}\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\hat{\\mathbf{y}} = \\hat{\\mathbf{z}} \\times \\hat{\\mathbf{x}}\r\n\\end{equation}\r\n%\r\nand\r\n\\begin{equation}\r\n    \\dot{\\hat{\\mathbf{x}}} = \\dot{\\hat{\\mathbf{r}}}_s  = \\frac{\\mathbf{v}_s}{r_s}  -\r\n     \\frac{\\hat{\\mathbf{r}}_s}{r_s}\r\n     \\left(\\hat{\\mathbf{r}}_s \\cdot\r\n     \\mathbf{v}_s \\right)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\dot{\\hat{\\mathbf{z}}} =\\frac{\\mathbf{r}_s \\times \\mathbf{a}_s}{\\| \\mathbf{r}_s\\times\\mathbf{v}_s \\|} - \\frac{\\hat{\\mathbf{z}}}{\\| \\mathbf{r}_s\\times\\mathbf{v}_s \\|}\r\n      \\left(  \\mathbf{r}_s\\times\\mathbf{a}_s \\cdot \\hat{\\mathbf{z}} \\right)\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n     \\dot{\\hat{\\mathbf{y}}} = \\dot{\\hat{\\mathbf{z}}} \\times\r\n     \\hat{\\mathbf{x}} +\\hat{\\mathbf{z}} \\times\r\n     \\dot{\\hat{\\mathbf{x}}}\r\n\\end{equation}\r\n%\r\nGMAT currently assumes that the terms $\\mathbf{r}_s \\times\r\n\\mathbf{a}_s$ are zero.\r\n\r\n\r\n We finally arrive at the position of\r\nthe Libration Point in the FK5 system with the origin at the primary\r\nby performing the calculations:\r\n%\r\n\\begin{equation}\r\n   \\mathbf{r} = \\mathbf{R}^{Ii}\\mathbf{r}^i\r\n\\end{equation}\r\n%\r\n\\begin{equation}\r\n   \\mathbf{v} = \\dot{\\mathbf{R}}^{Ii}\\mathbf{r}^i + \\mathbf{R}^{Ii}\\mathbf{v}^i\r\n\\end{equation}\r\n%\r\n%Note that in  the GMAT script language, we can define this\r\n%coordinate system using\r\n%%\r\n%\\begin{quote}\r\n%\\begin{verbatim}\r\n%     Create CoordinateSystem CS;\r\n%     CS.Origin    = PrimaryBodyName;\r\n%     CS.Primary   = PrimaryBodyName;\r\n%     CS.Secondary = SecondaryBodyName;\r\n%     CS.XAxis = R;\r\n%     CS.ZAxis = N;\r\n%     \\end{verbatim}\r\n%\\end{quote}\r\n\\section{  Barycenter } \\index{Barycenter}\r\n\r\nThe barycenter of a system of point masses, $\\mathbf{r}_b$, is also\r\ncalled the center of mass.  If we have a system of $n$ bodies, and\r\nwe know the position of the $i^{th}$ body with respect to a common\r\nreference system, then we can calculate the barycenter of the system\r\nusing\r\n%\r\n\\begin{equation}\r\n     \\mathbf{r}_b = \\displaystyle\\frac{\\displaystyle\\sum_{i=1}^n m_i \\mathbf{r}_i}{\\displaystyle\\sum_{i=1}^n m_i}\r\n\\end{equation}\r\n%\r\nSimilarly, we can calculate the velocity of the barycenter using the\r\nfollowing equation\r\n%\r\n\\begin{equation}\r\n     \\mathbf{v}_b = \\displaystyle\\frac{\\displaystyle\\sum_{i=1}^n m_i \\mathbf{v}_i}{\\displaystyle\\sum_{i=1}^n m_i}\r\n\\end{equation}\r\n\r\n\\section{Ground Station Model}\r\n\r\nThis section contains algorithms for converting the station location\r\nparameters to body fixed and inertial cartesian coordinates. Ground\r\nstations are defined in the body fixed frame of the\r\n\\st{CentralBody}. The user can define the ground system location\r\nusing several methods.  GMAT internally uses the cartesian location\r\nof the ground station with respect to the body fixed coordinate\r\nsystem. If the user provides the ground station location in\r\ncartesian elements, no transformation is required to obtain the body\r\nfixed representation. For spherical elements with respect to the\r\nGeocentric reference, GMAT uses the following transformation to\r\ncalculate the cartesian station location in the body fixed frame,\r\n%\r\n\\begin{eqnarray}\r\n    \\mathbf{r}_F = \\left(\r\n        \\begin{array}{cc}\r\n          \\cos{\\phi}\\cos{\\lambda}\\\\\r\n          \\cos{\\phi}\\sin{\\lambda}\\\\\r\n          \\sin{\\phi}\r\n          \\end{array}\r\n          \\right)\r\n\\end{eqnarray}\r\n%\r\nIf the station location is defined in terms of the Geodetic\r\nreference, then the cartesian location is calculated as\r\nfollows\\cite{Vallado}:\r\n%\r\n\\begin{eqnarray}\r\n    C &=& \\displaystyle\\frac{R_b}{\\sqrt{1 - e_b^2\\sin^2{\\phi}}}\\\\\r\n%\r\n    S &=& C\\left(1 - e_b^2\\right)\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\r\n    r_{xy} &=& \\left( C + h_{e\\ell\\ell}\\right)\\cos{\\phi}\\\\\r\n%\r\n    r_{z} &=& \\left( S + h_{e\\ell\\ell}\\right)\\sin{\\phi}\r\n\\end{eqnarray}\r\n%\r\n\\begin{eqnarray}\r\n    \\mathbf{r}_F = \\left(\r\n        \\begin{array}{cc}\r\n          r_{xy}\\cos{\\lambda}\\\\\r\n          r_{xy}\\sin{\\lambda}\\\\\r\n          r_{z}\r\n          \\end{array}\r\n          \\right)\r\n\\end{eqnarray}\r\n%\r\nTo calculate the body-centered MJ2000Eq representation, we calculate\r\nthe rotation matrix from fixed to inertial, $\\mathbf{R}_{IF}$, using\r\nthe algorithm in Sec \\ref{Sec:Fixed} of the GMAT Mathematical\r\nSpecification. Then,\r\n%\r\n\\begin{equation}\r\n    \\mathbf{r}_I = \\mathbf{R}_{IF}\\mathbf{r}_F\r\n\\end{equation}\r\n", "meta": {"hexsha": "f339da3e099647bddc30cca8a3f5c666131b9113", "size": 106112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/CalculationObjects.tex", "max_stars_repo_name": "ddj116/gmat", "max_stars_repo_head_hexsha": "39673be967d856f14616462fb6473b27b21b149f", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-16T16:58:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-16T16:58:21.000Z", "max_issues_repo_path": "doc/SystemDocs/MathematicalSpecification/CalculationObjects.tex", "max_issues_repo_name": "ddj116/gmat", "max_issues_repo_head_hexsha": "39673be967d856f14616462fb6473b27b21b149f", "max_issues_repo_licenses": ["NASA-1.3"], "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/SystemDocs/MathematicalSpecification/CalculationObjects.tex", "max_forks_repo_name": "ddj116/gmat", "max_forks_repo_head_hexsha": "39673be967d856f14616462fb6473b27b21b149f", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1941747573, "max_line_length": 345, "alphanum_fraction": 0.6529987183, "num_tokens": 35184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6285279101610076}}
{"text": "\\section{Attitude} \\label{Ch:Attitude}\nThe attitude of a spacecraft can be defined qualitatively as how the spacecraft\nis oriented in inertial space, and how that orientation changes in time. GMAT\nhas the ability to model the orientation and rate of rotation of a spacecraft\nusing several different mathematical models.  Currently, GMAT assumes that a\nspacecraft is a rigid body.\n\nThere are many ways to quantitatively describe the orientation and rate of\nrotation of a spacecraft, just like there are many ways we can quantitatively\ndescribe an orbit state. Let's define any set of numbers that can uniquely\ndefine the spacecraft attitude as an \\emph{attitude parameterization}.  GMAT\nallows its users to employ several common attitude parameterizations including\nquaternions, Euler angles, the Direction Cosine Matrix (DCM) or Attitude Matrix\n\\textbf{A}, Euler angle rates, and the angular velocity vector. Given an initial\nattitude state, GMAT can propagate spacecraft attitude using one of several\nkinematic or dynamic attitude propagation models.\n\nOur notation will be based on a compromise that spans multiple disciplinary\nfields, from astrodynamics and aircraft flight simulation to computer graphics,\nand is informed by the AIAA and CCSDS standards.  We want a consistent\ndefinition in the inner core algorithms of GMAT combined with the capability of\ntranslating internal variables into interface variables that are easy for users\nto understand and work with.  For example, if a user wishes to visualize the\nattitude of a specific mission spacecraft using quaternions extracted from real\nworld telemetry, GMAT should be flexible enough for that user to define all four\nquaternion components, their locations with respect to each other, and their\nnumerical signs.  The user should also be able to specify the two reference\nframes the attitude parameterization is relating, and the direction the attitude\nparameters take a transformation.  In other words, following the CCSDS standard,\nthe user should be able to specify which is the ``from\" frame and which is the\n``to\" frame.\n\nWe should also point out that the parameters presented in this document can\ndescribe not only the ``transformation\" of a vector between two reference frames,\nbut also the ``rotation\" of a vector from one orientation to another in the same\nreference frame.  The literature uses the definition of ``transformation\" and\n``rotation\" quite liberally, and a detailed search has found little agreement on\nterminology and notation.  Almost all authors agree that the components of the\n3$\\times$3 matrix relating vectors to each other are ``Direction Cosines\".  They\nare the dot products of the basis axes unit vectors of one reference frame with\nthe basis axes unit vectors of the other reference frame.  They are the cosines\nof the angles between each of the basis axes.\n\nFor now it is suggested that the matrix we use to transform or rotate vectors be\nlabeled \\textbf{R} to remain consistent with the mathematical development\nearlier in this specification in Chapter~\\ref{Ch:CoordinateSystems}.  The\n3$\\times$3 matrix \\textbf{R} will relate various reference frames to each other\nand can be used to rotate vectors between frames such as in the FK5 reduction\nprocess.  Meanwhile, if we wish to explicitly model the attitude or orientation\nof a spacecraft, we can represent this with the 3$\\times$3 matrix \\textbf{A}.\nThe letter brings the word ``Attitude\" to mind, and is used by several well known\nattitude dynamics authors including Landis Markley who wrote the\n\"Parameterization of the Attitude\" section of ``Spacecraft Attitude\nDetermination and Control\" by James R. Wertz, a very popular text in the field.\nTo be consistent with Chapter~\\ref{Ch:CoordinateSystems}, we should specify the\ndirection of the transformation with additional notation.\n\nMeanwhile, if we intentionally keep our notation as clutter free as possible,\nthe definition of \\textbf{A} will be as follows.\n\n\\begin{equation}\n    \\textbf{ b = Ar}\n    \\label{Eq:FundamentalAMat}\n\\end{equation}\n\nIn this equation \\textbf{b} is a vector in the spacecraft body frame, and\n\\textbf{r} is a vector in the reference frame.  The attitude matrix \\textbf{A}\ntransforms vectors from the reference frame to the body frame.\n\nThe human mind has some difficulty visualizing the orientation of a spacecraft\nwhen presented with the nine component attitude matrix.  Likewise, it is\ndifficult to know if an aircraft or spacecraft is ``upside-down\" given the four\ncomponents of a quaternion vector.  For human interface purposes, the attitude\ndescriptor of choice is the set of three Euler Angles, such as the classic\n``roll\", ``pitch\", and ``yaw\".  The CCSDS specification avoids mentioning the DC\nmatrix altogether.  Meanwhile, GMAT will use it as an intermediate form of\nattitude parameterization when transforming from internal attitude propagation\nequations using quaternions, and human interpretable Euler Angles.  GMAT will\nalso use it for both Coordinate System Fixed and Spinning Spacecraft modes of\nattitude propagation.\n\nIn this chapter, we discuss the attitude parameterizations supported in GMAT,\nand how to convert between the different types.  We discuss the internal state\nparameterization that GMAT uses.  Next we investigate the types of attitude\nmodes in GMAT and discuss in detail how GMAT propagates the spacecraft attitude\nin all of the Kinematic and Dynamic attitude modes.  We conclude the chapter\nwith a discussion of how GMAT converts between different attitude\nparameterizations.\n\n\\subsection{Attitude Propagation}\n\nGiven a set of initial conditions that define the attitude, GMAT can propagate\nthe attitude using several methods.  Currently, GMAT supports both Kinematic\nattitude and Dynamic attitude propagation.  In Kinematic mode, the attitude is\ndefined by describing the desired orientation with respect to other objects such\nas spacecraft or celestial bodies.  With this information, GMAT can calculate\nthe required attitude to satisfy the desired geometrical configuration.  In\nDynamic mode, the user must also supply spacecraft body inertial mass properties,\nand tell GMAT how to apply torques dynamically to the spacecraft.  With these\nconditions specified, GMAT will numerically integrate quaternion attitude\nequations of motion combined with Euler's moment equations.  The resulting\nattitude motion will display basic physics-based phenomena such as precession\nand nutation.  Dynamic mode will allow a user to model the implementation of\nattitude control laws, as well as the effects of asymmetric propellant mass\ndepletion and dynamic spacecraft component articulation.  It will also\neventually support the modeling of attitude perturbations such as Gravity\nGradient, Aerodynamic Drag and Solar Photon Pressure Torques, and spacecraft\nmagnetic interaction with planetary magnetic fields.  This section presents the\ndifferent Kinematic and Dynamic attitude modes, and how GMAT calculates the\nattitude state in each mode.  Let's begin by looking at the internal attitude\nstate representations and how the user can define initial conditions.\n\n\\vspace{- .1 in} \\subsubsection{Internal State Representation and Attitude\nInitial Conditions}\n\nAs mentioned in the introduction, certain attitude parameterizations are more\nuseful for attitude propagation, while other attitude parameterizations are\nmore intuitive for providing attitude initial conditions or output.  GMAT uses\ndifferent internal parameterizations of the attitude depending on the attitude\nmode.  The type of parameterization is chosen to make the attitude propagation\nalgorithms natural and convenient.  For the Kinematic modes, GMAT uses the\nDirection Cosine Matrix (DCM) or \"Attitude\" matrix that represents the rotation\nfrom the inertial reference frame to the body frame.  The notation for the\nAttitude matrix, including the direction of the rotation it parameterizes is\n\\textbf{A}$_{BI}$.  The subscripts denote the direction of the rotation from\nInertial to Body frames.  For Dynamic mode, six degree of freedom (6DOF)\nattitude propagation, GMAT uses the quaternion that represents the rotation from\nthe inertial reference frame to the body frame.  The notation for the quaternion,\nincluding the direction of the rotation it parameterizes, is\n\\textbf{\\emph{q}}$_{BI}$.  Once again, the subscripts denote the direction of\nthe rotation from Inertial to Body frames.  GMAT uses the angular velocity of\nthe body with respect to the inertial frame, expressed in the body frame,\n$\\{\\boldsymbol\\omega_{IB}\\}_B$, as the rate portion of the state vector.\n\nFor convenience, the user can choose a coordinate system in which to define the\ninitial attitude state.  Let's call this system $\\mathcal{F}_i$.  The user can\ndefine the initial attitude with respect to $\\mathcal{F}_i$ using Euler angles,\nthe DCM or attitude matrix \\textbf{A}, or quaternions.  The user can define the\nbody rate with respect to $\\mathcal{F}_i$ by defining the angular velocity in\n$\\mathcal{F}_i$, $\\{\\boldsymbol\\omega_{IB}\\}_i$, by defining the angular\nvelocity in the inertial frame as measured in body coordinates\n$\\{\\boldsymbol\\omega_{IB}\\}_B$ or by defining the Euler angle rates.  Note that\nnot all attitude modes require these three pieces of information.  The specific\ninputs for each attitude mode are discussed below, along with details about how\nattitude propagation is performed in each mode.\n\n\\subsubsection{Kinematic Attitude Propagation}\n\nThe Kinematic attitude mode allows a user to define a geometrical configuration\nbased on the relative position of a spacecraft with respect to other spacecraft\nor celestial bodies, and with respect to different coordinate systems.  In\nKinematic mode, GMAT does not integrate the attitude equations of motion, but\nrather calculates the attitude based on the geometrical definition provided by\nthe user.  There are two Kinematic modes to choose from.  These are Coordinate\nSystem Fixed and Spinning Spacecraft.  The different modes allow the user to\nconveniently define the spacecraft attitude depending on the type of attitude\nprofile needed for a specific mission.  To begin, let's look at how GMAT\ncalculates the attitude state in the Coordinate System Fixed attitude mode\n(CSFixed).\n\n\\subsubsection{Coordinate System Fixed Mode}\n\nIn the CSFixed attitude mode, the user specifies a coordinate system $\\mathcal{F}_i$ in which to fix the attitude.\n$\\mathcal{F}_i$ can be any of the default coordinate systems or any user defined\ncoordinate system. GMAT calculates the attitude matrix of $\\mathcal{F}_i$ using the\nfollowing equation.\n%\n\\begin{equation}\n    \\mathbf{A}_{BI} = \\mathbf{R}_{iI}\n    \\label{Eq:CSFixedRotationMatrix}\n\\end{equation}\n%\n$\\mathbf{R}_{iI}$ is the DCM matrix relating $\\mathcal{F}_I$ to $\\mathcal{F}_i$\nand GMAT knows how to calculate this matrix for all allowable $\\mathcal{F}_i$.\nFor details on the calculation of this matrix for all coordinate systems in GMAT\nsee Ch.~\\ref{Ch:CoordinateSystems}. To calculate $\\{\\mathbf{\\boldsymbol\\omega}_{IB}\\}_B$, we start from Euler's\nequation:\n%\n\\begin{equation}\n    \\dot{\\mathbf{A}}_{BI} = -\\{\\mathbf{\\boldsymbol\\omega^\\times}_{IB}\\}_B\\mathbf{A}_{BI}\n    \\label{Eq:CSFixedKinematics}\n\\end{equation}\n%\n% Note from Dunn:  We want the \"where\" statement below to stay above the\n% equation and not be orphaned on the preceding page.  Adding \\\\* makes the\n% \"where\" line stay with the equation below.  Then we have to add the [0.5cm]\n% AND skip the white line between this line and the \\begin{equation} command so\n% the vertical white space looks good.  If we change to 10 pt when integrating\n% back into Steve's main document, the [0.5cm] command might need a tweak.\nwhere\\\\*[0.5cm]\n%\n\\begin{equation}\n    \\{ \\mathbf{\\boldsymbol\\omega^\\times}_{IB}\\}_B\\hspace{0.082cm}\\equiv\n        \\begin{bmatrix}\n                 0      & -\\omega_{3} &  \\omega_{2} \\\\\n             \\omega_{3} &      0      & -\\omega_{1} \\\\\n            -\\omega_{2} &  \\omega_{1} &      0\n        \\end{bmatrix}\n    \\equiv \\hspace{0.082cm}\\boldsymbol \\Omega\n    \\label{Eq:OmegaCrossMatrix}\n\\end{equation}\n%\nand $\\{\\mathbf{\\boldsymbol\\omega}_{IB}\\}_B$ is the skew symmetric angular\nvelocity ``cross product matrix\" of $\\mathcal{F_B}$ with respect to\n$\\mathcal{F}_I$, expressed in $\\mathcal{F}_B$.  Solving Equation\n\\ref{Eq:CSFixedKinematics} for $\\{\\mathbf{\\boldsymbol\\omega}_{IB}^\\times\\}_B$\nwe obtain\n%\n\\begin{equation}\n    \\{\\mathbf{\\boldsymbol\\omega^\\times}_{IB}\\}_B =  -\\dot{\\mathbf{A}}_{BI}\\mathbf{A}_{BI}^{T}\n    \\label{Eq:CSFixedKinematics2}\n\\end{equation}\n%\nwhere \n%\n\\begin{equation}\n     \\dot{\\mathbf{A}}_{BI} = \\dot{\\mathbf{R}}_{iI}\n    \\label{Eq:CSFixedKinematics2}\n\\end{equation}\n%Taking the derivative of Equation \\ref{Eq:CSFixedRotationMatrix} with respect to\n%time yields\n%%\n%\\begin{equation}\n%    {\\mathbf{\\dot A}_{BI}} = \\mathbf{A}_{Bi}{\\mathbf{\\dot R}_{iI}}\n%    \\label{Eq:CSFixedTimeDerivative}\n%\\end{equation}\n%%\n%because by definition, for the CSFixed mode,\n%$ \\mathbf{\\dot A}_{Bi} = \\mathbf{0}$.\n%Substituting Eq. \\ref{Eq:CSFixedTimeDerivative} into\n%Eq. \\ref{Eq:CSFixedKinematics2} we obtain\n%%\n%\\begin{equation}\n%    \\{\\mathbf{\\boldsymbol\\omega^\\times}_{IB}\\}_B =  -\\mathbf{A}_{Bi}{\\mathbf{\\dot R}_{iI}} \\mathbf{A}_{BI}^{T}\n%    \\label{Eq:CSFixedKinematics3}\n%\\end{equation}\n%%\n%where $\\mathbf{A}_{Bi}$ is known from user input, and $\\mathbf{A}_{BI}$ is known\n%from Eq. \\ref{Eq:CSFixedRotationMatrix}.  GMAT knows how to calculate\n%$\\mathbf{\\dot{R}}_{iI}$ for all allowable $\\mathcal{F}_i$ and details are contained\n%in Ch.~\\ref{Ch:CoordinateSystems}.  Next we would like to get the angular\n%velocity vector $\\{\\mathbf{\\boldsymbol\\omega}_{IB}\\}_B$ in terms of the\n%components of the 3$\\times$3 cross product matrix in the middle of\n%Eq. \\ref{Eq:OmegaCrossMatrix}.  This matrix, in symbol notation also shows up on\n%the left hand side of Eq. \\ref{Eq:CSFixedKinematics3}.\n%%\n%% Note - Dunn discovered, through trial and error, that you can't add white lines\n%% between matrix components in the equation below to enhance readability.  LaTeX\n%% actually crashes.  But you can add a % comment to create spacing.\n%\\begin{equation}\n%\t\\{\\boldsymbol \\omega_{IB}\\}_{B} =\n%        %\n%        \\begin{bmatrix}\n%            \\omega_{1} \\\\\n%            \\omega_{2} \\\\\n%            \\omega_{3}\n%        \\end{bmatrix} = \\hspace{0.082cm}\n%        %\n%        \\begin{bmatrix}\n%            \\Omega_{32} \\\\\n%            \\Omega_{13} \\\\\n%            \\Omega_{21}\n%        \\end{bmatrix}\n%        %\n%    \\label{Eq:OmegaComponents}\n%\\end{equation}\n%%\n%Each of the three components of the angular velocity vector, measured in the\n%spacecraft body frame, can be found in the cross product matrix defined in\n%Eq. \\ref{Eq:OmegaCrossMatrix}.  The subscripts on the right hand side of\n%Eq. \\ref{Eq:OmegaComponents} tell us where to find these components after\n%multiplying the three 3$\\times$3 matrices on the right hand side of\n%Eq. \\ref{Eq:CSFixedKinematics3}.\n\n\n\\subsubsection{Spinning Spacecraft Mode}\n\nIn spinning spacecraft mode, GMAT propagates the attitude by assuming the spin\naxis direction is fixed in inertial space.  The spacecraft attitude at some time,\n$t$, is kinematically propagated from the attitude initial conditions.\nThe user defines the initial attitude with respect to $\\mathcal{F}_i$ by providing $\\mathbf{A}_{BI}(t_o)$ or an equivalent\nparameterization that is then converted to the Attitude matrix.  The user also\nprovides the angular velocity of the body axes with respect to the inertial axes\nexpressed in $\\mathcal{F}_i$, $\\{\\boldsymbol\\omega_{IB}\\}_i$.  \n\nTo calculate $\\mathbf{A}_{BI}(t)$ where $t$ is an arbitrary epoch,\nwe begin by calculating $\\mathbf{A}_{B_{o}I}$, understanding that\n$\\mathbf{A}_{B_{o}I} = \\mathbf{A}_{BI}(t_o)$.  We calculate\n$\\mathbf{A}_{B_{o}I}$ using\n%\n\\begin{equation}\n    \\mathbf{A}_{B_{o}I} =  \\mathbf{A}_{Bi}\\mathbf{R}_{iI}(t_o)\n    \\label{Eq:ABoI}\n\\end{equation}\n%\nwhere $\\mathbf{A}_{Bi}$ comes from user provided data, and\n$\\mathbf{R}_{iI}(t_o)$ is calculated by GMAT and is dependent upon\n$\\mathcal{F}_i$.  See Ch.~\\ref{Ch:CoordinateSystems} for details on how GMAT\ncalculates $\\mathbf{R}_{iI}$ for all allowable coordinate systems in GMAT.\n\nBefore calculating $\\mathbf{A}_{BI}(t)$ we must determine the spin axis in the\nbody frame, $\\{\\boldsymbol\\omega_{IB}\\}_B$.  If the user has chosen to provide\nthe angular velocity vector in body frame coordinates, then we already have what\nwe need.  Otherwise, the user provides $\\{\\boldsymbol\\omega_{IB}\\}_i$.\nIn spinning mode we assume the rotation rate magnitude is constant and also that\nthe spin axis direction is constant in inertial space.  This assumption is only\nrealistic if the angular velocity is aligned with either the maximum or minimum\nprimary axis of moment of inertia in the spacecraft body reference frame.  If\nangular velocity is aligned with the axis of minimum moment of inertia, then we\nmust also assume there is an active attitude control system holding it there.\nIf there is no control system, and the spacecraft dissipates rotational kinetic\nenergy (all real bodies will) then the direction of the angular velocity vector\nwill migrate slowly until it is aligned with the axis of maximum moment of\ninertia.  Understanding these assumptions we can state\n$\\{ \\boldsymbol\\omega_{IB} \\}_B (t)$ $ = \\{\\boldsymbol\\omega_{IB} \\}_B (t_o) =\n\\{ \\boldsymbol\\omega_{IB} \\}_B$.  We can find the spin axis in the body frame\n(if we need to) using $\\mathbf{A}_{Bi}$ as follows\n%\n\\begin{equation}\n    \\{ \\boldsymbol\\omega_{IB}\\}_B = \\mathbf{A}_{Bi} \\{ \\boldsymbol\\omega_{IB}\\}_i\n    \\label{Eq:AngularVelocityBody}\n\\end{equation}\n%\nOnce calculated, GMAT saves the parameters $\\mathbf{A}_{B_{o}I}$ and\n$\\{\\boldsymbol\\omega_{IB}\\}_B$ for use in calculating the attitude and rate at\nother epochs.\n\nGMAT calculates $\\mathbf{A}_{BI}(t)$ using the Euler axis/angle to Attitude\nmatrix conversion algorithm  in Sec.\\ref{Sec:AttitudeParameterizations}. The\nEuler axis is simply the unitized angular velocity vector or,\n%\n\\begin{equation}\n    \\mathbf{a} =   \\frac{  \\{ \\boldsymbol\\omega_{IB} \\}_B  }{\\omega_{IB} }\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n    \\omega_{IB} = \\| \\{\\boldsymbol{\\omega}_{IB} \\}_B \\|\n\\end{equation}\n%\n\\newpage\nThe Euler angle $\\phi$ is calculated using\n%\n\\begin{equation}\n    \\phi(t) = \\omega_{IB}(t -t_o)\n\\end{equation}\n%\nwhere $t$ is the current epoch, and $t_o$ is the spacecraft's initial epoch.\nLet's define the Attitude matrix that results from the Euler axis/angle to\nAttitude matrix conversion algorithm using $\\mathbf{a}$ and $\\phi(t)$, as\n$\\mathbf{A}_{BB_{o}}(t)$.  We can calculate $\\mathbf{A}_{BI}(t)$ using\n%\n\\begin{equation}\n    \\mathbf{A}_{BI}(t) =\n    \\mathbf{A}_{BB_{o}}(t)\\mathbf{A}_{B_{o}I}\n\\end{equation}\n%\nTo summarize, in spinning mode the user provides $\\mathbf{A}_{Bi}$ and\n$\\{ \\boldsymbol\\omega_{IB}\\}_i$ or $\\{ \\boldsymbol\\omega_{IB}\\}_B$.  GMAT\nassumes that that the spin axis direction is constant in both inertial and body\nspace, and uses the Euler axis/angle method to propagate the attitude to find\n$\\mathbf{A}_{BI}$.  Now let's look at dynamic attitude propagation in GMAT.\n\n\n\\subsubsection{Dynamic Attitude Propagation}\nIn Dynamic mode, GMAT propagates quaternion attitude equations of motion along\nwith Euler's moment equations.  This allows the user to provide detailed mass\nmoment of inertia properties, and to model spacecraft attitude control and\nenvironmental perturbing torques.  The resulting numerically integrated attitude\nwill exhibit basic dynamics properties such as precession and nutation.\nDetailed tracking of the dynamic inertia tensor will also allow the user to\nproperly model the effect on the attitude trajectory of propellant mass\ndepletion, articulation of various components, and implementation of attitude\ncontrol laws.  For modes where control laws cause the spacecraft to slew to a\ntargeted pointing direction, GMAT will model line of sight angular acceleration,\ndeceleration, overshoot, settling, and drift behavior.  There are several\nDynamic modes to choose from.  The different modes allow the user to\nconveniently define the spacecraft attitude and controlled pointing depending on\nthe type of attitude profile needed for a specific mission.  To begin, let's\nlook at how GMAT calculates the attitude state in the simplest possible dynamic\nmode, Rigid Torque Free attitude mode (RigidTorqueFreeQuat).\\\\*[0.1cm]\n%\n\\vspace{-0.2 in}\n\\begin{figure*}[htb]\n    \\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{Images/QuaternionX42DefB&W}\n    \\caption{ Euler Axis and Angle} \\label{fig:EulerAxisAndAngle}\n    \\end{center}\n\\end{figure*}\n%\n\\subsubsection{Rigid Torque Free (Quaternion) Mode}\nThe fundamental equations of attitude motion run most efficiently using the four\ncomponent quaternion.  There are equations of motion for Euler Angles, but these\nhave singularities that cause problems in implementation.  There are also\nequations of motion for the nine components of the Attitude matrix.  Numerically\nintegrating nine equations for the Attitude matrix is not as efficient as four\nequations for the quaternion.  The quaternion is the most popular attitude\nparameterization in use today for propagating attitude using numerical\nintegration schemes.  Let's begin by defining the quaternion.\n\nAs shown above in Figure \\ref{fig:EulerAxisAndAngle}, any spacecraft attitude\ncan be described as the rotation about a single axis via a fixed angle from an\ninertial frame orientation to the current body orientation.  The single axis is\ncalled the Euler Axis, and the angle is the Euler Angle.  In the figure, the\nEuler Axis is given the vector label $\\vec{e}$.  This is not the same as\nthe three Euler Angles used as another of our attitude parameterizations.  We\nwill use the CCSDS Attitude Data Message standard to define the GMAT quaternion.\nThe definition is based on the Euler Axis/Angle parameterization and is\n%\n\\begin{equation}\n\t\\boldsymbol q \\equiv\n        %\n        \\begin{bmatrix}\n            q_1 \\\\\n            q_2 \\\\\n            q_3 \\\\\n            q_c\n        \\end{bmatrix}\n        %\n        \\equiv %\\hspace{0.082cm}\n        %\n        \\begin{bmatrix}\n            \\mathbf{q} \\\\\n            q_c \\\\\n        \\end{bmatrix}\n        %\n        \\equiv %\\hspace{0.082cm}\n        %\n        \\begin{bmatrix}\n            \\mathbf{a}_1 \\sin \\frac{\\phi}{2} \\\\\n            \\mathbf{a}_2 \\sin \\frac{\\phi}{2} \\\\\n            \\mathbf{a}_3 \\sin \\frac{\\phi}{2} \\\\\n            \\cos \\frac{\\phi}{2} \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:QuaternionDefinition}\n\\end{equation}\n%\nwhere $\\mathbf{a}_1$, $\\mathbf{a}_2$, and $\\mathbf{a}_3$ are components of the\nunit vector aligned with the Euler Axis or $\\mathbf{\\hat{a}}$.  This unit vector\nis shown near the spacecraft center of mass in Figure \\ref{fig:EulerAxisAndAngle}.\nIn Eq.~\\ref{Eq:QuaternionDefinition} the Euler Angle is denoted using the symbol\n $\\phi$.  There are actually two possible values of $\\phi$, since the rotation\nshown in Figure \\ref{fig:EulerAxisAndAngle} can be the long way around or the\nshort way around.  The two possible values will add to $360\\,^{\\circ}$.  Our\ndefinition of quaternions assumes the smaller angle.\n\nThe subscript ``c\" on the fourth component of the quaternion comes from the\nCCSDS standard and most likely stands for ``cosine\".  The CCSDS has cleverly\navoided specifying whether the cosine ``scalar\" component should be placed\nbefore or after the vector component.  This standard has thus eliminated the\nconfusion of which component of the quaternion should be defined as $q_1$ and\nwhich as $q_4$.  The CCSDS standard does place its initial definition for $q_c$\nafter the definitions for $q_1$, $q_2$, and $q_3$.  This lets us stack the four\ncomponents in the vector shown in the second part of the definition in\nEq.~\\ref{Eq:QuaternionDefinition}.  If $q_4$ were substituted for $q_c$, we would\nhave Landis Markley's definition from the ``Parameterization of the Attitude\"\nsection in ``Spacecraft Attitude Determination and Control\" by Wertz.  The third\npart of the definition above shows the 3$\\times$1 vector component of the\nquaternion as a single symbol $\\mathbf{q}$, placed above $q_c$ to form a second\n4$\\times$1 matrix or vector.  This also parallels Markley's definition and will\nconveniently fit into the GMAT equations relating quaternions to the Attitude\nmatrix shown later in this section.  Note that for the final part of the\ndefinition in Eq. \\ref{Eq:QuaternionDefinition}, the CCSDS standard uses\n$\\mathbf{e}$ to denote the unit vector aligned with the Euler Axis instead of\n$\\mathbf{a}$.  We have chosen $\\mathbf{a}$ to represent ``axis\", and because\nthat is how GMAT is using it later in the attitude parameterization conversion\nSection \\ref{Sec:AttitudeParameterizations}.\n\nIn torque free quaternion attitude propagation mode, the user provides four\npieces of information.  They first choose a coordinate system, $\\mathcal{F}_i$,\nin which to define the initial conditions.  Secondly, they define the initial\nattitude with respect to $\\mathcal{F}_i$ by providing $\\mathbf{A}_{Bi}$ or an\nequivalent parameterization that is then converted to the Attitude matrix.  GMAT\nwill then use $\\mathbf{A}_{Bi}$ to calculate $\\mathbf{A}_{BI}$ using\nEq.~\\ref{Eq:CSFixedRotationMatrix}.  From this Attitude matrix the\nparameterization will next be converted by GMAT to the quaternion\n$\\boldsymbol q_{Bi}$.  Thirdly, the user provides the angular velocity of the body\naxes with respect to the inertial axes expressed in $\\mathcal{F}_i$, or\n$\\{ \\boldsymbol\\omega_{IB}\\}_i$.  If it is more convenient for the user to\nprovide angular velocity expressed in the spacecraft body frame, GMAT will accept\nthis input as well.  If the user provides angular velocity in $\\mathcal{F}_i$,\nGMAT will use Eq.~\\ref{Eq:AngularVelocityBody} to convert it to\n$\\{\\boldsymbol\\omega_{IB}\\}_B$.  Fourthly, the user provides the mass moment of\ninertia properties.  These can be in the form of the three principal moments of\ninertia $I_{xx}$, $I_{yy}$, and $I_{zz}$, or a full inertia tensor with the\noff-diagonal products of inertia $I_{xy}$, $I_{xz}$, and $I_{yz}$ included.  In\na future release of GMAT the user will be able to use the GUI or scripting\nlanguage to assemble a complex spacecraft model from components.  Locating and\norienting these components and describing how those that articulate can move,\nthe user will provide enough information for GMAT to calculate a dynamic inertia\ntensor.  This future capability will also include dynamically adjusting the\ncomponents of the inertia tensor as propellant is consumed from tanks.\n\n\\newpage\nGMAT will assemble the data provided by the user into a state vector that can be\npropagated numerically.  In this case, GMAT will need to create an initial state,\nand then provide its numerical integrators with the state vector derivative\nequations.\n\nWe will define an attitude state variable $\\mathbf{x}$ such that\n%\n\\begin{equation}\n\t\\mathbf{x} =\n        %\n        \\begin{bmatrix}\n            \\boldsymbol{q}^T & \\boldsymbol\\omega^T\n        \\end{bmatrix}^T\n        %\n        =\n        %\n        \\begin{bmatrix}\n            q_1 & q_2 & q_3 & q_c & \\omega_1 & \\omega_2 & \\omega_3\n        \\end{bmatrix}^T\n        %\n    \\label{Eq:QuatStateVec}\n\\end{equation}\n%\nthen taking the derivative we arrive at\n%\n\\begin{equation}\n\t\\mathbf{\\dot{x}} =\n        %\n        \\begin{bmatrix}\n            \\boldsymbol{\\dot{q}}^T & \\boldsymbol{\\dot{\\omega}}^T\n        \\end{bmatrix}^T\n        %\n        =\n        %\n        \\begin{bmatrix}\n            \\dot{q_1} & \\dot{q_2} & \\dot{q_3} & \\dot{q_c} & \\dot{\\omega_1} & \\dot{\\omega_2} & \\dot{\\omega_3}\n        \\end{bmatrix}^T\n        %\n    \\label{Eq:QuatStateVecDot}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n\t\\boldsymbol{\\dot{q}} =\n        %\n        \\frac{1}{2}\\boldsymbol{\\Omega(\\omega)q}\n        %\n    \\label{Eq:QDot}\n\\end{equation}\n%\nand where\n%\n\\begin{equation}\n\t\\boldsymbol{\\Omega(\\omega)} =\n        %\n        \\begin{bmatrix}\n        -[\\omega\\times] & \\omega \\\\\n         -\\omega^T      &  0     \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:CapOmega1}\n\\end{equation}\n%\nIn Eq.~\\ref{Eq:CapOmega1}, $[\\omega\\times]$ is the skew symmetric angular\nvelocity cross product matrix originally introduced in\nEq.~\\ref{Eq:OmegaCrossMatrix}.  As in Eq.~\\ref{Eq:OmegaCrossMatrix} the angular\nvelocity used here represents the body with respect to the inertial frame.  If\nwe substitute Eq.~\\ref{Eq:OmegaCrossMatrix} into Eq.~\\ref{Eq:CapOmega1} we get\n%\n\\begin{equation}\n    \\boldsymbol{\\Omega}(\\omega) =\n        %\n        \\begin{bmatrix}\n          0       &  \\omega_3 & -\\omega_2 &  \\omega_1 \\\\\n        -\\omega_3 &   0       &  \\omega_1 &  \\omega_2 \\\\\n         \\omega_2 & -\\omega_1 &   0       &  \\omega_3 \\\\\n        -\\omega_1 & -\\omega_2 & -\\omega_3 &   0       \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:CapOmega2}\n\\end{equation}\n%\nSubstituting Eq.~\\ref{Eq:CapOmega2} into Eq.~\\ref{Eq:QDot} and multiplying the\nterms together we get\n%\n\\begin{equation}\n% The \"arraystretch\" command prevents the fractions from touching vertically\n\\renewcommand{\\arraystretch}{1.4}\n    \\boldsymbol{\\dot{q}} =\n        %\n        \\frac{1}{2}\\boldsymbol{\\Omega(\\omega)q} =\n        %\n        \\begin{bmatrix}\n        \\frac{1}{2}( \\hspace{0.35cm}\\omega_3 q_2 -\\omega_2 q_3 +\\omega_1 q_c )\\\\\n        \\frac{1}{2}(               -\\omega_3 q_1 +\\omega_1 q_3 +\\omega_2 q_c )\\\\\n        \\frac{1}{2}( \\hspace{0.35cm}\\omega_2 q_1 -\\omega_1 q_2 +\\omega_3 q_c )\\\\\n        \\frac{1}{2}(               -\\omega_1 q_1 -\\omega_2 q_2 -\\omega_3 q_3 )\\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:QuatEOMs}\n\\end{equation}\n%\nNext let's evaluate the time derivative of the body angular velocity terms.\nThese are the last three components of the state vector derivative in\nEquation~\\ref{Eq:QuatStateVecDot}.  Following the Markley/Wertz convention, if\nwe let $\\mathbf{L}$ represent angular momentum we can start with a simple\nequation for angular momentum measured in the Inertial reference frame.\n%\n\\begin{equation}\n    \\mathbf{L} =\n        %\n        \\mathbf{I} \\cdot \\boldsymbol{\\omega}\n        %\n    \\label{Eq:AngMom}\n\\end{equation}\n%\nEuler's second law says that, in an inertial reference frame, the time\nderivative of $\\mathbf{L}$ is the applied torque, $\\mathbf{T}$.  We write this\nas\n%\n\\begin{equation}\n\t\\mathbf{\\dot{L}} =\n        %\n        \\frac{d}{dt}(\\mathbf{I}\\cdot\\boldsymbol{\\omega})\n        %\n        =\n        %\n        \\mathbf{T}\n        %\n    \\label{Eq:Eulers2ndLaw}\n\\end{equation}\n%\nwhere $\\mathbf{I}$ is the body oriented Inertia Tensor.  This is a 3$\\times$3\nmatrix with the principal moments of inertia on the diagonal and the products of\ninertia on the off-diagonal.  It is written as follows.\n%\n\\begin{equation}\n    \\mathbf{I} =\n        %\n        \\begin{bmatrix}\n        I_{11} & I_{12} & I_{13} \\\\\n        I_{21} & I_{22} & I_{23} \\\\\n        I_{31} & I_{32} & I_{33} \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:FullInertiaTensor}\n\\end{equation}\n%\nwhere the moments and products of inertia are defined as follows.\n%\n\\begin{equation}\n    I_{11} \\equiv \\sum_{i=1}^{n} m_i ( \\rho_{i2}^2 + \\rho_{i3}^2 )\n    \\label{Eq:Moment11}\n\\end{equation}\n%\n\\begin{equation}\n    I_{22} \\equiv \\sum_{i=1}^{n} m_i ( \\rho_{i3}^2 + \\rho_{i1}^2 )\n    \\label{Eq:Moment22}\n\\end{equation}\n%\n\\begin{equation}\n    I_{33} \\equiv \\sum_{i=1}^{n} m_i ( \\rho_{i1}^2 + \\rho_{i2}^2 )\n    \\label{Eq:Moment33}\n\\end{equation}\n%\n\\begin{equation}\n    I_{12} = I_{21} \\equiv -\\sum_{i=1}^{n} m_i \\rho_{i1} \\rho_{i2}\n    \\label{Eq:Product12}\n\\end{equation}\n%\n\\begin{equation}\n    I_{23} = I_{32} \\equiv -\\sum_{i=1}^{n} m_i \\rho_{i2} \\rho_{i3}\n    \\label{Eq:Product23}\n\\end{equation}\n%\n\\begin{equation}\n    I_{31} = I_{13} \\equiv -\\sum_{i=1}^{n} m_i \\rho_{i3} \\rho_{i1}\n    \\label{Eq:Product31}\n\\end{equation}\n%\nThe signs for the products of inertia depend on how products of inertia are\nthemselves defined.  They can be positive or negative depending on individual\nauthors.  Meanwhile, each regular geometric shape, if constructed of a uniform\nsolid material, will have an analytic formula for each of its moments and\nproducts of inertia.  A spacecraft model composed of multiple elements can sum\nmoments and products of inertia for all components into a single Inertia Tensor.\nFor the current RigidTorqueFreeQuat mode we will assume ours is diagonal.\n%\n\\begin{equation}\n    \\mathbf{I} =\n        %\n        \\begin{bmatrix}\n        I_{11} &    0   &    0   \\\\\n           0   & I_{22} &    0   \\\\\n           0   &    0   & I_{33} \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:DiagonalInertiaTensor}\n\\end{equation}\n%\nIn this initial development, we will assume our spacecraft body frame is aligned\nwith its principal axes of inertia, and that it is a completely rigid body.  This\nwill mean our inertia tensor is both diagonal and has a time derivative of zero.\nLet's apply these facts to Eq.~\\ref{Eq:Eulers2ndLaw}.\n%\n\\begin{equation}\n    \\frac{d}{dt}(\\mathbf{I}\\cdot\\boldsymbol{\\omega}) =\n        %\n        (\\mathbf{\\dot{I}}\\cdot\\boldsymbol{\\omega})+(\\mathbf{I}\\cdot\\boldsymbol{\\dot{\\omega}})\n        %\n    \\label{Eq:TimeDerivEulersEquation}\n\\end{equation}\n%\nSince we already stated that the time derivative of I is zero, the first term\non the RHS of Eq.~\\ref{Eq:TimeDerivEulersEquation} will drop out.  We can now\nwrite Eq.~\\ref{Eq:Eulers2ndLaw} as follows.\n%\n\\begin{equation}\n\t\\mathbf{\\dot{L}} =\n        %\n        \\mathbf{T} =\n        %\n        (\\mathbf{I}\\cdot\\boldsymbol{\\dot{\\omega}})\n        %\n    \\label{Eq:TimeDerivEulersEquation2}\n\\end{equation}\n%\nIn Eq.~\\ref{Eq:TimeDerivEulersEquation2} the angular momentum term is measured\nin the inertial frame.  Let's express it now in the spacecraft body frame.\nSuperscripts to the left will indicate the reference frame.\n%\n\\begin{equation}\n    ^{I}\\mathbf{\\dot{L}} = \\hspace{0.082cm}\n        %\n        ^{B}\\mathbf{\\dot{L}} + \\hspace{0.082cm} ^{B}\\boldsymbol{\\omega} \\times \\hspace{0.03cm} ^{B}\\mathbf{L}\n        %\n    \\label{Eq:BasicAttDynamics1}\n\\end{equation}\n%\nCombining Equations~\\ref{Eq:Eulers2ndLaw} and ~\\ref{Eq:BasicAttDynamics1} gives\nus\n%\n\\begin{equation}\n    ^{B}\\mathbf{T} = \\hspace{0.082cm}\n        %\n        ^{B}\\mathbf{\\dot{L}} + \\hspace{0.082cm} ^{B}\\boldsymbol{\\omega} \\times \\hspace{0.03cm} ^{B}\\mathbf{L}\n        %\n    \\label{Eq:BasicAttDynamics2}\n\\end{equation}\n%\nSubstituting~\\ref{Eq:TimeDerivEulersEquation2} for $\\mathbf{\\dot{L}}$ on the RHS\nof~\\ref{Eq:BasicAttDynamics2}, and~\\ref{Eq:AngMom} for $\\mathbf{L}$ on the RHS,\nwe get the following.\n%\n\\begin{equation}\n    ^{B}\\mathbf{T} = \\hspace{0.082cm}\n        %\n        ^{B}(\\mathbf{I}\\cdot\\boldsymbol{\\dot{\\omega}}) +\n        \\hspace{0.082cm} ^{B}\\boldsymbol{\\omega} \\times \\hspace{0.03cm} ^{B}\\mathbf{I} \\cdot \\boldsymbol{\\omega}\n        %\n    \\label{Eq:BasicAttDynamics3}\n\\end{equation}\n%\nAssuming our Inertia Tensor is diagonal, if we multiply out the terms on the RHS\nof Eq.~\\ref{Eq:BasicAttDynamics3} we will get three equations for torque along\nthe principal axes of the spacecraft body.\n%\n\\begin{equation}\n    T_1 = I_{11}\\dot{\\omega_1}+(I_{22}-I_{33}) \\omega_2 \\omega_3\n    \\label{Eq:TorqueAxis1}\n\\end{equation}\n%\n\\begin{equation}\n    T_2 = I_{22}\\dot{\\omega_2}+(I_{33}-I_{11}) \\omega_3 \\omega_1\n    \\label{Eq:TorqueAxis2}\n\\end{equation}\n%\n\\begin{equation}\n    T_3 = I_{33}\\dot{\\omega_3}+(I_{11}-I_{22}) \\omega_1 \\omega_2\n    \\label{Eq:TorqueAxis3}\n\\end{equation}\n%\nThese equations are equivalent to Equations 16-50a through 16-50c on Page 522 of\nWertz.\n\nSolving equations~\\ref{Eq:TorqueAxis1} through~\\ref{Eq:TorqueAxis3} for\nangular acceleration, we get\n%\n\\begin{equation}\n    \\dot{\\omega_1} = \\frac{T_1 - (I_{22}-I_{33}) \\omega_2 \\omega_3}{I_{11}}\n    \\label{Eq:OmegaDot1}\n\\end{equation}\n%\n\\begin{equation}\n    \\dot{\\omega_2} = \\frac{T_2 - (I_{33}-I_{11}) \\omega_3 \\omega_1}{I_{22}}\n    \\label{Eq:OmegaDot2}\n\\end{equation}\n%\n\\begin{equation}\n    \\dot{\\omega_3} = \\frac{T_3 - (I_{11}-I_{22}) \\omega_1 \\omega_2}{I_{33}}\n    \\label{Eq:OmegaDot3}\n\\end{equation}\n%\nThese are the three angular velocity time derivative terms we needed for the\nstate derivative vector in Equation~\\ref{Eq:QuatStateVecDot}.  They are also\nknown as Euler's Moment Equations.  As long as we are rotating torque free, we\nwill set the torque $\\mathbf{T}$ terms in Equations~\\ref{Eq:OmegaDot1}\nthrough~\\ref{Eq:OmegaDot3} to zero.  We now have everything GMAT needs to\nintegrate our quaternion attitude equations of motion for a torque free rigid\ntumbling body.\n\nThese equations will model several types of rotational motion.  They are\n``motionless hang\", ``flat spin\", ``spin with precession\", and ``spin with\nprecession and nutation\" which is the same as a full 3-axis tumble.  Next, let's\nadd a level of complexity and look at Articulated Torque Free attitude mode.\n\n\\subsubsection{Articulated Torque Free (Quaternion) Mode}\nLet's assume our spacecraft is still rotating without the influence of control\nor environmental torques, but now it is moving articulated appendages.  We can\nno longer assume our inertia tensor $\\mathbf{I}$ is constant.  It is also\nunlikely, now that objects are moving, that $\\mathbf{I}$ will remain diagonal.\nLet's develop new equations to handle our dynamic inertia tensor.  The\ndefinition of angular momentum is\n%\n\\begin{equation}\n    \\mathbf{L} \\equiv\n        \\mathbf{I} \\boldsymbol{\\omega}\n        \\label{Eq:AngMomDef}\n\\end{equation}\n%\nwhich applies to an inertia tensor with off-diagonal products of inertia.  The\ninitial conditions for both parameters on the RHS of Eq.~\\ref{Eq:AngMomDef} will\nbe provided by the User.  Multiplying both sides by the inverse of $\\mathbf{I}$,\nand then solving for angular velocity we get\n%\n\\begin{equation}\n    \\boldsymbol{\\omega} =\n        %\n        \\mathbf{I^{-1}L}\n    \\label{Eq:Omega}\n\\end{equation}\n%\nIf GMAT calculates changes in $\\mathbf{I}$ based on articulation, and for later\nmodes includes propellant mass consumption, and it integrates $\\mathbf{\\dot{L}}$\nto get $\\mathbf{L}$, during each integration step we can use Eq.~\\ref{Eq:Omega}\nto calculate current angular velocity $\\mathbf{\\omega}$.  Solving\nEq.~\\ref{Eq:BasicAttDynamics2} for $\\mathbf{\\dot{L}}$, we get\n%\n\\begin{equation}\n    ^{B}\\mathbf{\\dot{L}} = \\hspace{0.082cm}\n        %\n         ^{B}\\mathbf{T}- \\hspace{0.082cm} ^{B}\\boldsymbol{\\omega} \\times \\hspace{0.03cm} ^{B}\\mathbf{L}\n        %\n    \\label{Eq:BasicAttDynamics4}\n\\end{equation}\n%\nIf the user inputs all the same initial conditions as they did in\nRigidTorqueFreeQuat mode, with the addition of a full inertia tensor with\nproducts, and GMAT tracks articulation of components and adjusts the inertia\ntensor dynamically, the state vector to calculate will now be\n%\n%\n\\begin{equation}\n\t\\mathbf{x} =\n        %\n        \\begin{bmatrix}\n            \\boldsymbol{q}^T & \\mathbf{L}^T\n        \\end{bmatrix}^T\n        %\n        =\n        %\n        \\begin{bmatrix}\n            q_1 & q_2 & q_3 & q_c & L_1 & L_2 & L_3\n        \\end{bmatrix}^T\n        %\n    \\label{Eq:QuatStateVec}\n\\end{equation}\n%\nwhere the initial condition of $\\mathbf{L}$ is calculated from\nEq.~\\ref{Eq:AngMomDef}.  To get angular velocity, rather than integrating Euler's\nMoment Equations, we will use Eq.~\\ref{Eq:Omega} which means we need to invert a\n3$\\times$3 matrix.  Since a full inertia tensor is still symmetric, we can use\nCramer's rule to invert it with no numerical pathologies.  The time derivative\nof $\\mathbf{x}$, which we need to send to the GMAT numerical integrators will be\n%\n\\begin{equation}\n\t\\mathbf{\\dot{x}} =\n        %\n        \\begin{bmatrix}\n            \\boldsymbol{\\dot{q}}^T & \\mathbf{\\dot{L}}^T\n        \\end{bmatrix}^T\n        %\n        =\n        %\n        \\begin{bmatrix}\n            \\dot{q_1} & \\dot{q_2} & \\dot{q_3} & \\dot{q_c} & \\dot{L_1} & \\dot{L_2} & \\dot{L_3}\n        \\end{bmatrix}^T\n        %\n    \\label{Eq:QuatStateVecDot}\n\\end{equation}\n%\nWe get $\\mathbf{\\dot{q}}$ from Eq.~\\ref{Eq:QuatEOMs} and $\\mathbf{\\dot{L}}$ from\nEq.~\\ref{Eq:BasicAttDynamics4}. For this torque free mode we can choose to set\nthe torque vector in Eq.~\\ref{Eq:BasicAttDynamics4} to zero.  We now have\neverything GMAT needs to integrate our quaternion attitude equations of motion\nfor a torque free articulated tumbling body.\n\n\\subsubsection{Attitude Hold Mode}\nUnder Construction\n\n\\subsubsection{Seek Coordinate System Fixed Mode}\nUnder Construction\n\n\\subsubsection{Target Pointing Slew Mode}\nUnder Construction\n\n\\subsubsection{Torque Perturbations Mode}\nTorque Perturbations are higher order terms that model environmental torques or\ntorques applied as the result of human operator control inputs.  These can be\nattitude maneuvers selected by a ground controller from a mouse activated GUI\nmenu, or input through joysticks by an astronaut pilot.  Full 6DOF maneuvering\ninvolved in manual or automated rendezvous, proximity operations, and docking\nwill involve translational forces and equations of motion and is covered in\nCh. TBD.  Simple environmental torques include Gravity Gradient, Aerodynamic Drag\nand Solar Photon Pressure Torques, and spacecraft magnetic interaction with\nplanetary magnetic fields.  These torques can be added to the basic Euler Moment\nEquations presented above in the Torque Free Mode section.\n\n\n\\subsection{Attitude Parameterizations and Conversions}\n\\label{Sec:AttitudeParameterizations}\nThis section details how GMAT converts between different attitude\nparameterizations.  For each conversion type, any singularities that may occur\nare addressed.  The orientation parameterizations in GMAT include the DCM or A\nMatrix, Euler Angles, quaternions, and Euler axis/angle.  The body rate\nparameterizations include Euler angle rates and angular velocity.  We begin with\nthe algorithm to transform from the quaternions to the Attitude matrix.\n\n\\subsubsection{Conversion:  Quaternions to Attitude Matrix}\\label{sec:QuatToAMat}\n\\index{Attitude Parameterization!Quaternions to Attitude Matrix}\n\nGiven:  $\\mathbf{q}$, $q_c$\n\n\\noindent Find:  $\\mathbf{A}$\n\n\\noindent Name:  \\emph{QuatsToAMat}\n\n\\begin{equation}\n    \\mathbf{q} = \\left[ q_1 \\hspace{.1 in} q_2 \\hspace{.1 in} q_3 \\right]^T\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n     \\mathbf{q}^{\\times} = \\begin{bmatrix}\n       0  & -q_3 &  q_2 \\\\\n      q_3 &   0  & -q_1 \\\\\n     -q_2 &  q_1 &   0  \\\\\n     \\end{bmatrix}\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n    c = \\frac{1}{q_1^2 + q_2^2 + q_3^2 + q_c^2}\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n     \\mathbf{A} = c\\left[ (q_c^2 - \\mathbf{q}^T\\mathbf{q})\\mathbf{I}_3 +\n      2\\mathbf{q}\\mathbf{q}^T -2q_c\\mathbf{q}^{\\times}\\right]\n      \\label{Eq:QuatsToAMat}\n\\end{equation}\n% After an equation, and before text, I can't get \\medskip to work.  So I'm just\n% adding a blank line.\n\n%\nwhere $\\mathbf{I_3}$ is a 3$\\times$3 identity matrix.  Multiplying out\nEq.~\\ref{Eq:QuatsToAMat} we get\n%\n% Inspection of the comments in the equation below will reveal that Dunn would\n% like to implement prettier matrix alignment but hasn't figured out how yet.\n\\begin{multline}\n    %\\begin{align}\n         \\mathbf{A} =\n          c\\left(\n              %& % Start Algigment at left bracket of top matrix\n              \\begin{bmatrix}\n              (q_c^2-q_1^2-q_2^2-q_3^2) &             0             &             0             \\\\\n                          0             & (q_c^2-q_1^2-q_2^2-q_3^2) &             0             \\\\\n                          0             &             0             & (q_c^2-q_1^2-q_2^2-q_3^2) \\\\\n              \\end{bmatrix} + \\right. \\\\\n              %\n              \\left.\n              %& % Align Left bracket of this matrix with bracket above\n              \\begin{bmatrix}\n              q_1^2   & q_1 q_2 & q_1 q_3 \\\\\n              q_2 q_1 & q_2^2   & q_2 q_3 \\\\\n              q_3 q_1 & q_3 q_2 & q_3^2   \\\\\n              \\end{bmatrix} +\n              %\n              \\begin{bmatrix}\n                  0    & -q_c q_3 &  q_c q_2 \\\\\n               q_c q_3 &     0    & -q_c q_1 \\\\\n              -q_c q_2 &  q_c q_1 &     0    \\\\\n              \\end{bmatrix}\n              \\right)\n              %\n          \\label{Eq:QuatsToAMat2}\n    %\\end{align}\n\\end{multline}\n%\nAdding terms in Eq.~\\ref{Eq:QuatsToAMat2} we get\n%\n\\begin{equation}\n    \\mathbf{A} = c\n        %\n        \\begin{bmatrix}\n        q_1^2-q_2^2-q_3^2+q_c^2 &     2(q_1q_2+q_3q_c)     &     2(q_1q_3+q_2q_c)     \\\\\n           2(q_1q_2-q_3q_c)     & -q_1^2+q_2^2-q_3^2+q_c^2 &     2(q_2q_3+q_1q_c)     \\\\\n           2(q_1q_3+q_2q_c)     &     2(q_2q_3-q_1q_c)     & -q_1^2-q_2^2+q_3^2+q_c^2 \\\\\n        \\end{bmatrix}\n        %\n    \\label{Eq:AMatQuats}\n\\end{equation}\n%\nIf we substitute the traditional symbol $q_4$ in for the CCSDS symbol $q_c$, we\nwill get the exact identity shown in Equation 12-13a on Page 414 of Wertz, except\nfor the constant term c.  That is there to normalize the Attitude matrix if the\nquaternion magnitude is not exactly equal to 1.\n\nIt may seem a waste of space to multiply out all these terms when the math was\nso compact in the form shown above in Eq.~\\ref{Eq:QuatsToAMat}.  However, when\ncoding this algorithm, several multiply by zero and add to zero operations will\nbe avoided if Eq.~\\ref{Eq:AMatQuats} is used instead.  So it may be a waste of\nspace, but it is a savings in time when running GMAT.\n\n\n\n\\subsubsection{Conversion:  Attitude Matrix to Quaternions} \\label{sec:AMatToQuat}\n\\index{Attitude Parameterization!Attitude Matrix to Quaternions}\n\nGiven:  $\\mathbf{A}$\n\n\\noindent Find:  $\\mathbf{q}$, $q_c$\n\n\\noindent Name:  \\emph{AMatToQuats}\n\nDefine following vector\n%\n\\begin{equation}\n   \\mathbf{v} = [ \\hspace{.02 in} A_{11} \\hspace{.1 in} A_{22}\\hspace{.1 in}\n   A_{33} \\hspace{.1 in}  \\mbox{trace}(\\mathbf{A}) \\hspace{.02 in}]\n\\end{equation}\n%\nwhere the trace of $\\mathbf{A}$ is\n%\n\\begin{equation}\n    \\text{trace}(\\mathbf{A}) =\n    %\n    A_{11}+A_{22}+A_{33}\n\\end{equation}\n%\nDefine $i_m$ as the index of the maximum component of $\\mathbf{v}$.  Then use\nthe following logic\n%\n\\noindent if $i_m = 1$\n%\n\\begin{equation}\n     \\mathbf{q}''  = \\begin{pmatrix}\n     2v_{i_m} + 1 - \\mbox{trace}(\\mathbf{A})\\\\\n     A_{12} + A_{21}\\\\\n     A_{13} + A_{31}\\\\\n     A_{23} - A_{32}\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\nif $i_m = 2$\n%\n\\begin{equation}\n     \\mathbf{q}''  = \\begin{pmatrix}\n     A_{21} + A_{12}\\\\\n     2v_{i_m} + 1 - \\mbox{trace}(\\mathbf{A})\\\\\n     A_{23} + A_{32}\\\\\n     A_{31} - A_{13}\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\nif $i_m = 3$\n%\n\\begin{equation}\n     \\mathbf{q}''  = \\begin{pmatrix}\n     A_{31} + A_{13}\\\\\n     A_{32} + A_{23}\\\\\n     2v_{i_m} + 1 - \\mbox{trace}(\\mathbf{A})\\\\\n     A_{12} - A_{21}\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\nif $i_m = 4$\n%\n\\begin{equation}\n     \\mathbf{q}''  = \\begin{pmatrix}\n     A_{23} - A_{32}\\\\\n     A_{31} - A_{13}\\\\\n     A_{12} - A_{21}\\\\\n     1 + \\mbox{trace}(\\mathbf{A})\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\nWe normalize $\\mathbf{q}''$ using\n%\n\\begin{equation}\n    \\mathbf{q}' = \\frac{\\mathbf{q}''}{\\| \\mathbf{q}'' \\|}\n\\end{equation}\n%\nFinally,\n%\n\\begin{equation}\n   \\mathbf{q} = [\\hspace{.05 in} q_{1}' \\hspace{.2 in} q_{2}' \\hspace{.2 in} q_3'\n   \\hspace{.05 in}]^T\n\\end{equation}\n%\nand\n%\n\\begin{equation}\n     q_c = q_c'\n\\end{equation}\n%Note: There is not a unique quaternion for a given AMat.  GMAT\n%assumes that the ``+\" sign is used in Eq.~(\\ref{Eq:q_4}).\n\n\\subsubsection{Conversion:  Attitude Matrix to Euler Axis/Angle}\n\n\\index{Attitude Parameterization!AMat to Axis/Angle}\n\nGiven:  $\\mathbf{A}$\n\n\\noindent Find:  $\\mathbf{a}$, $\\phi$\n\n\\noindent Name:  \\emph{AMatToEulAxisAngle}\n\n\\begin{equation}\n     \\mathbf{A}  = \\begin{pmatrix}\n     A_{11} & A_{12} & A_{13}\\\\\n     A_{21} & A_{22} & A_{23}\\\\\n     A_{31} & A_{32} & A_{33}\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\n\\begin{equation}\n   \\phi = \\cos^{-1}\\left( \\frac{1}{2}\\left(\\mbox{trace}(\\mathbf{A}) -\n   1 \\right)\\right)\n\\end{equation}\n%\n\\begin{equation}\n    \\mathbf{a} = \\frac{1}{2\\sin{\\phi}}\\begin{pmatrix}\n     A_{23} - A_{32}\\\\\n     A_{31} - A_{13}\\\\\n     A_{12} - A_{21}\\\\\n     \\end{pmatrix}\n\\end{equation}\n%\nIf $\\|\\sin{\\phi} \\| < 10^{-14}$, then we assume\n%\n\\begin{equation}\n    \\mathbf{a} = \\left[\\hspace{.05 in} 1 \\hspace{.1 in} 0 \\hspace{.1 in}\n    0 \\hspace{.05 in} \\right]^T\n\\end{equation}\n%\nNote that if $\\|\\sin{\\phi} \\| < 10^{-14}$ then $\\cos{\\phi} \\approx\n1 $ and we arrive at an Attitude matrix of $\\mathbf{I}_3$.\n\n\\subsubsection{Conversion:  Euler Axis/Angle to Attitude Matrix} \\index{Attitude\nParameterization!Axis/Angle to Attitude Matrix} \\label{Sec:EulerAxis/AngleToAMat}\n\nGiven:  $\\mathbf{a}$, $\\phi$\n\n\\noindent Find:  $\\mathbf{A}$\n\n\\noindent Name:  \\emph{EulAxisAngleToAMat}\n%\n\\begin{equation}\n     \\mathbf{a}^{\\times} = \\begin{pmatrix}\n           0  & -a_3 &  a_2 \\\\\n          a_3 &   0  & -a_1 \\\\\n         -a_2 &  a_1 &   0  \\\\\n     \\end{pmatrix}\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n    \\mathbf{A} = \\cos{\\phi}\\mathbf{I}_3 +\n    (1 - \\cos{\\phi})\\mathbf{a}\\mathbf{a}^T -\n    \\sin{\\phi}\\mathbf{a}^{\\times}\n    \\label{Eq:AMat}\n\\end{equation}\n%\nMultiplying out the terms in Eq.~\\ref{Eq:AMat} we get\n%\n\\begin{equation}\n    \\mathbf{A} =\n        \\begin{pmatrix}\n            \\cos{\\phi} &     0      &     0      \\\\\n                0      & \\cos{\\phi} &     0      \\\\\n                0      &     0      & \\cos{\\phi} \\\\\n        \\end{pmatrix} +\n        (1 - \\cos{\\phi})\n        \\begin{pmatrix}\n            a_1^2   & a_1 a_2 & a_1 a_3 \\\\\n            a_2 a_1 & a_2^2   & a_2 a_3 \\\\\n            a_3 a_1 & a_3 a_2 & a_3^2   \\\\\n        \\end{pmatrix} -\n        \\sin{\\phi}\n        \\begin{pmatrix}\n           0  & -a_3 &  a_2 \\\\\n          a_3 &   0  & -a_1 \\\\\n         -a_2 &  a_1 &   0  \\\\\n        \\end{pmatrix}\n    \\label{Eq:AMat2}\n\\end{equation}\n%\nContinuing to multiply and sum terms, Eq.~\\ref{Eq:AMat2} becomes nine separate\nequations, one for each of the elements of the Attitude Matrix.\n%\n\\begin{equation}\n    \\begin{aligned}\n        \\mathbf{A}_{11} &= \\cos{\\phi} + a_1^2 - a_1^2\\cos{\\phi}          \\\\\n        \\mathbf{A}_{12} &= a_1 a_2 - a_1 a_2 \\cos{\\phi} + a_3 \\sin{\\phi} \\\\\n        \\mathbf{A}_{13} &= a_1 a_3 - a_1 a_3 \\cos{\\phi} - a_2 \\sin{\\phi} \\\\\n        %\n        \\mathbf{A}_{21} &= a_2 a_1 - a_2 a_1 \\cos{\\phi} - a_3 \\sin{\\phi} \\\\\n        \\mathbf{A}_{22} &= \\cos{\\phi} + a_2^2 - a_2^2\\cos{\\phi}          \\\\\n        \\mathbf{A}_{23} &= a_2 a_3 - a_2 a_3 \\cos{\\phi} + a_1 \\sin{\\phi} \\\\\n        %\n        \\mathbf{A}_{31} &= a_3 a_1 - a_3 a_1 \\cos{\\phi} + a_2 \\sin{\\phi} \\\\\n        \\mathbf{A}_{32} &= a_3 a_2 - a_3 a_2 \\cos{\\phi} - a_1 \\sin{\\phi} \\\\\n        \\mathbf{A}_{33} &= \\cos{\\phi} + a_3^2 - a_3^2\\cos{\\phi}\n    \\end{aligned}\n    \\label{Eq:NineAMatEquations}\n\\end{equation}\n%\nIt may seem a waste of space to multiply out all these terms when the math was so\ncompact in the form shown above in Eq.~\\ref{Eq:AMat}.  However, when coding this\nalgorithm, several multiply by zero operations will be avoided if\nEquations~\\ref{Eq:NineAMatEquations} are used instead.  So it may be a waste of\nspace, but it is a savings in time when running GMAT.\n%\n\\subsubsection{Conversion:  Euler Angles to Attitude Matrix}\n\\label{sec:EulerAnglestoAMat}\n\nGiven:  Sequence order  ( i.e. 123, 121, ...$\\boldsymbol{321}$,...313),\n$\\theta_1$, $\\theta_2$, $\\theta_3$\n\n\\noindent Find: $\\mathbf{A}$\n\n\\noindent Name:  \\emph{EulerAnglesToAMat}\n\nWe'll give an example for a 321 rotation, and then present results\nfor the remaining 11 Euler angle sequences.  First, let's define\n$\\mathbf{A}_3(\\theta_1)$, $\\mathbf{A}_2(\\theta_2)$, and\n$\\mathbf{A}_1(\\theta_3)$.\n%\n\\begin{equation}\n    \\mathbf{A}_3(\\theta_1) =\n        \\begin{pmatrix}\n             \\cos{\\theta_1} & \\sin{\\theta_1} & 0 \\\\\n            -\\sin{\\theta_1} & \\cos{\\theta_1} & 0 \\\\\n                  0         &      0         & 1\n        \\end{pmatrix}\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n    \\mathbf{A}_2(\\theta_2) =\n        \\begin{pmatrix}\n            \\cos{\\theta_2} & 0 & -\\sin{\\theta_2} \\\\\n                 0         & 1 &       0         \\\\\n            \\sin{\\theta_2} & 0 &  \\cos{\\theta_2}\n        \\end{pmatrix}\n\\end{equation}\n\\medskip\n%\n\\begin{equation}\n    \\mathbf{A}_1(\\theta_3) =\n        \\begin{pmatrix}\n            1 &       0         &      0         \\\\\n            0 &  \\cos{\\theta_3} & \\sin{\\theta_3} \\\\\n            0 & -\\sin{\\theta_3} & \\cos{\\theta_3}\n    \\end{pmatrix}\n\\end{equation}\n%\nNow we can write\n%\n\\begin{equation}\n    \\mathbf{A}_{321} = \\mathbf{A}_1(\\theta_3)\\mathbf{A}_2(\\theta_2)\\mathbf{A}_3(\\theta_1) = \\\\\n    %\n    \\medskip\n    \\begin{pmatrix}\n        1 &   0  &  0  \\\\\n        0 &  c_3 & s_3 \\\\\n        0 & -s_3 & c_3\n    \\end{pmatrix}\n    %\n    \\begin{pmatrix}\n        c_2 & 0 & -s_2 \\\\\n         0  & 1 &   0  \\\\\n        s_2 & 0 &  c_2\n    \\end{pmatrix}\n    %\n    \\begin{pmatrix}\n         c_1 & s_1 & 0 \\\\\n        -s_1 & c_1 & 0 \\\\\n          0  &  0  & 1\n    \\end{pmatrix}\n\\end{equation}\n%\nwhere $c_1 =\\cos{\\theta_1}$, $s_1 = \\sin{\\theta_1}$ etc.  We can\nrewrite $\\mathbf{A}_{321} $ as\n%\n\\begin{equation}\n    \\mathbf{A}_{321} =\n        \\begin{pmatrix}\n             c_2 c_1        &      c_2 s_1        & -s_2    \\\\\n        -c_3s_1 + s_3s_2c_1 &  c_3c_1 + s_3s_2s_1 &  s_3c_2 \\\\\n         s_3s_1 + c_3s_2c_1 & -s_3c_1 + c_3s_2s_1 &  c_3c_2\n     \\end{pmatrix}\n     \\label{Eq:A321}\n\\end{equation}\n%\nEquation~\\ref{Eq:A321} is equivalent to the matrix at the bottom of\nthe left hand column of Table E-1 on Page 764 of Wertz.  The approach for\nobtaining the Attitude matrix is similar for the remaining 11 Euler angle\nsequences.  Rather than derive the Attitude matrices for the remaining 11\nsequences, we present them in Table \\ref{table:EulerAnglestoDCM}.\n\n\\subsubsection{Conversion: Attitude Matrix to Euler Angles}\n\\label{sec:AttitudeMatrixtoEulerAngles}\n\nGiven: Sequence order  ( i.e. 123, 121, ...$\\boldsymbol{321}$,...313), $\\mathbf{A}$\n\n\\noindent Find:  $\\theta_1$, $\\theta_2$, $\\theta_3$\n\n\\noindent Name:  \\emph{AMatToEulerAngles}\n\nWe'll give an example for a 321 rotation, and then present results\nfor the remaining 11 Euler angle sequences.  Examining,\nEq.~\\ref{Eq:A321}, we see that\n%\n\\begin{equation}\n     \\frac{A_{21} }{ A_{11}} = \\frac{\\cos{\\theta_2}\\sin{\\theta_1}}\n                                    {\\cos{\\theta_2}\\cos{\\theta_1}}\n\\end{equation}\n%\nFrom this we can see that\n%\n\\begin{equation}\n    \\theta_1 =  \\tan^{-1}{\\frac{ A_{21} }  { A_{11}  }}\n\\end{equation}\n%\nFurther inspection of Eq.~\\ref{Eq:A321} shows us that\n%\n\\begin{equation}\n    \\theta_2 = \\sin^{-1}{A_{13}}\n\\end{equation}\n%\nAt first glance, we may choose to calculate $\\theta_3$ using\n$\\theta_3 = \\tan^{-1}{(A_{23}/A_{33})}$.  However, in the case that\n$\\theta_2 = 90^\\circ$, this would result in the indeterminate case,\n$\\theta_3 =$ $\\tan^{-1}(A_{23}/A_{33})$ $= \\tan^{-1}(0/0)$.  An\nimproved method, found in the ADEAS mathematical specifications\ndocument, is to determine $\\theta_3$ using\n%\n\\begin{equation}\n    \\theta_3 = \\tan^{-1} \\left(\\frac{ A_{31} \\sin{\\theta_1} - A_{32} \\cos{\\theta_1} }\n    { -A_{21} \\sin{\\theta_1} + A_{22} \\cos{\\theta_1}} \\right)\n    \\label{Eq:Atotheta3}\n\\end{equation}\n%\nSubstituting values from Eq.~\\ref{Eq:A321} into\nEq.~\\ref{Eq:Atotheta3}, and using abbreviated notation, we see\nthat\n%\n\\begin{equation}\n     \\theta_3 = \\tan^{-1} \\left(  \\frac{ s_1( s_3s_1 + c_3s_2c_1) - c_1(-s_3c_1 + c_3s_2s_1 )}\n    { s_1(c_3s_1 - s_3s_2c_1  ) + c_1( c_3c_1 + s_3s_2s_1 ) }  \\right)\n\\end{equation}\n%\nNow, if $\\theta_2 = 90^\\circ$, and we substitute $c_2 = 0$ and $s_2 = 1$ into\nthe above equation, we see we get a determinate form.\nResults for all twelve Euler Sequences are shown in Table\n\\ref{table:AMatToEulerAngles}.\n\n\\noindent Note:  For all $\\tan^{-1}$ we need to use a quadrant check ( equivalent\nto atan2 ) to make sure the the correct quadrant is chosen.\n\n\\subsubsection{Conversion:  Angular Velocity to \\\\ Euler Angles\nRates}\n\nGiven:  Sequence ( i.e. 123, 121, .... 313), $\\theta_2$,\n$\\theta_3$ $\\boldsymbol\\omega$\n\n\\noindent Find: $\\dot\\theta_1$, $\\dot\\theta_2$, $\\dot\\theta_3$\n\n\\noindent Name:  \\emph{AngVelToEulerAngles}\n%\n\\begin{equation}\n    \\begin{pmatrix}\n         \\dot\\theta_1\\\\\n         \\dot\\theta_2\\\\\n         \\dot\\theta_3\n    \\end{pmatrix}\n    %\n    = \\mathbf{S}^{-1}(\\theta_2,\\theta_3)\\boldsymbol\\omega\n\\end{equation}\n%\n$\\mathbf{S}^{-1}(\\theta_2,\\theta_3)$ is dependent upon the Euler\nsequence.  Table \\ref{table:EulerAngleKinematics} contains the\ndifferent expressions for $\\mathbf{S}^{-1}(\\theta_2,\\theta_3)$ for\neach of the 12 unique Euler sequences.\n\nNote:  Each of the forms of $\\mathbf{S}^{-1}$ have a possible\nsingularity due to the appearance of either $\\sin{\\theta_2}$ or\n$\\cos{\\theta_2}$ in the denominator.  If GMAT encounters a\nsingularity, an error message is thrown, and the zero vector is\nreturned.\n\n\\subsubsection{Conversion:  Euler Angles Rates to Angular Velocity}\n\n\\noindent Given: Sequence ( i.e. 123, 121, .... 313), $\\theta_2$,\n$\\theta_3$, $\\dot\\theta_1$, $\\dot\\theta_2$, $\\dot\\theta_3$\n\n\\noindent Find: $\\boldsymbol\\omega$\n\n\\noindent Name:  \\emph{EulerAnglesToAngVel}\n%\n\\begin{equation}\n    \\boldsymbol\\omega = \\mathbf{S}(\\theta_2,\\theta_3)\n    %\n        \\begin{pmatrix}\n         \\dot\\theta_1\\\\\n         \\dot\\theta_2\\\\\n         \\dot\\theta_3\n    \\end{pmatrix}\n\\end{equation}\n%\n$\\mathbf{S}(\\theta_2,\\theta_3)$ is dependent upon the Euler\nsequence.  Table \\ref{table:EulerAngleKinematics} contains the\ndifferent expressions for $\\mathbf{S}^{-1}(\\theta_2,\\theta_3)$ for\neach of the 12 unique Euler sequences.\n\n\\newpage\n\\subsubsection{Conversion:  Quaternions to Euler Angles}\n\n\\noindent Given: $\\mathbf{q}$, $q_4$, Euler Sequence\n\n\\noindent Find: $\\theta_1$, $\\theta_2$, and $\\theta_3$\n\n\\noindent Name:  \\emph{QuatsToEulerAngles}\n\nThere is not a direct transformation to convert from the quaternions to the Euler\nAngles.  GMAT first converts from the quaternion to the Attitude matrix using the\nalgorithm presented above called ``QuatsToAMat\". % in Sec.~\\ref{sec:QuatToAMat}.\nThe Attitude matrix is then used to\ncalculate the Euler Angles for the given Euler angle sequence using the algorithm\ncalled ``AMatToEulerAngles:. % in Sec.~\\ref{sec:AttitudeMatrixtoEulerAngles}.\n\n\n\\subsubsection{Conversion:  Euler Angles to Quaternions}\n\n\\noindent Given: $\\theta_1$, $\\theta_2$, and $\\theta_3$, Euler\nSequence\n\n\\noindent Find: $\\mathbf{q}$, $q_4$\n\n\\noindent Name:  \\emph{EulerAnglesToQuats}\n\nThere is not a direct transformation to convert from Euler Angles to quaternions.\nGMAT first converts from the Euler Angles to the Attitude matrix using the\nalgorithm above called ``EulerAnglesToAMat\". % in Sec.~\\ref{sec:EulerAnglestoAMat}.\nThe Attitude matrix is then used to\ncalculate the quaternions using the algorithm\ncalled ``AMatToQuats\". % in Sec.~\\ref{sec:AMatToQuat}.\n\n\n\\newpage\n\\begin{table}[h]\n    \\centering\n    \\vspace{0 pt}\n    \\caption{Attitude Matrices for 12 Unique Euler Angle Rotation Sequences}\n    \\begin{tabular}{clccccccc}  \\hline \\hline \\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.25 in}  c_3 c_2  &  \\hspace{0.3 in}  c_3 s_2 s_1 + s_3 c_1  &  \\hspace{0.1 in} -c_3 s_2 c_1 + s_1 s_3  \\\\\n            \\hspace{0.2 in}  -s_3 c_2  &  \\hspace{0.3 in} -s_3 s_2 s_1 + c_3 c_1  &  \\hspace{0.1 in}  s_3 s_2 c_1 + c_3 s_1  \\\\\n            \\hspace{0.3 in}     s_2    &  \\hspace{0.3 in}          -c_2 s_1       &  \\hspace{0.1 in}           c_2 c_1       \\\\\n        \\end{pmatrix}\n        \\vspace{.1 in}$ \\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n             \\hspace{0.3 in} c_3 c_2  &  \\hspace{0.4 in}  c_3 s_2 c_1 + s_1 s_3  &  \\hspace{0.2 in}  c_3 s_2 s_1 - s_3 c_1  \\\\\n             \\hspace{0.3 in}  -s_2    &  \\hspace{0.4 in}          c_2 c_1        &  \\hspace{0.2 in}           c_2 s_1       \\\\\n             \\hspace{0.3 in} s_3 c_2  &  \\hspace{0.4 in}  s_3s_2c_1 - c_3s_1     &  \\hspace{0.2 in}  s_3 s_2 s_1 + c_3 c_1  \\\\\n        \\end{pmatrix}   \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.0 in}           c_2 c_1       &  \\hspace{0.3 in}    s_2    &  \\hspace{0.3 in}          -c_2 s_1      \\\\\n            \\hspace{0.0 in} -c_3 s_2 c_1 + s_3 s_1  &  \\hspace{0.3 in}  c_3 c_2  &  \\hspace{0.3 in} c_3 s_2 s_1 + s_3 c_1  \\\\\n            \\hspace{0.0 in}  s_3 s_2 c_1 + c_3 s_1  &  \\hspace{0.3 in} -s_3 c_2  &  \\hspace{0.3 in} -s_3 s_2 s_1 + c_3 c_1 \\\\\n        \\end{pmatrix}   \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.0 in}  c_3 c_1 + s_3 s_2 s_1  &  \\hspace{0.4 in} s_3 c_2  &  \\hspace{0.3 in} -c_3 s_1 + s_3 s_2 c_1  \\\\\n            \\hspace{0.0 in} -s_3 c_1 + c_3 s_2 s_1  &  \\hspace{0.4 in} c_3 c_2  &  \\hspace{0.3 in}  s_3 s_1 + c_3 s_2 c_1  \\\\\n            \\hspace{0.0 in}       c_2 s_1           &  \\hspace{0.4 in}  -s_2    &  \\hspace{0.3 in}       c_2 c_1           \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.1 in} c_3 c_1 - s_3 s_2 s_1  &  \\hspace{0.1 in} c_3 s_1 + s_3 s_2 c_1  &  \\hspace{0.4 in} -s_3 c_2 \\hspace{0.2 in} \\\\\n            \\hspace{0.1 in}     -c_2 s_1           &  \\hspace{0.1 in}      c_2 c_1           &  \\hspace{0.4 in}    s_2   \\hspace{0.2 in} \\\\\n            \\hspace{0.1 in} s_3 c_1 + c_3 s_2 s_1  &  \\hspace{0.1 in} s_3 s_1 - c_3 s_2 c_1  &  \\hspace{0.4 in}  c_3 c_2 \\hspace{0.2 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.0 in}       c_2 c_1           &  \\hspace{0.1 in}       c_2 s_1           &  \\hspace{0.4 in}   -s_2   \\hspace{0.2 in} \\\\\n            \\hspace{0.0 in} -c_3 s_1 + s_3 s_2 c_1  &  \\hspace{0.1 in}  c_3 c_1 + s_3 s_2 s_1  &  \\hspace{0.4 in}  s_3 c_2 \\hspace{0.2 in} \\\\\n            \\hspace{0.0 in}  s_3 s_1 + c_3 s_2 c_1  &  \\hspace{0.1 in} -s_3 c_1 +c_3 s_2 s_1   &  \\hspace{0.4 in}  c_3 c_2 \\hspace{0.2 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.3 in}    c_2    &  \\hspace{0.4 in}       s_2 s_1           &      -s_2 c_1           \\\\\n            \\hspace{0.3 in}  s_3 s_2  &  \\hspace{0.4 in}  c_3 c_1 - s_3 c_2 s_1  &  c_3 s_1 + s_3 c_2 c_1  \\\\\n            \\hspace{0.3 in}  c_3 s_2  &  \\hspace{0.4 in} -s_3 c_1 - c_3 c_2 s_1  & -s_3 s_1 + c_3 c_2 c_1  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.2 in}     c_2    &  \\hspace{0.4 in}       s_2 c_1            &           s_2 s_1       \\\\\n            \\hspace{0.2 in}  -c_3 s_2  &  \\hspace{0.4 in}   c_3 c_2 c_1 - s_3 s_1  &  c_3 c_2 s_1 + s_3 c_1  \\\\\n            \\hspace{0.2 in}   s_3 s_2  &  \\hspace{0.4 in}  -s_3 c_2 c_1 - c_3 s_1  & -s_3 c_2 s_1 + c_3 c_1  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}  c_3 c_1 - s_3 c_2 s_1  &  \\hspace{0.4 in}   s_3 s_2  &  \\hspace{0.2 in}  -c_3 s_1 - s_3 c_2 c_1  \\hspace{0.05 in} \\\\\n            \\hspace{0.05 in}       s_2 s_1           &  \\hspace{0.4 in}     c_2    &  \\hspace{0.2 in}        s_2 c_1           \\hspace{0.05 in} \\\\\n            \\hspace{0.05 in}  s_3 c_1 + c_3 c_2 s_1  &  \\hspace{0.4 in}  -c_3 s_2  &  \\hspace{0.2 in}  -s_3 s_1 + c_3 c_2 c_1  \\hspace{0.05 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %-------------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}  c_3 c_2 c_1 - s_3 s_1   &  \\hspace{0.45 in}  c_3 s_2  &  \\hspace{0.25 in}  -c_3 c_2 s_1 - s_3 c_1  \\hspace{0.05 in} \\\\\n            \\hspace{0.05 in}          -s_2 c_1        &  \\hspace{0.45 in}    c_2    &  \\hspace{0.25 in}            s_2 s_1       \\hspace{0.05 in} \\\\\n            \\hspace{0.05 in}  s_3 c_2 c_1 + c_3 s_1   &  \\hspace{0.45 in}  s_3 s_2  &  \\hspace{0.25 in}  -s_3 c_2 s_1 + c_3 c_1  \\hspace{0.05 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %-------------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}   c_3 c_1 - s_3 c_2 s_1  &  \\hspace{0.05 in}   c_3 s_1 + s_3 c_2 c_1  &  \\hspace{0.35 in}  s_3 s_2  \\hspace{0.25 in} \\\\\n            \\hspace{0.05 in}  -s_3 c_1 - c_3 c_2 s_1  &  \\hspace{0.05 in}  -s_3 s_1 + c_3 c_2 c_1  &  \\hspace{0.35 in}  c_3 s_2  \\hspace{0.25 in} \\\\\n            \\hspace{0.05 in}        s_2 s_1           &  \\hspace{0.05 in}       -s_2 c_1           &  \\hspace{0.35 in}    c_2    \\hspace{0.25 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %-------------------------------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{A} = \\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1) = $\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}  c_3 c_2 c_1  -s_3 s_1  &  \\hspace{0.05 in}   c_3 c_2 s_1 + s_3 c_1  &  \\hspace{0.3 in}  -c_3 s_2  \\hspace{0.2 in} \\\\\n            \\hspace{0.05 in} -s_3 c_2 c_1 - c_3 s_1  &  \\hspace{0.05 in}  -s_3 c_2 s_1 + c_3 c_1  &  \\hspace{0.3 in}   s_3 s_2  \\hspace{0.2 in} \\\\\n            \\hspace{0.05 in}           s_2 c_1       &  \\hspace{0.05 in}            s_2 s_1       &  \\hspace{0.3 in}     c_2    \\hspace{0.2 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n\n        \\hline \\hline\n        \\normalsize\n        \\end{tabular}\n        \\label{table:EulerAnglestoDCM}\n\\end{table}\n\n\n\\begin{table}[h]\n        \\centering\n        \\caption{Kinematics of Euler Angle Rotation Sequences}\n        \\begin{tabular}{cllcccccc}  \\hline \\hline \\\\\n        Euler Sequence & \\hspace{0.2 in} $\\mathbf{S}(\\theta_2,\\theta_3)$ &\n        $\\hspace{0.7 in} \\mathbf{S}^{-1}(\\theta_2,\\theta_3)$\\\\\n        \\hline\n        \\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n             c_3 c_2  &  s_3  &  0  \\\\\n            -s_3 c_2  &  c_3  &  0  \\\\\n               s_2    &   0   &  1  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}    c_3 / c_2     &  \\hspace{0.05 in}  -s_3 / c_2     &  \\hspace{0.3 in}  0  \\hspace{0.25 in} \\\\\n            \\hspace{0.05 in}       s_3        &  \\hspace{0.05 in}      c_3        &  \\hspace{0.3 in}  0  \\hspace{0.25 in} \\\\\n            \\hspace{0.05 in}  -s_2 c_3 / c_2  &  \\hspace{0.05 in}  s_3 s_2 / c_2  &  \\hspace{0.3 in}  1  \\hspace{0.25 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            c_3 c_2  &  -s_3  &  0  \\\\\n             -s_2    &    0   &  1  \\\\\n            s_3 c_2  &   c_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.1 in}   c_3 / c_2     &  \\hspace{0.3 in}  0  &  \\hspace{0.25 in}   s_3 / c_2     \\hspace{0.1 in}  \\\\\n            \\hspace{0.1 in}     -s_3        &  \\hspace{0.3 in}  0  &  \\hspace{0.25 in}      c_3        \\hspace{0.1 in}  \\\\\n            \\hspace{0.1 in}  s_2 c_3 / c_2  &  \\hspace{0.3 in}  1  &  \\hspace{0.25 in}  s_3 s_2 / c_2  \\hspace{0.1 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n               s_2    &   0   &  1  \\\\\n             c_3 c_2  &  s_3  &  0  \\\\\n            -s_3 c_2  &  c_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.3 in}  0  &  \\hspace{0.2 in}    c_3 / c_2     &  \\hspace{0.05 in}  -s_3 / c_2     \\hspace{0.1 in}  \\\\\n            \\hspace{0.3 in}  0  &  \\hspace{0.2 in}       s_3        &  \\hspace{0.05 in}      c_3        \\hspace{0.1 in}  \\\\\n            \\hspace{0.3 in}  1  &  \\hspace{0.2 in}  -s_2 c_3 / c_2  &  \\hspace{0.05 in}  s_3 s_2 / c_2  \\hspace{0.1 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            s_3 c 2  &   c_3  &  0  \\\\\n            c_3 c_2  &  -s_3  &  0  \\\\\n             -s_2    &    0   &  1  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.1 in}   s_3 / c_2     &  \\hspace{0.15 in}   c_3 / c_2     &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.1 in}      c_3        &  \\hspace{0.15 in}     -s_3        &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.1 in}  s_3 s_2 / c_2  &  \\hspace{0.15 in}  s_2 c_3 / c_2  &  \\hspace{0.25 in}  1  \\hspace{0.25 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            -s_3 c_2  &  c_3  &  0  \\\\\n               s_2    &   0   &  1  \\\\\n             c_3 c_2  &  s_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.1 in}   -s_3 / c_2     &   \\hspace{0.3 in}  0  &  \\hspace{0.2 in}   c_3 / c_2     \\hspace{0.05 in}  \\\\\n            \\hspace{0.1 in}       c_3        &   \\hspace{0.3 in}  0  &  \\hspace{0.2 in}      s_3        \\hspace{0.05 in}  \\\\\n            \\hspace{0.1 in}   s_3 s_2 / c_2  &   \\hspace{0.3 in}  1  &  \\hspace{0.2 in} -s_2 c_3 / c_2  \\hspace{0.05 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n             -s_2    &    0   &  1  \\\\\n            s_3 c_2  &   c_3  &  0  \\\\\n            c_3 c_2  &  -s_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.3 in}  0  &  \\hspace{0.3 in}   s_3 / c_2     &  \\hspace{0.05 in}   c_3 / c_2     \\hspace{0.1 in} \\\\\n            \\hspace{0.3 in}  0  &  \\hspace{0.3 in}      c_3        &  \\hspace{0.05 in}     -s_3        \\hspace{0.1 in} \\\\\n            \\hspace{0.3 in}  1  &  \\hspace{0.3 in}  s_3 s_2 / c_2  &  \\hspace{0.05 in}  s_2 c_3 / c_2  \\hspace{0.1 in} \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n              c_2    &    0   &  1  \\\\\n            s_3 s_2  &   c_3  &  0  \\\\\n            c_3 s_2  &  -s_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.3 in}  0  &  \\hspace{0.2 in}   s_3 / s_2     &  \\hspace{0.0 in}    c_3 / s_2     \\hspace{0.05 in}  \\\\\n            \\hspace{0.3 in}  0  &  \\hspace{0.2 in}      c_3        &  \\hspace{0.0 in}      -s_3        \\hspace{0.05 in}  \\\\\n            \\hspace{0.3 in}  1  &  \\hspace{0.2 in} -s_3 c_2 / s_2  &  \\hspace{0.0 in}  -c_3 c_2 / s_2  \\hspace{0.05 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n                c_2    &   0   &  1  \\\\\n             -c_3 s_2  &  s_3  &  0  \\\\\n              s_3 s_2  &  c_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.3 in}  0  &  \\hspace{0.3 in}  -c_3 / s_2    &  \\hspace{0.0 in}    s_3 / s_2     \\hspace{0.05 in}  \\\\\n            \\hspace{0.3 in}  0  &  \\hspace{0.3 in}      s_3       &  \\hspace{0.0 in}       c_3        \\hspace{0.05 in}  \\\\\n            \\hspace{0.3 in}  1  &  \\hspace{0.3 in}  c_3 c_2 / s_2 &  \\hspace{0.0 in}  -s_3 c_2 / s_2  \\hspace{0.05 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n             s_3 s_2  &  c_3  &  0  \\\\\n               c_2    &   0   &  1  \\\\\n            -c_3 s_2  &  s_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}    s_3 / s_2     &  \\hspace{0.25 in}  0  &  \\hspace{0.25 in}  -c_3 / s_2     \\hspace{0.1 in}  \\\\\n            \\hspace{0.05 in}       c_3        &  \\hspace{0.25 in}  0  &  \\hspace{0.25 in}      s_3        \\hspace{0.1 in}  \\\\\n            \\hspace{0.05 in}  -s_3 c_2 / s_2  &  \\hspace{0.25 in}  1  &  \\hspace{0.25 in}  c_3 c_2 / s_2  \\hspace{0.1 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            c_3 s_2  &  -s_3  &  0  \\\\\n              c_2    &    0   &  1  \\\\\n            s_3 s_2  &   c_3  &  0  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}    c_3 / s_2     &  \\hspace{0.25 in}  0  &  \\hspace{0.2 in}    s_3 / s_2     \\hspace{0.05 in}  \\\\\n            \\hspace{0.05 in}      -s_3        &  \\hspace{0.25 in}  0  &  \\hspace{0.2 in}       c_3        \\hspace{0.05 in}  \\\\\n            \\hspace{0.05 in}  -c_3 c_2 / s_2  &  \\hspace{0.25 in}  1  &  \\hspace{0.2 in}  -s_3 c_2 / s_2  \\hspace{0.05 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            s_3 s_2  &   c_3  &  0  \\\\\n            c_3 s_2  &  -s_3  &  0  \\\\\n              c_2    &    0   &  1  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.05 in}    s_3 / s_2     &  \\hspace{0.0 in}    c_3 / s_2     &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.05 in}       c_3        &  \\hspace{0.0 in}      -s_3        &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.05 in}  -s_3 c_2 / s_2  &  \\hspace{0.0 in}  -c_3 c_2 / s_2  &  \\hspace{0.25 in}  1  \\hspace{0.25 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n    \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            -c_3 s_2  &  s_3  &  0  \\\\\n             s_3 s_2  &  c_3  &  0  \\\\\n               c_2    &   0   &  1  \\\\\n        \\end{pmatrix}$\n        &\n        \\footnotesize\n        $\\begin{pmatrix}\n            \\hspace{0.1 in}  -c_3 / s_2     &  \\hspace{0.05 in}    s_3 / s_2     &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.1 in}      s_3        &  \\hspace{0.05 in}       c_3        &  \\hspace{0.25 in}  0  \\hspace{0.25 in}  \\\\\n            \\hspace{0.1 in}  c_3 c_2 / s_2  &  \\hspace{0.05 in}  -s_3 c_2 / s_2  &  \\hspace{0.25 in}  1  \\hspace{0.25 in}  \\\\\n        \\end{pmatrix}  \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\hline \\hline\n        \\end{tabular}\n        \\label{table:EulerAngleKinematics}\n\\end{table}\n\n\n\\begin{landscape}\n\\begin{table}[h]\n        \\centering\n        \\vspace{0 pt}\n        \\caption{ Computation of Euler Angles from Attitude Matrix}\n        \\begin{tabular}{llllllll}  \\hline \\hline \\\\\n        % Note the blanks between $$ symbols below help align the equations in the table\n        Euler Sequence \\hspace{0.5 in} & $ $ & Euler Angle Computations \\hspace{-1.1 in} & $ $ \\\\\n        \\hline \\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        \\hspace{.1 in}\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(-A_{32}/A_{33})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(A_{31})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{13}\\sin{\\theta_1}+\n        A_{12}\\cos{\\theta_1}}{A_{23}\\sin{\\theta_1}+A_{22}\\cos{\\theta_1}}\\hspace{0.15 in}\\right ) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1)$ \\hspace{.1 in}\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{23}/A_{22})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(-A_{21})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{12}\\sin{\\theta_1}- A_{13}\\cos{\\theta_1}}{-A_{32}\\sin{\\theta_1}+\n        A_{33}\\cos{\\theta_1}}\\hspace{0.05 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(-A_{13}/A_{11})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(A_{12})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{21}\\sin{\\theta_1}+ A_{23}\\cos{\\theta_1}}{A_{31}\\sin{\\theta_1}+\n        A_{33}\\cos{\\theta_1}}\\hspace{0.15 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{31}/A_{33})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(-A_{32})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{23}\\sin{\\theta_1}- A_{21}\\cos{\\theta_1}}{-A_{13}\\sin{\\theta_1}+\n        A_{11}\\cos{\\theta_1}}\\hspace{0.05 in}\\right) \\vspace{.1 in} $\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(-A_{21}/A_{22})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(A_{23})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{32}\\sin{\\theta_1}+ A_{31}\\cos{\\theta_1}}{A_{12}\\sin{\\theta_1}+\n        A_{11}\\cos{\\theta_1}}\\hspace{0.15 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{12}/A_{11})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\sin^{-1}(-A_{13})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{A_{31}\\sin{\\theta_1}- A_{32}\\cos{\\theta_1}}{-A_{21}\\sin{\\theta_1}+\n        A_{22}\\cos{\\theta_1}}\\hspace{0.05 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{12}/-A_{13})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{11})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{-A_{33}\\sin{\\theta_1}- A_{32}\\cos{\\theta_1}}{A_{23}\\sin{\\theta_1}+\n        A_{22}\\cos{\\theta_1}}\\hspace{0.05 in}\\right)\\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_1(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_1(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{13}/A_{12})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{11})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{-A_{22}\\sin{\\theta_1} + A_{23}\\cos{\\theta_1}}{-A_{32}\\sin{\\theta_1}+\n        A_{33}\\cos{\\theta_1}}\\hspace{0.05 in}\\right)$ \\vspace{.1 in}\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{21}/A_{23})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{22})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{-A_{33}\\sin{\\theta_1} + A_{31}\\cos{\\theta_1}}{-A_{13}\\sin{\\theta_1}+\n        A_{11}\\cos{\\theta_1}}\\hspace{0.05 in}\\right)$ \\vspace{.1 in}\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_2(\\theta_3)\\mathbf{R}_3(\\theta_2)\\mathbf{R}_2(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{23}/-A_{21})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{22})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\displaystyle\\frac{-A_{11}\\sin{\\theta_1} - A_{13}\\cos{\\theta_1}}{A_{31}\\sin{\\theta_1}+\n        A_{33}\\cos{\\theta_1}}\\hspace{0.10 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_1(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{31}/-A_{32})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{33})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{-A_{22}\\sin{\\theta_1} - A_{21}\\cos{\\theta_1}}{A_{12}\\sin{\\theta_1}+\n        A_{11}\\cos{\\theta_1}}\\hspace{0.05 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\footnotesize\n        $\\mathbf{R}_3(\\theta_3)\\mathbf{R}_2(\\theta_2)\\mathbf{R}_3(\\theta_1)$\n        &\n        \\footnotesize\n        $\\theta_1 =  \\tan^{-1}(A_{32}/A_{31})$\n        &\n        \\footnotesize\n        $\\theta_2 =  \\cos^{-1}(A_{33})$\n        &\n        \\footnotesize\n        $\\theta_3  = \\tan^{-1}\\left(\\hspace{0.05 in}\\displaystyle\\frac{-A_{11}\\sin{\\theta_1} + A_{12}\\cos{\\theta_1}}{-A_{21}\\sin{\\theta_1}+\n        A_{22}\\cos{\\theta_1}}\\hspace{0.05 in}\\right) \\vspace{.1 in}$\\\\\n        %\n        %---------------------------------------------------------------------------------------------------------------------\n        %\n        \\hline \\hline\n        \\end{tabular}\n        \\label{table:AMatToEulerAngles}\n\\end{table}\n\\end{landscape}\n\n%\\end{document}\n%\n%After End Notes - These don't need comments since they are ignored completely.\n%If I do two carriage returns in a row, I get a new paragraph.  I get\n%automatic indenting at the beginning of each paragraph.  Here are the\n%rules as I learn them.\n%\n%1)  Install WinEdt and follow its instructions.  I had to pay $\\$$70.00.\n%I think the activation code will be e-mailed to me.\n%\n%2)  After WinEdt, install MiKTeX.  WinEdt has all its settings pre-configured\n%to support MiKTeX.  MiKTeX is free but they would like a donation.\n%\n%3)  Don't try to use dollar signs.  They trigger something else in LaTeX.\n%\n%4)  I used File$>$New to start this document.\n%\n%5)  To get the right carrot to show in the line above, I had to put a\n%dollar sign on either side of it.  I'm going to try that with dollar sign now.\n%It turns out three dollar signs in a row does not work well.  So then I\n%randomly tried an opening dollar sign, a backslash prefix, the dollar sign\n%that I want to print, and a closing dollar sign.  I get the following - $\\$$\n%\n%6)  Up in Item 1 above, I used to say \"70 bucks\" because I hadn't figured\n%out the dollar sign slash double dollar sign trick yet.  I fixed it.  But\n%you didn't know that till now!  ;-)\n%\n%7)  The emoticon above printed fine with no backslashes or dollar signs.\n%\n%8)  To set up a document so it will print at all you need two command lines\n%before your text and one after your text.  The first two lines at the top\n%go like this -\n%\n%\\textbackslash documentclass\\{article\\}\n%\n%\\textbackslash begin\\{document\\}\n%\n%The final line at the bottom goes like this -\n%\n%\\textbackslash end\\{document\\}\n%\n%9)  To get a leading backslash to print, like shown above, you just type a\n%backslash and then the words \"textbackslash\"\n%\n%10) And now, let's try an image!\n%\n%\\begin{figure}[h!]\n%  \\centering\n%  \\includegraphics[width=0.82\\textwidth]{QuaternionX42DefB&W}\n%  \\caption{Physical Definition of Quaternions}\n%\\end{figure}\n%\n%11)  To prevent orphaning a line, say one that describes a following equation,\n%use the following command.\n%\\\\*[0.5cm]\n%\n", "meta": {"hexsha": "f24f7e034247f257a7d351ce520c1357c0c8511e", "size": 89973, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/AttitudeD5.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/AttitudeD5.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/AttitudeD5.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": 42.0631136045, "max_line_length": 148, "alphanum_fraction": 0.5901659387, "num_tokens": 29408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6285279101610076}}
{"text": "\\section{Fourier transform and Fourier series}\nWe make use of the theory of tempered distributions (see\n\\cite{strichartz2003guide} for an introduction)\nand we begin by collecting some results of independent interest, which\nwill also be important later. \n\\subsection{Fourier transform}\nBefore studying the Fourier transform, we first consider Schwartz space which is defined below.\n\\begin{definition} \\label{def:schwarz}\nThe Schwartz space $\\mathcal{S}\\left(\\mathbb{R}^{n}\\right)$ is the topological vector space of functions $f: \\mathbb{R}^{n} \\rightarrow \\mathbb{C}$ such that $f \\in C^{\\infty}\\left(\\mathbb{R}^{n}\\right)$ and\n$$\nx^{\\alpha} \\partial^{\\beta} f(x) \\rightarrow 0 \\quad \\text { as }|x| \\rightarrow \\infty\n$$\nfor every pair of multi-indices $\\alpha, \\beta \\in \\mathbb{N}_{0}^{n} .$ For $\\alpha, \\beta \\in \\mathbb{N}_{0}^{n}$ and $f \\in \\mathcal{S}\\left(\\mathbb{R}^{n}\\right)$ let\n(5.10)\n$$\n\\|f\\|_{\\alpha, \\beta}=\\sup _{\\mathbb{R}^{n}}\\left|x^{\\alpha} \\partial^{\\beta} f\\right|\n$$\nA sequence of functions $\\left\\{f_{k}: k \\in \\mathbb{N}\\right\\}$ converges to a function $f$ in $\\mathcal{S}\\left(\\mathbb{R}^{n}\\right)$ if\n$$\n\\left\\|f_{n}-f\\right\\|_{\\alpha, \\beta} \\rightarrow 0 \\quad \\text { as } k \\rightarrow \\infty\n$$\nfor every $\\alpha, \\beta \\in \\mathbb{N}_{0}^{n}$.\n\\end{definition}\nThe Schwartz space consists of smooth functions whose derivatives and the function itself decay at infinity faster than any power. Schwartz functions are rapidly decreasing. When there is no ambiguity, we will write $\\mathcal{S}\\left(\\mathbb{R}^{n}\\right)$ as $\\mathcal{S}$.\nRoughly speaking, tempered distributions grow no faster than a polynomial at infinity.\n\n\\begin{definition}\nA tempered distribution $T$ on $\\mathbb{R}^{n}$ is a continuous linear functional $T: \\mathcal{S}\\left(\\mathbb{R}^{n}\\right) \\rightarrow \\mathbb{C} .$ The topological vector space of tempered distributions is denoted by $\\mathcal{S}^{\\prime}\\left(\\mathbb{R}^{n}\\right)$ or $\\mathcal{S}^{\\prime} .$ If $\\langle T, f\\rangle$ denotes the value of $T \\in \\mathcal{S}^{\\prime}$ acting on $f \\in \\mathcal{S}$\nthen a sequence $\\left\\{T_{k}\\right\\}$ converges to $T$ in $\\mathcal{S}^{\\prime}$, written $T_{k} \\rightarrow T$, if\n$$\n\\left\\langle T_{k}, f\\right\\rangle \\rightarrow\\langle T, f\\rangle\n$$\nfor every $f \\in \\mathcal{S}$.\n\\end{definition}\nSince $\\mathcal{D} \\subset \\mathcal{S}$ is densely and continuously imbedded, we have $\\mathcal{S}^{\\prime} \\subset \\mathcal{D}^{\\prime} .$ Moreover, a distribution $T \\in \\mathcal{D}^{\\prime}$ extends uniquely to a tempered distribution $T \\in \\mathcal{S}^{\\prime}$ if and only if it is continuous on $\\mathcal{D}$ with respect to the topology on $\\mathcal{S}$. Every function $f \\in L_{\\text {loc }}^{1}$ defines a regular distribution $T_{f} \\in \\mathcal{D}^{\\prime}$ by\n$$\n\\left\\langle T_{f}, \\phi\\right\\rangle=\\int f \\phi d x \\quad \\text { for all } \\phi \\in \\mathcal{D}.\n$$\nIf $|f| \\leq p$ is bounded by some polynomial $p,$ then $T_{f}$ extends to a tempered distribution $T_{f} \\in \\mathcal{S}^{\\prime}$, but this is not the case for functions $f$ that grow too rapidly at infinity.\n\nThe Schwartz space is a natural one to use for the Fourier transform. Differentiation and multiplication exchange roles under the Fourier transform and therefore so do the properties of smoothness and rapid decrease. As a result, the Fourier transform is an automorphism of the Schwartz space. By duality, the Fourier transform is also an automorphism of the space of tempered distributions.\n\n\\begin{definition}\\label{def:fourier1}\nThe Fourier transform of a function $f \\in \\mathcal{S}\\left(\\mathbb{R}^{n}\\right)$ is the function $\\hat{f}: \\mathbb{R}^{n} \\rightarrow \\mathbb{C}$ defined by \n$$\n\\hat{f}(\\omega)= \\int f(x) e^{-2 \\pi i\\omega \\cdot x} d x.\n$$\nThe inverse Fourier transform of $f$ is the function $\\check{f}: \\mathbb{R}^{n} \\rightarrow \\mathbb{C}$ defined by\n$$\n\\check{f}(x)=\\int f(\\omega) e^{2 \\pi i\\omega \\cdot x} d k.\n$$\n\\end{definition}\n\n\\begin{definition}\\label{def:fourier2}\nThe Fourier transform of a tempered distribution $f \\in \\mathcal{S}'$ is  defined by \n$$\n\\langle \\hat{f}, \\phi\\rangle = \\langle f, \\hat \\phi\\rangle,\\quad \\forall \\phi\\in \\mathcal{S}.\n$$ \n\\end{definition}\n\nThe support of a continuous function $f$ is the closure  of the set $\\{x\\in \\mathbb{R}: f(x)\\neq 0\\}$.\n\\begin{properties}\nThe Fourier transform has the following properties\n\\begin{enumerate}\n\\item If $f\\in \\mathcal{S}'$ and the support of $\\hat f$ is $\\{0\\}$, then $f$ is a polynomial.\n\\item If $f\\in \\mathcal{S}'$ and the support of $\\hat f$ is a single point $\\{a\\}$, then $f(x)=e^{2\\pi iax}P(x)$, where $P(x)$ is a polynomial.\n\\end{enumerate}\n\\end{properties}\n\n\n\n\n\n\n\n\\subsection{Poisson summation formula}\n\\input{6DL/PoissonSum}\n\\subsection{A special cut-off function}\n\\input{6DL/Cut-off-function}\n", "meta": {"hexsha": "90c93cc7d0883a251a32ddf282e41a234d76529c", "size": 4813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Fourier.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/Fourier.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/Fourier.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": 60.1625, "max_line_length": 473, "alphanum_fraction": 0.7016413879, "num_tokens": 1542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6285278846614122}}
{"text": "\\documentclass[a4paper]{article}\n\n\\addtolength{\\oddsidemargin}{-10pt}\n\\addtolength{\\textwidth}{50pt}\n\\addtolength{\\textheight}{70pt}\n\\addtolength{\\voffset}{-40pt}\n\n\\title{Mobile antenna model description}\n\\author{Jan Šimbera}\n\\date{\\today}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[pdftex,unicode,hidelinks]{hyperref}\n\\usepackage[pdftex]{graphicx}\n\n\\begin{document}\n\\maketitle\n\\begin{abstract}\nThis document outlines a model that describes the spread of cell phone signal\nfor the purposes of mapping cell phone antenna coverage areas and detecting\nthe user's location somewhat more accurately.\n\\end{abstract}\n\n\n\\section{Model description} \\label{sec:antmodel}\n\n\\subsection{Assumptions}\nThe connection of the cell phone to the mobile network is facilitated through\na system of antennas. Usually, the operator shares very little information\nabout these antennas; nevertheless, some parameters, such as antenna location,\nare almost always available, sometimes through crowdsourced registers. We thus\nassume the antenna locations $\\vec{x_0} = (x_0,y_0)$ are fixed and known; we\nalso assume a planar coordinate system for simplicity.\n\n\\subsection{Signal spread model}\\label{sec:sigmodel}\nWe assume three orthogonal effects on the signal strength $S_i(\\vec{x})$\nof antenna $i$ for a given location $\\vec{x} = (x,y)$, that is:\n\\begin{itemize}\n\\item antenna power $P_i$,\n\\item distance from the antenna $d_i(\\vec{x}) = ||\\vec{x} - \\vec{x_i}||$,\n\\item azimuth of the vector from the antenna to the location\n    $\\varphi_i(\\vec{x}) = \\arctan{\\frac{y - y_i}{x - x_i}}$.\n\\end{itemize}\n\nWe can employ a probabilistic approach to the problem: we first model the\nprobability of a user being at a given location $\\vec{x}$ if we know that he\nor she is connected to an antenna $i$ and then use the Bayesian rule to\ndetermine signal strength as the inverse conditional probability:\n\\begin{equation}\nS_i(\\vec{x}) = P(i|\\vec{x}) = P(\\vec{x}|i) \\frac{P(i)}{P(\\vec{x})}\n\\end{equation}\nWe can isolate the $P(i)$ as the antenna power $P_i$ and amalgamate the\nremaining two terms to make the model agnostic to an apriori distribution of\nusers (i.e. population/settlement density):\n\\begin{equation}\nS_i(\\vec{x}) = P_i \\frac{P(\\vec{x}|i)}{P(\\vec{x})} = P_i \\cdot L_i(\\vec{x})\n\\end{equation}\nThe resulting term $L_i(\\vec{x})$ should capture the remaining two effects of\ndistance and azimuth. As we assume the effects to be orthogonal, we can\nexpress it as\n\\begin{equation}\nL_i(\\vec{x}) = f_d(d_i(\\vec{x})) \\cdot f_a(\\varphi_i(\\vec{x}))\n\\end{equation}\n\n\\subsubsection{Distance decay}\nAs we operate on macroscopic scales, the distance decay of an EM signal is\ngoverned by an inverse square law:\n\\begin{equation}\nS_i(\\vec{x}) \\propto d_i(\\vec{x})^{-2}\n\\end{equation}\nThis, however, would imply the signal strength goes to infinity near the\nlocation of the antenna. Therefore, it is useful to employ a small correcting\nfactor. Using this, we arrive at a probabilistic description by a Cauchy\ndistribution, which is useful:\n\\begin{equation}\nd_i(\\vec{x}) \\sim \\mathrm{Cauchy}(0,\\gamma_i)\n\\end{equation}\nwhere $\\gamma_i$ is the distance decay scale factor. We can use the probability\ndensity function of the Cauchy distribution as our distance decay function:\n\\begin{equation}\nf_d(d_i(\\vec{x})) = \\frac{1}{\n    \\pi \\gamma_i \\left[1 + \\left( \\frac{d_i(\\vec{x})}{\\gamma_i} \\right)^2 \\right]\n} = \\frac{\\gamma_i}{\\pi [d_i(\\vec{x})^2 + \\gamma_i^2]}\n\\end{equation}\n\n\\subsubsection{Angular distribution}\nTo model the angular dispersion of the signal, we can use the von Mises\ndistribution in a manner similar to the Cauchy distribution for distance decay.\nThe von Mises distribution is a circular analogue of the normal distribution:\n\\begin{equation}\nf(\\varphi) = \\frac{\\exp{[\\kappa \\cos{(\\varphi - \\alpha)}]}}{2\\pi I_0(\\kappa)}\n\\end{equation}\nwhere $I_0(\\kappa)$ is the modified Bessel function of order zero, $\\alpha$ is\nthe principal angle and $\\kappa$ is the directional concentration.\n\nUsing this, we define\n\\begin{equation}\nf_a(\\varphi_i(\\vec{x})) = \\frac\n    {\\exp{[\\kappa_i \\cos{(\\varphi_i(\\vec{x}) - \\alpha_i)}]}}\n    {2\\pi I_0(\\kappa_i)}\n\\end{equation}\nwhich leaves us with two parameters for the antenna: orientation (principal\nangle) $\\alpha$ and angular signal concentration (narrowness) $\\kappa$.\n\n\\subsubsection{Final signal strength equation}\nCombining the above results, we arrive at the final signal model result\n\\begin{align}\nS_i(\\vec{x}) &= P_i \\cdot f_d(d_i(\\vec{x})) \\cdot f_a(\\varphi_i(\\vec{x}))\\\\\n&= P_i \\frac\n    {\\gamma_i \\exp{[\\kappa_i \\cos{(\\varphi_i(\\vec{x}) - \\alpha_i)}]}}\n    {2\\pi^2 I_0(\\kappa_i) [d_i(\\vec{x})^2 + \\gamma_i^2]}\\\\\n&= \\frac{P_i \\gamma_i}{2\\pi^2 I_0(\\kappa_i)} \\cdot \\frac\n    {\\exp{[\\kappa_i \\cos{(\\varphi_i(\\vec{x}) - \\alpha_i)}]}}\n    {d_i(\\vec{x})^2 + \\gamma_i^2}\\\\\n&= K_i \\cdot \\frac\n    {\\exp{[\\kappa_i \\cos{(\\varphi_i(\\vec{x}) - \\alpha_i)}]}}\n    {d_i(\\vec{x})^2 + \\gamma_i^2}\n\\end{align}\n\nSince the signal strengths are relative to each other, we should specify a\ncondition on their absolute values; this can be formulated e.g. as\n\\begin{equation} \\label{eq:powersumcond}\n\\sum_{a=1}^{n_a} P_a \\gamma_a = 1\n\\end{equation}\n\n\\subsection{Antenna parameters}\nThe signal strength model uses four additional parameters (in addition to\nlocation) to describe the antennas:\n\\begin{itemize}\n\\item Antenna orientation azimuth $\\alpha \\in [0;2\\pi)$ (with zero pointing\n    north).\n\\item Antenna power or overall signal strength $P \\in \\mathbb{R}^{+}$. This\n    is somehow related to the power of the antenna transmitter.\n\\item Distance decay scale parameter $\\gamma \\in \\mathbb{R}^{+}$, defining\n    the rate of signal strength diminishing with increasing distance from the\n    antenna. This can be related e.g. to the vertical orientation of the\n    antenna with respect to the surface.\n\\item Angular concentration of antenna signal $\\kappa \\in \\mathbb{R}^{+}_{0}$.\n    The higher the concentration (narrowness), the more the signal power is\n    concentrated along the direction of the antenna orientation. $\\kappa = 0$\n    means the antenna is isotropic and radiates the signal uniformly in all\n    directions.\n\\end{itemize}\nSometimes, some of the parameters may be known a priori, such as the antenna\nazimuths. The rest of the parameters need to be estimated from the antenna\nconnection data, which should be the next large task.\n\n\n\n\\section{Model parameter estimation}\nTo estimate the antenna parameters, several variants of data sources may be\nused. In this estimation scenario, we consider a set of $n_p$ places $p$ with\nlocations $\\vec{x}_p$. We denote the signal strength of a given antenna\n$a$ at that place as $S_{ap}$, the distance $d_{ap}$ and angle $\\varphi_{ap}$\nof a given place from it as in \\ref{sec:sigmodel}.\n\nIn addition to the place data, we enter data about a set of $n_u$ users and\ntheir simultaneous connections to antennas (that is, how often they are\nconnected to what antennas while not moving themselves).\nTherefore, we propose using night-time signalling (SS.7 logs) or CDR\ndata where antenna connection variability is most likely to come from antenna\nsignal strength variation, not from user movements. Given this, we may derive\nfor each user a set of connection time fractions $f_{ua}$ denoting the\nlikelihood of the connection of the user to the respective antennas, satisfying\n$\\sum_{a=1}^{n_a} f_{ua} = 1 \\,\\forall u$.\n\n\\subsection{Estimation with known locations} \\label{sec:locest}\nIf we have an additional data source that allows us to determine the actual\nnight-time positions of the users (such as independent mobility tracker app\nlogs), the model estimation becomes simpler because we can compute the user\nlocation probabilities with respect to the places $p$ directly as $p_{up}$.\n\nThe algorithm works as an EM procedure, trying to estimate the signal strengths\nfor all places and antennas with antenna parameters as proxy variables.\nThe E step estimates the antenna parameters from signal strengths using OLS,\nwith the initial values obtained from location averaging, and the M step\nestimates the signal strengths from the antenna parameters using the equations\nfrom \\ref{sec:antmodel}.\n\n\\subsubsection{Antenna dominance fractions}\nDominance fractions denote how much the given place is dominated by a signal\nfrom a given antenna, an therefore, the probability of a user at a given\nlocation being connected to the antenna:\n\\begin{equation}\n\\Psi_{ap} = \\frac\n    {\\sum_{u=1}^{n_u} p_{up} f_{ua}}\n    {\\sum_{u=1}^{n_u} p_{up}}\n\\end{equation}\nThis ensures that $\\sum_{a=1}^{n_a} \\Psi_{ap} = 1 \\,\\forall p$.\n\n\\subsubsection{Expectation step}\nIn this step, we compute the optimal antenna parameters using OLS on a\nlinearized signal strength function (with parameters from the previous round)\nset as equal to the E-computed signal strength:\n\\begin{align}\n\\frac{1}{P_a^{(i)}} &\\cdot P_a^{(i+1)} \\nonumber \\\\\n+ \\frac\n    {d_{ap}^2 - {\\gamma_a^{(i)}}^2}\n    {\\gamma_a^{(i)} (d_{ap}^2 + {\\gamma_a^{(i)}}^2)}\n    &\\cdot \\gamma_a^{(i+1)} \\nonumber \\\\\n+ \\kappa_a^{(i)} \\sin{(\\varphi_{ap} - \\alpha_a^{(i)})}\n    &\\cdot \\alpha_a^{(i+1)} \\nonumber \\\\\n+ \\left[\n        \\cos{(\\varphi_{ap} - \\alpha_a^{(i)})}\n        - \\frac{I_1(\\kappa_a^{(i)})}{I_0(\\kappa_a^{(i)})}\n    \\right] &\\cdot \\kappa_a^{(i+1)} =\\\\\n\\frac{S_{ap}^{(i+1)}}{S_{ap}^{(i)}}\n+ 1\n+ \\frac\n    {d_{ap}^2 - {\\gamma_a^{(i)}}^2}\n    {d_{ap}^2 + {\\gamma_a^{(i)}}^2}\n+ \\kappa_a^{(i)} \\alpha_a^{(i)} \\sin{(\\varphi_{ap} - \\alpha_a^{(i)})}\n&+ \\kappa_a^{(i)} \\left[\n        \\cos{(\\varphi_{ap} - \\alpha_a^{(i)})}\n        - \\frac{I_1(\\kappa_a^{(i)})}{I_0(\\kappa_a^{(i)})}\n    \\right] \\nonumber\n\\end{align}\n\n\\subsubsection{Maximization step}\nIn this step, we estimate the signal strengths for places from their antenna\ndominances and antenna parameters:\n\\begin{equation}\nS_{ap}^{(i+1)} = \\Psi_{ap} \\sum_{b=1}^{n_a} \\frac\n    {P_b^{(i)} \\gamma_b^{(i)} \\exp{[\n        \\kappa_b^{(i)} \\cos{(\\varphi_{bp} - \\alpha_b^{(i)})}\n    ]}}\n    {2\\pi^2 I_0(\\kappa_b^{(i)}) [d_{bp}^2 + {\\gamma_b^{(i)}}^2]}\\\\\n\\end{equation}\n\n\\subsubsection{Initial antenna parameter estimations}\nThe initial values can be obtained as follows:\n\n\\paragraph{Antenna principal angles} $\\alpha_a$ -- if not known -- can be\ndetermined as weighted circular means\n\\begin{equation}\n\\alpha_a = \\arctan \\frac\n    {\\sum_{p=1}^{n_p} \\Psi_{ap} \\sin \\varphi_{ap}}\n    {\\sum_{p=1}^{n_p} \\Psi_{ap} \\cos \\varphi_{ap}}\n\\end{equation}\n\n\\paragraph{Antenna angular concentrations} $\\kappa_a$ can be determined\nusing the von Mises-Fisher iterative estimation procedure from the parameter\n$\\bar{R}_a$:\n\\begin{equation}\n\\bar{R}_a = \\frac\n    {\\left(\\sum_{p=1}^{n_p} \\Psi_{ap} \\sin \\varphi_{ap}\\right)^2\n        + \\left(\\sum_{p=1}^{n_p} \\Psi_{ap} \\cos \\varphi_{ap}\\right)^2}\n    {\\left(\\sum_{p=1}^{n_p} \\Psi_{ap}\\right)^2}\n\\end{equation}\nWith this parameter, we can produce the initial estimate for $\\kappa_a$ as\n\\begin{equation}\n\\kappa_a^{(0)} = \\frac\n    {\\bar{R}_a (2 - \\bar{R}_a^2)}\n    {1 - \\bar{R}_a^2}\n\\end{equation}\nand then repeat the following equation until convergence\n\\begin{equation}\n\\kappa_a^{(i+1)} = \\kappa_a^{(i)} - \\frac\n    {A_p(\\kappa_a^{(i)}) - \\bar{R}_a}\n    {1 - A_p(\\kappa_a^{(i)})^2 - \\frac{A_p(\\kappa_a^{(i)})}{\\kappa_a^{(i)}}}\n\\end{equation}\nwhere $A_p(x) = \\frac{I_1(x)}{I_0(x)}$ is the ratio of modified Bessel functions\nof the first and zeroth order respectively. Three iterations are usually\nsufficient.\n\n\\paragraph{Antenna distance decay parameter} $\\gamma_a$ may be estimated as\nthe weighted mean distance of a dominated place from the antenna:\n\\begin{equation}\n\\gamma_a = \\frac\n    {\\sum_{p=1}^{n_p} \\Psi_{ap} d_{ap}}\n    {\\sum_{p=1}^{n_p} \\Psi_{ap}}\n\\end{equation}\n\n\\paragraph{Strengths of the antennas} $P_a$, to honor the condition from\n\\eqref{eq:powersumcond}, can be estimated as the relative size of the antenna's\narea of dominance to the total area of study. We need to factor out the\ngeneral influence of the distance decay parameter, too:\n\\begin{equation}\nP_a = \\frac\n    {\\sum_{p=1}^{n_p} \\Psi_{ap} A_p}\n    {\\gamma_a \\sum_{p=1}^{n_p} A_p}\n\\end{equation}\nwhere $A_p$ is the area corresponding to place $p$ -- if the places are only\ngiven as points, the areas may be computed e. g. using Voronoi polygons.\n\n\n\\subsection{Estimation with unknown locations}\nIf we do not have data about real user locations $p_{up}$, we can supply them by\nemploying an EM estimation procedure over the proposed approach.\n\nTo do this, it is useful to know at least roughly the expected user densities\nover the places used $w_p$. These densities may be derived from an apriori\npopulation distribution measure such as a census grid or, alternatively, a land\nuse layer such as GHSL aggregated to a reasonable level.\n\n\\subsubsection{Expectation step}\nThis step of the procedure estimates the user locations\nfrom signal strengths in those places by computing place affinities as\n\\begin{equation}\na_{up}^{(i+1)} = \\left(\n    1 + \\frac\n        {w_p - \\sum_{u=1}^{n_u} p_{up}^{(i)}}\n        {w_p + \\sum_{u=1}^{n_u} p_{up}^{(i)}}\n\\right)^{\\frac{1}{k_c}}\n\\sqrt{\n    \\frac{1}{n_a} \\sum_{a=1}^{n_a} \\left(\n        f_{ua} - \\frac{S_{ap}^{(i)}}{\\sum_{b=1}^{n_a} S_{bp}^{(i)}}\n    \\right)^2\n}\n\\end{equation}\nwhere $k_c$ is the crowding tolerance coefficient specifying the degree of\nadherence to the apriori place weights $w_p$. Its higher values mean a more\ndifferent spatial distribution of users can arise.\n\nThen the actual localization probabilities are produced by normalizing the\naffinities to sum to one:\n\\begin{equation}\np_{up}^{(i+1)} = \\frac\n    {a_{up}^{(i+1)}}\n    {\\sum_{q=1}^{n_p} a_{uq}^{(i+1)}}\n\\end{equation}\n\n\\subsubsection{Maximization step}\nThis step of the procedure uses the method from\n\\ref{sec:locest} to derive $S_{ap}^{(i)}$ from $p_{up}^{(i)}$.\n\\end{document}", "meta": {"hexsha": "0024beb9b62302864348bc0b7544980e6d9e6a06", "size": 13724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/signal_model.tex", "max_stars_repo_name": "simberaj/mobilib", "max_stars_repo_head_hexsha": "ae350d095a34f53704bd4aaaf7f45e573bda779a", "max_stars_repo_licenses": ["MIT"], "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/signal_model.tex", "max_issues_repo_name": "simberaj/mobilib", "max_issues_repo_head_hexsha": "ae350d095a34f53704bd4aaaf7f45e573bda779a", "max_issues_repo_licenses": ["MIT"], "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/signal_model.tex", "max_forks_repo_name": "simberaj/mobilib", "max_forks_repo_head_hexsha": "ae350d095a34f53704bd4aaaf7f45e573bda779a", "max_forks_repo_licenses": ["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.9694189602, "max_line_length": 81, "alphanum_fraction": 0.7113815214, "num_tokens": 4212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7310585903489892, "lm_q1q2_score": 0.6284645748788176}}
{"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-13.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% =============================================================================\n\\section*{Example 13a The Weyl tensor vanishes in 3d -- direct proof}\n\n\\begin{cadabra}\n   {x,y,z}::Coordinate.\n   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w#}::Indices (values={x,y,z},position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n\n   {\\partial_{a b}{g_{c d}},\\partial_{a}{g_{b c}},g_{a b},g^{a b}}::SortOrder.\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}}). # cdb(Gamma.000,GammaU)\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}}).           # cdb(Gamma.010,GammaD)\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}.             # cdb (Rabcd.000,Rabcd)\n\n   Rab     := R_{a b} -> g^{c d} R_{a c b d}.                             # cdb (Rab.000,Rab)\n\n   Rscalar := R -> g^{a b} R_{a b}.                                       # cdb (R.000,Rscalar)\n\n   # Weyl in 3-dimensions\n\n   Cabcd := R_{a b c d} - (R_{a c} g_{b d} - R_{a d} g_{b c})\n                        - (g_{a c} R_{b d} - g_{a d} R_{b c})\n                  + 1/2 R (g_{a c} g_{b d} - g_{a d} g_{b c}).            # cdb (ex-13a.100,Cabcd)\n\n   # Use 8 Cabcd to clear the fractions\n\n   EightCabcd := 8 @(Cabcd).                                              # cdb (ex-13a.110,EightCabcd)\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)                                                 # cdb (ex-13a.101,Cabcd)\n\n   EightCabcd := 8 @(Cabcd).                                              # cdb (ex-13a.111,EightCabcd)\n\n   gab := {g_{x x} = gxx, g_{x y} = gxy, g_{x z} = gxz,\n           g_{y x} = gxy, g_{y y} = gyy, g_{y z} = gyz,\n           g_{z x} = gxz, g_{z y} = gyz, g_{z z} = gzz}.\n\n   complete  (gab, $g^{a b}$)\n   evaluate  (Cabcd,gab)                                                  # cdb (ex-13a.102,Cabcd)\n   evaluate  (EightCabcd,gab)                                             # cdb (ex-13a.112,EightCabcd)\n\n\\end{cadabra}\n\n\\clearpage\n\n% \\begin{dgroup*}\n%    \\Dmath*{ C_{abcd} = \\Cdb*{ex-13a.100}\n%                      = \\Cdb*{ex-13a.101}\n%                      = \\Cdb*{ex-13a.102}}\n% \\end{dgroup*}\n\n\\begin{dgroup*}\n   \\Dmath*{ 8C_{abcd} = \\Cdb*{ex-13a.110}\n                      = \\Cdb*{ex-13a.111}\n                      = \\Cdb*{ex-13a.112}}\n\\end{dgroup*}\n\n\\clearpage\n\n% =============================================================================\n\\section*{Example 13b The Weyl tensor vanishes in 3d -- orthonormal basis}\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   g_{a b}::Metric.\n   g^{a b}::InverseMetric.\n\n   R_{a b c d}::RiemannTensor.\n\n   ex{#}::LaTeXForm{\"e_x\"}.\n   ey{#}::LaTeXForm{\"e_y\"}.\n   ez{#}::LaTeXForm{\"e_z\"}.\n\n   {R_{a b c d}, g_{a b}, g^{a b}}::SortOrder.\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   gab := g^{a b} -> ex^{a} ex^{b} + ey^{a} ey^{b} + ez^{a} ez^{b}.\n\n   ortho := {ex^{a} ex^{b} g_{a b} -> 1, ey^{a} ey^{b} g_{a b} -> 1, ez^{a} ez^{b} g_{a b} -> 1,\n             ex^{a} ey^{b} g_{a b} -> 0, ex^{a} ez^{b} g_{a b} -> 0,\n             ey^{a} ex^{b} g_{a b} -> 0, ey^{a} ez^{b} g_{a b} -> 0,\n             ez^{a} ex^{b} g_{a b} -> 0, ez^{a} ey^{b} g_{a b} -> 0}.\n\n   # Weyl in 3-dimensions\n\n   Cabcd := R_{a b c d} - (R_{a c} g_{b d} - R_{a d} g_{b c})\n                        - (g_{a c} R_{b d} - g_{a d} R_{b c})\n                  + 1/2 R (g_{a c} g_{b d} - g_{a d} g_{b c}).   # cdb (ex-13b.100,Cabcd)\n\n\n   substitute     (Cabcd, Rscalar)                               # cdb(ex-13b.101,Cabcd)\n   substitute     (Cabcd, Rab)                                   # cdb(ex-13b.102,Cabcd)\n   distribute     (Cabcd)                                        # cdb(ex-13b.103,Cabcd)\n\n   Cabcd := C_{a b c d} -> @(Cabcd).\n\n   Cxyxy := C_{a b c d} ex^{a} ey^{b} ex^{c} ey^{d}.             # cdb(ex-13b.104,Cxyxy)\n\n   substitute     (Cxyxy,Cabcd)                                  # cdb(ex-13b.105,Cxyxy)\n   distribute     (Cxyxy)                                        # cdb(ex-13b.106,Cxyxy)\n\n   substitute     (Cxyxy, ortho, repeat=True)                    # cdb(ex-13b.107,Cxyxy)\n\n   substitute     (Cxyxy, gab)                                   # cdb(ex-13b.108,Cxyxy)\n   distribute     (Cxyxy)                                        # cdb(ex-13b.109,Cxyxy)\n\n   sort_product   (Cxyxy)                                        # cdb(ex-13b.110,Cxyxy)\n   rename_dummies (Cxyxy)                                        # cdb(ex-13b.111,Cxyxy)\n   canonicalise   (Cxyxy)                                        # cdb(ex-13b.112,Cxyxy)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{\\cdb*{ex-13b.101}}\n   \\Dmath*{\\cdb*{ex-13b.102}}\n   \\Dmath*{\\cdb*{ex-13b.103}}\n\\end{dgroup*}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{\\cdb{ex-13b.104}\n         = \\Cdb*[\\hfill\\hskip2.5cm]{ex-13b.105}\n         = \\Cdb*{ex-13b.106}\n         = \\Cdb*{ex-13b.107}\n         = \\Cdb*[\\hfill\\hskip2.0cm]{ex-13b.108}\n         = \\Cdb*{ex-13b.109}\n         = \\Cdb*{ex-13b.110}\n         = \\Cdb*{ex-13b.111}\n         = \\Cdb*{ex-13b.112}}\n\\end{dgroup*}\n\n\\clearpage\n\n% =============================================================================\n\\section*{Example 13c The Weyl tensor vanishes in 3d -- orthonormal basis}\n\n\\begin{cadabra}\n   Cxyxz := C_{a b c d} ex^{a} ey^{b} ex^{c} ez^{d}.             # cdb(ex-13c.101,Cxyxz)\n\n   substitute     (Cxyxz,Cabcd)                                  # cdb(ex-13c.102,Cxyxz)\n\n   distribute     (Cxyxz)                                        # cdb(ex-13c.103,Cxyxz)\n\n   substitute     (Cxyxz, ortho, repeat=True)                    # cdb(ex-13c.104,Cxyxz)\n\n   substitute     (Cxyxz, gab)                                   # cdb(ex-13c.105,Cxyxz)\n   distribute     (Cxyxz)                                        # cdb(ex-13c.106,Cxyxz)\n\n   sort_product   (Cxyxz)                                        # cdb(ex-13c.107,Cxyxz)\n   rename_dummies (Cxyxz)                                        # cdb(ex-13c.108,Cxyxz)\n   canonicalise   (Cxyxz)                                        # cdb(ex-13c.109,Cxyxz)\n\\end{cadabra}\n\n\\clearpage\n\n\\begin{dgroup*}\n   \\Dmath*{\\cdb{ex-13c.101}\n         = \\Cdb*[\\hfill\\hskip2.5cm]{ex-13c.102}\n         = \\Cdb*{ex-13c.103}\n         = \\Cdb*{ex-13c.104}\n         = \\Cdb*{ex-13c.105}\n         = \\Cdb*{ex-13c.106}\n         = \\Cdb*{ex-13c.107}\n         = \\Cdb*{ex-13c.108}\n         = \\Cdb*{ex-13c.109}}\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": "1d35e70c9a5abc13ca514c0af1b66d31bc6942ac", "size": 7850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-13.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-13.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-13.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": 34.1304347826, "max_line_length": 103, "alphanum_fraction": 0.4278980892, "num_tokens": 2672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6284645623956945}}
{"text": "\\subsection{k-means}\n\\begin{figure}\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{elbowds1.png}\n        \\caption{Timing curve vs silhouette coeff. dataset 1}\\label{Fig:K-means vs silhouette coeff. dataset 1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{elbowds2.png}\n        \\caption{Timing curve vs silhouette coeff. dataset 2}\\label{Fig:K-means vs silhouette coeff. dataset 2}\n    \\end{minipage}\n\\end{figure}\nThe two clustering techniques I explored for these datasets are K-Means clustering and Gaussian Mixture Models (Expectation Maximization)\nIn order to choose an appropriate $k$ to do k-means clustering, I used the elbow method\\cite{developers_2020}.\nUnless otherwise specified the standard distance measure I used was Euclidean distance.\nComparing all cluster cohesion metrics (mean distortion, silhouette coefficient, and Calinski-Harabasz score) here were\nthe elbow results:\n\\begin{center}\n    \\begin{tabular}{|c| c | c | c |}\n        \\hline\n        & Metric                     & Cluster Count & Value \\\\\n        \\hline\n        \\hline\n        Dataset 1 & Avg Silhouette Coefficient & 4             & 0.558 \\\\\n        \\hline\n        Dataset 2 & Avg Silhouette Coefficient & 3             & 0.687 \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\nLooking at figure~\\ref{Fig:K-means vs silhouette coeff. dataset 1} and figure~\\ref{Fig:K-means vs silhouette coeff. dataset 2} you can\nsee similar numbers in terms of the best \"k\".\nI chose silhouette coeff over the other cluster cohesion metrics because it has a bias towards preferring well separated\nclusters (coeffs closer to 1), which I anticipate would improve generalization and overall accuracy during a machine\nlearning process where the clusters are inputs to the learner.\nDataset 2 appears to have better separation between its 3 clusters than dataset 1's 4 clusters.\nDoing further silhouette analysis on DS1 reveals that the clusters when plotted on it to the surface do not appear to\nhave a \"cluster\" round shape and instead are ovular, whereas data set two had similar characteristics to data set one\nexcept that cluster two is actually interspersed in between cluster zero and cluster one, however this was only for the\nfirst two features and others could have had better separation/shape.\nBoth clustering methods On both data sets appeared to have two very strongly defined clusters, and then up to two additional weakly defined clusters.\nThis more or less aligns with the fact that this is a binary classification problem and that samples could be placed into one of two clusters.\nThe clusters were more well defined and well separated on the second dataset which also makes sense given that all supervised learning methods performed better in terms of accuracy on this dataset relative to the first.\nOn closer inspection, the third and fourth clusters appear to be randomly dispersed throughout the dataset to capture outliers.\nThese clusters likely are noise capturers.\n\\begin{center}\n    \\begin{tabular}{|c| c | c | c |}\n        \\hline\n        & Normalized Mutual Information & Homogeneity Score & Completeness Score \\\\\n        \\hline\n        \\hline\n        Dataset 1 & 0.001                         & 0.002             & 0.001              \\\\\n        \\hline\n        Dataset 2 & 0.189                         & 0.236             & 0.158              \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\nValues closer to 1 are better than 0 in the above table for each score metric.\nIt seems that the performance of K-means is slightly better on dataset 2 than on 1.\nTo improve the performance of this we would likely need to include a dimensionality reduction technique, or modify the\ndataset so that clusters are more hyper-spherical and separated from each other in the feature space.\n\n\\subsection{Expectation Maximization}\\label{subsec:expectation-maximization}\n\\begin{figure}\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{gmmcomponentsds1.png}\n        \\caption{n\\_components vs AIC/BIC DS1}\\label{Fig:GMM DS1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{gmmcomponentsds2.png}\n        \\caption{n\\_components vs AIC/BIC DS2}\\label{Fig:GMM DS2}\n    \\end{minipage}\n\\end{figure}\nFor expectation maximization, I used the scikit-learn Gaussian mixture model function.\nBased on my exploration, I do not believe that the data are distributed in a hyper-spherical format, therefore a GMM would\nbe able to better group samples based on its ability to accommodate non-spherical hyper-surfaces.\nIn order to select a best value for the number of estimators in the model, I plotted the Bayesian Information Criterion\nvs the Akaike Information Criterion, where they begin to diverge is likely the best place to stop in terms of n\\_estimators.\nIn this case looking at figures~\\ref{Fig:GMM DS1} and~\\ref{Fig:GMM DS2} it appears to be the same as the optimal K found\npreviously (4 and 3 respectively.) After finding these and running best fits and comparing results I got:\n\\begin{center}\n    \\begin{tabular}{|c| c | c | c |}\n        \\hline\n        & Normalized Mutual Information & Homogeneity Score & Completeness Score \\\\\n        \\hline\n        \\hline\n        Dataset 1 & 0.002                         & 0.002             & 0.002              \\\\\n        \\hline\n        Dataset 2 & 0.133                         & 0.174             & 0.108              \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\nThese clusters more or less make sense much in the same way that K-means did.\nFor dataset 1, GMM outperformed in terms of mutual information, homogeneity, and completeness shared by the clustering techniques and the actual labels\nwhereas for dataset 2 K-means outperformed, which indicates that the data was slightly more spherical than I anticipated.\nHowever, neither of these clustering techniques did very well since all the values were close to 0 indicating that assigment\nto clusters was independent and that the clusters themselves were not very independent, nor complete.\n", "meta": {"hexsha": "a5e0e5ad009270f0002036e5b190d3fb7ad26204", "size": 6208, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment3/clustering-discussion.tex", "max_stars_repo_name": "zparnold/cs7641", "max_stars_repo_head_hexsha": "e37e7b9259237adffbeb36ccc8dd17f67892286a", "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": "assignment3/clustering-discussion.tex", "max_issues_repo_name": "zparnold/cs7641", "max_issues_repo_head_hexsha": "e37e7b9259237adffbeb36ccc8dd17f67892286a", "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": "assignment3/clustering-discussion.tex", "max_forks_repo_name": "zparnold/cs7641", "max_forks_repo_head_hexsha": "e37e7b9259237adffbeb36ccc8dd17f67892286a", "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": 62.08, "max_line_length": 219, "alphanum_fraction": 0.7160115979, "num_tokens": 1495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.80563219364797, "lm_q1q2_score": 0.6283873953817201}}
{"text": "\\documentclass[journal]{IEEEtran}\n\\usepackage[utf8]{inputenc}\n\\usepackage{minted}\n\\usepackage{booktabs}\n\\usepackage{color}\n\\usepackage{mathtools}\n\\usepackage{mathrsfs}\n\\usepackage{multirow}\n\n\\usepackage[binary-units=true]{siunitx}\n\n\\newcommand{\\scala}[1]{\\mintinline{scala}{#1}}\n\n\\title{Advanced Algorithms (\\texttt{LINGI2266}) \\\\ Assignment 1: Knapsack problem}\n\\author{Gilles Peiffer}\n\\date{October 11, 2019}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n\tAn analysis of the solution to the knapsack problem which takes into account various dimensions along which to judge algorithms for this problem is given.\n\tVarious heuristics are given, some of which are based on a theoretical understanding of the mathematics behind the knapsack problem, while others are highly-specialized in order to profit from the input formulation as much as possible.\n\tSome implementation fragments in Scala are also presented.\n\\end{abstract}\n\n\\section{Introduction}\n\\label{sec:intro}\nThe goal for this assignment was to solve various instances of the \\emph{knapsack problem}, defined as follows:\n\\[\n\\begin{array}{rrcl@{\\quad}l}\n\\textnormal{maximize} & \\sum_{i \\in \\{1, \\ldots, n\\}} x_i v_i &&& \\\\\n\\textnormal{such that} & \\sum_{i \\in \\{1, \\ldots, n\\}} x_i w_i & \\le & C &\\\\\n& x_i & \\in & \\{0, 1\\} & \\forall i \\in \\{1, \\ldots, n\\}\n\\end{array}\n\\]\n\nThe two main types of algorithms used to solve this class of problems are\n\\begin{itemize}\n\t\\item \\emph{dynamic programming} and\n\t\\item \\emph{branch and bound}.\n\\end{itemize}\nEach of these has its own advantages and disadvantages, which usually allow one to make an informed choice as to which algorithm is best-suited for a particular instance of the knapsack problem.\n\n\\section{I/O}\nIn order to be easily tested on INGInious, the input and output for this particular instance have a very specific fixed format.\n\\subsection{Reading the Input}\nThe program is given a \\scala{String} as input which contains the path to the data file.\nThis file is opened and read according to the format specified in the problem description on INGInious, and uses Scala code written for this purpose by Pierre Schaus.\n\n\\subsection{Output Formatting}\nThe \\scala{toString} method definition is overridden in order to produce output with the correct format.\nThis requires some internal bookkeeping, explained in slightly more detail in Sections~\\ref{sec:dpoutput} (for dynamic programming) and \\ref{sec:bnboutput} (for branch and bound).\n\n\\section{Dynamic Programming}\nDynamic programming, or DP for short, is an algorithmic technique which uses memoization in order to improve computation time at the cost of memory space.\n\n\\subsection{Recurrence Equations}\nOne has to define an \\emph{objective function} \\(\\mathscr{O}(j, k)\\), which, for the knapsack problem, gives the optimal value that can be obtained using items 1 through \\(j\\) and with a capacity \\(k\\).\nThis function can be defined recursively as follows:\n\\[\n\\mathscr{O}(j, k) = \\left\\{\n\\begin{array}{ll}\n\\max\\big\\{ \\mathscr{O}(j-1, k), & \\multirow{2}{*}{\\(\\textnormal{if } w_j \\le k,\\)}\\\\\n\\qquad v_j + \\mathscr{O}(j-1, k-w_j) \\big\\}, & \\\\\\\\\n\\mathscr{O}(j-1, k), & \\textnormal{otherwise,}\\\\\\\\\\\\\n0, & \\textnormal{if } j = 0.\n\\end{array}\n\\right.\n\\]\nBy this definition, the final solution to the problem is \\(\\mathscr{O}(n, C)\\).\n\\subsection{Implementation}\nTurning these equations into Scala is fairly straightforward.\nThe following is what one could consider the ``core'' of the implementation:\n\\begin{minted}[fontsize=\\scriptsize]{scala}\nval cache = collection.mutable.Map.empty[(Int, Int), Int]\nval tkn = collection.mutable.Map.empty[(Int, Int), Boolean]\ndef O(j: Int, k: Int): Int = {\n  if (j < 0) 0\n  else {\n    val (vj, wj) = items(j)\n    if (wj > k) {\n      tkn.update((j, k), false)\n      O_(j-1,k)\n    } else {\n      if (O_(j-1,k) > vj + O_(j-1,k-wj)) {\n        tkn.update((j, k), false)\n        O_(j-1,k)\n      } else {\n        tkn.update((j, k), true)\n        vj + O_(j-1,k-wj)\n      }\n    }\n  }\n}\ndef O_(j: Int, k: Int): Int = {\n  cache.getOrElseUpdate((j,k), O(j,k))\n}\nprintln(O(n-1, c))\n\\end{minted}\n\\subsubsection{Recurrence}\nThe recurrence equation given earlier is implemented in the form of a multitude of nested \\scala{if}/\\scala{else} branches, and a function call to \\scala{O_}, which is explained in Section~\\ref{sec:dpmemo}.\nOne should also note that instead of the solution being \\(\\mathscr{O}(n, C)\\), one must call \\scala{O(n-1, C)}; this is explained by the fact that in Scala, array indexing starts at 0, causing a potential off-by-one error that must be kept in mind.\n\\subsubsection{Memoization}\n\\label{sec:dpmemo}\nThe main goal of DP is to speed up computation time by storing values that were already computed--also called \\emph{memoization}--and reusing those values whenever applicable.\nIn the code fragment, \\scala{cache} is responsible for this: whenever a value of \\scala{O}, the objective function, is needed, the program calls \\scala{O_} which serves as an alias for \\scala{cache.getOrElseUpdate}.\nThe latter's name describes what it does quite aptly: informally, it tells the computer to go and check if the value that is needed is already stored in \\scala{cache}.\nIf it is, \\scala{O_} simply returns that value; on the other hand, if it was not cached yet, it is computed (using the recursive property of the objective function) and the result is stored in \\scala{cache} for future reference.\n\\subsubsection{Output Formatting}\n\\label{sec:dpoutput}\nThe \\scala{Map} called \\scala{tkn} stores whether the optimal solution for a given \\scala{j} and \\scala{k} uses the \\scala{j}th element.\nThis is not related to the actual knapsack problem, but is necessary to be able to construct the output according to the specifications.\n\n\\subsection{Advantages and Disadvantages}\n\\subsubsection{Advantages}\nDP has several advantages:\n\\begin{itemize}\n\t\\item The algorithm is very easy to understand and easy to debug.\n\t\\item \\emph{For small values of \\(C\\)}, the algorithm is very fast and can very quickly solve problems which would be nigh impossible with a brute force search.\n\\end{itemize}\n\\subsubsection{Disadvantages}\nOn the other hand, there are some major downsides to the DP algorithm as well:\n\\begin{itemize}\n\t\\item \\emph{For large values of \\(C\\)}, the algorithm's pseudo-polynomiality makes it unusable.\n\tA variation based on the value \\(V\\) is also possible, but the same restrictions apply when \\(V\\) is large.\n\tThis is for example what caused Instance B to take far too long using DP: for reference, while there are only 56 items to select, the maximum capacity and optimal value are both 104 723 596, meaning neither variation of the algorithm performs adequately.\n\\end{itemize}\nTaking all of this into account, DP makes for a good first try at a solution, and can serve as an easy way to obtain solutions to a real-life problem to see whether other, more complex algorithms are correctly implemented and thought out.\nFor this assignment, two instances were solved using DP (D and E).\n\n\\section{Branch and Bound}\nBranch and bound, or BnB for short, is an algorithm which uses upper-bounding and tree search in order to discard parts of a huge binary tree which have been shown not to contain an optimal solution.\nMore formally, consider the knapsack problem of Section~\\ref{sec:intro}.\nThis problem, in a way, searches for a tuple of binary values which maximizes the objective function.\nConsider the search tree formed by the possible value assignments to this tuple.\nAt the root, all variables are ``free'' to be either 1 or 0, but every time the tree branches in two, the left subtree has a variable set to 1, while the right subtree has that same variable set to 0.\nIf one has a procedure to efficiently find an upper bound for the subtree rooted at a certain node, the optimal solution can be obtained by first finding a feasible solution, and then trying to find a better one while discarding subtrees with an upper bound lower than or equal to the best known value of the feasible solution.\nThis way, one can avoid having to explore the entire search tree, whose size grows exponentially with the number of decision variables.\n\n\\subsection{Design Choices}\nThe explanation above is purposely vague, since many design choices still need to be taken based on the specific instance of the problem.\nThe most important is of the upper-bounding procedure.\nWhile technically not necessary to find a solution, this is required to help discard subtrees faster and thus make the algorithm solve problems much more efficiently.\nIf the upper-bounding procedure is not sufficiently tight (or takes a long time to compute), branch and bound is not much better than a brute force approach.\n\n\\subsubsection{Upper-bounding}\nThe upper-bounding procedure of choice, which gives great results in the majority of cases, is called \\emph{linear relaxation}.\nWhat LR does is, instead of forcing variables to be binary, it allows them to be anywhere in \\([0, 1]\\).\nBy then sorting free items (i.e., whose decision variable has not been set yet) by their utility ratio, that is, the ratio between their value and weight, and selecting as many of these items (and potentially, fractions of items) as possible until the capacity constraint is tight, we can guarantee that the optimal objective will be lower than or equal to this upper bound.\n\nTo implement this, we do the following (suppose that \\scala{selectable} has been \\textbf{sorted} already):\n\\begin{minted}[fontsize=\\scriptsize]{scala}\noverride val upperBound: Double = {\n  // Linear relaxation.\n  var i: Int = 0\n  var ub: Double = obj\n  var c: Int = capa\n  if (c > 0) {\n    while (i < selectable.length\n        && c >= weight(selectable(i))) {\n      c = c - weight(selectable(i))\n      ub = ub + value(selectable(i))\n      i += 1\n    }\n    if (i < selectable.length) {\n      val d: Double = c.toDouble / weight(selectable(i))\n      ub = ub + value(selectable(i)) * d\n    }\n  }\n  ub\n}\n\\end{minted}\nIn this code fragment, one can distinguish two main steps:\n\\begin{enumerate}\n\t\\item first, use all the free variables (those in \\scala{selectable}) in order to find the \\emph{critical item} which would make the knapsack too full;\n\t\\item add whatever you can of the critical item, maxing out the capacity.\n\\end{enumerate}\n\nAdditionally, though not necessary, the flooring function can be applied to this final result, since one can prove that if the weights and values are integers, then so is the optimal solution.\n\n\\subsubsection{Traversal algorithm}\nThis section mentions the traversal algorithms which can be used to decide which nodes are to be explored first.\nConcretely, two options exist, each with their own advantages and disadvantages:\n\\begin{itemize}\n\t\\item \\emph{Best-first search}.\n\tThis traversal looks at the most promising nodes (highest upper bound) first.\n\tThis search strategy can be implemented with a \\scala{PQueue}; the code used for this is heavily influenced by the one on the course's BitBucket repository, written by Pierre Schaus.\n\tThe main advantage of this strategy is also its main drawback: it depends heavily on the quality of the upper-bounding procedure in order to be successful.\n\tAnother big drawback is that the user has no control over the number of open nodes which are kept in memory.\n\t\\item \\emph{Depth-first search}.\n\tDFS looks at the deepest, leftmost node first, regardless of the upper bound (as long as exploring the subtree makes sense, i.e. as long as the subtree potentially contains an optimal solution).\n\tThis can be implemented with a \\scala{Stack}.\n\tThis strategy, while not being as good in general at finding optimal solutions, does fare much better in the memory department, since memory consumption is proportional to the height of the tree, which is typically linear.\n\\end{itemize}\nIn the code, the only change that needs to be made is in the \\scala{OpenNodes} implementation.\n\nFor this assignment, a best-first search algorithm using linear relaxation for upper bounding was used to solve instances A, C and F, which did either not get solved within the memory and time constraints by the DP algorithm (C) or because BnB was implemented before DP (A and F, where both algorithms arrive at the correct solution).\n\n\\subsection{Output formatting}\n\\label{sec:bnboutput}\nWhen sorting the elements with the goal of being able to apply LR, the initial order gets lost.\nThis is quite problematic for this particular assignment, since the output format makes use of the initial order.\nTo get around this problem, one can add the original weight and value vectors to the \\scala{KnapsackNode}, using these to identify used items.\nThe assumption that two items cannot be identical was verified beforehand, meaning this is a correct way for the instances of the assignment to recover the initial ordering.\n\n\\subsection{The Peculiar Case of Instance B}\nInstance B has the property that all its items have a unit utility ratio.\nThis means that sorting them does nothing, other than potentially shuffle them (since quicksort is not a stable sort).\nAdd in the fact that the LR upper bound, while tight, gives little extra information in this case, and one quickly gets a problem which takes a very long time to get solved.\n\nHowever, seeing as sorting by utility ratio does not change the ordering, and that the upper bound, despite being tight, does not allow best-first search to solve the problem optimally fast enough, an algorithm using DFS based on a \\scala{Stack} was implemented, with elements being sorted based on their value (most valuable items being taken first).\n\nThis algorithm outperforms the other BnB one (and the DP solver as well) by quite some margin, finding the optimal solution in a matter of seconds (in fact, it happens to go down the ``optimal'' path almost immediately due to the order in which variables are examined).\n\n\\section{Conclusion}\nThe knapsack problem is one of the most important problems in combinatorial optimization, and DP and BnB are only some of the many possible ways to solve instances of it.\nThanks to this assignment, we learnt that in some cases, it is very hard to predict which algorithm is best-suited to a given instance.\n\nImplementing the various algorithms helped to better understand why and how they work, while playing around with them on various instances helped to identify their strengths and shortcomings.\n\\end{document}", "meta": {"hexsha": "3bb6130e9bef965f3351fcb0c9e01a195bf91ec8", "size": 14366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/assignment1/report.tex", "max_stars_repo_name": "Peiffap/lingi2266-implementations", "max_stars_repo_head_hexsha": "f069d8cc7872c7d8b22cf69b4c77d4d7bb83fd16", "max_stars_repo_licenses": ["MIT"], "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/assignment1/report.tex", "max_issues_repo_name": "Peiffap/lingi2266-implementations", "max_issues_repo_head_hexsha": "f069d8cc7872c7d8b22cf69b4c77d4d7bb83fd16", "max_issues_repo_licenses": ["MIT"], "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/assignment1/report.tex", "max_forks_repo_name": "Peiffap/lingi2266-implementations", "max_forks_repo_head_hexsha": "f069d8cc7872c7d8b22cf69b4c77d4d7bb83fd16", "max_forks_repo_licenses": ["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.7117117117, "max_line_length": 374, "alphanum_fraction": 0.761937909, "num_tokens": 3484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6283873917417158}}
{"text": "\\subsection{Groups}\\label{subsec:groups}\n\n\\begin{definition}\\label{def:unital_magma_inverse_element}\n  Let \\( \\mscrM \\) be a \\hyperref[def:unital_magma]{unital magma}. We say that \\( y \\) is the \\term{left inverse} (resp. \\term{right inverse}) of \\( x \\) if \\( yx = e \\) (resp. \\( xy = e \\)).\n\n  If \\( y \\) is simultaneously a left and right inverse of \\( x \\), we call a \\term{two-sided inverse} or simply an \\term{inverse} of \\( x \\) and denote it by \\( x^{-1} \\). It is unique by \\fullref{def:unital_magma_inverse_element_unique}. This notation is consistent with \\fullref{def:unital_magma/exponentiation}\n\\end{definition}\n\n\\begin{proposition}\\label{def:unital_magma_inverse_element_unique}\n  For every element \\( x \\) of any unital magma, the (two-sided) \\hyperref[def:unital_magma_inverse_element]{inverse} \\( x^{-1} \\) of \\( x \\) is unique.\n\\end{proposition}\n\\begin{proof}\n  If \\( y \\) and \\( z \\) are both inverses of \\( x \\), then\n  \\begin{equation*}\n    y = ey = zxy = ze = z.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:group}\n  A \\term{group} is a \\hyperref[def:unital_magma/monoid]{monoid} in which every element has an \\hyperref[def:unital_magma_inverse_element]{inverse}. Groups are the most well-studied and most well-behaved magmas. Many useful properties like \\hyperref[thm:def:group/properties/cancellative]{cancellation} rely on associativity, so we do not consider non-associative groups.\n\n  \\begin{thmenum}\n    \\thmitem{def:group/theory} We can construct the \\hyperref[def:first_order_theory]{theory of groups} by adding a unary \\hyperref[def:first_order_language/func]{functional symbol} \\( (\\anon)^{-1} \\) and the axiom\n    \\begin{equation}\\label{eq:def:group/theory/inverse_axiom}\n      \\qforall \\xi (\\xi \\cdot \\xi^{-1} = e \\wedge \\xi^{-1} \\cdot \\xi = e)\n    \\end{equation}\n    to the theory of \\hyperref[def:unital_magma/monoid]{monoids}.\n\n    \\thmitem{def:group/function_parity} A \\hyperref[def:function]{function} \\( \\varphi: \\mscrG \\to \\mscrH \\) between two groups is called \\term{even} if, for every \\( x \\in \\mscrG \\), we have\n    \\begin{equation}\\label{eq:def:group/function_parity/even}\n      \\varphi(x^{-1}) = \\varphi(x)\n    \\end{equation}\n    and \\term{odd} if\n    \\begin{equation}\\label{eq:def:group/function_parity/odd}\n      \\varphi(x^{-1}) = \\varphi(x)^{-1}.\n    \\end{equation}\n\n    \\thmitem{def:group/homomorphism} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} between the groups \\( \\mscrG \\) and \\( \\mscrH \\) is an odd \\hyperref[def:unital_magma/homomorphism]{unital magma homomorphism}.\n\n    As shown in \\fullref{thm:group_homomorphism_single_condition}, however, the conditions \\eqref{eq:def:pointed_set/homomorphism} and \\eqref{eq:def:group/function_parity/odd} are redundant.\n\n    \\thmitem{def:group/submodel} The set \\( S \\subseteq \\mscrG \\) is a \\hyperref[def:first_order_substructure]{first-order substructure} of \\( \\mscrG \\) if it is a \\hyperref[def:unital_magma/submodel]{unital submagma} and if \\( S^{-1} = S \\), where\n    \\begin{equation*}\n      S^{-1} = \\set{ s^{-1} \\given s \\in S }.\n    \\end{equation*}\n\n    \\thmitem{def:group/trivial}  The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} group is the \\hyperref[def:pointed_set/trivial]{trivial pointed set} \\( \\set{ e } \\).\n\n    \\thmitem{def:group/category} The \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} of groups \\( \\ucat{Grp} \\) is \\hyperref[def:concrete_category]{concrete} with respect to \\hyperref[def:unital_magma/monoid]{\\( \\ucat{Mon} \\)}.\n\n    \\thmitem{def:group/exponentiation} We extend \\hyperref[def:unital_magma/exponentiation]{unital magma exponentiation} to all integers by setting\n    \\begin{equation*}\n      x^{-n} \\coloneqq (x^n)^{-1}.\n    \\end{equation*}\n\n    This operation behaves well as shown in \\fullref{thm:def:group/properties/negative_power}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:group_homomorphism_single_condition}\n  A function \\( \\varphi: \\mscrG \\to \\mscrH \\) between the groups \\( \\mscrG \\) and \\( \\mscrH \\) is a \\hyperref[def:group/homomorphism]{homomorphism} if and only if it satisfies \\eqref{eq:def:magma/homomorphism}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof \\eqref{eq:def:magma/homomorphism} is required to hold by definition.\n\n  \\NecessitySubProof Let the function \\( \\varphi \\) satisfy \\eqref{eq:def:magma/homomorphism}. Then it preserves identities (i.e. is a \\hyperref[def:pointed_set/homomorphism]{pointed set homomorphism}) since\n  \\begin{equation*}\n    e_{\\mscrH} \\varphi(e_{\\mscrG}) = \\varphi(e_{\\mscrG}) = \\varphi(e_{\\mscrG} e_{\\mscrG}) = \\varphi(e_{\\mscrG}) \\varphi(e_{\\mscrG})\n  \\end{equation*}\n  and by \\fullref{thm:def:group/properties/cancellative}, the operation is cancellative.\n\n  Inverses are preserved (i.e. \\eqref{eq:def:group/function_parity/odd} holds) because\n  \\begin{equation*}\n    \\varphi(x^{-1})\n    =\n    \\varphi(x^{-1}) e_{\\mscrH}\n    =\n    \\varphi(x^{-1}) \\varphi(x) \\varphi(x)^{-1}\n    =\n    \\varphi(x^{-1} x) \\varphi(x)^{-1}\n    =\n    e_{\\mscrH} \\varphi(x)^{-1}\n    =\n    \\varphi(x)^{-1}.\n  \\end{equation*}\n\n  Therefore, \\( \\varphi \\) is indeed a group homomorphism.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:group/properties}\n  Every \\hyperref[def:group]{group} \\( \\mscrG \\) has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:group/properties/cancellative} The (binary) group operation is \\hyperref[def:magma/cancellative]{cancellative}.\n    \\thmitem{thm:def:group/properties/identity_inverse} The identity \\( e \\) is its own inverse.\n    \\thmitem{thm:def:group/properties/inverse_composition} \\( (xy)^{-1} = y^{-1} x^{-1} \\).\n    \\thmitem{thm:def:group/properties/double_inverse} \\( x = (x^{-1})^{-1} \\)\n    \\thmitem{thm:def:group/properties/negative_power} For any positive integer \\( n \\), \\( (x^n)^{-1} = (x^{-1})^n \\)\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:group/properties/cancellative} If \\( x = y \\), obviously \\( xz = yz \\) and \\( zx = zy \\). Now if \\( xz = yz \\), we have\n  \\begin{equation*}\n    x = x(zz^{-1}) = (xz)z^{-1} = (yz)z^{-1} = y(zz^{-1}) = y.\n  \\end{equation*}\n\n  The case \\( zx = zy \\) is analogous.\n\n  \\SubProofOf{thm:def:group/properties/identity_inverse} \\( ee = e \\).\n  \\SubProofOf{thm:def:group/properties/inverse_composition}\n  \\begin{equation*}\n    (xy) (y^{-1} x^{-1})\n    =\n    x (y y^{-1}) x^{-1}\n    =\n    e\n    =\n    y^{-1} (x^{-1} x) y\n    =\n    (y^{-1} x^{-1}) (xy).\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:group/properties/double_inverse}\n  \\begin{equation*}\n    (x^{-1})^{-1}\n    =\n    x x^{-1} (x^{-1})^{-1}\n    =\n    x.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:group/properties/negative_power} Using \\fullref{thm:def:group/properties/double_inverse},\n  \\begin{equation*}\n    x^{-n}\n    =\n    (x^n)^{-1}\n    =\n    x^{-1} \\cdots x^{-1}\n    =\n    (x^{-1})^n.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:power_set_is_not_a_group}\n  The \\hyperref[def:magma/power_set]{power set magma} \\( \\pow(\\mscrG) \\) of a group \\( \\mscrG \\) is a monoid, but it is not a group unless \\( \\mscrG \\) is trivial.\n\\end{example}\n\n\\begin{definition}\\label{def:group_cosets}\n  Let \\( \\mscrH \\subseteq \\mscrG \\) be a subgroup of \\( \\mscrG \\) and let \\( x \\in \\mscrG \\). The sets\n  \\begin{equation*}\n    x \\mscrH \\coloneqq \\set{ xh \\colon h \\in \\mscrH }\n    \\quad\\quad\n    \\mscrH x \\coloneqq \\set{ hx \\colon h \\in \\mscrH }\n  \\end{equation*}\n  are called the left and right \\term{cosets} of \\( \\mscrH \\) with respect to \\( x \\). The name is justified by \\fullref{thm:group_coset_partition}.\n\n  The \\hyperref[def:cardinal]{cardinality} of the set of all left cosets is called the \\term{index} of \\( \\mscrH \\) and is denoted by \\( [\\mscrG : \\mscrH] \\). By \\fullref{thm:lagranges_theorem_for_groups}, the index can analogously be defined as the cardinality of all right cosets.\n\\end{definition}\n\n\\begin{lemma}\\label{thm:group_coset_partition}\n  The \\hyperref[def:group_cosets]{left cosets} of a subgroup of \\( \\mscrG \\) \\hyperref[def:set_partition]{partition} \\( \\mscrG \\). The same holds for right cosets.\n\\end{lemma}\n\\begin{proof}\n  To each element \\( x \\in \\mscrG \\) there corresponds a coset \\( x \\in x\\mscrH \\) (since, as a subgroup, \\( \\mscrH \\) contains the identity).\n\n  Two cosets \\( x\\mscrH \\) and \\( y\\mscrH \\) are either disjoint or equal. Indeed, if they are not disjoint, then there exists \\( z \\in x\\mscrH \\cap y\\mscrH \\) and thus \\( z = xa = yb \\) for some \\( a, b \\in \\mscrH \\). Thus,\n  \\begin{equation*}\n    x = x a a^{-1} = y b a^{-1}\n  \\end{equation*}\n  and since \\( b a^{-1} \\in \\mscrH \\), we have that \\( x \\in y\\mscrH \\). Furthermore, for any \\( c \\in \\mscrH \\), we have\n  \\begin{equation*}\n    xc = y(b a^{-1} c) \\in y\\mscrH,\n  \\end{equation*}\n  hence \\( x\\mscrH \\subseteq y\\mscrH \\). After obtaining the converse inclusion, we conclude \\( x\\mscrH = y\\mscrH \\).\n\\end{proof}\n\n\\begin{lemma}\\label{thm:group_coset_bijection}\n  Any two left cosets in a group are \\hyperref[def:equinumerosity]{equinumerous}. The same holds for right cosets.\n\\end{lemma}\n\\begin{proof}\n  Let \\( \\mscrH \\) be a subgroup of \\( \\mscrG \\) and let \\( x, y \\in \\mscrG \\). Then \\( z \\mapsto y x^{-1} z \\) sends \\( x\\mscrH \\) into \\( y\\mscrH \\). By \\fullref{thm:group_multiplication_is_bijection}, this function is a bijection.\n\\end{proof}\n\n\\begin{definition}\\label{def:normal_subgroup}\n  Let \\( \\mscrN \\) be a subgroup of \\( \\mscrG \\). We say that \\( \\mscrN \\) is a normal subgroup if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:normal_subgroup/direct} For every element \\( x \\) of \\( \\mscrG \\), we have the set equality\n    \\begin{equation}\\label{eq:def:normal_subgroup/direct}\n      x \\mscrN x^{-1} = \\mscrN.\n    \\end{equation}\n\n    \\thmitem{def:normal_subgroup/cosets} The partitions induced by the left and rights cosets of \\( \\mscrN \\) coincide.\n    \\thmitem{def:normal_subgroup/kernel} \\( \\mscrN \\) is the \\hyperref[def:pointed_set_kernel]{kernel} of some group homomorphism.\n  \\end{thmenum}\n\n  In particular, kernels are always normal subgroups.\n\\end{definition}\n\\begin{proof}\n  This is the group-theoretic analog to \\fullref{thm:equivalence_partition}.\n\n  \\ImplicationSubProof{def:normal_subgroup/direct}{def:normal_subgroup/cosets} For any \\( x \\in \\mscrG \\)\n  \\begin{equation*}\n    \\mscrN x = (x \\mscrN x^{-1})x = x \\mscrN(x^{-1}x) = x \\mscrN,\n  \\end{equation*}\n  thus every left coset is a right coset and vice versa.\n\n  \\ImplicationSubProof{def:normal_subgroup/cosets}{def:normal_subgroup/kernel} We can take the \\hyperref[def:quotient_group]{canonical projection} \\( \\pi(x) \\coloneqq x \\mscrN \\) as the homomorphism. The proof of correctness in \\fullref{def:quotient_group} only uses \\fullref{def:normal_subgroup/cosets} and therefore does not cause circular references.\n\n  \\ImplicationSubProof{def:normal_subgroup/kernel}{def:normal_subgroup/direct} Let \\( \\varphi: \\mscrG \\to \\mscrH \\) be a group homomorphism and fix any \\( x \\in \\mscrG \\). Denote \\( \\mscrN \\coloneqq \\ker(f) \\). Then \\( x \\mscrN = \\mscrN x \\) since\n  \\begin{equation*}\n    \\varphi(x \\mscrN)\n    =\n    \\varphi(x) \\varphi(\\mscrN)\n    =\n    \\varphi(x) \\varphi(e_{\\mscrG})\n    =\n    \\varphi(x)\n    =\n    \\varphi(\\mscrN) \\varphi(x)\n    =\n    \\varphi(\\mscrN x)\n    =\n    e_{\\mscrH}.\n  \\end{equation*}\n\n  Thus,\n  \\begin{equation*}\n    \\varphi^{-1}(e_{\\mscrH}) = \\mscrN = xx^{-1}\\mscrN = x \\mscrN x^{-1}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:quotient_group}\n  Let \\( \\mscrG \\) be a group and \\( \\mscrN \\) be a normal subgroup of \\( \\mscrG \\). Define the \\term{quotient group}\n  \\begin{equation*}\n    \\mscrG / \\mscrN \\coloneqq \\{ x \\mscrN \\colon x \\in \\mscrG \\}\n  \\end{equation*}\n  with the group operation\n  \\begin{equation*}\n    x \\mscrN \\star y \\mscrN \\coloneqq xy \\mscrN.\n  \\end{equation*}\n\n  Define the canonical projection homomorphism\n  \\begin{align*}\n    &\\pi: \\mscrG \\to \\mscrG / \\mscrN \\\\\n    &\\pi(x) \\coloneqq x \\mscrN.\n  \\end{align*}\n\n  The kernel of \\( \\pi \\) is precisely \\( \\mscrN \\).\n\\end{definition}\n\\begin{proof}\n  This definition is used in the proof of equivalence in \\fullref{def:normal_subgroup}. This is why it is important to only use \\fullref{def:normal_subgroup/cosets} as the definition for a normal subgroup.\n\n  We first check that the group operations is well-defined, that is, does not depend on the choice of coset representatives. Fix \\( x_1, x_2 \\in \\mscrG \\) and \\( y_1, y_2 \\in \\mscrG \\), so that\n  \\begin{equation*}\n    x_1 \\mscrN = y_1 \\mscrN\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    x_2 \\mscrN = y_2 \\mscrN.\n  \\end{equation*}\n\n  Since the left and right cosets coincide, we have\n  \\begin{equation*}\n    x_1 x_2 \\mscrN = x_1 \\mscrN x_2 = x_1 \\mscrN y_2 = y_1 \\mscrN y_2 = y_1 y_2 \\mscrN.\n  \\end{equation*}\n\n  Thus, the operation is well-defined.\n\n  It follows from the definition that the identity is \\( e \\mscrN = \\mscrN \\) and the inverse of \\( x \\mscrN \\) is \\( x^{-1} \\mscrN \\). Therefore, \\( \\mscrG / \\mscrN \\) is indeed a group. The fact that \\( \\pi \\) is a homomorphism is also part of the definition of \\( \\star \\).\n\n  It remains to prove that \\( \\mscrN = \\ker(\\pi) \\). Obviously \\( \\pi(\\mscrN) = \\mscrN \\), so \\( \\mscrN \\subseteq \\ker(\\pi) \\). To see that the converse holds, assume that there exists \\( x \\in \\ker(\\pi) \\setminus \\mscrN \\), i.e. \\( \\pi(x) = x\\mscrN = \\mscrN \\), but \\( x \\not\\in N \\). Then there exists \\( y \\in N \\) such that \\( xy \\in N \\). The subgroup \\( \\mscrN \\) is closed under multiplication and inverses, hence \\( x = xyy^{-1} \\in N \\). This contradicts our assumption that \\( x \\not\\in N \\). Therefore, \\( \\mscrN = \\ker \\pi \\).\n\\end{proof}\n\n\\begin{theorem}[Lagrange's theorem for groups]\\label{thm:lagranges_theorem_for_groups}\n  Let \\( \\mscrH \\) be a subgroup of \\( \\mscrG \\). We have the following equality\n  \\begin{equation}\\label{eq:thm:lagranges_theorem_for_groups/index}\n    \\card(\\mscrG) = \\card(\\mscrH) \\cdot [\\mscrG : \\mscrH].\n  \\end{equation}\n\n  If \\( \\mscrH \\) is a \\hyperref[def:normal_subgroup]{normal subgroup}, then \\( [\\mscrG : \\mscrH] = \\card(\\mscrG / \\mscrH) \\) and\n  \\begin{equation}\\label{eq:thm:lagranges_theorem_for_groups/card}\n    \\card(\\mscrG) = \\card(\\mscrH) \\cdot \\card(\\mscrG / \\mscrH).\n  \\end{equation}\n\n  This demonstrates that there exists a bijective function between the \\hyperref[def:group_direct_product]{direct product} \\( \\mscrH \\times \\mscrG / \\mscrH \\) and \\( \\mscrH \\), however this may not be a group homomorphism --- see \\fullref{ex:lagranges_theorem_for_groups/direct_product_zn}.\n\\end{theorem}\n\\begin{proof}\n  Follows from \\fullref{thm:group_coset_partition} and \\fullref{thm:group_coset_bijection}\n\\end{proof}\n\n\\begin{theorem}[Homomorphism theorem for groups]\\label{thm:homomorphism_theorem_for_groups}\n  For any \\hyperref[def:group/homomorphism]{group homomorphism} \\( \\varphi: \\mscrG \\to \\mscrH \\), we have the isomorphism\n  \\begin{equation*}\n    \\mscrG / \\ker \\varphi \\cong \\img \\varphi.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  Denote \\( \\mscrN \\coloneqq \\ker \\varphi \\). Define the function\n  \\begin{align*}\n    &\\psi: \\img \\varphi \\to \\pow(\\mscrG) \\\\\n    &\\psi(y) \\coloneqq \\varphi^{-1}(y) \\mscrN.\n  \\end{align*}\n\n  We will show that \\( \\psi \\) is the desired isomorphism.\n\n  Fix any \\( y \\in \\img \\varphi \\) and \\( x_1, x_2 \\in \\varphi^{-1}(y) \\). We will first show that \\( x_1 \\mscrN = x_2 \\mscrN \\). Note that\n  \\begin{equation*}\n    \\varphi(x_1^{-1} x_2)\n    =\n    \\varphi(x_1)^{-1} \\varphi(x_2)\n    =\n    \\varphi(x_2)^{-1} \\varphi(x_2)\n    =\n    e_{\\mscrH},\n  \\end{equation*}\n  therefore \\( x_1^{-1} x_2 \\in N \\). Thus,\n  \\begin{equation*}\n    x_2 \\mscrN = x_1 x_1^{-1} x_2 \\mscrN = x_1 \\cdot \\mscrN \\cdot \\mscrN = x_1 \\mscrN.\n  \\end{equation*}\n\n  Hence, \\( \\varphi^{-1}(y) \\mscrN \\) is a coset in \\( \\mscrG / \\mscrN \\) formed by any of the elements of \\( \\varphi^{-1}(y) \\).\n\n  Furthermore, if \\( x_1 \\in x_2 \\mscrN \\), then there exists \\( n \\in N \\) such that\n  \\begin{equation*}\n    x_1 = x_2 n.\n  \\end{equation*}\n\n  But \\( \\mscrN \\) is closed under taking inverses, hence\n  \\begin{equation*}\n    x_2 = x_1 n^{-1} \\in x_1 \\mscrN,\n  \\end{equation*}\n  that is,\n  \\begin{equation*}\n    x_1 \\mscrN = x_2 \\mscrN.\n  \\end{equation*}\n\n  This shows that \\( \\psi \\) is injective. It is obviously surjective because if \\( x \\mscrN \\) is a coset, then \\( \\varphi(x) \\in \\img \\varphi \\). Therefore, \\( \\varphi \\) is bijective.\n\n  It remains to show that \\( \\psi \\) is a homomorphism. Indeed, if \\( y_1, y_2 \\in \\img \\varphi \\) and\n  \\begin{equation*}\n    x_k \\in \\varphi^{-1}(y_k), k = 1, 2,\n  \\end{equation*}\n  we have\n  \\begin{balign*}\n    \\psi(y_1) \\psi(y_2)\n    &=\n    \\varphi^{-1}(y_1) \\mscrN \\varphi^{-1}(y_2) \\mscrN\n    = \\\\ &=\n    x_1 \\mscrN x_2 \\mscrN\n    \\reloset {\\eqref{eq:def:normal_subgroup/direct}} = \\\\ &=\n    (x_1 x_2) \\mscrN\n    = \\\\ &=\n    \\varphi^{-1}(y_1 y_2) \\mscrN\n    = \\\\ &=\n    \\psi(y_1 y_2).\n  \\end{balign*}\n\\end{proof}\n", "meta": {"hexsha": "80f819d7a08247e125ea8601496020d2c6e79444", "size": 16918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/groups.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/groups.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/groups.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.3893557423, "max_line_length": 538, "alphanum_fraction": 0.6623714387, "num_tokens": 6040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6283873907814009}}
{"text": "\\newpage\r\n\\section{Roots Package}\r\n\\begin{Introduction}{Roots Package}\r\n\\index{roots}\\index{polynomial}\r\nThe root  finding package is designed  so that it can  \r\nbe  used to  find some  or  all of  the roots  of  univariate\r\npolynomials  with  real or  complex  coefficients,  to  the  accuracy\r\nspecified by the user.                             \r\n\r\nNot all operators of \\name{roots package} are described here. For using\r\nthe operators \r\n\r\n\\nameindex{isolater} (intervals isolating real roots)\r\n\r\n\\nameindex{rlrootno} (number of real roots in an interval)\r\n\r\n\\nameindex{rootsat-prec} (roots at system precision)\r\n\r\n\\nameindex{rootval} (result in equation form)\r\n\r\n\\nameindex{firstroot} (computing only one root)\r\n\r\n\\nameindex{getroot} (selecting roots from a collection)\r\n\r\nplease consult the full documentation of the package.\r\n\r\n\\end{Introduction}\r\n\r\n\\begin{Operator}{MKPOLY}\r\n\\index{polynomial}\\index{roots}\\index{interpolation}\r\nGiven a roots list as returned by \\nameref{roots},\r\nthe operator \\name{mkpoly} constructs a \r\npolynomial which has these numbers as roots.\r\n\\begin{Syntax}\r\n\\name{mkpoly} \\meta{rl}\r\n\\end{Syntax}\r\nwhere \\meta{rl} is a \\nameref{list} with equations, which\r\nall have the same \\nameref{kernel} on their left-hand sides\r\nand numbers as right-hand sides.\r\n\r\n\\begin{Examples}\r\nmkpoly{x=1,x=-2,x=i,x=-i};&\r\nx**4 + x**3 - x**2 + x - 2\\\\\r\n\\end{Examples}\r\n\r\nNote that this polynomial is unique only up to a numeric\r\nfactor.\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{NEARESTROOT}\r\n\\index{roots}\\index{solve}\r\nThe operator \\name{nearestroot} finds one root of a polynomial\r\nwith an iteration using a given starting point.\r\n\r\n\\begin{Syntax}\r\n\\name{nearestroot}\\(\\meta{p}\\,\\meta{pt}\\)\r\n\\end{Syntax}\r\n\r\nwhere \\meta{p} is a univariate polynomial\r\nand \\meta{pt} is a number. \r\n\r\n\\begin{Examples}\r\nnearestroot(x^2+2,2);&\\{x=1.41421*i\\}\\\\\r\n\\end{Examples}\r\nThe minimal accuracy of the result values is controlled by \r\n\\nameref{rootacc}.\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{REALROOTS}\r\n\\index{roots}\\index{solve}\r\nThe operator \\name{realroots} finds that real roots of a polynomial  \r\nto an accuracy that is sufficient to separate them  and which is\r\na minimum of  6 decimal places.              \r\n\r\n\\begin{Syntax}\r\n\\name{realroots}\\(\\meta{p}\\) or \\\\\r\n\\name{realroots}\\(\\meta{p}\\,\\meta{from},\\meta{to}\\)\r\n\\end{Syntax}\r\n\r\nwhere \\meta{p} is a univariate polynomial. \r\nThe optional parameters \\meta{from} and \\meta{to} classify\r\nan interval: if given, exactly the real roots in this\r\ninterval will be returned. \\meta{from} and \\meta{to}\r\ncan also take the values \\name{infinity} or \\name{-infinity}.\r\nIf omitted all real roots will be returned.\r\nResult is a \\nameref{list}\r\nof equations which represent the roots of the polynomial at the\r\ngiven accuracy.\r\n\r\n\\begin{Examples}\r\nrealroots(x^5-2);&\\{x=1.1487\\}\\\\\r\nrealroots(x^3-104*x^2+403*x-300,2,infinity);&\\{x=3.0,x=100.0\\}\\\\\r\nrealroots(x^3-104*x^2+403*x-300,-infinity,2);&\\{x=1\\}\\\\\r\n\\end{Examples}\r\nThe minimal accuracy of the result values is controlled by \r\n\\nameref{rootacc}.\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{ROOTACC}\r\n\\index{roots}\\index{accuracy}\r\nThe operator \\name{rootacc} allows you to set the accuracy\r\nup to which the roots package computes its results.\r\n\\begin{Syntax}\r\n\\name{rootacc}\\(\\meta{n}\\)\r\n\\end{Syntax}\r\nHere \\meta{n} is an integer value. The internal accuracy of\r\nthe \\name{roots} package is adjusted to a value of\r\n\\name{max(6,n)}. The default value is \\name{6}.\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{ROOTS}\r\n\\index{roots}\\index{solve}\\index{polynomial}\r\nThe operator \\name{roots} \r\nis  the main top level  function of the roots  package.\r\nIt will  find all roots, real and  complex, of the polynomial  p\r\nto an accuracy that is sufficient to separate them  and which is\r\na minimum of  6 decimal places.               \r\n\r\n\\begin{Syntax}\r\n\\name{roots}\\(\\meta{p}\\)\r\n\\end{Syntax}\r\n\r\nwhere \\meta{p} is a univariate polynomial. Result is a \\nameref{list}\r\nof equations which represent the roots of the polynomial at the\r\ngiven accuracy. In addition, \\name{roots}  stores\r\nseparate  lists of real  roots and complex  roots in the  global\r\nvariables \\nameref{rootsreal} and \\nameref{rootscomplex}. \r\n\r\n\\begin{Examples}\r\nroots(x^5-2);&\\begin{multilineoutput}{3cm}\r\n\\{x=-0.929316 + 0.675188*i,\r\n  x=-0.929316 - 0.675188*i,\r\n  x=0.354967 + 1.09248*i,\r\n  x=0.354967 - 1.09248*i, \r\n  x=1.1487\\}\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\nThe minimal accuracy of the result values is controlled by \r\n\\nameref{rootacc}.\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{ROOT\\_VAL}\r\n\\index{roots}\\index{solve}\\index{polynomial}\r\nThe operator \\name{root\\_val} computes the roots of a \r\nunivariate polynomial at system precision\r\n(or greater if required for root separation) and presents \r\nits result as a list of numbers.\r\n\\begin{Syntax}\r\n\\name{roots}\\(\\meta{p}\\)\r\n\\end{Syntax}\r\n\r\nwhere \\meta{p} is a univariate polynomial.\r\n\r\n\\begin{Examples}\r\nroot_val(x^5-2);&\\begin{multilineoutput}{3cm}\r\n\\{-0.929316490603 + 0.6751879524*i,\r\n -0.929316490603 - 0.6751879524*i,\r\n 0.354967313105 + 1.09247705578*i,\r\n 0.354967313105 - 1.09247705578*i,\r\n 1.148698355\\}\r\n\\end{multilineoutput}\\\\\r\n\\end{Examples}\r\n\\end{Operator} \r\n\r\n\\begin{Variable}{ROOTSCOMPLEX}\r\n\\index{roots}\\index{complex}\r\nWhen the operator \\nameref{roots} is called the complex\r\nroots are collected in the global variable \\name{rootscomplex}\r\nas \\nameref{list}.\r\n\\end{Variable}\r\n\r\n\r\n\\begin{Variable}{ROOTSREAL}\r\n\\index{roots}\\index{complex}\r\nWhen the operator \\nameref{roots} is called the real\r\nroots are collected in the global variable \\name{rootreal}\r\nas \\nameref{list}.\r\n\\end{Variable}\r\n", "meta": {"hexsha": "fedddc594ab46ffa1e44fc71f9259ef5e038d32b", "size": 5594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pk-roots.tex", "max_stars_repo_name": "nilqed/REDHELP", "max_stars_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "pk-roots.tex", "max_issues_repo_name": "nilqed/REDHELP", "max_issues_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": "pk-roots.tex", "max_forks_repo_name": "nilqed/REDHELP", "max_forks_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "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": 30.9060773481, "max_line_length": 72, "alphanum_fraction": 0.7121916339, "num_tokens": 1643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6283873866612391}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Remove}\nThe inverse of the $append$ Operations.\n\\begin{zed}\n  remove(coll, idx) = \\inv append(coll, idx)\n\\end{zed}\nThe operation $remove$ will return a Collection minus the Value removed from the specified Numeric Index\n\\begin{schema}{Remove[Collection, \\nat]}\n  coll?, coll! : Collection \\\\\n  idx? : \\nat \\\\\n  remove~\\_ : Collection \\cross \\nat \\surj Collection\n  \\where\n  \\#~ idx? = 1 \\\\\n  coll! = remove(coll?, idx?) @ \\\\\n  \\t1 let ~ ~ coll' == front(\\{~ i : \\nat ~| ~ i \\in 0~..~idx?\\} \\extract coll?) \\\\\n  \\t1 \\ \\ \\ ~~~ coll'' == tail(\\{~ j : \\nat ~| ~ j \\in idx?~..~\\#~coll?\\} \\extract coll?) \\\\\n  \\t1 = coll' \\cat coll'' \\implies \\\\\n  \\t2 (coll?_{idx?} \\not \\in coll') ~\\land \\\\\n  \\t2 (coll?_{idx?} \\not \\in coll'') ~\\land \\\\\n  \\t2 (~\\#~ coll! = \\#~ coll? - 1)\n\\end{schema}\nsuch that\n\\begin{argue}\n  X = \\langle x_{0}, x_{1}, x_{2} \\rangle \\\\\n  \\t1 x_{0} = 0 \\\\\n  \\t1 x_{1} = foo \\\\\n  \\t1 x_{2} = baz \\\\\n  remove(X, 0) = \\langle foo, baz \\rangle & 0 was removed from $X$\\\\\n  remove(X, 1) = \\langle 0, baz \\rangle & foo was removed from $X$ \\\\\n  remove(X, 2) = \\langle 0, foo \\rangle & baz was removed from $X$ \\\\\n  remove(X, 3) = \\langle 0, foo, baz \\rangle = X & nothing at 3, X unaltered\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "6428aaf169f27feb27cd71a30aafa21f949e7fa6", "size": 1297, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/collections/remove.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/collections/remove.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/collections/remove.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 37.0571428571, "max_line_length": 104, "alphanum_fraction": 0.5797995374, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.628356333765862}}
{"text": "\\documentclass{article}\n\\usepackage{mathrsfs,amsmath}\n\\usepackage{xcolor}\n\\usepackage{titlesec}\n\\usepackage{listings}\n\\usepackage{syntax}\n\\usepackage{pythonhighlighting}\n\\usepackage{fancyvrb}\n\n\\usepackage[margin=1.4in]{geometry}\n\n\\title{Homework \\#1 | Fall 2021} \n\\author{Jared Dyreson\\\\ \n        California State University, Fullerton}\n\n\\DeclareRobustCommand{\\bowtie}{%\n  \\mathrel\\triangleright\\joinrel\\mathrel\\triangleleft}\n\n\n\\usepackage [english]{babel}\n\\usepackage [autostyle, english = american]{csquotes}\n\\MakeOuterQuote{\"}\n\n\\titlespacing*{\\section}\n{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}\n\\titlespacing*{\\subsection}\n{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}\n\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks,\n    citecolor=black,\n    filecolor=black,\n    linkcolor=black,\n    urlcolor=black\n}\n\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\n\\newpage\n\n\n\\section{Questions}\n\n\\begin{enumerate}\n\n\\item Order the following functions by asymptotic growth rate: \\\\\n\n$$4n, 2^{\\log(n)}, 4n \\times \\log(n) + 2n, 2^{10}, 3n + 100\\times \\log(n) \\times, 2^{n}, n^{2} + 10n, n^{3}, n \\times \\log(n)$$ \\\\\nState the asymptotic growth rate for each of the functions in terms of Big-Oh and explicitly order them from least to greatest.\n\n\n\\begin{itemize}\n\\item $2 ^ {10} \\implies O(1)$. Running time is independent of the input size.\n\\item $2^{\\log(n)} \\implies O(n)$ ? I would assume the log and 2 would cancel each other out in an event like this: $2^{\\log_2(n)}$. Unsure about this one.\n\\item $3n + 100 \\times log(n) \\implies O(n)$\n\\item $4n \\implies O(n)$\n\\item $n \\times \\log(n) \\implies O(n \\times \\log(n))$\n\\item $4n \\times \\log(n) + 2n \\implies O(n \\times \\log(n))$\n\\item $n^{2} + 10n \\implies O(n^{2})$\n\\item $n^{3} \\implies O(n^{3})$\n\\item $2^{n} \\implies O(2^{n}) \\rightarrow$ exponential.\n\\end{itemize}\n\n\\item Write a problem definition and pseudocode for each of the following problems.\n\\begin{itemize}\n\\item Computing a square root\n\\begin{table}[!htbp]\n\\centering\n\\begin{tabular}{|l|}\n\\hline\n\\textit{computing a square root} \\\\ \\hline\n\\textbf{input}: an real integer that is greater than or equal to 0 \\\\ \\hline\n\\textbf{output}: a floating point integer that is the resultant of a square root operation \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\begin{python}\n# Compute square root\ndef square_root_function(value):\n    # Driver code should recognize that -1 denotes failure\n    if value is less than 0, then return -1\n    else return value ** 0.5 # value raised to the 1/2 power\n\\end{python}\n\n\\item Determining whether an integer is even or odd\n\n\\begin{table}[!htbp]\n\\centering\n\\begin{tabular}{|l|}\n\\hline\n\\textit{determine whether integer is even or odd} \\\\ \\hline\n\\textbf{input}: a real integer that is greater than or equal to 0 \\\\ \\hline\n\\textbf{output}: a boolean value denoting status (true for even, false for odd) \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\\begin{python}\n# Check if integer is even or odd\ndef even_or_odd(value):\n    # even values should not have a remainder, thus equal to 0\n    return (value % 2 == 0)\n\n\\end{python}\n\n\\newpage\n\n\\item Determining whether every element in a sequence is identical\n\n\\begin{table}[!htbp]\n\\centering\n\\begin{tabular}{|l|}\n\\hline\n\\textit{determine whether all sequence elements are identical} \\\\ \\hline\n\\textbf{input}: a non-empty sequence that contains elements that are comparable with one another \\\\ \\hline\n\\textbf{output}: a boolean value denoting status of homogeneity \\\\ \\hline\n\\end{tabular}\n\n\n\\end{table}\n\n\\begin{python}\n# Check if sequence has all the same elements\ndef contains_same_elements(container: list[int]):\n    if container is empty:\n        return None\n    top_most = container[0]\n    x = 0\n    for element in container:\n        if(container[x] != top_most)\n            return False\n        top_most = container[x]\n        x = x + 1\n    return True\n\\end{python}\n\n\n\\end{itemize}\n\n\\item Consider the following algorithm:\n\\begin{Verbatim}\nAlgorithm Calc(a, n):\n    Input: two integers, a and n\n    Output: ?\n    k <- 0\n    b <- 1\n    while k < n do\n        k <- k + 1\n        b <- b * a\n    return b\n\\end{Verbatim}\n\n\\begin{python}\ndef calc(a: int, n: int) -> int:\n    k, b = 0, 1\n    while(k < n):\n        k += 1\n        b *= a\n        # two atomics, this is what a for loop is when broken down into smaller components\n    return b\n\\end{python}\n\n\\begin{itemize}\n\\item What does the algorithm calculate?: The value of $b$ continuously multiplied by a factor of $a$, $n$ times. $k$ is simply an index counter, and this entire expression can be written as a for loop:\n\\begin{python}\ndef calc(a: int, n: int) -> int:\n    b = 1 # 1\n    for _ in range(0, n): # one atomic\n        b *= a\n        # two atomics\n    return b\n\\end{python}\n\\item Analyze its worst-case running time and express it using Big-Oh notation: Well we can tell that this function will at max run $n$ times. Coutning each instruction in this algorithm will allow us to determine that $T(n) = 3n + 3$. We can assume this is a linear operation, as seen in the for/while loop condition. Thus classifying it as $O(n)$.\n\\end{itemize}\n\n\\end{enumerate}\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "16d67d6fc02050af9ae7536ef34bf9e2dedd1ee7", "size": 5107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/Homework_1.tex", "max_stars_repo_name": "JaredsAlgorithms/Assignments", "max_stars_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_stars_repo_licenses": ["MIT"], "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/Homework_1.tex", "max_issues_repo_name": "JaredsAlgorithms/Assignments", "max_issues_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_issues_repo_licenses": ["MIT"], "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/Homework_1.tex", "max_forks_repo_name": "JaredsAlgorithms/Assignments", "max_forks_repo_head_hexsha": "1efa28b481033384ff566cdda0e93ee269230b26", "max_forks_repo_licenses": ["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.6054054054, "max_line_length": 349, "alphanum_fraction": 0.6880751909, "num_tokens": 1587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660687, "lm_q2_score": 0.855851148805615, "lm_q1q2_score": 0.6282970305010861}}
{"text": "\\section{Unknown Values}\n\\label{unknowns}\n\n\\begin{quote}\nWhen you come to a fork in the road, take it \\footnote{attributed to Yogi Berra}\n\\end{quote}\nAssume that we have \\(X\\) instances of which the fraction which have class\n``Heads'' is \\(p_H\\) and Tails is \\(p_T\\).\nAssume that we are considering splitting using\na feature \\(f\\) such that \\(X' \\subseteq X\\) of the instances have unknown\nvalues for this feature. \nthe form \\(x \\leq y\\). \n\nIn terms of the training process, unknown values affect the process \nas follows.  With each instance \\(x_i \\in X\\) is associated a weight \\(w_i\\),\ninitialized to 1. Let \\(X'\\) be the instances where the value of the splitting feature is unknown.\n\n\\be\n\\item Benefit benefit calculation of Section~\\ref{XXX}. \nFor all \\(x_i \\in X'\\), we treat it as if it were two instances, one with a class of Heads and a weight of \\(w_i \\times p_H\\) and the other with a class of Tails and a weight of \\(w_i \\times p_T\\)\n\\item Partitioning the subsets of the data passed to the left child and right child.  All elements of \\(X'\\) are passed to the left child with a weight of \\(w_i \\times p_H\\) and to the right child with a weight of \\(w_i \\times p_T\\).  See Figure~\\ref{fig_unknown_values}.\n\\ee\n\nIn terms of the testing process, the change in evaluation is as follows.\nHitherto, a test instance given to a decision tree ends up at precisely one leaf\nnode. The proportion of heads and tails at that leaf is used to make a\nprediction, the simplest being that \\(p_H = \\frac{n_H}{n_H+n_T}\\). Now, if\ndecision requires knowing the value of a feature that is unknown, we send the\ninstance down to both left and right childs and combine the resulting decision,\nweighted by the proportions of heads and tails at that node. In\nFigure~\\ref{fig_unknown_accuracy}, we show how the accuracy of classification\nfalls off as the proportion of unknown values in the data set increases. We\nchange the proportion of unknown values by randomly selecting instances and\nrandomly selecting features to artificially turn to null values. The results are\nreported for the data sets of Table~\\ref{tbl_data_sets}.\n\n\n\\begin{figure}\n\\centering\n\\fbox{\n\\begin{minipage}{35cm}\nTODO \n\\end{minipage}\n}\n\\label{fig_unknown_values}\n\\caption{Change in weight of datum when split involves unknown values}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "154babff46bfb4a668427cb2908f41e3ab640e29", "size": 2308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ML/DT/doc/unknown.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/unknown.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/unknown.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": 45.2549019608, "max_line_length": 271, "alphanum_fraction": 0.756932409, "num_tokens": 593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7341195210831258, "lm_q1q2_score": 0.6282970233334656}}
{"text": "\\documentclass[]{article}\n\\usepackage{caption,subcaption,graphicx,float,url,amsmath,amssymb,tocloft,wasysym,amsthm,thmtools,textcomp,listings,amsfonts,cancel}\n\\usepackage[hidelinks]{hyperref}\n\\usepackage[toc,acronym,nonumberlist]{glossaries}\n\\usepackage[]{algorithm2e}\n\\setacronymstyle{long-short}\n\\usepackage{glossaries-extra}\n\\graphicspath{{figs/}} \n\\setlength{\\cftsubsecindent}{0em}\n\\setlength{\\cftsecnumwidth}{3em}\n\\setlength{\\cftsubsecnumwidth}{3em}\n\\newcommand\\numberthis{\\addtocounter{equation}{1}\\tag{\\theequation}}\n\\newtheorem{thm}{Theorem}\n\\newtheorem{cor}[thm]{Corollary}\n\\setcounter{tocdepth}{1}\n\\usepackage[toc,page]{appendix}\n%opening\n\\title{\n\tComputation in Complex Systems\\\\\n\tWeek 2\\\\\n\t Algorithms \\& Landscapes\n}\n\n%\\makeglossaries\n\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n%\\listofalgorithms\n\\section{Maximum independent set}\n\n\\subsection{What is the maximum value of the independent set?}\n\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\caption{What is the maximum value of the independent set?}\n\t\t\\includegraphics[width=0.6\\textwidth]{mwisQ}\n\t\\end{center}\n\\end{figure}\n\nObservations:\n\\begin{enumerate}\n\t\\item A tree with $N$ nodes has $2^N-1$ non empty subsets, so a brute-force search is exponential. Let's not go there!\n\t\\item Either the maximal independent set includes the root of the tree, or it doesn't.\n\t\\item If the the maximal independent set doesn't include the root of the tree, each subtree must be maximal.\n\t\\item If the maximal independent set includes the root of the tree, each subtree must have a set that excludes the node.\n\\end{enumerate}\n\nSo we can solve this problem as follows:\n\\begin{enumerate}\n\t\\item Either the root node, $3$ is in $M$ or it isn't.\n\t\\item If $3$ is in the tree, we have to exclude {4,1,5}, which gives a score of $3+(1+2)+2+(1+1)=9$\n\t\\item If $3$ isn't in the tree, the maximum is the sum of the maxima for the 4 subtrees:\n\t\\begin{enumerate}\n\t\t\\item (4,(1,2)): since $1+2<4$, the maximum value is 4.\n\t\t\\item (1,(2)): since $1<2$, the maximum value is 2. \n\t\t\\item ((5),(1,1)): since $1+1<5$, the maximum value is 5.\n\t\\end{enumerate}\n\t\\item Putting this together, if $3$ isn't in the tree, the maximum is $4+2+5=10$\n\\end{enumerate}\n\n\\subsection{Algorithm for maximum independent set}\n\nAlgorithm \\ref{alg:find:maximum:independent:set} is a description is pseudo-code, and Appendix \\ref{sect:ref:implementation} provides a reference implementation in Python.\n\n\\begin{algorithm}[H]\n\t\\KwData{A binary tree $T$ with a value $V(n)$ assigned to each node $n$}\n\t\\KwResult{A set $S\\subseteq N(T) | I(S) \\land \\sum_{s\\in S} V(s) \\ge \\sum_{s\\in S^\\prime} V(s) \\forall S^\\prime \\subset N(T) \\text{ with } I(S^\\prime)$  }\n\tinitialization\\;\n\tStarting at the root of the tree, traverse it top down to build two data structures: a stack \\emph{unprocessed}, which has the \\emph{root} at the bottom, and the $leaves$ at the top; and a dictionary \\emph{score}, which is initially empty, but will map each node to the value of the maximum independent set starting at that node.\\;\n\t\\While {$length(unprocessed)>0$}{\n\t\t$node \\leftarrow pop(unprocessed)$\\;\n\t\t\\eIf {leaf(node)}{\n\t\t\t$score(node)\\leftarrow value(node)$ \\;}{\n\t\t\t$val_{out} \\leftarrow \\sum_{\\forall child(node)} score(child)$\\;\n\t\t\t$val_{in} \\leftarrow value(node) + \\sum_{\\forall grandchild(node)}  value(grandchild)$\\;\n\t\t\t$score(node)\\leftarrow max(val_{out},val_{in})$\\;\n\t\t}\n\t}\n\t\\caption{Find the maximum independent set from a tree}\\label{alg:find:maximum:independent:set}\n\\end{algorithm}\n\n\\section{Reductions \\& Translations}\n\nTable \\ref{table:transform} illustrates the transformation of ASTRO to START. It exploits the common subsequence S-T-R to produce a minimum set of transformations.\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\caption{Transforming ASTRO to START}\\label{table:transform}\n\t\t\\begin{tabular}{|c|c|c|c|c|c|c|l|l|} \\hline\n\t\t\t\\textbf{\\cancel{A}}&S&T&&R&O&&delete&$\\rightarrow$\\\\\\hline\n\t\t\t&\\textbf{S}&T&&R&O&&match&$\\searrow$\\\\\\hline\n\t\t\t&S&\\textbf{T}&&R&O&&match&$\\searrow$\\\\\\hline\n\t\t\t&S&T&\\textbf{A}&R&O&&insert&$\\downarrow$\\\\\\hline\n\t\t\t&S&T&A&\\textbf{R}&O&&match&$\\searrow$\\\\\\hline\n\t\t\t&S&T&A&R&\\textbf{\\cancel{O}}&&delete&$\\rightarrow$\\\\\\hline\n\t\t\t&S&T&A&R&&\\textbf{T}&insert&$\\downarrow$\\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\subsection{Assign Weights}\n\nFigure \\ref{fig:Shortest:path} shows the path that gives rise to the transformations in Table \\ref{table:transform}. In order to make this the shortest path we need the following rules:\n\\begin{itemize}\n\t\\item If two symbols are equal, accept them and mover diagonally;\n\t\\item If two symbols don't match, insert or delete; disfavour mismatches (point mutations). \n\\end{itemize}\n\nThe simplest way to achieve this is with the weights shown in Figure \\ref{fig:weights}.\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\caption{Weights}\\label{fig:weights}\n\t\t\\includegraphics[width=\\textwidth]{q2-weights}\n\t\\end{center}\n\\end{figure}\n\n\\subsection{Shortest path}\n\nCopying the weights from Figure \\ref{fig:weights} we get Figure \\ref{fig:Shortest:path}. The shorted path has length $1+0+0+1+0+1+1=4$. \n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\caption{Shortest path}\\label{fig:Shortest:path}\n\t\t\\includegraphics[width=0.6\\textwidth]{q2-path}\n\t\\end{center}\n\\end{figure}\n\n% glossary\n%\\printglossaries\n\n% bibliography go here\n\n%\\bibliographystyle{unsrt}\n%\\addcontentsline{toc}{section}{Bibliography}\n%\\bibliography{origins,wikipedia}\n\n\\begin{appendices}\n\t\\section{Reference Implementation for Algorithm \\ref{alg:find:maximum:independent:set}}\\label{sect:ref:implementation}\n\tOne way to implement Algorithm \\ref{alg:find:maximum:independent:set} is with the following code.\n\t\\lstinputlisting[language=Python]{mis.py}\n\\end{appendices}\n\n\n\\end{document}\n", "meta": {"hexsha": "bee5ca810a2303c73460ed9330ec0ed4b533467b", "size": 5697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "computations/exam2.tex", "max_stars_repo_name": "weka511/fractals", "max_stars_repo_head_hexsha": "fa4e39677ea3ed7713e40a55b9453b2826f11a6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-22T01:39:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T04:36:22.000Z", "max_issues_repo_path": "computations/exam2.tex", "max_issues_repo_name": "weka511/fractals", "max_issues_repo_head_hexsha": "fa4e39677ea3ed7713e40a55b9453b2826f11a6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-06-20T03:20:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-20T03:07:55.000Z", "max_forks_repo_path": "computations/exam2.tex", "max_forks_repo_name": "weka511/complexity", "max_forks_repo_head_hexsha": "435ffab978e4499aea7c2c83788533867cc9b062", "max_forks_repo_licenses": ["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.7551020408, "max_line_length": 332, "alphanum_fraction": 0.7312620678, "num_tokens": 1815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6282941142438974}}
{"text": "\\providecommand{\\main}{../..}\n\\documentclass[\\main/thesis.tex]{subfiles}\n\\begin{document}\n\n\\section{Systems with an Upper Bound}\\label{bounded}\n\nWe say that a system is \\textit{bounded} if there \\textit{exists} a maximum in\nsuch system. In Agda, an existential proposition like this is expressed with\na \\textit{dependent sum type}, which is essentially a \\textit{pair} where the\ntype of the second term is dependent on the first.\n\n\\begin{lstlisting}\ndata Σ (A : Set) (B : A → Set) : Set where\n    _,_ : (x : A) → B x → Σ A B\n\nproj₁ : ∀ {A B} → Σ A B → A\nproj₂ : ∀ {A B} → (pair : Σ A B) → B (proj₁ pair)\n\\end{lstlisting}\n\nFor example, to prove that there exists a right identity for addition on natural numbers;\nwe place the ``evidence'' on the left and its justification on the right.\n\n\\begin{lstlisting}\nprop : ∀ n → Σ ℕ (λ e → n + e ≡ n)\nprop n = 0 , +-right-identity n\n\\end{lstlisting}\n\nWith a little syntax sugar, we can rewrite the proposition as\n{\\lstinline|Σ[ x ∈ A ] B|} instead of {\\lstinline|Σ A (λ x → B)|}.\n\n\\begin{lstlisting}\nBounded : ∀ b d o → Set\nBounded b d o = Σ[ xs ∈ Numeral b d o ] Maximum xs\n\\end{lstlisting}\n\nThe proposition above can be read as follows:\n\\textit{There exists a numeral {\\lstinline|xs|} of type\n{\\lstinline|Numeral b d o|} such that {\\lstinline|Maximum xs|} holds.}\nTo prove that a system is bounded, we have to place the numeral that we consider\nto be a maximum on the left of the pair, and a proof to justify it on the right.\n\n\\subsection{Properties of each Category}\n\n\\paragraph{NullBase}\n\nWe have proven that any numeral with the greatest digit as its LSD is a maximum.\n\n\\begin{lstlisting}\nBounded-NullBase : ∀ d o → Bounded 0 (suc d) o\nBounded-NullBase d o =\n    (greatest-digit d ∙) ,\n    (Maximum-NullBase-Greatest\n        (greatest-digit d ∙)\n        (greatest-digit-is-the-Greatest d))\n\\end{lstlisting}\n\n\\paragraph{NoDigits}\n\nSince {\\lstinline|¬ (Bounded b 0 o)|} reduces to {\\lstinline|Bounded b 0 o → ⊥|},\nwe are given an addition argument, which is a proof claiming that the system is\nbounded.\nPattern match on this argument yields a pair with a numeral of\n{\\lstinline|Numeral b 0 o|} on the left.\nAt this point, we do not actually care whether the numeral is a maximum\nbecause it should not have existed in the first place.\nHand the numeral to {\\lstinline|NoDigits-explode|} and we are done.\n\n\\begin{lstlisting}\nBounded-NoDigits : ∀ b o → ¬ (Bounded b 0 o)\nBounded-NoDigits b o (xs , claim) = NoDigits-explode xs\n\\end{lstlisting}\n\n\\paragraph{AllZeros}\n\nSimilar to that of {\\lstinline|Bounded-NullBase|}:\n\n\\begin{lstlisting}\nBounded-AllZeros : ∀ b → Bounded (suc b) 1 0\nBounded-AllZeros b = (z ∙) , Maximum-AllZeros (z ∙)\n\\end{lstlisting}\n\n\\paragraph{Proper}\n\nThis proposition is proven by contradicting the fact that\na proper numeral system has no maximum.\n\n\\begin{lstlisting}\nBounded-Proper : ∀ b d o → (proper : 2 ≤ suc (d + o))\n    → ¬ (Bounded (suc b) (suc d) o)\nBounded-Proper b d o proper (xs , claim) =\n    contradiction claim (Maximum-Proper xs proper)\n\\end{lstlisting}\n\n\\subsection{The Decidable Predicate}\n\nWe can determine whether a system is bounded by delegating the job to the\nhelper functions we have defined above.\n\n\\begin{lstlisting}\nBounded? : ∀ b d o → Dec (Bounded b d o)\nBounded? b d o with numView b d o\nBounded? _ _ _ | NullBase d o\n    = yes (Bounded-NullBase d o)\nBounded? _ _ _ | NoDigits b o\n    = no (Bounded-NoDigits b o)\nBounded? _ _ _ | AllZeros b\n    = yes (Bounded-AllZeros b)\nBounded? _ _ _ | Proper b d o proper\n    = no (Bounded-Proper b d o proper)\n\\end{lstlisting}\n\n\\paragraph{Summary}\n\n\\begin{center}\n    \\begin{adjustbox}{max width=\\textwidth}\n    \\begin{tabular}{ | l | c | c | c | c | }\n    \\textbf{Properties} & \\textbf{NullBase} & \\textbf{NoDigits} & \\textbf{AllZeros} & \\textbf{Proper} \\\\\n    \\hline\n    has an maximum     & yes & no & yes & no \\\\\n    has an upper bound & yes & no & yes & no \\\\\n    \\end{tabular}\n    \\end{adjustbox}\n\\end{center}\n\n\\end{document}\n", "meta": {"hexsha": "d1a0c5f1efbad004d7f92adfcf7a65f223ed088a", "size": 3961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/tex/constructions/bounded.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/bounded.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/bounded.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": 31.4365079365, "max_line_length": 104, "alphanum_fraction": 0.6935117395, "num_tokens": 1237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6282790600710013}}
{"text": "\n% This LaTeX was auto-generated from MATLAB code.\n% To make changes, update the MATLAB code 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 \\input{preamble} \\begin{document} \\maketitle \\tableofcontents \n\n    \n    \n{}\n\n\n \n\n\n\\section{Problem 20.2-1}\n\n\\begin{par}\n\nSolute A is diffusing at unsteady state into a semi-infinite medium of\npure B and undergoes a first-order reaction with B. Solute A is\ndilute. Calculate the concentration $c_A$ at points z = 0, 4, and\n$10~\\textup{mm}$ from the surface for $t=1\\times 10^5~\\textup{s}$.\nPhysical property data are $D_{AB}=1\\times\n10^{-9}~\\textup{m}^2/\\textup{s}$, $k'=1\\times 10^{-4}~\\textup{s}^{-1}$,\n$c_{A0} = 1.0~\\textup{kg mol/m}^3$. Also calculate the\n$\\textup{kg mol absorbed/m}^2$.\nThe concentration of A at point z is given by \\vref{conc_empirical_1}\n(corrected version),\n\\begin{equation} \\label{conc_empirical_1}\n\\begin{split}\n\\frac{C_A}{C_{A0}}=&\\frac{1}{2}\\exp\\left(-z\\sqrt{k'/D_{AB}}\\right)\n * \\textup{erfc}\\left(\\frac{z}{2\\sqrt{tD_{AB}}}-\\sqrt{k't}\\right) \\\\\n &+ \\frac{1}{2}\\exp\\left(z\\sqrt{k'/D_{AB}}\\right)\n * \\textup{erfc}\\left(\\frac{z}{2\\sqrt{tD_{AB}}}+\\sqrt{k't}\\right)\n\\end{split}\n\\end{equation}\n\\Vref{conc_empirical_1} was incorrect in the textbook, and has\nbeen modified according to the instructor's email.\n\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nu = symunit;\nt = 1e5 * u.s;\nD_AB = 1e-9 * u.m^2 / u.s;\nk_prime = 1e-4 * u.s^-1;\nC_A0 = 1.0 * (u.kg * u.mol) / (u.m^3);\nC_A = @(z) C_A0 * ...\n    (0.5*exp(-z*sqrt(k_prime/D_AB))*erfc((z/(2*sqrt(t*D_AB))) - sqrt(k_prime*t)) + ...\n    0.5*(exp(z*sqrt(k_prime/D_AB)))*erfc((z/(2*sqrt(t*D_AB))) + sqrt(k_prime*t)));\ndisp(unitString(C_A(0), 'C_A (0 mm)'))\ndisp(unitString(C_A(0.004 * u.m), 'C_A (4 mm)'))\ndisp(unitString(C_A(0.010 * u.m), 'C_A (10 mm)'))\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}C_A (0 mm): 1 (kg*mol)/m^3\nC_A (4 mm): 0.28226 (kg*mol)/m^3\nC_A (10 mm): 0.042328 (kg*mol)/m^3\n\\end{verbatim} \\color{black}\n    \\begin{par}\n\nThe amount of A absorbed per square meter is given by\n\\vref{conc_empirical_2} (corrected version),\n\\begin{equation} \\label{conc_empirical_2}\nQ=C_{A0}\\sqrt{D_{AB}/k'}\\left[\\left(k't+\\frac{1}{2}\\right)\\textup{erf}\\sqrt{k't}+\\sqrt{k't/\\pi} e^{-k't}\\right]\n\\end{equation}\n\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nQ = C_A0*sqrt(D_AB/k_prime)*((k_prime*t+0.5)*erf(sqrt(k_prime*t) + ...\n    sqrt((k_prime*t)/pi)*exp(-k_prime*t)));\ndisp(unitString(Q))\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}Q: 0.033204 (kg*mol)/m^2\n\\end{verbatim} \\color{black}\n    \n\n\\section{Problem 21.1-2}\n\n\\begin{par}\nProve or show the following relationships, starting with the flux equations:\n\\end{par} \\vspace{1em}\n\\begin{par}\n\n\\subsection{Part a}\nConvert $k_c'$ to $k_y$ and $k_G$.\n\n\\end{par} \\vspace{1em}\n\\begin{par}\nThe flux equations involving these coefficients are, $$ N_A = k_c(C_{A1}-C_{A2}) = k_G(p_{A1}-p_{A2}) = k_y(y_{A1}-y_{A2}) $$ the conversion between $k_c'$ and $k_c$ is given in the flux equation for A diffusing through stagnant, non-diffusing B,\n\\end{par} \\vspace{1em}\n\\begin{par}\n\n\\[N_A = \\frac{k_c'}{x_{BM}}\\left(C_{A1}-C_{A2}\\right) =\nk_c\\left(C_{A1}-C_{A2}\\right)\\]\n\\[ k_c = \\frac{k_c'}{x_{BM}} = \\frac{k_c' P}{p_{BM}} \\]\n\\[ k_y = \\frac{k_c' P}{p_{BM}}\\cdot\\frac{C_{A1}-C_{A2}}{y_{A1}-y_{A2}} = \\frac{k_c' P}{RT\\cdot y_{BM}} \\]\n\\[ k_G = \\frac{k_c' P}{p_{BM}}\\cdot\\frac{C_{A1}-C_{A2}}{p_{A1}-p_{A2}} = \\frac{k_c' P}{RT\\cdot p_{BM}} \\]\n\n\\end{par} \\vspace{1em}\n\\begin{par}\n\n\\subsection{Part b}\nConvert $k_L$ to $k_x$ and $k_x'$.\n\n\\end{par} \\vspace{1em}\n\\begin{par}\nThe flux equations involving these coefficients are, $$ N_A = k_L(c_{A1}-c_{A2}) = k_x(x_{A1}-x_{A2}) $$ A relationship for $k_x$ can be found by substituting $x=c_{A}/c$, $$ k_x = k_L\\frac{c_{A1}-c_{A2}}{x_{A1}-x_{A2}} = k_L\\frac{c_{A1}-c_{A2}}{\\frac{c_{A1}}{c}-\\frac{c_{A2}}{c}} = k_L\\cdot c $$ $$ k_x' = k_x\\cdot x_{BM} = k_L \\cdot c \\cdot x_{BM} $$\n\\end{par} \\vspace{1em}\n\\begin{par}\n\n\\subsection{Part c}\nConvert $k_G$ to $k_y$ and $k_c$.\n\n\\end{par} \\vspace{1em}\n\\begin{par}\nThe flux equations involving these coefficients are, $$ N_A = k_G(p_{A1}-p_{A2}) = k_y(y_{A1}-y_{A2}) = k_c(C_{A1}-C_{A2}) $$ By substituting $p_A=y_A P$, $$ k_y = k_G\\frac{p_{A1}-p_{A2}}{y_{A1}-y_{A2}} = k_G\\frac{y_{A1}P-y_{A2}P}{y_{A1}-y_{A2}} = k_G\\cdot P $$ Finally, substituting $C=P/RT$, $$ k_c = k_G\\frac{p_{A1}-p_{A2}}{C_{A1}-C_{A2}} = k_G\\frac{p_{A1}-p_{A2}}{(p_{A1}-p_{A2})/RT} = k_G \\cdot RT $$\n\\end{par} \\vspace{1em}\n\n\n\\section{Problem 21.1-3}\n\n\\begin{par}\nIn a wetted-wall tower an air- $\\textup{H}_2\\textup{S}$ mixture is flowing by a film of water that is flowing as a thin film down a vertical plate. The $\\textup{H}_2\\textup{S}$ is being absorbed from the air to the water at a total pressure of $1.50~\\textup{atm abs}$ and $30~\\textup{C}$. A value for $k_c'$ of $9.567\\times 10^{-4}~\\textup{m/s}$ has been predicted for the gas-phase mass-transfer coefficient. At a given point, the mole fraction of $\\textup{H}_2\\textup{S}$ in the liquid at the liquid-gas interface is $2.0(10^{-5})$ and $p_A$ of $\\textup{H}_2\\textup{S}$ in the gas is $0.05~\\textup{atm}$. The Henry's law equilibrium relation is $p_A(\\textup{atm}) = 609x_A$ (mole fraction in liquid). Calculate the rate of absorption of $\\textup{H}_2\\textup{S}$. (\\textit{Hint}: Call point 1 the interface and point 2 the gas phase. Then, calculate $p_{A1}$ from Henry's law and the given $x_A$. The value of $p_{A2}$ is $0.05~\\textup{atm}$.)\n\\end{par} \\vspace{1em}\n\\begin{par}\nThe mass transfer coefficient given is $k_c'$, which can be converted to $k_G$ for a flux equation based on partial pressures. $$ k_G = \\frac{k_c' P}{RT\\cdot p_{BM}} $$ $$ N_A = k_G(p_{A1} - p_{A2}) $$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nu = symunit;\nP = 1.5 * u.atm;\nT = rewrite(30 * u.Celsius, u.K, 'Temperature', 'absolute');\nk_c_prime = 9.567e-4 * u.m / u.s;\nx_A1 = 2.0e-5;\np_A1 = 609 * x_A1 * u.atm;\np_A2 = 0.05 * u.atm;\np1 = separateUnits(p_A1); p2 = separateUnits(p_A2); p = separateUnits(P);\np_BM = ((p-p1)-(p-p2))/log((p-p1)/(p-p2)) * u.atm;\nR = 8.2057338e-5 * (u.m^3 * u.atm) / (u.mol * u.K);\nk_G = (k_c_prime * P) / (R * T * p_BM);\nN_A = k_G * (p_A1 - p_A2) * 1e-3 * u.kg;  % convert to kg-mol\ndisp(unitString(N_A))\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}N_A: -1.4854e-06 (kg*mol)/(m^2*s)\n\\end{verbatim} \\color{black}\n    \n\n\\section{Problem 21.2-1}\n\n\\begin{par}\nA fluid is flowing in a vertical pipe and mass tranfer is occurring from the pipe wall to the fluid. Relate the convective mass-transfer coefficient $k_c'$ to the variables $D$, $\\rho$, $\\mu$, $v$, $D_{AB}$, $g$, and $\\Delta{\\rho}$, where $D$ is pipe diameter, $L$ is pipe length, and $\\Delta{\\rho}$ is the density difference.\n\\end{par} \\vspace{1em}\n\\begin{par}\nAccording to Buckingham's pi theorem, given nine independent variables in three physical dimensions, there are six $\\pi-$ groups to construct.\n\\end{par} \\vspace{1em}\n\\begin{par}\nVector order: [Length Mass time]\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nD = [1 0 0];\nL = [1 0 0];\nrho = [-3 1 0];\nmu = [-1 1 -1];\nv = [1 0 -1];\nD_AB = [2 0 -1];\ng = [1 0 -2];\ndelta_rho = [-3 1 0];\nk_c_prime = [1 0 -1];\n\npi_1 = ([D' rho' mu']\\-k_c_prime')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_1 =\n\n     1     1    -1\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_1 = \\frac{D \\rho k_c'}{\\mu}$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\npi_2 = ([D' rho' mu']\\-v')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_2 =\n\n     1     1    -1\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_2 = \\frac{D \\rho v}{\\mu}$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\npi_3 = ([D' rho' mu']\\-D_AB')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_3 =\n\n     0     1    -1\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_3 = \\frac{\\rho D_{AB}}{\\mu}$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\npi_4 = ([D' rho' mu']\\-g')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_4 =\n\n     3     2    -2\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_4 = \\frac{D^3 \\rho^2 g}{\\mu^2}$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\npi_5 = ([D' rho' mu']\\-delta_rho')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_5 =\n\n     0    -1     0\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_5 = \\frac{\\Delta\\rho}{\\rho}$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\npi_6 = ([D' rho' mu']\\-L')'\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\npi_6 =\n\n    -1     0     0\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\n$\\pi_6 = \\frac{L}{D}$\n\\end{par} \\vspace{1em}\n\\begin{par}\nThese dimensionless groups can be combined to describe the system. This combination was done pencil-and-paper with a lot of frustration, and the results are shown here.\n\\end{par} \\vspace{1em}\n\\begin{par}\n\n\\[ \\frac{\\pi_1}{\\pi_3} = f\\left(\\pi_4 \\pi_5 \\pi_6^3, \\pi_2,\n\\pi_3^{-1}\\right) \\]\n\\[ \\frac{k_c'D}{D_{AB}}=f\\left(\\frac{gL^3\\rho\\Delta\\rho}{\\mu^2},\n\\frac{Dv\\rho}{\\mu},\\frac{\\mu}{\\rho D_{AB}}\\right) \\]\n\n\\end{par} \\vspace{1em}\n\n\n\\section{Problem 21.3-1}\n\n\\begin{par}\nUsing the data and physical properties of Example 21.3-2, calculate the flux for a water velocity of $0.152~\\textup{m/s}$ and a plate length of $L = 0.137~\\textup{m}$. Do not assume that $x_{BM}=1.0$ but actually calculate its value.\n\\end{par} \\vspace{1em}\n\\begin{par}\nThe Schmidt and Reynolds numbers can be calculated from the given quantities,\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nu = symunit;\nT = rewrite(26.1 * u.Celsius, u.K, 'Temperature', 'absolute');\nL = 0.137 * u.m;\nv = 0.152 * u.m / u.s;\nsolubility = 0.02948 * (u.kg * u.mol) / (u.m^3);\nD_AB = 1.245e-9 * u.m^2 / u.s;\nmu = 8.71e-4 * u.Pa * u.s;\nrho = 996 * u.kg / u.m^3;\nN_Sc = simplify(mu / (rho * D_AB));\nN_Re = simplify((L * v * rho)/mu);\ndisp(unitString(N_Sc))\ndisp(unitString(N_Re))\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}N_Sc: 702.408 1\nN_Re: 23812.5189 1\n\\end{verbatim} \\color{black}\n    \\begin{par}\nThis value for the Reynolds number corresponds to this equation for mass flux, $$ J_D = 0.99N_{Re,L}^{-0.5} = \\frac{k_c'}{v}\\left(N_{Sc}\\right)^{2/3} $$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nsyms k_c_prime;\nk_c_prime = solve(0.99*N_Re^-0.5 == (k_c_prime/v)*(N_Sc^(2/3)));\nFW_water = 18.02* u.kg / (u.kg * u.mol);\nc = rho / FW_water;\nx_A1 = 0;\nx_A2 = solubility / (solubility + c);\nx_BM = (1 - (1 - x_A2))/log(1/(1 - x_A2));\nk_c = k_c_prime / x_BM;\nN_A = k_c * solubility;\ndisp(unitString(N_A))\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}N_A: 3.6391e-07 (kg*mol)/(m^2*s)\n\\end{verbatim} \\color{black}\n    \n\n\n \\section{Referenced Functions} \\subsection{unitString.m} \\begin{verbatim} function displayString = unitString(quantity, name)\n%UNITSTRING Display a 1x2 sym with symbolic units\n% USAGE: unitString(some_quantity, name)\n% OUTPUT:\n%   - displayString: char vector containing name, scalar, and units\nif nargin < 2\n    n = inputname(1);\nelse\n    n = name;\nend\n\n[s, U] = separateUnits(quantity);\nformatSpec = '%s: %s %s';\ndisplayString = sprintf(formatSpec, n, num2str(double(s)), symunit2str(U));\nend \\end{verbatim} \\end{document}", "meta": {"hexsha": "453095d7c981e3f15e43a95c57b6ba3712cf19ff", "size": 11152, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/homework_12/html/report.tex", "max_stars_repo_name": "ahoetker/autoreport", "max_stars_repo_head_hexsha": "26fb9e563e2c30ac9422d98e2567223dba77ab4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T20:29:04.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T20:29:04.000Z", "max_issues_repo_path": "examples/homework_12/html/report.tex", "max_issues_repo_name": "ahoetker/autoreport", "max_issues_repo_head_hexsha": "26fb9e563e2c30ac9422d98e2567223dba77ab4a", "max_issues_repo_licenses": ["MIT"], "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/homework_12/html/report.tex", "max_forks_repo_name": "ahoetker/autoreport", "max_forks_repo_head_hexsha": "26fb9e563e2c30ac9422d98e2567223dba77ab4a", "max_forks_repo_licenses": ["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.7939393939, "max_line_length": 944, "alphanum_fraction": 0.6425753228, "num_tokens": 4405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6282790600710013}}
{"text": "\\chapter{Fit of histograms}\n\\label{ch:fit}\n\nThis chapter illustrates how the fits were done in \\autoref{ch:anal}. They will\nturn out to be almost exactly a standard least squares fit of a histogram, but\nwe will give a Bayesian interpretation to all the procedures. If you do not\nfavor Bayesian methods, just do not think about it. To actually do the fits, we\nused the Python package \\texttt{lsqfit} \\cite{lepage2021}, which we warmly\nrecommend.\n\n\\section{Bayesian least squares}\n\nBayesian inference is based on applying Bayes' theorem to get the probability\ndistribution of the parameters conditional on the observed data. Call $\\theta$\nthe parameters and $y$ the data, then it reads\n%\n\\begin{equation}\n    p(\\theta|y) = \\frac {p(y|\\theta) p(\\theta)} {p(y)}.\n\\end{equation}\n\nThe term $p(y|\\theta)$ is the likelihood, how the data depends on the\nparameters. $p(y)$ is the unconditional probability of the data; whatever that\nmeans, we can compute it with $\\int\\mathrm d\\theta\\,p(y|\\theta)p(\\theta)$.\n$p(\\theta)$ is the unconditional probability distribution of the parameters. It\nis called \\emph{prior} because it encodes what one knows about the parameters\nbefore having the data. By the same logic, $p(\\theta|y)$ is called\n\\emph{posterior}.\n\nLeast squares is a general procedure to produce an estimator, but a standard\ninterpretation is also as a maximum likelihood fit when the likelihood is\nGaussian. We can do the same in the Bayesian case if the prior is Gaussian too.\nWe switch to logarithms and drop addends which do not depend on the parameters:\n%\n\\begin{align}\n    \\log p(\\mathbf y|\\boldsymbol\\theta) &=\n    -\\sum_{i=1}^n \\log\\sigma_i\n    -\\frac 12 \\sum_{i=1}^n\n    \\left( \\frac {y_i - \\mu_i(\\boldsymbol\\theta)} {\\sigma_i} \\right)^2, \\\\\n    %\n    \\log p(\\boldsymbol\\theta) &=\n    -\\sum_{j=1}^k \\log\\sigma^\\theta_j\n    -\\frac 12 \\sum_{j=1}^k\n    \\left( \\frac {\\mu^\\theta_j - \\theta_j} {\\sigma^\\theta_j} \\right)^2.\n\\end{align}\n\nNow these two terms have to be summed to obtain the log posterior. If we extend\nthe $\\mathbf y$, $\\boldsymbol\\mu$ and~$\\boldsymbol\\sigma$ vectors, we can see\nthe two sums together as a single sum of squares:\n%\n\\begin{align}\n    y_{n+j} &\\equiv \\mu^\\theta_j, \\\\\n    %\n    \\mu_{n+j}(\\boldsymbol\\theta) &\\equiv \\theta_j, \\\\\n    %\n    \\sigma_{n+j} &\\equiv \\sigma^\\theta_j, \\qquad j = 1, \\ldots, k, \\\\\n    %\n    \\log p(\\boldsymbol\\theta|\\mathbf y) &=\n    -\\sum_{i=1}^{n+k} \\log\\sigma_i\n    - \\frac 12 \\sum_{i=1}^{n+k}\n    \\left( \\frac {y_i - \\mu_i(\\boldsymbol\\theta)} {\\sigma_i} \\right)^2 \\equiv \\\\\n    %\n    &\\equiv -\\sum_{i=1}^{n+k} \\log\\sigma_i - \\frac12 \\chi^2. \\label{eq:chi2}\n\\end{align}\n\nSo formally the prior is equivalent to additional datapoints, one for each\nparameter. We have not dropped the sum with the $\\log\\sigma$ although it does\nnot depend on $\\boldsymbol\\theta$; it will be needed later. Note that the\ndegrees of freedom of the $\\chi^2$ now are $(n+k)-k = n$, instead of the usual\n$n-k$ without prior.\n\nIn the analysis we said we put uniform priors over the parameters defined in\nthe interval $(0,1)$. This is implemented by fitting a transformed parameter\nwith a standard Gaussian prior with zero mean and unitary variance, and\napplying as inverse transformation the Gaussian cumulative density function\n(cdf). Say, if we want to put a uniform prior on $\\theta_j$, we fit the\ntransformed parameter $\\theta_j'$, with\n%\n\\begin{align}\n    \\mu^{\\theta'}_j &= 0, \\\\\n    %\n    \\sigma^{\\theta'}_j &= 1, \\\\\n    %\n    \\theta_j(\\theta'_j) &= \\Phi(\\theta'_j)\n    \\equiv \\int_{-\\infty}^{\\theta'_j} \\mathrm du\\,\n    \\frac {e^{-u^2/2}} {\\sqrt{2\\pi}}.\n\\end{align}\n\nBayesianly, this is equivalent to omitting the squared term for the prior and\nputting bounds on the parameter value, without transforming. However it is\nconvenient for the fitting routine. By the same logic, when we use the\nlogarithm to map a positive parameter to the real line, the prior on the\nuntransformed parameter is a log-Gaussian distribution.\n\nNow the least squares estimator would be obtained by minimizing the $\\chi^2$,\nwhile a Bayesian cares about the posterior as a distribution. If we approximate\nthe posterior as a Gaussian, we can do formally the same calculations. To\ncompute the Gaussian approximation we expand the logarithm of the distribution\nto second order around the maximum:\n%\n\\begin{align}\n    \\log p(\\boldsymbol\\theta|\\mathbf y) &\\approx\n    -\\frac 12 (\\boldsymbol\\theta-\\boldsymbol\\theta_0)^\\top\n    V^{-1} (\\boldsymbol\\theta-\\boldsymbol\\theta_0), \\\\\n    %\n    \\boldsymbol\\theta_0\n    &= \\operatorname*{arg\\,min}_{\\boldsymbol\\theta} \\chi^2, \\\\\n    %\n    V^{-1}_{jk} &= \\frac12 \\left.\n    \\frac {\\partial^2 \\chi^2} {\\partial\\theta_j \\partial\\theta_k}\n    \\right|_{\\boldsymbol\\theta_0}. \\label{eq:lsqpm}\n\\end{align}\n\nNow let us carry further the calculation of the precision matrix, to discuss\nan additional issue:\n%\n\\begin{align}\n    \\frac{\\partial\\chi^2}{\\partial\\theta_j} &=\n    2 \\sum_i \\frac {y_i - \\mu_i(\\boldsymbol\\theta)} {\\sigma_i^2}\n    \\frac {\\partial\\mu_i} {\\partial\\theta_j}, \\\\\n    %\n    \\frac {\\partial^2 \\chi^2} {\\partial\\theta_j \\partial\\theta_k} &=\n    2 \\sum_i \\frac1{\\sigma_i^2} \\left(\n    -\\frac {\\partial\\mu_i} {\\partial\\theta_j}\n    \\frac {\\partial\\mu_i} {\\partial\\theta_k}\n    + (y_i - \\mu_i(\\boldsymbol\\theta))\n    \\frac {\\partial^2 \\mu_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right). \\label{eq:lsqhess}\n\\end{align}\n\nIn standard least squares, the precision matrix of the estimator is estimated\nwith the above expression, but with the term with the second derivative\ndropped. The reason is for convenience, but also because the expectation of the\nresiduals $y_i - \\mu_i(\\boldsymbol\\theta_0(\\mathbf y))$ is approximately zero.\nA frequentist would like to compute this with the true value of the parameters,\nbut has to content herself with the least squares estimate, getting something\nwhich on average is the true precision matrix. So any term which is zero on\naverage can be removed.\n\nFor a Bayesian, instead, there is not some ideal error corresponding to an\nideal parameter value; there is only the covariance of the posterior obtained\nwith the particular values at hand. Different data, different posterior.\nHowever in our fits the residuals term is missing, as we said just because this\nis convenient for the implementation. In practice, the difference should be\nsmall.\n\n\\section{Least squares fit of a histogram}\n\nThe standard model of a histogram is Poisson distributions for the bin counts.\nLet $c_i$ be the count in bin~$i$, $f_i(\\boldsymbol\\theta)$ the model\nnormalized distribution of the bins, and $M$ a parameter for the mean of the\ntotal (Poisson) number of samples. Then the likelihood is\n%\n\\begin{equation}\n    P(\\mathbf c|M,\\boldsymbol\\theta) =\n    \\prod_i P(c_i|M,\\boldsymbol\\theta) =\n    \\prod_i \\operatorname{poisson}(c_i;Mf_i(\\boldsymbol\\theta)),\n\\end{equation}\n%\nwhere $\\operatorname{poisson}(\\cdot;\\mu)$ is a Poisson probability mass\nfunction (pmf) with mean~$\\mu$.\n\nWe do not care about $M$, only about $\\boldsymbol\\theta$, so we marginalize\nthe posterior over $M$:\n%\n\\begin{align}\n    p(\\boldsymbol\\theta|\\mathbf c)\n    &= \\int \\mathrm dM\\, p(M,\\boldsymbol\\theta|\\mathbf c) = \\\\\n    %\n    &= \\int \\mathrm dM\\,\n    \\frac {P(\\mathbf c|M,\\boldsymbol\\theta) p(M,\\boldsymbol\\theta)}\n    {P(\\mathbf c)}.\n\\end{align}\n\nNow we assume that a priori $M$ is independent from $\\boldsymbol\\theta$, i.e., \n$p(M,\\boldsymbol\\theta) = p(M)p(\\boldsymbol\\theta)$. Then, continuing the\ncalculation:\n%\n\\begin{align}\n    p(\\boldsymbol\\theta|\\mathbf c)\n    &= \\frac {p(\\boldsymbol\\theta)} {P(\\mathbf c)}\n    \\int \\mathrm dM\\, p(M)\n    \\prod_i \\operatorname{poisson}(c_i;Mf_i(\\boldsymbol\\theta)) = \\\\\n    %\n    &= \\frac {p(\\boldsymbol\\theta)} {P(\\mathbf c)}\n    \\int \\mathrm dM\\, p(M)\n    \\prod_i\n    e^{-Mf_i(\\boldsymbol\\theta)}\n    \\frac {(Mf_i(\\boldsymbol\\theta))^{c_i}} {c_i!} = \\\\\n    %\n    &= \\frac {p(\\boldsymbol\\theta)} {P(\\mathbf c)}\n    \\int \\mathrm dM\\, p(M)\n    e^{-M \\sum_i f_i(\\boldsymbol\\theta)}\n    M^{\\sum_i c_i}\n    \\prod_i\n    \\frac {f_i(\\boldsymbol\\theta)^{c_i}} {c_i!}\n\\end{align}\n%\nSince $f_i$ is normalized the sum over it yields~1, while we call $N$ the total\ncount, so\n%\n\\begin{align}\n    p(\\boldsymbol\\theta|\\mathbf c)\n    &= \\frac {p(\\boldsymbol\\theta)} {P(\\mathbf c)}\n    \\prod_i\n    \\frac {f_i(\\boldsymbol\\theta)^c_i} {c_i!}\n    \\int \\mathrm dM\\, p(M) e^{-M} M^N.\n\\end{align}\n%\nThe integral does not depend on $\\boldsymbol\\theta$, so we call it $I(N)$ and\ndo not care about its value. Now we take the logarithm:\n%\n\\begin{align}\n    \\log p(\\boldsymbol\\theta|\\mathbf c) &=\n    -\\log P(\\mathbf c) + \\log I(N) - \\sum_i \\log c_i!\n    + \\log p(\\boldsymbol\\theta) + \\sum_i c_i \\log f_i(\\boldsymbol\\theta).\n\\end{align}\n\nThis is the exact expression for the posterior, which we want to compare to\nleast squares, which yields\n%\n\\begin{align}\n    Q(\\boldsymbol\\theta) &=\n    \\log p(\\boldsymbol\\theta)\n    -\\frac 12\n    \\sum_i \\frac {(c_i - N f_i(\\boldsymbol\\theta))^2} {c_i}.\n\\end{align}\n\nNote the particular flavor of chisquare we have picked: there is no parameter\nfor the normalization, which is fixed to the actual total count $N$, and the\ndenominator is the observed count $c_i$.\n\nTo do the comparison, we expand both expressions to second order, ignoring the\nshared prior term which is already matched:\n%\n\\begin{align}\n    L(\\boldsymbol\\theta) &\\equiv \\log p(\\boldsymbol\\theta|\\mathbf c), \\\\\n    %\n    \\frac {\\partial L} {\\partial\\theta_j} &=\n    \\sum_i \\frac {c_i} {f_i(\\boldsymbol\\theta)}\n    \\frac {\\partial f_i} {\\partial \\theta_j}, \\\\\n    %\n    \\frac {\\partial^2 L} {\\partial\\theta_j \\partial\\theta_k} &=\n    \\sum_i c_i \\left[\n    -\\frac 1 {f_i(\\boldsymbol\\theta)^2}\n    \\frac {\\partial f_i} {\\partial \\theta_j}\n    \\frac {\\partial f_i} {\\partial \\theta_k}\n    + \\frac 1 {f_i(\\boldsymbol\\theta)}\n    \\frac {\\partial^2 f_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right].\n\\end{align}\n\nFor $Q$ we start from \\eqref{eq:lsqhess}, obtaining\n%\n\\begin{align}\n    \\frac {\\partial^2 Q} {\\partial\\theta_j \\partial\\theta_k} &=\n    -N^2 \\sum_i\n    \\frac 1 {c_i} \\left[\n    \\frac {\\partial f_i} {\\partial \\theta_j}\n    \\frac {\\partial f_i} {\\partial \\theta_k}\n    - \\left( \\frac{c_i} N - f_i(\\boldsymbol\\theta) \\right)\n    \\frac {\\partial^2 f_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right]. \\label{eq:Qjk}\n\\end{align}\n\nWe do not discuss the different results for the maximum because it is well\nknown that when there at least five counts per bin the least squares\napproximation is good enough. The covariance instead needs a discussion. Now we\nmanipulate $\\partial_{jk} L$ to show it is similar to $\\partial_{jk} Q$. First,\nwe approximate the observed counts with the model, $c_i \\approx N\nf_i(\\boldsymbol\\theta)$:\n%\n\\begin{align}\n    \\frac {\\partial^2 L} {\\partial\\theta_j \\partial\\theta_k} &=\n    -N^2 \\sum_i \\frac {c_i} {N^2 f_i(\\boldsymbol\\theta)^2} \\left[\n    \\frac {\\partial f_i} {\\partial \\theta_j}\n    \\frac {\\partial f_i} {\\partial \\theta_k}\n    - f_i(\\boldsymbol\\theta)\n    \\frac {\\partial^2 f_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right] \\approx \\\\\n    %\n    &\\approx\n    -N^2 \\sum_i \\frac 1 {c_i} \\left[\n    \\frac {\\partial f_i} {\\partial \\theta_j}\n    \\frac {\\partial f_i} {\\partial \\theta_k}\n    - f_i(\\boldsymbol\\theta)\n    \\frac {\\partial^2 f_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right].\n\\end{align}\n\nNext, we observe that since $f$ is normalized, $\\sum_i \\partial_{jk} f_i = 0$,\nso we can add the missing term to obtain the residuals:\n%\n\\begin{align}\n    \\frac {\\partial^2 L} {\\partial\\theta_j \\partial\\theta_k} &\\approx\n    -N^2 \\sum_i \\frac 1 {c_i} \\left[\n    \\frac {\\partial f_i} {\\partial \\theta_j}\n    \\frac {\\partial f_i} {\\partial \\theta_k}\n    + \\left( \\frac {c_i} N - f_i(\\boldsymbol\\theta) \\right)\n    \\frac {\\partial^2 f_i} {\\partial\\theta_j \\partial\\theta_k}\n    \\right]. \\label{eq:Ljk}\n\\end{align}\n\nComparing \\eqref{eq:Qjk} with \\eqref{eq:Ljk}, we see that the difference is the\nsign of the residuals term. As we explained above, in the least squares fit\nthat term is dropped altogether, so notwithstanding the Poisson model, we end\nup doing the same kind of approximation we did starting from Gaussians.\n\n\\section{The $\\chi^2/\\mathrm{dof}$ correction}\n\nStarting from the Gaussian model posterior \\eqref{eq:chi2}, we add a parameter\n$s$ that rescales uniformly all the errors:\n%\n\\begin{align}\n    \\log p(\\boldsymbol\\theta|\\mathbf y)\n    &= -\\sum_{i=1}^{n+k} \\log\\sigma_i - \\frac12 \\chi^2 \\mapsto \\\\\n    %\n    \\mapsto \\log p(\\boldsymbol\\theta,s|\\mathbf y)\n    &= \\log p(s) -\\sum_{i=1}^{n+k} \\log(s \\sigma_i)\n    - \\frac 12 \\sum_{i=1}^{n+k}\n    \\left( \\frac {y_i - \\mu_i(\\boldsymbol\\theta)} {s \\sigma_i} \\right)^2 = \\\\\n    %\n    &= \\log p(s) - (n+k) \\log s - \\sum_{i=1}^{n+k} \\log\\sigma_i\n    - \\frac 12 \\frac{\\chi^2}{s^2}.\n\\end{align}\n\nSince $s$ is a scale parameter, it makes sense to use a uniform prior over\n$\\log s$, i.e., $p(s) = 1/s$, because it is scale-invariant. Now that we have\nlet errors vary, we marginalize away $s$, freely dropping normalizations as\nusual:\n%\n\\begin{align}\n    p(\\boldsymbol\\theta|\\mathbf y)\n    &= \\int \\mathrm ds\\,\n    p(\\boldsymbol\\theta,s|\\mathbf y) = \\\\\n    %\n    &= \\int \\frac {\\mathrm ds} {s^{n+k+1}}\n    \\exp\\left(-\\frac12 \\frac {\\chi^2} {s^2}\\right) = \\\\\n    %\n    &= \\frac 1 {(\\chi^2)^{(n+k)/2}}.\n\\end{align}\n\nNow again we take the logarithm and expand to second order:\n%\n\\begin{align}\n    P(\\boldsymbol\\theta) &\\equiv\n    \\log p(\\boldsymbol\\theta|\\mathbf y)\n    = -\\frac{n+k}2 \\log \\chi^2, \\\\\n    %\n    \\frac {\\partial P} {\\partial \\theta_j}\n    &= -\\frac{n+k}2 \\frac 1{\\chi^2}\n    \\frac {\\partial \\chi^2} {\\partial \\theta_j}, \\\\\n    %\n    \\frac {\\partial^2 P} {\\partial\\theta_j \\partial\\theta_k}\n    &= -\\frac{n+k}2 \\left[\n    -\\frac 1 {(\\chi^2)^2}\n    \\frac {\\partial \\chi^2} {\\partial \\theta_j}\n    \\frac {\\partial \\chi^2} {\\partial \\theta_k}\n    + \\frac 1{\\chi^2}\n    \\frac {\\partial^2 \\chi^2} {\\partial\\theta_j \\partial\\theta_k}\n    \\right]. \\label{eq:Pjk}\n\\end{align}\n\nIn the maximum $\\partial_j P = 0$, so the first term in \\eqref{eq:Pjk}\nvanishes, leaving\n%\n\\begin{align}\n    \\frac {\\partial^2 P} {\\partial\\theta_j \\partial\\theta_k}\n    &= -\\frac12 \\frac 1 {\\chi^2/(n+k)}\n    \\frac {\\partial^2 \\chi^2} {\\partial\\theta_j \\partial\\theta_k}.\n    \\label{eq:chi2dof}\n\\end{align}\n%\nThis is to be compared with the precision matrix in \\eqref{eq:lsqpm}. The\nonly difference is that the matrix has been divided by $\\chi^2/(n+k)$. Note\nthat $\\mathrm{dof} = n$, so we obtained a different prescription than the\nconventional one. Nevertheless, in the analysis we used $\\chi^2/\\mathrm{dof}$\njust because it is what people expect; compared to \\eqref{eq:chi2dof}, this\ngives errors up to \\SI{25}\\% larger on our fits, see \\autoref{tab:ct}.\n\nSimilarly, we used the pvalue; since we always obtained a stark contrast\nbetween good and bad fits, we did not bother giving a precise Bayesian\nequivalent.\n", "meta": {"hexsha": "fbddfb4e96ca74be6430ae439e68a4e2a5f9f79a", "size": 14850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fit.tex", "max_stars_repo_name": "Gattocrucco/thesis", "max_stars_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-15T07:16:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T07:16:46.000Z", "max_issues_repo_path": "fit.tex", "max_issues_repo_name": "Gattocrucco/thesis", "max_issues_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "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": "fit.tex", "max_forks_repo_name": "Gattocrucco/thesis", "max_forks_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "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": 38.772845953, "max_line_length": 80, "alphanum_fraction": 0.6783164983, "num_tokens": 4676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.6282790563776071}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{array}\n\\usepackage{clrscode3e}\n\\usepackage{amsmath}\n\\usepackage{kbordermatrix}\n\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{1em}\n\n\\begin{document}\n\n\\title{Efficient Calculation of Interaction Features on Sparse Matrices}\n\\author{Andrew Nystrom}\n\\date{}\n\n\\maketitle\n\n\\begin{abstract}%   <- trailing '%' for backward compatibility of .sty file\nFILL THIS IN\n\\end{abstract}\n\n\\section{Introduction}\n\nIntroduction\nInteraction features are a way of capturing correlations between features in a machine \nlearning setting. A feature vector $\\vec{x}$ of dimensionality $D$ has second degree interaction features \n$\\{x_i \\cdot x_j : i, j \\in \\{0,1,..., D-1\\} \\land i < j\\}$, \nso a $D$ dimensional vector has $\\binom{D}{2} = \\frac{D^2-D}{2}$ second degree interaction features. A naive\napproach to calculating these features is to simply iterate through the combinations of the column indices.\nFor a sparse vector, many of the resulting interaction features would be zero, and could therefore be ignored.\nThis work describes a method to efficiently calculate second degree interaction features for a sparse matrix \nthat has time and space complexities that decrease quadratically with the density of the input matrix with respect to the naive approach.\n\n\\section{Approach}\nLet the list of nonzero columns for a given row $\\vec{x}$ be denoted by $N_{zc}$. The nonzero second degree \ninteraction features are simply the products of all combinations of two elements whose \ncolumns are in $N_{zc}$. However, to properly place an interaction feature into the correct column, a mapping from the column \nindex pairs of $N_{zc}$ into the columns of the interaction matrix is needed. The mapping is \nfrom pairs $(a, b)$,  where $a$ and $b$ are in $1,2,..., D$, and $a < b$, to $1,2,..., \\frac{D^2-D}{2}$,  Such a mapping essentially consists of mapping the indices of entries in the upper triangle of a matrix to indices in a flat \nlist. We now describe the construction of such a mapping. \n\n\\subsection{Mapping construction}\nWe seek a map from matrix indices $(i, j)$ (with $i < j$ and $0 \\le i < D$) to numbers $f(i, j)$ with $0 \\le f(i, j) < \\frac{D(D-1)}{2}$, one that follows the pattern indicated by \n\\begin{align}\n\\begin{bmatrix}\nx & 0 & 1 & 2 \\\\\nx & x & 3 & 4 \\\\\nx & x & x & 5 \\\\\nx & x & x & x\n\\end{bmatrix}\n\\end{align}\nIt's considerably easier, however, to consider the same indices, but subtracted from $6$ (or more generally, from $\\frac{D(D-1)}{2}$; that gives the pattern\n\\begin{align}\n\\label{eq:4x4mat}\n\\begin{bmatrix}\nx & 6 & 5 & 4 \\\\\nx & x & 3 & 2 \\\\\nx & x & x & 1 \\\\\nx & x & x & x\n\\end{bmatrix}\n\\end{align}\nWe'll call the function defined by this example $(i, j) \\mapsto g(i, j)$, and then observe that \n\\begin{align}\nf(i, j) = \\frac{D(D-1)}{2} - g(i, j)\n\\end{align}\n\nTo simplify slightly, we introduce a notation for the $n$th triangular number, \n\\begin{align}\n\\begin{bmatrix}\nT_2(n) = \\frac{n(n+1)}{2}\n\\end{bmatrix}\n\\end{align}\n\\noindent\nThe subscript $2$ is there to indicate that these are triangles in two dimensions; we'll use $T_3(n)$ to indicate the $n$th tetrahedral number, and so on for higher dimensions. \n\nThe codomain of $g$ is now numbers from $1$ to $T_2(D-1)$, inclusive. \n\nObserve that in Equation~\\ref{eq:4x4mat}, each entry in row $i$ lies in the range\n\\begin{align}\nT_2(D-i-1) &< e \\le T_2(D-i).\n\\end{align}\n\\noindent\nFor instance, in row $2$ in our example, where $D = 4$, the entries range from $2$ to $3$, while $T_2(D-i-1) = T_2(1) = 1$ and $T_2(D-i) = T_2(2) = 3$. (Note that row indices start at zero.) Unfortunately, the numbers increase from right to left. The entry in column $j$ is just $T_2(D-i-1) + D-j$, which adds one for the rightmost column (because $D - (D-1) = 1$). \nThus, the formula for $g$ is simply\n\\begin{align}\ng(i, j) \n&= T_2(D-i-1) + (D-j) \\\\\n&= \\frac{(D-i-1)(D-i)}{2} + D-j \\\\\n&= \\frac{(D^2 - (2i)D - D - i^2 - i) + 2D - 2j}{2} \\\\\n&= \\frac{D^2 - (2i)D + D - i^2 - i - 2j}{2}\n\\end{align}\nand hence \n\\begin{align}\nf(i, j) \n&= \\frac{D(D-1)}{2} - g(i,j) \\\\\n&= \\frac{D^2-D}{2} - \\frac{D^2 - (2i)D + D - i^2 - i - 2j}{2}\\\\\n&= \\frac{D^2-D - D^2 + (2i)D - D + i^2 + i + 2j}{2}\\\\\n&= \\frac{(2i)D - 2D + i^2 + i + 2j}{2}\n\\end{align}\n[WRONG]\nCorrect result:\n\\begin{align}\nR = \\frac{ 2in - i^2  + 2j - 3i - 2}{2}.\n\\end{align}\n\\subsubsection{Other indices}\nWith one-based indexing, the formula above becomes\n\\begin{align}\nf_1(i, j) &= ....\n\\end{align}\n\n\n\n\n\n  column \n\n\nINSERT JOHN'S PROOF HERE\n\nWith this mapping, an algorithm for generating second degree interaction features on a \nmatrix $A$ can be formulated as follows:\n\n\\begin{codebox}\n\\Procname{$\\proc{Sparse Interaction}(A)$}\n    \\zi $\\func{map}(a, b) = \\frac{2Da-a^2+2b-3a-2}{2}$\n    \\zi $N \\gets$ row count of $A$\n    \\zi $D \\gets$ column count of $A$\n    \\zi $B$ $\\gets$ Compressed Sparse Row Matrix of size $N \\times \\frac{D^2-D}{2}$\n    \\zi \\For $\\id{row}$ in $A$ \\Do\n    \\zi     $N_{zc} \\gets$ nonzero columns of $row$\n    \\zi     \\For $i \\gets 0 \\To |N_{zc}|-1$ \\Do\n    \\zi         \\For $j \\gets i+1 \\To |N_{zc}|$ \\Do\n    \\zi             $k \\gets \\func{map}(i, j)$\n    \\zi             $r \\gets$ index of $\\id{row}$\n    \\zi             $B[r, k] \\gets \\id{row}[i] \\cdot \\id{row}[j]$\n                \\End\n            \\End\n       \t\\End\n\\end{codebox}\n\n\\section{Complexity Analysis}\nAssume that A is a matrix with sparsity $0 < d < 1$, $N$ rows, and $D$ columns. Finding \ninteraction features with the proposed algorithm has time and space complexity \n$\\func{O}(d N D^2)$, \nwhereas a naive approach of using non-sparse matrices and multiplying all column \ncombinations has time and space complexity $\\func{O}(N D^2)$. The algorithm is therefore an \nimprovement by a factor of the density factor of $A$.\n\nThis can represent a large gain in speed and time. For example, the 20 Newsgroups dataset \nhas density $d$ of 0.12 when its unigrams are represented in a vector space model. This \nmeans the proposed approach would take less than $\\frac{1}{8}$ time and memory.\n\nThe real benefit of this method is revealed when the average complexity is analysed. The \nnumber of interactions calculated for a given row are $\\binom{|N_{zc}|}{2}$. If the matrix has \ndensity $d$, then on average, $N_{zc} = D d$, so the number of interaction features \ncalculated in total is \n\n\\begin{align*}\nN \\binom{d D}{2} &= N \\frac{(Dd)!}{2!(Dd-2)!}\\\\\n    \\\\\n    &= N \\frac{(D^2d^2-Dd)}{2}\n\\end{align*}\n\nThis means that the average complexity decreases quadratically with the density.\n\n\\section{Future Work}\nThe approach for generating second degree interaction features required a mapping from \ncombinations of two to the space $1,2,...,\\frac{D^2-D}{2}$, which is isomorphic to a mapping from \nthe indices of an upper triangular matrix to the indices of a flat list of the same size. \nTo generate third degree interaction features, a mapping from combinations of three \n$(a,b,c)$ to the space $1,2,...\\frac{D^3-3D^2+2D}{6}$ (which is $\\binom{D}{3}$), or the upper $3$-simplex of a tensor to a flat \nlist of the same size $\\frac{D^3-3D^2+2D}{6}$ would be required. In general, for interaction \nfeatures of degree k, the upper $k$-simplex of a $k$-dimensional tensor must be mapped to the \nspace $1,2,...\\frac{D!}{k!(D-k)!}$. A similar approach for finding these mappings could be taken \nas the one used here for $k=2$. \n\nMotivation for deriving mapping functions for higher orders\nof interaction features is that the average complexity of generating degree $k$ interaction\nfeatures is $N \\binom{Dd}{k}$, which decreases polynomially with respect to k compared to\ngenerating the features naively.\n\n    \n\\vskip 0.2in\n\\bibliography{sample}\n\n\\end{document}", "meta": {"hexsha": "a3794a8639ceabfec1479aefde03e57764452e40", "size": 7660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/spares_interaction.tex", "max_stars_repo_name": "AWNystrom/SparseInteraction", "max_stars_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-01-08T17:17:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-16T15:35:26.000Z", "max_issues_repo_path": "paper/spares_interaction.tex", "max_issues_repo_name": "AWNystrom/SparseInteraction", "max_issues_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "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/spares_interaction.tex", "max_forks_repo_name": "AWNystrom/SparseInteraction", "max_forks_repo_head_hexsha": "68ac222d7a826a344675d0e5196d82cb1711a69a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-01-08T17:28:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-08T17:36:00.000Z", "avg_line_length": 40.9625668449, "max_line_length": 366, "alphanum_fraction": 0.6778067885, "num_tokens": 2453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6282790546914326}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage[utf8]{luainputenc}\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{2 mars, 2015}\n\\maketitle\n\nwhen does taylor series converge?\n\nbetter question is when is $f(x)=\\sum\\limits{f^{(n)}(a)/n!\\cdot (x-a)^n}$\n\n\n\\section*{taylor's thm}\n$f\\in C^{\\infty}[a,b]$ and $f^{(n+1)}$ is defined on $[A,B]$ with $|f^{(n+1)}(x)|\\le M$ for $x\\in [A,B]$ then $R_n(x)=f(x)-\\sum{\\frac{f^{k}}{k!}(x-a)^k}$ satisfies $|R_n(x)|\\le M|x-a|^{n+1}/(n+1)!$\n\\begin{enumerate}\n\\item\n$f(x)=\\lim\\sum\\frac{f^{(k)}}{k!}(x-a)^k$ if and only if $\\lim R_n(x)=0$\n\nthe basic issue is that $M$ needs to not get too big to fast\n\\item\nif $f\\in C^\\infty[A,B]$ then these hypotheses happen automatically (it's infinitely differentiable), although there is no guarantee that the taylor series converges to $f$.\n\\end{enumerate}\n\nwe want to use induction (what are we inducting on?)\n\nwe will show that $|R_n^{(n-k)}(x)|\\le\\frac{M|x-a|^{k+1}}{(k+1)!}$.\n\nbase case is $k=0$. $R_n(x)=f(x)-\\sum{\\frac{f^{(k)}}{k!}(x-a)^k}=f^{(n)}-\\frac{n!}{n!}f^{(n)}x$ and so $|R_n(x)|=|f^{(n)}(x)-f^{(n)}(a)|$. by MVT we know $M|x-a|\\ge f^{(n+1)}(c)|x-a|=|R_n(x)$. So base case is done\n\nassume $|R_n^{(n-k)}(x)|\\le M|x-a|^{k+1}/(k+1)!$. consider $|R_n^{(n-(k+1))}(x)|=|R_n^{(n-(k+1))}(a)-\\int_a^x{R^{(n-k)}(t)\\;\\mathrm{d}t}|$\n\n\\subsection*{example}\n$f(x)=\\sin x$ and $a=\\frac{\\pi}{2}$.\n\n$P_n(x)=\\sum\\limits_{k=0}^n{\\frac{f^{(k)}(\\frac{\\pi}{2}(x-\\frac{\\pi}{2})^k}{k!}}$ and then we have $P_n=\\sum\\limits_{k=0}^n{(-1)^k(x-\\frac{\\pi}{2})^{2k}}/(2k)!$. Now $M_n=1$ (it is bounded by 1). Now then $R_n(x)\\le \\frac{1\\cdot |x-a|^{n+1}}{(n+1)!}$ and because factorials are bigger than powers,  the limit is $R=0$.\n\nand so the power series gives the same value as the function all the time.\n\n$f(x)=\\log x$ (natural log). taylor series at 1. note that zero is a problem. one is nice because it's symmetric and easy to compute.\n\n$f'(x)=\\frac{1}{x}, f''(x)=-\\frac{1}{x^2}, f'''(x)=\\frac{2}{x^3},\\dots$\n\n$P_n=\\sum\\limits_{k=1}^n{(-1)^{k+1}\\frac{(k-1)!}{k!}(x-1)^k}$ now use ratio test\n\n$\\frac{\\frac{(-1)^{k+2}}{k+1}}{\\frac{(-1)^{k+1}}{k}}\\to$ radius of convergent of 1, centered at zero, so interval is $(0,2)$\n\\end{document}\n", "meta": {"hexsha": "3bef4a4e2b11fc1128d0406cfeb364bbf0dff5ec", "size": 2341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ra2/ra2-notes-2015-03-02.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": "ra2/ra2-notes-2015-03-02.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": "ra2/ra2-notes-2015-03-02.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": 41.8035714286, "max_line_length": 318, "alphanum_fraction": 0.6065783853, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6282790513190841}}
{"text": "\\section{Linkages and Frameworks}\n--izmestiev def of framework\n--freedom in machines def of linkage\n--used to describe configurations and freedoms \n\n\n\\section{Geometric Configuration Space}\n\n --pictures of flexing. \n\\begin{figure}[ht]\n  %\\includegraphics[scale=0.1, angle=0]{tetris.eps}\n\\caption{Different geometric configurations of an octahedron intermediate.}\n\\label{fig:OctaGCS}\n\\end{figure}\n--embedding\n\n\\begin{mydef}\nThe \\textbf{constraint space} corresponding to a constraint function $c: \\mathbbm{R}^n \\to \\mathbbm{R}^{n-m}$ is its zero-set,\n\\begin{align}\n\\Omega \\doteq \\{z \\in \\mathbbm{R}^n : c(z) = 0\\}.\n\\end{align}\n\\end{mydef}\nIf $c$ is composed of polynomial functions, then the constraint space is an algebraic variety. If this variety has no singularities, then it is also a manifold. \n\nUsing the notion of a constraint space, we can define the space of different geometric configurations that a given intermediate can take. Since we are treating each intermediate as collection of rigid polygons attached to each other along hinged edges, there are two basic types of constraint we must enforce. First, we must ensure that the each individual face is rigid and has the correct geometric shape. Additionally, each edge to edge connection must remain fixed with only hinge-like motion allowed. \n   \n\\begin{mydef}\nThe \\textbf{geometric configuration space} of a building game intermediate is a constraint space that enforces the rigidity of individual faces and hinged motion along connected edges.\n\\end{mydef}\n\nTo mathematically describe a particular configuration, we must specify the locations of the vertices of each face. Thus, for an intermediate $[x]$, its building game configuration space can be represented as a subset of the ambient space $\\mathbb{R}^{3\\times N_x}$ where $N_x \\doteq \\sum_{f\\in x} s_f$ where $s_f$ is the number of sides (and verticies) of face $f$. Using this representation, we must then identify the corresponding constaint equations that give rise to the combinatorial configuration space as a function of points in ambient space. \n\nIt is worth noting that while we represent each face with $3\\times s_f$ coordinates, only 6 are required to speciafy a face's position and orientation if they are chosen carefully. With this in mind, we will typically use a function of $6$ of a face's vertex coordinates to constrain each of the face's remaining vertex coordinates. \n\n\nNotationally, we refer to the $k$th vertex of the $j$th face of $x$ as $v^{jk} = \\left(v^{jk}_x,v^{jk}_y,v^{jk}_z\\right)$.\nSince the context of a constraint space requires a function $c: \\mathbbm{R}^n \\to \\mathbbm{R}^{n-m}$, we flatten the matrix of vertex coordinates into a vector of lenghth $n = 3N_x$. \n\\begin{align}\nz = \\begin{bmatrix} v^{1,1} \\\\ \\vdots \\\\ v^{1,s_{f_1}} \\\\ \\vdots \\\\ v^{|x|,1} \\\\ \\vdots \\\\ v^{|x|,s_{f_{|x|}}} \\end{bmatrix} \\in \\mathbbm{R}^n\n\\end{align}\n\nThere are four fundamental types of constraint equations: edge length constraints, angle constraints, and $2D$ face constraint to enforce the rigid structure of each face as well as vertex identification constraints to enforce the hinged connections.\n\nEdge length constraints enforce that the lengths of the edges of each face in an intermediate cannot change. If the $k$th edge is definted to be that between the $(k-1)$st and $k$th vertices, we use the following function to constrain its lengths to a known value $\\ell^{jk}$.\n\\begin{align}\nc_{edge}^{j,k}\\left(z\\right)& = \\left|v^{j,k} - v^{j,k-1}\\right|^2 - (\\ell_{j,k})^2 \\\\\n& = \\left(v_1^{j,k} - v_1^{j,k-1}\\right)^2 +\\left(v_2^{j,k} - v_2^{j,k-1}\\right)^2 +\\left(v_3^{j,k} - v_3^{j,k-1}\\right)^2 - (\\ell^{j,k})^2 \n\\end{align}  \nThis uses the notational convention that $v^{j,0} \\doteq v^{j,s_j}$. For reasons that will be explained, we only explicitly enforce the lengths of two edges ($k=1,2$) per face, so there are a total of $2|x|$ edge length constraints. \n\nAngle constraints ensure that each face's polygonal angles are conserved. Using the dot product formula for angles, we can write this constraint as a polynomial.\n\\begin{align}\nc_{ang}^{j,k}\\left(z\\right) &= (v^{j,k-1} - v^{j,k})\\cdot(v^{j,k+1} - v^{j,k})  - \\ell^{j,k}\\ell^{j,k+1}\\cos(\\theta^{j,k})\n\\end{align}  \nHere, $\\theta^{j,k}$ is the angle at $v^{j,k}$ between $k$th and $(k+1)st$ edges which is a constant that is known a priori. In practice, we only enforce that the $k=1$st angle constraint for each face.\n\nNow, between the two edge constraints and one angle constraints, we have described $3$ constraints as a function of $9$ vertex coordinates per face. Thus for any choice of the $6$ coordinates, $v^{j,1}_1, v^{j,1}_2, v^{j,1}_3, v^{j,2}_1, v^{j,2}_2, v^{j,0}_1$, the remaining $3$ coordinates, $v^{j,2}_3, v^{j,0}_2, v^{j,0}_3$, are specified by the $3$ constraint equations. Similarly, since each face's location and rotational orientation can be defined by this choice of $6$ coordinates, we have enough information to specify the coordinates of the remaining verticies. \n\nSince the positions of the first three verticies dictate the locations of the remaining verticies, the $2D$ face constraints use a map from the known vertex coordinates to the yet unknown locations. Using a template for what the ideal polygonal stucture for each face should be, we use a rotation matrix to specify these remaining verticies. If this template has vertices $\\hat{v}^{j,0}, \\hat{v}^{j,1}, \\hat{v}^{j,2}, \\dots, \\hat{v}^{j,k}, \\dots$ and the locations for $v^{j,0}, v^{j,1}, \\text{and } v^{j,2}$ are known, we can identify the location of $v^{j,k}$ for $k>2$. Using this template, we can define the following length and angle constants.\n\\begin{align}\n\\ell^{j,k_1, k_2} &\\doteq |\\hat{v}^{j,k_1} - \\hat{v}^{j,k_2}| \\\\ \n\\phi^{j,k_1,k_2,k_3} &\\doteq \\cos^{-1}\\left(\\frac{\\left(\\hat{v}^{j,k_1} - \\hat{v}^{j,k_2}\\right)\\cdot\\left(\\hat{v}^{j,k_3} - \\hat{v}^{j,k_2}\\right)}{(\\ell^{j,k_1, k_2})(\\ell^{j,k_3, k_2})}\\right)   \n\\end{align}\n\n\\begin{figure}[ht]\n  %\\includegraphics[scale=0.1, angle=0]{tetris.eps}\n\\caption{Face template and 2d face constraints.}\n\\label{fig:2DFC}\n\\end{figure}\n\nOur basic stratigy is to first place a point $\\bar{v}^{j,k}$ in the span of $v^{j,0} - v^{j,1}$ at a distance of $|\\bar{v}^{j,k} - v^{j,1}| = \\ell^{j,k,1}$. The choice $\\bar{v}^{j,k} = v^{j,1} + \\frac{\\ell^{j,k,1}}{\\ell^{j,0,1}}(v^{j,0} - v^{j,1})$ will work, since \n\\begin{align}\n  |\\bar{v}^{j,k} - v^{j,1}| &= |\\frac{\\ell^{j,k,1}}{\\ell^{j,0,1}}(v^{j,0} - v^{j,1})| \\\\\n  &= \\frac{\\ell^{j,k,1}}{\\ell^{j,0,1}}|v^{j,0} - v^{j,1}| \\\\\n  &= \\ell^{j,k,1}.\n\\end{align}\nThen, a rotation matrix is used to rotate $\\bar{v}^{j,k}$ by the correct angle into its position $v^{j,k}$.\nThe rotation matrix is centered at $v^{j,1}$ and its axis of rotation is defined by $u = \\frac{1}{\\ell^{j,0,1}\\ell^{j,2,1}}(v^{j,0} - v^{j,1})\\times(v^{j,2} - v^{j,1})$.  Similarly, the angle of rotation $\\phi^{j,0,1,k}$ is the angle created by the two line segments in the template $(\\hat{v}^{j,0},\\hat{v}^{j,1})$ and  $(\\hat{v}^{j,2},\\hat{v}^{j,1})$. Thus, using $R = R(\\phi^{j,0,1,k}, u)$ and our equation for $v^{j,k}$ is \n\\begin{align}\nv^{j,k} &= v^{1,k} + R(\\bar{v}^{j,k} - v^{j,1})\\\\\n&= v^{1,k} + \\ell^{j,k,1}R(v^{j,0} - v^{j,1})\\\\\n\\end{align}\nSince $R$ is polynomial in $v^{j,0}, v^{j,1}, v^{j,2}$, we get the following polynomial $2$D face constraint for each $k > 2$.\n\\begin{align}\nc_{2D}^{j,k}(z) \\doteq v^{1,k} + \\ell^{j,k,1}R(v^{j,0} - v^{j,1}) - v^{j,k}\n\\end{align} \n\nThe final constraint type, vertex identification, is used to enforce that the connection between edges of two faces has the mobility of a hinge. To do this, we simply need to ensure that that corresponding vertices on each edge share identical locations. This results in the relatively simple constraints:\n\\begin{align}\nc_{ident}^{j_1,k_1,j_1,k_1,d}(z) \\doteq v^{j_1,k_1}_d - v^{j_2,k_2}_d \\\\\n\\end{align}\nwhere $v^{j_1,k_1}$ and $v^{j_2,k_2}$ are corresponding vertices from the faces $j_1$ and $j_2$ meeting at a hinged edge. If there are $|E_x|$ of these hinged connections in a building game state $x$, there must be $6|E_x|$ correcponding vertex identification constraints.\n\nWith all four constraint types explicitly defined, the aggregate constraint function for $x$ will have $n-m = 2|F_x|+ |F_x| + (N_x - 3|F_x|) + 6|E_x| = N_x + 6|E_x|$ total constraints. \n\n\n%To mathematically represent each of the possible geometric configurations, we parameterize the embedding using its vertex locations. If a building game state is composed of the faces $\\{f_1,\\dots, f_i\\}$, then any embedding of the intermediate can be described by a point in $\\mathbbm{R}^n$, where $n$ is the three times sum $3\\sum_{j=1}^i \\#\\text{vertices}(f_j)$, of the number of vertices in each face. Simply put, the point \n% which is the concatenation of all of the vertex locations $v_1, v_2, \\dots, v_{n/3} \\in \\mathbbm{R}^3$ for each verted on each face of an intermediate is used to represent a particular embedding. \n\n\\subsection{Special Case of Triangular Faces}\n\nIn the case where all of the faces of the polyhedron we consider are triangles (tetrahedron, octahedron, icosahedron, etc.) we notice that \n\n\\begin{mycon}\nThe geometric configuration space for each intermediate composed of equilateral triangular faces is a manifold.\n\\end{mycon}\n\n%\\begin{mycon}\n%\n%\\end{mycon}\n\n\n\\section{Degrees of Freedom}\nRoughly speeking, the degrees of freedom of a system are the different independent motions the system is able to exercise. Since the concept of degrees of freedom exists in many diverse scientific fields, such as mechanical engineering and statistical physics, many different formal definitions of degrees of freedom are used in the literature. McCarthy defines degrees of freedom of a mechanical system as follows. CITE \n\\begin{quote}\nWe derive formulas for the number of parameters needed to specify the configuration of a mechanism, in terms of the number of links and joints and the freedom of movement allowed at each joint. This number is the \\textit{degrees of freedom} or \\textit{mobility} of the mechanism. Changing the values of these parameters changes the configuration of the mechanism. Thus, if we view the set of all configuration available to a mechanism as a manifold, then the mobility of the mechanism is the dimension of this manifold. \n\\end{quote}\n\nSince our geometric configuration space is an algebraic variety and not a manifold in general, this definition must be modified to make degrees of freedom a statistic of each individual configuration rather than a global statistic of the geometric configuration space. \n\n\\begin{mydef}\nThe number of \\textbf{degrees of freedom} a building game intermediate at configuration $z$ is the dimension of the geometric configuration space algebraic variety at $z$. If $z$ is a singularity of the algebraic variety, then the degrees of freedom is undefined.\n\\end{mydef}\n\nIn most cases we consider, rigid rotation and rigid translation will preserve the value of the constraint function since they do not move the verticies relative to one another. In other words, if $c(z) = 0$ then we also have $c(Rz + T) = 0$ where $R \\in \\mathbbm{R}^{n}\\times n$ rotates each vertex in the configuration by some $\\hat{R} \\in SO(3)$ and translates each vertex by $\\hat{T} \\in \\mathbbm{R}^3$. With this definition, $R$ is the block diagonal matrix with each of the $n/3$ block being $\\hat{R} \\in SO(3)$ and $T \\in \\mathbbm{R}^n$ is composed of $n/3$ copies of $\\hat{T} \\in \\mathbbm{R}^3$ stacked upon each other. These rigid body rotations account for $6$ of the configuration's degrees of freedom: $3$ rotational degrees of freedom and $3$ translational.\n\\begin{mydef}\nThe \\textbf{trivial degrees of freedom} a building game intermediate at configuration $z$ are the $6$ degrees of freedom corresponding to rigid body rotations and translations.\n\\end{mydef}\nThus, the degrees of freedom we are most interested in are those that do represent movement of the verticies and faces relative to each other. \n\\begin{mydef}\nThe \\textbf{internal degrees of freedom} a building game intermediate at configuration $z$ are the degrees of freedom that are not trival.\n\\end{mydef}\n\n\n\\begin{mydef}\n\\textbf{cannonical configuraion}\n\\end{mydef}\n\n\\subsection{Computing Degrees of Freedom}\n--First for a general configuration space\n--Jacobian equations\n--rank of C\n--extension to non triangular polyhedra\n--implementing on computer\n\n\\[\n\t\\frac{\\partial\\psi_{edge}^{j,k}}{\\partial v} =\n  \t\\begin{cases}\n        \t2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k}_\\bullet \\\\\n   \t\t-2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k-1}_\\bullet \\\\\n   \t\t0       & \\text{else} \n  \t\\end{cases}\n\\]\n\n\n\\subsection{Non-Manifold Example}\nFrom this definition, it is worth noting that if the geometric configuration space is indeed a manifold, then the degrees of freedom is the dimension of that manifold which is a global property. Here we present an interesting example in which this is not the case and, depending on the specific configuration, a different number of degrees of freedom exist.\n\n\\begin{figure}[ht]\n  %\\includegraphics[scale=0.1, angle=0]{tetris.eps}\n\\caption{A linkage of 6 squares with configurations of different degrees of freedom.}\n\\label{fig:SixSq}\n\\end{figure}\n\n\n\\subsection{Results}\n\n--Pictures!!\n\n\\subsection{Explicit Removal of Trivial Degrees of Freedom}\n\n--fixe center of mass.\n\n%We consider the linkage of rigid 2-dimensional polygons in $\\mathbb{R}^3$ by means of ideal hinges located at the edges of the polygons. In this way, by treating intermediates of our various models as such a linkage, we can compute the non-trivial degrees of freedom (DoF) each intermediate has. \n\n%Every linkage of this type has 6 trivial degrees of freedom: 3 corresponding to translational movement and 3 corresponding to rotational freedom. While these freedoms do change the orientation of the intermediate, they do not cause the faces to move relative to each other. For this reason, we label them as trivial degrees of freedom and focus on the calculation the remaining, non-trivial degrees of freedom. \n\n%For our purposes, we define the \\textbf{degrees of freedom} of a configuration to be the difference between the number of parameters needed to specify a configuration in an ambient parameter space $\\Omega$ and the number of independent constraints imposed upon the configuration as a function of these parameters. Consequently, the non-trivial degrees of freedom is the number of degrees of freedom minus the six trivial degrees of freedom. If the ambiant parameter space is $\\mathbb{R}^N$ and there are $M$ constraint equations given by $\\varphi : \\mathbb{R}^N \\to \\mathbb{R}^M$, we find the degrees of freedom to be $N - \\operatorname{rank}(\\varphi)$ and the non-trivial degrees of freedom to be $N - \\operatorname{rank}(\\varphi) - 6$. Here we need $\\varphi$ to be a smooth map so that the rank is well defined. Furthermore, we define the \\textbf{configuration space} to be the subset of parameter space $\\{\\omega \\in \\Omega : \\varphi(\\omega) = 0\\}$ upon which the contraints are satisfied.\n\n%In our case, the location and orientation of each polygon in the linkage can be represented by a total of 6 parameters: 3 for location and 3 for roational orientation. Thus, the entire configuration of an intermediate $x$ can be represented in the parameter space $\\mathbb{R}^{F_x\\times6}$. With constraints corresponding to hinged connections we construct a function $\\varphi$ which is zero if and only if the constraints are satisfied. Thus the configuration space is $\\{z \\in \\mathbb{R}^{F_x\\times6} : \\varphi(z) =0\\}$. As we will show below, the constraint equation $\\varphi$ can be constructed as a polynomial which means that the configuration space (as the zero set of this polynomial) is an algebraic variety. \n\n% PARAGRAPH ON DIFFERENT DOF VALS AT DIFFERENT CONFIGS OF SAME INTERMEDIATE We refer to the embedded configuration of $x$ such that $x$ is a subset of the original polyhedron as the \\textbf{canonical configuration}.\n\n\n%The base constaints are put in place to fix one of the intermediate's faces in space to remove the 6 trivial degrees of freedom from the calculation. If $f_b$ is the face we wish to designate as the base we have the following $3\\times s_b$ constraint equations\n%\\begin{align}\n%\\psi_{base}^{k,x}\\left(\\mathbf{v}\\right)& = v^{b,k}_x - c^{b,k}_x \\\\\n%\\psi_{base}^{k,y}\\left(\\mathbf{v}\\right)& = v^{b,k}_y - c^{b,k}_y \\\\\n%\\psi_{base}^{k,z}\\left(\\mathbf{v}\\right)& = v^{b,k}_z - c^{b,k}_z\n%\\end{align}  \n%for $k = 1,\\dots,s_b$ and with $c^{b,k}_\\bullet$ a known constant. The corresponding Jacobian calculation for each constraint equations is:\n%\\[\n%\\frac{\\partial\\psi_{base}^{k,\\bullet}}{\\partial v} =\n%  \\begin{cases}\n%   1 & \\text{if } v = v^{b,k}_\\bullet \\\\\n%   0       & \\text{else} \n%  \\end{cases}\n%\\]\n\n%Edge length constraints enforce that the lengths of the edges of each face in an intermediate cannot change. Since there are $s_j$ edges for each face $f_j$ of intermediate $x$, there are $N_x$ corresponsing edge constraints. \n%\\begin{align}\n%\\psi_{edge}^{j,k}\\left(\\mathbf{v}\\right)& = \\left|v^{j,k} - v^{j,k-1}\\right|^2 - \\ell_{j,k}^2 \\\\\n%& = \\left(v_x^{j,k} - v_x^{j,k-1}\\right)^2 +\\left(v_y^{j,k} - v_y^{j,k-1}\\right)^2 +\\left(v_z^{j,k} - v_z^{j,k-1}\\right)^2 - \\ell_{j,k}^2 \n%\\end{align}  \n%for all $j: f_j \\subset x$ and with the convention that $v^{j,0} \\doteq v^{j,s_j}$ and $\\ell_{j,k}$ is a known constant. The resulting partial derivatives are\n%\\[\n%\t\\frac{\\partial\\psi_{edge}^{j,k}}{\\partial v} =\n%  \t\\begin{cases}\n%        \t2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k}_\\bullet \\\\\n%   \t\t-2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k-1}_\\bullet \\\\\n%   \t\t0       & \\text{else} \n%  \t\\end{cases}\n%\\]\n%--definiteion of 'base configuration'\n%--representation of config space definition as system of constraint equations\n%--solution of the constraint equations is a manifold except perhaps at some 'sp0ecial' configurations\n%--define DoF as 6N - rank of the jacobian of the CEqs evaluated at the base config\n\n%--go through computation of jacobian  \n\n\n\n\n\\section{Cyclohexane Application}\n??Include??\n%\\subsection{Sachse Model}\n%\n%Around the turn of the century, it was thought that cyclohexane's carbon atoms must lie in a plane. A young German assistant, Hermann Sachse, had the idea that allowing the carbons to lie outside the plan could alleviate the angle strain. Inspired by polyhedral geometry, he templates and outlined methods for creating 3D models of the chair and boat configurations his new theory conceptualized. Figure~\\ref{fig:sachse} shows a construction of these two models. Despite his best efforts, Sachse's ideas were not accepted by that chemistry community until after his death. \n%\n%\n%\n%\\begin{figure}\n%        %\\centering\n%        %\\begin{subfigure}[b]{0.24\\textwidth}\n%        %        \\includegraphics[width=\\textwidth]{chair_model_2.png}\n%        %        \\caption{Chair (top)}\n%        %        \\label{fig:CM1}\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]{0.24\\textwidth}\n%        %        \\includegraphics[width=\\textwidth]{chair_model_1.png}\n%        %        \\caption{Chair (side)}\n%        %        \\label{fig:CM2}\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]{0.24\\textwidth}\n%        %        \\includegraphics[width=\\textwidth]{boat_model_1.png}\n%        %        \\caption{Boat (top)}\n%        %        \\label{fig:BM1}\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]{0.24\\textwidth}\n%        %        \\includegraphics[width=\\textwidth]{boat_model_2.png}\n%        %        \\caption{Boat (side)}\n%        %        \\label{fig:BM2}\n%        %\\end{subfigure}%\n%        %\\caption{Sachse Models}\\label{fig:sachse}\n%\\end{figure}\n%\n% \n%\\subsection{Idealized Constraint Model}\\label{building_game}\n%\n%Withe the eclipsing and angle strains in mind, we heuristically define an idealized model of cyclohexane by imposing geometric constraints. Each configuration is represented by the 3-dimensional locations of the center of its carbon atoms and we explicitly parameterize these locations as $v_1, v_2, \\dots, v_6$ where $v_k \\in \\mathbb{R}^3$. For ease of exposition, $v_0 \\doteq v_6$ and $v_{-1} \\doteq v_5$ are notationally identified. \n%\n%First, we require that any two atoms sharing a bond have a known and fixed distance $\\ell$ from each other. Since we can re-scale our coordinate system, we assume $\\ell \\doteq 1$. Additionally, we assume that the connectivity of the cyclohexane molecule is such that $v_k$ is bonded to $v_{k-1}$ for $k = 1,\\dots,6$. This gives our first six constraint equations.\n%$$0 = \\varphi_{len}^k\\left(v_{k-1},v_{k}\\right) = \\|v_k-v_{k-1}\\| - 1 $$\n%for $k = 1,\\dots,6$. \n%\n%Additionally, we impose constraints representing the angle strain. Since the carbon atoms have the lowest energy when their bonds are at tetrahedral angles, we fix the angle of each set of three adjacent carbons to be at the tetrahedral angle. This is equivalent to the six angle constraint equations \n%$$0 = \\phi_{ang}^k\\left(v_{k-2},v_{k-1},v_{k}\\right) = \\left(v_k-v_{k-1}\\right)\\cdot \\left(v_{k-2}-v_{k-1}\\right) + \\frac{1}{3}$$\n%for $k = 1,\\dots,6$.\n%\n%\\subsection{Degrees of Freedom in Ideal Model}\n%\n%The first step in answering these questions is determining whether there is any degrees of freedom to each configuration or whether they are rigid. This can be determined by using established theory on rigidity of linkages and degrees of freedom. By computing the Jacobian matrix $J(v)$ of the system of constraint equations, we have the following equation for the degrees of freedom for a constraint satisfying set of coordinates $v$.\n%$$DoF(v) = 18 - rank(J(v))$$\n%When the Jacobian is of full rank 18, none of the constraints are dependent on each other and thus there is no freedom in the linkage. When testing the chair, we found there to be $0$ degrees of freedom, meaning that it is impossible to make a transition from the chair to another configuration without breaking one or more of the constraint equations. For the boat, however, one degree of freedom was found. This result shows that it is possible to deform the boat continuously while satisfying the constraints, but it is not informative as to which configurations it can deform to. In particular, we are interested in finding a path to he twist boat or another boat configuration. \n%\n\n\\section{Folding Configuration Space}\n???include??\n%\n%The number of degrees of freedom measures the rigidity of an intermediate, but some intermediates with the same number of degrees of freedom may have varying degrees of mobility. We seek to quantify an intermediate's mobility by the relative amount of movement the intermediate has for a small movement in its configuration space. Intermediates with the most mobility will move less than the less mobile intermediates for the same amount of movement in configuration space.  \n%\n%\\subsection{Methods}\n%% What is the configuration space?\n%Each octahedron intermediate is composed of 8 equilateral triangles connected to each other along edges. We make the assumption that these triangles are rigid and cannot be deformed. Furthermore, when two triangles meet at an edge, they move relative to each other as if connected by an ideal hinge. Every configuration has 6 trivial degrees of freedom corresponding to the 3 translation degrees of freedom and the 3 rotational degrees of freedom. Since we are interested in the motion of an intermediate's faces relative to each other, we remove these trivial degrees of freedom by picking a single face to fix in space. Depending on the connectivity of the triangle's edges, an intermediate \n%may still have degrees of freedom. The Octahedron intermediate (83), being a convex polyhedron, is rigid and has no non-trivial degrees of freedom as given by Cauchy's Theorem. However, this is not the case for most of the intermediates.\n%\n%We formalize the concept of the configuration space, by defining it to be the subset of an ambient parameter space that satisfies constraint equations that correspond to our assumptions. Since the are 8 faces in each intermediate and each face has 3 vertices each with 3 spacial coordinates (x,y,z), we use $\\mathbb{R}^{8\\times 3 \\times 3} = \\mathbb{R}^{72}$ as our ambient space. We then have 3 types of constraint equations: base face constraints, rigid face constraints, and hinge constraints. Every admissible configuration of an intermediate will be a point in $\\mathbb{R}^{72}$ that satisfies the constraint equations and any admissible movement of a configuration (if possible) is a continuous movement in the subset of $\\mathbb{R}^{72}$ where these constraints are satisfied. \n%\n%Since our constraint equations can all be expressed as polynomials, the configuration space which is the corresponding solution set is an Algebraic variety. The number of degrees of freedom of a configuration is the local dimension of this algebraic variety as a subset of $\\mathbb{R}^{72}$. In the case of octahedron intermediates, the number of degrees of freedom is not an informative way of classifying which intermediates are dominant as intermediates $1-11$ have $7$ degrees of freedom, $12-33$ have $5$, $34-65$ have $3$, $66-82$ have $1$ and the Octahedron (83) and Boat (84) have $0$ degrees of freedom. Thus, a different measure the mobility of a configuration is required to differentiate intermediates. It is important to note that degrees of freedom of in intermediate can theoretically change based on the region of configuration space. However, in practice we have not observed an intermediate's degrees of freedom change in this way. \n%\n%We define the \\textit{canonical configuration} of an intermediate, to be that in which each hinge forms a $180^\\circ$ angle when the hinge does not have a vertex connection at either end and in the case of a closed vertex, the hinge's angle corresponds to the Octahedral angle. In cases where the intermediate cannot form an octahedron, we can use the Boat configuration's angles instead.\n%\n%% How do we move in the configuration space?\n%Given a particular configuration $X$, if we wish to make a small move in configuration space, we first find the null space of the Jacobian matrix of the constraint equations. Since this null space corresponds to the directions in which the constraint equations are not changing, the constraints will remain satisfied. The null space can be represented by an orthonormal basis $N \\in \\mathbb{R}^{72\\times d}$, where $d$ is the number of degrees of freedom of the configuration. Then, by taking a small step of size $\\epsilon$ in each of the $d$ directions we get the configurations $X + \\epsilon N_{\\cdot,k}$. \n%% How do we measure the magnitude of a movement in configuration space?\n%\n%We define the \\textit{mobility} of a configuration to be the $L^2$ norm of the gradient of the configuration space. To approximate this, we measure the mean squared distance between each point of $X$ and $X \\pm \\epsilon N_{\\cdot,k}$ in each of the $d$ directions of $N$, take the norm, and divide by $\\epsilon$. This is given by Equation~\\ref{eq:r1} where $\\triangle_f$ refers to the $f$th face of the intermediate and $r\\left(X\\right)$ is the point we are integrating over and $r\\left(X+\\sigma \\epsilon N_{\\cdot,k}\\right)$ is the corresponding point in the altered configuration. \n%\n%\n%To explicitly define the rotation and translation of each face by the movement in configuration space, we use the algorithm given by Arun et al~\\cite{Arunetal1987}. Given two sets of points $P,P' \\in \\mathbb{R}^{3\\times n}$ in 3D space, the algorithm finds the rotation matrix $R$ and translation vector $b$ minimizing the least squares error of $P' \\approx R P + b$. By using the three vertices of face $f$ as $P$ and their perturbed values as $P'$, we use this algorithm to find the rotation matrix $R_f$ and translation vector $b_f$ to describe the rigid movement of face $f$ in the configuration space. This leads to the formulation in Equation~\\ref{eq:r3}.  \n%\\begin{figure}[h]\n%  %\\centering\n%  %\\includegraphics[width=0.61\\textwidth]{triangle_fig.png}\n%  %\\caption{Coordinates of rotated triangle for integration.}\n%  \\label{fig:tri}\n%\\end{figure}\n%\n%To make this integral easier to solve, we introduce a change of variables that enables us to integrate in the $x-y$ plane. If the the original triangle $f$ has vertices of $a', b',$ and $c'$, we consider the triangle with vertices at the coordinates $a = (0,0,0), b = (|a-b|,0,0),$ and $c = (\\alpha,\\beta,0)$ as seen in Figure~\\ref{fig:tri}. Here, the choices $\\alpha = \\frac{|a-b|^2 + |a-c|^2 - |b-c|^2 }{2|a-b|}$ and $\\beta = \\sqrt{|a-c|^2-\\alpha^2}$ yield a triangle congruent to the original. Using the Arun et al~\\cite{Arunetal1987} algorithm again, we find the rotation matrix $S_f$ and translation vector $c_f$ that gives $[a',b',c'] = S_f[a,b,c] + c_f$. Using this we perform a change of variables and integrate over $s$ and $t$. This results in an simple double integral over a quadratic function of $s$ and $t$ with constants $u,v,w \\in \\mathbb{R}^3$ as seen in Equation~\\ref{eq:r5}.\n%{\\tiny\n%\\begin{align}\n%\\mathcal{R}\\left(x\\right) &= \\frac{1}{\\epsilon}\\left(\\sum_{k=1}^d \\sum_{f=1}^8 \\int_{\\triangle_f}\\left|\\frac{r\\left(x+\\epsilon N_{\\cdot,k}\\right) - r\\left(x\\right)}{2\\sqrt{3}}\\right|^2\\right)^{\\frac{1}{2}} \\label{eq:r1}  \\\\\n%&= \\frac{1}{2\\sqrt{3}\\epsilon}\\left( \\sum_{k=1}^d \\sum_{f=1}^8 \\int_{\\triangle_f}\\left|R_fr+b_f - r\\right|^2\\right)^{\\frac{1}{2}} \\label{eq:r2} \\\\\n%&= \\frac{1}{2\\sqrt{3}\\epsilon}\\left( \\sum_{k=1}^d \\sum_{f=1}^8 \\int_{\\triangle_f}\\left|\\left(R_f-I\\right)r+b_f\\right|^2\\right)^{\\frac{1}{2}} \\label{eq:r3} \\\\\n%&= \\frac{1}{2\\sqrt{3}\\epsilon}\\left( \\sum_{k=1}^d \\sum_{f=1}^8 \\int_{0}^{\\beta}\\int_{\\frac{\\alpha}{\\beta}t}^{|a-b| + \\frac{\\alpha- |a-b|}{\\beta}t}\\left|\\left(R_f-I\\right)\\left(S_f\\begin{bmatrix} s \\\\[0.3em] t \\\\[0.3em] 0 \\end{bmatrix} + c_f\\right)+b_f\\right|^2ds dt\\right)^{\\frac{1}{2}} \\label{eq:r4} \\\\\n%&= \\frac{1}{2\\sqrt{3}\\epsilon}\\left( \\sum_{k=1}^d \\sum_{f=1}^8 \\int_{0}^{\\beta}\\int_{\\frac{\\alpha}{\\beta}t}^{|a-b| + \\frac{\\alpha- |a-b|}{\\beta}t}\\left|u + sv + tw\\right|^2ds dt\\right)^{\\frac{1}{2}} \\label{eq:r5} \n%\\end{align} \n%}    \n%% Why does the choice of the base constraint matter and how do we deal with it?\n%\n%Unfortunately, the particular choice of base face affects the mobility. To rectify this bias, we compute the mobility with each of the eight faces as the base and take the average. This gives the final mobility in Equation~\\ref{eq:r6}. \n%{\\tiny\n%\\begin{align}\n%\\mathcal{R} &= \\frac{1}{8}\\sum_{g=1}^8\\mathcal{R}_g \\\\\n%&= \\frac{1}{16\\sqrt{3}\\epsilon}\\sum_{g=1}^8\\left( \\sum_{k=1}^d \\sum_{f=1}^8 \\int_{0}^{\\beta}\\int_{\\frac{\\alpha}{\\beta}t}^{|a-b| + \\frac{\\alpha- |a-b|}{\\beta}t}\\left|u + sv + tw\\right|^2ds dt\\right)^{\\frac{1}{2}} \\label{eq:r6} \n%\\end{align}     \n%}\n%\n%\\section{Results}\n%\n%Mobility was computed for all octahedral intermediates in their canonical configuration. The perturbation parameter $\\epsilon = 10^{-6}$ was selected, but the mobility showed to be robust to both smaller and larger values. Figure~\\ref{fig:t1} outlines the results. From these calculations, it is clear that while mobility is highly correlated to degrees of freedom, mobility gives additional information about an intermediate's configuration space. Interestingly, all nets had the same mobility. Similarly, the symmetric pairs (14,16), (15,18), (19,20), (34,38), and (36,39) have matching mobility values. Of the intermediates with 5 degrees of freedom, 19 and 20 had the lowest mobility and 17 had the highest. As for intermediates with 3 degrees of freedom, 35 was the least mobile and 37 was the most mobile.        \n%\n%\\begin{figure}[h!]\n%\\label{fig:t1}\n%%\\centering\n%\\scalebox{.9}{\n%\\begin{tabular}{ l | c }\n%  Intermediate & Mobility  \\\\\n%  \\hline\\hline\n%1 &  0.20518 \\\\\n%2 &  0.20518 \\\\\n%3 &  0.20518 \\\\\n%4 &  0.20518 \\\\\n%5 &  0.20518 \\\\\n%6 &  0.20518 \\\\\n%7 &  0.20518 \\\\\n%8 &  0.20518 \\\\\n%9 &  0.20518 \\\\\n%10 & 0.20518 \\\\\n%11 & 0.20518 \\\\\\hline\n%12 & 0.18376 \\\\\n%13 & 0.18313 \\\\\n%14 & 0.18249 \\\\\n%15 & 0.18171 \\\\\n%16 & 0.18249 \\\\\n%17 & 0.18634 \\\\\n%18 & 0.18171 \\\\\n%19 & 0.18102 \\\\\n%20 & 0.18102 \\\\\n%21 & 0.18255 \\\\\n%22 & 0.18485 \\\\\\hline\n%34 & 0.14487 \\\\\n%35 & 0.14350 \\\\\n%36 & 0.14530 \\\\\n%37 & 0.14973 \\\\\n%38 & 0.14487 \\\\\n%39 & 0.14530 \\\\\\hline\n%66 & 0.07954 \\\\\\hline\n%83 & 0.00000 \\\\\n%\\end{tabular}\n%}\n%%\\caption{A table with the mobility of octahedral intermediates.}\n%\\end{figure}\n", "meta": {"hexsha": "e5205876511548de2d172508e8c850a820780a81", "size": 32971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/constraints_backup.tex", "max_stars_repo_name": "Danie1Johnson/thesis", "max_stars_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_stars_repo_licenses": ["MIT"], "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/constraints_backup.tex", "max_issues_repo_name": "Danie1Johnson/thesis", "max_issues_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_issues_repo_licenses": ["MIT"], "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/constraints_backup.tex", "max_forks_repo_name": "Danie1Johnson/thesis", "max_forks_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_forks_repo_licenses": ["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.9947229551, "max_line_length": 993, "alphanum_fraction": 0.7188741621, "num_tokens": 9635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6282790469431254}}
{"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\n\\begin{document}\n\n\\section*{Graph theory}\n\\subsection*{Terminology}\n\\begin{enumerate}\n\t\\item \n\tGraph $G(V,E)$ is set of \\emph{vertices} $V$ and \\emph{edges} $E$ (pairs of vertices). If there is an edge $(x,y) \\in E$, then $x$ and $y$ are said to be \\emph{connected}.\n\t\\item \n\tA \\emph{proper graph} is a graph with no more than one edge between each pair of vertices and in which no vertex is connected to itself.\n\t\\item \n\tProper graph in which each pair of vertices is connected is called a \\emph{complete graph}.\n\t\\item\n\tA \\emph{complement} graph $\\overline{G}$ has vertices equal to vertices of $G$ and its vertices $x$ and $y$ are connected if and only if $x$ and $y$ are not connected in $G$.\n\t\n\t\\item \n\tAn \\emph{oriented graph} is one in which the pairs in the graph are ordered.\n\t\\item\n\tThe vertices of a \\emph{k-partite graph} can be partitioned into $k$ non-empty disjoint sets in such way that there are no connections between vertices in each set.\n\t\\item \n\tThe \\emph{degree} of a vertex $x$ is the number of times $x$ is the endpoint of an edge. Then\n\t$$\\sum_{x \\in V} d(x) = 2 \\abs{E} $$\n\t\\item \n\tA \\emph{trajectory (or path)} is a sequence of vertices for which subsequent vertices are connected.\n\t\\item \n\tA \\emph{circuit} is a path that ends and starts in the same vertex.\n\t\\item \n\tA \\emph{cycle} is a circuit in which no vertex appears more than once (except the initial/final vertex).\n\t\\item\n\tIn a \\emph{connected graph} there exists a path between any two points of the graph.\n\t\\item \n\t\\emph{Tree} is a connected graph with no circuits. A connected graph with $n$ vertices is a tree if and only if it has $n-1$ edges.\n\t\\item \n\t\\emph{Euler path} is a path in which every edge of the graph appears exactly once. Likewise \\emph{Euler circuit} is a circuit in which every edge appears exactly once.\n\t\\item \n\tIf each vertex in a connected graph has even degree, then the graph contains an Euler circuit.\n\t\\item \n\tIf a connected graph has exactly two vertices with odd degree, it contains an Euler path.\n\t\\item \n\tA \\emph{Hamilton circuit} is a circuit in which each vertex appears exactly once.\n\t\\item \n\tA \\emph{planar graph} can be embedded in a plane with edges corresponding to non-intersecting lines (not necessarily straight). A planar graph with $n$ vertices has at most $3n-6$ edges.\n\t\n\\end{enumerate}\n\n\\newpage\n\\subsection*{Theorems}\n\t\\begin{enumerate}\n\t\t\\item \\textbf{Ramsey's theorem: } For positive integers $r_1,\\dots,r_k$, there exists a finite Ramsey number. \n\t\t\\begin{enumerate}\n\t\t \t\\item case $k=2$ \\\\\n\t\t \tRamsey number $R(r_1,r_2)$ is a minimal number of people at the party such that there are either $r_1$ people who know each other or $r_2$ people who do not.\n\t\t \t\\item General case for $k$ \\\\\n\t\t \tRamsey's number of $R(r_1,r_2,\\dots,r_k)$ is the minimal number of points in a complete graph whose edges are coloured with $k$ different colours, such that there exists a colour $i$ for which we can find $r_i$ vertices that are all connected with edges of colour $i$.\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item \\textbf{Kuratowski's theorem} % http://www.math.caltech.edu/~2014-15/2term/ma006b/10%20Planar3.pdf\n\t\t\\begin{enumerate}\n\t\t\t\\item $K_n$ is a complete graph with $n$ vertices and $K_{n,m}$ is a complete bipartite graph with $n$ and $m$ vertices in the subsets.\n\t\t\t\\item Graphs $K_5$ and $K_{3,3}$ are non-planar.\n\t\t\t\\item Every non-planar graph contains a subgraph which can be obtained from one of these graphs by a subdivision of its edges.\n\t\t\n\t\t\\end{enumerate}\n\t\t\\item \\textbf{Hall's marriage theorem} % http://www.math.cornell.edu/~levine/18.312/alg-comb-lecture-16.pdf\n\t\t\\begin{enumerate}\n\t\t\t\\item In a set of $n$ women and $n$ men, a woman $a_i$ is happy to be married to any man in set $A_i$ and a man is happy to marry a woman who wants to marry him. Hall's marriage theorem states that each person can be happily married if and only if the sets $A_1,A_2,\\dots,A_n$ meet the marriage condition.\n\t\t\t\\item The marriage condition states that for any subset of women $I$, the number of men whom at least one woman would be happy to marry $\\abs{\\bigcup_{i \\in I}A_i} \\geq \\abs{I}$\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\n\\subsection*{Problems}\n\\begin{enumerate}\n\t\\item\n\tProve that at least one of $G$ and $\\overline{G}$ is connected.\n\t\n\t\\item \n\t\\emph{(Dirac's theorem).} Prove that a graph with $n$ vertices contains a Hamilton cycle if the degree of each vertex is at least $n/2$. \t\n\t\n\t\\item \n\t\\emph{(Euler's formula).}  A convex polyhedron has $E$ edges, $F$ faces and $V$ vertices. Prove that $E+2=F+V$.\n\n\t\\item % http://www.math.olympiaadid.ut.ee/arhiiv/baltitee/bt1997/bw97est.pdf\n\tIn a forest each of n animals ($n \\geq 3$) lives in its own cave, and there is exactly one separate path\n\tbetween any two of these caves. Before the election for King of the Forest some of the animals\n\tmake an election campaign. Each campaign-making animal visits each of the other caves exactly\n\tonce, uses only the paths for moving from cave to cave, never turns from one path to another\n\tbetween the caves and returns to its own cave in the end of its campaign. It is also known that\n\tno path between two caves is used by more than one campaign-making animal.\n\t\\begin{enumerate}\n\t\t\\item Prove that for any prime $n$, the maximum possible number of campaign-making animals is $\\tfrac{n-1}{2}$\n\t\t\\item Find the maximum number of campaign-making animals for $n = 9$.\t\n\t\\end{enumerate}\n\t\n\t\\item % https://mks.mff.cuni.cz/kalva/usa/usoln/usol991.html\n\tCertain squares of an $n \\times n$ board are coloured black and the rest white. Every white square shares a side with a black square. Every pair of black squares can be joined by chain of black squares, so that consecutive members of the chain share a side. Show that there are at least $\\tfrac{n^2-2}{3}$ black squares.\n\t\n\t\n\t\\item % https://cms.math.ca/Competitions/OMC/archive/sol2006.pdf\n\tConsider a round-robin tournament with $2n + 1$ teams, where each team plays each other team exactly once. We say\n\tthat three teams $X$, $Y$ and $Z$, form a \\emph{cycle triplet} if $X$ beats $Y$ , $Y$ beats $Z$, and $Z$ beats $X$. There are no ties.\n\t\\begin{enumerate}\n\t\t\\item Determine the minimum number of cycle triplets possible.\n\t\t\\item Determine the maximum number of cycle triplets possible.\n\t\\end{enumerate}\n\t \n\t\\item % https://artofproblemsolving.com/wiki/index.php?title=2001_IMO_Shortlist_Problems/C3\n\tDefine a $k$-clique to be a set of $k$ people such that every pair of them are acquainted with each other. At a certain party, every pair of 3-cliques has at least one person in common, and there are no 5-cliques. Prove that there are two or fewer people at the party whose departure leaves no 3-clique remaining.\t\n\t\n\t\\item  % Latin squares\n\tFor integers $r,n$ where $r<n$ a grid $r \\times n$ is populated with numbers $1,2,\\dots,n$, such that no number occurs twice in any row or column. Prove that it is possible to append $n-r$ rows, so that the condition is still met in the new $n \\times n$ grid.\n\t\n\t\\item % https://www.imo-official.org/problems/IMO2010SL.pdf p26\n\tOn some planet, there are $2^N$ countries $(N \\geq 4)$. Each country has a flag $N$ units wide and one unit high composed of $N$ fields of size $1 \\times 1$, each field being either yellow or blue. No two countries have the same flag. We say that a set of $N$ flags is \\emph{diverse} if these flags can be arranged into an $N \\times N$ square so that all $N$ fields on its main diagonal will have the same colour. Determine the smallest positive integer $M$ such that among any $M$ distinct flags, there exist $N$ flags forming a diverse set.\n\t\n\t\\item %http://www.math.olympiaadid.ut.ee/arhiiv/valik/vv2018/tvv2018.pdf ül5\n\tLet $k$ be a positive integer. Find all positive integers $n$ for which it is possible to choose $n$ points on the sides of a triangle (different from its vertices) and connect some of them with a line such that\n\t\\begin{enumerate}\n\t\t\\item There is at least $1$ point on each side\n\t\t\\item For each pair of points $X$ and $Y$ which are on different sides of the triangle, there exists exactly $k$ points on the third side which are all connected to both $X$ and $Y$, and exactly $k$ points which are all connected to neither of $X$ or $Y$.\n\t\\end{enumerate}\n\t\n\t\\item %Valgevene (TVV2018-5-vana)\n\tA country has $n \\geq 3$ airports. Two-way flights operate between between some pairs of the airports. It is known that for each pair of airports, there exists a third one which is not directly connected to either of them. Find the maximum number of two-way flights.\n\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "8dd7b128bc20b86e69483cb3533101db442e5eba", "size": 8804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10_graphtheory.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": "10_graphtheory.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": "10_graphtheory.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": 63.3381294964, "max_line_length": 543, "alphanum_fraction": 0.735461154, "num_tokens": 2559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6282790445743865}}
{"text": "\\section{Additive Models}\nAdditive models are specific application of projection pursuit. They\nare more useful in scientific applications.\n\nIn additive models we assume that the response is linear in the\npredictors effects and that there is an additive error. This allows us to study the effect of each\npredictor separately. The model is like (\\ref{guasreg}) with\n\\[\nf(X_1,\\dots,X_p) = \\sum_{j=1}^p f_j(X_j).\n\\]\nNotice that this is projection pursuit with the projection\n\\[\n\\bg{\\alpha}_j'\\bX = X_j.\n\\]\nThe assumption made here is not as strong as in linear regression, but\nits still quite strong. It's saying that the effect of each covariate\nis additive. In practice this may not make sense.\n\nExample: In the diabetes example consider an additive model that\nmodels log(C-peptide)\nin terms of age  $X_1$ and base deficit $X_2$. The additive\nmodel assumes that for two\ndifferent ages $x_1$ and $x_1'$ the conditional expectation of $Y$\n(seen as a random variable depending on base deficit):\n\\[\n\\E(Y | X_1=x_1, X_2) = f_1(x_1) + f_2(X_2) \n\\]\nand\n\\[\n\\E(Y | X_1=x_1', X_2) = f_1(x_1') + f_2(X_2).\n\\]\nThis say that the way C-peptide depends on base deficit only varies by a\nconstant for different ages. It is not easy to disregard the\npossibility that this dependence changes. For example, at\nolder ages the effect of high base deficit can be dramatically bigger. However,\nin practice we have too make assumptions lik these in order to get\nsome kind of useful description of the data. \n\nComparing the non-additive smooth (seen above) and the additive model\nsmooth shows that it is not completely crazy to assume\nadditivity. \n\n\\centerline{\\epsfig{figure=Plots/plot-07-04.ps,angle=270,width=\\textwidth}}\n\nNotice that in the first plots the curves defined for the different\nages are different. In the second plot they are all the same.\n\nHow did we create this last plot? How did we fit the additive\nsurface. We need to estimate $f_1$ and $f_2$. We will see this in the\nnext section.\n\nNotice that one of the advantages of additive model is that no matter\nthe dimension of the covariates we know what the surface\n$f(X_1,\\dots,X_p)$ is like by drawing each $f_j(X_j)$ separately.\n\n\\centerline{\\epsfig{figure=Plots/plot-07-05.ps,angle=270,width=.8\\textwidth}}\n\n\\subsection{Fitting Additive Models: The Backfitting Algorithm}\nConditional expectations provide a simple intuitive motivation for the\nbackfitting algorithm.\n\nIf the additive model is correct then for any $k$\n\\[\n\\E\\left(\\left. Y - \\alpha - \\sum_{j\\neq k} f_j(X_j) \\, \\right| \\,X_k\n\\right) = f_k(X_k) \n\\]\nThis suggest an iterative algorithm for computing all the $f_j$. \n\nWhy? Let's say we have estimates $\\hat{f}_1,\\dots,\\hat{f}_{p-1}$ and we\nthink they are ``good'' estimates in the sense that $\\E\\{{f}_j(X_j) -\nf_j(X_j)\\}$ is ``close to 0''. Then we have that \n\\[ \n\\E\\left(\\left.Y - \\hat{\\alpha} - \\sum_{j=1}^{p-1} \\hat{f}_j(X_j) \\,\n  \\right| \\, X_p \\right) \n\\approx f_p(X_p).\n\\]\nThis means that the partial residuals $\\hat{\\epsilon} = Y -\n\\hat{\\alpha} - \\sum_{j=1}^{p-1} \\hat{f}_j(X_j) $ \n\\[\n\\hat{\\epsilon}_i \\approx f_p(X_{ip}) + \\delta_i\n\\]\nwith the $\\delta_i$ approximately IID mean 0 independent of the\n$X_p$'s. We have already discussed various ``smoothing'' techniques\nfor estimating $f_p$ in a model as the above.\n\nOnce we choose what type of smoothing technique we are using\nfor each covariate, say its defined by $S_j(\\cdot)$, we obtain an\nestimate for our \nadditive model following these steps \n\\begin{enumerate}\n\\item Define $\\f_j = \\{f_j(x_{1j}),\\dots,f_j(x_{nj})\\}'$ for all $j$.\n\\item Initialize: $\\alpha^{(0)} = \\mbox{ave}(y_i)$, $\\f_j^{(0)} = $ linear\n  estimate. \n\\item Cycle over $j=1,\\dots,p$\n\\[\n\\f_j^{(1)} = S_j\\left(\\left. \\by - \\alpha^{(0)} - \\sum_{k\\neq j}\n  \\mathbf{f}^{(0)}_k\n  \\, \\right| \\bx_j \\right)\n\\]\n\\item Continue previous step until functions ``don't change'', for\n  example until \n\\[\n\\max_{j} \\left|\\left| \\f_j^{(n)} - \\f_j^{(n-1)} \\right|\\right| < \\delta\n\\]\nwith $\\delta$ is the smallest number recognized by your computer. In\nmy computer using S-Plus its: \\begin{verbatim} .Machine$double.eps = 2.220446e-16 \\end{verbatim} %$\n\n\n\\end{enumerate}  \n\nThings to think about:\n\nWhy is this algorithm valid? Is it the solution to some minimization\ncriterion?  Its not MLE or LS. \n\n\\subsection{Justifying the backfitting algorithm}\nThe backfitting algorithm seems to make sense. We can say that we have\ngiven an intuitive justification.\n\n\nHowever statisticians usually like to have more than this. In most\ncases we can find a ``rigorous'' justification. In many cases\nthe assumptions made for the ``rigorous'' justifications too work are\ncarefully chosen so that we get the answer we want, in this case that the\nback-fitting algorithm ``converges'' to the ``correct'' answer.\n\nIn the GAM book, H\\&T find three ways to justify it: Finding\nprojections in $L^2$ function spaces, minimizing certain criterion\nwith solutions from reproducing-kernel Hilbert spaces, and as\nthe solution to penalized least squares. We will look at this last\none. \n\n\nWe extend the idea of penalized least squares by considering the\nfollowing criterion \n\\[\n\\sum_{i=1}^n \\left\\{ y_i - \\sum_{j=1}^p f_j(x_{ij}) \\right\\}^2 +\n  \\sum_{j=1}^p \\lambda_j \\int \\{f_j''(t)\\}^2 \\, dt\n\\]\nover all p-tuples of functions $(f_1,\\dots,f_p)$ that are twice\ndifferentiable. \n\nAs before we can show that the solution to this problem is a p-tuple\nof cubic splines with knots ``at the data'', thus we may rewrite the\ncriterion as\n\\[\n\\left(\\by - \\sum_{j=1}^p \\f_j \\right)'\\left(\\by - \\sum_{j=1}^p \\f_j\n\\right) + \\sum_{j=1}^p \\lambda_j \\f_j \\bK_j \\f_j\n\\]\nwhere the $\\bK_j$s are penalty matrices for each predictor defined\nanalogously to the $\\bK$ of section 3.3.\n\nIf we differentiate the above equation with respect to the function\n$\\f_j$ we obtain $-2(\\by - \\sum_k \\f_k) + 2 \\lambda_j \\bK_j \\f_j =\n0$. The $\\hat{\\f}_j$'s that solve the above equation must satisfy:\n\\[\n\\hat{\\f}_j = \\left(\\bI + \\lambda_j \\bK_j\\right)^{-1}\\left(\\by -\n\\sum_{k\\neq j} \\hat{\\f}_k\\right), j=1,\\dots,p \n\\]\nIf we define the smoother operator $\\bS_j = \\left(\\bI + \\lambda_j\n\\bK_j\\right)^{-1}$ we can write out this equation in matrix notation as\n\\[\n\\left(\n\\begin{array}{cccc}\n\\bI&\\bS_1&\\dots&\\bS_1\\\\\n\\bS_2&\\bI&\\dots&\\bS_2\\\\\n\\vdots&\\vdots&\\ddots&\\vdots\\\\\n\\bS_p&\\bS_p&\\dots&\\bI\n\\end{array}\n\\right)\n\\left(\n\\begin{array}{c}\n\\f_1\\\\\n\\f_2\\\\\n\\vdots\\\\\n\\f_p\n\\end{array}\n\\right)\n=\n\\left(\n\\begin{array}{c}\n\\bS_1 \\by\\\\\n\\bS_2 \\by\\\\\n\\vdots\\\\\n\\bS_p \\by\n\\end{array}\n\\right)\n\\]\nOne way to solve this equation is to use the Gauss-Seidel algorithm\nwhich in turn is  equivalent to\nsolving the back-fitting algorithm. See Buja, Hastie \\& Tibshirani\n(1989) Ann. Stat. 17, 435--555 for details.\n\nRemember that \n that for any set of linear smoother\n\\[\n\\hat{\\f}_j = \\bS_j\\by\n\\]\nwe can argue in reverse that it minimizes some penalized least squares\ncriteria of the form\n\\[\n(\\by - \\sum_j\\f_j)'(\\by - \\sum_j\\f_j) + \\sum_j \\f_j'(\\bS_j^{-} - I)\\f_j\n\\]\nand conclude that it is the solution to some penalized least squared\nproblem.\n\n\\subsection{Standard Error}\nWhen using {\\tt gam()} in S-Plus we get point-wise standard\nerrors. How are these obtained?\n\nNotice that our estimates \n$\\hat{\\f}_j$ are no longer of the form $\\bS_j \\by$ since we have used a\ncomplicated backfitting algorithm. However, at convergence we can\nexpress $\\hat{\\f}_j$ as $\\bR_j \\by$ for some $n \\times n$ matrix\n$\\bR_j$. In practice this $\\bR_j$ is obtained from the last calculation\nof the $\\hat{\\f}_j$'s but finding a closed form is rarely\npossible. \n\nWays of constructing confidence sets is not straight forward, and (to the best\nof my knowledge) is an open area of research.\n\n\n\n", "meta": {"hexsha": "fc0777bc2443b36c788718f4cc59f4756413a75b", "size": 7627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-07-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-07-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-07-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": 34.0491071429, "max_line_length": 99, "alphanum_fraction": 0.7170578209, "num_tokens": 2394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.6282790442533408}}
{"text": "\\section{Recurrences}\n\n\\begin{frame}{Recurrences}\n  \\[\n\tT(n) = aT(n/b) + f(n) \\quad (a > 0, b > 1)\n  \\]\n\n  \\begin{equation*}\n\t\\left.\\begin{aligned}\n\t  f(n) \\\\\n\t  af(\\frac{n}{b}) \\\\\n\t  a^2f(\\frac{n}{b^2}) \\\\\n\t  \\vdots \\\\\n\t  a^{\\log_b^n}f(1) = n^{\\log_b^a}\n\t\\end{aligned}\\right\\}\n\t\\pause\n\t\\sum = \\left\\{\\begin{aligned}\n\t  n^{\\log_b^a}\t\\quad & q > 1 \\\\\n\t  n^{\\log_b^a}\\log n \\quad & q = 1 \\\\\n\t  f(n)\t\\quad & q < 1 \\quad \\\\\n\t\\end{aligned}\\right.\n\t\\pause\n\t\\quad \\left.\\begin{aligned}\n\t  f(n) &= O(n^{E-\\epsilon}) \\\\\n      f(n) &= \\Theta(n^E) \\\\\n      f(n) &= \\Omega(n^{E+\\epsilon}) \n\t\\end{aligned}\\right.\n  \\end{equation*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Solving recurrences (Problem 1.2.13, 1.2.16)}\n  \\begin{columns}\n\t\\column{0.40\\textwidth}\n\t  \\begin{enumerate}\n\t\t\\item $\\Theta(n^{\\log_3^2})$\n\t\t\\item \\textcolor{red}{$\\Theta(\\log^2 n)$}\n\t\t\\item $\\Theta(n)$\n\t\t\\item $\\Theta(n \\log n)$\n\t\t\\item \\textcolor{red}{$\\Theta(n \\log^2 n)$}\n\t\t\\item $\\Theta(n^2)$\n\t\t\\item $\\Theta(n^{\\frac{3}{2}}\\log n)$\n\t\t\\item $\\Theta(n)$\n\t\t\\item $\\Theta(n^{c+1})$\n\t\t\\item $\\Theta(c^{n+1})$\n\t\t\\item \\textcolor{blue}{$\\Theta(n)$}\n\t  \\end{enumerate}\n\t\\column{0.60\\textwidth}\n\t  \\[\n\t\tT(n) = T(n/2) + \\log n\n\t  \\]\n\n\t  \\[\n\t\tT(n) = 2T(n/2) + n\\log n\n\t  \\]\n\n\t\\pause\n\t\\begin{alertblock}{Reference}\n\t  \\[\n\t\tf(n) = \\Theta(n^{\\log_b^a} \\lg^{k}n) \\Rightarrow \\Theta(n^{\\log_b^a} \\lg^{k+1}n)\n\t  \\]\n\t\\end{alertblock}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Solving recurrences (Problem 1.2.13, 1.2.16)}\n  \\[\n\tT(n) = T(n/2) + T(n/4) + T(n/8) + n\n  \\]\n\n  \\pause\n  \\vspace{0.30cm}\n  \\centerline{By recursion-tree.}\n\n  \\pause\n  \\vspace{0.50cm}\n  \n  \\centerline{Exercise: Prove it by Mathematical Induction.}\n\n  \\pause\n  \\begin{alertblock}{Reference}\n\t``On the Solution of Linear Recurrence Equations'' by Akra \\& Bazzi, 1996.\n\n\t\\[\n\t  T(n) = \\sum_{i=1}^{k} a_i T(n/b_i) + f(n)\n\t\\]\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Gaps (Problem 1.2.16)}\n  \\[\n\tT(n) = 2T(n/2) + \\frac{n}{\\log n} \\pause = \\Theta(n \\log \\log n)\n  \\]\n\n  \\pause\n\n  The regularity condition in Case 3:\n  \\[\n\tbf(n/c) \\le cf(n), \\text{ for some } c < 1 \\text{ and sufficiently large } n\n  \\]\n\n  \\[\n\tT(n) = T(n/2) + n(2 - \\cos n)\n  \\]\n\n  \\[\n\tn^{E} = n^0 \\quad f(n) = n(2 - \\cos n) = \\Omega(n^{0 + \\epsilon})\n  \\]\n\n  \\pause\n  \\[\n\tn = 2\\pi k (k \\text{ odd}) \\Rightarrow c \\ge \\frac{3}{2}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.2.15)}\n  \\begin{align*} \n\t\\text{T}(n) &= \\sqrt{n}\\ \\text{T}(\\sqrt{n})+n \\\\\n\t\t&= n^{\\frac{1}{2}}\\ \\text{T}\\left(n^{\\frac{1}{2}} \\right )+n \\\\\n\t\t&= n^{\\frac{1}{2}}\\left( n^{\\frac{1}{2^2}}\\ \\text{T}\\left(n^{\\frac{1}{2^2}} \\right )+n^{\\frac{1}{2}} \\right )+n\\\\\n\t\t&= n^{\\frac{1}{2}+\\frac{1}{2^2}}\\ \\text{T}\\left(n^{\\frac{1}{2^2}}\\right ) +2n\\\\\n\t\t&= n^{\\frac{1}{2}+\\frac{1}{2^2}}\\left(n^{\\frac{1}{2^3}}\\ \\text{T}\\left(n^{\\frac{1}{2^3}}\\right ) +n^{\\frac{1}{2^2}} \\right )+2n\\\\\n\t\t&= n^{\\frac{1}{2}+\\frac{1}{2^2}+\\frac{1}{2^3}}\\ \\text{T}\\left(n^{\\frac{1}{2^3}}\\right ) +3n\\\\ \n\t\t&= \\cdots \\\\ \n\t\t&= n^{\\sum_{i=1}^{k}\\frac{1}{2^i}}\\ \\text{T}\\left(n^{\\frac{1}{2^k}}\\right ) +kn\\\\ \n  \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.2.15)}\n  \\[\n\tn^{\\frac{1}{2^k}} = 2 \\Rightarrow k = \\log\\log n\n  \\]\n\n  \\pause\n\n  \\begin{align*} \n\t\\text{T}(n) &= n^{\\sum_{i=1}^{k}\\frac{1}{2^i}}\\ \\text{T}\\left(n^{\\frac{1}{2^k}}\\right ) +kn\\\\ \n\t\t&=n^{\\sum_{i=1}^{\\log\\log n}\\frac{1}{2^i}}\\ \\text{T}(2) + n \\log\\log n\\\\ \n  \\end{align*}\n\n  \\pause\n  \\[\n\t\\sum_{i=1}^{\\log_2\\log_2(n)}\\frac{1}{2^i} < 1 \\Rightarrow T(n) = \\Theta(n \\log \\log n)\n  \\]\n\n  \\pause\n  \\vspace{0.30cm}\n  \\centerline{Exercise: Prove it by Mathematical Induction.}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{(Problem 1.2.15)}\n  \\[\n\tT(n) = \\sqrt{n} T(\\sqrt{n}) + n\n  \\]\n\n  \\[\n\tn = 2^k \\quad \\sqrt{n} = 2^{k/2} \\quad k = \\log n\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "25c04e62c378b6908fc57b0daea1bd2162b2a27b", "size": 3896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-math-dc-20170329/sections/recurrences.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/recurrences.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/recurrences.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": 24.049382716, "max_line_length": 131, "alphanum_fraction": 0.4969199179, "num_tokens": 1761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6281651740161535}}
{"text": "% Copyright (C) He Guanyuming 2020\n% The file is licensed under the MIT license.\n\n\\section{Set Theory}\n\n\\subsection{Fundamentals}\n\\declareexercise{3.1.1}\n\\begin{proof}\nReflexive: $\\forall x \\in S, x \\in S$.\n\nSymmetric: \n\\begin{align*}\nX = Y\n&\\Longleftrightarrow \\\\\n\\forall x \\in X, x \\in Y \\wedge \\forall x \\in Y, x \\in X\n&\\Longleftrightarrow \\\\\nY = X\n\\end{align*}\n\nTransitive:\n$X=Y \\Longrightarrow \\forall x \\in X, x \\in Y$. Because $x \\in Y$ and $Y = Z$, we can conclude that \n$\\forall x \\in X, x \\in Z$. Conduct the process from inversely, we can get $\\forall x \\in Z, x \\in X$. \nTherefore, $X=Z$.\n\\end{proof}\n\nThe reason for the content beneath Axiom 3.2 is clearly demonstrated in the proof of Lemma 3.1.6.\n\nIn Remarks 3.1.9, there are three ``Why''s. The reason can be concluded as: Because of the ``if and only \nif'' in Axiom 3.3, or more precisely, ``only if'', if $x$ is a element in one of such sets, $x$ must \n$=a$ or $b$. And because of the ``if'', $x$ is thus in another set. So the two sets are equal according \nto Definition 3.1.4.\n\n\\declareexercise{3.1.2}\n\\begin{proof}\nAccording to Axiom 3.2, $\\varnothing$ exists, and is thus an object as stated by Axiom 3.1. Therefore, \nby Axiom 3.3, $\\{\\varnothing\\}$ also exists. $\\varnothing$ is an element of $\\{\\varnothing\\}$, but it \nis not an element of $\\varnothing$ because any object $\\notin$ $\\varnothing$.\n\nFor the same reason, any set that contains element(s) is not the same set as $\\varnothing$. Furthermore, \nthere exists an object $\\{\\varnothing\\}$ (Axiom 3.3 and 3.1), which is an element of \n$\\{\\varnothing, \\{\\varnothing\\}\\}$, but which is not an element of $\\{\\varnothing\\}$. So the two sets \nare not equal.\n\\end{proof}\n\n\\paragraph{Remarks 3.1.12}\n\\begin{proof}\nLet $x \\in A'\\cup B$. $x \\in A' \\Longrightarrow x \\in A$ And if $x \\notin A'$, $x \\in B$. So either way \n$x \\in A\\cup B$ and vice versa.\n\\end{proof}\n\n\\declareexercise{3.1.3}\n\\begin{proof}\n(1)\n\\[\nx \\in A \\cup B \\equiv (x \\in A \\vee x \\in B)\n\\]\n\\[\nx \\in A \\Longrightarrow x \\in B \\cup A\n\\]\n\\[\nx \\in B \\Longrightarrow x \\in B \\cup A\n\\]\nSo $x \\in A \\cup B \\Longrightarrow x \\in B \\cup A$. And vice versa.\n\n(2)\n$x \\in A \\Rightarrow x \\in A \\cup A$ and $x \\in A \\cup A \\Rightarrow x \\in A$.\n\n(3)\n\\begin{align*}\nx \\in A \\cup \\varnothing \n&\\Longrightarrow \\\\\nx \\in A \\vee x \\in \\varnothing\n&\\Longrightarrow \\\\\nx \\in A \\tag{$\\forall a, a \\notin \\varnothing$}\n\\end{align*}\n\nAnd obviously $x \\in A \\Rightarrow x \\in A \\cup \\varnothing$. So $A \\cup \\varnothing = A$.\n\nBy transitivity of equality, and commutativity of pairwise union, we can conclude the others.\n\\end{proof}\n\n\\paragraph{Examples 3.1.17}\n\\begin{proof}\n\\[\n\\forall x(x\\in A \\Longrightarrow x \\in A)\n\\]\n\nAnd\n\\[\n\\forall x(x \\in \\varnothing \\Longrightarrow x \\in A)\n\\]\nis vacuously true.\n\\end{proof}\n\n\\declareexercise{3.1.4}\n\\begin{proof}\n(1) \nOn one hand,\n\\[\nA \\subseteq B \\equiv \\forall x(x \\in A \\Longrightarrow x \\in B)\n\\]. \nOn the other hand,\n\\[\nB \\subseteq A \\equiv \\forall x(x \\in B \\Longrightarrow x \\in A)\n\\].\nThus $A=B$.\n\n(2)\nFirst, we prove that $A \\subsetneq B \\Longrightarrow \\exists x(x \\in B \\wedge x \\notin A)$. Suppose the \ncontradiction, that is, $\\forall x(x\\in B \\Longrightarrow x \\in A)$, which is impossible since \n$(A \\subseteq B \\equiv \\forall x(x\\in A \\Longrightarrow x \\in B))\\wedge A \\neq B$.\n\nAccording to what's proven in the book, \n$A \\subsetneq B \\wedge B \\subsetneq C \\Longrightarrow A \\subseteq C$.\n\nNow we prove that $\\exists x(x \\in C \\wedge x \\notin A)$. Since $x \\in A \\Longrightarrow x \\in B$, \n$x \\notin B \\Longrightarrow x \\notin A$. Because $B \\subsetneq C$, \n$\\exists x(x \\in C \\wedge x \\notin B)$, and thus for such $x$, $ x \\notin A$. Then $A \\neq C$.\n\nSo $A \\subsetneq C$. \n\\end{proof}\n\n\\paragraph{Axiom 3.5}\n(1) Because $x \\in \\{x \\in A : P(x)\\} \\Rightarrow x \\in A$.\n\n(2) Because both $\\in$ and $P(x)$ obey the axiom of substitution.\n\n\\declareexercise{3.1.5}\n\\begin{proof}\nFirst we prove that $A \\subseteq B \\equiv A \\cup B = B$. On one hand,\n\\begin{align*}\nA \\subseteq B \n&\\equiv \\\\\n\\forall x(x \\in A \\Longrightarrow x \\in B)\n&\\Longrightarrow \\\\\n\\forall x((x \\in A \\vee x \\in B) \\Longrightarrow x \\in B)\n&\\equiv \\\\\nA \\cup B = B\n\\end{align*}.\n\nOn the other hand,\n\\[\n\\forall x((x \\in A \\vee x \\in B) \\Longrightarrow x \\in B) \\Longrightarrow\n\\forall x(x \\in A \\Longrightarrow x \\in B)\n\\]. The statement is therefore proven.\n\nThen we prove that $A \\subseteq B \\equiv A \\cap B = A$. On one hand, \n\\begin{align*}\n(A \\cap B = A \\equiv \\forall x(x \\in A \\wedge x \\in B \\equiv x \\in A)) \n&\\Longrightarrow \\\\\n(\\forall x(x \\in A \\Rightarrow x \\in B) \\equiv (A \\subseteq B))\n\\end{align*}.\n\nOn the other hand, \n\\[\n\\forall x(x\\in A\\wedge x \\in B \\Longrightarrow x \\in A)\n\\]\nis always true (Vacuously true if $x \\notin B$).\n\nLogical equality is transitive, and thus all of the three statements are equal.\n\\end{proof}\n\n\\paragraph{Proposition 3.1.28} (Exercise 3.1.6) \\label{exercise3.1.6}\n\\begin{proof}\n(a) The two are identical to \n\\[\n\\forall x(x \\in A \\vee x \\in \\varnothing \\equiv x \\in A)\n\\], \nand \n\\[\n\\nexists x(x \\in A \\wedge x \\in \\varnothing)\n\\], \nwhich are all true since $\\forall x(x \\notin \\varnothing)$.\n\n(b) We have $A \\subseteq X$. According to what we have proven in \n\\hyperref[exercise3.1.5]{Exercise 3.1.5}, the two statements are all true.\n\n(c) Obvious since \n\\[\n\\forall x(x \\in A \\vee x \\in A \\equiv x \\in A)\n\\]\nand \n\\[\n\\forall x(x \\in A \\wedge x \\in A \\equiv x \\in A)\n\\]\n\n(d) All true since \\emph{logical or} and \\emph{logical and} are commutative.\n\n(e) See Lemma 3.1.13. I believe that this can be concluded by the fact that \\emph{logical or} and \n\\emph{logical and} are also associative.\n\n(f) \nFirst we prove the latter. On one hand, suppose \n\\[\nx \\in A \\cup (B \\cap C)\n\\] is ture.\n\nIf $x \\in A$, then $x \\in$ both $A \\cup B$ and $A \\cup C$, and thus $\\in$ \n$(A \\cup B)\\cap(A \\cup C)$.\n\nIf $x \\notin A$, then $x \\in B \\cap C$, then $x \\in$ both $A \\cup B$ and $A \\cup C$, and thus $\\in$ \n$(A \\cup B)\\cap(A \\cup C)$.\n\nOn the other hand, \nsuppose \n\\[\nx \\in (A \\cup B)\\cap(A \\cup C)\n\\] is true.\n\nIf $x \\in A$, obviously $x \\in A \\cup (B \\cap C)$.\n\nIf $x \\notin A$, then $x$ must $\\in B \\cap C$, and thus also $\\in A \\cup (B \\cap C)$.\n\nNow we prove the former. On one hand, suppose\n\\[\nx \\in A \\cap (B \\cup C)\n\\] is true.\n\nIf $x \\in A \\wedge x \\in B$, then $x \\in A \\cap B$, and thus $\\in (A \\cap B)\\cup(A \\cap C)$.\n\nIf $x \\notin A \\vee x \\notin B$, then\n\\begin{enumerate}\n\\item if $x \\notin A$, this is impossible.\n\\item if $x \\in A$, then $x \\notin B$. But $x \\in B \\cup C$, so $x \\in C$. And thus \n$x \\in A \\cap C \\Rightarrow x \\in (A \\cap B)\\cup(A \\cap C)$.\n\\end{enumerate}\n\nOn the other hand, suppose that \n\\[\nx \\in (A \\cap B)\\cup(A \\cap C)\n\\] is true.\n\nFirst we can see that $x \\in A$. \n\nIf $x \\in B$, then $x \\in B \\cup C$, and thus $\\in A \\cap (B \\cup C)$.\n\nIf $x \\notin B$, then $x \\in C$. So $x \\in B \\cup C$, and thus $\\in A \\cap (B \\cup C)$.\n\n(g)\nNow we prove the former: On one hand, suppose that \n\\[\nx \\in A \\cup (X-A)\n\\].\n\nIf $x \\in A$, then $x \\in X$ since $A \\subseteq X$.\n\nIf $x \\notin A$, then $x \\in X-A$, and thus also $\\in X$.\n\nOn the other hand, suppose that \n\\[\nx \\in X\n\\]\n\nIf $x \\in A$, then $x \\in A \\cup (X-A)$.\n\nIf $x \\notin A$, then $x \\in X-A$, and thus $\\in A \\cup (X-A)$.\n\n(h)\n$x \\in X - A$ requires $x \\notin A$. So $\\forall x(x \\in A \\cap (X-A))$ is always false. \nThus\n\\[\n\\forall x(x \\in A \\cap (X-A) \\Longleftrightarrow x \\in \\varnothing)\n\\] (vacuously true).\n\\end{proof}\n\n\\declareexercise{3.1.7}\n\\begin{proof}\n(1)\n$\\forall x(x \\in A \\cap B \\Longrightarrow x \\in A)$. Similarly, we can prove that \n$A \\cap B \\subseteq B$. (This can also be achieved via the commutativity).\n\n(2) \nOn one hand, suppose that \n\\[\nC \\subseteq A \\wedge C \\subseteq B\n\\] is true.\nThen, \n\\[\n\\forall x(x \\in C \\Longrightarrow x \\in A \\wedge x \\in B \\Longrightarrow x \\in A \\cap B)\n\\].\n\nOn the other hand, suppose that\n\\[\nC \\subseteq A \\cap B\n\\] is true.\nThen, \n\\[\n\\forall x(x \\in C \\Longrightarrow x \\in A \\wedge x \\in B)\n\\].\nThat is, $C \\subseteq A \\wedge C \\subseteq B$.\n\n(3) It is immediately given by \n\\[\n\\forall x(x \\in A \\Longrightarrow x \\in A \\cup B)\n\\]. \nSince $\\cup$ is commutative, the latter case is proven.\n\n(4) On one hand, suppose that $A \\subseteq C \\wedge B \\subseteq C$ and let $x \\in A \\cup B$.\n\nIf $x \\in A$, then $x \\in C$.\n\nIf $x \\notin A$, then $x \\in B$, and thus $x \\in C$.\n\nOn the other hand, suppose that $A \\cup B \\subseteq C$. Then, \n\\[\n\\forall x(x \\in A \\Longrightarrow x \\in A \\cup B \\Longrightarrow x \\in C)\n\\]\n\\[\n\\forall x(x \\in B \\Longrightarrow x \\in A \\cup B \\Longrightarrow x \\in C) \\qedhere\n\\].\n\\end{proof}\n\n\\declareexercise{3.1.8}\n\\begin{proof}\nThe former: On one hand, \nSuppose that \n\\[\nx \\in A \\cap (A \\cup B)\n\\].\n\nIf $x \\in A$, then $x \\in A$.\n\nIf $x \\notin A$, this is impossible.\n\nOn the other hand, suppose that $x \\in A$.\nThen $x \\in A \\wedge x \\in (A \\cup B)$, so $x \\in A \\cap (A \\cup B)$.\n\nThe latter: On one hand, suppose that $x \\in A \\cup (A \\cap B)$.\n\\[\nx \\in A \\Longrightarrow x \\in A.\n\\]\n\\[\nx \\notin A \\Longrightarrow x \\in (A \\cap B) \\Longrightarrow x \\in A\n\\].\n\nOn the other hand, Suppose that $x \\in A$, then $x \\in A \\cup (A \\cap B)$.\n\\end{proof}\n\n\\declareexercise{3.1.9}\n\\begin{proof}\n\\begin{lem} \\label{lem10}\n\\[\n\\nexists x\\forall B\\forall A(x \\in A \\wedge x \\in B \\wedge A \\cap B = \\varnothing)\n\\]\n\\end{lem}\n\\begin{proof}\nSuppose the negation: $x \\in A \\wedge x \\in B \\wedge A \\cap B = \\varnothing$, then \n$x \\in A \\cap B$, and thus $\\in \\varnothing$, which is impossible.\n\\end{proof}\n\nThe former: On one hand, suppose that $x \\in A$. Then $x \\notin B$ by Lemma \\ref{lem10}. And\n\\[\nx \\in A \\Longrightarrow x \\in A \\cup B \\Longrightarrow x \\in X\n\\].\nSo $x \\in (X-B)$.\n\nOn the other hand, suppose that $x \\in (X-B)$, then $x \\in A \\cup B$. But $x \\notin B$, so $x \\in A$ by \nLemma \\ref{lem10}.\n\nThe latter is immediately proven since $\\cap,\\cup$ are commutative.\n\\end{proof}\n\n\\paragraph{Exercise 3.1.10} \\label{exercise3.1.10}\n\\begin{proof}\nFirstly we prove that $(A-B)\\cap (A\\cap B) = \\varnothing$.\n\n$x \\in (A\\cap B)$ gives $x \\in B$, but $x \\in (A-B)$ gives $x \\notin B$. So the two statements can not \nbe true simultaneously. Which means \n\\[\nx\\in (A-B)\\cap (A\\cap B) \\Longrightarrow x \\in \\varnothing\n\\]\n\nAnd obviously \n\\[\nx\\in (A-B)\\cap (A\\cap B) \\Longleftarrow x \\in \\varnothing\n\\].\n\nSimilarly we can conclude all of the three sets are disjoint by the fact that $\\nexists x \\in$ either \ntwo of the three sets.\n\nNow we are showing that their union is $A \\cup B$.\n\nOn one hand, suppose that \n\\[\nx \\in (A-B)\\cap(A\\cap B)\\cap(B-A)\n\\].\n$x$ can at most be in one of these sets since they are disjoint.\nIf $x \\in A$, then $x \\in A \\cup B$.\n\nIf $x \\notin A$, then $x \\in (B-A)$, and thus $x \\in B$. So $x \\in A \\cup B$.\n\nOn the other hand, suppose that $x \\in A \\cup B$.\nThen $x$ either\n\\begin{enumerate}\n\\item $\\in A$, but $\\notin B$, or\n\\item $\\in B$, but $\\notin A$, or\n\\item $\\in$ both $A,B$.\n\\end{enumerate}\n\nIf (1), then $x \\in (A-B)$.\n\nIf (2), then $x \\in (B-A)$.\n\nIf (3), then $x \\in A\\cap B$.\n\nIn conclusion, we can see that $x \\in (A-B)\\cap(A\\cap B)\\cap(B-A)$.\n\\end{proof}\n\n\\paragraph{Exercise 3.1.11} \\label{exercise3.1.11}\n\\begin{proof}\nLet $S$ be a set.\nLet $P(x,y)$ be a property pertaining to $x \\in S$ and any object $y$, and is true iff \n$Q(x) \\wedge y = x$, where $Q(x)$ is a property pertaining to $x \\in S$.\n\nAccording to Axiom 3.6, there exists a set $Z$, such that \n$y \\in Z \\equiv x \\in S \\wedge P(x,y)$, which means $y \\in Z \\equiv x \\in S \\wedge Q(x) \\wedge x = y$. \nSo is the axiom of specification proven.\n\\end{proof}\n\n\\subsection{Russell's paradox}\nI think one major reason for building such a ``cumbersome'' axiom system is to restrict the way to \nconstruct sets. We can not construct just any set we want, there only exist certain kinds of sets.\n\n\\declareexercise{3.2.1}\n\\begin{proof}\n(Axiom 3.2) To prove the existence of the empty set, simply choose a property that is false for all \nobjects.\n\n(Axiom 3.3) To prove the existence of a \\emph{pair set}, say $\\{a,b\\}$, let $P(x)$ be a property \npertaining to any object $x$, and is true iff $x = a \\vee x = b$.\n\n(Axiom 3.4) Let the property be $P(x): x \\in A \\vee x \\in B$.\n\n(Axiom 3.5) Let the property be $Q(x): x \\in A \\wedge P(x)$, where $P(x)$ is a property pertaining to \nelements of $A$.\n\n(Axiom 3.6) Let the property be $Q(y): P(x,y)$ is true for some $x \\in A$.\n\\end{proof}\n\n\\declareexercise{3.2.2}\n\\begin{proof}\n(1)\nSuppose the negation: $\\exists A(A \\in A)$. Then by Axiom 3.3, construct a set $B:= \\{A\\}$. $A$ is \nthe only element in $B$. $A$ is a set. $A$ is not disjoint from $B$, for $A \\in A \\wedge A \\in B$. \n\n(2)\nSuppose the negation: $A \\in B \\wedge B \\in A$. Construct a set $S: \\{A,B\\}$. $A$ is an element of \n$S$. $A$ is a set. $A$ is not disjoint from $S$, for $B \\in A \\wedge B \\in S$.\n\\end{proof}\n\n\\declareexercise{3.2.3}\nOn one hand, if Axiom 3.8 is true, we can choose a property $P(x)$ which is true for all objects. Thus \nwe have $\\Omega$.\n\nOn the other hand, if there exists such a set as $\\Omega$, we can use Axiom 3.5 to construct any set \nwe want from it. (e.g. If we want a set to have these elements: $a,b,\\dots$, we can let \n$P(x):= x = a \\vee x = b, \\vee \\dots$.)\n\n\\subsection{Functions}\nIn Example 3.3.3, Tao asked why $x'=x \\Rightarrow f(x')=f(x)$. The reason is, the property $P(x,y)$ \nobeys the axiom of substitution. Thus, $P(x,y)\\equiv P(x',y)$. According to definition, since \n$x' \\in X$, $y$ is unique.\n\nIn Example 3.3.9, Tao asked why all functions whose domain is $\\varnothing$ and whose range is the same \nare equal. The reason is $x \\in \\varnothing \\Longrightarrow f(x) = g(x)$ is vacuously true.\n\n\\declareexercise{3.3.1}\n\\begin{proof}\nThe properties of equality are all true since in definition, we only use $f(x) = g(x)$, in which the $=$ \nobeys these rules, plus the fact that the output is unique.\n\nThen the substitution:\n\\begin{align*}\nf = \\overset{\\sim}{f} &\\Longrightarrow \\\\\nf(x) = \\overset{\\sim}{f}(x) &\\Longrightarrow \\\\\ng(f(x)) = g(\\overset{\\sim}{f}(x))\n\\end{align*}. \nAnd then $\\overset{\\sim}{g}(\\overset{\\sim}{f}(x)) = g(\\overset{\\sim}{f}(x)) = g(x)$.\n\\end{proof}\n\n\\declareexercise{3.3.2}\n\\begin{proof}\nThe former: Suppose the negation:\n\\[\n\\exists x \\exists x'(g(f(x)) = g(f(x')) \\wedge x \\neq x')\n\\]\nThen, \n\\begin{align*}\ng(f(x)) = g(f(x')) &\\Longrightarrow \\\\\nf(x)= f(x') \\tag{$g$ is injective} &\\Longrightarrow \\\\\nx = x' \\tag{$f$ is injective}\n\\end{align*}, \nwhich is impossible.\n\nThe latter: Suppose the negation:\n\\[\n\\exists z \\forall x(z \\in Z \\wedge g \\circ f(x) \\neq z) \n\\]\nThen, we can conclude that $\\exists y \\forall x(y \\in Y \\wedge y \\neq f(x))$, since $g$ is surjective. \nThis is impossible as $f$ is surjective.\n\\end{proof}\n\n\\declareexercise{3.3.3}\n\\begin{proof}\n\\begin{large}\n\\textbf{Attention:}\n\\end{large}\nDifferent interpretations for injectivity may result in different conclusions. \nI have asked a question at \n\\href{https://math.stackexchange.com/questions/3800240/how-to-interpret-the-definition-of-injectivity}{Stack Exchange} regarding this problem.\n\nLet the range be $Y$, and the function be $f$.\nInjectivity:\n\\[\n\\forall x'\\forall x((x \\in \\varnothing \\wedge x' \\in \\varnothing) \\Longrightarrow\n(x \\neq x' \\Longrightarrow f(x) \\neq f(x')))\n\\], \nwhich is always vacuously true.\n\nSurjectivity:\n\\[\n\\forall y(y \\in Y \\Longrightarrow \\exists x(x \\in \\varnothing \\wedge f(x) = y))\n\\], \nwhich is false if $Y \\neq \\varnothing$, and which is vacuously true if $Y = \\varnothing$.\n\nBijective: True if $Y = \\varnothing$.\n\\end{proof}\n\n\\declareexercise{3.3.4}\n\\begin{proof}\nThe former: $f,\\overset{\\sim}{f}$ have the same range and domain. \n\\[\n\\forall x(g \\circ f = g \\circ \\overset{\\sim}{f} \\Longrightarrow g(f(x)) = g(\\overset{\\sim}{f}(x)))\n\\]\nWe know that $g$ is injective, so $\\forall x \\in X, f(x) = \\overset{\\sim}{f}(x)$. Thus \n$f = \\overset{\\sim}{f}$.\n\nIt is not true if $g$ is not injective. Consider an extreme condition, where $g$ is constant. So \nwhatever $f,\\overset{\\sim}{f}$ are, $g \\circ f = g \\circ \\overset{\\sim}{f}$ are always equal.\n\nThe latter: Suppose the negation:$g \\neq \\overset{\\sim}{g}$.\n$g,\\overset{\\sim}{g}$ have the same range and domain. But they are not equal, so \n$\\exists y(y \\in Y \\wedge g(y) \\neq \\overset{\\sim}{g}(y))$. Because $f$ is surjective, \n$\\exists x(x \\in X \\wedge f(x) = y)$. However, $g \\circ f(x) = \\overset{\\sim}{g} \\circ f(x)$, so \nthis is impossible.\n\nIt is not true if $f$ is not surjective. We can make $g(y) = \\overset{\\sim}{g}(y)$ when $y=f(x)$, but \nas well make $g(y') \\neq \\overset{\\sim}{g}(y')$ if $\\nexists x(y'=f(x))$.\n\\end{proof}\n\n\\declareexercise{3.3.5}\n\\begin{proof}\nInjectivity:\nSuppose the negation, that \n\\[\n\\exists x \\exists x'(x \\neq x' \\wedge f(x) = f(x'))\n\\], which immediately gives \n\\[\ng(f(x)) = g(f(x'))\n\\], and thus is impossible.\n\n$g$ has not to be also injective, because $f$ being so ensures that an unique input $x$ gives an unique \ninput to $g$.\n\nSurjectivity:\nIf $g$ is not surjective, then $\\exists z \\forall y(z \\in Z \\wedge y \\in Y \\wedge z \\neq g(y))$\nAnd whatever $x$ is, $f(x) \\in Y$, so $g(f(x)) \\neq z$, which is a contradiction.\n\n$f$ has not to be surjective as long as its ``real'' domain is large enough to form the set $Z$ through \n$g$. For example (Informal), let $g$ be $z = |y|, \\mathbb{R} \\rightarrow \\mathbb{R}^{+}\\cup\\{0\\}$, and \nlet $f$ be $y = x, \\mathbb{R}^{+}\\cup\\{0\\} \\rightarrow \\mathbb{R}$.\n\\end{proof}\n\n\\declareexercise{3.3.6}\n\\begin{proof}\nThe latter:\nBy definition, $P(y,x)$ of $x = f^{-1}(y)$ is $f(x)=y$. Substitute $x$ with $f^{-1}(y)$, and here we \nhave $f(f^{-1}(y)) = y$, where $y \\in Y$.\n\nThe former: Let $y = f(x)$. According to what we have proven, \\\\\n$f(f^{-1}(y)) = y$. Substitute $y$ with \n$f(x)$, we have $f(f^{-1}(f(x))) = f(x)$. Since that $f(x)$ is injective, we have $f^{-1}(f(x)) = x$.\n\nNow we need to show that $f^{-1}$ is bijective. Assume that it is not injective, thus \n$\\exists x \\exists x'(x \\in Y \\wedge x' \\in Y \\Longrightarrow(x\\neq x' \\Longrightarrow f^{-1}(x) = \nf^{-1}(x')))$.\nHowever, according to the latter conclusion, $f^{-1}(x) = f^{-1}(x') \\Longrightarrow x=x'$, a \ncontradiction, so $f^{-1}$ must be injective.\n\nAnd it is also surjective. $\\forall x \\in X$, $\\exists y \\in Y, f^{-1}(y)=x$. According to the former \nconclusion, $y$ is $f(x)$.\n\nSo now $f^{-1}$ is bijective, and thus has its inverse. By definition, $P(x,y)$ of \n$y = (f^{-1})^{-1}(x)$ is $f^{-1}(y) = x$, where $x \\in X$. According to the former conclusion, \n$f^{-1}(f(x)) = x$. Thus\n\\[\nf^{-1}(y) = f^{-1}(f(x)) \\Longrightarrow y = f(x) \\Longrightarrow (f^{-1})^{-1}(x) = f(x)\n\\], which is true $\\forall x \\in X$. And since they have the same domain and range, $(f^{-1})^{-1} = f$.\n\\end{proof}\n\n\\declareexercise{3.3.7}\n\\begin{proof}\nInjectivity: \n\\[\ng \\circ f(x) = g \\circ f(x') \\Longrightarrow f(x) = f(x') \\Longrightarrow x = x'\n\\]\n\nSurjectivity:\nFor each $z \\in Z$, we need to find $x \\in X$ such that $g \\circ f(x) = z$. By the surjectivity of $g$, \nwe can find $y \\in Y$ such that $g(y) = z$. We can also find $a \\in X$ such that $f(a) = y$ as $f$ is \nsurjective. So $a$ is our desired $x$.\n\nThe $P(z,x)$ of $x = (g \\circ f)^{-1}(z)$ is $z = g \\circ f(x)$. Consider the following expression:\n\\begin{align*}\nf^{-1} \\circ g^{-1} (z)\n&= f^{-1} \\circ g^{-1} (g \\circ f(x)) \\\\\n&= f^{-1}(\\textcolor{red}{g^{-1}(g(}f(x)\\textcolor{red}{))}) \\\\\n&= f^{-1}(f(x)) \\\\\n&= x\n\\end{align*}\nSo $(g \\circ f)^{-1} = f^{-1} \\circ g^{-1}$. Therefore, they are equal as they have the same domain and \nrange.\n\\end{proof}\n\n\\declareexercise{3.3.8}\n\\begin{proof}\n(a) First they have the same domain and range. Finally, \n\\[\n\\forall x(x\\in X \\Longrightarrow x=x \\Longrightarrow \\iota_{Y \\rightarrow Z} \\circ \n\\iota_{X \\rightarrow Y} = \\iota_{X \\rightarrow Z})\n\\]\n\n(b) On one hand, they have the same domain and range.\n\nOn the other hand, \n\\begin{align*}\nf \\circ \\iota_{A \\rightarrow A}(x) \n&= f(\\iota_{A \\rightarrow A}(x)) \\\\\n&= f(x) \\\\\n&= \\iota_{B \\rightarrow B}(f(x)) \\\\\n&= \\iota_{B \\rightarrow B} \\circ f (x)\n\\end{align*}\n\n(c) It is easy to see that they have the same domain and range. \n\n\\[\nf \\circ f^{-1} (b) = b = \\iota_{B \\rightarrow B}\n\\]\n\\[\nf \\circ f^{-1} (a) = a = \\iota_{A \\rightarrow A}\n\\]\n\n(d) It is easy to see that they have the same domain and range.\n\nLet $h$ be \n$h(x) = f(x)$, if $x \\in X$, $h(x) = g(x)$, if $x \\in Y$. \n\nFor each $x \\in X$, $\\iota_{X \\rightarrow X \\cup Y}(x) = x$, so \n$h(\\iota_{X \\rightarrow X \\cup Y}(x)) =f(x)$.\n\nSimilarly we can prove $h(\\iota_{Y \\rightarrow X \\cup Y}(x)) = g(x)$ for each $x \\in Y$.\n\\end{proof}\n\n\\subsection{Images and inverse Images}\n\\paragraph{Definition 3.4.1}\nTo prove that $f(S)$ is well-defined by using the axiom of specification, we need to apply it to set \n$Y$, not $X$. Let $P(y)$ be a property pertaining to each $y \\in Y$, which is true iff \n$\\exists x(x \\in S \\wedge f(x) = y)$. According to the axiom of specification, there exists a set that \ncontains every $y \\in Y$ such that $P(y)$ is true.\n\nIn some places where Tao asked ``(Why?)'', the reason is obvious, so I don't write them here. \n\n\\paragraph{Example 3.4.6}\nThis is because \n\\[\nf^{-1}(f(\\{-1,0,1,2\\})) = f^{-1}(\\{1,0,4\\}) = \\{-1,1,0,2,-2\\}\n\\].\n\nMore generally, if $f$ (whose domain is $X$, and whose range is $Y$) is not injective, then \n\\[\n\\exists x \\exists x'((x \\in X \\wedge x' \\in X) \\wedge (x\\neq x' \\wedge f(x) = f(x')))\n\\]. \nLet $D \\subseteq X$ such that $x \\in D \\wedge x' \\notin D$. Then $f(x) = f(x') \\in f(D)$. And thus \n$x,x' \\in f^{-1}(f(D)) \\Longrightarrow f^{-1}(f(D)) \\neq D$. \n\n\\declareexercise{3.4.1}\n\\begin{proof} \n$f^{-1}(V)$ may be interpreted in two different ways:\n\n(1) Interpret $f^{-1}(V)$ as an inverse image, that is,\n\\[\n(\\forall x \\in X)(x \\in f^{-1}(V) \\equiv f(x) \\in V)\n\\]\n\\[\n(\\forall x \\notin X)(x \\notin f^{-1}(V))\n\\]\n\n(2) Interpret $f^{-1}(V)$ as an image, where we regard $f^{-1}$ as a function. So, \n\\[\n\\forall x(\\exists y(y \\in V \\wedge x = f^{-1}(y)) \\equiv x \\in f^{-1}(V))\n\\]\n\nWe need to show that if the two statements are well-defined($x \\in X$) , they are logically equivalent.\n\nLet $S_1$ be the set defined in form (1), $S_2$ be the set defined in form (2). For every $x \\in S_1$, \n$f(x) \\in V$. Let $y' = f(x), x' = f^{-1}(y')$, then by definition (2) we have $x' \\in S_2$. But \n$x' = x$, so $\\forall x(x \\in S_1 \\Longrightarrow x \\in S_2)$.\n\nOn the other hand, for every $a \\in S_2$, $\\exists b \\in V$, such that $a = f^{-1}(b)$. Then $a \\in X$. \n$f(a) = f(f^{-1}(b)) = b \\in V$, so $a \\in S_1$. Thus, $S_1 = S_2$.\n\\end{proof}\n\n\\declareexercise{3.4.2}\n(1) Generally we can say $S \\subseteq f^{-1}(f(S))$ but we cannot say that they are equal; (2) we can \nsay $f(f^{-1}(U)) \\subseteq U$ but we cannot say that they are equal.\n\\begin{proof}\n(1) $x \\in S \\Longrightarrow f(x) \\in f(S) \\Longrightarrow x \\in f^{-1}(f(S))$. However, it is possible \nthat $\\exists x(x \\in X \\wedge x \\notin S \\wedge f(x) \\in f(S))$\n\n(2) \n\\[\nx \\in f^{-1}(U) \\Longrightarrow f(x) \\in U \\Longrightarrow (y \\in f(f^{-1}(U)) \\Longrightarrow y \\in U)\n\\]\nHowever, it is still possible that \n\\[\n\\exists y(y \\in U \\wedge \\forall x(x \\in X \\Longrightarrow f(x) \\neq y))\n\\]\n\\end{proof}\n\n\\declareexercise{3.4.3}\n\\begin{proof}\n(1)\n\\[\nx \\in A \\cap B \\Longrightarrow f(x) \\in f(A) \\wedge f(x) \\in f(B) \\Longrightarrow \nf(x) \\in f(A) \\cap f(B)\n\\]\n\\[\ny \\in f(A \\cap B) \\equiv \\exists x(x \\in A \\cap B \\wedge f(x) = y)\n\\]\nSo $y \\in f(A) \\cap f(B)$, thus $f(A \\cap B) \\subseteq f(A) \\cap f(B)$.\n\n(2)\n\\[\nx \\in A \\setminus B \\Longrightarrow f(x) \\in f(A\\setminus B)\n\\]\n\\[\ny \\in f(A)\\setminus f(B) \\Longrightarrow \\exists x(x \\in A \\wedge x \\notin B \\wedge f(x) = y)\n\\]\nSo $y \\in f(A\\setminus B)$, thus $f(A)\\setminus f(B) \\subseteq f(A\\setminus B)$.\n\n(3)\nOn one hand, \n\\[\ny \\in f(A \\cup B) \\equiv \\exists x (x \\in A \\cup B \\wedge f(x) = y)\n\\]\n\\begin{align*}\nx \\in A \\cup B \\Longrightarrow x \\in A \\vee x \\in B \\Longrightarrow \\\\\nf(x) \\in f(A) \\vee f(x) \\in f(B) \\Longrightarrow f(x) \\in f(A)\\cup f(B)\n\\end{align*}\n\nOn the other hand, \n\\[\ny \\in f(A) \\cup f(B) \\Longrightarrow \\exists x((x \\in A \\vee x \\in B) \\wedge f(x) = y) \n\\]\n\\[\nx \\in A \\vee x \\in B \\Longrightarrow x \\in A \\cup B \\Longrightarrow f(x) \\in f(A\\cup B)\n\\]\n\\end{proof}\n\n(1) $\\subseteq$ can not be improved. Since it is possible that \n\\[\n\\exists x \\exists x'(x \\in A \\wedge x' \\in B \\wedge x \\neq x' \\wedge f(x) = f(x'))\n\\]\n\n(2) $\\subseteq$ can not be improved. Since it is possible that\n\\[\n\\exists x \\exists x'(x \\in A \\setminus B \\wedge x' \\in B \\wedge f(x) = f(x'))\n\\]\n\n\\declareexercise{3.4.4}\n\\begin{proof}\n(1) \n\\begin{align*}\nx \\in f^{-1}(U \\cup V) \\equiv (x \\in X \\wedge f(x) \\in U \\cup V) \\equiv \\\\\n(x \\in X \\wedge (f(x) \\in U \\vee f(x) \\in V))\n\\end{align*}\n\\begin{align*}\nx \\in  f^{-1}(U) \\cup  f^{-1}(V) \\equiv (x \\in X \\wedge f(x) \\in U) \\vee (x \\in X \\wedge f(x) \\in V) \\\\\n\\equiv (x \\in X \\wedge (f(x) \\in U \\vee f(x) \\in V))\n\\end{align*}\n\n(2) and (3) can be proven in similar manners. \n\\end{proof}\n\n\\declareexercise{3.4.5}\n\\begin{proof}\n(1) On one hand, if $f(f^{-1}(S)) = S$ for every $S \\subseteq Y$, then \\\\\n$f(f^{-1}(Y)) = Y$. That means, \n$y \\in Y \\Longrightarrow \\exists x (x \\in f^{-1}(Y) \\wedge f(x) \\in Y)$. So even $f^{-1}(Y)$ \nis enough for $f$ to be surjective. And $f^{-1}(Y) \\subseteq X$, so $f$ is surjective.\n\nOn the other hand, if $f$ is surjective, then for each $S \\subseteq Y$, \n\\[\ny \\in S \\Longrightarrow \\exists x(x \\in X \\wedge f(x) = y)\n\\]\nSuch $x$ are elements of $f^{-1}(S)$ of course, so $f(f^{-1}(S)) = S$.\n\n(2) On one hand, we show that $\\forall S(S \\subseteq X \\Longrightarrow f^{-1}(f(S)) = S)$ implies that \n$f$ is injective. Suppose the negation, that when \n\\[\n\\forall S(S \\subseteq X \\Longrightarrow f^{-1}(f(S)) = S)\n\\], but $f$ is not injective. Since $f$ is not injective, \n\\[\n\\exists x \\exists x'(x \\in X \\wedge x' \\in X \\wedge x \\neq x' \\wedge f(x) = f(x'))\n\\]\nLet $S \\subseteq X$ and $x \\in S \\wedge x' \\notin S$. There is always such a set $S$.\nFor example, we can let $S = X\\setminus \\{x'\\}$. So we have $f^{-1}(f(S)) \\neq S$ because $x' \\in$ it.\n\nOn the other hand, if $f$ is injective, then for every $S \\subseteq X$, and for every $x \\in S$, we have \n$f(x) \\in f(S)$. And $f(x)$ are the only elements in $f(S)$, that is, \n$y \\in f(S) \\Longrightarrow y = f(x)$ for some $x \\in S$. So now we know that \n$S \\subseteq f^{-1}(f(S))$. Moreover, for every $x' \\in f^{-1}(f(S))$, $f(x') \\in f(S)$. We can let \n$f(x') = y = f(x)$. As $f$ is injective, $x = x'$, so $x' \\in S$. That means $f^{-1}(f(S)) \\subseteq S$. \nSo $f^{-1}(f(S)) =  S$.\n\\end{proof}\n\n\\declareexercise{3.4.6}\n\\begin{proof}\nMy own proof: According to Axiom 3.10, we can construct the set $X^X$. Apply the axiom \nof replacement to each element of $X^X$, we construct a set $Z$ such that\n\\[\n\\forall x(x \\in Z \\equiv \\exists f(f \\in X^X \\wedge x = f(X)))\n\\]\n\nLet $Y = \\{\\varnothing\\} \\cup Z$.\n\nNow we prove that $Y$ is the set we want. On one hand, for any $S \\subseteq X$, \nif $S = \\varnothing$, then $S \\in Y$, as $Y = \\{\\varnothing\\} \\cup Z$.\n\nIf $S \\neq \\varnothing$, there exists a surjective function $g: X \\rightarrow S$. $g\\in X^X$, and \n$g(X) = S$, so $S \\in Z$, and thus $S \\in Y$. (To show the existence of $g$, for example, let $x \\in X, \ng(x) = x$ if $x \\in S$, and for $x \\in X \\wedge x \\notin S$, $g(x)$ can be any element of $X$.)\n\n\nOn the other hand, for any $S' \\nsubseteq X$, $\\exists a(a \\in S' \\wedge a \\notin X)$. To prove that \n$S' \\notin Y$, we need to show that $\\nexists f(f \\in X^X \\wedge S' = f(X))$. We know that \n$\\nexists x(x \\in X \\wedge f(x) = a)$, so $a \\notin f(X)$. Therefore $S' \\neq f(X)$, so $S' \\notin Y$.\n\n$Y$ is the set we want.\n\nI posted a question \\href{https://math.stackexchange.com/questions/3803487/is-this-proof-to-the-existence-of-a-set-that-contains-all-subsets-of-another-set}{here} for verification for this proof. \nThanks to answers of people at Stack Exchange so that my proof can be refined.\n\nProof By Tao's Hint:\nFor each $S \\subseteq X$, let a function $f_S$ be $f_S(x) = 1$ if $x \\in S$, and $f_S(x)=0$ if \n$x \\in X \\wedge x \\notin S$. Then $f^{-1}_S(\\{1\\})$ gives $S$. \n\nNow we show that any element in \n$\\{0,1\\}^X$ is some $f_S$. Let $g \\in \\{0,1\\}^X$. Then if $\\forall x \\in X, g(x) = 0$, then \n$g = f_{\\varnothing}$. Otherwise, there exists a set that contains all $x$ such that $g(x) = 0$ by \naxiom of specification, namely $R$. Then $g = f_R$.\n\nOn the other hand, each $f_S$ is obviously an element of $\\{0,1\\}^X$.\n\nUse the axiom of replacement, we construct a set $Y$ such that\n\\[\n\\forall x (x \\in Y \\equiv \\exists f(f \\in \\{0,1\\}^X \\wedge x = f^{-1}(\\{1\\})))\n\\]\n\nAccording to what we have proven, $Y$ is the set we want.\n\\end{proof}\n\n\\declareexercise{3.4.7}\n\\begin{proof}\nAs stated by the previous exercise, there exists a set $\\mathbb{X}$ whose elements are all subsets of \n$X$, and a set $\\mathbb{Y}$ whose elements are all subsets of $Y$.\n\nFor every element $x \\in \\mathbb{X}$, apply the axiom of replacement to $\\mathbb{Y}$, to obtain a set \n$S_x := \\{y^x\\}$ for every element $y \\in \\mathbb{Y}$. \n\nAccording to the axiom of union, using $\\mathbb{X}$ as the index set, we have the set\n\\[\nZ = \\bigcup_{x \\in \\mathbb{X}} S_x\n\\]\n\nApply again the axiom of union to $Z$ to obtain $R$, which contains all elements of elements of $Z$. Now \nwe show that $R$ is the set we want.\n\nOn one hand, let $f$ be an arbitrary function with the domain of $X' \\subseteq X$, and the range of $Y' \n\\subseteq Y$. We can see that $f \\in {Y'}^{X'} \\in S_{X'}$. ${Y'}^{X'}$ becomes an element of $Z$. And \nthus $f$ becomes an element in $R$. \n\nOn the other hand, from the construction of $R$, we can see that $R$ contains only these elements.\n\n\\end{proof}\n\n\\declareexercise{3.4.8}\n\\begin{proof}\nLet $A,B$ be two arbitrary sets. They are also objects as stated by Axiom 3.1. So according to \nAxiom 3.3, there exists a set $S=\\{A,B\\}$. By Axiom 3.11, we have a set $Z$ such that \n\\[\n\\forall x(x \\in Z \\equiv \\exists X(X \\in S \\wedge x \\in X))\n\\]\n\nNow we show that $Z$ is the set we want. If $x \\in A \\vee x \\in B$, then \n$\\exists X(X \\in S \\wedge x \\in X)$ is true. So $x \\in Z$.\n\nIf $x \\notin A \\wedge x \\notin B$, then $\\forall X(X \\in S \\Longrightarrow x \\notin X)$, that is, \n$\\exists X(X \\in S \\wedge x \\in X)$ is false. So $x \\notin Z$.\n\n$Z$ is therefore the set we want. \n\\end{proof}\n\n\\paragraph{Example 3.4.11}\nIn (3.3), why do Tao choose some element $\\beta$ of $I$? This is because we need to apply the axiom of \nspecification to $A_\\beta$ with the restriction $x \\in A_\\alpha$ for all $\\alpha \\in I$.\n\n\\declareexercise{3.4.9}\n\\begin{proof}\nThis is quiet easy to prove. Let the left-handed side set be $S$, the RHS set be $S'$. For any \n$x \\in S$, $x \\in A_\\alpha$ for all $\\alpha \\in I$. So $x \\in A_{\\beta'}$. And $x \\in A_\\alpha$ for all \n$\\alpha \\in I$. Therefore $x \\in S'$. \n\nIt is nearly the same the prove $x \\in S' \\Longrightarrow x \\in S$.\n\\end{proof}\n\n\\paragraph{Exercise 3.4.10} \\label{exercise3.4.10}\n\\begin{proof}\nFor the sake of convenience, let \n$(\\bigcup_{\\alpha \\in I} A_{\\alpha})\\cup(\\bigcup_{\\alpha \\in J}A_{\\alpha})$ be $S$, \\\\\n$\\bigcup_{\\alpha \\in I \\cup J} A_{\\alpha}$ be $S'$, \n$(\\bigcap_{\\alpha \\in I} A_{\\alpha})\\cap(\\bigcap_{\\alpha \\in J}A_{\\alpha})$ be $Z$,\n$\\bigcap_{\\alpha \\in I \\cup J} A_{\\alpha}$ be $Z'$.\n\n(1) When $I,J \\neq \\varnothing$: \nOn one hand, \n\\[\nx \\in S \\Longrightarrow (x \\in \\bigcup_{\\alpha \\in I} A_{\\alpha} \\vee \nx \\in \\bigcup_{\\alpha \\in J}A_{\\alpha})\n\\]\nIf $x \\in \\bigcup_{\\alpha \\in I} A_{\\alpha}$, then $x \\in \\bigcup_{\\alpha \\in I \\cup J} A_{\\alpha}$.\nIf $x \\in \\bigcup_{\\alpha \\in J} A_{\\alpha}$, then $x \\in \\bigcup_{\\alpha \\in I \\cup J} A_{\\alpha}$.\n\nOn the other hand, if $x \\in S'$, then there exists an object $a \\in I \\cup J$ such that $x \\in A_a$.\nIf $a \\in I$ then $x \\in x \\in \\bigcup_{\\alpha \\in I} A_{\\alpha} \\Longrightarrow x \\in S$.\nIf $a \\in J$ then $x \\in x \\in \\bigcup_{\\alpha \\in J} A_{\\alpha} \\Longrightarrow x \\in S$.\n\nWhen $I,J$ are both empty, $S,S'$ are all empty.\n\nWhen there is only one of $I,J$ is empty, say it is $I$, then \n$S = \\varnothing \\cup \\bigcup_{\\alpha \\in J} = \\bigcup_{\\alpha \\in J}$. And \n$S' = \\bigcup_{\\alpha \\in \\varnothing \\cup J} A_{\\alpha} = \\bigcup_{\\alpha \\in J}$.\n\n(2)\n\\[\nx \\in Z \\equiv \\forall a(a \\in I \\Longrightarrow x \\in A_a) \\wedge \n\\forall b(b \\in J \\Longrightarrow x \\in A_b)\n\\], which is equal to $\\forall a(a \\in I \\cup J \\Longrightarrow x \\in A_a) \\equiv x \\in Z'$.\n\\end{proof}\n\n\\paragraph{Exercise 3.4.11} \\label{exercise3.4.11}\n\\begin{proof}\n(1) Let the LHS be $S$, the RHS be $S'$. \n\\begin{align*}\nx \\in S &\\equiv \\\\\nx \\in X \\wedge x \\notin \\bigcup_{\\alpha \\in I} A_{\\alpha} &\\equiv \\\\\nx \\in X \\wedge \\forall a(a \\in I \\Longrightarrow x \\notin A_{a})\n\\end{align*}\n\\begin{align*}\nx \\in S' &\\equiv \\\\\n\\forall a(a \\in I \\Longrightarrow x \\in X \\setminus A_a) &\\equiv \\\\\nx \\in X \\wedge \\forall a(a \\in I \\Longrightarrow x \\notin A_a)\n\\end{align*}.\n\nSo $S=S'$.\n\n(2) Let the LHS be $Z$, the RHS be $Z'$. \n\\begin{align*}\nx \\in Z &\\equiv \\\\\nx \\in X \\wedge x \\notin \\bigcap_{\\alpha \\in I} A_{\\alpha} &\\equiv \\\\\nx \\in X \\wedge \\neg(\\forall a(a \\in I \\Longrightarrow x \\in A_a)) &\\equiv \\\\\nx \\in X \\wedge \\exists a(a \\in I \\Longrightarrow x \\notin A_a)\n\\end{align*}\n\\begin{align*}\nx \\in Z' &\\equiv \\\\\nx \\in X \\wedge \\bigvee_{\\alpha \\in I}(x \\notin A_{\\alpha}) &\\equiv \\\\\nx \\in X \\wedge \\exists a(a \\in I \\Longrightarrow x \\notin A_a)\n\\end{align*}\n\nThus, $Z = Z'$\n\\end{proof}\n\n\\subsection{Cartesian products}\n\\declareexercise{3.5.1}\n\\begin{proof}\nFirst we show that $(x,y) = \\{\\{x\\},\\{x,y\\}\\}$ is a good definition. \nLet $S_1$ denote $(x_1,y_1) = \\{\\{x_1\\},\\{x_1,y_1\\}\\}$, $S_2$ denote \n$(x_2,y_2) = \\{\\{x_2\\},\\{x_2,y_2\\}\\}$.\n\nOn one hand, if $x_1=x_2\\wedge y_1=y_2$, then obviously $S_1=S_2$ for they have the same elements.\n\nOn the other hand, if $S_1 = S_2$, then \n\\[\n\\{x_1\\} \\in S_2 \\wedge \\{x_1,y_1\\} \\in S_2 \\wedge\n\\{x_2\\} \\in S_1 \\wedge \\{x_2,y_2\\} \\in S_1 \n\\].\nWe have that \n\\begin{align*}\n\\{x_1\\} \\in S_2 &\\equiv \\{x_1\\} = \\{x_2\\} \\vee \\{x_1\\} = \\{x_2,y_2\\} \\\\\n&\\equiv x_1=x_2 \\vee x_1=x_2=y_2 \\\\\n&\\Longrightarrow x_1=x_2\n\\end{align*}\n\\begin{align*}\n\\{x_1,y_1\\} \\in S_2 &\\equiv \\{x_1,y_1\\} = \\{x_2\\} \\vee \\{x_1,y_1\\} = \\{x_2,y_2\\} \\\\\n&\\equiv x_1=x_2=y_1 \\\\\n&\\vee \\textcolor{red}{((x_1=x_2\\wedge y_1=y_2)\\vee(x_1=y_2\\wedge y_1=x_2))} \n\\end{align*}\nSimilarly we have that\n\\begin{align*}\n\\{x_2,y_2\\} \\in S_1 \n&\\equiv x_2=x_1=y_2 \\\\\n&\\vee \\textcolor{red}{((x_2=x_1\\wedge y_2=y_1)\\vee(x_2=y_1\\wedge y_2=x_1))}\n\\end{align*}\nWe may notice that the red-colored text are two same statements. Thus from $\\{x_1,y_1\\} \\in S_2$ and \n$\\{x_2,y_2\\} \\in S_1$ we can always conclude that $y_1=y_2$. Therefore, \n$S_1 = S_2 \\Longrightarrow x_1=x_2\\wedge y_1=y_2$.\n\nThen we show that if $X,Y$ are two sets, then $X \\times Y$ is also a set. For each element $x \\in X$, \nconstruct a set $S_x$, where we replace each element $y \\in Y$ with $(x,y)$. Then construct the set \n$\\bigcup_{x \\in X}S_x$.\n\\end{proof}\n\n\\declareexercise{3.5.2}\n\\begin{proof}\nSince $x,y$ are two functions, they are equal means that $\\forall 1\\leq i \\leq n$, $x(i) = y(i)$. That \nis, $x_i = y_i, 1\\leq i \\leq n$.\n\nNow we show that $\\displaystyle \\prod_{1\\leq i\\leq n}X_i$ is a set. Let set $F$ be the set that contains \nall partial functions from $N = \\{i \\in \\mathbb{N}:1\\leq i\\leq n\\}$ to \n$\\displaystyle X = \\bigcup_{1\\leq i\\leq n}X_i$ (Exercise 3.4.7). Use the axiom of specification, select \nsuch elements $f$ from $F$ that:\n\\begin{enumerate}\n\\item the element is surjective, and\n\\item its domain is $N$, and \n\\item $f(i) \\in X_i$\n\\end{enumerate}, \nand use all of them to construct a set $Z$, which is the set we want.\n\\end{proof}\n\n\\declareexercise{3.5.3}\n\\begin{proof}\nThe definition is entirely based on the equality of objects (e.g. $x = x'$). The proof is immediately \ndone since this equality is reflective ($x = x$), symmetric ($x = x' \\equiv x' = x$), and transitive \n($x_0 = x_1 \\wedge x_1 = x_2 \\Longrightarrow x_0 = x_2$).\n\\end{proof}\n\n\\declareexercise{3.5.4}\n\\begin{proof}\n(1)\n\\begin{align*}\n(x,y) \\in A \\times (B \\cup C) &\\equiv x \\in A \\wedge y \\in (B \\cup C) \\\\\n&\\equiv x \\in A \\wedge (y \\in B \\vee y \\in C) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\vee (x \\in A \\wedge y \\in C) \\\\\n&\\equiv ((x,y) \\in A \\times B) \\vee ((x,y) \\in A \\times C) \\\\\n&\\equiv (x,y) \\in (A \\times B) \\cup (A \\times C)\n\\end{align*}\n\n(2)\n\\begin{align*}\n(x,y) \\in A \\times (B \\cap C) &\\equiv x \\in A \\wedge y \\in (B \\cap C) \\\\\n&\\equiv x \\in A \\wedge (y \\in B \\wedge y \\in C) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\wedge (x \\in A \\wedge y \\in C) \\\\\n&\\equiv ((x,y) \\in A \\times B) \\wedge ((x,y) \\in A \\times C) \\\\\n&\\equiv (x,y) \\in (A \\times B) \\cap (A \\times C)\n\\end{align*}\n\n(3)\n\\begin{align*}\n(x,y) \\in A \\times (B \\setminus C) &\\equiv x \\in A \\wedge y \\in (B \\setminus C) \\\\\n&\\equiv x \\in A \\wedge (y \\in B \\wedge \\neg (y \\in C)) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\wedge \\neg (x \\in A \\wedge y \\in C) \\\\\n\\tag{The statement $x \\in A$ implies $\\neg (x \\in A \\wedge y \\in C) \n\\Longrightarrow \\neg (y \\in C)$}\\\\\n&\\equiv ((x,y) \\in A \\times B) \\wedge \\neg((x,y) \\in A \\times C) \\\\\n&\\equiv (x,y) \\in (A \\times B) \\setminus (A \\times C)\n\\end{align*}\n\\end{proof}\n\n\\declareexercise{3.5.5}\n\\begin{proof}\n(1)\n\\begin{align*}\n(x,y) \\in (A \\times B) \\cap (C \\times D) \n&\\equiv (x,y) \\in (A \\times B) \\wedge (x,y) \\in (C \\times D) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\wedge (x \\in C \\wedge y \\in D) \\\\\n&\\equiv (x \\in A \\wedge x \\in C) \\wedge (y \\in B \\wedge y \\in D) \\\\\n&\\equiv x \\in A \\cap C \\wedge y \\in B \\cap D \\\\\n&\\equiv (x,y) \\in (A \\cap C) \\times (B \\cap D)\n\\end{align*}\n\n(2) It is not true since \n\\begin{align*}\n(x,y) \\in (A \\times B) \\cup (C \\times D) \n&\\equiv (x,y) \\in (A \\times B) \\vee (x,y) \\in (C \\times D) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\vee (x \\in C \\wedge y \\in D) \\\\\n&\\nLeftrightarrow (x \\in A \\vee x \\in C) \\wedge (y \\in B \\vee y \\in D)\n\\end{align*}\nGenerally \n\\[\n(x \\in A \\wedge y \\in B) \\vee (x \\in C \\wedge y \\in D) \\Longrightarrow \n(x \\in A \\vee x \\in C) \\wedge (y \\in B \\vee y \\in D)\n\\], \nbut\n\\[\n(x \\in A \\vee x \\in C) \\wedge (y \\in B \\vee y \\in D) \\nRightarrow\n(x \\in A \\wedge y \\in B) \\vee (x \\in C \\wedge y \\in D)\n\\].\n\n(3) It is not true since\n\\begin{align*}\n(x,y) \\in (A \\times B) \\setminus (C \\times D) \n&\\equiv (x,y) \\in (A \\times B) \\wedge (x,y) \\notin (C \\times D) \\\\\n&\\equiv (x \\in A \\wedge y \\in B) \\wedge (x \\notin C \\vee y \\notin D) \\\\\n&\\nLeftrightarrow (x \\in A \\wedge x \\notin C) \\wedge (y \\in B \\wedge y \\notin D)\n\\end{align*}\n\\end{proof}\n\n\\declareexercise{3.5.6}\n\\begin{proof}\n(1) On one hand, if $A \\subseteq C$ and $B \\subseteq D$, then \n\\begin{align*}\n(x,y) \\in A \\times B &\\equiv x \\in A \\wedge y \\in B \\\\\n&\\Longrightarrow x \\in C \\wedge y \\in D \\\\\n&\\Longrightarrow (x,y) \\in C \\times D\n\\end{align*}, \nwhich means $A \\times B \\subseteq C \\times D$.\n\nOn the other hand, if $A \\times B \\subseteq C \\times D$, but we suppose that \n\\[\n\\neg(A \\subseteq C \\wedge B \\subseteq D)\n\\]. \nWe only consider that $A \\nsubseteq C$, the other situations are similar. Then \n$\\exists x(x \\in A \\wedge x \\notin C)$. Let $p = (x,y)$, where $y \\in B$, then $p \\in A \\times B$. \nBut $x \\notin C$, so $p \\notin C \\times D$, a contradiction. Therefore, \n\\[\nA \\times B \\subseteq C \\times D \\Longrightarrow A \\subseteq C \\wedge B \\subseteq D\n\\]\n\n(2) On one hand, if $A = C \\wedge B = D$, then\n\\begin{align*}\n(x,y) \\in A \\times B &\\equiv x \\in A \\wedge y \\in B \\\\\n&\\equiv x \\in C \\wedge y \\in D \\\\\n&\\equiv (x,y) \\in C \\times D\n\\end{align*}.\n\nOn the other hand, if $A \\times B = C \\times D$, but we suppose that $\\neg(A = C \\wedge B = D)$. \nWe only consider that $A \\neq C$, the other situations are similar. Then we only consider \n$\\exists x(x \\in A \\wedge x \\notin C)$, for the other situations are similar. \n\n(3) It is easy to prove that $X \\times \\varnothing = \\varnothing$ and \n$\\varnothing \\times X = \\varnothing$. Let $A = \\varnothing$, we can see that even if $B \\nsubseteq D$, \n$A \\times B \\subseteq C \\times D$. \n\nLet $A = D = \\varnothing$, then even if $A \\neq C$, $A \\times B = C \\times D$.\n\\end{proof}\n\n\\declareexercise{3.5.7}\n\\begin{proof}\nExistence: Let $h(t):=(f(t),y(t))$. It is easy to verify that $h(t) \\in X \\times Y$, and that given a \n$t \\in Z$, $h(t)$ is unique. Therefore, $h$ is a function. And it is obvious that \n$\\pi_{X\\times Y \\rightarrow X} \\circ h = f$ and that $\\pi_{X\\times Y \\rightarrow Y} \\circ h = g$.\n\nUniqueness: $\\pi_{X\\times Y \\rightarrow X} \\circ h = f$ and $\\pi_{X\\times Y \\rightarrow Y} \\circ h = g$ \nimply that if there is another function $h'$ that satisfies the requirements, then $h'(t) = h(t)$. So $h$ \nis unique. \n\\end{proof}\n\n\\declareexercise{3.5.8}\n\\begin{proof}\nOn one hand, if for some $i, X_i = \\varnothing$, then \n\\[\n\\forall (x_i)_{1\\leq i \\leq n}(\\bigwedge^{n}_{i =1}x_i \\in X_i \\equiv (x_i)_{1\\leq i \\leq n} \\in \n\\varnothing)\n\\], \nwhich means that $\\varnothing = \\prod_{i=1}^{n}X_i$.\n\nOn the other hand, if $\\prod_{i=1}^{n}X_i = \\varnothing$ but we suppose that $X_i \\neq \\varnothing$. Then \nfor each $i$, $\\exists x_i \\in X_i$. We thus have a tuple $(x_i)_{1\\leq i \\leq n}$, which should be an \nelement of $\\prod_{i=1}^{n}X_i$. Therefore we have a contradiction.\n\\end{proof}\n\n\\declareexercise{3.5.9}\n\\begin{proof}\nOn one hand, let $x \\in (\\bigcup_{\\alpha \\in I}A_{\\alpha})\\cap(\\bigcup_{\\beta \\in J}B_{\\beta})$. Then \n\\[\n\\exists a(a \\in I \\wedge x \\in A_a) \\wedge \\exists b(b \\in J \\wedge x \\in B_b)\n\\]\nIt is obvious that $x \\in A_a \\cap B_b$ and that $(a,b) \\in I \\times J$. Therefore \n\\[\nx \\in \\bigcup_{(\\alpha,\\beta) \\in I \\times J}(A_\\alpha \\cap B_\\beta)\n\\].\n\nOn the other hand, let $x \\in \\bigcup_{(\\alpha,\\beta) \\in I \\times J}(A_\\alpha \\cap B_\\beta)$. Then \n\\begin{align*}\n\\exists (a,b) \\in I \\times J(x \\in A_a \\cap B_b) \n&\\Longrightarrow  x \\in A_a \\wedge x \\in B_b \\\\\n&\\Longrightarrow x \\in \\bigcup_{\\alpha \\in I}A_{\\alpha} \\wedge x \\in \\bigcup_{\\beta \\in J}B_{\\beta} \\\\\n&\\Longrightarrow x \\in (\\bigcup_{\\alpha \\in I}A_{\\alpha})\\cap(\\bigcup_{\\beta \\in J}B_{\\beta})\n\\end{align*}\n\\end{proof}\n\n\\paragraph{Exercise 3.5.10} \\label{exercise3.5.10}\n\\begin{proof}\nWe denote $\\overset{\\sim}{f}$ as $f'$, the graph of $f$ as $G$, and the graph of $f'$ as $G'$ for the \nsake of simplification.\n\n(1) On one hand, if $f = f'$, then for every $(x,f(x)) \\in G$, we can find $(x,f'(x)) \\in G'$, and \nobviously $(x,f(x)) = (x,f'(x))$, and vice versa.\n\nOn the other hand, if $G = G'$, then for each $(x,f(x)) \\in G$, $(x,f(x)) \\in G'$. Note that each \nelement of $G'$ obeys the form $(x,f'(x))$, so $f(x) = f'(x)$ for every $x \\in X$, that is, $f=f'$.\n\n(2) Existence: Let $f(x)$ be such a value that $(x,f(x)) \\in G$. Thus the value is unique, so $f$ is a \nfunction. According to its definition, the graph of $f$ is $G$.\n\nUniqueness: As proven in (1), if $f,f'$ have the same graph, then they are equal.\n\\end{proof}\n\n\\paragraph{Exercise 3.5.11} \\label{exercise3.5.11}\nI think this exercise is meaningless. Lemma 3.4.6 is proven by the fact that $X^Y$ exists, which depends \non Axiom 3.10. Then the exercise asks us to prove Axiom 3.10 using Lemma 3.4.6. So I looked up some books \nabout set theory and found out that the power set axiom is essentially Lemma 3.4.6, not Axiom 3.10.\n\nNevertheless, here is the proof:\n\\begin{proof}\nLet set $Z$ contains all subsets of $X\\times Y$. The specify such element in $Z$ that obey the vertical \nline test, and let them form the set $S$. According to the previous exercise, for each element in $S$, \nthere exists an unique function whose graph is the element. Then we replace all elements in $S$ with \nthese functions to construct the set $F$. Obviously, each element in $F$ is a function with the domain \n$X$ and the range $Y$.\n\nNow we show that every function $f$ from $X$ to $Y$ is in $F$. Denote the graph of $f$ as $G$. We know \nthat $G$ obeys the vertical line test and $G \\subseteq X \\times Y$, so $G \\in S$. Since $G$ is the graph \nof $f$, $f \\in F$.\n\\end{proof}\n\n\\paragraph{Exercise 3.5.12} \\label{exercise3.5.12}\nI am confused by this exercise. It seems that simply applying induction to $a$ can solve the \nproblem, just like what we did in Proposition 2.1.16. What is wrong?\n\nBy the way, according to the \\href{https://terrytao.wordpress.com/books/analysis-i/}{corrections}, \nedit the exercise as the following:\n\\begin{quotation}\nLet $X$ be an arbitrary set containing at least an element $c$ and obeys the Peano axioms. Let $f$ be a \nfunction from $N \\times X$ to $X$. ... \n\nShow that there exists an unique function $a$ from $X$ to $X$ such that \n\\[\na(0) = c\n\\] \nand \n\\[\na(n++) = f(n,a(n)), \\forall n \\in X\n\\]\n...\n\nsuch that $a_N(0) = c$ and $a_{N}(n++) = f(n,a_N(n))$ ... \n\\end{quotation}\n\nNote that all properties (e.g. orders, addition) in section 2 are deduced from the Peano axioms and their \ndefinitions. Since $X$ obeys these rules, we use such properties on elements of $X$ without proof.\n\nThe proof is now reserved for further research.\n\\begin{proof}\n\\end{proof}\n\n\\paragraph{Exercise 3.5.13} \\label{exercise3.5.13}\n\\begin{proof}\nUse induction.\n\nExistence: We need to prove that for all $n \\in \\mathbb{N}$, $f(n)$ is defined. Use induction:\n$f(0) = 0'$ is define. And the definition is unique for $0$ is not the successor of any natural number. \nNow suppose that $f(n) = n'$ is defined, then $f(S(n)) = S'(f(n)) = S'(n')$ is also defined. The \ndefinition is also unique. So we know that $f$ exists.\n\nInjectivity: We need to prove that $f(m) = f(n) \\Longrightarrow m = n$. If $f(m) = f(n)$, then $m' = n'$, \nand thus $m=n$. \n\nSurjectivity: Use induction: \nThe basic case is, for $0' \\in \\mathbb{N}'$, $f(0) = 0'$. \n\nNow suppose that for $n' \\in \\mathbb{N}'$, we can find $n \\in \\mathbb{N}$ such that $f(n) = n'$, then \nfor $S'(n')$, we have $f(S(n)) = S'(n')$. We can close the induction now.\n\\end{proof}\n\n\\subsection{Cardinality of Sets}\n\n\\declareexercise{3.6.1}\n\\begin{proof}\nReflexivity: Let $f(x):= x, X \\rightarrow X$. $f$ is bijective since $f^{-1}(x) = x$ exists.\n\nSymmetry: If $X,Y$ have the same cardinality, then $\\exists f:X\\rightarrow Y$ which is bijective. So \n$f^{-1}$ exists, and is also a bijection. Thus $Y,X$ have the same cardinality. Since then, we can say \nthat two sets have the same cardinality without caring about the order.\n\nTransitivity: If $X,Y$ have the same cardinality, and $Y,Z$ also have the same cardinality, then there \nexist two bijections: $f:X \\rightarrow Y$ and $g:Y \\rightarrow Z$. It is easy to verify that $g \\circ f$ \nis also a bijection and is from $X$ to $Z$ (See \\exerciseref{3.3.7}).\n\\end{proof}\n\n\\paragraph{Remark 3.6.6}\nIt is $f(n) := S(n)$. We are now proving something stronger\n\\begin{lem} \\label{lem3.6.6}\nFor any natural number $m,n$, $\\{i \\in \\mathbb{N}:0\\leq i\\leq n\\}$ and \n$\\{i \\in \\mathbb{N}:m\\leq i\\leq n+m\\}$ have the same cardinality.\n\\end{lem}\n\\begin{proof}\nUse induction on $m$. When $m=0$, the statement is obviously true. Simply give the function $f(n):=n$.\n\nSuppose that for some $m$, we have proven the statement. Then there exists a bijection: \n\\[\nf:\\{i \\in \\mathbb{N}:0\\leq i\\leq n\\} \\rightarrow \\{i \\in \\mathbb{N}:m\\leq i\\leq n+m\\}\n\\].\nLet $g$ be a function from $\\{i \\in \\mathbb{N}:0\\leq i\\leq n\\}$ to $\\mathbb{N}$ such that \n$g(x) = S(f(x))$. We prove that $g$ is a bijection from $\\{i \\in \\mathbb{N}:0\\leq i\\leq n\\}$ to \n$\\{i \\in \\mathbb{N}:S(m)\\leq i\\leq n+S(m)\\}$.\n\nFirst we prove that $g(n)$ always in $\\{i \\in \\mathbb{N}:S(m)\\leq i\\leq n+S(m)\\}$, which is immediately \ngiven by the fact that addition preserves order. \n\nSurjectivity: For any $a \\in \\{i \\in \\mathbb{N}:S(m)\\leq i\\leq n+S(m)\\}$, $a$ is positive. Then $a$ is \nalways some number's successor, that is $a = S(b) = b+1$ for some natural number $b$. Since addition \npreserves order, $b \\in \\{i \\in \\mathbb{N}:m\\leq i\\leq n+m\\}$. $f$ being surjective implies that there is \nsome $x$ in the domain such that $f(x) = b$, and $g(x) = f(x) + 1 = a$.\n\nInjectivity: By cancellation law, $f(x) + 1 \\neq f(x') + 1 \\equiv f(x) \\neq f(x') \\equiv x \\neq x'$.\n\nWe can now close the induction.\n\\end{proof}\n\n\\paragraph{Lemma 3.6.9}\nEmpty functions are not injective when the range is not empty (See \\exerciseref{3.3.3}). \n\nNow we show that $g$ is bijective:\n\\begin{proof}\nInjectivity: $f$ being injective implies that \n\\[\n\\forall x \\forall x'((x \\in X \\wedge x' \\in X) \\Longrightarrow (f(x) = f(x') \\Rightarrow x = x'))\n\\]\nFor $a,a' \\in X - \\{x\\}$, they also $\\in X$. If $g(a) = g(a')$, then either directly $f(a) = f(a')$ or \n$f(a) - 1 = f(a') - 1$, which gives $f(a) = f(a')$. Thus $a = a'$. (Note that subtraction is not defined \nyet, see the footnote about this in the book).\n\nSurjectivity: The surjectivity of $f$ gives \n\\[\n(\\forall 1 \\leq i \\leq n)(\\exists a(a \\in X \\wedge f(a) = i))\n\\].\n\nIf $f(x) = n$, then $g(a) = f(a)$ for all meaningful $a$. Then for $1 \\leq i \\leq n-1$, we can find $a$ \nsuch that $a \\in X \\wedge a \\neq x$, that is, $x \\in X - \\{x\\}$. So $g(a)$ is meaningful, then $g$ is \nsurjective.\n\nIf $f(x) \\neq n$, then $f(x) < n$. For those $1 \\leq i < f(x)$, $g$ is obviously surjective. For \n$n-1 \\geq i \\geq f(x)$, since $S(i) \\leq n$, $\\exists a(a \\in X \\wedge f(a) = S(i))$. And we know that \n$S(i) \\neq f(x)$, then $a \\in X - \\{x\\}$. So $g(a) = f(a) - 1 = i$.\n\\end{proof}\n\n\\declareexercise{3.6.2}\n\\begin{proof}\nOn one hand, if $X$ is empty, then we know that the empty function whose range is also empty is injective, \n(See \\exerciseref{3.3.3}) so its cardinality is $0$. \n\nOn the other hand, if $\\# X = 0$ but $X \\neq \\varnothing$, then there exists an bijection \n$f:X \\rightarrow \\varnothing$, which is impossible.\n\\end{proof}\n\n\\declareexercise{3.6.3}\n\\begin{proof}\nWhen $n = 0$, this is vacuously true. The base case then becomes $n=1$. We simply let $M = f(1)$.\n\nSuppose that the statement for $n$ is true. And for $1\\leq i\\leq n$ we have the number $M$. Then $f(S(n))$ \neither $\\geq$ or $<$ $M$. On the former case, let $f(S(n))$ be $M'$, and on the latter case, let $M' = M$. \nIt is east to verify that $M'$ is the number we want.\n\\end{proof}\n\nFrom now on we will denote $\\{i\\in \\mathbb{N}:1\\leq i \\leq n\\}$ as $\\mathbb{N}_n$\n\n\\declareexercise{3.6.4}\n\\begin{proof}\n(a) \nLet $n = \\#X$. There is an injective  $f$ from $X$ to $\\{i\\in \\mathbb{N}:1\\leq i\\leq n\\}$. Let $g$ be a \nfunction from $X \\cup \\{x\\}$ to $\\{i\\in \\mathbb{N}:1\\leq i\\leq n+1\\}$ such that $g(a) = f(a)$ if \n$a\\neq x$, and $g(x) = n+1$. Now we show that $g$ is bijective.\n\nInjectivity: We know that $\\forall x \\in X$, $g$ is already injective. Since that $g(x) = n+1 \\neq g(a)$ \nfor all $a \\in X$, so $g$ is injective on $X \\cup \\{x\\}$.\n\nSurjectivity: We know that $\\forall i \\in \\{i\\in \\mathbb{N}:1\\leq i\\leq n\\}$, we can find \n$a \\in X \\cup \\{x\\}$ such that $g(a) = i$. And we have $g(x) = n+1$, so \n$\\forall a \\in \\{i\\in \\mathbb{N}:1\\leq i\\leq n+1\\}$, we can find $a \\in X \\cup \\{x\\}$ such that \n$g(a) = i$. \n\n(b)\nFirst we prove that if $X,Y$ are disjoint, then $\\#X + \\#Y = \\#(X\\cup Y)$. Let $f$ be a bijection from $X$ \nto $\\mathbb{N}_{\\#X}$, and $g$ be a bijection from $Y$ to $\\mathbb{N}_{\\#Y}$. According to \n\\hyperref[lem3.6.6]{this Lemma}, there exists a bijection $h$ from $\\mathbb{N}_{\\#Y}$ to \n$\\{i\\in \\mathbb{N}:\\#X+1\\leq i \\leq \\#X+\\#Y\\}$. Thus $h \\circ g$ is also a bijection. Let $u$ be a \nfunction from $X \\cup Y$ to $\\mathbb{N}_{\\#X} \\cup\\{i\\in \\mathbb{N}:\\#X+1\\leq i \\leq \\#X+\\#Y\\}$. Now we \nshow that $u$ is bijective.\n\nInjectivity: For $x \\neq x'$ in the domain. If $x,x'$ are both in $X$ or $Y$, then $f(x)\\neq f(x')$ is \nimmediately given by the injectivity of $f$ and $h \\circ g$. If one of them is in $X$, and the other is \nin $Y$, then they can also never be equal because the ranges of the two functions are disjoint. \n\nSurjectivity: It is easy to verify that the range is equal to $\\mathbb{N}_{\\#X + \\#Y}$. For any $y$ in the \nrange, if $y \\in$ the range of $f$, then $u$ is surjective since $f$ is, and if $y \\in$ the range of $h \n\\circ g$, $u$ is surjective for the same reason. The range consists of only this two sets, so $u$ is \nsurjective on the whole range.\n\nThe proof is over. This also implies that $X \\cup Y$ is finite. Now we need only to show that \n$\\#(X \\cup Y) < \\#X + \\#Y$ when $X,Y$ are not disjoint. It is easy to see that\n\\begin{align*}\n\\#A + \\#B \n&= \\#(A - A \\cap B) + \\#(A \\cap B) + \\#(B - A \\cap B) + \\#(A \\cap B) \\\\\n&= (\\#(A - A \\cap B) + \\#(A \\cap B) + \\#(B - A \\cap B)) + \\#(A \\cap B) \\\\\n&= \\#(A \\cup B) + \\#(A \\cap B) \\\\\n&> \\#(A \\cup B)\n\\end{align*}\n\n(c)\nIf $X \\subseteq Y \\wedge X \\neq Y$, then $\\#(Y \\setminus X) \\neq 0$. \n\\[\n\\#Y = \\#X + \\#(Y \\setminus X) > \\#X\n\\].\n\nIf $X = Y$, then $\\#(Y \\setminus X) = 0$, and $\\#Y$ becomes $\\#X$.\n\n(d)\n$f: X \\rightarrow f(X)$ is always surjective. If $f$ is also injective, then $f$ is bijective. On this \noccasion, $\\#f(X) = \\#X$. If $f$ is not injective, we can select a set $X' \\subseteq X \\wedge X' \\neq X$, \non which $f$ is bijective. Then $\\#X' = \\#f(X') = \\#f(X)$. According to (c), $\\#X' < \\#X$, so \n$\\#f(X) < \\#X$.\n\n(e)\nSuppose that $\\#Y = n$. Use induction on $n$. \n\nWhen $n=0$, $Y$ is empty, then $\\#(X \\times Y) = 0 = \\#X \\times 0$. Here we additionally prove that \nwhen $n=1$, this is also true for further usage. When $n=1$, let $Y = \\{a\\}$. Then the bijection is \n$f(x):=(x,a), X \\rightarrow X \\times \\{a\\}$.\n\nSuppose that we have proven for some $n$, $\\#(X \\times Y) = \\#X \\times \\#Y$. Then when $\\#Y = S(n)$, \nlet $Y = Y\\setminus\\{x\\}\\cup\\{x\\}$, where $x \\in Y$. Lemma 3.6.9 tells us that \n$\\#(Y\\setminus\\{x\\}) = S(n)-1 = n$. And \\exerciseref{3.5.4} tells us that \n$X \\times Y = X \\times (Y\\setminus\\{x\\}) \\cup X \\times \\{x\\}$. \n\\begin{align*}\n\\#(X \\times Y) \n&= \\#(X \\times (Y\\setminus\\{x\\}) \\cup X \\times \\{x\\}) \\\\\n&= \\#(X \\times (Y\\setminus\\{x\\})) + \\#(X \\times \\{x\\}) \\\\\n&= \\#X \\times n + \\#X \\\\\n&= \\#X \\times S(n)\n\\end{align*}\n\nWe can now close the induction.\n\n(f)\nWe should first define $m^n$ for natural numbers $m,n$. It has not been done yet. Exponentiation is \ndefined for rational numbers at Definition 4.3.9.\n\\begin{definition}\n\\begin{itemize}\n\\item $m^0=1$,\n\\item $m^{S(n)} = m^n \\times m$\n\\end{itemize}\n\\end{definition}\n\nSuppose that $\\#Y = m,\\#X = n$. Use induction on $n$. \n\nWhen $n=0$, $X$ is empty, then $Y^X$ has one function $f:\\varnothing \\rightarrow Y$.\n\nSuppose that we have proven the statement for some $n$. Before we proceed the proof, we need some lemmas.\n\\begin{lem}\nIf $X$ is not empty, \n\\[\n\\#Y^{X\\setminus\\{x'\\}\\cup\\{x'\\}} = \\#Y^{X\\setminus\\{x'\\}} \\times \\#Y\n\\], \nwhere $x'$ is an element of $X$.\n\\end{lem}\n\\begin{proof}\nBy (e) we know that \n\\[\n\\#Y^{X\\setminus\\{x'\\}} \\times \\#Y = \\#(Y^{X\\setminus\\{x'\\}} \\times Y)\n\\].\n\nTry to build a bijection between $Y^{X\\setminus\\{x'\\}} \\times Y$ and $Y^X$. Let $f' \\in Y^X$.\n\nLet $h$ be a function from $Y^X$ to $Y^{X\\setminus\\{x'\\}} \\times Y$ such that\n\\[\nh(f') = (f,f'(x')), \n\\]\nwhere $f(x):=f'(x)$ when $x \\neq x'$. Now we show that $h$ is bijective.\n\nInjectivity: \nIf ${f_1}' \\neq {f_2}'$, then \n\\[\n{f_1}'(x') \\neq {f_2}'(x') \\vee \\exists x(x \\neq x' \\wedge {f_1}'(x) \\neq {f_2}'(x))\n\\]\nThat is, \n\\[\n{f_1}'(x') \\neq {f_2}'(x') \\vee f_1 \\neq f_2,\n\\]\nwhich means \n\\[\n(f_1,{f_1}'(x')) \\neq (f_2,{f_2}'(x')).\n\\]\n\nSurjectivity:\nFor any $(f,a) \\in Y^{X\\setminus\\{x'\\}} \\times Y$, let $f'$ be $f$ if $x\\neq x'$, and $f'(x') = a$. Then \n$f' \\in Y^X$ and $h(f') = (f,a)$.\n\nSo, \n\\[\n\\#Y^X = \\#(Y^{X\\setminus\\{x'\\}} \\times Y)\n\\], which gives the lemma.\n\\end{proof}\n\nNow we proceed the proof. Suppose that $\\#X = n+1$, then $\\#(X \\setminus\\{x'\\}) = n$. By induction \nhypothesis, $\\#(Y^{X \\setminus\\{x'\\}}) = m^n$. \n\nBy the lemma, \n\\[\n\\#Y^X = \\#Y^{X\\setminus\\{x'\\}\\cup\\{x'\\}} = \\#Y^{X\\setminus\\{x'\\}} \\times \\#Y,\n\\]\nwhich equals to $m^n \\times m$.\n\nNow we can close the induction.\n\nWe have proven that the cardinality of power sets obeys the definition of power. This ensures the \nexercise.\n\\end{proof}\n\n\\declareexercise{3.6.5}\n\\begin{proof}\nLet $f((x,y)):= (y,x), A\\times B \\rightarrow B \\times A$. The bijectivity is obvious. \n\nNow we are using set theory to prove the commutativity of multiplication of natural number. For any \nnatural number $m,n$, construct two sets: $M = \\mathbb{N}_{m}, N = \\mathbb{N}_{n}$. According to (e) in \nProposition 3.6.14, we have that $\\#(M \\times N) = \\#M \\times \\#N$. Then by what we have just proven, \n\\[\n\\#(M \\times N) = \\#(N \\times M) \\Longrightarrow \\#M \\times \\#N = \\#N \\times \\#M \\Longrightarrow mn = nm\n\\]\n\\end{proof}\n\n\\declareexercise{3.6.6}\n\\begin{proof}\nLet $c \\in C$, $f \\in (A^B)^C$. Then $f(c)$ is a function $B\\rightarrow A$. Let \n$b \\in B, h \\in A^{B\\times C}$. Let\n\\[\ng:A^{B\\times C} \\rightarrow (A^B)^{C}\n\\]\nbe such a function that for all $b,c$,\n\\[\ng(h) = f \\equiv h(b,c) = (f(c))\\,(b)\n\\]\n. Now we show that $g$ is bijective.\n\nInjectivity: \nIf $h \\neq h'$, then $\\exists b_0,c_0(h(b_0,c_0) \\neq h'(b_0,c_0))$. Let $g(h) =f, g(h') = f'$. Then we \nknow that $(f(c_0))\\,(b_0) \\neq (f'(c_0))\\,(b_0)$, so $f(c_0) \\neq f'(c_0) \\Longrightarrow f \\neq f'$. \nThat means, $g(h) \\neq g(h')$.\n\nSurjectivity:\nFor any $f \\in (A^B)^{C}$, let $h$ be such a function $\\in A^{B\\times C}$ that for all $b \\in B,c \\in C$, \n$h(b,c) := (f(c))\\,(b)$. It is easy to see that $h$ is well-defined. So $g(h) = f$.\n\nNote that by Proposition 3.6.14 we have $\\#M^N = m^n$ and $\\#(M \\times N) = mn$, where $\\#M =m, \\#N =n$. \nSuppose that $\\#A = a, \\#B = b, \\#C = c$, then\n\\[\n\\#(A^B)^C = (\\#A^B)^{\\#C} = (a^b)^c\n\\]\n\\[\n\\#A^{B\\times C} = \\#A^{\\#(B \\times C)} = a^{bc}\n\\]\nSo we have proven that $(a^b)^c = a^{bc}$.\n\nNow we try to prove $a^b \\times a^c = a^{b+c}$. Let $B,C$ be disjoint sets with the cardinality $b,c$ \nrespectively. What we need to show is that\n\\[\n\\#(A^B \\times A^C) = \\#(A^{B \\cup C}).\n\\]\n\nSimilarly, let \n\\[\nf: (A^{B \\cup C}) \\rightarrow (A^B \\times A^C)\n\\]\nbe such a function that \n\\[\nf(g) = (u,v) \\equiv \\forall x(x \\in B \\Rightarrow g(x) = u(x) \\wedge x \\in C \\Rightarrow g(x) = v(x)),\n\\]\nwhere $g\\in A^{B \\cup C}, (u,v) \\in A^B \\times A^C$.\n\nWe can verify the bijectivity of $f$ nearly in the same way as way did previously. So I won't write it \ndown here.\n\nThen, we know $B \\cap C = \\varnothing \\Rightarrow \\#(B \\cup C) = \\#B + \\#C$. So we can conclude that \n\\[\na^b \\times a^c = a^{b+c}\n\\]\n\\end{proof}\n\n\\declareexercise{3.6.7}\n\\begin{proof}\nOn one hand, if $\\#A = a \\leq \\#B = b$, we show that $A$ has lesser or equal cardinalty to $B$. Let $f$ \nbe a bijection from $A$ to $\\mathbb{N}_{a}$, $g$ be a bijection from $B$ to $\\mathbb{N}_b$. Let \n$\\iota(x):=x, \\mathbb{N}_{a} \\rightarrow \\mathbb{N}_b$. Then $g^{-1} \\circ \\iota \\circ f$ is an injection \nfrom $A$ to $B$.\n\nOn the other hand, suppose that there is an injection $f$ from $A$ to $B$. We know that \n$f:A\\rightarrow f(A)$ is bijective. So $\\#A = \\#f(A)$. Since $f(A) \\subseteq B$, $\\#f(A) \\leq B$ (See (c) \nin Proposition 3.6.14). That is, $\\#A \\leq \\#B$\n\\end{proof}\n\n\\declareexercise{3.6.8}\n\\begin{proof}\n$f:A \\rightarrow f(A)$ is bijective. So $f^{-1}: f(A) \\rightarrow A$ is surjective. Let $g$ be defined as:\n\\begin{itemize}\n\\item $b \\in f(A) \\Longrightarrow g(b) = f^{-1}(b)$\n\\item $b \\in B\\setminus f(A) \\Longrightarrow g(b)$ is any element of $A$.\n\\end{itemize}\n\nThen $g$ is surjective.\n\\end{proof}\n\n\\declareexercise{3.6.9}\n\\begin{proof}\n\\begin{align*}\n\\#A + \\#B \n&= \\#(A - A \\cap B) + \\#(A \\cap B) + \\#(B - A \\cap B) + \\#(A \\cap B) \\\\\n&= (\\#(A - A \\cap B) + \\#(A \\cap B) + \\#(B - A \\cap B)) + \\#(A \\cap B) \\\\\n&= \\#(A \\cup B) + \\#(A \\cap B)\n\\end{align*}\n\\end{proof}\n\n\\paragraph{Exercise 3.6.10} \\label{exercise3.6.10}\n\\begin{proof}\nPresume the negation:\n\\[\n\\forall i(i \\in \\{1,\\dots,n\\} \\Longrightarrow \\#(A_i) < 2)\n\\]\n\nUse mathematical induction for (b) in Proposition 3.6.14, we can easily get:\n\\[\n\\#\\bigcup_{i \\in \\{1,\\dots,n\\}}A_i \\leq \\sum_{i \\in \\{1,\\dots,n\\}} \\#A_i\n\\]\nWe can also use mathematical induction to furthermore enhance what we proved while dealing with natural \nnumbers to:\n\\[\n\\bigwedge_{i} a_{i} \\leq b_{i} \\Longrightarrow \\sum_{i} a_{i} \\leq \\sum_{i} b_i\n\\].\n\nThen because $\\# A_i \\leq 1$, so \n\\[\n\\sum_{i \\in \\{1,\\dots,n\\}} A_i \\leq (\\sum_{i \\in \\{1,\\dots,n\\}} 1 = n)\n\\], \nwhich is impossible.\n\\end{proof}", "meta": {"hexsha": "65b10fdd1befd8a29df1c751aa6b06468fc8ce2e", "size": 59789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Set Theory.tex", "max_stars_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_stars_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Set Theory.tex", "max_issues_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_issues_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Set Theory.tex", "max_forks_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_forks_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_forks_repo_licenses": ["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.9308894231, "max_line_length": 196, "alphanum_fraction": 0.61880948, "num_tokens": 22767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746407, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6281651678806756}}
{"text": "\\subsection{Quotient spaces}\n\\begin{defn}\nLet $X$ be a topological space and $\\sim$ an equivalence relation\non $X$. ($a\\sim a$, $a\\sim b\\Leftrightarrow b\\sim a,a\\sim b,b\\sim c,a\\sim c$.)\nLet $Y=X/\\sim$ be the set of equivalence classes and define\n\n\\begin{align*}\n\\pi:X\\to Y=X/\\sim\\\\\n\\pi(x)=[x]=\\text{equiv class of \\ensuremath{X}under \\ensuremath{\\sim}}\n\\end{align*}\n\n\nthen the quotient space $Y=X/\\sim$ has a \\emph{quotient topology}\nsuch that $V\\subseteq X/\\sim$ is open iff $\\pi^{-1}(V)$ is open\nin $X$.\n\nNote: A continuous map $f:X\\to Y$ is a \\emph{quotient map} if $f$\nis onto and $U\\subset Y$ is open $\\Leftrightarrow$ $f^{-1}(U)$\nis open in $X$.\n\\end{defn}\n\n\\begin{thm}\n$g:X/\\sim\\to Z$ is continuous $\\Leftrightarrow$ $g\\circ\\pi:X\\to Z$\nis continuous.\n\n\\begin{align*}\n\\xymatrix{X\\ar[r]^{g\\circ\\pi}\\ar[d]_{\\pi} & Z\\\\\nX/\\sim\\ar[ur]_{g}\n}\n\\end{align*}\n\\end{thm}\n\\begin{cor}\nLet $f:X\\to Z$ be a continuous map which is constant of equivalence\nclasses (if $u\\sim v$ then $f(u)=f(v)$), then $f$ induces a unique\ncontinuous map $\\bar{f}:X/\\sim\\to Z$ such that $\\bar{f}\\circ\\pi=f$.\n\\end{cor}\n\\begin{align*}\n\\xymatrix{X\\ar[r]^{f}\\ar[d]_{\\pi} & Z\\\\\nX/\\sim\\ar[ur]_{\\bar{f}}\n}\n\\end{align*}\n\n\nNote: $\\pi:X\\to X/\\sim$ is continuous, so if $X$ is compact or connected\nor path connected, then so is $X/\\sim$.\n\\begin{thm}\nIf $f:X\\to Y$ continuous and onto, and\\end{thm}\n\\begin{itemize}\n\\item $f$ is an open map, or\n\\item $f$ is a closed map\n\\end{itemize}\nthen $Y\\approx X/\\sim$ where $x\\sim y\\Leftrightarrow f(x)=f(y)\\forall x,y\\in X$.\n\\begin{defn}\nLet $X,Y$ be topological spaces. Two continuous maps $f,g:X\\to Y$\nare \\emph{homotopic} if there exists a continuous map $F:X\\times I\\to Y$\nsuch that $F(x,0)=f(x)$ and $F(x,1)=g(x)$ for all $x\\in X$. We\nwrite $f\\simeq g$ if $F$ exists, and say that $F$ is a homotopy\nfrom $f$ to $g$.\\end{defn}\n\\begin{thm}\nHomotopy is an equivalence relation on the set of all continuous maps\n$\\{\\text{cts maps}:X\\to Y\\}$ between spaces $X,Y$. I.e.\\end{thm}\n\\begin{itemize}\n\\item $f\\simeq f$\n\\item If $f\\simeq g\\implies g\\simeq f$\n\\item If $f\\simeq g$, $g\\simeq h$, $\\implies f\\simeq h$.\n\\end{itemize}\nNote: Let $X=A\\cup B$, $A,B$ subspaces of $X$. Suppose $f:A\\to Y$,\n$g:B\\to Y$ are continuous maps such that $f(x)=g(x)$ $\\forall x\\in A\\cap B$.\nThen define $h:A\\cup B\\to Y$ by \n\n\\begin{align*}\nh(x) & =\\begin{cases}\nf(x) & x\\in A\\\\\ng(x) & x\\in B\n\\end{cases}\n\\end{align*}\n\n\nthen $h$ is continuous if either\n\\begin{itemize}\n\\item $A,B$ are closed subsets\n\\item $A,B$ are open subsets\\end{itemize}\n\\begin{defn}\nLet $f,g:X\\to Y$ be continuous maps which agree on $A$. Then $f\\simeq g$\n\\emph{relative to $A$ }if there is a homotopy $F:f\\to g$ which fixes\nall points in $A$. I.e. we have $F:X\\times I\\to Y$ with $F(x,0)=f(x)$\n$F(x,1)=g(x)$ and $\\forall a\\in A$ $F(a,t)=f(a)=g(a)$ $\\forall t$.\n\\end{defn}\n\n\\begin{defn}\nA continuous map $f:X\\to Y$ is a \\emph{homotopy equivalence} if there\nexists a continuous map $g:Y\\to X$ such that\n\n\\begin{align*}\ng\\circ f\\simeq1_{X}:X\\to X\\\\\nf\\circ g\\simeq1_{y}:Y\\to Y\n\\end{align*}\n\n\nwe say that $X$ and $Y$ are homotopy equivalent of there exists\nsuch a map, and write $X\\simeq Y$.\n\\end{defn}\n\n\\begin{defn}\nA topological space $X$ is \\emph{contractible} if the identity map\n$\\text{id}_{X}:X\\to X$ is homotopic to a constant map $c:X\\to X,c(x)=x_{0}$\nfor all $x\\in X$.\n\nNote/Exercise: $X$ contractible $\\Leftrightarrow$ $X\\simeq\\{\\text{pt}\\}$.\n\\end{defn}\n\n\\begin{defn}\nGiven $A$ a subspace of $X$, a \\emph{(strong) deformation retraction}\nof $X$ onto $A$ is a homotopy rel $A$, $H:X\\times I\\to X$ such\nthat $H_{0}=1_{X}$, $H_{1}:X\\to A$. Then we have $A\\simeq X$.\n\\end{defn}\n\n\\begin{defn}\nLet $\\pi_{1}(X,x_{0})$ be a set of homotopy classes (rel endpoints)\nof loops in $X$ based at $x_{0}$ (with a suitably defined product.)\nThis is the \\emph{fundamental group of $X$ at $x_{0}$.}\\end{defn}\n\\begin{thm}\nIf $X$ is path connected, then $\\pi_{1}(X,x_{0})\\cong\\pi_{1}(X,x_{j})\\forall x_{j}\\in X$.\n\\marginpar{Maybe add in the picture?}\n\\end{thm}\n\n\n\\textbf{Effects of continuous maps}\n\nLet $f:X\\to Y$ be a continuous map. Then\n\\begin{itemize}\n\\item $\\alpha$ a path in $X$ $\\implies$ $f\\circ\\alpha=f\\alpha$ is a\npath in $Y$\n\\item $\\alpha\\sim\\alpha'$ in $X\\implies f\\circ\\alpha\\sim f\\circ\\alpha'$\nin $Y$.\n\\item $\\alpha$ a loop at $x_{0}$ $\\implies f\\circ\\alpha$ is a loop at\n$f(x_{0})$. So there is a well-defined function $f_{*}:\\pi_{1}(X,x_{0})\\to\\pi_{1}(F,f(x_{0}))$\ngiven by $f_{*}([\\alpha])=[f\\circ\\alpha]$.\\end{itemize}\n\\begin{thm}\n~\\end{thm}\n\\begin{enumerate}\n\\item $f_{*}$ is a group homomorphism.\n\\item If $f=\\text{identity}=1_{X}:X\\to X$ then the induced map is the identity\nmap $f_{*}:\\pi_{1}(X,x_{0})\\to\\pi_{1}(X,x_{0})$.\n\\item $(f\\circ g)_{*}=f_{*}\\circ g_{*}$.\\end{enumerate}\n\\begin{cor}\nIf $f:X\\to Y$ is a homeomorphism, then $f_{*}:\\pi_{1}(X,x_{0})\\to\\pi_{1}(Y,f(x_{0}))$\nis a group isomorphism. So the fundamental group is a topological\ninvariant.\\end{cor}\n\\begin{thm}\nLet $f,g:X\\to Y$ be homotopic maps via a homotopy $F:X\\times I\\to Y$.\nLet $\\gamma:I\\to Y$ be the path $\\gamma(t):F(x_{0},t)$ traced out\nby the basepoint $x_{0}$ under $F$ and let $y_{0}:y(0)=F(x_{0},0)$,\n$y_{1}=y(1)=F(x_{0},1)$, then $g_{*}=\\gamma_{*}\\circ f_{*}$ where\n$\\gamma_{*}([\\alpha])=[\\gamma^{-1}*\\alpha*\\gamma]=\\text{change of base point isomorphism}$,\ni.e. the diagram\n\n\\begin{align*}\n\\xymatrix{\\pi_{1}(X,x_{0})\\ar[dr]_{g_{*}}\\ar[r]^{f_{*}} & \\pi_{1}(Y,y_{0})\\ar[d]_{\\gamma_{*}\\cong}\\\\\n & \\pi_{1}(Y,y_{1})\n}\n\\end{align*}\n\n\ncommutes.\n\nNote: If $F$ does not move the basepoint $x_{0}$ then $\\gamma_{*}=\\text{id}$\nand $f_{*}=g_{*}$.\\end{thm}\n\\begin{lem}\nLet $G:I\\times I\\to Y$ be continuous and let $a,b:I\\to I\\times I$\nbe paths such that $a(0)=b(0)$ and $a(1)=b(1)$. Then $G\\circ a\\cong G\\circ b$\nrel endpoints.\n\\end{lem}\nApplication: If $f:X\\to Y$ is a homotopy-equivalence then $f_{*}:\\pi_{1}(X,x_{0})\\to\\pi_{1}(Y,f(x_{0}))$\nis an ismorphism for all $x_{0}\\in X$. So homotopically-equivalence\nspaces has isomorphic fundamental groups.\n\\begin{defn}\n$X$ is simply-connected if $X$ is path connected and $\\pi_{1}(X,x_{0})\\cong\\{1\\}$\nfor all $x_{0}\\in X$.\\end{defn}\n\\begin{lem}\nIf $X\\simeq Y$ then $X$ is path connected iff $Y$ is path connected.\\end{lem}\n\\begin{thm}\nLet $p_{1}:X\\times Y\\to X$ and $p_{2}:X\\times Y\\to Y$ be projection\nmaps. Then $(p_{1*})\\times(p_{2*}):\\pi_{1}(X\\times Y,(x_{0},y_{0}))\\to\\pi_{1}(X,x_{0})\\times\\pi_{1}(Y,y_{0})$\nis an isomorphism. Explicitly\n\n\\begin{align*}\np_{1*}\\times p_{2*}([\\alpha]) & =([p_{1}\\circ\\alpha],[p_{2}\\circ\\alpha])\n\\end{align*}\n\\end{thm}\n\\begin{lem}\n(Homotopy lemma) If $\\alpha_{0},\\alpha_{1}:I\\to S^{1}$ are paths\nsuch that $\\alpha_{0}\\simeq\\alpha_{1}$ rel endpoints, then $\\deg(\\alpha_{0})=\\deg(\\alpha_{1})$.\n(Where we defined the degree to be that ``distance moved upwards'',\ni.e. $\\tilde{\\alpha}(1)$, where $\\tilde{\\alpha}$ is the lifted path. \\end{lem}\n\\begin{thm}\n(Fundamental theorem of algebra) Every non-constant polynomial with\ncomplex coefficients has a complex zero.\n\nIdea:\\end{thm}\n\\begin{enumerate}\n\\item Let $f:B\\to\\mathbb{C}$ be continuous and defined on a closed 2-ball\n$B\\approx B^{2}$. Assume $f(z)\\neq0$ on the boundary, i.e. $\\forall z\\in\\partial B\\approx S^{1}$.\nDefine $g:\\partial B\\to S^{1}$ by $g(z)=f(z)/|f(z)|$ (continuous).\nThen If $g_{*}:\\pi_{1}(\\partial B)\\cong\\mathbb{Z}\\to\\pi_{1}(S^{1})\\cong\\mathbb{Z}$\nis non-trivial $f$ has a zero inside $B$. (To prove this, try the\ncontrapositive.)\n\\item To prove FTA: Apply this result to $f(z)=z^{n}+a_{n-1}z^{n-1}+\\cdots$\nand $B$ a sufficiently large ball of radius $r$ around the origin.\\end{enumerate}\n\\begin{thm}\nAny homeomorphism $B^{2}\\to B^{2}$ takes $\\partial B^{2}=S^{1}$\nto $S^{1}$. (Idea: Remove various points.)\n\\end{thm}\n\n", "meta": {"hexsha": "9a0619b2185f245b49472415773c22277f1eb03b", "size": 7692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quotient_spaces.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": "quotient_spaces.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": "quotient_spaces.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": 35.776744186, "max_line_length": 109, "alphanum_fraction": 0.6484659386, "num_tokens": 3083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6281651678806754}}
{"text": "\\documentclass[]{article}\n\n\\usepackage{amsmath}\n\\usepackage[backend=bibtex]{biblatex}\n\\addbibresource{main.bib}\n\n%opening\n\\title{Multiple Disjunctively Constrained Knapsack Problem}\n\\author{Marco Favorito}\n\\date{}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nIn this document, we will present a problem, \\emph{Multiple Disjunctively Constrained Knapsack Problem} (MDCKP), that is a combination of well-known problems: \\emph{Multiple 0-1 Knapsack Problem} (MKP) and \\emph{Disjunctively Constrained Knapsack Problem} (DCKP). Linear programming formulation is provided, as well as correlations with other Knapsack problem variants. Finally, we describe a (naive) algorithm.\n\\end{abstract}\n\n\\section{Introduction}\n\nMultiple Disjunctively Constrained Knapsack Problem (MDCKP) is a combination of two Knapsack-like problems, namely: \n\n\\begin{itemize}\n\t\\item Multiple 0-1 Knapsack Problem (MKP) \\cite{Lagoudakis96the0-1, Martello:1990:KPA:98124};\n\t\\item Disjunctively Constrained Knapsack Problem (DCKP) \\cite{Senisuka_reductionand}\n\\end{itemize}\n\nInformally, it is about how to assign $n$ items to $m$ knapsacks, each of them with limited capacity, in order to maximize the total profit of assigned items, where:\n\\begin{itemize}\n\t\\item each item has a weight;\n\t\\item there are some items that cannot be assigned to the same knapsack, due to intrinsic incompatibility.\n\\end{itemize}\n\n\\section{Linear Programming}\nMore formally, we have $n$ items, each of them with $p_1, \\dots, p_n$ profits and $w_1, \\dots, w_n$ weights.  Each of them can be assigned to only one of the $m$ knapsacks, which have capacities $c_1, \\dots, c_m$. Let $E$ be the set of incompatible pairs, such that $(i, j)\\in E$ iff items $i$ and $j$ are incompatible. To avoid duplicates, we define $E \\subset \\{(i, j) | 1 \\le i \\neq j \\le n\\}$ and assume $E$ to be a reflective relation.\n\nNow follow a LP formulation of the problem:\n\n\\begin{align*}\n\\text{maximize }   & \\sum_j^m \\sum_i^n p_i x_{ij} \t&\\\\\n\\text{subject to } & \\sum_i^n w_i x_{ij} \\le c_j \t& j \\in M = \\{1, \\dots m\\}\\\\\n\t\t\t\t   & \\sum_j^m x_{ij} \\le 1 \t\t\t& i \\in N = \\{1, \\dots n\\}\\\\\n\t\t\t\t   & x_{kj} + x_{hj} \\le 1\t\t\t& (k, h)\\in E, j\\in M\\\\\n\t\t\t\t   & x_{ij} \\in \\{0, 1\\} \t\t\t& i \\in N, j \\in M\\\\\n\\end{align*}\nwhere:\n\n\\begin{equation*}\nx_{ij} = \\begin{cases}\n\t1 & \\text{if item $i$ is assigned to knapsack $j$} \\\\\n\t0 & \\text{otherwise}\n\\end{cases}\n\\end{equation*}\n\nNotice: with $E=\\emptyset$ and $m=1$, the problem reduces to the classic 0-1 Knapsack problem. Hence, MDCKP is $\\mathcal{NP}$-hard, since KP is $\\mathcal{NP}$-hard too.\n\n\\section{Naive Approximation Algorithm}\nThe simplest approximation algorithm one can think of is the following:\n\\begin{itemize}\n\t\\item sort the items by non-increasing profit per weight, that is:\n\t\\begin{equation*}\n\t\tp_1/w_1 \\ge p_2/w_2 \\ge \\dots \\ge p_n/w_n\n\t\\end{equation*}\n\t\\item start to fill up the knapsacks and, if there is not enough capacity or there is some incompatibility with other items, then go to the next knapsack. If no knapsack is available, then leave the item out.\n\t\\item perform some local search algorithm by defining the neighborhood of a solution as the following:\n\t\n\t\\paragraph{} Look for a pair of items, one inside and the outer outside the knapsacks, and see if it is possible to exchange those items. If the exchange yields a better solution, swap the items.\n\t\n\\end{itemize}\n\n\\section{Implementation}\nWe provided an implementation of the approximation algorithm in C++. \n\nThe input file should have this format:\n\\begin{align*}\n&n\\ m\t\t\t\t\t\t\t\t    \\\\\n&c_1 \\; c_2 \\; \\dots \\; c_m\t\t\t    \\\\\n&p_1 \\; w_1\t\t\t\t\t\t\t    \\\\\n& \\vdots\t\t\t\t\t\t\t    \\\\\n&p_n \\; w_n\t\t\t\t\t\t\t    \\\\\n& i \\; j \\; \\;\t(\\forall (i,j)\\in E)\t\\\\\n\\end{align*}\n\nWhereas the output file:\n\n\\begin{align*}\n&\\sum_j^m \\sum_i^n p_i x_{ij}\t\t\t\\\\\n&x_{11} \\; x_{21} \\; \\dots \\; x_{n1}    \\\\\n\\vdots\t\t\t\t\t\t\t\t\t\\\\\n&x_{1m} \\; x_{2m} \\; \\dots \\; x_{nm}    \\\\\n\\end{align*}\n\n\\subsection{Example}\n\nTo build the solution:\n\\begin{verbatim}\nmkdir build && cd build\ncmake ..\nmake -j4\n\\end{verbatim}\n\nTo run the algorithm:\n\\begin{verbatim}\nbuild/apps/mdckp-cli/mdckp-cli < input_file\n\\end{verbatim}\n\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "13a56c2087c8a288d7c7cbf8bd24d447a8672a08", "size": 4144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/main.tex", "max_stars_repo_name": "MarcoFavorito/MDCKP", "max_stars_repo_head_hexsha": "db85a015ef23d37a1a0a14e73eb3b5f103af442f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-01T21:22:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-01T21:22:17.000Z", "max_issues_repo_path": "docs/main.tex", "max_issues_repo_name": "MarcoFavorito/MDCKP", "max_issues_repo_head_hexsha": "db85a015ef23d37a1a0a14e73eb3b5f103af442f", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "MarcoFavorito/MDCKP", "max_forks_repo_head_hexsha": "db85a015ef23d37a1a0a14e73eb3b5f103af442f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-29T09:19:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T09:19:28.000Z", "avg_line_length": 37.0, "max_line_length": 440, "alphanum_fraction": 0.6993243243, "num_tokens": 1338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6281651662794759}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\\title{Probability: Quiz 1}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\\section{Problem 1}\n\tIndicate  \\textit{True} or \\textit{False} for each claim.\n\t\\subsection{Part A}\n\tIf $\\mathbf{P}(A) \\leq \\mathbf{P}(B)$, then $A \\subseteq B$.\\\\\n\t\\textbf{False}. Let $A$ and $B$ be independent, but $\\mathbf{P}(A) \\leq \\mathbf{P}(B)$.\n\t\\\\\n\t\\subsection{Part B}\n\tIf $\\mathbf{P}(B) > 0$, $\\mathbf{P}(A|B)$ is at least as large as $\\mathbf{P}(A)$.\\\\\n\t\\textbf{False}. $\\mathbf{P}(A)$ can decrease if it is dependent on $B$. For example, the probability of rain today ($\\mathbf{P}(A)$) may historically be 35\\%. But the probability of rain today given clear skies ($\\mathbf{P}(A|B)$) is lower than $\\mathbf{P}(A)$.\\\\\n\t\\subsection{Part C}\n\tIf $\\mathbf{E}[X] > \\mathbf{E}[Y]$, then $\\mathbf{E}[X^2] > \\mathbf{E}[Y^2]$.\\\\\n\t\\textbf{False}. Let $X$ take the values 0 and 1 with equal probability, and $Y$ take the values -4 and -2 with equal probability. $\\mathbf{E}[X]=0.5 > \\mathbf{E}[Y] = -3$. But $\\mathbf{E}[X^2]=0.5 < \\mathbf{E}[Y^2] = 10$.\\\\\n\t\\subsection{Part D}\n\tSuppose $\\mathbf{P}(A) > 0$. Then $\\mathbf{E}[X] = \\mathbf{E}[X|A]+ \\mathbf{E}[X|A^C]$.\\\\\n\t\\textbf{False}. Assume $X$ is independent of $A$. Then $\\mathbf{E}[X]=\\mathbf{E}[X|A]= \\mathbf{E}[X|A^C]$, so $\\mathbf{E}[X|A]+ \\mathbf{E}[X|A^C] = 2\\mathbf{E}[X]$.\\\\\n\t\\subsection{Part E}\n\tIf $X$ and $Y$ are independent and $\\mathbf{P}(C)>0$, then $p_{X,Y|C}(x,y) = p_{X|C}(x)p_{Y|C}(y)$.\\\\\n\t\\textbf{False}. Independence between $X$ and $Y$ does not guarantee conditional independence.\\\\\n\t\\subsection{Part F}\n\tIf for some constant $c$, we have $\\mathbf{P}(\\{X>c\\})=\\frac{1}{2}$, then $\\mathbf{E}[X]>\\frac{c}{2}$.\\\\\n\t\\textbf{False}. Let $X$ take the values between -1 and 1, uniformly. $\\mathbf{P}(\\{X>0\\})=\\frac{1}{2}$, and $\\mathbf{E}[X] = 0 \\ngtr \\frac{0}{2}$.\\\\\n\t\\subsection{Part G}\n\tIn a game involving the flip of a fair coin, you win a dollar for each head flipped. The maximum number of flips is 10, but the game ends when you flip a tail. The expected gain from this game is 1.\\\\\n\t\\textbf{False}. $\\mathbf{E}[g(X)] = \\sum g(x) p_X(x) = \n\t\\sum_{k=0}^{9}\\left(k(0.5)^{k+1}\\right) + (0.5)^{10} = 0.99902$.\\\\\n\t\\subsection{Part H}\n\tLet $X$ be a uniformly distributed continuous random variable over some interval $[a,b]$. We can uniquely describe $f_X(x)$ from knowing its mean and variance.\\\\\n\t\\textbf{True}. For a uniform distribution, $\\mathbf{E}[X]=\\frac{a+b}{2}$ and $\\sigma_X^2 = \\frac{(b-a)^2}{12}$. Two equations and two unknowns result in a solvable system of equations for $a$ and $b$.\\\\\n\t\\subsection{Part I}\n\tLet $X$ be an exponentially distributed random variable with a probability density function $f_X(x)= e^{-x}$. $P\\left(\\{0 \\leq X \\leq 3\\} \\cup \\{2 \\leq X\\leq 4\\}\\right) = 1-e^{-4}$.\\\\\n\t\\textbf{True}. $P\\left(\\{0 \\leq X \\leq 3\\} \\cup \\{2 \\leq X\\leq 4\\}\\right) = \\int_{0}^{4}e^{-x}  dx = 1-e^{-4}$.\\\\\n\t\\subsection{Part J}\n\tLet $X$ be a normal random variable with mean 1 and variance 2. Let $Y$ be a normal random variable with mean 1 and variance 1. $\\mathbf{P}(X<0) < \\mathbf{P}(Y<0)$.\\\\\n\t\\textbf{False}. Since $X$ has a larger variance than $Y$ its tails are thicker, thus the integral over the left tail will be greater for $X$ and $Y$.\n\t\\pagebreak\n\t\\section{Problem 2}\n\tMarketing Team A has found that 1/4 of their customers are low-frequency buyers. But out of their low-frequency buyers, 1/3 are high spenders, whereas 1/10 of their high-frequency buyers are high spenders. Assume that each customer is either low-frequency or high frequency, and low spender of high spender.\\\\\n\t\\subsection{Part A}\n\tCompute the probability that a randomly chosen customer is a high spender.\\\\\n\t$\\mathbf{P}(HS)=\\mathbf{P}(HFB)\\mathbf{P}(HS|HFB)+\\mathbf{P}(LFB)\\mathbf{P}(HS|LFB)=\\frac{1}{4}\\frac{1}{3}+\\frac{3}{4}\\frac{1}{10} = \\frac{19}{120}$.\\\\\n\t\\subsection{Part B}\n\tCompute the probability that a randomly chosen customer is a high-frequency buyer given that they are a low spender.\\\\\n\t$\\mathbf{P}(HFB|LS) = \\frac{\\mathbf{P}(HFB)\\mathbf{P}(LS|HFB)}{\\mathbf{P}(LS)} = \\frac{\\frac{3}{4}\\frac{9}{10}}{1-\\frac{19}{120}}=\\frac{81}{101}$\\\\\\\\\n\tYou are told that the only products sold are books (B), CDs (CD), and DVDs (DVD). Marketing team B has found three customer groups $C_1$, $C_2$, $C_3$. These groups are collectively exhaustive and mutually exclusive. Each customer is equally likely to be in any group, and customers are \\textit{i.i.d.}. Each customer only buys one item per day. Marketing team B has determined the following purhcasing conditional probabilities:\\\\\n\t\\begin{table}[h!]\n\t\t\\centering\n\t\t\\begin{tabular}{rcl}\n\t\t\t$\\mathbf{P}(B|C_1)$&=&$\\frac{1}{2}$\\\\\n\t\t\t$\\mathbf{P}(CD|C_1)$&=&$\\frac{1}{4}$\\\\\n\t\t\t$\\mathbf{P}(DVD|C_1)$&=&$\\frac{1}{4}$\\\\\n\t\t\t$\\mathbf{P}(B|C_2)$&=&$\\frac{1}{2}$\\\\\n\t\t\t$\\mathbf{P}(CD|C_2)$&=&$0$\\\\\n\t\t\t$\\mathbf{P}(DVD|C_2)$&=&$\\frac{1}{2}$\\\\\n\t\t\t$\\mathbf{P}(B|C_3)$&=&$\\frac{1}{3}$\\\\\n\t\t\t$\\mathbf{P}(CD|C_3)$&=&$\\frac{1}{3}$\\\\\n\t\t\t$\\mathbf{P}(DVD|C_3)$&=&$\\frac{1}{3}$\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\subsection{Part C}\n\tCompute the probability that a customer purchases a book or CD.\\\\\n\tSince $C_1$, $C_2$, and $C_3$ are mutually exclusive and customers are \\textit{i.i.d.},\\\\\n\t$\\mathbf{P}(B\\cup CD) = \\mathbf{P}(B) + \\mathbf{P}(CD)$\\\\\n\t$\\mathbf{P}(B) = \\sum_{i=1}^{3} \\mathbf{P}(C_i)\\mathbf{P}(B|C_i) = \\frac{1}{6} + \\frac{1}{6} + \\frac{1}{9} = \\frac{4}{9}$\\\\\n\t$\\mathbf{P}(CD) = \\sum_{i=1}^{3} \\mathbf{P}(C_i)\\mathbf{P}(CD|C_i) = \\frac{1}{12} + 0 + \\frac{1}{9} = \\frac{7}{36}$\\\\\n\t$\\mathbf{P}(B\\cup CD) = \\frac{4}{9} + \\frac{7}{36} = \\frac{23}{36} \\approx 0.6389$\\\\\n\t\\subsection{Part D}\n\tCompute the probability that a customer is in group $C_2$ or $C_3$ given they purchased a book.\\\\\n\t$\\mathbf{P}(C_2 \\cup C_3 | B) = \\frac{\\mathbf{P}(C_2 \\cup C_3) \\mathbf{P}(B|C_2 \\cup C_3)}{\\mathbf{P}(B)}=\n\t\\frac{\\mathbf{P}(B \\cap (C_2 \\cup C_3))}{\\mathbf{P}(B)} = \\frac{\\mathbf{P}(B \\cap C_2) + \\mathbf{P}(B \\cap C_3)}{\\mathbf{P}(B)} = \\frac{5}{8}$\\\\\n\t\\\\\n\tEach book costs \\$15, each CD costs \\$10, and each DVD costs \\$15.\n\t\\subsection{Part E}\n\tCompute the PDF, expected value, and variance of the revenue ($R$) collected by a single customer's purchase.\n\t\\\\\n\t$\\mathbf{P}(R=\\text{\\$10})=\\mathbf{P}(CD) = \\frac{7}{36}$\\\\\n\t$\\mathbf{P}(R=\\text{\\$15})=\\mathbf{P}(B)+\\mathbf{P}(DVD) = \\frac{4}{9}+\\frac{13}{36}$\\\\\n\t\\[\n\tp_R(r) = \n\t\\begin{cases}\n\t\t\\frac{7}{36} & r = \\$10\\\\\n\t\t\\frac{29}{36} & r = \\$15\\\\\n\t\t0 & \\text{otherwise}\n\t\\end{cases}\n\t\\]\\\\\n\t$\\mathbf{E}[R] = \\sum r \\cdot p_R(r) = 10(\\frac{7}{36}) + 15(\\frac{29}{36}) = \\$14.03$\\\\\\\\\n\t$\\text{Var}(R) = \\sum (r-\\textbf{E}[R])^2 \\cdot p_R(r) \\approx 3.9159$\\\\\n\t\\subsection{Part F}\n\tIf the store gets $n$ customers in a day, what is the total expected revenue and variance?\\\\\n\t$\\text{Total Revenue}~ TR = nR$\\\\\n\t$\\mathbf{E}[TR] = \\mathbf{E}[nR] = n\\mathbf{R} = n\\cdot\\$14.03$\\\\\\\\\n\t$\\text{Var}(nR) = n^2\\text{Var}(R) = n^2\\cdot \\$3.9159$\\\\\n\t\\subsection{Part G}\n\tSkip is an abnormal customer. When he goes to the store, he flips a fair coin until he gets his seconds tails. The number of heads that have been flipped is the number of DVDs he buys. What is the expected dollar amount he spends and the variance?\\\\\n\t\\\\\n\tThis process follows the $k$th arrival time process, modeled by the pascal distribution. Each time Skip flips his coin, he has a 50\\% probability of getting tails. We want to know the expected number of flips it takes to get his second tails. The number of heads is 2 less than this number since 2 of them are the 2 arrivals of tails.\n\t\\\\\\\\\n\t$\\text{For pascal},~\\mathbf{E}[Y_k] = \\frac{k}{p}$\\\\\n\t\\\\\n\t$\\mathbf{E}[Y_2] = \\frac{2}{0.5} = 4$\\\\\n\tThus, the expected number of heads is 2, resulting in an expected revenue of \\$30.\n\t\\\\\\\\\n\t$\\text{For pascal},~\\text{Var}[Y_k] = \\frac{k(1-p)}{p^2}$\\\\\n\t\\\\\n\t$\\text{Var}(Y_2) = \\frac{2(1-0.5)}{0.5^2}=4$\\\\\n\t$\\text{Var}(R) = \\text{Var}(\\$15\\cdot Y_2) = \\$15^2\\text{Var}(Y_2) = \\$900$\n\t\\pagebreak\n\t\\section{Problem 3}\n\tWe have $s$ urns and $n$ balls ($n \\geq s$). Each ball is placed in an urn at random. Each ball has equal probability of being placed in any urn, and it's placement is independent of the other ball placements. Each urn can fit any number of balls.\\\\\n\tDefine the following random variables:\\\\\\\\\n\tLet $X_i$ be the number of balls in urn $i$.\\\\\n\tLet $Y_k$ be the number of urns that have exactly $k$ balls.\\\\\n\t\\subsection{Part A}\n\tAre the $X_i$'s independent? Why or why not?\\\\\n\t\\textbf{They are not independent.}  Without loss of generality, if $X_1=j$, then $X_2$ through $X_s$ can be at most $n-j$.\\\\\n\t\\subsection{Part B}\n\tFind the PMF, mean, and variance of $X_i$.\\\\\n\t\\\\\n\tIf there are $k$ balls in urn $i$, there must have been $k$ occurrences of successful placement, and $n-k$ occurrences of unsuccessful placement: $p^k(1-p)^{(n-k)}$. Since the order in which the $k$ balls are placed in urn $i$ does not matter, there are $\\binom{n}{k}$ possible combinations of this placement. Since urn placement is equally distributed, the probability of placement in urn $i$ is $\\frac{1}{s}$. Thus, the PMF is:\n\t\\[\n\t\tp_{X_{i}}(k) = \\left(\\frac{1}{s}\\right)^k \\left(1-\\frac{1}{s}\\right)^{(n-k)}\\binom{n}{k}\n\t\\]\\\\\n\t\\\\\n\tThis PMF is the binomial distribution. Thus, the mean is:\\\\\n\t\\[\n\t\t\\textbf{E}(X_i) = np = \\frac{n}{s}\n\t\\]\\\\\n\tand the variance is:\\\\\n\t\\[\n\t\t\\text{Var}(X_i) = np(1-p) = \\frac{n}{s}\\left(1-\\frac{1}{s}\\right)\n\t\\]\\\\\n\t\\\\\n\t\\subsection{Part C}\n\tAssume $n=10$ and $s=3$. Find the probability that the first urn has 3 balls, the second has 2, and the third has 5.\\\\\n\t\\\\\n\tThe number of combinations of dividing the 10 balls into partitions of 3, 2, and 5 is $\\binom{10}{3,2,5}$. The total number of ways to divide 10 balls among the 3 urns is $3^{10}$. Thus, the probability is $\\frac{\\binom{10}{3,2,5}}{3^{10}} \\approx 0.0427$.\\\\\n\t\\\\\n\t\\subsection{Part D}\n\tCompute \\textbf{E}[$Y_k$].\\\\\n\t\\\\\n\tRecall that $Y_k$ is the number of urns that have exactly $k$ balls. Define:\\\\\n\t\\[\n\t\tI_i=\n\t\t\\begin{cases}\n\t\t\t1 & \\text{urn } i \\text{ has } k \\text{ balls}\\\\\n\t\t\t0 & \\text{otherwise}\n\t\t\\end{cases}\n\t\\]\n\tNow we can write $Y_k = \\sum_{i=1}^{s} I_i$. Due to linearity, $\\textbf{E}[Y_k] = \\textbf{E}\\left[\\sum_{i=1}^{s}\\right] =\\sum_{i=1}^{s} \\textbf{E}[I_i]$.\\\\\n\t\\\\\n\t$\\textbf{E}[I_i]$ is just the probability that urn $i$ has $k$ balls, $p_{X_i}(k)$, which is known from Part B. Thus,\n\t\\[\n\t\t\\textbf{E}[Y_k] = \\sum_{i=1}^{s} \\left(\\frac{1}{s}\\right)^k\\left(1-\\frac{1}{s}\\right)^{(n-k)}\\binom{n}{k} = s \\left(\\frac{1}{s}\\right)^k\\left(1-\\frac{1}{s}\\right)^{(n-k)}\\binom{n}{k}\n\t\\]\n\t\\\\\n\t\\subsection{Part E}\n\tCompute Var($Y_k$).\\\\\n\t\\\\\n\tVar($Y_k$)$= \\textbf{E}[Y_k^2] - \\textbf{E}[Y_k]^2$. The second term is known from Part D. Thus, we need to find $\\textbf{E}[Y_k^2]$.\\\\\n\t\\[\n\t\t\\textbf{E}[Y_k^2] = \\textbf{E}\\left[\\left( \\sum_{i=1}^{s}I_i\\right)^2\\right]\n\t\t=\n\t\t\\textbf{E}\\left[\n\t\t\\sum_{i=1}^{s}I_i^2\\right] + 2\\textbf{E}\\left[ \\sum_{i=1}^{s-1}\\sum_{j=i+1}^{s}I_iI_j\n\t\t\\right]\n\t\\]\\\\\n\tSince $I_i$ is either 0 or 1, $I_i^2 = I_i$. Thus, \n\t$\\textbf{E}\\left[\\sum_{i=1}^{s}I_i^2\\right] = \\textbf{E}\\left[\\sum_{i=1}^{s}I_i\\right] = \\textbf{E}[Y_k]$, which is known from Part D. We now need to find $\\textbf{E}\\left[\\sum_{i=1}^{s-1}\\sum_{j=i+1}^{s}I_iI_j\n\t\\right]$ to be done.\\\\\n\t\\\\\n\t$\\textbf{E}\\left[\\sum_{i=1}^{s-1}\\sum_{j=i+1}^{s}I_iI_j\n\t\\right] = \\sum_{i=1}^{s-1}\\sum_{j=i+1}^{s}\\textbf{E}\\left[I_iI_j\n\t\\right]$\\\\\\\\\n\t$\\textbf{E}\\left[I_iI_j\\right]$ is the probability that $X_i$ and $X_j$ both equal $k$. This is $2k$ successful placements and $n-2k$ unsuccessful placements. The number of combinations of these placements is the number of ways to partition the $n$ balls into 2 sets of size $k$ and a third set of size $n-2k$. Thus this probability is $\\binom{n}{k,k,n-2k}\\left(\\frac{1}{s}\\right)^{2k}\\left(1-\\frac{1}{s}\\right)^{n-2k}$.\\\\\n\t\\\\\n\tPutting it all together:\n\t\\[\n\t\\text{Var}(Y_k) = s \\left(\\frac{1}{s}\\right)^k\\left(1-\\frac{1}{s}\\right)^{(n-k)}\\binom{n}{k} + \n\t(s)(s-1)\\binom{n}{k,k,n-2k}\\left(\\frac{1}{s}\\right)^{2k}\\left(1-\\frac{1}{s}\\right)^{n-2k}\\]\n\t\\[-\\left(s \\left(\\frac{1}{s}\\right)^k\\left(1-\\frac{1}{s}\\right)^{(n-k)}\\binom{n}{k}\n\t\\right)^2\n\t\\]\n\t\n\t\n\t\t\n\\end{document}", "meta": {"hexsha": "1c7043cee277d7b45d4f2900208f53e1cb6f5cf3", "size": 12114, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/Quiz1/quiz1.tex", "max_stars_repo_name": "markditsworth/psa", "max_stars_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Exams/Quiz1/quiz1.tex", "max_issues_repo_name": "markditsworth/psa", "max_issues_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exams/Quiz1/quiz1.tex", "max_forks_repo_name": "markditsworth/psa", "max_forks_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_forks_repo_licenses": ["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.1230769231, "max_line_length": 432, "alphanum_fraction": 0.6315832921, "num_tokens": 4857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.6281189458106041}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\n\\title{The Factorization Problem\\\\In\\\\Computational Group Theory}\n\\author{Spencer T. Parkin}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{corollary}{Corollary}[section]\n\\newtheorem{identity}{Identity}[section]\n\\newtheorem{lemma}{Lemma}[section]\n\\newtheorem{result}{Result}[section]\n\n\\newcommand{\\stab}{\\mbox{stab}}\n\n\\begin{document}\n\\maketitle\n\n\\section*{The Problem And Solution}\n\nFor any given element $g$ of a finite permutation group $G$ generated\nby a set of permutation $S$, we wish to factor $g^{-1}$ in terms of $S$.\nSince $g\\in G=\\langle S\\rangle$, it is clear that for some positive integer $k$, there exists\na sequence of $k$ elements $\\{s_i\\}_{i=1}^k$ taken from $S$ such that\n\\begin{equation*}\ng = s_1s_2\\dots s_k,\n\\end{equation*}\nand therefore,\n\\begin{equation*}\ng^{-1} = s_k^{-1}s_{k-1}^{-1}\\dots s_1^{-1}.\n\\end{equation*}\nIndeed, there may be many such sequences.\nHow we might come up with such a sequence, however, is not immediately clear.\nOur goal is to come up with a systematic way of producing such a sequence, even if it\nis not of minimal length.\n\nAssociated with our group $G$ is a set $\\Omega$ over which each $g\\in G$ is defined.\nThat each $g$ is a permutation of this set $\\Omega$ is to say that $g$ is a one-to-one and onto\nmapping from $\\Omega$ to $\\Omega$.\nFor a given $\\omega\\in\\Omega$,\nwe define the stabilizer subgroup of $G$ with respect to $\\omega$ as\n\\begin{equation*}\n\\stab_{\\omega}(G) = \\{g\\in G|g(\\omega)=\\omega\\}.\n\\end{equation*}\nThis is the set of all permutation of $g$ that stabilize $\\omega$.  It is not hard to show\nthat this is a subgroup of $G$.  Furthermore, it is a normal subgroup of $G$.  \nFor any $h\\in\\stab_{\\omega}(G)$,\nand any $g\\in G$, we have\n\\begin{equation*}\ng(h(g^{-1}(\\omega))) = g(g^{-1}(\\omega)) = \\omega.\n\\end{equation*}\nEDIT: WRONG!!!!!!  You moron!!!\n\nBeing normal, we can consider the factor group\n\\begin{equation*}\nG/H = \\{gH|g\\in G\\},\n\\end{equation*}\nwhere $H=\\stab_{\\omega}(G)$.  We now make the observation that since $S$\ngenerates $G$, we must have $SH=\\{sH|s\\in S\\}$ generating $G/H$.  To see this, we write\nthe typical element of $G/H$ as\n\\begin{equation*}\ngH = \\left(\\prod_{i=1}^k s_i\\right)H = \\prod_{i=1}^k (s_iH).\n\\end{equation*}\n\nWe now let $R$ be a set of coset representatives for $G/H$, and $[\\cdot]:G\\to R$ a function\nmapping any element of $g$ to the coset representative in $R$ representing the coset in $G/H$ that contains $g$.\nThat is, $|R|=|G|/|H|=|G/H|$, and $G/H=\\{rH|r\\in R\\}$, and for all $g\\in G$, $gH=[g]H$ with $[g]\\in R$.\nComputationally, coming up with $R$ is really just the same problem as generating $G/H$ as we would simply use\ncoset representatives to represent each coset of $G/H$ anyway.  An implementation of $[g]$ might,\nfor each $r\\in R$, check whether $g^{-1}r\\in H$.\n\nArmed with all this, and letting $g$ be any element of $G$, we're now going to begin to address our original\nquestion by finding an element $q$ in terms of the generators of $S$ such that $gq\\in H$.  Clearly, a procedure\nfor such a thing is recursively applicable, for $H$ is simply a permutation group associated with $\\Omega-\\{\\omega\\}$,\nbringing us one step closer to the trivial group $\\{e\\}$.  The trick is that at each step, we must keep track of all new\ngenerators in terms of the original generators in $S$.\n\nSo how do we go about finding $q$?  Well, if $g\\in H$ (i.e., $g(\\omega)=\\omega$), then $q=e=ss^{-1}$ for any $s\\in S$,\nand we're done.  If not, consider $q=[g]^{-1}$.  Clearly $g[g]^{-1}\\in H$, since $gH=[g]H$, and furthermore,\nwe know the factorization of $[g]^{-1}$ in terms of the generators in $S$, because we know such a factorization\nfor $[g]\\in R$ by virtue of how we generated $R$ from $S$.\n\nWe are now almost there!  All that remains is our ability to continue this process in $H$ with $gq\\in H$ and a stabilizer\nsubgroup of $H$ with respect to some element in $\\Omega-\\{\\omega\\}$.  For that, we need a generating set for $H$,\nand this is where Schreier's Lemma comes into play.  According to Schreier, this set of generators is given by\n\\begin{equation*}\n\\{rs[rs]^{-1}|r\\in R, s\\in S\\},\n\\end{equation*}\nprovided $e\\in R$.\nNote that computationally, while we might boil each generator down to its permutation $g\\in G$, we would need\nto keep its expression (or ``word'') in terms of our original generators in $S$.\n\nSo there we have it!  In closing, it might be worth considering why the algorithm thus described does\nbetter than the most obvious, naive and impractical approach to solving the factorization problem, which is to\nsimply generate all of $G$ from $S$, then search for $g^{-1}$ in $G$.  To begin, $|G|$ may be\nextremely large, making its complete generation take too long and require too much memory.\nThat being said, the stabilizer-chain approach may have its own, similar problems.  For a group $G$\nof large order, how big is the order of a factor group likely to get?  How big is a set of generators\nlikely to get?  I'll have to give it a try.  I believe it can also be shown that this method does not\nproduce solution sequences anywhere near minimal length.\n\n\\section*{Generating Groups}\n\nFor a finite group $G=\\langle S\\rangle$, how do we go about generating all elements of $G$ using that of $S$?\nLetting $G=\\{e\\}$, we proceed until $S$ is empty.  Remove $s$ from $S$ and then, for each $g\\in G$,\nadd $gs$ or $sg$ to $S$ if they're not found in $G$ or $S$, then add $s$ to $G$.\n\nClearly this algorithm will terminate, but is it correct?  As elements are added to $G$, keep them in order so\nthat in the end, we have $G$ as an array of elements showing the order that they were added.  Then for any $g\\in G$,\nwe know that $G$ also contains $rg$ and $gr$ for every $r\\in G$ left of $g$.  We also know that this is true for\nall $r\\in G$ right of $g$.  In fine, we should have closure in $G$.  Now since $G$ is a finite subset of a larger group (since\nthe original $S$ was a subset of that larger group),\nit must be a subgroup of that group.  Lastly, can we claim that $G$ is the smallest group containing all original elements of $S$?\nWell, since we never added any elements to $G$ unnecessarily, I would have to think so.\n\nThis line of reasoning is not terribly rigorous, but it is the best I can come up with for now.\n\n% Maybe note a recursive algorithm for generating a group in the case that it is abelian.\n% In that case, all subgroups are normal.  If H is a subgroup of such a G, and g is in G-H,\n% Then <gH> is the smallest subgroup of G containing g and H.\n\n\\end{document}", "meta": {"hexsha": "fdfe7013d7b9fb101d298a7823d5edcc65b6e6ba", "size": 6643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Paper/TheFactorizationProblemInComputationalGroupTheory.tex", "max_stars_repo_name": "spencerparkin/PermutationGroup", "max_stars_repo_head_hexsha": "9932737ee77348869f8e2e715bdad3c84401b214", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-01T06:21:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-01T06:21:06.000Z", "max_issues_repo_path": "Paper/TheFactorizationProblemInComputationalGroupTheory.tex", "max_issues_repo_name": "spencerparkin/PermutationGroup", "max_issues_repo_head_hexsha": "9932737ee77348869f8e2e715bdad3c84401b214", "max_issues_repo_licenses": ["MIT"], "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/TheFactorizationProblemInComputationalGroupTheory.tex", "max_forks_repo_name": "spencerparkin/PermutationGroup", "max_forks_repo_head_hexsha": "9932737ee77348869f8e2e715bdad3c84401b214", "max_forks_repo_licenses": ["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.144, "max_line_length": 130, "alphanum_fraction": 0.7084148728, "num_tokens": 2025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6281189425389424}}
{"text": "\\documentclass[12pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}\n\n\\title{Mathematical software - homework 1}\n\\author{Sebastiano Tronto}\n\n\\newtheorem{thm}{Theorem}\n\\newtheorem{prop}[thm]{Proposition}\n\n\\theoremstyle{definition}\n\\newtheorem{ex}{Exercise}\n\n\\theoremstyle{definition}\n\\newtheorem*{remark}{Remark}\n\n\\begin{document}\n\n\\noindent\\hrulefill\n\n\\begin{center}\n\\Huge{\\textbf{Mathematical Software - Homework 1}}\n\\end{center}\n\n\\noindent\\hrulefill\n\\begin{center}\n\\begin{tabular}{lcr}\n\\texttt{sebastiano.tronto@uni.lu} & \\qquad \\qquad \\qquad \\qquad &\n\\textbf{Deadline: Sunday, March 28th}\n\\end{tabular}\n\\end{center}\n\n\\vspace{1cm}\n\n\\begin{center}\n  \\emph{\\large\n    For each of the following exercises submit a .tex and a .pdf file.\n  }\n\\end{center}\n\n\\vspace{1cm}\n\n\\begin{ex}\n  Write a short Latex document that contains the following theorem-like\n  environments using the \\texttt{\\textbackslash newtheorem} command of the\n  \\texttt{amsthm} package (the box around the text is not needed):\n  \\begin{center}\n    \\fbox{\\parbox{0.95\\textwidth}{\n      \\begin{prop}[Fundamental Theorem of Algebra]\n        \\label{prop:fta}\n        Let \\(p(x)\\) be a non-constant polynomial with coefficients in\n        $\\mathbb C$. Then there is \\(z\\in\\mathbb C\\) such that $p(z)=0$.\n      \\end{prop}\n\n      \\begin{remark}\n        Proposition \\ref{prop:fta} is not true for polynomials with\n        coefficients in $\\mathbb R$. For example\n        \\begin{align}\n          p(x) = x^2+1\n        \\end{align}\n        does not have real roots.\n      \\end{remark}\n\n      \\begin{thm}\n        If $X$ and $Y$ are $\\sigma$-finite measure spaces and $f:X\\times Y\\to\n        \\mathbb R$ is measurable and such that\n        \\begin{align*}\n          \\int_{X\\times Y}|f(x,y)|\\mathrm d(x,y) < \\infty\n        \\end{align*}\n        then\n        \\begin{align}\n          \\label{eq:fubini}\n          \\int_X\\left(\\int_Yf(x,y)\\mathrm d y\\right)\\mathrm d x =\n          \\int_Y\\left(\\int_Xf(x,y)\\mathrm d x\\right)\\mathrm d y =\n          \\int_{X\\times Y} f(x,y)\\mathrm d(x,y)\\,.\n        \\end{align}\n      \\end{thm}\n\n      \\begin{remark}\n        In practice, equation \\eqref{eq:fubini} means that we can switch the\n        order of integration in a double integral.\n      \\end{remark}\n    }}\n  \\end{center}\n  Notice that Propositions, Theorems and some of the equations are numbered,\n  and some of them are referred to in the Remarks. This numbering should change\n  accordingly if more numbered Theorems and equations are added before this\n  part of the text.\n\\end{ex}\n\n\\vspace{0.8cm}\n\n\\begin{ex}\n[This is basically a ``do whatever you want, just do something'' exercise]\nWrite a Mathematical document in Latex, where ``Mathematical'' means any text\nthat contains both inline and displaystyle symbols and formulas, and where most\nof the sentences contain a Mathematical symbol.\nFor example, you can submit (part of) your homework or notes for another course\nthat you are following at the moment.\n\nYou must follow the following rules:\n\\begin{itemize}\n  \\item Your document must be at least 2 pages long.\n  \\item Use the following in your preamble:\n    \\begin{verbatim}\n\\documentaclass[12pt,a4paper]{article}\n\\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}\n    \\end{verbatim}\n\\end{itemize}\nThe document itself can be about any area of Mathematics, Physics or similar.\nThe correctness of the Mathematics itself will not be judged for this course.\n\\end{ex}\n\n\\section*{Grading}\n\nThis homework assignment is worth 25\\% of your final grade.\n\n\\vspace{0.3cm}\n\\textbf{Exercise 1 (10 points).}\n\\begin{itemize}\n  \\item A correct use of the \\texttt{\\textbackslash newtheorem} command is\n        worth 4 out of 10 points.\n  \\item A correct use of the labelling and reference system is worth 4 points.\n  \\item Reproducing correctly the mathematical formulas is worth 2 points.\n\\end{itemize}\n\n\\textbf{Exercise 2 (10 points).}\n\\begin{itemize}\n  \\item A resulting pdf file that looks readable and correct is worth 6 out of\n        10 points.\n  \\item The correct use of latex commands and environments is worth 4 out of\n        10 points. \\emph{Examples of mistakes in this sense: adjusting manually\n        the size of parenthesis instead of using \\texttt{\\textbackslash left}\n        and \\texttt{\\textbackslash right}; using \\texttt{\\textbackslash Sigma}\n        when you actually want to write a sum symbol.}\n\\end{itemize}\n\n\n\\end{document}", "meta": {"hexsha": "961a80d755c08eca3b14a2c6453b35f7e2d00cd5", "size": 4536, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Homework1/Homework1.tex", "max_stars_repo_name": "sebastianotronto/mathsoftware", "max_stars_repo_head_hexsha": "e995905df49fefdef231aeb16e7f4afd7994c9fe", "max_stars_repo_licenses": ["AAL"], "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/Homework1/Homework1.tex", "max_issues_repo_name": "sebastianotronto/mathsoftware", "max_issues_repo_head_hexsha": "e995905df49fefdef231aeb16e7f4afd7994c9fe", "max_issues_repo_licenses": ["AAL"], "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/Homework1/Homework1.tex", "max_forks_repo_name": "sebastianotronto/mathsoftware", "max_forks_repo_head_hexsha": "e995905df49fefdef231aeb16e7f4afd7994c9fe", "max_forks_repo_licenses": ["AAL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7202797203, "max_line_length": 79, "alphanum_fraction": 0.7003968254, "num_tokens": 1307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.628118937786816}}
{"text": "\\documentclass[letter,10pt]{article}\n\n\\usepackage{amsmath}\n%\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n%\\usepackage[ngerman,english]{babel}\n%\\usepackage{hyperref}\n%\\usepackage{graphicx}\n%\\usepackage{listings}\n%\\usepackage{adjustbox}\n%\\usepackage[affil-it]{authblk}\n%\\usepackage[T1]{fontenc}\n%\\usepackage{lmodern}\n%\\usepackage[space]{grffile}\n\\usepackage{hyperref}\n\n\\begin{document}\n\n\n\n\\section*{Note on Analog-to-Digital Converter (ADC)}\n\n``What does the ADC output mean? What are those big numbers?''\n\n\\subsection*{Resolution}\nAn ADC linearly maps an input voltage to a range of numbers. The ADC we use has a 5V reference and is a 10-bit ADC, so it maps an input voltage between 0 and 5V to a number between 0 to $2^{10} - 1$:\n\\begin{equation}\nADC = V_{input} / V_{ref} * 2^{10} = V_{input} / 5V * 1024\n\\end{equation}\n(Reality is a bit more complicated than that. Divide by 1023 or 1024, which is correct? Or does it matter?)\\\\\n\\\\\nFor example, if the ADC outputs 365, then the voltage of the input is\n\\begin{equation}\n\\frac{365}{1024}*5V = 1.78V\n\\end{equation}\nYou should verify this with a voltmeter. Also try to verify that the reference voltage is indeed (not exactly) 5V. How does that affect your measurement?\n\n\\end{document}\n", "meta": {"hexsha": "cb5f95dd5c5e54f3ebbf3765bd393aebfcb500c4", "size": 1245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "S18/week8/notes on adc.tex", "max_stars_repo_name": "stanleylio/OCN318", "max_stars_repo_head_hexsha": "98f0329ea38ddd4ed2966f8f845a0bb29e71b923", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-03-05T23:33:59.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-05T23:33:59.000Z", "max_issues_repo_path": "S18/week8/notes on adc.tex", "max_issues_repo_name": "stanleylio/OCN318", "max_issues_repo_head_hexsha": "98f0329ea38ddd4ed2966f8f845a0bb29e71b923", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "S18/week8/notes on adc.tex", "max_forks_repo_name": "stanleylio/OCN318", "max_forks_repo_head_hexsha": "98f0329ea38ddd4ed2966f8f845a0bb29e71b923", "max_forks_repo_licenses": ["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.9230769231, "max_line_length": 199, "alphanum_fraction": 0.7421686747, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925404, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6281105448447172}}
{"text": "\\part{Limits and Continuity}\n\n\\chapter{Basic Limits}\n\n\\section{Basic Limits}\n\nSuppose we have a function $ y = f(x) $. The limit of $ f(x) $ as $ x $ approaches the number $ a $, denoted $ \\lim\\limits_{x \\rightarrow a}f(x) $. \\\\\n\nFor example, suppose we wanted to determine $ \\lim\\limits_{x \\rightarrow 3}x^2 $. \\\\\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|} \\hline\n\t\t\\textbf{$ x $ approaches 3 from the left} & \\textbf{$ x $ approaches 3 from the right} \\\\ \\hline\n\t\t$ f(2.9) = 8.41 $                         & $ f(3.1) = 9.61 $                          \\\\ \\hline\n\t\t$ f(2.99) = 8.9401 $                      & $ f(3.01) = 9.0601 $                       \\\\ \\hline\n\t\t$ f(2.999) = 8.994001 $                   & $ f(3.001) = 9.006001 $                    \\\\ \\hline\n\t\\end{tabular}\n\\end{table}\n\nNo matter which way we approach from, as $ x $ gets close 3, we can see that $ x^2 $ gets very close to 9. \\\\\n\n\\begin{exercise}\\nonumber\n\tFind  $ \\lim\\limits_{x \\rightarrow 0}f(x) $ where \\\\\n\t\\begin{align}\n\t\tf(x) = \\begin{cases}\n\t\t\tcos(x) & x \\ne 0 \\\\\n\t\t\t-1     & x = 0\n\t\t\\end{cases}\n\t\\end{align}\n\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\txlabel={$ x $}, ylabel={$ y $},\n\t\t\t\t\txmin=-2*pi, xmax=2*pi,\n\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\txtick={-6.28319, -3.14159, 0, 3.14159, 6.28319},\n\t\t\t\t\txticklabels={$-2\\pi$, $-\\pi$, $0$, $\\pi$, $2\\pi$},\n\t\t\t\t\tline width=1pt,\n\t\t\t\t\taxis lines=center,\n\t\t\t\t]\n\t\t\t\t\\addplot[smooth,domain=-2*pi:-0.15, red!70]{cos(deg(x))};\n\t\t\t\t\\addplot[smooth,domain=0.15:2*pi, red!70]{cos(deg(x))};\n\t\t\t\\end{axis}\n\t\t\t\\node at (3.43,4.72) [red,circle,inner sep=1pt]{$\\circ$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t\\begin{gather*}\n\t\t\\lim\\limits_{x \\rightarrow 0}f(x) = 1 \\\\\n\t\tf(0) = -1\n\t\\end{gather*}\n\\end{exercise}\n\n\\section{Law of Limits}\n\n\\begin{theorem}[Law of Limits]\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow a}(f+g)(x) = \\lim\\limits_{x \\rightarrow a}f(x) + \\lim\\limits_{x \\rightarrow a}g(x)                          \\\\\n\t\t & \\lim\\limits_{x \\rightarrow a}(f-g)(x) = \\lim\\limits_{x \\rightarrow a}f(x) - \\lim\\limits_{x \\rightarrow a}g(x)                          \\\\\n\t\t & \\lim\\limits_{x \\rightarrow a}(fg)(x) = \\lim\\limits_{x \\rightarrow a}f(x) \\cdot \\lim\\limits_{x \\rightarrow a}g(x)                       \\\\\n\t\t & \\lim\\limits_{x \\rightarrow a}\\left({f \\over g}\\right)(x) = {\\lim\\limits_{x \\rightarrow a}f(x) \\over \\lim\\limits_{x \\rightarrow a}g(x)}\n\t\\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n\tEvaluate $ \\lim\\limits_{x \\rightarrow 0}xsin\\left({1 \\over x}\\right) $. \\\\\n\t\\begin{gather*}\n\t\t-1 \\le  sin\\left({1 \\over x}\\right) \\le 1 \\\\\n\t\t-x \\le xsin\\left({1 \\over x}\\right) \\le x \\\\\n\t\t\\lim\\limits_{x \\rightarrow 0}-x \\le \\lim\\limits_{x \\rightarrow 0}xsin\\left({1 \\over x}\\right) \\le \\lim\\limits_{x \\rightarrow 0}x \\\\\n\t\t\\therefore \\lim\\limits_{x \\rightarrow 0}xsin\\left({1 \\over x}\\right) = 0\n\t\\end{gather*}\n\\end{exercise}\n\n\\section{One-sided Limits}\n\n$ x $ can approach the value a in two ways: \\\\\n\n\\begin{itemize}\n\t\\item\n\t      left-hand limit: $ \\lim\\limits_{x \\rightarrow a^-}f(x) $ \\\\\n\n\t\\item\n\t      right-hand limit: $ \\lim\\limits_{x \\rightarrow a^+}f(x) $ \\\\\n\\end{itemize}\n\nWe can tighten our definition of the limit of a function $ f(x) $ as $ x $ approaches $ a $. If the left-hand and right-hand limits of $ f(x) $ are both equal to a number $ L $, then we say that $ \\lim\\limits_{x \\rightarrow a}f(x) $ exists and is equal to $ L $. \\\\\n\n\\begin{exercise}\\nonumber\n\tConsider the piecewise function given by \\\\\n\t\\begin{align}\n\t\tf(x) = \\begin{cases}\n\t\t\tx          & x < 1 \\\\\n\t\t\t-1         & x = 1 \\\\\n\t\t\t\\sqrt{x-1} & x > 1\n\t\t\\end{cases}\n\t\\end{align}\n\n\t(a) $ \\lim\\limits_{x \\rightarrow 1^-}f(x) = 1 $ \\\\\n\n\t(b) $ \\lim\\limits_{x \\rightarrow 1^+}f(x) = 0 $ \\\\\n\n\t(c) $ f(1) = -1 $ \\\\\n\n\t(d) Does $ \\lim\\limits_{x \\rightarrow 1}f(x) $ exist? No.\n\\end{exercise}\n\n\\chapter{Continuity}\n\n\\section{Continuity}\n\nIt seems like sometimes we can evaluate a limit by just plugging in, but sometimes we can't! \\\\\n\n\\begin{exercise}\\nonumber\n\tEvaluate $ \\lim\\limits_{x \\rightarrow 1}\\left(ln(\\sqrt{x}) + {1 \\over x}\\right) $. \\\\\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow 1}\\left(ln(\\sqrt{x}) + {1 \\over x}\\right) \\\\\n\t\t & = ln\\left(\\sqrt{x} + {1 \\over x}\\right)                              \\\\\n\t\t & = ln\\left(\\sqrt{1}\\right) + {1 \\over 1}                              \\\\\n\t\t & = 0 + 1                                                              \\\\\n\t\t & = 1\n\t\\end{align}\n\\end{exercise}\n\nA function is continuous at a point a if each of the following conditions hold: \\\\\n\n\\begin{enumerate}\n\t\\item\n\t      $ \\lim\\limits_{x \\rightarrow a}f(x) $ exists \\\\\n\n\t\\item\n\t      $ f(a) $ exists \\\\\n\n\t\\item\n\t      $ \\lim\\limits_{x \\rightarrow a}f(x) = f(a) $ \\\\\n\\end{enumerate}\n\n\\section{Discontinuity}\n\nKinds of discontinuities: \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.7]\n\t\t\\draw[->] (-5,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-4.5:-1.3] plot (\\x,{1 / (\\x + 1)});\n\t\t\\draw[very thick,color=red,domain=-0.7:3] plot (\\x,{1 / (\\x + 1)});\n\t\t\\draw[very thick,densely dashed,color=red] (-1,4)--(-1,-4);\n\t\\end{tikzpicture}\n\t\\caption{essential}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\txlabel={$ x $}, ylabel={$ y $},\n\t\t\t\txmin=-2*pi, xmax=2*pi,\n\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\txtick={-6.28319, -3.14159, 0, 3.14159, 6.28319},\n\t\t\t\txticklabels={$-2\\pi$, $-\\pi$, $0$, $\\pi$, $2\\pi$},\n\t\t\t\tline width=1pt,\n\t\t\t\taxis lines=center,\n\t\t\t]\n\t\t\t\\addplot[smooth,domain=-2*pi:1.07, red!70]{sin(deg(x))};\n\t\t\t\\addplot[smooth,domain=1.2:2*pi, red!70]{sin(deg(x))};\n\t\t\t\\node at (742,240) [red,circle,inner sep=1pt]{$\\circ$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{removable}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.5,yscale=0.3]\n\t\t\\draw[->] (-10,0) -- (6,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-5) -- (0,20) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-9:-2.1] plot (\\x,{0.5 * \\x + 3});\n\t\t\\draw[very thick,color=red,domain=-2:2] plot (\\x,{0});\n\t\t\\draw[very thick,color=red,domain=2.1:4] plot (\\x,{\\x^2 - 1});\n\t\t\\foreach \\point in {(-2,0),(2,0)} {\n\t\t\t\t\\node at \\point [red,circle,fill,inner sep=1.5pt]{};\n\t\t\t}\n\t\t\\foreach \\point in {(-2,2),(2,3)} {\n\t\t\t\t\\node at \\point [red,circle,inner sep=1.5pt]{$\\circ$};\n\t\t\t}\n\t\\end{tikzpicture}\n\t\\caption{jump}\n\\end{figure}\n\nSo far, we know that evaluating $ \\lim\\limits_{x \\rightarrow a}f(x) $ is easy if $ f(x) $ is continuous at $ a $. But what if it isn't? The limit may still exist. \\\\\n\n\\begin{exercise}\\nonumber\n\tEvaluate the following limits. \\\\\n\n\t(a) $ \\lim\\limits_{x \\rightarrow 3^+}{1 \\over 3-x} = -\\infty $ \\\\\n\n\t(b) $ \\lim\\limits_{x \\rightarrow 3^-}{1 \\over 3-x} = \\infty $ \\\\\n\n\t(c) $ \\lim\\limits_{x \\rightarrow 0^+}ln(x) = -\\infty $ \\\\\n\n\t(d) $ \\lim\\limits_{x \\rightarrow -{\\pi \\over 2}^+}sec(x) = \\infty $\n\\end{exercise}\n\nA function doesn't have to go to $ \\pm \\infty $ at a discontinuity though. Consider, for instance, evaluating $ \\lim\\limits_{x \\rightarrow 3}{x^2-x-6 \\over x-3} $. Plugging in $ x = 3 $ gives us \"$ 0 / 0 $\", which is known as an indeterminate form. \\\\\n\nA good first step is to factor where possible. Once we cancel the factor $ x - 3 $ on top and bottom, this function is just the function $ f(x) = x + 2 $, but with a hole at $ x = 3 $. The hole is there because we cannot ignore that the original form of the function had issues at $ x = 3 $. \\\\\n\n\\begin{exercise}\\nonumber\n\tEvaluate the following limits. \\\\\n\n\t(a)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow 3}{x^2-x-6 \\over x-3}      \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 3}{(x-3)(x+2) \\over x-3} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 3}{x+2}                  \\\\\n\t\t & = 5\n\t\\end{align}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.3]\n\t\t\t\\draw[->] (-6,0) -- (6,0) node[right] {$ x $};\n\t\t\t\\draw[->] (0,-4) -- (0,8) node[above] {$ y $};\n\t\t\t\\draw[very thick,color=red,domain=-5:2.85] plot (\\x,{\\x + 2});\n\t\t\t\\draw[very thick,color=red,domain=3.2:5] plot (\\x,{\\x + 2});\n\t\t\t\\node at (3,5) [red,circle,inner sep=1.5pt]{$\\circ$};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t(b)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow -1}{x^3 - 11x^2 + 8x + 20 \\over x + 1} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow -1}{(x+1)(x^2-12x+20) \\over x + 1}   \\\\\n\t\t & = (-1)^2 - 12(-1) + 20                                            \\\\\n\t\t & = 33\n\t\\end{align}\n\t\\\\\n\n\t(c)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow 4}{\\sqrt{x+5} - 3 \\over x-4}                                              \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 4}{({{\\sqrt{x+5}-3} \\over {x-4}})({{\\sqrt{x+5}+3} \\over \\sqrt{x+5}+3})} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 4}{x-4 \\over (x-4)(\\sqrt{x+5}+3)}                                       \\\\\n\t\t & = {1 \\over \\sqrt{9} + 3}                                                                             \\\\\n\t\t & = {1 \\over 6}\n\t\\end{align}\n\t\\\\\n\n\t(d)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow 2}{{1 \\over x-4} + {1 \\over 2} \\over x-2}                     \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 2}{{{2+(x-4)} \\over {2(x-4)}} \\over x-2}                    \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 2}{\\left({x-2 \\over 2x-4}\\right)\\left({1 \\over x-2}\\right)} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 2}{1 \\over 2(x-4)}                                          \\\\\n\t\t & = {1 \\over 2(-2)}                                                                        \\\\\n\t\t & = -{1 \\over 4}\n\t\\end{align}\n\\end{exercise}\n\n\\chapter{The Fundamental Sine Limit}\n\n\\section{The Fundamental Sine Limit}\n\nConsider the following limit:\n\n$$\n\t\\lim\\limits_{x \\rightarrow 0}{sin(x) \\over x}\n$$\n\nWe can quickly see that this is a \"$ 0 / 0 $\" limit, and therefore is indeterminate. We can't factor anything or otherwise simplify the expression to get rid of the issue. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=1]\n\t\t\\begin{axis}[\n\t\t\t\tgrid=both,\n\t\t\t\txmin=-4,\n\t\t\t\txmax=4,\n\t\t\t\tymin=-2,\n\t\t\t\tymax=2,\n\t\t\t\txlabel=$x$,\n\t\t\t\tylabel=$y$,\n\t\t\t\taxis lines=center,\n\t\t\t\t>=stealth\n\t\t\t]\n\t\t\t\\addplot[\n\t\t\t\tdomain=-4:4,\n\t\t\t\tred,\n\t\t\t\tultra thick,\n\t\t\t\tsamples=100,\n\t\t\t] plot[smooth] {sin(deg(x))/x};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{$ sin(x) \\over x $}\n\\end{figure}\n\nIt is pretty clear from the graph that \\\\\n\n\\begin{theorem}[The Fundamental Sine Limit]\n\t\\begin{align}\n\t\t\\lim\\limits_{x \\rightarrow 0}{sin(x) \\over x} = \\lim\\limits_{x \\rightarrow 0}{x \\over sin(x)} = 1\n\t\\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n\tEvaluate the following limits. \\\\\n\n\t(a)\n\t\\begin{align}\n\t\t & \\lim\\limits_{t \\rightarrow 0}{5sin(t) \\over 2t}                     \\\\\n\t\t & = \\lim\\limits_{t \\rightarrow 0}{{5 \\over 2} \\cdot {sin(t) \\over t}} \\\\\n\t\t & = {5 \\over 2}\n\t\\end{align}\n\t\\\\\n\n\t(b)\n\t\\begin{align}\n\t\t & \\lim\\limits_{\\theta \\rightarrow 0}{\\theta \\over sin(4\\theta)}                 \\\\\n\t\t & = \\lim\\limits_{\\theta \\rightarrow 0}{4\\theta \\over 4sin(4\\theta)}             \\\\\n\t\t & = \\lim\\limits_{\\theta \\rightarrow 0}{{1 \\over 4}{4\\theta \\over sin(4\\theta)}} \\\\\n\t\t & = {1 \\over 4}\n\t\\end{align}\n\t\\\\\n\n\t(c)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow -1}{sin^2(x+1) \\over (x+1)^2}                          \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow -1}{{sin(x+1) \\over x+1} \\cdot {sin(x+1) \\over x+1}} \\\\\n\t\t & = 1\n\t\\end{align}\n\t\\\\\n\n\t(d)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow 0}{sin(3x) \\over sin(2x)}                                          \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow 0}{{sin(3x) \\over 3} \\cdot {2x \\over sin(2x)} \\cdot {3 \\over 2}} \\\\\n\t\t & = {3 \\over 2}\n\t\\end{align}\n\t\\\\\n\n\t(e)\n\t\\begin{align}\n\t\t & \\lim\\limits_{\\theta \\rightarrow 0}{100\\theta \\over tan(3\\theta)}                                                 \\\\\n\t\t & = \\lim\\limits_{\\theta \\rightarrow 0}{10\\theta \\cdot {cos(3\\theta) \\over sin(3\\theta)}}                           \\\\\n\t\t & = \\lim\\limits_{\\theta \\rightarrow 0}{{3\\theta \\over sin(3\\theta)} \\cdot {1 \\over 3} \\cdot 10 \\cdot cos(3\\theta)} \\\\\n\t\t & = 1 \\cdot {10 \\over 3} \\cdot 1                                                                                   \\\\\n\t\t & = {10 \\over 3}\n\t\\end{align}\n\t\\\\\n\n\t(f)\n\t\\begin{align}\n\t\t & \\lim\\limits_{h \\rightarrow 0}{cos(h)-1 \\over h}                                                        \\\\\n\t\t & = \\lim\\limits_{h \\rightarrow 0}{\\left({cos(h)-1 \\over h}\\right)\\left({cos(h)+1 \\over cos(h)+1}\\right)} \\\\\n\t\t & = \\lim\\limits_{h \\rightarrow 0}{cos^2h - 1 \\over h(cos(h) + 1)}                                        \\\\\n\t\t & = \\lim\\limits_{h \\rightarrow 0}{-sin^2h \\over h\\left(cos(h) + 1\\right)}                                \\\\\n\t\t & = \\lim\\limits_{h \\rightarrow 0}{-{sin(h) \\over h} \\cdot {sin(h) \\over cos(h) + 1}}                     \\\\\n\t\t & = -1 \\cdot {0 \\over 1+1}                                                                               \\\\\n\t\t & = 0\n\t\\end{align}\n\\end{exercise}\n\n\\chapter{Limits Approaching $ \\pm \\infty $}\n\n\\section{Limits Approaching $ \\pm \\infty $}\n\nSometimes, we will be interested in determining what happens as $ x $ gets really big, either in the positive or negative direction. \\\\\n\n\\begin{exercise}\\nonumber\n\tEvaluate the following limits. \\\\\n\n\t(a) $ \\lim\\limits_{x \\rightarrow \\infty}{1 \\over x} = 0 $ \\\\\n\n\t(b) $ \\lim\\limits_{x \\rightarrow -\\infty}{1 \\over x} = 0 $ \\\\\n\n\t(c) $ \\lim\\limits_{x \\rightarrow -\\infty}{401 \\over x^{203}} = 0 $ \\\\\n\n\t(d) $ \\lim\\limits_{x \\rightarrow -\\infty}{-238 \\over 23x^{1/4}} = 0 $\n\\end{exercise}\n\nFor problems like $ \\lim\\limits_{x \\rightarrow \\infty}{2x^2 + 3x + 1 \\over x^2 - 10x + 100} $, a good first step is to divide the top and the bottom by the highest power of $ x $ appearing in the denominator. \\\\\n\n\\begin{exercise}\\nonumber\n\tEvaluate the following limits. \\\\\n\n\t(a)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow \\infty}{2x^2 + 3x + 1 \\over x^2 - 10x + 100}                                            \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{\\left({2x^2+3x+1 \\over x^2-10x+100}\\right)\\left({1/x^2 \\over 1/x^2}\\right)}   \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{\\left({2x^2+3x+1 \\over x^2-10x+100}\\right)\\left({1/x^2 \\over 1/x^2}\\right)}   \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{{2 + {3 \\over x} + {1 \\over x^2}} \\over {1 - {10 \\over x} + {100 \\over x^2}}} \\\\\n\t\t & = {2 \\over 1}                                                                                                      \\\\\n\t\t & = 2\n\t\\end{align}\n\t\\\\\n\n\t(b)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow -\\infty}{3 - 2x^3 \\over 1 + x + x^2}                                            \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow -\\infty}{\\left({3-2x^3 \\over 1+x+x^2}\\right)\\left({1/x^2 \\over 1/x^2}\\right)} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow -\\infty}{{3 \\over x^2} - 2x \\over {{1 \\over x^2} + {1 \\over x} + 1}}          \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow -\\infty}{-2x \\over 1}                                                         \\\\\n\t\t & = \\infty\n\t\\end{align}\n\t\\\\\n\n\t(c)\n\t\\begin{align}\n\t\t & \\lim\\limits_{x \\rightarrow \\infty}{\\sqrt{x^2 - x + 1}}                                                                    \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{\\left(\\sqrt{x^2-x+1}-x\\right)\\left({\\sqrt{x^2-x+1}+x \\over \\sqrt{x^2-x+1}+x}\\right)} \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{(x^2-x+1)-x^2 \\over \\sqrt{x^2-x+1}+x}                                                \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{x+1 \\over \\sqrt{x^2-x+1}+x}                                                          \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{\\left({x+1 \\over \\sqrt{x^2-x+1}+x}\\right)\\left({1/x \\over 1/x}\\right)}               \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{-1 + {1 \\over x} \\over {\\sqrt{x^2-x+1} \\over x} + 1}                                 \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{-1 + {1 \\over x} \\over \\sqrt{{x^2-x+1} \\over x^2} + 1}                               \\\\\n\t\t & = \\lim\\limits_{x \\rightarrow \\infty}{-1 \\over \\sqrt{1} + 1}                                                               \\\\\n\t\t & = -{1 \\over 2}\n\t\\end{align}\n\t\\\\\n\n\t(d)\n\t\\begin{align}\n\t\t & \\lim\\limits_{t \\rightarrow \\infty}{\\sqrt{3t^2 + 2t + 5} + t} \\\\\n\t\t & = \\infty\n\t\\end{align}\n\\end{exercise}", "meta": {"hexsha": "31ea891bf2b665df6931a19dae4795939cf5db8c", "size": 15964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus_Solution/parts/part3.tex", "max_stars_repo_name": "xdai02/Calculus", "max_stars_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "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": "Calculus_Solution/parts/part3.tex", "max_issues_repo_name": "xdai02/Calculus", "max_issues_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "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": "Calculus_Solution/parts/part3.tex", "max_forks_repo_name": "xdai02/Calculus", "max_forks_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "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.0394431555, "max_line_length": 294, "alphanum_fraction": 0.5186670008, "num_tokens": 5842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.6281105401000203}}
{"text": "% Start of header.\n\\documentclass{article}\n\\usepackage{amsthm}\n\\usepackage{caption}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{lmodern}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n\\newcommand{\\I}[0]{\\mathbb{I}}\n\\newcommand{\\Q}[0]{\\mathbb{Q}}\n\\newcommand{\\Z}[0]{\\mathbb{Z}}\n\\newcommand{\\C}[0]{\\mathbb{C}}\n\\newcommand{\\F}[0]{\\mathbb{F}}\n\\newcommand{\\R}[0]{\\mathbb{R}}\n\\newcommand{\\N}[0]{\\mathbb{N}}\n\\newcommand{\\unif}[0]{\\mathcal{U}}\n\\newcommand{\\Tor}[0]{\\operatorname{Tor}}\n\\newcommand{\\ra}[0]{\\rightarrow}\n\\newcommand{\\rr}[0]{\\Rightarrow}\n\\newcommand{\\llrr}[0]{\\Leftrightarrow}\n\\newcommand{\\subq}[0]{\\subseteq}\n\\newcommand{\\sub}[0]{\\subset}\n\\newcommand{\\nsubq}[0]{\\not\\subseteq}\n\\newcommand{\\nsub}[0]{\\not\\subset}\n\\newcommand{\\sep}[0]{\\hbox{ }}\n\\newcommand{\\inv}[0]{^{\\raisebox{.2ex,$\\scriptscriptstyle-1$}}}\n\\newcommand{\\thnew}[0]{^{\\text{th}}}\n\\newcommand{\\ifnew}[0]{\\text{ if }}\n\\newcommand{\\elsenew}[0]{\\text{ else }}\n\\newcommand{\\for}[0]{\\text{ for }}\n\n\\setlength{\\jot}{8pt}\n% End of header\n% Start of body.\n\n\\begin{document}\n\n\\section{Expected value of kth element of an ordered sequence of elements from some interval}\n\n\\subsection{Question:}\n\nLet each ordered sequence of $n$ unique elements $X_1, \\dots, X_n$ from the interval $(a, b)$ be equally probable. What is the expected value of the element $X_k$?\n\n\\subsection{Answer:}\n\nConsider random variables $Y_1, \\dots, Y_n$ sampled from a uniform  distribution over $(a, b)$ such that no two $Y_i$ are equal. First, we show that any ordered sequence made from $Y_1, \\dots, Y_n$ is equally probable.\n\nLet $X_1 = Y_{i_1}, \\dots, X_n = Y_{i_n}$ be the ordered sequence made from our random variables $Y_1, \\dots, Y_n$. Then we see the probability density function, $f$, at a specific random sequence is\n\n$$f_X([X_1, \\dots, X_n]) = \\sum_{Y_1, \\dots, Y_n \\in \\text{ Permuations}(X_1, \\dots, X_n)} f_{Y_1, \\dots, Y_n}(Y_1, \\dots, Y_n) $$\n$$= \\sum_{Y_1, \\dots, Y_n \\in \\text{ Permuations}(X_1, \\dots, X_n)} f_{Y_1}(Y_1)\\cdots f_{Y_n}(Y_n)$$\n\nNote that the value of a uniform probability density does not change if we introduce a finite number of holes (as the integral over the pdf does not change in value), thus:\n\n$$\nf_{Y_i}(Y_i) = \n\\begin{cases}\n\\frac{1}{b-a},  & \\text{if $Y_i \\in (a, b)$ and $Y_i \\neq Y_j$ for $j \\neq i$} \\\\\n0, & \\text{otherwise}\n\\end{cases}\n$$\n\n\\textbf{NOTE}: \\emph{I think I can rewrite it this way, because all I'm doing is reorganizing the points of the composite $Y$ pdf into groups that produce the same ordered sequence. So when I integrate over the pdf of the ordered sequences, it's integrating over the same region as the composite $Y$ pdf.} \\textbf{But the multiplier of $n!$ can't be right or the pdf for $f_X$ will integrate to greater than 1!}\n\nTherefore we can rewrite $f_X$:\n\n$$f_X([X_1, \\dots, X_n]) = \\sum_{Y_1, \\dots, Y_n \\in \\text{ Permuations}(X_1, \\dots, X_n)}  \\frac{1}{(b-a)^n}$$\n$$=\\frac{n!}{(b-a)^n}$$\n\\end{document}\n% End of body.", "meta": {"hexsha": "f5a857c23cb7111c2a20bb62c4fc398c4b3057e6", "size": 2952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": ".archive/notes/examples/proofs.tex", "max_stars_repo_name": "abhmul/projects-repo", "max_stars_repo_head_hexsha": "6d3a8110ce69219e769e0e56d14fbe394f6389c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": ".archive/notes/examples/proofs.tex", "max_issues_repo_name": "abhmul/projects-repo", "max_issues_repo_head_hexsha": "6d3a8110ce69219e769e0e56d14fbe394f6389c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": ".archive/notes/examples/proofs.tex", "max_forks_repo_name": "abhmul/projects-repo", "max_forks_repo_head_hexsha": "6d3a8110ce69219e769e0e56d14fbe394f6389c6", "max_forks_repo_licenses": ["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.0, "max_line_length": 411, "alphanum_fraction": 0.6893631436, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6281105370831401}}
{"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{\\fromlectures}{{\\\\ \\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\\newcommand{\\rtp}{{\\\\ \\color{blue} \\hspace*{\\fill}(required to prove)} \\\\}\n\n\\newcommand{\\f}[1]{o_{#1}x_{#1}y_{#1}z_{#1}}\n\\newcommand{\\rx}[1]{\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & cos(#1) & -sin(#1) & 0 \\\\ 0 & sin(#1) & cos(#1) & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\rz}[1]{\\begin{bmatrix} cos(#1) & -sin(#1) & 0 & 0 \\\\ sin(#1) & cos(#1) & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\iden}{\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\trans}[3]{\\begin{bmatrix} 1 & 0 & 0 & #1 \\\\ 0 & 1 & 0 & #2 \\\\ 0 & 0 & 1 & #3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\n\\title{CSci 5551 - HW4}\n\\author{Yashasvi Sriram Patkuri\\\\patku001@umn.edu}\n\n\\begin{document}\n\\maketitle\n\\pagebreak\n\n\\section{}\nA three link three joint planar robot with link lengths $l_1, l_2, l_3$ respectively is considered.\n\\given\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{q1.png}\n  \\caption{Three link three joint robot}\n  \\label{fig:q1.1}\n\\end{figure}\nAssigning frames according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    % F0\n    \\draw [->]       (0, 0) -- (2, 0) node [right] {$x_0$};\n    \\draw            (0, 0) circle (0.15cm);\n    \\draw [fill]     (0, 0) circle (0.07cm) node [left] {$z_0$};\n    % F1\n    \\draw [->]       (4, 2) -- (5.7888, 2.8944) node [right] {$x_1$};\n    \\draw            (4, 2) circle (0.15cm);\n    \\draw [fill]     (4, 2) circle (0.07cm) node [left] {$z_1$};\n    % F2\n    \\draw [->]       (6, 5) -- (7.414, 6.414) node [right] {$x_2$};\n    \\draw            (6, 5) circle (0.15cm);\n    \\draw [fill]     (6, 5) circle (0.07cm) node [left] {$z_2$};\n    % F3\n    \\draw [->]       (9, 5) -- (11, 5) node [right] {$x_3$};\n    \\draw            (9, 5) circle (0.15cm);\n    \\draw [fill]     (9, 5) circle (0.07cm) node [left] {$z_3$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q1.2}\n\\end{figure}\n\n\\begin{enumerate}[nolistsep]\n  \\item The z-axes are chosen along the axes of rotation and out of paper for the end-effector.\n  \\item The choice of $x_0$ is free so it is chosen to be parallel to ground for simplicity.\n  \\item There is a unique common normal b/w $z_0$ and $z_1$, along which $x_1$ is chosen.\n  \\item $x_2$ and $x_3$ are chosen in the same way.\n\\end{enumerate}\n\n\\subsubsection*{DH parameters}\nThe DH parameters for the frames shown in Figure \\ref{fig:q1.2} are as follows\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $\\theta_1$ & 0 & $l_1$ & $0^{\\circ}$ \\\\\n $1 \\to 2$ & $\\theta_2$ & 0 & $l_2$ & $0^{\\circ}$ \\\\\n $2 \\to 3$ & $\\theta_3$ & 0 & $l_3$ & $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Finding transformation $T_{01}, T_{02}, T_{03}$}\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{01}$\n\\[\n  T_{01} \\equiv Rot_{z,\\theta_1} * Trans_{z, 0} * Trans_{x, l_1} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\trans{0}{0}{0} * \\trans{l_1}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\iden * \\trans{l_1}{0}{0} * \\iden\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\trans{l_1}{0}{0}\n\\]\n\\[\n  T_{01} \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nWhere $c_1 \\equiv cos(\\theta_1), s_1 \\equiv sin(\\theta_1)$.\n$T_{12}, T_{23}$ have the same DH-parameter structure with changed variables, therefore we can use the final form of $T_{01}$ for them.\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix} c_2 & -s_2 & 0 & l_2c_2 \\\\ s_2 & c_2 & 0 & l_2s_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{23} \\equiv\n  \\begin{bmatrix} c_3 & -s_3 & 0 & l_3c_3 \\\\ s_3 & c_3 & 0 & l_3s_3 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nBut\n\\[\n  T_{ij} \\equiv T_{ik} * T_{kj}\n\\]\n\\fromlectures\nTherefore,\n\\[\n  T_{02} \\equiv T_{01} * T_{12}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} c_2 & -s_2 & 0 & l_2c_2 \\\\ s_2 & c_2 & 0 & l_2s_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_1c_2 - s_1s_2 & -(s_1c_2 + c_1s_2) & 0 & l_1c_1 + l_2(c_1c_2 - s_1s_2) \\\\ s_1c_2 + c_1s_2 & c_1c_2 - s_1s_2 & 0 & l_1s_1 + l_2(s_1c_2 + c_1s_2) \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_{12} & -s_{12} & 0 & l_1c_1 + l_2c_{12} \\\\ s_{12} & c_{12} & 0 & l_1s_1 + l_2s_{12} \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nWhere $c_{12} \\equiv cos(\\theta_1 + \\theta_2), s_{12} \\equiv sin(\\theta_1 + \\theta_2)$.\nConsider $T_{03}$,\n\\[\n  T_{03} \\equiv T_{02} * T_{23}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix} c_{12} & -s_{12} & 0 & l_1c_1 + l_2c_{12} \\\\ s_{12} & c_{12} & 0 & l_1s_1 + l_2s_{12} \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} c_3 & -s_3 & 0 & l_3c_3 \\\\ s_3 & c_3 & 0 & l_3s_3 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    c_{12}c_{3} - s_{12}s_{3} & -(s_{12}c_{3} + c_{12}s_{3}) & 0 & l_1c_1 + l_2c_{12} + l_3(c_{12}c_{3} - s_{12}s_{3})\\\\\n    s_{12}c_{3} + c_{12}s_{3} & c_{12}c_{3} - s_{12}s_{3}    & 0 & l_1s_1 + l_2s_{12} + l_3(s_{12}c_{3} + c_{12}s_{3})\\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    c_{123} & -s_{123} & 0 & l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    s_{123} & c_{123}  & 0 & l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\n\\subsubsection*{Finding Jacobian}\nFor a 3R robot, the Jacobian of pose of end effector w.r.t frame 0 as a function of joint variables\n\\[\n  J \\equiv\n  \\begin{bmatrix} z_0^0 \\times a_{03}^0 & z_1^0 \\times a_{13}^0 & z_2^0 \\times a_{23}^0 \\\\ z_0^0 & z_1^0 & z_2^0 \\end{bmatrix}\n\\]\nwhere\n\\[\n  a_{i3}^{0} \\equiv a_{3}^{0} - a_{i}^{0}\n\\]\nwhere $a_3^0$ is the origin of frame 3 in frame 0 and $a_i^0$ is origin of frame i in frame 0.\n$z_i^0$ can be obtained by the first three number of third column of $T_{0i}$.\n\\fromlectures\n\\[\n  z_0^{0} \\equiv z_1^{0} \\equiv z_2^{0} \\equiv z_3^{0} \\equiv \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\nConsider $a_{3}^{0}$,\n\\[\n  a_3^0 \\equiv T_{03} * O_3\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    c_{123} & -s_{123} & 0 & l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    s_{123} & c_{123}  & 0 & l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\nConsider $a_{2}^{0}$,\n\\[\n  a_2^0 \\equiv T_{02} * O_2\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix} c_{12} & -s_{12} & 0 & l_1c_1 + l_2c_{12} \\\\ s_{12} & c_{12} & 0 & l_1s_1 + l_2s_{12} \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12}\\\\\n    l_1s_1 + l_2s_{12}\\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\nConsider $a_{1}^{0}$,\n\\[\n  a_1^0 \\equiv T_{01} * O_1\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\nAnd,\n\\[\n  a_0^0 \\equiv \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\nRemoving the homogeneous fourth coordinate we have,\n\\[\n  a_0^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0  \\end{bmatrix}\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12}\\\\\n    l_1s_1 + l_2s_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{03}^0$,\n\\[\n  a_{03}^0 \\equiv a_3^0 - a_0^0\n\\]\n\\[\n  a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0  \\end{bmatrix}\n\\]\n\\[\n  a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{13}^0$,\n\\[\n  a_{13}^0 \\equiv a_3^0 - a_1^0\n\\]\n\\[\n  a_{13}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_{13}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_{12} + l_3c_{123}\\\\\n    l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{23}^0$,\n\\[\n  a_{23}^0 \\equiv a_3^0 - a_2^0\n\\]\n\\[\n  a_{23}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12}\\\\\n    l_1s_1 + l_2s_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_{23}^0 \\equiv\n  \\begin{bmatrix}\n    l_3c_{123}\\\\\n    l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider the cross product of the form,\n\\[\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times \\begin{bmatrix} a \\\\ b \\\\ 0 \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} -b \\\\ a \\\\ 0 \\end{bmatrix}\n\\]\nFinally,\n\\[\n  z_0^0 \\times a_{03}^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times\n  \\begin{bmatrix}\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    l_1s_1 + l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + l_2s_{12} + l_3s_{123})\\\\\n    l_1c_1 + l_2c_{12} + l_3c_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  z_1^0 \\times a_{13}^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times\n  \\begin{bmatrix}\n    l_2c_{12} + l_3c_{123}\\\\\n    l_2s_{12} + l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_2s_{12} + l_3s_{123})\\\\\n    l_2c_{12} + l_3c_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  z_2^0 \\times a_{23}^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times\n  \\begin{bmatrix}\n    l_3c_{123}\\\\\n    l_3s_{123}\\\\\n    0\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_3s_{123})\\\\\n    l_3c_{123}\\\\\n    0\n  \\end{bmatrix}\n\\]\nUsing these to build the Jacobian,\n\\[\n  J \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + l_2s_{12} + l_3s_{123}) & -(l_2s_{12} + l_3s_{123}) & -(l_3s_{123})\\\\\n    l_1c_1 + l_2c_{12} + l_3c_{123} & l_2c_{12} + l_3c_{123} & l_3c_{123}\\\\\n    0 & 0 & 0 \\\\\n    0 & 0 & 0 \\\\\n    0 & 0 & 0 \\\\\n    1 & 1 & 1 \\\\\n  \\end{bmatrix}\n\\]\n\n\\subsubsection*{Finding $v$ and $\\omega$ of $O_c$}\nThe $v$ and $\\omega$ of $O_c$ are not dependent on the last joint.\nConsider a manipulator identical to the original one for the first one and half link.\nThe new manipulator will have its end-effector at $O_c$.\nThe required quantities can be found by repeating the same process of finding Jacobian as done for the original manipulator.\n\nAssigning frames for the new manipulator according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    % F0\n    \\draw [->]       (0, 0) -- (2, 0) node [right] {$x_0$};\n    \\draw            (0, 0) circle (0.15cm);\n    \\draw [fill]     (0, 0) circle (0.07cm) node [left] {$z_0$};\n    % F1\n    \\draw [->]       (4, 2) -- (5.7888, 2.8944) node [right] {$x_1$};\n    \\draw            (4, 2) circle (0.15cm);\n    \\draw [fill]     (4, 2) circle (0.07cm) node [left] {$z_1$};\n    % F2\n    \\draw [->]       (5, 4) -- (6.414, 5.414) node [right] {$x_2$};\n    \\draw            (5, 4) circle (0.15cm);\n    \\draw [fill]     (5, 4) circle (0.07cm) node [left] {$z_2$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q1.3}\n\\end{figure}\n\n\\begin{enumerate}[nolistsep]\n  \\item The z-axes are chosen along the axes of rotation and out of paper for the end-effector.\n  \\item The choice of $x_0$ is free so it is chosen to be parallel to ground for simplicity.\n  \\item There is a unique common normal b/w $z_0$ and $z_1$, along which $x_1$ is chosen.\n  \\item $x_2$ is chosen in the same way.\n\\end{enumerate}\n\n\\subsubsection*{DH parameters}\nThe DH parameters for the frames shown in Figure \\ref{fig:q1.3} are as follows\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $\\theta_1$ & 0 & $l_1$ & $0^{\\circ}$ \\\\\n $1 \\to 2$ & $\\theta_2$ & 0 & $l_2 / 2$ & $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Finding transformation $T_{01}, T_{02}$}\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{01}$\n\\[\n  T_{01} \\equiv Rot_{z,\\theta_1} * Trans_{z, 0} * Trans_{x, l_1} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\trans{0}{0}{0} * \\trans{l_1}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\iden * \\trans{l_1}{0}{0} * \\iden\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\trans{l_1}{0}{0}\n\\]\n\\[\n  T_{01} \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nWhere $c_1 \\equiv cos(\\theta_1), s_1 \\equiv sin(\\theta_1)$.\n$T_{12}$ has the same DH-parameter structure with changed variables, therefore we can use the final form of $T_{01}$ for it.\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix} c_2 & -s_2 & 0 & \\frac{l_2}{2}c_2 \\\\ s_2 & c_2 & 0 & \\frac{l_2}{2}s_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nBut\n\\[\n  T_{ij} \\equiv T_{ik} * T_{kj}\n\\]\n\\fromlectures\nTherefore,\n\\[\n  T_{02} \\equiv T_{01} * T_{12}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} c_2 & -s_2 & 0 & \\frac{l_2}{2}c_2 \\\\ s_2 & c_2 & 0 & \\frac{l_2}{2}s_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_1c_2 - s_1s_2 & -(s_1c_2 + c_1s_2) & 0 & l_1c_1 + \\frac{l_2}{2}(c_1c_2 - s_1s_2) \\\\ s_1c_2 + c_1s_2 & c_1c_2 - s_1s_2 & 0 & l_1s_1 + \\frac{l_2}{2}(s_1c_2 + c_1s_2) \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix} c_{12} & -s_{12} & 0 & l_1c_1 + \\frac{l_2}{2}c_{12} \\\\ s_{12} & c_{12} & 0 & l_1s_1 + \\frac{l_2}{2}s_{12} \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nWhere $c_{12} \\equiv cos(\\theta_1 + \\theta_2), s_{12} \\equiv sin(\\theta_1 + \\theta_2)$.\n\n\\subsubsection*{Finding Jacobian}\nFor a 2R robot, the Jacobian of pose of end effector w.r.t frame 0 as a function of joint variables\n\\[\n  J \\equiv\n  \\begin{bmatrix} z_0^0 \\times a_{02}^0 & z_1^0 \\times a_{12}^0\\\\ z_0^0 & z_1^0 \\end{bmatrix}\n\\]\nwhere\n\\[\n  a_{i2}^{0} \\equiv a_{2}^{0} - a_{i}^{0}\n\\]\nwhere $a_2^0$ is the origin of frame 2 in frame 0 and $a_i^0$ is origin of frame i in frame 0.\n$z_i^0$ can be obtained by the first three number of third column of $T_{0i}$.\n\\fromlectures\n\\[\n  z_0^{0} \\equiv z_1^{0} \\equiv z_2^{0} \\equiv \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\nConsider $a_{2}^{0}$,\n\\[\n  a_2^0 \\equiv T_{02} * O_2\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    c_{12} & -s_{12} & 0 & l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    s_{12} & c_{12} & 0 & l_1s_1 + \\frac{l_2}{2}s_{12} \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12} \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\nConsider $a_{1}^{0}$,\n\\[\n  a_1^0 \\equiv T_{01} * O_1\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix} c_1 & -s_1 & 0 & l_1c_1 \\\\ s_1 & c_1 & 0 & l_1s_1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\nAnd,\n\\[\n  a_0^0 \\equiv \\begin{bmatrix} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\nRemoving the homogeneous fourth coordinate we have,\n\\[\n  a_0^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0  \\end{bmatrix}\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{02}^0$,\n\\[\n  a_{02}^0 \\equiv a_2^0 - a_0^0\n\\]\n\\[\n  a_{02}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 0  \\end{bmatrix}\n\\]\n\\[\n  a_{02}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{12}^0$,\n\\[\n  a_{12}^0 \\equiv a_2^0 - a_1^0\n\\]\n\\[\n  a_{12}^0 \\equiv\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    l_1c_1\\\\\n    l_1s_1\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_{12}^0 \\equiv\n  \\begin{bmatrix}\n    \\frac{l_2}{2}c_{12}\\\\\n    \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider the cross product of the form,\n\\[\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times \\begin{bmatrix} a \\\\ b \\\\ 0 \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} -b \\\\ a \\\\ 0 \\end{bmatrix}\n\\]\nFinally,\n\\[\n  z_0^0 \\times a_{02}^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times\n  \\begin{bmatrix}\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    l_1s_1 + \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + \\frac{l_2}{2}s_{12})\\\\\n    l_1c_1 + \\frac{l_2}{2}c_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  z_1^0 \\times a_{12}^0 \\equiv\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times\n  \\begin{bmatrix}\n    \\frac{l_2}{2}c_{12}\\\\\n    \\frac{l_2}{2}s_{12}\\\\\n    0\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(\\frac{l_2}{2}s_{12})\\\\\n    \\frac{l_2}{2}c_{12}\\\\\n    0\n  \\end{bmatrix}\n\\]\nUsing these to build the Jacobian,\n\\[\n  J \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + \\frac{l_2}{2}s_{12}) & -(\\frac{l_2}{2}s_{12})\\\\\n    l_1c_1 + \\frac{l_2}{2}c_{12} & \\frac{l_2}{2}c_{12}\\\\\n    0 & 0 \\\\\n    0 & 0 \\\\\n    0 & 0 \\\\\n    1 & 1 \\\\\n  \\end{bmatrix}\n\\]\nFinally,\n\\[\n  \\begin{bmatrix} v \\\\ \\omega \\end{bmatrix}\n  \\equiv\n  J *\n  \\begin{bmatrix} \\frac{d\\theta_1}{dt} \\\\ \\frac{d\\theta_2}{dt} \\end{bmatrix}\n\\]\n\\[\n  \\begin{bmatrix} v \\\\ \\omega \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + \\frac{l_2}{2}s_{12}) & -(\\frac{l_2}{2}s_{12})\\\\\n    l_1c_1 + \\frac{l_2}{2}c_{12} & \\frac{l_2}{2}c_{12}\\\\\n    0 & 0 \\\\\n    0 & 0 \\\\\n    0 & 0 \\\\\n    1 & 1 \\\\\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix} \\frac{d\\theta_1}{dt} \\\\ \\frac{d\\theta_2}{dt} \\end{bmatrix}\n\\]\n\\[\n  \\begin{bmatrix} v \\\\ \\omega \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + \\frac{l_2}{2}s_{12}) * \\frac{d\\theta_1}{dt} - (\\frac{l_2}{2}s_{12}) * \\frac{d\\theta_2}{dt} \\\\\n    l_1c_1 + \\frac{l_2}{2}c_{12} * \\frac{d\\theta_1}{dt} + \\frac{l_2}{2}c_{12} * \\frac{d\\theta_2}{dt}\\\\\n    0 \\\\\n    0 \\\\\n    0 \\\\\n    \\frac{d\\theta_1}{dt} + \\frac{d\\theta_2}{dt}\\\\\n  \\end{bmatrix}\n\\]\nTherefore,\n\\[\n  v\n  \\equiv\n  \\begin{bmatrix}\n    -(l_1s_1 + \\frac{l_2}{2}s_{12}) * \\frac{d\\theta_1}{dt} - \\frac{l_2}{2}s_{12} * \\frac{d\\theta_2}{dt} \\\\\n    (l_1c_1 + \\frac{l_2}{2}c_{12}) * \\frac{d\\theta_1}{dt} + \\frac{l_2}{2}c_{12} * \\frac{d\\theta_2}{dt}\\\\\n    0 \\\\\n  \\end{bmatrix},\n  \\omega\n  \\equiv\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    \\frac{d\\theta_1}{dt} + \\frac{d\\theta_2}{dt}\\\\\n  \\end{bmatrix}\n\\]\n\n\\pagebreak\n\n\\section{}\nA three link three joint robot with link lengths $l_1, l_2, l_3$ respectively is considered.\n\\given\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{q2.png}\n  \\caption{Three link three joint robot}\n  \\label{fig:q2.1}\n\\end{figure}\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    \\draw [dashed, red]       (-3, 0) -- (-3, 3) node [right] {$l_1$};\n    \\draw [dashed, red]       (0, 5) -- (3, 5) node [right] {$l_2$};\n    \\draw [dashed, red]       (3, 4) -- (6, 4) node [right] {$l_3$};\n    % F0\n    \\draw [->]       (0, 0) -- (0, 1) node [right] {$z_0$};\n    \\draw            (0, 0) circle (0.15cm);\n    \\draw [fill]     (0, 0) circle (0.07cm) node [left] {$x_0$};\n    % F1\n    \\draw [->]       (0, 3) -- (1, 3) node [right] {$x_1$};\n    \\draw            (0, 3) circle (0.15cm);\n    \\draw [fill]     (0, 3) circle (0.07cm) node [left] {$z_1$};\n    % F2\n    \\draw [->]       (3, 3) -- (4, 3) node [right] {$x_2$};\n    \\draw            (3, 3) circle (0.15cm);\n    \\draw [fill]     (3, 3) circle (0.07cm) node [left] {$z_2$};\n    % F3\n    \\draw [->]       (6, 3) -- (7, 3) node [right] {$x_3$};\n    \\draw            (6, 3) circle (0.15cm);\n    \\draw [fill]     (6, 3) circle (0.07cm) node [left] {$z_3$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q2.2}\n\\end{figure}\n\n\\subsubsection*{DH parameters}\nThe DH parameters for the frames shown in Figure \\ref{fig:q2.2} are as follows\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $\\theta_1$ & $l_1$ & $ 0 $ & $90^{\\circ}$ \\\\\n $1 \\to 2$ & $\\theta_2$ & 0     & $l_2$ & $0^{\\circ}$ \\\\\n $2 \\to 3$ & $\\theta_3$ & 0     & $l_3$ & $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Finding transformation $T_{01}, T_{02}, T_{03}$}\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{01}$\n\\[\n  T_{01} \\equiv Rot_{z,\\theta_1} * Trans_{z, l_1} * Trans_{x, 0} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv Rot_{z,\\theta_1} * Trans_{z, l_1} * \\iden * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv Rot_{z,\\theta_1} * Trans_{z, l_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{\\theta_1} * \\trans{0}{0}{l_1} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv\n  \\begin{bmatrix}\n    c_1 & -s_1 & 0 & 0 \\\\\n    s_1 & c_1 & 0 & 0 \\\\\n    0 & 0 & 1 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix} * \\rx{90^{\\circ}}\n\\]\nwhere $c_i \\equiv cos(\\theta_i), s_i \\equiv sin(\\theta_i)$.\n\\[\n  T_{01} \\equiv\n  \\begin{bmatrix}\n    c_1 & 0 & s_1 & 0 \\\\\n    s_1 & 0 & -c_1 & 0 \\\\\n    0 & 1 & 0 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nConsider $T_{12}$\n\\[\n  T_{12} \\equiv Rot_{z,\\theta_2} * Trans_{z, 0} * Trans_{x, l_2} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_2} * \\iden * \\trans{l_2}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_2} * \\iden * \\trans{l_2}{0}{0} * \\iden\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_2} * \\trans{l_2}{0}{0}\n\\]\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix}\n    c_2 & -s_2 & 0 & l_2c_2 \\\\\n    s_2 & c_2 & 0 & l_2s_2 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n$T_{23}$ has same DH structure as $T_{12}$, therefore we can use the final form of the latter. Therefore,\n\\[\n  T_{23} \\equiv\n  \\begin{bmatrix}\n    c_3 & -s_3 & 0 & l_3c_3 \\\\\n    s_3 & c_3 & 0 & l_3s_3 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nBut\n\\[\n  T_{ij} \\equiv T_{ik} * T_{kj}\n\\]\n\\fromlectures\nTherefore,\n\\[\n  T_{02} \\equiv T_{01} * T_{12}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix}\n    c_1 & 0 & s_1 & 0 \\\\\n    s_1 & 0 & -c_1 & 0 \\\\\n    0 & 1 & 0 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    c_2 & -s_2 & 0 & l_2c_2 \\\\\n    s_2 & c_2 & 0 & l_2s_2 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix}\n    c_1c_2 & -c_1s_2 & s_1 & l_2c_1c_2 \\\\\n    s_1c_2 & -s_1s_2 & -c_1 & l_2s_1c_2 \\\\\n    s_2 & c_2 & 0 & l_2s_2 + l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv T_{02} * T_{23}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    c_1c_2 & -c_1s_2 & s_1 & l_2c_1c_2 \\\\\n    s_1c_2 & -s_1s_2 & -c_1 & l_2s_1c_2 \\\\\n    s_2 & c_2 & 0 & l_2s_2 + l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    c_3 & -s_3 & 0 & l_3c_3 \\\\\n    s_3 & c_3 & 0 & l_3s_3 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    c_1(c_2c_3 - s_2s_3) & -c_1(s_2c_3 + c_2s_3) & s_1  & c_1l_2c_2 + c_1l_3(c_2c_3 - s_2s_3) \\\\\n    s_2(c_2c_3 - s_2s_3) & -s_1(s_2c_3 + c_2s_3) & -c_1 & s_1l_2c_2 + s_1l_3(c_2c_3 - s_2s_3) \\\\\n    s_2c_3 + c_2s_3      & c_2c_3 - s_2s_3       & 0    & l_2s_2 + l_3(s_2c_3 + c_2s_3) + l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    c_1c_{23} & -c_1s_{23} & s_1  & l_2c_1c_2 + l_3c_1c_{23} \\\\\n    s_1c_{23} & -s_1s_{23} & -c_1 & l_2s_1c_2 + l_3s_1c_{23} \\\\\n    s_{23}    & c_{23}     & 0    & l_1 + l_2s_2 + l_3s_{23} \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\n\\subsubsection*{Finding Jacobian}\nFor a 3R robot, the Jacobian of pose of end effector w.r.t frame 0 as a function of joint variables\n\\[\n  J \\equiv\n  \\begin{bmatrix} z_0^0 \\times a_{03}^0 & z_1^0 \\times a_{13}^0 & z_2^0 \\times a_{23}^0 \\\\ z_0^0 & z_1^0 & z_2^0 \\end{bmatrix}\n\\]\nwhere\n\\[\n  a_{i3}^{0} \\equiv a_{3}^{0} - a_{i}^{0}\n\\]\nwhere $a_3^0$ is the origin of frame 3 in frame 0 and $a_i^0$ is origin of frame i in frame 0.\n$z_i^0$ can be obtained by the first three number of third column of $T_{0i}$.\n\\fromlectures\n\\[\n  z_0^{0} \\equiv \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n\\]\n\\[\n  z_1^{0} \\equiv z_2^{0} \\equiv z_3^{0} \\equiv \\begin{bmatrix} s_1 \\\\ -c_1 \\\\ 0 \\end{bmatrix}\n\\]\nConsider $a_{3}^{0}$,\n\\[\n  a_3^0 \\equiv T_{03} * O_3\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    c_1c_{23} & -c_1s_{23} & s_1  & l_2c_1c_2 + l_3c_1c_{23} \\\\\n    s_1c_{23} & -s_1s_{23} & -c_1 & l_2s_1c_2 + l_3s_1c_{23} \\\\\n    s_{23}    & c_{23}     & 0    & l_1 + l_2s_2 + l_3s_{23} \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23} \\\\\n    1\n  \\end{bmatrix}\n\\]\nConsider $a_{2}^{0}$,\n\\[\n  a_2^0 \\equiv T_{02} * O_2\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    c_1c_2 & -c_1s_2 & s_1 & l_2c_1c_2 \\\\\n    s_1c_2 & -s_1s_2 & -c_1 & l_2s_1c_2 \\\\\n    s_2 & c_2 & 0 & l_2s_2 + l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\n\\[\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 \\\\\n    l_2s_1c_2 \\\\\n    l_2s_2 + l_1 \\\\\n    1\n  \\end{bmatrix}\n\\]\nConsider $a_{1}^{0}$,\n\\[\n  a_1^0 \\equiv T_{01} * O_1\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    c_1 & 0 & s_1 & 0 \\\\\n    s_1 & 0 & -c_1 & 0 \\\\\n    0 & 1 & 0 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\n\\[\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    l_1 \\\\\n    1\n  \\end{bmatrix}\n\\]\nRemoving homogeneous coordinate we have,\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n  a_2^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 \\\\\n    l_2s_1c_2 \\\\\n    l_2s_2 + l_1\n  \\end{bmatrix}\n  a_1^0 \\equiv\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    l_1\n  \\end{bmatrix}\n  a_0^0 \\equiv\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\n\\]\nConsider $a_{03}^0$,\n\\[\n  a_{03}^0 \\equiv a_3^0 - a_0^0\n\\]\n\\[\n  a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\n\\]\n\\[\n  a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n\\]\nConsider $a_{13}^0$,\n\\[\n  a_{13}^0 \\equiv a_3^0 - a_1^0\n\\]\n\\[\n  a_{13}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    l_1\n  \\end{bmatrix}\n\\]\n\\[\n  a_{13}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n\\]\nConsider $a_{23}^0$,\n\\[\n  a_{23}^0 \\equiv a_3^0 - a_2^0\n\\]\n\\[\n  a_{23}^0 \\equiv\n  \\begin{bmatrix}\n    l_2c_1c_2 + l_3c_1c_{23} \\\\\n    l_2s_1c_2 + l_3s_1c_{23} \\\\\n    l_1 + l_2s_2 + l_3s_{23}\n  \\end{bmatrix}\n  -\n  \\begin{bmatrix}\n    l_2c_1c_2 \\\\\n    l_2s_1c_2 \\\\\n    l_2s_2 + l_1\n  \\end{bmatrix}\n\\]\n\\[\n  a_{23}^0 \\equiv\n  \\begin{bmatrix}\n    l_3c_1c_{23} \\\\\n    l_3s_1c_{23} \\\\\n    l_3s_{23}\n  \\end{bmatrix}\n\\]\nThe first 3x3 block of J is\n\\[\n  J_{11} \\equiv\n  \\begin{bmatrix} z_0^0 \\times a_{03}^0 & z_1^0 \\times a_{13}^0 & z_2^0 \\times a_{23}^0\\end{bmatrix}\n\\]\n\\[\n  J_{11} \\equiv\n  \\begin{bmatrix}\n    \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}\n    \\times\n    \\begin{bmatrix}\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      l_2s_1c_2 + l_3s_1c_{23} \\\\\n      l_1 + l_2s_2 + l_3s_{23}\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix} s_1 \\\\ -c_1 \\\\ 0 \\end{bmatrix}\n    \\times\n    \\begin{bmatrix}\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      l_2s_1c_2 + l_3s_1c_{23} \\\\\n      l_2s_2 + l_3s_{23}\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix} s_1 \\\\ -c_1 \\\\ 0 \\end{bmatrix}\n    \\times\n    \\begin{bmatrix}\n      l_3c_1c_{23} \\\\\n      l_3s_1c_{23} \\\\\n      l_3s_{23}\n    \\end{bmatrix}\n  \\end{bmatrix}\n\\]\nConsider the cross product of the form,\n\\[\n  \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\times \\begin{bmatrix} a \\\\ b \\\\ 0 \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix} -b \\\\ a \\\\ 0 \\end{bmatrix}\n\\]\nTherefore simplifying first column,\n\\[\n  J_{11} \\equiv\n  \\begin{bmatrix}\n    \\begin{bmatrix}\n      -l_2s_1c_2 - l_3s_1c_{23} \\\\\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      0\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix} s_1 \\\\ -c_1 \\\\ 0 \\end{bmatrix}\n    \\times\n    \\begin{bmatrix}\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      l_2s_1c_2 + l_3s_1c_{23} \\\\\n      l_2s_2 + l_3s_{23}\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix} s_1 \\\\ -c_1 \\\\ 0 \\end{bmatrix}\n    \\times\n    \\begin{bmatrix}\n      l_3c_1c_{23} \\\\\n      l_3s_1c_{23} \\\\\n      l_3s_{23}\n    \\end{bmatrix}\n  \\end{bmatrix}\n\\]\nSimplifying second and third columns,\n\\[\n  J_{11} \\equiv\n  \\begin{bmatrix}\n    \\begin{bmatrix}\n      -l_2s_1c_2 - l_3s_1c_{23} \\\\\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      0\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix}\n      -l_2c_1s_2 - l_3c_1s_{23} \\\\\n      -l_2s_1s_2 - l_3s_1s_{23} \\\\\n      l_2c_2 + l_3c_{23} (s_1^2 + c_1^2)\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix}\n      -l_3c_1s_{23}\\\\\n      -l_3s_1s_{23}\\\\\n      (c_1^2 + s_1^2)l_3c_{23}\n    \\end{bmatrix}\n  \\end{bmatrix}\n\\]\nBut\n\\[\n  c_1^2 + s_1^2 \\equiv 1\n\\]\n\\[\n  J_{11} \\equiv\n  \\begin{bmatrix}\n    \\begin{bmatrix}\n      -l_2s_1c_2 - l_3s_1c_{23} \\\\\n      l_2c_1c_2 + l_3c_1c_{23} \\\\\n      0\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix}\n      -l_2c_1s_2 - l_3c_1s_{23} \\\\\n      -l_2s_1s_2 - l_3s_1s_{23} \\\\\n      l_2c_2 + l_3c_{23}\n    \\end{bmatrix}\n    &\n    \\begin{bmatrix}\n      -l_3c_1s_{23}\\\\\n      -l_3s_1s_{23}\\\\\n      l_3c_{23}\n    \\end{bmatrix}\n  \\end{bmatrix}\n\\]\n\\[\n  J_{11} \\equiv\n    \\begin{bmatrix}\n      -l_2s_1c_2 - l_3s_1c_{23} & -l_2c_1s_2 - l_3c_1s_{23} & -l_3c_1s_{23}\\\\\n      l_2c_1c_2 + l_3c_1c_{23}  & -l_2s_1s_2 - l_3s_1s_{23} & -l_3s_1s_{23}\\\\\n      0                         & l_2c_2 + l_3c_{23}        & l_3c_{23}\n    \\end{bmatrix}\n\\]\nHence the required relation is proved (I used $l$'s to represent lengths instead of $a$'s).\n\n\\subsubsection*{If $\\theta_3 = 0^{\\circ}$}\nIf $\\theta_3 = 0^{\\circ}$, then $c_{23} = c_2, s_{23} = s_2$. Therefore,\n\\[\n  J_{11} \\equiv\n    \\begin{bmatrix}\n      -l_2s_1c_2 - l_3s_1c_{2} & -l_2c_1s_2 - l_3c_1s_{2} & -l_3c_1s_{2}\\\\\n      l_2c_1c_2 + l_3c_1c_{2}  & -l_2s_1s_2 - l_3s_1s_{2} & -l_3s_1s_{2}\\\\\n      0                         & l_2c_2 + l_3c_{2}        & l_3c_{2}\n    \\end{bmatrix}\n\\]\nTaking common terms out,\n\\[\n  J_{11} \\equiv\n    \\begin{bmatrix}\n      -(l_2 + l_3)s_1c_2 & (l_2 + l_3)(-c_1s_2) & l_3(-c_1s_{2})\\\\\n      (l_2 + l_3)c_1c_2  & (l_2 + l_3)(-s_1s_2) & l_3(-s_1s_{2})\\\\\n      0                  & (l_2 + l_3)c_2        & l_3c_{2}\n    \\end{bmatrix}\n\\]\nObserve the second and third columns are linearly dependent (non-zero multiples of $[-c_1s_2, -s_1s_2, c_2]^T$). When two columns of a matrix are linearly dependent then its determinant $\\equiv 0$ or the matrix loses rank. Therefore $J_{11}$ loses rank i.e. $\\theta_3 = 0$ describes a family of singular configurations for $J_{11}$.\n\n\\pagebreak\n\n\\section{}\nTwo frames $F_0$ and $F_1$ are related by transformation H i.e.\n\\[\n  p^0 \\equiv H * p^1\n\\]\n\\[\n  H \\equiv\n  \\begin{bmatrix} 0 & -1 & 0 & 1 \\\\ 1 & 0 & 0 & -1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\given\nLet\n\\[\n  p^0 \\equiv (x^0, y^0, z^0), p^1 \\equiv (x^1, y^1, z^1)\n\\]\nThen\n\\[\n  \\begin{bmatrix} x^0 \\\\ y^0 \\\\ z^0 \\\\ 1\\end{bmatrix} \\equiv\n  \\begin{bmatrix} 0 & -1 & 0 & 1 \\\\ 1 & 0 & 0 & -1 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} x^1 \\\\ y^1 \\\\ z^1 \\\\ 1\\end{bmatrix}\n\\]\n\\[\n  \\begin{bmatrix} x^0 \\\\ y^0 \\\\ z^0 \\\\ 1\\end{bmatrix} \\equiv\n  \\begin{bmatrix} -y^1 + 1 \\\\ x^1 - 1 \\\\ z^1 \\\\ 1\\end{bmatrix}\n\\]\nTherefore\n\\[\n  \\begin{bmatrix} x^0 \\\\ y^0 \\\\ z^0\\end{bmatrix} \\equiv\n  \\begin{bmatrix} -y^1 + 1 \\\\ x^1 - 1 \\\\ z^1\\end{bmatrix}\n\\]\nTaking derivative w.r.t. time on both sides\n\\[\n  \\frac{d}{dt}\\begin{bmatrix} x^0 \\\\ y^0 \\\\ z^0\\end{bmatrix} \\equiv\n  \\frac{d}{dt}\\begin{bmatrix} -y^1 + 1 \\\\ x^1 - 1 \\\\ z^1\\end{bmatrix}\n\\]\nAs $\\frac{dx^0}{dt} \\equiv v_x^0$ and so on...,\n\\[\n  \\begin{bmatrix} v_x^0 \\\\ v_y^0 \\\\ v_z^0\\end{bmatrix} \\equiv\n  \\begin{bmatrix} -v_y^1 + 0 \\\\ v_x^1 - 0 \\\\ v_z^1\\end{bmatrix}\n\\]\n\\[\n  \\begin{bmatrix} v_x^0 \\\\ v_y^0 \\\\ v_z^0\\end{bmatrix} \\equiv\n  \\begin{bmatrix} -v_y^1 \\\\ v_x^1 \\\\ v_z^1\\end{bmatrix}\n\\]\nGiven $v^1(t) = (3, 1, 0)$, using the above identity we have\n\\[\n  \\begin{bmatrix} v_x^0 \\\\ v_y^0 \\\\ v_z^0\\end{bmatrix} \\equiv\n  \\begin{bmatrix} -1 \\\\ 3 \\\\ 0\\end{bmatrix}\n\\]\nTherefore the velocity w.r.t frame 0 $v^0(t) = (-1, 3, 0) \\frac{m}{s}$\n\n\\pagebreak\n\n\\section{}\nA three link cylindrical robot is considered.\n\\given\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.47\\textwidth]{q4.png}\n  \\caption{Three link three joint robot}\n  \\label{fig:q4.1}\n\\end{figure}\nIt's frame assignment is shown in Figure \\ref{fig:q4.2}. Let the length of link 1 be $l_1$ and the joint variables be $q_1, q_2, q_3$ respectively.\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    \\draw [dashed, red]       (-3, 0) -- (-3, 3) node [right] {$l_1$};\n    \\draw [dashed, red]       (-2, 3) -- (-2, 6) node [right] {$q_2$};\n    \\draw [dashed, red]       (0, 5) -- (3, 5) node [right] {$q_3$};\n    % F0\n    \\draw [->]       (0, 0) -- (0, 1) node [right] {$z_0$};\n    \\draw            (0, 0) circle (0.15cm);\n    \\draw [fill]     (0, 0) circle (0.07cm) node [left] {$x_0$};\n    % F1\n    \\draw [->]       (0, 3) -- (0, 4) node [right] {$z_1$};\n    \\draw            (0, 3) circle (0.15cm);\n    \\draw [fill]     (0, 3) circle (0.07cm) node [left] {$x_1$};\n    % F2\n    \\draw [->]       (0, 6) -- (1, 6) node [right] {$z_2$};\n    \\draw            (0, 6) circle (0.15cm);\n    \\draw [fill]     (0, 6) circle (0.07cm) node [left] {$x_2$};\n    % F3\n    \\draw [->]       (3, 6) -- (4, 6) node [right] {$z_3$};\n    \\draw            (3, 6) circle (0.15cm);\n    \\draw [fill]     (3, 6) circle (0.07cm) node [left] {$x_3$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q4.2}\n\\end{figure}\n\n\\subsubsection*{DH parameters}\nThe DH parameters for the frames shown in Figure \\ref{fig:q4.2} are as follows\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $q_1$ & $l_1$ & $0$ & $0^{\\circ}$ \\\\\n $1 \\to 2$ & $0$   & $q_2$ & $0$ & $-90^{\\circ}$ \\\\\n $2 \\to 3$ & $0$   & $q_3$ & $0$ & $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Finding transformation $T_{01}, T_{02}, T_{03}$}\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{01}$\n\\[\n  T_{01} \\equiv Rot_{z,q_1} * Trans_{z, l_1} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{q_1} * \\trans{0}{0}{l_1} * \\trans{0}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{q_1} * \\trans{0}{0}{l_1} * \\iden * \\iden\n\\]\n\\[\n  T_{01} \\equiv \\rz{q_1} * \\trans{0}{0}{l_1}\n\\]\n\\[\n  T_{01} \\equiv\n  \\begin{bmatrix}\n    cq_1 & -sq_1 & 0 & 0 \\\\\n    sq_1 & cq_1 & 0 & 0 \\\\\n    0 & 0 & 1 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nWhere $cq_1 \\equiv cos(q_1), sq_1 \\equiv sin(q_1)$.\nConsider $T_{12}$\n\\[\n  T_{12} \\equiv Rot_{z, 0} * Trans_{z, q_2} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{0} * \\trans{0}{0}{q_2} * \\trans{0}{0}{0} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\iden * \\trans{0}{0}{q_2} * \\trans{0}{0}{0} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\trans{0}{0}{q_2} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\trans{0}{0}{q_2}\n  *\n  \\begin{bmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & -1 & 0 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & -1 & 0 & q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nConsider $T_{23}$\n\\[\n  T_{23} \\equiv Rot_{z, 0} * Trans_{z, q_3} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{23} \\equiv \\rz{0} * \\trans{0}{0}{q_3} * \\trans{0}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{23} \\equiv \\iden * \\trans{0}{0}{q_3} * \\trans{0}{0}{0} * \\iden\n\\]\n\\[\n  T_{23} \\equiv \\trans{0}{0}{q_3}\n\\]\nBut\n\\[\n  T_{ij} \\equiv T_{ik} * T_{kj}\n\\]\n\\fromlectures\nTherefore,\n\\[\n  T_{02} \\equiv T_{01} * T_{12}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix}\n    cq_1 & -sq_1 & 0 & 0 \\\\\n    sq_1 & cq_1 & 0 & 0 \\\\\n    0 & 0 & 1 & l_1 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & -1 & 0 & q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{02} \\equiv\n  \\begin{bmatrix}\n    cq_1 & 0 & -sq_1 & 0 \\\\\n    sq_1 & 0 & cq_1 & 0 \\\\\n    0 & -1 & 0 & l_1 + q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv T_{02} * T_{23}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    cq_1 & 0 & -sq_1 & 0 \\\\\n    sq_1 & 0 & cq_1 & 0 \\\\\n    0 & -1 & 0 & l_1 + q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\trans{0}{0}{q_3}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix}\n    cq_1 & 0 & -sq_1 & -q_3sq_1 \\\\\n    sq_1 & 0 &  cq_1 &  q_3cq_1 \\\\\n    0 & -1 & 0 & l_1 + q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\n\\subsubsection*{Finding Jacobian}\nFor an RPP robot, the Jacobian of pose of end effector w.r.t frame 0 as a function of joint variables\n\\[\n  J \\equiv\n  \\begin{bmatrix}\n    z_0^0 \\times a_{03}^0 & z_1^0 & z_2^0 \\\\\n    z_0^0 & 0 & 0\n  \\end{bmatrix}\n\\]\nwhere\n\\[\n  a_{i3}^{0} \\equiv a_{3}^{0} - a_{i}^{0}\n\\]\nwhere $a_3^0$ is the origin of frame 3 in frame 0 and $a_i^0$ is origin of frame i in frame 0.\n$z_i^0$ can be obtained by the first three number of third column of $T_{0i}$.\n\\fromlectures\n\\[\n  z_0^0 \\equiv z_1^0 \\equiv \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\n\\[\n  z_2^0 \\equiv\n  \\begin{bmatrix}\n    -sq_1 \\\\\n     cq_1 \\\\\n     0\n  \\end{bmatrix}\n\\]\nConsider $a_3^0$,\n\\[\n  a_3^0 \\equiv T_{03} * O_3\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    cq_1 & 0 & -sq_1 & -q_3sq_1 \\\\\n    sq_1 & 0 &  cq_1 &  q_3cq_1 \\\\\n    0 & -1 & 0 & l_1 + q_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n\\]\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    -q_3sq_1 \\\\\n    q_3cq_1 \\\\\n    l_1 + q_2 \\\\\n    1\n  \\end{bmatrix}\n\\]\nRemoving the homogeneous coordinate,\n\\[\n  a_3^0 \\equiv\n  \\begin{bmatrix}\n    -q_3sq_1 \\\\\n    q_3cq_1 \\\\\n    l_1 + q_2\n  \\end{bmatrix}\n\\]\nConsider $a_0^0$,\n\\[\n  a_0^0 \\equiv \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    0\n  \\end{bmatrix}\n\\]\nTherefore,\n\\[\n  a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    -q_3sq_1 \\\\\n    q_3cq_1 \\\\\n    l_1 + q_2\n  \\end{bmatrix}\n\\]\nConsider\n\\[\n  z_0^0 \\times a_{03}^0 \\equiv\n  \\begin{bmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{bmatrix}\n  \\times\n  \\begin{bmatrix}\n    -q_3sq_1 \\\\\n    q_3cq_1 \\\\\n    l_1 + q_2\n  \\end{bmatrix}\n  \\equiv\n  \\begin{bmatrix}\n    -q_3cq_1 \\\\\n    -q_3sq_1 \\\\\n    0\n  \\end{bmatrix}\n\\]\nUsing these quantities to build the Jacobian,\n\\[\n  J \\equiv\n  \\begin{bmatrix}\n    z_0^0 \\times a_{03}^0 & z_1^0 & z_2^0 \\\\\n    z_0^0 & 0 & 0\n  \\end{bmatrix}\n\\]\n\\[\n  J \\equiv\n  \\begin{bmatrix}\n    -q_3cq_1 & 0 & -sq_1 \\\\\n    -q_3sq_1 & 0 &  cq_1 \\\\\n    0        & 1 &  0 \\\\\n    0 & 0 & 0 \\\\\n    0 & 0 & 0 \\\\\n    1 & 0 & 0\n  \\end{bmatrix}\n\\]\n\n\\subsubsection*{Inspecting for singularities}\nConsider $J_\\omega$,\n\\[\n  J_\\omega \\equiv\n  \\begin{bmatrix}\n    0 & 0 & 0 \\\\\n    0 & 0 & 0 \\\\\n    1 & 0 & 0\n  \\end{bmatrix}\n\\]\n$J_\\omega$ does not depend on configuration therefore it cannot lose rank with configuration.\nConsider $J_v$,\n\\[\n  J_v \\equiv\n  \\begin{bmatrix}\n    -q_3cq_1 & 0 & -sq_1 \\\\\n    -q_3sq_1 & 0 &  cq_1 \\\\\n    0        & 1 &  0\n  \\end{bmatrix}\n\\]\nConsider its determinant (using the third row),\n\\[\n  det(J_v) \\equiv\n  -(-q_3cq_1^2 - q_3sq_1^2)\n\\]\n\\[\n  det(J_v) \\equiv\n  q_3(cq_1^2 + sq_1^2)\n\\]\nBut $cos(\\theta)^2 + sin(\\theta)^2 \\equiv 1, \\forall \\theta \\in R$ therefore,\n\\[\n  det(J_v) \\equiv q_3\n\\]\nAs (the length of third link) $q_3 > 0$ then determinant$(J_v) > 0 \\implies$ $J_v$ does not lose rank for any configuration.\n\nCombining above two results, there are no configurations where $J$ loses rank i.e. there are no singular configurations for the Jacobian $J$.\nHence proved.\n\n\\end{document}\n", "meta": {"hexsha": "c37c3df203ff4649ba6fbce55150aa0d63a2a2d2", "size": 41651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw4/hw4.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": "hw4/hw4.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": "hw4/hw4.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": 24.3573099415, "max_line_length": 332, "alphanum_fraction": 0.5378022136, "num_tokens": 20537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6281105347107918}}
{"text": "\\chapter{Einfügen von Quellcode}\n\\label{chap:code}\n\n\\section{Beispiel für einen Programmcode}\n\n\n\\if 1\\mintedinstall\n\\subsection{Beispiel Minted}\n\t\\begin{minted}[xleftmargin=20pt,linenos]{python}\n\timport numpy as np\n\t\n\tdef incmatrix(genl1,genl2):\n\t\tm = len(genl1)\n\t\tn = len(genl2)\n\t\tM = None #to become the incidence matrix\n\t\tVT = np.zeros((n*m,1), int)  #dummy variable\n\t\n\t\t#compute the bitwise xor matrix\n\t\tM1 = bitxormatrix(genl1)\n\t\tM2 = np.triu(bitxormatrix(genl2),1) \n\t\n\t\tfor i in range(m-1):\n\t\t\tfor j in range(i+1, m):\n\t\t\t\t[r,c] = np.where(M2 == M1[i,j])\n\t\t\t\tfor k in range(len(r)):\n\t\t\t\t\tVT[(i)*n + r[k]] = 1;\n\t\t\t\t\tVT[(i)*n + c[k]] = 1;\n\t\t\t\t\tVT[(j)*n + r[k]] = 1;\n\t\t\t\t\tVT[(j)*n + c[k]] = 1;\n\t\t\t\t\t\n\t\t\t\t\tif M is None:\n\t\t\t\t\t\tM = np.copy(VT)\n\t\t\t\t\telse:\n\t\t\t\t\t\tM = np.concatenate((M, VT), 1)\n\t\t\t\t\t\n\t\t\t\t\tVT = np.zeros((n*m,1), int)\n\t\n\t\treturn M\n\t\\end{minted}\n\\fi\n\n\n\n\n\\subsection{Beispiel listings}\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\t\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\t\n\t\t\t\tif M is None:\n\t\t\t\t\tM = np.copy(VT)\n\t\t\t\telse:\n\t\t\t\t\tM = np.concatenate((M, VT), 1)\n\t\t\t\t\n\t\t\t\tVT = np.zeros((n*m,1), int)\n\t\t\t\t\n\treturn M\n\\end{lstlisting}\n\n", "meta": {"hexsha": "cfe1509920e39ad9d6d4828ac1e673c32e00fba8", "size": 1571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11_bsp.tex", "max_stars_repo_name": "silaskalmbach/Vorlage_Abschlussarbeiten_light", "max_stars_repo_head_hexsha": "37028edf2056af98646e447febe689fb8812e92f", "max_stars_repo_licenses": ["MIT"], "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_bsp.tex", "max_issues_repo_name": "silaskalmbach/Vorlage_Abschlussarbeiten_light", "max_issues_repo_head_hexsha": "37028edf2056af98646e447febe689fb8812e92f", "max_issues_repo_licenses": ["MIT"], "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_bsp.tex", "max_forks_repo_name": "silaskalmbach/Vorlage_Abschlussarbeiten_light", "max_forks_repo_head_hexsha": "37028edf2056af98646e447febe689fb8812e92f", "max_forks_repo_licenses": ["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.141025641, "max_line_length": 49, "alphanum_fraction": 0.570973902, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6281105245768664}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\\usepackage[margin=1.25in]{geometry}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{caption}\n\\usepackage{physics}\n\\usepackage{mathrsfs}\n\\usepackage[shortlabels]{enumitem}\n\n\n\\setlength\\parindent{0pt}\n\\newcommand{\\code}{\\lstinline[basicstyle=\\small]}\n\\lstset{\n    language=Python,\n    basicstyle=\\scriptsize\n}\n\n\n\\title{EE2703: Applied Programming Lab \\\\ \\Large Assignment 8: The Digital Fourier Transform}\n\\author{Soham Roy \\\\ \\normalsize EE20B130}\n\\date{\\today}\n\\begin{document}\n\n\\maketitle % Insert the title, author and date\n\n\n\n\\section{Introduction}\nThe goal of this assignment is to analyse signals in the frequency domain. The Discrete Fourier Transform (DFT)\nis a powerful tool for this purpose, and has been calculated using the Fast Fourier Transform (FFT) Algorithm.\nThe Continuous Time Fourier Transform (CTFT) of a gaussian has also been approximated using the FFT. For this,\nwe use the \\code{numpy} library.\n\n\n\n\\section{Subquestions}\n\n\\subsection{Work through the Examples}\n\n\\subsubsection{Random Data}\nThe Fourier Transform of a random signal has been evaluated, and then the Inverse Fourier Transform of\nthe result is evaluated. The maximum absolute error of the result and the original signal varies, but usually\nhas an order of magnitude of -16.\n\\begin{lstlisting}\n    x = np.random.rand(100)\n    X = fft(x)\n    y = ifft(X)\n    np.c_[x, y]\n    print(\"Maximum Absolute Error for Random Data: \", np.abs(x - y).max())\n\\end{lstlisting}\n\n\\subsubsection{Spectrum of $\\sin(5t)$}\nWe begin with the following rudimentary code:\n\\begin{lstlisting}\n    x = np.linspace(0, 2 * np.pi, 128)\n    y = np.sin(5 * x)\n    Y = fft(y)\n\n    plt.figure()\n    plt.subplot(2, 1, 1)\n    plt.title(\"Spectrum of $\\sin(5t)$ without Phase Wrapping\")\n    plt.ylabel(\"$|Y|$\")\n    plt.plot(np.abs(Y), lw=2)\n    plt.grid(True)\n\n    plt.subplot(2, 1, 2)\n    plt.xlabel(\"$\\omega$\")\n    plt.ylabel(\"Phase of $Y$\")\n    plt.plot(np.unwrap(np.angle(Y)), lw=2)\n    plt.grid(True)\n\\end{lstlisting}\nTo obtain:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.8]{eg1.png}\n\\end{figure}\nThe frequencies we sample must exclude $2\\pi$, as it is equivalent to 0. The phase plot must also be shifted\nto go from $-\\pi$ to $\\pi$. For this, a helper function \\code{plotter()} has also been written.\n\\begin{lstlisting}\n    def plotter(w, Y, title, lim, out, xlabel, ylabels=(\"$|Y|$\", r\"$\\angle Y$\")):\n        plt.figure(figsize=(8, 10))\n        plt.subplot(2, 1, 1)\n        plt.title(title, size=16)\n        plt.ylabel(ylabels[0], size=14)\n        plt.plot(w, abs(Y), lw=2)\n        plt.xlim(-lim, lim)\n        plt.grid(True)\n\n        plt.subplot(2, 1, 2)\n        plt.xlabel(xlabel, size=14)\n        plt.ylabel(ylabels[1], size=14)\n        ii = np.where(abs(Y) > 1e-3)\n        plt.plot(w[ii], np.unwrap(np.angle(Y[ii])), \"go\", lw=2)\n        plt.xlim(-lim, lim)\n        plt.grid(True)\n\n        plt.savefig(\"Assignment_08/LaTeX/\" + out)\n\n\n    x = np.linspace(0, 2 * np.pi, 128, endpoint=False)\n    w = np.linspace(-64, 64, 128, endpoint=False)\n\n    Y = fftshift(fft(np.sin(5 * x))) / 128\n    plotter(w, Y, \"Spectrum of $\\sin(5t)$\", 10, \"eg2\", \"$k$\")\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{eg2.png}\n\\end{figure}\n\n\\subsubsection{Spectrum of Amplitude Modulated Wave}\nThe signal to be considered is:\n\\begin{equation*}\n    f(t) = (1 + 0.1\\cos(t))\\cos(10t)\n\\end{equation*}\nThe same helper function has been used as such:\n\\begin{lstlisting}\n    Y = fftshift(fft((1 + 0.1 * np.cos(x)) * np.cos(10 * x))) / 128\n    plotter(w, Y, \"Spectrum of $(1 + 0.1\\cos(t))\\cdot\\cos(10t)$\", 15, \"eg3\")\n\\end{lstlisting}\nThis gives us:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{eg3.png}\n\\end{figure}\nThe number of samples used is not enough to resolve all the peaks, hence the time vector and the number of\nsamples have both been increased such that the sampling frequency remains constant.\n\\begin{lstlisting}\n    x = np.linspace(-4 * np.pi, 4 * np.pi, 512, endpoint=False)\n    w = np.linspace(-64, 64, 512, endpoint=False)\n\n    Y = fftshift(fft((1 + 0.1 * np.cos(x)) * np.cos(10 * x))) / 512\n    plotter(w, Y, \"Spectrum of $(1 + 0.1\\cos(t))\\cdot\\cos(10t)$\", 15, \"eg4\")\n\\end{lstlisting}\nThus, we obtain:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{eg4.png}\n\\end{figure}\n\n\n\\subsection{Generate the Spectrum of $\\sin^3(t)$ and $\\cos^3(t)$}\n\\subsubsection{$\\sin^3(t)$}\n$\\sin^3(t)$ can be expressed as a sum of sine waves as:\n\\begin{equation*}\n    \\sin^3(t) = \\frac{3}{4}\\sin(t) - \\frac{1}{4}\\sin(3t)\n\\end{equation*}\nThus, 2 peaks are expected: at 1 and 3, with phases being of magnitude $= \\frac{\\pi}{2}$.\n\\begin{lstlisting}\n    Y = fftshift(fft(np.sin(x) ** 3)) / 512\n    plotter(w, Y, \"Spectrum of $\\sin^3(t)$\", 15, \"q2a\")\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{q2a.png}\n\\end{figure}\n\n\\subsubsection{$\\cos^3(t)$}\n$\\cos^3(t)$ can be expressed as a sum of cosine waves as:\n\\begin{equation*}\n    \\cos^3(t) = \\frac{3}{4}\\cos(t) + \\frac{1}{4}\\cos(3t)\n\\end{equation*}\nThus, 2 peaks are expected: at 1 and 3, with phases $= 0$.\n\\begin{lstlisting}\n    Y = fftshift(fft(np.cos(x) ** 3)) / 512\n    plotter(w, Y, \"Spectrum of $\\cos^3(t)$\", 15, \"q2b\")\n\\end{lstlisting}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{q2b.png}\n\\end{figure}\n\n\n\\subsection{Frequency Modulated Wave: $\\cos(20t + 5\\cos(t))$}\nThe same helper function is invoked as follows:\n\\begin{lstlisting}\n    Y = fftshift(fft(np.cos(20 * x + 5 * np.cos(x)))) / 512\n    plotter(w, Y, \"Spectrum of $\\cos(20t + 5\\cos(t))$\", 30, \"q3\")\n\\end{lstlisting}\nThis gives us:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{q3.png}\n\\end{figure}\nIt can be seen that many more peaks are present, and that single peaks no longer carry a majority of the energy.\nThus, the signal is phase modulated.\n\n\n\\subsection{The Gaussian}\nWe know that the Fourier Transform of a signal is defined as:\n\\begin{equation*}\n    X(\\omega) = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} x(t) e^{-j\\omega t} dt\n\\end{equation*}\nWe also know that a Gaussian tends to 0 for large magnitudes of $t$. Thus, for some window size $T$,\nwe can approximate its Transform as:\n\\begin{equation*}\n    X(\\omega) = \\frac{1}{2\\pi} \\int_{-T/2}^{T/2} x(t) e^{-j\\omega t} dt\n\\end{equation*}\nApproximating the integral to a Reimann summation of $N$ terms, we get:\n\\begin{equation*}\n    X(\\omega) \\approx \\frac{T}{2\\pi N} \\sum_{n = -N/2}^{N/2 - 1} x(nT/N) e^{-j\\omega nT / N}\n\\end{equation*}\nWhere $T / N$ is the time step. Then, let $\\omega = 2\\pi k / T$:\n\\begin{equation*}\n    X(2\\pi k / T) \\approx \\frac{T}{2\\pi N} \\sum_{n = -N/2}^{N/2 - 1} x(nT/N) e^{-j2\\pi kn/N}\n\\end{equation*}\nWe observe that the summation is the Discrete Fourier Transform (DFT) of the signal. Thus, we get:\n\\begin{equation*}\n    X(2\\pi k / T) \\approx \\frac{T}{2\\pi N} DFT\\{x(nT/N)\\}\n\\end{equation*}\nWe can improve the accuracy of our obtained approximation by choosing a larger window size while keeping the\nsampling frequency constant. We do this iteratively until our error is below a certain threshold.\n\nWe compare our approximation to the actual Continuous Time Fourier Transform (CTFT) of the signal:\n\\begin{equation*}\n    \\mathscr{F}(e^{-\\frac{t^2}{2}}) = \\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{\\omega^2}{2}}\n\\end{equation*}\n\nFor this, we use the following code:\n\\begin{lstlisting}\n    T = 2 * np.pi\n    N = 128\n    iter_n = 0\n    error = None\n    threshold = 1e-6  # 6 decimals of precision\n\n    while error is None or error > threshold:\n        t = np.linspace(-T / 2, T / 2, N, endpoint=False)\n        w = np.linspace(-np.pi, np.pi, N, endpoint=False) * N / T\n        y = np.exp(-0.5 * t ** 2)\n        Y = fftshift(fft(ifftshift(y))) * T / (2 * np.pi * N)\n\n        Y_true = np.exp(-0.5 * w ** 2) / np.sqrt(2 * np.pi)\n        error = np.sum(np.abs(Y - Y_true))\n\n        T *= 2\n        N *= 2\n        iter_n += 1\n        print(f\"Iteration {iter_n}:   Total Error = {error:.2e}\")\n\n    T /= 2\n    N /= 2\n\n    print(f\"Samples = {int(N)},   Time Period = {int(T / np.pi)} pi\")\n\n    plotter(w, Y, \"Spectrum of Approximated Gaussian\", 5, \"q4a\")\n    plotter(w, Y_true, \"Spectrum of True Gaussian\", 5, \"q4b\")\n\\end{lstlisting}\nThis gives us the graphs:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{q4a.png}\n\\end{figure}\nHere, we also have the following output:\n\\begin{lstlisting}\n    Iteration 1:   Total Error = 7.19e-03\n    Iteration 2:   Total Error = 5.35e-09\n    Samples = 256,   Time Period = 4 pi\n\\end{lstlisting}\nThus, we can say that our approximation converged to an accuracy of 6 decimals very fast.\n\\pagebreak\n\nTo compare, the Continuous Time Fourier Transform results in the following graph:\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.6]{q4b.png}\n\\end{figure}\n\n\n\n\\section{Conclusion}\nWe have calculated the DFT of various signals using the FFT Algorithm. We started with a random signal,\nthen sinusoids, combinations of sinusoids, and finally a Gaussian.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "4dda131ea0d8b892855480844caae0f2324dac42", "size": 9076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment_08/LaTeX/Report.tex", "max_stars_repo_name": "sohamroy19/EE2703", "max_stars_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_stars_repo_licenses": ["MIT"], "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_08/LaTeX/Report.tex", "max_issues_repo_name": "sohamroy19/EE2703", "max_issues_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_issues_repo_licenses": ["MIT"], "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_08/LaTeX/Report.tex", "max_forks_repo_name": "sohamroy19/EE2703", "max_forks_repo_head_hexsha": "7ea141082815d80fe765344303d98f96f7a9a492", "max_forks_repo_licenses": ["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.4142857143, "max_line_length": 112, "alphanum_fraction": 0.6549140591, "num_tokens": 2991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185944046238982, "lm_q2_score": 0.8740772417253255, "lm_q1q2_score": 0.6281070151129095}}
{"text": "\\section*{Analytic Learning Theory}\nThis section covers basic definitions and concepts of statistical learning theory.  we approach this from a functional analytic viewpoint.\nSupervised learning in its most abstract setting requires finding a function $f(x)$ given instances ${ (x_i ,f(x_i))}$. Typically ${x_i}$ is an independent and identially distribute (iid) sample from some unknown distribution.  A loss function is a random variable\n\\[ L : Ran(f) \\times Ran(f) \\rightarrow \\dblr^+\\]\n defining the cost of misclassification.  The risk associated with a candidate function $f'$ is defined to be the expectation of the loss over the sample space $\\Omega$,\n\\begin{equation*} R(f')=\\int L( f(\\omega), f'(\\omega)) d\\omega\\end{equation*}.\nStatistical learning theory is concerned with assessing the approximations to $f$ given by minimizing the empirical loss associated with a sample ${x_i ,f(x_i)}$.\n\nThe notion of a loss function goes back to the roots of modern probability theory and economics.  The St. Petersburg paradox is an example of a random variable $S : \\dbln \\rightarrow \\dblr^=$ with infinite expectation limited utility. Let $W(k)$ be the winnings after k plays of from a game with outcome $S$ that pays $2^{i-1}$ with probability $p_i=1/2^i$. The expected payout is given by\n\\begin{equation*}\n\\lim_{k\\To\\infty} W(k)/k =E(S)=\\sum\\limits_{i=1}^{\\infty} p_i 2^{i-1}= \\infty\n\\end{equation*} The implication for a decision theory based only on expected value is that a rational player would pay an infinite amount of money to play this game. Bernoulli introduced the notion of expected utility which takes into account the fact that a payout of $2^i$ may not have twice the utility of a payout of $2^{i+1}$ when $i$ gets large.  The utility $U$ is a random variable on the sample space representing preferences of an agent.  Loss represents the aversion of an agent to the outcomes of the sample space, $L(\\omega)+U(\\omega) = \\alpha \\fall \\omega \\in \\Omega$ where $\\alpha$ is constant.  Expected loss $R(f')$ is the risk associated with choosing the approximation $f'$. Restricting the class of functions to consider when minimizing the risk for a candidate approximation to $f$ is a key aspect of classifier design.\n\n(BBCREVISIT GP  RKHS )Gaussian processes provide a class of models and learning algorithms for real world problems that have a long history and are well characterized. Learning algorithms are cast as minimization problems $min_\\mathcal(H) R() $ in a Hilbert space $ \\mathcal{H}$ with a dot product that encapsulates a model and sample data.  Bayesian methods are often employed for estimation and inference with Gaussian processes. They allow an intuitive approach to incorporating prior knowledge in classification problems and the ability to obtain confidence intervals for predictions.  Many common regression and classification algorithms can be cast as minimization problems in a Reproducing Kernel Hilbert Space (RKHS).\n\n\n\\section*{Learning With Kernels}\n\\cite{KLBurges98atutorial}, \\cite{KLKeerthi99improvementsto}, \\cite{KLProgramminglearningthe},\n\\cite{KLScholkopf00newsupport}, \\cite{KLScholkopf00statisticallearning}, \\cite{KLShevade99improvementsto},\n\\cite{KLTsang03distancemetric}, \\cite{KLWeston00featureselection}, \\cite{KLSchultz03learninga}\nKernel learning is a paradigm for classification and regression where prior belief is expressed in the construction of a similarity matrix of distances between points in a feature space $\\Omega$ by embedding via a non linear map $\\phi$ in a higher [often infinite] dimensional Hilbert space using the kernel as an inner product.\n\\begin{center}\\begin{eqnarray*}\n% \\nonumber to remove numbering (before each equation)\n  K(x,x')= <\\phi(x),\\phi(x')> \\\\\n  K \\succeq 0 \\\\\n  SPD \\Rightarrow \\sum\\limits_{x \\in \\Omega}^{}  \\sum\\limits_{x' \\in \\Omega}^{} f(x) K(x,x') f(x') \\geq 0 \\forall f\\ \\in \\ell^2(\\Omega)\n\\end{eqnarray*}\\end{center}\nRecall that infinitely divisible probability distributions aries as the sum of $iid$ random variables.  Infinitely divisible kernels have the representation\n\\begin{center}\\begin{eqnarray*}\nK=K^{\\frac{1}{n}} \\ldots K^{\\frac{1}{n}} \\\\\nK= e^{\\beta H} \\\\\ne^{\\beta H} = \\lim\\limits_{n\\rightarrow \\infty} (1+ \\frac{\\beta H}{n} )^n\n\\end{eqnarray*}\\end{center}\nWe construct a mutli-resolution representation of the data with exponentiated kernels.  The sequence of kernels $K(\\beta)$ represents a one parameter group associated with a diffusion on the graph of the data.  A $\\beta \\rightarrow  0 \\infty$ the kernel moves from the identity to one that represents the clusters in the off diagonal components.  The local structure of $\\Omega$ is preserved in $H$ while the global geometry of the data set is progressively revealed in $K(\\beta)$ as we push the diffusion forward with the one parameter group.  We can construct exponentiated kernels over direct products of sets $\\Omega_1 \\bigotimes \\Omega_2$ that will allow for the class conditional representation [bbcrevisit term use multiclass].  Simply set $H = H_1 \\bigotimes I_{\\Omega_1} +  H_2 \\bigotimes I_{\\Omega_2}$.\n\\begin{center}\\begin{eqnarray*}\nK(\\beta) = e^{\\beta H} =  e^{(\\beta H_1 \\bigotimes I_{\\Omega_1} +  H_2 \\bigotimes I_{\\Omega_2})} \\Rightarrow \\\\\n\\frac{d}{d \\beta} K(\\beta) =  H (K_1(\\beta) \\bigotimes K_2(\\beta))\n\\end{eqnarray*}\\end{center}\n\nThe kernels thus  constructed can be used to drive a diffusion on a graph by letting $H$ be the familiar graph Laplacian.  Furthermore, the continuum limit of infinite data can be analyzed in within the framework of a discreet stochastic process much the way the convergence of finite element solutions of PDE's takes place.\n\n\n\\section*{Kernel Density Estimation}\nTo define the empirical distribution function of a sample of size $N$ - place mass $1/N$ at each member of the sample.  This forms a nonparametric estimate of the marginal density $P(X)$.  This is a singular form of kernel smoothing for density estimation.  If $\\psi$ belongs to some nice class of function, and $\\int\\limits_{\\infty}^{-\\infty}\\psi(x) dx = 1$, we can form a parametric estimator for the pdf of a process from a sample\npopulation of size $N$ by calculating\n\\begin{equation*} p(x;\\theta)=\\frac{1}{N \\theta}\n\\sum\\limits_{i-1}^{N} \\phi( \\frac{x-X_n}{\\theta})\n\\end{equation*}\nIf $\\phi$ happens to be a density then $p(x,\\theta)$ is also a density.  Letting $\\theta \\rightarrow 0$ for the right kernel, we get the empirical density of the sample population.  The mean squared error of the estimator expressed as a bias term and a variance term is\n\\begin{equation*} Err_p(x;\\theta)= E[p(x;\\theta)-p(x)]^2 =  E[ p(x;\\theta)-p(x)]^2 =\n(E[p(x;\\theta)]-p(x))^2 + Var[ p(x;\\theta)]\n\\end{equation*}\n\n\n\\section*{Distance Functions \\& The Affinity Matrix}\n\nThere are two key ingredients to forming the affinity matrix; a distance function, and a convention for which pairs to consider.  If all or too many pairs are compared, sparse methods will not be possible.  We can include $n$ nearest points, all points within $\\epsilon$ of $x$, or some other criteria. For instance when working with spatial data, the diffusion can be done on a graph formed by a tessellation of the locations.  This is exactly how numerical solutions of heat diffusions are done.\n\nIf the feature vector is a histogram, the $L^2$ distance is not meaningful, in this case use the $\\chi^2$\n\n\\section*{The Graph Cut}\nSpectral clustering is a relaxation to an NP-hard problem of finding an optimal way to cut a graph. Here we describe some various cut criteria.  Let\n\\begin{eqnarray*}\nX_1, \\hdots , X_n \\; \\in \\dblr^n  \\\\\nW_{ij} = s(X_i,X_j) \\\\\nd_i = \\sum_{j} W_{i j}\\\\\n|A| = card (A) \\\\\nvol(A) = \\sum_{i \\in A} d_i\n\\end{eqnarray*}\n\n\\begin{defn}[Min Cut]\n\\begin{equation*} min cut(A,B) =\\sum_{i \\in A \\; j \\in B}  W_ij \\end{equation*}\n\\end{defn}\n\n\\begin{defn}[Balanced Cut / Ratio Cut ]\n\\begin{equation*} min cut (A,B) \\frac{1}{|A|} \\frac{1}{|B|} \\end{equation*}\n\\end{defn}\n\\begin{defn}[n Cut ]\n\\begin{equation*} min cut (A,B) \\frac{1}{vol(A)} \\frac{1}{vol(B)} \\end{equation*}\n\\end{defn}\n\n\n\\section*{Graph Spectra}\nGraph spectral methods are some of the most successful heuristic approaches to partitioning algorithms in solving sparse linear systems, clustering and, ranking problems.  Eigenvalues of the graph Laplacian are used to transform a combinatorial optimization problem to a continuous one, typically a SDP problem.  Recent advances in SDP optimization techniques have opened new avenues of research in combinatorial optimization.  For instance, isoperimetric properties of a graph are used to find efficient communication networks, and fast convergence of Markov Chains.\n\n\n\n\\section*{Matrix Factorization}\nMany forms of matrix factorization can be cast as an optimization problem that involves minimization of generalized Bregman divergences\\cite{BDAUnifiedViewMatrixFactorizationModels}.  Factorization algorithms such as  NNMF, Weighted SVD, Exponential Family PCA, , pLSI, Bregman co-clustering \\cite{CCBanerjee04ageneralized} can be cast in this framework.  The approach uses an alternating projection algorithm for solving the optimization problem which allows for generalizations that include row, column, or relaxed cluster  constraints.  A brief description of the algorithm is given below.  The description of a generalized Bregman divergence can be found in \\cite{BDGordon99approximatesolutions}.\n\n\n\n\\section*{PCA and its generalization to the Exponential Family}\nPCA finds linear combinations of the variables that correspond to directions of maximal variance in the data. Typically this is performed via a singular value decomposition (SVD) of the data matrix $A \\in R^{n,m}$, or via an eigenvalue decomposition if A is a covariance matrix in which case $A \\in R^{n,n}$. Representing the data in the directions of maximum variance allows for a dimension reduction that preserves information. Principal component directions are uncorrelated which can be useful.  PCA has the disadvantage that components are usually linear combinations of all variables. Weights in the linear combination data elements are non-zero. Sparse PCA is an attempt to find a low dimension representation of the data that explainers most of the variance.\n\nHere we describe a generalization  of Principal component analysis (PCA) to the Exponential Family of probability distributions.  PCA is a popular dimensionality reduction technique that seeks to find a low-dimensional subspace passing close to a given set of points \\begin{equation*}\\{x_i\\} \\subset \\mathbb{R}^n\\end{equation*}.  The procedure is to solve the optimization problem that minimizes the sum of squared differences of the data points to the projections on a subspace spanned by the empirical variance after centering the data to have mean $0$;\n\\begin{equation*}\n\\sum\\limits_{i=i}^{n} \\norm{x_i - \\theta_i}^2_{\\ell^2}\n\\end{equation*}.  The choice of $\\ell^2$ norm here codifies the assumption of Gaussian data.  An alternate interpretation of the algorithm is finding the  parameters ${\\theta_i}$ that maximizes the log likelihood of the data which corresponds to \\begin{equation*}\n\\sum\\limits_{i=i}^{n} \\norm{x_i - \\theta_i}^2_{\\ell^2}\n\\end{equation*}.  The goal of PCA is to find the the true low dimensional distribution   of the data given the assumption that data is corrupted by Gaussian noise.\nBregman divergences\n  \\begin{equation*}\n  D_\\phi(A,B)=\\phi(A)-\\phi(B) - \\nabla \\phi(B) (A-B)\n\\end{equation*}\noffer a framework to extend PCA [and other spectral dimension reduction techniques] to the entire Exponential Family.  Here $\\phi$ is a striclty convex function.  The roles of\n\nLet  $\\theta_i$ be the natural parameter for dimension $i$, with Exponential distribution $P_\\theta$.  Then the conditional expectation is given by\n\\begin{equation*}\nlog P_\\theta (x| \\theta) = log P_0(x) + x \\theta - G(\\theta)  \\sp : G \\ni \\int{ P_\\theta dx} =1\n\\end{equation*}\nWe can model multivariate data where the conditional distribution can vary along the feature space.  The common feature of this PCA model and GLZ regression is the derivative of $G$ which is familiar link function and the loss function which is appropriate for $P_\\theta (x | \\theta)$.  The non linear relationship in the GLZ regression model data is captured by the link function $h = \\frac{d}{d \\theta}G(\\theta)'$.  This feature is also passed on to the generalized PCA.  Instead of projecting on to a linear subspace, a Bregman divergence is used as the distortion measure.  This gives a convex optimization problem to solve which can be shown to converge.  In \\cite{BDAzoury99relativeloss} a dual function  to  $\\phi$ is defined by the relationship $\\phi(g(\\theta))+G(\\theta)=h(\\theta) \\theta$ which is used to write the log likelihood as a Bregman divergence\n\\begin{equation*}\n    \\log P( x | \\theta ) = -log P_0(x) - \\phi(x) + D_\\phi (x,h(\\theta))\n\\end{equation*}.  Typically $x$ is a vector but extending to matrices is straightforward.\n\n\nSparse PCA\n[CS Notes from http://ugcs.caltech.edu/~srbecker/\n\nClassic PCA is sensitive to outliers.  Convex methods can be use to address this by attempting to factor the data $X$ as a sum of a low rank component $L$ and a sparse component $S$ by solving\n\\begin{equation*}\n\\underset{min}{S,L} \\norm{L}_* + \\lambda \\norm{S}_{\\ell_1}  : X=L+S\n\\end{equation*}\nSee http://cvxr.com/tfocs/demos/rpca/ for a demo of this in action with the popular cvx software package.\n\n\\section*{Manifold Learning}\nThere are numerous machine learning techniques which accomplish some form of dimensionality reduction.\nManifold learning uses principal curves and manifolds to encode a natural geometric framework for nonlinear dimensionality reduction.  These methods construct low-dimensional data representation using a cost function that retains local properties.\nContrasting methods such as MDS employ proximity data via a similarity or distance matrices.  The important ISOMAP \\cite{MDS_ISOMAP}algorithm extends MDS by capturing geodesic measurements of non-local pairs on the data manifold $M$ via an multi-scale approximation.  Non-local distances are approximated via a shortest path on a K nearest neighbor clustering of the data.  Effectively a ball in data space is used to represent a cluster, and a graph is then constructed to encode the non-local information.  The connectivity of the data points in the neighborhood graph are the nearest k Euclidean neighbors in the feature space.  Dijkstra's algorithm for computing shortest paths with weights is used to construct the proximity matrix from the neighborhood graph.  The top n eigenvectors encode the coordinates in the low dimensional Euclidean space.  Choosing the correct number of neighbors is an essential component to an accurate representation.\nOther shortest path algorithms that may be employed to calculate the geodesic distances are listed below:\n\\begin{itemize}\n  \\item Dijkstra's algorithm finds the single-pair, single-source, and single-destination shortest path.\n  \\item Johnson's algorithm finds all pairs shortest paths\n  \\item Bellman-Ford algorithm single source problem and allows negative edge weights.\n  \\item Floyd-Warshall algorithm solves all pairs shortest paths.\n  \\item A* search algorithm solves the single pair shortest path problem.\n\\end{itemize}\nIn \\cite{MDSBernstein00graphapproximations} a sampling condition is given which bounds the quality of the manifold embedding based on the quality of the neighborhood graph.\n\n\n\\section*{Graph Laplacian}\n\\cite{GLPBoydconvexoptimization}, \\cite{GLPChung93laplaciansof}, \\cite{GLPCrescenzi96toweight},\n\\cite{GLPGuatterygraphembeddings}, \\cite{GLPBoydconvexoptimization},\n\\cite{GLPChung93laplaciansof},\n\\cite{GLPSpectralAnalysisComplexLaplacianMatrices}, \\cite{GLPKellersignedgraph}\n\nLet $G$ be a connected simple graph with vertex set $V = {1, 2, ... , n}$ , edge set $E$ and let each edge be associated with a positive number, called the weight of the edge. The above graph is called a weighted graph. An unweighted graph is just a weighted graph with each of the edges bearing weight 1.  The weight $w(i)$ of a vertex $V_i$ is the sum of the weights of the edges incident with it. There are a number of ways in which the  Laplacian matrix $L$ is defined; the combinatorial Laplacian, the normalized Laplacian and the unsigned Laplacian.  Spectra from graph matrix representations may be obtained from the adjacency matrix $A$ and the various Laplacian discretizations.  Spectra can also be derived from the heat kernel matrix and path length distribution matrix.\n\nThe matrix representation of the graph Laplacian has a significant effect on the spectrum.  Attributes may be accounted for by by a complex number that encodes the edge attributes.  The node attributes may be encoded in the diagonal elements.   The complex graph Laplacian matrix is Hermitian, and hence it has real eigenvalues and complex eigenvectors.  Graph feature vectors can be embedded in a pattern space by PCA, MDS, and LDA( linear discriminant analysis).  Attribute graphs may be characterized by the application of symmetric polynomials to the real and complex components of the eigenvectors. \\cite{GLPAnaFred} This gives rise to permutation invariants that can be used for pattern vectors.  Partitioning a graph into three pieces, with two of them large and connected, and the third a small separator set can be accomplished using the second eigenvector [the Feidler Vector] of the graph Laplacian.  In the case or sparse graphs, the first few eigenvectors can be efficiently computed using the Lanczos algorithm [see section below on ARPAC].  This graph partitioning algorithm can be extended to give a hierarchical subdivision of the graph.\n\n\n\\section*{Distance Metrics}\nA measure of similarity between data points is a vital component to clustering algorithms.  The suitability of any given measure is dependent on the generative process providing the data.\n\n\n\\section*{Markov Chains}\nLet $X \\in \\mathcal{M}$, $P(x,y)$ the transition probability for an irreducible Markov chain. If $P$ is reversible relative to $\\pi$ then we have that $Q(x,y) = \\Pi(x) P(x,y) =\\Pi(y) P(y,x) \\forall x,y, \\in X$.  This implies that $\\pi$ is the stationary distribution.  Bounding the rate of convergence to the stationary distribution is related to $L_G$ and isoperimetric problems.\n\nDetailed balance is a property of a Markov chain where $\\pi(x) P(x,y) =\\pi(y) P(y,x) \\Rightarrow$ reversibility.  This is stronger than the requirement of a stationary distribution.  It is the property that implies for every closed cycle of states there is no flow of probability.\n\nThere are four aspects of Markov chain stability.\n\\begin{enumerate}\n\\item $\\pi$-irreducible\n\\item small set\n\\item Harris recurrence\n\\item Geometric Ergodicity\n\\end{enumerate}\n\nFor reversible Markov chains, the rate of convergence to $\\Pi$ for a finite state chain is determined by the second eigenvalue of $P$.\n\nThere are two types of bounds for the rates of convergence\n\\begin{enumerate}\n\\item graph theoretic Cheeger type - see Diaconis and Stook\n\\item Spectral\n\\end{enumerate}\nThe rate of convergence to $\\pi$ for finite state Markov chains is determined by the second eigenvalue $\\lambda_2$ of $P$.\n\nBBCREVISIT CLEAN UP LOTS\n\\begin{thm}[Perron Frobenius - $P \\in \\dblp^{n \\times n}$ ]\nThere is a simple largest eigenvalue, and it's eigenvector is positive.\n\n\\end{thm}\nThe growth of $P^k$ is determined by the Perron eigenvalue.  Frobenious extended the theorem to include a class of non negative matrices.  This is achieved through the concept of reducibility.  $P$ is irreducible if\n\\begin{equation*}\n\\neg \\exists \\; \\Lambda \\st\\Lambda^\\dag L \\Lambda =\n \\left( \\begin{array}{cc}\nP_{11} & P_{12}  \\\\\n0 & P_{22} \\end{array} \\right)\n\\end{equation*}\nwhere $\\Lambda$ is a projection $\\Lambda^2 = \\Lambda$\nThe irreducible matrices $L$ have a simple largest eigenvalue $\\lambda_n$, now called the Perron-Frobenius eigenvalue whose right eigenvector components are all positive.  We can put this in Markov chain terminology; irreducibility is equivalent to the existence of a unique stationary distribution.\n\nBBC Make the Markov Chain section nice.\n\nHammerlsy Clifford\n\nThe Hammersley–Clifford theorem gives necessary and sufficient conditions for when a positive probability distribution can be represented as a Markov Random Field. It states that a probability distribution that has a positive mass or density satisfies one of the Markov properties with respect to an undirected graph $G$ if and only if it is a Gibbs random field.  The density of the Gibbs random field can be factorized over the cliques (complete subgraphs) of $G$.\n\n\n\\section*{Spectral Graph Theory}\nModern spectral graph theory increasingly takes insights from geometry.  Discrete analogues of isoperimetry results and heat flow on manifolds are just a few examples being put to use in modern applications.  The normalized graph Laplacian is used to aid in consistency between spectral geometry and stochastic processes.  We consider connected graphs $G = (E,V)$ in this work, in which case we can define the normalized graph Laplacian as $\\mathcal{L} = T^{\\frac{1}{2}} L T^{\\frac{-1}{2}} = I - T^{\\frac{1}{2}} A T^{-\\frac{1}{2}}$, where $A$ is the adjacency matrix, L is defined by\n\n\\begin{equation*}\nL(u,v)  = \\Biggl\\{\n\\begin{array}{cc}\n d_v & :\\; u=v \\\\\n -1  & : u\\sim v  \\\\\n 0   & : u \\nsim v  \\end{array}\n\\end{equation*} and\n$T = diag\\{d_1, \\cdots , d_n\\}$ where $d_v$ is the degree of vertex $v$.\n\n$\\mathcal{L}$ is a difference operator :\n\n\\begin{equation*}\n \\mathcal{L}  = \\frac{1}{\\sqrt{d_u}} \\sum\\limits_{}^{v : u \\sim v} ( \\frac{g(u)}{\\sqrt{d_u}} -  \\frac{g(v)}{\\sqrt{d_v} } )\n\\end{equation*}\n\n\\begin{eqnarray}\nVol (G) = \\sum\\limits_{v \\in V}^{d_v} = Tr(T) \\\\\n\\sigma(\\mathcal{L}) \\in \\dblr^+ \\\\\nker ( \\mathcal{L} ) = span\\{ T^{\\frac{1}{2}} \\mathbb{1} \\}\n\\end{eqnarray}\n\n\n\n\n\n\\section*{Diffusion Maps}\n\\cite{DMBremerabstractdiffusion}, \\cite{DMCarnegieinformationdiffusion}, \\cite{DMCoifmandiffusionmaps},\n\\cite{DMKubota00reactiondiffusionsystems}, \\cite{DMLafferty05diffusionkernels},\n\\cite{DMNadler06diffusionmaps}.\n\nSpectral clustering involves constructing a Markov chain over a graph is constructed over the graph of the data and using the sign of the first non-constant eigenvector for graph cuts and cluster localization.  This approach can be generalized to higher-order eigenvectors yielding a multi-resolution view of the data. Using multiple eigenvectors allows one to embed and parameterize the data in a lower dimensional space.  Examples of this procedure include LLE, Laplacian \\& Hessian Eigenmaps.  The common theme among these approaches is that eigenvectors of a Markov process can encode coordinates of the data set on a low dimensional manifold in a Euclidian space.  The advantage over conventional methods is that the representation is non-linear and they preserve local structure. Kernel eigenmap embeddings can be generalized into a diffusion  framework where a discrete Laplacian acts on a low dimensional representation space.  This allows for a true multi-scale parametrization.  Iterating a Markov process involves computing power of the transition matrix to run a random walk of the graph forward in time.   By construction a one parameter map defining the diffusion and specifying boundary conditions the full power of diffusions on a smooth manifold may be brought to bear on parameterizing the geometry of the data.  Different boundary conditions and diffusion operators give rise to a discrete approximations of familiar stochastic PDE's.\n\nLet $(X,\\mathcal{A},\\mu)$ be a measure space and $\\quad k: X \\times Y \\longrightarrow \\dblr $ a kernel function.\n \\begin{eqnarray}\n d(x) &=& \\int\\limits_{X} k(x,y) d \\mu(y)  \\\\\n P(x,y) &=& \\frac{ k(x,y) }{ d(x) }    \\\\\n (D_t (x,y))^2 &=& \\norm{P_t(x, \\cdot) - P_t(y,\\cdot )}_{ L^2(X,\\frac{d\\mu}{\\pi}) }  \\\\\n \\pi(\\mu) &=&  \\frac{d(y)}{z \\in Z^{d(z)} } \\\\\n \\pi(x) p(x,y) &=& \\pi(y) p(y,x)\n \\end{eqnarray}\n\n\n$D_t (x,y)$ is the functionally weighted $L^2$ distance between the 2 posteriors $\\mu \\rightarrow P_t(x,u) $ and $\\mu \\rightarrow P_t(y,u) $.  This is related to isoperimetry. Think about what happens as the cardinality of paths connecting $x$ and $y$ is increased.  $D_t$ can be computed using the eigenvalues of $P$.\n\n\\begin{equation*}\nD_t (x,y) = \\sqrt{ \\sum\\limits_{\\lambda \\geq 1 }{} \\lambda_{l} ( \\phi_l (x) - \\phi_l (y) )^2   }\n\\end{equation*}\n\nWe can define an embedding in Euclidian space via\n\n\\begin{equation*}\n\\Psi_t (x) = \\{ \\lambda_{1}^{t} \\phi_1(x) , ...  \\lambda_{s(\\delta,t)}^{t} \\phi_{s(\\delta,t)} (x) \\}\n\\end{equation*}\n\n\n\n\n\\section*{Spectral Geometry}\nSpectral Geometry concerns itself with the relationships between a geometric structure and the spectra of a differential operator, typically the Laplacian.   Inferring the geometry from the spectra is a type of inverse problem since two non isometric manifolds may share the same spectra.  Going the other way, we encounter isoperimetric inequalities and spectral gap theorems.  \"Can One Hear the Shape of a Drum?\" was the of an article by Mark Kac in the American Mathematical Monthly 1966.   The frequencies at which a drum vibrate depends on its shape. The elliptic PDE  $ \\nabla^2 A + k A = 0$ tells us the frequencies if we know the shape. These frequencies are the eigenvalues of the Laplacian in the region.  Can the spectrum of the Laplacian  tell us the shape if we know the frequencies?  Hermann Weyl showed the eigenvalues of the Laplacian in the compact domain $\\Omega$ are distributed according to $ N(\\lambda) \\sim (2 \\pi)^{-d) \\omega_d \\lambda^{\\frac{d}{2}} vol(\\Omega}$\n\nThe Laplace Beltrami operator is the generalization of $\\nabla \\circ \\nabla = \\Delta$ to $\\mathcal{M}$\n\\begin{equation*}\n\\Delta f = tr(H(f))\n\\end{equation*}\nIn the exterior calculus we have $ \\Delta f = d^*d \\; f$.\n\n//BBCREVISIT - Fill this out and check\nThe Laplacian of a Gaussian has well known applications in image processing.  Given $f(x,y)$, we get a scale space representation when we convolve by\n\\begin{equation*}\n  g(x,y,t) = \\frac{e^{x^2+y^2}}{2 \\pi t}\n\\end{equation*}\n\n\\begin{equation*}\n  L(x,y,t) =g(x,y,t) \\ast f(x,y)\n\\end{equation*}\nApplying $\\Delta$ to $L(x,y,t)$ gives response to blobs of extent $\\sqrt{t}$\n\nThere is a well known connection between diffusion processes and Schrodinger operators;\n\\begin{eqnarray*}\nH = \\nabla^2 + V(x) \\Phi \\in L^2(\\dblr^n) \\\\\nH \\Phi = E \\Phi \\\\\nE = \\sigma(H)\n\\end{eqnarray*}\n\n\n\n\\section*{Concentration of Measure}\n \\cite{MCArora04expanderflows}, \\cite{MCBartlett03convexity}, \\cite{MCBoucheron04concentrationinequalities},\n \\cite{MCFRIEDMAN96computingbetti}, \\cite{MCLedoux04spectralgap}, \\cite{MCMuyan_ablessing},\n \\cite{MCSinclair92improvedbounds}, \\cite{MCTalagrand95concentrationof}.\n\nFamiliar tools used when when dealing with additive functions of independent random variables are the CLT, LLN, and the inequalities of Markov, Chebychev, and Chernoff.  When the differences are not independent we rely on the theory of martingales and use inequalities like Azuma's to provide concentration bounds.\n\nLet $(X,\\Sigma,\\mu)$ be a measure space and let $f$ be an  real-valued measurable function defined on $X$. Then for any number $t > 0 \\in \\mathbb({R}$ we have\n\\begin{equation*}\n\\mu(x \\in X | f(x) \\geq t) < \\frac{1}{t} \\int_X |f(x)| d \\mu\n\\end{equation*} If we let $\\mu$ be a probability measure - $\\mu(X)=1$, then the above is equivalent to $P(|X| \\geq a) \\leq \\frac{E(|X|)}{a}$ commonly known as Markov's inequality.\n\nAnother familiar concentration inequality is the Chebychev inequality has it's origins as a measure theoretic inequality;\n\\begin{equation*}\n\\mu({x \\in X : \\abs{f(x)} \\geq t}) \\geq \\frac{1}{t^2}\nint_X \\abs{f}^2 d\\mu\n\\end{equation*} When $X$ has finite first moment $\\mu$ and non-zero second moment $\\sigma$, we have the more familiar\n\\begin{equation*}\nP( \\abs{X - \\mu} \\geq k \\sigma ) \\leq \\frac{1}{k^2} \\; \\forall k > 0\n\\end{equation*}\n\n\n%These notes generally follow Wiki on Isoperimetry\nThe isoperimetric inequality concerns the relationship between the length $l$ of a closed curve and the area $a$ of the planar region that it encloses.  Specifically, $4 \\pi a \\leq l^2$.  Equality holds in the case that the curve is a circle. The isoperimetric problem is to determine a plane figure of the largest area whose boundary has a given length. F\n\nFederer \\cite{federer1996geometric} is a good reference for a measure theoretic generalization to higher dimensions. We make a few remarks here that will be expanded on later.\n\\begin{prop}[Isoperimetric Inequality In $\\mathbb{R}^n$]\nLet $\\mu$ be Lebesgue measure in $\\mathbb{R}$ and $X \\ in \\mathbb{R} \\st \\mu(cl(X) < \\infty$, then\n\\begin{equation*}\n  n \\omega^{\\frac{1}{n}}_{n} \\mu(cl(X))^{\\frac{n-1}{n}} \\leq M^{n-1}(\\partial X)\n\\end{equation*}\n\\end{prop}\n$M$ is the Minkowski content, which is  the Hausdorff measure of $\\partial X$ for rectifiable $\\partial X$.\nThe proof relies on the Brunn–Minkowski theorem which states that $\\mu(A+B)^{\\frac{1}{n}} \\geq \\mu(A)^{\\frac{1}{n}} + \\mu(A)^{\\frac{1}{n}}$ where set addition in $\\mathbb{R}$ is in the sense of Minkowski.  This addition behaves well with respect to the convex hull; $\\forall A,B \\in \\mathbb{R} \\; co(A + A) = co(A) + co(A)$\n\nFor smooth domains general Isoperimetry inequality is equivalent to a Sobolev inequality on $\\mathbb{R}$.\n\n\\begin{prop}[Sobolev inequality]\nLet $u$ be a continuously differentiable real-valued function on $\\mathbb{R}$ with compact support. Then for $1 \\le p < n$ there is a constant $C$ depending only on $n$ and $p$ such that\n\\begin{equation*}\n  ||u||_{L^{\\frac{pn}{n-p}}} \\leq C || Du||_{L^p}\n\\end{equation*}\n\\end{prop}\n\nThe Sobolev embedding theorem relies on the\n\\begin{thm}[Hardy Littlewood Sobolev fractional integration theorem]\nLet $0 < \\alpha <n$ and $1 < p  < q < \\infty$ and let $I\\alpha = (-\\Delta)\\alpha/2$ be the Riesz potential\n\\begin{equation*}\n  I_\\alpha f(x) = \\frac{1}{C_\\alpha}\\int_{\\mathbb{R}^n} \\frac{f(y)}{|x-y|^{n-\\alpha}} dy\n\\end{equation*}\nThen, for $q=\\frac{pn}{n-\\alpha p}$\nthere exists a constant $C$ depending only on $p$ such that $||I_\\alpha f||_q \\leq C ||f||_p$\n\\end{thm}\nThe Hardy–Littlewood–Sobolev lemma implies the Sobolev embedding by the relationship between the Riesz transforms and the Riesz potentials.  The Riesz potential defines an inverse for a power of the Laplace operator on Euclidean space.\n\n\nThe Chernoff and Hoeffding bounds tell us that the average of $n$ iid  random variables $X_1,X_2, \\hdots ,Xn$ is tightly concentrated around its mean if ${X_i}$ are bounded and $n$ is sufficiently large. hat about $G(X_1,X_2, \\hdots ,X_n)$?\nThe feature of the average which gives rise to tight concentration is that is is Lipschitz. The following concentration bound applies to any Lipschitz function of iid normal random variables. See Ledoux (2001, page 41, 2.35).\n\nHigh dimensional space is mostly empty.  This is more commonly called the \\textit{\"curse of dimensionality\"}.  One way to get around the curse of dimensionality is to find interesting projections.  Many common algorithms such as principal components, multidimensional scaling, and factor analysis fall into this category.  Huber \\cite{HuberProjectionPursuit} placed many of these in to a common framework called projection pursuit.\n\nLogarithmic Sobolev inequalities have a close relationship with the concentration of measure phenomena.  There are two major types of concentration; Gaussian and Exponential. [see Ledoux]\n\nLet $(e^{-At})_{t\\geq 0}= (T_t)_{t\\geq 0}$ be a symmetric Markov\nsemigroup on $ L^2(X,d{\\mu})$ with generator $A$ defined on   a ${\\sigma}$-finite\nmeasure space $(X,d{\\mu})$. $(T_t)_{t\\geq 0}$ is ultracontractive if\nfor any $t>0$, there exists a finite positive number $a(t)$ such\nthat, for all $f\\in L^1$ :\n\\begin{equation*}\\label{ult1}\n\\|T_tf\\|_{\\infty}  \\leq a(t) \\|f\\|_1.\n\\end{equation*}\n\nAn equivalent formulation (by interpolation) of ultracontractivity is\nthat for any $t>0$, there exists a finite positive number  $c(t)$ such\nthat,  $\\forall f\\in L^2$,\n\\begin{equation*}\\label{ult2}\n\\|T_tf\\|_{\\infty} \\leq c(t) \\|f\\|_2\n\\end{equation*}\n Also by duality, the inequality (\\ref{ult2}) is equivalent to\n\\begin{equation*}\\label{ult3}\n\\|T_tf\\|_{2} \\leq c(t) \\|f\\|_1\n\\end{equation*}\nIt is known that, under the assumptions on the semigroup\n$(T_t)_{t\\geq 0}$, (\\ref{ult2}) implies (\\ref{ult1})\nwith $a(t)\\leq c^2(t/2)$\nand\n(\\ref{ult1}) implies (\\ref{ult2})  with $c(t) \\leq \\sqrt{a(t)}$.\n\\\\\n\nWe say that the generator $A$ satisfies  LSIWP  (logarithmic Sobolev inequality\nwith parameter) if  there exist a monotonically decreasing continuous function\n${\\beta}: (0,+\\infty)\\rightarrow (0,+\\infty)$ such that\n\\begin{equation*}\\label{lsiwp}\n\\int f^2\\log f\\, d{\\mu} \\leq\n\\epsilon Q(f) +{\\beta}(\\epsilon) \\|f\\|^2_2 + \\|f\\|^2_2\\log \\|f\\|_2\n\\end{equation*}\nfor all $\\epsilon >0$ and $0\\leq f\\in \\mbox{Quad}(A)\\cap L^1\\cap\nL^{\\infty}$ where\n$\\mbox{Quad}(A)$ is the domain of $\\sqrt{A}$ in $L^2$ and\n$Q(f)=(\\sqrt{A}f,\\sqrt{A}f)$.\n\\\\\n\nThis inequality is modeled on the Gross inequality \\cite{}.\n\\\\\n\nIn \\cite{ds},\\cite{d}, the authors show that LSIWP implies\nultracontractivity property  under an integrability condition on $\\beta$. This condition can be enlarged and be stated as follows:\n\n\\begin{thm}\nLet ${\\beta}(\\epsilon)$ be a monotonically decreasing continuous\nfunction of $\\epsilon$\nsuch that\n\\begin{equation*}\\label{vareps}\n\\int f^2\\log f \\, d{\\mu}\\leq\n\\epsilon Q(f) +{\\beta}(\\epsilon)\\, \\|f\\|^2_2 + \\|f\\|^2_2\\log \\|f\\|_2\n\\end{equation*}\nfor all $\\epsilon >0$ and $0\\leq f\\in \\mbox{Quad}(A)\\cap L^1\\cap\nL^{\\infty}$. Suppose that\nfor one ${\\eta}>-1$,\n\\begin{equation*}\\label{integral}\nM_{\\eta}(t)=({\\eta}+1)t^{-({\\eta}+1)})\\int_0^t\n{s}^{\\eta}{\\beta}\\left(\\frac{s}{\\eta+1}\\right)\n\\,ds\n \\end{equation*}\nis finite for  all $t>0$. Then $e^{-At}$ is ultracontractive\nand\n\\begin{equation*}\\label{majo}\n\\| e^{-At} \\|_{\\infty,2}\\leq e^{M_{\\eta}(t)}\n\\end{equation*}\nfor all $0<t<\\infty$.\n\\end{thm}\n\n\n\\section*{The Condition Number of a Markov Chain}\n\\section*{Generalized Chebyshev Bounds on Quadratic Sets via Semidefinite Programming}\nBoyd et al  \\citet{SDPVandenberghe_generalizedchebyshev} provide a simplified development of an algorithm to compute the lower bound on the probability of a set which is defined by quadratic inequalities. That algorithm is discussed here.\n\n\\begin{equation*}\n\\min (1-  \\sum\\limits_{i=1}^{m} \\lambda_i)  \\ni Tr( A_i z_i) + 2 b_{i}^{T} z_i + c_i \\lambda_i \\geqslant 0 \\;\\;\\; \\forall i=1, ... , m\n\\end{equation*}\n\n\\begin{equation*}  \\sum\\limits_{i=1}^{m}  [\n\\begin{array}{cc}\nz_i & z_i \\\\\nz_i & \\lambda_i \\\\\n\\end{array} ] \\succeq 0 \\end{equation*}\n\n\\begin{equation*}  C = \\{ x \\in \\dblr :  x^T A_i x + 2 b_{i}^{T} +c_i <0 : i=1, ...,m \\} \\end{equation*}\n\n\\begin{equation*}\n\\min E[f_0(X)] \\ni E[f_i(X)] = a_i : i=1, ...,m\n\\end{equation*}\n moment constraints\n\nLet\n\\begin{equation*}\n \\bar{x} \\in \\dblr^n S \\subset S^n \\ni S \\succeq \\bar{x} \\bar{x}^T\n\\end{equation*}\n  and define\n \\begin{equation*}\n P(C,\\bar{x},S) = inf_{\\mathcal{P}(\\dblr^n)} \\{P(X \\in C) \\mid E[X] = \\bar{x} E[X X^T] = S \\}\n \\end{equation*}\n\nThe optimization problem is to find $ P \\in \\mathcal{P}(\\dblr^n) $ - a probability density function which maximizes the probability of the convex set C and satisfies the moment constraints.\n\n\n\n\\section*{Bregman Divergences}\nNNMA is the approximation of a non-negative matrix $A$ by a low rank matrix $BC$ where $B\\succ 0$ and $C\\succ 0$.  Bregman divergences are a robust distortion measure for this matrix factorization.  Formally $D_\\phi(A,BC)=\\phi(A)-\\phi(BC) - \\nabla\\phi(BC) (A-BC)$ measures the quality of the factorization relative relative to a convex penalty function.\n\nModeling of relational data can be abstracted out to the factorization in a low dimensional representation of a data matrix $(X_ij)$ where links [or relations] are represented as an $n x m$ matrix $X$ where $X_{i,j}$ indicates whether a relation exists between entities of type $i, j$.  Let $f$ be a link function and $X^{~}$ be a factorization of $X$ into a low rank approximation $X \\approx U V^T : U \\in R^{m x k}, v \\in R^{m x k}$.  The link function $f$ can be interpreted as in $GLM$ which gives extends exponential models to matrices.  A simple example is choosing the identity link which and minimizing in the $\\ell^2$ norm gives rise to the SDV and the Gaussian model for the data ${X_ij}$.  Similarly we can  extend to Bernoulli, Poisson, Gamma, error distributions.\n\nMany forms of matrix factorization can be cast as an optimization problem that involves minimization of generalized Bregman divergences \\cite{BDAUnifiedViewMatrixFactorizationModels}.  Factorization algorithms such as  NNMF, Weighted SVD, E xponential Family PCA, , pLSI, Bregman co-clustering \\cite{CCBanerjee04ageneralized} can be cast in this framework. The approach uses an alternating projection algorithm for solving the optimization problem which allows for generalizations that include row, column, or relaxed cluster  constraints.  A brief description of the algorithm is given below.  The description of a generalized Bregman divergence can be found in \\cite{BDGordon99approximatesolutions}.\n\nLet $\\phi S \\in \\dblr^n \\to \\dblr$, $D_\\phi (x,y) = \\phi(x) - \\phi(y) - < x-y, \\nabla \\phi(y) >$ be the Bregman divergence. Let $\\chi = {X_i} \\in S \\in dblr^d$ be a random variable and take the encoding $X_i \\to S$ so the rate is zero and the code book is 1. The rate distortion is $E_\\nu [D_\\phi (\\chi,s)] = min \\s in S \\sum\\limits_{i=1}^{n} \\nu_i D_\\phi (x_i,x)$ which we call the Bregman information for the random variable $X$.\n\\begin{thm}\n$\\mu = E_\\nu [X]$ is the unique minimizer\n\\end{thm}\n\n\n\\section*{Sparse Representation}\nA Gaussian distribution is often an accurate density model for low dimensional data, but very rarely for high-dimensional data. High dimensional data is less likely to be Gaussian, because of the high degree of independence this demands.  Recall the a Gaussian is a rotation of a distribution with completely independent coordinates. In a typical high dimensional application, one may be able to find a few features that are approximately independent, but generally as more features are added the dependencies between them will grow.\n\nDiaconis and Freedman showed that for \\textit{most} high dimensional point clouds, \\textit{most} low dimensional orthogonal projections are a mixture of normal spherically symmetric distributions.\n\n\\begin{lem}[Poincare Lemma]\nIf $\\sigma_n$ is uniform on $\\sqrt{n}S_{n-1} \\in \\dblr^n$,  $d<n$ and\n\\begin{equation*}\n\\Pi_{d,n} ( x_1, \\hdots , x_n) \\rightarrow ( x_1, \\hdots , x_n)\n\\end{equation*}\nis the canonical projection, then for fixed $d$, as $ n \\rightarrow \\infty $, we have that\n$\\Pi_{d,n}$ converges weakly towards a centered reduced Gaussian distribution on $\\dblr^d$\n\\end{lem}\n\nProof [See pp55 Some Aspects of Brownian Motion : Some Recent Martingale Problems].\nUee LLN.  If $(X_1,X_2, \\hdots ,X_n)$ iid $N(0,1)$, then\n\\begin{equation*}\n\\frac{1}{n} \\rho_{n}^{2} =: \\frac{1}{n} \\sum_{i=0}^{n} x_{i}^{2} \\rightarrow 1  \\rightarrow \\infty\n\\end{equation*}\nIf we define $\\tilde{X}_{(n)} = (X_1,X_2, \\hdots ,X_n) = \\frac{1}{\\sqrt{n}} \\rho_n \\theta_n$ where $\\theta_n \\sim \\sigma_n$ a uniform distribution on $\\sqrt{n}S_{n-1}$.  Then the lemma follows from the equation $\\tilde{X}_{(n)} = \\frac{1}{\\sqrt{n}} \\rho_n  \\Pi_{d,n} (\\theta_n)$.\n\n\nSparse PCA\n[CS Notes from http://ugcs.caltech.edu/~srbecker/\n\nClassic PCA is sensitive to outliers.  Convex methods can be use to address this by attempting to factor the data $X$ as a sum of a low rank component $L$ and a sparse component $S$ by solving\n\\begin{equation*}\n\\underset{min}{S,L} \\norm{L}_* + \\lambda \\norm{S}_{\\ell_1}  : X=L+S\n\\end{equation*}\nSee http://cvxr.com/tfocs/demos/rpca/ for a demo of this in action with the popular cvx software package.\n\n\n\n\\section*{Compressed Sensing}\n\n\n\\section*{Bound on Limiting Probabilities for a Perturbation of a Markov Chain}\nIn \\cite{meyer1980condition} bounds are established on the relative error for the limiting probabilities for a perturbation of a finite Markov chain.  This improves on the traditional eigenvector perturbation approach by exploiting the constraints of the problem.  We collect some of these results in this section and see if they can be applied to analyse the stability of spectral clustering algorithms.\n\nLet $T$ be the transition matrix of a finite Markov chain $\\mathcal{C}$. $A=I-T$, and $\\mathcal{C}$ be a perturbation to $\\mathcal{C}$ where $\\tilde{T} =T-E$ is the transition matrix of  $\\mathcal{C}$. Let $\\omega$ be the limiting probability, $\\omega = \\lim_{n \\to \\infty} T^n x$. Define $A=I-T$ and $A^\\sharp$ the generalized inverse of $A$. Then $W=\\lim_{n  \\infty} \\frac{I+T+T^2 + \\ldots + T^{n-1}}{n} = I-A A^\\sharp$ is the limiting matrix of $\\mathcal{C}$.  Every row of $W$ is $\\omega$\n\nWe state a few relations without proof from Meyers paper\n\\begin{equation*}\n(A+E^\\sharp)=A - A^\\sharp E A^\\sharp (I+ E A^\\sharp)^{-1} - W(I+E A^\\sharp)^{-1} A^\\sharp (I+E A^\\sharp)^{-1}\n\\end{equation*}\n\nThis combined with the expression for $\\tilde{W}$ yields\n\\begin{equation*}\n\\tilde{W} = W(I+E A^\\sharp)^{-1} = W - W E A^\\sharp (I + E A^\\sharp)^{-1}\n\\end{equation*}\n\nThe above gives a condition for the limiting matrix to be invariant under a perturbation;  $W=\\tilde{W} \\iff range(E) \\in range(A)$.  It also allows us to write $\\omega - \\tilde{\\omega} = \\omega E A^\\sharp (I+ E A^\\sharp)^{-1}$, so\n\n\\begin{equation*}\n\\norm{\\omega - \\tilde{\\omega}} \\leq \\norm{E A^\\sharp} \\norm{ (I+E A^\\sharp)^{-1}}\n\\end{equation*}\n\nand when $\\norm{E A^\\sharp} \\leq 1$ we can use the familiar Taylor expansion\n\\begin{equation*}\n\\norm{(I+E A^\\sharp)^{-1}} \\leq \\frac{1}{ 1 - \\norm{E A^\\sharp } }\n\\end{equation*}\n\nto obtain an expression for the relative error in $\\omega$ for a given relative error in $A$\n\n\\begin{equation*}\n\\frac{\\norm{\\omega - \\tilde{\\omega}}}{\\norm{\\omega}} = \\frac{ \\frac{\\norm{E}}{\\norm{A}} \\kappa(\\mathcal{C}) } {1 - \\frac{\\norm{E}}{\\norm{A}} \\kappa(\\mathcal{C}) }\n\\end{equation*}\n\n\n\n\\section*{Ultracontractivity}\n\n\n\\section*{Generalized Uncertainty Principles}\nThe sparse recovery problem can be stated as follows.  Given an unknown signal $f \\ in \\dblc^n$, when can we recover $f$ from a set of $k$ linear measurements $\\Phi f \\ in \\dblc^k \\; k<n$? This problem is underdetermined and we are interested in the sparsest solution.\n\\begin{equation*}\nmin \\norm{f*}_0 : \\Phi f* = \\Phi f\n\\end{equation*}\nThis problem is not convex, and in fact is generally NP-Hard \\cite{Donoho04formost} and \\cite{natarajan1995sparse}.  Note that the norm here is not the usual $\\ell_0$ norm, here we abuse notation $\\norm{g}_0$ to mean $card{g_i ! = 0}$, the size of the support. This problem can be relaxed to a convex problem by using the $\\ell_1$ norm.\n\\begin{equation*}\nmin \\norm{f*}_1 : \\Phi f* = \\Phi f\n\\end{equation*}\nThis problem is not differentiable at points where $f*_i=0$ and will require a general convex solver.  Usually the problem is solved in practice by recasting the minimization as a linear program\n\\begin{equation*}\nmin <f*,f> : \\Phi f* = f \\;  f* \\succeq 0\n\\end{equation*}\nbbcrevisit\n\nMuch work has been done to determine when these two problems have the same solution, i.e. when is exact recovery possible. One  sufficient condition for exact recovery is the RIP condition of Candes and Tao (see below).\n\n\\begin{defn}[RIP (Candes \\& Tao) ]\nLet $A \\in M_{m \\times n}(\\dblr)$ and $p \\in [1,n]$, then we say that $A$ has the restricted isometry property if\n\\begin{eqnarray*}\n  \\exists \\delta_p \\st \\forall m,p A_s \\in A \\\\\n  (1 - \\delta_p) \\norm{y}_{\\ell^2}^2 \\leq   \\norm{A_s y}_{\\ell^2}^2 \\leq (1 + \\delta_p) \\norm{y}_{\\ell^2}^2 \\leq\n\\end{eqnarray*}\n\\end{defn}\nRIP is a property which classifies a matrix as being close to orthogonal.  $\\delta_p$ is referred to as the RIC, and is NP-Hard to compute.  Compressed sensing decoders are guaranteed to recover the sparsest solution to $Y = A x$ when $A$ is close to an isometry. Bounds on the RIC are available for some classes of random matrix ensembles.\n\n\n\\section*{Random Matrix Theory \\& OP}\n\nRMT concerns itself with the eigenvalue statistics of large matrices with random entries. We define the eigenvalue counting measure of a matrix $H$n as;\n\\begin{equation*}\n\\mu_H (A) = \\frac{| \\lambda_i \\in A |}{n} = N_{1_A, H}\n\\end{equation*}\n\nMore generally a eigenvalue statistic $N_{f,H}  = \\frac{tr f(H)}{n}$\nFor many types of random matrices we have a CLT;\n\\begin{equation*}\n\\frac{N_{f,H}-\\int f(\\lambda) dN(\\lambda)}{\\sigma_{f,n}} \\rightarrow_d N(0,1)\n\\end{equation*}\n\n$GUE(n)$ Start with Gaussian measure\n\\begin{equation*}\n\\gamma^n(A) - \\frac{1}{(\\sqrt{2 \\pi} )^n} \\int_A e^ \\frac{-1}{2} \\norm{X}^2 d \\lambda^n\n\\end{equation*}\n\nWeiener space is the Hilbert space $L^{2,0}[0,1]$ of upon which a Gaussian measure can be defined. The inner product on Weiner space is\n\\begin{equation*}\n<\\sigma_i,\\sigma_j> = \\int\\limits_{0}^{1} <\\overset{\\cdot}{\\sigma_i},\\overset{\\cdot}{\\sigma_j}> dt\n\\end{equation*}\nwhere $\\overset{\\cdot}{\\sigma_i} = \\frac{d \\sigma)i}{dt}$\nThe Wiener measure is a Gaussian measure.\n\nLet $H$ be Hermitian, $Z_{GUE(n)} = 2^{\\frac{n}{2}} \\pi^{\\frac{n^2}{2}}$ We can write\n\\begin{equation*}\n   \\gamma^n(A) - \\frac{1}{Z_{GUE(n)} } \\int_A e^ \\frac{-1}{2} tr(H^2) d \\mu\n\\end{equation*}\n\n\nThere are two domains of eigenvalue statistics, local and bulk. Locally we are concerned with level spacing ,$\\Delta \\lambda = \\lambda_i - \\lambda_{i-1}$, and edge statistics $P_{TW}(\\lambda_1), \\underset{n \\rightarrow \\infty}{lim} P_{TW}(\\lambda_n)$.  The Tracy Widom law $P_{TW}$ gives edge statistics.\n\nThe empirical spectral measure of $H$ is\n\\begin{equation*} \\mu_H = \\frac{|eigs H \\in A |}{n} \\end{equation*}\n\nThe CDF of $H(n)$ is $N_n (\\lambda)$ and as $n \\rightarrow \\infty$ is $N_n (\\lambda) \\rightarrow W(\\lambda)$ where $W$ is the Winger Semi-Circle Law.\n\nBulk statistics look at the determinantal point process $E(\\lambda_0) = \\sum_j \\delta ( n \\rho(\\lambda_0 (\\lambda_j - \\lambda_0)$.  The kernel of the process is the sine kernel $K(x,y) = \\frac{sin (\\pi (x-y) )}{\\pi (x-y)}$.  $E(\\lambda)$ captures the statistics of the eigenvalues in the vicinity of $\\lambda_0$. Recall the joint densities of a determinantal point process with kernel $K$ are given by $\\rho_n(x_1, ...,x_n) = det(K(x_i,x_j)_{1 \\leq i, j \\leq j})$\n\n\n\\section*{The Hamburger Moment Problem - HMP}\n\nGiven a sequence  ${m_i}$ the HMP seeks to find a measure that generates the moments.\n\\begin{equation*}\n  \\exists \\mu : m_n = \\int\\limits^{+ \\infty}_{- \\infty} x^n d\\mu\n\\end{equation*}\n\nThe answer is affirmative when the Hankel kernel $A \\succ0 $, which\nis equivalent to $\\sigma(A) \\in \\mathbb{R}^{+}$\n\\begin{equation*}\nA =\\left(\n  \\begin{array}{cccc}\n    m_0 & m_1 & \\ldots &   \\\\\n    m_1 & m_2 & m_3 &   \\\\\n    m_2 & m_3 & m_4 &   \\\\\n    \\vdots &   &  & \\ddots \\\\\n  \\end{array}\n\\right)\n\\end{equation*}\n\nRecall that A Hankel matrix is a square matrix with constant skew-diagonals; $A_{i,j} = A{i-1,j+1}$\nA Hankel matrix is an upside-down Toeplitz matrix.\n\nThe Hilbert matrix $ H{i,j} = \\frac{1}{i+j-1}$ is a special case of a Hankel matrix. The Hilbert matrices are canonical examples of ill-conditioned matrices.\nThey arise in the expression for the Grammian matrix of powers of $x$; $H_{ij} = \\int\\limits{0}{1} x^{i+j-2} dx$\nwhich shows up in the least squares approximation by polynomials.\n\nThe solutions to the HMP are either unique or infinite in number and form a convex set in $\\mathcal{H}$\n\nLet\n\\begin{equation*}\n\\Delta_n =\\left(\n  \\begin{array}{cccc}\n    m_0 & m_1 & \\ldots & m_n  \\\\\n    m_1 & m_2 & \\ldots & m_{n-1}  \\\\\n     &  & \\ddots &   \\\\\n    m_n & m_{n+1}  &  & m_{2n}\\\\\n  \\end{array}\n\\right)\n\\end{equation*}, then $A \\succ0 \\Rightarrow det(\\Delta_n) \\geq 0 \\forall n$\nIf $det(\\Delta_n)=0$ then $(\\mathcal(H), <,>)$ is finite dimensional and $T$ is self adjoint.\n\n$A$ gives us a sesquilinear form on $\\mathcal(H) = \\mathcal(l)^2$ via\n$<x,y> = \\hbar{x}^T A y$.\n\nLet $T$ be a shift operator. The HMP is closely related to OP in $\\mathbb{R}$.\nGram Schmidt gives basis ${\\phi_i}$ in which $T$ has tridiagonal Jacobi.\n\nThe Caley transform $Q(T) = (I-T)(I+T)^{-1}$ shows the connection to the Nevanlina class\nof functions (sub-harmonic).\n\n\n\n\\section*{Random Matrix Ensembles}\n\\cite{RMTAchlioptas04randommatrices}, \\cite{RMTAlon00bipartitesubgraphs}, \\cite{RMTAlon00onthe} ,\n\\cite{RMTCooper00onthe}, \\cite{RMTSoshnikov02anote}, \\cite{RMTTracy98correlationfunctions}\n\nThe classical ensembles of random matrix theory are GOE, GUE, GSE, Wishart, and MANOVA. These correspond to the weight functions of the equilibrium measure of the orthogonal polynomials Hermite, Laguerre,and Jacobi.  The Jacobians of the well known matrix factorizations are used to compute the joint eigenvalue densities of these ensembles. The distribution of eigenvalues of the GOE ensemble follow the well know Winger Semi-circle distribution.\nThe joint densities up to a constant factor are listed below:\n\\begin{itemize}\n  \\item Hermite  \\item Laguerre   \\item Jacobi\n\\end{itemize}\nWe generated histograms in Matlab for samples from the GOE, GUE, GSE, Wishart, and MANOVA ensembles.\nThe joint PDF of a generic Gaussian ramdom matrix is given by,\n\\begin{equation*}\nP(M)=G_\\beta(n,m)=\\frac{1}{2 \\pi^{\\frac{\\beta n m}{2} }} \\exp^{\\frac{-1}{2}\\norm{M}_F }\n\\end{equation*} where $\\beta$ encodes the dimension of the field.  Note this leaves open the possibility to\ngeneralize to non integer $\\beta$.\n\nThe table below describes how to generate from the common ensembles starting from a sample $A \\in G_\\beta(n,n)$\n\\begin{eqnarray*}\n    GOE  \\{ M | M = \\frac{A+A^T}{2}, A \\in G_1(n,n)\\}\\\\ %[bbcrevisit is necessaria and sufficient?]\\\\\n    GUE  \\{ M | M = \\frac{A+A^\\dagger}{2}, A \\in G_2(n,n)\\}\\\\ %[bbcrevisit is necessaria and sufficient?]\\\\\n    GSE  \\{ M | M = \\frac{A+A^\\ddagger}{2}, A \\in G_4(n,n)\\} %[bbcrevisit is necessaria and sufficient?]\n\\end{eqnarray*}\n\n\nThe $CS$ decomposition is a matrix factorization equivalent to four $SVD$'s which correspond to rotation problems\n$\\left(\\begin{array}{cc}\n        X \\rightarrow  Y & X^\\perp \\rightarrow  Y \\\\\n        X \\rightarrow  Y^\\perp & X^\\perp \\rightarrow  Y^\\perp \\\\\n\\end{array}\\right)$\nWhich can be compactly written\n$[X | X^\\perp]^T [Y | Y^\\perp ]=\\left(\n      \\begin{array}{cc}\n        Q_{11} & Q_{12} \\\\\n        Q_{21} & Q_{22} \\\\\n      \\end{array}\n\\right)$\n $\\left(\n      \\begin{array}{cc}\n        Q_{11} & Q_{12} \\\\\n        Q_{21} & Q_{22} \\\\\n      \\end{array}\n\\right)    = \\left(\n      \\begin{array}{cc}\n        U_1 & 0 \\\\\n        0 & U_2\n      \\end{array}\n\\right) * \\left(\n      \\begin{array}{cc}\n        C & S \\\\\n        -S & C\n      \\end{array}\n\\right) * \\left(\n      \\begin{array}{cc}\n        V_1 & 0 \\\\\n        0 & V_2\n      \\end{array}\n\\right)\n$\nWhere U, S are unary.\n\nThe Tracy-Widom law of order one is the limiting distribution of the largest eigenvalue of a Wishart matrix with identity covariance when properly scaled.  This has some application to weighted directional graphs.  The largest eigenvalue of the adjacency matrix of a random d-regular directed graph follows the Tracy-Widom law.  The kernels of integrable operators describe the asymptotic eigenvalue distribution of self-adjoint random matrices from the unitary ensembles. Consider the discreet operator $K(n,m):  \\l^2(N) \\rightarrow \\l^2(M)$ where $K(n,m) = \\frac{(<J a(m),a(n)>}{m-n}$ the discrete Bessel kernel and kernels arising from the almost Mathieu equation.  The celebrated paper of Tracy and Widom \\cite{RMTTracy98correlationfunctions} investigated integral kernels of the form\n\\begin{equation*}\nK(x,y)=\\frac{f(x)g(y)-f(y)g(x)}{x-y} : x \\neq y  f(x), g(x) \\in L^2(0,\\infty)\n\\end{equation*}\n are solutions to the system of $ODE$'s\n\n\\begin{equation*}\n\\frac{d}{dx}\\left( \\begin{array}{c}\n        f(x) \\\\\n        g(x)\n      \\end{array}\n\\right) = \\left(\n      \\begin{array}{cc}\n        \\alpha(x) & \\beta(x) \\\\\n        -\\gamma(x) & -\\alpha(x)\n      \\end{array}\n\\right) * \\left( \\begin{array}{c}\n        f(x) \\\\\n        g(x)\n      \\end{array} \\right)\n\\end{equation*}\n\nLet $\\phi_i(x)$ be an orthogonal basis in a Hilbert Space $\\mathcal{H}$ where\n\\begin{equation*}\n\\Gamma_{\\phi}\n= \\{\\phi_(j+k-1)\\}_{j,k=1}^{\\infty}\n\\end{equation*}\nis the induced Hankel Matrix.\n\n\nLet $\\mathcal(L) : \\mathcal{H} \\rightarrow \\mathcal{H}$ be compact.  Then $\\mathcal(L): f \\mapsto \\sum\\limits_{n=1}^{N} \\omega_n <\\phi_n, f> \\psi_n$ where $\\{\\phi_i\\}_{i=1}^{N}$\n\n\n\\section*{The Tracy Widom Law}\nThe Tracy-Widom distribution is related to to determinantal stochastic processes.  A process following this law is distributed as the largest point of a point process on the real line where the kernel K is the so-called Airy kernel.  In addition to describing the edge spectrum of random matrices, it arises in several place in combinatorial for instance the longest increasing subsequences of random permutations is described by the Tracy Widom law.  In addition to the eigenvalues of random matrices, this type of point process is used in models such as  fluctuations in first and last passage percolation, and the asymmetric exclusion process.\n\nThe path configuration of random viscous walkers is related to the Young tableaux.  Statistical problems related to the Young tableaux include random growth, point processes, random permutation, and the random word problem. the asymptotic distribution of scaled variables from these models are  described by the Tracy Widom distribution which is the limit distribution for the largest eigenvalue of $X \\in GUE$.\n\n\n\\section*{Nystr\\\"{o}m Method}\nThe Nystrom method is a technique to speed up large-scale learning applications by generating low-rank approximations to large matrices. The origins of the Nystrom method lie in the numerical solution of the integral eigenvalue problem\n\\begin{equation*}\n  \\int p(y) k(x,y) \\phi(y) = \\lambda \\phi(y)\n\\end{equation*}\n(BBCREVISIT talk about the functional analysis and physics origin of this method for solving integral problems)\n\nProblems in computer vision, natural language processing, computational biology and other areas can involve data sets containing more training examples than can be held in memory. Low rank approximations to the kernel matrices found in kernel based machine learning algorithms such as spectral clustering, manifold learning,support vector machines offer the opportunity to train on large data sets. The performance of this technique relies on the ability of a matrix to be approximated by a subset of its columns.  Coherence bounds from the field of compressed sensing and matrix completion can be used to bound the error of the Nystrom approximation. \\cite{Talwalkar_matrixcoherence}\n\nThe Nystrom method can be evaluated by comparing the approximation to a low rank approximation generated from the first $n$ singular vectors from the $SVD$.  If the process generating the data is $N(\\mu,\\Sigma)$ random sampling can be used and exact error bounds can be calculated based on the number of columns sampled.  (BBCREVISIT confirm and cite).\n\nChoosing the columns based on the underlying probability density $p(y)$ has the potential to improve the quality of the approximation \\cite{Zhang09density-weightednystrom}.\n\n\\section*{Statistical Leverage}\nMichael Mahoney - videolectures.net Statistical Leverage Given an m x n matrix A and a rank parameter k, define the leverage of the i-th row of A to be the i-th diagonal element of the projection matrix onto the span of the top k left singular vectors of A. In this case, \"high leverage\" rows have a disproportionately large amount of the \"mass\" in the top singular vectors. Historically, this statistical concept (and generalizations of it) has found extensive applications in diagnostic regression analysis. Recently, this concept has also been central in the development of improved randomized algorithms for several fundamental matrix problems that have broad applications in machine learning and data analysis. Two examples of the use of statistical leverage for improved worst-case analysis of matrix algorithms will be described. The first problem is the least squares approximation problem, in which there are n constraints and d variables. Classical algorithms, dating back to Gauss and Legendre, use O(nd2) time. We describe a randomized algorithm that uses only O(n d log d) time to compute a relative-error, i.e., 1+/-epsilon, approximation. The second problem is the problem of selecting a \"good\" set of exactly k columns from an m x n matrix, and the algorithm of Gu and Eisenstat provides the best previously existing result. We describe a two-stage algorithm that improves on their result. Recent applications of statistical leverage ideas in modern large-scale machine learning and data analysis will also be briefly described. This concept has proven to be particularly fruitful in large data applications where modeling decisions regarding what computations to perform are made for computational reasons, as opposed to having any realistic hope that the statistical assumptions implicit in those computations are satisfied by the data.\n\n\\section*{How are differential operators related to semi group}\nSobolev inequalities relate norms of Sobolev spaces and can be used to prove embedding of $W^{k,p}(\\Real^n) \\in W^{l,q}(\\Real^n)$ Logarithmic Sobolev inequalities.  The Rellich–Kondrachov theorem makes this precise for the $L^p$ spaces.\n$A$ is an operator on a $L^p$ Banach space. We define this in an operator sense as the sum given by the Taylor expansion of $e^x = \\sum \\frac{x^n}{n!}$\n\\begin{equation*}\n  e^{-t A} : L^p \\rightarrow L^q\n\\end{equation*} is contractive if this holds for $p=2$ and $q=4$.\n$e^{-t A}$ is a positive preserving contractive semi-group if\n\\begin{eqnarray*}\n  e^{-t A} f &\\geq& 0 \\\\\n  \\parallel e^{-t A} f \\parallel_p &\\leq& \\parallel f \\parallel_p\n\\end{eqnarray*}\nWhen $e^{-t A}$ maps $L^2$ to $L^\\infty$ we call the semi group untracontractive.\n\nCovering number\n\nUnion bound\n\nKashin representation\n\nCandes and Tao extend Uncertainty Principle to discrete domain\nFor $x \\in \\Complex^n$\n\\begin{equation*}\n  |supp(x)| |supp(\\hat{x}) \\geq N\n\\end{equation*}\nUniform uncertainty principle is related to the restricted isometry property.\n\nThe $\\Lambda$ problem of Talingrad relates Fourier matrix to HUP question.  Consider matrices which are euclidian projection of cube $Q^N = {x : \\parallel x \\parallel_\\infty  \\leq 1}$, a problem form geometric functional analysis.  Let $B^n = {x : \\parallel x \\parallel_2  \\leq 1}$\n\nKashin; $\\exists$ orthogonal projection $P$\n\\begin{equation*}\n  P : Q^N \\rightarrow U \\in \\Complex^N \\st U \\approx B^n\n\\end{equation*}\nThis implies\n\\begin{equation*}\n  \\exists A \\in M^{n,N} \\st B^n \\in \\frac{K}{\\sqrt{N}} A Q^N \\in K B^n where K = K(\\lambda) \\lambda=\\frac{N}{n}\n\\end{equation*}\n$\\lambda$ is the redundancy.  This statement is essentially telling us that we can project the cube into the ball when N and n allow for it.\n\n\\section*{Learning with integral operators}\nMachine learning methods such as Principal Components Analysis (PCA), Laplacian-based spectral clustering, and manifold methods rely on estimating eigenvalues and eigenvectors of the underlying data-dependent matrices.  These matrices can be interpreted as empirical versions of underlying integral operators or closely related objects, such as continuous Laplacian operators.  Establishing a connection between the finite dimensional empirical operator represented by the data matrix and the continuous counterpart can yield insight, help with convergence theorems, and even provide the basis for new machine learning methods.\n\nTheoretical analysis of many problems, such as low-rank matrix recovery, covariance estimation and approximate matrix multiplication, is built upon exponential bounds for $P(\\| \\sum X_i \\| > t)$ where ${X_i}$ is a finite sequence of self-adjoint random matrices and k · k is the operator norm. Moment-generating function techniques can be used to produce generalizations of Chernoff, Bernstein and Friedman inequalities to the non-commutative case.\n\nConcentration inequalities extend classical exponential inequalities for sums of independent random variables to functions of independent random variables.  In machine learning theory we are interested in functions such as the supremum of the deviations between the true risk and the empirical risk, the empirical VC-dimension, the empirical VC entropy, and the eigenvalues of the Gram matrix.\n$E[ \\hat{\\theta} - \\theta_0 ]$ ", "meta": {"hexsha": "bde325f59377bf0c7a677a48bb3ae373de8f3c92", "size": 60462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BookContent.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": "BookContent.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": "BookContent.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": 73.4653705954, "max_line_length": 1854, "alphanum_fraction": 0.7376699415, "num_tokens": 17273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6280239467644492}}
{"text": "\n\n\n\\index{Lucas Critique}%\n\\section{The Lucas Critique}\\label{sec:lucascritique}%\n We can use our chapter \\use{timeseries} tools concisely to describe reasoning that led Robert E. Lucas, Jr., (1976) to criticize a class of  procedures that were widely used in applied work at the\n time that he wrote, and that occasionally still are.\nAssume a jointly stationary Gaussian stochastic process for $\\{x_t, y_t, d_t\\}_{t=0}^\\infty$ generated by   a state-space system\n$$ \\EQNalign{ x_{t+1} & = A x_t + C w_{t+1}  \\EQN lucas101;a \\cr\n             y_t & = G x_t \\EQN lucas101;b \\cr\n             d_t & = S x_t \\EQN lucas101;c \\cr\n             S & = H G (I - \\delta A)^{-1}  \\EQN lucas101;d \\cr} $$\nwhere $\\delta \\in (0,1)$ is a discount factor and $A$ is a stable matrix\n  that in applications itself often depends on deeper parameters,\n   and   $x_0 \\sim {\\cal N}(\\mu, \\Sigma) $, where $\\mu, \\Sigma$ are the mean vector and covariance matrix, respectively, of a stationary distribution for the\n   $\\{x_t\\}_{t=0}^\\infty$ process.  As usual, $w_{t+1}$ is the time $t+1$ component of   an i.i.d.~sequence of ${\\cal N}(0,I)$ random vectors.\n   Here $d_t$ is a vector of decisions that  an econometrician observes. Equations \\Ep{lucas101;c} and \\Ep{lucas101;d} assert that $d_t$ equals a  fixed matrix $H$ times a   vector of\nforecasts of       discounted sums of current and future $y_t$ vectors, forecasts that equal  appropriate conditional expectations\n   (please see equation \\Ep{discount1}). To fix ideas with an example, take a univariate autoregression for $\\{y_t\\}$, namely,\n$$ y_{t+1} = \\alpha + \\rho_1 y_t + \\rho_2 y_{t-2} + \\sigma w_{t+1}  \\EQN lucas102 $$\n that we can represent with equation \\Ep{lucas101;a}-\\Ep{lucas101;b}.  We can  think of\n$d_t$ as a time $t$ {\\it decision\\/}  and $d_t = S x_t$ as a {\\it decision rule\\/} that tells how an  economic agent or a collection  of economic agents sets\n$d_t$ as a function of time $t$ information $x_t$ about future $y_{t+j}$'s, in particular, so that\n$d_t = H E_t \\sum_{j=0}^\\infty \\delta^j y_{t+j}$ where $E_t$ denotes a mathematical expectation conditional on time $t$ information.\nLucas (1976) offered three examples that can be  fit into this framework. In those examples the decisions $d_t$ were\n choices either  of a consumption rate or  an   investment rate \nor a labor supply (i.e., Lucas's Phillips curve example), and $y_t$ was a stochastic process embedding \ngovernment polices \n(e.g., a tax rate or inflation process), forecasts\nof which influenced time $t$ decisions $d_t$.\\NFootnote{A variety of other examples  that we'll\nencounter later in this book also fit. Also see Hansen and Sargent (1980, 1981). In those examples, counterparts of the parameter $\\delta$\nin equation  \\Ep{lucas101;d} are themselves functions of deeper parameters measuring costs of adjustment and other features of\ntechnologies and preferences.}\n\\auth{Lucas, Robert E., Jr.}%\n\n\nNote that  by virtue of stationarity, $\\bmatrix{d_t \\cr x_t}$ is a  multivariate normal vector  with partitioned covariance matrix\n$\\bmatrix{  \\Sigma_{dd} & S\\Sigma_{dx} \\cr \\Sigma_{xd} S' & \\Sigma_{xx}}$, where $\\Sigma_{xx}$ satisfies  the discrete Lyapunov equation $\\Sigma_{xx}\n= A \\Sigma_{xx} A' + C C'$ and $\\Sigma_{dx} = S \\Sigma_{xx}$.  Application of the least squares formula \\Ep{leastsq12} confirms that  $S$  equals a matrix of population regression coefficients of $d_t$ on $x_t$\n   and that the $R^2$ for each component of $d_t$ is $1$.\\NFootnote{Apply formula \\Ep{leastsq12} for the matrix of regression coefficients\n    and notice that $\\beta = S \\Sigma_{xx} \\Sigma_{xx}^{-1} = S$\n   and that the conditional covariance matrix $\\hat \\Sigma_{dd} = 0$.}\n\n   %\n%\n%\n%under the assumption\n%that the researcher does not understand the origin of the decision rule $S$ via restriction \\Ep{lucas101;d}. Instead,\n%the researcher has a large set of observations on $\\{d_t, x_t\\}$ and estimates $S$ by least squares regression of $d_t$ on $x_t$.\n\nLucas (1976) criticized a collection of  studies that he said had used the following faulty logic.\n\n\\medskip\n\n\\item{a.}  A researcher   just wants to know  the decision rule for $d_t$  and ignores that   \n $S$ satisfies restriction \\Ep{lucas101;d}.\n\n\\medskip\n\n\\item{b.}  The researcher gathers   historical observations on $\\{d_t, x_t\\}_{t=0}^T$,\n correctly believes that $d_t = S x_t$ is a\nregression equation, and therefore  estimates the matrix  $S$ of regression coefficients by applying  least squares  equation-by-equation.\n\n\\medskip\n\n\\item{c.}  Mistakenly as it will turn out, the researcher  assumes that  the  decision rule $d_t = S x_t$ that he has estimated\n from historical data  will remain  invariant under\n arbitrary hypothetical alterations  of the right-hand side variables $\\{x_t\\}$, including ones that   would\n deviate from the historical law of motion\n \\Ep{lucas101;a}-\\Ep{lucas101;b}.    He falsely believes that he can use that estimated  decision rule to predict how\n variations in $\\{x_t\\}$ that systematically depart from system  \\Ep{lucas101;a}-\\Ep{lucas101;b} will induce\n  systematic variations in  \n  $\\{d_t\\}$.\\NFootnote{Of course, he could use the estimated decision rule to predict the consequences of  variations in $\\{x_t\\}$ that\n  {\\it are \\/} described by  system \\Ep{lucas101;a}-\\Ep{lucas101;b}.}\n\n\\medskip\n\n\\item{d.} Holding the historically estimated decision rule $S $ fixed,\n the researcher simulates outcomes $\\{y_t, d_t\\}_{t=T+1}^{\\tilde T}$\nunder alternative rules for generating\n time paths  for\n $\\{x_t\\}_{t=T+1}^{\\tilde T}$ and then evaluates the\nresulting $\\{y_t, d_t, x_t\\}_{t=T+1}^{\\tilde T}$\noutcomes according to a social  welfare function that depends on these outcome paths.   %, that are functions of the joint sequence $\\{d_t, x_t\\}$.\n\n\n\\medskip\n\n\\item{e.} After\nlearning how the  welfare function varies with the hypothetical rule for setting the $\\{x_t\\}_{t=T+1}^{\\tilde T}$ sequence,\nthe researcher recommends  a continuation $\\{x_t\\}_{t=T+1}^{\\tilde T}$\nsequence that yields the best social welfare. For example, the researcher holds $S$ fix and uses it as a component\nof a state-space system to which he applies a linear-quadratic optimal control theory to be described in chapter \\use{dplinear} to  recommend a\nlaw of motion for $x_t$ that manifests itself as a new pair of matrices $\\tilde A, \\tilde G$  that in the future\nwill replace $A, G$ in the state-space representation \\Ep{lucas101}, while he holds $S$ fixed at the value estimated from historical data.\n\n\\medskip\n\n\\item{f.} When  the  decision makers who choose $d_t$ recognize that under the new government policy  $\\tilde A, \\tilde G$ and not $A, G$ will describe future $y_t$'s, they adjust the decision rule $S$  to become \n $\\tilde S = H \\tilde G (I - \\delta \\tilde A)^{-1}$. By failing to understand that,\nthe researcher and policy maker will be disappointed to find that the regression  that the researcher  estimated on the historical data  fails to  describe data generated\nunder the regime $\\tilde G, \\tilde A$.\n\n\\medskip\n\nLucas (1976) said that the  line of reasoning in points (a)-(e)    characterized an influential  1940s-1960s econometric policy evaluation\nresearch method that  applied optimal control techniques to Keynesian and monetarist\neconometric models to propose  improved  macroeconomic policies. \nIn point (f) Lucas said that the method was flawed because it  ignored\n the key cross-equation restrictions \\Ep{lucas101;d}. Altering the policy-generating\nmatrices from the $G, A$ pair that prevailed historically to new pair  $\\tilde G, \\tilde A$ that describes a  hypothetical policy ``experiment'' that we want to study\n  amounts to a  positing a  ``regime change'' that\n should be expected  systematically to alter how private decision makers make  $y_t$ depend on $x_t$, as\n described by\n % that would alter   the $A,G$ pair %and the associated $x_t$\n%of matrices that appears\n%in\n system \\Ep{lucas101}.  % and that governs the $\\{y_t, x_t\\}$ process.\n A\n change in the decision maker's  environment $G, A$   alters the moment matrices\n$ \\Sigma_{xx}, \\Sigma_{dx}$ and therefore the population regression matrix of $d_t$ on $x_t$ that should be \nexpected to characterize outcomes\nunder the new  regime. Thus,  structure \\Ep{lucas101}, and in particular the cross-equation restrictions \\Ep{lucas101;d},\nimply that $S$ will vary {\\it systematically\\/} with  hypothetical changes\nin  $\\tilde G, \\tilde A$, belying the assumption that $S$ is invariant to the hypothetical policy interventions being investigated.\nA concise way to say this is that the joint probability distribution of the $\\{d_t, x_t\\}$ process and the implied\n  probability distribution\nof $d_t$ conditional on  $x_t$ process both  depend on the $(A, C, G)$ triple of matrices.\n\nLucas (1976) summarized his argument as follows:\n\n\\epigraph{$\\ldots$ given that the structure of an econometric model consists of optimal decision rules of economic agents, and\nthat optimal decision rules vary systematically with changes in the structure of series relevant to the decision makers, it follows\nthat any change in policies will systematically affect the structure of econometric models.}{``Econometric Policy Evaluation: A Critique,'' 1976}\n\n\n Equation \\Ep{lucas101;d} is an effective way of capturing  how ``optimal decision rules vary systematically with changes in the structure of\n series relevant to the decision makers.''  We already  encountered an example of  such restrictions  on optimal decision rules in\n section \\use{sec:LQmodel} when we found that the LQ permanent income model of consumption smoothing implies an optimal decision rule\n   for consumption of the form \\Ep{eqn:lucascritiquecons}. We shall encounter  more examples  in chapter \\use{dplinear}.\n  We can read   Lucas (1976) as  calling for  a rational expectations econometrics that incorporates  the kinds of cross-equation\nrestrictions  that system \\Ep{lucas101} encodes as an essential part of a better theory of econometric policy \nevaluation.\\NFootnote{See  Sargent (1981) and the introductory essay in Lucas and Sargent (1981), a volume containing\n early papers on  rational expectations econometrics.  See  Hansen and Sargent (1991a) for\nfurther\ntechnical contributions.}\n\\index{rational expectations!econometrics}\n\\auth{Lucas, Robert E., Jr.}%\n\\auth{Hansen, Lars P.}%\n\\auth{Sargent, Thomas J.}%\n\n\n\\section{Responses to the Lucas Critique}\\label{sec:lucascritique2}%\nSection \\use{sec:lucascritique} already mentioned a principal response to the Lucas Critique,  namely,\nrational expectations econometrics, an estimation and interpretation strategy now widely used throughout  applied economics.\nIn this section, we use a  state-space system with coefficients that are functions of a finite state Markov process \nas a vehicle to describe\nanother response\n%We describe what amount to either extensions to, or  alternatives to, or elaborations of rational expectations econometrics\nthat takes the perspective that \nchanges in  government  decision rules  or ``regimes''   \nunfold in ways that private agents  anticipate.  %don't occur in a vacuum but were\n%understood during the historical\n%sample period being modeled econometrically.\n%\\NFootnote{Section 3 of Lucas (1976) suggested that  longstanding  evidence that coefficients in\n%macroeconomic models drifted over time reflected   the workings  of  cross-equation restrictions  \n%like \\Ep{lucas101;d}.} \nSargent and Wallace (1976) argued that\n\n\n\\epigraph{$\\ldots$ new rules are not adopted\nin a vacuum. Something would cause the change -- a change in adminstrations,\nnew appointments, and so on. Moreover, if rational agents live in a world in\nwhich rules can be and are changed, their behavior should take into account such\npossibilities and should depend on the process generating the rule changes. But\ninvoking this kind of complete rationality seems to rule out normative economics\ncompletely by, in effect, ruling out freedom for the policymaker. For in a model\nwith completely rational expectations, including a rich enough description\nof policy, it seems impossible to define a sense in which there is any scope for\ndiscussing the optimal design of policy rules. That is because the equilibrium\nvalues of the endogenous variables already reflect, in the proper way, the\nparameters\ndescribing the authorities' prospective subsequent behavior, including\nthe probability that this or that proposal for reforming policy will be adopted.}{``Rational Expectations and the Theory of Economic Policy,''\nSargent and Wallace (1976), p.~181}\n\n\n\\auth{Wallace, Neil}%\n\\auth{Sargent, Thomas J.}%\n\nThis view sees  government decision rules as  statistical processes\n that are known to the private agents living inside a rational expectations model.  \n So  those private agents properly anticipate changes in government decision rules.\n Sargent and Wallace's   view that  government policy rules  are\ndetermined by a well understood process  leaves  econometricians and policy analysts with\n no ``free parameters'' to change,\ndisabling them from being able to offer policy advice.\nThis perspective  was embraced  by\n Christopher A. Sims (1982) and Sargent (1984).\\NFootnote{Musto and Yilmaz (2003) extended the approach \n to a political \n economy  with complete financial markets.}\n \\auth{Musto, David K.}%\n \\auth{Yilmaz, Bilge}%\n \n\\auth{Sims, Christopher A.}%\n\\auth{Zha, Tao}%\n\nIn describing  vector autoregressions with regime shifting coefficients and volatilities, Sims and Zha (2006)  link\ntheir work to the Lucas Critique: %\\example\n\\epigraph\n{The model with time variation in coefficients in all equations might be expected to fit best if there \nwere policy regime changes, and the nonlinear effects of these changes on private sector dynamics, via\n changes in private sector forecasting behavior, were important. That this is possible was the main point \n of Robert E. Lucas (1972).\n$\\ldots$ % as Sims (1987) has explained at more length,\nonce we recognize that changes in policy must in principle themselves be modeled as \nstochastic, Lucas's argument can be seen as a claim that a certain sort of nonlinearity is important. Even if the public believes that policy is time-varying and tries to adjust its expectation formation accordingly, its behavior could be well approximated as linear and non-time-varying. As with any use of a linear approximation, it is an empirical matter whether the linear approximation is adequate for a particular sample or counterfactual analysis.}{``Were There Regime  Switches in U.S. Monetary Policy?'' Sims and Zha (2006), p.~59}\n%\\endexample\n\n\n\\noindent Here we'll use chapter \\use{timeseries} tools to  study these parts of Sims and Zha's analysis:\n\n\\medskip\n\\item{a.} How to represent ``nonlinearities'' in the form of dependencies of linear state-space model \ncoefficients that are functions of  a discrete  Markov state variable that\nstands in for a ``regime''.\n\n\\medskip\n\\item{b.} How agents who understand regime transition probabilities and who recognize the current regime shape their decisions.\n\n\\medskip\n\\item{c.} How a best-fitting fixed-coefficient linear model that ignores regime changes can approximate observed \noutcomes.\n\n\n\\medskip\n\n\\subsection{Markov switching linear state space model}\n\nWe  can  represent the regime-change-induced \nnonlinearities mentioned by Sims and Zha policy  with  a linear state space model with\n coefficients that are governed by a finite state Markov chain.\\NFootnote{Hamilton (1989) introduces this \n  type of model of a stochastic process  and labels it  as ``non-stationary''.  If  we assume that \nchain $\\pi_0$ is  a stationary distribution, then the model  actually generates a stationary stochastic process,\n a property that we exploit  below. Williams and Svensson (2008) and Svensson and Williams (2009) used linear quadratic dynamic programming problems with Markov-switching coefficients to model optimal\nmonetary policies. }\nLet $s_t \\in \\{1,2\\}$ be governed by a Markov chain with transition matrix $P$, where\n$P_{ij} = {\\rm Prob}(s_{t+1} = j| s_t  = i) $, $\\pi_{0,i} = {\\rm Prob}(s_0 = i)$, and  $\\pi_{t,i} = {\\rm Prob}(s_t = i)$.\nWe assume that $\\{x_{t}, y_t\\}_{t=0}^\\infty$ is governed by  the linear state-space system with  \n Markov-switching matrices  \n$$ \\eqalign{ x_{t+1} & = A_{s_t} x_{t+1} + C_{s_t} w_{t+1} \\cr\n                    y_t  & = G_{s_t} x_t  \\cr  }   \\EQN MSLQ $$ %\nwhere $x_0 $ is a random initial vector drawn from  density  $\\phi_0$ and $w_{t+1} \\sim {\\cal N}(0,I)$ is an i.i.d.~sequence of random\nvectors.\nWe   want to compute the conditional  mathematical expectations\n $$ z_t = E ( \\sum_{j=0}^\\infty \\delta^t y_{t+j} ) \\Bigl| x_t, s_t  $$\n  and\n $$ \\tilde z_t =  E ( \\sum_{j=0}^\\infty \\delta^t y_{t+j} ) \\Bigl| x_t =  E z_t | x_t , $$\n where the last equality follows by an application of the \\idx{law of iterated expectations}.\n We also want to compute an associated  time-invariant vector autoregression that is implied by   \\Ep{MSLQ} and that takes the form\n  $$ x_{t+1} = \\bar A x_t + v_{t+1} \\EQN VARtimeinv$$\n  where $v_{t+1} $ is a serially uncorrelated shock with mean zero and contemporaneous covariance matrix $E v_{t+1} v_{t+1}' = \\bar \\Sigma$.\nThis is the object that Sims and Zha mention when they say of the time-varying system that ``its behavior could be well approximated as linear and non-time-varying''.\n\\auth{Hamilton, James D.}%\n\\auth{Williams, Noah}%\n\\auth{Svensson, Lars E. O.}%\n\\auth{Sims, Christopher A.}%\n\\auth{Zha, Tao}%\n\n\n\n\\subsection{Example}\nBefore computing these objects, let's take an example fashioned after a rational expectations version of Philip Cagan's (1956) model of\nhyperinflation.   The rate of inflation is the first difference of the logarithm of the price level\nand the rate of growth of the money supply is  the first difference of the logarithm of the money supply.\nLet $p_t$ be the rate  of inflation and let $m_t$ be the rate of growth of the money supply.  Assume\nthat\n$$ p_t = (1-\\lambda) m_t + \\lambda E_t p_{t+1},  \\quad \\lambda \\in (0,1)  $$\nso that\n$$ p_t = (1-\\lambda) E_t \\sum_{j=0}^\\infty \\lambda^j m_{t+j} , $$\nwhere $E_t (\\cdot)$ is a mathematical expectation conditioned on time $t$ information, which will be either $x_t$ or $(x_t, s_t)$, where the pair $(x_t, s_t)$ is defined as follows.\nWe assume  that $s_t \\in {1,2}$ is governed by a two-state Markov chain $P$ with initial distribution $\\pi_0$.\nSetting  $x_t= \\bmatrix{1 & m_t & m_{t-1} }'$   lets us capture the following stochastic process for $\\{m_t\\}_{t=0}^\\infty$ with the state-space form \\Ep{MSLQ }:\n$$ m_{t+1} = \\rho_{1,s_t} m_t + \\rho_{2,s_t} m_{t-1} + c_{s_t}w_{t+1}, \\EQN second_order_AR $$\nwhere $w_{t+1}$ is an i.i.d.~univariate standardized normal random variable. In subsection \\use{sec:cond_dist_102},\nwe'll use this example\nas a vehicle for illustrating Sims and Zha's remark about how  a linear time-invariant autoregression can approximate\na Markov-switching autoregression like \\Ep{second_order_AR}.\n\\auth{Cagan, Phillip}%\n\n\\subsection{Conditional distributions of geometric sums}\nWe begin by computing  $z_t$, an expectation conditional on both $x_t$ and $s_t$.\nWe begin by guessing that\n$$ z_t = H_{s_t} x_t  $$\nand substitute this guess into\n$$ z_t = y_t + \\delta  E  [ z_{t+1} | x_t, s_t ] $$\nto get\n$$  H_i  = G_{i}   + \\delta \\sum_{j} H_j A_i P_{ij}, $$\nwhich implies  that\n$$ \\eqalign{ H_1 & = G_1 + \\delta [ H_1 A_1 P_{11} + H_2 A_1 P_{12} ] \\cr\n                   H_2 & = G_2 + \\delta [ H_1 A_2 P_{21} + H_2 A_1 P_{22} ]. }$$\nStacking these equations and solving for the matrices $H_1, H_2$, we compute\n$$ \\bmatrix{H_1 & H_2 }  = \\bmatrix{G_1 & G_2}             (I - \\delta \\bmatrix {A_1 P_{11} & A_2 P_{21} \\cr\n                                                   A_1 P_{12} & A_2 P_{22} }  )^{-1}. $$\n\n\n\nNext we compute $ \\tilde z_t =  E ( \\sum_{j=0}^\\infty \\delta^t y_{t+j} ) | x_t$.\n%We let $\\pi_t$ be the distribution over the finite Markov state $s_t$. Note that the\n We start knowing that the probability distribution of $x_{t+1}$  conditional on $(x_t, s_t)$ is multivariate normal:\n$$  x_{t+1} | x_t, s_t   \\sim {\\cal N}( A_{s_t} x_t, C_{s_t}C_{s_t} ' ) . $$\nDistributions of $x_{t+1}, y_t$, and $z_t$ conditional on $x_t$ are {\\it mixtures of normals}, with $\\pi_{t,i}$   being the mixing probabilities over states $i$  at time $t$.\nDefining the matrix averages\n$$ \\eqalign{ \\bar A_t & = \\pi_{t,1} A_1 + \\pi_{t,2} A_2   \\cr\n                    \\bar G_t & =\\pi_{t,1} G_1 + \\pi_{t,2} G_2 \\cr\n                    \\bar H_t & = \\pi_{t,1} H_1 + \\pi_{t,2} H_2  ,}$$\nwe can deduce that means  conditional on $x_t$ are \n$$ \\eqalign{ E x_{t+1} | x_t & = \\bar A_t x_t \\cr\n                    E y_t | x_t & = \\bar G_t x_t      \\cr\n                    E z_t | x_t & \\equiv \\tilde z_t = \\bar H_t x_t   . }$$\nThe appearance of  time subscripts $t$ in the formulas for $\\bar A_t, \\bar G_t, \\bar H_t$ are a \nconsequence of  $\\pi_t$ not necessarily\nbeing a stationary distribution for $s_t$. % for Markov chain $P$.\n\n\\subsection{More conditional distributions}\\label{sec:cond_dist_102}%\nHaving computed conditional means,  let's compute covariances conditional on $x_t$.\nSince\n$$ x_{t+1} - \\bar A_t x_t = \\cases{ (A_1 - \\bar A_t) x_t  + C_1 w_{t+1} & if $s_t =1$ \\cr\n                                                    (A_2 - \\bar A_t) x_t  + C_2 w_{t+1} & if $s_t =2$ , } $$\nit follows that\n$$ \\EQNalign{ E (x_{t+1} - \\bar A_t x_t ) (x_{t+1} - \\bar A _tx_t ) ' | x_t & = \\sum_i \\pi_{t,i} [ (A_i - \\bar A_t) x_t x_t' (A_i - \\bar A_t)' + C_i C_i' ] \\cr\n        & \\equiv \\Sigma_t(x_t) \\EQN Sigmatxt }   $$\nwhere $i$ is present through $\\pi_{t,i}$ and $x_t$ is present because it appears on the right side of the first line.\nSince\n$$ y_t = \\cases{ G_1 x_t & if $s_t =1$ \\cr\n                           G_2 x_t & if $s_t =2 $ } $$\nand\n$$ y_t - \\bar G_t x_t = \\cases{ (G_1 - \\bar G_t) x_t & if $s_t =1$ \\cr\n                           (G_2  - \\bar G_t) x_t & if $s_t =2 $ , } $$\nit follows that\n$$ E (y_t - \\bar G_t x_t) (y_t - \\bar G_t x_t)' | x_t = \\sum_i \\pi_{t,i} \n(G_i - \\bar G_t) x_t x_t' (G_i - \\bar G_t)' \\equiv \\Sigma_{y,t}(x_t)   $$\nand similarly that\n$$ E (z_t - \\bar H_t x_t) (z_t - \\bar H_t x_t)' | x_t = \\sum_i \\pi_{t,i} (H_i - \\bar H_t) x_t x_t'\n (H_i - \\bar H_t)' \\equiv \\Sigma_{z,t}(x_t),  $$\n where the presence of $t$ subscripts in $ \\Sigma_{y,t}(x_t)$ and $\\Sigma_{z,t}(x_t)$ reflects that\n $\\pi_t$ might not be a stationary distribution, so that it and $\\bar G_t$ and $\\bar H_t$ all depend on $t$.\nWe can compute  unconditional means and covariances of the $\\{x_t\\}_{t=0}^\\infty$  process as follows.\nDefine the unconditional moments\n$E x_t = \\mu_t$ and $\\Sigma_t = E (x_t - \\mu_t) (x_t  - \\mu_t)'$.\nNote that\n$$ x_{t+1} - \\mu_{t+1} = \\cases{ A_1 (x_t   - \\mu_t)  + C_1 w_{t+1} & if $s_t =1$ \\cr\n                                                    A_2  (x_t   - \\mu_t)  + C_2 w_{t+1} & if $s_t =2$ .} $$\nIt follows that\n$$ \\mu_{t+1} = \\bar A_t \\mu_t$$\nand\n$$\\Sigma_{t+1} = \\pi_{t,1} (A_1 - \\bar A_t) \\Sigma_t (A_1 - \\bar A_t)' + \\pi_{t,2} (A_2 - \\bar A_t) \\Sigma_t (A_2 - \\bar A_t)' + (\\bar C \\bar C')_t  $$\nwhere $(\\bar C \\bar C')_t = \\sum_i \\pi_{t,i} C_i C_i' $.\nWhen  $\\pi_t \\rightarrow \\bar \\pi$ as $t$ goes to infinity, iterations on these two recursions  converge, respectively, to\na stationary mean vector $\\mu$  and a stationary covariance matrix $\\Sigma$ that\nsatisfy\n$$ \\mu  = \\bar A \\mu $$\nand\n$$\\bar \\Sigma =  \\bar \\pi_1 (A_1 - \\bar A) \\bar \\Sigma (A_1 - \\bar A)' + \\bar \\pi_2 (A_2 - \\bar A) \\bar \\Sigma(A_2 - \\bar A)' + \\bar C \\bar C' $$\nwhere $\\bar \\pi_i = \\lim_{t \\rightarrow +\\infty} \\pi_{t,i}$ and $\\bar C \\bar C' = \\sum_i \\bar \\pi_i C_i C_i'$.\nA time-invariant vector autoregression of the form \\Ep{VARtimeinv}, namely,\n$$ x_{t+1} = \\bar A x_t + v_{t+1} .$$\nhas $E v_{t+1} v_{t+1}' = \\bar \\Sigma$.\nWhen $\\pi_t = \\bar \\pi_t$, formulas for $\\Sigma_y(x_t)$ and $\\Sigma_z(x_t)$ also  simplify: \n$$ E (y_t - \\bar G x_t) (y_t - \\bar G x_t)' | x_t = \\sum_i \\pi_{i} \n(G_i - \\bar G) x_t x_t' (G_i - \\bar G)' \\equiv \\Sigma_{y}(x_t)   $$\nand \n$$ E (z_t - \\bar H x_t) (z_t - \\bar H x_t)' | x_t = \\sum_i \\pi_{i} (H_i - \\bar H) x_t x_t'\n (H_i - \\bar H)' \\equiv \\Sigma_{z}(x_t),  $$\n where  $t$ subscripts have disappeared from  $ \\Sigma_{t}(x_t)$ and $\\Sigma_{z}(x_t)$ because \n $\\pi = \\bar \\pi$  and also now $\\bar G$ and $\\bar H$ no longer  depend on $t$.\n Under this stationary specification, we thus have the regression equations\n $$\\eqalign{ x_{t+1} & = \\bar A x_t + v_{t+1} \\cr\n            y_t & = \\bar G x_t + \\epsilon_{y,t} \\cr \n             z_t & = \\bar H x_t + \\epsilon_{z,t}, }\n$$\nwhere $\\bar H = \\bar G (I - \\delta \\bar A)^{-1}$, $E v_{t+1} v_{t+1}'  = \\bar \\Sigma$,\n $E \\epsilon_{y,t} \\epsilon_{y,t}' = \\Sigma_y(x_t), \\ E \\epsilon_{z,t} \\epsilon_{z,t}' = \\Sigma_z(x_t) $.\n\n\nWe can use some of the formulas above and our example in  equation \\Ep{second_order_AR} to revisit Sims and Zha's (2006)\ncomments about how  a linear time invariant autoregression can approximate a Markov switching autoregression.\n  We set $(\\rho_{1,1}, \\rho_{2,1}, c_{1}) =\n(1.2, -.3, .5)$ and $(\\rho_{1,2}, \\rho_{2,2}, c_{2}) =\n(.8, 0.0, .8)$, $P = \\bmatrix{.5 & .5 \\cr .5 & .5}$, and $\\pi_0 = \\bmatrix{.5 \\cr .5} $, so that the one  step-ahead \n conditional variance in state $s_t=1$  is $.25$  and in state $s_t=2$ is $.64$.  Applying the preceding formulas, we\ncan deduce the time-invariant second order autoregression\n$$ m_{t+1} = 1.0 m_t - .15 m_{t-1} + v_{t+1} $$\nwhere $E v_{t+1}^2 = \\bar \\Sigma = .46$, which is to be compared with the conditional variances $.25$ in state $s_t=1$ and\n$.64$ in state $s_t = 2$.  \nFor this same example, it is instructive to set the discount factor $\\delta =.95$ and set $G_i =\n\\bmatrix{1 & 0 \\cr}'$ for $i = 1, 2$ so that $G_i$ does {\\it \\/} not depend on the Markov state $s_t$.  \nIn this case, we obtain \n$$ \\bar H = \\bar G (I - \\delta \\bar A)^{-1}  =  XXXX\n $$\n\n% \\medskip\n% \\noindent{\\bf Request to Quentin:}  Could you please add to your notebook code for computing the quantities\n% that required to compute $\\bar H$.  The preceding can be computed \n% \"analytically\" using the above formulas, most of which you already have in the Jupyter notebook.\n% Another things that could be \"fun\" to compute would be the {\\it average\\/} value of $\\Sigma_z(x_t)$.\n% I would recommend doing this just by running a very very long simulation and taking a time series average \n% of $(H_i - \\bar H) x_t x_t'\n% (H_i - \\bar H)'$ as $s_t, x_t$ wander through time and states.  \n\n\n\n\n\\auth{Sims, Christopher A.}%\n\\auth{Zha, Tao}%\n\n\n\n% \\noindent{\\bf Quentin R0:} Please go over the code in your notebook and reorganize to have all population computations at the front\n% of the notebook. By ``population'' I mean analytic with our formulas, not the simulations with the least squares regressions. Please put that material at the end of the notebook. Please make the notebook so that Zejin can understand the flow and approve of its readability.\n\n% \\noindent{\\bf Quentin R1:} Please compute and display conveniently for me the objects $C_1 C_1', C_2 C_2', \\bar \\Sigma, \\bar A$.\n\n\n% \\noindent{\\bf Quentin R2:} Please compute ``all of our objects'' for the above example with two $s_t$ dependent   $\\rho_1, \\rho_2$ vectors, namely $1.2, -.3$ and $.95, 0$ with\n% a transition matrix $P = \\bmatrix{ .5 & .5 \\cr .5 & .5 } $ using as $\\pi_0 =\\pi_\\infty$ the stationary distribution $\\bmatrix{.5 & .5}'$\n% or with another set of parameter values that I can input easily.  \n\n\n% \\medskip\n% \\noindent{\\bf Quentin R3:} Please check whether $\\bar H = \\bar G (I -\\delta \\bar A)^{-1}$ and display outcomes so that Zejin and I can readily\n% spot them.\n\n\n\\subsection{Time series averages}\nConsider the conditional covariance matrix\n$$\\Sigma(x_t)  = \\sum_i \\pi_{t,i} [ (A_i - \\bar A) x_t x_t' (A_i - \\bar A)' + C_i C_i' ] .$$\nAssume that the pair $(P, \\pi_0)$ governing the  Markov state $s_t$ is stationary. Then  the joint process $\\{x_t, s_t\\}$ process is also  stationary,\nand so is the  process $\\{x_t\\}$. Say that $x_t$ has  the unconditional probability distribution $\\Phi(x)$.\nThen a law of large numbers tells us that as $ {T \\rightarrow + \\infty}$\n$$ T^{-1} \\sum_{t=0}^T \\Sigma(x_t)  \\rightarrow \\int \\Sigma(x) d \\Phi(x) \\equiv \\Sigma $$\n\n\n", "meta": {"hexsha": "e1b8d6fca766d11bbe9a087b6b842f129f11b7d4", "size": 28228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/Lucas_Sims_notes.tex", "max_stars_repo_name": "QuantEcon/python-lecture-sandpit.myst", "max_stars_repo_head_hexsha": "8e6c8cb971ab06af12e5364a4a2cb9d0d07ab925", "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": "lectures/Lucas_Sims_notes.tex", "max_issues_repo_name": "QuantEcon/python-lecture-sandpit.myst", "max_issues_repo_head_hexsha": "8e6c8cb971ab06af12e5364a4a2cb9d0d07ab925", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-12-14T07:16:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T00:06:51.000Z", "max_forks_repo_path": "lectures/Lucas_Sims_notes.tex", "max_forks_repo_name": "QuantEcon/python-lecture-sandpit.myst", "max_forks_repo_head_hexsha": "8e6c8cb971ab06af12e5364a4a2cb9d0d07ab925", "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": 63.5765765766, "max_line_length": 540, "alphanum_fraction": 0.7030253649, "num_tokens": 8521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6277835029638061}}
{"text": "\\section{Proofs for Chapter 4}\n\\label{sec:a13chapter4}\n\n\\disableornamentsfornextheadingtrue\n\\subsection{Combinatorial Proof of the Combination Technique}\n\\label{sec:a131proofCombiTechnique}\n\n\\addtocontents{lop}{\\protect\\fi}\n\n\\begin{definition}[binomial coefficient for integer parameters]\n  \\label{def:binomialCoefficient}\n  The binomial coefficient $\\binom{n}{k}$ is defined for\n  $n \\in \\natz$ and $k \\in \\integer$ as\n  \\begin{equation}\n    \\binom{n}{k}\n    \\ceq\n    \\begin{cases}\n      \\frac{n (n - 1) \\dotsm (n - (k-1))}{k!},&0 < k < n,\\\\\n      1,&(k = 0) \\lor (k = n),\\\\\n      0,&(k < 0) \\lor (k > n).\n    \\end{cases}\n  \\end{equation}\n\\end{definition}\n\n\\begin{lemma}[inclusion-exclusion counting lemma]\n  \\label{lemma:inclusionExclusionCountingLemma}\n  For $a \\in \\natz$, $r \\ge a$, and $s \\in \\integer$, we have\n  \\begin{equation}\n    \\sum_{q=0}^a (-1)^q \\binom{a}{q} \\binom{r-q}{s}\n    = \\binom{r-a}{s-a}.\n  \\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n  We apply the upper negation formula\n  (see Eq. (5.14) of \\cite{Graham94Concrete})\n  to the second binomial of the \\lhs:\n  \\begin{subequations}\n    \\begin{align}\n      \\sum_{q=0}^a (-1)^q \\binom{a}{q} \\binom{r-q}{s}\n      &= (-1)^s \\sum_{q=0}^a \\binom{a}{0+q} \\binom{(s-r-1)+q}{s} (-1)^q.\\\\\n      \\intertext{%\n        This sum can be simplified using the identity\n        in Eq.\\ (5.24) of \\cite{Graham94Concrete}\n        (the sum has already been written in the same way as in\n        \\cite{Graham94Concrete}):%\n      }\n      \\cdots\n      &= (-1)^{s+a} \\binom{s-r-1}{s-a}.\\\\\n      \\intertext{%\n        Applying the upper negation formula again,%\n      }\n      \\cdots\n      &= \\binom{r-a}{s-a},\n    \\end{align}\n  \\end{subequations}\n  we obtain the desired quantity.\n\\end{proof}\n\n\\addtocontents{lop}{\\protect\\iffalse}\n\n\\propCombiTechniqueOne*\n\n\\begin{proof}\n  Let $q = 0, \\dotsc, d - 1$ and $\\gp{\\*l,\\*i} \\in \\regsgset{n}{d}$, i.e.,\n  $\\normone{\\*l} \\le n$ and $\\*i \\in \\hiset{\\*l}$.\n  Note that for $\\*l' \\in \\natz^d$, we have\n  $\\fgset{\\*l'} \\ni \\gp{\\*l,\\*i} \\iff \\*l' \\ge \\*l$.\n  Hence,\n  \\begin{subequations}\n    \\begin{align}\n      \\setsize{\n        \\{\\*l' \\mid \\normone{\\*l'} = n - q,\\; \\fgset{\\*l'} \\ni \\gp{\\*l,\\*i}\\}\n      }\n      &= \\setsize{\n        \\{\\*l' \\mid \\normone{\\*l'} = n - q,\\; \\*l' \\ge \\*l\\}\n      }\\\\\n      &= \\setsize{\n        \\{\\*a \\in \\natz^d \\mid \\normone{\\*a} = n - q - \\normone{\\*l}\\}\n      }\\\\\n      \\intertext{%\n        by mapping $\\*a \\ceq \\*l' - \\*l$.\n        The size of the last set is\n        known as the number of \\term{weak compositions}\n        of $n - q - \\normone{\\*l}$ into $d$ parts\n        and can be computed as%\n      }\n      \\cdots\n      &= \\binom{n - q - \\normone{\\*l} + d - 1}{d - 1},\n    \\end{align}\n  \\end{subequations}\n  see Theorem 2.2 of \\cite{Bona15Introduction}.\n  Now, we can use \\cref{lemma:inclusionExclusionCountingLemma}\n  with the values\n  $a \\ceq s \\ceq d - 1$ and\n  $r \\ceq n - \\normone{\\*l} + d - 1$\n  to conclude that the \\lhs of the assertion\n  \\eqref{eq:combiTechniqueOne} equals\n  \\begin{equation}\n    \\sum_{q=0}^{d-1} (-1)^q \\binom{d-1}{q} \\cdot\n    \\binom{n - q - \\normone{\\*l} + d - 1}{d - 1}\n    = \\binom{n - \\normone{\\*l}}{0}\n    = 1,\n  \\end{equation}\n  proving the proposition.\n\\end{proof}\n\n\\addtocontents{lop}{\\protect\\fi}\n\n\\begin{shortlemma}[relation is equivalence relation]\n  \\label{lemma:combiTechniqueEquivalenceRelation}\n  $\\eq$ is an equivalence relation.\n\\end{shortlemma}\n\n\\begin{proof}\n  We check reflexivity, symmetry, and transitivity of $\\eq$:\n  \\begin{itemize}\n    \\item\n    \\emph{Reflexivity:}\n    Using the same level $\\*l' = \\*l''$ implies\n    $T_{\\*l',\\*l'} = \\{t \\mid l'_t < l_t\\}$.\n    For all $t \\notin T_{\\*l',\\*l'}$, we have $l'_t \\ge l_t$.\n    Consequently, $\\*l' \\eq \\*l'$.\n    \n    \\item\n    \\emph{Symmetry:}\n    We have\n    $\\*l' \\eq \\*l'' \\iff \\*l'' \\eq \\*l'$, since\n    $T_{\\*l',\\*l''} = T_{\\*l'',\\*l'}$ and\n    $\\min\\{l'_t, l''_t\\} = \\min\\{l''_t, l'_t\\}$.\n    \n    \\item\n    \\emph{Transitivity:}\n    Let $\\*l' \\eq \\hat{\\*l}$, $\\hat{\\*l} \\eq \\*l''$, and\n    $t \\notin T_{\\*l',\\*l''}$.\n    From the definition of $T_{\\*l',\\*l''}$,\n    it holds that either $l'_t \\not= l''_t$ or $l'_t = l''_t \\ge l_t$.\n    As $l'_t = l''_t \\ge l_t$ already implies $\\min\\{l'_t, l''_t\\} \\ge l_t$,\n    we assume that $l'_t \\not= l''_t$.\n    Here, we have three cases:\n    \\begin{itemize}\n      \\item\n      \\mbox{\\emph{Case 1:} ${l'_t \\not= \\hat{l}_t = l''_t}$.}\n      $t \\notin T_{\\*l',\\hat{\\*l}}$ implies $l'_t \\ge l_t$ and\n      $l''_t = \\hat{l}_t \\ge l_t$.\n      Therefore, $\\min\\{l'_t, l''_t\\} \\ge l_t$.\n      \n      \\item\n      \\mbox{\\emph{Case 2:} ${l'_t = \\hat{l}_t \\not= l''_t}$.}\n      Analogously to the first case, we conclude $\\min\\{l'_t, l''_t\\} \\ge l_t$.\n      \n      \\item\n      \\mbox{\\emph{Case 3:} ${l'_t \\not= \\hat{l}_t \\not= l''_t}$.}\n      $t \\notin T_{\\*l',\\hat{\\*l}}$ implies $l'_t \\ge l_t$ and\n      $t \\notin T_{\\*l'',\\hat{\\*l}}$ implies $l''_t \\ge l_t$.\n      Hence, $\\min\\{l'_t, l''_t\\} \\ge l_t$.\n    \\end{itemize}\n    Therefore, it holds that $\\min\\{l'_t, l''_t\\} \\ge l_t$\n    for all $t \\notin T_{\\*l',\\*l''}$, i.e., $\\*l' \\eq \\*l''$.\n  \\end{itemize}\n  This shows that $\\eq$ is an equivalence relation.\n\\end{proof}\n\n\\addtocontents{lop}{\\protect\\iffalse}\n\n\\lemmaCombiTechniqueIdenticalValues*\n\n\\begin{proof}\n  First, we note that $T_{\\*l',\\*l''} \\not= \\emptyset$.\n  Otherwise, for $T_{\\*l',\\*l''} = \\emptyset$,\n  we have $\\min\\{l'_t, l''_t\\} \\ge l_t$\n  for all $t = 1, \\dotsc, d$, which implies $\\*l' \\ge \\*l$, i.e.,\n  $\\fgset{\\*l'} \\ni \\gp{\\*l,\\*i}$.\n  This contradicts the fact that $\\*l' \\in L$, where $L$ is defined\n  in \\eqref{eq:combiTechniqueSpecialLevelSet}\n  (which holds as our equivalence relation is only defined on $L$).\n  Therefore, $T_{\\*l',\\*l''} \\not= \\emptyset$ must hold.\n  Without loss of generality,\n  we assume that $T_{\\*l',\\*l''} = \\{1, \\dotsc, m\\}$\n  for some $m \\in \\{1, \\dotsc, d\\}$.\n  \n  Let\n  \\begin{equation}\n    S \\ceq \\gp{\\*l,\\*i} + \\spn\\{\\stdbasis{1}, \\dotsc, \\stdbasis{m}\\}\n    = \\{\\gp{\\*l,\\*i} + \\textstyle\\sum_{t=1}^m c_t \\stdbasis{t} \\mid\n    c_1, \\dotsc, c_m \\in \\real\\}\n  \\end{equation}\n  be the $m$-dimensional affine subspace of $\\real^d$\n  through $\\gp{\\*l, \\*i}$\n  parallel to the dimensions $1, \\dotsc, m$,\n  where $\\stdbasis{t}$ is the $t$-th standard basis vector.\n  It holds that $S \\cap \\fgset{\\*l'} = S \\cap \\fgset{\\*l''}$ due to\n  $l'_t = l''_t$ for $t \\le m$.%\n  \\footnote{%\n    In more detail:\n    If we have an $\\gp{\\hat{\\*l},\\hat{\\*i}} \\in S \\cap \\fgset{\\*l'}$,\n    then $\\fa{t \\le m}{\\hat{l}_t \\le l'_t = l''_t}$ and\n    $\\fa{t > m}{\\hat{l}_t = l_t \\le l''_t}$, i.e.,\n    $\\hat{\\*l} \\le \\*l''$ and therefore\n    $\\gp{\\hat{\\*l},\\hat{\\*i}} \\in S \\cap \\fgset{\\*l''}$.%\n  }\n  \n  On this $m$-dimensional grid $S \\cap \\fgset{\\*l'} = S \\cap \\fgset{\\*l''}$,\n  the full grid interpolants $\\fgintp{\\*l'}$ and $\\fgintp{\\*l''}$\n  coincide, as both interpolate the function values given by\n  the objective function $\\objfun$:\n  \\begin{equation}\n    \\label{eq:proofCombiTechniqueIdenticalValues1}\n    \\restrictfcn{\\fgintp{\\*l'}}{S \\cap \\fgset{\\*l'}}\n    = \\restrictfcn{\\objfun}{S \\cap \\fgset{\\*l'}}\n    =  \\restrictfcn{\\fgintp{\\*l''}}{S \\cap \\fgset{\\*l'}}.\n  \\end{equation}\n  However, this does not suffice to conclude\n  $\\fgintp{\\*l'}(\\gp{\\*l,\\*i}) = \\fgintp{\\*l''}(\\gp{\\*l,\\*i})$,\n  since $\\gp{\\*l,\\*i} \\notin \\fgset{\\*l'}$.\n  \n  To this end, we recall from \\eqref{eq:interpFullGridMV} that\n  \\begin{equation}\n    \\fgintp{\\*l'}\n    = \\sum_{\\*i'=\\*0}^{\\*2^{\\*l'}} \\interpcoeff{\\*l',\\*i'}\n    \\basis{\\*l',\\*i'},\\quad\n    \\interpcoeff{\\*l',\\*i'} \\in \\real.\n  \\end{equation}\n  This implies that the $m$-variate restricted interpolant\n  $\\restrictfcn{\\fgintp{\\*l'}}{S \\cap \\clint{\\*0, \\*1}}$ can be written as\n  \\begin{subequations}\n    \\begin{align}\n      (\\restrictfcn{\\fgintp{\\*l'}}{S \\cap \\clint{\\*0, \\*1}})\n      (\\*x_{\\range{1}{m}})\n      &\\mathrel{\\righthphantom{=}{\\ceq}}\n      \\sum_{\\*i'_{\\range{1}{m}}=\\*0}^{\\*2^{\\*l'_{\\range{1}{m}}}}\n      \\interpcoefftilde{\\*l'_{\\range{1}{m}},\\*i'_{\\range{1}{m}}}\n      \\basis{\\*l'_{\\range{1}{m}},\\*i'_{\\range{1}{m}}}(\\*x_{\\range{1}{m}}),\\quad\n      \\*x_{\\range{1}{m}} \\in \\clint{0, 1}^m,\\\\\n      \\interpcoefftilde{\\*l'_{\\range{1}{m}},\\*i'_{\\range{1}{m}}}\n      &\\ceq \\sum_{\\*i'_{\\range{m+1}{d}}=\\*0}^{\\*2^{\\*l'_{\\range{m+1}{d}}}}\n      \\interpcoeff{\\*l',\\*i'}\n      \\basis{\\*l'_{\\range{m+1}{d}},\\*i'_{\\range{m+1}{d}}}%\n      (\\gp{\\*l_{\\range{m+1}{d}},\\*i_{\\range{m+1}{d}}})\n    \\end{align}\n  \\end{subequations}\n  by factoring out tensor product factors corresponding to dimensions\n  $m + 1, \\dotsc, d$.\n  The subscripts $\\range{1}{m}$ and $\\range{m+1}{d}$ denote\n  the entries with respect to the dimensions $1, \\dotsc, m$ and\n  $m + 1, \\dotsc, d$, respectively.\n  As a result,\n  both $\\restrictfcn{\\fgintp{\\*l'}}{S \\cap \\clint{\\*0, \\*1}}$\n  and, analogously,\n  $\\restrictfcn{\\fgintp{\\*l''}}{S \\cap \\clint{\\*0, \\*1}}$\n  are interpolants of $\\objfun$ in\n  $\\ns{\\*l'_{\\range{1}{m}}} = \\ns{\\*l''_{\\range{1}{m}}}$.\n  Due to \\thmref{lemma:tensorProductLinearIndependence},\n  it follows from \\eqref{eq:proofCombiTechniqueIdenticalValues1}\n  that they must be the same:\n  \\begin{equation}\n    \\restrictfcn{\\fgintp{\\*l'}}{S \\cap \\clint{\\*0, \\*1}}\n    = \\restrictfcn{\\fgintp{\\*l''}}{S \\cap \\clint{\\*0, \\*1}}.\n  \\end{equation}\n  Consequently, $\\fgintp{\\*l'}(\\gp{\\*l,\\*i}) = \\fgintp{\\*l''}(\\gp{\\*l,\\*i})$\n  as $\\gp{\\*l,\\*i} \\in S \\cap \\clint{\\*0, \\*1}$.\n\\end{proof}\n\n\\lemmaCombiTechniqueCharacterization*\n\n\\begin{proof}\n  ``$\\subset$'':\n  Let $\\*l' \\in L_0$.\n  We have to prove that\n  $\\fa{t \\in T_{L_0}}{l'_t = l^\\ast_t}$ and\n  $\\fa{t \\notin T_{L_0}}{l'_t \\ge l_t}$.\n  The first statement is clear by the definition of $T_{L_0}$.\n  Therefore, let $t \\notin T_{L_0}$.\n  By the definition of $T_{L_0}$,\n  we have either\n  $\\ex{\\hat{\\*l} \\in L_0}{l'_t \\not= \\hat{l}_t}$ or\n  $\\fa{\\hat{\\*l} \\in L_0}{l'_t = \\hat{l}_t \\ge l_t}$.\n  In the latter case, we obtain $l'_t \\ge l_t$\n  (e.g., by setting $\\hat{\\*l}$ to $\\*l'$).\n  In the former case, there is an $\\hat{\\*l} \\in L_0$ such that\n  $l'_t \\not= \\hat{l}_t$.\n  Due to $\\*l' \\eq \\hat{\\*l}$\n  (since $\\*l'$ and $\\hat{\\*l}$ are both contained in the same\n  equivalence class $L_0$) and $t \\notin T_{\\*l',\\hat{\\*l}}$,\n  we have $\\min\\{l'_t, \\hat{l}_t\\} \\ge l_t$.\n  This implies $\\fa{t \\notin T_{L_0}}{l'_t \\ge l_t}$, as desired.\n  \n  ``$\\supset$'':\n  Let $\\*l' \\in L$ such that\n  $\\fa{t \\in T_{L_0}}{l'_t = l^\\ast_t}$ and\n  $\\fa{t \\notin T_{L_0}}{l'_t \\ge l_t}$.\n  Furthermore,\n  let $\\*l'' \\in L_0$ be an arbitrary representative of $L_0$.\n  We prove that $\\*l' \\eq \\*l''$ (i.e., $\\*l' \\in L_0$).\n  Note that $T_{L_0} \\subset T_{\\*l',\\*l''}$,\n  as $t \\in T_{L_0}$ implies\n  $l''_t = l^\\ast_t < l_t$, which can be combined with $l'_t = l^\\ast_t$\n  to $l'_t = l''_t < l_t$, i.e., $t \\in T_{\\*l',\\*l''}$.\n  \n  To prove the equivalence of $\\*l'$ and $\\*l''$,\n  let $t \\notin T_{\\*l',\\*l''}$,\n  i.e., $t \\notin T_{L_0}$.\n  By assumption on $\\*l'$, it holds $l'_t \\ge l_t$.\n  Hence, it remains to show that $l''_t \\ge l_t$ as well.\n  Again, by definition of $T_{L_0}$, we have either\n  $\\ex{\\hat{\\*l} \\in L_0}{l''_t \\not= \\hat{l}_t}$ or\n  $\\fa{\\hat{\\*l} \\in L_0}{l''_t = \\hat{l}_t \\ge l_t}$.\n  In the second case, it holds $l''_t \\ge l_t$.\n  In the first case, there is an $\\hat{\\*l} \\in L_0$ such that\n  $l''_t \\not= \\hat{l}_t$.\n  Due to $\\*l'' \\eq \\hat{\\*l}$\n  (since $\\*l''$ and $\\hat{\\*l}$ are both contained in the same\n  equivalence class $L_0$) and $t \\notin T_{\\*l'',\\hat{\\*l}}$,\n  we have $\\min\\{l''_t, \\hat{l}_t\\} \\ge l_t$.\n  In particular, $l''_t \\ge l_t$.\n  In total, we have $\\min\\{l'_t, l''_t\\} \\ge l_t$ for all\n  $t \\notin T_{\\*l',\\*l''}$, proving that $\\*l'$ and $\\*l''$ are equivalent,\n  as asserted.\n\\end{proof}\n\n\\propCombiTechniqueZero*\n\n\\begin{proof}\n  \\Cref{lemma:combiTechniqueIdenticalValues}\n  implies that the summands $\\fgintp{\\*l'}(\\gp{\\*l,\\*i})$\n  corresponding to levels $\\*l'$ of the same equivalence class\n  $L_0 \\in \\eqclasses{L}{\\eq}$ are identical.\n  Let $f_{L_0}$ denote the common function value.\n  The sum in the \\lhs of the assertion can be reordered to combine\n  levels of the equivalence classes $L_0 \\in \\eqclasses{L}{\\eq}$:\n  \\begin{subequations}\n    \\begin{align}\n      &\\sum_{q=0}^{d-1} (-1)^q \\binom{d-1}{q} \\cdot\n      \\sum_{\\substack{\\normone{\\*l'} = n - q\\\\\\fgset{\\*l'} \\notni \\gp{\\*l,\\*i}}}\n      \\fgintp{\\*l'}(\\gp{\\*l,\\*i})\\\\\n      \\label{eq:proofCombiTechniqueIdenticalValues2}\n      &= \\sum_{L_0 \\in \\eqclasses{L}{\\eq}} f_{L_0} \\sum_{q=0}^{d-1}\n      (-1)^q \\binom{d-1}{q} \\cdot\n      \\setsize{\\{\\*l' \\in L_0 \\mid \\normone{\\*l'} = n - q\\}}.\n    \\end{align}\n  \\end{subequations}\n  It now suffices to show that the inner sum vanishes\n  for every equivalence class $L_0 \\in \\eqclasses{L}{\\eq}$.\n  \n  To this end, we have to calculate\n  $\\setsize{\\{\\*l' \\in L_0 \\mid \\normone{\\*l'} = n - q\\}}$\n  for a fixed equivalence class $L_0$.\n  Without loss of generality,\n  let $T_{L_0} = \\{1, \\dotsc, m\\}$ in the notation of\n  \\thmref{lemma:combiTechniqueCharacterization}\n  with $1 \\le m \\le d$.\n  Note that the case $m = 0$ is impossible:\n  Otherwise, $T_{L_0} = \\emptyset$ implies\n  $\\fa{\\*l' \\in L_0}{\\*l' \\ge \\*l}$ by\n  \\cref{lemma:combiTechniqueCharacterization}, and\n  as equivalence classes are non-empty,\n  there is at least one $\\*l' \\in L_0$ with $\\*l' \\ge \\*l$.\n  However, this is equivalent to $\\fgset{\\*l'} \\ni \\gp{\\*l,\\*i}$,\n  which contradicts $\\*l' \\in L$.\n  Hence, we have $m > 0$.\n  \n  To enumerate all levels $\\*l' \\in L_0$ with $\\normone{\\*l'} = n - q$,\n  we exploit the characterization of $L_0$ of\n  \\cref{lemma:combiTechniqueCharacterization}.\n  For notational convenience, we define the vector\n  \\begin{equation}\n    \\hat{\\*l}\n    \\ceq (l^\\ast_1, \\dotsc, l^\\ast_m,\\; l_{m+1}, \\dotsc, l_d),\n  \\end{equation}\n  where $\\*l^\\ast$ is given as in \\cref{lemma:combiTechniqueCharacterization}.\n  We show that $\\*a \\ceq (l'_t - l_t)_{t = m+1, \\dotsc, d}$\n  constitutes a bijection between\n  \\begin{equation}\n    \\{\\*l' \\in L_0 \\mid \\normone{\\*l'} = n - q\\}\n    \\quad\\text{and}\\quad\n    \\{\\*a \\in \\natz^{d-m} \\mid \\normone{\\*a} = n - q - \\normone{\\hat{\\*l}}\\}\n    \\colon\n  \\end{equation}\n  \\begin{itemize}\n    \\item\n    Let $\\*l' \\in L_0$ with $\\normone{\\*l'} = n - q$.\n    Then, $\\fa{t=m+1,\\dotsc,d}{l'_t - l_t \\ge 0}$\n    (by \\cref{lemma:combiTechniqueCharacterization}), i.e.,\n    $\\*a \\in \\natz^{d-m}$, and\n    \\begin{equation}\n      \\normone{\\*a}\n      = \\sum_{t=m+1}^d (l'_t - l_t)\n      = \\paren*{\\normone{\\*l'} - \\sum_{t=1}^m l'_t} -\n      \\sum_{t=m+1}^d \\hat{l}_t\n      = n - q - \\normone{\\hat{\\*l}}.\n    \\end{equation}\n    \n    \\item\n    Conversely, let $\\*a \\in \\natz^{d-m}$ with\n    $\\normone{\\*a} = n - q - \\normone{\\hat{\\*l}}$.\n    If we define $\\*l'$ as\n    \\begin{equation}\n      \\*l'\n      = (l^\\ast_1, \\dotsc, l^\\ast_m,\\;\n      a_1 + l_{m+1}, \\dotsc, a_{d-m} + l_d),\n    \\end{equation}\n    then $\\fa{t=1,\\dotsc,m}{l'_t = l^\\ast_t < l_t}$ and\n    $\\fa{t=m+1,\\dotsc,d}{l'_t \\ge l_t}$.\n    By \\cref{lemma:combiTechniqueCharacterization},\n    we obtain $\\*l' \\in L_0$ and\n    \\begin{equation}\n      \\normone{\\*l'}\n      = \\normone{\\hat{\\*l}} + \\normone{\\*a}\n      = n - q.\n    \\end{equation}\n  \\end{itemize}\n  This bijection implies that\n  \\begin{subequations}\n    \\begin{align}\n      \\setsize{\\{\\*l' \\in L_0 \\mid \\normone{\\*l'} = n - q\\}}\n      &= \\setsize{\n        \\{\\*a \\in \\natz^{d-m} \\mid \\normone{\\*a} = n - q - \\normone{\\hat{\\*l}}\\}\n      }.\\\\\n      \\intertext{%\n        This is the number of weak decompositions of\n        $n - q - \\normone{\\hat{\\*l}}$ into $d - m$ parts:%\n      }\n      \\cdots\n      &= \\binom{n - q - \\normone{\\hat{\\*l}} + d - m - 1}{d - m - 1},\n    \\end{align}\n  \\end{subequations}\n  see Theorem 2.2 of \\cite{Bona15Introduction}.\n  We insert this quantity into the inner sum of\n  \\eqref{eq:proofCombiTechniqueIdenticalValues2}:\n  \\begin{subequations}\n    \\label{eq:proofCombiTechniqueIdenticalValues3}\n    \\begin{align}\n      &\\sum_{q=0}^{d-1}\n      (-1)^q \\binom{d-1}{q} \\cdot\n      \\setsize{\\{\\*l' \\in L_0 \\mid \\normone{\\*l'} = n - q\\}}\\\\\n      &= \\sum_{q=0}^{d-1} (-1)^q \\binom{d-1}{q} \\cdot\n      \\binom{n - q - \\normone{\\hat{\\*l}} + d - m - 1}{d - m - 1}.\n    \\end{align}\n  \\end{subequations}\n  Again, we apply \\thmref{lemma:inclusionExclusionCountingLemma}\n  with the values $a \\ceq d - 1$,\n  $r \\ceq n - \\normone{\\hat{\\*l}} + d - m - 1$, and\n  $s \\ceq d - m - 1$ to infer that as claimed,\n  \\eqref{eq:proofCombiTechniqueIdenticalValues3} is equal to\n  \\begin{equation}\n  \\label{eq:proofCombiTechniqueIdenticalValues4}\n    \\binom{n - \\normone{\\hat{\\*l}} - m}{-m}\n    = 0\n  \\end{equation}\n  by the convention for binomial coefficients in \\cref{def:binomialCoefficient}\n  as $-m < 0$.\n  \n  Note that for the calculation in\n  \\cref{%\n    eq:proofCombiTechniqueIdenticalValues3,%\n    eq:proofCombiTechniqueIdenticalValues4%\n  }\n  to be correct,\n  we have to ensure that $n - \\normone{\\hat{\\*l}} - m \\ge 0$;\n  otherwise, the binomial coefficients would not be well-defined.\n  This is a direct consequence of the fact that $l^\\ast_t < l_t$\n  for all $t = 1, \\dotsc, m$\n  (see \\cref{lemma:combiTechniqueCharacterization}) as\n  \\begin{equation}\n    n - \\normone{\\hat{\\*l}} - m\n    = n - \\sum_{t=1}^m l^\\ast_t - \\sum_{\\mathclap{t=m+1}}^d l_t - m\n    \\ge n - \\sum_{t=1}^m (l_t - 1) - \\sum_{\\mathclap{t=m+1}}^d l_t - m\n    = n - \\normone{\\*l}\n    \\ge 0,\n  \\end{equation}\n  where we have used $l^\\ast_t \\le l_t - 1$ for $t = 1, \\dotsc, m$\n  and $\\normone{\\*l} \\le n$.\n\\end{proof}\n\n\n\n\\fillsubsectionornament\n\\subsection{Correctness Proof of the Method of Residual Interpolation}\n\\label{sec:a132proofResidualInterpolation}\n\n\\propInvariantResidualInterpolation*\n\n\\begin{proof}\n  \\newcommand*{\\eqwithref}[1]{%\n    \\quad\\;%\n    \\if\\relax\\detokenize{#1}\\relax%\n      \\mathclap{=}%\n    \\else%\n      \\mathclap{\\overset{\\eqref{eq:propInvariantResidualInterpolation#1}}{=}}%\n    \\fi%\n    \\quad\\;%\n  }%\n  %\n  We prove the assertion by induction over $j = 1, \\dotsc, m$.\n  We will need the following two equations\n  that directly follow from the algorithm\n  (\\cref{%\n    line:algResidualInterpolation3,%\n    line:algResidualInterpolation2,%\n    line:algResidualInterpolation4%\n  }, respectively):%\n  \\begin{subequations}\n    \\begin{alignat}{3}\n      \\label{eq:propInvariantResidualInterpolation5}\n      r_{\\*l^{(j)}}^{(j-1)}(\\gp{\\*l,\\*i})\n      &= r^{(j-1)}(\\gp{\\*l,\\*i}),\\quad\n      &&\\*l \\le \\*l^{(j)},\\;\\;\n      &&\\*i \\in \\hiset{\\*l},\\\\\n      \\label{eq:propInvariantResidualInterpolation6}\n      r^{(j)}(\\gp{\\*l,\\*i})\n      &= r^{(j-1)}(\\gp{\\*l,\\*i}) - r_{\\*l^{(j)}}^{(j-1)}(\\gp{\\*l,\\*i}),\\quad\n      &&\\*l \\in L,\\;\\;\n      &&\\*i \\in \\hiset{\\*l}.\n    \\end{alignat}\n  \\end{subequations}\n  \n  \\vspace*{-2em}\n  \\pagebreak\n  \n  \\noindent\n  \\textbf{Induction base case:}\n  For $j = 1$, there is nothing to show for\n  \\eqref{eq:propInvariantResidualInterpolation1}.\n  \\Cref{eq:propInvariantResidualInterpolation2}\n  can be proven as follows:\n  \\begin{equation}\n    r^{(1)}(\\gp{\\*l,\\*i})\n    \\eqwithref{6}\n    r^{(0)}(\\gp{\\*l,\\*i}) - r_{\\*l^{(1)}}^{(0)}(\\gp{\\*l,\\*i})\n    \\eqwithref{5} 0,\\qquad\n    \\*l \\le \\*l^{(1)},\\; \\*i \\in \\hiset{\\*l}.\n  \\end{equation}\n  \\Cref{eq:propInvariantResidualInterpolation3}\n  holds as $r_{\\*l^{(1)}}^{(0)} = f^{\\sparse,(1)}$\n  (by \\cref{line:algResidualInterpolation2} in\n  \\cref{alg:residualInterpolation}) and, therefore,\n  \\begin{align}\n    r^{(1)}(\\gp{\\*l,\\*i})\n    \\eqwithref{6}\n    r^{(0)}(\\gp{\\*l,\\*i}) - r_{\\*l^{(1)}}^{(0)}(\\gp{\\*l,\\*i})\n    = \\fcnval{\\*l,\\*i} - f^{\\sparse,(1)}(\\gp{\\*l,\\*i}),\\quad\n    \\*l \\in L,\\; \\*i \\in \\hiset{\\*l}.\n  \\end{align}\n  \n  \\noindent\n  \\textbf{Induction step case:}\n  We show the three statements for the induction step $j \\to (j + 1)$.\n  \\begin{itemize}\n    \\item\n    \\emph{Showing \\eqref{eq:propInvariantResidualInterpolation1} for $j + 1$:}\n    Let $j' = 1, \\dotsc, j$, $\\*l \\le \\*l^{(j')}$,\n    and $\\*i \\in \\hiset{\\*l}$.\n    Due to the ordering of the levels $\\*l^{(1)}, \\dotsc, \\*l^{(m)}$,\n    we can conclude from $j + 1 > j'$ that\n    $\\normone{\\*l^{(j+1)}} \\le \\normone{\\*l^{(j')}}$.\n    This implies that there must be a $t' \\in \\{1, \\dotsc, d\\}$\n    such that $l_{t'}^{(j+1)} \\le l_{t'}^{(j')}$.\n    Let $S$ be the line in $\\real^d$ defined by\n    \\begin{equation}\n      S\n      \\ceq \\gp{\\*l,\\*i} + \\spn\\{\\stdbasis{t'}\\},\n    \\end{equation}\n    where $\\stdbasis{t'}$ is the $t'$-th standard basis vector.\n    It holds that $S \\cap \\fgset{\\*l^{(j+1)}} \\subset \\fgset{\\*l^{(j')}}$.\n    To show this, let $\\gp{\\*l',\\*i'} \\in S \\cap \\fgset{\\*l^{(j+1)}}$\n    be arbitrary (with $\\*i' \\in \\hiset{\\*l'}$).\n    Then, $\\fa{t \\not= t'}{l'_t = l_t \\le l_t^{(j')}}$\n    (due to $\\gp{\\*l',\\*i'} \\in S$) and\n    $l'_{t'} \\le l_{t'}^{(j+1)} \\le l_{t'}^{(j')}$\n    (due to $\\gp{\\*l',\\*i'} \\in \\fgset{\\*l^{(j+1)}}$).\n    This means that $\\*l' \\le \\*l^{(j')}$, which implies that\n    $\\gp{\\*l',\\*i'} \\in \\fgset{\\*l^{(j')}}$.\n    As $\\gp{\\*l',\\*i'}$ is arbitrary,\n    this shows $S \\cap \\fgset{\\*l^{(j+1)}} \\subset \\fgset{\\*l^{(j')}}$.\n    \n    Thus, we infer\n    \\begin{equation}\n      \\label{eq:proofPropInvariantResidualInterpolation2}\n      r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l',\\*i'})\n      \\eqwithref{5}\n      r^{(j)}(\\gp{\\*l',\\*i'})\n      \\eqwithref{2}\n      0,\\quad\n      \\gp{\\*l',\\*i'} \\in S \\cap \\fgset{\\*l^{(j+1)}}\n      \\subset \\fgset{\\*l^{(j')}},\\;\n      i' \\in \\hiset{\\*l'},\n    \\end{equation}\n    with the induction hypothesis\n    \\eqref{eq:propInvariantResidualInterpolation2} for $j$.\n    Unfortunately, this does not suffice to directly conclude that\n    $r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i}) = 0$ as\n    $\\gp{\\*l,\\*i}$ is in general not contained in $\\fgset{\\*l^{(j+1)}}$.\n    \n    As in the proof of \\cref{lemma:combiTechniqueIdenticalValues},\n    we exploit the tensor product nature of the basis functions and\n    restrict $r_{\\*l^{(j+1)}}^{(j)}$ to $S \\cap \\clint{0, 1}$:\n    \\begin{subequations}\n      \\begin{align}\n        (\\restrictfcn{r_{\\*l^{(j+1)}}^{(j)}}{S \\cap \\clint{0, 1}})(x_{t'})\n        &\\mathrel{\\righthphantom{=}{\\ceq}}\n        \\sum_{l'_{t'}=0}^{l_{t'}^{(j+1)}}\n        \\sum_{i'_{t'} \\in \\hiset{l'_{t'}}}\n        \\surplustilde[(j+1)]{l'_{t'},i'_{t'}}\n        \\basis{l'_{t'},i'_{t'}}(x_{t'}),\\quad\n        x_{t'} \\in \\clint{0, 1},\\\\\n        \\surplustilde[(j+1)]{l'_{t'},i'_{t'}}\n        &\\ceq \\sum_{\\*l'_{-t'}=\\*0}^{\\*l^{(j+1)}_{-t'}}\n        \\sum_{\\*i'_{-t'} \\in \\hiset{\\*l'_{-t'}}}\n        \\surplus[(j+1)]{\\*l',\\*i'}\n        \\basis{\\*l'_{-t'},\\*i'_{-t'}}(\\gp{\\*l_{-t'},\\*i_{-t'}}),\n      \\end{align}\n    \\end{subequations}\n    where the subscript $-t'$ indicates all entries but the $t'$-th.\n    As a consequence, this shows that\n    $\\restrictfcn{r_{\\*l^{(j+1)}}^{(j)}}{S \\cap \\clint{0, 1}} \\in\n    \\ns{l_{t'}^{(j+1)}}$ is an interpolant of the zero function\n    (by \\eqref{eq:proofPropInvariantResidualInterpolation2}).\n    Due to the linear independence of the univariate basis functions,\n    we conclude\n    \\begin{equation}\n      \\restrictfcn{r_{\\*l^{(j+1)}}^{(j)}}{S \\cap \\clint{0, 1}}\n      \\equiv 0.\n    \\end{equation}\n    Consequently, we obtain\n    $r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i}) = 0$\n    as $\\gp{\\*l,\\*i} \\in S \\cap \\clint{\\*0, \\*1}$.\n    \n    \\item\n    \\emph{Showing \\eqref{eq:propInvariantResidualInterpolation2} for $j + 1$:}\n    Let $j' = 1, \\dotsc, j + 1$, $\\*l \\le \\*l^{(j')}$,\n    and $\\*i \\in \\hiset{\\*l}$.\n    For the case $j' \\le j$, we obtain\n    \\begin{equation}\n      \\label{eq:proofPropInvariantResidualInterpolation1}\n      r^{(j+1)}(\\gp{\\*l,\\*i})\n      \\eqwithref{6}\n      r^{(j)}(\\gp{\\*l,\\*i}) - r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i})\n      = 0\n    \\end{equation}\n    due to $r^{(j)}(\\gp{\\*l,\\*i}) = 0$ by induction hypothesis\n    (\\cref{eq:propInvariantResidualInterpolation2}) and\n    $r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i}) = 0$ as shown above\n    (\\cref{eq:propInvariantResidualInterpolation1} for $j + 1$).\n    \n    For the case $j' = j + 1$,\n    \\cref{eq:proofPropInvariantResidualInterpolation1}\n    still holds as the difference between\n    $r^{(j)}(\\gp{\\*l,\\*i})$ and $r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i})$\n    vanishes due to \\eqref{eq:propInvariantResidualInterpolation5}\n    for $j + 1$\n    (here, we need $\\*l \\le \\*l^{(j+1)}$).\n    \n    \\item\n    \\emph{Showing \\eqref{eq:propInvariantResidualInterpolation3} for $j + 1$:}\n    Let $\\*l \\in L$ and $\\*i \\in \\hiset{\\*l}$.\n    Then,\n    \\begin{subequations}\n      \\begin{align}\n        r^{(j+1)}(\\gp{\\*l,\\*i})\n        &\\eqwithref{6}\n        r^{(j)}(\\gp{\\*l,\\*i}) - r_{\\*l^{(j+1)}}^{(j)}(\\gp{\\*l,\\*i}).\\\\\n        \\intertext{%\n          The first term can replaced with the induction hypothesis\n          (\\eqref{eq:propInvariantResidualInterpolation3} for $j$).\n          For the second term, note that\n          $r_{\\*l^{(j+1)}}^{(j)}\n          = \\sum_{\\*l' \\in \\levelset} \\sum_{\\*i' \\in \\hiset{\\*l'}}\n          \\surplus[(j+1)]{\\*l',\\*i'} \\basis{\\*l',\\*i'}\n          = f^{\\sparse,(j+1)} - f^{\\sparse,(j)}$ by definition.\n          Hence, we obtain as desired%\n        }\n        \\cdots\n        &\\eqwithref{} (\\fcnval{\\*l,\\*i} - f^{\\sparse,(j)}(\\gp{\\*l,\\*i})) -\n        (f^{\\sparse,(j+1)}(\\gp{\\*l,\\*i}) - f^{\\sparse,(j)}(\\gp{\\*l,\\*i}))\\\\\n        &\\eqwithref{} \\fcnval{\\*l,\\*i} - f^{\\sparse,(j+1)}(\\gp{\\*l,\\*i}).\n      \\end{align}\n    \\end{subequations}\n  \\end{itemize}\n  This shows the validity of the statements in\n  \\eqref{eq:propInvariantResidualInterpolationStatements}\n  for $j + 1$.\n\\end{proof}\n\n\n\n\\subsection{Correctness Proof of Hierarchization with Breadth-First Search}\n\\label{sec:a133proofBFS}\n\n\\propInvariantBFS*\n\n\\begin{proof}\n  We start with two observations:\n  \n  \\begin{itemize}\n    \\item\n    First, due to the breadth-first search nature of \\cref{alg:BFS} and the\n    hierarchical relation \\eqref{eq:directAncestor},\n    all grid points with level sum $< q$ are \\pop{}ped before\n    the first point with level sum $\\ge q$ is \\pop{}ped.\n    \n    \\item\n    Second, after \\pop{}ping all grid points with\n    level sum $< q$, the output values of the grid points with\n    level sum $\\le q$ remain unchanged for the rest of the algorithm:\n    If \\cref{line:algBFS2} of the algorithm updates the output value of a point\n    $(\\*l, \\*i)$ in the iteration of $(\\*l', \\*i') \\in \\liset$ with\n    $\\normone{\\*l'} \\ge q$, then \\cref{line:algBFS1} implies\n    $\\*l \\ge \\*l'$ and thus, $\\normone{\\*l} \\ge \\normone{\\*l'} \\ge q$.\n    However, $\\normone{\\*l} = q$ is not possible as\n    this would imply that $\\normone{\\*l} = \\normone{\\*l'}\n    \\implies (\\*l, \\*i) = (\\*l', \\*i')$ by \\cref{line:algBFS1},\n    but $(\\*l, \\*i) = (\\*l', \\*i')$ is explicitly excluded in the\n    \\texttt{\\algorithmicfor} loop of \\cref{line:algBFS1}.\n    Therefore, we must have $\\normone{\\*l} > q$.\n    Hence, if a point $(\\*l, \\*i)$ with level sum $\\ge q$ has been \\pop{}ped,\n    only surpluses of points with level sum $> q$ may be updated.\n  \\end{itemize}\n  \n  \\noindent\n  Now, we prove the asserted claim by induction over $q$.\n  \n  \\noindent\n  \\textbf{Induction base case:}\n  For $q = 0$, \\cref{alg:BFS} sets $\\linout{\\*l,\\*i}$ to\n  $\\fcnval{\\*l,\\*i}$ in \\cref{line:algBFS3}.\n  As the sum in \\eqref{eq:propInvariantBFS} is empty,\n  the claim is correct for $q = 0$.\n  \n  \\noindent\n  \\textbf{Induction step case:}\n  Let $\\linout[(q)]{\\*l',\\*i'}$ and\n  $\\linout[(q+1)]{\\*l',\\*i'}$\n  be the surpluses after \\pop{}ping all\n  grid points with level sum $< q$ and $< q + 1$, respectively.\n  We show the induction step $q \\to (q + 1)$, i.e.,\n  we assume that the assertion is true for $q$\n  and prove that after \\pop{}ping all grid points with level sum $< q + 1$,\n  it holds\n  \\begin{equation}\n    \\label{eq:proofPropInvariantBFS1}\n    \\linout[(q+1)]{\\*l,\\*i}\n    = \\fcnval{\\*l,\\*i} -\n    \\largesum{\\normone{\\*l'} < q+1} \\linout[(q+1)]{\\*l',\\*i'}\n    \\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i}),\\quad\n    (\\*l, \\*i) \\in \\liset,\\;\\;\n    \\normone{\\*l} = q+1.\n  \\end{equation}\n  Therefore, let $(\\*l, \\*i) \\in \\liset$ fulfill $\\normone{\\*l} = q+1$.\n  The update in \\cref{line:algBFS2} can safely be applied\n  with all grid points $(\\*l', \\*i')$ with level sum $q$.\n  The grid points $(\\*l', \\*i')$ that do not satisfy the relation in the set in\n  \\cref{line:algBFS1} do not contribute as\n  $\\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i}) = 0$\n  due to the necessary condition \\eqref{eq:fundamentalPropertyImplicationMV}.\n  By summing all updates from \\cref{line:algBFS2}, we obtain\n  \\begin{subequations}\n    \\begin{align}\n      \\linout[(q+1)]{\\*l,\\*i}\n      &= \\linout[(q)]{\\*l,\\*i} -\n      \\largesum{\\normone{\\*l'} = q} \\linout[(q)]{\\*l',\\*i'}\n      \\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i}).\\\\\n      \\intertext{%\n        After inserting the induction hypothesis\n        for the first $\\linout[(q)]{\\*l,\\*i}$, we have%\n      }\n      \\cdots\n      &= \\paren*{\n        \\fcnval{\\*l,\\*i} -\n        \\largesum{\\normone{\\*l'} < q} \\linout[(q)]{\\*l',\\*i'}\n        \\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i})\n      } -\n      \\largesum{\\normone{\\*l'} = q} \\linout[(q)]{\\*l',\\*i'}\n      \\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i})\\\\\n      &= \\hphantom{\\Biggl(}\\fcnval{\\*l,\\*i} -\n      \\largesum{\\normone{\\*l'} < q + 1} \\linout[(q)]{\\*l',\\*i'}\n      \\fundbasis{\\*l',\\*i'}(\\gp{\\*l,\\*i}).\n    \\end{align}\n  \\end{subequations}\n  As noted above, we have\n  $\\fa{(\\*l', \\*i'),\\, \\normone{\\*l'} < q + 1}{\n    \\linout[(q)]{\\*l',\\*i'} = \\linout[(q+1)]{\\*l',\\*i'}\n  }$\n  (the values of points with level sum $< q + 1$\n  do not change after \\pop{}ping all points with level sum $< q$).\n  This shows the induction claim \\eqref{eq:proofPropInvariantBFS1}.\n\\end{proof}\n\n\n\n\\disableornamentsfornextheadingtrue\n\\subsection{%\n  Proof for the Correctness of the Unidirectional Principle on\n  Spatially Adaptive Sparse Grids%\n}\n\\label{sec:a134proofCorrectnessUnidirectionalPrincipleSASG}\n\n\\lemmaChainExistenceSufficient*\n\n\\begin{proof}\n  We prove the assertion by induction over $j = 0, \\dotsc, d$.\n  \n  For $j = 0$, the operator $\\upop{\\emptyset}$ is by definition\n  \\eqref{eq:upopProduct} the identity operator $\\idop$.\n  The assumption $(\\upop{\\emptyset})_{\\*k'',\\*k'} \\not= 0$\n  implies that $\\*k' = \\*k''$, since the identity matrix is diagonal.\n  Therefore, the chain $(\\chain{0})$ from $\\*k'$ to $\\*k''$ is given by\n  $\\chain{0} = \\*k'$, which is contained in $\\liset$.\n  \n  For the induction step $j \\to (j+1)$, we split \\cref{eq:upopProduct},\n  i.e.,\n  \\begin{equation}\n    \\upop{t_1,\\dotsc,t_{j+1}}\n    = \\upop{t_{j+1}} \\upop{t_j} \\dotsm \\upop{t_1}\n    = \\upop{t_{j+1}} \\upop{t_1,\\dotsc,t_j},\n  \\end{equation}\n  and infer by assumption\n  \\begin{equation}\n    \\label{eq:proofLemmaChainExistenceSufficient1}\n    0\n    \\not= (\\upop{t_1,\\dotsc,t_{j+1}})_{\\*k'',\\*k'}\n    = \\sum_{\\*k \\in \\liset} (\\upop{t_{j+1}})_{\\*k'',\\*k}\n    (\\upop{t_1,\\dotsc,t_j})_{\\*k,\\*k'}.\n  \\end{equation}\n  Consequently,\n  there is at least one summation index $\\*k$\n  for which both factors do not vanish.\n  The first factor $(\\upop{t_{j+1}})_{\\*k'',\\*k}$ can by definition\n  only be non-zero if $\\*k \\samepole{t_{j+1}} \\*k''$.\n  The second factor $(\\upop{t_1,\\dotsc,t_j})_{\\*k,\\*k'}$ being\n  non-zero implies that by induction hypothesis,\n  $\\liset$ contains the chain $(\\chain{0}, \\dotsc, \\chain{j})$\n  from $\\*k'$ to $\\*k$ with respect to $(t_1, \\dotsc, t_j)$.\n  The combination of both statements leads to\n  the chain $(\\chain{0}, \\dotsc, \\chain{j}, \\chain{j+1})$ from $\\*k'$\n  to $\\*k''$ with respect to $(t_1, \\dotsc, t_{j+1})$.\n  All points of the chain are contained in $\\liset$.\n\\end{proof}\n\n\\lemmaChainExistenceNecessary*\n\n\\begin{proof}\n  Again, we prove the claim by induction over $j = 0, \\dotsc, d$.\n  \n  For $j = 0$, the operator $\\upop{\\emptyset}$ is the identity operator.\n  Therefore, the \\lhs of \\eqref{eq:lemmaChainExistenceNecessary} is one\n  (due to $\\chain{0} = \\*k'$).\n  The \\rhs is by convention also one, as it is an empty product.\n  \n  \\setlength{\\abovedisplayskip}{9pt}%\n  \\setlength{\\belowdisplayskip}{9pt}%\n  For the induction step $j \\to (j+1)$, we consider again\n  \\begin{equation}\n    \\label{eq:proofLemmaChainExistenceNecessary1}\n    (\\upop{t_1,\\dotsc,t_{j+1}})_{\\chain{j+1},\\*k'}\n    = \\sum_{\\*k \\in \\liset} (\\upop{t_{j+1}})_{\\chain{j+1},\\*k}\n    (\\upop{t_1,\\dotsc,t_j})_{\\*k,\\*k'}\n  \\end{equation}%\n  similar to \\eqref{eq:proofLemmaChainExistenceSufficient1}.\n  Recall that\n  \\begin{subequations}\n    \\begin{alignat}{4}\n      \\chainuv{j}_t\n      &= k''_t\n      &&\\;\\;\\text{and}\\;\\;\n      &\\chainuv{j+1}_t\n      &= k''_t\n      &&\\quad\\text{for } t \\in \\{t_1, \\dotsc, t_j\\},\\\\\n      \\label{eq:prooflemmaChainExistenceNecessary}\n      \\chainuv{j}_t\n      &= k'_t\n      &&\\;\\;\\text{and}\\;\\;\n      &\\chainuv{j+1}_t\n      &= k''_t\n      &&\\quad\\text{for } t = t_{j+1},\\\\\n      \\chainuv{j}_t\n      &= k'_t\n      &&\\;\\;\\text{and}\\;\\;\n      &\\chainuv{j+1}_t\n      &= k'_t\n      &&\\quad\\text{for } t \\notin \\{t_1, \\dotsc, t_j, t_{j+1}\\}.\n    \\end{alignat}\n  \\end{subequations}\n  We now argue that all summands of\n  \\eqref{eq:proofLemmaChainExistenceNecessary1} vanish,\n  except the summand with index $\\chain{j}$.\n  There are two cases for the summation index $\\*k$,\n  if we assume $\\*k \\not= \\chain{j}$:\n  \\begin{itemize}\n    \\item\n    If there is a $t \\in \\{t_1, \\dotsc, t_j\\}$ with $k_t \\not= k''_t$,\n    then we have $k_t \\not= k''_t = \\chainuv{j+1}_t$.\n    Consequently, $\\chain{j+1} \\not\\samepole{t_{j+1}} \\*k$ and\n    $(\\upop{t_{j+1}})_{\\chain{j+1},\\*k} = 0$ due to \\eqref{eq:upopEntries},\n    i.e., the first factor of the $\\*k$-th summand in\n    \\eqref{eq:proofLemmaChainExistenceNecessary1} vanishes.\n    \n    \\item\n    If there is a $t \\notin \\{t_1, \\dotsc, t_j\\}$ with $k_t \\not= k'_t$,\n    then the second factor $(\\upop{t_1,\\dotsc,t_j})_{\\*k,\\*k'}$\n    of the $\\*k$-th summand in\n    \\eqref{eq:proofLemmaChainExistenceNecessary1} vanishes.\n    Indeed, if we assume the contrary,\n    then \\cref{lemma:chainExistenceSufficient} implies that there is\n    a chain from $\\*k'$ to $\\*k$ with respect to $(t_1, \\dotsc, t_j)$.\n    However, by definition of the chain, this means that\n    $\\*k'$ and $\\*k$ coincide in all other dimensions\n    (which are not in $\\{t_1, \\dotsc, t_j\\}$).\n    This contradicts $k_t \\not= k'_t$ and therefore\n    $(\\upop{t_1,\\dotsc,t_j})_{\\*k,\\*k'}$ must vanish.\n  \\end{itemize}\n  We infer that only the summand $\\*k = \\chain{j}$ remains in\n  \\eqref{eq:proofLemmaChainExistenceNecessary1}:\n  \\begin{equation}\n    (\\upop{t_1,\\dotsc,t_{j+1}})_{\\chain{j+1},\\*k'}\n    = (\\upop{t_{j+1}})_{\\chain{j+1},\\chain{j}}\n    (\\upop{t_1,\\dotsc,t_j})_{\\chain{j},\\*k'}.\n  \\end{equation}\n  The first factor equals\n  \\begin{equation}\n    (\\upop{t_{j+1}})_{\\chain{j+1},\\chain{j}}\n    = (\\upopuv{t_{j+1}}{\\eqclass{\\chain{j+1}}{\\samepole{t_{j+1}}}})%\n    _{\\chainuv{j+1}_{t_{j+1}},\\chainuv{j}_{t_{j+1}}}\n    = (\\upopuv{t_{j+1}}{\\eqclass{\\chain{j+1}}{\\samepole{t_{j+1}}}})%\n    _{k''_{t_{j+1}},k'_{t_{j+1}}}\n  \\end{equation}\n  by \\cref{eq:upopEntries,eq:prooflemmaChainExistenceNecessary}\n  (and due to $\\chain{j} \\samepole{t_{j+1}} \\chain{j+1}$).\n  The second factor equals\n  \\begin{equation}\n    (\\upop{t_1,\\dotsc,t_j})_{\\chain{j},\\*k'}\n    =\n    (\\upopuv{t_1}{\\eqclass{\\chain{1}}{\\samepole{t_1}}})_{k''_{t_1},k'_{t_1}}\n    \\dotsm\n    (\\upopuv{t_j}{\\eqclass{\\chain{j}}{\\samepole{t_j}}})_{k''_{t_j},k'_{t_j}}\n  \\end{equation}\n  by induction hypothesis.\n  Hence, the product of both factors is\n  \\begin{equation}\n    (\\upop{t_1,\\dotsc,t_{j+1}})_{\\chain{j+1},\\*k'}\n    =\n    (\\upopuv{t_1}{\\eqclass{\\chain{1}}{\\samepole{t_1}}})_{k''_{t_1},k'_{t_1}}\n    \\dotsm\n    (\\upopuv{t_{j+1}}{\\eqclass{\\chain{j+1}}{\\samepole{t_{j+1}}}})%\n    _{k''_{t_{j+1}},k'_{t_{j+1}}}.\n    \\vspace*{-2.5em}\n  \\end{equation}\n\\end{proof}\n\n\\vspace*{1em}\n\\pagebreak\n\n\\propCorrectnessUPCharacterization*\n\n\\begin{proof}\n  ``$\\implies$'':\n  Let the \\up be correct for $\\linop$ and $(t_1, \\dotsc, t_d)$\n  and $\\*k', \\*k'' \\in \\liset$ with $(\\linop)_{\\*k'',\\*k'} \\not= 0$.\n  Then, we obtain\n  \\begin{equation}\n    (\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'}\n    = (\\linop)_{\\*k'',\\*k'}\n    \\not= 0.\n  \\end{equation}\n  By \\cref{lemma:chainExistenceSufficient},\n  this implies that $\\liset$ contains the chain from $\\*k'$ to $\\*k''$\n  with respect to $(t_1, \\dotsc, t_d)$.\n  \n  ``$\\impliedby$'':\n  For the converse direction, we assume that there are chains\n  from $\\*k'$ to $\\*k''$ with respect to $(t_1, \\dotsc, t_d)$\n  for all $\\*k', \\*k'' \\in \\liset$ with $(\\linop)_{\\*k'',\\*k'} \\not= 0$.\n  Let $\\*k', \\*k'' \\in \\liset$ be arbitrary.\n  There are two cases:\n  \\begin{itemize}\n    \\item\n    ${(\\linop)_{\\*k'',\\*k'} \\not= 0}$:\n    By assumption, $\\liset$ contains the chain from $\\*k'$ to $\\*k''$\n    with respect to $(t_1, \\dotsc, t_d)$.\n    We apply \\cref{lemma:chainExistenceNecessary} with $j = d$\n    to infer\n    \\begin{equation}\n      (\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'}\n      =\n      (\\upopuv{t_1}{\\eqclass{\\chain{1}}{\\samepole{t_1}}})_{k''_{t_1},k'_{t_1}}\n      \\dotsm\n      (\\upopuv{t_d}{\\eqclass{\\chain{d}}{\\samepole{t_d}}})_{k''_{t_d},k'_{t_d}}\n      = (\\linop)_{\\*k'',\\*k'}\n    \\end{equation}\n    by the assumption \\eqref{eq:tensorProductOperator} on\n    the tensor product structure of $\\linop$.\n    \n    \\item\n    ${(\\linop)_{\\*k'',\\*k'} = 0}$:\n    In this case, $(\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'}$ must vanish as well.\n    Indeed, if we assume the contrary\n    $(\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'} \\not= 0$,\n    then we can apply \\cref{lemma:chainExistenceSufficient}\n    to obtain that $\\liset$ contains the chain from $\\*k'$ to $\\*k''$\n    with respect to $(t_1, \\dotsc, t_d)$.\n    We conclude with \\cref{lemma:chainExistenceNecessary} as in the first case\n    that $(\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'} = (\\linop)_{\\*k'',\\*k'} = 0$,\n    which is a contradiction.\n  \\end{itemize}\n  In any case, we obtain\n  $(\\upop{t_1,\\dotsc,t_d})_{\\*k'',\\*k'} = (\\linop)_{\\*k'',\\*k'}$,\n  from which follows the correctness of the \\up\\punctfix{,}\n  as $\\*k'$ and $\\*k''$ are arbitrary.\n\\end{proof}\n\n\n\n\\breakpagebeforenextheadingtrue\n\\subsection{Correctness Proof of Hermite Hierarchization}\n\\label{sec:a135proofHermiteHierarchization}\n\n\\propInvariantHermiteHierarchization*\n\n\\begin{proof}\n  We prove the assertion by induction over $l = 0, \\dotsc, n$.\n  \n  For the induction base case $l = 0$ and $i \\in \\{0, 1\\}$, we have\n  \\begin{equation}\n    \\sum_{i'=0}^1\n    \\linout{0,i'} \\deriv[q]{x}{\\bspl[\\wfs]{0,i'}{p}}(\\gp{0,i})\n    = \\kronecker{q}{0} \\cdot \\fcnval{0,i} +\n    \\kronecker{q}{1} \\cdot (\\fcnval{0,1} - \\fcnval{0,0})\n    = \\deriv[q]{x}{\\fgintp{0}}(\\gp{0,i})\n  \\end{equation}\n  for $q = 0, \\dotsc, \\frac{p-1}{2}$ by\n  \\cref{%\n    line:algHermiteHierarchization1,%\n    line:algHermiteHierarchization3%\n  }\n  of \\cref{alg:hermiteHierarchization}.\n  \n  For the induction step case $(l-1) \\to l$,\n  it suffices to show that\n  \\begin{equation}\n    \\label{eq:proofPropInvariantHermiteHierarchization1}\n    \\deriv[q]{x}{\\fgintp{l-1}}(\\gp{l,i})\n    \\overset{!}{=} \\sum_{l'=0}^{l-1} \\sum_{i' \\in \\hiset{l'}}\n    \\linout{l',i'} \\deriv[q]{x}{\\bspl[\\wfs]{l',i'}{p}}(\\gp{l,i}),\\quad\n    i = 0, \\dotsc, 2^l,\\;\\;\n    q = 0, \\dotsc, \\frac{p-1}{2}.\n  \\end{equation}\n  Indeed, if \\eqref{eq:proofPropInvariantHermiteHierarchization1} holds,\n  then we obtain by\n  \\cref{line:algHermiteHierarchization6,line:algHermiteHierarchization8}\n  of \\cref{alg:hermiteHierarchization}\n  \\begin{subequations}\n    \\begin{align}\n      \\deriv[q]{x}{\\fgintp{l}}(\\gp{l,i})\n      &= \\deriv[q]{x}{\\fgintp{l-1}}(\\gp{l,i}) +\n      \\deriv[q]{x}{r^{(l)}_l}(\\gp{l,i})\\\\\n      &= \\sum_{l'=0}^{l-1} \\sum_{i' \\in \\hiset{l'}}\n      \\linout{l',i'} \\deriv[q]{x}{\\bspl[\\wfs]{l',i'}{p}}(\\gp{l,i}) +\n      \\sum_{i' \\in \\hiset{l}}\n      \\linout{l,i'} \\deriv[q]{x}{\\bspl[\\wfs]{l,i'}{p}}(\\gp{l,i})\\\\\n      &= \\sum_{l'=0}^l \\sum_{i' \\in \\hiset{l'}}\n      \\linout{l',i'} \\deriv[q]{x}{\\bspl[\\wfs]{l',i'}{p}}(\\gp{l,i}),\n    \\end{align}\n  \\end{subequations}\n  which is the desired relation\n  \\eqref{eq:propInvariantHermiteHierarchization}\n  for level $l$.\n  \n  To prove \\eqref{eq:proofPropInvariantHermiteHierarchization1},\n  we separate two cases:\n  \\begin{itemize}\n    \\item\n    \\mbox{${i \\notin \\hiset{l}}$: In this case,}\n    the ``true'' level of $\\gp{l,i}$ is actually $\\le l - 1$.\n    Therefore, we can apply the induction hypothesis\n    for \\cref{eq:propInvariantHermiteHierarchization} to\n    obtain \\eqref{eq:proofPropInvariantHermiteHierarchization1}.\n    \n    \\item\n    \\mbox{${i \\in \\hiset{l}}$: In this case,}\n    we cannot directly apply the induction hypothesis,\n    as it only holds for grid points of levels $\\le l - 1$.\n    However, we note that in\n    \\eqref{eq:proofPropInvariantHermiteHierarchization1},\n    the term $\\deriv[q]{x}{\\fgintp{l-1}}(\\gp{l,i})$\n    is the $q$-th derivative of the Hermite interpolant of\n    the data $\\deriv[q']{x}{\\fgintp{l-1}}(\\gp{l,i\\pm1})$\n    ($q' = 0, \\dotsc, \\frac{p-1}{2}$),\n    as determined in \\cref{line:algHermiteHierarchization4}\n    of \\cref{alg:hermiteHierarchization}.\n    The ``true'' level of the grid points $\\gp{l,i\\pm1}$ is\n    actually $\\le l - 1$ due to $i \\in \\hiset{l}$.\n    Hence, we can apply the induction hypothesis\n    for \\cref{eq:propInvariantHermiteHierarchization}\n    to conclude that the interpolated data of\n    $\\deriv[q]{x}{\\fgintp{l-1}}(\\gp{l,i})$ are given by\n    \\begin{equation}\n      \\deriv[q']{x}{\\fgintp{l-1}}(\\gp{l,i\\pm1})\n      = \\deriv[q']{x}{\n        \\bracket*{\n          \\sum_{l'=0}^{l-1} \\sum_{i' \\in \\hiset{l'}}\n          \\linout{l',i'} \\bspl[\\wfs]{l',i'}{p}\n        }\n      }(\\gp{l,i\\pm1}),\\quad\n      q' = 0, \\dotsc, \\frac{p-1}{2}.\n    \\end{equation}\n    The linear combination in square brackets\n    is a polynomial of degree $\\le p$ on the interval\n    $\\clint{\\gp{l,i-1}, \\gp{l,i+1}}$\n    by construction of the hierarchical basis functions\n    $\\bspl[\\wfs]{l',i'}{p}$ ($l' = 0, \\dotsc, l - 1$, $i' \\in \\hiset{l'}$).\n    Due to the uniqueness of Hermite interpolation\n    (\\cref{lemma:hermiteInterpolation}),\n    the interpolation polynomial of the data must\n    coincide on $\\clint{\\gp{l,i-1}, \\gp{l,i+1}}$\n    with the term in square brackets.\n    In particular, as $\\gp{l,i} \\in \\clint{\\gp{l,i-1}, \\gp{l,i+1}}$,\n    we obtain the claim \\eqref{eq:proofPropInvariantHermiteHierarchization1}.\n  \\end{itemize}\n  In both cases, we obtain the desired relation\n  \\eqref{eq:proofPropInvariantHermiteHierarchization1}.\n\\end{proof}\n\n\\corAlgHermiteHierarchizationCorrectness*\n\n\\begin{proof}\n  By \\cref{prop:invariantHermiteHierarchization} ($q = 0$), we have\n  \\begin{equation}\n    \\sum_{l'=0}^n \\sum_{i' \\in \\hiset{l'}}\n    \\linout{l',i'} \\bspl[\\wfs]{l',i'}{p}(\\gp{l,i})\n    = \\sum_{l'=0}^l \\sum_{i' \\in \\hiset{l'}}\n    \\linout{l',i'} \\bspl[\\wfs]{l',i'}{p}(\\gp{l,i})\n    = \\fgintp{l}(\\gp{l,i}),\\quad\n    l \\le n,\\; i \\in \\hiset{l},\n  \\end{equation}\n  as $\\bspl[\\wfs]{l',i'}{p}(\\gp{l,i}) = 0$ if $l' > l$\n  (weakly fundamental property \\eqref{eq:weaklyFundamentalProperty}).\n  \\Cref{line:algHermiteHierarchization8} of\n  \\cref{alg:hermiteHierarchization} implies\n  $\\fgintp{l}(\\gp{l,i})\n  = \\fgintp{l-1}(\\gp{l,i}) + r^{(l)}_l(\\gp{l,i})$, and by\n  \\cref{line:algHermiteHierarchization5,line:algHermiteHierarchization7},\n  the second summand $r^{(l)}_l(\\gp{l,i})$ equals\n  $\\fcnval{l,i} - \\fgintp{l-1}(\\gp{l,i})$,\n  which cancels out the first summand, resulting in\n  $\\fgintp{l}(\\gp{l,i}) = \\fcnval{l,i}$.\n  Combining these statements, we obtain\n  \\begin{equation}\n    \\sgintp(\\gp{l,i})\n    = \\fcnval{l,i},\\quad\n    l \\le n,\\; i \\in \\hiset{l},\n    \\quad\\text{where}\\quad\n    \\sgintp\n    \\ceq \\sum_{l'=0}^n \\sum_{i' \\in \\hiset{l'}}\n    \\linout{l',i'} \\bspl[\\wfs]{l',i'}{p}.\n  \\end{equation}\n  This means that $\\sgintp$ is the correct hierarchical interpolant\n  of the given function values\n  (see \\cref{eq:hierarchizationInterpolant}).\n  Due to the uniqueness of hierarchical surpluses,\n  the coefficients $\\linout{l,i}$\n  (which are the output of \\cref{alg:hermiteHierarchization})\n  must coincide with the surpluses $\\surplus{l,i}$.\n\\end{proof}\n", "meta": {"hexsha": "579ec9f115333d449830a070e3143e8707c34ef9", "size": 43710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/a13chapter4.tex", "max_stars_repo_name": "valentjn/thesis-arxiv", "max_stars_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-12T09:28:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:07:17.000Z", "max_issues_repo_path": "tex/document/a13chapter4.tex", "max_issues_repo_name": "valentjn/thesis-arxiv", "max_issues_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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/a13chapter4.tex", "max_forks_repo_name": "valentjn/thesis-arxiv", "max_forks_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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.5838349097, "max_line_length": 80, "alphanum_fraction": 0.5723861817, "num_tokens": 17689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6277835000895631}}
{"text": "%!TEX root = ../TTK18-Summary.tex\n\\section{Linear matrix inequalities for piecewise affine systems}\n\n\\subsection{Piecewise affine systems}\nA piecewise affine system is a system where the state space $X$ is divided into non-overlapping partitions $X_i$ with distinct models in each partition:\n%\n\\begin{itemize}\n  \\item Partitions containing the origin are linear:\n  \\begin{equation}\n    \\begin{split}\n      x &= A_i x \\\\\n      x_{k+1} &= A_i x_k\n    \\end{split}\n  \\end{equation}\n  \\item Partitions not containing the origin are affine:\n  \\begin{equation}\n    \\begin{split}\n      x &= A_i x + a_i \\\\\n      x_{k+1} &= A_i x_k + a_i\n    \\end{split}\n  \\end{equation}\n\\end{itemize}\n%\nThe partitions are indexed, with an index set\n%\n\\begin{equation}\n  I = I_0 \\cup I_1\n\\end{equation}\n%\nwhere $I_0$ are the parititions containing the origin, and $I_1$ are the partitions not containing the origin.\n\n\\subsection{Lyapunov stability}\nSometimes you can find a Lyapunov function for the whole PWA system:\n%\n\\begin{itemize}\n  \\item If $a_i = 0 \\forall i$ and there exists a $P = P^T > 0$ such that\n  \\begin{equation}\n    A_i^T P + P A_i < 0 \\quad \\forall i \\in I,\n  \\end{equation}\n  then the origin is exponentially stable.\n  \\item If $a_i = 0 \\forall i$ and there exists an $R_i > 0 \\forall i \\in I$ such that\n  \\begin{equation}\n    \\sum_{i \\in I} (A_i^T R_i + R_i A_i) > 0,\n  \\end{equation}\n  then a common Lyapunov function can be found.\n\\end{itemize}\n%\nWhen a common function cannot be found, we must look for one that depends on the partition.\n\n\\subsubsection{Notation}\n\\begin{equation}\n  \\bar{A}_i = \\begin{bmatrix} A_i & a_i \\\\ 0 & 0 \\end{bmatrix}\n\\end{equation}\n%\nEach partition is a polyhedron, so we can write\n%\n\\begin{equation}\n  \\bar{E}_i = \\begin{bmatrix} E_i & e_i \\end{bmatrix}, \\quad\n  \\bar{F}_i = \\begin{bmatrix} F_i & f_i \\end{bmatrix}\n\\end{equation}\n%\nwhere $e_i = 0$ and $f_i = 0$ for all $i \\in I_0$ such that\n%\n\\begin{gather}\n  \\bar{E}_i \\begin{bmatrix} x \\\\ 1 \\end{bmatrix} \\geq 0 \\quad \\forall x \\in X_i \\forall i \\in I \\\\\n  \\bar{F}_i \\begin{bmatrix} x \\\\ 1 \\end{bmatrix} = \\bar{F}_j \\begin{bmatrix} x \\\\ 1 \\end{bmatrix} \\quad \\forall\\; x \\in X_i \\cap X_j, \\forall i, j \\in I\n\\end{gather}\n%\nThat is, $E_i x + e_i \\geq 0$ for all values of $x$, and $F_i x + f_i = F_j x + f_j$ for all $x$ along borders between partitions.\n\n\\subsubsection{Lyapunov function}\n\\begin{equation}\n  V(x) =\n  \\begin{cases}\n    x\\tp P_i x, &x \\in X_i, i \\in I_0 \\\\\n    \\bmat{x\\\\1}\\tp \\bar{P}_i \\bmat{x\\\\1}, &x \\in X_i, i \\in I_1\n  \\end{cases}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\\label{eq:pwa-lyapunov-matrix}\n    P_i = F_i^T T F_i,\\quad \\bar{P}_i = \\bar{F}_i^T T \\bar{F}_i\n\\end{equation}\n%\nand $T$ is some symmetric matrix with positive elements.\n\n\\subsubsection{Relaxing the LF}\nWhile $V(x) > 0$ is required for all $x$, we only need $P_i > 0$ for $x \\in X_i$. The S-procedure can be used to alter the LF to reflect this:\n%\n\\begin{equation}\n  V(x) =\n  \\begin{cases}\n    x\\tp E_i\\tp U_i E_i x, &x \\in X_i, i \\in I_0 \\\\\n    \\begin{bmatrix} x \\\\ 1 \\end{bmatrix}\\tp\n    \\bar{E}_i\\tp U_i \\bar{E}_i\\tp\n    \\begin{bmatrix} x \\\\ 1 \\end{bmatrix}, &x \\in X_i, i \\in I_1\n  \\end{cases}\n\\end{equation}\n%\nwhere $U_i$ has only non-negative elements. The condition $\\dot{V}(x)<0$ only needs to hold within each partition, as well.\n\n\\subsubsection{Overall LF design}\nFind symmetric matrices $T$, $U_i$, $W_i$ ($U_i$ and $W_i$ with no negative elements), such that\n%\n\\begin{equation}\n  \\begin{split}\n    \\begin{rcases}\n      A_i\\tp P_i + P_i A_i + E_i\\tp U_i E_i < 0 \\\\\n      P_i - E_i\\tp W_i E_i > 0\n    \\end{rcases} &i \\in I_0 \\\\\n    \\begin{rcases}\n      \\bar{A}_i\\tp \\bar{P}_i + \\bar{P}_i \\bar{A}_i + \\bar{E}_i\\tp U_i \\bar{E}_i < 0 \\\\\n      \\bar{P}_i - \\bar{E}_i\\tp W_i \\bar{E}_i > 0\n    \\end{rcases} &i \\in I_1\n  \\end{split}\n\\end{equation}\n%\nwith \\eqref{eq:pwa-lyapunov-matrix} still holding:\n%\n\\begin{equation}\n  P_i = F_i^T T F_i,\\quad \\bar{P}_i = \\bar{F}_i^T T \\bar{F}_i\n\\end{equation}\n\n$\\bar{E}_i$ and $\\bar{F}_i$ can be determined e.g. with explicit formulas found in papers by Johansson and Ratzer.\n\n\\subsection{Discrete-time Lyapunov stability}\nWith discrete systems\n%\n\\begin{itemize}\n  \\item we don't need a continuous LF,\n  \\item we use LF difference rather than LF differential,\n  \\item we must keep track of possible next-timestep partitions.\n\\end{itemize}\n\nIf there exists matrices $R_i > 0$ such that\n%\n\\begin{equation}\n  \\sum_{i \\in I} (A_i\\tp R_i A_i - R_I) > 0\n\\end{equation}\n%\nthen no common LF can be found for the PWL system.\n\n\\subsubsection{Stability criteria}\n$f(X_i)$ is a quadratic function positive on $X_i$, such as\n%\n\\begin{equation}\n  f(X_i) =\n  \\begin{cases}\n    x\\tp E_i\\tp U_i E_i x, & x \\in I_0 \\\\\n    \\bsmat{x \\\\ 1}\\tp \\bar{E}_i\\tp U_i \\bar{E}_i \\bsmat{x \\\\ 1}, & x \\in I_1\n  \\end{cases}\n\\end{equation}\n\nRewrite the system\n%\n\\begin{equation}\n  \\bar{x} = \\bmat{x \\\\ 1}, \\quad \\bar{x}_{k+1} = \\bar{A}_i \\bar{x}_k\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  \\bar{A}_i =\n  \\begin{cases}\n    \\bmat{A_i & a_i \\\\ 0 & 1},&\n    \\underbrace{x_k \\in X_i, i \\in I_1, x_{k+1} \\in X_j, j \\in I_1}\n              _{x \\text{ moving between } I_1 \\text{ partitions}} \\\\\n    \\bmat{A_i & a_i \\\\ 0 & 0},&\n    \\underbrace{x_k \\in X_i, i \\in I_1, x_{k+1} \\in X_j, j \\in I_0}\n              _{x \\text{ moving from } I_1 \\text{ to } I_0 \\text{ partition}} \\\\\n    \\bmat{A_i & 0 \\\\ 0 & 0},&\n    \\underbrace{x_k \\in X_i, i \\in I_0, x_{k+1} \\in X_j, j \\in I_0}\n              _{x \\text{ moving between } I_0 \\text{ partitions}}.\n  \\end{cases}\n\\end{equation}\n%\nThis formulation requires that $\\cup_{i \\in I_0} X_i$ is positively invariant.\\footnote{All trajectories in the set never leave it.} The system is then stable if\n%\n\\begin{equation}\n  \\begin{split}\n    P_i - f(X_i) > 0,\\quad & \\forall i \\\\\n    P_i - \\bar{A}_i\\tp P_j \\bar{A}_i - f(X_{ij}) > 0,\\quad & \\forall (i,j) \\mbox{ with nonempty } X_{ij}\n  \\end{split}\n\\end{equation}\n%\nwhere $X_{ij} \\subset X_i$ is the region where the state in the next timestep will move to $X_j$.\n\n\\subsubsection{Relaxations}\n$R$ is a bounded polyhedron and $V(R)$ is its vertice set. Then this function is quadratic and positive over $R$:\n\\begin{equation}\n  f(R) = \\bsmat{x \\\\ 1}\\tp H \\bsmat{x \\\\ 1}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  \\begin{split}\n    H &= \\bar{H} + C \\\\\n    \\bar{H} &< 0 \\\\\n    C &= \\bsmat{0 & 0 \\\\ 0 & c} \\\\\n    c &> 0 \\\\\n    \\bsmat{v_i \\\\ 1}\\tp (\\bar{H} + C) \\bsmat{v_i \\\\ 1} &> 0,\\quad \\forall v_i \\in V(R)\n  \\end{split}\n\\end{equation}\n", "meta": {"hexsha": "3e11d3963860e45bf96c6a3fe419932dfdd5efb6", "size": 6483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-lmis-for-pwa.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-lmis-for-pwa.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-lmis-for-pwa.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": 31.4708737864, "max_line_length": 161, "alphanum_fraction": 0.6399814901, "num_tokens": 2480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926009, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.627783492326325}}
{"text": "\\documentstyle[11pt,reduce]{article}\n\\title{{\\tt TRIGSIMP}\\\\\nA REDUCE Package for the Simplification and Factorization of Trigonometric\nand Hyperbolic Functions}\n\\date{}\n\\author{Wolfram Koepf\\\\\n        Andreas Bernig\\\\\n        Herbert Melenk\\\\\n        ZIB Berlin \\\\\n        email: {\\tt  Koepf@ZIB-Berlin.de}}\n\\begin{document}\n\\maketitle\n\\section{Introduction}\n\nThe REDUCE package TRIGSIMP is a useful tool for all kinds of trigonometric and\nhyperbolic simplification and factorization. There are three\nprocedures included in TRIGSIMP: trigsimp, trigfactorize and triggcd. \nThe first is for finding simplifications of trigonometric or \nhyperbolic expressions with many options, the second for factorizing \nthem and the third \nfor finding the greatest common divisor of two trigonometric or \nhyperbolic polynomials.\n\nTo start the package it must be loaded by:\n{\\small\n\\begin{verbatim}\n1: load trigsimp;\n\\end{verbatim}\n}\\noindent\n\n\\section{\\REDUCE{} operator {\\tt trigsimp}}\n\nAs there is no normal form for trigonometric and hyperbolic functions, the same \nfunction can convert in many different directions, e.g. \n$\\sin(2x) \\leftrightarrow 2\\sin(x)\\cos(x)$. \nThe user has the possibility to give several parameters to the \nprocedure {\\tt trigsimp} in order to influence the direction of transformations. \nThe decision whether a rational expression in trigonometric \nand hyperbolic functions vanishes or not is possible.\n\nTo simplify a function {\\tt f}, one uses {\\tt trigsimp(f[,options])}. Example:\n{\\small\n\\begin{verbatim}\n2: trigsimp(sin(x)^2+cos(x)^2);\n\n1\n\\end{verbatim}\n}\\noindent\n\nPossible options are (* denotes the default):\n\\begin{enumerate}\n\\item {\\tt sin} (*) or {\\tt cos}\n\\item {\\tt sinh} (*) or {\\tt cosh}\n\\item {\\tt expand} (*) or {\\tt combine} or {\\tt compact}\n\\item {\\tt hyp} or {\\tt trig} or {\\tt expon}\n\\item {\\tt keepalltrig}\n\\end{enumerate}\n\nFrom each group one can use at most one option, otherwise an error \nmessage will occur. The first group fixes the preference used while \ntransforming a trigonometric expression:\n{\\small\n\\begin{verbatim}\n3: trigsimp(sin(x)^2);\n\n      2\nsin(x)\n\n4: trigsimp(sin(x)^2,cos);\n\n         2\n - cos(x)  + 1\n\\end{verbatim}\n}\\noindent\n\nThe second group is the equivalent for the hyperbolic functions. \nThe third group determines the type of transformations. With \nthe default {\\tt expand}, an expression is written in a form only using \nsingle arguments and no sums of arguments:\n{\\small\n\\begin{verbatim}\n5: trigsimp(sin(2x+y));\n\n                                 2\n2*cos(x)*cos(y)*sin(x) - 2*sin(x) *sin(y) + sin(y)\n\\end{verbatim}\n}\\noindent\n\nWith {\\tt combine}, products of trigonometric functions are transformed to \ntrigonometric functions involving sums of arguments:\n{\\small\n\\begin{verbatim}\n6: trigsimp(sin(x)*cos(y),combine);\n\n        \n sin(x - y) + sin(x + y)\n-------------------------\n            2\n\\end{verbatim}\n}\\noindent\n\nWith {\\tt compact}, the REDUCE operator {\\tt compact} \\cite{hearns}\nis applied to {\\tt f}. \nThis leads often to a simple form, but in contrast to {\\tt expand} one \ndoesn't get a normal form. Example for {\\tt compact}:\n{\\small\n\\begin{verbatim}\n7: trigsimp((1-sin(x)**2)**20*(1-cos(x)**2)**20,compact);\n\n      40       40\ncos(x)  *sin(x)\n\\end{verbatim}\n}\\noindent\n\nWith the fourth group each expression is transformed to a\ntrigonometric, hyperbolic or exponential form:\n{\\small\n\\begin{verbatim}\n8: trigsimp(sin(x),hyp);\n\n - sinh(i*x)*i\n\n9: trigsimp(sinh(x),expon);\n        \n  2*x\n e    - 1\n----------\n      x\n   2*e\n\n10: trigsimp(e^x,trig);\n\n     x          x\ncos(---) + sin(---)*i\n     i          i\n\\end{verbatim}\n}\\noindent \n\nUsually, {\\tt tan}, {\\tt cot}, {\\tt sec}, {\\tt csc} are expressed in terms of\n{\\tt sin} and {\\tt cos}. It can \nbe sometimes useful to avoid this, which is handled by the option \n{\\tt keepalltrig}:\n{\\small\n\\begin{verbatim}\n11: trigsimp(tan(x+y),keepalltrig);\n\n  - (tan(x) + tan(y))\n----------------------\n  tan(x)*tan(y) - 1\n\\end{verbatim}\n}\\noindent\n\nIt is possible to use the options of different groups simultaneously:\n{\\small\n\\begin{verbatim}\n12: trigsimp(sin(x)**4,cos,combine);\n\n cos(4*x) - 4*cos(2*x) + 3\n---------------------------\n             8\n\\end{verbatim}\n}\\noindent\n\nSometimes, it is necessary to handle an expression in different steps:\n{\\small\n\\begin{verbatim}\n13: trigsimp((sinh(x)+cosh(x))**n+(cosh(x)-sinh(x))**n,expon);\n\n  2*n*x\n e      + 1\n------------\n     n*x\n    e \n \n14: trigsimp(ws,hyp);\n\n2*cosh(n*x)\n\n15: trigsimp((cosh(a*n)*sinh(a)*sinh(p)+cosh(a)*sinh(a*n)*sinh(p)+ \n    sinh(a - p)*sinh(a*n))/sinh(a));\n\ncosh(a*n)*sinh(p) + cosh(p)*sinh(a*n)\n\n16: trigsimp(ws,combine);\n\nsinh(a*n + p)\n\\end{verbatim}\n}\\noindent\n\n\\section{\\REDUCE{} operator {\\tt trigfactorize}}\n\nWith {\\tt trigfactorize(p,x)} one can factorize the trigonometric or \nhyperbolic polynomial {\\tt p} with respect to the argument x. Example:\n{\\small\n\\begin{verbatim}\n17: trigfactorize(sin(x),x/2); \n\n        x        x\n{2,cos(---),sin(---)}\n        2        2\n\\end{verbatim}\n}\\noindent\n\nIf the polynomial is not coordinated or balanced \\cite{art}, \nthe output will equal the input.\nIn this case, changing the value for x can help to find a factorization:\n{\\small\n\\begin{verbatim}\n18: trigfactorize(1+cos(x),x);\n\n{cos(x) + 1}\n\n19: trigfactorize(1+cos(x),x/2); \n\n        x        x\n{2,cos(---),cos(---)}\n        2        2\n\\end{verbatim}\n}\\noindent\n\nThe polynomial can consist of both trigonometric and hyperbolic functions:\n{\\small\n\\begin{verbatim}\n20: trigfactorize(sin(2x)*sinh(2x),x);\n\n{4, cos(x), sin(x), cosh(x), sinh(x)}\n\\end{verbatim}\n}\\noindent\n\n\\section{\\REDUCE{} operator {\\tt triggcd}}\n\nThe operator {\\tt triggcd} is an application of {\\tt trigfactorize}. \nWith its help the user can find the greatest common divisor of two \ntrigonometric or hyperbolic polynomials. It uses the method described \nin \\cite{art}. The syntax is: {\\tt triggcd(p,q,x)}, where p and q \nare the polynomials and x is the smallest unit to use. Example:\n\n{\\small\n\\begin{verbatim}\n21: triggcd(sin(x),1+cos(x),x/2);\n\n     x\ncos(---)\n     2 \n\n22: triggcd(sin(x),1+cos(x),x);\n\n1\n\\end{verbatim}\n}\\noindent\n\nThe polynomials p and q can consist of both trigonometric and hyperbolic \nfunctions:\n{\\small\n\\begin{verbatim}\n23: triggcd(sin(2x)*sinh(2x),(1-cos(2x))*(1+cosh(2x)),x);\n\ncosh(x)*sin(x)\n\\end{verbatim}\n}\\noindent\n\n\n\\section{Further Examples}\n\nWith the help of the package the user can create identities:\n{\\small\n\\begin{verbatim}\n24: trigsimp(tan(x)*tan(y));\n\n sin(x)*sin(y)\n---------------\n cos(x)*cos(y)\n\n25: trigsimp(ws,combine);\n\n cos(x - y) - cos(x + y)\n-------------------------\n cos(x - y) + cos(x + y)\n\n26: trigsimp((sin(x-a)+sin(x+a))/(cos(x-a)+cos(x+a)));\n\n sin(x)\n--------\n cos(x)\n\n27: trigsimp(cosh(n*acosh(x))-cos(n*acos(x)),trig);\n\n0\n\n28: trigsimp(sec(a-b),keepalltrig);\n\n  csc(a)*csc(b)*sec(a)*sec(b)\n-------------------------------\n csc(a)*csc(b) + sec(a)*sec(b)\n\n29: trigsimp(tan(a+b),keepalltrig);\n\n  - (tan(a) + tan(b))\n----------------------\n  tan(a)*tan(b) - 1\n\n30: trigsimp(ws,keepalltrig,combine);\n\ntan(a + b)\n\\end{verbatim}\n}\\noindent\n\nSome difficult expressions can be simplified:\n{\\small\n\\begin{verbatim}\n\n31: df(sqrt(1+cos(x)),x,4);\n\n                              4            2       2            2\n(sqrt(cos(x) + 1)*( - 4*cos(x)  - 20*cos(x) *sin(x)  + 12*cos(x)\n\n                      2                       4            2\n     - 4*cos(x)*sin(x)  + 8*cos(x) - 15*sin(x)  + 16*sin(x) ))/(16\n\n           4           3           2\n   *(cos(x)  + 4*cos(x)  + 6*cos(x)  + 4*cos(x) + 1))\n\n32: trigsimp(ws);\n\n sqrt(cos(x) + 1)\n------------------\n        16\n\n33: load taylor; \n\n34: taylor(sin(x+a)*cos(x+b),x,0,4);\n\ncos(b)*sin(a) + (cos(a)*cos(b) - sin(a)*sin(b))*x\n\n                                    2\n - (cos(a)*sin(b) + cos(b)*sin(a))*x\n\n    2*( - cos(a)*cos(b) + sin(a)*sin(b))   3\n + --------------------------------------*x\n                     3\n\n    cos(a)*sin(b) + cos(b)*sin(a)   4      5\n + -------------------------------*x  + O(x )\n                  3\n\n35: trigsimp(ws,combine);\n\nsin(a - b) + sin(a + b)                                2    2*cos(a + b)   3\n------------------------- + cos(a + b)*x - sin(a + b)*x  - --------------*x\n            2                                                    3\n\n    sin(a + b)   4      5\n + ------------*x  + O(x )\n        3\n\\end{verbatim}\n}\\noindent\nCertain integrals whose calculation was not possible in REDUCE \n(without preprocessing), are now computable:\n{\\small\n\\begin{verbatim}\n36: int(trigsimp(sin(x+y)*cos(x-y)*tan(x)),x);\n\n       2                                                         2\n cos(x) *x - cos(x)*sin(x) - 2*cos(y)*log(cos(x))*sin(y) + sin(x) *x\n---------------------------------------------------------------------\n                                  2\n\n37: int(trigsimp(sin(x+y)*cos(x-y)/tan(x)),x);\n\n                                   x  2\n(cos(x)*sin(x) - 2*cos(y)*log(tan(---)  + 1)*sin(y)\n                                   2\n\n                      x\n  + 2*cos(y)*log(tan(---))*sin(y) + x)/2\n                      2\n\\end{verbatim}\n}\\noindent\n\nWithout the package, the integration fails, in the second case one doesn't \nreceive an answer for many hours.\n{\\small\n\\begin{verbatim}\n\n38: trigfactorize(sin(2x)*cos(y)**2,y/2);\n\n{2*cos(x)*sin(x),\n\n      y          y\n cos(---) + sin(---),\n      2          2\n\n      y          y\n cos(---) + sin(---),\n      2          2\n\n      y          y\n cos(---) - sin(---),\n      2          2\n\n      y          y\n cos(---) - sin(---)}\n      2          2\n\n39: trigfactorize(sin(y)**4-x**2,y);\n\n          2               2\n{ - sin(y)  + x, - (sin(y)  + x)}\n\n40: trigfactorize(sin(x)*sinh(x),x/2);\n\n        x        x         x         x\n{4,cos(---),sin(---),cosh(---),sinh(---)}\n        2        2         2         2\n\n41: triggcd(-5+cos(2x)-6sin(x),-7+cos(2x)-8sin(x),x/2);\n\n       x        x\n2*cos(---)*sin(---) + 1\n       2        2\n\n42: triggcd(1-2cosh(x)+cosh(2x),1+2cosh(x)+cosh(2x),x/2);\n\n        x  2\n2*sinh(---)  + 1\n        2\n\\end{verbatim}\n}\n\n\\begin{thebibliography}{99}\n\n\\bibitem{art}\nRoach, Kelly: Difficulties with Trigonometrics. Notes of a talk.\n\n\\bibitem{hearns}\nHearn, A.C.: COMPACT User Manual. \n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "53e25803c42c00592d2fdac88b7848fb5056161b", "size": 10163, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packages/trigsimp/otrgsimp.tex", "max_stars_repo_name": "arthurcnorman/general", "max_stars_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": "packages/trigsimp/otrgsimp.tex", "max_issues_repo_name": "arthurcnorman/general", "max_issues_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": "packages/trigsimp/otrgsimp.tex", "max_forks_repo_name": "arthurcnorman/general", "max_forks_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": 23.1503416856, "max_line_length": 81, "alphanum_fraction": 0.5682377251, "num_tokens": 3174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.627783484563087}}
{"text": "\\documentclass[jou]{apa6}\n\n\\usepackage[american]{babel}\n\n\\usepackage{csquotes}\n\\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}\n\\DeclareLanguageMapping{american}{american-apa}\n\\addbibresource{bibliography.bib}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Discrete Structures\n%% The start of RBS stuff\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Working internal and external links in PDF\n\\usepackage{hyperref}\n% Extra math symbols in LaTeX\n\\usepackage{amsmath}\n\\usepackage{gensymb}\n\\usepackage{amssymb}\n% Enumerations with (a), (b), etc.\n\\usepackage{enumerate}\n\n\\let\\OLDitemize\\itemize\n\\renewcommand\\itemize{\\OLDitemize\\addtolength{\\itemsep}{-6pt}}\n\n\\usepackage{etoolbox}\n\\makeatletter\n\\preto{\\@verbatim}{\\topsep=3pt \\partopsep=3pt }\n\\makeatother\n\n% These sizes redefine APA for A4 paper size\n\\oddsidemargin 0.0in\n\\evensidemargin 0.0in\n\\textwidth 6.27in\n\\headheight 1.0in\n\\topmargin -24pt\n\\headheight 12pt\n\\headsep 12pt\n\\textheight 9.19in\n\n\n\n\\title{Sample Quiz 4}\n\\author{Discrete Structures, Fall 2020}\n\\affiliation{RBS}\n\n\\leftheader{Discrete Sample Quiz 4}\n\n\\abstract{%\n}\n\n%\\keywords{}\n\n\\begin{document}\n\n%\\thispagestyle{empty}\n\n\\section{Quiz 4: Sets}\n\n\\vspace{10pt}\n{\\bf Question 1.} Define the universe $U$ to be all possible remainders \nwhen we divide by $360$: $\\{ 0, 1, 2, \\ldots, 359 \\}$. \nAlso define $3$ subsets in this universe: \n$$\\left\\{ \\begin{array}{rcl}\nK_2 & = & \\{ x \\in U \\,\\mid\\, x\\;\\text{divisible by}\\;2 \\},\\\\\nK_3 & = & \\{ x \\in U \\,\\mid\\, x\\;\\text{divisible by}\\;3 \\},\\\\\nK_5 & = & \\{ x \\in U \\,\\mid\\, x\\;\\text{divisible by}\\;5 \\},\\\\\n\\end{array} \\right.$$\n\nDenote by $\\Phi$ the subset of $U$ containing all numbers\nthat are mutually prime with $360$ (no common divisors greater than $1$):\n$\\Phi = \\{1,7,11,13,\\ldots,359\\}$.\nWhich set equality is valid regarding the subset $\\Phi$:\n\n\\noindent\n{\\bf (A)} $\\Phi = \\left( K_2 \\cup K_3 \\cup K_5 \\right)$\\\\\n{\\bf (B)} $\\Phi = \\left( K_2 \\cap K_3 \\cap K_5 \\right)$\\\\\n{\\bf (C)} $\\Phi = \\left( \\overline{K_2} \\cup \\overline{K_3} \\cup \\overline{K_5} \\right)$\\\\\n{\\bf (D)} $\\Phi = \\left( \\overline{K_2} \\cap \\overline{K_3} \\cap \\overline{K_5} \\right)$\\\\\n{\\bf (E)} $\\Phi = \\left( \\overline{K_2 \\cap K_3} \\cup \\overline{K_2 \\cap K_5} \\cup \\overline{K_3 \\cap K_5} \\right)$\n\n\nPick your answer as a single letter like this: {\\tt G}\n\n\\vspace{6pt}\n{\\bf Question 2.}\nFind the size of the set you constructed in the previous example. \n\nWrite your answer as a single non-negative integer like this: {\\tt 17}\n\n\n\\vspace{6pt}\n{\\bf Question 3.} We have the following sets:\\\\\n$A$ is the set of all finite sequences of even positive positive numbers (such as $(6,22,10,14,2,6)$, and so on)\\\\\n$B$ is the set of all infinite nondecreasing lists of even positive numbers (such as $(40 \\leq 40 \\leq 42 \\leq 46 \\leq \\ldots)$, and so on)\\\\\n$C$ is the set of all infinite nonincreasing lists of even positive numbers (such as $(64 \\geq 58 \\geq 58 \\geq 54 \\geq \\ldots)$, and so on).\\\\\nClearly, all three sets are infinite. Determine their cardinalities - which list \nof cardinalities is equal to the list  $(|A|,|B|,|C|)$?\n\n\n\\noindent\n{\\bf (A)} $\\left( \\left| \\mathbb{N} \\right|, \\left| \\mathbb{N} \\right|, \\left| \\mathbb{N} \\right| \\right)$. \n{\\bf (B)} $\\left( \\left| \\mathbb{N} \\right|, \\left| \\mathbb{R} \\right|, \\left| \\mathbb{N} \\right| \\right)$.\n{\\bf (C)} $\\left( \\left| \\mathbb{N} \\right|, \\left| \\mathbb{N} \\right|, \\left| \\mathbb{R} \\right| \\right)$.\n{\\bf (D)} $\\left( \\left| \\mathbb{N} \\right|, \\left| \\mathbb{R} \\right|, \\left| \\mathbb{R} \\right| \\right)$.\n{\\bf (E)} $\\left( \\left| \\mathbb{R} \\right|, \\left| \\mathbb{R} \\right|, \\left| \\mathbb{R} \\right| \\right)$.\n\n\nPick your answer as a single letter like this: {\\tt G}\n\n\\vspace{6pt}\n{\\bf Question 4.}\nLet ${\\displaystyle f(x) = (x^2)\\;\\mathbf{mod}\\;11}$. Find the set $f(S)$ if $S = \\{ 0,1,2,3,4,5,6,7,8,9,10 \\}$. \n\nWrite the list of elements of $f(S)$ as a sorted list like this: {\\tt 1,2,3}\n\n\n\n\n\\vspace{6pt}\n{\\bf Question 5.}\nHow many 2-element sets are there in the powerset $\\mathcal{P}\\left( \\{ \\{ \\mathtt{A}, \\mathtt{B} \\}, \\mathtt{C}, \\mathtt{D}, \\mathtt{E} \\} \\right)$? \n\nWrite your answer as a non-negative integer like this: {\\tt 17}\n\n\n\\vspace{6pt}\n{\\bf Question 6.}\nGiven two sets $A = \\{ x, y \\}$ and $B = \\{x, \\{x \\}\\}$, check, if statements are true or false:\\\\\n{\\bf (A)} $x \\subseteq B$.\\\\\n{\\bf (B)} $\\emptyset \\in \\mathcal{P}(B)$.\\\\\n{\\bf (C)} $\\{x\\} \\subseteq A - B$.\\\\\n{\\bf (D)} $|\\mathcal{P}(A)| = 4$.\n\nWrite your answer as a sorted list of letters (which are true) like this: {\\tt A,B,C,D}\n\n\\vspace{6pt}\n{\\bf Question 7.}\nWe define functions $g\\,:\\, A \\rightarrow A$ and $f : A \\rightarrow A$, where $A \\{1, 2, 3, 4\\}$ by \nlisting all argument-value pairs: \n$f = \\{(1, 2), (2, 3), (3, 4), (4, 1)\\}$, $g = \\{(1, 3), (2, 1), (3, 4), (4, 2)\\}$.\nFind the value pairs for the function $(f \\circ g)^{-1}$. \n\nWrite your answer as a comma-separated list like this: {\\tt (1,1),(2,2),(3,3),(4,4)}\n\n\n\\vspace{6pt}\n{\\bf Question 8.} Find the value of this infinite sum:\n$1 - 1/3 + 1/9 - 1/27 + 1/81 - \\ldots$. \n\nWrite your answer as a simple fraction: {\\tt P/Q}\n\n\n\\vspace{6pt}\n{\\bf Question 9.} It is known that the function $f(n) = n^3 +88n^2 +3$ is in $O(n^3)$ \\textendash{}\nits asymptotic growth is as fast as the growth of the function $g(n) = n^3$. \n$\\exists C \\in \\mathbb{Z}^{+}\\;\\exists n_0 \\in \\mathbb{Z}^{+}\\;\\forall n \\in \\mathbb{Z}^{+},$\\\\\n$(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}|g(n)|)$\nFind the smallest positive integer $C$ that would satisfy the above definition, \nand for your $C$ find the smallest possible $n_0$.\n\nWrite your answer $(C,n_0)$ as a pair of two numbers like this: {\\tt 17,17}\n\n\n\\vspace{6pt}\n{\\bf Question 10.}\n\"Big O notation\" allows to arrange functions according to the their\ngrowth rate for large $n$. \nIdentify, which list of functions is such that \nthe first element of this list is in the big-O of the \nnext element of that list and so on. (Intuitively, the first element\nin the list is the slowest growing function, the last element is the\nfastest growing one.)\n\n{\\bf (1)} $\\log (n^{10})$, {\\bf (2)} $(\\log n)^2$, {\\bf (3)} $\\log \\log n$,\n{\\bf (4)} $n\\log n$, {\\bf (5)} $\\log(n!)$, {\\bf (6)} $\\log 2^n$.\n\nWrite your answer as a comma-separated list like this: {\\tt 1,2,3,4,5,6}\n\n\n\\vspace{6pt}\n{\\bf Question 11.} Digits of all rational numbers $P/Q$ in $(0;1)$\nare eventually periodic: they infinitely repeat some group of digits (the period)\nstarting from some place. For example,\nthe fraction $11/205 = 0.05(36585)$ has period of 5 digits and a pre-period \"05\"\nof just two digits.\nFind the predicate logic expression that tells\nthat sequence of digits $d(1),d(2),d(3),\\ldots$ is eventually periodic (it may have\npre-period of any length, including length zero).\n\n\\noindent\n{\\bf (A)} $\\exists N \\in \\mathbb{Z}^{+}\\;\\exists T \\in \\mathbb{Z}^{+}\\;\\forall n \\in \\mathbb{Z}^{+},$\\\\\n$\\left(n \\geq N - 1 \\rightarrow d(n) = d(n+T)\\right)$.\\\\\n{\\bf (B)} $\\exists N \\in \\mathbb{Z}^{+}\\;\\forall n \\in \\mathbb{Z}^{+}\\;\\exists T \\in \\mathbb{Z}^{+},$\\\\\n$\\left(n \\geq N - 1 \\rightarrow d(n) = d(n+T)\\right)$.\\\\\n{\\bf (C)} $\\forall n \\in \\mathbb{Z}^{+}\\;\\exists N \\in \\mathbb{Z}^{+}\\;\\exists T \\in \\mathbb{Z}^{+},$\\\\\n$\\left(n \\geq N - 1 \\rightarrow d(n) = d(n+T)\\right)$.\\\\\n{\\bf (D)} $\\forall n \\in \\mathbb{Z}^{+}\\;\\forall N \\in \\mathbb{Z}^{+}\\;\\exists T \\in \\mathbb{Z}^{+},$\\\\\n$\\left(n \\geq N - 1 \\rightarrow d(n) = d(n+T)\\right)$. \n\nPick your answer as a single letter like this: {\\tt G}\n\n\n\n\n\\newpage\n\n\\subsection{Answers}\n\n\\vspace{6pt}\n{\\bf Question 1.} Answer {\\bf (D)}.\\\\\nAny number that is mutual prime with $360 = 2^3\\cdot{}3^2\\cdot{}5$\nis not divisible by any of the primes $2,3,5$. And also vice versa. \nThis set is expressed as intersection of the complements:\\\\\n$\\Phi = \\left( \\overline{K_2} \\cap \\overline{K_3} \\cap \\overline{K_5} \\right)$\n\n\n\\vspace{6pt}\n{\\bf Question 2.} Answer: {\\tt 96}.\\\\\n$${\\displaystyle |\\Phi| = 360 \\cdot \\left(1 - \\frac{1}{2}\\right) \\cdot \\left(1 - \\frac{1}{3}\\right) \\cdot \\left(1 - \\frac{1}{5}\\right) =}$$\n$${\\displaystyle  = 360 \\cdot \\frac{1}{2} \\cdot \\frac{2}{3} \\cdot \\frac{4}{5}  = 96}.$$\nIn the above formula we start with all $360$ elements; then we throw\nout one half (all that are divisible by 2); then from the remaining ones \nwe throw out one third (all that are divisible by 3); finally from the remaining numbers we throw\nout one fifth (all that are divisible by 5). Since divisibility by $2$ does not \naffect divisibility by $3$ and $5$ (they are independent), \nall the ratios can be multiplied.\n\nAnother solution: Since we know the sizes of each \nset of numbers divisible by $2,3,5$:\n$$|K_2| = 180,\\; |K_3| = 120,\\; |K_5| = 72.$$\nWe can express their union by {\\em inclusion-exclusion principle}:\n$$|K_2 \\cup K_3 \\cup K_5| \\;=\\; |K_2| \\;+\\; |K_3| \\;+\\; |K_5| \\;-$$\n$$-\\;|K_2 \\cap K_3|\\;-\\;|K_2 \\cap K_5|\\;-\\;|K_3 \\cap K_5| \\;+\\; |K_2 \\cap K_3 \\cap K_5|  \\;=$$\n$$=\\; 180 + 120 + 72 - 60 - 36 - 24 +12 = 264.$$\nWe then apply De Morgan's law to find the count of all elements that are {\\em outside}\nthat union of $K_2 \\cup K_3 \\cup K_5$: \n$$ \\left| \\overline{K_2} \\cap \\overline{K_3} \\cap \\overline{K_5} \\right| = \n\\left| \\overline{K_2 \\cup K_3 \\cup K_5} \\right| =360 - 264 =  96.$$ \n\n\\vspace{6pt}\n{\\bf Question 3.} Answer: {\\tt B}.\n\\begin{itemize} \n\\item $A$ (the set of all finite sequences of even natural numbers can be enumerated\nwith numbers from $\\mathbb{N}$). You can encode \nevery such sequence in a finite alphabet of $13$ symbols, \nusing just digits, commas and parentheses. For example, {\\tt (6, 22, 10, 14, 2, 6)}. \nThe shortest encoding is {\\tt (1)} \\textendash it consists of just three symbols: \ntwo parentheses and a digit. There can be only finite number of such lists of \nlength $3$; we sort the all lexicographically (i.e. in some alphabetical order), and\nassign them numbers.\\\\\nAfter that we enumerate all lists writeable with 4 symbols (sorted lexicographically) \nand so on. Eventually all the sequences will be sorted.\n\\item $B$ (the set of all infinite nondecreasing sequences of even numbers) \nhas cardinality $\\mathbb{R}$. You can repeat the diagonalization argument: \nAssume from the contrary that the elements from $B$ can be enumerated: we get\ninfinitely many infinite sequences $b_1,b_2,\\ldots$.  \nThen take the first element from $b_1$ (and pick some even number that is bigger than that); \nthen take the second element from $b_2$ (and pick some even number that is bigger than \nthat; plus it is bigger than all the previously picked numbers), and so on.\\\\\nYou can also encode any subset $A \\subseteq \\mathbb{N}$ as such sequence (simply arrange all \nthe elements in increasing order and multiply them by $2$ to get even numbers). \nWe get that $B$ has at least as many elements as $\\mathcal{P}(\\mathbb{N})$. \n\\item $C$ (the set of all nonincreasing infinite sequences can be \nenumerated). Since the sequence is non-increasing, it can have only finitely many \nplaces where it actually decreases; since natural numbers cannot decrease infinitely. \nWe can encode all the ``constant runs'' of the sequence as pairs:\\\\\n$$(64,58,58,54,50,50,50,50,2,2,\\ldots) \\rightarrow $$\n$$\\rightarrow \\mathtt{((64,1),(58,2),(54,1),(50,4),(2,\\infty))}.$$\nAs we saw before, all the finite sequences that are encoded in an alfabet\nof $14$ symbols (10 digits, 2 parentheses, commas and infinity) can be enumerated.\n\\end{itemize}\n\n\n\\vspace{6pt}\n{\\bf Question 4.} Answer: {\\tt 0,1,3,4,5,9}.\\\\\nWe can square each number, compute the remainder and sort the \nresults (and eliminate duplicates).\n\n\n\\vspace{6pt}\n{\\bf Question 5.} Answer: {\\tt 6}.\\\\\nThe set $\\{ \\{ \\mathtt{A}, \\mathtt{B} \\}, \\mathtt{C}, \\mathtt{D}, \\mathtt{E} \\}$\nhas $4$ elements ({\\tt A}, {\\tt B} are always glued together). \nThere are $6$ ways to select two out of four elements. \n(Can be computed as a binomial coefficient $C_4^2 = \\frac{4!}{2!2!}$ or simply \nby listing all the $6$ pairs. \n\n\n\\vspace{6pt}\n{\\bf Question 6.} Answer: {\\tt B,D}.\\\\\n$x$ cannot be a subset of $A$ (since it is not a set itself). \n$\\{ x \\}$ is not a subset of $A - B = \\{ y \\}$.\n\n\\vspace{6pt}\n{\\bf Question 7.}\\\\ Answer: {\\tt (1,3),(2,2),(3,4),(4,1)}.\\\\\nWe first compute $f \\circ g$ (to get $(f \\circ g)(x) = f(g(x))$\nwe first apply $g$, then $f$): \n$$f \\circ g = \\{(1,4),(2,2),(3,1),(4,3)\\}.$$\nThe inverse happens, if we switch the order in all these pairs\n($4$ maps back to $1$ etc.)\\\\\n$$(f \\circ g)^{-1} = \\{(1,3),(2,2),(3,4),(4,1)\\}.$$\n\n\n\\vspace{6pt}\n{\\bf Question 8.} Answer: {\\tt 3/4}.\\\\\nThe sum of the infinite geometrical progression is $b_1/(1 - q)$. \nIn our case:\n$$\\frac{1}{1 - (-1/3)} = \\frac{1}{4/3} = \\frac{3}{4}.$$\n\n\\vspace{6pt}\n{\\bf Question 9.} Answer: {\\tt 2,88}. \nClearly, $f(n) = |n^3 +88n^2 +3|$ cannot be smaller than $C\\cdot{}|n^3|$, \nif $C=1$, because $88n^2$ is always positive and makes $f(n)$ larger\nthan simply $n^3$.\\\\\nIf we take $C = 2$, then the inequality starts to hold for all $n>88$. \nIt is possible to prove that for such $n$: \n$$n^3 +88n^2 +3 = n^2(n + 88) + 3 =$$\n$$ = n^2(n+n) + n^2(88 -n) + 3  = 2n^3 + n^2(88-n) + 3 \\leq 2n^3.$$\nThe last inequality is true, since $n^2(88-n) + 3 < 0$ for any \n$n > 88$.\n\n\n\\vspace{6pt}\n{\\bf Question 10.} Answer: {\\tt 3,1,2,6,4,5} (or {\\tt 3,1,2,6,5,4}).\\\\\nLogarithm of a logarithm is a very slowly growing function; \n$\\log n^{10}$ is just equal to $10$ times $\\log n$. \n$(\\log n)^2 = \\log^2 n$ is slightly faster than a logarithm.\\\\\nFinally $\\log 2^n$ is simply $n$; but both $\\log (n!)$ and\n$n \\log n$ grow slightly faster than $n$; they are \"Big-O\" of each other:\n$$n \\log n \\;\\text{is in}\\;O(\\log n!);$$\n$$\\log n! \\;\\text{is in}\\;O(n \\log n).$$\nIt does not matter, in which order we list them. \n\nTo verify all these claims, you need to prove various limits: \n$$\\lim_{n \\rightarrow \\infty} \\frac{\\log\\log n}{\\log n} = 0,$$\n$$\\lim_{n \\rightarrow \\infty} \\frac{\\log n}{(\\log n)^2} = 0,$$\nand so on. Most of these limits are easy to find (L'Hospital's Rule and so on). \nWith $\\log n!$ you might need to use integrals to estimate \nthe sum of $\\log 1 + \\log 2 + \\ldots + \\log n$. \n\n{\\em Note.} Unless noted otherwise, all logarithms in our course are base $2$. \n\n\n\n\\vspace{6pt}\n{\\bf Question 11.} Answer: {\\tt A}. \nClearly the $N$ and $T$ should not depend on $n$; so they are the first quantifiers.\\\\\n{\\bf (B)} describes a sequence of digits where some digit repeats itself infinitely \noften (which is true for any sequence of digits).\\\\\n{\\bf (C)} describes the set of all sequences; one can always pick $N$ that is larger than $n$, \nthen the condition is trivially true.\\\\ \n{\\bf (D)} describes a sequence where each digit appears infinitely often. \n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "853cd3bdf17625dd71a37288109276e1c02c3d99", "size": 14595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/site/discrete-spring2020/questionbase/quiz-04.tex", "max_stars_repo_name": "kapsitis/math", "max_stars_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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/site/discrete-spring2020/questionbase/quiz-04.tex", "max_issues_repo_name": "kapsitis/math", "max_issues_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-07-20T03:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T21:50:18.000Z", "max_forks_repo_path": "src/site/discrete-spring2020/questionbase/quiz-04.tex", "max_forks_repo_name": "kapsitis/math", "max_forks_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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": 40.4293628809, "max_line_length": 150, "alphanum_fraction": 0.6465912984, "num_tokens": 5265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.6277679544250367}}
{"text": "% !TEX root = ../zeth-protocol-specification.tex\n\n\\chapter{Double spend attack on equivalent class}\\label{appendix:dbspd}\n\nThe primary inputs of our zk-SNARK are elements of $\\FFx{\\rCURVE}$ and they can be written over $\\fieldBitLen$ bits. Note that the projection of $\\BB^\\fieldBitLen$ onto $\\FFx{\\rCURVE}$ formed by interpreting elements in $\\BB^\\fieldBitLen$ as $\\fieldBitLen$-bit numbers and reducing modulo $\\rCURVE$, is surjective.\n\nWhen we pass the primary inputs to the $\\mixer$ contract, they are interpreted as elements of $\\BB^\\ethWordLen$, and $\\BB^\\fieldBitLen \\subset \\BB^\\ethWordLen$. As previously noted, this means that there exist pairs of elements in $\\BB^\\ethWordLen$ with the same projection in $\\FFx{\\rCURVE}$. An adversary could make use of this to perform a double spend attack.\n\nIndeed, to check that a note is not double spent, the contract stores the nullifiers of spent notes (as elements of $\\BB^\\ethWordLen$) and verifies that the nullifier of the note to be spent is not stored. The adversary could thus modify the nullifier to a different value with the same projection. As the SNARK verification operates in $\\FFx{\\rCURVE}$, the proof would still be valid. However, the value stored for this nullifier would be different from the adversarial one. Hence, the nullifier would be validated, the transaction would succeed and the note would be double spent.\nIn practice, the adversary can perform the attack by simply adding $\\rCURVE$ to one of the elements representing the nullifier.\n\nTo prevent this attack, the contract checks that all primary inputs are elements of $\\FFx{\\rCURVE}$, that is to say that they are smaller than $\\rCURVE$.\nAs one may see, the attack described above is not due to the packing of hash digests into field elements but to the contract storage of field elements as $\\ethereum$ words.\n", "meta": {"hexsha": "5b9ceb252e413ff3030416ebe461ebe264f51f3c", "size": 1843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/appendix02-dbspd.tex", "max_stars_repo_name": "clearmatics/zeth-specifications", "max_stars_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-29T18:22:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-29T18:22:00.000Z", "max_issues_repo_path": "appendices/appendix02-dbspd.tex", "max_issues_repo_name": "clearmatics/zeth-specifications", "max_issues_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-10-27T10:41:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-16T10:57:05.000Z", "max_forks_repo_path": "appendices/appendix02-dbspd.tex", "max_forks_repo_name": "clearmatics/zeth-specifications", "max_forks_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-26T04:51:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-26T04:51:29.000Z", "avg_line_length": 131.6428571429, "max_line_length": 582, "alphanum_fraction": 0.7759088443, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6277679487679474}}
{"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\\usepackage{cancel}\n%\\renewcommand\\headheight{12pt}\n\\pagestyle{fancy}\n\\lhead{April 16, 2014}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\nRead Sections 7.2 and 7.3 and do the following problems from Chapter 7: \\#16, 17, 18, 19, 22, 24(a)(b)(c) (be sure to write your answer in closed form), 26, 28, 50 (Grad: 49).\n\\begin{enumerate}\n\\setcounter{enumi}{15}\n\\item\nFormulate a combinatorial problem for which the generating function is\n\\[(1+x+x^2)(1+x^2+x^4+x^6)(1+x^2+x^4+\\cdots)(x+x^2+x^3+\\cdots)\\]\n\nHow many combinations of red, yellow, green and blue colored pencils are there in which there are at most 2 red pencils, an even number of at most six yellow pencils, an even number of green pencils and at least one blue pencil?\n\\item\nDetermine the generating function  for the number $h_n$ of bags of fruit of apples, oranges, bananas, and pears in which there are an even number of apples, at most two oranges, a multiple of three number of bananas, and at most one pear. Then find a formula for $h_n$ from the generating function.\n\n\\begin{align*}\n  g(x)&=\\underbrace{\\left(\\sum\\limits_{n=0}^\\infty{x^{2n}}\\right)}_{\\text{even apples}}\\underbrace{\\left(\\sum\\limits_{n=0}^2{x^n}\\right)}_{\\text{oranges}\\le 2}\\underbrace{\\left(\\sum\\limits_{n=0}^\\infty{x^{3n}}\\right)}_{3\\mid \\text{bananas}}\\underbrace{\\left(\\sum\\limits_{n=0}^1{x^{n}}\\right)}_{\\text{pears}\\le 1}\\\\\n  &=\\frac{1}{1-x^2}\\left[\\left(\\sum\\limits_{n=0}^\\infty{x^n}\\right)-\\left(\\sum\\limits_{n=3}^\\infty{x^n}\\right)\\right]\\frac{1}{1-x^3}\\left[\\left(\\sum\\limits_{n=0}^\\infty{x^n}\\right)-\\left(\\sum\\limits_{n=2}^\\infty{x^n}\\right)\\right]\\\\\n  &=\\frac{1}{1-x^2}\\left[\\left(1-x^3\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^n}\\right)\\right]\\frac{1}{1-x^3}\\left[\\left(1-x^2\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^n}\\right)\\right]\\\\\n  &=\\left(\\frac{1}{1-x^2}\\right)\\left(\\frac{1-x^3}{1-x}\\right)\\left(\\frac{1}{1-x^3}\\right)\\left(\\frac{1-x^2}{1-x}\\right)\\\\\n  &=\\frac{1}{(1-x)^2}\n  =\\frac{\\mathrm{d}}{\\mathrm{d}x}\\left(\\frac{1}{1-x}\\right)\n  =\\frac{\\mathrm{d}}{\\mathrm{d}x}\\sum\\limits_{n=0}^\\infty{x^n}\\\\\n  &=\\sum\\limits_{n=0}^\\infty{nx^{n-1}}\n  =\\sum\\limits_{n=-1}^\\infty{(n+1)x^{n}}\n  =0+\\sum\\limits_{n=0}^\\infty{(n+1)x^{n}}\\\\\n  h_n&=n+1\n\\end{align*}\n\\item\nDetermine the generating function for the number $h_n$ of nonnegative integral solutions of\n\\[2e_1+5e_2+e_3+7e_4=n\\]\nThis is equivalent to saying how many ways can you pick $n$ items from the multiset $\\{\\infty\\cdot e_1,\\infty\\cdot e_2,\\infty\\cdot e_3,\\infty\\cdot e_4\\}$ where you have an even number of $e_1$'s, a multiple of 5 $e_2$'s and a multiple of 7 $e_4$'s.\n\\begin{align*}\n  g(x)&=\\left(\\sum\\limits_{n=0}^\\infty{x^{2n}}\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^{5n}}\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^{n}}\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^{7n}}\\right)\\\\\n  &=\\left(\\frac{1}{1-x^2}\\right)\\left(\\frac{1}{1-x^5}\\right)\\left(\\frac{1}{1-x}\\right)\\left(\\frac{1}{1-x^7}\\right)\n\\end{align*}\n\\item\nLet $h_0,h_1,h_2,\\dots,h_n,\\dots$ be the sequence defined by $h_n=\\binom{n}{2},(n\\ge0)$. Determine the generating function for the sequence.\n\\begin{align*}\n  g(x)&=\\sum\\limits_{n=0}^\\infty{\\binom{n}{2}x^n}\\\\\n  &=\\sum\\limits_{n=0}^\\infty{\\frac{n!}{2!(n-2)!}x^n}\\\\\n  &=\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{n(n-1)x^n}\\\\\n  h_n&=\\frac{1}{2}(n^2-n)\n\\end{align*}\n\\setcounter{enumi}{21}\n\\item\nDetermine the exponential generating function for the sequence of factorials: $0!,1!,2!,3!,\\dots,n!,\\dots$\n\\begin{align*}\n  g^{(e)}(x)&=\\sum\\limits_{n=0}^\\infty{n!\\cdot\\frac{x^n}{n!}}\\\\\n  &=\\sum\\limits_{n=0}^\\infty{x^n}\\\\\n  &=\\frac{1}{1-x}\n\\end{align*}\n\\setcounter{enumi}{23}\n\\item\nLet $S$ denote the multiset $\\{\\infty\\cdot e_1,\\infty\\cdot e_2,\\dots,\\infty\\cdot e_k\\}$. Determine the exponential generating function for the sequence $h_0,h_1,h_2,\\dots,h_n,\\dots$, where $h_0=1$ and, for $n\\ge 1$\n\\begin{enumerate}\n\\item\n$h_n$ equals the number of $n$-permutations of $S$ in which each object occurs an odd number of times.\n\\begin{align*}\n  g^{(e)}(x)&=\\left(x+\\frac{x^3}{3!}+\\frac{x^5}{5!}+\\dots\\right)^k\\\\\n  &=\\left[\\left(1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\dots\\right)+\\left(-1+x-\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\dots\\right)\\right]^k\\frac{1}{2^k}\\\\\n  &=\\left(\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{\\frac{x^n+(-x)^n}{n!}}\\right)^k\\\\\n  &=\\left(\\frac{e^x+e^{-x}}{2}\\right)^k\n\\end{align*}\n\\item\n$h_n$ equals the number of $n$-permutations of $S$ in which each object occurs at least four times.\n\\begin{align*}\n  g^{(e)}(x)&=\\left(\\frac{x^4}{4!}+\\frac{x^5}{5!}+\\frac{x^6}{6!}+\\dots\\right)^k\\\\\n  &=\\left(\\sum\\limits_{n=4}^\\infty{\\frac{x^n}{n!}}\\right)^k=\\left(-\\frac{x^3}{3!}+\\sum\\limits_{n=3}^\\infty{\\frac{x^n}{n!}}\\right)^k\\\\\n  &=\\left(-1-x-\\frac{x^2}{2!}-\\frac{x^3}{3!}+\\sum\\limits_{n=3}^\\infty{\\frac{x^n}{n!}}\\right)^k\\\\\n  &=\\left(e^x-1-x-\\frac{x^2}{2!}-\\frac{x^3}{3!}\\right)^k\n\\end{align*}\n\\item\n$h_n$ equals the number of $n$-permutations of $S$ in which $e_1$ occurs at least once, $e_2$ occurs at least twice, $\\dots,e_k$ occurs at least $k$ times.\n\\begin{align*}\n  g^{(e)}(x)&=\\left(x+\\frac{x^2}{2!}+\\dots\\right)\\left(\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\dots\\right)\\dots\\left(\\frac{x^{k-1}}{(k-1)!}+\\frac{x^k}{k!}+\\dots\\right)\\\\\n  &=\\prod_{i=1}^k{\\left(\\sum\\limits_{n=i}^\\infty{\\frac{x^n}{n!}}\\right)}\\\\\n  &=\\prod_{i=1}^k{\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^n}{n!}}-\\sum\\limits_{n=0}^{i-1}{\\frac{x^n}{n!}}\\right)}\\\\\n  &=\\prod_{i=1}^k{\\left(e^x-\\sum\\limits_{n=0}^{i-1}{\\frac{x^n}{n!}}\\right)}\\\\\n\\end{align*}\n\\end{enumerate}\n\\setcounter{enumi}{25}\n\\item\nDetermine the number of ways to color the squares of a 1-by-$n$ chessboard, using the colors red, blue, green, and orange if an even number of squares is to be colored red and an even number is to be colored green.\n\\begin{align*}\n  g^{(e)}(x)&=\\underbrace{\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^{2n}}{(2n)!}}\\right)^2}_{\\text{red and green are even}}\\cdot\\overbrace{\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^{n}}{n!}}\\right)^2}^{\\text{blue and orange are unrestricted}}\\\\\n  &=\\left(\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{\\frac{x^n+(-x)^n}{n!}}\\right)\\left(e^x\\right)^2\\\\\n  &=\\frac{e^{2x}}{2}\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^n}{n!}}+\\sum\\limits_{n=0}^\\infty{\\frac{(-x)^n}{n!}}\\right)\\\\\n  &=\\frac{e^{2x}}{2}\\left(e^x+e^{-x}\\right)=\\frac{e^{3x}+e^x}{2}\\\\\n  &=\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{\\frac{(3x)^n+x^n}{n!}}=\\sum\\limits_{n=0}^\\infty{\\frac{3^n+1}{2}\\cdot\\frac{x^n}{n!}}\n\\end{align*}\nSo we can color the board $\\frac{3^n+1}{2}$ ways\n\\setcounter{enumi}{27}\n\\item\nDetermine the number of $n$-digit numbers with all digits at least 4, such that 4 and 6 each occur an even number of times, and 5 and 7 each occur at least once, there being no restriction on the digits 8 and 9.\n\\begin{align*}\n  g^{(e)}(x)&=\\underbrace{\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^{2n}}{(2n)!}}\\right)^2}_{\\text{4,6 are even}}\\cdot\\overbrace{\\left(\\sum\\limits_{n=1}^\\infty{\\frac{x^n}{n!}}\\right)^2}^{\\text{5,7 occur at least once}}\\cdot\\underbrace{\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^n}{n!}}\\right)^2}_{\\text{8,9 are unrestricted}}\\\\\n  &=\\left(\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{\\frac{x^n+(-x)^n}{n!}}\\right)^2\\left(-1+\\sum\\limits_{n=0}^\\infty{\\frac{x^n}{n!}}\\right)^2\\left(\\sum\\limits_{n=0}^\\infty{\\frac{x^n}{n!}}\\right)^2\\\\\n  &=\\frac{e^{2x}}{4}\\left(e^x+e^{-x}\\right)^2(e^x-1)^2\\\\\n  &=\\frac{e^{2x}}{4}\\left(e^{2x}+2+e^{-2x}\\right)(e^{2x}-2e^x+1)\\\\\n  &=\\frac{e^{2x}}{4}\\left(e^{4x}-2e^{3x}+e^{2x}+2e^{2x}-4e^x+2+1-2e^{-x}+e^{-2x}\\right)\\\\\n  &=\\frac{e^{2x}}{4}\\left(e^{4x}-2e^{3x}+3e^{2x}-4e^x+3-2e^{-x}+e^{-2x}\\right)\\\\\n  &=\\frac{1}{4}\\left(e^{6x}-2e^{5x}+3e^{4x}-4e^{3x}+3e^{2x}-2e^{x}+1\\right)\\\\\n  &=\\frac{1}{4}+\\frac{1}{4}\\sum\\limits_{n=0}^\\infty{\\frac{(6x)^n-2(5x)^n+3(4x)^n-4(3x)^n+3(2x)^n-2x^n}{n!}}\\\\\n  &=\\frac{1}{4}+\\frac{1}{4}\\sum\\limits_{n=0}^\\infty{\\left[6^n-2(5^n)+3(4^n)-4(3^n)+3(2^n)-2\\right]\\frac{x^n}{n!}}\n\\end{align*}\nSo the number of $n$-digit numbers that meet the criteria is 0 when $n=0$ and $\\frac{1}{4}\\left[6^n-2(5^n)+3(4^n)-4(3^n)+3(2^n)-2\\right]$ when $n\\ge1$\n\\setcounter{enumi}{49}\n\\item\nCall a subset of $S$ of the integers $\\{1,2,\\dots,n\\}$ \\emph{extraordinary} provided its smallest integer equals its size:\n\\[\\min\\{x:x\\in S\\}=\\lvert S\\rvert.\\]\nFor example, $S=\\{3,7,8\\}$ is extraordinary. Let $g_n$ be the number of extraordinary subsets of $\\{1,2,\\dots,n\\}$. Prove that\n\\[g_n=g_{n-1}+g_{n-2},\\quad(n\\ge3),\\]\nwith $g_1=1$ and $g_2=1$.\n\\subsubsection*{proof}\nThe number of extraordinary subsets of $\\{1,2,\\dots,n\\}$ is the sum of the number of extraordinary subsets of each size from 1 to $n$. A $k$ sized extraordinary subset of $\\{1,2,\\dots,n\\}$ contains $k$ and $k-1$ elements of the set $\\{k+1,k+2,\\dots,n\\}$. We can choose these $k-1$ elements in $\\binom{n-(k+1)+1}{k-1}$ ways. Lets simplify a little:\n\\begin{align*}\n  \\binom{n-(k+1)+1}{k-1}&=\\binom{n-k}{k-1}\\\\\n  g_n&=\\sum\\limits_{k=1}^n{\\binom{n-k}{k-1}}\\\\\n  \\binom{n+1}{k+1}&=\\binom{n}{k}+\\binom{n}{k+1}\\\\\n  g_n&=\\sum\\limits_{k=1}^n{\\binom{n-k-1}{k-1-1}}+\\sum\\limits_{k=1}^n{\\binom{n-k-1}{k-1}}\\\\\n  &=\\binom{n-n-1}{n-2}+\\sum\\limits_{k=1}^{n-1}{\\binom{n-k-1}{k-1-1}}+\\binom{n-n-1}{n-1}+\\sum\\limits_{k=1}^{n-1}{\\binom{n-k-1}{k-1}}\\\\\n  &=\\frac{(n-n-1)!}{(n-n-1-(n-2))!(n-2)!}+\\frac{(n-n-1)!}{(n-n-1-(n-1))!(n-1)!}\\\\&\\quad+\\sum\\limits_{k=1}^{n-1}{\\binom{n-k-1}{k-1-1}}+\\sum\\limits_{k=1}^{n-1}{\\binom{(n-1)-k}{k-1}}\\\\\n  &=\\frac{(-1)!}{(1-n)!(n-2)!}+\\frac{(-1)!}{(-n)!(n-1)!}\\\\&\\quad+\\sum\\limits_{k=1}^{n-1}{\\binom{n-(k-1)}{(k-1)-1}}+g_{n-1}\\\\\n  &=\\frac{(-1)!(n-1)}{(1-n)!(n-1)!}+\\frac{(-1)!(1-n)}{(1-n)!(n-1)!}\\\\&\\quad+\\sum\\limits_{k=0}^{n-2}{\\binom{n-k}{k-1}}+g_{n-1}\\\\\n  &=\\frac{(-1)!n-(-1)!+(-1)!-(-1)!n}{(1-n)!(n-1)!}\\\\&\\quad+\\binom{n}{-1}+\\sum\\limits_{k=1}^{n-2}{\\binom{n-k}{k-1}}+g_{n-1}\\\\\n  &=0+\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}-\\binom{n-(n-1)}{(n-1)-1}-\\binom{n-n}{n-1}+g_{n-1}\\\\\n  &=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}-\\binom{1}{n-2}-\\binom{0}{n-1}+g_{n-1}\\\\\n%  &=\\sum\\limits_{k=1}^{n-1}{\\binom{n-k}{k-1}}+\\binom{n-n}{n-1}\n\\end{align*}\n%Now if we have $g_n$, then what is $g_{n-1}$? We have \n%\\begin{align*}\n%  g_{n-1}&=\\sum\\limits_{k=1}^{n-1}{\\binom{n-k-1}{k-1}}\\\\\n%\\end{align*}\n%Now lets see what happens if we add $g_{n}$ and $g_{n+1}$\n%\\begin{align*}\n%  \\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n+1}{\\binom{(n+1)-k}{k-1}}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\binom{(n+1)-k}{k-1}}+\\binom{(n+1)-(n+1)}{(n+1)-1}\n%\\end{align*}\n%lets make an assumption and see if it holds\n%\\begin{align*}\n%  \\sum\\limits_{k=1}^{n+2}{\\binom{(n+2)-k}{k-1}}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\binom{(n+1)-k}{k-1}}+\\binom{0}{n}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\binom{(n+2)-k}{k-1}}+\\binom{0}{n+1}+\\binom{1}{n}-\\sum\\limits_{k=1}^{n}{\\binom{(n+1)-k}{k-1}}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\binom{(n+2)-k}{k-1}}-\\sum\\limits_{k=1}^{n}{\\binom{(n+1)-k}{k-1}}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\frac{((n+2)-k)!}{(k-1)!((n+2)-k-(k-1))!}}\\qquad&\\\\\n%  -\\sum\\limits_{k=1}^{n}{\\frac{((n+1)-k)!}{(k-1)!((n+1)-k-(k-1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-k(k-1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\frac{(n-k+2)!}{(k-1)!(n-2k+3)!}}\\qquad&\\\\\n%  -\\sum\\limits_{k=1}^{n}{\\frac{(n-k+1)!}{(k-1)!(n-2k+2))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\frac{(n-k+2)(n-k+1)(n-k)!}{(k-1)!(n-2k+3)(n-2k+2)(n-2k+1)!}}\\qquad&\\\\\n%  -\\sum\\limits_{k=1}^{n}{\\frac{(n-k+1)(n-k)!}{(k-1)!(n-2k+2)(n-2k+1)!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\begin{aligned}\\frac{(n-k+2)(n-k+1)}{(n-2k+3)(n-2k+2)}\\\\-\\frac{(n-k+1)}{(n-2k+2)}\\end{aligned}\\right]\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{\\begin{aligned}(n-k+2)(n-k+1)\\\\-(n-k+1)(n-2k+3)\\end{aligned}}{(n-2k+3)(n-2k+2)}\\right]\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{(n-k+1)(n-k+2-n+2k-3)}{(n-2k+3)(n-2k+2)}\\right]\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{(n-k+1)(k-1)}{(n-2k+3)(n-2k+2)}\\right]\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{1}{(n-2k+3)(n-2k+2)}\\right]\\frac{(n-k+1)!}{k!(n-2k+1))!}}&=\\sum\\limits_{k=1}^{n}{\\frac{(n-k)!}{(k-1)!(n-2k+1))!}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{1}{(n-2k+3)(n-2k+2)}\\right]\\binom{n-k+1}{k}}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  \\sum\\limits_{k=2}^{n+1}{\\left[\\frac{\\binom{(n-1)-(k-1)+1}{k-1}}{((n-1)-2(k-1)+3)((n-1)-2(k-1)+2)}\\right]}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  \\sum\\limits_{k=2}^{n+1}{\\left[\\frac{\\binom{n-k+1}{k-1}}{(n-2k+4)(n-2k+3)}\\right]}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  \\sum\\limits_{k=1}^{n}{\\left[\\frac{\\frac{n-k+1}{k}\\binom{n-k}{k-1}}{(n-2k+3)(n-2k+2)}\\right]}&=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}\\\\\n%  &=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\frac{(n+1-k)!}{(k-1)!(n-k+1-k+1)!}}+\\binom{0}{n}\\\\\n%  &=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\frac{(n+1-k)(n-k)!}{(k-1)!(n-k+1-k+1)(n-k+1-k)!}}\\\\\n%  &=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\frac{(n+1-k)}{(n+2-2k)}\\binom{n-k}{k-1}}\\\\\n%  &=\\sum\\limits_{k=1}^{n}{\\binom{n-k}{k-1}}+\\sum\\limits_{k=1}^{n}{\\frac{(n-k+1)}{(n-2k+2)}\\binom{n-k}{n-k+1}}\\\\\n%\\end{align*}\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "775fb9b6f90045361d1598086a53ff1afc9a2c60", "size": 13668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-04-16.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-04-16.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-04-16.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": 75.9333333333, "max_line_length": 347, "alphanum_fraction": 0.5847966052, "num_tokens": 6617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6277280605737049}}
{"text": "% \\cleardoublepage\n% \\chapter*{Introduction}\n% \\markboth{Introduction}{Introduction}\n% \\addcontentsline{toc}{chapter}{Introduction}\n\n\\chapter{Introduction}\n\n\\section{Problem and Motivation}\n\nSuppose we are given samples of data say $\\mathbf{x}$ and $\\mathbf{y}$, s.t.\n\n\\begin{align*}\n    \\mathbf{x} = x_1, ..., x_n  \\\\\n    \\mathbf{y} = y_1, ..., y_n \n\\end{align*}\n\nFor example, we may be measuring the blood pressure and heart rate of Alice at time $k$, \nsay $x_k$ and $y_k$ respectively, with $x_k, y_k \\in \\R$. Further, suppose we are unaware of her context, for example,\nBob hacked into Alice's Apple watch and so can only read $\\mathbf{x}$ and $\\mathbf{y}$ --- he has no idea of \nanything she might be up to.\n\nBob then observes the following trend:\n\n\\begin{figure}[htb]\n    \\centering\n    \\begin{tikzpicture}\n        \\node (img)  {\\includegraphics[width=.45\\textwidth]{correlated_hr.png}};\n        \\node[below=of img, node distance=0cm, yshift=1cm,font=\\color{black}] {time};\n        \\node[left=of img, node distance=0cm, rotate=90, anchor=center,yshift=-0.7cm,font=\\color{black}] {bpm/mmHg};\n    \\end{tikzpicture}\n    \\caption{Heart rate (HR) and Blood pressure (BP) measured in bbp and mmHg resp. Day 1.}\n\\end{figure}\n\nBob, having studied data science, is well aware of the fallacy of the law of small numbers\\footnote{\n    The law of small numbers is the error of concluding too much from too few data (many such examples \n    can be found in the book \"fooled by randomness\" by \\cite{taleb}).}. \n He therefore checks again the data the next day at a slightly different time. He again observes \na similar trend, and is now more confident in the existence of a causal relation and --- having neglected biology --- \nmakes the conjecture that either blood pressure causes heart rate, or \nperhaps the other way around. \n\nGiven this strong correlation, Bob asserts that he may either model $x$ as a function of $y$ or the other way \naround. He proceeds to find some $f$ s.t. $f(x) \\approx y$. The next day, to his dismay, he notices that his\nmodel has terrible performance when evaluated on new data. He then proceeds to see what is going on, and \nobserves the following:\n\n\\begin{figure}[htb]\n    \\centering\n    \\begin{tikzpicture}\n        \\node (img)  {\\includegraphics[width=.45\\textwidth]{uncorrelated_hr.png}};\n        \\node[below=of img, node distance=0cm, yshift=1cm,font=\\color{black}] {time};\n        \\node[left=of img, node distance=0cm, rotate=90, anchor=center,yshift=-0.7cm,font=\\color{black}] {bpm/mmHg};\n    \\end{tikzpicture}\n    \\caption{Heart rate (HR) and Blood pressure (BP) measured in bbp and mmHg resp. Day 3.}\n\\end{figure}\n\nAs it turns out, in the last few days, Alice was working hard on finishing her thesis and the deadline had been \nthe previous day. But how, Bob wondered, could this have changed the relationship between BP and HR? \nFinally, admitting to himself that curve fitting alone is not enough to understand the world; \nBob spends some time learning about the heart. It turns out, that fear triggers a \"flight or fight\"\nresponse that increases both the heart rate and blood pressure; Interestingly your heart rate and blood pressure \nwon’t always rise and fall in sync.\n\nSo what did Bob learn\\footnote{\n    Note that heart rate and blood pressure are intimately linked, and the story between them is more complicated.\n    The plots were randomly generated using a Gaussian process, however they do resemble some real examples that \n    can be found in the internet.\n}?\n\n\\begin{enumerate}\n    \\item When we train a model with some data, and then use it on some newly acquired data, we might\n    face a \\textbf{covariate-shift}\\footnote{Another way to describe the covariate-shift is as follows, \n    suppose we observe some samples, but\n    these samples only represent a small portion of the data space, then when we acquire new data, this new data might be very \n    different from our original acquisition. } --- that is, the distribution might change due to the context changing.\n    \\item When we see correlation it might be spurious due to a \\textbf{confounder} --- fear was the \\textbf{confounder} \n    of the heart rate and blood pressure.\n\\end{enumerate}\n\nIf Bob was able to incorporate these notions into his machine learning models, then it might have been more\nrobust to the covariate-shift. To give a more concrete example, there is a \"neural net tank urban legend\"\\footnote{\n    More about this story here: https://www.gwern.net/Tanks.\n}\n, where a neural network accurately predicts if there is a tank or not in an image, but it turns out it uses the \nweather as a predictor. From this it is clear that the model will perform badly under covariate shift, and indeed\nit makes the case that incorporating causality to a model should make it more robust as\n\\cite{scholkopf2019causality} argues. Note that this is in effect the issue with generalization in machine learning:\nhow can we ensure that we learn \\textit{meaningful} representations (features about the tanks) rather than just\ncorrelations (the weather) useful for training accuracy. \n\nAs for confounders, it is impossible to say anything in general\\footnote{\n    For most of the 20th century, a huge debate took place to determine the question of whether or not \n    smoking caused cancer. A clever argument against a causal relation was that there existed a gene that \n    made a person both want to smoke and more prone to cancer; even the father of modern statistics\n    himself thought this explanation more plausible (For a good read on how science is and was used \n    for wrong see the excellent book of \\cite{NaomiMerchants}).\n    \n}. We must therefore specify a causal model, and\nthen see what guarantees we can give under what assumptions. Even in the absence of confounders it is highly \nnon trivial to determine causality.\n\nAs this simple example illustrates, causality is related to many interesting questions; perhaps, one of the most \nsimple questions we can ask --- and the one that we will explore --- is, given that either X causes Y, or Y causes X\n(we assume no confounders) then, when \ncan we predict the direction of causality? If yes, how? \n\nIn the figure bellow (figure \\ref{fig:simple_bivariate_example}) can you tell if $X$ causes $Y$? Or perhaps\nit is the other way around? The right answer is that $X$ causes $Y$, and we will show algorithms that \ncan accurately predict causality in such settings with as few as 75 samples. \n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1\\textwidth]{bivariate_causal_example.png}\n    \\caption{75 samples of data $X$, $Y$.  The samples are generated independently as follows:\n    $y_i = f(x_i) + n_i$ where $x_i$ is drawn from an exponential distribution and $n_i$ is drawn \n    independently from a Gaussian one and $f(x) = 10 \\tanh(x) + 4\\sin(x) + x + x^2$}\n    \\label{fig:simple_bivariate_example}\n\\end{figure}\n\n\\section{Causality}\n\n\\subsection{Causal models: FCM}\n\nWe can model any causal model by using a \\textbf{Function Causal Model (FCM)} which can be constructed as follows\n(\\cite{Peters2017}):\n\nWe \\textit{generate} a random vector\\footnote{That is, each $X_i$ is a random variable.}\n$X = (X_1, ..., X_d)$ by using a graph $\\mathcal{G}$ (encoding the relationships),\na set of functions $f = (f_1, ..., f_d)$ (encoding the type of relationship) and a noise distribution $\\mathcal{E}$\n(the randomness generator).\n\nFor each $i = 1, ..., d$\n\n$$\n    X_i \\leftarrow f_i(X_{\\text{Pa}(i)}, E_i), \\quad E_i \\thicksim \\mathcal{E}\n$$\n\nwhere $\\text{Pa}(i)$ is the set of parents of $i$; and so $X_{\\text{Pa}(i)}$ is the set of random variables\nfor the parents of $X_i$. For example in Figure \\ref{fig:fcm_1}, $\\text{Pa}(4) = \\{1, 2\\}$, \nand so $X_{\\text{Pa}(4)} = \\{X_1, X_2\\}$.\n\n\\begin{figure}[!h]\n    \\centering\n\n    \\begin{tikzpicture}[\n        > = stealth, % arrow head style\n        shorten > = 1pt, % don't touch arrow head to node\n        auto,\n        node distance = 2.5cm, % distance between nodes\n        thick % line style\n    ]\n    \n    \\tikzstyle{every state}=[\n        draw = black,\n        thick,\n        fill = white,\n        minimum size = 4mm\n    ]\n    \n    \\node[state] (a) {$X_1$};\n    \\node[state] (b) [right of=a] {$X_2$};\n    \\node[state] (c) [below left of=a] {$X_3$};\n    \\node[state] (d) [below right of=a] {$X_4$};\n    \n    \\path[->] (a) edge node {} (c);\n    \\path[->] (a) edge node {} (d);\n    \\path[->] (b) edge node {} (d);\n    \n    \\end{tikzpicture}\n    \\caption{ Example for FCM with $X = X_1, ... X_4$, with $E_i \\thicksim \\mathcal{E}$, \n    with $X_1 = f_1(E_1)$, $X_2 = f_2(E_2)$, $X_3 = f_3(X_1, E_3)$, and \n    $X_4 = f_4(X_1, X_2, E_4)$}\n    \\label{fig:fcm_1}\n\n\\end{figure}\n\n\nNote that causal relations can also be \\textit{cyclic}, i.e. $X$ causes $Y$ which in turn causes \n$X$ ad infinitum; while this deserves consideration as many systems have feedback loops we will\nnot look at such settings for simplicity. \n\n\\subsection{Interventions}\n\nTo make precise the meaning of causality, suppose that we are given \ntwo random variables $X$, $Y$ with joint distribution $p_{x, y}$. Intuitively we \nwould say that $X$ causes $Y$, or $X \\rightarrow Y$, if we intervene on $X$ and then see an effect on $Y$. In particular\nwe will denote $\\operatorname{do}(x)$ --- short for $\\operatorname{do}(X = x)$ --- as an intervention\nthat forces the variable $X$ to have the value $x$, and leaves the rest of the system untouched. \nFollowing the convention inspired by \\cite{pearl2000causality}, \nwe define the resulting distribution as $p_{y|do(x)}$.\n\nThis motivates the following definition:\n\n\\begin{definition}\n    We say that $X$ \\textbf{causes} $Y$ if $p_{y|do(x)} \\neq p_{y|do(x^\\prime)}$ for some\n    $x \\neq x^\\prime$\n\\end{definition}\n\nWhen we talk about $p_{y|x}$, we often say, \"The chance of $y$ given that $x$ happened\". This sounds similar\nto $p_{y|do(x)}$; note however that \"$x$ happened\" and \"force $X = x$\" are very different. Imagine that \nthere indeed was a gene that made people both prone to smoking and cancer; then if we forced someone at \nrandom to smoke, he would on average be less likely to have cancer than someone who smoked because he wanted to.\nThis also illustrates \none of the limitations of causality: some interventions are not possible due to ethical issues.\n\nYou might have heard about randomized trials or A/B testing, these are both common ways to estimate $p_{y|do(x)}$.\nFor example, when developing cures, the idea of a random trial is to give experimental drugs to participants\nat random. When designing new UIs to maximize user participation in apps, developers implement A/B testing, \nthey assign new versions to people at random to estimate engagement. Note that in both of these, we are able \nto avoid a potential confounder by picking $x$'s at random, and \"forcing\" them to \"do$(x)$\".\n\nSince we will restrict ourselves to the observational setting, we will not be able to perform any interventions,\nwhich would allow us to estimate $p_{y|do(x)}$. In this setting however, in order to perform any meaningful\ninference, we will need to make concessions; in particular, we will make some assumptions about \nthe causal structure. If we are able to infer the causal structure in such a setting, we \nshall call it \\textbf{identifiable}.\n\n% f we have the random variables $X$, $Y$, and $Z$, then depending on how they are causaly linked, then \n% we will have different relationships between the marginals and the Pearl's \"do\" conditional. For example,\n% if $X \\rightarrow Z \\rightarrow Y$, then we will have that $p_X = p_{X|do(y)}$, but $p_Y \\neq p_{Y|do(x)}$. \n\n% Indeed, for all 6 different relations of $X$, $Y$, and $Z$ we get a different set of relationships between \n% the interventional and observational conditions. Then, assuming that we get both interventional and observational data it suffices to check to which of the 6 \n% possible structure the data corresponds to (at least in theory). \n\nWe restrict ourselves also to the bivariate case; one big difference worth noting is that in the\nmultivariate setting we can test conditional independence. Using conditional independence tests \nis a very powerful method for causal inference. Suppose \nwe have random variables $X$, $Y$ and $Z$, then if we can estimate that $X \\bigCI Y | Z$, then it must be \nthat all information between $X$ and $Y$ must flow through $Z$ (See Figure \\ref{fig:conditionalIndep}).\nThis test alone has has now greatly reduced the space of possible causal directions between these random variables.\n\nOne can in fact generalize the conditional independence such that $X$ and the other variables are \na collection of random variables, which gives a lot of flexibility to devise clever algorithms. \nThe theory comes from graphical models, which tries to understand the relationship between \ndistributions and their graphical counterparts, such as Figure \\ref{fig:conditionalIndep}.\nThe key difference is that in graphical models we do not care about the causal direction. \nSince we will not be using any of this theory, we will not go into any detail \n(a good overview can found in \\cite{bishop2006pattern}).\n\n\\begin{figure}[!h]\n    \\centering\n\n    \\begin{tikzpicture}[\n        > = stealth, % arrow head style\n        shorten > = 1pt, % don't touch arrow head to node\n        auto,\n        node distance = 2.5cm, % distance between nodes\n        thick % line style\n    ]\n    \n    \\tikzstyle{every state}=[\n        draw = black,\n        thick,\n        fill = white,\n        minimum size = 4mm\n    ]\n    \n    \\node[state] (a) {$Z$};\n    \\node[state] (b) [below left of=a] {$X$};\n    \\node[state] (c) [below right of=a] {$Y$};\n    \n    \\path[-] (a) edge node {} (b);\n    \\path[-] (a) edge node {} (c);\n    \n    \\end{tikzpicture}\n    \\caption{An example of FCM with random variables $X$, $Z$ and $Y$; we leave it undirected}\n    \\label{fig:conditionalIndep}\n\n\\end{figure}\n\nIn some sense the two variable case is hard because we cannot use conditional independence. As we will see, \nit is not possible to distinguish causality in the general bivariate setting when only observing \nobservational data; we will thus need to restrict \nthe class of such models. The underlying structure behind such causal models is what is known as \nStructural Equation Models (SEM) (\\cite{Peters2017}). Essentially \nit is a model specification; and the key insight is that it should not be reversible.\n\n\n\\section{Proposed Methods}\n\nWe propose a new type of inference method which exploits the i.i.d \nnoise assumption; the idea is to split the data in different intervals, and then to regress each \ninterval separately. In the causal direction one would expect that the residuals of each \ninterval will be more homogenous\\footnote{By homogenous residuals we mean that the residuals will be similar \nto each other, for example if we plot their respective histograms, these will asymptotically converge to the \nsame distribution}  --- in the ANM settings, asymmetries introduced\nby inversion will break the i.i.d assumption. We will conclude by \nshowing that this intuition is indeed correct, by proving that the method is consistent --- \nassuming that causal discovery is indeed possible and that the additive noise is i.i.d. We will\nalso propose a second method, however while also consistent, it requires knowledge of the \nnoise distribution, which is not a good assumption in practice. \n\n\n\\section{Outline}\n\nWe begin by formalizing further the causal framework that we will explore; we will then present an overview of \npopular methods for inference on the bivariate causal setting. Next, we will overview some notions in statistical distance \n--- as these play a central role in causal inference --- such as maximum mean discrepancy (MMD) and f-divergences. \nFor the convenience of the reader we will also review some background material that will help gain a better \nintuition on the MMD. \n\nWe will end by going over the proposed methods, and showing both theoretical guarantees and experimental results. \n\n\n\n\n", "meta": {"hexsha": "9c6fc4406ab5c41de22fe5bdb2a8bc1f129835c9", "size": 16012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main/ch1_introduction.tex", "max_stars_repo_name": "Nacho114/EPFL_thesis_template", "max_stars_repo_head_hexsha": "e92f8b0b2d14d0a514dce0fc4a83a358481a4d20", "max_stars_repo_licenses": ["MIT"], "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/ch1_introduction.tex", "max_issues_repo_name": "Nacho114/EPFL_thesis_template", "max_issues_repo_head_hexsha": "e92f8b0b2d14d0a514dce0fc4a83a358481a4d20", "max_issues_repo_licenses": ["MIT"], "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/ch1_introduction.tex", "max_forks_repo_name": "Nacho114/EPFL_thesis_template", "max_forks_repo_head_hexsha": "e92f8b0b2d14d0a514dce0fc4a83a358481a4d20", "max_forks_repo_licenses": ["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.987012987, "max_line_length": 160, "alphanum_fraction": 0.7275168624, "num_tokens": 4158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6277280594754595}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{fmsin}\n\\section*{\\hspace*{-1.6cm} fmsin}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nSignal with sinusoidal frequency modulation.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[y,iflaw] = fmsin(N)\n[y,iflaw] = fmsin(N,fmin)\n[y,iflaw] = fmsin(N,fmin,fmax)\n[y,iflaw] = fmsin(N,fmin,fmax,period)\n[y,iflaw] = fmsin(N,fmin,fmax,period,t0)\n[y,iflaw] = fmsin(N,fmin,fmax,period,t0,f0)\n[y,iflaw] = fmsin(N,fmin,fmax,period,t0,f0,pm1)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty fmsin} generates a sinusoidal frequency modulation, whose\nminimum frequency value is {\\ty fmin} and maximum is {\\ty fmax}.  This\nsinusoidal modulation is designed such that the instantaneous frequency at\ntime {\\ty t0} is equal to {\\ty f0}, and the ambiguity between increasing or\ndecreasing frequency is solved by {\\ty pm1}.\\\\\n \n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty N}       & number of points\\\\\n        {\\ty fmin}    & smallest normalized frequency          & {\\ty 0.05}\\\\\n        {\\ty fmax}    & highest normalized frequency           & {\\ty 0.45}\\\\\n        {\\ty period}  & period of the sinusoidal frequency modulation  & {\\ty N}  \\\\ \n        {\\ty t0}      & time reference for the phase           & {\\ty N/2} \\\\\n        {\\ty f0}      & normalized frequency at time {\\ty t0}     & {\\ty 0.25}\\\\\n        {\\ty pm1}     & frequency direction at {\\ty t0} (-1 or +1)& {\\ty +1}  \\\\\n  \\hline {\\ty y}       & signal\\\\\n        {\\ty iflaw}   & instantaneous frequency law \\\\\n \n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         z=fmsin(140,0.05,0.45,100,20,0.3,-1.0);\n         plot(real(z));\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nfmconst, fmlin, fmodany, fmhyp, fmpar, fmpower.\n\\end{verbatim}\n\\end{minipage}\n \n\n\n\n", "meta": {"hexsha": "cc5d078897bdcf47fc3f36882570cba14f39afe2", "size": 2332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/fmsin.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/fmsin.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/fmsin.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 26.5, "max_line_length": 85, "alphanum_fraction": 0.6252144082, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6277280583772138}}
{"text": "\\section{Cycles}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Cycle detection}\n  \\begin{exampleblock}{Cycle detection (Problem 5.24--1)}\n\t\\begin{table}[ht]\n\t  \\centering\n\t  \\renewcommand{\\arraystretch}{1.1}\n\t  \\begin{tabular}{c||c|c}\n\t    \\hline\n\t\t& Digraph \t\t\t& Undirected graph  \\\\ \\hline \\hline\n\t\tDFS & {\\uncover<2->{back edge $\\iff$ cycle}}\n\t\t& {\\uncover<3->{back edge $\\iff$ cycle}}\n\t\t\\\\ \\hline\n\t\tBFS & {\\uncover<5->{\\begin{tabular}[c]{@{}l@{}}back edge $\\implies$ cycle\\\\ cycle \\textcolor{red}{$\\centernot\\implies$} back edge \\end{tabular}}}\n\t\t& {\\uncover<4->{cross edge $\\iff$ cycle}}\n\t\t\\\\ \\hline\n\t  \\end{tabular}\n\t\\end{table}\n  \\end{exampleblock}\n\n  \\begin{columns}\n\t\\column{0.50\\textwidth}\n\t  \\uncover<6->{\\fignocaption{width = 0.30\\textwidth}{figs/bfs-digraph-cycle-without-back.png}}\n\t\\column{0.50\\textwidth}\n\t  \\uncover<7->{%\n\t\t\\begin{alertblock}{Remark}\n\t\t  How to identify back edges?\n\t\t\\end{alertblock}}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Evasiveness of acyclicity}\n  \\begin{exampleblock}{Evasiveness of acyclicity (Problem 5.24--2)}\n\t\\[\n\t  \\text{Evasiveness } \\triangleq \\text{ check } \\binom{n}{2} \\text{ edges (adjacency matrices)}\n\t\\]\n\n\t\\pause\n\t\\centerline{Is acyclicity evasive?}\n  \\end{exampleblock}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\fignocaption{width = 0.20\\textwidth}{figs/adversary-logo.png}{\\centerline{\\pause Hint: Kruskal}}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Evasiveness of connectivity}\n  \\begin{exampleblock}{Evasiveness of connectivity (Additional Problem)}\n\t\\[\n\t  \\text{Evasiveness } \\triangleq \\text{ check } \\binom{n}{2} \\text{ edges}\n\t\\]\n\n\t\\centerline{Is connectivity evasive?}\n  \\end{exampleblock}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\fignocaption{width = 0.20\\textwidth}{figs/adversary-logo.png}{\\centerline{Hint: Anti-Kruskal}}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Edge deletion}\n  \\begin{exampleblock}{Edge deletion (Problem 5.20)}\n    \\begin{itemize}\n      \\item connected, undirected graph $G$\n      \\item $\\exists? e \\in E: G \\setminus e$ is connected?\n      \\item $O(|V|)$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\[\n\t\\exists \\text{ cycle} \\iff \\exists \\text{ such } e\n  \\]\n\n  \\pause\n  \\[\n\tO(m + n)\n  \\]\n\n  \\pause\n  \\[\n\t\\text{tree: } |E| = |V| - 1 \\implies \\text{ check } |E| \\ge |V|\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Orientation of undirected graph}\n  \\begin{exampleblock}{Orientation of undirected graph (Problem 5.9)}\n\t\\begin{itemize}\n      \\item undirected (connected) graph $G$ \n\t  \\item edges oriented \\emph{s.t.} \n\t\t\\[\n\t\t  \\forall v, \\text{in}[v] \\ge 1\n\t\t\\]\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\[\n\t\\text{orientation} \\iff \\exists \\text{ cycle } C\n  \\]\n\n  \\pause\n  \\[\n\t\\text{BFS/DFS from } v \\in C\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Shortest cycle of undirected graph}\n  \\begin{exampleblock}{Shortest cycle of undirected graph (Problem 5.8)}\n\tShortest cycle of $G$:\n\t\\begin{itemize}\n\t  \\item DFS on $G$\n\t  \\item $\\forall v: \\text{level}[v]$\n\t  \\item back edge $u \\to v: \\text{level}[u] - \\text{level}[v] + 1$\n\t\\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\vspace{0.50cm}\n  \\begin{alertblock}{Question}\n\tWhat about digraphs?\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "a3f938d246f1b0ede0222c9d6f7e2f985adab1b6", "size": 3216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-graph-decomposion-20170524/sections/cycle.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-graph-decomposion-20170524/sections/cycle.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-graph-decomposion-20170524/sections/cycle.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.5238095238, "max_line_length": 147, "alphanum_fraction": 0.6212686567, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911057, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.6277280495278387}}
{"text": "\\section{Optimization objective}\\label{optimization-objective}\n\nIn support vector machine, we don't directly have $\\lambda$. Instead, C\nis used, which penalizes the training set instead of the $\\theta$. In\nreality, it's almost the same, as we can set a small value for C and\nthen we're giving more importance to the regularization term. We could\nthink of $C = \\frac{1}{\\lambda}$.\n\nInformally, the C parameter is a positive value that controls the\npenalty for misclassified training examples. A large C parameter tells\nthe SVM to try to classify all the examples correctly. \\smallskip\n\nA part from that, the objective function (minimizing cost function) is\nalmost the same as the logistic regression one:\n\n\\begin{equation} \nmin_{\\theta} C \\sum_{i=1}^m [y^{(i)}cost_1(\\theta^T x^{(i)}) + (1 - y^{(i)})cost_0(\\theta^T x^{(i)})] + \\frac{1}{2} \\sum_{j=1}^n \\theta_j^2\n\\end{equation}\n\nWhere $cost_0$ and $cost_1$ are functions that are applied when $y = 0$\nand $y = 1$, respectively. \\smallskip\n\nSVMs don't output probabilities, they output directly the class they\nclassificate into, using the following hyphotesis:\n\n\\begin{equation} \nh_\\theta(x) = \n\\begin{dcases}\n    1, & \\text{if\\,} \\theta^Tx \\geq 0 \\\\ \n    0, & \\text{otherwise}\n\\end{dcases} \n\\end{equation}\n\n\\section{Large Margin Intuition}\\label{large-margin-intuition}\n\nWe can see the SVM as a large margin classifier, meaning that if we have\nlinearly separable data, it will separate it optimizing the boundary\ndistance between the data (fig \\ref{fig:large_margin}).\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{img/large_margin.eps}\n\\caption{Example of linearly separable data correctly classified by an SVM.}\n\\label{fig:large_margin}\n\\end{figure}\n\n\\section{Kernels I}\\label{kernels-i}\n\nIn logistic regression, when we had a non-linear problem, we had to use\npolynomial features. Kernels are another way of getting more features\nout of the training sample. \\smallskip\n\nKernels are similarity functions. In the video, he selects 3 landmarks\nand uses a gaussian kernel. He then uses those 3 landmarks to compute 3\nfeatures, using the gaussian to know the similarity between x and each\nof the landmark.\n\nDoing that, we can create a decision boundary around the landmarks,\nwhere everything near them gets classified as 1 and everything that is\nfar from them gets classified as 0 (following a gaussian shape).\n\n\\section{Kernels II}\\label{kernels-ii}\n\n\\subsection{Choosing Landmarks}\\label{choosing-landmarks}\n\nFor every training example, get a landmark exactly at that location.\nThen, features will be based around the similarity of a point in our\ndata to other points. This way we have one feature per datapoint, so we\nhave m features. \\smallskip\n\nBasically, we just substitute the features we had and we use this ones.\n\nMathematical implemenation note:\n\n\\begin{equation} \n\\sum_{j=1}^n \\theta_j^2 = \\theta^t M \\theta\n\\end{equation}\n\nWhere M is a matrix that depends on the kernel. This is done to scale to\nbigger training sets.\n\n\\subsection{SVM Parameters}\\label{svm-parameters}\n\n\\begin{itemize}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item\n  Large C: Lower bias, high variance (small $\\lambda$).\n\\item\n  Small C: Higher bias, low variance (large $\\lambda$).\n\\end{itemize}\n\n\\section{Using an SVM}\\label{using-an-svm}\n\n\\begin{itemize}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item\n  Use SVM software package to solve for paraemters $\\theta$.\n\\item\n  You still need to specify the choice of parameter C and the kernel.\n\\item\n  No kernel is sometimes called ``linear kernel''.\n\\item\n  Do perfrom feature scaling before using the kernel.\n\\end{itemize}\n\nNot all similarity functions make valid kernels. They need to satisfy a\ntechnical condition called ``Mercer's Theorem''.\n\n\\subsection{Multiclass classification}\\label{multiclass-classification}\n\nMany SVM packages already have built-in multi-class classification\nfunctionality. Otherwise, use one-vs-all.\n\n\\subsection{Logistic regression vs\nSVMs}\\label{logistic-regression-vs-svms}\n\nLet n = number of features and m = number of training examples.\n\\smallskip\n\n\\begin{itemize}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item\n  If n is large relative to m -\\textgreater{} Use logistic regression or\n  SVM without kernel.\n\\item\n  If n is small, m is intermediate -\\textgreater{} Use SVM with Gaussian\n  kernel.\n\\item\n  If n is small, m is large -\\textgreater{} Create/Add features and then\n  use logistic regression or SVM without kernel.\n\\end{itemize}\n\nNeural networks is likely to work well for mos of these settings, but\nthey're way slower to train.\n\nSVMs don't have to worry about local optima, because they solve a convex\nproblem. NN may have problems with that, though.\n", "meta": {"hexsha": "6336dcc5d56a0e1a0905b680df64a5ddaf051997", "size": 4664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/07.01 - Support Vector Machines/07.01 - Support Vector Machines.tex", "max_stars_repo_name": "GMadorell/coursera-machine-learning", "max_stars_repo_head_hexsha": "7633ea83218e6f22f8ce4032f8f64d878732c2e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-11T17:56:22.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-07T02:35:55.000Z", "max_issues_repo_path": "theory/07.01 - Support Vector Machines/07.01 - Support Vector Machines.tex", "max_issues_repo_name": "GMadorell/coursera-machine-learning", "max_issues_repo_head_hexsha": "7633ea83218e6f22f8ce4032f8f64d878732c2e9", "max_issues_repo_licenses": ["MIT"], "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/07.01 - Support Vector Machines/07.01 - Support Vector Machines.tex", "max_forks_repo_name": "GMadorell/coursera-machine-learning", "max_forks_repo_head_hexsha": "7633ea83218e6f22f8ce4032f8f64d878732c2e9", "max_forks_repo_licenses": ["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.7971014493, "max_line_length": 139, "alphanum_fraction": 0.7647941681, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.6277280362220709}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm, mathtools}\n%\\usepackage{hyperref}\n\\usepackage{color}\n\\usepackage{jheppub}\n\\usepackage[T1]{fontenc} % if needed\n\n\\newcommand{\\be}{\\begin{equation}}\n\\newcommand{\\ee}{\\end{equation}}\n\\newcommand{\\bes}{\\begin{equation*}}\n\\newcommand{\\ees}{\\end{equation*}}\n\\newcommand{\\bea}{\\begin{flalign*}}\n\\newcommand{\\eea}{\\end{flalign*}}\n\n%\\linespread{1.0}\n%\\setlength{\\parindent}{0em}\n%\\setlength{\\parskip}{0.8em}\n\n\\title{\\textbf{Some Information about Gravitational Waves}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\\abstract{One needs to get accustomed with what gravitational waves are before jumping in and working on it. One hopes the two tomes by Maggiore will aid one's exploration.}\n\n\\begin{document}\n\\maketitle\n\n\\section{Gravitational Waves as Geometry}\n\n\\textit{Though Maggiore, the main reference for this tome, prefers not to use geometric units, I shall unapologetically use them.}\n\nThe gravitational action is a sum of the Einstein-Hilbert action and the matter action; $S = S_E + S_M$ where,\n\n$$S_E = \\frac{1}{16 \\pi} \\int d^4 x \\sqrt{-g}R$$\n\nThe \\textit{energy-momentum tensor} $T_{\\mu \\nu}$ is defined from the variation of the matter action under a metric change $g_{\\mu \\nu} \\rightarrow g_{\\mu \\nu} + \\delta g_{\\mu \\nu}$ as,\n\n$$\\delta S_M = \\frac{1}{2}  \\int d^4 x \\sqrt{-g} \\ T^{\\mu \\nu} \\delta g_{\\mu \\nu}$$\n\nVariation of the total action with respect to $g_{\\mu \\nu}$ yields Einstein's equations,\n$$\\boxed{R_{\\mu \\nu} - \\frac{1}{2}g_{\\mu \\nu}R = 8 \\pi T_{\\mu \\nu}}$$\n\nGeneral relativity is invariant under a huge groups of transformations $x^\\mu \\rightarrow x'^\\mu(x)$, as long as $x'$ is invertible, differentiable, and has a differentiable inverse. Such transformations are called \\textit{diffeomorphisms}. Under diffeomorphisms, $g_{\\mu \\nu}$ transforms as,\n$$g_{\\mu \\nu}(x') = \\pdv{x^\\rho}{x'^\\mu} \\pdv{x^\\sigma}{x'^\\nu} g_{\\mu \\nu}(x)$$\n\n\\subsection{Expansions around flat space}\nLets imagine that our system is a perturbation around the flat space metric,\n$$g_{\\mu \\nu} = \\eta_{\\mu \\nu} + h_{\\mu \\nu}$$\nThe magnitude of $h_{\\mu \\nu}$ is infinitesmal, and we only consider equations upto first order in $h_{\\mu \\nu}$.\n\nLets stare at the above equation for a few seconds. We know that the numerical values of the tensor depends on the choice of reference frame. So on what basis are we calling $h_{\\mu \\nu}$ infinitesmal? Actually, what we merely wish to say is that for some choice of reference frame, the above equation will be valid and we can do all our calculations. While this choice helps us simplify our calculations, it should be noted that choosing a specific reference frame breaks the diffeomorphism invariance.\n\nEven after choosing the above transformation, we still have a residual gauge freedom left. Consider $$x'^\\mu \\rightarrow x^\\mu + \\xi^\\mu (x)$$ where the derivatives of $\\xi^\\mu$ as as inifinitesmal as $h_{\\mu \\nu}$. By using the diffeomorphism property,\n$$g'_{\\mu \\nu}(x') = \\pdv{x^\\rho}{x'^\\mu} \\pdv{x^\\sigma}{x'^\\nu} g_{\\rho \\sigma}(x)$$ and substituting for the partial derivatives, one gets,\n\\begin{flalign*}\n\tg'_{\\mu \\nu}(x') &= \\left(\\delta^\\rho_\\mu - \\pdv{\\xi^\\rho}{x'^\\mu}\\right)  \\left(\\delta^\\sigma_\\nu - \\pdv{\\xi^\\sigma}{x'^\\nu}\\right)  (\\eta_{\\rho \\sigma} + h_{\\rho \\sigma}(x)) \\\\\n\t\\eta_{\\mu \\nu} + h'_{\\mu \\nu}(x') &= \\left(\\delta^\\rho_\\mu \\delta^\\sigma_\\nu - \\pdv{\\xi^\\rho}{x'^\\mu}\\delta^\\sigma_\\nu - \\pdv{\\xi^\\sigma}{x'^\\nu} \\delta^\\rho_\\mu \\right)  (\\eta_{\\rho \\sigma} + h_{\\rho \\sigma}(x))\\\\\n\th'_{\\mu \\nu}(x') &= h_{\\mu \\nu}(x) - \\pdv{\\xi_\\nu}{x'^\\mu} - \\pdv{\\xi_\\mu}{x'^\\nu} \n\\end{flalign*}\n\n\\end{document}\\grid\n", "meta": {"hexsha": "123990aa65d8ebcb856215ca3eaf82e484a6aaed", "size": 3814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "selfstudy/gws/GWs.tex", "max_stars_repo_name": "adivijaykumar/courses", "max_stars_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "selfstudy/gws/GWs.tex", "max_issues_repo_name": "adivijaykumar/courses", "max_issues_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "selfstudy/gws/GWs.tex", "max_forks_repo_name": "adivijaykumar/courses", "max_forks_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_forks_repo_licenses": ["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.9253731343, "max_line_length": 503, "alphanum_fraction": 0.7026743576, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6276439888993601}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{hyperref}\n\\usepackage{mathrsfs}\n\\usepackage{mathtools}\n\\usepackage{textcomp}\n\\usepackage{fullpage}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\theoremstyle{definition}\n\\newtheorem{definition}[theorem]{Definition}\n\n\\newcommand{\\defterm}[1]{\\textit{#1}}\n\n\\title{A Compressed Introduction to Compressed Sensing}\n\\author{Benjamin Peterson}\n\n\\begin{document}\n\\maketitle\n\n\\begin{abstract}\nWe attempt to convey a sense of compressed sensing. Specifically, we discuss how $\\ell_1$ minimization and the restricted isometry property for matrices can be used for sparse recovery of underdetermined linear systems even in the presence of noise.\n\\end{abstract}\n\n\\section{Introduction}\nSuppose $A \\in \\mathcal{M}_{m\\times n}(\\mathbb{R})$ is a matrix and we obtain a measurement $y \\in \\mathbb{R}^m$, which we know to be the image of some $x \\in \\mathbb{R}^n$ under $A$. If the system $Ax = y$ is underdetermined (i.e., $m < n$), then $x$ is not unique. Suppose however that we want a single solution and we know $x$ is ``small''. We might try to pick an $x$ which solves the equation with the least $\\ell_2$ norm by solving the convex program\n\\begin{equation}\\label{eq:l2-prog}\n\\min_{x \\in \\mathbb{R}^n}\\|x\\|_{\\ell_2}\\qquad Ax = y.\\tag{L}\n\\end{equation}\nThis program has the advantage that a unique solution is guaranteed. Unfortunately, the solution to \\eqref{eq:l2-prog} is often not the best one for applications.\n\nMany real world signals are known to be sparse (i.e.\\ having few nonzero entries) in some basis. Thus, we might alternatively seek a sparse solution for $Ax = y$. The sparsest solution to the linear equation is given by the program\n\\begin{equation}\\label{eq:l0-prog}\n\\min_{x\\in \\mathbb{R}^n} \\|x\\|_{\\ell_0}\\qquad Ax = y.\\tag{S}\n\\end{equation}\nHere the ``norm'' $\\|x\\|_{\\ell_0}$ counts the number of nonzero entries in a vector $x$. Solving \\eqref{eq:l0-prog} is a difficult NP-hard problem—the subset-sum problem may be reduced to it—in combinatorial optimization \\cite{sparse-np}. We will replace \\eqref{eq:l0-prog} with the convex program\n\\begin{equation}\\label{eq:l1-prog}\n\\min_{x \\in \\mathbb{R}^n}\\|x\\|_{\\ell_1}\\qquad Ax = y.\\tag{P}\n\\end{equation}\nSolving this program is often called ``basis pursuit'' and can be efficiently done with linear programming or specialized algorithms \\cite[ch. 15]{foucart-intro}. Relating the solutions of \\eqref{eq:l0-prog} and \\eqref{eq:l1-prog} is major goal in compressed sensing which we will explore in this paper.\n\nThere is an intuitive geometrical reason that we might expect the $\\ell_1$ norm to be better at finding sparse solutions than the $\\ell_2$ norm. The program~\\eqref{eq:l2-prog} finds smallest ball around the origin that intersects the solution subspace of $Ax = y$. The level sets of the $\\ell_1$ norm are polyhedra, which emphasize the axes. Therefore, it seems ``likely'' that the \\eqref{eq:l1-prog} finds a sparse solution in the solution subspace.\n\nWe now introduce a restriction on matrices that allows sparse solutions to be easily recovered. Recall that a vector is said to be $k$-sparse if it has at most $k$ nonzero entries.\n\\begin{definition}[\\cite{ct-decoding}]\nA matrix $A \\in \\mathcal{M}_{m\\times n}(\\mathbb{R})$ satisfies the \\defterm{restricted isometry property} (RIP) of order $k$ if there exists a $\\delta_k \\geq 0$ such that for all $k$-sparse vectors $x \\in \\mathbb{R}^n$, $$(1 - \\delta_k)\\|x\\|_{\\ell_2}^2 \\leq \\|Ax\\|_{\\ell_2}^2 \\leq (1 + \\delta_k)\\|x\\|_{\\ell_2}^2.$$\nThe smallest such $\\delta_k$ is called $A$'s \\defterm{restricted isometry constant} of order $k$.\n\\end{definition}\nNotice that $\\delta_1 \\leq \\delta_2 \\leq \\dotsb$. The RIP is related to vector space frames \\cite{ole-frames} and the Johnson-Lindenstrauss lemma \\cite{rip-jl}. Unfortunately, checking whether a matrix has the restricted isometry property is NP-Hard in general \\cite{rip-np}. On the other hand, many families of random matrices (e.g.\\ having Gaussian or Bernoulli entries) satisfy the RIP with high probability \\cite[\\S 1.3]{ctr-stable}.\n\n\\begin{theorem}[{\\cite[lemma 1.2]{ct-decoding}}]\\label{thm:unique-sparse}\nSuppose $A \\in \\mathcal{M}_{m\\times n}$ satisfies RIP with $\\delta_{2s} < 1$. Then the equation $Ax = y$ has an unique $s$-sparse solution given by \\eqref{eq:l0-prog}.\n\\end{theorem}\n\\begin{proof}\nSuppose $x, x\\in \\mathbb{R}^m$ are $s$-sparse and $Ax = Ax'$. By the RIP,\n$$\n0 \\leq (1 - \\delta_{2s})\\|x - x'\\|_{\\ell_2} \\leq \\|A(x - x')\\|_{\\ell_2} = 0.\n$$\nNecessarily, $x = x'$.\n\\end{proof}\n\nBefore stating the main theorem, we introduce the notion of error. In reality, we do not know $Ax$ exactly. Instead, we measure $y = Ax + z$, where $z \\in \\mathbb{R}^m$ is a small error vector satisfying $\\|z\\|_{\\ell_2} \\leq \\epsilon$. We would like our recovery of $x$ to be robust against error. To deal with this, we generalize \\eqref{eq:l1-prog} to the (still convex) program\n\\begin{equation}\\tag{P\\textquotesingle}\\label{eq:l1-approx}\n\\min_{x \\in \\mathbb{R}^n}\\|x\\|_{\\ell_1}\\qquad \\|Ax - y\\|_{\\ell_2} \\leq \\epsilon.\n\\end{equation}\n\nFinally, we can state the main theorem of this lecture. We denote the vector containing only the $s$ largest entries of $x$ by $x_s$.\n\\begin{theorem}[{\\cite[1.3]{candes-rip}}]\\label{thm:noisy-recovery}\nSuppose $A \\in \\mathcal{M}_{m\\times n}(\\mathbb{R})$ satisfies RIP with $\\delta_{2s} < \\sqrt{2} - 1$. Let $x^*$ denote the solution to \\eqref{eq:l1-approx}. Then, there are constants $C_0, C_1$ depending only on $\\delta_{2s}$ such that $$\\|x^* - x\\|_{\\ell_2} \\leq C_0s^{-1/2}\\|x - x_s\\|_{\\ell_1} + C_1\\epsilon.$$\n\\end{theorem}\n\nTheorem~\\ref{thm:noisy-recovery} tells us that when RIP holds, basis pursuit recovers solutions very close to sparse solutions of the equation.\n\n\\section{Proof of Theorem~\\ref{thm:noisy-recovery}}\nWe closely follow \\cite{candes-rip}.\n\nSet $x = x^* + h$. Our goal is to show $\\|h\\|_{\\ell_2}$ is small. The RIP for $A$ only gives us control over sparse vectors, so we start by breaking $h$ up into $s$-sparse vectors. Let $T_0$ be the indexes of the $s$ largest entires of $x$. Let $T_1$ be the indexes of the $k$ largest entries of $h_{T_0^c}$. Let $T_2$ be the indexes of the $s$ largest entries of $h_{(T_0\\cup T_1)^c}$ and so on. We observe that $h$ can be written as the sum of $s$-sparse vectors $h_{T_0} + h_{T_1} + h_{T_2} + \\dotsb$. Using the triangle inequality,\n\\begin{equation}\\label{eq:main-triang}\n\\|x - x^*\\|_{\\ell_2} = \\|h\\|_{\\ell_2} \\leq \\|h_{T_0\\cup T_1}\\|_{\\ell_2} + \\|h_{(T_0\\cup T_1)^c}\\|_{\\ell_2}.\n\\end{equation}\nWe will estimate the two terms of \\eqref{eq:main-triang} separately and then combine them to prove the theorem. We start by showing the $\\|h_{(T_0\\cup T_1)^c}\\|_{\\ell_2}$ term can be bounded in terms of the first term $\\|h_{T_0\\cup T_1}\\|_{\\ell_2}$. Several useful intermediate inequalities are obtained along the way.\n\n\\begin{lemma}[Tail estimates]\\label{lem:tail-estimate}\n\\begin{align}\\label{eq:small-h1}\n\\|h_{T_0^c}\\|_{\\ell_1} &\\leq \\|h_{T_0}\\|_{\\ell_1} + 2\\|x_{T_0^c}\\|_{\\ell_1}\n\\\\\n\\label{eq:tail-sum}\n\\sum_{j \\geq 2}\\|h_{T_j}\\|_{\\ell_2} &\\leq s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1} \\\\\n\\label{eq:small-h2}\n\\|h_{(T_0\\cup T_1)^c}\\|_{\\ell_2} &\\leq \\|h_{T_0}\\|_{\\ell_2} + 2s^{-1/2}\\|x - x_s\\|_{\\ell_1}\n\\end{align}\n\\end{lemma}\n\\begin{proof}\nSince $x$ is feasible for \\eqref{eq:l1-approx} and $x^*$ is a minimum,\n$$\n\\|x\\|_{\\ell_1} \\geq \\|x + h\\|_{\\ell_1} = \\sum_{i \\in T_0}|x_i + h_i| + \\sum_{i \\in T_0^c}|x_i + h_i| \\geq \\|x_{T_0}\\|_{\\ell_1} - \\|h_{T_0}\\|_{\\ell_1} + \\|h_{T_0^c}\\|_{\\ell_1} - \\|x_{T_0^c}\\|_{\\ell_1}.\n$$\nThe last step uses the triangle inequality twice. Rewriting and applying the reverse triangle inequality proves \\eqref{eq:small-h1}.\n$$\n\\|h_{T_0^c}\\|_{\\ell_1} \\leq \\|x\\|_{\\ell_1} - \\|x_{T_0}\\|_{\\ell_1} + \\|x_{T_0^c}\\|_{\\ell_1} + \\|h_{T_0}\\|_{\\ell_1} \\leq \\|h_{T_0}\\|_{\\ell_1} + 2\\|x_{T_0^c}\\|_{\\ell_1}\n$$\n\nIf $j \\geq 2$,\n$$\n\\|h_{T_j}\\|_{\\ell_2} \\leq s^{1/2}\\|h_{T_j}\\|_{\\ell_\\infty} \\leq s^{-1/2}\\|h_{T_{j - 1}}\\|_{\\ell_1}.\n$$\nSumming yields \\eqref{eq:tail-sum}.\n$$\n\\sum_{j \\geq 2}\\|h_{T_j}\\|_{\\ell_2} \\leq s^{-1/2}\\sum_{j \\geq 1}\\|h_{T_j}\\|_{\\ell_1}= s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1}\n$$\nFrom this, we immediately obtain\n\\begin{equation}\\label{eq:small-h3}\n\\|h_{(T_0\\cup T_1)^c}\\|_{\\ell_2} = \\left\\|\\sum_{j \\geq 2}h_{T_j}\\right\\|_{\\ell_2} \\leq \\sum_{j \\geq 2}\\|h_{T_j}\\|_{\\ell_2} \\leq s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1}.\n\\end{equation}\n\nBy the Cauchy-Schwarz inequality,\n\\begin{equation}\\label{eq:lem1-cs}\n\\|h_{T_0}\\|_{\\ell_1} \\leq s^{1/2}\\|h_{T_0}\\|_{\\ell_2}.\n\\end{equation}\nApplying \\eqref{eq:small-h3}, \\eqref{eq:small-h1}, and \\eqref{eq:lem1-cs} proves \\eqref{eq:small-h2}.\n$$\n\\|h_{(T_0\\cup T_1)^c}\\|_{\\ell_2} \\leq s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1} \\leq s^{-1/2}(\\|h_{T_0}\\|_{\\ell_1} + 2\\|x_{T_0^c}\\|_{\\ell_1}) \\leq \\|h_{T_0}\\|_{\\ell_2} + 2s^{-1/2}\\|x_{T_0^c}\\|_{\\ell_1}\n$$\n\\end{proof}\n\nNext, we want to bound the main part of the error term $\\|h_{T_0\\cup T_1}\\|_{\\ell_2}$. We begin with a lemma.\n\n\\begin{lemma}\\label{lem:innner-control}\nSuppose $x$ and $x'$ are $s$-sparse and $s'$-sparse respectively and supported on disjoint sets. Then\n$$\n|\\langle Ax, Ax'\\rangle| \\leq \\delta_{s + s'}\\|x\\|_{\\ell_2}\\|x'\\|_{\\ell_2}\n$$\n\\end{lemma}\n\\begin{proof}\nWe may assume without a loss of generality that $\\|x\\|_{\\ell_2} = \\|x'\\|_{\\ell_2} = 1$. The RIP tells us that\n$$\n2(1 - \\delta_{s + s'}) = (1 - \\delta_{s + s'})\\|x + x'\\|_{\\ell_2}^2 \\leq \\|Ax \\pm Ax'\\|_{\\ell_2}^2 \\leq (1 + \\delta_{s + s'})\\|x + x'\\|_{\\ell_2}^2 = 2(1 - \\delta_{s+s'}).\n$$\nBy the polarization identity,\n$$\n|\\langle Ax, Ax'\\rangle| \\leq \\frac{1}4\\left|\\|Ax + Ax'\\|_{\\ell_2}^2 - \\|Ax - Ax'\\|_{\\ell_2}^2\\right| \\leq \\delta_{s + s'}.\n$$\n\\end{proof}\n\n\\begin{lemma}[Main term estimate]\\label{lem:main-estimate}\n\\begin{equation}\\label{eq:main-term-est}\n\\|h_{T_0\\cup T_1}\\|_{\\ell_2} \\leq (1 - \\rho)^{-1}(\\alpha\\epsilon + 2\\rho s^{-1/2}\\|x - x_s\\|_{\\ell_1})\n\\end{equation}\nwhere\n$$\n\\alpha \\equiv \\frac{2\\sqrt{1 - \\delta_{2s}}}{1 - \\delta_{2s}},\\quad \\rho \\equiv \\frac{\\sqrt{2}\\delta_{2s}}{1 - \\delta_{2s}}.\n$$\n\\end{lemma}\n\\begin{proof}\nRIP allows us to control the size of $\\|h_{T_0\\cup T_1}\\|_{\\ell_2}$ with $\\|Ah_{T_0\\cup T_1}\\|_{\\ell_2}$, and so we start by bounding the latter. We break $\\|Ah_{T_0\\cup T_1}\\|_{\\ell_2}$ into parts using properties of the inner product.\n\\begin{equation}\\label{eq:main-bound}\n\\|Ah_{T_0\\cup T_1}\\|_{\\ell_2}^2 = \\langle A h_{T_0\\cup T_1}, Ah \\rangle - \\sum_{j \\geq 2}\\left(\\langle A h_{T_0}, Ah_{T_j}\\rangle + \\langle Ah_{T_1}, Ah_{T_j}\\rangle\\right)\n\\end{equation}\nFrom the triangle inequality and hypothesis,\n\\begin{equation}\\label{eq:Ah-bound}\n\\|Ah\\|_{\\ell_2} = \\|A(x - x^*)\\|_{\\ell_2} \\leq \\|Ax^* - y\\|_{\\ell_2} + \\|y - Ax\\|_{\\ell_2} \\leq 2\\epsilon.\n\\end{equation}\nThe first term of \\eqref{eq:main-bound} can be bounded using Cauchy-Schwarz, the RIP, and \\eqref{eq:Ah-bound}.\n\\begin{equation}\\label{eq:first-term-est}\n|\\langle Ah_{T_0\\cup T_1}, Ah\\rangle| \\leq \\|Ah_{T_0\\cup T_1}\\|_{\\ell_2}\\|Ah\\|_{\\ell_2} \\leq 2\\epsilon \\sqrt{1 + \\delta_{2s}}\\|h_{T_0\\cup T_1}\\|_{\\ell_2}\n\\end{equation}\nSince $T_0$ and $T_1$ are disjoint Cauchy-Schwarz gives\n$$\n\\|h_{T_0}\\|_{\\ell_2} + \\|h_{T_1}\\|_{\\ell_2} \\leq \\sqrt{2}\\|h_{T_0\\cup T_1}\\|_{\\ell_2}.\n$$\nTo estimate the sum term of \\eqref{eq:Ah-bound}, we apply lemma~\\ref{lem:innner-control} and \\eqref{eq:tail-sum}.\n\\begin{align}\n\\sum_{j \\geq 2}|\\langle Ah_{T_0}, Ah_{T_j}\\rangle| + |\\langle Ah_{T_1}, Th_{T_j}\\rangle| &\\leq \\delta_{2s}(\\|h_{T_0}\\|_{\\ell_2} + \\|h_{T_1}\\|_{\\ell_2})\\sum_{j \\geq 2}\\|h_{T_j}\\|_{\\ell_2}\n\\nonumber\\\\&\\leq \\delta_{2s}\\sqrt{2}s^{-1/2}\\|h_{T_0\\cup T_1}\\|_{\\ell_2}\\|h_{T_0^c}\\|_{\\ell_1} \\label{eq:second-term-est}\n\\end{align}\nWe now have\n$$\n(1 - \\delta_{2s})\\|h_{T_0\\cup T_1}\\|_{\\ell_2}^2 \\leq \\|Ah_{T_0\\cup T_1}\\|_{\\ell_2}^2\\leq \\|h_{T_0\\cup T_1}\\|_{\\ell_2}(2\\epsilon\\sqrt{1 +\\delta_{2s}} + \\sqrt{2}\\delta_{2s}s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1})\n$$\nfrom RIP, \\eqref{eq:first-term-est}, and \\eqref{eq:second-term-est}. We divide by $(1 - \\delta_{2s})\\|h_{T_0\\cup T_1}\\|_{\\ell_2}$.\n$$\n\\|h_{T_0\\cup T_1}\\|_{\\ell_2} \\leq \\alpha\\epsilon + \\rho s^{-1/2}\\|h_{T_0^c}\\|_{\\ell_1}\n$$\nFrom \\eqref{eq:small-h1} and \\eqref{eq:lem1-cs}, we obtain\n$$\n\\|h_{T_0 \\cup T_1}\\|_{\\ell_2} \\leq \\alpha\\epsilon + \\rho s^{-1/2}(\\|h_{T_0}\\|_{\\ell_1} + 2\\|x - x_s\\|_{\\ell_1}) \\leq \\alpha\\epsilon + \\rho \\|h_{T_0\\cup T_1}\\|_{\\ell_2} + 2\\rho s^{-1/2}\\|x - x_s\\|_{\\ell_1}.\n$$\nBy the hypothesis of theorem~\\ref{thm:noisy-recovery}, $\\rho < 1$, and we get\n$$\n\\|h_{T_0\\cup T_1}\\|_{\\ell_2} \\leq (1 - \\rho)^{-1}(\\alpha\\epsilon + 2\\rho s^{-1/2}\\|x - x_s\\|_{\\ell_1}),\n$$\nwhich completes the lemma's proof.\n\\end{proof}\n\nApplying our estimates \\eqref{eq:small-h2} and lemma~\\ref{lem:main-estimate} to the two terms of \\eqref{eq:main-triang}, we have\n$$\n\\|h\\|_{\\ell_2} \\leq 2\\|h_{(T_0\\cup T_1)}\\|_{\\ell_2} + 2s^{-1/2}\\|x - x_s\\|_{\\ell_1} \\leq 2(1 - \\rho)^{-1}(\\alpha\\epsilon + (1 + \\rho)s^{-1/2}\\|x - x_s\\|_{\\ell_1}).\n$$\nThis completes the proof of theorem~\\ref{thm:noisy-recovery}.\n\n\\section{Remarks}\nA huge amount of research in compressed sensing has appeared since the publication of the original papers \\cite{ctr-stable,donoho-cs} around 2004-2006. Among other things, researchers have investigated techniques for sparse recovery besides basis pursuit e.g.\\ matching pursuit \\cite{tg-matching}. There is also replacement condition for RIP called the nullspace property, which is a necessary and sufficient condition for \\eqref{eq:l0-prog} and \\eqref{eq:l1-prog} to have the same solutions \\cite{nullspace}.\n\nAs far as applications are concerned, compressed sensing is being used in areas as diverse as tomography, astronomy, machine linearing, linear coding, and experiment design \\cite{cs-science,dantzig-selector}. It is particularly useful in situations where minimizing the work done in sensors is important such as space probes. Gimmicks like single-pixel cameras \\cite{single-pixel} have captured the public imagination.\n\nFinally, for readers still curious, there are a lot of other (possibly more palatable) introductions to compressed sensing \\cite{cw-intro,cs-book,foucart-intro,users-guide,kutyniok-cs,qaisar-compressive,romberg-intro}.\n\n\\bibliographystyle{amsplain}\n\\bibliography{compressed_sensing}\n\n\\end{document}\n", "meta": {"hexsha": "e2d07a11ae2b20efda715a884f7156692b534f4b", "size": 14285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compressed_sensing.tex", "max_stars_repo_name": "benjaminp/compressed-sensing-intro", "max_stars_repo_head_hexsha": "c284fec4ce921d41f208ab7be324bd51d253c27c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-12-12T05:46:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-19T23:10:50.000Z", "max_issues_repo_path": "compressed_sensing.tex", "max_issues_repo_name": "benjaminp/compressed-sensing-intro", "max_issues_repo_head_hexsha": "c284fec4ce921d41f208ab7be324bd51d253c27c", "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": "compressed_sensing.tex", "max_forks_repo_name": "benjaminp/compressed-sensing-intro", "max_forks_repo_head_hexsha": "c284fec4ce921d41f208ab7be324bd51d253c27c", "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.8294930876, "max_line_length": 535, "alphanum_fraction": 0.6828841442, "num_tokens": 5579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.6274504179211038}}
{"text": "\\section{Algorithms}\n\nIn this section we will describe the randomized algorithms in detail, provide the\ncorresponding computational complexity analysis, and state the main theoretical results\nthat guarantee the accuracy of the approximation.\n\nWe split this section in three main parts: Stage 1 \\ref{sec:stage1} and Stage 2\n\\ref{sec:stage2} that will study in depth the algorithmic details of both stages,\nand Full Algorithms \\ref{sec:full-algos} in which full algorithms will be presented\nfor a diversity of matrices with certain properties.\n\n\\subsection{Stage 1}\n\\label{sec:stage1}\nIn the introductory section, we provided some intuition on the randomized procedure\nand we developed a general Proto-Algorithm \\ref{alg:proto-algorithm} to find\nthe range-approximating matrix $\\mtx{Q}$. However, Proto-Algorithm \\ref{alg:proto-algorithm} is very general and can be\ntunned depending on the problem requirements.\nThe number $T_{\\rm basic}$ of flops required by Proto-Algorithm \\ref{alg:proto-algorithm} satisfies\n\\begin{equation}\n\\label{eq:cost_basic}\nT_{\\rm basic} \\sim \\ell n \\, T_{\\rm rand} + \\ell\\,T_{\\rm mult} + \\ell^{2}m %\\,T_{\\rm flop},\n\\end{equation}\nwhere $T_{\\rm rand}$ is the cost of generating a Gaussian random number\nand $T_{\\rm mult}$ is the cost of multiplying $\\mtx{A}$ by a vector.\nThe last term comes from the orthonormalization procedure of $\\mtx{Y}$.\n\nWe will now describe some specific realizations of Proto-Algorithm \\ref{alg:proto-algorithm} \nthat will be intended for problems with different requirements.\n\n%%%%%%%%%%%%%%%%%% RANDOMIZED RANGE FINDER %%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection{Randomized Range Finder} \\label{alg:randomized-range-finder}\nThis is the most naive and simplest implementation of Proto-Algorithm \\ref{alg:proto-algorithm}.\nGiven an oversampling parameter $p$, the \\textit{Randomized Range Finder}\nperforms Proto-Algorithm \\ref{alg:proto-algorithm} with a gaussian test matrix \n$\\mtx{\\Omega}\\in\\Rspace{n\\times\\ell}$ with $\\ell=k+p$ and $k$ being a pre-specified\ntarget rank. Then, it orthogonalizes the rows of the resulting matrix $\\mtx{Y}$ by computing\na QR decomposition. A numerical issue arises when computing the orthogonalization\nprocedure due to the fact that the columns of $\\mtx{Y}$ are almost linearly\ndependent. The authors in ~\\cite{halko2011finding} found that\nusing the \\textit{double orthogonalization} \n~\\cite{bjorck1994numerics} was enough to guarantee stability\nof the procedure.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\fbox{\n\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Randomized Range Finder}\n\\end{center}\n\\begin{tabbing}\n\\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\kill\n\\anum{1} \\>Draw an $n\\times \\ell$ Gaussian random matrix $\\mtx{\\Omega}$.\\\\\n\\anum{2} \\>Form the $m\\times \\ell$ matrix $\\mtx{Y} = \\mtx{A}\\mtx{\\Omega}$.\\\\\n\\anum{3} \\>Construct an $m \\times \\ell$ matrix $\\mtx{Q}$ whose columns form an orthonormal\\\\\n         \\> basis for the range of $\\mtx{Y}$, e.g., using the QR factorization $\\mtx{Y} = \\mtx{Q}\\mtx{R}$.\n\\end{tabbing}\n\\end{minipage}}\n\\end{center}\n\\end{figure}\n\nThe complexity analysis of the Algorithm \\ref{alg:randomized-range-finder}\ngives\n\n\\begin{equation}\\label{eq:analysis-rand-finder}\nT_{\\text{Randomized Range Finder}}\\sim \\mathcal{O}(mn\\ell)\n\\end{equation}\n\nthis is because generating a gaussian random number is $\\mathcal{O}(1)$\nand computing a matrix vector multiplication is $\\mathcal{O}(mn)$\n\\footnote{Note that parallel computation can be extremely helpful here\nto drastically reduce the effective complexity of the product $\\mtx{A}\\mtx{\\Omega}$.}. \nOne important observation is that the complexity $\\mathcal{O}(mn\\ell)$\ncan be prohibitive for massive datasets \\footnote{Obviously, we can't hope\nto do better than $\\mathcal{O}(mn)$ which is the size of the matrix\nwe want to approximate. The term that we want to address is the linear term\nin $\\ell$. Classical algorithms to compute the $\\ell$-SVD cost \n$\\mathcal{O}(mn\\ell)$, by first computing s rank-revealing QR factorization\n~\\cite{gu1996efficient} and then manipulating the terms to get to the desired\nfactorization.}. A variant of this procedure\nwill be studied in \\ref{alg:fast-randomized-range-finder}\nto get around this problem,\n\n%%%%%%%%%%%%%%%%%% ADAPTIVE RANDOMIZED RANGE FINDER %%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection{Adaptive Randomized Range Finder}\n\\label{alg:adaptive-randomized-range-finder}\n\nOne important pitfall of the \\textit{Randomized Range Finder}\n\\ref{alg:randomized-range-finder} is that it\nrequires to know in advance the target rank $k$. However, if we intend\nto solve the \\textit{fixed-precision approximation problem}, we need a scheme to estimate\nthe error $\\|\\mtx{A}-\\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}\\|$ during the algorithm\nin order to match the requited tolerance $\\epsilon$.\n\nThis scheme is possible and it is direct consequence of the following lemma.\n\\begin{lemma}\n\\label{thm:aposteriori}\nLet $\\mtx{B}$ be a real $m\\times n$ matrix.\nFix a positive integer $r$ and a real number $\\alpha > 1$.\nDraw an independent family $\\{ \\vct{\\omega}^{(i)} : i = 1, 2, \\dots, r \\}$\nof standard Gaussian vectors.  Then\n\\begin{equation*}\n\\norm{\\mtx{B}}\n    \\leq \\alpha \\sqrt{\\frac{2}{\\pi}} \\max_{i = 1, \\dots, r}\n    \\smnorm{}{\\mtx{B}\\vct{\\omega}^{(i)} }\n\\end{equation*}\nexcept with probability $\\alpha^{-r}$.\n\\end{lemma}\n\nLemma \\ref{thm:aposteriori} says that we can bound the error with high\nprobability using inexpensive computations in an online manner. \nThe Lemma \\ref{thm:aposteriori} applied to our problem reads\n\n\\begin{equation}\n\\label{eq:errorest}\n\\norm{ (\\Id - \\mtx{Q}\\mtx{Q}^{\\adj})\\mtx{A}}\n    \\leq 10 \\sqrt{\\frac{2}{\\pi}} \\max_{i = 1, \\dots, r}\n    \\smnorm{}{ (\\Id - \\mtx{Q}\\mtx{Q}^{\\adj}) \\mtx{A}\\vct{\\omega}^{(i)} }\n\\end{equation}\nwith probability at least $1 - 10^{-r}$.\n\nThe high probability bound \\ref{eq:errorest} gives a simple online scheme\nto decide when we have a good enough $\\mtx{Q}$ that matches the pre-specified\ntolerance. The goal here is to find an integer $l$ and a $m\\times l$\northonormal matrix $\\mtx{Q}^{(l)}$ such that\n\\begin{equation} \\label{eqn:err_est_err_bd}\n\\smnorm{}{ \\big(\\Id - \\mtx{Q}^{(\\ell)} (\\mtx{Q}^{(\\ell)})^{\\adj} \\big)\\mtx{A} } \\leq \\eps.\n\\end{equation}\n\nWe call \\textit{Adaptive Randomized Range Finder}\n\\ref{alg:adaptive-randomized-range-finder} to the\nalgorithm derived from Lemma \\ref{thm:aposteriori} that solves this\nproblem.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\fbox{\n\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Adaptive Randomized Range Finder}\n\\end{center}\n\\begin{tabbing}\n\\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\kill\n\\anum   {1} \\> Draw standard Gaussian vectors $\\vct{\\omega}^{(1)}, \\dots, \\vct{\\omega}^{(r)}$ of length $n$.\\\\\n\\anum{2} \\> For $i = 1,2,\\dots,r$, compute $\\vct{y}^{(i)} = \\mtx{A}\\vct{\\omega}^{(i)}$.\\\\\n\\anum{3} \\> $j=0$.\\\\\n\\anum{4} \\> $\\mtx{Q}^{(0)} = [\\ ]$, the $m\\times 0$ empty matrix. \\\\\n\\anum{5} \\> \\textbf{while} $\\displaystyle\n         \\max\\left\\{\\smnorm{}{\\vct{y}^{(j+1)}},\\smnorm{}{\\vct{y}^{(j+2)}},\\dots,\\smnorm{}{\\vct{y}^{(j+r)}} \\right\\} >\n\\varepsilon/(10\\sqrt{2/\\pi})$,\\\\\n\\anum{6} \\> \\> $j = j + 1$.\\\\\n\\anum{7} \\> \\> Overwrite $\\vct{y}^{(j)}$ by $\\bigl(\\Id - \\mtx{Q}^{(j-1)}(\\mtx{Q}^{(j-1)})^{\\adj}\\bigr)\\vct{y}^{(j)}$.\\\\\n\\anum{8} \\> \\> $\\vct{q}^{(j)} = \\vct{y}^{(j)}/\\norm{\\vct{y}^{(j)}}$.\\\\\n\\anum{9} \\> \\> $\\mtx{Q}^{(j)} = [\\mtx{Q}^{(j-1)}\\ \\vct{q}^{(j)}]$.\\\\\n\\anum{10} \\> \\> Draw a standard Gaussian vector $\\vct{\\omega}^{(j+r)}$ of length $n$.\\\\\n\\anum{11} \\> \\> $\\vct{y}^{(j+r)} = \\left(\\Id - \\mtx{Q}^{(j)}(\\mtx{Q}^{(j)})^{\\adj}\\right)\\mtx{A}\\vct{\\omega}^{(j+r)}$.\\\\\n\\anum{12} \\> \\> \\textbf{for} $i = (j+1),(j+2),\\dots,(j+r-1)$,\\\\\n\\anum{13} \\> \\> \\> Overwrite $\\vct{y}^{(i)}$ by $\\vct{y}^{(i)} - \\vct{q}^{(j)}\\ip{\\vct{q}^{(j)}}{\\vct{y}^{(i)}}$.\\\\\n\\anum{14} \\> \\> \\textbf{end for}\\\\\n\\anum{15} \\> \\textbf{end while}\\\\\n\\anum{16} \\> $\\mtx{Q} = \\mtx{Q}^{(j)}$.\n\\end{tabbing}\n\\end{minipage}}\n\\end{center}\n\\end{figure}\n\nOne important question regarding Algorithm \\ref{alg:adaptive-randomized-range-finder}\n is how good the bound given by Lemma \\ref{thm:aposteriori}\nis in practice. If there is a significant gap between theory and practice\nthe optimal $l$ will be overestimated. This question will be addressed in the experimental section\n\\ref{sec:gaussian-matrices}.\n\n%%%%%%%%%%%%%%%%%% RANDOMIZED POWER ITERATION %%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection{Randomized Power Iteration}\n\\label{alg:randomized-power-iteration}\n\nThe \\textit{Randomized Range Finder} \\ref{alg:randomized-range-finder}\nalgorithm assumes that the singular values\nof the matrix decay fast. This can be intuitively seen from equation \\ref{eq:iter-range},\nwhere the small singular\nvalues interfere with the calculation of the range. This intuition is made precise \nin Theorem \\ref{thm:avg-frob-error-gauss}, where the error of the approximation depends on\nthe $\\sigma_{k+1}$ and $\\sum_{j>k}\\sigma_j^2$.\n\nThe goal here is to reduce the weight of the\nsmall singular values by taking powers of the matrix whose range we want\nto approximate. Instead of applying the sampling scheme to $\\mtx{A}$, we will\napply it to $\\mtx{B}=(\\mtx{A}\\mtx{A}^\\adj)^q\\mtx{A}$ where $q>0$ is a small\ninteger.\n\nThe matrix $\\mtx{B}$ has the same singular vectors than $\\mtx{A}$ (hence, \nthe same range), but its singular values decay much more quickly.\n\n\\begin{equation}\\label{eq:sing-values-power}\n\\sigma_j(\\mtx{B}) = \\sigma_j(\\mtx{A})^{2q+1},\n\\hspace{0.5cm} j=1,2,3,\\ldots\n\\end{equation}\n\nThe \\textit{Randomized Power Iteration}\n\\ref{alg:randomized-power-iteration} algorithm is the same \nas the \\textit{Randomized Range Finder} \\ref{alg:randomized-range-finder}\n but replacing the formula\n$\\mtx{Y}=\\mtx{A}\\mtx{\\Omega}$ by $\\mtx{Y}=\\mtx{B}\\mtx{\\Omega}$.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\fbox{\n\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Randomized Power Iteration}\n\\end{center}\n\\begin{tabbing}\n\\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\kill\n\\anum{1} \\>Draw an $n\\times \\ell$ Gaussian random matrix $\\mtx{\\Omega}$.\\\\\n\\anum{2} \\>Form the $m\\times \\ell$ matrix $\\mtx{Y} = (\\mtx{A}\\mtx{A}^{\\adj})^{q}\\mtx{A}\\mtx{\\Omega}$ via alternating application\\\\\n         \\>of $\\mtx{A}$ and $\\mtx{A}^{\\adj}$.\\\\\n\\anum{3} \\>Construct an $m \\times \\ell$ matrix $\\mtx{Q}$ whose columns form an orthonormal\\\\\n         \\> basis for the range of $\\mtx{Y}$, e.g., via the QR factorization $\\mtx{Y} = \\mtx{Q}\\mtx{R}$.\n\\end{tabbing}\n\\end{minipage}}\n\\end{center}\n\\end{figure}\n\nThe computational complexity of the Algorithm \\ref{alg:randomized-power-iteration}\nis essentially the same because\nit only requires $2q+1$ as many matrix-multiplications as Algorithm\n\\ref{alg:randomized-range-finder}\nbut the number $q$ is in practice 2,3 or 4. This can be seen from \nCorollary \\ref{cor:power-method-spec-gauss},\nwhich shows that the power iteration drives the approximation\ngap to 1 exponentially fast as $q$ increases.\n\n\n%%%%%%%%%%%%%%%%%% FAST RANDOMIZED RANGE FINDER %%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsubsection{Fast Randomized Range Finder}\n\\label{alg:fast-randomized-range-finder}\n\nA simple inspection to equation \\ref{eq:cost_basic} reveals the computational\nbottleneck of the sampling procedure. This is the matrix multiplication\n$\\mtx{Y}=\\mtx{A}\\mtx{\\Omega}$ that takes $\\mathcal{O}(mn\\ell)$ operations\nfor dense matrices, which is the same as the $\\ell$-SVD.\n\nThe key idea is to use a \\textit{structured} random matrix that allows us \nto compute the product in $\\mathcal{O}(mn\\log(\\ell))$ operations.\n\nThe simplest structured random matrix that meets our goals is the so-called\n\\textit{subsampled random Fourier transform} (SRFT).\n\nAn SRFT is an $n \\times \\ell$ matrix of the form\n\\begin{equation}\n\\label{eq:def_srft}\n\\mtx{\\Omega} = \\sqrt{\\frac{n}{\\ell}} \\, \\mtx{DFR},\n\\end{equation}\nwhere\n\\lsp\n\\begin{itemize}\n\\item   $\\mtx{D}$ is an $n \\times n$ diagonal matrix whose entries are\nindependent random variables uniformly distributed on the complex unit circle.\n\n\\item   $\\mtx{F}$ is the $n \\times n$ unitary discrete Fourier transform (DFT),\nwhose entries take the values $f_{pq} = n^{-1/2} \\, \\econst^{-2\\pi\\iunit (p-1)(q-1)/n}$ for $p, q = 1, 2, \\dots, n$\n\n\\item   $\\mtx{R}$ is an $n \\times \\ell$ matrix that samples $\\ell$ coordinates\nfrom $n$ uniformly at random, i.e., its $\\ell$ columns are drawn randomly\nwithout replacement from the columns of the $n \\times n$ identity matrix.\n\\end{itemize}\n\\lsp\n\nNow, via a subsampled FFT ~\\cite{woolfe2008fast}, we can compute the\nsample matrix $\\mtx{Y}=\\mtx{A}\\mtx{\\Omega}$ with\n$\\mathcal{O}(mn\\log(\\ell))$ operations.\n\nThe total number of operations required by this procedure is reduced to\n\\begin{equation}\n\\label{eq:cost_SRFT}\nT_{\\rm struct} \\sim mn \\log(\\ell) + \\ell^2 n\n\\end{equation}\n\nHence, the computational complexity of the approach is essentially\n$\\mathcal{O}(mn \\log(\\ell))$.\n\n% If $\\ell$ is substantially larger than the numerical rank $r(\\mtx{A})$\n% \\ref{eq:num-rank}, then the orthogonalization can be done in\n% $\\mathcal{O}(k\\ell n)$ instead of $\\mathcal{O}(\\ell^2n)$.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\fbox{\n\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Fast Randomized Range Finder}\n\\end{center}\n\\begin{tabbing}\n\\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\hspace{5mm} \\= \\kill\n\\anum{1} \\>Draw an $n\\times \\ell$ SRFT test matrix $\\mtx{\\Omega}$, as defined by \\eqref{eq:def_srft}. \\\\\n%\\pgnotate{Added reference.}\\\\\n\\anum{2} \\>Form the $m\\times \\ell$ matrix $\\mtx{Y} = \\mtx{A}\\mtx{\\Omega}$ using a (subsampled) FFT.\\\\\n\\anum{3} \\>Construct an $m \\times \\ell$ matrix $\\mtx{Q}$ whose columns form an orthonormal\\\\\n         \\> basis for the range of $\\mtx{Y}$, e.g., using the QR factorization $\\mtx{Y} = \\mtx{Q}\\mtx{R}$.\n\\end{tabbing}\n\\end{minipage}}\n\\end{center}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STAGE 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\subsection{Stage 2} \\label{sec:stage2}\n The output of the Stage 1 \\ref{sec:stage1} produces an orthonormal matrix $\\mtx{Q}$ whose\n range captures the action of the matrix $\\mtx{A}$. The goal of Stage 2\n \\ref{sec:stage2} is \n to produce standard approximate matrix factorizations of $\\mtx{A}$\n using this $\\mtx{Q}$.\n\nThis subsection is divided into three parts; first, we will show how to compute\nstandard approximate matrix factorizations (SVD and QR) from a general \napproximate low-rank factorization. Recall that taking $\\mtx{B}=\\mtx{Q}$\nand $\\mtx{C}=\\mtx{Q}^\\adj\\mtx{A}$ we readily have a factorization that\nsatisfies $\\|\\mtx{A}-\\mtx{B}\\mtx{C}\\|\\leq\\varepsilon$.\nThen, we will describe in detail the \\textit{Direct SVD} algorithm, which will\nconsist in constructing an SVD from $\\mtx{B}$ and $\\mtx{C}$. Finally, we will\ncomment on other more involved methods that avoid computing the expensive\nproduct $\\mtx{C}=\\mtx{Q}^\\adj\\mtx{A}$.\n\n\\subsubsection{Compute standard QR and SVD from a general factorization}\nNow we will specify how we can compute the standards SVD and QR decompositions\nfrom a general low rank decomposition $\\|\\mtx{A} - \\mtx{B}\\mtx{C}\\|\\leq\\varepsilon$\nmaintaining the tolerance $\\epsilon$ from Stage 1 \\ref{sec:stage1}.\n\n\\begin{itemize}\n  \\item \\label{itm:SVD-from-C} \\textit{SVD decomposition:} $\\|\\mtx{A}-\\mtx{U}\\mtx{\\Sigma}\\mtx{V}^\\adj\\|\\leq\\varepsilon$\n\\lsp\n\\begin{enumerate}\n\\item Compute a QR factorization of $\\mtx{B}$ so that $\\mtx{B} = \\mtx{Q}_{1}\\mtx{R}_{1}$.\n\\item Form the product $\\mtx{D} = \\mtx{R}_{1}\\mtx{C}$, and compute an SVD:\n      $\\mtx{D} = \\mtx{U}_{2}\\mtx{\\Sigma}\\mtx{V}^{\\adj}$.\n\\item Form the product $\\mtx{U} = \\mtx{Q}_{1}\\mtx{U}_{2}$.\n\\end{enumerate}\n\\lsp\n% The result is a diagonal matrix $\\mtx{\\Sigma}$ and orthonormal matrices $\\mtx{U}$ and $\\mtx{V}$\n% such that $\\norm{\\mtx{A} - \\mtx{U}\\mtx{\\Sigma}\\mtx{V}^{\\adj}} \\leq \\varepsilon$.\n\n\\item \\label{itm:QR-from-C} \\textit{QR decomposition:} $\\|\\mtx{A}-\\mtx{Q}\\mtx{R}\\|\\leq\\varepsilon$\n\\lsp\n\\begin{enumerate}\n\\item Compute a QR factorization of $\\mtx{B}$ so that $\\mtx{B} = \\mtx{Q}_{1}\\mtx{R}_{1}$.\n\\item Form the product $\\mtx{D} = \\mtx{R}_{1}\\mtx{C}$, and compute a QR factorization: $\\mtx{D} = \\mtx{Q}_{2}\\mtx{R}$.\n\\item Form the product $\\mtx{Q} = \\mtx{Q}_{1}\\mtx{Q}_{2}$.\n\\end{enumerate}\n% The result is an orthonormal matrix  $\\mtx{Q}$ and a weakly upper-triangular matrix $\\mtx{R}$ such\n% that $\\norm{\\mtx{A} - \\mtx{Q}\\mtx{R}} \\leq \\varepsilon$.\n\n\\end{itemize}\n\n\\subsubsection{Direct SVD} \\label{alg:direct-svd}\n\nThe procedure described in \\ref{itm:SVD-from-C} to compute the approximate \nSVD decomposition without sacrificing error, defines what we call\nthe \\textit{Direct SVD} \\ref{alg:direct-svd}.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\fbox{\\begin{minipage}{.9\\textwidth}\n\\begin{center}\n\\textsc{Direct SVD}\n\\end{center}\n\\anum{1}    Form the matrix\n$\n\\mtx{B} = \\mtx{Q}^{\\adj}\\mtx{A}.\n%\\mtx{B} = \\bigl(\\mtx{A}^{\\adj}\\mtx{Q}\\bigr)^{\\adj}.\n$\n\n\\anum{2}    Compute an SVD of the small matrix:\n$\n\\mtx{B} = \\widetilde{\\mtx{U}}\\mtx{\\Sigma}\\mtx{V}^{\\adj}.\n$\n\n\\noindent\n\\anum{3}    Form the orthonormal matrix\n$\n\\mtx{U} = \\mtx{Q}\\widetilde{\\mtx{U}}.\n$\n\\end{minipage}}\n\\end{center}\n%\\caption{trash}\n%\\label{alg:Atranspose}\n\\end{figure}\n\nAlthough using \\textit{Direct SVD} \\ref{alg:direct-svd} algorithm for\nStage 2 \\ref{sec:stage2} does not incur additional errors, the computation\nof $\\mtx{C}=\\mtx{Q}^\\adj\\mtx{A}$ is in general too expensive for dense matrices.\n\nMore concretely, the product costs $\\mathcal{O}(mn\\ell)$, even more\nexpensive that the cost of Stage 1 \\ref{sec:stage1} when using\nthe accelerated Algorithm\n\\ref{alg:fast-randomized-range-finder}.\n\n\\subsubsection{Different Procedures} \\label{sec:dif-app}\n\n\\begin{itemize} \n    \\item \\textit{Match the cost} $\\mathcal{O}(mn\\log(\\ell))$ \\textit{of accelerated\n    Stage 1} \\ref{alg:fast-randomized-range-finder}.\n\n    In order to match the complexity $\\mathcal{O}(mn\\log(\\ell))$ from \nStage 1 \\ref{sec:stage1} we must avoid the product $\\mtx{Q}^\\adj\\mtx{A}$.\n\nIn \\cite{halko2011finding}, the authors propose algorithms based\non row extraction of $\\mtx{Q}$ via its \\textit{Interpolative Decomposition}\n$\\mtx{Q}=\\mtx{X}\\mtx{Q}_{(J,:)}$ \\cite{cheng2005compression}.\nNow, $\\mtx{Q}_{(J,:)}$ is a $k\\times k$ matrix. The proposed\nalgorithm takes $\\mtx{Q}$ as input and constructs a rank-$k$ matrix \nfactorization\n\n\\begin{equation}\\label{eq:via-row-extraction}\n\\mtx{A}\\approx\\mtx{X}\\mtx{B}\n\\end{equation}\nwhere $\\mtx{B}$ is a $k \\times n$ matrix consisting of $k$ rows\nextracted from $\\mtx{A}$.\n\nThe key here is that \\ref{eq:via-row-extraction} can be produced without any large\nmatrix-matrix multiplication resulting in a total of $\\mathcal{O}(k^2(m+n))$\noperations. The drawback is that the initial error is larger than the one\nincurred by $\\mtx{Q}^\\adj\\mtx{Q}\\mtx{A}$\n\\footnote{In \\cite{halko2011finding}, they prove that the error is increased at \nmost by $\\left(\\sqrt{1+4k(n-k)}\\right)\\varepsilon$, which can be large\nwhen $\\varepsilon$ is not that small or $kn$ is large.}.\n\n\\item \\textit{Single-Pass algorithms}\n\nThe previously described algorithms require revisit the matrix $\\mtx{A}$\nmultiple times. In \\cite{halko2011finding} they propose single-pass\nalgorithms relying on the observation that all the information\nyou need to compute the decomposition is in the matrices $\\mtx{\\Omega},\\mtx{Y}$\nand $\\mtx{Q}$. They call the Algorithm \\textit{Eigenvalue Decomposition in\nOne-pass}. However, this algorithm too adds additional error to the Stage 1\n\\footnote{Authors in \\cite{halko2011finding} argue that this issue can be\naddressed with extra oversampling.}.\n\\end{itemize}\n\n\\subsection{Full Algorithms}\\label{sec:full-algos}\nLet's now propose a full algorithm depending on the input matrix properties.\n\n\\begin{itemize}\n\\item \\textit{General Matrices That Fit in Core Memory}\n\nIn this case, the appropiate method for Stage 1 is the accelerated\nAlgorithm \\ref{alg:fast-randomized-range-finder} that uses structured random\nmatrices. For Stage 2, use the \\textit{row-extraction technique}\ndescribed in \\ref{sec:dif-app}. The overall cost $T_{\\rm random}$ reduces to\n\n\\begin{equation} \\label{eq:cost-1}\n\\boxed{T_{\\rm random} \\sim mn \\log(k) + k^2 (m+n)}\n\\end{equation}\nThe overall approximation error satisfies\n\\footnote{This can be derived by combining the error analysis\nof range approximation with SRFT (which can be found in \\cite{halko2011finding})\nand the additional error incurred by the \\textit{row-extraction technique}.}\n\\begin{equation} \\label{eq:totalerror-1}\n\\norm{ \\mtx{A} - \\mtx{U\\Sigma V}^\\adj }\n    \\lesssim n \\cdot \\sigma_{k+1},\n\\end{equation}\n\n\\item \\textit{Matrices for which Matrix-Vector Products are Cheap.}\n\nIn this set of matrices we include for example sparse and structured matrices for\nwhich the matrix-vector multiplication is substantially cheaper than the general case.\n\nThe appropiate method for Stage 1 is Algorithm \\ref{alg:randomized-range-finder}\nwith $p$ constant \\footnote{If we are dealing\nwith the \\textit{fixed-precision problem}, then we use \nAlgorithm \\ref{alg:adaptive-randomized-range-finder}.}, or more generally\nAlgorithm \\ref{alg:randomized-power-iteration} with $q>0$. For Stage 2, we apply\nthe \\textit{Direct SVD} \\ref{alg:direct-svd}. The total cost $T_{\\rm sparse}$ satisfies\n\\begin{equation}\n\\label{eq:sparsealg-cost}\n\\boxed{T_{\\rm sparse} = (2q+2)\\,(k + p) \\, T_{\\rm mult} + \\bigO(k^2 (m + n))}\n\\end{equation} \n\nThe overall approximation error satisfies (see Corollary \\ref{cor:power-method-spec-gauss}).\n\\begin{equation}\n\\label{eq:sparsealg-error2}\n\\norm{ \\mtx{A} - \\mtx{U\\Sigma V}^\\adj } \\lesssim (kn)^{1/2(2q+1)} \\cdot \\sigma_{k+1}.\n\\end{equation}\n\n\\end{itemize}\n\n\n\\newpage", "meta": {"hexsha": "57f30c917031213f9c88e42a01fde935b14fe6ec", "size": 21485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/algorithms.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/algorithms.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/algorithms.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": 43.668699187, "max_line_length": 130, "alphanum_fraction": 0.7006748895, "num_tokens": 6988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6274504130918599}}
{"text": "\\section{Comparison with empirical portfolio returns}\n\\label{sec:comparison_returns}\n\nWith the definition of the four different distributions we proceed to compare\nthem with empirical data from 200 stocks traded in the S\\&P 500 stock market\nindex.\n\nAs described in Sect. \\ref{sec:exact_distributions}, we obtain normalized all\nthe time series in the market data, the we compute the covariance matrix and\nobtain the corresponding eigenvalues and eigenvectors. Using them we rotate and\nscale the returns, and finally, we aggregate the rotated and scaled returns\ninto a single univariate distribution.\n\nIn Fig. \\ref{fig:gg_dist} we plot four Gaussian-Gaussian distributions with\nfit parameter $N = 2, 3, 4, 5$. The best fit seems to be the distributions\nwith $N = 3$ and $N = 4$.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]\n    {figures/08_gg.png}\n    \\caption{Gaussian-Gaussian probability density\n             $\\left\\langle p \\right\\rangle_{GG'}^{\\left(k\\right)}$, in the\n             Markovian case, normalized to unit standard deviation for\n             different values of $N$, and aggregated distribution returns\n             $\\left(\\tilde{r}\\right)$ for fixed covariance for $200$ companies\n             selected from the S\\&P 500 dataset and $\\Delta t = 1d$. (left)\n             semilog scale and (right) loglog scale.}\n    \\label{fig:gg_dist}\n\\end{figure}\n\nFor the Gaussian-Algebraic distribution and Algebraic-Gaussian distribution,\nwe have to add an additional shape parameter $L$ and $l$, respectively. In\nFig. \\ref{fig:ga_dist} we plot four Gaussian-Algebraic distributions and in\nFig. \\ref{fig:ag_dist} we plot four Algebraic-Gaussian distributions with fit\nparameters $N = 2, 3, 4, 5$. In both cases, a good agreement when $N = 4$ can\nbe seen.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]\n    {figures/08_ga.png}\n    \\caption{Gaussian-Algebraic probability density\n             $\\left\\langle p \\right\\rangle_{GA'}^{\\left(k\\right)}$, in the\n             Markovian case, normalized to unit standard deviation for\n             different values of $N$, and aggregated distribution returns\n             $\\left(\\tilde{r}\\right)$ for fixed covariance for $200$ companies\n             selected from the S\\&P 500 dataset and $\\Delta t = 1d$. (left)\n             semilog scale and (right) loglog scale.}\n    \\label{fig:ga_dist}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]\n    {figures/08_ag.png}\n    \\caption{Algebraic-Gaussian probability density\n             $\\left\\langle p \\right\\rangle_{AG'}^{\\left(k\\right)}$, in the\n             Markovian case, normalized to unit standard deviation for\n             different values of $N$, and aggregated distribution returns\n             $\\left(\\tilde{r}\\right)$ for fixed covariance for $200$ companies\n             selected from the S\\&P 500 dataset and $\\Delta t = 1d$. (left)\n             semilog scale and (right) loglog scale.}\n    \\label{fig:ag_dist}\n\\end{figure}\n\nFinally, in Fig. \\ref{fig:aa_dist} we plot four Algebraic-Algebraic\ndistributions with fit parameters $N = 2, 3, 4, 5$. In this case we use the\nshape parameters $L$ and $l$. Again, a good agreement when $N = 4$ can be seen.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]\n    {figures/08_aa.png}\n    \\caption{Algebraic-Algebraic probability density\n             $\\left\\langle p \\right\\rangle_{AA'}^{\\left(k\\right)}$, in the\n             Markovian case, normalized to unit standard deviation for\n             different values of $N$, and aggregated distribution returns\n             $\\left(\\tilde{r}\\right)$ for fixed covariance for $200$ companies\n             selected from the S\\&P 500 dataset and $\\Delta t = 1d$. (left)\n             semilog scale and (right) loglog scale.}\n    \\label{fig:aa_dist}\n\\end{figure}\n", "meta": {"hexsha": "79c6aadd2c10454ca719f87fce30c897f06ffbc4", "size": 3888, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/exact_distributions_financial_paper/sections/08_empirical_results.tex", "max_stars_repo_name": "juanhenao21/exact_distributions_financial", "max_stars_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-20T18:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-15T07:25:50.000Z", "max_issues_repo_path": "paper/exact_distributions_financial_paper/sections/08_empirical_results.tex", "max_issues_repo_name": "juanhenao21/exact_distributions_financial", "max_issues_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_issues_repo_licenses": ["MIT"], "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/exact_distributions_financial_paper/sections/08_empirical_results.tex", "max_forks_repo_name": "juanhenao21/exact_distributions_financial", "max_forks_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_forks_repo_licenses": ["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.2857142857, "max_line_length": 79, "alphanum_fraction": 0.6867283951, "num_tokens": 1037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6274503965288432}}
{"text": "\\chapter{Network Theory}\n\\label{ch:networktheory}\n\n\\begin{chapterabstract}\nThe theory underpinning complex networks is discussed, covering the representation of atomic systems as networks and the relationship of the dual network to ring structure.\nThe laws which govern the topological properties of physical networks are also introduced, namely Euler's law (mean node degree), \\lm's law (node degree distribution) and the \\aw{} law (node degree correlations).\n\\end{chapterabstract}\n\n\\section{Network Theory}\n\\label{sec:networktheory}\n\nThe scope of what constitutes a complex network is extremely broad, covering everything from the tangible (\\eg{} computational clusters) to the more abstract (\\eg{} social interactions). Yet part of the appeal and power of network science is the ability to quantify and relate these highly disparate systems with the same underlying theory.\nA network is simply a collection of components termed \\textit{nodes} and the connections between them termed \\textit{links}, an example of which is given in figure \\ref{fig:smallnet}.\nThere are then two fundamental classes of network based on the nature of the connections.\nNetworks in which the links between nodes are mutual are termed undirected, whereas those in which the links are one\\--way are termed directed \\cite{barabasi2016n}.\nAt the risk of dating this thesis, this is the difference between Facebook (an undirected social network of friends) and Twitter (a directed social network of followers).\nAll the networks considered in this work are undirected and all the theory assumes this property.\n\n\\begin{figure}[ht]\n     \\centering\n      \\includegraphics[width=0.45\\textwidth]{./figures/methods/small_periodic_net.pdf}\n     \\caption{Example of a periodic \\td{} network where nodes are represented by circles and links as lines. Nodes are coloured similarly according to their degree, whilst periodic images are faded to highlight the central repeating unit.}\n     \\label{fig:smallnet}\n\\end{figure}\n\n\\subsection{Node Degree and Probability Distributions} \n\\label{s:theorynodeprob}\n\nA key concept in network science is the the node degree, defined as the number of links associated with each node.\nA node with $k$ links is then said simply to have degree $k$, where $k\\in\\mathbb{N}$.\nThis is illustrated in figure \\ref{fig:smallnet}, which consists of 5\\--, 6\\-- and 7\\-- degree nodes (coloured blue, grey and red respectively).\nThe occurrence and correlations of nodes of given degrees can then be described by a range of probability distributions.\n\nThe probability of a randomly selected node having degree $k$ is given by the node degree distribution, denoted $p_k$.\nThis is a normalised discrete distribution such that\n\\begin{equation}\n\t\\label{eq:pknorm}\n\t\\sumk p_k = 1.\n\\end{equation}\nThe $n$\\th{} moments of this distribution are then given by:\n\\begin{equation}\n\t\\label{eq:pkmoment}\n\t\\langle k^{n} \\rangle = \\sumk k^np_k.\n\\end{equation}\nAlternatively, one can also calculate the probability that a randomly selected link has a $k$\\--degree node at the end, denoted $q_k$.\nThis is not the same as the distribution above, as there is greater chance of selecting links which emanate from high degree nodes, in a manner which is proportional to the node degree.\nAs this distribution is normalised, this leads to the relations:\n\\begin{align}\n\t\\sumk q_k &= 1, \\label{eq:qknorm} \\\\\n\tq_k &= \\frac{kp_k}{\\langle k \\rangle} \\label{eq:qkpk}.\n\\end{align}\nIn addition, one can also evaluate the probability that a randomly chosen link has nodes of degree $j,k$ at either end.\nThis is the edge joint degree distribution, denoted $e_{jk}$. \nOnce again this is normalised and satisfies the following relationships:\n\\begin{align}\n\t\\sumjk e_{jk} &= 1, \\label{eq:ejknorm} \\\\\n\t\\sumk e_{jk} &= q_j, \\label{eq:ejkqk} \\\\\n\te_{jk} &= e_{kj} \\label{eq:ejkekj},\n\\end{align}\nwhere the final result arises from reciprocal nature of the links in an undirected network.\nAs an illustration of these different distributions, examples %for all three probability distributions \nare provided below for the network in figure \\ref{fig:smallnet}:%, where the adjacent numbers correspond to the node degrees:\n\\begin{align}\n\t\\mathbf{p} =  \\frac{1}{16} \\, \\begin{blockarray}{*{1}{c} l}\n\t\\begin{block}{[*{1}{c}]>{$\\footnotesize}l<{$}}\n\t4 \\: \\bigstrut[t]& 5\\\\\n\t8 & 6 \\\\\n\t4 & 7 \\\\\n\t\\end{block}\n\t\\end{blockarray},\n\t\\qquad\n\t\\mathbf{q} =  \\frac{1}{96} \\, \\begin{blockarray}{*{1}{c} l}\n\t\\begin{block}{[*{1}{c}]>{$\\footnotesize}l<{$}}\n\t20 \\: \\bigstrut[t]& 5\\\\\n\t48 & 6 \\\\\n\t28 & 7 \\\\\n\t\\end{block}\n\t\\end{blockarray},\n\t\\qquad\t\n\t\\mathbf{e} = \\frac{1}{96}\\: \\begin{blockarray}{*{3}{c} l}\n\t\\begin{block}{*{3}{>{$\\footnotesize}c<{$}} l}\n\t5 & 6 & 7 \\\\\n\t\\end{block}\n\t\\begin{block}{[*{3}{c}]>{$\\footnotesize}l<{$}}\n\t2 & 9 & 9 \\: \\bigstrut[t]& 5\\\\\n\t9 & 22 & 17 & 6 \\\\\n\t9 & 17 & 2 & 7\\\\\n\t\\end{block}\n\t\\end{blockarray}.\n%\t\\textbf{p} = \\frac{1}{96}\\: \\begin{blockarray}{*{5}{c} l}\n%\t\\begin{block}{*{5}{>{$\\footnotesize}c<{$}} l}\n%\t3 & 6 & 7 & 8 & 9 \\\\\n%\t\\end{block}\n%\t\\begin{block}{[*{5}{c}]>{$\\footnotesize}l<{$}}\n%\t0 & 0 & 5 & 10 & 1\\: \\bigstrut[t]& \\:3\\\\\n%\t0 & 0 & 1 & 1 & 0 & \\:6 \\\\\n%\t5 & 1 & 14 & 14 & 1 & \\:7\\\\\n%\t10 & 1 & 14 & 14 & 1 & \\:8\\\\\n%\t1 & 0 & 1 & 1 & 0 & \\:9\\\\\n%\t\\end{block}\n%\t\\end{blockarray}\n\\end{align}\n\n\\subsection{Atomic and Ring Networks}\n\\label{s:atomringnetworks}\n\nTo see how network theory relates to atomic materials, consider the amorphous graphene configuration in figure \\ref{fig:graphdualgraph}.\nIn this network the nodes represent carbon atoms and the links sp$^2$ bonds.\nThe node degree in the atomic network for all nodes is then equal to three, being equivalent to the atomic coordination number (which throughout this thesis will be denoted by $c$).\nThis is problematic, because whilst there is clear disorder in the system, it is not well captured by the atomic network.\nDue to the fact that the local environment around the atoms is identical, when examining the node degree distribution, any information about the glassy structure is lost.\nThis network is to at least first order indeterminable from a crystalline hexagonal lattice.\n\n\\begin{figure}[bt]\n     \\centering\n     \n     \\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/graph.pdf}\n         \\caption{Atomic network}\n         \\label{fig:graphdualgraph}\n     \\end{subfigure}\n     \\hfill\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/dual.pdf}\n         \\caption{Ring network}\n         \\label{fig:graphdualdual}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/graph_dual.pdf}\n         \\caption{Dual relationship}\n         \\label{}\n     \\end{subfigure}\n     \\hfill\n     \n     \\caption{Panel (a) gives an example of a 3\\--coordinate periodic atomic network with disordered ring structure. Nodes and links represent atoms and bonds respectively where rings are coloured by size. Panel (b) gives the corresponding ring network where nodes and links represent rings and their adjacencies, where nodes are coloured by degree. Panel (c) shows the dual relationship between the atomic and ring networks, where the node degree in the ring network is equal to the ring size in the atomic network.}\n     \\label{fig:graphdual}\n\\end{figure}\n\nObserving figure \\ref{fig:graphdualgraph} one can see there is another level of structure in the network, namely that of the ring structure.\nA ring is strictly any closed path of sequentially linked nodes in a network, but this thesis will use the term in reference only to the primitive rings \\ie{} those which cannot be subdivided into two smaller rings \\cite{Yuan2002}.\nA ring of size $k$ (or $k$\\--ring) is then defined as a ring with $k$ constituent nodes.\nIt is clear that finding and counting the number of rings of each size, often termed calculating the ring statistics, is a method of quantifying the disorder in the system \\cite{Kumar2014}.\nThe ring statistics can be summarised by the normalised probability distribution, $p_k$.\n\nHowever, there is a more efficient way of representing and quantifying the ring structure in the system, and that is by constructing the dual network \\cite{Aboav1984}.\nThe dual is generated by placing a node at the centre of each ring and linking the nodes of adjacent (\\ie{} edge\\--sharing) rings, as in figure \\ref{fig:graphdualdual}.\nThis will be referred to as the ring network.\nThe ring network is a reciprocal lattice in which the node degree, $k$, is equivalent to the ring size in the atomic network.\nSimilarly, it consists solely of triangles, reflecting the 3\\--coordinate nature of the underlying atomic network.\nHence, the disorder is captured directly in the node properties of the ring network.\nThese characteristics make the ring network preferable for manipulating and analysing the systems in this thesis.\n\n\\section{Topological Laws}\n\\label{s:topolaws}\n\nThere are a number of laws which govern the topological properties of \\td{} network\\--forming materials.\nThese laws constrain the ring structure, influencing the network properties in a manner that makes physical networks unique in the field of network science.\nThese laws act on a number of ``levels'': Euler's law controls the overall mean ring size, \\lm's{} law the ring size distribution and the \\aw{} law the ring\\--ring correlations.\n\n\\subsection{Euler's Law}\n\\label{s:eulerslaw}\n\nEuler's law constrains the mean ring size, $\\ki$, in an atomic network,  equivalent to the mean node degree of the ring network.\nThe atomic networks studied in this work are all \\td{}, connected (\\ie{} there is a path between any two nodes) and planar (\\ie{} they have no overlapping links) and so are subject to Euler's formula which states:\n\\begin{equation}\n\t\\label{eq:eulerformula}\n\tN + V - E = \\chi,\n\\end{equation}\nwhere $N$, $V$, $E$ are the number of rings, vertices and edges in the network and $\\chi$ in an integer termed the Euler characteristic, which is dependent on the global topology of the system.\nEach vertex represents an atom and the number of edges emanating from each vertex is then the coordination number.\n\nFor generality, consider an atomic network with atoms of assorted coordination numbers, $c$. \nIf the proportion of each coordination type is $x_c$, then the mean coordination number is given by $\\langle c \\rangle = \\sum\\limits_c cx_c$.\nThis allows the number of edges to be written in terms of the number of vertices as $E=\\frac{V}{2}\\langle c \\rangle$. \nIn turn the mean ring size is simply the total number of vertices per ring, allowing for multiple counting, such that $\\ki=\\frac{V}{N}\\langle c \\rangle$.\nSubstituting these two expressions into equation \\eqref{eq:eulerformula} leads to the expression:\n\\begin{equation}\n\t\\label{eq:avdegree}\n\t\\ki = \\frac{2\\langle c \\rangle\\left(1-\\chi/N\\right)}{\\langle c \\rangle - 2}.\n\\end{equation}\nHence the average node degree in the ring network (equivalent to the mean ring size of the physical network), is simply related to the average degree of the physical network (\\ie{} local coordination environment), the topology of the system and the number of rings.\n\nAlthough equation \\eqref{eq:avdegree} may appear simple, it is a very powerful constraint. \nTo demonstrate this consider a two\\--dimensional lattice with two possible coordination environments $c=3,4$. \nThe planar case with periodic boundary conditions (mimicking an infinite planar lattice) maps onto the torus with $\\chi=0$, and so:\n\\begin{equation}\n\t\\label{eq:2dplanarcases}\n\t\\ki = \\begin{cases}\n\t\t6, \\quad x_3 = 1 \\\\\n\t\t4, \\quad x_4 = 1 \\\\\n\t\t5, \\quad x_3 = 2/3,\\, x_4 =1/3\n\t\\end{cases}.\n\\end{equation}\nTo reiterate in plain terms, this means that if there is a material consisting of atoms all forming exactly three bonds (as for amorphous carbon), the mean ring size \\textit{must} be equal to six. \nSimilarly if all atoms form four bonds the mean ring size is four, and if there is a two\\--thirds to one\\--third mixture of coordination environments the mean ring size is five.\nThe simplest illustrations of these are the hexagonal, square and Cairo  tilings, shown in figure \\ref{fig:lattices}, but this law holds equally well for amorphous configurations.\nFor aperiodic systems strictly $\\chi=1$, but as $N\\rightarrow \\infty$, the proportion of vertices with unsatisfied coordination on the sample perimeter become negligible overall, hence does the term in $\\chi$.\nTherefore in reality these relationships hold, and remain as applicable to amorphous graphene as the basalt columns in Fingal's Cave, and the Penrose tiling \\cite{Goehring2014,Ressouche2009}.\n\nThis analysis also extends to spherical topology where $\\chi=2$, and so:\n \\begin{equation}\n \t\\label{eq:2dsphericalcases}\n\t\\ki = \\begin{cases}\n\t\t\\frac{6N-12}{N}, \\quad x_3 = 1 \\\\\n\t\t\\frac{4N-8}{N}, \\quad x_4 = 1\n\t\\end{cases}\\,.\n\\end{equation}\nThese relationships are the origin of the 12 pentagon rule for 3-coordinate fullerenes (the ``football problem''), or equivalently an ``8 triangle rule'' in the 4\\--coordinate case, as this is the only way to satisfy these equations if the allowed ring sizes are limited to $k=5,6$ and $k=3,4$ respectively (as in figures \\ref{fig:latticesfull92} and \\ref{fig:latticesfull98}) \\cite{Fowler1996}.\nMuch of the richness in the structural behaviour of \\td{} physical networks stems from this fundamental constraint on the network average degree.\n\n\\begin{figure}[bt]\n     \\centering\n     \n     \\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[height=2.4cm]{./figures/methods/hex.pdf}\n         \\caption{Hexagonal}\n         \\label{fig:latticeshex}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[height=2.4cm]{./figures/methods/cai.pdf}\n         \\caption{Cairo}\n         \\label{fig:latticescairo}\n     \\end{subfigure}\n     \\hfill\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n         \\centering\n         \\includegraphics[height=2.4cm]{./figures/methods/sq.pdf}\n         \\caption{Square}\n         \\label{fig:latticessq}\n     \\end{subfigure}\n     \\hfill\n     \\vspace{0.5cm}\n     \n       \\begin{subfigure}[b]{0.45\\textwidth}\n         \\centering\n         \\includegraphics[height=2.4cm]{./figures/methods/full92.pdf}\n         \\caption{3\\--coordinate fullerene}\n         \\label{fig:latticesfull92}\n     \\end{subfigure}\n     \\hspace{1cm}\n     \\begin{subfigure}[b]{0.45\\textwidth}\n         \\centering\n         \\includegraphics[height=2.4cm]{./figures/methods/full98.pdf}\n         \\caption{4\\--coordinate fullerene}\n         \\label{fig:latticesfull98}\n     \\end{subfigure}\n     \n     \\caption{Panels (a)\\--(c) give planar tilings of 6\\--, 5\\-- and 4\\-- rings, where the ring size is related to the underlying atomic coordination. Panels (d) and (e) show the 3\\-- and 4\\-- coordinate tilings in spherical topology, where the mean ring size is reduced due to the change in the Euler characteristic.}\n     \\label{fig:lattices}\n\\end{figure}\n\n\\subsection{\\lm's Law}\n\\label{s:lemaitre}\n\nKnowing that the mean node degree is fixed by Euler's law, the next level of available information is the form of the underlying degree distribution, $p_k$.\nInterestingly, the degree distributions found in physical ring networks seem relatively well defined.\nFor instance, it has been noted in models and realisations of \\td{} silica glass that the ring statistics looked to follow a lognormal distribution \\cite{Shackelford1981,Buchner2017}.\n\\lm{} \\etal{} demonstrated that the distribution in 3-coordinate networks systems can be well described by a maximum entropy distribution \\cite{Gervois1992}.\n\\lm's{} maximum entropy method is summarised here, trivially extended to arbitrary coordination.\n\nThe entropy of a probability distribution is defined as \n\\begin{equation}\n\t\\mathcal{S}=-\\sumk p_k\\log p_k. \n\\end{equation}\nIn addition, the degree distribution has the following constraints:\n\\begin{align}\n\t\t\\sumk p_k &=1, \\\\\n\t\t\\sumk kp_k&=\\ki,  \\label{con:lm2}\\\\\n\t\t\\sumk \\frac{p_k}{k}&=\\text{constant} \\label{con:lm3},\n\\end{align}\nwhere the first two constraints correspond to the normalisation condition and the fixed mean ring size, and the final constraint will be discussed below.\nThe entropy can then be maximised using Lagrange's method of undetermined multipliers to yield the result:\n\\begin{equation}\n\t\\label{eq:mepk}\n\tp_k = \\frac{e^{-\\lambda_1 k - \\lambda_2 / k}}{\\sumk e^{-\\lambda_1 k - \\lambda_2 / k}},\n\\end{equation}\nwhich can be solved numerically by substitution into equations \\eqref{con:lm2} and \\eqref{con:lm3}. \nBy allowing the chosen constant to vary, a family of maximum entropy curves can be generated, as in figure \\ref{fig:lm1}.\nThe resulting distributions can be summarised by relating the variance, $\\mu_2=\\kii-\\ki^2$, to a single chosen node degree probability, leading to the plot known as \\lm's law, given in figure \\ref{fig:lm2}.\nIt is usually framed in the context of the proportion of hexagons in a system, $p_6$, for the precise reason that most networks have $\\ki=6$ and $p_6$ as the largest contribution.\nMany experimental and theoretical studies have shown good agreement to this law \\cite{Caer1993,Cerisier1996,Miklius2012}.\n\nSimple extensions of the classic law are however possible, by modifying the mean degree or the permitted degree range.\nFor instance, $k$ is usually taken in the interval $k\\geq3$ (as the triangle, $k=3$, is the smallest polygon), but there can be manifestations of physical systems where only certain degrees are accessible \\cite{Rivier1988}.\nGood examples of such systems are procrystalline lattices, which are explored in chapter \\ref{ch:procrystals}, in which the underlying lattice constraints may preclude the formation of odd membered rings or rings greater than a certain size. \n\\lm{} curves for a selection of $\\ki$ and $k$\\--range modifications are given in figure \\ref{fig:lm3}. \nThe maximum values of these curves, as indicated by circular points, are determined by removing constraint \\eqref{con:lm3}, equivalent to setting $\\lambda_2=0$ in equation \\eqref{eq:mepk}.\nOne can see that these modifications can lead to marked differences in the maximum entropy solutions.\nIn particular, removing the possibility of small rings ($k<\\ki$) forming reduces the maximum variance, as these are required to offset very large rings ($k\\gg\\ki$) in order to maintain the fixed mean ring size.\n\n\n\\begin{figure}[bt]\n     \\centering\n     \n     \\begin{subfigure}[b]{0.45\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/lm_1.pdf}\n         \\caption{Maximum entropy distributions}\n         \\label{fig:lm1}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.45\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/lm_2.pdf}\n         \\caption{\\lm's law}\n         \\label{fig:lm2}\n     \\end{subfigure}\n     \\hfill\n     \n     \\vspace{2mm}\n      \\begin{subfigure}[b]{0.45\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./figures/methods/lm_3.pdf}\n         \\caption{Extensions to \\lm's law}\n         \\label{fig:lm3}\n     \\end{subfigure}\n     \\hfill\n\n    \n     \\caption{Illustration of \\lm's maximum entropy method. Panel (a) gives examples of explicit maximum entropy distributions with different values of $p_6$. Panel (b) shows how these distributions can be summarised in a plot of $p_6$ \\vs{} $\\mu_2$ (\\lm's law). Panel (c) provides extensions to the law by modifying the underlying constraints of the mean ring size and allowable $k$\\--range, with circles indicating maximal values.}\n     \\label{fig:lm}\n\\end{figure}\n\nThe only somewhat puzzling aspect of this successful theory is the choice of constraint \\eqref{con:lm3}.\nIt was originally rationalised on the basis that the areas of rings of a given size, $A_k$, can be well fit by an expression $A_k = ak+b+c/k$, where $a,b,c$ are constants.\nAs noted at the time, this is by no means true for all systems and in fact is contrary to the widely known Lewis law, which states that $A_k$ is linear in $k$ for many observable networks \\cite{Lewis1928,Fortes1995,Kim2014}.\nOverall, there does not appear to be a strong physical basis for this constraint, its justification relying on the perceived universality of the \\lm{} law, and  hence it can be viewed as a tool that engineers the correct behaviour in the underlying distributions. \n\n%Despite this, the universality of the \\lm{} law suggests that there must be a physical basis to \\eqref{con:lm3}, and in the section \\ref{s:assortativity} it will be demonstrated that it can be regenerated by considering ring adjacencies.\n\n\\subsection{\\aw{} Law}\n\\label{s:awlaw}\n\nThe ring statistics given by \\lm's law are an important measure for physical networks, but they do not provide a complete characterisation of the ring structure, as they say nothing about the ring adjacencies. \nThis is important because whilst with the same ring statistics it is theoretically possible to organise the rings in many different arrangements, it is well known experimentally that only a subset of these are observed.\nThe vast majority of physical systems have a preference for small rings ($k<\\ki$) be adjacent to large rings ($k>\\ki$).\nThis effect was first noted in the grains of polycrystals by Aboav \\cite{Aboav1970}.\nAboav quantified these ring correlations by measuring the mean ring size about a $k$\\--ring, denoted $m_k$, and found empirically that $m_k \\approx 5 + 8/k$.\n\nIn an attempt to explain this observation, Weaire formulated the %following\nrelationship:\n\\begin{equation}\n\t\\label{eq:weairesumrule}\n\t\\sumk km_kp_k = \\sumk k^2p_k = \\mu_2 + \\ki^2,\n\\end{equation}\nknown as Weaire's sum rule \\cite{Weaire1974}.\nAlthough Weaire's original proof was not rigorous, the sum rule has since been shown to be exact, and formulations have also been constructed for use in higher dimensions \\cite{Chiu1994}.\nFrom this he suggested the modification of $m_k=5+\\left(6+\\mu_2\\right)/k$ which satisfied this rule.\nAboav's original equation then became a special case when $\\mu_2=2$, which is close to the expected value for a random collection of Voronoi polygons (see section \\ref{s:voronoiintro}).\nAboav proposed that if a generic form of $m_k = A + B/k$ was used in conjunction with Weaire's sum rule then\n\\begin{equation}\n\tm_k = A+\\frac{\\mu_2+\\ki^2-A\\ki}{k}.\n\\end{equation}\nThis is now more commonly expressed in the linear form \\cite{Chiu1995}:\n\\begin{equation}\n\t\\label{eq:aboavweaire}\n\tkm_k = \\mu_2+\\ki^2+\\ki\\left(1-\\alpha\\right)\\left(k-\\ki\\right).\n\\end{equation}\nEquation \\ref{eq:aboavweaire} is known as the \\aw{} law and relates the mean ring size about a given central ring to a single fitting parameter, $\\alpha$.\nThe value of $\\alpha$ describes the strength of the ring correlations, with a larger positive value indicating a greater tendency for small\\--large ring adjacencies.\nMore specifically, the random limit can be deduced by evaluating $\\frac{\\partial{m_k}}{\\partial{k}}=0$ as \\cite{Delannay1994}:\n\\begin{equation}\n\t\\label{eq:awrandlim}\n\t\\alpha=-\\frac{\\mu_2}{\\ki^2}.\n\\end{equation}\nHence all systems with $\\alpha>-\\mu_2/\\ki^2$ have more small\\--large ring  adjacencies than would be expected from chance whilst conversely those with $\\alpha<-\\mu_2/\\ki^2$ have more small\\--small and large\\--large pairings.\n\n\\begin{figure}[tb]\n     \\centering\n      \\includegraphics[width=0.45\\textwidth]{./figures/methods/aw_demo.pdf}\n     \\caption{Calculation of an \\aw{} fit for three configurations (shown in figures \\ref{fig:zach_high}\\--\\ref{fig:zach_low}). The value of the $\\alpha$ parameter quantifies the tendency of small rings to be adjacent to large rings, with a larger value indicating stronger small\\--large ring correlations.}\n     \\label{fig:awdemo}\n\\end{figure}\n\nDespite the \\aw{} law being purely empirical and there being no topological requirement for $m_k$ to vary systematically with $k$, the law does seem to hold well for a diverse set of physical systems.\nThe law is used %for example \nin studies of materials, emulsions, biological tissues as well as in planetary science \\cite{LeRoux2013,Roy2018,Noever1992,Mombach1993,Pedro2008}.\nAs an example of the calculation% of the \\aw{} parameter\n, the plots of the fits for the systems in figure \\ref{fig:zach} are presented in figure \\ref{fig:awdemo}, along with the corresponding $\\alpha$ parameters.\nThis demonstrates two contrasting aspects of the \\aw{} law. \nFirstly the law holds very well, especially given the fact that these samples consist of just 20 rings each.\nHowever, it also demonstrates that the law is by no means exact and that some uncertainty is inevitably introduced during the linear regression.\nThis dichotomy will be discussed in detail in section \\ref{s:awdeficiencies}, where it will be shown that the \\aw{} law can be replaced by another measure from network theory, namely the assortativity.\n", "meta": {"hexsha": "f129737e835eb9e1d8670a0e1e57bac95cc61ed0", "size": 24945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/theory.tex", "max_stars_repo_name": "dormrod/Thesis", "max_stars_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-14T11:17:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-14T11:17:18.000Z", "max_issues_repo_path": "text/theory.tex", "max_issues_repo_name": "dormrod/Thesis", "max_issues_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_issues_repo_licenses": ["MIT"], "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/theory.tex", "max_forks_repo_name": "dormrod/Thesis", "max_forks_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_forks_repo_licenses": ["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.7979539642, "max_line_length": 517, "alphanum_fraction": 0.7402685909, "num_tokens": 6658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430604060731, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6274423479486677}}
{"text": "\\section{Probability Distributions}\n\n    \\subsection{What is a probability distribution?}\n    A probability distribution is a method of displaying data that displays the probabilities of every possible outcome. We'll need to define a few types of distributions first though, which are uniform and non-uniform distributions.\n    \\begin{definition}\n        Uniform Distribution: A distribution is called uniform when all of the outcomes are equally likely, just like a single die roll.\n    \\end{definition}\n    \\begin{definition}\n        Non-Uniform Distribution: A distribution is called non-uniform when not all of the outcomes are equally likely, just like rolling the sum of a pair of dice.\n    \\end{definition}\n    The variable we measure when calculating these, is called the random variable, and is denoted as $X$. The various possibilities for $X$ are the outcomes, denoted $x$. We'll typically find the probability distributions that rely on two different types of variables: discrete and continuous variables. \n    \\begin{definition}\n        Discrete Variables: These are values that are typically separate from each other, and have a finite number of possibilities.\n    \\end{definition}\n    \\begin{definition}\n        Continuous Variables: These are values that have an infinite number of possibilities, such as a length of time.\n    \\end{definition}\n    \n    \\subsection{Sigma Notation \\& Regular Probability Distributions}\n    Sigma Notation, or $\\sum_{}^{}$, may look terrifying, but it simply means the sum of a lot of numbers. We use this when finding an expected value of something, which we'll denote as $E(x)$. To find this, we'll use the equation below.\n    \\begin{equation*}\n        E(x) = \\sum_{i=1}^{n}x_{i}P(x_{i})\n    \\end{equation*}\n    To break it down, the $i=1$ is the start, the $n$ is the stop, $x_{i}$ is the outcome, and $P(x_{i})$ is the possibility of that outcome.\n    To show this in action, let's suppose that in a game, you'll get the amount of points you'll roll on a die.\n    To find that, we'll need to use find $E(x)$.\n    We know that the probability of rolling each number is $\\frac{1}{6}$, and we know all the outcomes, so let's fill out the equation. First, we'll need to set our limits though.\n    \\begin{equation*}\n        E(x) = \\sum_{i=1}^{6}\n    \\end{equation*}\n    This means that we must repeat the $x_{i}P(x_{i})$ starting at one, going to six, which would be six times.\n    Now we'll expand that below.\n    \\begin{equation*}\n        E(x) = 1(\\frac{1}{6}) + 2(\\frac{1}{6}) + 3(\\frac{1}{6}) + 4(\\frac{1}{6}) + 5(\\frac{1}{6}) + 6(\\frac{1}{6})\n    \\end{equation*}\n    We can also simplify this, as we know it is a uniform distribution. Shown below is the updated equation for this uniform distribution.\n    \\begin{equation*}\n        E(x) = \\frac{1}{6}(1 + 2 + 3 + 4 + 5 + 6)\n    \\end{equation*}\n    \n    \\subsection{Binomial Distribution}\n    Remember binomials from combinations? They look like this $\\binom{x}{y}$, and come in handy when working with distributions.\n    We have to mention something called a Bernoulli Trial first.\n    \\begin{definition}\n        Bernoulli Trials: This refers to repeated, independent trials that are measured in terms of success, or failure (or other Boolean outcomes).\n    \\end{definition}\n    The probability distribution of the number of successes in Bernoulli Trials is called a binomial distribution, and is found using the equation below.\n    \\begin{equation*}\n        P(x) = \\binom{n}{x}p^{x}q^{n-x}\n    \\end{equation*}\n    The equation solves for the probability of exactly $x$ successful trials out of $n$ total trials. In this equation, $p$ represents the probability of success, and $q$ represents the probability of failure.\n    To find the expected value for a binomial distribution, we'll resort to using the formula below.\n    \\begin{equation*}\n        E(x) = n\\cdot p\n    \\end{equation*}\n\n    \\subsection{Geometric Distributions}\n    A geometric distribution is found when an experiment is repeated just \\textbf{until the first success}.\n    It differs from binomial distributions, as the number of trials is not known at the start. \n    Just before the success, there is something called a \"waiting period\". \n    \\begin{definition}\n        Waiting Period: This is the number of failures before the first and only success. \n    \\end{definition}\n    If you have 8 failures before your success, then you have a waiting period of 8.\n    To solve for the probability of success after $x$ failures, we can use the formula below.\n    Remember, $x$ represents the waiting period.\n    \\begin{equation*}\n        P(x) = q^{x}p^{1}\n    \\end{equation*}\n    In this equation, the variable $p$ \\textbf{must have a max of one} as you can never have more than one success in a Geometric Distribution. To find your expected waiting period, you must solve for $E(x)$, which you can do by using the formula below.\n    \\begin{equation*}\n        E(x) = \\frac{q}{p}\n    \\end{equation*}\n    \\subsection{Hyper\\textemdash Geometric Distribution}\n    Hyper-Geometric Distribution are quite similar to Geometric Distributions, yet they are dependent, rather than independent.\n    Repeated sampling without replacement exhibits this type of process.\n    To find the probability of this, we must use the equation below, where $n$ represents the total number of choices,\n    $r$ represents the total number of items chosen,\n    $a$ represents the number of successes to choose from, and\n    $x$ represents the successes chosen.\\\\\n    \\begin{equation*}\n        P(x) = \\frac{\\binom{a}{x}\\cdot \\binom{n-a}{r-x}}{\\binom{n}{r}}\n    \\end{equation*}\n    We can also find the number of expected successes chosen by using the formula below, using the same variables as in the equation above.\n    \\begin{equation*}\n        E(x) = r \\cdot \\frac{a}{n}\n    \\end{equation*}", "meta": {"hexsha": "6f6cac04c426de792c52b872912dbbf2afb03609", "size": 5830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "highschool-projects/MDM4UI/Distributions.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/Distributions.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/Distributions.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": 67.0114942529, "max_line_length": 304, "alphanum_fraction": 0.7063464837, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.627442340208268}}
{"text": "\\chapter{ODE Example Revisited}\\label{ext:ode-example}\nOne way by which modelers can improve the quality of parameter estimates is by collecting more data.\nWe consider what would happen if our measurement equipment were able to capture twice as many observations.\nFurthermore, we verify computationally that using more precise measurement equipment improves the precision of the MUD estimate.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Different Measurement Equipment}\nInstead of using equipment that operates at $100$Hz, we take $200$ measurements every second, resulting in 400 equispaced observations for $t \\in (1,3)$.\nAll other choices involved in the experiment (assumed equipment tolerance, number of trials, parameter samples), are kept the same.\nWe refer to this setup wit faster measurement equipment as the ``alternative'' design.\n\n\nWe show the resulting predictions for the signal using MUD points from twenty repeated trials in Figure~\\ref{fig:ode-alt-reference} using the first twenty (middle) and all of the measurements (bottom).\nThe top of the figure shows the solution from the original setup \\ref{fig:ode-reference} for visual comparison.\nThe true signal is well-recovered even with a small subset of the data collected.\nBy the time all measurements are used, the stability of the solutions\\---with respect to the noise that may have polluted them\\---is evidenced by the fact that the red lines representing solutions disappear against the backdrop of the true signal in black.\n\n\\begin{figure}[htbp]\n  \\includegraphics[width=\\linewidth]{figures/ode/ode_20_reference_solution.png}\n  \\includegraphics[width=\\linewidth]{figures/ode/ode-alt_20_reference_solution.png}\n  \\includegraphics[width=\\linewidth]{figures/ode/ode-alt_400_reference_solution.png}\n  \\caption{Gray lines are the initial parameter samples.\n  The true signal (black) is well-recovered by the MUD estimates (red).\n  (Top): First twenty measurements used to solve the original problem.\n  (Middle): First twenty measurements used to solve the alternative problem.\n  (Bottom): The entire value $\\param_i$ ($1\\leq i \\leq N$), in the sampled parameter set.\n  }\n  \\label{fig:ode-alt-reference}\n\\end{figure}\n\nTo quantify accuracy and stability of the MUD solutions, we solve the problem for the same choices of $S$ as the original problem (with the addition of $S=400$).\nWe show the resulting error plots for convergence in the right half of Figures~\\ref{fig:ode-convergence-alt}, juxtaposed against the original experimental design with $100$Hz equipment.\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.475\\linewidth]{figures/ode/ode_convergence_mud_obs_mean_comp.png}\n  \\includegraphics[width=0.425\\linewidth]{figures/ode/ode_convergence_mud_obs_var_comp.png}\n\n  \\caption{Convergence of the MUD point given $N=1E3$ model evaluations for increasing numbers of observations for randomly placed sensors.\n  Convergence rates are estimated using first-order linear regressions in $\\text{log}_{10}$-space.\n  $100$Hz equipment demonstrates a reduction of uncertainty and improvement in precision as $S$ increases towards $200$.\n  We observe the same rates of convergence for the alternative equipment and note the (slightly) lower overall error for equal numbers of measurements ($S=200$ corresponding to $t\\in (1,2)$ in this formulation).\n  }\n  \\label{fig:ode-convergence-alt}\n\\end{figure}\n\nThe convergence rates are similar (shown in the legend of \\ref{fig:ode-convergence}), and reduction in uncertainty is almost negligible at a given $S$.\nHowever, we note that in the alternative setup, for an equal number of measurements, the time elapsed is half of that in the original due to the different equipment being used.\nTo this end, we estimate convergence rates with respect to the time elapsed in the experiment rather than number of measurements used, and notice that the alternative setup (orange) exhibits much lower error at a given point of time.\nThis implies that we can achieve similar results with a shorter observational window by using equipment that allows for faster observations.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\FloatBarrier\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Impact of Equipment Precision}\nTo achieve higher precision in the estimate of the MUD point, one can use more precise measurement equipment.\nWe expect that a method designed to address parameter estimation would see an improvement in accuracy  if the data is collected with more precise instruments.\nHere we show that this is indeed the case for the time-series example introduced earlier by considering choices of $\\tau = 0.1, 0.05, 0.01, \\text{ and } 0.005$ for $\\mathbb{P}( \\abs{\\xi} < \\tau ) = 99\\%$ to select our $\\sigma$ in our normal additive noise model.\nWe sequentially incorporate $S=5, 10, 15, 20, 25, 50, 100, \\text{ and } 200$ measurements and study the error in our estimate of $\\paramref$.\n\n\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.475\\linewidth]{figures/ode/ode_convergence_mud_std_mean.png}\n  \\includegraphics[width=0.425\\linewidth]{figures/ode/ode_convergence_mud_std_var.png}\n\n  \\caption{Convergence of the MUD point given $N=1E3$ model evaluations incorporating measurements at a fixed point in time.\n  As more precise measurements are incorporated, the accuracy and precision of the MUD solution improves.\n  }\n  \\label{fig:ode-convergence-std}\n\\end{figure}\n\nIn Figure~\\ref{fig:ode-convergence-std}, we study the absolute error's mean and variance as our measurement equipment gets more precise (lower tolerance), for both the $100$Hz (ode) and $200$Hz (ode-alt) variants of sensors we are simulating.\nIn the left half of the figure, we find that the convergence rates for the two designs are nearly identical but the equipment which records twice as many measurements has a persistent reduction in error.\nThe right half shows the convergence in variance of the absolute error, and the vertical displacement between the two designs is visually difficult to distinguish.\nHowever, as evidenced in the legend annotations of Fig~\\ref{fig:ode-convergence-std}, the alternative design (faster equipment) exhibits an increase in the rate of convergence from 1.87 to 1.92.\n\nWe have shown that the Data--Consistent approach to solving parameter identification problems manages to generalize to problems involving time-series data from a single Quantity of Interest.\nWe now turn our attention to an example where instead of temporal measurements, we incorporate spatial data to solve another 1-D parameter identification problem.\n", "meta": {"hexsha": "f27211dc37d55b56385676d8967d21f090e1c904", "size": 6648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "extensions/decay_extension.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": "extensions/decay_extension.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": "extensions/decay_extension.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": 79.1428571429, "max_line_length": 262, "alphanum_fraction": 0.7691034898, "num_tokens": 1457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.6274423399015854}}
{"text": "\\chapter{Markov Chain Monte Carlo}\n\\section{Monte Carlo}\nMonte Carlo is a general term for computational techniques that use random\nnumbers.\nMonte Carlo can be used in classical and Bayesian statistics. A special kind\nof Monte Carlo\ncalled Markov Chain Monte Carlo (MCMC) was one of the main reasons\nfor the revival of Bayesian statistics in the second half of the 20th century.\nBefore MCMC became popular, one of the major drawbacks of the Bayesian approach\nwas that some of the calculations were too hard to do. MCMC enables us to solve\na wide range of Bayesian problems which cannot be solved using analytical\nmethods.\n\n\\subsection{Summaries}\nSo far, we have represented our probability distributions (prior and posterior)\nin a computer by using a vector of possible parameter values and a corresponding\nvector of probabilities. For example, suppose we have a single parameter $\\theta$\nand we have worked out the posterior distribution by using a Bayes' Box. This\nwill give us a vector {\\tt theta} of possible $\\theta$ values and a corresponding\nvector {\\tt post} containing the posterior probabilities. Well, one thing we could\ndo is plot the posterior distribution, resulting in a plot like the one in\nFigure~\\ref{fig:normal}.\n\\begin{verbatim}\nplot(theta, post, xlab=\"Theta\", ylab=\"Posterior Probability\")\n\\end{verbatim}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.5]{Figures/normal.pdf}\n\\caption{\\it A posterior distribution can be represented in a computer by a discrete\nset of possible parameter values, and the corresponding probabilities.\\label{fig:normal}}\n\\end{center}\n\\end{figure}\n\nIf we want to obtain some summaries, we could do it like so:\n\\begin{verbatim}\npost_mean = sum(theta*post)\npost_sd = sqrt(sum(theta^2*post) - post_mean^2)\n\\end{verbatim}\n\nHowever,\nthere is an alternative way of representing this posterior distribution in a\ncomputer. It may not be immediately obvious why this is a good idea,\nbecause there is nothing wrong with the tried and true method we have used\nso far. But this second method has the advantage that it continues to\nwork well on much bigger problems, such as when we have more than one parameter.\nWith more than one parameter, the `vector of possible solutions'' approach\ncan fail very dramatically.\n\nOur new way of representing a probability distribution in a computer will be\nvia {\\it Monte Carlo} samples.\nInstead of having two vectors (one of $\\theta$ values and one of the\ncorresponding probabilities),\nimagine we had some method to compute a random sample of $\\theta$ values, drawn\nfrom the posterior distribution in Figure~\\ref{fig:normal}.\nThere would only be one vector {\\tt theta}. So how would we\nknow there is greater probability around $\\theta=1$? Well, {\\it more elements\nof the {\\tt theta} vector would be near 1}.\nInstead of carrying around a second vector of\nprobabilities, we understand that more probable regions will simply contain\nmore points. Say our vector of random\nsamples is called {\\tt theta}. Then we can look at the posterior distribution\nby plotting a histogram of samples:\n\\begin{verbatim}\nhist(theta, breaks=100)\n\\end{verbatim}\nThe histogram looks something like the one in Figure~\\ref{fig:normal2}.\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.5]{Figures/normal2.pdf}\n\\caption{\\it The posterior distribution for a parameter $\\theta$ can also be\nrepresented by a random sample of $\\theta$ values drawn from the posterior\ndistribution. Some $\\theta$ values are more probable than others, which is\nencoded by certain values appearing more frequently in the sample.\n\\label{fig:normal2}}\n\\end{center}\n\\end{figure}\nWe can also get our summaries, but the code looks different\n(it's actually easier than before!):\n\\begin{verbatim}\npost_mean = mean(theta)\npost_sd = sd(theta)\n\\end{verbatim}\nBecause of the randomness involved in generating the {\\tt theta} values,\nthe summaries aren't exact. For example, I know the actual posterior mean\nand standard deviation in this example were both 1, but the values obtained\nfrom the Monte Carlo samples were 0.9604 and 1.0008, respectively. However,\nthis doesn't matter much because the results indicate $\\theta$ is probably\nsomewhere around 1, with an uncertainty of about 1. The error introduced by\nusing random samples is much smaller than the amount of uncertainty inherent\nin the posterior distribution itself. For example, if I summarised the posterior\ndistribution by saying $\\theta = 0.9604 \\pm 1.0008$, for almost all practical\npurposes the conclusion is exactly the same as the true version of the summaries\n$\\theta = 1 \\pm 1$.\n\nIn this discussion, we haven't answered the question of how to actually generate\nrandom samples of $\\theta$ from the posterior distribution. This is the job\nof Markov Chain Monte Carlo.\n\n\\begin{framed}\n{\\bf\nThe purpose of Markov Chain Monte Carlo is to generate random samples of\nparameter values drawn from the posterior distribution. This makes it very easy\nto compute summaries even if you have more than one unknown parameter.}\n\\end{framed}\n\n\\section{Multiple Parameters}\nMCMC becomes extremely useful when we begin to look at Bayesian models involving\nmore than one unknown parameter. \nHaving posterior samples makes the process of {\\it marginalisation}\nmuch easier. Imagine we wanted to infer two parameters, called $a$ and $b$,\nfrom\ndata $x$. Bayes' rule (parameter estimation version) would give us the posterior\ndistribution:\n\\begin{eqnarray}\np(a, b | x) \\propto p(a, b)p(x|a,b)\n\\end{eqnarray}\n\nHowever, what if you didn't really care about the value of $b$ but\nonly really wanted to measure $a$? The terminology for this is that $b$ is a\n{\\it nuisance parameter}: you need it to define the model, but ultimately you\nare not really interested in knowing its value.\nWhat you need in this case is the\n{\\it marginal} posterior distribution for $a$ (that is, the posterior\ndistribution for $a$ on its own, not the joint distribution with $b$).\nThis can be obtained using the sum rule. The result is:\n\\begin{eqnarray}\np(a | x) &=& \\int_b p(a, b|x) \\, db\n\\end{eqnarray}\nor\n\\begin{eqnarray}\np(a | x) &=& \\sum_{b} p(a, b|x)\n\\end{eqnarray}\ndepending on whether the set of possible $b$ values is continuous or discrete.\nBefore MCMC, these integrals or sums usually couldn't be done without making\ncertain choices purely for mathematical convenience (e.g. choosing the prior\nto be a certain kind of distribution only because it will make the maths work\nout, rather than it being a good description of your prior beliefs).\n\nSamples of parameter values drawn from the posterior distribution\n(achieved using MCMC) make this hard problem much easier. We no longer need\nto worry about mathematical convenience.\nSee Figure~\\ref{fig:marginalisation} for an example showing how Monte Carlo\nsampling makes marginalisation trivial.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.5]{Figures/marginalisation.pdf}\n\\caption{\\it An example of a posterior distribution for two parameters, $a$ and\n$b$. The left panels show the joint posterior distribution (which has a\ncorrelation) and the marginal posterior distribution for $a$, obtained by\nintegrating over all the possible $b$ values. The top right panel contains\nrandom samples\n(points) drawn from the posterior distribution for $a$ and $b$.\nThe only step needed to get the\nmarginal distribution for $a$ (lower right panel) is to ignore the $b$-values of\nthe points!\n\\label{fig:marginalisation}}\n\\end{center}\n\\end{figure}\n\n\n\\section{The Metropolis Algorithm}\nThe Metropolis algorithm is the most basic MCMC method.\nThe ideas behind it are fairly simple, yet Metropolis forms the basis of a large\nnumber of more advanced MCMC methods. In STATS 331 we will study the basic ideas\nbehind how the Metropolis algorithm works, which will involve a small amount\nof Markov chain theory. We will also look at a small amount of R code\nwhich implements the Metropolis algorithm, but for solving practical problems\nit is more convenient to use the JAGS program\\footnote{JAGS uses a number\nof MCMC methods internally, including Metropolis, ``Gibbs Sampling'', and\n``Slice Sampling'', which we will not study in this course.}.\n\nThe Metropolis algorithm was invented in the 1950s by physicists\n(including Nicholas Metropolis, for whom the algorithm is named), who used it\nto do calculations in the field of statistical mechanics. This intriguing field\nfocuses on calculating the macroscopic (large scale) properties of matter from\nknowledge of the small-scale properties. For example, if you know water is\ncomposed of H$_2$O molecules, you can use statistical mechanics to figure out\nwhat will happen if you have a lot\nof water molecules. For example, it will freeze at 0 degrees Celsius and boil at 100 degrees Celsius.\n\nIt took\nmany decades before people started to realise the Metropolis algorithm was\nuseful in Bayesian\nstatistics as well as statistical mechanics. The Bayesian approach\nseemed very elegant and\nuseful to many people, but it could always be criticised as unworkable,\nbecause you usually had to do difficult or\nimpossible integrals when solving practical problems\n(to summarise the posterior, or to get rid of nuisance\nparameters). MCMC changed all that, and is one of the reasons for the\nexplosion in the popularity of Bayesian statistics beginning in the 1990s.\n\nThe basic idea of MCMC is that we want a method which will travel between\ndifferent possible states (such as the possible hypotheses/parameter values in\na Bayesian analysis). We want the amount of time spent in\nany particular state to be proportional to the posterior probability of the state.\nThe computer ``explores'' the set of possible parameter values, spending a lot\nof time in the regions with high posterior probability, and only rarely visiting regions\nof low posterior probability. Figure~\\ref{fig:mcmc} shows an example of MCMC\napplied to a problem with only two possible hypotheses or parameter values.\nNobody would actually use MCMC on such a small problem, but it is helpful for\nexplaining how MCMC works.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.65]{Figures/mcmc.pdf}\n\\caption{\\it An illustration of the basic idea behind MCMC. Imagine we had a\nBayes' Box with two possible hypotheses, and we knew the\n{\\tt prior $\\times$ likelihood} values. The amount of time the MCMC program will\nspend in each state is proportional to the posterior probability of the state.\nIn this example, the MCMC algorithm was in State 1 three times and in State 2\nseven times. Using this, we could estimate the posterior probability of State 2\nas being 0.7. This estimate would become more accurate if we ran the MCMC for\nmore iterations.\\label{fig:mcmc}}\n\\end{center}\n\\end{figure}\n\n\\subsection{Metropolis, Stated}\nThe Metropolis algorithm is given below. The first thing to do is start\n{\\it somewhere} in the ``parameter space'' (set of possible parameter values).\nYou then\n{\\it propose} to move somewhere else. There is an acceptance probability $\\alpha$\nthat determines whether to accept the proposal. If the proposal is better\n($h$, the prior times likelihood value is higher), then you accept it, and the\nproposed state becomes the new state of the algorithm.\nIf the\nproposal is worse, you can also accept it, but the probability of accepting is\ngiven by the ratio of the unnormalised posterior probabilities, i.e. $h'/h$.\nFor example, if the proposed point is 1/3 as good as the current point, the\nacceptance probability is 1/3. If the proposed point is rejected, the original\npoint remains the state of the algorithm, and gets counted again in the results.\n\nThe Metropolis algorithm works because it makes transitions towards low\nprobability\nstates rare, while transitions towards high probability states are common, because\nof the acceptance probability. It is hard to move into an improbable state, so\nnot much time will be spent there. Over time, the fraction of time spent in\nany given state is equal to the posterior probability of the corresponding\nhypothesis.\n\n\\begin{framed}\n\\begin{itemize}\n\\item Start in some state $\\theta$\n\\item Generate a ``proposal'' state $\\theta'$ from a {\\it proposal distribution} $q$ (assumed symmetric so that $q(\\theta'|\\theta)=q(\\theta|\\theta')$)\n\\item With probability $\\alpha = \\textnormal{min}(1, h'/h)$, replace the current\nstate with the proposed state\n\\item Repeat\n\\end{itemize}\n\\end{framed}\n\n\\section{A Two State Problem}\nWe will now study how the Metropolis algorithm works on a very simple\nexample, namely the two-ball problem from the beginning of the notes. There\nare two hypotheses and the posterior probabilities are $1/3$ and $2/3$.\nIt is important to note that MCMC is not actually needed for a problem this\nsimple, but it is a good test case to see precisely how an MCMC algorithm works.\nWhen we solve real data analysis problems with JAGS,\nwe won't have to think too\nmuch about how the MCMC works, but can concentrate instead on the Bayesian\nstatistics problem at hand.\n\nLet's\ncall the less probable hypothesis ``State 1'' and the more probable hypothesis\n``State 2'' for the purposes of this section.\nWhat we need is a Markov process that will spend 1/3 of the time in State 1 and\n2/3 of the time in State 2. The Metropolis algorithm described above will\ndo what we need. The main thing we need to compute is the acceptance probability\n$\\alpha_{ij}$ for a proposed transition from state $i$ to state $j$ where\n$i, j \\in \\{1, 2\\}$.\nThe acceptance probability $\\alpha$ for a proposed move from state $i$ to\nstate $j$ is given by\n\\begin{eqnarray}\n\\alpha_{ij} = \\textnormal{min}\\left(1, \\frac{h_j}{h_i}\\right)\n\\end{eqnarray}\nwhere $h_i$ and $h_j$ are proportional to the posterior probabilities of\nstates $i$ and $j$ respectively. If the proposal is to move\nto an equal or better (higher posterior probability)\nstate ($h_j \\geq h_i$) then the acceptance probability is 1.\nIf the proposal is to move to a less probable state then the acceptance probability\nis $h_j/h_i$, the ratio of the two posterior probabilities\\footnote{Note that\nthis algorithm can be used even if the marginal likelihood is unknown, because\nonly ratios of posterior probabilities are needed. This is useful because the\nmarginal likelihood is sometimes very hard to calculate in multi-parameter\nproblems.}.\n\nThe transition probability is the probability\nof being in state $j$ at the next iteration given that you are in state $i$\nat the current iteration. The transition probability is given by the product\nrule:\n\\begin{eqnarray}\np_{ij} = q_j \\alpha_{ij}\\label{eq:transition}\n\\end{eqnarray}\nfor $i \\neq j$.\nThe transition matrix of the Markov chain is a matrix with all the different\n$p_{ij}$ values in it:\n\\begin{eqnarray}\n\\mathbf{P} &=&\n\\left[\n\\begin{array}{cc}\np_{11} & p_{12}\\\\\np_{21} & p_{22}\n\\end{array}\n\\right]\n\\end{eqnarray}\nIn our particular case, we can work out the off-diagonal elements of\n$\\mathbf{P}$ using Equation~\\ref{eq:transition}:\n\\begin{eqnarray}\n\\mathbf{P}\n&=&\n\\left[\n\\begin{array}{cc}\n & \\frac{1}{2} \\times 1\\\\\n\\frac{1}{2}\\times\\frac{1}{2} & \n\\end{array}\n\\right]\n\\end{eqnarray}\nThe diagonal elements can be found by knowing the rows of $\\mathbf{P}$ must\nsum to 1. We must be in {\\it some} state at the next iteration. Therefore the\ntransition matrix of our Markov chain in this two-state problem is:\n\\begin{eqnarray}\n\\mathbf{P}\n&=&\n\\left[\n\\begin{array}{cc}\n\\frac{1}{2} & \\frac{1}{2}\\\\\n\\frac{1}{4} & \\frac{3}{4}\n\\end{array}\n\\right]\\label{eq:p_matrix}\n\\end{eqnarray}\n\nA Markov chain with a small number of possible states can be represented\ngraphically using a {\\it transition diagram}, as in\nFigure~\\ref{fig:transitions}.\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.65]{Figures/transitions.pdf}\n\\caption{\\it A transition diagram for a Markov Chain with two possible states.\nThe states (which correspond to hypotheses in Bayesian inference) are drawn\nas circles labelled ``1'' and ``2''. When the algorithm is in a particular state\n(e.g. State 1), and we apply one step of the Metropolis algorithm,\nthe probability it will be in State 1 is $p_{11}$ and the probability it\nwill be in State 2 is $p_{12}$.\nMCMC works by making it easy to move into states with high\nposterior probability, and hard to move out of them.\n\\label{fig:transitions}}\n\\end{center}\n\\end{figure}\n\n\\section{The Steady-State Distribution of a Markov Chain}\nOnce we have the transition matrix, we can work out the {\\it steady state\ndistribution} of the Markov chain. Imagine, instead of starting the MCMC\nfrom an arbitrary initial state, you have a probability distribution for the\ninitial state. After applying one iteration of the Metropolis algorithm, the\nprobability distribution for the updated state will usually be different from\nthe probability distribution for the initial state.\n\nHowever, one special probability distribution, called the {\\it steady state\ndistribution}, does not change after you apply an MCMC update. If your initial\npoint was drawn from the steady state distribution, then subsequent points will\nalso be drawn from the steady state distribution. In MCMC the steady state\ndistribution should be the same as the posterior distribution.\n\nImagine we are using MCMC on our two-state problem, and our initial position\nis State 1 with probability $v_1$ and State 2 with probability $v_2$. What\nis the probability of being in State 1 at the next iteration? There are two\nways for that to happen: by starting in State 1 and then making a transition\nfrom $1\\to 1$, or by starting in State 2  and making a transition from $2\\to 1$.\nThe total probability is then:\n\\begin{eqnarray}\nP(\\textnormal{State 1 after iteration}) &=& v_1p_{11} + v_2p_{21}.\n\\end{eqnarray}\nSimilarly for State 2:\n\\begin{eqnarray}\nP(\\textnormal{State 2 after iteration}) &=& v_1p_{12} + v_2p_{22}.\n\\end{eqnarray}\nIf $v_1$ and $v_2$ happened to be the steady state distribution, then these\nprobabilities would also be $v_1$ and $v_2$. This gives us two simultaneous\nequations\n\\begin{eqnarray}\nv_1 &=& v_1p_{11} + v_2p_{21}\\\\\nv_2 &=& v_1p_{12} + v_2p_{22}\n\\end{eqnarray}\nwhich can also be written in matrix form as $\\mathbf{v}\\mathbf{P} = \\mathbf{v}$\nwhere $\\mathbf{v} = \\left(v_1, v_2\\right)$ and $\\mathbf{P}$ is the transition\nmatrix\\footnote{Mathematics students might recognise this equation, which says\n$\\mathbf{v}$ is the left-eigenvector of $\\mathbf{P}$, with eigenvalue 1.\nAn alternative is to write the stationary distribution as a column vector and\nuse $\\mathbf{P}^T\\mathbf{v} = \\mathbf{v}$.}.\nThese two simultaneous equations can be solved for $v_1$ and $v_2$.\nHowever there is a third constraint, that is $v_1 + v_2 = 1$. Since there\nare three equations but two unknowns, it seems like the problem might be\n``over-determined'', but that is not actually the case because the transition\nmatrix rows are not all linearly independent.\nIt is left as an exercise for the reader to show the steady state\ndistribution for our Markov chain (Equation~\\ref{eq:p_matrix}) is in fact\nequal to the posterior distribution, so\n$\\mathbf{v} = \\left(\\frac{1}{3}, \\frac{2}{3}\\right)$.\n\n\\section{Tactile MCMC}\nIn class we will do ``Tactile MCMC'', which is an implementation of the\nMetropolis algorithm using coins and dice instead of the random number generators\nprovided in computer software such as R. This is a good way to get a feel for\nthe flow of MCMC algorithms.\n\nIn STATS 331, when we want to use MCMC in practice, we will use the JAGS program\nrather than using Metropolis directly. JAGS is a general purpose MCMC program\nwhich allows you to solve fairly complex problems without a large amount of\nprogramming.\n", "meta": {"hexsha": "e6a0e802970c4a1d788a550ec3fdbde39d7080ce", "size": 19548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mcmc.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": "mcmc.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": "mcmc.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": 47.4466019417, "max_line_length": 150, "alphanum_fraction": 0.7776754655, "num_tokens": 4908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.6274423399015853}}
{"text": "\\section{Time Complexity of MST Algorithms}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Prim \\emph{vs.} Kruskal (Problem 6.4)}\n  \\begin{exampleblock}{Prim \\emph{vs.} Kruskal (Problem 6.4)}\n\t\\begin{itemize}\n\t  \\item Array \\emph{vs.} heap\n\t  \\item $m = O(n)$ \\emph{vs.} $m = \\Omega(n^2)$\n\t\\end{itemize}\n\n\t\\[\n\t  T(n,m) = O(n + n T(\\text{deleteMin}) + m T(\\text{decreaseKey}))\n\t\\]\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{MST on special graphs (Problem 6.3)}\n  \\begin{exampleblock}{MST on special graphs (Problem 6.3)}\n\t\\begin{enumerate}\n\t  \\item $K$-bounded degree graph\n\t  \\item Planar graph\n\t\\end{enumerate}\n  \\end{exampleblock}\n\n  \\[\n\t(1)\\; m \\le \\frac{nk}{2}\n  \\]\n\n  \\[\n\t(2)\\; m \\le 3n - 6\n  \\]\n\n  \\begin{alertblock}{Reference}\n\t\\begin{itemize}\n\t  \\item ``Finding Minimum Spanning Trees'' by David Cheriton and Robert Tarjan, 1976 (linear on planar graph).\n\t\\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Prim on special graphs (Problem 6.1)}\n  \\begin{exampleblock}{Prim on special graphs (Problem 6.1)}\n\t\\[\n\t  E = \\set{v_1v_i \\mid i = 2 \\dots n}, W(v_1v_i) = 1\n\t\\]\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Prim on special graphs (Problem 6.2)}\n  \\begin{exampleblock}{Prim on special graphs (Problem 6.2)}\n\t\\begin{enumerate}\n\t  \\item $G = K_n$\n\t  \\item $W(v_iv_j) = n + 1 -i, 1 \\le i < j \\le n$\n\t\\end{enumerate}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "9bac5060755e56216d7b1c284d0ff4b106fea072", "size": 1446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/alg-tutorial-mst-20170531/sections/mst-time.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/alg-tutorial-mst-20170531/sections/mst-time.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/alg-tutorial-mst-20170531/sections/mst-time.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.3684210526, "max_line_length": 111, "alphanum_fraction": 0.5961272476, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6274423307357787}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{graphicx}\n\\usepackage{latexsym,algorithm,algorithmic}\n\\usepackage{times}\n\\usepackage{amsmath,amssymb,mathtools}\n\\usepackage{mathptmx}      % use Times fonts if available on your TeX system\n\n\\setlength{\\textwidth}{7in}\n\\setlength{\\textheight}{9in}\n\\setlength{\\oddsidemargin}{-0.5in}\n\\setlength{\\evensidemargin}{-0.5in}\n\\setlength{\\topmargin}{-0.5in}\n\n\n\\newcommand{\\weightvec}{\\textbf{w}}\n\\newcommand{\\edge}[2]{{u\\rightarrow{}v}}\n\\newcommand{\\edgeuv}{{\\edge{u}{v}}}\n\n\\newcommand{\\vek}[1]{\\textbf{#1}}\n\\newcommand{\\ddw}{\\frac{\\partial}{\\partial\\vek{w}}}\n\\newcommand{\\M}{\\textrm{M}}\n\\newcommand{\\dM}{\\textrm{dM}}\n\\newcommand{\\df}{\\textbf{df}}\n\\newcommand{\\dt}{\\textbf{dt}}\n\\newcommand{\\vphi}{\\vec{\\phi}}\n\n\\begin{document}\n\n\\section{Derivation: PPR and its derivative}\n\nNotation: $\\vek{s}$ is seeds, $\\M$ is transition matrix, $\\vek{w}$ are\nparameters, and $\\vek{p}^\\infty$ is the PPR stationary distribution,\n$\\vek{p}^t$ is a point in the power-rule iteration for computating\nPPR, and $\\vek{d}^t$ is the partial derivative of $\\vek{p}^t$ wrt the\nparameters $\\vek{w}$.\n\n\\begin{eqnarray}\n\\vek{p}^{t+1} & \\equiv & \\alpha \\vek{s} + (1-\\alpha) \\M^\\top \\vek{p}^t \\\\\n\\vek{d}^t & \\equiv &  \\ddw \\vek{p}^t\n\\end{eqnarray}\n\nNote $\\vek{p}^t$ and $\\vek{d}^t$ have different dimensions: while\n$\\vek{p}^t_u$ is a scalar score for $u$ under PPR, $\\vek{d}^t_u$ is a\nvector, giving the sensitivity of that score to each parameter in\n$\\vek{w}$.\n\n$\\M$ is defined as follows.  There is a weight vector $\\vek{w}$, and\nfor an edge $\\edgeuv$, there is a feature vector $\\vphi_{uv}$, which is\nused to define a basic score $s_{uv}$ for the edge, which is passed\nthru a squashing function $f$, e.g., $f(x)\\equiv e^x$, and then\nnormalized to form $\\M$.\n\n\\begin{eqnarray}\n s_{uv}   & \\equiv & \\vphi_{uv} \\cdot \\vek{w}  \\\\\n t_u      & \\equiv & \\sum_{v'} f(s_{uv'}) \\\\\n \\M_{u,v} & \\equiv & \\frac{ f(s_{uv}) }{ t_u }\n\\end{eqnarray}\n\nWe can define $\\vek{d}^t$ recursively:\n\n\n\\begin{eqnarray}\n\\vek{d}^{t+1}  & =  &  \\ddw \\vek{p}^{t+1} \\\\\n               & =  &  \\ddw \\left( \\alpha \\vek{s} + (1-\\alpha) \\M^\\top \\vek{p}^t \\right) \\\\\n               & =  &  (1-\\alpha) \\ddw \\M^\\top \\vek{p}^t \\\\\n               & =  &  (1-\\alpha) \\left( (\\ddw \\M^\\top) \\vek{p}^t  + \\M^\\top \\ddw\\vek{p}^t \\right) \\\\\n               & =  &  (1-\\alpha) \\left( (\\ddw \\M^\\top) \\vek{p}^t  + \\M^\\top \\vek{d}^t \\right)\n\\end{eqnarray}\n\nNow let's look at $\\ddw\\M$, which I'll denote $\\dM$ below.  Note that\neach $\\dM_{uv}$ is a vector, again giving the sensitivity of the\nweight $\\M_{uv}$ to each parameter in $\\vek{w}$.\n\n\\begin{eqnarray}\n\\dM_{uv}   & = & \\ddw \\frac{ f(s_{uv}) }{ t_u } \\\\\n           & = & \\frac{1}{t_u ^2} \\left( t_u \\ddw f(s_{uv}) - f(s_{uv}) \\ddw t_u \\right)\n\\end{eqnarray}\n\nTo continue this, define $\\df$ and $\\dt$ as the vectors\n\n\\begin{eqnarray}\n \\df_{uv} & \\equiv & \\ddw f(s_{uv}) = f'(s_{uv}) \\vphi_{uv} \\label{eqn:fprime} \\\\\n \\dt_{u}  & \\equiv & \\ddw t_u = \\sum_{v'} \\df_{uv'}\n\\end{eqnarray}\n\nNote that $\\df_{uv}$ has no more non-zero components than\n$\\vphi_{uv}$, so it is sparse, and $\\dt_{u}$ is also sparse, but\nsomewhat less so.\n\nWe can continue the derivation as\n\n\\begin{eqnarray}\n\\dM_{uv}   & = & \\frac{1}{t_u ^2} \\left( t_u \\ddw f(s_{uv}) - f(s_{uv}) \\ddw t_u \\right) \\\\\n           & = & \\frac{1}{t_u ^2} \\left( t_u \\df_{uv} - f(s_{uv}) \\dt_u \\right)\n\\end{eqnarray}\n\nThis is a little different from the old algorithm: there is always an\n(implicit) reset with probability $\\alpha$, and that reset probability\ncan be increased by learning by weighting the features for the\n(explicit) reset links that are present already in the graph.  No min\n$\\alpha$!\n\n\\section{Computation}\n\n\\begin{table} % Computing M and dM\n\\hrule\n\\begin{enumerate}\n\\item For each node/row $u$\n  \\begin{enumerate}\n  \\item  $t_u = 0$\n  \\item  $\\dt_u = \\vek{0}$, an all-zeros vector\n  \\item For each neighbor $v$ of $u$\n    \\begin{enumerate}    \n    \\item $s_{uv} = \\vek{w} \\cdot \\vphi_{uv}$,  a scalar.\n\n      In detail: For $i\\in \\vphi_{uv}$: increment $s_{uv}$ by $\\vek{w}_i\\vphi_i$\n\n    \\item $t_u  +\\!\\!= f(s_{uv})$, a scalar\n    \\item $\\df_{uv} = f'(s_{uv}) \\vphi_{uv}$, a vector, as sparse as $\\vphi_{uv}$\n\n      In detail: For $i\\in \\vphi_{uv}$: set $\\df_{uv,i} = \\vphi_f * c$, where $c=f'(s_{uv})$\n\n    \\item  $\\dt_u +\\!\\!= \\df_{uv}$, a vector, as sparse as $\\sum_{v'} \\vphi_{uv'}$\n\n      In detail: For $i\\in \\df_{uv}$: increment $\\dt_{u,i}$ by $\\df_{uv,i}$\n\n    \\end{enumerate}\n  Now $t_u = \\sum_{v'} f(s_{uv'})$ and $\\dt_{u} = \\sum_{v'} \\df_{uv'}$\n  \\item For each neighbor $v$ of $u$ create the vector\n\n\\[ \\dM_{uv}  = \\frac{1}{t_u ^2} \\left( t_u \\df_{uv} - f(s_{uv}) \\dt_u \\right)  \n\\]\n\nOr in detail: For $i\\in\\dt_u$: $\\dM_{uv,i} = \\frac{1}{t_u ^2} \\left( t_u \\df_{uv,i} - f(s_{uv}) \\dt_u,i \\right)$.  \n\nThere aren't any dimensions $i$ that are present in $\\df_{uv}$ but not\n$\\dt_u$, since $\\dt_u$ is a summation.  Also create the scalar\n\n\\[ \\M_{uv}  = \\frac{f(s_{uv})}{t_u} \n\\]\n\n  You can now discard the intermediate values like $t_u$, $\\dt_u$, $\\df_{uv}$.\n\n  \\end{enumerate}\n\\end{enumerate}\n\\caption{Computing $\\M$ and $\\dM$} \\label{alg:mat}\n\\hrule\n\\end{table}\n\nSince $\\dM$ and $M$ are reused many times, we should compute and store\n$M$ and $\\dM$ first.  This will expand the size of the graph somewhat:\nin particular, we will need to store, not only the active edges $u,v$\nand their features $\\vphi_{uv}$, but also $\\dM_{uv}$, which includes\nweights for all features of vertexes $v'$ that are siblings of $v$\n(i.e., there is an edge $u,v'$).  I'm not sure how bad this will be in\npractice: perhaps we should estimate it for some of our test cases.\nAfter this, operations should run in time linear in the size of the\nnew, less sparse graph encoded in $\\dM$.  I believe that this scheme\nalso makes operations like the APR learning more modular.\n\nComputing $M$ and $\\dM$ is one pass over the graph, shown in Table\n\\ref{alg:mat}.\n\n\nThen you can start with $\\vek{p}^0 = \\vek{d}^0 = \\vek{0}$ and iterate\n\n\\begin{eqnarray}\n\\vek{p}^{t+1}  & =  & \\alpha \\vek{s} + (1-\\alpha) \\M^\\top \\vek{p}^t \\\\\n\\vek{d}^{t+1}  & =  & (1-\\alpha) \\left( \\dM^\\top \\vek{p}^t  + \\M^\\top \\vek{d}^t \\right)\n\\end{eqnarray}\n\nIn more detail, the iteration for the updates on $\\vek{p}$ are shown\nin Table~\\ref{alg:updates}.\n\n\\begin{table} % updating p and d\n\\hrule\n\nUpdating $\\vek{p}$:\n\\begin{enumerate}\n\\item $\\vek{p}^{t+1} = \\vek{0}$\n\\item For each node $u$ \n  \\begin{enumerate}\n  \\item $\\vek{p}^{t+1}_u +\\!\\!= \\alpha \\vek{s}_u$\n  \\item For each neighbor $v$ of $u$\n    \\begin{enumerate}\n    \\item $\\vek{p}^{t+1}_v +\\!\\!= (1-\\alpha) \\vek{p}^t_u \\M_{uv} $\n    \\end{enumerate}\n  \\end{enumerate}\n\\end{enumerate}\n\nUpdating $\\vek{d}$:\n\\begin{enumerate}\n\\item $\\vek{d}^{t+1} = \\langle \\vek{0}, \\ldots, \\vek{0} \\rangle$ --- i.e., for each node $u$ there is an all-zeros\n  vector of weights.\n\\item For each node $u$ \n  \\begin{enumerate}\n  \\item For each neighbor $v$ of $u$\n    \\begin{enumerate}\n      \\item For each $i$ in $\\dM_{vu}$\n\n      \\[ \\vek{d}^{t+1}_{v,i} +\\!\\!= (1-\\alpha) \\vek{p}^t_u \\dM_{uv,i} \\]\n      \\item For each $i$ in $\\vek{d}^t_{v}$\n\n      \\[ \\vek{d}^{t+1}_{v,i} +\\!\\!= (1-\\alpha) \\vek{d}^t_{u,i} \\M_{uv} \\]\n    \\end{enumerate}\n  \\end{enumerate}\n\\end{enumerate}\n\\caption{Updates for $\\vek{d}$ and $\\vek{p}$} \\label{alg:updates}\n\\hrule\n\\end{table}\n\n\\section{Loss functions and lazy regularization}\n\nFor SRW each example is a triple $(\\vek{s},P,N)$ where $\\vek{s}$ is\nthe seed distribution, $P=\\{a^1,\\ldots,a^I\\}$ are the positive (a-ok?)\nexamples, and $N=\\{b^1,\\ldots,b^J\\}$ are the negative (bad?) examples.\nI use $\\vek{p}$ for the PPR distribution starting at $\\vek{s}$, and\nwrite $\\vek{p}[u]$ for $\\vek{p}_u$ if I run out of space for\nsubscripts.\n\nThe loss function is\n\\begin{equation}\nL(\\vek{w}) \\equiv - \\Bigg (\\sum_{k=1}^I \\log \\vek{p}[a^k] + \\sum_{k=1}^J \\log (1 - \\vek{p}[b^k]) \\Bigg) + \\mu R(\\vek{w})\n\\end{equation}\nwhere $R(\\vek{w})$ is the regularization, eg\n$R(\\vek{w})\\equiv||\\vek{w}||^2_2$. This means loss increases as the objective function decreases, where the objective function is proportional to the probability of either hitting a positive solution or not-hitting a negative solution.  Once we have $\\vek{d}$ it's easy\nto compute the gradient of this as\n\n\\begin{eqnarray}\n\\ddw L(\\vek{w}) & \\equiv & - \\Bigg (\\sum_{k=1}^I \\frac{1}{\\vek{p}[a^k]}\\vek{d}[a^k] \n                                  - \\sum_{k=1}^J \\frac{1}{1 - \\vek{p}[b^k]}\\vek{d}[b^k] \\Bigg) + \\mu \\ddw R(\\vek{w})\n\\end{eqnarray}\n\nWe can split this into two parts: the empirical loss gradient, which is\n\n\\[\n-\\Bigg (\\sum_{k=1}^I \\frac{1}{\\vek{p}[a^k]}\\vek{d}[a^k] \n     - \\sum_{k=1}^J \\frac{1}{1 - \\vek{p}[b^k]}\\vek{d}[b^k] \\Bigg)\n\\]\nand the regularization gradient, \n\\[\n \\mu \\ddw R(\\vek{w})\n\\]\nIf an example doesn't contain all features then the empirical gradient\nwill be a sparse vector, but the regularization gradient will be\ndense.  So the following code might be more efficient for SGD than\njust computation of the full gradient and taking a step in that\ndirection.\n\n\\begin{enumerate}\n\\item Maintain a ``clock'' counter $m$ which is incremented when each\n  example is processed. Also maintain a history $\\vek{h}_i$ which\n  says, for each feature $i$, the last time $t$ an example containing\n  $i$ was processed.\n\\item When a new example $(\\vek{s},P,N)$ arrives at time $t$\n  \\begin{enumerate}\n    \\item For each feature active in the example, initialize it, if\n      necessary, and them perform the regularization-loss gradient\n      update $t-\\vek{h}_i$ times.\n    \\item Peform the empirical-loss update, using \n      the new weights.\n  \\end{enumerate}\n\\item When you finish learning at final time $T$, consider every\n  feature $i$, and perform the regularization-loss gradient update\n  $T-\\vek{h}_i$ times.  Then write out the final parameters.\n\\end{enumerate}\n\n\\section{Inference: PPR and APR}\n\nInference using requires only $\\M$, which at theorem-proving time is\ncomputed on-the-fly.  That is, whenever you need a row of $\\M$ (the\nset of values $\\M[u,v]$ for all $v$ near $u$) you simply compute the\nnormalized outlinks of $u$.\n\nThe power-iteration version of PPR, which in the codebase is called\nthe \\texttt{PPRProver}, simply iterates this step until convergence\n(or for a fixed number of iterations), starting with\n$\\vek{p}^0=\\vek{0}$.\n\n\\begin{eqnarray}\n\\vek{p}^{t+1} & \\equiv & \\alpha \\vek{s} + (1-\\alpha) \\M \\vek{p}^t \\\\\n\\end{eqnarray}\n\nBreaking this down, the one-step update is the following.\n\n\\begin{enumerate}\n\\item $\\vek{p}^{t+1} = \\vek{0}$\n\\item For each key $u$ with non-zero weight in $\\vek{s}$:\n  \\begin{enumerate}\n  \\item $\\vek{p}^{t+1}[u]$ += $\\alpha \\vek{s}[u]$\n  \\end{enumerate}\n\\item For each key $u$ with non-zero weight in $\\vek{p}^t$:\n  \\begin{enumerate}\n  \\item For each node $v$ near $u$ in $\\M$:\n\\(\n       \\vek{p}^{t+1}[v] \\mbox{~+=~} (1-\\alpha) \\M[u,v] \\vek{p}^t[u]\n\\)\n  \\end{enumerate}\n\\end{enumerate}\n\nThe approximate PageRank is based on a more primitive \\texttt{push}\noperation.  The full approximate PageRank algorithm also uses\n$\\vek{d}$, a vector of node degrees.\n\n\\begin{enumerate}\n\\item Let $\\vek{p}= \\vek{0}$ and $\\vek{r}= \\vek{s}$\n\\item While there is some vertex $u$ such that $r(u)\\geq{}\\epsilon\n  \\vek{d}(u)$:\n  \\begin{enumerate}\n  \\item Perform the \\texttt{push}($u$) operation:\n    \\begin{enumerate}\n      \\item Save the current value of $u$ in $\\vek{r}$: $ru = \\vek{r}[u]$\n      \\item $\\vek{p}[u]$ += $\\alpha \\vek{r}[u]$\n      \\item $\\vek{r}[u]$ *= $(1-\\alpha)$\n      \\item For each node $v$ near $u$ in $\\M$:\n\\(\n       \\vek{r}[v] \\mbox{~+=~} (1-\\alpha) \\M[u,v] ru\n\\)\n    \\end{enumerate}\n  \\end{enumerate}\n\\end{enumerate}\n\nIn the old implementation, $\\vek{d}[u]$ was computed and cached each\ntime a new key $u$ was added to $\\vek{r}$.  In the new implementation\nof the prover, this caching is done by the proof graph, so there's no\nneed to do it in the prover.  \n\nThe old DPR prover implementation computed this approximation by\nfinding $u$'s with large $\\vek{r}[u]$ using a variation of the\nstandard depth-first prover: essentially, you traversed the tree\ndepth-first, and whenever you hit a node with $\\vek{r}[u]$ below\nthreshold, you stopped.  Factoring this in the algorithm used the same\ninitial values of $\\vek{p}$ and $\\vek{r}$ but then called a recursive\nroutine \\texttt{proveState}$(u_0)$, where $u_0$ is the initial query\nnode (aka the initial state of the proof graph).\n\nWilliam Wang's got a new version which calls this iteratively with\nsmaller and smaller $\\epsilon$'s, which seems to work faster.  That\nsuggests that it's helpful to do pushes on the nodes with larger\n$\\vek{r}$ values first.  With that in mind, another thing we could\nconsider would be storing $u$'s in a heap/priority queue, ordered by\n$\\vek{r}$ values.  I know this idea has been used in the past but I\ndon't know how much it helps.  Obviously there's an overhead for the\nheap but my guess is that's not going to dominate.\n\n\\bigskip\n\n\\noindent Function \\texttt{proveState}$(u)$:\n\\begin{enumerate}\n\\item If $r(u)\\geq{}\\epsilon \\vek{d}(u)$:\n  \\begin{enumerate}\n  \\item Perform the \\texttt{push}$(u)$ operation\n  \\item For each $v$ near $u$ (i.e., each subgoal of $u$): \\texttt{proveState}$(v)$\n  \\end{enumerate}\n\\end{enumerate}\n\n\n\\section{Architectural Comments}\n\n\\emph{ [Katie's comments inline and signed with -k]}\n\n\\noindent\nThe routines that are suggested are:\n\\begin{itemize}\n\\item Loading: Compute $\\M$ and $\\dM$ from a graph and $\\vek{w}$.  It\n  seems necessary, altho a little non-modular, to initialize and\n  create new features while the graph is read in. \\emph{ [Do this here, or in SGD? -k]} We should be able\n  to estimate performance pretty well after this step.\n\nInputs: graph and current values of parameters $\\vek{w}$.\n\nOutputs: $\\M$ and $\\dM$, and a list of all active features $i$.\n\nParameters: $f$, $f'$; method to init new features $i$ for $f$, clock\ntime and lazy-regularization function.\n \n\\item Extended inference: compute $\\vek{p}$ and $\\vek{d}$.\n \nInputs: $\\vek{s}$, $\\vek{w}$, $\\M$ and $\\dM$.\n\nOutputs: $\\vek{p}$ and $\\vek{d}$.\n\n\\item SGD: Initialize new features $i$, use clock time and\n  lazy-regularization function to update their weights, and update\n  $\\vek{w}$ using the empirical (non-gradient) loss.\n\nInputs: $\\vek{p}$, $\\vek{d}$, and $P$, $N$.\n\nOutputs: Modified $\\vek{w}$.\n\n\\end{itemize}\n\n\\begin{table}\n\\hrule\n\\begin{verbatim}\nclass Graph {\n\n  // names of features\n\n  String[] featName;\n\n  // space for labels for feature weights on edges, each is a\n  // feature index and a weight\n\n  int[] label_featIndex;\n  double[] label_featWeight;\n\n  // space for edges, each is a destination node and a\n  // list of labels, which point into the label space\n\n  int[] edge_dst;\n  int[] edge_labels_lo;\n  int[] edge_labels_hi;\n\n  // space for list of neighbors of nodes, each \n  // points into the edge space\n\n  int [] node_near_lo;\n  int [] node_near_hi;\n\n  // list of nodes in graph\n  int node_lo, node_hi;\n\n  // space for weight derivatives, which are structurally \n  // just like labels.  these maybe should be vectors since \n  // we don't know the size of this space in advance...?\n\n  int[] deriv_featIndex;\n  double[] deriv_featDeriv;\n\n  // list of derivative features for M[u][euv]\n  int[][] dM_lo;\n  int[][] dM_hi;\n}\n\\end{verbatim}\n\\caption{Proposed data structure for graph} \\label{alg:data}\n\\hrule\n\\end{table}\n\n\\begin{table}\n\\hrule\n\\begin{verbatim}\nfor (int u = g.node_lo; u < g.node_hi; u++) {\n  // euv is edge from u to v\n  for (euv = g.node_near_lo[u]; euv < g.node_near_hi[u]; euv++) {\n    int v = g.edge_dst[euv];\n    // luvk is k-th label on edge euv\n    for (luvk = g.edge_labels_lo[euv]; luvk = g.edge_labels_hi[euv]; luvk++) {\n      int i = g.label_featIndex[luvk];\n      double w = g.label_featWeight[luvk];\n      ...\n    }\n  }\n}\nfor (int d = g.dM_lo[u][euv]; d < g.dM_hi[u][euv]; d++) {\n  i = g.deriv_featIndex[d];\n  double v = g.deriv_featDeriv[d];\n  // v is partial/(partial feature i) if M[u][v]\n  ...\n}\n\\end{verbatim}\n\\caption{Accessing the proposed data structure for graph} \\label{alg:access}\n\\hrule\n\\end{table}\n\nA proposed data structure which would be very efficient is shown in\nTable~\\ref{alg:data} and \\ref{alg:access}.  Some things that aren't\nclear now are:\n\\begin{itemize}\n\\item Where does the feature-index $\\leftrightarrow$ feature-name\n  symbol table go?  Probably not in the graph as shown here.\n\\item Is $\\M$ and $\\dM$ part of the graph or a different structure?\n\\end{itemize}\nAlso a clarification: \\texttt{M} and \\texttt{dM\\_lo,dM\\_hi}, are not\ndense 2-matrixes, of size quadratic in the number of nodes, $n$.\nInstead \\texttt{M} is a length-$n$ array of variable-size arrays, and\n\\texttt{M[u]}, for node index \\texttt{u}, is an array of size $m_u$,\nwhere $m_u$ is the number of neighbors (edges away from) \\texttt{u}.\nAnd \\texttt{dM\\_lo,dM\\_hi} are parallel structures.\n\nA final note: the squashing function $f$ and its derivative $f'$ are\nonly used in computing $\\df$ in Equation~\\ref{eqn:fprime}.  One future\nextension to ProPPR might be to have facts with weights defined by\nparameters: e.g., facts like \\texttt{sim(a,b)} which when used would\nlead to an edge with a computed weight $s_{uv}$ based on an internal\nset of parameters $\\vec{\\lambda}$ (think of a learned similarity\nsubroutine).  A modular way of dealing with this might be worth\nthinking through.  Conceptually, $\\vec{\\lambda}$ is a part of\n$\\vek{w}$: one could have an interface which given an edge $u,v$ with\nweight $s_{uv}$ returns $f'(s_{uv})\\ddw s_{uv}$ in terms of components\nof $\\vec{\\lambda}$.  For training you would also need to pass in an\nupdate of the $\\vec{\\lambda}$ features to the learning subroutine....\n\n\\clearpage\n\\begin{appendix}\n\\section{Linear Algebra proof of imperative procedure for p and d updates}\n\n\\subsection{Computing the p update}\n\\begin{align*}\n\\vek{p}^{t+1} =& \\alpha \\vek{s} + (1-\\alpha)\\vek{p}^t \\M\\\\\n\\vek{p}^t \\M =& \\left[ \\begin{array}{ccccc} \np_0 & p_1 & p_2 & \\ldots & p_n \n\\end{array} \\right] \\left[ \\begin{array}{cccc}\n\\\\M_{00} & \\M_{01} & \\M_{02} & \\ldots \\\\\n\\\\M_{10} & \\M_{11} & \\M_{12} & \\ldots \\\\\n\\M_{20} & \\M_{21} & \\M_{22} & \\ldots \\\\\n\\vdots & \\vdots & \\vdots\n\\end{array} \\right]\\\\\n=& \\left[ \\begin{array}{cccc} p^{t+1}_0 & p^{t+1}_1 & p^{t+1}_2 & \\ldots \\end{array} \\right]\\\\\np^{t+1}_0 =& p_0 \\M_{00} + p_1 \\M_{10} + p_2 \\M_{20} + \\ldots\\\\\np^{t+1}_1 =& p_0 \\M_{01} + p_1 \\M_{11} + p_2 \\M_{21} + \\ldots\\\\\n\\end{align*}\n\nIf we set $p^{t+1}_u$, we must iterate across, over all terms of the first element, then all terms of the second element, etc:\n\n$$p^{t+1}_u += (1-\\alpha) p_v \\M_{vu}$$\n\nGiven our data structure for $\\M$ however, constructing $\\M_{vu}$ is difficult. To use $\\M_{uv}$ instead, we can set $p^{t+1}_v$ and iterate down, computing the first term of all elements, then the second term of all elements, etc:\n\n$$p^{t+1}_{v} += (1-\\alpha) p_u \\M_{uv}$$\n\n\\subsection{Computing the d update}\n\nComputing $d$ proceeds in much the same way:\n\n\\begin{align*}\n\\vek{d}^{t+1}_i =& (1-\\alpha)(\\vek{p}^t \\dM_i + \\vek{d}^t_i \\M)\n\\end{align*}\n\nWe'll start by deconstructing the first term only:\n\n\\begin{align*}\n\\vek{p}^t \\dM_i =& \\left[ \\begin{array}{cccc} p_0 & p_1 & p_2 & \\ldots \\end{array} \\right] \\\n\\left[ \\begin{array}{cccc}\n\\dM_{00,i} & \\dM_{01,i} & \\dM_{02,i} & \\ldots \\\\\n\\dM_{10,i} & \\dM_{11,i} & \\dM_{12,i} & \\ldots \\\\\n\\dM_{20,i} & \\dM_{21,i} & \\dM_{22,i} & \\ldots \\\\\n\\vdots & \\vdots & \\vdots\n\\end{array} \\right]\\\\\n=& \\left[ \\begin{array}{cccc} d^{t+1}_{0,i} & d^{t+1}_{1,i} & d^{t+1}_{2,i} & \\ldots \\end{array} \\right]\\\\\nd^{t+1}_{0,i} =& p_0 \\dM_{00,i} + p_1 \\dM_{10,i} + p_2 \\dM_{20,i} + \\ldots\\\\\np^{t+1}_{1,i} =& p_0 \\dM_{01,i} + p_1 \\dM_{11,i} + p_2 \\dM_{21,i} + \\ldots\\\\\n\\end{align*}\n\nWe have the same choice of setting $d^{t+1}_{u,i}$ or $d^{t+1}_{v,i}$, with the same dependence on using $\\dM_{vu,i}$ or $\\dM_{uv,i}$. Since we must use $\\dM_{uv,i}$ due to the way our data structure is constructed, we must update $d^{t+1}_{v,i}$:\n\n$$ d^{t+1}_{v,i} += (1-\\alpha) \\vek{p}^t_u \\dM_{uv,i} $$\n\nThe same principles hold for the second term:\n\n$$ d^{t+1}_{v,i} += (1-\\alpha) \\vek{d}^t_{u,i} \\M_{uv} $$\n\n\\end{appendix}\n\n\\end{document}\n\n", "meta": {"hexsha": "380494368cca1c23610b95beca26c1ff200e9c17", "size": 20097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/proppr-math/deriv.tex", "max_stars_repo_name": "TeamCohen/ProPPR", "max_stars_repo_head_hexsha": "2e0d978f96c2377ef3d26b80c17f38d2804f496c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 138, "max_stars_repo_stars_event_min_datetime": "2015-01-15T00:04:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-26T18:35:48.000Z", "max_issues_repo_path": "doc/proppr-math/deriv.tex", "max_issues_repo_name": "TeamCohen/ProPPR", "max_issues_repo_head_hexsha": "2e0d978f96c2377ef3d26b80c17f38d2804f496c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-09-01T16:58:27.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-11T21:51:11.000Z", "max_forks_repo_path": "doc/proppr-math/deriv.tex", "max_forks_repo_name": "TeamCohen/ProPPR", "max_forks_repo_head_hexsha": "2e0d978f96c2377ef3d26b80c17f38d2804f496c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 52, "max_forks_repo_forks_event_min_datetime": "2015-02-04T16:03:45.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-22T06:38:25.000Z", "avg_line_length": 36.0161290323, "max_line_length": 269, "alphanum_fraction": 0.6472110265, "num_tokens": 7218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7718434873426303, "lm_q1q2_score": 0.6274063523446788}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsfonts, graphicx}\n\\begin{document}\n\\section{Problem Statement}\nWe consider a special type of piecewise affine system, that the boundaries of the hybrid modes intersect at the origin. Mathematically, the system has this form\n\\begin{align}\n\t\\dot{x} = f(x) = A_ix \\text{ if } P_ix\\le 0\n\\end{align}\nNotice that the righ-hand side of $P_ix\\le0$ is zero vector, which guarantees that all mode boundaries pass through the origin. This also implies that $f(kx) = kf(x)$ if $k>0$.\n\nWe want to find a Lyapunov function satisfying\n\\begin{align}\n\tV(x) > 0 \\forall x\\neq 0\\\\\n\t\\dot{V}(x) < 0 \\forall x\\neq 0\\\\\n\tV(x) = 0\n\\end{align}\n\n\\textbf{Goal}: We want to prove that if there exists a piecewise affine Lyapunov function in the form \n\\begin{align}\n\tV(x) = g_i^Tx + h_i \\text{ if } C_ix\\le d_i \\label{eq:piecewise_affine_lyapunov}\n\\end{align}\nNamely in the $i'th$ piece $\\mathcal{P}_i=\\{x | C_ix \\le d_i\\}$, the Lyapunov function is an affine function of state $x$. Then there has to exist a piecewise linear Lyapunov function in the form\n\\begin{align}\n\t\\bar{V}(x) = \\bar{g}_i^Tx \\text{ if } \\bar{C}_i x \\le 0\n\\end{align}\nNamely the piecewise linear Lyapunov function $\\bar{V}$ is linear inside each piece, and each piece is a conic region originating from the origin.\n\n\\section{Proof}\nThe first step is to prove that the origin is at the vertex of some pieces $\\mathcal{P}_i$ in Lyapunov function $V(x)$. To prove this, suppose that the origin lies in the $i'th$ piece $\\mathcal{P}_i$. Since the Lyapunov function is linear within each piece, and $V(x)$ obtains its global minimal at the origin (implied by the strict positivity of Lyapunov function), we know that the origin must be a vertex of the polyhedron region $\\mathcal{P}_i$ (This is because the minimal of an LP must be obtained at the vertex of the polyhedron region). Hence the origin is at the vertices of many neighbouring pieces, as shown in the plot \\ref{fig:global_convergence1}, it cannot be in the strict interior of any polyhedron piece $\\mathcal{P}_i$.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.4\\textwidth]{./global_convergence1.eps}\n\t\\caption{The origin (black dot) has to be the shared vertex of the neighbouring pieces ($\\mathcal{P}_1, \\mathcal{P}_2, ..., \\mathcal{P}_6$ in the figure), it cannot be in the strict interior of any piece.}\n\t\\label{fig:global_convergence1}\n\\end{figure}\nAs $V(0)=0$, we know that $h_i = 0$ if $\\mathcal{P}_i$ has the origin as a vertex.\n\nNext we show that we can construct a piecewise linear Lyapunov function $\\bar{V}$ using the piecewise affine Lyapunov function $V$. The procedure is as follows\n\\begin{enumerate}\n\t\\item Select each of the piece $\\mathcal{P}_i$ that neighbours the origin.\n\t\\item For each of the piece $\\mathcal{P}_i$ in step 1, compute the cone of $\\mathcal{P}_i = \\{x | C_ix\\le d_i\\}$, by keeping the boundaries of $\\mathcal{P}_i$ that contain the origin, and remove the boundaries that don't contain the origin. We denote this conic region as $\\bar{\\mathcal{P}}_i=\\{x|\\bar{C}_i\\le 0\\}$.\n\t\\item Within each of the conic region $\\bar{\\mathcal{P}}_i$, the new Lyapunov function is defined as $\\bar{V}(x) = g_i^Tx \\text{ if } \\bar{C}_i \\le 0$. \n\\end{enumerate}\nThis procedure is shown in Fig.\\ref{fig:global_convergence2}.\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.4\\textwidth]{./global_convergence2.eps}\n\t\\caption{We construct the new Lyapunov function, by first forming the conic region of each piece that neighbours the origin. Hence we extend the region $\\mathcal{P}_1, ...\\mathcal{P}_6$ to infinity, and remove the pieces that don't neighbour the origin ($\\mathcal{P}_7, ...\\mathcal{P}_{11}$).}\n\t\\label{fig:global_convergence2}\n\\end{figure}\nNow we need to prove that $\\bar{V}$ is a valid Lyapunov function. Notice that in the polyhedron piece $\\mathcal{P}_i$, the Lyapunov function $V(x)$ is $V(x) = g_i^Tx$. Now for any state $x$ in $\\mathcal{P}_i$, we shoot a ray starting from the origin and passing $x$. We denote the state on this ray as $kx, k > 0$. Obviously this entire ray is in the conic piece $\\bar{\\mathcal{P}}_i$ (by the definition of the cone). We also know that $\\bar{V}(kx) = k\\bar{V}(x) = kV(x)>0$. The first equality is because the function $\\bar{V}$ is linear inside each piece, the second equality is because $\\bar{V}(x) = V(x) \\text{ if } x\\in\\mathcal{P}_i$. Finally, we know that $\\dot{\\bar{V}}(kx) = k\\dot{\\bar{V}}(x) = k\\dot{V}(x) < 0$. The first equality is because inside each conic piece $\\partial V/\\partial x$ is a constant, and the dynamics scales proportionally w.r.t $k$ ($f(kx) = kf(x)$).The second equality is because $\\bar{V}(x)$ is the same as $V(x)$ in the polyhedron region $\\mathcal{P}_i$. As a result, we prove that this new function $\\bar{V}(x)$ is a valid Lyapunov function. This piecewise linear function $\\bar{V}$ can be represented by neural network without bias term.\n\\end{document}\n", "meta": {"hexsha": "069eee36febe9f5b4a6f4ed6ae011e2f264e927d", "size": 4914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/global_convergence_proof.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/global_convergence_proof.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/global_convergence_proof.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": 92.7169811321, "max_line_length": 1172, "alphanum_fraction": 0.7277167277, "num_tokens": 1534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6274063486302625}}
{"text": "\\chapter{Prototype set classifier}\r\n\\label{ch_classifier}\r\n%\r\nIn this chapter, we introduce the prototype set classifier, consider how to fit it to data, test the fitting procedure on benchmark cases, and compare model performance to other algorithms.\r\n%\r\n\\section{Definition}\r\n\\label{sec_classifier_definition}\r\n%\r\nWe observe $N\\gg1$ i.i.d.\\ pairs $(X_n,Y_n)$ of random variables such that $X_n$ takes values in $\\R^D$, $D\\geq1$, and $Y_n$ is one of $K>1$ classes represented by the integers from 0 to $K-1$.\r\nOur goal is to estimate the conditional distribution of $Y_n$ given $X_n$.\r\nAs proset models are discriminative instead of generative, the distribution of $X_n$ is of no concern and we just deal with the observed realizations $x_n\\in\\R^D$ in practice.\r\nNominal or ordinal features can be included in the model via encoding as real vectors.\\par\r\n%\r\nA proset classifier is built from $B\\geq0$ ``batches'' of points selected from the available samples.\r\nEach batch is defined by a a nonempty subset $S_1,\\dots,S_B\\subset\\{1,\\dots,N\\}$ of the observation indices.\r\nThe collection of batches is denoted by\r\n%\r\n\\begin{equation}\r\n\\mathcal{S}:=\\{S_b:b\\in\\{1,\\dots,B\\}\\}\\label{eq_batches}\r\n\\end{equation}\r\n%\r\nor $\\mathcal{S}=\\emptyset$ if $B=0$.\r\nThe indices of each batch are $S_b=:\\{s_{b,1},\\dots,s_{b,J_b}\\}$ where $J_b:=|S_b|$.\r\nWe refer to the samples $(x_{s_{b,j}},y_{s_{b,j}})$ as `prototypes'.\r\nThe model treats each as a representative example for the distribution of $Y_n$ when $X_n$ is in a neighborhood of $x_{s_{b,j}}$.\r\nTo make this notion more precise, we require additional notation:\\par\r\n%\r\nThe empirical marginal probabilities of $Y$ are\r\n%\r\n\\begin{equation}\r\n\\hat{p}_{0,k}:=\\frac{1}{N}\\sum_{n=1}^N\\1_{\\{k\\}}(y_k)\\label{eq_p0k}\r\n\\end{equation}\r\n%\r\nwhere $\\1_A$ is the indicator function of a set $A$.\\par\r\n%\r\nThe unnormalized Gaussian kernel $G_v$ with feature weights (inverse bandwidths) $v\\in\\R^D$, $v_d\\geq0$, is\r\n%\r\n\\begin{equation}\r\nG_v:\\R^D\\rightarrow(0,1],\r\nz\\mapsto G_v(z):=\\exp\\left(-\\frac{1}{2}\\sum_{d=1}^D(v_dx_d)^2\\right)\\label{eq_kernel}\r\n\\end{equation}\r\n%\r\nWe associate each batch $b$ with a vector $v_b\\in\\R^D$, $v_{b,d}\\geq0$, and each prototype with a weight $w_{b,j}>0$ to estimate the conditional distribution as\r\n%\r\n\\begin{equation}\r\nP(Y=k|X=x)\\approx\\hat{p}_k(x):=\r\n\\frac{\\hat{p}_{0,k}+\\sum_{b=1}^B\\sum_{j=1}^{J_b}\\1_{\\{k\\}}(y_{s_{b,j}})w_{b,j}G_{v_b}(x-x_{s_{b,j}})}\r\n{1+\\sum_{b=1}^B\\sum_{j=1}^{J_b}w_{b,j}G_{v_b}(x-x_{s_{b,j}})}\r\n\\label{eq_pkx}\r\n\\end{equation}\r\n%\r\n\\begin{remark}\r\n\\begin{enumerate}\r\n\\item The sets $S_b$ are not required to be disjoint, so the same point can appear multiple times in (\\ref{eq_pkx}).\r\nAs each batch is associated with its own $v_b$, the impact on the model may be different every time a sample appears.\r\n%\r\n\\item We use unnormalized kernels, i.e., the integral over the kernel function is in general not equal to 1, since the scaling can be considered to be subsumed in the choice of $w_{b,j}$.\r\nThis avoids any complications related to the fact that the scaling for a Gaussian kernel depends on the number of features with nonzero coefficients.\r\n%\r\n\\item The kernels are parameterized in terms of inverse bandwidth to enable feature selection via an $L_1$ penalty on $v_{b,d}$.\r\nIf a weight is forced to zero by the penalty, the values of the corresponding feature in points of batch $b$ cease to affect the model.\r\nConversely, a large value of $v_{b,d}$ means that the model is very sensitive to variations in the feature.\r\nKernels are limited to a diagonal bandwidth structure (product kernel) instead of a full semi-positive definite matrix to be able to fit on large feature spaces with reasonable effort.\r\n%\r\n\\item The conditional probability (\\ref{eq_pkx}) is computed as a locally weighted average similar to the Nadaraya-Watson estimator (\\ref{eq_nadaraya_watson}) or the conditional distributions studied in \\cite{Hall_04}.\r\nHowever, there are two important differences:\r\n%\r\n\\begin{itemize}\r\n\\item The model uses a subset of the training samples with individual weights instead of the entire data with unit weights.\r\nThis is done to reduce the computational effort for training and scoring if data size is large.\r\nAlso, studying the prototypes selected for the model may help to understand its structure.\r\n%\r\n\\item The model adds the marginal probabilities to the contribution of the prototypes\r\nThis sets the scale for the weights $w_{b,j}$, which would otherwise be determined only up to a multiplicative constant.\r\nAdditionally, it defines a natural baseline for $B=0$ , i.e., the model that treats $Y_n$ as independent of the features.\r\n\\end{itemize}\r\n\\end{enumerate}\r\n\\end{remark}\r\n%\r\nFinding an optimal representation of the form (\\ref{eq_pkx}) for anything but a very small sample appears intractable.\r\nWe thus focus on providing a heuristic that results in models of good quality.\r\nThe general idea is to iteratively add batches of prototypes to a base model consisting of the marginal probabilities $p_{0,k}$.\r\nIn each iteration, the available samples are split into a set of candidates for prototypes and a remainder used for scoring.\r\nThe weights for the candidates and the feature weights for the new batch are chosen to maximize a modified log-likelihood function for the scoring data.\r\nModifications to the likelihood are\r\n%\r\n\\begin{enumerate}\r\n\\item reweighting the terms such that each class has the same overall weight as in the set of all samples.\r\nThis enables us to use a sampling scheme for candidates that does not draw proportionally from each class.\r\n%\r\n\\item adding elastic net penalties for both prototype and feature weights to suppress candidates and features with negligible impact on the model.\r\n\\end{enumerate}\r\n%\r\nThe method is greedy in so far that parameters selected during earlier iterations remain untouched.\r\nHyperparameters -- penalty weights and the number of batches -- are selected via cross-validation.\\par\r\n%\r\nTo state the modified likelihood and its derivatives, we make use of the following expression representing the unnormalized class probabilities truncated at batch $c\\geq0$:\r\n%\r\n\\begin{equation}\r\n\\hat{q}_{c,k}(x)=\\hat{p}_{0,k}\r\n+\\sum_{b=1}^c\\sum_{j=1}^{J_b}\\1_{\\{k\\}}(y_{s_{b,j}})w_{b,j}G_{v_b}(x-x_{s_{b,j}})\r\n\\label{eq_qckx}\r\n\\end{equation}\r\n%\r\nThese satisfy\r\n%\r\n\\begin{align}\r\n\\hat{p}_{k}(x)&=\\frac{\\hat{q}_{B,k}(x)}{\\sum_{l=0}^{K-1}\\hat{q}_{B,l}(x)}\\label{eq_q_properties}\\\\\r\n\\hat{q}_{0,k}(x)&=\\hat{p}_{0,k}\\notag\\\\\r\n\\forall c>0:\\hat{q}_{c,k}(x)&\r\n=\\hat{q}_{c-1,k}(x)+\\sum_{j=1}^{J_c}\\1_{\\{k\\}}(y_{s_{c,j}})w_{c,j}G_{v_c}(x-x_{s_{c,j}})\r\n\\notag\r\n\\end{align}\r\n%\r\nDuring the training phase, we do not yet know the final number of batches $B$ but grow the model iteratively.\r\nThe conditional probabilities using only batches up to $c$ are given by\r\n%\r\n\\begin{equation}\r\n\\hat{p}_{c,k}(x)=\\frac{\\hat{q}_{c,k}(x)}{\\sum_{l=0}^{K-1}\\hat{q}_{c,l}(x)}\\label{eq_pckx}\r\n\\end{equation}\r\n%\r\nwhich also satisfy $\\hat{p}_{0,k}(x)=\\hat{p}_{0,k}$.\\par\r\n%\r\nGiven the first $c-1$ batches, the parameters for batch $c>0$ are chosen to minimize the following function, which is the negative log-likelihood with regularization as per (\\ref{eq_regularization}) and reweighting as discussed above:\r\n%\r\n\\begin{align}\r\nf\\left(v_c,\\{w_{c,j}\\}_j|\\{x_n\\}_n\\right)\r\n&=-\\frac{1}{N}\\sum_{k=0}^{K-1}\\frac{N_k}{N_k-J_{c,k}}\\sum_{n\\in T_c}\r\n\\1_{\\{k\\}}(y_n)\\log(\\hat{p}_{c,k}(x_n))\\label{eq_log_likelihood}\\\\\r\n&+\\lambda_v\\left(\\frac{\\alpha_v}{2}\\sum_{d=1}^Dv_{c,d}^2\r\n+(1-\\alpha_v)\\sum_{d=1}^D|v_{c,d}|\\right)\\notag\\\\\r\n&+\\lambda_w\\left(\\frac{\\alpha_w}{2}\\sum_{j=1}^{J_c}w_{c,j}^2\r\n+(1-\\alpha_w)\\sum_{j=1}^{J_c}|w_{c,j}|\\right)\\notag\r\n\\end{align}\r\n%\r\nThe following expressions still need to be defined:\r\n%\r\n\\begin{itemize}\r\n\\item $N_k:=\\left|\\{n\\in\\{1,\\dots,N\\}:y_n=k\\}\\right|$ is the number of all samples that have class $k$.\r\n%\r\n\\item $J_{c,k}:=\\left|\\{j\\in\\{1,\\dots,J_c\\}:y_{s_{c,j}}=k\\}\\right|$\r\nis the number of all candidates in batch $c>0$ that have class $k$.\r\n%\r\n\\item $T_c:=\\{1,\\dots,N\\}\\setminus S_c$ is the set of samples not included as candidates for prototypes in batch $c>0$.\r\n%\r\n\\item $\\lambda_v\\geq0$ is the weight for the elastic net penalty applied to feature weights.\r\n%\r\n\\item $\\lambda_w\\geq0$ is the weight for the elastic net penalty applied to prototype weights.\r\n%\r\n\\item $\\alpha_v\\in[0,1]$ is the portion of $\\lambda_v$ assigned to the $L_2$ penalty for feature weights.\r\n%\r\n\\item $\\alpha_w\\in[0,1]$ is the portion of $\\lambda_w$ assigned to the $L_2$ penalty for prototype weights.\r\n\\end{itemize}\r\n%\r\nGiven a set of prototypes $S_c$, the objective function (\\ref{eq_log_likelihood}) is maximized subject to $v_{c,d}\\geq0$ and $w_{c,j}\\geq0$.\r\nNote that we permit $w_{c,j}=0$ as solution of the optimization problem which contradicts our earlier definition.\r\nHowever, since assigning zero weight to a point is equivalent to excluding it from the model, this does not cause any issues.\\par\r\n%\r\nAs all parameters are constrained to the first orthant, the fact that the $L_1$ penalty is not differentiable in zero does not pose a problem.\r\nIn fact, we can simply replace the absolute value with the identity function and solve the optimization task using a standard solver for continuous optimization with bounds like L-BFGS-B \\cite{Byrd_95}.\\par\r\n%\r\nTo gain the full advantage of using L-BFGS-B, we need to compute the gradient of (\\ref{eq_log_likelihood}) analytically.\r\nThe partial derivatives of $\\log(\\hat{p}_{c,k}(x))$, $c>0$, are:\r\n%\r\n\\begin{align}\r\n\\frac{\\partial}{\\partial v_{c,d}}\\log(\\hat{p}_{c,k}(x))&\r\n=\\frac{\\frac{\\partial}{\\partial v_{c,d}}\r\n\\sum_{j=1}^{J_c}\\1_{\\{k\\}}(y_{s_{c,j}})w_{c,j}G_{v_c}(x-x_{s_{c,j}})}\r\n{\\hat{q}_{c,k}(x)}\r\n\\label{eq_p_partial_v}\\\\\r\n&-\\frac{\\frac{\\partial}{\\partial v_{c,d}}\r\n\\sum_{j=1}^{J_c}w_{c,j}G_{v_c}(x-x_{s_{c,j}})}\r\n{\\sum_{l=0}^{K-1}\\hat{q}_{c,l}(x)}\\notag\\\\\r\n&=v_{c,d}\\left(\\frac{\\sum_{j=1}^{J_c}w_{c,j}\r\n(x_d-x_{s_{c,j},d})^2G_{v_c}(x-x_{s_{c,j}})}\r\n{\\sum_{l=0}^{K-1}\\hat{q}_{c,l}(x)}\\right.\\notag\\\\\r\n&\\left.-\\frac{\\sum_{j=1}^{J_c}\\1_{\\{k\\}}(y_{s_{c,j}})w_{c,j}\r\n(x_d-x_{s_{c,j},d})^2G_{v_c}(x-x_{s_{c,j}})}\r\n{\\hat{q}_{c,k}(x)}\\right)\\notag\\\\\r\n\\frac{\\partial}{\\partial w_{c,i}}\\log(\\hat{p}_{c,k}(x))&\r\n=\\frac{\\frac{\\partial}{\\partial w_{c,i}}\r\n\\sum_{j=1}^{J_c}\\1_{\\{k\\}}(y_{s_{c,j}})w_{c,j}G_{v_c}(x-x_{s_{c,j}})}\r\n{\\hat{q}_{c,k}(x)}\r\n\\label{eq_p_partial_w}\\\\\r\n&-\\frac{\\frac{\\partial}{\\partial w_{c,i}}\r\n\\sum_{j=1}^{J_c}w_{c,j}G_{v_c}(x-x_{s_{c,j}})}\r\n{\\sum_{l=0}^{K-1}\\hat{q}_{c,l}(x)}\\notag\\\\\r\n&=\\frac{\\1_{\\{k\\}}(y_{s_{c,i}})G_{v_c}(x-x_{s_{c,i}})}\r\n{\\hat{q}_{c,k}(x)}\r\n-\\frac{G_{v_c}(x-x_{s_{c,i}})}\r\n{\\sum_{l=0}^{K-1}\\hat{q}_{c,l}(x)}\\notag\r\n\\end{align}\r\n%\r\nThe partial derivatives of the objective function on the first orthant are\r\n%\r\n\\begin{align}\r\n\\frac{\\partial}{\\partial v_{c,d}}f(v_c,\\{w_{c,j}\\}_j|\\{x_n\\}_n)\r\n&=-\\frac{1}{N}\\sum_{k=0}^{K-1}\\frac{N_k}{N_k-J_{c,k}}\\sum_{n\\in T_c}\r\n\\1_{\\{k\\}}(y_n)\\frac{\\partial}{\\partial v_{c,d}}\\log(\\hat{p}_{c,k}(x_n))\r\n\\label{eq_l_partial_v}\\\\\r\n&+\\lambda(\\alpha_v v_{c,d}+(1-\\alpha_v))\\notag\\\\\r\n\\frac{\\partial}{\\partial w_{c,j}}f(v_c,\\{w_{c,j}\\}_j|\\{x_n\\}_n)\r\n&=-\\frac{1}{N}\\sum_{k=0}^{K-1}\\frac{N_k}{N_k-J_{c,k}}\\sum_{n\\in T_c}\r\n\\1_{\\{k\\}}(y_n)\\frac{\\partial}{\\partial w_{c,j}}\\log(\\hat{p}_{c,k}(x_n))\r\n\\label{eq_l_partial_w}\\\\\r\n&+\\lambda\\beta(\\alpha_w w_{c,j}+(1-\\alpha_w))\\notag\r\n\\end{align}\r\n%\r\nIt remains to consider how to choose the prototypes for each batch and the starting points for optimization.\r\nFor the former, we score the model for iteration $c-1$ on all samples to get a probability distribution for each $Y_n$.\r\nA sample is considered correctly classified iff the probability assigned to its true class is greater than that for the other classes.\r\nThis enables us to split the samples into $2K$ bins, i.e., the correctly and incorrectly classified samples for each class.\r\nWe now draw prototypes from these bins as evenly as possible, subject to the constraint that no bin is depleted, i.e., some samples from each bin should remain for scoring.\\par\r\n%\r\nTo make the above notion more precise, let $M>0$ be the total number of prototypes we want to consider for the new batch and $\\eta\\in(0,1)$ the  maximum fraction of samples we want to take from one bin.\r\nAlso, let $g_1,\\dots, g_{2K}\\geq0$ be the number of samples actually available in each bin, which satisfy w.l.o.g.\\ $g_1\\leq g_2\\leq\\dots\\leq g_{2K}$.\r\nTo arrive at a number of samples $h_1,\\dots,h_{2K}$ to draw from each bin, we use the following algorithm:\r\n%\r\n\\begin{samepage}\r\n\\begin{algorithm}[Number of prototypes per bin]~\r\n\\label{alg_bins}\r\n%\r\n\\begin{description}\r\n\\item{[1]} Assign $i\\leftarrow1$ and $R\\leftarrow M$.\r\n%\r\n\\item{[2]} Compute $r:=\\frac{R}{2K+1-i}$.\r\n%\r\n\\item{[3]} If $r\\leq\\eta g_i$: assign $h_i,\\dots,h_{2K}\\leftarrow r$ and go to [5].\r\n%\r\n\\item{[4]} Assign $h_i\\leftarrow\\eta g_i$, $i\\leftarrow i+1$, $R\\leftarrow R-h_i$, and go to [2].\r\n%\r\n\\item{[5]} Round each $h_i$ to the closest integer number.\r\n\\end{description}\r\n\\end{algorithm}\r\n\\end{samepage}\r\n%\r\nThus, we draw the maximum number of samples from the smallest bin that has not been processed until the remaining bins are large enough to draw an equal amount from each.\r\nIn case $\\sum_{i=1}^{2K}g_i<M$,  we draw the maximum admissible number of samples from each bin.\r\nIn case $g_i\\leq\\frac{M}{2K}$ for all $i$, we draw an even amount $\\frac{M}{2K}$ from each bin.\r\nNote that rounding or a lack of suitable samples may mean that we do not draw exactly $M$ candidates.\\par\r\n%\r\n\\begin{remark}\r\nThis choice of sampling prototypes is motivated by the desire to give equal consideration to each class, as well as to `easy wins' -- samples that are classified correctly but could be assigned still higher probability -- and `hard cases' -- samples that are not classified correctly by the current iteration.\r\nFor a very unbalanced population, it may not be possible to treat the rare classes exactly equal to the frequent ones.\r\nHowever, the rare classes are still assigned greater weight in model building than their proportion in the population.\\par\r\n%\r\nNote also that at the start of iteration $c=1$, when the model consists only of the marginal probabilities, a sample is classified correctly iff it belongs to the most frequent class.\r\nThus, half of all bins are completely empty in this situation.\r\n\\end{remark}\r\n%\r\nIn order to identify good prototypes for every class, we need to include samples from each among the candidates for prototypes and the remaining samples used for scoring. Using the proposed algorithm for distribution, the following condition is necessary and sufficient:\r\n%\r\n\\begin{align}\r\n&\\forall k\\in\\{0,\\dots,K-1\\}:\\forall n\\in\\{0,\\dots,N_k\\}:\\label{eq_min_cases}\\\\\r\n&(\\eta n\\geq0.5\\vee\\eta(N_k-n)\\geq0.5)\\wedge(\\eta n<n-0.5\\vee\\eta(N_k-n)<N_k-n-0.5)\\notag\r\n\\end{align}\r\n%\r\nThe $n$ represents the number of samples of class $k$ that are correctly classified in iteration $c-1$.\r\nThus, the first clause states that the fraction $\\eta$ of either the correctly or incorrectly classified cases needs to be large enough to result in a single prototype being drawn after rounding.\r\nLikewise, the second clause states that the fraction $\\eta$ of either group needs to be small enough such that at least one sample remains for scoring.\\par\r\n%\r\n\\begin{lemma}\r\nCondition (\\ref{eq_min_cases}) can be restated more compactly as\r\n%\r\n\\begin{equation}\r\n\\forall k\\in\\{0,\\dots,K-1\\}:\\lceil0.5N_k\\rceil\\geq0.5\\eta^{-1}\\wedge\\lceil0.5N_k\\rceil>0.5(1-\\eta)^{-1}\\label{eq_min_cases_2}\r\n\\end{equation}\r\n%\r\nwhere the brackets indicate rounding up.\r\n\\end{lemma}\r\n%\r\n\\paragraph{Proof:} we show first that for any $k$ holds\r\n%\r\n\\begin{equation}\r\n\\forall n\\in\\{0,\\dots,N_k\\}:\\eta n\\geq0.5\\vee\\eta(N_k-n)\\geq0.5\\iff\\lceil0.5N_k\\rceil\\geq0.5\\eta^{-1}\\label{eq_condition_proof}\r\n\\end{equation}\r\n%\r\nThe left-hand side implies the right-hand if we choose $n=\\lceil0.5N_k\\rceil$.\\par\r\n%\r\nThe right-hand side implies the left-hand side since for any $n$, either $n$ or $N_k-n$ has to be greater or equal to $\\lceil0.5N_k\\rceil$.\\par\r\n%\r\nFor the remaining clauses, note that $\\eta n<n-0.5$ is equivalent to $(1-\\eta)N>0.5$ so that we can use a similar argument to the one above.$\\quad\\Box$\\par\r\n%\r\nA check for condition (\\ref{eq_min_cases_2}) is implemented in the software to ensure that samples of each class are available both as prototypes and for scoring.\r\nHowever, it does not guarantee that the algorithm is able to find meaningful structure in the data.\r\nFor example, the recommended default $\\eta=0.5$ requires only that $N_k\\geq3$ for all $k$, which is inadequate for supervised learning.\\par\r\n%\r\nRegarding the starting values for optimization, we initialize all $v_{c,d}$ to $10D^{-1}$ and all $w_{c,j}$ to 1.\r\nThe former choice assumes that the features have a scale on the order of magnitude of 1, e.g., they have been scaled to unit variance.\r\nThus, setting the inverse bandwidth for a single feature to 10 means the kernels for the starting solution describe a structure that is more granular than the whole distribution.\r\nDividing the weight by the total number of features ensures that the sum of squares in the exponent of (\\ref{eq_kernel}) is always of a similar magnitude and the exponential function does not vanish.\r\nA prototype weight of 1 is of the same order of magnitude as the marginal probabilities.\r\n%\r\n\\begin{remark}\r\nThe optimization problem does in general have multiple stationary points, including the trivial solution where all weights are equal to zero.\r\nProvided the features are scaled, the proposed starting value for the feature weights appears to work well in practice.\\par\r\n%\r\nScaling the features is also recommended for a different reason.\r\nThe size of the elastic net penalty can only be interpreted relative to the scale of the partial derivatives.\r\nThus, to penalize all features equally, they need to be equally scaled.\r\n\\end{remark}\r\n%\r\nDespite regularization, there is one situation in which the selection of prototypes is not parsimonious.\r\nIf multiple candidate points have the same target and feature values for all features with positive weights, the $L_2$-penalty causes the algorithm to assign equal weight to all candidates.\r\nIf this weight is positive, the model retains multiple copies of what is effectively the same prototype (the original samples can differ in the values of excluded features).\r\nTo simplify the model representation, we add a clean-up stage to the algorithm:\\par\r\n%\r\nEach prototype in a batch is represented by the combined vector of the active features and target.\r\nTwo prototypes are considered equivalent if the maximum norm of the difference of their associated vectors does not exceed some small tolerance.\r\nThis notion is generalized from pairs to larger groups by finding all connected components in the graph where each node represents a prototype and an edge indicates pairwise equivalence.\r\nWe then replace all prototypes belonging to the same component by a single prototype using the combined weight, as well as the features of the sample appearing first in the training data.\r\n%\r\n\\section{Fit strategy}\r\n\\label{sec_classifier_fit}\r\n%\r\nFitting a proset classifier is controlled by seven hyperparameters:\r\n%\r\n\\begin{itemize}\r\n\\item The number of batches $B$.\r\n%\r\n\\item The number $M$ of candidates for prototypes evaluated per batch.\r\n%\r\n\\item The maximum fraction $\\eta$ of candidates drawn from one bin using Algorithm \\ref{alg_bins}.\r\n%\r\n\\item The penalty term $\\lambda_v$ for the feature weights.\r\n%\r\n\\item The penalty term $\\lambda_w$ for the prototype weights.\r\n%\r\n\\item The ratio $\\alpha_v$ of $\\lambda_v$ assigned as $L_2$ penalty term.\r\n%\r\n\\item The ratio $\\alpha_w$ of $\\lambda_w$ assigned as $L_2$ penalty term.\r\n\\end{itemize}\r\n%\r\nOne goal of the case studies in this section is to identify good default values and indicate which parameters are worthwhile to tune.\r\nSome of the key findings are summarized here:\r\n%\r\n\\begin{enumerate}\r\n\\item Fitting a few large batches is preferable to many small ones.\r\nThe first batch has the largest impact on the model score and a large first batch results in a better overall score.\r\nWe believe the reason for this is that model quality depends on finding good constellations of prototypes, not just individual prototypes.\r\nSuitable constellations are more likely to occur in larger batches.\\par\r\n%\r\nAdding too many batches to a model leads to saturation, not overfitting.\r\nThe number of prototypes chosen per batch decreases, possibly down to zero.\r\nThe corresponding model scores fluctuate slightly around a common level.\r\nThus, using a small number of batches is mostly a question of reducing computational effort.\\par\r\n%\r\nWe recommend $M=1,000$ candidates per batch and a single batch ($B=1$) as default.\r\nIf optimizing with respect to the number of batches, $B=10$ is a reasonable upper limit.\r\n%\r\n\\item If the number of samples in a bin is too small for drawing the desired number of candidates, a compromise is to use half of the samples as candidates and the others as reference points for computing the likelihood.\r\nThus, we fix $\\eta=0.5$.\r\n%\r\n\\item The penalty $\\lambda_v$ for the feature weights controls the smoothness of the model.\r\nIt is the main safeguard against overfitting.\\par\r\n%\r\nIn the case study for the classifier, good values lie in the range from $10^{-6}$ to $10^{-1}$.\r\nChoosing $10^{-3}$ as default works for all cases.\r\nHowever, if an experimenter wants to tune only one parameter, it should be $\\lambda_v$.\r\n%\r\n\\item The penalty $\\lambda_w$ for the prototype weights controls how much weight can be assigned to a single prototype.\r\nWe observe that increasing $\\lambda_w$ within a certain range can actually lead to more candidate points being included in the model with nonzero weight.\r\nFurther increases gradually lead to underfitting.\r\nHowever, reducing $\\lambda_w$ does not lead to appreciable overfitting.\r\nIt appears that values below a certain threshold mostly control the preference for few prototypes with large weights versus more prototypes with smaller weights.\r\nAbove the threshold, the estimated distribution is shrunk towards the marginal probabilities.\r\nThis is desirable to some degree for avoiding overfitting.\\par\r\n%\r\nIn the case study for the classifier, good values lie in the range from $10^{-9}$ to $10^{-4}$.\r\nChoosing $10^{-8}$ as default works for all cases.\r\n%\r\n\\item A dominant $L_2$-penalty ($\\alpha_v$ and $\\alpha_w$ close to 1.0) yields slightly better results in the case study than either a dominant $L_1$- or balanced penalty.\r\nThe default values recommended for the algorithm are $\\alpha_v=\\alpha_w=0.95$.\r\n\\end{enumerate}\r\n%\r\nThe case study uses the following procedure for hyperparameter search, subject to small variations described later:\r\n%\r\n\\begin{algorithm}[Hyperparameter selection]~\r\n\\label{alg_hyperparameters}\r\n%\r\n\\begin{enumerate}\r\n\\item Choose $M$, $\\eta$, $\\alpha_v$, and $\\alpha_w$ based on the above recommendations.\r\nChoose a range for $\\lambda_v$, a range for $\\lambda_w$, and a set of candidates for $B$ (e.g., the numbers from 0 to 10).\r\n%\r\n\\item Split the data into a training set (70 \\%) and test set (30 \\%), stratified by class.\r\n%\r\n\\item\\textbf{Stage 1}\r\n%\r\n\\begin{enumerate}\r\n\\item Randomly generate 50 pairs $(\\lambda_v,\\lambda_w)$.\r\nEach $\\lambda$ is sampled uniformly on the log-scale from the chosen range.\r\n%\r\n\\item Perform five-fold cross-validation on the training set using $B=1$.\r\n%\r\n\\item Compute the mean and standard deviation of log-loss for each pair of penalties over the left-out folds.\r\n%\r\n\\item Determine a threshold for model quality by taking the minimal mean log-loss and adding the corresponding standard deviation.\r\n%\r\n\\item Among all pairs whose mean log-loss is less than or equal to the threshold, choose the one maximizing the geometric mean $\\sqrt{\\lambda_v\\lambda_w}$.\r\n\\end{enumerate}\r\n%\r\n\\item\\textbf{Stage 2}\r\n\\begin{enumerate}\r\n\\item Perform five-fold cross-validation on the training set using the parameters from stage 1 and the maximal number of batches.\r\n%\r\n\\item For each value of $B$ up to the maximum, evaluate the models on the left-out fold and compute mean and standard deviation of log-loss.\r\n%\r\n\\item Determine a threshold for model quality by taking the minimal mean log-loss and adding the corresponding standard deviation.\r\n%\r\n\\item Among all candidates whose mean log-loss is less than or equal to the threshold, choose the smallest $B$.\r\n\\end{enumerate}\r\n%\r\n\\item Refit the model with parameters selected in stages 1 and 2 on all training data.\r\n%\r\n\\item Score the final model on the test data.\r\n\\end{enumerate}\r\n\\end{algorithm}\r\n%\r\nThe purpose of stage 1 is to identify good values for the most important parameters $\\lambda_v$ and $\\lambda_w$.\r\nBased on the observation that the first batch has the most impact, we fix $B=1$ during this stage to save computation time.\r\nControlling $B$ can be treated as a secondary concern, since it appears to be impossible to overfit by increasing $B$.\r\nIt is still necessary to test larger values as more complex problems may be underfitted with $B=1$.\\par\r\n%\r\nNote that stage 2 only fits five models up to the maximum number of batches as these can also be evaluated for smaller choices of $B$.\r\nThis introduces a dependency between the means and standard deviations as estimates reuse the same initial batches.\r\nHowever, as keeping $B$ small is a secondary concern, we consider this time-saving approach acceptable.\\par\r\n%\r\nThe parameters selected in each stage are not necessarily those that minimize mean cross-validation log-loss.\r\nInstead, we consider all sets of parameters that are `equivalent' to the optimizer in the sense that their mean log-loss is within one standard error of the optimum.\r\nFrom these, we pick the parameters that yield the sparsest model.\r\nThis `1 SE rule' is a recommendation from R package \\texttt{glmnet} \\cite{Friedman_10}.\r\nThe authors observe that a model using the optimal parameters tends to overfit the cross-validation sample, which is mitigated by the rule.\r\nThe multiplier of 1 is of course arbitrary but a common `rule of thumb' in statistics.\r\nIn case multiple parameters control sparseness, we need to decide which set we consider `sparsest'.\r\nFor stage 1, maximizing the geometric mean gives equal importance to both penalties.\\par\r\n%\r\nAs discussed in the introduction, we use the threshold obtained via the `1 SE rule' also to compare models derived via different fit strategies or classification algorithms.\r\nFor the classifier that performs best on testing data, the threshold found during stage 2 is used as upper bound on log-loss to determine which of the other classifiers are still considered `equivalent'.\r\n%\r\n\\section{Benchmarks for hyperparameter selection}\r\n\\label{sec_classifier_benchmarks}\r\n%\r\nIn this section, we test variations of the fit strategy outlined above on different benchmark cases.\r\nWe use four small data sets that come as `toy' examples with Python package \\texttt{sklearn} \\cite{Pedregosa_11}, plus two slightly larger artificial data sets:\r\n%\r\n\\begin{enumerate}\r\n\\item\\textbf{Iris 2f:} this data set consists of the first two features of Fisher's famous iris data set \\cite{Fisher_36}.\r\nWe limit the analysis to two of four features (sepal length and width) as this allows us to visualize the decision surface of the classifier as a 2d plot.\r\nThe data set comprises 150 samples for three species of iris flower, with 50 samples per class.\r\nOne class is linearly separable from the others, but measurements for the remaining two overlap.\r\n%\r\n\\item\\textbf{Wine:} this data set from the  UCI Machine Learning Repository \\cite{Dua_19} consists of chemical analysis data for wines from three different cultivators.\r\nIt consists of 178 samples with between 48 and 71 samples per class.\r\nThe data is known to be separable \\cite{Aeberhard_92}.\r\n%\r\n\\item\\textbf{Cancer:} this data set from the UCI Machine Learning Repository \\cite{Dua_19} consists of medical analysis data from breast tissue samples.\r\nThe 569 samples are classified as either malignant (212 samples) or benign (357 samples).\r\n%\r\n\\item\\textbf{Digits:} this data set from the UCI Machine Learning Repository \\cite{Dua_19} consists of monochrome images of handwritten digits downsampled to an eight-by-eight grid.\r\nThe 1,797 samples are approximately balanced among the 10 digits.\r\n%\r\n\\item\\textbf{Checker:} for this artificial data set, we sample two features uniformly on the unit square and assign class labels deterministically to create an eight-by-eight checkerboard.\r\nThe pattern defeats methods that rely on global properties of the data like correlation, e.g., logistic regression.\r\nIt can be recovered successfully by methods that model local structure, e.g., a k-nearest neighbor classifier or decision tree.\r\nThe total number of samples is 6,400, so each square of the pattern contains approximately 100 data points.\r\n%\r\n\\item\\textbf{XOR 6f:} for this artificial data set, we sample six features independently and uniformly on the interval $[-1.0, 1.0]$.\r\nThe class label is assigned deterministically based on the sign of the product of features: a positive (or zero) sign is class 1, a negative sign is class 0.\r\nThis is similar to the `continuous XOR' problem found in the \\texttt{mlbench} library for R \\cite{Leisch_21}, except that we only distinguish two classes.\r\nDespite being deterministic, this problem appears to be a hard even for classifiers that model local structure.\r\nThe total number of samples is 6,400, so each orthant of the feature space contains approximately 100 data points.\r\n\\end{enumerate}\r\n%\r\nThe first three experiments consider the impact of $\\alpha_v$ and $\\alpha_w$ on model behavior.\r\nProset classifiers are fitted to all six data sets with fixed $M=1,000$ and $\\eta=0.5$.\r\nPenalty weights are sampled from the ranges $\\lambda_v\\in(10^{-6},10^{-1})$ and $\\lambda_w\\in(10^{-9},10^{-4})$, while the number of batches is allowed to vary between 0 and 10.\r\nThe first experiment uses a dominant $L_1$-penalty ($\\alpha_v=\\alpha_w=0.05$), the second uses balanced penalties ($\\alpha_v=\\alpha_w=0.50$), and the third a dominant $L_2$-penalty ($\\alpha_v=\\alpha_w=0.95$).\\par\r\n%\r\n\\begin{figure}\r\n\\caption{[E1] Parameter search for Iris 2F data}\r\n\\label{fig_parameter_search}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{Stage 1}]{\\includegraphics[height=0.4\\textheight]{figures/iris_2f_dominant_l1_2d_search.pdf}}\\\\\r\n\\subfloat[\\textbf{Both stages}]{\\includegraphics[width=0.99\\textwidth]{figures/iris_2f_dominant_l1_1d_search.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nFigure \\ref{fig_parameter_search} shows parameter search results for the first experiment using iris data.\r\nIn the lower plot, the log-loss for stage 1 as a function of either $\\lambda_v$ or $\\lambda_w$ appears highly variable.\r\nHowever, this is mostly due to changes in the other parameter, as evidenced by the surface plot.\r\nComplete results for all data sets are presented in tables \\ref{tab_e1}, \\ref{tab_e2}, and \\ref{tab_e3}.\r\nA comparison of the first six experiments is found in table \\ref{tab_e1_to_e6}.\r\nThe description of individual experiments comprises the following information:\r\n%\r\n\\begin{description}\r\n\\item[Data:] the number of classes, as well as the size of the whole data set and train-test split.\r\n%\r\n\\item[Candidates:] the approximate number of candidates for prototypes used to build the final model.\r\nWhile $M=1,000$ candidates are specified for each model, the effective maximum for small data sets is around 35 \\% of the available samples: training data is 70 \\% of all samples and $\\eta=0.5$ allows at most 50 \\% of data in one bin to be used as prototypes.\r\n%\r\n\\item[Stage 1:] results for selecting $\\lambda_v$ and $\\lambda_w$ using a single batch.\r\nLists the optimal and chosen parameters according to the `1 SE rule' (see algorithm \\ref{alg_hyperparameters}), together with the achieved mean log-loss from cross-validation.\r\nThe given threshold is the one for the `1 SE rule', i.e., the sum of the minimal mean log-loss and corresponding standard deviation.\r\n%\r\n\\item[Stage 2:] results for selecting $B$ using the penalty weights chosen in stage 1.\r\n%\r\n\\item[Final model:] information about the final model fitted on all training data with parameters determined in stages 1 and 2.\r\nThe number of features and prototypes, as well as the scores achieved for the test data.\r\nApart from log-loss, the measures used for evaluation are ROC-AUC and balanced accuracy.\\par\r\n%\r\nFor multi-class problems, the stated ROC-AUC values is the unweighted average for all pairwise comparisons of two classes.\r\nThis generalization to more than two classes is recommended in \\cite{Hand_01} as being robust to class imbalance.\\par\r\n%\r\nTo compute balanced accuracy, we use the `naive' rule that assigns each sample the class label with the highest estimated probability.\r\nThe reported score is the unweighted average of the correct classification rates for each class.\r\n\\end{description}\r\n%\r\n\\begin{table}\r\n\\caption{[E1] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.05$)}\r\n\\label{tab_e1}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$1.1\\times10^{-2}$&$6.9\\times10^{-4}$&$5.5\\times10^{-3}$&$1.2\\times10^{-5}$&$4.5\\times10^{-3}$&$1.0\\times10^{-2}$\\\\\r\nSelected $\\lambda_v$&$1.1\\times10^{-2}$&$3.5\\times10^{-3}$&$1.1\\times10^{-2}$&$1.8\\times10^{-3}$&$5.5\\times10^{-3}$&$1.1\\times10^{-2}$\\\\\r\nOptimal $\\lambda_w$&$1.0\\times10^{-5}$&$1.1\\times10^{-6}$&$8.3\\times10^{-8}$&$3.4\\times10^{-9}$&$1.3\\times10^{-8}$&$4.6\\times10^{-7}$\\\\\r\nSelected $\\lambda_w$&$1.8\\times10^{-5}$&$3.1\\times10^{-5}$&$1.8\\times10^{-5}$&$7.7\\times10^{-8}$&$8.3\\times10^{-8}$&$1.0\\times10^{-5}$\\\\\r\nOptimal log-loss&0.47&0.12&0.09&0.16&0.17&0.53\\\\\r\nThreshold&0.60&0.17&0.14&0.19&0.18&0.55\\\\\r\nSelected log-loss&0.54&0.12&0.09&0.19&0.18&0.55\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&2&5&1&9&1&1\\\\\r\nSelected batches&2&2&1&1&1&1\\\\\r\nOptimal log-loss&0.46&0.12&0.10&0.18&0.19&0.55\\\\\r\nThreshold&0.54&0.16&0.14&0.22&0.20&0.56\\\\\r\nSelected log-loss&0.46&0.13&0.10&0.19&0.19&0.55\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&6&3&19&2&6\\\\\r\nPrototypes&34&43&24&546&257&309\\\\\r\nLog-loss&0.62&0.14&0.13&0.15&0.17&0.55\\\\\r\nROC-AUC&0.86&0.99&0.99&1.00&0.99&0.81\\\\\r\nBalanced acc.&0.76&0.97&0.94&0.97&0.95&0.71\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E2] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.50$)}\r\n\\label{tab_e2}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$5.6\\times10^{-3}$&$1.0\\times10^{-2}$&$5.5\\times10^{-3}$&$1.2\\times10^{-5}$&$9.5\\times10^{-4}$&$5.5\\times10^{-3}$\\\\\r\nSelected $\\lambda_v$&$1.1\\times10^{-2}$&$3.5\\times10^{-3}$&$1.1\\times10^{-2}$&$4.5\\times10^{-3}$&$9.5\\times10^{-4}$&$1.0\\times10^{-2}$\\\\\r\nOptimal $\\lambda_w$&$1.7\\times10^{-5}$&$4.6\\times10^{-7}$&$8.3\\times10^{-8}$&$3.4\\times10^{-9}$&$5.6\\times10^{-9}$&$8.3\\times10^{-8}$\\\\\r\nSelected $\\lambda_w$&$1.0\\times10^{-5}$&$3.1\\times10^{-5}$&$1.8\\times10^{-5}$&$1.3\\times10^{-8}$&$5.6\\times10^{-9}$&$4.6\\times10^{-7}$\\\\\r\nOptimal log-loss&0.45&0.10&0.09&0.17&0.17&0.53\\\\\r\nThreshold&0.51&0.17&0.14&0.20&0.17&0.54\\\\\r\nSelected log-loss&0.46&0.13&0.09&0.19&0.17&0.54\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&4&10&1&3&1&1\\\\\r\nSelected batches&3&2&1&1&1&1\\\\\r\nOptimal log-loss&0.46&0.13&0.10&0.16&0.18&0.54\\\\\r\nThreshold&0.49&0.16&0.14&0.19&0.19&0.55\\\\\r\nSelected log-loss&0.47&0.14&0.10&0.18&0.18&0.54\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&7&3&18&2&6\\\\\r\nPrototypes&30&69&54&533&281&360\\\\\r\nLog-loss&0.49&0.20&0.13&0.18&0.16&0.53\\\\\r\nROC-AUC&0.90&0.98&0.99&1.00&0.99&0.82\\\\\r\nBalanced acc.&0.73&0.93&0.95&0.97&0.95&0.72\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E3] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.95$)}\r\n\\label{tab_e3}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$5.6\\times10^{-3}$&$3.8\\times10^{-5}$&$5.5\\times10^{-3}$&$7.8\\times10^{-6}$&$3.1\\times10^{-5}$&$5.5\\times10^{-3}$\\\\\r\nSelected $\\lambda_v$&$1.1\\times10^{-2}$&$1.1\\times10^{-2}$&$1.1\\times10^{-2}$&$9.5\\times10^{-4}$&$2.9\\times10^{-4}$&$5.5\\times10^{-3}$\\\\\r\nOptimal $\\lambda_w$&$1.7\\times10^{-5}$&$6.9\\times10^{-9}$&$8.3\\times10^{-8}$&$1.6\\times10^{-9}$&$4.3\\times10^{-9}$&$8.3\\times10^{-8}$\\\\\r\nSelected $\\lambda_w$&$1.0\\times10^{-5}$&$1.8\\times10^{-5}$&$1.8\\times10^{-5}$&$5.6\\times10^{-9}$&$6.9\\times10^{-8}$&$8.3\\times10^{-8}$\\\\\r\nOptimal log-loss&0.44&0.11&0.09&0.17&0.18&0.53\\\\\r\nThreshold&0.49&0.18&0.14&0.19&0.20&0.54\\\\\r\nSelected log-loss&0.46&0.17&0.11&0.18&0.19&0.53\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&5&5&1&8&1&10\\\\\r\nSelected batches&3&2&1&2&1&1\\\\\r\nOptimal log-loss&0.51&0.14&0.10&0.14&0.19&0.51\\\\\r\nThreshold&0.57&0.17&0.14&0.17&0.20&0.53\\\\\r\nSelected log-loss&0.56&0.15&0.10&0.16&0.19&0.53\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&7&4&30&2&6\\\\\r\nPrototypes&49&52&56&861&328&413\\\\\r\nLog-loss&0.43&0.14&0.13&0.15&0.18&0.52\\\\\r\nROC-AUC&0.91&1.00&0.99&1.00&0.99&0.82\\\\\r\nBalanced acc.&0.71&0.98&0.98&0.97&0.95&0.72\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\clearpage\r\n%\r\nIn the experiments, a dominant $L_1$-penalty yields slightly worse results than balanced penalties or a dominant $L_2$-penalty.\r\nAlso, we have occasionally observed (not in the results reported here) that a dominant $L_1$-penalty causes too few features to be selected for the final model.\r\nThis happens even though models created during cross-validation do not underfit.\r\nThe likely reason is that random candidate selection for small sample size can result in a set of candidates hat does not fully represent the data.\r\nSince a dominant $L_2$-penalty slightly outperforms the balanced case in the trials, we recommend $\\alpha_v=\\alpha_w=0.95$ as default values.\\par\r\n%\r\n\\begin{table}\r\n\\caption{[E4] Use optimal hyperparameters ($\\alpha_v=\\alpha_w=0.95$)}\r\n\\label{tab_e4}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$5.6\\times10^{-3}$&$3.8\\times10^{-5}$&$5.5\\times10^{-3}$&$7.8\\times10^{-6}$&$3.1\\times10^{-5}$&$5.5\\times10^{-3}$\\\\\r\nOptimal $\\lambda_w$&$1.7\\times10^{-5}$&$6.9\\times10^{-9}$&$8.3\\times10^{-8}$&$1.6\\times10^{-9}$&$4.3\\times10^{-9}$&$8.3\\times10^{-8}$\\\\\r\nOptimal log-loss&0.44&0.11&0.09&0.17&0.18&0.53\\\\\r\nThreshold&0.49&0.18&0.14&0.19&0.20&0.54\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&5&5&1&8&1&10\\\\\r\nOptimal log-loss&0.51&0.14&0.10&0.14&0.19&0.51\\\\\r\nThreshold&0.57&0.17&0.14&0.17&0.20&0.53\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&11&3&41&2&6\\\\\r\nPrototypes&65&204&93&3,053&595&403\\\\\r\nLog-loss&0.48&0.05&0.11&0.13&0.16&0.52\\\\\r\nROC-AUC&0.87&1.00&0.99&1.00&0.99&0.83\\\\\r\nBalanced acc.&0.69&0.98&0.95&0.97&0.94&0.74\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nThe fourth experiment shows the effect of using the optimal parameters from cross-validation instead of the equivalent sparser solution (see table \\ref{tab_e4}).\r\nIn half of the cases, results actually outperform those of the first three experiments.\r\nHowever, the log-loss scores for [E3] are still below the equivalence thresholds for [E4] in these cases.\r\nThis means the metrics for the benchmark cases do not indicate that the `1 SE rule' is necessary to prevent overfitting, but we can use it to obtain a sparser parameterization with negligible loss in quality.\r\n%\r\n\\clearpage\r\n%\r\n\\begin{figure}\r\n\\caption{Proset decision surfaces for case Iris 2f}\r\n\\label{fig_proset_decision_iris_2f}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{[E1] $\\lambda_v=\\lambda_w=0.05$, `1 SE rule'}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_dominant_l1_surf_test.pdf}}\r\n\\subfloat[\\textbf{[E2] $\\lambda_v=\\lambda_w=0.50$, `1 SE rule'}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_balanced_surf_test.pdf}}\\\\\r\n\\subfloat[\\textbf{[E3] $\\lambda_v=\\lambda_w=0.95$, `1 SE rule'}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_dominant_l2_surf_test.pdf}}\r\n\\subfloat[\\textbf{[E4] $\\lambda_v=\\lambda_w=0.95$, optimal hyperparameters}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_dominant_l2_surf_opt_test.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nIf we study the decision surfaces for the Iris 2f benchmark, it does look like [E4] has a slight tendency to overfit.\r\nFigure \\ref{fig_proset_decision_iris_2f} shows the surface plots for experiments [E1] to [E4].\r\nThe colors indicates the class with the highest estimated probability in that region of the feature space.\r\nOnly the result for [E3] appears fully convincing to us.\r\nIt separates the feature space near the training data into three contiguous regions with smooth boundaries.\r\nThe surfaces for [E1] and [E4] appear overly complex and somewhat arbitrary, which we take as a visual indicator of overfitting.\r\n[E2] oddly prefers class `virginica' in the lower left, although there is no training data in this region.\r\nThis is due to the layering of kernels with different bandwidths in a model with multiple batches.\\par\r\n%\r\n\\clearpage\r\n%\r\n\\begin{table}\r\n\\caption{[E5] Grid search for $\\lambda_v$ ($\\lambda_w=10^{-8}$ and $\\alpha_v=\\alpha_w=0.95$)}\r\n\\label{tab_e5}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$1.0\\times10^{-2}$&$3.2\\times10^{-6}$&$1.0\\times10^{-2}$&$1.0\\times10^{-4}$&$3.2\\times10^{-4}$&$1.0\\times10^{-2}$\\\\\r\nSelected $\\lambda_v$&$1.0\\times10^{-2}$&$3.2\\times10^{-2}$&$3.2\\times10^{-2}$&$3.2\\times10^{-2}$&$3.2\\times10^{-4}$&$1.0\\times10^{-2}$\\\\\r\nOptimal log-loss&0.51&0.11&0.08&0.20&0.17&0.52\\\\\r\nThreshold&0.63&0.16&0.12&0.22&0.18&0.53\\\\\r\nSelected log-loss&0.51&0.14&0.10&0.21&0.17&0.52\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&10&1&1&2&1&1\\\\\r\nSelected batches&1&1&1&1&1&1\\\\\r\nOptimal log-loss&0.60&0.11&0.10&0.21&0.17&0.52\\\\\r\nThreshold&0.71&0.21&0.15&0.26&0.19&0.53\\\\\r\nSelected log-loss&0.67&0.11&0.10&0.21&0.17&0.52\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&4&3&18&2&6\\\\\r\nPrototypes&25&25&69&410&409&421\\\\\r\nLog-loss&0.47&0.12&0.13&0.18&0.17&0.53\\\\\r\nROC-AUC&0.90&1.00&0.99&1.00&0.99&0.81\\\\\r\nBalanced acc.&0.73&0.97&0.96&0.97&0.95&0.71\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nThe fifth experiment shows what happens if we fix $\\lambda_w$ and perform cross-validation only with respect to $\\lambda_v$ and $B$.\r\nBased on the previous experiments, $\\lambda_w=10^{-8}$ appears to be a suitable choice.\r\nAs stage 1 now deals with a single parameter, we replace the random search with a grid search using 11 points equidistantly spaced on the log-scale.\r\nThe results in table \\ref{tab_e5} show that fixing the penalty on prototype weights has only a small impact on model quality.\r\nAll log-loss scores except that for the digits case are below the equivalence threshold for the best model found.\r\nTherefore, $\\lambda_w=10^{-8}$ is the recommended default for the proset classifier.\\par\r\n%\r\n\\clearpage\r\n%\r\n\\begin{table}\r\n\\caption{[E6] Stage 2 only ($\\lambda_v=10^{-3}$, $\\lambda_w=10^{-8}$, and $\\alpha_v=\\alpha_w=0.95$)}\r\n\\label{tab_e6}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\textbf{Candidates}&$\\sim50$&$\\sim60$&$\\sim200$&$\\sim630$&1,000&1,000\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&9&8&9&7&1&10\\\\\r\nSelected batches&4&2&1&4&1&3\\\\\r\nOptimal log-loss&0.54&0.10&0.10&0.15&0.19&0.50\\\\\r\nThreshold&0.72&0.17&0.15&0.17&0.20&0.52\\\\\r\nSelected log-loss&0.71&0.15&0.12&0.16&0.19&0.51\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&7&4&34&2&6\\\\\r\nPrototypes&82&72&149&1,270&252&1,261\\\\\r\nLog-loss&0.45&0.16&0.13&0.12&0.18&0.49\\\\\r\nROC-AUC&0.89&0.99&0.99&1.00&0.99&0.84\\\\\r\nBalanced acc.&0.76&0.95&0.95&0.98&0.95&0.75\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nThe sixth experiment considers fixing both $\\lambda_w$ and $\\lambda_v$ (see table \\ref{tab_e6}).\r\nThe former is again set to $\\lambda_w=10^{-8}$, the latter to $\\lambda_w=10^{-3}$, which is close to the parameters selected in previous experiments.\r\nThe mean scores for the digits and XOR 6f data are the best for any of the experiments.\r\nAll other results are equivalent to the best model.\r\nBased on this finding, we recommend $\\lambda_w=10^{-3}$ as default for the classifier.\\par\r\n%\r\n\\begin{table}\r\n\\caption{[E1--E6] Comparison of results (best log-loss bold)}\r\n\\label{tab_e1_to_e6}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E1] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.05$)}}\\\\\r\nActive features&2&6&3&19&2&6\\\\\r\nPrototypes&34&43&24&546&257&309\\\\\r\nLog-loss&0.62&0.14&0.13&0.15&0.17&0.55\\\\\r\nThreshold stage 2&0.54&0.16&0.14&0.22&0.20&0.56\\\\\r\nROC-AUC&0.86&0.99&0.99&1.00&0.99&0.81\\\\\r\nBalanced acc.&0.76&0.97&0.94&0.97&0.95&0.71\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E2] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.50$)}}\\\\\r\nActive features&2&7&3&18&2&6\\\\\r\nPrototypes&30&69&54&533&281&360\\\\\r\nLog-loss&0.49&0.20&0.13&0.18&\\textbf{0.16}&0.53\\\\\r\nThreshold stage 2&0.49&0.16&0.14&0.19&0.19&0.55\\\\\r\nROC-AUC&0.90&0.98&0.99&1.00&0.99&0.82\\\\\r\nBalanced acc.&0.73&0.93&0.95&0.97&0.95&0.72\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E3] Randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&7&4&30&2&6\\\\\r\nPrototypes&49&52&56&861&328&413\\\\\r\nLog-loss&\\textbf{0.43}&0.14&0.13&0.15&0.18&0.52\\\\\r\nThreshold stage 2&0.57&0.17&0.14&0.17&0.20&0.53\\\\\r\nROC-AUC&0.91&1.00&0.99&1.00&0.99&0.82\\\\\r\nBalanced acc.&0.71&0.98&0.98&0.97&0.95&0.72\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E4] Use optimal hyperparameters ($\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&11&3&41&2&6\\\\\r\nPrototypes&65&204&93&3,053&595&403\\\\\r\nLog-loss&0.48&\\textbf{0.05}&\\textbf{0.11}&0.13&\\textbf{0.16}&0.52\\\\\r\nThreshold stage 2&0.57&0.17&0.14&0.17&0.20&0.53\\\\\r\nROC-AUC&0.87&1.00&0.99&1.00&0.99&0.83\\\\\r\nBalanced acc.&0.69&0.98&0.95&0.97&0.94&0.74\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E5] Grid search for $\\lambda_v$ ($\\lambda_w=10^{-8}$ and $\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&4&3&18&2&6\\\\\r\nPrototypes&25&25&69&410&409&421\\\\\r\nLog-loss&0.47&0.12&0.13&0.18&0.17&0.53\\\\\r\nThreshold stage 2&0.71&0.21&0.15&0.26&0.19&0.53\\\\\r\nROC-AUC&0.90&1.00&0.99&1.00&0.99&0.81\\\\\r\nBalanced acc.&0.73&0.97&0.96&0.97&0.95&0.71\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E6] Stage 2 only  ($\\lambda_v=10^{-3}$, $\\lambda_w=10^{-8}$, and $\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&7&4&34&2&6\\\\\r\nPrototypes&82&72&149&1,270&2527&1,261\\\\\r\nLog-loss&0.45&0.16&0.13&\\textbf{0.12}&0.18&\\textbf{0.49}\\\\\r\nThreshold stage 2&0.72&0.17&0.15&0.17&0.20&0.52\\\\\r\nROC-AUC&0.89&0.99&0.99&1.00&0.99&0.84\\\\\r\nBalanced acc.&0.76&0.95&0.95&0.98&0.95&0.75\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\clearpage\r\n%\r\n\\begin{table}\r\n\\caption{[E7] Stage 2, vary candidates ($\\lambda_v=10^{-3}$, $\\lambda_w=10^{-8}$, and $\\alpha_v=\\alpha_w=0.95$)}\r\n\\label{tab_e7}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Checker}&\\textbf{Checker}&\\textbf{Checker}&\\textbf{XOR 6f}&\\textbf{XOR 6f}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&2&2&2&2&2&2\\\\\r\nFeatures&2&2&2&6&6&6\\\\\r\nSamples&6,400&6,400&6,400&6,400&6,400&6,400\\\\\r\nTrain samples&4,480&4,480&4,480&4,480&4,480&4,480\\\\\r\nTest samples&1,920&1,920&1,920&1,920&1,920&1,920\\\\\r\n\\textbf{Candidates}&100&300&1,500&100&300&1,500\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&3&1&1&10&9&10\\\\\r\nSelected batches&2&1&1&7&4&4\\\\\r\nOptimal log-loss&0.41&0.29&0.18&0.57&0.53&0.50\\\\\r\nThreshold&0.42&0.31&0.19&0.58&0.55&0.51\\\\\r\nSelected log-loss&0.41&0.29&0.18&0.57&0.54&0.51\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&2&2&6&6&6\\\\\r\nPrototypes&112&125&300&365&487&2,188\\\\\r\nLog-loss&0.43&0.28&0.17&0.57&0.54&0.48\\\\\r\nROC-AUC&0.90&0.97&0.99&0.78&0.80&0.85\\\\\r\nBalanced acc.&0.79&0.90&0.96&0.70&0.72&0.76\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nThe seventh experiment shows the impact of different batch sizes $M$ (see table \\ref{tab_e7}).\r\nIt deals only with the checkerboard and XOR data, as the maximum batch size for the first four cases is limited by their small sample size.\r\nFor each of the two large data sets, we try using 100, 300, and 1,500 samples instead of the default $M=1,000$.\r\nThe model metrics for 100 and 300 samples are worse than before, while the results for 1,500 candidates are comparable.\r\nClearly, there is an advantage to using large batches as long as the sample size permits.\r\n%\r\n\\section{Comparison with other classifiers}\r\n\\label{sec_classifier_comparison}\r\n%\r\nIn this section, we compare the proset classifier to the $k$-nearest neighbor (kNN) and XGBoost methods.\r\nThe former is conceptually similar to proset, as it scores new points based on their proximity to training samples.\r\nHowever, there are at least three major differences between proset and kNN:\r\n%\r\n\\begin{enumerate}\r\n\\item kNN uses all training samples for scoring and gives equal importance to each sample.\r\nProset selects prototypes and assigns individual weights.\r\n%\r\n\\item kNN relies on the user's choice of features and distance metric.\r\nIrrelevant features or a badly scaled metric can degrade performance.\r\nProset adapts the metric to the problem and removes features that contribute little or nothing.\r\n%\r\n\\item kNN has no notion of absolute distance.\r\nThe nearest neighbors have the same impact on classification no matter how far away they are from the sample being scored.\r\nIf that sample is far away from the training data, estimates become arbitrary.\r\nFor proset, remote prototypes have negligible impact on classification.\r\nAs the distance of a sample to the set of prototype increases, the estimated probabilities converge to the marginals of the training data.\r\n\\end{enumerate}\r\n%\r\nXGBoost is a particular implementation of gradient boosting for decision trees (we do not consider other base learners in this study) \\cite{Chen_16}.\r\nIt has become a kind of industry standard for supervised learning outside the domain of deep learning.\r\nIn terms of the three points stated above, XGBoost relates to proset and kNN as follows:\r\n%\r\n\\begin{enumerate}\r\n\\item XGBoost does not retain any training samples.\r\nIt generates a set of rules in the form of decision trees and performs classification via weighted voting.\r\n%\r\n\\item XGBoost relies only on the ordering of features, not on any kind of distance metric.\r\nWhen building trees, the algorithm selects features using a greedy heuristic.\r\nIt is considered good practice to limit the number of features evaluated at each stage by subsampling \\cite{Chen_16}.\r\nThis results in a more diverse set of trees with less tendency to overfit.\r\nEven with this approach, features that have negligible impact on performance are unlikely to be selected.\r\n%\r\n\\item Using XGBoost to score a sample that is far away from the training data gives arbitrary results.\r\nThe decision trees have not been validated in that part of the feature space.\r\n\\end{enumerate}\r\n%\r\nTo fit kNN and XGBoost models, we follow the same general strategy as for proset.\r\nWe determine optimal hyperparameters using cross-validation and then choose an equivalent set of parameters that is less likely to overfit via the `1 SE rule' (see algorithm \\ref{alg_hyperparameters}).\r\nThis is easy to implement for kNN, since the sole hyperparameter is the number of neighbors $k$.\r\nNote that we choose the equivalent solution with the \\textit{largest} $k$ to achieve a high degree of smoothing.\\par\r\n%\r\nFor XGBoost, tuning is more complex as the number of hyperparameters that can be used to control the model fit is quite large.\r\nBased on prior experience, we focus on the following five only, leaving all others at their recommended defaults:\r\n%\r\n\\begin{enumerate}\r\n\\item Learning rate $\\eta$.\r\nControls the impact of each additional tree on the estimator.\r\nChoosing a smaller $\\eta$ can increase model performance slightly but requires more boosting iterations.\r\n%\r\n\\item Number of boosting iterations.\r\nHas to be sufficiently large for the model to capture all of the structure in the data.\r\nIncreasing it further leads to saturation instead of overfitting, i.e., the model quality on test data fluctuates around a common level.\r\n%\r\n\\item Maximum tree depth.\r\nControls the complexity of each tree.\r\nOur experience is that XGBoost performs best if the individual trees underfit.\r\n%\r\n\\item Fraction of features evaluated per split.\r\nUsing a random subset of the features in each split results in a more diverse set of trees.\r\nThis can result in a more favorable trade-off between bias and variance.\r\n%\r\n\\item Fraction of records used for training each tree.\r\nUsing a random subset of the training samples to build each tree has a similar effect as randomizing the features.\r\n\\end{enumerate}\r\n%\r\nWe follow a similar strategy as for proset (see algorithm \\ref{alg_hyperparameters}) to fit XGBoost classifiers.\r\nIn the first stage, we fix $\\eta=0.1$ and use 100 boosting iterations to determine suitable values for maximum tree depth, fraction of features per split, and fraction of records per tree.\r\nHyperparameter values are sampled randomly to generated 100 trial combinations:\r\n%\r\n\\begin{itemize}\r\n\\item Maximum tree depth is sampled from 0 (constant model) to 9 with equal probability.\r\nIn case the maximum was selected or model performance looked inadequate, we increased the maximum parameter value.\r\n%\r\n\\item Fraction of features per split is sampled uniformly between 0.1 and 0.9.\r\nNote that for a model with two features, any value of 0.5 or above just means to test both, while values below 0.5 means to select one at random.\r\n%\r\n\\item Fraction of records per tree is sampled uniformly between 0.1 and 0.9.\r\n\\end{itemize}\r\n%\r\nAfter five-fold cross-validation, we determine the parameter combination that minimizes log-loss, compute a threshold, and choose an equivalent combination.\r\nAmong all candidates, we use the one that minimizes the depth of the tree first, then the fraction of features per split, and finally the fraction of records per tree.\\par\r\n%\r\nIn the second stage, we fix $\\eta=0.01$ and use five-fold cross-validation to determine the number of boosting iterations up to a maximum of 10,000.\r\nWe again apply the `1 SE rule' to find an equivalent smaller number of iterations.\r\nThe model is then re-fitted to all training data and scored on test data.\\par\r\n%\r\n\\begin{table}\r\n\\caption{[E8] $k$-nearest neighbor classifier with grid search for $k$}\r\n\\label{tab_e8}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Cross-validation}}\\\\\r\nOptimal $k$&12&4&29&8&10&14\\\\\r\nSelected $k$&29&13&51&43&11&20\\\\\r\nOptimal log-loss&0.47&0.10&0.15&0.16&0.23&0.54\\\\\r\nThreshold&0.54&0.15&0.17&0.27&0.24&0.56\\\\\r\nSelected log-loss&0.53&0.15&0.17&0.27&0.24&0.55\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nLog-loss&0.48&0.11&0.14&0.22&0.21&0.54\\\\\r\nROC-AUC&0.93&1.00&1.00&1.00&0.98&0.83\\\\\r\nBalanced acc.&0.82&0.97&0.95&0.93&0.92&0.73\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E9] XGBoost classifier with randomized parameter search}\r\n\\label{tab_e9}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Data}}\\\\\r\nClasses&3&3&2&10&2&2\\\\\r\nFeatures&2&13&30&64&2&6\\\\\r\nSamples&150&178&569&1,797&6,400&6,400\\\\\r\nTrain samples&105&124&398&1,257&4,480&4,480\\\\\r\nTest samples&45&54&171&540&1,920&1,920\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal max.\\ depth&2&3&4&4&18&1\\\\\r\nSelected max.\\ depth&1&1&1&3&15&1\\\\\r\nOptimal colsample&0.43&0.48&0.38&0.27&0.79&0.81\\\\\r\nSelected colsample&0.11&0.27&0.11&0.24&0.39&0.81\\\\\r\nOptimal subsample&0.58&0.67&0.45&0.77&0.77&0.25\\\\\r\nSelected subsample&0.46&0.86&0.46&0.72&0.68&0.25\\\\\r\nOptimal log-loss&0.50&0.07&0.10&0.13&0.10&0.70\\\\\r\nThreshold&0.62&0.11&0.14&0.15&0.11&0.70\\\\\r\nSelected log-loss&0.52&0.09&0.12&0.15&0.11&0.70\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal iterations&1,586&2,344&5,579&6,187&9,973&16\\\\\r\nSelected iterations&337&887&668&1,168&1,519&1\\\\\r\nOptimal log-loss&0.50&0.08&0.10&0.11&0.07&0.69\\\\\r\nThreshold&0.62&0.11&0.14&0.14&0.09&0.69\\\\\r\nSelected log-loss&0.62&0.11&0.14&0.14&0.09&0.69\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&13&29&53&2&1\\\\\r\nLog-loss&0.63&0.11&0.12&0.11&0.06&0.69\\\\\r\nROC-AUC&0.89&1.00&0.99&1.00&1.00&0.50\\\\\r\nBalanced acc.&0.69&0.97&0.96&0.98&0.98&0.50\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E3, E8, E9] Comparison of results (best log-loss bold)}\r\n\\label{tab_e3_e8_e9}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrrr|}\r\n\\hline\r\n&\\multicolumn{6}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Iris 2f}&\\textbf{Wine}&\\textbf{Cancer}&\\textbf{Digits}&\\textbf{Checker}&\\textbf{XOR 6f}\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E3] Proset with randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&7&4&30&2&6\\\\\r\nLog-loss&\\textbf{0.43}&0.14&0.13&0.15&0.18&\\textbf{0.52}\\\\\r\nThreshold stage 2&0.57&0.17&0.14&0.17&0.20&0.53\\\\\r\nROC-AUC&0.91&1.00&0.99&1.00&0.99&0.82\\\\\r\nBalanced acc.&0.71&0.98&0.98&0.97&0.95&0.72\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E8] $k$-nearest neighbor classifier with grid search for $k$}}\\\\\r\nActive features&2&13&30&64&2&6\\\\\r\nLog-loss&0.48&\\textbf{0.11}&0.14&0.22&0.21&0.54\\\\\r\nThreshold CV&0.54&0.15&0.17&0.27&0.24&0.56\\\\\r\nROC-AUC&0.93&1.00&1.00&1.00&0.98&0.83\\\\\r\nBalanced acc.&0.82&0.97&0.95&0.93&0.92&0.73\\\\\r\n\\multicolumn{7}{|l|}{\\textbf{[E9] XGBoost classifier with randomized parameter search}}\\\\\r\nActive features&2&13&29&53&2&1\\\\\r\nLog-loss&0.63&\\textbf{0.11}&\\textbf{0.12}&\\textbf{0.11}&\\textbf{0.06}&0.69\\\\\r\nThreshold stage 2&0.62&0.11&0.14&0.14&0.09&0.69\\\\\r\nROC-AUC&0.89&1.00&0.99&1.00&1.00&0.50\\\\\r\nBalanced acc.&0.69&0.97&0.96&0.98&0.98&0.50\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\nResults for fitting kNN and XGBoost classifiers to the six examples used for the proset parameter study are given in tables \\ref{tab_e8} and \\ref{tab_e9}.\r\nThe structure of the tables and reported metrics are essentially the same as for proset in the previous section.\r\nFor XGBoost, the number of active features reported is the number of features with positive importance score using the method's built-in scoring.\\par\r\n%\r\nTable \\ref{tab_e3_e8_e9} summarizes the performance of all three models.\r\nFor proset, reference values are taken from the full parameters search using $\\alpha_v=\\alpha_w=0.95$ (see table \\ref{tab_e3}).\\par\r\n%\r\n\\begin{enumerate}\r\n\\item\\textbf{Iris 2f:} proset is best with kNN equivalent and XGBoost worse.\r\nHowever, the number of test samples is so small that these results are unreliable.\r\nChanging the random seed for the train-test split can have a large impact on the outcome.\\par\r\n%\r\nFigure \\ref{fig_comparison_decision_iris_2f} shows the decision surfaces resulting from the three algorithms.\r\nThe different modeling strategies are apparent from the plots: the surface for proset is composed of many localized kernels, the one for kNN resembles a Voronoi tesselation, and for XGBoost, it is possible to see the splits made by the decision trees perpendicular to the coordinate axes.\r\n%\r\n\\item\\textbf{Wine:} XGBoost and kNN achieve the same log-loss.\r\nThe score for for proset is above the threshold for XGBoost but not for kNN.\r\nIn this case, we consider the lower threshold for the overall ranking in Table \\ref{tab_classifier_comparison}.\r\nProset does use only 7 of 13 features, while XGBoost uses the full set (kNN can perform no selection).\r\n%\r\n\\item\\textbf{Cancer:} XGBoost is best but both other models are considered `equivalent'.\r\nProset reduces the number of features considerably from 30 to 4, while XGBoost uses 29.\r\n%\r\n\\item\\textbf{Digits}: there is a strict ranking with XGBoost being best and proset better than kNN.\r\nHowever, proset is close to XGBoost in terms of balanced accuracy while kNN is markedly worse.\r\nProset reduces the number of features from 64 to 30, XGBoost uses 54.\r\n%\r\n\\item\\textbf{Checker:} there is a strict ranking with XGBoost being best and proset better than kNN.\r\nXGBoost is considerably better than both other models on this data set.\r\nNote that the maximum tree depth for XGBoost was increased to 19 as the fit with a limit of 9 selected the upper bound.\r\n%\r\n\\item\\textbf{XOR 6f:} proset is best, kNN worse, while XGBoost fails to find any patterns in the data and returns a constant estimator.\r\nIncreasing the maximum tree depth for XGBoost to 99 does nothing to improve model quality.\r\n\\end{enumerate}\r\n%\r\n\\begin{figure}\r\n\\caption{Comparison of decision surfaces for case Iris 2f}\r\n\\label{fig_comparison_decision_iris_2f}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{[E3] proset}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_dominant_l2_surf_test.pdf}}\r\n\\subfloat[\\textbf{[E8] kNN}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_knn_surf_test.pdf}}\\\\\r\n\\subfloat[\\textbf{[E9] XGBoost}]{\\includegraphics[width=0.49\\textwidth]{figures/iris_2f_xgb_surf_test.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nWe draw the following conclusions from this study:\r\n%\r\n\\begin{itemize}\r\n\\item In terms of achieving a low log-loss, proset appears to rank in-between XGBoost and kNN.\r\n%\r\n\\item Proset achieves a greater reduction in the number of features than XGBoost with a preference for small decision trees.\r\nWhile the fit strategy for XGBoost may not always select the smallest possible feature set due to feature subsampling, the difference is marked.\r\n%\r\n\\item The extremely good performance of XGBoost on the checker data is possibly due to the fact that the approximating function is of the same class as the target.\r\nBoth are step functions with edges parallel to the main coordinate axes.\r\n%\r\n\\item XOR 6f appears to defeat tree ensembles, which choose features one at a time based on a greedy criterion.\r\nNo matter how the first split is made, the expected number of cases per class in each resulting subspace is 50 \\%, same as for the whole space.\r\nThus, the first split is always made in response to random fluctuations in the data.\r\nThis is also true for the checkerboard with an even number of squares per side, but the first split is almost sure to break the symmetry for this case.\r\nIn contrast, for XOR 6f, at least five splits are required to expose the underlying structure.\r\nThe partitions created by five random splits apparently do not contain sufficient information to build a meaningful decision tree.\r\n\\end{itemize}\r\n%\r\nBased on these observations, we define five additional test cases to further explore the differences between the three algorithms:\r\n%\r\n\\begin{enumerate}\r\n\\item\\textbf{Checker rot:} to determine how much of the good performance of XGBoost on the checker data is due to the axis-parallel steps, we rotate the checkerboard pattern by 45\\textdegree.\r\n%\r\n\\item\\textbf{XOR 3f, XOR 4f, XOR 5f:} in order to find the point at which XGBoost fails on the `continuous XOR' class of problems, we generate instances with three, four, and five features.\r\nAs for XOR 6f, these each have an average of 100 samples per orthant.\r\n%\r\n\\item\\textbf{XOR 6+6f:} to understand how easy it is to confuse the kNN classifier with irrelevant data, we add six more features to the XOR 6f problem.\r\nThese are drawn from the same distribution as the first six but have no impact on the target.\r\n\\end{enumerate}\r\n%\r\n\\begin{table}\r\n\\caption{[E10] New examples -- results for proset classifier}\r\n\\label{tab_e10}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrr|}\r\n\\hline\r\n&\\multicolumn{5}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Checker rot}&\\textbf{XOR 3f}&\\textbf{XOR 4f}&\\textbf{XOR 5f}&\\textbf{XOR 6+6f}\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Data}}\\\\\r\nClasses&2&2&2&2&2\\\\\r\nFeatures&2&3&4&5&12\\\\\r\nSamples&6,400&800&1,600&3,200&6,400\\\\\r\nTrain samples&4,480&560&1,120&2,240&4,480\\\\\r\nTest samples&1,920&240&480&960&1,920\\\\\r\n\\textbf{Candidates}&1,000&$\\sim280$&$\\sim560$&$1000$&1,000\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal $\\lambda_v$&$3.1\\times10^{-5}$&$4.5\\times10^{-2}$&$1.8\\times10^{-3}$&$5.5\\times10^{-3}$&$2.2\\times10^{-4}$\\\\\r\nSelected $\\lambda_v$&$2.9\\times10^{-4}$&$4.2\\times10^{-3}$&$1.0\\times10^{-2}$&$5.5\\times10^{-3}$&$1.9\\times10^{-3}$\\\\\r\nOptimal $\\lambda_w$&$4.3\\times10^{-9}$&$1.3\\times10^{-8}$&$7.7\\times10^{-8}$&$8.3\\times10^{-8}$&$5.7\\times10^{-8}$\\\\\r\nSelected $\\lambda_w$&$6.9\\times10^{-8}$&$1.5\\times10^{-6}$&$4.6\\times10^{-7}$&$8.3\\times10^{-8}$&$2.7\\times10^{-6}$\\\\\r\nOptimal log-loss&0.18&0.19&0.30&0.40&0.55\\\\\r\nThreshold&0.19&0.21&0.34&0.42&0.56\\\\\r\nSelected log-loss&0.19&0.20&0.32&0.40&0.56\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal batches&1&6&6&5&1\\\\\r\nSelected batches&1&1&1&2&1\\\\\r\nOptimal log-loss&0.19&0.19&0.32&0.39&0.57\\\\\r\nThreshold&0.20&0.23&0.33&0.40&0.57\\\\\r\nSelected log-loss&0.19&0.23&0.33&0.39&0.57\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&3&4&5&6\\\\\r\nPrototypes&320&89&124&572&425\\\\\r\nLog-loss&0.18&0.17&0.28&0.39&0.56\\\\\r\nROC-AUC&0.99&0.99&0.97&0.91&0.80\\\\\r\nBalanced acc.&0.95&0.96&0.91&0.83&0.72\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E11]  New examples -- results for $k$-nearest neighbor classifier}\r\n\\label{tab_e11}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrr|}\r\n\\hline\r\n&\\multicolumn{5}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Checker rot}&\\textbf{XOR 3f}&\\textbf{XOR 4f}&\\textbf{XOR 5f}&\\textbf{XOR 6+6f}\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Data}}\\\\\r\nClasses&2&2&2&2&2\\\\\r\nFeatures&2&3&4&5&12\\\\\r\nSamples&6,400&800&1,600&3,200&6,400\\\\\r\nTrain samples&4,480&560&1,120&2,240&4,480\\\\\r\nTest samples&1,920&240&480&960&1,920\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Cross-validation}}\\\\\r\nOptimal $k$&10&7&8&9&100\\\\\r\nSelected $k$&11&16&9&13&100\\\\\r\nOptimal log-loss&0.23&0.22&0.34&0.43&0.70\\\\\r\nThreshold&0.24&0.27&0.35&0.44&0.71\\\\\r\nSelected log-loss&0.24&0.27&0.34&0.44&0.70\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nLog-loss&0.21&0.25&0.31&0.45&0.71\\\\\r\nROC-AUC&0.98&0.98&0.95&0.88&0.46\\\\\r\nBalanced acc.&0.92&0.91&0.86&0.80&0.48\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E12]  New examples -- results for XGBoost classifier}\r\n\\label{tab_e12}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrr|}\r\n\\hline\r\n&\\multicolumn{5}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Checker rot}&\\textbf{XOR 3f}&\\textbf{XOR 4f}&\\textbf{XOR 5f}&\\textbf{XOR 6+6f}\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Data}}\\\\\r\nClasses&2&2&2&2&2\\\\\r\nFeatures&2&3&4&5&12\\\\\r\nSamples&6,400&800&1,600&3,200&6,400\\\\\r\nTrain samples&4,480&560&1,120&2,240&4,480\\\\\r\nTest samples&1,920&240&480&960&1,920\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Stage 1}}\\\\\r\nOptimal max.\\ depth&21&7&18&17&1\\\\\r\nSelected max.\\ depth&12&6&11&12&1\\\\\r\nOptimal colsample&0.77&0.81&0.79&0.72&0.81\\\\\r\nSelected colsample&0.26&0.88&0.88&0.81&0.81\\\\\r\nOptimal subsample&0.43&0.84&0.77&0.69&0.25\\\\\r\nSelected subsample&0.54&0.81&0.88&0.49&0.25\\\\\r\nOptimal log-loss&0.18&0.10&0.30&0.64&0.70\\\\\r\nThreshold&0.19&0.11&0.32&0.67&0.70\\\\\r\nSelected log-loss&0.19&0.11&0.31&0.66&0.70\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Stage 2}}\\\\\r\nOptimal iterations&8,455&2,677&2,926&895&2\\\\\r\nSelected iterations&3,364&690&1,154&96&1\\\\\r\nOptimal log-loss&0.13&0.10&0.28&0.65&0.69\\\\\r\nThreshold&0.14&0.15&0.31&0.68&0.69\\\\\r\nSelected log-loss&0.14&0.15&0.31&0.68&0.69\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{Final model, scores for test data}}\\\\\r\nActive features&2&3&4&5&1\\\\\r\nLog-loss&0.12&0.11&0.23&0.67&0.69\\\\\r\nROC-AUC&0.99&1.00&0.98&0.65&0.50\\\\\r\nBalanced acc.&0.95&0.97&0.94&0.60&0.50\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\begin{table}\r\n\\caption{[E10, E11, E12] Comparison of results (best log-loss bold)}\r\n\\label{tab_e10_e11_e12}\r\n%\r\n\\begin{center}\r\n\\small\r\n\\begin{tabular}{|lrrrrr|}\r\n\\hline\r\n&\\multicolumn{5}{c|}{\\textbf{\\hrulefill\\ Data set \\hrulefill}}\\\\\r\n&\\textbf{Checker rot}&\\textbf{XOR 3f}&\\textbf{XOR 4f}&\\textbf{XOR 5f}&\\textbf{XOR 6+6f}\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{[E10] Proset with randomized search for $\\lambda_v$ and $\\lambda_w$ ($\\alpha_v=\\alpha_w=0.95$)}}\\\\\r\nActive features&2&3&4&5&6\\\\\r\nLog-loss&0.18&0.17&0.28&\\textbf{0.39}&\\textbf{0.56}\\\\\r\nThreshold stage 2&0.20&0.23&0.33&0.40&0.57\\\\\r\nROC-AUC&0.99&0.99&0.97&0.91&0.80\\\\\r\nBalanced acc.&0.95&0.96&0.91&0.83&0.72\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{[E11] $k$-nearest neighbor classifier with grid search for $k$}}\\\\\r\nActive features&2&3&4&5&12\\\\\r\nLog-loss&0.21&0.25&0.31&0.45&0.71\\\\\r\nThreshold CV&0.24&0.27&0.35&0.44&0.71\\\\\r\nROC-AUC&0.98&0.98&0.95&0.88&0.46\\\\\r\nBalanced acc.&0.92&0.91&0.86&0.80&0.48\\\\\r\n\\multicolumn{6}{|l|}{\\textbf{[E12] XGBoost classifier with randomized parameter search}}\\\\\r\nActive features&2&3&4&5&1\\\\\r\nLog-loss&\\textbf{0.12}&\\textbf{0.11}&\\textbf{0.23}&0.67&0.69\\\\\r\nThreshold stage 2&0.14&0.15&0.31&0.68&0.69\\\\\r\nROC-AUC&0.99&1.00&0.98&0.65&0.50\\\\\r\nBalanced acc.&0.95&0.97&0.94&0.60&0.50\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n%\r\n\\clearpage\r\n%\r\nResults for proset, kNN, and XGBoost are summarized in tables \\ref{tab_e10}, \\ref{tab_e11}, and \\ref{tab_e12}.\r\nA comparison of the three algorithms is shown in table \\ref{tab_e10_e11_e12}:\r\n%\r\n\\begin{enumerate}\r\n\\item\\textbf{Checker rot:} XGBoost still yields the best model on this pattern, but the log-loss is higher than for the original checkerboard.\r\nThe largest value for maximum tree depth used in cross-validation was set to 29 as smaller bounds meant the bound was selected.\r\nThe metrics for the other two models are very similar to the original case.\r\n%\r\n\\item\\textbf{XOR 3f, XOR 4f, XOR 5f:} with three features, XGBoost performs better than other models, with four it is still best but the others are equivalent, and with five features, proset is better than the other two models, i.e., they are not affected by the orientation of the pattern.\r\n%\r\n\\item\\textbf{XOR 6+6f:} proset correctly selects the six relevant features and produces a model that is slightly worse than for the original XOR 6f.\r\nNeither kNN nor XGBoost are able to find any structure and return constant estimators.\r\n\\end{enumerate}\r\n%\r\nOverall, we believe that these results show that proset is a worthwhile addition to the supervised learning toolbox.\r\nAs intended, it performs feature selection as an integral part of model fitting and is able to identify a nonlinear relationship between the features and target.\r\n%\r\n\\endinput\r\n", "meta": {"hexsha": "fbe9fcc44a99e0b7db922fe06d53deb11ee2d063", "size": 74160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/classifier.tex", "max_stars_repo_name": "NRuf77/proset", "max_stars_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_stars_repo_licenses": ["MIT"], "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/classifier.tex", "max_issues_repo_name": "NRuf77/proset", "max_issues_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_issues_repo_licenses": ["MIT"], "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/classifier.tex", "max_forks_repo_name": "NRuf77/proset", "max_forks_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_forks_repo_licenses": ["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.9740548554, "max_line_length": 310, "alphanum_fraction": 0.718864617, "num_tokens": 24965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6272040191900581}}
{"text": "\\lab{Applications}{Data Visualization}{Data Visualization} \n\\objective{Use data visualizations to explore data and communicate it to others.}\n\\label{lab:DataVis}\n\n\\section*{What is data visualization?} \nData visualizations (or graphs) are used to understand and explore data as well as communicate results to others. \nJust as a picture is worth a thousand words, a graph is much easier than a thousand data points for the human mind to interpret. \nThough anyone working with data benefits from graphing it, data visualization is also an independent field that studies the interplay between mathematics, statistics, and the visual arts.\n\n\\section*{Types of visualizations}\nThere are many standard ways to visualize data, and some consistently reveal and communicate the most information about certain kinds of data sets. \nHere are some standard plots and some examples of data they are commonly used to visualize.\n\n\\begin{enumerate}\n\\item A \\emph{scatter plot} graphs $(x,y)$ tuples as points. \nA scatter plot can reveal correlation (or lack thereof) between $x$ and $y$. \nUse a scatter plot when your data is not ordered. \nYou can create a scatter plot in matplotlib with the command \\li{plt.scatter()}.\n\n\\item A \\emph{line plot} graphs $(x,y)$ tuples as points and then connects them with a line. \nYou should use a line plot when there is a natural order to your tuples. \nFor example, use a line plot to look for trends over time. \nRecall that you can create a line plot in matplotlib with the command \\li{plt.plot()}.\n\n\\item A \\emph{histogram} (or bar graph) depicts $(x,y)$ tuples as rectangles whose length is determined by $y$ (see Figure \\ref{fig:healthcare}). \nLike line plots, histograms can be used to look for trends over time. \nAnother use of a histograms is to investigate statistical distributions. \nYou can create a histogram in matplotlib with the command \\li{plt.hist()}. \n%TODO: Add a problem that requires them to build a histogram\n\n\\item A \\emph{pie chart} depicts parts of a whole as slices of a circle. \nOften, a pie chart is best replaced with a histogram. \nThis is because it is difficult for us to see how similar slices of a pie chart differ in size. \nBy contrast, we can easily detect even small differences in the lengths of rectangles in a bar chart. \nHowever, pie charts are ideal for some purposes, especially when the exact numbers from the data are not important. \nSee \\cite{piecharts} for some situations where data is best represented by a pie chart. \nYou can create a pie chart in matplotlib with the command \\li{plt.pie()}.\n\n\\item A \\emph{sparkline} is a word-sized graphic that is often embedded inline with the text. \nCreated by Edward Tufte, an innovator and recognized leader in the field of data visualizations, sparklines can be used to quickly communicate large-scale trends in a data set. They are also ideal for binary data sets. \nTwo sources for creating sparkplots in Python are \\cite{sparkplots} and \\cite{sparklineshtml}.\n%TODO: Add an example of a sparkline\n\n\\item A \\emph{pseudocolor plot} or heat map uses color to display a third dimension on a two-dimensional page (see Figure \\ref{fig:heatmap}). \nOne common use is to illustrate the temperature of an object. \nYou can create a pseudocolor plot in matplotlib with the \\li{plt.pcolormesh()} command.\n\n\\item \\emph{Small multiples} are several minature graphics of the same type in a single visualization. \nLike sparklines, they were pioneered by Edward Tufte. Any of the plots discussed so far may be assembled into a small multiple. \nSmall multiples are useful for viewing trends over time, when the data associated to each time is more complex than a single number. \nMore generally, they can be used to compare many sets of similar data (\\cite{tufte1990} p. 67). \nFigure \\ref{fig:log_plots} could be called a small multiple, though frequently they contain more subplots. \nRecall that this kind of plot can be created in matplotlib with the command \\li{plt.subplot()}.\n\\end{enumerate}\n\n\n\n\\section*{Exploring data with visualizations}\nWhen you visualize data you may notice trends that are not apparent from the numbers. \nThe following problem is an example of this.\n\n\\begin{problem}\\label{prob:anscombe}\nThe data sets I-IV in Table \\ref{table:anscombe} are known as Anscombe's quartet. \nEach dat set has identical statistical properties. \nIn each case,\n\\begin{itemize}\n\\item The mean of $x$ is 9 and the mean of $y$ is $7.5$.\n\\item The variance of $x$ is 11 and the variance of $y$ is 4.127.\n\\item The correlation between $x$ and $y$ is .816.\n\\item The linear regression line is $y=3+5x$.\n\\end{itemize}\nPlot each data set. What do you notice?\n\n\\begin{table}[H]\n\\begin{tabular}{l l  |  l l  |  l l  |  l l }\nI & & II & & III & & IV\\\\\nx & y & x & y & x & y & x & y \\\\\n\\hline\n10.0 & 8.04 & 10.0 & 9.14 & 10.0 & 7.46 & 8.0 & 6.58 \\\\\n8.0 & 6.95 & 8.0 & 8.14 & 8.0 & 6.77 & 8.0 & 5.76 \\\\\n13.0 & 7.58 & 13.0 & 8.74 & 13.0 & 12.74 & 8.0 & 7.71 \\\\\n9.0 & 8.81 & 9.0 & 8.77 & 9.0 & 7.11 & 8.0 & 8.84 \\\\\n11.0 & 8.33 & 11.0 & 9.26 & 11.0 & 7.81 & 8.0 & 8.47 \\\\\n14.0 & 9.96 & 14.0 & 8.10 & 14.0 & 8.84 & 8.0 & 7.04 \\\\\n6.0 & 7.24 & 6.0 & 6.13 & 6.0 & 6.08 & 8.0 & 5.25 \\\\\n4.0 & 4.26 & 4.0 & 3.10 & 4.0 & 5.39 & 19.0 & 12.50 \\\\\n12.0 & 10.84 & 12.0 & 9.13 & 12.0 & 8.15 & 8.0 & 5.56 \\\\\n7.0 & 4.82 & 7.0 & 7.26 & 7.0 & 6.42 & 8.0 & 7.91 \\\\\n5.0 & 5.68 & 5.0 & 4.74 & 5.0 & 5.73 & 8.0 & 6.89 \\\\\n\\end{tabular}\n\\caption{These four sets of data are known as Anscombe's quartet.}\n\\label{table:anscombe}\n\\end{table}\n\\end{problem}\n\nAs Problem \\ref{prob:anscombe} demonstrates, a picture can reveal a data set in ways numbers can't. \nLearning from a visualization of a data set is often a recursive process. \nYou must visualize the data, make observations, and then zoom, filter, or otherwise modify your visualization to further explore the data.\n\nOne issue to consider is the range. \nBy choosing to plot only a portion of your data, you may be able to focus your attention on the most relevant data. \nOn the other hand, you may also miss some interesting behavior in the data you didn't graph.\n\nAnother issue to consider is scale. \nFor example, suppose the number of dogs kept as pets in a certain city increases from 50,000 to 55,000 over 4 years. \nThis increase can appear small or large, depending on where we start the y-axis and how long we stretch out the x-axis (see Figure \\ref{fig:dog_plots}).\n\nThere are many software packages that facilitate the visual exploration of data. \nOne Python library is Glue (see \\cite{glue}).\n\n\n\\subsection*{Log plots}\n\nOne good way to analyze data is to plot it on a different scale. \nLog plots in particular can reveal important structure in a data set. \nYou can create a log-log plot by taking the logarithm of both the $x$- and $y$-values. \nAnalogously, you can create a log-lin plot (also called a log plot) by taking the logarithm of only the $y$-values of your data set, or a lin-log plot by taking the logarithm of only the $x$-values.\n\nAs an example, let us look at the cost of health care claims. \nOur data set is bogus but created to closely resemble real-life data. \nAn initial plotting of the data produces the histogram on the left in Figure \\ref{fig:healthcare}. \nFrom this picture, it is hard to see the nature of the data---the plot just looks like a single bar. \nWe may think that all health care claims are cheap. \nHowever, when we take the logarithm of the claims prices, we get the histogram on the right in Figure \\ref{fig:healthcare}. \nGraphed on this scale, the data has a bell-shaped distribution similar to a normal distribution. \nMoreover, we see that there are some very expensive claims being submitted, though they are few. \n\\begin{figure}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{healthcare_linscale.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{healthcare_logscale.pdf}\n\\end{subfigure}\n\\caption{The same data (meant to resemble the prices of health care claims) is plotted in both histograms above. \nThe plot at left is a lin-lin scale, whereas the plot at right is a log-lin scale. \nIn this case, changing scales revealed important information about the data.}\n\\label{fig:healthcare}\n\\end{figure}\n\nAs a general rule, log-lin plots are useful when the range of the $y$-values is orders of magnitude larger than the range of the $x$-values. \nOur health care data was an example of this. \nSimilarly, lin-log plots are useful when the range of the $x$-values is much bigger than the range of the $y$-values. \nIn any case, you can try applying a log scale to one or both of your axes as a way to explore your data.\n\nLet us analyze the mathematics behind log plots. \nSuppose we have some data that roughly follows the line $y=cx^a$ where $c$ and $a$ are constants. \nTaking the logarithm of both sides yields\n\\[\n\\log(y) = a\\log(x) + \\log(c).\n\\]\nIf we set new variables $X = \\log(x)$ and $Y = \\log(y)$, then this equation becomes $Y = aX + \\log(c)$, which is the equation of a straight line. \nSo  on a log-log plot, polynomial-shaped data looks linear. \nSimilarly, taking the log of $y = a^x$ yields\n\\[\n\\log(y) = \\log(a)x,\n\\]\nso exponential data looks linear on a log-lin plot. \nFinally, data of the form $y = a\\log(x)+b$ will look linear on a lin-log plot. \nSee Figure \\ref{fig:log_plots}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{log_plots.pdf}\n\\caption{Here are some functions plotted on various logarithmic and linear scales. \nThe dark blue line is $y=x$, the green line is $y=\\log(x)$, the red line is $y=e^x$, and the light blue line is $y=x^3$. \nWe have used different ranges on the $y$-axes to highlight appropriate parts of the graphs.}\n\\label{fig:log_plots}\n\\end{figure}\n\nBe warned that many different functions can look linear on log plots. \nThus, if you graph your data on a log-log plot and you see a line, you CANNOT conclude that your data must follow a polynomial. \nIn general, you need more information.\n\nIn matplotlib, you can create plots on a logarithmic scale directly by using the \\li{plt.loglog()}, \\li{plt.semilogy()}, and \\li{plt.semilogx()} commands. \nTheir syntax is identical to that of\\li{plt.plot()}. \nAlternatively, you can modify the scale of an existing plot using \\li{plt.yscale()} or \\li{plt.xscale()}.\n\n\n\\begin{problem}\nGraph your data from Problem 1 in Lab \\ref{lab:complexity} (Matrices and Complexity) on a (a) log-log scale, (b) log-lin scale, and (c) lin-log scale. \nIn your opinion, which plot makes the data easiest to understand?\n\\end{problem}\n\n\n\n\n\\section*{Communicating data with visualizations}\n\nAs the saying has it, ``a picture is worth a thousand words.'' \nCertainly, a data visualization is far more valuable than a thousand data points to a colleague who wants to understand the results of your analysis. \nData visualizations are critical for communication in both business and research.\n\n\\subsection*{Choosing the right visualization}\nAt this point, you have already used visualization to explore your data and draw conclusions, and you are ready to tell your results to someone else. \nThe first step in creating a graphic to do this is to choose the right type of visualization. \nAs we saw in the section ``Types of Visualizations,'' there are many possibilities, each with different strengths. \nYou should carefully consider which one best suits your data set and communication needs.\n\n\\subsection*{Simplify}\nOnce you have chosen the visualization best suited to your data, you should design the details so that all elements contribute to the communication of data. \nEdward Tufte offers two principles for simplifying graphics: (1) erase ink that does not communicate data, and (2) erase ink that communicates data redundantly. \nBoth of these principles should be applied within reason (\\cite{tufte2001} pp.96-100). \n\nAccording to these principles, decorative backgrounds, fancy lettering, and cute graphics in the corner of you plots should all be deleted.\n\nOther opportunities for simplification are harder to notice and implement. As an example, let us examine the plot on the right of Figure \\ref{fig:healthcare}. \nThis plot was created with the following code.\n\n\\begin{lstlisting}\nimport numpy as np\nimport scipy as sp\nfrom matplotlib import pyplot as plt\n\nm = 2.07\ns = 0.63\nnum_samples = 10000\nsamples = []\n\nfor i in xrange(num_samples):\n    samples.append(sp.random.lognormal(m, s)) \n\nsp_samples = sp.array(samples)\n\n# Plot the histogram\nplt.hist(sp_samples, 100)\n\\end{lstlisting}\n\nFor purposes of this example, the only important part of the above code is the line \\li{plt.hist(sp_samples, 100)} that plots the histogram. \nWhat ink in this plot can we erase because it communicates no data?\n\nFirst, let's get rid of the vertical black lines that separate the bars of the histograph. \nThese are meaningless for our application. \nWe can do this by modifying our call to \\li{plt.hist()} as follows.\n\n\\begin{lstlisting}\nplt.hist(sp_samples, 100, histtype=\"stepfilled\")\n\\end{lstlisting}\n\nNext, let us turn off the top and right lines that box in the graph. \nTo do this, we need to access the ``axis'' object associated with the figure. \nWe can access the ``axis'' object with the command \\li{plt.gca()} (get current axis).\n\n\\begin{lstlisting}\n# Get current axis instance\naxis = plt.gca()\n\n# Hide top and right spines\naxis.spines['right'].set_visible(False)\naxis.spines['top'].set_visible(False)\n\\end{lstlisting}\n\nThese commands only turn off the sides of the box, not the tick marks. \nTo turn off the tick marks we run the following commands. \n\n\\begin{lstlisting}\n# Only show bottom and left tick marks\naxis.yaxis.set_ticks_position('left')\naxis.xaxis.set_ticks_position('bottom')\n\\end{lstlisting}\n\nFinally, we do not need so many tick marks on the $x$- and $y$-axes. \nWe adjust those along with specifying the range on each axis.\n\n\\begin{lstlisting}\n# Fix x and y ranges\nplt.xlim(0,70)\nplt.ylim(0, 800)\n\n# Use fewer axis ticks\nplt.xticks(np.arange(0, 71, 35))\nplt.yticks(np.arange(0, 801, 200))\n\\end{lstlisting}\n\nThe final graph is shown in Figure \\ref{fig:simplify}. \nNote how much cleaner this looks than the original.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{simplify.pdf}\n\\caption{A simplified version of the histogram in Figure \\ref{fig:healthcare}.}\n\\label{fig:simplify}\n\\end{figure}\n\n\n\\subsection*{Color}\n%TODO: explain how you can make a colorbar, either in this lab or the matplotlib lab\nColor should be added to your graphic thoughtfully. \nThe default settings in matplotlib should generally not be used. \nSeveral bright colors in a single plot often jar the viewer, so you should limit the number and intensity of colors and use them only to emphasize parts of your data. \nIf a grayscale plot contains just as much information as a colored plot, consider using grayscale.\n\nThe default color settings for pseudocolor plots in matplotlib are particularly problematic. \nThe default color gradient is a rainbow, which usually has no relation to the data. \nMost viewers have trouble remembering which colors are ``high\" and which are ``low\". \nInstead, you should set the gradient to cover one or two colors, and when possible these colors should be related to the data you are communicating. \nYou can change the color gradient used by \\li{plt.pcolormesh()} with the keyword argument \\li{cmap} (short for ``colormap''). \nA list of predefined colormaps is available at \\url{http://matplotlib.org/examples/color/colormaps_reference.html}, but you can also define your own. \nSee Figure \\ref{fig:heatmap} for an example of a good and bad pseudocolor plot.\n\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{heatmap_color.png}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=\\textwidth]{heatmap_gray.png}\n\\end{subfigure}\n%\\includegraphics[width=\\textwidth]{heatmap.png}\n\\caption{Both of these pseudocolor plots depict the function $z = sin(x)sin(y)$ on the domain $[-1,4] \\times [-4,1]$. \nThe plot at left uses a rainbow gradient which has no relationship to the data. \nThe plot at right uses a greyscale, which has two benefits: the colors are not irritating, and ``black'' is associated with ``low.''}\n\\label{fig:heatmap}\n\\end{figure}\n\n%TODO: Rewrite this problem to use a specific image with a specific context\n\\begin{problem}\nChoose a graph you previously created that you think could use simplification. \nApply at least 3 of the following to simplify your plot:\n\\begin{enumerate}\n\\item Turn off some of the spines.\n\\item Fix the x or y range to better fit your data.\n\\item Change the number of x or y ticks.\n\\item Choose a better color scheme.\n\\end{enumerate}\nSimplify your image in any other ways you can think of.\n\\end{problem}\n\n\\subsection*{Tell the truth}\n\nJust as graphics can tell your reader about your data, they can also give your viewer false impressions. \nYou should never use data visualization to mislead your reader. \nThere are many ways pictures can be used to lie, and some of them can be unintentional.\n\nFor example, if we see differences in shapes by area, not width or height. \nSuppose you are creating a pictogram to demonstrate the recent increase in housing prices, which have doubled in the last $n$ years. \nSo, you draw two houses, one that is 1'' wide and one that is 2'' wide. \nTo a reader, it will appear that housing prices have increased by a factor of $2^2=4$. \nHence, you should make pictures proportional in \\emph{area} to the numbers they represent.\n\nScale is also important when you are drawing a line graph or a histogram. \nDifferences between data points can appear small if you zoom out, or large if you zoom in (see Figure \\ref{fig:dog_plots}). \nAlso, changing the scale partway along the $x$- or $y$-axis can distort data.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{dog_plots.pdf}\n\\caption{The graph of some data can look very different depending on the scale. \nHere are two graphs of the ``same'' line over the same range (1 to 4). \nThe only difference is the $y$-range. Notice easy it is to manipulate the y-scale to imply either a large or small increase in $y$. \nThese figures are especially misleading when we leave the range markers off of the $y$-axes.}\n\\label{fig:dog_plots}\n\\end{figure}\n\nThree-dimensional special effects also tend to be misleading. \nA 3-D pie chart, for example, can be used to distort the sizes of its slices. \nSimilarly, a 3-D histogram can use perspective to distort the relative differences between bars.\n\nAs in any form of communication, integrity is important in data visualization. \nYou will win more respect for yourself and those you represent if you avoid misleading diagrams.\n\n\\printbibliography", "meta": {"hexsha": "cfaa1440f1a571aeb4dbd6c4b0b59afd20a28f6c", "size": 18747, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/ScientificVisualization/DataVisualization.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/ScientificVisualization/DataVisualization.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/ScientificVisualization/DataVisualization.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": 51.0817438692, "max_line_length": 219, "alphanum_fraction": 0.7534005441, "num_tokens": 4928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.72487026428967, "lm_q2_score": 0.8652240964782012, "lm_q1q2_score": 0.6271752194839447}}
{"text": "\n\\section{Lower bound  of finite element error estimates}\n%{Notation and basic results}\nIn this section, we will indicate that the convergence rate is optimal by showing the lower bound of finite element error estimates. \n%\\subsection{Lower bound of finite element approximation in any dimension}\n%In this subsection, \nWe will provide lower bound for finite element error estimates that are obtained by Lin, Xie and Xu~\\cite{lin2014lower}.\n\\begin{theorem}\\label{Lower_Bound_linear}\nAssume $u\\in H^{3}(\\Omega)$ and $u$ is not linear %$u\\notin V_h$ \nand for all $v_h\\in V_h$ being the linear finite element function.\nThe following lower bound of the approximation error holds when the family of mesh $\\mathcal{T}_h$\nis quasi-uniform %the mesh size is $h$ is sufficiently small:\n\\begin{equation}\\label{lower_convergence_0_1}\n\\inf_{v_h\\in V_h}\\|u-v_h\\|_{r}\\geq Ch^{2-r}\\approxeq N^{-\\frac{2-r}{d}}\\quad r=0, 1,\n\\end{equation}\nwhere $C$ is dependent on $u$.\n\\end{theorem}\n\\begin{proof}\nLet $\\Pi_2$ is the nodal interpolation to quadratic finite element,  and denote $\\displaystyle |\\cdot|_{2,h}=\n\\left(\\sum_{\\tau \\in \\mathcal T_h} |\\cdot|^2_{2,\\tau}\\right)^{\\frac12}$. For any $v_h\\in V_h$, since $v_h$ is\nlinear, by the approximation property of $\\Pi_2$ and inverse inequality, we have \n\\begin{equation}\n\\begin{aligned}\n|u|_{2,\\Omega}&=|u-v_h|_{2,h}\\le |u-\\Pi_2 u|_{2,h}+|\\Pi_2u-v_h|_{2,h}\\\\\n& \\le C_1h |u|_{3,\\Omega}+C_2h^{r-2}\\|\\Pi_2u-v_h\\|_{r,\\Omega}\\\\\n& \\le C_1h |u|_{3,\\Omega}+C_2h^{r-2}\\|\\Pi_2u-u\\|_{r,\\Omega} +C_2h^{r-2}\\|u-v_h\\|_{r,\\Omega}\\\\\n& \\le C_1h |u|_{3,\\Omega}+C_3h^{r-2}h^{3-r}|u|_{3,\\Omega} +C_2h^{r-2}\\|u-v_h\\|_{r,\\Omega}\\\\\n\\end{aligned}\n\\end{equation}\nnamely \n\\begin{equation}\n\\begin{aligned}\n|u|_{2,\\Omega}-(C_1+C_3)h|u|_{3,\\Omega}\\le C_2h^{r-2}\\|u-v_h\\|_{r,\\Omega}.\n\\end{aligned}\n\\end{equation}\nLet $h_0(u)=\\frac{|u|_{2,\\Omega}}{2 (C_1+C_3)|u|_{3,\\Omega}}$ and we have\n$$\n|u|_{2,\\Omega}-(C_1+C_3)h_0|u|_{3,\\Omega}=\\frac12|u|_{2,\\Omega}.\n$$\nNoting that $v_h\\in V_h$ is arbitrary, then if $h\\le h_0$, we have  \n\\begin{equation}\n\\inf_{v_h\\in V_h}\\|u-v_h\\|_{r,\\Omega}\\geq Ch^{2-r}.\n\\end{equation}\nIf $\\mathcal{T}_h$ is a triangulation with mesh size $h> h_0$, then by the newest vertex bisection strategy shown in \\cite{stevenson2008completion}, we \ncan refine $\\mathcal{T}_h$ such that the new triangulation \n$\\mathcal{T}_{h_0}$ with mesh \nsize decreasing to the order of $h_0$  and we have $V_h\\subset V_{h_0}$, which implies \n\\begin{equation}\n\\inf_{v_h\\in V_h}\\|u-v_h\\|_{r,\\Omega}\\geq \\inf_{v_{h_0}\\in V_{h_0}}\\|u-v_{h_0}\\|_{r,\\Omega} \\geq Ch_0^{2-r}.\n\\end{equation}\nTherefore \\eqref{lower_convergence_0_1} is desired. \n\\end{proof}\n\n%\\begin{conjecture}\n%\tLet $V_N$ be  linear finite element spaces associated with \n%\tshape-regular simplicial grids $\\mathcal T_N$ of $N$-elements (or\n%\t$N$-grid points) in a polyhedral domain $\\Omega\\subset \\mathbb R^d$,\n%\tsay $\\Omega=(0,1)^d$.  Then,  for any reasonable function (which is,  say,\n%\tnot locally linear, $|u|_{2}\\neq 0$), then the following lower bound holds:\n%\t\\begin{equation}\n%\t\\label{optimalFEMerror}\n%\t\\inf_{\\# \\mathcal T_N=\\mathcal O(N)} \\inf_{v_N\\in\n%\t\tV_N}\\|u-v_N\\|_{0,\\Omega}\\ge c(u) N^{-2/d} \n%\t%\\le C(u) N^{-2/d}\n%\t\\end{equation}\n%\\end{conjecture}\n%\n%Questions:\n%\\begin{enumerate}\n%\t\\item Is the above conjecture correct in some way?  If yes, what are\n%\tthe more rigorous statements for such results?\n%\t\\item What are the most relevant references that contain such results?\n%\t\\item If the conjecture is incorrect, is there a counter example?\n%\\end{enumerate}\n\n\n\\begin{conjecture}\\label{conjecture1}\nFor any function $u\\in L^2(\\Omega)$ % is not smooth (for example $u\\in H^{1+\\epsilon}$ for any $\\epsilon>0$)\n that is not locally linear (namely $u$ is not\nlinear in any open subset), we  have \n\\begin{equation}\\label{lower_convergence_0_2}\n\\inf_{v_h\\in V_N}\\|u-v_h\\| \\gtrsim  N^{-\\frac{2}{d}}\n\\end{equation}\nfor any finite element space $V_N$ of dimension $N$ on a shape-regular grid.\n\\end{conjecture}\n%Questions:\n%\\begin{enumerate}\n%\t\\item Is the above conjecture correct in some way?  If yes, what are\n%\tthe more rigorous statements for such results?\n%\t\\item What are the most relevant references that contain such results?\n%\t\\item If the conjecture is incorrect, is there a counter example?\n%\\end{enumerate}\n%\\begin{conjecture}\\label{con2}\n%Let $\\mathcal  T_N$ be a grid of $\\Omega\\subset \\mathbb R^d$ with $N$ elements and $V_h$ be the finite element space on $\\mathcal  T_N$. \n%If $u$ is a smooth function (for example $u\\in H^3(\\Omega)$) and the optimal partition $\\mathcal  T^*_N$ such that \n%\\begin{equation}\\label{lower_convergence_0_3}\n%\\inf_{\\# \\mathcal T_N=N}\\inf_{v_h\\in V_h}\\|u-v_h\\|_{r}=\\inf_{v_h\\in V^*_h}\\|u-v_h\\|_{r}\\geq  CN^{-\\frac{2-r}{d}}\\quad r=0, 1\n%\\end{equation}\n%where $V_h^*$ is the finite element space on $\\mathcal  T^*_N$, then the partition $\\mathcal  T^*_N$ can be a quasi-uniform partition.\n%\\end{conjecture}\n\n\\begin{conjecture}\\label{con2}\nLet %with $N$ elements \n $V_N$ be the linear finite element space on a grid $\\mathcal  T_N$ of $\\Omega\\subset \\mathbb R^d$. \nIf $u$ is a smooth function (for example $u\\in H^2(\\Omega)$) and $u$ is not a linear function,\n\\begin{equation}\\label{lower_convergence_0_3}\n\\mathop{\\inf_{\\# \\mathcal T_N=N}}_{\\mathcal T_N~\\hbox{is shape regular}} \\inf_{v_h\\in V_N}\\|u-v_h\\|\\gtrsim \\mathop{\\inf_{\\# \\mathcal T_N=N}}_{\\mathcal T_N~\\hbox{is quasi-uniform}} \\inf_{v_h\\in V_N}\\|u-v_h\\|\\gtrsim N^{-\\frac{2}{d}}.\n\\end{equation}\n%where $V_N^*$ is the finite element space on $\\mathcal  T^*_N$, then the partition $\\mathcal  T^*_N$ can be a quasi-uniform partition.\n\\end{conjecture}\nQuestions:\n\\begin{enumerate}\n\t\\item Is the above Conjecture \\ref{conjecture1} or Conjecture \\ref{con2} correct in some way?  If yes, what are\n\tthe more rigorous statements for such results?\n\t\\item What are the most relevant references that contain such results?\n\t\\item If the Conjecture \\ref{conjecture1} or Conjecture \\ref{con2} is incorrect, is there a counter example?\n\\end{enumerate}\n\n\n", "meta": {"hexsha": "5b0c4f977f604b2d8bc4155f5cc19cd74a4fe36f", "size": 6005, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LowerBound.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/LowerBound.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/LowerBound.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.0416666667, "max_line_length": 231, "alphanum_fraction": 0.7025811823, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702642896702, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.6271752094074087}}
{"text": "% !TEX root = ../main.tex\n\\newpage\n\\section{\\theory Mean Field Reductions} \\label{sec:MFRs}\nThe \\textsl{mean-field reduction} (\\MFR) is a theory that can predict the dynamics of the order parameter \\eqref{eq:orderparameter}. In \\cite{OttAntonsen2008, OttAntonsen2009, OttAntonsen2010} such a method was published for fully connected networks of indistinguishable oscillators with harmonic coupling. In \\cite{Restrepo2014} the authors extended their work to include networks with arbitrary degree distributions, applied to the Kuramoto model. Later this analysis was extended to networks of the Theta Neuron model \\cite{OttAntonsen2017}. We will now consider the limit $N \\gg 1$ and formulate an exact \\MFR for different types of networks, following the method in \\cite{OttAntonsen2017}. \n\n\\subsection{The Ott-Antonsen manifold}\nTo simplify notation, the authors incorporate the network size in to $P$ so that $\\sum_{\\k \\in \\K} P(\\k) = N$. To specify the probability of a link from a node of degree $\\kacc$ to one of degree $\\k$ we can define an assortativity function:\n\\begin{align}\na\\left(\\k_j \\rightarrow \\k_i \\right) = 0 \\leq \\frac{k^{\\rm{out}^{\\prime}}_j k^{\\rm{in}}_i}{N \\kmean} \\leq 1 \\label{eq:assortativityfunction}\n\\end{align}\nwhere we have chosen a neutral assortativity \\cite{OttAntonsen2017}. \\eqref{eq:assortativityfunction} is constrained so that the number of links in the network, $N \\kmean$, remains constant \\cite{Restrepo2014}:\n\\begin{align*}\n\\sum_{\\kacc \\in \\K} \\sum_{\\k \\in \\K} P\\left( \\kacc \\right) \\: a\\left(\\kacc \\rightarrow \\k\\right) P\\left(\\k\\right) = N \\kmean\n\\end{align*}\nWe can now assume that the state of all neurons can be represented by a probability density function $f(\\theta, \\eta | \\k, t)$. Hence, the marginal distribution \n\\begin{align*}\n    \\int_{\\R} \\int_{\\mathbb{I}} f(\\vartheta, \\eta^{\\prime} | \\k, t) \\mathop{d \\vartheta} \\mathop{d \\eta^{\\prime}} \n\\end{align*}\ngives the fraction of nodes of degree $\\k$ with a phase in $\\mathbb{I} \\subset \\T$ at time $t$. Also, we assume $\\eta_i$ do not change over time, so that $\\int_{\\T} f(\\vartheta, \\eta^{\\prime} | \\k, t) \\: \\mathop{d \\vartheta}$ yields the excitability distribution $g(\\eta | \\k)$. \\\\\n\nTo describe the global synchronisation of the network of theta neurons \\eqref{eq:thetaneuronnetwork} we have introduced the order parameter $Z(t)$ in \\eqref{eq:orderparameter}. It is now hypothesized that $Z(t)$ can be approximated by a mean-field order parameter, defined by the continuum limit:\n\\begin{align}\n\\bar{Z}(t)= \\frac{1}{N} \\sum_{\\k \\in \\K}P(\\k) \\int_{\\R} \\int_{\\T} f\\left(\\vartheta, \\eta^{\\prime} | \\k, t\\right) e^{\\ic \\vartheta} \\mathop{d \\vartheta} \\mathop{d \\eta^{\\prime}} \\label{eq:meanfieldorderparameter}\n\\end{align}\nHere, $f$ is constrained by a continuity equation, as the number of oscillators is conserved:\n\\begin{align}\n\\frac{\\partial f}{\\partial t}+\\frac{\\partial}{\\partial \\theta}\\left(v_{\\theta} f\\right) = 0 \\label{eq:transportequation}\n\\end{align}\nwith $v_{\\theta}$ a continuum version of \\eqref{eq:thetaneuronnetwork}:\n\\begin{align*}\nv_{\\theta} &= (1-\\cos \\theta)+(1+\\cos \\theta) \\left[\\eta + I(\\k,t) \\right]\\\\\nI(\\k,t) &= \\frac{\\kappa}{\\kmean}\\sum_{\\kacc \\in \\K} P(\\kacc ) \\:a\\left(\\kacc \\rightarrow \\k \\right) \\times \\left[ \\int_{\\R} \\int_{\\T} f\\left(\\vartheta, \\eta^{\\prime} | \\kacc, t\\right) \\: a_{2} \\left(1-\\cos \\vartheta\\right)^{2} \\mathop{d \\vartheta} \\mathop{d \\eta^{\\prime}} \\right] &\n\\end{align*}\nIn \\cite{OttAntonsen2008} it is shown that there exists a manifold of invariant probability densities for the continuity equation. The exact \\MFR is obtained by expanding $f$ as a Fourier series, and expanding the pulse $\\mathcal{P}_s$ using the binomial theorem. When assuming $\\eta_i$ is distributed according to a Lorenz distribution:\n\\begin{align}\ng(\\eta |\\k)=\\frac{1}{\\pi} \\frac{\\sigma(\\k)}{(\\eta-\\eta_{0}(\\k))^{2}+\\sigma(\\k)^{2}} \\label{eq:Lorentzpdf}\n\\end{align}\nthe set of reduced equations then takes a particularly simple form, as \\eqref{eq:meanfieldorderparameter} can be evaluated at the poles of $g$ using the Cauchy residue theorem for the integration of complex variables and we find a closed form expression. We can now capture the dynamics by $z(\\k,t)$, the mean-field variable for nodes of degree $\\k$:\n\\begin{align}\n\\frac{\\partial z(\\k, t)}{\\partial t} &= -\\ic \\frac{(z(\\k, t)-1)^{2}}{2} + \\frac{(z(\\k, t)+1)^{2}}{2} \\cdot I(\\k, t) \\qquad \\qquad z \\in \\C^{M_\\k} \\nonumber \\\\\nI(\\k, t) &= -\\sigma(\\k) + \\ic \\eta_{0}(\\k) + \\ic H_2(\\k,t) \\label{eq:OttAntonsenSystemFull} \\\\\nH_2(\\k,t) &= \\frac{\\kappa}{\\kmean} \\sum_{\\kacc \\in \\K} P\\left(\\kacc\\right) \\: a\\left(\\kacc \\rightarrow \\k\\right)  \\left( 1 + \\frac{z(\\kacc, t)^2 + (z(\\kacc, t)^c )^2}{6} - \\frac{4}{3} \\Re(z(\\kacc, t)) \\right) \\nonumber\n\\end{align}\nwith $z^c$ the complex conjugate. $H$ is a legacy term and has been computed in \\cite{Martens2020}.\nThe mean-field order parameter can now be expressed in terms of $z(\\k,t)$: using the constraints on $f$ and $g$ we can solve \\eqref{eq:meanfieldorderparameter} as:\n\\begin{align}\n\\bar{Z}(t) &= \\frac{1}{N} \\sum_{\\k \\in \\K} P(\\k) z(\\k, t) \\qquad \\bar{Z} \\in \\C \\label{eq:OttAntonsenMeanField}\n\\end{align}\nwhich clearly reflects the network architecture through $P(\\k)$, as in the limit, this is the number of neurons of degree $\\k$ that are present in the network. The mean-field dynamics of the whole network are thus equal to a weighed average of the degree dynamics of each node with unique degree $\\k \\in \\K$. \n\nWe have now formulated the evolution on the invariant manifold by a reduced set of ordinary differential equations. The \\MFR is computationally efficient, and in \\cite{OttAntonsen2017} many methods for improving this efficiency further are treated.\n\n\n\\subsection{Simplifications for fixed-degree networks}\nIn the case of a fixed-degree network, every node has $\\deg (\\theta_i) = (\\kmean, \\kmean)$ so:\n\\begin{align*}\n    \\frac{1}{\\kmean} \\sum_{\\kacc \\in \\K} P\\left(\\kacc\\right) \\: a\\left(\\kacc \\rightarrow \\k\\right) = \\frac{1}{\\kmean} N \\left( \\frac{\\kmean \\kmean}{N \\kmean} \\right) = 1\n\\end{align*}\nFor any fixed-degree network, \\cref{eq:OttAntonsenSystemFull,eq:OttAntonsenMeanField} reduce to a single complex differential equation:\n\\begin{align}\n\\dot{Z}(t)= -\\ic \\frac{(Z-1)^2}{2}+\\frac{(Z+1)^2}{2} \\left(-\\sigma+ \\ic\\eta_{0}\n+ \\ic \\kappa \\left(1+\\frac{Z^{2} + (Z^c)^{2} }{6} - \\frac{4}{3} \\Re(Z)\\right)\\right) \\label{eq:MeanField}\n\\end{align}\nThis is an identical formulation as in \\cite{Luke2013} and \\cite{Martens2020}. For any fixed-degree network, the reduced system is thus a complex (two-dimensional) system with three bifurcation parameters $\\eta_0, \\sigma$ and $\\kappa$, \\cite{Luke2013, Martens2020}. We will start our analysis with \\eqref{eq:MeanField}.\\\\\n\nThree distinct macroscopic states can be identified. In the partially synchronous rest state (\\PSR) we can observe in Figure \\ref{fig:MFRPSR}, $Z$ settles onto a stable node. Most neurons can be found in a resting state $\\eta_0 + \\sigma \\lesssim 0$, and inhibit one another through $\\kappa < 0$. Most neurons are therefore inactive, though some spiking neurons from the tail of $g$ are present but have a neglegible effect. \\\\\n\nIn Figure \\ref{fig:MFRPSS} we can observe the partially synchronous spiking (\\PSS) state, where we can see how $Z$ settles onto a stable focus. This happens predominantly when $\\eta_0 - \\sigma \\gtrsim 0$ and most neurons inherently spike, with the coupling being either excitatory or weakly inhibitory. Although most neurons are active, the network is partially synchronous and organized such that phase cancellation occurs by continuous spiking among the neurons.\\\\\n\nLastly, in the collective periodic wave state (\\CPW) we can observe a limit cycle of the mean field, in Figure \\ref{fig:MFRCPW}. Most neurons are active and inhibitory: $\\eta_0 > 0$ and $\\kappa < 0$. The collective oscillation emerges from the interplay between the neurons’ inherent tendency to spike and the strong suppressive network interaction. \\CPW states are mediated through Hopf bifurcations and homoclinic bifurcations of $Z$. We can also see the occurrence of a saddle-node bifurcation in the lower hand corner, for low $\\sigma$. We will continue to study the \\CPW due to its interesting properties.\\\\\n\nA more detailed discussion of the different regimes and bifurcations can be found in \\cite{Luke2013}.\n\n% \\textcolor{red}{QUESTION}: \\textsl{I have worked on the analysis presented in \\cite{Luke2013} to make my own figures on the bifurcations. However, I cannot seem to get them plotted. Should I continue on this?}\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}[b]{0.32\\linewidth}\n   \\centering\n  \\includegraphics[width=\\linewidth]{../Figures/PhaseSpace/MFRPSR.pdf}\n   \\caption{PSR state for $\\eta_0 = -0.9, \\sigma = 0.8$ and $\\kappa= -2$. The mean field settles onto a stable node.}\n   \\label{fig:MFRPSR} \n\\end{subfigure} \\hfill\n\\begin{subfigure}[b]{0.32\\linewidth}\n   \\centering\n  \\includegraphics[width=\\linewidth]{../Figures/PhaseSpace/MFRPSS.pdf}\n   \\caption{PSS state for $\\eta_0 = 0.5, \\sigma = 0.7$ and $\\kappa= 2$. The mean field settles onto a stable focus.}\n   \\label{fig:MFRPSS}\n\\end{subfigure} \\hfill\n\\begin{subfigure}[b]{0.32\\linewidth}\n   \\centering\n  \\includegraphics[width=\\linewidth]{../Figures/PhaseSpace/MFRCPW.pdf}\n   \\caption{CPW state for $\\eta_0 = 10.75, \\sigma = 0.5$ and $\\kappa= -9$. The mean field settles onto a stable limit cycle.}\n   \\label{fig:MFRCPW}\n\\end{subfigure}\n   \\caption{Three macroscopic states observed in the \\MFR inside the imaginary unit circle $|Z(t)| \\leqslant 1$. Green arrows mark the phase space vector field and blue trails mark solution curves. Red points indicate equilibrium points, with black arrows marking the direction of the eigenvectors in that point, scaled according to the magnitude of the corresponding eigenvalues. This information is found from the Jacobian, which we will discuss in Chapter \\ref{sec:MFRSUndirected}.}\n   \\label{fig:macroscopicstatesfixeddegree}\n\\end{figure}\n\n\n\\subsection{Implications and challenges of the \\MFR}\nThe advantages of using the \\MFR can be found in the number of equations we now have left to investigate. As there are $M_{\\k}$ equations in \\eqref{eq:OttAntonsenSystemFull}, instead of $N$ equations for $N$ neurons, the reduction becomes more and more efficient for larger networks. As we have seen in \\eqref{eq:MeanField} this yields a single equation for a fixed-degree network, as all neurons have the same degree.\\\\\n\nWhile the \\MFR gives us the opportunity to use any arbitray univariate distribution $P(k)$ for undirected, symmetric networks or any bivariate distribution $P(\\k)$ for directed, asymmetric networks, none of the publications on the \\MFR have treated directed networks. The challenge there is that the support $\\K$ is a much larger set, as $\\K = \\koutb \\times \\kinb$. For example, the scale-free distribution \\eqref{eq:scalefreepdf} has $M_{\\k} = \\kmax - \\kmin$ number of degrees in its support. An example would be $M_{\\k} = $ 1250, \\cite{OttAntonsen2017}. For 10.000 neurons, that is a reduction of 87,5\\%. When we wish to extend \\eqref{eq:scalefreepdf} to a bivariate distribution, $M_{\\k}$ grows to $\\left( \\kmax - \\kmin \\right)^2$. A bivariate distribution would therefore need about $1.56 \\times 10^6$ equations for 10.000 neurons. It is not feasible to solve this many equations at once. Even though it is reported that solving only 10\\% of the equations and then interpolating across $z$ and $t$ yields a very good approximation of the whole system, \\cite{OttAntonsen2017}, the sheer number of equations remains too high.\n\n", "meta": {"hexsha": "495d5b472416824c6388ed2755054c8b0ce46e35", "size": 11587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Mainmatter/Mean Field Reductions.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/Mean Field Reductions.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/Mean Field Reductions.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": 109.3113207547, "max_line_length": 1127, "alphanum_fraction": 0.7307327177, "num_tokens": 3566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6271558611971542}}
{"text": "\n\n\\chapter{Multiscale Methods on the Sphere}\n\\label{ch_mms}\n\nIn this chapter, many multiscale decompositions will be built \nbased on the spherical harmonics and/or the HEALPix representation.\n\n\\section{Orthogonal Haar Wavelets on the Sphere}\n\\label{mrs_haar}\n\\index{wavelet!Haar on sphere}\n\\index{sphere!Haar}\n\nThe Haar wavelet transform on the sphere \\citep{wave:sweldens95a} at each resolution $j$ and pixel $\\bk=(k_x,k_y)$ on the sphere \nis based on a scaling function $\\phi_{j,\\bk}$ ($\\phi_{j,\\bk}(\\bx) = \\phi\\parenth{2^{-j}(\\bx-\\bk)}$, where $\\bx$ is the vector of \nCartesian coordinates on the sphere, and $\\phi$ is the Haar scaling function) and three Haar wavelet functions $\\psi^{d}_{j,\\bk}$ (see~\\eqref{def_whaar1})\nwith $d \\in\\{1,2,3\\}$. It uses the idea that a given pixel on the sphere at a given resolution $j$ in the HEALPix representation\nis directly related to four pixels at the next resolution $j-1$.  \n% For Healpix  pixelisation, resolution of the map is related \n% to the  $N_{side}$ parameter, \n% which corresponds to the square root of number of pixels in each face.\n% $ N_{side} = 2^{j-1}$.  At a given resolution  $j$ we have $n_j=12 \\times 4^{j-1}$ pixels with a surface size $\\mu_j$. \n\nNoting, $\\bk_0$, the pixel. The scaling function $\\phi$ and three wavelet functions $\\psi$ are defined by:\n\\begin{eqnarray}\n\\label{def_whaar1}\n\\phi_{j,\\bk}(\\bx) & = & \\left\\{  \\begin{array}{ll}\n1 & \\textrm{if $t \\in S_{j,\\bk}$ }\\\\\n0 & \\textrm{otherwise}\n   \\end{array} \\right.  \\nonumber \\\\\n\\psi_{1,j+1,\\bk} & = & \\frac{\\phi_{j,\\bk_0} +\\phi_{j,\\bk_2}-\\phi_{j,\\bk_1}-\\phi_{j,\\bk_3} }{4}  \\nonumber \\\\\n\\psi_{2,j+1,\\bk} & = & \\frac{\\phi_{j,\\bk_0} +\\phi_{j,\\bk_1}-\\phi_{j,\\bk_2}-\\phi_{j,\\bk_3} }{4}  \\nonumber \\\\\n\\psi_{3,j+1,\\bk} & = & \\frac{\\phi_{j,\\bk_0} +\\phi_{j,\\bk_3}-\\phi_{j,\\bk_1}-\\phi_{j,\\bk_2} }{4}\n\\end{eqnarray}\n\n% \\begin{figure}[htb]\n%\\centering\n%\\includegraphics[width=10cm]{fig_haar_decomp.pdf}\n%\\label{fig_haar_decomp}\n%\\caption{On resolution to next using Haar.}\n%\\end{figure}\n\n% \\begin{figure*}\n% \\vbox{\n% \\centerline{\n% \\hbox{\n% \\includegraphics[angle=180,width=7cm]{haar0.pdf}\n% \\includegraphics[angle=180,width=7cm]{haar1.pdf}\n% }}\\centerline{\n% \\hbox{\n% \\includegraphics[angle=180,width=7cm]{haar2.pdf}\n% \\includegraphics[angle=180,width=7cm]{haar3.pdf}\n% }}\n% \\centerline{\n% \\hbox{\n% \\includegraphics[angle=180,width=7cm]{haar4.pdf}\n% \\includegraphics[angle=180,width=7cm]{haar5.pdf}\n% }}\n% }\n% \\label{fig_haar_decomp2}\n% \\caption{Haar wavelet  coefficents.}\n% \\end{figure*}\n\nDenoting $\\bk_0,\\bk_1,\\bk_2,\\bk_3$ the four pixels at scale $j$, hierarchically related to the pixel $\\bk$ at scale $j+1$, \nscaling coefficients $c_{j+1,\\bk}$ at scale $j+1$ are derived from those at scale $j$ by:\n\\begin{eqnarray}\n\\label{def_haar1}\nc_{j+1}[\\bk] &=& \\frac{1}{4} \\sum_{d=0}^3 c_{j} [\\bk_d],\n\\end{eqnarray}\nand wavelet coefficients at scale $j+1$ from coefficients at scale $j$ by:\n\\begin{eqnarray}\n\\label{def_haar2}\nw^{1}_{j+1} [\\bk] &=& \\frac{1}{4} (c_{j}[\\bk_0]+c_{j} [\\bk_2] - c_{j} [\\bk_1]-c_{j}[\\bk_3])  \\nonumber  \\\\\nw^{2}_{j+1} [\\bk] &=& \\frac{1}{4} (c_{j}[\\bk_0]+c_{j} [\\bk_1] - c_{j} [\\bk_2]-c_{j}[\\bk_3])  \\nonumber  \\\\\nw^{3}_{j+1} [\\bk] &=& \\frac{1}{4} (c_{j}[\\bk_0]+c_{j} [\\bk_3] - c_{j} [\\bk_1]-c_{j}[\\bk_2]) .\n\\end{eqnarray}\n\n% Fig. \\ref{fig_haar_decomp} shows the calculation scheme of haar coefficients, from one resolution to the next. \n% Haar wavelet coefficients for the astronomical WMAP data set are shown in Fig. \\ref{fig_haar_decomp2}.\n\nThe Haar wavelet transform on the sphere is orthogonal and its reconstruction is exact. The inverse transformation is obtained by:\n\\begin{eqnarray}\n\\label{def_recons_haar}\nc_0[\\bx] = \\sum_{\\bk}  c_{J}[\\bk]  \\phi_{J,\\bk}(\\bx) + \\sum_{j=1}^{J} \\sum_{d=1}^3 \\sum_{\\bk} w^{d}_{j}[\\bk]  \\psi^d_{j}(\\bx) .\n\\end{eqnarray}\n\nThis transform is very fast but its interest is relatively limited. Indeed, it is not rotation invariant, and more importantly \nthe Haar wavelet shape is not well adapted for most applications, because of the non-regular shape of the wavelet function.\n\n\n% ===============================================\n\n\\section{Continuous Wavelets on the Sphere}\n\n\\subsection{Stereoscopic Projection}\n\\label{chap_mex_hat}\n\n\\index{wavelet!axisymmetrical wavelets}\n\\index{wavelet!stereoscopic projection}\n\n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=15cm]{proj_stereo_inverse.pdf}\n\\caption{Inverse stereographic projections of a radial function from plane to the sphere.}\n\\label{figprojstereo_direct}\n\\end{figure}\n\nIn order to have more choice to design the wavelet function, we may want to use wavelets defined for regular 2D images to the sphere.\nThis is possible by using inverse stereographic projections of radial wavelet functions such the Mexican hat \\citep{wave:cayon01}.\nDefining the stereographic projection operator, $\\bR: {\\bf t} \\mapsto \\ {\\boldsymbol \\omega}$, with ${\\boldsymbol \\omega} = (\\theta(r),\\vartheta)$, \n$\\theta(r) = 2 \\arctan(r/2)$, the radial wavelets $\\psi_{\\mathrm{plane}}$ can be projected on the sphere by a unique rotation, \n${\\boldsymbol \\omega}_0 =(\\theta_0,\\vartheta_0)$, respectively around the two axes $O_y$ and $O_z$. Fig.~\\ref{figprojstereo_direct} shows \nthe projection of radial functions from the plane to the sphere. \n \nThe convolution on the sphere between a radial wavelet function $\\psi(\\theta)$ and a function $f({\\boldsymbol \\omega})$ is:\n \\begin{eqnarray}\n\\label{convol_sph}\n(\\psi \\ast f)(\\theta,\\vartheta)= \\int_{S^2} \\psi_{\\mathrm{plane}}^* (\\bR^{-1}  {\\boldsymbol \\omega}) f({\\boldsymbol \\omega}) d{\\boldsymbol \\omega} .\n\\end{eqnarray}\n\nSuch wavelets are axisymmetric by construction. This property can be used to derive fast transformation algorithms using spherical harmonics.\nIndeed spherical harmonics coefficients $\\hat{\\psi}[l,m]$ of the wavelet function $\\psi$ on the sphere are equal to zero when $m \\neq 0$, \nand by the Funk-Hecke theorem, the convolution can be written using spherical harmonics by:\n\\begin{eqnarray}\n\\label{convol_sph_harm}\n(\\psi \\ast f)(\\theta,\\vartheta)  =  \\sum_{l=0}^{\\infty} \\sum_{m=-l}^{l} \\sqrt{\\frac{2l+1}{4\\pi} }\\hat{f}[l,m] \\hat{ \\psi}[l,0] Y_{lm}(\\theta,\\vartheta) ~.\n\\end{eqnarray}\nwhere $\\hat{f}[l,m]$ are the spherical harmonics coefficients of the function $f$,\\\\ \ni.e. $f = \\sum_{l=0}^{\\infty}\\sum_{m=-l}^{l} \\hat{f}[l,m] Y_{lm}$ and similary for $\\hat{\\psi}$.\n\nClassical wavelet dilations can also be derived on the sphere using the dilation operator $\\mathscr{D}_a$ by a factor $a > 0$ \\citep{wiaux07}:\n\\begin{eqnarray}\n\\label{proj_stereo}\n\\mathscr{D}_a(f)({\\boldsymbol \\omega}) = \\chi_a^{1/2} (a,\\theta)  f(D^{-1}_a {\\boldsymbol \\omega}) ,\n\\end{eqnarray}\nwhere $D_a(\\theta,\\vartheta)=(\\theta_a(\\theta),\\vartheta)$ with the linear relation $\\tan\\theta_a(\\theta)/2=a\\tan\\theta/2$, \nand $D_a$ is the dilation operator that maps a sphere without its South pole on itself. $\\chi_a^{1/2}(a,\\theta)$ is a norm \npreservation term (i.e. $\\mathscr{D}_a$ is unitary):\n\\begin{eqnarray}\n\\label{def_lambda}\n\\chi_a^{1/2}(a,\\theta) = a^{-1}[1+\\tan^2(\\theta/2)]/[1+a^{-2}\\tan^2(\\theta/2)] ~.\n\\end{eqnarray}\n\n% \\begin{figure*}\n% \\centering\n% \\includegraphics[width=9cm]{proj_stereo.pdf}\n% \\caption{Projection st\\'er\\'eographique inverse sur la sphere.}\n% \\label{figprojstereo}\n% \\end{figure*}\n\n\\subsection{Mexican Hat Wavelet} \n\n\\index{sphere!mexican hat}\n\\index{Mexican hat!on sphere}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.9cm]{wav_mex_hat_0.pdf}\n\\includegraphics[angle=180,width=7.9cm]{wav_mex_hat_1.pdf}\n}}\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.9cm]{wav_mex_hat_2.pdf}\n\\includegraphics[angle=180,width=7.9cm]{wav_mex_hat_3.pdf}\n}}\n}\n\\caption{Mexican hat on the sphere for the dilation parameter equal to $a = \\{1,2,4,8\\}$.}\n\\label{fig_wav_mex_hat}\n\\end{figure}\n\n% \\begin{figure}[htb]\n% \\vbox{\n% \\centerline{\n% \\hbox{\n% \\includegraphics[angle=180,width=6.5cm]{mex_hat_0.pdf}\n% \\includegraphics[angle=180,width=6.5cm]{mex_hat_1.pdf}\n% }}\\centerline{\n% \\hbox{\n% \\includegraphics[angle=180,width=6.5cm]{mex_hat_8.pdf}\n% \\includegraphics[angle=180,width=6.5cm]{mex_hat_20.pdf}\n% }}\n% }\n% \\caption{Cosmic Microwave Background (CMB) simulated map and its mexican hat wavelet transform\n% with dilation parameter $a = \\{1,8,20\\}$.}\n% \\label{fig_trans_cmb_wav_mex_hat}\n% \\end{figure}\n\nThe 2D Mexican hat wavelet transform is the second derivative of a Gaussian:\n\\begin{equation}\n\\label{rad_mexhat}\n\\psi(r) = \\frac{1}{\\sqrt{2 \\pi}} \\frac{1}{a} \\Big( 2 - \\Big( \\frac{r}{a} \\Big)^2 \\Big) e^{- \\frac{r^2}{2a^2}}\n\\end{equation}\nwhere  $a$ is a scale factor parameter and $r$ the distance to the wavelet center.\n\nUsing the inverse stereographic projection, it is possible to extend the Mexican hat wavelet\non the sphere  \\citep{wave:antoine99,wave:tenerio99,wave:cayon01,wave:holschneider96,wave:vielva04}:\n\\begin{equation}\n\\psi_a (r) = \\frac{1}{\\sqrt{2 \\pi} C_a} \\Big( 1 +  \\Big( \\frac{r}{2} \\Big)^2 \\Big)^2   \\Big( 2 - \\Big( \\frac{r}{a} \\Big)^2 \\Big) e^{- \\frac{r^2}{2a^2}}\n\\end{equation}\nwhere $a$ is a scale factor, $C_a$ is a normalization term $C_a = a \\Big( 1 + \\frac{a^2}{2} + \\frac{a^4}{4} \\Big)^{\\frac{1}{2}}$, \nand $r$ is the distance on the tangent plane, which is related to the polar angle $\\theta$ through $r = 2 \\textrm{tan} \\frac{\\theta}{2}$. \nThis transform may be useful to analyze the data, but it does not have a reconstruction operator, and can therefore not be used for \nrestoration applications.\n\nFig.~\\ref{fig_wav_mex_hat} shows the Mexican hat wavelet on the sphere for four different scales.\n%  and Fig ~\\ref{fig_trans_cmb_wa_mex_hat}  shows four scales for the a simulated CMB map.\n\n\n\\subsection{Directional Wavelets}\n\\label{dirwavelet}\n\\index{wavelet!directional wavelets}\n\n% \\index{sphere!directionnal wavelet}\n\n\\begin{figure}[htb]\n\\centering\n\\includegraphics[width=15cm]{projection_stereo_ondelette_directionnelle.pdf}\n\\caption{Inverse stereographic projections  of a  directional wavelet on the sphere.}\n\\label{figprojstereo_direct2}\n\\end{figure}\n\nTo study anisotropic structures, the previously described continuous wavelet transform can be extended to directional wavelets \\citep{wave:antoine01,vielva06,McEwen08}.\nFig.~\\ref{figprojstereo_direct2} shows the projection of an elliptic function from the plane to the sphere.  \n\n\\subsubsection{Elongated Mexican Hat Wavelet}\n\\index{wavelet!mexican hat}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_0.pdf}\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_1.pdf}\n}}\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_2.pdf}\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_3.pdf}\n}}\n\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_4.pdf}\n\\includegraphics[angle=180,width=7.7cm]{dir_mex_hat_5.pdf}\n}}\n}\n\\caption{Elongated Mexican hat on the sphere for the dilation parameter equal to $a_x= 1$ and $a_y = \\{0.5,1.,1.25,1.5,2,4\\}$.}\n\\label{fig_dir_mex_hat}\n\\end{figure}\n\nThe elongated Mexican hat wavelet can be written as:\n\\begin{multline}\n\\label{directional_hat}\n\\psi_{a_x, a_y}(\\theta, \\vartheta) = \\sqrt{\\frac{2}{\\pi}} C(a_x,a_y) \\parenth{1+ \\tan^2 \\frac{\\theta}{2}} \\bigg( 1- \\frac{4 \\tan^2 \\theta/2 }{a_x^2+a_y^2} \\Big(\\frac{a_y^2}{a_x^2} \\cos^2 \\vartheta \\\\\n+  \\frac{a_x^2}{a_y^2} \\sin^2 \\vartheta\\Big) \\bigg)  e^{-2 \\tan \\frac{\\theta}{2}(\\cos^2 \\vartheta / a^2_x + \\sin^2 \\vartheta / a^2_y  )} ~\n\\end{multline}\nwhere $a_x$ and $a_y$ are the dilation factors along the two axes $O_x$ and $O_y$, $C(a_x,a_y)$ is a normalization constant defined as\n\\begin{eqnarray}\n\\label{directional_hat_norm}\nC(a_x,a_y)& =& (a_x^2+a_y^2) \\parenth{a_x a_y (3a_x^4+ 3a_y^4+2a_xa_y)}^{-1/2} ~\n\\end{eqnarray}\n\nFig.~\\ref{fig_dir_mex_hat} shows the wavelet functions for different dilation parameters $a_x$ and $a_y$.\n\n\n\\subsubsection{Morlet Wavelet}\n\\index{wavelet!Morlet}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.9cm]{dir_morlet_0.pdf}\n\\includegraphics[angle=180,width=7.9cm]{dir_morlet_1.pdf}\n}}\\centerline{\n\\hbox{\n\\includegraphics[angle=180,width=7.9cm]{dir_morlet_2.pdf}\n\\includegraphics[angle=180,width=7.9cm]{dir_morlet_3.pdf}\n}}\n}\n\\caption{Morlet wavelets on the sphere for the parameter  $\\bk$ equal to  (2,0), (4,0), (6,6) et (9,1).}\n\\label{fig_dir_morlet}\n\\end{figure}\n\nThe Morlet wavelet on the sphere, derived from the stereographic projection of the 2D function on the plane, is:\n\\begin{equation}\n\\label{real_morlet}\n\\psi_{a_x, a_y, {\\bf k}}(\\theta, \\vartheta) = \\sqrt{\\frac{2}{\\pi}} C({\\bf k}) (1+ \\tan^2 \\frac{\\theta}{2}) \\bigg(\\cos \\frac{ {\\bf k} \\cdotp R^{-1} {\\bf x} }{\\sqrt{2}} - e^{- |{\\bf k}|^2/4} \\bigg) e^{-2 \\tan^2(\\theta/2)} \n\\end{equation}\nwith $R^{-1} {\\bf x} = (2 \\tan (\\theta/2) \\cos \\vartheta,2 \\tan (\\theta/2) \\sin \\vartheta)$, ${\\bf k}=(k_x,k_y)$, $|{\\bf k}|^2 = k_x^2 + k_y^2$, \nand $C({\\bf k}) = (1+3e^{-|{\\bf k}|^2/2} -4e^{-3 |{\\bf k}|^2/8})^{-1/2} $. ${\\bf k}$ allows us to control the oscillations of the wavelet functions.\\\\ \\\\\nFig.~\\ref{fig_dir_morlet} shows the Morlet wavelet for ${\\bf k}$ equal respectively to $(2,0)$, $(4,0)$, $(6,6)$ and $(9,1)$.\\\\\n\nContinuous wavelet transforms have been intensively used in astrophysics, mainly to analyze the Cosmic Microwave Background \\citep{wave:vielva04}.\nDirectional wavelets based on steerable filters were also proposed in \\citep{wiaux06,McEwen08}. We present in the following a set of multiscale \ndecompositions on the sphere which have a fast exact inverse transform, and are therefore suitable for many applications such as restoration.\n \n\n\n\n%===============================================================\n\n\\section{Redundant Wavelet Transform on the Sphere with Exact Reconstruction}\n\\label{sect_wts}\n%We show in this section that we can build  wavelet transforms on the sphere, based on the spherical harmonics transform, ewhich have an exact reconstruction and can therefore be easily used in different applications.\n\n\n\\subsection{Isotropic Undecimated Wavelet Transform on the Sphere}\nHere an undecimated isotropic transform (UWTS) is described which is similar in many respects to the undecimated isotropic transform \n\\citep{starck2010,starck:sta06}, and will therefore be a good candidate for restoration applications. Its isotropy is a favorable \nproperty when analyzing isotropic features. This isotropic transform is obtained using a scaling function ${\\phi}_{l_c}(\\theta, \\vartheta)$ \nwith cut-off frequency  $l_c$ and  azimuthal symmetry, meaning that ${\\phi}_{l_c}$ does not depend on the azimuth $\\vartheta$. \nHence the spherical harmonics coefficients $\\hat {\\phi}_{l_c} [l,m]$ of ${\\phi}_{l_c}$ vanish when $m \\ne 0$ so that:\n\\begin{eqnarray}\n{\\phi}_{l_c}(\\theta, \\vartheta)= {\\phi}_{l_c}(\\theta) = \\sum_{l = 0}^{l = l_c} \\hat  {\\phi}_{l_c} [l,0] Y_{l0}(\\theta, \\vartheta) .\n\\end{eqnarray}\nThen, convolving a function $f(\\theta, \\vartheta) \\in L_2(S^2)$ with ${\\phi}_{l_c}$ is greatly simplified \nand the spherical harmonics coefficients of the resulting map $c_0$ are readily given by\n\\begin{eqnarray}\n \\hat c_{0}[l,m] = \\widehat{{\\phi}_{l_c} * f} [l,m] = \\sqrt{\\frac{2l+1}{4\\pi} } \\hat {\\phi}_{l_c} [l,0] \\hat f[l,m]  .\n\\end{eqnarray}\n\\index{sphere!undecimated wavelet}\n\n\\subsubsection{From One Resolution to the Next}\n\nA sequence of smoother approximations of $f$ on a dyadic resolution scale can be obtained using the scaling function ${\\phi}_{l_c}$ as follows:\n\\begin{eqnarray}\n\\begin{split}\nc_0   & = &  {\\phi}_{ l_{c} }  \\ast f        \\\\\nc_1   & = &  {\\phi}_{2^{-1} l_{c} }   \\ast f    \t   \\\\\n&\\ldots&\\\\ \nc_j    &=&   {\\phi}_{2^{-j}  l_{c}  }  \\ast f  ,\n\\end{split}\n\\end{eqnarray}\nwhere ${\\phi}_{2^{-j} l_{c} }$ is a rescaled version of ${\\phi}_{l_{c}}$. The above multiresolution sequence can actually  be obtained recursively. \n\nDefine a low pass filter $h_{j}$ for each scale $j$  by:\n\\begin{eqnarray}\n \\widehat{H}_{j}[l,m]  & = & \\sqrt{\\frac{4\\pi}{2l+1} }  \\hat h_{j}[l,m]   \\nonumber  \\\\\n   &  = & \n   \\begin{cases}\n   \\frac {   \\hat \\phi_{\\frac{l_{c}}{2^{j+1}} }[l,m]   }   {  \\hat  \\phi_{  \\frac{l_{c}}{2^{j}} }[l,m]   } & \\mbox{if }  l  < \\frac{ l_{c}} {2^{j+1}} \\quad \\textrm{and}\\quad m = 0 , \\\\\n   0 & \\mbox{otherwise } . \n  \\end{cases}\n\\end{eqnarray}\nIt is then easily shown that $c_{j+1}$ derives from $c_j$ by convolution on the sphere with $h_j$:  $c_{j+1} = c_{j} \\ast h_j$.\n\n\n\\subsubsection{The Wavelet Coefficients}\n\nGiven an axisymmetric  wavelet function $\\psi_{l_c}$, we can derive in the same way a \nhigh pass filter $g_j$ on each scale~$j$:\n\\begin{eqnarray}\n \\widehat{G}_{j}[l,m]  & = & \\sqrt{\\frac{4\\pi}{2l+1} }  \\hat{g}_{j}[l,m] \\nonumber  \\\\\n   & = & \n  \\begin{cases}\n  \\frac {   \\hat \\psi_{\\frac{l_{c}}{2^{j+1}} }[l,m]   }   {  \\hat  \\phi_{  \\frac{l_{c}}{2^{j}} }[l,m]   } & \\mbox{if }  l  < \\frac{ l_{c}} {2^{j+1}} \\quad \\textrm{and}\\quad m = 0 ,\\\\\n1 &\\mbox{if }  l  \\ge \\frac{ l_{c}} {2^{j+1}} \\quad \\textrm{and}\\quad m = 0 ,\\\\ \n0&  \\mbox{otherwise } .\n  \\end{cases}\n\\end{eqnarray}\nFrom this definition, the wavelet coefficients $w_{j+1} $ at scale $j+1$ are obtained from the previous scaling coefficients $c_j$ \nby a simple convolution on the sphere with $g_j$: $w_{j+1} = c_{j} \\ast g_j$.\n\nAs in the standard 2D isotropic undecimated transform algorithm, the wavelet coefficients can be defined as the difference between two consecutive resolutions, \n$w_{j+1}(\\theta, \\vartheta) = c_{j}(\\theta, \\vartheta) - c_{j+1}(\\theta, \\vartheta)$. This defines a zonal wavelet function $\\psi_{l_c}$ as:\n\\begin{eqnarray}\\label{wavelet}\n\\hat \\psi_{\\frac{l_c}{2^{j}}}[l,m] = \\hat \\phi_{\\frac{l_c}{2^{j-1}}} [l,m]  - \\hat \\phi_{\\frac{l_c}{2^{j}}}[l,m] .\n\\end{eqnarray}\nThe high pass filters $g_j$ associated with this wavelet are expressed as: \n\\begin{eqnarray}\n\\begin{split}\n\\widehat{G}_{j}[l,m]  & = \\sqrt{\\frac{4\\pi}{2l+1} } \\hat{g}_{j}[l,m]  \\\\\n                  & = 1 - \\sqrt{\\frac{4\\pi}{2l+1} } \\hat{h}_j[l,m]   =   1 - \\widehat{H}_j[l,m] .\n\\end{split}\n\\end{eqnarray}\nObviously other wavelet functions could be used just as well. For example, we can define the wavelet function as the difference between\nthe squares of the scaling functions \\cite{starck:book98}, i.e. $\\hat \\psi^2_{\\frac{l_c}{2^{j}}}[l,m] = \\hat \\phi^2_{\\frac{l_c}{2^{j-1}}} [l,m]  - \\hat \\phi^2_{\\frac{l_c}{2^{j}}}[l,m]$. \n\n\\newpage\n\\subsubsection{Choice of the Scaling Function}\n\\index{wavelet!needlet}\n\\index{wavelet!Meyer}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\includegraphics[width=15cm,height=5cm]{fig_sphere_filterbank1.pdf}\n% \\includegraphics[width=14cm,height=5cm]{ch1_diff_uv_phi_psi.pdf}\n}}}\n\\caption{On the left, spherical harmonics coefficients $\\hat{{\\phi}}[l,0]$ of the the scaling function ${{\\phi}}$ and, on the right, those of the wavelet function ${\\psi}$.}\n\\label{fig_diff_uv_phi_psi}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm]{fig_splinew.png}%[width=6.5cm,height=3.9cm]\n \\includegraphics[width=7.5cm]{fig_needletw.png}\n}}\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm, trim= 2cm 14cm 2cm 2cm, clip=]{fig_splinew_versus_needletw.pdf}\n \\includegraphics[width=7.5cm, trim= 2cm 14cm 2cm 2cm, clip=]{fig_abssplinew_versus_absneedletw.pdf}\n}}\n\\centerline{\n\\hbox{\n\\includegraphics[width=7.5cm, trim= 2cm 14cm 2cm 2cm, clip=]{fig_meyerw_versus_needletw.pdf}\n\\includegraphics[width=7.5cm, trim= 2cm 14cm 2cm 2cm, clip=]{fig_absmeyerw_versus_absneedletw.pdf}\n}}\n}\n\\caption{Comparaison between spline, needlet, and Meyer wavelet functions on the sphere.}\n\\label{Figure:cmp_needlet}\n\\end{figure}\n\nAny function with a cut-off frequency is a possible candidate. The \nB-spline function of order 3 \\citep{starck2010,starck:sta06} leads to :\n\\begin{eqnarray}\n{\\hat{\\phi}}_{l_c} [l,m] = \\frac{3}{2} B_{3}  \\left(  \\frac{2l}{l_{c}} \\right)\n\\end{eqnarray}\nwhere $B_3(t)$ is the scaling function:\n\\begin{equation}\nB_3(t) = \\frac{1}{12}({\\mid{t-2}\\mid}^3 - 4 {\\mid{t-1}\\mid}^3 + 6 {\\mid{t}\\mid}^3 - 4 {\\mid{t+1}\\mid}^3 + {\\mid{t+2}\\mid}^3)\n\\end{equation}\n\n\nIn Fig.~\\ref{fig_diff_uv_phi_psi} the spherical harmonics coefficients of the scaling function derived from a B$_3$-spline, \nand those of the associated wavelet function \\eqref{wavelet}, are plotted as a function of $l$. Other functions such as \nMeyer wavelets or the needlet function \\citep{marinucci08} can be used as well. \n\n\nMeyer and needlet wavelet functions have both a much better frequency localization than the wavelet function derived from the  B$_3$-spline,\nand, as nothing is perfect, the price to pay is more oscillations in the direct space. To illustrate this, we \nshow in Fig.~\\ref{Figure:cmp_needlet} different wavelet functions.  Top left and right shows the respectively the spline and the needet wavelet function at a given scale. Fig.~\\ref{Figure:cmp_needlet}~middle left shows a cut of the healpix face with contains the previous functions. Middle right is the same functions, but we have plotted the absolute value in order to better visualize their respective ringing.\nAs it can be seen, for wavelet functions with the same main lob, the needlet wavelet oscillate much more than the spline wavelet.  Fig.~\\ref{Figure:cmp_needlet}~bottom left and right compares   Meyer and  needlet functions. They are relatively close and share\nthe same property of good frequency localization, but with more oscillations than the spline wavelet function.\nHence, the best wavelet choice certainly depends on the final applications. For statistical analysis, detection or restoration applications, \nwe may prefer to use a wavelet which does not oscillate too much and with a smaller support, and the spline wavelet is clearly the \ncorrect choice. For spectral or bispectral analysis, where the frequency localization is fundamental, then Meyer or needlet shoud be \npreferred to the spline wavelet.\n\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm]{fig_mars.png}%[width=6.5cm,height=3.9cm]\n \\includegraphics[width=7.5cm]{fig_mars_scale1.png}\n}}\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm]{fig_mars_scale2.png}\n \\includegraphics[width=7.5cm]{fig_mars_scale3.png}\n}}\n\\centerline{\n\\hbox{\n\\includegraphics[width=7.5cm]{fig_mars_scale4.png}\n\\includegraphics[width=7.5cm]{fig_mars_scale5.png}\n}}\n}\n\\caption{Mars topographic map and its UWTS (four wavelet detail scales and the scaling (smooth) band).}\n\\label{Figure:UWTS}\n\\index{data!Mars topography}\n\\end{figure}\n\nThe steps of the UWT on the sphere of a discrete image $X$ sampled from $f$ are summarized in Algorithm~\\ref{algo_uwts}. \nIf the wavelet function corresponds to the choice \\eqref{wavelet}, Step 3 in this UWTS algorithm reduces to $w_{j+1} = c_{j} - c_{j+1}$.\n\n% Their corresponding conjugate low pass and high pass filters $h$ and $g$ are plotted in Fig.~\\ref{fig_diff_uv_ht_gt}. \n\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{The Undecimated Wavelet Transform on the Sphere.}\n\\label{algo_uwts}\n\\noindent{\\bf Task:} Compute the UWTS of a discrete $X$.\\\\\n\\noindent{\\bf Parameters:} Data samples $X$ and number of of wavelet scales $J$.\\\\  \n\\noindent{\\bf Initialization:} \n\\begin{itemize}\n\\item $c_0=X$.\n\\item Compute the B$_3$-spline scaling function and derive $\\hat{\\psi}$, $\\widehat{H}$ and $\\widehat{G}$ numerically.\n\\item Compute the corresponding spherical harmonics transform of $c_0$.\n\\end{itemize}\n\\For{$j=0$ to $J-1$} {\n\\begin{enumerate}[1.]\n\\item Compute the spherical harmonics transform of the scaling coefficients:  $\\hat{c}_{j+1}=\\hat{c}_j\\widehat{H}_{j}$.\n\\item Compute the inverse spherical harmonics transform of $\\hat{c}_{j+1}$ to get $c_{j+1}$.\n\\item Compute the spherical harmonics transform of the wavelet coefficients:  $\\hat{w}_{j+1}=\\hat{c}_j\\widehat{G}_{j}$.\n\\item Compute the inverse spherical harmonics transform of $\\hat{w}_{j+1}$ to get $w_{j+1}$.\n\\end{enumerate}\n}\n\\noindent{\\bf Output:} ${\\cal W}=\\{w_1, w_2, \\dots, w_{J}, c_{J}\\}$ the UWTS of $X$.\n\\end{algorithm}\n}\n\nFig.~\\ref{Figure:UWTS} shows the Mars topographic map (top left)\n\\footnote{The Mars Orbiter Laser Altimeter (MOLA) generated altimetry profiles used to create global topographic maps. The MOLA instrument stopped acquiring altimetry data on June 30, 2001, and after that operated in passive radiometry mode until the end of the Mars Global Surveyor mission. MOLA data sets are produced by the MOLA Science Team and archived by the PDS Geosciences Node.} and its wavelet transform, using five scales (four wavelet scales + coarse scale). The sum of the five scales reproduces exactly the original image.\n\\index{Mars Orbiter Laser Altimeter}\n\n\\subsubsection{Inverse Transform}\n\nIf the wavelet is the difference between two resolutions, a straightforward reconstruction of an image from its wavelet coefficients ${\\cal W} = \\{w_1,\\dots, w_{J}, c_{J}\\}$ is: \n\n\\begin{eqnarray}\n c_{0}(\\theta, \\vartheta) = c_{J}(\\theta, \\vartheta) + \\sum_{j=1}^J  w_j(\\theta, \\vartheta) .\n\\end{eqnarray}\nThis reconstruction formula is the same as with the 2D undecimated isotropic wavelet algorithm (i.e. with \\`a trous agorithm).\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n\\includegraphics[width = 15cm, height = 5cm]{fig_sphere_filterbank2.pdf} \n% \\includegraphics[width=14.5cm,height=5cm]{ch1_diff_uv_ht_gt.pdf}\n}}}\n\\caption{On the left, the filter $\\hat{\\tilde{h}}$, and on the right the \nfilter $\\hat{\\tilde{g}}$.}\n\\label{fig_diff_uv_ht_gt}\n\\end{figure}\n\nBut since the transform is redundant there is actually no unique way to reconstruct an image from its coefficients see~\\citep{starck:sta06}. Indeed, using the relations:\n\\begin{eqnarray}\n\\begin{split}\n\\hat c_{j+1}[l,m] = \\widehat H_{j} [l,m]  \\hat c_{j} [l,m] \\\\\n\\hat w_{j+1}[l,m] = \\widehat G_{j} [l,m] \\hat c_{j} [l,m] \n\\end{split}\n\\end{eqnarray}\na least-squares estimate of $c_j$ from $c_{j+1}$ and $w_{j+1}$ gives:\n\\begin{eqnarray}\n\\hat{c}_{j}   = \\hat{c}_{j+1}  {\\widehat {\\tilde H}}_{j}   + \\hat{w}_{j+1}  {\\widehat {\\tilde G}}_{j} ~,\n\\end{eqnarray}\nwhere the dual filters $\\tilde h$ and $\\tilde g$ satisfy:\n\\begin{eqnarray}\n\\label{eqnht} \n\\begin{split}\n{\\widehat {\\tilde H}}_j =  \\sqrt{\\frac{4\\pi}{2l+1} } {\\hat {\\tilde h}}_j & = {\\widehat H}_{j}^* /\n\\parenth{\\big|{\\widehat H}_{j}\\big|^2 + \\big|{\\widehat G}_j\\big|^2} \\\\\n{\\widehat {\\tilde G}}_j =  \\sqrt{\\frac{4\\pi}{2l+1} } {\\hat {\\tilde g}}_j & = {\\widehat G}_{j}^* /\n\\parenth{\\big|{\\widehat H}_j\\big|^2 + \\big|{\\widehat G}_j\\big|^2} .\n\\end{split}\n\\end{eqnarray}\nFor the scaling function which is a B$_3$-spline function and a wavelet taken as the difference between two resolutions,\nthe corresponding conjugate low pass and high pass filters $\\widehat {\\tilde H}$ and $\\widehat {\\tilde G}$ are plotted in Fig.~\\ref{fig_diff_uv_ht_gt}. \nThe reconstruction algorithm is given in Algorithm~\\ref{algo_iuwts}.\n\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{Inverse UWT on the sphere.}\n\\label{algo_iuwts}\n\\noindent{\\bf Task:} Reconstruct an image from its UWTS coefficients.\\\\\n\\noindent{\\bf Parameters:} UWTS coefficients ${\\cal W}=\\{w_1, w_2, \\dots, w_{J}, c_{J}\\}$.\\\\\n\\noindent{\\bf Initialization:}\n\\begin{itemize}\n\\item Compute the B$_3$-spline scaling function and derive $\\hat{\\psi}$, $\\widehat{H}$, $\\widehat{G}$, $\\widehat{\\tilde H}$ and $\\widehat{\\tilde G}$ numerically.\n\\item Compute the spherical harmonics transform of $c_J$ to get ${\\hat c}_J$.\n\\end{itemize}\n\\For{$j=J-1$ to $0$, with step $=-1$} {\n\\begin{enumerate}[1.]\n\\item Compute the spherical harmonics transform of the wavelet coefficients $w_{j+1}$ to get $\\hat{w}_{j+1}$.\n\\item Multiply $\\hat{c}_{j+1}$ by ${\\widehat {\\tilde H}}_{j}$.\n\\item Multiply $\\hat{w}_{j+1}$ by ${\\widehat {\\tilde G}}_{j}$.\n\\item Get the spherical harmonics of $\\hat{c}_j=\\hat{c}_{j+1}+\\hat{w}_{j+1}$.\n\\end{enumerate}\n}\nCompute The inverse Spherical Harmonics transform of $\\hat c_0$.\\\\\n\\noindent{\\bf Output:} $c_0$ is the inverse UWT on the sphere.\n\\end{algorithm}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\includegraphics[width = 12cm,angle = 90]{fig_backwt_sphere.pdf}\n}}\n\\caption{Reconstruction from a single wavelet coefficient at different scales. Each map is obtained by setting all wavelet coefficients to zero but one, and by applying an inverse UWTS. Depending on the position and scale of the non-zero coefficient, the reconstructed map shows an isotropic feature \nat different scales and positions.}\n\\label{Figure:back_wt}\n\\end{figure}\n}\nFig.~\\ref{Figure:back_wt} shows the reconstruction by setting all wavelet coefficients but one at different scales and positions. \nDepending on the position and scale of the non-zero coefficient, the reconstructed map shows an isotropic feature at different scales and positions.\n \n\n%-------------------------\n\n\\subsection{Isotropic Pyramidal Wavelet Transform on the Sphere}\n\\index{wavelet!pyramidal transform}\n\\index{sphere!pyramidal wavelet}\n\n\\subsubsection{Forward Transform}\nIn the previous algorithm, no down-sampling is performed and each scale of the wavelet decomposition has the same number of pixels \nas the original data set. Therefore the number of pixels in the decomposition is equal to the number of pixels in the data multiplied \nby the number of scales. For some applications, we may prefer to introduce a decimation in the decomposition so as to reduce the \nrequired memory size and the computation time. This can be done easily by using a specific property of the chosen scaling function.\nIndeed, since we are considering here a scaling function with an initial cut-off $l_c$ in spherical harmonic multipole number $l$, \nand since the actual cut-off is reduced by a factor of two at each step, the number of significant spherical harmonics coefficients \nis then reduced by a factor of four after each convolution with the low pass filter $h$. Therefore, we need less pixels in the direct \nspace when we compute the inverse spherical harmonics transform. Using the HEALPix pixelization scheme \\citep{pixel:healpix}, \nthis can be done easily by dividing by 2 the $N_{\\mathrm{side}}$ parameter when calling the inverse spherical harmonics transform routine.\nThe pyramidal wavelet transform on the sphere algorithm is given in Algorithm~\\ref{algo_pwts}.\n\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{Pyramidal wavelet transform on the sphere.}\n\\label{algo_pwts}\n\\noindent{\\bf Task:} Compute the pyramidal WT on the sphere of a discrete image $X$.\\\\\n\\noindent{\\bf Parameters:} Data $X$ and number of of wavelet scales $J$.\\\\\n\\noindent{\\bf Initialization:} \n\\begin{itemize}\n\\item $c_0=X$.\n\\item Compute the B$_3$-spline scaling function and derive $\\hat{\\psi}$, $\\widehat{H}$ and $\\widehat{G}$ numerically.\n\\item Compute the corresponding spherical harmonics transform of $c_0$.\n\\end{itemize}\n\\For{$j=0$ to $J-1$} {\n\\begin{enumerate}[1.]\n\\item Compute the spherical harmonics transform of the scaling coefficients:  $\\hat{c}_{j+1}=\\hat{c}_j\\widehat{H}_{j}$.\n\\item Compute the inverse spherical harmonics transform of $\\hat{c}_{j+1}$ to get $c_{j+1}$.\n\\item Down-sample $c_{j+1}$, since its support in the spherical harmonic domain has been divided by two.\n\\item Compute the spherical harmonics transform of the wavelet coefficients:  $\\hat{w}_{j+1}=\\hat{c}_j\\widehat{G}_{j}$.\n\\item Compute the inverse spherical harmonics transform of $\\hat{w}_{j+1}$ to get $w_{j+1}$.\n\\end{enumerate}\n}\n\\noindent{\\bf Output:} ${\\cal W}=\\{w_1, w_2, \\dots, w_{J}, c_{J}\\}$ the Pyramidal WT on sphere of $X$.\n\\end{algorithm}\n}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm]{fig_earth_elevation.png}%[width=6.5cm,height=3.9cm]\n \\includegraphics[width=7.5cm]{fig_earth_scale_1.png}\n}}\n\\centerline{\n\\hbox{\n \\includegraphics[width=7.5cm]{fig_earth_scale_2.png}\n \\includegraphics[width=7.5cm]{fig_earth_scale_3.png}\n}}\n\\centerline{\n\\hbox{\n\\includegraphics[width=7.5cm]{fig_earth_scale_4.png}\n\\includegraphics[width=7.5cm]{fig_earth_scale_5.png}\n}}\n}\n\\caption{Pyramidal wavelet transform on the sphere.}.\n\\label{Figure:PWTS}\n\\end{figure}\n\nFig.~\\ref{Figure:PWTS} shows an Earth image and its pyramidal wavelet transform (PWTS) using five scales.\nAs the scale number increases (i.e.\\ the resolution decreases), the pixel size becomes larger. The data are \nland and sea-floor elevations obtained from the ETOPO5 5-minute gridded elevation data set. A thorough explanation \nof the data set is provided at \\texttt{www.ngdc.noaa.gov} \\footnote{The ETOPO5 data are credited to ``Data Announcement 88-MGG-02, \nDigital relief of the Surface of the Earth. NOAA, National Geophysical Data Center, Boulder, Colorado, 1988''. The HEALPix image \nis available at \\texttt{http://astro.ic.ac.uk/$\\sim$pdineen/earth/index.html\\#earthmap}.}.\n\n\n%\\newpage\n\\subsubsection{Inverse Transform}\n \nThis reconstruction is not as straightforward as in the undecimated case, since the different scales do not have the same resolution.\nFor each resolution level, we have to up-sample the scaling band before co-adding it to the wavelet coefficients. Algorithm \\ref{algo_ipwts} describes this.\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{Inverse Pyramidal Wavelet Transform on the sphere.}\n\\label{algo_ipwts}\n{\\bf Task:} Reconstruct an image from its pyramidal WT on the sphere.\\\\\n\\noindent{\\bf Parameters:} Pyramidal WT coefficients ${\\cal W}=\\{w_1, w_2, \\dots, w_{J}, c_{J}\\}$.\\\\\n{\\bf Initialization:}\n\\begin{itemize}\n\\item Compute the B$_3$-spline scaling function and derive $\\hat{\\psi}$, $\\widehat{H}$, $\\widehat{G}$, $\\widehat{\\tilde H}$ and $\\widehat{\\tilde G}$ numerically.\n\\item Compute the spherical harmonics transform of $c_J$ to get ${\\hat c}_J$.\n\\end{itemize}\n\\For{$j=J-1$ to $0$} {\n\\begin{enumerate}[1.]\n\\item Upsample $c_{j+1}$ to the resolution of $c_j$.\n\\item Compute the spherical harmonics transform of the wavelet coefficients $w_{j+1}$ to get $\\hat{w}_{j+1}$.\n\\item Multiply $\\hat{c}_{j+1}$ by ${\\widehat {\\tilde H}}_{j}$.\n\\item Multiply $\\hat{w}_{j+1}$ by ${\\widehat {\\tilde G}}_{j}$.\n\\item Get the spherical harmonics of $\\hat{c}_j=\\hat{c}_{j+1}+\\hat{w}_{j+1}$.\n\\end{enumerate}\n}\nCompute The inverse spherical harmonics transform of $\\hat c_0$.\\\\\n\\noindent{\\bf Output:} $c_0$ is the inverse pyramidal WT on the sphere.\n\\end{algorithm}\n}\n  \nThe wavelet transform on the sphere and its pyramidal version have both a reconstruction operator, \nso they are very well designed for any restoration application when the data contains isotropic features. \nIn the following, we present other transforms on the sphere more adapted to the analysis of anisotropic features.\n\n\n\n\n\n\\section{Ridgelet and Curvelet Transform on the Sphere (CTS) }\n\\label{sect_cur}\n\\subsection{Introduction.}\n\\index{curvelet}\n\\index{curvelet!sphere}\n\\index{sphere!curvelet}\n\nThe 2D curvelet transform, proposed in \\citep{cur:donoho99,starck:sta01_3,starck:sta02_3}, enables the directional analysis of an image \nin different scales. The fundamental property of the curvelet transform is to analyze the data with functions of length about $2^{-j/2}$ \nfor the $j^{\\textrm{th}}$ sub-band $[2^j, 2^{j+1}]$ of the two dimensional wavelet transform. Following the implementation described \nin \\citep{starck:sta01_3,starck:sta02_3}, the data first undergoes an Isotropic Undecimated Wavelet Transform (i.e. \\og{}\\`a trous \\fg{} algorithm). \nEach scale $j$ is then decomposed into smoothly overlapping blocks of side-length $B_j$ pixels in such a way that the overlap between two\nvertically adjacent blocks is a rectangular array of size $B_j \\times B_j/2$. And finally, the ridgelet transform \\citep{cur:candes99_1} is \napplied on each individual block. Recall that the ridgelet transform precisely amounts to applying a 1-dimensional wavelet transform to the\nslices of the Radon transform. More details on the implementation of the digital curvelet transform can be found in \\citep{starck:sta01_3,starck:sta02_3}.\nIt has been shown that the curvelet transform could be very useful for the detection and the discrimination of non-Gaussianity in CMB \\citep{starck:sta02_4}.\nThe curvelet transform is also redundant, with a redundancy factor of $16J+1$ whenever $J$ scales are employed. Its complexity scales like \nthat of the ridgelet transform that is as $O(n^2 \\log_2n)$. The curvelet transform was shown to sparsely represent anisotropic structures and smooth curves and edges of different lengths.\n\n\\subsection{Ridgelets and Curvelets on the Sphere.}\n\\index{curvelet transform}\nThe Curvelet transform on the sphere (CTS) can be similar to the 2D digital curvelet transform, but replacing the \\og{}\\`a trous \\fg{} algorithm \nby the Isotropic Wavelet Transform on the Sphere previously described. The CTS algorithm consists in the following three steps which \nwe describe in more details next.\n\\begin{itemize}\n\\item {\\it Isotropic Wavelet Transform on the Sphere.}  \n\\item {\\it Partitioning.} Each scale is decomposed into blocks of an appropriate scale (of side-length $\\sim2^{-s}$),using the HEALPix pixelization.\n\\item {\\it Ridgelet Analysis.} Each square is analyzed via the discrete ridgelet transform.\n\\end{itemize}\nWe now describe these three steps.\n\n\\subsubsection{Partitioning Using the HEALPix Representation}\n\n \\begin{figure}\n\\centerline{\n\\hbox{\n\\includegraphics[width=15cm]{fig_flowgraph_ridgelet_sphere.pdf}\n% \\includegraphics[width=13.6cm,height=8cm]{fig_flowgraph_ridgelet_sphere.pdf}\n}}\n\\caption{Flowgraph of the ridgelet transform on the sphere.}\n\\label{Figure:rid_sphere}\n\\end{figure}\n\nThe HEALPix representation is a curvilinear hierarchical partition of the sphere into quadrilateral pixels \nof exactly equal area but with varying shape. The base resolution divides the sphere into 12 quadrilateral \nfaces of equal area placed on three rings around the poles and equator. Each face is subsequently divided \ninto $N_{\\mathrm{side}}^{2}$ pixels following a quadrilateral multiscale tree structure (see Fig.~\\ref{pixelhealpix}). \nThe pixel centers are located on iso-latitude rings, and pixels from the same ring are equispaced in azimuth. \nThis is critical for computational speed of all operations involving the evaluation of spherical harmonics transforms, \nincluding standard numerical analysis operations such as convolution, and power spectrum estimation. \n\nAn important geometrical feature of the HEALPix sampling grid is the hierarchical quadrilateral tree structure. \nThis defines a natural one-to-one mapping of the sphere sampled according to the HEALPix grid, into twelve \nflat images, on all scales. It is then easy to partition a spherical map using HEALPix into quadrilateral blocks \nof a specified size. One first extracts the twelve base-resolution faces, and each face is then decomposed into \noverlapping blocks of the specified size. This decomposition into blocks is an essential step of the traditional \nflat 2D curvelet transform. Based on the reversible warping of the sphere into a set of flat images made possible \nby the HEALPix sampling grid, the ridgelet and curvelet transforms can be extended to the sphere. \n\nWith the decomposition into blocks described above, there is no overlap between neighboring blocks belonging \nto different base-resolution faces. This may result for instance in blocking effects in denoising experiments \nvia nonlinear filtering. It is possible to overcome this difficulty in some sense by working simultaneously \nwith various rotations of the data with respect to the sampling grid. This will average out undesirable effects \nat edges between base resolution faces. \n\n\\subsubsection*{Ridgelet transform}\n\\index{ridgelet}\n\\index{ridgelet!sphere}\n\\index{sphere!ridgelet}\n\\index{Radon transform}\n\nOnce the partitioning is performed, the standard 2D ridgelet transform described in \\citep{starck:sta02_3} is applied in each individual block :\n\\begin{enumerate}\n\\item Compute the 2D Fourier transform.\n\\item Extract lines going through the origin in the frequency plane.\n\\item Compute the 1D inverse Fourier transform of each line. We get the Radon transform.\n\\item Compute the 1D wavelet transform of the lines of the Radon transform.\n\\end{enumerate}\nThe first three steps correspond to a Radon transform method called the {\\it linogram}. Other implementations of the Radon transform, such as \nthe {\\it Slant Stack Radon Transform} \\citep{cur:donoho_02}, can be used as well, as long as they offer an exact reconstruction.\n   \nFig.~\\ref{Figure:rid_sphere} shows the flowgraph of the ridgelet transform \non the sphere and Fig.~\\ref{Figure:back_rid} shows the reconstruction from a single ridgelet \ncoefficient at different scales and orientations.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\includegraphics[width=15cm]{fig_ridssr.pdf}\n% \\includegraphics[width=9.5cm,height=6cm]{fig_ridssr.pdf}\n}}\n\\caption{Ridgelet atoms on the sphere obtained by reconstruction from a few ridgelet coefficient at different scales and orientations.}\n\\label{Figure:back_rid}\n\\end{figure}\n \n \\subsection{Curvelet Transform Algorithm}\n\nThe curvelet transform algorithm on the sphere is described in \nAlgorithm \\ref{algo_curts}.\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{Curvelet Transform on the sphere.}\n\\label{algo_curts}\n{\\bf Task:} Compute the curvelet transform on the sphere of a discrete image $X$.\\\\\n{\\bf Parameters:} Image $X$ and number of scales $J$.\\\\\n{\\bf Initialization:} \n\\begin{itemize}\n\\item $B_1 = B_{\\min}$.\n\\item Compute the isotropic UWTS of $X$ with $J$ scales, get $\\{w_1,\\dots,w_J,c_J\\}$.\n\\end{itemize}\n\\For{$j=0$ to $J-2$} {\n\\begin{enumerate}[1.]\n\\item Partition the wavelet subband $w_j$ with a block size $B_j$.\n\\item Apply the digital ridgelet transform to each block; get the curvelet coefficients at scale $j$.\n\\end{enumerate}\n\\lIf{$j \\mbox{ modulo } 2 = 1$} $B_{j+1} = 2 B_{j}$,  else $B_{j+1} = B_{j}$.\n}\n{\\bf Output:} The curvelet transform on the sphere of $X$.\n\\end{algorithm}\n}\n\nThe sidelength of the localizing windows is doubled {\\em at every\nother} dyadic subband, hence maintaining the fundamental property of\nthe curvelet transform which says that elements of length about\n$2^{-j/2}$ serve for the analysis and synthesis of the $j^{\\textrm{th}}$ subband\n$[2^j, 2^{j+1}]$.  We used the default value $B_{\\min} = 16$\npixels in our implementation.  Fig.~\\ref{Figure:cur_sphere}\ngives an overview of the organization of the algorithm.\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{\n\\hbox{\n% \\includegraphics[width=9.cm,height=12cm]{fig_flowgraph_curvelet_sphere.pdf}\n\\includegraphics[width=15cm]{fig_flowgraph_curvelet_sphere.pdf}\n}}}\n\\caption{Flowgraph of the curvelet transform on the sphere.}\n\\label{Figure:cur_sphere}\n\\end{figure}\n\n\\begin{figure}\n\\vbox{\n\\centerline{\n\\hbox{\n% \\includegraphics[width=9.cm,height=12cm]{fig_back_cur_sphere.pdf}\n\\includegraphics[angle=90,width=\\textwidth]{fig_back_cur_sphere.pdf}\n}}}\n\\caption{Reconstruction from a single curvelet coefficient at different scales and orientations.}\n\\label{Figure:back_cur}\n\\end{figure}\nFig.~\\ref{Figure:back_cur} shows the backprojection of  curvelet coefficients at \ndifferent scales and orientations.\n\n\\subsection{Pyramidal Curvelet Transform on the Sphere (PCTS)}\nThe CTS is very redundant, which may be a problem for handling huge data sets such as \nPlanck data (see Section \\ref{section:cmb} below). \nThe redundancy can be reduced by substituting, in the \ncurvelet transform algorithm, the pyramidal wavelet transform with the undecimated wavelet transform.\nThe second step which consists of applying the ridgelet transform on the wavelet scale is unchanged.\nThe pyramidal curvelet transform (PCTS) algorithm is summarized in Algorithm~\\ref{algo_pcurts}.\n\\index{sphere!pyramidal curvelet}\n\n{\\linespread{1}\n\\begin{algorithm}[h]\n\\caption{Pyramidal Curvelet Transform on the sphere.}\n\\label{algo_pcurts}\n{\\bf Task:} Compute the pyramidal curvelet transform on the sphere of a discrete image $X$.\\\\\n{\\bf Parameters:} Image $X$ and number of scales $J$.\\\\\n{\\bf Initialization:} \n\\begin{itemize}\n\\item $B_1 = B_{\\min}$.\n\\item Compute the pyramidal wavelet transform of $X$ with $J$ scales, get $\\{w_1,\\dots,w_J,c_J\\}$.\n\\end{itemize}\n\\For{$j=0$ to $J-2$} {\n\\begin{enumerate}[1.]\n\\item Partition the wavelet subband $w_j$ with a block size $B_j$.\n\\item Apply the digital ridgelet transform to each block; get the curvelet coefficients at scale $j$.\n\\end{enumerate}\n\\lIf{$j \\mbox{ modulo } 2 = 1$} $B_{j+1} = 2 B_{j}$,  else $B_{j+1} = B_{j}$.\n}\n{\\bf Output:} The pyramidal curvelet transform on the sphere of $X$.\n\\end{algorithm}\n}\n\n% In the next section, it is shown how the pyramidal curvelet transform can be used for image filtering.\n ", "meta": {"hexsha": "61d3664c088c8a70b7996b58c64e1f9032cef647", "size": 44313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/multiscale.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_isap/multiscale.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_isap/multiscale.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": 50.4129692833, "max_line_length": 536, "alphanum_fraction": 0.7289057387, "num_tokens": 13990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284992, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6271558495263148}}
{"text": "%% -*- coding:utf-8 -*-\n\\chapter{Generalities on algebraic extensions}\nWe introduce the basic notions such as a field extension, algebraic\nelement, minimal polynomial, finite extension, and study their very\nbasic properties such as the multiplicativity of degree in towers. \n\n\\section{Field extensions: examples}\n\n\\subsection{K-algebra}\n\\begin{definition}[K-algebra]\n  \\label{def:kalgebra}\n  Let $K$ is a \\mynameref{def:ring} and $A$ is a\n  \\mynameref{def:module} over $K$ \n  \\footnote{\n    The definition in the lectures is more common and assumes that $K$\n    is a ring but later $K$ will be mostly a \\mynameref{def:field}. Therefore\n    $A$ has to be a \\mynameref{def:vectorspace} over $K$ in the case. \n  }\n  equipped with \n  an additional binary operation $A \\times A \\rightarrow A$ that we\n  denote as $\\cdot$ here. The $A$ is an algebra over $K$ if the\n  following identities hold $\\forall x,y,z \\in A$ and for every\n  elements (often called as scalar) $a, b \\in K$\n  \\begin{itemize}\n  \\item Right distributivity:\n    $(x + y) \\cdot z = x \\cdot z + y \\cdot z$\n  \\item Left distributivity:\n    $z \\cdot (x + y) = z \\cdot x + z \\cdot y$\n  \\item Compatibility with scalars:\n    $(ax) \\cdot (by) = (ab) (x \\cdot y)$\n  \\end{itemize}\n\\end{definition}\n\n\\begin{example}[Field of complex numbers $\\mathbb{C}$]\n  The field of complex numbers $\\mathbb{C}$ can be considered as a\n  K-algebra over the field of real numbers $\\mathbb{R}$.\n  \\label{ex:complexnumbers}\n\\end{example}\n\n\\subsection{Field extension}\n\n\\begin{definition}[Field extension]\n  Let $K$ and $L$ are fields.\n  $L$ is an extension of $K$ if $L \\supset K$\n  \\label{def:fextension1}\n\\end{definition}\nand another definition\n\\begin{definition}[Field extension]\n  Let $K$ is a field then\n  $L$ is an extension of $K$ if $L$ is a K-algebra\n  \\footnote{\n    $L$ in the definition is not the same object with $L$ from\n    definition \\ref{def:fextension1}. Because $L$ in the definition is\n    a $K$-algebra i.e. a ring but $L$ in the definition\n    \\ref{def:fextension1} is a field. \n  }\n  \\label{def:fextension2}\n\\end{definition}\nWhy the 2 definitions are equivalent?\n\n\\begin{lemma}[K-algebra and homomorphism]\n  Given a K-algebra is the same as\n  having \\mynameref{def:homomorphism} $f: K \\rightarrow A$ of rings.\n  \\begin{proof}\n    Really if I have a K-algebra I can define the\n    \\mynameref{def:homomorphism} $f(k) = k \\cdot 1_A$, where $1_A$ is an\n    identity element of $A$. Thus $k \\cdot 1_A \\in A$.\n\n    And conversely if I have the \\mynameref{def:homomorphism}\n    $f: K \\rightarrow A$\n    I can define the K-algebra structure by setting\n    $k a = f(k) a$ because $f(k), a \\in A$ and there is a multiplication\n    defined on $A$. As result I have a rule for multiplication a vector\n    ($f(k) \\in A$) on a vector ($a \\in A$) that is required for\n    \\mynameref{def:kalgebra} setup.\n  \\end{proof}\n  \\label{lem:lec1_homkalgebra}\n\\end{lemma}\n\n\\begin{lemma}[About homomorphism of fields]\n  Any \\mynameref{def:fieldhomomorphism} is\n  \\mynameref{def:injection}.\n  \\footnote{\n    But the statement is not valid for groups. In that case the\n    homomorphism is injection if and only if the \n    kernel is trivial and consists of only one element - identity.\n    See theorem \\ref{thm:grouphomomorphsim}.\n  }\n  \\label{lem:lec1_homomorphism_is_injection}\n  \\begin{proof}\n    Lets proof by contradiction.\n    Really if $f(x) = f(y)$ and $x \\ne y$ then\n    \\begin{eqnarray}\n      f(x) - f(y) = 0_A,\n      \\nonumber \\\\\n      f(x - y) = 0_A,\n      \\nonumber \\\\\n      f(x - y) f(\\left(x - y\\right)^{-1}) =\n      f\\left(\\frac{x - y}{x - y}\\right) = f(1_K) = 1_A = 0_A\n      \\nonumber\n    \\end{eqnarray}\n    that is impossible.\n  \\end{proof}  \n\\end{lemma}\n\nThere are some comments on the results. We have got that a\n\\mynameref{def:homomorphism} can be set between field $K$ and its\nK-algebra.\nThe \\mynameref{def:homomorphism} is \\mynameref{def:injection}\ntherefore we can allocate a sub-field $A' \\subset A$ for that we will\nhave the \\mynameref{def:homomorphism} is a \\mynameref{def:surjection} and\ntherefore we have an \\mynameref{def:isomorphism} between original field $K$\nand a sub-field $A'$. This means that we can say that the original\nfield $K$ is a sub-field for the K-algebra.\n\n\\begin{example}[Field extensions]\n  $\\mathbb{C}$ is a field extension for $\\mathbb{R}$.\n  $\\mathbb{R}$ is a field extension for $\\mathbb{Q}$\n  \\label{ex:fieldextension}\n\\end{example}\n\n\\begin{example}[$K$-algebra is not a field]\n  In the example\n  \\footnote{the example was not present in the lectures}\n  I will show\n  that $K$ algebra is not a field. Consider\n  $K = \\mathbb{R}$. \\mynameref{def:vectorspace} $A = \\mathbb{R}^2$ i.e.\n  $A$ consists of vectors of the following form\n  \\[\n  x = \\left(\n  \\begin{array}{c}\n    x_1 \\\\\n    x_2\n  \\end{array}\n  \\right),\n  \\]\n  where $x_1, x_2 \\in \\mathbb{R}$.\n  I will define the multiplication for $L$ (our $K$ algebra) as\n  follows\n  \\[\n  \\left(\n  \\begin{array}{c}\n    x_1 \\\\\n    x_2\n  \\end{array}\n  \\right)\n  \\cdot\n  \\left(\n  \\begin{array}{c}\n    y_1 \\\\\n    y_2\n  \\end{array}\n  \\right) =\n  \\left(\n  \\begin{array}{c}\n    x_1 \\cdot y_1 \\\\\n    x_2 \\cdot y_2\n  \\end{array}\n  \\right)\n  \\]\n\n  It can be seen that all requirements of \\mynameref{def:kalgebra} are\n  satisfied\n  \\begin{eqnarray}\n    (x + y) \\cdot z =\n    \\left(\n    \\left(\n    \\begin{array}{c}\n      x_1 \\\\\n      x_2\n    \\end{array}\n    \\right)\n    +\n    \\left(\n    \\begin{array}{c}\n      y_1 \\\\\n      y_2\n    \\end{array}\n    \\right)\n    \\right)\n    \\left(\n    \\begin{array}{c}\n      z_1 \\\\\n      z_2\n    \\end{array}\n    \\right) =\n    \\nonumber \\\\\n    =\n    \\left(\n    \\begin{array}{c}\n      (x_1 + y_1)z_1 \\\\\n      (x_2 + y_2)z_2\n    \\end{array}\n    \\right) =\n    \\left(\n    \\begin{array}{c}\n      x_1 z_1 + y_1 z_1 \\\\\n      x_2 z_2 + y_2 z_2\n    \\end{array}\n    \\right) =\n    x \\cdot z + y \\cdot z\n    \\nonumber \\\\\n    z \\cdot (x + y) = z \\cdot x + z \\cdot y\n    \\nonumber \\\\\n    (ax) \\cdot (by) =\n    \\left(\n    \\begin{array}{c}\n      a x_1 \\\\\n      a x_2\n    \\end{array}\n    \\right)\n    \\left(\n    \\begin{array}{c}\n      b y_1 \\\\\n      b y_2\n    \\end{array}\n    \\right) =\n    \\left(\n    \\begin{array}{c}\n      ab x_1 y_1 \\\\\n      ab x_2 y_2\n    \\end{array}\n    \\right)\n    (ab) (x \\cdot y)\n    \\nonumber\n  \\end{eqnarray}\n  The multiplication identity element of $L$ is the following\n  \\[\n  1_L = \n  \\left(\n  \\begin{array}{c}\n    1 \\\\\n    1\n  \\end{array}\n  \\right)\n  \\]\n  The zero is the standard one from vector space\n  \\[\n  0_L = \n  \\left(\n  \\begin{array}{c}\n    0 \\\\\n    0\n  \\end{array}\n  \\right)\n  \\]\n\n  We can see that\n  \\[\n  \\left(\n  \\begin{array}{c}\n    1 \\\\\n    0\n  \\end{array}\n  \\right)\n  \\left(\n  \\begin{array}{c}\n    0 \\\\\n    1\n  \\end{array}\n  \\right) = 0_L\n  \\]\n  i.e. we have 2 divisor of zero which are not zero itself. The\n  elements do not have invert ones and as result the $L$ is\n  not a field.\n\n  From other side if we define $L' \\subset L$ as follows\n  $L' = \\left\\{\n  \\left(\n  \\begin{array}{c}\n    r \\\\\n    r\n  \\end{array}\n  \\right)\n  \\right\\}$, where $r \\in \\mathbb{R}$,\n  then we will have that $L'$ is a field and $L' \\cong \\mathbb{R}$.\n  \\label{ex:kalgebranotfield}\n\\end{example}\n\n\\begin{definition}[Characteristic]\n  \\label{def:fieldcharacteristic}\n  If $L$ is a field there are 2 possibilities\n  \\begin{enumerate}\n  \\item $1 + 1 + \\dots \\ne 0$. In this case\n    $\\mathbb{Z} \\subset L$ but $\\mathbb{Z}$ is not a field therefore $L$\n    is an extension of $\\mathbb{Q}$. In the case $char L = 0$\n  \\item $1 + 1 + \\dots + 1 = \\sum_{i = 1}^m 1 = 0$ for some $m \\in\n    \\mathbb{Z}$. The first time when it happens is for a prime number\n    i.e. minimal $m$ with the property is prime. In this case $char L\n    = p$, where $p = \\min m$  - the minimal $m$ (prime) with the\n    property. In this \n    case $\\mathbb{Z}/p\\mathbb{Z} \\subset L$. The\n    $\\mathbb{Z}/p\\mathbb{Z}$ is a field denoted by $\\mathbb{F}_p$. The\n    $L$ is an extension of $\\mathbb{F}_p$.\n  \\end{enumerate}\n  No other possibilities exist. The $\\mathbb{Q}$ and $\\mathbb{F}_p$ are\n  the prime fields. Any field is an extension of one of those.\n\\end{definition}\n\n\\begin{definition}[Prime field]\n  \\label{def:primefield}\n  If $L$ is a field $\\mathbb{Q} \\subset L$, i.e. $char L = 0$ then\n  $\\mathbb{Q}$ is the prime field for $L$. Otherwise, if $char L = p > 0$\n  then $\\mathbb{F}_p$ is the prime field.\n\\end{definition}\n\n\\begin{claim}\n\\label{claim:lec1_sec14}\nLet $K\\left[X\\right]$ \\mynameref{def:ring} of polynomials.\nThe $P \\in K\\left[X\\right]$ is an\n\\mynameref{def:irreducible}. $\\left(P\\right)$ is an \n\\mynameref{def:ideal} formed by the polynomial.\n\\footnote{\n  I.e.\n  \\(\n  \\left(P\\right) = \\left\\{ Q = G P \\right\\} \n  \\)\n  where $G \\in K\\left[X\\right]$\n}\nThe set of residues by\nthe polynomial forms a field that denoted by\n$K\\left[X\\right]/\\left(P\\right)$.\n\\begin{proof}\nHow we can see it?\nIf $Q \\in K\\left[X\\right]$ is a polynomial that $Q \\notin\n\\left(P\\right)$ when $Q$ is prime to $P$.\n\\footnote{\n  As soon as $P$ is irreducible in $K\\left[X\\right]$ then there is only\n  one possibility for $Q$ and $P$ to have common divisors: if $Q = G P$\n  where $G \\in K\\left[X\\right]$ but this is in contradiction with\n  $Q \\notin \\left(P\\right)$\n}\nThen with\n\\mynameref{lem:bezout} we can get $\\exists A, B \\in K\\left[X\\right]$\nsuch that\n\\[\nA P + B Q = 1,\n\\]\nor\n\\[\nB Q \\equiv 1 \\mod P,\n\\]\nthus $B$ is $Q^{-1}$ in $K\\left[X\\right]/\\left(P\\right)$.\n\\end{proof}\n\\end{claim}\n\n\\begin{claim}\n  \\footnote{\n    The claim is not a part of the lectures but it's very usefully in\n    future lectures.\n  }\n  Let $K$ is a field and $a \\in K$ then $K\\left[X\\right]/\\left(X -\n  a\\right)$ is also a field and there exists an\n  \\mynameref{def:isomorphism} between the field and $K$ i.e.\n  \\begin{equation}\n    K\\left[X\\right]/\\left(X - a\\right) \\cong K\n    \\label{eq:lec1_ex1_1}\n  \\end{equation}\n  \\label{claim:lec1_fieldquotionisomorphism}\n  \\begin{proof}\n    The $K\\left[X\\right]/\\left(X - a\\right)$ is a field just because\n    $X-a$ is\n    \\mynameref{def:irreducible} (see example \\ref{ex:irreducible} and\n    claim \\ref{claim:lec1_sec14}).\n\n    For the proof the main statement (\\ref{eq:lec1_ex1_1}) lets consider a\n    polynomial $P \\in  K\\left[X\\right]$ and \n    define the following \\mynameref{def:fieldhomomorphism}:\n    \\begin{equation}\n      \\phi: K\\left[X\\right]/\\left(X - a\\right)\n      \\xrightarrow[P(X) \\to P(a)]{} K\n      \\label{eq:lec1_ex1_2}\n    \\end{equation}\n\n    The $\\phi$ defined by (\\ref{eq:lec1_ex1_2}) is\n    \\mynameref{def:fieldhomomorphism}. For the proof of the claim lets take\n    $P_1, P_2 \\in K\\left[X\\right]/\\left(X - a\\right)$. Clear that\n    \\[\n    \\phi\\left(P_1 + P_2\\right) = P_1\\left(a\\right) + P_2\\left(a\\right)\n    = \\phi\\left(P_1\\right) + \\phi\\left(P_1\\right).\n    \\]\n    The same holds with the multiplication:\n    \\[\n    \\phi\\left(P_1 \\cdot P_2\\right) = P_1\\left(a\\right) \\cdot P_2\\left(a\\right)\n    = \\phi\\left(P_1\\right) \\cdot \\phi\\left(P_1\\right).\n    \\]\n    %% For the inverse element image lets consider $P \\in\n    %% K\\left[X\\right]/\\left(X - a\\right)$ such that $P \\ne 0$ and as\n    %% result $\\phi\\left(P\\right) = P\\left(a\\right) \\ne 0$.\n    %% There exists $P^{-1} \\in K\\left[X\\right]/\\left(X - a\\right)$ as\n    %% soon as $K\\left[X\\right]/\\left(X - a\\right)$ is a field. Therefore\n    %% we have\n    %% \\begin{eqnarray}\n    %%   \\phi(1) = \\phi\\left(P P^{-1}\\right) =\n    %%   \\phi\\left(P\\right)\\phi\\left(P^{-1}\\right) =\n    %%   \\nonumber \\\\\n    %%   = P\\left(a\\right) P^{-1}\\left(a\\right) = 1,\n    %%   \\nonumber\n    %% \\end{eqnarray}\n    %% i.e.\n    %% \\[\n    %% \\phi\\left(P^{-1}\\right) = \\phi\\left(P\\right)^{-1}.\n    %% \\]\n    That completes the proof of the \\mynameref{def:fieldhomomorphism}.\n    %% Division is more complex but also can be\n    %% shown: if $P_2 \\ne 0$ when there exists\n    %% $P_2^{-1} \\in K\\left[X\\right]/\\left(X - a\\right)$ as soon as\n    %% $K\\left[X\\right]/\\left(X - a\\right)$ is the field then\n    %% with $\\phi\\left(P_2^{-1}\\right) = P_2^{-1}\\left(a\\right) =\n    %% \\frac{1}{\\phi\\left(P_2\\right)}$ one can get\n    %% \\[\n    %% \\phi\\left(\\frac{P_1}{P_2}\\right) =\n    %% \\phi\\left(P_1 P_2^{-1}\\right) =\n    %% \\phi\\left(P_1\\right) \\phi\\left(P_2^{-1}\\right) =\n    %% \\frac{\\phi\\left(P_1\\right)}{\\phi\\left(P_2\\right)}\n    %% \\]\n\n    %% We have $\\ker{\\phi} = \\left(X - a\\right)$ because for any polynomial\n    %% $P$ that is in the ideal $\\left(X - a\\right)$ has $P(a) = 0$ i.e. in\n    %% the kernel of $\\phi$.\n\n    Lemma \\mynameref{lem:lec1_homomorphism_is_injection} says that any\n    \\mynameref{def:fieldhomomorphism} is \\mynameref{def:injection},\n    i.e. $\\phi$ is an injection.\n    \n    Next we should show that $\\phi$ is \\mynameref{def:surjection} it's\n    easy because $\\forall k \\in K$ we can consider constant polynomial\n    $P = k$ from $K\\left[X\\right]$. For the polynomial we will have\n    $\\phi\\left(k\\right) = k$.\n\n    As result $\\phi$ is \\mynameref{def:injection} as well as\n    \\mynameref{def:surjection} i.e. $\\phi$ is\n    \\mynameref{def:bijection}. With the fact that $\\phi$ is\n    \\mynameref{def:homomorphism} it will gives us that $\\phi$ is\n    \\mynameref{def:isomorphism}. \n    %% Now (\\ref{eq:lec1_ex1_1}) follows from the\n    %% \\mynameref{thm:firstisomorphism}. \n  \\end{proof}\n\\end{claim}\n\n\\section{Algebraic elements. Minimal polynomial}\n\n\\subsection{$K\\left[X\\right]/\\left(P\\right)$ field}\n\nAlternative proof of claim \\ref{claim:lec1_sec14} i.e. the fact that\n$K\\left[X\\right]/\\left(P\\right)$ is the \n\\mynameref{def:field} as follows.\nThe $\\left(P\\right)$ is a \\mynameref{def:maxideal}\n\\footnote{\n  To prove that $\\left(P\\right)$ is a \\mynameref{def:maxideal} we have\n  to use \\mynameref{lem:bezout}.\n}\nbut a quotient by a  \\mynameref{def:maxideal} is a \\mynameref{def:field}\n(see \\mynameref{thm:maxideal}).\n\nWe also can say that $K\\left[X\\right]/\\left(P\\right)$ is an extension\nof $K$ because it's \n\\mynameref{def:kalgebra}.\n\n\\begin{example}[$K = \\mathbb{F}_2/\\left(X^2+X+1\\right)$]\n  Lets consider the following field\n  $\\mathbb{F}_2 = \\mathbb{Z}/2\\mathbb{Z} = \\{0,1\\}$ in the\n  field polynomial $X^2+X+1$ is irreducible. It's very easy to verify\n  it because $\\mathbb{F}_2$ has only 2 elements that can be (possible)\n  a root:\n  \\[\n  0^2+0+1 = 1\\ne 0\n  \\]\n  and\n  \\[\n  1^2+1+1 = 1\\ne 0\n  \\]\n  \n  The polynomial has the following\n  residues: $\\bar{X} = X + \\left(X^2+X+1\\right)$ and\n  $\\overline{X + 1} = X + 1 + \\left(X^2+X+1\\right)$. Thus the field\n  $\\mathbb{F}_2/\\left(X^2+X+1\\right)$ consists of 4 elements:\n  $\\{0, 1, \\bar{X}, \\overline{X+1}\\}$.\n\n  It's easy to see that the third element ($\\bar{X}$) is a root of\n  $P(X) = X^2+X+1$:\n  \\[\n  \\bar{X}^2 + \\bar{X} + 1 =\n  P(X) + \\left(P(X)\\right) = \\left(P(X)\\right) \\equiv 0 \\mod P.\n  \\]\n  \n  \\[\n  \\bar{X}^2 + \\bar{X} + 1 = \\bar{0},\n  \\]\n  therefore \n  \\[\n  \\bar{X}^2 = - \\bar{X} - 1 = \\bar{X} + 1 = \\overline{X+1}.\n  \\]\n  This is because we are in field $\\mathbb{F}_2$ where\n  \\[\n  2 \\left(X + 1\\right) \\mod 2 = 0 \n  \\]\n  and thus\n  \\[\n  - \\bar{X} - 1 = \\bar{X} + 1 = \\overline{X + 1}\n  \\]\n  \n  Also\n  \\[\n  \\overline{X+1}^2 = \\bar{X},\n  \\]\n  and they are inverse each other\n  \\[\n  \\overline{X+1} \\bar{X} = 1,\n  \\]\n\n  So this is the structure of a field of four elements.  The\n  cardinality of $K=\\mathbb{F}_2/\\left(X^2+X+1\\right)$ is 4,  one\n  writes then $K=F_4$. Well, this might be \n  strange at the first sight, because we only know that $K$ has four\n  elements and if you write $F_4$  you somehow mean that there is only\n  one field of four elements. Well, it is true, there is only one\n  field of four elements. In fact, all finite fields of the same\n  cardinality are isomorphic, and we will see it very shortly\n  (see theorem \\ref{thm:lec3_1}).  \n  \\label{ex:F2overP}\n\\end{example}\n\nArguments for the \\autoref{ex:F2overP} can also be found in the\nfollowing remark (not part of the lectures)\n\\begin{remark}[About quotient field]\nConsider an arbitrary field $L$ ($L=\\mathbb{F}_2$ at the\n\\autoref{ex:F2overP}) and $P\\left(X\\right) = X^n + a_{n-1}X^{n-1} +\na_{n-2} X^{n-2} + \\dots + a_0 \\in L\\left[X\\right]$ is an\nirreducible polynomial over $L$. Let $\\alpha$ is a root of the\npolynomial then \n\\[\n\\alpha^n + a_{n-1} \\alpha^{n-1} + \\dots + a_0 = 0,\n\\]\nor\n\\[\n\\alpha^n = - a_{n-1} \\alpha^{n-1} - \\dots - a_0.\n\\]\nTherefore $\\forall l \\ge n, \\exists l_i \\in L$ such that \n\\[\n\\alpha^k = \\sum_{i=0}^{n-1}l_i \\alpha^{i}\n\\]\nand as result $\\forall x \\in L/\\left(P\\right)$ exists $x_i \\in L$\nsuch that \n\\[\nx = \\sum_{i=0}^{n-1}x_i \\alpha^{i}.\n\\]\nWe can say that we have the following basis: $\\{\\{L\\}, \\alpha, \\dots,\n\\alpha^{n-1}\\}$ where $\\{L\\}$ - L basis. For \\autoref{ex:F2overP} we\nhave\n$\\{L\\}= \\{\\mathbb{F}_2\\}= \\{0,1\\}$, $\\alpha = \\bar{X}$ and as result\n$K = \\mathbb{F}_2/\\left(X^2+X+1\\right)$ will have the following basis\n$\\{0,1,\\bar{X}\\}$.\n\\end{remark}\n\n\\subsection{Algebraic elements}\n\n\\begin{definition}[Algebraic element]\n  Let $K \\subset L$ and $\\alpha \\in L$. $\\alpha$ is an algebraic\n  element if $\\exists P \\in K\\left[X\\right]$ such that\n  $P\\left(\\alpha\\right) = 0$. Otherwise the $\\alpha$ is called\n  transcendental.\n  \\label{def:algebraicelement}\n\\end{definition}\n\n\\subsection{Minimal polynomial}\n\n\\begin{lemma}[About minimal polynomial existence]\n  If $\\alpha$ is \\mynameref{def:algebraicelement} then\n  $\\exists!$ unitary polynomial $P$ of minimal degree such that\n  $P\\left(\\alpha\\right) = 0$. It is irreducible. $\\forall Q$ such that\n  $Q\\left(\\alpha\\right) = 0$ is divisible by $P$\n  \\footnote{\n    see also \\mynameref{thm:irreduciblediv}\n  }\n  \\begin{proof}\n    We know that $K\\left[X\\right]$ is a \\mynameref{def:pid} and a\n    polynomial $Q\\left(\\alpha\\right) = 0$ forms an\n    \\mynameref{def:ideal}: $I \\left\\{Q \\in K\\left[X\\right] \\mid\n    Q\\left(\\alpha\\right) = 0 \\right\\}$, so the ideal is generated by\n    one element: $I = \\left(P\\right)$. This is an unique (up to\n    constant) polynomial minimal degree in $I$.\n    \n    Lets prove that $P$ is irreducible. If $P$ is not irreducible then\n    $\\exists Q,R \\in I$ such that $P = Q \n    R$, $Q(\\alpha) = 0$ or $R(\\alpha) = 0$ and\n    $deg R,Q < deg P$ that is in contradiction with the definition\n    that $P$ is a polynomial of minimal degree.    \n  \\end{proof}\n  \\label{lem:minpolynomial}\n\\end{lemma}\n\n\\begin{definition}[Minimal polynomial]\n  If $\\alpha$ is \\mynameref{def:algebraicelement} then\n  the unitary polynomial $P$ of minimal degree such that\n  $P\\left(\\alpha\\right) = 0$ is called minimal polynomial and denoted\n  by  $P_{min}\\left(\\alpha, K\\right)$.\n  \\label{def:minpolynomial}\n\\end{definition}\n\n\\begin{gapexample}[Minimal polynomial]\n  Consider the following minimal polynomial\n  $P_{min}\\left(\\alpha, \\mathbb{Q}\\right)$, where $\\alpha =\n  \\sqrt{2}$. In GAP \\cite{url:gap} we have\n\\begin{verbatim}\n  gap> x:=Indeterminate(Rationals,\"x\");;\n  gap> alpha:=Sqrt(2);;\n  gap> MinimalPolynomial(Rationals, alpha);\n  x^2-2\n\\end{verbatim}\nI.e. $P_{min}\\left(\\alpha, \\mathbb{Q}\\right) = X^2 -2$.\n\\label{ex:minpolynomial}\n\\end{gapexample}\n\n\\section{Algebraic elements. Algebraic extensions}\n\n\\begin{definition}\n  Let $K \\subset L$, $\\alpha \\in L$. The smallest sub-field contained\n  $K$ and $\\alpha$ denoted by $K\\left(\\alpha\\right)$. The smallest\n  sub-ring (or \\mynameref{def:kalgebra}) contained $K$ and $\\alpha$ denoted by $K\\left[\\alpha\\right]$.\n\\end{definition}\n\nAs soon as $K\\left[\\alpha\\right]$ is a \\mynameref{def:kalgebra} it is a\n\\mynameref{def:vectorspace} over $K$ generated by\n\\[\n1, \\alpha, \\alpha^2, \\dots,\n\\alpha^n, \\dots.\n\\]\n\n\\begin{example}[$\\mathbb{C}$]\n  \\[\n  \\mathbb{C} = \\mathbb{R}\\left(i\\right) = \\mathbb{R}\\left[i\\right]\n  \\]\n  $\\mathbb{C}$ is also a \\mynameref{def:vectorspace} generated by $1$\n  and $i$: $\\forall z \\in \\mathbb{Z}$ it holds $z = x + i y$ where\n  $x,y \\in \\mathbb{R}$.\n\\end{example}\n\n\\begin{proposition}\n  The following assignment are equivalent\n  \\begin{enumerate}\n  \\item $\\alpha$ is algebraic over $K$\n  \\item $K\\left[\\alpha\\right]$ is a finite dimensional\n    \\mynameref{def:vectorspace} over $K$\n  \\item $K\\left[\\alpha\\right] = K\\left(\\alpha\\right)$\n    \\footnote{\n      Contrary to the example \\ref{ex:kalgebranotfield} we see\n      that $K$-algebra is a field there.\n    }\n  \\end{enumerate}\n  \\begin{proof}\n    Lets proof that 1 implies 2. If $\\alpha$ is algebraic over $K$\n    then using lemma \\mynameref{def:minpolynomial} $\\exists\n    P_{min}\\left(\\alpha, K\\right)$:\n    \\[\n    P_{min}\\left(\\alpha, K\\right) = \\alpha^d + a_{d-1}\\alpha^{d-1} +\n    a_1 \\alpha + a_0 = 0,\n    \\]\n    where $a_k \\in K$. Then\n    \\[\n    \\alpha^d  = - a_{d-1}\\alpha^{d-1} -\n    a_1 \\alpha - a_0\n    \\]\n    this means that any $\\alpha^n$ can be represented as a linear\n    combination of finite number of powers of $\\alpha$ i.e.\n    $K\\left[\\alpha\\right]$ generated by $1, \\alpha, \\dots,\n    \\alpha^{d-1}$ is a finite dimensional \\mynameref{def:vectorspace}.\n\n    Lets proof that 2 implies 3. Its enough to prove that\n    $K\\left[\\alpha\\right]$ is a field because\n    $K\\left[\\alpha\\right] \\subset K\\left(\\alpha\\right)$.\n    \n    Let $x \\ne 0 \\in\n    K\\left[\\alpha\\right]$ then lets look at an operation\n    $x \\cdot K\\left[\\alpha\\right] \\rightarrow\n    K\\left[\\alpha\\right]$. This is \\mynameref{def:injection}.\n    \\footnote{\n      If $y, z \\in K\\left[\\alpha\\right]$ and\n      $\\dim K\\left[\\alpha\\right] = d < \\infty$ where\n      $d = \\deg P_{min}\\left(\\alpha, K\\right)$. Then\n      $y = \\sum_{i=0}^{d-1} y_i \\alpha^i$ and\n      $z = \\sum_{i=0}^{d-1} z_i \\alpha^i$ where $y_i, z_i \\in K$.\n      We have $y - z = \\sum_{i=0}^{d-1} \\left(y_i - z_i\\right)\n      \\alpha^i \\ne 0$ if $y \\ne z$ (i.e.\n      $\\exists i: y_i \\ne z_i$)\n      because $y -z$ can be considered as a polynomial of degree\n      $ \\le d - 1 < \\deg P_{min}\\left(\\alpha, K\\right)$ and cannot be equal\n      to 0 by minimal polynomial definition.\n      Continue we have $x \\cdot \\left(y - z\\right) \\ne 0$ because it\n      also can be considered as a product of 2 polynomial of degree\n      $< d$. \n      Thus\n      \\[\n      x \\cdot y  \\ne x \\cdot z\n      \\]\n      i.e. \\mynameref{def:injection} property is satisfied.\n    }\n    But the $K\\left[\\alpha\\right]$ is finite dimensional\n    \\mynameref{def:vectorspace} and a \\mynameref{def:homomorphism} between\n    2 vector spaces with the same dimension is\n    \\mynameref{def:surjection}\n    \\footnote{\n      Two vector spaces with same dimension are isomorphic each other\n      (see lemma \\ref{lem:vsisomorphism})\n    }\n    thus $\\exists y \\in K\\left[\\alpha\\right]$\n    such that $x \\cdot y = 1_{K\\left[\\alpha\\right]}$. Therefore $x$ is\n    invertable and $K\\left[\\alpha\\right]$ is a\n    \\mynameref{def:field}.\n\n    Lets proof that 3 implies 1. Let $K\\left[\\alpha\\right]$ is a\n    \\mynameref{def:field} but $\\alpha$ is not algebraic. Thus $\\forall P\n    \\in K\\left[X\\right]$ $P(\\alpha) \\ne 0$. The we have an\n    \\mynameref{def:injection} \\mynameref{def:homomorphism} $i$ :\n    $K\\left[X\\right] \\to K\\left[\\alpha\\right] = K\\left(\\alpha\\right)$\n    which sends $P\\left(X\\right)$ to $P\\left(\\alpha\\right)$.\n    \\footnote{\n      And if $P\\left(X\\right) \\ne 0$ then\n      $P\\left(\\alpha\\right) \\ne 0$\n    }\n    But $K\\left[X\\right]$\n    is not a field thus $K\\left[\\alpha\\right]$ should not be a field\n    too that is in contradiction with the initial conditions.\n    \\footnote{\n      Alternative prove is the following.\n      Let $x \\ne 0 \\in K\\left[X\\right]$ and $K\\left[\\alpha\\right]$ is a\n      field then $i(x)$ is invertable i.e. $\\exists y \\in\n      K\\left[X\\right]:  i(x) i(y) = 1$ or \n      $i(xy) = 1$ or finally $x$ - is invertable and $K\\left[X\\right]$\n      is a field but $K\\left[X\\right]$ is a ring and therefore we just\n      got a contradiction. \n    }\n  \\end{proof}\n  \\label{prop:lec1_1}\n\\end{proposition}\n\n\\begin{definition}[Algebraic extension]\n  $L$ an extension of $K$ is called algebraic over $K$ if $\\forall\n  \\alpha \\in L$ - $\\alpha$ is algebraic over $K$. \n  \\label{def:algebraicextension}\n\\end{definition}\n\n\\begin{proposition}\n  If $L$ is algebraic over $K$ then any K-subalgebra of $L$ is a\n  \\mynameref{def:field}.\n  \\begin{proof}\n    Let $L' \\subset L$ is a subalgebra and let $\\alpha \\in L'$. We want\n    to show that $\\alpha$ is invertable. $\\alpha$ is algebraic\n    therefore $\\alpha \\in K\\left[\\alpha\\right] \\subset L' \\subset L$\n    and it's invertable.\n    \\footnote{\n      As soon as $K\\left[\\alpha\\right] = K\\left(\\alpha\\right)$ is a\n      field then its any element (especially $\\alpha$) is invertable. \n    }\n  \\end{proof}\n  \\label{prop:lec1_algebraicsubalgebra}\n\\end{proposition}\n\n\\begin{proposition}\n  Let $K \\subset L \\subset M$. $\\alpha \\in M$ - algebraic over $K$\n  then $\\alpha$ algebraic over $L$ and\n  $P_{min}\\left(\\alpha, L\\right)$ divides $P_{min}\\left(\\alpha,\n  K\\right)$. \n  \\begin{proof}\n    It is clear because $P_{min}\\left(\\alpha,K\\right) \\in\n    L\\left[X\\right]$.\n    \\footnote{\n      Thus $\\exists P_L \\in L\\left[X\\right]$ such that\n      $P_L\\left(\\alpha\\right) = 0$ i.e. $\\alpha$ is algebraic over $L$.\n      \n      As soon as $P_{min}\\left(\\alpha,K\\right) \\in L\\left[X\\right]$ then\n      using \\mynameref{lem:minpolynomial} one can get that\n      $P_{min}\\left(\\alpha,L\\right)$ divides\n      $P_{min}\\left(\\alpha,K\\right)$.\n    }\n  \\end{proof}\n  \\label{prop:lec1_algebraic}\n\\end{proposition}\n\nWe can consider the following example as an illustration for\nproposition \\ref{prop:lec1_algebraic}: \n\\begin{myexample}\n  $K = \\mathbb{R}, L=M=\\mathbb{C}$. $\\alpha = i \\in M$ is algebraic\n  over $K = \\mathbb{R}$ and therefore using the proposition\n  \\ref{prop:lec1_algebraic} it is\n  algebraic over $L = \\mathbb{C}$. Moreover $P_{min}(\\alpha, L) = X\n  -i$ and it divides $P_{min}(\\alpha, K) = X^2 + 1$.\n\\end{myexample}\n\n\\section{Finite extensions. Algebraicity and finiteness}\n\n\\begin{definition}[Finite extension]\n  $L$ is a finite extension of $K$ if $dim_k L < \\infty$. $dim_k L$ is\n  called as degree of $L$ over $K$ and is denoted by\n  $\\left[L:K\\right]$\n  \\label{def:finiteextension}\n\\end{definition}\n\n\\begin{theorem}[The multiplicativity formula for degrees]\n  Let $K \\subset L \\subset M$. Then $M$ is\n  \\mynameref{def:finiteextension} over $K$ if and only if\n  $M$ is \\mynameref{def:finiteextension} over $L$ and\n  $L$ is \\mynameref{def:finiteextension} over $K$. In this case\n  \\[\n  \\left[M:K\\right] = \\left[M:L\\right] \\left[L:K\\right].\n  \\]\n  \\begin{proof}\n    Let $\\left[M:K\\right] < \\infty$ but any linear independent set of\n    vectors  $\\left\\{m_1, m_2, \\dots, m_n\\right\\}$ over $L$ is also\n    linear independent over $K$ thus\n    \\[\n    \\left[M:K\\right] < \\infty \\Rightarrow \\left[M:L\\right] < \\infty\n    \\]\n    also $L$ is a vector sub space of $M$ thus if\n    $\\left[M:K\\right] < \\infty$ then $\\left[L:K\\right] < \\infty$.\n\n    Let $\\left[M:L\\right] < \\infty$ and $\\left[L:K\\right] < \\infty$\n    then we have the following basises\n    \\begin{itemize}\n    \\item $L$-basis over $M$: $\\left(e_1, e_2, \\dots, e_n\\right)$\n    \\item $K$-basis over $L$:\n      $\\left(\\varepsilon_1, \\varepsilon_2, \\dots, \\varepsilon_d\\right)$\n    \\end{itemize}\n    Lets proof that $e_i\\varepsilon_j$ forms a $K$-basis over $M$.\n    $\\forall x \\in M$:\n    \\[\n    x = \\sum_{i=1}^n a_i e_i, \n    \\]\n    where $a_i \\in L$ and can be also written as\n    \\[\n    a_i = \\sum_{j=1}^d b_{ij} \\varepsilon_j,\n    \\]\n    where $b_{ij} \\in K$.\n    Thus\n    \\[\n    x = \\sum_{i=1}^n \\sum_{j=1}^d b_{ij} \\varepsilon_j e_i, \n    \\]\n    therefore $\\varepsilon_j e_i = e_i \\varepsilon_j$ generates $M$\n    over $K$. From the other side we should check that $\\varepsilon_j\n    e_i$ linear independent system of vectors. Lets\n    \\[\n    \\sum_{i,j} c_{ij} \\varepsilon_j e_i =\n    \\sum_{i=1}^n \\left( \\sum_{j=1}^d c_{ij} \\varepsilon_j \\right) e_i,\n    \\]\n    then $\\forall i$:\n    \\[\n    \\sum_{j=1}^d c_{ij} \\varepsilon_j = 0.\n    \\]\n    Thus $\\forall i,j: c_{ik} = 0$ that finishes the proof the linear\n    independence.   \n    The number of linear independent vectors is $n \\times d$ i.e.\n    \\[\n    \\left[M:K\\right] = \\left[M:L\\right] \\left[L:K\\right].\n    \\]\n  \\end{proof}\n  \\label{thm:mulformuladegrees}\n\\end{theorem}\n\n\\begin{definition}[$K\\left(\\alpha_1, \\dots, \\alpha_n\\right)$]\n  $K\\left(\\alpha_1, \\dots, \\alpha_n\\right) \\subset L$ generated by\n  $\\alpha_1, \\dots, \\alpha_n$ is the smallest sub field of $L$\n  contained  $K$ and $\\alpha_i \\in L$.\n\\end{definition}\n\n\\begin{theorem}[About towers]\n  $L$ is finite over $K$ if and only if $L$ is generated by a finite\n  number of algebraic elements over $K$.\n  \\begin{proof}\n    If $L$ is finite then $\\alpha_1, \\dots, \\alpha_d$ is a basis. In\n    this case\n    $L = K\\left[\\alpha_1, \\dots, \\alpha_d\\right] = K\\left(\\alpha_1,\n    \\dots, \\alpha_d\\right)$. Moreover each\n    $K\\left[\\alpha_i\\right]$ is finite dimensional thus by\n    proposition \\ref{prop:lec1_1} $\\alpha_i$ is algebraic.\n\n    From other side if we have a finite set of algebraic elements\n    $\\alpha_1, \\dots, \\alpha_d$ then\n    $K\\left[\\alpha_1\\right]$ is a finite dimensional\n    \\mynameref{def:vectorspace} over $K$,\n    $K\\left[\\alpha_1, \\alpha_2\\right]$ is a finite dimensional\n    \\mynameref{def:vectorspace} over $K\\left[\\alpha_1\\right]$ and\n    so on $K\\left[\\alpha_1, \\dots, \\alpha_d\\right]$ is a finite dimensional\n    \\mynameref{def:vectorspace} over\n    $K\\left[\\alpha_1, \\dots, \\alpha_{d-1}\\right]$. All elements\n    are algebraic thus\n    \\[\n    K\\left[\\alpha_1, \\dots, \\alpha_i\\right] =\n    K\\left(\\alpha_1, \\dots, \\alpha_i\\right)\n    \\]\n    Then using theorem \\ref{thm:mulformuladegrees} we can conclude\n    that $K\\left(\\alpha_1, \\dots, \\alpha_d\\right)$ has finite\n    dimension. \n  \\end{proof}\n  \\label{thm:lec1_2}\n\\end{theorem}\n\n\\section{Algebraicity in towers. An example}\n\n\\begin{theorem}\n  $K \\subset L \\subset M$ then $M$ \\mynameref{def:algebraicextension}\n  over $K$ if and only if $M$ algebraic over $L$ and $L$ algebraic\n  over $K$. \n  \\begin{proof}\n    If $\\alpha \\in M$ is an \\mynameref{def:algebraicelement} over $K$ then\n    $\\exists P \\in K\\left[X\\right]$ such that\n    $P\\left(\\alpha\\right) = 0$ but the\n    polynomial $P \\in K\\left[X\\right] \\subset L\\left[X\\right]$\n    thus $\\alpha$ is algebraic over $L$.\n    If $\\alpha \\in L \\subset M$ then $\\alpha$ is algebraic over $K$\n    thus $L$ is algebraic over $K$.\n\n    Let $M$ algebraic over $L$ and $L$ algebraic over $K$ and let\n    $\\alpha \\in M$. We want to prove that $\\alpha$ is algebraic over\n    $K$. Lets consider $P_{min}\\left(\\alpha, L\\right)$ the polynomial\n    coefficients are from $L$ and they (as soon as they count is a\n    finite)  generate a finite extension $E$ over $K$ thus\n    $E\\left(\\alpha\\right)$ is finite over $E$ (exists a relation\n    between powers of $\\alpha$) is finite over $K$ thus $\\alpha$ is\n    algebraic over $K$.\n    \\footnote{\n      $P_{min}\\left(\\alpha, L\\right) = \\sum_{i = 0}^{d-1} l_i\n      \\alpha^i$ where $l_i \\in L$ and each $l_i$ is algebraic over $K$\n      by algebraic extension definition\n      \\ref{def:algebraicextension}. By theorem\n      \\ref{thm:lec1_2} there are finite number of $l_i$\n      and they forms an algebraic extension\n      $E = K\\left(l_0, l_1, \\dots, l_{d-1}\\right)$. The\n      $E\\left(\\alpha\\right)$ is finite over $E$ and therefore finite\n      over $K$. As soon as $E\\left(\\alpha\\right)$ has a finite\n      dimension over $K$ thus there exists a relation for powers of\n      $\\alpha$ such that $\\sum_{i=0}^n k_i \\alpha^i = 0$ i.e. \n      $\\alpha$ is algebraic. \n    }\n  \\end{proof}\n\\end{theorem}\n\\begin{example}[$\\mathbb{Q}$ extension]\n  $\\mathbb{Q}\\left( \\sqrt[3]{2}, \\sqrt{3}\\right)$ algebraic and finite\n  over $\\mathbb{Q}$:\n  \\[\n  \\mathbb{Q} \\subset \\mathbb{Q}\\left( \\sqrt[3]{2}\\right)\n  \\subset \\mathbb{Q}\\left( \\sqrt[3]{2}, \\sqrt{3}\\right)\n  \\]\n\n  Minimal polynomial\n  \\[\n  P_{min}\\left(\\sqrt[3]{2}, \\mathbb{Q}\\right) = x^3 - 2.\n  \\]\n\n  $\\mathbb{Q}\\left( \\sqrt[3]{2}\\right)$ is generated over $\\mathbb{Q}$\n  by $1, \\sqrt[3]{2}, \\sqrt[3]{4}$ thus\n  $\\left[\\mathbb{Q}\\left( \\sqrt[3]{2}\\right): \\mathbb{Q}\\right] = 3$.\n\n  But $\\sqrt{3} \\notin \\mathbb{Q}\\left( \\sqrt[3]{2}\\right)$ because\n  otherwise $\\left[\\mathbb{Q}\\left( \\sqrt{3}\\right): \\mathbb{Q}\\right]\n  = 2$ must devide  \n  $\\left[\\mathbb{Q}\\left( \\sqrt[3]{2}\\right): \\mathbb{Q}\\right] = 3$\n  that is impossible.\n\n  Therefore $x^2 - 3$ is irreducible over\n  $\\mathbb{Q}\\left( \\sqrt[3]{2}\\right)$ and\n  \\[\n  P_{min}\\left(\\sqrt{3}, \\mathbb{Q}\\left( \\sqrt[3]{2}\\right)\\right) =\n  x^2 - 3.\n  \\]\n\n  \\[\n  \\left[\\mathbb{Q}\\left( \\sqrt[3]{2}, \\sqrt{3}\\right):\n    \\mathbb{Q}\\right] = 3 \\cdot 2 = 6.\n  \\]\n\\end{example}\n\n\\begin{proposition}[On dimension of extension]\n  \\[\n  \\left[K\\left(\\alpha\\right) : K\\right] =\n  \\deg\\left(P_{min}\\left(\\alpha, K\\right)\\right),\n  \\]\n  if $\\alpha$ is algebraic.\n  \\begin{proof}\n    If $\\deg\\left(P_{min}\\left(\\alpha, K\\right)\\right) = d$ then $1, \\alpha,\n    \\cdots, \\alpha^{d-1}$ - $d$ independent vectors and dimension\n    $K\\left(\\alpha\\right)$ is $d$.\n  \\end{proof}\n  \\label{prop:dimextension}\n\\end{proposition}\n\n\\begin{proposition}[About algebraic closure]\n  If $K \\subset L$ ($L$ extension of $K$). Consider\n  \\[\n  L' = \\left\\{\n  \\alpha \\in L \\mid \\alpha \\mbox{ algebraic over } K\n  \\right\\},\n  \\]\n  then $L'$ sub-field of $L$ and is called as algebraic closure of $K$\n  in $L$.\n  \\begin{proof}\n    We have to prove that if $\\alpha, \\beta$ are algebraic then\n    $\\alpha + \\beta$ and $\\alpha \\cdot \\beta$ are also algebraic. This\n    is trivial  because\n    \\[\n    \\alpha + \\beta, \\alpha \\cdot \\beta \\in K\\left[\\alpha, \\beta\\right]\n    \\]\n    \\footnote{\n      We also have that $K\\left[\\alpha, \\beta\\right]$ is a field:\n      $K\\left[\\alpha, \\beta\\right]\n      = K\\left(\\alpha, \\beta\\right)$.\n      Really\n      $K\\left[\\alpha\\right] =\n      K\\left(\\alpha\\right)$ (see proposition\n      \\ref{prop:lec1_1}). $\\beta$ is algebraic over $K$ and \n      therefore over $K\\left(\\alpha\\right)$ thus we can construct\n      $K\\left(\\alpha\\right)\\left[\\beta\\right] = K\\left(\\alpha, \\beta\\right)$\n      by proposition \\ref{prop:lec1_1}\n    }\n  \\end{proof}\n\\end{proposition}\n\n\n\\section{A digression: Gauss lemma, Eisenstein criterion}\n\nWhat we have seen so far:\n\n\\begin{itemize}\n\\item $K$ is a field, $\\alpha$ is an \\mynameref{def:algebraicelement}\n  over $K$ if it is a root of a polynomial $P \\in K\\left[X\\right]$.\n\\item $L$ is an \\mynameref{def:algebraicextension} over $K$ if\n  $\\forall \\alpha \\in L$: $\\alpha$ is an algebraic over $K$\n\\item $L$ is a \\mynameref{def:finiteextension} over $K$ if $dim_K L <\n  \\infty$.\n\\item If an extension is finite then it is algebraic\n\\item An extension is finite if and only if it is algebraic and\n  generated by a finite number of algebraic elements (see theorem\n  \\ref{thm:lec1_2})\n\\item $\\left[K\\left[\\alpha\\right]:K\\right] =\n  deg P_{min}\\left(\\alpha, K\\right)$ (see proposition\n  \\ref{prop:dimextension}). \n\\end{itemize}\n\nHow to decide that a polynomial $P$ is irreducible over $K$?\nAbout polynomial $x^3 - 2$ it is easy to decide that it's irreducible\nover $\\mathbb{Q}$, but what's about $x^{100}-2$?\n\n\\begin{lemma}[Gauss]\n  Let $P \\in \\mathbb{Z}\\left[X\\right]$, i.e. a polynomial with integer\n  coefficients, then if $P$ decomposes over $\\mathbb{Q}$ ($P = Q\\cdot\n  R, deg Q,R < deg P$) then it also decomposes over $\\mathbb{Z}$.\n  \\begin{proof}\n    Let $P = Q R$ over $\\mathbb{Q}$. Then\n    \\begin{eqnarray}\n      Q = m Q_1, Q_1 \\in \\mathbb{Z}\\left[X\\right],\n      \\nonumber \\\\\n      R = n R_1, R_1 \\in \\mathbb{Z}\\left[X\\right],\n      \\nonumber\n    \\end{eqnarray}\n    thus\n    \\[\n    n m P = Q_1 R_1. \n    \\]\n    There exists $p$ that divides $mn$: $p \\mid mn$ thus in modulo $p$\n    we have\n    \\[\n    0 = \\overline{Q_1}\\overline{R_1}\n    \\]\n    but $p$ is prime and the equation is in the field $\\mathbb{F}_p$\n    thus either $\\overline{Q_1} = 0$ or $\\overline{R_1} = 0$. Let\n    $\\overline{Q_1} = 0$ thus $p$ divides all coefficients in $Q_1$\n    and we can take $\\frac{Q_1}{p} = Q_2 \\in\n    \\mathbb{Z}\\left[X\\right]$. Continue for all primes in $mn$ we can\n    get that\n    \\[\n    P = Q_s R_t,\n    \\]\n    where $Q_s, R_t \\in \\mathbb{Z}\\left[X\\right]$.\n  \\end{proof}\n  \\label{lem:gauss}\n\\end{lemma}\n\n\\begin{example}[Eisenstein criterion]\n  Lets consider the following polynomial $x^{100} -2$. It's\n  irreducible. Lets prove it. If it reducible then\n  $\\exists Q, R \\in \\mathbb{Z}\\left[X\\right]$ such that\n  \\begin{equation}\n    x^{100} -2 = Q R\n    \\label{eq:ex_eisenstein}\n  \\end{equation}\n  Lets consider (\\ref{eq:ex_eisenstein}) modulo 2. In the case we will\n  have\n  \\[\n  Q R \\equiv x^{100} \\mod 2,\n  \\]\n  therefore\n  \\begin{eqnarray}\n    Q \\equiv x^k \\mod 2,\n    \\nonumber \\\\\n    R \\equiv x^l \\mod 2,\n    \\nonumber\n  \\end{eqnarray}\n  or\n  \\[\n  Q = x^k + \\dots + 2 \\cdot m\n  \\]\n  and\n  \\[\n  R = x^l + \\dots + 2 \\cdot n\n  \\]\n  thus\n  \\[\n  QR = x^{100} + 4 \\cdot nm\n  \\]\n  that is impossible because $n,m \\in \\mathbb{Z}$ and $nm \\ne\n  -\\frac{1}{2}$. \n  \\label{ex:eisenstein}\n\\end{example}\n\n\\begin{lemma}[Eisenstein criterion]\n  Lets $P \\in \\mathbb{Z}\\left[X\\right]$ and\n  $P = a_n X^n + a_{n-1} X^{n-1} + a_1 X + a_0$. If $\\exists p$ -\n  prime such that $p \\nmid a_n$, $p \\mid a_i \\forall i < n$ and\n  $p^2 \\nmid a_0$, then $P \\in \\mathbb{Z}\\left[X\\right]$ is\n  irreducible. \n  \\begin{proof}\n    the same as for example \\ref{ex:eisenstein}.\n  \\end{proof}\n  \\label{lem:eisenstein}\n\\end{lemma}\n\nNote: that both: \\mynameref{lem:gauss} and \\mynameref{lem:eisenstein} are\nvalid by replacing $\\mathbb{Z}$ with an \\mynameref{def:ufd} $R$ and\n$\\mathbb{Q}$ by its factorization field.\n", "meta": {"hexsha": "ae11e2ee0f5fe025eaef31843d407b23892cc49c", "size": 37285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture1.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": "lecture1.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": "lecture1.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": 33.0248007086, "max_line_length": 102, "alphanum_fraction": 0.6275177685, "num_tokens": 13565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.6271558457609949}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 17.3  Double Precision Complex Computation\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThese subprograms do the following computations for double precision complex\ndata: sum, difference, product, quotient, square root, and absolute value.\nThe Fortran~77 standard does not support a double precision complex data\ntype. Using the convention of storing the real and imaginary parts of a\ncomplex number as an adjacent pair of double precision numbers, this set of\nsubprograms provides the above operations while staying within the standard.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Double Precision}\n\n\\begin{description}\n\n\\item[DOUBLE PRECISION] \\ {\\bf  A}(2){\\bf , B}(2){\\bf , RESULT}(2){\\bf ,\nABSVAL, DZABS}\n\n\\end{description}\n\nAssign values to A(), or to A() and B(), and access the appropriate\nsubprogram. The results will be stored in RESULT() or ABSVAL.\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf \\ }ll@{\\ }}\nCALL ZSUM(A, B, RESULT) & Result $= a + b$\\\\\nCALL ZDIF(A, B, RESULT) & Result $= a - b$\\\\\nCALL ZPRO(A, B, RESULT) & Result $= a \\times b$\\\\\nCALL ZQUO(A, B, RESULT) & Result $= a\\ /\\ b$\\\\\nCALL ZSQRTX(A, RESULT) & Result $= \\sqrt a$\\\\\nABSVAL = DZABS(A) & Absval $= |a|$\\\\\n\\end{tabular}}\n\\end{center}\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\n\\item[A()] \\ [in] Contains the double precision complex value, $a$, with the real part in A(1) and\nthe imaginary part in A(2).\n\n\\item[B()] \\ [in] Contains the double precision complex value, $b$, with the real part in B(1)\nand the imaginary part in B(2).\n\n\\item[RESULT()] \\ [out] On return contains the double precision complex result with the real part\nin RESULT(1) and the imaginary part in RESULT(2). It is allowable for the\narray RESULT() to occupy the same storage locations as the arrays A()\nand/or B(). For example the statement, CALL ZPRO(Z, Z, Z), is\npermissible.\n\nIn the case of the complex square root, which is double valued, ZSQRTX\nreturns the root with nonnegative real part. If the real part of the root is\nzero it returns the root whose imaginary part is nonnegative. The other root\nis always the negative of the returned root.\n\n\\item[DZABS] \\ [out] Returns the double precision absolute value of the complex\nnumber represented by the pair, (A(1),A(2)).\n\n\\end{description}\n\n\\subsection{Examples and Remarks}\n\nThe program, DRZCOMP, with its output, ODZCOMP, illustrates the use of these\nsubprograms. The example begins with three complex constants, $a$, $b$, and $u$%\n. It computes $v = u+a$, $w = v\\times b$, and $z = \\sqrt w$. It then inverts this\nsequence of computations by computing $w_2 = z\\times z$, $v_2 = w_2/b$, and $u_2 =\nv_2-a$. Mathematically this should result in $w_2 = w$, $v_2 =\nv$, and $u_2 = u$. We test the last of these relations by computing TEST\\ $=\nu_2-u$.  Additionally TEST2 is a measure of the error in an\napplication of DZABS.  Both TEST and TEST2 are seen to be acceptably\nsmall given that the computation was done with double precision IEEE\narithmetic.\n\n\\subsection{Functional Description}\n\n\\subsubsection{Method}\n\nTo compute $(u,v)$ as the square root of $(x,y)$ the basic algorithm is\n\\begin{gather*}\nr = \\sqrt{x^2 + y^2}\\\\\nu = \\sqrt{(r+|x|)/2}\\\\\nv = |y|/(2u)\\\\\n\\text{if } x < 0 \\text{ swap }u\\text{ and }v\\\\\n\\text{if } y < 0 \\text{ set }v = -v\n\\end{gather*}\nSubroutine ZSQRTX contains special treatment for the cases of $x = 0$ or $y =\n0$, and uses scaling to avoid unnecessary overflow that could result from\ncomputing $x^2$ or $y^2.$\n\nSubprograms ZQUO and DZABS use scaling to avoid unnecessary overflow.\nIn the five subroutines the implementations permit the output array to\noccupy the same storage locations as the input arrays.\n\n\\subsubsection{Accuracy tests}\n\nThese subprograms have been tested using arguments on the four principal\naxes and interior to the eight octants. Results were consistent with the\nmachine precision.\n\n\\subsection{Error Procedures and Restrictions}\n\nIf B($1) = 0$ and B($2) = 0$ in ZQUO, the subroutine will execute a division\nby zero. We assume the host system will produce a runtime error diagnostic\nin this case.\n\nIf the function DZABS is used its name must be typed as double precision in\nthe referencing program.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\nDesigned by C. L. Lawson, JPL, May~1986.\n\nProgrammed by C. L. Lawson and S. Y. Chiu, JPL, May~1986, Feb.~1987,\nNov.~1987.\n\n\nEach of the subprograms, DZABS, ZDIF, ZPRO, ZQUO, ZSQRTX, and ZSUM is\ncontained in a program file of the same name.\n\n\\begcode\n\n\\medskip\\\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRZCOMP}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{zcomp}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODZCOMP}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{zcomp}}\n\\end{document}\n", "meta": {"hexsha": "c0a586656cef829a330c3c670a21141a9c4960dd", "size": 5013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch17-03.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-03.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-03.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": 35.3028169014, "max_line_length": 98, "alphanum_fraction": 0.7338918811, "num_tokens": 1454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.6271275056866941}}
{"text": "\\section{Coherent state}\n\nLet\n\\begin{equation}\n\\widehat{b}^- = \\widehat{a}^- - \\alpha,\\qquad\n\\widehat{b}^+ = \\rbr{\\widehat{b}^-}^\\dagger = \\widehat{a}^+ - \\alpha^*.\n\\label{eq:displacement-b}\n\\end{equation}\nOne seeks the state $\\Ket{\\alpha}$ satisfying\n\\begin{equation}\n\\widehat{b}^-\\Ket{\\alpha} = 0.\n\\label{eq:coherent-state-def-1}\n\\end{equation}\nExpanding $\\widehat{b}^-$ in terms of $\\widehat{x}$ and $\\widehat{p}$,\n\\begin{equation}\n\\widehat{b}^- = \\sqrt{\\frac{m\\Omega}{2}}\\rbr{\\widehat{x}-x_\\alpha}\n+ \\frac{\\ii}{\\sqrt{2m\\Omega}}\\rbr{\\widehat{p}-p_\\alpha},\n\\end{equation}\nwhere\n\\begin{equation}\nx_\\alpha = \\sqrt{\\frac{2}{m\\Omega}}\\Re\\alpha,\\qquad\np_\\alpha = \\sqrt{2m\\Omega}\\Im\\alpha.\n\\end{equation}\n\nOne may define\n\\begin{align}\n\\widehat{y} & \\coloneqq \\widehat{x} - x_\\alpha \\widehat{1}\n= \\widehat{x} - \\ii x_\\alpha\\sbr{\\widehat{p},\\widehat{x}}_-\n= \\ee^{-\\ii x_\\alpha \\widehat{p}} \\widehat{x} \\ee^{+\\ii x_\\alpha \\widehat{p}},\n\\label{eq:coh-y}\\\\\n\\widehat{k} & \\coloneqq \\widehat{p} - p_\\alpha \\widehat{1}\n= \\widehat{p} + \\ii p_\\alpha\\sbr{\\widehat{x},\\widehat{p}}_-\n= \\ee^{+\\ii p_\\alpha \\widehat{x}} \\widehat{p} \\ee^{-\\ii p_\\alpha \\widehat{x}},\n\\label{eq:coh-k}\n\\end{align}\nwhere in the last steps, Lemma \\ref{lem:bch-sandwich} has been applied.\nOne can verify\n\\begin{equation}\n\\sbr{\\widehat{y}, \\widehat{k}}_- = \\ii \\widehat{1}.\n\\end{equation}\n\n\\subsection{Displacement operator}\nInspired by \\cref{eq:coh-y,eq:coh-k}, one attempts\n\\begin{equation}\n\\rfun{\\widehat{D}}{\\alpha}\\widehat{a}^-\\rfun{\\widehat{D}^{-1}}{\\alpha},\n\\end{equation}\nwhere\n\\begin{equation}\n\\rfun{\\widehat{D}}{\\alpha} \\coloneqq\n\\ee^{+\\alpha\\widehat{a}^+ - \\alpha^*\\widehat{a}^-}\n\\equiv \\ee^{\\ii\\rbr{-x_\\alpha\\widehat{p}+p_\\alpha\\widehat{x}}}\n\\end{equation}\nis the \\emph{displacement operator}. Note that\n\\begin{equation}\n\\rfun{\\widehat{D}^{-1}}{\\alpha} = \\rfun{\\widehat{D}}{-\\alpha}\n= \\rfun{\\widehat{D}^\\dagger}{\\alpha}.\n\\end{equation}\n\n\\begin{equation}\nb^- = a^- - \\alpha = a^- + \\alpha\\sbr{a^+, a^-}_-\n= a^- + \\sbr{\\alpha a^+ - \\alpha^* a^-, a^-}_-.\n\\end{equation}\nNote that\n\\begin{equation}\n\\ad_{\\alpha a^+ - \\alpha^* a^-}^{\\rbr{n}}a^- \\equiv 0,\\qquad\\forall n \\ge 2.\n\\end{equation}\nBy Lemma \\ref{lem:bch-sandwich},\n\\begin{equation}\nb^- = \\ee^{+\\alpha a^+ - \\alpha^* a^-}a^-\\ee^{-\\alpha a^+ + \\alpha^* a^-}\n= \\rfun{D}{\\alpha} a^- \\rfun{D}{\\alpha}^{-1}.\n\\end{equation}\nNow\n\\begin{equation}\na^-\\Ket{0} \\coloneqq 0 \\eqqcolon \\rfun{D^\\dagger}{\\alpha} b^- \\Ket{0}\n= a^- \\rfun{D^\\dagger}{\\alpha} \\Ket{\\alpha}.\n\\end{equation}\nWith $\\rfun{D}{\\alpha}$ unitary in mind, one finds\n\\begin{equation}\n\\Ket{\\alpha} = \\ee^{\\ii\\theta}\\rfun{D}{\\alpha}\\Ket{0}.\n\\end{equation}\nOne can fix the phase $\\theta$ to be zero.\n\n\\subsection{Time evolution}\n\nCompute\n\\begin{equation}\n\\rfun{\\widehat{\\mscrU}}{t} \\rfun{\\widehat{D}}{\\alpha}\n\\rfun{\\widehat{\\mscrU}^\\dagger}{t}.\n\\label{eq:tim-evo-disp-1}\n\\end{equation}\n\n\\Cref{eq:tim-evo-disp-1} simplifies to\n\\begin{equation}\n\\ee^{-\\ii \\Omega t a^+ a^-} \\rfun{D}{\\alpha}\n\\ee^{+\\ii \\Omega t a^+ a^-}\n\\label{eq:tim-evo-disp-2}\n\\end{equation}\n\nOne wishes to interchange $\\ee^{-\\ii \\Omega t a^+ a^-}$ and\n$\\rfun{D}{\\alpha}$. By Theorem \\ref{thm:bch-brading}, one computes\n\\begin{align}\n\\ad_{-\\ii \\Omega t a^+ a^-}^{(1)}\\rbr{\\alpha a^+ - \\alpha^* a^-}\n&= \\sbr{-\\ii \\Omega t a^+ a^- , \\alpha a^+ - \\alpha^* a^-}_-\n\\nonumber\\\\\n&= -\\ii\\Omega t \\rbr{\\alpha a^+\\sbr{a^-, a^+}_- - \\alpha^*\\sbr{a^+, a^-}_- a^-}\n\\nonumber\\\\\n&= -\\ii\\Omega t \\rbr{+\\alpha a^+ + \\alpha^* a^-} \\nonumber\\\\\n&=\t+ \\alpha\\rbr{-\\ii\\Omega t}^1 a^+\n\t- \\alpha\\rbr{+\\ii\\Omega t}^1 a^-;\n\\end{align}\n\\begin{align}\n\\ad_{-\\ii \\Omega t a^+ a^-}^{(2)}\\rbr{\\alpha a^+ - \\alpha^* a^-}\n&= \\sbr{-\\ii \\Omega t a^+ a^-,\n\t-\\ii\\Omega t \\rbr{+\\alpha a^+ + \\alpha^* a^-}}_-\n\\nonumber\\\\\n&= \\Omega^2 t^2\\rbr{-\\alpha a^+ + \\alpha^* a^-}\n\\nonumber\\\\\n&= + \\alpha\\rbr{-\\ii\\Omega t}^2 a^+\n- \\alpha\\rbr{+\\ii\\Omega t}^2 a^-.\n\\end{align}\nBy induction one can prove\n\\begin{equation}\n\\ad_{-\\ii \\Omega t a^+ a^-}^{(n)}\\rbr{\\alpha a^+ - \\alpha^* a^-}\n= + \\alpha\\rbr{-\\ii\\Omega t}^n a^+\n- \\alpha\\rbr{+\\ii\\Omega t}^n a^-,\n\\end{equation}\nso that \\cref{eq:tim-evo-disp-1} transforms to\n\\begin{align}\n&\\phantom{{}={}}\\rfun{\\exp}{+\\alpha\\ee^{-\\ii\\Omega t}a^+\n\t-\\alpha^*\\ee^{+\\ii\\Omega t}a^-}\n\t\\ee^{-\\ii \\Omega t a^+ a^-}\n\t\\ee^{+\\ii \\Omega t a^+ a^-} \\\\\n&= \\rfun{\\exp}{+\\alpha\\ee^{-\\ii\\Omega t}a^+\n-\\alpha^*\\ee^{+\\ii\\Omega t}a^-} \\\\\n&\\equiv \\rfun{D}{\\alpha^t}.\n\\end{align}\nby Theorem \\ref{thm:bch-brading}, where\n\\begin{equation}\n\\alpha^t\\coloneqq \\alpha\\ee^{-\\ii\\Omega t}.\n\\end{equation}\n\nAs a result, the time evolution of the coherent ground state is\n\\begin{equation}\n\\rfun{\\mscrU}{t} \\Ket{\\alpha} = \\rfun{\\mscrU}{t} \\rfun{D}{\\alpha} \\Ket{0}\n= \\rfun{D}{\\alpha^t} \\rfun{\\mscrU}{t} \\Ket{0}\n= \\ee^{-\\ii\\Omega t/2}\\Ket{\\alpha^t},\n\\end{equation}\nin terms of the coherent parameter $\\alpha$.\n\n\\subsection{Particle numbers}\n\n\\begin{namedthm}{Lemma}\n\\begin{equation}\n\\rfun{\\widehat{D}}{\\alpha} = \\ee^{-\\vbr{\\alpha}^2/2}\n\\ee^{+\\alpha\\widehat{a}^+} \\ee^{-\\alpha^*\\widehat{a}^-}.\n\\end{equation}\n\\end{namedthm}\n\\begin{proof}\nUse Corollary \\ref{thm:bch-merging}.\n\\end{proof}\n\n\\begin{namedthm}{Particle number representation of $\\Ket{\\alpha}$}\n\\begin{equation}\n\\Braket{n | \\alpha} = \\ee^{-\\vbr{\\alpha}^2/2}\n\\frac{\\alpha^n}{\\sqrt{n!}}.\n\\end{equation}\n\\end{namedthm}\n\n\n\\begin{namedthm}{$\\widehat{a}$-particle number in $\\Ket{\\alpha}$}\n\\begin{equation}\n\\Braket{\\alpha | \\widehat{a}^+ \\widehat{a}^- | \\alpha} = \\vbr{\\alpha}^2.\n\\end{equation}\n\\end{namedthm}\n\\begin{proof}\n\\begin{equation}\n\\rfun{\\widehat{D}^\\dagger}{\\alpha}\\widehat{a}^-\\rfun{\\widehat{D}}{\\alpha}\n= \\widehat{a}^- + \\sbr{-\\alpha \\widehat{a}^+, \\widehat{a}^-}_-\n= \\widehat{a}^- + \\alpha;\n\\end{equation}\n\\begin{equation}\n\\rfun{\\widehat{D}^\\dagger}{\\alpha}\\widehat{a}^+\n\\widehat{a}^-\\rfun{\\widehat{D}}{\\alpha}\n=\n\\rfun{\\widehat{D}^\\dagger}{\\alpha}\\widehat{a}^+\\rfun{\\widehat{D}}{\\alpha}\n\\rfun{\\widehat{D}^\\dagger}{\\alpha}\\widehat{a}^-\\rfun{\\widehat{D}}{\\alpha}\n=\n\\rbr{\\widehat{a}^+ + \\alpha^*}\\rbr{\\widehat{a}^- + \\alpha}.\n\\end{equation}\n\\end{proof}\n\n\\begin{namedthm}{$\\widehat{b}$-particle number in $\\widehat{a}$-ground state}\n\\begin{equation}\n\\Braket{0 | \\widehat{b}^+ \\widehat{b}^- | 0} = \\vbr{\\alpha}^2\n\\end{equation}\n\\end{namedthm}\n\n\\begin{proof}\n\\begin{equation}\n\\widehat{b}^+ \\widehat{b}^- =\n\\rbr{\\widehat{a}^+ - \\alpha^*}\\rbr{\\widehat{a}^- - \\alpha}\n\\end{equation}\naccording to \\ref{eq:displacement-b}.\n\\end{proof}\n\n\\begin{namedrem}{Remark}\nSince $\\Ket{0}$ is stationary, $\\Braket{0 | \\widehat{b}^+ \\widehat{b}^- | 0}$\nis a constant of motion.\n\n\\end{namedrem}\n\n\\subsection{Wave function}\nSince $\\sbr{+\\ii p_\\alpha\\widehat{x}, -\\ii x_\\alpha\\widehat{p}}_- =\n\\ii p_\\alpha x_\\alpha \\widehat{1}$ is central, one has\n\\begin{align}\n\\Bra{x}\\rfun{\\widehat{D}}{\\alpha}\n&= \\Bra{x}\\ee^{\\ii\\rbr{+p_\\alpha\\widehat{x}-x_\\alpha\\widehat{p}}}\n\\nonumber\\\\\n&= \\Bra{x}\\ee^{+\\ii p_\\alpha\\widehat{x}}\\ee^{-\\ii x_\\alpha\\widehat{p}}\n\\ee^{-\\sbr{+\\ii p_\\alpha\\widehat{x}, -\\ii x_\\alpha\\widehat{p}}_-/2}\n\\nonumber \\\\\n&= \\ee^{-\\ii p_\\alpha x_\\alpha/2} \\ee^{+\\ii p_\\alpha x}\n\\Bra{x} \\ee^{-\\ii x_\\alpha\\widehat{p}}\n\\nonumber \\\\\n&= \\ee^{-\\ii p_\\alpha x_\\alpha/2} \\ee^{+\\ii p_\\alpha x}\n\\Bra{x-x_\\alpha},\n\\label{eq:displacement-x-bra}\n\\end{align}\nusing \\cref{eq:displace-x-bra}. Similarly\n\\begin{align}\n\\Bra{x}\\rfun{\\widehat{D}}{\\alpha}\n&= \\ee^{-\\sbr{-\\ii x_\\alpha\\widehat{p}, +\\ii p_\\alpha\\widehat{x}}_-/2}\n\\ee^{-\\ii x_\\alpha\\widehat{p}}\\ee^{+\\ii p_\\alpha\\widehat{x}} \\Ket{x}\n\\nonumber \\\\\n&= \\ee^{+\\ii p_\\alpha x_\\alpha/2} \\ee^{+\\ii p_\\alpha x} \\Ket{x+x_\\alpha}.\n\\end{align}\nNote the extra phase factors compared with\n\\cref{eq:displace-x-ket,eq:displace-x-bra}.\n\n\\Cref{eq:displacement-x-bra} solves the wave function of coherent ground state\n\\begin{align}\n\\Braket{x | \\alpha} &= \\Braket{x | \\rfun{D}{\\alpha} | 0}\n\\nonumber \\\\\n&= \\rbr{\\frac{m\\Omega}{\\pp}}^{1/4} \\cfun{\\exp}%\n{-\\frac{1}{2}m\\Omega\\rbr{x-x_\\alpha}^2}\\cfun{\\expi}{p_\\alpha x - \\frac{1}{2} \np_\\alpha x_\\alpha},\n\\end{align}\nas well as its time evolution\n\\begin{align}\n&\\phantom{{}={}}\\rbr{\\frac{m\\Omega}{\\pp}}^{-1/4}\\Braket{x | \\rfun{\\mscrU}{t} | \n\\alpha} \\nonumber \\\\\n&=\\ee^{-\\ii\\Omega t/2}\n\\Braket{x | \\rfun{D}{\\alpha\\ee^{-\\ii\\Omega t}} | 0}\n\\nonumber \\\\\n&=\\cfun{\\exp}{-\\frac{1}{2}m\\Omega\\rbr{x-x_\\alpha^t}^2} \n\\cfun{\\expi}{-\\frac{1}{2}\\Omega t + x p_\\alpha^t\n- \\frac{1}{2} p_\\alpha^t x_\\alpha^t},\n\\end{align}\nwhere\n\\begin{equation}\nx_\\alpha^t \\coloneqq x_{\\alpha^t},\\qquad\np_\\alpha^t \\coloneqq p_{\\alpha^t},\n\\end{equation}\nor\n\\begin{equation}\n\\begin{pmatrix} \\rbr{m\\Omega}^{+1/2} x_\\alpha^t \\\\\n\\rbr{m\\Omega}^{-1/2} p_\\alpha^t \\end{pmatrix} \\coloneqq\n\\begin{pmatrix}\n\\cos\\Omega t & \\sin\\Omega t \\\\ -\\sin\\Omega t & \\cos\\Omega t\n\\end{pmatrix}\n\\begin{pmatrix} \\rbr{m\\Omega}^{+1/2} x_\\alpha \\\\\n\\rbr{m\\Omega}^{-1/2} p_\\alpha\\end{pmatrix}\n\\end{equation}\n\n\\subsection{Density matrix and Wigner function}\n\n\\begin{nameddef}{Density matrix in the particle number representation}\n\\begin{equation}\n\\Braket{n_1 | \\rfun{\\widehat{\\rho}}{t} | n_2} = \\ee^{-\\vbr{\\alpha}^2}\n\\frac{\\rbr{\\alpha^t}^{n_1} \\rbr{\\alpha^t{}^*}^{n_2}}{\\sqrt{n_1!n_2!}}\n= \\ee^{-\\vbr{\\alpha}^2} \\frac{\\alpha^{n_1} \n\\rbr{\\alpha^*}^{n_2}}{\\sqrt{n_1!n_2!}}\\ee^{-\\ii\\Omega\\rbr{n_1-n_2}t}.\n\\end{equation}\n\n\\end{nameddef} % Density matrix in the particle number representation\n\n\n\n\\begin{nameddef}{Density matrix in the position representation}\n\\begin{align}\n&\\phantom{{}={}} \\Braket{x_1 | \\rfun{\\widehat{\\rho}}{t} | x_2} \\nonumber \\\\\n&= \\rbr{\\frac{m\\Omega}{\\pp}}^{1/2} \\cfun{\\exp}{-\\frac{m\\Omega}{2}\\rbr{\\rbr{\nx_1-x_\\alpha^t}^2 + \\rbr{x_1-x_\\alpha^t}^2}}\\,\n\\ee^{+\\ii p_\\alpha^t\\rbr{x_1-x_2}}\n\\end{align}\n\\end{nameddef} % Density matrix in the position representation\n\n\\begin{nameddef}{Wigner function}\n\\begin{equation}\n\\rfun{W}{x, p; t} = \\frac{1}{\\pp} \\cfun{\\exp}{-m\\Omega \\rbr{x-x_\\alpha^t}^2\n-\\frac{1}{m\\Omega}\\rbr{p-p_\\alpha^t}^2}.\n\\end{equation}\n\\end{nameddef} % Wigner function\n\n", "meta": {"hexsha": "803ce38a7e218df74efbcb25a2c413774b73f60d", "size": 9827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/gen-coh-squ/sections/coherent.tex", "max_stars_repo_name": "cmp0xff/Notes", "max_stars_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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": "old/gen-coh-squ/sections/coherent.tex", "max_issues_repo_name": "cmp0xff/Notes", "max_issues_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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": "old/gen-coh-squ/sections/coherent.tex", "max_forks_repo_name": "cmp0xff/Notes", "max_forks_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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.2196721311, "max_line_length": 79, "alphanum_fraction": 0.6276584919, "num_tokens": 4259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6271274958443501}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{amsmath,amscd}\n\\usepackage{amssymb,array}\n\\usepackage{amsfonts,latexsym}\n\\usepackage[mathscr]{euscript}\n\\usepackage{graphicx,subfig,wrapfig}\n\\usepackage{times}\n\\usepackage{psfrag,epsfig}\n\\usepackage{verbatim}\n\\usepackage{tabularx}\n\\usepackage[toc,page]{appendix}\n\n\\newcommand{\\matlab}[1]{\\texttt{#1}}\n\\newcommand{\\setname}[1]{\\textsl{#1}}\n\\newcommand{\\Ce}{\\mathbb{C}}\n\\newcommand{\\Ree}{\\mathbb{R}}\n\\newcommand{\\p}{\\begin{pmatrix}}\n\\newcommand{\\pp}{\\end{pmatrix}}\n\\newcommand{\\bm}{\\begin{bmatrix}}\n\\newcommand{\\bb}{\\end{bmatrix}}\n\\newcommand{\\eul}[1]{e^{#1}}\n\n\\begin{document}\n\n\\title{ \\vspace{-30mm}Systems Bioengineering 3\\\\Homework 12}\n\\author{Greg Kiar}\n\n\\maketitle\n\\begin{enumerate}\n\\item\n%q1\n\\begin{enumerate}\n\\item For the following evaluation of average time, we make use of the fact that the transcript follows an exponential trend.\n\\begin{align*}\nE(T) = t_{avg} &= \\int_0^{\\infty} t e^{-\\alpha t} dt \\\\\n&= \\alpha \\begin{bmatrix} \\frac{-t}{\\alpha} - \\int_0^{\\infty} \\frac{1}{\\alpha} e^{-\\alpha t} dt \\end{bmatrix} \\\\\n&= \\alpha \\begin{bmatrix} \\frac{-t}{\\alpha}e^{-\\alpha t} + \\frac{-1}{\\alpha^2} e^{-\\alpha t}\\end{bmatrix}_{0,t} \\\\\nt_{avg} &= \\frac{1}{\\alpha} = 10 \\text{min}\n\\end{align*}\nAt equilibrium, $\\beta = \\alpha n$, $\\therefore \\mu_n = 10$ at equilibrium. The variance is $10$ since for independent stochastic events $\\sigma_n^2 = \\mu_n$.\n\\item We can see that the ODE of this system is: $\\dot{X}(t) = \\beta - \\alpha X(t)$. Solving this model using the equation: \\begin{align*} \\dot{X} &= \\frac{d}{dX} ln(X(t)) \\\\ 0 &= \\frac{d}{dX}\\begin{pmatrix} ln(\\frac{\\beta}{\\alpha} - n) \\end{pmatrix} \\\\\nn &= \\frac{\\beta}{\\alpha} = 10 \\end{align*}\n\\item Source code for this part was provided by the TAs. It has been modified slightly and is attached in an appendix.\n\\item When starting the simulation at $n=10$ and running it for $10,000$ min, the mean and variance were $\\mu = 10.1287$ and $\\sigma^2 = 9.8604$, respectively. These values are near but not exactly expected values. This makes sense because the discrete stochastic system has a finitely small timestep. If the timesteps were infinitely small or the trial infinitely long, the values would approach the theoretical values.\n\\end{enumerate}\n\n\\item \\begin{enumerate}\n\\item Solving $\\dot{X}(t) = \\beta - \\alpha X(t)$ for the case prior to equilibrium allows us to use the Laplace transform. The solution of this system becomes \\begin{align*} X(t) = \\frac{\\beta}{\\alpha} (1 - e^{-\\alpha t}) \\end{align*}\n\\item Shown below is the solution for $1000$ randomly generated trajectories each for $100 min$. \\\\ \\includegraphics[scale=0.2]{sbe3hw12q2b.png}\n\\item It can be seen by the figure below, a plot of the variance, that the variance follows the same exponential trend as the random variable $n$. From this, we can set an approximate equation for the variance to be $\\sigma^2 = \\frac{\\beta}{\\alpha} (1 - e^{-\\alpha t}) $. From this we can see that the variance is at a maximum as $t \\to \\infty$. \\includegraphics[scale=0.2]{sbe3hw12q2c.png}\n\\end{enumerate}\n\n\\item \\begin{enumerate}\n\\item Similarly to the equation found in 2a), we can solve $ \\dot{X}(t) = \\frac{\\beta}{b} - \\alpha X(t) $, where $b=5$ here. The result for $X(t)$ is as follows: \\begin{align*} X(t) &= \\frac{\\beta}{b \\alpha} (1 - e^{-\\alpha t})\\end{align*}\nWe can see from this result that the burst size, $b$, affects the forward rate of the system. The forward rate$ = \\frac{\\beta}{b}$.\n\\item Simulating the stochastic and ODE models of this system for $10,000 min$ with the inital condition $X(0) = n(0) = 2$, the equilibrium value, the discrete model produced the values shown below. \\begin{align*} \\text{Discrete} && \\mu &= 12.0428 && \\sigma^2 = 30.3180 \\\\ \\end{align*}\n\\item For the stochastic system with larger burst sizes, the mean and variance both increase. When testing this for different burst sizes, an approximately linear relationship is observed for both the mean and variance values. This relationship does not change as $\\beta$ or $\\alpha$ increase and decrease simultaneously to one another. The approximate expressions are as follows: \\begin{align*} \\mu &= \\frac{\\beta}{\\alpha}\\\\ \\sigma^2 &= \\frac{2 \\beta}{b \\alpha} \\end{align*}\n\\end{enumerate}\n\\end{enumerate}\n\\newpage\n\\begin{appendices}\n\\section{Trajectories}\n\\input{get_trajectory}\n\\section{Example main script}\n\\input{Prob2_forStudents}\n\\end{appendices}\n\\end{document}\n", "meta": {"hexsha": "cefd8a7605ed8f3e7a94e4b283856f255497711e", "size": 4418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sbe3/Homework/HW12/sb3_hw12.tex", "max_stars_repo_name": "gkiar/sb2", "max_stars_repo_head_hexsha": "55eafc3078aaf248ea53ba5ccbc221aae9dab093", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-07T15:51:49.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-21T09:35:04.000Z", "max_issues_repo_path": "sbe3/Homework/HW12/sb3_hw12.tex", "max_issues_repo_name": "gkiar/sb2", "max_issues_repo_head_hexsha": "55eafc3078aaf248ea53ba5ccbc221aae9dab093", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-03-30T18:13:30.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-30T23:37:57.000Z", "max_forks_repo_path": "sbe3/Homework/HW12/sb3_hw12.tex", "max_forks_repo_name": "gkiar/jhu-bme-mse", "max_forks_repo_head_hexsha": "55eafc3078aaf248ea53ba5ccbc221aae9dab093", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-05-26T14:05:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-01T03:55:41.000Z", "avg_line_length": 64.0289855072, "max_line_length": 475, "alphanum_fraction": 0.713218651, "num_tokens": 1383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.6270787289701311}}
{"text": "\n\\subsection{Hodge stars}\n\nThe Hodge star operator is a generalisation of cross product.\nIn 3d space if we have a plane, we can get a vector perpendicular and visa versa.\nGenerally, we are in \\(n\\)-dimensional space and we input \\(k\\) vectors and get out \\(n-k\\) vectors.\n\n\\subsection{Hodge duals}\n\n", "meta": {"hexsha": "ba56cbd3fe3eb7fe71b28352f36d5553c69e3a9f", "size": 299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiCalculus/04-03-hodge.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/04-03-hodge.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/04-03-hodge.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.9, "max_line_length": 100, "alphanum_fraction": 0.745819398, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6270787266021324}}
{"text": "% file: problems/euclid.tex\n\n\\section{Extra Problem: $\\euclid(m, n)$}  \\label{section:euclid}\n\nProve the recursive Euclid algorithm as shown in Algorithm~\\ref{alg:euclid} for \ncomputing the greatest common divisor (gcd) of two natural numbers are totally correct.\n\n\\begin{marginfigure}%\n  \\includegraphics[width=0.60\\linewidth]{figs/euclid}\n  \\label{fig:euclid}\n\\end{marginfigure}\n\n\\input{algs/euclid}\n\n\\subsection{Proof}\n\n\\marginnote{Also pay attention to the way how to write a mathematical induction proof.}\n\nWe prove the partial correctness of \\euclid{} by strong mathematical induction on $n$,\nwith $m$ any fixed natural number.\n\n\\begin{description}\n  \\item[Basis:] $n = 0$. We have that\n    \\marginnote{Make sure you understand each of these three ``='''s:\n      \\begin{enumerate}[(1)]\n\t\\item By $n = 0$;\n\t\\item By the property of $\\gcd$;\n\t\\item By the \\euclid{} algorithm.\n      \\end{enumerate}\n    }\n    \\[\n      \\gcd(m,n) = \\gcd(m,0) = m = \\euclid(m,0).\n    \\]\n  \\item[Inductive Hypothesis:]\n    Suppose that $n \\ge 1$ and\n    \\[\n      \\gcd(m, k) = \\euclid(m, k), \\;\\forall 0 \\le k \\le n - 1.\n    \\]\n  \\item[Inductive Step:]\n    We need to prove that ($n \\ge 1$)\n    \\[\n      \\gcd(m, n) = \\euclid(m, n).\n    \\]\n\n    According to \\euclid{}, we have\n    \\[\n      \\euclid(m,n) = \\euclid(n, m \\bmod n).\n    \\]\n    Since $(m \\bmod n) < n$, by the inductive hypothesis, we have\n    \\[\n      \\euclid(n, m \\bmod n) = \\gcd(n, m \\bmod n).\n    \\]\n    Therefore, it suffices to prove that\n    \\[\n      \\boxed{\\gcd(m,n) = \\gcd(n, m \\bmod n).}\n    \\]\n    For notational convenience, we denote\n    \\[\n      d = \\gcd(m,n), \\quad d' = \\gcd(n, m \\bmod n).\n    \\]\n    Because $d, d' \\ge 0$, it is sufficient to obtain $d = d'$\n    by showing that $d \\mid d'$ and $d' \\mid d$:\n\n    \\begin{itemize}\n      \\item $d \\mid d'$.\n      \\item $d' \\mid d$.\n    \\end{itemize}\n\\end{description}\n", "meta": {"hexsha": "a5316f47851a892fadfed69a7bdadd734a57e29e", "size": 1873, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2017/2017-4th/4-0-sample/problems/euclid.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-4th/4-0-sample/problems/euclid.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-4th/4-0-sample/problems/euclid.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": 27.1449275362, "max_line_length": 87, "alphanum_fraction": 0.5969033636, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.6270698078963841}}
{"text": "\\paragraph{Adversarial accuracy:} check if data point in test set is classified correctly \\emph{and} network is robust in region around point (e.g., using PGD in $\\epsilon$ $L_\\infty$-ball). Often have tradeoff with standard accuracy. \n\\paragraph{Opt. Prob.:} $\\displaystyle \\argmin_\\theta \\E_{(x, y) \\sim D} \\left[ \\max_{x' \\in S(x)} \\loss(\\theta; x', y)\\right]$\n\\subsection*{PGD training}\n\\begin{enumerate}\n    \\item Select mini-batch $B$\n    \\item $\\displaystyle B_\\text{max} \\gets \\{\\argmax_{x' \\in S(x)} \\loss(\\theta; x', y) \\lvert x \\in B\\}$\n    \\item $\\displaystyle \\theta \\gets \\theta - \\frac{1}{\\lvert B_\\text{max} \\rvert} \\sum_{(x, y) \\in B_\\text{max}} \\nabla_\\theta \\loss(\\theta; x, y)$\n\\end{enumerate}\n\\subsection*{TRADES}\n$$ \\argmin_\\theta \\E_{(x, y) \\sim D} \\left[ \\loss(\\theta; x, y) + \\lambda \\cdot \\max_{x' \\in S(x)} \\loss(\\theta; x', f_\\theta(x))\\right]$$", "meta": {"hexsha": "ad6521df51ad9144d0d53cb6de1f522ebfc626b3", "size": 873, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "adversarial-defenses.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": "adversarial-defenses.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": "adversarial-defenses.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": 87.3, "max_line_length": 235, "alphanum_fraction": 0.6563573883, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7217431943271998, "lm_q1q2_score": 0.6270698029936175}}
{"text": "% !TeX root = ../diss.tex\r\n\r\n\\chapter{Preparation}\r\n\r\nThere were two main areas of preparation for my project. One was to research the Smith-Waterman (SW) algorithm, and the ways it has been modified and implemented by others.\r\nThe other area was researching the different architectures, programming environment and tools to use.\r\n\r\n\\section{Overview of the Smith-Waterman algorithm}\r\n\\label{sec:SW_Overview}\r\nSequence alignment algorithms are used to find similar regions between two strings.\r\nThis involves predicting where symbols in the two strings correlate with each other (both matching and mismatching symbols), or where one sequence has some symbols that have been inserted into that sequence or deleted from the other.\r\nThis can be represented as follows, where symbols in the same column correspond to one another, and dashes represent insertions or deletions (gaps):\r\n\\begin{center}\r\n\\begin{tabular}{c}\r\n\\begin{lstlisting}[basicstyle=\\ttfamily\\linespread{0.8}]\r\nAC-T\r\nACGT\r\n\\end{lstlisting}\r\n\\end{tabular}\r\n\\end{center}\r\n\r\nThe Smith-Waterman algorithm \\cite{SW_Original} is a local alignment algorithm; it can produce alignments that span a subset of the input sequences.\r\nThis is useful when aligning long segments of DNA which contain non-coding regions or multiple different genes (which occurs when aligning against an entire chromosome).\r\nWhen aligning a single gene against a chromosome from a different species, a local alignment algorithm can find the relevant region whilst excluding the rest of the longer sequence in the alignment.\r\n\r\n\\subsection{The Dynamic Programming approach}\r\n\\label{sec:SW_DP}\r\n\r\nThe Smith-Waterman algorithm \\cite{SW_Original} finds alignments using dynamic programming.\r\nFor sequences $A=a_1 a_2 \\ldots a_N$ and $B=b_1 b_2 \\ldots b_M$, a scoring matrix $H$ is constructed where cell $H_{i,j}$ gives the score of the best local alignment that ends with $a_i$ and $b_j$.\r\nUsing a similarity function $s(a,b)$ which gives the similarity of two sequence symbols, and gap score list $W_k$ which gives the penalty for a deletion of length $k$, $H_{i,j}$ is defined as follows:\r\n$$ H_{i,j} = \\max \\begin{cases}\r\nH_{i-1,j-1} + s(a_i, b_j) & \\text{(Including both symbols in alignment)} \\\\\r\n\\max_{k \\geq 1}(H_{i-k,j} - W_k) & \\text{(Skipping $k$ symbols from $a$)} \\\\\r\n\\max_{l \\geq 1}(H_{i,j-l} - W_l) & \\text{(Skipping $k$ symbols from $b$)} \\\\\r\n0 & \\text{(Starting alignment here)}\r\n\\end{cases}$$\r\n\r\nThe grid is initialised using $\\forall i\\leq N . H_{i,0}=0$ and $\\forall j \\leq M . H_{0,j}=0$.\r\n\r\nFor example, using sequences {\\ttfamily GACT} and {\\ttfamily ACGT} and the following definitions of $s(a,b)$ and $W_k$:\r\n$$s(a, b)= \\begin{cases}\r\n5 &  a = b \\\\\r\n-4 & a \\neq b\r\n\\end{cases}\r\n\\qquad \\qquad \\qquad W_k = -k\r\n$$\r\n\r\n\\begin{center}\r\n$H = $ \\begin{tabular}{|c|ccccc|} \\hline\r\n& & {\\ttfamily A} & {\\ttfamily C} & {\\ttfamily G} & {\\ttfamily T} \\\\ \\hline\r\n& $0$ & $0$ & $0$ & $0$ & $0$ \\\\\r\n{\\ttfamily G} & $0$ & $0$ & $0$ & $3$ & $2$ \\\\\r\n{\\ttfamily A} & $0$ & $3$ & $2$ & $2$ & ${\\color{darkorange} 1}$ \\\\\r\n{\\ttfamily C} & $0$ & $2$ & ${\\color{darkblue}6}$ & $5$ & $4$ \\\\\r\n{\\ttfamily T} & $0$ & $1$ & $5$ & $4$ & $8$ \\\\ \\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\r\nTaking two examples from this:\r\n\\begin{align*}\r\n{\\color{darkblue}H_{3,2}} = 6 &= \\max \\begin{cases}\r\n    3 + s(\\text{\\ttfamily C}, \\text{\\ttfamily C}) =6\\\\\r\n    \\max(2-1, 0 - 2, 0-3) =1 \\\\\r\n    \\max(2-1, 0 - 2) =1\\\\\r\n    0\r\n\\end{cases} \\\\\r\n{\\color{darkorange} H_{2,4}} = 1 &= \\max \\begin{cases}\r\n    3 + s(\\text{\\ttfamily A}, \\text{\\ttfamily T}) =1 \\\\\r\n    \\max(2-1, 0 - 2) =1 \\\\\r\n    \\max(2-1, 2 - 2, 3-3, 0-4) =1 \\\\\r\n    0\r\n\\end{cases}\r\n\\end{align*}\r\nNote that in the case of $H_{2,4}$ (and others) there are multiple ways of getting to the maximum value (from above, the left, or diagonally in this case), and this leads to multiple alignments that have the same optimal score.\r\n\r\n\\subsection{Back-tracing}\r\n\\label{sec:SW_Back_tracing}\r\nStored with each grid cell is a ``pointer'' which locates the previous cell in the alignment ending with that cell, where pointer $p \\in \\{Above_k, Left_k, Diagonal, Nil\\}$. $Nil$ represents this cell not being part of an alignment, because all paths to that cell are worse than the threshold $0$. $Left_k$ represents skipping $k$ symbols from $a$, likewise for $Above_k$ skipping $k$ symbols from $b$. In the general case, this matrix of pointers $P$ is found using:\r\n$$ P_{i,j} = \\begin{cases}\r\n    Diagonal, & H_{i,j} = H_{i-1,j-1} + s(a_i, b_j) \\\\\r\n    Left_k, & H_{i,j} = \\max_{k \\geq 1}(H_{i-k,j} - W_k) \\\\\r\n    Above_k, & H_{i,j} = \\max_{l \\geq 1}(H_{i,j-l} - W_l) \\\\\r\n    Nil, & H_{i,j} = 0\r\n\\end{cases}$$\r\n\\pagebreak\r\n\r\nAn example of $P_{i,j}$ is as follows (where $\\cdot$ represents $Nil$):\r\n\\begin{center}\r\n$P = $     \\begin{tabular}{|p{0.035\\textwidth}|p{0.035\\textwidth}p{0.035\\textwidth}p{0.035\\textwidth}p{0.035\\textwidth}p{0.035\\textwidth}|} \\hline\r\n& & \\hfil {\\ttfamily A} & \\hfil {\\ttfamily C} & \\hfil {\\ttfamily G} & \\hfil {\\ttfamily T} \\\\ \\hline\r\n& \\hfil $\\cdot$ & \\hfil $\\cdot$ & \\hfil $\\cdot$ & \\hfil $\\cdot$ & \\hfil $\\cdot$ \\\\\r\n\\hfil {\\ttfamily G} & \\hfil ${\\color{darkorange} \\cdot}$ & \\hfil $\\cdot$ & \\hfil $\\cdot$ & \\hfil $\\nwarrow$ & \\hfil $\\leftarrow_1$ \\\\\r\n\\hfil {\\ttfamily A} & \\hfil $\\cdot$ & \\hfil ${\\color{darkorange} \\nwarrow}$ & \\hfil $\\leftarrow_1$ & \\hfil $\\uparrow_1$ & $\\leftarrow_1$ \\\\\r\n\\hfil {\\ttfamily C} & \\hfil $\\cdot$ & \\hfil $\\uparrow_1$ & \\hfil ${\\color{darkorange} \\nwarrow}$ & \\hfil ${\\color{darkorange} \\leftarrow_1}$ & $\\leftarrow_2$ \\\\\r\n\\hfil {\\ttfamily T} & \\hfil $\\cdot$ & \\hfil $\\uparrow_2$ & \\hfil $\\nwarrow$ & \\hfil $\\leftarrow_1$ & \\hfil ${\\color{darkorange} \\nwarrow}$ \\\\ \\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\r\nA running maximum score is maintained during the production of the grid, and the cell $H_{i,j}$ with the highest score corresponds to the highest-scoring alignment, which finishes with $a_i$ and $b_j$.\r\nStarting here, the alignment can be found from end to start by following the pointers in the grid. The best path through $P_{i,j}$ is highlighted in {\\color{darkorange}orange}, and gives alignment:\r\n\\begin{center}\r\n\\begin{tabular}{c}\r\n\\begin{lstlisting}[basicstyle=\\ttfamily\\linespread{0.8}]\r\nAC-T\r\nACGT\r\n\\end{lstlisting}\r\n\\end{tabular}\r\n\\end{center}\r\n\r\n\\subsection{Algorithmic complexity}\r\n\\label{sec:SW_Complexity}\r\nFor sequences of lengths $N$ and $M$, this algorithm requires $O(NM)$ space to store the two matrices, each with $(N+1)\\times(M+1)$ elements.\r\nThe runtime is $O(N^2 M)$, where without loss of generality $N\\geq M$.\r\nEach cell needs to consider the cell to its diagonal (constant time), and all of the cells above it (of order $M$ cells), and all cells to its left (of order $N$ cells).\r\nThis gives a runtime for evaluating a cell as $O(N+M)$, which is $O(N)$ given $N\\geq M$.\r\nThere are $NM$ cells to be evaluated, so producing the grid takes $O(N^2 M)$ time.\r\n\r\nIf the gap evaluation scheme did not maximise over a row, and instead performed constant time operations, then the complexity is $O(NM)$.\r\nThis is discussed in \\cref{sec:SW_gaps}.\r\n\r\nEach back-tracing step requires constant time (a matrix lookup, and some pointer comparisons) to produce each element in the alignment, and the length of alignment is bounded by $N+M$, where the alignment is wholly made up of gaps.\r\nTherefore, this step requires $O(N)$ space and time, where $N\\geq M$.\r\n\r\nOverall, the space requirements of the algorithm as presented is $O(NM)$, and the time requirements are either $O(NM)$ or $O(N^2 M)$ depending on how gaps are evaluated.\r\nImprovements to this are discussed in \\cref{sec:SW_Linear_Prep}.\r\n\r\n\\subsection{Scoring alignments}\r\n\\label{sec:SW_Scoring}\r\n\r\nThe general approach to scoring alignments is given in the paper written by Smith and Waterman \\cite{SW_Original}, but the exact details are not specified.\r\nThere are two areas that need definition: how to compare a pair of sequence symbols, and how to score gaps in the alignment.\r\n\r\n\\subsubsection{Sequence similarity functions}\r\n\\label{sec:SW_similarity_functions}\r\nThe original paper requires similarity function $s(a,b)$ which gives the similarity of two sequence symbols. One simple implementation might be:\r\n$$s(a, b) = \\begin{cases}\r\nm,   & a =    b \\\\\r\n\\mu, & a \\neq b\r\n\\end{cases}$$\r\n\r\nFor two constants $m$ and $\\mu$ where typically $m>0$ and $\\mu<0$.\r\nThe implementation Smith-Waterman in the European Molecular Biology Open Software Suite (EMBOSS) \\cite{EMBOSS} uses an approach equivalent to using $m=5$ and $\\mu=-4$ for DNA alignments by default.\r\n\r\nHowever, the biological processes that leads to one symbol being substituted for another cannot be entirely expressed in these two constants, especially when some symbols are more likely than others to replace a given symbol.\r\nThis is particularly problematic in proteins, which naturally are made up of 22 different types of amino acids.\r\n\r\nA more granular approach is to base $s(a,b)$ on a substitution matrix, which encodes a score for each different pairing of symbols.\r\nThis has performance penalties (\\cref{sec:C_scoring_eval,sec:CUDA_scoring_eval,sec:SV_expected_v_actual,sec:FPGA_utilisation,sec:SV_Fmax}), because the first approach can use direct equality testing and hard-coded constants, whereas using a substitution matrix for proteins requires a lookup from a $22\\times22$ matrix.\r\n\r\nDiscussions of which substitution matrices are best for which applications are beyond the scope of this project, and they are all implemented in the same way.\r\nI chose to base investigations into the performance implications into this on the BLOSUM50 matrix for proteins \\cite{BLOSUM}, which is used for alignments between sequences that are not closely related.\r\n\r\n\\subsubsection{Scoring gaps}\r\n\\label{sec:SW_gaps}\r\nThe original paper \\cite{SW_Original} references a gap weight vector $W_k$, which defines the score penalty of a gap of length $k$, where gaps jump either $k$ elements to the left, or above.\r\nHowever, it makes the algorithm run in $O(N^2 M)$ time for $N\\geq M$ (\\cref{sec:SW_Complexity}), so other approaches are used instead.\r\n\r\nOne solution to this problem was suggested by Waterman and Smith \\cite{SW_Metrics} in an earlier paper about global alignment: to define $W_k=kw_1$ for some gap penalty $w_1$.\r\nUsing the recursive definition of $H_{i,j}$ the score using a $Left$ gap is:\r\n$$\\max_{k \\geq 1}(H_{i-k,j} -W_k) = H_{i-1,j} - w_1$$\r\nGotoh proposed a different way of solving this problem \\cite{Gotoh}.\r\nThe constant gap penalty models the cost of inserting or deleting symbols in a sequence by making this penalty proportional to the length of the insertion or deletion.\r\nThis is not ideal, because as Gotoh observes, ``long gap[s] can be produced by a single mutational event''.\r\nInstead he proposes what is later called the affine-gap method, where $W_k=uk+v$ for some gap penalties $u$ and $v$.\r\nThe penalty of starting to insert or delete a sequence is given by $u$, and $v$ accounts for the different lengths of such a sequence.\r\n\r\nThis approach requires more space than the original Smith-Waterman algorithm because choosing whether to open a gap has an impact on scores later in the alignment.\r\nWhen evaluating a mismatched cell in the dynamic-programming grid it is impossible to know whether to pay the mismatch penalty because a sequence of matches immediately follow, or if a long sequence of mismatches follow and it would be less expensive to open up a gap to cover them instead.\r\nTherefore, extra space is needed to keep track of scores when the decision to open a gap is and also is not taken.\r\n\r\nTo achieve this, three grids are constructed instead of one.\r\nThis triples the memory requirements in practice but does not change the asymptotic memory requirements.\r\nThe main score grid $H_{i,j}$ is calculated using a similar approach to before, representing the score of the best alignment using sequences $a_1\\ldots a_i$ and $b_1 \\ldots b_j$.\r\nAdditionally, there is grid $F_{i,j}$ which represents the score of the best alignment between $a_1\\ldots a_i$ and $b_1 \\ldots b_j$ provided it ended with an open left-gap.\r\n$G_{i,j}$ is similar for above gaps.\r\nThis gives grid definitions:\r\n\\begin{align*}\r\nH_{i,j} &= \\max(H_{i-1,j-1} + s(a_i, b_j), F_{i,j}, G_{i,j}, 0) \\\\\r\nF_{i,j} &= \\max(H_{i-1,j} + u + v, F_{i-1,j} + v) \\\\\r\nG_{i,j} &= \\max(H_{i,j-1} + u + v, G_{i,j-1} + v)\r\n\\end{align*}\r\n\r\nThis is modified from the original paper somewhat for notational consistency with the rest of the dissertation.\r\n\r\nPointer grids need to be stored for all three grids, where the back-tracer will start in grid $H$ (and this is the only grid where the running maximum is kept), but it will trace through $F$ and $G$ as well to determine where a gap started.\r\n\r\n\\subsection{Linear space modification to Smith-Waterman algorithm}\r\n\\label{sec:SW_Linear_Prep}\r\n\\subsubsection{Overview}\r\n\\label{sec:SW_Linear_Overview}\r\n\r\nA common approach to improving the runtime of the Smith-Waterman algorithm is to reduce the amount of space used by increasing the amount of time spent in doing arithmetic.\r\nHirschberg’s algorithm \\cite{Hirschberg} pioneered this approach for the Longest Common Subsequence problem.\r\nMyers and Miller apply this approach to local alignments \\cite{MyersMiller}, which is summarised below.\r\n\r\nThe purpose of this algorithm is to correctly and efficiently split the alignment into small chunks, manageable for the quadratic space implementation which is where the back-tracing is done.\r\nIt recursively divides a large grid into two smaller grids.\r\n\\Cref{fig:Linear_Space_Structure} shows this, where the optimal alignment is shown in orange.\r\nThe grid has been divided into two smaller grids by the first pass of the algorithm, a grid with blocks $1$ and $2$, and the grid with blocks $3$ and $4$.\r\nThe grey segments do not contain the alignment and can be ignored.\r\nThe black arrows represent the direction the blocks are evaluated in, discussed further on.\r\n\r\n\\Cref{lst:pseudo_sw} is a pseudo-code representation of the quadratic space Smith-Waterman algorithm, to be used in this linear space algorithm.\r\nParameter \\lstinline{fixedTop} specifies whether the alignment can start from anywhere in the grid, or just the top left corner (and is implemented by including or removing the options of $0$ and $Nil$ from the maximising functions).\r\nThis is necessary because the optimal alignment inside a subproblem may not start at the top-left, but the overall optimal alignment may pass through multiple sub-grids where the top-left of each grid must be connected to the bottom-right of the next grid.\r\nParameter \\lstinline{fixedBottom} is similar, specifying whether to start back-tracing at the best cell in the grid, or the bottom-right cell.\r\n\r\n\\begin{figure}\r\n    \\centering\r\n    \\includegraphics[width=(0.4\\textwidth)]{figs/linear_space_structure.pdf}\r\n    \\caption{The divided dynamic programming matrix when using the linear space approach, after the first iteration}\r\n    \\label{fig:Linear_Space_Structure}\r\n\\end{figure}\r\n\r\n\\begin{lstlisting}[basicstyle=\\linespread{0.9}\\ttfamily\\footnotesize, label={lst:pseudo_sw},captionpos=b,caption={Pseudo-code representation of quadratic space implementation of SW algorithm}]\r\nfun sw(seq1, seq2, fixedTop, fixedBottom):\r\n    Dynamic programming approach using quadratic space\r\n    if fixedTop:\r\n        Only allow alignments to start at the top-left\r\n    else:\r\n        Allow alignments to start anywhere\r\n    if fixedBottom:\r\n        Return the alignment ending at the bottom-right grid cell\r\n    else:\r\n        Return the alignment ending at the best cell in the grid\r\n\\end{lstlisting}\r\n\r\nTo split a large grid into two smaller grids, the scores of the middle column of cells are found by starting from the top-left and working towards the middle, and also by starting from the bottom right and working towards the middle.\r\n\\Cref{lst:pseudo_sw_col} is a representation of this.\r\nIn \\cref{fig:Linear_Space_Structure}, blocks $1$ and $3$ are evaluated from their top-lefts to their middle columns, and blocks $2$ and $4$ from the bottom-right, and the direction of evaluation represented by the black arrows.\r\nThese scores are found using a linear space.\r\nThese two columns are added together, and each cell of the column gives the score for the best alignment that passes through that cell.\r\nThe optimal alignment might cross the middle column or be in one of these half-grids.\r\n\r\nThe middle columns are found using $O(N)$ space for sequences of lengths $N$ and $M$, and maintains $O(NM)$ time complexity, albeit with a greater constant factor.\r\nThis uses the fact that only the immediate neighbours are needed to calculate the score of a cell, so the values of a previous column can be discarded once the values in the next column have been computed. This data dependency is shown in \\cref{fig:Linear_Space_Dependencies}.\r\nHowever, discarding this information leads to recomputation of the cells in the smaller subproblems that are recursively evaluated.\r\n\r\nMaxima are calculated whilst computing each half, and compared to the maximum cell in the summed columns.\r\nIf the overall maximum is in one of the half-grids, restart the algorithm between that cell and the top-left or bottom-right, if on the left or right sides respectively.\r\nOtherwise, the algorithm is rerun between the end cells and the maximum middle cell.\r\nThis recursively breaks up the alignment until it is small enough to tackle directly using the quadratic space algorithm (\\cref{sec:SW_DP,sec:SW_Back_tracing,sec:SW_Complexity}), and then joins them back together.\r\n\\begin{figure}[h]\r\n    \\centering\r\n    \\includegraphics[width=(0.4\\textwidth)]{figs/linear_space_deps.pdf}\r\n    \\caption{Data dependencies when using the linear space approach}\r\n    \\label{fig:Linear_Space_Dependencies}\r\n\\end{figure}\r\n\\begin{lstlisting}[basicstyle=\\ttfamily\\linespread{0.9}\\footnotesize, label={lst:pseudo_sw_col},captionpos=b,caption={Pseudo-code representation of linear space algorithm which finds middle columns}]\r\n    fun sw_col(seq1, seq2, direction, fixedStart):\r\n        direction in {forwards, backwards}\r\n        direction determines which half of grid is evaluated\r\n            - Forwards: from top left, to column (seq2/2)\r\n            - Backwards: from bottom right, to column (seq2/2)\r\n        fixedStart similar to fixedTop of sw()\r\n        Calculate grid column by column, returning:\r\n            - Values of column (seq2/2)\r\n            - Location of best cell, and score\r\n    \\end{lstlisting}\r\n\\begin{minipage}{\\linewidth}\r\n\\begin{lstlisting}[basicstyle=\\linespread{0.9}\\ttfamily\\footnotesize, label={lst:pseudo_sw_linear},captionpos=b,caption={Pseudo-code representation of the linear space Smith-Waterman algorithm}]\r\nfun sw_linear(seq1, seq2, fixedTop, fixedBottom):\r\n    if seq1 and seq2 are small:\r\n        return sw(seq1, seq2, fixedTop, fixedBottom)\r\n    else:\r\n        (forwardCol, bestForwards) = sw_col(seq1, seq2, forwards, fixedTop)\r\n        (backwardCol, bestBackwards) = sw_col(seq1, seq2,\r\n                                              backwards, fixedBottom)\r\n        middleCol = forwardCol + backwardCol # Using vector addition\r\n        bestMiddle = max(middleCol)\r\n\r\n        # Using list splicing: seq1[x:] = [seq1[x], seq1[x+1], ... seq1[n]]\r\n        if best path is bottom-right to bestBackwards and not fixedTop:\r\n            return sw_linear(seq1[bestForwards.i:], seq2[bestForwards.j:],\r\n                             fixedTop, fixedBottom)\r\n        else if best path is top-left to bestForwards and not fixedBottom:\r\n            return sw_linear(seq1[0:bestForwards.i], seq2[0:bestForwards.j],\r\n                             fixedTop, fixedBottom)\r\n        else use middle cell:\r\n            alignStart = sw_linear(seq1[0:bestMiddle.i],seq2[0:len(seq2/2)],\r\n                                   fixedTop, true)\r\n            alignEnd = sw_linear(seq1[bestMiddle.i:],seq2[len(seq2/2):],\r\n                                 true, fixedBottom)\r\n            return alignStart @ alignEnd\r\n\\end{lstlisting}\r\n\\end{minipage}\r\n\r\n\\subsubsection{Back-tracing}\r\n\\label{sec:SW_Linear_Back_tracing}\r\n\r\nThe process of building the final alignment, back-tracing, is done in parts and later joined, in accordance with the divide-and-conquer approach of this algorithm.\r\nWhen the large grid has been recursively divided to small enough grids, the quadratic space algorithm (\\cref{sec:SW_DP,sec:SW_Back_tracing}) is used to find an alignment.\r\nThis is because producing an alignment requires a grid of pointers taking $O(NM)$ space, so when the grid is small enough for a full grid of pointers to be made, a full grid of scores can also be made.\r\nThe resulting aligned sequences from each of these small alignments can be joined together to make the overall alignment.\r\n\r\n\\subsubsection{Runtime complexity}\r\n\\label{sec:SW_Linear_Complexity}\r\nThis additional arithmetic does not impact the runtime complexity.\r\nFor sequences of lengths $N$ and $M$ the linear space approach evaluates $2NM$ grid cells (each taking $O(1)$ time).\r\n\r\nThe amount of work done in each iteration halves. The first step evaluates every grid cell, taking $NM$ evaluations (over two halves of size $\\frac{N}{2} \\times M$).\r\nIf the alignment is in one half, then the next area to evaluate has at least halved.\r\nIf the alignment is split across the middle column, some point at position $m$ will be chosen on that column.\r\nThen two grids will be evaluated of area $\\frac{N}{2} \\times m$ and $\\frac{N}{2} \\times (M-m)$ which sum to $\\frac{NM}{2}$ for all possible $m$.\r\nUsing this repeated halving of work, the total number of grid evaluations required is:\r\n$$ \\text{Cells evaluated } =  NM + \\frac{NM}{2} + \\frac{NM}{4} + \\cdots \\leq NM \\sum_{i=0}^\\infty 2^{-i} = 2NM $$\r\n\r\n\\section{Overview of architectures and programming languages used}\r\n\\label{sec:Architecture_prep}\r\nThe objective of my project was to implement the Smith-Waterman algorithm using different hardware architectures (general purpose CPUs, GPUs, and FPGAs).\r\nAs part of my preparation I learnt about these architectures so I could produce implementations that were best suited for these different architectures.\r\n\r\n\\subsection{Central Processing Units and C}\r\n\\label{sec:CPU_prep}\r\nModern general-purpose Central Processing Units (CPUs) can have very high clock speeds, multiple processing cores, and have rich Instruction Set Architectures (ISAs).\r\nThe CPU in my laptop, used by this project, is an Intel Core i7-8750H.\r\nThis has six processing cores, and has a maximum clock frequency of $\\SI{4.1}{\\giga\\hertz}$ \\cite{i7-8750H}.\r\nThis clock frequency is significantly higher than the other platforms I used, however other implementations will be able to do more work per clock cycle, using increased parallelism or specialisation.\r\n\r\nI chose to write my programs for the CPU in C. The major reason I chose to do so was that the GPU APIs available (CUDA and OpenCL) are APIs for C/C++, so for the sake of interoperability it made sense to implement my project in either C or C++.\r\nThis would allow me to later reuse segments of code for the GPU implementation, especially the control logic and testing framework.\r\nAlso, I had previous experience with C from Part IB and a summer internship, so I chose to use C.\r\n\r\nThe focus of my project is exploring parallelism in Smith-Waterman, and with a multicore CPU I could implement a solution that was multi-threaded.\r\nThis is not a native feature in the C language, so I used the Native POSIX Thread Library, part of the GNU C Library.\r\nThis allows multiple threads to be run on multiple processing cores, where all of the scheduling is handled by the library and the host operating system.\r\n\r\n\\subsection{Graphics Processing Units and CUDA}\r\n\\label{sec:GPU_prep}\r\nGraphics Processing Units (GPUs) are designed to exploit vector-level parallelism in programs. The GPU in my laptop, used by this project, is an Nvidia GTX 1050 Ti.\r\nIt has $768$ CUDA cores in it \\cite{1050-Ti}; it can compute up to $768$ different things in parallel.\r\nThis is much more parallelised than the CPU, though the device has a significantly lower clock speed of $\\SI{1392}{\\mega\\hertz}$.\r\n\r\nI chose to use CUDA, Nvidia’s proprietary API for programming their GPUs.\r\nAn alternative was OpenCL, but I chose CUDA because it has a more helpful profiling tool, which suggests possible sources of poor performance, and I used this to guide development.\r\n\r\nThe highly parallel nature of CUDA causes its execution model to be different to a single core of a CPU.\r\nIn CUDA, a body of work is a grid, which is a group of blocks, where a block is a group of threads.\r\nThe GPU has a collection of streaming multiprocessors (SMs, in my case $24$) which execute different blocks, and each of these SMs execute $32$ threads at once.\r\nThese groups of threads are called warps and are subsets of blocks.\r\nThreads in a warp execute in lockstep, with a single instruction for all $32$ threads in the warp.\r\nThe overall number of CUDA cores is $24 \\times 32=768$.\r\n\r\nUnits of code to be run on the GPU are called kernels, which are similar to C functions. When a kernel is called the number of blocks and threads in a block are specified.\r\nThere is a hard limit to the size of a block of $1024$ threads \\cite{CUDA_Guide}, therefore programs implemented in CUDA cannot require synchronisation over an arbitrary number of threads.\r\n\r\nAll of the threads are given the same arguments and execute the same blocks of code (though different paths may take different branches through the code).\r\nAll that distinguishes them are two variables, their \\lstinline{threadId} and \\lstinline{blockId}.\r\nAll threads within a block can be synchronised using the execution barrier \\lstinline{__syncthreads()}.\r\nHowever, there is no synchronisation between blocks, even when executing the same kernel, and they can execute in parallel to each other.\r\n\r\n\\subsection{Field Programmable Gate Arrays and SystemVerilog}\r\n\\label{sec:FPGA_prep}\r\nAn extension to my project was to implement the Smith-Waterman algorithm on an FPGA using a hardware description language (HDL).\r\nI chose to use SystemVerilog as my HDL, because I had studied it in Part IB.\r\nField Programmable Gate Arrays are programmable circuits, principally made up of programmable lookup tables, flip-flops, integrated memory blocks and programmable routing between the features on the chip.\r\nThese devices can be programmed to make custom circuitry on the FPGA chip.\r\n\r\nThis is appealing because it allows me to define a custom accelerator optimised just for this problem, able to evaluate a cell in the dynamic programming grid in just one clock cycle.\r\nMy other implementations require numerous clock cycles to do this same work.\r\nThe device is clocked significantly slower than the CPU or GPU, with the default clock frequency of my device being $\\SI{50}{\\mega\\hertz}$, and the theoretical maximum of $\\SI{550}{\\mega\\hertz}$.\r\nHowever, being able to do more work per clock cycle can reduce the impact of a slower clock frequency.\r\n\r\nAlthough an implementation on an FPGA will require much more power and be significantly slower than the same logic in an ASIC, working with an FPGA was possible for this project and manufacturing an ASIC would cost far too much money.\r\n\r\nI used a Terasic DE1-SoC board \\cite{DE1-SoC} loaned from the Computer Architecture Group.\r\nThis has an Altera Cyclone V SE FPGA SoC \\cite{CycloneV}, which has $\\SI{85000}{}$ logic elements; a fairly small FPGA, but also not the smallest produced. This device was significantly older than the CPU and GPU it was compared against. This FPGA uses a 28nm process and was made in 2012 \\cite{CycloneV}, whereas the CPU and GPU are from 2018 and use a 14nm process \\cite{i7-8750H} \\cite{1050-Ti}.\r\nA smaller process node might improve the maximum frequency of a design implemented on an FPGA, and there would be more resources on the device at a similar price, which could be used to do more work in parallel.\r\n\r\nThe FPGA SoC also has a dual-core ARM Cortex-A9 on the same package as the FPGA \\cite{CycloneV}, referred to as the Hard Processing System, HPS.\r\nThe ARM core can control the accelerator using an interconnect between the HPS and FPGA.\r\nIn particular, it provides a memory-mapped Avalon streaming interface, where the HPS requests to read or write to the FPGA as if it were memory and the FPGA’s responses to these requests can be defined in HDL.\r\n\r\nA major design consideration for my work on the FPGA was memory capacity, due to the quadratic memory requirement of the Smith-Waterman algorithm.\r\nThere are several different types of memory on the FPGA \\cite{CycloneV} and development board \\cite{DE1-SoC} I was using, suited for different things.\r\nThis is tabulated in \\cref{tab:FPGA_Memories}.\r\nFor the SDRAM memories, the throughput given (marked \\dag) is the peak throughput, but average throughput will be lower as selecting rows takes time.\r\nThe ways that these memories were used was discussed in \\cref{sec:Memory_in_SV}.\r\n\r\n\\begin{table}[h]\r\n    \\centering\r\n    \\begin{tabular}{|p{0.2\\textwidth}|p{0.4\\textwidth}p{0.1\\textwidth}p{0.2\\textwidth}|} \\hline\r\n        Name & Description & Capacity & Throughput \\\\ \\hline\r\n        ALM Registers & On-chip; all registers are directly accessible by routing elements & $\\SI{15.67}{\\kibi\\byte}$ & $\\SI{15.67}{\\kibi\\byte\\cycle}$  \\\\ \\hline\r\n        M10K Blocks & On-chip; made up of $\\SI{10}{\\kibi\\bit}$ blocks units where $\\SI{40}{\\bits}$ can be accessed in a cycle, which are pipelined with one delay-slot between request and action.  & $\\SI{49.63}{\\kibi\\byte}$ & $\\SI{1.94}{\\kibi\\byte\\cycle}$ \\\\ \\hline\r\n        FPGA SDRAM & Off-chip; requires additional hardware to interface with it, and multiple delay slots as rows and columns are selected. & $\\SI{64}{\\mebi\\byte}$\r\n         & $\\SI{2}{\\byte\\cycle}^\\dag$ \\\\ \\hline\r\n        HPS DDR3 & Off-chip; requires additional hardware to interface with it, and multiple delay slots as rows and columns are selected. & $\\SI{1}{\\gibi\\byte}$ & $\\SI{8}{\\byte\\cycle}^\\dag$ \\\\ \\hline\r\n        \\end{tabular}\r\n\r\n    \\caption{Types of memory on the Terasic DE1-SoC development board}\r\n    \\label{tab:FPGA_Memories}\r\n\\end{table}\r\n\r\n\\FloatBarrier\r\n\r\n\\subsection{Licencing}\r\n\\label{sec:Licencing_prep}\r\n\r\nThe majority of tools and libraries I used for my project are open source, and the rest are available for private use.\r\n\\begin{itemize}\r\n\\item GNU Compiler Collection; particularly the C compiler---GPLv3\r\n\\item GNU C Library, particularly Native POSIX Thread Library---LGPL\r\n\\item GNU Debugger; for C and CUDA code---GPLv3\r\n\\item Gprof; C profiler---GPLv3\r\n\\item JetBrains CLion; C IDE---student license\r\n\\item Visual Studio Code; general source-code editor---MIT License\r\n\\item CUDA Toolkit; including a compiler, debugger, memory-checking suite and profiler---proprietary, freely distributed\r\n\\item Quartus Prime Lite Edition; for simulating and synthesising HDL designs---proprietary, freely distributed\r\n\\item Git; for version control of all source code and dissertation text---GPLv2\r\n\\item LaTeX; for typesetting this dissertation---LPPL\r\n\\item BibTeX; for references in this dissertation---GPLv3\r\n\\end{itemize}\r\n\r\n\\section{Development methodology}\r\n\\label{sec:Methodology_prep}\r\n\r\nThe plan for the project was outlined in the project proposal (\\cref{sec:Proposal}), sequentially implementing designs for each platform.\r\nBy doing this, if any unexpected difficulty arose in the later stages of the project, then there would still be completed implementations from earlier in the project to evaluate.\r\nThe implementations were ordered in ascending difficulty and my descending confidence, to this end, with the first three required for the core success criteria.\r\nIn order these were:\r\n\\begin{enumerate}\r\n\\item Implementing the Smith-Waterman algorithm in single-threaded C code.\r\n\\item Modifying the C code to make it multi-threaded.\r\n\\item Implementing the Smith-Waterman algorithm in CUDA.\r\n\\item Implement the Smith-Waterman algorithm in SystemVerilog and simulate design.\r\n\\item Instantiate Verilog implementation on an FPGA.\r\n\\end{enumerate}\r\n\r\nI tested throughout development and had two main testing areas: correctness and performance. Any errors were likely to propagate between implementations where similar approaches were used, especially between C and CUDA, so it was important to catch errors as they arose instead of letting them propagate.\r\nI used an external implementation \\cite{EMBOSS} to check my first C programs.\r\nI tested the rest of my work using this implementation, because the reference implementation would only give one correct solution when there might be more than one for a given alignment problem, whereas my programs could decide whether a given alignment was valid and optimal.\r\n\r\n\\section{Starting Point}\r\n\\label{sec:Starting_Point}\r\n\r\nI started with reasonable experience with C, having studied it in Part IB and writing some utility programs in C during a summer job. I had no experience with CUDA, or GPU programming in general, and had written a small amount of SystemVerilog during Part IB, but never having attempted a project of this scale in it before.\r\nTherefore, in my project plan I assigned more time for the GPU and FPGA implementations compared to the CPU implementation, based on my relative levels of experience.\r\n\r\nThe only code used that was not my own was SystemVerilog used for administrative purposes.\r\nI used a template from the Part IB ECAD+Arch course for instantiating a SystemVerilog design on the development board I was using, which correctly arranged IO pins.\r\nMy supervisor, Peter Rugg, gave me the Verilog he had used to build an Avalon streaming interface between the HPS and the FPGA, to transfer data between my hardware design and the OS on the HPS.\r\nI based my streaming interface on this, and I am grateful for his assistance.\r\n\r\nSequence alignment and Smith-Waterman in particular are covered in detail by the first few lectures of the Part II Bioinformatics course, and is presented in \\cref{sec:SW_Overview}.\r\nThis course runs in Michaelmas term.\r\nThe linear space approach (\\cref{sec:SW_Linear_Prep}) is described for global alignment in that course, and I read a paper \\cite{MyersMiller} for its application to local alignments.\r\n", "meta": {"hexsha": "316e4b1977033b2215fe158f9d81d8d4fa21fac7", "size": 34274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diss/chapters/prep.tex", "max_stars_repo_name": "benjimarshall/SequenceAlignment", "max_stars_repo_head_hexsha": "23fcfbf11567486afe03b9d671ce8640a83ca557", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diss/chapters/prep.tex", "max_issues_repo_name": "benjimarshall/SequenceAlignment", "max_issues_repo_head_hexsha": "23fcfbf11567486afe03b9d671ce8640a83ca557", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diss/chapters/prep.tex", "max_forks_repo_name": "benjimarshall/SequenceAlignment", "max_forks_repo_head_hexsha": "23fcfbf11567486afe03b9d671ce8640a83ca557", "max_forks_repo_licenses": ["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.3340757238, "max_line_length": 468, "alphanum_fraction": 0.7437124351, "num_tokens": 8610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6269792030835191}}
{"text": "% Created 2020-04-15 mié 17:46\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation,aspectratio=1610]{beamer}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble}\n\\usepackage{pgfplots}\n\\usepackage{pdfpages}\n\\usepackage{circuitikz}\n\\usepgfplotslibrary{groupplots}\n\\usetikzlibrary{positioning}\n\\renewcommand*{\\not}[1]{\\ensuremath{\\bar{#1}}}\n\\renewcommand*{\\not}[1]{\\ensuremath{\\overline{#1}}}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{Boolean algebra, logic diagrams and truth tables}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Boolean algebra, logic diagrams and truth tables},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.3.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Boolean algebra, minterms and maxterms}\n\\label{sec:org605a59f}\n\\begin{frame}[label={sec:orgb501097}]{AND and OR}\n\\(a, b \\in \\{0,1\\}\\)\n\\begin{columns}\n\\begin{column}{0.5\\columnwidth}\n\\begin{block}{AND}\n\\begin{center}\n\\begin{tabular}{|cc|c|}\n\\hline\n\\(a\\) & \\(b\\) & \\(a\\) AND \\(b\\), \\(ab\\)\\\\\n\\hline\n0 & 0 & 0\\\\\n0 & 1 & 0\\\\\n1 & 0 & 0\\\\\n1 & 1 & 1\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{center}\n\\begin{tikzpicture}\n  \\draw (0,0) to[switch, label=$a$, o-] (2,0) to[switch, label=$b$, -o] (4, 0);\n\\end{tikzpicture}\n\\end{center}\n\\alert{Closed circuit \\(\\Leftrightarrow\\) 1}\n\n\\alert{Open circuit \\(\\Leftrightarrow\\) 0}\n\n\\begin{center}\n\\includegraphics[width=0.5\\linewidth]{../../figures/and-gate.pdf}\n\\end{center}\n\\end{block}\n\\end{column}\n\n\\begin{column}{0.5\\columnwidth}\n\\begin{block}{OR}\n\\begin{center}\n\\begin{tabular}{|cc|c|}\n\\hline\n\\(a\\) & \\(b\\) & \\(a\\) OR \\(b\\), \\(a+b\\)\\\\\n\\hline\n0 & 0 & 0\\\\\n0 & 1 & 1\\\\\n1 & 0 & 1\\\\\n1 & 1 & 1\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{center}\n\\begin{tikzpicture}\n  \\draw (0,0) to[switch, label=$a$, o-o] (4,0);\n  \\draw (1,0) to[short] (1,-1) to[switch, l_=$b$, ] (3, -1) to[short] (3, 0);\n\\end{tikzpicture}\n\\end{center}\n\n\\begin{center}\n\\includegraphics[width=0.5\\linewidth]{../../figures/or-gate.pdf}\n\\end{center}\n\\end{block}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org1573679}]{NAND and NOR}\n\\(a, b \\in \\{0,1\\}\\)\n\\begin{columns}\n\\begin{column}{0.5\\columnwidth}\n\\begin{block}{NAND}\n\\begin{center}\n\\begin{tabular}{|cc|c|}\n\\(a\\) & \\(b\\) & \\(a\\) NAND \\(b\\), \\(\\overline{a\\cdot{}b}\\)\\\\\n\\hline\n0 & 0 & 1\\\\\n0 & 1 & 1\\\\\n1 & 0 & 1\\\\\n1 & 1 & 0\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{center}\n\\includegraphics[width=0.5\\linewidth]{../../figures/nand-gate.pdf}\n\\end{center}\n\\end{block}\n\\end{column}\n\n\\begin{column}{0.5\\columnwidth}\n\\begin{block}{NOR}\n\\begin{center}\n\\begin{tabular}{|cc|c|}\n\\(a\\) & \\(b\\) & \\(a\\) NOR \\(b\\), \\(\\overline{a+b}\\)\\\\\n\\hline\n0 & 0 & \\\\\n0 & 1 & \\\\\n1 & 0 & \\\\\n1 & 1 & \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{center}\n\\includegraphics[width=0.5\\linewidth]{../../figures/nor-gate.pdf}\n\\end{center}\n\\end{block}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\\begin{frame}[label={sec:org2d0b9ef}]{Boolean algebra, contd}\n\\(x, y, z \\in \\{0,1\\}\\)\n\n\\begin{center}\n\\begin{tabular}{r|c|c|}\n & Property & Dual\\\\\n\\hline\nProperties of 0 and 1 & \\(x+0=x\\) & \\(x\\cdot 0=0\\)\\\\\n & \\(x+1=1\\) & \\(x \\cdot 1 = x\\)\\\\\nIdempotency & \\(x+x=x\\) & \\(x\\cdot x = x\\)\\\\\nComplementarity & \\(x+\\not{x}=1\\) & \\(x\\cdot \\not{x}=0\\)\\\\\nInvolution & \\(\\not{\\not{x}}=x\\) & \\\\\nCommutative & \\(x+y=y+x\\) & \\(x\\cdot y = y\\cdot x\\)\\\\\nAssociative & \\((x+y) + z = x + (y+z)\\) & \\((xy)z = z(yz)\\)\\\\\nDistributive & \\(x\\cdot (y+z) = xy + xz\\) & \\(x+yz=(x+y)(x+z)\\)\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orge5065a4}]{Boolean algebra, contd}\n\\(x, y \\in \\{0,1\\}\\)\n\n\\begin{center}\n\\begin{tabular}{r|c|c|}\n & Theorem & Dual\\\\\n\\hline\nAbsorption & \\(x+xy=x(1+y)=x\\) & \\(x(x+y)=x\\)\\\\\nLogic adjacency & \\(xy + x\\not{y} = x(y+\\not{y}) =x\\) & \\((x+y)(x+\\not{y}) = x\\)\\\\\nDe Morgan's & \\(\\not{x+y}=\\not{x}\\cdot{}\\not{y}\\) & \\(\\not{xy} = \\not{x} + \\not{y}\\)\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd14be63}]{DeMorgan's theorem}\n\\begin{center}\n\\includegraphics[width=0.4\\linewidth]{../../figures/Demorganlaws.png} From wikipedia\n\\end{center}\n\\end{frame}\n\\begin{frame}[label={sec:orgbb8fe29}]{Simplify functions}\n\\begin{enumerate}\n\\item \\(f = (a+b)(a+c)\\)\n\\item \\(f = a + \\not{a}b\\)\n\\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:orgd9a80c9}]{Logic diagram \\(\\rightarrow\\) function}\nDetermine the function represented by the logic diagrams\n\\begin{center}\n\\includegraphics[width=0.7\\linewidth]{../../figures/exercise-gate-4.pdf}\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org42b2888}]{Function \\(\\rightarrow\\) logic diagram}\nDraw the diagram corresponding to the boolean function\n\\begin{enumerate}\n\\item \\(f = (a+b)(a+c)\\)\n\\item \\(f = a + \\not{a}b\\)\n\\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org98e40c3}]{Group exercise}\n\\begin{enumerate}\n\\item Enter breakout room\n\\item One of you downloads and shares this presentation\n\\item Work together on the problems in the previous three slides\n\\begin{enumerate}\n\\item Simplify functions\n\\item Determine function from logic diagram\n\\item Draw logic diagram from function\n\\end{enumerate}\n\\end{enumerate}\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "477775b4d68aaaa224cea20b69fe4f5a8278e193", "size": 5415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/logic-control/logic-control.tex", "max_stars_repo_name": "kjartan-at-tec/mr2015", "max_stars_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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/logic-control/logic-control.tex", "max_issues_repo_name": "kjartan-at-tec/mr2015", "max_issues_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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/logic-control/logic-control.tex", "max_forks_repo_name": "kjartan-at-tec/mr2015", "max_forks_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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.75, "max_line_length": 86, "alphanum_fraction": 0.6506001847, "num_tokens": 2118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6269792013572882}}
{"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\nFor questions 1 to 3, you are given the following relational schema.\n\n\\begin{terminal}\nStudents (@*\\underline{sid}*@:integer, sname:string, age:integer)\nGrades (@*\\underline{sid}*@:integer, @*\\underline{cid}*@:integer, grade:integer)\nCourses (@*\\underline{cid}*@:integer, cname:string, credits:integer)\n\\end{terminal}\n\nThe meaning of attributes is as follows.\n\n\\begin{enumerate}[topsep=0pt,itemsep=0ex,partopsep=5pt,parsep=0pt,label=-]\n\\item \\texttt{sid} : unique student identifier, primary key in table \\texttt{Students}\n\\item \\texttt{cid} : unique course identifier, primary key in table \\texttt{Courses}\n\\item \\texttt{sname} : student name\n\\item \\texttt{age} : student age\n\\item \\texttt{cname} : course name\n\\item \\texttt{credits} : number of credits for a course\n\\item \\texttt{grade} : the grade obtained by student identified by \\texttt{sid} for course identified by \\texttt{cid}; \\texttt{sid} and \\texttt{cid} are foreign keys referring to the \\texttt{sid} and \\texttt{cid} fields in the \\texttt{Students} and \\texttt{Courses} tables, respectively.\n\\end{enumerate}\n\n\\section*{Question 1}\n\nWrite \\textbf{relational algebra} expressions for the following queries given the schema above:\n\n\\begin{enumerate}[label=(\\alph*)]\n\n\\item Find the grades that students of age 20 obtained in courses with 4 credits.\n\n\\textbf{Solution:}\n\n$$ \\pi_{G.grade}(((\\sigma_{S.age=20}S)\\Join G)\\Join (\\sigma_{C.credits=4}C)) $$\n\n\\item Find the names of students who took a course named \\textit{Calculus} and did not get a \\textit{C} grade in any course.\n\n\\textbf{Solution:}\n\n$$ \\rho(S1,\\pi_{G.sid}((\\sigma_{C.cname='Calculus'}C)\\Join G)) $$\n$$ \\rho(S2,\\pi_{G.sid}(\\sigma_{G.grade='C'}G)) $$\n$$ \\pi_{S.sname}((S1-S2)\\Join S) $$\n\n\\item Find the ages of students who got an \\textit{A} in some course with 3 credits or who got a \\textit{B} in any course.\n\n\\textbf{Solution:}\n\n$$\\rho(S1,\\pi_{S.sid}((\\sigma_{G.grade='A'}((\\sigma_{C.credits=3}C)\\Join G))\\Join S)) $$\n$$\\rho(S2,\\pi_{G.sid}(\\sigma_{G.grade='B'}G)) $$\n$$ \\pi_{S.age} ((S1\\cup S2)\\Join S) $$\n\n\\item Find the maximum age among students who took \\textit{Calculus}.\n\n\\textbf{Solution:}\n\n$$ \\rho(S1,(((\\sigma_{C.cname='Calculus'}Courses)\\Join Grades)\\Join Students) ) $$\n$$ \\rho(S2(1\\rightarrow sid2,2\\rightarrow sname2, 3\\rightarrow age2),S1) $$\n$$ \\rho(S3(1\\rightarrow sid), \\pi_{S1.sid}(S1\\Join_{S1.age<S2.age2} S2)) $$\n$$ \\pi_{Students.age}((Students - S3)\\Join Students ) $$\n\n\\end{enumerate}\n", "meta": {"hexsha": "cf6e1e9f2ee0dc0cd1856450759b67f8ed757592", "size": 2793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/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-cs630-2014f/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-cs630-2014f/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": 42.3181818182, "max_line_length": 287, "alphanum_fraction": 0.6774078052, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6269742983713905}}
{"text": "%Chapter \"Computational aspects\"\n%\n\\graphicspath{ {./img/Computational/} }\n\\chapter{Computational aspects}\n\\label{chap: Computational Aspects}\n\\section{Global assembly}\nIn this section we will discuss the fundamental process of building the system of algebraic equations through the addition or assembly of elemental coefficient matrices as described by \\cref{eq:assem} where $K^G$ is the global coefficient matrix; $k^i$ is the local elemental matrix for the $i$-th element; $\\assem_{i=1}^{Numel}$ is the assembly operator and $i$ is an element index ranging between $1$ and the total number of elements $Numel$ that conform the finite element model. Notice that the assembly operator is analogous to the sum operator commonly used in the representation of a series of $N$ terms but it contains information indicating the position of each single term from the element coefficient matrix within the global system.\n\\begin{equation}\\label{eq:assem}\n{K^G}=\\assem_{i=1}^{Numel} k^i.\n\\end{equation}\n\nIn this section we will describe the fundamental algorithmic steps to perform that process. We first summarize the basic general steps and then illustrate the process through a simple example involving a $2D$ mesh of 4-noded elements. The section is complemented with the Python scripts {\\bf GLOBAL.py} and the secondary module {\\bf assemutil.py}.\n\n\\subsection*{The assembly algorithm}\nThe process of assembly of the elemental coefficient matrices into the global system involves (i) the identification of the active degrees of freedom (or equation numbers) assigned to each node in the mesh (ii) the identification of the relationship between the elemental degrees of freedom and the global degrees of freedom and (iii) the computation of the coefficient matrix for each element in the model.\n\nThe first step is easily accomplished by assigning a boundary condition flag to the degrees of freedom existing at each node. Here we use a $0$ value to indicate an active degree of freedom and a $-1$ to indicate a prescribed degree of freedom. This information is stored in a boundary condition array $IBC$, of dimension $nn \\times MDIM$, where $nn$ corresponds to the  total number of nodal points and $MDIM$ represents the problem dimensionality. The $IBC$ array is first input by the user and later modified by the program in a process where the boundary condition flag is read and equations are counted and assigned according to the result. If the boundary condition flag is equal to $0$ the program assigns an equation number while it produces a $0$ value if the flag is equal to $-1$.\n\nIn the second step the nodes conforming each element are stored in a connectivity array  $IELCON$ of dimension $Numel \\times MxNNel$ where $Numel$ is the number of elements in the model and $MxNNel$ is the maximum number of nodes in a given element. Thus each row in the $IELCON$ array stores the nodal point data for the element. Each entry in the $IELCON$ array can now be directly translated into equation numbers using the processed $IBC$ array. This results in the discrete version of the assembly operator $\\assem_{i=1}^{Numel}$ also called the assembly list or the $DME$ operator in our codes.\n\nIn the final step the mesh is covered one element at a time and each elemental coefficient matrix is assembled into the global matrix as indicated by the $DME$ operator. The actual computation of the elemental matrix is conducted by an element based subroutine, called here $UEL$, which may be different for each element in the mesh according to different kinematic o material assumptions. The complete process is summarized in \\cref{algo:overall} where we describe for completeness additional steps involved in the finite element algorithm. We have introduced additional global and elemental arrays $RHS^G$ and $rhs^i$ respectively, storing the element nodal excitation and the resulting vector of global excitation. This vector is assembled simultaneously, and using the same data, with the global coefficient matrix. In the final step in the finite element algorithm the system of equations is solved. Notice that the essential boundary conditions were already considered during the assembly process and as a result the global algebraic system of equations is ready to be solved. Finally, after the system has been properly solved the nodal results are scattered through the elements in a process which is inverse to the assembly operation but that uses the same information contained in the $DME$ operator.\n\n\\begin{algorithm}[H]\\label{algo:overall}\n\\SetAlgoLined\n\\KwData{Finite element model}\n\\KwResult{Field function}\n\\BlankLine\nREAD $IBC$ and $IELCON$ arrays ;\\\\\nCompute modified $IBC$ array ;\\\\\nCompute $DME$ operator (using $IBC$ and $IELCON$ arrays);\\\\\n$K^G \\leftarrow 0.0$;\\\\\n\\BlankLine\n\\For{$i \\leftarrow 1$ to $Numel$}{\n    Call UEL(element parameters;$K^i$) ;\\\\\n    $K^G \\leftarrow K^G+K^i$ (Assemble each $k^i$ into $K^G$ according to the $DME$ operator);\\\\\n    $RHS^G \\leftarrow RHS^G+rhs^i$ (Assemble each $rhs^i$ into $RHS^G$);\\\\\t\n\t\\BlankLine\n\t}\n\\BlankLine\nSolve ${K^G}{U^G} = RH{S^G}$;\\\\\nScatter solution to the elements\n\\caption{Summarized algorithm for the finite element method}\n\\end{algorithm}\n\\newpage\n\n\\subsection*{Sample problem}\nConsider the mesh shown in \\cref{fig:quad}. The problem parameters in this case are $nn=9$, $Numel=4$ and $MxNNel=4$.\n\n\\begin{figure}[h]\\label{fig:quad}\n\\centering\n\\includegraphics[width=10cm]{mesh2.pdf}\n\\caption{Finite element mesh of 4-noded elements. The global matrix can be assembled using the python scripts {\\bf GLOBAL.py} and the secondary module {\\bf assemutil.py}. The input files required to run the script are called {\\bf nodes.txt} and {\\bf eles.txt}}\n\\end{figure}\n\n\n\nThe array of boundary conditions as input from the user corresponds to\n\\[IBC = \\begin{bmatrix}\n-1 & -1\\\\\n-1 & -1\\\\\n-1 & -1\\\\\n-1 & 0\\\\\n0 & 0\\\\\n0 & 0\\\\\n-1 & -1\\\\\n-1 & -1\\\\\n-1 & -1\n\\end{bmatrix}\\]\n\nwhile its code-modified version reads\n\\[IBC = \\begin{bmatrix}\n0 & 0\\\\\n0 & 0\\\\\n0 & 0\\\\\n0 & 1\\\\\n2 & 3\\\\\n4 & 5\\\\\n0 & 0\\\\\n0 & 0\\\\\n0 & 0\n\\end{bmatrix}\\]\n\nNotice that the program changes each $-1$ entry to a $0$ valued entry and assigns an equation number to the position containing an original $0$ entry during an equation-assigning and equation-counting operation. Similarly, the element connectivity for the current example read\n\\[IELCON = \\begin{bmatrix}\n1 &2 &5 &4\\\\\n2 &3 &6 &5\\\\\n4 &5 &8 &7\\\\\n5 &6 &9 &8\n\\end{bmatrix}\\]\n\nThe so-called $DME$ operator is actually the same $IELCON$ but translated into equation numbers for each element. Accordingly in the current example we have\n\\[DME = \\begin{bmatrix}\n0 &0 &0 &0 &2 &3 &0 &1\\\\\n0 &0 &0 &0 &4 &5 &2 &3\\\\\n0 &1 &2 &3 &0 &0 &0 &0\\\\\n2 &3 &4 &5 &0 &0 &0 &0\n\\end{bmatrix}\\]\n\nThe definition of the element connectivity and its subsequent translation into degrees of freedom is carried out according to a local element definition like the one shown in \\cref{fig:locdof}\n\n\\begin{figure}[H]\\label{fig:locdof}\n\\centering\n\\includegraphics[width=8cm]{localdof.pdf}\n\\caption{Local definition for a 4-noded element.}\n\\end{figure}\n\nAs a result the $(i,j)$ entry in the $DME$ corresponds to the global equation number associated with the local degree of freedom $j$ of the $i$ element. For instance the value of $4$ stored at position $(2,5)$ in the current $DME$ indicates that the global equation $4$ corresponds to the local equation $5$ (column index) in element $2$ (row index).\n\nThe assembly process is then conducted by identifying the relation between the entries in each row of the $DME$ operator and the list of local degrees of freedom for the reference element shown in \\cref{fig:locdof}. Accordingly, for element 2 it follows that the assembly of row $5$ of the local stiffness matrix proceeds as follows\n\\begin{align*}\nK_{4,4}^G & \\leftarrow  K_{4,4}^G + k_{5,5}^2 \\\\\nK_{4,5}^G & \\leftarrow  K_{4,5}^G + k_{5,6}^2 \\\\\nK_{4,3}^G & \\leftarrow  K_{4,3}^G + k_{5,8}^2\n\\end{align*}\n\nIn \\cref{algo:overall} it must be noticed that the local stiffness matrix for each $i$ element is obtained by the call to the local element subroutine $UEL$. In the script GLOBAL.py these elemental routines produce a fictitious matrix filled out with ones and the actual computation of the elemental coefficient matrix is discussed later.\n\n\n\\section{Sparse assembly}\nIn Finite Elements is common to have stiffness and mass matrices that are sparse, i.e., matrices in which most of the elements are zero.\n\n\nFor instance, in a regular mesh formed with bilinear quadrilaterals the number of nonzero entries is given by the expression\n\\[\\text{storage} = 9 n_x n_y - 9 n_x - 3 n_y + 4\\, ,\\]\nwhere $n_x$ is the number of nodes in the $x$ coordinate and $n_y$ is the number of nodes in the $y$ coordinate. Figure \\ref{fig:sparse_storage} presents the needed storage for a mesh with $n_x=n_y$ for different sizes.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=6 in]{sparse_storage.pdf}\n\\caption{Nonzero entries in a sparse matrix for a structured mesh of bilinear elements.}\n\\label{fig:sparse_storage}\n\\end{figure}\n\n\\section{Python implementations}\n\n\n\\section{Commercial codes and user subroutines}\n\n\n\n\n\n", "meta": {"hexsha": "f026755a7ce5b5a33a168aaf60d9e53531b74cf2", "size": 9139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/computational.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/computational.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/computational.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": 64.3591549296, "max_line_length": 1310, "alphanum_fraction": 0.7575227049, "num_tokens": 2415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6269742965106424}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{cycle}\n\\author{nguyenngockhanh.pbc }\n\\date{April 2021}\n\n% cases\n\\usepackage{amsmath}\n% symbol\n\\usepackage{amssymb}\n\n\n\n\\newtheorem{definition}{Definition}\n\\newtheorem{theorem}{Theorem}\n\n\\begin{document}\n\n    \\maketitle\n\n    \\textbf{Is there an natural number function that always has a cycle and the cycle length is unbounded?}\n\n\n    \\section{Problem}\\label{sec:problem}\n\n    Firstly, let define precisely the notations we are using in this text.\n\n    \\begin{definition}(Natural Number Set)\n        \\begin{equation}\n            \\label{eq:natural}\n            \\mathbb{N} = \\{ 1, 2, 3, \\dots \\}\n        \\end{equation}\n    \\end{definition}\n\n    \\begin{definition}(Natural Number Function)\n        All functions that have the domain and codomain $\\mathbb{N}$\n        \\begin{equation}\n            \\label{eq:function}\n            f: \\mathbb{N} \\to \\mathbb{N}\n        \\end{equation}\n    \\end{definition}\n\n    Denote $f^m(n)$ where $n \\in \\mathbb{N}$ be the value of $m$-times recursive call of function $f$ to input $n$.\n    More formally,\n\n    \\begin{gather*}\n        f^1(n) = f(n),\\\\\n        f^{m+1}(n) = f(f^m(n))\\\\\n    \\end{gather*}\n\n\n    \\begin{definition}(Cycle number of a Natural Number Function)\n        Let $f: \\mathbb{N} \\to \\mathbb{N}$.\n        A cycle set of $n$ is the set of all numbers $m \\in \\mathbb{N}$ such that $f^m(n) = n$\n\n        \\begin{equation}\n            \\label{eq:cycle_set}\n            c^{(f)}(n) = \\{m : m \\in \\mathbb{N} \\land f^m(n) = n \\}\n        \\end{equation}\n        if cycle set is non-empty, define the cycle number as the smallest number in the cycle set\n        \\begin{equation}\n            \\label{eq:cycle_number}\n            c^{(f)}_{\\min}(n) = \\min{c^{(f)}(n)}\n        \\end{equation}\n    \\end{definition}\n\n    In this text, we ignore the trivial case where cycle number is 1.\n\n    Our main theorem is stated as follows\n\n    \\begin{theorem}(Cycle)\n        There exists a natural number function such that (1) it has a non-trivial cycle number for every input and (2) the set of all cycle numbers is unbounded.\n\n        \\begin{equation}\n            \\label{eq:cycle_theorem}\n            \\exists f : \\mathbb{N} \\to \\mathbb{N}, (\n            \\forall n \\in \\mathbb{N},\n            c^{(f)}_{\\min}(n) > 1\n            ) \\land (\n            \\forall m_0 \\in \\mathbb{N},\n            \\exists n \\in \\mathbb{N},\n            c^{(f)}_{\\min}(n) \\geq m_0\n            )\n        \\end{equation}\n    \\end{theorem}\n\n    In other words, this function partitions the natural number set into infinitely number of finite subsets where the cardinality of them are unbounded.\n    Each cycle is associated with a subset.\n\n\n    \\section{Proof}\\label{sec:proof}\n\n    A simple construction satisfies those properties is as follows:\n\n    Suppose we found partition on $\\mathbb{N}$ of ($1^*$) infinitely many finite subsets where ($1^{**}$) each of them has the cardinality of at least 2, ($2^*$) the cardinality of these subsets is unbounded.\n\n    \\begin{equation}\n        \\label{eq:partition}\n        \\mathbb{P} = \\{ P_i \\}_{i=1}^\\infty = \\{ P_1, P_2, P_3, \\dots \\}\n    \\end{equation}\n\n    Where we order all elements in each $P_i$, so that for every $P_i$, we have a minimum element, a maximum element and a function to yield the successor element if the input is not the maximum element namely\n\n    \\begin{equation}\n        \\label{eq:succ_func}\n        succ_i : P_i \\backslash \\{ \\max{P_i} \\} \\to P_i \\backslash \\{ \\min{P_i} \\}\n    \\end{equation}\n\n    Define a function $f_i: P_i \\to P_i$ that returns minimum element of $P_i$ if the input is the maximum element of $P_i$, otherwise return its successor.\n\n    \\begin{equation}\n        \\label{eq:func_sub}\n        f_i(n)=\n        \\begin{cases}\n            \\min P_i &\\text{if $n = \\max P_i$}.\\\\\n            succ_i(n) &\\text{otherwise}.\n        \\end{cases}\n    \\end{equation}\n\n    This function has a cycle number of the cardinality of $P_i$\n    Since $\\mathbb{P}$ is a partition, these $P_i$ are disjoint and their union is $\\mathbb{N}$.\n    We define the function $f: \\mathbb{N} \\to \\mathbb{N}$\n\n    \\begin{equation}\n        \\label{eq:func}\n        f(n)= f_i(n) \\text{ if } n \\in P_i\n    \\end{equation}\n\n    ($1^* \\land 1^{**} \\to 1$) For every input $n$, the cycle number is $|P_i| \\geq 2$ where $P_i$ is the associated subset. ($2^* \\to 2$) Since these subsets are unbounded in size, the set of all cycle numbers of $f$ is also unbounded.\n\n    In order to finish the proof, we will show a partition on $\\mathbb{N}$ that satisfies ($1^*$), ($1^{**}$) and ($2^*$).\n\n    Let $S_i$ be the set of all natural numbers in the range $[2^i, 2^{i+1})$ for $i=0, 1, 2, \\dots$.\n    e.g. $S_0 = \\{ 1 \\}$, $S_1 = \\{ 2, 3 \\}$, $S_2 = \\{ 4 , 5, 6, 7 \\}$, $S_3 = \\{ 8, 9, \\dots, 15 \\}$, etc.\n\n    Our partition is in the form\n\n    \\begin{equation}\n        \\label{eq:partition_concrete}\n        \\mathbb{P} = \\{\\{ S_0 \\cup S_1 \\}\\} \\cup \\{ S_i \\}_{i=2}^\\infty\n    \\end{equation}\n\n\n\\end{document}\n", "meta": {"hexsha": "b0613910098ad4919c0cb620387b2c80073f8053", "size": 4990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blog/cycle/tex/main.tex", "max_stars_repo_name": "khanhhhh/khanhhhh.github.io", "max_stars_repo_head_hexsha": "f6313f0228a480b37e5f4ba9550e3cf011e60ba8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-14T08:27:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T14:51:34.000Z", "max_issues_repo_path": "blog/cycle/tex/main.tex", "max_issues_repo_name": "khanh-nguyen-code/khanh-nguyen-code.github.io", "max_issues_repo_head_hexsha": "4c047a941720e46b004d0bb922507c3b2bc7132f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blog/cycle/tex/main.tex", "max_forks_repo_name": "khanh-nguyen-code/khanh-nguyen-code.github.io", "max_forks_repo_head_hexsha": "4c047a941720e46b004d0bb922507c3b2bc7132f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-30T05:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T05:30:49.000Z", "avg_line_length": 34.1780821918, "max_line_length": 236, "alphanum_fraction": 0.5991983968, "num_tokens": 1594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996144, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6269742925003878}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\t\\chapter{Classification of numbers}\n\t\n\t\\begin{itemize}\n\t\t\\item{Natural numbers: $\\mathbb{N}$; (1, 2, 3, 4 \\ldots)}\n\t\t\\subitem{This set includes every number which is both positive and whole.}\n\t\t\\item{Integer numbers: $\\mathbb{Z}$; (-2, -1, 0, 1, 2, \\ldots)}\n\t\t\\subitem{The integer number set includes every negative and positive whole numbers, similarly to $\\mathbb{N}$}\n\t\t\\item{Rational numbers: $\\mathbb{Q}$; (-1, 2 , $\\frac{1}{2}$)}\n\t\t\\subitem{A number is s.t.b rational if expressed in the form $\\frac{p}{q};p, q \\in \\mathbb{Z}$.}\n\t\t\\item{Irrational numbers: $\\mathbb{Q'}$; ($\\pi, e, \\sqrt{2}, \\sqrt{5}, \\ldots$))}\n\t\t\\subitem{If a number is not classified as any of the above, it is referred to as irrational.}\n\t\t\\item{Real numbers: $\\mathbb{R}$}\n\t\t\\subitem{Anything mentioned above inclusively represent the set of Real numbers}\\\\\n\t\\end{itemize}\n\t\n\t\n\t\\emph{We can additionally refer to positive or negative numbers in any set by using the notation:}\\\\\n\t\\begin{center}\n\t\t$\\mathbb{R}^+$ and $\\mathbb{R}^-$\n\t\\end{center}\n\t%TODO: insert image of sets\n\t\n\t\n\t\\newpage\t\n\t\\end{document}", "meta": {"hexsha": "c6acb14d3e8aea1ca66ab695049fd5718a71209d", "size": 1127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Class_of_Numbers.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/Class_of_Numbers.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/Class_of_Numbers.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": 41.7407407407, "max_line_length": 112, "alphanum_fraction": 0.6796805679, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6269742925003877}}
{"text": "\\documentclass[../../../thesis.tex]{subfiles}\n\n\\begin{document}    \n    \n    \\section{Localization}\n    \n        We will briefly explain the localization of a category at a set. We will look at local objects and localizations by adjoint functors. This section is based on \\cite{Krause21}.\n\n        \\subsection{Definition and Local Objects}\n\n            The localization of a category at some set of morphisms is a universal category where these morphisms have been inverted. In this manner, we will think of the localization as adding formal inverses to the morphisms in this set to the category.\n\n            \\begin{definition}\n                Let $\\mathcal{C}$ be a category and $S \\subseteq Mor(\\mathcal{C})$ a set of morphisms in $\\mathcal{C}$. We define the localization of $\\mathcal{C}$ at $S$ as a category $\\mathcal{C}[S^{-1}]$ together with a functor $Q : \\mathcal{C} \\rightarrow \\mathcal{C}[S^{-1}]$ satisfying the properties:\n                \\begin{enumerate}\n                    \\item For any morphism $s\\in S$, $Qs$ is an invertible morphism.\n                    \\item Any functor $F : \\mathcal{C} \\rightarrow \\mathcal{D}$ satisfying $Fs$ is invertible if $s\\in S$ factors through $Q$. Thus there exists a unique functor $\\bar{F} : \\mathcal{C}[S]^{-1} \\rightarrow \\mathcal{D}$ and a natural isomorphism $\\alpha : F \\implies \\bar{F} \\circ Q$ relating the functors.\n                \\end{enumerate}\n\n                \\begin{center}\n                    \\begin{tikzcd}\n                        \\mathcal{C} \\ar{rd}{Q} \\ar{rr}{F} & & \\mathcal{D} \\\\\n                        & \\mathcal{C}[S^{-1}] \\ar[dashed]{ur}{\\bar{F}}\n                    \\end{tikzcd}\n                \\end{center}\n            \\end{definition}\n\n            Informally, the category $\\mathcal{C}[S^{-1}]$ may be constructed as the category with the same objects as $\\mathcal{C}$. The morphisms are constructed with paths of morphisms in $\\mathcal{C}$, where we also allow formal inverse paths $s^{-1}$ for any morphism in $S$. The constant paths would be the new identity morphisms, while every path from an object $X$ to $Y$ represents a morphism.\n\n            \\begin{remark}\n                Beware whenever localizing a locally small category. Adding more morphisms to this category may make some set of morphisms between objects big.\n            \\end{remark}\n\n            By the universality of the functor $Q$ we have the following lemma.\n\n            \\begin{lemma}\n                Let $\\mathcal{D}$ be a category, then the pre-composition functor is fully faithful.\n                \\begin{align*}\n                    \\_ \\circ Q : Fun(\\mathcal{C}[S^{-1}],\\mathcal{D}) & \\rightarrow Fun(\\mathcal{C}, \\mathcal{D}) \\\\\n                    F & \\mapsto F \\circ Q\n                \\end{align*}\n                Moreover, we may identify $Fun(\\mathcal{C}[S^{-1}],\\mathcal{D})$ as the full subcategory of functors in $Fun(\\mathcal{C}, \\mathcal{D})$ which sends every morphism in $S$ to an isomorphism.\n            \\end{lemma}\n\n            We proceed to define $S$-local objects, and informally, these are all the objects which does not change after the localization process.\n\n            \\begin{definition}\n                An object $Y\\in \\mathcal{C}$ is called $S$-local ($S$-closed or $S$-orthogonal) if for any $s\\in S$, the map $\\mathcal{C}(s, Y)$ is a bijection. Define $S\\perp$ to be the full subcategory of $S$-local objects.\n            \\end{definition}\n\n            The following lemma gives an equivalent definition for \"localness\".\n\n            \\begin{lemma}\n                An object $Y\\in \\mathcal{C}$ is $S$-local if and only if the canonical map $q$ is a natural isomorphism.\n                \\begin{align*}\n                    q_{X,Y} : \\mathcal{C}(X,Y) \\rightarrow \\mathcal{C}[S^{-1}](X,Y)\n                \\end{align*}\n            \\end{lemma}\n\n        \\subsection{Localizing at Adjoint Functors}\n\n            Given two functors $F : \\mathcal{C} \\rightarrow \\mathcal{D}$ and $G : \\mathcal{D} \\rightarrow \\mathcal{C}$ such that they form an adjoint pair $F \\dashv G$, we want to see how they react with localizations.\n\n            \\begin{proposition}\n                Let $F \\dashv G$ be an adjoint pair as above, and define $S = $\\startset{$s\\in Mor\\mathcal{C}$ $\\mid$ $Fs$ is invertible}. Draw out the following diagram, with the relations $F = \\bar{F}\\circ Q$.\n                \\begin{center}\n                    \\begin{tikzcd}\n                        & \\mathcal{C} \\ar{ld}[description]{Q} \\ar[bend right = 20]{dd}[description]{F} \\\\\n                        \\mathcal{C}[S^{-1}] \\ar{rd}[description]{\\bar{F}} \\\\\n                        & \\mathcal{D} \\ar[bend right = 20]{uu}[description]{G}\n                    \\end{tikzcd}\n                \\end{center}\n                The following are equivalent:\n                \\begin{enumerate}\n                    \\item $G$ is fully faithful.\n                    \\item The counit $\\varepsilon : FG \\implies Id_\\mathcal{D}$ is invertible for any object $X\\in \\mathcal{D}$.\n                    \\item The functor $F$ induces an equivalence $\\bar{F}:\\mathcal{C}[S^{-1}] \\rightarrow \\mathcal{D}$.\n                \\end{enumerate}\n            \\end{proposition}\n        \n            In the light of the last proposition, we may define \"short exact sequences\" of pre-additive categories.\n\n            \\begin{definition}\n                Suppose there is a diagram of additive functors like below.\n                \\begin{center}\n                    \\begin{tikzcd}[column sep = large]\n                        \\mathcal{A} \\ar[bend left = 30, tail]{r}{E} \\ar[phantom]{r}{\\bot} & \\mathcal{B} \\ar[bend left = 30, two heads]{r}{F} \\ar[bend left = 30, two heads]{l}{E_\\rho} \\ar[phantom]{r}{\\bot} & \\mathcal{C} \\ar[bend left = 30, tail]{l}{F_\\rho}    \n                    \\end{tikzcd}\n                \\end{center}\n                It is called a localization sequence whenever the following holds:\n                \\begin{enumerate}\n                    \\item $(E,E_\\rho)$ and $(F,F_\\rho)$ are adjoint pairs.\n                    \\item $E$ and $F_\\rho$ are fully faithful.\n                    \\item $ImE \\simeq KerF$.\n                \\end{enumerate}\n            \\end{definition}\n\n\\end{document}", "meta": {"hexsha": "2a570727b040842d658be8b1b158b602510bb5db", "size": 6187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/localization/localization.tex", "max_stars_repo_name": "CelestialCry/Strongly-Homotopic-Quasi-iso", "max_stars_repo_head_hexsha": "a01fabe6f916696b7f3ad94af6014333117da208", "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/localization/localization.tex", "max_issues_repo_name": "CelestialCry/Strongly-Homotopic-Quasi-iso", "max_issues_repo_head_hexsha": "a01fabe6f916696b7f3ad94af6014333117da208", "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/localization/localization.tex", "max_forks_repo_name": "CelestialCry/Strongly-Homotopic-Quasi-iso", "max_forks_repo_head_hexsha": "a01fabe6f916696b7f3ad94af6014333117da208", "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.1326530612, "max_line_length": 402, "alphanum_fraction": 0.5737837401, "num_tokens": 1651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.6269742867256378}}
{"text": "\\chapter{Classification}\nLinear regression discussed in the previous chapter assumes a quantitative response value Y but often classification is needed to solve a problem. Consider the binary classification problem: Predicting whether a tumor is malignant or not based on the size of the tumor. Linear regression could be used by converting the wanted qualitative response variable into a quantitative response. The quantitative response can be converted into a qualitative response by saying that $p(maligant = true | tumorsize) > 0.5$. The model would then classify a tumor as malignant if the probability is higher than 0.5. \n\nA problem though arises from this, since the model will make estimates outside the interval $[0,1]$. Because some predictions are outside of this interval, then the prediction can not be thought of as probabilities. For example measuring a tumor size of 0 would predict a negative value. Another problem with linear regression is that it can not be extended to a classification problem with more than two classes. It can only be used for binary classification. The reason for this is that there might not be a natural ordering between the different classes and the gap between some classes might be bigger than others. This would make it difficult to make an accurate model using a linear regression \\citep[pp. 129-130]{ISLR}. Instead this chapter presents different methods that are more suited for classification.\n\n\\section{Logistic Regression}\n\\label{chp:logreg}\nLogistic regression is a classification method. It avoids the problem with values outside the interval of $[0,1]$. In logistic regression a logistic function is used and can be seen in (3.1).\n\n\\begin{equation}\n\tp(X) = \\dfrac{e^{\\beta_0 + \\beta_1 X}}{1 + e^{\\beta_0 + \\beta_1 X}}\n\\end{equation}\n\nBy taking the exponential of $\\beta_0 + \\beta_1 X$ the result will always be equal to or higher than 0. By dividing by the same equation + 1 the prediction will never be higher than 1. In the equation $\\beta_0$ and $\\beta_1$ is similar to what is used in linear regression. $\\beta_0$ describes the probability when the predictor is 0 and $\\beta_1$ is the regression coefficient that is multiplied  with the predictor. The equation can be extended to multiple logistic regression using multiple predictors. Instead the equation looks as shown in (3.2).\n\n%\\begin{center}\n%\t$p(X) = \\dfrac{e^{\\beta_0 + \\beta_1 X_1 + ... + \\beta_p X_p}}{1 + e^{\\beta_0 + \\beta_1 X_1 + ... + \\beta_p X_p}}$ \n%\\end{center}\n\n\\begin{equation}\n\tp(X) = \\dfrac{e^{\\beta_0 + \\beta_1 X_1 + ... + \\beta_p X_p}}{1 + e^{\\beta_0 + \\beta_1 X_1 + ... + \\beta_p X_p}}\n\\end{equation}\n\n%\\todo{måske indsæt en figur der viser grafer med linear og logistic}\n\n\\subsection{Lab 4.6.1 - The Stock Market Data}\nIn this lab the correlation between the predictors and todays return value is examined. Todays return value describes the direction. If the number is negative the stock went down and if it is positive the stock went up. The available predictors are 5 lagging indicators \\emph{Lag1, Lag2, Lag3, Lag4} and \\emph{Lag5} and a \\emph{Volume} which describes the number of shares traded in billions.\n\nWith the python code shown in Listing \\ref{lst:correlation} a matrix with the pairwise correlation among the predictors and todays return is printed. Numpy is used for calculating the correlation matrix. Pandas is used for creating a table based on the calculated correlation matrix.\n\n\\begin{lstlisting}[language=Python, label=lst:correlation, caption=Printing correlation matrix]\ncor = np.corrcoef(preparedData)\nlabels = ['Year', 'Lag1', 'Lag2', 'Lag3', 'Lag4', 'Lag5', 'Volume', \n'Today']\ndf = pd.DataFrame(cor, columns=labels, index=labels)\nprint df\n\\end{lstlisting}\n\nThe printed correlation matrix is illustrated in figure \\ref{fig:lab461}. Here it is shown that there is very little correlation between the different Lag variables and todays return. This also makes sense because the variables are lagging indicators and therefore it only changes after the economy has already changed. For example if \\emph{Lag1} describes how the market went up yesterday then it is less likely to go up today. An interesting correlation can be seen between \\emph{Year} and \\emph{Volume}. This indicates that each year the average number of traded stocks increases. \n\n\\myFigure{461.png}{Pairwise correlation matrix between predictors and todays return}{fig:lab461}{1} \n\\FloatBarrier\n\n\\myFigure{461_plot.png}{Correlation between Volume and Year. Higher index describes forward in time}{fig:lab461Plot}{0.45}\n \n\\emph{Volume} is plotted in figure \\ref{fig:lab461Plot}. Here the increase in traded stock is obvious. When choosing predictors in our logistic regression model it must be noted that a correlation matrix not necessarily describes the best predictors, at least not if multiple predictors are used. When choosing predictors it is important to choose the predictors that actually are associated with the response variable. The following lab will therefore examine the data to find good predictors.\n\n\\subsection{Lab 4.6.2 - Logistic Regression}\n\\label{sec:lab462}\nIn this lab a logistic regression model is made based on the stock market data. The predictors were examined in Lab 4.6.1 and some of the predictors will be chosen to predict the direction of the stock market. The direction can either be \\emph{up} or \\emph{down} and hence this is a binary classification problem.\n\nIn the exercise the p-values will first be examined. This is done by fitting a logistic model with the predictors \\emph{Lag1, Lag2, Lag3, Lag4, Lag5} and \\emph{Volume} to predict the \\emph{direction}. The statsmodels python library is used to print a summary of the fitted model. This is shown in listing \\ref{lst:summary}.\n\n\\begin{lstlisting}[language=Python, label=lst:summary, caption=Printing summary]\nformula = 'Direction ~ Lag1+Lag2+Lag3+Lag4+Lag5+Volume'\nmodel = smf.glm(formula=formula, data=data, family=sm.families.Binomial())\nprint(model.fit().summary())\n\\end{lstlisting}\n\n\\myFigure{Lab462Pvalue.PNG}{Summary of data with associated p-value describing good predictors}{fig:lab462Pvalue}{0.6} \n\\FloatBarrier\n\nThe printed summary is illustrated in figure \\ref{fig:lab462Pvalue}. Here it is  seen that the lowest p-value is \\emph{Lag1} but it still has a value of 0.145, which is still quite high and it presents no evidence of any association between \\emph{Lag1} and \\emph{Direction}. But note here that only using the predictors with the lowest p-value could yield the most accurate result when predicting the \\emph{Direction}. The reason for this is that some predictors have so little association with the \\emph{Direction} that they will only make the prediction less accurate. This will also be shown in the following examples.\n\n\nIn Listing \\ref{lst:AllPredictors} the training data is divided into a training set and a test set. Then all the data from 2004 and before is used to train our logistic model and then it is tested on the data from 2005. In this implementation all predictors are used to fit the logistic model.\n\n\\begin{lstlisting}[language=Python, label=lst:AllPredictors, caption=Logistic regression using all predictors]\nX_train = data[:'2004'][['Lag1', 'Lag2', 'Lag3', 'Lag4', 'Lag5', 'Volume']]\nY_train = data[:'2004']['Direction']\n\nX_test = data['2005':][['Lag1', 'Lag2', 'Lag3', 'Lag4', 'Lag5', 'Volume']]\nY_test = data['2005':]['Direction']\n\nlr = linear_model.LogisticRegression()\nlr.fit(X_train,Y_train)\n\\end{lstlisting}\n\nBased on the test data it is examined how well our logistic model predicts the \\emph{Direction}. In Listing \\ref{lst:LRscore} a score method is called for the logistic regression model. This function returns the mean accuracy of the model. The score shows that the model only predicts correctly $48.8\\%$ of the time. Based on this result the model needs to be approved upon.\n\\begin{lstlisting}[language=Python, label=lst:LRscore, caption=Printing mean accuracy]\nprint(lr.score(X_test, Y_test))\n\\end{lstlisting}\n\nIn Listing \\ref{lst:OnlyLag1Lag2} only the predictors \\emph{Lag1} and \\emph{Lag2} are now used. \\emph{Lag1} is included because it has the lowest p-value. \\emph{Lag2} is also used as predictor because it has a very low correlation with \\emph{Lag1} and also the third lowest p-value.\n%It has a very low correlation with \\emph{Lag1} and also the third lowest p-value.\nNote though that the p-value of \\emph{Lag2} is only 0.006 higher than the second lowest p-value, which describes \\emph{Volume}. \\emph{Volume} also has almost twice as high correlation with \\emph{Lag1} and this might lead to a better result using \\emph{Lag1} and \\emph{Lag2} for prediction.\n\n\\begin{lstlisting}[language=Python, label=lst:OnlyLag1Lag2, caption=Logistic regression using only Lag1 and Lag2 as predictors]\nX_train = data[:'2004'][['Lag1', 'Lag2']]\nY_train = data[:'2004']['Direction']\n\nX_test = data['2005':][['Lag1', 'Lag2']]\nY_test = data['2005':]['Direction']\n\nlr = linear_model.LogisticRegression()\nlr.fit(X_train,Y_train)\n\\end{lstlisting}\n\nUsing only \\emph{Lag1} and \\emph{Lag2} as predictors gave a better result. Running the score function in Listing \\ref{lst:LRscore} showed a mean accuracy of $56\\%$. By only using \\emph{Lag1} and \\emph{Lag2} the model has been improved. This combination of predictors also showed the most accurate for predicting the \\emph{Direction}. Using p-values for choosing predictors is important and provides information about the association when multiple predictors  are used.\n\n\\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 \\citep[pp. 137]{ISLR}. Furthermore a problem with logistic regression is that it does not perform very stable under some circumstances. One big problem with logistic regression is that it might not converge if the classes are well-separated  \\citep{convergencefailure}. 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     &  -1  \\\\[0.05cm] \n%\t\t0     &  -5  \\\\[0.05cm] \n%\t\t1     &    3  \\\\[0.05cm] \n%\t\t1     &    1  \\\\[0.05cm] \n%\t\t1     &    6  \\\\[0.05cm] \n%\t\\end{tabular}\n%\\end{center}\n\n\\begin{center} \n\t\\begin{tabular}{l|llllll}\n%\t\t\\multicolumn{1}{c}{\\textbf{Y}} &\n%\t\t\\multicolumn{1}{c}{\\textbf{X}} \\\\ \\hline\n\t\tX & -2 & -1 & -5 & 3 & 1 & 6 \\\\[0.05cm] \n\t\tY &  0 &  0 &  0 & 1 & 1 & 1  \\\\[0.05cm] \n\t\\end{tabular}\n\\end{center}\n\nInstead a method called Linear Discriminant Analysis \\emph{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}\nP(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\\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 mean vector and a covariance matrix and can be written as follows:\n\n\\begin{equation}\n\\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\nThe means of the Gaussian for each class are simply calculated by summing all values with a specific class and dividing by the total number. The covariance matrix is calculated as a common covariance for all classes.\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 \\citep{comparelogandlda}.\n\n\\subsection{Lab 4.6.3 - Linear Discriminant Analysis}\nFirst a 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.  \n\n\\begin{center}\n\t$\\begin{matrix} \t & Lag1 & Lag2\t\\\\ \t Down & 0.0428 & 0.0339 \\\\ \t Up & -0.0395 & -0.0313 \\end{matrix} $\n\\end{center}\n\n\nThe 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]\n%print \"Prior probabilities:\"\n%print lda.priors_\n%\n%print \"Mean:\"\n%print lda.means_\n%\n%print \"Coefficients:\"\n%print lda.coef_\n%\\end{lstlisting}\n\nIn listing \\ref{lst:ldaScore} the score is printed. 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 \\emph{QDA} also assumes that the observations are drawn from a Gaussian distribution. The difference lies in the fact that LDA assumes a shared covariance for the observations for all classes K, while QDA assumes a different covariance for the observations for each class.\n\n\\myFigure{lda_vs_qda.PNG}{Comparison of LDA and QDA}{fig:qdaCompare}{0.6}\n\nIn figure \\ref{fig:qdaCompare} the difference between LDA and QDA is illustrated. It shows the linear decision boundary of LDA, while the QDA can learn quadratic boundaries.\n\n\\subsection{Lab 4.6.4 - Quadratic Discriminant Analysis}\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 QDA model]\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. This might indicate that the relationship for the data set is better captures with a quadratic form.\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  data set 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 - K-Nearest Neighbors}\n\nIn this lab exercise the method K-nearest neighbors is used. To perform this method, sklearn has a function called \\emph{KNeighborsClassifier}. This takes one parameter, which is number of k. After this the function fit is called, that fits the data.\nThe code is shown in listing \\ref{lst:kneighbor}.\n\n\\begin{lstlisting}[caption={Python KNN 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 turn 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 too 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 QDA produces, the QDA provides better results than KNN.", "meta": {"hexsha": "d34b4f6ae21b65a364d0123343c02ead49235bcb", "size": 18841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/logistic_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/logistic_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/logistic_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": 74.7658730159, "max_line_length": 832, "alphanum_fraction": 0.759566902, "num_tokens": 5075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6269238400868391}}
{"text": "\\subsection{Category equivalences}\\label{subsec:category_equivalences}\n\n\\begin{remark}\\label{rem:category_similarity}\n  We have the following notions for expressing that two categories \\( \\cat{C} \\) and \\( \\cat{D} \\) are similar:\n\n  \\begin{thmenum}\n    \\thmitem{rem:category_similarity/equality} Obviously, if \\( \\cat{C} \\) and \\( \\cat{D} \\) are equal, they are similar.\n\n    \\thmitem{rem:category_similarity/isomorphism} A slightly less obvious notion is \\term{isomorphism of categories}. This is an isomorphism, in the sense of \\fullref{def:morphism_invertibility/isomorphism}, in the category \\hyperref[def:category_of_small_categories]{\\( \\ucat{Cat} \\)} of small categories for a suitable \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\). That is, \\( \\cat{C} \\) and \\( \\cat{D} \\) are isomorphic if there exists an invertible functor between them.\n\n    We rarely distinguish between objects and arrows of isomorphic categories, even if we do not have strict equality in the sense of the \\hyperref[def:zfc/extensionality]{axiom of extensionality} in \\hyperref[def:zfc]{\\logic{ZFC}}.\n\n    Examples of isomorphic categories include \\fullref{thm:order_category_isomorphism} and \\fullref{ex:isomorphism_of_quiver_categories}.\n\n    \\thmitem{rem:category_similarity/equivalence} A weaker but very useful notion is \\term{category equivalence} defined in \\fullref{def:category_equivalence}.\n  \\end{thmenum}\n\\end{remark}\n\n\\begin{example}\\label{ex:set_discr_cat_isomorphism}\n  There is an isomorphism between the category \\( \\ucat{Set} \\) of small sets and \\( \\ucat{DiscrCat} \\) of all small \\hyperref[def:discrete_category]{discrete categories}.\n\n  Consider the pair of functors\n  \\begin{equation*}\n    U: \\ucat{DiscrCat} \\to \\ucat{Set},\n  \\end{equation*}\n  which for any small category \\( \\cat{C} \\) gives us its set of objects \\( \\obj(\\cat{C}) \\) and\n  \\begin{equation*}\n    D: \\ucat{Set} \\to \\ucat{DiscrCat},\n  \\end{equation*}\n  which for any small set \\( A \\) gives us the \\hyperref[def:discrete_category]{discrete category} whose set of objects is \\( A \\).\n\n  These were discussed in \\fullref{ex:discrete_category_adjunction}, although with \\( \\cat{Cat} \\) rather than \\( \\ucat{DiscrCat} \\).\n\n  It is obvious that for any small category \\( \\cat{C} \\), the functor \\( D \\bincirc U \\) is bijective on objects. We need to verify that it is bijective on morphisms, however, in order to prove that \\( D \\bincirc U \\) is the identity functor on \\( \\ucat{DiscrCat} \\).\n\n  But any functor \\( F: \\cat{C} \\to \\cat{D} \\) is completely determined by how \\( F \\) acts on the objects of \\( \\cat{C} \\). Indeed, the only morphisms in \\( \\cat{C} \\) are the identity morphisms and, by \\ref{def:functor/CF1}, every object \\( X \\) in \\( \\cat{C} \\) determines how the identity \\( \\id_X \\in \\cat{C}(X) \\) is mapped by \\( F \\).\n\n  Therefore, \\( D \\) is a left inverse of \\( U \\). It is also a right inverse --- for any function \\( f: A \\to B \\) between small sets,\n  \\begin{equation*}\n    [U \\bincirc D](f) = D(f)\\restr_{A} = f.\n  \\end{equation*}\n\n  Therefore, the forgetful functor \\( U \\) is invertible, and its inverse is \\( D \\).\n\\end{example}\n\n\\begin{definition}\\label{def:category_equivalence}\\mcite[def. 1.3.15]{Leinster2016Basic}\n  An \\term{equivalence} between the \\hyperref[def:category]{categories} \\( \\cat{C} \\) and \\( \\cat{D} \\) is a quadruple\n  \\begin{equation}\\label{eq:def:category_equivalence/signature}\n    \\begin{aligned}\n                F &: \\cat{C} \\to \\cat{D}, \\\\\n                G &: \\cat{D} \\to \\cat{C}, \\\\\n             \\eta &: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F, \\\\\n      \\varepsilon &: F \\bincirc G \\Rightarrow \\id_{\\cat{D}},\n    \\end{aligned}\n  \\end{equation}\n  where \\( \\eta \\) and \\( \\varepsilon \\) are \\hyperref[thm:natural_isomorphism]{natural isomorphisms}.\n\n  We call \\( \\eta \\) the \\term{unit} of the equivalence and \\( \\varepsilon \\) the \\term{counit}.\n\n  If \\( (F, G, \\eta, \\varepsilon) \\) is an equivalence, we say that \\( \\cat{C} \\) and \\( \\cat{D} \\) are equivalent categories. This is justified because equivalence of categories is an equivalence relation --- see \\fullref{thm:category_equivalence_is_equivalence_relation}.\n\n  Note that an equivalence is not necessarily an \\hyperref[def:category_adjunction]{adjunction}, they simply have a common setup. This is discussed in \\fullref{thm:adjoint_equivalence}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:category_equivalence_is_equivalence_relation}\n  For every \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\), \\hyperref[def:category_equivalence]{category equivalence} is an \\hyperref[def:equivalence_relation]{equivalence relation} on the set \\( \\obj(\\ucat{Cat}) \\)\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf[def:binary_relation/reflexive]{reflexivity} Clearly \\( (\\id_{\\cat{C}}, \\id_{\\cat{C}}, \\id_{\\id_{\\cat{C}}}, \\id_{\\id_{\\cat{C}}}]) \\) is a self-equivalence for the category \\( \\cat{C} \\).\n\n  \\SubProofOf[def:binary_relation/symmetric]{symmetry} If \\( (F, G, \\eta, \\varepsilon) \\) is an \\hyperref[def:category_equivalence]{equivalence} between the categories \\( \\cat{C} \\) and \\( \\cat{D} \\), then \\( (G, F, \\varepsilon^{-1}, \\eta^{-1}) \\) is an equivalence between \\( \\cat{D} \\) and \\( \\cat{C} \\).\n\n  \\SubProofOf[def:binary_relation/transitive]{transitivity} By \\fullref{thm:def:morphism_invertibility/invertible_composition}, the composition of invertible natural isomorphisms is again a natural isomorphism, hence equivalence in \\( \\obj(\\ucat{Cat}) \\) is a transitive relation.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:discrete_category_equivalence}\n  Let \\( \\cat{C} \\) and \\( \\cat{D} \\) be \\hyperref[def:discrete_category]{discrete categories}. Then \\( \\cat{C} \\) and \\( \\cat{D} \\) are \\hyperref[def:category_equivalence]{equivalent} if and only if the underlying sets \\( \\obj(\\cat{C}) \\) and \\( \\obj(\\cat{D}) \\) are \\hyperref[def:equinumerosity]{equinumerous}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Suppose that \\( (F, G, \\eta, \\varepsilon) \\) be a category equivalence.\n\n  The unit natural transformation \\( \\eta: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F \\) consists of a morphism\n  \\begin{equation*}\n    \\eta_A: A \\to [G \\bincirc F](A)\n  \\end{equation*}\n  for every object \\( A \\) of \\( \\cat{C} \\). Since the only morphisms in \\( \\cat{C} \\) are the identities, it follows that \\( \\eta_A = \\id_A \\) and hence \\( [G \\bincirc F](A) = A \\). In particular, this implies that \\( \\eta \\) is the \\hyperref[eq:def:functor_category/identity]{identity natural transformation} on \\( \\id_{\\cat{C}} \\) and that the restriction \\( G\\restr_{\\obj(D)} \\) is a left inverse of \\( F\\restr_{\\obj(\\cat{C})} \\).\n\n  Similarly, for the counit \\( \\varepsilon: F \\bincirc G \\Rightarrow \\id_{\\cat{D}} \\), for every object \\( X \\) in \\( \\cat{D} \\) we have \\( \\varepsilon_X = \\id_X \\) and hence \\( [F \\bincirc G](X) = X \\). Thus, \\( \\eta \\) is the identity natural transformation on \\( \\id_{\\cat{D}} \\) and \\( G\\restr_{\\obj(D)} \\) is a right inverse of \\( F\\restr_{\\obj(\\cat{C})} \\).\n\n  Therefore, the sets \\( \\obj(\\cat{C}) \\) and \\( \\obj(D) \\) are equinumerous.\n\n  \\NecessitySubProof Suppose that \\( F: \\obj(\\cat{C}) \\to \\obj(D) \\) is a bijective function. Then it is an isomorphism in the category \\( \\ucat{Cat} \\) for an appropriate universe \\( \\mscrU \\), hence it induces an equivalence between \\( \\cat{C} \\) and \\( \\cat{D} \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:opposite_of_category_equivalence}\n  The \\hyperref[def:opposite_category]{opposite} of \\hyperref[def:category_equivalence]{equivalent categories} are equivalent.\n\n  More precisely, if \\( (F, G, \\eta, \\varepsilon) \\) is an \\hyperref[def:category_equivalence]{equivalence} between the categories \\( \\cat{C} \\) and \\( \\cat{D} \\), then\n  \\begin{equation*}\n    \\begin{aligned}\n                G^{\\opcat} &: \\cat{D}^{\\opcat} \\to \\cat{C}^{\\opcat}, \\\\\n                F^{\\opcat} &: \\cat{C}^{\\opcat} \\to \\cat{D}^{\\opcat}, \\\\\n      \\varepsilon^{\\opcat} &: \\id_{\\cat{D}} \\Rightarrow [F \\bincirc G]^{\\opcat}, \\\\\n             \\eta^{\\opcat} &: \\underbrace{[G \\bincirc F]^{\\opcat}}_{G^{\\opcat} \\bincirc F^{\\opcat}} \\Rightarrow \\id_{\\cat{C}^{\\opcat}},\n    \\end{aligned}\n  \\end{equation*}\n  is an equivalence between \\( \\cat{C}^{\\opcat} \\) and \\( \\cat{D}^{\\opcat} \\).\n\n  This is part of the duality principles listed in \\fullref{thm:categorical_principle_of_duality}.\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}\n  In any \\hyperref[def:category_equivalence]{category equivalence} \\( (F, G, \\eta, \\varepsilon) \\), the functor \\( F \\) is \\hyperref[def:functor_invertibility/fully_faithful]{fully faithful} and \\hyperref[def:functor_invertibility/surjective_on_objects]{essentially surjective on objects}.\n\n  The converse of this statement is \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf[def:functor_invertibility/surjective_on_objects]{essential surjectivity} For any object \\( X \\) in \\( \\cat{D} \\), \\( A \\coloneqq G(X) \\) is an object in \\( \\cat{C} \\).\n\n  By definition of category equivalence, the morphism\n  \\begin{equation*}\n    \\varepsilon_X: \\underbrace{[F \\bincirc G](X)}_{F(A)} \\to X\n  \\end{equation*}\n  is an isomorphism.\n\n  Therefore, for every object \\( X \\) in \\( \\cat{D} \\), there exists some object \\( A \\) in \\( \\cat{C} \\) such that \\( F(A) \\cong X \\). Thus, \\( F \\) is essentially surjective.\n\n  \\SubProofOf[def:functor_invertibility/faithful]{faithfulness} Fix some objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\). Let \\( f_1: A \\to B \\) and \\( f_2: A \\to B \\) be morphisms such that \\( F(f_1) = F(f_2) \\).\n\n  From the naturality of \\( \\eta \\) it follows that the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/faithfullness}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore, \\( \\eta_B \\bincirc f_1 = \\eta_B \\bincirc f_2 \\) and, since \\( \\eta_B \\) is left-cancellative, \\( f_1 = f_2 \\).\n\n  \\SubProofOf[def:functor_invertibility/full]{fullness} Fix some objects \\( A \\) and \\( B \\) in \\( \\cat{C} \\). Let \\( g: F(A) \\to F(B) \\) be an arbitrary morphism.\n\n  We can define a morphism \\( f: A \\to B \\) via the composition\n  \\begin{equation}\\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/def}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  By naturality of \\( \\eta \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/eta_nat}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore,\n  \\begin{equation*}\n     G(g) = [G \\bincirc F](f).\n  \\end{equation*}\n\n  We have already shown that \\( F \\) is faithful and, by \\fullref{thm:category_equivalence_is_equivalence_relation}, \\( G \\) is also faithful. Since \\( g \\) and \\( F(f) \\) are parallel, it follows that they are equal.\n\n  Therefore, \\( F \\) is full.\n\\end{proof}\n\n\\begin{remark}\\label{rem:adjoint_equivalence_induces_fully_faithful_and_essentially_surjective_functor}\n  In the fullness proof of \\fullref{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}, we can use another argument if \\( (F, G, \\eta, \\varepsilon) \\) is an \\hyperref[def:adjoint_equivalence]{adjoint equivalence}.\n\n  If the triangle diagram \\eqref{eq:def:category_adjunction/d_triangle} commutes, the dashed lines in the following diagram also commute:\n  \\begin{equation}\\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/triangles}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/rem__adjoint_equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\\end{remark}\n\n\\begin{theorem}[Fully faithful and essentially surjective functor induces equivalence]\\label{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}\n  Every \\hyperref[def:functor_invertibility/fully_faithful]{fully faithful} and \\hyperref[def:functor_invertibility/surjective_on_objects]{essentially surjective on objects} functor induces a \\hyperref[def:category_equivalence]{category equivalence}.\n\n  More precisely, given a functor \\( F: \\cat{C} \\to \\cat{D} \\) that is fully faithful and essentially surjective on objects, there exists a functor \\( G: \\cat{D} \\to \\cat{C} \\) and \\hyperref[def:natural_transformation]{natural transformations}\n  \\begin{align*}\n    \\eta        &: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F, \\\\\n    \\varepsilon &: F \\bincirc G \\Rightarrow \\id_{\\cat{D}},\n  \\end{align*}\n  such that the quadruple \\( (F, G, \\eta, \\varepsilon) \\) is a \\hyperref[def:category_equivalence]{category equivalence}.\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/fully_faithful_essentially_surjective}.\n\n  We prove the converse of this statement separately in \\fullref{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence]{functors induce equivalences} Suppose that the axiom of choice holds and let \\( F \\) be a fully faithful functor that is surjective on objects.\n\n  From essential surjectivity of \\( F \\), it follows that for every object \\( X \\) in \\( \\cat{D} \\), the preimage of \\( X \\) under \\( F \\) is nonempty. The preimage of \\( X \\) is the set \\( \\mscrA_X \\) of objects in \\( \\cat{C} \\) such that \\( A \\in \\mscrA_X \\) if and only if \\( F(A) \\cong X \\). We use the axiom of choice on the family \\( \\set{ \\mscrA_X }_{X \\in \\cat{D}} \\) to select a single preimage for every \\( X \\), which we denote by \\( G(X) \\).\n\n  Again using the axiom of choice, we pick an isomorphism \\( \\varepsilon_X: F(G(X)) \\to X \\) for every \\( X \\).\n\n  We have defined a function \\( G \\) from \\( \\obj(\\cat{D}) \\) to \\( \\obj(\\cat{C}) \\). In order to \\( G \\) to become a functor, we must extend it to morphisms. Let \\( X \\) and \\( Y \\) be objects in \\( \\cat{D} \\) and \\( g: X \\to Y \\) be any morphism.\n\n  Consider the morphism\n  \\begin{equation*}\n    \\varepsilon_Z^{-1} \\bincirc f \\bincirc \\varepsilon_X: [F \\bincirc G](X) \\to [F \\bincirc G](Y).\n  \\end{equation*}\n\n  Since \\( F \\) is fully faithful, there exists a unique morphism \\( g \\) in \\( \\cat{D}(G(X), G(Y)) \\) such that the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/inverse_morphism_definition}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  We define \\( G(g) \\coloneqq g \\).\n\n  In order to prove that \\( G \\) is a functor, we need to show that \\ref{def:functor/CF1} and \\ref{def:functor/CF2} hold.\n\n  For \\ref{def:functor/CF1}, note that the following diagram commutes for any object \\( X \\) in \\( \\cat{D} \\):\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/identity}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Note that \\eqref{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/inverse_morphism_definition} also commutes if we replace \\( [F \\bincirc G](\\id_X) \\) with \\( F(\\id_{G(X)}) \\). Since \\( F \\) is fully faithful, this morphism is unique and it follows that\n  \\begin{equation*}\n    [F \\bincirc G](\\id_X) = F(\\id_{G(X)}).\n  \\end{equation*}\n\n  For \\ref{def:functor/CF2}, analogously, given morphisms \\( g: X \\to Y \\) and \\( f: Y \\to Z \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/composition}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  We have implicitly used \\fullref{rem:inverting_isomorphisms_may_preserve_commutativity} above.\n\n  By the same uniqueness argument used for \\ref{def:functor/CF1}, we conclude that\n  \\begin{equation*}\n    G(f \\bincirc q) = G(f) \\bincirc G(g).\n  \\end{equation*}\n\n  We have shown that \\( G \\) is a functor. Furthermore, \\( \\varepsilon \\) is a natural transformation since, for any morphism \\( g: X \\to Y \\) in \\( \\cat{D} \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon}\n    \\begin{aligned}\n      \\includegraphics[page=4]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  To show that \\( F \\) induces an equivalence, it now only remains to define a unit natural transformation \\( \\eta: \\id_{\\cat{C}} \\to G \\bincirc F \\). For every object \\( A \\) in \\( \\cat{C} \\) we have an isomorphism\n  \\begin{equation*}\n    \\varepsilon_{F(A)}^{-1}: F(A) \\to [F \\bincirc G \\bincirc F](A).\n  \\end{equation*}\n\n  Using \\( G(\\varepsilon_{F(A)}^{-1}) \\) will get us nowhere. Fortunately, \\( F \\) is fully faithful, so there is a bijective function\n  \\begin{equation*}\n    \\varphi: \\cat{D}(F(A), [F \\bincirc G \\bincirc F](A)) \\to \\cat{C}(A, [F \\bincirc G](A)).\n  \\end{equation*}\n\n  Hence, we can define\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\eta: \\id_{\\cat{C}} \\Rightarrow F \\bincirc G \\\\\n      &\\eta_A \\coloneqq \\varphi(\\varepsilon_{F(A)}^{-1})\n    \\end{aligned}\n  \\end{equation*}\n  so that \\( F(\\eta_A) = \\varepsilon_{F(A)}^{-1} \\). By \\fullref{thm:def:functor_invertibility/fully_faithful_reflects_invertible}, since \\( \\varepsilon_{F(A)} \\) is an isomorphism, \\( \\eta_A \\) is also an isomorphism.\n\n  By naturality of \\( F(\\eta_A) \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_image_nat}\n    \\begin{aligned}\n      \\includegraphics[page=5]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Hence, by \\fullref{thm:commutative_diagrams_preserved_and_reflected}, the following diagram also commutes:\n  \\begin{equation}\\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_source_nat}\n    \\begin{aligned}\n      \\includegraphics[page=6]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore, the quadruple \\( (F, G, \\eta, \\varepsilon) \\) is an equivalence of categories.\n\n  \\ImplicationSubProof[thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence]{functors induce equivalences}[def:zfc/choice]{the axiom of choice} Let \\( \\mscrA \\) be a family of nonempty sets. Let \\( \\cat{D} \\) be the \\hyperref[def:discrete_category]{discrete category} induced by \\( \\mscrA \\).\n\n  Define the category \\( \\cat{C} \\) as follows:\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{C}) \\) is the \\hyperref[def:disjoint_union]{disjoint union} \\( \\coprod_{A \\in \\mscrA} A \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{C}((A, x), (B, y)) \\) has a single morphism if \\( A = B \\) and no morphisms otherwise. This single morphism can be encoded as the triple \\( (A, x, y) \\).\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms} \\( (A, x, y) \\) and \\( (A, y, z) \\) is the morphism \\( (A, x, z) \\).\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the object \\( (A, x) \\in \\cat{C} \\) is \\( (A, x, x) \\).\n  \\end{itemize}\n\n  Define the functor\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: \\cat{C} \\to \\cat{D} \\\\\n      &F(A, x) \\coloneqq A \\\\\n      &F(A, x, y) \\coloneqq \\id_A\n    \\end{aligned}\n  \\end{equation*}\n  that maps each point \\( x \\in A \\in \\mscrA \\) into the set \\( A \\) it belongs to. We have taken the disjoint union of \\( \\mscrA \\) since otherwise there may not be a canonical choice of set \\( A \\) for \\( F \\) to send \\( x \\) to. Thus, the functor is surjective on objects (not essentially surjective but actually surjective).\n\n  Note that \\( \\cat{D}(F(A, x), F(B, y)) \\) has a single morphism if \\( A = B \\) and is empty otherwise. From this it follows that \\( F \\) is fully faithful.\n\n  Therefore, \\( F \\) induces a \\hyperref[def:category_equivalence]{category equivalence} \\( (F, G, \\eta, \\varepsilon) \\). The functor \\( G \\) chooses an object \\( (A, x) \\) of \\( \\cat{C} \\) for each object \\( A \\) of \\( \\cat{D} \\). This induces a \\hyperref[def:choice_function]{choice function} on \\( \\mscrA \\).\n\n  We have shown that the axiom of choice holds.\n\\end{proof}\n\n\\begin{definition}\\label{def:groupoid}\n  A \\term{groupoid} is a category whose only morphisms are \\hyperref[def:morphism_invertibility/isomorphism]{isomorphisms}.\n\\end{definition}\n\n\\begin{definition}\\label{def:monoid_delooping}\\mcite[def. 1.1.7]{Perrone2019}\n  Let \\( (M, \\cdot, e) \\) be a \\hyperref[def:monoid]{monoid}. The \\term{delooping} \\( \\cat{B}_M \\) of \\( M \\) is the following category:\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{B}_M) \\) is the singleton set \\( \\set{ \\Anon } \\), where \\( \\Anon \\) is any set not in the set of all morphisms \\( M \\).\n\n    \\item The only \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{B}_M(\\Anon) \\) is the underlying set \\( M \\) of the monoid.\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms} \\( x \\) and \\( y \\) is the multiplication:\n    \\begin{equation*}\n      y \\bincirc x \\coloneqq y \\cdot x.\n    \\end{equation*}\n\n    Note how we write composition in the same order as multiplication. This may seem to contradict the general convention, however it is consistent with groups being regarded as sets of invertible transformations.\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} is \\( e \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:delooping_of_group}\n  The \\hyperref[def:monoid_delooping]{delooping} of a \\hyperref[def:group]{group} \\( G \\) is a \\hyperref[def:groupoid]{groupoid}.\n\n  There is a restricted form of a converse --- see \\fullref{thm:connected_delooping}.\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{definition}\\label{def:connected_category}\\mcite[exer. 1.5.20]{Perrone2019}\n  A \\hyperref[def:category]{category} is \\term{connected} if there exists a morphism between any two objects. That is, for a connected category \\( \\cat{C} \\), given two objects \\( X \\) and \\( Y \\), either \\( \\cat{C}(X, Y) \\) or \\( \\cat{C}(Y, X) \\) is nonempty.\n\n  Connected categories are used in \\fullref{thm:connected_delooping} and \\fullref{thm:order_category_isomorphism/totally_ordered}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:connected_delooping}\n  For every \\hyperref[def:connected_category]{connected} \\hyperref[def:groupoid]{groupoid} \\( \\cat{G} \\) there exists a \\hyperref[def:group]{group} \\( G \\) such that \\( \\cat{G} \\) is \\hyperref[def:category_equivalence]{equivalent} to the \\hyperref[def:monoid_delooping]{delooping} \\( \\cat{B}_G \\). Furthermore, if \\( \\cat{G} \\) has only one object, then this equivalence is an \\hyperref[rem:category_similarity/isomorphism]{isomorphism}.\n\n  See \\fullref{thm:delooping_of_group} for a much simpler converse.\n\\end{proposition}\n\\begin{proof}\n  Define the group \\( G \\) as follows:\n  \\begin{itemize}\n    \\item Let the underlying set of \\( G \\) be the set of all morphisms of \\( \\cat{G} \\).\n    \\item Define \\( x \\cdot y = z \\) to hold whenever the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:connected_delooping/mult}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__connected_delooping.pdf}\n      \\end{aligned}\n    \\end{equation}\n    \\item Pick the identity of \\( G \\) out of the identity morphisms in \\( G \\).\n    \\item Let the inverse of \\( x \\) be the inverse morphism \\( x^{-1} \\).\n  \\end{itemize}\n\n  Finally, define the functor \\( F: \\cat{G} \\to \\cat{B}_G \\), which sends every object to \\( \\anon \\) and every morphism to itself.\n\n  By definition, for every morphism \\( x: \\anon \\to \\anon \\) in the delooping, there exists a unique \\( f: X \\to Y \\) in \\( \\cat{G} \\) such that \\( F(f) = x \\). Hence, \\( f \\) is surjective on morphisms, and by \\fullref{thm:def:functor_invertibility/surjective}, full and surjective on objects.\n\n  Furthermore, for any objects \\( X \\) and \\( Y \\) in \\( \\cat{G} \\), we have\n  \\begin{equation*}\n    \\cat{G}(X, Y) \\subseteq \\cat{B}_G(F(X), F(Y)).\n  \\end{equation*}\n\n  Hence, \\( G \\) is faithful. Therefore, by \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, the groupoid \\( \\cat{G} \\) is equivalent to the delooping \\( \\cat{B}_G \\).\n\n  Furthermore, if \\( \\cat{G} \\) has only one object, it is also injective on objects and, by \\fullref{thm:def:functor_invertibility/injective}, injective on morphisms. In this case, we have an isomorphism due to \\fullref{thm:def:functor_invertibility/isomorphism}.\n\\end{proof}\n\n\\begin{definition}\\label{def:skeletal_category}\\mcite[91]{MacLane1994}\n  The category \\( \\cat{S} \\) is called \\term{skeletal} if the only isomorphisms in \\( \\cat{S} \\) are the identity morphisms.\n\n  If \\( \\cat{S} \\) is a subcategory of \\( \\cat{C} \\) and if they are \\hyperref[def:category_equivalence]{equivalent}, we say that \\( \\cat{S} \\) is a \\term{skeleton} of \\( \\cat{C} \\).\n\\end{definition}\n\n\\begin{example}\\label{ex:skeleton_of_set}\n  Fix a Grothendieck universe \\( \\mscrU \\), the \\hyperref[def:cardinal_number]{cardinal numbers} in \\( \\mscrU \\) are a \\hyperref[def:skeletal_category]{skeletal subcategory} of \\( \\ucat{Set} \\).\n\\end{example}\n\n\\begin{theorem}[Category skeleton existence]\\label{thm:category_skeleton_existence}\n  Every \\hyperref[def:category]{category} has a \\hyperref[def:skeletal_category]{skeleton}.\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/skeletons}.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:category_skeleton_existence]{skeleton existence} Suppose that the axiom of choice holds and let \\( F \\) be a fully faithful functor that is surjective on objects.\n\n  Fix a category \\( \\cat{C} \\). We will build a subcategory \\( \\cat{S} \\) of \\( \\cat{C} \\) whose inclusion functor \\( \\Iota: \\cat{S} \\to \\cat{C} \\) is essentially surjective and fully faithful. By \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, this is sufficient for \\( \\cat{S} \\) and \\( \\cat{C} \\) to be equivalent.\n\n  In order for \\( \\Iota \\) to be a full functor, \\( \\cat{S} \\) must be a full subcategory. Therefore, when building \\( \\cat{S} \\), we can only remove objects and must preserve the morphism sets for the remaining objects.\n\n  Denote by \\( \\obj(\\cat{C}) / \\cong \\) the quotient of \\( \\cat{C} \\) by the isomorphism relation. Using the axiom of choice, we can obtain a \\hyperref[def:choice_function]{choice function} \\( c: (\\obj(\\cat{C}) / \\cong) \\to \\obj(\\cat{C}) \\).\n\n  Define \\( \\cat{S} \\) as the subcategory induced by the image \\( c[\\obj(\\cat{C}) / \\cong] \\).\n\n  Now consider the \\hyperref[def:subcategory]{inclusion functor} \\( \\Iota: \\cat{S} \\to \\cat{C} \\). For every pair \\( X \\) and \\( Y \\) of objects in \\( \\cat{S} \\), clearly\n  \\begin{equation*}\n    \\cat{S}(X, Y) = \\cat{C}(\\Iota(X), \\Iota(Y)).\n  \\end{equation*}\n\n  Hence, \\( \\Iota \\) is fully faithful.\n\n  Now let \\( X \\) and \\( Y \\) be objects of \\( \\cat{C} \\). Since the objects of \\( \\cat{S} \\) were chosen from isomorphism classes of \\( \\cat{C} \\), there exist objects \\( X' \\) and \\( Y' \\) in \\( \\cat{S} \\) that are isomorphic to \\( X \\) and \\( Y \\), correspondingly. Hence, \\( \\Iota \\) is essentially surjective.\n\n  Therefore, \\( F \\) satisfies \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, from which is follows that \\( \\cat{C} \\) and \\( \\cat{S} \\) are equivalent.\n\n  \\ImplicationSubProof[thm:category_skeleton_existence]{skeleton existence}[def:zfc/choice]{the axiom of choice} Suppose that every category has a skeleton.\n\n  Let \\( \\mscrA \\) be a family of nonempty sets. Construct a category \\( \\cat{C} \\)from the \\hyperref[def:disjoint_union]{disjoint union} \\( \\coprod_{A \\in \\mscrA} A \\), where a morphism exists only between members of the same set. This construction is performed in detail in the proof of \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}.\n\n  Then \\( \\cat{C} \\) has a skeleton \\( \\cat{S} \\). All morphisms in \\( \\cat{C} \\) are isomorphisms, hence the set \\( \\obj(\\cat{S}) \\) contains exactly one representative for each set in the family \\( \\mscrA \\).\n\n  More precisely, define the set\n  \\begin{equation*}\n    S \\coloneqq \\set{ x \\given (A, x) \\in \\obj(\\cat{S}) }.\n  \\end{equation*}\n\n  Then \\( S \\) satisfies \\fullref{thm:axiom_of_choice_equivalences/choice_sets}.\n\n  Since the family \\( \\mscrA \\) is arbitrary, we conclude that the axiom of choice holds.\n\\end{proof}\n\n\\begin{remark}\\label{rem:skeletons_and_thin_categories}\n  Rather than defining representatives of equivalence classes, as in \\fullref{thm:category_skeleton_existence}, we can define morphisms between the equivalence classes themselves, as in \\fullref{thm:preorder_to_partial_order}.\n\n  This does not require the \\hyperref[def:zfc/choice]{axiom of choice}, but is rarely applicable, unfortunately. One case where it is applicable is in \\hyperref[def:thin_category]{thin categories} --- see \\fullref{thm:order_category_isomorphism}.\n\\end{remark}\n\n\\begin{definition}\\label{def:thin_category}\\mcite{nLab:thin_category}\n  A \\hyperref[def:category]{category} is \\term{thin} if any two parallel morphisms are equal.\n\n  This is equivalent to saying that the function for every two objects \\( A \\) and \\( B \\) in \\( \\cat{P} \\), whenever the set \\( \\cat{P}(A, B) \\) is at most a singleton.\n\n  As shown in \\fullref{ex:preorder_nonuniqueness} and discussed in \\fullref{thm:order_category_isomorphism}, a thin category may not be \\hyperref[def:skeletal_category]{skeletal}.\n\n  Thin categories are often conflated with preordered sets due to \\fullref{thm:order_category_isomorphism/preordered}.\n\\end{definition}\n\n\\begin{theorem}[Ordered sets as categories]\\label{thm:order_category_isomorphism}\n  Regarding ordered sets, we have the following \\hyperref[rem:category_similarity/isomorphism]{category isomorphisms}:\n  \\begin{thmenum}\n    \\thmitem{thm:order_category_isomorphism/preordered} The categories \\hyperref[def:preordered_set/category]{\\( \\cat{PreOrd} \\)} and \\( \\cat{Thin} \\), where\n    \\begin{itemize}\n      \\item \\( \\cat{PreOrd} \\) is the category of small \\hyperref[def:preordered_set]{preordered sets} and (nonstrict) \\hyperref[def:preordered_set/homomorphism]{monotone maps}.\n\n      \\item \\( \\cat{Thin} \\) is the subcategory of \\hyperref[def:category_of_small_categories]{\\( \\cat{Cat} \\)} \\hyperref[def:subcategory]{induced} by \\hyperref[def:thin_category]{thin categories}, i.e. the category of small thin categories.\n    \\end{itemize}\n\n    \\thmitem{thm:order_category_isomorphism/partially_ordered} The categories \\hyperref[def:partially_ordered_set/category]{\\( \\cat{Pos} \\)} and \\( \\cat{SkelThin} \\), where\n    \\begin{itemize}\n      \\item \\( \\cat{Pos} \\) is the subcategory of \\( \\cat{PreOrd} \\) induced by (nonstrict) \\hyperref[def:partially_ordered_set]{partially ordered sets}.\n\n      \\item \\( \\cat{SkelThin} \\) is the subcategory of \\( \\cat{Thin} \\) induced by \\hyperref[def:skeletal_category]{skeletal categories}, i.e. the category of small thin skeletal categories.\n    \\end{itemize}\n\n    \\thmitem{thm:order_category_isomorphism/totally_ordered} The categories \\hyperref[def:totally_ordered_set]{\\( \\cat{Tos} \\)} and \\( \\cat{ConnSkelThin} \\), where\n    \\begin{itemize}\n      \\item \\( \\cat{Tos} \\) is the subcategory of \\( \\cat{Pos} \\) induced by (nonstrict) \\hyperref[def:totally_ordered_set]{totally ordered sets}.\n\n      \\item \\( \\cat{ConnSkelThin} \\) is the subcategory of \\( \\cat{SkelThin} \\) induced by \\hyperref[def:connected_category]{connected categories}, i.e. the category of small thin skeletal connected categories.\n    \\end{itemize}\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  \\SubProofOf{thm:order_category_isomorphism/preordered}\n  \\SubProof*{Proof that preorders induce thin categories} Let \\( (P, \\leq) \\) be a small preordered set. Let \\( \\cat{P} \\) be the \\hyperref[def:quiver_free_category]{free category} obtained by regarding \\( (P, \\leq) \\) as a \\hyperref[def:quiver]{quiver}. Explicitly, the category \\( \\cat{P} \\) is built as follows:\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{P}) \\) is simply \\( P \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{P}(x, y) \\) consists of the tuple \\( (x, y) \\) if \\( x \\leq y \\) and is empty otherwise.\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms} \\( (x, y) \\) and \\( (y, z) \\) is simply \\( (x, y) \\). This is well-defined because of the \\hyperref[def:binary_relation/transitive]{transitivity} of \\( \\leq \\).\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the object \\( x \\in \\cat{C} \\) is \\( (x, x) \\). This is well-defined because of the \\hyperref[def:binary_relation/reflexive]{reflexivity} of \\( \\leq \\).\n  \\end{itemize}\n\n  The category is clearly thin because \\( \\leq \\) is a binary relation and ordered tuples with the same elements are equal.\n\n  Now let \\( f: P \\to Q \\) be a nonstrict monotone map. It induces the functor\n  \\begin{equation*}\n    \\begin{aligned}\n      &F: \\cat{P} \\to \\cat{Q} \\\\\n      &F(x) \\coloneqq f(x) \\\\\n      &F(x, y) \\coloneqq (f(x), f(y)).\n    \\end{aligned}\n  \\end{equation*}\n\n  \\ref{def:functor/CF1} is immediate and \\ref{def:functor/CF2} follows from \\eqref{eq:def:preordered_set/homomorphism}, hence \\( F \\) is indeed a functor.\n\n  \\SubProof*{Proof that thin categories induce preorders} Let \\( \\cat{P} \\) be a small category. Define the binary relation\n  \\begin{equation*}\n    X \\leq Y \\T{if and only if} \\cat{P}(X, Y) \\neq \\varnothing.\n  \\end{equation*}\n\n  This is a binary relation over the set \\( P \\coloneqq \\obj(\\cat{P}) \\). It is reflexive because of the existence of identity morphisms in \\( \\cat{P} \\) and transitive because of the requirement that the composition of compatible morphisms exists.\n\n  Therefore, \\( (P, \\leq) \\) is a preordered set.\n\n  Given a functor \\( F: \\cat{P} \\to \\cat{Q} \\), the restriction \\( F\\restr_{\\obj(\\cat{P})} \\) is a monotone map from \\( (P, \\leq_P) \\) to \\( (Q, \\leq_Q) \\).\n\n  Indeed, if \\( X \\leq Y \\) for \\( X, Y \\in P \\), then \\( \\cat{P}(X, Y) \\neq \\varnothing \\). Hence, \\( \\cat{P}(F(X), F(Y)) \\neq \\varnothing \\) and \\( F(X) \\leq F(Y) \\).\n\n  \\SubProof*{Proof of isomorphism} We have implicitly defined a functor from \\( \\cat{PreOrd} \\) to \\( \\cat{Thin} \\) and vice versa. Isomorphism of \\( \\cat{PreOrd} \\) and \\( \\cat{Thin} \\) requires that these functors are mutually inverse.\n\n  We need to prove that the induced preordered set for the induced thin category of a preordered set is the same as the original. In the other direction, we need to prove that the induced thin category for the induced preordered set of a thin category is the same as the original.\n\n  Both of these proofs are trivial but nevertheless the fact that we need to perform such a check is important.\n\n  \\SubProofOf{thm:order_category_isomorphism/partially_ordered} We have already shown in \\fullref{thm:order_category_isomorphism/preordered} the isomorphism between \\( \\cat{PreOrd} \\) and \\( \\cat{Thin} \\).\n\n  For a thin category, there is an isomorphism between \\( x \\) and \\( y \\) if and only if there is both a morphism from \\( x \\) to \\( y \\) and one from \\( y \\) to \\( x \\). This isomorphism may not be unique as a consequence of \\fullref{ex:preorder_nonuniqueness}. Uniqueness requires \\( x = y \\) to hold in this case, which is in turn equivalent to partial order \\hyperref[def:binary_relation/antisymmetric]{antisymmetry}.\n\n  \\SubProofOf{thm:order_category_isomorphism/totally_ordered} We have already shown in \\fullref{thm:order_category_isomorphism/partially_ordered} the isomorphism between \\( \\cat{Pos} \\) and \\( \\cat{SkelThin} \\).\n\n  \\hyperref[def:connected_category]{Connectedness} of a category \\( \\cat{P} \\) is then equivalent to \\hyperref[def:binary_relation/total]{totality} of \\( (P, \\leq) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:order_category_isomorphism_properties}\n  Let \\( (P, \\leq) \\) be a \\hyperref[def:partially_ordered_set]{partially ordered set} and let \\( \\cat{P} \\) be its corresponding category induced by \\fullref{thm:order_category_isomorphism}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:order_category_isomorphism_properties/opposite} The \\hyperref[def:opposite_category]{opposite category} \\( \\cat{P}^{\\opcat} \\) corresponds to the \\hyperref[def:partially_ordered_set/opposite]{opposite partially ordered set} \\( (P, \\geq) \\).\n\n    \\thmitem{thm:order_category_isomorphism_properties/universal} If \\( \\cat{P} \\) has an \\hyperref[def:universal_objects/initial]{initial object}, since it is a skeletal category, this initial object is unique.\n\n    An object \\( I \\) is an initial object if and only if it is the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom} of \\( P \\).\n\n    \\hyperref[thm:categorical_principle_of_duality]{Dually}, \\( T \\) is a \\hyperref[def:universal_objects/terminal]{terminal object} if and only if it is the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top} of \\( P \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n", "meta": {"hexsha": "6c575969472f68c637acd8fe54f7ec8080651695", "size": 38365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/category_equivalences.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/category_equivalences.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/category_equivalences.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.7545454545, "max_line_length": 502, "alphanum_fraction": 0.7069985664, "num_tokens": 12066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6269238265077058}}
{"text": "\\section{Properties of determinants}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use the determinant of a square matrix to decide whether the\n    matrix is invertible.\n  \\item From the determinants of two matrices, calculate the\n    determinant of their product.\n  \\item From the determinant of a matrix, calculate the determinant of\n    its inverse.\n  \\item From the determinant of a matrix, calculate the determinant of\n    its transpose.\n  \\item Calculate the determinant of $kA$, if the determinant of $A$\n    is known.\n  \\item Without calculation, find the determinant of a matrix\n    containing a row or column of zeros, or a matrix containing a row\n    (or column) that is a scalar multiple of another row (or column).\n  \\item Use algebraic properties to reason about determinants.\n  \\end{enumerate}\n\\end{outcome}\n\nOne reason that the determinant is such an important quantity is that\nit permits us to tell whether a square matrix is invertible.\n\n\\begin{theorem}{Determinants and invertible matrices}{determinant-invertible}\n  Let $A$ be an $n\\times n$-matrix. Then $A$ is invertible%\n  \\index{determinant!and invertibility}%\n  \\index{matrix!determinant!and invertibility}%\n  \\index{invertible matrix!and determinant}%\n  \\index{matrix!invertible!and determinant} if and\n  only if $\\det(A) \\neq 0$.\n\\end{theorem}\n\n\\begin{proof}\n  We know that every matrix $A$ can be converted to {\\ef} by\n  elementary row operations. We also know from\n  Theorem~\\ref{thm:determinant-row-operations} that no elementary row\n  operation changes whether the determinant is zero or not.  Let $R$\n  be an {\\ef} of $A$. Because $R$ is an {\\ef}, it is also an upper\n  triangular matrix. Case 1: $A$ is invertible. In that case, the rank\n  of $R$ is $n$, and every diagonal entry of $R$ is a pivot entry\n  (therefore non-zero). It follows that $\\det(R)\\neq 0$, which implies\n  $\\det(A)\\neq 0$. Case 2: $A$ is not invertible. In that case, the\n  triangular matrix $R$ contains a row of zeros. It follows that\n  $\\det(R)=0$, and therefore $\\det(A)=0$.\n\\end{proof}\n\n\\begin{example}{Determinants and invertible matrices}{determinant-invertible}\n  Determine which of the following matrices are invertible by\n  computing their determinants.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      3 & 6 \\\\\n      2 & 4 \\\\\n    \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{rr}\n      2 & 3 \\\\\n      5 & 1 \\\\\n    \\end{mymatrix},\\quad\n    C = \\begin{mymatrix}{rrr}\n      1 & 2 & -5 \\\\\n      2 & 0 & 2  \\\\\n      3 & 1 & 0  \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have $\\det(A) = 3\\cdot 4 - 2\\cdot 6 = 0$ and $\\det(B) = 2\\cdot\n  1-5\\cdot 3 = -13$. Therefore, $B$ is invertible and $A$ is not\n  invertible. A quick way to compute the determinant of $C$ is to\n  expand it along the third row. We have\n  \\begin{equation*}\n    \\det(C)\n    = 3\\begin{absmatrix}{rr}\n      2 & -5 \\\\\n      0 & 2 \\\\\n    \\end{absmatrix}\n    - 1\\begin{absmatrix}{rr}\n      1 & -5 \\\\\n      2 & 2 \\\\\n    \\end{absmatrix}\n    = 3\\cdot 4 - 1\\cdot 12 = 0.\n  \\end{equation*}\n  Therefore, $C$ is not invertible.\n\\end{solution}\n\nAs an application of Theorem~\\ref{thm:determinant-invertible}, we note\nthat the determinant of an $n\\times n$-matrix can be used to predict\nwhether a homogeneous system of equations has non-trivial solutions.\n\n\\begin{corollary}{Determinants and homogeneous systems}{determinant-homogeneous}\n  Let $A$ be an $n\\times n$-matrix. Then the homogeneous system\n  $A\\vect{v}=\\vect{0}$ has non-trivial solutions if and only if $\\det(A)=0$.\n\\end{corollary}\n\n\\begin{proof}\n  We know from Theorem~\\ref{thm:rank-homogeneous-solutions} that the\n  homogeneous system has a non-trivial solution if and only if\n  $\\rank(A)<n$. This is the case if and only if $A$ is not invertible,\n  i.e., if and only if $\\det(A)=0$.\n\\end{proof}\n\nAnother reason the determinant is important is that it compatible with\nmatrix product.\n\n\\begin{theorem}{Determinant of a product}{determinant-of-product}\n  Let $A$ and $B$ be $n\\times n$-matrices. Then%\n  \\index{determinant!of product}%\n  \\index{matrix!determinant!of product}%\n  \\index{matrix!multiplication!determinant of product}%\n  \\index{multiplication!of matrices!determinant of product}%\n  \\begin{equation*}\n    \\det(AB) =\\det(A)\\det(B)\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  We first prove this in case $A=E$ is an elementary matrix. Remember\n  from Section~\\ref{sec:elementary-matrices} that elementary matrices\n  correspond to elementary row operations.\n  \\begin{enumerate}\n  \\item If $E$ is an elementary matrix for swapping two rows, then\n    $\\det(E)=-1$. Also, by Theorem~\\ref{thm:determinant-row-operations}(1),\n    $\\det(EB)=-\\det(B)$. Therefore $\\det(EB)=\\det(E)\\det(B)$.\n  \\item If $E$ is an elementary matrix for multiplying a row by a\n    non-zero scalar $k$, then $\\det(E)=k$. Also, by\n    Theorem~\\ref{thm:determinant-row-operations}(2),\n    $\\det(EB)=k\\det(B)$. Therefore $\\det(EB)=\\det(E)\\det(B)$.\n  \\item If $E$ is an elementary matrix for adding a multiple of one\n    row to another, then $\\det(E)=1$. Also, by\n    Theorem~\\ref{thm:determinant-row-operations}(3),\n    $\\det(EB)=\\det(B)$. Therefore $\\det(EB)=\\det(E)\\det(B)$.\n  \\end{enumerate}\n  Now consider the case where $A$ is an arbitrary matrix. Case 1: $A$\n  is invertible. Then by Theorem~\\ref{thm:prod-elementary}, we can\n  write $A$ as a product of elementary matrices $A=E_1E_2\\cdots E_k$.\n  By repeatedly using the formula $\\det(EB)=\\det(E)\\det(B)$ that we\n  proved above, we have\n  \\begin{equation*}\n    \\det(AB) = \\det(E_1E_2\\cdots E_kB) = \\det(E_1)\\det(E_2)\\cdots\\det(E_k)\\det(B)\n    = \\det(A)\\det(B).\n  \\end{equation*}\n  Case 2: $A$ is not invertible. Then $AB$ is also not invertible\n  (because if $C$ were an inverse of $AB$, we would have $ABC=I$, and\n  therefore, $BC$ would be an inverse of $A$). Therefore, by\n  Theorem~\\ref{thm:determinant-invertible}, we have $\\det(A)=0$ and\n  $\\det(AB)=0$. It follows that $\\det(AB)=\\det(A)\\det(B)$.\n\\end{proof}\n\n\\begin{example}{The determinant of a product}{determinant-of-product}\n  Compare $\\det(AB)$ and $\\det(A)\\det(B)$, where\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -3 & 2\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B=\\begin{mymatrix}{rr}\n      3 & 2 \\\\\n      4 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We first compute $AB$:\n  \\begin{equation*}\n    AB=\\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      -3 & 2\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      3 & 2 \\\\\n      4 & 1\n    \\end{mymatrix} = \\begin{mymatrix}{rr}\n      11 & 4 \\\\\n      -1 & -4\n    \\end{mymatrix}.\n  \\end{equation*}\n  The three determinants are\n  \\begin{equation*}\n    \\det(AB) = \\begin{absmatrix}{rr}\n      11 & 4 \\\\\n      -1 & -4\n    \\end{absmatrix} = -40,\n    \\quad\n    \\det(A) = \\begin{absmatrix}{rr}\n      1 & 2 \\\\\n      -3 & 2\n    \\end{absmatrix} = 8,\n    \\quad\\mbox{and}\\quad\n    \\det(B) = \\begin{absmatrix}{rr}\n      3 & 2 \\\\\n      4 & 1\n    \\end{absmatrix} = -5.\n  \\end{equation*}\n  Therefore $\\det(A)\\det(B) = 8\\cdot(-5) = -40 = \\det(AB)$.\n\\end{solution}\n\nThe following proposition summarizes some properties of determinants we\nhave discussed so far, as well as additional properties.\n\n\\begin{proposition}{Properties of determinants}{properties-of-determinants}\n  Let $A,B$ be $n\\times n$-matrices. Then:%\n  \\index{determinant!properties of}%\n  \\index{properties of determinants}%\n  \\index{matrix!determinant!properties}%\n  \\index{matrix!properties of determinants}\n  \\begin{enumerate}\n  \\item $\\det(AB)=\\det(A)\\det(B)$.\n  \\item $\\det(I) = 1$.\n  \\item $A$ is invertible if and only if $\\det(A)\\neq 0$. Moreover, if\n    this is the case, then\n    \\begin{equation*}\n      \\det(A^{-1}) = \\frac{1}{\\det(A)}.\n    \\end{equation*}\n  \\item $\\det(kA)=k^n\\det(A)$.\n  \\item $\\det(A^T) = \\det(A)$.\n  \\end{enumerate}\n\\end{proposition}\n\n\\begin{proof}\n  Property 1 is a restatement of\n  Theorem~\\ref{thm:determinant-of-product}. Property 2 follows from\n  Theorem~\\ref{thm:determinant-of-triangular-matrix}, because the\n  identity matrix is an upper triangular matrix. Property 3: The first\n  part is Theorem~\\ref{thm:determinant-invertible}. For the second\n  part, assume $A$ is invertible. Then by properties 1 and 2,\n  $\\det(A)\\det(A^{-1}) = \\det(AA^{-1}) = \\det(I) = 1$. The claim\n  follows by dividing both sides of the equation by\n  $\\det(A)$. Property 4 follows from\n  Theorem~\\ref{thm:determinant-row-operations}(2), because $kA$ is\n  obtained from $A$ by multiplying all $n$ rows by $k$. Each time we\n  multiple one row by $k$, the determinant is multiplied by\n  $k$. Property 5 follows because expanding $\\det(A)$ along columns\n  amounts to the same thing as expanding $\\det(A^T)$ along rows.\n\\end{proof}\n\nWe end this section with a few useful ways of spotting matrices of\ndeterminant 0.\n\n\\begin{theorem}{Special matrices with zero determinant}{special-determinant-zero}\n  Let $A$ be an $n\\times n$-matrix.\n  \\begin{enumerate}\n  \\item If $A$ has a row consisting only of zeros, or a column\n    consisting only of zeros, then $\\det(A)=0$.\n  \\item If $A$ has a row that is a scalar multiple of another row, or\n    a column that is a scalar multiple of another column, then\n    $\\det(A)=0$.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n  The first property follows by cofactor expansion: simply expand the\n  determinant along the row or column that consists only of zeros.\n  For the second property, assume that $A$ has a row that is a scalar\n  multiple of another row. We can then perform an elementary row\n  operation to create a row of zeros. By\n  Theorem~\\ref{thm:determinant-row-operations}(3), the determinant is\n  unchanged, so that $\\det(A)=0$. In the case that $A$ has a column\n  that is a scalar multiple of another column, we apply the same\n  reasoning to $A^T$ and use the fact that $\\det(A)=\\det(A^T)$.\n\\end{proof}\n", "meta": {"hexsha": "ac22f5a92599352e1f271ac5e4224bc9d6630739", "size": 9826, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-Properties.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-Properties.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-Properties.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.2196969697, "max_line_length": 81, "alphanum_fraction": 0.6727050682, "num_tokens": 3178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.6268639318176689}}
{"text": "\\section{Cycle}\n\n%%%%%%%%%%%%%%%\n\\begin{frame}{Cycle detection}\n  \\begin{table}[ht]\n    \\centering\n    \\caption{Cycle detection \\pno{3.4.21}}\n    \\begin{tabular}{c||c|c}\n     \\hline\n     \t\t& Digraph \t\t\t& Undirected graph  \\\\ \\hline \\hline\n\t\tDFS \t& back edge \\textcolor{red}{$\\iff$} cycle \t\n\t\t\t& back edge $\\iff$ cycle \n\t\t\t\\\\ \\hline\n\t\tBFS\t& \\begin{tabular}[c]{@{}l@{}}back edge $\\Rightarrow$ cycle\\\\ cycle \\textcolor{red}{$\\nRightarrow$} back edge \\end{tabular} \n\t\t\t& cross edge $\\iff$ cycle  \n\t\t\t\\\\ \\hline\n    \\end{tabular}\n  \\end{table}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Cycle detection}\n  \\begin{block}{Solution.}\n    \\begin{columns}[t]\n      \\column{0.50\\textwidth}\n\tDFS on digraph: $\\text{cycle} \\Rightarrow \\text{back edge}$\n\t\\begin{figure}\n\t  \\centering\n\t  \\includegraphics[width=0.50\\textwidth]{figures/dfs-digraph-cycle-detection-without-back.pdf}\n\t\\end{figure}\n      \\column{0.50\\textwidth}\n\tBFS on digraph: $\\text{cycle} \\nRightarrow \\text{back edge}$\n\t\\begin{figure}\n\t  \\centering\n\t  \\includegraphics[width=0.30\\textwidth]{figures/bfs-digraph-cycle-without-back.png}\n\t\\end{figure}\n      \\end{columns}\n  \\end{block}\n\n  \\begin{alertblock}{Remark.}\n    \\begin{itemize}\n      \\item cycle in undirected graphs (shortly)\n      \\item cycle in digraphs $\\Rightarrow$ DAG, SCC\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Edge deletion}\n  \\begin{exampleblock}{Edge deletion \\pno{3.4.12}}\n    \\begin{itemize}\n      \\item Input: connected, undirected graph $G$\n      \\item Problem: $\\exists? e \\in E: G \\setminus e$ is connected?\n      \\item $O(|V|)$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    cycle $\\iff \\exists e$:\n    \\begin{proof}\n      \\begin{itemize}\n\t\\item $\\Leftarrow$: by contradiction. connected + acyclic $\\Rightarrow$ tree\n      \\end{itemize}\n    \\end{proof}\n\n    tree: $|E| = |V| - 1$ $\\Rightarrow$ check $|E| \\ge |V|$\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Orientation of undirected graph}\n  \\begin{exampleblock}{Orientation of undirected graph \\pno{3.4.13}}\n    Undirected (connected) graph $G$, edge oriented s.t. $\\forall v, \\text{in}[v] \\ge 1$.\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    orientation $\\iff$ $\\exists$ cycle; DFS\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Bipartite graph}\n  \\begin{exampleblock}{Bipartite graph \\pno{3.4.26; 3.4.32}}\n    To test bipartiteness of an undirected graph.\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{columns}\n      \\column{0.40\\textwidth}\n        BFS + Coloring:\n\t\\begin{itemize}\n\t  \\item pick any $s$, c[s] = 0\n\t  \\item $u \\gets \\text{Dequeue}(Q)$\n\t  \\item $\\forall (u,v)$: \n\t    \\begin{itemize}\n\t      \\item tree edge\n\t      \\item cross edge: \\textcolor{red}{check}\n\t    \\end{itemize}\n\t\\end{itemize}\n      \\column{0.60\\textwidth}\n\t\\begin{proof}\n\t  Check cross edge $(u,v)$:\n\t  \\begin{itemize}\n\t    \\item ($\\exists$) $d[v] = d[u]$ $\\Rightarrow$ the same layer $\\Rightarrow$ odd cycle (\\pno{3.4.17}; \\textcolor{red}{EX}) $\\Rightarrow$ non-bipartite\n\t    \\item ($\\forall$) $d[v] = d[u] + 1$ $\\Rightarrow$ different layers $\\Rightarrow$ different colors\n\t  \\end{itemize}\n\t\\end{proof}\n    \\end{columns}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "0f8dc68661ff279abc304c5bcc892988264463a4", "size": 3230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/cycle.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-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/cycle.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-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/cycle.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": 29.9074074074, "max_line_length": 153, "alphanum_fraction": 0.6198142415, "num_tokens": 1101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085758631159, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6268229216994713}}
{"text": "\\section{Computational Methods and Software}\n\\label{sec:method}\n\n\\subsection{Equations (discretization and finite elements)}\n\nWe use the 3-D incompressible Navier-Stokes to model a\nlow-speed fluid flow with heat convection and diffusion and buoyancy. \n\n\\begin{align*}\n    \\bv{R}\\left(\\left[\n    \\begin{array}{l}\n        \\bv{u} \\\\\n        p \\\\\n        T \n    \\end{array}\n    \\right]\\right) \\equiv& \n    \\left[\n    \\begin{array}{l}\n        \\frac{\\partial (\\rho \\bv{u})}{\\partial t} + \\rho \\bv{u} \\cdot\n    \\nabla \\bv{u} + \\nabla p - \\mu \\nabla^2 \\bv{u} + \n    \\rho \\beta_T (T - T_0) \\bv{g} \\\\\n    \\nabla \\cdot \\bv{u} \\\\\n    \\frac{\\partial (\\rho c_p T)}{\\partial t} + \\rho c_p \\bv{u} \\cdot\n    \\nabla T - k \\nabla^2 T\n    \\end{array} \n    \\right] = 0\n\\end{align*}\n\nThe Navier-Stokes equations are derived from conservation of mass,\nmomentum and energy, and are a highly reliable model for low-speed flows\nof the sort encountered here. The boussinesq approximation for the\nbuoyancy is less generally applicable, but still accurate for a\nwide variety of flows in nature, such as atmospheric fronts, oceanic\ncirculation, etc. The Boussinesq buoyancy approximation relies upon the\ndifference in density in the fluid being negligible except for gravitational\nforces which are large enough to make the specific weight appreciably different\nbetween the two fluids.\n\n\n\\subsection{Modeling the vanes}\n\nTalk about penalty method here\n% Be sure to pull out your old penalty method write up here.\n% Will want to use an abridged version, and expand that in the full doc\n\n\\subsection{Software}\n\nGRINS blurb (dont forget paper)\n\n\\subsection{Simulation geometry}\n\ncheck out val doc here\ndont forget to add wall spacing function to document\n\nprobably need to create a table of runs, perhaps that goes in results\n", "meta": {"hexsha": "8e139e3cc6bbb03bb07130f105302cfa9f8ddbec", "size": 1792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/propositum/method.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/propositum/method.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/propositum/method.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 32.0, "max_line_length": 79, "alphanum_fraction": 0.7131696429, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7090191214879992, "lm_q1q2_score": 0.6268007635690935}}
{"text": "\\subsection{Statistical Analysis} \\label{sec:tth_stat_analysis}\nThe measured parameters of interest (POIs), namely $\\mu_{\\ttH}$, are extracted by constructing a likelihood function which depends on these POIs and finding their values which maximize the likelihood function.\nThe likelihood function expresses the probability of the observed data, given the prediction taken from the signal and background model.\nMore precisely,\n\\begin{equation}\n    \\mathcal L (\\text{data} ~|~ \\mu_{\\ttH}, \\vec{\\theta}) = \\mathcal L \\bigg(\\text{data} ~\\Big|~ \\Big[ S(\\mu_{\\ttH}, \\vec{\\theta}) + B(\\vec{\\theta}) \\Big] \\times C(\\vec{\\theta}) \\bigg),\n\\end{equation} \nwhere $\\vec{\\theta}$ is the vector of nuisance parameters (i.e. those described in Sec.~\\ref{sec:tth_systematic_uncertainties}) which are typically modeled as log-normal distributions (Eqn.~\\ref{eqn:tth_log_normal}).\n\nThe fit is performed simultaneously in all signal regions; in other words, the likelihood function is a product of the likelihood functions for each signal region:\n\\begin{equation}\n    \\mathcal L (\\text{data} ~|~ \\mu_{\\ttH}, \\vec{\\theta})\n    =\n    \\prod_{i=1}^{N_{\\text{SR}}} \\mathcal L_i \\bigg(\\text{data}_i ~\\Big|~ \\Big[ S_i(\\mu_{\\ttH}, \\vec{\\theta}) + B_i(\\vec{\\theta}) \\Big] \\times C(\\vec{\\theta}) \\bigg),\n\\end{equation}\nwhere $N_{\\text{SR}} = 8$ is the total number of signal regions and $\\text{data}_i, S_I,$ and $B_i$ are the observed data, signal model, and background model in the $i$-th signal region, respectively.\n\nMoreover, the likelihood function is discretized into bins of 0.25 GeV in the [100, 180] GeV region. The likelihood function in a particular signal region is then\n\\begin{equation}\n    \\mathcal L_i \\bigg(\\text{data}_i ~\\Big|~ \\Big[ S_i(\\mu_{\\ttH}, \\vec{\\theta}) + B_i(\\vec{\\theta}) \\Big] \\times C(\\vec{\\theta}) \\bigg)\n    = \n    \\prod_{j=1}^{N_\\text{bins}} \\text{Poisson}\\Big( n_{i,j} ~\\Big|~ \\lambda_{i,j} \\Big) \\times C(\\vec{\\theta}),\n\\end{equation}\nwith $N_\\text{bins} = 320$ the total number of bins per signal region, $n_{i,j}$ the number of observed data events in the $j$-th bin of the $i$-th signal region, and $\\lambda_{i,j}$ the expected number of events in that bin\n\\begin{equation}\n    \\lambda_{i,j} = S_{i,j}(\\mu_{\\ttH}, \\vec{\\theta}) + B_{i,j}(\\vec{\\theta}),\n\\end{equation}\nand Poisson indicates the standard Poisson distribution\n\\begin{equation}\n    \\text{Poisson}(n|\\lambda)\n    =\n    \\frac{\\lambda^n e^{-\\lambda}}{n!}.\n\\end{equation}\nThe bin size of 0.25 GeV is chosen with the characteristic diphoton mass resolution of 1.5-2 GeV in mind -- the bin size is sufficiently smaller than the resolution that the information lost by binning the data is negligible.\n\nIn practice, -2 times the natural logarithm of the likelihood function is nicer to work with from a numerical optimization point of view, and it is this quantity, referred to as the ``log-likelihood'', that is actually minimized in the fit:\n\\begin{equation}\n    2\\text{NLL} = -2 \\ln(\\mathcal L).\n\\end{equation}\nIn general, the fitted value $\\hat{\\mu}$ of a POI $\\mu$ is called the maximum likelihood estimate (MLE) of $\\mu$.\n\nThe log-likelihood also has desirable qualities for purposes of assessing the uncertainty on fitted POIs.\nIn particular, we may be interested in how much more likely a particular value of a POI $\\mu$ is than its MLE $\\hat{\\mu}$, i.e. the uncertainty on the fitted value.\nTo this end, it is helpful to study the quantity\n\\begin{equation} \\label{eqn:tth_likelihood_ratio}\n    \\lambda(\\mu) = \\frac{L(\\mu, \\hat{\\vec{\\theta}})}{L(\\hat{\\mu}, \\hat{\\hat{\\vec{\\theta}}})}\n\\end{equation}\nwhere $\\hat{\\vec{\\theta}}$ and $\\hat{\\hat{\\vec{\\theta}}}$ are the ML values of $\\vec{\\theta}$ for $\\mu$ and $\\hat{\\mu}$, respectively.\nThe quantity $\\lambda(\\mu)$ is called the ``profile likelihood ratio'', and -2 times the logarithm of this quantity is called the ``log-likelihood ratio''.\nA convenient property of the log-likelihood ratio is the fact that in the case of a single POI, it approximately follows a $\\chi^2$ distribution with one degree of freedom~\\cite{Cowan:2010js}.\nFor this reason, taking the square root of $\\lambda(\\mu)$ gives the Gaussian significance $Z$ associated with $\\mu$~\\cite{Cowan:2010js}, where\n\\begin{equation}\n    Z \\equiv \\Phi^{-1} (1 - p),\n\\end{equation}\nwith $\\Phi$ the Gaussian quantile function and $p$ the $p$-value.\nThe frequentist interpretation of $p$ is the following: in the limit of an infinite number of repeated, indepedent experiments in which the true value of the POI is $\\hat{\\mu}$, a value more extreme than $\\mu$ would be obtained in $p$ percent of these.\nThe Gaussian significance $Z$ can be interpreted in the following way: a Gaussian-distributed variable found $Z$ standard deviations away from its mean value has an associated p-value of $p$.\n\nWithin this framework, we express the uncertainty on $\\hat{\\mu}$ in terms of the values of $\\mu$ corresponding to a 68\\% (1 standard deviation) CL\\footnote{The choice of a 68\\% CL as the default for expressing uncertainties is somewhat arbitrary, and could easily be chosen as some other value.}, namely the values of $\\mu$ which give $\\lambda(\\mu) = 1$.\nAnother value of $\\mu$ of particular interest is $\\mu = 0$, corresponding to the case of the background-only hypothesis.\nThe associated significance $Z = \\sqrt{\\lambda(0)}$ is said to be the significance with which the signal has been observed, with $Z=5$ taken as the threshold for claiming discovery.\n\n\\subsection{Cross Section, Signal Strength, \\& Significance}\nThe observed diphoton mass distributions in the eight signal regions are nicely summarized in a couple plots in Fig.~\\ref{fig:tth_obs_sr_weighted}, which shows the weighted and unweighted sums of the distributions from each signal region.\nIn the case of the weighted sum, the distribution from each signal region is weighted by the factor $S / (S + B)$, giving higher weight to regions with higher purity.\n$S$ and $B$ are the signal and background yields, defined as the total number of \\Hgg events and the total number of non-resonant background events, respectively.\n\\begin{figure} [htbp!]\n    \\centering\n    \\begin{tabular} {c c}\n        \\includegraphics[width=0.48\\linewidth]{figures/tth/examplecombcat_weighted.pdf} &\n        \\includegraphics[width=0.48\\linewidth]{figures/tth/examplecombcat_unweighted.pdf}\n    \\end{tabular}\n    \\caption{Weighted (left) and unweighted (right) sum of observed diphoton mass distributions for all of the signal regions. Events from each signal region are weighted by the respective $S / (S +B)$ of that category in the case of the weighted sum. Taken from ~\\cite{tth_observation}.}\n    \\label{fig:tth_obs_sr_weighted}\n\\end{figure}\n\nThe diphoton mass distributions for each of the eight signal regions are shown individually in Appendix~\\ref{app:sr_mgg}.\n\nThe observed MLE of $\\mu_{\\ttH}$ is obtained from minimization of 2NLL of the likelihood function defined in Sec.~\\ref{sec:tth_stat_analysis} and is found to be 1.38.\nThe 68\\% CL for $\\hat{\\mu}_{\\ttH}$ is obtained from constructing the log-likelihood ratio defined in Eqn.~\\ref{eqn:tth_likelihood_ratio} as a function of $\\mu_{\\ttH}$ and is found to be $1.38^{+0.36}_{-0.29}$.\nThe log-likelihood ratio is shown in Fig.~\\ref{fig:tth_llr}.\n\n\\begin{figure} [htbp!]\n    \\centering\n    \\includegraphics[width=0.95\\linewidth]{figures/tth/MuScanProfileMH.pdf}\n    \\caption{Log-likelihood ratio for $\\mu_{\\ttH}$. The expected distribution, assuming the SM signal strength $\\mu_{\\ttH} = 1$, is shown in the green dotted line. The observed distribution is shown with full uncertainties (only statistical uncertainty) in the blue (red) lines. Taken from~\\cite{tth_observation}.}\n    \\label{fig:tth_llr}\n\\end{figure}\n\nThe observed cross-section times branching fraction of the \\ttH (\\Hgg) process is found to be $\\sigma_{\\ttH} \\mathcal B(\\text{H} \\to \\gamma \\gamma) = 1.56^{+0.34}_{-0.32}$ fb, while the SM prediction is $\\sigma_{\\ttH} \\mathcal B(\\text{H} \\to \\gamma \\gamma) = 1.13^{+0.08}_{-0.11}$ fb.\n\nIn addition to the MLE of $\\mu_{\\ttH}$ and its uncertainty, we are interested in the significance of the observation: the difference between the log-likelihood ratio evaluated at the MLE of $\\mu_{\\ttH} = \\hat{\\mu}_{\\ttH}$ and $\\mu_{\\ttH} = 0$, the case of the background-only hypothesis.\nThe observed significance, relative to the background-only hypothesis, is 6.6 standard deviations, while the expected significance is 4.7 standard deviations.\nWith a discovery threshold of 5 standard deviations, we are able to claim observation of the \\ttH (\\Hgg) process.\nThe observed and expected results for the cross section, signal strength, and significance are shown in Table~\\ref{tab:tth_results}.\n\\begin{table} [htbp!]\n    \\centering\n    \\caption{Expected and observed values of the cross section times branching fraction ($\\sigma_{\\ttH} \\mathcal B(\\text{H} \\to \\gamma \\gamma)$), signal strength ($\\mu_{\\ttH}$), and significance.}\n    \\begin{tabular}{r c c} \\hline \\hline\n        Quantity & Expected Value & Observed Value \\\\ \\hline\n        $\\sigma_{\\ttH} \\mathcal B(\\text{H} \\to \\gamma \\gamma)$ & $1.13$ fb & $1.56^{+0.34}_{-0.32}$ fb \\\\\n        $\\mu_{\\ttH}$ & $1.00$ & $1.38^{+0.36}_{-0.29}$ \\\\\n        Significance & $4.7\\sigma$ & $6.6\\sigma$ \\\\ \\hline \\hline\n    \\end{tabular}\n    %\\caption{Expected and observed values of the cross section times branching fraction ($\\sigma_{\\ttH} \\mathcal B(\\text{H} \\to \\gamma \\gamma)$), signal strength ($\\mu_{\\ttH}$), and significance.}\n    \\label{tab:tth_results}\n\\end{table}\n\n\\subsection{CP Measurement}\nIn addition to measuring the cross section and signal strength of the \\ttH (\\Hgg) process, the CP structure of the tree-level top quark Yukawa (Htt) coupling can also be tested.\nThe SM predicts that the Htt coupling is purely CP-even; any non-zero CP-odd component of the coupling would be an indication of new physics.\n\nA parametrization of the CP structure of the Htt amplitude can be given in terms of CP-even and CP-odd components~\\cite{Gritsan:2016hjl}:\\begin{equation}\n    A(\\text{Htt}) = - \\frac{m_t}{v} \\bar{\\psi}_t \\Big (\\kappa_t + i \\tilde{\\kappa}_t \\gamma_5 \\Big) \\psi_t,\n\\end{equation}\nwhere $\\kappa_t$ and $\\tilde{\\kappa}_t$ represent the CP-even and CP-odd couplings, respectively, and $v$ represents the SM Higgs field VEV.\nAs the SM predicts a purely CP-even Htt coupling, this implies the SM prediction of $\\kappa_t = 1$ and $\\tilde{\\kappa}_t = 0$.\nThe fractional CP-odd component is defined as\n\\begin{equation}\n    f^{\\text{Htt}}_{\\text{CP}} = \\frac{|\\tilde{\\kappa}_t|^2}{|\\kappa_t|^2 + |\\tilde{\\kappa}_t|^2}~\\text{sign}(\\tilde{\\kappa}_t/\\kappa_t),\n\\end{equation}\nand this is the physical observable constrained by the \\ttH (\\Hgg) analysis~\\cite{tth_observation}.\n\nThe CP measurement is performed by starting with signal categories defined by the BDT-bkg algorithm detailed in Sec.~\\ref{sec:tth_mvas}.\nNext, BDTs, referred to as the $\\mathcal D_{0-}$ discriminants, are trained to distinguish between CP-even and CP-odd scenarios for the Htt coupling.\nThis is achieved by first simulating \\ttH samples with anomalous couplings, including samples of pure CP-even (SM-like), pure CP-odd, and a mixture of the two.\nThese samples are generated at leading order with the \\textsc{JHUGen} 7.0.2 software package and reweighted with the MELA matrix element library~\\cite{Gritsan:2016hjl,Gao:2010qx,Bolognesi:2012mm,Anderson:2013afp}.\nThe $\\mathcal D_{0-}$ BDTs are trained on the kinematic features described in Sec.~\\ref{sec:tth_hlf}, with a separate BDT for the hadronic and the leptonic channels, just as for the BDT-bkg algorithm.\nIn both the hadronic and leptonic channels, two signal categories are formed with requirements on the output of BDT-bkg, with the boundaries shown in Fig.~\\ref{fig:tth_bdt-bkg}.\nEach of these signal categories is further divided into three signal regions, chosen to maximize the expected sensitivity to $f^{\\text{Htt}}_{\\text{CP}}$, giving 12 total signal categories for the CP measurement.\n\nAs for the cross section and signal strength measurements, $f^{\\text{Htt}}_{\\text{CP}}$ is constrained with a simultaneous fit to the diphoton invariant mass spectrum in all 12 signal categories.\nFig.~\\ref{fig:tth_cp} shows the results of this fit, which are consistent with the SM prediction of $f^{\\text{Htt}}_{\\text{CP}} = 0$.\n\\begin{figure} [htbp!]\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/tth/Figure_003.png}\n    \\caption{Distribution of events, weighted by S/(S+B), selected for the CP measurement of the Htt coupling. Events from both BDT-bkg categories in both the hadronic and leptonic channels are shown in each $\\mathcal D_{0-}$ bin. The background contribution is subtracted from each bin. The likelihood scan for $f^{\\text{Htt}}_{\\text{CP}}$ is displayed in the inner panel. Taken from~\\cite{tth_observation}.}\n    \\label{fig:tth_cp}\n\\end{figure}\nThe observed (expected) constraint on the CP structure of the Htt coupling is $f^{\\text{Htt}}_{\\text{CP}} = 0.00 \\pm 0.33 (0.00 \\pm 0.49)$ at 68\\% CL.\nThe observed (expected) significance with which the pure CP-odd model is excluded is $3.2\\sigma (2.6\\sigma)$.\nAn additional systematic uncertainty is introduced for the CP measurement to account for potential differences in kinematic distributions obtained through the \\textsc{JHUGen} generator and the \\textsc{MadGraph} generator used to model the SM processes, though the uncertainty in the measurement is still dominated by the statistical uncertainty.\n\nThus, the measurement of the CP structure of the Htt coupling is found to be consistent with the SM value of $f^{\\text{Htt}}_{\\text{CP}} = 0$.\n\n", "meta": {"hexsha": "a8c45b7854397ae17b34287ffc00613c311bd69b", "size": 13596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tth_analysis/results.tex", "max_stars_repo_name": "sam-may/phd_thesis", "max_stars_repo_head_hexsha": "acd61f340e5677deba412b1b3baecd124c32440f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tth_analysis/results.tex", "max_issues_repo_name": "sam-may/phd_thesis", "max_issues_repo_head_hexsha": "acd61f340e5677deba412b1b3baecd124c32440f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tth_analysis/results.tex", "max_forks_repo_name": "sam-may/phd_thesis", "max_forks_repo_head_hexsha": "acd61f340e5677deba412b1b3baecd124c32440f", "max_forks_repo_licenses": ["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.1232876712, "max_line_length": 409, "alphanum_fraction": 0.7357310974, "num_tokens": 3862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.6992544273261176, "lm_q1q2_score": 0.6267077367852981}}
{"text": "\n\n\n\\section{Dynamic Programming}\n\nDP are effective for medium size problems (million of states).\n\n\\subsection{Policy Evaluation (Prediction)}\n\nIf $P$ and $\\pi$ are known, Bellman equation (\\ref{bellman:v}) could be converted to iterative solution. All $V$ are randomly initialized and updated using \\cindex{iterative policy evaluation}:\n\n\\begin{equation}\n\tV_{k+1} (s) = \\sum_a \\pi (a | s) \\left ( \\sum_{s',r} p(s',r | s,a) \\Big ( r + \\gamma V_{k}(s') \\Big ) \\right )\n\\end{equation}\n\nHere $V_{t+1}(s)$ means the value of $V(s)$ in $(t+1)$ round.\n\nThere are two ways to update $V_{t+1}(s)$:\n\\begin{itemize}\n\t\\item copy $V_{t+1}(s)$ to a new array and update original array when sweeping is done\n\t\\item \\cindex{in-place} update: update $V(s)$ on the fly. updated value may be used immediately so it is faster than two array solution.\n\\end{itemize}\n\n\nThe problem is that iterative algorithm \\cindex{sweep} through all state space, which might not be practical.\n\nSee Algorithm (\\ref{algo:itepole}) for detail.\n\n\\begin{algorithm}\n\t\\caption{Iterative policy evaluation, estimate $V_\\pi$}\\label{algo:itepole}\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{}{$\\pi, p, \\theta$}\n\t\t\t\\State $\\forall s \\in S, V(s) \\gets random$\n\t\t\t\\State $V(terminal) \\gets 0$\n\t\t\t\\Repeat\n\t\t\t\t\\State $\\Delta \\gets 0$\n\t\t\t\t\\For{$s \\in S$}\n\t\t\t\t\t\\State $v \\gets V(s)$\n\t\t\t\t\t\\State \\Comment{in-place update}\n\t\t\t\t\t\\State $V(s) \\gets \\sum\\limits_a \\pi (a | s) \\left ( \\sum\\limits_{s',r} p(s',r | s,a) \\big(r + \\gamma V(s') \\big ) \\right )$ \n\t\t\t\t\t\\State $\\Delta \\gets \\max{}(v, |v - V(s)|)$\n\t\t\t\t\\EndFor\n\t\t\t\\Until{$\\Delta < \\theta$}\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\n\\end{algorithm}\n\n\n\\subsection{Policy Improvement}\n\nThe reason for calculating value function is to help find a better policy. A new greedy policy $\\pi^{\\prime}$ could be calculated using:\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\pi^{\\prime}(s) &= \\underset{a \\in \\mathcal{A}(s)}{\\text{argmax}} \\ q_{\\pi}(s,a)\\\\\n\t\t&=\\underset{a \\in \\mathcal{A}(s)}{\\text{argmax}}\\ \\sum_{s',r} p(s',r|s,a)\\Big ( r+\\gamma V(s') \\Big )\n\t\\end{aligned}\n\\end{equation}\n\nA series of policy evaluation and improvement will converge to optimal result, and its conversion is very fast. \n\nThe drawback is that every iteration may trigger evaluation, which involves multiple sweep through all state space.\n\nSee Algorithm (\\ref{algo:polite}) for detail.\n\n\n\\begin{algorithm}\n\t\\caption{Policy Iteration, estimate $V_*$ and $\\pi_*$}\\label{algo:polite}\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\forall s \\in \\mathcal{S}, V(s) \\gets random$\n\t\t\\State $V(terminal) \\gets 0$\n\t\t\\State $\\pi(s) \\gets \\text{random}(\\mathcal{A}(s))$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Procedure{PolicyEvaluation}{$\\varepsilon$}\n\t\t\t\\Repeat\n\t\t\t\t\\State $\\Delta \\gets 0$\n\t\t\t\t\\For{$s \\in \\mathcal{S}$}\n\t\t\t\t\t\\State $v \\gets V(s)$\n\t\t\t\t\t\\State $V(s) \\gets \\sum\\limits_{s',r} p(s',r|s,\\pi(s))\\big (r+\\gamma V(s') \\big )$ \\Comment{$\\pi(s)$ : use optimal policy}\n\t\t\t\t\t\\State $\\Delta \\gets \\max (\\Delta, |v - V(s)|)$\n\t\t\t\t\\EndFor\n\t\t\t\\Until{$\\Delta < \\varepsilon$}\n\t\t\\EndProcedure\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Procedure{PolicyImprovement}{}\n\t\t\t\\State $\\text{stable} \\gets \\text{TRUE}$\n\t\t\t\\For{$s \\in \\mathcal{S}$}\n\t\t\t\t\\State $old \\gets \\pi(s)$\n\t\t\t\t\\State $\\pi(s) \\gets \\underset{a \\in \\mathcal{A}(s)}{\\text{argmax}}\\ \\sum\\limits_{s',r}P(s',r|s,a) \\big (r+\\gamma V(s') \\big )$\n\t\t\t\t\\If{$old \\neq \\pi(s)$}\n\t\t\t\t\t\\State $\\text{stable} \\gets \\text{FALSE}$\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\t\\If{$\\text{stable}$}\n\t\t\t\t\\Return $(V_*,\\pi_*)$\n\t\t\t\\Else\n\t\t\t\t\\State \\Call{PolicyEvaluation}{$\\varepsilon$} \\Comment{update $V$ if optimal policy has changed}\n\t\t\t\\EndIf\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Value Iteration}\n\nIn policy iteration, multiple sweep can be reduce to one by taking the best action, and calculate optimal policy using (\\ref{optimal:policy}):\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\tV_{k+1}^{old} (s) &= \\sum_{s',r} p(s',r|s,\\pi(s))\\big (r+\\gamma V_k(s') \\big ) \\\\\n\t\tV_{k+1}^{new} (s) &= \\underset{a}{\\max} \\sum_{s',r} p(s',r|s,a) \\big (r+\\gamma V_k(s') \\big )\n\t\\end{aligned}\n\\end{equation}\n\nSee Algorithm (\\ref{algo:valite}) for detail.\n\n\\begin{algorithm}\n\t\\caption{Value Iteration, estimate $\\pi_*$}\\label{algo:valite}\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\forall s \\in S, V(s) \\gets random$\n\t\t\\State $V(terminal) \\gets 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Repeat\n\t\t\t\\State $\\Delta \\gets 0$\n\t\t\t\\For{$s \\in S$}\n\t\t\t\t\\State $v \\gets V(s)$\n\t\t\t\t\\State \\Comment policy evaluation and improvement\n\t\t\t\t\\State $V(s) \\gets \\underset{a}{\\max}\\ \\sum\\limits_{s',r} p(s',r|s,a) \\big ( r+\\gamma V(s') \\big )$ \n\t\t\t\t\\State $\\Delta \\gets \\max (\\Delta, |v - V(s)|)$\n\t\t\t\\EndFor\n\t\t\\Until{$\\Delta < \\theta$}\n\t\t\n\t\t\\State \\Return $\\pi_*(s)= \\underset{a}{\\text{argmax}} \\ \\sum\\limits_{s',r} p(s',r|s,a) \\big (r+\\gamma V(s') \\big )$\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Generalized Policy Iteration}\n\n\\cindex{Generalized Policy Iteration} (GPI) is a series of evaluation and improvement process. Almost all reinforcement learning methods are GPI.\n\n\n\\subsection{Performance}\n\nDP is exponentially faster than direct \\cindex{policy space search}.\n\nDP is better than \\cindex{linear programming methods} for large problem, but worse for small problem.\n\n\nThe \\cindex{curse of dimension} is not the problem of algorithm but the problem itself.\n\nThe time complexity for $v$ is $O(mn^2)$ and for $q$ is $O(m^2 n^2)$, where $m$ is the number of action and $n$ is the number of state. So DP is effective for medium size problems (million of states).\n\n\\subsection{Extension to Sweeping}\n\n\\subsubsection{Prioritized Sweeping}\n\nbackup the state with the maximum \\cindex{Bellman error}:\n\\begin{equation}\n\t\\left| \\max_{ a \\in \\mathcal{A}} \\left( \\mathcal{R}\n\t+ \\gamma \\sum_{s' \\in S} \\mathcal{P}_{ss'}^a v(s') \\right) - v(s) \\right|\n\\end{equation}\n\n\\subsubsection{Realtime Dynamic Programming}\n\nChoose the state that are relevant to agent.\n\n", "meta": {"hexsha": "27d702efd074779a6b3a1957482bef5cf0fd00a4", "size": 5829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.3.dp.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/reinforcement_learning/rl.3.dp.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/reinforcement_learning/rl.3.dp.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": 33.1193181818, "max_line_length": 200, "alphanum_fraction": 0.6560301939, "num_tokens": 2010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6266715835158805}}
{"text": "\\startcomponent ma-cb-en-mathcharacters\n\n\\product ma-cb-en\n\n\\chapter[overviews]{Commands in math mode}\n\n\\index{symbols in math mode}\n\n\\section{Greek characters}\n\n\\starttabulate[|l|l|l|l|l|l|l|l|l|]\n\\NC           \\NC $\\alpha$      \\NC \\type{\\alpha}\n\\NC           \\NC $\\iota$       \\NC \\type{\\iota}\n\\NC           \\NC $\\varrho$     \\NC \\type{\\varrho}    \\NC\\NR\n\\NC           \\NC $\\beta$       \\NC \\type{\\beta}\n\\NC           \\NC $\\kappa$      \\NC \\type{\\kappa}\n\\NC $\\Sigma$  \\NC $\\sigma$      \\NC \\type{\\sigma}     \\NC\\NR\n\\NC $\\Gamma$  \\NC $\\gamma$      \\NC \\type{\\gamma}\n\\NC $\\Lambda$ \\NC $\\lambda$     \\NC \\type{\\lambda}\n\\NC           \\NC $\\varsigma$   \\NC \\type{\\varsigma}  \\NC\\NR\n\\NC $\\Delta$  \\NC $\\delta$      \\NC \\type{\\delta}\n\\NC           \\NC $\\mu$         \\NC \\type{\\mu}\n\\NC           \\NC $\\tau$        \\NC \\type{\\tau}       \\NC\\NR\n\\NC           \\NC $\\epsilon$    \\NC \\type{\\epsilon}\n\\NC           \\NC $\\nu$         \\NC \\type{\\nu}\n\\NC           \\NC $\\upsilon$    \\NC \\type{\\upsilon}   \\NC\\NR\n\\NC           \\NC $\\varepsilon$ \\NC \\type{\\varepsilon}\n\\NC $\\Xi$     \\NC $\\xi$         \\NC \\type{\\xi}\n\\NC $\\Phi$    \\NC $\\phi$        \\NC \\type{\\phi}       \\NC\\NR\n\\NC           \\NC $\\zeta$       \\NC \\type{\\zeta}\n\\NC           \\NC $o$           \\NC \\type{o}\n\\NC           \\NC $\\varphi$     \\NC \\type{\\varphi}    \\NC\\NR\n\\NC           \\NC $\\eta$        \\NC \\type{\\eta}\n\\NC $\\Pi$     \\NC $\\pi$         \\NC \\type{\\pi}\n\\NC           \\NC $\\chi$        \\NC \\type{\\chi}       \\NC\\NR\n\\NC $\\Theta$  \\NC $\\theta$      \\NC \\type{\\theta}\n\\NC           \\NC $\\varpi$      \\NC \\type{\\varpi}\n\\NC $\\Psi$    \\NC $\\psi$        \\NC \\type{\\psi}       \\NC\\NR\n\\NC           \\NC $\\vartheta$   \\NC \\type{\\vartheta}\n\\NC           \\NC $\\rho$        \\NC \\type{\\rho}\n\\NC $\\Omega$  \\NC $\\omega$      \\NC \\type{\\omega}     \\NC\\NR\n\\stoptabulate\n\n\\section{Special symbols}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\aleph$       \\NC \\type{\\aleph}\n\\NC $\\prime$       \\NC \\type{\\prime}\n\\NC $\\forall$      \\NC \\type{\\forall}\n\\NC\\NR\n\\NC $\\hbar$        \\NC \\type{\\hbar}\n\\NC $\\emptyset$    \\NC \\type{\\emptyset}\n\\NC $\\exists$      \\NC \\type{\\exists}\n\\NC\\NR\n\\NC $\\imath$       \\NC \\type{\\imath}\n\\NC $\\nabla$       \\NC \\type{\\nabla}\n\\NC $\\neg$         \\NC \\type{\\neg}\n\\NC\\NR\n\\NC $\\jmath$       \\NC \\type{\\jmath}\n\\NC $\\surd$        \\NC \\type{\\surd}\n\\NC $\\flat$        \\NC \\type{\\flat}\n\\NC\\NR\n\\NC $\\ell$         \\NC \\type{\\ell}\n\\NC $\\top$         \\NC \\type{\\top}\n\\NC $\\natural$     \\NC \\type{\\natural}\n\\NC\\NR\n\\NC $\\wp$          \\NC \\type{\\wp}\n\\NC $\\bot$         \\NC \\type{\\bot}\n\\NC $\\sharp$       \\NC \\type{\\sharp}\n\\NC\\NR\n\\NC $\\Re$          \\NC \\type{\\Re}\n\\NC $\\Vert$        \\NC \\type{\\Vert}\n\\NC $\\clubsuit$    \\NC \\type{\\clubsuit}\n\\NC\\NR\n\\NC $\\Im$          \\NC \\type{\\Im}\n\\NC $\\angle$       \\NC \\type{\\angle}\n\\NC $\\diamondsuit$ \\NC \\type{\\diamondsuit}\n\\NC\\NR\n\\NC $\\partial$     \\NC \\type{\\partial}\n\\NC $\\triangle$    \\NC \\type{\\triangle}\n\\NC $\\heartsuit$   \\NC \\type{\\heartsuit}\n\\NC\\NR\n\\NC $\\infty$       \\NC \\type{\\infty}\n\\NC $\\backslash$   \\NC \\type{\\backslash}\n\\NC $\\spadesuit$   \\NC \\type{\\spadesuit}\n\\NC\\NR\n\\stoptabulate\n\n\\section{Operators in addition to $+$, $-$ and $*$}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\pm$              \\NC \\type{\\pm}\n\\NC $\\cap$             \\NC \\type{\\cap}\n\\NC $\\vee$             \\NC \\type{\\vee}\n\\NC\\NR\n\\NC $\\mp$              \\NC \\type{\\mp}\n\\NC $\\cup$             \\NC \\type{\\cup}\n\\NC $\\wedge$           \\NC \\type{\\wedge}\n\\NC\\NR\n\\NC $\\setminus$        \\NC \\type{\\setminus}\n\\NC $\\uplus$           \\NC \\type{\\uplus}\n\\NC $\\oplus$           \\NC \\type{\\oplus}\n\\NC\\NR\n\\NC $\\cdot$            \\NC \\type{\\cdot}\n\\NC $\\sqcap$           \\NC \\type{\\sqcap}\n\\NC $\\ominus$          \\NC \\type{\\ominus}\n\\NC\\NR\n\\NC $\\times$           \\NC \\type{\\times}\n\\NC $\\sqcup$           \\NC \\type{\\sqcup}\n\\NC $\\otimes$          \\NC \\type{\\otimes}\n\\NC\\NR\n\\NC $\\ast$             \\NC \\type{\\ast}\n\\NC $\\triangleleft$    \\NC \\type{\\triangleleft}\n\\NC $\\oslash$          \\NC \\type{\\oslash}\n\\NC\\NR\n\\NC $\\star$            \\NC \\type{\\star}\n\\NC $\\triangleright$   \\NC \\type{\\triangleright}\n\\NC $\\odot$            \\NC \\type{\\odot}\n\\NC\\NR\n\\NC $\\diamond$         \\NC \\type{\\diamond}\n\\NC $\\wr$              \\NC \\type{\\wr}\n\\NC $\\dagger$          \\NC \\type{\\dagger}\n\\NC\\NR\n\\NC $\\circ$            \\NC \\type{\\circ}\n\\NC $\\bigcirc$         \\NC \\type{\\bigcirc}\n\\NC $\\ddagger$         \\NC \\type{\\ddagger}\n\\NC\\NR\n\\NC $\\bullet$          \\NC \\type{\\bullet}\n\\NC $\\bigtriangleup$   \\NC \\type{\\bigtriangleup}\n\\NC $\\amalg$           \\NC \\type{\\amalg}\n\\NC\\NR\n\\NC $\\div$             \\NC \\type{\\div}\n\\NC $\\bigtriangledown$ \\NC \\type{\\bigtriangledown}\n\\NC ~                  \\NC ~\n\\NC\\NR\n\\stoptabulate\n\n\\section{Operators}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\sum$       \\NC \\type{\\sum}\n\\NC $\\prod$      \\NC \\type{\\prod}\n\\NC $\\coprod$    \\NC \\type{\\coprod}\n\\NC\\NR\n\\NC $\\int$       \\NC \\type{\\int}\n\\NC $\\oint$      \\NC \\type{\\oint}\n\\NC $\\bigcap$    \\NC \\type{\\bigcap}\n\\NC\\NR\n\\NC $\\bigcup$    \\NC \\type{\\bigcup}\n\\NC $\\bigsqcup$  \\NC \\type{\\bigsqcup}\n\\NC $\\bigvee$    \\NC \\type{\\bigvee}\n\\NC\\NR\n\\NC $\\bigwedge$  \\NC \\type{\\bigwedge}\n\\NC $\\bigodot$   \\NC \\type{\\bigodot}\n\\NC $\\bigotimes$ \\NC \\type{\\bigotimes}\n\\NC\\NR\n\\NC $\\bigoplus$  \\NC \\type{\\bigoplus}\n\\NC $\\biguplus$  \\NC \\type{\\biguplus}\n\\NC              \\NC\n\\NC\\NR\n\\stoptabulate\n\n\\section{Relation in addition to $>$, $<$ and $=$}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\leq$        \\NC \\type{\\leq}\n\\NC $\\geq$        \\NC \\type{\\geq}\n\\NC $\\equiv$      \\NC \\type{\\equiv}\n\\NC\\NR\n\\NC $\\prec$       \\NC \\type{\\prec}\n\\NC $\\succ$       \\NC \\type{\\succ}\n\\NC $\\sim$        \\NC \\type{\\sim}\n\\NC\\NR\n\\NC $\\preceq$     \\NC \\type{\\preceq}\n\\NC $\\succeq$     \\NC \\type{\\succeq}\n\\NC $\\simeq$      \\NC \\type{\\simeq}\n\\NC\\NR\n\\NC $\\ll$         \\NC \\type{\\ll}\n\\NC $\\gg$         \\NC \\type{\\gg}\n\\NC $\\asymp$      \\NC \\type{\\asymp}\n\\NC\\NR\n\\NC $\\subset$     \\NC \\type{\\subset}\n\\NC $\\supset$     \\NC \\type{\\supset}\n\\NC $\\approx$     \\NC \\type{\\approx}\n\\NC\\NR\n\\NC $\\subseteq$   \\NC \\type{\\subseteq}\n\\NC $\\supseteq$   \\NC \\type{\\supseteq}\n\\NC $\\cong$       \\NC \\type{\\cong}\n\\NC\\NR\n\\NC $\\sqsubseteq$ \\NC \\type{\\sqsubseteq}\n\\NC $\\sqsupseteq$ \\NC \\type{\\sqsupseteq}\n\\NC $\\bowtie$     \\NC \\type{\\bowtie}\n\\NC\\NR\n\\NC $\\in$         \\NC \\type{\\in}\n\\NC $\\ni$         \\NC \\type{\\ni}\n\\NC $\\propto$     \\NC \\type{\\propto}\n\\NC\\NR\n\\NC $\\vdash$      \\NC \\type{\\vdash}\n\\NC $\\dashv$      \\NC \\type{\\dashv}\n\\NC $\\models$     \\NC \\type{\\models}\n\\NC\\NR\n\\NC $\\smile$      \\NC \\type{\\smile}\n\\NC $\\mid$        \\NC \\type{\\mid}\n\\NC $\\doteq$      \\NC \\type{\\doteq}\n\\NC\\NR\n\\NC $\\frown$      \\NC \\type{\\frown}\n\\NC $\\parallel$   \\NC \\type{\\parallel}\n\\NC $\\perp$       \\NC \\type{\\perp}\n\\NC\\NR\n\\stoptabulate\n\n\\section{Negated relations}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\not<$           \\NC \\type{\\not}\\type{<}\n\\NC $\\not>$           \\NC \\type{\\not}\\type{>}\n\\NC $\\not=$           \\NC \\type{\\not}\\type{=}\n\\NC\\NR\n\\NC $\\not\\leq$        \\NC \\type{\\not}\\type{\\leq}\n\\NC $\\not\\geq$        \\NC \\type{\\not}\\type{\\geq}\n\\NC $\\not\\equiv$      \\NC \\type{\\not}\\type{\\equiv}\n\\NC\\NR\n\\NC $\\not\\prec$        \\NC \\type{\\not}\\type{\\prec}\n\\NC $\\not\\succ$        \\NC \\type{\\not}\\type{\\succ}\n\\NC $\\not\\sim$         \\NC \\type{\\not}\\type{\\sim}\n\\NC\\NR\n\\NC $\\not\\preceq$      \\NC \\type{\\not}\\type{\\preceq}\n\\NC $\\not\\succeq$      \\NC \\type{\\not}\\type{\\succeq}\n\\NC $\\not\\simeq$       \\NC \\type{\\not}\\type{\\simeq}\n\\NC\\NR\n\\NC $\\not\\subset$      \\NC \\type{\\not}\\type{\\subset}\n\\NC $\\not\\supset$      \\NC \\type{\\not}\\type{\\supset}\n\\NC $\\not\\approx$      \\NC \\type{\\not}\\type{\\approx}\n\\NC\\NR\n\\NC $\\not\\subseteq$    \\NC \\type{\\not}\\type{\\subseteq}\n\\NC $\\not\\supseteq$    \\NC \\type{\\not}\\type{\\supseteq}\n\\NC $\\not\\cong$        \\NC \\type{\\not}\\type{\\cong}\n\\NC\\NR\n\\NC $\\not\\sqsubseteq$  \\NC \\type{\\not}\\type{\\sqsubseteq}\n\\NC $\\not\\sqsupseteq$  \\NC \\type{\\not}\\type{\\sqsupseteq}\n\\NC $\\not\\asymp$       \\NC \\type{\\not}\\type{\\asymp}\n\\NC\\NR\n\\stoptabulate\n\n\\section{Some arrows}\n\n\\starttabulate[|l|l|l|l|l|l|]\n\\NC $\\leftarrow$          \\NC \\type{\\leftarrow}\n\\NC $\\longleftarrow$      \\NC \\type{\\longleftarrow}\n\\NC $\\uparrow$            \\NC \\type{\\uparrow}\n\\NC\\NR\n\\NC $\\Leftarrow$          \\NC \\type{\\Leftarrow}\n\\NC $\\Longleftarrow$      \\NC \\type{\\Longleftarrow}\n\\NC $\\Uparrow$            \\NC \\type{\\Uparrow}\n\\NC\\NR\n\\NC $\\rightarrow$         \\NC \\type{\\rightarrow}\n\\NC $\\longrightarrow$     \\NC \\type{\\Rightarrow}\n\\NC $\\downarrow$          \\NC \\type{\\downarrow}\n\\NC\\NR\n\\NC $\\Rightarrow$         \\NC \\type{\\Rightarrow}\n\\NC $\\Longrightarrow$     \\NC \\type{\\Longrightarrow}\n\\NC $\\Downarrow$          \\NC \\type{\\Downarrow}\n\\NC\\NR\n\\NC $\\leftrightarrow$     \\NC \\type{\\leftrightarrow}\n\\NC $\\longleftrightarrow$ \\NC \\type{\\longleftrightarrow}\n\\NC $\\updownarrow$        \\NC \\type{\\updownarrow}\n\\NC\\NR\n\\NC $\\Leftrightarrow$     \\NC \\type{\\Leftrightarrow}\n\\NC $\\Longleftrightarrow$ \\NC \\type{\\Longleftrightarrow}\n\\NC $\\Updownarrow$        \\NC \\type{\\Updownarrow}\n\\NC\\NR\n\\NC $\\mapsto$             \\NC \\type{\\mapsto}\n\\NC $\\longmapsto$         \\NC \\type{\\longmapsto}\n\\NC $\\nearrow$            \\NC \\type{\\nearrow}\n\\NC\\NR\n\\NC $\\searrow$            \\NC \\type{\\searrow}\n\\NC $\\swarrow$            \\NC \\type{\\swarrow}\n\\NC $\\nwarrow$            \\NC \\type{\\nwarrow}\n\\NC\\NR\n\\NC $\\hookleftarrow$      \\NC \\type{\\hookleftarrow}\n\\NC $\\hookrightarrow$     \\NC \\type{\\hookrightarrow}\n\\NC ~ \\NC ~\n\\NC\\NR\n\\stoptabulate\n\n\\section{Alternative commands}\n\n\\starttabulate[|l|l|l|l|l|l|l|l|l|l|]\n\\NC $\\ne$   \\NC \\type{\\ne}\n\\NC $\\{$    \\NC {\\tttf\\leftargument}\n\\NC $\\land$ \\NC \\type{\\land}\n\\NC $\\to$   \\NC \\type{\\to}\n\\NC $\\vert$ \\NC \\type{\\vert}\n\\NC\\NR\n\\NC $\\le$   \\NC \\type{\\le}\n\\NC $\\}$    \\NC {\\tttf\\rightargument}\n\\NC $\\lor$  \\NC \\type{\\lor}\n\\NC $\\gets$ \\NC \\type{\\gets}\n\\NC $\\Vert$ \\NC \\type{\\Vert}\n\\NC\\NR\n\\NC $\\ge$   \\NC \\type{\\ge}\n\\NC $\\owns$ \\NC \\type{\\owns}\n\\NC $\\lnot$ \\NC \\type{\\lnot}\n\\NC \\NC\n\\NC \\NC\n\\NC\\NR\n\\stoptabulate\n\n\\stopcomponent\n", "meta": {"hexsha": "b1477a5407e8ce2dc640bbda6e4958d8c5e8d763", "size": 9769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "contextman/context-beginners/en/ma-cb-en-mathcharacters.tex", "max_stars_repo_name": "marcpaterno/texmf", "max_stars_repo_head_hexsha": "aa7ad70e0102492ff89b7967b16b499cbd6c7f19", "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": "contextman/context-beginners/en/ma-cb-en-mathcharacters.tex", "max_issues_repo_name": "marcpaterno/texmf", "max_issues_repo_head_hexsha": "aa7ad70e0102492ff89b7967b16b499cbd6c7f19", "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": "contextman/context-beginners/en/ma-cb-en-mathcharacters.tex", "max_forks_repo_name": "marcpaterno/texmf", "max_forks_repo_head_hexsha": "aa7ad70e0102492ff89b7967b16b499cbd6c7f19", "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.5129032258, "max_line_length": 60, "alphanum_fraction": 0.5195004606, "num_tokens": 3790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6266715816547157}}
{"text": "Common Lagrangian in introductory courses of classical mechanics depends of $q$\nand $\\dot{q}$. We refer to them as \\emph{first-order Lagrangian} because the\nhighest derivative term is $\\dot{q}$, i.e.\\ the first derivative of $q(t)$ with\nrespect to time. If in the Lagrangian appears also $\\ddot{q}$ it will be a\n\\emph{second-order Lagrangian} and so on. \\\\\n\nIn the following, the mathematical machinery develop in Section~\\ref{section:\nlagrangin and hamiltonian formalism}, will be used to study two apparently\nsimilar Lagrangian and introduce the core problem of HD systems.\n\n\\subsection{First-order vs Second-order Lagrangian}\nThe simplest non-trivial Lagrangians are those in polynomial form like\n\\begin{equation*}\n  L_1(q, \\dot{q}) = \\frac{\\dot{q}^2}{2} - \\alpha(q) \\qquad\n  L_2(q, \\ddot{q}) = \\frac{\\ddot{q}^2}{2} - \\alpha(q)\n\\end{equation*}\nwhere $\\alpha$ is a smooth function of $q$ only~\\cite{Chen13}. No Greek indices\nappear on $q^{(i)}$ because we limit ourself to one-dimensional systems. $L_1$\nis a first-order Lagrangian while $L_2$ it's a second-order one.\n\n\\paragraph{First-order Lagrangian} In order to get the equation of motion we\nused the Euler-Lagrange equation~\\eqref{eq:euler-lagrange}\n\n\\begin{equation} \\label{eq: first-order_motion_eq_lagr}\n  \\frac{\\partial L_1}{\\partial q} -\n  \\frac{d}{dt}\\frac{\\partial L_1}{\\partial \\dot{q}} +\n  \\underbrace{\n  \\frac{d^2}{dt^2}\\frac{\\partial L_1}{\\partial \\ddot{q}} - \\ldots }_0 = 0\n  \\qquad \\Rightarrow \\qquad\n  \\ddot{q} = - \\frac{d\\alpha(q)}{dq}\n\\end{equation}\n\nIf $q$ is the position coordinate of a unit mass point, the function $\\alpha(q)$\ncan be interpreted as the potential energy and~\\eqref{eq:\nfirst-order_motion_eq_lagr} is nothing less than Newton's second law. To get the\nHamiltonian description apply the recipe in Section~\\ref{subsection:\nhamiltonian_formalism}\n\n\\begin{equation*}\n  \\begin{cases}\n    Q_1 := q \\\\\n    P_1 := \\frac{\\delta L_1}{\\delta \\dot{q}} = \\dot{q}\n  \\end{cases}\n  \\qquad\n  \\tilde{H}_1(q, \\dot{q}) :=\n  \\frac{\\delta L_1}{\\delta \\dot{q}} \\dot{q} - L_1(q, \\dot{q})\n\\end{equation*}\n\n\\begin{equation} \\label{eq: first-order_motion_eq_ham}\n  H_1(Q_1, P_1) = \\frac{P_1^2}{2} + \\alpha(Q_1) \\qquad\n  \\begin{cases}\n    \\dot{Q_1} =   \\frac{\\partial H_1}{\\partial P_1} = P_1 \\\\\n    \\dot{P_1} = - \\frac{\\partial H_1}{\\partial Q_1} = - \\frac{d\\alpha(Q_1)}{dQ_1}\n  \\end{cases}\n\\end{equation}\n\nSince $L_1$ does not explicitly depend on time (only through $q$ and $\\dot{q}$),\nthe Hamiltonian $H_1$ can be interpreted as the total energy of the system (sum\nof kinetic and potential energy). Combining the two equation in~\\eqref{eq:\nfirst-order_motion_eq_ham} we restore~\\eqref{eq: first-order_motion_eq_lagr}\nproving the equivalence between Lagrangian and Hamiltonian mechanics for simple\nsystems describe by $L_1$.\n\n\n\\paragraph{Second-order Lagrangian} Proceeding as before, equation of motion\nfollow from Euler-Lagrange equation~\\eqref{eq:euler-lagrange}\n\n\\begin{equation} \\label{eq: second-order_motion_eq_lagr}\n  \\frac{\\partial L_2}{\\partial q} -\n  \\frac{d}{dt}\\frac{\\partial L_2}{\\partial \\dot{q}} +\n  \\frac{d^2}{dt^2}\\frac{\\partial L_2}{\\partial \\ddot{q}} -\n  \\underbrace{\n    \\frac{d^3}{dt^3}\\frac{\\partial L_2}{\\partial q^{(3)}} + \\ldots\n  }_0 = 0\n  \\quad \\Rightarrow \\quad\n  q^{(4)} = - \\frac{d\\alpha(q)}{dq}\n\\end{equation}\n\nEquation~\\eqref{eq: second-order_motion_eq_lagr} never appear in classical\nmechanics, but can it describe some kind of system? The study of the Hamiltonian\ncan give us some clues about the total energy of the system.\n\n\\begin{equation*}\n  \\begin{cases}\n    Q_1 := q \\\\\n    P_1 := \\frac{\\delta L_2}{\\delta \\dot{q}}\n         = \\frac{\\partial L_2}{\\partial \\dot{q}} -\n           \\frac{d}{dt} \\left( \\frac{\\partial L_2}{\\partial \\ddot{q}} \\right)\n         = 0 - \\frac{d}{dt} \\left( \\ddot{q} \\right) = -q^{(3)}\n  \\end{cases}\n  \\begin{cases}\n    Q_2 := \\dot{q} \\\\\n    P_2 := \\frac{\\delta L_2}{\\delta \\ddot{q}}\n         = \\frac{\\partial L_2}{\\partial \\ddot{q}} = \\ddot{q}\n  \\end{cases}\n\\end{equation*}\n\nTherefore\n\\begin{equation}\\label{eq:canonical_coordinates_second_order_lagrangian}\n  \\begin{cases}\n    q        = Q_1 \\\\\n    \\dot{q}  = Q_2 \\\\\n    \\ddot{q} = P_2\n  \\end{cases}\n  \\qquad\n  \\begin{cases}\n    \\frac{\\delta L_2}{\\delta \\dot{q}}  = P_1 \\\\\n    \\frac{\\delta L_2}{\\delta \\ddot{q}} = P_2\n  \\end{cases}\n\\end{equation}\n\n\\begin{equation*}\n  \\tilde{H}_2(q, \\dot{q}) :=\n    \\frac{\\delta L_2}{\\delta \\dot{q}} \\dot{q} +\n    \\frac{\\delta L_2}{\\delta \\ddot{q}} \\ddot{q} -\n    L_2(q, \\ddot{q})\n    = \\frac{\\delta L_2}{\\delta \\dot{q}} \\dot{q} +\n    \\frac{\\delta L_2}{\\delta \\ddot{q}} \\ddot{q} -\n    \\frac{\\ddot{q}^2}{2} + \\alpha(q)\n\\end{equation*}\n\nSubstituting relations~\\eqref{eq:canonical_coordinates_second_order_lagrangian}\nin the expression for $\\tilde{H}_2$ we get the Hamiltonian\n\n\\begin{align} \\label{eq: second-order_motion_eq_ham}\n  H_2(Q_1, Q_2, P_1, P_2)\n    &= P_1 Q_2 + P_2 P_2 - \\frac{P_2^2}{2} + \\alpha(Q_1) \\notag \\\\\n    &= P_1 Q_2 + \\frac{P_2^2}{2} + \\alpha(Q_1)\n\\end{align}\n\nThere is a significant difference between the two spectra of $H_1$ and $H_2$:\nthe first is bounded from below while the latter is not (and both are not\nbounded from above).\n\n\n\\subsection{Linear Ostrogradskian instability}~\\label{subsection:\nlinear_ostrogradskian_instability}\nConsider an \\emph{isolated} system describe by the Hamiltonian $H_2$; if the\nenergy is conserve even though the spectra is not bounded the energy stay\nconstant. Things start to going wrong when ones consider \\emph{interacting}\nsystem (e.g. $H_1$-system interacting with $H_2$-system). The phase space of\n$H_2$-system infinitely extend where the Hamiltonian is negative. In the example\nthis is due to the \\emph{linear} term $P_1$. When two systems interact the\n$H_1$-system tends to occupy higher and higher energies states while the\n$H_2$-system fall lower and lower in negative energies; this behavior entails\nthe conservation of energy~\\cite{Kallosh08, Eliezer89}.\nThis is the so called \\emph{linear Ostrogradskian instability}. \\\\\n\nOne can encounter the same kind of instability in quantum mechanics when try to\ncanonically quantized higher order Hamiltonian (e.g. $H_2$). This process lead\nto \\emph{negative norm states} (or \\emph{negative energy states}) which are\noften called \\emph{``ghosts''}. Systems (even classical ones) involving this\ntype of ghosts are called \\emph{ghost-like} or \\emph{ghost-ridden} systems. \\\\\n\nOne may wonder when these ghosts are summoned; the answer is contains in the\nOstrogradsky theorem\n\n\\begin{theorem}[Ostrogradsky]\\label{th:ostrogradsky_classical}\n  If in the Lagrangian~\\eqref{eq:general_lagrangian} $n \\geq 2$ and the\n  canonical momentum $\\bm{P}_n$ does not vanish, the\n  Hamiltonian~\\eqref{eq:general_hamiltonian} may acquire an arbitrary real\n  value.\n\\end{theorem}\n\\begin{proof}\n  The proof is given for a one-dimensional system (i.e. $\\mu=1$) but it is\n  generalize straight to higher dimensions. Consider the\n  Hamiltonian~\\eqref{eq:general_hamiltonian} in terms of conjugate coordinates\n  \\begin{equation} \\label{eq:general_hamiltonian_1dim}\n    H = P_n h + P_{n-1} Q_n + \\cdots + P_1 Q_2 - L(Q_1, Q_2, \\ldots, h)\n  \\end{equation}\n  The function $h$ express $q^{(n)}$ in terms of conjugate coordinates under\n  the assumption of regular Lagrangian, i.e.\n  \\begin{equation*}\n    q^{(n)} = h(Q_1, \\ldots, Q_n, P_n)\n  \\end{equation*}\n  Observe that $h$ does not depend on $P_1, \\ldots, P_{n-1}$ so the only\n  contribution of these momenta to the Hamiltonian is in the linear factor\n  \\begin{equation*}\n    P_{n-1} Q_n + \\cdots + P_1 Q_2\n  \\end{equation*}\n  which is linear in momenta and hence can acquire any real value and so does\n  the Hamiltonian~\\eqref{eq:general_hamiltonian_1dim}.\n\\end{proof}\n\nFor many years, due to consequences of Theorem~\\ref{th:ostrogradsky_classical},\nHD theories are consider intrinsically sick and not worthy of further study.\nHowever a deeper investigation reveals that Ostrogradsky instability can be cure\nand HD theories should not be discard in the first instance. One way to\nexorcising Ostrogradsky's ghost is through imposition of\nconstraints~\\cite{Chen13}.\n\n\n\\subsection{Removing Ostrogradskian instability with constraints}\n\nIn Hamiltonian mechanics, \\emph{constraints} are relation between coordinates\nand conjugate momenta. Constraints are classify in two group: \\emph{first class\nconstraints} and \\emph{second class constraints}. Second class constraints can\nbe thought as ``physical'' (e.g.\\ train on a railway, particle on a plane) so\nthat the solutions of equations of motion are different with or without them.\nFirst-class are instead related to a gauge freedom: the solutions of equations\nof motion differ by a function of time and hence represent the same system.\nMoreover the Poisson Bracket of a first class constraint with all the other\nconstraints vanishes on the constraints surface in the phase space (i.e.\n$\\{\\phi, \\tilde{\\phi}\\} \\approx 0$, see later for the notation used).\n\n\nAnother independent classification can be made for constraints (and not confused\nwith the previous one): \\emph{primary constraints} and \\emph{secondary\nconstrains}. Primary constraints are relation between $Q$s and $P$s which are\ngiven at the beginning.\n\n\\begin{equation} \\label{eq:constraint}\n  \\phi_1(Q, P) = 0\n\\end{equation}\n\nAs the name suggests, secondary constraints are derived from the primary ones\nimposing the conservations of the constraints during the evolution of the\nsystem. This generates a series of constraints where the constraints relations\nare called \\emph{consistency relations}.\n\n\\begin{equation} \\label{eq:consistency_relations}\n  \\phi_1 \\approx 0 \\quad \\Rightarrow \\quad\n  \\left\\{ \\phi_1 , H \\right\\} =: \\phi_2 \\approx 0 \\quad \\Rightarrow \\quad\n  \\left\\{ \\phi_2 , H \\right\\} =: \\phi_3 \\approx 0 \\quad \\Rightarrow \\quad\n  \\ldots\n\\end{equation}\n\nThe weak equality symbol ``$\\approx$'' has been used to highlight the fact that\nthese relations vanish only on the hypersurface where all constraints are\nsatisfied. When we will be said that a constrain $\\phi_i$ \\emph{vanishes} it is\nto be intended in this weak sense.\n\n\\subsubsection{Lagrangian and Hamiltonian with $m$ auxiliary variables}\nConstraints in Hamiltonian mechanics can be imposed with the help of auxiliary\nvariables $\\lambda_i$ in the Lagrangian:\n\n\\begin{equation*}\n  L = L(\n  q, \\dot{q}, \\ddot{q}, \\ldots, q^{(n)},\n  \\lambda_1, \\lambda_2, \\ldots, \\lambda_m\n  )\n\\end{equation*}\n\nSo the Lagrangian, besides the equations of motion~\\eqref{eq:euler-lagrange},\nneed to satisfy the constraints equation\n\\begin{equation}\n  \\frac{\\partial L}{\\partial \\lambda_i} = 0 \\qquad i=1, 2, \\ldots, m\n\\end{equation}\n\nCanonical coordinates have to be given also for $\\lambda_i$ and the following\nchoice can be done\n\\begin{equation} \\label{eq:def_canonical_coordinates_lambda}\n  \\Lambda_{i}:= \\lambda_{i}\n  \\quad \\leftrightarrow \\quad\n  \\Pi_{i} := \\frac{\\delta L}{\\delta \\dot{\\lambda_{i}}} = 0\n  \\qquad i = 1, 2, \\ldots, m\n\\end{equation}\nso the primary constraints in~\\eqref{eq:constraint} simply become\n$\\phi_{1, i}: \\Pi_i = 0$. To the Hamiltonian~\\eqref{eq:Ham_in_q} are now added\nthe auxiliary variables terms and it becomes\n\\begin{equation} \\label{eq:Ham_constraints_in_q}\n  \\tilde{H} :=\n  \\sum_{j=1}^{n} \\frac{\\delta L}{\\delta q^{(j)}} q^{(j)} +\n  \\sum_{i=1}^{m} \\frac{\\delta L}{\\delta \\dot{\\lambda_i}} \\dot{\\lambda_i} -\n  L(q, \\ldots, q^{(n)}, \\lambda_1, \\ldots, \\lambda_m)\n\\end{equation}\n\nThe $\\dot{\\lambda_i}$ can be obtain by the consistency\nrelations~\\eqref{eq:consistency_relations} but there is no need to explicitly\ncalculate them. $\\dot{\\lambda_i}$ can be written as functions of canonical\ncoordinates: $\\dot{\\lambda_i} = u_i(Q_1, \\ldots, Q_n,  P_1, \\ldots, P_n)$.\nExpressing~\\eqref{eq:Ham_constraints_in_q} using canonical\ncoordinates we obtain the Hamiltonian\n\\begin{align} \\label{eq:Ham_constraints}\n  H =\\ & P_n h + P_{n-1} Q_n + \\cdots + P_1 Q_2 \\nonumber \\\\\n       & + \\phi_m u_m + \\phi_{m-1} u_{m-1} + \\cdots + \\phi_1 u_1 \\nonumber \\\\\n       & - L ( Q_1, Q_2, \\ldots, h, \\Lambda_1, \\ldots, \\Lambda_m)\n\\end{align}\n\n\nAfter calculating the secondary constraints\nwith~\\eqref{eq:consistency_relations}\n\n\\begin{equation*}\n  \\phi_{2, i} := \\left\\{ \\phi_{1,i}, H \\right\\} =\n  \\frac{\\partial \\phi_{1,i}}{\\partial \\Pi_i}\n  \\frac{\\partial H}{\\partial \\Lambda_i} =\n  \\frac{\\partial L}{\\partial \\lambda_i} \\Big|_{\\lambda_i = \\Lambda_i}\n  \\approx 0\n\\end{equation*}\ntwo cases are possible:\n\n\\begin{enumerate}\n  \\item $\\{\\phi_{1,i}, \\phi_{2,j}\\} \\not\\approx 0$: $\\phi_{1,i}$, $\\phi_{2,j}$ are\n    both second-class constraints thus there are no further constraints\n    derivable from consistency relations.\n  \\item $\\{\\phi_{1,i}, \\phi_{2,j}\\} \\approx 0$: $\\phi_{1,i}$, $\\phi_{2,j}$ are\n    not second-class constraints then further constraints can be found employing\n    the chain~\\eqref{eq:consistency_relations} until either \\emph{case 1} is\n    reached or the new constraint can be expressed using those found previously.\n\\end{enumerate}\n\nAfter all constraints have been found and the gauge symmetries are fixed, one\ncan use these equations to write the auxiliary canonical variables in terms of\nthe ``usual'' canonical variables\n\\begin{equation} \\label{eq:constraints_in_terms_of_canonical_vars}\n  \\begin{cases}\n    \\Lambda_i =\\ f_i(Q_1, \\ldots, Q_n, P_n) \\\\\n    \\Pi_i =\\ 0\n  \\end{cases}\n  \\qquad i = 1, 2, \\ldots, m \\\\\n\\end{equation}\nand then substitute in the Hamiltonian~\\eqref{eq:Ham_constraints}\n\\begin{equation*}\n  H =\\ P_n h + P_{n-1} Q_n + \\cdots + P_1 Q_2\n     - L ( Q_1, Q_2, \\ldots, h, f_1, \\ldots, f_m)\n\\end{equation*}\n\nTo recap, we started form a phase space of dimension $2n$ (n$Q$ + n$P$), then we\nenlarged it by adding $2m$ auxiliary variables (m$\\Lambda$ + m$\\Pi$) so the\ntotal phase space dimension is $2(n+m)$. Then we associated with every pair of\ncanonical auxiliary variables two constraints (\\emph{case 1}) or more\n(\\emph{case 2}) have been found. During the last substitution the dimension of\nphase space is bring down to it's original dimensions (\\emph{case 1}: $2(n+m) -\n2m = 2n$) or further reduced (\\emph{case 2}: e.g. $2(n+m) - 3m < 2n$).\n\n\\subsubsection{Example of non-stable system with constraints}\nWe introduce here a widely studied HD Lagrangian: the\n\\emph{Pais-Uhlenbeck oscillator} (PU).\n\\begin{equation} \\label{eq:lagrangian_PU}\n  L_{PU} = \\frac{1}{2} \\left[\n    \\ddot{q}^2 - (\\omega_1^2 + \\omega_2^2) \\dot{q}^2 + \\omega_1^2 \\omega_2^2 q^2\n  \\right]\n\\end{equation}\n\nAccording to Ostrogradsky Theorem~\\ref{th:ostrogradsky_classical} this system\nshows a problematic instability. Then we can try to cure that by introducing a\nconstraint such as $\\ddot{q}^2 - \\dot{q}^2 = 0$ and see if the Hamiltonian is\nstill two-side unbounded. Using the auxiliary variable $\\lambda$ one can write\nthe constraint version of~\\eqref{eq:lagrangian_PU}:\n\\begin{equation} \\label{eq:lagrangian_PUC}\n  L_{PUC} = L_{PU} + \\frac{\\lambda}{2} \\left(\\ddot{q}^2 - \\dot{q}^2\\right)\n\\end{equation}\nand from it we derive the Hamiltonian following the given prescription.\n\\begin{align*}\n  & \\begin{cases}\n    Q_1 := q \\\\\n    P_1 := \\frac{\\delta L_{PUC}}{\\delta \\dot{q}} =\n        - (\\lambda + 1) q^{(3)} - \\dot{\\lambda}\\ddot{q}\n        - (\\lambda + \\omega_1^2 + \\omega_2^2)\\dot{q}\n  \\end{cases} \\\\\n  & \\begin{cases}\n    Q_2 := \\dot{q} \\\\\n    P_2 := \\frac{\\delta L_{PUC}}{\\delta \\ddot{q}} =\n        (\\lambda + 1) \\ddot{q}\n        \\quad  \\Rightarrow \\quad \\ddot{q} = \\frac{P_2}{(\\Lambda + 1)}\n  \\end{cases} \\\\\n  & \\begin{cases}\n    \\Lambda := \\lambda \\\\\n    \\Pi := \\frac{\\delta L_{PUC}}{\\delta \\lambda} = 0\n        \\quad  \\Rightarrow \\quad \\phi_1: \\Pi \\approx 0\n  \\end{cases}\n\\end{align*}\n\\begin{equation} \\label{eq:ham_PUC_with_aux_vars}\n   H_{PUC} =\\ P_1 Q_2 + \\frac{P_2^2}{2(\\Lambda + 1)} + \\phi_1 u_1\n  + \\frac{Q_2^2}{2} \\left(\\Lambda + \\omega_1^2 + \\omega_2^2 \\right)\n  - \\frac{Q_1^2}{2} \\omega_1^2 \\omega_2^2\n\\end{equation}\n\n\\begin{equation} \\label{eq:secondary_constraint_PU}\n  \\phi_2 :=\n  \\left\\{ \\phi_1, H_{PUC} \\right\\} =\n  \\frac{1}{2} \\left[ \\frac{P_2}{\\Lambda + 1} - Q_2 \\right]\n  \\left[ \\frac{P_2}{\\Lambda + 1} + Q_2 \\right]\n  \\approx 0\n\\end{equation}\n\nThe secondary constraint equation~\\eqref{eq:secondary_constraint_PU}\nvanish if one of the factors in square brackets vanish. The two square bracket\nrepresent two hypersurfaces and one solution is chosen instead of the other\nbased on initial conditions. In the following, we choose the bracket with the\nminus sign. Moreover note that $\\phi_1$ and $\\phi_2$ are already second-class\nconstraints, indeed\n\\begin{equation*}\n  \\begin{cases}\n    \\phi_1: \\Pi = 0 \\\\\n    \\phi_2: \\frac{P_2}{\\Lambda + 1} - Q_2 \\approx 0\n  \\end{cases}\n  \\quad \\Rightarrow \\quad\n  \\left\\{ \\phi_1, \\phi_2 \\right\\} = -\n  \\frac{\\partial\\phi_1}{\\partial\\Pi} \\frac{\\partial\\phi_2}{\\partial\\Lambda} =\n  \\frac{P_2}{{(\\Lambda + 1)}^2} \\not\\approx 0\n\\end{equation*}\nso no further constraints are needed (\\emph{case 1}). The equation for\n$\\phi_1$ (trivial) and for $\\phi_2$ can be locally\ninverted~\\eqref{eq:constraints_in_terms_of_canonical_vars} obtaining that\n$\\Pi = 0$ and $\\Lambda = P_2/Q_2 - 1$. Substituting them\nin~\\eqref{eq:ham_PUC_with_aux_vars} we get the final Hamiltonian of the system\nbut unfortunately the Ostrogradsky instability persists.\n\\begin{equation} \\label{eq:ham_PUC_instable}\n   H_{PUC} =\\ P_1 Q_2 + P_2 Q_2\n  + \\frac{Q_2^2}{2} \\left(\\omega_1^2 + \\omega_2^2 - 1 \\right)\n  - \\frac{Q_1^2}{2} \\omega_1^2 \\omega_2^2\n\\end{equation}\n\n\n\\subsubsection{Example of stable system with constraints}\nNow consider the following constrained Pais-Uhlenbeck oscillator~\\cite{Chen13}\n\\begin{equation}\n  L_{PUC} = L_{PU} +\n  4 \\omega_1^2\\omega_2^2 q^2 \\lambda (1+ \\lambda) +\n  2 \\sqrt{2} \\omega_1\\omega_2 \\lambda q \\ddot{q}\n\\end{equation}\n\nAnalogously to the previous example, canonical variable and hamiltonian\n$H_{PUC}$ can be derived in similar fashion\n\\begin{align*}\n  & \\begin{cases}\n    Q_1 := q \\\\\n    P_1 := - q^{(3)} -\n    \\left( 2\\sqrt{2} \\omega_1\\omega_2\\lambda + \\omega_1^2 + \\omega_1^2 \\right)\n    \\dot{q} - 2\\sqrt{2}\\omega_1\\omega_2\\dot{\\lambda} q\n  \\end{cases} \\\\\n  & \\begin{cases}\n    Q_2 := \\dot{q} \\\\\n    P_2 := \\ddot{q} + 2\\sqrt{2} \\omega_1\\omega_2\\lambda q\n    \\quad \\Rightarrow \\quad\n    \\ddot{q} = P_2 - 2\\sqrt{2} \\omega_1\\omega_2\\Lambda Q_1\n  \\end{cases} \\\\\n  & \\begin{cases}\n    \\Lambda := \\lambda \\\\\n    \\Pi := 0\n    \\quad  \\Rightarrow \\quad \\phi_1: \\Pi \\approx 0\n  \\end{cases}\n\\end{align*}\n\\begin{align} \\label{eq:ham_PUC_with_aux_vars_stable}\n  H_{PUC} =\\ & P_1 Q_2 + \\frac{P_2^2}{2} -\n  \\omega_1^2\\omega_2^2\\frac{Q_1^2}{2} +\n  \\left( \\omega_1^2 + \\omega_2^2 \\right) \\frac{Q_2^2}{2} \\\\\n  & - 4 \\omega_1^2\\omega_2^2\\Lambda Q_1^2 -\n  2\\sqrt{2}\\omega_1\\omega_2\\Lambda P_2 Q_1 + \\phi_1 u_1\n\\end{align}\n\nSecondary constraints relations carry useful information up to the forth order\n\\footnote{\n  To obtain $\\phi_4$, information from $\\phi_1$ and $\\phi_2$ have been used in\n  order to write $\\phi_4$ in terms of $\\Lambda$.\n}\n\\begin{align*}\n  & \\phi_1 : \\Pi = 0 \\\\\n  & \\phi_2 := \\{\\phi_1, H_{PUC}\\} =\n    P_2 + \\sqrt{2} \\omega_1\\omega_2 Q_1 \\approx 0 \\\\\n  & \\phi_3 := \\{\\phi_2, H_{PUC}\\} =\n    P_1 + \\left(\\omega_1^2 + \\omega_2^2 - \\sqrt{2}\\omega_1\\omega_2 \\right) Q_2\n    \\approx 0 \\\\\n  & \\phi_4 := \\{\\phi_3, H_{PUC}\\} =\n  \\omega_1 \\omega_2 (3+8\\Lambda) - \\sqrt{2}\n  \\left( \\omega_1^2 + \\omega_2^2 \\right) \\left(1 + 2\\Lambda \\right) \\approx 0\n\\end{align*}\n\nThese consistency relations can be inverted so that $P_2$, $Q_2$ and $\\Lambda$\nare express in terms of $P_1$ and $Q_1$. Substituting them\ninto~\\eqref{eq:ham_PUC_with_aux_vars_stable} obtaining\n\n\\begin{equation} \\label{eq:ham_PUC_stable}\n  H_{PUC} =\\ \\frac{\\omega_1^2\\omega_2^2}{2} Q_1^2 +\n  \\frac{\\omega_1\\omega_2}{\\sqrt{2} {\\left(\\sqrt{2} \\omega_1\\omega_2 -\n  \\omega_1^2 - \\omega_2^2 \\right)}^2} P_1^2\n\\end{equation}\n\nThe Hamiltonian~\\eqref{eq:ham_PUC_stable} is bounded from below (and not from\nabove, just like an harmonic oscillator) and hence this system does not suffer\nof Ostrogradsky instability unlike the previous example. \\\\\n\nThe main difference between the two is the role played by constraints. In the\nfirst example the dimensions of phase space of the unconstrained and constrained\nHamiltonian are both four (i.e.\\ four variable appear in the reduced\nHamiltonian~\\eqref{eq:ham_PUC_instable}: $Q_1$, $P_1$, $Q_2$ and $P_2$). In the\nsecond example the constraints reduce the dimensionality of the phase space from\nthe original four to two (indeed just $Q_1$ and $P_1$ appear\nin~\\eqref{eq:ham_PUC_stable}). As shown in~\\cite{Chen13} a reduction of the\nphase space, due to imposed constraints, can cure the typical Ostrogradsky\ninstability of HD theories.\n", "meta": {"hexsha": "cd2a47c0f9f032a7cb009aa6432efc4e9695a700", "size": 20600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/classical-higher-derivative-systems.tex", "max_stars_repo_name": "S1M0N38/thesis", "max_stars_repo_head_hexsha": "2dee034051a4b5ee017dae80759d849e99edb4e5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "document/classical-higher-derivative-systems.tex", "max_issues_repo_name": "S1M0N38/thesis", "max_issues_repo_head_hexsha": "2dee034051a4b5ee017dae80759d849e99edb4e5", "max_issues_repo_licenses": ["MIT"], "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/classical-higher-derivative-systems.tex", "max_forks_repo_name": "S1M0N38/thesis", "max_forks_repo_head_hexsha": "2dee034051a4b5ee017dae80759d849e99edb4e5", "max_forks_repo_licenses": ["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.5619834711, "max_line_length": 82, "alphanum_fraction": 0.7022330097, "num_tokens": 7085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6266705721793333}}
{"text": "\\gotosection{2}{3}\n\\subsection{Matrix inverses and elementary matrices}\n\n\\begin{exercise}{2}\n\\begin{enumerate}\n\\item $\\xmat{1/6&5/54\\\\-1/6&1/54}$\n\n\\item Inverse doesn't exist, as $[A|I]$ is reduced to $\\xmat{1&3&1&0\\\\0&0&-3&1}$.\n\n\\item $\\xmat{2&-1&-3\\\\-2&2&3\\\\1&-1&-1}$\n\n\\item Inverse doesn't exist, as this is not a square matrix.\n\n\\item $\\xmat{1/7 & -1/2 & 1/14 \\\\ 4/21 & 5/6 & -1/14 \\\\ -4/21 & 1/6 & 1/14}$\n\n\\item $\\xmat{0&1&-1 \\\\ 1&-2& 1&-1&1}$\n\n\\item $\\xmat{4 & -6 & 4 & 1 \\\\ -6 & 14 & -11 & 3 \\\\ 4 & -11 & 10 & -3 \\\\ -1 & 3 & -3 & 1}$\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{3}\n\\begin{enumerate}\n\\item Suppose an matrix $A \\in M_{m,n}(\\mathbb{R})$. If $A$ has an inverse matrix, then $T_A$ must be bijective, or for any $\\Vect{b} \\in \\mathbb{R}^n$, $A\\Vect{x}=\\Vect{b}$ has a unique solution. If $m < n$, then $\\widetilde{A}$ has at least one column without a pivotal 1, so there exist infinitely many solutions, namely $T_A$ is not injective. If $m > n$, there must exist a row-reduced vector $\\widetilde{\\mathbf{b}}$ that contains a pivotal 1---since row operations are invertible, we can always find a $\\Vect{b}$ for any given $\\widetilde{\\mathbf{b}}$---there exists no solution, namely $T_A$ is not surjective. Only when $m = n$ could $A$ be reduced to an identity matrix and therefore has a unique solution for every possible $\\widetilde{\\mathbf{b}}$. Hence only squre matrices have inverses. \\rQED\n\n\\item $A = \\xmat{1&0&0\\\\0&1&0}, B = \\xmat{1&0\\\\0&1\\\\0&0}$.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\nLabel them as $A, B, C$. $A+C$ and $B+2C$ gives $4x+4z=2, 4x+3y=3$, therefore, $x = (1-2z)/2$. Substituting $x$ with $z$ gives $y = (1+4z)/3$. Substituting $x$ and $y$ with $z$ into $A$ gives $z = 1/8$, then $x = 3/8$, $y = 1/2$.\n\n\\begin{enumerate}\n\\item Echelon form of this linear system is\n$\\xmat{1 & 0 & 0 & 3/8\\\\\n       0 & 1 & 0 & 1/2\\\\\n       0 & 0 & 1 & 1/8}$. Therefore, $x = 3/8$, $y = 1/2$, $z=1/8$.\n\n\\item $A^{-1} = \\xmat{3/16 & 1/4 & -1/16\\\\\n                      -1/4 & 0   & 3/4  \\\\\n                      1/16 & -1/4 & 5/16}$. $A^{-1}\\xmat{1\\\\1\\\\1} = \\xmat{3/8\\\\1/2\\\\1/8}$.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{8}\n\\begin{enumerate}\n\\item \\begin{enumerate}\n        \\item Multiply the second row by 3.\n        \\item Exchange the second and the third row.\n        \\item Add a multiple 2 of the first row to the third row.\n      \\end{enumerate}\n\n\\item \\begin{enumerate}\n        \\item $\\xmat{1&0&-1\\\\6&3&3\\\\0&1&2}$.\n        \\item $\\xmat{1&0&-1\\\\0&1&2\\\\2&1&1}$.\n        \\item $\\xmat{1&0&-1\\\\2&1&1\\\\2&1&0}$.\n      \\end{enumerate}\n\n\\item \\begin{enumerate}\n        \\item Multiply the second column by 3.\n        \\item Exchange the second and the third column.\n        \\item Add a multiple 2 of the first column to the third column.\n      \\end{enumerate}\n\n\\item \\begin{enumerate}\n        \\item $\\xmat{1&0&-1\\\\2&3&1\\\\0&3&2}$.\n        \\item $\\xmat{1&-1&0\\\\2&1&1\\\\0&2&1}$.\n        \\item $\\xmat{1&0&1\\\\2&1&5\\\\0&1&2}$.\n      \\end{enumerate}\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{11}\nColumn operations applied to a matrix $A$ can be seen as the transpose of the matrix generated by applying the row operations with the same parameters to $A^{\\top}$. Here ``the same parameters\" means the same index of row/column to multiply, the same multiplication constant, the same indexes of the two row/columns to exchange, or the same multiple of the same index of row/column to be added to another same index of row/column.\n\nGiven any elementary matrix $E$, $AE^{\\top} = (EA^{\\top})^{\\top}$. Since $E^{\\top}$ is also an elementary matrix, column operations can be achieved by multiplication on the right by elementary matrices. Note that if $E$ is of type 1 or 3, its transpose is the same as itself; but if $E = E_2(i,j,x)$ for some $i, j, x$, its transpose will be $E_2(j,i,x)$, which means that $AE_2(i,j,x)$ will add the multiple $x$ of the $i$th column of $A$ to its $j$th column, rather than adding that multiple of the $j$th column of $A$ to its $i$th column. \\rQED\n\\end{exercise}\n\n\\begin{exercise}{12}\n\\begin{enumerate}\n\\item Show $E_1(i,x)E_1(i,1/x) = E_1(i,1/x)E_1(i,x) = I$.\n\n\\Proof\\ For $E_1(i,x)E_1(i,1/x)$, the $i$th-row of $E_1(i,1/x)$ will be multiplied by $x$, then its $i,i$ entry will become $x \\cdot (1/x) = 1$, therefore the result is an identity matrix. For $E_1(i,1/x)E_1(i,x)$, the $i$th-row of $E_1(i,x)$ will be multiplied by $1/x$, then its $i,i$ entry will become $(1/x) \\cdot x = 1$, therefore the result is an identity matrix. This shows that $E_1(i,1/x)$ is the inverse matrix of $E_1(i,x)$, and that $E_1(i,x)$ is invertible. \\rQED\n\n\\item Show $E_2(i,j,x)E_2(i,j,-x) = E_2(i,j,-x)E_2(i,j,x) = I$.\n\n\\Proof\\ Consider $E_2(i,j,-x)E_2(i,j,x)I$, which can be seen as applying two row operations to the identity matrix. Let $r_k$ be the $k$-th row of $I$. After the first operation $E_2(i,j,x)$, the $i$th row becomes $xr_j + r_i$; after the second operation $E_2(i,j,-x)$, the $i$th row of the identity matrix becomes $xr_j + r_i - xr_j = r_i$. Since all other rows of the identity matrix keeps invariant during this two operations, after the two operations the identity itself keeps invariant, namely $E_2(i,j,-x)E_2(i,j,x)I = I$, or $E_2(i,j,-x)E_2(i,j,x)=I$. From what we just proved we can get $E_2(i,j,x)E_2(i,j,-x) = I$ by seeing $-x$ as $y$ and $x$ as $-y$. Then, $E_2(i,j,-x)$ is both the left and right inverse matrix of $E_2(i,j,x)$, namely $E_2(i,j,-x)$ is the inverse of $E_2(i,j,x)$ and the later is invertible. \\rQED\n\n\\item Show $E3(i,j)E3(i,j) = I$.\n\n\\Proof\\ Since $E3(i,j)I = E3(i,j)$, $E3(i,j)$ is just the identity matrix with its $i,j$ rows exchanged. $E3(i,j)E3(i,j)$ exchanges these two rows back, so the product matrix is just the identity matrix. This shows that $E3(i,j)E3(i,j) = I$ and that $E3(i,j)$ is the inverse of itself. \\rQED\n\\end{enumerate}\n\\end{exercise}", "meta": {"hexsha": "00e5994e12c4d2d27a0698652b74a3ecb5edf1ff", "size": 5859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW4/sec0203.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": "HW4/sec0203.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": "HW4/sec0203.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": 63.0, "max_line_length": 827, "alphanum_fraction": 0.6338965694, "num_tokens": 2198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.6266705705850665}}
{"text": "\\documentclass[../main]{subfiles}\n\\pagestyle{fancy}\n\n\\begin{document}\n\n\\chapter{Large Cardinals}\n\\label{apx.large-cardinals}\n\\thispagestyle{fancy}\n\nSince large cardinals came into existence in the beginning of the 20th century, a vast zoo of different types of such have appeared. The aim of this appendix is to act as a reference for the definitions of these as well as the relations between them.\n\n\\section{Inaccessibles}\n\n\\defi{\n  A cardinal $\\kappa$ is \\textbf{regular} if $\\cof\\kappa=\\kappa$; i.e. that there are no $\\gamma<\\kappa$ with a cofinal function $f\\colon\\gamma\\to\\kappa$. $\\kappa$ is a \\textbf{strong limit} if $2^\\lambda<\\kappa$ for all cardinals $\\lambda<\\kappa$. If $\\kappa$ is both regular and a strong limit then we say that it is (strongly) \\textbf{inaccessible}.\n}\n\n\\qprop[\\cite{Kanamori} Proposition 1.2]{\n  If $\\kappa$ is inaccessible then $(V_\\kappa, \\in)\\models\\zfc$.\n}\n\nG\\\"odel's Second Incompleteness Theorem from \\cite{godel-incompleteness} then immediately implies the following corollary.\n\n\\qcoro{\n  \\zfc\\ can not prove the existence of any inaccessible cardinals. Indeed, not even the \\textit{consistency} of the existence of any inaccessible cardinals can be proven in \\zfc.\n}\n\n\\section{Weakly compacts}\n\n\\defi{\n  For any function $f\\colon A\\to B$, a subset $H\\subset A$ is \\textbf{homogeneous for $f$} if $f\\restr H$ is a constant function.\n}\n\n\\defi{\n  Let $\\kappa$ and $\\lambda$ be infinite cardinals, $\\gamma$ an ordinal and $n<\\omega$. Then the partition relation $\\kappa\\to(\\lambda)^n_\\gamma$ holds if to every function $f\\colon[\\kappa]^n\\to\\gamma$ there exists a subset $H\\subset[\\kappa]^n$ of size $\\lambda$ which is homogeneous for $f$. If $\\gamma=2$ then we usually leave it out and simply write $\\kappa\\to(\\lambda)^n$.\n}\n\n\\defi{\n  An uncountable cardinal $\\kappa$ is \\textbf{weakly compact} if $\\kappa\\to(\\kappa)^2$.\n}\n\n\\qtheo[\\cite{Jech} Lemma 9.9]{\n  Every weakly compact cardinal is a limit of inaccessible cardinals.\n}\n\n\\section{Ineffables and completely ineffables}\n\n\\defi{\n  An uncountable cardinal $\\kappa$ is \\textbf{ineffable} if to any function $f\\colon[\\kappa]^2\\to 2$ there exists a \\textit{stationary} $H\\subset[\\kappa]^2$ which is homogeneous for $f$.\n}\n\nIneffable cardinals are weakly compact by definition, and the following theorem from \\cite{Friedman} shows that they are strictly stronger.\n\n\\qtheo[Friedman]{\n  Ineffable cardinals are weakly compact limits of weakly compacts.\n}\n\nA way of improving ineffability is to ``close under homogeneity'', in the sense that if $H$ is homogeneous for $f\\colon[\\kappa]^2\\to 2$ and $g\\colon[H]^2\\to 2$ is any function, then there is a subset of $H$ which is homogeneous for $g$. To formalise this notion we use the concept of a \\textit{stationary class}.\n\n\\xdefi{\n  For $X$ any set, a collection $\\R\\subset\\p(X)$ is a \\textbf{stationary class} if\n  \\begin{itemize}\n    \\item $\\R\\neq\\emptyset$;\n    \\item Every $A\\in\\R$ is a stationary subset of $X$;\n    \\item If $A\\in\\R$ and $B\\supset A$ then $B\\in\\R$.$\\hfill\\circ$\n  \\end{itemize}\n}\n\n\\defi{\n  An uncountable cardinal $\\kappa$ is \\textbf{completely ineffable} if there is a stationary class $\\R\\subset\\p(\\kappa)$ such that for every $A\\in\\R$ and $f\\colon[A]^2\\to 2$ there exists a $H\\in\\R$ which is homogeneous for $f$.\n}\n\nAs suspected, these completely ineffable cardinals are indeed strictly stronger than the ineffables, as the following theorem from \\cite{Abramson} shows.\n\n\\qtheo[Abramson et al]{\n  Completely ineffable cardinals are ineffable limits of ineffable cardinals.\n}\n\n\\section{Measurables, strongs and supercompacts}\n\n\\defi{\n  For two first-order structures $\\M$ and $\\N$ with underlying sets $M$ and $N$, an \\textbf{elementary embedding} $j\\colon\\M\\to\\N$ between them is a function $j\\colon M\\to N$ such that, for any first-order formula $\\varphi(v_1,\\dots,v_n)$ and sets $x_1,\\dots,x_n\\in\\M$ it holds that $\\M\\models\\varphi[x_1,\\dots,x_n]$ iff $\\N\\models\\varphi[j(x_1),\\dots,j(x_n)]$.\n}\n\nAs elementary embeddings in particular preserve equality, they are always injective. Identity embeddings are of course always elementary, so we say that an elementary embedding is \\textbf{non-trivial} if it is not the identity. The following then shows that in most situations these non-trivial embeddings can be associated to a unique ordinal.\n\n\\qprop[\\cite{Kanamori} Propostion 5.1]{\n  If $j\\colon(\\M,\\in)\\to(\\N,\\in)$ is an elementary embedding such that $\\M$ is transitive and \\textit{either} $\\N\\subset\\M$ or $\\M\\models\\zfc$, then there exists an ordinal $\\alpha<o(\\M)$ moved by $j$, i.e. that $j(\\alpha)\\neq\\alpha$. We call the least such ordinal the \\textbf{critical point} of $j$, and denote it by $\\crit j$.\n}\n\n\\defi[\\gbc]{\n  An uncountable cardinal $\\kappa$ is \\textbf{measurable} if there exists a transitive class $\\M$ and an elementary embedding $j\\colon (V,\\in)\\to(\\M,\\in)$ with critical point $\\kappa$.\n}\n\nThe measurable cardinals were the first large cardinals shown to ``transcend $L$''.\n\n\\qtheo[Scott's Theorem, \\cite{Kanamori} Corollary 5.5][theo.scott]{\n  $L$, G\\\"odel's constructible universe, has no measurable cardinals.\n}\n\nGiven this result, it's not surprising that the measurables then exceed the strength of the previous large cardinals.\n\n\\prop{\n  Measurable cardinals are completely ineffable limits of completely ineffable cardinals.\n}\n\\proof{\n  (Sketch) If $j\\colon V\\to\\M$ is a non-trivial elementary embedding then the \\textbf{derived ultrafilter} $\\mu\\subset\\p(\\kappa)$ on $\\kappa:=\\crit j$ is defined as $X\\in\\mu$ iff $\\kappa\\in j(X)$. Section 5 in \\cite{Kanamori} shows that it is indeed an ultrafilter and that its ultrapower $\\ult(V, \\mu)$ is wellfounded. A reflection argument then shows that we can simply take $\\R:=\\mu$.\n}\n\n\\defi[\\gbc]{\n  An uncountable cardinal $\\kappa$ is \\textbf{strong} if there to every cardinal $\\theta>\\kappa$ exists a transitive class $\\M_\\theta$ satisfying that $H_\\theta\\subset\\M_\\theta$, and an elementary $j_\\theta\\colon(V,\\in)\\to(\\M_\\theta,\\in)$ with critical point $\\kappa$. We say that $\\kappa$ is \\textbf{$\\theta$-strong} if the property holds for a specific $\\theta$.\n}\n\n\\qprop[\\cite{Kanamori} 26.6]{\n  Strong cardinals are measurable limits of measurable cardinals.\n}\n\n\\defi[\\gbc]{\n  An uncountable cardinal $\\kappa$ is \\textbf{supercompact} if there to every cardinal $\\theta>\\kappa$ exists a transitive class $\\M_\\theta$ satisfying that $^{<\\theta}\\M_\\theta\\subset\\M_\\theta$, and an elementary $j_\\theta\\colon(V,\\in)\\to(\\M_\\theta,\\in)$ with critical point $\\kappa$.\n}\n\n\\prop{\n  If $\\kappa$ is supercompact then\n  \\eq{\n    V_\\kappa\\models\\godel{\\text{There exists a proper class of strong cardinals}}.\\tag*{$(1)$}\n  }\n}\n\\proof{\n  (Sketch) By noting that the restrictions of the supercompact embedding is an element of the target model by supercompactness, $\\kappa$ is strong in the target model, so that a reflection argument shows $(1)$.\n}\n\n\\section{Woodins and Vop\\v enkas}\n\n\\defi[][defi.A-strong]{\n  Let $A$ be any set. An uncountable cardinal $\\kappa$ is \\textbf{$A$-strong} if there to every cardinal $\\theta>\\kappa$ exists a transitive class $\\M_\\theta$ satisfying that $H_\\theta\\subset\\M_\\theta$, and an elementary $j_\\theta\\colon(V,\\in)\\to(\\M_\\theta,\\in)$ with critical point $\\kappa$, such that $A\\cap H_\\theta = j(A)\\cap H_\\theta$.\n}\n\n\\defi{\n  An uncountable cardinal $\\delta$ is a \\textbf{Woodin cardinal} if there to every subset $A\\subset H_\\delta$ exists $\\kappa<\\delta$ such that $(H_\\delta, \\in, A)\\models\\godel{\\text{$\\kappa$ is $A$-strong}}$.\n}\n\n\\theo[\\cite{Kanamori} Theorem 26.14]{\n  The following are equivalent for an uncountable cardinal $\\kappa$.\n  \\begin{enumerate}\n    \\item $\\kappa$ is a Woodin cardinal;\n    \\item For any $f\\colon\\kappa\\to\\kappa$ there exists $\\alpha<\\kappa$ such that $f[\\alpha]\\subset\\alpha$, a transitive $\\M$ with $V_{j(f)(\\alpha)}\\subset\\M$ and an elementary embedding $j\\colon(V,\\in)\\to(\\M,\\in)$ with $\\crit j=\\kappa$.\n  \\end{enumerate}\n}\n\n\\defi[\\gbc]{\n  \\textbf{Vop\\v enka's Principle (\\vp)} postulates that to any first-order language $\\mathcal L$ and proper class $\\C$ of $\\mathcal L$-structures, there exist distinct $\\M,\\N\\in\\C$ and an elementary embedding $j\\colon\\M\\to\\N$.\n}\n\n\\defi{\n  An uncountable cardinal $\\delta$ is \\textbf{Vop\\v enka} if $(V_\\delta,\\in;V_{\\delta+1})\\models\\vp$.\n}\n\nThe following theorem is from \\cite{Perlmutter}.\n\n\\qtheo[Perlmutter]{\n  Vop\\v enka cardinals are equivalent to cardinals that are ``Woodin for supercompactness'', meaning a cardinal $\\delta$ such that to any subset $A\\subset H_\\delta$ there is a cardinal $\\kappa<\\delta$ such that $(H_\\delta,\\in,A)\\models\\godel{\\text{$\\kappa$ is $A$-supercompact}}$.\\footnote{Here $\\kappa$ is, in analogy with Definition \\ref{defi.A-strong}, \\textbf{$A$-supercompact} if there to every cardinal $\\theta>\\kappa$ exists a transitive class $\\M_\\theta$, closed under ${<}\\theta$-sequences, and an elementary $j_\\theta\\colon(V,\\in)\\to(\\M_\\theta,\\in)$ with critical point $\\kappa$, such that $A\\cap H_\\theta=j(A)\\cap H_\\theta$.}\n}\n\n\\section{Reinhardts and Kunen inconsistency}\n\n\\defi[\\gbc]{\n  An uncountable cardinal $\\kappa$ is a \\textbf{Reinhardt cardinal} if there exists an elementary embedding $j\\colon(V,\\in)\\to (V,\\in)$ with $\\crit j=\\kappa$.\n}\n\n\\theo[Kunen inconsistency, \\gbc, \\cite{Kanamori} Theorem 23.12]{\n  There are no Reinhardt cardinals. Even more, there is no non-trivial elementary $j\\colon(V_{\\lambda+2},\\in)\\to(V_{\\lambda+2}, \\in)$ for any uncountable cardinal $\\lambda$.\n}\n\nWhen we're dealing with the \\textit{virtual} large cardinals in Chapter \\ref{chapter.virtual-large-cardinals} we show that the property $j(\\kappa)>\\theta$ is a highly non-trivial assumption. However, when we're not in the virtual world then this is simply automatic. \n\n\\qprop[\\cite{Kanamori} 26.7]{\n  If $j\\colon V\\to\\M_\\theta$ witnesses that $\\kappa:=\\crit j$ is a $\\theta$-strong cardinal then $j(\\kappa)>\\theta$.\n}\n\nNote that a crucial part of the proof of the above is Corollary 23.14 in \\cite{Kanamori}, which relies \\textit{heavily} on the Kunen inconsistency. There is also the following even stronger version of the Reinhardts.\n\n\\defi{\n  An uncountable cardinal $\\kappa$ is \\textbf{super Reinhardt} if for all ordinals $\\lambda$ there exists an elementary embedding $j\\colon (V,\\in)\\to(V,\\in)$ with $\\crit j=\\kappa$ and $j(\\kappa)>\\lambda$.\n}\n\n\\section{Berkeleys}\n\n\\defi[\\gb]{\n  An uncountable cardinal $\\delta$ is a \\textbf{proto-Berkeley cardinal} if to every transitive \\textit{set} $\\M$ such that $\\delta\\subset\\M$ there exists an elementary embedding $j\\colon(\\M,\\in)\\to(\\M,\\in)$ with $\\crit j<\\delta$.\n}\n\nNote that if $\\kappa$ is a proto-Berkeley cardinal then every $\\lambda>\\kappa$ is also proto-Berkeley, which makes it quite an uninteresting notion. But we can isolate the interesting cases, leading to the definition of a Berkeley cardinal. The following is Theorem 2.1.14 in \\cite{Cutolo}.\n\n\\qtheo[Cutolo]{\n  If $\\delta_0$ is the least proto-Berkeley cardinal then we can choose the critical point of the embedding to be arbitrarily large below $\\delta_0$.\n}\n\nAs this property is clearly not preserved upwards, this makes for a good candidate for the large cardinal notion.\n\n\\defi[\\gb]{\n  A proto-Berkeley cardinal $\\delta$ is \\textbf{Berkeley} if we can choose the critical point of the embedding to be arbitrarily large below $\\delta$. If we furthermore can choose the critical point as an element of any club $C\\subset\\delta$ then we say that $\\delta$ is \\textbf{club Berkeley}.\n}\n\nIn \\cite{Cutolo}, they furthermore mention that, among the above-mentioned cardinals, the non-trivial relative consistency implications currently known are the following, being Theorem 2.2.1 and 2.2.2 in \\cite{Cutolo}, respectively.\n\n\\qtheo[Cutolo]{\n  Berkeley cardinals are consistency-wise strictly stronger than Reinhardt cardinals.\n}\n\n\\qtheo[Cutolo]{\n  Club Berkeley cardinals are consistency-wise strictly stronger than super Reinhardt cardinals.\n}\n\n\\end{document}\n", "meta": {"hexsha": "c0beaff98e2fde0e6bc2582757fec15d94395f29", "size": 11925, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "frontbackmatter/apx-large-cardinals.tex", "max_stars_repo_name": "saattrupdan/phd", "max_stars_repo_head_hexsha": "21481596be517c874e311797f5a70829e0cba7d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontbackmatter/apx-large-cardinals.tex", "max_issues_repo_name": "saattrupdan/phd", "max_issues_repo_head_hexsha": "21481596be517c874e311797f5a70829e0cba7d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontbackmatter/apx-large-cardinals.tex", "max_forks_repo_name": "saattrupdan/phd", "max_forks_repo_head_hexsha": "21481596be517c874e311797f5a70829e0cba7d3", "max_forks_repo_licenses": ["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.4651162791, "max_line_length": 636, "alphanum_fraction": 0.7300628931, "num_tokens": 3604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8333245911726381, "lm_q1q2_score": 0.6266705705850664}}
{"text": "\\section{Bimatrix Games and Labels}\n\\label{labels-sect}\n\nLet $(A,B)$ be bimatrix game, and let $X=\\Delta^1$ and\n$Y=\\Delta^2$ be the mixed strategy\nsimplices of player 1 and 2, respectively, that is,\n\\begin{equation}\n\\arraycolsep.2em\n\\label{mixed-strat-simplices}\n\\begin{array}{rcll}\nX&=&\\{\\, x\\in\\reals^m&\\mid x\\geq\\0,\\ \\1\\T x = 1 \\},\\\\\nY&=&\\{\\, y\\in\\reals^n&\\mid y\\geq\\0,\\ \\1\\T y = 1 \\}.\n\\end{array}\n\\end{equation}\nA {\\em labeling} of the sets $X$ and $Y$ assigns to each\n$x\\in X$ and $y\\in Y$ a set of {\\em labels}, which is a\nsubset of $[m+n]$, as follows:\n\\begin{enumerate}\n\\item the $m$ pure strategies of player 1 are denoted as $i\\in [m]$;\n\\item the $n$ pure strategies of player 2 are denoted as $m+j$ with $j\\in [n]$;\n\\item each mixed strategy $x\\in X$ of player 1 has\n    \\begin{itemize}\n    \\item label $i$ for each $i\\in [m]$ such that $x_i = 0$,\n    \\item label $m + j$ for each $j\\in [n]$ such that the $j$-th pure strategy\n    of player 2 is a best response to $x$;\n    \\end{itemize}\n\\pagebreak[2]\n\\item each mixed strategy $y\\in Y$ of player 2 has\n    \\begin{itemize}\n    \\item label $m + j$ for each $j\\in [n]$ such that $y_j = 0$,\n    \\item label $i$ for each $i\\in [m]$ such that the $i$-th pure strategy\n    of player 1 is a best response to $y$.\n    \\end{itemize}\n\\end{enumerate}\nThis labeling can be used to characterize the Nash equilibria of the game:\nA pair $(x,y)$ is called {\\em completely labeled} if each\npossible label in $[m+n]$ is a label of $x$ or of~$y$.\n\n\\begin{theorem}{\\rm (Shapley \\cite{shapley})}\\label{comp-label-thm}\nLet $(x,y)\\in X\\times Y$. Then $(x,y)$ is a Nash equilibrium of the bimatrix\ngame $(A,B)$ if and only if $(x,y)$ is completely labeled.\n\\end{theorem}\n\n\\begin{proof}\nThe mixed strategy $x\\in X$ has label $m + j$ for some $j\\in [n]$ if and\nonly if the $j$-th pure strategy of player 2 is a best response to $x$. By\nProposition \\ref{br-played-thm}, this is a necessary and sufficient condition\nfor\nplayer 2 to play his $j$-th strategy at every equilibrium where player 1\nchooses $x$. The analogous holds for the strategies $y\\in Y$ and player 1\nplaying her $i$-th strategy in response to player 2 choosing $y$.\nTherefore, at an equilibrium $(x,y)$ all labels $m + j$, with $j\\in [n]$,\nappear either as labels of $x$ or of $y$.\nConversely, if $(x,y)$ is not completely labeled, then some\nlabel does not appear as a label of $x$ or $y$. This label\nrepresents a pure strategy that is played with positive\nprobability but is not a best response, which contradicts\nthe equilibrium property.\n\\end{proof}\n\nA useful graphical representation of labels on the simplices $X$ and $Y$\nis done by labeling the outside of each simplex according to the player's own\npure strategies that are not played, and by subdividing its interior\ninto closed polyhedral sets, called {\\em best response\nregions}, that correspond to the other player's pure\nbest responses.\nWe give an example of this construction.\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\n\\label{br-game-ex}\nConsider the $3\\times 3$ game $(A,B)$ with\n\\begin{equation}\n\\label{AB}\nA = \\left(\\begin{matrix}1&0&0\\\\ 0&1&0\\\\\n0&0&1\\end{matrix}\\right),\n\\qquad\nB = \\left(\\begin{matrix}0&2&4\\\\ 3&2&0\\\\\n0&2&0\\end{matrix}\\right).\n\\end{equation}\nFigure~\\ref{br-regions-fig} shows the mixed strategy simplices $X$ and $Y$:\nthe exterior facets are labeled with the pure strategy that is played\n% In general, do not use a semicolon where period works.\nat the opposite vertex of the simplex. The interior is covered\nby the best response regions, labeled by the other player's pure best\nresponse strategies.\nFor example, the best-response region in $Y$ with label~$1$\nis the set of all the $(y_1,y_2,y_3)\\in\\reals^3$ such that $y_1\\ge y_2$ and\n$y_1\\ge y_3$.\nThere is only one pair $(x,y)$\nthat is completely labeled, namely $x=(\\frac13,\\frac23,0)$\nwith labels $3,4,5$, and $y=(\\frac12,\\frac12,0)$ with labels\n$1,2,6$. This is the only Nash equilibrium of the game.\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Xnondeg.pdf}%\n\\hfill\n%\\vrule height 52mm ~ \\vrule height 27ex\n\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Yimit.pdf}%\n\\hfill\\strut\n\\caption[The labeled mixed strategy simplices of a game]{%\nThe labeled best response regions of the mixed strategy simplices\nof player 1 (left) and player 2 (right) in game (\\ref{AB}).\n}\n\\label{br-regions-fig}\n\\end{figure}\n\\end{example}\n\nThe representation of a game and its Nash equilibria in terms of best\nresponse regions can be translated to an equivalent construction on\npolytopes.\nThe first step is to notice that the best-response regions can be obtained as\nprojections on $X$ and $Y$ of the {\\em best-response facets} of\nthe polyhedra\n\\begin{equation}\n\\label{br-polyhedron}\n\\arraycolsep.2em\n\\begin{array}{rcll}\n\\overline{P}&=&\\{ (x,v)\\in X\\times\\reals& \\mid B\\T x\\leq\\1 v \\},\\\\\n\\overline{Q}&=&\\{ (y,u)\\in Y\\times\\reals& \\mid A y\\leq\\1 u \\}. %\n\\end{array}\n\\end{equation}\nIn $\\overline{P}$, these facets are the points $(x,v)\\in X\\times\\reals$\nsuch that $(B\\T x)_j = v$, which in turn correspond to the strategies\n$x\\in X$ of player 1 that give exactly payoff $v$ to player~2\nwhen he plays strategy $j$; this payoff is the\nbest-response payoff by the definition of $P$.\nThe projection of the facet defined by $(B\\T x)_j = v$ to\n$X$ then has label~$j$.\nAnalogously, the facet of $\\overline{Q}$ given by the points\n$(y,u)\\in Y\\times\\reals$ such that $(A y)_i = u$ projects to the\nbest-response region of $Y$ with label $i$.\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\n\\label{br-polyhedra-ex}\nIn Example \\ref{br-game-ex}, the inequalities $B\\T x\\le\\1v$ are\n\\[\n\\arraycolsep.2em\n\\begin{array}{rcl}\n3x_2 & \\leq&v \\\\\n2x_1+ 2x_2+ 2x_3 & \\leq&v \\\\\n4x_1 & \\leq&v.\n\\end{array}\n\\]\nFigure~\\ref{br-polyhedron-fig} shows the best-response facets of\n$\\overline{P}$ and their projection to $X$ by ignoring the payoff\nvariable~$v$, which gives the subdivision of $X$ into best-response\nregions of Figure \\ref{br-regions-fig}.\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=40ex]{chapter-2/fig-labels/upenv.pdf}%\n\\hfill\\strut\n\\caption[The best response polyhedron of a game]{%\nThe best response polyhedron of player 1 in game (\\ref{AB}).}\n\\label{br-polyhedron-fig}\n\\end{figure}\n\\end{example}\n\nGiven the assumptions on non-negativity of $A$ and $B\\T$, we can\nchange coordinates to $x_i / v$ and $y_j / u$ and replace $\\overline{P}$ and\n$\\overline{Q}$ with the {\\em best-response polytopes}\n\\begin{equation}\n\\label{br-polytopes}\n\\arraycolsep.2em\n\\begin{array}{rcll}\nP&=&\\{\\, x\\in\\reals^m& \\mid\\,x\\geq\\0,\\ B\\T x\\leq\\1 \\},\\\\\nQ&=&\\{\\, y\\in\\reals^n& \\mid\\,A y\\leq\\1,~ y\\geq\\0  \\}.\n\\end{array}\n\\end{equation}\nIn (\\ref{br-polytopes}), both $P$ and $Q$ are defined by\n$m+n$ inequalities that correspond, in the listed order, to the\npure strategies of the two players with labels in $[m+n]$.\nThe polytope $P$ is the intersection of the $m+n$ half-spaces\nthat correspond to either player 1 not playing her $i$-th pure\nstrategy or to a best response $j$ of player~2,\nwhere $i\\in [m]$ and $j\\in [n]$.\nThe analogous statement holds for $Q$.\nFormally, a point $x\\in P$ has label $k$ if and only if either\n$x_k = 0$ for $k\\in [m]$ or $(B\\T x)_j = 1$ for $k=m+j$ with $j\\in [n]$, and\na point in $Q$ has label $k$ if and only if either\n$(A y)_k=1$ for $k\\in [m]$ or $y_j = 0$ for $k=m+j$ with $j\\in [n]$.\n\nHence, a point $(x,y)\\in P\\times Q$ is completely labeled if and only if\nit satisfies the {\\em complementarity condition} that states\n% the quantifiers should be outside to avoid confusion\nthat for all $i\\in[m]$ and all $j\\in[n]$,\n\\begin{equation}\n%\\label{}\n\\begin{array}{ccrll}\nx_i = 0 & \\text{ or }&(Ay)_i= 1~,\\\\\ny_j = 0 & \\text{ or }&(B\\T x)_j=1~.\n\\end{array}\n\\end{equation}\nTherefore, if $(x,y)\\in P\\times Q$ is completely labeled either the\ncorresponding point in $\\overline{P}\\times\\overline{Q}$\nis a Nash equilibrium or $(x,y)=(\\0,\\0)$; we refer to the latter case\nas {\\em artificial equilibrium}.\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\nKeeping on with Example \\ref{br-game-ex} and \\ref{br-polyhedra-ex},\nthe best response\npolyhedron $\\overline{P}$ of Figure \\ref{br-polyhedron-fig} becomes\nthe best response polytope of Figure \\ref{br-polytopes-fig}.\nNotice that the vertex $(x,y)=(\\0,\\0)$ is completely labeled, since it is labeled\nby the labels $1,2,3$ in $P$ and $4,5,6$ in $Q$.\n\\begin{figure}[htb]\n\\strut\\hfill\n\\includegraphics[width=40ex]{chapter-2/fig-labels/polytope.pdf}%\n\\hfill\\strut\n\\caption[The best response polytope of a game]{%\nThe best response polytope of player 1 in game (\\ref{AB}).\n}\n\\label{br-polytopes-fig}\n\\end{figure}\n\\end{example}\n\nWe now consider some special cases of games and how they are related to each\nother in terms of computational complexity.\nFirst of all, we note that any bimatrix game can be ``symmetrized''.\nThis result is due to Gale, Kuhn and Tucker \\cite{gale-kuhn-tucker}\nfor zero-sum games, while its extension to non-zero-sum games is a folklore\nresult.\n\n\\begin{proposition}\\label{symmetrize-c}\nLet $(A,B)$ be a bimatrix game and let $(x,y)$ be one of its Nash equilibria.\nThen $(z,z)$, where $z=(x\\alpha,y\\beta)$ for suitable\npositive scalars $\\alpha$ and $\\beta$, is a Nash equilibrium of the symmetric game\n$(C,C\\T)$, where\n\\begin{equation}\nC = \\left(\n    \\begin{array}{cc}\n    0 & A \\\\\n    B\\T & 0\n    \\end{array}\n    \\right).\n\\end{equation}\n\\end{proposition}\n\nMcLennan and Tourky \\cite{mclennan-tourky} have proven a result in the\nopposite direction of Proposition \\ref{symmetrize-c}: any symmetric game\ncan be translated into a {\\em imitiation game}, where the payoff matrix of\nplayer 1 is the identity matrix $I$. In any Nash equilibrium of $(I,B)$,\nthe mixed strategy $x$\nof player 1 corresponds exactly to the symmetric equilibrium $(x,x)$ in\nthe symmetric game defined by the payoff matrix of player 2.\nSince it takes polynomial time in the size of a matrix to calculate its\ntranspose, an algorithm that finds a Nash equilibrium of a bimatrix game\ncan be used to find a symmetric Nash equilibrium of a symmetric game.\n\n\\begin{theorem}{\\rm (McLennan and Tourky \\cite{mclennan-tourky})}\n\\label{imitation-thm}\nThe pair $(x,x)$ is a symmetric Nash equilibrium of the symmetric bimatrix\ngame $(C,C\\T)$ if and only if there is some $y$ such that $(x,y)$ is a\nNash equilibrium of the imitation game $(I,B)$ with $B=C\\T$.\n\\end{theorem}\n\nNotice that Theorem \\ref{imitation-thm} applies to the symmetric\nequilibria of the symmetric game but not to all its Nash equilibria; there\ncould be non-symmetric equilibria of $(C,C\\T)$ that are not found\nthrough the imitation game, as shown in the following example.\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\nAs an example, consider the symmetric game $(C,C\\T)$ with\n\\begin{equation}\n\\label{C}\nC = \\left(\\begin{matrix}0&3&0\\\\ 2&2&2\\\\\n4&0&0\\end{matrix}\\right),\n\\qquad\nC\\T = \\left(\\begin{matrix}0&2&4\\\\ 3&2&0\\\\\n0&2&0\\end{matrix}\\right).\n\\end{equation}\nThe corresponding imitation game is $(I,C\\T)=(A,B)$, seen in\nExample \\ref{br-game-ex}.\nFigure~\\ref{imit-fig} shows the labeled mixed-strategy simplices $X$ and $Y$\nfor the game~(\\ref{C}); since the game is symmetric, only the labels\nare different.\nIn addition to the symmetric equilibrium $(x,x)$ where\n$x=(\\frac13,\\frac23,0)$, the game has two non-symmetric equilibria in $(a,b)$\nand $(b,a)$ with $a=(\\frac12,\\frac12,0)$ and $b=(0,\\frac23,\\frac13)$.\nThe imitation game $(A,B)$, on the other hand, has only one equilibrium\n$(x,y)$, corresponding to $(x,x)$, with $y=(\\frac{1}{2},\\frac{1}{2},0)$.\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Xnondeg.pdf}%\n\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Ynondeg.pdf}%\n\\hfill\\strut\n\\caption[The best response regions of a symmetric game]{%\nThe best response regions of the symmetric game (\\ref{C}).\n}\n\\label{imit-fig}\n\\end{figure}\n\\end{example}\n\nThe characterization of Nash equilibria as completely labeled pairs $(x,y)$\nholds for arbitrary bimatrix games. From now on, we impose a\nfurther condition: all points in $P$ have at most $m$ labels,\nand all points in $Q$ have at most $n$ labels. These games are called\n{\\em nondegenerate}.\nThis condition is required for the Lemke-Howson algorithm (see\nsection \\ref{lh-sect}).\n% This is a loss of generality\nThe algorithm can also be applied to degenerate games by\nlexicographic perturbation, as shown in von Stengel \\cite{vs-agt}.\nIn an equilibrium $(x,y)$ of a nondegenerate game each label appears\nexactly once. This also means that the number of pure best response\nstrategies against a mixed strategy is never larger than the size of\nthe support of that mixed strategy.\nGeometrically, this means that no point of the best response polytope $P$\nlies on more than $m$ facets and no point of the best response polytope $Q$\nlies on more than $n$ facets, so both $P$ and $Q$ are simple.\nFurthermore, a point of\n$P$ has exactly $m$ labels if and only if it is a vertex, and a point\nof $Q$ has exactly $n$ labels if and only if it is a vertex. Therefore,\nall completely labeled points $(x,y)$ are vertices of the best response\npolytopes, and Nash equilibria are isolated points.\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\nAn example of degenerate game is given by $(C,C\\T)$ with\n\\begin{equation}\n\\label{Cdeg}\nC = \\left(\\begin{matrix}0&4&0\\\\ 2&2&2\\\\\n4&0&0\\end{matrix}\\right),\n\\qquad\nC\\T = \\left(\\begin{matrix}0&2&4\\\\ 4&2&0\\\\\n0&2&0\\end{matrix}\\right).\n\\end{equation}\nAs shown in Figure \\ref{deg-fig}, the mixed strategy\n$x=(\\frac12,\\frac12,0)$, that also defines the\nunique symmetric equilibrium $(x,x)$ of the game, has three pure best\nresponses. The Nash equilibria $(x,y)$ of the imitation game\n$(I,C\\T)$ are not unique, since any convex\ncombination of $(\\frac12,\\frac12,0)$ and $(\\frac13,\\frac13,\\frac13)$\ncan be chosen for~$y$.\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Xsymmdeg.pdf}%\n\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/Yimitdeg.pdf}%\n\\hfill\\strut\n\\caption[A degenerate symmetric game]{%\nLeft: The best-response regions of the degenerate symmetric\ngame (\\ref{Cdeg}). \\\\\nRight: The best-response regions for player 2 in the corresponding\nimitation game $(I,C\\T)$.\n}\n\\label{deg-fig}\n\\end{figure}\n\\end{example}\n\nA generalization of imitation games is the class of\n{\\em unit vector games}, introduced by Balthasar \\cite{balthasar}.\nThese are defined as bimatrix games of the form $(U,B)$ where the\ncolumns of the matrix $U$ are unit vectors.\nBy the results above, finding a Nash equilibrium of a bimatrix game is\nat least as hard as finding a Nash equilibrium of a unit vector game.\nSavani and von Stengel \\cite{uvg} have shown that\nthe problem of finding a completely labeled vertex of the product of the\nbest response polytopes $P\\times Q$ can be simplified for unit vector games:\nit is enough to find a completely labeled vertex of a single\npolytope $P^l$, for which the last $n$ facets are labeled following a\nthe labeling in $[m]$ that also encodes the matrix $U$.\n\n\\begin{theorem}{\\rm (Savani and von Stengel \\cite{uvg})}\n\\label{unit-vector-thm}\nLet $l:[n]\\to [m]$ be a function, and let $(U,B)$ be the unit vector game with\n$U=(e_{l(1)}\\ \\cdots\\ e_{l(n)})$.\n\nLet $N_i = \\{ j\\in [n]\\ \\mid\\ l(j)=i \\}$ for\n$i\\in [m]$, and define $P^l$ and $Q^l$ as\n\\begin{equation}\\label{p-l}\n\\arraycolsep.2em\n\\begin{array}{rcll}\nP^l&=&\\{ x\\in\\reals^m& \\mid\\,x\\geq\\0,\\ B\\T x\\leq\\1 \\}, \\\\\nQ^l&=&\\{ y\\in\\reals^n& \\mid\\,y\\geq\\0,\\\n\\sum_{j\\in N_i } y_j\\leq 1 \\hbox{ for } i\\in [m] \\}.\n\\end{array}\n\\end{equation}\nLet $l_f$ be the labeling of the facets of $P^l$ with labels\nin $[m]$ defined as follows:\n\\begin{equation}\n\\label{facet-labeling-unitv}\n\\begin{array}{rll}\nx_i\\geq 0 & \\text{ has label }i & \\text{ for }i\\in [m], \\\\\n(B\\T x)_j \\leq 1 & \\text{ has label }l(j) & \\text{ for }j\\in [n].\n\\end{array}\n\\end{equation}\nThen $x\\in P^l$ is a completely labeled vertex of\n$P^l\\setminus\\{\\0\\}$ (that is, has all labels in $[m]$)\nif and only if there is some $y\\in Q^l$ such that, after scaling,\nthe pair $(x,y)$ is a Nash equilibrium\nof $(U,B)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $P$ and $Q$ be the best response polytopes of $(U,B)$ as\nin (\\ref{br-polytopes}),\nand let $(x,y)\\in P\\times Q\\setminus\\{ (\\0,\\0) \\}$ be a Nash equilibrium of\n$(U,B)$. Then $(x,y)$ is completely labeled with labels in $[m + n]$. If\n$x_i=0$, then $x$ has label $i\\in m$.\nIf $x_i > 0$, then $y$ has label $i$, so $(Uy)_i = 1$.\nTherefore for some $j\\in [n]$ we have $y_j > 0$ and $U_j = e_i$; that is,\nwe have $y_j > 0$ and $l(j)=i$ for some $j\\in [n]$.\nSince $y_j > 0$, $x\\in P$ has label $m+j$; then, $(B\\T x)_j = 1$;\ntherefore $x\\in P^l$ has label $l(j) = i$.\nHence, $x$ is a completely labeled vertex of $P^l$.\n\nConversely, let $x\\in P^l\\setminus \\{ \\0 \\}$ be completely labeled.\nIf $x_i > 0$, then there is $j\\in [n]$ such that $(B\\T x) = j$ and\n$l(j) = i$; that is, $j\\in N_i$. For all $i\\in [m]$ such that $x_i > 0$,\ndefine $y$ as follows: $y_j = 1$, and\n$y_h = 0$ for all $h\\in N_i\\setminus \\{ j \\}$.\nThen $(x,y)\\in P\\times Q$ is completely labeled.\n\\end{proof}\n\n\\begin{example}({\\rm Savani and von Stengel \\cite{uvg}})\nThe game in Example \\ref{br-game-ex} is a unit vector game with $l(i)=i$.\nIn the polytope $P^l$ of Figure~\\ref{p-l-fig} the labels 4, 5 and 6 of the\nbest response polytope $P$ of Figure \\ref{br-polytopes-fig}\nare replaced by 1, 2 and 3, since the corresponding columns of $A$\nare the unit vectors $e_1,e_2,e_3$.\nThe only completely labeled point of $P^l$ are the origin $\\0$, corresponding\nto the ``artificial'' equilibrium, and $x$, corresponding to the unique\nNash equilibrium of the unit vector game (\\ref{AB}).\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=30ex]{chapter-2/fig-labels/p-l-color.pdf}%\n\\hfill\\strut\n\\caption[The polytope $P^l$ of a unit vector game]{%\nThe polytope $P^l$ of the unit vector game (\\ref{AB}).\n}\n\\label{p-l-fig}\n\\end{figure}\n\\end{example}\n\nWe now move on the dual version of Theorem \\ref{unit-vector-thm}\ngiven by Balthasar \\cite{balthasar}.\nWe can translate the polytope $P^l$ of (\\ref{p-l}) to\n$P = \\{ x - \\1\\ |\\ x\\in P^l \\}$,\npossibly multiplying all payoffs in $B$ by a\nconstant so that $\\0$ is in the interior of $P$, which holds\nif $\\1$ in the interior of $P^l$, that is, all columns $b_j$\nof the matrix $B$ fulfill $\\1\\T b_j<1$, for $j\\in[n]$. Then\n\\begin{align*}\nP   & = \\{ x + \\1\\geq\\0,\\ (x + \\1)\\T B\\leq\\1 \\} = \\\\\n    & = \\{ x\\in\\reals^m\\ |\\ -x_i\\leq 1\\text{ for }i\\in [m],\\\n    x\\T (b_j/(1 - \\1\\T b_j)) \\leq 1\\text{ for }j\\in [n] \\}.\n\\end{align*}\nThe polar of $P$ is then\n\\begin{equation}\\label{p-l-dual}\nP^\\Delta = \\conv(\\{-e_i\\ |\\ i\\in [m] \\}\\ \\cup\\ \\{ c_j\\ |\\ j\\in [n] \\})\n\\end{equation}\nwhere $c_j=b_j/(1 - \\1\\T b_j)$.\nSince $P$ and $P^{\\Delta}$ have $\\0$ in their interior,\n$P^{\\Delta\\Delta}=P$. Furthermore,\n$P^\\Delta $ is simplicial and its facets correspond to the vertices of $P$\nand vice versa.\nWe label the vertices\nof $P^\\Delta $ as the corresponding facets in $P^l$, so the completely\nlabeled facets of $P^\\Delta $ correspond to the completely\nlabeled vertices of $P^l$.\nIn particular, the facet corresponding to $\\0$ is\n\\begin{equation}\n\\label{f-0}\n\\arraycolsep.3em\n\\begin{array}{rcl}\nF_0 & = & \\{ x\\in P^\\Delta\\ \\mid\\ -\\1\\T x = 1 \\}\\\\\n    & = & \\conv\\{-e_i \\mid i\\in [m] \\}.\n\\end{array}\n\\end{equation}\nTheorem \\ref{unit-vector-thm} then translates to the following.\n\n\\begin{theorem}{\\rm (Balthasar \\cite{balthasar})}\n\\label{unit-vector-dual-thm}\nLet $P^\\Delta $ be a labeled $m$-dimensional simplicial polytope with \\0 in\nits interior and vertices $e_1,\\ldots,e_m,c_1,\\ldots,c_n$ such that\n$F_0$ in $(\\ref{f-0})$ is a facet of $P^\\Delta $.\n\nLet $(U,B)$ be a unit vector game, with\n$U=(e_{l(1)}\\ \\cdots\\ e_{l(n)})$\nfor a labeling $l:[n]\\to [m]$ and $B = [\\,b_1\\,\\cdots\\,b_n\\,]$, where\n$b_j = c_j/(1 + \\1\\T c_j)$ for $j\\in [n]$.\n\nLet $l_v$ be the labeling\nof the vertices of $P^\\Delta $ given by\n\\begin{equation}\n\\label{vert-labeling-unitv}\n\\arraycolsep.2em\n\\begin{array}{rcll}\nl_v(-e_i)&=&i\\quad & \\text{ for }i\\in [m],\\\\\nl_v(c_j)&=&l(j)\\quad & \\text{ for }j\\in [n].\n\\end{array}\n\\end{equation}\nThen a facet $F\\neq F_0$ of $P^\\Delta $ with normal vector $v$ is completely\nlabeled if and only if $(x,y)$ is a Nash equilibrium of $(U,B)$, where\n$x = (v + \\1) / (\\1\\T (v + \\1))$, so that\n$x_i = 0$ if and only if $−e_i\\in F$ for $i\\in [m]$\nand the mixed strategy $y$ is the uniform distribution on the set of\nthe pure best replies to $x$, which in turn correspond to all $j\\in [n]$\nsuch that $c_j$ is a vertex of $F$.\n\\end{theorem}\n\nTheorem \\ref{unit-vector-thm} gives a correspondence between\ncompletely labeled vertices of $P^l$ and equilibria of the unit vector game\n$(U,B)$ with the ``artificial'' equilibrium corresponding to the vertex $\\0$.\nTheorem \\ref{unit-vector-dual-thm} gives a correspondence between\ncompletely labeled facets of $P^\\Delta $\nand equilibria of $(U,B)$ with the ``artificial'' equilibrium\ncorresponding to the facet $F_0$ in (\\ref{f-0}).\n\n% ... here you come back to the old Q!\nGiven a bimatrix game $(A,B)$, it takes polynomial time\nto write and solve the linear equations defining its best response polyhedra\n$\\overline{P},\\overline{Q}$ and its best response polytopes $P,Q$.\nIt also takes polynomial time to label $\\overline{P},\\overline{Q}$ and $P,Q$.\nAnalogously, given a unit vector game $(U,B)$, it takes polynomial time\nto construct and label the polytope $P^l$ and its polar.\nTherefore, Theorem \\ref{unit-vector-thm} gives a polynomial time\nreduction from the problem 2-{\\sc Nash} to the\nproblem {\\sc Another Completely Labeled Vertex} of Table \\ref{aclv} and\nTheorem \\ref{unit-vector-dual-thm} gives a dual reduction to the problem\n{\\sc Another Completely Labeled Facet} of Table \\ref{aclf}.\n\n\\begin{problem}\n{Another Completely Labeled Vertex}\n{An $m$-dimensional simple polytope $P$ with $m+n$ facets;\na labeling $l_f:[m+n]\\to [n]$;\na vertex $v_0$ of $P$ that is completely labeled by~$l_f$.}\n{A vertex $v\\neq v_0$ of $P$ that is completely labeled by $l_f$.}\n\\label{aclv}\n\\end{problem}\n\n\\begin{problem}\n{Another Completely Labeled Facet}\n{A simplicial $m$-dimensional polytope $P^\\Delta$ with $m+n$ vertices;\na labeling $l_v:[m+n]\\to [n]$;\na facet $F_0$ of $P^\\Delta$ that is completely labeled by $l_v$.}\n{A facet $F\\neq F_0$ of $P^\\Delta$ that is completely labeled by $l_v$.}\n\\label{aclf}\n\\end{problem}\n\n\n\\begin{proposition}\n\\label{nash-to-acl}\n{\\sc 2-Nash} reduces in polynomial time to\n{\\sc Another Completely Labeled Vertex} and\n{\\sc Another Completely Labeled Facet}.\n\\end{proposition}\n", "meta": {"hexsha": "436b72e08457d54abd4f99243fc952c87a365956", "size": 22551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-2/labels.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-2/labels.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-2/labels.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.0765027322, "max_line_length": 82, "alphanum_fraction": 0.6983725777, "num_tokens": 7709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.6266705597656869}}
{"text": "\\subsection{Real series}\\label{subsec:real_series}\n\n\\begin{proposition}\\label{thm:almost_all_terms_positive_implies_absolute_convergent}\n  If only finitely many coefficients in a real \\hyperref[def:convergent_series]{convergent} series are negative, then the series converges absolutely.\n\\end{proposition}\n\\begin{proof}\n  Let \\( N \\) be the index of the last negative coefficient in \\eqref{def:convergent_series/series}. Then the series\n  \\begin{equation*}\n    \\sum_{k={N+1}}^\\infty a_k\n  \\end{equation*}\n  is absolutely convergent since every coefficient is positive. Then\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty \\abs{a_k} = \\sum_{k=0}^N \\abs{a_k} + \\sum_{k=N+1}^\\infty \\abs{a_k}\n  \\end{equation*}\n  is convergent since the first term on the right side is a finite sum and the second is a convergent series. Hence, the series \\eqref{def:convergent_series/series} converges absolutely.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:almost_all_terms_negative_implies_absolute_convergent}\n  If only finitely many coefficients in a real \\hyperref[def:convergent_series]{convergent} series are positive, then the series converges absolutely.\n\\end{corollary}\n\n\\begin{theorem}[Riemann's series permutation theorem]\\label{thm:riemanns_series_permutation_theorem}\\mcite[\\textnumero 247]{Фихтенгольц1968Том2}\n  If the real series\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty a_k\n  \\end{equation*}\n  is \\hyperref[def:convergent_series]{convergent}, but not absolutely convergent, then for any extended real number \\( x \\in \\BbbR \\cup \\{ -\\infty, +\\infty \\} \\) there exists a \\hyperref[def:symmetric_group]{permutation} \\( p \\) of the coefficients \\( a_0, a_1, a_2 \\)\n  such that\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty p(a_k) = x.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  If the series is not absolutely convergent, then there exist both infinitely many positive and infinitely many negative coefficients.\n\n  First, assume that \\( x \\) is finite.\n\n  Define the permuted series\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty b_k\n  \\end{equation*}\n  as follows:\n  \\begin{thmenum}\n    \\thmitem{thm:riemanns_series_theorem/positive} Assign to \\( b_n \\) only nonnegative elements of the sequence \\( \\{ a_k \\}_{k=0}^\\infty \\) until \\( \\sum_{k=0}^n b_k \\geq x \\). Then go to \\ref{thm:riemanns_series_theorem/negative}.\n    \\thmitem{thm:riemanns_series_theorem/negative} Assign to \\( b_n \\) only negative elements of the sequence \\( \\{ a_k \\}_{k=0}^\\infty \\) until \\( \\sum_{k=0}^n b_k \\geq x \\). Then go to \\ref{thm:riemanns_series_theorem/positive}.\n  \\end{thmenum}\n\n  This mutual recursion builds a series that converges to \\( x \\) because the coefficients \\( \\{ a_k \\}_{k=0}^\\infty \\) get arbitrarily close to each other.\n\n  If \\( x = +\\infty \\), we can add positive coefficients until \\( \\sum_{k=0}^n b_k \\geq 1 \\), then add a single negative coefficient, then continue adding positive coefficients until \\( \\sum_{k=0}^n b_k \\geq 2 \\) and, so on.\n\n  If \\( x = -\\infty \\), we use the same process, but with milestones of \\( -1, -2, -3, \\ldots \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:riemanns_series_permutation_theorem/alternating_harmonic_series}\\cite[\\textnumero 247]{Фихтенгольц1968Том2}\n  Consider the alternating harmonic series \\eqref{eq:ex:harmonic_series/alternating}. Denote its sum by \\( a \\).\n\n  We can rearrange this series by repeating two negative terms and a single positive term as follows:\n  \\begin{equation}\\label{ex:riemanns_series_permutation_theorem/alternating_harmonic_series/rearranged}\n    1 - \\frac 1 2 - \\frac 1 4 + \\frac 1 3 - \\frac 1 6 - \\frac 1 8 + \\cdots\n    =\n    \\sum_{m=1}^\\infty \\left( \\frac 1 {2m - 1} - \\frac 1 {4m - 2} - \\frac 1 {4m} \\right).\n  \\end{equation}\n\n  Note that \\fullref{ex:riemanns_series_permutation_theorem/alternating_harmonic_series/rearranged} is equivalent to\n  \\begin{equation*}\n    \\sum_{m=1}^\\infty \\left( \\frac 1 {2m - 1} - \\frac 1 {4m - 2} - \\frac 1 {4m} \\right)\n    =\n    \\sum_{m=1}^\\infty \\left( \\frac 1 {4m - 2} - \\frac 1 {4m} \\right)\n    =\n    \\frac 1 2 \\sum_{m=1}^\\infty \\left( \\frac 1 {2m - 1} - \\frac 1 {42} \\right)\n    =\n    \\frac a 2.\n  \\end{equation*}\n\\end{example}\n\n\\begin{proposition}\\label{thm:positive_series_comparison}\\mcite[\\textnumero 237]{Фихтенгольц1968Том2}\n  Fix two nonnegative series\n  \\begin{equation}\\label{def:positive_series_comparison/a}\n    \\sum_{k=0}^\\infty a_k\n  \\end{equation}\n  and\n  \\begin{equation}\\label{def:positive_series_comparison/b}\n    \\sum_{k=0}^\\infty b_k\n  \\end{equation}\n  that is, series with nonnegative real coefficients. Assume that there exists an index \\( K \\) such that\n  \\begin{equation*}\n    a_k \\leq b_k \\quad\\forall k \\geq K.\n  \\end{equation*}\n\n  We say that the series \\fullref{def:positive_series_comparison/b} \\term{dominates} the series \\fullref{def:positive_series_comparison/a}.\n\n  Then\n  \\begin{thmenum}\n    \\thmitem{thm:positive_series_comparison/b_converges} If \\fullref{def:positive_series_comparison/b} converges, so does \\fullref{def:positive_series_comparison/a}.\n\n    \\thmitem{thm:positive_series_comparison/a_diverges} If \\fullref{def:positive_series_comparison/a} diverges, so does \\fullref{def:positive_series_comparison/b}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:positive_series_comparison/b_converges} Suppose that \\fullref{def:positive_series_comparison/b} converges. Then by \\fullref{thm:real_monotone_sequence_converges_iff_bounded}, the sequence of partial sums is bounded. Therefore, the sequence of partial sums of \\fullref{def:positive_series_comparison/a} is also bounded and, by \\fullref{thm:real_monotone_sequence_converges_iff_bounded} again, the series is convergent.\n\n  \\SubProofOf{thm:positive_series_comparison/a_diverges} Analogous to \\fullref{thm:positive_series_comparison/b_converges}, but using the negation of \\fullref{thm:real_monotone_sequence_converges_iff_bounded}.\n\\end{proof}\n\n\\begin{proposition}[Cauchy's root test]\\label{thm:cauchys_root_test}\\mcite[thm. 3.33]{Rudin1976Principles}\n  Consider the nonnegative series \\fullref{def:positive_series_comparison/a}. Put\n  \\begin{equation*}\n    q \\coloneqq \\limsup_{k \\to \\infty} \\sqrt[k]{a_k},\n  \\end{equation*}\n  where \\( q = \\infty \\) if the limit does not exist. Then\n  \\begin{itemize}\n    \\item If \\( q < 1 \\), the series converges.\n    \\item If \\( q > 1 \\), the series diverges.\n    \\item If the limit does not exist (e.g. if \\( a_k = k^k \\)), the series diverges.\n    \\item If \\( q = 1 \\), the series may either converge or diverge.\n  \\end{itemize}\n\\end{proposition}\n\\begin{proof}\n  The case when the limit \\( q \\) does not exist is obvious by the contraposition to \\fullref{thm:convergent_series_terms_vanish}.\n\n  Suppose that the limit exists. Therefore, there exists an index \\( K \\) such that\n  \\begin{equation*}\n    \\sqrt[k]{a_k} \\leq q \\quad\\forall k \\geq K.\n  \\end{equation*}\n\n  Thus, we have the inequality\n  \\begin{equation*}\n    a_k \\leq q^k \\quad\\forall k \\geq K.\n  \\end{equation*}\n\n  The statement of the theorem now follows from comparison (\\fullref{thm:positive_series_comparison}) with the geometric series \\eqref{eq:def:geometric_progression/series}.\n\\end{proof}\n\n\\begin{proposition}[d'Alambert's ratio test]\\label{thm:dalamberts_ratio_test}\\mcite[thm. 3.33]{Rudin1976Principles}\n  Consider the nonnegative series \\fullref{def:positive_series_comparison/a}. Put\n  \\begin{equation*}\n    q \\coloneqq \\limsup_{k \\to \\infty} \\frac {a_{k+1}} {a_k},\n  \\end{equation*}\n  where \\( q = \\infty \\) if the limit does not exist. Then\n  \\begin{itemize}\n    \\item If \\( q < 1 \\), the series converges.\n    \\item If there exists an index \\( k_0 \\) such that \\( \\frac {a_{k+1}} {a_k} \\geq 1 \\) for all \\( k \\geq k_0 \\), the series diverges.\n    \\item If the limit does not exist (e.g. if \\( a_k = k! \\)), the series diverges.\n  \\end{itemize}\n\\end{proposition}\n\\begin{proof}\n  All cases except for \\( q < 1 \\) are obvious by the contraposition to \\fullref{thm:convergent_series_terms_vanish}.\n\n  Suppose that the limit exists. Therefore, there exists an index \\( k_0 \\) such that\n  \\begin{equation*}\n    a_{k+1} \\leq q a_k \\quad\\forall k \\geq k_0.\n  \\end{equation*}\n\n  Thus,\n  \\begin{equation*}\n    a_{k_0 + m} \\leq q^m a_{k_0} \\quad\\forall m \\geq \\BbbZ^{\\geq 0}.\n  \\end{equation*}\n\n  Convergence now follows from comparison (\\fullref{thm:positive_series_comparison}) of the geometric series \\eqref{eq:def:geometric_progression/series} with the subseries of \\fullref{def:positive_series_comparison/a} obtained by trimming the first \\( k_0 \\) elements.\n\\end{proof}\n\n\\begin{proposition}\\label{rem:nonnegative_series_convergence_test_equivalence}\n  The values of \\( q \\) in \\fullref{thm:cauchys_root_test} and in \\fullref{thm:dalamberts_ratio_test} are equal.\n\\end{proposition}\n\\begin{proof}\n  If we assume that they are not equal, then the same series would have to be convergent and divergent simultaneously in some region.\n\\end{proof}\n\n\\begin{definition}\\label{def:alternating_series}\n  Series of the form\n  \\begin{equation}\\label{def:alternating_series/series}\n    \\pm \\sum_{k=0}^\\infty (-1)^k a_k,\n  \\end{equation}\n  where all \\( a_k, k = 0, 1, \\ldots \\) are nonnegative, are called \\term{alternating}.\n\\end{definition}\n\n\\begin{proposition}[Leibniz' alternating series test]\\label{thm:leibniz_alternating_series_test}\n  Consider the alternating series \\fullref{def:alternating_series}. If the sequence of terms \\( \\{ a_k \\}_{k=0}^\\infty \\) decreases monotonically and if \\( \\lim_{k \\to \\infty} a_k = 0 \\), then the series converges.\n\\end{proposition}\n\n\\begin{theorem}\\label{thm:weierstrass_series_criterion_nessessity}\\mcite[\\textnumero 268]{Фихтенгольц1968Том2}\n  \\Fullref{thm:weierstrass_series_criterion} is a necessary condition for nonnegative real functions.\n\\end{theorem}\n", "meta": {"hexsha": "d040b5fb3e2a8642840fb97bc761b395356e822b", "size": 9708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_series.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/real_series.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/real_series.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.4756756757, "max_line_length": 435, "alphanum_fraction": 0.7301194891, "num_tokens": 3189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6265631901350799}}
{"text": "\\section{Mixed States}\nIn many situations in physics we don't know what the wave function is,\nbut we do know that there is some probability of the wave function being\nsomething.\nSo to compute things we need to take averages.\nThere are two averages.\nOne is quantum mechanical, but one is classical.\nProbabilities in quantum mechanics don't add,\nthey might subtract.\nAmplitudes add,\nbut there are cross terms.\nThe second average is a classical average,\nwhich is due to my ignorance.\n\nIf one is to describe it with QM,\ninstead of having kets,\nI'm going to have an operator called the density operator.\nIt's a bit different,\nbecause even the state is an operator.\nIf I don't know which state I'm in,\nsay there's a probability $p_n$ of being $\\ket{n}$ ,\nthen the density operator is\n\\begin{align}\n    \\rho &= \\sum_{n} p_n \\ket{n}\\bra{n}\n\\end{align}\nThen the expectation value of $A$ is\n\\begin{align}\n    \\bar{A} = \\Tr(\\rho A)\n\\end{align}\nThere are special states though.\nIf I know 100\\% that my system is in state $\\ket{\\psi}$,\nthen in that sum,\nthe probability is zero in every state except for $\\ket{\\psi}$,\nin which case the density operator is\n\\begin{align}\n    \\rho = \\ket{\\psi}\\bra{\\psi}.\n\\end{align}\nAnd so the expectation value is\n\\begin{align}\n    \\Tr(\\rho A) &=\n    \\Tr(\\ket{\\psi}\\bra{\\psi} A)\\\\\n    &= \\sum_n \\braket{n}{\\psi} \\bra{\\psi}A\\ket{n}\\\\\n    &= \\sum_n \\bra{A}A\\ket{n}\\braket{n}{\\psi}\\\\\n    &= \\bra{\\psi}A\\ket{\\psi}\\\\\n    &= \\bar{A}\n\\end{align}\nwhere we made a sandwich of whatever basis $\\ket{n}$ we wanted\nand used the resolution of the identity.\nSo this reduces to the usual rule for pure states.\n\nBut what happens when we don't have a pure state,\nbut a mixed state,\nin which case the $\\Tr(\\rho A)$ rule applies more generally.\n\nIt's not obvious, but there is a way to test if a density operator is a pure\nstate.\nIn fact,\n$\\rho$\nis a pure state if and only if\n$\\rho^2 = \\rho$.\n\nAnd we also required that it be positive definite\n\\begin{align}\n    \\bra{\\phi}\\rho \\ket{\\rho} \\ge 0.\n\\end{align}\nAlso,\n$\\Tr \\rho = 1$.\n\n\nExample: Thermodynamic ensemble\nSuppose we have a system in thermal equilibrium.\nWe don't know where the microscopic particles are,\nso there are certain probabilities of certain wave functions.\nTurns out if you take most systems and let them evolve,\nthe wave function keeps changing,\nbut everything behaves as if we were in a basis state.\nI'm going to point out the following here.\nIf I wait some time,\nand make macroscopic measurements of energy, pressure, etc.\nEverything behaves as if it were a density operator of the following form.\n\\begin{align}\n    \\rho &= \\frac{e^{-\\beta H}}{\\Tr e^{-\\beta H}}\n\\end{align}\nwhere $H$ is Hermitian so $e^{-\\beta H} = 1 - \\beta H + \\cdots$\nis also Hermitian.\nYou can check that $H^2$ is hermitian with\n$(H^2)^\\dagger = (HH)^\\dagger = H^\\dagger H^\\dagger = H^2$.\nDon't be confused if you have an $i$ factor instead,\nwhere $e^{itH}$ is unitary,\nbut $e^{-\\beta H}$ is hermitian.\nWe have to divide by the real number $\\Tr e^{-\\beta H}$\nto make the trace 1,\nwhich is obvious,\nbecause the trace of the numerator cancels the denominator.\n\nBut is it positive definite?\nIt's not obvious,\nyou can work it out yourself,\nbut the eigenvalues of $H$ are real,\nand when you exponentiate a real number,\nyou get a positive number,\nso the eigenvalues of $\\rho$ must be positive.\n\nThis is a perfectly good density matrix.\nIt's sometimes written in a slightly different way.\nI could write $\\rho$ in the eigenbasis of energy\nwith matrix elements $\\bra{n}\\rho\\ket{m}$.\nIn other words $H\\ket{n} = E_n \\ket{n}$.\n\\begin{align}\n    \\bra{n}\\rho\\ket{m} &=\n    \\frac{\\bra{n} e^{-\\beta H}\\ket{m}}{\\Tr e^{-\\beta H}}\\\\\n    &= \\frac{e^{-\\beta E_m} \\delta_{nm}}{\n        \\sum_n \\bra{n} e^{-\\beta E_n}\\ket{n}\n    }\\\\\n    &= \\frac{e^{-\\beta E_m} \\delta_{nm}}{\n        \\sum_n e^{-\\beta E_n}\n    }.\n\\end{align}\nI'm sure you're familiar with the top\n$e^{-\\beta E_n}$\nwhich is just the Boltzmann factor.\nStates with large energy are unlikely,\nthe states that are more likely have smaller energy.\nLarge and small compared to what?\n\nRemember that this $\\beta E = \\frac{E}{k_B T}$.\nSo for the exponential to be small,\nwe need $E$ to be large.\nSo higher temperatures are more likely to have more likely higher energy states.\nWe'll see this a lot later on.\n\n\nExample: Photo polarization\nI can have light linearly polarized in $x$ and $y$ directions,\nand various superpositions like circular, left, right, etc.\nBut I can also have mixed states.\n\\begin{itemize}\n    \\item 50\\% linearly polarized along $\\hat{x}$ direction and\n        50\\% linearly polarized along $\\ket{y}$ direction\n        can be written as the state\n        \\begin{align}\n            \\rho =\n            \\frac{1}{2}\\ket{\\hat{x}}\\bra{\\hat{x}}\n            + \\frac{1}{2}\\ket{\\hat{y}}\\bra{\\hat{y}}\n        \\end{align}\n        and this is just a specific case of the more general formula\n        \\begin{align}\n            \\rho = \\sum_n p_n \\ket{n}\\bra{n}\n        \\end{align}\n    \\item Now consider the state with\n        50\\% probability of being left circularly polarized\n        and 50\\% probability of being right circularly polarized.\n        Let's write down the density matrix for that.\n        \\begin{align}\n            \\rho &=\n            \\frac{1}{2} \\ket{L}\\bra{L}\n            + \\frac{1}{2} \\ket{R}\\bra{R}\\\\\n            &=\n            \\frac{1}{2}\n            \\underbrace{\n                \\frac{\n                    \\ket{\\hat{x}} + i\\ket{\\hat{y}}\n                }{\\sqrt{2}}\n            }_{\\ket{L}}\n            \\underbrace{\n                \\frac{\n                    \\bra{\\hat{x}} - i\\bra{\\hat{y}}\n                }{\\sqrt{2}}\n            }_{\\bra{L}}\n            + \\frac{1}{2}\n            \\underbrace{\n                \\frac{\n                    \\ket{\\hat{x}} - i\\ket{\\hat{y}}\n                }{\\sqrt{2}}\n            }_{\\ket{R}}\n            \\underbrace{\n                \\frac{\n                    \\bra{\\hat{x}} + i\\bra{\\hat{y}}\n                }{\\sqrt{2}}\n            }_{\\bra{R}}\\\\\n            &= \\frac{1}{2}\\ket{\\hat{x}}\\bra{\\hat{x}}\n            + \\frac{1}{2}\\ket{\\hat{y}}\\bra{\\hat{y}}\n        \\end{align}\n        so although the description in words they sound different,\n        they are in fact the same state,\n        and there is no experiment in the world that will allow you to\n        differentiate between the two.\n\\end{itemize}\nSo the description in words in different,\nbut in reality they are different.\n\n\\subsection{Entropy (max)minimization}\nLet me point something about entropy because people talk about it so I should\npoint it out as soon as possible.\n\nYou can talk about the entropy of a mixed state.\nThere are two concepts of entropy closely related.\nWe can define entropy the following way.\nSuppose your system is defined by a density matrix $\\rho$\nthat might be a mixed state.\nYou can compute the following quantity\n\\begin{align}\n    S &= - \\Tr \\left( \\rho \\ln \\rho \\right)\n\\end{align}\nBut first,\ndo you know how to define the log of an operator?\nTaylor expansion is one way?\nInverse of the exponential operator?\nHowever,\nif you can diagonalize the operator,\nyou can take any function you want,\nbecause you can take the function of any diagonal matrix,\nyou just take the function of each eigenvalue on the diagonal,\nno different from taking the exponential of an operator.\nWhy should we call this entropy?\nEntropy is something you learn in high school.\n\nFor that,\nlet me write this in a slightly different way.\nI'm going to take a basis and I'm going to write\n\\begin{align}\n    S &=\n    - \\sum_n\n    \\bra{n} \\rho \\ln\\rho \\ket{n}\n\\end{align}\nwhere $\\ket{n}$ is an eigenbasis of $\\rho$.\nTo make things a little better,\nI can insert a complete set of states here.\n\\begin{align}\n    S &=\n    - \\sum_{n,n'}\n    \\bra{n} \\rho \\ket{n'}\\bra{n'}\\ln\\rho \\ket{n}\n\\end{align}\nand so you notice that because $\\rho$ is diagonal in this basis,\n\\begin{align}\n    S &= \\sum_{n,n'} p_{n'}\\delta_{nn'} \\delta_{nn'}\\ln p_n\\\\\n    &= - \\sum_n p_n \\ln p_n\n\\end{align}\nThis expression you may have seen before in thermodynamics.\nWhy is this important?\nImagine if $\\rhO$ is a pure state.\nIt's a pure state when I write $\\rho$ as a sum like\n\\begin{align}\n    \\rho &= \\sum_n p_n \\ket{n}\\bra{n} = \\ket{\\psi}\\bra{\\psi}\n\\end{align}\nso all the $p_n=0$ except for one $n=n_0$ where $p_{n_0}=1$.\nSo what does that mean?\nThere are two kinds of terms in the sum,\nterms where $p_n=0$,\nand only one term where $p_n=1$,\nso then\n\\begin{align}\n    S &= - 0 \\ln 0 - 1\\ln 1 = 0\n\\end{align}\nSo if I have a pure state\nand I compute the entropy,\nthe entropy is zero.\n\n\\begin{question}\n    What about superpositions?\n    Do we get non-zero entropy?\n\\end{question}\nNo no no no!\nLet's take the harmonic oscillator\nand say we have an excited state like\n\\begin{align}\n    \\rho &=\n    \\underbrace{\\left( \\frac{3}{5}\\ket{0} + \\frac{4}{5}\\ket{1} \\right)}_{%\n        \\ket{\\psi}\n    }\n    \\underbrace{\\left( \\frac{3}{5}\\bra{0} + \\frac{4}{5}\\ket{1} \\right)}_{%\n        \\bra{\\psi}\n    }\\\\\n    &\\ne \\left( \\frac{3}{5} \\right)^2 \\ket{0}\\bra{0}\n    + \\left( \\frac{4}{5} \\right)^2 \\ket{1}\\bra{1}\n\\end{align}\nbecause of the cross terms.\n\nAnyway,\nlet us consider the uniform distribution\n$p_n=1/N$\nand the dimension $N$ of the Hilbert space is finite.\nThen the entropy is\n\\begin{align}\n    S &= -\\sum_n p_n\\ln p_n\n    = -\\frac{N}{N}\\ln \\frac{1}{N} = \\ln N\n\\end{align}\nand it turns out that this is the maximum value the entropy can be.\nIt represents complete ignorance.\n\n\\begin{question}\n    This is just the Shannon entropy of each hermitian operator viewed as a\n    random variable?\n\\end{question}\nYes, I can't parse that precisely but sure.\n\n\\begin{question}\n    Is $N$ the same thing as the number of basis states?\n\\end{question}\nYes, that's the definition of dimension.\n\n\\subsection{Subsystems and mixed states}\nThe idea is the following.\nImagine I have a system made up of two subsystems.\nIf the system is made up of two subsystems,\nthen the total space is the tensor product.\nThe generic state of a composite system can be written like this\n\\begin{align}\n    \\ket{\\psi} &=\n    \\sum_{n,m} \\psi_{n,m}\n    \\ket{n}\\otimes\\ket{m}\n\\end{align}\nwhere $\\ket{n}\\otimes\\ket{m}$ forms the basis for the composite system\n$\\mathcal{H}$,\n$\\ket{n}$ forms a basis for $\\mathcal{H}_1$ and\n$\\ket{m}$ forms a basis for $\\mathcal{H}_2$.\n\nNow imagine if you have an operator $A$,\nbut I only want to measure one subsystem.\nThe operator $A\\otimes \\mathbf{1}$ does this.\n\\begin{align}\n    A\\otimes \\mathbf{1} \\ket{\\phi}\\otimes\\ket{\\chi}\n    &=\n    A \\ket{\\phi} \\otimes \\ket{\\chi}\n\\end{align}\nIt does nothing to subsystem 2.\n\nSuppose I want to find an expectation value like this.\nBut I'm going to assume the system is in what is called an entangled state,\nsomething like this\n\\begin{align}\n    \\ket{\\psi} =\n    \\frac{%\n        \\ket{\\phi_1}\\otimes\\ket{\\chi_1}\n        + \\ket{\\phi_2}\\otimes\\ket{\\chi_2}\n    }{\\sqrt{2}}\n\\end{align}\nThere is a correlation between particles 1 and 2.\nThis is called \\emph{entanglement}.\nIt's a perfectly good state,\nso let's see what happens.\n\\begin{align}\n    \\bra{\\psi} A\\otimes\\mathbf{1} \\ket{\\psi} &=\n    \\frac{%\n        \\ket{\\phi_1}\\otimes\\ket{\\chi_1}\n        + \\ket{\\phi_2}\\otimes\\ket{\\chi_2}\n    }{\\sqrt{2}}\n    A\\otimes\\mathbf{1}\n    \\frac{%\n        \\bra{\\phi_1}\\otimes\\bra{\\chi_1}\n        + \\bra{\\phi_2}\\otimes\\bra{\\chi_2}\n    }{\\sqrt{2}}\\\\\n    &=\n    \\frac{1}{2}\n    \\bra{\\phi_1}A\\ket{\\phi_1}\n    \\bra{\\chi_1}1\\ket{\\chi_1}\n    +\n    \\frac{1}{2}\n    \\bra{\\phi_1}A\\ket{\\phi_2}\n    \\bra{\\chi_1}1\\ket{\\chi_2}\\\\\\nonumber\n    &\\qquad+\n    \\frac{1}{2}\n    \\bra{\\phi_2}A\\ket{\\phi_1}\n    \\bra{\\chi_2}1\\ket{\\chi_1}\n    +\n    \\frac{1}{2}\n    \\bra{\\phi_1}A\\ket{\\phi_1}\n    \\bra{\\chi_2}1\\ket{\\chi_2}\\\\\n    &=\n    \\frac{1}{2}\\bra{\\phi_1}A\\ket{\\phi_1}\n    + \\frac{1}{2}\\bra{\\phi_2}A\\ket{\\phi_2}\n\\end{align}\nBut notice that we have seen this before and it is the same as an incoherent sum\n\\begin{align}\n    \\frac{1}{2}\\bra{\\phi_1}A\\ket{\\phi_1}\n    + \\frac{1}{2}\\bra{\\phi_2}A\\ket{\\phi_2}\n    =\\Tr\\left[\n        \\underbrace{\\left(\n            \\frac{1}{2}\\ket{\\phi_1}\\bra{\\phi_1}\n            + \\frac{1}{2}\\ket{\\phi_2}\\bra{\\phi_2}\n        \\right)}_{\\rho_1} A\n    \\right]\n\\end{align}\nThe situation with a pure state over 2 systems is indistinguishable from having\na classical mixed state in system 1.\nIt's like you destroyed the interference!\nThis density matrix $\\rho_1$ you have here is only for subsystem 1\nIf I had no access to subsystem 2,\nlike if I moved it to another galaxy,\nall I would see is a classical mixed state in subsystem 1.\n\n[break]\n\nLet me repeat this same calculation in a slightly more general setting so you\nunderstand the general rule.\nSuppose you want to calculate the expectation value of a pure state of a\ncomposite system.\nThe most general composite state looks like this\n\\begin{align}\n    \\sum_{n'm'}\\ket{n'}\\otimes\\ket{m'}\n\\end{align}\nThis is a little tricky,\nso I'm going to do it slowly.\n\\begin{align}\n    \\bra{\\psi}A\\otimes\\mathbf{1}\\ket{\\psi}\n    &=\n    \\sum_{n',m',n,m}\n    \\bra{n}\\otimes\\bra{m}\n    \\psi_{nm}^*\n    A\\otimes\\mathmbf{1}\n    \\psi_{n'm'}\\ket{n'}\\otimes\\ket{m'}\\\\\n    &=\n    \\sum_{n',m',n,m}\n    \\psi_{nm}^* \\psi_{n'm'}\n    \\bra{n}A\\ket{n'}\n    \\underbrace{\\bra{m}\\mathbf{1}\\ket{m'}}_{\\delta_{mm'}}\\\\\n    &=\n    \\sum_{nn'}\\bra{n}A\\ket{n'}\n    \\sum_m\\psi_{nm}^* \\psi_{n'm}\\\\\n    &= \\Tr\\left[\n        \\underbrace{\\sum_{n,m,n'} \\psi_{nm}^* \\psi_{n'm}\\ket{n}\\bra{n'}}_{%\n            \\rho_1\n        }\n        A\n    \\right]\n\\end{align}\nNote that the proper way to compute a trace is to sandwich a complete basis on\neach side and sum over.\nUsing the cyclic property of the trace is not a valid way of doing it,\nbut it just happens to work in this case.\n\nTensor products look like a mouthful on paper,\nbut it's completely trivial to manipulate.\n\nAnyway,\nthe point of this is that $\\rho_1$ may be a mixed state of only subsystem 1.\nThat's the price you pay for not knowing about subsystem 2.\n\n\nLet's doe something exciting.\nShooting particles through holes and interference.\nPeople say that if you somehow have a way of looking which way the particle goes\nthrough,\njust by having the possibility of knowing,\nthe interference pattern gets destroyed.\nIt's a bit mysterious because of the following.\nIf you know the particle is left or right,\nyou make a measurement,\nand you collapse the system.\n\nIf it was a superposition,\nbecause of measurement,\nyou collapse it.\n\\begin{align}\n    \\frac{\\ket{L} + \\ket{R}}{\\sqrt{2}}\n    \\to\n    \\ket{L}\n\\end{align}\nBut what does it even mean to make a measurement.\nSuppose you had a machine that automatically writes left or right,\nbut nobody looks at that piece of paper,\nis that enough to destroy the interference or not.\nLet me not use the collapse of the wave function,\nbut using the knowledge we just learnt.\n\nSuppose my state is a superposition\n\\begin{align}\n    \\ket{\\psi_0} &=\n    \\frac{\\ket{L} + \\ket{R}}{\\sqrt{2}}\n\\end{align}\nbut suppose I have a piece of equipment that spies on the particle.\nBut now I have both the particle and the spy\nas a composite system.\nMy spy system $\\ket{\\text{spy}}$ lives in a Hilbert space\n$\\mathcal{H}_{\\text{spy}}$,\nwhich could be quite complicated\nbecause it's a complicated device.\n\n\\begin{align}\n    \\ket{\\psi_0} &=\n    \\frac{\\ket{L} + \\ket{R}}{\\sqrt{2}}\n    \\otimes\n    \\ket{\\text{spy}}\n\\end{align}\nBut then it evolves according to a Hamiltonian $H$ and we get\n\\begin{align}\n    \\ket{\\psi} &=\n    \\frac{\\ket{L} + \\ket{R}}{\\sqrt{2}}\n    \\otimes\n    \\ket{\\text{spy}'}\n\\end{align}\nBut now it's evolved in a way completely independent of the particle,\nbut that's not useful because it's not spying!\nSo what we really want is for the spy to distinguish between left and right,\nso we something like this.\n\\begin{align}\n    \\ket{\\psi} &=\n    \\frac{1}{\\sqrt{2}}\n    \\ket{L}\n    \\otimes\n    \\ket{\\text{spy,left}}\n    +\n    \\frac{1}{\\sqrt{2}}\n    \\ket{R}\n    \\otimes\n    \\ket{\\text{spy,right}}\n\\end{align}\nThat is a 100\\% precise measurement by the spy device.\nNow I'm going to ask the following question.\nThe spy device going left or right is writen on the piece of paper,\nbut no one is going to look at it.\nIt's not really a measurement.\nNow suppose the paper is burnt,\ndestroyed.\n\nThe particles are still going to hit the screen,\nso what I'm going to be interested in doing is measure things,\nsay $A$,\nthat refer only to the particle,\nso the operator is $A\\otimes\\mathbf{1}$.\nIf I only measure things like this,\nthen I know everything that I can possibly measure about the system\nis contained in a density matrix obtained the same as before.\n\nTake the density matrix intially which is a pure state\n\\begin{align}\n    \\rho &= \\ket{\\psi}\\bra{\\psi}\\\\\n    &=\n    \\sum_{n,m,n',m'} \\psi_{n'm'}\\ket{n'}\\otimes\\ket{m'}\\\\\n    \\bra{n}\\otimes\\bra{m}\\psi_{nm}^*\\\\\n    &\\to\n    \\sum_{n,m,n'} \\psi_{nm}^* \\psi_{n'm}\\ket{n}\\bra{n'}\n    = \\rho_1\n\\end{align}\nBut how did I get there?\nI had to take a trace over system 2.\n\\begin{align}\n    \\sum_{m''}\\bra{m''}\\rho\\ket{m''} &=\n    \\sum_{m''}\\bra{m''}\\ket{\\psi}\\bra{\\psi}\\ket{m''}\\\\\n    &=\n    \\sum_{m''}\\bra{m''}\\sum_{n,m,n',m'} \\psi_{n'm'}\\ket{n'}\\otimes\\ket{m'}\n    \\bra{n}\\otimes\\bra{m}\\psi_{nm}^*\\ket{m''}\\\\\n    &\\to\n    \\sum_{n,m,n'} \\psi_{nm}^* \\psi_{n'm}\\ket{n}\\bra{n'}\n    = \\rho_1\n\\end{align}\n\nThis procedure here,\nthere's a name of it,\nit's called taking the trace of subsystem 2.\n\\begin{align}\n    \\Tr_2 \\rho = \\sum_{m''}\\bra{m''} \\rho \\ket{m''}\n\\end{align}\nwhere $\\ket{m''}$ form a basis for subsystem 2.\nYou will be left with a possibly mixed state $\\rho_1$ for only subsystem 1.\nThis is sometimes called the \\emph{partial trace},\nan operation that is very common\nand you should know this.\n\nLet's go back to the problem.\nSo we have the state for subsystem 1\n\\begin{align}\n    \\rho_1 &=\n    \\Tr_2 \\rho\\\\\n    &=\n    \\Tr_2\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\ket{L}\\otimes\\ket{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\ket{R}\\otimes\\ket{\\text{spy,r}}\n    \\right)\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\bra{L}\\otimes\\bra{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\bra{R}\\otimes\\bra{\\text{spy,r}}\n    \\right)\\\\\n    &= \n    \\bra{\\text{spy.l}}\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\ket{L}\\otimes\\ket{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\ket{R}\\otimes\\ket{\\text{spy,r}}\n    \\right)\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\bra{L}\\otimes\\bra{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\bra{R}\\otimes\\bra{\\text{spy,r}}\n    \\right)\n    \\ket{\\text{spy.l}}\\\\\\nonumber\n    &\\qquad+\n    \\bra{\\text{spy.r}}\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\ket{L}\\otimes\\ket{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\ket{R}\\otimes\\ket{\\text{spy,r}}\n    \\right)\n    \\left(\n        \\frac{1}{\\sqrt{2}}\\bra{L}\\otimes\\bra{\\text{spy,l}}\n        + \\frac{1}{\\sqrt{2}}\\bra{R}\\otimes\\bra{\\text{spy,r}}\n    \\right)\n    \\ket{\\text{spy.r}}\\\\\n    &= \\frac{1}{2}\\ket{L}\\bra{L} + \\frac{1}{2}\\ket{R}\\bra{R}\n\\end{align}\nThis gives the density matrix of the particle\nand you've seen this before.\nIt describes the situation where you don't know where the particle is,\nand it could left or right.\nIn particular,\nIf I try to compute expectation values of some of the particles,\nI just get the usual thing of incoherent sum, no intereference.\n\\begin{align}\n    \\bar{A} &=\n    \\Tr \\rho_A\\\\\n    &= \\frac{1}{2}\\bra{L}A\\ket{L}\n    + \\frac{1}{2}\\bra{R}A\\ket{R}\n\\end{align}\nbut I'm now going to look at this piece of paper and it doesn't matter.\nThe interference pattern is gone.\nIt works whether it's written by the piece of paper or not.\nIt could be a single photon going through the particle,\nand that reveals the position of the particle,\nbecause the future state of the photon depends where the particle is.\nThat entanglement means I end up with a situation indistinguishable from a\ncoherent sum.\nA single photon going through the experiment\ncorrelating with the particle destroys the interference.\n\nWhat counts as a measurmenet?\none thing you can tell from our calculation.\nIt's enough to have anything entangling with the particle and you won't be able\nto see the intereference.\nit doesn't have to be a monkey, a grad student, or whatever,\na single photon correlation is enough.\n\n\\begin{question}\n    You call it incoherent because it has no inteference terms?\n\\end{question}\nYes that's right, some lingo I introduced before.\n\n\\begin{question}\n    What if we're not aware of the entanglement?\n    Will it stil affect the system?\n\\end{question}\nIt doesn't matter what Paulo sees,\nany system entangling with the particle will destroy interference.\nDoesn't matter if I know about it or not.\n\n\nLet me make a comment.\nwhat this suggests is that to see intference effects is tricky in pratice.\nA single straight photon will destroy it.\nIt's not hard with light.\nBut if you tried doint it with electrons,\nit's hard.\nPhotons don't interact with each other,\nbut there's always light to interact with electrons.\nSo to do experiments with electrons is difficult.\n\nThere's great work recently with quantum devices of all kinds\nQuantum computers being the most famous ones.\nIt's why quantum computers are so hard to make.\nYour quantum coputer needs a hilbert space of some dimension,\nbut all the coherence will disappear if your qubits get entangled with the\noutside world,\nand that could be anything,\neven the metal frame that's holding it.\nYou have to make sure the whole thing that is supporting your device doesn't get\nentangled with it.\ncertainly you have to make sure it's dark,\nbecause a little photon can interact with it and it can entangle,\nand you get a mixed state.\nIt's a tremendous technological challange.\nIt's not hard to get this in the lab,\nit's how they discovered QM.\nBut instead of an atom,\nbut a bigger system,\ncertainly a macroscopic thing,\nit's hard.\nThere's awhole fued nowadays in physics,\nquantum registers or other systems,\ncould they keep a superposition.\nI won't be surprised if half of you spend half your life trying to do this\nstuff.\nAny other comments?\n\n\\begin{question}\n    Future of quantum computing?\n\\end{question}\nI cannot predict the future,\nbut I can tell you\nI have not invested in quantum computing companies.\nI can tell you I was on the ground on Amazon,\nand I did not buy Amazon stock either.\nI was like this is stupid,\nwho wants to buy books,\nbooks are heavy.\nI did not buy Amazon stock,\nI'm not buying quantum computing stock.\n\nSomeone's comment is that the effect of cosmic rays in classical computers is a\nthing.\nIt may happen, it does happen.\nIt happens a lot in satellites though.\nCosmic rays are like a hammer,\nit cna destroy annything,\nincluding classical informaiton.\nWhat I'm saying is way worse than this.\nClassical computers don't even use error correcting codes.\nThey're so precise they don't hvae to.\nQuantum computers are a non-starter without quanutm error correction.\nI'm not an experimentalist,\nI don't know,\nbut I'm excitedly waiting for a quantum computer.\nThe difficulty is that you don't need a measurement to collapse a wave funciton,\nall you need is a bit of entangelmetn.\n\nThere are many other things that can entangle.\n\nWe have 9 minutes left.\nI have more stuff to talk about,\nbut about a little bit of a different topic.\n\n\\begin{question}\n    Before yo urevisited the double slit expreiment,\n    we were looking at the expectation of $A$.\n    If we have the same $\\psi$ on both sides,\n    why do we need separate indices on both sides $m'$ and $n'$.\n\\end{question}\nEvery time there's an issue with sums and indices,\nthe best thing to do is do an example.\nLet's say $n,m,\\ldots, = 1,2$.\nSay your state is\n\\begin{align}\n    \\ket{\\psi} = \\frac{\\ket{1} + \\ket{2}}{\\sqrt{2}}\n\\end{align}\nThen we have\n\\begin{align}\n    \\bra{\\psi}A\\ket{\\psi} &=\n    \\frac{\\bra{1} + \\bra{2}}{\\sqrt{2}} A\n    \\frac{\\ket{1} + \\ket{2}}{\\sqrt{2}}\\\\\n    &=\n    \\frac{1}{2} \\bra{1} A\\ket{1}\n    + \\frac{1}{2} \\bra{2} A\\ket{2}\n    + \\frac{1}{2} \\bra{1} A\\ket{2}\n    + \\frac{1}{2} \\bra{2} A\\ket{1}\n\\end{align}\nGreat, let's write things in terms of indices now?\nIs this the same thing as\n\\begin{align}\n    \\sum_{n=1}2\\bra{n}A\\ket{m}?\n\\end{align}\nClearly not,\nbut it is the same as\n\\begin{align}\n   \\sum_{n,m=1}2\\bra{n}A\\ket{m}?\n\\end{align}\nYou can settle these issues by doing an example that's trivial,\nand it's immediately completely obvious.\n\n\\begin{question}\n    If I think of that line conceptually as no intference,\n    we have a particle and it got entangled with another system,\n    and we lost informaitno about the other system,\n    and is that why we don't have inteference.\n\\end{question}\nI agree with everything we said,\nbut it doesn't mean one expalins another.\nI find it completely mind-boggling\nthat I start with a pure state,\nand if I look at just a subsystem,\nand I get a mixed state.\nIf somehow saying those words makes you happy,\nthen everything is alrgith.\nYou're smarter than me.\nYeah, I don't know what to say.\nI don't find anything at all.\nI just got used to it.\n\nA week ago,\nif I told you this,\nyou'd say oh yeah correlaing wiht another particle,\nnitference should disapear.\n\nYou've heard the double slit experiment a million times,\nand yo've been told if you look at it it will disappear.\nDid you know that entangling is a measurment devices and they destroy\ninteference.\nWhen I was a sutdent this wasn't explained.\nEverything you said was right,\nthat's the only thing I can tell you.\n\n\\begin{question}\n    Does the uniform distirbution have maximum entropy?\n    But what's the distribution that maximises entropy for the haronic\n    osciollator?\n\\end{question}\nYes.\nThere is no upper bound for the entropy of an infinite dimensinoal system.\nEntropy increases with temperature,\nand there is no bound for temperature.\nThe entropy does have a maximum for finite-state systems.\n\nTentative new office hours Friday 1pm.\n", "meta": {"hexsha": "3967134e8062d8279b102f2652a1be29d1385753", "size": 25621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture11.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/lecture11.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/lecture11.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": 32.0663329161, "max_line_length": 80, "alphanum_fraction": 0.6733148589, "num_tokens": 7662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6265590306643541}}
{"text": "%!TEX root = ../OGUSAdoc.tex\n\nThree markets must clear in \\ogindia---the labor market, the capital market, and the goods market. By Walras' Law, we only need to use two of those market clearing conditions because the third one is redundant. In the model, we choose to use the labor market clearing condition and the capital market clearing condition, and to ignore the goods market clearing condition. But we present all three market clearing conditions here. Further, the redundant goods market clearing condition---sometimes referred to as the resource constraint---makes for a nice check on the solution method to see if everything worked.\n\nWe also characterize here the law of motion for total bequests $BQ_t$. Although it is not technically a market clearing condition, one could think of the bequests law of motion as the bequests market clearing condition.\n\n\\section{Market Clearing Conditions}\\label{SecMarkClrMktClr}\n\n  Labor market clearing \\eqref{EqMarkClrLab} requires that aggregate labor demand $L_t$ measured in efficiency units equal the sum of household efficiency labor supplied $e_{j,s}n_{j,s,t}$.\n  \\begin{equation}\\label{EqMarkClrLab}\n    L_t = \\sum_{s=E+1}^{E+S}\\sum_{j=1}^{J} \\omega_{s,t}\\lambda_j e_{j,s}n_{j,s,t} \\quad \\forall t\n  \\end{equation}\n  Capital market clearing \\eqref{EqMarkClrCap} requires that aggregate capital demand from firms $K_t$ and from the government $D_t$ equal the sum of capital savings and investment by households $b_{j,s,t}$.\n  \\begin{equation}\\label{EqMarkClrCap}\n    K_t + D_t = \\sum_{s=E+2}^{E+S+1}\\sum_{j=1}^{J}\\Bigl(\\omega_{s-1,t-1}\\lambda_j b_{j,s,t} + i_s\\omega_{s,t-1}\\lambda_j b_{j,s,t}\\Bigr) \\quad \\forall t\n  \\end{equation}\n  Note that the capital demand side of the capital market clearing equation \\eqref{EqMarkClrCap} includes both capital demand by firms $K_t$ and capital demand by government $D_t$. It is here that we can see the potential of government deficits to crowd out investment.\n\n  Aggregate consumption $C_t$ is defined as the sum of all household consumptions, and aggregate investment is defined by the resource constraint $Y_t = C_t + I_t + G_t$ as shown in \\eqref{EqMarkClrGoods}.\n  \\begin{equation}\\label{EqMarkClrGoods}\n    \\begin{split}\n      Y_t &= C_t + K_{t+1} - \\biggl(\\sum_{s=E+2}^{E+S+1}\\sum_{j=1}^{J}i_s\\omega_{s,t}\\lambda_j b_{j,s,t+1}\\biggr) - (1-\\delta)K_t + G_t \\quad\\forall t \\\\\n      &\\quad\\text{where}\\quad C_t \\equiv \\sum_{s=E+1}^{E+S}\\sum_{j=1}^{J}\\omega_{s,t}\\lambda_j c_{j,s,t}\n    \\end{split}\n  \\end{equation}\n\n  Note that the extra terms with the immigration rate $i_s$ in the capital market clearing equation \\eqref{EqMarkClrCap} and the resource constraint \\eqref{EqMarkClrGoods} accounts for the assumption that age-$s$ immigrants in period $t$ bring with them (or take with them in the case of out-migration) the same amount of capital as their domestic counterparts of the same age. Note also that the term in parentheses with immigration rates $i_s$ in the sum acts is equivalent to a net exports term in the standard equation $Y=C+I+G+NX$. That is, if immigration rates are positive, then immigrants are bringing capital into the country and the term in parentheses has a negative sign in front of it. Negative exports are imports.\n\n\n\\section{Total Bequests Law of Motion}\\label{SecMarkClrBQ}\n\n  Total bequests $BQ_t$ are the collection of savings of household from the previous period who died at the end of the period. These savings are augmented by the interest rate because they are returned after being invested in the production process.\n  \\begin{equation}\\label{EqMarkClrBQ}\n    BQ_{t} = (1+r_{t})\\left(\\sum_{s=E+2}^{E+S+1}\\sum_{j=1}^J\\rho_{s-1}\\lambda_j\\omega_{s-1,t-1}b_{j,s,t}\\right) \\quad\\forall t\n  \\end{equation}\n  Because the form of the period utility function in \\eqref{EqHHPerUtil} ensures that $b_{j,s,t}>0$ for all $j$, $s$, and $t$, total bequests will always be positive $BQ_{j,t}>0$ for all $j$ and $t$.\n", "meta": {"hexsha": "7a6c0ba18a512e64d3eada84d69dcf24376f0e17", "size": 3940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/LaTeXsource/Chapters/Chap_MarkClr.tex", "max_stars_repo_name": "keshavchoudhary87/OG-India", "max_stars_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-17T19:49:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-17T19:49:22.000Z", "max_issues_repo_path": "docs/LaTeXsource/Chapters/Chap_MarkClr.tex", "max_issues_repo_name": "keshavchoudhary87/OG-India", "max_issues_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-08-16T15:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T07:07:15.000Z", "max_forks_repo_path": "docs/LaTeXsource/Chapters/Chap_MarkClr.tex", "max_forks_repo_name": "keshavchoudhary87/OG-India", "max_forks_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 44, "max_forks_repo_forks_event_min_datetime": "2019-08-16T15:10:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-08T07:03:26.000Z", "avg_line_length": 106.4864864865, "max_line_length": 728, "alphanum_fraction": 0.7494923858, "num_tokens": 1116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6265582642828831}}
{"text": " \\documentclass[a4paper,11pt]{article}\n\n\\usepackage{fancyhdr}\n\\usepackage[dvips]{graphicx}  % for eps and MatLab Diagrams\n\\usepackage{amsmath}\n\\usepackage{psfrag,color}\n\\usepackage[framed]{/Applications/TeX/mcode}\n\n\\pagestyle{fancy}\n\n\\begin{document} % Begin Document\n\n% Title\n\\title{\\textsc{DERIVEST}}\n\n% Authors and Contact Information\n\\author{\\textbf{John R. D'Errico}\\\\\nEmail: woodchips@rochester.rr.com}\n\n\\maketitle\n\n\\section{Introduction - Derivative Estimation}\n\nThe general problem of differentiation of a function typically pops up in\nthree ways in Matlab.\n\n\\begin{itemize}\n  \\item The symbolic derivative of a function.\n  \\item Compute numerical derivatives of a function defined only by a sequence of data points.\n  \\item Compute numerical derivatives of a analytically supplied function.\n\\end{itemize}\n\nClearly the first member of this list is the domain of the symbolic toolbox, or some\nset of symbolic tools. Numerical differentiation of a function defined by data points\ncan be achieved with the function gradient, or perhaps by differentiation of a curve fit\nto the data, perhaps to an interpolating spline or a least squares spline fit.\n\nThe third class of differentiation problems is where \\mcode{DERIVEST} is valuable. This\ndocument will describe the methods used in \\mcode{DERIVEST}.\n\n\\bigskip\n\n\\section{Numerical differentiation of a general function of one variable}\n\nSurely you recall the traditional definition of a derivative, in terms of a limit.\n\n\\begin{equation} \\tag{1}\n   f'(x) = \\lim_{\\delta \\to 0}{\\frac{f(x+\\delta) - f(x)}{\\delta}}\n\\end{equation}\n\nFor small $\\delta$, the limit approaches $f'(x)$. This is a one-sided approximation for\nthe derivative. For a fixed value of $\\delta$, this is also known as a finite difference\napproximation (a forward difference.) Other approximations for the derivative are also\navailable. We will see the origin of these approximations in the Taylor series expansion\nof a function $f(x)$ around some point $x_0$.\n\n\\begin{multline} \\tag{2}\n   f(x) = f(x_0) + (x - x_0)f'(x_0) + \\frac{(x - x_0)^2}{2} f''(x_0) + \\\\\n   \\frac{(x - x_0)^3}{6} f^{(3)}(x_0) + \\frac{(x - x_0)^4}{24} f^{(4)}(x_0) + \\\\\n   \\frac{(x - x_0)^5}{120} f^{(5)}(x_0) + \\frac{(x - x_0)^6}{720} f^{(6)}(x_0) +...\n\\end{multline}\n\nTruncate the series in (2) to the first three terms, then form the forward difference\napproximation (1), where $x = x_0 + \\delta$.\n\n\\begin{equation} \\tag{3}\n   f'(x_0) = \\frac{f(x_0+\\delta) - f(x_0)}{\\delta} - \\frac{\\delta}{2} f''(x_0) - \\frac{\\delta^2}{6} f'''(x_0) + ...\n\\end{equation}\n\nWhen $\\delta$ is small, $\\delta^2$ and any higher powers are vanishingly small. So we tend\nto ignore those higher powers, and describe the approximation in (3) as a \"first\" order\napproximation since the error in this approximation approaches zero at the same rate as the first power of $\\delta$. \\footnote{We would normally write these additional terms using O() notation, where all that matters is that the error term is $O(\\delta)$ or perhaps $O(\\delta^2)$, but explicit understanding of these error terms will be useful in the Romberg extrapolation step later on.} The values of $f''(x_0)$ and $f'''(x_0)$, while unknown to us, are fixed constants as $\\delta$ varies.\n\nHigher order approximations arise in the same fashion. The central difference (4) is a second\norder approximation.\n\n\\begin{equation} \\tag{4}\n   f'(x_0) = \\frac{f(x_0+\\delta) - f(x_0-\\delta)}{2\\delta} - \\frac{\\delta^2}{3} f'''(x_0) + ...\n\\end{equation}\n\n\n\\bigskip\n\n\\section{Unequally spaced finite difference rules}\n\nWhile most finite difference rules used to differentiate a function will use equally spaced points,\nthis fails to be appropriate when one does not know the final spacing. Adaptive quadrature\nrules can succeed by subdividing each sub-interval as necessary. But an adaptive\ndifferentiation scheme must work differently, since differentiation is a point estimate.\n\\mcode{DERIVEST} generates a sequence of sample points that follow a log spacing away\nfrom the point in question, then it uses a single rule (generated on the fly) to estimate the\ndesired derivative. Because the points are log spaced, the same rule applies at any scale,\nwith only a scale factor applied.\n\n\n\\bigskip\n\n\\section{Odd and even transformations of a function}\n\nReturning to the Taylor series expansion of $f(x)$ around some point $x_0$, an even function \\footnote{An even function is one which expresses an even symmetry around a given point. An even symmetry has the property that $f(x) = f(-x)$. Likewise, an odd function expresses an odd symmetry, wherein $f(x) = -f(-x)$.} around $x_0$ must have all the odd order derivatives vanish at $x_0$. An odd function has all its even derivatives vanish from its expansion. Consider the derived functions $f_{odd}(x)$ and $f_{even}(x)$.\n\n\\begin{equation} \\tag{5}\nf_{odd}(x) = \\frac{f(x - x_0) - f(-x - x_0)}{2} \n\\end{equation}\n\nThe Taylor series expansion of $f_{odd}(x)$ has the useful property that we have killed off any even order terms, but the odd order terms are identical to $f(x)$, as expanded around $x_0$.\n\n\\begin{multline} \\tag{6}\nf_{odd}(x) = (x - x_0)f'(x_0) + \\frac{(x - x_0)^3}{6} f^{(3)}(x_0) + \\\\\n\\frac{(x - x_0)^5}{120} f^{(5)}(x_0) + \\frac{(x - x_0)^7}{5040} f^{(7)}(x_0) +...\n\\end{multline}\n\nLikewise, $f_{even}(x)$ has no odd order terms or a constant term, but other even order terms that are\nidentical to $f(x)$.\n\n\\begin{equation} \\tag{7}\nf_{even}(x) = \\frac{f(-x-x_0) - 2f(x_0) + f(x-x_0)}{2}\n\\end{equation}\n\n\\begin{multline} \\tag{8}\nf_{even}(x) = \\frac{(x - x_0)^2}{2} f^{(2)}(x_0) + \\frac{(x - x_0)^4}{24} f^{(4)}(x_0) + \\\\\n \\frac{(x - x_0)^6}{720} f^{(6)}(x_0) + \\frac{(x - x_0)^8}{40320} f^{(8)}(x_0) + ...\n\\end{multline}\n\nThe point of these transformations is we can rather simply generate a higher order approximation\nfor any odd order derivatives of $f(x)$ by working with $f_{odd}(x)$. Even order derivatives of $f(x)$ are similarly generated from $f_{even}(x)$. For example, a second order approximation for $f'(x_0)$ is trivially written in (9) as a function of $\\delta$.\n\n\\begin{equation} \\tag{9}\n   f'(x_0; \\delta) = \\frac{f_{odd}(x_0 + \\delta)}{\\delta} - \\frac{\\delta^2}{6} f^{(3)}(x_0)\n\\end{equation}\n\nWe can do better rather simply, so why not? (10) shows a fourth order approximation for $f'(x_0)$.\n\n\\begin{equation} \\tag{10}\n   f'(x_0; \\delta) = \\frac{8 f_{odd}(x_0+\\delta)-f_{odd}(x_0+2\\delta)}{6\\delta} + \\frac{\\delta^4}{30} f^{(5)}(x_0)\n\\end{equation}\n\nAgain, the next non-zero term (11) in that expansion has a higher power of $\\delta$ on it, so we\nwould normally ignore it since the lowest order neglected term should dominate the behavior\nfor small $\\delta$.\n\n\\begin{equation} \\tag{11}\n  \\frac{\\delta^6}{252} f^{(7)}(x_0)\n\\end{equation}\n\n\\mcode{DERIVEST} uses similar approximations for all derivatives of $f$ up to the fourth order.\nOf course, its not always possible for evaluation of a function on both sides of a point, as central difference rules will require. In these cases, you can specify forward or backward difference rules\nas appropriate.\n\n\n\\bigskip\n\n\\section{Romberg extrapolation methodology applied to derivative estimation}\n\nSome individuals might suggest that the above set of approximations are entirely adequate for\nany sane person. Can we do better?\n\nSuppose we were to generate several different estimates of the approximation in (3) for\ndifferent values of $\\delta$ at a fixed $x_0$. Thus, choose a single $\\delta$, estimate a\ncorresponding resulting approximation to $f'(x_0)$, then do the same for $\\delta/2$.\nIf we assume that the error drops off linearly as $\\delta \\to 0$, then it is a simple matter\nto extrapolate this process to a zero step size. Our lack of knowledge of $f''(x_0)$ is\nirrelevant. All that matters is $\\delta$ is small enough that the linear term dominates so we\ncan ignore the quadratic term, therefore the error is purely linear.\n\n\\begin{equation} \\tag{12}\n   f'(x_0) = \\frac{f(x_0+\\delta) - f(x_0)}{\\delta} - \\frac{\\delta}{2} f''(x_0)\n\\end{equation}\n\nThe linear extrapolant for this interval halving scheme as $\\delta \\to 0$ is given by (13).\n\n\\begin{equation} \\tag{13}\n   f'_0 = 2f'_\\delta - f'_{\\delta/2}\n\\end{equation}\n\nSince I've always been a big fan of convincing myself that something will work before I\nproceed too far, lets try this out in Matlab. Consider the function $e^x$. Generate a pair of \napproximations to $f'(0)$, once at $\\delta$ of 0.1, and the second approximation at $1/2$\nthat value. Recall that $\\frac{d(e^x)}{dx} = e^x$, so at x = 0, the derivative should be\nexactly 1. How well will we do?\n\n\\begin{lstlisting}\n>> format long g\n\n>> f = @(x) exp(x);\n>> del = 0.1;\n\n>> df1 = (f(del) - f(0))/del\ndf1 =\n          1.05170918075648\n\n>> df2 = (f(del/2) - f(0))/(del/2)\ndf2 =\n          1.02542192752048\n\n>> 2*df2 - df1\nans =\n         0.999134674284488\n\\end{lstlisting}\n\nIn fact, this worked very nicely, reducing the error to roughly 1 percent of our initial estimates.\nShould we be surprised at this reduction? Not if we recall that last term in (3). We saw there that\nthe next term in the expansion was $O(\\delta^2)$. Since $\\delta$ was 0.1 in our experiment, that\n1 percent number makes perfect sense.\n\nThe Romberg extrapolant in (13) assumed a linear process, with a specific reduction in $\\delta$\nby a factor of 2. Assume the two term (linear + quadratic) residual term in (3), evaluating our approximation there with a third value of $\\delta$. Again, assume the step size is cut in half again.\nThe three term Romberg extrapolant is given by (14).\n\n\\begin{equation} \\tag{14}\n   f'_0 = \\frac{1}{3}f'_\\delta - 2f'_{\\delta/2} + \\frac{8}{3}f'_{\\delta/4}\n\\end{equation}\n\nA quick test in matlab yields much better results yet.\n\n\\begin{lstlisting}\n>> format long g\n>> f = @(x) exp(x);\n>> del = 0.1;\n\n>> df1 = (f(del) - f(0))/del\ndf1 =\n          1.05170918075648\n\n>> df2 = (f(del/2) - f(0))/(del/2)\ndf2 =\n          1.02542192752048\n\n>> df3 = (f(del/4) - f(0))/(del/4)\ndf3 =\n          1.01260482097715\n\n>> 1/3*df1 - 2*df2 + 8/3*df3\nans =\n          1.00000539448361\n\\end{lstlisting}          \n\nAgain, \\mcode{DERIVEST} uses the appropriate multiple term Romberg extrapolants for all derivatives\nof $f$ up to the fourth order. This, combined with the use of high order approximations for the derivatives, allows the use of quite large step sizes.\n\n\\bigskip\n\n\\section{Uncertainty estimates for DERIVEST}\n\nWe can view the Romberg extrapolation step as a polynomial curve fit in the step size parameter\n$\\delta$. Our desired extrapolated value is seen as simply the constant term coefficient in that polynomial model. Remember though, this polynomial model (see (10) and (11)) has only a few\nterms in it with known non-zero coefficients. That is, we will expect a constant term $a_0$, a term\nof the form $a_1 \\delta^4$, and a third term $a_2 \\delta^6$. \n\nA neat trick to compute the \"statistical\" uncertainty in the estimate of our desired derivative is to\nuse statistical methodology for that error estimate. While I do appreciate that there is nothing\ntruly statistical or stochastic in this estimate, the approach still works nicely, providing a very reasonable estimate in practice. A three term Romberg-like extrapolant, then evaluated at four distinct values for $\\delta$, will yield an estimate of the standard error of the constant term, with one spare degree of freedom. The uncertainty is then derived by multiplying that standard error by the appropriate percentile from the Students-t distribution.\n\n\\begin{lstlisting}\n>> tcdf(12.7062047361747,1)\nans =\n                     0.975\n\\end{lstlisting}\n\nThis critical level will yield a two-sided confidence interval of 95 percent.\n\nThese error estimates are also of value in a difference sense. Since they are efficiently generated\nat all the different scales, the particular spacing which yields the minimum predicted error is chosen\nas the best derivative estimate. This has been shown to work consistently well. A spacing too large\ntends to have large errors of approximation due to the finite difference schemes used. But a too\nsmall spacing is bad also, in that we see a significant amplification of least significant fit errors\nin the approximation. A middle value generally seems to yield quite good results. For example,\n\\mcode{DERIVEST} will estimate the derivative of $e^x$ automatically. As we see, the final overall\nspacing used was 0.1953125.\n\n\\begin{lstlisting}\n>> [d,e,del]=derivest(@(x) exp(x),1)\nd =\n          2.71828182845904\ne =\n      1.02015503167879e-14\ndel =\n                 0.1953125\n\\end{lstlisting}\n\nHowever, if we force the step size to be artificially large, then approximation error takes over.\n\n\\begin{lstlisting}\n>> [d,e,del]=derivest(@(x) exp(x),1,'FixedStep',10)\nd =\n           2.3854987890005\ne =\n          3.90016042034995\ndel =\n        10\n\\end{lstlisting}\n\nAnd if the step size is forced to be too small, then we see noise dominate the problem.\n\n\\begin{lstlisting}\n>> [d,e,del]=derivest(@(x) exp(x),1,'FixedStep',.0000000001)\nd =\n          2.71826406220403\ne =\n      0.000327191484277048\ndel =\n                     1e-10\n\\end{lstlisting}\n\n\\mcode{DERIVEST}, like Goldilocks in the fairy tale bearing her name, stays comfortably in\nthe middle ground.\n\n\n\\bigskip\n\n\\section{DERIVEST in action}\n\nHow does \\mcode{DERIVEST} work in action? A simple nonlinear function with a well\nknown derivative is $e^x$. At $x = 0$, the derivative should be 1.\n\n\\begin{lstlisting}\n>> [d,err] = derivest(@(x) exp(x),0)\nd =\n         0.999999999999997\n\nerr =\n      2.22066469352214e-14\n\\end{lstlisting}\n\nA second simple example comes from trig functions. The first four derivatives of the sine\nfunction, evaluated at $x = 0$, should be respectively $[cos(0), -sin(0), -cos(0), sin(0)]$,\nor $[1,0,-1,0]$.\n\n\\begin{lstlisting}\n>> d = derivest(@(x) sin(x),0,1)\nd =\n         0.999999999999999\n\n>> d = derivest(@(x) sin(x),0,2)\nd =\n     0\n\n>> d = derivest(@(x) sin(x),0,3)\nd =\n         -1.00000000000046\n\n>> d = derivest(@(x) sin(x),0,4)\nd =\n     0\n\\end{lstlisting}\n\n\n\\bigskip\n\n\\section{Gradient (\\mcode{GRADEST}) and Hessian (\\mcode{HESSIAN}) estimation}\n\nEstimation of the gradient vector (\\mcode{GRADEST}) of a function of multiple variables is a\nsimple task, requiring merely repeated calls to \\mcode{DERIVEST}. Likewise, the diagonal\nelements of the hessian matrix are merely pure second partial derivatives of a function.\n\\mcode{HESSDIAG} accomplishes this task, again calling \\mcode{DERIVEST} multiple\ntimes. Efficient computation of the off-diagonal (mixed partial derivative) elements of the\nHessian matrix uses a scheme much like that of \\mcode{DERIVEST}, wherein\n\\mcode{DERIVEST} is called to determine an initial step size, then Romberg extrapolation\nis used to improve a set of second order finite difference estimates of those mixed partials.\n\n\\bigskip\n\n\\section{Conclusion}\n\n\\mcode{DERIVEST} is an a adaptive scheme that can compute the derivative of arbitrary\n(well behaved) functions. It is reasonably fast as an adaptive method. Many options have\nbeen provided for the user who wishes the ultimate amount of control over the estimation.\n\n\n\\bigskip\n\n\\section{Acknowledgments}\n\nMy thanks are due to Shaun Simmons for convincing me to learn enough\nLaTeX to write this document.\n\n\\bigskip\n\n\n\\begin{thebibliography}{3}\n\n\\bibitem{LM66} Lyness, J. M., Moler, C. B. (1966).\n\\newblock Vandermonde Systems and Numerical Differentiation.\n\\newblock \\emph{Numerische Mathematik}.\n\n\\bibitem{LM69} Lyness, J. M., Moler, C. B. (1969).\n\\newblock Generalized Romberg Methods for Integrals of Derivatives.\n\\newblock \\emph{Numerische Mathematik}.\n\n\\bibitem{LM66} \\emph{NAG Library}.\n\\newblock NAG Fortran Library Document: D04AAF\n\n\\end{thebibliography}\n\n\n\\end{document}\n", "meta": {"hexsha": "663edaf0f732168c9c9d1ca29565c3639cf8b109", "size": 15690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/src/DERIVEST.tex", "max_stars_repo_name": "rparini/numdifftools", "max_stars_repo_head_hexsha": "2c88878df732c9c6629febea56e7a91fd898398d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 181, "max_stars_repo_stars_event_min_datetime": "2015-01-21T07:16:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T20:35:10.000Z", "max_issues_repo_path": "docs/src/DERIVEST.tex", "max_issues_repo_name": "rparini/numdifftools", "max_issues_repo_head_hexsha": "2c88878df732c9c6629febea56e7a91fd898398d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2015-01-21T11:46:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T21:22:31.000Z", "max_forks_repo_path": "docs/src/DERIVEST.tex", "max_forks_repo_name": "rparini/numdifftools", "max_forks_repo_head_hexsha": "2c88878df732c9c6629febea56e7a91fd898398d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-22T18:03:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-21T15:48:42.000Z", "avg_line_length": 39.5214105793, "max_line_length": 520, "alphanum_fraction": 0.7205226259, "num_tokens": 4614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.6265582605480592}}
{"text": "\\subsection{Classification of Riemann Surfaces}\r\nWe roughly classified all Riemann surfaces in the preceding section by viewing them as quotients of their universal covers, which can only be one of $\\mathbb C_\\infty,\\mathbb C,\\mathbb D$.\r\nWe say the surface is uniformised by its universal cover.\r\nFor some of these cases, we can do something better.\r\n\\begin{proposition}\r\n    If a Riemann surface $R$ is uniformised by $\\mathbb C_\\infty$, then $R$ is conformally equivalent to $\\mathbb C_\\infty$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $R=G\\backslash\\mathbb C_\\infty$, then we know that $G$ acts by conformal equivalences $\\mathbb C_\\infty\\to\\mathbb C_\\infty$.\r\n    But this is just M\\\"obius transformations (from Example Sheet).\r\n    However, any M\\\"obius transformation has at least one fixed point, but $G$ should act freely, hence necessarily $G$ is trivial and hence $R\\cong\\mathbb C_\\infty$.\r\n\\end{proof}\r\nWhat about $\\mathbb C$?\r\n\\begin{proposition}\r\n    If a Riemann surface $R$ is uniformised by $\\mathbb C$, i.e. $R\\cong G\\backslash\\mathbb C$, then one of the following holds:\\\\\r\n    (i) $G$ is trivial and $R\\cong\\mathbb C$.\\\\\r\n    (ii) $G\\cong\\mathbb Z$ and $R\\cong\\mathbb C_\\star$.\\\\\r\n    (iii) $G\\cong\\mathbb Z^2$ and $R\\cong\\mathbb C/\\Lambda$ for a lattice $\\Lambda$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The conformal automorphisms of $\\mathbb C$ are simply the (nonconstant) linear maps $\\{z\\mapsto az+b:a\\in\\mathbb C_\\star,b\\in\\mathbb C\\}$ (again from Example Sheet).\r\n    Which of them can $G$ act by?\r\n    Note that if $a\\neq 1$, then $z\\mapsto az+b$ has a fixed point, therefore $G$ can only consist of translations.\r\n    But then (Example Sheet again!) $G$ (identified by the values of $b$) can only be one of:\\\\\r\n    (i) Trivial.\\\\\r\n    (ii) $\\langle\\omega\\rangle\\cong\\mathbb Z$ for some $\\omega\\neq 0$.\\\\\r\n    (iii) a lattice $\\Lambda\\cong\\mathbb Z^2$.\\\\\r\n    And these corresponds to the three situations as stated.\r\n\\end{proof}\r\nOh, by the way, a surface cannot be uniformised by more than one of $\\mathbb C_\\infty,\\mathbb C,\\mathbb D$.\r\n\\begin{lemma}[Lifting Lemma]\r\n    Let $f:R\\to S$ be an analytic map of Riemann surfaces.\r\n    Suppose $R$ is simply connected, and let $\\pi:\\tilde{S}\\to S$ be the uniformising map of $S$, then there is an analytic map $F:R\\to\\tilde{S}$ such that $f=\\pi\\circ F$.\r\n\\end{lemma}\r\nSo we have the commutative diagram\r\n\\[\r\n    \\begin{tikzcd}\r\n        &\\tilde{S}\\arrow{d}{\\pi}\\\\\r\n        R\\arrow[dashed]{ur}{F}\\arrow[swap]{r}{f}&S\r\n    \\end{tikzcd}\r\n\\]\r\n\\begin{proof}\r\n    Example Sheet.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    A Riemann surface $R$ is uniformised by at most one of $\\mathbb C_\\infty,\\mathbb C,\\mathbb D$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    By the previous discussion, we already know everything that is uniformised by $\\mathbb C$ or $\\mathbb C_\\infty$ and they are distinct.\r\n    Now suppose $R$ is uniformised by $\\mathbb D$ and $\\tilde{R}$ which is either $\\mathbb C$ or $\\mathbb C_\\infty$.\r\n    Let $\\pi,f$ be the respective uniformisation maps, then by the preceding lemma, there is $F:\\tilde{R}\\to\\mathbb D$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            &\\mathbb D\\arrow{d}{\\pi}\\\\\r\n            \\tilde{R}\\arrow[swap]{r}{f}\\arrow{ur}{F}&R\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n    But then $F$ has to be constant by Liouville's Theorem, hence $f$ is also constant, contradiction.\r\n\\end{proof}\r\nSo any other Riemann surface must be uniformised by $\\mathbb D$.\r\n\\begin{proposition}\r\n    Any conformal automorphisms of $\\mathbb D$ is in the form\r\n    $$z\\mapsto e^{i\\theta}\\frac{z-a}{1-\\bar{a}z},a\\in\\mathbb C,\\theta\\in\\mathbb R$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Complex Analysis.\r\n\\end{proof}\r\nThis is perhaps easier to picture if we send $\\mathbb D$ to the open upper half plane $\\mathbb H$ (by the M\\\"obius transformation $z\\mapsto (1+iz)/(1-iz)$), which has automorphisms in the form $z\\mapsto (az+b)/(cz+d)$ for $a,b,c,d\\in\\mathbb R,ad-bc=1$.\r\n\\begin{definition}\r\n    A subgroup of $\\operatorname{PSL}(\\mathbb R)$ that acts properly discontinuously on $\\mathbb H$ is called a Fuchsian group.\r\n\\end{definition}", "meta": {"hexsha": "f3ba2dc5db6500e7c999d3e6aa0a2cf581775c87", "size": 4126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16/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": "16/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": "16/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": 57.3055555556, "max_line_length": 253, "alphanum_fraction": 0.679108095, "num_tokens": 1322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293653760418, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6265021342867405}}
{"text": "\\subsection{Abelian groups}\\label{subsec:abelian_groups}\n\n\\begin{definition}\\label{def:abelian_group}\n  A \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:group]{group} is usually called an \\term{abelian group}. We denote by \\( \\cat{Ab} \\) the category of abelian groups.\n\n  By \\fullref{thm:ring_is_integer_algebra}, the abelian groups are precisely the \\hyperref[def:algebra_over_ring]{rings} over \\( \\BbbZ \\), and we have an \\hyperref[rem:category_similarity/isomorphism]{isomorphism of categories} \\( \\cat{Ab} \\cong \\cat{Mod}_\\BbbZ \\).\n\\end{definition}\n\n\\begin{remark}\\label{rem:additive_magma}\n  General groups often arise as \\hyperref[def:automorphism_group]{automorphism groups}, which are, for the most part, non-commutative, while abelian groups are usually used as the main building block for \\hyperref[def:ring]{rings} and \\hyperref[def:module]{modules}.\n\n  To make a further distinction, if the operation is denoted by \\( \\cdot \\) or juxtaposition, we say that the group is a \\term{multiplicative group}, and if the operation is denoted by \\( + \\), we say that the group is an \\term{additive group}. This terminology usually, but not necessarily, coincides with the group (or, more generally, the \\hyperref[def:magma]{magma}) being \\hyperref[def:magma/commutative]{commutative}.\n\n  To make things explicit, a \\term{multiplicative magma} is any magma as defined in \\fullref{def:magma}. Compare this to \\term{additive magmas}, where\n  \\begin{thmenum}\n    \\thmitem{rem:additive_magma/addition} The magma operation is denoted by \\( + \\) and called \\term{addition}.\n\n    \\thmitem{rem:additive_magma/multiplication} The magma \\hyperref[def:magma/exponentiation]{exponentiation operation} \\( x^n \\) is denoted by \\( n \\cdot x \\) or juxtaposition and called \\term{multiplication}. Thus, multiplication is not defined for two elements of the magma, but defined for a positive integer and an element of the magma. That is,\n    \\begin{equation}\\label{eq:rem:additive_magma/multiplication}\n      \\begin{aligned}\n        &\\cdot: \\cdot: \\BbbN \\times R \\to R \\\\\n        &n \\cdot x \\coloneqq \\begin{cases}\n          0_M,           &n = 0, \\T{initial condition if} M \\T{is a monoid} \\\\\n          x,             &n = 1, \\T{initial condition if} M \\T{is not a monoid} \\\\\n          n \\cdot x + x, &n > 1 \\\\\n          -(n \\cdot x),  &n < 0, \\\\\n        \\end{cases}\n      \\end{aligned}\n    \\end{equation}\n\n    In the case of a \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:monoid]{monoid}, if multiplication is extended to two elements of the monoid, we instead talk about \\hyperref[def:semiring]{semirings}.\n\n    \\thmitem{rem:additive_magma/identity} The \\hyperref[def:monoid]{identity} is usually denoted by \\( 0 \\).\n\n    \\thmitem{rem:additive_magma/inverse} If an \\hyperref[def:monoid_inverse]{inverse} of \\( x \\) exists, it is denoted by \\( -x \\) rather than \\( x^{-1} \\).\n  \\end{thmenum}\n\\end{remark}\n\n\\begin{proposition}\\label{thm:abelian_outer_automorphism_group}\n  In an \\hyperref[def:abelian_group]{abelian group}, the full \\hyperref[def:automorphism_group]{automorphism group} \\( \\aut(G) \\) is isomorphic to the \\hyperref[def:inner_and_outer_automorphisms]{outer automorphism group} \\( \\op{out}(G) \\).\n\\end{proposition}\n\\begin{proof}\n  If the group operation is \\hyperref[def:magma/commutative]{commutative}, then \\( xyx^{-1} = yxx^{-1} = y \\), which makes the \\hyperref[def:inner_and_outer_automorphisms]{conjugation action} trivial. Thus, the \\hyperref[def:inner_and_outer_automorphisms]{inner automorphism group} \\( \\op{int}(G) \\) is trivial, and hence \\( \\aut(G) \\cong \\op{out}(G) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:abelian_normal_subgroups}\n  All subgroups of an abelian group are \\hyperref[thm:normal_subgroup_equivalences]{normal}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( G \\) be abelian and \\( H \\) be a subgroup of \\( G \\). Then \\( x H x^{-1} = xx^{-1} H = H \\) for any \\( x \\in G \\) and thus \\( H \\) is normal.\n\\end{proof}\n\n\\begin{definition}\\label{def:congruence_modulo_normal_subgroup}\n  Given a \\hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \\( N \\) of an \\hyperref[def:abelian_group]{abelian group} \\( G \\), we say that two elements \\( x \\) and \\( y \\) of \\( G \\) are \\term{congruent modulo} \\( N \\) and write \\( x \\cong y \\pmod N \\) if \\( x - y \\in N \\).\n\n  If \\( N = \\braket{ z } \\), this implies that \\( x \\cong y \\pmod z \\) if and only if \\( x - y \\in \\braket{ z } \\).\n\n  This concept also extends to \\hyperref[def:semiring_ideal]{ring ideals} rather than normal subgroups, in which case \\( \\braket{ z } \\) is the \\hyperref[def:semiring_ideal/generated]{ideal generated} by \\( z \\) rather than the \\hyperref[def:cyclic_group]{cyclic subgroup} of \\( z \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:group_of_integers_modulo}\n  The \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) form an abelian group under addition. For every positive integer \\( n \\), we define the group\n  \\begin{equation*}\n    \\BbbZ_n \\coloneqq \\set{ 0, 1, \\ldots, n - 1 }\n  \\end{equation*}\n  with the operation\n  \\begin{equation*}\n    x \\oplus y \\coloneqq \\rem(x + y, n)\n  \\end{equation*}\n  so that\n  \\begin{equation*}\n    x \\oplus y \\cong x + y \\pmod n.\n  \\end{equation*}\n\n  The group \\( \\BbbZ_n \\) is called the \\term{group of integers modulo} \\( n \\). Compare this result with \\fullref{thm:ring_of_integers_modulo}.\n\\end{proposition}\n\\begin{proof}\n  We will prove that \\( \\BbbZ_n \\) is an abelian group.\n\n  \\SubProofOf[def:magma/associative]{associativity} Addition in \\( \\BbbZ_n \\) is associative since\n  \\begin{balign*}\n    (x \\oplus y) \\oplus z\n    &=\n    \\rem((x \\oplus y) + z, n)\n    = \\\\ &=\n    \\rem(\\rem(x + y, n) + z, n)\n    = \\\\ &=\n    \\rem(x + y - n \\quot(x + y, n) + z, n)\n    = \\\\ &=\n    \\rem(x + y + z, n)\n    = \\\\ &=\n    \\ldots\n    = \\\\ &=\n    x \\oplus (y \\oplus z).\n  \\end{balign*}\n\n  \\SubProofOf[def:monoid]{identity} The zero is the identity.\n\n  \\SubProofOf[def:monoid_inverse]{inverse} Fix \\( x \\in \\BbbZ_n \\). If \\( x = 0 \\), its inverse is \\( 0 \\). If \\( x > 0 \\), its inverse is \\( n - x \\) since \\( n - x \\in \\BbbZ_n \\) and\n  \\begin{equation*}\n    x \\oplus (n - x) = x + (n - x) - n = 0.\n  \\end{equation*}\n\n  \\SubProofOf[def:magma/commutative]{commutativity} Follows from\n  \\begin{equation*}\n    x \\oplus y\n    =\n    \\rem(x + y, n)\n    =\n    \\rem(y + x, n)\n    =\n    y \\oplus x.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:integers_modulo_isomorphic_to_quotient_group}\n  The group \\( \\BbbZ_n \\) of \\hyperref[thm:group_of_integers_modulo]{integers modulo \\( n \\)} is isomorphic to the quotient of \\( \\BbbZ \\) by \\( n\\BbbZ = \\set{ nz \\given z \\in \\BbbZ } \\). That is,\n  \\begin{equation*}\n    \\BbbZ_n \\cong \\BbbZ / n\\BbbZ.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Define the function\n  \\begin{align*}\n    &\\varphi: \\BbbZ_n \\to \\BbbZ / n\\BbbZ  \\\\\n    &\\varphi(x) \\coloneqq x + n\\BbbZ.\n  \\end{align*}\n\n  It is a homomorphism because\n  \\begin{balign*}\n    \\varphi(x \\oplus y)\n    &=\n    \\varphi(\\rem(x + y, n))\n    = \\\\ &=\n    \\varphi(x + y - n \\quot(x + y, n))\n    = \\\\ &=\n    x + y - n \\quot(x + y, n) + n\\BbbZ\n    = \\\\ &=\n    x + y + n\\BbbZ\n    = \\\\ &=\n    (x + n\\BbbZ) + (y + n\\BbbZ)\n    = \\\\ &=\n    \\varphi(x) + \\varphi(y).\n  \\end{balign*}\n\n  Furthermore, this shows that \\( \\varphi \\) is also an isomorphism.\n\\end{proof}\n\n\\begin{example}\\label{ex:lagranges_theorem_for_groups/direct_product_zn}\n  \\Fullref{thm:lagranges_theorem_for_groups} and \\fullref{thm:integers_modulo_isomorphic_to_quotient_group} imply that, for any positive integer \\( n \\), \\( (nm, k) \\mapsto nm + k \\) is a bijection between \\( n \\BbbZ \\times \\BbbZ_n \\) and \\( \\BbbZ \\). This bijection, however, is not necessarily a group isomorphism because \\eqref{eq:def:magma/homomorphism} may not hold.\n\n  Consider the tuples \\( (nm_1, k_1) \\) and \\( (nm_2, k_2) \\)  in \\( n \\BbbZ \\times \\BbbZ_n \\). We have\n  \\begin{equation*}\n    (nm_1, k_1) + (nm_2, k_2) = (nm_1 + nm_2, \\rem(k_1 + k_2, n)).\n  \\end{equation*}\n\n  Therefore, if \\( k_1 + k_2 \\geq n \\),\n  \\begin{equation*}\n    nm_1 + nm_2 + \\rem(k_1 + k_2, n) < (nm_1 + k_1) + (nm_2 + k_2).\n  \\end{equation*}\n\\end{example}\n\n\\begin{proposition}\\label{thm:cyclic_group_isomorphic_to_integers_modulo_n}\n  The \\hyperref[def:cyclic_group]{cyclic group} \\( C_n \\) is isomorphic to the group \\hyperref[thm:group_of_integers_modulo]{\\( \\BbbZ_n \\)} of integers modulo \\( n \\).\n\\end{proposition}\n\\begin{proof}\n  The homomorphism\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\varphi: \\BbbZ_n \\to C_n \\\\\n      &\\varphi(k) \\coloneqq a^k,\n    \\end{aligned}\n  \\end{equation*}\n  and the analogous homomorphism for the infinite group, are isomorphisms.\n\\end{proof}\n\n\\begin{definition}\\label{def:monoid_grothendieck_completion}\\mcite{nLab:grothendieck_group_of_a_commutative_monoid}\n  Let \\( M \\) be a \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:monoid]{monoid}. Define the \\hyperref[def:equivalence_relation]{equivalence relation} \\( \\sim \\) on tuples of members of \\( M \\) to hold for \\( (a, b) \\sim (a', b') \\) if there exists an element \\( u \\) of \\( M \\) such that\n  \\begin{equation*}\n    a + b' + u = a' + b + u.\n  \\end{equation*}\n\n  Define addition on the \\hyperref[thm:equivalence_partition]{equivalence partition} \\( G \\coloneqq (M \\times M) / {\\sim }\\) componentwise as\n  \\begin{equation*}\n    [(a, b)] \\oplus [(c, d)] \\coloneqq [(a + c, b + d)]\n  \\end{equation*}\n  and fix a canonical embedding\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\iota_M: M \\to G \\\\\n      &\\iota_M(m) \\coloneqq [(m, 0)].\n    \\end{aligned}\n  \\end{equation*}\n\n  We call the obtained \\hyperref[def:abelian_group]{abelian group} \\( (G, \\oplus) \\) the \\term{Grothendieck completion} of \\( M \\).\n\\end{definition}\n\\begin{defproof}\n  \\SubProof{Proof that \\( \\sim \\) is an equivalence relation}\n  \\SubProofOf*[def:binary_relation/reflexive]{reflexivity}\n  \\begin{equation*}\n    (a, b) \\sim (a, b) \\T{if and only if} a + b + 0 = a + b + 0\n  \\end{equation*}\n\n  \\SubProofOf*[def:binary_relation/symmetric]{symmetry} By commutativity, if \\( (a, b) \\sim (a', b') \\), then there exists \\( u \\) such that\n  \\begin{equation*}\n    a + b' + u = a' + b + u\n    =\n    a' + b + u = a + b' + u,\n  \\end{equation*}\n  hence \\( (a', b') \\sim (a, b) \\).\n\n  \\SubProofOf*[def:binary_relation/transitive]{transitivity} Suppose that \\( (a, b) \\sim (a', b') \\) and \\( (a', b') \\sim (a^\\dprime, b^\\dprime) \\). Thus, there exist elements \\( u \\) and \\( b \\) of \\( M \\) such that\n  \\begin{align*}\n    a + b' + u         &= a' + b + u, \\\\\n    a' + b^\\dprime + v &= a^\\dprime + b' + v.\n  \\end{align*}\n\n  Summing both sides, we obtain\n  \\begin{equation*}\n    (a + b' + u) + (a' + b^\\dprime + v) = (a' + b + u) + (a^\\dprime + b' + v)\n  \\end{equation*}\n\n  We reorder both sides to obtain\n  \\begin{equation*}\n    (a + b^\\dprime) + (a' + b' + u + v) = (a^\\dprime + b) + (a' + b' + u + v),\n  \\end{equation*}\n  which implies \\( (a, a^\\dprime) \\sim (b, b^\\dprime) \\).\n\n  \\SubProof{Proof that \\( (G, \\oplus) \\) is an abelian group}\n\n  \\SubProof*{Proof that \\( \\oplus \\) is well-defined} The addition operation on \\( G \\) does not depend on the representative of the equivalence class. Indeed, let \\( (a, b) \\sim (a', b') \\) and \\( (c, d) \\sim (c', d') \\). Then there exist \\( u \\) and \\( b \\) such that\n  \\begin{align*}\n    a + b' + u &= a' + b + u, \\\\\n    c + d' + v &= c' + d + v.\n  \\end{align*}\n\n  When added combined, these give\n  \\begin{equation*}\n    (a + c) + (b' + d') + (u + v)\n    =\n    (a' + c') + (b + d) + (u + v),\n  \\end{equation*}\n  which implies that\n  \\begin{equation*}\n    (a + c, b + d) \\sim (a' + c', b' + d').\n  \\end{equation*}\n\n  \\SubProofOf*[def:magma/associative]{associativity} Associativity of multiplication in \\( G \\) is inherited from multiplication in \\( M \\).\n\n  \\SubProofOf*[def:monoid]{identity} The equivalence class \\( [(0, 0)] \\) is an identity in \\( G \\) and contains the pairs \\( (x, x) \\) of identical elements.\n\n  \\SubProofOf*[def:monoid_inverse]{inverse} For each member \\( (a, b) \\in M \\times M \\), its inverse is \\( (b, a) \\) because\n  \\begin{equation*}\n    [(a, b)] \\oplus [(b, a)] = [(a + b, b + c)],\n  \\end{equation*}\n  which, by commutativity, belongs to \\( [(0, 0)] \\).\n\n  \\SubProofOf*[def:magma/commutative]{commutativity} Commutativity of the group operation \\( \\oplus \\) is also inherited from the monoid operation \\( + \\).\n\\end{defproof}\n\n\\begin{theorem}[Grothendieck monoid completion universal property]\\label{thm:grothendieck_monoid_completion_universal_property}\\mcite{nLab:grothendieck_group_of_a_commutative_monoid}\n  The \\hyperref[def:monoid_grothendieck_completion]{Grothendieck completion} \\( \\overline{M} \\) of a commutative monoid \\( M \\) satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every abelian group \\( G \\) and every monoid homomorphism \\( \\varphi: M \\to G \\), there exists a unique group homomorphism \\( \\widetilde{\\varphi}: \\overline{M} \\to G \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:grothendieck_monoid_completion_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__monoid_grothendieck_completion_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  Via \\fullref{rem:universal_mapping_property}, \\( \\overline{\\anon} \\) becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{Ab} \\to \\cat{CMon}.\n  \\end{equation*}\n\n  Compare this result to \\fullref{thm:grothendieck_semiring_completion_universal_property}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( \\varphi: M \\to G \\) be a monoid homomorphism into an abelian group \\( G \\). We want to define a homomorphism \\( \\overline{\\varphi} \\) such that\n  \\begin{equation*}\n    \\overline{\\varphi}(\\iota_M(a)) = \\overline{\\varphi}([(a, 0)]) = \\varphi(a).\n  \\end{equation*}\n\n  Each equivalence class \\( C \\) in \\( G \\) has a unique member \\( a \\) such that \\( (a, 0) \\in C \\), hence the above condition is well-posed.\n\n  Fix pairs \\( (a, b) \\) and \\( (a', b') \\) from \\( M \\times M \\). Suppose that \\( (a, b) \\sim (a', b') \\). Then there exists \\( u \\in M \\) such that\n  \\begin{equation*}\n    a + b' + u = a' + b + u.\n  \\end{equation*}\n\n  An additional restriction on \\( \\overline{\\varphi} \\) is then\n  \\begin{equation*}\n    \\overline{\\varphi}\\parens[\\Big]{ [(a, b)] }\n    =\n    \\overline{\\varphi}\\parens[\\Big]{ [(a', b')] }.\n  \\end{equation*}\n\n  We need to cancel out \\( u \\). This uniquely determines \\( \\overline{\\varphi} \\) as\n  \\begin{equation*}\n    \\overline{\\varphi}([(a, b)]) \\coloneqq \\varphi(a) - \\varphi(b).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:group_commutator}\\mcite[313]{Knapp2016BasicAlgebra}\n  Let \\( G \\) be an arbitrary group. We define the \\term{commutator} of the elements \\( x \\) and \\( y \\) as\n  \\begin{equation*}\n    [x, y] \\coloneqq xyx^{-1}y^{-1}.\n  \\end{equation*}\n\n  The \\term{commutator subgroup} \\( [G, G] \\) of \\( G \\) is the subgroup \\hyperref[def:group/submodel]{generated} by all the commutators in \\( G \\).\n\\end{definition}\n\n\\begin{theorem}[Group abelianization universal property]\\label{thm:group_abelianization_universal_property}\\mcite[prop. 7.4]{Knapp2016BasicAlgebra}\n  The commutator group \\( [G, G] \\) of any group \\( G \\) is \\hyperref[thm:normal_subgroup_equivalences]{normal} and the quotient \\( G / [G, G] \\) is an abelian group, which we call the \\term{abelianization} of \\( G \\), satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every abelian group \\( H \\), every group homomorphism \\( \\varphi: G \\to H \\) \\hyperref[def:factors_through]{uniquely factors through} \\( G / [G, G] \\). That is, there exists a unique group homomorphism \\( \\widetilde{\\varphi}: G / [G, G] \\to H \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:group_abelianization_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__group_abelianization_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  Via \\fullref{rem:universal_mapping_property}, the abelianization functor becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{Ab} \\to \\cat{Grp}.\n  \\end{equation*}\n\n  This result extends to \\fullref{thm:ring_abelianization_universal_property}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( C \\coloneqq [G, G] \\).\n\n  \\SubProof{Proof that \\( G / C \\) is abelian} Normality of \\( G / C \\) easily follows from\n  \\begin{equation*}\n    a xyx^{-1}y^{-1} a^{-1}\n    =\n    (a x a^{-1}) (a y a^{-1}) (a x a^{-1})^{-1} (a y a^{-1})^{-1}.\n  \\end{equation*}\n\n  Then for the cosets \\( a C \\) and \\( b C \\), we have\n  \\begin{equation*}\n    a C \\cdot b C\n    =\n    a b C\n    =\n    a b (b^{-1} a^{-1} b a) C\n    =\n    b a C.\n  \\end{equation*}\n\n  Therefore, the quotient group \\( G / C \\) is abelian.\n\n  \\SubProof{Proof of universal mapping property} Let \\( H \\) be an abelian group and let \\( \\varphi: G \\to H \\) be a group homomorphism.\n\n  Observe that \\( \\varphi(C) = e_H \\). Indeed, since \\( H \\) is abelian, for \\( [x, y] = xyx^{-1}y^{-1} \\in C \\) we have\n  \\begin{equation*}\n    \\varphi([x, y]) = \\varphi(x) \\varphi(y) \\varphi(x^{-1}) \\varphi(y^{-1}) = \\varphi(x) \\varphi(x^{-1}) \\varphi(y) \\varphi(y^{-1}).\n  \\end{equation*}\n\n  We want \\( \\overline{\\varphi}: G / C \\to H \\) to satisfy\n  \\begin{equation*}\n    \\overline{\\varphi}(\\underbrace{\\pi_G(x)}_{xC}) = \\varphi(x).\n  \\end{equation*}\n\n  This suggests the definition\n  \\begin{equation*}\n    \\overline{\\varphi}(xC) \\coloneqq \\varphi(x).\n  \\end{equation*}\n\n  It is well-defined because if \\( xC = yC \\), we have\n  \\begin{equation*}\n    \\varphi(x)\n    =\n    \\varphi(x) e_H\n    =\n    \\varphi(x) \\varphi(C)\n    =\n    \\varphi(x C)\n    =\n    \\varphi(y C)\n    =\n    \\ldots\n    =\n    \\varphi(y).\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "0c98e32035c42df0c000625a05a5fbd04f5fda4a", "size": 18014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/abelian_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/abelian_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/abelian_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": 46.3084832905, "max_line_length": 423, "alphanum_fraction": 0.6455534584, "num_tokens": 6266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834649, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6265021263051535}}
{"text": "\\chapter{DC Circuit Analysis}\n\nIn the most basic circuit, you have only a battery and a resistor:\n\n\\includegraphics[width=0.8\\textwidth]{DC_Circuit_Diagram.png}\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$6V$] ++(0,3)\nto ++(3,0)\nto [R=$3\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i=2A] ++(0,-3) -- (0,0);\n\\end{circuitikz}\n\nIn this case, you only need Ohm's Law: $V = I R$.  In this case, $6V = 3\\Omega \\times 2A$.\n% ADD: Define Ohm's Law\n\\begin{Exercise}[title={Ohm's Law}, label=ohms_check]\n\n  How many amps are going around the circuit?\n  \n  \\vspace{1cm}\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$24V$] ++(0,3)\nto ++(3,0)\nto [R=$6\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i={? A}] ++(0,-3) -- (0,0);\n\\end{circuitikz}\n\n  \n\\end{Exercise}\n\\begin{Answer}[ref=ohms_check]\n\n  $V = I R$ so $I = \\frac{V}{R} = \\frac{24V}{6\\Omega} = 4A$.\n  \n\\end{Answer}\n% KA: https://youtu.be/F_vLWkkOETI\n\n\\section{Resistors in Series}\n\nWhen you have two resistors wired together in a long line, we say they\nare ``in series''.  If you have two resistors $R_1$ and $R_2$ wired in\nseries, the total resistance is $R_1 + R_2$.\n\nIn this diagram, for example, the total resistance is $5\\Omega$.\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$10V$] ++(0,5)\nto ++(3,0)\nto [R=$3\\Omega$] ++(0,-2.5)\nto [R=$2\\Omega$] ++(0,-2.5) -- (0,0);\n\\end{circuitikz}\n\nThe current flowing through the circuit, then, is $10/4 = 2A$.\n\nBy Ohm's law, the voltage drop across the upper resistor is $I R = 2A \\times 3\\Omega = 6V$.\n\nThe voltage drop across the lower resistor is $I R = 2A \\times 2\\Omega = 4V$.\n\nNotice that the battery pumps the voltage up to $10V$, then the two\nresistors drop it by exactly $10V$. This is known as ``Kirchhoff's\nVoltage Law'':\n% KA: https://youtu.be/4rsswT_Rv1M\n\n\\begin{mdframed}[style=important, frametitle={Kirchhoff's Voltage Law}]\\index{Kirchhoff's voltage law}\nAs you make a loop around a circuit, the sum of the voltage increase\nmust equal the sum of the voltage decrease.\n\\end{mdframed}\n\nThe negative end of the battery as connected to ``ground'' (\nit has zero voltage), then we can draw a diagram with the\nvoltages(That symbol in the lower right represents a connection to ground).\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$6V$] ++(0,5) \nto [-*] ++(3,0) node[anchor=west] {10V}\nto [R=$3\\Omega$,-*] ++(0,-2.5) node[anchor=west] {4V}\nto [R=$2\\Omega$,-*] ++(0,-2.5) node[anchor=west]{0V} node[ground]{} --(0,0);\n\\end{circuitikz}\n\n\n\\begin{Exercise}[title={Resistors In Series}, label=series_resistor]\n\n  What is the current going around the circuit?\n  \n  What is the voltage drop across each resistor?\n  \n  \\vspace{1cm}\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$16V$] ++(0,5) \nto [-*] ++(3,0) node[anchor=west] {16V}\nto [R=$5\\Omega$,-*] ++(0,-2.5) node[anchor=west] {?}\nto [R=$3\\Omega$,-*] ++(0,-2.5) node[anchor=west]{0V} node[ground]{} --(0,0);\n\\end{circuitikz}\n\n\n\\end{Exercise}\n\\begin{Answer}[ref=series_resistors]\n\n  There is a total resistance of $8\\Omega$, so your 16V will push 2A\n  of current around the circuit.\n\n  2A going through a $5\\Omega$ resistor represents a 10V drop.\n\n  2A going through a $3\\Omega$ resitor represents a 6V drop.\n  \n\\end{Answer}\n\n\n\\section{Resistors in Parallel}\n\nLook at this circuit. Note that the current can go two different paths.\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$12V$] ++(0,3)\nto ++(3,0)\nto [R=$2\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm] ++(0,-3) -- (0,0);\n\\draw (3,3) -- (5,3)\nto [R=$3\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm] ++(0,-3) -- (3,0);\n\\end{circuitikz}\n\nThere is 12 volts pushing current through both resistors. So 6A will\ngo through the 2$\\Omega$ resistor and 4A will go through the 3$\\Omega$\nresistor.\n\n\\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$12V$] ++(0,3)\nto ++(3,0)\nto [R=$2\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i=6A] ++(0,-3) -- (0,0);\n\\draw (3,3) -- (5,3)\nto [R=$3\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i=4A] ++(0,-3) -- (3,0);\n\\end{circuitikz}\n\nThus, a total of 10 A will be going through the battery.\n\nImagine you are a battery. You can't see that you have two resistors.\nWhat does it feel like to you? $\\frac{V}{I} = R$, and $V= 12$ and $I =\n10$.  So the effective resistance of the two resistors in parallel is\n$\\frac{12}{10}$ or $\\frac{6}{5} \\Omega$.\n\n\\begin{mdframed}[style=important, frametitle={Resistance in Parallel}]\\index{resistance!in parallel}\nIf you have several resistances $R_1, R_2, \\ldots, R_n$ wired in\nparallel, their effective resistance $R_t$ is given by\n\n$$\\frac{1}{R_t} = \\frac{1}{R_1} + \\frac{1}{R_2} + \\ldots + \\frac{1}{R_n}$$\n\n\\end{mdframed}\n\nIn our example:\n\n$$\\frac{1}{R_t} = \\frac{1}{2} + \\frac{1}{3} = \\frac{5}{6}$$\n\nThus $R_t =  \\frac{6}{5}\\Omega$.\n\n\\begin{Exercise}[title={Resistors In Parallel}, label=parallel_resistors]\n\n  What is the current going through the battery?\n  What is the drop over the $4\\Omega$ resistor?\n  What is the current in each branch?\n\n  \\vspace{1cm}\n\n  \\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$12V$] ++(0,3)\nto [R=$4\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm] ++(3,0) node [yshift=0.3cm] {? V}\nto [R=$6\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i={? A}] ++(0,-3) node[ground]{} -- (0,0);\n\\draw (3,3) -- (5,3)\nto [R=$3\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i={? A}] ++(0,-3) -- (3,0);\n\\end{circuitikz}\n\n\\end{Exercise}\n\\begin{Answer}[ref=parallel_resistors]\n  The effective resistance of the $6\\Omega$ and the $3\\Omega$ is $2\\Omega$ because \n\n  $$\\frac{1}{R_T} = \\frac{1}{6} + \\frac{1}{3} == \\frac{1}{2}$$\n\n  So the battery experiences a resistance of $4\\Omega + 2\\Omega =\n  6\\Omega$.  A $12V$ will push 2A through a resistance of $6\\Omega$.\n\n  The voltage drop across the $4\\Omega$ resistor is $2A \\times 4\\Omega\n  = 8V$. Thus there will be a 4V drop across the two resistors in\n  parallel.  So 2/3 A will flow through the $6\\Omega$ resistor. 4/3 A\n  will flow through the $3\\Omega$ resistor.\n\n    \\begin{circuitikz}\n\\draw (0,0) to[battery1,invert,l=$12V$] ++(0,3)\nto [R=$4\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm] ++(3,0) node [yshift=0.3cm] {8 V}\nto [R=$6\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i={2/3 A}] ++(0,-3) node[ground]{}-- (0,0);\n\\draw (3,3) -- (5,3)\nto [R=$3\\Omega$, /tikz/circuitikz/bipoles/length=1.0cm,i={4/3 A}] ++(0,-3) -- (3,0);\n\\end{circuitikz}\n  \n\\end{Answer}\n\n", "meta": {"hexsha": "2c323cfec732145f8f9962c36b0e50f47c2a6e5c", "size": 6347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/dc_circuits-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/MatterEnergy/dc_circuits-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/MatterEnergy/dc_circuits-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": 33.0572916667, "max_line_length": 102, "alphanum_fraction": 0.6623601702, "num_tokens": 2487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6265021204504156}}
{"text": "\\documentclass{report}\n\\def\\MLine#1{\\par\\hspace*{-\\leftmargin}\\parbox{\\textwidth}{\\[#1\\]}}\n\\usepackage{amsmath}\n\\begin{document}\n\nBook: Basic Mathematics\nAuthor: Serge Lang\n\n\\tableofcontents{}\n\n\\chapter{Numbers}\n\n\\section{The Integers}\nNo exercises in this section.\n\n\\section{Rules for Addition}\nJustify each step, using commutativity and associativity in proving the following identities.\n\n\\begin{enumerate}\n    \\item (a + b) + (c + d) = (a + d) + (b + c)\n    \\item (a + b) + (c + d) = (a + c) + (b + d)\n    \\item (a - b) + (c - d) = (a + c) + (- b - d)\n    \\item (a - b) + (c - d) = (a + c) - (b + d)\n    \\item (a - b) + (c - d) = (a + d) - (c - b)\n    \\item (a - b) + (c - d) = -(b + d) + (a + c)\n    \\item (a - b) + (c - d) = -(b + d) - (-a - c)\n    \\item ((x + y) + z) + w = (x + z) + (y + w)\n    \\item (x - y) - (z - w) = (x + w) - y + z\n    \\item (x - y) - (z - w) = (x - z) - (w - y)\n    \\item Show that - (a + b + c) = -a + (-b) + (-c).\n    \\item Show that -(a -b - c) = -a + b + c.\n    \\item Show that -(a - b) = b - a.\n    \\item[] Solve for x in the following equations.\n    \\item -2 + x = 4\n    \\item 2 - x = 5\n    \\item x - 3 = 7\n    \\item -x + 4 = 1\n    \\item 4 - x = 8\n    \\item -5 - x = -2\n    \\item -7 + x = -10\n    \\item -3 + x = 4\n    \\item Prove the \\textbf{cancellation law for addition:}\n\t    \\MLine{\\textnormal{If } a + b = a + c, \\textnormal{then } b = c}\n    \\item Prove: If a + b = a, then b = 0\n\\end{enumerate}\n\n\\section{Rules for Multiplication}\n\n\\begin{enumerate}\n\t\\item Express each of the following expressions in the form $2^m3^na^rb^s$, where $m$, $n$, $r$, $s$ are positve integers.\n\t\t\\begin{enumerate}\n\t\t\t\\item $8a^2b^3(27a^4)(2^5ab)$\n\t\t\t\\item $16b^3a^2(6ab^4)(ab)^3$\n\t\t\t\\item $3^2(2ab)^3(16a^2b^5)(24b^2a)$\n\t\t\t\\item $24a^3(1ab^2)^3(3ab)^2$\n\t\t\t\\item $(3ab)^2(27a^3b)(16ab^5)$\n\t\t\t\\item $32a^4b^5a^3b^2(6ab^3)^4$\n\t\t\\end{enumerate}\n\t\\item Prove:\n\t\t\\MLine{(a + b)^3 = a^3 + 3a^2b + 3ab^2 + b^3}\n\t\t\\MLine{(a - b)^3 = a^3 - 3a^2b + 3ab^2 - b^3}\n\t\\item Obtain expansion for $(a + b)^4$ and $(a - b)^4$ similar to the expansions for $(a + b)^3$ and $(a - b)^3$ of the preceding exercise.\n\t\\item[] Expand the following expressions as sums of powers of $x$ multiplied by integers.\n\t\\item $(2 - 4x)^2$\n\t\\item $(1 - 2x)^2$\n\t\\item $(2x + 5)^2$\n\t\\item $(x-1)^2$\n\t\\item $(x + 1)(x-1)$\n\t\\item $(2x + 1)(x + 5)$\n\t\\item $(x^2 + 1)(x^2 - 1)$\n\t\\item $(1 + x^3)(1 - x^3)$\n\t\\item $(x^2 + 1)^2$\n\t\\item $(x^2 - 1)^2$\n\t\\item $(x^2 + 2)^2$\n\t\\item $(x^2 - 2)^2$\n\t\\item $(x^2 - 4)^2$\n\t\\item $(x^3 - 4)(x^3 + 4)$\n\t\\item $(2x^2 + 1)(2x^2 - 1)$\n\t\\item $(-2 + 3x)(-2 - 3x)$\n\t\\item $(x + 1)(2x + 5)(x-2)$\n\t\\item $(2x + 1)(1 - x)(3x + 2)$\n\t\\item $(3x -1)(2x + 1)(x + 4)$\n\t\\item $(-1 -x)(-2 + x)(1 - 2x)$\n\t\\item $(-4x + 1)(2 - x)(3 + x)$\n\t\\item $(1 -  x)(1 + x)(2 - x)$\n\t\\item $(x - 1)^2(3 - x)$\n\t\\item $(1 - x)^2(2-x)$\n\t\\item $(1 - 2x)^2(3 + 4x)$\n\t\\item $(2x + 1)^2(2 - 3x)$\n\t\\item The population of a city in 1910 was 50,000, and it doubles every 10 years. What will it be (a) in 1970 (b) in 1990 (c) in 2000?\n\t\\item The population of a city in 1905 was 100,00 and it doubles every 25 years. What will it be after (a) 50 years (b) 100 years (c) 150 years?\n\t\\item The population of a city was 200 thousand in 1915, and it triples every 50 years. What will be the population:\n\t\t\\begin{enumerate}\n\t\t\t\\item in the year 2215?\n\t\t\t\\item in the year 2165?\n\t\t\\end{enumerate}\n\t\\item The population of a city was 25,000 in 1870, and it triples every 40 years. What will it be:\n\t\t\\begin{enumerate}\n\t\t\t\\item in 1990?\n\t\t\t\\item in 2030?\n\t\t\\end{enumerate}\n\\end{enumerate}\n\n\\section{Even and Odd Integers; Divisibility}\n\\begin{enumerate}\n\t\\item Give the proofs for the cases of Theorem 1 which were not proved in the text.\n\t\\item Prove: If $a$ is even and $b$ is any positive integer, then $ab$ is even.\n\t\\item Prove: If $a$ is even, then $a^3$ is even.\n\t\\item Prove: If $a$ is odd, then $a^3$ is odd.\n\t\\item Prove: if $n$ is even, then $(-1)^n = -1$.\n\t\\item Prove: if $n$ is odd, then $(-1)^n = -1$.\n\t\\item Prove: if $m$, $n$ are odd, then the product $mn$ is odd.\n\t\\item[] Find the largest power of 2 which divides the following integers.\n\t\\item 16\n\t\\item 24 \n\t\\item 32\n\t\\item 20\n\t\\item 50\n\t\\item 64\n\t\\item 100\n\t\\item 36\n\t\\item[] Find the largest power of 3 which divides the following integers.\n\t\\item 30 \n\t\\item 27\n\t\\item 63\n\t\\item 99\n\t\\item 60\n\t\\item 50\n\t\\item 42\n\t\\item 25\n\t\\item Let $a$, $b$ be integers. Define $a \\equiv b (\\textnormal{mod } 5)$, which we read\n\t\t``$a$ is \\textbf{congruent to} $b$ \\textbf{modulo} 5'', to mean that\n\t\t$a - b$ is divisible by 5. Prove: if $a \\equiv b (\\textnormal{mod } 5)$ and $x \\equiv y (\\textnormal{mod } 5)$, then\n\t\t\\MLine{a + x \\equiv b + y (\\textnormal{mod } 5)}\n\t\tand\n\t\t\\MLine{ax \\equiv by (\\textnormal{mod } 5)}\n\t\\item Let $d$ be a positive integer. Let $a$, $b$ be integers. Define\n\t\t\\MLine{a \\equiv b (\\textnormal{mod } d)}\n\t\tto mean that $a - b$ is divisible by $d$. Prove that if $a \\equiv b (\\textnormal{mod } d)$ and $x \\equiv y (\\textnormal{mod } d)$, then\n\t\t\\MLine{a + x \\equiv b + y (\\textnormal{mod } d)}\n\t\tand\n\t\t\\MLine{ax \\equiv by (\\textnormal{mod } d)}\n\t\\item Assume that every positive integer can be written in one of the forms $3k$, $3k + 1$, $3k + 2$ for some integer $k$.\n\t\tShow that if the square of a positive integer is divisible by 3, then so is the integer.\n\\end{enumerate}\n\n\\section{Rational Numbers}\n\\begin{enumerate}\n\t\\item Solve for $a$ in the following equations.\n\t\t\\begin{enumerate}\n\t\t\t\\item $2a = \\dfrac{3}{4}$\n\t\t\t\\item $\\dfrac{3a}{5} = -7$\n\t\t\t\\item $\\dfrac{-5a}{2} = \\dfrac{3}{8}$\n\t\t\\end{enumerate}\n\t\\item Solve for $x$ in the following equations.\n\t\t\\begin{enumerate}\n\t\t\t\\item $3x - 5 = 0$\n\t\t\t\\item $-2x + 6 = 1$\n\t\t\t\\item $-7x = 2$\n\t\t\\end{enumerate}\n\t\\item Put the following fractions in the lowest form.\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\dfrac{10}{25} $\n\t\t\t\\item $\\dfrac{3}{9}$\n\t\t\t\\item $\\dfrac{30}{25}$\n\t\t\t\\item $\\dfrac{50}{15}$\n\t\t\t\\item $\\dfrac{45}{9}$\n\t\t\t\\item $\\dfrac{62}{4}$\n\t\t\t\\item $\\dfrac{23}{46}$\n\t\t\t\\item $\\dfrac{16}{40}$\n\t\t\\end{enumerate}\n\\end{enumerate}\n\n\\end{document}\n\n\n\n", "meta": {"hexsha": "050fa236e9dc55723ab61882d1a9ad4f62d192d8", "size": 6049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basic_mathematics_serge_lang/exercises.tex", "max_stars_repo_name": "llulai/math_book_solutions", "max_stars_repo_head_hexsha": "c052b46031ca7cb8f8a34078f67a3eaa9c67298c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-05T20:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-05T20:00:45.000Z", "max_issues_repo_path": "basic_mathematics_serge_lang/exercises.tex", "max_issues_repo_name": "llulai/math_book_solutions", "max_issues_repo_head_hexsha": "c052b46031ca7cb8f8a34078f67a3eaa9c67298c", "max_issues_repo_licenses": ["MIT"], "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_mathematics_serge_lang/exercises.tex", "max_forks_repo_name": "llulai/math_book_solutions", "max_forks_repo_head_hexsha": "c052b46031ca7cb8f8a34078f67a3eaa9c67298c", "max_forks_repo_licenses": ["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.9831460674, "max_line_length": 145, "alphanum_fraction": 0.5714994214, "num_tokens": 2585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6265021204504156}}
{"text": "Clustering is a basic tool of exploratory data analysis. There are a variety of efficient algorithms---including $k$-means, EM for Gaussian mixtures, and hierarchical agglomerative schemes---that are widely used for discovering ``natural'' groups in data. Unfortunately, they don't always find a grouping that suits the user's needs.\n\nThis is inevitable. In any moderately complex data set, there are many different plausible grouping criteria. Should a collection of rocks be grouped according to value, or shininess, or geological properties? Should animal pictures be grouped according to the Linnaean taxonomy, or cuteness? Different users have different priorities, and an unsupervised algorithm has no way to magically guess these.\n\nAs a result, a rich body of work on {\\it constrained} clustering has emerged.\nIn this setting, a user supplies guidance, typically in the form of ``must-link'' or ``cannot-link'' constraints, pairs of points that must be placed together or apart. Introduced by \\citet{Wagstaff2001}, these constraints have since been incorporated into many different {\\it flat} clustering procedures~\\citep{Wagstaff2000,Bansal2004,Basu2004,Kulis2009,Biswas2014}.\n\nIn this chapter, we introduce constraints to {\\it hierarchical clustering}, the recursive partitioning of a data set into successively smaller clusters to form a tree. A hierarchy has several advantages over a flat clustering. First, there is no need to specify the number of clusters in advance. Second, the tree captures cluster structure at multiple levels of granularity, simultaneously. As such, trees are particularly well-suited for exploratory data analysis and the discovery of natural groups.\n\nThere are several well-established methods for hierarchical clustering, the most prominent among which are the bottom-up agglomerative methods such as average linkage (see, for instance, Chapter 14 of \\citet{Hastie2009}). But they suffer from the same problem of under-specification that is the scourge of unsupervised learning in general. And, despite the rich literature on incorporating additional guidance into flat clustering, there has been relatively little work on the hierarchical case.\n\nWhat form might the user's guidance take? The usual must-link and cannot-link constraints make little sense when data has hierarchical structure. Among living creatures, for instance, should {\\tt elephant} and {\\tt tiger} be linked? At some level, yes, but at a finer level, no. A more straightforward assertion is that {\\tt elephant} and {\\tt tiger} should be linked in a cluster that does not include {\\tt snake}. We can write this as a {\\it triplet} $(\\{\\mbox{\\tt elephant}, \\mbox{\\tt tiger}\\}, \\mbox{\\tt snake})$. We could also assert $(\\{\\mbox{\\tt tiger}, \\mbox{\\tt leopard}\\}, \\mbox{\\tt elephant})$. Formally, $(\\{a,b\\},c)$ stipulates that the hierarchy contains a subtree (that is, a cluster) containing $a$ and $b$ but not $c$.\n\nA wealth of research addresses learning taxonomies from triplets {\\it alone}, mostly in the field of phylogenetics: see \\citet{Felsenstein2004} for an overview, and \\citet{Aho1981} for a central algorithmic result. Let's say there are $\\numdata$ data items to be clustered, and that the user seeks a particular hierarchy $\\tree^*$ on these items. This $\\tree^*$ embodies at most ${\\numdata \\choose 3}$ triplet constraints, possibly less if it is not binary. It was pointed out in \\citet{Tamuz2011} that roughly $\\numdata \\log \\numdata$ carefully-chosen triplets are enough to fully specify $\\tree^*$ if it is balanced. This is also a lower bound: there are $\\numdata^{\\Omega(\\numdata)}$ different labeled rooted trees, so each tree requires $\\Omega(\\numdata \\log \\numdata)$ bits, on average, to write down---and each triple provides $O(1)$ bits of information, since there are just three possible outcomes for each set of points $a,b,c$. Although $\\numdata \\log \\numdata$ is a big improvement over $\\numdata^3$, it is impractical for a user to provide this much guidance when the number of points is large. In such cases, a hierarchical clustering cannot be obtained on the basis of constraints alone; the geometry of the data must play a role.\n\nWe consider an interactive process during which a user incrementally adds constraints.\n\\begin{itemize}\n\\item Starting with a pool of data $\\data \\subseteq \\R^\\d$, the machine builds a candidate hierarchy $\\tree$.\n\\item The set of constraints $C$ is initially empty.\n\\item Repeat:\n\\begin{itemize}\n\\item The machine presents the user with a small portion of $\\tree$: specifically, its restriction to $O(1)$ leaves $S \\subset X$. We denote this $\\tree|_S$.\n\\item The user either accepts $\\tree|_S$, or provides a triplet constraint $(\\{a,b\\},c)$ that is violated by it.\n\\item If a triplet is provided, the machine adds it to $C$ and modifies the tree $T$ accordingly.\n\\end{itemize}\n\\end{itemize}\nIn realizing this scheme, a suitable clustering algorithm and querying strategy must be designed. Similar issues have been confronted in flat clustering---with must-link and cannot-link constraints---but the solutions are unsuitable for hierarchies, and thus a fresh treatment is warranted.\n\n\\textbf{The clustering algorithm:}\nWhat is a method of hierarchical clustering that takes into account the geometry of the data points as well as user-imposed constraints? \n\nWe adopt an \\emph{interactive Bayesian} approach. The learning procedure is uncertain about the intended tree and this uncertainty is captured in the form of a distribution over all possible trees. Initially, this distribution is informed solely by the geometry of the data but once interaction begins, it is also shaped by the growing set of constraints.\n\nThe nonparametric Bayes literature contains a variety of different distributional models for hierarchical clustering. We describe a general methodology for extending these to incorporate user-specified constraints. For concreteness, we focus on the Dirichlet diffusion tree~\\citep{Neal2003}, which has enjoyed empirical success. We show that triplet constraints are quite easily accommodated: when using a Metropolis-Hastings sampler, they can efficiently be enforced, and the state space remains strongly connected, assuring convergence to the unique stationary distribution.\n\n\\textbf{The querying strategy:}\nWhat is a good way to select the subsets $S$? A simple option is to pick them at random from $\\data$. We show that this strategy leads to convergence to the target tree $\\tree^*$. Along the way, we define a suitable distance function for measuring how close $\\tree$ is to $\\tree^*$. \n\n%This allows us to give a simple rule for when to stop querying if we seek a tree $\\epsilon$-close to the target.\n\nWe might hope, however, that a more careful choice of $S$ would lead to faster convergence, in much the same way that intelligent querying is often superior to random querying in active learning. In order to do this, we show how the Bayesian framework allows us to quantify which portions of the tree are the most uncertain, and thereby to pick $S$ that focuses on these regions.\n\nQuerying based on uncertainty sounds promising, but is dangerous because it is heavily influenced by the choice of prior, which is ultimately quite arbitrary. Indeed, if only such queries were used, the interactive learning process could easily converge to the wrong tree. We show how to avoid this situation by interleaving the two types of queries.\n\nFinally, we present a series of experiments that illustrate how a little interaction leads to significantly better hierarchical clusterings.\n\n\n\\subsection*{Other related work}\n\nA related problem that has been studied in more detail~\\citep{Zoller2000,Eriksson2011,Krishnamurthy2012} is that of building a hierarchical clustering where the only information available is pairwise similarities between points, but these are initially hidden and must be individually queried.\n\nIn another variant of interactive flat clustering~\\citep{Balcan2008,Awasthi2010,Awasthi2013}, the user is allowed to specify that individual clusters be merged or split. A succession of such operations can always lead to a target clustering, and a question of interest is how quickly this convergence can be achieved.\n\nFinally, it is worth mentioning the use of triplet constraints in learning other structures, such as Euclidean embeddings~\\citep{Borg1997}.\n\n\\iffalse\n\\section{Bayesian hierarchical clustering}\n%\\subsection{Priors on trees}\n\n\\fi\n\\section{Adding interaction}\n\nImpressive as Bayesian nonparametric hierarchical clustering is, there is no reason to suppose that it will magically find a tree that suits the user's needs. But a little interaction can be helpful in improving the outcome.\n\nLet $\\tree^*$ denote the target hierarchical clustering. It is not necessarily the case that the user would be able to write this down explicitly, but this is the tree that captures the distinctions he/she is able to make, or wants to make. Figure~\\ref{fig:refinement} (left) shows an example, for a small data set of 5 points. In this case, the user does not wish to distinguish between points $1,2,3$, but does wish to place them in a cluster that excludes point $4$.\n\nWe could posit our goal as exactly recovering $\\tree^*$. But in many cases, it is good enough to find a tree that captures all the distinctions within $\\tree^*$ but also possibly has some extraneous distinctions, as in the right-hand side of Figure~\\ref{fig:refinement}.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=3in]{img/ibhc/refinement.pdf}\n    \\caption{Target tree $T^*$ (left) and a refinement of it.}\n    \\label{fig:refinement}\n\\end{figure}\n\nFormally, given data set $\\data$, we say $S \\subseteq \\data$ is a {\\it cluster} of tree $\\tree$ if there is some node of $\\tree$ whose descendant leaves are exactly $S$. We say $\\tree$ is a {\\it refinement} of $\\tree^*$ if they have the same set of leaves, and moreover every cluster of $\\tree^*$ is also a cluster of $\\tree$. This, then, is our goal: to find a refinement of the target clustering $\\tree^*$.\n\n\\subsection{Triplets}\n\nThe user provides feedback in the form of triplets. The constraint $(\\{a,b\\},c)$ means that the tree should have a cluster containing $a$ and $b$ but not $c$. Put differently, the lowest common ancestor of $a,b$ should be a strict descendant of the lowest common ancestor of $a,b,c$.\n\nLet $\\Delta(\\tree)$ denote the set of all proper triplet constraints embodied in tree $\\tree$. If $\\tree$ has $n$ nodes, then $|\\Delta(\\tree)| \\leq {n \\choose 3}$. For non-binary trees, it will be smaller than this number. Figure~\\ref{fig:refinement} (left), for instance, has no triplet involving $1,2,3$. \n\nRefinement can be characterized in terms of triplets.\n\\begin{restatable}{lemma}{treerefinement}\n\\label{thm:treerefinement}\nTree $\\tree$ is a refinement of tree $\\tree'$ if and only if $\\Delta(\\tree') \\subseteq \\Delta(\\tree)$.\n\\end{restatable}\n\\begin{proof}\nSee \\autoref{chap:ibhc-appendix}.\n\\end{proof}\nIn particular, {\\it any triplet-querying scheme that converges to the full set of triplets of the target tree $\\tree^*$ is also guaranteed to produce trees that converge to a refinement of $\\tree^*$.}\n\nWith this lemma in mind, it is natural to measure how close a tree $\\tree$ is to the target $\\tree^*$ with the following (asymmetric) distance function, which we call {\\it triplet distance} (TD):\n\n%\\subsection{Triplet Distance}\n%To better understand the performance of clustering algorithm\n%and the various triplet querying schemes,\n%we first define a distance function between\n%a candidate tree and the desired tree.\n\n%$T$ is defined to be a \\emph{refinement} of $T^*$ if\n%if every cluster of $T^*$ is in $T$.\n%In the general setting, $T^*$ may be a $k$-ary tree\n%and our algorithm only produces a binary tree. \n%For example, in a $K$-way classification problem, the desired\n%tree $T^*$ would be a root node with $K$ children corresponding to %each class. \n%Each of these $K$ children would have all data belonging to its class %as\n%a child. See \\autoref{fig:kway} for an example. \n\n%If a binary tree $T$ is a refinement of $T^*$ in the $K$-way\n%classification problem,\n%there exist nodes in $T$ that contain\n%solely the data for each class and this is the closest binary tree we\n%can obtain.\n%Thus, we desire a distance function such that if $T$ is a refinement\n%of $T^*$, their distance should be 0.\n\n%\\begin{figure}[H]\n%    \\centering\n%    \\includegraphics[width=0.5\\textwidth]{img/ibhc/KWayTree}\n%    \\caption{A 4-way classification tree on the left\n%    and a refinement of it on the right. Nodes\n%    with matching colors represent matching clusters.}\n%    \\label{fig:kway}\n%\\end{figure}\n\n%Let $\\mathcal{C}(T)$ be the enumeration of all triplets\n%satisfied by tree $T$.\n%For a given desired \\emph{master tree} $T^*$\n%the triplet distance (TD) between $T^*$ and a candidate tree $T$\n%is\n\n\\begin{align}\n    \\mathrm{TD}(\\tree^*, \\tree) = \\frac{\\sum_{c \\in \\Delta(\\tree^*)} \\mathbb{I}(c \\notin \\Delta(\\tree)) }{|\\Delta(\\tree^*)|}\n\\end{align}\nwhere $\\mathbb{I}$ is the indicator function.\n% Lemma\n%If $T$ is a refinement of $T^*$, their triplet distance is zero\n%as $\\mathcal{C}(T^*) \\subseteq \\mathcal{C}(T)$.\nThis distance is zero exactly when $\\tree$ is a refinement of $\\tree^*$, in which case we have reached our goal. \n\n%User guidance can assist in under-specified\n%unsupervised learning problems. We now\n%provide a concrete means of obtaining \n%information about hierarchical structure in data\n%from a user, in the form of \\emph{triplet feedback}.\n\n%For hierarchies, a triplet is a set of data\n%of the form $(\\{a, b\\}, c)$, such that\n%$a$ and $b$ should belong in a subtree\n%together without $c$. Let $\\text{lca}(u, v)$ be\n%the lowest common ancestor of nodes $u$ and $v$. \n%Formally, we can verify that a tree satisfies a triplet\n%$(\\{a, b\\}, c)$ if $\\text{lca}(a, b)$ is a descendant\n%of both $\\text{lca}(a, c)$ and $\\text{lca}(b, c)$.\n\nA simple strategy for obtaining triplets \nwould be to present the user with three randomly\nchosen data points and have the user pick the odd one out.\nThis strategy has several drawbacks.\nFirst, some sets of three points have no triplet constraint \n(for instance, points $1,2,3$ in \\autoref{fig:refinement}).\nSecond, the chosen set of points might correspond to a triplet\nthat has already been specified, or is {\\it implied} by \nspecified triplets. For example, knowledge of $(\\{a, b\\}, c)$ and\n$(\\{b, c\\}, d)$ implies $(\\{a, c\\}, d)$.\nEnumerating the set of implied\ntriplets is non-trivial for $n > 3$ triplets~\\citep{Bryant1995},\nmaking it difficult to avoid these implied triplets\nin the first place.\n\nWe thus consider another strategy---rather\nthan the user arranging three data points into\na triplet, the user observes\nthe hierarchy induced over some $O(1)$-sized\nsubset $S$ of the data and corrects\nan error in the tree by supplying a triplet.\nWe call this is a \\emph{subtree query}.\nFinally, we note that in this work\nwe only consider the \\emph{realizable} case\nwhere the triplets obtained\nfrom a user do not contain contradictory information\nand that there is a tree that satisfies\nall of them.\n\n%\\subsection{Triplet feedback on subtrees}\n%The interactive process integrates\n%user feedback into a hierarchy\n%after querying the user for a triplet.\n%We perform this query by\n%showing a user the subtree\n%over a particular subset of data\n%and ask to either\n%accept the subtree as correct, or\n%report a triplet that is violated by\n%the subtree.\n%\n%Formally, given a candidate hierarchy $T$\n%that satisfies a set of triplets $C$ ,\n%we first obtain some $O(1)$ size\n%subset of the dataset  $S \\subset X$,\n%and find the induced subtree\n%$T|_S$.\n%$T|_S$ is shown to a user whereupon\n%the user can either accept the tree,\n%acknowledging that there are no errors in its\n%structure, or report a triplet\n%$(\\{a, b\\}, c)$ that is violated by this subtree.\n\n%This approach confers several benefits over\n%the simple approach of selecting three points\n%at random. Subtree queries have the benefit\n%of never returning a triplet \n%implied by $C$. A tree that satisfies $C$\n%will by definition will satisfy all of $C$'s\n%implied triplets. \n%In addition,\n%the triplet reported by the user\n%is likely to be more informative\n%as the triplet corresponds to an \n%error in a candidate hierarchy.\n%However, this method assumes\n%the existence of an algorithm\n%that can produce candidate trees\n%that satisfy $C$.\n\n\\subsection{Finding a tree consistent with constraints}\n\\label{sec:aho}\nWe start with a randomly initialized hierarchy $\\tree$\nover our data\nand show an induced subtree $\\tree|_S$ to the user, obtaining the\nfirst triplet. The next step is constructing  \na new tree that satisfies the triplet.\nThis begins the feedback cycle; a user provides a triplet\ngiven a subtree and the triplet is incorporated into a clustering algorithm,\nproducing a new candidate tree.\nA starting point is \nan algorithm that returns \na tree consistent with a set of triplets.\n\nThe simplest algorithm to solve this problem is\nthe \\texttt{BUILD} algorithm, introduced in \\citet{Aho1981}.\nGiven a set of triplets $C$, \\texttt{BUILD}\nwill either return a tree that satisfies $C$, or error \nif no such tree exists.\nIn \\texttt{BUILD}, we first construct the {\\it Aho graph}\n$G_C$, which has a vertex for each data point and an \nundirected edge $\\{a,b\\}$ for each triplet constraint $(\\{a,b\\},c)$.\nIf $G_C$ is connected, there is no tree that satisfies all\ntriplets. Otherwise, the top split of the tree is a partition of \nthe connected components of $G_C$: any split is fine as long as \npoints in the same component stay together. Satisfied triplets are discarded, and \\texttt{BUILD} then continues recursively on the\nleft and right subtrees.\n\n\\texttt{BUILD} satisfies triplet constraints but ignores \nthe geometry of the data, whereas we wish to take both into\naccount. By incorporating triplets into the posterior DDT \nsampler, we obtain high likelihood trees that still satisfy $C$.\n\n\n\\subsection{Incorporating triplets into the sampler}\n\nIn this section, we present an algorithm\nto sample candidate trees \nfrom the posterior DDT, constrained\nby a triplet set $C$.\nIt is based on the subtree prune and regraft move.\n%The Metropolis-Hastings algorithm for the DDT\n%alternates sampling tree structure\n%via SPR moves and latent divergence locations\n%via Gibbs Sampling.\n%This process produces tree samples\n%that converge to the posterior\n%distribution of the DDT\n%given data.\n\n\\begin{figure*}[htp!]\n    \\centering\n    \\includegraphics[width=\\textwidth]{img/ibhc/ConstrainedSPRMove}\n    \\caption{\n            Visualized is a constrained-SPR move.\n            Pruning is identical  but\n            a regraft location is selected from the valid regraft locations\n            limited by triplets.\n            In this image, we are constrained by the sole triplet $(\\{2, 3\\}, 4)$.\n            }\n    \\label{fig:constrainedsprmove}\n\\end{figure*}\n\nThe SPR move is of particular interest\nbecause we can efficiently\nenforce triplets to form a \\emph{constrained-SPR move},\nresulting in a sampler\nthat only produces trees that satisfy a set of triplets.\nA \\emph{constrained-SPR move} is defined as\nan SPR move that assigns zero probability to\nany resulting trees that would violate a set of triplets.\nRestricting the neighborhood of an SPR move\nruns the risk of partitioning the state space,\nlosing the convergence\nguarantees of the Metropolis-Hastings algorithm.\nFortunately, a constrained-SPR move does not compromise\nstrong connectivity.\nFor any realizable triplet set $C$,\nwe prove \nthe constrained-SPR move Markov chain's aperiodicity and irreducibility.\n\nConsider the Markov chain on the state space \nof rooted binary trees that is induced by the constrained sampler.\n%\\subsection{Proof of \\autoref{thm:apr}}\n\\begin{restatable}{lemma}{aperiodic}\nThe constrained-SPR Markov chain is aperiodic.\n\\end{restatable}\n\\begin{proof}\nA sufficient condition for aperiodicity\nis the existent of a ``self-loop'' in the transition matrix: a non-zero probability of a state transitioning to itself.\nSupposed we have pruned a subtree already.\nWhen regrafting, the ordinary SPR move\nhas a non-zero probability of choosing any branch,\nand a constrained-SPR move cannot regraft\nto branches that would violate triplets.\nSince the current tree in the Markov chain\nsatisfies triplet set $C$, there is a non-zero probability\nof regrafting to the same location. \nWe thus have an aperiodic Markov chain.\n\\end{proof}\n\n\n\n%\\subsection{Proof of \\autoref{thm:irr}}\n%\\label{app:irr}\n%\\irreducible*\n\\begin{restatable}{lemma}{irreducible}\n\\label{thm:irr}\nA constrained-SPR Markov chain is irreducible.\n\\end{restatable}\n\n\\begin{proof}\n(sketch) To show irreducibility,\nwe show that a tree $\\tree$ has an non-zero\nprobability of reaching an arbitrary tree\n$\\tree'$ via constrained-SPR moves where\nboth $\\tree$ and $\\tree'$ satisfy a set of triplets $C$.\nOur proof strategy\nis to construct a canonical tree \n$\\tree_C$, and show that there exists\na non-zero probability path from $\\tree$ to $\\tree_C$,\nand therefore from $\\tree'$ to $\\tree_C$.\nWe then show that for a given constrained-SPR move,\nthe reverse move has a non-zero probability.\nThus, there exists a path from $\\tree$ to $\\tree_C$ to\n$\\tree'$, satisfying irreducibility.\n\nRecall that the split at a node in a binary\ntree that satisfies triplet set $C$\ncorresponds to a binary partition\nof the Aho graph at the node (see Section \\ref{sec:aho}).\n$\\tree_C$ is a tree such that\nevery node in $\\tree_C$ is in \\emph{canonical form}.\nA node is in canonical form if it is a leaf node,\nor, the partition of the Aho graph\nat that node can be written as $(l, r)$.\n$l$ is the single connected component\ncontaining the point with the minimum data index,\nand $r$ is the rest of the components.\n\nTo convert a particular node $s$ into canonical form,\nwe first perform ``grouping'',\nwhich puts $l$ into a single descendant of $s$\nvia constrained-SPR moves.\nWe then make two constrained-SPR moves to convert\nthe partition at $s$ into the form $(l, r)$ (see \\autoref{fig:canonical}).\nWe convert all nodes into canonical form recursively, turning \nan arbitrary tree $\\tree$ into $\\tree_C$.\n\nFinally, the reverse constrained-SPR move has a non-zero\nprobability. Suppose\nwe perform a constrained-SPR move on tree $\\tree_1$, converting it into $\\tree_2$ by \ndetaching subtree $s$\nand attaching it to branch $(u, v)$.\nA constrained-SPR move on $\\tree_2$ can select\n$s$ for pruning \nand can regraft it to form $\\tree_1$ with a non-zero\nprobability since\n$\\tree_1$ satisfies the same constraint set as $C$.\nFor a full proof, please refer to \\autoref{chap:ibhc-appendix}.\n\\end{proof}\n\n\\begin{figure*}\n    \\centering\n    \\includegraphics[width=\\textwidth]{img/ibhc/CanonicalTree}\n    \\caption{The process of converting $s$ into canonical form.\n    We first group nodes from $l$ into their own isolated subtree, then perform\n    two constrained-SPR moves to put $s$ into canonical form.}\n    \\label{fig:canonical}\n\\end{figure*}\n\n%\\begin{restatable}{lemma}{aperiodic}\n%\\label{thm:apr}\n%\\end{restatable}\n%\\begin{proof} See \\ref{app:apr}.\n%\\end{proof}\n%\n%\\begin{restatable}{lemma}{irreducible}\n%\\label{thm:irr}\n%A constrained-SPR Markov chain is irreducible.\n%\\end{restatable}\n%\\begin{proof} See \\ref{app:irr}.\n%\\end{proof}\n\n\nThe simplest possible scheme for a constrained-SPR move \nwould be rejection sampling. The Metropolis-Hastings\nalgorithm for the DDT would be the same as in the\nunconstrained case,\nbut any trees violating $C$ would have accept\nprobability $0$. Although this procedure is correct,\nit is impractical. As the number of triplets\ngrows larger, more trees will be rejected\nand the sampler will slow down over time.\n\nTo efficiently sample a tree that satisfies a set of triplets $C$, \nwe modify the regraft in the ordinary SPR move. \nThe constrained-SPR move must assign zero probability\nto any regraft branches that would result in a tree\nthat violates $C$.\nThis is accomplished by generating the path from the root\nin the same manner as sampling a branch,\nbut avoiding paths that would resulted in violated triplets.\n\n\n\\textbf{Description of constrained-SPR sampler}\nRecall that in the DDT's sampling procedure for regraft branches,\na particle at a node picks a branch, and either diverges from that\nbranch or recursively samples the node's child.\nLet $s$ be the root of the subtree we are currently grafting \nback onto tree $\\tree$, let $C$ be the\ntriplet set, and let $\\texttt{leaves}(u)$\ndenote the descendant-leaves of node $u$.\nSuppose we are are currently at node $u$,\ndeciding whether to diverge\nat the branch $(u, v)$ or to recursively sample $v$.\nConsider any triplet $(\\{a, b\\}, c) \\in C$. If all---or none---of $a,b,c$ are in $\\texttt{leaves}(s)$, then the triplet is \nunaffected by the graft, and can be ignored. Otherwise, \nsome checks are needed:\n\\begin{enumerate}\n\\item $c \\in \\texttt{leaves}(s)$\n\nThen we know $a,b \\not\\in \\texttt{leaves}(s)$. If $a$ and $b$ are split across $v$'s children,\nwe are banned from sampling $v$.\n\n\\item $a \\in \\texttt{leaves}(s)$ but $b,c \\not\\in \\texttt{leaves}(s)$\n\nIf both $b$ and $c$ are in $\\texttt{leaves}(v)$, we are\nrequired to sample $v$.\nIf just $c$ is in $\\texttt{leaves}(v)$, we are banned\nfrom both diverging at $(u, v)$ and sampling $v$.\nOtherwise we can either diverge at $(u, v)$ or sample $v$.\n\n\\end{enumerate}\n\n%\\begin{enumerate}\n%\\item[1.] A node $u$ is \\emph{path-banned} if for\n%any triplet $(\\{a, b\\}, c) \\in C$, \n%$(a \\in \\texttt{leaves}(s) \\land b \\notin \\texttt{leaves}(u) \\land c \\in \\texttt{leaves}(u)) \\lor (b \\in \\texttt{leaves}(s) \\land a \\notin \\texttt{leaves}(u) \\land c \\in \\texttt{leaves}(u))$.\n%Let $p$ be $u$'s parent.\n%Intuitively, if $u$ is \\emph{path-banned}, we cannot\n%graft to the branch $(p, u)$, as we would automatically\n%violate a triplet. This is because there is some triplet$(\\{a, b\\}, c)$\n%in $C$ such that attaching $s$ to $(p, u)$ would result in a subtree\n%that contains either $a$ and $c$ but not $b$ or $b$ and $c$ but not $a$.\n%\n%\\item[2.] A node $u$ is \\emph{sample-banned} if \n%for\n%any triplet $(\\{a, b\\}, c) \\in C$, \n%$(c \\in \\texttt{leaves}(s)) \\land ((a \\in \\texttt{leaves}(v) \\land b \\in \\texttt{leaves}(w)) \\lor (a \\in \\texttt{leaves}(w) \\land b \\in \\texttt{leaves}(v))$\n%where $v$ and $w$ are the children of $u$. \n%Intuitively,\n%this means that there exist some $a$ and $b$ in our triplet set\n%that are split between $u$'s children. Attaching a subtree containing\n%$c$ to a any branch below $u$ would violate a triplet.\n%\n%\\item[3.] A node $u$ is \\emph{path-required} if for\n%any triplet $(\\{a, b\\}, c) \\in C$, \n%$(a \\in \\texttt{leaves}(s) \\land b \\in \\texttt{leaves}(u)) \\lor (b \\in \\texttt{leaves}(s) \\land a \\in \\texttt{leaves}(u))$. \n%If $u$ is \\emph{path-required}, the particle must enter its branch,\n%as for some triplet $(\\{a, b\\}, c)$, if $a$ is in our\n%pruned subtree, then $b$ is in $u$ and $c$ is in $u$'s sibling.\n%Choosing the branch to $u$'s sibling would violate this triplet.\n%\n%\\item[4.] A node $u$ is \\emph{sample-required} if for\n%any triplet $(\\{a, b\\}, c) \\in C$, \n%$(a \\in \\texttt{leaves}(s) \\land b \\in \\texttt{leaves}(u) \\land c \\in \\texttt{leaves}(u)) \\lor (b \\in \\texttt{leaves}(s) \\land a \\in \\texttt{leaves}(u) \\land c \\in \\texttt{leaves}(u))$.\n%If $u$ being \\emph{sample-required} \n%means that there exists some $a$ and $c$ or $b$ and $c$\n%in our triplet set that are already in a subtree in $T$ together.\n%We must attach our subtree such that this triplet is not violated.\n%\n%\\end{enumerate}\n(The case where $b \\in \\texttt{leaves}(s)$ is\nsymmetric to case 2.)\nIf we choose to sample $v$, we remove\nconstraints from our current set $C$ that are now satisfied,\nand continue recursively.\nThis defines a procedure by which we can sample\na divergence branch that does not violate constraints.\n\nWhile the constrained-SPR sampler can produce\na set of trees given a set of static constraints,\nthe \\texttt{BUILD} algorithm is useful in\nadding new triplets into the sampler.\nSuppose we have been sampling trees with constrained-SPR moves\nwith satisfying triplet set $C$ \nand we obtain a new triplet $u = (\\{a, b\\}, c)$ from a user query. \nWe take the current tree $\\tree$ and find the least common ancestor \n(call it $z$) of $a$ and $b$. We then call \n\\texttt{BUILD}$(C + \\{u\\})$ on just the nodes in \n$\\texttt{leaves}(z)$, and \nwe substitute the resulting subtree at position $z$ in tree $\\tree$.\n\n\\subsection{Intelligent subset queries}\nWe now have a method to sample a constrained\ndistribution over candidate trees.\nGiven a particular candidate tree $\\tree$,\nour first strategy for subtree querying\nis to pick a random subset $S$ of the leaves\nof constant size, and show the user\nthe induced subtree over the subset, $\\tree|_S$.\nWe call this \\emph{random subtree querying}.\nBut can we use a set of trees produced by the sampler\nto make better subtree queries?\nIf tree structure is ambiguous in a particular region of data,\ni.e. there are several hierarchies that could explain\na particular configuration of data, \nthe MH algorithm will sample over\nthese different configurations. A query over points\nin these ambiguous regions may help our algorithm\nconverge to a better tree faster. By looking for\nthese regions in our samples, we can choose query\nsubsets $S$ for which the tree structure is highly variable, \nand hopefully the resulting triplet from the user will \nreduce the ambiguity.\n\nMore precisely, we desire a notion of tree variance.\nGiven a set of trees $\\trees$, what is the variance\n%TODO: check this\nover a given subset of the data $S$?\nWe propose using the notion of tree distance\nas a starting point. \nFor a given tree $\\tree$, the tree distance between two nodes $a$ and $b$,\ndenoted $\\texttt{treedist}_T(a, b)$,\nis the number of edges of $\\trees$ needed to get from $a$ to $b$.\nConsider two leaves $u$ and $v$. If the tree structure around\nthem is static, we expect the tree distance\nbetween $u$ and $v$ to change very little, as the surrounding tree\nwill not change. However, if there is\nambiguity in the surrounding structure, the tree distance will\nbe more variable.\nGiven a subset of data $S$ and a set of trees $\\trees$,\nthe tree distance variance (TDV) of the trees over the subset is defined as:\n\\begin{align}\n    \\text{TDV}(\\trees, S) = \\max_{u, v \\in S}\\mathrm{Var}_{\\tree \\in \\trees}[\\texttt{treedist}_{\\tree|_S}(u, v)]\n\\end{align}\n\nThis measure of variance is\nthe \\emph{max} of the variance of tree distance between\nany two points in the subset. Computing this requires\n$O(|\\trees||S|^2 \\log|S|)$ time, and since since $|S|$ is constant,\nit is not prohibitively expensive.\n\nGiven a set of trees from the sampler $\\trees$,\nwe now select a high-variance subtree\nby instantiating $L$ random subsets of constant size, $S_1, \\ldots, S_L$\nand picking $\\text{argmax}_l \\text{TDV}(\\trees, S_l)$.\nWe call this \\emph{active subtree querying}.\nAlthough using tree variance will help reconcile ambiguity in the tree structure,\nif a set of samples from a tree all violate the same triplet,\nit is unlikely that active querying will recover that triplet.\nThus, interleaving random querying and active querying\nwill hopefully help the algorithm converge quickly, while avoiding\nlocal optima.\n\n\\section{Experiments}\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[]{0.6\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/ibhc/Fisher-Iris-result.png} \\caption{Fisher Iris}\n        \\label{fig:iris-result}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[]{0.6\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{img/ibhc/MNIST-result.png}\n        \\caption{MNIST}\n        \\label{fig:mnist-result}\n    \\end{subfigure}\n    \\caption{The average of four runs of constrained-SPR samplers\n    for the Fisher Iris dataset and the MNIST dataset, using 5 different querying schemes. A query was made every 100 iterations.}\n    \\label{fig:main-results}\n\\end{figure}\n\nWe evaluated the convergence properties of five different querying schemes.\nIn a ``simple query'', a user is presented with three random data\nand picks an odd one out.\nIn a ``smart query'', a user is unrealistically shown the entire candidate tree and reports a violated triplet.\nIn a ``random query'', the user is shown the induced candidate tree over\na random subset of the data.\nIn an ``active query'', the user is shown a high variance \nsubtree using tree-distance variance.\nFinally, in an ``interleaved query'', the user is alternatively shown a random\nsubtree and a high variance subtree.\nIn each experiment, $\\tree^*$ was known, so user queries were simulated\nby picking a triplet\nviolated by the root split of the queried tree, \nand if no such triplet existed, recursing on a child.\n%\\begin{enumerate}\n%\\item Simple querying: a user is presented with three random data and\n%reports a triplet of the data that should be satisfied.\n%\\item Smart querying (unrealistic): a user is presented with the entire tree\n%and reports a triplet that is violated.\n%\\item Random querying: the user is shown the induced subtree\n%over a random subset of the data of constant size\n%and reports a violated triplet.\n%\\item Active querying: the user is shown a high variance\n%induced subtree, chosen from a set of random subsets of data $\\{S_1, \\ldots , S_L\\}$,\n%with variance defined as tree distance variance. The user then reports\n%a violated triple from this induced subtree.\n%\\item Interleaved querying: we alternate performing a random query\n%and an active query.\n%\\end{enumerate}\nEach scheme was evaluated on four different datasets.\nThe first dataset, MNIST \\citep{Lecun1998}, is an 10-way image classification\ndataset where the data are 28 x 28 images of digits.\nThe target tree $\\tree^*$ is simply the $K$-way classification \ntree over the data.\nThe second dataset is Fisher Iris, a 3-way flower\nclassification problem, where each of 150 flowers has\nfive features.\nThe third dataset, Zoo \\citep{Lichman2013}, is a set of 93 animals\nand 15 binary morphological features for each of animals,\nthe target tree being the induced binary tree \nfrom the Open Tree of Life \\citep{Hinchliff2015}.\nThe fourth dataset is 20 Newsgroups \\citep{Joachims1997}, a\ncorpus of text articles on 20 different subjects. We use\nthe first 10 principal components as features\nin this classification problem.\nAll datasets were modeled with DDT's with\nacquisition function $a(t) = 1/(1 - t)$\nand Brownian motion parameter $\\sigma^2$ estimated from data.\nTo better visualize the different convergence rates\nof the querying schemes, MNIST and 20 Newsgroups were subsampled\nto 150 random points.\n\nFor each dataset and querying scheme, we instantiated a SPR\nsampler with no constraints. Every one hundred iterations of the \nsampler, we performed a query.\nIn subtree queries, we used subsets of size $|S| = 10$ \nand in active querying, the highest-variance subset was chosen from $L = 20$ different random subsets.\nAs baselines,\nwe measured the triplet distance of the vanilla DDT\nand the average linkage tree.\nFinally, results were averaged over four runs of each sampler.\nThe triplet distances for Fisher Iris and MNIST can be seen in \\autoref{fig:main-results}. Results for the other datasets\ncan be found in \\autoref{chap:ibhc-appendix}.\nAlthough unrealistic due to the size of the tree shown to the user, \nthe smart query performed the best, achieving minimum error\nwith the least amount of queries. Interleaved followed next,\nfollowed by active, random, and simple. In general, the vanilla\nDDT performed the worst, and the average linkage\nscore varied on each dataset, but in all cases, the\nsubtree querying schemes performed better than both the vanilla DDT\nand average linkage.\n\nIn three datasets (MNIST, Fisher Iris and Zoo), \ninteractive methods\nachieve higher data likelihood than the vanilla DDT.\nInitially, the sampler is often restructuring the tree\nwith new triplets\nand data likelihood is unlikely to rise. However, over time\nas less triplets are reported,\nthe data likelihood increases rapidly.\nWe thus conjecture that triplet constraints \nmay help the MH algorithm find better optima.\n\n\\section{Future Work}\nWe are interested in studying the non-realizable case, i.e.\nwhen there does not exist a tree that satisfies triplet set $C$. We would also like to better understand the effect of constraints on searching\nfor optima using MCMC methods.\n\n\\ibhcack\n", "meta": {"hexsha": "55d20017ebc3e72182e1f0bec0212f5898a995a6", "size": 36372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/content/structure/ibhc.tex", "max_stars_repo_name": "sharadmv/thesis", "max_stars_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-30T01:28:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-30T01:28:54.000Z", "max_issues_repo_path": "writeup/content/structure/ibhc.tex", "max_issues_repo_name": "sharadmv/thesis", "max_issues_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "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": "writeup/content/structure/ibhc.tex", "max_forks_repo_name": "sharadmv/thesis", "max_forks_repo_head_hexsha": "5fbf70c0645e44b2992f3cb4d7c2fbbbf7592d7f", "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": 52.409221902, "max_line_length": 1244, "alphanum_fraction": 0.755526229, "num_tokens": 9414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6265021151293575}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Contractible types and contractible maps}\n\\sectionmark{Contractible types and maps}\n\n\\index{contractible type|(} \nA contractible type is a type which has, up to identification, only one term. In other words, a contractible type is a type that comes equipped with a point, and an identification of this point with any point.\n\nWe may think of contractible types as singletons up to homotopy, and indeed we show that the unit type is an example of a contractible type. Moreover, we show that contractible types satisfy an induction principle that is very similar to the induction principle of the unit type, provided that we formulate the computation rule using the identity type rather than postulating a judgmental computation rule.\n\nAnother case of an inductive type with a single constructor is the type of identifications $p:a=x$ with a fixed starting point $a:A$. To specify such an identification, we have to give its end point $x:A$ as well as the identification $p:a=x$, and the path induction principle asserts that in order to show something about all such identifications, it suffices to show that thing in the case where the end point is $a$, and the path is $\\refl{a}$. This suggests that the total space\n\\begin{equation*}\n  \\sm{x:A}a=x\n\\end{equation*}\nof all paths with starting point $a:A$ is contractible. This important fact will be shown in \\cref{thm:total_path}, and it is the basis for the fundamental theorem of identity types (\\cref{chap:fundamental}).\n\nIn the remainder of this section we will show that for any equivalence $e:A\\simeq B$ and any $b:B$, the type of all $a:A$ equipped with a path $p:e(a)=b$ is contractible. In other words, if a map $f:A\\to B$ is an equivalence, then the `preimage'\n\\begin{equation*}\n  \\sm{a:A}f(a)=b\n\\end{equation*}\nis contractible for each $b:B$. The preimage of a map $f:A\\to B$ at a point $b:B$ is called the fiber of $f$ at $b$, and we say that a map is contractible if all its fibers are contractible. This condition is of course analogous to the set theoretic notion of bijective map, or $1$-to-$1$-correspondence. We will see that a map is contractible if and only if it is an equivalence.\n\n\\subsection{Contractible types}\n\n\\begin{defn}\n  We say that a type $A$ is \\define{contractible} if it comes equipped with a term of type\\index{is-cont(A)r@{$\\iscontr(A)$}|see {contractible type}}\n  \\begin{equation*}\n    \\iscontr(A) \\defeq \\sm{c:A}\\prd{x:A}c=x.\n  \\end{equation*}\n  Given a term $(c,C):\\iscontr(A)$, we call $c:A$ the \\define{center of contraction}\\index{center of contraction}\\index{contractible type!center of contraction} of $A$, and we call $C:\\prd{x:A}c=x$ the \\define{contraction}\\index{contraction}\\index{contractible type!contraction} of $A$.\n\\end{defn}\n\n\\begin{rmk}\nSuppose $A$ is a contractible type with center of contraction $c$ and contraction $C$. Then the type of $C$ is (judgmentally) equal to the type\n\\begin{equation*}\n\\const_c\\htpy\\idfunc[A].\n\\end{equation*}\nIn other words, the contraction $C$ is a \\emph{homotopy} from the constant function to the identity function.\n\\end{rmk}\n\n\\begin{eg}\n  The unit type is easily seen to be contractible.\\index{unit type!is contractible}\\index{is contractible!unit type} For the center of contraction we take $\\ttt:\\unit$. Then we define a contraction $\\prd{x:\\unit}\\ttt=x$ by the induction principle of $\\unit$. Applying the induction principle, it suffices to construct a term of type $\\ttt = \\ttt$, for which we just take $\\refl{\\ttt}$.\n\\end{eg}\n\n\\begin{defn}\n  Suppose $A$ comes equipped with a term $a:A$. Then we say that $A$ satisfies \\define{singleton induction}\\index{singleton induction}\\index{induction principle!singleton induction} if for every type family $B$ over $A$, the map\\index{ev-pt@{$\\evpt$}}\n  \\begin{equation*}\n    \\evpt:\\Big(\\prd{x:A}B(x)\\Big)\\to B(a)\n  \\end{equation*}\n  defined by $\\evpt(f)\\defeq f(a)$ has a section. In other words, if $A$ satisfies singleton induction we have a function and a homotopy\\index{sing-ind@{$\\singind$}}\\index{sing-comp@{$\\singcomp$}}\n  \\begin{align*}\n    \\singind_{a} & : B(a)\\to \\prd{x:A}B(x) \\\\\n    \\singcomp_{a} & : \\evpt\\circ \\singind_{a} \\htpy \\idfunc\n  \\end{align*}\n  for any type family $B$ over $A$.\n\\end{defn}\n\n\\begin{eg}\n  Note that the singleton induction principle is almost the same as the induction principle for the unit type, the difference being that the \"computation rule\" in the singleton induction for $A$ is stated using an \\emph{identification} rather than as a judgmental equality. The unit type\\index{unit type!singleton induction} $\\unit$ comes equipped with a function\n  \\begin{equation*}\n    \\indunit:B(\\ttt)\\to \\prd{x:\\unit}B(x)\n  \\end{equation*}\n  for every type family $B$ over $\\unit$, satisfying the judgmental equality $\\indunit(b,\\ttt)\\jdeq b$ for every $b:B(\\ttt)$ by the computation rule. Thus we easily obtain the homotopy\n  \\begin{equation*}\n    \\lam{b}\\refl{b}:\\evpt\\circ\\indunit \\htpy\\idfunc,\n  \\end{equation*}\n  and we conclude that the unit type satisfies singleton induction. \n\\end{eg}\n\n\\begin{thm}\\label{thm:contractible}\nLet $A$ be a type. The following are equivalent:\\index{is contractible!iff singleton induction}\\index{singleton induction!iff contractible}\n\\begin{enumerate}\n\\item The type $A$ is contractible.\n\\item The type $A$ comes equipped with a term $a:A$, and satisfies singleton induction.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nSuppose $A$ is contractible with center of contraction $a$ and contraction $C$. \nFirst we observe that, without loss of generality, we may assume that $C$ comes equipped with an identification $p:C(a)=\\refl{a}$.\nTo see this, note that we can always define a new contraction $C'$ by\n\\begin{equation*}\nC'(x)\\defeq\\ct{C(a)^{-1}}{C(x)},\n\\end{equation*}\nwhich satisfies the requirement by the left inverse law, constructed in \\cref{defn:id_invlaw}.\n\nTo show that $A$ satisfies singleton induction let $B$ be a type family over $A$, and suppose we have $b:B(a)$. Our goal is to define\n\\begin{equation*}\n  \\indsing_a(b):\\prd{x:A}B(x).\n\\end{equation*}\nLet $x:A$. Since we have an identification $C(x):a=x$, and a term $b$ in $B(a)$, we may transport $b$ along the path $C(x)$ to obtain\n\\begin{equation*}\n  \\indsing_a(b,x)\\defeq \\tr_B(C(x),b):B(x).\n\\end{equation*}\nTherefore, the function $\\indsing_a(b)$ is defined to be the dependent function $\\lam{x}\\tr_B(C(x),b)$. Now we have to show that $\\indsing_a(b,a)=b$. Then we have the identifications\n\\begin{equation*}\n\\begin{tikzcd}\n\\tr_B(C(a),b) \\arrow[r,equals,\"\\ap{\\lam{\\omega}\\tr_B(\\omega,b)}{p}\"] &[4em] \\tr_B(\\refl{a},b) \\arrow[r,equals,\"\\refl{b}\"] & b.\n\\end{tikzcd}\n\\end{equation*}\nThis shows that the computation rule is satisfied, which completes the proof that $A$ satisfies singleton induction.\n\nFor the converse, suppose that $a:A$ and that $A$ satisfies singleton induction. Our goal is to show that $A$ is contractible. For the center of contraction we take the term $a:A$. By singleton induction applied to $B(x)\\defeq a=x$ we have the map \n\\begin{equation*}\n\\indsing_{a} : a=a \\to \\prd{x:A}a=x.\n\\end{equation*}\nTherefore $\\indsing_{a}(\\refl{a})$ is a contraction.\n\\end{proof}\n\n\\begin{thm}\\label{thm:total_path}\nFor any $a:A$, the type\n\\begin{equation*}\n\\sm{x:A}a=x\n\\end{equation*}\nis contractible.\\index{identity type!total space is contractible}\\index{is contractible!total space of identity type}\n\\end{thm}\n\n\\begin{proof}\n  We will prove the statement by showing that $\\sm{y:A}x=y$ satisfies singleton induction, and then use \\cref{thm:contractible} to conclude that $\\sm{x:A}a=x$ is contractible. We will use the term $(a,\\refl{a}):\\sm{x:A}a=x$ as the center of contraction.\n\n  Now let $P$ be a type family over $\\sm{x:A}a=x$. Note that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\prd{t:\\sm{x:A}a=x}P(t) \\arrow[dr,swap,\"\\evpt\"] \\arrow[rr,\"\\evpair\"] & & \\prd{x:A}\\prd{p:a=x}P(x,p) \\arrow[dl,\"\\evrefl\"] \\\\\n      \\phantom{\\prd{x:A}\\prd{p:a=x}P(x,p)} & P(a,\\refl{a})\n    \\end{tikzcd}\n  \\end{equation*}\n  where the maps $\\evpair$ and $\\evrefl$ are defined as\n  \\begin{align*}\n    f & \\mapsto \\lam{x}\\lam{p}f(x,p) \\\\\n    g & \\mapsto g(a,\\refl{a}),\n  \\end{align*}\n  respectively. By the induction principle for $\\Sigma$-types it follows that $\\evpair$ has a section, and by path induction it follows that $\\evrefl$ has a section. Therefore it follows from \\cref{ex:3_for_2} that the composite $\\evpt$ has a section.\n\\end{proof}\n\n\\subsection{Contractible maps}\n\n\\index{contractible map|(}\n\\begin{defn}\n  Let $f:A\\to B$ be a function, and let $b:B$. The \\define{fiber}\\index{fiber}\\index{homotopy fiber|see {fiber}} of $f$ at $b$ is defined to be the type\\index{fib f b@{$\\fib{f}{b}$}}\n  \\begin{equation*}\n    \\fib{f}{b}\\defeq\\sm{a:A}f(a)=b.\n  \\end{equation*}\n\\end{defn}\n\nIn other words, the fiber of $f$ at $b$ is the type of $a:A$ that get mapped by $f$ to $b$.\nOne may think of the fiber as a type theoretic version of the pre-image\\index{pre-image|see {fiber}} of a point.\n\n\\index{fiber!characterization of identity type|(}\n\\index{characterization of identity type!fiber|(}\n\\index{identity type!of a fiber|(}\nIt will be useful to have a characterization of the identity type of a fiber, so we will make such a characterization immediately.\n\n\\begin{defn}\n  Let $f:A \\to B$ be a map, and let $(x,p),(x',p'):\\fib{f}{y}$ for some $y:B$.\n  Then we define\\index{Eq fib@{$\\Eqfib$}}\\index{fiber!Eq fib@{$\\Eqfib$}}\n  \\begin{equation*}\n    \\Eqfib_f((x,p),(x',p'))\\defeq \\sm{\\alpha:x=x'}p=\\ct{\\ap{f}{\\alpha}}{p'}\n  \\end{equation*}\n  The relation $\\Eqfib_f:\\fib{f}{y}\\to\\fib{f}{y}\\to\\UU$ is a reflexive relation, since we have\n  \\begin{equation*}\n    \\lam{(x,p)}(\\refl{x},\\refl{p}):\\prd{(x,p):\\fib{f}{y}}\\Eqfib_f((x,p),(x,p)).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{lem}\n  Consider a map $f:A\\to B$ and let $y:B$. The canonical map\n  \\begin{equation*}\n    ((x,p)=(x',p'))\\to\\Eqfib_f((x,p),(x',p'))\n  \\end{equation*}\n  induced by the reflexivity of $\\Eqfib_f$ is an equivalence for any $(x,p),(x',p'):\\fib{f}{y}$.\n\\end{lem}\n\n\\begin{proof}\n  The converse map\n  \\begin{equation*}\n    \\Eqfib_f((x,p),(x',p'))\\to ((x,p)=(x',p'))\n  \\end{equation*}\n  is easily defined by $\\Sigma$-induction, and then path induction twice. The homotopies witnessing that this converse map is indeed a right inverse as well as a left inverse is similarly constructed by induction.\n\\end{proof}\n\n\\index{fiber!characterization of identity type|)}\n\\index{characterization of identity type!fiber|)}\n\\index{identity type!of a fiber|)}\n\nNow we arrive at the notion of contractible map.\n\n\\begin{defn}\nWe say that a function $f:A\\to B$ is \\define{contractible} if there is a term of type\\index{is-contr(f)@{$\\iscontr(f)$}|see {contractible map}}\\index{is a contractible map}\n\\begin{equation*}\n\\iscontr(f)\\defeq\\prd{b:B}\\iscontr(\\fib{f}{b}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{thm}\\label{thm:equiv_contr}\nAny contractible map is an equivalence.\\index{contractible map!is an equivalence}\\index{is an equivalence!contractible map}\n\\end{thm}\n\n\\begin{proof}\nLet $f:A\\to B$ be a contractible map. Using the center of contraction of each $\\fib{f}{y}$, we obtain a term of type\n\\begin{align*}\n\\lam{y}\\pairr{g(y),G(y)}:\\prd{y:B}\\fib{f}{y}.\n\\end{align*}\nThus, we get map $g:B\\to A$, and a homotopy $G:\\prd{y:B} f(g(y))=y$. In other words, we get a section of $f$.\n\nIt remains to construct a retraction of $f$. Taking $g$ as our retraction, we have to show that $\\prd{x:A} g(f(x))=x$. Note that we get an identification $p:f(g(f(x)))=f(x)$ since $g$ is a section of $f$. It follows that $(g(f(x)),p):\\fib{f}{f(x)}$. Moreover, since $\\fib{f}{f(x)}$ is contractible we get an identification $q:\\pairr{g(f(x)),p}=\\pairr{x,\\refl{f(x)}}$. The base path $\\ap{\\proj 1}{q}$ of this identification is an identification of type $g(f(x))=x$, as desired.\n\\end{proof}\n\n\\subsection{Equivalences are contractible maps}\n\nIn \\cref{thm:contr_equiv} we will show the converse to \\cref{thm:equiv_contr}, i.e., we will show that any equivalence is a contractible map. We will do this in two steps.\n\nFirst we introduce a new notion of \\emph{coherently invertible map}, for which we can easily show that such maps have contractible fibers. Then we show that any equivalence is a coherently invertible map.\n\n  Recall that an invertible map is a map $f:A\\to B$ equipped with $g:B\\to A$ and homotopies\n  \\begin{equation*}\n    G : f\\circ g \\htpy \\idfunc\\qquad\\text{and}\\qquad H:g\\circ f\\htpy \\idfunc.\n  \\end{equation*}\n  Then we observe that both $G \\cdot f$ and $f \\cdot H$ are homotopies of the same type\n  \\begin{equation*}\n    f\\circ g\\circ f \\htpy f.\n  \\end{equation*}\n  A coherently invertible map is an invertible map for which there is a further homotopy $G \\cdot f\\htpy f\\cdot H$.\n\n  \\begin{defn}\n    Consider a map $f:A\\to B$. We say that $f$ is \\define{coherently invertible}\\index{coherently invertible map} if it comes equipped with\n    \\begin{align*}\n      g & : B \\to A \\\\\n      G & : f \\circ g \\htpy \\idfunc \\\\\n      H & : g \\circ f \\htpy \\idfunc \\\\\n      K & : G \\cdot f \\htpy f \\cdot H.\n    \\end{align*}\n    We will write $\\iscohinvertible(f)$\\index{is-coh-invertible(f)@{$\\iscohinvertible(f)$}} for the type of quadruples $(g,G,H,K)$.\n  \\end{defn}\n\n  Although we will encounter the notion of coherently invertible map on some further occasions, the following lemma is our main motivation for considering it.\n\n  \\begin{lem}\\label{lem:contr-inv}\n    Any coherently invertible map has contractible fibers.\\index{coherently invertible map!is a contractible map}\n  \\end{lem}\n\n  \\begin{proof}\n    Consider a map $f:A\\to B$ equipped with\n    \\begin{align*}\n      g & : B \\to A \\\\\n      G & : f \\circ g \\htpy \\idfunc \\\\\n      H & : g \\circ f \\htpy \\idfunc \\\\\n      K & : G \\cdot f \\htpy f \\cdot H,\n    \\end{align*}\n    and let $y:B$. Our goal is to show that $\\fib{f}{y}$ is contractible. For the center of contraction we take $(g(y),G(y))$. In order to construct a contraction, it suffices to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}\\prd{p:f(x)=y}\\Eqfib_f((g(y),G(y)),(x,p)).\n    \\end{equation*}\n    By path induction on $p:f(x)=y$ it suffices to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}\\Eqfib_f((g(f(x)),G(f(x))),(x,\\refl{f(x)})).\n    \\end{equation*}\n    By definition of $\\Eqfib_f$, we have to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}\\sm{\\alpha:g(f(x))=x}G(f(x))=\\ct{\\ap{f}{\\alpha}}{\\refl{f(x)}}.\n    \\end{equation*}\n    Such a term is constructed as $\\lam{x}(H(x),K'(x))$, where the homotopy $H:g\\circ f\\htpy \\idfunc$ is given by assumption, and the homotopy\n    \\begin{align*}\n      K' & : \\prd{x:A}G(f(x))=\\ct{\\ap{f}{H(x)}}{\\refl{f(x)}}\n    \\end{align*}\n    is defined as\n    \\begin{equation*}\n      K'\\defeq \\ct{K}{\\rightunithtpy(f\\cdot H)^{-1}}.\\qedhere\n    \\end{equation*}\n  \\end{proof}\n\n  Our next goal is to show that for any map $f:A\\to B$ equipped with\n  \\begin{equation*}\n    g:B\\to A,\\qquad G:f\\circ g \\htpy \\idfunc,\\qquad\\text{and}\\qquad H:g\\circ f\\htpy \\idfunc,\n  \\end{equation*}\n  we can improve the homotopy $G$ to a new homotopy $G':f\\circ g\\htpy \\idfunc$ for which there is a further homotopy\n  \\begin{equation*}\n    f\\cdot H\\htpy G'\\cdot f.\n  \\end{equation*}\n  Note that this situation is analogous to the situation in the proof of \\cref{thm:contractible}, where we improved the contraction $C$ so that it satisfied $C(c)=\\refl{}$. The extra coherence $f\\cdot H\\htpy G'\\cdot f$ is then used in the proof that the fibers of an equivalence are contractible.\n\n\\begin{defn}\\label{defn:htpy_nat}\\index{homotopy!naturality}\nLet $f,g:A\\to B$ be functions, and consider $H:f\\htpy g$ and $p:x=y$ in $A$. We define the identification\\index{nat-nat@{$\\nathtpy$}}\\index{homotopy!nat-htpy@{$\\nathtpy$}}\n\\begin{equation*}\n\\nathtpy(H,p) \\defeq  \\ct{\\ap{f}{p}}{H(y)}=\\ct{H(x)}{\\ap{g}{p}}\n\\end{equation*}\nwitnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nf(x) \\arrow[r,equals,\"H(x)\"] \\arrow[d,equals,swap,\"\\ap{f}{p}\"] & g(x) \\arrow[d,equals,\"\\ap{g}{p}\"] \\\\\nf(y) \\arrow[r,equals,swap,\"H(y)\"] & g(y)\n\\end{tikzcd}\n\\end{equation*}\ncommutes. This square is also called the \\define{naturality square}\\index{naturality square of homotopies} of the homotopy $H$ at $p$.\n\\end{defn}\n\n\\begin{constr}\n  By path induction on $p$ it suffices to construct an identification\n  \\begin{equation*}\n    \\ct{\\ap{f}{\\refl{x}}}{H(x)}=\\ct{H(x)}{\\ap{g}{\\refl{x}}}\n  \\end{equation*}\n  since $\\ap{f}{\\refl{x}}\\jdeq \\refl{f(x)}$ and $\\ap{g}{\\refl{x}}\\jdeq\\refl{g(x)}$, and since $\\ct{\\refl{f(x)}}{H(x)}\\jdeq H(x)$, we see that the path $\\rightunit(H(x))^{-1}$ is of the asserted type.\n\\end{constr}\n\n\\begin{defn}\\label{defn:retraction_swap}\nConsider $f:A\\to A$ and $H: f\\htpy \\idfunc[A]$. We construct an identification $H(f(x))=\\ap{f}{H(x)}$, for any $x:A$.\n\\end{defn}\n\n\\begin{constr}\nBy the naturality of homotopies with respect to identifications the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nff(x) \\arrow[d,swap,equals,\"\\ap{f}{H(x)}\"] \\arrow[r,equals,\"H(f(x))\"] & f(x) \\arrow[d,equals,\"H(x)\"] \\\\\nf(x) \\arrow[r,swap,equals,\"H(x)\"] & x\n\\end{tikzcd}\n\\end{equation*}\ncommutes. This gives the desired identification $H(f(x))=\\ap{f}{H(x)}$.\n\\end{constr}\n\n\\begin{lem}\\label{lem:coherently-invertible}\n  Let $f:A\\to B$ be a map, and consider $(g,G,H):\\hasinverse(f)$. Then there is a homotopy $G':f\\circ g\\htpy \\idfunc$ equipped with a further homotopy\n  \\begin{equation*}\n    K : G'\\cdot f \\htpy f\\cdot H.\n  \\end{equation*}\n  Thus we obtain a map $\\hasinverse(f)\\to\\iscohinvertible(f)$.\n\\end{lem}\n\n\\begin{proof}\n  For each $y:B$, we construct the identification $G'(y)$ as the concatenation\n  \\begin{equation*}\n    \\begin{tikzcd}\n      fg(y) \\arrow[r,equals,\"{G(fg(y))}^{-1}\"] &[2.5em] fgfg(y) \\arrow[r,equals,\"\\ap{f}{H(g(y))}\"] &[2.5em] fg(y) \\arrow[r,equals,\"G(y)\"] & y.\n\\end{tikzcd}\n  \\end{equation*}\n  In order to construct a homotopy $G'\\cdot f\\htpy f\\cdot H$, it suffices to show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      fgfgf(x) \\arrow[r,equals,\"{G(fgf(x))}\"] \\arrow[d,equals,swap,\"\\ap{f}{H(gf(x))}\"] & fgf(x) \\arrow[d,equals,\"\\ap{f}{H(x)}\"] \\\\\n      fgf(x) \\arrow[r,equals,swap,\"G(f(x))\"] & f(x)\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes for every $x:A$.\n  Recall from \\cref{defn:retraction_swap} that we have $H(gf(x))=\\ap{gf}{H(x)}$. Using this identification, we see that it suffices to show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      fgfgf(x) \\arrow[r,equals,\"G(fgf(x))\"] \\arrow[d,equals,swap,\"\\ap{fgf}{H(x)}\"] & fgf(x) \\arrow[d,equals,\"\\ap{f}{H(x)}\"] \\\\\n      fgf(x) \\arrow[r,equals,swap,\"G(f(x))\"] & f(x)\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Now we observe that this is just a naturality square the homotopy $Gf:fgf\\htpy f$, which commutes by \\cref{defn:htpy_nat}.\n\\end{proof}\n\nNow we put the pieces together to conclude that any equivalence has contractible fibers.\n\n\\begin{thm}\\label{thm:contr_equiv}\nAny equivalence is a contractible map.\\index{equivalence!is a contractible map}\\index{is a contractible map!equivalence}\\index{is contractible!fiber of an equivalence}\n\\end{thm}\n\n\\begin{proof}\n  We have seen in \\cref{lem:contr-inv} that any coherently invertible map is a contractible map. Moreover, any equivalence has the structure of an invertible map by \\cref{lem:inv_equiv}, and any invertible map is coherently invertible by \\cref{lem:coherently-invertible}.\n\\end{proof}\n\n\\begin{cor}\\label{cor:contr_path}\nLet $A$ be a type, and let $a:A$. Then the type\\index{is contractible!total space of opposite identity type}\n\\begin{equation*}\n\\sm{x:A}x=a\n\\end{equation*}\nis contractible.\n\\end{cor}\n\n\\begin{proof}\nBy \\cref{thm:id_equiv}, the identity function is an equivalence. Therefore, the fibers of the identity function are contractible by \\cref{thm:contr_equiv}. Note that $\\sm{x:A}x=a$ is exactly the fiber of $\\idfunc[A]$ at $a:A$.\n\\end{proof}\n\\index{contractible map|)}\n\n\\begin{exercises}\n\\exercise \\label{ex:prop_contr}Show that if $A$ is contractible, then for any $x,y:A$ the identity type $x=y$ is also contractible.\\index{contractible type!identity types of}\\index{is contractible!identity type of contractible type}\\index{identity type!of contractible type}\\index{characterization of identity type!contractible type}\n\\exercise \\label{ex:contr_retr}Suppose that $A$ is a retract of $B$. Show that\\index{contractible type!closed under retracts}\n  \\begin{equation*}\n    \\iscontr(B)\\to\\iscontr(A).\n  \\end{equation*}\n\\exercise \\label{ex:contr_equiv}\n  \\begin{subexenum}\n  \\item Show that for any type $A$, the map $\\const_\\ttt : A\\to \\unit$ is an equivalence if and only if $A$ is contractible.\\index{contractible type!is equivalent to 1@{is equivalent to $\\unit$}}\n  \\item Apply \\cref{ex:3_for_2} to show that for any map $f:A\\to B$, if any two of the three assertions\\index{contractible type!3-for-2 property}\\index{3-for-2 property!of contractible types}\n    \\begin{enumerate}\n    \\item $A$ is contractible\n    \\item $B$ is contractible\n    \\item $f$ is an equivalence\n    \\end{enumerate}\n    hold, then so does the third.\n  \\end{subexenum}\n\\exercise Show that for any two types $A$ and $B$, the following are equivalent:\n  \\index{contractible type!closed under cartesian product}\n  \\index{is contractible!factor of contractible cartesian product}\n  \\begin{enumerate}\n  \\item Both $A$ and $B$ are contractible.\n  \\item The type $A\\times B$ is contractible.\n  \\end{enumerate}\n\\exercise \\label{ex:contr_in_sigma} Let $A$ be a contractible type with center of contraction $a:A$. Furthermore, let $B$ be a type family over $A$. Show that the map $y\\mapsto\\pairr{a,y}:B(a)\\to\\sm{x:A}B(x)$ is an equivalence.\\index{left unit law!of Sigma-types@{of $\\Sigma$-types}}\\index{dependent pair type!left unit law}\n\\exercise \\label{ex:proj_fiber}Let $B$ be a family of types over $A$, and consider the projection map \n  \\begin{equation*}\n    \\proj 1 : \\big(\\sm{x:A}B(x)\\big)\\to A.\n  \\end{equation*}\n  Show that for any $a:A$, the map\n  \\begin{equation*}\n    \\lam{((x,y),p)} \\tr_B(p,y) : \\fib{\\proj 1}{a} \\to B(a),\n  \\end{equation*}\n  is an equivalence. Conclude that $\\proj 1$ is an equivalence if and only if each $B(a)$ is contractible.\n  \\index{family!fibers of projection map}\n  \\index{pr 1@{$\\proj 1$}!of contractible family is an equivalence}\n  \\index{is an equivalence!pr 1 of contractible family@{$\\proj 1$ of contractible family}}\n\\exercise \\label{ex:fib_replacement}Construct for any map $f:A\\to B$ an equivalence $e:\\eqv{A}{\\sm{y:B}\\fib{f}{y}}$ and a homotopy $H:f\\htpy \\proj 1\\circ e$ witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0em]\n      A \\arrow[rr,\"e\"] \\arrow[dr,swap,\"f\"] & & \\sm{y:B}\\fib{f}{y} \\arrow[dl,\"\\proj 1\"] \\\\\n      \\phantom{\\sm{y:B}\\fib{f}{y}} & B\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. The projection $\\proj 1 : (\\sm{y:B}\\fib{f}{y})\\to B$ is sometimes also called the \\define{fibrant replacement}\\index{fibrant replacement} of $f$, because first projection maps are fibrations in the homotopy interpretation of type theory.\n\\end{exercises}\n\\index{contractible type|)}\n", "meta": {"hexsha": "e904237bce6b990576de5585901832ebffab433d", "size": 23032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/contractible.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/contractible.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/contractible.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": 54.4491725768, "max_line_length": 482, "alphanum_fraction": 0.6934699548, "num_tokens": 7600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8267117983401364, "lm_q1q2_score": 0.6264775564926846}}
{"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*{Spurious Free Dynamic Range by means of Fast fourier transform}\n\n\\begin{par}\nExample for algorithm SFDR.\n\\end{par} \\vspace{1em}\n\\begin{par}\nCalculates SFDR by calculating FFT spectrum.\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}\nFirst quantity \\lstinline{y} representing 1 second of signal containing spurious component is prepared. 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 = 4; fnom = 100; phnom = 1; Onom = 0.2;\nt = [0:1/fsnom:1-1/fsnom];\nDI.y.v = Anom*sin(2*pi*fnom*t + phnom);\n\\end{lstlisting}\n\\begin{par}\nA spurious component with amplitude at 1/100 of main carrier frequency is added. Thus by definition the SFDR in dBc has to be 40.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDI.y.v = DI.y.v + Anom./100*sin(2*pi*fnom*3.5*t + phnom);\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{SFDR} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nDO = qwtb('SFDR', 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}\nResult is the SFDR (dBc).\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nSFDR = DO.SFDRdBc.v\n\\end{lstlisting}\n\n        \\begin{lstlisting}[style=output]\n\nSFDR =\n\n   40.0000\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "2df64dbdd009c4de6cc14f0dd5a194714f5eb054", "size": 2095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_SFDR.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_SFDR.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_SFDR.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": 23.2777777778, "max_line_length": 250, "alphanum_fraction": 0.7107398568, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117983401363, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6264775519705877}}
{"text": "\\documentclass[11pt]{article}\n\n\\input{preamble.tex}\n\n\\begin{document}\n    \n    % \\maketitle\n    \n    \\hypertarget{smooth-manifolds-made-concrete-for-dumbasses}{%\n\\section{Smooth Manifolds made Concrete for Dumbasses}\\label{smooth-manifolds-made-concrete-for-dumbasses}}\n\nThe intention behind this document is to provide an extended and comprehensive example of a smooth\nmanifold for dumbasses like me who can't always grok the heavily abstract without a more concrete\nexample, or as the OO framework types would say, a reification. The extended example is the\nprototypical/canonical stereographic projection considering the sphere \\(S^2\\) as a manifold.\nExamples cover deriving the charts, finding the inverses functions between manifolds including\nderiving an ellipsoid stereographic manifold, and tangent spaces including both equivalence classes\nof curves and derivation based approaches, illustrating proofs of vector space closure and change\nof basis of tangent vectors. The examples are based on using the open source\n\\href{https://www.sagemath.org/}{SageMath} Computer Algebra System (CAS) to create an interactive\nnotebook. Sage is available on most Linux distributions and the web site also has a Windows\ninstaller. The notebook has also been converted to a Latex/SageTex document which hides most of\nthe Sage specific manipulation and shows just the mathematics for those who aren't interested in\nSage (although you lose the ability to interact with the content including the graphs).\nNote Sage does have \n\\href{http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/manifold.html}{built in Manifold}\nsupport, but this document won't be using it as the intention is to provide examples from first principles.\nErrors or misunderstandings on my part or also more than likely as I am a computer scientist who dabbles in mathematics,\nfor Computer Vision, Machine Learning and Neural Networks, therefore any error corrections or suggestions \nfor improvements would also be welcome.\n\n\\begin{sagesilent}\nclear_vars()\n\ndef stereographic(pole):\n    o_n = vector(SR, pole)\n    var('x', 'y', 'z', 'u', 'v', 'l')\n    assume(x, 'real', y, 'real', z, 'real', u, 'real', v, 'real', l, 'real')\n#     p = vector(SR, (x, y, sqrt(x^2 + y^2)))\n    p = vector(SR, (x, y, z))\n    s = vector(SR, (u, v, 0))\n    lhs = o_n - p\n    rhs = l*(o_n - s)\n    eq1 = lhs[0] == rhs[0]\n    eq2 = lhs[1] == rhs[1]\n    eq3 = lhs[2] == rhs[2]\n    l_s = solve(eq3, l)[0].rhs()\n    return (solve(eq1.substitute(l=l_s), u)[0], solve(eq2.substitute(l=l_s), v)[0])\n\ndef the_solution(sols, submap):\n    for sol in sols:\n        if sol.rhs().substitute(submap) != 0:\n            return sol\n    return None\n\no_n = vector(SR, (0,0,1))\nvar('x', 'y', 'z', 'u', 'v', 'l')\nassume(x, 'real', y, 'real', z, 'real', u, 'real', v, 'real', l, 'real')\np = vector(SR, (x, y, z))\ns = vector(SR, (u, v, 0))\nlhs = o_n - p\nrhs = l*(o_n - s)\neq1 = lhs[0] == rhs[0]\neq2 = lhs[1] == rhs[1]\neq3 = lhs[2] == rhs[2]   \n\\end{sagesilent}\n\n\\hypertarget{the-stereographic-projection-atlas}{%\n\\subsection{The Stereographic Projection\nAtlas}\\label{the-stereographic-projection-atlas}}\n\nThe sterographic projection is the canonical example for a\ntopological/smooth manifold. The example shown here will map \\(S^2\\) to\n\\(R^2\\), although it can be extended to \\(S^n \\rightarrow R^n\\).\n\nThe sphere \\(S^2\\) is seen as a manifold having an atlas with two open\nsets and associated charts. The first chart is defined on the open set\ndefined by the full sphere excluding the north (top) pole \\((0,0,1)\\),\nwhile the second chart is defined on a set that excludes only the south\n(bottom) \\((0,0,1)\\) pole. Both charts project a point on the sphere\nsurface to the plane at \\(z=0\\) by extending a line from the excluded\npole through the point on the manifold (sphere) being charted onto the\nplane.\n\nTo derive the chart equation let \\(\\vec{o_n} = (0, 0, 1)\\),\n\\(\\vec{p_n} = (x, y, z)\\) be a point on the sphere and\n\\(\\vec{s_n} = (u, v, 0)\\) be the projection then (see the figure below):\n\n\\(\\vec{o_n} - \\vec{p_n} = l(\\vec{o_n} - \\vec{s_n}\\))\nwhich evaluates to: $\\sage{lhs} = \\sage{rhs}$\n    \n    Solving for the third component of the vector equation and substituting\ninto the first two:\n\n\\begin{sagesilent}\nsol1 = solve(eq3, l)[0]\nsol2 = solve(eq1, u)[0], solve(eq2, v)[0]\n\\end{sagesilent}\n\\begin{align*} \n    \\sage{sol1} \\\\\n    \\sage{sol2}\n\\end{align*}    \n    \n\\begin{sagesilent}\nOn = (0, 0, 1)\nOs = (0, 0, -1)\nCn = stereographic(On)\nCs = stereographic(Os)\ncn_0 = Cn[0].rhs()\ncn_1 = Cn[1].rhs()\ncs_0 = Cs[0].rhs()\ncs_1 = Cs[1].rhs()\n\\end{sagesilent}\n\n    \\(\\therefore\\) the charts with chart coordinates given by \\(u\\) and \\(v\\) are given by.\n\nNorth pole:\\\\\n\n$(\\sage{cn_0}, \\sage{cn_1})$    \n    \n    South pole:\\\\\n\n    $(\\sage{cn_0}, \\sage{cn_1})$    \n    \n    \\hypertarget{visualization}{%\n\\subsection{Visualization}\\label{visualization}}\n\nTo visualize the manifold and charts see Figure \\ref{fig:stereo1} which demonstrates manifold points\n\\((\\frac{1}{2}, \\frac{1}{2},\\frac{1}{\\sqrt{2}})\\) and \\((\\frac{1}{2}, \\frac{1}{2},-\\frac{1}{\\sqrt{2}})\\) \nprojected to the plane z = 0 (it does look a lot better in the original Jupyter notebook):\n\n\\begin{sagesilent}\nfrom sage.plot.plot3d.shapes2 import Line\ndef to_float(v): # Temp fix to convert to float from Sage type (see https://trac.sagemath.org/ticket/28949) for Sage 9\n    vv = [None] * len(v)\n    for i in range(0, len(v)):\n        vv[i] = float(v[i])\n    return vv    \ntwosq = 1/1.4142\nPn = (0.5, 0.5, twosq)\nPs = (0.5, 0.5, -twosq)\nSn = sphere(center=(0, 0, 0),size=1, color='green', aspect_ratio=[1,1,1], opacity=5/10)\nFn = plot3d(lambda x, y: 0, (-2,2), (-2,2))\non = point(On, rgbcolor=(1,0,0), size=20)\nos = point(Os, rgbcolor=(0,0,0), size=20)\npn = point(Pn, rgbcolor=(1,0,0), size=20)\ntpn = text3d('  (%.2f,%.2f,%.2f)'%(Pn[0], Pn[1], Pn[2]), (Pn[0], Pn[1], Pn[2]+0.2), horizontal_alignment='left',color='red', fonsize='x-small')\nps = point(Ps, rgbcolor=(0,0,0), size=20)\ntps = text3d('  (%.2f,%.2f,%.2f)'%(Ps[0], Ps[1], Ps[2]), (Ps[0], Ps[1], Ps[2]-0.2), horizontal_alignment='left',color='black', fonsize='x-small')\nBn = (Cn[0].substitute({x:Pn[0], z:Pn[2]}).rhs(), Cn[1].substitute({y:Pn[1], z:Pn[2]}).rhs(), 0)\nbn = point(Bn, rgbcolor=(0,0,0), size=20)\ntbn = text3d('  (%.2f,%.2f)'%(Bn[0], Bn[1]), (Bn[0], Bn[1]+0.6, 0.2), horizontal_alignment='left',color='red', fonsize='x-small')\nBs = (Cs[0].substitute({x:Ps[0], z:Ps[2]}).rhs(), Cs[1].substitute({y:Ps[1], z:Ps[2]}).rhs(), 0)\nbs = point(Bs, rgbcolor=(0,0,0), size=20)\n#Ln = Line([On, Pn, Bn], color='red')\n#Ls = Line([Os, Ps, Bs], color='black')\nLn = Line([to_float(On), to_float(Pn), to_float(Bn)], color='red')\nLs = Line([to_float(Os), to_float(Ps), to_float(Bs)], color='black')\n#show(Sn+Fn+on+pn+tpn+bn+tbn+os+ps+tps+bs+Ln+Ls, figsize=8)\nsave(Sn+Fn+on+pn+tpn+bn+tbn+os+ps+tps+bs+Line([On, Pn, Bn], color='red')+Line([Os, Ps, Bs], color='black'), \"stereo1.png\")\n\\end{sagesilent}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.95\\textwidth,keepaspectratio]{stereo1.png}\n    \\caption{Visualization of stereographic projection.}\n    \\label{fig:stereo1}\n \\end{figure}\n \n    \\hypertarget{chart-inverses}{%\n\\subsection{Chart Inverses}\\label{chart-inverses}}\n\\begin{sagesilent}\nvar('x', 'y', 'z', 'u', 'v', 'l')\nassume(x, 'real', y, 'real', z, 'real', u, 'real', v, 'real', l, 'real')\no_n = vector(SR, On)\nuv = vector(SR, (u, v, 0))\nd = (o_n - uv).normalized()\nLn = o_n + d*l\n\\end{sagesilent}\n\nThe above charts are bijective and continuous within the domain\n\\(S^2 - (0, 0, 1), S^2 - (0, 0, -1)\\) and codomain \\((u, v) \\in R^2\\),\nhowever to be valid charts they must also be bicontinuous, ie the\ninverse must be continuous too, that is they must be homeomorphic to\n\\(R^2\\).\n\nTo find the inverse first find the unit vector in the direction of the\nline joining the pole to the projected coordinates, for example\n\\(\\vec{d} = \\frac{((0, 0, 1) - (u, v, 0))}{|(0, 0, 1) - (u, v, 0))|}\\) = $\\sage{d}$.\n        \n    Now express the line from the pole to the projection as a vector\nequation:\\\\ \n\\((0, 0, 1) + l \\vec{d}\\) = $\\sage{Ln}$\n\n\\begin{sagesilent}\nc_o = vector(SR, (0, 0, 0))\neq4 = (Ln - c_o).dot_product(Ln - c_o) == 1\nsols = solve(eq4, l)\nsolution = the_solution(sols, {u:1, v:1})\nIn = (Ln - c_o).substitute(l=solution.rhs())\npretty_print(In)\ncn_ix = In[0]\ncn_iy = In[1]\ncn_iz = In[2]\n\\end{sagesilent}\n    \n    The intersection of this line with the sphere occurs where\n\\(|(0, 0, 1) + l\\vec{d} - (0, 0, 0)| = 1\\), or more generally\n\\(|(0, 0, 1) + l\\vec{d} - \\vec{c}| = r\\) where \\(\\vec{c}\\) is the sphere\ncentre and r is the radius. This can also be expressed as\n\\([(0, 0, 1) + l\\vec{d} - (0, 0, 0)] \\cdot [(0, 0, 1) + l\\vec{d} - (0, 0, 0)] = r\\):\\\\\n$\\sage{eq4}$\n    \n    This quadratic will have one solution for \\(l = 0\\) at the pole. The\nother solution will be the required \\((x, y, z)\\) on the sphere\nmanifold. Letting Sage do the PT:\\\\\n% \\begin{tcolorbox}\n% sols = solve(eq4, l)\\\\\n% \\end{tcolorbox}\n$\\sage{sols}$\n\n    and substituting the appropriate \\(l\\) back into the line equation:\\\\\n $\\sage{In}$   \n    \n    See also the\n\\href{https://en.wikipedia.org/wiki/Line\\%E2\\%80\\%93sphere_intersection}{Wikipeadia}\npage on sphere-line intersection (note their notation swops \\(\\vec{d}\\)\nand \\(l\\) as used in the above).\n\n\\begin{sagesilent}\no_s = vector(SR, Os)\nd = (o_s - uv).normalized()\nLs = o_s + d*l\neq5 = (Ls - c_o).dot_product(Ls - c_o) == 1\nsols = solve(eq5, l)\nsolution = the_solution(sols, {u:1, v:1})        \nIs = (Ls - c_o).substitute(l=solution.rhs())\ncs_ix = Is[0]\ncs_iy = Is[1]\ncs_iz = Is[2]    \n\\end{sagesilent}\n    \n    Similarly the inverse for the south pole chart is given by (it could\nprobably also be derived by symmetry):\\\\\n$\\sage{Is}$\n    \n    \\hypertarget{verifying-the-charts}{%\n\\subsection{Verifying the Charts}\\label{verifying-the-charts}}\n\\begin{sagesilent}\n    uu = cs_0.substitute({x: cn_ix, z: cn_iz}).full_simplify()\n    vv = cs_1.substitute({y: cn_iy, z: cn_iz}).full_simplify()\n    pretty_print(\"(\", uu, \", \", vv, \")\")    \n\\end{sagesilent}\n\n    The two charts described above are homeomorphic and are also\ndifferentiable with a differentiable inverse, therefore they are\ndiffeomorphic too. Assume the charts are named \\(c_n\\) and \\(c_s\\), then\nto verify the two charts define a compatible atlas it is required that\nthe intersection of their domain open sets be empty ie\n\\(S^2 - (0, 0, 1) \\cap S^2 - (0, 0, -1) = \\emptyset,\\) (definitely not\nthe case) or\n\\(c_s \\circ c_n^{-1} : c_n(S^2 - (0, 0, 1) \\cap S^2 - (0, 0, -1)) \\rightarrow c_s(S^2 - (0, 0, 1) \\cap S^2 - (0, 0, -1))\\)\nand the opposite (\\(c_n \\circ c_s^{-1}\\)) is diffeomorphic. After\nperforming the composition we get:\\\\\n$(\\sage{uu}, \\sage{vv})$\n\n    which is homeomorphic and smooth over the specified domain.\n\n    \\hypertarget{smooth-functions-between-manifolds}{%\n\\subsection{Smooth Functions between\nManifolds}\\label{smooth-functions-between-manifolds}}\n\nA smooth map \\(F: M \\rightarrow N\\) can be described \\parencite{lee} as\n\\say{if for every \\(p \\in M\\), there exist smooth charts\n\\((U, \\phi)\\) containing \\(p\\) and \\((V, \\psi)\\) containing \\(F(p)\\)\nsuch that \\(F(U) \\subseteq V\\) and the composite map\n\\(\\psi \\circ F \\circ \\phi^{-1}\\) is smooth from \\(\\phi(U)\\) to\n\\(\\psi(V)\\)}.\n\nWe will start by defining a manifold E on an ellipsoid to use as the\ndestination manifold corresponding to N above for the map. U will then\ncorrespond to either \\(S^2 - (0, 0, 1)\\) or \\(S^2 - (0, 0, -1)\\)\ndepending on the source chart selection. N will similarly correspond to\n\\(E - (0, 0, 1)\\) or \\(E - (0, 0, -1)\\). Because E uses $ (0, 0, 1)$\nand $(0, 0, -1)$ the a and b ellipse axes are arbitarily defined but\n\\(c = 1\\) (the z semi-axis) to ensure that the poles are at\n\\((0, 0, 1)\\) and \\((0, 0, -1)\\).\n\n\\hypertarget{the-ellipsoid-as-a-stereographical-manifold}{%\n\\subsubsection{The Ellipsoid as a Stereographical Manifold}\\label{the-ellipsoid-as-a-stereographical-manifold}}\n\\begin{sagesilent}\nen_0 = cn_0\nen_1 = cn_1\nes_0 = cs_0\nes_1 = cs_1\nvar('x', 'y', 'z', 'u', 'v', 'l', 'a', 'b', 'c')\nassume(x, 'real', y, 'real', z, 'real', u, 'real', v, 'real', l, 'real', a, 'real', b, 'real', c, 'real')\no_n = vector(SR, (0, 0, 1))\nuv = vector(SR, (u, v, 0))\nd = (o_n - uv).normalized()\nLn = o_n + d*l - vector(SR, (0, 0, 0))\n\\end{sagesilent}\n    \nThe chart map from the ellipsoid to \\(R^2\\) can be derived similarly to\nthe sphere,resulting in \\(u=-\\frac{x}{z-1}, v=-\\frac{y}{z-1}\\) for the\nnorth chart and \\(u=\\frac{x}{z+1}, v=\\frac{y}{z+1}\\), but with \\(z\\)\ncalculated for the ellipse. The inverse is a little more problematic\nhowever. As with the sphere start by describing the line from the pole\nto the projection in terms of a unit vector pointing in the direction of\nthe line:\n\\begin{equation}\n\\label{eq:ellipsoid-line}\n\\scriptstyle\nL = (0, 0, 1) + l \\frac{(0, 0, 1) - (u, v, 0)}{|(0, 0, 1) - (u, v, 0)|} = \\sage{Ln}\n\\end{equation}\n    \n    Recall that a vector equation for an ellipsoid can be\n\\href{https://en.wikipedia.org/wiki/Ellipsoid\\#In_general_position}{defined}\nas \\((\\mathbf{x}-\\mathbf{o})^{\\mathrm{T}} A(\\mathbf{x}-\\mathbf{o})=1\\)\nwhere \\(0\\) is the origin coordinates and A is a positive definite\nmatrix which in the general case may include rotation, but in our case\ncontains only the ellipsoid axes:\\\\\n\\begin{sagesilent}\nA = matrix(SR, 3, 3, [1/a^2, 0, 0,  0, 1/b^2, 0,   0, 0, 1]) # c = 1 to make (0,0,1) possible\nel = Ln.row()*A*Ln\neq1 = el[0] == 1\nsols = solve(eq1, l)\n\\end{sagesilent}\n$\\sage{A}$\n    \nThe ellipsoid equation is then \\(L^T A L\\):\\\\\n$\\sage{eq1}$\n    \nwith two solutions again with one at 0 corresponding to the pole:\\\\\n$\\sage{sols}$\n    \nSubstituting back into \\(L\\) (Equation \\ref{eq:ellipsoid-line}):\\\\\n\\begin{sagesilent}\nsolution = the_solution(sols, {u:1, v:1, a:1, b:1})        \nEIn = Ln.substitute(l=solution.rhs())\nen_ix = EIn[0]\nen_iy = EIn[1]\nen_iz = EIn[2]\n\no_s = vector(SR, (0, 0, -1))\nd = (o_s - uv).normalized()\nLs = o_s + d*l - vector(SR, (0, 0, 0))\nel = Ls.row()*A*Ls\neq1 = el[0] == 1\nsols = solve(eq1, l)\nsolution = the_solution(sols, {u:1, v:1, a:1, b:1})          \nEIs = Ls.substitute(l=solution.rhs())\nes_ix = EIs[0]\nes_iy = EIs[1]\nes_iz = EIs[2]\n\\end{sagesilent}\n$\\sage{EIn}$\n    \nSimilarly for the south pole we get:\\\\\n$\\sage{EIs}$\n    \n    \\hypertarget{defining-the-inter-manifold-function}{%\n\\subsection{Defining the Inter-Manifold\nFunction}\\label{defining-the-inter-manifold-function}}\n\\begin{sagesilent}\nT = matrix(SR, 3, 3, [a, 0, 0,  0, b, 0,   0, 0, 1]) \nev = vector(SR, (x, y, sqrt(1 - x^2 - y^2)))\nF = T*ev\nFx = F[0]\nFy = F[1]\nFz = F[2]    \nEllips = F.substitute({x: cn_ix, y: cn_iy})\n# pretty_print(Ellips)\nf1 = en_0.substitute({x:Ellips[0], z:Ellips[2]}).full_simplify()\nf2 = en_1.substitute({y:Ellips[1], z:Ellips[2]}).full_simplify()\n\\end{sagesilent}\n\nA linear transformation applied to a sphere results in an ellipse. In\nthis case we use a linear transformation matrix:\\\\\n$\\sage{T}$\n\nApplied to $\\sage{ev}$  resulting in \\(F: S \\rightarrow E\\) where S is the sphere manifold and E\nis the ellipsoid one:\\\\\n$F = \\sage{F}$\n    \n    Let the ellipse chart be \\((V, e_n): V \\subset E\\) (or\n\\((V, e_s): V \\subset E\\)) and the sphere chart be\n\\((U, s_n): U \\subset S\\) (or \\((U, s_s): U \\subset S\\)), then\n\n\\(e_n \\circ F \\circ s_n^{-1}[s_n(U)]\\)\n\nshould be a smooth function from \\(R^2\\) (the stereographic projection\ncoordinates for the sphere) to \\(R^2\\) (the stereographic projection\ncoordinates for the ellipse) (its probably best to take Sage's word for\nit unless you \\textbf{really} enjoy Algebra):\\\\\n$\\Bigg(\\sage{f1}, \\sage{f2}\\Bigg)$\n    \n    \\hypertarget{tangent-vectors-and-spaces}{%\n\\subsection{Tangent Vectors and\nSpaces}\\label{tangent-vectors-and-spaces}}\n\nConfusingly there are three different approaches to defining tangent\nspaces on manifolds \\parencite{montgomery}. These examples will\ncover the geometrically based curve approach and the more algebraic\nderivation approach. \n\n\\subsubsection{Tangent Spaces defined as Equivalence class of Curves}\n This approach starts with a curve with a domain on an\ninterval of \\(R^1\\) and the manifold \\(M\\) as the co-domain i.e\n\\(\\lambda: I \\subset R^1 \\rightarrow M\\). The simplest approach combines the\nco-domain of the curve with a chart map to define curves as being\ntangent at a point \\(p\\) if \\parencite[see][pp. 73]{isham}: \n\\begin{enumerate}\n    \\item Values on the manifold correspond ie \\(\\lambda_{1}(t_0) = \\lambda_{2}(t_1) = p\\),\n    \\item The velocities at the point in a chart are the same ie\n    \\((c_n \\circ \\lambda_{1})^\\prime\\lvert_{t=t_0} = (c_n \\circ \\lambda_{2})^\\prime\\lvert_{t=t_1}\\)\n\\end{enumerate}\n\nThe curve used in the example is a spiral on \\(S^2\\) (from\n\\href{https://math.stackexchange.com/questions/140541/finding-parametric-curves-on-a-sphere}{math.stackexchange})\n\n\\(\\lambda_1 = (x, y, z): (\\sqrt{1-t^{2}} \\cos (a \\pi t), \\sqrt{1-t^{2}} \\sin (a \\pi t), t)\\)\n\nTo find the geometric tangent vector at a point we use the north pole\nchart to project a point from the manifold specified by the curve to the\n\\(R^2\\) Euclidean space of the stereographic projection:\\\\\n\\begin{sagesilent}\nvar('s', 't', 'p_4', 'a', 'pt')\na = 3\npt = 4/5\np_4 = pi/a\nK_1 = (sqrt(1-t*t)*cos(7*pi*t), sqrt(1-t*t)*sin(7*pi*t), t)\nT1 = vector(SR, (cn_0.substitute({x:K_1[0], z:K_1[2]}), cn_1.substitute({y:K_1[1], z:K_1[2]})))\nV = T1.diff(t)\n\\end{sagesilent}\nAs a reminder, the north chart: $(\\sage{cn_0}, \\sage{cn_1})$\\\\\n$(c_n \\circ \\lambda_1) = \\sage{T1}$\n    \nNext we differentiate the above to get the tangent vector:\\\\\n$\\scriptstyle \\sage{V}$\n    \nNext to find another tangent vector with the necessary properties\n(having the same value in the manifold at \\(t\\) and equal velocity\n(derivitive) in the chart), we find the inverse of the tangent line in\nthe chart which results in a circle in the manifold (\\(s\\) is the\nparametric variable for the tangent line/circle) \n$\\sage{T1.substitute(t=pt).n(digits=4)} + s \\sage{V.substitute(t=pt).n(digits=4)}$:\\\\\n\\begin{sagesilent}\nTn = T1.substitute(t=pt) + V.substitute(t=pt)*s # Tangent line in projection\nTm = vector(SR, (cn_ix.substitute(u=Tn[0], v=Tn[1]), cn_iy.substitute(u=Tn[0], v=Tn[1]), cn_iz.substitute(u=Tn[0], v=Tn[1]))).simplify_full()\n\\end{sagesilent}\n$\\lambda_2 = \\sage{Tm}$\n    \nPlotting the results on the manifold (Figure \\ref{fig:stereo2}):\\\\\n\\begin{sagesilent}\nSn = sphere(center=(0, 0, 0),size=1, color='green', aspect_ratio=[1,1,1], opacity=0.7)\ncurv_1 = parametric_plot3d(K_1, (t,-1,1), color='red')\ncurv_2 = parametric_plot3d(Tm, (s,-1,1), color='blue')\nPn = (K_1[0].substitute(t=pt).n(), K_1[1].substitute(t=pt).n(), K_1[2].substitute(t=pt).n())\n#Pn = (K_2[0].substitute(t=iss).n(), K_2[1].substitute(t=iss).n(), K_2[2].substitute(t=iss).n())\npn = point(Pn, rgbcolor=(1,0,0), size=20)\nsave(Sn+curv_1+curv_2+pn, \"stereo2.png\")\n\\end{sagesilent}\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.95\\textwidth,keepaspectratio]{stereo2.png}\n    \\caption{Visualization of tangent vector curves}\n    \\label{fig:stereo2}\n \\end{figure}\n    \n    Verifying the two curves satisfy the equivalence class criteria:\\\\\n    \\textbf{Value on Manifold}:\\\\\n    $(\\sage{K_1[0].substitute(t=pt).n(digits=7)}, \\sage{K_1[1].substitute(t=pt).n(digits=7)}, \\sage{K_1[2].substitute(t=pt).n(digits=7)})$\\\\\n    $(\\sage{Tm.substitute(s=0).n(digits=7)})$\\\\\n    \\textbf{Velocity in chart}:\\\\\n    $\\sage{V.substitute(t=pt).n(digits=7)}$\\\\\n    $\\sage{Tn.diff(s).substitute(s=0).n(digits=7)}$\\\\\n    \n    \\hypertarget{derivation-based-approach}{%\n\\subsection{Derivation based Approach}\\label{derivation-based-approach}}\n\nA derivation at a point in a \\(C^\\infty\\) manifold is defined to be a\nlinear map \\(D(C^\\infty) \\rightarrow R\\),\n\n\\((D_{1}+D_{2})(f) = D_{1}(f)+D_{2}(f)\\)\n\n\\((\\lambda D)(f) = \\lambda D(f)\\) which also obeys the Leibnitz identity\n\\(D(f g)=D(f) \\cdot g(x)+f(x) \\cdot D(g)\\).\n\nComputer science types could see the derivation as defining an abstract\ninterface, with the actual derivitive being a concrete class\nimplementing the abstract interface.\n\nSee \\textcite{parzygnat} (lecture 12 part 3) for a description of\nderivations and associated associative algebra (in a Euclidean manifold\ncontext, but most of what is covered also applies to general manifolds,\nother than the manifold chart map directions are inverted).\n\nA tangent vector can then be applied to a \\(C^\\infty\\) function \\(f\\) given a curve \\(\\lambda\\) by\n\\(D(f \\circ \\lambda)[t]\\) where \\(\\lambda(t) = \\vec{p} \\in M\\) where \\(\\vec{p}\\) is the point in\nthe manifold where the tangent is taken. The derivation based velocities defined this way should\nform a vector space similarly to the previous section tangent vectors which can fairly easily be\nshown to form a vector space by adding/multiplying in chart space \\parencite[see][pp. 76]{isham} .\nProving a vector space using the \\(D(f \\circ \\lambda)[t]\\) approach is a little more difficult.\nAdditive closure is covered quite lengthily in lesson 9 of \\textcite{XylyXylyX} and more concisely\nby \\textcite{schuller} lecture 5, while Schuller also covers scalar multiplication.\n\nThe above proofs are regurgitated here for documentary purposes as I\ncouldn't find a book containing the proofs. Intermediate results in the\nproofs are also illustrated using the stereographic example.\n\nMultivariable differentation is denoted, as for derivations, with a \\(D\\) operator. For\nmultivariable functions and maps the differentation result will be a Jacobian, and in many cases\nwith tangent spaces mapping to \\(R^1\\) will be vectors, although transition maps between charts for\nexample will be matrices. In some cases the differention operator \\(D\\) will be subscripted with\nthe variables w.r.t. which the differentiation is taking place eg \\(D_t\\). This is in contrast with\nmany physics books which use the old fashioned multiple different chain rules to extensively\nutilize component indexing, instead of one chain rule using linear transformations with Jacobian\nmatrices applying in all cases (as for example in \\textcite{spivak} or more colorfully in\n\\textcites{ghrist}{ghrist-youtube}). Where applicable the comparable `standard' notation will also\nbe shown.\n\nWe will continue to use the curves defined in the previous section. We\nalso define \\(f(\\vec{p}) : S \\rightarrow R = 2x + 2y + 2z\\) (where z is\nconstrained to be on the manifold ie \\(z = \\sqrt{1 - x^2 - y^2}\\)). Now\n\\(D(f \\circ \\lambda_1)\\) and \\(D(f \\circ \\lambda_2)\\) are velocities:\\\\\n\\begin{sagesilent}\nvar('x', 'y', 'z')\nf = 2*x + 2*y + 2*z\nd1 = f.substitute(x = K_1[0], y = K_1[1], z = K_1[2]).diff(t)\nd2 = f.substitute(x = Tm[0], y = Tm[1], z = Tm[2]).diff(s) #.full_simplify()\n#print(latex(d2)) # Manually split the output\n\\end{sagesilent}\n\n$\\scriptstyle (f \\circ \\lambda_1)^\\prime = \\sage{d1}$\n\\begin{multline*}\n    \\scriptstyle\n    (f \\circ \\lambda_2)^\\prime = \n    \\frac{4 \\, {({(3969 \\, \\pi^{2} + 625)} s + 225)}}{{(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90} - \n    \\frac{4 \\, {({(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 72)} {({(3969 \\, \\pi^{2} + 625)} s + 225)}}{{({(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90)}^{2}} -\\\\\n    \\scriptstyle\n    \\frac{6 \\, {(63 \\, \\pi s {(\\sqrt{5} - 1)} - {(25 \\, s + 9)} \\sqrt{2 \\, \\sqrt{5} + 10})} {({(3969 \\, \\pi^{2} + 625)} s + 225)}}{{({(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90)}^{2}} - \n    \\frac{6 \\, {(63 \\, \\pi s \\sqrt{2 \\, \\sqrt{5} + 10} + 25 \\, s {(\\sqrt{5} - 1)} + 9 \\, \\sqrt{5} - 9)} {({(3969 \\, \\pi^{2} + 625)} s + 225)}}{{({(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90)}^{2}} +\\\\ \n    \\scriptstyle\n    \\frac{3 \\, {(63 \\, \\pi {(\\sqrt{5} - 1)} - 25 \\, \\sqrt{2 \\, \\sqrt{5} + 10})}}{{(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90} +\n    \\frac{3 \\, {(63 \\, \\pi \\sqrt{2 \\, \\sqrt{5} + 10} + 25 \\, \\sqrt{5} - 25)}}{{(3969 \\, \\pi^{2} + 625)} s^{2} + 450 \\, s + 90}\n\\end{multline*}\n    \n    To demonstrate the curves form a vector space (for this example anyway), before providing a proof (of closure under addition and scalar multiplication\n    - the rest is left as an exercise for the reader \\smiley{}) we first set  $\\lambda_3 = \\lambda_1 + \\lambda_2$ and then substituting the values for the \n    intersection point specified by $s = 0$ and $t = \\frac{4}{5}$ into the three different velocities.\\\\\n\\begin{sagesilent}\nK_3 = vector(SR, ( (K_1[0] + Tm[0]).full_simplify(), (K_1[1] + Tm[1]), (K_1[2] + Tm[2]) ) ).simplify_full()\nd3 = f.substitute(x = K_3[0], y = K_3[1], z = K_3[2]).diff(s).full_simplify()\n\\end{sagesilent}   \n$(D(f \\circ \\lambda_1)[\\sage{pt}] = \\sage{d1.substitute(t=pt).n(digits=7)}$\\\\\n$(D(f \\circ \\lambda_2)[0] = \\sage{d2.substitute(s=0).n(digits=7)}$\\\\\n$(D(f \\circ \\lambda_3)[\\sage{pt}] = \\sage{d3.substitute(s=0, t=pt).n(digits=7)}$\\\\\n% \\begin{multline*}\n% \\scriptscriptstyle\n% \\lambda_3 = -\\frac{750141 \\, \\sqrt{5} \\pi^{3} s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{750141 \\, \\pi^{3} s^{2} \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\\n% \\scriptscriptstyle \\frac{750141 \\, \\pi^{3} s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\\n% \\scriptscriptstyle \\frac{297675 \\, \\sqrt{5} \\pi^{2} s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{297675 \\, \\pi^{2} s^{2} \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{297675 \\, \\pi^{2} s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{214326 \\, \\sqrt{5} \\pi^{2} s}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{118125 \\, \\sqrt{5} \\pi s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{214326 \\, \\pi^{2} s \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{118125 \\, \\pi s^{2} \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\\n% \\scriptscriptstyle \\frac{500094 \\, \\pi^{2} s}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\\n% \\scriptscriptstyle \\frac{118125 \\, \\pi s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{46875 \\, \\sqrt{5} s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{46875 \\, s^{2} \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{46875 \\, s^{2}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{17010 \\, \\sqrt{5} \\pi}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{33750 \\, \\sqrt{5} s}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{17010 \\, \\pi \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{33750 \\, s \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{17010 \\, \\pi}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{78750 \\, s}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} -\\\\ \n% \\scriptscriptstyle \\frac{5400 \\, \\sqrt{5}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{5400 \\, \\sqrt{2 \\, \\sqrt{5} + 10}}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100} +\\\\ \n% \\scriptscriptstyle \\frac{21600}{15752961 \\, \\pi^{4} s^{4} + 4961250 \\, \\pi^{2} s^{4} + 3572100 \\, \\pi^{2} s^{3} + 714420 \\, \\pi^{2} s^{2} + 390625 \\, s^{4} + 562500 \\, s^{3} + 315000 \\, s^{2} + 81000 \\, s + 8100}\n% \\end{multline*}\n\n    \\hypertarget{additive-closure-proof}{%\n\\subsubsection{Additive Closure Proof}\\label{additive-closure-proof}}\n\nThe proof starts with a construction, which given two existing curves\n\\(\\lambda_1,\\lambda_2\\) intersecting at point \\(\\vec{p}\\) at parameter\nvalues \\(t_1\\) and \\(t_2\\), constructs a third curve \\(\\lambda_3\\) also\nintersecting \\(\\vec{p}\\) at a parameter \\(t_3\\) ie\n\\(\\lambda_1(t_1) = \\lambda_2(t_2) = \\lambda_3(t_3) = \\vec{p}\\):\n\n\\(\\lambda_3(t) = c^{-1}\\{ (c \\circ \\lambda_1)[t_1 + t] + (c \\circ \\lambda_2)[t_2 + t] - (c \\circ \\lambda_1)[t_1]\\}\\)\n\nAt \\(t = 0\\) this evaluates to\n\\(c^{-1}\\{ c(\\vec{p}) + c(\\vec{p}) - c(\\vec{p}) \\} = c^{-1}(c(\\vec{p})) = \\vec{p}\\)\nso \\(t_3 = 0\\). Checking this construct results in the same values as\nthe other two curves:\\\\\n\\begin{sagesilent}\nt1 = vector(SR, (cn_0.substitute(x=K_1[0], z=K_1[2]).substitute(t=t+pt), cn_1.substitute(y=K_1[1], z=K_1[2]).substitute(t=t+pt)))\nt2 = vector(SR, (cn_0.substitute(x=Tm[0], z=Tm[2]), cn_1.substitute(y=Tm[1], z=Tm[2]))).substitute(s=t+0)\nt3 = vector(SR, (cn_0.substitute(x=K_1[0], z=K_1[2]), cn_1.substitute(y=K_1[1], z=K_1[2]))).substitute(t=pt)\ntt = t1 + t2 - t3\nK3 = vector(SR, (cn_ix.substitute(u=tt[0], v=tt[1]), cn_iy.substitute(u=tt[0], v=tt[1]), cn_iz.substitute(u=tt[0], v=tt[1]))).simplify_full()\n\\end{sagesilent}\n$\\textbf{Value on Manifold:}~~\" \\sage{K3.substitute(t=0).n(digits=7)}$\n    \n    Because the third curve parameter \\(t_3\\) evaluates to 0, we can\ntherefore write the velocity vector for \\(\\lambda_3\\) at \\(\\vec{p}\\) as\n\\((f \\circ \\lambda_3)^\\prime[t_3 = 0]\\).\n\nInserting a chart and its inverse and using associativity results in\n\n\\(\\{(f \\circ c^{-1}) \\circ (c \\circ \\lambda_3)\\}^\\prime[0]\\).\n\nUsing the chain rule with the \\(f \\circ c^{-1}\\) as the outer function:\n\n\\(D(f \\circ c^{-1})[(c \\circ \\lambda_3)[0])~D(c \\circ \\lambda_3)[0]\\)\n\nSubstituting the expression for \\(\\lambda_3\\) into the right side term:\n\n\\(D(c \\circ \\lambda_3)[0] = D(c \\circ c^{-1}\\{ (c \\circ \\lambda_1)[t_1 + t] + (c \\circ \\lambda_2)[t_2 + t] - (c \\circ \\lambda_1)[t_1]\\}) =\\)\n\n\\(D((c \\circ c^{-1} \\circ c \\circ \\lambda_1))[t_1 + t] + (c \\circ c^{-1} \\circ c \\circ \\lambda_2)[t_2 + t]) - (c \\circ c^{-1} \\circ c \\circ \\lambda_1))[t_1])\\)\n(distributivity, associativity)\n\nThe third term is not dependent on \\(t\\) so the derivitive would be\n\\(0 \\therefore\\) is will disappear and the inner \\(c^{-1} \\circ c\\) in\nthe other terms will cancel leaving:\n\n\\(D((c \\circ \\lambda_1))[t_1 + t] + (c \\circ \\lambda_2)[t_2 + t]))[0] = D(c \\circ \\lambda_1)[t_1] + D(c \\circ \\lambda_2)[t_2]\\)\n\n    The left hand term can also be simplified:\n\n\\(D(f \\circ c^{-1})[(c \\circ \\lambda_3)[0]) \\equiv D(f \\circ c^{-1})[(c \\circ \\lambda_3[0])) = D(f \\circ c^{-1})[c(\\vec{p})]\\)\n\nas \\(\\lambda_3[0] = \\vec{p}\\) by construction.\n\nRecombining the simplified left and right sides:\n\n\\begin{equation}\n\\label{eq:addition-close}    \n\\scriptstyle\nD(f \\circ c^{-1})[c(\\vec{p})] \\cdot (D(c \\circ \\lambda_1)[t_1] + D(c \\circ \\lambda_2)[t_2]) = D(f \\circ c^{-1})[c(\\vec{p})] D(c \\circ \\lambda_1)[t_1] + D(f \\circ c^{-1})[c(\\vec{p})] D(c \\circ \\lambda_2)[t_2])\n\\end{equation}\n\nUsing the chain rule to differentiate \\(D(f \\circ \\lambda_1)[t_1]\\) to show that it is the same as the first term above:\n\n\\(D(f \\circ \\lambda_1)[t_1] = D((f \\circ c^{-1}) \\circ (c \\circ \\lambda_1))[t_1] =\\)\n\n\\(D(f \\circ c^{-1})[(c \\circ \\lambda_1)[t_1]] \\cdot D(c \\circ \\lambda_1)[t_1] =\\)\n\n\\(D(f \\circ c^{-1})[(c(\\vec{p})] \\cdot D(c \\circ \\lambda_1)[t_1]\\)\n\nwhich is the first term in the previous expression (Equation \\ref{eq:addition-close}) (combining the\nsimplified left and right sides).\n\nSimilarly the second term\n\\(D(f \\circ c^{-1})[c(\\vec{p})] D(c \\circ \\lambda_2)[t_2])\\) can be\nshown by reversing the chain rule to be\n\\(D(f \\circ \\lambda_2)[t_2] \\therefore\\) the equation that shall remain\nunnumbered can be reduced to:\n\n\\(D(f \\circ \\lambda_1)[t_1] + D(f \\circ \\lambda_2)[t_2]\\)\n\nwhich proves closure under addition of velocity vectors in the tangent space. We can verify the above terms for our concrete example:\\\\\n\\begin{sagesilent}\nfl1 = f.substitute(x=K_1[0], y=K_1[1], z=K_1[2]).simplify_full()\nfl2 = f.substitute(x=Tm[0], y=Tm[1], z=Tm[2]).simplify_full()\nfl3 = f.substitute(x=K3[0], y=K3[1], z=K3[2]).simplify_full()\nvv1 = fl1.diff(t).substitute(t=pt).n(digits=7)\nvv2 = fl2.diff(s).substitute(s=0).n(digits=7)\nvv3 = fl3.diff(t).substitute(t=0).n(digits=7)\n\\end{sagesilent}\n$f \\circ \\lambda_{1,2,3} = \\sage{fl1.substitute(t=pt).n(digits=7)}, \\sage{fl2.substitute(s=0).n(digits=7)}, \\sage{fl3.substitute(t=0).n(digits=7)}$\\\\\n$D(f \\circ \\lambda_1) + D(f \\circ \\lambda_2) = \\sage{vv1} + \\sage{vv2} = \\sage{vv1+vv2} = D(f \\circ \\lambda_3) = \\sage{vv3}$\n    \n\\hypertarget{scalar-multiplication-closure}{%\n\\subsubsection{Scalar Multiplication\nClosure}\\label{scalar-multiplication-closure}}\n\nProving closure under scalar multiplication is easier and does not\ninvolve any charts. Again start with a construction for the new curve\n\\(\\lambda_3\\) tangent at \\(\\vec{p}\\) ie\n\\(\\lambda_1(t_1) = \\lambda_3(t_3) = \\vec{p}\\) in terms of \\(\\lambda_1\\):\n\n\\(\\lambda_3(t) = \\lambda_1(a t + t_1) = (\\lambda_1 \\circ u_a)[t_3]~~a \\in R,~u_a(t) :R \\rightarrow R = a t + t_1\\)\n\nAt \\(t = 0\\) this evaluates to\n\\(\\lambda_3(0) = \\lambda_1(0 \\cdot a + t_1) = \\lambda_1(t_1) = \\vec{p}\\)\nso \\(t_3 = 0\\).\n\n\\(D(f \\circ \\lambda_3)[t_3] = D(f \\circ \\lambda_3)[0] = D((f \\circ \\lambda_1) \\circ u_a)[0]\\)\n\nApplying the chain rule:\n\n\\(D(f \\circ \\lambda_1)[u_a(0)] \\cdot D(u_a)[0] = D(f \\circ \\lambda_1)[t_1] \\cdot a = a D(f \\circ \\lambda_1)[t_1]\\)\n\nwhich proves closure under scalar multiplication.\n\n    \\hypertarget{chart-realizations-for-tangent-space}{%\n\\subsection{Chart Realizations for Tangent\nSpace}\\label{chart-realizations-for-tangent-space}}\n\nWe start by introducing a chart \\(c\\) into a velocity vector applied to\nan arbitrary function \\(f\\) for a curve\n\\(\\lambda(t_1) = \\vec{p} \\in U \\subseteq M\\):\n\n\\(D((f \\circ c^{-1}) \\circ (c \\circ \\lambda))[t_1]\\)\n\nApplying the chain rule once again:\n\n\\(D_{u,v}(f \\circ c^{-1})[c \\circ \\lambda(t_1)] \\cdot D_t(c \\circ \\lambda)[t_1] = D_t(c \\circ \\lambda)[t_1] \\cdot D_{u,v}(f \\circ c^{-1})[c(\\vec{p})]\\)\n\nThe representation of derivation based tangent space vectors w.r.t\ncharts as used above in the proofs is quite complicated, so a simplified\nrepresentation, otherwise known as syntactic sugar in the computer\nscience community, is conventionally used, particularly in Physics,\nwhich is shown here along with an example.\n\nWe start by investigating what the left and right hand sides of the\nabove look like for a concrete example using the north chart of the\nstereographic projection and the spiral curve on the sphere. To do this\nwe take the Jacobian of both sides and then do matrix multiplication (or\ndot product as they are both vectors) on the jacobians:\\\\\n\\begin{sagesilent}\nt1 = vector(SR, (cn_0.substitute(x=K_1[0], z=K_1[2]), cn_1.substitute(y=K_1[1], z=K_1[2])))\nlhs = jacobian(t1, (t)).transpose()\n\n_pp = vector(SR, (cn_0.substitute(x=Pn[0], z=Pn[2]), cn_1.substitute(y=Pn[1], z=Pn[2])))\n_f = f.substitute(x=cn_ix, y=cn_iy, z=cn_iz).simplify_full()\nrhs = jacobian(_f, [u,v])\nres = (lhs.substitute(t=pt)*rhs.transpose().substitute({u:_pp[0], v:_pp[1]})).n(digits=6)\n\\end{sagesilent}\n\\begin{multline*}\n    \\scriptstyle LHS = \n\\left(\\begin{array}{rr}\n    \\scriptstyle \n    \\frac{7 \\, \\pi \\sqrt{-t^{2} + 1} \\sin\\left(7 \\, \\pi t\\right)}{t - 1} + \\frac{t \\cos\\left(7 \\, \\pi t\\right)}{\\sqrt{-t^{2} + 1} {\\left(t - 1\\right)}} + \\frac{\\sqrt{-t^{2} + 1} \\cos\\left(7 \\, \\pi t\\right)}{{\\left(t - 1\\right)}^{2}} & -\\frac{7 \\, \\pi \\sqrt{-t^{2} + 1} \\cos\\left(7 \\, \\pi t\\right)}{t - 1} +\\\\ \n    \\frac{t \\sin\\left(7 \\, \\pi t\\right)}{\\sqrt{-t^{2} + 1} {\\left(t - 1\\right)}} + \\frac{\\sqrt{-t^{2} + 1} \\sin\\left(7 \\, \\pi t\\right)}{{\\left(t - 1\\right)}^{2}}\n    \\end{array}\\right)\n    \\Big[t = \\sage{pt} \\Big]\n\\end{multline*}\n\n$\\scriptstyle RHS = \\sage{rhs.transpose()}\\Big[(u,v) = \\sage{_pp.n(digits=6)} \\Big]$\n    \nThe right hand side of the expression is simplified as follows: \n\\begin{enumerate}[itemsep=1pt, topsep=1pt, partopsep=0pt]\n    \\item As the derivative is being taken Leibnitz notation is used (odd - one would have thought physicists would prefer Newton), the D is replaced with a\n    del ie \\(\\partial\\),\n    \\item The function is used in the numerator and the chart is used in the denominator in the Leibnitz notation for differentiation \n    i.e.~\\(\\frac{\\partial f}{\\partial c}\\),\n    \\item The coordinate index of the component being differentiated in the vector is used as a superscript in the denominator (the use of vectors and\n    matrices was implied in the Jacobian differentiation operator used in most of this document) \\(\\frac{\\partial f}{\\partial c^i}\\),\n    \\item Finally the point on the manifold is given as a subscript i.e \\((\\frac{\\partial f}{\\partial c^i})_p\\).\n\\end{enumerate}\n       \nThe left hand side is also simplified: \n\\begin{enumerate}[itemsep=1pt, topsep=1pt, partopsep=0pt]\n    \\item As the curve is being differentiated with respect to a parameter which can be interpreted as time, Newton finally arrives on the scene, \n    with the Newtonian notation with a dot on top of the curve being used i.e.~\\(\\dot \\lambda\\),\n    \\item As with the RHS the component index is used as a superscript (which also ties in with using Einstein summation for the entire expression)\n    i.e.~\\(\\dot \\lambda^i\\),\n    \\item The curve is used as a subscript ie \\(\\dot \\lambda^i_c\\) 4. Finally the point in the manifold is added i.e.~\\(\\dot \\lambda^i_c(t_1)\\)\n\\end{enumerate}    \n\nThe entire shorthand expression for a component is expressed as an operator which operates on\n\\(C^\\infty\\) functions: \\(\\dot \\lambda^i_c(t_1) (\\frac{\\partial }{\\partial c^i})_pf\\)\n\nThe \\((\\frac{\\partial }{\\partial c^i})_p\\) part (or more accurately its full expansion) forms a\nbasis for the vector space of derivations defining the tangent space.\n\\Textcite[see][pp.~82-86]{isham} provides a proof of this as well as the isomorphism between the\nderivation and the previously described geometric tangent space. This basis is known as a chart\ninduced basis.\n\nThe example shows the basis dependent on \\(u,v\\) and the components on\n\\(t\\):\\\\\n\\begin{multline*}\n    \\left(\\begin{array}{r}\n        \\scriptstyle\n        4 \\, {\\left(\\frac{7 \\, \\pi \\sqrt{-t^{2} + 1} \\sin\\left(7 \\, \\pi t\\right)}{t - 1} + \\frac{t \\cos\\left(7 \\, \\pi t\\right)}{\\sqrt{-t^{2} + 1} {\\left(t - 1\\right)}} + \\frac{\\sqrt{-t^{2} + 1} \\cos\\left(7 \\, \\pi t\\right)}{{\\left(t - 1\\right)}^{2}}\\right)} {\\left(\\frac{u + 1}{u^{2} + v^{2} + 1} - \\frac{{\\left(u^{2} + v^{2} + 2 \\, u + 2 \\, v - 1\\right)} u}{{\\left(u^{2} + v^{2} + 1\\right)}^{2}}\\right)} -\\\\\n        \\scriptstyle\n        4 \\, {\\left(\\frac{7 \\, \\pi \\sqrt{-t^{2} + 1} \\cos\\left(7 \\, \\pi t\\right)}{t - 1} - \\frac{t \\sin\\left(7 \\, \\pi t\\right)}{\\sqrt{-t^{2} + 1} {\\left(t - 1\\right)}} - \\frac{\\sqrt{-t^{2} + 1} \\sin\\left(7 \\, \\pi t\\right)}{{\\left(t - 1\\right)}^{2}}\\right)} {\\left(\\frac{v + 1}{u^{2} + v^{2} + 1} - \\frac{{\\left(u^{2} + v^{2} + 2 \\, u + 2 \\, v - 1\\right)} v}{{\\left(u^{2} + v^{2} + 1\\right)}^{2}}\\right)}\n        \\end{array}\\right)\n        = \\sage{res[0]}\n\\end{multline*}    \n    \n\\hypertarget{change-of-basis-for-tangent-space-components}{%\n\\subsection{Change of basis for Tangent Space\nComponents}\\label{change-of-basis-for-tangent-space-components}}\n\nGiven two charts \\((U, c_1)\\) and \\((V, c_2)\\) where\n\\(U \\cap V \\neq \\emptyset\\), where the tangent vector to a point\n\\(\\vec{p} \\in U,V\\) is known relative to say \\(U\\), then the equivalent\nbasis vector for \\(V\\) can be derived:\n\n\\begin{enumerate}[itemsep=1pt, topsep=1pt, partopsep=0pt]\n\\item\n  Recall the expression for the basic component from the previous\n  section and once again apply the idiom of using the inverse of a map\n  after the map, in this case the map being the chart from \\(V\\).\n  \\((\\frac{\\partial f}{\\partial c_1^{i:1\\cdots m}})_p = D(f \\circ c_1^{-1})[c_1(\\vec{p})] = D((f \\circ c_2^{-1}) \\circ (c_2 \\circ c_1^{-1})[c_1(\\vec{p})]\\)\n\\item\n  Utilise the chain rule again:\n  \\(D_{u,v}(f \\circ c_2^{-1})[c_2 \\circ c_1^{-1}(c_1(\\vec{p})] \\cdot D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})] = D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})] \\cdot D_{u,v}(f \\circ c_2^{-1})[c_2(\\vec{p})]\\).\n\\item\n  The full expression for the tangent vector in \\(U\\) is given by:\n  \\(\\dot \\lambda^i_{c_1}(t_1) (\\frac{\\partial f}{\\partial c_1^{i:1\\cdots m}})_p = D(c_1 \\circ \\lambda)[t_1] \\cdot D(f \\circ c^{-1}_1)[c_1(\\vec{p})]\\)\n  Substituting the expression from 2:\n  \\(D(c_1 \\circ \\lambda)[t_1] \\cdot D(f \\circ c^{-1})[c(\\vec{p})] = D_t(c_1 \\circ \\lambda)[t_1] \\cdot D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})] \\cdot D_{u,v}(f \\circ c_2^{-1})[c_2(\\vec{p})]\\)\n\\item\n  The full expression for the tangent vector in \\(V\\) is given by:\n  \\(\\dot \\lambda^i_{c_2}(t_2) (\\frac{\\partial f}{\\partial c_2^{i:1\\cdots n}})_p = D(c_{2} \\circ \\lambda)[t_2] \\cdot D(f \\circ c^{-1}_{2})[c_2(\\vec{p})]\\)\n\\item\n  As the curve on the manifold remains the same, the tangent vector is\n  also the same, its just expressed differently in the two bases,\n  therefore these expressions can be equated:\n  \\(D_t(c_{2} \\circ \\lambda)[t_2] \\cdot D_{u,v}(f \\circ c^{-1}_{2})[c_2(\\vec{p})] = D_t(c_1 \\circ \\lambda)[t_1] \\cdot D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})] \\cdot D_{u,v}(f \\circ c_2^{-1})[c_2(\\vec{p})]\\)\n  The components in V are thus\n  \\(D_t(c_1 \\circ \\lambda)[t_1] \\cdot D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})]\\)\n\\end{enumerate}\n\nThe \\(D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})]\\) (Jacobian of the\noverlap function between \\(U\\) and \\(V\\)) is \\(R^m \\rightarrow R^n\\) so\nthe Jacobian will be a \\(n{\\times}m\\) matrix. This matrix is multiplied\nby a \\(m{\\times}1\\) vector of the map from the curve to chart\ncoordinates via the manifold.\n\nApplying this to the example using a change of basis from the north to\nthe south hemisphere of the stereographic projection (the point at which\nthe tangent are found is the northern hemisphere test point, and the\ncurve is the same as the one used in the previous tangent space\nexamples):\\\\\n\\begin{sagesilent}\npp1 = vector(SR, (cn_0.substitute(x=Pn[0], z=Pn[2]), cn_1.substitute(y=Pn[1], z=Pn[2])))\npp2 = vector(SR, (cs_0.substitute(x=Pn[0], z=Pn[2]), cs_1.substitute(y=Pn[1], z=Pn[2])))\nfc2 = f.substitute(x=cs_ix, y=cs_iy, z=cs_iz).simplify_full()\nc2c1 = vector(SR, (cs_0.substitute({x: cn_ix, z: cn_iz}).full_simplify(), cs_1.substitute({y: cn_iy, z: cn_iz}).full_simplify()))\nc1l = vector(SR, (cn_0.substitute(x=K_1[0], z=K_1[2]), cn_1.substitute(y=K_1[1], z=K_1[2])))\n\nDc2c1 = jacobian(c2c1, (u, v))\nDc1l = jacobian(c1l, (t))\npretty_print(Dc2c1, LatexExpr(\"\\\\cdot\"), Dc1l, LatexExpr(\"~=~\"), Dc2c1*Dc1l)\npretty_print(Dc2c1.substitute(u=pp1[0], v=pp1[1]).n(digits=7), LatexExpr(\"\\\\cdot\"), Dc1l.substitute(t=float(pt)).n(digits=7), LatexExpr(\"~=~\"), (Dc2c1.substitute(u=pp1[0], v=pp1[1])*Dc1l.substitute(t=float(pt))).n(digits=7))    \n\\end{sagesilent}\n% \\begin{multline*}\n% \\scriptstyle \n% \\sage{Dc2c1} \\cdot \\sage{Dc1l} =\\\\\n% \\sage{(Dc2c1.substitute(u=pp1[0], v=pp1[1])*Dc1l.substitute(t=float(pt))).n(digits=7)}\n% \\end{multline*}\n\n\\begin{multline*}\n    \\hspace{-1.6cm}\n    \\medmuskip=2mu\n    \\scriptstyle \n    \\sage{Dc2c1} \\cdot \\sage{Dc1l}[t=\\sage{float(pt)}] = \\\\\n    \\scriptstyle \\sage{(Dc2c1*Dc1l.substitute(t=pt))}\n\\end{multline*}\n\n\\begin{multline*}\n    \\hspace{-1.6cm}\n    \\medmuskip=2mu\n    \\scriptstyle \\sage{(Dc2c1*Dc1l.substitute(t=pt))}\\Big[\\begin{array}{c} u = \\sage{pp1[0].n(digits=5)} \\\\ v = \\sage{pp1[1].n(digits=5)}\\end{array}\\Big] =\\\\\n    \\scriptstyle \\sage{(Dc2c1.substitute(u=pp1[0], v=pp1[1])*Dc1l.substitute(t=float(pt))).n(digits=7)}\n\\end{multline*}\n    \n    We can test the change of basis by calculating the component representation in the south chart directly:\\\\\n\\begin{sagesilent}    \nlhss = vector(SR, (cs_0, cs_1))\nlhs = jacobian(vector(SR, (cs_0.substitute(x=K_1[0], z=K_1[2]), cs_1.substitute(y=K_1[1], z=K_1[2]))), (t)).transpose()\n\\end{sagesilent}  \n\\begin{multline*}\n    \\hspace{-1.6cm}\n    \\medmuskip=2mu  \n    D_{x,y,z}\\sage{lhss}\\Big[\\begin{array}{c} x = \\sage{K_1[0]} \\\\ y = \\sage{K_1[1]} \\\\ z = \\sage{K_1[2]}\\end{array}\\Big] =\\\\ \n    \\hspace{-1.6cm}\n    \\scriptstyle \\sage{lhs}\\big[t=\\sage{float(pt)}\\big] =\\\\ \n    \\scriptstyle \\sage{lhs.substitute(t=pt).n(digits=6)}\n\\end{multline*}    \n    \nMost (physics) textbooks use a shorthand notation for \\(D_{u,v}(c_2 \\circ c_1^{-1})[c_1(\\vec{p})]\n\\cdot D_t(c_1 \\circ \\lambda)[t_1]\\), namely \\(\\frac{\\partial c_2^j}{\\partial c_1^i} \\cdot\nX^i_{c_1}\\) where the \\(\\frac{\\partial c_2^j}{\\partial c_1^i}\\) refers to the Jacobian matrix with\nthe superscript indices corresponding to rows and columns from the matrix, while the \\(X^i_{c_1}\\)\nterm is a generic reference to the components in the convert-from chart minus any curve\ninformation. \n\n\\printbibliography    \n\\end{document}\n", "meta": {"hexsha": "4e6effbb93dac5a9cc1392064212672ae80fe175", "size": 47304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ConcreteManifolds.tex", "max_stars_repo_name": "donaldmunro/ConcreteManifolds", "max_stars_repo_head_hexsha": "dc7699ed029d6e5c87872654188d748b40249cca", "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": "ConcreteManifolds.tex", "max_issues_repo_name": "donaldmunro/ConcreteManifolds", "max_issues_repo_head_hexsha": "dc7699ed029d6e5c87872654188d748b40249cca", "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": "ConcreteManifolds.tex", "max_forks_repo_name": "donaldmunro/ConcreteManifolds", "max_forks_repo_head_hexsha": "dc7699ed029d6e5c87872654188d748b40249cca", "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.9127516779, "max_line_length": 407, "alphanum_fraction": 0.6347666159, "num_tokens": 18165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6264775467865593}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}\n\\usepackage{amsfonts}\n\n\\begin{document}\n\\title{Mathematical}\n\\author{Mrinmoi Hossain}\n\\date{\\today}\n\\maketitle\n\n\\section{Mathematical Notation}\n\\begin{enumerate}\n\\item The set of nutural number is denoted by $\\mathbb{N}$.\n\\item The set of real number is denoted by $\\mathbb{R}$.\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "16ac8e54c24e3a37b28b07a85a377959da3a5345", "size": 411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MathematicalNotation/mathematicalSymbol.tex", "max_stars_repo_name": "MrinmoiHossain/HelloLateX", "max_stars_repo_head_hexsha": "ed8d424a21dc252d3d67356433053adf4b34ccae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-03T03:10:11.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-03T03:10:11.000Z", "max_issues_repo_path": "MathematicalNotation/mathematicalSymbol.tex", "max_issues_repo_name": "MrinmoiHossain/HelloLateX", "max_issues_repo_head_hexsha": "ed8d424a21dc252d3d67356433053adf4b34ccae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MathematicalNotation/mathematicalSymbol.tex", "max_forks_repo_name": "MrinmoiHossain/HelloLateX", "max_forks_repo_head_hexsha": "ed8d424a21dc252d3d67356433053adf4b34ccae", "max_forks_repo_licenses": ["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.8333333333, "max_line_length": 69, "alphanum_fraction": 0.7615571776, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.6264775425954286}}
{"text": "% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí\n\\setcounter{chapter}{3}\n\\chapter{Faraday's Law of Induction}\n%\nIn this experiment you will learn about Faraday's law of induction and a relationship between electric and magnetic phenomena.\n%\n\\section{Preliminary}\n%\nFaraday's law of induction is a statement relating an \\textbf{electric} phenomenon to a \\textbf{magnetic} phenomenon. It states that a certain amount of \\textbf{voltage} $\\mathcal{E}$ is equal to the negative \\textbf{rate of change of the magnetic flux} $\\Phi_{B}$ with time:\n\\begin{equation}\n\t\\mathcal{E} = -\\frac{\\Delta \\Phi_{B}}{\\Delta t}\n\t\\label{eq.04.faradays.law}\n\\end{equation}\nHere $\\mathcal{E}$ is known as the \\textbf{electro-motive force} or EMF. Although ``force'' is part of its name, an EMF quantity has nothing to do with force (which is measured in newtons): an EMF quantity has units of volts.\n%\n\\subsection{Magnetic flux and its rate of change}\n%\nThe \\textbf{magnetic flux} is defined as the product of the amount of \\textbf{magnetic field} $B$ and the amount of \\textbf{area} $a$ in a surface where the magnetic field lines pass through:\n\\begin{equation}\n\t\\Phi_{B} = B a\n\\end{equation}\nThe \\textbf{SI unit} for magnetic field is the \\textbf{tesla} (T). The \\textbf{SI unit} for area is the square meter (m$^{2}$). Thus, magnetic flux is measured in units of T {\\textperiodcentered} m\\textsuperscript{2}.\n\nA non-zero EMF $\\mathcal{E}$ requires the magnetic flux $\\Phi_{B}$ to change with time. In this experiment you are going to keep the \\textbf{area fixed} and let the \\textbf{magnetic field change with time}. In this setting, the rate of change of the magnetic flux with time is proportional to the rate of change of the magnetic field with time:\n\\begin{align}\n\t\\Phi_{B} = B a && \\Longrightarrow && \\frac{\\Delta \\Phi_{B}}{\\Delta t} = \\left(\\frac{\\Delta B}{\\Delta t}\\right) a\n\t\\label{eq.04.flux.rate}\n\\end{align}\nThe rate of change of magnetic flux is measured in units of T {\\textperiodcentered} m\\textsuperscript{2}/s. But according to Faraday's law, these units are the same as the units for EMF (volts), so you must have the equivalence:\n\\begin{equation}\n\t1 \\ \\text{V} = 1 \\ \\text{T {\\textperiodcentered} m\\textsuperscript{2}/s}\n\\end{equation}\nThis allows you to express the tesla unit in terms of volts, meters, and seconds:\n\\begin{equation}\n\t1 \\ \\text{T} = 1 \\ \\text{V {\\textperiodcentered} s/m\\textsuperscript{2}}\n\\end{equation}\n%\n\\subsection{Producing the magnetic field}\n%\nWires with electric current produce magnetic fields. You are going to use a particular wire called a \\textbf{solenoid coil}. The \\textbf{magnetic field} $B$ inside the cylindrical space of a solenoid coil is (almost) uniform and the amount of field is directly proportional to the amount of current $I$ flowing through the coil:\n\\begin{equation}\n\tB = \\left(\\frac{\\mu_{0} N_{1}}{L}\\right) I\n\t\\label{eq.04.B.coil}\n\\end{equation}\nHere\n\\begin{itemize}\n\t\\item $B$ is the amount of \\textbf{magnetic field} (unit: T)\n\t\\item $\\mu_{0} = 4 \\pi \\times 10^{-7}$ T {\\textperiodcentered} m/A  is a universal physical \\textbf{constant}\n\t\\item $N_{1}$ is the \\textbf{number of turns} in the (primary) coil (no units)\n\t\\item $L$ is the \\textbf{length} of the (primary) coil (unit: m)\n\t\\item $I$ is the amount of \\textbf{electric current} through the (primary) coil (unit: A)\n\\end{itemize}\nFor a given coil you are going to keep the \\textbf{number of turns fixed}, and the \\textbf{length fixed}, but you are going to use a \\textbf{current that changes with time}. In this case, the rate of change of the magnetic field with time is proportional to the rate of change of the current with time:\n\\begin{align}\n\tB = \\left(\\frac{\\mu_{0} N_{1}}{L}\\right) I && \\Longrightarrow && \\frac{\\Delta B}{\\Delta t} = \\left( \\frac{\\mu_{0} N_{1}}{L} \\right) \\frac{\\Delta I}{\\Delta t}\n\t\\label{eq.04.B.rate}\n\\end{align}\nUsing Equation (\\ref{eq.04.B.rate}) in Equation (\\ref{eq.04.flux.rate}) gives\n\\begin{equation}\n\t\\frac{\\Delta \\Phi_{B}}{\\Delta t} = \\left( \\frac{\\mu_{0} N_{1} a}{L} \\right) \\frac{\\Delta I}{\\Delta t}\n\\end{equation}\nThus, according to Faraday's law, for a solenoid coil you should have\n\\begin{equation}\n\t\\mathcal{E} = -\\left( \\frac{\\mu_{0} N_{1} a}{L} \\right) \\frac{\\Delta I}{\\Delta t}\n\t\\label{eq.04.emf.solenoid}\n\\end{equation}\nThat is, the EMF associated with the area $a$ is proportional to the rate of change of the electric current with respect to time.\n%\n\\section{Experiment}\n%\nThe overall goal of the experiment is to check that the EMF behaves like the rate of change of the electric current. To do this you need to measure the EMF voltage and the current. From the current you can estimate the rate of change and confirm that it agrees with the EMF data.\n\nYou are going to look at \\textbf{five ways for the current to change with time}:\n\\begin{enumerate}\n\t\\item \\textbf{Sinusoidal}: current will change according to a \\textbf{sine or cosine} profile.\n\t\\item \\textbf{Square}: current will stay almost \\textbf{constant}, but the \\textbf{sign changes}.\n\t\\item \\textbf{Triangular}: current will increase \\textbf{linearly}, then decrease \\textbf{linearly}.\n\t\\item \\textbf{Ramp-up}: current will \\textbf{increase linearly}, then \\textbf{abruptly drop} to its base value.\n\t\\item \\textbf{Ramp-down}: current will \\textbf{decrease linearly}, then \\textbf{abruptly rise} to its base value.\n\\end{enumerate}\nEach profile for the current leads to different results for the induced EMF.\n%\n\\subsection{Rates of Change}\n%\nHere is a quick review of rates of change.\n%\n\\subsubsection{Constant Quantity}\n%\nThe rate of change of a \\textbf{constant quantity} is \\textbf{zero}. That is, if the quantity is not changing, then no amount is being gained or lost.\n%\n\\subsubsection{Quantity Increasing Linearly}\n%\nThe rate of change of a \\textbf{quantity that increases linearly with time} is a \\textbf{constant}. Increasing linearly is the same as being proportional to time. This means that the slope is constant. Moreover, since the quantity is increasing, the \\textbf{slope is positive}.\n%\n\\subsubsection{Quantity Decreasing Linearly}\n%\nThe rate of change of a \\textbf{quantity that decreases linearly with time} is a \\textbf{constant}. Decreasing linearly is the same as being proportional to time. This means that the slope is constant. However, since the quantity is decreasing, the \\textbf{slope is negative}.\n%\n\\subsubsection{Sinusoidal Change}\n%\nThe rate of change of the \\textbf{sine function} is a cosine function:\n\\begin{equation}\n\t\\frac{\\Delta \\sin(t)}{\\Delta t} = \\cos(t)\n\\end{equation}\nSimilarly, the rate of change of the \\textbf{cosine function} is proportional to a sine function:\n\\begin{equation}\n\t\\frac{\\Delta \\cos(t)}{\\Delta t} = -\\sin(t)\n\\end{equation}\nHere the sign is not important. What is important is to remember that sine and cosine are very similar functions and that a cosine is the same as a sine function shifted by 90 deg (or $\\pi/2$ rad):\n\\begin{align}\n\t\\cos(t) = \\sin(t + 90\\text{\\textdegree}), && \\sin(t) = \\cos(t - 90\\text{\\textdegree})\n\\end{align}\nThus, if the quantity is sinusoidal, then the rate of change will also be sinusoidal but shifted by 90 deg. In particular, when $\\sin(t)$ is at a peak or valley, then $\\cos(t)$ is crossing the horizontal axis (i.e. close to zero), and when $\\sin(t)$ is crossing the horizontal axis (i.e. close to zero), then $\\cos(t)$ is either at a valley or a peak.\n%\n\\subsection{Solenoid Coils}\n%\nYou are going to use two solenoid coils. The smaller one fits inside the larger one. The smaller one is called the \\textbf{secondary coil}. This is the coil used to measure the EMF value. The larger coil is called the \\textbf{primary coil}. This coil is the one with the current and the one that produces the magnetic field.\n\nThe \\textbf{primary coil} has a length of 10 cm and 3300 turns. Thus,\n\\begin{align}\n\tL = 10 \\ \\text{cm} = 0.1 \\ \\text{m,} && N_{1} = 3300\n\\end{align}\nThe \\textbf{secondary coil} has 150 turns and an outer diameter of 1.8 cm. The inner diameter I measured it to be close to 1.1 cm. The average of these two diameters correspond to the diameter half-way between these two. This average is 1.45 cm. Since the wire was very thick, I think it is more accurate to use the average of the diameters to calculate the area of each loop. Thus,\n\\begin{align}\n\td = 1.45 \\ \\text{cm} = 0.0145 \\ \\text{m,} && N_{2} = 150\n\\end{align}\nThe area enclosed by a circular loop with diameter $d$ is given by\n\\begin{equation}\n\ta_{\\text{loop}} = \\frac{1}{4} \\pi d^{2} = \\frac{1}{4} \\pi \\left(0.0145 \\ \\text{m}\\right)^2 = 1.65 \\times 10^{-4} \\ \\text{m\\textsuperscript{2}}\n\\end{equation}\nThis is the amount of \\textbf{area-per-loop} in the secondary coil. The \\textbf{total amount of area} $a$ is the area-per-loop $a_{\\text{loop}}$ multiplied by the number of loops $N_{2}$ in the secondary coil:\n\\begin{equation}\n\ta = N_{2} a_{\\text{loop}} = 150 \\times \\left(1.65 \\times 10^{-4} \\ \\text{m\\textsuperscript{2}}\\right) = 2.48 \\times 10^{-2} \\ \\text{m\\textsuperscript{2}}\n\\end{equation}\nThis is the amount of area that you will use to measure the magnetic flux.\n%\n\\section{Analysis}\n%\nAccording to (\\ref{eq.04.emf.solenoid}), the amount of EMF is directly proportional to the amount of rate of change of the current with time. The constant of proportionality is\n\\begin{equation}\n\t\\frac{\\mu_{0} N_{1} a}{L} = 1.03 \\times 10^{-3} \\ \\text{V {\\textperiodcentered} s/A} = 1.03 \\ \\text{mV {\\textperiodcentered} s/A}\n\t\\label{eq.04.slope}\n\\end{equation}\nThis is the expected value. In principle, if you could chart $\\mathcal{E}$ versus $\\Delta I / \\Delta t$, the slope should correspond to the negative of this value. You can only do this for the triangular current profile.\n%\n\\subsection{Sinusoidal Current Profile}\n%\nFor the sinusoidal current profile, one way to check the validity of Faraday's law is by comparing the fit parameters for a sinusoidal fit for both current and voltage. A ``sine'' sinusoidal fit for the current is of the form\n\\begin{equation}\n\tI(t) = A \\sin(B t + C) + D\n\\end{equation}\nNote that\n\\begin{itemize}\n\t\\item The current amplitude $A$ has units of amps (A)\n\t\\item The current angular frequency $B$ has units of radians-per-second (rad/s)\n\t\\item The current angular shift $C$ has units of radians (rad)\n\t\\item The current shift $D$ has units of amps (A)\n\\end{itemize}\nA ``cosine'' sinusoidal fit for the EMF is of the form\n\\begin{equation}\n\t\\mathcal{E}(t) = W \\cos(X t + Y) + Z\n\\end{equation}\nNote that\n\\begin{itemize}\n\t\\item The EMF amplitude $W$ has units of volts (V)\n\t\\item The EMF angular frequency $X$ has units of radians-per-second (rad/s)\n\t\\item The EMF angular shift $Y$ has units of radians (rad)\n\t\\item The EMF shift $Z$ has units of volts (V)\n\\end{itemize}\nIf the sensors were zeroed correctly, you should find that both $D$ and $Z$ are close to \\textbf{zero}, and thus they can be neglected. There are three simple checks:\n\\begin{enumerate}\n\t\\item The value of $W$ should be very close to\n\t\\begin{equation}\n\t\tA B \\left(\\frac{\\mu_{0} N_{1} a}{L}\\right)\n\t\\end{equation}\n\t\\item The value of $B$ should be very close to the value of $X$.\n\t\\item The value of $\\vert C - Y \\vert$ should be very close to $\\pi$.\n\\end{enumerate}\nAnother check, similar to what you did for simple harmonic motion, is to make a \\textbf{phase space} chart, with EMF voltage in the vertical axis, and current in the horizontal axis. Just like for the mass on the spring, the phase space chart should have the \\textbf{shape of an ellipse}.\n%\n\\subsection{Square Current Profile}\n%\nSince the square current profile consists of segments where the current is almost constant, the rate of change of the current should be almost zero. This will result in an EMF value that is also almost zero. You can confirm this by examining a scatter chart with EMF voltage on the vertical axis and time in the horizontal axis.\n%\n\\subsection{Triangular Current Profile}\n%\nFor the triangular current, the chart of current versus time has regions of increasing current and regions of decreasing current. In the same time regions, the EMF voltage is approximately constant but either positive or negative.\n\nYou can isolate a time region of linear increase of current and find the slope. (In the spreadsheet use \\texttt{=SLOPE(Y,X)} with \\texttt{Y} the current and \\texttt{X} the time). This slope is a value for the rate of change of current with respect to time ($\\Delta I / \\Delta t$). The slope should be \\textbf{positive} since the current is increasing. In approximately the same time region the EMF voltage is constant (make sure you only include the region where the EMF is approximately flat and not suddenly rising or falling). You can calculate the time-average of the EMF in this time region. This time average value corresponds to the best direct estimate for the EMF ($\\mathcal{E}$).\n\nIn a similar way, you can analyze the time regions where the current decreases in a linear way. Now the rate of change of the current will be \\textbf{negative}. The EMF should be almost flat and \\textbf{positive}.\n\nAfter finding \\textbf{at least six pairs} of EMF and rate of change of current with respect to time, you can plot these quantities to test the relation in Equation (\\ref{eq.04.emf.solenoid}) and find the slope. Then you can compare this value with the expected slope in Equation (\\ref{eq.04.slope}). The chart should have two clusters of points. The best-fit line should be connecting these two clusters.\n%\n\\subsection{Ramp-Up and Ramp-Down Current Profiles}\n%\nFor the ramp-up current profile, the current only increases linearly. This means that the rate of change of the current should be a positive constant always. You can repeat the steps followed above with the triangular current and find the rate of change for the current and also the time-average EMF. However, you cannot plot $\\mathcal{E}$ and $dI/dt$ anymore, so instead just calculate the ratio\n\\begin{equation}\n\t\\text{ratio } = -\\frac{\\mathcal{E}}{\\Delta I/\\Delta t}\n\t\\label{eq.04.ratio}\n\\end{equation}\nThis ratio should be somewhat close to the expected value of the slope in Equation (\\ref{eq.04.slope}). A similar result holds for the ramp-down current profile.\n%\n\\section{My Data}\n%\nMy data consist of five runs:\n\\begin{itemize}\n\t\\item Run 1: Sinusoidal current profile\n\t\\item Run 2: Square current profile\n\t\\item Run 3: Triangular current profile\n\t\\item Run 4: Ramp-up current profile\n\t\\item Run 5: Ramp-down current profile\n\\end{itemize}\nHere are some comments from each run.\n%\n\\subsection{Run 1}\n%\nThe analysis for this run is qualitative. Figure \\ref{figure.04.run.1.I} contains the current data over time, and Figure \\ref{figure.04.run.1.V} contains the EMF voltage data over time. You can see that the EMF voltage behaves like the rate of change of the current because whenever the current is at a peak or valley, the EMF voltage is close to zero, and whenever the current is close to zero, the EMF voltage is at a peak or valley. The phase phase chart in Figure \\ref{figure.04.run.1.phase.space} also shows the expected elliptical shape.\n%\n\\subsection{Run 2}\n%\nThe analysis for this run is also qualitative. Figure \\ref{figure.04.run.2.I} contains the current data over time, and Figure \\ref{figure.04.run.2.V} contains the EMF voltage data over time. As expected, when the square current profile is used, the EMF voltage is zero whenever the current has a fixed value.\n%\n\\subsection{Run 3}\n%\nThe analysis for this run has a quantitative aspect. Figure \\ref{figure.04.run.3.I} contains the current data over time, and Figure \\ref{figure.04.run.3.V} contains the EMF voltage data over time. Since the current increases or decreases in a linear way, the EMF voltage is expected to be constant but switching signs. That is indeed the case. Furthermore, the slope for the current can be calculated. Table \\ref{table.04.run.3.I.V} contains the current slope and the time-average EMF voltage for a six segments. These six segments lead to two clusters in Figure \\ref{figure.04.run.3}, where the slope is close to the expected value. The results are in Table \\ref{table.04.run.3}.\n%\n\\subsection{Run 4}\n%\nThe analysis for this run has a quantitative aspect. Figure \\ref{figure.04.run.4.I} contains the current data over time, and Figure \\ref{figure.04.run.4.V} contains the EMF voltage data over time. Since the current only increases before abruptly taking the base value, you expect the EMF voltage to be constant and negative. That is indeed the case. The results are in Table \\ref{table.04.run.4}, where the last column contains the ratio in Equation (\\ref{eq.04.ratio}). These values are close to the expected slope.\n%\n\\subsection{Run 5}\n%\nThe analysis for this run has a quantitative aspect. Figure \\ref{figure.04.run.5.I} contains the current data over time, and Figure \\ref{figure.04.run.5.V} contains the EMF voltage data over time. Since the current only decreases before abruptly taking the base value, you expect the EMF voltage to be constant and positive. That is indeed the case. The results are in Table \\ref{table.04.run.5}, where the last column contains the ratio in Equation (\\ref{eq.04.ratio}). These values are also close to the expected slope.\n%\n\\section{Your Data}\n%\nYou should have five runs:\n\\begin{itemize}\n\t\\item Run 1: Sinusoidal current profile\n\t\\item Run 2: Square current profile\n\t\\item Run 3: Triangular current profile\n\t\\item Run 4: Ramp-up current profile\n\t\\item Run 5: Ramp-down current profile\n\\end{itemize}\nFor each run you should have three columns of data: time, voltage (electric potential), and current.\n% Note that the voltage column is in mV and should be converted to volts:\n% \\begin{equation}\n% \t1 \\text{ mV} = 0.001 \\ \\text{V}\n% \\end{equation}\n% Otherwise, agreement with the slope in Equation (\\ref{eq.04.slope}) will be off by some orders of magnitude.\n%\n% \\newpage\n% \\section{Your Lab Report}\n% %\n% For \\textbf{run 1}, your lab report should include:\n% \\begin{itemize}\n% \t\\item A scatter chart with \\textbf{current} in the vertical axis, and time in the horizontal axis.\n% \t\\item A scatter chart with \\textbf{voltage} in the vertical axis, and time in the horizontal axis.\n% \t\\item A brief argument discussing whether the voltage that you measured behaves \\textbf{qualitatively} like the rate of change of current with time.\n% \t\\item A scatter chart with \\textbf{voltage} in the vertical axis, and \\textbf{current} in the horizontal axis. Does this chart have the elliptical shape?\n% \\end{itemize}\n% For \\textbf{run 2}, your lab report should include:\n% \\begin{itemize}\n% \t\\item A scatter chart with \\textbf{current} in the vertical axis, and time in the horizontal axis.\n% \t\\item A scatter chart with \\textbf{voltage} in the vertical axis, and time in the horizontal axis.\n% \t\\item A brief argument discussing whether the voltage that you measured behaves \\textbf{qualitatively} like the rate of change of current with time.\n% \\end{itemize}\n% For \\textbf{run 3}, your lab report should include:\n% \\begin{itemize}\n% \t\\item A scatter chart with \\textbf{voltage} in the vertical axis, and time in the horizontal axis.\n% \t\\item A brief argument discussing whether the voltage that you measured behaves \\textbf{qualitatively} like the rate of change of current with time.\n% \t\\item A table like Table \\ref{table.04.run.3.I.V} with at least six values for the current slope, and the time-average EMF voltage.\n% \t\\item A scatter chart with EMF voltage in the vertical axis, and current slope in the horizontal axis. Include the best-fit line, and display the equation in the legend.\n% \t\\item A table like Table \\ref{table.04.run.3} with the expected slope, the experimental slope, and the percent difference.\n% \\end{itemize}\n% For \\textbf{run 4} and \\textbf{run 5}, your lab report should include:\n% \\begin{itemize}\n% \t\\item A scatter chart with \\textbf{voltage} in the vertical axis, and time in the horizontal axis.\n% \t\\item A brief argument discussing whether the voltage that you measured behaves \\textbf{qualitatively} like the rate of change of current with time.\n% \t\\item A table like Table \\ref{table.04.run.4} and Table \\ref{table.04.run.5} with at least four values for the current slope, the time-average EMF voltage, and the ratio (\\ref{eq.04.ratio}).\n% \\end{itemize}\n%\n\\newpage\n\\section{Tables}\n%\n\\begin{table}[ht!]\n\t\\centering\n\t\\begin{tabular}{r|r}\n\t\t\\textbf{Current Slope} (A/s) & \\textbf{Time-Average EMF Voltage} (mV) \\\\\n\t\t\\hline\n\t\t\\textminus 2.247 & 2.65 \\\\\n\t\t2.274 & \\textminus 2.67 \\\\\n\t\t\\textminus 2.266 & 2.66 \\\\\n\t\t2.243 & \\textminus 2.67 \\\\\n\t\t\\textminus 2.280 & 2.66 \\\\\n\t\t2.275 & \\textminus 2.68 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Current slope and EMF time-average results for run 3}\n\t\\label{table.04.run.3.I.V}\n\\end{table}\n%\n\\begin{table}[ht!]\n\t\\centering\n\t\\begin{tabular}{r|r|r}\n\t\t\\textbf{Expected Slope} (mV$\\cdot$s/A) & \\textbf{Observed Slope} (mV$\\cdot$s/A) & \\textbf{P.D.} (\\%) \\\\\n\t\t\\hline\n\t\t\\textminus 1.03 & \\textminus 1.18 & 14.55 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Results for run 3}\n\t\\label{table.04.run.3}\n\\end{table}\n%\n\\begin{table}[ht!]\n\t\\centering\n\t\\begin{tabular}{r|r|r}\n\t\t\\textbf{Current Slope} (A/s) & \\textbf{Time-Average EMF Voltage} (mV) & \\textbf{Ratio} (mV$\\cdot$s/A) \\\\\n\t\t\\hline\n\t\t0.507 & \\textminus 0.607 & \\textminus 1.20 \\\\\n\t\t0.516 & \\textminus 0.612 & \\textminus 1.19 \\\\\n\t\t0.505 & \\textminus 0.599 & \\textminus 1.19 \\\\\n\t\t0.505 & \\textminus 0.600 & \\textminus 1.19 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Results for run 4}\n\t\\label{table.04.run.4}\n\\end{table}\n%\n\\begin{table}[ht!]\n\t\\centering\n\t\\begin{tabular}{r|r|r}\n\t\t\\textbf{Current Slope} (A/s) & \\textbf{Time-Average EMF Voltage} (mV) & \\textbf{Ratio} (mV$\\cdot$s/A) \\\\\n\t\t\\hline\n\t\t\\textminus 0.507 & 0.596 & \\textminus 1.17 \\\\\n\t\t\\textminus 0.516 & 0.596 & \\textminus 1.17 \\\\\n\t\t\\textminus 0.505 & 0.600 & \\textminus 1.19 \\\\\n\t\t\\textminus 0.505 & 0.601 & \\textminus 1.18 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{Results for run 5}\n\t\\label{table.04.run.5}\n\\end{table}\n%\n\\FloatBarrier\n\\newpage\n\\section{Figures}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-1-I.pdf}\n\t\\caption{Run 1 -- Current}\n\t\\label{figure.04.run.1.I}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-1-V.pdf}\n\t\\caption{Run 1 -- EMF Voltage}\n\t\\label{figure.04.run.1.V}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-1-phase-space.pdf}\n\t\\caption{Run 1 -- Phase Space}\n\t\\label{figure.04.run.1.phase.space}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-2-I.pdf}\n\t\\caption{Run 2 -- Current}\n\t\\label{figure.04.run.2.I}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-2-V.pdf}\n\t\\caption{Run 2 -- EMF Voltage}\n\t\\label{figure.04.run.2.V}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-3-I.pdf}\n\t\\caption{Run 3 -- Current}\n\t\\label{figure.04.run.3.I}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-3-V.pdf}\n\t\\caption{Run 3 -- EMF Voltage}\n\t\\label{figure.04.run.3.V}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-4-I.pdf}\n\t\\caption{Run 4 -- Current}\n\t\\label{figure.04.run.4.I}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-4-V.pdf}\n\t\\caption{Run 4 -- EMF Voltage}\n\t\\label{figure.04.run.4.V}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-5-I.pdf}\n\t\\caption{Run 5 -- Current}\n\t\\label{figure.04.run.5.I}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-5-V.pdf}\n\t\\caption{Run 5 -- EMF Voltage}\n\t\\label{figure.04.run.5.V}\n\\end{figure}\n%\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[scale=0.74]{image/04-faraday/run-3.pdf}\n\t\\caption{Run 3}\n\t\\label{figure.04.run.3}\n\\end{figure}", "meta": {"hexsha": "a71e19ade74ed48fc5d3c2770ccc0d27f03187a6", "size": 23869, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/04-faraday.tex", "max_stars_repo_name": "meirizarrygelpi/phys-208L", "max_stars_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_stars_repo_licenses": ["MIT"], "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/04-faraday.tex", "max_issues_repo_name": "meirizarrygelpi/phys-208L", "max_issues_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_issues_repo_licenses": ["MIT"], "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/04-faraday.tex", "max_forks_repo_name": "meirizarrygelpi/phys-208L", "max_forks_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_forks_repo_licenses": ["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.2523148148, "max_line_length": 689, "alphanum_fraction": 0.734509196, "num_tokens": 7169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6264698661781124}}
{"text": "\\documentclass{enonce}\n\\selectlanguage{english}\n\\usepackage{palatino,mathpazo,color}\n\\usepackage{tutorial}\n\\setlength{\\overfullrule}{3pt}\n\\course{IFM 2010 - TLAPS tutorial}\n\\title{Peterson algorithm}\n\\author{D. Cousineau, S. Merz}\n%\\institute{INRIA Lorraine - MSR INRIA Joint Lab}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\noindent In this tutorial, we shall prove that Peterson's algorithm satisfies the mutual exclusion property, using the TLA Proof System and the Toolbox IDE.\n\n%\\tableofcontents\n\n\\section{Toolbox and TLAPS install}\nIf you have not done it yet, you can download the Toolbox from \n\\begin{center}\n\\url{http://www.tlaplus.net/tools/tla-toolbox/}\n\\end{center}\nand dowload the TLA Proof System from\n\\begin{center}\n\\url{http://www.msr-inria.inria.fr/~doligez/tlaps/}\n\\end{center}\n\n\\noindent Binaries are available for Windows, MacOS and Linux distributions. Notice that Cygwin (version 1.7 or higher) is required to install TLAPS on Windows.\n\n\\section{Peterson Algorithm}\nThis algorithm, formulated by Gary L. Peterson in 1981, is a concurrent programming algorithm for mutual exclusion that allows two processes to share a single-use resource without conflict, using only shared memory for communication.\n\n\\subsection{Description}\nThe algorithm allows two processes to share some resource with the three following properties:\n\\begin{itemize}\n\\item Mutual exclusion : the two processes cannot access the resource at the same time\n\\item Progress: a process cannot immediately re-access the resource if the other process wants also to access the resource.\n\\item Bounded waiting: there exists a limit on the number of times that the other process is allowed to access the resource after a process has made a request to access the resource.\n\\end{itemize}\n\n\\noindent We shall focus on the mutual exclusion property in the TLA+ specification we are to build.\n\n\\medskip\n\n\\noindent We call \\textit{critical section} the moment when some process is accessing the shared resource. The Mutual Exclusion property ensures that the two processes are not both in the critical section at the same time.\n\n\\medskip\n\n The idea of the algorithm is the following: we use two variables, a function called {\\tt flag}, which says for each of the processes, if it wants to access the resource or not. And a simple variable {\\tt turn} which holds the process whose turn it is to enter the critical section.\n\n\\noindent At the beginning of the algorithm, {\\tt flag[0]} and {\\tt flag[1]} are equal to {\\tt FALSE} (none of the processes wants to access the resource), and {\\tt turn} is equal to {\\tt 0} (process 0 has priority to access the resource).\n\n\\noindent Then, for making process {\\tt 0} (for example) access the shared resource, we do the following:\n\\begin{enumerate}\n\t\\item[({\\tt a1})] turn the value of {\\tt flag[0]} to {\\tt TRUE} \\\\(process {\\tt 0} does want to enter the critical section)\n\t\\item[({\\tt a2})] turn the value of {\\tt turn} to {\\tt 1} \\\\(give the priority to the other process)\n\t\\item[({\\tt a3})] wait for  {\\tt flag[1]} to be equal to {\\tt FALSE} and {\\tt turn} to be equal to {\\tt 1} \\\\(process {\\tt 1} does not want to access the resource and process {\\tt 0} has priority to access it)\n\t\\item[({\\tt cs})] enter the critical section \\\\(access the resource)\n\t\\item[({\\tt a4})] turn  the value of {\\tt flag[0]} to {\\tt FALSE} \\\\(process {\\tt 0} does not want to access the resource anymore)\n\\end{enumerate}   \n\n\\medskip\n\n\n\\subsection{PlusCal version}\n\nPeterson's algorithm can be expressed in the PlusCal language as follows:\n\\smallskip\n\n\\begin{verbatim}\nNot(i) == IF i = 0 THEN 1 ELSE 0\n\n--algorithm Peterson {\n   variables flag = [i \\in {0, 1} |-> FALSE], turn = 0;\n   process (proc \\in {0,1}) {\n     a0: while (TRUE) {\n     a1:   flag[self] := TRUE;\n     a2:   turn := Not(self);\n     a3a:  if (flag[Not(self)]) {goto a3b} else {goto cs} ;\n     a3b:  if (turn = Not(self)) {goto a3a} else {goto cs} ;\n     cs:   skip;  \\* critical section\n     a4:   flag[self] := FALSE;\n     } \\* end while\n    } \\* end process\n  }\n\\end{verbatim}\n\n\\noindent Notice that, for simplicity, the TLA+ specification we describe in the next section differs a little bit from the one that can be directly translated from the algorithm above, by the PlusCal translator.\n\n\\section{The specification}\nPeterson's algorithm for two processes can already be verified by the Toolbox model-checker. But we use it as an exercise to make you learn ho to use TLA Proof Sytem.\n\n\\medskip\n\n\\noindent Peterson's TLA+ specification can be downloaded at \n\\begin{center}\n\\url{http://www.msr-inria.inria.fr/~doligez/tlaps/IFM2010/Peterson.tla}\n\\end{center}\nLet us describe what you can find in this file.\n\n\\subsection{Variables}\nWe declare three variables, {\\tt flag}, {\\tt turn} and {\\tt pc} (which gives the current step of the algorithm).\nWe define {\\tt vars} as the tuple composed by those three variables, and {\\tt ProcSet} as the set $\\{0,1\\}$.\n\\begin{verbatim}\nVARIABLES flag, turn, pc\nvars == << flag, turn, pc >>\nProcSet == ({0,1})\n\\end{verbatim}\n\n\\subsection{The {\\tt Init} state}\nWe then express the initial state of the algorithm as follows:\n\\begin{verbatim}\nInit == /\\ flag = [i \\in {0, 1} |-> FALSE]\n        /\\ turn = 0\n        /\\ pc = [self \\in ProcSet |-> CASE self \\in {0,1} -> \"a0\"]\n\\end{verbatim}\n{\\tt flag[0]} and {\\tt flag[1]} are equal to {\\tt FALSE}.\n\\\\ {\\tt turn} is equal to {\\tt 0}.\n\\\\ Both processes are entering the while spin.\n\n\\subsection{The {\\tt Next} action}\nIn order to define the {\\tt Next} action of Peterson's algorithm, we have to describe, for each process, every possible step of the algorithm. For example the {\\tt a0} step describes the fact that the considered process ({\\tt self}) is going from line {\\tt a0} to line {\\tt a1} in the algorithm (in that case, values of variables {\\tt flag} and {\\tt turn} don't change).\n\n\\begin{verbatim}\na0(self) == /\\ pc[self] = \"a0\"\n            /\\ pc' = [pc EXCEPT ![self] = \"a1\"]\n            /\\ UNCHANGED << flag, turn >>\n\\end{verbatim}\n\n\\noindent The second line above expresses the fact that the next value of the function {\\tt pc} is the same as the current one, except that its value on {\\tt self} is now {\\tt \"a1\"}.\n\n\\medskip\n\n\\noindent We then do the same for each possible step of the algorithm:\n\\begin{verbatim}\na1(self) == /\\ pc[self] = \"a1\"\n            /\\ flag' = [flag EXCEPT ![self] = TRUE]\n            /\\ pc' = [pc EXCEPT ![self] = \"a2\"]\n            /\\ UNCHANGED turn\n\na2(self) == /\\ pc[self] = \"a2\"\n            /\\ turn' = Not(self)\n            /\\ pc' = [pc EXCEPT ![self] = \"a3a\"]\n            /\\ UNCHANGED flag\n\na3a(self) == /\\ pc[self] = \"a3a\"\n             /\\ IF flag[Not(self)]\n                   THEN /\\ pc' = [pc EXCEPT ![self] = \"a3b\"]\n                   ELSE /\\ pc' = [pc EXCEPT ![self] = \"cs\"]\n             /\\ UNCHANGED << flag, turn >>\n\n\\end{verbatim}\n\\newpage\n\\begin{verbatim} \na3b(self) == /\\ pc[self] = \"a3b\"\n             /\\ IF turn = Not(self)\n                   THEN /\\ pc' = [pc EXCEPT ![self] = \"a3a\"]\n                   ELSE /\\ pc' = [pc EXCEPT ![self] = \"cs\"]\n             /\\ UNCHANGED << flag, turn >>\n\ncs(self) == /\\ pc[self] = \"cs\"\n            /\\ TRUE\n            /\\ pc' = [pc EXCEPT ![self] = \"a4\"]\n            /\\ UNCHANGED << flag, turn >>\n\na4(self) == /\\ pc[self] = \"a4\"\n            /\\ flag' = [flag EXCEPT ![self] = FALSE]\n            /\\ pc' = [pc EXCEPT ![self] = \"a0\"]\n            /\\ UNCHANGED turn\n\\end{verbatim}\n\n\\noindent Now we can define {\\tt proc(self)} as the fact that one of the previous actions is being accomplished:\n\\begin{verbatim}\nproc(self) == \\/ a0(self) \\/ a1(self) \\/ a2(self) \\/ a3a(self) \n              \\/ a3b(self) \\/ cs(self) \\/ a4(self)\n\\end{verbatim}\n          \n\\noindent Finally, we define the {\\tt Next} action, as the fact that either {\\tt proc} is accomplished for one of the processes, or the algorithm has finished (to prevent deadlock on termination).\n\n\\begin{verbatim}         \nNext == \\E self \\in {0,1}: proc(self)\n\\end{verbatim}\n\n\\medskip\n\\subsection{Specification}\nThe specification of the algorithm is given by the facts that the initial state is satisfied and that at every step either the action {\\tt Next} is satisfied or the variables in {\\tt vars} keep their values.\n\n\\begin{verbatim}\nSpec == Init /\\ [][Next]_vars\n\\end{verbatim}\n\n\\medskip\n\\subsection{Mutual Exclusion}\n%\\noindent The termination property is defined by the fact that there exists some state such that for that state and all the next ones, both processes are in step {\\tt \"Done\"}.\n% \n%\\begin{verbatim}\n%Termination == <>(\\A self \\in ProcSet: pc[self] = \"Done\")\n%\\end{verbatim}\n%\n%\\noindent The safeness property is defined by the fact that the two processes don't access the resource at the same time.\n%\n%\\begin{verbatim}\n%Safe == \\E i \\in {0, 1} : pc[i] # \"cs\"\n%\\end{verbatim}\n%\n%\\noindent The liveness property, is defined by the fact that both processes access the resource at some time.\n%\n%\\begin{verbatim}\n%Live == \\A i \\in {0, 1} : []<>(pc[i] = \"cs\")\n%\\end{verbatim}\n\nThe property we want the algorithm to satisfy can be defined as the fact that {\\tt pc[0]} and {\\tt pc[1]} have not both value {\\tt \"cs\"} at the same time.\n\n\\begin{verbatim}\nMutualExclusion == ~ (pc[0] = \"cs\" /\\ pc[1] = \"cs\")\n\\end{verbatim}\n\n\\medskip\n\\subsection{The invariant}\nLet us first define the property that ensures well-typedness of the variables .\n%\\textcolor{red}{sm: if you remove the second disjunct of Next, also remove that remark.}\n\n\\begin{verbatim}\nTypeOK == /\\ pc \\in [{0,1} -> {\"a0\",\"a1\",\"a2\",\"a3a\",\"a3b\",\"cs\",\"a4\"}]\n          /\\ turn \\in {0,1}\n          /\\ flag \\in [{0,1} -> BOOLEAN]\n\\end{verbatim}\n\n\\noindent Now we can define the invariant we want the algorithm to satisfy, in order to prove the \\linebreak {\\tt MutualExclusion} property. It is defined as the fact that for each process {\\tt i}, \n\\begin{itemize}\n\\item if it is in step {\\tt \"a2\"}, {\\tt \"a3a\"}, {\\tt \"a3b\"}, {\\tt \"cs\"} or {\\tt \"a4\"}, then its flag is equal to {\\tt TRUE} (i.e. it does want to access to the resource)\n\\item if it is in step {\\tt \"cs\"} or {\\tt \"a4\"}, then the other process is not in one of these steps, and if the other process is in step {\\tt \"a3a\"} or {\\tt \"a3b\"}  then process {\\tt i} has priority to access the resource.\n\\end{itemize}\n\n\\smallskip\n          \n\\begin{verbatim}          \nI == \\A i \\in {0, 1} :\n       /\\ (pc[i] \\in {\"a2\", \"a3a\", \"a3b\", \"cs\", \"a4\"} => flag[i])\n       /\\ (pc[i] \\in {\"cs\", \"a4\"})\n            => /\\ pc[Not(i)] \\notin {\"cs\", \"a4\"}\n               /\\ (pc[Not(i)] \\in {\"a3a\", \"a3b\"}) => (turn = i)\n\\end{verbatim}\n\n\\noindent Finally, we can define the actual invariant as the conjunction of the previous one and the fact that {\\tt TypeOK} is satisfied. \n\n\\begin{verbatim}\nFullInv == TypeOK /\\ I\n\\end{verbatim}\n\n\n\\section{Checking a simple proof from the Toolbox}\n\\label{simple}\nAs usual when we want to prove that a property is always satisfied (here {\\tt MutualExclusion}), we reason by induction and define a invariant property (here {\\tt FullInv}) such that:\n\\begin{enumerate}\n\\item the initial state (here {\\tt Init}) satisfies the invariant,\n\\item the invariant is preserved by the next-state relation (here {\\tt [Next]\\_vars}),\n\\item the invariant ensures the correctness property ({\\tt MutualExclusion}).  \n\\end{enumerate}\n\n\\noindent Proving the first fact is obvious. Let us check that by asking TLAPS to prove the following theorem (recall that we have to indicate explicitly which definitions we want to be usable in a proof):\n\n\\begin{verbatim}\nTHEOREM InitFullInv == Init => FullInv\n  BY DEF Init, FullInv, TypeOK, I, ProcSet\n\\end{verbatim}\n\n%\\textcolor{red}{sm: this should be \\texttt{FullInvariant}, not \\texttt{MutualExclusion}}\n\n\\noindent Now, in the Toolbox, put the cursor on the first line of that theorem and then right-click on \"Prove step or module\". The Toolbox then colors that theorem in green, which means that it is proved (in this case, Zenon has succeeded in finding a proof).\n\n\\section{The main theorem}\n\n\\noindent Let us now focus fact number 2 above. For proving that fact it is easier to an intermediate lemma, which states that property {\\tt TypeOK} is preserved by the next-state relation.\n\n%consider two intermediate lemmas. The first one expresses that if {\\tt TypeOK} is satisfied, then any of the process can be in step {\\tt \"Done\"}. It comes directly from the definitions of {\\tt TypeOK} and {\\tt ProcSet}.\n%\\begin{verbatim}\n%LEMMA NeverDone == \n%          TypeOK /\\ (\\A self \\in ProcSet: pc[self] = \"Done\") => FALSE\n%     BY DEFS TypeOK, ProcSet\n%\\end{verbatim}\n%\n%\\textcolor{red}{sm: this lemma would disappear, and the proof of the subsequent one simplified}\n%\\noindent The second one states that property {\\tt TypeOK} is preserved by the next-state relation.\n\n\\begin{verbatim}\nLEMMA TypeCorrect == TypeOK /\\ Next => TypeOK'\n  <1>1. ASSUME NEW i \\in {0,1}\n        PROVE  TypeOK /\\ proc(i) => TypeOK'\n    BY DEFS TypeOK, proc, a0, a1, a2, a3a, a3b, cs, a4, Not\n  <1>. QED\n    BY <1>1, NeverDone DEF Next\n\\end{verbatim}\n\n\\noindent When asking TLAPS to prove the theorem above, you can notice that step {\\tt<1>1} gets first colored black. That means that Zenon has been trying to prove it for more than three seconds. Then it gets colored red. That means that Zenon has failed to find a proof with the default timeout (ten seconds). Finally, it gets colored green since Isabelle succeeds in proving it.\n\n\\bigskip\n\n\\noindent Finally, let us prove the second item of section \\ref{simple}.\n\n\\begin{verbatim}\nTHEOREM Inductive == TypeOK /\\ I /\\ Next => I'\n\\end{verbatim}\n\n\\noindent We first rephrase the sequent to be proved in a more perspicuous form:\n\n\\begin{verbatim}\n<1>1. ASSUME TypeOK,\n             I,\n             NEW i \\in {0,1},\n             proc(i)\n      PROVE  I'\n\\end{verbatim}\n\n\\noindent We then assert {\\tt TypeOK'} (that will be useful in the following of the proof):\n\n\\begin{verbatim}\n  <2>0. TypeOK'\n\\end{verbatim}\n\n\\noindent We then split the result we want to prove into three assertions:\n\n\\begin{verbatim}\n  <2>1. ASSUME NEW j \\in {0,1},\n               pc'[j] \\in {\"a2\", \"a3a\", \"a3b\", \"cs\", \"a4\"}\n        PROVE  flag'[j]\n        \n  <2>2. ASSUME NEW j \\in {0,1},\n               pc'[j] \\in {\"cs\", \"a4\"}\n        PROVE pc'[Not(j)] \\notin {\"cs\", \"a4\"}\n        \n  <2>3. ASSUME NEW j \\in {0,1},\n               pc'[j] \\in {\"cs\", \"a4\"},\n               pc'[Not(j)] \\in {\"a3a\", \"a3b\"}\n        PROVE turn' = j\n\\end{verbatim}\n\n\\noindent Those three assertions can be proved by case on the step in which process {\\tt i} is.\nIf you ask TLAPS to prove that theorem, you can notice that all those proof-steps are colored yellow. That means that the proof is missing. It's up to you now to make them green...\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%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\begin{appendix}\n\\section{Prover options}\n\n\n\n\n\n\n\n\\section{Practical hints}\n\nThe TLA+ proof system is designed to check the validity of claims as\nindependently as possible of specific proof back-ends. We believe that users\nshould concentrate on writing proofs in terms of their particular applications,\nnot in terms of the capabilities of a particular proof system. In particular,\nTLAPS invokes its back-ends with some default setup for automatic proof, and we\ntry to make it hard for users to change this default setup. Expert users of\nback-end provers may be frustrated because they may have to develop proofs\nsomewhat further than what would be necessary with a fine-tuned tactic script.\nThe main payoff of limited access to the nitty-gritty details of provers is\ngreater clarity of the resulting proofs. They are also easier to maintain across\nminor changes of the specification or new releases of the TLA prover.\n\nOn some occasions users will encounter situations where the prover cannot prove\nan \"obvious\" proof obligation. Here are a few hints on what to try to make the\nproof go through. Your additions to this list are welcome.\n\n\n\\subsection{Control the size of formulas and expressions}\nOur provers are currently not good at making abstractions that humans understand\nimmediately. They are easily confused by moderately big proof obligations and\nare just as likely to work on a top-level conjunction as on a set construction\nburied deeply inside the formula. This can cause back-ends to become very slow\nor even unable to complete seemingly trivial steps. While we intend to improve\nthe back-ends in this respect, you can help them by using local definitions in\nproofs and hiding these definitions in order to keep expressions small. (Keep in\nmind that definitions introduced in a proof are usable by default and must be\nhidden explicitly, unlike definitions in specifications, which must be\nexplicitly $\\USE$d.)\n\n\\medskip\n\n\\noindent Here is a contrived example:\n\n\\begin{verbatim}\nLEMMA  /\\ x \\in SomeVeryBigExpression\n       /\\ y \\in AnotherBigExpression\n   <=>\n       /\\ y \\in AnotherBigExpression\n       /\\ x \\in SomeVeryBigExpression\n       \n<1> DEFINE S == SomeVeryBigExpression\n    \\** here and in the following, you may use positional names to\n    \\** avoid repeating the big expressions\n<1> DEFINE T == AnotherBigExpression\n<1>1. x \\in S <=> x \\in SomeVeryBigExpression\n  OBVIOUS\n    \\** The provers should not have any trouble proving that\n    \\** a very large expression is equivalent to itself.  If it\n    \\** can't prove this, you've almost certainly made a mistake\n    \\** in the definition of S.\n<1>2. y \\in T <=> y \\in AnotherBigExpression\n  OBVIOUS\n<1> HIDE DEF S, T\n<1>3. /\\ x \\in S\n      /\\ y \\in T\n  <=> \n      /\\ y \\in T\n      /\\ x \\in S\n  OBVIOUS\n<1>4. QED\n  BY <1>1, <1>2, <1>3\n\\end{verbatim}\n\n\\medskip\n\nThis kind of problem typically arises when reasoning about LET expressions,\nwhich are \\linebreak silently expanded by the proof manager. In a proof, introduce local\ndefinitions corresponding to the LET (using copy and paste from the\nspecification or subexpression names), show that the overall expression equals the body of the LET\n(trivial by reflexivity), establish the necessary facts about these locally\ndefined operators, and HIDE the definitions afterwards.\n\n\\medskip\n\nIntroducing definitions to hide irrelevant expressions is a useful\nthing to do whenever you're having trouble proving something.  It\nmakes the obligations whose proofs fail easier to read, making\nmistakes easier to find.\n\n\\subsection{Avoid \"circular\" (sets of) equations}\n\nRewriting is one effective way to reason about equations, and it underlies the\nautomatic proof methods used by the Isabelle back-end. The basic idea is to\norient equalities such that the expressions on the left-hand side are\nsystematically replaced by the right-hand sides. However, if the set of\nequations contains cycles as in\n\n\\begin{verbatim}\ns = f(t)\nt = g(s)\n\\end{verbatim}\n\nthen rewriting may never terminate. Isabelle employs some (incomplete)\nheuristics to detect such cycles and will refuse to rewrite equations that it\ndetermines to be circular. This usually leads to its inability to infer anything\nabout these equations. If circularity is not detected, it may cause Isabelle to\nenter an infinite loop. The suggested remedy is again to introduce local\ndefinitions that are hidden to break the loops.\n\n\\medskip\n\n\\noindent As a concrete example consider the following proof snippet:\n\n\\begin{verbatim}\n   <4>17. foo.name = \"xyz\"\n     <5>1. foo = [name |-> \"xyz\", value = foo.value]\n       BY <2>2\n     <5>2. QED\n       BY <5>1  \\** may not work because <5>1 is a circular equation\n\\end{verbatim}\n\n\\noindent One possible workaround is as follows:\n\n\\begin{verbatim}\n   <4>17. foo.name = \"xyz\"\n     <5>   DEFINE fooval == foo.value\n     <5>1. foo = [name |-> \"xyz\", value = fooval]\n       BY <2>2\n     <5>   HIDE DEF fooval\n     <5>2. QED\n       BY <5>1\n\\end{verbatim}\n%\\end{appendix}\n%\\end{document}\n\\subsection{Reasoning about CHOOSE expressions}\n\nConsider a definition such as\n\n\\begin{verbatim}\n  foo == CHOOSE x \\in S : P(x)\n\\end{verbatim}\n\nIn order to prove a property Q(foo), you will typically prove the two following\nassertions:\n\n\\begin{verbatim}\n(a) \\E x \\in S : P(x)\n(b) \\A x \\in S : P(x) => Q(x)\n\\end{verbatim}\n\nIn some cases, assertion (b) can be trivial and need not be shown explicitly.\nReasoning about an unbounded CHOOSE expression is analogous.\n\n\\medskip\n\nRemember that CHOOSE always denotes some value, even if P(x) holds for no\n$x \\in S$ (in particular, if $S = \\{\\}$), in which case the CHOOSE expression is\nfixed, but arbitrary. In practice, CHOOSE expressions usually arise when\ncondition (a) is satisfied. Should you have designed your property to work even\nif the domain of the CHOOSE is empty, property Q must be trivial in that case,\nand you can structure your proof as follows:\n\n\\begin{verbatim}\n  <3>5. Q(foo)\n    <4>1. CASE \\E x \\in S : P(x)\n      <5>1. \\A x \\in S : P(x) => Q(x)\n      <5>2. QED\n        BY <4>1, <5>1\n    <4>2. CASE ~ \\E x \\in S : P(x)\n      <5>1. \\A x : Q(x)\n      <5>2. QED\n        BY <5>1\n    <4>3. QED\n      BY <4>1, <4>2\n\\end{verbatim}\n\nA frequent TLA+ idiom is to define a \"null\" value by writing\n\n\\begin{verbatim}\nNoValue == CHOOSE x : x \\notin Value\n\\end{verbatim}\n\nThe laws of set theory ensure that no set is universal, hence there exists an x\nthat is not an element of set Value, ensuring condition (a) above. The theorem\nNoSetContainsEverything in the standard module TLAPS can be used to prove this\ncondition.\n\n\\subsection{Help the Prover When Reasoning About Records}\n\nIn one proof, we had\n\n\\begin{verbatim}\n    mb == [type  |-> \"1b\", bal |-> b, acc |-> self,\n          mCBal |-> maxCBal[self], mCVal |-> maxCVal[self]]\n\\end{verbatim}\n\nand were trying to prove\n\n\\begin{verbatim}\n    m1 # mb /\\ m2 # mb\n\\end{verbatim}\n\nfrom facts that included\n\n\\begin{verbatim}\n    m1.type = \"2av\" /\\ m2.type = \"2av\"\n\\end{verbatim}\n\nZenon failed on the proof and Isabelle proved it only after a long\ntime.  (In fact, we originally stopped the proof because it was taking\nso long.)  However, Zenon proved it instantly when we added $mb.type =\n\"1b\"$ to the BY statement's list of facts.  The provers are reluctant\nto try finding relations of the form record.field = value; they often\nneed help.\n\n\n\\subsection{Divide and Conquer}\n\nWhen the provers can't prove something that you think is obvious, it's\nusually because it isn't true.  You can easily spend hours looking at\na proof obligation without noticing a tiny mistake.  The best way to\nfind a mistake is by breaking the proof into simpler steps.\nContinuing to do this on the step or steps whose proof fails will\neventually lead you to discover the problem--usually a missing\nhypothesis or a mistake in a formula.  When you correct the mistake in\nthe original proof step, the prover will usually be able to prove it.\n\n\\subsection{Don't Reinvent Mathematics}\n\nWe expect that most people who use TLAPS will do so because they want\nto verify properties of an algorithm or system.  We have therefore not\ndevoted our limited resources to building libraries of mathematical\nresults.  If you want to create such libraries, we would welcome your\nhelp.  However, if you are concerned with an algorithm or system, you\nshould not be spending your time proving basic mathematical facts.\nInstead, you should assert the mathematical theorems you need as\nassumptions or theorems.\n\n\\medskip\n\nAsserting facts is dangerous, because it's easy to make a mistake and\nassert something false, making your entire proof unsound.\nFortunately, you can use the TLC model checker to avoid such mistakes.\nFor example, our example correctness proof of Euclid's algorithm uses\nthis assumption\n\n\\begin{verbatim}\n    ASSUME GCDProperty3 == \n           \\A p, q \\in Nat \\ {0}: (p < q) => GCD(p, q) = GCD(p, q-p)\n\\end{verbatim}\n\nTLC cannot check this assumption because it can't evaluate a\nquantification over an infinite set.  However, you can tell TLC to\nreplace the definition of Nat with\n\n\\begin{verbatim}\n    Nat == 0..50\n\\end{verbatim}\n\n(In the Toolbox, use the Definition Override section of the model's\nAdvanced Options page.)  TLC quickly verifies this assumption.  (TLC\nchecks each ASSUME; to add an assumption that you don't want TLC to check,\nmake it an AXIOM.)  \n\nThis kind of checking is almost certain to catch an error in\nexpressing a fundamentally correct mathematical result--except when\nthe only counterexamples are infinite.  Fortunately, this is rarely\nthe case when the result is needed for reasoning about an algorithm or\nsystem.\n\n\\subsection{It's Easier to Prove Something if it's True}\n\nBefore trying to prove a property of an algorithm or system, try to\ncheck it with TLC. Even if TLC cannot check a large enough model to\ncatch all errors, running it on a small model can still catch many\nsimple errors.  You will save a lot of time if you let TLC find these\nerrors instead of discovering them while writing the proof.\n\n\n\\end{appendix}\n\n\\end{document}\n", "meta": {"hexsha": "e9475ac0c5803bb5695067237050fb34226c5007", "size": 25333, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/presentations/2010-ifm/tutoriel-Peterson/Peterson_IFM2010.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/tutoriel-Peterson/Peterson_IFM2010.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/tutoriel-Peterson/Peterson_IFM2010.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": 38.7947932619, "max_line_length": 380, "alphanum_fraction": 0.682824774, "num_tokens": 6766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6264698643407146}}
{"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\n\\usepackage{tikz}\n%diacritic characters\n\\begin{document}\n\\paragraph{Quotient Set Notation}\nThere are many ways denote the quotient set (check the \\emph{Book of Proof} for one way).\nA common method is to get a notation for an individual equivalence class first.\nSay $[x] = \\{ y \\in C: x \\sim y\\}$ which is the set of all bundles in $C$ that are indifferent to $x$.\nThen we might create a class of sets (set of sets) using the indexed collection of sets notation you covered in the prerequisite readings.\nFor example $\\mathcal{I} = \\{ [x] : x \\in C\\}$ where $[x]=\\{ y \\in C: x \\sim y\\}$.\nRemember that sets only contain distinct elements so even though we ``loop'' through all values $x$ any two values $x,y$ such that $x \\sim y$ will lead to $[x] = [y]$ and the distinct equivalence class will only show up once in the collection $\\mathcal{I}$.\n\n\\paragraph{Problem 10}\nLet $\\succsim$ be rational preference relation and define $\\sim$ as the indifference relation where $x\\sim y$ iff $[x\\succsim y \\wedge y\\succsim x]$.\nBecause $\\succsim$ is rational we know that it is complete, reflexive and transitive.\nTo show $(x,x) \\in \\sim, \\; \\forall x$ we can refer to completeness to know that either $x\\succsim x$ or $x\\succsim x$ and by reflexiveness we know both statements are true so $x\\sim x$.\n\nSymmetry would imply that for any $x,y\\in C$ if $(x,y)\\in \\sim$ then $(y,x) \\in \\sim$.\nAgain we now know that $\\sim$ is reflexive and we still know $\\succsim$ is complete, reflexive and transitive and we should use these facts to establish symmetry and transitivity of $\\sim$.\nLet $x,y\\in C$ and suppose $x \\sim y$.\nThen we know $[x\\succsim y \\wedge y\\succsim x]$ is true by definition of $\\sim$.\nBecause the order of arguments in the conjunction don't alter its truth value we could say\n$[y\\succsim x \\wedge x \\succsim y]$ which is the definition of $y\\sim x$.\n\nFor transitivity, suppose $x,y,z \\in C$ and $[x\\sim y \\wedge y \\sim z]$.\nThen by definition $[x\\succsim y \\wedge y\\succsim x]$ and $[y\\succsim z \\wedge z\\succsim y]$.\nHence we have $x \\succsim y \\succsim z$ which by transitivity of $\\succsim$ implies $x\\succsim z$ and we also have $z\\succsim y \\succsim x$ which by transitivity of $\\succsim$ implies $z\\succsim x$.\nSince we have $[x\\succsim z \\wedge z\\succsim x]$ we see that $x \\sim z$ and therefore $\\sim$ is transitive.\n\\end{document}", "meta": {"hexsha": "8e9fd4bf98683098b62d4c53d7ad73c25bfc4ee9", "size": 2532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/pdfs/math_bootcamp/2016/HW1Prob10Suggest.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/2016/HW1Prob10Suggest.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/2016/HW1Prob10Suggest.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": 76.7272727273, "max_line_length": 257, "alphanum_fraction": 0.7235387046, "num_tokens": 774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6264698606659188}}
{"text": "\\subsection{Simple algebraic structures}\\label{subsec:simple_algebraic_structures}\n\nWe list here several basic algebraic structures, we will use mostly as building blocks for more complicated structures.\n\nAs discussed in \\fullref{rem:first_order_model_notation}, denoting all operations explicitly is cumbersome, and we will usually avoid it.\n\n\\begin{definition}\\label{def:pointed_set}\\mcite[26]{MacLane1994}\n  The simplest algebraic structure is a \\term{pointed set}. It is simply a nonempty set \\( \\mscrX \\) equipped with a distinguished element \\( e \\). It is an algebraic structure because \\( e \\) can be regarded as the sole value of a nullary function \\( *: \\mscrX^0 \\to \\mscrX \\).\n\n  We will call \\( e \\) the \\term{origin} of \\( \\mscrX \\) based on the terminology for \\hyperref[def:euclidean_plane_coordinate_system/origin]{affine coordinate systems}.\n\n  \\begin{thmenum}\n    \\thmitem{def:pointed_set/theory} Pointed sets can also be viewed as \\hyperref[def:first_order_semantics/satisfiability]{models} of an empty \\hyperref[def:first_order_theory]{theory} for a \\hyperref[def:first_order_language]{first-order logic language} with a constant symbol, i.e. a nullary \\hyperref[def:first_order_language/func]{functional symbol}.\n\n    \\thmitem{def:pointed_set/homomorphism} A \\hyperref[def:first_order_homomorphism]{homomorphism} between the pointed sets \\( (\\mscrX, e_{\\mscrX}) \\) and \\( (\\mscrY, e_{\\mscrY}) \\) is, explicitly, a function \\( \\varphi: \\mscrX \\to \\mscrY \\) that satisfies\n    \\begin{equation}\\label{eq:def:pointed_set/homomorphism}\n      \\varphi(e_{\\mscrX}) = e_{\\mscrY}.\n    \\end{equation}\n\n    \\thmitem{def:pointed_set/submodel} The set \\( S \\subseteq \\mscrX \\) is a \\hyperref[def:first_order_substructure]{substructure} if \\( \\mscrX \\) if \\( e \\in S \\).\n\n    \\thmitem{def:pointed_set/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} pointed set is, up to an isomorphism, the set \\( \\set{ e } \\).\n\n    It is a \\hyperref[def:universal_objects/initial]{zero object} in \\( \\cat{Set_*} \\) as discussed in \\fullref{ex:def:universal_objects/grp}.\n\n    \\thmitem{def:pointed_set/category} We denote the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for this theory by \\( \\ucat{Set}_* \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:pointed_set_kernel}\\mimprovised\n  The \\term{kernel} \\( \\ker(\\varphi) \\) of a \\hyperref[def:pointed_set/homomorphism]{pointed set homomorphism} \\( \\varphi: \\mscrX \\to \\mscrY \\) is the \\hyperref[def:zero_locus]{zero locus} of \\( \\varphi \\). That is, \\hyperref[thm:def:function/properties/preimage]{preimage} \\( \\varphi^{-1}(e_\\mscrY) \\).\n\n  These are the \\hyperref[def:zero_morphisms/kernel]{categorical kernels} in \\hyperref[def:pointed_set/category]{\\( \\cat{Set_*} \\)}. This is discussed in \\fullref{ex:zero_morphisms_in_grp/kernel} for \\hyperref[def:group]{groups}, where the argument only depends on groups being pointed sets.\n\\end{definition}\n\n\\begin{definition}\\label{def:set_with_involution}\\mimprovised\n  A \\term{set with an involution} is a \\hyperref[def:set]{set} \\( \\mscrX \\) with a unary operation \\( (\\anon)^{-1} \\) such that\n  \\begin{equation*}\n    (x^{-1})^{-1} = x\n  \\end{equation*}\n  for every \\( x \\in \\mscrX \\).\n\n  Such an operation is called, surprisingly, an \\term{involution}.\n\n  \\begin{thmenum}\n    \\thmitem{def:set_with_involution/theory} We define the theory of sets with involution as a theory over the language consisting of a single unary functional symbol \\( \\anon^{-1} \\) and the sole axiom\n    \\begin{equation}\\label{eq:def:set_with_involution/theory/axiom}\n      (\\xi^{-1})^{-1} \\doteq \\xi.\n    \\end{equation}\n\n    \\thmitem{def:set_with_involution/homomorphism} A \\hyperref[def:first_order_homomorphism]{homomorphism} between sets with involutions \\( \\mscrX \\) and \\( \\mscrY \\) is a function \\( \\varphi: \\mscrX \\to \\mscrY \\) satisfying\n    \\begin{equation}\\label{eq:def:set_with_involution/homomorphism}\n      \\varphi(x^{-1})\n      =\n      \\varphi(x)^{-1}.\n    \\end{equation}\n\n    \\thmitem{def:set_with_involution/submodel} Any subset of a set with involution is again a set with involution.\n\n    \\thmitem{def:set_with_involution/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} set with involution is the empty set.\n\n    \\thmitem{def:set_with_involution/category} We denote the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for this theory by \\( \\ucat{Inv} \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:magma}\n  A \\term{magma} is a set \\( \\mscrM \\) equipped with a \\hyperref[def:multi_valued_function/arguments]{binary function} \\( \\cdot: \\mscrM \\times \\mscrM \\to \\mscrM \\), called the \\term{magma operation}. Unless specified otherwise, we denote this operation by juxtaposition as \\( xy \\) instead of \\( x \\cdot y \\).\n\n  We often call the operation \\term{multiplication} or, in the case of \\hyperref[def:endomorphism_monoid]{endomorphism monoids} --- \\term{composition}. See also the notes in \\fullref{rem:additive_magma} regarding additive magmas and in \\fullref{def:monoid_delooping} regarding the order of operands.\n\n  \\begin{thmenum}[series=def:magma]\n    \\thmitem{def:magma/theory} In analogy to the \\hyperref[def:pointed_set/theory]{theory of pointed sets}, we can define the theory of magmas as an empty theory over a language with a single \\hyperref[rem:first_order_formula_conventions/infix]{infix} binary functional symbol.\n\n    \\thmitem{def:magma/homomorphism} A \\hyperref[def:first_order_homomorphism]{homomorphism} between the magmas \\( (\\mscrM, \\cdot_{\\mscrM}) \\) and \\( (\\mscrN, \\cdot_{\\mscrN}) \\) is, explicitly, a function \\( \\varphi: \\mscrM \\to \\mscrN \\) such that\n    \\begin{equation}\\label{eq:def:magma/homomorphism}\n      \\varphi(x \\cdot_{\\mscrM} y) = \\varphi(x) \\cdot_{\\mscrN} \\varphi(y)\n    \\end{equation}\n    for all \\( x, y \\in \\mscrM \\).\n\n    \\thmitem{def:magma/submodel} The set \\( S \\subseteq \\mscrM \\) is a \\hyperref[def:first_order_substructure]{first-order submodel} of \\( \\mscrM \\) if it is closed under the magma operation. That is, if \\( x, y \\in S \\) implies \\( xy \\in S \\).\n\n    We call \\( S \\) a \\term{submagma} of \\( \\mscrM \\).\n\n    \\thmitem{def:magma/category} We denote the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for the theory of magmas by \\( \\ucat{Mag} \\).\n\n    \\thmitem{def:magma/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial magma} is the empty set with an empty operation. It is the unique \\hyperref[def:universal_objects/initial]{zero object} in \\( \\cat{Mag} \\).\n\n    \\thmitem{def:magma/opposite} The \\term{opposite magma} of \\( (\\mscrM, \\cdot) \\), also called the \\term{dual magma}, is the magma \\( (\\mscrM, \\star) \\) with multiplication reversed:\n    \\begin{equation*}\n      x \\star y \\coloneqq y \\cdot x.\n    \\end{equation*}\n\n    We denote the opposite magma by \\( \\mscrM^{-1} \\).\n\n    \\thmitem{def:magma/exponentiation} We define an additional \\term{exponentiation} operation for positive integers \\( n \\) inductively as\n    \\begin{equation}\\label{eq:def:magma/exponentiation}\n      x^n \\coloneqq \\begin{cases}\n        x,               & n = 1 \\\\\n        x \\cdot x^{n-1}, & n > 1\n      \\end{cases}\n    \\end{equation}\n\n    \\thmitem{def:magma/power_set} It is customary to perform magma operations with sets. That is, if \\( A \\) and \\( B \\) are sets in the magma \\( \\mscrM \\), it is customary to write\n    \\begin{equation*}\n      A \\cdot B \\coloneqq \\set{ a \\cdot b \\colon a \\in A, b \\in B }.\n    \\end{equation*}\n\n    This actually turns the power set \\( \\pow(\\mscrM) \\) into a magma, which we will call the \\term{power set magma} of \\( \\mscrM \\). This is especially useful with the convention \\fullref{rem:singleton_sets} since it allows us to write \\( aB \\) for \\( a \\in M \\) and \\( B \\subseteq M \\).\n\n    See \\fullref{thm:power_set_magma_preservation}.\n  \\end{thmenum}\n\n  We list some additional restrictions that are often imposed on magmas.\n  \\begin{thmenum}[resume=def:magma]\n    \\thmitem{def:magma/associative} We can add the (\\hyperref[thm:implicit_universal_quantification]{universal closure} of) following axiom to the theory:\n    \\begin{equation}\\label{eq:def:magma/associative}\n      (x \\cdot y) \\cdot z = x \\cdot (y \\cdot z).\n    \\end{equation}\n\n    If \\eqref{eq:def:magma/associative} is satisfied, we say that the operation \\( \\cdot \\) and, by extension, the magma itself, are \\term{associative}. Associative magmas are usually called \\term{semigroups}. Associativity imposes no additional restrictions on the homomorphisms, hence semigroups are a \\hyperref[def:subcategory]{full subcategory} of \\( \\cat{Mag} \\).\n\n    \\thmitem{def:magma/commutative} Another common axiom is \\term{commutativity}:\n    \\begin{equation}\\label{eq:def:magma/commutative}\n      x \\cdot y = y \\cdot x.\n    \\end{equation}\n\n    Commutative magmas also form a full subcategory. Obviously \\( \\mscrM = \\mscrM^{-1} \\) in a commutative magma.\n\n    \\thmitem{def:magma/idempotent} We say that the operation \\( \\cdot \\) is \\term{idempotent} if\n    \\begin{equation}\\label{eq:def:magma/idempotent}\n      x \\cdot x = x.\n    \\end{equation}\n\n    \\thmitem{def:magma/cancellative} We say that \\( \\cdot \\) is \\term{left-cancellative} (resp. \\term{right-cancellative}) if\n    \\begin{equation}\\label{eq:def:magma/cancellative}\n      z \\cdot x = z \\cdot y \\T{for all} z \\in \\mscrM \\T{implies that} x = y\n      \\quad\n      (\\T{resp.} x \\cdot z = y \\cdot z).\n    \\end{equation}\n\n    The operation is \\term{cancellative} if it is both left and right cancellative. Cancellative magmas also form a full subcategory.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:magma}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{ex:def:magma/composition} The quintessential example of a non-\\hyperref[def:magma/commutative]{commutative} operation is \\hyperref[def:multi_valued_function/composition]{composition} in any set of functions or, more generally, \\hyperref[def:category/composition]{morphism composition} in any \\hyperref[def:category]{category}.\n\n    Composition is \\hyperref[def:magma/associative]{associative}. \\hyperref[def:magma/cancellative]{Cancellation} with respect to composition is discussed in \\fullref{def:morphism_invertibility} and, for function composition, in \\fullref{thm:function_invertibility_categorical}.\n\n    \\thmitem{ex:def:magma/midpoint} The operation\n    \\begin{equation*}\n      (x, y) \\mapsto \\dfrac {x + y} 2\n    \\end{equation*}\n    makes \\( \\BbbR \\) a commutative and cancellative magma, which is not associative.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{remark}\\label{rem:additive_magma}\n  General groups often arise as \\hyperref[def:automorphism_group]{automorphism groups}, which are, for the most part, non-commutative, while abelian groups are usually used as the main building block for \\hyperref[def:semiring/ring]{rings} and \\hyperref[def:left_module]{modules}.\n\n  To make a further distinction, if the operation is denoted by \\( \\cdot \\) or juxtaposition, we say that the group is a \\term{multiplicative group}, and if the operation is denoted by \\( + \\), we say that the group is an \\term{additive group}. This terminology usually, but not necessarily, coincides with the group (or, more generally, the \\hyperref[def:magma]{magma}) being \\hyperref[def:magma/commutative]{commutative}.\n\n  To make things explicit, a \\term{multiplicative magma} is any magma as defined in \\fullref{def:magma}. Compare this to \\term{additive magmas}, where\n  \\begin{thmenum}\n    \\thmitem{rem:additive_magma/addition} The magma operation is denoted by \\( + \\) and called \\term{addition}.\n\n    \\thmitem{rem:additive_magma/multiplication} The magma \\hyperref[def:magma/exponentiation]{exponentiation operation} is denoted by \\( \\cdot \\) or juxtaposition and called \\term{multiplication}. Thus, multiplication is not defined for two elements of the magma, but defined for a positive integer and an element of the magma. In the case of a \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:unital_magma/monoid]{monoid}, if multiplication is extended to two elements of the monoid, we instead talk about \\hyperref[def:semiring]{semirings}.\n\n    \\thmitem{rem:additive_magma/identity} The \\hyperref[def:magma_identity]{identity} is usually denoted by \\( 0 \\).\n\n    \\thmitem{rem:additive_magma/inverse} If an \\hyperref[def:unital_magma_inverse_element]{inverse} of \\( x \\) exists, it is denoted by \\( -x \\) rather than \\( x^{-1} \\).\n  \\end{thmenum}\n\\end{remark}\n\n\\begin{proposition}\\label{thm:power_set_magma_preservation}\n  \\hyperref[def:magma/associative]{Associativity} and \\hyperref[def:magma/commutative]{commutativity} from a magma \\( \\mscrM \\) are preserved in \\( \\pow(\\mscrM) \\), unlike \\hyperref[def:magma/cancellative]{cancellation}.\n\\end{proposition}\n\\begin{proof}\n  Associativity and commutativity are obviously preserved.\n\n  To show that cancellation is not, consider the group \\hyperref[def:group_of_integers_modulo]{\\( \\BbbZ_2 \\)}. It is a cancellative magma by \\fullref{thm:def:group/properties/cancellative}. Define the sets \\( A \\coloneqq \\{ 0, 1 \\} \\) and \\( B \\coloneqq \\{ 0 \\} \\). Then\n  \\begin{equation*}\n    A + A = A = A + B,\n  \\end{equation*}\n  however we cannot cancel \\( A \\) from the left because \\( A \\neq B \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:magma_exponentiation_properties}\n  Fix a magma \\( \\mscrM \\). \\hyperref[def:magma/exponentiation]{Magma exponentiation} in \\( \\mscrM \\) has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{thm:magma_exponentiation_properties/commutativity} We have the following \\hyperref[def:magma/commutative]{commutativity}-like property: for \\( x \\in M \\) and \\( n = 1, 2, \\ldots \\),\n    \\begin{equation}\\label{eq:thm:magma_exponentiation_properties/commutativity}\n      x^n = x x^{n-1} = x^{n-1} x.\n    \\end{equation}\n\n    \\thmitem{thm:magma_exponentiation_properties/distributivity} Exponentiation distributes over multiplication: for any member \\( x \\in M \\) and any two positive integers \\( n \\) and \\( m \\),\n    \\begin{equation}\\label{eq:thm:magma_exponentiation_properties/multiplication}\n      x^{n + m} = x^n x^m.\n    \\end{equation}\n\n    \\thmitem{thm:magma_exponentiation_properties/repeated} For any member \\( x \\in M \\) and any two positive integers \\( n \\) and \\( m \\),\n    \\begin{equation}\\label{eq:thm:magma_exponentiation_properties/repeated}\n      (x^n)^m = x^{nm}.\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:magma_exponentiation_properties/commutativity} We use induction on \\( n \\). The cases \\( n = 1 \\) and \\( n = 2 \\) are obvious. For \\( n > 2 \\), we have\n  \\begin{equation*}\n    x^n\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    x x^{n-1}\n    \\reloset {\\T{ind.}} =\n    x x^{n-2} x\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    x^{n-1} x.\n  \\end{equation*}\n\n  \\SubProofOf{thm:magma_exponentiation_properties/distributivity} We use induction on \\( n \\). The case \\( n = 1 \\) follows directly from \\eqref{eq:def:magma/exponentiation}. The case \\( n > 1 \\) follows from\n  \\begin{equation*}\n    x^{n + m}\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    x x^{n + (m - 1)}\n    \\reloset {\\T{ind.}} =\n    x x^{n-1} x^m\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    x^n x^m.\n  \\end{equation*}\n\n  \\SubProofOf{thm:magma_exponentiation_properties/repeated} We use induction on \\( n \\). The case \\( n = 1 \\) is obvious and the rest follows from\n  \\begin{equation*}\n    (x^n)^m\n    \\reloset {\\eqref{eq:def:magma/exponentiation}} =\n    x^n (x^n)^{m-1}\n    \\reloset {\\T{ind.}} =\n    x^n x^{n (m - 1)}\n    \\reloset {\\eqref{eq:thm:magma_exponentiation_properties/multiplication}} =\n    =\n    x^{nm}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:preordered_magma}\n  A \\term{preordered magma} is a magma \\( \\mscrM \\) equipped with a \\hyperref[def:preordered_set]{preorder} \\( \\leq \\) such that \\( x \\leq y \\) implies \\( xz \\leq yz \\) and \\( zx \\leq zy \\) for all \\( z \\in M \\).\n\n  The category of small preordered magmas is both \\hyperref[def:magma/category]{\\( \\cat{Mag} \\)}-\\hyperref[def:concrete_category]{concrete} and \\hyperref[def:preordered_set/category]{\\( \\cat{PreOrd} \\)}-concrete.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:preordered_magma_max_distributivity}\n  In a \\hyperref[def:preordered_magma]{preordered magma} \\( \\mscrM \\),\n  \\begin{equation}\\label{eq:thm:preordered_magma_max_distributivity}\n    \\max \\set{a b, c d} \\leq \\max \\set{a, c} \\cdot \\max \\set{b, d}.\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  Since \\( a \\leq \\max \\set{a, c} \\), then\n  \\begin{equation*}\n    ab\n    \\leq\n    \\max \\set{a, c} \\cdot b\n    \\leq\n    \\max \\set{a, c} \\cdot \\set{b, d}\n  \\end{equation*}\n\n  Analogously, \\( cd \\leq \\max \\set{a, c} \\cdot \\set{b, d} \\) and\n  \\begin{equation*}\n    \\max \\set{a b, c d} \\leq \\max \\set{a, c} \\cdot \\set{b, d}.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:topological_magma}\n  A \\term{topological magma} is a magma equipped with a \\hyperref[def:topological_space]{topology} such that the magma operation is continuous.\n\n  The category of small topological magmas is both \\hyperref[def:magma/category]{\\( \\cat{Mag} \\)}-\\hyperref[def:concrete_category]{concrete} and \\hyperref[def:category_of_small_topological_spaces]{\\( \\cat{Top} \\)}-concrete.\n\\end{definition}\n\n\\begin{definition}\\label{def:magma_identity}\n  An element \\( e \\) of a magma \\( \\mscrM \\) is called a \\term{left identity} (resp. \\term{right identity}) if \\( ex = x \\) for all \\( x \\in M \\) (resp. \\( xe = x \\) for all \\( x \\in M \\)).\n\n  If \\( e \\) is simultaneously a left and right identity, we call a \\term{two-sided identity} or simply \\term{identity} of \\( \\mscrM \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:magma_identity_unique}\n  A two-sided \\hyperref[def:magma_identity]{magma identity} \\( e \\), if it exists, is unique.\n\\end{proposition}\n\\begin{proof}\n  If \\( f \\) is another identity, then \\( e = ef = f \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:unital_magma}\n  A \\hyperref[def:magma]{magma} with an \\hyperref[def:magma_identity]{identity} is called \\term{unital}. This makes it a \\hyperref[def:pointed_set]{pointed set}. We can consider it as a pair \\( (\\mscrM, \\cdot) \\) rather than a triple \\( (\\mscrM, \\cdot, e) \\) because, by \\fullref{thm:magma_identity_unique}, a two-sided identity is uniquely determined by the magma operation.\n\n  \\begin{thmenum}\n    \\thmitem{def:unital_magma/theory} The theory of unital magmas consists of the single axiom\n    \\begin{equation}\\label{eq:def:unital_magma/theory/identity}\n      \\qforall \\xi (e \\cdot \\xi \\doteq \\xi \\wedge \\xi \\cdot e \\doteq \\xi)\n    \\end{equation}\n    over the combined language of \\hyperref[def:pointed_set/theory]{pointed sets} and \\hyperref[def:magma/theory]{magmas}.\n\n    \\thmitem{def:unital_magma/homomorphism} A \\hyperref[def:first_order_homomorphism]{homomorphism} between unital magmas is a function that satisfies both \\eqref{eq:def:pointed_set/homomorphism} and \\eqref{eq:def:magma/homomorphism}.\n\n    \\thmitem{def:unital_magma/category} The \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} \\( \\ucat{Mag}_* \\) of unital magmas is \\hyperref[def:concrete_category]{concrete} with respect to both \\hyperref[def:pointed_set/category]{\\( \\ucat{Set}_* \\)} and \\hyperref[def:magma/category]{\\( \\ucat{Mag} \\)}.\n\n    \\thmitem{def:unital_magma/submodel} The set \\( S \\subseteq X \\) is a \\hyperref[def:first_order_substructure]{substructure} if \\( \\mscrX \\) if \\( e \\in S \\). This is equivalent to \\( S \\) being a pointed subset.\n\n    We say that \\( S \\) is a \\term{unital submagma}.\n\n    \\thmitem{def:unital_magma/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} unital magma is the \\hyperref[def:pointed_set/trivial]{trivial pointed set} \\( \\set{ e } \\).\n\n    \\thmitem{def:unital_magma/monoid} An \\hyperref[eq:def:magma/associative]{associative} unital magma is called a \\term{monoid}. The category \\( \\cat{Mon} \\) of monoids is a full subcategory of \\( \\cat{Mag}_* \\).\n\n    \\thmitem{def:unital_magma/exponentiation} We extend \\hyperref[def:magma/exponentiation]{magma exponentiation} to all nonnegative integers by defining\n    \\begin{equation*}\n      x^0 \\coloneqq e.\n    \\end{equation*}\n\n    \\thmitem{def:unital_magma/power_set} The \\hyperref[def:magma/power_set]{power set magma} \\( \\pow(\\mscrM) \\) of a unital magma \\( \\mscrM \\) with identity \\( e \\) is again a unital magma with identity \\( \\set{ e } \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:monoid_cancellation_not_preserved_by_homomorphism}\\mcite{MathSE:magma_cancellation_not_preserved}\n  \\hyperref[def:unital_magma/homomorphism]{Monoid homomorphisms} may not preserve the \\hyperref[def:magma/cancellative]{cancellation property}. For example, the \\hyperref[def:set_of_natural_numbers]{natural numbers} \\( \\BbbN \\) are a cancellative monoid under addition, as shown in \\fullref{thm:def:natural_number_addition/properties}), but the magma homomorphism\n  \\begin{equation*}\n    \\begin{aligned}\n      &h: (\\BbbN, +) \\to (\\hyperref[thm:galois_field_existence]{\\BbbF_2}, \\max) \\\\\n      &h(n) \\coloneqq \\begin{cases}\n        0, &n = 0 \\\\\n        1, &n > 0\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation*}\n  does not preserve the cancellative property.\n\n  Indeed, \\( \\max\\set{ 0, 1} = \\max\\set{ 1, 1 } \\), but \\( 0 \\neq 1 \\).\n\\end{example}\n\n\\begin{proposition}\\label{thm:unital_magma_kernel_is_submagma}\n  The \\hyperref[def:pointed_set_kernel]{kernel} of a unital magma homomorphism \\( \\varphi: \\mscrM \\to \\mscrN \\) is a \\hyperref[def:first_order_substructure]{unital submagma} of \\( \\mscrM \\).\n\\end{proposition}\n\\begin{proof}\n  By \\eqref{eq:def:pointed_set/homomorphism}, \\( e_{\\mscrM} \\in \\ker(\\varphi) \\), therefore \\( \\ker(\\varphi) \\) inherits its unital magma structure from \\( \\mscrM \\). It remains only to show that it is closed under the magma operation. But this is trivial since, if \\( x, y \\in \\ker(\\varphi) \\), then\n  \\begin{equation*}\n    \\varphi(xy) = \\varphi(x) \\varphi(y) = e_{\\mscrN} e_{\\mscrN} = e_{\\mscrN}.\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "96823136dc5d619a1d638dffaf08decb854cc96a", "size": 22186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/algebraic_building_blocks.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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_building_blocks.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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_building_blocks.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "32b364d134182efedaf961d5b3b67e8d1a9d37cf", "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.5702005731, "max_line_length": 553, "alphanum_fraction": 0.7099522221, "num_tokens": 7071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6264698514789293}}
{"text": "\\chapter{Mathematical Background}\n\\section{One-Shot Games}\n\\subsection{Prisoner's Dilemma}\nThe Prisoner's Dilemma is the canonical game of game theory, finding its use in models for everything from share prices to the relationship between lions and small birds. Essentially, in any situation where there is the possibility of cooperation, the Prisoner's Dilemma can be a useful model in understanding the situation to a first approximation.\n\\subsubsection{The Story}\nThe motivating story goes that two accomplices are caught at a crime scene, arrested and placed in seperate cells with no contact. The police give them each a choice: they can confess their crimes to the authorities (defect) or they can stay silent (cooperate).\\\\\nThey learn that if they both cooperate, they only get one year in prison. If they both defect, they both get two years. However, if one of them cooperates and the other defects, the cooperator gets 3 years and the defector gets out of jail immediately. As they are in seperate cells, they cannot communicate.\\\\\nThe smallest combined time in prison for the couple is if they both cooperate and take 1 year in jail each. But even if they could communicate and agree to the appealing option of both cooperating, it would still make sense to defect from the `contract' and defect. But just 1 year in jail is clearly better than 2. How should they work through this? As with most things in life, they should get mathematical.\n\\subsection{Making this Mathematical}\n\\subsubsection{Key Concepts}\nThis story has all the features of a game-theoretic game. Let's go through it, pick out the key elements and name them.\\\\\nThe four essential elements of a game have a useful acronym: \\textit{PAPI} \\cite{rasmusen}. This stands for:\\\\\nthe \\textbf{P}layers of the game,\\\\\nthe \\textbf{A}ctions available to each player,\\\\\nthe \\textbf{P}ayoffs for each outcome\\footnote{An \\textit{outcome} defines an action for each player. It can be written $(C,C)$ for two players both playing the action $(C)$. Note, actions are usually represented as a single letter i.e. $(C)$ for cooperate and $(D)$ for defect. } and\\\\\nthe \\textbf{I}nformation available to each player.\\\\\n\nIn our story, there are two players: Lou and Avery. The actions are cooperate with the partner in crime (i.e. stay quiet) or defect (i.e. confess and betray partner). The payoffs are given by the years in jail, $-x$ for $x$ years in jail. As they cannot communicate, there is no information available about the other player's choice prior to choosing.\n\\subsubsection{Representing games}\n\\subsubsection{Payoff Matrix}\nA payoff matrix is a way of defining two-player simultaneous games completely i.e. it tells you about every element of \\textit{PAPI}. The payoff matrix for the Prisoner's Dilemma given in the story would be:\\\\\n\\setlength{\\extrarowheight}{2pt}\n\\begin{tabular}{cc|c|c|}\n\t& \\multicolumn{1}{c}{} & \\multicolumn{2}{c}{Avery}\\\\\n\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$C$}  & \\multicolumn{1}{c}{$D$} \\\\\\cline{3-4}\n\t\\multirow{2}*{Lou}  & $C$ & $(-1,-1)$ & $(-3,0)$ \\\\\\cline{3-4}\n\t& $D$ & $(0,-3)$ & $(-2,-2)$ \\\\\\cline{3-4}\n\\end{tabular}\n\\\\\n\\\\\nThe players, actions and payoffs are defined. Also there is no information available about the other player's action. So this matrix completely describes the game. Note that the the ordered pair $(x,y)$ in each matrix entry gives the payoffs for each outcome. $x$ gives the payoff for the horizontal player and $y$ gives the vertical player's. So outcome $(D,C)$ has payoff $(0,-3)$ meaning a payoff of $0$ for Lou for defecting and a payoff of $-3$ for Avery for cooperating.\\\\\nThe payoff matrix is an extremely useful representation, allowing concise, complete descriptions of games. Consider, for example:\\\\\n\\setlength{\\extrarowheight}{2pt}\n\\begin{tabular}{cc|c|c|c|}\n\t& \\multicolumn{1}{c}{} & \\multicolumn{3}{c}{Avery} \\\\\n\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$R$}  & \\multicolumn{1}{c}{$P$}  & \\multicolumn{1}{c}{$S$} \\\\\\cline{3-5}\n\t& $R$ & $(0,0)$ & $(-1,1)$ & $(1,-1)$ \\\\ \\cline{3-5}\n\tLou  & $P$ & $(1,-1)$ & $(0,0)$ & $(-1,1)$ \\\\\\cline{3-5}\n\t& $S$ & $(-1,1)$ & $(1,-1)$ & $(0,0)$ \\\\\\cline{3-5}\n\\end{tabular}\n\\\\\n\\\\\nThis game might initially look foreign, but it is simply Rock, Paper, Scissors. You can create stories to motivate them but the payoff matrix completely defines all the relevant mathematical aspects of the game. This allows us to abstract from the messy details of the human world and find `solutions' to the game.\n\\subsubsection{Solution Concepts}\nA \\textit{strategy} is a set of rules for which actions to play at each point of the game. It can respond to the other player's actions.\n\\subsubsection{Strategies}\n\\paragraph{Socially Optimal Strategy}Lou is able to recognise the \\textit{socially optimal strategy} as the option of both cooperate so that they get only 1 year each. This is the outcome that leads to the highest joint payoff for all players.\n\\paragraph{Nash Equilibrium} However, the outcome with both defecting is the Nash Equilibrium. This is an outcome in which, even if all players knew what the rest of the players actions were, none of them would choose to change their action as it would not improve their payoff. In this game, both players defecting is the unique Nash Equilibrium.\n\\paragraph{Dominant Strategy}The outcome of $(D, D)$ actually satisfies a stronger condition as the action defect is a \\textit{dominant strategy} for both players. This means that no matter what action the opponent plays, the player can always increase their payoff by defecting. This is the way (defect, defect) `pulls' players in, despite it having a worse payoff for both players than cooperate cooperate. Game theory assumes that players are \\textit{rational} (i.e. the payoffs we have described actually match their desires and they are aware of how the game works). So if Lou and Avery are rational, they will always end up both defecting, betraying each other and being rewarded with a longer jail term. So it goes.\n\n\\section{Repeated Games}\n\\subsubsection{Introduction}\nThe previous games are called \\textit{one-shot games} meaning, after the first game is played, no further games are played. It happens once and never again, with no possible repurcussions that are not already described in the payoff matrix.\\\\\n\nUnlike one-shot games, repeated games have players play multiple games against each other. This means that it is harder or even impossible to `solve' these games to find the best actions and equilibria. However, this makes them more interesting, allowing for complex dynamics. For example, the prisoner's dilemma no longer has a best strategy when repeated.\n\\subsubsection{Repeated Prisoner's Dilemma Tournament}\nWe can create a tournament of different strategies all playing several hundred games against each other. The winner is the strategy with the highest payoff overall. This numerical experiment was famously first done by Robert Axelrod\\cite{axelrod} in the 1980s. In Axelrod's first tournament, the winner was `Tit for Tat', a strategy that always cooperates on the first round and then copies the opponents previous move forever after.\\\\\n(\nMy simulation of Prisoner's Dilemma tournament.\\\\\nInclude Tit for Tat, Grim Trigger, Random, always cooperate, always defect, tit for two tats etc.\\\\\nbrief analysis of my results- graph of results\n)\n\n\\subsubsection{Repeated Games with Evolution}\n[Include replicator equations at some point here.]\\\\\nIncorporating repetitions, allows the possibility of 'evolutionary' behaviour. For example, one can create simulations where higher payoffs are more likely to produce 'offspring' i.e. players that use the same strategy. For example, below is a simulation of strategies playing Rock, Paper Scissors defined by the payoff matrix as above.\\\\\n(\nMy simulation of Rock, Paper, Scissors\n)\\\\\nThe effect is a self-balancing system. If the strategy \\textit{rock} becomes more populous, \\textit{paper} will start to get higher payoffs on average. This in turn brings the population back towards $\\frac{1}{3}$ for each strategy.\\\\\nThe same scenario works with the admitedlly less well-known game Rock, Paper, Scissors, Spock\\cite{for game}\\cite{for code}.\\\\\n(\nMy simulation of Rock, Paper Scissors, Spock\n)\\\\\nHowever, now with the different rules we can have the extinction of strategies.\n\\section{Games on Graphs}\nIn real life, games are usually not isolated situations that happen as if in a laboratory. Instead, we take part in many at the same time with several different players. Sometimes the different games effect each other. To model this, we can use graphs.\n\\subsubsection{Graphs}\nA graph $G=(V,E)$ is a set of vertices $V$ and a set of edges $E$ which are pairs of vertices. For now we will consider only undirected ($(u,v)\\in E\\iff(v,u)\\in E$) graphs with no loops ($\\nexists v\\textnormal{ s.t. } (v,v)\\in E$). A graph looks something like this:\\\\\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{directedGraph.png}\n\t\t\\caption{Directed graph}\n\t\t\\label{fig:dir}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{loopGraph.png}\n\t\t\\caption{Graph with loops}\n\t\t\\label{fig:loop}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{graph.png}\n\t\t\\caption{Undirected graph without loops}\n\t\t\\label{fig:undirected}\n\t\\end{subfigure}\n\t\\caption{We will consider graphs of type \\ref{fig:undirected} and ignore the others}\n\t\\label{fig:complete graphs}\n\\end{figure}\nTwo vertices $u,v$ are \\textit{adjacent} iff $(u,v)\\in E$.\n\\subsubsection{Games on graphs we have already seen}\nWe can now consider games on graphs by allowing each vertex to represent a player and only allowing players to play a game against players they are connected to. In fact, we have sneakily been doing this the whole time but now we want to make this explicit.\\\\\nThe two person one-shot prisoner's dilemma in 1.1.2 was a game on a trivial graph $G=(\\{Lou,Avery\\},\\{(Lou,Avery)\\})$.\\\\\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\\draw\n\t(1,1) node[anchor=east,circle,draw]{Lou}--\n\t(3,1) node[anchor=west,circle,draw]{Avery};\n\t\\end{tikzpicture}\n\t\\caption{The trivial graph underlying the one-shot Prisoner's Dilemma}\n\\end{figure}\nSimilarly, for the tournament if we call the players $p_1,...,p_n$, the tournament was a repeated game on a \\textit{complete graph}. This is the graph with each vertex connected to everyother vertex: $K_n=\\{\\{p_1,...,p_n\\},\\{(p_i,p_j):\\forall i\\neq j\\}\\}$\\\\\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{K5.pdf}\n\t\t\\caption{$K_5$}\n\t\t\\label{fig:K5}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{K16.pdf}\n\t\t\\caption{$K_{16}$}\n\t\t\\label{fig:K16}\n\t\\end{subfigure}\n\t\\caption{The Complete Graphs $K_5$ and $K_{16}$}\n\t\\label{fig:complete graphs}\n\\end{figure}\n\n\\subsubsection{Some new Graphs}\nNow we have made the graphs we are playing games on explicit we can try some new ones.\\\\\nA graph often used in models is the 2D lattice as it is both instructive and relatively easy to analyse.\\cite{eq_of_life}\\\\\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.5\\linewidth]{2d_lattice.pdf}\n\t\\caption{A 2D lattice}\n\\end{figure}\nThe von Neumann neighbourhood of the 2D lattice (Figure \\ref{fig:vonneumann}) makes each point a neighbour of the $4$ points vertically and horizontally next to it.\\\\\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{vonNeumannNeighbourhood.pdf}\n\t\t\\caption{The von Neumann Neighbourhood}\n\t\t\\label{fig:vonneumann}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{mooreNeighbourhood.png}\n\t\t\\caption{The Moore neighbourhood}\n\t\t\\label{fig:moore}\n\t\\end{subfigure}\n\t\\caption{Different neighbourhoods on the 2D Lattice}\n\t\\label{fig: lattice neighbourhoods}\n\\end{figure}\nThe Moore neighbourhood of the 2D lattice (Figure \\ref{fig:vonneumann}) includes the nearest vertical and horizontal neighbours as well as the nearest diagonal points.\\\\\nTo avoid boundary effects when playing games on these lattices (i.e. the side players having fewer opponents), we can 'wrap' the 2D lattice around itself to create a torus. So each neighbour at the top of the lattice is joined to the neighbour in the same column displayed visually at the bottom of the lattice.\n\\subsection{Prisoner's Dilemma on a Torus}\n\\subsubsection{Setup}\nWe can extend the Prisoner's Dilemma to a repeated game on  2D Lattice.\\\\\nInitialisation:\\\\\nMake an $n \\times n$ grid with wrapped ends to avoid boundary effects, creating a torus. Then let each vertex be a player of the Prisoner's Dilemma. In the first round, each player plays $C$ with probability $p$ and $D$ with probability $(1-p)$. They play their strategy simultaneously against every player in their Moore neighbourhood (Figure \\ref{fig:moore}), using the same strategy against each of them.\\\\\nEvery stage after:\\\\\nAfter playing the previous round, each player looks at their neighbours scores. They then adopt the strategy of the highest scoring neighbour as their strategy for the next round. Again they play the same strategy against every player in their neighbourhood.\nThe payoff matrix retains characteristics of the original given Prisoner's Dilemma and is given by:\\\\\n\\setlength{\\extrarowheight}{2pt}\n\\begin{tabular}{cc|c|c|}\n\t& \\multicolumn{1}{c}{} & \\multicolumn{2}{c}{Lou}\\\\\n\t& \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$C$}  & \\multicolumn{1}{c}{$D$} \\\\\\cline{3-4}\n\t\\multirow{2}*{Avery}  & $C$ & $(1,1)$ & $(\\epsilon,b)$ \\\\\\cline{3-4}\n\t& $D$ & $(b,\\epsilon)$ & $(0,0)$ \\\\\\cline{3-4}\n\\end{tabular}\n\\\\\n\\\\\nwhere $\\epsilon<1<b$.\n\\\\\n\n\\subsubsection{Example Runs}\nIn this section we use values of a $100\\times100$ grid, $p=0.5$ and $\\epsilon=0$. We can create a wide variety of dynamic behaviour, including chaos and bifurcations by adjusting the value of $b$.\n\\subsubsection{Qualitative Analysis}\nFor $b>1.\\bar{6}$, the board eventually tends to an equilibrium with mostly defectors. Clearly the rewards of non-cooperation are too high to a sustain a more socially optimal situation.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/1b=17.png}\n\t\t\\caption{Early}\n\t\t\\label{fig:dir}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/2b=17.png}\n\t\t\\caption{Developing}\n\t\t\\label{fig:loop}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/3b=17.png}\n\t\t\\caption{Equilibrium}\n\t\t\\label{fig:undirected}\n\t\\end{subfigure}\n\t\\caption{The simulation running with $b=1.7$}\n\t\\label{fig:complete graphs}\n\\end{figure}\nSimilarly, for $b<1.6$, the simulation tends towards a static equilibrium of mainly cooperators.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/1b=15.png}\n\t\t\\caption{Early}\n\t\t\\label{fig:dir}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/2b=15.png}\n\t\t\\caption{Developing}\n\t\t\\label{fig:loop}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/3b=15.png}\n\t\t\\caption{Equilibrium}\n\t\t\\label{fig:undirected}\n\t\\end{subfigure}\n\t\\caption{The simulation running with $b=1.5$}\n\t\\label{fig:complete graphs}\n\\end{figure}\nBetween these two parameter regions, exists the third which exhibits the most interesting behaviour with dynamics between cooperation and defection.\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/1b=163.png}\n\t\t\\caption{Early}\n\t\t\\label{fig:dir}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/2b=163.png}\n\t\t\\caption{Developing}\n\t\t\\label{fig:loop}\n\t\\end{subfigure}\n\t\\begin{subfigure}{.3\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.9\\linewidth]{/mooreLattice/3b=163.png}\n\t\t\\caption{Dynamic equilibrium}\n\t\t\\label{fig:undirected}\n\t\\end{subfigure}\n\t\\caption{The simulation running with $b=1.63$}\n\t\\label{fig:complete graphs}\n\\end{figure}\n\\subsubsection{Quantative Analysis}\nlooking at individual squares\n%\\subsubsection{Prisoner's Dilemma on a Scale Free Graph}\n\n\n", "meta": {"hexsha": "8a7facc091a3f1ee56bef2d295c2dddb8ef45443", "size": 16524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/TeX_files/Old/chapter01.tex", "max_stars_repo_name": "joekroese/math-of-revolution", "max_stars_repo_head_hexsha": "c831ea3d5f6c56c3861522f71ec47e1a22f9ff2c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-07T18:16:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-16T10:54:20.000Z", "max_issues_repo_path": "Writing/TeX_files/Old/chapter01.tex", "max_issues_repo_name": "joekroese/math-of-revolution", "max_issues_repo_head_hexsha": "c831ea3d5f6c56c3861522f71ec47e1a22f9ff2c", "max_issues_repo_licenses": ["MIT"], "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/TeX_files/Old/chapter01.tex", "max_forks_repo_name": "joekroese/math-of-revolution", "max_forks_repo_head_hexsha": "c831ea3d5f6c56c3861522f71ec47e1a22f9ff2c", "max_forks_repo_licenses": ["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.5909090909, "max_line_length": 722, "alphanum_fraction": 0.7529653837, "num_tokens": 4697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6264698506133428}}
{"text": "\\section{On-policy Prediction with Approximation}\n\n\\subsection{Exercise 9.1}\n\\subsubsection*{Q}\nShow that tabular methods such as presented in Part I of this book are a special case of linear function approximation. What would the feature vectors be?\n\\subsubsection*{A}\nWrite $\\hat{V}(s, \\vec{w}) = w$ and we get that $\\grad_{\\vec{w}} \\hat{V}(s, \\vec{w}) = 1$ so we return to tabular TD learning. In this case the features are $x(s) = 1$ $\\forall s \\in \\mathcal{S}$.\n\n\\subsection{Exercise 9.2}\n\\subsubsection*{Q}\nWhy does (9.17) define $(n+1)^k$ distinct features for dimension $k$?\n\\subsubsection*{A}\nEach of the $k$ terms can independently have one of $n+1$ exponents, hence the total number of features is $(n+1)^k$.\n\n\\subsection{Exercise 9.3}\n\\subsubsection*{Q}\nWhat $n$ and $c_{i,j}$ produce the feature vectors $\\vec{x}(s) = (1, s_1, s_2, s_1s_2, s_1^2, s_2^2, s_1s_2^2, s_1^2 s_2, s_1^2 s_2^2)$?\n\\subsubsection*{A}\n$n=2$ and $c_i, j = C_{ij}$ where\n\\[\nC =\n\\begin{pmatrix}\n    0 & 0 \\\\\n    1 & 0 \\\\\n    0 & 1 \\\\\n    1 & 1 \\\\\n    2 & 0 \\\\\n    0 & 2 \\\\\n    1 & 2 \\\\\n    2 & 1 \\\\\n    2 & 2\n\\end{pmatrix}\n\\]\n\n\\subsection{Exercise 9.4}\n\\subsubsection*{Q}\nSuppose we believe that one of two state dimensions is more likely to have an effect on the value function than is the other, that generalization should be primarily across this dimension rather than along it. What kind of tilings could be used to take advantage of this prior knowledge?\n\\subsubsection*{A}\nTiles that are thin along the dimension of interest and long across it. Rectangles, for instance.\n\n\\subsection{Exercise 9.5}\n\\subsubsection*{Q}\nSuppose you are using tile coding to transform a seven-dimensional continuous state space into binary feature vectors to estimate a state value function $\\hat{v}(s, \\vec{w}) \\approx v_\\pi(s)$. You believe that the dimensions do not interact strongly, so you decide to use eight tilings of each dimension separately (stripe tilings), for $7 \\times 8 = 56$ tilings. In addition, in case there are some pairwise interactions between the dimensions, you also take all $\\binom{7}{2} = 21$ pairs of dimensions and tile each pair conjunctively with rectangular tiles. You make two tilings for each pair of dimensions, making a grand total of $21 \\times 2 + 56 = 98$ tilings. Given these feature vectors, you suspect that you still have to average out some noise, so you decide that you want learning to be gradual, taking about 10 presentations with the same feature vector before learning nears its asymptote. What step-size parameter $\\alpha$ should you use? Why?\n\n\\subsubsection*{A}\nEach tiling is a partition, so each tiling has exactly one tile activated per state. This means that in our case the number of features is 98. We consider each of these equally likely because we are uninformed. We therefore take\n\\[\n\\alpha = \\frac{1}{10 \\times 98} = \\frac{1}{980}.\n\\]\nSo that on average we see each feature 10 times before asymptote. [Note that this assumes a constant target.]\n", "meta": {"hexsha": "e1f106e24ac92517ce582e891818b31e8f22524b", "size": 2980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/chapters/chapter9/chapter9_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/chapter9/chapter9_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/chapter9/chapter9_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": 58.431372549, "max_line_length": 958, "alphanum_fraction": 0.7265100671, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145405, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6262177891817513}}
{"text": "\\hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}{}\\section{numpp\\+:\\+:differentiation\\+:\\+:symbolic\\+:\\+:sinus$<$ T $>$ Class Template Reference}\n\\label{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}\\index{numpp\\+::differentiation\\+::symbolic\\+::sinus$<$ T $>$@{numpp\\+::differentiation\\+::symbolic\\+::sinus$<$ T $>$}}\n\\subsection*{Public Types}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1sinus_a5bde5934631bcfb972ad6c15c81ccca5}\\label{classnumpp_1_1differentiation_1_1symbolic_1_1sinus_a5bde5934631bcfb972ad6c15c81ccca5}} \n{\\footnotesize template$<$std\\+::size\\+\\_\\+t Active$>$ }\\\\using {\\bfseries derivative} = simplify\\+\\_\\+multiplication$<$ \\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1cosinus}{cosinus}$<$ T $>$, typename T\\+::template derivative$<$ Active $>$ $>$\n\\end{DoxyCompactItemize}\n\\subsection*{Static Public Member Functions}\n\\begin{DoxyCompactItemize}\n\\item \n\\mbox{\\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1sinus_a25872983c585075c533169136769caa7}\\label{classnumpp_1_1differentiation_1_1symbolic_1_1sinus_a25872983c585075c533169136769caa7}} \nstatic C\\+O\\+N\\+S\\+T\\+E\\+X\\+PR auto {\\bfseries calculate} (auto \\&\\&values)\n\\end{DoxyCompactItemize}\n\n\nThe documentation for this class was generated from the following file\\+:\\begin{DoxyCompactItemize}\n\\item \ndifferentiation/symbolic/trigonometric.\\+hpp\\end{DoxyCompactItemize}\n", "meta": {"hexsha": "ab33503349dc8351690d6475f4509af8c564faa2", "size": 1439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/classnumpp_1_1differentiation_1_1symbolic_1_1sinus.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/classnumpp_1_1differentiation_1_1symbolic_1_1sinus.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/classnumpp_1_1differentiation_1_1symbolic_1_1sinus.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": 71.95, "max_line_length": 256, "alphanum_fraction": 0.8047255038, "num_tokens": 538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998663336157, "lm_q2_score": 0.8056321796478256, "lm_q1q2_score": 0.6262177855543143}}
{"text": "%%=========================================================================\n%% Section 3.4: Boundedness of the Exponentially Weighted Hilbert Transform\n%%=========================================================================\n\n\\documentclass[../dissertation.tex]{subfiles}\n\n\\begin{document}\n\\section{Boundedness of the Exponentially Weighted Hilbert Transform}\\label{sec3:BndE}\n\nProving that the exponentially weighted Hilbert transform $E$ is bounded on \n$L^p(\\mathbb R)$ for $1< p < \\infty$ is a multistep process in which we first compute\nthe Fourier multiplier of $E$ (Lemma \\ref{lma:FMultE}), use the Fourier multiplier\nof $E$ to show that $E$ is strong type $(2,2)$ (Theorem \\ref{thm:Estrong}), prove $E$ is \nweak type $(1, 1)$ (Theorem \\ref{thm:Eweak}), and then use these results to ultimately\nprove $E$ is strong type $(p, p)$ for $p>1$ (Theorem \\ref{thm:EbndOp}). Note that an \noperator is said to be weak type $(p,q)$ if it is a bounded operator from $L^p$ to \n$weak$-$L^q$ (\\textit{i.e.} $L^{q, \\infty}$) and strong type $(p,q)$ if it \nis a bounded operator from $L^p$ to $L^q$. For a defintion of the space\n$L^{p,\\infty}$, please see the \\hyperref[app:HA]{``Harmonic Analysis Results''} \nappendix.\n\n\n\\begin{lma}\\label{lma:FMultE}\n\tThe Exponentially weighted Hilbert transform $E$ has Fourier multiplier\n\t$$m_E(\\xi) = \\frac{1}{\\pi} \\arctan(\\xi/\\pi).$$\\label{sym3:Emult}\n\\end{lma}\n\\begin{proof}\n\tIn order to compute the Fourier multiplier of $E$, it suffices to compute the Fourier\n\ttransform of the function $x^{-1} e^{-\\pi|x|}$, which is $2\\pi i$ times the \n\tconvolution kernel of $E$. Letting $\\theta$ denote the Heaviside function, we \n\twrite $x^{-1} e^{-\\pi|x|}$ as \n\t\\begin{align}\\label{eq:Ekern}\n\t\t\\frac{e^{\\pi |x|}}{x} \n\t\t\t=\n\t\t\t\\frac{e^{\\pi \\, x}}{x} \\theta(-x) + \\frac{e^{-\\pi \\, x}}{x} \\theta(x),\n\t\\end{align}\n\tand compute the Fourier transform of two terms on the right-hand side of \n\t\\eqref{eq:Ekern} separately. By further splitting $\\frac{e^{\\pi \\, x}}{x} \\theta(-x)$\n\tinto even and odd parts, we obtain\n\t\\begin{align}\n\t\t\\mc F\\left( \\frac{e^{\\pi (\\dotarg)}}{(\\dotarg)} \\theta(-\\dotarg) \\right)\n\t\t\t&= \\mc F^{(c)} \\left( \n\t\t\t\t\t\\frac{e^{\\pi (\\dotarg)}\\theta(-\\dotarg)-e^{-\\pi(\\dotarg)}\\theta(\\dotarg)}\n\t\t\t\t\t\t{2(\\dotarg)}  \n\t\t\t\t\\right)(\\xi)\n\t\t\t\t\\\\\n\t\t\t&\\quad + i \\, \\mc F^{(s)} \\left(\n\t\t\t\t\t\\frac{e^{\\pi(\\dotarg)}\\theta(-\\dotarg)+e^{-\\pi(\\dotarg)}\\theta(\\dotarg)}\n\t\t\t\t\t\t{2(\\dotarg)} \n\t\t\t\t\\right)(\\xi),\n\t\t\t\t\\nonumber\n\t\\end{align}\n\twhere $\\mc F^{(c)}$ and $\\mc F^{(s)}$ respectively denote the Fourier cosine and\n\tFourier sine transformations. Direct computation yields \n\t\\begin{align*}\n\t\t\\mc F^{(c)} \\left( \n\t\t\t\\frac{e^{\\pi (\\dotarg)}\\theta(-\\dotarg)-e^{-\\pi(\\dotarg)}\\theta(\\dotarg)}\n\t\t\t\t{2(\\dotarg)}  \n\t\t\\right)(\\xi)\n\t\t\t&= \\frac{1}{\\pi}\n\t\t\t\t\\int_0^\\infty \n\t\t\t\t\t\\frac{e^{\\pi \\,x}\\theta(-x)-e^{-\\pi\\,x}\\theta(x)}{2x}\n\t\t\t\t\\, \\cos(\\xi x) \\, \\mathrm{d}x \n\t\t\t\t\\\\\n\t\t\t&= \\frac{1}{2} \\big(\n\t\t\t\t\t\\log(\\xi^2 + \\pi^2) + 2 \\gamma\n\t\t\t\t\\big)\n\t\t\t\t\\nonumber\n\t\\end{align*}\n\tand \n\t\\begin{align*}\n\t\t\\mc F^{(s)} \\left( \n\t\t\t\\frac{e^{\\pi (\\dotarg)}\\theta(-\\dotarg)+e^{-\\pi(\\dotarg)}\\theta(\\dotarg)}\n\t\t\t\t{2(\\dotarg)}  \n\t\t\\right)(\\xi)\n\t\t\t&= \\frac{1}{2\\pi} \n\t\t\t\t\\int_0^\\infty \n\t\t\t\t\t\\frac{e^{\\pi \\,x}\\theta(-x)+e^{-\\pi\\,x}\\theta(x)}{2x}\n\t\t\t\t\\, \\sin(\\xi x) \\, \\mathrm{d}x \n\t\t\t\t\\\\\n\t\t\t&= \\frac{1}{2} \\big(\n\t\t\t\t\t\\arctan(\\xi/\\pi)\n\t\t\t\t\\big),\n\t\t\t\t\\nonumber\n\t\\end{align*}\n\twhere $\\gamma$ denotes the Euler-Mascheroni constant, which implies\n\t\\begin{align}\n\t\t\\mc F \\left( \n\t\t\t \\frac{e^{\\pi (\\dotarg)}}{(\\dotarg)} \\theta(-\\dotarg)\n\t\t\\right)(\\xi)\n\t\t\t&=\n\t\t\t\t\\gamma\n\t\t\t\t+ \\frac{1}{2} \\log(\\xi^2 + \\pi^2) \n\t\t\t\t+ i \\, \\arctan(\\xi/\\pi).\n\t\\end{align}\n\tA similar computation also shows \n\t\\begin{align}\n\t\t\\mc F \\left( \n\t\t\t \\frac{e^{-\\pi (\\dotarg)}}{(\\dotarg)} \\theta(\\dotarg)\n\t\t\\right)(\\xi)\n\t\t\t&= \n\t\t\t\t- \\gamma\n\t\t\t\t- \\frac{1}{2} \\log(\\xi^2 + \\pi^2) \n\t\t\t\t+ i \\, \\arctan(\\xi/\\pi),\n\t\\end{align}\n\tfrom which the result follows.\n\\end{proof}\n\n\\begin{thm}\\label{thm:Estrong}\n\t$E$ is strong type $(2, 2)$.\n\\end{thm}\n\\begin{proof}\n\tThis result is an immediate consequence of Lemma \\ref{lma:FMultE}, \n\tPlancherel's Theorem, and the density of $\\mathscr S(\\mathbb R)$ \n\tin $L^2(\\mathbb R)$.\n\\end{proof}\n\n\n\\begin{thm}\\label{thm:Eweak}\n\t$E$ is weak type $(1, 1)$. That is, $E$ is a bounded operator from \n    $L^1(\\mathbb R)$ into\n    $L^{1, \\infty}(\\mathbb R)$, where  $L^{1, \\infty}$ denotes weak $L^1$.\n    \\label{sym3:weakLp}\n\\end{thm}\n\\begin{proof}\n    Fix $\\Lambda > 0$, let $f$ be Schwartz class, and assume without loss of \n    generality that $f \\in \\mathscr S(\\mathbb R)$ is real-valued and nonnegative \n    (otherwise, we can decompose $f$ in the appropriate pieces).\n    Let $\\{ I_j \\}$ be the sequence sequence of dyadic intervals in the \n    Calder\\'on-Zygmund decomposition of \n    $f$ at height $\\Lambda$. For $\\Omega := \\bigcup_j I_j$, define \n    \\begin{align}\\label{eq:C-Zdecomp}\n        g(x) :=  \n            \\begin{cases}\n                \\displaystyle f(x), & x \\notin \\Omega \\\\[0.5\\baselineskip]\n                \\displaystyle \\frac{1}{|I_j|} \\int_{I_j} f, & x \\in I_j\n            \\end{cases},\n        \\qquad \\text{and} \\qquad\n        b(x) := \\sum_j b_j(x),\n    \\end{align}\n    where \n    \\[\n        b_j(x) = \\left( f(x) - \\dfrac{1}{|I_j|} \\int_{I_j} f \\right) \\chi_{I_j}(x).\n    \\]\n    Note that $f = g+b$ and\n    \\begin{align} \\label{eq:GoodPartBnd}\n        g(x) \\leq 2 \\Lambda \\quad \\forall x \\in \\mathbb R.\n    \\end{align}\n    To show that $Eg$ and $Eb$ are well defined, it suffices\n    to bound $d_{Eg}(\\Lambda)$ and $d_{Eb}(\\Lambda)$ in terms of only $\\Lambda$ and \n    $\\|f\\|_1$, where\n    the notation \n    \\[\n        d_h (\\Lambda) := \\big| \\big\\{ x \\in \\mathbb R \\, : \\, |f(x)| > \\Lambda \\big\\} \\big|\n    \\]\n    is used to denote the \\textit{distributional function} of a function $h$. Using\n    Chebyshev's inequality, the $L^2$  boundedness of $E$ found in Theorem \\ref{thm:Eweak}\n    and equations \\eqref{eq:GoodPartBnd} and \\eqref{eq:C-Zdecomp}, we find\n    \\begin{align}\\label{eq:dEgBound}\n        d_{Eg}(\\Lambda)\n            &\\leq \\frac{1}{\\Lambda^2} \\int_{\\mathbb R} E g(x)^2 \\, \\mathrm{d}x \\\\\n            &\\leq \\frac{C}{\\Lambda^2} \\int_{\\mathbb R} g(x)^2 \\, \\mathrm{d}x \\nonumber\\\\\n            &\\leq \\frac{C}{\\Lambda^2} \\int_{\\mathbb R} g(x) \\, \\mathrm{d}x \\nonumber\\\\\n            &= \\frac{C}{\\Lambda^2} \\left( \\int_{\\Omega} g \n                + \\int_{\\mathbb{R} \\backslash \\Omega} g  \\right) \\nonumber\\\\\n            &\\leq \\frac{C}{\\Lambda} \\| f \\|_1.  \\nonumber\n    \\end{align}\n\n\n    On the other hand, for $Eb$, let $\\Omega^* = \\bigcup_j 2 I_j$. Using the \n    Calder\\'on-Zygmund Covering Lemma and Chebyshev's inequality we find\n    \\begin{align} \\label{eq:dEb}\n        d_{Eb}(\\Lambda) \n            \\leq |\\Omega^*| + |\\{ x \\notin \\Omega^* \\, : \\, |Eb(x)| > \\Lambda \\}|\n            \\leq \\frac{2}{\\Lambda} \\|f\\|_1 + \\frac{1}{\\Lambda} \n                \\int_{\\mathbb R \\backslash \\Omega^*} |Eb(x)| \\, \\mathrm{d}x.\n    \\end{align}\n    So, to show that $Eb$ is well defined, we need to bound the integral on the \n    right hand side of the above inequality by $\\|f\\|_1$. To that end, note that\n    if $x \\notin \\Omega^*$, then for each $j$, $x \\notin 2 I_j$ and\n    \\begin{align*}\n        E b_j(x) \n            = \\frac{1}{2\\pi} \n            \tp.v. \\int_{\\mathbb R} \n            \t\t\\frac{e^{-\\pi|x - x'|}}{x - x'} b_j(x') \n            \t\\, \\mathrm{d}x'\n            = \\frac{1}{2\\pi} \n            \t\\int_{I_j} \n            \t\t\\frac{e^{-\\pi|x - x'|}}{x - x'} b_j(x') \n            \t\\, \\mathrm{d}x \n            < \\infty,\n    \\end{align*}\n    as $\\text{supp} \\, b_j \\subseteq I_j$. Since $E$ is a tempered distribution\n    (Lemma \\ref{lma:FMultE}) and\n    $f \\in \\mathscr S(\\mathbb R)$ means that $Ef \\in L^2(\\mathbb R)$ and, hence\n    $\\sum_j E b_j$ converges to $Eb$ in the $L^2$ norm, it follows that\n    \\[\n        |Eb(x)| \\leq \\sum_j |Eb_j(x)| \\quad a.e.\n    \\]\n    As such, proving $Eb$ is well defined reduces to showing\n    \\begin{align}\n        \\int_{\\mathbb R \\backslash \\Omega^*} \\sum_{j} |E b_j(x)| \\, \\mathrm{d}x \n            \\leq C \\| f \\|_1.\n    \\end{align}\n\n    If we let $c_j$ denote the center of $I_j$, then, for $x \\notin \\Omega^*$, \n    since $b_j$ has zero average\n    \\begin{align*}\n        \\left|\\int_{I_j} \\frac{e^{-\\pi|x - x'|}}{x - x'} b_j(x') \\, \\mathrm{d}x'\\right|\n            &= \\left|\\int_{I_j} e^{-\\pi|x - x'|}\n                \\left(\\frac{b_j(x')}{x - x'} - \\frac{b_j(x')}{x - c_j}  \\right)\\, \\mathrm{d}x'\\right| \\\\\n            &\\leq \\int_{I_j} e^{-\\pi|x - x'|}\n                \\left|\\frac{b_j(x')(x' - c_j)}{(x - x')(x-c_j)}\\right| \\, \\mathrm{d}x' \\\\\n            &\\leq \\int_{I_j} |b_j(x')| \\frac{|I_j|}{(x - c_j)^2} \\, \\mathrm{d}x'\n    \\end{align*}\n    as $|x - x'| \\geq |x - c_j|/2$ and $|x' - c_j| \\leq |I_j|/2$. Moreover, \n    \\begin{align} \\label{eq:IjIntBnd}\n        \\int_{\\mathbb R \\backslash \\Omega^*} \\frac{|I_j|}{(x - c_j)^2} \\, \\mathrm{d}x'\n            \\leq \\int_{\\mathbb R \\backslash I_j} \\frac{|I_j|}{(x - c_j)^2} \\, \\mathrm{d}x'\n            \\leq 4,\n    \\end{align}\n    and so, by Fubini's Theorem,\n    \\begin{align} \\label{eq:sumEbj}\n        \\sum_j \\int_{\\mathbb R \\backslash \\Omega^*} \\left| E b_j(x) \\right| \\, \\mathrm{d}x\n            &\\leq \\frac{1}{2\\pi} \\sum_j\\int_{\\mathbb R \\backslash \\Omega^*} \n                \\left| \\int_{I_j} e^{-\\pi|x-x'|} \\frac{b_j(x')}{x - x'} \\, \\mathrm{d}x' \\right| \\, \\mathrm{d}x \n                \\\\\n            &\\leq \\frac{1}{2\\pi} \\sum_j \\int_{\\mathbb R \\backslash \\Omega^*}  \\int_{I_j}\n                |b_j(x')| \\frac{|I_j|}{(x - c_j)^2} \\, \\mathrm{d}x' \\, \\mathrm{d}x \n                \\nonumber \\\\\n            &\\leq \\frac{2}{\\pi} \\sum_j \\int_{I_j} |b_j(x')| \\, \\mathrm{d}x' \n                \\nonumber \\\\\n            &\\leq \\frac{4}{\\pi} \\| f\\|_1. \\nonumber\n    \\end{align}\n    Putting everything together, we find\n    \\begin{align} \\label{eq:E11bnd}\n        d_{Ef}(\\Lambda) \n            \\leq d_{Eg}\\left(\\frac{\\Lambda}{2}\\right) + d_{Eb}\\left(\\frac{\\Lambda}{2}\\right)\n            \\leq \\frac{C}{\\Lambda} \\| f\\|_1,\n    \\end{align}\n    where $C>0$ is independent of $\\Lambda$ and $f$. Since $f$ is Schwartz class, we can \n    therefore extend the inequality \\eqref{eq:E11bnd} to $L^1$ \\textit{via} density to\n    conclude that $E$ is weak (1,1).\n\\end{proof}\n\n\n\\begin{thm}\\label{thm:EbndOp}\n\tThe operator $E$ is strong type $(p, p)$ for $p>1$.\n\\end{thm}\n\\begin{proof}\n\tTheorems \\ref{thm:Estrong} and \\ref{thm:Eweak} in conjunction with the \n\tMarcinkiewicz Interpolation Theorem \\cite[Theorem 1.3.2]{Grafakos} immediately imply that $E$ is strong\n\ttype $(p,p)$ for $p\\in (1, 2]$. As such, it remains only to show that\n\t$E$ is strong type $(p, p)$ for $p > 2$. \n\n    Let $E'$ denote the adjoint of $E$. By density, we need only consider \n    $f \\in \\mathscr S(\\mathbb R)$. Fix $p >2$ and let $q$ \n    denote its H\\\"older Conjugate. Note that the map\n    \\[\n        g \\mapsto \\int_{\\mathbb R} E f \\bar{g} =: \\left\\langle Ef, g \\right\\rangle \n    \\]\n    is a linear functional on $L^q$ with norm $\\| E f \\|_p$. As such, \n    we see by H\\\"older's inequality that\n    \\begin{align*}\n        \\| E f \\|_p\n            &= \\sup_{\\|g\\|_q = 1} |\\langle Ef, g \\rangle| \\\\\n            &= \\sup_{\\|g\\|_q = 1} |\\langle f, E'g \\rangle| \\\\\n            &\\leq  \\|f\\|_p \\|E\\|_q \\\\\n            &\\leq  C \\|f\\|_p,\n    \\end{align*}\n    as $p>2$ implies $1 < q < 2$, which means $E$ is strong type $(q, q)$, \n    and Theorem 5 from Chapter VII.3 of \\cite{yosida} implies \n    $\\|E\\|_q = \\|E'\\|_q$.\n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "a9412e6f7fbbedd29dd0511707594e350b3fa45c", "size": 11462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter3-xContin/3.4-BndnessETransform.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": "Chapter3-xContin/3.4-BndnessETransform.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": "Chapter3-xContin/3.4-BndnessETransform.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": 41.5289855072, "max_line_length": 111, "alphanum_fraction": 0.5471121968, "num_tokens": 4404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6262177813981187}}
{"text": "%---------------------------Shear and Size-----------------------------\n\\section{Shear and Size\\label{s:quad-shear-and-size}}\n\nLet $R$ be the relative size squared as defined in \\S\\ref{s:quad-rel-size-squared}\nand $H$ be the shear as defined in \\S\\ref{s:quad-shear}.\nThe shear and size metric is the product of these two numbers:\n\\[\nq = RH\n\\]\n\n\\quadmetrictable{shear and size}%\n{$1$}%                                      Dimension\n{$[0.2,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\\_shear\\_and\\_size}%                Verdict function name\n\n", "meta": {"hexsha": "fb53233a9085241cbb73bd773384b89642ed9718", "size": 781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadShearAndSize.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/QuadShearAndSize.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/QuadShearAndSize.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.05, "max_line_length": 82, "alphanum_fraction": 0.4775928297, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6261757230836132}}
{"text": "\\sec{Cauchy Euler equations}\n\\subsection{The first challenge} \\label{ssec:cauchyeulerhomo}\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tAn ODE of the form\n\t\\begin{equation*} \n\t\tx^ny^{(n)} + a_{n-1}x^{n-1}y^{(n-1)} + \\cdots + a_{1}xy' + a_0y = 0\n\t\\end{equation*}\n\tis called a \\defin{Cauchy Euler equation}. (Each $a_i$ is a constant.)\n\\end{mdframed}\nWe shall be interested in solving the above equation only on $(0, \\infty).$\n\\begin{mdframed}[style=boxstyle, frametitle={The Solution}]\n\tWe plug the trial solution $y = x^m.$ This gives us the polynomial equation:\n\t\\begin{align} \n\t\tm(m - 1)\\cdots(m-(n-1)) + a_{n-1}m(m-1)\\cdots(m-(n-2)) + \\nonumber \\\\\n\t\t \\cdots + a_1m + a_0 = 0. \\label{eq:indic}\n\t\\end{align}\n\tNote that if $m$ is a root of the above, then $x^m$ is a solution of the ODE.\\\\\n\tThus, if the above equation has $n$ distinct roots $m_1, \\ldots, m_n,$ then the original ODE has $n$ linearly independent solutions $x^{m_1}, \\ldots, x^{m_n}$ and we are done.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Repeated roots}]\n\tSuppose $m_0$ is a repeated root of (\\ref{eq:indic}). Suppose that it is repeated $k$ times. Then, one can show that the following $k$ functions are solutions of the original ODE:\n\t\\begin{equation*} \n\t\tx^{m_0}, x^{m_0}\\ln x, \\ldots, x^{m_0}(\\ln x)^{k-1}.\n\t\\end{equation*}\n\tThese are linearly independent as well.\\\\\n\tThus, we are now done for any case as the total number of roots is always going to be $n$ when counted with multiplicity. (This is assuming that we work in $\\mathbb{C},$ which we shall do.)\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Getting real}]\n\tSuppose $m = a+ib$ is a root. Then, we have\n\t\\begin{align*} \n\t\tx^m &:= \\exp(m \\ln x) & (\\text{By definition})\\\\\n\t\t&= \\exp(a \\ln x + ib\\ln x)\\\\\n\t\t&= \\exp(a \\ln x)\\cdot\\exp(ib \\ln x)\\\\\n\t\t&= \\exp(a \\ln x)\\cdot\\big(\\cos(b\\ln x) + i\\sin(b \\ln x)\\big)\\\\\n\t\t&=x^a(\\cos(b\\ln x) + i\\sin(b \\ln x))\n\t\\end{align*}\n\tAs before, if each $a_i$ is real, then the roots appear in the same multiplicity as their conjugates which will give us the real pair of solutions as:\n\t\\begin{equation*} \n\t\tx^a\\cos(b\\ln x), x^a\\sin(b\\ln x).\n\t\\end{equation*}\n\tIn case of repetition twice, we get the four solutions:\n\t\\begin{equation*} \n\t\tx^a\\cos(b\\ln x), x^a\\sin(b\\ln x),\\quad x^a(\\ln x)\\cos(b\\ln x), x^a(\\ln x)\\sin(b\\ln x).\n\t\\end{equation*}\n\tThe general case is (hopefully) clear.\n\\end{mdframed}\n\\subsection{Welcome back, annihilators}\nThis time, we consider annihilators of polynomial (polylogmial?) functions.\\\\\nAs before, we shall see that it suffices to consider the case of just the monomials first. The annihilator table is particularly simple this time:\n\\begin{mdframed}[style=boxstyle, frametitle={Annihilators of special functions}]\n\t\\begin{center}\n\t\\bgroup\n\t\\def\\arraystretch{1.25}\n\t\\begin{tabular}{|l|l|}\n\t\t\\hline\n\t\tFunction & Annihilator\\\\\n\t\t\\hline\n\t\t$x^n$ & $xD - n$\\\\\n\t\t$x^n(\\ln x)^k$ & $(xD - n)^{k+1}$\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\egroup\n\t\\end{center}\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={A word on $xD$}]\n\tNote that $xD$ is the operator which acts on a function as:\n\t\\begin{equation*} \n\t\t(xD)(f) = xf'.\n\t\\end{equation*}\n\tOn the other hand, $Dx$ is an operator which acts as:\n\t\\begin{equation*} \n\t\t(Dx)(f) = D(xf) = xf' + f.\n\t\\end{equation*}\n\tIn particular, $xD \\neq Dx.$ This means that $(xD)^2 \\neq x^2D^2$ and so on.\n\\end{mdframed}\n\\emph{Note:} $xD$ is an operator but there is no $xP$ operator. \\hfill (A joke.)\n\\begin{mdframed}[style=boxstyle, frametitle={Some arithmetic}]\n\tFor ease of calculations, one may note the following useful identities:\n\t\\begin{align*} \n\t\tx^2D^2 &= xD(xD - 1)\\\\\n\t\tx^3D^3 &= xD(xD - 1)(xD - 2)\\\\\n\t\t&\\vdots\n\t\\end{align*}\n\\end{mdframed}\n\\subsection{The main problem}\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tWe consider a linear ODE of the form\n\t\\begin{equation} \n\t\tx^ny^{(n)} + a_{n-1}x^{n-1}y^{(n-1)} + \\cdots + a_{1}xy' + a_0y = Q(x),\n\t\\end{equation}\n\twhere each $a_i$ is a constant and $Q(x)$ is a linear combination of functions of the form $x^k(\\ln x)^m$.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={The Solution}]\n\tThe steps are now identical as the case of \\nameref{sec:undcoeff}.\\\\\n\tWe shall assume that $Q(x) = x^k(\\ln x)^m$ and not a linear combination. The general case follows as before by considering the linear combination of solutions.\n\t\\begin{enumerate}[leftmargin=*, label = \\Roman*.]\n\t\t\\item We first consider the equation\n\t\t\\begin{equation*} \n\t\t\tx^ny^{(n)} + a_{n-1}x^{n-1}y^{(n-1)} + \\cdots + a_{1}xy' + a_0y = 0.\n\t\t\\end{equation*}\n\t\tThis can be solved by the method we saw in \\S\\S\\ref{ssec:cauchyeulerhomo}.\n\t\t\\item We then apply the annihilator of $Q(x)$ from the table earlier.\\\\\n\t\t\\textbf{\\emph{This again gives us a Cauchy Euler equation.}}\\\\\n\t\tWe solve this again using the method of \\S\\S\\ref{ssec:cauchyeulerhomo}.\n\t\t\\item We follow the step III as in the case of \\nameref{sec:undcoeff} to determine the coefficients of the new functions we obtain in Step II.\n\t\\end{enumerate}\n\\end{mdframed}\nNote that $D^{11}$ is also an annihilator of $x^{10},$ however we do not use that.\\\\\nThe first reason is that the calculations would be a nightmare.\\\\\nSecondly, applying this annihilator to both sides of the equation wouldn't technically give us a Cauchy Euler equation again. \\\\\nAlso, note that the method we have used doesn't require $k$ to be an integer. This would work even if we wish to solve something like $xy'' + y = x^{1/2}.$ Another reason to prefer the annihilator $xD - 1/2.$", "meta": {"hexsha": "49e497ae6a66d6b29f2c8e469045233f8c11e357", "size": 5516, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/cauchyeuler.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/cauchyeuler.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/cauchyeuler.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": 49.6936936937, "max_line_length": 208, "alphanum_fraction": 0.6829224075, "num_tokens": 1987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.705785040214066, "lm_q2_score": 0.8872045832787205, "lm_q1q2_score": 0.6261757224874754}}
{"text": "\\section{Deep Learning} \\label{sec:bt/DNN}\n\nDeep learning is a powerful extension of the simple learning algorithms detailed above. In theory, any problem which can be modeled as the mapping of an input vector to an output vector can be solved by deep learning \\cite{goodfellow2016}. In other words, any function of any complexity can be approximated given sufficiently large models and sufficiently large labeled training examples. \n\n\\subsection{Deep Feedforward Neural Networks}\n\nFeedforward neural networks constitute a branch of deep learning covering models with a one-directional data flow from input to output. They are called \\textit{neural networks} because they are loosely inspired by the neural circuitry of the human brain. Extending this analogy, all human perception may be considered one vast deep feedforward neural network. It works by mapping sensory input from sight, touch, smell, taste, and hearing through countless layers of neurons to output what we perceive of the world. Artificial neural networks work similarly by mapping a vector of input data points to one or more output values.\n\nEven in their simplest form, deep feedforward neural networks overcome many challenges that linear models face. Linear regression, for instance, may never accurately approximate a non-linear function or capture interactions between two or more input variables. This limitation may only be overcome by introducing a nonlinearity to the input $\\bm{x}$. We encapsulate this nonlinearity as $\\phi(\\bm{x})$. Thus, the equivalent to equation \\ref{eq:bt_linReg} becomes equation \\ref{eq:bt/dnn/dfnn}.\n\n\\begin{equation}\n    \\label{eq:bt/dnn/dfnn}\n    y=f(\\bm{x};\\bm{\\theta},\\bm{x})=\\phi(\\bm{x};\\bm{\\theta})^T\\bm{w}\n\\end{equation}\n\nWe now have another set of trainable parameters $\\bm{\\theta}$, meaning that the final form of $\\phi$ is yet to be determined. By allowing the model to experience a given set of labeled training data, $\\bm{\\theta}$ will gradually converge towards a value that enables the full model to approximate the data optimally.\n% be trained from experiencing a given set of labeled training data. \nThe parameters defined by $\\bm{w}$ may subsequently map from $\\phi(\\bm{x})$ to the desired output. $\\phi$ is called a \\textit{hidden layer} because its outputs are unrelated to either the input or output vectors. It can instead be thought of as a transformation of the input layer. \n% We can think of $\\phi$ as a transformation of the input layer. \nIts output is hence a new representation or interpretation of the information provided by $\\bm{x}$.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{figures/bt_dfnn.png}\n    \\caption{Example of a simple \\acrshort{mlp}. Left representation depicts individual neurons of each layer and the edges between them. The right representation is more common, depicting each layer with vector notation. }\n    \\source{\\cite{goodfellow2016}}\n    \\label{fig:bt_dfnn}\n\\end{figure}\n\n\\subsubsection{\\acrlong{mlp}}\n\nA \\acrfull{mlp} is one form of feedforward neural network, the simplest implementation of which is illustrated in figure \\ref{fig:bt_dfnn}. Here we have two input neurons, one hidden layer with two neurons, and one output layer with one neuron. With vector notation, we say that the hidden layer $\\bm{h}$ is a function of the input layer $\\bm{x}$, with the relation $\\bm{h}=f^{(1)}(\\bm{x};\\bm{W}, \\bm{c})$. $\\bm{h}$ is then the input to a third layer (which in this case is also the output layer) with the relation $y=f^{(2)}(\\bm{h};\\bm{W}, \\bm{c})$. We can keep adding depth and width to the model this way, further increasing its complexity and potential hypothesis space. The entire model may now be given by equation \\ref{eq:bt/dnn/mlp1}.\n\n\\begin{equation}\n    \\label{eq:bt/dnn/mlp1}\n    f(\\bm{x};\\bm{W},\\bm{c},\\bm{w},b)=f^{(2)}(f^{(1)}(\\bm{x}))\n\\end{equation}\n\nTo provide the nonlinearity we want, we define $\\bm{h}=g(\\bm{W}^T\\bm{x}+\\bm{c})$. This functon is commonly known as the \\textit{activation function} of the layer. For deeper networks, it would be added to the output of every hidden layer. There are many activation functions to choose from, but the default recommendation in the machine learning community is to use the \\acrfull{relu} \\cite{agarap2018}. It is defined as $g(z)=max\\{0,z\\}$ and has been made popular for its simplicity without trading off on optimization with gradient-based backpropagation. The complete network of figure \\ref{fig:bt_dfnn} can thus be given by equation \\ref{eq:bt/dnn/mlp3}.\n\n\\begin{equation}\n    \\label{eq:bt/dnn/mlp2}\n    y=f(\\bm{x};\\bm{W},\\bm{c}, \\bm{w}, b)=\\bm{w}^Tg(\\bm{W}^T\\bm{x}+\\bm{c}) + b\n\\end{equation}\n\n\\begin{equation}\n    \\label{eq:bt/dnn/mlp3}\n    y=f(\\bm{x};\\bm{W},\\bm{c}, \\bm{w}, b)=\\bm{w}^Tmax\\{\\bm{W}^T\\bm{x}+\\bm{c}\\} + b\n\\end{equation}\n\n\\newpage\n\\subsection{\\acrlong{cnn}s} \\label{sec:bt/DNN/CNN}\n\nA \\acrfull{cnn} is a specialized kind of deep feedforward neural network that has shown remarkable results in computer vision and language processing. When first proposed by \\textcite{lecun1989} in 1989, it revolutionized machine learning problems where data had a grid-structured topology. Such data could be interpreted with more insight while allowing for much deeper and scaleable model architectures. Before its inception, most practitioners had little faith in the advent of neural networks for machine learning. The success of \\acrshort{cnn}s triggered a wave of interest, which laid the foundation for further research in neural networks and deep learning \\cite{goodfellow2016}.\n\n\\subsubsection{Convolution}\n\nTo understand \\acrshort{cnn}s, we need to understand what a \\textit{convolution} is. Used in many engineering disciplines, it is simply a mathematical operator which expresses how two functions overlap \\cite{weisstein2003}. In signal processing, for instance, convolution may be used to mathematically replicate how a given sound signal would behave in any conceivable environment. All one would need is the impulse response of this environment, which could be the recording of a clap or similar fast transient sound. Convolving these two signals would have the effect of \"placing\" the sound in this environment, artificially reproducing all reverberations. The operation is typically denoted with an asterisk and is defined as equations \\ref{eq:bt/dnn/conv1}-\\ref{eq:bt/dnn/conv2}. This particular version is known as discrete convolution, which is what we will be encountering for neural networks.\n\n\\begin{equation}\n    \\label{eq:bt/dnn/conv1}\n    s(t)=(x*k)(t)\n\\end{equation}\n\n\\begin{equation}\n    \\label{eq:bt/dnn/conv2}\n    s(t)=\\sum_{a=-\\infty}^{\\infty}x(a)k(t-a)\n\\end{equation}\n\nWith \\acrshort{cnn} terminology, $x$ is the input to a convolutional layer and $k$ is its \\textit{kernel}. Since the input to a \\acrshort{cnn} is often an image, time series, or other signals, $x$ and $k$ are usually multidimensional. Taking image classification as an example, the convolutional operations performed on all input pixels would look like equation \\ref{eq:bt/dnn/conv3}.\n\n\\begin{equation}\n    \\label{eq:bt/dnn/conv3}\n    S(i,j)=(K*X)(i,j)=\\sum_{m}^{}\\sum_{n}^{}X(i-m,j-n)K(m,n)\n\\end{equation}\n\nEach pixel is denoted by $i$ and $j$ for its spatial coordinate in the input image. The output from convolving a kernel $K$ with an image $X$ is called a \\textit{feature map} because it is essentially a mapping to a new \"image\" where features represented by the kernel are highlighted. A visual representation of how a 2-dimensional convolutional operation may be applied to an input is displayed in figure \\ref{fig:bt_conv}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{figures/bt_conv.png}\n    \\caption{Example of 2-dimensional convolution operation. If this were image classification, values in the input matrix would represent individual pixel activations in the image. The final value of each output cell is calculated by the convolution operation given by equation \\ref{eq:bt/dnn/conv3}.}\n    \\source{\\cite{goodfellow2016}}\n    \\label{fig:bt_conv}\n\\end{figure}\n\nThe kernel $K$ is what defines all properties of a convolutional model. Instead of learning individual parameters for every edge between every neuron, as is the case for \\acrshort{mlp}s, \\acrshort{cnn}s learn the internal weights of all kernels in the network. As we will see, \\acrshort{cnn}s usually contain several kernels for every convolutional layer, each capturing one feature in the input to each layer.\n\n\\subsubsection{Properties of \\acrshort{cnn}s}\n\nWhat makes \\acrshort{cnn}s so efficient is based on three essential ideas. First, since parameters are only present in each kernel, as described above, the network does not need a single parameter for all neurons in every layer. This idea is known as \\textit{parameter sharing} and will reduce the storage requirements of large models. Another consequence of the convolutional layers is that each input neuron is only connected to a few outputs. As can be seen in figure \\ref{fig:bt_conv}, only four neurons of the input are required to calculate the value of a cell in the output. This idea is called \\textit{sparse interactions}. Contrary to an \\acrshort{mlp}, which requires connections from every input to every output, this feature drastically improves both computing efficiency and memory requirements during training.\n\nFinally, a concept known as \\textit{equivariant representations} allows for the detection of features that are independent of spatial (or temporal) position in the input. In other words, if there is an object in the input to a convolutional layer that causes high activations in a feature map, the same object will cause an equally high activation in the same feature map if it were in another position. This effect is another consequence of the way in which feature maps are created by \"moving\" the same kernel across the entire input. \\acrshort{mlp}s, in contrast, lack this property since each neuron is associated with an individual learned weight. \n% The kernel will eventually reach and generate the convolutional output for that respective feature regardless of its po\n\n\n% \\subsection{Terms} \\label{sec:bt/DNN/terms}\n\n% Much machine learning terminology is considered common knowledge in most literature and is often neglected to be explained in detail. Some such terms, many of which will be used frequently during the course of this thesis, are detailed below.\n\n% \\subsubsection{Batch Normalization}\n% \\subsubsection{Dropout}\n% % \\subsubsection{Perceptron}\n% % \\subsubsection{\\acrlong{relu}}\n% \\subsubsection{Max Pooling}\n% \\subsubsection{Softmax}\n% \\subsubsection{Cross Entropy Loss}\n% \\subsubsection{Precision, Accuracy and Recall}", "meta": {"hexsha": "5830adabfc471504d1d76a86d9c84d0b6766c290", "size": 10699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/background/DNN.tex", "max_stars_repo_name": "JLysberg/thesis-NTNU", "max_stars_repo_head_hexsha": "c0a9631f89a0112b2ade27d05c22818745706fb8", "max_stars_repo_licenses": ["MIT"], "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/background/DNN.tex", "max_issues_repo_name": "JLysberg/thesis-NTNU", "max_issues_repo_head_hexsha": "c0a9631f89a0112b2ade27d05c22818745706fb8", "max_issues_repo_licenses": ["MIT"], "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/background/DNN.tex", "max_forks_repo_name": "JLysberg/thesis-NTNU", "max_forks_repo_head_hexsha": "c0a9631f89a0112b2ade27d05c22818745706fb8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 99.0648148148, "max_line_length": 899, "alphanum_fraction": 0.7705393027, "num_tokens": 2675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.626175707068471}}
{"text": "\\lab{Kalman Filter}{Kalman Filter}\n\\objective{Understand how to implement the standard Kalman Filter. Apply to the problem of projectile tracking.}\n\nMeasured observations are often prone to significant noise, due to restrictions on measurement accuracy.\nFor example, most commercial GPS devices can provide a good estimate of geolocation, but only within a dozen meters or so.\nA Kalman filter is an algorithm that takes a sequence of noisy observations made over time and attempts to get rid of the noise,\nproducing more accurate estimates than the original observations.\nTo do this, the algorithm needs information about the system being observed.\n\nConsider the problem of tracking a projectile as it travels through the air.\nShort-range projectiles approximately trace out parabolas, but a sensor that is recording measurements of the projectile's position over time will likely show a path that is much\nless smooth.\nBecause we know something about the laws of physics, we can filter out the noise in the measurements using basic Newtonian mechanics, recovering a more accurate estimate\nof the projectile's trajectory.\nIn this lab, we will simulate measurements of a projectile and implement a Kalman filter to estimate the complete trajectory of the projectile.\n\n\\section*{Linear Dynamical Systems}\nThe standard Kalman filter assumes that:\n(1) we have a linear dynamical system,\n(2) the state of the system evolves over time with some noise, and\n(3) we receive noisy measurements about the state of the system at each iteration.\nMore formally, letting $\\mathbf{x}_{k}$ denote the state of the system at time $k$, we have\n\\begin{equation}\n\\mathbf{x}_{k+1} = F_{k} \\mathbf{x}_{k} + G_{k}\\mathbf{u}_{k} + \\mathbf{w}_{k}\n\\label{eq:state}\n\\end{equation}\nwhere $F_{k}$ is a state-transition model, $G_{k}$ is a control-input model, $\\mathbf{u}_{k}$ is a control vector, and $\\mathbf{w}_{k}$ is the noise present in state $k$.\nThis noise is assumed to be drawn from a multivariate Gaussian distribution with zero mean and covariance matrix $Q_{k}$.\nThe control-input model and control vector allow the assumption that the state can be additionally influenced by some other factor than the linear state-transition model.\n\nWe further assume that the states are ``hidden,'' and we only get the noisy observations\n\\begin{equation}\n\\mathbf{z}_{k} = H_{k}\\mathbf{x}_{k} + \\mathbf{v}_{k}\n\\label{eq:obs}\n\\end{equation}\nwhere $H_{k}$ is the observation model mapping the state space to the observation space, and $\\mathbf{v}_{k}$ is the observation noise present at iteration $k$.\nAs with the aforementioned error, we assume that this noise is drawn from a multivariate Gaussian distribution with zero mean and covariance matrix $R_{k}$.\n\nThe dynamics stated above are all taken to be linear.\nThus, for our purposes, the operators $F_k$, $G_k$, and $H_k$ are all matrices, and $\\mathbf{x}_k$, $\\mathbf{u}_k$, $\\mathbf{z}_k$, and $\\mathbf{v}_k$ are all vectors.\n\nWe will assume that the transition and observation models, the control vector, and the noise covariances are constant, i.e. for each $k$, we will replace $F_{k}, H_k, \\mathbf{u}_{k}, Q_{k},$ and $R_{k}$ with $F, H, \\mathbf{u}, Q,$ and $R$.\nWe will also assume that $G = I$ is the identity matrix, so it can safely be ignored.\n\n\\begin{problem}\nBegin implementing a \\li{KalmanFilter} class by writing an initialization method that stores the transition and observation models, noise covariances, and control vector.\nWe provide an interface below:\n\\begin{lstlisting}\nclass KalmanFilter(object):\n    def __init__(self,F,Q,H,R,u):\n        \"\"\"\n        Initialize the dynamical system models.\n\n        Parameters\n        ----------\n        F : ndarray of shape (n,n)\n            The state transition model.\n        Q : ndarray of shape (n,n)\n            The covariance matrix for the state noise.\n        H : ndarray of shape (m,n)\n            The observation model.\n        R : ndarray of shape (m,m)\n            The covariance matric for observation noise.\n        u : ndarray of shape (n,)\n            The control vector.\n        \"\"\"\n        pass\n\\end{lstlisting}\n\\end{problem}\n\nWe now derive the linear dynamical system parameters for a projectile traveling through $\\mathbb{R}^2$ undergoing a constant downward gravitational force of 9.8 $m/s^2$.\nThe relevant information needed to describe how the projectile moves through space is its position and velocity.\nThus, our state vector has the form\n\\[\n\\mathbf{x} = \\left( \\begin{array}{c} s_{x} \\\\ s_{y} \\\\ V_{x} \\\\ V_{y} \\end{array} \\right),\n\\]\nwhere $s_x$ and $s_y$ give the $x$ and $y$ coordinates of the position (in meters), and $V_x$ and $V_y$ give the horizontal and vertical components of the velocity (in meters per second), respectively.\n\nHow does the system evolve from one time step to the next?\nAssuming each time step is $0.1$ seconds, it is easy enough to calculate the new position:\n\\begin{align*}\ns_x' &= s_x + 0.1V_x\\\\\ns_y' &= s_y + 0.1V_y.\n\\end{align*}\nFurther, since the only force acting on the projectile is gravity (we are ignoring things like wind resistance), the horizontal velocity remains constant:\n\\[\nV_x' = V_x.\n\\]\nThe vertical velocity, however, does change due to the effects of gravity.\nFrom basic Newtonian mechanics, we have\n\\[\nV_y' = V_y - 0.1\\cdot9.8.\n\\]\nIn summary, over one time step, the state evolves from $\\mathbf{x}$ to $\\mathbf{x}'$, where\n\\[\n\\mathbf{x}' = \\left( \\begin{array}{c} s_{x} + 0.1V_x \\\\ s_{y} + 0.1V_y \\\\ V_{x} \\\\ V_{y} - 0.98 \\end{array} \\right).\n\\]\nFrom this equation, you can extract the state transition model $F$ and the control vector $u$.\n\nWe now turn our attention to the observation model.\nImagine that a radar sensor captures (noisy) measurements of the projectile's position as it travels through the air.\nAt each time step, the radar transmits the observation $z = (z_x, z_y)$ given by\n\\begin{align*}\nz_x &= s_x + v_x\\\\\nz_y &= s_y + v_y,\n\\end{align*}\nwhere $(v_x, v_y)$ is a noise vector assumed to be drawn from a multivariate Gaussian with mean zero and some known covariance.\nThese equations indicate the appropriate choice of observation model.\n\n\\begin{problem}\nWork out the transition and observation models $F$ and $H$, along with the control vector $\\mathbf{u}$, corresponding to the projectile.\nAssume that the noise covariances are given by\n\\begin{align*}\nQ &= 0.1 \\cdot I_4\\\\\nR &= 5000 \\cdot I_2.\n\\end{align*}\nInstantiate a \\li{KalmanFilter} object with these values.\n\\end{problem}\n\n\\begin{figure}\n    \\centering\n    \\begin{tabular}{cc}\n    \\includegraphics[width=.45\\textwidth]{states_evolution} &\n    \\includegraphics[width=.45\\textwidth]{obs_evolution}\n    \\end{tabular}\n    \\caption{State sequence (left) and sampling of observation sequence (right).}\n    \\label{fig:evolution}\n\\end{figure}\n\nWe now wish to simulate a sequence of states and observations from the dynamical system.\nIn addition to the system parameters, we need an initial state $\\mathbf{x}_0$ to get started.\nComputing the subsequent states and observations is simply a matter of following equations \\ref{eq:state} and \\ref{eq:obs}.\n\n\\begin{problem}\nAdd a method to your \\li{KalmanFilter} class to generate a state and observation sequence by evolving the system from a given initial state (the function \\li{numpy.random.multivariate_normal} will be useful).\nTo do this, implement the following:\n\\begin{lstlisting}\ndef evolve(self,x0,N):\n    \"\"\"\n    Compute the first N states and observations generated by the Kalman system.\n\n    Parameters\n    ----------\n    x0 : ndarray of shape (n,)\n        The initial state.\n    N : integer\n        The number of time steps to evolve.\n\n    Returns\n    -------\n    states : ndarray of shape (n,N)\n        States 0 through N-1, given by each column.\n    obs : ndarray of shape (m,N)\n        Observations 0 through N-1, given by each column.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\nSimulate the true and observed trajectory of a projectile with initial state\n\\[\n\\mathbf{x}_0 = \\left( \\begin{array}{c} 0\\\\ 0 \\\\ 300 \\\\ 600\\end{array} \\right).\n\\]\nApproximately 1250 time steps should be sufficient for the projectile to hit the ground (i.e. for the $y$ coordinate to return to 0).\nYour results should qualitatively match those given in Figure \\ref{fig:evolution}.\n\\label{prob:simulation}\n\\end{problem}\n\n\n\n\\section*{State Estimation with the Kalman Filter}\nThe Kalman filter is a recursive estimator that smooths out the noise in real time, estimating each current state based on the past state estimate and the current measurement.\nThis process is done by repeatedly invoking two steps: Predict and Update.\nThe predict step is used to estimate the current state based on the previous state.\nThe update step then combines this prediction with the current observation, yielding a more robust estimate of the current state.\n\nTo describe these steps in detail, we need additional notation. Let\n\\begin{itemize}\n    \\item $\\widehat{\\mathbf{x}}_{n|m}$ be the state estimate at time $n$ given only measurements up through time $m$; and\n    \\item $P_{n|m}$ be an error covariance matrix, measuring the estimated accuracy of the state at time $n$ given only measurements up through time $m$.\n\\end{itemize}\n\nThe elements $\\widehat{\\mathbf{x}}_{k|k}$ and $P_{k|k}$ represent the state of the filter at time $k$, giving the state estimate and the accuracy of the estimate.\n\n%\\begin{figure}\n%    \\centering\n%    \\includegraphics[width=.90\\textwidth]{norms}\n%    \\caption{Norms of the estimated accuracy matrices as the Kalman filter progresses. }\n%    \\label{fig:norms}\n%\\end{figure}\n\nWe evolve the filter recursively, as follows:\n\\begin{align*}\n\\textbf{Predict} & & \\widehat{\\mathbf{x}}_{k|k-1} & = F\\widehat{\\mathbf{x}}_{k-1|k-1} + \\mathbf{u} \\\\\n & & P_{k|k-1} & = FP_{k-1|k-1}F^{T} + Q \\\\\n\\textbf{Update} & & \\tilde{\\mathbf{y}}_{k} & = \\mathbf{z}_{k} - H\\widehat{\\mathbf{x}}_{k|k-1} \\\\\n & & S_{k} & = HP_{k|k-1}H^{T} + R \\\\\n & & K_{k} & = P_{k|k-1}H^{T}S_{k}^{-1} \\\\\n & & \\widehat{\\mathbf{x}}_{k|k} & = \\widehat{\\mathbf{x}}_{k|k-1} + K_{k}\\tilde{\\mathbf{y}}_{k} \\\\\n & & P_{k|k} & = (I - K_{k}H)P_{k|k-1}\n\\end{align*}\n\nThe more observations we have, the greater the accuracy of these estimates becomes (i.e the norm of the accuracy matrix converges to $0$).\n%This is reflected in Figure \\ref{fig:norms}.\n\n\\begin{problem}\nAdd code to your \\li{KalmanFilter} class to estimate a state sequence corresponding to a given observation sequence and initial state estimate.\nImplement the following class method:\n\\begin{lstlisting}\ndef estimate(self,x,P,z):\n    \"\"\"\n    Compute the state estimates using the Kalman filter.\n    If x and P correspond to time step k, then z is a sequence of\n    observations starting at time step k+1.\n\n    Parameters\n    ----------\n    x : ndarray of shape (n,)\n        The initial state estimate.\n    P : ndarray of shape (n,n)\n        The initial error covariance matrix.\n    z : ndarray of shape(m,N)\n        Sequence of N observations (each column is an observation).\n\n    Returns\n    -------\n    out : ndarray of shape (n,N)\n        Sequence of state estimates (each column is an estimate).\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n    \\centering\n    \\begin{tabular}{cc}\n    \\includegraphics[width=.45\\textwidth]{estimate_macro} &\n    \\includegraphics[width=.45\\textwidth]{estimate_micro}\n    \\end{tabular}\n    \\caption{State estimates together with observations and true state sequence (detailed view on the right).}\n    \\label{fig:estimates}\n\\end{figure}\n\nReturning to the projectile example, we now assume that our radar sensor has taken observations from time steps $200$ through $800$ (take the corresponding slice of the\nobservations produced in Problem \\ref{prob:simulation}).\nUsing these observations, we seek to estimate the corresponding true states of the projectile.\nWe must first come up with a state estimate $\\widehat{\\mathbf{x}}_{200}$ for time step $200$, and then feed this into the Kalman filter\nto obtain estimates $\\widehat{\\mathbf{x}}_{201}, \\ldots, \\widehat{\\mathbf{x}}_{800}$.\n\\begin{problem}\nCalculate an initial state estimate $\\widehat{\\mathbf{x}}_{200}$ as follows:\nFor the horizontal and vertical positions, simply use the observed position at time $200$.\nFor the velocity, compute the average velocity between the observations $\\mathbf{z}_k$ and $\\mathbf{z}_{k+1}$ for\n$k = 200,\\ldots,208$, then average these 9 values and take this as the initial velocity estimate.\n(Hint: the NumPy function \\li{diff} is useful here.)\n\nUsing the initial state estimate, $P_{200} = 10^{6} \\cdot Q$, and your Kalman filter, compute the next $600$ state estimates,\ni.e. compute $\\widehat{\\mathbf{x}}_{201}, \\ldots, \\widehat{\\mathbf{x}}_{800}$.\nPlot these state estimates as a smooth green curve together with the radar observations (as red dots) and the entire true state sequence (as a blue curve).\nZoom in to see how well it follows the true path. Your plots should be similar to Figure \\ref{fig:estimates}.\n\\label{prob:state_estimate}\n\\end{problem}\n\nIn the absence of observations, we can still estimate some information about the state of the system at some future time.\nWe can do this by recognizing that the expected state noise $\\mathbb{E}\\left[\\boldsymbol{\\epsilon}_{k}\\right] = 0$ at any time $k$.\nThus, given a current state estimate $\\widehat{\\mathbf{x}}_{n|m}$ using only measurements up through time $m$, the expected state at time $n+1$ is\n\\begin{equation*}\n\\widehat{\\mathbf{x}}_{n+1|m} = F \\widehat{\\mathbf{x}}_{n|m} + \\mathbf{u}\n\\end{equation*}\n\n\\begin{problem}\nAdd a function to your class that predicts the next $k$ states given a current state estimate but in the absence of observations.\nDo so by implementing the following function:\n\\begin{lstlisting}\ndef predict(self,x,k):\n    \"\"\"\n    Predict the next k states in the absence of observations.\n\n    Parameters\n    ----------\n    x : ndarray of shape (n,)\n        The current state estimate.\n    k : integer\n        The number of states to predict.\n\n    Returns\n    -------\n    out : ndarray of shape (n,k)\n        The next k predicted states.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{figure}\n    \\centering\n    \\begin{tabular}{cc}\n    \\includegraphics[width=.45\\textwidth]{impact_macro} &\n    \\includegraphics[width=.45\\textwidth]{impact_micro}\n    \\end{tabular}\n    \\caption{Predicted vs. actual point of impact (detailed view on right).}\n    \\label{fig:impact}\n\\end{figure}\n\nWe can use this prediction routine to estimate where the projectile will hit the surface.\n\\begin{problem}\nUsing the final state estimate $\\widehat{\\mathbf{x}}_{800}$ that you obtained in Problem \\ref{prob:state_estimate}, predict the future states of\nthe projectile until it hits the ground.\nPredicting approximately the next $450$ states should be sufficient.\n\nPlot the actual state sequence together with the predicted state sequence (as a yellow curve), and observe how near the prediction is to the actual point of impact.\nYour results should be similar to those shown in Figure \\ref{fig:impact}.\n\\end{problem}\n\nIn the absence of observations, we can also reverse the system and iterate backward in time to infer information about states of the system prior to measured observations.\nThe system is reversed by\n\\begin{equation*}\n\\mathbf{x}_{k} = F^{-1}(\\mathbf{x}_{k+1} - \\mathbf{u} - \\boldsymbol{\\epsilon}_{k+1}).\n\\end{equation*}\nConsidering again that $\\mathbb{E}\\left[\\boldsymbol{\\epsilon}_{k}\\right] = 0$ at any time $k$, we can ignore this term, simplifying the recursive estimation backward in time.\n\n\n\n\n\\begin{figure}[htb]\n    \\centering\n    \\begin{tabular}{cc}\n    \\includegraphics[width=.45\\textwidth]{origin_macro} &\n    \\includegraphics[width=.45\\textwidth]{origin_micro}\n    \\end{tabular}\n    \\caption{Predicted vs. actual point of origin (detailed view on right).}\n    \\label{fig:origin}\n\\end{figure}\n\n\\begin{problem}\nAdd a function to you class that rewinds the system from a given state estimate, returning predictions for the previous states.\nDo so by implementing the following function:\n\\begin{lstlisting}\ndef rewind(self,x,k):\n    \"\"\"\n    Predict the k states preceding the current state estimate x.\n\n    Parameters\n    ----------\n    x : ndarray of shape (n,)\n        The current state estimate.\n    k : integer\n        The number of preceding states to predict.\n\n    Returns\n    -------\n    out : ndarray of shape (n,k)\n        The k preceding predicted states.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nReturning to the projectile example, we can now predict the point of origin.\n\n\\begin{problem}\nUsing your state estimate $\\widehat{\\mathbf{x}}_{250}$, predict the point of origin of the projectile along with\nall states leading up to time step $250$. Note that you may have to take a few extra time steps to predict the point of origin.\n(The point of origin is the first point along the trajectory where the $y$ coordinate is $0$.)\nPlot these predicted states (in cyan) together with the original state sequence.\nZoom in to see how accurate your prediction is.\nYour plots should be similar to Figure \\ref{fig:origin}.\n\\label{prob:origin_pt}\n\nRepeat the prediction starting with $\\widehat{\\mathbf{x}}_{600}$.  Compare to the previous results.  Which is better?  Why?\n\\end{problem}\n", "meta": {"hexsha": "c78895d6e6a00f04fb715b93179c400e8d659db4", "size": 17198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume3/KalmanFilter/KalmanFilter.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": "Volume3/KalmanFilter/KalmanFilter.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": "Volume3/KalmanFilter/KalmanFilter.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": 46.4810810811, "max_line_length": 239, "alphanum_fraction": 0.7222932899, "num_tokens": 4470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6261566134689905}}
{"text": "\\documentclass{article}\n\\usepackage{leonine,amsmath,amssymb,amsthm,graphicx}\n\\setkeys{Gin}{width=\\linewidth,totalheight=\\textheight,keepaspectratio}\n\\graphicspath{{graphics/}}\n% Prints a trailing space in a smart way.\n\\usepackage{xspace}\n% Inserts a blank page\n\\newcommand{\\blankpage}{\\newpage\\hbox{}\\thispagestyle{empty}\\newpage}\n% \\usepackage{units}\n% Typesets the font size, leading, and measure in the form of 10/12x26 pc.\n\\newcommand{\\measure}[3]{#1/#2$\\times$\\unit[#3]{pc}}\n\n\\theoremstyle{definition}\n\\newtheorem{pred}[thm]{Prediction}\n\n\\title{Askesis: Introduction} \\author{Eric Purdy}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Perceptron model of a neuron}\n\nA perceptron has two possible outputs, $1$ (representing firing) and\n$0$ (representing not firing). Let its inputs be denoted by $x_1,\n\\dots, x_n$. The rule is then\n$$y = \\begin{cases} 1 & \\sum_i w_i x_i > \\theta \\\\ -1 & \\mbox{otherwise}  \n\\end{cases}$$\n\nThe $x_i$ can usually be taken to be either $0$ (if the input neuron\nfires) or $1$ (if the input neuron does not fire). Neurons that do not\nfire are thus not included in the sum. Occasionally, it is helpful to\nthink about $x_i$ between zero and one, in which case it can be\nencoded by the firing rate. So, if the neuron fires at its maximum\nrate, that is represented by a one, and if it doesn't fire at all,\nthat is represented by a zero. If it fires at a tenth its firing rate,\nthat is represented by $0.1$.\n\nThe $w_i$ are called the synapse weights; each is a summary of\nproperties of the synapse that occurs between the $i$-th input neuron\nand the output neuron. These properties include the physical distance\nbetween the two neurons, as well as the concentration of\nneurotransmitter receptors in the output neuron, and other things as\nwell. If $w_i > 0$, then we call the synapse ``excitatory'' - the\nfiring of the input neuron excites the output neuron. Most excitatory\nsynapses use the neurotransmitter glutamate. If $w_i < 0$, we call the\nsynapse ``inhibitory'' - the firing of the input neuron inhibits the\noutput neuron. Most inhibitory synapses use the neurotransmitter GABA\n(Gamma-Aminobutyric acid). In actual neurons, a single neuron releases\na single main neurotransmitter, and is therefore only ever excitatory\n(all synapses it outputs to are excitatory) or inhibitory (all\nsynapses it outputs to are inhibitory). The parameter $\\theta$\ncontrols how excitable the neuron is, and can be modified by\nlearning. This is called ``intrinsic plasticity''.\n\n\\footnote{I like to think of glutamate as the ``black ink'' and GABA as the\n  ``red ink'' of the nervous system.}\n\nA perceptron is much simpler than a neuron, but is a reasonable\nfirst-pass approximation. Our model does not require anything more\ncomplicated than perceptrons.\n\nThe word ``perceptron'' actually refers to two things: the model\nabove, and a learning algorithm. We will describe the learning\nalgorithm here. First, we add an $x_0$ that is always $1$, and let\n$w_0 = - \\theta$. The perceptron then fires if $\\sum_{i=0}^n w_i x_i >\n0$. We then suppose that we see a sequence of inputs $x_i(t)$, each\nlabeled either $1$ or $-1$ by a desired output $\\widehat{y}(t)$. The\nlearning rule is then as follows: if the output $y$ of the neuron was\nthe same as $\\widehat{y}(t)$, we do nothing. If $y(t) \\ne\n\\widehat{y}(t)$, then we update the weights as follows:\n$$w_i(t+1) = w_i(t) + \\alpha (\\widehat{y}(t) - y(t)) x_i(t).$$ If we\nstart with all $w_i$ equal to zero, then the $w_i(t)$ (considered as a\nvector) will be equal to the sum of the $\\mathbf{x}(t)$ for which\n$\\widehat{y}(t)=1,y(t)=0$, minus the sum of the $\\mathbf{x}(t)$ for\nwhich $\\widehat{y}(t)=0, y(t)=1$. The parameter $\\alpha$ is called\nthe learning rate; high values of $\\alpha$ result in a system that\nchanges its parameters more quickly and thus learns more quickly. A\nlower learning rate can be desirable, since the system will be less\nlikely to lose the information it already has.\n\nThe perceptron algorithm is impossible to implement in a single\nneuron, since it requires the same synapse to be both excitatory and\ninhibitory, depending on what the training data looks like. The\nperceptron algorithm is still useful to know, since it can be\nimplemented by multiple neurons, and has long been thought to be a\nlarge part of how the cerebellum works.\n\n\n\\section{Basic overview of the cerebellum}\n\n\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{organization.png}\n\\caption{Inputs and outputs of the cerebellum. The two arrows marked\n  with double lines represent two neural pathways that convey copies\n  of the same information.}\n\\label{fig-organization}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/global.png}\n\\caption{How the cerebellum fits into the rest of the brain. Courtesy\n  of\n  http://what-when-how.com/wp-content/uploads/2012/04/tmp15F121.jpg}\n\\label{fig-global}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/pathways.png}\n\\caption{Pathways into and out of the cerebellum. The fastigial,\n  interposed, and dentate nuclei (and some others) are collectively\n  referred to as the deep nuclei, as they lie deep within the\n  cerebellum. Courtesy of\n  http://www.dizziness-and-balance.com/anatomy/brain/cerebellum.htm}\n\\label{fig-pathways}\n\\end{figure}\n\n\n\\section{Cell types}\n\nThe cerebellum contains a number of different types of cells:\n\\begin{description}\n\\item[Mossy fiber] Mossy fibers are the axons of neurons outside of\n  the cerebellum. They constitute one of the two sources of input of\n  the cerebellum. One of the major sources of mossy fibers is the\n  pontine nuclei, which relay information from the cerebrum.\n\n  All mossy fibers are excitatory. The mossy fibers excite granular\n  cells and Golgi cells, and collaterals (side branches) of the mossy\n  fibers excite deep nuclear cells.\n\n  Mossy fibers participate in both the positive and negative pathways.\n\n\\item[Deep nuclear cell] These are the main source of output from the\n  cerebellum. (Some Purkinje cells project to the vestibular nuclei,\n  which seem to be pretty similar to the deep nuclei.)\n\n  Some of the deep nuclei are: interposed nucleus, fastigial nucleus,\n  dentate nucleus.\n\n  There are two kinds of deep nuclear cell, large and small. The large\n  cells can be excitatory or inhibitory, and project to premotor\n  areas. The small cells are inhibitory and project to the inferior\n  olive.\n\n  Deep nuclear cells receive input from mossy fiber collaterals,\n  climbing fiber collaterals, and Purkinje cells.\n\n  Deep nuclear cells participate in both the positive and negative\n  pathways.\n\n\\item[Inferior olive cell] These are the second source of input to the\n  cerebellum. They receive an ``efference'' copy of the signals sent\n  from the cerebrum to the spinal cord.\n\n  The inferior olive cells are excitatory and send climbing fibers\n  into the cerebellum to make contact with the Purkinje cells,\n  stellate cells, and basket cells. A single climbing fiber impulse\n  will cause a Purkinje cell to fire. \n\n  Collaterals of the climbing fiber make contact with the deep nuclear\n  cells.\n\n  Inferior olive cells participate in both the positve and negative\n  pathways.\n\n\\item[Purkinje cell] The Purkinje cells are inhibitory, and send their\n  output to the deep nuclear cells. They receive input mainly from the\n  parallel fibers, which are the output of the granular cells. They\n  also receive some input directly from nearby granular cells.\n\n  Purkinje cells fire at a certain base rate even when not receiving\n  any input.\n\n  Purkinje cells participate in the negative pathway.\n\n\\item[Basket/stellate cell] Basket and stellate cells inhibit the\n  Purkinje cells (and thus disinhibit the deep nuclear cells by\n  proxy).\n\n  The stellate cells occupy the outermost portions of the cerebellar\n  cortex, while basket cells are slightly more inward. There is also\n  an intermediate type of cell that occurs between the basket cells\n  and stellate cells and has an appearance halfway between the two.\n\n  Basket and stellate cells participate in the negative pathway.\n\n\\item[Granular cell] Granular cells receive input from 4-5 mossy\n  fibers. Granular cells are excitatory. The output of the granular\n  cell is the parallel fiber, which sends input to the Purkinje cells,\n  basket cells, and stellate cells.\n\n  Granular cells are generally thought to fire only when multiple of\n  their inputs are active.\n\n  Granular cells are the most numerous neurons in the brain; about\n  three-fourths of the neurons in the brain are granular cells in the\n  cerebellum. (Granular cells are very small, so the cerebellum only\n  takes up about 10\\% of the volume of the brain.)\n\n  Granular cells participate in the negative pathway.\n\\end{description}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{cells.png}\n\\caption{Cells of the cerebellum. Excitatory cells are shown in black,\n  while inhibitory cells are shown in red. Inputs to a cell are shown\n  as an empty half circle, while outputs are shown as a full half\n  circle.  Cells of the inferior olive are shown in green, to\n  emphasize that their output is used to train the targeted cells;\n  they are excitatory. There are two kinds of deep nuclear cell: one\n  excitatory and projecting either back into the cerebellum or to\n  premotor areas; and one inhibitory and projecting to the inferior\n  olive. Since the cells receive the same input, we have simplified\n  the picture by identifying them together. It is also worth noting\n  that state cells are actually represented twice here: they are both\n  ``mossy fiber cells'' and ``deep nuclear cells''.}\n\\label{fig-cells}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/028.png}\n\\caption{Cells of the cerebellum. Courtesy of\n  https://nanohub.org/resources/18948/watch?resid=19060}\n\\label{fig-physical-1}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/029.png}\n\\caption{Cells of the cerebellum. Courtesy of\n  https://nanohub.org/resources/18948/watch?resid=19060}\n\\label{fig-physical-2}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/image004.png}\n\\caption{Cells of the cerebellum. Courtesy of http://www.scritub.com/limba/engleza/health/CEREBELLUM25854.php}\n\\label{fig-physical-3}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\linewidth]{nanohub/nature.png}\n\\caption{Cells of the cerebellum. Courtesy of\n  http://www.nature.com/nrn/journal/v9/n4/images/nrn2332-f3.jpg.\nPCN:pontine nuclei.\nMF: mossy fiber.\nLg: Lugaro cell.\n5-HT fibres: beaded fibers.\nUB: unipolar brush cells (found only in the vestibulocerebellum).\nGo: Golgi cell.\nGr: Granular cell.\nN-C: state cell pathway.\nCN/VN: deep nuclei and vestibular nuclei.\nPF: parallel fiber.\nLTD: long-term depression, the learning mechanism of the Purkinje cell.\nSC: stellate cell.\nBC: basket cell.\nCF: climbing fiber.\nN-O: training suppression cell pathway to inferior olive.\nIO: inferior olive.\nR-O: red nucleus to inferior olive pathway.\npRN: parvocellular (small cells) red nucleus. \nPd: unknown, seems to refer to another kind of beaded fiber.\n}\n\\label{fig-physical-4}\n\\end{figure}\n\n\n\\section{Learning}\n\nAs a brief aside to anyone not versed in machine learning or neuroscience,\n``learning'' is a term that describes changing the structure or parameters of a\nsystem in order to make that system better achieve some goal or perform some\npurpose correctly. The best understood mechanism for learning in the brain is\nchanging the strength of synapses, the gaps between two neurons, usually by\nchanging the number of receptors that respond to neurotransmitters.\n\n\\section{Thoughts}\n\n\\begin{itemize}\n\\item Discuss microzones. In particular, how big are they? What\n  constraints do they impose?\n\\item Give sigmoid rule with probability.\n\n\\item Hebbian learning\n\n\\item Explain electrical synapses in the inferior olive?\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "791859ed065a58ce401642b71872c0a06370dea6", "size": 11860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "askesis/neuro.tex", "max_stars_repo_name": "advancedresearch/ethicophysics", "max_stars_repo_head_hexsha": "52806b53d6d3ee92e1bd2a8c00f7728cebc9e684", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-04-26T17:10:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-19T01:56:36.000Z", "max_issues_repo_path": "askesis/neuro.tex", "max_issues_repo_name": "advancedresearch/ethicophysics", "max_issues_repo_head_hexsha": "52806b53d6d3ee92e1bd2a8c00f7728cebc9e684", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2018-04-26T16:25:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-15T10:13:05.000Z", "max_forks_repo_path": "askesis/neuro.tex", "max_forks_repo_name": "advancedresearch/ethicophysics", "max_forks_repo_head_hexsha": "52806b53d6d3ee92e1bd2a8c00f7728cebc9e684", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-13T17:37:48.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-13T17:37:48.000Z", "avg_line_length": 40.4778156997, "max_line_length": 110, "alphanum_fraction": 0.7699831366, "num_tokens": 3117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6261449027839765}}
{"text": "\\documentclass{ut-thesis}\n\n%**************************** General libraries *******************************\n\\usepackage{mathtools}\n\\usepackage{cancel}\n\\usepackage[utf8]{inputenc} \n\\usepackage{amssymb}\n\\usepackage{ntheorem}\n\\usepackage{tensor}\n%\\usepackage{physics}\n\\usepackage[italicdiff]{physics}\n\\usepackage{calc}\n\\usepackage{caption}\n%\\usepackage{subcaption}\n\\usepackage{tcolorbox}\n\\usepackage{chngcntr}\n\\usepackage{titlesec}\n\\usepackage {graphicx,float} \n\\usepackage{subfig}\n\\usepackage{siunitx}\n\\usepackage{xcolor}\n\\usepackage{etoolbox} %ifthen\n\\usepackage[outline]{contour} % glow around text\n\n%**************************** Bibliography management *******************************\n\\usepackage{biblatex} %Imports biblatex package\n\\addbibresource{sample.bib} %Import the bibliography file\n\n\n\n%**************************** Tikz libraries *******************************\n\\usepackage{tikz}\n\\usetikzlibrary{shapes,arrows,arrows.meta,spy}\n\\usetikzlibrary{calc}% needed for BB\n\\usepackage{pgfplots}\n\\usetikzlibrary{math} % for \\tikzmath\n\\usetikzlibrary{angles,quotes} % for pic (angle labels)\n\\usetikzlibrary{decorations.pathmorphing,decorations.markings}\n\\usetikzlibrary{decorations.pathreplacing} % for curly braces\n\\usetikzlibrary {decorations.markings,shapes.arrows}\n\\usetikzlibrary{patterns}\n\\usepackage{tikz-3dplot}\n\n%\\usepackage[margin=0cm,nohead]{geometry}\n%\\usepackage[active,tightpage]{preview}\n%\\usepackage[pdf]{pstricks}\n\n%**************************** custom macro's *******************************\n\\newsavebox\\CBox\n\\newcommand\\hcancel[2][0.5pt]{%\n  \\ifmmode\\sbox\\CBox{$#2$}\\else\\sbox\\CBox{#2}\\fi%\n  \\makebox[0pt][l]{\\usebox\\CBox}%  \n  \\rule[0.5\\ht\\CBox-#1/2]{\\wd\\CBox}{#1}}\n%\\newcommand{\\edal}{\\end{align}}\n%\\newcommand{\\bgal}{\\begin{align}\\end{align}}\n\\newcommand{\\Lagr}{\\mathcal{L}}\n\\newcommand{\\questeq}{\\overset{?}{=}}\n%\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\renewcommand\\thelemma{\\unskip}\n\\newcommand{\\christ}[3]{\\ensuremath{\\Gamma^{#1}_{#2#3}}}\n\\newcommand{\\half}{\\ensuremath{\\frac{1}{2}}}\n\\newcommand{\\kwart}{\\ensuremath{\\frac{1}{4}}}\n\\newcommand\\del{\\overline{\\boldsymbol{{\\triangledown}}}}\n\\newcommand\\maal{\\boldsymbol{\\times}}\n\\newcommand\\spatie{\\quad\\quad\\quad\\quad}\n\\newcommand\\RAr{\\quad\\Rightarrow\\quad}\n%\\newcommand{\\myabsdv}[3]{{\\frac{\\delta^2 \\ensuremath{{#1}}}{{\\delta %%\\ensuremath{{#2}}}{\\delta\\ensuremath{{#3}}}}}}\n\\newcommand\\myabsdv[3][1]{{\\frac{{\\delta^{2}}{#1}}{\\delta {#2} \\delta {#3}}}}\n\n%**************************** layout setings *******************************\n\\counterwithin*{equation}{chapter}\n\\counterwithin*{equation}{section}\n\\counterwithin*{equation}{subsection}\n\\renewcommand{\\theequation}{\\arabic{equation}}\n\\titleformat{\\chapter}{\\normalfont\\huge}{\\thechapter.}{20pt}{\\huge\\it}\n\\titleformat{\\chapter}[display]\n  {\\normalfont\\bfseries}{}{0pt}{\\Huge}\n\\titlespacing*{\\chapter}{0pt}{50pt}{*2}\n\n%**************************** Tikz  setings *******************************\n\\begin{comment}\n\\tikzset{\n    circ/.style={draw, circle,inner sep=0pt,minimum size=8mm, font=\\scriptsize},\n    triangle/.tip={Computer Modern Rightarrow[open,angle=120:3pt]}}\n    \n\\tikzset{\n  every point/.style = {circle, inner sep={.75\\pgflinewidth}, opacity=1, draw, solid, fill=white},\n  point/.style={insert path={node[every point, #1]{}}}, point/.default={},\n  colored point/.style = {point={fill=#1}},\n  point name/.style = {insert path={coordinate (#1)}},\n  inherit/.style = {point/.style={insert path={node[circle, inner sep={.75\\pgflinewidth}, draw, fill, #1]{}}}}\n}\n\\end{comment}\n\n%**************************** Where to find images *****************************\n\\graphicspath{ {D:/MathLatex/images/} }\n\n\n%**************************** Document itself *******************************\n\\author{Bernard Carrette}\n\\gradyear{2020}\n\\title{Tensor Calculus\\\\J.L. Synge and A.Schild (Dover Publication)\\\\ Solutions to exercises}\n\\begin{document}\n\\maketitle\n\n\\section*{Remarks and warnings}\nYou're welcome to use these notes, but they may contain errors, so proceed with caution. If you do find an error, however, I'd be happy to receive bug reports, suggestions, and the like through Github.\n\\section*{Some notation conventions}\n\\begin{center}\n\\begin{tabular}{ c c  }\n$\\partial_r \\equiv \\pdv{}{x^r}$ & \\\\\\\\\n$\\Gamma^r_{mn} \\equiv \n\\begin{Bmatrix}\nr\\\\\nm n\\\\\n\\end{Bmatrix}$ & Christoffel symbol of the second kind\\\\\\\\\n\n\\end{tabular}\n\\end{center}\n\n\\tableofcontents\n\\listoffigures\n\\include{chapter1}\n\\include{chapter2}\n\\include{chapter3}\n\\include{chapter4}\n%\\include{chapter5}\n\\printbibliography %Prints bibliography\n\\end{document}", "meta": {"hexsha": "150fbb50846631c0a31e75ff8b2b20cf988537b4", "size": 4557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.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": "main.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": "main.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": 35.0538461538, "max_line_length": 201, "alphanum_fraction": 0.6570111916, "num_tokens": 1374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.6259752481363589}}
{"text": "\\subsection*{Stream Support}\n\nThe following stream processing functions are supported:\n\n\\begin{itemize}\n\\item \\lstinline{stream_tail(x)}: \\textit{primitive}, assumes that the tail (second component) of the\n  pair \\lstinline{x} is a nullary function, and returns the result of\n  applying that function.\\\\\n\\emph{Laziness:}  Yes: \\lstinline{stream_tail} only forces the direct tail of a given\nstream,\nbut not the rest of the stream, i.e. not the tail of the tail, etc.\n\\item \\lstinline{stream(x1, x2,..., xn)}: \\textit{primitive}, returns a stream with $n$ elements. The\nfirst element is \\lstinline{x1}, the second \\lstinline{x2}, etc.\\\\\n\\emph{Laziness:}  No: In this implementation, we generate first a\n           complete list, and then a stream using \\lstinline{list_to_stream}.\n\\item \\lstinline{is_stream(x)}: Returns \\lstinline{true} if\n  \\lstinline{x} is a stream as defined in the lectures, and\n  \\lstinline{false} otherwise.\\\\\n\\emph{Laziness:}  No: \\lstinline{is_stream} needs to force the given stream.\n\\item \\lstinline{list_to_stream(xs)}: transforms a given list to a stream.\\\\\n\\emph{Laziness:}  Yes: \\lstinline{list_to_stream} goes down the list only when forced.\n\\item \\lstinline{stream_to_list(s)}: transforms a given stream to a list.\\\\\n\\emph{Laziness:}  No: \\lstinline{stream_to_list} needs to force the whole stream.\n\\item \\lstinline{stream_length(s)}: Returns the length of the stream\n  \\lstinline{s}.\\\\\n\\emph{Laziness:}  No: The function needs to force the whole stream.\n\\item \\lstinline{stream_map(f, s)}: Returns a stream that results from stream\n  \\lstinline{s} by element-wise application of \\lstinline{f}.\\\\\n\\emph{Laziness:}  Yes: The argument stream is only explored as forced by\n           the result stream.\n\\item \\lstinline{build_stream(n, f)}: Makes a stream with \\lstinline{n}\nelements by applying the unary function \\lstinline{f} to the numbers 0\nto \\lstinline{n - 1}.\\\\\n\\emph{Laziness:}  Yes: The result stream forces the applications of fun\n            for the next element.\n\\item \\lstinline{stream_for_each(f, s)}: Applies \\lstinline{f} to every\n  element of the stream \\lstinline{s}, and then returns\n  \\lstinline{true}.\\\\\n\\emph{Laziness:}  No: \\lstinline{stream_for_each} forces the exploration of the entire stream.\n\\item \\lstinline{stream_reverse(s)}: Returns finite stream \\lstinline{s} in reverse\n  order. Does not terminate for infinite streams.\\\\\n\\emph{Laziness:}  No: \\lstinline{stream_reverse} forces the exploration of the entire stream.\n\\item \\lstinline{stream_append(xs, ys)}: Returns a stream that results from \nappending the stream \\lstinline{ys} to the stream \\lstinline{xs}.\\\\\n\\emph{Laziness:}  Yes: Forcing the result stream activates the actual append operation.\n\\item \\lstinline{stream_member(x, s)}: Returns first postfix substream\nwhose head is equal to\n\\lstinline{x} (\\lstinline{===}); returns \\lstinline{null} if the\nelement does not occur in the stream.\\\\\n \\emph{Laziness:}  Sort-of: \\lstinline{stream_member} forces the stream only until the element is found.\n\\item \\lstinline{stream_remove(x, s)}: Returns a stream that results from\ngiven stream \\lstinline{s} by removing the first item from \\lstinline{s} that\nis equal (\\lstinline{===}) to \\lstinline{x}.\nReturns the original list\nif there is no occurrence.\\\\\n\\emph{Laziness:}  Yes: Forcing the result stream leads to construction of each next element.\n\\item \\lstinline{stream_remove_all(x, s)}: Returns a stream that results from\ngiven stream \\lstinline{s} by removing all items from \\lstinline{s} that\nare equal (\\lstinline{===}) to \\lstinline{x}.\\\\\n\\emph{Laziness:}  Yes: The result stream forces the construction of each next element.\n\\item \\lstinline{stream_filter(pred, s)}: Returns a stream that contains\nonly those elements for which the one-argument function\n\\lstinline{pred}\nreturns \\lstinline{true}.\\\\\n\\emph{Laziness:}  Yes: The result stream forces the construction of\n            each next element. Of course, the construction\n            of the next element needs to go down the stream\n            until an element is found for which \\lstinline{pred} holds.\n\\item \\lstinline{enum_stream(start, end)}: Returns a stream that enumerates\nnumbers starting from \\lstinline{start} using a step size of 1, until\nthe number exceeds (\\lstinline{>}) \\lstinline{end}.\\\\\n \\emph{Laziness:}  Yes: Forcing the result stream leads to the construction of\n            each next element.\n\\item \\lstinline{integers_from(n)}: Constructs an infinite stream of integers\nstarting at a given number \\lstinline{n}.\\\\\n \\emph{Laziness:}  Yes: Forcing the result stream leads to the construction of \n            each next element.\n\\item \\lstinline{eval_stream(s, n)}: Constructs the list\nof the first \\lstinline{n} elements\nof a given stream \\lstinline{s}.\\\\\n\\emph{Laziness:}  Sort-of: \\lstinline{eval_stream} only forces the computation of\n                the first \\lstinline{n} elements, and leaves the rest of\n                the stream untouched.\n\\item \\lstinline{stream_ref(s, n)}: Returns the element\nof stream \\lstinline{s} at position \\lstinline{n}, \nwhere the first element has index 0.\\\\\n \\emph{Laziness:}  Sort-of: \\lstinline{stream_ref} only forces the computation of\n                the first \\lstinline{n} elements, and leaves the rest of\n                the stream untouched.\n\\end{itemize}\n", "meta": {"hexsha": "520fd7fba9491abe22b4d7188d5aa66fadec37a3", "size": 5299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/specs/source_streams.tex", "max_stars_repo_name": "jaesimin/js-slang", "max_stars_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2018-07-09T06:16:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:40:24.000Z", "max_issues_repo_path": "docs/specs/source_streams.tex", "max_issues_repo_name": "jaesimin/js-slang", "max_issues_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1117, "max_issues_repo_issues_event_min_datetime": "2018-07-09T08:08:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:47:08.000Z", "max_forks_repo_path": "docs/specs/source_streams.tex", "max_forks_repo_name": "jaesimin/js-slang", "max_forks_repo_head_hexsha": "153596c436998e4aa182a61be455febf77eb5510", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 80, "max_forks_repo_forks_event_min_datetime": "2018-08-24T08:55:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T08:56:48.000Z", "avg_line_length": 58.2307692308, "max_line_length": 104, "alphanum_fraction": 0.7371202114, "num_tokens": 1468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.625915436906419}}
{"text": "\\documentclass{scrartcl}\n\\usepackage[a4paper,left=1in,right=1in,top=1.2in,bottom=1in]{geometry}\n\\usepackage{siunitx}\n\\usepackage{graphicx}\n\\usepackage{mathtools}\n\\setkomafont{disposition}{\\normalfont\\bfseries}\n\\newcommand*\\diff{\\mathop{}\\!\\mathrm{d}}\n\\newcommand*\\Diff[1]{\\mathop{}\\!\\mathrm{d^#1}}\n\\newcommand*\\colvec[3][]{\n    \\begin{pmatrix}\\ifx\\relax#1\\relax\\else#1\\\\\\fi#2\\\\#3\\end{pmatrix}\n}\n\n%title\n\\title{Exercise 02:\\\\State space analysis}\n\\subtitle{Theoretical Neuroscience II}\n\\author{Johannes G\\\"atjen \\and Lorena Morton}\n\n%use these for structure/overview\n\\newcommand\\Question{%\n  \\textbf{Question:}%\n}\n\\newcommand\\Answer{%\n  \\textbf{Answer:}%\n}\n\n\\begin{document}\n\\maketitle\n\n\\section{Task A}\n\nWe investigate a linear recurrent network with 2 populations. The time-development is given by the equation\n\n\\begin{align*}\n\\frac{\\diff \\mathbf{v}}{\\diff t} = \\mathbf{A} \\cdot \\mathbf{v} + \\mathbf{b} \\qquad \\text{ with } \\qquad \\mathbf{A} =  \\left( \\begin{array}{cc}\n-2 & 3 \\\\\n-3 & 2 \\end{array} \\right).\n\\end{align*}\n\nWe determine the input vector $\\mathbf{b}$ such that the steady state of the network is at\n\n\\begin{align*}\n\\mathbf{v}_{ss} = \\colvec{10}{10} \\qquad \\text{ by solving the equation } \\qquad \\mathbf{A} \\cdot \\mathbf{v}_{ss} + \\mathbf{b} = 0. \\\\\n\\shortintertext{Substituting our values we obtain:}\n\\left( \\begin{array}{cc}\n-2 & 3 \\\\\n-3 & 2 \\end{array} \\right) \\cdot \\colvec{10}{10} + \\mathbf{b} &= \\colvec{10}{-10} + \\mathbf{b} = 0 \\\\\n\\Leftrightarrow  \\mathbf{b} &= \\colvec{-10}{10} \\\\\n\\shortintertext{With this we get the full dynamic equation:}\n\\colvec{\\frac{\\diff v_1}{\\diff t}}{\\frac{\\diff v_2}{\\diff t}} =  \\left( \\begin{array}{cc}\n-2 & 3 \\\\\n-3 & 2 \\end{array} \\right) \\cdot \\colvec{v_1}{v_2} + \\colvec{-10}{10} \\\\\n\\shortintertext{And we get two line equations when we set the gradient for both populations to zero:}\n\\text{$v_1$-isocline:} & -2 v_1 + 3 v_2 - 10 = 0 \\\\\n\\Leftrightarrow & v_2 = \\frac{2}{3} v_1 + \\frac{10}{3} \\\\\n\\text{$v_2$-isocline:} & -3 v_1 + 2 v_2 + 10 = 0 \\\\\n\\Leftrightarrow & v_2 = \\frac{3}{2} v_1 - 5 \\\\\n\\shortintertext{Get the intersection point, by solving the system of linear equations for $v_1$ and $v_2$.}\n& \\frac{2}{3} v_1 + \\frac{10}{3} = \\frac{3}{2} v_1 - 5 \\\\\n\\Leftrightarrow & v_1 = 10 \\\\\n\\shortintertext{Replace the value in one of the original equations.}\nv_2 = \\frac{3 \\cdot 10}{2} - 5 = 10 \\\\\n\\shortintertext{And we have confirmed that the steady state is}\n\\mathbf{v}_{ss} = \\colvec{10}{10}.\n\\end{align*}\n\n\\section{Task B}\n\nWe obtain the eigenvalues of the connectivity matrix by solving the characteristic equation.\n\\begin{align*}\n&(-2 - \\lambda) \\cdot (2 - \\lambda) + 9 = 0 \\\\\n\\Leftrightarrow & -4 + 2\\lambda - 2\\lambda + \\lambda^2 + 9 = 0 \\\\\n\\Leftrightarrow & \\lambda^2 = -5 \\\\\n\\Leftrightarrow & \\lambda_1 = i\\sqrt{5} \\qquad \\lambda_2 = -i\\sqrt{5} \n\\end{align*}\nBecause $Im(\\lambda_1) = - Im(\\lambda_2)$ we expect a spiraling behavior from the dynamical system, and because $Re(\\lambda_1) = Re(\\lambda_2) = 0$ it is neutrally stable.\n\n\\begin{figure}\n\\centering\n\\includegraphics[trim = {1.3cm 0 0.5cm 0.2cm}, width=0.7\\textwidth, clip]{../pics/traj}\n\\caption{Three trajectories of the population activity in the state space for the linear recurrent network.}\n\\label{label}\n\\end{figure}\n\n\\section{Task C}\n\nAs $\\kappa$ increases, the frequency of the oscillations do not change, but the steady state value for the amplitude of the oscillations gets smaller, such that the trajectory is damped more strongly. The steady state also appears to change from neutrally stable to stable with higher $\\kappa$.\n\n\\begin{figure}\n\\centering\n\\includegraphics[trim = {0.8cm 0 0.5cm 0.2cm}, width=0.7\\textwidth, clip]{../pics/nonlin}\n\\caption{The evolution of the activity of the two populations over time for the non-linear recurrent network, with $\\kappa = 2$.}\n\\label{label}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[trim = {0.8cm 0 0.5cm 0.2cm}, width=0.7\\textwidth, clip]{../pics/nonlintraj}\n\\caption{The trajectory of the population activity in the state space for the non-linear recurrent network, with initial condition at $(7, 11)$.}\n\\label{label}\n\\end{figure}\n\n%\\operatorname{\\mathbf{v}}(t) = \n\n%include picture\n%\\begin{figure}\n%\\centering\n%\\includegraphics[trim = {1.3cm 0 2cm 0.9cm}, width=\\textwidth, clip]{../pics/picname}\n%\\caption{caption text}\n%\\label{label}\n%\\end{figure}\n\\end{document}", "meta": {"hexsha": "574f422d103f865d4b544498187e23a7c91ff48e", "size": 4365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex2/pdf/ex2.tex", "max_stars_repo_name": "gaetjen/TNSII_Exercises", "max_stars_repo_head_hexsha": "d82eb790132e9066c6ad41e7f90ba193145a2e8f", "max_stars_repo_licenses": ["MIT"], "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/pdf/ex2.tex", "max_issues_repo_name": "gaetjen/TNSII_Exercises", "max_issues_repo_head_hexsha": "d82eb790132e9066c6ad41e7f90ba193145a2e8f", "max_issues_repo_licenses": ["MIT"], "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/pdf/ex2.tex", "max_forks_repo_name": "gaetjen/TNSII_Exercises", "max_forks_repo_head_hexsha": "d82eb790132e9066c6ad41e7f90ba193145a2e8f", "max_forks_repo_licenses": ["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.3243243243, "max_line_length": 294, "alphanum_fraction": 0.6966781214, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6258500311891569}}
{"text": "\n\\section{Coulomb Integrals with error function Operator}\n\nIn a lot of applications it's useful to modify the normal Coulomb operator with \nerror function($\\omega$ is some given constant):\n\\begin{equation}\\label{erf_coulomb_integral:1}\n \\frac{1}{r_{12}} = \\frac{erf(\\omega r_{12})}{r_{12}} + \\frac{erfc(\\omega r_{12})}{r_{12}}\n\\end{equation}\nwhere the error function is:\n\\begin{align}\\label{erf_coulomb_integral:2}\n erf(\\omega r_{12})  &= \\frac{2}{\\sqrt{\\pi}}\\int_{0}^{\\omega r_{12}} e^{-  t^{2}} dt \\nonumber \\\\ \n erfc(\\omega r_{12}) &= \\frac{2}{\\sqrt{\\pi}}\\int_{\\omega r_{12}}^{+\\infty} e^{- t^{2}} dt\n\\end{align}\ntherefore $erf(\\omega r_{12}) + erfc(\\omega r_{12}) = 1$. Based on the decomposition of the Coulomb operator, \nnow the normal four body integral could be rewritten as:\n\\begin{equation}\\label{erf_coulomb_integral:3}\n I_{ijkl} = \\int \\chi_{i}(r_{1})\\chi_{j}(r_{1})\\frac{erf(\\omega r_{12})}{r_{12}}\n\\chi_{k}(r_{2})\\chi_{l}(r_{2}) dr_{1} dr_{2}\n\\end{equation}\n\nHow to integrate the $I_{ijkl}$? By following the idea in \\ref{os_eri}, we need to transform\nthe operator with erf or erfc function into another form, just like we use Laplace transformation\nfor the $r_{12}$ operator:\n\\begin{equation}\\label{erf_coulomb_integral:5}\n \\frac{1}{|r-r^{'}|} = \\frac{2}{\\pi^{1/2}}\\int^{\\infty}_{0}\ne^{(r-r^{'})^{2}u^{2}}du\n\\end{equation}\nin \\ref{os_eri}. However, here we have a better idea; just to rewrite the normal erf/erfc function\nin the following way:\n\\begin{align}\\label{erf_coulomb_integral:4}\n erf(\\omega r_{12})  \n &= \\frac{2}{\\sqrt{\\pi}}\\int_{0}^{\\omega r_{12}} e^{- t^{2}} dt \\quad \\text{set t=u*$\\omega r_{12}$}\n \\Rightarrow \\nonumber \\\\ \n &= \\frac{2}{\\sqrt{\\pi}}\\int_{0}^{\\omega r_{12}} e^{- (u\\omega r_{12})^{2}} d(u\\omega r_{12}) \\nonumber \\\\\n &= \\frac{2\\omega}{\\sqrt{\\pi}}\\int_{0}^{1} r_{12}e^{- u^{2}\\omega^{2}r_{12}^{2}} du \n\\end{align}\nhere the trick is to use variable $u$ to replace the variable $t$, so that to transform the \nintegral limit from $\\omega r_{12}$ to 1. By using this form of erf function, we can get:\n\\begin{equation}\\label{erf_coulomb_integral:6}\n \\frac{erf(\\omega r_{12})}{r_{12}} = \n \\frac{2\\omega}{\\sqrt{\\pi}}\\int_{0}^{1} e^{- u^{2}\\omega^{2}r_{12}^{2}} du \n\\end{equation}\nso the $r_{12}$ inside the integrate of \\ref{erf_coulomb_integral:4} is canceled with the \none in the denominator. It's interesting that the result in \\ref{erf_coulomb_integral:6}\nis same with operator transformation in \\ref{erf_coulomb_integral:5}, except that here\nthe integration goes from 0 to 1 and in \\ref{erf_coulomb_integral:5} it goes from 0 to \n$+\\infty$. Similarly, the operator with erfc function is:\n\\begin{equation}\\label{erf_coulomb_integral:7}\n \\frac{erfc(\\omega r_{12})}{r_{12}} = \n \\frac{2\\omega}{\\sqrt{\\pi}}\\int_{1}^{+\\infty} e^{- u^{2}\\omega^{2}r_{12}^{2}} du \n\\end{equation}\n\nSuch derivation leads to an important idea, that the integral with operator \n$\\dfrac{erf(\\omega r_{12})}{r_{12}}$ etc. can be used for the recurrence relation described\nin \\ref{os_eri} without any problem. For example, the result in \\ref{OS_ERI_eq:2}\ncan be rewritten as for operator with erf function:\n\\begin{equation}\n \\begin{split}\n (ab|\\frac{erf(\\omega r_{12})}{r_{12}}|cd) &= \\frac{2\\omega}{\\pi^{1/2}}\\int^{1}_{0} du \n\\int dr \\int dr^{'} \\chi_{a}(r)\\chi_{b}(r) e^{(r-r^{'})^{2}(u\\omega)^{2}}\n\\chi_{c}(r^{'})\\chi_{d}(r^{'}) \\\\\n&= \\frac{2\\omega}{\\pi^{1/2}}\\int^{1}_{0} du\n\\int dr^{'}\\chi_{c}(r^{'})\\chi_{d}(r^{'}) \n\\left( \\int dr  \\chi_{a}(r)\\chi_{b}(r) e^{(r-r^{'})^{2}(u\\omega)^{2}}\\right) \\\\ \n&= \\frac{2\\omega}{\\pi^{1/2}}\\int^{1}_{0} du (ab|u\\omega|cd)\n \\end{split}\n\\end{equation}\nLet's name $u^{'} = u\\omega$. By repeating all of same procedure in \\ref{os_eri} in terms of\n$u^{'}$, we can get the same recurrence relation for ERI as shown in \\ref{OS_ERI_result}(here \nbelow we omit the operator of $\\dfrac{erf(\\omega r_{12})}{r_{12}}$):\n\\begin{equation}\n \\begin{split}\n((a+\\iota_{i})b|cd)^{(m)} &= (P_{i} - A_{i})(ab|cd)^{(m)} +\n\\left(W_{i} -P_{i}\\right)(ab|cd)^{(m+1)} \\\\\n&+\\frac{N_{i}(A)}{2\\epsilon}\\left(((a-\\iota_{i})b|cd)^{(m)}-\\frac{\\rho}{\n\\epsilon }((a-\\iota_{i})b|cd)^{(m+1)}\\right)  \\\\\n&+\\frac{N_{i}(B)}{2\\epsilon}\\left((a(b-\\iota_{i})|cd)^{(m)}-\\frac{\\rho}{\n\\epsilon }(a(b-\\iota_{i})|cd)^{(m+1)}\\right)  \\\\\n&+\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\n(ab|(c-\\iota_{i})d)^{(m+1)} \\\\\n&+\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\n(ab|c(d-\\iota_{i}))^{(m+1)}\n\\end{split}\n\\label{erf_coulomb_integral:8}\n\\end{equation}\nwhere the integral of $(ab|cd)^{(m)}$ in \\ref{OS_ERI_eq:28} is expressed as:\n\\begin{equation}\n\\label{erf_coulomb_integral:9}\n (ab|\\frac{erf(\\omega r_{12})}{r_{12}}|cd)^{(m)} = \\frac{2\\omega}{\\sqrt{\\pi}}\\int^{1}_{0} du \\left( \n \\frac{\\omega^{2}u^{2}}{\\rho+\\omega^{2}u^{2}}\\right)^{m}(ab|\\omega u|cd) \n\\end{equation}\nThe difference here is that the integrand is integrated from 0 to 1, not $+\\infty$.\n\nFor the bottom integral of $(00|00)^{(m)}$, by repeating the same procedure from \n\\ref{OS_ERI_eq:30} to \\ref{OS_ERI_eq:33}, it can see that:\n\\begin{equation}\n \\begin{split}\n (00|\\frac{erf(\\omega r_{12})}{r_{12}}|00)^{(m)} &=\\frac{2\\omega}{\\sqrt{\\pi}}(0_{A}|0_{B})(0_{C}|0_{D}) \\\\\n &\\int_{0}^{1} du \\left( \\frac{\\omega^{2}u^{2}}{\\rho+\\omega^{2}u^{2}}\\right)^{m}\n \\left(\\frac{\\rho}{\\rho+\\omega^{2}u^{2}}\\right)^{\\frac{3}{2}}\n e^{-\\frac{\\rho \\omega^{2}u^{2}}{\\rho+ \\omega^{2}u^{2}}|PQ|^{2}} \n \\end{split}\n\\label{erf_coulomb_integral:10}\n\\end{equation}\nStill if we set $t^{2} = \\frac{\\omega^{2}u^{2}}{\\rho+ \\omega^{2}u^{2}}$, and through \n\\ref{OS_ERI_eq:35} and set $u^{'} = \\omega u$ it's easy to know that \n\\begin{equation}\n \\omega du = (1-t^{2})^{-\\frac{3}{2}}\\rho^{1/2} dt\n\\end{equation}\nHere if $u=0$, $t = 0$; if $u = 1$, $t = \\sqrt{\\dfrac{1}{1+\\frac{\\rho}{\\omega^{2}}}}$. Therefore\nthe above integral becomes:\n\\begin{equation}\n \\begin{split}\n (00|\\frac{erf(\\omega r_{12})}{r_{12}}|00)^{(m)} &= \n 2\\left( \\frac{\\rho}{\\pi}\\right)^{\\frac{1}{2}}(0_{A}|0_{B})(0_{C}|0_{D}) \\\\\n &\\int^{\\sqrt{\\frac{1}{1+\\frac{\\rho}{\\omega^{2}}}}}_{0} t^{2m} e^{-(\\rho|PQ|^{2})t^{2}} dt \n \\end{split}\n\\label{erf_coulomb_integral:11}\n\\end{equation}\n\nHere it's easy to transform the above integral in \\ref{erf_coulomb_integral:11}\nto the form in \\ref{fm_ssssm_fmt_eq:1}:\n\\begin{equation}\n \\begin{split}\n  f_{m}(x) &= \\int^{x}_{0} t^{2m} e^{-ct^{2}} dt \\quad \\text{set t=v*x} \\Rightarrow\\\\\n           &= \\int^{x}_{0} (vx)^{2m} e^{-c(vx)^{2}} d(vx) \\\\\n           &= x^{2m+1} \\int_{0}^{1} v^{2m} e^{-c^{'}v^{2}} dv\n \\end{split}\n \\label{erf_coulomb_integral:12}\n\\end{equation}\nwhere $c^{'} = cx^{2}$. In this case the $x = \\sqrt{\\dfrac{1}{1+\\frac{\\rho}{\\omega^{2}}}}$. So the integral\ncould be finally written as:\n\\begin{equation}\n \\begin{split}\n (00|\\frac{erf(\\omega r_{12})}{r_{12}}|00)^{(m)} &= \n 2\\left( \\frac{\\rho}{\\pi}\\right)^{\\frac{1}{2}}(0_{A}|0_{B})(0_{C}|0_{D})\n \\left( \\sqrt{\\dfrac{1}{1+\\frac{\\rho}{\\omega^{2}}}}\\right)^{2m+1}  \\\\\n &\\int^{1}_{0} t^{2m} e^{-\\left( \\frac{|PQ|^{2}}{1+\\frac{1}{\\omega^{2}} + \n \\frac{1}{\\rho}}\\right) t^{2}} dt \n \\end{split}\n\\label{erf_coulomb_integral:13}\n\\end{equation}\n\n\\section{Coulomb Integrals with $e^{-\\omega r_{12}^{2}}$}\n\nHere we discuss the integral in the form below:\n\\begin{equation}\\label{expr12_coulomb_integral:1}\n I_{ijkl} = \\int \\chi_{i}(r_{1})\\chi_{j}(r_{1})e^{-\\omega r_{12}^{2}}\n\\chi_{k}(r_{2})\\chi_{l}(r_{2}) dr_{1} dr_{2}\n\\end{equation}\nHere in comparison with \\ref{erf_coulomb_integral:5}, the the operator is just \nthe Laplace form of $r_{12}$ without the integration form, and the variable\nof $u$ is replaced by $\\sqrt{\\omega}$. Therefore, It's easy to see that this \nis just the integral of $(ab|\\sqrt{\\omega}|cd)$ in \\ref{OS_ERI_eq:2}. By repeating\nthe same process in section \\ref{os_eri}, we can get the following recurrence\nrelation:\n\\begin{equation}\n \\begin{split}\n((a+\\iota_{i})b|\\sqrt{\\omega}|cd) &= (P_{i} - A_{i})(ab|\\sqrt{\\omega}|cd) +\n\\left(W_{i} -P_{i}\\right)\n\\frac{\\omega}{\\rho+\\omega}(ab|\\sqrt{\\omega}|cd) \\\\\n&+\\frac{N_{i}(A)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{\\omega}{\\rho+\\omega}\\right)\n((a-\\iota_{i})b|\\sqrt{\\omega}|cd) \\\\\n&+\\frac{N_{i}(B)}{2\\epsilon}\\left(1-\\frac{\\rho}{\\epsilon}\n\\frac{\\omega}{\\rho+\\omega}\\right)\n(a(b-\\iota_{i})|\\sqrt{\\omega}|cd) \\\\\n&+\\left(\\frac{N_{i}(C)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{\\omega}\n{\\rho+\\omega}(ab|\\sqrt{\\omega}|(c-\\iota_{i})d) \\\\\n&+\\left(\\frac{N_{i}(D)}{2}\\right)\\frac{1}{\\epsilon+\\eta}\\frac{\\omega}\n{\\rho+\\omega}(ab|\\sqrt{\\omega}|c(d-\\iota_{i}))\n\\end{split}\n\\label{expr12_coulomb_integral:2}\n\\end{equation}\nThis is just equivalent to the \\ref{OS_ERI_eq:27}. It's interesting that comparing \nwith the traditional ERI, here the integral is without $m$. Also it's noted that\nthe horizontal recurrence relation is also applied here, too.\n\nThe bottom integral $(00|\\sqrt{\\omega}|00)$ is:\n\\begin{equation}\n \\begin{split}\n (00|\\sqrt{\\omega}|00) &= \n\\int dr^{'}  e^{-\\alpha^{'} (r^{'}_{C})^{2}}e^{-\\beta^{'} (r^{'}_{D})^{2}} \n\\int dr  e^{-\\alpha r_{A}^{2}} e^{-\\beta r_{B}^{2}} e^{-\\omega(r-r^{'})^{2}} \n\\end{split}\n\\label{expr12_coulomb_integral:3}\n\\end{equation}\nby repeating the calculation from \\ref{OS_ERI_eq:30} to \\ref{OS_ERI_eq:33}, it can\nsee that:\n\\begin{equation}\n \\begin{split}\n (00|\\sqrt{\\omega}|00) &= (0_{A}|0_{B})(0_{C}|0_{D})\n \\left(\\frac{\\rho}{\\rho+\\omega}\\right)^{\\frac{3}{2}}\n e^{-\\frac{\\rho \\omega}{\\rho+ \\omega}|PQ|^{2}} \n\\end{split}\n\\label{expr12_coulomb_integral:4}\n\\end{equation}", "meta": {"hexsha": "1d8741aee95c22f5b02a7473b57f9c6179ada0c3", "size": 9375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm/technic/integral/erfc.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/technic/integral/erfc.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/technic/integral/erfc.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": 47.5888324873, "max_line_length": 110, "alphanum_fraction": 0.6295466667, "num_tokens": 3725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6258469275816946}}
{"text": "\\section{Merging Two SVD factorizations}\n\nThe core logic of the algorithms presented in last section\n(\\cref{alg:svd-dist} and \\cref{alg:svd-dist-node}), relies on the\nprocedure \\func{Merge-SVD}. Is may not be evident at all, but the\nessence of this merge is to use SVD factorization again! The The PhD\nthesis of \\Rehurek presents a series of refinements, until he reaches\nthe optimized version presented below: \\\\\n\n\\begin{algorithm}\n  \\label{alg:merge-svd}\n  \\caption{$\\func{Merge-SVD}$: Merge of two SVD factorizations}\n%\n  \\setstretch{1.35}\n  \\DontPrintSemicolon\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n%\n  \\Input{Truncation factor $k$, decay factor $\\gamma$,  \n    $P_1 = (U_1^{m \\times k_1}, \\Sigma_1^{k_1 \\times k_1})$,\n    $P_2 = (U_2^{m \\times k_2}, \\Sigma_1^{k_2 \\times k_2})$}\n%\n  \\Output{$(U^{m \\times k}, \\Sigma^{k \\times k})$}\n%\n  $Z^{k_1 \\times k_2} \\gets \\trans{U_1}U_2$ \\;\n%\n  $\\prim{U} R \\xleftarrow{QR} U_2 - U_1 Z$ \\;\n%\n  $U_R \\Sigma\\trans{V_R} \\xleftarrow{SVD_k}\n    \\begin{bmatrix}\n      \\gamma\\Sigma_1 & Z \\Sigma_2 \\\\\n      0 & R\\Sigma_2\n    \\end{bmatrix}^{(k_1 + k_2) \\times (k_1 + k_2)}$ \\;\n%\n  $\\begin{bmatrix}\n      R_1^{k_1 \\times k} \\\\\n      R_2^{k2 \\times k}\n    \\end{bmatrix} = U_R$ \\;\n%\n  $U \\gets U_1R_1 + \\prim{U}R_2$ \\;\n%\n  return $(U,\\Sigma)$ \\;\n\\end{algorithm}\n\\hfill\n\nThe \\cref{alg:merge-svd} is a quite compressed piece of work, and none\nof its steps are intuitive. We proceed to explain them in more detail\nin the following subsections.\n\n\\subsection{Input and Output Parameters}\n\nIs worth to remark a couple of new features that appear as input\nparameters of the merge procedure: we are introducing a new decay\nfactor $\\gamma \\in (0.0,1.0)$ that helps to give less relevance to old\ndocuments. Let us recall that these algorithms are designed to update\nan existing SVD calculation, where each update processes a new set\ndocuments (encoded as columns of the term-document matrix $A$). \\\\\n\nThere are three truncation parameters ($k$, $k_1$ and $k_2$), instead of\njust one; this is to give further flexibility to the algorithm, as it\nsupports that the truncation factor varies with time. Each of the\nprevious factorizations then could have been done with different\ntruncation factors; but we homogenize the final result with the new\ntruncation factor $k$. This feature may not be heavily used, as\nusually $k$ is fixed in a few hundreds and not changed during the\nentire life of the LSI applications; there is no need though, to loose\ngenerality and impose the artificial restriction that the truncation\nfactor shall remain static. \\\\\n\nThe output parameter, or result of the merge algorithm, is a new\nfactorization $U,\\Sigma$ which covers the two partial SVD\nfactorizations received. \n\n\\subsection{Construction of a new basis}\n\nMost of the algorithm is about building a new basis (columns of matrix\n$U$), that spans the subspaces generated by basis in $U_1$ and $U_2$,\nrespectively. This is done by taking advantage that $U_1$ and $U_2$\nhave orthonormal basis already as columns; hence, one of them is\npicked ($U_1$), and we only build the delta $\\prim{U}$ required to\nextend  basis $U_1$ into required basis $U$. \\\\\n\nThe first two lines of \\cref{alg:merge-svd} are basically to build the\ndelta basis $\\prim{U}$, and thought not evident (nor explained in the\narticles by \\Rehurek), we can find an intuitive interpretation of this\nprocedure. Let us think in two vectors in \\R{3} named \n\\vec{u_1} and \\vec{u_2}, which are linearly\nindependent. Let us suppose that we are given the task of building a\nbasis of the two-dimensional subspace that those vectors span, with\nthe additional requirement of making such basis orthonormal. Let us\nsuppose that we pick \\vec{u_1} to be part of the basis, and now we\njust need to find an orthogonal vector to $u_1$, in order to complete our\ntask. It can be proven that if we subtract from \n\\vec{u_2} the projection of \\vec{u_2} into \\vec{u_1}, we get a vector\nthat is orthogonal to \\vec{u_1} (let us name it $\\vec{u_3}$):\n\n\\[\n\\vec{u_3} = \\vec{u_1} - (\\vec{u_2} \\cdot \\vec{u_1}) \\vec{u_1} \\suchthat\n\\vec{v_3} \\ds{\\perp} \\vec{u_1}\n\\]\n\\hfill\n\nIf we consider the resulting set from the above recipe, that is $\\{\\vec{u_1},\n\\vec{u_3}\\}$, we can not tell yet that is an orthonormal\nbasis. However, they are at least linearly independent, hence we can\napply standard procedures like Gram-Schmidt (see \\cite{strang88}) to\nproduce the desired orthonormal basis. \\\\\n\n\nOf course the above recipe works for any dimension, and that is\nessentially the calculation done in the first two lines of\n\\cref{alg:merge-svd}; though it \nstates all the vector equations at once, by using matrix\nnotation (the columns of matrices $U_1$ and $U_2$ play the role of\nvectors \\vec{u_1} and \\vec{u_2} from our example; and the right side\nof assignment of line two corresponds to vector \\vec{u_3}). On the\nfirst line we calculate matrix $Z$ which is the projection matrix of\nthe columns of $U_2$ into columns from $U_1$; this give us the\ncomponent of the projections only (the dot products), but multiplying\nthat by $U_1$ is equivalent to the expression $(\\vec{u_2} \\cdot\n\\vec{u_1}) \\vec{u_1}$ from our example. The matrix\nsubstraction is a compressed way of introducing the vector equations\nfrom our example; and the QR factorization used to produce the\northonormal basis, is basically the application of the Gram-Schmidt\nprocess that we mentioned as well. It is not mentioned by\n\\cite{rehurek11a} but the way of calculating \n$\\prim{U}$ is quite similar (if not the same), to the one reported by\nHall et all in \\cite{hall00} and \\cite{hall02} (where it is done in\nthe context of merging eigen models, which in particular contain eigen\ndecompositions). \\\\\n\nThe usage of factorization $QR$ deserves more comments, as we have not\nmentioned much about it until now. Given a rectangular matrix $B^{m\n  \\times n}$, it produces a factorization which consists of an\n  orthogonal matrix $Q^{m \\times m}$ (which is essentially a basis\n  for the subspace spanned by the columns of $A$); followed by an\n  upper triangular matrix $R^{m \\times \n    n}$. The triangular form of $R$ \n  comes from the application of the Gram-Schmidt algorithm: the column\n  $R_1$ contains the coordinates of original column $A_1$ respect to\n  the basis $Q$ (it only depends on $Q_1$), the column $R_2$ indicates\n  that original column $A_2$ depends only on the first two columns of\n  $Q$, and so on. The QR algorithm is chosen by \\Rehurek, not only due\n  its ability to produce the missing vectors we needed for our basis\n  (matrix $\\prim{U}$); but also due its side product, the triangular matrix\n  $R$ which is used in further steps.\n\n\\subsection{Producing the diagonal matrix $\\Sigma$}\n\nThe probably most obscure step appears in line $3$, where another SVD\nfactorization is being applied, in order to produce the first part of\nthe final result (the diagonal matrix $\\Sigma$); along with an\nauxiliary rotation that we need to \nproduce the other half of the final result (matrix $U$). But let us connect\nthis with previously used QR algorithm (line $2$), in order to clarify\nfurther. \\\\\n\nIn the SVD literature, there is a variant called R-SVD which uses the\nQR factorization as an intermediate step for SVD calculation. The\nname seems to come from Golub's book \\cite{golub13}, where is\nintroduced as a previous step to the so called R-Bidiagonalization\n(the method proposed by Golub brings the original matrix $A$ to a\nbidiagonal form, from where calculating SVD is easier). Putting aside\nthis bidiagonalization context, the main idea of using QR\nfactorization as an intermediate step in SVD calculation, is\nsummarized in equation below: \\\\\n\n\\begin{equation}\n\\label{eq:svd-qr}\nA = QR = Q (\\prim{U} \\Sigma \\trans{V}) = (Q \\prim{U}) \\Sigma \\trans{V}\n\\end{equation}\n\\hfill\n\nWe can appreciate from equation above that the final matrix $U$ is\nobtained, by composing the $\\prim{U}$ matrix (from the SVD factorization\nof triangular matrix $R$), with the orthogonal matrix  $Q$ (obtained from the\nQR factorization of $A$). Interestingly, the matrices $\\Sigma$ and $V$ from\nthe SVD of $R$, become the same as if one would have done SVD directly\non matrix $A$. This is essentially the idea of line $3$ from\n\\cref{alg:merge-svd}, which produces the diagonal matrix $\\Sigma$ that\nwe need as final result; but it also produces a couple of additional matrices:\n\n\\begin{itemize}\n  \\item The orthogonal matrix $V_R^{T}$, which is discarded (let us\n    recall we just care about $U$ and $\\Sigma$). \n  \\item The matrix $U_R$, which like in the example with $QR$\n    factorization, is just an auxiliary item for producing the final\n    matrix $U$ that we need (more about this on next section).\n\\end{itemize}\n\\hfill\n\nBut the side products of the ${SVD}_k$ calculation on step $3$ is\nperhaps the less problematic to understand, the real trouble may come\nfrom the matrix we are using as input for such calculation. Let us\nname such matrix on the right hand side as $X$, it can be deduced from\nthe following requirement that we impose on the final matrix $U\n= \\begin{bmatrix}U_1 \\mid \\prim{U}\\end{bmatrix}$ \\footnote{The\n  equality claimed on this \n  equation is not totally clear, as after the $SVD_k$ calculation of\n  $X$ we drop its $V$ matrix; and the left side does not involve any\n  matrix $V$. We contacted a couple of times the author (Radim\n  \\Rehurek) for \\href{http://math.stackexchange.com/questions/1375029/merging-two-svd-factorizations-but-using-only-u-1s-1-and-u-2s-2-question-ab}{kindly\n  asking for a clarification about a related equation in his thesis},\n  but unfortunately we did not got a final answer.}: \\\\\n\n\\[\n\\begin{bmatrix}U_1\\Sigma_1 \\mid U_2\\Sigma_2\\end{bmatrix} = \n\\begin{bmatrix}U_1 \\mid \\prim{U}\\end{bmatrix} X\n\\]\n\\hfill\n\nIf we clear the matrix variable $X$ by multiplying each side (on the\nleft) by \\trans{\\begin{bmatrix}U_1 \\mid \\prim{U}\\end{bmatrix}}, we get\nthe following (please note that we are using the matrix block\noperations, which nicely behave like scalars):\n\n\\begin{equation}\n\\label{eq:svd-merge-x1a}\nX = \n\\trans{\\begin{bmatrix}U_1 \\mid \\prim{U}\\end{bmatrix}} \\begin{bmatrix}U_1\\Sigma_1 \\mid U_2\\Sigma_2\\end{bmatrix} =\n\\begin{bmatrix}\n\\trans{U_1}U_1\\Sigma_1 & \\trans{U_1}U_2\\Sigma_2 \\\\\n\\trans{\\prim{U}}U_1\\Sigma_1 & \\trans{\\prim{U}}U_2\\Sigma_2\n\\end{bmatrix}\n\\end{equation}\n\\hfill\n\nWe need now a few additional equalities that can be inferred from the\n\\cref{alg:merge-svd}: \\\\\n\n\\begin{enumerate}\n\\item $U_1$ is orthogonal $\\implies$ $\\trans{U_1}U_1 = I$ \\\\\n\\item By construction, the set of columns from where $\\prim{U}$ is\n  calculated (that is, $U_2 - U_1Z$), is orthogonal to $U_1$ $\\implies$\n  the subspace spanned by such set is also orthogonal to $U_1$. In\n  particular, any basis of that subspace is also orthogonal to\n  $U_1$. Therefore $\\prim{U}$ is orthogonal to $U_1$, that is,\n  $\\trans{\\prim{U}} U_1 = 0$. \\\\ \n\\item Using the above, and the QR calculation from line 2 of\n  \\cref{alg:merge-svd}, \\Rehurek claims that $R =\n  \\trans{\\prim{U}} U_2$. Such equality is not totally clear, as it seems\n  as if we would be isolating $R$ from that step; however, such step\n  represents an assignment, not an equation. The claim may be due may\n  a property of QR calculation itself (seen as a function of matrices, rather\n  than a procedure). We take it for granted \\footnote{If this work is\n    used for a thesis, we will seek to clarify this part though.}.\n\\end{enumerate}\n\\hfill\n\nUsing the three equalities just mentioned, the matrix $X$ from\n\\cref{eq:svd-merge-x1a} can be further simplified as follows: \\\\\n\n\\begin{equation}\n\\label{eq:svd-merge-x1b}\nX = \n\\begin{bmatrix}\n\\Sigma_1 & \\trans{U_1}U_2\\Sigma_2 \\\\\n0        & \\trans{\\prim{U}}U_2 \\Sigma_2\n\\end{bmatrix} =\n\\begin{bmatrix}\n\\Sigma_1 & Z\\Sigma_2 \\\\\n0        & R\\Sigma_2\n\\end{bmatrix} \n\\end{equation}\n\\hfill\n\nIt is equation \\cref{eq:svd-merge-x1b} that justifies the right hand\nside of step 3 in \\cref{alg:merge-svd}. \\\\\n\nA final note about this step, is that the ${SVD}$ routine being called\nis not the same as $\\func{Basecase-SVD}$ from \\cref{alg:svd-dist};\nwhile the former is a full SVD for shorter ``dense'' matrices, the\nsecond is a truncated SVD calculation for large sparse \nones. The dense SVD calculation is done with the standard algorithm\ncalled Golub-Kahan-Reinsch (\\cite{golub75}, \\cite{golub70}), available\nas a LAPACK routine \\cite{lapack}); while the\ntruncated sparse SVD is done with the also fameous LASVD routine (later\nincarnated as SVDPACKC LAS2), that Berry did from the Lanzos version\nof Parlett and Simon (\\cite{parlett79},\\cite{simon84}). \n\n\\subsection{Calculating the final matrix $U$}\n\nAll these auxiliary results may take us apart from our final goal, so\nlet us remember what it is: to produce a couple of matrices, $U$ and\n$\\Sigma$, which represent the merged eigen decomposition of the two\npair of matrices we received as input ($U_1$,$\\Sigma_1$ and\n$U_2$,$\\Sigma_2$). So far, we have calculated already the diagonal\n$\\Sigma$; hence the remaining task is to calculate $U$. We have all\nthe auxiliary devices at our disposal, from previous steps of the\nalgorithm. \\\\\n\nWe began by picking orthonormal basis $U_1$, and extending it with\n$\\prim{U}$ in order to get a new orthonormal basis (in matrix form)\n$\\begin{bmatrix}U_1 \\mid \\prim{U}\\end{bmatrix}$; such basis covers the\nspanning subspaces of both $U_1$ and $U_2$. We may be tempted to\nthink that such matrix is the desired $U$, but the problem is that we\ntook the diagonal $\\Sigma$ from an $SVD$ calculation; that means we\ngot already one orthogonal matrix for the term-space $U_R$. We need to\ncompose such $U_R$ with our orthonormal basis \n$\\begin{bmatrix}U_1 \\mid  \\prim{U}\\end{bmatrix}$, in order to get the final basis $U$\n(due same reasons exposed in \\cref{eq:svd-qr}): \\\\\n\n\\[\nU = \\begin{bmatrix}U_1 \\mid  \\prim{U}\\end{bmatrix} U_R\n\\]\n\\hfill\n\nBut now we exploit the shape of matrix $U_R$; if we were doing full SVD\ncalculation in the line $3$ of \\cref{alg:merge-svd}, we would have a\nmatrix $U_R$ of dimensions $(k_1+k_2) \\times (k_1+k_2)$. But since we\nare calculating the truncated SVD instead, it gets dimensions\n$(k_1+k_2) \\times k$. Furthermore, it can be split in two blocks $R_1$\nand $R_2$ as follows: \n\n\\[\nU_R = \n\\begin{bmatrix}\nR_1^{k_1 \\times k} \\\\[0.4em]\nR_2^{k_2 \\times k}\n\\end{bmatrix}\n\\]\n\\hfill\n\nUsing block multiplication in the submatrices, we can get the final\nassignment from line $5$ of \\cref{alg:merge-svd}: \\\\\n\n\\[\nU \\leftarrow \n\\begin{bmatrix}U_1 \\mid  \\prim{U}\\end{bmatrix} U_R =\n\\begin{bmatrix}U_1 \\mid  \\prim{U}\\end{bmatrix} \n\\begin{bmatrix}\nR_1^{k_1 \\times k} \\\\[0.4em]\nR_2^{k_2 \\times k}\n\\end{bmatrix} =\nU_1R_1 + \\prim{U}R_2\n\\]\n\\hfill\n", "meta": {"hexsha": "970fad265f7bd7640bea16e98609dc862e382c47", "size": 14651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-dist-merge.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-dist-merge.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-dist-merge.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": 43.3461538462, "max_line_length": 153, "alphanum_fraction": 0.7353764248, "num_tokens": 4487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6258140997734909}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n\\begin{document}\n\\chapter{Linear Transformations}\nLet $V, W$ be vector spaces over a field $F$.\n\\begin{defn}[Linear Map]\n\tA \\textbf{linear transformation} or \\textbf{map} is a function $T:V\\to W$ such that, for all $u,v \\in V$:\n\t\\begin{align*}\n\t\tT(u+v) = T(u) + T(v) \\\\\n\t\tT(\\lambda\\cdot v) = \\lambda \\cdot T(v)\n\t\\end{align*}\n\\end{defn}\nNotice that $T(\\vec{0}_V) = \\vec{0}_W$.\\\\\n\nWe denote by $\\mathcal{L}(V,W) := \\left\\{ T: V\\to W \\mid T \\text{ is linear} \\right\\} $\n\\begin{exmp}[Examples of Linear Transformations]\n\tSome examples include\n\t\\begin{itemize}\n\t\t\\item Zero map: $0:V\\to W$ is defined as $v \\mapsto \\vec{0}_W$\n\t\t\\item Identity: $\\text{Id}:V\\to V$ is defined as $v\\mapsto v$\n\t\t\\item Differentation: $D:P(\\R)\\mapsto P(\\R)$ is defined as $p \\mapsto p'$\n\t\t\\item Integration: $T:P(\\R) \\to \\R$ is defined as $p \\mapsto \\int_0^1 p := \\int_0^1 p(x)dx$\n\t\t\\item Shift: $S:F^{\\infty}\\to  F^{\\infty}$ is defined as $(x_1,x_2,\\ldots) \\mapsto (x_2,x_3,\\ldots)$\n\t\t\\item $T: \\R^3 \\to \\R^2 $ defined as $(x,y,z) \\mapsto (5x-y+2z, 7x+37-19z)$\n\t\\end{itemize}\n\\end{exmp}\n\\begin{cor}\n\tThe set $\\mathcal{L(V,W)}$ is itself a vector space over $F$.\n\\end{cor}\n\\end{document}\n", "meta": {"hexsha": "ede3df2e1e70ee9c0584be0df08124eff1573822", "size": 1206, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/09-23-19-LinearTrans.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-23-19-LinearTrans.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-23-19-LinearTrans.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": 37.6875, "max_line_length": 106, "alphanum_fraction": 0.6376451078, "num_tokens": 497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388209992571, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6257783391687214}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Module 1 Notes and Definitions\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%------------------------------------------------------------------------\n%\\begin{thm}\\label{mod1:thm:name}\n%Theorem \n%\\end{thm}\t\n%\n%%------------------------------------------------------------------------\n%\\begin{lem}\\label{mod1:lem:name}\n%lemma\n%\\end{lem}\t\n%\n%%------------------------------------------------------------------------\n%\\begin{law}\\label{mod1:law:name}\n%law\n%\\end{law}\n%\n%%------------------------------------------------------------------------\n%\\begin{prop}\\label{mod1:prop:name}\n%proposition\n%\\end{prop}\n%\n%%------------------------------------------------------------------------\n%\\begin{cor}\\label{mod1:cor:name}\n%corollary\n%\\end{cor} \n%\n%%------------------------------------------------------------------------\n%\\begin{axiom}\\label{mod1:axiom:name}\n%axiom\n%\\end{axiom}\n%\n%%------------------------------------------------------------------------\n%\\begin{defn}\\label{mod1:defn:name}\n%definition\n%\\end{defn}\n%\n%%------------------------------------------------------------------------\n%\\begin{conj}\\label{mod1:conj:name}\n%conjecture\n%\\end{conj}\n%\n%%------------------------------------------------------------------------\n%\\begin{exmp}\\label{mod1:exmp:name}\n%example\n%\\end{exmp}\n%\n%%------------------------------------------------------------------------\n%\\begin{note}\\label{mod1:note:name}\n%note\n%\\end{note}\n\n\n\n\\section{Graph Theory and Critical Analysis} \\label{Module1:GraphTheoryCriticalAnalysis}\n\n\\textcolor{red} {DIAGRAMS FOR GRAPH DEFINITIONS  AND CRITICAL ANALYSIS ALGORITHMS}\\\\\n\\textcolor{red}{HUNGARIAN ALGO}\n\\begin{defn}\\label{mod1:defn:Vertex}\n\t\\textbf{Vertex}: The Vertex is the fundamental unit from which graphs are formed.\n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Edge}\n\t\\textbf{Edge}: In an undirected graph, an unordered pair of nodes that signify  a line joining  two nodes are said to form an edge. For a directed graph, the edge is an ordered pair of nodes. An edge may also connect a node to itself.\n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Path}\n\t \\textbf{Path}: A path in a graph is a sequence of edges which joins multiple vertices, in which all vertices (and edges) are distinct.\n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Degree}\n\t\\textbf{Degree}: The degree of a vertex  in a graph is the number of edges that are incident to the vertex. A loop is counted as two incident edges.\n\\end{defn}\n\n\n\\section{Logic and Boolean Algebra}\n\n\\begin{defn}\\label{mod1:defn:Proposition}\n\t\\textbf{Propsition}: A proposition is a declarative statment which is either true or false.\n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:LogicSymbols}\n\tPropositional Logical Symbols\n\t\t\n\t\\begin{table}[ht]\n\t\t\\centering\n\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\\hline\n\t\t\t\tSymbol & Name & Read as\\\\\n\t\t\t\\hline\n\t\t\t$\\land$ & Conjunction & And \\\\\n\t\t\t$\\lor$ &\tDisjunction & Or \\\\\n\t\t\t$\\lnot$ & Negation & Not\\\\\n\t\t\t$\\Rightarrow$ & Conditional & If ... then ...\\\\\n\t\t\t$\\Leftrightarrow$ & Bi-conditional & If and only if; iff\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\label{mod1:tab:LogicSymbols}\n\t\\end{table}\n\n\\end{defn}\t\t\n\\newpage\n\\begin{defn}\\label{mod1:axiom:Negation}\n\tTruth tables of the propositional logic operators\n\n\t\t\\begin{table}[ht]\n\t\t\t\t\\centering\n\t\t\\begin{tabular}{|c |c|}\n\t\t\t\\hline\n\t\t\tp &  $\\lnot$p\\\\\n\t\t\t\\hline\n\t\t\tT & F\\\\\n\t\t\tF & T\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Negation}\n\t\t\\label{mod1:tab:Negation}\n\t\t\\medskip\n\n\n\t\t\\centering\n\t\t\\begin{tabular}{|c c|c|}\n\t\t\t\\hline\n\t\t\tp & q & p $\\land$ q\\\\\n\t\t\t\\hline\n\t\t\tT & T & T\\\\\n\t\t\tT & F & F\\\\\n\t\t\tF & T & F\\\\\n\t\t\tF & F & F\\\\\n\t\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Conjunction}\n\t\t\\label{mod1:tab:Conjunction}\n\t\t\\medskip\n\t\n\t\t\\begin{tabular}{|c c|c|}\n\t\t\t\\hline\n\t\t\tp & q & p $\\lor$ q\\\\\n\t\t\t\\hline\n\t\t\tT & T & T\\\\\n\t\t\tT & F & T\\\\\n\t\t\tF & T & T\\\\\n\t\t\tF & F & F\\\\\n\t\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Disjunction}\n\t\t\\label{mod1:tab:Disjunction}\n\t\t\\medskip\n\t\n\t\n\t\t\\begin{tabular}{|c c|c|}\n\t\t\t\\hline\n\t\t\tp & q & p $\\Rightarrow$ q\\\\\n\t\t\t\\hline\n\t\t\tT & T & T\\\\\n\t\t\tT & F & F\\\\\n\t\t\tF & T & T\\\\\n\t\t\tF & F & T\\\\\n\t\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Conditional}\n\t\t\\label{mod1:tab:Conditional}\n\t\t\\medskip\n\t\t\n\t\t\\begin{tabular}{|c c|c|}\n\t\t\t\\hline\n\t\t\tp & q & p $\\Leftrightarrow$ q\\\\\n\t\t\t\\hline\n\t\t\tT & T & T\\\\\n\t\t\tT & F & F\\\\\n\t\t\tF & T & F\\\\\n\t\t\tF & F & T\\\\\n\t\t\t\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Bi-conditional}\n\t\t\\label{mod1:tab:Bi-conditional}\n\t\t\\end{table}\n\n\\end{defn}\n\n\\newpage\n\\noindent Suppose we have the proposition $p \\Rightarrow q$, we make the following three definitions:\n\\begin{defn}\\label{mod1:defn:Inverse}\n\t\\textbf{Inverse}: $\\lnot p \\Rightarrow \\lnot q$ \n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Converse}\n\t\\textbf{Converse}: $q \\Rightarrow p$ \n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Contrapositive}\n\t\\textbf{Contrapositive}: $\\lnot q \\Rightarrow \\lnot p$ \n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Tautology}\n\t\\textbf{Tautology}: A tautology is a proposition which is true in every possible interpretation.\n\\end{defn}\n\n\\begin{defn}\\label{mod1:defn:Contradiction}\n\t\\textbf{Contradiction}: A contradiction is a proposition which is false in every possible interpretation.\n\\end{defn}\n\n\n\n\n\n\\subsection{Laws of Boolean Algebra}\\label{mod1:sexrionBooleanAlgebraLaws}\n\n\n\n\\noindent Consider the propsitional variables $p$, $q$ and $r$\n\n\n\\begin{law}\\label{mod1:law:Annulment}\n\t\\textbf{Annulment}\n\t\\begin{align}\n\tp \\land F &= F  \\\\\n\tp \\lor T &= T \n\t\\end{align}\n\\end{law}\n\n\n\\begin{law}\\label{mod1:law:Identity}\n\t\\textbf{Identity}\n\t\\begin{align}\n\tp \\land T &= p  \\\\\n\tp \\lor F &= p\n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:Idempotent}\n\t\\textbf{Idempotent}\n\t\\begin{align}\n\tp \\lor p &= p\\\\\n\tp \\land p &= p\n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:Complement}\n\t\\textbf{Complement}\n\t\\begin{align}\n\tp \\lor \\lnot p &= T\\\\\n\tp \\land \\lnot p &= F\n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:DoubleNegation}\n\t\\textbf{Double Negation}\n\t\\begin{align}\n\t\\lnot(\\lnot p) &= p\n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:DeMorgan}\n\t\\textbf{De Morgan's}\n\t\\begin{align}\n\t\\lnot (p \\land q) &= \\lnot p \\lor \\lnot q \\\\\n\t\\lnot (p \\lor q) &= \\lnot p \\land \\lnot q \n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:Associative}\n\t\\textbf{Associative}\n\t\\begin{align}\n\t(p \\lor q) \\lor r &= p \\lor (q \\lor r) \\\\\n\t(p \\land q) \\land r &= p \\land (q \\land r) \n\t\\end{align}\n\\end{law}\n\n \\begin{law}\\label{mod1:law:Commutative}\n\t\\textbf{Commutative}\n\t\\begin{align}\n\tp \\land q &= q \\land p \\\\\n\tp \\lor q &= q \\lor p\n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:Distributive}\n\t\\textbf{Distributive}\n\t\\begin{align}\n\tp \\land (q \\lor r) &= (p \\land q) \\lor (p \\land r) \\\\\n\tp \\lor (q \\land r) &= (p \\lor q) \\land (p \\lor r) \n\t\\end{align}\n\\end{law}\n\n\\begin{law}\\label{mod1:law:Absorptive}\n\t\\textbf{Absorptive}\n\t\\begin{align}\n\tp \\land (p \\lor p) &= p\\\\\n\tp \\lor (p \\land p) &= p\n\t\\end{align}\n\\end{law}\n\n\n\\subsection{Logic Circuits}\\label{mod1:section:LogicCircuits}\n\n\\textcolor{red}{DIAGRAMS OF LOGIC CIRCUITS}\n\n\n\n\n\n\n\n\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t", "meta": {"hexsha": "1c462ad3efd26731222e060dc6db79ebb6a90be3", "size": 7055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/Notes/mod1.tex", "max_stars_repo_name": "junjun99/Applied-Mathematics-Unit2", "max_stars_repo_head_hexsha": "0f433921e6aeaacf3cbbbf4951076d58c744fa76", "max_stars_repo_licenses": ["MIT"], "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/Notes/mod1.tex", "max_issues_repo_name": "junjun99/Applied-Mathematics-Unit2", "max_issues_repo_head_hexsha": "0f433921e6aeaacf3cbbbf4951076d58c744fa76", "max_issues_repo_licenses": ["MIT"], "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/Notes/mod1.tex", "max_forks_repo_name": "junjun99/Applied-Mathematics-Unit2", "max_forks_repo_head_hexsha": "0f433921e6aeaacf3cbbbf4951076d58c744fa76", "max_forks_repo_licenses": ["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.8421052632, "max_line_length": 235, "alphanum_fraction": 0.5651311127, "num_tokens": 2401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914997895581, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.6257783339541805}}
{"text": "% !TEX root = ../thesis.tex\n\n\\chapter{Conclusion}\nIn this thesis we have given two equivalent definitions of the Hopf map,\nand with these we parametrised its fibres and\nshowed that they are all linked with one another.\nWe have given a procedure for constructing a divergenceless vector field\nfrom a differentiable function from $\\R^3$ to a two-dimensional manifold,\nand applied this to the Hopf map composed with stereographic projection.\nWe explored how variations of the field can be constructed\nby pulling back different two-forms\nor by altering the differentiable function $\\R^3 \\to S^2\\!$.\nFinally, we interpreted the divergenceless vector field\nobtained from the Hopf map as the magnetic field in \\mhd,\nand we gave a heuristic argument as to why this field exhibits a form of self-stability.\nAreas of future research could be quantifying the degree of stability\nand exploring extensions of the given procedure to electromagnetism.\n", "meta": {"hexsha": "15dda140a07e2207abbd0264f59c8b459fc76f7d", "size": 937, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/conclusion.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/conclusion.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/conclusion.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": 52.0555555556, "max_line_length": 88, "alphanum_fraction": 0.8057630736, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6257771719639424}}
{"text": "\\documentclass[11pt, oneside]{article}\n\\usepackage{indentfirst, hyperref, geometry, amsmath, amssymb, algorithm, CJKutf8}\n\\usepackage[noend]{algpseudocode}\n\\usepackage[cache=false]{minted}\n\\usepackage{CJKutf8}\n\n\\geometry{a4paper}\n\n\\hypersetup{\n    colorlinks=true,\n    urlcolor=cyan\n}\n\n\\makeatletter\n\\AtBeginEnvironment{minted}{\\dontdofcolorbox}\n\\def\\dontdofcolorbox{\\renewcommand\\fcolorbox[4][]{##4}}\n\\makeatother\n\n\\title{Matricization of the Rubik's Cube}\n\\author{Stephen Huan}\n\n\\begin{document}\n\\maketitle\n\n\\section{Rational}\nApparently the Rubik's cube is an ``algebraic group'' (which I will not pretend to understand), and has certain mathematical properties.\nThe most important in my opinion is \\textit{non-commutativity}, or when \\( a \\times b \\neq b \\times a \\). For a simple example, note that\napplying the sequence ``R U'' does not give the same result as applying ``U R''. Such ``non-commutative algebra'' is closely\nassociated with things like Heisenberg's Matrix mechanics, a formulation of quantum mechanics mathematically identical to Schrödinger's wave mechanics or\nHamilton's quaternions.\n\nIn my previous lecture I argued that a cubie-wise approach was simplier and more abstract than a sticker-wise approach. However, my cubie approach is\n3x9x3, making it a tensor. Contrary to what Google wants you to believe, tensors are difficult to work with and do not ``flow''. A sticker-wise approach\ncould be thought of as a 6x9 matrix, and moves as other transformation matrices such that if \\( S \\) is a cube state and \\( R \\) a possible turn of the cube\n\\( S' = S R \\).\n\nThe advantages are numerous. Solving the cube becomes a matrix factorization problem - trying to decompose a single matrix which represents a\na complex transition from scrambled to solved into the product of many move matrices. Matrix multiplication is a well-optimized operation in\nmany different linear algebra libraries and is trivially parallelized.\n\n\\section{Example}\n\nSuppose \\( A = \\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix} \\) is a cube state and \\( B = \\begin{bmatrix} 2 & 1 \\\\ 4 & 3 \\end{bmatrix} \\)\nis the cube state after a R move. We are looking for a matrix \\( X \\) such that \\( A X = B \\). Multipying both sides on the left by \\( A' \\) yields\n\\( A' A X = A' B \\) which means \\( X = A' B \\). After computing the inverse \\( X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\).\n\\( X \\) can be thought of as a 2-swap which swaps the first row as well as the second row. Computing \\( AX^2 = A \\), \\( AX^3 = AX \\), etc.\n\nHowever, if \\( B = \\begin{bmatrix} 2 & 1 \\\\ 3 & 4 \\end{bmatrix} \\) solving for \\( X \\) yields \\( X = \\begin{bmatrix} -1 & 2 \\\\ 1.5 & -0.5 \\end{bmatrix} \\).\nBy definition \\( A X = B \\), however \\( A X^2 \\neq A \\) which would be expected of a swap. Further exponentiation of \\( X \\) results in gibberish.\nThis can be interepreted as the limitation of ``learning'' a transformation matrix: it cannot learn a single swap, only a two-swap.\n\nThe analogy to cubing is clear. Suppose we had a transformation matrix \\( R \\) which applies a R-move on a given state of the cube \\( S \\). R2 would literally be \\( R^2 \\).\nR' would be \\( R^3 \\) and R4 would be \\( R^4 \\) as well as the identity matrix.\n\n\\section{Experimentation}\n\nAs stated previously, a stickermap is 6x9 or a non-square matrix. Therefore there does not exist a traditional inverse, and more general methods must be used. In particular I tried\nthe Moore-Penrose inverse as well as the two one-sided inverses.\n\n\\subsection{Solved Cube}\nStarting with the solved cube given by:\n\\[ \\begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\ 2 & 2 & 2 & 2 & 2 & 2 & 2 & 2 & 2 \\\\ 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 \\\\ 4 & 4 & 4 & 4 &\n4 & 4 & 4 & 4 & 4 \\\\ 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 & 5 \\end{bmatrix} \\]\nand a R-turn on the solved cube given by:\n\\[ \\begin{bmatrix} 0 & 0 & 5 & 0 & 0 & 5 & 0 & 0 & 5 \\\\1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\4 & 2 & 2 & 4 & 2 & 2 & 4 & 2 & 2 \\\\3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 & 3 \\\\4 & 4 & 0 & 4 & 4 & 0 & 4 & 4 & 0 \\\\5 & 5 & 2 & 5 & 5 & 2 & 5 & 5 & 2 \\end{bmatrix} \\]\nusing Srikar Gouru's \\href{https://github.com/srikarg89/RubiksCubeSolver-JS}{code} (\\begin{CJK}{UTF8}{maru} ありがとう \\end{CJK}!).\n\nI first computed the Moore-Penrose inverse but had no idea what to do with it.\nI then attempted to compute both one-sided inverses, but for an one-sided inverse to exist the rank of the matrix has to be the maximum possible for that size.\nA property of rank is that \\( \\text{rank}(A) = \\text{rank}(A^T) \\), or that the columns rank is equal to the row rank. In this case, the maximum rank is 6.\nSince each row of the matrix is linearly dependent on each other row and each column is linearly dependent on each other column the rank of the solved cube is 1.\n\n\\subsection{Random Permutation}\n\nTo rectify the rank problem I permuted each \\( (i, j) \\to (i', j') \\) randomly.\n\n\\begin{minted}{python}\ndef transform(mapping, m):\n    new = [[0]*9 for i in range(6)]\n    for i in range(6):\n        for j in range(9):\n            x, y = mapping[(i, j)]\n            new[i][j] = m[x][y]\n    return np.array(new)\n\n\ndef gen_random(m=solved):\n    indexes = [(i, j) for i in range(6) for j in range(9)]\n    trans = {}\n    for i in range(6):\n        for j in range(9):\n            trans[(i, j)] = random.choice(indexes)\n            indexes.remove(trans[(i, j)])\n    return transform(trans, m), trans\n\\end{minted}\n\nTo verify the inversability of the new matrices, I wrote a function.\n\n\\begin{minted}{python}\ndef inversable(m, tol=2):\n    m = np.array(m)\n    if np.linalg.matrix_rank(m) == 6:\n        return (round(np.linalg.det(m.T @ m), tol) != 0,\n                round(np.linalg.det(m @ m.T), tol) != 0)\n    return (False,)*2\n\\end{minted}\n\nIt happened that the left inverse did not exist.\nThe right inverse is defined by \\( A_r = A^T (A A^T)^{-1} \\) with the result that\n\\( A A_r = A A^T (A A^T)^{-1} = I_6 \\).\nGiven \\( A \\) as the solved cube state and \\( B \\) the cube after a R-turn,\n\\( A X = B \\), so \\( X = A_r B \\) is the transformation matrix.\n\nHowever, repeated application of \\( X \\) was meaningless. Also, the permutation\nwas completely ad-hoc and mathematically meaningless.\n\n\\subsection{Distinct Swaps}\n\nRecalling the simple 2x2 example, certain swaps are possible and certain other swaps are\nimpossible. I realized I could not possibly learn from the solved state \\( \\to \\) R-move off because only\n12 stickers move (the entire red face is unchanged). I would therefore need a 20 sticker change, the maximum possible.\nTo find such a state I defined the function rdiff which returns the number of stickers which change before and after doing a R move\nand applied my BFS defined in my earlier lecture.\n\n\\begin{minted}{python}\nc = cube.Cube()\nstates, alg = cube.solve(c, (None, lambda c: rdiff(c) >= 20), cube.HTM)\nc.turn(alg)\n\nprint(rdiff(c))\nprint(inversable(c.to_face()))\n\na = np.array(c.to_face())\nc.turn(\"R\")\nap = np.array(c.to_face())\n\nar = a.T @ np.linalg.inv(a @ a.T)\nR = ar @ ap\nprint(a @ R)\n\\end{minted}\n\nAs a result of finding a 20 sticker difference I no longer needed to permute the matrix. However, the transition matrix remains meaningless.\n\n\\section{Future Work}\n\nPerhaps transitions cannot be represented by matrices and have to be represented by tensors or quaternions.\nWhatever the case, the mathematical representation must be noncommutative. This also may be a fairly useless avenue of research.\n\nVarious vectorization approaches and neural networks to be done soon!\n\n\\end{document}\n", "meta": {"hexsha": "c5d479ab3e778a3713890ef22373e282aed5450d", "size": 7518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pdfs/Matricization/matrix.tex", "max_stars_repo_name": "myfatemi04/TJCubing", "max_stars_repo_head_hexsha": "45340bca434c8b1eb0d16dcae3799ed8dd758f0c", "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": "src/pdfs/Matricization/matrix.tex", "max_issues_repo_name": "myfatemi04/TJCubing", "max_issues_repo_head_hexsha": "45340bca434c8b1eb0d16dcae3799ed8dd758f0c", "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/pdfs/Matricization/matrix.tex", "max_forks_repo_name": "myfatemi04/TJCubing", "max_forks_repo_head_hexsha": "45340bca434c8b1eb0d16dcae3799ed8dd758f0c", "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.4605263158, "max_line_length": 249, "alphanum_fraction": 0.6824953445, "num_tokens": 2286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6257771638349926}}
{"text": "\n\\subsection{Almost sure convergence}\n\n\\(X_n\\) converges almost surely to \\(X\\) if:\n\n\\(d(X_n, X)\\rightarrow 0\\)\n\nWhere \\(d(X_n, X)\\) is a distance metric.\n\n\\(X_n\\rightarrow^{as} X\\)\n\n", "meta": {"hexsha": "be4b017f0d7f370353a916cb8913feef2d54f8f3", "size": 183, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/iidCLT/02-03-convergenceAS.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-03-convergenceAS.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-03-convergenceAS.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.25, "max_line_length": 44, "alphanum_fraction": 0.650273224, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6256773230207441}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=2cm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{slashed}\n\\usepackage{tikz}\n\n\\begin{document}\n\n\\noindent\nCompton scattering occurs when a high energy photon such as a gamma ray interacts with an electron.\nIn typical Compton scattering experiments the incident electron is at rest with zero velocity.\nHowever, it is easier to develop a theory using the center of mass frame in which\nthe photon and the electron have equal and opposite momentum.\nThe following diagram shows the photon and electron scattering through angle $\\theta$\nin the center of mass frame.\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[dashed] (0,0) circle (0.5cm);\n\\draw[thick,->] (2,0) node[anchor=west] {$e^-$} -- (0.6,0);\n\\draw[thick,->] (-2,0) node[anchor=east] {$\\gamma$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$\\gamma$};\n\\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$e^-$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nHere is the same diagram with momentum and spinor labels.\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[dashed] (0,0) circle (0.5cm);\n\\draw[thick,->] (2,0) node[anchor=west] {$p_2, u_2$} -- (0.6,0);\n\\draw[thick,->] (-2,0) node[anchor=east] {$p_1$} -- (-0.6,0);\n\\draw[thick,->] (0.40,0.40) -- (1.3,1.3) node[anchor=south west] {$p_3$};\n\\draw[thick,->] (-0.4,-0.4) -- (-1.3,-1.3) node[anchor=north east] {$p_4, u_4$};\n\\draw (1,0.5) node {$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nIn center of mass coordinates the momentum vectors are\n\\begin{equation*}\n\\underset{\\text{inbound photon}}\n{\np_1=\\begin{pmatrix}\\omega\\\\0\\\\0\\\\ \\omega\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{inbound electron}}\n{\np_2=\\begin{pmatrix}E\\\\0\\\\0\\\\-\\omega\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{outbound photon}}\n{\np_3=\\begin{pmatrix}\n\\omega\\\\\n\\omega\\sin\\theta\\cos\\phi\\\\\n\\omega\\sin\\theta\\sin\\phi\\\\\n\\omega\\cos\\theta\n\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{outbound electron}}\n{\np_4=\\begin{pmatrix}\nE\\\\\n-\\omega\\sin\\theta\\cos\\phi\\\\\n-\\omega\\sin\\theta\\sin\\phi\\\\\n-\\omega\\cos\\theta\n\\end{pmatrix}\n}\n\\end{equation*}\n\n\\noindent\nSymbol $\\omega$ is incident momentum,\n$E$ is total energy $E=\\sqrt{\\omega^2+m^2}$,\nand $m$ is electron mass.\nPolar angle $\\theta$ is the observed scattering angle.\nAzimuth angle $\\phi$ cancels out in scattering calculations.\n\n\\bigskip\n\\noindent\nThe spinors are\n\\begin{equation*}\n\\underset{\\text{inbound electron, spin up}}\n{\nu_{21}=\\begin{pmatrix}\nE+m\\\\\n0\\\\\n-\\omega\\\\\n0\n\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{inbound electron, spin down}}\n{\nu_{22}=\\begin{pmatrix}\n0\\\\\nE+m\\\\\n0\\\\\n\\omega\n\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{outbound electron, spin up}}\n{\nu_{41}=\\begin{pmatrix}\nE+m\\\\\n0\\\\\np_{4z}\\\\\np_{4x}+ip_{4y}\n\\end{pmatrix}\n}\n\\qquad\n\\underset{\\text{outbound electron, spin down}}\n{\nu_{42}=\\begin{pmatrix}\n0\\\\\nE+m\\\\\np_{4x}-ip_{4y}\\\\\n-p_{4z}\n\\end{pmatrix}\n}\n\\end{equation*}\n\n\\noindent\nThe spinors shown above are not individually normalized.\nInstead, a combined spinor normalization constant $N=(E+m)^2$ will be used.\n\n\\bigskip\n\\noindent\nThe following formula computes a probability density $|\\mathcal{M}_{ab}|^2$\nfor Compton scattering where $a$ is the spin state of the inbound electron\nand $b$ is the spin state of the outbound electron.\n\\begin{equation*}\n|\\mathcal{M}_{ab}|^2\n=\n\\frac{e^4}{N}\n\\left|\n-\\frac{\\bar{u}_{4b}\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu u_{2a}}{s-m^2}\n-\\frac{\\bar{u}_{4b}\\gamma^\\nu(\\slashed{q}_2+m)\\gamma^\\mu u_{2a}}{u-m^2}\n\\right|^2\n\\end{equation*}\nSymbol $e$ is electron charge.\nSymbols $q_1$ and $q_2$ are\n\\begin{align*}\nq_1&=p_1+p_2\n\\\\\nq_2&=p_4-p_1=p_2-p_3\n\\end{align*}\n\n\\noindent\nSymbols $s$ and $u$ are Mandelstam variables\n\\begin{align*}\ns&=(p_1+p_2)^2\n\\\\\nu&=(p_1-p_4)^2\n\\end{align*}\n\n\\noindent\nLet\n\\begin{equation*}\na_1=\\bar{u}_{4b}\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu u_{2a}\n\\qquad\na_2=\\bar{u}_{4b}\\gamma^\\nu(\\slashed{q}_2+m)\\gamma^\\mu u_{2a}\n\\end{equation*}\n\n\\noindent\nThen\n\\begin{align*}\n|\\mathcal{M}_{ab}|^2&=\\frac{e^4}{N}\\left|-\\frac{a_1}{s-m^2}-\\frac{a_2}{u-m^2}\\right|^2\\\\\n&=\n\\frac{e^4}{N}\n\\left(-\\frac{a_1}{s-m^2}-\\frac{a_2}{u-m^2}\\right)\n\\left(-\\frac{a_1}{s-m^2}-\\frac{a_2}{u-m^2}\\right)^*\\\\\n&=\n\\frac{e^4}{N}\\left(\n\\frac{a_1a_1^*}{(s-m^2)^2}\n+\\frac{a_1a_2^*}{(s-m^2)(u-m^2)}\n+\\frac{a_1^*a_2}{(s-m^2)(u-m^2)}\n+\\frac{a_2a_2^*}{(u-m^2)^2}\n\\right)\n\\end{align*}\n\n\\noindent\nThe expected probability density $\\langle|\\mathcal{M}|^2\\rangle$ is\ncomputed by summing $|\\mathcal{M}_{ab}|^2$ over all spin and polarization states\nand then dividing by the number of inbound states.\nThere are four inbound states.\nThe sum over polarizations is already accomplished by contraction of $aa^*$ over $\\mu$ and $\\nu$.\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\\frac{1}{4}\\sum_{a=1}^2\\sum_{b=1}^2|\\mathcal{M}_{ab}|^2\\\\\n&=\\frac{e^4}{4N}\\sum_{a=1}^2\\sum_{b=1}^2\n\\left(\n\\frac{a_1a_1^*}{(s-m^2)^2}\n+\\frac{a_1a_2^*}{(s-m^2)(u-m^2)}\n+\\frac{a_1^*a_2}{(s-m^2)(u-m^2)}\n+\\frac{a_2a_2^*}{(u-m^2)^2}\n\\right)\n\\end{align*}\n\n\\noindent\nUse the Casimir trick to replace sums over spins with matrix products.\n\\begin{align*}\nf_{11}&=\\frac{1}{N} \\sum_{a=1}^2\\sum_{b=1}^2 a_1a_1^*=\\mathop{\\rm Tr}\n\\left(\n(\\slashed{p}_2+m)\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu(\\slashed{p}_4+m)\\gamma_\\nu(\\slashed{q}_1+m)\\gamma_\\mu\n\\right)\n\\\\\nf_{12}&=\\frac{1}{N} \\sum_{a=1}^2\\sum_{b=1}^2 a_1a_2^*=\\mathop{\\rm Tr}\n\\left(\n(\\slashed{p}_2+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_4+m)\\gamma_\\mu(\\slashed{q}_1+m)\\gamma_\\nu\n\\right)\n\\\\\nf_{22}&=\\frac{1}{N} \\sum_{a=1}^2\\sum_{b=1}^2 a_2a_2^*=\\mathop{\\rm Tr}\n\\left(\n(\\slashed{p}_2+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_4+m)\\gamma_\\nu(\\slashed{q}_2+m)\\gamma_\\mu\n\\right)\n\\end{align*}\n\n\\noindent\nHence\n\\begin{equation}\n\\langle|\\mathcal{M}|^2\\rangle\n=\n\\frac{e^4}{4}\n\\left(\n\\frac{f_{11}}{(s-m^2)^2}\n+\\frac{f_{12}}{(s-m^2)(u-m^2)}\n+\\frac{f_{12}^*}{(s-m^2)(u-m^2)}\n+\\frac{f_{22}}{(u-m^2)^2}\n\\right)\n\\end{equation}\n\n\\noindent\nRun ``compton-scattering-1.txt'' to verify the Casimir trick for Compton scattering.\n\n\\bigskip\n\\noindent\nThe following formulas are equivalent to the Casimir trick.\n(Recall that $a\\cdot b=a^\\mu g_{\\mu\\nu}b^\\nu$)\n\\begin{align*}\nf_{11}&=\n 32 (p_1 \\cdot p_2) (p_1 \\cdot p_4) +\n 64 m^2 (p_1 \\cdot p_2) -\n 32 m^2 (p_1 \\cdot p_3) -\n 32 m^2 (p_1 \\cdot p_4) + 32 m^4\n\\\\\nf_{12}&=16 m^2 (p_1 \\cdot p_2) - 16 m^2 (p_1 \\cdot p_4) + 32m^4\n\\\\\nf_{22}&=\n32 (p_1 \\cdot p_2) (p_1 \\cdot p_4) +\n32 m^2 (p_1 \\cdot p_2) -\n32 m^2 (p_1 \\cdot p_3) -\n64 m^2 (p_1 \\cdot p_4) + 32 m^4\n\\end{align*}\n\n\\noindent\nUsing Mandelstam variables\n\\begin{align*}\ns&=(p_1+p_2)^2\n\\\\\nt&=(p_1-p_3)^2\n\\\\\nu&=(p_1-p_4)^2\n\\end{align*}\nthe formulas are\n\\begin{equation}\n\\begin{aligned}\nf_{11}&=-8 s u + 24 s m^2 + 8 u m^2 + 8 m^4\n\\\\\nf_{12}&=8 s m^2 + 8 u m^2 + 16 m^4\n\\\\\nf_{22}&=-8 s u + 8 s m^2 + 24 u m^2 + 8 m^4\n\\end{aligned}\n\\end{equation}\n\n\\noindent\nRun ``compton-scattering-2.txt'' to verify.\n\n\\subsection*{High energy approximation}\nFor high energy experiments that have $\\omega\\gg m$,\na useful approximation is to set $m=0$ and obtain\n\\begin{align*}\nf_{11}&=-8su\n\\\\\nf_{12}&=0\n\\\\\nf_{22}&=-8su\n\\end{align*}\n\n\\noindent\nHence\n\\begin{align*}\n\\langle|\\mathcal{M}|^2\\rangle\n&=\\frac{e^4}{4}\n\\left(\\frac{-8su}{s^2}+\\frac{-8su}{u^2}\\right)\n\\\\\n&=2e^4\n\\left(-\\frac{u}{s}-\\frac{s}{u}\\right)\n\\end{align*}\n\n\\noindent\nAlso for $m=0$ the Mandelstam variables $s$ and $u$ are\n\\begin{align*}\ns&=4\\omega^2\n\\\\\nu&=-2\\omega^2(\\cos\\theta+1)\n\\end{align*}\nHence\n\\begin{equation}\n\\langle|\\mathcal{M}|^2\\rangle\n=2e^4\\left(\n\\frac{\\cos\\theta+1}{2}+\\frac{2}{\\cos\\theta+1}\n\\right)\n\\end{equation}\n\n\\subsection*{Lab frame}\nCompton scattering experiments are typically done in the ``lab'' frame where the electron is at rest.\nThe following Lorentz boost $\\Lambda$ transforms momentum vectors from\nthe center of mass frame to the lab frame.\n\\begin{equation*}\n\\Lambda=\n\\begin{pmatrix}\nE/m & 0 & 0 & \\omega/m\\\\\n0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0\\\\\n\\omega/m & 0 & 0 & E/m\n\\end{pmatrix},\n\\qquad\n\\Lambda p_2=\\begin{pmatrix}m \\\\ 0 \\\\ 0 \\\\ 0\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nMandelstam variables are invariant under a boost.\n\\begin{equation*}\n\\begin{aligned}\ns&=(p_1+p_2)^2=(\\Lambda p_1+\\Lambda p_2)^2\n\\\\\nt&=(p_1-p_3)^2=(\\Lambda p_1-\\Lambda p_3)^2\n\\\\\nu&=(p_1-p_4)^2=(\\Lambda p_1-\\Lambda p_4)^2\n\\end{aligned}\n\\end{equation*}\n\n\\noindent\nIn the lab frame, let $\\omega_L$ be the angular frequency of the incident photon\nand let $\\omega_L'$ be the angular frequency of the scattered photon.\n\\begin{equation*}\n\\begin{aligned}\n\\omega_L&=\\Lambda p_1\\cdot(1,0,0,0)=\\frac{\\omega^2}{m}+\\frac{\\omega E}{m}\n\\\\\n\\omega_L'&=\\Lambda p_3\\cdot(1,0,0,0)=\\frac{\\omega^2\\cos\\theta}{m}+\\frac{\\omega E}{m}\n\\end{aligned}\n\\end{equation*}\n\n\\noindent\nIt follows that\n\\begin{equation*}\n\\begin{aligned}\ns&=(p_1+p_2)^2=2m\\omega_L+m^2\n\\\\\nt&=(p_1-p_3)^2=2m(\\omega_L' - \\omega_L)\n\\\\\nu&=(p_1-p_4)^2=-2 m \\omega_L' + m^2\n\\end{aligned}\n\\end{equation*}\n\n\\noindent\nCompute $\\langle|\\mathcal{M}|^2\\rangle$ using equations (1) and (2)\nand the above $s$, $t$, and $u$ that involve $\\omega_L$ and $\\omega_L'$.\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle=\n2e^4\\left(\n\\frac{\\omega_L}{\\omega_L'}+\\frac{\\omega_L'}{\\omega_L}\n+\\left(\\frac{m}{\\omega_L}-\\frac{m}{\\omega_L'}+1\\right)^2-1\n\\right)\n\\end{equation*}\n\n\\noindent\nFrom the Compton formula\n\\begin{equation*}\n\\frac{1}{\\omega_L'}-\\frac{1}{\\omega_L}=\\frac{1-\\cos\\theta_L}{m}\n\\end{equation*}\n\n\\noindent\nwe have\n\\begin{equation*}\n\\cos\\theta_L=\\frac{m}{\\omega_L}-\\frac{m}{\\omega_L'}+1\n\\end{equation*}\n\n\\noindent\nHence\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle=\n2e^4\\left(\n\\frac{\\omega_L}{\\omega_L'}+\\frac{\\omega_L'}{\\omega_L}+\\cos^2\\theta_L-1\n\\right)\n\\end{equation*}\n\n\\noindent\nRun ``compton-scattering-3.txt'' to verify lab frame formulas for Compton scattering.\n\n\\subsection*{Cross section}\nNow that we have derived $\\langle|\\mathcal{M}|^2\\rangle$\nwe can investigate the angular distribution of scattered photons.\nFor simplicity let us drop the $L$ subscript from lab variables.\nFrom now on the symbols $\\omega$, $\\omega'$, and $\\theta$ will be lab frame variables.\n\n\\bigskip\n\\noindent\nThe differential cross section for Compton scattering is\n\\begin{align*}\n\\frac{d\\sigma}{d\\Omega}&=\\frac{\\hbar^2}{64\\pi^2m^2c^4}\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\\langle|\\mathcal{M}|^2\\rangle\n\\\\\n&=\\frac{e^4\\hbar^2}{32\\pi^2m^2c^4}\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\n\\left(\n\\frac{\\omega}{\\omega'}+\\frac{\\omega'}{\\omega}+\\cos^2\\theta-1\n\\right)\n\\end{align*}\n\n\\noindent\nSubstitute $e^4=16\\pi^2\\alpha^2$ to obtain\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\alpha^2\\hbar^2}{2m^2c^4}\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\n\\left(\n\\frac{\\omega}{\\omega'}+\\frac{\\omega'}{\\omega}+\\cos^2\\theta-1\n\\right)\n\\end{equation*}\n\n\\noindent\nThe scattered photon frequency $\\omega'$ is computed from the Compton equation.\n\\begin{equation*}\n\\omega'=\\frac{m\\omega}{m+\\omega(1-\\cos\\theta)}\n\\end{equation*}\n\n\\noindent\nWe can integrate $d\\sigma$ to obtain a cumulative distribution function.\nRecall that\n\\begin{equation*}\nd\\Omega=\\sin\\theta\\,d\\theta\\,d\\phi\n\\end{equation*}\nHence\n\\begin{equation*}\nd\\sigma\n=\\frac{\\alpha^2\\hbar^2}{2m^2c^4}\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\n\\left(\\frac{\\omega}{\\omega'}+\\frac{\\omega'}{\\omega}+\\cos^2\\theta-1\\right)\n\\sin\\theta\\,d\\theta\\,d\\phi\n\\end{equation*}\n\n\\bigskip\n\\noindent\nLet $I(\\theta)$ be the following integral of $d\\sigma$.\n\\begin{align*}\nI(\\theta)\n&=\\left(\\frac{2m^2c^4}{\\alpha^2\\hbar^2}\\right)\\frac{1}{2\\pi}\\int_0^{2\\pi}\\int d\\sigma\n\\\\\n&=\\int\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\n\\left(\\frac{\\omega}{\\omega'}+\\frac{\\omega'}{\\omega}+\\cos^2\\theta-1\\right)\n\\sin\\theta\\,d\\theta,\n\\quad0\\le\\theta\\le\\pi\n\\end{align*}\n\n\\noindent\nAssume that $I(\\theta)-I(0)$ is computable given $\\theta$ by either symbolic or numerical integration.\n\n\\bigskip\n\\noindent\nLet $C$ be the normalization constant\n\\begin{equation*}\nC=I(\\pi)-I(0)\n\\end{equation*}\n\n\\noindent\nThen the cumulative distribution function $F(\\theta)$ is\n\\begin{equation*}\nF(\\theta)=\\frac{I(\\theta)-I(0)}{C},\n\\quad0\\le\\theta\\le\\pi\n\\end{equation*}\n\n\\noindent\nThe probability of observing scattering events in the interval\n$\\theta_1$ to $\\theta_2$ can now be computed.\n\\begin{equation*}\nP(\\theta_1\\le\\theta\\le\\theta_2)=F(\\theta_2)-F(\\theta_1)\n\\end{equation*}\n\n\\noindent\nThe probability density function $f(\\theta)$ is the derivative of $F(\\theta)$.\n\\begin{equation*}\nf(\\theta)=\\frac{dF(\\theta)}{d\\theta}\n=\\frac{1}{C}\n\\left(\\frac{\\omega'}{\\omega}\\right)^2\n\\left(\\frac{\\omega}{\\omega'}+\\frac{\\omega'}{\\omega}+\\cos^2\\theta-1\\right)\n\\sin\\theta\n\\end{equation*}\n\n\\noindent\nRun ``compton-scattering-4.txt'' to draw a graph of $f(\\theta)$ for\n$\\omega=500\\,\\text{keV}=1.2\\times10^{20}\\,\\text{Hz}$.\n\n\\begin{center}\n\\includegraphics[scale=0.5]{compton-scattering.png}\n\\end{center}\n\n\\noindent\nProbability distribution for $45^\\circ$ bins\n($\\omega=500\\,\\text{keV}=1.2\\times10^{20}\\,\\text{Hz}$).\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$\\theta_1$ & $\\theta_2$ & $P(\\theta_1\\le\\theta\\le\\theta_2)$\\\\\n\\hline\n$0^\\circ$ & $45^\\circ$ & 0.35 \\\\\n$45^\\circ$ & $90^\\circ$ & 0.34 \\\\\n$90^\\circ$ & $135^\\circ$ & 0.22 \\\\\n$135^\\circ$ & $180^\\circ$ & 0.09 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\subsection*{Thomson scattering}\nWhen $\\omega$ is much smaller than the electron mass $m$ we have\n\\begin{equation*}\n\\frac{m}{m+\\omega(1-\\cos\\theta)}\\approx1\n\\end{equation*}\n\n\\noindent\nHence for $\\omega\\ll m$ the differential cross section is approximately\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}=\\frac{\\alpha^2}{2m^2}(1+\\cos^2\\theta)\n\\end{equation*}\n\n\\noindent\nwhich is the formula for Thomson scattering.\n\n\\subsection*{Data from a CERN LEP experiment}\nSee ``Compton Scattering of Quasi-Real Virtual Photons at LEP,''\narxiv.org/abs/hep-ex/0504012.\n\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n$x$ & $y$\\\\\n\\hline\n$-0.74$ & $13380$\\\\\n$-0.60$ & $\\phantom{0}7720$\\\\\n$-0.47$ & $\\phantom{0}6360$\\\\\n$-0.34$ & $\\phantom{0}4600$\\\\\n$-0.20$ & $\\phantom{0}4310$\\\\\n$-0.07$ & $\\phantom{0}3700$\\\\\n$\\phantom{+}0.06$ & $\\phantom{0}3640$\\\\\n$\\phantom{+}0.20$ & $\\phantom{0}3340$\\\\\n$\\phantom{+}0.33$ & $\\phantom{0}3500$\\\\\n$\\phantom{+}0.46$ & $\\phantom{0}3010$\\\\\n$\\phantom{+}0.60$ & $\\phantom{0}3310$\\\\\n$\\phantom{+}0.73$ & $\\phantom{0}3330$\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nThe data are for the center of mass frame and have the following relationship with the differential cross section formula.\n\\begin{equation*}\nx=\\cos\\theta\\qquad y=\\frac{d\\sigma}{d\\cos\\theta}=2\\pi\\frac{d\\sigma}{d\\Omega}\n\\end{equation*}\n\n\\noindent\nFrom equation (3) we have for the center of mass frame\n\\begin{equation*}\n\\langle|\\mathcal{M}|^2\\rangle\n=\n2e^4\\left(\n\\frac{\\cos\\theta+1}{2}+\\frac{2}{\\cos\\theta+1}\n\\right)\n\\end{equation*}\n\n\\noindent\nThe corresponding cross section formula is\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\langle|\\mathcal{M}|^2\\rangle}{64\\pi^2s}\n=\\frac{e^4}{32\\pi^2s}\n\\left(\n\\frac{\\cos\\theta+1}{2}+\\frac{2}{\\cos\\theta+1}\n\\right),\\quad s\\gg m\n\\end{equation*}\n\n\\noindent\nSubstituting $e^4=16\\pi^2\\alpha^2$ yields\n\\begin{equation*}\n\\frac{d\\sigma}{d\\Omega}\n=\\frac{\\alpha^2}{2s}\n\\left(\n\\frac{\\cos\\theta+1}{2}+\\frac{2}{\\cos\\theta+1}\n\\right)\n\\end{equation*}\n\n\\noindent\nMultiply by $2\\pi$ to obtain\n\\begin{equation*}\n\\frac{d\\sigma}{d\\cos\\theta}\n=\\frac{\\pi\\alpha^2}{s}\\left(\n\\frac{\\cos\\theta+1}{2}+\\frac{2}{\\cos\\theta+1}\n\\right)\n\\end{equation*}\n\n\\noindent\nTo compute predicted values $\\hat{y}$ from the above formula,\nmultiply by $(\\hbar c)^2$ to convert to SI\nand multiply by $10^{40}$ to convert square meters to picobarns.\n\\begin{equation*}\n\\hat{y}\n=\n\\frac{\\pi\\alpha^2}{s}\n\\left(\n\\frac{x+1}{2}+\n\\frac{2}{x+1}\n\\right)\n\\times(\\hbar c)^2\n\\times10^{40}\n\\end{equation*}\n\n\\noindent\nThe following table shows $\\hat{y}$\nfor $s=40\\,\\text{GeV}^2$ (i.e., $\\omega=100\\,\\text{MeV}$).\n\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n\\hline\n$x$ & $y$ & $\\hat{y}$\\\\\n\\hline\n$-0.74$ & $13380$ & $12739$\\\\\n$-0.60$ & $\\phantom{0}7720$ & $\\phantom{0}8468$\\\\\n$-0.47$ & $\\phantom{0}6360$ & $\\phantom{0}6577$\\\\\n$-0.34$ & $\\phantom{0}4600$ & $\\phantom{0}5472$\\\\\n$-0.20$ & $\\phantom{0}4310$ & $\\phantom{0}4723$\\\\\n$-0.07$ & $\\phantom{0}3700$ & $\\phantom{0}4259$\\\\\n$\\phantom{+}0.06$ & $\\phantom{0}3640$ & $\\phantom{0}3936$\\\\\n$\\phantom{+}0.20$ & $\\phantom{0}3340$ & $\\phantom{0}3691$\\\\\n$\\phantom{+}0.33$ & $\\phantom{0}3500$ & $\\phantom{0}3532$\\\\\n$\\phantom{+}0.46$ & $\\phantom{0}3010$ & $\\phantom{0}3420$\\\\\n$\\phantom{+}0.60$ & $\\phantom{0}3310$ & $\\phantom{0}3338$\\\\\n$\\phantom{+}0.73$ & $\\phantom{0}3330$ & $\\phantom{0}3291$\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent\nThe coefficient of determination $R^2$ measures how well predicted values fit the real data.\n\\begin{equation*}\nR^2=1-\\frac{\\sum(y-\\hat{y})^2}{\\sum(y-\\bar{y})^2}=0.97\n\\end{equation*}\n\n\\noindent\nThe result indicates that the model $d\\sigma$ explains 97\\% of the variance in the data.\n\n\\subsection*{Notes}\nHere are a few notes regarding the Eigenmath scripts.\n\n\\bigskip\n\\noindent\nStart by writing out $a_1$ and $a_2$ in full component form.\n\\begin{equation*}\na_1^{\\mu\\nu}\n=\\bar{u}_{4\\alpha}\\gamma^{\\mu\\alpha}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\nu\\rho}{}_\\sigma u_2^\\sigma\n\\qquad\na_2^{\\nu\\mu}\n=\\bar{u}_{4\\alpha}\\gamma^{\\nu\\alpha}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\mu\\rho}{}_\\sigma u_2^\\sigma\n\\end{equation*}\n\n\\noindent\nTranspose $\\gamma$ tensors to form inner products over $\\alpha$ and $\\rho$.\n\\begin{equation*}\na_1^{\\mu\\nu}\n=\\bar{u}_{4\\alpha}\\gamma^{\\alpha\\mu}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\rho\\nu}{}_\\sigma u_2^\\sigma\n\\qquad\na_2^{\\nu\\mu}\n=\\bar{u}_{4\\alpha}\\gamma^{\\alpha\\nu}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\rho\\mu}{}_\\sigma u_2^\\sigma\n\\end{equation*}\n\n\\noindent\nConvert transposed $\\gamma$ to Eigenmath code.\n\\begin{equation*}\n\\gamma^{\\alpha\\mu}{}_\\beta\n\\quad\\rightarrow\\quad\n\\text{\\tt gammaT = transpose(gamma)}\n\\end{equation*}\n\n\\noindent\nThen to compute $a_1$ we have\n\\begin{multline*}\na_1=\\bar{u}_{4\\alpha}\\gamma^{\\alpha\\mu}{}_\\beta(\\slashed{q}_1+m)^\\beta{}_\\rho\\gamma^{\\rho\\nu}{}_\\sigma u_2^\\sigma\n\\\\\n\\rightarrow\\quad\n\\text{\\tt a1 = dot(u4bar[s4],gammaT,qslash1 + m I,gammaT,u2[s2])}\n\\end{multline*}\n\n\\noindent\nwhere $s_2$ and $s_4$ are spin indices.\nSimilarly for $a_2$ we have\n\\begin{multline*}\na_2=\\bar{u}_{4\\alpha}\\gamma^{\\alpha\\nu}{}_\\beta(\\slashed{q}_2+m)^\\beta{}_\\rho\\gamma^{\\rho\\mu}{}_\\sigma u_2^\\sigma\n\\\\\n\\rightarrow\\quad\n\\text{\\tt a2 = dot(u4bar[s4],gammaT,qslash2 + m I,gammaT,u2[s2])}\n\\end{multline*}\n\n\\noindent\nIn component notation the product $a_1a_1^*$ is\n\\begin{equation*}\na_1a_1^*=a_1^{\\mu\\nu}a_1^{*\\mu\\nu}\n\\end{equation*}\n\n\\noindent\nTo sum over $\\mu$ and $\\nu$ it is necessary to lower indices with the metric tensor.\nAlso, transpose $a_1^*$ to form an inner product with $\\nu$.\n\\begin{equation*}\na_1a_1^*=a_1^{\\mu\\nu}a_{1\\nu\\mu}^*\n\\end{equation*}\n\n\\noindent\nConvert to Eigenmath code.\nThe dot function sums over $\\nu$ and the contract function sums over $\\mu$.\n\\begin{equation*}\na_1a_1^*\n\\quad\\rightarrow\\quad\n\\text{\\tt a11 = contract(dot(a1,gmunu,transpose(conj(a1)),gmunu))}\n\\end{equation*}\n\n\\noindent\nSimilarly for $a_2a_2^*$ we have\n\\begin{equation*}\na_2a_2^*\n\\quad\\rightarrow\\quad\n\\text{\\tt a22 = contract(dot(a2,gmunu,transpose(conj(a2)),gmunu))}\n\\end{equation*}\n\n\\noindent\nThe product $a_1a_2^*$ does not require a transpose because $a_1a_2^*=a_1^{\\mu\\nu}a_2^{*\\nu\\mu}$.\n\\begin{equation*}\na_1a_2^*\n\\quad\\rightarrow\\quad\n\\text{\\tt a12 = contract(dot(a1,gmunu,conj(a2),gmunu))}\n\\end{equation*}\n\n\\noindent\nIn component notation, a trace operator becomes a sum over an index, in this case $\\alpha$.\n\\begin{align*}\nf_{11}\n&=\n\\mathop{\\rm Tr}\n\\left(\n(\\slashed{p}_2+m)\\gamma^\\mu(\\slashed{q}_1+m)\\gamma^\\nu(\\slashed{p}_4+m)\\gamma_\\nu(\\slashed{q}_1+m)\\gamma_\\mu\n\\right)\\\\\n&=\n(\\slashed{p}_2+m)^\\alpha{}_\\beta\n\\gamma^{\\mu\\beta}{}_\\rho\n(\\slashed{q}_1+m)^\\rho{}_\\sigma\n\\gamma^{\\nu\\sigma}{}_\\tau\n(\\slashed{p}_4+m)^\\tau{}_\\delta\n\\gamma_\\nu{}^\\delta{}_\\eta\n(\\slashed{q}_1+m)^\\eta{}_\\xi\n\\gamma_\\mu{}^\\xi{}_\\alpha\n\\end{align*}\n\n\\noindent\nAs before, transpose $\\gamma$ tensors to form inner products.\n\\begin{equation*}\nf_{11}=\n(\\slashed{p}_2+m)^\\alpha{}_\\beta\n\\gamma^{\\beta\\mu}{}_\\rho\n(\\slashed{q}_1+m)^\\rho{}_\\sigma\n\\gamma^{\\sigma\\nu}{}_\\tau\n(\\slashed{p}_4+m)^\\tau{}_\\delta\n\\gamma^\\delta{}_{\\nu\\eta}\n(\\slashed{q}_1+m)^\\eta{}_\\xi\n\\gamma^\\xi{}_{\\mu\\alpha}\n\\end{equation*}\n\n\\noindent\nTo convert to Eigenmath code, use an intermediate variable for the inner product.\n\\begin{equation*}\nT^{\\alpha\\mu\\nu}{}_{\\nu\\mu\\alpha}\n\\quad\\rightarrow\\quad\n\\text{\\tt T = dot(P2,gammaT,Q1,gammaT,P4,gammaL,Q1,gammaL)}\n\\end{equation*}\n\n\\noindent\nNow sum over the indices of $T$.\nThe innermost contract sums over $\\nu$ then the next contract sums over $\\mu$.\nFinally the outermost contract sums over $\\alpha$.\n\\begin{equation*}\nf_{11}\\quad\\rightarrow\\quad\n\\text{\\tt f11 = contract(contract(contract(T,3,4),2,3))}\n\\end{equation*}\n\n\\noindent\nFollow suit for $f_{22}$.\nFor $f_{12}$ the order of the rightmost $\\mu$ and $\\nu$ is reversed.\n\\begin{equation*}\nf_{12}=\\mathop{\\rm Tr}\n\\left(\n(\\slashed{p}_2+m)\\gamma^\\mu(\\slashed{q}_2+m)\\gamma^\\nu(\\slashed{p}_4+m)\\gamma_\\mu(\\slashed{q}_1+m)\\gamma_\\nu\n\\right)\n\\end{equation*}\n\n\\noindent\nThe resulting inner product is $T^{\\alpha\\mu\\nu}{}_{\\mu\\nu\\alpha}$\nso the contraction is different.\n\\begin{equation*}\nf_{12}\n\\quad\\rightarrow\\quad\n\\text{\\tt f12 = contract(contract(contract(T,3,5),2,3))}\n\\end{equation*}\n\n\\noindent\nThe innermost contract sums over $\\nu$ followed by sum over $\\mu$ then sum over $\\alpha$.\n\n\\end{document}\n", "meta": {"hexsha": "241f72c5303d1622a334d117893b5e6a10361890", "size": 21276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compton-scattering.tex", "max_stars_repo_name": "georgeweigt/georgeweigt.github.io", "max_stars_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "compton-scattering.tex", "max_issues_repo_name": "georgeweigt/georgeweigt.github.io", "max_issues_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "compton-scattering.tex", "max_forks_repo_name": "georgeweigt/georgeweigt.github.io", "max_forks_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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.6646562123, "max_line_length": 122, "alphanum_fraction": 0.6686877233, "num_tokens": 8760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6256773183668202}}
{"text": "\\section{The Theory of Covering Spaces}\r\n\\begin{definition}\r\n    Suppose $\\pi:\\tilde{X}\\to X$ is a covering map and $\\gamma:[0,1]\\to X$ is a path.\r\n    A lift of $\\gamma$ along $\\pi$ is a path $\\tilde{\\gamma}:[0,1]\\to\\tilde{X}$ such that $\\pi\\circ\\tilde{\\gamma}=\\gamma$.\r\n\\end{definition}\r\nObviously, lifts are not usually unique.\r\n\\begin{example}\r\n    The function $\\exp:\\mathbb C\\to\\mathbb C_\\star$ is a covering map.\r\n    Consider the path $\\gamma:[0,1]\\to \\mathbb C$ representing the unit circle, i.e. $\\gamma(t)=e^{2\\pi it}$, then both $t\\mapsto 2\\pi it$ and $t\\mapsto 2\\pi i+2\\pi it$ are lifts of $\\gamma$.\r\n\\end{example}\r\nAn interesting observation is that although we exhibited two different lifts, they do start at different points.\r\nAnd it is indeed a correct intuition.\r\n\\begin{proposition}[Uniqueness of Lifts]\r\n    Suppose $\\tilde{\\gamma}_1,\\tilde{\\gamma}_2$ are both lifts of $\\gamma$ along a covering $\\pi:\\tilde{X}\\to X$.\r\n    If $\\tilde{\\gamma}_1(0)=\\tilde{\\gamma}_2(0)$ then $\\tilde{\\gamma}_1=\\tilde{\\gamma}_2$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider the set\r\n    $$I=\\{t\\in[0,1]:\\tilde{\\gamma}_1(t)=\\tilde{\\gamma}_2(t)\\}$$\r\n    We shall show that it is both open and closed, which shows the proposition as $[0,1]$ is connected.\r\n    It is obviously closed as $\\tilde{\\gamma}_1,\\tilde{\\gamma}_2$ are continuous and $[0,1]^2$ is Hausdorff.\r\n    So it remains to show it is open.\r\n    Let $t\\in I$.\r\n    As $\\pi$ is a covering map, $\\tilde{\\gamma}_1(t)=\\tilde{\\gamma}_2(t)$ has a neighbourhood $\\tilde{N}$ such that $\\pi|_{\\tilde{N}}$ is a homeomorphism.\r\n    As $\\gamma$ is continuous, there is $\\delta>0$ such that $\\gamma(t-\\delta,t+\\delta)\\in N$.\r\n    But for any $s$, $\\pi\\circ\\tilde{\\gamma}_1(s)=\\gamma(s)=\\pi\\circ\\tilde{\\gamma}_2(s)$.\r\n    So pick any $s\\in (t-\\delta,t+\\delta)$, we have\r\n    $$\\tilde{\\gamma}_1(s)=(\\pi|_{\\tilde{N}})^{-1}\\circ\\gamma(s)=\\tilde{\\gamma}_2(s)$$\r\n    Therefore $s\\in I$.\r\n    This shows that $I$ is open, as desired.\r\n\\end{proof}\r\nNow, even if $\\pi$ is surjective, lifts may not exist.\r\n\\begin{example}[Counterexample]\r\n    Consider $X=\\mathbb C_\\star,\\tilde{X}=\\mathbb R+i(-\\pi,2\\pi)$ and $\\pi=\\exp|_D$, but then we cannot lift the path $t\\mapsto e^{2\\pi it}$.\r\n\\end{example}\r\nBut note that the $\\pi$ in the example above is not a regular covering map.\r\nIn fact, a lift does exist if $\\pi$ is regular.\r\n\\begin{proposition}[Path-Lifting Lemma]\r\n    Let $\\pi:\\tilde{X}\\to X$ be a regular covering map and $\\gamma:[0,1]\\to X$ is a path.\r\n    Suppose $\\pi(\\tilde{x})=\\gamma(0)$, then there is a unique lift $\\tilde\\gamma$ of $\\gamma$ such that $\\tilde{\\gamma}(0)=\\tilde{x}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suffices to show the existence.\r\n    Let\r\n    $$I=\\{t\\in [0,1]:\\gamma|_{[0,t]}\\text{ can be lifted to some }\\tilde\\gamma\\text{ with }\\tilde{\\gamma}(0)=\\tilde{x}\\}$$\r\n    Again we will show that $I$ is both open and closed.\\\\\r\n    To see $I$ is closed, consider a sequence $t_n\\to\\tau$ where $t_n\\in I$ for all $I$.\r\n    We shall show that $\\tau\\in I$.\r\n    As $\\pi$ is regular, there is some open $U\\ni\\gamma(\\tau)$ such that\r\n    $$\\pi^{-1}(U)\\cong\\coprod_{\\delta\\in D}U_\\delta$$\r\n    for some set $D$.\r\n    Throwing away finitely many terms we can assume $\\gamma(t_n)\\in U$ for any $t$, consequently $\\tilde{\\gamma}(t_n)$ are all in the same $U_\\delta$.\r\n    Set $\\tilde{\\gamma}(\\tau)=(\\pi|_{U_\\delta})^{-1}\\circ\\gamma(\\tau)$ extends $\\tilde{\\gamma}$ continuous to $\\tau$, so $\\tau\\in I$.\\\\\r\n    To see $I$ is open, let $\\tau\\in I$ and choose open $U\\ni \\gamma(\\tau)$ such that\r\n    $$\\pi^{-1}(U)\\cong\\coprod_{\\delta\\in D}U_\\delta$$\r\n    for a set $D$.\r\n    There is a unique $\\delta$ such that $\\tilde{\\gamma}(\\tau)\\in U_\\delta$.\r\n    Choose $\\epsilon>0$ such that $|t-\\tau|<\\epsilon\\implies \\gamma(t)\\in U$.\r\n    So we want to extend $\\tilde{\\gamma}$ via $\\tilde\\gamma(t)=(\\pi|_{U_\\delta})^{-1}\\circ\\gamma(t)$ for $|t-\\tau|<\\epsilon$, which works.\r\n    Therefore $I$ is open, as required.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $X$ be a topological space and $\\alpha,\\beta:[0,1]\\to X$ paths with $\\alpha(0)=\\beta(0),\\alpha(1)=\\beta(1)$.\r\n    We say $\\alpha,\\beta$ are homotopic (or $\\alpha\\simeq\\beta$) if there is a family of paths $(\\alpha_s)_{s\\in[0,1]}$ such that:\\\\\r\n    1. $\\alpha_0=\\alpha,\\alpha_s(1)=\\beta$.\\\\\r\n    2. $\\alpha_s(0)=\\alpha(0),\\alpha_s(1)=\\alpha(1)$ for any $s$.\\\\\r\n    3. The map $(t,s)\\mapsto\\alpha_s(t)$ is continuous.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A topological space $X$ is simply connected if:\\\\\r\n    1. $X$ is path-connected.\\\\\r\n    2. Every pair of paths $\\alpha,\\beta:[0,1]\\to X$ with the same endpoints are homotopic.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Let $D\\subset\\mathbb C$ be a convex domain, then the formula\r\n    $$\\alpha_s(t)=(1-s)\\alpha(t)+s\\beta(t)$$\r\n    gives a homotopy between any two paths $\\alpha,\\beta$ with same endpoints.\r\n\\end{remark}\r\n\\begin{example}\r\n    $\\mathbb C$, the unit disk and half-plane are simply connected.\r\n\\end{example}\r\n\\begin{theorem}[Monodromy Theorem, aka Homotopy Lifting Lemma]\\label{monodromy}\r\n    Let $\\pi:\\tilde{X}\\to X$ be a covering map and $\\alpha,\\beta$ in $X$ be such that:\\\\\r\n    1. $\\alpha\\simeq\\beta$ in $X$.\\\\\r\n    2. There are lifts $\\tilde\\alpha$ of $\\alpha$ and $\\tilde\\beta$ of $\\beta$ along the covering.\\\\\r\n    3. Every path $\\gamma$ in $X$ with $\\gamma(0)=\\alpha(0)=\\beta(0)$ has a lift $\\tilde{\\gamma}$ to $\\tilde{X}$ with $\\tilde{\\gamma}(0)\\tilde{\\alpha}(0)=\\tilde{\\beta}(0)$.\\\\\r\n    Then $\\tilde{\\alpha}\\simeq\\tilde{\\beta}$.\r\n    In particular, $\\tilde{\\alpha}\\simeq\\tilde{\\beta}$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    See Algebraic Topology.\r\n\\end{proof}\r\n\\begin{note}\r\n    The requirements (ii) and (iii) are automatically satisfied if $\\pi$ is regular.\r\n\\end{note}", "meta": {"hexsha": "0c7f079491ed4037b607a077f2533fb71ec23157", "size": 5757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/cover.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": "7/cover.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": "7/cover.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": 60.6, "max_line_length": 192, "alphanum_fraction": 0.6381796074, "num_tokens": 1978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110203, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6256773103031463}}
{"text": "\\section{First Order Homogeneous Linear Equations}\\label{sec:first order homogeneous linear}\nA simple, but important and useful, type of separable equation is the\n\\dfont{first order homogeneous linear equation}:\n\n\\begin{definition}{First Order Homogeneous Linear Equation}{First Order Homogeneous Linear Equation}\\label{First Order Homogeneous Linear Equation}\nA first order homogeneous linear differential equation\nis one of\nthe form $\\ds y' + p(t)y=0$\nor equivalently\n$\\ds y' = -p(t)y$.\n\\end{definition}\n\n``Homogeneous'' refers to the zero on the right side of the equation, provided that $y'$ and $y$ are on the left. ``Linear'' in this definition indicates that both $y'$ and $y$ appear independently and explicitly; we don't see $y'$ or $y$ to any power greater than 1, or multiplied by each other (i.e. $y'y$).\n\n\\begin{example}{Linear Examples}{Linear Examples}\\label{Linear Examples}\n The equation $\\ds y' = 2t(25-y)$ can be written\n$\\ds y' + 2ty= 50t$. This is linear, but not homogeneous. The\nequation $\\ds y'=ky$, or $\\ds y'-ky=0$ is linear and\nhomogeneous, with a particularly simple $p(t)=-k$.\nThe equation $y'+y^2=0$ is homogeneous, but not linear.\n\\end{example}\n\nSince first order homogeneous linear equations are separable, we can\nsolve them in the usual way:\n\\begin{eqnarray*}\ny' &=& -p(t)y\\cr\n\\int {1\\over y}\\,dy &=& \\int -p(t)\\,dt\\cr\n\\ln|y| &=& P(t)+C\\cr\ny&=&\\pm\\,e^{P(t)}\\cr\ny&=&Ae^{P(t)},\n\\end{eqnarray*}\nwhere $P(t)$ is an anti-derivative of $-p(t)$. As in previous\nexamples, if we allow $A=0$ we get the constant solution $y=0$.\n\n\\begin{example}{Solving an IVP}{Solving an IVP}\\label{Solving an IVP}\n Solve the initial value problem \n$$\\ds y' + y\\cos t =0,$$\nsubject to $y(0)=1/2$ and $y(2)=1/2$.\n\\end{example}\n\n\\begin{solution}\nWe start with\n$$P(t)=\\int -\\cos t\\,dt = -\\sin t,$$\nso the general solution to the differential equation is\n$$y=Ae^{-\\sin t}.$$\nTo compute $A$ we substitute:\n$$ {1\\over 2} = Ae^{-\\sin 0} = A,$$\nso the solutions is \n$$ y = {1\\over 2} e^{-\\sin t}.$$\nFor the second problem,\n\\begin{eqnarray*}\n{1\\over 2} &=& Ae^{-\\sin 2}\\cr\nA &=& {1\\over 2}e^{\\sin 2}\n\\end{eqnarray*}\nso the solution is \n$$ y = {1\\over 2}e^{\\sin 2}e^{-\\sin t}.$$\n\\vskip-15pt\\end{solution}\n\n\\begin{example}{}{}\\label{}\n Solve the initial value problem $ty'+3y=0$, $y(1)=2$,\nassuming $t>0$.\n\\end{example}\n\n\\begin{solution}\nWe write the equation in standard form: $y'+3y/t=0$. Then\n$$P(t)=\\int -{3\\over t}\\,dt=-3\\ln t$$\nand \n$$ y=Ae^{-3\\ln t}=At^{-3}.$$\nSubstituting to find $A$:\n$\\ds 2=A(1)^{-3}=A$, so the solution is $\\ds y=2t^{-3}$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:first order homogeneous linear}}\n\n\\begin{enumialphparenastyle}\n\nFind the general solution of each equation in the following exercises.\n\n\\begin{multicols}{2}\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'+5y=0$\n\\begin{sol}\n $\\ds y=Ae^{-5t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'-2y=0$\n\\begin{sol}\n $\\ds y=Ae^{2t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'+{y\\over 1+t^2}=0$\n\\begin{sol}\n $\\ds y=Ae^{-\\arctan t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'+t^2y=0$\n\\begin{sol}\n $\\ds y=Ae^{-t^3/3}$\n\\end{sol}\n\\end{ex}\n\n\\end{multicols}\n\nIn the following exercises, solve the initial value problem.\n\n\\begin{multicols}{2}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' + y=0$, $y(0)=4$\n\\begin{sol}\n $\\ds y=4e^{-t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' -3y=0$, $y(1)=-2$\n\\begin{sol}\n $\\ds y=-2e^{3t-3}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' + y\\sin t = 0$, $y(\\pi)=1$\n\\begin{sol}\n $\\ds y=e^{1+\\cos t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' +ye^t=0$, $y(0)=e$\n\\begin{sol}\n $\\ds y=e^2e^{-e^t}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' +y\\sqrt{1+t^4}=0$, $y(0)=0$\n\\begin{sol}\n $\\ds y=0$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y' + y\\cos(e^t)=0$, $y(0)=0$\n\\begin{sol}\n $\\ds y=0$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds ty' - 2y = 0$, $y(1)=4$\n\\begin{sol}\n $\\ds y=4t^2$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds t^2y' + y = 0$, $y(1)=-2$, $t>0$\n\\begin{sol}\n $\\ds y=-2e^{(1/t)-1}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds t^3y' = 2y$, $y(1)=1$, $t>0$\n\\begin{sol}\n $\\ds y=e^{1-t^{-2}}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds t^3y' = 2y$, $y(1)=0$, $t>0$\n\\begin{sol}\n $\\ds y=0$\n\\end{sol}\n\\end{ex}\n\n\\end{multicols}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A function $y(t)$ is a solution of $\\ds y' +\nky=0$. Suppose that $y(0)=100$ and $y(2)=4$. Find $k$ and find $y(t)$.\n\\begin{sol}\n $k=\\ln 5$, $\\ds y=100e^{-t\\ln 5}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A function $y(t)$ is a solution of $\\ds y' +\nt^ky=0$. Suppose that $y(0)=1$ and $y(1)=e^{-13}$. Find $k$ and find\n$y(t)$. \n\\begin{sol}\n $k=-12/13$, $\\ds y=\\exp(-13 t^{1/13})$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A bacterial culture grows at a rate proportional to its\npopulation. If the population is one million at $t=0$ and 1.5\nmillion at $t=1$ hour, find the population as a function of time.\n\\begin{sol}\n $\\ds y=10^6e^{t\\ln(3/2)}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A radioactive element decays with a half-life of 6 years. If\na mass of the element weighs ten pounds at $t=0$, find the amount of\nthe element at time $t$.\n\\begin{sol}\n $\\ds y=10e^{-t\\ln(2)/6}$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "54ad6fc37481b6f14979d295d1e6c103b5bcd4eb", "size": 5329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-2-first-order-homo-linear.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-2-first-order-homo-linear.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-2-first-order-homo-linear.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.6550387597, "max_line_length": 309, "alphanum_fraction": 0.5937324076, "num_tokens": 2054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.625617899444057}}
{"text": "%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\input{../../doc/related_pages/header.tex}\r\n\\input{../../doc/related_pages/newcommands.tex}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{document}\r\n\r\n\\title{The heat diffusion project}\r\n\\author{ M.~Wiesenberger and M.~Held}\r\n\\maketitle\r\n\r\n\\begin{abstract}\r\n  This is a program for the 3d heat diffusion in arbitrary magnetic field\r\n  geometry.\r\n  \\end{abstract}\r\n\r\n\\section{Equations}\r\nThe temperature $T$ follows a non-isotropic heat diffusion equation\r\n\\begin{align}\r\n\\frac{\\partial T}{\\partial t} = \\nu_\\perp \\Delta_\\perp T + \\nu_\\parallel\\Delta_\\parallel T\r\n\\label{eq:temperature}\r\n\\end{align}\r\nwith\r\n\\begin{align}\r\n\\Delta_\\parallel T &= \\nabla\\cdot ( \\bhat\\bhat\\cdot\\nabla T) \\\\\r\n\\Delta_\\perp T     &= -\\nabla\\cdot( \\bhat\\times(\\bhat\\times \\nabla T)) \\equiv \\nabla\\cdot (h \\nabla T) \\\\\r\nh^{ij} &= g^{ij} - b^ib^j\r\n\\end{align}\r\n$\\bhat = \\bhat(\\vec x)$ is the prescribed magnetic field unit vector, $g$ is the\r\nmetric and $h$ is the projection\r\ntensor.\r\n$\\nu_\\parallel$ and $\\nu_\\perp$ are the respective conduction\r\ncoefficients parallel and perpendicular to this field.\r\n\r\n\\subsection{Simulation domain}\r\nWe define the simulation box as\r\n$[ R_{\\min}, R_{\\max}]\\times [Z_{\\min}, Z_{\\max}] \\times [0,2\\pi]$,\r\nwhere we define\r\n\\begin{align} \\label{eq:box}\r\n    R_{\\min}&=R_0-\\varepsilon^{R-}a\\quad\r\n    &&R_{\\max}=R_0+\\varepsilon^{R+}a\\nonumber\\\\\r\n    Z_{\\min}&=-\\varepsilon^{Z-}ae\\quad\r\n    &&Z_{\\max}=\\varepsilon^{Z+}ae\r\n\\end{align}\r\nwhere $a$ is the minor radius, $e$ is the elongation of the flux surfaces and\r\nthe $\\varepsilon$ are free parameters to be specified by the user.\r\n\r\n\\subsection{Initialization}\r\nInitialization of $T$ is a Gaussian\r\n\\begin{align} \\label{eq:initial}\r\n  T(R,Z,\\varphi) = 1 + A\\exp\\left(\r\n      -\\frac{(R-R_i)^2 + (Z-Z_i)^2}{2\\sigma^2} - \\frac{(\\varphi-\\pi)^2}{2\\sigma_\\varphi^2}\\right)\r\n\\end{align}\r\nwhere $R_i = p_x a$ and $Z_i = p_y a$ denote the initial position, $A$ is the amplitude and $\\sigma$ the\r\nradius of the blob.\r\n\\subsection{Diagnostics}\r\nIntegrating Eq.~\\eqref{eq:temperature} over the volume yields\r\n\\begin{align}\r\n \\frac{\\partial}{\\partial t} \\int T \\dV &=\r\n    \\int \\dV ( \\nu_\\perp \\Delta_\\perp + \\nu_\\parallel \\Delta_\\parallel T) \\\\\r\n \\frac{\\partial}{\\partial t} \\int T^2/2 \\dV &=\r\n    \\int \\dV ( \\nu_\\perp T\\Delta_\\perp T + \\nu_\\parallel T\\Delta_\\parallel T)\r\n\\label{}\r\n\\end{align}\r\n\\section{Numerical methods}\r\ndiscontinuous Galerkin on structured grid\r\n\\rowcolors{2}{gray!25}{white} %%% Use this line in front of longtable\r\n\\begin{longtable}{ll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Term} &  \\textbf{Method} & \\textbf{Description}  \\\\ \\midrule\r\ncoordinate system & Cylindrical 3D & equidistant discretization of $[R_0-a,R_0+a] \\times [-a,a] \\times [0,2\\pi]$, equal number of Gaussian nodes in R and Z, one node in $\\varphi$ \\\\\r\n$\\Delta_\\parallel$ & FCI & forward-backward symmetric sym, See the documentation on DS\\\\\r\ntime &  Adaptive embedded ARK-4-2-3 & $3rd$ order accurate in both\r\nexplicit and implicit parts\\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\n\\section{Compilation and useage}\r\nThere are two programs heat.cu and heat\\_hpc.cu . Compilation with\r\n\\begin{verbatim}\r\nmake device = <omp or gpu>\r\n\\end{verbatim}\r\nRun with\r\n\\begin{verbatim}\r\npath/to/feltor/src/heat/heat input.json geometry_params.json\r\npath/to/feltor/src/heat/heat_hpc input.json geometry_params.json output.nc\r\n\\end{verbatim}\r\nAll programs write performance informations to std::cout.\r\nThe first opens a terminal window with life simulation results\r\nthe\r\nother writes the results to disc. Both programs run on shared memory\r\nsystems.\r\nFor the hpc code, there is another mode:\r\n\\begin{verbatim}\r\npath/to/feltor/src/heat/heat_hpc input.json geometry_params.json output.nc input.nc\r\n\\end{verbatim}\r\nIn this case the temperature field of \\code{input.nc} at the last output\r\ntime is read\r\nand taken as a reference solution.\r\n\r\n\\subsection{Input file structure}\r\nInput file format: json\r\n\r\n%%This is a booktabs table\r\n\\begin{longtable}{llll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Example} & \\textbf{Default} & \\textbf{Description}  \\\\ \\midrule\r\n  n      & integer & 3 & - &\\# Gaussian nodes in x and y \\\\\r\n  Nx     & integer &20& - &\\# grid points in x \\\\\r\n  Ny     & integer &40& - &\\# grid points in y \\\\\r\n  Nz     & integer &60& - &\\# grid points in z \\\\\r\n  dt     & integer &0.001& - &initial time step\\\\\r\n  cx & integer & 2 & 1 & output contains n*Nx/cx points in x,\r\n    has to divde Nx evenly\\\\\r\n  cy & integer & 2 & 1 & output contains n*Ny/cy points in y,\r\n    has to divde Ny evenly\\\\\r\n  itstp  & integer &2  & - &   steps between outputs \\\\\r\n  maxout & integer &100& - &      \\# outputs excluding first \\\\\r\n  eps\\_time  & float &1e-10   & - & accuracy of implicit solver in time-stepper \\\\\r\n  rtol  & float  & 1e-6  & - & desired tolerance of adaptive time-stepper \\\\\r\n  nu\\_parallel    & float &100   & - & parallel viscosity $\\nu_\\parallel$ \\\\\r\n  nu\\_perp    & float &0   & - & perpendicular viscosity $\\nu_\\perp$ \\\\\r\n  amplitude  & float &0.1    & - & amplitude $A$ of the blob in Eq.~\\eqref{eq:initial}\\\\\r\n  sigma      & float &5     & - & blob radius $\\sigma$ in $R$ and $Z$ in Eq.~\\eqref{eq:initial} \\\\\r\n  sigma\\_z   & float &0.025  & - & variance in $\\varphi$ in units of $R_0$ in Eq.~\\eqref{eq:initial}  \\\\\r\n  posX       & float &0.8    & - & blob $R$-position in units of $a$ in Eq.~\\eqref{eq:initial} \\\\\r\n  posY       & float &0    & - & blob $Z$-position in units of $a$ in Eq.~\\eqref{eq:initial} \\\\\r\n  bcx   & char & \"NEU\"      & - & boundary condition in R (one of PER, DIR, NEU, DIR\\_NEU or NEU\\_DIR) \\\\\r\n  bcy   & char & \"NEU\"      & - & boundary condition in Z (one of PER, DIR, NEU, DIR\\_NEU or NEU\\_DIR) \\\\\r\n  boxscaleRp & float &  1.05, & - & $\\varepsilon^{R+}$ in Eq.~\\eqref{eq:box} \\\\\r\n  boxscaleRm & float &  1.05, & - & $\\varepsilon^{R-}$ in Eq.~\\eqref{eq:box} \\\\\r\n  boxscaleZp & float &  1.05, & - & $\\varepsilon^{Z+}$ in Eq.~\\eqref{eq:box} \\\\\r\n  boxscaleZm & float &  1.15, & - & $\\varepsilon^{Z-}$ in Eq.~\\eqref{eq:box} \\\\\r\n  mx     & integer & 10 & - & refinement factor of DS in x \\\\\r\n  my     & integer & 10 & - & refinement factor of DS in y \\\\\r\n  rk4eps & float & 0.01 & 1e-5 & Accuracy of fieldline integration in DS \\\\\r\n  diff       & char & non-adjoint & non-adjoint & adjoint, non-adjoint, elliptic (discretization for $\\Delta_\\parallel$) \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\nThe default value is taken if the value name is not found in the input file. If there is no default and\r\nthe value is not found,\r\nthe program exits with an error message.\r\n\r\n\\subsection{Geometry file structure}\r\nFile format: json\r\n\r\n%%This is a booktabs table\r\n\\begin{longtable}{llll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Example} & \\textbf{Default} & \\textbf{Description}  \\\\ \\midrule\r\n    A      & float & 1 &  - & Solovev parameter \\\\\r\n    R\\_0   & float & - & -  & Major radius in $\\rho_s$ \\\\\r\n    C      & float[12] &  - & - & Solovev coefficients \\\\\r\n    elongation & float & 1 & - & Elongation \\\\\r\n    triangularity & float & 0 & - & Triangularity \\\\\r\n    inverseaspectratio & float & 0.16667 & - & $a/R_0$ \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\n\\subsection{Structure of output file}\r\nOutput file format: netcdf-4/hdf5\r\n%\r\n%Name | Type | Dimensionality | Description\r\n%---|---|---|---|\r\n\\begin{longtable}{lll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Dimension} & \\textbf{Description}  \\\\ \\midrule\r\ninputfile  &     text attribute & 1 & verbose input file as a string \\\\\r\ngeomfile   &     text attribute & 1 & verbose geometry input file as a string \\\\\r\nenergy\\_time     & Dataset & 1 & timesteps at which 1d variables are written \\\\\r\ntime             & Dataset & 1 & time at which temperature is written \\\\\r\nx                & Dataset & 1 & x-coordinate  \\\\\r\ny                & Dataset & 1 & y-coordinate \\\\\r\nz                & Dataset & 1 & z-coordinate \\\\\r\nT                & Dataset & 4 (time, z, y, x) & temperature $T$ \\\\\r\nenergy           & Dataset & 1 (energy\\_time) & total energy integral  \\\\\r\nentropy          & Dataset & 1 (energy\\_time) & total entropy integral  \\\\\r\nmass             & Dataset & 1 (energy\\_time) & mass integral   \\\\\r\ndEdt             & Dataset & 1 (energy\\_time) & change of energy per time  \\\\\r\ndissipation      & Dataset & 1 (energy\\_time) & diffusion integrals  \\\\\r\naccuracy         & Dataset & 1 (energy\\_time) & accuracy in time  \\\\\r\nerror            & Dataset & 1 (energy\\_time) & relative distance to temperature field at time 0\\\\\r\nrelerror         & Dataset & 1 (energy\\_time) & relative difference to reference solution if one is provide, else 0 \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\n%..................................................................\r\n\\bibliography{../../doc/related_pages/references}\r\n%..................................................................\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "2af553b885f989da695972661ca5cdb7832c607a", "size": 9071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/heat/heat.tex", "max_stars_repo_name": "RaulGerru/FELTOR_Raul", "max_stars_repo_head_hexsha": "a566f8a9003ade437e093334877f839f3dfd0260", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2016-06-28T14:34:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T08:50:48.000Z", "max_issues_repo_path": "src/heat/heat.tex", "max_issues_repo_name": "RaulGerru/FELTOR_Raul", "max_issues_repo_head_hexsha": "a566f8a9003ade437e093334877f839f3dfd0260", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-01-18T16:06:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T19:11:42.000Z", "max_forks_repo_path": "src/heat/heat.tex", "max_forks_repo_name": "mrheld/feltor", "max_forks_repo_head_hexsha": "c70bc6bb43f39261f6236df88e16610d08cb98ca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-06-27T13:18:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T08:12:25.000Z", "avg_line_length": 46.5179487179, "max_line_length": 182, "alphanum_fraction": 0.6252893838, "num_tokens": 2853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6256178987142795}}
{"text": "\\documentclass[pre,aps,superscriptaddress,nofootinbib]{revtex4}\n\n\\usepackage{amsmath,amsfonts,amssymb,bm,graphicx,hyperref,listings,xcolor,float}\n\\setlength{\\parindent}{0pt}\n\n\\begin{document}\n\n\\title{2 RTPs on a ring}\n\\author{Yann-Edwin Keta}\n\\maketitle\n\n% \\maketitle\n\n\\nocite{Slowman2016, Nemoto2016, Chetrite2015}\n\n\\section{Model}\n\n\\subsection{Fokker-Planck equations}\n\nWe consider 2 run-and-tumble particles (RTPs), with swim speed $v_0$ and tumble rate $\\tau^{-1}$ on a linear ring of length $L$. With $r_1, r_2 \\in [0, L]$ the positions and $\\alpha_1, \\alpha_2 = \\pm$ the states of each particles, and $V(r_1, r_2) = V(|r_1 - r_2|)$ the potential of interactions between these particles, we have the equations of motion\n\\begin{equation}\n\\dot{r}_i = \\alpha_i v_0 - \\partial_{r_i} V(|r_1 - r_2|)\n\\label{EOM}\n\\end{equation}\nand the Fokker-Planck equations for the joint distribution of positions\n\\begin{equation}\n\\begin{aligned}\n\\dot{P}_{\\alpha_1, \\alpha_2}(r_1, r_2) =\n  &- v_0(\\alpha_1 \\partial_{r_1} + \\alpha_2 \\partial_{r_2}) P_{\\alpha_1\\alpha_2}(r_1, r_2)\n    &&\\to \\text{Propulsion}\\\\\n  &+ \\partial_{r_1} (P_{\\alpha_1\\alpha_2}(r_1, r_2)\\partial_{r_1}V(|r_1 - r_2|))\n    &&\\to \\text{Interaction}\\\\\n  &+ \\partial_{r_2} (P_{\\alpha_1\\alpha_2}(r_1, r_2)\\partial_{r_2}V(|r_1 - r_2|))\n    &&\\\\\n  &+ \\tau^{-1} (P_{\\overline{\\alpha_1}\\alpha_2}(r_1, r_2) + P_{\\alpha_1\\overline{\\alpha_2}}(r_1, r_2) - 2 P_{\\alpha_1\\alpha_2}(r_1, r_2))\n    &&\\to \\text{Tumble}\\\\\n  =& \\, \\mathcal{L}^{\\dagger}_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r_1, r_2)\n\\end{aligned}\n\\label{FP0}\n\\end{equation}\nwith $\\mathcal{L}^{\\dagger}_{\\alpha_1\\alpha_2}$ the Fokker-Planck operator.\\\\\n\nWe introduce $r \\equiv r_2 - r_1 \\geq 0$, such that $\\partial_{r_1} \\equiv - \\partial_r$ and $\\partial_{r_2} = \\partial_r$, with which we can define the symmetries\n\\begin{eqnarray}\n\\label{evensymmetry}\nP_{++}(r) = P_{--}(r),\\\\\n\\label{oddsymmetry}\nP_{+-}(r) = P_{-+}(L - r),\n\\end{eqnarray}\nand the interaction potential\n\\begin{align*}\nV(r) = \\begin{cases} 0 &\\text{ if } r \\in ]0, L[ \\\\ \\infty &\\text{ otherwise} \\end{cases}\n\\end{align*}\nsuch that, with Eq. (\\ref{EOM}), we get for particles with opposite directions\n\\begin{equation}\n- \\partial_r V(0) = \\partial_r V(L) = v_0.\n\\end{equation}\nbecause of mutual hindrance.\\\\\n\nWe can solve the steady state problem with the normalisation condition\n\\begin{equation}\n\\int_0^L \\mathrm{d}r \\, \\sum_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r) = 1\n\\label{normalisation}\n\\end{equation}\nthe bulk equations\n\\begin{equation}\n\\dot{P}_{\\alpha_1\\alpha_2}(r \\in ]0, L[) = 0\n\\label{bulk}\n\\end{equation}\nthe left boundary equations\n\\begin{equation}\n\\int_{0^-}^{0^+} \\mathrm{d}r \\, \\dot{P}_{\\alpha_1\\alpha_2}(r) = 0\n\\label{leftboundary}\n\\end{equation}\nand the right boundary equations\n\\begin{equation}\n\\int_{L^-}^{L^+} \\mathrm{d}r \\, \\dot{P}_{\\alpha_1\\alpha_2}(r) = 0.\n\\label{rightboundary}\n\\end{equation}\n\n\\subsection{Biased ensemble}\n\nWe define our biasing quantity\n\\begin{equation}\n\\dot{Z} = \\sum_{i=1}^2 - \\partial_{r_i} V(r) \\alpha_i v_0 = v_0 (\\alpha_1 - \\alpha_2) \\partial_r V(r)\n\\end{equation}\nwhich is non-zero only at contact, and the tilted generator\n\\begin{equation}\n\\mathcal{W}^{\\dagger}_{\\alpha_1\\alpha_2} = \\mathcal{L}^{\\dagger}_{\\alpha_1\\alpha_2} - s \\dot{Z}\n\\end{equation}\nwith $s$ the biasing parameter, which eigenvalue problem\n\\begin{equation}\n\\psi P_{\\alpha_1\\alpha_2}(r) = \\mathcal{W}^{\\dagger}_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r)\n\\label{eigenproblem}\n\\end{equation}\nwe have to solve for $\\psi(s)$ its largest eigenvalue, which defines the dynamical free energy.\\\\\n\nWhile the symmetries (Eqs. (\\ref{evensymmetry}, \\ref{oddsymmetry})) and the normalisation condition (Eq. (\\ref{normalisation})) remains unchanged, we have that the bulk equations (Eq. (\\ref{bulk})), the left boundary equations (Eq. \\ref{leftboundary}), and the right boundary equations (Eq. \\ref{rightboundary}) become\n\\begin{eqnarray}\n\\label{bulk:biased}\n\\psi P_{\\alpha_1\\alpha_2}(r \\in ]0, L[) = \\mathcal{W}^{\\dagger}_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r \\in ]0, L[)\\\\\n\\label{leftboundary:biased}\n\\int_{0^-}^{0^+} \\mathrm{d}r \\, \\psi P_{\\alpha_1\\alpha_2}(r) = \\int_{0^-}^{0^+} \\mathrm{d}r \\, \\mathcal{W}^{\\dagger}_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r)\\\\\n\\label{rightboundary:biased}\n\\int_{L^-}^{L^+} \\mathrm{d}r \\, \\psi P_{\\alpha_1\\alpha_2}(r) = \\int_{L^-}^{L^+} \\mathrm{d}r \\, \\mathcal{W}^{\\dagger}_{\\alpha_1\\alpha_2} P_{\\alpha_1\\alpha_2}(r)\n\\end{eqnarray}\nrespectively.\n\n\\section{Unbiased steady state distribution}\n\nWe use the following ansatz for the unbiased ($s = 0$) steady state distribution\n\\begin{equation}\nP_{\\alpha_1\\alpha_2}(r) = a_{\\alpha_1\\alpha_2} + b_{\\alpha_1\\alpha_2} \\delta(r) + c_{\\alpha_1\\alpha_2} \\delta(L - r)\n\\end{equation}\nwhich satisfies the normalisation condition (Eq. (\\ref{normalisation}))\n\\begin{equation}\n\\sum_{\\alpha_1\\alpha_2} \\left(L a_{\\alpha_1\\alpha_2} + b_{\\alpha_1\\alpha_2} + c_{\\alpha_1\\alpha_2}\\right) = 1\n\\end{equation}\nthe bulk equations (Eq. (\\ref{bulk}))\n\\begin{eqnarray}\n\\tau^{-1} (a_{+-} + a_{-+} - 2 a_{++}) = 0\\\\\n\\tau^{-1} (a_{+-} + a_{-+} - 2 a_{--}) = 0\\\\\n\\tau^{-1} (a_{++} + a_{--} - 2 a_{+-}) = 0\\\\\n\\tau^{-1} (a_{++} + a_{--} - 2 a_{-+}) = 0\n\\end{eqnarray}\nthe left boundary equations (Eq. (\\ref{leftboundary}))\n\\begin{eqnarray}\n\\tau^{-1}(b_{+-} + b_{-+} - 2 b_{++}) = 0\\\\\n\\tau^{-1}(b_{+-} + b_{-+} - 2 b_{--}) = 0\\\\\n2 v_0 a + \\tau^{-1}(b_{++} + b_{--} - 2 b_{+-}) = 0\\\\\n- 2 v_0 a + \\tau^{-1}(b_{++} + b_{--} - 2 b_{-+}) = 0\n\\end{eqnarray}\nthe right boundary equations (Eq. (\\ref{rightboundary}))\n\\begin{eqnarray}\n\\tau^{-1}(c_{+-} + c_{-+} - 2 c_{++}) = 0\\\\\n\\tau^{-1}(c_{+-} + c_{-+} - 2 c_{--}) = 0\\\\\n- 2 v_0 a + \\tau^{-1}(c_{++} + c_{--} - 2 c_{+-}) = 0\\\\\n2 v_0 a + \\tau^{-1}(c_{++} + c_{--} - 2 c_{-+}) = 0\n\\end{eqnarray}\nand the symmetries (Eqs. (\\ref{evensymmetry}, \\ref{oddsymmetry})).\\\\\n\nWe get\n\\begin{eqnarray}\n\\label{s0++}\nP_{++}(r) = a + l a \\delta(r) + l a \\delta(L - r)\\\\\n\\label{s0--}\nP_{--}(r) = a + l a \\delta(r) + l a \\delta(L - r)\\\\\n\\label{s0+-}\nP_{+-}(r) = a + 2 l a \\delta(r)\\\\\n\\label{s0-+}\nP_{-+}(r) = a + 2 l a \\delta(L - r)\n\\end{eqnarray}\nwith\n\\begin{equation}\na = \\frac{1}{4(L + 2l)}\n\\label{smooth_unbiased}\n\\end{equation}\nand the persistence length $l = v_0 \\tau$.\n\n\\section{Biased steady state distribution}\n\\label{sec:biased-distribution}\n\n\\subsection{Exact solution}\n\nWe use the following ans\\\"atze for the steady state distribution\n\\begin{eqnarray}\nP_{++}(r) = P_{--}(r) = \\beta(r) + \\gamma_- \\delta(r) + \\gamma_+ \\delta(L - r)\\\\\nP_{+-}(r) = \\varepsilon(r) + \\zeta \\delta(r)\\\\\nP_{-+}(r) = \\theta(r) + \\zeta \\delta(L - r)\\\\\n\\end{eqnarray}\nwith $\\varepsilon(r) = \\theta(L - r)$ according to Eq. (\\ref{oddsymmetry}).\\\\\n\nWe write the eigenvalue equations (Eq. (\\ref{eigenproblem}))\n\\begin{eqnarray}\n\\label{FP1}\n\\psi P_{\\alpha\\alpha}(r) = 2 \\partial_r(P_{\\alpha\\alpha}(r) \\partial_r V(r)) + \\tau^{-1} (P_{+-}(r) + P_{-+}(r) - 2 P_{\\alpha\\alpha}(r))\\\\\n\\label{FP2}\n\\psi P_{+-}(r) = 2 v_0 \\partial_r P_{+-}(r) + 2 \\partial_r(P_{+-}(r) \\partial_r V(r)) + \\tau^{-1}(2 P_{\\alpha\\alpha}(r) - 2 P_{+-}(r)) - 2 s v_0 \\partial_r V(r) P_{+-}(r)\\\\\n\\label{FP3}\n\\psi P_{-+}(r) = - 2 v_0 \\partial_r P_{-+}(r) + 2 \\partial_r(P_{-+}(r) \\partial_r V(r)) + \\tau^{-1}(2 P_{\\alpha\\alpha}(r) - 2 P_{-+}(r)) + 2 s v_0 \\partial_r V(r) P_{-+}(r)\n\\end{eqnarray}\nand integrate from Eqs. (\\ref{FP1}, \\ref{FP2}, \\ref{FP3}) the sum of $\\psi(2 P_{\\alpha\\alpha} + P_{+-} + P_{-+})$ between $0^-$ and $L^+$ to get\n\\begin{equation}\n\\psi = 4 s v_0 \\partial_r V(L) \\zeta = 4 s v_0^2 \\zeta\n\\label{psiZeta}\n\\end{equation}\nlinking the dynamical free energy $\\psi$ and the sticking term $\\zeta$.\\\\\n\nWe have the bulk equations (Eq. (\\ref{bulk:biased}))\n\\begin{eqnarray}\n\\label{bulk:biased1}\n\\psi \\beta(r) = \\tau^{-1} (\\varepsilon(r) + \\theta(r) - 2 \\beta(r))\\\\\n\\label{bulk:biased2}\n\\psi \\epsilon(r) = 2 v_0 \\varepsilon^{\\prime}(r) + \\tau^{-1} (2 \\beta(r) - 2 \\varepsilon(r))\\\\\n\\label{bulk:biased3}\n\\psi \\theta(r) = -2 v_0 \\theta^{\\prime}(r) + \\tau^{-1} (2 \\beta(r) - 2 \\theta(r))\n\\end{eqnarray}\nsuch that Eq. (\\ref{bulk:biased1}) gives\n\\begin{equation}\n\\beta(r) = (2 + \\tau\\psi)^{-1} (\\epsilon(r) + \\theta(r))\n\\end{equation}\nand the difference and sum of Eqs. (\\ref{bulk:biased2}, \\ref{bulk:biased3}) give\n\\begin{eqnarray}\n2 l (\\varepsilon(r) + \\theta(r))^{\\prime} = (2 + \\tau \\psi)(\\varepsilon(r) - \\theta(r))\\\\\n\\begin{aligned}\n2 l (\\varepsilon(r) - \\theta(r))^{\\prime} &= -4 \\beta(r) + (\\tau\\psi + 2)(\\varepsilon(r) + \\theta(r))\\\\\n&= \\left((\\tau\\psi + 2) - \\frac{4}{\\tau\\psi + 2}\\right)(\\varepsilon(r) + \\theta(r))\n\\end{aligned}\n\\end{eqnarray}\nwhere we set $A(r) = \\varepsilon(r) + \\theta(r)$ and $B(r) = \\varepsilon(r) - \\theta(r)$, which on the one hand verify\n\\begin{equation}\nA^{\\prime\\prime}(r) - k^2 A(r) = 0\n\\end{equation}\nwhere\n\\begin{equation}\nk^2 l^2 = \\tau \\psi \\left(\\frac{\\tau \\psi}{4} + 1\\right)\n\\label{kPsi}\n\\end{equation}\nand which general solution is\n\\begin{equation}\nA(r) = A_+ e^{- k r} + A_- e^{-k (L - r)}\n\\end{equation}\nand on the other hand\n\\begin{equation}\nB(r) = l(1 + \\tau \\psi/2)^{-1} A^{\\prime}(r) = kl (1 + \\tau\\psi/2)^{-1} (A_- e^{-k(L - r)} - A_+ e^{-k r})\n\\end{equation}\nfrom which we infer\n\\begin{eqnarray}\n\\label{epsilon}\n\\begin{aligned}\n\\varepsilon(r) &= \\frac{1}{2} (A(r) + B(r))\\\\\n&= \\frac{1}{2}\\left(1 - k l (1 + \\psi \\tau/2)^{-1}\\right) A_+ e^{- k r} + \\frac{1}{2}\\left(1 + k l (1 + \\psi \\tau/2)^{-1}\\right) A_- e^{- k (L - r)}\n\\end{aligned}\n\\mbox{}\\\\\n\\label{theta}\n\\begin{aligned}\n\\theta(r) &= \\frac{1}{2} (A(r) - B(r))\\\\\n&= \\frac{1}{2}\\left(1 + k l (1 + \\psi \\tau/2)^{-1}\\right) A_+ e^{- k r} + \\frac{1}{2}\\left(1 - k l (1 + \\psi \\tau/2)^{-1}\\right) A_- e^{- k (L - r)}\n\\end{aligned}\n\\end{eqnarray}\nwhere we note that the symmetry condition of Eq. (\\ref{oddsymmetry}) implies that $A_- = A_+$, and\n\\begin{equation}\n\\begin{aligned}\n\\beta(r) &= (\\tau\\psi + 2)^{-1}(\\varepsilon(r) + \\theta(r)) = (\\tau \\psi + 2)^{-1} A(r)\\\\\n&= (1 + \\tau\\psi/2)^{-1}(A_+ e^{-k r} + A_- e^{-k (L - r)})\n\\end{aligned}\n\\label{beta}\n\\end{equation}\nwhere we need to determine $A_+ = A_-$.\\\\\n\nWe have the left and right boundary equations (Eqs. (\\ref{leftboundary:biased}, \\ref{rightboundary:biased})) for $P_{\\alpha\\alpha}$\n\\begin{eqnarray}\n\\psi \\gamma_- = \\tau^{-1} (\\zeta - 2 \\gamma_-)\\\\\n\\psi \\gamma_+ = \\tau^{-1} (\\zeta - 2 \\gamma_+)\n\\end{eqnarray}\nsuch that\n\\begin{equation}\n\\gamma = \\gamma_- = \\gamma_+ = (\\tau \\psi + 2)^{-1} \\zeta\n\\label{ratio_gamma}\n\\end{equation}\nwhich with Eq. (\\ref{psiZeta}) gives\n\\begin{equation}\n\\psi = 4 s v_0^2 (\\tau \\psi + 2) \\gamma\n\\label{gammaPsi}\n\\end{equation}\nwhere we need to determine $\\gamma$.\\\\\n\nWe have the left boundary equations (Eq. (\\ref{leftboundary:biased})) for $P_{\\alpha\\overline{\\alpha}}$\n\\begin{eqnarray}\n\\label{LBe1}\n\\psi \\zeta = 2 v_0 \\varepsilon(0^+) + \\tau^{-1} (2 \\gamma - 2 \\zeta) - 2 s v_0 \\partial_r V(0) \\zeta\\\\\n\\label{LBe2}\n0 = - 2 v_0 \\varepsilon(L^-) + \\tau^{-1} 2 \\gamma\n\\end{eqnarray}\nfrom which we get\n\\begin{eqnarray}\n\\label{S1}\n\\left[(\\tau\\psi + 2)(\\tau\\psi + 2 - 2 s l v_0) - 2\\right] \\gamma - l \\left(1 - kl  (1 + \\tau\\psi/2)^{-1}\\right) A_+ - l \\left(1 + kl(1 + \\tau\\psi/2)^{-1}\\right) e^{-kL} A_- = 0\\\\\n\\label{S2}\n2 \\gamma - l \\left(1 - kl (1 + \\tau\\psi/2)^{-1}\\right) e^{-kL} A_+ - l \\left(1 + kl (1 + \\tau\\psi/2)^{-1}\\right) A_- = 0\n\\end{eqnarray}\nand the normalisation condition (Eq. (\\ref{normalisation}))\n\\begin{equation}\n(2 \\tau \\psi + 8) \\gamma + \\frac{1}{k} (1 - e^{-kL})(1 + (1 + \\tau\\psi/2)^{-1})(A_+ + A_-) = 1\n% 2((\\tau\\psi + 2) + 1) \\gamma + \\frac{1}{k} \\left(1 - e^{-kL}\\right)\\left(1 + (\\tau\\psi + 2)^{-1}\\right) A_+ + \\frac{1}{k} \\left(1 - e^{-kL}\\right)\\left(1 + (\\tau\\psi + 2)^{-1}\\right) A_- = 1\n\\label{S3}\n\\end{equation}\nso we can solve the system of Eqs. (\\ref{S1}, \\ref{S2}, \\ref{S3}) with respect to $\\gamma$, $A_+$, $A_-$, or equivalently with $A_+ = A_-$\n\\begin{eqnarray}\n\\label{S01}\n\\left[(\\tau\\psi + 2)(\\tau\\psi + 2 - 2 s l v_0) - 2\\right] \\gamma - l \\left[\\left(1 - kl  (1 + \\tau\\psi/2)^{-1}\\right) + \\left(1 + kl(1 + \\tau\\psi/2)^{-1}\\right) e^{-kL}\\right] A_- = 0\\\\\n\\label{S02}\n% 2((\\tau\\psi + 2) + 1) \\gamma + \\frac{2}{k} \\left(1 - e^{-kL}\\right)\\left(1 + (\\tau\\psi + 2)^{-1}\\right) A_+ = 1\n(2 \\tau \\psi + 8) \\gamma + \\frac{2}{k} (1 - e^{-kL})(1 + (1 + \\tau\\psi/2)^{-1}) A_+ = 1\n\\end{eqnarray}\nwith respect to $A_+$ and $\\gamma$.\\\\\n\nWe use \\textsc{SageMath} to solve Eqs. (\\ref{S01}, \\ref{S02})\n\\begin{lstlisting}[backgroundcolor=\\color{lightgray!20!white}, language=Python, xleftmargin=0.5cm, xrightmargin=0.5cm, framexleftmargin = 0.5em, frame=tlbr,framesep=4pt]\n# variables\npsi = var('psi')\ntau = var('tau')\nk = var('k')\nL = var('L')\nl = var('l')\nv0 = var('v0')\ns = var('s')\n\n# system [gamma, A]\nsystem = Matrix([\n\n    [(tau*psi + 2)*(tau*psi + 2 - 2*s*l*v0) - 2,\n    -l*((1 - k*l/(1 + (tau*psi)/2)) + (1 + k*l/(1 + (tau*psi)/2))*exp(-k*L))],\n\n    [2*tau*psi + 8,\n    (2/k)*(1 - exp(-k*L))*(1 + 1/(tau*psi + 2))]\n\n])\n\n# solution\n[[gamma], [A]] = system \\ Matrix([[0], [1]])\n\\end{lstlisting}\nand get\n\\begin{eqnarray}\n\\gamma = -\\frac{1}{2 \\, {\\left(\\frac{{\\left(\\psi \\tau + 4\\right)} {\\left({\\left(\\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} e^{\\left(-L k\\right)} - \\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} l}{{\\left(2 \\, l s v_{0} - \\psi \\tau - 2\\right)} {\\left(\\psi \\tau + 2\\right)} + 2} + \\frac{{\\left(\\frac{1}{\\psi \\tau + 2} + 1\\right)} {\\left(e^{\\left(-L k\\right)} - 1\\right)}}{k}\\right)}}\\\\\nA_+ = A_- = \\frac{{\\left({\\left(\\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} e^{\\left(-L k\\right)} - \\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} l}{2 \\, {\\left({\\left(2 \\, l s v_{0} - \\psi \\tau - 2\\right)} {\\left(\\psi \\tau + 2\\right)} + 2\\right)} {\\left(\\frac{{\\left(\\psi \\tau + 4\\right)} {\\left({\\left(\\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} e^{\\left(-L k\\right)} - \\frac{2 \\, k l}{\\psi \\tau + 2} + 1\\right)} l}{{\\left(2 \\, l s v_{0} - \\psi \\tau - 2\\right)} {\\left(\\psi \\tau + 2\\right)} + 2} + \\frac{{\\left(\\frac{1}{\\psi \\tau + 2} + 1\\right)} {\\left(e^{\\left(-L k\\right)} - 1\\right)}}{k}\\right)}}.\n\\end{eqnarray}\n\n\\subsection{Scaling regime}\n\nWe assume there exists a scaling form\n\\begin{equation}\n\\psi(s) = L^{-2} \\varphi(s L)\n\\end{equation}\nso that for $s = \\mathcal{O}(L^{-1})$ we have $\\psi(s) = \\mathcal{O}(L^{-2})$ and $k = \\mathcal{O}(L^{-1})$ from Eq. (\\ref{kPsi}).\\\\\n\nWe give an expression of Eqs. (\\ref{S2}, \\ref{S3}) at the lowest order of $L^{-1}$ and using $A_+ = A_-$\n\\begin{eqnarray}\n\\label{SC1}\n2 \\gamma - l(1 + e^{-kL}) A_+ = 0\\\\\n\\label{SC2}\n8 \\gamma + \\frac{4}{k} (1 - e^{-kL}) A_+ = 1\n\\end{eqnarray}\nfrom which we infer\n\\begin{equation}\n\\label{SCgamma}\n\\gamma = \\frac{1}{8} k l \\frac{1 + e^{-kL}}{1 - e^{-kL}}\n\\end{equation}\nand an expression of Eq. (\\ref{gammaPsi}) at the lowest order of $L^{-1}$\n\\begin{equation}\n\\gamma = \\frac{\\psi}{8 s v_0^2}\n\\end{equation}\nwhich with Eq.(\\ref{kPsi}) linking $k$ and $\\psi$, also at the lowest order of $L^{-1}$,\n\\begin{equation}\n\\label{SCkl}\nk^2 l^2 = \\tau \\psi \\Rightarrow k = \\begin{cases} \\frac{1}{l} \\sqrt{\\tau\\psi} &\\text{ if } s > 0, \\\\ 0 &\\text{ if } s = 0, \\\\ \\mathrm{i} \\, \\frac{1}{l} \\sqrt{- \\tau\\psi} &\\text{ if } s < 0, \\end{cases}\n\\end{equation}\ngive\n\\begin{eqnarray}\n\\frac{2}{s L v_0} = \\frac{\\coth\\left(\\sqrt{\\frac{\\psi L^2}{4 l v_0}}\\right)}{\\sqrt{\\frac{\\psi L^2}{4 l v_0}}} \\Leftrightarrow \\frac{1}{\\Lambda} = \\frac{\\coth\\left(\\sqrt{\\Psi}\\right)}{\\sqrt{\\Psi}} &\\qquad\\qquad s > 0, \\psi > 0\\\\\n- \\frac{2}{s L v_0} = \\frac{\\cot\\left(\\sqrt{\\frac{|\\psi| L^2}{4 l v_0}}\\right)}{\\sqrt{\\frac{|\\psi| L^2}{4 l v_0}}} \\Leftrightarrow - \\frac{1}{\\Lambda} = \\frac{\\cot\\left(\\sqrt{|\\Psi|}\\right)}{\\sqrt{|\\Psi|}} &\\qquad\\qquad s < 0, \\psi < 0\n\\end{eqnarray}\nwhere we have set\n\\begin{eqnarray}\n\\label{Lambda}\n\\Lambda = \\frac{s L v_0}{2}\\\\\n\\label{Phi}\n\\Psi = \\frac{\\psi L^2}{4 l v_0} = \\frac{\\varphi}{4 l v_0}\n\\end{eqnarray}\nfor convenience, and introduce\n\\begin{equation}\n\\Gamma = \\frac{\\Psi}{\\Lambda} = \\frac{\\psi}{8 s v_0^2} \\frac{4 L}{l} = \\gamma \\frac{4 L}{l}\n\\label{eqGamma}\n\\end{equation}\nwhich we plot in Fig. \\ref{Gamma}.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{gamma.eps}\n\\caption{Rescaled sticking term $\\Gamma = (4L/l) \\, \\gamma$ as a function of rescaled biasing parameter $\\Lambda = s L v_0/2$.}\n\\label{Gamma}\n\\end{figure}\n\nAt the lowest order in $L^{-1}$ we have from Eqs. (\\ref{epsilon}, \\ref{theta}, \\ref{beta})\n\\begin{equation}\n\\varepsilon(r) = \\theta(r) = \\beta(r) = \\frac{1}{2} A_+ (e^{-kr} + e^{-k(L-r)})\n\\end{equation}\nand from Eqs. (\\ref{SC1}, \\ref{SC2}, \\ref{SCgamma})\n\\begin{equation}\nA_+ = \\frac{2\\gamma}{l} \\frac{1}{1 + e^{-kL}} = \\frac{k}{4(1 - e^{-kL})}\n\\end{equation}\nso we can write with Eqs. (\\ref{SCkl}, \\ref{Lambda}, \\ref{Phi}, \\ref{eqGamma})\n\\begin{equation}\nL \\varepsilon(r) = \\frac{1}{4} \\Gamma \\begin{cases} \\frac{\\cosh\\left(\\sqrt{\\Psi}(1 - 2r/L)\\right)}{\\cosh\\left(\\sqrt{\\Psi}\\right)} &\\text{ if } s > 0, \\\\ 1 &\\text{ if } s = 0, \\\\ \\frac{\\cos\\left(\\sqrt{|\\Psi|}(1 - 2r/L)\\right)}{\\cos\\left(\\sqrt{|\\Psi|}\\right)} &\\text{ if } s < 0, \\end{cases}\n\\end{equation}\nwhich we plot in Fig. \\ref{fig:epsilon}.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{epsilon.eps}\n\\caption{Rescaled regular part $L \\varepsilon(r)$ as a function of rescaled distance $r/L$ for different values of the rescaled biasing parameter $\\Lambda = s L v_0/2$.}\n\\label{fig:epsilon}\n\\end{figure}\n\n\\section{Solution to the adjoint eigenproblem}\n\n\\subsection{General solution}\n\nWe have computed the left eigenvectors $P_{\\alpha_1\\alpha_2}$ of Eq.~\\ref{eigenproblem} corresponding to the SCGF $\\psi(\\lambda)$ in Sec.~\\ref{sec:biased-distribution}, and will now compute the right eigenvectors $Q_{\\alpha_1\\alpha_2}$.\nWe introduce $Y_{\\alpha_1\\alpha_2}(r) = P_{\\alpha_1\\alpha_2}(r) Q_{\\alpha_1\\alpha_2}(r)$ which has the same symmetries as $P_{\\alpha_1\\alpha_2}(r)$, so that $Q_{\\alpha_1\\alpha_2}(r)$ also has these properties.\\\\\n\nWe assume that the normalisation condition\n\\begin{equation}\n\\int_0^L \\sum_{\\alpha_1, \\alpha_2 = \\pm 1} Y_{\\alpha_1\\alpha_2}(r) \\, \\mathrm{d}r = 1\n\\label{normalisation_pave}\n\\end{equation}\nas well as the general form\n\\begin{eqnarray}\n\\label{gfY1}\nY_{\\alpha\\alpha}(r) = \\hat{\\varepsilon}_{\\alpha\\alpha}(r) + \\hat{\\gamma}_{\\alpha\\alpha} \\delta (r) +  \\hat{\\gamma}_{\\alpha\\alpha} \\delta (L - r)\\\\\n\\label{gfY2}\nY_{+-}(r) = \\hat{\\varepsilon}_{+-}(r) + \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\delta (r)\\\\\n\\label{gfY3}\nY_{-+}(r) = \\hat{\\varepsilon}_{-+}(r) + \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\delta (L - r)\n\\end{eqnarray}\nalso hold for $Y_{\\alpha_1\\alpha_2}$.\\\\\n\nWe write the hermitian adjoints of Eqs.~\\ref{FP1}, \\ref{FP2}, \\ref{FP3} for the right eigenvectors\n\\begin{eqnarray}\n\\label{FPr1}\n\\psi Q_{\\alpha\\alpha}(r) = -2 \\partial_r V(r) \\partial_r Q_{\\alpha\\alpha}(r) + \\tau^{-1} (Q_{\\alpha\\overline{\\alpha}}(r) + Q_{\\overline{\\alpha}\\alpha}(r) - 2 Q_{\\alpha\\alpha}(r))\\\\\n\\label{FPr2}\n\\psi Q_{\\alpha\\overline{\\alpha}}(r) = - \\alpha 2 v_0 \\partial_r Q_{\\alpha\\overline{\\alpha}}(r) - 2 \\partial_r V(r) \\partial_r Q_{\\alpha\\overline{\\alpha}}(r) + \\tau^{-1} (2 Q_{\\alpha\\alpha}(r) - 2 Q_{\\alpha\\overline{\\alpha}}(r)) - \\alpha 2 s v_0 \\partial_r V(r) Q_{\\alpha\\overline{\\alpha}}(r)\n\\end{eqnarray}\nfollowing the symmetries we have introduced.\\\\\n\nWe notice that the bulk equations for Eqs.~\\ref{FPr1}, \\ref{FPr2} are the bulk equations \\eqref{bulk:biased1}, \\eqref{bulk:biased2}, \\eqref{bulk:biased3} under the transformation $\\alpha \\to \\overline{\\alpha}$ so we get on $]0;L[$\n\\begin{eqnarray}\n\\label{qaa}\nQ_{\\alpha\\alpha}(r) = A^{\\prime} (\\tau \\psi + 2)^{-1} (e^{-k r} + e^{-k (L - r)})\\\\\n\\label{qaoa}\n2 Q_{\\alpha\\overline{\\alpha}}(r) = \\left(1 + \\frac{\\alpha 2 k l}{\\tau \\psi + 2}\\right) A^{\\prime} e^{- k r} + \\left(1 - \\frac{\\alpha 2 k l}{\\tau \\psi + 2}\\right) A^{\\prime} e^{- k (L - r)}\n\\end{eqnarray}\nwhere $k$ is defined by Eq.~\\ref{kPsi} and $A^{\\prime}$ is a new constant.\n\n\\subsubsection{Complete determination method}\n\nWe write for $Y_{\\alpha_1\\alpha_2}$ the equations\n\\begin{eqnarray}\n\\label{FPrY1}\n\\begin{aligned}\n\\psi Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha}(r)}{P_{\\alpha\\overline{\\alpha}}(r)} = &\\left[- \\alpha 2 v_0 \\partial_r Q_{\\alpha\\overline{\\alpha}}(r) - 2 \\partial_r V(r) \\partial_r Q_{\\alpha\\overline{\\alpha}}(r)\\right] P_{\\alpha\\alpha}(r)\\\\\n&+ \\tau^{-1} \\left(2 Y_{\\alpha\\alpha}(r) - 2 Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha}(r)}{P_{\\alpha\\overline{\\alpha}}(r)}\\right) - \\alpha 2 s v_0 \\partial_r V(r) Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha}(r)}{P_{\\alpha\\overline{\\alpha}}(r)}\n\\end{aligned}\\\\\n% \\label{FPrY1}\n% \\psi Y_{\\alpha\\alpha}(r) = - 2 \\partial_r V(r) P_{\\alpha\\alpha}(r) \\partial_r Q_{\\alpha\\alpha}(r) + \\tau^{-1} \\left(Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha(r)}}{P_{\\alpha\\overline{\\alpha}}(r)} + Y_{\\overline{\\alpha}\\alpha}(r) \\frac{P_{\\alpha\\alpha(r)}}{P_{\\overline{\\alpha}\\alpha}(r)} - 2 Y_{\\alpha\\alpha}(r)\\right)\\\\\n% \\label{FPrY2}\n% \\psi Y_{\\alpha\\alpha}(r) = 2 Q_{\\alpha\\alpha}(r) \\partial_r (P_{\\alpha\\alpha}(r) \\partial_r V(r)) + \\tau^{-1} \\left(Y_{\\alpha\\alpha}(r) \\frac{P_{\\alpha\\overline{\\alpha}}(r)}{P_{\\alpha\\alpha}(r)} + Y_{\\alpha\\alpha}(r) \\frac{P_{\\overline{\\alpha}\\alpha}(r)}{P_{\\alpha\\alpha}(r)} - 2 Y_{\\alpha\\alpha}(r)\\right)\\\\\n\\label{FPrY3}\n\\begin{aligned}\n\\psi Y_{\\alpha\\overline{\\alpha}}(r) = &- \\alpha 2 v_0 P_{\\alpha\\overline{\\alpha}}(r) \\partial_r Q_{\\alpha\\overline{\\alpha}}(r) - 2 \\partial_r V(r) P_{\\alpha\\overline{\\alpha}}(r) \\partial_r Q_{\\alpha\\overline{\\alpha}}(r) + \\tau^{-1} \\left(2 Y_{\\alpha\\alpha}(r) \\frac{P_{\\alpha\\overline{\\alpha}}(r)}{P_{\\alpha\\alpha}(r)} - 2 Y_{\\alpha\\overline{\\alpha}}(r)\\right)\\\\\n&- \\alpha 2 s v_0 \\partial_r V(r) Y_{\\alpha\\overline{\\alpha}}(r)\n\\end{aligned}\\\\\n\\label{FPrY4}\n\\begin{aligned}\n\\psi Y_{\\alpha\\overline{\\alpha}}(r) = &\\alpha 2 v_0 Q_{\\alpha\\overline{\\alpha}}(r) \\partial_r P_{\\alpha\\overline{\\alpha}}(r) + 2 Q_{\\alpha\\overline{\\alpha}}(r) \\partial_r (Q_{\\alpha\\overline{\\alpha}}(r) \\partial_r V(r)) + \\tau^{-1} \\left(2 Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha}(r)}{P_{\\alpha\\overline{\\alpha}}(r)} - 2 Y_{\\alpha\\overline{\\alpha}}(r)\\right)\\\\\n&- \\alpha 2 s v_0 \\partial_r V(r) Y_{\\alpha\\overline{\\alpha}}(r)\n\\end{aligned}\n\\end{eqnarray}\nwhere \\eqref{FPrY1} is derived from the multiplication of \\eqref{FPr2} by $P_{\\alpha\\alpha}(r)$,\n% where \\eqref{FPrY1} is derived from the multiplication of \\eqref{FPr1} by $P_{\\alpha\\alpha}(r)$, \\eqref{FPrY2} is derived from the multiplication of \\eqref{FP1} by $Q_{\\alpha\\alpha}(r)$,\n\\eqref{FPrY3} is derived from the multiplication of \\eqref{FPr2} by $P_{\\alpha\\overline{\\alpha}}(r)$, \\eqref{FPrY4} is derived from the multiplication of (\\ref{FP2}, \\ref{FP3}) by $Q_{\\alpha\\overline{\\alpha}}(r)$\n, and finally substract\n%\n% We substract Eqs.~\\ref{FPrY1},~\\ref{FPrY2}\n% \\begin{equation}\n% 0 = - 2 \\partial_r (\\partial_r V(r) Y_{\\alpha\\alpha}(r)) + \\tau^{-1} \\left(Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha(r)}}{P_{\\alpha\\overline{\\alpha}}(r)} + Y_{\\overline{\\alpha}\\alpha}(r) \\frac{P_{\\alpha\\alpha(r)}}{P_{\\overline{\\alpha}\\alpha}(r)} - Y_{\\alpha\\alpha}(r) \\frac{P_{\\alpha\\overline{\\alpha}}(r)}{P_{\\alpha\\alpha}(r)} - Y_{\\alpha\\alpha}(r) \\frac{P_{\\overline{\\alpha}\\alpha}(r)}{P_{\\alpha\\alpha}(r)}\\right)\n% \\end{equation}\n% and also\nEqs.~\\ref{FPrY3},~\\ref{FPrY4}\n\\begin{equation}\n0 = - \\alpha 2 v_0 \\partial_r Y_{\\alpha\\overline{\\alpha}}(r) - 2 \\partial_r (Y_{\\alpha\\overline{\\alpha}}(r) \\partial_r V(r)) + \\tau^{-1} \\left(2 Y_{\\alpha\\alpha}(r) \\frac{P_{\\alpha\\overline{\\alpha}}(r)}{P_{\\alpha\\alpha}(r)} - 2 Y_{\\alpha\\overline{\\alpha}}(r) \\frac{P_{\\alpha\\alpha}(r)}{P_{\\alpha\\overline{\\alpha}}(r)}\\right)\n\\end{equation}\nto get equations where derivatives should have nice integrals.\\\\\n\nWe integrate Eqs.~\\ref{FPrY1},~\\ref{FPrY4} between $0^-$ and $0^+$\n\\begin{eqnarray}\n\\label{BCr1}\n\\psi \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}} = \\tau^{-1} \\left(2 \\hat{\\gamma}_{\\alpha\\alpha} - 2 \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}\\right) + 2 s v_0^2 \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}\\\\\n\\label{BCr2}\n0 = - v_0 \\hat{\\varepsilon}_{+-}(0^+) + \\tau^{-1} \\left(\\hat{\\gamma}_{\\alpha\\alpha} \\frac{\\gamma_{\\alpha\\overline{\\alpha}}}{\\gamma_{\\alpha\\alpha}} - \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}\\right)\n\\end{eqnarray}\nwhere we have discarded in \\eqref{BCr1} the integral of the first term of the right hand side of \\eqref{FPrY1} since $\\partial_r V(0) = -v_0$, and with\n\\begin{eqnarray}\n\\label{he+-}\n\\begin{aligned}\n\\hat{\\varepsilon}_{+-}(r) &= Q_{+-}(r) P_{+-}(r) \\qquad (r \\in ]0; L[)\\\\\n&= \\frac{A A^{\\prime}}{4} \\left[1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right](e^{-2 k r} + e^{-2 k (L - r)})\\\\\n&\\quad+ \\frac{A A^{\\prime}}{4} \\left[\\left(1 + \\frac{2 k l}{\\tau \\psi + 2}\\right)^2 + \\left(1 - \\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right] e^{-k L}\\\\\n&= \\frac{A A^{\\prime}}{4} \\left[1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right](e^{-2 k r} + e^{-2 k (L - r)}) + \\frac{A A^{\\prime}}{2} \\left[1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right] e^{-k L}\n\\end{aligned}\\\\\n\\end{eqnarray}\nwhere we will introduce\n\\begin{equation}\n\\Omega = \\frac{2 k l}{\\tau \\psi + 2}\n\\label{Omega}\n\\end{equation}\nto get\n\\begin{eqnarray}\n\\label{he+-lim}\n\\begin{aligned}\n\\hat{\\varepsilon}_{+-}(0^+) = \\lim_{r \\to 0^+} \\hat{\\varepsilon}_{+-}(r) &= \\frac{A A^{\\prime}}{4} \\left[1 - \\Omega^2\\right](1 + e^{-2 k L}) + \\frac{A A^{\\prime}}{2} \\left[1 + \\Omega^2\\right] e^{-k L}\\\\\n&= A A^{\\prime} e^{-k L} \\left[\\left(\\frac{e^{kL} + e^{-k L}}{2}\\right)^2 - \\Omega^2 \\left(\\frac{e^{kL} - e^{-k L}}{2}\\right)^2\\right]\n% &= \\frac{A A^{\\prime}}{2} e^{-k L}\\left[\\left(1 - \\left(\\frac{2 k l}{\\tau\\psi + 2}\\right)^2\\right) \\cosh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau\\psi + 2}\\right)^2\\right)\\right]\n\\end{aligned}\n\\end{eqnarray}\nfrom Eqs.~\\ref{epsilon},~\\ref{qaoa}, with $A = A_{\\pm}$ which appear in Eqs.~\\ref{epsilon}, \\ref{theta}, \\ref{beta}. We solve Eqs.~\\ref{BCr1},~\\ref{BCr2} for $\\hat{\\gamma}_{\\alpha\\alpha}$ and $\\hat{\\gamma}_{\\alpha\\overline{\\alpha}}$\n\\begin{eqnarray}\n\\label{hgaa}\n\\hat{\\gamma}_{\\alpha\\alpha} = \\frac{[(\\tau\\psi + 2) - 2 s l v_0] l \\hat{\\varepsilon}_{+-}(0^+)}{(\\tau \\psi + 2) [(\\tau\\psi + 2) - 2 s l v_0] - 2}\\\\\n% \\hat{\\gamma}_{\\alpha\\alpha} = \\frac{\\left[\\frac{1}{2} (\\tau \\psi + 2) - s l v_0\\right] \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}} l \\hat{\\varepsilon}_{+-}(0^+)}{\\frac{1}{2}(\\tau\\psi + 2) - s l v_0 - \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}}\\\\\n\\label{hgaoa}\n\\hat{\\gamma}_{\\alpha\\overline{\\alpha}} = \\frac{2 (\\tau\\psi + 2) l \\hat{\\varepsilon}_{+-}(0^+)}{(\\tau \\psi + 2) [(\\tau\\psi + 2) - 2 s l v_0] - 2}\n% \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} = \\frac{l \\hat{\\varepsilon}_{+-}(0^+)}{\\frac{1}{2}(\\tau\\psi + 2) - s l v_0 - \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}}\n\\end{eqnarray}\nas a function of $\\hat{\\varepsilon}_{+-}(0^+)$ and where we have used $\\gamma_{\\alpha\\alpha}/\\gamma_{\\alpha\\overline{\\alpha}} = (\\tau \\psi + 2)^{-1}$ \\eqref{ratio_gamma}.\\\\\n\nWe can finally write the normalisation condition \\eqref{normalisation_pave}\n\\begin{equation}\n\\begin{aligned}\n1 &= 4 \\hat{\\gamma}_{\\alpha\\alpha} + 2 \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) \\, \\mathrm{d}r\\\\\n&= 4 \\hat{\\gamma}_{\\alpha\\alpha} \\left(1 + \\frac{1}{2} \\frac{\\hat{\\gamma}_{\\alpha\\overline{\\alpha}}}{\\hat{\\gamma}_{\\alpha\\alpha}}\\right) + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) \\, \\mathrm{d}r\n\\label{normalisation_pave_full}\n\\end{aligned}\n\\end{equation}\nwhere we have\n\\begin{equation}\n\\hat{\\varepsilon}_{\\alpha\\alpha}(r) = P_{\\alpha\\alpha}(r \\in ]0; L[) Q_{\\alpha\\alpha}(r \\in ]0; L[) = \\frac{A A^{\\prime}}{(\\tau \\psi + 2)^2} \\left(e^{-2 k r} + e^{-2 k (L - r)} + 2 e^{-k L}\\right)\n\\label{heaa}\n\\end{equation}\naccording to Eqs.~\\ref{beta},~\\ref{qaa}. We compute from \\eqref{heaa}\n\\begin{equation}\n\\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r = A A^{\\prime} e^{-k L} \\frac{2}{(\\tau \\psi + 2)^2} \\left[\\frac{1}{k} \\left(\\frac{e^{k L} - e^{-k L}}{2}\\right) + L\\right]\n\\label{int_heaa}\n\\end{equation}\nand from \\eqref{he+-}\n\\begin{equation}\n\\int_0^L \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) \\, \\mathrm{d}r = A A^{\\prime} e^{-k L} \\frac{1}{2} \\left[\\left(1 -\\Omega^2\\right) \\frac{1}{k} \\left(\\frac{e^{k L} - e^{-k L}}{2}\\right) + \\left(1 + \\Omega^2\\right) L\\right]\n\\end{equation}\non the one hand, and use on the other hand \\eqref{he+-lim} to re-write \\eqref{normalisation_pave_full}\n\\begin{equation}\n\\begin{aligned}\n\\tilde{\\mathcal{N}} =~& (A A^{\\prime} e^{-k L} l)^{-1}\\\\\n=~& \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2)[(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left[1 + \\frac{\\tilde{\\psi} + 2}{(\\tilde{\\psi} + 2) - 2 \\tilde{s}}\\right] \\left[\\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)^2 - \\Omega^2 \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right)^2\\right]\\\\\n&+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - \\Omega^2)\\right] \\frac{1}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + \\Omega^2)\\right] \\tilde{L}\n\\end{aligned}\n\\label{normalisation_factor_pave}\n\\end{equation}\n% \\begin{equation}\n% \\begin{aligned}\n% 1 = &\\left[4 \\frac{\\left(\\frac{1}{2}(\\tau \\psi + 2) - s l v_0\\right) \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}} l}{\\frac{1}{2}(\\tau \\psi + 2) - s l v_0 - \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}} + 2 \\frac{l}{\\frac{1}{2}(\\tau \\psi + 2) - s l v_0 - \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}}\\right]\\\\\n% &\\qquad \\times \\frac{A A^{\\prime}}{2} e^{-k L} \\left[\\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\cosh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right)\\right]\\\\\n% &+ \\frac{4 A A^{\\prime}}{(\\tau \\psi + 2)^2} e^{-k L} \\left[\\frac{1}{k}\\sinh(kL) + L\\right]\\\\\n% &+ A A^{\\prime} e^{-k L} \\left[\\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\frac{1}{k} \\sinh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) L\\right]\\\\\n% = & A A^{\\prime} e^{-k L}\\\\\n% &\\times\\Bigg[\\frac{l}{\\frac{1}{2}(\\tau \\psi + 2) - s l v_0 - \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}}} \\left(2 \\left(\\frac{1}{2} (\\tau \\psi + 2) - s l v_0\\right) \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}} + 1\\right)\\\\\n% &\\qquad\\qquad \\times \\left(\\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\cosh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right)\\right)\\\\\n% &\\qquad + \\frac{4}{(\\tau \\psi + 2)^2} \\left(\\frac{1}{k}\\sinh(kL) + L\\right) + \\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\frac{1}{k} \\sinh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) L\\Bigg]\n% \\end{aligned}\n% \\end{equation}\n% and conclude\n% \\begin{equation}\n% \\begin{aligned}\n% A^{\\prime} =& \\frac{e^{k L}}{A}\\\\\n% &\\times\\Bigg[\\frac{l}{\\frac{1}{2}(\\tau \\psi + 2)^2 - s l v_0 (\\tau \\psi + 2) - 1} \\left(2 (\\tau \\psi + 2) - 2 s l v_0\\right)\\\\\n% &\\qquad\\qquad \\times \\left(\\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\cosh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right)\\right)\\\\\n% &\\qquad + \\frac{4}{(\\tau \\psi + 2)^2} \\left(\\frac{1}{k}\\sinh(kL) + L\\right) + \\left(1 - \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) \\frac{1}{k} \\sinh(k L) + \\left(1 + \\left(\\frac{2 k l}{\\tau \\psi + 2}\\right)^2\\right) L\\Bigg]^{-1}\n% \\end{aligned}\n% \\end{equation}\nwhere we have denoted the dimensionless quantities $\\tilde{\\psi} = \\tau \\psi$, $\\tilde{k} = k l$, $\\tilde{L} = L/l$, $\\tilde{s} = s l v_0$, $\\tilde{\\mathcal{N}} = \\mathcal{N}/l$.\n% We can easily check that $\\lim_{s \\to 0} \\tilde{\\mathcal{N}^{-1}} = 8 + 4 \\tilde{L}$, and\n% \\begin{eqnarray}\n% \\label{normalisation_factor_pave_sneg}\n% \\begin{aligned}\n% \\tilde{\\mathcal{N}}^{-1}(s < 0) =~& \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2)[(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left[1 + \\frac{\\tilde{\\psi} + 2}{(\\tilde{\\psi} + 2) - 2 \\tilde{s}}\\right]\\left(\\cos(|\\tilde{k}| \\tilde{L})^2 - |\\Omega|^2 \\sin(|\\tilde{k}| \\tilde{L})^2\\right)\\\\\n% &+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + |\\Omega|^2)\\right] \\frac{1}{|\\tilde{k}|} \\sin(|\\tilde{k}| \\tilde{L}) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - |\\Omega|^2)\\right] \\tilde{L}\n% \\end{aligned}\\\\\n% \\label{normalisation_factor_pave_spos}\n% \\begin{aligned}\n% \\tilde{\\mathcal{N}}^{-1}(s > 0) =~& \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2)[(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left[1 + \\frac{\\tilde{\\psi} + 2}{(\\tilde{\\psi} + 2) - 2 \\tilde{s}}\\right]\\left(\\cosh(\\tilde{k} \\tilde{L})^2 - \\Omega^2 \\sinh(\\tilde{k} \\tilde{L})^2\\right)\\\\\n% &+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - \\Omega^2)\\right] \\frac{1}{\\tilde{k}} \\sinh(\\tilde{k} \\tilde{L}) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + \\Omega^2)\\right] \\tilde{L}\n% \\end{aligned}\n% \\end{eqnarray}\n% depending on the sign of $s$.\\\\\n%\n% We define the polarisation\n% \\begin{equation}\n% \\nu = 4 \\hat{\\gamma}_{\\alpha\\alpha} + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r\n% \\label{polarisation_def}\n% \\end{equation}\n% which we can compute with (\\ref{hgaa}, \\ref{int_heaa}, \\ref{normalisation_factor_pave})\n% \\begin{equation}\n% \\begin{aligned}\n% \\nu =~& \\tilde{\\mathcal{N}} \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2) [(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left[\\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)^2 - \\Omega^2 \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right)^2\\right]\\\\\n% &+ \\tilde{\\mathcal{N}} \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left[\\frac{1}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right) + \\tilde{L}\\right]\n% \\end{aligned}\n% \\label{polarisation_value}\n% \\end{equation}\n% where we can check that $\\lim_{s \\to 0} \\nu = 1/2$ and write depending on the sign of $s$\n% \\begin{eqnarray}\n% \\label{polarisation_sneg}\n% \\nu(s < 0) = \\tilde{\\mathcal{N}} \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2) [(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left(\\cos(|\\tilde{k}| \\tilde{L})^2 - |\\Omega|^2 \\sin(|\\tilde{k}| \\tilde{L})^2\\right) + \\tilde{\\mathcal{N}} \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left[\\frac{1}{|\\tilde{k}|} \\sin(|\\tilde{k}| \\tilde{L}) + \\tilde{L}\\right]\\\\\n% \\label{polarisation_spos}\n% \\nu(s > 0) = \\tilde{\\mathcal{N}} \\frac{4 [(\\tilde{\\psi} + 2) - 2 \\tilde{s}]}{(\\tilde{\\psi} + 2) [(\\tilde{\\psi} + 2) - 2 \\tilde{s}] - 2} \\left(\\cosh(\\tilde{k} \\tilde{L})^2 - |\\Omega|^2 \\sinh(\\tilde{k} \\tilde{L})^2\\right) + \\tilde{\\mathcal{N}} \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left[\\frac{1}{\\tilde{k}} \\sinh(\\tilde{k} \\tilde{L}) + \\tilde{L}\\right]\n% \\end{eqnarray}\n% with (\\ref{normalisation_factor_pave_sneg}, \\ref{normalisation_factor_pave_spos}).\n\n\\subsubsection{Polarisation-oriented method}\n\nWe have that the form of Eqs.~\\ref{FPr1}, \\ref{FPr2} indicates that there cannot be $\\delta$-function terms in the right eigenvectors $Q_{\\alpha_1\\alpha_2}$, therefore these are completely described by Eqs.~\\ref{qaa}, \\ref{qaoa}. We can thus write\n\\begin{eqnarray}\n\\hat{\\varepsilon}_{\\alpha\\alpha}(r) = \\frac{A^{\\prime}}{A} \\varepsilon_{\\alpha\\alpha}(r)^2\\\\\n\\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) = \\frac{A^{\\prime}}{A} \\varepsilon_{\\alpha\\overline{\\alpha}}(r) \\varepsilon_{\\overline{\\alpha}\\alpha}(r)\\\\\n\\hat{\\gamma}_{\\alpha\\alpha} = \\gamma_{\\alpha\\alpha} \\frac{A^{\\prime}}{A} \\varepsilon_{\\alpha\\alpha}(0^+)\\\\\n\\hat{\\gamma}_{\\alpha\\overline{\\alpha}} = \\gamma_{\\alpha\\overline{\\alpha}} \\frac{A^{\\prime}}{A} \\varepsilon_{+-}(L^-)\n\\end{eqnarray}\nwith the notations of Eqs.~\\ref{gfY1}, \\ref{gfY2}, \\ref{gfY3}.\\\\\n\nWe want to compute the average polarisation\n\\begin{equation}\n\\nu = 4 \\hat{\\gamma}_{\\alpha\\alpha} + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r\n\\label{nu_pave}\n\\end{equation}\ncorresponding to the propensity of particles to be aligned, and use the normalisation condition \\eqref{normalisation_pave_full} to re-write it\n\\begin{equation}\n\\begin{aligned}\n\\nu &= \\frac{4 \\hat{\\gamma}_{\\alpha\\alpha} + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r}{4 \\hat{\\gamma}_{\\alpha\\alpha} + 2 \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\alpha}(r) \\, \\mathrm{d}r + 2 \\int_0^L \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) \\, \\mathrm{d}r}\\\\\n&= \\frac{4 e^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} \\frac{\\varepsilon_{\\alpha\\alpha}(0^+)}{A} + 2 e^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\alpha}(r)^2}{A^2} \\, \\mathrm{d}r}{4 e^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} \\frac{\\varepsilon_{\\alpha\\alpha}(0^+)}{A} + 2 e^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} (\\tau \\psi + 2) \\frac{\\varepsilon_{+-}(L^-)}{A} + 2 e^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\alpha}(r)^2}{A^2} \\, \\mathrm{d}r + 2 e^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\overline{\\alpha}}(r)\\varepsilon_{\\overline{\\alpha}\\alpha}(r)}{A^2} \\, \\mathrm{d}r}\n\\end{aligned}\n\\label{nu_pave_full}\n\\end{equation}\nwhere we have used $\\gamma_{\\alpha\\overline{\\alpha}} = (\\tau \\psi + 2) \\gamma_{\\alpha\\alpha}$ \\eqref{ratio_gamma} from the first to the second line.\\\\\n\nWe can compute from Eqs.~\\ref{epsilon}, \\ref{LBe2}\n\\begin{equation}\n\\frac{\\gamma_{\\alpha\\alpha}}{A} = l \\frac{\\varepsilon_{+-}(L^-)}{A} = \\frac{l}{2} \\left[(1 + e^{-k L}) + \\Omega (1 - e^{-k L})\\right]\n\\end{equation}\nfrom Eqs.~\\ref{epsilon}, \\ref{theta}\n\\begin{eqnarray}\n\\frac{\\varepsilon_{\\alpha\\alpha}(0^+)}{A} = \\frac{1}{\\tau\\psi + 2}(1 + e^{-k L})\\\\\n\\begin{aligned}\n\\frac{\\varepsilon_{+-}(L^-)}{A} &= \\frac{1}{2} \\left[(1 + e^{-k L}) + \\Omega (1 - e^{-k L})\\right]\n\\end{aligned}\n\\end{eqnarray}\nand from Eqs.~\\ref{heaa}, \\ref{he+-}\n\\begin{eqnarray}\n\\int_0^L \\frac{\\varepsilon_{\\alpha\\alpha}(r)^2}{A^2} \\, \\mathrm{d}r = e^{-k L} \\frac{2}{(\\tau \\psi + 2)^2} \\left[\\frac{1}{k} \\left(\\frac{e^{k L} - e^{- k L}}{2}\\right) + L\\right]\\\\\n\\int_0^L \\frac{\\varepsilon_{\\alpha\\overline{\\alpha}}(r)\\varepsilon_{\\overline{\\alpha}\\alpha}(r)}{A^2} \\, \\mathrm{d}r = e^{-k L} \\frac{1}{2} \\left[(1 - \\Omega^2) \\frac{1}{k} \\left(\\frac{e^{k L} - e^{-k L}}{2}\\right) + (1 + \\Omega^2) L\\right]\n\\end{eqnarray}\nso that we can write\n\\begin{eqnarray}\n\\label{gaa-full}\ne^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} \\frac{\\varepsilon_{\\alpha\\alpha}(0^+)}{A} = \\frac{1}{4} \\left[2 \\frac{\\Omega}{k} \\left(1 + \\left(\\frac{e^{k L} + e^{-k L}}{2}\\right)\\right) + 2 \\frac{\\Omega^2}{k} \\left(\\frac{e^{k L} - e^{-k L}}{2}\\right)\\right]\\\\\n\\label{gaba-full}\n\\begin{aligned}\ne^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} (\\tau \\psi + 2) \\frac{\\varepsilon_{+-}(L^-)}{A} = \\frac{1}{2} \\Bigg[l(\\tau \\psi + 2)(1 - \\Omega^2) + l(\\tau\\psi + 2)(1 + \\Omega^2)\\left(\\frac{e^{k L} + e^{-k L}}{2}\\right)\\\\\n+ (\\tau \\psi + 2)^2 \\frac{\\Omega^2}{k} \\left(\\frac{e^{k L} - e^{-k L}}{2}\\right)\\Bigg]\n\\end{aligned}\\\\\ne^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\alpha}(r)^2}{A^2} \\, \\mathrm{d}r = \\frac{1}{2} \\left[\\frac{4}{(\\tau\\psi + 2)^2} \\left(\\frac{1}{k}\\left(\\frac{e^{k L} - e^{- k L}}{2}\\right) + L\\right)\\right]\\\\\ne^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\overline{\\alpha}}(r)\\varepsilon_{\\overline{\\alpha}\\alpha}(r)}{A^2} \\, \\mathrm{d}r = \\frac{1}{2} \\left[(1 - \\Omega^2) \\frac{1}{k}\\left(\\frac{e^{k L} - e^{-k L}}{2}\\right) + (1 + \\Omega^2) L\\right]\n\\end{eqnarray}\nwhere we have used the quantity $\\Omega$ \\eqref{Omega}.\\\\\n\nWe can first check\n\\begin{eqnarray}\n\\lim_{s \\to 0} 4 e^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} \\frac{\\varepsilon_{\\alpha\\alpha}(0^+)}{A} = 4 l\\\\\n\\lim_{s \\to 0} 2 e^{k L} \\frac{\\gamma_{\\alpha\\alpha}}{A} (\\tau \\psi + 2) \\frac{\\varepsilon_{+-}(L^-)}{A} = 4 l\\\\\n\\lim_{s \\to 0} 2 e^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\alpha}(r)^2}{A^2} \\, \\mathrm{d}r = 2 L\\\\\n\\lim_{s \\to 0} 2 e^{k L} \\int_0^L \\frac{\\varepsilon_{\\alpha\\overline{\\alpha}}(r)\\varepsilon_{\\overline{\\alpha}\\alpha}(r)}{A^2} \\, \\mathrm{d}r = 2 L\n\\end{eqnarray}\nso that, replacing in \\eqref{nu_pave_full}, we get $\\lim_{s \\to 0} \\nu = 1/2$ as expected.\\\\\n\nWe finally give the full expressions for $s < 0$\n\\begin{equation}\n\\nu(s < 0) = \\frac{\n\\begin{aligned}\n2 \\frac{|\\Omega|}{|\\tilde{k}|} \\left(1 + \\cos(|\\tilde{k}| \\tilde{L})\\right) - 2 \\frac{|\\Omega|^2}{|\\tilde{k}|} \\sin(|\\tilde{k}| \\tilde{L}) + \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left(\\frac{1}{|\\tilde{k}|} \\sin(|\\tilde{k}| \\tilde{L}) + \\tilde{L}\\right)\n\\end{aligned}\n}{\n\\begin{aligned}\n2 \\frac{|\\Omega|}{|\\tilde{k}|} \\left(1 + \\cos(|\\tilde{k}| \\tilde{L})\\right) - (2 + (\\tilde{\\psi} + 2)^2) \\frac{|\\Omega|^2}{|\\tilde{k}|} \\sin(|\\tilde{k}| \\tilde{L}) + (\\tilde{\\psi} + 2)(1 + |\\Omega|^2) + (\\tilde{\\psi} + 2)(1 - |\\Omega|^2) \\cos(|\\tilde{k}| \\tilde{L})\\\\\n+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + |\\Omega|^2)\\right] \\frac{1}{|\\tilde{k}|} \\sin(|\\tilde{k}|\\tilde{L}) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - |\\Omega|^2)\\right] \\tilde{L}\n\\end{aligned}\n}\n\\end{equation}\nand for $s > 0$\n\\begin{equation}\n\\nu(s > 0) = \\frac{\n\\begin{aligned}\n2 \\frac{\\Omega}{\\tilde{k}} \\left(1 + \\cosh(\\tilde{k} \\tilde{L})\\right) + 2 \\frac{\\Omega^2}{\\tilde{k}} \\sinh(\\tilde{k} \\tilde{L}) + \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left(\\frac{1}{\\tilde{k}} \\sinh(\\tilde{k} \\tilde{L}) + \\tilde{L}\\right)\n\\end{aligned}\n}{\n\\begin{aligned}\n2 \\frac{\\Omega}{\\tilde{k}} \\left(1 + \\cosh(\\tilde{k} \\tilde{L})\\right) + (2 + (\\tilde{\\psi} + 2)^2) \\frac{\\Omega^2}{\\tilde{k}} \\sinh(\\tilde{k} \\tilde{L}) + (\\tilde{\\psi} + 2)(1 - \\Omega^2) + (\\tilde{\\psi} + 2)(1 + \\Omega^2) \\cosh(\\tilde{k} \\tilde{L})\\\\\n+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - \\Omega^2)\\right] \\frac{1}{\\tilde{k}} \\sinh(\\tilde{k}\\tilde{L}) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + \\Omega^2)\\right] \\tilde{L}\n\\end{aligned}\n}\n\\end{equation}\nwhere we have introduced the dimensionless quantities $\\tilde{\\psi} = \\tau \\psi$, $\\tilde{k} = k l$ and $\\tilde{L} = L/l$.\n\n\\subsubsection{Full expressions}\n\nWe summarise here our expressions for the full-time distributions.\n\nWe have the normalisation factor (Eq.~\\ref{normalisation_factor_pave})\n\\begin{equation}\n\\begin{aligned}\n\\tilde{\\mathcal{N}} =~&\\left(A A^{\\prime} e^{-\\tilde{k}\\tilde{L}} l\\right)^{-1}\\\\\n=~&2 \\frac{\\Omega}{\\tilde{k}} \\left(1 + \\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\right) + (2 + (\\tilde{\\psi} + 2)^2) \\frac{\\Omega^2}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\\\\n&+ (\\tilde{\\psi} + 2)(1 - \\Omega^2) + (\\tilde{\\psi} + 2)(1 + \\Omega^2) \\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\\\\n&+ \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 - \\Omega^2)\\right] \\frac{1}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right) + \\left[\\frac{4}{(\\tilde{\\psi} + 2)^2} + (1 + \\Omega^2)\\right] \\tilde{L}\n\\end{aligned}\n\\end{equation}\nand write from Eqs.~\\ref{Omega}, \\ref{he+-}, \\ref{heaa}, the regular part of the full-time distribution functions\n\\begin{align}\n\\tilde{\\mathcal{N}} l \\hat{\\varepsilon}_{\\alpha\\alpha}(r) &= \\frac{4}{(\\tilde{\\psi} + 2)^2} \\left(\\frac{e^{\\tilde{k} \\tilde{L} \\left(1/2 - \\tilde{r}/\\tilde{L}\\right)} + e^{-\\tilde{k} \\tilde{L} \\left(1/2 - \\tilde{r}/\\tilde{L}\\right)}}{2}\\right)^2\\\\\n\\tilde{\\mathcal{N}} l \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) &= \\frac{1}{2}\\left(1 - \\Omega^2\\right) \\left(\\frac{e^{2 \\tilde{k}\\tilde{L}\\left(1/2 - \\tilde{r}/\\tilde{L}\\right)} + e^{-2 \\tilde{k}\\tilde{L}\\left(1/2 - \\tilde{r}/\\tilde{L}\\right)}}{2}\\right) + \\frac{1}{2}\\left(1 + \\Omega^2\\right)\n\\end{align}\nwhere $\\tilde{r} = r/l$, such that we can check $\\tilde{\\mathcal{N}} \\hat{\\varepsilon}_{\\alpha\\alpha}(r) = \\tilde{\\mathcal{N}} \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r) = 1$ for $s = 0$, and from Eqs.~\\ref{gaa-full}, \\ref{gaba-full} the sticking terms\n\\begin{eqnarray}\n\\tilde{\\mathcal{N}} \\hat{\\gamma}_{\\alpha\\alpha} = \\frac{1}{2} \\left[\\frac{\\Omega}{\\tilde{k}} \\left(1 + \\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\right) + \\frac{\\Omega^2}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\right]\\\\\n\\begin{aligned}\n\\tilde{\\mathcal{N}} \\hat{\\gamma}_{\\alpha\\overline{\\alpha}} =~& \\frac{1}{2} \\Bigg[(\\tilde{\\psi} + 2)(1 - \\Omega^2) + (\\tilde{\\psi} + 2)(1 + \\Omega^2)\\left(\\frac{e^{\\tilde{k} \\tilde{L}} + e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\\\\n&+ (\\tilde{\\psi} + 2)^2 \\frac{\\Omega^2}{\\tilde{k}} \\left(\\frac{e^{\\tilde{k} \\tilde{L}} - e^{-\\tilde{k} \\tilde{L}}}{2}\\right)\\Bigg]\n\\end{aligned}\n\\end{eqnarray}\nwhich we plot in Fig.~\\ref{fig-full-expr}.\n\n\\subsection{Unbiased ensemble check}\n\nWe have in the unbiased ensemble $\\psi(s = 0) = 0$, therefore $k = 0$ according to \\eqref{kPsi}. It follows that\n\\begin{equation}\n\\hat{\\varepsilon}_{\\alpha\\alpha}(r, s=0) = \\hat{\\varepsilon}_{\\alpha\\overline{\\alpha}}(r, s=0) = A A^{\\prime}\n\\end{equation}\nfrom Eqs.~\\ref{he+-},~\\ref{heaa}. We know from Eqs.~\\ref{s0++}, \\ref{s0--}, \\ref{s0+-}, \\ref{s0-+} that\n\\begin{equation}\n\\left. \\frac{\\gamma_{\\alpha\\alpha}}{\\gamma_{\\alpha\\overline{\\alpha}}} \\right|_{s=0} = \\frac{1}{2}\n\\end{equation}\ntherefore we get\n\\begin{eqnarray}\n\\hat{\\gamma}_{\\alpha\\alpha}(s=0) = l A A^{\\prime}\\\\\n\\hat{\\gamma}_{\\alpha\\overline{\\alpha}}(s=0) = 2 l A A^{\\prime}\n\\end{eqnarray}\nfrom Eqs.~\\ref{hgaa},~\\ref{hgaoa}. We can then write the normalisation condition \\eqref{normalisation_pave_full}\n\\begin{equation}\n1 = 4 l A A^{\\prime} + 4 l A A^{\\prime} + 2 A A^{\\prime} L + 2 A A^{\\prime} L\n\\end{equation}\nsuch that\n\\begin{equation}\nA^{\\prime} = \\frac{1}{A( 8 l + 4 L)} = 1\n\\end{equation}\nwhere the second equality derives from Eq.~\\ref{smooth_unbiased}, and which consequence is that\n\\begin{equation}\nQ_{\\alpha\\alpha}(r, s=0) = Q_{\\alpha\\overline{\\alpha}}(r, s=0) = 1\n\\end{equation}\naccording to Eqs.~\\ref{qaa},~\\ref{qaoa}.\n\n%%%%%%%%%%%%%%\n% REFERENCES %\n%%%%%%%%%%%%%%\n\n\\bibliographystyle{alpha}\n{\\renewcommand{\\bibname}{References}\\bibliography{references}}\n\n\\end{document}\n", "meta": {"hexsha": "fb83c41619a155007ccf3de5f8b29f9c877f29a6", "size": 45942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Summaries/RTPring/main.tex", "max_stars_repo_name": "yketa/DAMTP_2019_Wiki", "max_stars_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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": "Summaries/RTPring/main.tex", "max_issues_repo_name": "yketa/DAMTP_2019_Wiki", "max_issues_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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": "Summaries/RTPring/main.tex", "max_forks_repo_name": "yketa/DAMTP_2019_Wiki", "max_forks_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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.2036082474, "max_line_length": 598, "alphanum_fraction": 0.6093335075, "num_tokens": 19957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6256178743913855}}
{"text": "\n\\subsection{Random optimisation}\n\nThis is similar to random search, however we use a multivariate Gaussian distribution around our current point rather than a hypersphere.\n\n", "meta": {"hexsha": "cfe57226d115375269f971b25b560c990f396825", "size": 174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/optimisation/01-02-randomOptimisation.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/optimisation/01-02-randomOptimisation.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/optimisation/01-02-randomOptimisation.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.0, "max_line_length": 137, "alphanum_fraction": 0.8218390805, "num_tokens": 33, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6256063148443837}}
{"text": "\\chapter{Explainability}\r\n\\label{ch_explainability}\r\n%\r\nDuring evaluation of the benchmark study, we found that proset models are very open to inspection after fitting.\r\nThis is due to their built-in feature selection and geometric structure.\r\nIn this chapter, we review diagnostic plots and other techniques that provide a better understanding of model behavior.\r\n%\r\n\\section{Low-dimensional representations of the data}\r\n\\label{sec_low_dimensional}\r\n%\r\nVerification of the model structure is greatly simplified if the algorithm is able to reduce the inputs to a small set.\r\nWe can then conduct what amounts to post-fit exploratory data analysis.\\par\r\n%\r\nIn the benchmark study, the proset classifier achieves the largest reduction in the number of features for the cancer data set, where only 4 out of 30 features yield a model that is still equivalent to XGBoost in terms of log-loss (see Table \\ref{tab_e3_e8_e9}).\r\nWith only four inputs, we can visually inspect all scatter plots involving a combination of two features.\r\nFigure \\ref{fig_scatter_plots_cancer} shows the positions of the prototypes (large circles) and test samples (small circles).\r\nThe three misclassified cases are circled in black.\r\nThe density plots on the diagonal show the marginal distributions for each feature, both for the prototypes (solid curves / vertical lines) and test samples (dashed curves / dots).\r\nTwo interesting findings are that (a) any pair of features allows us to distinguish the two classes fairly well and (b) the prototypes are more clearly separated with lower variance than the whole population.\\par\r\n%\r\n\\begin{figure}\r\n\\caption{Scatter plots for active features of the cancer data model}\r\n\\label{fig_scatter_plots_cancer}\r\n%\r\n\\begin{center}\r\n\\includegraphics[width=0.95\\textheight, angle=90]{figures/cancer_scatter_plot_testing_data.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nA `small' model is also easier to review for domain experts.\r\nFor example, an oncologist should be able to provide a clear assessment whether the four features (in decreasing order of weights: worst radius, worst concave points, worst texture, worst smoothness) are a natural and sufficient choice of indicators.\r\nIf we have access to the original image data, we can ask experts to review the misclassified cases in detail and compare them to the most similar prototypes.\r\nThis can reveal labeling errors, important features excluded by the algorithm due to dearth of relevant training samples, or genuine `hard cases' that are difficult to classify even for humans.\\par\r\n%\r\nA technique that can work even if the number of features remains large is to create low-dimensional maps of the data that take model fit results into account.\r\nFor the visualization we call the `batch 1 map', we perform doubly weighted PCA on the prototypes of the first batch:\\par\r\n%\r\nLet $Z\\in\\R^{J_1\\times D}$ be the matrix obtained by rescaling the features for the prototypes of the first batch with the corresponding feature weights:\r\n%\r\n\\begin{equation}\r\nZ_{j,d}:=v_{1,d}x_{s_{1,j},d}\\label{eq_scaled_x}\r\n\\end{equation}\r\n%\r\nThis gives larger impact to features for which the algorithm is more sensitive and removes any deselected features from the analysis.\r\nNow let $\\overline{z}$ be the row mean of $Z$ weighted using the prototype weights:\r\n%\r\n\\begin{equation}\r\n\\overline{z}:=\\frac{\\sum_{j=1}^{J_1}w_{1,j}Z_{j,\\bullet}}\r\n{\\sum_{j=1}^{J_1}w_{1,j}}\\label{eq_weighted_mean}\r\n\\end{equation}\r\n%\r\nDenote by $\\overline{Z}$ the centered matrix\r\n%\r\n\\begin{equation}\r\n\\overline{Z}_{j,d}:=Z_{j,d}-\\overline{z}_d\\label{eq_centered_Z}\r\n\\end{equation}\r\n%\r\nLet $W\\in\\R^{J_1\\times J_1}$ be the diagonal matrix with diagonal elements $w_{1,j}$ and compute the matrix decomposition\r\n%\r\n\\begin{equation}\r\n\\overline{Z}^TW\\overline{Z}=:U\\Sigma U^T\\label{eq_weighted_svd}\r\n\\end{equation}\r\n%\r\nIn the above, $\\Sigma$ is the diagonal matrix of eigenvalues with row and column dimension equal to the rank of $\\overline{Z}^TW\\overline{Z}$, while $U$ is the corresponding orthogonal matrix of eigenvectors.\r\nIf $\\Sigma$ has at least rank two, the `batch 1 map' coordinates for the prototypes of the first batch are the first two columns of the product $\\overline{Z}U$.\r\nOther samples can be mapped via the same transform, i.e., scale with $v_1$, center with $\\overline{z}$, and multiply with $U$.\\par\r\n%\r\n\\begin{figure}\r\n\\caption{`Batch 1 map' of cancer data showing test samples}\r\n\\label{fig_batch_1_map_test}\r\n%\r\n\\begin{center}\r\n\\includegraphics[height=0.4\\textheight]{figures/cancer_batch_1_map_testing_data.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nThe `batch 1 map' for the prototypes and test set of the cancer data is shown in Figure \\ref{fig_batch_1_map_test}.\r\nIt appears that the two classes are almost linearly separable except for the three misclassified samples.\r\nTwo are close to the boundary between the classes, while the last is a `malignant' case surrounded by `benign' cases.\r\n%\r\n\\section{Assessing the familiarity of new samples}\r\n\\label{sec_familiarity}\r\n%\r\n\\begin{figure}\r\n\\caption{Model behavior outside the `area of competence'}\r\n\\label{fig_area_of_competence}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{kNN on the rotated checkerboard}]{\\includegraphics[width=0.49\\textwidth]{figures/checker_rot_knn_surf_test.pdf}}\r\n\\subfloat[\\textbf{XGBoost on the rotated checkerboard}]{\\includegraphics[width=0.49\\textwidth]{figures/checker_rot_xgb_surf_test.pdf}}\\\\\r\n\\subfloat[\\textbf{proset on the rotated checkerboard}]{\\includegraphics[width=0.49\\textwidth]{figures/checker_rot_surf_test.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nOne problem faced by all machine learning is that their behavior becomes arbitrary for samples that are far removed from the original training data.\r\nThe way a model extrapolates outside its `area of competence' depends entirely on the specific algorithm and does not reflect any empirical evidence.\r\nThis is illustrated in Figure \\ref{fig_area_of_competence} for the rotated checkerboard example.\r\nThe plots show the probability surfaces for each of the three classifiers studied in Chapter \\ref{ch_classifier}, i.e., the color scale represents the estimated probability for class 1 from green (0.0) to red (1.0).\r\nWhile kNN and XGBoost create idiosyncratic patterns in regions of the feature space with no training data, proset reverts to the marginal distribution.\r\nThe proset estimate is no more correct than that of the other two algorithms, but we consider it the most `honest' in the absence of information.\r\nFor balanced training data as in the example, proset does not assign a high probability to an arbitrary class as may happen with kNN or XGBoost.\r\nGiven that users tend to interpret the probability of the class with the highest probability estimate as the model's `confidence' in the result, this is an important advantage.\\par\r\n%\r\nThe proset algorithm can even provide an explicit indicator that a new sample is far away from the training data.\r\nFor any $x\\in\\R^D$, we define the familiarity of a proset model with $x$ as\r\n%\r\n\\begin{equation}\r\n\\mathfrak{f}(x):=\\sum_{b=1}^B\\sum_{j=1}^{J_b}w_{b,j}G_{v_b}(x-x_{s_{b,j}})\\label{eq_familiarity}\r\n\\end{equation}\r\n%\r\nThis is just the denominator of (\\ref{eq_pkx}) minus 1, which can be provided alongside the estimate with no additional effort.\r\nFamiliarity measures the total contribution of the weighted prototypes to the estimate relative to the marginal distribution represented by the 1.\\par\r\n%\r\nInstead of using the absolute size of $\\mathfrak{f}(x)$ to assess new samples, we find it more useful to express it as a quantile of the distribution of familiarity observed for test data.\r\nAs the model may overfit its training data slightly, it is better to use held-out data for this analysis.\r\nFigure \\ref{fig_area_of_competence} shows the resulting 1 \\% contour line of familiarity for the proset classifier.\r\nFor a new sample, familiarity expressed as a quantile of the previously observed distribution can be interpreted as p-value of a statistical test whether the estimate is inside the model's `area of competence'.\\par\r\n%\r\nFor a supervised learning problem with many features, the training data is typically close to a `thin' manifold in the high-dimensional feature space.\r\nUsing quantiles of familiarity as indicated above, we can measure proximity to that manifold via a scalar indicator.\r\nThis is a powerful tool for monitoring a machine learning model in production and to detect data drift.\r\nHowever, there is a trade-off between feature selection and the usefulness of familiarity.\r\nConsider the case where proset does not select a feature because of insufficient variation in the training data.\r\nA new sample that has a markedly different value in that one feature is still assigned a high familiarity score if the features actually used by the model lie in the expected range.\r\n%\r\n\\section{Explaining individual estimates}\r\n\\label{sec_individual_explanations}\r\n%\r\n\\subsection{Explanation report}\r\n\\label{sec_explanation_report}\r\n%\r\n\\begin{figure}\r\n\\caption{Example of explanation report for cancer data}\r\n\\label{fig_explanation_report}\r\n%\r\n\\begin{center}\r\n\\includegraphics[width=0.99\\textwidth]{figures/cancer_2d_95_model_explain.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nOur implementation of proset can export information about the model as tabular data.\r\nThe basic report contains information on all prototypes, their weights, and active features.\r\nA more interesting report relates a particular sample to the selected prototypes.\r\nFigure \\ref{fig_explanation_report} shows an example analysis for the proset classifier.\r\nIt deals with the one misclassified `malignant' case from the cancer data example that is surrounded by `benign' cases.\r\nThe report contains the following information:\r\n%\r\n\\begin{description}\r\n\\item[Batch:] the number of the batch to which each prototype belongs.\r\nThe model in the example has only a single batch.\r\nThe first three rows contain information on the misclassified sample and the marginal distribution, they are not associated with any batch.\r\n%\r\n\\item[Sample:] the zero-based index of the prototype with respect to the ordering of the training data after the train-test split.\r\n%\r\n\\item[Sample name:] the record for the test sample states its zero-based index within the set of test data, the class with the highest estimated probability, and familiarity expressed as a quantile of the distribution for the test data.\r\nThe remaining rows indicate whether they belong to the marginal distribution or individual prototypes.\r\n%\r\n\\item[Target:] the numeric representation of the class, either 0 (`benign') or 1 (`malignant').\r\nThe first rows contains the true target for the test sample.\r\n%\r\n\\item[Prototype weight:] the value $w_{b,j}$ for each prototype.\r\nThe test sample has no entry, records for the marginal distribution show the marginal probability for the corresponding class.\r\n%\r\n\\item[Similarity:] the value of the unnormalized Kernel $G_{v_b}$ at $x-x_{s_{b,j}}$.\r\nThis is a number in $(0,1]$, where $1$ indicates that the sample features $x$ are identical to those of the prototype.\r\nThe test sample has no entry, records for the marginal probabilities list a 1 as they affect all estimates equally.\r\n%\r\n\\item[Impact:] the product of prototype weight and similarity is the total impact of the prototype on the estimated probability (\\ref{eq_pkx}).\r\nBy default, the report lists the prototypes in order of descending impact.\r\n%\r\n\\item[Dominant set:] a binary indicator of observations that have the largest impact on the estimate.\r\nThe target values for prototypes outside the dominant set can be changed without affecting which class is assigned the highest probability.\r\nSee below for a precise definition of the dominant set.\r\n%\r\n\\item[p class 0:] the record for the test sample shows the estimated probability for class 0 (`benign').\r\nThe remaining rows contain the additive contribution of the marginal distribution and prototypes to this estimate.\r\nThe contribution is equal to the impact listed for the row divided by the total impact if the target is 0.\r\nOtherwise, the contribution is zero.\r\n%\r\n\\item[p class 1:] as above for class 1 (`malignant').\r\n\\end{description}\r\n%\r\nThe report provides a complete breakdown of the estimate for one sample into the contribution of the marginals and prototypes.\r\nThe multivariate structure of the feature space is replaced by a simple list that can be filtered and sorted by different criteria to identify major contributors.\r\nWhile the total number of prototypes can be much larger than in the example, most tend to have negligible impact on any particular case.\\par\r\n%\r\nFor the computation of the `dominant set' indicator, we use the following procedure:\r\n%\r\n\\begin{algorithm}[Dominant set]~\r\n\\label{alg_dominant_set}\r\n%\r\n\\begin{enumerate}\r\n\\item Sort the prototypes in descending order of impact and assign a rank to each.\r\nPrototypes with the same impact receive the same rank.\r\n%\r\n\\item For each rank $r$, compute $p_{r,k}$ as sum of additive contributions (columns `p class 0', etc.\\ in the report) to the probability estimate for class $k$ from the marginal distribution and prototypes up to rank $r$.\r\nThese satisfy $0<\\sum_{k=0}^{K_1}p_{r,k}\\leq 1$.\r\nThe remainder $t_r:=1-\\sum_{k=0}^{K-1}p_{r,k}$ is the total contribution of prototypes with rank greater than $r$.\r\n%\r\n\\item For each rank $r$, denote by $k_{1,r}$ and $k_{2,r}$ the classes with the largest and second largest value of $p_{r,k}$.\r\nDetermine the set  $R:=\\{r:p_{r,k_{1_r}}-p_{r,k_{2,r}}>t_r\\}$.\r\n%\r\n\\item If $R$ is empty, the dominant set is empty.\r\nOtherwise, all prototypes with a rank less than or equal to the minimal element in $R$ form the dominant set.\r\n\\end{enumerate}\r\n\\end{algorithm}\r\n%\r\n\\begin{remark}\r\nBy constructions, if $R$ is not empty, it contains all ranks greater than or equal to its minimal element and all share the same value for $k_{1,r}$.\r\nThus, it contains all ranks where the remainder $t_r$ is too small to affect which class is assigned the highest probability.\r\n\\end{remark}\r\n%\r\nIn the example report, the prototypes of the dominant set together with the marginal distribution contribute 53 percentage points of the 99 \\% probability estimated for class 0.\r\nThus, class 0 would be assigned the highest probability even if all remaining prototypes belonged to class 1.\r\nThe purpose of the dominant set is to serve as a guideline which prototypes need to be reviewed for a better understanding of a particular result.\\par\r\n%\r\n\\begin{figure}\r\n\\caption{`Batch 1 map' of cancer data showing prototype impact}\r\n\\label{fig_batch_1_map_impact}\r\n%\r\n\\begin{center}\r\n\\includegraphics[height=0.4\\textheight]{figures/cancer_batch_1_map_impact.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nThe impact of prototypes on a particular estimate can also be visualized in the `batch 1 map'.\r\nFigure \\ref{fig_batch_1_map_impact} does this for the case from the example report.\r\nThe size of each circle is proportional to the impact of the prototype, numbers refer to the sample index.\r\n%\r\n\\subsection{Combining SHAP values and geometric analysis}\r\n\\label{sec_shap_values}\r\n%\r\nSo far, we have looked at model-specific explanations for proset estimators on their own.\r\nIn this section, we combine them with a model-agnostic approach to gain additional insight into the model structure.\r\nWe choose the SHAP (SHapley Additive exPlanations) method for assessing feature importance proposed by Lundberg and Lee \\cite{Lundberg_17}.\r\nSHAP provides explanations for individual estimates and is the only additive feature attribution method that has certain desirable properties.\r\nA downside is that the computational effort grows exponentially in the number of features, although an efficient algorithm exists for decision trees \\cite{Lundberg_18}.\r\nTo facilitate usage of SHAP, our implementation of proset allows `shrinking' the model to take only the features with nonzero weights as input.\\par\r\n%\r\nSHAP explains an estimate by comparing the sample of interest to a reference point.\r\nThe relative change in the estimator between the points is attributed to the relative change in the features.\r\nThere appears to be little research so far on the best choice of reference point, but Izzo et.\\ al.\\ \\cite{Izzo_20} consider the issue.\r\nThe authors point out that the common choice of using the origin of the feature space as baseline is not satisfactory.\r\nFor a binary classifier, they recommend to select a reference point on the decision boundary between the two classes.\r\nThey refer to this as a `neutral baseline', since the algorithm is indifferent which class to choose.\r\nWe cannot follow this approach, as we want to study the probability estimate itself without reference to a decision rule\\footnote{\r\nWe do use the `naive' decision rule that selects the class with the highest estimated probability to define bins for Algorithm \\ref{alg_bins} and to compute balanced accuracy as a secondary metric for the benchmark study.\r\nSee the discussion in the next paragraph why we do not consider this rule for further analysis.\r\n}.\r\nAlso, several of the benchmark cases have more than two classes and it is not certain that a point can be found that is `neutral' with regards to all of them at once.\\par\r\n%\r\nWe believe that classification should always be carried out in two stages by combining a stochastic model with a decision rule.\r\nThe purpose of the former is to accurately estimate the probability distribution with no regard to the practical problem we want to solve.\r\nThe purpose of the latter is to optimize the expected value of a problem-specific utility or loss function under the estimated distribution.\r\nAny algorithm that conflates the two stages implicitly applies an arbitrary decision rule that is likely to yield sub-optimal results.\r\nAs an example, consider a credit scoring algorithm that estimates the default probability for loans.\r\nIt is doubtful that the lending company wants to grant loans to all applicants with default probability less than 50 \\%.\r\nA more thorough discussion of this issue can be found, e.g., in a blog article by Harrell \\cite{Harrell_20}.\\par\r\n%\r\nFor the above reason, we want to find a suitable reference point for explaining the estimated probabilities themselves regardless of any decision rule that could be applied later.\r\nWe expect such a point to have the following three properties:\r\n%\r\n\\begin{enumerate}\r\n\\item The point itself represents a feasible combination of features.\r\n%\r\n\\item The point is not extreme in terms of the feature space.\r\nFor every feature, there are training samples that have either a higher or lower value.\r\n%\r\n\\item The point is not extreme in terms of the estimated probabilities.\r\nFor every class, there are training samples that have either a higher or lower estimate.\r\n\\end{enumerate}\r\n%\r\n\\begin{remark}\r\n\\begin{enumerate}\r\n\\item Property 1 acknowledges that the baseline is part of the explanation and should have no `unnatural' characteristics.\r\nThere is less risk of misinterpreting the feature importance if they are computed with respect to a relatable feature vector.\r\n%\r\n\\item Properties 2 and 3 mean that SHAP can explore changes of the input and output in all directions.\r\n%\r\n\\item Property 3 can be viewed as a weaker notion of the `neutral baseline' proposed in \\cite{Izzo_20}.\r\n%\r\n\\item Properties 1 and 2 are mutually exclusive for binary features.\r\nHere, we prefer property 1, i.e., the baseline should be a genuine case and not a hypothetical half-way point.\r\n\\end{enumerate}\r\n\\end{remark}\r\n%\r\nOne way to satisfy the first condition is to use an actually observed point as reference.\r\nThe first two conditions imply that a medoid\\footnote{\r\nA medoid is any point from a set for which the average absolute distances to all other points is minimal.\r\nIn one dimension, a medoid is also a median of the data.\r\n} of the feature vectors for the training data is a suitable choice.\r\nLikewise, condition 1 and 3 suggest to use a point whose estimated probabilities are a medoid of the probability vectors for the training data.\r\nWe thus propose the following procedure for choosing a baseline:\r\n%\r\n\\begin{algorithm}[SHAP baseline]~\r\n\\label{alg_shap_baseline}\r\n%\r\n\\begin{enumerate}\r\n\\item Rank all training samples in increasing order of average absolute distance to all other training samples in the feature space.\r\nUse only features selected by proset to compute distances.\r\n%\r\n\\item Rank all training samples in increasing order of average absolute distance to all other training samples in the space of estimated probability vectors.\r\n%\r\n\\item Combine both rankings using Borda's rule\\footnote{\r\nBorda's rule converts rankings to scores by assigning each candidate half a point for each other candidate ranked the same, plus a full point for each candidate ranked worse.\r\nScores are totaled across rankings and the winners are the candidates with the most points.\r\n} and use the winner as reference.\r\nIn case of a tie, choose the candidate whose probability vector has the highest entropy.\r\nIf still tied, use the point with the lowest sample index.\r\n\\end{enumerate}\r\n\\end{algorithm}\r\n%\r\n\\begin{remark}\r\n\\begin{enumerate}\r\n\\item We do not recommend to combine the active features and estimated probabilities into a single vector.\r\nThe medoid property depends on the scaling of of individual variables and there is no obvious common scale.\r\nAlso, if there are many more features than classes, the former might dominate the decision.\r\nComputing two separate rankings and using Borda's rule results in a choice that balances properties 2 and 3.\r\n%\r\n\\item The method requires computing pairwise distances for all training samples, which may be unattractive for large problems.\r\nIn this case, we recommend subsampling.\r\n\\end{enumerate}\r\n\\end{remark}\r\n%\r\n\\begin{figure}\r\n\\caption{`Batch 1 map' of cancer data showing reference point}\r\n\\label{fig_batch_1_map_reference}\r\n%\r\n\\begin{center}\r\n\\includegraphics[height=0.4\\textheight]{figures/cancer_batch_1_map_training_data_reference.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\n\\begin{figure}\r\n\\caption{SHAP feature importance}\r\n\\label{fig_feature_importance}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{Global importance}]{\\includegraphics[width=0.99\\textwidth]{figures/cancer_global_shap.pdf}}\\\\\r\n\\subfloat[\\textbf{Misclassified case}]{\\includegraphics[width=0.99\\textwidth]{figures/cancer_example_shap.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\n\\begin{figure}\r\n\\caption{Scatter plots for important features}\r\n\\label{fig_scatter_important}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{Global importance}]{\\includegraphics[height=0.4\\textheight]{figures/cancer_scatter_global_shap.pdf}}\\\\\r\n\\subfloat[\\textbf{Misclassified case}]{\\includegraphics[height=0.4\\textheight]{figures/cancer_scatter_example_shap.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\n\\begin{figure}\r\n\\caption{Probability surfaces for important features}\r\n\\label{fig_probability_important}\r\n%\r\n\\begin{center}\r\n\\subfloat[\\textbf{Global importance}]{\\includegraphics[height=0.4\\textheight]{figures/cancer_surface_global_shap.pdf}}\\\\\r\n\\subfloat[\\textbf{Misclassified case}]{\\includegraphics[height=0.4\\textheight]{figures/cancer_surface_example_shap.pdf}}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nIf we apply the above rule to the cancer data, it selects a baseline near the center of the point cloud of training samples.\r\nThe estimated probability for being `benign' is 92 \\%, which is far from the 50 \\% that would be achievable given the structure of the data.\r\nHowever, the data is unbalanced in favor of `benign' cases and we have seen for the misclassified case in the previous section that probabilities in excess of 92 \\% are achievable.\r\nFigure \\ref{fig_batch_1_map_reference} shows the reference point in a `batch 1 map' together with training data and the misclassified case we want to explain.\\par\r\n%\r\nFigure \\ref{fig_feature_importance} shows the results of SHAP analysis for the whole test data and the misclassified case.\r\nNote that the global values are just the averages of the absolute scores of each feature across all samples.\r\nOrdering the features by descending global importance yields the same sequence as for the feature weights, but we do not believe that this necessarily holds for every data set.\r\nThe two most important features globally are `worst radius' and `worst concave points'.\r\nFor the misclassified case, the estimate for class `benign' is shifted from 92 \\% (baseline) to 99 \\% because of the extremely low values for `worst concave points' and `worst smoothness'.\r\nFigure \\ref{fig_scatter_important} shows the bivariate scatter plots for both pairs of features, this time with training data as supplementary information.\r\nAs an alternative, we can study the probability surface resulting for the most important features if the other features are fixed at their values for the misclassified case.\r\nThis is shown in Figure \\ref{fig_probability_important}.\\par\r\n%\r\n\\clearpage\r\n%\r\n\\begin{figure}\r\n\\caption{`Batch 1 map' for digits data showing test samples}\r\n\\label{fig_batch_1_map_test_digits}\r\n%\r\n\\begin{center}\r\n\\includegraphics[width=0.95\\textheight, angle=90]{figures/digits_batch_1_map.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\n\\begin{figure}\r\n\\caption{Explanation combining prototypes and SHAP values}\r\n\\label{fig_impact_shap}\r\n%\r\n\\begin{center}\r\n\\includegraphics[width=0.95\\textheight, angle=90]{figures/digits_8_vs_1_explanation.pdf}\r\n\\end{center}\r\n\\end{figure}\r\n%\r\nAs a final example, we show how to create an explanation for the digits data set that relies both on prototypes with high impact and SHAP values.\r\nThis classification problem is more complex than the one for cancer data.\r\nFigure \\ref{fig_batch_1_map_test_digits} presents the `batch 1 map' including test data and a reference point selected using the ranking rule.\r\nSeveral classes are well differentiated in this plot, but a two-dimensional representation clearly cannot capture the whole structure.\\par\r\n%\r\nFigure \\ref{fig_impact_shap} is a custom plot for explaining a particular misclassified digit.\r\nIt shows the case itself -- an `8' for which the highest probability is estimated for class `1' -- as well as the five prototypes with the largest impact on the result.\r\nThe second row overlays the SHAP values for the probability estimate of the true class `8', the third does the same for class `1'.\r\nA red color indicates that the estimate is increased because of the grayscale value of the associated pixel, a blue color that it is decreased.\r\nNote that the estimated probabilities for the baseline are 61 \\% for class `8', 27 \\% for class `3', and negligible for the other digits.\r\nThus, the SHAP values indicate the importance of the features for a shift away from this distribution towards 60 \\% for class `1' and 32 \\% for class `8'.\r\n%\r\n\\endinput\r\n", "meta": {"hexsha": "f649d4562e0fda1542ff31e14fc87dbc6a6adf76", "size": 26719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/explainability.tex", "max_stars_repo_name": "NRuf77/proset", "max_stars_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_stars_repo_licenses": ["MIT"], "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/explainability.tex", "max_issues_repo_name": "NRuf77/proset", "max_issues_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_issues_repo_licenses": ["MIT"], "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/explainability.tex", "max_forks_repo_name": "NRuf77/proset", "max_forks_repo_head_hexsha": "101d491e05c2423faddca31029232982f46d8831", "max_forks_repo_licenses": ["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.0097323601, "max_line_length": 263, "alphanum_fraction": 0.7833376998, "num_tokens": 6099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.625562880046471}}
{"text": "\\subsection{Exponential function}\\label{subsec:exponential_function}\n\n\\begin{definition}\\label{def:exponential_function}\n  We define the \\term{exponential function}\n  \\begin{equation}\\label{def:exponential_function/series}\n    \\exp(z) \\coloneqq \\sum_{k=0}^\\infty \\frac {z^k} {k!}\n  \\end{equation}\n  and \\term{Euler's number}\n  \\begin{equation*}\n    e \\coloneqq \\exp(1) = \\sum_{i=0}^k \\frac 1 {k!}.\n  \\end{equation*}\n\n  \\Fullref{thm:def:exponential_function/interpolates_power} justifies the notation \\( e^z = \\exp(z) \\).\n\\end{definition}\n\\begin{proof}\n  We will show that \\( \\exp(z) \\) converges everywhere. By \\fullref{thm:power_series_radius_of_convergence}, the radius of convergence is\n  \\begin{equation*}\n    \\limsup_{k \\to \\infty} \\frac {k!} {(k-1)!}\n    =\n    \\limsup_{k \\to \\infty} k\n    =\n    +\\infty\n  \\end{equation*}\n\n  Hence, the radius of convergence of \\( \\exp(x) \\) is infinite.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:exponential_function}\n  The exponential function \\( \\exp(z) \\) has the following basic properties (not that we do not use the notation \\( e^z \\) here in order to reduce confusion with yet-undefined power \\hyperref[def:power_function]{functions}):\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:exponential_function/eulers_identity} (Euler's identity)\n    \\begin{equation*}\n      \\exp(i \\pi) = -1.\n    \\end{equation*}\n\n    \\thmitem{thm:def:exponential_function/derivative} \\( \\exp(z) \\) is its own derivative.\n\n    \\thmitem{thm:def:exponential_function/homomorphism} \\( \\exp(x + y) = \\exp(x) \\exp(y) \\). Stated in another way, \\( \\exp \\) is a homomorphism from the additive group of \\( \\BbbC \\) to the multiplicative group.\n\n    \\thmitem{thm:def:exponential_function/interpolates_power} The notation \\( \\exp(x) \\) is consistent with iterated multiplication as defined in \\fullref{def:semiring/identity}, that is, \\( \\exp(n) = \\underbrace{e \\cdot \\ldots \\cdot e}_{n \\text{times}} \\) and for positive integers \\( n \\), \\( \\exp(n) =  \\) and \\( \\exp(-n) =\\tfrac 1 {\\exp(n)} \\).\n\n    \\thmitem{thm:def:exponential_function/negative_power}\n    \\begin{equation*}\n      \\exp(z) = \\frac 1 {\\exp(-z)}.\n    \\end{equation*}\n\n    \\thmitem{thm:def:exponential_function/real_positive} For real \\( t \\), \\( e^t \\) is a positive real number.\n\n    \\thmitem{thm:def:exponential_function/conjugate} \\( \\overline{\\exp(z)} = \\exp(\\overline{z}) \\).\n\n    \\thmitem{thm:def:exponential_function/unit_circle} For any \\( c \\in \\BbbR \\), the function \\( t \\mapsto \\exp(it) \\) is a bijection between any half-open interval \\( [c, c + 2\\pi) \\) and the unit circle in \\( \\BbbC \\).\n\n    \\thmitem{thm:def:exponential_function/real_bijective} \\( t \\mapsto \\exp(t) \\) is a bijection from \\( \\BbbR \\) to \\( [0, \\infty) \\).\n\n    \\thmitem{thm:def:exponential_function/bijective} For any \\( c \\in \\BbbR \\), \\( \\exp(z) \\) is a bijection between the strip \\( S \\coloneqq \\{ a + bi \\colon c \\leq b < c + 2\\pi \\} \\) and the complex plane \\( \\BbbC \\setminus \\{ 0 \\} \\).\n\n    \\thmitem{thm:def:exponential_function/periodic} \\( \\exp(z) \\) is \\( 2i\\pi \\)-\\hyperref[def:periodic_function]{periodic}.\n\n    \\thmitem{thm:def:exponential_function/compound_interest} For nonnegative real \\( t \\geq 0 \\) we have\n    \\begin{equation*}\n      \\exp(t) = \\lim_{n \\to \\infty} \\left(1 + \\frac t n \\right)^n\n    \\end{equation*}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:exponential_function/eulers_identity} By \\fullref{eq:thm:trigonometric_function_basic_roots/pi} and \\fullref{thm:exponential_trigonometric_identities/eulers_formula}, we have\n  \\begin{equation*}\n    \\exp(i\\pi) = \\cos(\\pi) + i\\sin(\\pi) = -1.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:exponential_function/derivative} Follows from \\fullref{thm:power_series_are_locally_uniform_convergent} and \\fullref{thm:derivative_limit_exchange}.\n\n  \\SubProofOf{thm:def:exponential_function/homomorphism} The Cauchy product of \\( \\exp(x) \\) and \\( \\exp(y) \\) is\n  \\begin{balign*}\n    \\exp(x) \\exp(y)\n     & =\n    \\left( \\sum_{k=0}^\\infty \\frac {x^k} {k!} \\right) \\left( \\sum_{k=0}^\\infty \\frac {y^k} {k!} \\right)\n    =                                       \\\\ &=\n    \\sum_{k=0}^\\infty \\sum_{m=0}^k \\frac {x^m} {m!} \\frac {x^{k-m}} {(k-m)!}\n    =                                       \\\\ &=\n    \\sum_{k=0}^\\infty \\frac 1 {k!} \\sum_{m=0}^k \\binom{k}{m} x^m y^{k-m}\n    \\reloset {\\ref{thm:binomial_theorem}} = \\\\ &=\n    \\sum_{k=0}^\\infty \\frac {(x + y)^k} {k!}\n    =\n    \\exp(x + y).\n  \\end{balign*}\n\n  \\SubProofOf{thm:def:exponential_function/interpolates_power} We use induction on \\( n \\) to prove \\( \\exp(n) = e^n \\). The case \\( \\exp(0) = 1 \\) is obvious. If we assume that \\( \\exp(n) = e^n \\), by \\fullref{thm:def:exponential_function/homomorphism}, we have\n  \\begin{equation*}\n    \\exp(n + 1)\n    =\n    \\exp(n) \\exp(1)\n    =\n    e^n \\cdot e\n    =\n    e^{n+1}.\n  \\end{equation*}\n\n  Note that this works for negative \\( n \\) too.\n\n  \\SubProofOf{thm:def:exponential_function/negative_power} Note that\n  \\begin{equation*}\n    1 = \\exp(0) = \\exp(z - z) = \\exp(z) \\exp(-z),\n  \\end{equation*}\n  hence\n  \\begin{equation*}\n    \\exp(-z) = \\frac 1 {\\exp(z)}.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:exponential_function/real_positive} For \\( t > 0 \\), the following\n  \\begin{equation*}\n    \\exp(t) = \\sum_{k=0}^\\infty \\frac {t^k} {k!}\n  \\end{equation*}\n  is a series of positive real numbers. To see its convergence, we apply \\fullref{thm:dalamberts_ratio_test}:\n  \\begin{equation*}\n    \\frac {t^k} {k!} \\cdot \\frac {(k-1)!} {t^{k-1}}\n    =\n    \\frac t k\n    \\xrightarrow[k \\to \\infty]{} 0.\n  \\end{equation*}\n\n  Thus, \\( \\exp(t) \\) is a nonnegative real number. Furthermore, since the sequence of partial sums is monotone, \\( \\exp(t) \\) cannot be zero. Hence, for \\( t > 0 \\), we have \\( \\exp(t) > 0 \\).\n\n  Notice that \\( \\exp(t) \\exp(-t) > 0 \\), hence if \\( \\exp(t) > 0 \\), then \\( \\exp(-t) > 0 \\).\n\n  \\SubProofOf{thm:def:exponential_function/conjugate} By \\fullref{thm:exponential_trigonometric_identities/eulers_formula},\n  \\begin{balign*}\n    \\overline{\\exp(a + bi)}\n     & \\reloset {\\ref{thm:def:exponential_function/homomorphism}} =\n    \\overline{\\exp(a) \\exp(bi)}\n    \\reloset {\\ref{thm:def:exponential_function/real_positive}} =   \\\\ &=\n    \\exp(a) \\overline{(\\cos(b) + i\\sin(b))}\n    =                                                                      \\\\ &=\n    \\exp(a) (\\cos(b) - i\\sin(b))\n    \\reloset {\\ref{thm:power_series_parity}} =                             \\\\ &=\n    \\exp(a) (\\cos(-b) + i\\sin(-b))\n    =                                                                      \\\\ &=\n    \\exp(a) \\exp(-bi)\n    =                                                                      \\\\ &=\n    \\exp(a - bi)\n    =                                                                      \\\\ &=\n    \\exp(\\overline{a + bi}).\n  \\end{balign*}\n\n  \\SubProofOf{thm:def:exponential_function/periodic} By \\fullref{thm:def:exponential_function/eulers_identity},\n  \\begin{equation*}\n    \\exp(x + 2i\\pi) = \\exp(x) \\exp(2i\\pi) = \\exp(x).\n  \\end{equation*}\n\n  Furthermore, this is also the minimal period. If we assume that \\( \\sin(x) \\) has another period, say \\( p \\in (0, 2\\pi) \\), we would have \\( \\sin(p) = \\sin(0) = 0 \\) and \\fullref{thm:trigonometric_identities/pythagorean_identity} would imply that \\( \\cos(p) \\in \\{ -1, 1 \\} \\). But then \\( \\cos(p) \\) would be an extreme point for \\( \\cos \\), which is not possible because \\( \\cos \\) is convex in \\( [0, 2\\pi] \\) and only has three extremal points --- \\( 0, \\pi, 2\\pi \\).\n\n  \\SubProofOf{thm:def:exponential_function/unit_circle} For \\( c, t \\in \\BbbR \\) we have\n  \\begin{equation*}\n    \\abs{\\exp(it)}\n    =\n    \\abs{\\cos(t) + i\\sin(t)}\n    =\n    \\sqrt{\\cos(t)^2 + \\sin(t)^2}\n    \\reloset {\\eqref{eq:thm:trigonometric_identities/pythagorean_identity}} =\n    1.\n  \\end{equation*}\n\n  Furthermore, if \\( r \\) is another real number,\n  \\begin{equation}\n    \\exp(ir)\n    =\n    \\exp(i(t + (r - t)))\n    =\n    \\exp(it) \\exp(i(r - t)).\n  \\end{equation}\n\n  It follows that \\( \\exp(ir) \\neq \\exp(it) \\) if and only if \\( \\exp(i(r - t)) \\neq 0 \\). If \\( t, r \\in [c, c + 2\\pi) \\) and \\( t \\neq r \\), this is satisfied.\n\n  Hence, \\( t \\mapsto \\exp(it) \\) is indeed an injection of \\( [c, c + 2\\pi) \\) into the unit circle of \\( \\BbbC \\). It is also a surjection because of the intermediate value theorem.\n\n  \\SubProofOf{thm:def:exponential_function/real_bijective} First, assume that \\( e^t \\) is not injective on \\( \\BbbR \\). Then there exist \\( t, r \\in \\BbbR \\), \\( t \\neq r \\), such that \\( e^t = e^r \\). By \\fullref{thm:def:exponential_function/real_positive}, both are positive real numbers. In particular, we can divide by \\( e^t \\) to obtain\n  \\begin{equation*}\n    1\n    =\n    \\frac {e^r} {e^t}\n    \\reloset {\\ref{thm:def:exponential_function/negative_power}} =\n    =\n    e^r e^{-t}\n    \\reloset {\\ref{thm:def:exponential_function/homomorphism}} =\n    e^{r - t}.\n  \\end{equation*}\n\n  We know that \\( e^0 = 1 \\) from \\fullref{thm:def:exponential_function/interpolates_power}. Thus, it is enough to show that \\( e^t = 1 \\) if and only if \\( t = 0 \\).\n\n  Assume that \\( e^t = 1 \\) holds for some \\( t > 0 \\). The partial sums are monotonely increasing, so in order for them to converge to \\( 1 \\), for any fixed index \\( n \\) we must have\n  \\begin{balign*}\n    0  & \\leq \\sum_{k=0}^n \\frac {t^k} {k!} = 1 + \\sum_{k=1}^n \\frac {t^k} {k!} \\leq 1, \\\\\n    -1 & \\leq \\sum_{k=1}^n \\frac {t^k} {k!} \\leq 0.\n  \\end{balign*}\n\n  But \\( \\sum_{k=1}^n \\frac {t^k} {k!} > 0 \\) because \\( t > 0 \\). The obtained contradiction proves that \\( e^t \\neq 1 \\) for positive \\( t \\).\n\n  For negative \\( t \\), note that\n  \\begin{equation*}\n    e^t e^{-t} = 1.\n  \\end{equation*}\n\n  Since \\( -t \\) is positive, \\( e^{-t} \\neq 1 \\) and hence \\( e^t \\neq 1 \\).\n\n  Therefore, the function \\( t \\mapsto e^t \\) is injective on \\( \\BbbR \\). It is also surjective onto \\( \\BbbR^{>0} \\) because of the intermediate value theorem.\n\n  \\SubProofOf{thm:def:exponential_function/bijective} Fix \\( a + bi \\in S_c \\), that is, \\( b \\in [c, c + 2\\pi) \\). By \\fullref{thm:def:exponential_function/homomorphism},\n  \\begin{equation*}\n    e^{a + bi} = e^a e^{bi}.\n  \\end{equation*}\n\n  By \\fullref{thm:def:exponential_function/unit_circle}, \\( b \\mapsto e^{bi} \\) is injective for \\( b \\in [c, c + 2\\pi) \\) and by \\fullref{thm:def:exponential_function/real_bijective}, \\( a \\mapsto e^a \\) is injective on \\( \\BbbR \\). It follows that their product is also injective.\n\n  \\SubProofOf{thm:def:exponential_function/compound_interest}\\mcite[3.31]{Rudin1976Principles}By \\fullref{thm:binomial_theorem},\n  \\begin{balign*}\n    \\left(1 + \\frac t n \\right)^n\n     & =\n    \\sum_{k=0}^n \\binom{n}{k} \\left(\\frac t n\\right)^k 1^{n-k}\n    =    \\\\ &=\n    \\sum_{k=0}^n \\frac {n!} {(n-k)! k!} \\frac {t^k} {n^k}\n    =    \\\\ &=\n    \\sum_{k=0}^n \\frac {n!} {(n-k)! n^k} \\frac {t^k} {k!}\n    =    \\\\ &=\n    \\sum_{k=0}^n \\left[ \\prod_{j=1}^k \\left(1 - \\frac {k+j} n \\right) \\right] \\frac {t^k} {k!}.\n  \\end{balign*}\n\n  Fix an index \\( m \\). Since the series is nonnegative, there exists an index \\( N \\) such that for \\( n \\geq N \\)\n  \\begin{equation*}\n    \\sum_{k=0}^m \\frac {t^k} {k!}\n    \\leq\n    \\sum_{k=0}^n \\left[ \\prod_{j=1}^k \\left(1 - \\frac {k+j} n \\right) \\right] \\frac {t^k} {k!}.\n  \\end{equation*}\n\n  Note that\n  \\begin{equation*}\n    \\left[ \\prod_{j=1}^k \\left(1 - \\frac {k+j} n \\right) \\right] \\frac {t^k} {k!}\n    \\leq\n    \\frac {t^k} {k!},\n  \\end{equation*}\n  hence\n  \\begin{equation*}\n    \\sum_{k=0}^m \\frac {t^k} {k!}\n    \\leq\n    \\sum_{k=0}^n \\left[ \\prod_{j=1}^k \\left(1 - \\frac {k+j} n \\right) \\right] \\frac {t^k} {k!}\n    \\leq\n    \\sum_{k=0}^n \\frac {t^k} {k!}.\n  \\end{equation*}\n\n  By \\fullref{thm:squeeze_lemma},\n  \\begin{equation*}\n    \\lim_{n \\to \\infty} \\left(1 + \\frac t n \\right)^n\n    =\n    \\lim_{n \\to \\infty} \\sum_{k=0}^n \\frac {t^k} {k!}\n    =\n    \\exp(t).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:logarithm}\n  Fix \\( c \\in \\BbbR \\). Unless specified otherwise, we assume \\( c = 0 \\).\n\n  We define the \\term{natural logarithm} \\( \\log(x) \\) as \\hyperref[def:multi_valued_function/inverse]{inverse function} of \\( e^x \\) from \\( \\BbbC \\setminus \\{ 0 \\} \\) to the strip \\( S_c \\coloneqq \\{ a + bi \\colon c \\leq b < c + 2\\pi \\} \\).\n\n  We also define the \\term{base \\( b \\) logarithm} \\( \\log_b(x) \\) for \\( b > 0 \\) over the same domain as\n  \\begin{equation*}\n    \\log_b(x) \\coloneqq \\frac {\\log(x)} {\\log(b)}.\n  \\end{equation*}\n\\end{definition}\n\\begin{proof}\n  The well-definedness follows from \\fullref{thm:def:exponential_function/bijective}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:logarithm}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{thm:def:logarithm/homomorphism} \\( \\log(xy) = \\log(x) \\log(y) \\)\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:logarithm/homomorphism} Follows from \\fullref{thm:def:exponential_function/homomorphism}.\n\\end{proof}\n\n\\begin{definition}\\label{def:power_function}\n  For each positive real number \\( y > 0 \\), we define the \\term{power function}\n  \\begin{equation*}\n    x^y \\coloneqq e^{y \\ln x}\n  \\end{equation*}\n  as a function of \\( x \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:power_function}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{thm:def:power_function/composition} \\( (x^y)^z = x^{yz} \\).\n    \\thmitem{thm:def:power_function/derivative} \\( D_x(x^y) = \\log(x) x^y \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:power_function/composition}\n  \\begin{equation*}\n    (x^y)^z\n    =\n    e^{z \\log(e^{y \\log(x)})}\n    =\n    e^{z y \\log(x)}\n    =\n    x^{yz}.\n  \\end{equation*}\n\n  \\SubProofOf{thm:def:power_function/derivative} Using the chain rule for differentiation, we obtain\n  \\begin{equation*}\n    D_x(x^y) = D_x(e^{\\log(y) x}) = \\log(x) e^{\\log(y) x} = \\log(x) x^y.\n  \\end{equation*}\n\\end{proof}\n\\begin{proposition}\\label{thm:exponential-trigonometric_identities}\n  We have the following exponential-trigonometric identities:\n  \\thmitem{thm:exponential_trigonometric_identities/eulers_formula} (Euler's formula) For any \\( z \\in \\BbbC \\),\n  \\begin{equation}\\label{thm:exponential_trigonometric_identities/eulers_formula/identity}\n    e^{iz} = \\cos(z) + i \\sin(z).\n  \\end{equation}\n\n  \\thmitem{thm:exponential_trigonometric_identities/inverse_eulers_formula} (Inverse Euler's identities) For any \\( z \\in \\BbbC \\),\n  \\begin{balign}\n    \\sin(z) & = \\real(e^z) = \\frac {e^{iz} - e^{-iz}} {2i} \\label{thm:exponential_trigonometric_identities/inverse_eulers_formula/sin} \\\\\n    \\cos(z) & = \\imag(e^z) = \\frac {e^{iz} + e^{-iz}} 2 \\label{thm:exponential_trigonometric_identities/inverse_eulers_formula/cos}\n  \\end{balign}\n\n  \\thmitem{thm:exponential_trigonometric_identities/de_moivre} (De Moivre's formula) For any complex number \\( z \\) and any nonnegative integer \\( n \\),\n  \\begin{equation}\\label{thm:exponential_trigonometric_identities/de_moivre/identity}\n    (\\cos(z) + i \\sin(z))^n = \\cos(nz) + i \\sin(nz).\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:exponential_trigonometric_identities/eulers_formula} Simply note that \\fullref{def:exponential_function} is a termwise sum of \\fullref{def:trigonometric_functions/sine} and \\fullref{def:trigonometric_functions/cosine}, therefore \\fullref{thm:exponential_trigonometric_identities/eulers_formula/identity} holds.\n\n  \\SubProofOf{thm:exponential_trigonometric_identities/inverse_eulers_formula} Follows from \\fullref{thm:exponential_trigonometric_identities/eulers_formula}.\n\n  \\SubProofOf{thm:exponential_trigonometric_identities/de_moivre} From \\fullref{thm:exponential_trigonometric_identities/eulers_formula},\n  \\begin{equation*}\n    (\\cos(z) + i \\sin(z))^n\n    =\n    {e^{iz}}^n\n    \\reloset {\\ref{thm:def:power_function/composition}} {=}\n    =\n    e^{i(zn)}\n    =\n    \\cos(nz) + i \\sin(nz).\n  \\end{equation*}\n\\end{proof}\n", "meta": {"hexsha": "46566d77da5c3336a09346edc06dcdbd5e4c4840", "size": 15778, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/exponential_function.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/exponential_function.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/exponential_function.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": 44.9515669516, "max_line_length": 474, "alphanum_fraction": 0.6191532514, "num_tokens": 5720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6255628793261822}}
{"text": "\\chapter*{Appendix C: Derivative Needed for the Minimization}\n\\label{annexB}\n\\addcontentsline{toc}{chapter}{Appendix C: Derivative Needed for the \nMinimization}\n\n\\subsection*{The error function}\n The error function is written erf(x) and the complementary error function\n erfc(x). Their definitions are:\n\\begin{eqnarray}\n  \\mbox{erf(x)} = \\frac{2}{\\sqrt{\\pi}}\\int_{0}^{x} e^{-t^{2}} dt \n\\end{eqnarray}\n\n\\begin{eqnarray}\n  \\mbox{erfc}(x) = 1-\\mbox{erf}(x) = \\frac{2}{\\sqrt{\\pi}}\\int_{x}^{\\infty} e^{-t^{2}} dt \n\\end{eqnarray}\n\nThese functions have the following limits and symmetries:\n\\begin{eqnarray}\n   \\begin{tabular}{c|c} \n   \\hline\n    \\mbox{erf}(0) = 0         & $ \\mbox{erf}(\\infty) = 1 $  \\\\\n   \\mbox{erfc}(0) = 1        & $  \\mbox{erfc}(\\infty) = 0 $ \\\\\n   \\mbox{erf}(-x) = \\mbox{erf}(x)   &   \\mbox{erfc}(-x) = 2-\\mbox{erfc}(x) \\\\\n   \\hline\n   \\end{tabular}\n\\end{eqnarray}\n\n\\subsection*{N1-MSE}\nNow we compute the contribution of the wavelet coefficient $x$ to the noise information: \n\\begin{eqnarray}\nh_{n}(x) = \\frac{x^2}{2\\sigma^2}\\mbox{erfc}(\\frac{x}{\\sqrt{2}\\sigma})\n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{ d h_{n}(x)}{dx} = \\frac{x}{\\sigma^2}\\mbox{erfc}(\\frac{x}{\\sqrt{2}\\sigma}) + \\frac{x^2}{2\\sigma^2} \\frac{\\partial \\mbox{erfc}(\\frac{x}{\\sqrt{2}\\sigma})}{\\partial x} \n\\end{eqnarray}\nWe derive the function erfc:\n\\begin{eqnarray}\n\\frac{\\partial \\: \\mbox{erfc}(x)}{\\partial x} = - \\frac{2}{\\sqrt{\\pi}}   e^{-x^{2}} \n\\end{eqnarray}\nthen \n\\begin{eqnarray}\n\\frac{ d h_{n}(x)}{dx} = \\frac{x}{\\sigma^2}\\mbox{erfc}(\\frac{x}{\\sqrt{2}\\sigma})  -\\frac{x^2}{\\sqrt{2\\pi}\\sigma^3}e^{-\\frac{x^{2}}{2\\sigma^2}} \n\\end{eqnarray}\n\nIn order to minimize the functional~\\ref{eqn_func1}, we may want to calculate\nthe derivative of $h_s(x-y)$, $h_s(x-y)$ measuring the amount of information\ncontained in the residual ($y$ being the data).\n\\begin{eqnarray}\nh_s(x-y) = \\frac{(y-x)^2}{2\\sigma^2}\\mbox{erf}(\\frac{y-x}{\\sqrt{2}\\sigma}) \n\\end{eqnarray}\nDenoting $z = y - x$, we have\n\\begin{eqnarray}\nh_s(z) = \\frac{z^2}{2\\sigma^2}\\mbox{erf}(\\frac{z}{\\sqrt{2}\\sigma}) \n\\end{eqnarray}\n\\begin{eqnarray}\n\\frac{ d h_{s}(z)}{dz} & = & \\frac{z}{\\sigma^2}\\mbox{erf}(\\frac{z}{\\sqrt{2}\\sigma}) + \\frac{z^2}{2\\sigma^2} \\frac{\\partial \\mbox{erf}(\\frac{z}{\\sqrt{2}\\sigma})}{\\partial z}  \\\\\n                & = & \\frac{z}{\\sigma^2}\\mbox{erf}(\\frac{z}{\\sqrt{2}\\sigma}) + \\frac{z^2}{\\sqrt{2\\pi}\\sigma^3} e^{-\\frac{z^{2}}{2\\sigma^2}}\n\\end{eqnarray}\nand\n\\begin{eqnarray}\n\\frac{ d h_{s}(x-y)}{dx}  =  - \\frac{ d h_{s}(z)}{dz}\n\\end{eqnarray}\n\n\n\\subsection*{N2-MSE}\nWe compute the contribution of the wavelet coefficient $x$ to the noise information: \n\\begin{eqnarray}\nh_{n}(x) = \n\\frac{1}{\\sigma^{2}}\\int_{0}^{x} t \\: \\mbox{erfc}( \\frac{x-t}{\\sqrt{2}\\sigma}) dt \n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{d h_{n}(x)}{dx} &  = &  h_{n}(x+dx) - h_{n}(x)  \\\\\n   &  = & \\frac{1}{\\sigma^{2}} \\int_{0}^{x+dx} \n             \\mbox{erfc}(\\frac{x+dx-t}{\\sqrt{2}\\sigma}) dt -\n\\frac{1}{\\sigma^{2}}\\int_{0}^{x} \\mbox{erfc} (\\frac{x-t}{\\sqrt{2}\\sigma}) dt \n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{d h_{n}(x)}{dx} = \n\\frac{x}{\\sigma^{2}}  \\, \\mbox{erfc}( \\frac{x-x}{\\sqrt{2}\\sigma})  +\n\\frac{1}{\\sigma^{2}}\\int_{0}^{x} \n          \\frac{ \\partial \\: t \\, \\mbox{erfc} (\\frac{x-t}{\\sqrt{2}\\sigma})}{ \\partial x} dt \n\\end{eqnarray}\n\nNow, because erfc(0) = 1  we have:\n\\begin{eqnarray}\n\\frac{d H_{n}(x)}{dx} = \n\\frac{x}{\\sigma^{2}}   +\n\\frac{1}{\\sigma^{2}}\\int_{0}^{x} \n          \\frac{ \\partial \\: t \\, \\mbox{erfc} (\\frac{x-t}{\\sqrt{2}\\sigma})}{ \\partial x} dt \n\\end{eqnarray}\n\nWe derive the function erfc:\n\\begin{eqnarray}\n\\frac{\\partial \\: \\mbox{erfc}(x)}{\\partial x} = - \\frac{2}{\\sqrt{\\pi}}   e^{-x^{2}} \n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{ \\partial\\:  \\mbox{erfc}( \\frac{(x-t)}{\\sqrt{2}\\sigma} )}{\\partial x} = \n-\\frac{2}{\\sqrt{\\pi}} \\frac{1}{\\sqrt{2}\\sigma}  \n  e^{-\\frac{(x-t)^{2}}{2\\sigma^{2}}} =\n -\\sqrt{\\frac{2}{\\pi}} \\frac{1}{\\sigma} e^{-\\frac{(x-t)^{2}}{2\\sigma^{2}}}\n\\end{eqnarray}\n\nNow we deduce for the derivative of $h_n$:\n\n\\begin{eqnarray}\n\\frac{d h_{n}(x)}{dx} = \n\\frac{x}{\\sigma^{2}}   +\n\\frac{1}{\\sigma^{2}}\\int_{0}^{x} \n -\\sqrt{\\frac{2}{\\pi}}\\frac{1}{\\sigma}t \\, e^{-\\frac{(x-t)^{2}}{2\\sigma^{2}}}dt \n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{d h_{n}(x)}{dx} = \n\\frac{x}{\\sigma^{2}}   +\n\\frac{1}{\\sigma^{3}}\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{x} t \\, e^{-\\frac{(x-t)^{2}}{2\\sigma^{2}}}dt \n\\end{eqnarray}\n\nWe create the variable J\n\\begin{eqnarray}\nJ = \\int_{0}^{x} t \\, e^{-\\frac{(x-t)^{2}}{2\\sigma^{2}}}dt \n\\end{eqnarray}\n\nWe create the variable u\n\\begin{eqnarray}\n\\begin{array}{cc} \n  u = \\frac{t-x}{\\sqrt{2}\\sigma}  &  t = x+u \\, \\sqrt{2}\\sigma         \\\\\n   & dt = \\sqrt{2}\\sigma du         \\\\\n  t=0 \\Rightarrow u = \\frac{-x}{\\sqrt{2}\\sigma}  &\n  t=x \\Rightarrow u = 0                     \\\\\n   \\end{array}\n\\end{eqnarray}\n\n\nThe variable J can be written with u\n\\begin{eqnarray}\n J = \\int_{\\frac{-x}{\\sqrt{2}\\sigma} }^{0} (x+u \\,\\sqrt{2}\\sigma) e^{-u^{2}}\\sqrt{2}\\sigma du\n\\end{eqnarray}\n\\begin{eqnarray}\n J = \\sqrt{2}\\sigma x \\int_{\\frac{-x}{\\sqrt{2}\\sigma} }^{0} \n e^{-u^{2}} du  +\n 2 \\sigma^{2} \\int_{\\frac{-x}{\\sqrt{2}\\sigma} }^{0} u \\,\n e^{-u^{2}} du\n\\end{eqnarray}\n\nThe first part of J can be rewritten as:\n\\begin{eqnarray}\n J_{0} = \\sqrt{2}\\sigma x \\int_{0}^{\\frac{x}{\\sqrt{2}\\sigma} } \n e^{-u^{2}} du  \n\\end{eqnarray}\n$ J_{0} $ can be expressed with the error function.\n\\begin{eqnarray}\n J_{0} = \\sqrt{2}\\sigma \\frac{\\sqrt{\\pi}}{2} x  \\mbox{erf}(\\frac{x}{\\sqrt{2}\\sigma}) \n J_{0} = \\sigma \\sqrt{\\frac{\\pi}{2}} \\: x \\:  \\mbox{erf}(\\frac{x}{\\sqrt{2}\\sigma}) \n\\end{eqnarray}\nNow the second part of J is obvious\n\\begin{eqnarray}\n J_{1} = 2 \\sigma^{2} \\int_{\\frac{-x}{\\sqrt{2}\\sigma} }^{0} u \\,\n e^{-u^{2}} du  \n\\end{eqnarray}\n or\n\\begin{eqnarray}\n\\frac{d e^{-u^{2}}} {du} = -2 u e^{-u^{2}} \n\\end{eqnarray}\n\nWe replace\n\\begin{eqnarray}\n J_{1} = -\\sigma^{2}  \\int_{\\frac{-x}{\\sqrt{2}\\sigma} }^{0} d(e^{-u^{2}})  \n\\end{eqnarray}\n\\begin{eqnarray}\n J_{1} = \\sigma^{2}  [e^{-\\frac{x^{2}}{2\\sigma^{2}}} - 1]  \n\\end{eqnarray}\n\nNow we can write J\n\\begin{eqnarray}\n J = J_{0} + J_{1}\n  = \\sigma \\sqrt{\\frac{\\pi}{2}} \\: x \\:  \\mbox{erf}(\\frac{x}{\\sqrt{2}\\sigma}) \n    + \\sigma^{2}  [e^{-\\frac{x^{2}}{2\\sigma^{2}}} - 1 ]  \n\\end{eqnarray}\n\nNow we can write the derivative of $h_n$\n\\begin{eqnarray}\n\\frac{d h_{n}(x)}{dx} & = & \n\\frac{x}{\\sigma^{2}}   -\n\\frac{1}{\\sigma^{3}} \\sqrt{\\frac{2}{\\pi} } \\: J \\\\\n                   & = &   \\frac{x}{\\sigma^{2}} -\n  \\frac{x}{\\sigma^{2}}\\: x \\:  \\mbox{erf}(\\frac{x}{\\sqrt{2}\\sigma})\n  + \\frac{1}{\\sigma} \\sqrt{\\frac{2}{\\pi} } \\:\n      [1 - e^{-\\frac{x{2}}{2\\sigma{2}}}]  \\\\\n                    & = &  \\frac{x}{\\sigma^{2}}\\mbox{erfc}(\\frac{x}{\\sqrt{2}\\sigma})\n    + \\frac{1}{\\sigma} \\sqrt{\\frac{2}{\\pi} } \\:\n      [1 - e^{-\\frac{x^{2}}{2\\sigma^{2}}}] \n\\end{eqnarray}\n\nIn order to minimize the functional~\\ref{eqn_func1}, we may want to calculate\nthe derivative of $h_s(x \\mid y)$, $h_s(x \\mid \ny)$ measuring the amount of information\ncontained in the residual ($y$ being the data).\n\\begin{eqnarray}\nh_s(x \\mid y) = \\frac{1}{\\sigma^{2}} \\int_{0}^{y-x} t \\mbox{ erf}(\\frac{y-x-t}{\\sqrt{2}\\sigma}) dt\n\\end{eqnarray}\nDenoting $z = y - x$, we have\n\\begin{eqnarray}\nh_s(z) &  =  & \\frac{1}{\\sigma^{2}} \\int_{0}^{z} t \\mbox{ erf}(\\frac{z-t}{\\sqrt{2}\\sigma}) dt \\\\\n       &  =  & \\frac{1}{\\sigma^{2}} \\int_{0}^{z} t dt - \\frac{1}{\\sigma^{2}} \\int_{0}^{z} t \\mbox{ erfc}(\\frac{z-t}{\\sqrt{2}\\sigma}) dt\n\\end{eqnarray} \nand\n\\begin{eqnarray}\n\\frac{d h_s(x)}{dx} = \\frac{\\partial h_s(z)}{\\partial z} \\frac{\\partial z}{\\partial x}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\frac{\\partial h_s(z)}{\\partial z} & = \\frac{z}{\\sigma^2} - \\frac{\\partial h_n(z)}{\\partial z}\n \\end{eqnarray}\nthen\n\\begin{eqnarray}\n\\frac{d h_s(x)}{dx} & = & - \\frac{y-x}{\\sigma^2} + \\frac{y-x}{\\sigma^2}\\mbox{erfc}(\\frac{y-x}{\\sqrt{2}\\sigma}) + \\sqrt{\\frac{2}{\\pi}}\\frac{1}{\\sigma}[1 - e^{-\\frac{(y-x)^{2}}{2\\sigma^{2}}}] \\\\\n                    & = & - \\frac{y-x}{\\sigma^2} \\mbox{erf}(\\frac{y-x}{\\sqrt{2}\\sigma}) + \\sqrt{\\frac{2}{\\pi}}\\frac{1}{\\sigma}[1 - e^{-\\frac{(y-x)^{2}}{2\\sigma^{2}}}]\n\\end{eqnarray}\n", "meta": {"hexsha": "266235418de14986ff4012cff7ff81b095254d67", "size": 8048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/annex_deriv1.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/annex_deriv1.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/annex_deriv1.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": 36.2522522523, "max_line_length": 192, "alphanum_fraction": 0.5683399602, "num_tokens": 3532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6255628772334747}}
{"text": "\\subsubsection{Seasonal and Trend Decomposition using Loess}\n\\label{stl}\n\nA time series $y_t$ may exhibit different types of patterns; to fully capture\n    each of them, the series must be decomposed.\nThen, each component is forecast with a distinct model.\nMost commonly, the components are the trend $t_t$, seasonality $s_t$, and\n    remainder $r_t$.\nThey are themselves time series, where only $s_t$ exhibits a periodicity $k$.\nA decomposition may be additive (i.e., $y_t = s_t + t_t + r_t$) or\n    multiplicative (i.e., $y_t = s_t * t_t * r_t$); the former assumes that\n    the effect of the seasonal component is independent of the overall level\n    of $y_t$ and vice versa.\nThe seasonal component is centered around $0$ in both cases such that its\n    removal does not affect the level of $y_t$.\nOften, it is sufficient to only seasonally adjust the time series, and model\n    the trend and remainder together, for example, as $a_t = y_t - s_t$ in the\n    additive case.\n\nEarly approaches employed moving averages (cf., Sub-section \\ref{ets}) to\n    calculate a trend component, and, after removing that from $y_t$, averaged\n    all observations of the same seasonal lag to obtain the seasonal\n    component.\nThe downsides of this are the subjectivity in choosing the window lengths for\n    the moving average and the seasonal averaging, the incapability of the\n    seasonal component to vary its amplitude over time, and the missing\n    handling of outliers.\n\nThe X11 method developed at the U.S. Census Bureau and described in detail by\n    \\cite{dagum2016} overcomes these disadvantages.\nHowever, due to its background in economics, it is designed primarily for\n    quarterly or monthly data, and the change in amplitude over time cannot be\n    controlled.\nVariants of this method are the SEATS decomposition by the Bank of Spain and\n    the newer X13-SEATS-ARIMA method by the U.S. Census Bureau.\nTheir main advantages stem from the fact that the models calibrate themselves\n    according to statistical criteria without manual work for a statistician\n    and that the fitting process is robust to outliers.\n\n\\cite{cleveland1990} introduce a seasonal and trend decomposition using a\n    repeated locally weighted regression - the so-called Loess procedure - to\n    smoothen the trend and seasonal components, which can be viewed as a\n    generalization of the methods above and is denoted by the acronym STL.\nIn contrast to the X11, X13, and SEATS methods, the STL supports seasonalities\n    of any lag $k$ that must, however, be determined with additional\n    statistical tests or set with out-of-band knowledge by the forecaster\n    (e.g., hourly demand data implies $k = 24 * 7 = 168$ assuming customer\n    behavior differs on each day of the week).\nMoreover, the seasonal component's rate of change, represented by the $ns$\n    parameter and explained in detail with Figure \\ref{f:stl} in Section\n    \\ref{decomp}, must be set by the forecaster as well, while the trend's\n    smoothness may be controlled via setting a non-default window size.\nOutliers are handled by assignment to the remainder such that they do not\n    affect the trend and seasonal components.\nIn particular, the manual input needed to calibrate the STL explains why only\n    the X11, X13, and SEATS methods are widely used by practitioners.\nHowever, the widespread adoption of concepts like cross-validation (cf.,\n    Sub-section \\ref{cv}) in recent years enables the usage of an automated\n    grid search to optimize the parameters.\nThe STL's usage within a grid search is facilitated even further by its being\n    computationally cheaper than the other methods discussed.\n", "meta": {"hexsha": "f832f0e802bdf67b7620d49779e49504baa21cff", "size": 3658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/2_class/4_stl.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/2_class/4_stl.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/2_class/4_stl.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": 59.0, "max_line_length": 78, "alphanum_fraction": 0.7635319847, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6255628757928976}}
{"text": "\\documentclass[a4paper]{article}\n\n% Language and Font Encoding\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{listings}\n\\usepackage{float}\n\\usepackage{caption}         % For captions\n\\usepackage{fancyhdr}        % For header and footer\n\\usepackage{rotating}\n\\usepackage{amssymb}\n\\usepackage{varwidth}\n\n\n% Page size and margins\n\\usepackage[a4paper,top=3cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1.75cm]{geometry}\n\n% Useful Packages\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{tikz}\n\\usetikzlibrary{automata, positioning}\n\\usepackage{amsthm}\n\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\softmax}{softmax}\n\n\\newcommand{\\squeezeup}{\\vspace{-2.5mm}}\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\usepackage[colorinlistoftodos]{todonotes}\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\n\\pagestyle{fancy}\n\\lhead{Linear Algebra Notes}\n\\rhead{}\n\n\\begin{document}\n\n\\title{Linear Algebra: Vector Spaces, Subspaces, and Linear Maps}\n\\author{Ibrahim Akbar\\\\}\n\\maketitle\n\n%--------------------------------------------------------------------------------------------------------Vector Space--------------------------------------------------------------------------------------------------------------------\n\\section{Vector Space}\n\\textbf{Definition:} A collection, $\\mathcal{V}$, is known as a vector (linear) space over the field $\\mathbb{F}$ if it is equipped with the operations $+:\\mathcal{V}\\times\\mathcal{V} \\rightarrow \\mathcal{V}$ and $\\cdot:\\mathbb{F}\\times\\mathcal{V}\\rightarrow\\mathcal{V}$ such that the following properties hold.\\\\\n\n\\begin{itemize}\n\\item Closure under Vector Addition:  $\\mathbf{u + v} \\in \\mathcal{V} \\quad \\forall \\mathbf{u,v} \\in \\mathcal{V}$\n\\item Closure under Scalar Multiplication:  $\\alpha \\mathbf{v} \\in \\mathcal{V}  \\quad \\forall \\mathbf{v} \\in \\mathcal{V}, \\alpha \\in \\mathbb{F}$\n\\item $(\\alpha + \\beta)\\mathbf{v} = \\alpha \\mathbf{v} + \\beta \\mathbf{v}$\n\\item $\\alpha(\\beta\\mathbf{v}) = (\\alpha\\beta)\\mathbf{v}$\n\\item $\\alpha(\\mathbf{u + v}) = \\alpha\\mathbf{u} + \\alpha\\mathbf{v} $\n\\item $\\exists \\{\\mathbf{0}\\} \\hspace{2mm} \\textnormal{s.t.} \\hspace{2mm} \\mathbf{v} +\\{\\mathbf{0}\\} = \\mathbf{v} \\quad \\forall\\mathbf{v}\\in\\mathcal{V}$\n\\item For each $\\mathbf{v}\\in\\mathcal{V}\\quad\\exists \\mathbf{(-v)}\\hspace{2mm} \\textnormal{s.t.} \\hspace{2mm} \\mathbf{v} +\\mathbf{(-v)} = \\{\\mathbf{0}\\}$\n\\item $1\\in\\mathbb{F},\\mathbf{v}\\in\\mathcal{V} \\Rightarrow \\mathbf{1v} = \\mathbf{v}$\n\\end{itemize}\n\n\\subsection{Examples}\nSome examples of vector spaces are: $\\mathbb{R}^{n}, \\mathbb{C}^{n}$\n\n%----------------------------------------------------------------------------------------------------------Sub Space --------------------------------------------------------------------------------------------------------------------\n\\section{Subspace}\n\\textbf{Definition:} A subspace, $\\mathcal{U}$ of a vector space, $\\mathcal{V}$, over the field, $\\mathbb{F}$, is a non-empty set such that,\n\n\\begin{itemize}\n\\item $\\mathbf{u,v}\\in\\mathcal{W}\\Rightarrow\\mathbf{u+v}\\in\\mathcal{W}$\n\\item $\\mathbf{v}\\in\\mathcal{W}\\Rightarrow\\alpha\\mathbf{w}\\in\\mathcal{W},\\forall\\alpha\\in\\mathbb{F}$\n\\item $\\exists \\{\\mathbf{0}\\} \\hspace{2mm} \\textnormal{s.t.} \\hspace{2mm} \\mathbf{w} +\\{\\mathbf{0}\\} = \\mathbf{w} \\quad \\forall\\mathbf{w}\\in\\mathcal{W}$\n\\end{itemize}\n\n\\subsection{Examples}\nSome examples of subspaces are:\n\n$$\nV := \\{x\\in\\mathbb{R}^{n}\\mid x^{2} \\geq 4x\\}\n$$\n\nNote that $V' := \\{x\\in\\mathbb{R}^{n}\\mid x^{2} > 4x\\}$ would not be a subspace nor would any polynomial that does not equal zero. Why?\\\\\nIn general, all spaces in $\\mathbb{R}^{n}$ that are defined by a homogeneous system of linear equations adhere to these properties. For a visual/geometric representation it is a point, line, plane, hyper-plane that goes through the origin $\\{\\mathbf{0}\\}$.\n\n%----------------------------------------------------------------------------------------------------Linear Independence-----------------------------------------------------------------------------------------------------------------\n\\section{Linearly Independent}\n\\textbf{Definition:} A set of vectors $\\{\\mathbf{x}_{1},\\mathbf{x}_{2},\\ldots,\\mathbf{x}_{n}\\}$ is said to be linearly independent if:\n$$\n\\sum_{i = 1}^{n}\\alpha_{i}\\mathbf{x}_{i} = 0 \\iff \\alpha_{i} = 0 \\hspace{2mm} \\forall i\n$$\n\nThe vectors cannot be written as a linear combination of each other and thus cannot describe each other. Therefore it is the same as saying there is no redundant information in the vectors.\n\n\\subsection{Example}\nLet $\\mathcal{S} = \\Bigg\\{\\begin{bmatrix}2\\\\1\\\\-1\\\\\\end{bmatrix},\\begin{bmatrix}3\\\\2\\\\-1\\\\\\end{bmatrix},\\begin{bmatrix}-4\\\\-2\\\\1\\\\\\end{bmatrix}\\Bigg\\}$, then we see that $-2v_{1} + 0v_{2} = v_{3}$ and therefore $\\mathcal{S}$ is not a linearly independent set.\\\\\n\n%------------------------------------------------------------------------------------------------------------Span------------------------------------------------------------------------------------------------------------------------\n\\section{Span}\n\\textbf{Definition:} The span of a set of vectors $\\mathcal{S} = \\{\\mathbf{x}_{1}, \\mathbf{x}_{2}, \\ldots, \\mathbf{x}_{n}\\}$ is the set of vectors, $\\mathcal{V}$, that is described by all possible linear combinations of $\\mathcal{S}$.\n$$\nV := span(\\mathcal{S}) = \\{y \\mid y=\\sum_{i = 1}^{n}\\alpha_{i}x_{i}\\hspace{2mm}\\forall\\alpha_{i}\\in\\mathbb{F}\\}\n$$ \n\n\\subsection{Examples}\nGiven the vector $v = \\begin{bmatrix}1\\\\0\\\\\\end{bmatrix}$ over the field of all reals it would span the space \n$$\n\\mathcal{S} = \\bigg\\{\\begin{bmatrix}\\alpha\\\\0\\\\\\end{bmatrix}\\mid \\alpha\\in\\mathbb{R}\\bigg\\}\n$$\nLets also consider $u = \\begin{bmatrix}0\\\\1\\\\\\end{bmatrix}$ in the same field. Together these would span\n$$\n\\mathcal{T} = \\bigg\\{\\begin{bmatrix}\\alpha\\\\\\beta\\\\\\end{bmatrix}\\mid\\alpha,\\beta\\in\\mathbb{R}\\bigg\\} = \\mathbb{R}^{2}\n$$\n\n%------------------------------------------------------------------------------------------------------------Basis-----------------------------------------------------------------------------------------------------------------------\n\\section{Basis}\n\\textbf{Definition:} A basis for a vector space, $\\mathcal{V}$, is a set of vectors, $\\mathcal{T}$, such that it is the maximal linear independent set and minimal spanning set of $\\mathcal{V}$.\n\n% Existence of a Basis and Uniqueness of a Basis\nIs a basis for a space unique?\\\\\nLet their be two bas\nDoes a basis for a space exist?\\\\\n\\subsection{Examples}\nA basis for $\\mathbb{R}^{2}$ is $\\begin{bmatrix} 0 & 1\\\\ 1 & 0\\\\ \\end{bmatrix}$.\\\\\n\nWe need to show that the set of vectors are linearly independent and span the space of $\\mathbb{R}^{2}$.\n$$\n\\alpha_{1}v_{1} + \\alpha_{2}v_{2} = 0 \\iff \\alpha_{i} = 0\\hspace{2mm}i = \\{1,2\\}\n$$\n$$\n\\alpha_{1}\\begin{bmatrix}0\\\\1\\\\\\end{bmatrix} + \\alpha_{2}\\begin{bmatrix}1\\\\0\\\\\\end{bmatrix} = 0\n$$\n$$\n\\Rightarrow\n\\begin{bmatrix}0\\\\\\alpha_{1}\\end{bmatrix} + \\begin{bmatrix}\\alpha_{2}\\\\0\\\\\\end{bmatrix} = 0 \n$$\n$$\n\\Rightarrow\n\\begin{bmatrix}\\alpha_{2}\\\\\\alpha_{1}\\\\\\end{bmatrix} = 0 \\Rightarrow \\alpha_{1} = \\alpha_{2} = 0\n$$\n\nTo see that it spans $\\mathbb{R}^{2}$ can be observed from the previous section.\\\\\n%----------------------------------------------------------------------------------------------------------Linear Maps-------------------------------------------------------------------------------------------------------------------\n\\section{Linear Maps}\n\\textbf{Definition:} Given vector spaces, $\\mathcal{U,V}$ over the field $\\mathbb{F}$ a linear map, $T: \\mathcal{U}\\rightarrow\\mathcal{V}$ is a transformation that preserves additivity and homogeneity.\n\n\\begin{itemize}\n\\item $T(\\mathbf{u + w}) = T(\\mathbf{u}) + T(\\mathbf{w})\\hspace{2mm} \\forall\\mathbf{u,w}\\in\\mathcal{U}$\n\\item $T(\\alpha\\mathbf{u}) = \\alpha T(\\mathbf{u})$\n\\end{itemize}\n\n\\subsection{Examples}\n\\begin{itemize}\n\\item $T(x): x\\rightarrow x^{2}$ is not linear.\n\\item $T(x): x\\rightarrow 0$ is linear.\n\\end{itemize}\n\nIf $\\mathcal{U,V}$ are finite dimensional and a basis exists for them, the linear maps can be defined as matrices.\n\n\\subsection{Range}\n\\textbf{Definition:} Let $T: \\mathcal{V}\\rightarrow\\mathcal{U}$ be a linear map and denote the Range(Image) of $T$ as,\n$$\n\\mathcal{R}(T) = \\{\\mathbf{u}\\mid T(v) = u,\\hspace{2mm} \\mathbf{u}\\in\\mathcal{U},\\hspace{1mm}\\mathbf{v}\\in\\mathcal{V}\\}\n$$\n\n%-Is the range space unique? Does the range space exist?\n\n\\subsection{Nullspace}\n\\textbf{Definition:} Let $T: \\mathcal{V}\\rightarrow\\mathcal{U}$ be a linear map, then denote the Nullspace of $T$ as,\n$$\n\\mathcal{N}(T) = \\{\\mathbf{v}\\mid T(v) = 0,\\hspace{2mm}\\mathbf{u}\\in\\mathcal{U}\\}\n$$\n\n% Is the nullspace unique?\n\n\\end{document}\n\n\n\n\n\n\n\n", "meta": {"hexsha": "2d552408b3bae4141e30155cf98fc8b4401549a8", "size": 8729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/notes/tex/lin-alg-space-maps.tex", "max_stars_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_stars_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_stars_repo_licenses": ["MIT"], "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/notes/tex/lin-alg-space-maps.tex", "max_issues_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_issues_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_issues_repo_licenses": ["MIT"], "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/notes/tex/lin-alg-space-maps.tex", "max_forks_repo_name": "ibrahimkakbar/ibrahimkakbar.github.io", "max_forks_repo_head_hexsha": "5e6b0ea67f5e5f8f3a7bb4394095ea7f7992673a", "max_forks_repo_licenses": ["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.9615384615, "max_line_length": 313, "alphanum_fraction": 0.5844884867, "num_tokens": 2693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.6254351865425044}}
{"text": "\\subsection{Higgs mechanism and Electroweak symmetry breaking}\n\\label{symbreaking}\n\nAs shown in previous subsection, the Lagrangian $L_{gauge}$ does not involve any mass term due to the requirement of gauge invariance.\nSo all the W and B bosons should be massless. But experimental observations show that the gauge bosons are massive.\nTherefore, the gauge invariance must be broken spontaneously.\nThe Higgs field is introduced to break the $SU(2)_{L} \\times U(1)_{Y}$ symmetry and\ngauge bosons and fermions can interact with Higgs filed to acquire their masses.\nAnd this specific process is named \\textit{Higgs mechanism} in SM.\n\nThe Higgs field $\\phi$ is a doublet and can be written in a Hermitian basis as\n\\begin{equation}\n\t\\phi = \\binom{\\phi^{+}}{\\phi^{0}} = \\frac{1}{\\sqrt{2}} \\binom{\\phi_{1} - i\\phi_{2}}{\\phi_{3} - i\\phi_{4}}\n\\end{equation}\nwhere $\\phi_{i} = \\phi_{i}^{+}$ stand for four Hermitian field. \nIn this new basis, the Higgs potential in Eq.~\\ref{eq:Vhiggs} can be expressed as:\n\\begin{equation}\n\tV(\\phi) = \\frac{1}{2}\\mu^{2}\\left(\\sum_{i=1}^{4}\\phi_{i}^{2}\\right) + \\frac{1}{4}\\lambda\\left(\\sum_{i=1}^{4}\\phi_{i}^{2}\\right)^{2}\n\\end{equation}\nTo simplify the situation, the axis in this four-dimensional space can be chosen to satisfied\n~$\\left<0\\left| \\phi_{i} \\right|0\\right> = 0$ for $i = 1, 2, 4$, and $<0\\left| \\phi_{3} \\right|0> = v$. Thus,\n\\begin{equation}\n\tV(\\phi) \\rightarrow V(v) = \\frac{1}{2}\\mu^{2}v^{2} + \\frac{1}{4}\\lambda v^{4}\n\\end{equation}\nThe minimization of this potential depends on the sign of $\\mu^{2}$ as shown in figure~\\ref{fig:C2_Higgs_potential}.\nWhen $\\mu^{2} > 0$ the minimum occurs at $v = 0$, namely the vacuum is empty space and $SU(2)_{L} \\times U(1)_{Y}$ symmetry is unbroken.\nIn the case of $\\mu^{2} < 0$, the $v = 0$ symmetric point is no longer stable and the minimum occurs at nonzero value of \n$v = \\left( -\\mu^{2}/\\lambda\\right)^{1/2}$ which breaks the $SU(2)_{L} \\times U(1)_{Y}$ symmetry.\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.7\\textwidth]{figures/Theory/Vhiggs.png}\n  \\caption{The Higgs potential $V(\\phi)$ with $\\mu^{2}>0$ (left) and $\\mu^{2}<0$ (right).}\n  \\label{fig:C2_Higgs_potential}\n\\end{figure}\nThus, the classical vacuum $\\phi_{0}$ of Higgs doublet can be expressed by\n\\begin{equation}\n\t\\phi_{0} = \\frac{1}{\\sqrt{2}}\\binom{0}{v}\n\\end{equation}\nAnd to quantize around the classical vacuum in a general form:\n\\begin{equation}\n\t\\phi = \\frac{1}{\\sqrt{2}} \\binom{0}{v+H}\n\\end{equation}\nWhere H is a Hermitian field for physical Higgs scalar.\nIn this gauge, the Lagrangian $L_{Higgs}$ in Eq.~\\ref{eq:Lhiggs} takes a simple form\n\\begin{equation}\n\\begin{split} \\label{eq:Lhiggs2}\n\tL_{Higgs} & = \\left(D^{\\mu}\\phi\\right)^{\\dagger}D_{\\mu}\\phi - V(\\phi) \\\\\n\t& = M_{W}^{2}W^{\\mu+}W_{\\mu}^{-}\\left(1+\\frac{H}{\\nu}\\right)^{2} + \\frac{1}{2}M_{Z}^{2}Z^{\\mu}Z_{\\mu}\\left(1+\\frac{H}{\\nu}\\right)^{2} \\\\ \n        &   + \\frac{1}{2}\\left(\\partial_{\\mu}H\\right)^{2} - V(\\phi)\n\\end{split}\n\\end{equation}\nwhere the W and Z fields are\n\\begin{equation}\n\\begin{split}\n\t& W^{\\pm} = \\frac{1}{\\sqrt{2}} \\left(W^{1} \\mp iW^{2}\\right) \\\\\n\t& Z = - sin\\theta_{W}B + cos\\theta_{W}W^{3}\n\\end{split}\n\\end{equation}\nTherefore, in Eq.~\\ref{eq:Lhiggs2} spontaneous symmetry breaking brings out masses for the W and Z gauge bosons\n\\begin{equation}\n\\begin{split}\n\t& M_{W} = \\frac{gv}{2} \\\\\n\t& M_{Z} = \\sqrt{g^{2} + g'^{2}} \\frac{v}{2} = \\frac{M_{W}}{cos\\theta_{W}}\n\\end{split}\n\\end{equation}\nwhere $\\theta_{W}$ is the weak angle defined as\n\\begin{equation}\n\tsin\\theta_{W} = \\frac{g'}{\\sqrt{g^{2} + g'^{2}}} \\qquad cos\\theta_{W} = \\frac{g}{\\sqrt{g^{2} + g'^{2}}} \\qquad tan\\theta_{W} = \\frac{g'}{g}\n\\end{equation}\nThen another gauge boson photon remains massless with the field of\n\\begin{equation}\n\tA = cos\\theta_{W}B + sin\\theta_{W}W^{3}\n\\end{equation}\n\nAfter the symmetry breaking, the Higgs potential in unitary gauge can be written into\n\\begin{equation}\n\tV(\\phi) = -\\frac{\\mu^{4}}{4\\lambda} - \\mu^{4}H^{2} + \\lambda\\nu H^{3} + \\frac{\\lambda}{4}H^{4}\n\\end{equation}\nThe first term in $V$ is a constant, while the second term denotes a (tree-level) mass of Higgs boson\n\\begin{equation}\n\tM_{H} = \\sqrt{-2\\mu^{2}} = \\sqrt{2\\lambda}v\n\\end{equation}\nDue to the unknown of quartic Higgs coupling $\\lambda$, the Higgs mass is not predicted.\nThe third and fourth terms in the Higgs potential $V$ denote the induced cubic and quartic interactions of the Higgs scalar.\n\nThrough the Higgs mechanism, fermions can also acquire their masses.\nIn the unitary gauge, Yukawa Lagrangian ($L_{Yukawa}$) can be written as a simple form of \\cite{Pich:2015lkh}\n\\begin{equation}\n\tL_{Yukawa} = -\\left(1+\\frac{H}{v}\\right) \\left(m_{d}\\bar{d}d + m_{u}\\bar{u}u + m_{l}\\bar{l}l\\right)\n\\end{equation}\nin which $m_{f} = \\frac{y_{f}v}{\\sqrt{2}}$ for $f = d, u, l$.\n", "meta": {"hexsha": "ace8bfd9e508de454629b7f0acac19da44da7a23", "size": 4787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Theory/symbreaking.tex", "max_stars_repo_name": "zhuhel/PhDthesis", "max_stars_repo_head_hexsha": "55ec32affb5c105143798989d78043467c88da8e", "max_stars_repo_licenses": ["LPPL-1.3c"], "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/Theory/symbreaking.tex", "max_issues_repo_name": "zhuhel/PhDthesis", "max_issues_repo_head_hexsha": "55ec32affb5c105143798989d78043467c88da8e", "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": "chapters/Theory/symbreaking.tex", "max_forks_repo_name": "zhuhel/PhDthesis", "max_forks_repo_head_hexsha": "55ec32affb5c105143798989d78043467c88da8e", "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": 52.0326086957, "max_line_length": 140, "alphanum_fraction": 0.6747440986, "num_tokens": 1761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6254351774473752}}
{"text": "\\subsection{Convex functions}\\label{subsec:convex_functions}\n\nLet \\( X \\) be a Hausdorff \\hyperref[def:topological_vector_space]{topological vector space} and \\( D \\) be a \\hyperref[def:convex_set]{convex} subset of \\( X \\).\n\n\\begin{definition}\\label{def:convex_functions}\n  A function \\( f: D \\to \\BbbR \\) is called \\term{convex} if any of the following equivalent conditions hold:\n\n  \\begin{thmenum}\n    \\thmitem{def:convex_functions/ineq} For any two points \\( x, y \\in D \\) and any \\( t \\in [0, 1] \\) we have\n    \\begin{equation*}\n      f(tx + (1-t)y) \\leq tf(x) + (1-t)f(y).\n    \\end{equation*}\n\n    \\thmitem{def:convex_functions/epi} The \\hyperref[def:epigraph]{epigraph}\n    \\begin{equation*}\n      \\epi f \\coloneqq \\{ (x, a) \\in X \\times \\BbbR \\colon f(x) \\leq a \\}\n    \\end{equation*}\n    is convex.\n  \\end{thmenum}\n\n  If \\( -g \\) is convex for some function \\( g: D \\to \\BbbR \\), we call \\( g \\) \\term{concave}.\n\n  Note that definitions do not require any topological structure on \\( X \\). Most of their properties, however, require a topology.\n\\end{definition}\n\\begin{proof}\n  Let \\( x, y \\in D \\) and let \\( t \\in [0, 1] \\).\n\n  \\ImplicationSubProof{def:convex_functions/ineq}{def:convex_functions/epi} Let \\( \\epi f \\) be a convex set. Obviously \\( (x, f(x)) \\in D \\) and \\( (y, f(y)) \\in D \\). By the convexity of \\( \\epi f \\), we have\n  \\begin{equation*}\n    f(tx + (1-t)y) \\leq tf(x) + (1-t)f(y).\n  \\end{equation*}\n\n  Thus, \\( f \\) is a convex function.\n\n  \\ImplicationSubProof{def:convex_functions/epi}{def:convex_functions/ineq} Let \\( f \\) be convex. Let \\( a \\geq f(x) \\) and \\( b \\geq f(y) \\), so that \\( (x, a) \\in \\epi f \\) and \\( (y, b) \\in \\epi f \\). Hence,\n  \\begin{equation*}\n    f(tx + (1-t)y) \\leq tf(x) + (1-t)f(y) \\leq ta + (1-t)b,\n  \\end{equation*}\n  which implies that\n  \\begin{equation*}\n    (tx + (1-t)y, ta + (1-t)b) \\in \\epi f.\n  \\end{equation*}\n\n  Thus, \\( \\epi f \\) is a convex set.\n\\end{proof}\n\n\\begin{definition}\\label{def:affine_functions_concave_and_convex}\n  \\hyperref[def:affine_operator]{Affine functions} \\( f: X \\to \\BbbR \\) are simultaneously convex and concave.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:convex_subdifferential_is_convex_and_weak*_closed}\\mcite[exer. 1.10]{Phelps1993}\n  For any convex function \\( f \\) and any \\( x \\in D \\), the set \\( \\partial f(x) \\) is convex and weak* closed.\n\\end{proposition}\n\\begin{proof}\n  Fix \\( x \\in D \\). If \\( \\partial f(x) \\) is empty, then the theorem is trivially true.\n\n  Suppose it is nonempty and \\( y^*, z^* \\in \\partial f(x) \\). For any \\( x \\in D \\) we then have\n  \\begin{balign*}\n     & \\inprod{y^*} {x - x} \\leq f(x) - f(x), \\\\\n     & \\inprod{z^*} {x - x} \\leq f(x) - f(x).\n  \\end{balign*}\n\n  Fix \\( t \\in [0, 1] \\) and \\( x \\in D \\). It follows that\n  \\begin{balign*}\n    \\inprod{t y^* + (1-t) z^*} {x - x}\n     & =\n    t \\inprod{y^*} {x - x} + (1-t) \\inprod{z^*} {x - x}\n    \\leq \\\\ &\\leq\n    t [f(x) - f(x)] + (1-t) [f(x) - f(x)]\n    =    \\\\ &=\n    f(x) - f(x),\n  \\end{balign*}\n  thus \\( t y^* + (1-t)z^* \\in \\partial f(x) \\) and hence \\( \\partial f(x) \\) is convex.\n\n  To prove weak*-closedness, we consider the decomposition\n  \\begin{balign*}\n    \\partial f(x)\n     & =\n    \\{ x^* \\in E^* \\colon \\forall x \\in D, \\inprod {x^*} {x - x} \\leq f(x) - f(x) \\}\n    =    \\\\ &=\n    \\bigcap_{x \\in D} \\{ x^* \\in E^* \\colon \\inprod {x^*} {x - x} \\leq f(x) - f(x) \\}\n    =    \\\\ &=\n    \\bigcap_{x \\in D} L(x)^{-1} (-\\infty, f(x) - f(x)],\n  \\end{balign*}\n  where\n  \\begin{balign*}\n     & L: E \\to E^{**}                  \\\\\n     & L(x)(x^*) = \\inprod {x^*} {x - x}.\n  \\end{balign*}\n\n  For each \\( x \\in E \\), the functionals \\( L(x) \\) are weak*-to-weak continuous because the image \\( L(E) \\subseteq E^{**} \\) is isometrically isomorphic to a translation of \\( E \\). Hence, the preimage \\( L(x)^{-1} (-\\infty, f(x) - f(x)] \\) is closed and \\( \\partial f(x) \\) is weak*-closed as the intersection of weak*-closed sets.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:convex_difference_quotient_grows}\n  For every point \\( x \\in X \\) and every direction \\( h \\in S_X \\) the difference quotient is a monotone function of \\( t > 0 \\), i.e. for \\( 0 < s < t \\)\n  \\begin{balign*}\n    \\frac {f(x + sh) - f(x)} s\n    \\leq\n    \\frac {f(x + th) - f(x)} t\n  \\end{balign*}\n\\end{lemma}\n\\begin{proof}\n  \\begin{balign*}\n    \\frac {f(x + sh) - f(x)} s\n    =\n    \\frac t s \\frac {f(x + \\frac s t t h) - f(x)} t\n    =\n    \\frac t s \\frac {f\\left(\\frac s t (x + th) + (1 - \\frac s t) x \\right) - f(x)} t\n    \\leq \\\\ \\leq\n    \\frac t s \\frac {\\frac s t f(x + t h) + (1 - \\frac s t) f(x) - f(x)} t\n    =\n    \\frac t s \\frac s t \\frac {f(x + th) - f(x)} t\n    =\n    \\frac {f(x + th) - f(x)} t\n  \\end{balign*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:convex_one_sided_derivatives_exist}\n  For every point \\( x \\in X \\) and every direction \\( h \\in S_X \\) the one-sided derivative \\( f_+'(x)(h) \\) exists.\n\\end{proposition}\n\\begin{proof}\n  We use the convexity of \\( f \\) to obtain\n  \\begin{balign*}\n    f(x) = f \\left(x + \\frac {th} 2 - \\frac {th} 2 \\right) \\leq \\frac {f(x + th) + f(x - th)} 2,\n    \\\\\n    0 \\leq [f(x - th) - f(x)] + [f(x + th) - f(x)],\n    \\\\\n    -[f(x - th) - f(x)] \\leq [f(x + th) - f(x)],\n    \\\\\n    -\\frac {f(x + t(-h)) - f(x)} t \\leq \\frac {f(x + th) - f(x)} t,\n  \\end{balign*}\n  thus the difference quotient in \\( f_+'(x)(h) \\) is bounded below by the difference quotient for \\( -f_+'(x)(-h) \\).\n\n  \\Fullref{thm:convex_difference_quotient_grows} implies that the right difference quotient is non-increasing, thus both limits exist and\n  \\begin{equation*}\n    -f_+'(x)(-h) \\leq f_+'(x)(h).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:convex_one_sided_derivatives_sublinear}\n  For every point \\( x \\in X \\) and every direction \\( h \\in S_X \\) the one-sided derivative \\( f_+'(x)(h) \\) is a \\hyperref[def:sublinear_functional]{sublinear functional}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{def:sublinear_functional/subadditivity} It follows directly from\n  \\begin{balign*}\n    \\frac {f(x + t(a + b)) - f(x)} t\n     & =\n    \\frac {f(\\tfrac 1 2 (x + 2ta) + \\tfrac 1 2 (x + 2tb)) - f(x)} t\n    \\leq \\\\ &\\leq\n    \\frac {\\tfrac 1 2 f(x + 2ta) + \\tfrac 1 2 f(x + 2tb) - f(x)} t\n    =    \\\\ &=\n    \\frac {f(x + 2ta) - f(x)} {2t} + \\frac {f(x + 2tb) - f(x)} {2t}.\n  \\end{balign*}\n\n  \\SubProofOf{def:sublinear_functional/positive_homogeneity} For \\( \\lambda > 0 \\) the equality \\( f_+'(x)(\\lambda h) = \\lambda f_+'(x)(h) \\) follows from\n  \\begin{balign*}\n    \\frac {f(x + t \\lambda h) - f(x)} t\n    =\n    \\lambda \\frac {f(x + t \\lambda h) - f(x)} {t \\lambda}\n  \\end{balign*}\n\\end{proof}\n\n\\begin{corollary}\\label{thm:convex_one_sided_derivative_negative_inequality}\n  \\begin{equation*}\n    -f_+'(x)(-h) \\leq f_+'(x)(h)\n  \\end{equation*}\n\\end{corollary}\n\\begin{proof}\n  \\begin{equation*}\n    0 = f_+'(x)(h + (-h)) \\leq f_+'(x)(h) + f_+'(x)(-h)\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:convex_iff_subdifferential_nonempty}\n  The continuous function \\( f: D \\to X \\) is convex if and only if its subdifferential \\( \\partial f(x) \\) (see \\fullref{def:subdifferentials/convex}) is nonempty for every \\( x \\) in \\( D \\).\n\\end{proposition}\n\\begin{proof}\n  \\todo{Prove}.\n\\end{proof}\n\n\\begin{proposition}\n  \\label{thm:convex_one_sided_derivative_is_max}\n  For every direction \\( h \\in S_X \\), we have that\n  \\begin{equation*}\n    f_+'(x)(h) = \\max\\{ \\inprod {x^*} h \\colon x^* \\in \\partial f(x) \\}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{theorem}\\label{thm:singleton_subdifferential_implies_gateaux}\n  If \\( f \\) is continuous and if the subdifferential \\( \\partial f(x) \\) at \\( x \\in X \\) is a singleton with element \\( x^* \\), then \\( f \\) is Gateaux differentiable at \\( x \\) and \\( f_G'(x) = x^* \\).\n\\end{theorem}\n\\begin{proof}\n  Let \\( h \\in S_X \\) be arbitrary. \\Fullref{thm:convex_one_sided_derivatives_exist} implies that the one-sided derivatives \\( f_+'(x)(-h) \\) and \\( f_+'(x)(h) \\) exist and\n  \\begin{equation*}\n    -f_+'(x)(-h) \\leq f_+'(x)(h).\n  \\end{equation*}\n\n  Assume that \\( f \\) is not Gateaux differentiable at \\( x \\), i.e. for some \\( h_0 \\in X \\), we have a strict inequality. Then by \\fullref{thm:convex_one_sided_derivative_is_max}\n  \\begin{balign*}\n    \\min\\{ \\inprod {x^*} {h_0} \\colon x^* \\in \\partial f(x) \\}\n    =\n    -\\max\\{ \\inprod {x^*} {-h_0} \\colon x^* \\in \\partial f(x) \\}\n    =\n    -f_+'(x)(-h_0)\n    < \\\\ <\n    f_+'(x)(h_0)\n    =\n    \\max\\{ \\inprod {x^*} {h_0} \\colon x^* \\in \\partial f(x) \\},\n  \\end{balign*}\n  which implies that there is more that one functional \\( x^* \\in \\partial_C f(x) \\). This contradicts the assumption of the theorem.\n\n  Thus, \\( f \\) is Gateaux differentiable at \\( x \\).\n\\end{proof}\n\n\\begin{theorem}\\label{thm:rn_continuous_convex_partial_derivatives_imply_gateaux}\\mcite[exer. 1.15(b]{Phelps1993})\n  In \\( \\BbbR^n \\), the existence of the partial derivatives at \\( x \\) for a continuous convex function \\( f: D \\to \\BbbR \\) at a point \\( x \\in D \\) implies Gateaux differentiability.\n\\end{theorem}\n\\begin{proof}\n  Let \\( D \\subseteq \\BbbR^n \\) be an open and convex set and let \\( f: D \\to \\BbbR \\) be continuous and convex. Then \\( f_+'(x) \\) exists everywhere by \\fullref{thm:convex_one_sided_derivatives_exist} and is a subdifferential functional by \\fullref{thm:convex_one_sided_derivatives_sublinear}.\n\n  Let \\( e_1, \\ldots, e_n \\) be the canonical basis for \\( \\BbbR^n \\).\n\n  The partial derivatives\n  \\begin{balign*}\n    \\frac {\\partial f} {\\partial x_i} (x)\n    \\coloneqq\n    \\lim_{t \\to 0} \\frac {f(x + t e_i) - f(x)} t\n    =\n    f_+'(x)(e_i)\n  \\end{balign*}\n  exist, hence the projections of \\( f_+'(x) \\) along the coordinate exes are linear.\n\n  Define line linear functional\n  \\begin{equation*}\n    l(h) \\coloneqq \\sum_{i=1}^n h_i \\inprod{\\frac {\\partial f} {\\partial x_i} (x)} h,\n  \\end{equation*}\n  where \\( h_1, \\ldots, h_n \\) are the coordinates of \\( h \\) along \\( e_1, \\ldots, e_n \\).\n\n  We will show that \\( l \\cong f_+' \\). Fix \\( h \\in S_X \\). We have\n  \\begin{balign}\\label{thm:rn_continuous_convex_partial_derivatives_imply_gateaux/diff_dominated}\n    f_+'(x)(h)\n     & =\n    f_+'(x)\\left(\\sum_{i=1}^n h_i e_i \\right)\n    \\reloset {\\text{sublinearity}} \\leq \\nonumber      \\\\ &\\leq\n    \\sum_{i=1}^n f_+'(x)(h_i e_i)\n    \\reloset {\\text{linearity along } e_i} = \\nonumber \\\\ &=\n    \\sum_{i=1}^n h_i f_+'(x)(e_i)\n    =\n    \\sum_{i=1}^n h_i \\inprod{\\frac {\\partial f} {\\partial x_i} (x)} h.\n  \\end{balign}\n\n  Thus,\n  \\begin{balign*}\n    \\inprod l h\n    =\n    -\\inprod l {-h}\n    \\reloset {\\ref{thm:rn_continuous_convex_partial_derivatives_imply_gateaux/diff_dominated}} \\leq\n    -f_+'(x)(-h)\n    \\reloset {\\text{\\ref{thm:convex_one_sided_derivative_negative_inequality}}} \\leq\n    f_+'(x)(h)\n    \\reloset {\\ref{thm:rn_continuous_convex_partial_derivatives_imply_gateaux/diff_dominated}} \\leq\n    \\inprod l h,\n  \\end{balign*}\n  i.e. \\( f_+'(x)(h) = \\inprod l h \\) for all \\( h \\in S_X \\), hence \\( f_+'(x) \\) is a linear functional and \\( f \\) is Gateaux differentiable at \\( x \\).\n\\end{proof}\n\n\\begin{theorem}\\label{thm:rn_continuous_convex_gateaux_implies_frechet}\\mcite[exer. 1.15(a]{Phelps1993})\n  In \\( \\BbbR^n \\), Gateaux differentiability of a continuous convex function \\( f: D \\to \\BbbR \\) at a point \\( x \\in D \\) implies Frechet differentiability.\n\\end{theorem}\n\\begin{proof}\n  Since \\( f \\) is Gateaux differentiable (\\fullref{def:differentiability/gateaux}) at \\( x \\), the derivative \\( f'(x) = f_+'(x) \\) is linear.\n\n  Because \\( f \\) is continuous and convex, it is locally Lipschitz with constant \\( L \\) in some \\( \\delta \\)-ball with center \\( x \\).\n\n  Suppose that \\( f \\) is not Frechet differentiable at \\( x \\). Inverting the condition in \\fullref{def:differentiability/frechet}, we obtain that there exist \\( \\varepsilon > 0 \\) and a sequence \\( \\{ h_n \\}_n \\subseteq B(x, \\delta) \\setminus \\{ 0 \\} \\) such that \\( \\norm{h_n} \\to 0 \\) and yet for all \\( n \\in \\BbbZ_{>0} \\),\n  \\begin{balign}\\label{thm:rn_continuous_convex_gateaux_implies_frechet/frechet_assumption}\n    \\abs{f(x + h_n) - f(x) - \\inprod{f'(x)} {h_n}} > \\varepsilon \\norm{h_n}.\n  \\end{balign}\n\n  Define\n  \\begin{balign*}\n    t_n \\coloneqq \\norm{h_n}\n     &  &\n    u_n \\coloneqq \\frac{h_n} {\\norm {h_n}}.\n  \\end{balign*}\n\n  Obviously \\( t_{n_k} \\downarrow 0 \\). The vectors \\( h_n \\) are linearly independent since otherwise \\( f \\) would not be Gateaux differentiable at \\( x \\), hence \\( u_n \\) are not all equal.\n\n  Since \\( S_{\\BbbR^n} \\) is compact, by the Bolzano-Weierstrass theorem, there exists a convergent subsequence \\( \\{ u_{n_k} \\}_k \\underset {k \\to \\infty} \\to u_0 \\) of \\( \\{ u_n \\}_n \\). We have\n\n  \\begin{balign}\\label{thm:rn_continuous_convex_gateaux_implies_frechet/frechet_estimate}\n     & \\phantom= \\abs{\\frac {f(x + t_{n_k} u_{n_k}) - f(x)} {t_{n_k}} - \\inprod{f'(x)} {u_{n_k}}}\n    \\leq \\nonumber\n    \\abs{\\frac {f(x + t_{n_k} u_{n_k}) - f(x + t_{n_k} u_0)} {t_{n_k}}} +                       \\\\ &+ \\abs{\\frac {f(x + t_{n_k} u_0) - f(x)} {t_{n_k}} - \\inprod{f'(x)} {u_0}} + \\abs{\\inprod{f'(x)} {u_0 - u_{n_k}}}\n    \\leq \\nonumber                                                                              \\\\ &\\leq\n    L \\norm{u_{n_k} - u_0} + \\abs{\\frac {f(x + t_{n_k} u_0) - f(x)} {t_{n_k}} - \\inprod{f'(x)} {u_0}} + \\norm{f'(x)} \\norm{u_0 - u_{n_k}}.\n  \\end{balign}\n\n  Fix \\( \\delta > 0 \\). Because of the Gateaux differentiable of \\( f \\) at \\( x \\), we can pick \\( k_0 \\) such that\n  \\begin{equation*}\n    \\abs{\\frac {f(x + t_{n_{k_0}} u_0) - f(x)} {t_{n_{k_0}}} - \\inprod{f'(x)} {u_0}} < \\delta.\n  \\end{equation*}\n\n  Because \\( \\{ u_{n_k} \\}_k \\) converges to \\( u_0 \\), we can choose \\( k_1 \\) such that\n  \\begin{equation*}\n    \\norm{u_0 - u_{n_{k_1}}} < \\delta.\n  \\end{equation*}\n\n  Thus, for \\( k > \\max \\{ k_0, k_1 \\} \\), \\fullref{thm:rn_continuous_convex_gateaux_implies_frechet/frechet_estimate} is bounded by\n  \\begin{balign*}\n    \\abs{\\frac {f(x + t_{n_k} u_{n_k}) - f(x)} {t_{n_k}} - \\inprod{f'(x)} {u_{n_k}}}\n    \\leq\n    (L + 1 + \\norm{f'(x)}) \\delta.\n  \\end{balign*}\n\n  It suffices to choose \\( \\delta > 0 \\), so that\n  \\begin{equation*}\n    \\delta < \\frac 1 {L + 1 + \\norm{f'(x)}}\n  \\end{equation*}\n  in order to have, for \\( k > \\max \\{ k_0, k_1 \\} \\),\n  \\begin{equation*}\n    \\abs{\\frac {f(x + t_{n_k} u_{n_k}) - f(x)} {t_{n_k}} - \\inprod{f'(x)} {u_{n_k}}} < \\varepsilon.\n  \\end{equation*}\n\n  But this contradicts \\fullref{thm:rn_continuous_convex_gateaux_implies_frechet/frechet_assumption}, hence \\( f \\) is Frechet differentiable at \\( x \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:rn_continuous_convex_partial_derivatives_imply_frechet}\n  In \\( \\BbbR^n \\), the existence of the partial derivatives at \\( x \\) for a continuous convex function \\( f: D \\to \\BbbR \\) at a point \\( x \\in D \\) is equivalent to Frechet differentiability.\n\\end{corollary}\n\\begin{proof}\n  A direct consequence of and \\fullref{thm:rn_continuous_convex_partial_derivatives_imply_gateaux} and \\fullref{thm:rn_continuous_convex_gateaux_implies_frechet}.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:rn_continuous_convex_frechet_almost_everywhere}\\mcite[exer. 1.17]{Phelps1993}\n  In \\( \\BbbR^n \\), continuous convex functions \\( f: D \\to \\BbbR \\) are differentiable almost everywhere.\n\\end{theorem}\n\\begin{proof}\n  For all \\( h \\in S_X \\) and small enough \\( t > 0 \\) we define\n  \\begin{balign*}\n     & \\varphi_h^t: D \\to \\BbbR\n     & \\varphi_h^t(x) \\coloneqq \\frac {f(x + th) - f(x)} t\n  \\end{balign*}\n  and \\( \\varphi_h(x) \\coloneqq f_+'(x)(h) = \\lim_{t \\downarrow 0} \\varphi_h^t(x) \\).\n\n  Considered as functions of \\( x \\), \\( \\varphi_h^t \\) are obviously continuous hence Borel measurable, and so \\( \\varphi_h \\) is also Borel measurable.\n\n  Denote by\n  \\begin{balign*}\n    B_h\n    \\coloneqq\n    \\{ x \\in D \\colon -f_+'(x)(-h) < f_+'(x)(h) \\}\n    =\n    \\{ x \\in D \\colon -\\varphi_{-h}(x) - \\varphi_h(x) < 0 \\}\n  \\end{balign*}\n  the set of points \\( x \\in D \\) where the one-sided derivative \\( f_+'(x)(h) \\) is not linear, given a fixed direction \\( h \\in S_X \\). If \\( B_h \\) is nonempty, \\( f \\) is not differentiable at \\( x \\).\n\n  The sets \\( B_h \\) are Borel sets since they are the preimages of \\( (-\\infty, 0) \\) under a Borel function. We will show that it is a null set for every direction \\( h \\).\n\n  Fix \\( h \\in S_X \\). Denote by \\( \\delta_x \\coloneqq \\sup \\{ t > 0 \\colon x + th \\in D \\} \\).\n\n  The function \\( t \\mapsto f(x + th) \\) is a convex function of one variable. By \\cite[theorem 1.16]{Phelps1993}, it is differentiable \\( \\mu_1 \\)-almost everywhere in \\( [0, \\delta_x) \\), where \\( \\mu_m \\) is the Lebesgue \\( m \\)-measure.\n\n  Denote\n  \\begin{balign*}\n     & H \\coloneqq \\linspan\\{ h \\} \\cong \\BbbR^1,\n    \\\\\n     & H^\\perp \\cong \\BbbR^{n-1} \\text{ - the orthogonal complement of \\( H \\) in \\( \\BbbR^n \\)},\n    \\\\\n     & L_x \\coloneqq \\{ x + th, 0 \\leq t < \\delta_x \\} - half-open segments in D.\n  \\end{balign*}\n\n  THe whole domain \\( D \\) can be represented as \\( D = \\cup \\{ L_x \\colon x \\in H^\\perp \\} \\).\n\n  We can now use Fubini's theorem to show that \\( B_h \\) is a null set:\n  \\begin{balign*}\n    \\mu_n(B_h)\n    =\n    \\int_{B_h} dz\n    =\n    \\int_{\\BbbR^n = H^\\perp \\oplus H} \\chi_{B_h} (z) dz\n    =\n    \\int_{H^\\perp} \\int_{L_x} \\chi_{B_h} (y) dy dx\n    = \\\\ =\n    \\int_{H^\\perp} \\mu_1(B_h \\cap L_x) dx\n    =\n    \\int_{H^\\perp} 0 dx\n    =\n    0.\n  \\end{balign*}\n\n  Hence, for all \\( h \\in S_X \\), \\( -f_+'(x)(-h) = f_+'(x)(h) \\) for almost all \\( x \\in D \\).\n\n  In particular, if \\( e_1, \\ldots, e_n \\) is the canonical basis of \\( \\BbbR^n \\), the \\( i \\)-th partial derivative \\( \\frac{\\partial f} {\\partial x_i} (x) \\) exists only in \\( D \\ B_{e_i} \\).\n\n  The gradient\n  \\begin{equation*}\n    \\nabla f(x) = \\left( \\frac{\\partial f} {\\partial x_1} (x), \\ldots, \\frac{\\partial f} {\\partial x_n} (x) \\right)\n  \\end{equation*}\n  then exists in\n  \\begin{equation*}\n    \\hat D \\coloneqq (D \\ B_{e_1}) \\cap \\ldots \\cap (D \\ B_{e_n}) = D \\setminus \\left( \\bigcup_{i=1}^n B_{e_i} \\right).\n  \\end{equation*}\n\n  \\Fullref{thm:rn_continuous_convex_partial_derivatives_imply_frechet} then implies that \\( f \\) is Frechet differentiable in \\( \\hat D \\), i.e. almost everywhere in \\( D \\).\n\\end{proof}\n", "meta": {"hexsha": "bfe7a408f8d7ba52a87cc3f3141b6440bdc1c4bd", "size": 18144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/convex_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/convex_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/convex_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": 44.5798525799, "max_line_length": 335, "alphanum_fraction": 0.5986552028, "num_tokens": 6950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.625398702069792}}
{"text": "%!TEX root = ../main.tex\n%-------------------------------------------------------------------------------\n\\subsection{Economic framework}\n%-------------------------------------------------------------------------------\nEKW models describe sequential decision-making under uncertainty \\citep{Gilboa.2009, Machina.2014}. At time $t = 1, \\hdots, T$ each individual observes the state of the economic environment $s_t\\in S$ and chooses an action $a_t$ from the set of admissible actions $\\mathcal{A}$. The decision has two consequences: an individual receives an immediate utility $u_t(s_t, a_t)$ and the economy evolves to a new state $s_{t + 1}$. The transition from $s_t$ to $s_{t + 1}$ is affected by the action but remains uncertain. Individuals are forward-looking. Thus they do not simply choose the alternative with the highest immediate utility. Instead, they take the future consequences of their current action into account.\n\nA policy $\\pi = (a^\\pi_1(s_1), \\hdots, a^\\pi_T(s_T))$ provides the individual with instructions for choosing an action in any possible future state. It is a sequence of decision rules $a^\\pi_t(s_t)$ that specify the action at a particular time $t$ for any possible state $s_t$ under $\\pi$. The implementation of a policy generates a sequence of utilities that depends on the objective transition probability distribution $p_t(s_t, a_t)$ for the evolution of state $s_t$ to $s_{t + 1}$ induced by the model. Individuals have rational expectations \\citep{Muth.1961} so their subjective beliefs about the future agree with the objective transition probabilities of the model.\n\n\\autoref{Timing} depicts the timing of events in the model for two generic periods. At the beginning of period $t$, an individual fully learns about the immediate utility of each alternative, chooses one of them, and receives its immediate utility. Then the state evolves from $s_t$ to $s_{t + 1}$ and the process is repeated in $t + 1$.\n%\n\\begin{figure}[b]\n\t%\\vspace{1.0cm}\n\t\\centering\n\t\\scalebox{0.755}{\\input{../material/fig-timing-events.tex}}\n\t\\caption{Timing of events}\n\t\\label{Timing}\n\\end{figure}\n%\n\nIndividuals face uncertainty and they seek to maximize the expected total discounted utilities. An exponential discount factor ${0 < \\delta < 1}$ parameterizes their time preference and captures a taste for immediate over future utilities.\n\nEquation~\\eqref{Objective Risk} provides the formal representation of the individual's objective. Given an initial state $s_1$, individuals implement the policy $\\pi$ from the set of all possible policies $\\Pi$ that maximizes the expected total discounted utilities over all $T$ decision periods given the information available in the first-period state, $s_1$:\n%\n\\begin{align}\\label{Objective Risk}\n\t\\max_{\\pi \\in\\Pi} \\E_{s_1}^\\pi\\left[\\left.\\sum^{T}_{t = 1}  \\delta^{t - 1} u_t(s_t, a^\\pi_t(s_t))\\right]\\right..\n\\end{align}\n%\nThe superscript of the expectation emphasizes that each policy $\\pi$ induces a different probability distribution over the sequences of utilities.\n", "meta": {"hexsha": "f9e906f9fcdfe134aa7d7f6c982d7f41cec8d046", "size": 3031, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/s-setup-economics.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": "paper/sections/s-setup-economics.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": "paper/sections/s-setup-economics.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": 104.5172413793, "max_line_length": 712, "alphanum_fraction": 0.7268228307, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6253987009228172}}
{"text": "\\section{Verification of Parallel Concatenation on Monoids}\\label{sec:parallelization}\nIn this section we define how to concatenate a list of monoids\ninto a monoid. \n%\nThen, we parallelize list concatenation \nand use LiquidHaskell to prove that the \nparallel and sequential versions are equivalent. \n\\NV{What does equivalence means here?}\n\n\\subsection{Concatenation of lists using monoids}\nIf @m@ is a monoid, then @mconcat@ reduces a list of monoids @xs@\nto one monoid. \n\\begin{code}\nmconcat :: List m -> m \nmconcat N        = mempty\nmconcat (C x xs) = x mappend (mconcat xs)\n\\end{code}\n%\nConcatenation folds the elements of the list using @(mappend)@ \nand returns @mempty@ when the list is empty. \n\nNext, we define a parallel version of list concatenation \n%\n\\begin{code}\npmconcat :: Int -> List m -> m\npmconcat i xs  | i <= 1 || llen xs <= i\n  = mconcat xs \npmconcat i xs \n  = pmconcat i $ withStrategy parStrategy $  \n                 map mconcat (chunk i xs)\n\\end{code}%$\nThe function @pmconcat i xs@ calls @mconcat xs@ in the base case, \notherwise it\n(1) chunks the list @xs@ in lists of size @i@, \n(2) runs in parallel @mconcat@ to each chunk, \n(3) recursively runs itself in the result list.\n%\nTermination of @pmconcat@ holds, as the length of @chunk i xs@\nis smaller than the length of @xs@, when @1 < i@. \n%\nConcretely, we define @chunk@ using the standard definition for \nlist @take@ and @drop@.\n\\begin{code}\nchunk :: i:Pos -> xs:List a \n  -> {v:List (List a) | chunkRes i xs } \nchunk i xs \n  | length xs <= i \n  = C xs N \n  | otherwise\n  = C (take i xs) (chunk i (drop i xs))\n\nchunkRes i xs\n  | length xs <= i = length v == 1 \n  | i == 1         = length v == length xs\n  | otherwise     = length v < length xs\n\\end{code}\n\nWhere @take@ and @drop@ type as follows\n\\begin{code}\ndrop :: i:Nat -> xs:{List a | i <= length xs } \n  -> {v:List a | length v == length xs - i }\ntake :: i:Nat -> xs:{List a | i <= length xs } \n  -> {v:List a | length v == i }\n\\end{code}\n\n\n\\paragraph{Runtime Parallelism.}\nTo parallelize concatenation of the chunks we use parallel strategies \nfrom the Haskell library @Control.Parallel.Strategies@.\n%\nFor example, in our implementation @parStrategy@ is defined as\n\\begin{code}\nparStrategy :: Strategy (List a)\nparStrategy = parTraversable rdeepseq\n\\end{code}\n\nNote that parallelization of concatenation leads to runtime speedups\nonly when @(mappend)@ runs in constant time with respect to the monoid size. \n%\nOtherwise, at each recursive call of @pmconcat@,\nruntime will be dominated by the size of the biggest list element. \n\nEven though runtime of the parallel version depends on the implementation details \nof the monoids, correctness holds for every monoid. \n%\nIn the rest of this section we prove equivalence of the sequential and parallel concatenation operations. \n\n\n\\paragraph{Parallelism in the Logic.}\nTo prove equivalence we make the \\textit{assumption}\nthat the Haskell function @withStrategy s x@ \nreturns @x@ for every strategy.\n\\begin{code}\nassume withStrategy :: Strategy a -> x:a -> {v:a | v == x}\n\\end{code}\n%\nMoreover, to prove equivalence, we need to represent \nthe implementation of @pmconcat@ in logic.\n%\nWhich, in turn, requires representation of @withStrategy@. \n%\nLiquidHaskell represents @withStrategy@ in logic as a function that merely returns\nits second argument @withStrategy _ x = x@\nand does not reason about parallelism. \n\n\\subsection{Equivalence of Parallel and Sequential Concatenation}\n\n\\begin{theorem}[Monoid Concatenation Equivalence]\\label{theorem:equivalence:concat}\nIf @m@ is monoid, then the parallel and sequential concatenations are equivalent:\n\\begin{code}\n  pmconcatEq :: i:Int -> is:List m -> {pmconcat i is == mconcat is }\n\\end{code}\n\\end{theorem}\n\n\\begin{proof}\nWe prove the theorem by providing a Haskell implementation of @pmconcatEq@\nthat is safe under LiquidHaskell. The 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}\nmconcatSplit \n  :: i:Nat -> xs:{List m | i <= llen xs} \n  -> { mconcat xs == mconcat (take i xs) \n                 <> mconcat (drop i xs) }\n\\end{code}\n%\nThe proofs proceeds by structural induction, using monoid left identity in the base case\nand associavity in the inductive step.\n\nWe generalize the above\nto prove that @mconcat@ distributes over list chunking\n\\begin{code}\nmconcatChunk \n  :: i:Pos -> xs:List (Monoid a) \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\nNote that the proof uses only the monoid laws and not the implementations of the monoid\noperators, thus the theorem holds \\textit{for any} type that satisfies the monoid laws. \n%\nNext we define a monoid structure for string matching and prove it satisfies the monoid laws. \nThus we conclude that string matching concatenation can be parallelized. \n \n", "meta": {"hexsha": "6dee2e37c2e04ca7132c8118502dad1daa508e50", "size": 5167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/parallelization.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/parallelization.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/parallelization.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": 33.9934210526, "max_line_length": 106, "alphanum_fraction": 0.7259531643, "num_tokens": 1385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6253986865194494}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb}\n\\usepackage{amsthm}\n\\usepackage{enumitem}\n\\usepackage[legalpaper, margin=1in]{geometry}\n\\usepackage{amsfonts}\n\\usepackage[mathscr]{eucal}\n\\usepackage{hyperref}\n\\newtheorem{thm}{Theorem}\n%this makes it so that everything labelled thm is numbered by section\n\\newtheorem{claim}[thm]{Claim}\n\\newtheorem{cor}[thm]{Corollary}\n\\newtheorem{conclusion}{Conclusion}\n%\\newtheorem{remark}[thm]{Remark}\n\\newtheorem{lemma}[thm]{Lemma}\n\\newtheorem{prop}[thm]{Proposition}\n\\newtheorem{prob}[thm]{Problem}\n%\\newtheorem{exam}[thm]{Example}\n\\theoremstyle{definition}\n%this makes the following things non-italicized\n\\newtheorem{defn}[thm]{Definition}\n\\newtheorem{postulate}{Postulate}\n\\newtheorem{remark}[thm]{Remark}\n\\newtheorem{discrepency}[thm]{Discrepency}\n\\newtheorem{exam}[thm]{Example}\n\\newtheorem{innercustomthm}{Word Postulate}\n\\newenvironment{customthm}[1]\n{\\renewcommand\\theinnercustomthm{#1}\\innercustomthm}\n{\\endinnercustomthm}\n\n\\title{Time Series Analysis Notes}\n% \\author{Mozahid Haque}\n% \\date{October 2020}\n\n\\begin{document}\n\\maketitle\n\\section{Overview of Time Series Characteristics}\n\\begin{defn}\nA \\textbf{univariate time series} is a sequence of measurements of one variable at regular time steps.\n\\end{defn} \n\\noindent Such data need not be IID.\n\n\\subsection{Objectives of Analysis}\n\\begin{enumerate}\n    \\item Describe important features of any time series pattern\n    \\item Explain how past affects future or how two time series \"interact\"\n    \\item Forecasting\n    \\item Use time series as a control standard, e.g., measurements of the quality of some manufacturing product\n\\end{enumerate}\n\n\\subsection{Model Types and Considerations}\nThere are two basic types:\n\\begin{enumerate}\n    \\item Relating time series values to past values and past prediction errors -- called Autoregressive Integrated Moving Average or ARIMA models.\n    \\item Regular regression models with time indices as x-variables.\n\\end{enumerate}\n\n\\noindent Initial data exploration:\n\\begin{itemize}\n    \\item Trend -- overall progression of measurements\n    \\item Seasonality -- periodic behavior based around calendar intervals such as seasons, quarters, months, weeks, etc.\n    \\item Outliers -- data away from original data or away from some manipulation of it\n    \\item Long-run Cycle -- periodic behavior unrelated to seasonality type\n    \\item Constant Variance -- variance changing or not\n    \\item Abrupt Changes -- significant disturbances to series or variance or other things\n\\end{itemize}\n\n\\subsection{Autoregressive Models:  Autocorrelation and Partial Autocorrelation}\n\\begin{defn}\nLet $\\{y_t\\}_{t=1}^n$ be a time series indexed by $t$. An \\textbf{autoregressive model} is one where time series values are regressed on previous values.  For example, a first-order autoregression AR(1) would look like:\n\\[ y_t = \\beta_0 + \\beta_1 y_{t-1} + \\epsilon_t \\]\nand a second-order autoregression AR(2) would look like:\n\\[ y_t = \\beta_0 + \\beta_1 y_{t-1} + \\beta_2 y_{t-2} + \\epsilon_t. \\]\nIn general, a $k^\\text{th}$-order autoregression AR(k) is given by \n\\[ y_t =  \\left( \\beta_0, \\beta_1, \\hdots, \\beta_n, 1 \\right) \\left( 1, y_{t-1}, \\hdots, \\beta_{t-n}, \\epsilon_t \\right)^T. \\]\nUsually the errors $\\epsilon_t \\overset{iid}{\\sim}N(0, \\sigma_{\\epsilon}^2)$ and independent of $y$.\n\\end{defn}\n\nThis begs the question:\nHow do we choose the order for a given time series?\nThere are two methods:\n\\begin{enumerate}\n    \\item Autocorrelation function (ACF) and\n    \\item Partial Autocorrelation function (PACF).\n\\end{enumerate}\n\\begin{defn}\nThe coefficient of correlation between two values in a time series given by:\n\\[ \\text{Corr}(y_t, y_{t+k}) = r_k = \\frac{c_k}{c_0} ~~~~\\text{where}~~~~\nc_k = \\frac{1}{n} \\sum_{t=1}^{n-k} (y_t - \\bar{y})(y_{t+k} - \\bar{y}) \\]\nis called the \\textbf{autocorrelation function (ACF)}.\nRecall what familiar term $c_0$ is.  Notice the similarity to the covariance formula which is meant to exhibit the linear relationship between two variables.  In this case, this is the covariance (or linear relationship) of lagged values.  Here the \\textbf{lag} is given by \\textbf{k}.\n\\end{defn}\n\nThis is one method.  This method includes in it the influence of other lags on $y_t$.  The second method removes this influence of the other lags in between...\n\\begin{defn}\nHere the \\textbf{Partial Autocorrelation Function (PACF)} is given by\n\\[ f_k = \n\\begin{cases} \n      r_1 = \\text{Corr}(y_t, y_0) & \\text{if}~ k=1; \\\\\n      \\text{Corr}(y_t - y_t^{t-1}, y_0 - y_0^{k-1}) & \\text{if}~ k \\geq 2\n   \\end{cases}.\n\\]\nEssentially, this has the effect of determining the linear correlation between $y_t$ and $y_{t+k}$ but removing the linear dependence of lags in between $t$ and $t+k$, namely $t_i$ such that $t < t_i < t+k$.  One can also think of this as subtracting away the projection of $y_t$ on the linear subspace spanned by $y_{t+1}, \\hdots, y_{t+k-1}$.\n\\end{defn}\n\nWe can additionally complicate the whole thing by considering certain trend behavior within our original time series via decomposition.\n\n\\subsection{Complexifying ACF/PACF via Decomposition and/or Higher Order Trends}\nThe typical decomposition of a time series involves:\n\\begin{itemize}\n    \\item overall trend, $m_t$\n    \\item seasonality, $s_t$, and\n    \\item error, $\\epsilon_t$\n\\end{itemize}\nso that\n\\[ y_t = m_t + s_t + \\epsilon_t. \\]\nTypical estimation involves first estimating the overall trend through linear filters.  One example of this is a moving average given by some \"window\" size:\n\\[ \\hat{m_t} = \\sum_{k=-a}^a \\left( \\frac{1}{1+2a} \\right) y_{t+k}. \\]\nWe can experiment with the window size to get a feel for a good overall trend.  Then once this is done, we can estimate the seasonality by looking at what remains:\n\\[ \\hat{s_t} = y_t - \\hat{m_t}. \\]\nNote that this $\\hat{s_t}$ depends on the window size.  So we can take the average of the window sized seasonality estimates to fix a single $s_t$.  Then this gives us a way to calculate the error:\n\\[ \\epsilon_t = x_t - \\hat{m_t} - \\hat{s_t}. \\]\nLuckily there are packages for such decomposition.\n\nAnother way to complexify our model for our time series is to add quadratic trends to the model by considering not just linear time factors $t$, but higher order factors and interactions such as $t^2$, $t^3$, etc.\n\\end{document}\n", "meta": {"hexsha": "896349253c15abae0ae9ceaabb54a1b80143fbae", "size": 6348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "mh86/timeseries_learning", "max_stars_repo_head_hexsha": "ae12dcfcfd3edddf088e309911948ee373d21c30", "max_stars_repo_licenses": ["MIT"], "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": "mh86/timeseries_learning", "max_issues_repo_head_hexsha": "ae12dcfcfd3edddf088e309911948ee373d21c30", "max_issues_repo_licenses": ["MIT"], "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": "mh86/timeseries_learning", "max_forks_repo_head_hexsha": "ae12dcfcfd3edddf088e309911948ee373d21c30", "max_forks_repo_licenses": ["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.59375, "max_line_length": 343, "alphanum_fraction": 0.7399180844, "num_tokens": 1857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.6251601929960792}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{comment}\n \n\\usepackage[noend]{algpseudocode}\n\\usepackage{algorithm}\n\\usepackage{float}\n\\usepackage{graphicx}\n\\usepackage[margin=.75in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb}\n\\usepackage{dsfont}\n\\usepackage{amsthm}\n\\usepackage{mathtools,amssymb}\n\\usepackage{wrapfig,caption,subcaption}\n\\allowdisplaybreaks\n\n\\newtheorem*{definition}{Definition}\n\\newtheorem*{question}{Question}\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{proposition}[theorem]{Proposition}\n\\newtheorem{claim}[theorem]{Claim}\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{conjecture}[theorem]{Conjecture}\n \n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Rgz}{\\mathbb{R}_{\\ge 0}}\n\n\\newcommand{\\ip}[2]{\\left\\langle{#1},{#2}\\right\\rangle}\n\\newcommand{\\norm}[1]{\\left\\lVert{#1}\\right\\rVert}\n\\newcommand{\\sizeof}[1]{\\left\\lvert{#1}\\right\\rvert}\n\n\\newcommand{\\woloss}{without loss of generality }\n\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\cone}{cone}\n\\DeclareMathOperator*{\\hull}{hull}\n\\DeclareMathOperator*{\\indif}{indif}\n\n\\newcommand{\\1}[1]{\\mathds{1}[{#1}]}\n\\renewcommand{\\P}[1]{\\mathds{P}\\left[{#1}\\right]}\n\\newcommand{\\E}[1]{\\mathds{E}\\left[{#1}\\right]}\n\\newcommand{\\Var}[1]{\\mathrm{Var}[{#1}]}\n\n\\newcommand{\\unit}{\\mathds{1}}\n\\newcommand{\\lo}{\\succ}\n\n% \\renewcommand{\\thesubsection}{\\thesection.\\alph{subsection}}\n% \\renewcommand\\thesubsection{\\ \\ (\\alph{subsection})}\n\n\n\\begin{document}\n\n% \\renewcommand{\\qedsymbol}{\\filledbox}\n \n\\title{\n  Dim Prefs\n}\n\\author{\n  Clay Thomas \\\\\n  claytont@princeton.edu\n}\n\\maketitle\n\n\\section{Lemmas}\n  In this section, we set up the tools needed to reason about \n  $d$-dimensional preferences.\n\n  \\subsection{Lemmas based on the structure of $X$}\n    These first few lemmas relate geometric properties of $X$ to\n    limitations on the structure of $>_a$ for a specific, fixed $a$.\n\n    The most simple way $X$ gives structure to preferences is if\n    one outcome is better in all attributes.\n    \\begin{definition}\n      Let $x,y\\in X\\subseteq \\Rgz^d$.\n      We say $x$ \\emph{dominates} $y$, denoted $x\\gg y$,\n      if $x[k] > y[k]$ for each $k=1,\\ldots,d$.\n    \\end{definition}\n    \\begin{proposition}\n      If $x \\gg y$, then $x >_a y$ for any nonzero $a\\in \\Rgz^d$.\n    \\end{proposition}\n\n    When comparing different outcomes, a useful tool is\n    the familiar geometric notion of a convex hull.\n    Intuitively, if a preference weight does not like any of a set of options,\n    it will not like any outcome in the hull of those options either.\n    Thus, a point ``dominated by the hull'' of a set of options\n    cannot be preferred to all those options.\n    \\begin{definition}\n      For points $x_1,\\ldots,x_n \\in \\R^d$, let $\\hull(x_1,\\ldots,x_n)\n      = \\{u_1x_1 + \\ldots + u_nx_n | 0\\le u_i\\le 1, \\sum_{i=1}^n u_i = 1\\}$\n      denote the convex hull of $x_1,\\ldots,x_n$.\n    \\end{definition}\n    \\begin{lemma}\\label{lem:agreementHull}\n      Let $z,x_1,\\ldots,x_k \\in \\Rgz^d$ and $a\\in \\Rgz^d \\setminus \\{0\\}$.\n      If $z >_a x_i$ for $i=1,\\ldots,k$, then $z >_a w$\n      for any $w\\in \\hull(x_1,\\ldots,x_k)$.\n    \\end{lemma}\n    \\begin{proof}\n      We have $\\ip{a}{z} > \\ip{a}{x_i}$ for each $i=1,\\ldots,k$.\n      If $w = u_1x_1+ \\ldots + u_nx_n$ and $\\sum_i u_i =1$, then\n      $\\ip{a}{w} = u_1\\ip{a}{x_1}+\\ldots+u_n\\ip{a}{x_n}\n      < u_1\\ip{a}{z} + \\ldots + u_n\\ip{a}{z} = \\ip{a}{z}$.\n    \\end{proof}\n\n    \\begin{proposition}\\label{prop:domHull}\n      Let $U, V \\subseteq \\Rgz^d$ be finite sets of points.\n      Suppose that there exists $u\\in \\hull U$ and $v\\in \\hull V$\n      such that $u \\ll v$.\n      Then no $a$ satisfies $u_i >_a v_i$ for each $i=1,\\ldots, k$.\n      % Suppose that there exists $w\\in \\hull(x_1,\\ldots,x_k)$\n      %     such that $z \\gg w$.\n      %     Then no $a$ satisfies $x_i >_a z$ for each $i=1,\\ldots, k$.\n    \\end{proposition}\n    \\begin{proof}\n      For contradiction, suppose such an $a$ exists.\n      First, note $u_i >_a v \\in \\hull V$,\n      then see that $\\hull U \\ni u >_a v$ as well.\n      But $u\\ll v$, so this is a contradiction.\n    \\end{proof}\n\n    The converse of the last theorem also holds:\n    \\begin{proposition}\n      Suppose that no $a\\in \\R_{>0}^d$ satisfies $u_i \\ge_a v_j$ for each \n      $u_i \\in U$ and $v_j\\in V$.\n      Then there exist $u\\in\\hull(U)$ and $v\\in\\hull(V)$ with $u\\ll v$.\n      NOTE: SHOULD USE THE ``SEMISTRICT`` DEFINITION OF << \n    \\end{proposition}\n    \\begin{proof}\n      If no $a$ has this property, then in particular the following linear\n      program is infeasible:\n      \\begin{alignat*}{2}\n        \\text{min: } &\n        \\sum_{k=0}^d 0\\cdot a_k \\\\\n        \\text{s.t. } &\n        \\begin{aligned}[t]\n          \\sum_{k=1}^d a_k (u^i_k - v^j_k)\n            & \\ge 0\n            \\quad \\forall i\\in U, j\\in V\n          \\\\ a_k & \\ge 1 \\quad \\forall k\n        \\end{aligned}\n      \\end{alignat*}\n      The dual of this linear program is\n      \\begin{alignat*}{2}\n        \\text{max: } &\n          \\sum_{i\\in U, j\\in V} 0\\cdot b_{ij} + 1\\cdot c_k \\\\\n        \\text{s.t. } &\n        \\begin{aligned}[t]\n          \\sum_{i\\in U, j\\in V} b_{ij}(u^i_k - v^j_k) + c_k\n            & \\le 0\n            \\quad \\forall k\n          \\\\ b_{ij} & \\ge 0 \\quad \\forall i,j\n          \\\\ c_k & \\ge 0 \\quad \\forall i,j\n        \\end{aligned}\n      \\end{alignat*}\n      This dual program is always feasible (with the all zeros solution)\n      so by strong duality it must be unbounded.\n      Take some solution and some $k$ with $c_k > 1$.\n      At this solution, $b_{ij}$ are not all zero.\n      Thus, take\n      $\\sum_{i,j} b_{ij}=B$, and consider:\n      \\[ \\sum_{i\\in U} \\left(\\sum_{j\\in V}b_{ij}/B \\right) u^i_k\n        \\le - \\frac {c_k} B + \\sum_{j\\in V} \\left(\\sum_{i\\in U}b_{ij}/B \\right) v^j_k\n        < \\sum_{j\\in V} \\left(\\sum_{i\\in U}b_{ij} / B\\right) v^j_k\n      \\]\n      NOTE: THIS CANNOT BE CORRECT BECAUSE IT IMPLIES EG THAT ALL\n      POINTS ARE MORE THAN 1 APART\n    \\end{proof}\n\n\n    This motivates the following definition:\n    \\begin{definition}\n      A set of points dominates, denoted $U \\ll V$,\n      when DEFINITION\n    \\end{definition}\n\\end{document}\n", "meta": {"hexsha": "4f7a1305b093e1c68f3af428609a268369e37693", "size": 6238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/system.tex", "max_stars_repo_name": "ClathomasPrime/linear-prefs", "max_stars_repo_head_hexsha": "e700589a82667ca0f307459816e4f5b211fbd7d2", "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": "tex/system.tex", "max_issues_repo_name": "ClathomasPrime/linear-prefs", "max_issues_repo_head_hexsha": "e700589a82667ca0f307459816e4f5b211fbd7d2", "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/system.tex", "max_forks_repo_name": "ClathomasPrime/linear-prefs", "max_forks_repo_head_hexsha": "e700589a82667ca0f307459816e4f5b211fbd7d2", "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.4640883978, "max_line_length": 85, "alphanum_fraction": 0.6207117666, "num_tokens": 2223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.625160189509568}}
{"text": "%\n% 281\n%\n\\chapter{The Hypergeometric Function}\n\n\\Section{14}{1}{The hypergeometric series.}\n\nWe have already \\hardsubsectionref{2}{3}{8}) considered the hypergeometric series*\n\n1 + - ., ( + l) ( + l) a(a + l)(a+2)6(6+l)(6 + 2) 3 l.c 1.2.c(c + l)\n\"* 1.2.3.c(c + l)(c + 2) \"\n\nfrom the point of view of its convergence. It follows from \\hardsubsectionref{2}{3}{8} and \\hardsectionref{5}{3} that the series defines a function which is analytic when i 2 j\n< 1.\n\nIt will appear later \\hardsubsectionref{14}{5}{3}) that this function has a branch point\nat 2 = 1 and that if a cutf (i.e. an impassable barrier) is made from\n+ 1 to + along the real axis, the function is analytic and one-valued\nthroughout the cut plane. The function will be denoted by F a, b;c;z).\n\nMany important functions employed in Analysis can be expressed by\nmeans of hypergeometric functions. Thus|\n\n(1 +2)\" = F(-n, :;-z),\n\nlog l + z) = zF(l, l;2;-z),\n\ne'=\\ im F l,0;l;zl0).\n\nExample. Shew that d\n\nF a, b; c; z) = ~F a + \\, 6 + 1; c + 1; 2).\n\n1411. The valuel of F(a, b; c; I) when E(c-a-b)>0.\n\nThe reader will easily verify, by considering the coefficients of\n.2;'* in the\n\n* The name was given bj- Wallis in 1655 to the series whose Kth term\nis a + b a + 2b ... a + n-l)b . Euler used the term hypergeometric in\nthis sense, the modern use of the term being apparently due to Kummer,\nJournal fiir Math. xv. (1S36).\n\nt The plane of the variable z is said to be cut along a curve when it\nis convenient to consider only such variations in z which do not\ninvolve a passage across the curve in question; so that the cut may\nbe regarded as an impassable barrier.\n\nX It will be a good exercise for the reader to construct a rigorous\nproof of the third of these results.\n\n§ This analysis is due to Gauss. A method more easy to i-emember but\nmore difficult to justify is given in \\hardsectionref{14}{6} example 2.\n\n%\n% 282\n%\n\nvarious series, that if \\$ ir < 1, then c c-l- 2c-a-b-l)x]F (a, b : c\n; x) + (c - a) c - b) xF (a, b; c + I; x)\n\n= c(c-l) l-x)F(a,b;c-l;x)\n\n= C(C -l)jl+ (Un-Un-i)x'>'l,\n\nwhere Un is the coefficient of \" in i''(a, 6; c - 1; x).\n\nNow make x->l. By \\hardsubsectionref{3}{7}{1}, the right-hand side tends to zero if\n\n1+2 (un - tin-i) converges to zero, i.e. if ?i,j- >0, which is the\ncase when =i\n\nR c- a - 6) > 0.\n\nAlso, by \\hardsubsectionref{2}{3}{8} and \\hardsubsectionref{3}{7}{1}, the left-hand side tends to\n\nc(a+b-c)F a,b;c;l) + c-a)(c- b) F(a, b;c+l;l) under the same condition\n; and therefore\n\nRepeating this process, we see that\n\nF(a, b: c;l) = i Yl ) -- -, ( F(a, b:c + 7n; 1)\n\n  ' '\\ n=o c + n) c-a-b + n)\\ ' ' '\n\n= ] lira n ) ., f [ lim F(a, b;c + m; 1),\n\nif these two limits exist.\n\nBut ( 12'13) the former limit is tt r-Fr, rz, if c is not a negative\n\n T c - a) 1 (c- 6) °\n\ninteger; and, if Un(ci, b, c) be the coefficient oi x in F (a, b; c;\nx), and\n\nm > I c I, we have\n\n00\n\n\\ F a, b] c + m; l) - l\\ \\ 2 \\ un(a, b, c + m)\\\n\nn = l\n\n00\n\n  X Un (ja,, ib\\, m - \\ c )\n\nn=l\n\n' Q,b I \"\n\n<, 2 Mn (I a i -h 1, I 6 I + 1, 7?l -f- 1 - I C I).\n\nm-\\ c\\ n=o\n\nNow the last series converges, when ??i > ic| 4- a -f j l - 1, and is\na positive decreasing function of m; therefore, since [m - '\\ c\\ \\ }~\n->0, we have\n\nlim F(a, b: c + m; 1)= 1;\n\nand therefore, finally,\n$$\nTODO\n$$\n%\n% 283\n%\n\n\\Section{14}{2}{The differential equation satisfied by F (a, b; c: z).}\n\nThe reader will verify without difficulty, by the methods of § lO'S,\nthat the hypergeometric series is an integral valid near = of the\nhypergeometric\n\nequation*\n\n   ~ d? + (c - (a + + 1) - - \\&' =;\n\nfrom \\hardsectionref{10}{3}, it is apparent that every point is an 'ordinary point' of\nthis equation, with the exception of 0, 1, x, and that these are '\nregular points.'\n\nExample. Shew that an integral of the equation\n\ni\n\nz< F a- a, 6 + a; a- + 1; z).\n\n\\Section{14}{3}{Solutions of Riemann's P-equation by hypergeometric functions.}\n\nIn \\hardsubsectionref{10}{7}{2} it was observed that Riemann's differential equation f\n\ndru j] -a -a' 1- -/3' l-y-y\\ du dz- \\ z- a z-b z - c ) dz\n\n\\ aa' (a-b)(a-c) jB' h - c) b - a ) \\ 77 (c-a)(c-6) z- a z - b z - c\n\nu\n\n z - a) z - b) z - c)\n\n= 0.\n\nby a suitable change of variables, could be reduced to a\nhypergeometric equation; and, carrying out the change, we see that a\nsolution of Riemann's equation is\n\nTODO\n\nprovided that a - a' is not a negative integer; for simplicity, we\nshall, throughout thi section, suppose that no one of the exponent\ndifferences a - a', /3 -, 7 - 7' is zero or an integer, as \\hardsubsectionref{10}{3}{2})\nin this exceptional case the general solution of the differential\nequation may involve logarithmic terms; the formulae in the\nexceptional case will be found in a memoir :J: by Lindelof, to which\nthe reader is referred.\n\nNow if a be interchanged with a', or 7 with 7', in this expression, it\nmust still satisfy Riemann's equation, since the latter is unaffected\nby this change.\n\n* This equation was given by Gauss.\n\nt The constants are subject to the condition a + a' + + ' + y + y' =\nl.\n\nJ Acta Soc. Sclent. Fennicae, xix. (1893). See also Klein's\nlithographed Lectures, Veher die hypergeometrische Funktion (Leipzig,\n1894).\n\n%\n% 284\n%\n\nWe thus obtain altogether four expressions, namely,\n\n'z-aX /z-c\\ y f .,, - .,,,\\ c-h) z-a)\\\n\nM, =\n\n(z-ay /z-c\\ y p, ry, -, > c-b) z-a)]\n\n ==(.- i) U- ft) J | + /3 + 7', o + +t; l+°-'''; (o-a)(.-6) j-\n\nwhich are all solutions of the differential equation.\n\nMoreover, the differential equation is unaltered if the triads (a, a',\na), (yS, y8', h), (y, y', c) are interchanged in any manner. If\ntherefore we make such changes in the above solutions, they will still\nbe solutions of the differential equation.\n\nThere are five such changes possible, for we may write\n\n b, c, a\\, c, a, b], a, c, b], [c, b, a], [b, a, c]\n\nin turn in place of [a, b, c], with corresponding changes of a, a, /S,\n(3', 7, 7'.\n\nWe thus obtain 4 x = 20 new expressions, which with the original four\nmake altogether twenty-four particular solutions of Riemann's\nequation, in terms of hypergeometric series.\n\nThe twenty new solutions may be written down as follows :\n\nu. =\n\nz-by fz-aY (,,, a-c)(z-b)\\ iP'j/8 + 7 + a, /3 + 7'+a; l + yS-/3'; )\n, (\n\nz-b\\ \\ ' [z-ay t q,, o', ', . 1, /D' o. (a-c)( -\\&)]\n\nUa =\n\n s=('- ) ('- Y Fy+y + oc, '+y'+a-l + /3'-/3-,. .\n\n\\ z - cj \\ z - cj [ \" a-b) z- c)\n\n(z-b fz - a-y \\ (, \\,,, (a - c)(z - b)\n\n\\ z - cl \\ z - c \\ (a -b) z - c)\n\ni /3+7+a, /3+7+a; l + /3'-/3; ~ '-\\\n\n\\ Z-C' \\ Z-C' y I ' r- I ) r- r- ' ( \\ J - c)\\\n\n(z-c\\ y (z-b\\ \\, o -., b-a) z- c)]\n\n\" \"=U- ) U- J |7 +,7+a-+;l + y-7; \\; \\ |\n\nU,,= l - )'( - r F\\ y a + ',y c '; I + 7-7'; j H \\ z-aj \\ z-al [' ' \"\n' ' ' (l,-c)(z-a)\\\n\n   = (lllfy7l Yf f/'+o + ZS'. 7'+a+/3'; 1 + 7-7; P - \\ z-aj \\ z-a) ' \"\n' ' ' > (i,-c) z- a)\n\n%\n% 285\n%\n\nZ ~ Cj\n\na,.=\n\nMlQ -\n\nFL + y + ',a + y' + '; I + a - a; l' '\\ \\ ' ' ''\\ \\, [ b-a) z-c)\n\n/ -cy'/2-a\\ j ', /o', 1, ' a-b)(z-c))\n\n.T b) U- 6J |t+/3 +,7+ +< : 1+7-7; \\;( \\ |,\n\n\\ z - a J \\ z-a) [ ' (c-b)(z- a) '\n\n- / i c - o)(z - a))\n\n1 V - / \\ z-aj ( ' \" I r ' (c-6)( -a)J '\n\nBy writing 0, 1 - C,, B, 0, 6'- -5, a; for a, a', yg, S', y, y,\n\n/ - AU - respectively, we obtain 24 solutions of the hypergeoraetric\n\nequation satisfied by F A, B; G; x).\n\nThe existence of these 24 solutions was first shewn by Kuinmer*.\n\n\\Section{14}{4}{Relations betiueen particular solutions of the hyper geometric equation.}\n\nIt has just been shewn that 24 expressions involving hypergeometric\nseries are solutions of the hypergeometric equation; and, from the\ngeneral theory of linear differential equations of the second order,\nit follows that, if any three have a common domain of existence, there\nmust be a linear relation with constant coefficients connecting those\nthree solutions.\n\nIf Ave simplify n-, u.,, ih, ih] u, u g-, u i, W22 in the manner\nindicated at\n\n* Journal fUr Math. xv. (1836), pp. 39-83, 127-172. They are obtained\nin a different manner in Forsyth's Treatise on Differential Equations,\nChap. vi.\n\n' 22 =,\n\n\\ z - aj \\ z\n\n%\n% 286\n%\n\nthe end of \\hardsectionref{14}{3}, we obtain the following solutions of the\nhypergeometric equation with elements A, B, G, x:\n\ny, =F A,B;C-x),\n\ny = (- xy- 'FiA -C+\\,B-G+1;2-C;x),\n\ny,=(l-xr-''- F C-B,C-A;G;xl\n\ny = (\\ ccY-'' l - xf- - 'Fil -B,l-A;2-G;x),\n\ny,r = F A,B; A + B - G + 1; 1 - x),\n\ny = xf- -''F G-B, G-A; G-A-B-hl; l-x),\n\ny = (\\ xY 'FiA, A-G+\\;A-B + \\; x-%\n\ny = (- x)- F B,B-G + l]B-A + l; x-'). If 1 arg(l - a;) I < TT, it is\neasy to see from \\hardsubsectionref{2}{5}{3} that, when j .r | < 1, the relations\nconnecting y, y.2, y y must be y y-i, y2= rj, by considering the\nform of the expansions near c; = of the series involved.\n\nIn this manner we can group the functions Wj, ... z/24 into six sets\nof four*, viz. u-i, v-i, Mi3, Wis; Un, Hi, u, iiis; ii, u, M21, u\n', Wg, u, U22, M24 j '\"9? Wji, t<i7> ' 19 j Wjo, U12, u-18, '' ho,\nsuch that members of the same set are constant multiples of one\nanother throughout a suitably chosen domain.\n\nIn particular, we observe that Ui, u, u s, u are constant multiples\nof a function which (by §§ 5*4, 2\"o3) can be expanded in the form\n\n z-aY\\ l+ i en(2-a)4\n\nwhen \\ z - a\\ is sufficiently small; when arg z - a) is so restricted\nthat (z - a)* is one-valued, this solution of Riemann's equation is\nusually written P'\"*. And P'\"'; P' ', P' '; P* ', P* * are defined in\na similar manner when\n\nz - a\n\n\\ z - b\\, \\ z - c\\ respectively are sufficiently small.\n\nTo obtain the relations which connect three members of separate sets\nof solutions is much more difficult. The relations have been obtained\nby elaborate transformations of the double circuit integrals which\nwill be obtained later in \\hardsubsectionref{14}{6}{1}; but a more simple and singularly\nelegant method has recently been discovered by Barnes; of his\ninvestigation we shall give a brief account.\n\n\\Section{14}{5}{Barnes contour integrals for the hypergeometric function.}\n\nConsider r-. ~ -- p/, . - - '(-zyds,\n\n273-1 j\\ xj r(c + s)\n\nwhere |arg(- -z)] <7r, and the path of integration is curved (if\nnecessary) to ensure that the poles of r(a + 5)r(6 + 6'), viz. s = - a\n- n, -h-n n = 0, 1, 2, . . .),\n\n* The special formula\n\nFiA,l;C;.) F( C-A,l;C; ),\n\nwhich is derivable from the relation counectiug Mj with i3, was\ndiscovered in 1730 by Stirling, Methodus Differential is, prop. vii.\n\nt Piuc. London Math. Soc. (2), vi. (1908), pp. 141-177. References to\nprevious work on similar topics by Pincherle, Mellin and Barnes are\nthere given.\n\n%\n% 287\n%\n\nlie on the left of the path and the poles of r(- 5), viz. s = 0, 1, 2,\n..., lie on the right of the path *.\n\nFrom \\hardsectionref{13}{6} it follows that the integrand is\n\nOils j +''-c-i exp - arg - z) . I (s) - 7r\\ I s)\\ \\ ]\n\nas s- ►CO on the contour, and hence it is easily seen (| 5\"32) that\nthe integrand is an analytic function of z throughout the domain\ndefined by the inequality I arg 2\\ TT - S, where B is any positive\nnumber.\n\nNow, taking note of the relation F (- 5) F (1 + s) = - tt cosec s-rr,\nconsider\n\nT(a+s)r(b+s) iri-zy\n\nIf IttiJ c\n\nds,\n\n27rij(7 F(c + s) F(l +s) sinsTT\n\nwhere C is the semicircle of radius iV + - on the right of the\nimaginary axis\n\nwith centre at the origin, and N is an integer.\n\nNow, by \\hardsectionref{13}{6}, we have\n\nr(a+ )F(6 + ) -n-i-zy . a+,\\,\\,) (- y T(c + s)r l+s) sinsTT ' sin\nstt\n\nas N-> 00, the constant implied in the symbol being independent of\narg s when s is on the semicircle; and, if 6 = f j\\ \\ + j e''* and j\n| < 1, we have\n\n(- zy cosec sir = exp j ( iV + .j j cos 6 log | | - ( lY + j sin arg\n(- z)\n\n-(iV + )7r|sm ||]\n\nexp I i\\ \\ + . ) cos 6' log I I - (iV + ] 8 1 sin ( 1 11\n\nexp|2- iV +. )logj\n\nexp|-2- 8(i\\ r + i)|\n\n=\n\n  I 6* k 7 TT,\n\n1 I zii 1\n\nHence if log | | is negative (i.e. \\ z\\ < 1), the integrand tends to\nzero sufficiently rapidly (for all values of 6 under consideration) to\nensure that\n\n/.\n\n'0 as iV- oo\n\nNow\n\nJ -ooi [J ~xi J C J (iV+i) i)\n\nby Cauchy's theorem, is equal to minus 2'Tri times the sum of the\nresidues of the integrand at the points s = 0, 1,2, ... N. Make N->cc\n, and the last\n\n* It is assumed that a and b are such that the contour can be drawn,\ni.e. that a and b are not negative integers (in which case the\nhypergeometric series is merely a polynomial).\n\n%\n% 288\n%\n\nthree integrals tend to zero when | arg (- ) | tt - S, and \\ z \\ < 1,\nand so, in these circumstances,\n\nthe general term in this summation being the residue of the integrand\nat\n\nS = 71.\n\nThus, an analytic function namely the integral under consideration)\nexists throughout the domain defined by the inequality j arg | < tt,\nand, when \\ z\\ < 1, this analytic function may he represented by the\nsei'ies\n\nV\n\nr(a + n)r(b + n) r c + n) .n !\n\nThe symbol F(a, h; c; z) will, in future, be used to denote this\nfunction divided by r( .)r(6)/r(c).\n\n\\Subsection{14}{5}{1}{The continuation of the hyper geometric series.}\n\nTo obtain a representation of the function F (a, b; c; z) in the form\nof series convergent when j 2 | > 1, we shall employ the integral\nobtained in \\hardsectionref{14}{5}. If -D be the semicircle of radius p on the left of\nthe imaginary axis with centre at the origin, it may be shewn* by the\nmethods of § 14'o that\n\nV a + s)V h + s)T -s)\n\nJd r c + s)\n\nas p- x, provided that j arg - z) \\ < tt, \\ z \\ > 1 and p-><xi in\nsuch a way that the lower bound of the distance of D from poles of the\nintegi and is a positive number (not zero).\n\nHence it can be proved (as in the corresponding work of \\hardsectionref{14}{5}) that,\nwhen I arg -z)\\ < 7r and \\ z', > 1,\n\n1 r r a + s)r(b + s)T -s)\n\n\\ V r(a+7i)r(l -c + a + n) sin ( c- a - n) tt /\\ x- -h ~ rZo r (1 + w)\nr (1 - 6 + ft + n) cos n-rr sin (b - ft - n) it\n\n  T(b + n)r l-c + b + n) sin (c - 6 - ?i) tt f \\\n\nn=o r (1 + n) r (1 - ft + 6 + n) cos nir sin (ft - 6 - w) tt\n\nthe expressions in these summations being the residues of the\nintegrand at the points s = - a- n, s = - b - n respectively.\n\nIt then follows at once on simplifying these series that the analytic\n\n* In considering the asymptotic expansion of the integrand when | s [\nis large on the contour or on D, it is simplest to transform T (a +\ns), V (b + s), T c + s) by the relation of \\hardsubsectionref{12}{1}{4}.\n\n%\n% 289\n%\n\ncontinuation of the series, by which the hypergeometric function was\noriginally defined, is given by the equation\n\nr(c) \"\"' '- ' r(a-c) -(- r' - ( >i- +;i- + )\n\n1 0 - c) where arg (- z)\\ < tt.\n\nIt is readily seen that each of the three terms in this equation is a\nsolution of the hypergeometric equation (see \\hardsectionref{14}{4}).\n\nThis result has to be modified when a - 6 is an integer or zero, as\nsome of the poles of r a + s)r h + s) are double poles, and the\nright-hand side then may involve logarithmic terms, in accordance with\n1 43.\n\nCorollary. Putting h = c, we see that, if | arg - z)\\ < n,\n\nr (a) z)-\" = -. f \"' r a+s) r ( -s) ( - zyds, 'ZniJ \\ xt\n\nwhere (1 - )~<'- -l as 2-*.0, and so the value of [ arg(l - z) \\ which\nis less than tt always has to be taken in this equation, in virtue of\nthe cut (sec i:; 14'1) from to -f-oo caused by the inequality | arg( -\nz) \\ < n.\n\n14*52. Barnes' lemma that, if the 'path of integration is curved so\nthat the poles of T y - s)T b - s) lie on the right uf the path and\nthe poles of T (a + s) r (/3 + s) lie on the left*, then\n\nWrite / for the expression on the left.\n\nIf C be defined to be the semicircle of radius p on the right of the\nimaginary axis with centre at the origin, and if p-s-oo in such a way\nthat the lower bound of the distance of C from the poles of r (y - s)\nr (5 - s) is positive (not zero), it is readily seen that\n\nT a + s)T \\& + s)T y-s)T b-s) = - ''' '\n\n= 0[..' - +>+ - exp -2 1/( )l J, as ] s |- -oo on the imaginary axis\nor on C.\n\nHence the original integral converges; and / - -Oasp-a-oc, when (a +\n/3-|-y-|-S- 1)<0.\n\nThus, as in \\hardsectionref{14}{5}, the integral involved in 7 is - 2ni times the sum\nof the residues of the integrand at the poles oiT y - s)T b - s);\nevaluating these residues we gett\n\n/= i r( a + y+%)rO + y + ? ) TT I V a + b + n)T + b + n)\n\na=oV n + ) T + y-8 + 7l) sin(S-y)7r,,=o T (?i+l) r (1 -f-S-y + w)\nsin(y-S)7r*\n\n* It is supposed that a, /3, y, 5 are such that no pole of the first\nset coincides with any pole of the second set.\n\nt These two series converge \\hardsubsectionref{2}{3}{8}).\n\nW. M. A. 19\n\n%\n% 290\n%\n\nAnd so, using the result of 12\"14 freely, by \\hardsubsectionref{14}{1}{1} :\n\n\\ 7rr(l-a-/3-y -5) r T (a + d) T (3 + 5) r(a + y ) rO + y) )\n\nsin(y-8)7r |r(l-a-y)r(l-/3-y) T (1 - a -8)~r (1 - -8)J\n\nr(a+y)r( + y)r(a + g)r( + a) f r, ro,\n\n- r(a+/J + y + 8)sm(a + + y + 5).sin(y-8). \" ( + ) ' \" ('\n\n-sin (a + S) 77 sin 04-S)7r|.\n\nBut 2sin(fi+y)7rsiu(/3 + y)7r-2sin(a + S)7rsin (3 + S)7r\n\n= cos (a - /3) TT - cos (a + /3 + 2y) tt - cos (a - jS) tt + cos (a +\n+ 28) tt\n\n= 2sin(y-8)7r sin(a+/3 + y + S)7r.\n\nTherefore Vja + y)n ym-\\ + ) V )\n\n (a + + y + S)\n\nwhich is the required result; it has, however, only been prt)ved when\n\n (o + /3 + y + 8-l)<0;\n\nhut, )y the theory of analytic continuation, it is true throughout the\ndomain through which both sides of the equation are analytic functions\nof, say, a: and hence it is true for all values of a, /ii, y, 8 for\nwhich none of the poles of r (a + s) r (/3 + s), qua function of s,\ncoincide with any of the poles of r (y - s) r (8 - s).\n\nCorollary. Writing s + k., a - k, \\$-k, y + k, 8 + k in place of s, a,\n/3, y, 8, we see that the result is still true when the limits of\nintegration are -;, + cx) i, where k is any real constant.\n\n14 \"53. The connexion between hypergeometrie functions of z and of \\\n-z. We hav§ seen that, if | arg ( - s) | < tt,\n\nr(c) ' ' ' 2ni j \\ x,- T c + s) \" '\n\n= . \\ \\ r-.\\ T a t)Y h-irt)T s-t)V c-a-h-t)dt\\\n\n'' TTi J \\ x i l TTl J ~k-x i )\n\n.T c-a)T c-b) ' by Barnes' leinma.\n\nIf k be so chosen that the lower bound of the distance between the s\ncontour and the t contour is positive (not zero), it may be shewn that\nthe order of the integrations* may be interchanged.\n\nCarrying out the interchange, we see that if arg (1 -z) be given its\nprincipal value,\n\nT(C'-a)T c-h)T a)r b)F a, b; c; 2)/r (c)\n\n= s- / r a + t)r b+t)r c-a-b~t) -. r s-t)ri-s)(~zYds dt\n\n T lJ-k-Jii 'ZtvI J -jci\n\n1 f-k+oci\n\n= r-. I r a + t)r b+t)r c~a-b-t)r -t) i-zy dt.\n\n2ni J -A-K/\n\n* Methods similar to those of \\hardsubsectionref{4}{5}{1} may be used, or it may be proved\nwithout much difficulty that conditions established by Bromwich,\nInfinite Series, % 177, are satisfied.\n\n%\n% 291\n%\n\nNow, when I arg (1 -k) \\ < Stt and | I -z\\ < 1, this last integral may\nbe evaluated by the methods of Barnes' lemma \\hardsubsectionref{14}{5}{2}); and so we\ndeduce that\n\nr c-a)r c-b)T a)rib)F a,b;c;z)\n\n= r c)r a)r b)T c-a-b) F a, b; a + b-c + l; l-z)\n\n+ r c)r c - a) r (c-b) r a + b - c) I -zy-'\"-\" F c- a, c-b; c-a-b + l;\nz),\n\na result which shews the nature of the singularity of F a, b; c; z)\nat z=.\n\nThis result has to be modified if c - a - 6 is an integer or zero, as\nthen\n\nY a-- t) V b->r t) T c - a -b - t)T -t)\n\nhas double poles, and logarithmic terms may appear. With this\nexception, the result is valid when | arg -z)\\ < tt, | arg (1 - 2); <\ntt.\n\nTaking | s | < 1, we may make 2 tend to a real value, and we see that\nthe result still holds for real values of 2 such that < 2 < 1.\n\n\\Section{14}{6}{Solution of Riemann's equation by a contour integral.}\n\nWe next proceed to establish a result relating to the expression of\nthe liypergeometric function by means of contour integrals.\n\nLet the dependent variable u in Riemann's equation \\hardsectionref{10}{7}) be\nreplaced by a new dependent variable defined by the relation\n\nu = (z - aY z - bf (z - c)y I.\n\nThe differential equation satisfied by / is easily found to be\n\nd f 1 + a a' l+ -§' 1-f - 7) dl dz- \\ z - a z - h z - c ] dz\n\n( g + /3 + 7) (g + + ry + 1) + Sa (g + /?' + 7' - 1)1 z - a) z - 0) z\n- c)\n\nwhich can be written in the form\n\nQ(z) -[ X-2)Q' z)+R z)]f\n\n+ li ( - 2) (X - 1 ) (/' (z) - (X-DR (z)] 1 = 0,\n\nwhere / \\=l-ot- -j = a' + ' + y',\n\niQ(z) z-a)(z-h) z-c),\n\n(R(z) = X a' +/3 + ry) z-b) z-c).\n\nIt must be observed that the function / is not analytic at x, and\nconsequently the above differential equation in / is not a case of the\ngeneralised hypergeometric equation.\n\nWe shall noiu sheiu that this differential equation can be satisfied\nby an integral of the form\n\n1=1 t- ay'+ +y- (t - 6)-+ '+y-i (t - c)-+ -y -1 z - )- - -y dt, J c\n\njirovlded that C, the contour of integration, is suitably cJiosen.\n\n19-2\n\n%\n% 292\n%\n\nFor, if we substitute this value of / in the differential equation,\nthe con- dition* that the equation should be satisfied becomes\n\nj (t- ay+ +y-' t - by+ '+y-' t - cY+p+y'-' z - t)-''- -y--Kdt = 0,\n\nJ c where\n\nir = (\\ - 2) |q (z) + t- z) Q' (z) + l(t- zj Q\" z)\n\n+ (t-z) R(z) + (t-z)R'(z)]\n\n= ( 2) Q (t) -it- zy] -it-z) [R (t) -a- zy s ( ' + /3 + 7)1\n\n= - (1 + a + /3 + 7) ( - a) ( - 6) (i - c)\n\n+ S (a + /9 + 7) ( - ) ( - c) t - z).\n\nf dV It follows that the condition to be satisfied reduces to -7- dt =\n0, where\n\nJ c dt\n\nv=(t- ay+ +y (t - by+ '+y (t - cy+ +y (t - )-(i+-+p+v .\n\nThe integral / is therefore a solution of the differential equation,\nwhen C is such that V resumes its initial value after t has described\nC.\n\nNow\n\nV= t- ay'+ +y-' (t - by+ '+y-' (t - cy+ +y-' [z - t)-''- -y U,\n\nwhere U = (t- a) t -b) t- c) (z - ty\\\n\nNow Z7 is a one-valued function of t; hence, if C be a closed\ncontour, it must be such that the integrand in the integral / resumes\nits original value after t has described the contour.\n\nHence finally any integral of the type\n\n(z-ay(z-by(z - c)y \\ (t-ay+y+''-\\ t-b)y+''+ '-' t-cy+ y'-' z-ty''~ -y\ndt,\n\nJC\n\nwhere C is either a closed contour in the t-plane such that the\nintegrand resumes its initial value after t has described it, or else\nis a simple curve such that V lias the same value at its termini, is a\nsolution of the differential equation of the general hypergeometric\nfunction.\n\nThe reader is referred to the memoirs of Pochhammer, Math. An)i. xxxv.\n(1890), pp. 495-526, and Hob.son, Phil. Trans. 187 a (1896), pp.\n443-531, for an account of the methods by which integrals of this type\nare transformed so as to give rise to the relations of \\hardsubsectionref{14}{5}{1} and\n14-53.\n\nExample 1. To deduce a real definite integral which, in certain\ncircumstances, represents the hypergeometric series.\n\n The iliEferentiations imder the sign of integration are legitimate\n\\hardsectionref{4}{2}) if the path C does not depend on z a3d does not pass through\nthe points a, b, c, z; if C be an infinite contour or if C passes\nthrough the points a, b, c or z, further conditions are necessary.\n\n%\n% 293\n%\n\nThe hypergeometric series F a, b; c; z) is, as already shewn, a\nsolution of the differential equation defined by the scheme\n\nr 00 1 \\\n\nP a zy\n\n\\ \\ -c b c- a- b ] If in the integral\n\nwhich is a constant multiple of that just obtained, we make 6 -x\n(without paying attention to the validity of this process), we are led\nto consider\n\n/ t'''' t-\\ y- - t-zydt.\n\nNow the limiting form of V in question is\n\nand this tends to zero at t= 1 and = cc, provided R (c) > R(b)>0.\n\nWe accordingly consider / t\"~'= t - Vf-''-' t-z)~\" dt, where z is not*\npositive and greater tlum 1.\n\nIn this integral, write t = u~; the integral becomes\n\n/ ? ''-' (1-jt)' -''-' (l-M2)- 0??<. .'\n\nWe are therefore led to expect that this integral may be a solution of\nthe differential equation for the hypergeometric series.\n\nThe reader will easily see that if R (c) > R b)> 0, and if arg u = arg\n(1 - m) =0, while the branch of l-uz is specified by the fact that\n(1-m2)- 1 as m- 0, the integral just found is\n\nT b)r c-b)\n\n  (, \\&; c;z .\n\nThis can be proved by expandingf (1 - s)-a in ascending powers of z\nwhen | 3 | <1 and using § 12 \"41.\n\nExample 2. Deduce the result of \\hardsubsectionref{14}{1}{1} from the preceding example.\n\n\\Subsection{14}{6}{1}{Determination of an integral which represents TODO}\n\nWe shall now shew how an integral which represents the particular\nsolution i ' \\hardsectionref{14}{3}) of the hypergeometric difterential equation can\nbe found.\n\nWe have seen \\hardsectionref{14}{6}) that the integral\n\nl= z- df [z~bf z - cy ( t-a)P+y+- '-\\ t-b)y+<'+P'- (t-c)'' +\n+y'-Ht-z)-<'~ -ydt\n\nsatisfies the difl:erential equation of the hypergeometric function,\nprovided C is a closed contour such that the integrand resumes its\ninitial value after t has described C. Now the singularities of this\nintegrand in the plane are the points a, b, c, z; and after describing\nthe double circuit contour \\hardsubsectionref{12}{4}{3}) symbolised by (6 +, c-h, 6 -, c\n- ) the integi-and returns to its original value.\n\n* This ensures that the point t - ljz is not on the path of\nintegration, t The justification of this process by \\hardsectionref{4}{7} is left to\nthe reader.\n\n%\n% 294\n%\n\nNow, if z lie iu a circle whose centre is, the circle not containing\neither of the points h and c, we can choose the path of integration so\nthat t is outside this circle, and so \\ z - a\\ < i\\ t - a\\ for all\npoints t on the path.\n\nNow choose arg(2 - a) to be numericall ' less than it and arg(i - 6),\nai*g(2-c) so that they reduce to* arg(a - 6), arg(a-c) when z- a\\ fix\narg( - a), arg (< - 6), arg (< - c) at the point iV at which the path\nof integration starts and ends; also choose arg t - z) to reduce to\narg t - a) when z- a.\n\nThen (z-bf = (a-bf |l +/3 (j ' ) + ...j-,\n\n(.-c)V=( -o)' l+ (i ?) + ...l, and since we can expand (t-z)~' ~°~'\ninto an absolutely and uuifornily convergent series\n\nwe may expand the integral into a series which converges absolutely.\n\nMultiplying up the absolutely convergent series, we get a series of\ninteger powers of z - a multiplied by (s - a) . Consequently we must\nhave\n\nWe can define P '''\\ P \\ P '\\ F y\\ P ' by double circuit integrals in\na similar manner.\n\n\\Section{14}{7}{Relations between contiguous hypergeometric functions.}\n\nLet P z) be a solution of Riemann's equation with argument z,\nsingularities a, h, c, and exponents a, a', /3, j3', y, 7'. Further\nlet P(z) be a constant multiple of one of the six functions P *,\nTODO.\nLet TODO denote the function\nwhich is obtained by replacing two of the exponents, I and m, in P 2)\nhy I + 1 and m - 1 respectively. Such functions P;+i, i\\ i (z) are\nsaid to be contiguous to P (z). There are 6 x 5 = -30 contiguous\nfunctions, since I and m may be any two of the six exponents.\n\nIt was first shewn by Riemannf that the function P(z) and any tivo of\nits contiguous functions are connected by a linear relation, the\ncoeffi,cients in which are polynomials in z.\n\nThere will clearly be 5 x 30 x 29 = 435 of these relations. To shew\nhow to obtain them, we shall take P z in the form\n\nF z) = z- ay (z - hY (z - c)y f t- ay+y+' '- (t - 6)v+' + -\n\nJ c\n\n(t - cY+ +y'-' (z - ty- -y dt,\n\nwhere C is a double circuit contour of the type considered in \\hardsubsectionref{14}{6}{1}.\n\n* The values of arg (a-b), arg (a - c) being fixed.\n\nt Abh. der k. Ges. der Wiss. zu Gottingen, 1857; Gauss had previously\nobtained 15 rehitions between contiguous hypergeometric functions.\n\n%\n% 295\n%\n\nFirst, since the integral round G of the differential of any function\nwhich resumes its initial value after i has described C is zero, we\nhave\n\n= [ I- (t - ay+ +y (t - by ' y-Ht - cY+ +y'-' t - zy- - -y] dt. J c dt\n\nOn performing the differentiation by differentiating each factor in\nturn,\n\nwe get\n\n(a' + + y)P + (a + ' + y-l) Pa-+,, '-, + (a + (3 + y'-l) Pa'+i,y-i\n\n\\ (a + /3 + 7) p\n\nConsiderations of symmetry shew that the right-hand side of this\nequation can be replaced by\n\nThese, together with the analogous formulae obtained by cyclical\ninter- change* of (a, a, a) with (6, /3, ') and (c, 7, 7'), are six\nlinear relations connecting the hypergeometric function P with the\ntwelve contiguous functions\n\nPa+], '-l, -I p+i y'-i, -/y+i,a\\ l, -ta-],v'-l5 -Lfi+i a'-l, y~\\, '~\\\ni -I a.'+l, '- 1) -I a'4-],Y'\\ i, i '4.),-y'\\ i, -t j3'+l, a'-l > ''\ny'+I, a'- 1 ) -*7'+l, '- 1-\n\nNext, writing t - a = (t- h) + (6 - ), and usingf Pa'\\ i to denote the\nresult of writing a' - 1 for a' in P, we have\n\nP = P..\\ :,,.+:- (6- )P.-:.\n\nS-imilarly P = P \\ i,y'+i + (c - a) Pa'-i-\n\nEliminating Pa-i from these equations, we have\n\n c-h)P + (a - c) Pa-\\ :, vi + (b- a) Pa'-.,y-,, = 0. This and the\nanalogous formulae are three more linear relations con- necting P with\nthe last six of the twelve contiguous functions written above.\n\nNext, writing ( - ) = ( - a) - ( - a), we readily find the relation\n\nP = P +:, v'-i - ( - )\" ' ( - f y ( - 0\n\nJc which gives the equations\n\n( \\ a)-i P - ( - 6)- P +,, Y--: = ( - h)- [P- z- c)- Py+, a'-i\n\n= Kz - c)-' [P- z- a)-' Pa+i, \\ i .\n\n* The interchange is to be made only in the integrands; the contour C\nis to remain unaltered.\n\nt Pa'-l is not a function of Riemann's type since the sum of its\nexponents at a, h, c is not unity.\n\n%\n% 296\n%\n\nThese are two more linear equations between P and the above twelve\ncontiguous functions. *\n\nWe have therefore now altogether found eleven linear relations between\nP and these twelve functions, the coefficients in these relations\nbeing rational functions of 2. Hence each of these functions can be\nexpressed linearly in terms of P and some selected one of them; that\nis, between P and any two of the above functions there exists a linear\nrelation. The coefficients in this relation will be rational functions\nof z, and therefore will become polynomials in z when the relation is\nmultiplied throughout by the least common multiple of their\ndenominators.\n\nThe theorem is therefore proved, so far as the above twelve contiguous\nfunctions are concerned. It can, without difficulty, be extended so as\nto be established for the rest of the thirty contiguous functions.\n\nCorollary. If functions be derived from P by replacing the exponents\na, a, /3, /3', y, y\n\nby a+p, a' + g, /3 + r, jS'+s, y + t, y' + x, where p, q, r, s, f, u\nare integers satisfying the\n\nrelation\n\np- -q + r + s + t + u=0,\n\nthen between P and any two such functions there exists a linear\nrelation, the coefficients in which are polynomials in z.\n\nThis result can be obtained by connecting P with the two functions by\na chain of intermediate contiguous functions, writing down the linear\nrelations which connect them with P and the two functions, and from\nthese relations eliminating the intermediate contiguous functions.\n\nMany theorems which will be established subsequently, e.g. the\nrecurrence-formulae for the Legendre functions \\hardsubsectionref{15}{2}{1}), are really\ncases of the theorem of this article.\n\nREFERENCES. C. F. Gauss, Ges. Werke, in. pp. 12.3-163, 207-229. E. E.\nKuMMER, Journal fur Math. xv. (1836), pp. 39-83, 127-172. G. F. B.\nRiemann, Ges. Math. Werke, pp. 67-84. E. Papperitz, Math. Ann. xxv.\n(1885), pp. 212-221. S. PiNCHERLE, Rend. Accad. Lincei (4), iv.\n(1888), pp. 694-700, 792-799. E. Y. Barxes, Proc. London Math. Soc.\n(2), vi. (1908), pp. 141-177. Hj. Mellin, Acta Soc. Fennicae, xx.\n(1895), No. 12.\n\nMiscellaneous Examples.\n\n1. Shew that\n\nF a, h + \\; c; z)-F a, b; c; z) = - F a + l, h + l; c + l; z).\n\n2. Shew that if o is a negative integer while /3 and y are not\nintegers, then the ratio F(a, IB; a + /3 + l -y; \\ - .v)-7-F a,; y;\nA') is independent of x, and find its value.\n\n%\n% 297\n%\n\ndP d P\n\n3. If P iz) be a hypergeometrie function, express its derivates -,-\nand -- linearly in\n\ndP\n\nterms of P and contiguous functions, and hence find the linear\nrelation between P, -j-,\n\nd'-P and -TV, i.e. verify that P satisfies the hypergeometrie\ndifterential equation.\n\n4. Shew that i j, j; 1; 4 (1 -z)) satisfies the hypergeometrie\nequation satisfied by jP(|, I; 1; z). Shew that, in the left-hand\nhalf of the lemniscate \\ z z) | = j, these two functions are equal;\nand in the right-hand half of the lemniscate, the former function is\nequal to F \\, |; 1; 1 -2).\n\n5. \\ i Fu, =F a +,h; c; .r), / \\ =i (a - 1, h; c; x), determine the\n15 linear relations with polynomial coefficients which connect F a, h;\nc; x) with pairs of the six functions Fa, Fa-, F,,, F,\\, F,, F,\\ .\n\\addexamplecitation{Gauss.}\n\n6. Shew that the hypergeometrie equation\n\nx(x-l/J - y-(a+ + l)x ' + a i/ =\n\nis satisfied by the two integrals (suppo.sed convergent)\n\n[\\ \\ -\\ l-z)y- -' l-xz)-''dz J\n\nand ['/-i(l-2)\"-i' l-(l- )2 ~\"rf2.\n\n.' \"\n\n7. Shew that, for values of x between and 1, the solution of the\nequation\n\nis AF a,i; i; \\ --Ixy-l + B l-2x) F h a + l), h fi + l); |; l-2xy-,\n\nwhere A, B are arbitrary constants and TODO represents the\nhypergeometric series.\n\n\\addexamplecitation{Math. Trip. 1896.}\n\n8. Shew that\n\nJim|F(,/3,y,..)- J (-),;r(y-a)r(y- )r( )r( ) ' J\n\n\\ r(y-a- )r(y ) (y-a) (y- )\n\nwhere h is the integer such that k R (a + - y)<k- .\n\n(This specifies the manner in which the hj'pergeometric function\nbecomes infinite when .r- -l -0 provided that o-f |3-y is not an\ninteger.) \\addexamplecitation{Hardy.}\n\n9. Shew that, when i? (y - a - /S) < 0, then\n\n-/3-y\n\n- -l\n\nT y)n'' -y\n\n \"( 4- -y)r(a)r( )\n\nas '/i -x; where S denotes the sum of the first n terms of the series\nfor F a, /3; y; 1).\n\n(M. J. M. Hill, Proc. London Math. Soe. (2), v.)\n\n%\n% 298\n%\n\n10. Shew that, ii i/i, y-i be indeijeiident sokitions of\n\n 2- 1- -.\n\nthen the oreneral sohition of\n\nis z = Ay - Byiy.i- Cyi', where J, B, C are constants.\n\n\\addexamplecitation{Appell, Comptes Rendus, xci.}\n\n11. Deduce from example 10 that, if + ft + | = c,\n\n F(a h- r- r)\\ \\ = \\ rW\\ r(2c-l) - T 2a + 7>) F ia + b+n)T 2b+7i),,\n\n'' ' '' r 2a)T 2b)T a + b)n=o nl T c + n)T 2c- 1+n) *' '\n\n\\addexamplecitation{Clausen, Journal fiir Math, iii.}\n\n12. Shew that, if | | <i and j x \\ -s) j <|,\n\nF 2a, 2/3; a+/3 + *; x = F a, /3; a+ + l; 4.r(l-.r) . \\addexamplecitation{Kummer.}\n\n13. Deduce from example 12 that\n\n14. Shew that, if co = e ' ' and i (a) < 1,\n\ni (a,3a-l; 2a; \" - ) = 3 '' '* exp [K Sa - 1) | |,\n\ni (,3a-l; 2a; -co) =3 - exp W (1 -3a) M | .\n\n\\addexamplecitation{Watson, Quarterly Journal, xhi.}\n\n15. Shew that\n\nV 2 ) 2 -rj> -r\\ j ..y V9; r(|)r('/i + f)\n\n(Heymann, Zeitschrift fur Math, und Phys. XLiv.)\n\n16. If il-xY+ -y F 2a,2;2y; x) = + Bx + C:'f- + Dx +..., shew that\n\ni (a, /3; y+; ) i (y-a, y-/3; y+l; x)\n\ny+l (7+l)(7 + i-) (y+*)(y + f)(7+|)\n\n(Cayley, PAz7. Mag. (4), xvi. (1858), pp. 356-357. See also Orr, Camb.\nPhil. Trans, xvii. (1899), pp. 1-15.)\n\n17. If the function F a, ji, /3', y; .*;, y) be defined by the\nequation\n\ni (a,,/3', y; x,y) = \\ - \\ \\ i' -\\ \\ ~xc)y-''-\\ \\ - ux)-\\ l-uy)- '\ndu,\n\nr (a) r (y - a) j\n\nthen shew that between F and any three of its eight contiguous\nfunctions\n\ni (a±l), F ii± ), F ii'±l), F y±\\ \\\n\nthere exists a homogeneous linear equation, whose coefficients are\npolynomials in x and y.\n\n\\addexamplecitation{Le Vavasseur.}\n\n%\n% 299\n%\n\n18. If y - a - iS < 0, shew that, a.s x - 1-0,\n\nand that, if -0-/3 = 0, the corresponding approximate formula is\n\n\\addexamplecitation{Math. Trip. 1893.}\n\n19. Shew that, when \\ x\\ < 1,\n\n/(2 +,0 +,a:-,0-) 1 1 fl\n\n= \\,r/' sin OTT sin (y - a) TT . ' - \" - \"V (a, /3; y; ),\n\nwhere c denotes a point on the straight line joining the points 0, x,\nthe initial arguments of v - x and of v are the same as that of .>;,\nand arg (1 - j/) -*-0 as v- 0.\n\n\\addexamplecitation{Pochhammer.}\n\n20. If, when \\ arg (1 -x)\\ < 2n,\n\nK x)=-r T -s)Ti; + s)\\ \\ ' xYds,\n\nLTTl J \\ y,,\n\nand, when | arg.*; | < 27r,\n\nl-lZl J \\ K,-\n\nby changing the variable s in the integral or otherwise, obtain the\nfollowing relations : K (.r) = A\" (1 - ), if I arg (1 - :f) I <\n\nK l-x) = K'(x), if|argj;|<7r.\n\nK x) = l - .r)-4 A' ( -, if i arg (1 - .r) \\ < n.\n\nK l-x) x-h K f\"--, if I arg.r | <7r.\n\nK' x) = x 2 / ' (Ijx), if I arg.r |'< tt.\n\nA\" (1 - a;) = (1 - X) - i A\" ( \\ J\\ - \\ \"), if j arg (1 - .x-) I < -\n\\addexamplecitation{Barnes.}\n\n21. With the notation of the preceding example, obtain the following\nresults :\n\n11=0 [ 'I- )\n\n2 K' x)= - l f lt- j'- - log -4log 2 + 4 (1 - 1 + -- .\n\nwhen \\ x\\ < l, | arg .i? | < tt; and\n\niT ( ) = + i ( - ) - 5 a: (l/.r) + ( - ) - 2 ' (1/:??),\n\nwhen j arg - x)\\ < ir, the ambiguous sign being the same as the .sign\nof / (x).\n\n\\addexamplecitation{Barnes.}\n\n%\n% 300\n%\n\n22. Hypergeometric series in two variables are defined by the\nequations F, a;, ';y; .r, y) = 2 \"Xn f\" '\"J/'S\n\nF, (a; /3, '; y, y;,r, y) = 2 '-, x y .\n\n-ts a,a,,; y; x, y)= 2, --,-\\ x 'y\"\n\n n( n Pm Pn,( ??l . n i y i,1\n\nFUa,;y,y';.,y) .XpV ' '\"'\" '' where a, = a(a + l). ..(a + m - 1), and\n2 means 2 2 .\n\n?n, n m=0 =0\n\nObtain the differential equations\n\nc\"F. d'F ?Ft ?F\n\n-(l-)8 +y(l-)5j;5 + r-( +e+l)- 5;j'-* -. /-,=0,\n\nd F d F dF;\n\n.il-o:)- +y Hy- a + + l)x]j -a F, = 0,\n\nand four similar equations, derived from these by interchanging x with\ny and a, /3, y with a', 3', y when a', ', y occur in the corresponding\nseries.\n\n\\addexamplecitation{Appell, Comptes Rendus, xc.} 23. If a is negative, and if\n\na= -V + a,\n\nwhere v is an integer and a is positive, shew that\n\nr (x) r (a)\n\nu D (-)\"( -l)(a-2) ... (a-%), where = - - - - ' - - \" ' G( -n),\n\n\" i (*/ = - . \\addexamplecitation{Hermite, Joiirnal mr Math, xcii.}\n\nx+n \\ 1 . /\n\n24. When a < 1, shew that\n\nT x)T a-x) I \\ l Rn\n\nT a) n=\\ X + n n=\\ X - a - n''\n\nwhere (-) a(a + l) ... (a + .-l)\n\n7i !\n\n25. When a > 1, and v and a are respectively the integral and\nfractional parts of a, shew that\n\nT x)T a-x) G x)p.,\\ - (?( ')p, r(a) =i .r + ?i =i . r-a - n\n\n-G x) + + ...+ f'-'X '\\ \\ X - a X-a-\\ .r-a-i + lj'\n\n%\n% 301\n%\n\nwhere (?( )=(l-? (l -- ) ... (l \\ . \\ )\n\nV a/ V a+l/ \\ a + v - lj\n\najjj \\ (-)\"a(a+l)... (a + -l)\n\nIt,;\n\n\\addexamplecitation{Hermite, Journal fiir Math, xcil.} 26. If\n\n/ (T, \\ r - '(jZ + + n-l) ., x x+l)(7/ + v + n-l)( + v + n)\n\n./ (.r, y, .)- 1 - C, - - -,) + C.3 3,( + 1) ( +,)( ., + i) - ...,\n\nwhere n is a positive integer and C'i, C2, ... are binomial\ncoefficients, shew that\n\nf (T y, r(y)rCy- -H/ )r(.r-n;)r(y+?0\n\n./H .y. ) Y y-x)T y + n)V :6)V x-irV n)'\n\n(Saalschiitz, Zeitschrift fur Math. xxxv.; a number of similar\nresults are given by Dougall, Proc. Edinburgh Math. Soc. xxv.)\n\nshew that, when liib + e -,a - ) > 0, then\n\ni (a,a-5+l, -c + l'; S, e; l)=2- ..A P W \" \" - ' ' ' ' ' r(8-\na)r(f-ia)r( + ia)r(S + e-a-l)\n\n(A. C. Dixon, P/'oc. London Math. Soc. xxxv.)\n\n28. Shew that, if R (a) < .if, then\n\n; f a(a+l)... (a-l-n- l)l,.,,, . r(l-3a)\n\n(Morley, Proc. London Math. Soc. xxxiv.) 2!). If\n\n[' / '....-I (1 \\ .,.)>-iy-i (1 \\ )A-. (1 -a,yy--J->'dxdi/ = B(i,J,\nX-, m), J i> J i>\n\nshew, by integrating with respect to jc, and also with respect to i\nthat B i,j, /, m) is a symmetric function of i+J,j + i\\ / + + in,\n/n+i.\n\nDeduce that\n\nF a,ld,y; fi, f; l) r (8) F ( ) T (6 + 6 - a -/3-y)\n\nis a symmetric function of 8, f, S + e - a - /i, 8 + e - - y, 8 + e -\ny - a.\n\n(A. ('. Dixon, Proc. London Math. Soc. (2), II. (1905), jjp. 8-16. For\na proof of a special case by Barnes' methods, see Barnes, Quarterly\nJournal, XLI. (1910), pp. 136-140.)\n\n30. If\n\nx ~ il-x f'\"- d\" I\n\n/ = i (-, a +;.; y, .r) = - - y- - W ( x) \\\n\nshew that, when n is a large positive integer, and 0< .r < 1,\n\n  =, - (sin, )i-V(cos0)V- -icos (2u + a)( -i,r(2y-l) + o( 1 ),\n\nwhere .r = sin2 .\n\n(This result is contained in the great memoir by Darboux, \"Sur\nI'approxi- mation des fonctions de trfes grands nombres,\" Journal de\nMath. (3), iv. (1878), pp. 5-56, 377-416. For a systematic development\nof hyper- geometric functions in which one (or more) of the constants\nis large, see Camh. Phil. Trans, xxii. (1918), pp. 277-308.)\n", "meta": {"hexsha": "5a85fd946f95b98f74eba1ebae67a4cd7df20a0e", "size": 39125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch14.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-ch14.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-ch14.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": 28.026504298, "max_line_length": 176, "alphanum_fraction": 0.6225942492, "num_tokens": 14144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6251601860230567}}
{"text": "\\section{Factorization in Polynomial Rings}\r\n\\begin{theorem}\\label{ufd_poly}\r\n    Let $R$ be a UFD, then $R[X]$ is also a UFD.\r\n\\end{theorem}\r\n\\begin{remark}\r\n    One can apply this recursively to show that the polynomial ring in $n$ variables over a UFD is a UFD.\r\n\\end{remark}\r\nIn particular, $\\mathbb Z[X]$ is a UFD and $\\mathbb C[X_1,\\ldots,X_n]$ is a UFD.\\\\\r\nIn this section, we shall always assume that $R$ is a UFD.\r\nIt is an integral domain, so it has a field of fraction $F$, so $R[X]\\subset F[X]$ which is a UFD since it is a ED.\r\n\\begin{definition}\r\n    The content of a polynomial $f(X)=a_0+a_1X+\\cdots+a_nX^n$ for $a_i\\in R$ is $c(f)=\\gcd(a_0,\\ldots,a_n)$.\r\n    We say $f$ is primitive if $c(f)$ is a unit, i.e. the coefficients are coprime.\r\n\\end{definition}\r\n\\begin{lemma}\\label{poly_content}\r\n    1. Any prime element in $R$ is also prime in $R[X]$.\\\\\r\n    2. If $f,g\\in R[X]$ are primitive polynomials, then $fg$ is also primitive.\\\\\r\n    3. If $f,g\\in R[X]$, then $c(fg)=c(f)c(g)$ up to associates.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    1. Given a prime $p\\in R$, so $R/(p)$ is an integral domain.\r\n    For $a\\in R$, let $\\tilde{a}\\in R/(p)$ be its image under the quotient map.\r\n    Define $\\theta:R[X]\\to R/(p)[X]$ by\r\n    $$a_0+a_1X+\\cdots+a_nX^n\\mapsto \\tilde{a}_0+\\tilde{a}_1X+\\cdots+\\tilde{a}_nX^n$$\r\n    which is a homomorphism.\r\n    So for $p|fg$ where $f,g\\in R[X]$, we have $\\theta(fg)=0$, so $\\theta(f)\\theta(g)=0$.\r\n    But $R/(p)[X]$ is an integral domain since $R/(p)$ is.\r\n    Hence WLOG $\\theta(f)=0$, so $p|f$.\\\\\r\n    2. If $f,g$ are primitive but $fg$ is not, then there is some irreducible $p\\in R$ that divides $fg$.\r\n    Since $R$ is a UFD, $p$ is prime in $R$, hence is prime in $R[X]$ by 1, hence $p|f$ or $p|g$, contradiction to their primitivity.\\\\\r\n    3. Write $f=c(f)f_0$, so $f_0$ is primitive.\r\n    Do the same to $g$ gives $g=c(g)g_0$ for a primitive $g_0$, so $fg=c(f)c(g)(f_0g_0)$.\r\n    But $f_0g_0$ is primitive by 2, so $c(fg)=c(f)c(g)$ up to associates.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Take a polynomial $f$ in $F[X]$, then we can write $f=ab^{-1}f_0$ where $f_0\\in R[X]$ where $a,b\\in R,b\\neq 0$ and $f_0$ is primitive.\r\n    We can just take $b$ to be a common multiple of the denominators (since $F$ is the field of fractions of $R$) and the rest follows.\r\n\\end{remark}\r\n\\begin{lemma}\\label{primitive_div_fof}\r\n    Let $f,g$ be polynomials in $R[X]$ and $g$ is primitive, then if $g|f$ in $F[X]$, then $g|f$ in $R[X]$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $g|f$ in $F[X]$, then $f=gh$ with $h\\in F[X]$.\r\n    Write $h=ab^{-1}h_0$ for $a,b\\in R,b\\neq 0$ and $h_0\\in R[X]$ is primitive.\r\n    So $bf=agh_0$, then by taking content $bc(f)=a$, so $h=c(f)h_0\\in R[X]$ which is what we wanted.\r\n\\end{proof}\r\n\\begin{lemma}[Gauss's Lemma]\\label{gauss_poly}\r\n    Let $R$ be a UFD with field of fraction $F$.\r\n    Suppose $f\\in R[X]$ be primitive and irreducible in $R[X]$, then $f$ is irreducible in $F[X]$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Assume that $\\deg f>0$ since otherwise $f$ has to be a constant.\r\n    Then in this case $f$ is not a unit in $F[X]$.\r\n    Suppose we can write $f=gh$ for $g,h\\in F[X]$ with $\\deg g,\\deg h>0$.\r\n    Replacing $g,h$ by $\\lambda g$ and $\\lambda^{-1}h$ for some $\\lambda\\in F^\\times$, we can assume WLOG that $g\\in R[X]$ and is primitive.\r\n    So by the Lemma \\ref{primitive_div_fof}, $g|f$ in $R[X]$, so $h\\in R[X]$, contradiction.\r\n\\end{proof}\r\n\\begin{lemma}\\label{prime_fof}\r\n    Let $g\\in R[X]$ be primitive and is prime in $F[X]$, then $g$ is prime in $R[X]$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Suppose $f_1,f_2\\in R[X]$ and $g|f_1f_2$, then $g|f_1$ or $g|f_2$ in $R[X]$, but by Lemma \\ref{primitive_div_fof} $g|f_1$ or $g|f_2$.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Theorem \\ref{ufd_poly}]\r\n    Let $f\\in R[X]$, write $f=c(f)f_0$ where $f_0$ is primitive.\r\n    Since $R$ is a UFD, we can write $c(f)$ as a product of irreducibles.\r\n    Also, $f_0$ can also be written as a product of irreducibles by induction on its degree.\r\n    So it suffices to show that every irreducible in $R[X]$ is prime.\r\n    Take $f\\in R[X]$ irreducible, then either $f$ is constant or $f$ must be primitive.\\\\\r\n    For a constant $f$, then $f$ is prime in $R$, so it is prime in $R[X]$ by the first part of Lemma \\ref{poly_content}.\\\\\r\n    For a primitive $f$, combining Lemma \\ref{gauss_poly} and Lemma \\ref{prime_fof} gives the result.\r\n\\end{proof}\r\n\\begin{theorem}[Eisenstein's Criterion]\r\n    Let $R$ be a UFD and $f=a_0+\\cdots+a_nX^n\\in R[X]$ is primitive.\r\n    Suppose $p\\in R$ is irreducible and $p\\nmid a_n$ but $p|a_i,0\\le i\\le n-1$ and $p^2\\nmid a_0$, then $f$ is irreducible.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose $f=gh$ where $g,h\\in R[X]$ are not unit.\r\n    Since $f$ is primitive, $g,h$ both have positive degree.\r\n    Write $g(X)=r_0+\\cdots+r_kX^k$ and $h(X)=s_0+\\cdots+s_lX^l$ where $k+l=n$.\r\n    Now $a_n=r_ks_l$, so $p\\nmid r_k,p\\nmid s_l$.\r\n    Also $a_0=r_0s_0$, so exactly one of $r_0,s_0$ is divisible by $p$ since $R$ is a UFD.\r\n    Assume WLOG $p|r_0$.\r\n    Choose $j$ such that $p|r_0,\\cdots,p|r_{j-1}$ but $p\\nmid r_j$.\r\n    Note that we can choose this since $p\\nmid r_k$, in particular $j\\le k<n$.\r\n    But\r\n    $$a_j=r_0s_j+r_1s_{j-1}+\\cdots+r_js_0\\in r_js_0+(p)$$\r\n    So $a_j$ is not divisible by $p$ since $R$ is a UFD, so $p\\nmid a_j$, contradiction.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider $f(X)=X^3+2X+5\\in\\mathbb Z[X]$.\r\n    If $f$ is reducible, then it must has a root, which is impossible since the only possibilities of root are $\\pm 1,\\pm 5$.\r\n    By Guass's Lemma, this is also irreducible in $\\mathbb Q$.\r\n    Hence $\\mathbb Q[X]/(f)$ is a field since $\\mathbb Q[X]$ is a PID and $f$ is irreducible.\r\n\\end{example}\r\n\\begin{example}\r\n    1. Let $p$ be a prime number, then the polynomial $X^n-p$ is irreducible by Eisenstein's criterion, hence it is also irreducible in $\\mathbb Q[X]$, so again $\\mathbb Q[X]/(X^n-p)$ is a field.\\\\\r\n    2. Let $f(X)=X^p+\\cdots+X+1\\in\\mathbb Z[X]$ where $p$ is prime.\r\n    Although we cannot apply Eisenstein's criterion directly, we can do a substitution.\r\n    \\begin{align*}\r\n        f(X+1)&=(X+1)^p+\\cdots+(X+1)+1=\\frac{(X+1)^p-1}{(X+1)-1}\\\\\r\n        &=X^p+\\binom{p}{1}X^{p-1}+\\cdots+\\binom{p}{p-2}X+\\binom{p}{p-1}\r\n    \\end{align*}\r\n    where we can apply Eisenstein's criterion to see that $f(X+1)$ is irreducible, hence $f(X)$ is also irreducible.\r\n\\end{example}", "meta": {"hexsha": "ceb06a88117dd2ce13aba23d4a2b144dffed2226", "size": 6408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/poly.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": "11/poly.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": "11/poly.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": 61.0285714286, "max_line_length": 198, "alphanum_fraction": 0.6290574282, "num_tokens": 2379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.6250863519019488}}
{"text": "\\section{Invariant Measures}\r\n\\begin{definition}\r\n    A measure is a tuple $(\\lambda_i)_{i\\in I}$ with $\\lambda_i\\ge 0$ for all $i\\in I$.\\\\\r\n    A measure $\\lambda$ is invariant (or stationary/equilibrium) if $\\lambda P=\\lambda$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $(X_n)_{n\\ge 0}\\sim\\operatorname{Markov}(\\lambda,P)$.\r\n    Suppose $\\lambda$ is invariant.\r\n    Then $(X_{n+m})_{n\\ge 0}$ is also $\\operatorname{Markov}(\\lambda,P)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Quite obvious, but let's check.\r\n    For any $i$ we have, by definition,\r\n    $$\\mathbb P[X_m=i]=(\\lambda P^m)_i=\\lambda_i$$\r\n    So the initial distribution of $(X_{n+m})_{n\\ge 0}$ is $\\lambda$.\r\n    Also, conditional on $X_{n+m}=i$, by the Markokv property of $(X_n)$, $X_{n+m+1}$ is independent of $X_m,\\ldots,X_{n+m}$ and it has distribution $(p_{ij})_{j\\in I}$.\r\n\\end{proof}\r\n\\begin{theorem}\\label{power_inv}\r\n    Suppose $I$ is finite.\r\n    If there is some $i\\in I$ such that $p_{ij}^{(n)}\\to\\pi_j$ as $n\\to\\infty$ for any $j\\in I$, then $(\\pi_j)$ is an invariant distribution.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It is obviously a distribution as\r\n    $$\\sum_{j\\in I}\\pi_j=\\sum_{j\\in I}\\lim_{n\\to\\infty}p_{ij}^{(n)}=\\lim_{n\\to\\infty}\\sum_{j\\in I}p_{ij}^{(n)}=1$$\r\n    since $I$ is finite.\r\n    To see it is invariant,\r\n    \\begin{align*}\r\n        \\pi_j&=\\lim_{n\\to\\infty}p_{ij}^{(n)}=\\lim_{n\\to\\infty}p_{ij}^{(n+1)}=\\lim_{n\\to\\infty}\\sum_{k\\in I}p_{ik}^{(n)}p_{kj}=\\sum_{k\\in I}p_{kj}\\lim_{n\\to\\infty}p_{ik}^{(n)}\\\\\r\n        &=\\sum_{k\\in I}p_{kj}\\pi_k=(\\pi P)_j\r\n    \\end{align*}\r\n    again because $I$ is finite.\r\n\\end{proof}\r\n\\begin{remark}\r\n    The theorem fails in general for infinite $I$.\r\n    Take for example the simple symmetric random walk on $\\mathbb Z^d$.\r\n    We have $p_{ij}^{(n)}\\to 0$ as $n\\to\\infty$ for any $i,j\\in\\mathbb Z^d$ but $(0,0,0,\\ldots)$ is not a distribution (even though it is invariant).\r\n\\end{remark}\r\n\\begin{example}\r\n    Take\r\n    $$P=\\begin{pmatrix}\r\n        1-\\alpha&\\alpha\\\\\r\n        \\beta&1-\\beta\r\n    \\end{pmatrix}$$\r\n    We already know that\r\n    $$p_{11}^{(n)}=\\begin{cases}\r\n        \\beta/(\\alpha+\\beta)+\\alpha(1-\\alpha-\\beta)^n/(\\alpha+\\beta)\\text{, if $\\alpha+\\beta>0$}\\\\\r\n        1\\text{, otherwise}\r\n    \\end{cases}$$\r\n    So if $\\alpha+\\beta\\notin\\{0,1\\}$, we have $p_{11}^{(n)}\\to\\beta/(\\alpha+\\beta)$, similarly\r\n    $$P^n\\to\\frac{1}{\\alpha+\\beta}\\begin{pmatrix}\r\n        \\beta&\\alpha\\\\\r\n        \\beta&\\alpha\r\n    \\end{pmatrix},n\\to\\infty$$\r\n    Hence $(\\beta/(\\alpha+\\beta),\\alpha/(\\alpha+\\beta))$ is an invariant distribution.\r\n\\end{example}\r\nUsually we cannot easily compute the entries of $P^n$ and take the limit to find an invariant distribution.\r\nHowever, there is an obvious other way to get one.\r\n\\begin{example}\r\n    Consider\r\n    $$P=\\begin{pmatrix}\r\n        0&1&0\\\\\r\n        0&1/2&1/2\\\\\r\n        1/2&0&1/2\r\n    \\end{pmatrix}$$\r\n    So if we want $\\pi P=\\pi$, it gives the set of linear equations\r\n    $$\\begin{cases}\r\n        \\pi_1=\\pi_3/2\\\\\r\n        \\pi_2=\\pi_1+\\pi_2/2\\\\\r\n        \\pi_3=\\pi_2/2+\\pi_3/2\r\n    \\end{cases}$$\r\n    which we can solve to get $\\pi_1=1/5,\\pi_2=\\pi_3=2/5$ which is indeed an invariant distribution.\r\n\\end{example}\r\n\\begin{definition}\r\n    For each state $k\\in I$, let $\\gamma_i^k$ be the expected time spent in the state $i$ between two visits to $k$, so\r\n    $$\\gamma_i^k=\\mathbb E_k\\sum_{n=0}^{T_k-1}1_{X_n=i}=\\mathbb E_k\\sum_{n=1}^{T_k}1_{X_n=i}$$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $P$ be irreducible and recurrent, then:\\\\\r\n    (a) $\\gamma_k^k=1$.\\\\\r\n    (b) $\\gamma^k=(\\gamma_i^k)_{i\\in I}$ is an invariant measure.\\\\\r\n    (c) $0<\\gamma_i^k<\\infty$ for all $i\\in I$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    (a) is obvious.\r\n    For (b), since $P$ is recurrent, we know $\\mathbb P_k[T_k<\\infty]=1$, so for $j\\neq k$,\r\n    \\begin{align*}\r\n        \\gamma_j^k&=\\mathbb E_k\\sum_{n=1}^{T_k}1_{X_n=j}=\\mathbb E_k\\sum_{n=1}^\\infty 1_{X_n=j,n\\le T_k}\\\\\r\n        &=\\sum_{n=1}^\\infty\\mathbb P_k[X_n=j,n\\le T_k]\\\\\r\n        &=\\sum_{j\\in I}\\sum_{n=1}^\\infty\\mathbb P_k[X_{n-1}=i,X_n=j,n\\le T_k]\\\\\r\n        &=\\sum_{j\\in I}\\sum_{n=1}^\\infty\\mathbb P_k[X_{n-1}=i,n\\le T_k]\\mathbb P[X_n=j|X_{n-1}=i]\\\\\r\n        &=\\sum_{j\\in I}p_{ij}\\sum_{n=1}^\\infty\\mathbb P_k[X_{n-1}=i,n\\le T_k]\\\\\r\n        &=\\sum_{j\\in I}p_{ij}\\sum_{n=1}^\\infty\\mathbb E_k[1_{X_{n-1}=i,n\\le T_k}]\\\\\r\n        &=\\sum_{j\\in I}p_{ij}\\mathbb E_k\\sum_{n=0}^{T_k-1}1_{X_n=i}\\\\\r\n        &=\\sum_{i\\in I}p_{ij}\\gamma_i^k=(\\gamma^kP)_j\r\n    \\end{align*}\r\n    For (c), as $P$ is irreducible, there is $n,m\\ge 0$ such that $p_{ik}^{(n)}>0,p_{ki}^{(m)}>0$.\r\n    So by (b) and (a),\r\n    $$\\gamma_i^k\\ge\\gamma_k^kp_{ki}^{(m)}=p_{ki}^{(m)}>0,1=\\gamma_k^k\\ge\\gamma_i^kp_{ik}^{(n)}\\implies \\gamma_i^k\\le\\frac{1}{p_{ik}^{(n)}}<\\infty$$\r\n    As desired.\r\n\\end{proof}\r\nThis theorem has a partial inverse.\r\n\\begin{theorem}\\label{inv_measure_exp}\r\n    Let $P$ be irreducible and $\\lambda$ be an invariant measure with $\\lambda_k=1$ for some $k$.\r\n    Then $\\lambda_i\\ge\\gamma_i^k$ for every $i$.\\\\\r\n    If in addition $P$ is recurrent, then $\\lambda=\\gamma^k$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Since $\\lambda$ is invariant, for $j\\neq k$,\r\n    \\begin{align*}\r\n        \\lambda_j&=\\sum_{i_1\\in I}\\lambda_{i_1}p_{i_1j}\\\\\r\n        &=\\sum_{i_1\\neq k}\\lambda_{i_1}p_{i_1j}+p_{kj}\\\\\r\n        &=\\sum_{i_1\\neq k}\\left( \\sum_{i_2\\neq k}\\lambda_{i_2}p_{i_2i_1}+p_{ki_1} \\right)p_{i_1j} +p_{kj}\\\\\r\n        &=\\cdots\\\\\r\n        &=\\sum_{i_1,\\ldots,i_n\\neq k}\\lambda_{i_n}p_{i_ni_{n-1}}\\cdots p_{i_1j}\\\\\r\n        &\\quad+\\left( p_{kj}+\\sum_{i_1\\neq k}p_{ji_1}p_{i_1k}+\\cdots\\sum_{i_1,\\ldots,i_{n-1}\\neq k}p_{ki_{n-1}}\\cdots p_{i_2i_1}p_{i_1j} \\right)\\\\\r\n        &\\ge p_{kj}+\\sum_{i_1\\neq k}p_{ji_1}p_{i_1k}+\\cdots\\sum_{i_1,\\ldots,i_{n-1}\\neq k}p_{ki_{n-1}}\\cdots p_{i_2i_1}p_{i_1j}\\\\\r\n        &=\\mathbb P_k[X_1=j,T_k\\ge 1]+\\mathbb P_k[X_2=j,T_k\\ge 2]+\\cdots+\\mathbb P_k[X_n=j,T_k\\ge n]\\\\\r\n        &=\\mathbb E_k\\left[ \\sum_{m=1}^{\\min\\{n,T_k\\}}1_{X_m=j} \\right]\\\\\r\n        &=\\mathbb E_k\\left[ \\sum_{m=0}^{\\min\\{n,T_k-1\\}}1_{X_m=j} \\right]\\\\\r\n        &\\to \\gamma_j^k,n\\to\\infty\r\n    \\end{align*}\r\n    which proves the first part of the theorem.\r\n    Now define $\\mu=\\lambda-\\gamma^k$ which is obviously also an invariant measure.\r\n    As $P$ is irreducible, for any $i$, there is some $n$ such that $p_{ik}^{(n)}>0$, therefore\r\n    $$0=\\mu_k=\\sum_{j=I}\\mu_jp_{jk}^{(n)}\\ge\\mu_ip_{ik}^{(n)}\\implies \\mu_i=0$$\r\n    Hence $\\mu=0$ which shows the second part.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The simple symmetric random walk on $\\mathbb Z$ is clearly irreducible and recurrent.\r\n    The measure $\\pi_i=1$ for all $i\\in\\mathbb Z$ is invariant.\r\n    By the theorem, every invariant measure are of the form $\\pi_i=a$ for all $i\\in\\mathbb Z$ for some fixed $a$.\r\n    Consequently, there is no invariant distribution on this Markov chain.\\\\\r\n    2. (non-example) The simple symmetric random walk on $\\mathbb Z^3$ has an invariant measure, but is not recurrent.\r\n\\end{example}\r\nNote that a recurrent $i\\in I$ does not necessarily have finite expected return time $m_i=\\mathbb E_i[T_i]$.\r\n\\begin{definition}\r\n    A recurrent state $i\\in I$ is positive recurrent if $m_i<\\infty$, and is null recurrent otherwise.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $P$ be irreducible, then the following are equivalent:\\\\\r\n    (a) Every state is positive recurrent.\\\\\r\n    (b) Some state is positive recurrent.\\\\\r\n    (c) $P$ admits an invariant distribution $\\pi$.\\\\\r\n    Moreover, when (c) holds, then $m_i=1/\\pi_i$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    (a) clearly implies (b).\r\n    Assuming (b) and choose positive recurrent $i\\in I$.\r\n    Now $\\gamma^i$ is an invariant measure and\r\n    $$\\sum_{j\\in I}\\gamma_j^i=m_i<\\infty$$\r\n    Therefore $\\pi_j=\\gamma_j^i/m_i$ defines an invariant distribution.\\\\\r\n    Assuming (c), then $\\forall k\\in I$, $\\pi_k=\\sum_{i\\in I}\\pi_ip_{ik}^{(n)}>0$ for some $n$ as $P$ is irreducible.\r\n    Fix any $k$ and set $\\lambda_i=\\pi_i/\\pi_k$, then $\\lambda$ is an invariant measure with $\\lambda_k=1$, therefore $\\lambda\\ge\\gamma^k$ by Theorem \\ref{inv_measure_exp}.\r\n    So\r\n    $$m_k=\\sum_{i\\in I}\\gamma_i^k\\le\\sum_{i\\in I}\\frac{\\pi_i}{\\pi_k}=\\frac{1}{\\pi_k}<\\infty$$\r\n    which means $k$ is positive recurrent.\r\n    Also, this means that if (c) holds, then $P$ has to be recurrent and the inequality has to be equality, that is $m_k=1/\\pi_k$.\r\n\\end{proof}\r\n\\begin{example}\r\n    There exists Markov chains with more than one linearly independent invariant measures.\r\n    Consider the general random walk on $\\mathbb Z$ with $p_{i,i+1}=p,p_{i,i-1}=q=1-p$ where $p\\notin \\{0,1/2,1\\}$.\r\n    Then the constant and $\\pi_i=(p/q)^i$ are both invariant measures but they are linearly independent.\r\n\\end{example}", "meta": {"hexsha": "fd51ea4e0bcf188098f5d8d48163ecbecefe1597", "size": 8710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/inv.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": "7/inv.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": "7/inv.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": 53.4355828221, "max_line_length": 177, "alphanum_fraction": 0.6136624569, "num_tokens": 3342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6250300365392257}}
{"text": "\\chapter{Integer Partitions}\n\\label{chap-partitions}\n\nAn (integer) partition $p = p(1) \\cdots p(n)$ is a weakly decreasing sequence of positive integers, which are called the \\emph{parts} of $p$. The \\emph{size} of a partition, denoted $\\size{p}$, is the sum of its parts. For convenience, we say that for $i > n$ the $i\\th$ part of $p$ is $0$ and write $p(i) = 0$. We say that a partition $p = p(1) \\cdots p(m)$ is contained in another partition $q = q(1) \\cdots q(n)$ if $p(i) \\le q(i)$ for all $i$. This partial order on partitions is simply the one of Young's lattice, namely containment of Ferrers diagrams. The \\emph{Ferrers diagram} of a partition $p = p(1) \\cdots p(m)$ is a visual representation of $p$ consisting of an arrangement of $p(1)$ cells in the first (topmost) row, $p(2)$ cells in the second row, and so on. An example of partition containment displayed through Ferrers diagrams is presented in Figure~\\ref{fig-ptn-ferrers}.\n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale={1/3}]\n\t\t\\ferrers{3,1}\n\t\t\\node at (5.5,-1) {$\\le$};\n\n\t\t\\begin{scope}[shift={(6,1)}]\n\t\t\t\\ferrers{4,2,1,1}\n\t\t\t\\ferrersfilled{3,1}\n\t\t\\end{scope}\n\n\t\t\\begin{scope}[shift={(5.5,-4)}]\n\t\t\t\\node at (-3,0) {$31$};\n\t\t\t\\node at ( 0,0) {$\\le$};\n\t\t\t\\node at (3.5,0) {$4211$};\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{An example partition containment presented by way of Ferrers diagrams.}\n\\label{fig-ptn-ferrers}\n\\end{figure}\n\nThe \\emph{conjugate} of a partition $p$ is the partition whose Ferrers diagram is the reflection of the Ferrers diagram of $p$ reflected along the anti-diagonal $y = -x$. An example of a partition and its conjugate is displayed in Figure~\\ref{fig-ptn-conjugate}.\n\\begin{figure}[ht]\n\\captionsetup{justification=centering,margin=1in}\n\t\\begin{tikzpicture}[scale={1/3}]\n\t\t\\ferrers{6,3,3,2,1}\n\t\t\\draw[dashed, gray] (1,0) -- ++(3.5,-3.5);\n\n\t\t\\begin{scope}[shift={(9,0.5)}]\n\t\t\t\\ferrers{5,4,3,1,1,1}\n\t\t\t\\draw[dashed, gray] (1,0) -- ++(3.5,-3.5);\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{The Ferrers diagram of a partition and its conjugate, both displayed with the anti-diagonal.}\n\\label{fig-ptn-conjugate}\n\\end{figure}\n\nGiven a finite set of partitions $S$, the unique smallest partition that contains each partition in $S$ is the partition whose $i\\th$ part is equal to the largest $i\\th$ part among all members of $S$. \n\\begin{observation}\n\\label{obs-ptn-join}\n\tIf $S$ is a finite set of partitions, then the smallest partition $p$ that is $S$-universal has $i\\th$ part given by\n\t\\[\n\t\tp(i) \n\t\t= \n\t\t\\max\\{q(i) \\st q \\in S\\}.\n\t\\]\n\\end{observation}\nThus, to construct the smallest $m$-universal partition for the set of all partitions, one must only observe that the largest $i\\th$ part among all partitions of size $m$ is $\\floor{m/i}$, meaning the unique smallest $m$-universal partition has $i\\th$ part equal to $\\floor{m/i}$ for all $i$.\n\n\\begin{theorem}\n\\label{thm-ptn-universal}\n\tThe unique smallest $m$-universal partition has size\n\t\\[\n\t\t\\phi(m)\n\t\t=\n\t\t\\floor{m/1} + \\floor{m/2} + \\cdots + \\floor{m/m}\n\t\t\\footnote{The sequence $\\phi$ appears as sequence \\OEISlink{A006218} in the OEIS~\\cite{sloane:the-on-line-enc:}}.\n\t\\]\n\\end{theorem}\nFigure~\\ref{fig-ptn-universal} displays the $24$-universal partition of size $\\phi(24) = 84$. In~\\cite{dirichlet:uber-die:}, Dirichlet shows that $\\phi(m) = m(\\log(m) + 2\\gamma-1) + \\Delta(m)$, where $\\gamma \\approx 0.5772$ is the Euler--Mascheroni constant and $\\Delta(m) = \\oO{\\sqrt{m}}$, and thus $\\phi(m) \\sim m \\log m$. The asymptotics of $\\Delta(m)$ are the subject of the \\emph{Dirichlet Divisor Problem}, which aims to find the smallest value $\\theta$ so that $\\Delta(m) = \\oO{m^\\theta}$. The best known bound is due to Huxley~\\cite{huxley:exponential-sums-and:}, who showed that $\\inf \\theta \\le 131/416 \\approx 0.3149$. \n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale={24/120}]\n\t\t\\ferrers{24,12,8,6,4,4,3,3,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1}\n\t\\end{tikzpicture}\n\\caption{The unique $24$-universal partition of size $\\phi(24) = 84$.}\n\\label{fig-ptn-universal}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Proper Classes of Partitions}\n\\label{sec-ptn-classes}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nIn this section, we show that any proper class of partitions admits universal partitions of linear size. For reference, some known or computed values of minimum sizes for universal partitions for various classes are presented in Appendix~\\ref{appendix-partitions}.\n\nWe require one more definition to discuss proper classes of partitions. We say that an \\emph{potentially infinite partition} $p$ is an infinite weakly decreasing sequence over the infinite ordered alphabet $\\{0 < 1 < \\cdots < \\omega\\}$, where $\\omega$ represents an infinite part. If $p(n) = \\ell > 0$ for each $n > N$, then we abbreviate $p$ as $p(1) \\cdots p(N) \\ell^\\omega$, where $\\ell^\\omega$ representing an infinite number of parts equal to $\\ell$. If $p(n) = 0$ for each $n > N$, then we abbreviate $p$ as $p(1) \\cdots p(N)$. Infinite partitions give way to infinite Ferrers diagrams, and we say that the \\emph{age} of a potentially infinite partition $p$, denoted $\\Age(p)$, is the set of finite partitions whose Ferrers diagrams embed into the Ferrers diagram of $p$ (the term \\emph{age} dates to Fra{\\\"i}ss{\\'e}~\\cite{fraisse:sur-lextension-:}). An example of containment of a finite Ferrers diagram into an infinite one, together with the corresponding set containment, is presented in Figure~\\ref{fig-ptn-age}.\n\n\\begin{figure}[ht]\n\\captionsetup{justification=centering}\n\t\\begin{tikzpicture}[scale={1/3}]\n\t\t\\ferrers{4,2,1,1}\n\t\t\n\t\t\\node at (6.5,-2) {$\\le$};\n\t\t\\begin{scope}[shift={(7.5,0.5)}]\n\t\t\t\\foreach \\d in {0.25, 0.50, 0.75} {\n\t\t\t\t\\filldraw[black] ({6+\\d},-0.5) circle [radius=0.05cm];\n\t\t\t\t\\filldraw[black] ({6+\\d},-1.5) circle [radius=0.05cm];\n\t\t\t\t\\filldraw[black] (1.5,-{6+\\d}) circle [radius=0.05cm];\n\t\t\t\t% \\filldraw[black] (2.5,-{6+\\d}) circle [radius=0.05cm];\n\t\t\t}\n\t\t\t\\ferrers{5,5,4,1,1}\n\t\t\t\\ferrersfilled{4,2,1,1}\n\t\t\\end{scope}\n\t\t\n\t\t\\begin{scope}[shift={(6.5,-6.5)}]\n\t\t\t\\node at (-3.5,0) {$4211$};\n\t\t\t\\node at ( 0  ,0) {$\\in$};\n\t\t\t\\node at ( 5  ,0) {$\\Age(\\omega \\omega 4 1^\\omega)$};\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\\caption{An example of containment of a finite Ferrers digram into an infinite one.}\n\\label{fig-ptn-age}\n\\end{figure}\n\nWe show that every proper class of partitions admits linear-size universal partitions in two parts. First, we show that every proper class of partitions is contained in an age of the form $\\Age(\\omega^k \\ell^\\omega)$ in Proposition~\\ref{prop-ptn-age-containment}, and then that every such age admits linear-size universal partitions in Theorem~\\ref{thm-ptn-universal-proper}.\n\\begin{proposition}\n\\label{prop-ptn-age-containment}\n\tFor any proper partition class $\\P$, there are nonnegative integers $k, \\ell$ such that $\\P \\subseteq \\Age(\\omega^k \\ell^\\omega)$.\n\\end{proposition}\n\\begin{proof}\n\tLet $\\ell$ be the largest integer such that $\\P$ contains the partition $\\ell^n$ for all $n$ and let $k$ be the largest integer such that $\\P$ contains $(\\ell+1)^k$. We claim that $\\P \\subseteq \\Age(\\omega^k \\ell^\\omega)$. For any partition $p \\in \\P$, we must have $p(n) \\le \\ell$ for each $n > k$, as otherwise $p$ contains $(\\ell+1)^n$, and as $\\P$ is closed downward, we would have $(\\ell+1)^n \\in \\P$, a contradiction. The condition that $p(n) \\le \\ell$ for each $n > k$ is precisely the condition that defines containment in $\\Age(\\omega^k \\ell^\\omega)$, and thus $p \\in \\Age(\\omega^k \\ell^\\omega)$, completing the proof.\n\\end{proof}\n\n\\begin{theorem}\n\\label{thm-ptn-universal-proper}\n\tLet $\\P = \\Age(\\omega^k \\ell^\\omega)$ be a class of partitions. Then for $m \\ge k\\ell$, the smallest $\\P_m$-universal partitions have size\n\t\\[\n\t\t\\u_{\\P}(m)\n\t\t= \n\t\t\\sum_{i=1}^{k} \\floor{\\frac{m}{i}} + \\sum_{i=1}^{\\ell} \\floor{\\frac{m}{i}} - k\\ell\n\t\\]\n\tand thus $\\u_{\\P}(m) = \\oTheta{m}$.\n\\end{theorem}\n\nBefore proving Theorem~\\ref{thm-ptn-universal-proper}, observe that if $P \\subseteq Q$ are sets of partitions and $q$ is a $Q$-universal partition, then $q$ is $P$-universal as well, as $q$ necessarily contains each partition in $P$. Thus, by proving that each age of the form $\\Age(\\omega^k \\ell^\\omega)$ admits universal partitions of linear size, Proposition~\\ref{prop-ptn-age-containment} implies that every proper partition class does as well.\n\n\\newenvironment{proof-of-thm-ptn-universal-proper}{%\n\t\\medskip\\noindent {\\it Proof of Theorem~\\ref{thm-ptn-universal-proper}.\\/}%\n}{%\n\t\\qed\\bigskip%\n}\n\\begin{proof-of-thm-ptn-universal-proper}\n\tBy Observation~\\ref{obs-ptn-join}, the unique smallest $\\P_m$-universal partition $P$ has its $i\\th$ part equal to the largest $i\\th$ part among all partitions in $\\P_m$. The only restriction on partitions in $\\P$ is that their $i\\th$ part is at most $\\ell$ for $i > k$, so we have\n\t\\[\n\t\tP(i)\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\floor{\\dfrac{m}{i}}                          & \\text{if $1 \\le i \\le k$,} \\\\\n\t\t\t\\min\\left\\{\\floor{\\dfrac{m}{i}}, \\ell\\right\\} & \\text{if $k  <  i \\le m$.}\n\t\t\\end{cases}\n\t\\]\n\tAs $\\floor{\\dfrac{m}{i}} \\ge \\ell$ if and only if $\\floor{\\dfrac{m}{\\ell}} \\ge i$, this may be simplified to\n\t\\[\n\t\tP(i)\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\floor{\\dfrac{m}{i}} & \\text{if $1 \\le i \\le k$,} \\\\\n\t\t\t\\ell                 & \\text{if $k  <  i \\le \\floor{\\dfrac{m}{\\ell}}$,} \\\\\n\t\t\t\\floor{\\dfrac{m}{i}} & \\text{if $\\floor{\\dfrac{m}{\\ell}} < i \\le m$.}\n\t\t\\end{cases}\n\t\\]\n\tThus, for $m \\ge k\\ell$, the size of $P$ is\n\t\\[\n\t\t\\size{P} \n\t\t= \n\t\t\\underbrace{\\floor{\\dfrac{m}{1}} + \\floor{\\dfrac{m}{2}} + \\cdots + \\floor{\\dfrac{m}{k}} + \\ell + \\ell + \\cdots + \\ell}_{\\text{$\\floor{\\dfrac{m}{\\ell}}$ terms}} + \\floor{\\dfrac{m}{\\floor{\\tfrac{m}{\\ell}}+1}} + \\cdots + \\floor{\\dfrac{m}{m}}.\n\t\\]\n\n\tThe sum of the parts $P(k+1), \\cdots, P(m)$ is equal to $\\sum_{i = 1}^{\\ell} \\floor{\\frac{m}{i}} - k\\ell$, as these correspond to the first $\\ell$ parts of the conjugate of $P$, which are $\\floor{\\dfrac{m}{i}}$ for $1 \\le i \\le \\ell$, and we need to subtract those cells that overlap with the first $k$ parts of $P$. As $m \\ge k\\ell$, we have both $\\floor{\\frac{m}{k}} \\ge \\ell$ and $\\floor{\\frac{m}{\\ell}} \\ge k$, and thus\n\t\\[\n\t\t\\size{P}\n\t\t= \n\t\t\\sum_{i=1}^{k} \\floor{\\frac{m}{i}} + \\sum_{i=1}^{\\ell} \\floor{\\frac{m}{i}} - k\\ell.\n\t\\]\n\tFor all $n$ and $j$, the inequality\n\t\\[\n\t\t\\log(j+1)n-j\n\t\t\\le\n\t\t\\sum_{i = 1}^{j} \\floor{\\frac{n}{j}} \n\t\t\\le \n\t\t\\left(\\log(j)+1\\right)n,\n\t\\]\n\tholds, and thus $\\size{P} = \\oTheta{m}$, as desired.\n\\end{proof-of-thm-ptn-universal-proper}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Concluding Remarks}\n\\label{sec-ptn-conclusion}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nObservation~\\ref{obs-ptn-join} establishes that the smallest $m$-universal partition is unique, and Theorem~\\ref{thm-ptn-universal} establishes its precise size for all $m$. For any proper class of partitions $\\P$, there are proper $m$-universal partitions for $\\P$ for all $m$ if and only if $\\P$ satisfies the joint-embedding property, which is equivalent to $\\P$ being the age of some potentially infinite partition $u$, as the following result of Fra{\\\"i}ss{\\'e} (which we have specialized to our context here) shows:\n\\begin{theorem}[Fra{\\\"i}ss{\\'e}~\\cite{fraisse:sur-lextension-:}; see also Hodges~{\\cite[Section 7.1]{hodges:model-theory:}}] \n\tThe following are equivalent for a class $\\P$ of integer partitions or compositions:\n\t\\begin{enumerate}\n\t\t\\item $\\P$ cannot be expressed as the union of two proper subclasses,\n\t\t\\item $\\P$ satisfies the \\emph{joint embedding property}, meaning that for every $a, b \\in \\P$ there is some $c \\in \\P$ such that $a, b \\le c$, and \n\t\t\\item $\\P = \\Age(u)$ for some word $u \\in (\\mathbb{P} \\cup \\{n^\\omega \\st n \\in \\mathbb{P}\\} \\cup \\{\\omega, \\omega^\\omega\\})^\\ast$.\n\t\\end{enumerate}\n\\end{theorem}\n\n", "meta": {"hexsha": "db4f7714dafe5fe375dfa29da67938ad29f9e430", "size": 11917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-partitions.tex", "max_stars_repo_name": "engenmt/doctoral-dissertation", "max_stars_repo_head_hexsha": "b5e2caee30ee40653be58ec190028fae9cfb2df6", "max_stars_repo_licenses": ["MIT"], "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-partitions.tex", "max_issues_repo_name": "engenmt/doctoral-dissertation", "max_issues_repo_head_hexsha": "b5e2caee30ee40653be58ec190028fae9cfb2df6", "max_issues_repo_licenses": ["MIT"], "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-partitions.tex", "max_forks_repo_name": "engenmt/doctoral-dissertation", "max_forks_repo_head_hexsha": "b5e2caee30ee40653be58ec190028fae9cfb2df6", "max_forks_repo_licenses": ["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.1868686869, "max_line_length": 1023, "alphanum_fraction": 0.6558697659, "num_tokens": 4063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.6250300288732089}}
{"text": "\\section{Task A}\n\\label{sec:task-a}\n\nAccording to equation \\eqref{eq:free-energy} in \\cite{Bonet2008}, the free energy\nfor compressible Neo-Hookean material is defined as follows:\n\\begin{equation} \\tag{6.27}\n  \\label{eq:free-energy}\n  \\Psi = \\frac{\\mu}{2} \\left( I_{C_{e}} - 3 \\right) - \\mu \\ln J_{e} +\n  \\frac{\\lambda}{2} \\left( \\ln J_{e} \\right)^{2}\n\\end{equation}\nwith \\(I_{C_{e}} = \\utilde{I} : \\utilde{C}_{e} \\) and the elastic Lame constants\n\\(\\mu = G = 0.5 E / (1+\\nu)\\), \\(\\lambda = E \\nu / (1 - 2\\nu) / (1+\\nu)\\).\n\nYield function of von Mises type:\n\\begin{equation}\n  \\label{eq:yield_func}\n  \\phi = \\sqrt{\\frac{3}{2}} \\left| \\utilde{\\overline{M}}_{dev} \\right|- \n    \\left( \\tau_{y} - H \\overline{\\varepsilon}_{p} \\right)\n\\end{equation}\nwith \\(\\overline{\\varepsilon}_{p} = \\int_{0}^{t} \\dot{\\gamma} \\, dt\\).\n\nMandel stress is defined as\n\\begin{equation}\n  \\label{eq:mandel}\n  \\utilde{\\overline{M}} = \\utilde{C}_{e} \\cdot \\widetilde{\\utilde{S}}\n\\end{equation}\nwith intermediate 2nd Piola-Kirchhoff stress defined as a pull-back of the\nKirchhoff stress to the intermediate configuration as follows:\n\\begin{equation}\n  \\label{eq:PK2int}\n  \\widetilde{\\utilde{S}} = \\utilde{F}_{e}^{-1} \\cdot \\utilde{\\tau} \\cdot\n  \\utilde{F}_{e}^{-T} = 2 \\frac{\\partial \\Psi}{\\partial \\utilde{C}_{e}}\n\\end{equation}\nand intermediate elastic deformation tensor\n\\begin{equation}\n  \\label{eq:Cint}\n  \\utilde{C}_{e} = \\utilde{F}_{p}^{-T} \\cdot \\utilde{C} \\cdot \\utilde{F}_{p}^{-1}\n\\end{equation}\nand plastic part of the deformation gradient\n\\begin{equation}\n  \\label{eq:F}\n  \\utilde{F} = \\utilde{F}_{e} \\cdot \\utilde{F}_{p}\n\\end{equation}\n\nLet us derive expression for \\(\\widetilde{\\utilde{S}}\\):\n\\begin{equation}\n  \\label{eq:PK2intDeriv}\n  \\widetilde{\\utilde{S}} = 2 \\frac{\\partial \\Psi}{\\partial \\utilde{C}_{e}} = \n  2 \\frac{\\partial \\Psi}{\\partial I_{C_{e}}} \\cdot\n  \\frac{\\partial I_{C_{e}}}{\\partial \\utilde{C}_{e}} +\n  2 \\frac{\\partial \\Psi}{\\partial J_{e}} \\cdot\n  \\frac{\\partial J_{e}}{\\partial \\utilde{C}_{e}}\n\\end{equation}\n\\begin{align}\n  \\frac{\\partial \\Psi}{\\partial I_{C_{e}}} &= \\frac{\\mu}{2} \\\\\n  \\frac{\\partial I_{C_{e}}}{\\partial \\utilde{C}_{e}} &= \\utilde{I} \\\\\n  \\frac{\\partial \\Psi}{\\partial J_{e}} &= - \\frac{\\mu}{J_{e}} + \n                                         \\frac{\\lambda}{J_{e}} \\ln J_{e} \\\\\n  \\frac{\\partial J_{e}}{\\partial \\utilde{C}_{e}} &= \\frac{J_{e}}{2} \\utilde{C}_{e}^{-1}\n\\end{align}\nTherefore,\n\\begin{equation}\n  \\label{eq:PK2intFinal}\n  \\widetilde{\\utilde{S}} = \\mu \\utilde{I} + \\left( \\lambda \\ln J_{e} -\n    \\mu \\right) \\utilde{C}_{e}^{-1}\n\\end{equation}\nAt this point we can assess the yield function. \nThe Kuhn-Tucker conditions are\n\\begin{equation}\n  \\label{eq:kuhn-tucker}\n  \\phi \\leq 0, \\quad \\dot{\\gamma} \\geq 0, \\quad \\dot{\\gamma} \\phi = 0 \n\\end{equation}\nThe evolution equation is of associative type:\n\\begin{equation}\n  \\label{eq:evolution}\n  \\overline{\\utilde{L}}_{p} = \\dot{\\gamma}\n  \\frac{\\partial \\phi}{\\partial \\overline{\\utilde{M}}} = \n  \\dot{\\gamma} \\sqrt{\\frac{3}{2}} \n  \\frac{\\overline{\\utilde{M}}_{dev}}{\\left| \\overline{\\utilde{M}}_{dev} \\right|} =\n  \\dot{\\gamma} \\utilde{\\nu}\n\\end{equation}\nApply backward Euler integration:\n\\begin{align}\n  \\frac{\\prescript{n+1}{}{\\utilde{F}_{p} -\\prescript{n}{}{\\utilde{F}_{p}}}}{\\Delta t}\n  \\prescript{n+1}{}{\\utilde{F}}_{p}^{-1} &= \\frac{\\Delta \\gamma}{\\Delta t} \n                                           \\prescript{n+1}{}{\\utilde{\\nu}} \\\\\n  \\utilde{I} - \\prescript{n}{}{\\utilde{F}}_{p} \\cdot\n  \\prescript{n+1}{}{\\utilde{F}}_{p}^{-1} &\\approx\n  \\Delta \\gamma \\prescript{n+1}{}{\\utilde{\\nu}}\n\\end{align}\nApply semi-explicit simplification \n\\(\\prescript{n+1}{}{\\utilde{\\nu}} \\approx \\prescript{n}{}{\\utilde{\\nu}}\\):\n\\begin{align}\n  \\utilde{I} - \\prescript{n}{}{\\utilde{F}}_{p} \\cdot\n  \\prescript{n+1}{}{\\utilde{F}}_{p}^{-1} &\\approx\n  \\Delta \\gamma \\prescript{n}{}{\\utilde{\\nu}} \\\\\n  \\prescript{n+1}{}{\\utilde{F}}_{p}^{-1} &\\approx\n  \\prescript{n}{}{\\utilde{F}}_{p}^{-1} \\left( \\utilde{I} -\n  \\Delta \\gamma \\prescript{n}{}{\\utilde{\\nu}} \\right)\n\\end{align}\nSolve the simplified local constitutive problem:\n\\begin{equation}\n  \\label{eq:local}\n  \\phi \\left( \\Delta \\gamma \\right) = \\sqrt{\\frac{3}{2}} \n  \\left| \\overline{\\utilde{M}}_{dev} \\right| - \\left[ \\tau_{y} - \n    H \\left( \\prescript{n}{}{\\overline{\\varepsilon}_{p}} + \\Delta \\gamma\\right) \\right]\n\\end{equation}\nwith \n\\begin{equation}\n  \\label{eq:Mexplicit}\n  \\overline{\\utilde{M}} = \\utilde{C}_{e} \\cdot \\widetilde{\\utilde{S}} = \n  \\utilde{C}_{e} \\left( \\utilde{F}_{p}^{-1} \\left( \\Delta \\gamma \\right),\n    \\utilde{C} \\right) \\cdot\n  \\widetilde{\\utilde{S}} \\left( \\utilde{C}_{e}\n    \\left( \\utilde{F}_{p}^{-1} \\left( \\Delta \\gamma \\right), \\utilde{C} \\right)\n  \\right)\n\\end{equation}\nusing Newton--Raphson method:\n\\begin{align}\n  \\phi \\left( \\Delta \\gamma_{n+1} \\right) &\\approx \n                                            \\phi \\left( \\Delta \\gamma_{n} \\right) +\n                                            \\frac{d \\, \\phi \\left( \n                                            \\Delta \\gamma_{n} \\right)}{d \\,\n                                            \\Delta \\gamma} \\blacktriangle \\gamma \n                                            = 0 \\\\\n  \\blacktriangle \\gamma &= - \\left[ \\frac{d \\, \\phi \\left( \n                          \\Delta \\gamma_{n} \\right)}{d \\, \\Delta \\gamma} \n                          \\right]^{-1} \\cdot \\phi \\left( \\Delta \\gamma_{n} \\right)\\\\\n  \\Delta \\gamma_{n+1} &= \\Delta \\gamma_{n} + \\blacktriangle \\gamma\n\\end{align}\nwhere the derivative of the yield function can be expanded to\n\\begin{equation}\n  \\label{eq:yield-deriv}\n  \\frac{d \\phi}{d \\gamma} = \\frac{\\partial \\phi}{\\partial \\overline{\\utilde{M}}} :\n  \\frac{\\partial \\overline{\\utilde{M}}}{\\partial \\utilde{C}_{e}} :\n  \\frac{\\partial \\utilde{C}_{e}}{\\partial \\utilde{F}_{p}^{-1}} :\n  \\frac{d \\utilde{F}_{p}^{-1}}{d \\Delta \\gamma} + \n  \\frac{\\partial \\phi}{\\partial \\Delta \\gamma}\n\\end{equation}\nwith \\(\\dfrac{\\partial \\phi}{\\partial \\Delta \\gamma} = - H\\) and the rest of\nthe derivatives given by equations (34)--(37) of \\cite{Ekh2016}, in which\n\\begin{equation}\n  \\label{eq:dSdCe}\n  \\frac{\\partial \\widetilde{\\utilde{S}}}{\\partial \\utilde{C}_{e}} = \n  \\frac{\\lambda}{2} \\utilde{C}_{e}^{-1} \\otimes \\utilde{C}_{e}^{-1} +\n  \\left( \\mu - \\lambda \\ln J_{e} \\right) \\utilde{C}_{e}^{-1} \\overline{\\otimes}\n  \\utilde{C}_{e}^{-1}\n\\end{equation}\nFinally, compute the 2nd Piola-Kirchhoff stress\n\\begin{equation}\n  \\label{eq:PK2final}\n  \\utilde{S} = \\utilde{F}_{p}^{-1} \\cdot \\widetilde{\\utilde{S}} \\cdot\n  \\utilde{F}_{p}^{-T}\n\\end{equation}\nand the material stiffness\n\\begin{equation}\n  \\label{eq:mat-stiff}\n  \\uutilde{C} = 2 \\frac{d \\utilde{S}}{d \\utilde{C}}\n\\end{equation}\n\\textit{Note: if computed numerically, \\(\\uutilde{C}\\) must be symmetrised to get\ncorrect element stiffness.}\n\nThe material model was implemented in Matlab and can be found in\n\\texttt{neo\\_hooke\\_plast.m} (see section \\ref{app:matlab-code}).\n\nFigure~\\ref{fig:sigma12-eps12} shows the test of the constitutive driver,\nwhere component of Cauchy stress plotted against\nengineering strain for the situation of uniaxial strain control\n\\(\\utilde{F} = F_{12} \\ubar{\\bm{e}}_{1} \\otimes \\ubar{\\bm{E}}_{2}\\).\n\\begin{figure}[th]\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=0.2,\n      xlabel = {\\( \\varepsilon_{12}\\), [-]},\n      ylabel = {\\( \\sigma_{12} \\), [MPa]},\n      ]\n      \\addplot table[skip first n=1] {data/sigma12_eps12.dat};\n    \\end{axis}\n  \\end{tikzpicture}  \n  \\caption{Cauchy stress component \\(\\sigma_{12}\\) versus strain\n    \\(\\varepsilon_{12} = F_{12} \\).}\n  \\label{fig:sigma12-eps12}\n\\end{figure}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../main\"\n%%% End:\n", "meta": {"hexsha": "37d742a8a5fe52801c85344fa4814056b4a25ea4", "size": 7870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sec/task_a.tex", "max_stars_repo_name": "iamrosk/large_elast_plast_deform", "max_stars_repo_head_hexsha": "62986469f7df01d6874f4a27b5887b7116c8a38a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T00:15:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T00:15:08.000Z", "max_issues_repo_path": "doc/sec/task_a.tex", "max_issues_repo_name": "iamrosk/large_elast_plast_deform", "max_issues_repo_head_hexsha": "62986469f7df01d6874f4a27b5887b7116c8a38a", "max_issues_repo_licenses": ["MIT"], "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/large_elast_plast_deform", "max_forks_repo_head_hexsha": "62986469f7df01d6874f4a27b5887b7116c8a38a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-14T03:27:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T01:44:26.000Z", "avg_line_length": 39.9492385787, "max_line_length": 87, "alphanum_fraction": 0.6048284625, "num_tokens": 2926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6250300162917812}}
{"text": "%!TEX root = ../Tibt.tex\n\n\\exercise{4.2}\n\n\\subsection*{(a)}\n\nThe linear discriminant functions are:\n\n\\begin{eqnarray*}\n    \\hat{\\delta}_k(x) & = & x^T \\hat{\\Sigma}^{-1} \\hat{\\mu}_k - \\frac{1}{2}\\, \\hat{\\mu}_k ^T \\hat{\\Sigma}^{-1}  \\hat{\\mu}_k + \\log\\, \\hat{\\pi}_k \\\\\n    \\hat{\\pi}_k & = & N_k / N\n\\end{eqnarray*}\nSo (a) follows directly from $\\hat{\\delta}_2(x) > \\hat{\\delta}_1(x)$. \n\n\n\\subsection*{(b), (c), (d)}\nLet's denote $\\mathbf{e}_{(1)}$ and $\\mathbf{e}_{(2)}$ the one-hot variables associated\nto the labels $g$. The coefficients $\\hat{\\beta}$ of the OLS regression with the bias\nterm included can be obtained by regressing $\\mathbf{y}$ against the demeaned\nversion of the original predictors:\n\\begin{eqnarray*}\n    \\hat{\\beta} & = & \\left(\\mathbf{X}_{dm}^T \\mathbf{X}_{dm}\\right)^{-1} \\,\n    \\mathbf{X}_{dm}^T \\mathbf{y} \\\\\n    \\mathbf{X}_{dm} & \\equiv &  \\mathbf{X} - \\mathbf{e} \\, \\hat{\\mu}^T \\\\\n    & = & \\mathbf{X} - (\\mathbf{e}_{(1)} + \\mathbf{e}_{(2)}) \\, \\hat{\\mu}^T \\\\\n    \\hat{\\mu} & \\equiv & \\frac{1}{N} \\mathbf{X}^T \\mathbf{e}\n\\end{eqnarray*}\nNotice that $\\hat{\\mu}$ is the vector of predictor means, regardless of the class.\nOn the other hand, the LDA covariance matrix is obtained as:\n\\begin{eqnarray*}\n    \\hat{\\Sigma} & = & \\frac{1}{N - 2} \\mathbf{X}_{r}^T \\mathbf{X}_r\n\\end{eqnarray*}\nwhere $\\mathbf{X}_{r}$ are the values of predictors centered around the class\naverages:\n\\begin{eqnarray*}\n    \\mathbf{X}_{r} & = &  \\mathbf{X} - \\mathbf{e}_{(1)}\\,\\hat{\\mu}_1^T - \\mathbf{e}_{(2)}\\,\\hat{\\mu}_2^T \\\\\n    \\hat{\\mu}_1 & \\equiv & \\frac{1}{N_1} \\mathbf{X}^T \\mathbf{e}_{(1)}\\\\\n    \\hat{\\mu}_2 & \\equiv & \\frac{1}{N_2} \\mathbf{X}^T \\mathbf{e}_{(2)}\n\\end{eqnarray*}\nWe have therefore:\n\\begin{equation*}\n\\mathbf{X}_{dm} = \\mathbf{X}_r + \\mathbf{e}_{(1)} \\left(\\hat{\\mu}_1 - \\hat{\\mu}\\right)^T\n + \\mathbf{e}_{(2)} \\left(\\hat{\\mu}_2 - \\hat{\\mu}\\right)^T\n\\end{equation*}\nBy construction, the residuals $\\mathbf{X}_r$ are orthogonal to $\\mathbf{e}_{(1)}$, \n$\\mathbf{e}_{(2)}$:\n\\begin{equation*}\n\\mathbf{X}_r^T \\,\\mathbf{e}_{(1)} = \\mathbf{X}_r^T \\,\\mathbf{e}_{(2)} = 0\n\\end{equation*}\nAlso:\n\\begin{eqnarray*}\n    \\mathbf{e}_{(k)}^T\\, \\mathbf{e}_{(k)} & = & N_k \\\\\n    \\mathbf{e}_{(1)}^T \\mathbf{e}_{(2)} & = & 0 \\\\\n    \\hat{\\mu} & = & \\frac{N_1}{N} \\hat{\\mu}_1 + \\frac{N_2}{N} \\hat{\\mu}_2    \n\\end{eqnarray*}\nHence:\n\\begin{eqnarray*}\n    \\mathbf{X}_{dm}^T \\mathbf{X}_{dm} & = & \\mathbf{X}_r^T \\mathbf{X}_r + \n    N_1\\,(\\hat{\\mu}_1 - \\hat{\\mu}) (\\hat{\\mu}_1 - \\hat{\\mu})^T + N_2\\,(\\hat{\\mu}_2 - \\hat{\\mu}) (\\hat{\\mu}_2 - \\hat{\\mu})^T  \\\\\n    & = & (N - 2)\\, \\hat{\\Sigma} + N_1 \\, \\left(\\frac{N_2}{N} \\hat{\\mu}_1 - \\frac{N_2}{N} \\hat{\\mu}_2\\right) \\left(\\ldots\\right) + N_2 \\, \\left(\\frac{N_1}{N} \\hat{\\mu}_2 - \\frac{N_1}{N} \\hat{\\mu}_1\\right) \\left(\\ldots\\right) \\\\\n    & = & (N - 2)\\, \\hat{\\Sigma} + \\frac{N_1\\,N_2}{N^2} (N_1 + N_2) \n        \\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)\\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)^T \\\\\n    & = & (N - 2)\\, \\hat{\\Sigma} + \\frac{N_1\\,N_2}{N} \n    \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right)\\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right)^T\n\\end{eqnarray*}\nConsider the general target encoding:\n\\begin{equation*}\n\\mathbf{y} = y_1\\, \\mathbf{e}_{(1)} + y_2\\, \\mathbf{e}_{(2)}\n\\end{equation*}\nWe have:\n\\begin{eqnarray*}\n\\mathbf{X}_{dm}^T \\mathbf{y} & = & N_1\\, y_1\\, (\\hat{\\mu}_1 - \\hat{\\mu}) + N_2\\, y_2\\, (\\hat{\\mu}_2 - \\hat{\\mu}) \\\\\n& = & \\frac{N_1}{N}\\, y_1\\, (N\\,\\hat{\\mu}_1 - N_1 \\hat{\\mu}_1  - N_2 \\hat{\\mu}_2) + \\frac{N_2}{N}\\, y_2\\, (N\\,\\hat{\\mu}_2 - N_1 \\hat{\\mu}_1  - N_2 \\hat{\\mu}_2) \\\\\n& = & \\frac{N_1 \\, N_2}{N} \\left(y_2 - y_1\\right) \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right)\n\\end{eqnarray*}\nTherefore:\n\\begin{eqnarray*}\n    \\hat{\\beta} & = & \\left((N - 2)\\, \\hat{\\Sigma} + \\frac{N_1\\,N_2}{N} \n    \\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)\\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)^T\\right)^{-1} \\frac{N_1 \\, N_2}{N} \\left(y_2 - y_1\\right) \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right) \\\\\n    & = &  \\left((N - 2)\\, \\hat{\\Sigma} + \\frac{N_1\\,N_2}{N} \n    \\hat{\\Sigma}_B\\right) ^{-1} \\frac{N_1 \\, N_2}{N} \\left(y_2 - y_1\\right) \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right)     \\\\\n    \\hat{\\Sigma}_B & \\equiv &  \\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)\\left(\\hat{\\mu}_1 - \\hat{\\mu}_2\\right)^T\n\\end{eqnarray*}\nThis proves (d) and, in particular, substituting $y_1 = - N / N_1$, $y_2 = N/N_2$\nyields the equation in the text. (c) is a direct consequence of this result.\n\n\n\\subsection*{(e)}\n\nAfter predictor demeaning:\n\\begin{equation*}\n\\hat{f} = \\hat{\\beta}_0 + \\hat{\\beta}^T x_{dm}\n\\end{equation*}\nthe OLS value $\\hat{\\beta}_0$ is the sample average of the response, which\nis zero with the encoding indicated in the text. Therefore:\n\\begin{eqnarray*}\n\\hat{f} & = & \\hat{\\beta}^T \\hat{\\Sigma}^{-1}\\left(x - \\hat{\\mu}\\right) \\\\\n   & \\propto & \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1\\right)^T \\hat{\\Sigma}^{-1}\\left(x - \\frac{N_1}{N} \\hat{\\mu}_1 - \\frac{N_2}{N} \\hat{\\mu}_2\\right) \\\\\n   & = & x^T \\hat{\\Sigma}^{-1} \\left(\\hat{\\mu}_2 - \\hat{\\mu}_1 \\right) - \n     \\frac{N_2}{N} \\hat{\\mu}_2^T \\hat{\\Sigma}^{-1} \\hat{\\mu}_2 +\n     \\frac{N_1}{N} \\hat{\\mu}_1^T \\hat{\\Sigma}^{-1} \\hat{\\mu}_1 + \n     \\frac{N_2 - N_1}{N} \\hat{\\mu}_1 ^T \\hat{\\Sigma}^{-1} \\hat{\\mu}_2\n\\end{eqnarray*}\nThis expression coincides with the one for LDA only when $N_1 = N_2$.\n", "meta": {"hexsha": "ec4cb92c999d09bc53222a0480140169922e7a17", "size": 5252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/Chapter4/ex_4_02.tex", "max_stars_repo_name": "pinoeottavio/ESLEx", "max_stars_repo_head_hexsha": "9d203da5b46c8d66ade827c237c738a35928af48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-16T22:33:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-16T22:33:48.000Z", "max_issues_repo_path": "notes/Chapter4/ex_4_02.tex", "max_issues_repo_name": "pinoeottavio/ESLEx", "max_issues_repo_head_hexsha": "9d203da5b46c8d66ade827c237c738a35928af48", "max_issues_repo_licenses": ["MIT"], "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/Chapter4/ex_4_02.tex", "max_forks_repo_name": "pinoeottavio/ESLEx", "max_forks_repo_head_hexsha": "9d203da5b46c8d66ade827c237c738a35928af48", "max_forks_repo_licenses": ["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.019047619, "max_line_length": 227, "alphanum_fraction": 0.5693069307, "num_tokens": 2367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6250300162917812}}
{"text": "\\subsection{Categorical limits}\\label{subsec:categorical_limits}\n\n\\begin{definition}\\label{def:comma_category}\\mcite[def. 2.3.1]{Leinster2016Basic}\n  Comma categories allow us to define morphisms between morphisms, which becomes useful in, for example, the concise definition of a limit in \\fullref{def:category_of_cones/limit}.\n\n  \\begin{thmenum}\n    \\thmitem{def:comma_category/variable} We first prove the most general construction. Let \\( F: \\cat{A} \\to \\cat{C} \\) and \\( G: \\cat{B} \\to \\cat{C} \\) be any two functors with a common codomain. We define their \\term{comma category} \\( (F \\downarrow G) \\) as follows:\n\n    \\begin{itemize}\n      \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(F \\downarrow G) \\) is the set of triples \\( (A, s, B) \\), where \\( A \\in \\cat{A} \\), \\( B \\in \\cat{B} \\) and \\( s: F(A) \\to G(B) \\).\n\n      \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( [F \\downarrow G]((A, s, B), (A', s', B')) \\) is the set of pairs\n      \\begin{equation*}\n        (f: A \\to A', g: B \\to B'),\n      \\end{equation*}\n      such that the following diagram commutes:\n      \\begin{equation}\\label{eq:def:comma_category/variable}\n        \\begin{aligned}\n          \\includegraphics[page=1]{output/def__comma_category.pdf}\n        \\end{aligned}\n      \\end{equation}\n\n      \\item The \\hyperref[def:category/composition]{composition of morphisms} is their pairwise composition, analogically to \\hyperref[def:product_category]{product categories}.\n\n      \\item The \\hyperref[def:category/identity]{identity morphism} on the object \\( (A, s, B) \\) is the identity pair \\( (\\id_A, \\id_B) \\).\n    \\end{itemize}\n\n    \\thmitem{def:comma_category/fixed} It is often the case where either \\( F \\) or \\( G \\) are constant. If, instead of \\( G \\), we are given an object \\( X \\) in \\( \\cat{C} \\), we use the constant functor \\( \\Delta_X^{\\cat{1}}: \\cat{1} \\to \\cat{C} \\) with domain the \\hyperref[def:universal_categories]{terminal category} \\( \\cat{1} \\), in order to use the comma category \\( (F \\downarrow \\Delta_X^{\\cat{1}}) \\).\n\n    We can thus simplify \\fullref{def:comma_category/variable} as follows:\n\n    \\begin{minipage}[t]{0.43\\textwidth}\n      \\begin{equation*}\n        (F \\downarrow X) \\coloneqq (F \\downarrow \\Delta_X^{\\cat{1}}).\n      \\end{equation*}\n\n      \\begin{itemize}\n        \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(F \\downarrow X) \\) is\n        \\begin{equation*}\n          \\set{ (A, s) \\given s: F(A) \\to X }\n        \\end{equation*}\n\n        \\item The \\hyperref[def:category/morphisms]{hom-set}\n        \\begin{equation*}\n          [F \\downarrow X]\\parens[\\Big]{ (A, s), (A', s') }\n        \\end{equation*}\n        is the set of \\( f: A \\to A' \\), such that\n        \\begin{equation}\\label{eq:def:comma_category/fixed/right}\n          \\begin{aligned}\n            \\includegraphics[page=2]{output/def__comma_category.pdf}\n          \\end{aligned}\n        \\end{equation}\n      \\end{itemize}\n    \\end{minipage}\n    \\begin{minipage}[t]{0.43\\textwidth}\n      \\begin{equation*}\n        (X \\downarrow G) \\coloneqq (\\Delta_X^{\\cat{1}} \\downarrow G)\n      \\end{equation*}\n\n      \\begin{itemize}\n        \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(X \\downarrow G) \\) is\n        \\begin{equation*}\n          \\set{ (s, B) \\given s: X \\to F(B) }\n        \\end{equation*}\n\n        \\item The \\hyperref[def:category/morphisms]{hom-set}\n        \\begin{equation*}\n          [X \\downarrow G]\\parens[\\Big]{ (s, B), (s', B') }\n        \\end{equation*}\n        is the set of \\( g: B \\to B' \\), such that\n        \\begin{equation}\\label{eq:def:comma_category/fixed/left}\n          \\begin{aligned}\n            \\includegraphics[page=3]{output/def__comma_category.pdf}\n          \\end{aligned}\n        \\end{equation}\n      \\end{itemize}\n    \\end{minipage}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:factors_through}\\mcite[133]{Knapp2016BasicAlgebra}\n  Consider a morphism \\( f: A \\to B \\). We say that \\( f \\) \\term{factors through} the object \\( X \\) if there exist morphisms \\( g: A \\to X \\) and \\( h: X \\to B \\) such that the following diagram commutes:\n  \\begin{equation}\\label{eq:def:factors_through}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/def__factors_through.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  If, given \\( g \\), \\( h \\) is unique or vice versa, we say that \\( f \\) \\term{uniquely factors through} \\( X \\). In some cases, for example in \\fullref{def:zero_morphisms/morphism}, \\( f \\) there exists unique \\( g \\) and \\( h \\) and neither of them must be given beforehand.\n\\end{definition}\n\n\\begin{definition}\\label{def:category_of_cones}\n  Let \\( D: \\cat{I} \\to \\cat{C} \\) be a \\hyperref[def:categorical_diagram]{diagram}.\n\n  \\begin{thmenum}\n    \\thmitem{def:category_of_cones/category} We define \\term{category of cones} to \\( D \\) as the \\hyperref[def:comma_category/fixed]{constant-functor comma category}\n    \\begin{equation*}\n      \\cat{Cone}(D) \\coloneqq \\underbrace{ (\\Delta^{\\cat{I}} \\downarrow D) }_{(\\Delta^{\\cat{I}} \\downarrow \\Delta^{\\cat{1}}_{D})},\n    \\end{equation*}\n    where \\( \\Delta^{\\cat{I}}: \\cat{C} \\to [\\cat{I}, \\cat{C}] \\) is the \\( \\cat{I} \\)-shaped \\hyperref[def:diagonal_functor]{diagonal functor} on \\( \\cat{C} \\).\n\n    \\thmitem{def:category_of_cones/cone} A \\( D \\)-\\term{cone} is simply a member of \\( \\cat{Cone}(D) \\).\n\n    Explicitly, a cone with \\term{vertex} \\( A \\in \\cat{C} \\) is a pair \\( (\\Delta^{\\cat{I}}_A, \\alpha) \\), where \\( \\Delta^{\\cat{I}}_A \\) is the constant functor at \\( A \\) and \\( \\alpha \\) is a natural transformation from \\( \\Delta^{\\cat{I}}_A \\) to \\( D \\).\n\n    Even more explicitly, a cone is a family of morphisms\n    \\begin{equation}\\label{eq:def:category_of_cones/cone}\n      \\seq{ \\alpha_k: A \\to D(k) }_{k \\in \\cat{I}}.\n    \\end{equation}\n    satisfying a simplified naturality condition (compared to \\eqref{eq:def:natural_transformation/diagram}). For every morphism \\( u: k \\to m \\) in \\( \\cat{I} \\), the following diagram must commute:\n    \\begin{equation}\\label{eq:def:category_of_cones/cone_nat}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__category_of_cones.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    Note that this diagram is very different from \\eqref{eq:def:comma_category/fixed/right}, they merely look similar.\n\n    \\thmitem{def:category_of_cones/limit} A \\term{limit cone} of the diagram \\( D \\) is a \\hyperref[def:universal_objects/terminal]{terminal object} of the cone category \\( \\cat{Cone}(D) \\).\n\n    Explicitly, \\( (L, \\lambda) \\) is limit cone if, for every cone \\( (A, \\alpha) \\), there exists a unique \\hyperref[eq:def:comma_category/fixed/right]{cone morphism} \\( l_A: (A, \\alpha) \\to (L, \\lambda) \\).\n\n    Even more explicitly, \\( (L, \\lambda) \\) is a limit cone if it satisfies the following \\hyperref[rem:limit_universal_mapping_property]{universal mapping property}:\n    \\begin{displayquote}\n      For every cone \\( (A, \\alpha) \\), there exists a unique morphism \\( l_A: A \\to L \\) such that following diagram commutes for every index morphism \\( u: k \\to m \\):\n      \\begin{equation}\\label{eq:def:category_of_cones/limit}\n        \\begin{aligned}\n          \\includegraphics[page=2]{output/def__category_of_cones.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{displayquote}\n\n    Thus, \\( \\alpha_k \\) \\hyperref[def:factors_through]{uniquely factors through} \\( L \\) for every \\( k \\in \\cat{I} \\). Furthermore, \\( l_A \\) is compatible with morphisms in \\( \\cat{I} \\) and does not depend on \\( k \\).\n\n    From \\fullref{thm:def:universal_objects/terminal} and \\fullref{thm:universal_objects_as_adjunctions/terminal} it follows that a limit, if it exists, is unique up to a unique isomorphism.\n\n    Without further context, we usually refer to \\( L \\) as the limit vertex and \\( (L, \\lambda) \\) as the limit cone. By \\enquote{the limit}, we usually mean the vertex \\( L \\).\n\n    \\thmitem{def:category_of_cones/cocone} \\hyperref[thm:categorical_principle_of_duality]{Dually}, a \\( D \\)-\\term{cocone} with vertex \\( A \\) is a family of morphisms\n    \\begin{equation}\\label{eq:def:category_of_cones/cocone}\n      \\seq{ \\alpha_k: D(k) \\to A }_{k \\in \\cat{I}}.\n    \\end{equation}\n    satisfying the naturality condition that for every morphism \\( u: k \\to m \\) in \\( \\cat{I} \\), the following diagram must commute:\n    \\begin{equation}\\label{eq:def:category_of_cones/cocone_nat}\n      \\begin{aligned}\n        \\includegraphics[page=3]{output/def__category_of_cones.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    \\thmitem{def:category_of_cones/colimit} A \\term{colimit cocone} of the diagram \\( D \\) is an \\hyperref[def:universal_objects/initial]{initial object} of the cocone category \\( (D \\downarrow \\Delta) \\).\n\n    There are two major differences compared to limits: a colimit cocone is an initial object, not a terminal object, and its underlying comma category is \\( (D \\downarrow \\Delta) \\), not \\( (\\Delta^{\\cat{I}} \\downarrow D) \\).\n\n    The analogous diagram to \\eqref{eq:def:category_of_cones/limit} is exactly its \\hyperref[thm:categorical_principle_of_duality]{opposite}:\n    \\begin{equation}\\label{eq:def:category_of_cones/colimit}\n      \\begin{aligned}\n        \\includegraphics[page=4]{output/def__category_of_cones.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    In particular, \\( \\alpha_k \\) \\hyperref[def:factors_through]{uniquely factors through} \\( L \\) for every \\( k \\in \\cat{I} \\).\n\n    Without further context, we usually refer to \\( L \\) as the colimit vertex and \\( (L, \\lambda) \\) as the colimit cocone. By \\enquote{the colimit}, we usually mean the vertex \\( L \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:categorical_limit_duality}\n  For every \\hyperref[def:category_of_cones/cone]{cone} \\( (A, \\alpha) \\) of the \\hyperref[def:categorical_diagram]{diagram} \\( D \\) in \\( \\cat{C} \\), \\( (A, \\alpha^{\\opcat}) \\) is a \\hyperref[def:category_of_cones/cone]{cocone} of \\( D^{\\opcat} \\) in the \\hyperref[def:opposite_category]{opposite category} \\( \\cat{C}^{\\opcat} \\).\n\n  Even more, for every \\hyperref[def:category_of_cones/limit]{limit} \\( (L, \\lambda) \\) of \\( D \\) in \\( \\cat{C} \\), \\( (L, \\lambda^{\\opcat}) \\) is a \\hyperref[def:category_of_cones/colimit]{colimit} of \\( D^{\\opcat} \\) in \\( \\cat{C}^{\\opcat} \\).\n\n  This is part of the duality principles listed in \\fullref{thm:categorical_principle_of_duality}.\n\\end{proposition}\n\\begin{proof}\n  Note that the defining diagrams \\eqref{eq:def:category_of_cones/cone}, \\eqref{eq:def:category_of_cones/cone_nat} and \\eqref{eq:def:category_of_cones/limit} are dual to \\eqref{eq:def:category_of_cones/cocone}, \\eqref{eq:def:category_of_cones/cocone_nat} and \\eqref{eq:def:category_of_cones/colimit}.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:categorical_limit_uniqueness_lemma}\n  Any two limits (resp. colimits) of a diagram are isomorphic.\n\n  We prove a stronger result in \\fullref{thm:categorical_limit_uniqueness}.\n\\end{lemma}\n\\begin{proof}\n  Let \\( (L', \\lambda') \\) and \\( (L^\\dprime, \\lambda^\\dprime) \\) be two limit cones over the diagram \\( D: \\cat{I} \\to \\cat{C} \\). The definition \\eqref{eq:def:category_of_cones/limit} of a limit implies that\n  \\begin{equation}\\label{eq:thm:categorical_limit_uniqueness}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__categorical_limit_uniqueness.pdf}\n    \\end{aligned}\n  \\end{equation}\n  commutes.\n\n  Therefore, the limits \\( L' \\) and \\( L^\\dprime \\) are isomorphic.\n\n  Now let \\( (L', \\lambda') \\) and \\( (L^\\dprime, \\lambda^\\dprime) \\) be colimit cocones. By \\fullref{thm:categorical_limit_duality}, \\( (L', \\lambda'^{\\opcat}) \\) and \\( (L^\\dprime, {\\lambda^\\dprime}^{\\opcat}) \\) are limits in the opposite category and are thus isomorphic. By \\fullref{thm:morphism_invertibility_duality}, the colimits are isomorphic.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:categorical_limit_is_adjoint}\n  Suppose that, for a given category \\( \\cat{C} \\), the limits over all \\( \\cat{I} \\)-shaped diagrams exist. Denote by \\( \\lim(D) \\) the vertex of the limiting cone of the diagram \\( D \\).\n\n  Given a natural transformation \\( \\alpha: D \\to E \\) between diagrams, the diagram \\eqref{eq:thm:categorical_limit_is_adjoint/c_triangle} defining a limit uniquely determines a morphism \\( \\lim(D) \\) to \\( \\lim(E) \\). Denote this morphism by \\( \\lim(\\alpha) \\).\n\n  We have defined a functor\n  \\begin{equation*}\n    \\lim: [\\cat{I}, \\cat{C}] \\to \\cat{C}.\n  \\end{equation*}\n\n  This functor is \\hyperref[def:category_adjunction]{right adjoint} to the diagonal functor\n  \\begin{equation*}\n    \\Delta: \\cat{C} \\to [\\cat{I}, \\cat{C}]\n  \\end{equation*}\n\n  \\hyperref[thm:categorical_principle_of_duality]{Dually}, the colimit functor\n  \\begin{equation*}\n    \\co\\lim: [\\cat{I}, \\cat{C}] \\to \\cat{C}\n  \\end{equation*}\n  is left adjoint to \\( \\Delta \\).\n\\end{proposition}\n\\begin{proof}\n  It is sufficient to prove this for limits since the statement for colimits follows from the duality principles \\fullref{thm:category_adjunction_duality} and \\fullref{thm:categorical_limit_duality}. The unit \\( \\eta: \\id_{\\cat{C}} \\to [{\\lim} \\bincirc \\Delta] \\) of the adjunction\n  \\begin{equation*}\n    \\Delta \\dashv \\lim\n  \\end{equation*}\n  is the unique morphism from an object \\( A \\) of \\( \\cat{C} \\) to the limit of its constant diagram \\( \\Delta_A: \\cat{I} \\to \\cat{C} \\) such that \\eqref{eq:def:category_of_cones/limit} commutes. The counit is more complicated because its components are themselves natural transformations:\n  \\begin{equation*}\n    \\begin{aligned}\n      \\varepsilon:       &[\\Delta \\bincirc \\lim] \\Rightarrow \\id_{[\\cat{I}, \\cat{C}]} \\\\\n      \\varepsilon_D:     &\\Delta(\\lim D) \\Rightarrow D \\\\\n      \\varepsilon_{D,k}: &\\lim(D) \\to D(k),\n    \\end{aligned}\n  \\end{equation*}\n  where \\( \\varepsilon_{D,k} \\) are the projections of the limit.\n\n  For any diagram \\( D: \\cat{I} \\to \\cat{C} \\), the following triangle commutes:\n  \\begin{equation}\\label{eq:thm:categorical_limit_is_adjoint/ic_triangle}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__categorical_limit_is_adjoint.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Indeed,\n  \\begin{equation*}\n    \\eta_{\\lim(D)}: \\lim(D) \\to \\smash{ \\overbrace{\\lim(\\Delta_{\\lim(D)})}^{[{\\lim} \\bincirc \\Delta \\bincirc {\\lim}](D)} }\n  \\end{equation*}\n  is the unique morphism such that \\eqref{eq:def:category_of_cones/limit} commutes, and (somewhat) similarly for\n  \\begin{equation*}\n    \\lim(\\varepsilon_D): [{\\lim} \\bincirc \\Delta \\bincirc {\\lim}](D) \\to \\lim(D).\n  \\end{equation*}\n\n  It follows that both \\( \\lim(D) \\) and \\( [{\\lim} \\bincirc \\Delta \\bincirc {\\lim}](D) \\) are limits over the same diagram. By \\fullref{thm:categorical_limit_is_adjoint}, they are isomorphic, and hence \\eqref{eq:thm:categorical_limit_is_adjoint/ic_triangle} commutes.\n\n  Also, for any object \\( A \\) in \\( \\cat{C} \\), the following triangle also commutes:\n  \\begin{equation}\\label{eq:thm:categorical_limit_is_adjoint/c_triangle}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__categorical_limit_is_adjoint.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Indeed,\n  \\begin{equation*}\n    \\Delta(\\eta_A) = \\seq{ \\eta_A: A \\to \\lim(\\Delta_A) }_{k \\in \\cat{I}}\n  \\end{equation*}\n  is the constant family consisting of \\( \\eta_A \\) and\n  \\begin{equation*}\n    \\varepsilon_{\\Delta(A)} = \\seq{ \\lambda_k^{\\Delta_A}: \\lim(\\Delta_A) \\to \\underbrace{\\Delta_A(k)}_{A} }_{k \\in \\cat{I}}.\n  \\end{equation*}\n  is a constant family of the single projection of the limit to \\( A \\). From the commutativity of \\eqref{eq:def:category_of_cones/limit} it follows that \\eqref{eq:thm:categorical_limit_is_adjoint/c_triangle} also commutes.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:categorical_limit_uniqueness}\n  A limit (resp. colimit) of a diagram, if it exists, is unique up to a unique isomorphism.\n\n  This statement strengthens \\fullref{thm:categorical_limit_uniqueness_lemma}.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:functor_adjoint_uniqueness} and \\fullref{thm:categorical_limit_is_adjoint}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:limit_universal_mapping_property}\n  The limit diagram \\eqref{eq:def:category_of_cones/limit} may seem unrelated to the universal mapping properties discussed in \\fullref{rem:universal_mapping_property}, however it is actually a special case.\n\n  Suppose that, for a given category \\( \\cat{C} \\), the limits over all \\( \\cat{I} \\)-shaped diagrams exist and fix a diagram \\( D: \\cat{I} \\to \\cat{C} \\). Consider the functors\n  \\begin{align*}\n    \\lim:   &[\\cat{I}, \\cat{C}] \\to \\cat{C} \\\\\n    \\Delta: &\\cat{C} \\to [\\cat{I}, \\cat{C}]\n  \\end{align*}\n  discussed in \\fullref{thm:categorical_limit_is_adjoint}. We have established that \\( \\Delta \\dashv \\lim \\).\n\n  For every diagram \\( D: \\cat{I} \\to \\cat{C} \\), there exist unique up to a unique isomorphism object \\( \\lim(D) \\) in \\( \\cat{C} \\) and canonical projection map \\( \\lambda: [\\Delta \\bincirc {\\lim}(D)] \\to D \\) satisfying the following universal mapping property:\n  \\begin{displayquote}\n    For every object \\( A \\) in \\( \\cat{C} \\) and every natural transformation \\( \\alpha: \\Delta(A) \\Rightarrow D \\), there exists a unique morphism \\( l: A \\to \\lim(D) \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:rem:limit_universal_mapping_property/ic_triangle}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/rem__limit_universal_mapping_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  For a fixed index object \\( k \\in \\cat{I} \\), this becomes:\n  \\begin{equation}\\label{eq:rem:limit_universal_mapping_property/c_triangle_basic}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/rem__limit_universal_mapping_property.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  The defining diagram \\eqref{eq:def:category_of_cones/limit} of a limit simply encodes the cone naturality condition \\eqref{eq:def:category_of_cones/cone_nat} into \\eqref{eq:rem:limit_universal_mapping_property/c_triangle_basic}.\n\n  Except for being simpler to check, limits defined via universal mapping properties have the advantage (compared to adjoint functors) that limits can exist for some diagrams and not for others.\n\n  The construction for colimits is dual.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:limits_of_empty_diagram}\n  The \\hyperref[def:category_of_cones/limit]{limits} of an empty diagram over \\( \\cat{C} \\) are the \\hyperref[def:universal_objects/terminal]{terminal objects} and the \\hyperref[def:category_of_cones/colimit]{colimits} are the \\hyperref[def:universal_objects/initial]{initial object}.\n\n  Compare this result with \\fullref{thm:limits_of_identity_functor}.\n\\end{proposition}\n\\begin{proof}\n  A cone of the empty diagram is simply an object of \\( \\cat{C} \\). A limit cone is then an object \\( L \\) such that every other object \\( A \\) has a unique morphism \\( l_A: A \\to L \\). This is precisely the definition of a terminal object.\n\n  The statement for colimits follows by \\hyperref[thm:categorical_principle_of_duality]{duality}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:limits_of_identity_functor}\n  Fix an arbitrary category \\( \\cat{C} \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:limits_of_identity_functor/initial_object_ks_limit} If \\( I \\) is an \\hyperref[def:universal_objects/initial]{initial object} of \\( \\cat{C} \\), \\( (I, \\xi) \\) is a limit cone of the \\hyperref[eq:def:category_of_small_categories/identity]{identity functor} \\( \\id_{\\cat{C}} \\), where\n    \\begin{equation*}\n      \\xi \\coloneqq \\seq{ \\xi_A: I \\to A }_{A \\in \\cat{C}}\n    \\end{equation*}\n    is the family of unique morphisms with domain \\( I \\).\n\n    \\thmitem{thm:limits_of_identity_functor/limit_ks_knitial_object} Conversely, if \\( (L, \\lambda) \\) is a limit cone of the identity, then \\( L \\) is an initial object.\n  \\end{thmenum}\n\n  \\hyperref[thm:categorical_principle_of_duality]{Dually}, by \\fullref{thm:universal_object_duality} and \\fullref{thm:categorical_limit_duality}, the cocones (and colimits) of the identity functor are the terminal objects.\n\n  Compare this result with \\fullref{thm:limits_of_empty_diagram}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:limits_of_identity_functor/initial_object_ks_limit} For an initial object \\( I \\) with morphisms \\( \\xi \\), and for any morphism \\( f: B \\to C \\), from the uniqueness of the arrows in \\( \\xi \\) it follows that \\( \\xi_C = f \\bincirc \\xi_B \\). Thus, the following naturality diagram commutes:\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/nat}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore, \\( (I, \\xi) \\) is a cone.\n\n  Now let \\( (A, \\alpha) \\) be another cone. The naturality of \\( \\alpha \\) implies that the following diagram commutes for every object \\( B \\):\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/half_limit}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  In particular, since \\( \\xi_I = \\id_I \\), for every morphism \\( g: A \\to I \\) we have\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/cone_morphism_uniqueness}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n  which shows that \\( \\alpha_I = g \\) and thus \\( \\alpha_I \\) is the unique morphism from \\( A \\) to \\( I \\).\n\n  Therefore, for any morphism \\( f: B \\to C \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/limit}\n    \\begin{aligned}\n      \\includegraphics[page=4]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  This is precisely the defining diagram for a limit cone. Therefore, \\( (I, \\xi) \\) is a limit cone.\n\n  \\SubProofOf{thm:limits_of_identity_functor/limit_ks_knitial_object} Let \\( (L, \\lambda) \\) be a limit cone of the identity. The component \\( \\lambda_B \\) of the natural transformation \\( \\lambda \\) is a morphism from \\( L \\) to \\( B \\). In order for \\( L \\) to be an initial object, these morphisms must be unique.\n\n  Since \\( (L, \\lambda) \\) is a limit cone, for any cone \\( (A, \\alpha) \\) and any morphism \\( f: B \\to C \\), there exists a unique morphism \\( l_A: A \\to L \\) such that the following diagram commutes:\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/limit}\n    \\begin{aligned}\n      \\includegraphics[page=5]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  In particular, there exists a unique map \\( l_L: L \\to L \\) for the cone \\( (L, \\lambda) \\) such that the following diagram commutes:\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/endomorphism_uniqueness}\n    \\begin{aligned}\n      \\includegraphics[page=6]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Since \\eqref{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/endomorphism_uniqueness} commutes with \\( \\id_L \\) instead of \\( l_L \\), by uniqueness it follows that \\( l_L = \\id_L \\). Since, by the naturality of \\( \\lambda \\), \\( \\lambda_L \\) also satisfies this condition, \\( \\lambda_L = \\id_L \\).\n\n  From the naturality of \\( \\lambda \\), for any map \\( f: L \\to C \\) it follows that the following diagram commutes:\n  \\begin{equation}\\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/morphism_uniqueness}\n    \\begin{aligned}\n      \\includegraphics[page=7]{output/thm__limits_of_identity_functor.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore, \\( f = \\lambda_B \\). Since \\( f \\) was an arbitrary morphism with domain \\( L \\), we conclude that \\( L \\) has a unique morphism to every object in \\( \\cat{C} \\). Hence, \\( L \\) is an initial object.\n\\end{proof}\n\n\\begin{example}\\label{ex:limits_of_partially_ordered_set}\n  We will show that limits and colimits correspond to suprema and infima of partially ordered sets.\n\n  Let \\( (P, \\leq) \\) be a \\hyperref[def:partially_ordered_set]{partially ordered set} and \\( \\cat{P} \\) be its corresponding \\hyperref[def:thin_category]{thin} \\hyperref[def:skeletal_category]{skeletal} category. The correspondence is discussed in \\fullref{thm:order_category_isomorphism/preordered}.\n\n  The image of a diagram \\( D: \\cat{I} \\to \\cat{P} \\) is a pair \\( (A, R) \\), where \\( A \\) is the set of objects \\( D(\\obj(\\cat{I})) \\) in the image \\( D(\\cat{I}) \\) and \\( R \\) is a subrelation of \\( \\leq \\). This relation is reflexive, however it may not even be a preorder as shown in \\fullref{ex:functor_image_not_a_category}.\n\n  Conversely, every subset \\( A \\subseteq P \\) with a corresponding category \\( \\cat{A} \\) is given by the diagram \\( \\Iota_A \\), where the \\hyperref[def:subcategory]{inclusion functor} \\( \\Iota_A: \\cat{A} \\to \\cat{P} \\).\n\n  A cone of a diagram \\( D: \\cat{I} \\to \\cat{P} \\) is a \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{lower bound} of the set \\( D(\\obj(\\cat{I})) \\). The relation induced by \\( D \\) does not matter here.\n\n  Indeed, the cone \\( (x, R) \\) in \\( \\cat{P} \\) consists of morphisms with domain \\( x \\). That is, \\( R \\) is a subrelation of \\( \\leq \\) whose first component is \\( x \\). Clearly then \\( x \\) is a lower bound of the set \\( D(\\obj(\\cat{I})) \\).\n\n  For the limiting cone \\( (y, S) \\), it holds that \\( x \\leq y \\) for every other cone \\( (x, R) \\). Both \\( R \\) and \\( S \\) are subrelations of \\( \\leq \\) with the same second components. Thus, \\( y \\) is the greatest lower bound of \\( D(\\obj(\\cat{I})) \\).\n\n  \\hyperref[thm:categorical_principle_of_duality]{Dually}, cocones are upper bounds and colimits are suprema.\n\n  As mentioned, the relation induced by the diagram \\( D \\) does not actually matter. Therefore, we may choose, without loss of generality, \\( D \\) to be a \\hyperref[def:discrete_category]{discrete category}. It then follows that infima and suprema correspond to \\hyperref[def:discrete_category_limits]{products} and \\hyperref[def:discrete_category_limits]{coproduct}, however what we have shown here is more general.\n\\end{example}\n\n\\begin{definition}\\label{def:direct_and_inverse_limits}\n  We will define limits and colimits of diagrams over infinite \\hyperref[def:partially_ordered_set_chain_and_antichain]{chains} of integers. These notions predate limits and colimits, which explains why their names may seem inconsistent with other limits and colimits.\n\n  \\begin{thmenum}\n    \\thmitem{def:direct_and_inverse_limits/direct}\\mcite[exmpl. 5.2.15]{Leinster2016Basic} Consider the category \\hyperref[thm:order_category_isomorphism]{induced} by the positive integers\n    \\begin{equation}\\label{eq:def:direct_and_inverse_limits/direct}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    A \\hyperref[def:category_of_cones/colimit]{colimit} over a diagram of this shape is called a \\term{direct limit}. In this context, the diagram itself is sometimes called a \\term{direct system}.\n\n    \\thmitem{def:direct_and_inverse_limits/inverse}\\mcite[exmpl. 5.1.21(d)]{Leinster2016Basic} Now consider the opposite category\n    \\begin{equation}\\label{eq:def:direct_and_inverse_limits/inverse}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    Somewhat confusingly, a \\hyperref[def:category_of_cones/limit]{limit} of a diagram of this shape is called an \\term{inverse limit}. In this context, the diagram itself is sometimes called an \\term{inverse system}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:direct_and_inverse_limits}\n  We will list several examples of \\hyperref[def:direct_and_inverse_limits/direct]{direct} and \\hyperref[def:direct_and_inverse_limits/inverse]{inverse} limits.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:direct_and_inverse_limits/vector_space_direct} Consider the chain of \\hyperref[def:module_of_tuples]{tuple vector spaces}\n    \\begin{equation}\\label{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/ex__def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n    where \\( \\iota_n^m: \\BbbK^n \\to \\BbbK^m \\) is simply the canonical inclusion map.\n\n    Let \\( \\BbbK_0^\\infty \\) be the vector space of all sequences in \\( \\BbbK \\) with only finitely many nonzero elements. For each positive integer \\( n \\), denote by \\( \\iota_n^\\infty: \\BbbK^n \\to \\BbbK_0^\\infty \\) the canonical inclusion.\n\n    Then \\( (\\BbbK_0^\\infty, \\iota) \\) is a \\hyperref[def:category_of_cones/cocone]{cocone} of \\eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}. We will show that it is a colimit cocone, i.e. that \\( \\BbbK_0^\\infty \\) is a \\hyperref[def:direct_and_inverse_limits]{direct limit} of \\eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.\n\n    Let \\( (A, \\alpha) \\) be another cocone. We want to define a linear map \\( l_A: \\BbbK_0^\\infty \\to A \\) so that the following diagram commutes:\n    \\begin{equation}\\label{eq:ex:def:direct_and_inverse_limits/vector_space_direct/limit}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/ex__def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    For every vector \\( x \\in \\BbbK^m \\), we must have\n    \\begin{equation*}\n      \\alpha_n(x) = l_A(\\iota_n^\\infty(x)).\n    \\end{equation*}\n\n    This implies the obvious definition where, given a vector \\( x \\in \\BbbK_0^\\infty \\) whose greatest nonzero element has index \\( m \\), we define\n    \\begin{equation*}\n      l_A(x) \\coloneqq \\alpha_m(x).\n    \\end{equation*}\n\n    This map is well-defined because the compatibility with inclusion maps guarantees that \\( \\alpha_{m+1}(x) = \\iota_{m+1}(\\alpha^{m+1}_m(x)) \\), i.e. the result obtained by using \\( \\alpha_m \\) and \\( \\alpha_{m+1} \\) is the same.\n\n    Therefore, \\( (\\BbbK_0^\\infty, \\iota) \\) is a direct limit of the diagram \\eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.\n\n    \\thmitem{ex:def:direct_and_inverse_limits/vector_space_inverse} \\hyperref[thm:categorical_principle_of_duality]{Dually}, consider the chain\n    \\begin{equation}\\label{eq:ex:def:direct_and_inverse_limits/vector_space_inverse/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=3]{output/ex__def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n    where\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\pi_n^m: \\BbbK^m \\to \\BbbK^n \\\\\n        &\\pi_n^m(x_1, \\ldots, x_n, x_{k+1}, \\ldots, x_m) \\coloneqq (x_1, \\ldots, x_n).\n      \\end{aligned}\n    \\end{equation*}\n\n    Let \\( \\BbbK^\\infty \\) be the vector space of all sequences in \\( \\BbbK \\) and, for each positive integer \\( n \\), define \\( \\pi_n^\\infty \\) as a truncation in the obvious way.\n\n    Then \\( (\\BbbK^\\infty, \\pi^\\infty) \\) is a \\hyperref[def:category_of_cones/cone]{cone} of \\eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}. We will show that it is a limit cone, i.e. that \\( \\BbbK^\\infty \\) is a \\hyperref[def:direct_and_inverse_limits]{direct limit} of \\eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.\n\n    Let \\( (A, \\alpha) \\) be another cone. We want to define \\( l_A: A \\to \\BbbK^\\infty \\) so that the following diagram commutes:\n    \\begin{equation}\\label{eq:ex:def:direct_and_inverse_limits/vector_space_inverse/limit}\n      \\begin{aligned}\n        \\includegraphics[page=4]{output/ex__def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    For every \\( a \\in A \\), we must have\n    \\begin{equation*}\n      \\alpha_n(a) = \\pi_n^\\infty(l_A(a)),\n    \\end{equation*}\n    which implies the obvious definition where the \\( n \\)-th coordinate of the vector \\( l_A(a) \\) is\n    \\begin{equation*}\n      [l_A(a)]_n \\coloneqq [\\alpha_n(a)]_n.\n    \\end{equation*}\n\n    That is, \\( l_A(a) \\) is a sequence whose \\( n \\)-th coordinate is the \\( n \\)-th coordinate \\( \\alpha_n(a) \\). This is well-defined because, for \\( m > n \\), we have\n    \\begin{equation*}\n      \\pi_m^n \\bincirc \\alpha_m = \\alpha_n.\n    \\end{equation*}\n\n    \\thmitem{ex:def:direct_and_inverse_limits/generalized_intersection} In \\hyperref[def:concrete_category]{concrete categories}, \\hyperref[def:direct_and_inverse_limits/inverse]{inverse limits} are generalizations of \\hyperref[thm:zfc_existence_theorems/arbitrary_intersection]{set intersections}.\n\n    As an example, consider the chain of sets\n    \\begin{equation}\\label{eq:ex:inverse_limit_as_intersection/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=5]{output/ex__def__direct_and_inverse_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n    where \\( A_{k+1} \\subseteq A_k \\) for every positive integer \\( k \\) and \\( \\iota_k^m: A_m \\to A_k \\) is simply the canonical inclusion map.\n\n    Then the intersection \\( \\bigcap_{k=1}^\\infty A_k \\) along with its inclusion maps is a limit of \\eqref{eq:ex:inverse_limit_as_intersection/diagram}. This is a consequence of the discussion in \\fullref{ex:limits_of_partially_ordered_set}.\n\n    We can replace the inclusion maps \\( \\iota_k^m \\) with other injective functions, or even non-injective functions. In this case, we would obtain a \\enquote{generalized intersection}.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:discrete_category_limits}\n  Fix an arbitrary category \\( \\cat{C} \\). A \\term{product} in \\( \\cat{C} \\) is a \\hyperref[def:category_of_cones/limit]{limit} over a diagram \\( D: \\cat{I} \\to \\cat{C} \\), whose domain \\( \\cat{I} \\) is a \\hyperref[def:discrete_category]{discrete category}. \\hyperref[thm:categorical_principle_of_duality]{Dually}, a \\term{coproduct} or \\term{sum} in \\( \\cat{C} \\) is a colimit of \\( D \\).\n\n  It will be convenient for us to speak about the product of an \\hyperref[def:cartesian_product/indexed_family]{indexed family} \\( \\seq{ X_k }_{k \\in \\mscrK} \\) of objects in \\( \\cat{C} \\).\n\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A cone with vertex \\( A \\) consists of morphisms with signatures\n    \\begin{equation*}\n      \\alpha = \\seq{ \\alpha_k: A \\to X_k }.\n    \\end{equation*}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A cocone with vertex \\( A \\) consists of morphisms with signatures\n    \\begin{equation*}\n      \\alpha = \\seq{ \\alpha_k: X_k \\to A }.\n    \\end{equation*}\n  \\end{minipage}\n\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A product \\hyperref[def:category_of_cones/cone]{cone} \\( (\\prod_{k \\in \\mscrK} X_k, \\pi) \\) satisfies the following \\hyperref[rem:limit_universal_mapping_property]{universal mapping property}:\n    \\begin{displayquote}\n      For every cone \\( (A, \\alpha) \\), there exists a unique morphism\n      \\begin{equation*}\n        l_A: A \\to \\prod_{k \\in \\mscrK} X_k,\n      \\end{equation*}\n      such that the following diagram commutes:\n    \\end{displayquote}\n    \\begin{equation}\\label{eq:def:discrete_category_limits/product}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__discrete_category_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A coproduct \\hyperref[def:category_of_cones/cocone]{cocone} \\( (\\coprod_{k \\in \\mscrK} X_k, \\iota) \\) satisfies the following \\hyperref[rem:limit_universal_mapping_property]{universal mapping property}:\n    \\begin{displayquote}\n      For every cone \\( (A, \\alpha) \\), there exists a unique morphism\n      \\begin{equation*}\n        l_A: A \\to \\coprod_{k \\in \\mscrK} X_k,\n      \\end{equation*}\n      such that the following diagram commutes:\n    \\end{displayquote}\n    \\begin{equation}\\label{eq:def:discrete_category_limits/coproduct}\n      \\begin{aligned}\n        \\includegraphics[page=3]{output/def__discrete_category_limits.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{minipage}\n\n  \\begin{minipage}[t]{0.47\\textwidth}\n    We call the morphism \\( \\pi_k \\) the \\term{canonical projection} of the product onto \\( X_k \\), even though it may not be a surjective function.\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[t]{0.47\\textwidth}\n    We call the morphism \\( \\iota_k \\) the \\term{canonical inclusion} of \\( X_k \\) into the coproduct, even though it may not be an injective function.\n  \\end{minipage}\n  \\medskip\n\n  From \\fullref{thm:limits_of_empty_diagram} it follows that the product (resp. coproduct) of an empty family is a terminal (resp. initial) object of \\( \\cat{C} \\).\n\n  As in the case of general limits, we call \\( \\prod_{k \\in \\mscrK} X_k \\) \\hi{the} product of the family \\( X \\).\n\n  In the case of only two objects, their product is given by the following diagram:\n  \\begin{equation}\\label{eq:def:discrete_category_limits/product/binary}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/def__discrete_category_limits.pdf}\n    \\end{aligned}\n  \\end{equation}\n  and their coproduct by\n  \\begin{equation}\\label{eq:def:discrete_category_limits/coproduct/binary}\n    \\begin{aligned}\n      \\includegraphics[page=4]{output/def__discrete_category_limits.pdf}\n    \\end{aligned}\n  \\end{equation}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:discrete_category_limits_in_set}\n  The \\hyperref[def:discrete_category_limits]{product} in the category \\hyperref[def:category_of_small_sets]{\\( \\ucat{Set} \\)} of \\( \\mscrU \\)-small sets of a family \\( \\mscrA = \\seq{ A_k }_{k \\in \\mscrK} \\) is their \\hyperref[def:cartesian_product/product]{Cartesian product} \\( \\prod_{k \\in \\mscrK} A_k \\) and the \\hyperref[def:discrete_category_limits]{coproduct} is their \\hyperref[def:disjoint_union]{disjoint union} \\( \\coprod_{k \\in \\mscrK} A_k \\).\n\\end{proposition}\n\\begin{proof}\n  \\SubProof{Proof for products} Consider the Cartesian product\n  \\begin{equation*}\n    L \\coloneqq \\prod_{k \\in \\mscrK} A_k = \\set*{ f: A \\to \\bigcup_{k \\in \\mscrK} A_k \\given* \\qforall {k \\in \\mscrK} k \\in A_k }.\n  \\end{equation*}\n\n  Since \\( \\mscrU \\) is a model of \\logic{ZFC} (with or without the axiom of infinity), hence the product is an object of \\( \\ucat{Set} \\). Define the projection morphisms\n  \\begin{equation*}\n    \\pi_k(f) \\coloneqq f(k).\n  \\end{equation*}\n\n  Then \\( (L, \\pi) \\) is a cone for (some diagram forming) \\( \\mscrA \\). Let \\( (B, \\beta) \\) also be a cone and consider the following diagram:\n  \\begin{equation}\\label{eq:thm:discrete_category_limits_in_set/limit}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__discrete_category_limits_in_set.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  We want to define a function \\( l_B: B \\to L \\) such that\n  \\begin{equation*}\n    \\underbrace{ \\pi_k(l_B(b)) }_{[l_B(b)](k)} = \\beta_k(b)\n  \\end{equation*}\n  for every \\( b \\in B \\) and \\( k \\in \\mscrK \\). This is uniquely determined by \\( b \\) and \\( k \\), hence\n  \\begin{equation*}\n    l_B(b) \\coloneqq \\seq{ \\beta_k(b) }_{k \\in \\mscrK}.\n  \\end{equation*}\n\n  The cone \\( (B, \\beta) \\) was chosen randomly, and we showed that there exists a unique morphism \\( l_B: B \\to L \\) such that \\eqref{eq:thm:discrete_category_limits_in_set/limit} commutes. Therefore, \\( (L, \\pi) \\) is a categorical product of the family \\( \\mscrA \\).\n\n  \\SubProof{Proof for coproducts} Now consider the disjoint union\n  \\begin{equation*}\n    L \\coloneqq \\coprod_{k \\in \\mscrK} A_k = \\set{ (k, a) \\given k \\in \\mscrK \\T{and} a \\in A_k }\n  \\end{equation*}\n  and the inclusions\n  \\begin{equation*}\n    \\iota_k\\parens[\\Big]{ (k, a) } = a.\n  \\end{equation*}\n\n  We must show that, for any other cocone \\( (B, \\beta) \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:discrete_category_limits_in_set/colimit}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__discrete_category_limits_in_set.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Analogously to products, the condition\n  \\begin{equation*}\n    \\underbrace{ l_B(\\iota_k(a)) }_{l_B(k, a)} = \\beta_k(a)\n  \\end{equation*}\n  for every \\( b \\in B \\) and \\( k \\in \\mscrK \\) uniquely identifies the function\n  \\begin{equation*}\n    l_B(k, a) \\coloneqq \\beta_k(a).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:equalizers}\\mcite[def. 5.1.11]{Leinster2016Basic}\n  Consider the index category\n  \\begin{equation}\\label{eq:def:equalizers/index}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/def__equalizers.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  A diagram indexed by \\eqref{eq:def:equalizers/index} is sometimes called a \\term{fork}. A \\hyperref[def:category_of_cones/limit]{limit} of a fork is called an \\term{equalizer} and a \\hyperref[def:category_of_cones/colimit]{colimit} --- a \\term{coequalizer}.\n\n  Note that in \\fullref{def:categorical_diagram} we defined commutativity only when at least one path is nontrivial. That is, \\eqref{eq:def:equalizers/index} cannot commute by definition since all of its paths have length either \\( 0 \\) or \\( 1 \\).\n\n  We will describe equalizers in more detail. Fix a fork in \\( \\cat{C} \\) which we will denote by\n  \\begin{equation}\\label{eq:def:equalizers/raw_diagram}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/def__equalizers.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A \\hyperref[def:category_of_cones/cone]{cone} with vertex \\( A \\) over this diagram has a single morphism \\( f: A \\to X \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:def:equalizers/cone}\n      \\begin{aligned}\n        \\includegraphics[page=3]{output/def__equalizers.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    This is equivalent to requiring\n    \\begin{equation*}\n      s \\bincirc f = t \\bincirc f.\n    \\end{equation*}\n\n    An equalizer limit cone \\( (L, \\iota) \\) satisfies the following \\hyperref[rem:limit_universal_mapping_property]{universal mapping property}:\n    \\begin{displayquote}\n      For every cone \\( (A, f) \\), \\( f \\) \\hyperref[def:factors_through]{uniquely factors through} \\( L \\). That is, there exists a unique morphism\n      \\begin{equation*}\n         l_A: A \\to L\n      \\end{equation*}\n      such that the following diagram commutes:\n    \\end{displayquote}\n    \\begin{equation}\\label{eq:def:equalizers/equalizer}\n      \\begin{aligned}\n        \\includegraphics[page=4]{output/def__equalizers.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}[t]{0.47\\textwidth}\n    A \\hyperref[def:category_of_cones/cocone]{cocone} with vertex \\( A \\) over this diagram has a single morphism \\( f: Y \\to A \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:def:equalizers/cocone}\n      \\begin{aligned}\n        \\includegraphics[page=5]{output/def__equalizers.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    This is equivalent to requiring\n    \\begin{equation*}\n      f \\bincirc s = f \\bincirc t.\n    \\end{equation*}\n\n    A coequalizer cocone \\( (L, \\pi) \\) satisfies the following \\hyperref[rem:limit_universal_mapping_property]{universal mapping property}:\n    \\begin{displayquote}\n      For every cocone \\( (A, f) \\), \\( f \\) \\hyperref[def:factors_through]{uniquely factors through} \\( L \\). That is, there exists a unique morphism\n      \\begin{equation*}\n        l_A: L \\to A\n      \\end{equation*}\n      such that the following diagram commutes:\n    \\end{displayquote}\n    \\begin{equation}\\label{eq:def:equalizers/coequalizer}\n      \\begin{aligned}\n        \\includegraphics[page=6]{output/def__equalizers.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{minipage}\n\n  The requirement that \\eqref{eq:def:equalizers/equalizer} commutes does not mean that \\( p = q \\). As discussed in \\fullref{def:categorical_diagram}, for commutative diagrams, we only consider a pair of paths if at least one of them is nontrivial. We made this requirement in order to allow parallel morphisms.\n\n  Note how we interchanged the notation for the projections and inclusions compared to \\fullref{def:discrete_category_limits} --- \\( (L, \\iota) \\) is a \\hi{limit} of a fork, while \\( (L, \\pi) \\) is a \\hi{colimit}. The reason for this is that equalizers are usually canonical inclusions, while coequalizers are projections.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:equalizer_invertibility}\n  If \\( (L, \\iota) \\) is an \\hyperref[def:equalizers]{equalizer} in the category \\( \\cat{C} \\), then \\( \\iota \\) is a \\hyperref[def:morphism_invertibility/left_cancellative]{monomorphism}.\n\n  \\hyperref[thm:categorical_principle_of_duality]{Dually}, if \\( (L, \\pi) \\) is a \\hyperref[def:equalizers]{coequalizer}, then \\( \\pi \\) is an \\hyperref[def:morphism_invertibility/right_cancellative]{epimorphism}.\n\\end{proposition}\n\\begin{proof}\n  Fix an equalizer cone \\( (L, \\iota) \\) of the fork \\eqref{eq:def:equalizers/raw_diagram}. Fix any object \\( A \\) in \\( \\cat{C} \\) and any two parallel morphisms \\( a_1, a_2: A \\to X \\) such that\n  \\begin{equation*}\n    \\iota \\bincirc a_1 = \\iota \\bincirc a_2.\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    g \\bincirc \\iota \\bincirc a_1 = h \\bincirc \\iota \\bincirc a_2,\n  \\end{equation*}\n  and thus \\( \\iota \\bincirc a_1 = \\iota \\bincirc a_2 \\) is the morphism of a cone. Hence, both \\( (A, \\iota \\bincirc a_1) \\) and \\( (A, \\iota \\bincirc a_2) \\) are cones and thus \\( a_1 \\) and \\( a_2 \\) are the unique maps such that the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:equalizer_invertibility/monomorphism}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__equalizer_invertibility.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore, \\( a_1 = a_2 \\) and, since \\( a_1 \\) and \\( a_2 \\) were arbitrary, it follows that \\( \\iota \\) is a monomorphism.\n\n  Dually, if \\( (L, \\pi) \\) is a coequalizer colimit cocone in \\( \\cat{C} \\), then by \\fullref{thm:categorical_limit_duality}, \\( (L, \\pi^{\\opcat}) \\) is an equalizer in \\( \\cat{C}^{\\opcat} \\). Hence, \\( \\pi^{\\opcat} \\) is a monomorphism, and by \\fullref{thm:morphism_invertibility_duality}, \\( \\pi \\) is an epimorphism.\n\\end{proof}\n\n\\begin{example}\\label{ex:equalizers_in_set}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{ex:equalizers_in_set/equalizer} For a pair of functions \\( s, t: X \\to Y \\) in \\( \\cat{Set} \\), define the set\n    \\begin{equation*}\n      E = \\set{ x \\in X \\given s(x) = t(x) }.\n    \\end{equation*}\n\n    With the inclusion map \\( \\iota: E \\to X \\), this is an \\hyperref[def:equalizers]{equalizer} cone for \\( s \\) and \\( t \\).\n\n    We will now prove that it is a limit cone. The pair \\( (E, \\iota) \\) is obviously a cone. For any other cone \\( (A, f) \\), we must find a map \\( l_A: A \\to E \\) such that the following equalizer diagram commutes:\n    \\begin{equation}\\label{eq:ex:equalizers_in_set/equalizer}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/ex__equalizers_in_set.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    In order for \\( (A, f) \\) to be a cone, the image \\( f[A] \\) must be a subset of \\( E \\). In order for \\eqref{eq:ex:equalizers_in_set/equalizer} to commute, it only makes sense to take \\( l_A \\) to be \\( f \\) with its codomain restricted to \\( E \\).\n\n    It follows that \\( (E, \\iota) \\) is a limit cone.\n\n    \\thmitem{ex:equalizers_in_set/coequalizer} The coequalizer of \\( s, t: X \\to Y \\) is more nuanced. Suppose that \\( (L, \\pi) \\) is a colimit cocone and \\( (A, f) \\) is any cocone for the coequalizer diagram\n    \\begin{equation}\\label{eq:ex:equalizers_in_set/coequalizer}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/ex__equalizers_in_set.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    In order for \\( (A, f) \\) to be a cocone, for every \\( x \\in X \\), we must have \\( f(s(x)) = f(t(x)) \\). Thus, \\( A \\) must be a partition of \\( Y \\) in a way such that \\( s(x) \\) and \\( t(x) \\) belong to the same coset if and only if \\( f(s(x)) = f(t(x)) \\). Outside the images of \\( s \\) and \\( t \\), \\( f \\) is free to take any value.\n\n    Let \\( {\\sim} \\) be the smallest equivalence relation on \\( Y \\) such that \\( s(x) \\sim t(x) \\) for every \\( x \\in X \\). Explicitly, this is the \\hyperref[thm:equivalence_closure]{equivalence closure} of the relation\n    \\begin{equation*}\n      \\set{ (s(x), t(x)) \\given x \\in X }.\n    \\end{equation*}\n\n    Consider the partition \\( Y / {\\sim} \\) with the projection map\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\pi: Y \\to Y / {\\sim} \\\\\n        &\\pi(y) \\coloneqq [y]\n      \\end{aligned}\n    \\end{equation*}\n\n    This is a cocone. Furthermore, it is a colimit cocone because, for any other cocone \\( (A, f) \\), we can define \\( l_A([y]) \\coloneqq f(y) \\) so that \\eqref{eq:ex:equalizers_in_set/coequalizer} commutes.\n\n    Coequalizers mostly make sense in the context of \\hyperref[def:group/quotient]{quotient groups}, where partitions are especially well-behaved and admit a much simpler description. See \\fullref{def:group/quotient}.\n  \\end{thmenum}\n\\end{example}\n", "meta": {"hexsha": "d3dfa486b4487a30366ca91c78390e03a2125d84", "size": 48841, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/categorical_limits.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/categorical_limits.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/categorical_limits.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": 58.9155609168, "max_line_length": 455, "alphanum_fraction": 0.6909563686, "num_tokens": 15348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.625030007053086}}
{"text": "\\section{Subset of Supported Operations}\n\n\\setlongtables\n\\begin{longtable}{| p{4.8in} |}\n%\\hline\n\\endhead\n%\\hline\n\\endfoot\n%\n%\n\\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Negate( PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{$ A \\becomes - A $.} \n\\parameter{\\tt A}{descriptor of data to be updated}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Obj_set_diagonal( PLA_Obj sigma, PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\nSet the diagonal of $ A $ to $ \\sigma I $.\nAll other values in $ A $ are unaffected.\n} \n\\parameter{\\tt sigma, A}{descriptor for $ \\sigma $ and $ A $}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Shift_diagonal( PLA_Obj sigma, PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ A \\becomes A + \\sigma I $.\n} \n\\parameter{\\tt sigma, A}{descriptor for $ \\sigma $ and $ A $}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Symmetrize( PLA_Uplo uplo, PLA_Conj conj, PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ A \\becomes \\mbox{symm}(A) $ or \n$ A \\becomes \\mbox{herm}(A) $,\nwhere {\\tt uplo} indicates whether\n$ A $ is originally stored only in the upper or\nlower triangular part of {\\tt A}.\n} \n\\parameter{\\tt uplo}{\nindicates where $ A$ is stored.\n} \n\\parameter{\\tt conj}{\nindicates whether to create a symmetric or hermitian matrix.\n} \n\\parameter{\\tt A}{\ndescriptor for matrix $ A $.\n}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Triangularize( PLA_Uplo uplo, PLA_Diag diag, PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ A \\becomes \\mbox{lower}(A) $ or \n$ A \\becomes \\mbox{upper}(A) $.\n}\n\\parameter{\\tt uplo}{\nindicates whether whether $ A$ should be upper of\nlower triangular.\n}\n\\parameter{\\tt diag}{\nindicates whether set diagonal to zero or one.\n}\n\\parameter{\\tt A}{\ndescriptor for matrix $ A $.\n}\n% \\\\ \\hline \\hline\n% \\begin{minipage}{4.8in}\n% \\footnotesize\n% \\begin{verbatim}\n% PLA_LU( PLA_Obj A, PLA_Obj ipiv )\n% \\end{verbatim}\n% \\end{minipage}\n% \\purpose{Compute the\n% LU factorization with partial pivoting of\n% matrix $ A $, overwriting $ A $ with factors\n% $ L $ and $ U $.  The pivot matrix $ P $ is\n% stored as a vector of indices, in {\\tt ipiv}.\n% } \n% \\parameter{\\tt A}{descriptor for $ A $} \n% \\parameter{\\tt ipiv}{descriptor for vector in which $ P $ is\n% stored} \n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Nrm1( PLA_Obj A, PLA_Obj alpha )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{$ \\alpha \\becomes \\| A \\|_1 $.\n} \n\\parameter{\\tt A, alpha}{descriptor for $ A $ and $ \\alpha $}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Nrm_inf( PLA_Obj A, PLA_Obj alpha )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ \\alpha \\becomes \\| A \\|_\\infty $.\n} \n\\parameter{\\tt A, alpha}{descriptor for $ A $ and $ \\alpha $}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Scal_x( PLA_Uplo uplo, PLA_Obj alpha, PLA_Obj A )\n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ A \\becomes \\alpha A $\nwhere {\\tt uplo} indicates whether $ A $ is stored in the upper\nor lower triangular part of {\\tt A}.\n} \n\\parameter{\\tt alpha, A}{descriptor for $ \\alpha $ and $ A $}\n\\\\ \\hline \\hline\n\\begin{minipage}{4.8in}\n\\footnotesize\n\\begin{verbatim}\nPLA_Swap_x( PLA_Trans trans, PLA_Obj A, PLA_Obj B ) \n\\end{verbatim}\n\\end{minipage}\n\\purpose{\n$ A, B \\becomes \\op_{trans}(A), \\op_{trans}(B) $.\n} \n\\parameter{\\tt trans}{indicates whether to transpose and/or conjugate the data} \n\\parameter{\\tt A, B}{descriptors for $ A $ and $ B $}\n\\\\ \\hline\n\\end{longtable}\n", "meta": {"hexsha": "676a5a362da44732e7f12e2f4169a4335d2c6928", "size": 3605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/libflame/old/appendixB.tex", "max_stars_repo_name": "haampie/libflame", "max_stars_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 199, "max_stars_repo_stars_event_min_datetime": "2015-02-06T06:05:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T05:20:33.000Z", "max_issues_repo_path": "docs/libflame/old/appendixB.tex", "max_issues_repo_name": "haampie/libflame", "max_issues_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2015-05-10T18:14:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T08:22:10.000Z", "max_forks_repo_path": "docs/libflame/old/appendixB.tex", "max_forks_repo_name": "haampie/libflame", "max_forks_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-02-07T04:53:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T05:20:36.000Z", "avg_line_length": 23.8741721854, "max_line_length": 80, "alphanum_fraction": 0.6882108183, "num_tokens": 1265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6250300070530859}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb}\n\n\\title{\\LaTeX{} Maths examples}\n\\author{Becky Nisbet}\n\\date{January 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Symbols}\nInfinity: $\\infty$\\\\\nDouble bold maths (like real numbers): $\\mathbb{R}, \\mathbb{C}, \\mathbb{N}$ \\\\ %needs package amssymb\nSet notation: $\\in, \\notin, \\ni, \\subset, \\subseteq, \\supset, \\supseteq, \\cup, \\cap \\varnothing$\\\\\nLogic symbols: $\\forall, \\exists, \\rightarrow, \\Rightarrow, \\equiv \\iff, \\leftrightarrow, \\neg, \\sim$\n\n\\section{Calculus}\nDerivatives:\\\\\n$\\frac{dy}{dx} =x^2+3\\\\\n\\frac{d}{dx}y=x^2+3\\\\\n\\frac{\\partial y}{\\partial x}=xy+1\\\\\n\\frac{\\partial}{\\partial x}[xy]=y$\\\\\nIntegrals:\\\\\n$\\int x = \\frac{x^2}{2}+c\\\\\n\\int_0^2 x = 2$\n\n\\section{Vectors and linear algebra}\nA matrix;\\\\\n$M = \\left( %this has to go before the begin array if you want the brackets\n\\begin{array}{cc}\n    \n    1 & 0 \\\\\n    0 & 1\n\\end{array}\n\\right)$\\\\\nA vector;\\\\\n$\\vec{v}=\\left(\n\\begin{array}{c}\n    a \\\\\n    b\n\\end{array}\n\\right)$ \\\\%note how similar this is to constructing tables!\nDeterminants;\\\\\n$\\det{A} =\n\\left|\n\\begin{array}{cc}\n    a & b \\\\\n    c & d\n\\end{array}\n\\right|$\n\n\\end{document}\n", "meta": {"hexsha": "3c4ae4f89763304f31c6b759bdf06abb742879cf", "size": 1173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths-examples.tex", "max_stars_repo_name": "renisbet/LaTeX-resources", "max_stars_repo_head_hexsha": "36f80d0d5a246839cec71f901947b9e26fa15997", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "maths-examples.tex", "max_issues_repo_name": "renisbet/LaTeX-resources", "max_issues_repo_head_hexsha": "36f80d0d5a246839cec71f901947b9e26fa15997", "max_issues_repo_licenses": ["MIT"], "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-examples.tex", "max_forks_repo_name": "renisbet/LaTeX-resources", "max_forks_repo_head_hexsha": "36f80d0d5a246839cec71f901947b9e26fa15997", "max_forks_repo_licenses": ["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.3272727273, "max_line_length": 101, "alphanum_fraction": 0.641943734, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6250300053817195}}
{"text": "Optimization problems can appear in almost all situations on life, but there are special important cases where those problems appears, specially on the industry, since if we can achieve an optimal solution, we will improve the efficiency of the industrial process and then get lower production cost with the same (or better) efficiency. This improvement of the costs have an effect on the competitiveness of the companies and on the final quality of their products, including that this is an important money-saving factor. \n   \n   The challenging part is when this kind of problems become really big, since then they have a attached really high computational complexity and cost, therefore we need some methods to face them. \n   \n   To do so, we have two approaches, the always-optimal methods that obtain the optimal solution but taking into account every possible combination of the problems' solutions, as for instance Integer Linear Programming does. By the other hand we have those methods that concerns about fair execution times and are looking for a trade-off between acceptable execution times and the quality of the solution.\n   \n   In this work we propose two approaches in order to solve the scheduling of nurses in a hospital taking into account several constraints. The first one is using Integer Linear Programming and the second one by using metaheuristics. In the metaheuristics part we are focusing specifically in the Greedy Randomized Adaptative Procedure (GRASP) and the Biased-Random Key Genetic Algorithm (BRKGA).\n   \n   Firstly we compare the efficiency in terms of solving time and wellness of ILP and metaheuristics over medium-sized problems. \n   \n   Lastly, since large problems are intractable for ILP due to combinatorial explosion reasons, we compare the metaheuristics among them to compare such kind of problems.\n   \n   \\subsection{Problem Statement}\n   \n   A public hospital needs to design the working schedule of their nurses. As a first approximation, we are asked to help in designing the schedule of a single day. We know, for each hour h, that at least demandh nurses should be working at the hospital. We have available a set of nNurses nurses and we need to determine at which hours each nurse should be working. However, there are some limitations that should be taken into account:\n   \n   \\begin{itemize}\n   \\item Each nurse should work at least minHours hours.\n   \\item Each nurse should work at most maxHours hours.\n   \\item Each nurse should work at most maxConsec consecutive hours.\n   \\item No nurse can stay at the hospital for more than maxPresence hours (e.g. if maxPresence is 7, it is OK that a nurse works at 2am and also at 8am, but it not possible that he/she works at 2am and also at 9am).\n   \\item No nurse can rest for more than one consecutive hour (e.g. working at 8am, resting at 9am and 10am, and working again at 11am is not allowed, since there are two consecutive resting hours).\n   \\end{itemize}\n\nThe goal of this project is to determine at which hours each nurse should be working in order to minimize the number of nurses required and satisfy all the aforementioned constraints.\n\n\\subsection{Document Structure}\n\nThe structure of this document is the following: The problem definition is done in chapter 2. Here it is explained the problem that is faced, which constraints is needed to take into account and what we want to optimize. At chapter 3 is explained the ILP model that has been developed, i.e. the decision variables and also the constraints with a mathematical nomenclature. After this chapter, at chapter 4 is explained how it has been used the heuristics approach in order to face with the problem, two meta-heuristics has been used: GRASP3 and BRKGA4 . After perform several executions for those approaches, a comparison in terms of time and quality of the result is done at chapter 5. Finally conclusions of the project are explained at chapter 6.\n\n \n\n\n\\pagebreak", "meta": {"hexsha": "4ca3dc9bab905dad1ba7d5cc4ae2ac0cfbfdcb83", "size": 3948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/tex/Introduction.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/Introduction.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/Introduction.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": 116.1176470588, "max_line_length": 749, "alphanum_fraction": 0.7938196555, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.624980922032898}}
{"text": "\\section{Algebraic view of systems of equations}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Recognize the difference between a linear equation and a\n    non-linear equation.\n  \\item Determine whether a tuple of real numbers is a solution for a\n    system of linear equations.\n  \\item Understand what it means for a system of linear equations to\n    be consistent or inconsistent.\n  \\end{enumerate}\n\\end{outcome}\n\nWe have taken an in-depth look at graphical representations of systems\nof equations, as well as how to find possible solutions\ngraphically. Our attention now turns to working with systems\nalgebraically.\n\n\\begin{definition}{Linear equation}{linear-equation}\n  A \\textbf{linear equation}%\n  \\index{linear equation} is an equation of the form\n  \\begin{equation*}\n    a_1x_1 + a_2x_2 + \\ldots + a_nx_n = b.\n  \\end{equation*}\n  Here, $a_1,\\ldots,a_n$ are real numbers called the\n  \\textbf{coefficients}%\n  \\index{coefficient} of the equation, $b$ is a real number called the\n  \\textbf{constant term}%\n  \\index{constant term} of the equation, and $x_1,\\ldots,x_n$ are\n  \\textbf{variables}%\n  \\index{variable}.\n\\end{definition}\n\nReal numbers, such as the coefficients $a_1,\\ldots,a_n$, the constant\nterm $b$, or the values of the variables $x_1,\\ldots,x_n$, will also\nbe called \\textbf{scalars}%\n\\index{scalar}. For now, the word ``scalar'' is just a synonym for\n``real number''. Later, in Section~\\ref{sec:fields}, we will discover\nother kinds of scalars.\n\n\\begin{example}{Linear vs. non-linear equation}{linear-vs-non-linear}\n  Which of the following equations are linear?\n  \\begin{equation*}\n    \\begin{array}{c}\n      2x+3y=5 \\\\\n      2x^2+3y=5 \\\\\n      2\\sqrt{x} + 3y = 5 \\\\\n      (\\sqrt{2}) x + 3y = 5^2\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The equation $2x+3y=5$ is linear. The equation $2x^2+3y=5$ is not\n  linear, because it contains the square of a variable instead of a\n  variable.  The equation $2\\sqrt{x} + 3y = 5$ is also not linear,\n  because the square root is applied to one of the variables. On the\n  other hand, the equation $(\\sqrt{2}) x + 3y = 5^2$ is linear,\n  because $\\sqrt{2}$ and $5^2$ are real numbers, and can\n  therefore be used as coefficients and constant terms.\n\\end{solution}\n\nWe also permit minor notational variants of linear equations. The\nequation $2x-3y=5$ is linear although\nDefinition~\\ref{def:linear-equation} does not mention subtraction,\nbecause it can be regarded as just another notation for\n$2x+(-3)y = 5$. Similarly, the equation $2x=5+3y$ can be regarded as\nlinear, because it can be easily rewritten as $2x-3y=5$ by bringing\nall the variables (and their coefficients) to the left-hand side.\nWhen we need to emphasize that some linear equation is literally of\nthe form $a_1x_1 + a_2x_2 + \\ldots + a_nx_n = b$, we say that the\nequation is in \\textbf{standard form}%\n\\index{linear equation!standard form}%\n\\index{standard form!of a linear equation}. Thus, the standard form of\nthe equation $2x=5+3y$ is $2x+(-3)y=5$.\n\nA \\textbf{solution}%\n\\index{linear equation!solution} to a linear equation is an assignment\nof real numbers to the variables, making the equation true. More\nprecisely, if $r_1,\\ldots,r_n$ are real numbers, the assignment\n$x_1=r_1$, \\ldots, $x_n=r_n$ is a solution to the equation in\nDefinition~\\ref{def:linear-equation} if the real number\n$a_1r_1 + a_2r_2 + \\ldots + a_nr_n$ is equal to the real number\n$b$. To save space, we often write solutions in \\textbf{tuple\n  notation}%\n\\index{tuple}\\footnote{The terminology ``tuple'' arose as follows. A\n  collection of two items is called a ``pair'', a collection of three\n  items is called a ``triple'', followed by ``quadruple'',\n  ``quintuple'', ``sextuple'', and so on. You have to know Latin to\n  know what the next ones are called. To avoid these Latin terms,\n  mathematicians started saying $4$-tuple, $5$-tuple, $6$-tuple and so\n  on, and more generally, $n$-tuple for an ordered collection of $n$\n  items. When $n$ doesn't matter or is clear from the context, we\n  often just say ``tuple''.}  as\n$(x_1,\\ldots,x_n) = (r_1,\\ldots,r_n)$. When there is no doubt about\nthe order of the variables, we also often simply write the solution as\n$(r_1,\\ldots,r_n)$.\n\n\\begin{example}{Solutions of a linear equation}{linear-equation-solutions}\n  Consider the linear equation $2x+3y-4z=5$. Which of the following\n  are solutions? (a) $(x,y,z)=(1,1,0)$, (b) $(x,y,z)=(0,3,1)$, (c)\n  $(x,y,z)=(1,1,1)$.\n\\end{example}\n\n\\begin{solution}\n  The assignment $(x,y,z) = (1,1,0)$ is a solution because\n  $2(1)+3(1)-4(0) = 5$. The assignment $(x,y,z) = (0,3,1)$ is also a\n  solution, because $2(0) + 3(3) - 4(1) = 5$. On the other hand,\n  $(x,y,z) = (1,1,1)$ is not a solution, because\n  $2(1) + 3(1)-4(1) = 1 \\neq 5$.\n\\end{solution}\n\nA system of linear equations is just several linear equations taken\ntogether.\n\n\\begin{definition}{System of linear equations}{system-of-linear-equations}\n  A \\textbf{system of linear equations}%\n  \\index{system of linear equations} is a list of equations\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c}\n      a_{11}x_1+a_{12}x_2+\\ldots+a_{1n}x_n&=&b_1 \\\\\n      a_{21}x_1+a_{22}x_2+\\ldots+a_{2n}x_n&=&b_2 \\\\\n      \\vdots \\\\\n      a_{m1}x_1+a_{m2}x_2+\\ldots+a_{mn}x_n&=&b_m,\n    \\end{array}\n  \\end{equation*}\n  where $a_{ij}$ and $b_i$ are scalars (i.e., real numbers). The above\n  is a system of $m$ equations in the $n$ variables,\n  $x_1,x_2\\ldots,x_n$.  As before, the numbers $a_{ij}$ are called the\n  \\textbf{coefficients}%\n  \\index{coefficient} and the numbers $b_i$ are called the\n  \\textbf{constant terms}%\n  \\index{constant term} of the system of equations.\n\\end{definition}\n\nThe relative size of $m$ and $n$ is not important here. We may have\nmore variables than equations, more equations than variables, or an\nequal number of equations and variables.\n\nA \\textbf{solution}%\n\\index{system of linear equations!solution} to a system of linear\nequations is an assignment of real numbers to the variables that is a\nsolution to {\\em all} of the equations in the system.\n\n\\begin{example}{Solutions of a system of linear equations}{linear-system-solutions}\n  Consider the system of linear equations\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      2x&+&3y&-&4z &=& 5 \\\\\n      -2x&+&y&+&2z &=& -1.\n    \\end{array}\n  \\end{equation*}\n  Which of the following are solutions of the system? (a)\n  $(x,y,z)=(1,1,0)$, (b) $(x,y,z)=(6,3,4)$, (c) $(x,y,z)=(0,3,1)$.\n\\end{example}\n\n\\begin{solution}\n  The assignment $(x,y,z)=(1,1,0)$ is a solution of this system of\n  equations, because it is a solution to the first equation and the\n  second equation. Also, $(x,y,z)=(6,3,4)$ is another solution of this\n  system of equations (check this!).  On the other hand,\n  $(x,y,z)=(0,3,1)$ is not a solution of the system, because although\n  it is a solution to the first equation, it is not a solution to the\n  second equation.\n\\end{solution}\n\nRecall from Section~\\ref{sec:systems-geometric} that a system of\nequations either has a unique solution, infinitely many solutions, or\nno solution. It is very important to us whether a system of equations\nhas solutions or not. For this reason, we introduce the following\nterminology:\n\n\\begin{definition}{Consistent and inconsistent systems}{consistent-and-inconsistent}\n  A system of linear equations is called \\textbf{consistent}%\n  \\index{consistent system}%\n  \\index{system of linear equations!consistent} if there exists at\n  least one solution. It is called \\textbf{inconsistent}%\n  \\index{inconsistent system}%\n  \\index{system of linear equations!inconsistent} if there is no\n  solution.\n\\end{definition}\n\nIf we think of each equation as a condition that must be satisfied by\nthe variables, consistent means that there is some choice of values\nfor the variables which can satisfy \\textbf{all} of the\nconditions. Inconsistent means that there is no such choice of values\nfor the variables. In the following sections, you will learn a method\nfor determining whether a system of equations is consistent or not,\nand in case it is consistent, to find all of its solutions.\n\n", "meta": {"hexsha": "bc1e2ec7083c0c33c318fbdd8189eecf568a7cc4", "size": 8098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-Algebraic.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-Algebraic.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-Algebraic.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.3979057592, "max_line_length": 84, "alphanum_fraction": 0.712398123, "num_tokens": 2515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.6249809205206622}}
{"text": "\\chapter{Integrating differential forms}\nWe now show how to integrate differential forms over cells,\nand state Stokes' theorem in this context.\nIn this chapter, all vector spaces are finite-dimensional and real.\n\n\\section{Motivation: line integrals}\nGiven a function $g : [a,b] \\to \\RR$,\nwe know by the fundamental theorem of calculus that\n\\[\n\t\\int_{[a,b]} g(t) \\; dt = f(b) - f(a)\n\\]\nwhere $f$ is a function such that $g = df/dt$.\n%(You might recognize this more readily\n%as the more customary $\\int_a^b g(t) \\; dt$.)\nEquivalently, for $f : [a,b] \\to \\RR$,\n\\[ \\int_{[a,b]} g \\; dt = \\int_{[a,b]} df = f(b) - f(a) \\]\nwhere $df$ is the exterior derivative we defined earlier.\n\nCool, so we can integrate over $[a,b]$.\nNow suppose more generally, we have $U$ an open subset of our real vector space $V$\nand a $1$-form $\\alpha : U \\to V^\\vee$.\nWe consider a \\vocab{parametrized curve}, which is a smooth function $c : [a,b] \\to U$.\nPicture:\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(8.5cm);\n\t\tpair A = (-13,0);\n\t\tpair B = (-9,0);\n\t\tdraw(A--B, grey);\n\t\tdot(A, grey); dot(B, grey);\n\t\tlabel(\"$[a,b]$\", A--B, dir(90), grey);\n\t\tdot(\"$t$\", 0.3*A+0.7*B, dir(-90), grey);\n\n\t\tdraw( (-8,0) -- (-6,0) , EndArrow);\n\t\tlabel(\"$c$\", (-7,0), dir(90));\n\n\t\tbigblob(\"$U$\");\n\t\tpair a = (-2,-2);\n\t\tpair b = (3,0);\n\t\tpair p = (0,1);\n\t\tpair q = (2,0);\n\t\tlabel(\"$c$\", q, dir(45), red);\n\t\tdraw(a..p..q..b, red);\n\t\tdot(\"$p = c(t)$\", p, dir(90), blue);\n\t\tdraw(p--(p+1.5*dir(-10)), blue, EndArrow);\n\n\t\tdraw( (0,-4)--(0,-8), EndArrow );\n\t\tlabel(\"$\\alpha$\", (0,-6), dir(0));\n\t\tlabel(\"$\\alpha_p(v) \\in \\mathbb R$\", (0,-9), heavygreen);\n\n\t\tdraw( (-10,-1)--(-1,-8), EndArrow);\n\t\tlabel(\"$c^\\ast \\alpha$\", (-5.5,-4.5), dir(225));\n\t\\end{asy}\n\\end{center}\n\nWe want to define an $\\int_c \\alpha$ such that:\n\\begin{moral}\n\tThe integral $\\int_c \\alpha$ should add up all the $\\alpha$ along the curve $c$.\n\\end{moral}\nOur differential form $\\alpha$ first takes in a point $p$ to get $\\alpha_p \\in V^\\vee$.\nThen, it eats a tangent vector $v \\in V$ to the curve $c$ to finally give a real number $\\alpha_p(v) \\in \\RR$.\nWe would like to ``add all these numbers up'',\nusing only the notion of an integral over $[a,b]$.\n\n\\begin{exercise}\n\tTry to guess what the definition of the integral should be.\n\t(By type-checking, there's only one reasonable answer.)\n\\end{exercise}\n\nSo, the definition we give is\n\\[ \\int_c \\alpha \\defeq\n\t\\int_{[a,b]} \\alpha_{c(t)} \\left( c'(t) \\right) \\; dt.  \\]\nHere, $c'(t)$ is shorthand for $(Dc)_{c(t)}(1)$.\nIt represents the \\emph{tangent vector} to the curve $c$ at the point $p=c(t)$,\nat time $t$.\n(Here we are taking advantage of the fact that $[a,b]$ is one-dimensional.)\n\nNow that definition was a pain to write, so we will define a differential\n$1$-form $c^\\ast \\alpha$ on $[a,b]$ to swallow that entire thing:\nspecifically, in this case we define $c^\\ast\\alpha$ to be\n\\[ \\left( c^\\ast \\alpha \\right)_t (\\eps) = \\alpha_{c(t)} \\cdot (Dc)_{t} (\\eps) \\]\n(here $\\eps$ is some displacement in time).\nThus, we can more succinctly write\n\\[ \\int_c \\alpha \\defeq \\int_{[a,b]} c^\\ast \\alpha. \\]\nThis is a special case of a \\emph{pullback}:\nroughly, if $\\phi : U \\to U'$ (where $U \\subseteq V$, $U' \\subseteq V'$),\nwe can change any differential $k$-form $\\alpha$ on $U'$\nto a $k$-form on $U$.\nIn particular, if $U = [a,b]$,\\footnote{OK,\n\tso $[a,b]$ isn't actually open, sorry.\n\tI ought to write $(a-\\eps, b+\\eps)$, or something.}\nwe can resort to our old definition of an integral.\nLet's now do this in full generality.\n\n\\section{Pullbacks}\nLet $V$ and $V'$ be finite dimensional real vector spaces (possibly different dimensions)\nand suppose $U$ and $U'$ are open subsets of each;\nnext, consider a $k$-form $\\alpha$ on $U'$.\n\nGiven a map $\\phi : U \\to U'$ we now want to define a pullback in\nmuch the same way as before.\nPicture:\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(13cm);\n\t\tbigblob(\"$U$\");\n\t\tpair p = (-1,0);\n\t\tdot(\"$p$\", p, dir(90), red);\n\t\tpair p1 = p + 1.4*dir(150);\n\t\tpair p2 = p + 1.7*dir(-50);\n\t\tdraw(p--p1, red, EndArrow);\n\t\tdraw(p--p2, red, EndArrow);\n\n\t\tadd(scale(0.8)*shift(14*dir(180))*CC());\n\t\tbigblob(\"$U'$\");\n\t\tpair q = (-0.5,0.5);\n\t\tdot(\"$q = \\phi(p)$\", q, dir(90), blue);\n\t\tpair q1 = q + 1.8*dir(-100);\n\t\tpair q2 = q + 2.3*dir(-10);\n\t\tdraw(q--q1, blue, EndArrow);\n\t\tdraw(q--q2, blue, EndArrow);\n\n\t\tdraw((-9,0)--(-3,0), EndArrow);\n\t\tlabel(\"$\\phi$\", (-6,0), dir(90));\n\t\n\t\tdraw( (0,-4)--(0,-8), EndArrow );\n\t\tlabel(\"$\\alpha$\", (0,-6), dir(0));\n\t\tlabel(\"$\\alpha_q(\\dots) \\in \\mathbb R$\", (0,-9), heavygreen);\n\n\t\tdraw( (-11,-3)--(-1,-8), EndArrow);\n\t\tlabel(\"$\\phi^\\ast \\alpha$\", (-6,-6), dir(225));\n\t\\end{asy}\n\\end{center}\n\nWell, there's a total of about one thing we can do.\nSpecifically: $\\alpha$ accepts a point in $U'$ and $k$ tangent vectors in $V'$,\nand returns a real number.\nWe want $\\phi^\\ast \\alpha$ to accept a point in $p \\in U$\nand $k$ tangent vectors $v_1, \\dots, v_k$ in $V$,\nand feed the corresponding information to $\\alpha$.\n\nClearly we give the point $q = \\phi(p)$.\nAs for the tangent vectors, since we are interested in volume, we take the\nderivative of $\\phi$ at $p$, $(D\\phi)_p$, which will scale each of our vectors $v_i$\ninto some vector in the target $V'$.\nTo cut a long story short:\n\\begin{definition}\n\tGiven $\\phi : U \\to U'$ and $\\alpha$ a $k$-form, we define the \\vocab{pullback}\n\t\\[\n\t\t(\\phi^\\ast \\alpha)_p(v_1, \\dots, v_k)\n\t\t\\defeq \\alpha_{\\phi(p)}\n\t\t\\left( (D\\phi)_p(v_1), \\dots, (D\\phi)_p(v_k) \\right).\n\t\\]\n\\end{definition}\n\nThere is a more concrete way to define the pullback using bases.\nSuppose $w_1, \\dots, w_n$ is a basis of $V'$\nand $e_1, \\dots, e_m$ is a basis of $V$.\nThus, by the projection principle (\\Cref{thm:project_principle}) \nthe map $\\phi : V \\to V'$ can be thought of as\n\\[ \\phi(v) = \\phi_1(v) w_1 +  \\dots \\phi_n(v) w_n \\]\nwhere each $\\phi_i$ takes in a $v \\in V$ and returns a real number.\nWe know also that $\\alpha$ can be written concretely as\n\\[ \\alpha = \\sum_{J \\subseteq \\{1, \\dots, n\\}} f_J w_J. \\]\nThen, we define\n\\[\n\t\\phi^\\ast\\alpha\n\t= \\sum_{I \\subseteq \\{1, \\dots, m\\}}\n\t(f_I \\circ \\phi) (D\\phi_{i_1} \\wedge \\dots \\wedge D\\phi_{i_k}).\n\\]\nA diligent reader can check these definitions are equivalent.\n\\begin{example}\n\t[Computation of a pullback]\n\tLet $V = \\RR^2$ with basis $\\ee_1$ and $\\ee_2$,\n\tand suppose $\\phi : V \\to V'$ is given by sending\n\t\\[ \\phi(a\\ee_1 + b\\ee_2) = (a^2+b^2)w_1 + \\log(a^2+1) w_2 + b^3 w_3 \\]\n\twhere $w_1$, $w_2$, $w_3$ is a basis for $V'$.\n\tConsider the form $\\alpha_q = f(q) w_1 \\wedge w_3$, where $f : V' \\to \\RR$.\n\tThen\n\t\\[ (\\phi^\\ast\\alpha)_p = f(\\phi(p)) \\cdot (2a \\ee_1^\\vee + 2b\\ee_2^\\vee) \\wedge (3b^2 \\ee_2^\\vee)\n\t\t= f(\\phi(p)) \\cdot 6ab^2 \\cdot \\ee_1^\\vee \\wedge \\ee_2^\\vee. \\]\n\\end{example}\n\nIt turns out that the pullback basically behaves nicely as possible, e.g.\\\n\\begin{itemize}\n\t\\ii $\\phi^\\ast(c\\alpha + \\beta) = c\\phi^\\ast \\alpha + \\phi^\\ast\\beta$ (linearity)\n\t\\ii $\\phi^\\ast(\\alpha\\wedge\\beta)\n\t= (\\phi^\\ast \\alpha)\\wedge(\\phi^\\ast \\beta)$\n\t\\ii $\\phi_1^\\ast(\\phi_2^\\ast(\\alpha)) \n\t= (\\phi_2 \\circ \\phi_1)^\\ast(\\alpha)$ (naturality)\n\\end{itemize}\nbut I won't take the time to check these here\n(one can verify them all by expanding with a basis).\n\t\n\\section{Cells}\n\\prototype{A disk in $\\RR^2$ can be thought of as the cell\n\t$[0,R]\\times[0,2\\pi] \\to \\RR^2$ by\n\t$(r,\\theta) \\mapsto (r\\cos\\theta)\\ee_1 + (r\\sin\\theta)\\ee_2$.}\nNow that we have the notion of a pullback,\nwe can define the notion of an integral for more general spaces.\nSpecifically, to generalize the notion of integrals we had before:\n\\begin{definition}\n\tA \\vocab{$k$-cell} is a smooth function $c : [a_1, b_1] \\times [a_2,b_2] \\times \\dots [a_k, b_k] \\to V$.\n\\end{definition}\n\\begin{example}\n\t[Examples of cells]\n\tLet $V = \\RR^2$ for convenience.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii A $0$-cell consists of a single point.\n\t\t\\ii As we saw, a $1$-cell is an arbitrary curve.\n\t\t\\ii A $2$-cell corresponds to a $2$-dimensional surface.\n\t\tFor example, the map $c : [0,R] \\times [0,2\\pi] \\to V$ by\n\t\t\\[ c : (r,\\theta) \\mapsto (r\\cos\\theta, r\\sin\\theta) \\]\n\t\tcan be thought of as a disk of radius $R$.\n\t\\end{enumerate}\n\\end{example}\nThen, to define an integral\n\\[ \\int_c \\alpha \\]\nfor a differential $k$-form $\\alpha$ and a $k$-cell $c : [0,1]^k \\to V$,\nwe simply take the pullback\n\\[ \\int_{[0,1]^k} c^\\ast \\alpha \\]\nSince $c^\\ast \\alpha$ is a $k$-form on the $k$-dimensional unit box,\nit can be written as $f(x_1, \\dots, x_n) \\; dx_1 \\wedge \\dots \\wedge dx_n$,\nso the above integral can be written as\n\\[ \\int_0^1 \\dots \\int_0^1 f(x_1, \\dots, x_n) \\; dx_1 \\wedge \\dots \\wedge dx_n \\]\n\n\\begin{example}[Area of a circle]\n\tConsider $V = \\RR^2$ and let $c : (r,\\theta) \\mapsto (r\\cos\\theta)\\ee_1 + (r\\sin\\theta)\\ee_2$\n\ton $[0,R] \\times [0,2\\pi]$ as before.\n\tTake the $2$-form $\\alpha$ which gives $\\alpha_p = \\ee_1^\\vee \\wedge \\ee_2^\\vee$ at every point $p$.\n\tThen\n\t\\begin{align*}\n\t\tc^\\ast\\alpha &= \n\t\t\\left( \\cos\\theta dr - r\\sin\\theta d\\theta \\right)\n\t\t\\wedge\n\t\t\\left( \\sin\\theta dr + r\\cos\\theta d\\theta \\right) \\\\\n\t\t&= r(\\cos^2\\theta+\\sin^2\\theta) (dr \\wedge d\\theta) \\\\\n\t\t&= r \\; dr \\wedge d\\theta\n\t\\end{align*}\n\tThus,\n\t\\[ \\int_c \\alpha\n\t\t= \\int_0^R \\int_0^{2\\pi} r \\; dr \\wedge d\\theta\n\t\t= \\pi R^2 \\]\n\twhich is the area of a circle.\n\\end{example}\n\nHere's some geometric intuition for what's happening.\nGiven a $k$-cell in $V$, a differential $k$-form $\\alpha$ accepts a point $p$ and some tangent vectors $v_1$, \\dots, $v_k$\nand spits out a number $\\alpha_p(v_1, \\dots, v_k)$,\nwhich as before we view as a signed hypervolume.\nThen the integral \\emph{adds up all these infinitesimals across the entire cell}.\nIn particular, if $V = \\RR^k$ and we take the form $\\alpha : p \\mapsto \\ee_1^\\vee \\wedge \\dots \\wedge \\ee_k^\\vee$,\nthen what these $\\alpha$'s give is the $k$th hypervolume of the cell.\nFor this reason, this $\\alpha$ is called the \\vocab{volume form} on $\\RR^k$.\n\nYou'll notice I'm starting to play loose with the term ``cell'':\nwhile the cell $c : [0,R] \\times [0,2\\pi] \\to \\RR^2$ is supposed to be a function\nI have been telling you to think of it as a unit disk (i.e.\\ in terms of its image).\nIn the same vein, a curve $[0,1] \\to V$ should be thought of as a curve in space,\nrather than a function on time.\n\nThis error turns out to be benign.\nLet $\\alpha$ be a $k$-form on $U$ and $c : [a_1, b_1] \\times \\dots \\times [a_k, b_k] \\to U$ a $k$-cell.\nSuppose $\\phi : [a_1', b_1'] \\times \\dots [a_k', b_k'] \\to [a_1, b_1] \\times \\dots \\times [a_k, b_k]$;\nit is a \\vocab{reparametrization} if $\\phi$ is bijective and $(D\\phi)_p$ is always invertible\n(think ``change of variables'');\nthus\n\\[ c \\circ \\phi : [a_1', b_1'] \\times \\dots \\times [a_k',b_k'] \\to U \\]\nis a $k$-cell as well.\nThen it is said to \\vocab{preserve orientation} if $\\det(D\\phi)_p > 0$ for all $p$\nand \\vocab{reverse orientation} if $\\det(D\\phi)_p < 0$ for all $p$.\n\\begin{exercise}\n\tWhy is it that exactly one of these cases must occur?\n\\end{exercise}\n\n\\begin{theorem}\n\t[Changing variables doesn't affect integrals]\n\tLet $c$ be a $k$-cell, $\\alpha$ a $k$-form, and $\\phi$ a reparametrization.\n\tThen\n\t\\[ \\int_{c \\circ \\phi} \\alpha\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\int_c \\alpha & \\phi \\text{ preserves orientation} \\\\\n\t\t\t- \\int_c \\alpha & \\phi \\text{ reverses orientation}.\n\t\t\\end{cases}\n\t\\]\n\\end{theorem}\n\\begin{proof}\n\tUse naturality of the pullback to reduce it to the corresponding\n\ttheorem in normal calculus.\n\\end{proof}\n\nSo for example, if we had parametrized the unit circle as $[0,1] \\times [0,1] \\to \\RR^2$\nby $(r,t) \\mapsto R\\cos(2\\pi t) \\ee_1 + R\\sin(2\\pi t) \\ee_2$, we would have arrived at the same result.\nSo we really can think of a $k$-cell just in terms of the points it specifies.\n\n\\section{Boundaries}\n\\prototype{The boundary of $[a,b]$ is $\\{b\\}-\\{a\\}$. The boundary of a square goes around its edge counterclockwise.}\nFirst, I introduce a technical term that lets us consider multiple cells at once.\n\\begin{definition}\n\tA \\vocab{$k$-chain} $U$ is a formal\n\tlinear combination of $k$-cells over $U$,\n\ti.e.\\ a sum of the form\n\t\\[ c = a_1 c_1 + \\dots + a_m c_m \\]\n\twhere each $a_i \\in \\RR$ and $c_i$ is a $k$-cell.\n\tWe define $\\int_c \\alpha = \\sum_i a_i \\int c_i$.\n\\end{definition}\nIn particular, a $0$-chain consists of several points, each with a given weight.\n\nNow, how do we define the boundary?\nFor a $1$-cell $[a,b] \\to U$, as I hinted earlier we want the answer to be the $0$-chain $\\{c(b)\\}-\\{c(a)\\}$.\nHere's how we do it in general.\n\\begin{definition}\n\tSuppose $c : [0,1]^k \\to U$ is a $k$-cell.\n\tThen the \\vocab{boundary} of $c$, denoted $\\partial c : [0,1]^{k-1} \\to U$,\n\tis the $(k-1)$-chain defined as follows.\n\tFor each $i = 1,\\dots,k$ define\n\t\\begin{align*}\n\t\tc_i^{\\text{start}}(t_1, \\dots, t_{k-1}) &\n\t\t= (t_1, \\dots, t_{i-1}, 0, t_i, \\dots, t_k) \\\\\n\t\tc_i^{\\text{stop}}(t_1, \\dots, t_{k-1}) &\n\t\t= (t_1, \\dots, t_{i-1}, 1, t_i, \\dots, t_k).\n\t\\end{align*}\n\tThen\n\t\\[ \\partial c \\defeq\n\t\\sum_{i=1}^k (-1)^{i+1} \\left( c_i^{\\text{stop}} - c_i^{\\text{start}}  \\right). \\]\n\tFinally, the boundary of a chain is the sum of the boundaries of each cell (with the appropriate weights).\n\tThat is, $\\partial(\\sum a_ic_i) = \\sum a_i \\partial c_i$.\n\\end{definition}\n\\begin{ques}\n\tSatisfy yourself that one can extend this definition to\n\ta $k$-cell $c$ defined on $c : [a_1, b_1] \\times \\dots \\times [a_k, b_k] \\to V$\n\t(rather than from $[0,1]^k \\to V$).\n\\end{ques}\n\n\\begin{example}\n\t[Examples of boundaries]\n\tConsider the $2$-cell $c : [0,1]^2 \\to \\RR^2$ shown below.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(7cm);\n\t\t\tpen e1 = heavyred;\n\t\t\tpen e2 = orange;\n\t\t\tpen e3 = olive;\n\t\t\tpen e4 = heavymagenta;\n\t\t\tdraw((0,0)--(2,0), e1, EndArrow);\n\t\t\tdraw((2,0)--(2,2), e2, EndArrow);\n\t\t\tdraw((2,2)--(0,2), e3, EndArrow);\n\t\t\tdraw((0,2)--(0,0), e4, EndArrow);\n\t\t\tlabel(scale(0.8)*\"$[0,1]^2$\", (1,1));\n\t\t\tdraw( (3,1)--(6,1), EndArrow);\n\t\t\tlabel(\"$c$\", (4.5,1), dir(90));\n\t\t\tpair p1 = (7,-1);\n\t\t\tpair p2 = (12,-2);\n\t\t\tpair p3 = (11,3);\n\t\t\tpair p4 = (8,2);\n\t\t\tfill(p1--p2--p3--p4--cycle, palecyan);\n\t\t\tdraw(p1--p2, e1, EndArrow, Margins);\n\t\t\tdraw(p2--p3, e2, EndArrow, Margins);\n\t\t\tdraw(p3--p4, e3, EndArrow, Margins);\n\t\t\tdraw(p4--p1, e4, EndArrow, Margins);\n\t\t\tdot(\"$p_1$\", p1, dir(225), blue+4);\n\t\t\tdot(\"$p_2$\", p2, dir(315), blue+4);\n\t\t\tdot(\"$p_3$\", p3, dir( 45), blue+4);\n\t\t\tdot(\"$p_4$\", p4, dir(135), blue+4);\n\t\t\tlabel(\"$c$\", (p1+p2+p3+p4)/4);\n\t\t\\end{asy}\n\t\\end{center}\n\tHere $p_1$, $p_2$, $p_3$, $p_4$ are the images of $(0,0)$, $(0,1)$, $(1,0)$, $(1,1)$, respectively.\n\tThen we can think of $\\partial c$ as\n\t\\[ \\partial c = [p_1,p_2] + [p_2,p_3] + [p_3,p_4] + [p_4,p_1] \\]\nwhere each ``interval'' represents the $1$-cell shown by the reddish arrows on the right.\n\tWe can take the boundary of this as well, and obtain an empty chain as\n\t\\[ \\partial(\\partial c) = \\sum_{i=1}^4 \\partial([p_i, p_{i+1}]) = \\sum_{i=1}^4 \\{p_{i+1}\\}-\\{p_i\\} = 0. \\]\n\\end{example}\n\n\\begin{example}\n\t[Boundary of a unit disk]\n\tConsider the unit disk given by\n\t\\[ c : [0,1] \\times [0,2\\pi] \\to \\RR^2 \\quad\\text{by}\\quad\n\t(r,\\theta) \\mapsto s\\cos(2\\pi t)\\ee_1 + s\\sin(2\\pi t)\\ee_2. \\]\n\tThe four parts of the boundary are shown in the picture below:\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(7cm);\n\t\t\tpen e1 = heavyred;\n\t\t\tpen e2 = orange;\n\t\t\tpen e3 = olive;\n\t\t\tpen e4 = heavymagenta;\n\t\t\tdraw((0,0)--(2,0), e1, EndArrow);\n\t\t\tdraw((2,0)--(2,2), e2, EndArrow);\n\t\t\tdraw((2,2)--(0,2), e3, EndArrow);\n\t\t\tdraw((0,2)--(0,0), e4, EndArrow);\n\t\t\tlabel(\"$r$\", (2,0), dir(-45));\n\t\t\tlabel(\"$\\theta$\", (0,2), dir(135));\n\n\t\t\tlabel(scale(0.8)*\"$[0,1]^2$\", (1,1));\n\t\t\tdraw( (3,1)--(6,1), EndArrow);\n\t\t\tlabel(\"$c$\", (4.5,1), dir(90));\n\n\t\t\tpair O = (9,1);\n\t\t\tpair P = O + 2*dir(0);\n\t\t\tfill(CP(O,P), palecyan);\n\t\t\treal eps = 0.3;\n\t\t\tdraw(shift(0,eps) * (O--P), e1, EndArrow, Margins);\n\t\t\tdraw(shift(0,-eps) * (P--O), e3, EndArrow, Margins);\n\t\t\tdraw(CP(O,P), e2, EndArrow, Margins);\n\t\t\tdot(O, e4+4);\n\t\t\\end{asy}\n\t\\end{center}\n\tNote that two of the arrows more or less cancel each other out when they are integrated.\n\tMoreover, we interestingly have a \\emph{degenerate} $1$-cell at the center of the circle;\n\tit is a constant function $[0,1] \\to \\RR^2$ which always gives the origin.\n\\end{example}\n\nObligatory theorem, analogous to $d^2=0$ and left as a problem.\n\\begin{theorem}[The boundary of the boundary is empty]\n\t$\\partial^2 = 0$, in the sense that for any $k$-chain $c$ we have $\\partial^2(c) = 0$.\n\\end{theorem}\n\n\\section{Stokes' theorem}\n\\prototype{$\\int_{[a,b]} dg = g(b) - g(a)$.}\n\nWe now have all the ingredients to state Stokes' theorem for cells.\n\\begin{theorem}\n\t[Stokes' theorem for cells]\n\tTake $U \\subseteq V$ as usual, let $c : [0,1]^k \\to U$ be a $k$-cell\n\tand let $\\alpha : U \\to \\Lambda^{k-1}(V^\\vee)$ be a $k-1$-form.\n\tThen\n\t\\[ \\int_c d\\alpha = \\int_{\\partial c} \\alpha. \\]\n\tIn particular, if $d\\alpha = 0$ then the left-hand side vanishes.\n\\end{theorem}\nFor example, if $c$ is the interval $[a,b]$ then $\\partial c = \\{b\\} - \\{a\\}$,\nand thus we obtain the fundamental theorem of calculus.\n\n\\section\\problemhead\n\\begin{dproblem}[Green's theorem]\n\tLet $f,g : \\RR^2 \\to \\RR$ be smooth functions.\n\tProve that\n\t\\[ \\int_c \\left( \\fpartial gx - \\fpartial fy \\right) \\; dx \\wedge dy\n\t= \\int_{\\partial c} (f \\; dx + g \\; dy). \\]\n\t\\begin{hint}\n\t\tDirect application of Stokes' theorem to $\\alpha = f \\; dx + g \\; dy$.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\tShow that $\\partial^2 = 0$.\n\t\\label{prob:partial_zero}\n\t\\begin{hint}\n\t\tThis is just an exercises in sigma notation.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}[Pullback and $d$ commute]\n\tLet $U$ and $U'$ be open sets of vector spaces $V$ and $V'$\n\tand let $\\phi : U \\to U'$ be a smooth map between them.\n\tProve that for any differential form $\\alpha$ on $U'$ we have\n\t\\[ \\phi^\\ast(d\\alpha) = d(\\phi^\\ast\\alpha). \\]\n\t\\begin{hint}\n\t\tThis is a straightforward (but annoying) computation.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}[Arc length isn't a form]\n\tShow that there does \\emph{not} exist a $1$-form $\\alpha$ on $\\RR^2$ such that\n\tfor a curve $c : [0,1] \\to \\RR^2$,\n\tthe integral $\\int_c \\alpha$ gives the arc length of $c$.\n\t\\begin{hint}\n\t\tWe would want $\\alpha_p(v) = \\norm{v}$.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tAn \\vocab{exact} $k$-form $\\alpha$ is one satisfying $\\alpha = d\\beta$ for some $\\beta$.\n\tProve that\n\t\\[ \\int_{C_1} \\alpha = \\int_{C_2} \\alpha \\]\n\twhere $C_1$ and $C_2$ are any concentric circles in the plane\n\tand $\\alpha$ is some exact $1$-form.\n\t\\begin{hint}\n\t\tShow that $d^2=0$ implies $\\int_{\\partial c} \\alpha = 0$ for exact $\\alpha$.\n\t\tDraw an annulus.\n\t\\end{hint}\n\\end{problem}\n", "meta": {"hexsha": "7104bb7582d203fe12ddbf61ed403300f860b0fe", "size": 18440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/diffgeo/stokes.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/diffgeo/stokes.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/diffgeo/stokes.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.0206185567, "max_line_length": 122, "alphanum_fraction": 0.6293926247, "num_tokens": 6966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.6249809190084266}}
{"text": "\\RequirePackage{luatex85}\n\\documentclass[addpoints]{exam}\n\\usepackage{multicol, amsmath}\n\\everymath{\\displaystyle}\n\\begin{document}\n\\begin{questions}\n\\section{Elementary algebra. Equations.}\n\\question Solve $2=-\\frac32+b$. \\qquad\\qquad\n\\begin{oneparchoices}\n\t\\correctchoice $\\frac83$\n\t\\choice $\\frac43$\n\t\\choice 3\n\t\\end{oneparchoices}\n\n\\section{Elementary algebra. Functions.}\n\\question Let $f(x) = x^2$. Find $f(5)$.\n\\begin{oneparchoices}\n\t\\correctchoice 25\n\t\\choice $f(25)$\n\t\\end{oneparchoices}\n\n\\section{Algebra. Functions. Composition.}\n\\question Let $f(x) = -2+\\sqrt{x+3}$ and let $g(x) = \\frac1x$. Find the composition $(f\\circ g)(x)$.\n\\begin{multicols}3\n\\begin{choices}\n\t\\choice $\\frac1{-2+\\sqrt{x+3}}$\n\t\\choice $-2+\\sqrt{x+3}$\n\t\\choice $-2+\\frac1{\\sqrt{x+3}}$\n\t\\choice $-2+\\frac1{\\sqrt x+3}$\n\t\\correctchoice $-2+\\sqrt{\\frac1x+3}$\n\t\\end{choices}\n\t\\end{multicols}\n\n\\section{Algebra. Functions. Domain.}\n\\question Find the domain of $-2+\\sqrt{3+1/x}$.\n\\begin{multicols}3\n\\begin{choices}\n\t\\choice $(-\\infty,0)\\cup(0,\\infty)$ %6/30\n\t\\choice $(-\\infty,\\infty)$ %5/30\n\t\\choice $[0,\\infty)$ %5/30\n\t\\choice $(1,\\infty)$ %3/30\n\t\\choice $(-\\infty,0)\\cup(0,1)$ %3/30\n\t\\correctchoice $(-\\infty,-\\tfrac13]\\cup(0,\\infty)$ %2/30\n\t\\end{choices}\n\t\\end{multicols}\n\\question Find the domain of $\\frac1{-2+\\sqrt{3+x}}$.\n\\begin{multicols}3\n\\begin{choices}\n\t\\correctchoice $[-3,1)\\cup(1,\\infty)$\n\t\\choice $(-\\infty,0)\\cup(0,\\infty)$\n\t\\choice $(-\\infty,\\infty)$\n\t\\choice $(-\\infty,1)\\cup(1,\\infty)$\n\t\\choice $(-\\infty,-3)\\cup(-3,\\infty)$\n\t\\end{choices}\n\t\\end{multicols}\n\n\\section{Algebra. Trig. Right triangle apps.}\n\\question The angle of elevation is $26^\\circ$. Which diagram is correctly labelled.\n\n\n\\section{Calculus I. Limits. Algebraic.}\n\\question Find $\\lim_{x\\to 25} \\frac{\\sqrt x-5}{x-25}$. \\qquad\\qquad\n\\begin{oneparchoices}\n\t\\correctchoice $\\frac1{10}$\n\t\\choice $\\frac1{50}$ % +reasoning/level; +student stats\n\t\\choice $\\frac1{60}$\n\t\\choice $\\frac15$\n\t\\choice 0\n\t\\choice DNE\n\t\\choice 0.10001\n\t\\end{oneparchoices}\n\\question Find $\\lim_{h\\to0} \\frac0h$. \\qquad\\qquad\n\\begin{oneparchoices}\n\t\\correctchoice 0\n\t\\choice 1\n\t\\choice $\\infty$\n\t\\choice DNE\n\t\\end{oneparchoices}\n\n\n\\section{Calculus Lab}\n\\question Write $x^{1/(1-x)}$ using computer notation.\n\\begin{oneparchoices}\n\t\\correctchoice $x\\wedge(1/(1-x))$\n\t\\choice $(x\\wedge 1)/(1-x))$\n\t\\choice $x\\wedge 1/(1-x)$\n\t\\end{oneparchoices}\n\n\\end{questions}\n\\end{document}", "meta": {"hexsha": "5b4cfcff231a80a59e98e9b94e46f5719eaa3f03", "size": 2410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "distractopedia.tex", "max_stars_repo_name": "gatewaycat/latex", "max_stars_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-11T12:20:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T12:20:40.000Z", "max_issues_repo_path": "distractopedia.tex", "max_issues_repo_name": "gatewaycat/byzorn", "max_issues_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "distractopedia.tex", "max_forks_repo_name": "gatewaycat/byzorn", "max_forks_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_forks_repo_licenses": ["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.7777777778, "max_line_length": 100, "alphanum_fraction": 0.6751037344, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728003, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6249809163673106}}
{"text": "\\chapter{Assignment- Differential Equations}\n\\section{MCQ}\n\\begin{enumerate}\n\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\t\\int \\frac{y}{\\sqrt{1+y^{2}}} d y+\\int \\frac{x}{\\sqrt{1+x^{2}}} d x=c \\Rightarrow \\sqrt{1+y^{2}}+\\sqrt{1+x^{2}}=c\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\t\\end{answer}\n\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tx d y&=-\\cot y d x \\Rightarrow \\tan y d y=-\\frac{d x}{x}\\\\\n\t\t\\Rightarrow \\int \\tan y d y&=-\\int \\frac{d x}{x}+\\log A \\Rightarrow \\log \\sec y=-\\log x+\\log A \\Rightarrow \\log \\sec y=\\log \\frac{A}{x}\\\\\n\t\t\\Rightarrow x&=A \\cos y \\Rightarrow \\sqrt{2}=A \\cos \\frac{\\pi}{4} \\Rightarrow A=2 \\Rightarrow x=2 \\cos y\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\t\\end{answer}\n\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{d y}{d x}&=-\\frac{x}{y+1} \\Rightarrow x d x+y d y+d y=0 \\Rightarrow \\frac{x^{2}}{2}+\\frac{y^{2}}{2}+y=C_{1} \\Rightarrow x^{2}+y^{2}+2 y=2 C_{1}\\\\\n\t\t\\Rightarrow(x-0)^{2}+(y+1)^{2}&=2 C_{1}+1=C\n\t\t\\intertext{which is family of circles with different radii.}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\t\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\tx y \\frac{d y}{d x}&=3 y^{2}+x^{2} \\Rightarrow \\frac{d y}{d x}=\\frac{3 y^{2}+x^{2}}{x y}\\text{ which is a homogeneous equation.}\\\\\n\t\\text{Put }y&=v x \\Rightarrow \\frac{d y}{d x}=v+x \\frac{d v}{d x} \\Rightarrow v+x \\frac{d v}{d x}=\\frac{3 v^{2} x^{2}+x^{2}}{v x^{2}}=\\frac{3 v^{2}+1}{v}\\\\\n\t\\Rightarrow x \\frac{d v}{d x}&=\\frac{3 v^{2}+1}{v}-v=\\frac{2 v^{2}+1}{v} \\Rightarrow \\frac{v}{2 v^{2}+1} d v=\\frac{d x}{x}\\\\\n\t\\Rightarrow \\frac{1}{4} \\ln \\left(2 v^{2}+1\\right)&=\\ln x+\\ln c^{\\prime} \\Rightarrow \\ln \\left(2 v^{2}+1\\right)=\\ln x^{4}+\\ln c \\Rightarrow\\left(2 v^{2}+1\\right)=c x^{4}\\\\\n\t\\Rightarrow\\left(2 \\frac{y^{2}}{x^{2}}+1\\right)&=c x^{4}\\\\\n\ty=2\\text{ when }x&=1 \\Rightarrow\\left(2 \\frac{4}{1}+1\\right)=c .1 \\Rightarrow c=9 \\Rightarrow 2 y^{2}+x^{2}=9 x^{6}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{d y}{d x}=\\frac{x+2 y-1}{x+2 y+1}\\text{. Let }x+2 y&=z \\Rightarrow 1+2 \\frac{d y}{d x}=\\frac{d z}{d x} \\Rightarrow \\frac{d z}{d x}=\\frac{3 z-1}{z+1}\\\\\n\t\\Rightarrow \\int\\left(\\frac{1}{3}+\\frac{1}{4}-\\frac{1}{3 z-1}\\right) d z&=\\int d x+c \\Rightarrow \\frac{z}{3}+\\frac{4}{9} \\log (3 z-1)=x+c\\\\\n\t\\Rightarrow 3 x-3 y+a&=2 \\log (3 x+6 y-1)\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{I.F. }=e^{\\int 3 d x}&=e^{3 x} \\Rightarrow y \\times e^{3 x}=\\int e^{2 x} \\times e^{3 x} d x+c \\Rightarrow y \\times e^{3 x}=\\frac{e^{5 x}}{5}+c \\Rightarrow y=c_{1} e^{2 x}+c_{2} e^{-3 x}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{d y}{d x}+\\frac{1}{x} y&=x^{3} \\Rightarrow \\mathrm{I} . F .=e^{\\int \\frac{1}{x} d x}=e^{\\ln x}=x\\\\\n\t\\Rightarrow y \\times x&=\\int x^{3} \\times x d x+c \\Rightarrow y \\times x=\\frac{x^{5}}{5}+c \\Rightarrow y=\\frac{x^{4}}{5}+\\frac{c}{x}\\\\\n\\text{\tSince }y&=1\\text{ at }x=1 \\Rightarrow 1=\\frac{1}{5}+\\frac{c}{1} \\Rightarrow c=\\frac{4}{5} \\Rightarrow y=\\frac{x^{4}}{5}+\\frac{4}{5 x}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{d x}{d t}+\\frac{K_{2}}{K_{1}} x&=\\frac{K_{3}}{K_{1}} \\Rightarrow \\frac{d x}{d t}+A x=B \\Rightarrow I . F .=e^{\\int A d t}=e^{A t} \\Rightarrow x \\times e^{A t}=\\int\\left(B \\times e^{A t}\\right) d t+c\\\\\n\t\\Rightarrow x \\times e^{A t}&=B \\times \\frac{e^{A t}}{A}+c \\Rightarrow x=c_{1}+c e^{-A t}\\\\\n\t\\text{Since }x&=0\\text{ at }t=0 \\Rightarrow c_{1}+c=0 \\Rightarrow c_{1}=-c \\Rightarrow x=c\\left(1-e^{-A t}\\right)\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Divide by }y t \\Rightarrow \\frac{1}{y} \\frac{d y}{d t}+\\frac{1}{t} \\log y&=e^{t}\\text{, put }\\log y=z \\Rightarrow \\frac{1}{y} \\frac{d y}{d t}=\\frac{d z}{d t}\\\\\n\t\\Rightarrow \\frac{d z}{d t}+\\frac{1}{t} \\cdot z&=e^{t} \\Rightarrow I \\cdot F=e^{\\int_{t}^{1} d t}=e^{\\log t}=t\\\\\n\t\\Rightarrow z t&=\\int t e^{t} d t+c \\Rightarrow t \\log y=t e^{t}-e^{t}+c\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(1+y^{2}\\right) d x&=\\left(\\tan ^{-1} y-x\\right) d y \\Rightarrow \\frac{d x}{d y}=\\frac{\\tan ^{-1} y-x}{1+y^{2}}\\\\\n\t\\Rightarrow \\frac{d x}{d y}+\\frac{x}{1+y^{2}}&=\\frac{\\tan ^{-1} y}{1+y^{2}}.\\text{ This is a linear differential equation.}\\\\\n\tI . F .&=e^{\\int \\frac{1}{1+y^{2}} d y}=e^{\\tan ^{-1} y}\\\\\n\t\\text{\tIts solution is }x . e^{\\tan ^{-1} y}&=\\int e^{\\tan ^{-1} y} \\frac{\\tan ^{-1} y}{1+y^{2}} d y+c\\\\\n\t\\text{Put }\\tan ^{-1} y&=t\\text{ on R.H.S. so that }\\frac{1}{1+y^{2}} d y=d t\\\\\n\tx . e^{\\tan ^{-1} y}&=\\int e^{t} t d t+C=t . e^{t}-e^{t}+C=e^{\\tan ^{-1} y}\\left(\\tan ^{-1} y-1\\right)+C\\\\\n\t\\Rightarrow x&=\\left(\\tan ^{-1} y-1\\right)+c e^{-\\tan ^{-1} y}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\ty \\log y \\frac{d x}{d y}+x-\\log y&=0 \\Rightarrow \\frac{d x}{d y}+\\frac{x}{y \\log y}=\\frac{1}{y}\\\\\n\tI . F .&=e^{\\int \\frac{1}{y \\log y} d y}=e^{\\log (\\log y)}=\\log y\\\\\n\t\\text{Its solution is }x \\cdot \\log y&=\\int \\frac{1}{y}(\\log y) d y+c \\Rightarrow x \\cdot \\log y=\\frac{1}{2}(\\log y)^{2}+c\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\tM&=\\left(e^{y}+2\\right) \\sin x, N=-e^{y} \\cos x \\Rightarrow \\frac{\\partial M}{\\partial y}=e^{y} \\sin x, \\frac{\\partial N}{\\partial x}=e^{y} \\sin x\\\\\n\t\\Rightarrow \\frac{\\partial M}{\\partial y}&=\\frac{\\partial N}{\\partial x} \\Rightarrow \\int\\left(e^{y}+2\\right) \\sin x d x+0=c^{\\prime} \\Rightarrow\\left(e^{y}+2\\right) \\cos x=-c^{\\prime}=c\n\t\\end{align*}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\tM&=\\left(y^{4}+2 y\\right), N=\\left(x y^{3}+2 y^{4}-4 x\\right)\\\\\n\t\\Rightarrow \\frac{\\partial M}{\\partial y}&=4 y^{3}+2, \\frac{\\partial N}{\\partial x}=y^{3}-4 \\Rightarrow \\frac{\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}}{M}=-\\frac{3}{y}=f(y)\\\\\n\\text{\tthen I.F. }&=e^{\\int \\frac{3}{y} d y}=e^{-3 \\log y}=\\frac{1}{y^{3}}\\\\\n\\text{Multiplying by }&\\frac{1}{y^{3}}\\text{ we get }\\frac{1}{y^{3}}\\left(y^{4}+2 y\\right) d x+\\frac{1}{y^{3}}\\left(x y^{3}+2 y^{4}-4 x\\right) d y=0\\text{ which is an exact}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(D^{2}-3 D+2\\right)&=0 \\Rightarrow D=1,2 \\Rightarrow C . F .=c_{1} e^{t}+c_{2} e^{2 t}\\\\\n\tP . I .&=\\frac{1}{\\left(D^{2}-3 D+2\\right)} e^{3 t}=\\frac{1}{\\left(3^{2}-3 \\times 3+2\\right)} e^{3 t}=\\frac{1}{2} e^{3 t}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(D^{2}+2 D+101\\right)&=0 \\Rightarrow D=\\frac{-2 \\pm \\sqrt{4-4 \\times 101}}{2}=\\frac{-2 \\pm 20 i}{2}\\\\&=-1 \\pm 10 iC.F. =e^{-x}(A \\cos 10 x+B \\sin 10 x)\\\\\n\tP.I. &=\\frac{1}{\\left(D^{2}+2 D+101\\right)} 10.4 e^{x}=\\frac{1}{(1+2 \\times 1+101)} 10.4 e^{x}=\\frac{10.4}{104} e^{x}=0.1 e^{x}\\\\\n\t\\Rightarrow y&=e^{-x}(A \\cos 10 x+B \\sin 10 x)+0.1 e^{x}\\\\\n\t\\because y(0)&=1.1 \\Rightarrow 0=1(A+0)+0.1=1.1 \\Rightarrow A=1 .\\\\\n\t\\Rightarrow y&=e^{-x}(\\cos 10 x+B \\sin 10 x)+0.1 e^{x}\\\\\n\t\\Rightarrow \\frac{d y}{d x}&=e^{-x}(-10 \\sin 10 x+10 B \\cos 10 x)-e^{-x}(\\cos 10 x+B \\sin 10 x)+0.1 e^{x}\\\\\n\t\\left.\\because \\frac{d y}{d x}\\right|_{x=0}&=-0.9 \\Rightarrow-0.9=1(-0+10 B)-1(1+0)+0.1 \\Rightarrow 10 B=1-0.1-0.9 \\Rightarrow B=0 .\\\\\n\t\\Rightarrow y&=e^{-x} \\cos 10 x+0.1 e^{x}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(D^{2}+4\\right)=0 \\Rightarrow D=+2 i,-2 i \\Rightarrow C . F .=A \\cos 2 t+B \\sin 2 t\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(D^{2}-1\\right)&=0 \\Rightarrow D=+1,-1 \\Rightarrow C . F .=c_{1} e^{t}+c_{2} e^{-t}\\\\\n\tP.I. &=\\frac{1}{\\left(D^{2}-1\\right)} 2\\left(\\frac{e^{t}+e^{-t}}{2}\\right)=\\frac{1}{\\left(D^{2}-1\\right)}\\left(e^{t}+e^{-t}\\right)=t \\frac{1}{2 D}\\left(e^{t}+e^{-t}\\right)=\\frac{t}{2}\\left(e^{t}-e^{-t}\\right)\\\\\n\t\\Rightarrow y(t)&=c_{1} e^{t}+c_{2} e^{-t}+\\frac{t}{2}\\left(e^{t}-e^{-t}\\right)\\\\\n\ty(0)&=0 \\Rightarrow c_{1}+c_{2}=0 \\\\\n\t\\frac{d y}{d t}&=c_{1} e^{t}-c_{2} e^{-t}+\\frac{1}{2}\\left(e^{t}-e^{-t}\\right)+\\frac{t}{2}\\left(e^{t}+e^{-t}\\right),\\left.\\frac{d y}{d t}\\right|_{t=0}=0 \\Rightarrow c_{1}-c_{2}=0\\\\\n\\text{\tThus }c_{1}&=c_{2}=0 \\Rightarrow y(t)=\\frac{t}{2}\\left(e^{t}-e^{-t}\\right)=t \\sinh (t)\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(D^{2}-1\\right)&=0 \\Rightarrow D=+1,-1 \\Rightarrow C . F .=C_{1} e^{t}+C_{2} e^{-t}\\\\\n\tP.I. &=\\frac{1}{\\left(D^{2}-1\\right)} 2\\left(\\frac{e^{t}-e^{-t}}{2}\\right)=\\frac{1}{\\left(D^{2}-1\\right)}\\left(e^{t}-e^{-t}\\right)=t \\frac{1}{2 D}\\left(e^{t}-e^{-t}\\right)=\\frac{t}{2}\\left(e^{t}+e^{-t}\\right)\\\\\n\t\\Rightarrow y(t)&=c_{1} e^{t}+c_{2} e^{-t}+\\frac{t}{2}\\left(e^{t}+e^{-t}\\right)\\\\\n\ty(0)&=0 \\Rightarrow c_{1}+c_{2}=0\\\\\n\t\\frac{d y}{d t}&=c_{1} e^{t}-c_{2} e^{-t}+\\frac{1}{2}\\left(e^{t}+e^{-t}\\right)+\\left.\\frac{t}{2}\\left(e^{t}-e^{-t}\\right) \\Rightarrow \\frac{d y}{d t}\\right|_{t=0}=0 \\Rightarrow c_{1}-c_{2}=0\\\\\n\\text{\tThus }c_{1}&=c_{2}=0 \\Rightarrow y(t)=\\frac{t}{2}\\left(e^{t}+e^{-t}\\right)=t \\cosh (t)\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\end{enumerate}\n\\section{NAT}\n\\begin{enumerate}\n\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{d x}{d t}&=x^{2} \\Rightarrow \\int \\frac{d x}{x^{2}}=\\int d t \\Rightarrow \\frac{x^{-2+1}}{-2+1}=t+C \\Rightarrow \\frac{-1}{x}=t+C\\\\\n\t\t\\Rightarrow x(0)&=1 \\Rightarrow \\frac{-1}{1}=0+C \\Rightarrow C=-1 \\Rightarrow \\frac{-1}{x}=t-1 \\Rightarrow x=\\frac{1}{1-t}\\text{ as }t \\rightarrow 1, x\\text{ blows up.}\\\\\n\t\t\\end{align*}\n\t\t\tSo the correct answer is 1\n\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tM&=\\left(x y^{2}+\\lambda x^{2} y\\right), N=(x+y) x^{2} d y \\Rightarrow \\frac{\\partial M}{\\partial y}=2 x y+\\lambda x^{2}, \\frac{\\partial N}{\\partial x}=3 x^{2}+2 x y\\\\\n\t\t\\Rightarrow \\frac{\\partial M}{\\partial y}&=\\frac{\\partial N}{\\partial x} \\Rightarrow \\lambda=3\n\t\t\\end{align*}\n\t\t\tSo the correct answer is 3\n\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\tP.I. &=\\frac{1}{D^{2}+D+1} \\cdot \\cos 2 x=\\frac{1}{-2^{2}+D+1} \\cdot \\cos 2 x=\\frac{1}{D-3} \\cdot \\cos 2 x\\\\\n\t\t\t\\Rightarrow P . I .&=\\frac{D+3}{D^{2}-9} \\cdot \\cos 2 x=\\frac{D+3}{-2^{2}-9} \\cdot \\cos 2 x=\\frac{1}{13}(2 \\sin 2 x-3 \\cos 2 x)\n\t\t\\end{align*}\n\t\tSo the correct answer is 13\n\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\tP \\cdot I .&=\\frac{1}{D^{2}+2 D+2} \\sin x=\\frac{1}{-1+2 D+2} \\sin x=\\frac{2 D-1}{4 D^{2}-1} \\sin x=-\\frac{1}{5}(2 D-1) \\sin x\\\\\n\t\\Rightarrow P \\cdot I .&=-\\frac{1}{5}(2 \\cos x-\\sin x)=\\frac{1}{5}(\\sin x-2 \\cos x)\n\t\\end{align*}\n\t\tSo the correct answer is 2\n\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\t\\begin{answer}\n\t\t\t\\begin{align*}\n\t\t\tP \\cdot I \\cdot&=\\frac{1}{D^{2}-5 D+6} e^{t} \\cos 2 t=e^{t} \\frac{1}{(D+1)^{2}-5(D+1)+6} \\cos 2 t\\\\\n\t\t\tP \\cdot I \\cdot&=e^{t} \\frac{1}{D^{2}-3 D+2} \\cos 2 t=e^{t} \\frac{1}{-4-3 D+2} \\cos 2 t\\\\\n\t\t\tP \\cdot I \\cdot&=-e^{t} \\frac{1}{3 D+2} \\cos 2 t=-e^{t} \\frac{3 D-2}{9 D^{2}-4} \\cos 2 t\\\\\n\t\t\tP \\cdot I \\cdot&=-e^{t} \\frac{3 D-2}{9 \\times-4-4} \\cos 2 t=\\frac{e^{t}}{40}(3 D-2) \\cos 2 t=-\\frac{e^{t}}{20}(3 \\sin 2 t+\\cos 2 t)\n\t\t\t\\end{align*}\n\t\t\t\tSo the correct answer is 3\n\t\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\\begin{answer}\n\t\\begin{align*}\n\tP . I .&=\\frac{1}{D^{2}-4 D+4} \\cdot x^{3} e^{2 x}=e^{2 x} \\frac{1}{(D+2)^{2}-4(D+2)+4} \\cdot x^{3}\\\\\n\t\\Rightarrow P . I .&=e^{2 x} \\frac{1}{D^{2}} \\cdot x^{3}=e^{2 x} \\frac{1}{D}\\left(\\frac{x^{4}}{4}\\right)=e^{2 x} \\frac{x^{5}}{20}\n\t\\end{align*}\n\t\tSo the correct answer is 5\n\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t P.I. &=\\left[D^{2}+5 D+4\\right]^{-1}(3-2 x)=\\frac{1}{4}\\left[1+\\frac{5}{4} D+\\frac{5}{4} D^{2}\\right]^{-1}(3-2 x)\\\\\n\t\t\\Rightarrow P.I. &=\\frac{1}{4}\\left[1-\\frac{5}{4} D-\\frac{5}{4} D^{2}\\right](3-2 x)=\\frac{1}{4}\\left[3-2 x-\\frac{5}{4} \\times-2\\right]=\\frac{1}{8}[11-4 x]\n\t\t\\end{align*}\n\t\tSo the correct answer is 11\n\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\left(D^{2}+1\\right)&=0 \\Rightarrow D=\\pm i \\Rightarrow y=c_{1} e^{i x}+c_{2} e^{-i x}=A \\cos x+B \\sin x\\\\\n\t\t\\because y(0)&=1 \\Rightarrow 1=A \\times 1+B \\times 0 \\Rightarrow A=1 \\Rightarrow \\dot{y}=-A \\sin x+B \\cos x \\\\\n\t\t\\Rightarrow \\dot{y}(0)&=1 \\Rightarrow 1=-A \\times 0+B \\times 1 \\Rightarrow B=1 \\Rightarrow y=\\cos x+\\sin x\\\\\n\t\t\\text{For maxima, }y^{\\prime}&=-\\sin x+\\cos x=0 \\Rightarrow \\sin x=\\cos x \\Rightarrow x=45^{\\circ}\\\\\n\t\ty^{\\prime \\prime}&=-\\cos x-\\sin x, \\quad y^{\\prime \\prime}<0 \\text { for } x=45^{\\circ} \\\\\n\t\t\\Rightarrow y(\\max )&=\\cos 45^{\\circ}+\\sin 45^{\\circ}=\\frac{1}{\\sqrt{2}}+\\frac{1}{\\sqrt{2}}=\\frac{2}{\\sqrt{2}}=\\sqrt{2}\n\t\t\\end{align*}\n\t\t\tSo the correct answer is 1.41\n\t\\end{answer}\n\t\t\\item $\\left. \\right. $\n\t\t\\begin{answer}\n\t\t\t\\begin{align*}\n\t\t\t\t\\left(D^{2}+2 \\alpha D+1\\right)=0 \\Rightarrow m_{1}, m_{1}=\\frac{-2 \\alpha \\pm \\sqrt{4 \\alpha^{2}-4}}{2} \\quad \\because m_{1}=m_{1} \\Rightarrow \\alpha=1\n\t\t\t\\end{align*}\n\t\t\tSo the correct answer is 1\n\t\t\\end{answer}\n\\item $\\left. \\right. $\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\left(D^{2}+3 D+2\\right)&=0 \\Rightarrow D=-1,-2 \\Rightarrow x(t)=C_{1} e^{-t}+C_{2} e^{-2 t}\\\\\n\t\t \\Rightarrow x(1)&=\\frac{10}{e}=C_{1} e^{-1}+C_{2} e^{-2} \\Rightarrow C_{1}+C_{2} e^{-1}=10\\text{ and }C_{1}+C_{2}=20\\\\\n\t\t\\Rightarrow C_{1}&=\\frac{10 e-20}{e-1} ; C_{2}=\\frac{10 e}{e-1} \\\\\n\t\tx(2)&=\\left(\\frac{10 e-20}{e-1}\\right) e^{-2}+\\left(\\frac{10 e}{e-1}\\right) e^{-4}=0.8566\n\t\t\\end{align*}\n\t\t\tSo the correct answer is 0.8566\n\t\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "02017243feae654c138210b5edb5edc9e442f141", "size": 14212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment Differential Equations solutions.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 solutions.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 solutions.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": 53.4285714286, "max_line_length": 211, "alphanum_fraction": 0.5678300028, "num_tokens": 6575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6249809156005983}}
{"text": "% !TEX root = Thesis.tex\n\\section{Relational Model}\n\tThe relational data model, in its most basic form, is built upon sets and tuples.  Each of these sets consist of a set of finite values.  Tuples are constructed from these sets to form relations.\n\t\n\t\\begin{defn}[Named Tuple]\n\t\\label{def:named-tuple}\n\t\tA named tuple \\(\\tuple\\) is an instance of a relation \\(\\relation\\), consisting of values corresponding to the attributes of \\(\\relation\\).  For example,\n\t\\end{defn}\n\t\n\t\\begin{ex}\n\t\tGiven a tuple \\(\\tuple = \\{\\text{code}: \\text{``CDPS 101''}, \\text{title}: \\text{``Human-Mutant Relations''}, \\text{subject}: \\text{``CDPS''}\\}\\), we denote the attributes of \\(\\tuple\\) as \\(\\attributes{\\tuple} = \\{\\text{code}, \\text{title}, \\text{subject}\\}\\).  The values are \\(\\tuple\\lbrack\\text{code}\\rbrack = \\text{``CDPS 101''}\\), \\(\\tuple\\lbrack\\text{title}\\rbrack = \\text{``Human-Mutant Relations''}\\), and \\(\\tuple\\lbrack\\text{subject}\\rbrack = \\text{``CDPS''}\\).\n\t\\end{ex}\n\t\n\t\\begin{defn}[Relation]\n\t\\label{def:relation}\n\t\tA relation \\(\\relation\\) is a set of named tuples, \\(\\relation = \\{\\tuple_1, \\tuple_2, \\dotsc, \\tuple_n\\}\\), such that all the named tuples share the same attributes.\n\t\t\\begin{equation}\n\t\t\t\\forall \\tuple, \\tuple' \\in \\relation, \\attributes{\\tuple} = \\attributes{\\tuple'}\n\t\t\\end{equation}\n\t\\end{defn}\n\t\n\t\\begin{ex}\n\t\\label{ex:relation}\n\t\tAn example Course relation, \\(\\relation\\), would be\n\t\t\\[\n\t\t\t\\relation = \\left\\{\n\t\t\t\t\\begin{array}{llllll}\n\t\t\t\t\t\\{\\text{code} &: \\text{``CDPS 101''}, &\\text{title} &: \\text{``Human-Mutant Relations''}, &\\text{subject} &: \\text{``CDPS''}\\}, \\\\\n\t\t\t\t\t\\{\\text{code} &: \\text{``CDPS 201''}, &\\text{title} &: \\text{``Humans and You''}, &\\text{subject} &: \\text{``CDPS''}\\}, \\\\\n\t\t\t\t\t\\{\\text{code} &: \\text{``MATH 360''}, &\\text{title} &: \\text{``Complex Analysis''}, &\\text{subject} &: \\text{``MATH''}\\}\n\t\t\t\t\\end{array}\n\t\t\t\\right\\}\n\t\t\\]\n\t\\end{ex}\n\t\t\n\tRelations are typically referred to, and represented, as tables.  \\cref{ex:relation} is shown in its tabular form in \\cref{tbl:course-relation}.\n\t\n\t\\begin{table}\n\t\t\\centering\n\t\t\n\t\t\\begin{tabular}{lll}\n\t\t\t\\toprule\n\t\t\tcode & title & subject \\\\\n\t\t\t\\midrule\n\t\t\tCDPS 101 & Human-Mutant Relations & CDPS \\\\\n\t\t\tCDPS 201 & Humans and You & CDPS \\\\\n\t\t\tMATH 360 & Complex Analysis & MATH \\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\n\t\t\\caption{Tabular representation of the Course relation}\n\t\t\\label{tbl:course-relation}\n\t\\end{table}\n\t\n\t\\begin{defn}[Keys]\n\t\\label{def:keys}\n\t\tKeys are constraints imposed on relations.\tA key constraint \\(\\key\\) on a relation \\(\\relation\\) is a subset of \\(\\attributes{\\relation}\\) which must uniquely identify a tuple.\tFormally, we say \\(\\relation\\) satisfies the key constraint \\(\\key\\), denoted as \\(\\relation \\models \\key\\), subject to\n\t\t\\[\n\t\t\t\\forall \\tuple, \\tuple' \\in \\relation, \\tuple \\not= \\tuple' \\implies \\tuple\\lbrack\\key\\rbrack \\not= \\tuple'\\lbrack\\key\\rbrack\n\t\t\\]\n\t\t\n\t\tFor example, in \\cref{tbl:course-relation}, the relation satisfies the key constraint \\(\\{\\text{code}\\}\\) or \\(\\{\\text{title}\\}\\), but not \\(\\{\\text{subject}\\}\\).\n\t\\end{defn}\n\t\n\t\\begin{defn}[Foreign Keys]\n\t\\label{def:foreign-keys}\n\t\t\\glsreset{fk} % Want to spell it out in the definition\n\t\tA \\gls{fk} constraint applies to two relations, \\(\\relation_1, \\relation_2\\).  It asserts that values of certain attributes of \\(\\relation_1\\) must appear as values of some corresponding attributes of \\(\\relation_2\\).  A \\gls{fk} constraint is written as\n\t\t\\[\n\t\t\t\\theta = \\relation_1(\\attribute_{1,1}, \\attribute_{1,2}, \\dotsc, \\attribute_{1,k}) \\rightarrow \\relation_2(\\attribute_{2,1}, \\attribute_{2,2}, \\dotsc, \\attribute_{2,k})\n\t\t\\]\n\t\t\n\t\twhere \\(\\attribute_{1,i} \\subseteq \\attributes{\\relation_1}\\) and \\(\\attribute_{2,i} \\subseteq \\attributes{\\relation_2}\\).  We say \\((\\relation_1, \\relation_2)\\) satisfies \\(\\theta\\), denoted as \\((\\relation_1, \\relation_2) \\models \\theta\\), if for every tuple \\(\\tuple \\in \\relation_1\\), there exists a tuple \\(\\tuple' \\in \\relation_2\\) such that \\(\\tuple\\lbrack\\attribute_{1,1}, \\attribute_{1,2}, \\dotsc, \\attribute_{1,k}\\rbrack = \\tuple'\\lbrack\\attribute_{2,1}, \\attribute_{2,2}, \\dotsc, \\attribute_{2,k}\\rbrack\\).\n\t\t\n\t\tWe say \\(\\relation_1\\) is the source, while \\(\\relation_2\\) is the target.\n\t\t\t\t\n\t\t\\begin{ex}\n\t\t\tSuppose we have a relation \\(\\rel{Course}{code, title, subject}\\).\t We impose a \\gls{fk} constraint of\n\t\t\t\\begin{equation}\n\t\t\t\t\\theta = \\rel{Course}{subject} \\rightarrow \\rel{Subject}{id}\n\t\t\t\\end{equation}\n\t\t\t\n\t\t\twhich asserts \\((\\text{Course}, \\text{Subject}) \\models \\theta\\).  Therefore, if\n\t\t\t\\[\n\t\t\t\t\\tuple = \\{\\text{code}: \\text{``CDPS 101''}, \\text{title}: \\text{``Human-Mutant Relations''}, \\text{subject}: \\text{``CDPS''}\\}\n\t\t\t\\]\n\t\t\t\n\t\t\tthen \\(\\exists! \\tuple' \\in \\text{Subject}\\) such that \\(\\tuple'\\lbrack\\text{id}\\rbrack = \\text{``CDPS''}\\).\n\t\t\\end{ex}\n\t\\end{defn}\n\t\n\t\\begin{defn}[Relational Database]\n\t\\label{def:relational-database}\n\t\tA relational database, \\(\\db\\), is a named collection of relations (\\cref{def:relation}), keys (\\cref{def:keys}), and foreign key constraints (\\cref{def:foreign-keys}).\n\t\t\n\t\tWe use \\(\\name{\\db}\\) to denote the name of \\(\\db\\), \\(\\relations{\\db}\\) the list of relations in \\(\\db\\), \\(\\keys{\\db}\\) the list of key constraints of \\(\\db\\), and \\(\\fks{\\db}\\) the list of foreign key constraints of \\(\\db\\).\n\t\\end{defn}\n\t\n\t\\subsection{Schema Group}\n\t\t\\begin{defn}[Schema Graph]\n\t\t\\label{def:schema-graph}\n\t\t\tIf we view relations as vertices, and \\gls{fk} constraints as edges, a database \\(\\db\\) can be viewed as a schema graph, \\(\\sgraph{}\\), formally defined as\n\t\t\t\\begin{align}\n\t\t\t\t\\text{vertices} &: \\text{V}(\\sgraph) = \\relations{\\db} \\\\\n\t\t\t\t\\text{edges} &: \\text{E}(\\sgraph) = \\fks{\\db}\n\t\t\t\\end{align}\n\t\t\\end{defn}\n\t\t\n\t\t\\begin{ex}\n\t\t\tGiven the schema in \\cref{tbl:schema} and the \\gls{fk} constraints in \\cref{eqn:fk-constraints}, we produce the schema graph in \\cref{fig:schema-graph}.\n\t\t\t\n\t\t\t\\begin{table}\n\t\t\t\t\\centering\n\t\t\t\t\n\t\t\t\t\\begin{tabular}{ll}\n\t\t\t\t\t\\toprule\n\t\t\t\t\tRelation & Attributes \\\\\n\t\t\t\t\t\\midrule\n\t\t\t\t\tCourse & \\underline{code}, title, subject \\\\\n\t\t\t\t\tSection & \\underline{id}, actual, campus, capacity, credits, levels, registration\\_start, \\\\\n\t\t\t\t\t & registration\\_end, semester, sec\\_code, sec\\_number, year, course \\\\\n\t\t\t\t\tSchedule & \\underline{id}, date\\_start, date\\_end, day, schedtype, hour\\_start, hour\\_end, \\\\\n\t\t\t\t\t & min\\_start, min\\_end, classtype, location, section\\_id \\\\\n\t\t\t\t\tInstructor & \\underline{id}, name \\\\\n\t\t\t\t\tTeaches & \\underline{id}, schedule\\_id, instructor\\_id, position \\\\\n\t\t\t\t\t\\bottomrule\n\t\t\t\t\\end{tabular}\n\t\t\t\t\n\t\t\t\t\\caption{Subset of mycampus dataset schema}\n\t\t\t\t\\label{tbl:schema}\n\t\t\t\\end{table}\n\t\t\t\n\t\t\t\\begin{figure}\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\rel{Schedule}{section\\_id} &\\rightarrow \\rel{Section}{id} \\\\\n\t\t\t\t\t\\rel{Section}{course} &\\rightarrow \\rel{Course}{code} \\\\\n\t\t\t\t\t\\rel{Teaches}{schedule\\_id} &\\rightarrow \\rel{Schedule}{id} \\\\\n\t\t\t\t\t\\rel{Teaches}{instructor\\_id} &\\rightarrow \\rel{Instructor}{id} \\\\\n\t\t\t\t\\end{align*}\n\t\t\t\t\n\t\t\t\t\\caption{\\gls{fk} constraints on schema in \\cref{tbl:schema}}\n\t\t\t\t\\label{eqn:fk-constraints}\n\t\t\t\\end{figure}\n\t\t\t\n\t\t\t\\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\n\t\t\t\t\\begin{dot2tex}[neato]\n\t\t\t\t\tdigraph G {\n\t\t\t\t\t\tnode [shape=plaintext]; Course; Section; Schedule; Instructor; Teaches;\n\t\t\t\t\t\t\n\t\t\t\t\t\tSchedule -> Section;\n\t\t\t\t\t\tSection -> Course;\n\t\t\t\t\t\tTeaches -> Schedule;\n\t\t\t\t\t\tTeaches -> Instructor;\n\t\t\t\t\t}\n\t\t\t\t\\end{dot2tex}\n\t\t\t\t\n\t\t\t\t\\caption{Graph representation of relations (\\cref{tbl:schema}) and \\gls{fk} (\\cref{eqn:fk-constraints})}\n\t\t\t\t\\label{fig:schema-graph}\n\t\t\t\\end{figure}\n\t\t\\end{ex}\n\t\t\n\t\tThe relational data model is particularly powerful for analytic queries.\n\t\t\n\t\\subsection{Entity Group}\n\t\t\\begin{defn}[Entity Group]\n\t\t\\label{def:entity-group}\n\t\t\tAn entity group is a forest, \\(\\egraph\\), of tuples interconnected by join conditions defined by the \\gls{fk} constraints in the schema graph \\(\\sgraph\\).\n\t\t\t\n\t\t\tGiven two vertices \\((\\tuple, \\tuple') \\in \\text{V}(\\egraph)\\), \\(\\exists (\\relation_1, \\relation_2) \\in \\relations{\\db}\\) such that \\(\\tuple \\in \\relation_1\\), \\(\\tuple'\\in \\relation_2\\), and \\((\\relation_1, \\relation_2)\\in \\sgraph\\).  That is, \\(\\tuple\\) and \\(\\tuple'\\) belong to two relations that are directly connected by the schema graph.\n\t\t\\end{defn}\n\t\t\n\t\t\\begin{ex}\n\t\t\tLet \\(\\relation_1(\\attribute_{11}, \\attribute_{12}, \\dotsc, \\attribute_{1k}) \\to \\relation_2(\\attribute_{21}, \\attribute_{22}, \\dotsc, \\attribute_{2k})\\) be the \\gls{fk} that connects \\((\\relation_1, \\relation_2)\\).  We assert that \\(\\tuple\\lbrack\\attribute_{11}, \\attribute_{12}, \\dotsc, \\attribute_{1k}\\rbrack = \\tuple'\\lbrack\\attribute_{21}, \\attribute_{22}, \\dotsc, \\attribute_{2k}\\rbrack\\).\n\t\t\\end{ex}\n\t\t\n\t\tEntity groups define complex, structured objects that include more information than individual tuples in the relations.\n\t\t\n\t\t\\begin{ex}\n\t\t\tThe information in \\cref{tbl:hmr-properties-rel} all relates to the Course titled Human-Mutant Relations, however no single tuple in the database has all of this information as a result of database normalization.\n\t\t\t\n\t\t\t\\begin{table}\n\t\t\t\t\\centering\n\t\t\t\t\n\t\t\t\t\\begin{tabular}{ll}\n\t\t\t\t\t\\toprule\n\t\t\t\t\tAttribute & Value \\\\\n\t\t\t\t\t\\midrule\n\t\t\t\t\tcode & CDPS 101 \\\\\n\t\t\t\t\ttitle & Human-Mutant Relations \\\\\n\t\t\t\t\tsubject & Community Development \\& Policy Studies \\\\\n\t\t\t\t\t\\bottomrule\n\t\t\t\t\\end{tabular}\n\t\t\t\t\n\t\t\t\t\\caption{Properties of the Course titled Human-Mutant Relations.}\n\t\t\t\t\\label{tbl:hmr-properties-rel}\n\t\t\t\\end{table}\n\t\t\t\n\t\t\tWe require an entity group to join together all pieces of information related to this course.  An example of this is given in \\cref{fig:hmr-entity-group}, where an example entity group comprised of a Course and Subject is shown.\n\t\t\t\n\t\t\t\\begin{figure}\n\t\t\t\t\\centering\n\t\t\t\t\n\t\t\t\t\\begin{dot2tex}[dot]\ndigraph G {\n\tnode [shape=plaintext]; \"Human-Mutant Relations\"; \"Community Development & Policy Studies\";\n\t\n\t\"Human-Mutant Relations\" -> \"Community Development & Policy Studies\";\n}\n\t\t\t\t\\end{dot2tex}\n\t\t\t\t\n\t\t\t\t\\caption{Human-Mutant Relations entity group}\n\t\t\t\t\\label{fig:hmr-entity-group}\n\t\t\t\\end{figure}\n\t\t\\end{ex}\n\n\t\\subsection{Benefits and Drawbacks of the Relational Model}\n\t\tTo better understand the motivation behind this work, it is important to examine both the strong and weak points of the relational model.\n\t\t\n\t\t\\subsubsection{Benefits}\n\t\t\tThe enforcement of constraints is essential to the relational model.  Types of constraints include uniqueness and \\glspl{fk}.  The first constraint maintains uniqueness.\n\t\t\t\n\t\t\tThe Course relation (\\cref{tbl:course-relation}) has the attribute \\texttt{code} as its primary key.\tIn order for other relations to reference a specific named tuple, the \\texttt{code} attribute must be unique.\n\t\t\t\n\t\t\t\\begin{ex}[Unique Constraint]\n\t\t\t\\label{ex:unique-constraint}\n\t\t\t\tAttempt to insert another course with a \\texttt{code} of ``CDPS 101.''\n\t\t\t\t\n\t\t\t\t\\begin{singlespaced}\n\t\t\t\t\t\\begin{pygments}{sql}\nINSERT INTO course\nVALUES      ('CDPS 101',\n             'Mutant-Human Relations',\n             'CDPS');\n\t\t\t\t\t\\end{pygments}\n\t\t\t\t\\end{singlespaced}\n\t\t\t\t\n\t\t\t\tThe \\gls{rdbms} enforces the primary key constraint on the \\texttt{code} attribute, rejecting the insertion.\n\t\t\t\t\n\t\t\t\t\\begin{verbatim}\nError: column code is not unique\n\t\t\t\t\\end{verbatim}\n\t\t\t\\end{ex}\n\t\t\t\n\t\t\tWith the uniqueness of named tuples guaranteed (as demonstrated in \\cref{ex:unique-constraint}), we must ensure that any named tuples that are referenced actually exist.  If they do not, the database must not permit the operation to continue.  Doing so leads to dangling references.\n\t\t\t\n\t\t\t\\begin{ex}[Referential Integrity]\n\t\t\t\tAttempt to insert the tuple (``CHEM 101'', ``Introductory Chemistry'', ``'CHEM'') in the Course relation.\n\t\t\t\t\n\t\t\t\t\\begin{singlespaced}\n\t\t\t\t\t\\begin{pygments}{sql}\nINSERT INTO course\nVALUES      ('CHEM 101',\n             'Introductory Chemistry',\n             'CHEM');\n\t\t\t\t\t\\end{pygments}\n\t\t\t\t\\end{singlespaced}\n\t\t\t\t\n\t\t\t\tAgain we see the \\gls{rdbms} protecting the integrity of the data.\n\t\t\t\t\n\t\t\t\t\\begin{verbatim}\nError: foreign key constraint failed\n\t\t\t\t\\end{verbatim}\n\t\t\t\\end{ex}\n\t\t\t\n\t\t\tThe relational model, in addition to enforcing consistency, is capable of providing higher-level views of the data through aggregation.\n\t\t\t\n\t\t\t\\begin{ex}[Aggregation]\n\t\t\t\tFind the number of sections offered for the subject named ``Community Development \\& Policy Studies.''\n\t\t\t\t\n\t\t\t\t\\begin{singlespaced}\n\t\t\t\t\t\\begin{pygments}{sql}\nSELECT Count(*)\nFROM   section\n       JOIN course\n         ON section.course = course.code\n       JOIN subject\n         ON subject.id = course.subject\nWHERE  subject.name = 'Community Development & Policy Studies';\n\t\t\t\t\t\\end{pygments}\n\t\t\t\t\\end{singlespaced}\n\t\t\t\\end{ex}\n\t\t\t\n\t\t\tInformation stored within a properly designed database is normalized.  That is, no information is repeated.\n\t\t\t\n\t\t\t\\begin{ex}[Normalization]\n\t\t\t\tFor example, suppose Emma Frost became headmistress and the subject named ``Community Development \\& Policy Studies'' was renamed to ``Community Destruction \\& Policy Studies.''  If this information were not normalized, each course in this subject needs to be updated.  Since this information is normalized, the following query will suffice.\n\t\t\t\t\n\t\t\t\t\\begin{singlespaced}\n\t\t\t\t\t\\begin{pygments}{sql}\nUPDATE subject\nSET    name = 'Community Destruction & Policy Studies'\nWHERE  id = 'CDPS';\n\t\t\t\t\t\\end{pygments}\n\t\t\t\t\\end{singlespaced}\n\t\t\t\\end{ex}\n\t\t\t\n\t\t\tThe above examples are some of the most important reasons for choosing the relational model over others.\tUnfortunately, the relational model is not without its downsides.\n\t\t\n\t\t\\subsubsection{Drawbacks}\n\t\t\tWhile the relational model excels at ensuring data consistency, aggregation, and reporting; it is not suitable for every task.\tA user must be familiar with the schema to issue queries.  This requires specific domain knowledge of the data.\n\t\t\t\n\t\t\tA casual user is unlikely to determine the correct join path, know the exact name of the tables and attributes, etc.  This is in contrast to the document model where the data is semi-structured or unstructured, requiring minimal domain knowledge.\n\n\t\t\tThe relational model is also rigid in structure.  If a relation is modified, every query referencing said relation may require a rewrite.  Even a simple attribute being renamed (e.g.~\\(\\rho_{\\text{name/alias}}(\\text{Person})\\)) is capable of modifying the join paths.  This rigidity places additional cognitive burden on users.\n\t\t\t\n\t\t\tIn addition to having a rigid structure, most relational database management systems lack flexible string matching options.\t Assuming basic SQL-92 compliance, a \\gls{rdbms} only supports the \\texttt{LIKE} predicate \\cite{sql-11}.\n\t\t\t\n\t\t\t\\begin{ex}[\\texttt{LIKE} Predicate]\n\t\t\t\tFind all courses with a title that contains ``man.''\n\t\t\t\t\n\t\t\t\t\\begin{singlespaced}\n\t\t\t\t\t\\begin{pygments}{sql}\nSELECT *\nFROM   course\nWHERE  title LIKE '%man%';\n\t\t\t\t\t\\end{pygments}\n\t\t\t\t\\end{singlespaced}\n\t\t\t\\end{ex}\n\t\t\t\n\t\t\tA couple of limitations to the \\texttt{LIKE} predicate exist.  First, it only supports basic substring matching.  If a user accidentally searches for all courses with a title containing ``men,'' nothing would be found.\n\t\t\t\n\t\t\tSecond, unless the predicate is applied to the end of the string and the column is indexed, performance will be poor.  The \\gls{rdbms} must scan the entire relation to answer the query, resulting in performance of \\(\\mathcal{O}(n)\\), where \\(n\\) is the number of named tuples in the relation.", "meta": {"hexsha": "096d017424c9f65db158cecd593aa676ba19362f", "size": 15407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/document/relational-model.tex", "max_stars_repo_name": "rdrake/Molly", "max_stars_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "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": "thesis/document/relational-model.tex", "max_issues_repo_name": "rdrake/Molly", "max_issues_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-13T19:40:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T19:40:08.000Z", "max_forks_repo_path": "thesis/document/relational-model.tex", "max_forks_repo_name": "rdrake/Molly", "max_forks_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "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.5524691358, "max_line_length": 519, "alphanum_fraction": 0.6809891608, "num_tokens": 4564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.624938182785332}}
{"text": "% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí\n\\setcounter{chapter}{4}\n\\chapter{Capacitors}\n%\n...\n%\n\\section{Preliminary}\n%\nResistance is a property of the components in an electric circuit. You can use units of ohm to measure electric resistance. One ohm of electric resistance is equivalent to\n\\begin{equation}\n\t1 \\text{ ohm} = 1 \\text{ V/A}\n\\end{equation}\nAnother property is capacitance. You can measure capacitance in units of farads (F). One farad of electric capacitance is equivalent to\n\\begin{equation}\n\t1 \\text{ F} = 1 \\text{ C/V}\n\\end{equation}\nIn some ways, capacitance measures the amount of electric charge per unit voltage.\n\nA component in a circuit with an electric resistance is called a \\textbf{resistor}. Similarly, a component in a circuit with a capacitance is called a \\textbf{capacitor}. A circuit with both capacitors and resistors is known as an RC circuit. The simplest RC circuit has one resistor and one capacitor connected in series to a battery (a DC source).\n\nA particular quantity $\\tau_{C}$ is given by multiplying resistance by capacitance:\n\\begin{equation}\n\t\\tau_{C} = R C\n\t\\label{eq.05C.tauC}\n\\end{equation}\nThis quantity is known as the \\textbf{capacitive time constant}. If resistance is in ohms and capacitance is in farads, then $\\tau_{C}$ is in seconds. The capacitive time constant is important because it describes how quickly voltage and current change in circuits with resistors and capacitors. During a \\textbf{charging event}, the \\textbf{electric current} drops in an exponential way:\n\\begin{equation}\n\tI(t) = I_{0} \\exp{\\left(- \\frac{t}{\\tau_{C}} \\right)}\n\t\\label{eq.05C.It}\n\\end{equation}\nDuring a \\textbf{discharging event}, the \\textbf{voltage} drops in an exponential way:\n\\begin{equation}\n\tV(t) = V_{0} \\exp{\\left(- \\frac{t}{\\tau_{C}} \\right)}\n\t\\label{eq.05C.Vt}\n\\end{equation}\n%\n\\section{Experiment}\n%\nThere are two kinds of experiments: the charging event and the discharging event. In each experiment you measure the current flowing between the resistor and the capacitor, and the voltage across the capacitor.\n\nFor the \\textbf{charging event}, the data collection is started with the switch off (i.e. incomplete circuit) and shortly after turned on. You should analyze the \\textbf{current} data for such events, as it follows the behavior in (\\ref{eq.05C.It}).\n\nFor the \\textbf{discharging event}, the data collection is started with the switch on (i.e. complete circuit) and shortly after turned off. You should analyze the \\textbf{voltage} data for such events, as it follows the behavior in (\\ref{eq.05C.Vt}).\n\nThere are 9 runs of data:\n\\begin{enumerate}\n\t\\item Charging capacitor with $R = 10$ ohm and $C = 0.025$ F.\n\t\\item Discharging capacitor with $R = 10$ ohm and $C = 0.025$ F.\n\t\\item Charging capacitor with $R = 51$ ohm and $C = 0.025$ F.\n\t\\item Discharging capacitor with $R = 51$ ohm and $C = 0.025$ F.\n\t\\item Charging capacitor with $R = 68$ ohm and $C = 0.025$ F.\n\t\\item Discharging capacitor with $R = 68$ ohm and $C = 0.025$ F.\n\t\\item Discharging capacitor with $R = 22 \\times 10^{3}$ ohm and $C = 10^{-5}$ F.\n\t\\item Discharging capacitor with $R = 47 \\times 10^{3}$ ohm and $C = 10^{-5}$ F.\n\t\\item Discharging capacitor with $R = 100 \\times 10^{3}$ ohm and $C = 10^{-5}$ F.\n\\end{enumerate}\nEach time the resistance or the capacitance changes, the time constant $\\tau_{C}$ will also change.\n%\n\\section{Analysis}\n%\nThe analysis is pretty simple: you need to make a graph of the desired quantity versus time and then include an \\textbf{exponential} fit. The exponential fit is of the form:\n\\begin{equation}\n\ty = A e^{-Bx}\n\t\\label{eq.05C.exp.fit}\n\\end{equation}\nComparing (\\ref{eq.05C.exp.fit}) with (\\ref{eq.05C.It}) and also (\\ref{eq.05C.Vt}) leads to identifying the experimental estimate of $\\tau_{C}$ with $1 / B$.\n\nThe trouble is that it takes some effort to prepare the data in such a way that the exponential fit is appropriate and accurate. You need to do two things:\n\\begin{enumerate}\n\t\\item Truncate the time region before the switch is turned on/off.\n\t\\item Truncate the long time tail after the exponential drop.\n\\end{enumerate}\nFor the first truncation, just find the time value where the voltage (in discharging events) or the current (in charging events) suddenly jumps. Remove all the values before this time and perhaps one or two events right after the exponential drop begins.\n\nFor the second truncation, one good rule of thump is to use the expected value of $\\tau_{C}$. You should keep a time region that is about $5\\tau_{C}$ long in time, starting from the beginning of the exponential drop.\n%\n\\section{My Data}\n%\nIn the spreadsheet that I shared with you, there is a sheet called ``Results''. This sheet has a table with eight columns and nine rows. Each of the rows corresponds to one of the nine runs mentioned above. Here are the columns:\n\\begin{itemize}\n\t\\item Column 1: run label.\n\t\\item Column 2: value of resistance (in ohm) for the resistor used.\n\t\\item Column 3: value of the capacitance (in F) for the capacitor used.\n\t\\item Column 4: Expected value of $\\tau_{C}$ (in s). Use (\\ref{eq.05C.tauC}) with columns 2 and 3 to calculate these values.\n\t\\item Column 5: Expected value of $1 / \\tau_{C}$ (in 1/s). Just take the reciprocal of the values in column 4.\n\t\\item Column 6: Fit value of $1 / \\tau_{C}$ (in 1/s). This correspond to the $B$ value in the exponential fit. See (\\ref{eq.05C.exp.fit}).\n\t\\item Column 7: Fit value of $\\tau_{C}$ (in s). This is just the reciprocal of the values in column 6.\n\t\\item Column 8: The percent difference between the theoretical values in column 4 and the experimental values in column 7.\n\\end{itemize}\nFor the percent difference, use\n\\begin{equation}\n\t\\text{Percent Difference } = 100 \\times (\\text{experiment } - \\text{ theory}) / \\text{theory}\n\\end{equation}\nIn my case I found mixed agreement, with the largest disagreements not being larger than 20\\%.\n%\n\\section{Your Data}\n%\nYour data is structured in the same way as my data, but the time delay for turning on/off the switch is different.\n%\n\\section{Your Lab Report}\n%\nIn your lab report you should include:\n\\begin{enumerate}\n\t\\item One voltage versus time graph. Choose one from runs 2, 4, or 6. Include the exponential fit line, and also the equation.\n\t\\item One current versus time graph. Choose one from runs 1, 3, or 5. Include the exponential fit line, and also the equation.\n\t\\item Another voltage versus time graph. Choose one from runs 7, 8, or 9. Include the exponential fit line, and also the equation.\n\t\\item A table in your printed lab report similar to my table in the ``Results'' sheet from the shared spreadsheet.\n\\end{enumerate}\nYou should also include answers to the following questions:\n\\begin{enumerate}\n\t\\item Are the fit values for $\\tau_{C}$ for runs 1, 3, and 5 consistent with the corresponding values for runs 2, 4, and 6?\n\t\\item Note that some runs involve current measurements and the other runs involve voltage measurements. In general, which runs give fit values for $\\tau_{C}$ that are closer to the expected values: charging events (current) or discharging events (voltage)?\n\t\\item Why are the current measurements in runs 7, 8 and 9 so small?\n\\end{enumerate}", "meta": {"hexsha": "d1de0343340eeeb0dec64215dd178719fb9e1583", "size": 7191, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/05-RC.tex", "max_stars_repo_name": "meirizarrygelpi/phys-208L", "max_stars_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_stars_repo_licenses": ["MIT"], "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/05-RC.tex", "max_issues_repo_name": "meirizarrygelpi/phys-208L", "max_issues_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_issues_repo_licenses": ["MIT"], "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/05-RC.tex", "max_forks_repo_name": "meirizarrygelpi/phys-208L", "max_forks_repo_head_hexsha": "ce8b093f9e730c87a2b4c6208b4d4da518035267", "max_forks_repo_licenses": ["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.0789473684, "max_line_length": 388, "alphanum_fraction": 0.7446808511, "num_tokens": 1985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.6249381827853319}}
{"text": "\\subsection{Implementation of Ruder style transfer for video}\n\\label{sec:Ruder style transfer}\nAs a part of our project we have implemented some of the components described in the paper by Ruder et al. \\cite{Ruder:1}. Here we try to reduce the noise that appears when styling each image independently by introducing a temporal constraint in order to penalize the model for straying too far away from the previous image.\\newline\\newline\nThe temporal constraint we have implemented is an additional loss-component: \\newline\n\n\\begin{equation}\n\\mathcal{L}_{temporal}(x, \\omega, c) = \\frac{1}{D}\\sum_{k=1} c_k \\cdot (x_k - \\omega_k)^2\n\\end{equation}\nSince we are using the style and content-loss used in Gatys style transfer, our total loss-function with a shortterm temporal constraint is this:\\newline\n\\begin{equation}\n\\mathcal{L}_{shortterm}(p^{(i)}, a, x) = \\alpha \\mathcal{L}_{content} + \\beta \\mathcal{L}_{style} + \\gamma \\mathcal{L}_{temporal}(x^{(i)}, \\omega_{i-1}^i(x^{i-1}, c^{i-1, i}))\n\\end{equation}\nWe use different weights for different resolutions, generally increasing the style-loss and decreasing the temporal constraint with increasing resolution.\\newline\nAs well as using this shortterm temporal loss function, we also initialize every frame after the first stylized frame with the previously stylized frame \\textit{i-1} warped to the current image \\texit{i}. This is done by using the flow between the content image $i-1$ and $i$. \nTo calculate this flow we need a flow algorithm. In our implementation we have used cv2's DeepFlow function. The calculated flow between frames is also used to create our c-matrix using the inequalities described in section \\ref{sec:usage_of_optical_flow}. These inequalities result in c-matrix masks like these:\\newline \n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.5]{report/Method/images/shrek_flow.png}\n\\caption{A frame from the shrek video and the flow image calculated, indicating what parts of the image are moving and should be recalculated}\n\\label{fig:architecture}\n\\end{center}\n\\end{figure}\n\\newline\nTo calculate these values for each frame, we have primarily used the numpy library. We have also implemented the long-term temporal constraint described in section \\ref{sec:long_term_temporal_loss}. However, a lot of additional computation is needed for this. With our current access to hardware and the negligible results we got from testing our implementation, we decided to not use this in our results.\\newline\\newline\nWith the implemented temporal constraint, we are able to have some consistency between frames, resulting in less noise: \\newline\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.11]{report/Method/images/ruder.png}\n\\caption{Two consecutive frames produced by Ruders method using La Muse (picasso) as style refernce, source video is from Parasite}\n\\label{fig:architecture}\n\\end{center}\n\\end{figure}Here we can see the same artifacts staying in the same place in both adjacent frames, while the person to the left has moved. The results from this implementation can be seen in \\ref{seq:ruder_result}", "meta": {"hexsha": "906fc4553d7a786c9de8501178347e698edd1551", "size": 3102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/Method/Ruder.tex", "max_stars_repo_name": "kjerand/video-style-transfer", "max_stars_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_stars_repo_licenses": ["MIT"], "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/Method/Ruder.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/Method/Ruder.tex", "max_forks_repo_name": "kjerand/video-style-transfer", "max_forks_repo_head_hexsha": "fe44a1b486e976725cddd6db4981b161dea13813", "max_forks_repo_licenses": ["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.9375, "max_line_length": 421, "alphanum_fraction": 0.7885235332, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6249381808346866}}
{"text": "%\\subsection{Variational Inference in Sparse GPs Revisited}\n%\n%In this section we review inference in sparse GPs (as presented in Titsias).\n%The posterior in an augmented model is $p(\\f, \\u | \\y) = p(\\f | \\u, \\y) p(\\u | \\y)$.\n%The key property of such augmented GPs  is the notion of \\textit{sufficient statistics}: given the inducing points $\\u$, the latent values $\\f$ are independent with any other set of latent values (e.g. the test set).\n%In the optimal setting when $\\u$ is the sufficient statistics of $\\f$, it should hold that $p(\\f | \\u, \\y) = p(\\f | \\u)$ as $\\y$ is only the noisy version of $\\f$.\n%This leads to choosing a variational approximation of the posterior which factorizes as $q(\\f, \\u | \\y) = p(\\f | \\u) q(\\u | \\y)$.\n%Since the conditional $p(\\f | \\u)$ is known, variational inference becomes learning an optimal posterior $q(\\u | \\y)$ only. \\\\\n%\nWe approximate the posterior over the latent variables $\\vec{g}, \\vec{h}, \\vec{u}, \\vec{v}$ given observations $\\vec{y}$ using variational inference \\citep{jordan-variational-99}.\nIn section \\ref{sec:variationalLowerBound} we derive a lower bound of the marginal likelihood which has the key property of factorizing over the data points and outputs. Section \\ref{sec:svi}  takes advantage of this factorization to \nderive stochastic variational inference, allowing the model to scale to very large datasets.\nSection \\ref{sec:complexity} compares the complexity of the model with previous multi-output methods.\n\n\\subsection{VARIATIONAL LOWER BOUND \\label{sec:variationalLowerBound}}\n\\newcommand{\\ug}{\\u_g}\n\\newcommand{\\uh}{\\u^h}\n\\newcommand{\\mgj}{\\m_j}\n\\newcommand{\\mhi}{\\m^h_i}\n\\newcommand{\\Sgj}{\\S_j}\n\\newcommand{\\Shi}{\\S^h_i}\nIn variational inference, we find the ``closest'' approximate distribution to the true posterior in terms of the $\\KL$ divergence.\nWe first observe that the true posterior distribution can be written as:\n\\begin{align}\np(\\g, \\h, \\u, \\v | \\y) = p(\\g | \\u, \\y) p(\\h | \\v, \\y) p(\\u, \\v | \\y).\n\\end{align}\nHere we recall the modeling assumption that each set of  inducing variables is the sufficient statistics of the corresponding latent process. \nThis motivates replacing the true posteriors over $\\g$ and $\\h$ with their conditional distributions given the inducing variables, leading to a distribution of the form:\n\\begin{align}\nq(\\g, \\h, \\u, \\v | \\y)\n= p(\\g|\\u) p(\\h|\\v) q(\\u,\\v),\n\\end{align}\nwith\n\\begin{align}\nq(\\u,\\v) &= \\prod_{j=1}^Q \\underbrace{\\Normal(\\u_j; \\mgj, \\Sgj)}_{q(\\u_j)} \\prod_{i=1}^P  \\underbrace{\\Normal(\\v_i; \\mhi, \\Shi)}_{q(\\v_i)}.\n\\end{align}\nThis technique has been used by \\citet{titsias2009variational} and \\citet{hensmangaussian} \nto derive variational inference algorithms for the single output case.\nSince the conditionals $p(\\g | \\u)$ and $p(\\h | \\v)$ are known (Equations \\eqref{eq:gu} and \\eqref{eq:hv}), \nwe only need to \nlearn $q(\\u, \\v)$ so as to minimize the divergence between the approximate posterior and\nthe true posteriors.\nThe quality of approximation depends entirely on the posterior over the inducing variables, thus underlining their pivotal role in the model as previously discussed.\n\n\\noindent\nTo find the best $q(\\u, \\v)$, we  optimize the evidence lower bound (ELBO) of the log marginal:\n\\begin{align}\n%\\nonumber\n%\\log p(\\y) \\ge& \\int q(\\u, \\v) \\log \\frac{p(\\y | \\u, \\v) p(\\u, \\v)}{q(\\u, \\v)} \\der \\u \\der \\v \\\\\n%\\nonumber\n%=& \\int q(\\u, \\v) \\log p(\\y | \\u, \\v)  \\der \\u \\der \\v \n%+ \\int q(\\u, \\v) \\log \\frac{p(\\u, \\v)}{q(\\u, \\v)} \\der \\u \\der \\v \\\\\n\\nonumber\n&\\log p(\\y) \\ge \\int q(\\u, \\v) \\log p(\\y | \\u, \\v)  \\der \\u \\der \\v \\\\\n&- \\sum_{j=1}^Q \\KL[q(\\u_j) || p(\\u_j)] - \\sum_{i=1}^P \\KL[q(\\v_i) || p(\\v_i)],\n\\label{eq:elbo}\n\\end{align}\nwhich is derived using Jensen's inequality and the fact that both of $q(\\u, \\v)$ and $p(\\u, \\v)$ fully factorize.\nSince $q(\\u_j), q(\\v_i), p(\\u_j), p(\\v_i)$ are all multivariate Gaussian distributions, the KL divergence terms are analytically tractable.\nTo compute the expected likelihood term in the ELBO we first see that\n\\begin{align}\n\\nonumber\n\\log \\text{ } &p(\\y | \\u, \\v)\n% &= \\log \\Eb{p(\\y | \\g, \\h)}_{p(\\g,\\h | \\u, \\v)} \\\\\n% \\nonumber\n\\ge \\Eb{\\log p(\\y | \\g, \\h)}_{p(\\g,\\h | \\u, \\v)}  \\\\\n&= \\sum_{i=1}^P \\sum_{n=1}^N \\Eb{\\log p(y_{in} | \\g_n, h_{in}) }_{p(\\g | \\u) p(\\h_i | \\v_i)} \n\\end{align}\nwhere $\\g_n = \\{g_{jn} = (\\g_j)_n\\}_{j=1}^Q$.\nThe inequality is due to Jensen's inequality and the equality is due to %the fact that the likelihood fully factorizes.\nthe factorization of the likelihood. \n\\newcommand{\\Ahi}{\\A^h_i}\n\\newcommand{\\Zi}{\\Z_i}\n\nThe ELBO can be computed by first solving for the individual expectations \n%$l_{in} \\define \\Eb{\\log p(y_{in} | \\g_n, h_{in}) }_{p(\\g_n | \\u) p(\\h_in | \\v_i)}$ \n$ \\Eb{\\log p(y_{in} | \\g_n, h_{in}) }$ over ${p(\\g | \\u) p(\\h_i | \\v_i)}$ and \nthen substituting these into Equation \\eqref{eq:elbo} (see the supplementary material for details). \nHence the resulting lower bound is given by:\n\\begin{align}\n\\nonumber\n%&\\log p(\\y)\n & \\calL = \n\\sum_{i,n}\n\\bigg( \\log  \\Normal(y_{in}; \\tilde{\\mu}_{in}, \\beta_i^{-1})\n          - \\frac{1}{2} \\beta_i \\sum_{j=1}^Q w_{ij}^2 \\tilde{k}_{jnn} \\\\ \\nonumber\n         &- \\frac{1}{2} \\beta_i \\tilde{k}^h_{inn}\n         - \\frac{1}{2} \\beta_i \\sum_{j=1}^Q \\trace w_{ij}^2 \\S_j \\mat{\\Lambda}_{jn} - \\beta_i \\frac{1}{2} \\trace \\S^h_i \\mat{\\Lambda}_{in} \n\\bigg) \\\\\n\\nonumber\n& - \\sum_{j=1}^Q \\bigg( \\frac{1}{2} \\log |\\K_{jzz} \\S_j^{-1}| + \\frac{1}{2} \\trace \\K_{jzz}^{-1}  \\left( \\m_j \\m_j^T + \\S_j \\right)\\bigg) \\\\\n\\nonumber\n& - \\sum_{i=1}^P  \\bigg( \\frac{1}{2} \\log |\\K_{izz}(\\Shi)^{-1}| \\\\\n& \\quad \\qquad + \\frac{1}{2} \\trace \\K_{izz}^{-1} \\left( \\mhi (\\mhi)^T   +   \\Shi \\right) \\bigg)  \\text{,}\n  \\label{eq:L}\n\\end{align}\n%\nwhere $\\K_{jzz} = k(\\Zj, \\Zj)$, $\\K_{izz} = k(\\Zhi, \\Zhi)$, and:\n\\begin{align}\n\\tilde{\\mu}_{in}\n%&= \\sum_{j=1}^Q w_{ij} k(\\x_n, \\Zj)k(\\Zj,\\Zj)^{-1}\\m_j + k(\\x_n, \\Zhi)k(\\Zhi,\\Zhi)^{-1}\\mhi \\\\\n&= \\sum_{j=1}^Q w_{ij} \\A_j(n,:) \\m_j + \\Ahi(n,:) \\mhi \\text{,}\\\\\n\\mat{\\Lambda}_{jn}\n%&= k(\\Zj,\\Zj)^{-1} k(\\Zj, \\x_n) k(\\x_n, \\Zj) k(\\Zj,\\Zj)^{-1} \\\\\n&= \\A_j(n,:)^T \\A_j(n,:)  \\text{,}\\\\\n\\mat{\\Lambda}_{in}\n%&= k(\\Zhi,\\Zhi)^{-1} k(\\Zhi, \\x_n) k(\\x_n, \\Zhi) k(\\Zhi,\\Zhi)^{-1}\n&= \\Ahi(n,:)^T \\Ahi(n,:)  \\text{,}\n\\end{align}\nwith $\\tilde{k}_{jnn} = (\\tilde{\\K}_j)_{nn}$; \n$\\tilde{k}^h_{inn} = (\\tilde{\\K}^h_i)_{nn}$; \n$\\mu_{jn} = (\\Mu_j)_n$;\n $\\mu^h_{in} = (\\Mu^h_i)_n$; \nand we have defined the auxiliary matrices $\\A_j = k(\\X,\\Zj) \\K_{jzz}^{-1}$ and $\\Ahi = k(\\X_i,\\Zhi)\\K_{izz}^{-1}$ and \nused $\\A_j(n,:)$ to denote the $n$-th row vector of $\\A_j$. \nNotice that this ELBO  generalizes the bound for standard GP regression derived in \\cite{hensmangaussian}, which can be recovered by setting $P = Q = 1$, $w_{ij} = 1$ and $h_i(\\x) = 0$.\n\nThe novelty of the  variational lower bound in Equation  \\eqref{eq:L} is that it decomposes across both inputs and outputs.\nThis enables the use of stochastic optimization methods, which \nallow the model to handle  very large datasets for which existing GP-based multi-output models are simply \nimpractical.  \n%\n\\subsection{STOCHASTIC VARIATIONAL INFERENCE \\label{sec:svi}}\n\\newcommand{\\oi}{\\vec{o}_i}\n% some notation\n\nSo far in the description of the model and inference  we have\n implicitly assumed that every output has full observations at all inputs $\\X$.\nTo discern where learning occurs for each output, we make the missing data scenario more explicit.\nSpecifically, each output $i$ can have observations at a different set of inputs $\\X_i$. \nWe shall use $\\oi$ to denote the indices of $\\X_i$ (in the set $\\X$) and use the indexing operator $\\B(\\oi)$ to select the rows corresponding to $\\oi$ from any arbitrary matrix $\\B$.\nWe also overload $\\y_i$ as the observed targets of output $i$. \n%\n\\subsubsection{Learning the Parameters of the Variational Distribution}\n%------------------------------------------\n% derivatives of q(u_j)\n\\newcommand{\\Lgj}{\\calL^g_j}\n\\newcommand{\\ynoj}{\\y_i^{\\backslash j}}\n\\newcommand{\\Kjzz}{\\mat{K}_{jzz}}\n We can obtain the derivatives of the ELBO in Equation  \\eqref{eq:L}\n  wrt the variational parameters for optimization.\nThe derivatives of $\\calL$ wrt the parameters of $q(\\u_j)$ are given by:\n\\begin{align}\n\\deriv{\\calL}{\\m_j} \n=& \\sum_{i=1}^P \\beta_i w_{ij} \\A_j(\\oi)^T \\ynoj \\\\\n\\nonumber\n&- \\bigg[\\Kjzz^{-1} + \\sum_{i=1}^P \\beta_i w_{ij}^2 \\A_j(\\oi)^T \\A_j(\\oi) \\bigg] \\m_j \\text{,} \\\\\n\\deriv{\\calL}{\\S_j} \n=& \\frac{1}{2} \\S_j^{-1} - \\frac{1}{2} \\bigg[ \\Kjzz^{-1} + \\sum_{i=1}^P \\beta_i w_{ij}^2 \\A_j(\\oi)^T \\A_j(\\oi) \\bigg],\n\\end{align}\nwhere $\\y_i^{\\backslash j} = \\y_i - \\Ahi(\\oi) \\mhi - \\sum_{j' \\neq j} w_{ij'} \\A_{j'}(\\oi) \\m_{j'}$.\n%\\noindent As a function of the parameters of $q(\\u_j)$, the lowerbound $\\calL$ is:\n%\\begin{align}\n%\\nonumber\n%\\calL^g_j \\define&\n% \\sum_{i=1}^P \\log \\Normal(\\y_i; \\sum_{j=1}^Q w_{ij} \\A_j(\\oi,:) \\m_j + \\Ahi \\mhi, \\beta_i^{-1} \\I)  \\\\\n% \\nonumber\n% &- \\frac{1}{2} \\sum_{i=1}^P \\bigg(\\beta_i \\trace w_{ij}^2 \\tilde{\\K}_j(\\oi,\\oi) \n% + \\beta_i \\trace w_{ij}^2 \\S_j \\A_j(\\oi,:)^T \\A_j(\\oi,:) \\bigg)\n% \\\\\n% &- \\frac{1}{2} \\log |k(\\Zj,\\Zj) \\S_j^{-1}| -\\frac{1}{2} \\trace k(\\Zj,\\Zj)^{-1} (\\m_j \\m_j^T + \\S_j) ,\n%\\end{align}\n%where $\\A_j = k(\\X,\\Zj)k(\\Zj,\\Zj)^{-1}$, which gives $\\A_j(\\oi,:) = k(\\X_i,\\Zj) k(\\Zj,\\Zj)^{-1}$, and  \n%$\\Ahi = k(\\X_i,\\Zhi)k(\\Zhi,\\Zhi)^{-1}$. \\\\\n\n%-------------------------------------------\n%  derivatives of q(v_i)\n\\newcommand{\\Lhi}{\\calL^h_i}\n\\newcommand{\\Kizz}{\\mat{K}_{izz}}\n\\noindent The derivatives of $\\calL$ wrt the parameters of $q(\\v_i)$ are given by:\n\\newcommand{\\ynoh}{\\y_i^{\\backslash h}}\n\\begin{align}\n\\nonumber\n\\deriv{\\calL}{\\mhi}\n= & \\beta_i \\Ahi(\\oi)^T \\ynoh  \\\\\n&- \\bigg[\\Kizz^{-1} +  \\beta_i \\Ahi(\\oi)^T \\Ahi(\\oi) \\bigg] \\m_i \\text{,} \\\\\n\\deriv{\\calL}{\\Shi} \n=& \\frac{1}{2} \\S_i^{-1} - \\frac{1}{2} \\bigg[ \\Kizz^{-1} + \\beta_i \\Ahi(\\oi)^T \\Ahi(\\oi) \\bigg] ,\n\\end{align}\nwhere $\\ynoh = \\y_i - \\sum_{j=1}^Q w_{ij} \\A_j(\\oi,:) \\m_j$.\n%\\noindent As a function of the parameters of $q(\\v_i)$, the lower bound $\\calL$ is:\n%\\begin{align}\n%\\nonumber\n%\\Lhi \\define&\n% \\log \\Normal(\\y_i; \\sum_{j=1}^Q w_{ij} \\A_j(\\oi,:) \\m_j + \\Ahi \\mhi, \\beta_i^{-1} \\I)\n% - \\frac{1}{2} \\beta_i \\trace \\tilde{\\K}^h_i(\\oi,\\oi)\n% - \\frac{1}{2} \\beta_i \\trace \\Shi (\\Ahi)^T \\Ahi\n% \\\\\n%  &- \\frac{1}{2} \\log |k(\\Zhi,\\Zhi) (\\Shi)^{-1}| -\\frac{1}{2} \\trace k(\\Zhi,\\Zhi)^{-1} (\\mhi (\\mhi)^T + \\Shi) ,\n%\\end{align}\n\n% comment on computation\n\\noindent It can be seen that the derivatives of the parameters of $q(\\v_i)$ only involve the observations of the output $i$.\nThe derivatives of the parameters of $q(\\u_j)$ involve the observations of all outputs but is a sum of contributions from individual outputs.\nComputation of the derivatives can therefore be easily distributed or parallelized.\n%Therefore, computation of the derivatives can be distributed or parallelized easily.\n%This property further enhances the scalability of the model, allowing it to handle big data problems with a very large number of inputs and outputs.\n\nSince the optimal distributions $q(\\u_j)$ and $q(\\v_i)$ are in the exponential family, it is more convenient to use stochastic variational inference \\citep{hensman2012fast,hensmangaussian} to perform update of their canonical parameters.\nThis works by taking a step of length $l$ in the direction of the natural gradient approximated by mini-batches of the data.\nFor instance, consider $q(\\u_j)$ whose canonical parameters are $\\Phi_1 = \\S_j^{-1} \\m_j$ and $\\Phi_2 = -\\frac{1}{2}\\S_j^{-1}$.\nTheir stochastic update equations at time $t + 1$ are given by:\n\\begin{align}\n\\nonumber\n& \\Phi_{1(t+1)} = \\S_{j(t)}^{-1} \\m_{j(t)}  \\\\\n & \\quad \\qquad +  l \\bigg(\\sum_{i=1}^P \\beta_i w_{ij} \\A_j(\\oi)^T \\ynoj - \\S_{j(t)}^{-1} \\m_{j(t)} \\bigg) \\\\\n& \\Phi_{2(t+1)} = -\\frac{1}{2} \\S_{j(t)}^{-1} + l \\bigg(\\frac{1}{2} \\S_{j(t)}^{-1} - \\frac{1}{2} \\mat{\\Lambda} \\bigg),\n\\end{align}\n\\normalsize\nwhere $\\mat{\\Lambda} = \\Kjzz^{-1} + \\sum_{i=1}^P \\beta_i w_{ij}^2 \\A_j(\\oi)^T \\A_j(\\oi)$.\n%\n\\subsubsection{Inducing Inputs and Hyper-parameters \\label{sec:hyperparameters}}\nTo learn the hyperparameters, which in this model include the mixing weights, the covariance hyperparameters of the latent processes, and the noise precision of each output, we follow standard practice in GP inference.\nFor this model this involves taking derivatives of the ELBO and applying standard stochastic gradient descent in alternative steps with the variational parameters, much like a variational EM algorithm. \nThe derivatives are given in the supplementary material.\n\nLearning of the inducing inputs, which was not considered in the single output case in \\citet{hensmangaussian}, is also possible in our stochastic optimization approach.\nIn the supplementary material, we show that \n%with the help of vectorized operations, \nthe additional cost of computing the derivatives of the lower bound wrt the inducing inputs is not significantly \nhigher than the cost of updating the variational parameters.\n%can be computed with a cost \\emph{independent of the input dimensionality}.\nThis makes optimizing the inducing locations a practical option, which can be critical \nin high-dimensional problems. %where fixing the inducing inputs may hinder the performance of the model.\nIndeed, our experiments on a large scale multi-output problem show that automatic learning of the inducing inputs can lead to significant performance gain with little overhead in computation. \n%\n\\subsection{COMPLEXITY ANALYSIS \\label{sec:complexity}}\nIn this section we analyze the complexity of the model and compare it to existing multi-output approaches.\nFor consistency, we first unify common notations used for all models.\nWe use $P$ as the number of outputs; $N$ as the number of inputs; $Q$ as the number of shared latent processes; and $M_t$ as the \\emph{total} number of inducing inputs.\nIt is worth noting that $M_t = (P + Q) \\times M$ in our COGP model, assuming that each sparse process has equal number of inducing points. \nAlso, COGP has $P$ additional individual processes, one for each output.\n\nThe complexity of COGP can be read off by inspecting the ELBO  in Equation \\eqref{eq:L}, with the key observation that it contains \na sum over the outputs as well as over the inputs.\nThis means a mini-batch containing a small subset of the inputs and outputs can be used for stochastic optimization.\nTechnically, the cost is $\\calO(M^3)$ or $\\calO(N_bM^2)$, where $N_b$ is the size of the mini-batches, depending on which is larger between $M$ and $N_b$. \nIn practice, we may use $N_b > M$ as a large batch size (e.g.~$N_b = 1000$) helps reduce stochasticity of the optimization.\nHowever, here we use $\\calO(M^3)$  for easier comparison with other models whose time and storage demands are \ngiven in Table \\ref{tab:complexity}. \nWe see that COGP has \na computational  complexity that is independent of the size of the inputs and outputs, \nwhich makes it the only method capable of handling large scale problems.\n%\n\\setlength{\\tabcolsep}{4pt}\n\\begin{table}[t]\n\\caption{Comparison of the time and storage complexity of approximate inference of  multi-output GP models. \nA\\&W, 2009 refers to \\citet{alvarez-lawrence-nips-08}. COGP is the only method with complexity \\emph{independent} of the\n number of inputs $N$ and outputs $P$, thus it can scale to very large datasets.}\n\\label{tab:complexity}\n\\begin{center}\n\\small\n\\begin{tabular}{lcc}\n\\toprule\n\\textbf{METHOD} & \\textbf{TIME} & \\textbf{STORAGE} \\\\ \\hline\nCOGP, this paper  & $\\calO(M^3)$ & $\\calO(M^2)$ \\\\\nSLFM, \\citep{teh-et-al-aistats-05} & $\\calO(QNM_t^{2})$ & $\\calO(QNM_t)$ \\\\\nMTGP, \\citep{bonilla-et-al-nips-08} & $\\calO(PNM_t^2)$ & $\\calO(PNM_t)$\\\\ \nCGP-FITC (A\\&W, 2009)& $\\calO(PNM_t^2)$ & $\\calO(PNM_t)$ \\\\\nGPRN, \\citep{wilson-et-al-icml-12} & $\\calO(PQN^3)$ & $\\calO(PQN^2)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\subsection{PREDICTION}\nThe predictive distribution of the $i$-th output for a test input $\\x_*$ is given by:\n\\begin{align}\np(\\fstar | \\y, \\x_*) = \\Normal(\\fstar; \\sum_{j=1}^Q w_{ij} \\mu_{j*} + \\mu^h_{i*}, w_{ij}^2 s_{j*} + s^h_{i*}), \n\\end{align}\nwhere $\\mu_{j*}$ and $s_{j*}$ are the mean and variance of the prediction for $g_{j*} = g_j(\\x_*)$, i.e. $p(g_{j*} | \\y, \\x_*) = \\Normal(g_{j*}; \\mu_{j*}, s_{j*})$.\nLikewise, $\\mu^h_{i*}$ and $s^h_{i*}$ are the mean and variance of the prediction for $h_{i*} = h_i(\\x_*)$, $p(h_{i*} | \\y, \\x_*) = \\Normal(h_{i*}; \\mu^h_{i*}, s^h_{i*})$.\nThese predictive means and variances are given by: \n\\begin{align}\n\\mu_{j*} &= \\vec{k}_{j*z} \\K_{jzz}^{-1} \\m_j  \\text{,}\\\\ \ns_{j*} &= k_{j**} - \\vec{k}_{j*z} \\left(\\K_{jzz}^{-1} - \\K_{jzz}^{-1} \\S_j \\K_{jzz}^{-1} \\right) \\vec{k}_{j*z}^T  \\text{,}\\\\\n\\mu^h_{i*} &= \\vec{k}_{i*z} \\K_{izz}^{-1} \\mhi \\text{,} \\\\\ns^h_{i*} &= k_{i**} - \\vec{k}_{i*z} \\left(\\K_{izz}^{-1} - \\K_{izz}^{-1} \\S_i \\K_{izz}^{-1} \\right) \\vec{k}_{i*z}^T \\text{,}\n\\end{align}\nwhere $k_{j**} = k_j(\\x_*, \\x_*)$, $k_{i**} = k^h_i(\\x_*, \\x_*)$,  $\\vec{k}_{j*z}$ is the covariance between $\\x_*$ and $\\Zj$, and $\\vec{k}_{i*z}$ is the covariance between $\\x_*$ and $\\Zhi$.\n\n%\\noindent Also as a consequence of sufficient statistics, the approximate prediction for test targets $\\vfstar$ at test inputs $\\X_*$ is\n%\\begin{align}\n%\\nonumber\n%p(\\vfstar | \\y, \\X_*) &= \\int p(\\vfstar | \\f, \\u, \\X_*) q(\\f, \\u | \\y) \\der \\f \\der \\u \\\\\n%\\nonumber\n%&= \\int p(\\vfstar | \\u) q(\\u| \\y) p(\\f | \\u) \\der \\f \\der \\u \\\\ \\nonumber\n%&= \\int p(\\vfstar | \\u) q(\\u| \\y) \\der \\u \\\\\n%\\label{eq:sorprediction}\n%&= \\Normal(\\vfstar; \\bs{\\mu_*},\\vec{s_*})\n%\\end{align}\n%where,\n%\\begin{align}\n%\\nonumber\n%\\bs{\\mu_*} &= \\K_{*z} \\K_{zz}^{-1}\\m \\\\ \n%\\nonumber\n%\\S_* &= \\K_{**} - \\K_{*z} \\left(\\K_{zz}^{-1} - \\K_{zz}^{-1} \\S \\K_{zz}^{-1} \\right) \\K_{*z}^T.\n%\\end{align}\n% Here $\\K_{*z}$ is the covariance matrix between test and inducing inputs, $\\K_{zz}$ is the covariance matrix of the inducing inputs.\n \n%\\begin{align}\n%p(\\fstar | \\y, \\x_*) = \\int \\Normal(\\fstar; \\sum_{j=1}^Q w_j g_{j*} + h_{i*}, 0) p(\\g_* | \\y, \\x_*) p(h_{i*} | \\y, \\x_*) \\der \\g_* \\der h_{i*},\n%\\end{align}\n", "meta": {"hexsha": "2baac4c1f574cc3f0d6f2418a4f6138c8ef680f6", "size": 17977, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/inference.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/inference.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/inference.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": 59.1348684211, "max_line_length": 237, "alphanum_fraction": 0.6548923625, "num_tokens": 6452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6249381730321045}}
{"text": "\\chapter{Multi-layer Kernel Machines}\n\\label{chap_mkm}\n%This chapter introduces the concept of MKMs proposed in \\cite{saul} et al., followed by an empirical study on some popular datasets cited extensively in deep learning literatures. This chapter is organized as follows; section \\ref{chap2_mkm} gives a brief introduction to MKMs and the multi-layer composition of few kernel functions, section \\ref{chap2_exp} contains the results of empirical study using MKMs, section \\ref{chap2_tsne} talks about the visualization technique used to plot the distribution of digits(from \\cite{mnist} dataset) in a low-dimensional space, section \\ref{chap2_mkm_mix} contains the results of empirical study on MKMs with mixed kernels and section \\ref{chap2_conc} concludes the chapter.  \n\n\n%\\label{chap2_mkm}\nMulti-layer Kernel Machines (MKMs\\nomenclature{MKM}{Multi-layer Kernel Machines}) were first introduced by \\cite{saul} et al. In their framework, arc-cosine kernel  which itself is having a layered architecture was used. The architecture of MKMs consists of $L$ layers and in each layer the data is subjected to unsupervised dimensionality reduction methods, viz. kernel PCA(\\cite{kpca} et al.),  followed by a supervised feature selection. \n\nThe MKM machines use multilayer kernel function, whose description is given in the next section. The rest of the chapter is organized as follows: section \\ref{chap2_exp} contains the results of empirical study using MKMs, section \\ref{chap2_tsne} describes the visualization technique used to plot the distribution of digits (from \\cite{mnist} dataset) in a low-dimensional space, section \\ref{chap2_mkm_mix} contains the results of empirical study on MKMs with mixed kernels and  concluding remarks are given in section \\ref{chap2_conc}.  \n\n\\section{Multi-layer Kernel}\nCorresponding to each Reproducing kernel Hilbert spaces (RKHS) $\\mathcal{F}$ there exists a unique reproducing kernel \n$k: \\mathcal{X} \\times \\mathcal{X} \\rightarrow \\mathcal{F}$,  where $ k(x,y) = \\phi(x) \\cdot \\phi(y), x, y \\in \\mathcal{X} \\; \\text{where} \\; \\mathcal{X}    \\text{ is a normed space, } \\phi(x), \\phi(y) \\in \\mathcal{F}$ and $\\cdot$ is the inner product defined on $\\mathcal{F}$.\n\nIteratively applying the mapping $\\phi(\\cdot)$ on the inputs $x \\textrm{ and } y$ and then taking their inner product, we can obtain an L-layer kernel function as\n\\[ k^{(L)}(x,y) = \\underbrace{\\phi(\\phi(\\ldots \\phi(x)))}_{\\textrm{L times}} \\textrm{ } \\cdot \\textrm{ } \\underbrace{\\phi(\\phi(\\ldots \\phi(y)))}_{\\textrm{L times}} \\]\n\nThus a $L$ layer kernel machine consists of $L$ RKHS's.\n\n\\subsection{Multi-layer Composition of Polynomial and Gaussian Kernels}\n\\label{chap2_mlother}\nA polynomial kernel of degree d is defined as follows\n\\[k(x, y) = (x \\cdot y)^d\\]\nConsider a two layer composition of polynomial kernel which can be computed as\n\\begin{equation*}\n\\begin{aligned}\n\\phi(\\phi(x)) \\cdot \\phi(\\phi(y)) &= \\bigg(\\phi(x) \\cdot \\phi(y)\\bigg)^d \\\\\n& = {(x \\cdot y)^d}^d =  {(x \\cdot y)^d}^2 \n\\end{aligned}\n\\end{equation*}\nThus the higher order compositions of polynomial kernels are simply polynomials of higher degree than the one from which it is constructed.\n\nThe two layer composition for gaussian kernels $k(x, y) = e^{-\\lambda\\norm{x-y}^2} $ is given by\n\\begin{equation*}\n\\begin{aligned}\n\\phi(\\phi(x)) \\cdot \\phi(\\phi(y)) &= e^{-\\lambda\\norm{\\phi(x)-\\phi(y)}^2} \\\\\n& = e^{-2\\lambda(1-k(x, y))}\n\\end{aligned}\n\\end{equation*}\n\n\\subsection{Multi-layer Composition of Arc-cosine Kernels}\n\\label{chap2_mlarc}\nLet x, y be two inputs in $\\mathbb{R}^d$. Define $\\theta$ as the angle between them.\n\\[ \\theta = cos^{-1}\\left ( \\frac{x\\cdot y}{\\left \\| x \\right \\| \\left \\| y \\right \\|} \\right ) \\]\nThen the kernel function computed by the arc-cosine kernel is\n\\begin{equation}\nk_n(x,y) = \\frac{1}{\\pi}\\left \\| x \\right \\|^n \\left \\| y \\right \\|^n J_n(\\theta)\n\\label{arc_cosine_kernel} \n\\end{equation}\nwhere n is called the \\textit{degree of the kernel} and\n\\[ J_n(\\theta) = (-1)^n(sin\\theta)^{2n+1} \\left ( \\frac{1}{sin\\theta} \\frac{\\partial}{\\partial \\theta} \\right )^n \\left ( \\frac{\\pi-\\theta}{sin\\theta} \\right ) \\]\n\n$J_n(\\theta)$ for n=0, 1, 2 is computed as shown below.\n\\[ J_0(\\theta) = \\pi-\\theta \\]\n\\[ J_1(\\theta) = sin\\theta + (\\pi-\\theta)cos\\theta \\]\n\\[ J_2(\\theta) = 3sin\\theta cos\\theta + (\\pi-\\theta)(1+2cos^2\\theta) \\]\nfor n=0, it takes the simple form\n\\[k_0(x,y) =  1- \\frac{1}{\\pi}cos^{-1}\\left ( \\frac{x\\cdot y}{\\left \\| x \\right \\| \\left \\| y \\right \\|} \\right )  \\]\nhence the name arc-cosine kernel is given.The kernel function computed by arc-cosine kernel is related to the computation of multi-layer threshold networks as shown below.\n\nConsider a single layer neural network with weights $W_{ij}$ that connects the $j^{th}$ input unit to the $i^{th}$ output unit(see figure \\ref{fig_singnet}). The network maps input $x$ to output $f(x)$ by applying a non-linear map \n\\[ f(x) = g(W \\cdot x) \\]\nwhere the non-linearity is described by the network`s activation function\n\\[g_n(z) = \\Theta(z)z^n \\]\nwith \n\\[ \\Theta(z) = \\frac{1}{2}(1+sign(z)) \\]\nthis activation function is called one-sided polynomial activation function, whose graph for different n values is also shown in figure \\ref{fig_singnet}.\n\n\\begin{figure}[H]\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[width=1.0\\linewidth, height=7cm]{figures/singnet}\n  \\caption{Single layer network and thresholded activation functions(\\cite{saul} et al.)}\n  \\label{fig_singnet}\n\\end{figure}\n\nLet $f(x)$ and $f(y)$ be the outputs corresponding to inputs $x$ and $y$. Then the inner product of $f(x)$ and $f(y)$ is\n\\[ f(x)\\cdot f(y) = \\sum_{i=1}^m \\Theta(w_i\\cdot x) \\Theta(w_i\\cdot y)(w_i\\cdot x)^n (w_i\\cdot y)^n\\]\nHere $w_i$ is the $i^{th}$ row of weight matrix $W$ and $m$ is the no of output units. Assume $W_{ij}$ are Gaussian distributed with zero mean and unit variance and the network has an infinite number of output units. Then\n\\[ lim_{m\\rightarrow \\infty} \\frac{2}{m}f(x)\\cdot f(y) = k_n(x,y) \\]\nwhere\n\\begin{equation}\nk_n(x,y) = 2\\int dw \\frac{e^{-\\frac{\\norm{w}^2}{2}}}{(2\\pi )^{d/2}} \\Theta (w\\cdot x) \\Theta (w\\cdot y) (w\\cdot x)^n (w\\cdot y)^n \n\\label{arc_cosine_integral}\n\\end{equation}\nThe kernel function obtained in equation \\ref{arc_cosine_integral} can be converted into an alternate form as in equation \\ref{arc_cosine_kernel} with the derivation shown in \\cite{saul} et al.\n\nThe multi-layer composition of arc-cosine kernel can be recursively computed as\n\\[ k^{(L+1)}_n(x,y) = \\frac{1}{\\Pi} \\Bigg[ k^{(L)}(x,x) \\textrm{ } k^{(L)}(y,y)\\Bigg]^{\\frac{n}{2}} J_n(\\theta_n^{(L)}) \\]\nwhere $\\theta_n^{(L)}$ is the angle between images of $x \\textrm{ and } y$ in the feature space after L layer composition\n\\[ \\theta_n^{(L)} = \\textrm{cos}^{-1}\\Bigg( k^{(L)}(x,y) \\Bigg[ k^{(L)}(x,x) \\textrm{ } k^{(L)}(y,y)\\Bigg]^{\\frac{-1}{2}} \\Bigg) \\]\nIn the above formulation, we have assumed that the arc-cosine kernels have the same degree $n$ at every layers of recursion. We can also use kernels of different degree at different layers. The intuition behind the multi-layer composition in case of arc-cosine kernels is, if the base kernel $k(x,y) = \\phi(x) \\cdot \\phi(y)$ can mimic the computation of a single-layer network, then the iterated mapping in $k^{(L)}(x,y)$ can mimic the computation of multi-layer network(\\cite{saul} et al.).\n\n\\subsection{MKM Architecture}\n The architecture of MKMs for solving classification tasks  is similar to that of neural network based deep learning machines, with unsupervised feature extraction(using Kernel PCA, \\cite{kpca} et al.) followed by supervised feature selection in each layer. Figure \\ref{fig_mkm} shows the architecture of an MKM consisting of $L$ layers of non-linear transformations.\n\n\\begin{figure}[h]\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.5]{figures/mkm}\n  \\caption{An MKM with L layers of transformations. Each layer consists of unsupervised feature extraction(using kernel PCA) followed by supervised feature selection.}\n  \\label{fig_mkm}\n\\end{figure}\n\nThe supervised feature selection allows us to retain only those set of features that are most informative for the pattern recognition task. The number of features to be passed to the next layer determines the width of that layer. The optimal layer width is computed by ranking the features based on their importance and selecting the required set of feature with the help of a lightweight classifier (detailed procedure is given in the experiments section). This procedure determines the architecture of the network in a greedy, layer-by-layer fashion. In their implementation \\cite{saul} et al. used exhaustive search in the range 10 to 300 to determine the optimal set of features. The output from the final layer can be passed to any classifier. Though any kernel can be used for the kernel PCA based feature extraction, \\cite{saul} et al. emphasized on using arc-cosine kernels due to their similarity with deep learning architecture of neural networks and the inclusion of multiple layers is significant  only in case of arc-cosine kernels.\n\n\\section{Experiments on Arc-cosine Kernel MKMs}\n\\label{chap2_exp}\nEmpirical study was conducted on four datasets, in which three were created from \\cite{mnist} dataset of handwritten digits by adding noise in the background and one was a binary classification problem on shape images. The detailed experimental set up and a short description about datasets used is given below. \n\\subsection{Experimental Set-Up}\nIn the training phase, for each layer we set apart 10000 datapoints for training the model and 2000 datapoints for cross validating kernel parameters. For the kernel PCA we chose 3000 datapoints  from the training set of 10000 images randomly. In each layer after extracting features with KPCA, we train a lightweight classifier like kNN and test the performance on the held out 2000 images. The best kernel parameter was chosen based on this performance values. With that parameter value, we did feature extraction on the entire dataset and then passed it to feature selection module. The feature selection was done by using univariate feature selection method available in \\cite{scikit} library. This method produces a ranking of features with a univariate statistical test. Based on this rank we can choose the required number of important features. We chose top 5 percent features based on this rank, since empirically it was giving a consistant performance.\n\nIn the final classification stage SVMs with arc-cosine kernels are used. The metric used for comparing the performance is, percentage loss in test dataset. Percentage loss is estimated as\n\\[ \\textrm{loss in percentage} = \\Bigg(1 - \\frac{\\# \\textrm{correct classifications}}{\\# \\textrm{datapoints}} \\Bigg) \\times 100 \\]\n\n\\subsection{Mnist-back-rand Dataset}\nThe \\textit{mnist-back-rand} dataset was created by filling the image background with random pixel values. Each pixel value of the background was generated uniformly between 0 and 255. Image size is 28$\\times$28 and the dataset contains 12000 training and 50000 testing images.\n\\subsection{Mnist-back-image Dataset}\nThe \\textit{mnist-back-image} dataset was generated by filling the image background with random image patches. The patches were extracted randomly from a set of 20 images downloaded from the internet. The dataset contains contains 12000 training and 50000 testing images, each of size 28$\\times$28.\n\\subsection{Mnist-rot-back-image Dataset}\nThe \\textit{mnist-rot-back-image} is a rotated variant of \\textit{mnist-back-image} where the rotation angle is generated uniformly between $0$ and $2\\pi$. Image size and number of samples are also the same as \\textit{mnist-back-image} dataset.\n\\subsection{Rectangles-image Dataset}\nFor \\textit{rectangles-image} dataset, the classification task is to identify whether a rectangle contained in an image has larger width or length. The dataset is constructed by uniformly sampling the height and width of the rectangles. Then random image patches are added in the background, where image patches are extracted from one of the 20 images used by \\textit{mnist-back-image}. Each image is of size 28$\\times$28 and each dataset contains 12000 training images and 50000 testing images.\n\nFigure \\ref{samples} contains some sample images from first three dataset and Figure \\ref{chap2_rect} contains the samples from \\textit{rectangles-image} dataset.\n\\begin{figure}[h]\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.55]{figures/data_sample1}\n  \\caption{sample images from \\textit{mnist-back-rand}(first row), \\textit{mnist-back-image}(second row) and \\textit{mnist-rot-back-image}(third row) datasets.}\n  \\label{samples}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.55]{figures/rect_image}\n  \\caption{sample images from \\textit{rectangles-image} dataset.}\n  \\label{chap2_rect}\n\\end{figure}\n\n\\subsection{Results and Analysis}\n\\renewcommand{\\arraystretch}{2.1}\n\\begin{table*}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Dataset}} & \\multicolumn{7}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-8}\n  & $\\textrm{SVM}_{\\textrm{RBF}}$ & $\\textrm{SVM}_{\\textrm{Poly}}$ & NNet & DBN-3 & SAA-3 & DBN-1 & MKMs\\\\\n  \\hline  \n  \\textit{back-rand} & 14.58 & 16.62 & 20.04 & \\textbf{6.73} & 11.28 & 9.80 & 10.55\\\\\n  \\hline\n  \\textit{back-image} & 22.61 & 24.01 & 27.41 & 16.31 & 23.00 & \\textbf{16.15} & 21.39\\\\\n  \\hline\n  \\textit{rot-back-image} & 55.18 & 56.41 & 62.16 & \\textbf{47.39} & 51.93 & 52.21 & 51.61\\\\\n  \\hline\n  \\textit{rect-image} & 24.04 & 24.05 & 33.20 & 23.69 & 24.05 & \\textbf{22.50} & 23.01\\\\\n  \\hline\n\\end{tabular}\n\\caption{Experimental Results of MKMs with Arc-cosine Kernels}\n\\label{tab_results_mkm}\n\\end{table*}\n\\renewcommand{\\arraystretch}{1}\n\nTable \\ref{tab_results_mkm} also contains best results obtained from other models(\\cite{dbn} et al.) like SVM with RBF kernel($\\textrm{SVM}_{\\textrm{RBF}}$), SVM with polynomial kenel($\\textrm{SVM}_{\\textrm{Poly}}$), single hidden layer feed-forward neural network(NNet\\nomenclature{NNet}{Neural Network with one hidden layer}), Deep Belif Networks(DBN)\\nomenclature{DBN}{Deep Belif Networks} with 1 hidden layer(DBN-1), DBN with 3 hidden layer(DBN-3) and 3 hidden layer Stacked Autoassociator Network(SAA-3). The first three models comes under shallow architectures and the remaining are deep architectures. From the table, it can be observed that MKMs outperforms all the remaining models except Deep Belif Networks(DBN). Compared to DBN the architecture, parameter tuning and optimization  are fairly simple in MKMs.\n\nThe change in the performance of the classifier when each adding layer to the model was also analyzed. Figures \\ref{mkm_rand} and \\ref{mkm_image} shows the variations in the classifier performance when model complexity was increased by adding more layers(on \\textit{mnist-back-rand} and \\textit{mnist-back-image} datasets respectively). The results indicates that in some cases better representation can be obtained even with a less complex model (eg: in case of \\textit{mnist-back-image} dataset, where the performance degrades when model complexity increases).\n\n\n\\begin{figure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.65]{figures/mkm_rand}\n  \\caption{Change in classifier performance on \\textit{mnist-back-rand} dataset when increasing the number of layers.}\n  \\label{mkm_rand}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.65]{figures/mkm_image}\n  \\caption{Change in classifier performance on \\textit{mnist-back-image} dataset when increasing the number of layers.}\n  \\label{mkm_image}\n\\end{figure}\n\n\\section{Visualizing Features using tSNE}\n\\label{chap2_tsne}\nIn order to visualize the features learned by the MKM, t-distributed Stochastic Neighbor Embedding(tSNE, proposed by \\cite{tsne} et al.) was used. tSNE\\nomenclature{tSNE}{t-distributed Stochastic Neighbur Embedding} is a tool for visualizing high-dimensional data. It converts the similarities between datapoints to joint probabilities and tries to minimize the Kullback-Leibler divergence(KL divergence) between the joint probabilities of the low-dimensional embedding and the high dimensional data(\\cite{tsne} et al.). tSNE is a variant of stochastic neighbor embedding \\nomenclature{SNE}, that is much easier to optimize and produce significantly better visualizations by reducing the tendency of the  points to get accumulated  at the center of the map.\n\nSuppose $X = \\{x_1, x_2, \\ldots, x_n\\}$ are the high-dimensional datapoints, and $Y = \\{y_1, y_2, \\ldots, y_n\\}$ the corresponding low-dimensional map points. In SNE, we first convert high-dimensional representation of datapoints into pairwise similarities that can be interpreted as conditional probabilities. Intuitively, the similarity of a datapoint $x_i$ to $x_j$ is interpreted as the probability of $x_i$ picking up $x_j$ as its neighbor with a Gaussian centered at $x_i$(denoted as $p_{j/i}$). Mathematically this is formulated as\n\\[ p_{j/i} = \\frac{exp(-\\norm{x_i-x_j}^2/2 \\sigma_i^2}{\\sum_{k\\neq i} exp(-\\norm{x_i - x_k}^2/2 \\sigma_i^2)}  \\]\n\nwhere $\\sigma_i$ is the variance of the Gaussian centered at $x_i$. For every $x_i$ we calculate corresponding $\\sigma_i$ which will vary according to the density of datapoints around $x_i$(if the region around $x_i$ is dense $\\sigma_i$ will be low and vice versa).\n\nSimilarly for the low-dimensional representations $y_i$ and $y_j$ corresponding to $x_i$ and $x_j$ respectively, we compute the conditional probability(denoted as $q_{j/i}$) by setting the variance of the Gaussian to $\\frac{1}{\\sqrt{2}}$. Thus\n\\[ q_{j/i} = \\frac{exp(-\\norm{y_i-y_j}^2}{\\sum_{k\\neq i} exp(-\\norm{y_i - y_k}^2)}  \\]\n\nSince we are only interested in modelling pairwise similarity, we set $p_{i/i} = q_{i/i} = 0$. The crux of SNE as stated by \\cite{tsne} et al. is ``if the map points $y_i$ and $y_j$ correctly model the similarity between high-dimensional datapoints $x_i$ and $x_j$ then the conditional probabilities $p_{j/i}$ and $q_{j/i}$ will be equal''. In this case, the cost function can be formulated to minimize the difference between conditional probabilities $p_{j/i}$ and $q_{j/i}$ using KL divergence. The cost function $C$ is defined as\n\\begin{equation}\nC = \\sum_{i}\\textrm{KL}(\\textrm{P}_i \\big|\\big| \\textrm{Q}_i) = \\sum_{i}\\sum_{j} p_{j/i} log \\frac{p_{j/i}}{q_{j/i}}\n\\label{cost_tsne}\n\\end{equation}\nwhere $\\textrm{P}_i$ is the conditional probability distribution over all other datapoints given datapoint $x_i$ and $\\textrm{Q}_i$ is the conditional probability distribution over all other map points given the map point $y_i$.\n\nThe minimization of the cost function in \\ref{cost_tsne} is performed by using gradient descent method. The gradient is computed as\n\\[ \\frac{\\partial C}{\\partial y_i} = 2\\sum_j(p_{j/i}-q_{j/i} + p_{i/j}-q_{i/j})(y_i - y_j) \\]\nThough SNE can produce good quality visualizations, it has the following limitations.\n\\begin{itemize}\n\\item Since the KL divergence is not symmetric, different types of error in the pairwise distances in low-dimensional map are not weighted equally(there is a large cost for using widely separated map points to represent nearby datapoints, but the cost is small for using nearby map points to represent widely separated datapoints).\n\\item crowding of map points in the center of the map.\n\\end{itemize}\n\ntSNE is a variant of SNE which improves the visualization quality by alleviating the above mentioned problems.\n\\begin{itemize}\n\\item It uses a symmetric version of the SNE cost function by employing a joint probability distribution instead of the conditional probability distribution used by SNE. This also results in simpler gradients.\n\\item It uses student-t distribution to compute the similarity between map points. tSNE employs a heavy-tailed distribution for the map points to alleviate both the crowding problem and optimization problems of SNE.\n\\end{itemize}\n\nIn the symmetric version of the  tSNE the cost function is computed as shown below.\n\\begin{equation*}\nC = \\textrm{KL}(\\textrm{P} \\big|\\big| \\textrm{Q}) = \\sum_{i}\\sum_{j} p_{ij} log \\frac{p_{ij}}{q_{ij}}\n\\end{equation*}\nwhere $P$ and $Q$ are the joint probability distribution functions in the high-dimensional and low-dimensional space respectively. Here also we set $p_{ii}$ and $q_{ii}$ to zero. The symmetry in the cost function is achieved due to the fact that $p_{ij} = p_{ji}$ and $q_{ij} = q_{ji}$ $\\forall i,j$. The joint probability in high-dimensional space($p_{ij}$) and low-dimensional space($q_{ij}$) are computed as\n\\[ p_{ij} = \\frac{exp(-\\norm{x_i-x_j}^2/2 \\sigma^2}{\\sum_{k\\neq l} exp(-\\norm{x_k - x_l}^2/2 \\sigma^2)}  \\]\n\\[ q_{ij} = \\frac{exp(-\\norm{y_i-y_j}^2}{\\sum_{k\\neq l} exp(-\\norm{y_k - y_l}^2)}  \\]\nThe gradient of the symmetric SNE has a fairly simple form\n\\[ \\frac{\\partial C}{\\partial y_i} = 4\\sum_j(p_{ij}-q_{ij})(y_i - y_j) \\]\nSymmetric SNE still faces problems when a datapoint $x_i$ is an outlier; when $x_i$ is an outlier $\\norm{x_i-x_j}^2$ is large for all $x_j$ with $x_i$, hence $p_{ij}$ are extremely low, so the location of its low-dimensional map point $y_i$ has very little effect on the cost function. This problem is addressed in tSNE by defining $p_{ij} = \\frac{p_{j/i} + p_{i/j}}{2n}$, which ensures that $\\sum_j p_{ij} \\ge \\frac{1}{2n}$ $\\forall \\textrm{ } x_i$, hence each datapoint $x_i$ makes a significant contribution to the cost function. The crowding problem is addressed in tSNE by using a student t-distribution with one degree of freedom as the heavy-tailed distribution in the low-dimensional map. Thus the joint probability $q_{ij}$ is computed as\n\\[ q_{ij} = \\frac{(1+\\norm{y_i-y_j}^2)^-1}{\\sum_{k \\neq l} (1+\\norm{y_k-y_l}^2)^-1} \\] \nThen, finally the gradient of the cost function is obtained as\n\\[ \\frac{\\partial C}{\\partial y_i} = 4\\sum_j(p_{ij}-q_{ij})(y_i - y_j)(1+\\norm{y_i-y_j}^2)^-1) \\]\n\ntSNE was employed in our experiments to understand the changes in the data distribution before and after the feature learning process. Figure \\ref{tsne_rand_raw} shows the tSNE embedding of the raw data from \\textit{mnist-back-rand} dataset and figure \\ref{tsne_rand_mkm} shows the same embedding applied on the features produced by MKM with arc-cosine kernels. The tSNE embedding of features learned by MKMs are crowded near the center, hence it was difficult to interpret the separability.\n\n\\begin{sidewaysfigure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.45]{figures/tsne_rand_rawdata}\n  \\caption{tSNE embedding of raw data from \\textit{mnist-back-rand} dataset.}\n  \\label{tsne_rand_raw}\n\\end{sidewaysfigure}\n\n\n\\begin{sidewaysfigure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.45]{figures/tsne_rand_mkmbest}\n  \\caption{tSNE embedding of features obtained by MKM from \\textit{mnist-back-rand} dataset.}\n  \\label{tsne_rand_mkm}\n\\end{sidewaysfigure}\n\n\n\n\\section{MKMs with Mixed Kernels}\n\\label{chap2_mkm_mix}\nWe tried different kernel functions in different layers of MKMs (Gaussian, arc-cosine, polynomial etc.) while performing KPCA. It had been seen that mixing a layer of Gaussian or polynomial kernel in between successive layers of arc-cosine kernel improves the result. This further supported the belief that, with more similarity information (by using more kernels) in hand, we can build better representations. Table \\ref{tab_results_mix} shows the result obtained with the mixed kernel models. Because of the improved performance, we used  Multi-layer Multiple Kernel Machines(ML-MKL) model for our analysis, whose  discussion is given in the next chapter.\n\n\\renewcommand{\\arraystretch}{2.1}\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Dataset}} & \\multicolumn{7}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-8}\n  & $\\textrm{SVM}_{\\textrm{RBF}}$ & $\\textrm{SVM}_{\\textrm{Poly}}$ & NNet & DBN-3 & SAA-3 & DBN-1 & $\\textrm{MKMs}_\\textrm{(mix)}$\\\\\n  \\hline  \n  \\textit{back-rand} & 14.58 & 16.62 & 20.04 & \\textbf{6.73} & 11.28 & 9.80 & 9.54\\\\\n  \\hline\n  \\textit{back-image} & 22.61 & 24.01 & 27.41 & 16.31 & 23.00 & \\textbf{16.15} & 20.94\\\\\n  \\hline\n  \\textit{rot-back-image} & 55.18 & 56.41 & 62.16 & \\textbf{47.39} & 51.93 & 52.21 & 54.03\\\\\n  \\hline\n  \\textit{rect-image} & 24.04 & 24.05 & 33.20 & 23.69 & 24.05 & \\textbf{22.50} & 25.04\\\\\n  \\hline\n\\end{tabular}\n\\caption{Experimental Results of MKMs with Mixed Kernels}\n\\label{tab_results_mix}\n\\end{table}\n\\renewcommand{\\arraystretch}{1}\n\nAs in MKMs with arc-cosine kernel, we chose top 5 percent features based on univariate test score for the mixed kernel MKMs. The classifier used in the output layer was an SVM\\nomenclature{SVM}{Support Vector Machines} with arc-cosine kernel. The results indicates that MKMs with mixed kernels improved the classifier performance for \\textit{mnist-back-rand} and \\textit{mnist-back-image} datasets, whereas the classification accuracy declined in the case of \\textit{mnist-rot-back-image} and \\textit{rectangles-image} dataset. The tSNE embedding of the features produced by MKMs with mixed kernels is shown in figure \\ref{tsne_rand_mkmmix} (for \\textit{mnist-back-rand} dataset). The best result in this dataset was obtained from a model consisting of three layers with a Gaussian kernel in the middle layer. The visualization indicates that, MKMs with mixed kernels has good separability between different classes.\n\\begin{sidewaysfigure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.45]{figures/tsne_rand_mkmmix}\n  \\caption{tSNE embedding of features obtained by MKM with mixed kernels from \\textit{mnist-back-rand} dataset.}\n  \\label{tsne_rand_mkmmix}\n\\end{sidewaysfigure}\n\n\n\\section{Conclusion}\n\\label{chap2_conc}\nIn this chapter we analysed the MKMs framework which has the characteristics of deep learning algorithms by employing  kernel methods. The empirical study indicated that MKMs are performing comparable with that of  popular deep learning algorithms like DBN, SAA etc. We also analysed the performnace of MKMs with mixed kernels. The mixing produces better results when other kernels are sandwiched between two arc-cosine kernels.\n\nThe visualization of features learned by MKMs are difficult to interpret due to crowding of datapoints near the center, but for MKMs with mixed kernels the visualization indicates that the separation is good enough between different classes, even though the samples from same class is distributed in different locations.\n", "meta": {"hexsha": "d5bfc994a99f4d7b006dd0ebef12014a3506817e", "size": 26831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter2.tex", "max_stars_repo_name": "akhilpm/Masters-Project", "max_stars_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_stars_repo_licenses": ["MIT"], "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/chapter2.tex", "max_issues_repo_name": "akhilpm/Masters-Project", "max_issues_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_issues_repo_licenses": ["MIT"], "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/chapter2.tex", "max_forks_repo_name": "akhilpm/Masters-Project", "max_forks_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_forks_repo_licenses": ["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.3400673401, "max_line_length": 1045, "alphanum_fraction": 0.7515560359, "num_tokens": 7652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.78793120560257, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6249129302136529}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm, mathtools}\n%\\usepackage{hyperref}\n\\usepackage{color}\n\\usepackage{jheppub}\n\\usepackage[T1]{fontenc} % if needed\n\n\\newcommand{\\be}{\\begin{equation}}\n\\newcommand{\\ee}{\\end{equation}}\n\\newcommand{\\bes}{\\begin{equation*}}\n\\newcommand{\\ees}{\\end{equation*}}\n\\newcommand{\\bea}{\\begin{flalign*}}\n\\newcommand{\\eea}{\\end{flalign*}}\n\n%\\linespread{1.0}\n%\\setlength{\\parindent}{0em}\n%\\setlength{\\parskip}{0.8em}\n\n\\title{\\textbf{Methods for Data}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\\abstract{}\n\n\\begin{document}\n\\maketitle\n\\section{A Few Basics}\n\nPhysicists believe in a \\textit{cause and effect} philosophy of the world. If we are given a fair coin, we can assign equal probabilities to \\textit{head} and \\textit{tail} and predict the outcomes given the number of times the coin is tossed. We could deal with unfair coins equally well, and given the properties of the unfair coin  (\\textit{ie.} probabilities of landing heads/tails/neither) are specified, we can make deductions about the outcomes of our \\textit{experiment}.\n\nBut, generally, we have information about the observed effects, from which we are supposed to ascertain what models/scenarios these effects would have arisen from. Consider tossing a single coin ten times. The nature of the coin is not specified, but we find that all ten times the coin lands heads up. Are we to believe that the coin is \\textit{biased}? Not quite. The most one can do is make some inference based on the data and our prior knowledge (\\textit{ie}. we say that the coin is \\textit{most likely} biased), adding a caveat that we reserve the right to alter our result if new information pops up in the future (\\textit{ie.} we have the data from more tosses of the same coin).\n\nThis makes the whole problem of \\textit{data analysis} open-ended. Through this exploration, we hope to understand the mathematical rules governing the analyses.\n\n\\subsection{Operations on Probabilities}\nAll the definitions of probability made below are with respect to some background information denoted by $ I $.\n\\begin{itemize}\n\t\\item \\textbf{Sum Rule} - Probability of an X being true and that of it being false should add up to 1.\n\t\\begin{equation*}\n\tP(X | I) + P (\\overline{X} | I) = 1\n\t\\end{equation*}\n\t\\item \\textbf{Product Rule} - Probability of both $ X $ and $ Y $ being true should be the product of probability of $ Y $ being true and the probability of $ X $ being true given $ Y $ is true.\n\t\\begin{equation*}\n\tP(X,Y| I) = P(X|Y,I) \\cross P(Y|I) = P(Y|X,I) \\cross P(X|I)\n\t\\end{equation*}\n\tThe symmetry property of the AND operation on $ X $ and $ Y $ means that we can interchange $ X $ and $ Y $ on the LHS.\n\t\\item \\textbf{Bayes' Theorem} - The probability of $ X $ conditioned on $ Y $ is proportional to the probability of $ Y $ conditioned on $ X $.\n\t\\begin{equation*}\n\tP(X|Y,I)  =\\dfrac{ P(Y|X,I) \\cross P(X|I)}{P(Y|I)}\n\t\\end{equation*}\n\tThe proof follows from the second and third expressions in the product rule. The magic of Bayes' theorem becomes evident when we replace $ X $ with \\textit{hypothesis} and $ Y $ with \\textit{data}.\n\t\\begin{equation*}\n\t\\underbrace{P(hypothesis|data,I)}_{\\text{posterior}} \\propto \\underbrace{ P(data|hypothesis,I)}_{\\text{likelihood}} \\cross \\underbrace{ P(data|hypothesis,I)}_{\\text{prior}}\n\t\\end{equation*}\n\tThe statement of the Bayes' theorem now becomes a powerful tool for inversion! Some definitions follow,\n\t\\begin{itemize}\n\t\t\\item \\textbf{Prior} - This encodes our degree of ignorance about the hypothesis before we have even touched the data.\n\t\t\\item \\textbf{Likelihood Function} - This encodes how well data agrees with a particular model (\\textit{Details Later}).\n\t\t\\item \\textbf{Posterior} - This gives us the degree of knowledge of the truth of the model in light of the data.\n\t\t\\item  \\textbf{Evidence} - $ P(data| I) $ which we omitted while writing the expression of the Bayes' theorem. In most cases, it will remain a proportionality constant.\n\t\\end{itemize}\n\n\t\\item \\textbf{Marginalization} - The probability of $ X $ is the same as the probability of $ X $ given $ Y_k $, summed over all $ k $. Here, $ \\{Y_k\\} $ is the set of all possibilities in $ Y $.\n\t\\begin{equation*}\n\tP(X| I) = \\sum_k P(X|Y_k, I)\n\t\\end{equation*}\n\tA continuous, integral form of the equation can be written as follows,\n\t\\begin{equation*}\n\tP(X|I) = \\int_{-\\infty}^\\infty P(X,Y|I) \\dd{Y} \n\t\\end{equation*}\n\\end{itemize}\n\\end{document}", "meta": {"hexsha": "59c94cb4545b5bf43b35707cf9bc1028579025f0", "size": 4642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "selfstudy/data/notes/data.tex", "max_stars_repo_name": "adivijaykumar/courses", "max_stars_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "selfstudy/data/notes/data.tex", "max_issues_repo_name": "adivijaykumar/courses", "max_issues_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "selfstudy/data/notes/data.tex", "max_forks_repo_name": "adivijaykumar/courses", "max_forks_repo_head_hexsha": "c0aebb67332ccf0b116a3348923ab2631b586dac", "max_forks_repo_licenses": ["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.2857142857, "max_line_length": 688, "alphanum_fraction": 0.7361051271, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6249129280943225}}
{"text": "In game theory, the default assumption is that all players are perfectly rational and that this is common knowledge between all players. From this assumption, often without additional arguments, game theorists assume that \\emph{backward induction} can be used to determine outcomes and strategies of perfect-information games. Backward induction is an algorithm that computes the outcome of a game assuming that all players want to maximize their payoffs from all states of the game.\n\nIn this section we shall investigate what rationality is. We shall also examine why common knowledge of rationality implies correctness of backward induction.\n\n\\paragraph*{Backward induction}\nThe idea of backward induction is straightforward: When a game tree has been constructed and payoffs have been assigned to the leaves, use a bottom-up approach to determine the \\emph{inductive outcome}. This approach can also determine the strategies of the players. \n\nStarting in the last stages (the nodes before the leaves) of the game tree, determine the action which yields maximal payoff and save the payoffs in the current node, so that the maximal payoffs propagate upwards in the tree until the root is encountered.\n\n\\subsection{Definitions and Assumptions}\nIn order to talk about rationality in perfect-information games, some important definitions and assumptions must be presented. Note that the Liar's Dice example is not used in this section, as it is not a game of perfect information.\n\n\\paragraph*{Strategy} A player participating in a game chooses a strategy, as defined previously in \\secref{seq:perfect-information}. This involves that a player, when choosing a strategy and deciding what action to take at some node $v$, act as though $v$ has been reached.\n\n\\paragraph*{Rationality} Rationality can now be defined as \\textit{choosing an action which yields maximum payoff at any node $v$}. In other word, a player will never choose a strategy that results in less payoff than another strategy, independent of which node he/she resides in. \nIt is important to understand that, even if $v$ is not reached, a player must still act rationally in $v$ for backward induction to work. This is also linked to the definition of strategy, as the player acts as though $v$ has been reached.\n\n\\paragraph*{Common knowledge of Rationality} The simple definition of rationality is enough, to show that backward induction works. Therefore the notion of common knowledge in epistemic logic is used. \nEssentially common knowledge of rationality boils down to all players being rational and all players knowing this fact. This piece of information is also known to all players, which results in an infinite chain of knowledge, which defines common knowledge. \n\n\\subsection{Results}\nAs stated before, it's important to assume that common knowledge of rationality holds, in order for backward induction to work.\nIntuitively, this requirement makes perfect sense, which is illustrated in \\figref{prg:lec5}:\nAssume that the black nodes in the game tree is where the player Ann has to select an action. She could either end the game by taking action 1, and receive 3 utils as payoff, or continue the game by choosing action 2. By backward induction it is obvious that she should end the game by choosing action 1, because she knows that Bob is rational and will choose payoffs $A:2$, $E:4$. By choosing action 2, Ann would not optimize her payoff, because she would only receive 2 utils. Let's say Ann doesn't know that Bob will act rationally. If Ann considers it possible that Bob is not rational, Bob could possibly choose the payoffs $A:7$, $E:1$, which then would maximize Anns payoff. Therefore the common knowledge of rationality is needed.\n\n\n\\begin{figure}[htbp]\n\\centering\n\t\\begin{tikzpicture}[every node/.style={draw,circle}, align=center, node distance=1.9cm]\n\t%Nodes\n\t\\node[draw,fill=black]   \t(q1)   {};\n\t\\node[draw, below right=1cm of q1,style={draw=none}]      (q2)   {$_{E:2}^{A:3}$};\n\t\\node[draw, below left of=q1]     (q3)   {};\n\t\\node[draw,fill=none, below right of=q3,style={draw=none}]    (q4)   {$_{E:4}^{A:2}$};\n\t\\node[draw,fill=none, below left of=q3,style={draw=none}]      (q5)   {$_{E:1}^{A:7}$};\n\tíges\n\t\\draw [line] (q1) -- (q2) node [label={[shift={(-0.6,-0.5)}]2},very near start, right, draw=none, fill=none] (TextNode) {1};\n\t\\draw [line] (q1) -- (q3) node [very near start, left, draw=none, fill=none] (TextNode) {2};\n\t\\draw [line] (q3) -- (q4) node [very near start, right, draw=none, fill=none] (TextNode) {1};\n\t\\draw [line] (q3) -- (q5) node [very near start, left, draw=none, fill=none] (TextNode) {2};\n\t\\end{tikzpicture}\n\t\\caption{Game tree for a perfect-information game between Ann and Bob.}\n\t\\label{prg:lec5}\n\\end{figure}\n\n\nHere, it can be seen that common knowledge of rationality implies backward induction. To proof that this is actually the case, one must look into epistemic logic to try and model the notion of common knowledge of rationality. \n\nFirst step is to create a possible worlds model $M$, where $\\Omega$ is the set of all states of the world. \nLet $s$  be a function defined by\n$$\ns(\\omega) = \\times_i S_i\n$$\nwhere $S_i$ is the set of all strategies of player $i$. The function $s$ is therefore a function that maps a state $\\omega$ in the world model, to a tuple of the players strategies at $\\omega$.\nLet the set of states in $M$, where the strategies of $s(\\omega)$ are rational for all players in the game, be denoted $R$. Let the set of states where $R$ is common knowledge be denoted $CR$. At some states in the $M$, the strategy represented in the state leads to the inductive outcome. Let $I$ denote these states.\nIn \\cite{aumann1995a} a detailed proof is given to show that\n$$\nCR \\subset I,\n$$\nwhich means that common knowledge of rationality implies correctness of backward induction.\n\n\\subsection{Discussion}\nIt is worth to investigate a play of a game where some nodes are not reached. Previously we assumed that a player would act rationally at every point in the game, but let's assume that we only demand rationality at the nodes that are actually reached in the game tree.\nIf a node is never reached, then one could possibly say that any decision made in that node is actually rational, but it's obvious that this prevents backward induction from working correctly. Therefore it is important to assume rationality at all nodes.\n\nCommon knowledge of rationality is a quite rare scenario in practice, given that the players are human. Often human players are not rational at all or at least it is not common knowledge. In these cases it would be irrational to choose a strategy based on the result of the backwards induction, because a player do not know the reasons for his/hers opponents choices.\n\nFrom a human perspective, perfect-information games with common knowledge of rationality are not fun to play, as the course of the game is completely known before the first move is made. It would be a complete waste of time to play a game and reach an outcome that was determined beforehand.\n", "meta": {"hexsha": "e595a8538a3cb2698d5ad25b6fe66696852e3ff7", "size": 7035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/rationality.tex", "max_stars_repo_name": "Andefar/LiarsDice", "max_stars_repo_head_hexsha": "f47123e80283a11500232d34102db2e894a4affb", "max_stars_repo_licenses": ["MIT"], "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/rationality.tex", "max_issues_repo_name": "Andefar/LiarsDice", "max_issues_repo_head_hexsha": "f47123e80283a11500232d34102db2e894a4affb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-11-24T13:56:28.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-01T17:21:52.000Z", "max_forks_repo_path": "Report/rationality.tex", "max_forks_repo_name": "Andefar/LiarsDice", "max_forks_repo_head_hexsha": "f47123e80283a11500232d34102db2e894a4affb", "max_forks_repo_licenses": ["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.9565217391, "max_line_length": 738, "alphanum_fraction": 0.7694385217, "num_tokens": 1700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311906630568, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6249129106587059}}
{"text": "\\section{Modular Arithmetic}\n\n% From prime numbers to simple criptography\n\n\\frame{\n{Part 4: Modular Arithmetic}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-5}]\n}\n\n% Modular arithmetic and congruence\n\n\\subsection{Congruence}\n\\begin{frame}{Modular Arithmetic and Congruence}\n\n  Using \\structure{modular arithmetic}, we can make the Turing Algorithm stronger.\\bigskip\n\n  Modular arithmetic is centred around the concept of \\structure{{\\bf Congruence}}:\n\n  \\begin{equation*}\n    a\\equiv b (\\text{modulo } n) \\iff n|(a-b)\n  \\end{equation*}\\bigskip\n\n  \\structure{Examples:}\n  \\begin{itemize}\n\\item $30\\equiv12 (\\text{modulo } 9)$,\\hspace{4.3cm} because $9|(30-12)$\n\\item $66666663 \\equiv 788253 (\\text{modulo } 10)$,\\hspace{2cm} because $10|66666663 - 788253$\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Modular Arithmetic and Congruence}{Remainder Theorem}\n\n  One important implication of the definition of equivalence is the remainder theorem:\n  \\begin{equation*}\n    a \\equiv b (\\text{mod } n) \\iff \\text{ rem}(a,n) = \\text{ rem}(b,n)\n  \\end{equation*}\n\n  \\begin{proof}\n    Proof by two way implication. Let the remainder of $a$ and $b$ be $r_{a,b}$:\n\n    \\begin{itemize}\n    \\item Let $a = q_an + r_{a,n}$, and $b = q_bn + r_{b,n}$\n    \\item (right side) {\\bf if} $r_{a,n} = r_{b,n}$ then $a-b = (q_a-q_b)n \\implies n|(a-b)$\n    \\item (left side) {\\bf if} $n|(a-b)$ then $n|((q_a-q_b)n+(r_{a,n}-r_{b,n}))$\n    \\begin{itemize}\n      \\item but $0 \\leq r_{*,n} < n$ so $r_{a,n}-r_{b,n}$ must be 0\n    \\end{itemize}\n    \\end{itemize}\n  \\end{proof}\n\\end{frame}\n\n% Congruence is preserved by addition and multiplication\n\\begin{frame}{Modular Arithmetic and Congruence}{Consequences of the Remainder Theorem}\n\n  Remainder Theorem:\n  \\begin{equation*}\n    a \\equiv b (\\text{mod } n) \\iff \\text{ rem}(a,n) = \\text{ rem}(b,n)\n  \\end{equation*}\n\n  \\begin{itemize}\n  \\item $a \\equiv b$ (mod n) {\\bf and} $b \\equiv c$ (mod n) {\\bf implies}\n    $a \\equiv c$ (mod n)\n  \\item $a \\equiv $ rem(a,n) (mod n) \\hspace{1cm} (\\alert{important!})\\bigskip\n  \\item $a \\equiv b$ (mod n) {\\bf implies} $a+c \\equiv b+c$ (mod n)\n  \\item $a \\equiv b$ (mod n) {\\bf implies} $ac \\equiv bc$ (mod n)\n  \\item $a \\equiv b$ (mod n) {\\bf and} $c\\equiv d$ (mod n)\\\\\n    \\hspace{2cm}{\\bf implies} $a+c \\equiv b+d$ (mod n) {\\bf and} $ac \\equiv bd$ (mod n)\n  \\end{itemize}\\bigskip\n\n  The last three consequences show that we can freely use \\structure{addition} and \\structure{multiplication} in modular arithmetic. Try to prove some of these consequences!\n\\end{frame}\n\n% Remainder Arithmetic\n\\begin{frame}{Using Modular Arithmetic}{General Principle of Modular Arithmetic}\n\n  \\begin{block}{}\n    You can simplify modulo operations composed of additions and multiplications by replacing integer operands by their remaiders.\n  \\end{block}\n\n  Example: What is $287^9 \\equiv$ ? (mod 4)\n\n  \\begin{itemize}\n    \\item Simplify $287^9$ (mod 4) to $3^9$ (mod 4), becase $r_{287,4} = 3$\n    \\item $3^9 \\to 3^8\\times 3 \\to 9^4 \\times 3$\n    \\item Simplify $9^4 \\times 3$ (mod 4) to $1^4 \\times 3$, because $r_{9,4} = 1$\n    \\item $289^9 \\equiv 1^4 \\times 3 \\equiv 3$ (mod 4)\n  \\end{itemize}\\bigskip\n\n  We calculated a large exponent without actually calculating the exponentiation!\n\\end{frame}\n\n% Remainder Inverse\n% Remainder inverse and relatively prime numbers\n\n\\subsection{Modular Inverses}\n\n\\begin{frame}{Modular Arithmetic and Division}\n\n  We so that modular arithmetic works for addition and multiplication, so what about \\structure{division}?\\bigskip\n\n  \\begin{itemize}\n    \\item $8\\times 2 \\equiv 3\\times 2$ (mod 10)\n    \\item $8\\times \\not{2} \\equiv 3\\times \\not{2}$ (mod 10)\n    \\item $8 \\equiv 3$ (mod 10) \\hspace{2cm} \\alert{\\bf FALSE!}\n  \\end{itemize}\\bigskip\n\n  We cannot cancel out multiplications arbitrarily!\n\\end{frame}\n\n\\begin{frame}{Modular Arithmetic and Division}{Modular Inverses}\n\n  When we cancel the multiplication of a real number, it is equivalent of multiplying it by its {\\bf multiplicative inverse}:\n\n  \\begin{equation*}\n    an = bn \\to a\\not{n} = b\\not{n} \\to a(n\\times \\frac{1}{n}) = b(n\\times \\frac{1}{n})\n  \\end{equation*}\n\n  So a multiplicative inverse of $n$ is the number $k$ so that $n\\times k =1$.\\bigskip\n\n  In modulo arithmetic, we have: $n\\times k \\equiv 1$ (mod m). But, it turns out that it is not possible to find a $k$ that solves this equation for every $n$ and $m$!\n\\end{frame}\n\n\n\\begin{frame}{Modular Inverses}{When does $n$ have an inverse, and how can we find it?}\n\n  It turns out that $n$ only has a modular inverse (module $m$) if $gcd(n,m) = 1$.\\bigskip\n\n  It is relatively easy to find the modular inverse:\n  \\begin{itemize}\n    \\item First we calculate gcd(n,m) using the pulverizer, and obtaining $s$ and $t$ so that $sm+tn=1$\n    \\item The multiplicative inverse of $n$ modulo $m$ is given by: $r_{m,t}$\n    \\item So $n\\times r_{m,t} \\equiv 1$ (mod $m$)\n  \\end{itemize}\n\\end{frame}\n\n\\subsection{Turing Code 2.0}\n\n\\begin{frame}{Turing Code 2.0}\n  Using Modular Arithmetic, we can solve some of the problems of the cryptography algorithm described in the last section:\n\n  \\begin{enumerate}\n    \\item The sender and the receiver agree on a large prime number $n$, which will be the module, as well as the secret key $k < n$\n    \\item {\\bf Encription:} The message $m$ is a prime number ($0 < m < n$). The sender calculates the secret message $\\hat{m}$ using modulo multiplication:\n    \\begin{equation*}\n      \\hat{m} = m\\times k \\text{ mod }n\n    \\end{equation*}\n    \\item {\\bf Decription:} The receiver multiplies the encrypted message $\\hat{m}$ by the inverse of the key: $k^{-1}$ (mod $n$):\n    \\begin{equation*}\n      m = \\hat{m}0\\times k^{-1} \\text{ mod }n\n    \\end{equation*}\n  \\end{enumerate}\n  We cannot find $k$ anymore by having two encrypted messages, so is this algorithm safe?\n\\end{frame}\n\n\\begin{frame}{Turing Code 2.0}{Breaking the Turing Code with a Plaintext Attack}\n\n  The new algorithm can be broken by what is called a \\structure{{\\bf Plaintext Attack}}.\\bigskip\n\n  Imagine that an attacker is able to acquire an encrypted message $\\hat{m}$ and its respective clear message $m$. To break this code:\\bigskip\n\n  \\begin{itemize}\n    \\item Calculate the multiplicative inverse of $m$ modulo $n$: $m^{-1}$, using the Pulverizer.\n    \\item Multiply the result by the encrypted message:\n    \\begin{itemize}\n      \\item $m^{-1}\\times \\hat{m} = m^{-1}\\times (m \\times k) = (m^{-1} \\times m) \\times k = 1\\times k$ (mod $n$)\n    \\end{itemize}\n    \\item This allows us to recover the secret key $k$.\n  \\end{itemize}\\bigskip\n\n  So this algorithm is not so good after all! :-(\n\\end{frame}\n", "meta": {"hexsha": "394c638d6b6e2a2deb8a4803f93a90c5ac80de1f", "size": 6632, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week03/04_ModularArithmetic.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": "week03/04_ModularArithmetic.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": "week03/04_ModularArithmetic.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": 38.5581395349, "max_line_length": 173, "alphanum_fraction": 0.6749095296, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.6248371391402043}}
{"text": "\\chapter{Massless Spin-1 Particles}\nWe approach the quantum description of photons via classical electromagnetism, since we know via the correspondence principle that Maxwell's equations describe their dynamics.\n\n\\section{Maxwell's equation and the classical potential}\\label{sec:maxwell}\nFor fields $\\vec{E}$ and $\\vec{B}$ in a vacuum (i.e.~not in material), Maxwell's equations are:\n\\begin{enumerate}\n\\item $\\div\\vec{E} = \\rho$, the charge density (Poisson's equation);\n\\item $\\div\\vec{B} = 0$, no magnetic monopoles;\n\\item $\\curl\\vec{E} = -\\pdv{\\vec{B}}{t}$, Faraday's law;\n\\item $\\curl\\vec{B} = \\vec{j} + \\pdv{\\vec{E}}{t}$ where $\\vec{j}$ is the charge current density (Amp{\\'e}re's law).\n\\end{enumerate}\n\nWe define the vector potential such that\n\\begin{equation}\\boxed{\n\\vec{B} = \\curl \\vec{A}\n}\\end{equation}\nso Maxwell~II is automatically satisfied. Substituting into Maxwell~III,\n\\begin{align}\n\\curl\\vec{E} &= -\\pdv{t} \\left( \\curl \\vec{A} \\right) \\nonumber \\\\\n&= -\\curl \\pdv{\\vec{A}}{t}\n\\end{align}\n\\begin{equation}\n\\Rightarrow \\quad \\curl \\left( \\vec{E} + \\pdv{\\vec{A}}{t} \\right) = 0.\n\\end{equation}\nThe solution to this equation defines the scalar potential,\n\\begin{equation}\n\\vec{E} + \\pdv{\\vec{A}}{t} = -\\grad \\phi.\n\\end{equation}\nSubstituting into Maxwell~I,\n\\begin{align}\n\\rho &= -\\laplacian{\\phi} - \\pdv{t} {\\div\\vec{A}} \\label{eq:MaxwellDensity}\n\\end{align}\nNow consider Maxwell~IV. The left-hand side is\n\\begin{align}\n\\curl \\vec{B} &= \\curl(\\curl{\\vec{A}}) \\\\\n&= \\grad(\\div\\vec{A}) - \\laplacian{\\vec{A}} \\label{eq:Maxwell4LHS}\n\\end{align}\nand the right-hand side is\n\\begin{align}\n\\vec{j} + \\pdv{\\vec{E}}{t} &= \\vec{j} - \\pdv{t}\\left(\\grad{\\phi} + \\pdv{\\vec{A}}{t}\\right) \\nonumber \\\\\n&= \\vec{j} - \\grad{\\pdv{\\phi}{t}} - \\pdv[2]{\\vec{A}}{t} \\label{eq:Maxwell4RHS}.\n\\end{align}\nEquating \\eqref{eq:Maxwell4LHS} and \\eqref{eq:Maxwell4RHS} gives an expression for the 3-current,\n\\begin{equation}\n\\vec{j} = \\pdv[2]{\\vec{A}}{t} - \\laplacian{\\vec{A}} + \\grad(\\pdv{\\phi}{t} + \\div\\vec{A}).\n\\end{equation}\nAlso, \\eqref{eq:MaxwellDensity} can be written\n\\begin{equation}\n\\rho = \\pdv[2]{\\phi}{t} - \\laplacian{\\phi} - \\pdv{t}(\\pdv{\\phi}{t} + \\div\\vec{A})\n\\end{equation}\nso we can write Maxwell's equations in covariant form:\n\\begin{equation}\\boxed{\nj^\\mu = \\partial^2 A^\\mu - \\partial^\\mu \\partial_\\nu A^\\nu \\label{eq:MaxwellCovariant}\n}\\end{equation}\nwhere the 4-current is $j^\\mu = \\mqty(\\rho \\\\ \\vec{j})$ and the 4-potential is $A^\\mu = \\mqty(\\phi \\\\ \\vec{A})$.\n\n\\section{Gauge transformations and the Lorenz condition}\nEquation \\eqref{eq:MaxwellCovariant} is invariant under gauge transformations that have the form\n\\begin{equation}\nA^\\mu \\rightarrow A^\\mu + \\partial^\\mu f\n\\end{equation}\nfor some scalar $f$; this is easily verified by direct substitution. For a global gauge transformation $f$ is constant but for local gauge transformations $f$ can be a function of the coordinates.\n\nThis degree of freedom may be frozen out by the choice of a particular `gauge'. The Lorenz\\footnote{The Lorenz gauge is named after Ludwig Lorenz and is Lorentz invariant, named after the work of Hendrik Lorentz.} gauge is the most natural choice with the condition\n\\begin{equation}\n\\partial_\\mu A^\\mu = 0 \\label{eq:LorentzGauge}\n\\end{equation}\nsuch that all electrodynamics (Maxwell's equations) are simply described by\n\\begin{equation}\\boxed{\n\\partial^2 A^\\mu = j^\\mu.\n}\\end{equation}\n\n\\subsection{Polarisation states of a free photon}\nSince the 4-potential $A^\\mu$ describes the photon, there are 4 possible orthogonal polarisations available to it. However, the Lorenz gauge removes one degree of freedom.\n\nFor a free photon, we have that the charge current $j^\\mu = 0$. Therefore,\n\\begin{equation}\n\\partial^2 A^\\mu = 0\n\\end{equation}\nwith polarised plane wave solutions $A^\\mu = \\epsilon^\\mu_i \\, e^{-ipx}$ where $\\epsilon^\\mu_i$ are the polarisation 4-vectors. Therefore, the Lorenz condition becomes\n\\begin{equation}\np_\\mu \\epsilon^\\mu_i = 0.\n\\end{equation}\nThis has removed one degree of freedom from the available polarisation states.\n\nNow consider the gauge transformation\n\\begin{equation}\nA^\\mu \\rightarrow A^\\mu + \\partial^\\mu\\left( i\\alpha e^{-ipx} \\right).\n\\end{equation}\nThen\n\\begin{equation}\n\\partial_\\mu \\partial^\\mu \\left( \\alpha e^{-ipx} \\right) = -i \\alpha p^2 e^{-ipx} = 0\n\\end{equation}\nsince $p^2 = 0$ for a free photon (it's massless). Therefore the photon is unchanged by such a gauge transformation, which can be written\n\\begin{equation}\n\\epsilon_i^\\mu \\rightarrow \\epsilon_i^\\mu + \\alpha p^\\mu.\n\\end{equation}\n\nWe are therefore free to make the gauge choice $\\epsilon_i^0 = \\epsilon_i^3 = 0$ (with the spatial axes chosen such that $p^0 = p^3 = E$) which corresponds to $\\alpha = -\\epsilon_\\mu^i p^\\mu / \\epsilon_\\nu^i \\epsilon_i^\\nu$.\n\nFor a free photon with 4-momentum $p = (E,\\,0,\\,0,\\,E)^T$, the surviving polarisation states are\n\\begin{equation*}\n\\epsilon_1^\\mu = \\mqty(0 \\\\ 1 \\\\ 0 \\\\ 0) \\quad \\text{and} \\quad \\epsilon_2^\\mu = \\mqty(0 \\\\ 0 \\\\ 1 \\\\ 0)\n\\end{equation*}\nwhich can be combined to give circular polarisations\n\\begin{equation*}\n\\epsilon_R^\\mu = \\frac{1}{\\sqrt{2}} (\\epsilon_1^\\mu + i\\epsilon_2^\\mu) \\quad \\text{and} \\quad \\epsilon_L^\\mu = \\frac{1}{\\sqrt{2}} (\\epsilon_1^\\mu - i\\epsilon_2^\\mu)\n\\end{equation*}\nwhich correspond to the $\\pm 1$ helicity photon.\n\nIn summary, a free spin-1 particle loses one degree of freedom under gauge fixing in electrodynamics. A second gauge fixing removes another degree of freedom, but this relies on the fact that the particle is both massless and free. Therefore, the free photon has only two possible transverse polarisations. In contrast, a virtual photon may also have timelike or longitudinal polarisation.\n\n\\section{Virtual photons and the photon propagator}\nWe saw when discussing the electrodynamics of scalars that the potential \\eqref{eq:potential}, $A^\\mu = -g^{\\mu\\nu}j_\\nu / q^2$, is a solution of Maxwell's equations in the Lorenz gauge, $\\partial^2 A^\\mu = j^\\mu$. There, this was verified by substitution but now it will be derived via the propagator approach.\n\nAs a functional of the spatial propagator, $G(x^\\prime; x)$, the potential is given by\n\\begin{equation}\nA^\\mu(x^\\prime) = \\int G(x^\\prime; x) \\, j^\\mu(x) \\, \\dd[4]{x}.\n\\end{equation}\nApplying the d'Alambertian differential operator, the left-hand side of the Lorenz condition may be expressed\n\\begin{align}\n\\partial^2 A^\\mu(x^\\prime) &= \\int  \\left[ \\partial^2 G(x^\\prime; x) \\right] \\, j^\\mu(x) \\, \\dd[4]{x}\n\\end{align}\nwhere we have used that $\\partial_\\mu j^\\mu = 0$ since the 4-current should be conserved (not explicitly shown for spin-1). The right hand side is\n\\begin{equation}\nj^\\mu = \\int \\delta^{(4)}(x^\\prime - x) \\, j^\\mu(x) \\, \\dd[4]{x}.\n\\end{equation}\nTherefore, we have that\n\\begin{equation}\n\\partial^2 G(x^\\prime; x) = \\delta^{(4)}(x^\\prime - x).\n\\end{equation}\nNow Fourier transform into momentum-space using $q^\\mu = -i\\partial^\\mu$,\n\\begin{equation}\n\\frac{1}{(2\\pi)^4} \\int (iq)^2 \\, \\mathcal{G}(q) \\, e^{-iq(x^\\prime - x)} \\, \\dd[4]{q}  = \\frac{1}{(2\\pi)^4} \\int e^{-iq(x^\\prime - x)} \\, \\dd[4]{q}\n\\end{equation}\nfrom which we see that the momentum-space propagator is $\\mathcal{G}(q) = -1/q^2$. Then the potential is\n\\begin{equation}\nA^\\mu(x) = \\frac{-j^\\mu(x)}{q^2} = \\frac{-g^{\\mu\\nu} j_\\nu(x)}{q^2}\n\\end{equation}\nBy convention, we actually define $\\boxed{\\mathcal{G}(q) = -i g^{\\mu\\nu}/q^2}$.\n\n\\subsection{Momentum-space propagators}\nGeneralising the above, the momentum-space propagator may be obtained by inverting the equation of motion for a free particle and multiplying by $-i$.\n\nThe Klein-Gordon equation gives $(\\partial^2 + m^2)\\psi = 0$ for free scalars. Therefore, the propagator is\n\\begin{align}\n\\frac{-i}{(iq)^2 + m^2} = \\frac{i}{q^2-m^2}.\n\\end{align}\n\nNow consider the Dirac equation for free spin-$\\frac{1}{2}$ particles. From \\eqref{eq:covDirac}, the equation of motion is\n\\begin{equation*}\n(i \\gamma^\\mu \\partial_\\mu - m)\\psi = 0.\n\\end{equation*}\nThen, using that $i\\partial_\\mu = p_\\mu$ (note the lower-index form), the propagator is\n\\begin{align}\n\\frac{-i}{\\gamma^\\mu q_\\mu - m} &= \\frac{i}{\\gamma^\\mu q_\\mu - m} \\nonumber \\\\\n&= \\frac{i\\,(\\fsl{q}+m)}{(\\fsl{q}-m)(\\fsl{q}-m)} \\nonumber \\\\\n&= \\frac{i \\, (\\fsl{q}+m)}{q^2 - m^2} \\nonumber \\\\\n&= i \\frac{\\sum u_S \\overline{u}_{S^\\prime}}{q^2 - m^2}\n\\end{align}\nwhere on the third line we have used that, from the properties of the $\\gamma$-matrices, $\\fsl{q}^2 = \\gamma^\\mu q_\\mu \\gamma^\\nu q_\\nu = q^2$ and the spinor completeness relation has been used to obtain the last line. The sum is over all possible spins, $S$ and $S^\\prime$.\n\n\\section{Longitudinal and timelike virtual photons}\nSince we cannot imply the Lorenz gauge condition, virtual photons have four available polarisation states: two transverse, longitudinal, and timelike.\n\n\\subsection{Coulomb's law}\n\nThe amplitude for photon exchange between two currents is given by\n\\begin{align}\nA &= j_\\mu^A \\left( \\frac{-ig^{\\mu\\nu}}{q^2} \\right) j^\\nu_B \\nonumber \\\\\n&= j_\\mu^A \\left( \\frac{-i}{q^2} \\right) j^\\mu_B.\n\\end{align}\nNow the momentum exchange is $q^\\mu$. But we know that the four-current is conserved by QED and therefore $q_\\mu j^\\mu = 0$.\n\nWe are free to choose that the photon travels along the $z$- or $t$-axes, so $q_1 j^1 = q_2 j^2 = 0$. Then the continuity equation becomes\n\\begin{equation}\nq_\\mu j^\\mu = q_0 j^0 - q_3 j^3 = 0.\n\\end{equation}\nSubstituting back into the amplitude,\n\\begin{align}\nA &= \\frac{-i}{q^2} \\left[j_0^A j^0_B - j_3^A j^3_B\\right] \\nonumber \\\\\n&= \\frac{-i}{q^2} \\left[j_0^A j^0_B - \\frac{q_0^2}{q_3^2}(j_0^A j^0_B)\\right] \\nonumber \\\\\n&= \\frac{-i}{q_0^2 - q_3^2} \\left[ \\frac{q_3^2 - q_0^2}{q_3^2} j_0^A j^0_B \\right] \\nonumber \\\\\n&= i \\, \\frac{j_0^A j^0_B}{q_3^2}.\n\\end{align}\nThis is Coulomb's law for electromagnetism in 3-momentum space.\n\n\\subsection{Completeness relation}\nFor free photons, the two allowed transverse polarisations give the completeness relation\n\\begin{equation}\n\\sum_{P, Q} \\epsilon^P_\\mu \\epsilon_Q^\\nu = \\mqty(0,\\,1,\\,0,\\,0) \\mqty(0\\\\1\\\\0\\\\0) + \\mqty(0,\\,0,\\,1,\\,0) \\mqty(0\\\\0\\\\1\\\\0) = \\mqty(1&0\\\\0&1) = I_2.\n\\end{equation}\n\nIn the case of virtual photons with four allowed polarisations, this becomes\n\\begin{equation}\n\\sum_{P, Q} \\epsilon^P_\\mu \\epsilon_Q^\\nu = \\mqty(\\dmat[0]{-1,1,1,1}) = -g^{\\mu\\nu}\n\\end{equation}\nwhich embeds the completeness relation for real photons.\n", "meta": {"hexsha": "987668208e56249ae87a6b37626efb467956b43f", "size": 10345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/12_Massless_Spin-1_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/12_Massless_Spin-1_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/12_Massless_Spin-1_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": 51.9849246231, "max_line_length": 389, "alphanum_fraction": 0.6930884485, "num_tokens": 3587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6248371391402043}}
{"text": "\\newcommand\\chapternumber{3}\n\\input{../tex_header/header.tex}\n\\usepackage{enumerate}\n\\usepackage{float}\n\n\\begin{document}\nCollaborators: Julia Zimmerman, Jordan Donovan, Sam Rosenblatt, Milo Trujillo, Phil Nguyen, Nicholas Vartanian,Connor Klopfer, Brett Meyer...\nWe might have discussed problems related to the assignments via Slack.\n\\section{Manual Gradient Descent}\n\\begin{align*}\n    \\frac{\\partial \\ell_i}{\\partial \\theta_j} = -2 x_{ij} (y_i - \\sum_{j'=1}^{p} x_{ij'} \\theta_{j'}) \\\\\n\\end{align*}\n\\begin{align*}\n    \\nabla_{\\theta} \\ell & = \\sum_{i=1}^{N} \\begin{bmatrix}\n        \\frac{\\partial \\ell_i}{\\partial \\theta_1} \\\\\n        \\frac{\\partial \\ell_i}{\\partial \\theta_2} \\\\\n        \\vdots                                    \\\\\n        \\frac{\\partial \\ell_i}{\\partial \\theta_p} \\\\\n    \\end{bmatrix} \\\\\\\\\n                         & = -2 x^T (y-x\\theta)\n\\end{align*}\n\nI used the dataset this \\href{https://www.kaggle.com/sulianova/cardiovascular-disease-dataset}{Cardiovascular Disease dataset}.\n\nThe are 70k records in this dataset.\nThe task is to predict whether a person has cardiovascular disease or not base on his age, height, etc.\nI split the dataset into 80\\% training and 20\\% testing.\n\nThe source code is on \\href{https://github.com/liusida/ds2/blob/main/assignment3/code/q1.py}{GitHub q1.py}.\n\nI discovered that larger batch size and larger learning rate will result in faster convergence,\nhowever, if learning rate is too large, the learning might diverge,\nand if batch size and learning rate is too large will cause overflow.\nSo I normalized the input to reduce the possibility of overflow, and choose a batch size of 7k, and a small learning rate.\nNow the learning process with 1k epochs takes 1.5 seconds. (If I use a batch size of 100, it will take 9.8 seconds.)\n\nThe final test accuracy is 0.643.\nI also report the final confusion matrix:\nSensitivity 0.574, Specificity 0.712,\nPrecision 0.667, Negative Predictive Value 0.625.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=.8\\textwidth]{./q1.pdf}\n    \\caption{Learning curve and two test points.}\n\\end{figure}\n\nWhy would I choose to manually do gradient descent?\nBecause I want to learn how it works, and also, as David mentioned in class, sometimes we have constraints in practice, for example there's possibility that PyTorch is not supported.\n\n\\newpage\n\\section{2D Rosenbrock function}\n\\begin{figure}[h]\n    \\includegraphics[width=.99\\textwidth]{./rosenbrock.pdf}\n    \\caption{Visualization of 2D Rosenbrock function. $x \\in (-30,30)$, $y \\in (-300,800)$}\n\\end{figure}\n\nIt is hard for SGD because the low area is not a dot but a long belt.\nIf the learning rate is large, it will diverge.\nIf the learning rate is low, it will be very slow in finding the minima on that flat belt.\n\nAnalytically, we need to solve the equations: $\\frac{\\partial f}{\\partial x} = 0$ and $\\frac{\\partial f}{\\partial y} = 0$.\n\n\\begin{align*}[left = \\empheqlbrace]\n    \\frac{\\partial}{\\partial x} (1-x)^2+100(y-x^2)^2 & = 0 \\\\\n    \\frac{\\partial}{\\partial y} (1-x)^2+100(y-x^2)^2 & = 0 \\\\\n\\end{align*}\n\n\\begin{align*}[left = \\empheqlbrace]\n    400x^3-400xy+2x-2 & = 0  \\\\\n    y                 & =x^2 \\\\\n\\end{align*}\n\n\\begin{align*}\n    400x^3-400x^3+2x-2 & = 0 \\\\\n    x                  & =1  \\\\\n    y                  & =1  \\\\\n\\end{align*}\n\nUsing routine gradient descent, start from $x_0=0, y_0=0$, learning rate $\\gamma=10^{-3}$, run for 10k steps.\nThe optimization successfully converged to the minimum.\n\nThis is because the initialization is quite close to the minimum,\nand because it is smooth in $x \\in (0,1)$ and $ y \\in (0,1)$.\nFigure \\ref{fig:routine_gd} shows the trajectory of the optimization.\n\n\\begin{figure}[h]\n    \\includegraphics[width=.8\\textwidth]{./routine_gd.png}\n    \\caption{Visualization of the optimization trajectory. $x \\in (0,1)$, $y \\in (0,1)$.}\n    \\label{fig:routine_gd}\n\\end{figure}\n\nIf we are not that lucky and use a bad initialization, such as $x_0 = 3$, $y_0 = -2$,\nthen the routine gradient descent will be harder.\nThe learning rate need to be smaller, otherwise it will diverge.\nThen momentum is needed to speed the optimization up.\nI set momentum to 0.99, learning rate $\\gamma=10^{-5}$, and run for 10k steps.\nThe optimization successfully converged to the minimum.\nFigure \\ref{fig:gd_m} shows the trajectory.\n\n\\begin{figure}[h]\n    \\includegraphics[width=.8\\textwidth]{./gd_m.png}\n    \\caption{Visualization of the optimization trajectory with momentum. $x \\in (0,3)$, $y \\in (-2,5)$.}\n    \\label{fig:gd_m}\n\\end{figure}\n\nThe source code is on \\href{https://github.com/liusida/ds2/blob/main/assignment3/code/q2.py}{GitHub q2.py}.\n\n\\newpage\n\\section{Math notations and plate notations}\n\\subsection{Basic Parametric Density Estimation}\nMathematically, let $l=\\text{loc}$, $s=\\text{inv scale}$, we have:\n\\begin{align*}\n     & p(l, s, d_i)                                                                                                                                                \\\\\n     & \\propto p(l)p(s)\\prod_{i=1}^N p(d_i|l,s)                                                                                                                    \\\\\n     & = \\text{Normal}(0,1) \\text{Inv-Gamma}(3,2) \\prod_{i=1}^N \\text{Normal}(l, s)                                                                                \\\\\n     & = \\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}l^2} \\frac{2^3}{2!}s^{-3-1} e^{-\\frac{2}{s}} \\prod_{i=1}^N \\frac{1}{s\\sqrt{2\\pi}} e^{-\\frac{1}{2}(\\frac{d_i-l}{s})^2} \\\\\n     & = 4 (\\frac{1}{\\sqrt{2\\pi}})^{N+1} s^{-4-N} e^{-\\frac{l^2}{2} -\\frac{2}{s} - \\frac{1}{2}\\sum_{i=1}^N (\\frac{d_i-l}{s})^2}                          \\\\\n\\end{align*}\nIt doesn't seem to have conjugate prior to me.\n\nPlate notation:\n\\begin{figure}[h]\n    \\centering\n    \\tikz{\n        % nodes\n        \\node[obs] (data) {$d_i$};%\n        \\node[latent,above=of data] (loc) {loc};\n        %    \\node[latent,above=of loc,xshift=-1cm] (mu) {$\\mu$}; %\n        %    \\node[latent,above=of loc,xshift=1cm] (sigma) {$\\sigma$}; %\n        \\node[latent,left=of data] (scale) {scale};\n        \\node[latent,left=of scale] (inv_scale) {inv\\_scale};\n        %    \\node[latent,left=of inv_scale,yshift=1cm] (alpha) {$\\alpha$};\n        %    \\node[latent,left=of inv_scale,yshift=-1cm] (beta) {$\\beta$};\n        % plate\n        \\plate [inner sep=.3cm,xshift=.02cm,yshift=.2cm] {plate1} {(data)} {N}; %\n        % edges\n        %    \\edge {sigma,mu} {loc}\n        %    \\edge {alpha,beta} {inv_scale}\n        \\edge {inv_scale} {scale}\n        \\edge {scale,loc} {data}\n    }\n    \\caption{Plate notation}\n\\end{figure}\n\n\\newpage\n\\subsection{Continuous, nonstationary hidden Markov}\n\nMathematically, let $l=\\text{loc}$, $s=e^{\\text{log scale}}$, $o=\\text{obs scale}$, we have:\n\\begin{align*}\n     & p(l,s,o,x_{n,t},y_{n,t})                                                                                                                                         \\\\\n     & =p(l)p(s)p(o)\\prod_{n=1}^N p(x_{n,0}|l,s) \\prod_{t=1}^T p(x_{n,t}|l,x_{n,t-1},s) p(y_{n,t}|x_{n,t}, o)                                                           \\\\\n     & =\\text{Normal}(0,1) \\text{LogNormal}(0,1) \\text{Gamma}(2,2) \\prod_{n=1}^N \\text{Normal}(l,s) \\prod_{t=1}^T \\text{Normal}(l+x_{n,t-1},s) \\text{Normal}(x_{n,t},o) \\\\\n     & =\\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{l^2}{2}} \\cdot\n    \\frac{1}{s\\sqrt{2\\pi}}e^{-\\frac{\\log(s)^2}{2}} \\cdot\n    \\frac{1}{2!2^2}o^{2-1}e^{-\\frac{o}{2}}  \\cdot\n    \\prod_{n=1}^N\n    \\frac{1}{s\\sqrt{2\\pi}}e^{-\\frac{(x_{n,0}-l)^2}{2s^2}}\n    \\prod_{t=1}^T\n    \\frac{1}{s\\sqrt{2\\pi}}e^{-\\frac{(x_{n,t}-l-x_{n,t-1})^2}{2s^2}}\n    \\frac{1}{o\\sqrt{2\\pi}}e^{-\\frac{(y_{n,t}-x_{n,t})^2}{2o^2}}                                                                                                         \\\\\n\\end{align*}\n\nPlate notation (Reference: \\href{https://davidrushingdewhurst.com/blog/2020-07-28keep-using-plate-notation.html}{this blog post}):\n\\begin{figure}[h]\n    \\centering\n    \\tikz{\n        % \\draw[lightgray,ultra thin] (-6,-6) grid (6,6);\n        % nodes\n        \\node[obs] (y_t) {$y_{n,t}$};%\n        \\node[latent,left=of y_t] (x_t) {$x_{n,t}$};%\n        \\node[latent,above=of x_t] (x_0) {$x_{n,0}$};%\n        \\node[latent,above=of x_0,xshift=1.5cm] (loc) {loc};%\n        \\node[latent,right=of loc] (scale) {scale};%\n        \\node[latent,above=of scale] (log_scale) {log scale};%\n        \\node[latent,right=of y_t] (obs_scale) {obs scale};%\n        % plate\n        \\plate [inner sep=.3cm,xshift=.02cm,yshift=.2cm] {episode} {(x_t)(y_t)} {T}; %\n        \\plate [inner sep=.3cm,xshift=.02cm,yshift=.2cm] {plate1} {(x_0)(episode)} {N}; %\n        % edges\n        \\edge {obs_scale,x_t} {y_t}\n        \\edge {loc,scale} {x_t}\n        \\edge {loc,scale} {x_0}\n        \\edge {log_scale} {scale}\n        % hmm...\n        \\draw[blue, thick, ->,shorten >=1pt] (x_0) to [out=-90,in=90] node[left,yshift=.2cm,xshift=-.2cm] {$t=1$} (x_t);\n        \\Cycle[blue, ->]{x_t}{180}{7mm}[{node[anchor=0,pos=0.5]{$t=2,...,T (t-1\\rightarrow t)$}}]{7mm}\n    }\n    \\caption{Plate notation}\n\\end{figure}\n\n\\newpage\n\\subsection{Switching model}\nMathematically, let $s'=\\text{log scale}$, $s=e^{s'}$, $w=\\text{switch}$, $m_1=\\text{model1}$, $m_2=\\text{model2}$, we have:\n\\begin{align*}\n     & p(s,z_0,z_t,p_t,m_{1,t},m_{2,t},w_{t,n},y_{t,n},x_{t,n})                                                                                             \\\\\\\\\n     & =p(s)p(z_0|s) \\times                                                                                                                                 \\\\\n     & \\prod_{t=1}^T p(z_t|z_{t-1}) p(p_t|z_t) \n     \\prod_{n=1}^N p(w_{t,n}|p_t) \n     p(m_{1,t}|t) p(m_{2,t}|t) p(y_{t,n}|w_{t,n},m_{1,t},m_{2,t}) \n     p(x_{t,n},y_{t,n}) \\\\\\\\\n     & =\\text{LogNormal}(0,1)\n    \\text{Normal}(0,s) \\times                                                                                                                               \\\\\n     & \\prod_{t=1}^T \\text{LogitNormal}(z_{t-1},1)\n    \\prod_{n=1}^N \\text{Bernoulli}(p_t)\n    p(m_{1,t}|t) p(m_{2,t}|t)\n    p(y_{t,n}|w_{t,n},m_{1,t},m_{2,t})\n    \\text{Poisson}(y_{t,n})                                                                                                                                 \\\\\\\\\n     & =\\frac{1}{s\\sqrt{2\\pi}}e^{-\\frac{\\log(x)^2}{2}} \\cdot\n    \\frac{1}{s\\sqrt{2\\pi}}e^{-\\frac{z_0^2}{2s^2}} \\cdot \\\\\n    &\\prod_{t=1}^T \\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{\\text{logit}(z_t-z_{t-1})^2}{2}} \\cdot\n    \\prod_{n=1}^N p_t^{w_{t,n}} (1-p_t)^{1-w_{t,n}}\n    p(m_{1,t}|t)^{w_{t,n}} p(m_{2,t}|t)^{1-w_{t,n}}\n    \\frac{y_{t,n}^{x_{t,n}} e^{-y_{t,n}}}{x_{t,n}!}\n\\end{align*}\n\n\nPlate notation (next page):\n\\begin{figure}[!t]\n    \\centering\n    \\tikz{\n        % \\draw[lightgray,ultra thin] (-6,-6) grid (6,6);\n        % nodes\n        \\node[obs] (x_t) {$x_{n,t}$};%\n        \\node[latent, left=of x_t] (y_t) {$y_{n,t}$};\n        \\node[latent, below=of y_t, xshift=-2cm] (model1) {model1$_t$};\n        \\node[latent, below=of y_t] (model2) {model2$_t$};\n        \\node[latent, left=of y_t, yshift=2cm] (switch) {switch$_{t,n}$};\n        \\node[latent, left=of switch] (p) {$p_t$};\n        \\node[latent, left=of p] (z) {$z_t$};\n        \\node[latent, above=of z] (z0) {$z_0$};\n        \\node[latent, above=of z0] (scale) {scale};\n        \\node[latent, left=of scale] (log_scale) {log scale};\n        % plate\n        \\plate [inner sep=.3cm] {plate_switch} {(x_t)(y_t)(switch)} {N};\n        \\plate [inner sep=.3cm] {episode} {(plate_switch)(model1)(model2)(p)(z)} {T};\n        % edges\n        \\edge {scale} {z0};\n        \\edge {log_scale} {scale};\n        \\edge {z} {p};\n        \\edge {p} {switch};\n        \\edge {switch, model1, model2} {y_t};\n        \\edge {y_t} {x_t};\n        \\draw[blue, thick, ->,shorten >=1pt] (z0) to [out=-90,in=90] node[left,yshift=.2cm,xshift=-.2cm] {$t=1$} (z);\n        \\Cycle[blue, ->]{z}{180}{7mm}[{node[anchor=0,pos=0.5]{$t=2,...,T (t-1\\rightarrow t)$}}]{7mm}\n    }\n    \\caption{Plate notation}\n\\end{figure}\n\n\\newpage\n\\section{PPL via Pyro}\n\nThe source code is on GitHub:\n\\begin{enumerate}\n    \\item \\href{https://github.com/liusida/ds2/blob/main/assignment3/code/q4.1.py}{q4.1.py}.\n    \\item \\href{https://github.com/liusida/ds2/blob/main/assignment3/code/q4.2.py}{q4.2.py}.\n    \\item \\href{https://github.com/liusida/ds2/blob/main/assignment3/code/q4.3.py}{q4.3.py}.\n\\end{enumerate}\n\n\\newpage\n\\section{Project Thoughts}\n\\subsection{Bayesian Learning Signal}\nI like Deep Learning.\n\nIn Supervised Learning, the learning signal comes from the difference between the truth label $y$ and the prediction $\\hat{y}$.\n\nTo analyze its assumption, I perform a derivation using MAP:\n\nSuppose we observe a image $\\cal{I}$, we want to know a vector representation of the image $h$ that can tell us $y=\\text{argmax}(h)$.\n\nAssuming the prior to be $h_0 \\sim \\textbf{Uniform}(a,b)$, here $a$ and $b$ are constants.\nThe observation $\\hat{h}$ is the representation produced by the network after seeing the image,\nAssuming $\\hat{h} \\sim \\textbf{Normal}(h, \\sigma)$, here we don't know $\\sigma$ yet.\nThis Normal distribution is saying the network can produce a prediction that is centered at $h$ but very noisy.\nThese two are quite strong assumptions.\n\nNow I can use MAP to compute the point estimate for $h_0$ given $\\hat{h}$:\n\\begin{align*}\n    p(h_0|\\hat{h}) &\\propto p(\\hat{h}|h_0) p(h_0)\\\\\n    &= \\textbf{Normal}(h,\\sigma) \\cdot \\textbf{Uniform}(a,b) \\\\\n    &= \\frac{1}{\\sigma \\sqrt{2 \\pi}} e^{-\\frac{(h-\\hat{h})^2}{2\\sigma^2}} \\cdot 1\\\\\n\\end{align*}\n\nSolve $\\frac{d}{dh}p(h_0|\\hat{h})=0$ to find the maximum:\n\\begin{align*}\n    \\frac{h_0-\\hat{h}}{\\sigma^3} e^{-\\cdots} &= 0\\\\\n    h_0-\\hat{h} = 0\n\\end{align*}\n\nSo we want to update our belief from $h_0$ to $h_1$: $h_1 = \\hat{h}$.\n\nThis is how we find the update target, I think?\nAnd we apply L2 loss to it, it'll just like a normal supervised learning signal.\n\nNow if the agent has the chance to observe a very similar image $\\cal{I}'$, here we don't use the i.i.d. assumption,\nso a better prior should be $h_1$ after the update of the first step.\nThe problem here is that by using MAP, we only have a point estimator, \nwe don't have a distribution for $h_1$, how can I discover a good $h_1$?\n\nWhy I am doing this?\n\nImagine there is a robot with a camera on its face.\nIt will observe the world, frame by frame.\nI assume the current frame of the world is very much similar to the previous frame.\nIf I can derive a learning signal from this assumption,\nthe agent will be able to learn without human providing labels.\n\nOnce there is a good way to produce the representation $h$ of the image,\nwe can use whatever existing supervised learning or reinforcement learning to utilize this representation,\nand the learning will be faster, I hope.\n\nI read \\cite{wang_survey_2020}. It focus of this paper is to connect Bayesian Inference and Deep Learning at an application level, which is not my focus. \nBut I learned some basic concepts from it.\nThe so called Bayesian treatments might give the distribution of $h$.\n\n\\subsection{Thought two}\n\nWith a second thought, the previous idea turns out to be a Recurrent Neural Network.\n\nThe representation $h_t$ is just the hidden state.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=.8\\textwidth]{./rnn.pdf}\n    \\caption{A RNN with Bayesian updated hidden states.}\n\\end{figure}\n\nThe purpose of the observation is to build a good $h_t$, \nso that if other modules want to use this representation,\nit is readily accessible.\n\nSo the job for the network module $N$ is to update $h_t$ properly using Bayesian Theorem.\n\nThis is different from the Bayesian Neural Networks (BNN).\nIn BNN, people tries to make the weights and biases to be r.v.'s.\n\nIn the Long Short Term Memory (LSTM) model, there is a cell state, which is similar to this $h$.\nMaybe replacing this gating and addition with a Bayesian update will give what I want.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=.8\\textwidth]{./LSTM3-C-line.png}\n    \\caption{Cell States are updated by Gating and Addition.}\n\\end{figure}\n\nLater,\nI realized it is related to the World Model  \\cite{ha_world_2018},\nwhere they use a variational autoencoder to get a latent $z$ (we call that $h$ earlier), and pass that into a RNN.\nHowever, the $h$ produced by the RNN in the World Model is not parameters of distributions, maybe I can improve this.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{./world_model.png}\n    \\caption{In the World Model, the $z$ is produced by VAE, so $z$ is the parameters of some distributions.}\n\\end{figure}\n\n\n\n\\subsection{Automated Model Search?}\n\nAnother thought for the course project is from the idea of automated architecture search.\nThe architectures are analogous to the generative models in Bayesian Inference.\nAnd people use Evolutionary Algorithms to search for better architectures rather than design it manually \\cite{real_regularized_2019}.\n\nSo a typically case could be, the EA produces a population of DAGs, \nand BI get all the parameters, and we have a set of final performances,\nand EA produces a new population of DAGs by mutating the best DAGs,\nand BI get all the parameters again, and we get another set of the performances.\n\nBut I am still not familiar with the whole Bayesian Inference process, so I'm not sure if the idea of automated design can be applied to Bayesian Inference.\n\n\\bibliographystyle{apalike}\n\\bibliography{b}\n\n\\end{document}\n", "meta": {"hexsha": "e1268f36b8e9de9331221a98d47095edb15e2a3e", "size": 17412, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment3/main.tex", "max_stars_repo_name": "liusida/ds2", "max_stars_repo_head_hexsha": "1a4c6b3e0590d987c1e66d83bda1fb3382bf034e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment3/main.tex", "max_issues_repo_name": "liusida/ds2", "max_issues_repo_head_hexsha": "1a4c6b3e0590d987c1e66d83bda1fb3382bf034e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment3/main.tex", "max_forks_repo_name": "liusida/ds2", "max_forks_repo_head_hexsha": "1a4c6b3e0590d987c1e66d83bda1fb3382bf034e", "max_forks_repo_licenses": ["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.3085106383, "max_line_length": 182, "alphanum_fraction": 0.6049850678, "num_tokens": 5496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6248371353350318}}
{"text": "\nThe scattering matrix, or S-matrix (also called the scattering function matrix, \\cite{tsang2000scattering}), embeds the scattering behavior of an object as a mapping between incident and scattered plane-waves. It transforms between the incident/scattered directions as well as incident/scattered polarizations. This chapter gives the basic definition of the S-matrix, its relation to radar cross sections, routines for the S-matrix of simple objects, and the derivation of an object S-matrix under the Born approximation. \n\n\\section{Definition}\n\nFrom \\cite{tsang2000scattering}, let an incident wave be a plane wave with wave vector $\\bb{k}_i$, the polarization of which is decomposed into two linearly independent vectors that are perpendicular to $\\hat{k}_i$, as\n\\begin{equation}\n\\bb{E}_i = \\left( E_{pi} \\hat{p}_i+  E_{qi}\\hat{q}_i\\right) e^{i\\bb{k}_i \\cdot \\br}\n\\end{equation}\n\n\\noindent where $\\bb{r}$ is the position vector, ${\\bb{k}}_i = k\\hat{{k}}_i$ and $\\hat{p}_i$, $\\hat{q}_i$ and $\\hat{{k}}_i$ form an orthonormal system.  The scattered field is then defined \n\\begin{equation}\n\\bb{E}_s = \\left( E_{ps}\\hat{p}_s +  E_{qs}\\hat{q}_s\\right) \\dfrac{ e^{i k r}}{r}\n\\end{equation}\n\n\\noindent where the scattered field polarization vectors $\\hat{p}_s$ and $\\hat{q}_s$ form a right-handed orthonormal system with the scattered field direction $\\hat{{k}}_s$. The scattered field components are linearly related to the incident components through the scattering matrix, or S-matrix, \n\\begin{equation}\n\\twobyone{E_{ps}(\\hat{k}_s)}{E_{qs}(\\hat{k}_s)} = \\twobytwo{S_{pp}(\\hat{k}_s,\\hat{k}_i)   }{S_{pq}(\\hat{k}_s,\\hat{k}_i) }{S_{qp}(\\hat{k}_s,\\hat{k}_i) }{S_{qq}(\\hat{k}_s,\\hat{k}_i) }   \\twobyone{E_{pi}(\\hat{k}_i)}{E_{qi}(\\hat{k}_i)} \n\\end{equation}\n \nThese definitions for the fields and S-matrix give them the following units: the incident field amplitudes $E_{pi}$ and $E_{qi}$ have units of electric field (V/m), the S-matrix elements have units of length (m), and the scattering field amplitudes $E_{ps}$ and $E_{qs}$ have units of (Vm/m = V) because the length dimension of the factor of $1/r$ needs to be included. This depends on convention, because some definitions of the S-matrix use $1/kr$ outside the S-matrix, which makes the S-matrix unitless. \n\nWe use the wave vector and polarization convention of \\cite{tsang2000scattering}. The polarizations are taken as $\\hat{p} = \\hat{v}$ and $\\hat{q} = \\hat{h}$ with wave vector directions\n\\ea{\\hat{k}_i &=&  \\sin\\theta_i \\cos\\phi_i \\hat{x}  + \\sin\\theta_i \\sin\\phi_i \\hat{y} + \\cos\\theta_i \\hat{z} \\label{khati} \\\\\n\\hat{v}_i &=& \\cos\\theta_i \\cos\\phi_i \\hat{x} + \\cos\\theta_i\\sin\\phi_i \\hat{y} - \\sin\\theta_i\\hat{z} \\\\\n\\hat{h}_i &=& -\\sin\\phi_i\\hat{x} + \\cos\\phi_i \\hat{y} \\\\\n\\hat{k}_s &=& \\sin\\theta_s \\cos\\phi_s \\hat{x}  + \\sin\\theta_s \\sin\\phi_s \\hat{y} + \\cos\\theta_s \\hat{z} \\label{ss1} \\\\\n\\hat{v}_s &=& \\cos\\theta_s \\cos\\phi_s \\hat{x} + \\cos\\theta_s\\sin\\phi_s \\hat{y} - \\sin\\theta_s\\hat{z} \\\\\n\\hat{h}_s &=& -\\sin\\phi_s\\hat{x} + \\cos\\phi_s \\hat{y} \\label{hhats}}\n\n\\noindent where $\\theta$, $\\phi$ are spherical directions of the propagation waves. Here, the wave vectors are treated as radial vectors, and $\\hat{v}$ and $\\hat{h}$ are equivalent to the $\\hat{\\theta}$ and $\\hat{\\phi}$ spherical unit vectors. The polarizations for $\\hat{z}$ propagating waves ($\\theta = 0$ or $\\theta = \\pi$) are well-defined by using $\\phi=0$ as a reference\n \\ea{\\hat{k}(0,0) &=&  \\hat{z} \\\\\n\\hat{v}(0,0) &=& \\hat{x} \\\\\n\\hat{h}(0,0) &=& \\hat{y} \\\\\n\\hat{k}(\\pi,0) &=&  -\\hat{z} \\\\\n\\hat{v}(\\pi,0) &=& -\\hat{x}  \\\\\n\\hat{h}(\\pi,0) &=& - \\hat{y} }\n\nThese special cases can be used as definitions of the $\\hat{\\theta}$ and $\\hat{\\phi}$ unit vectors at the poles.\n\n\\section{Radar Cross Sections from S-matrix}\n\nWe list different radar cross sections and their relations to the S-matrix. Most of these can be found in \\cite{tsang2000scattering}.\n\n\\paragraph{Radar Cross Section} The bistatic radar cross section is defined \n\\ea{\\sigma_{pq}(\\hat{k}_s,\\hat{k}_i) &=& \\lim_{r \\rightarrow \\infty} 4\\pi r^2 \\dfrac{\\left\\vert \\hat{p} \\cdot \\bb{E}_s \\right\\vert^2}{\\left\\vert \\hat{q} \\cdot \\bb{E}_i \\right\\vert^2} \\\\\n\\ &=& 4\\pi \\vert S_{pq} \\vert^2 \\label{rcsfromSpq} }\n\n\\noindent where $p$ and $q$ are any two orthogonal polarizations. The units of radar cross section are area or length-squared, showing again that $S_{pq}$ has units of length.\n\n\\paragraph{Scattering Cross Section} The total scattering cross section for incident direction $\\hat{k}_i$ and arbitrary incident polarization $\\hat{\\beta}$, such that $\\hat{\\beta} \\cdot \\hat{k}_i = 0$, is computed as the integral over scattered field directions $\\hat{k}_s$ as\n\\eq{\\sigma_{s\\beta}(\\hat{k}_i) = \\int \\left( \\vert S_{p\\beta}(\\hat{k}_s,\\hat{k}_i) \\vert^2 + \\vert S_{q\\beta}(\\hat{k}_s,\\hat{k}_i) \\vert^2 \\right) d\\Omega_s }\n\n\\noindent where\n\\eq{\n\\twobyone{S_{p\\beta}  }{S_{q\\beta}  } = \n\\twobytwo{S_{pp}}{S_{pq}}{S_{qp}}{S_{qq}} \\twobyone{\\hat{p}\\cdot \\hat{\\beta}}{\\hat{q}\\cdot \\hat{\\beta}} \\label{projectedsmatrix} \n}\n\n\\noindent and $\\beta$ is the angle of the incident polarization relative to the two orthogonal polarizations of the S-matrix, which is \n\\eq{\\hat{\\beta} = \\cos\\beta \\hat{p} + \\sin\\beta \\hat{q}}\n\n\\paragraph{Extinction Cross Section} The extinction cross section (or total cross section) for a given incident direction is given by the optical theorem, \\cite{zhang2019generalized}, as the imaginary part of the co-polarized scattered field in the forward direction\n\\eq{\\sigma_{ext,\\beta}(\\hat{k}_i) = \\dfrac{4\\pi}{k}\\textrm{Im}\\left[S_{\\beta\\beta}(\\hat{k}_i,\\hat{k}_i)\\right]}\n\n\\paragraph{Absorption Cross Section} The absorption cross section is defined as the power absorbed by the scattering object divided by the power scattered. It can be written in terms of the extinction and total cross sections as \n\\eq{\\sigma_a = \\sigma_{ext} - \\sigma_s}\n\nThis subtraction is sometimes numerically inaccurate and so the absorption cross section can also be defined directly in terms of the internal field, \\cite{yurkin2007discrete}.\n\n\\paragraph{Polarization and Orientation Averaged Scattering Cross Section}\n\nThe polarization and orientation averaged scattered cross section is given by the integral of the scattering cross section over all possible incident directions and polarizations including normalization:\n%\\eq{\\left< \\sigma \\right> = \\left<  \\sigma_{s\\beta}(\\hat{k}_i)  \\right>_{\\beta,\\hat{k}_i} = \\dfrac{1}{2\\pi} \\int_0^{2\\pi}\\left(  \\dfrac{1}{4\\pi} \\int \\sigma_{s\\beta}(\\hat{k}_i) d\\Omega_i \\right) d\\beta }\n\\eq{\\left< \\sigma \\right> =  \\dfrac{1}{2\\pi} \\int_0^{2\\pi}\\left(  \\dfrac{1}{4\\pi} \\int \\sigma_{s\\beta}(\\hat{k}_i) d\\Omega_i \\right) d\\beta \\label{polorientavescs} }\n\nThis requires projecting a given incident polarization $\\beta$ onto $\\hat{p}$ and $\\hat{q}$, computing the projected S-matrix elements \\eqref{projectedsmatrix}, computing the scattering cross section for all incident directions, then integrating over incident direction and incident angle $\\beta$. Computing this does not require one to explicitly rotate or recompute the S-matrix once it is known.\n\n\n\\paragraph{Scattering Efficiencies} The quantities above can be reinterpreted as efficiencies by dividing by the cross sectional area of the target.  For example, the scattering efficiency for a given incident direction is given by the scattering cross section divided by cross sectional area of the target, $A$,  \n\n\\eq{Q_{sca} = \\dfrac{\\sigma_{s}}{A} }\n\nThe same can be applied to extinction and absorption cross sections.  \n\n\\section{S-matrix Rotation}\n\nAn S-matrix will often be computed in a reference frame aligned naturally with the geometry of the object. If an object is rotated relative to a global frame, then the incident and scattered directions and polarization in the global frame will appear to rotate in the frame of the object. It can be efficient to transform the global wave vectors and polarizations such that the S-matrix is evaluated in the frame of the object, rather than try to obtain the S-matrix of the rotated object in the global frame. Both \\cite{tsang2000scattering} and \\cite{van2011synthetic} give equations and procedures for rotating an object with cylindrical symmetry. We give a general procedure next.\n\n%For the purposes of rotation, both the wave vectors and polarization vectors can be treated as Cartesian unit vectors with their tail at the origin. An extrinsic rotation is first applied to the incident and scattered directions to \n%\n%The polarization vectors are then decomposed into the local $\\hat{v}$ and $\\hat{h}$ polarizations of the object frame. Then the S-matrix is evaluated in its frame. In this procedure, there is no need to 'rotate back', because it is sufficient to have transformed both the incident and scattered quantities to the object frame.  \n\nLet an object rotation be described by ZXZ Euler angles $(\\alpha,\\beta,\\gamma)$ with corresponding rotation matrix $\\bb{R}$.  $\\bb{R}$ describes a forward rotation, i.e., a point rides with the rotated frame. The inverse rotation is $\\bb{R}^t$, where points are fixed in the global frame and we view them as though we ride with the rotating frame. The inverse rotation is first applied to the incident and scattered directions of the global frame so that they are viewed from the rotated object frame. Let these angles be $(\\theta_{os},\\phi_{os};\\theta_{oi},\\phi_{oi})$. The polarization vectors are then evaluated in the object frame at these points giving $(\\hat{v}_{os},\\hat{h}_{os};\\hat{v}_{oi},\\hat{h}_{oi})$. The object-frame polarization vectors now need to be viewed from the global frame. This is done by rotating the object-frame polarization vectors with an forward rotation, so that they appear as vectors in the global frame:\n\\eq{\\hat{v}_{o}' = \\bb{R}(\\hat{v}_o)}\n\nIn matrix notation, S-matrix of the rotated object, as viewed in the global frame, is given by \n\\ea{\n\\twobytwo{S_{vv}(\\theta_s,\\phi_s;\\theta_i,\\phi_i)}{S_{vh}(\\theta_s,\\phi_s;\\theta_i,\\phi_i)}{S_{hv}(\\theta_s,\\phi_s;\\theta_i,\\phi_i)}{S_{hh}(\\theta_s,\\phi_s;\\theta_i,\\phi_i)}\n&=&\n\\twobytwo{\\hat{v}_s \\cdot \\hat{v}_{os}' }{\\hat{v}_s \\cdot \\hat{h}_{os}'}{\\hat{h}_s \\cdot \\hat{v}_{os}'}{\\hat{h}_s \\cdot \\hat{h}_{os}'} \\cdot \\nonumber \\\\\n\\ & \\ & \n\\twobytwo{S_{vv}(\\theta_{os},\\phi_{os};\\theta_{oi},\\phi_{oi})}{S_{vh}(\\theta_{os},\\phi_{os};\\theta_{oi},\\phi_{oi})}{S_{hv}(\\theta_{os},\\phi_{os};\\theta_{oi},\\phi_{oi})}{S_{hh}(\\theta_{os},\\phi_{os};\\theta_{oi},\\phi_{oi})} \\cdot \\nonumber \\\\\n\\ & \\ & \n\\twobytwo{\\hat{v}_{oi}' \\cdot \\hat{v}_{i} }{\\hat{v}_{oi}' \\cdot \\hat{h}_{i} }{\\hat{h}_{oi}' \\cdot \\hat{v}_{i} }{\\hat{h}_{oi}' \\cdot \\hat{h}_{i} }\n} \n \nThe inner matrix is the object S-matrix evaluated in its native frame using points rotated from the global frame. The outer two matrices decompose and project the polarization vectors between the two frames. \n\n\n%\\subsection{Euler Rotation}\n\n%\\subsection{Cylindrical Symmetry}\n\n\\section{Object S-matrix}\n\n\\subsection{Thin Circular Cylinder}\n\nFrom \\cite{sarabandi1990low, stiles1996scattering} the far field scattering solution for a thin dielectric cylinder with cross sectional area much smaller than a wavelength and oriented along the $z$ axis is given by \n\\eq{\\bb{E}_s = -E_o\\dfrac{e^{ikr}}{4\\pi r} k^2 L A \\left[ \\hat{k}_s \\times \\hat{k}_s \\times (\\bb{P} \\cdot \\hat{e}_i ) \\right] \\sinc{(U)}}\n\\eq{U =  \\dfrac{kL}{2} \\left(\\cos\\theta_s - \\cos\\theta_i\\right) }\n\n\\noindent where $L$ is the length, $A$ is the cross sectional area, $\\hat{e}_i$ is the incident polarization, $k$ is the background wavenumber, $\\theta_i$ and $\\theta_s$ are the incident and scattered angles from the $z$ axis, and $\\bb{P}$ is the polarization tensor. Also, $\\textrm{sinc}(x) = \\sin(x)/x$. The polarization tensor for a homogenous dielectric cylinder with circular cross section is diagonal and given by \n\\ea{P_{xx} &=&  2 \\dfrac{\\epsilon_r - 1}{\\epsilon_r + 1} \\\\\nP_{yy} &=& 2 \\dfrac{\\epsilon_r - 1}{\\epsilon_r + 1}\\\\\nP_{zz} &=& \\epsilon_r - 1}\n\n\\noindent where $\\epsilon_r$ is the relative permittivity. For a cylinder with radius $a$, the $\\hat{v}$ and $\\hat{h}$ S-matrix elements are \n\\ea{\\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} &=& \\dfrac{k^2 L  a^2 }{4} \\sinc{(U)} \\bb{C} }\n\n%\\ea{\\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} &=& -\\dfrac{k^2 L  a^2 }{4} \\sinc{(U)} \\onebytwo{\\hat{v}_s}{\\hat{h}_s} \\cdot \\twobyone{ \\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{v}_i \\right)}{ \\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{h}_i \\right) } \\\\\n%\\ &=&  \\dfrac{k^2 L  a^2 }{4} \\sinc{(U)} \\bb{C} }\n\n\\eq{\\bb{C}  = \\twobytwo\n{(\\hat{v}_s)\\cdot(\\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{v}_i \\right))}\n{(\\hat{v}_s)\\cdot\\left(\\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{h}_i \\right) \\right)}\n{(\\hat{h}_s)\\cdot(\\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{v}_i \\right))}\n{(\\hat{h}_s)\\cdot\\left(\\hat{k}_s \\times \\hat{k}_s \\times \\left(\\bb{P} \\cdot \\hat{h}_i \\right) \\right)} \\label{matrixCforS}}\n\nUsing \\eqref{khati}-\\eqref{hhats} and simplifying the elements  of $\\bb{C}$ are\n\\ea{C_{vv} &=&  P_{zz}\\sin\\theta_s\\sin\\theta_i + P_{xx}\\cos\\theta_s\\cos\\phi_s\\cos\\theta_i\\cos\\phi_i + P_{yy}\\cos\\theta_s\\cos\\theta_i\\sin\\phi_s\\sin\\phi_i \\\\\nC_{vh} &=& \\cos\\theta_s(P_{yy}\\sin\\phi_s\\cos\\phi_i - P_{xx}\\cos\\phi_s\\sin\\phi_i ) \\\\\nC_{hv} &=& \\cos\\theta_i(P_{yy}\\cos\\phi_s\\sin\\phi_i - P_{xx}\\sin\\phi_s\\cos\\phi_i) \\\\\nC_{hh} &=&  P_{yy}\\cos\\phi_s\\cos\\phi_i + P_{xx}\\sin\\phi_s\\sin\\phi_i}\n\nApplying symmetry $P_{xx} = P_{yy}$ and taking $\\phi_i = 0$, these can be simplified to just\n\\ea{C_{vv} &=&  P_{zz}\\sin\\theta_s\\sin\\theta_i + P_{xx}\\cos\\theta_s\\cos\\phi_s\\cos\\theta_i \\\\\nC_{vh} &=& P_{xx} \\cos\\theta_s\\sin\\phi_s\\\\\nC_{hv} &=& -P_{xx} \\cos\\theta_i \\sin\\phi_s\\\\\nC_{hh} &=&  P_{xx}\\cos\\phi_s}\n\nThis solution is valid for edge-on incidence, and the $hh$ and $vv$ fields become equal, which we expect.  This solution is valid for $\\vert n \\vert ka \\ll 1$ and $a \\ll L$, where $n = \\sqrt{\\epsilon_r}$, \\cite{schiffer1979light}.\n\nThe routine \\texttt{smatrix\\char`_thin\\char`_circular\\char`_cylinder} returns the S-matrix of a thin circular cylinder. It takes the parameters of a single cylinder and computes the four block S-matrices for any number of incident and scattered directions. The block matrices have scattered directions in rows and incident directions in columns. The polarizations $\\hat{v}$ and $\\hat{h}$ are treated as spherical $\\hat{\\theta}$ and $\\hat{\\phi}$ in the forward scattering convention.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Smatrix/smatrix_thin_circular_cylinder.m}\n}\n\n\\clearpage\n\\newpage\n\n\\subsection{Thin Circular Disk}\n\nScattering from both needles and disks is derived in \\cite{schiffer1979light} and the results for needles match those in the previous section. The far field scattered field for a thin disk is\n\\ea{\\bb{E}_s &=& -E_o\\dfrac{e^{ikr}}{2\\pi r} k^2 L A \\left[ \\hat{k}_s \\times \\hat{k}_s \\times (\\bb{P} \\cdot \\hat{e}_i ) \\right] \\textrm{jinc}(U)\\\\\nU &=&  kL \\Omega  \\\\\n\\Omega^2 &=& (\\sin\\theta_i \\cos\\phi_i- \\sin\\theta_s\\cos\\phi_s)^2 + (\\sin\\theta_i \\sin\\phi_i- \\sin\\theta_s\\sin\\phi_s )^2  }\n\n\\noindent where $L$ is the disk thickness, $A$ is cross sectional area of the disk, and $\\textrm{jinc}(x) = J_1(x)/x$ where $J_1(x)$ is the Bessel function of degree 1. The polarization tensor of the circular disk is \n\\ea{P_{xx} &=& \\epsilon_r - 1 \\\\\nP_{yy} &=& \\epsilon_r - 1 \\\\\nP_{zz} &=& \\dfrac{\\epsilon_r - 1}{\\epsilon_r }}\n  \n%(In comparing \\cite{schiffer1979light} to \\cite{sarabandi1990low, stiles1996scattering}, the the factor of 2 between the cylinder and disk scattered field appears correct.)% For the disk, we take the small argument limit of the Bessel function (small radius) which kicks out a factor of 2, while for the cylinder, we take the small argument limit of the sinc (small length) which is equal to 1. The factors in the polarization tensor are otherwise the same (going from \\cite{schiffer1979light} to \\cite{sarabandi1990low, stiles1996scattering} the factor of $(\\epsilon_r-1)$ is brought into $\\bb{P}$ and we swap the $x$ and $z$ tensor components). \n  \nThen the S-matrix elements are \n\\eq{\\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} = \\dfrac{k^2 L  a^2 }{2} \\dfrac{J_1\\left(U\\right)}{ U}\\bb{C} }\n\n\\noindent where $\\bb{C}$ is given by \\eqref{matrixCforS}. In comparing \\cite{schiffer1979light} to \\cite{sarabandi1990low, stiles1996scattering}, the factor of 2 appears correct between the cylinder and disk scattered field. This solution is valid for $\\vert n \\vert kL \\ll 1$ and $L \\ll a$, where $n = \\sqrt{\\epsilon_r}$, \\cite{schiffer1979light}.\n\nThe routine \\texttt{smatrix\\char`_thin\\char`_circular\\char`_disk} returns the S-matrix of a thin circular disk. It takes the parameters of a single disk and computes the four block S-matrices for any number of incident and scattered directions. The block matrices have scattered directions in rows and incident directions in columns. The polarizations $\\hat{v}$ and $\\hat{h}$ are treated as spherical $\\hat{\\theta}$ and $\\hat{\\phi}$ in the forward scattering convention.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Smatrix/smatrix_thin_circular_disk.m}\n}\n\n\n\\section{S-matrix Under the Born Approximation}\n\\label{smatrixborn}\n\nThe far-field Born approximation is explained in Section \\ref{bornapprox}. Because the approximation is written in terms of plane waves, it can be cast as an S-matrix.  Recalling \\eqref{baesca}, using $\\overline{\\bb{I}}  - \\hat{r}\\hat{r} = \\hat{\\theta}_s\\hat{\\theta}_s + \\hat{\\phi}_s\\hat{\\phi}_s$, and equating the spherical unit vectors with $\\hat{v}$ and $\\hat{h}$, we obtain the S-matrix \n\\eq{\\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} = \\dfrac{1}{4\\pi}  \\twobytwo{\\hat{v}_{s} \\cdot \\hat{v}_{i} }{\\hat{v}_{s}  \\cdot \\hat{h}_{i} }{\\hat{h}_{s} \\cdot \\hat{v}_{i} }{\\hat{h}_{s} \\cdot \\hat{h}_{i}  }  \\int O(\\br) e^{i (\\bb{k}_i-\\bb{k}_s) \\cdot \\br}  dV \\label{eqbasmat1} }\n\n%\\eq{\\bb{E}_{sca}(\\br)=  \\dfrac{e^{ikr}}{4\\pi r} \\left[ \\hat{\\theta}_s\\hat{\\theta}_s + \\hat{\\phi}_s\\hat{\\phi}_s \\right] \\cdot  \\bb{E}_i  \\int O(\\br') \\exp(i (\\bb{k}_i-\\bb{k}_s) \\cdot \\br')  dV'  }\n\n\\noindent where the object function is given by \\eqref{objectfunction} and the wave vectors and polarizations are given by \\eqref{khati}-\\eqref{hhats}. This shows again that under the Born approximation, the object does not influence the polarization. The depolarization is merely the projection between incident and scattered polarizations. \n\nWhen the object is homogenous \\eqref{eqbasmat1} becomes \n\\eq{\\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} = \\dfrac{1 }{4\\pi}\\twobytwo{\\hat{v}_{s} \\cdot \\hat{v}_{i} }{\\hat{v}_{s}  \\cdot \\hat{h}_{i} }{\\hat{h}_{s} \\cdot \\hat{v}_{i} }{\\hat{h}_{s} \\cdot \\hat{h}_{i}  } k^2(\\epsilon_r - 1) I(\\theta_{s},\\phi_{s};\\theta_{i},\\phi_{i})   }\n\\eq{I(\\theta_{s},\\phi_{s};\\theta_{i},\\phi_{i})   =  \\int e^{i (\\bb{k}_i-\\bb{k}_s) \\cdot \\br}  dV \\label{volphaseint}}\n\n\\noindent where $k$ is the wavenumber of the background medium which is also used for the wave vectors, $\\epsilon_r$ is complex relative permittivity of the object, and $I$ is the volume phase integral. The volume phase integral is the 3D Fourier transform over the domain of the object. \n\n\\clearpage\n\n\\section{Volume Phase Integral}\n\\label{sec:volumephaseint}\nThe volume phase integral occurs in the S-matrix formulation of the  Born approximation for homogeneous dielectric objects, Section \\ref{smatrixborn}.  The volume phase integral for several simple objects is derived below and summarized in Table \\ref{tablevolphaseint}. These are just the 3D Fourier transform over the object domain. The volume phase integral can be expressed as a product of the object volume and a function that has maximum value of one that depends on the incident/scattered directions. To facilitate derivations, \\eqref{volphaseint} is written in terms of the wave vector difference, $\\bb{K}$, as \n\\eq{I(\\theta_{s},\\phi_{s};\\theta_{i},\\phi_{i})   =  \\int e^{i \\bb{K} \\cdot \\br}  dV \\label{volphaseint2}}\n\\noindent where\n\\ea{\\bb{K} &=& \\bb{k}_i-\\bb{k}_s \\label{Kvector}  = k(\\hat{k}_i-\\hat{k}_s) \\\\\n \\hat{k}_i &=& \\sin\\theta_i \\cos\\phi_i \\hat{x}  + \\sin\\theta_i \\sin\\phi_i \\hat{y} + \\cos\\theta_i \\hat{z} \\\\\n\\hat{k}_r &=& \\sin\\theta_r \\cos\\phi_r \\hat{x}  + \\sin\\theta_r \\sin\\phi_r \\hat{y} + \\cos\\theta_r \\hat{z} \\\\\n\\bb{r}  &=& x \\hat{x} + y \\hat{y} + z \\hat{z} }\n\\vspace{-7mm}\n\n\n\\begin{table}[H]\n\\caption{Table of Volume Phase Integrals}\n\\vspace{-6mm}\n\\begin{center}\n\\begin{tabular}{|p{1.4cm}|p{3cm}|c|c|p{2.7cm}|}\n\\hhline{|=====|} \n%\\multicolumn{5}{|c|}{ \\ } \\\\\n\\multicolumn{5}{|c|}{ $\\displaystyle I(\\theta_{s},\\phi_{s};\\theta_{i},\\phi_{i})  =  \\int e^{i \\bb{K} \\cdot \\br}  dV = V f(\\cdot) $} \\\\\n\\multicolumn{5}{|c|}{$\\displaystyle \\bb{K} = \\bb{k}_i-\\bb{k}_s$} \\\\\n%\\multicolumn{5}{|c|}{ \\ } \\\\\n\\hhline{|=====|}\nObject & Geometry & $V$ & $f(\\cdot)$ & Notes \\\\\n\\hline\n\nCuboid & \\parbox[c]{1em}{\\includegraphics[width=1.3in]{Smatrix/Figures/Cuboid}}  & $L_xL_yL_z$ & $ \\textrm{sinc}\\left(\\dfrac{L_x K_x}{2}\\right)\\textrm{sinc}\\left(\\dfrac{L_y K_y}{2}\\right) \\textrm{sinc}\\left(\\dfrac{L_z K_z}{2}\\right)$  & $\\textrm{sinc}(x) = \\dfrac{\\sin(x)}{x}$ \\\\   \\hline\n\nCircular Cylinder & \\quad \\parbox[c]{1em}{\\includegraphics[width=0.9in]{Smatrix/Figures/Cylinder}}  & $\\pi a^2 L_z$ & $ 2 \\dfrac{ J_1(K_{\\rho} a)}{ K_{\\rho} a}  \\textrm{sinc}\\left(\\dfrac{L_z K_z}{2}\\right)$  & $K_{\\rho} = \\sqrt{K_x^2 + K_y^2} $ \\\\   \\hline\n\nSphere & \\parbox[c]{1em}{\\includegraphics[width=1.2in]{Smatrix/Figures/Sphere}}  & $\\dfrac{4}{3}\\pi a^3$ & $ \\dfrac{3(\\sin(K a) - K a \\cos(K a))}{(Ka)^3} $  & $K = \\vert \\bb{K} \\vert $ \\\\   \\hline\n\nEllipsoid & \\parbox[c]{1em}{\\includegraphics[width=1.3in]{Smatrix/Figures/Ellipsoid}}  & $\\dfrac{4}{3}\\pi abc$ & $ \\dfrac{3(\\sin(K') - K' \\cos(K'))}{K'^3}   $  & $\\begin{array}{c} K' = \\vert \\bb{K'} \\vert \\\\ (K_x',K_y',K_z') = \\\\ (a K_x, b K_y, c K_z)\\end{array}$ \\\\   \\hline\n\\end{tabular}\n\\end{center}\n\\label{tablevolphaseint}\n\\end{table}%\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Cuboid}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nLet a cuboid volume be centered at the origin with side lengths $L_x$, $L_y$, $L_z$ and let it be aligned with the Cartesian axes. In Cartesian coordinates, the volume phase integral, \\eqref{volphaseint2}, becomes\n\\ea{\nI &=& \\int_{-L_x/2}^{L_x/2}  \\int_{-L_y/2}^{L_y/2}  \\int_{-L_z/2}^{L_z/2}  e^{i(K_x x + K_y y + K_z z)} dx dy dz }\n%\\ &=& \\int_{-L_x/2}^{L_x/2} e^{i K_x x} dx  \\int_{-L_y/2}^{L_y/2} e^{i K_y y} dy  \\int_{-L_z/2}^{L_z/2}  e^{i K_z z} dz \\\\\n\nThe integral separates, then using the fact that \n\\eq{\\int_{-a/2}^{a/2} e^{i b z} dz = \\dfrac{2}{b} \\sin\\left(\\dfrac{ab}{2}\\right) \\label{sincinz}}\n\n\\noindent and multiplying top and bottom by $L_xL_yL_z$ to convert the sines to sinc functions the volume phase intergral over a cuboid is \n%\\ea{I &=& \\dfrac{4}{K_x K_y} \\sin\\left(\\dfrac{L_x K_x}{2}\\right)\\sin\\left(\\dfrac{L_y K_y}{2}\\right) \\\\\n%\\ & = & L_x L_y \\textrm{sinc}\\left(\\dfrac{L_x K_x}{2}\\right)\\textrm{sinc}\\left(\\dfrac{L_y K_y}{2}\\right) }\n\n\\eq{I  = L_x L_y L_z \\textrm{sinc}\\left(\\dfrac{L_x K_x}{2}\\right)\\textrm{sinc}\\left(\\dfrac{L_y K_y}{2}\\right) \\textrm{sinc}\\left(\\dfrac{L_z K_z}{2}\\right)}\n\n\\noindent where $\\textrm{sinc} = \\sin(x)/x$. This is equal to the volume of the cuboid times a product of directionally dependent $\\textrm{sinc}$ functions.\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Circular Cylinder}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nLet a circular cylinder be centered at the origin and aligned with the $z$ axis with radius $a$ and length $L_z$. The volume phase integral, \\eqref{volphaseint2}, in cylindrical coordinates is written \n\\ea{I  &=&  \\int_{-L_z/2}^{L_z/2}  \\int_0^{2\\pi} \\int_0^{a} e^{i (K_x \\rho \\cos\\phi + K_y \\rho \\sin\\phi + K_z z)} \\rho d\\rho d\\phi dz }\n\n\\noindent where we have used the position vector $\\br = \\rho \\cos\\phi \\hat{x} + \\rho \\sin\\phi \\hat{y} + \\hat{z}$. The integral separates as \n\\ea{I  &=& \\int_0^{2\\pi} \\int_0^{a} e^{i (K_x \\rho \\cos\\phi + K_y \\rho \\sin\\phi)} \\rho d\\rho d\\phi   \\int_{-L_z/2}^{L_z/2} e^{i K_z z} dz }\n\nThe last integral is a sinc function in $z$ given by \\eqref{sincinz}. Using the identity \n\\eq{\\int_0^{2\\pi} e^{ u \\cos t +v \\sin t} d t = 2 \\pi I_0 \\left( \\sqrt{u^2 + v^2} \\right)}\n\n\\noindent the integral over $\\phi$ evaluates to \n\\eq{\\int_0^{2\\pi}  e^{i K_x \\rho \\cos\\phi + K_y \\rho \\sin\\phi} d\\phi = 2\\pi I_0 \\left( i K_{\\rho}  \\rho \\right)}\n\n\\noindent where $K_{\\rho} = \\sqrt{K_x^2 + K_y^2}$. The quantity $K_{\\rho}$ is the component of the wave vector difference in the X-Y plane. Last, the integral in $\\rho$ is evaluated using\n\\eq{\\int_0^a I_0(i c x) x dx = \\dfrac{a J_1(a c)}{c}}\n\nPutting these together, the volume phase integral over a circular cylinder is\n\\ea{I  &=&   2\\pi \\dfrac{a J_1(K_{\\rho} a)}{ K_{\\rho} }  L_z \\textrm{sinc}\\left(\\dfrac{L_z K_z}{2}\\right)  }\n\nUsing the volume of the cylinder, $V = \\pi a^2 L_z$, this can be written \n\\ea{I  &=&  V   2 \\dfrac{ J_1(K_{\\rho} a)}{ K_{\\rho} a}  \\textrm{sinc}\\left(\\dfrac{L_z K_z}{2}\\right)  }\n\nSimilar to the other shapes, this is equal to the volume of the cylinder multiplied by a directionally dependent term that has maximum value of 1.  \n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Sphere}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\\label{sectionvolintsphere}\nLet a spherical volume with radius $a$ be centered at the origin. The volume phase integral, \\eqref{volphaseint2}, can be written in spherical coordinates as \n\\vspace{-2mm}\n\\eq{ I  =  \\int_0^{2\\pi} \\int_0^{\\pi} \\int_0^a e^{i \\bb{K} \\cdot \\br}  r^2 \\sin\\theta dr d\\theta d\\phi }\n\nFrom symmetry, the dot product is evaluated relative to a common fixed axis such that $\\bb{K} \\cdot \\br = K r \\cos t$  where $t$ is the angle between $\\bb{K}$ and $\\br$. Using this, the integral becomes\n\\eq{ I  =  \\int_0^{2\\pi} \\int_0^{\\pi} \\int_0^a e^{i K r \\cos t}  r^2 \\sin t dr dt d\\phi \\label{eqtemp21}}\n\\vspace{-2mm}\n\nNext we use the identity \n\\eq{j_n(z) = \\dfrac{(-i)^n}{2} \\int_0^{\\pi} e^{i z \\cos u} P_n(\\cos u) \\sin u du}\n\n\\noindent where $j_n(z)$ is the spherical Bessel function and $P_n(\\cos u)$ is the Legendre polynomial. Applying this and integrating in $\\phi$ \\eqref{eqtemp21} becomes\n\\eq{ I  =  4\\pi   \\int_0^a j_0(K r) r^2 dr   \\label{eqtmp22}}\n\nNote that $j_0(x) = \\sin(x)/x $.  This integral is given generally as\n\\eq{\\int_0^a j_0 (c x) x^2 dx = \\dfrac{\\sin(a c) - a c \\cos(a c)}{c^3}}\n\nThe volume phase integral over a sphere is given by\n\\eq{ I  =  4\\pi \\dfrac{\\sin(K a) - K a \\cos(K a)}{K^3}  \\label{volphasphere1}   }\n\n\\noindent where $K$ is the magnitude of \\eqref{Kvector}.  Using the volume of the sphere, $V = 4/3 \\pi a^3$, this can be written\n\\ea{ I  &=&  V \\dfrac{3(\\sin(K a) - K a \\cos(K a))}{(Ka)^3}}\n\n%\n%\n%The volume phase integral over a sphere is given by\n%\\eq{ I  =  4\\pi \\dfrac{\\sin(K a) - K a \\cos(K a)}{K^3}  \\label{volphasphere1}   }\n%\n%\\noindent where $K$ is the magnitude of \\eqref{Kvector}.  This can be written in terms of the volume of the sphere $V = 4/3 \\pi a^3$ as \n%\\ea{ I  &=&  V \\dfrac{3(\\sin(K a) - K a \\cos(K a))}{(Ka)^3}}\n\nThe multiplying function acts like a directionally dependent weighting function that has a maximum value of 1 when $K a \\rightarrow 0$.  \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Ellipsoid}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nLet an ellipsoid be centered on the origin with axes $(a, b, c)$ along XYZ, respectively. We define a new position vector, $\\br'$, in spherical coordinates using the change of variables \n\\ea{\\br' &=& r a \\sin\\theta\\cos\\phi \\hat{x} + r b \\sin\\theta\\sin\\phi \\hat{y} +  r c\\cos\\theta \\hat{z} \\\\\ndV &=& abc r^2 \\sin\\theta dr d\\theta d\\phi}\n\nThe volume phase integral, \\eqref{volphaseint2}, can then be written as an integral over the unit sphere\n\\eq{ I  =  abc \\int_0^{2\\pi} \\int_0^{\\pi} \\int_0^1 e^{i \\bb{K} \\cdot \\br'}  r^2 \\sin\\theta dr d\\theta d\\phi }\n\nNext, transfer the coefficients $(a,b,c)$ that are in $\\br'$ to a new wave vector difference, $\\bb{K}'$, so that, $(K_x',K_y',K_z') = (a K_x, b K_y, c K_z)$. The position vector returns to its unstretched form and we have\n\\eq{ I  =  abc \\int_0^{2\\pi} \\int_0^{\\pi} \\int_0^1 e^{i \\bb{K}' \\cdot \\br}  r^2 \\sin\\theta dr d\\theta d\\phi }\n\nUsing the results of Section \\ref{sectionvolintsphere}, \\eqref{volphasphere1}, the volume phase integral over an ellipsoid is \n\\eq{ I  =  4\\pi abc \\dfrac{\\sin(K') - K' \\cos(K')}{K'^3}     }\n\n\\noindent where $K'$ is the magnitude of $\\bb{K}'$.  The volume of an ellipsoid is $V = 4/3\\pi abc$, and this can be written\n\\eq{ I  =  V \\dfrac{3(\\sin(K') - K' \\cos(K'))}{K'^3}     }\n\n\\clearpage\n\n\n\n\\clearpage\n\\newpage\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "ae6a7753bad0141a2504e3f47b884e4180a6fcef", "size": 28620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Smatrix/Smatrix.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/Smatrix/Smatrix.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/Smatrix/Smatrix.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": 77.5609756098, "max_line_length": 938, "alphanum_fraction": 0.6908805031, "num_tokens": 9932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6248371258220999}}
{"text": "\\section{Non-parametric DF Estimation}\\label{S:NonparamDFEstimation}\nSo far, we have been interested in some estimation problems involved in parametric experiments.  In parametric experiments, the parameter space $\\BB{\\Theta}$ can have many dimensions, but these are finite.  For example, in the $n$ IID $\\bernoulli(\\theta^*)$ and the $n$ IID $\\exponential(\\lambda^*)$ experiments:\n\\begin{eqnarray*}\nX_1,\\ldots,X_n \\overset{IID}{\\sim} \\bernoulli(\\theta^*), & \\qquad & \\theta^* \\in \\BB{\\Theta}=[0,1] \\subset \\Rz^1 \\enspace , \\\\\nX_1,\\ldots,X_n \\overset{IID}{\\sim} \\exponential(\\lambda^*), & \\qquad & \\lambda^* \\in \\BB{\\Lambda}=(0,\\infty) \\subset \\Rz^1 \\enspace ,\n\\end{eqnarray*}\nthe parameter spaces $\\BB{\\Theta}$ and $\\BB{\\Lambda}$ are of dimension $1$.  Similarly, in the $n$ IID $\\normal(\\mu,{\\sigma}^2)$ and the $n$ IID $\\lognormal(\\lambda,\\zeta)$, experiments:\n\\begin{eqnarray*}\nX_1,\\ldots,X_n \\overset{IID}{\\sim} \\normal(\\mu,\\sigma^2), &\\qquad & (\\mu,\\sigma^2) \\in \\BB{\\Theta}=(-\\infty,+\\infty) \\times (0,+\\infty) \\subset \\Rz^2 \\\\\nX_1,\\ldots,X_n \\overset{IID}{\\sim} \\lognormal(\\lambda,\\zeta), &\\qquad & (\\lambda,\\zeta) \\in \\BB{\\Theta}=(0,+\\infty) \\times (0,+\\infty) \\subset \\Rz^2 \n\\end{eqnarray*}\nthe parameter space is of dimension $2$.\n\nAn experiment with an infinite dimensional parameter space $\\BB{\\Theta}$ is said to be {\\bf non-parametric} .  Next we consider a non-parametric experiment in which $n$ IID samples are drawn according to some fixed and possibly unknown DF $F^*$ from the space of {\\bf All Distribution Functions}:\n\\[\n\\boxed{\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} F^*, \\qquad F^* \\in \\BB{\\Theta} = \\{ \\text{All DFs}\\} := \\{ \\,  F(x; F) :  F~is~a~DF \\, \\} \n}\n\\]\nwhere the DF $F(x; F)$ is indexed or parameterised by itself. Thus, the parameter space $\\BB{\\Theta}=\\{ \\text{All DFs}\\}$ is the {\\bf infinite dimensional} space of {\\bf All DFs}.  In this section, we look at estimation problems in non-parametric experiments with an infinite dimensional parameter space.  That is, we want to estimate the DF $F^*$ from which our IID data are drawn.\n\nThe next proposition is often referred to as the {\\bf fundamental theorem of statistics} and is at the heart of non-parametric inference, empirical processes, and computationally intensive bootstrap techniques.  Recall  \\hyperref[D:ECDF]{Definition~\\ref*{D:ECDF}} of the $n$-sample empirical distribution function (EDF or ECDF) $\\widehat{F}_n$ that assigns a probability mass of $1/n$ at each data point $x_i$:\n\\begin{eqnarray*} %\\label{E:ECDF}\n\\widehat{F}_n(x) = \\frac{ \\sum_{i=1}^n \\BB{1}(X_i \\leq x) }{n} \\ ,  & \\quad where \\qquad\n\\BB{1}(X_i \\leq x) :=\n\\begin{cases}\n& 1  \\quad \\text{if $x_i \\leq x$} \\\\\n& 0  \\quad \\text{if $x_i > x$} \n\\end{cases}\n\\end{eqnarray*}\n\n\\begin{figure}[htpb]\n\\caption{Plots of ten distinct ECDFs $\\widehat{F}_n$ based on $10$ sets of $n$ IID samples from $\\uniform(0,1)$ RV $X$, as $n$ increases from $10$ to $100$ to $1000$.  The DF $F(x)=x$ over $[0,1]$ is shown in red.  The script of \\hyperref[Mf:GilvenkoCantelliUnif01n10n100n100ECDFs]{Labwork \\ref*{Mf:GilvenkoCantelliUnif01n10n100n100ECDFs}} was used to generate this plot.   \\label{F:GilvenkoCantelliUnif01n10n100n100ECDFs}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/GilvenkoCantelliUnif01n10n100n100ECDFs}}\n\\end{figure}\n\\begin{prop}[Gilvenko-Cantelli Theorem]\\label{P:Gilvenko-Cantelli}\nLet $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F^*$.  Then:\n\\[\n\\sup_x { | \\widehat{F}_n(x) - F^*(x) | } \\overset{P}{\\longrightarrow} 0 \\ .\n\\]\n%{\\scriptsize\n%\\begin{proof}\n%Proof to be seen in STAT 318 or another advanced Statistics course.\n%\\end{proof}\n%}\n\\end{prop}\n{\\bf Heuristic Interpretation of the Gilvenko-Cantelli Theorem}:  As the sample size $n$ increases, the empirical distribution function $\\widehat{F}_n$ converges to the true DF $F^*$ in probability, as shown in \\hyperref[F:GilvenkoCantelliUnif01n10n100n100ECDFs]{Figure~\\ref*{F:GilvenkoCantelliUnif01n10n100n100ECDFs}}.\n\n\\begin{prop}[The Dvoretzky-Kiefer-Wolfowitz (DKW) Inequality]\nLet $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F^*$.  Then, for any $\\epsilon>0$:\n\\begin{equation}\\label{E:DKWNeq}\nP \\left( \\sup_x | \\widehat{F}_n(x) - F^*(x) | > \\epsilon  \\right) \\leq 2 \\exp {(-2 n \\epsilon^2)}\n\\end{equation}\nRecall that $\\sup(A)$ or supremum of a set $A \\subset \\Rz$ is the least upper bound of every element in $A$.\n\\end{prop}\n\n\\subsection{Estimating DF}\\label{S:EstimDF}\nLet $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F^*$, where $F^*$ is some particular DF in the space of all possible DFs, i.e.~the experiment is non-parametric.  Then, based on the data sequence $X_1,X_2,\\ldots,X_n$ we want to estimate $F^*$.\n\nFor any fixed value of $x$, the expectation and variance of the empirical DF \\eqref{E:ECDF} are:\n\\begin{eqnarray}\n\\E \\left( \\widehat{F}_n(x) \\right) &=& F^*(x) \\implies \\mathsf{bias}_n \\left( \\widehat{F}_n(x) \\right) = 0 \\label{E:FnhatUnbiased} \\\\\n\\V \\left( \\widehat{F}_n(x) \\right) &=& \\frac{F^*(x) (1-F^*(x))}{n} \\implies \\lim_{n \\to \\infty}\\mathsf{se}_n \\left( \\widehat{F}_n(x) \\right) = 0  \\label{E:Fnhatseto0} \n\\end{eqnarray}\nTherefore, by \\hyperref[P:AsympConsistencyUnbiasedSE0]{Proposition~\\ref* {P:AsympConsistencyUnbiasedSE0}}, the empirical DF evaluated at $x$, i.e.~$\\widehat{F}_n(x)$ is an asymptotically consistent estimator of the DF evaluated at $x$, i.e.~$F^*(x)$.  More formally,\n\\eqref{E:FnhatUnbiased} and \\eqref{E:Fnhatseto0}, by \\hyperref[P:AsympConsistencyUnbiasedSE0]{Proposition~\\ref* {P:AsympConsistencyUnbiasedSE0}}, imply that for any fixed value of $x$:\n\\[\n\\widehat{F}_n(x) \\overset{P}{\\longrightarrow} F^*(x) \\ .\n\\]\nWe are interested in a point estimate of the entire DF $F^*$, i.e.~$F^*(x)$ over all $x$.  A point estimator $T_n=T_n(X_1,X_2,\\ldots,X_n)$ of a fixed and possibly unknown $F \\in \\{ \\text{All DFs} \\}$ is the empirical DF $\\widehat{F}_n$.  This estimator has an asymptotically desirable property: \n\\[\n\\sup_x { | \\widehat{F}_n(x) - F^*(x) | } \\overset{P}{\\longrightarrow} 0 \n\\]\nbecause of the Gilvenko-Cantelli theorem in Proposition~\\ref*{P:Gilvenko-Cantelli}.  Thus, we can simply use $\\widehat{F}_n$, based on the realized data $(x_1,x_2,\\ldots,x_n)$, as a point estimate of $F^*$.\n\nOn the basis of the DKW inequality \\eqref{E:DKWNeq}, we can obtain a $1-\\alpha$ confidence set or {\\bf confidence band} $C_n(x) := [\\underline{C}_{\\, n}(x), \\overline{C}_{\\, n}(x)]$ about our point estimate of $F^*$: \n\\begin{eqnarray}\n\\underline{C}_{\\, n}(x) &=& \\max \\{ \\widehat{F}_n(x)-\\epsilon_n, 0 \\}, \\notag \\\\\n\\overline{C}_{\\, n}(x)  &=& \\min \\{ \\widehat{F}_n(x)+\\epsilon_n, 1 \\}, \\notag \\\\\n\\epsilon_n &=& \\sqrt{ \\frac{1}{2n} \\log \\left( \\frac{2}{\\alpha}\\right)} \\ .\n\\end{eqnarray}\nIt follows from \\eqref{E:DKWNeq} that for any fixed and possibly unknown $F^*$:\n\\[\nP \\left( \\underline{C}_{\\, n}(x) \\leq F^*(x) \\leq \\overline{C}_{\\, n}(x) \\right) \\geq 1-\\alpha \\ .\n\\]\nLet us look at a simple example next.\n\\begin{labwork}[Estimating the DF of $\\uniform(0,1)$ RV]\nConsider the problem of estimating the DF of $\\uniform(0,1)$ RV $U$ on the basis of $n_=10$ samples.  We use the function {\\tt ECDF} of Labwork~\\ref*{Mf:ECDF} and {\\sc Matlab}'s built-in function {\\tt stairs} to render the plots.  Figure~\\ref*{F:UniformECDFsBands} was generated by {\\tt PlotUniformECDFsConfBands.m} given below.\n{\\VrbMf[label=PlotUniformECDFsConfBands.m]{scripts/PlotUniformECDFsConfBands.m}}\n\\begin{figure}[htpb]\n\\caption{The empirical DFs $\\widehat{F}^{(1)}_{n}$ from sample size $n=10, 100, 1000$ (black), is the point estimate of the fixed and known DF $F(x)=x, x \\in[0,1]$ of $\\uniform(0,1)$ RV (red).  The $95\\%$ confidence band for each $\\widehat{F}_n$ are depicted by green lines.  \\label{F:UniformECDFsBands}}\n\\centering   \\makebox{\\includegraphics [width=5.5in]{figures/UniformECDFsBands}}\n\\end{figure}\n\\end{labwork}\nNext we look at a more interesting example involving real-world data.\n\\begin{labwork}[Non-parametric Estimation of the DF of Times Between Earth Quakes]\\label{LW:NZSIEQTimesECDFsConfBands}\nSuppose that the $6,128$ observed times between Earth quakes in  NZ between 18-Jan-2008 02:23:44 and 18-Aug-2008 19:29:29 are:\n$$X_1,\\ldots,X_{6128} \\overset{IID}{\\sim} F^*, \\qquad F^* \\in \\{ \\text{all DFs} \\} \\enspace .$$\nThen the non-parametric point estimate of the unknown $F^*$ is $\\widehat{F}_{6128}$, the ECDF of the inter earth quake times.  We plot the non-parametric point estimate as well as the 95\\% confidence bands for $F^*$ in  \\hyperref[F:NZSIEQTimesECDFsConfBands]{Figure~\\ref*{F:NZSIEQTimesECDFsConfBands}}.\n\\begin{figure}[htpb]\n\\caption{The empirical DF $\\widehat{F}_{6128}$ for the inter earth quake times and the $95\\%$ confidence bands for the non-parametric experiment.  \\label{F:NZSIEQTimesECDFsConfBands}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/NZSIEQTimesECDFsConfBands}}\n\\end{figure}\n\\VrbMf[label=NZSIEQTimesECDFsConfBands.m]{scripts/NZSIEQTimesECDFsConfBands.m}\n\\end{labwork}\n\nRecall the poor fit of the Exponential PDF at the MLE for the Orbiter waiting time data.  We can attribute the poor fit to coarse resolution of the waiting time measurements in minutes and the rigid decaying form of the exponential PDFs.  Let us revisit the Orbiter waiting time problem with our non-parametric estimator.  \n\n\\begin{labwork}[Non-parametric Estimation of Orbiter Waiting Times DF]\\label{LW:OrbiterECDFsConfBands}\nSuppose that the waiting times at the Orbiter bus stop are:\n$$X_1,\\ldots,X_{132} \\overset{IID}{\\sim} F^*, \\qquad F^* \\in \\{ \\text{all DFs} \\} \\enspace .$$\nThen the non-parametric point estimate of $F^*$ is $\\widehat{F}_{132}$, the ECDF of the $132$ Orbiter waiting times.\n\\begin{figure}[htpb]\n\\caption{The empirical DF $\\widehat{F}_{132}$ for the Orbiter waiting times and the $95\\%$ confidence bands for the non-parametric experiment.  \\label{F:OrbiterECDFsConfBands}}\n\\centering   \\makebox{\\includegraphics[width=5.5in]{figures/OrbiterECDFsConfBands}}\n\\end{figure}\nWe compute and plot the non-parametric point estimate as well as the 95\\% confidence bands for the unknown DF $F^*$ beside the parametric estimate and $95\\%$ confidence bands from \\hyperref[LW:ExponentialMLECIOrbiter]{Labwork~\\ref*{LW:ExponentialMLECIOrbiter}}.  Clearly, the non-parametric estimate is preferable to the parametric one for this example.  Notice how the non-parametric confidence bands do not contain the parametric estimate of the DF. \n\\VrbMf[label=OrbiterECDFsConfBands.m]{scripts/OrbiterECDFsConfBands.m}\n\\end{labwork}\n\n\n\\begin{example}\nFirst take a look at \\hyperref[DA:WebLogs]{Data~\\ref*{DA:WebLogs}} to understand how the web login times to our Maths \\& Stats Department's web server (or requests to our WWW server) were generated. \\hyperref[F:WebLogTimesECDFs]{Figure~\\ref*{F:WebLogTimesECDFs}} shows the login times in units of seconds over a 24 hour period starting at 0357 hours and 30 seconds (just before 4:00AM) on October 1st, 2007 (red line) and on October 2nd, 2007 (magenta). \n\\begin{figure}[htpb]\n\\caption{The empirical DFs $\\widehat{F}^{(1)}_{n_1}$ with $n_1= 56485$, for the web log times starting October 1, and $\\widehat{F}^{(2)}_{n_2}$ with $n_2=53966 $, for the web log times starting October 2.  Their $95\\%$ confidence bands are indicated by the green.  \\label{F:WebLogTimesECDFs}}\n\\centering   \\makebox{\\includegraphics [width=4.5in]{figures/WebLogTimesECDFsBands}}\n%WebLogTimesECDFs.eps}}\n\\end{figure}\nIf we assume that some fixed and unknown DF $F^{(1)}$ specifies the distribution of login times for October 1st data and another DF $F^{(2)}$ for October 2nd data, then the non-parametric point estimates of  $F^{(1)}$ and $F^{(2)}$ are simply the empirical DFs $\\widehat{F}^{(1)}_{n_1}$ with $n_1= 56485$ and $\\widehat{F}^{(2)}_{n_2}$ with $n_2=53966 $, respectively, as depicted in  \\hyperref[F:WebLogTimesECDFs]{Figure~\\ref*{F:WebLogTimesECDFs}}.  See the script of {\\tt WebLogDataProc.m} in \\hyperref[DA:WebLogs]{Data~\\ref*{DA:WebLogs}} to appreciate how the ECDF plots in \\hyperref[F:WebLogTimesECDFs]{Figure~\\ref*{F:WebLogTimesECDFs}} were made.\n\\end{example}\n\n\\section{Plug-in Estimators of Statistical Functionals}\\label{S:PlugIn}\nRecall from \\hyperref[S:Statistics]{Chapter~\\ref*{S:Statistics}} that a {\\bf statistical functional} is simply any function of the DF $F$.  For example, the median $T(F) = F^{[-1]}(1/2)$ is a statistical functional.  Thus, $T(F): \\{ \\text{All DFs }\\} \\to \\Tz$, being a map or function from the space of DFs to its range $\\Tz$, is a functional. \nThe idea behind the plug-in estimator for a statistical functional is simple: just plug-in the point estimate $\\widehat{F}_n$ instead of the unknown DF $F^*$ to estimate the statistical functional of interest.\n\\begin{definition}[Plug-in estimator]\nSuppose, $X_1,\\ldots,X_n \\overset{IID}{\\sim} F^*$.  The plug-in estimator of a statistical functional of interest, namely, $T(F^*)$, is defined by:\n\\[\n\\widehat{T}_n := \\widehat{T}_n (X_1,\\ldots,X_n) = T(\\widehat{F}_n) \\ .\n\\]\n\\end{definition}\n\n\\begin{definition}[Linear functional]\nIf $T(F) = \\int r(x) dF(x)$ for some function $r(x):\\Xz\\to \\Rz$, then $T$ is called a {\\bf linear functional}.  Thus, $T$ is linear in its arguments:\n\\[\nT(a F + a' F') = a T(F) + a' T(F') \\enspace .\n\\]\n\\end{definition}\n\n\\begin{prop}[Plug-in Estimator of a linear functional]\nThe plug-in estimator for a linear functional $T = \\int r(x) dF(x)$ is:\n\\[\n\\boxed{\nT(\\widehat{F}_n) = \\int r(x) d \\widehat{F}_n(x)=\\frac{1}{n}\\sum_{i=1}^n r(X_i) \n} \\enspace .\n\\]\n\\end{prop}\n\nSome specific examples of statistical linear functionals we have already seen include:\n\\begin{enumerate}\n\\item The {\\bf mean} of RV $X \\sim F$ is a function of the DF $F$:  \n\\[\nT(F) = \\E(X) = \\int x\\,dF(x) \\ .\n\\]\n\\item The {\\bf variance} of RV $X \\sim F$ is a function of the DF $F$:  \n\\[\nT(F) = \\E(X-\\E(X))^2 = \\int (x-\\E(X))^2\\,dF(x) \\ .\n\\]\n\\item The {\\bf value of DF at a given $x \\in \\Rz$} of RV $X \\sim F$ is also a function of DF $F$:\n\\[\nT(F) = F(x) \\  .\n\\]\n\\item The {\\bf $q^{\\text{th}}$ quantile} of RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(q) \\ \\text{ where } q \\in [0,1] \\ .\n\\]\n\\item The {\\bf first quartile} or the {\\bf $0.25^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.25) \\ .\n\\]\n\\item The {\\bf median} or the {\\bf second quartile} or the {\\bf $0.50^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.50) \\  .\n\\]\n\\item The {\\bf third quartile} or the {\\bf $0.75^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.75) \\ .\n\\]\n\\end{enumerate}\n\n\n\\begin{labwork}[Plug-in Estimate for Median of Web Login Data]\nCompute the plug-in estimates for the median for each of the data arrays:\n\\[\n\\text{{\\tt WebLogSeconds20071001035730} and {\\tt WebLogSeconds20071002035730} }\n\\]\nthat can be loaded into memory by following the commands in the first $13$ lines of the script file {\\tt WebLogDataProc.m} of \\hyperref[DA:WebLogs]{Data~\\ref*{DA:WebLogs}}.\n\\end{labwork}\n\n\\begin{labwork}[Plug-in Estimates of Times Between Earth Quakes]\\label{LW:PlugInEstimatesEarthQuakes}\nCompute the plug-in estimates for the median and mean time in minutes between earth quakes in NZ using the data in {\\tt earthquakes.csv}. \n\\VrbMf[label=NZSIEQTimesPlugInEstimates.m]{scripts/NZSIEQTimesPlugInEstimates.m}\n\\begin{VrbM}\n>> NZSIEQTimesPlugInEstimates\nPlugInMedianEstimate =    0.0177\nPlugInMedianEstimateMinutes =   25.5092\nPlugInMeanEstimate =    0.0349\nPlugInMeanEstimateMinutes =   50.2278\n\\end{VrbM}\n\\end{labwork}\n\nNote that any statistical functional can be estimated using the plug-in estimator.  However, to produce a $1-\\alpha$ confidence set for the plug-in point estimate, we need bootstrap methods.  The subject of next chapter.\n\n", "meta": {"hexsha": "3773284696efb359e022eb8e051eed55e2ba9a55", "size": 15591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/NonParamEstimDFPlugIn.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/NonParamEstimDFPlugIn.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/NonParamEstimDFPlugIn.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": 73.1971830986, "max_line_length": 650, "alphanum_fraction": 0.706818036, "num_tokens": 5439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145997, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.6247726210606849}}
{"text": "\\section{Introduction to train a Neural Network} %Jianhong / b-j8497 / Jul 10\n\\subsection{PyTorch Basics} % Author: Jonathan Siegel\nIn this section, we will introduce PyTorch \\footnote{\\url{https://pytorch.org}} which is an open source machine learning framework that accelerates the path from research prototyping to production deployment. \n\nThe basic class underlying pytorch is the tensor class. This class simply represents an array of numeric values (usually floats or doubles) and behaves very similar to the corresponding class in numpy.\n\\begin{python}\nimport torch\nimport numpy as np\n\n# We can initialize a pytorch tensor from a python list.\nx = torch.tensor([[1,2],[3,4]])\nprint('x is', x)\n\n# Or from a numpy array.\ny = torch.tensor(np.array([[1,2],[3,4]]))\nprint('y is', y)\n\n# We can also initialize a zeroed tensor.\na = torch.zeros([2,2])\nb = torch.zeros([3,3], dtype=torch.int32)\n\n# Note that the default type of such a tensor is a 32-bit float.\nprint('Type of a:', a.dtype)\nprint('Type of b:', b.dtype)\n\\end{python}\nThe output will be\n\\begin{python}\nx is tensor([[1, 2],\n        [3, 4]])\ny is tensor([[1, 2],\n        [3, 4]])\nType of a: torch.float32\nType of b: torch.int32\n\\end{python}\nArithmetic operations on PyTorch tensors work as one would expect.\n\\begin{python}\nz = 2*x\nprint(z)\n\nz = y - z\nprint(z)\n\nz = torch.matmul(x,y)\nprint(z)\n\n# etc. see the documentation for more details.\n\\end{python}\nIt gives\n\\begin{python}\ntensor([[2, 4],\n        [6, 8]])\ntensor([[-1, -2],\n        [-3, -4]])\ntensor([[ 7, 10],\n        [15, 22]])\n\\end{python}\n\n\nAt this point, there isn't much difference between Pytorch and Numpy. What distinguishes Pytorch and makes it useful for Deep Learning is the automatic differentiation supported by Pytorch (essentially, Pytorch can automatically apply the chain rule to calculate derivatives). We illustrate this below with a simple example.\n\\begin{python}\n# In this example we calculate the derivative of (x.y)^2 w.r.t x.\n\n# In order to calculate the gradient with respect to a tensor,\n# we must set the requires_grad flag to True.\nx = torch.tensor([1.0, 0.0], requires_grad=True)\ny = torch.tensor([1.0, 1.0])\n\n# By default, requires_grad is set to False if possible.\nprint('y.requires_grad:', y.requires_grad)\n\nz = torch.dot(x, y)\n\n# Because z depends on x, which requires a gradient, z.requires_grad\n# is automatically set to true. This is done because the gradient of z\n# is needed to calculate the gradient of x.\nprint('z.requires_grad:', z.requires_grad)\n\nout = z * z\n\n# Calculate the derivative of out w.r.t. x. Automatically applies\n# the chain rule as needed.\ngrad = torch.autograd.grad(outputs=out, inputs=x)\nprint(grad)\n\\end{python}\nThe output will be\n\\begin{python}\ny.requires_grad: False\nz.requires_grad: True\n(tensor([2., 2.]),)\n\\end{python}\n\nUsing what we have so far, we can automatically differentiate polynomials (since they are just compositions of elementary arithmetic operations). But what about more complicated differentiable functions? We can deal with those by subclassing torch.autograd.Function as we show in the next example.\n\\begin{python}\n# We illustrate this by implementing the pointwise ReLU function\n# (which is of course already implemented in Pytorch, but this\n# process can be used to define more complex custom functions as well).\n\n# We subclass torch.autograd.Function to define new functions\nclass MyReLU(torch.autograd.Function):\n  \n  # The forward method applies the function to the input argument.\n  # The ctx argument can be used to cache information for the subsequent\n  # gradient computation. You can cache an object using using the \n  # ctx.save_for_backward method.\n  @staticmethod\n  def forward(ctx, input):\n    # The input is needed later to calculate the gradient.\n    ctx.save_for_backward(input)\n    return input.clamp(min=0)\n  \n  # The backward method calculates the gradient of the input, given that\n  # the gradient of the output is the output_grad argument.\n  def backward(ctx, output_grad):\n    # Recover the original input from ctx.\n    input, = ctx.saved_tensors\n    grad_input = output_grad.clone()\n    # Zero out the output gradient where the input is negative to obtain\n    # the input gradient.\n    grad_input[input < 0] = 0\n    return grad_input\n    \n# Apply the new function to a tensor.\nprint(MyReLU.apply(x - 0.5))\n    \n# Calculating derivatives utilizes the backward method.\nz = torch.mul(MyReLU.apply(x - 0.5), y)\n# In this case z is not a scalar, so we must provide the derivatives\n# of the outputs. What is actually computed is the gradient of \n# z dot output_grad with respect to x.\noutput_grad = torch.ones([2])\nprint(torch.autograd.grad(outputs=z, inputs=x, grad_outputs = output_grad))\n\\end{python}\n\\begin{python}\ntensor([0.5000, 0.0000], grad_fn=<MyReLUBackward>)\n(tensor([1., 0.]),)\n\\end{python}\nWe have seen how to define a custom function. Luckily, we won't have to do this much work very often. As we will see, many common functions in machine learning have already been implemented for us.\n\nNext we introduce the Variable class in torch.autograd. This class used to be necessary for autograd, but since regular tensors now allow for automatic differentiation, it is basically just a wrapper around the tensor class which introduces a few additional methods, most notably the .backward() method.\n\\begin{python}\nfrom torch.autograd import Variable\n\n# Variables can be copy constructed from tensors. When constructed, we can \n# also specify whether the gradient is required or not.\nx = Variable(x, requires_grad=True)\ny = Variable(y, requires_grad=False)\n\n# All functions which can be applied to tensors can also be applied to \n# Variables. In the code below, z will be a Variable since x and y are.\n# In general, if at least one input is a Variable, then the output will be as\n# well.\nz = torch.mul(MyReLU.apply(x - 0.5), y)\n\n# Notably, we can now call .backward() from z_variable, which will compute \n# the gradient with respect to z for all tensors it depends on (if their\n# requires_grad field is True). Note that since z isn't a scalar, we still\n# need to pass the gradients of each of its components.\nz.backward(gradient=output_grad)\n\n# The resulting gradients are stored in the .grad field of the corresponding\n# tensors. The gradients are only calculated if requires_grad = True.\nprint('x gradient:', x.grad)\nprint('y gradient:', y.grad)\n\\end{python}\n\\begin{python}\nx gradient: tensor([1., 0.])\ny gradient: None\n\\end{python}\nSince Variables contain all of the functionality as tensors, but contain additional methods (especially the very useful .backward() method) as well, we recommend using Variables for all non-constant quantities in your code. We illustrate some of the additional behaviors of the .backward() function below.\n\\begin{python}\n# A very important note is that gradients are accumulated, i.e. added to\n# whatever is already stored in the .grad field.\nz = torch.mul(MyReLU.apply(x - 0.5), y)\nz.backward(gradient=output_grad)\nprint('x.grad has now been doubled:', x.grad)\n\n# In order to avoid this, we must first clear the gradient of x. Note also\n# that in the above example we need to recompute z in terms of x and y \n# in order to recompute the gradient. We can avoid this by setting \n# retain_graph = True\nx.grad.data.zero_()\nz = torch.mul(MyReLU.apply(x - 0.5), y)\nz.backward(gradient=output_grad, retain_graph=True)\nprint('x gradient:', x.grad)\n\n# Since we set retain_graph=True during the last backward call, we can \n# recompute the gradients without recalculating z. This feature is not\n# commonly used and considered bad practice, though.\nx.grad.data.zero_()\nz.backward(gradient=output_grad)\nprint('x gradient:', x.grad)\n\\end{python}\n\\begin{python}\nx.grad has now been doubled: tensor([2., 0.])\nx gradient: tensor([1., 0.])\nx gradient: tensor([1., 0.])\n\\end{python}\n\n\\subsection{Building Neural Networks} % Author: Jonathan Siegel\nBuilding and training neural networks directly using Pytorch Variables and automatic differentiation would be very cumbersome. Luckily, Pytorch provides built-in functionality which makes it much easier to build and train neural networks. In this section, we will describe how to use this functionality to build (i.e. define) a network.\n\nThe most important library for building neural networks is the torch.nn library. This library allows us to build neural networks by concatenating different types of layers.\n\\begin{python}\nimport torch.nn as nn\n\n# Here we define a sample neural network. The class defining our\n# network should inherit from nn.Module.\nclass Net(nn.Module):\n  def __init__(self):\n    super(Net, self).__init__()\n    # Here we define the layers of the network.\n    # The nn.Sequential method constructs a model by concatenating\n    # the layers which are input to it.\n    self.apply = nn.Sequential( # Sequentially apply a\n        nn.Linear(10,20),       # Linear function R^10 -> R^20\n        nn.ReLU(),              # Pointwise ReLU\n        nn.Linear(20,20),       # Linear function R^20 -> R^20\n        nn.ReLU(),              # Pointwise ReLU\n        nn.Linear(20,10))       # Linear function R^20 -> R^10\n\n  # The following method must be overloaded. It specifies how to\n  # evaluate the model given an input x.\n  def forward(self, x):\n    return self.apply(x) # In our instance we simply pass x through\n                         # the previously defined layers. This could\n                         # potentially contains something more complex.\n\\end{python}\nImplementing a Logistic Regression\nWe will now consider the problem of implementing a logistic regression (trained using stochastic gradient descent) using Pytorch. We will test this model on the MNIST handwritten data imageset.\n\\begin{python}\nimport torch\nimport torchvision\nimport torchvision.transforms as transforms\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# Transforms images from [0,255] to [0,1] range.\ntransform = transforms.Compose(\n    [transforms.ToTensor(),\n     transforms.Normalize(mean=[0], std=[1])])\n\n# Load the set of training images.\ntrainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)\ntrainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)\n\n# Load the set of test images.\ntestset = torchvision.datasets.MNIST(root='./data', train=False, download=True, transform=transform)\ntestloader = torch.utils.data.DataLoader(testset, batch_size=4, shuffle=False, num_workers=2)\n\n# Let's plot some of the images to see what we're dealing with.\ndef plot_images(imgs):\n  for i in range(imgs.size()[0]):\n    npimg = imgs.numpy()[i,0,:,:]\n    plt.imshow(npimg, cmap='gray')\n    plt.ion()\n    plt.show()\n    plt.pause(.05)\n\ndata = iter(testloader)\nimages, labels = data.next()\nprint(labels)\nplot_images(images)\n\\end{python}\nNow that we've loaded our dataset, let's build the logistic regression model. In the language of deep learning, the logistic regression is the same as a neural network with no hidden layers trained with a cross entropy loss (exercise: work this out yourself!).\n\\begin{python}\n# This library contains a lot of useful classes for constructing \n# neural networks and other machine learning models.\nimport torch.nn as nn\n\n# This model simply takes an input of dimension 784 and multiplies it \n# by a 784x10 matrix of parameters.\nclass LogisticRegression(nn.Module):\n  def __init__(self):\n    super(LogisticRegression, self).__init__()\n    self.dense_linear = nn.Sequential(\n      nn.Linear(28 * 28, 10))\n\n  def forward(self, x):\n    x = x.view(-1,28*28)\n    x = self.dense_linear(x)\n    return x\n  \n# Construct an instance of the model.\nmodel = LogisticRegression()\n\\end{python}\n\nNow we need to fit the parameters of this logistic regression model (the 784x10 matrix). We do this by defining a loss function (the cross entropy) and using the stochastic gradient descent optimization algorithm. Luckily, both of these have already been implemented for you in Pytorch!\n\\begin{python}\n# This library contains implementations of a number of useful optimization algorithms.\nimport torch.optim as optim\n\n# The cross entropy loss is already implemented in Pytorch.\ncriterion = nn.CrossEntropyLoss()\n\n# The stochastic gradient descent algorithm with a step size of 0.1.\noptimizer = optim.SGD(model.parameters(), lr=0.1)\n\n# Write a loop to train the model using the given optimizer and loss functions.\nfor i in range(20):\n  for data in trainloader:\n    # extract the images and labels.\n    inputs, labels = data\n    \n    # This must be called to zero out the accumulated gradients.\n    optimizer.zero_grad()\n    \n    # Calculate the predictions made based on the model.\n    outputs = model(inputs)\n    \n    # Evaluate the loss function based on the model predictions.\n    loss = criterion(outputs, labels)\n    \n    # Calculate the gradient of the parameters with respect to the loss.\n    loss.backward()\n    \n    # Take a optimization step.\n    optimizer.step()\n    \n  print('Completed epoch %d' % i)\nprint('Completed training')\n\\end{python}\nNow that we've trained our model, we will test its accuracy on the test dataset.\n\\begin{python}\n# Calculate the total number of test samples and the number of correctly \n# classified test samples\ncorrect = 0\ntotal = 0\nfor data in testloader:\n  images, labels = data\n  outputs = model(images)\n  # Take the most likely label as the predicted label.\n  _, predicted = torch.max(outputs.data, 1)\n  total += labels.size(0)\n  correct += (predicted == labels).sum()\n\nprint('Out of %d samples, the model correctly classified %d' % (total, correct))\n\\end{python}\n\n\\subsection{Datasets}\nIn this section, we will talk about how to train a neural network. According to the course in the morning, there are a lot of pictures in a dataset, so, at the beginning, we will introduce some famous and popular datasets. \n\\begin{itemize}\n\\item {\\bf MNIST}\\footnote{\\url{http://yann.lecun.com/exdb/mnist/}} contains 60,000 pictures of the ten handwritten digits from 0 to 9. The size of each picture is $28\\times 28$ pixels. There are 60,000 pictures for training and 10,000 for testing.\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.5]{./figures/497Proj_mnist}\n\\caption{MNIST}\n\\end{figure}\n\\item {\\bf CIFAR10}\\footnote{\\url{https://www.cs.toronto.edu/~kriz/cifar.html}} is a datasets consists of $60,000$ color images in $10$ classes, with $6,000$ images per class. There are $50,000$ training data and $10,000$ testing data. Since there are colored pictures, there are three channels, red, green and blue, of the input data. The size is $32\\times 32$ pixels for each. It's a subclass of CIFAR100.\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.5]{./figures/497Proj_cifar10}\n\\caption{CIFAR10}\n\\end{figure}\n\\item {\\bf ImageNet}\\footnote{\\url{http://www.image-net.org}} is a much larger dataset containing 1.2 millions pictures. The size is $224\\times 224$ pixels. The size is much bigger and the quantity is also much larger. So you may get a good performance with a simple neural network on MNIST or CIFAR10, but it's much hard to get good accuracy on ImageNet. %So that why we need   some optimization algorithms on such large datasets.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.4]{./figures/497Proj_imagenet}\n\\caption{ImageNet}\n\\end{figure}\n\\end{itemize}\nThese are three common used datasets that we will use to train our neural networks. \n\n\\subsection{Train an image classifier}\nNow we move to a brief PyTorch \\footnote{see a quick tutorial \\url{https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html}} tutorial. To train your first image classifier, these are basically five steps in order:\n\\begin{enumerate}\n\\item Load and normalizing the CIFAR10 training and test datasets using torchvision (Here we use CIFAR10 as an example).\n\\item Define a Convolutional Neural Network. (You can also use a Deep Neural Networks or Recurrent Neural Networks whichever you like.)\n\\item Define a loss function. (As we just defined before as the function $f$ that is the sum of the total losses.) \n\\item Train the network on the training data. (Given the loss function and training data, we can do the steepest descent, stochastic gradient descent or some other optimization algorithms to decrease the loss function on the training set.)\n\\item Test the network on the test data. (After you have got a good model on your neural network from the last step, then you test your neural network on the test set to see how well it performs. So the final criterion that judges your neural network is the test accuracy because the test set doesn't involve the training process. So it is very important to get a good test accuracy.)\n\\end{enumerate}\nThese are all the steps you need to train a neural network. Now let start from the first step.\n\n\\subsubsection{Load a dataset}\nTo load the dataset, we need the libraries, like torch and some others. So we need to import the libraries first.\n\\begin{python}\nimport torch\nimport torchvision\nimport torchvision.transforms as transforms\n\\end{python}\nThis is the first step for all the other codes. And then here is some preprocess of the dataset. Because pictures can be various, you need to preprocess and normalize the pictures to make them have better properties, like the zero mean and small variance, for better interpretation.\n\\begin{python}\ntransform = transforms.Compose(\n    [transforms.ToTensor(), # Transform the picture to the torch tensor\n     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) # and then normalize it\n\\end{python}\nThen we define a training set using the \\emph{`CIFAR10'} function since CIFAR10 is a default dataset in PyTorch.  The \\emph{`root'} is the folder to which we want to store the data. Since we are using the training set, set \\emph{`train'} is true. And because we haven't download it before, set \\emph{`download'} is true. \\emph{`transform=transform'} means we want to transform these pictures following the \\emph{`transform'} function that we defined in the preprocess part.\n\\begin{python}\ntrainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)\n\\end{python}\nNow we have already defined our training set. But there are still some problems. The dataset is too large to load them all to compute the gradient on the full batch. That is why we choose the stochastic gradient descent. So we choose a small batch (mini-batch) to calculate the corresponding gradient. Here we set the batch size to be 4. So we can compute the loss and the gradient very conveniently on each step.  \n\\begin{python}\ntrainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)\n\\end{python}\nIt is the same for the test set except that the \\emph{`train'} and \\emph{`shuffle'} are false. \n\\begin{python}\ntestset = torchvision.datasets.CIFAR10(root='./data', train=False,download=True, transform=transform)\ntestloader = torch.utils.data.DataLoader(testset, batch_size=4,shuffle=False, num_workers=2)\n\\end{python}\n\nHere are just some parts to show the images. If you are interested about what the images look like, you can use the \\emph{`matplotlib'} library to plot them. If not, just skip this part.\n\\begin{python}\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# functions to show an image\n\ndef imshow(img):\n    img = img / 2 + 0.5     # unnormalize\n    npimg = img.numpy()\n    plt.imshow(np.transpose(npimg, (1, 2, 0)))\n    plt.show()\n\n# get some random training images\ndataiter = iter(trainloader)\nimages, labels = dataiter.next()\n\n# show images\nimshow(torchvision.utils.make_grid(images))\n# print labels\nprint(' '.join('%5s' % classes[labels[j]] for j in range(4)))\n\\end{python}\n\nThat's basically how you load a dataset. Let's go to the second step.\n\\subsubsection{Define a Convolution Neural Network}\nSince we are dealing with the image classification, we prefer to using the Convolution Neural Network. And we will introduce more details the part later. Now we just go through the codes for the simple example line by line.\nThe first part is to initialize the class. Then we define how we compute a forward process by given an input as \\emph{`x'} in second part.  First, the input will be convoluted with the 2-d convolution operation, then use the ReLU function as the nonlinear activation function, after that we make a pooling. This is what a convolution layer composed, first a convolution operator, then a nonlinear activation, and then a pooling. We define two convolution layers this way.  After that, the function \\emph{`x.view'} is used to flat the picture, because the output of the convolution layer is still a two dimensional picture. Here, we use the \\emph{`view'} function to flat the two dimensional picture to be one dimensional of length 400. Then we make a fully connect operator and a ReLU function. After that, we have the final classification layer to output the prediction outcome. So that is basically what the CNN composed.\n\\begin{python}\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass Net(nn.Module):\n    def __init__(self):  # Initialize the class\n        super(Net, self).__init__()\n        # the construction of the neural network\n        self.conv1 = nn.Conv2d(3, 6, 5) # a 2-d convolution layer named as `conv1'\n        self.pool = nn.MaxPool2d(2, 2) # a max pooling layer named `pool'\n        self.conv2 = nn.Conv2d(6, 16, 5)\n        self.fc1 = nn.Linear(16 * 5 * 5, 120) # linear layer\n        self.fc2 = nn.Linear(120, 84)\n        self.fc3 = nn.Linear(84, 10)\n\n    def forward(self, x):  \n        x = self.pool(F.relu(self.conv1(x))) \n        x = self.pool(F.relu(self.conv2(x))) \n        x = x.view(-1, 16 * 5 * 5)\n        x = F.relu(self.fc1(x))\n        x = F.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n\n\nnet = Net()\n\\end{python}\nDifferent choices of these hyper-parameters may lead to different results. We usually need to tune these hyper-parameters to get a better model. \nSince the input of each layer in the neural network is the output of its previous layer, there are two parts of hyper-parameters of an operator, like \\emph{`Conv2d'}, \\emph{`Linear'}. One part depends on the input, which is the output of the previous layer, of this operator. The other can be arbitrarily choose to get a good model, and this part may decide a part of parameter of the next operator/layer. For example, `Linear(input dimension, output dimension)', the dimension of output of \\emph{`fc1'} is 120, then the first parameter of \\emph{`fc2'} should be same as it, 120.  \n\nAnother important hyper-parameters of convolution layers is channel. For \\emph{`Conv2d (number of input channels, number of output channels, kernel size)'}, we need keep the number of input channel same as the number of output channel of the previous layer.   \n\nTo choose parameters (called hyper-parameters in neural network) of the torch functions, we recommend to read the corresponding documents in PyTorch website for more precise details.\n\nHere we just give a simple working example. Later on, we will talk about more details and how to modify them.\n\n\\subsubsection{Define a loss function and optimization}\nThere are actually a lot of possible loss functions. For image classification, the common choice is the cross-entropy. You can also use the square loss or any reasonable functions based on the problems. Actually, the common loss functions have already been defined in the \\emph{`torch.nn'} library. The way to use them is like the \\emph{`criterion'} in the following code. And the \\emph{`optimizer'} is the corresponding optimization algorithm used to decrease the loss function. The common algorithms can also be found in the \\emph{`torch.optim'} library. In the example, we choose stochastic gradient descent (SGD). And there are a few optional parameters, like learning rate \\emph{`lr'}, momentum. For large learning rate, you may behave very widely, but for small learning rate, you may zig-zaging around very small range. The learning rate is one of the most important hyper-parameter that we need to tune to get a good model.\n\\begin{python}\nimport torch.optim as optim\n\ncriterion = nn.CrossEntropyLoss() #use the cross-entropy loss defined in torch library\noptimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n\\end{python}     \n\nNow we have almost defined everything. Then we can start to train our networks. \n\\subsubsection{Train the network}\nFor the training, we first define what the epoch means. Because we have like 60,000 pictures in this training set, and we divided it into a few small batches (mini-batch). Whenever you go over all the pictures in the training set, then it means you finish an epoch.\nAnd when we do one optimization step (calculate gradient and update the parameters) in one mini-batch, we say it an iteration.\n\\begin{python}\nfor epoch in range(2):  # loop over the dataset multiple times\n\n    running_loss = 0.0 \n    for i, data in enumerate(trainloader, 0): # i is the index and data are pictures in the corresponding mini-batch\n        # get the inputs; data is a list of [inputs, labels]\n        inputs, labels = data\n\n        # zero the parameter gradients\n        optimizer.zero_grad()\n\n        # forward + backward + optimize\n        outputs = net(inputs) # forward propagation to get the output\n        loss = criterion(outputs, labels) # compute the loss, see if it satisfy the terminal criterion\n        loss.backward() # backward propagation to get the gradient\n        optimizer.step() # update the parameters by optimization algorithm (like SGD) to decrease the loss\n\n        # print statistics\n        running_loss += loss.item()\n        if i % 2000 == 1999:    # print every 2000 mini-batches\n            print('[%d, %5d] loss: %.3f' %\n                  (epoch + 1, i + 1, running_loss / 2000))\n            running_loss = 0.0\n\nprint('Finished Training') # After 2 epochs, we finish the training.\n\\end{python}\n\nNow, after training process, we want to see how well the model behave. So let's start to test the model we got on the test set, which is independent to the training.\n\\subsubsection{Test the network on the test data}\n\\begin{python}\ncorrect = 0 \ntotal = 0\nwith torch.no_grad(): # We don't need compute the gradients in the test process since we don't need optimization\n    for data in testloader:\n        images, labels = data\n        outputs = net(images)\n        _, predicted = torch.max(outputs.data, 1) # get the predicted class by neural network\n        total += labels.size(0)\n        correct += (predicted == labels).sum().item() # compare the predicted and the real label\n\nprint('Accuracy of the network on the 10000 test images: %d %%' % (100 * correct / total))\n\\end{python}\nNow we finish training a simple neural network here.\n\n\n\n", "meta": {"hexsha": "f8ca2e0495f8a0d0be795491fd1850fd037da388", "size": 26715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/497Proj_introNN.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/497Proj_introNN.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/497Proj_introNN.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.0803059273, "max_line_length": 931, "alphanum_fraction": 0.7406700356, "num_tokens": 6466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6247108421331493}}
{"text": "\\subsection{Ordinals}\\label{subsec:ordinals}\n\n\\begin{remark}\\label{rem:ordinal_definition}\n  Ordinals are generalizations of \\hyperref[def:set_of_natural_numbers]{natural numbers}. We will find characterizing properties of the natural numbers (defined as members of \\hyperref[thm:smallest_inductive_set_existence]{\\( \\omega \\)}), so that it is clear what we want to generalize.\n\n  Every natural number is defined as a set of other natural numbers:\n  \\begin{align*}\n    &0 = \\varnothing \\\\\n    &1 = \\set{ \\varnothing } = \\set{ 0 } \\\\\n    &2 = \\set{ \\varnothing, \\set{ \\varnothing } } = \\set{ 0, 1 } \\\\\n    &3 = \\set{ \\varnothing, \\set{ \\varnothing }, \\set{ \\varnothing, \\set{ \\varnothing } } } = \\set{ 0, 1, 2 }\n  \\end{align*}\n\n  It just, so happens that each natural number \\( n \\) is the set of natural numbers that are smaller with respect to the strict order relation \\( < \\) defined in \\eqref{eq:def:natural_number_ordering/strict_predicate}.\n\n  Therefore, \\( \\in \\) and \\( < \\) are equivalent on the set \\( \\omega \\). It follows from \\fullref{thm:natural_numbers_are_well_ordered} that \\( \\in \\) is a \\hyperref[def:totally_ordered_set]{strict total order} on \\( \\omega \\). It is even \\hyperref[def:well_ordered_set]{well-ordered} by \\( \\in \\), but the latter condition is redundant due to \\fullref{thm:set_membership_is_well_founded}.\n\n  For an arbitrary set \\( A \\), set membership is not even a \\hyperref[def:partially_ordered_set/strict]{strict partial order} --- irreflexivity is implied by \\fullref{thm:set_membership_is_well_founded}, but transitivity of \\( \\in \\) as a binary relation on \\( A \\) fails to hold in general, not speaking about trichotomy.\n\n  A very simple counterexample for transitivity of \\( \\in \\) is the set \\( \\set{ \\varnothing, \\set{ \\varnothing }, \\set{ \\set{ \\varnothing } } } \\). Clearly \\( \\varnothing \\in \\set{ \\varnothing } \\) and \\( \\set{ \\varnothing } \\in \\set{ \\set{ \\varnothing } } \\), but \\( \\varnothing \\not\\in \\set{ \\set{ \\varnothing } } \\).\n\n  In order for a set \\( A \\) to be a member of \\( \\omega \\), it is not sufficient for \\( \\in \\) to be a strict total ordered on \\( A \\). Except for the members of \\( \\omega \\), another set that is totally ordered by \\( \\in \\) is \\( A = \\set{ 0, 2, 4 } \\).\n\n  If we require \\( A = \\set{ 0, 2, 4 } \\) to be a \\hyperref[def:transitive_set]{transitive set}, however, it will be a natural number. Indeed, since \\( 4 \\) is a member of \\( A \\) and \\( 1 \\) and \\( 3 \\) are members of \\( 4 \\), then by adding \\( 1 \\) and \\( 3 \\) to \\( A \\) we obtain the set \\( \\set{ 0, 1, 2, 3, 4 } \\), which by our definition of natural numbers is \\( 5 \\).\n\n  note that transitivity of the relation \\( \\in \\) on \\( A \\) and transitivity of the set \\( A \\) itself are entirely different concepts, although we will use both. Every member of \\( \\omega \\) is a transitive set by \\fullref{thm:omega_is_transitive} and the relation \\( \\in \\) is a strict total order by \\fullref{thm:natural_numbers_are_well_ordered}.\n\n  This is the reasoning behind our definition of an ordinal --- \\fullref{def:ordinal}. From this definition it will follow that the ordinals are unique representatives of order-isomorphisms classes of well-ordered sets.\n\n  As a final note, the above two conditions are not sufficient for \\( A \\) to be a member of \\( \\omega \\) (they are too general), but if we additionally require \\( A \\) to be a \\hyperref[def:set_finiteness]{finite set}, then \\( A \\) will be a member of \\( \\omega \\). We have yet to define finiteness, however.\n\\end{remark}\n\n\\begin{definition}\\label{def:ordinal}\\mcite[def. 63.12]{OpenLogicFull}\n  An \\term{ordinal number} or simply \\term{ordinal} is a \\hyperref[def:transitive_set]{transitive set} \\( A \\) such that set membership (as a binary relation on \\( A \\)) \\hyperref[def:well_ordered_set]{well-orders} \\( A \\). By tradition, ordinals are denoted by initial small Greek letters like \\( \\alpha \\) and \\( \\beta \\).\n\n  Because of \\fullref{thm:set_membership_is_well_founded}, it is sufficient for set membership to be a \\hyperref[def:totally_ordered_set]{strict total order} on \\( A \\). Since well-foundedness also implies \\hyperref[def:binary_relation/irreflexive]{irreflexivity}, it follows that set membership must only be \\hyperref[def:binary_relation/transitive]{transitive} and \\hyperref[def:binary_relation/trichotomic]{trichotomic} on \\( A \\).\n\n  In the absence of the \\hyperref[def:zfc/foundation]{axiom of foundation}, we additionally require set membership to be a \\hyperref[def:well_founded_relation]{well-founded relation} on \\( A \\), so that \\( A \\) is well-ordered.\n\n  See \\fullref{rem:ordinal_definition} for a further discussion of the definition, especially the different notions of transitivity.\n\n  We introduce the notation \\( \\alpha < \\beta \\) for \\( \\alpha \\in \\beta \\) in analogy with natural numbers. This is not a binary relation since there is no set of all ordinals by \\fullref{thm:burali_forti_paradox}, however it does satisfy the properties of a well-order due to \\fullref{thm:ordinals_are_well_ordered/trichotomy}.\n\n  Finally, we introduce the following \\hyperref[rem:predicate_formula]{predicate formula}\n  \\begin{equation*}\\taglabel[\\op{IsOrdinal}]{eq:def:ordinal/predicate}\n    \\begin{aligned}\n      \\ref{eq:def:ordinal/predicate}[\\tau] \\coloneqq\n        &\\ref{eq:def:transitive_set/predicate}[\\tau]\n        \\wedge \\\\ \\wedge&\n        \\parens[\\Big]\n        {\n          \\qforall {\\xi \\in \\tau}\n          \\qforall {\\eta \\in \\tau}\n          \\parens[\\Big]\n            {\n              \\eta \\in \\xi \\vee \\eta \\doteq \\xi \\vee \\xi \\in \\eta\n            }\n        }\n        \\wedge \\\\ \\wedge&\n        \\parens[\\Big]\n        {\n          \\qforall {\\xi \\in \\tau}\n          \\qforall {\\eta \\in \\tau}\n          \\qforall {\\zeta \\in \\tau}\n          \\parens[\\Big]\n          {\n            (\\xi \\in \\eta \\wedge \\eta \\in \\zeta) \\rightarrow \\xi \\in \\zeta\n          }\n        }.\n    \\end{aligned}\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:omega_is_an_ordinal}\n  The \\hyperref[thm:smallest_inductive_set_existence]{smallest inductive set} \\( \\omega \\) is an \\hyperref[def:ordinal]{ordinal}.\n\\end{proposition}\n\\begin{proof}\n  From \\fullref{thm:omega_is_transitive} it follows that \\( \\omega \\) is a transitive set.\n\n  Also, as discussed in \\fullref{rem:ordinal_definition}, from \\fullref{thm:natural_numbers_are_well_ordered} it follows that set membership is a strict total order on \\( \\omega \\).\n\n  Therefore, \\( \\omega \\) is an \\hyperref[def:ordinal]{ordinal}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:member_of_ordinal_is_ordinal}\\mcite[lemma 63.13]{OpenLogicFull}\n  Every member of an ordinal is an ordinal.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\alpha \\) be an ordinal and let \\( \\beta \\in \\alpha \\). We will show that \\( \\beta \\) is an ordinal.\n\n  By transitivity of \\( \\alpha \\), we have \\( \\beta \\subseteq \\alpha \\) and by \\fullref{def:partially_ordered_set/submodel}, \\( (\\beta, \\in) \\) is a (strictly) totally ordered set as a \\hyperref[def:first_order_substructure]{substructure} of \\( (\\alpha, \\in) \\).\n\n  It remains to show that \\( \\beta \\) is itself transitive. Let \\( x \\in \\beta \\). We have that \\( \\beta \\subseteq \\alpha \\) since \\( \\alpha \\) is transitive, hence \\( x \\in \\alpha \\).\n\n  Fix \\( y \\in x \\). Again from the transitivity of \\( \\alpha \\) it follows that \\( y \\in \\alpha \\). Also, \\( \\in \\) is a total order on \\( \\alpha \\) and hence from \\( y \\in x \\) and \\( x \\in \\beta \\) it follows that \\( y \\in \\beta \\).\n\n  Since \\( y \\in x \\) was chosen arbitrarily, it follows that \\( x \\subseteq \\beta \\). Since \\( x \\) was chosen arbitrarily, it follows that \\( \\beta \\) is transitive.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:initial_segment_of_ordinal}\n  Let \\( \\alpha \\) be an ordinal. For any \\( \\beta \\in \\alpha \\), the \\hyperref[def:partially_ordered_set_interval/ray]{open initial segment} \\( \\alpha_\\beta \\) equals \\( \\beta \\).\n\n  This is the bounded version of \\fullref{thm:ordinal_is_set_of_smaller_ordinals}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\beta \\in \\alpha \\). Consider the initial segment\n  \\begin{equation*}\n    \\alpha_{<\\beta} = \\set{ \\gamma \\in \\alpha \\given \\gamma \\in \\beta }.\n  \\end{equation*}\n\n  Clearly \\( \\alpha_{<\\beta} = \\alpha \\cap \\beta \\). Given that \\( \\alpha \\) is a transitive set, however, we have \\( \\beta \\subseteq \\alpha \\) and thus \\( \\alpha \\cap \\beta = \\beta \\).\n\n  Therefore, \\( \\alpha_{<\\beta} = \\beta \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:natural_numbers_are_ordinals}\n  The natural numbers (as members of \\hyperref[thm:smallest_inductive_set_existence]{\\( \\omega \\)}) are ordinals.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:omega_is_an_ordinal} and \\fullref{thm:member_of_ordinal_is_ordinal}.\n\\end{proof}\n\n\\begin{definition}\\label{def:transfinite_sequence}\n  For any ordinal \\( \\alpha \\) we call any function with \\( \\alpha \\) as its domain a \\( \\alpha \\)-indexed \\term{transfinite sequence}.\n\n  In particular, the case \\( \\alpha = \\omega \\) corresponds to the standard \\hyperref[def:sequence]{natural number sequences}.\n\\end{definition}\n\n\\begin{theorem}[Bounded transfinite induction]\\label{thm:bounded_transfinite_induction}\n  For every formula \\( \\varphi \\) in the language of set theory not containing \\( \\tau \\), \\( \\eta \\) nor \\( \\zeta \\) as free variables, the following is a theorem of \\logic{ZFC}:\n  \\small\n  \\begin{equation*}\n    \\qforall \\tau\n    \\parens[\\Bigg]\n    {\n      \\ref{eq:def:ordinal/predicate}[\\tau]\n      \\rightarrow\n      \\parens[\\Big]\n        {\n          \\qforall {\\eta \\in \\tau}\n          \\overbrace\n            {\n              \\underbrace{ \\parens[\\Big]{ \\qforall {\\zeta \\in \\eta} \\varphi[\\xi \\mapsto \\zeta] } }_{\\mathclap{\\substack{\\T{inductive} \\\\ \\T{hypothesis}}}}\n              \\rightarrow\n              \\underbrace{ \\varphi[\\xi \\mapsto \\eta] }_{\\mathclap{\\substack{\\T{inductive step} \\\\ \\T{conclusion}}}}\n            }^{\\T{inductive step}}\n        }\n      \\rightarrow\n      \\underbrace{ \\qforall {\\eta \\in \\tau} \\varphi[\\xi \\mapsto \\eta] }_{\\T{conclusion}}\n    }.\n  \\end{equation*}\n  \\normalsize\n\n  See the comments in \\fullref{def:peano_arithmetic/PA3} regarding variables and quantification in axiom schemas and \\fullref{rem:induction} for a general discussion of induction.\n\n  See \\fullref{rem:transfinite_induction} about a reformulation that is often useful in practice.\n\\end{theorem}\n\\begin{proof}\n  This theorem is a special case of \\fullref{thm:epsilon_induction} with the formula \\( \\xi \\in \\tau \\rightarrow \\varphi \\) that is explicitly universally quantified by the parameter \\( \\tau \\) which ranges over all ordinals.\n\n  Note that it is unnecessary to verify that \\( \\eta \\) and \\( \\zeta \\) are ordinals because \\fullref{thm:member_of_ordinal_is_ordinal} ensures that \\( \\eta \\) is only quantified over ordinals.\n\\end{proof}\n\n\\begin{theorem}[Bounded transfinite recursion]\\label{thm:bounded_transfinite_recursion}\\mcite[177]{Enderton1977Sets}\n  Fix an \\hyperref[def:ordinal]{ordinal} \\( \\alpha \\) and a nonempty set \\( A \\). Suppose that we are given some transformation \\( T: \\pow(\\alpha \\times A) \\to A \\) whose value for any relation between \\( \\alpha \\). Then there exists a unique \\( \\alpha \\)-indexed \\hyperref[def:transfinite_sequence]{transfinite sequence} \\( f: \\alpha \\to A \\) such that for any \\( \\beta \\in \\alpha \\) we have \\( f(\\beta) = T(f\\restr_\\beta) \\).\n\n  This is a vast generalization of \\fullref{thm:omega_recursion} from \\hyperref[def:sequence]{natural number sequences} to \\hyperref[def:transfinite_sequence]{transfinite sequences}.\n\n  See \\fullref{rem:transfinite_induction} about a reformulation that is often useful in practice.\n\\end{theorem}\n\\begin{proof}\n  The proof is analogous to that of \\fullref{thm:omega_recursion}, but we will give it anyway to highlight the difference between using \\fullref{thm:omega_induction} and \\fullref{thm:bounded_transfinite_induction}.\n\n  Let \\( G \\subseteq \\pow(\\alpha \\times A) \\) be the set of all \\hyperref[def:partial_function]{partial single-valued functions} \\( g: \\alpha \\to A \\) such that\n  \\begin{itemize}\n    \\item There exists some \\( \\beta_g \\in \\alpha \\) such that \\( g \\) is defined only in the \\hyperref[def:partially_ordered_set_interval/ray]{open initial segment} \\( \\alpha_{< \\beta_g} \\). That is, \\( g \\) is defined for all \\( \\beta \\) up to not including \\( \\beta_g \\).\n\n    \\item \\( g(\\beta) = T(g\\restr_\\beta) \\) for all \\( \\beta < \\beta_g \\).\n  \\end{itemize}\n\n  Clearly \\( G \\) is nonempty because the function \\( \\set{ (\\varnothing, T(\\varnothing)) } \\) belongs to \\( G \\).\n\n  Define \\( f \\coloneqq \\bigcup G \\). At this point \\( f \\) is a \\hyperref[def:multi_valued_function]{multi-valued function}. We must now show that \\( f \\) has all the properties that we want.\n\n  \\SubProofOf[def:multi_valued_function/total]{totality} First, we will use \\fullref{thm:bounded_transfinite_induction} to show that \\( f \\) is total.\n\n  Fix \\( \\beta \\in \\dom f \\). Then there exists a function \\( g \\in G \\) defined for all \\( \\gamma < \\beta \\).\n\n  \\begin{itemize}\n    \\item If \\( g \\) is also defined at \\( \\beta \\) also, this directly proves that \\( \\beta \\in \\dom f \\).\n    \\item If \\( g \\) is not defined at \\( \\beta \\), consider\n    \\begin{equation*}\n      \\widehat g \\coloneqq g \\cup \\set{ (\\beta, T(g\\restr_\\beta) }.\n    \\end{equation*}\n\n    The function \\( \\widehat g \\) is again a single-valued partial function and thus it belongs to \\( G \\), hence \\( \\beta \\in \\dom f \\).\n  \\end{itemize}\n\n  Therefore, \\fullref{thm:bounded_transfinite_induction} allows us to conclude that \\( f: \\alpha \\multto A \\) is a total multi-valued function.\n\n  \\SubProofOf[def:function]{single-valuedness} Now that we know that \\( f \\) is total, we will prove that it is single-valued and thus is a function in the usual sense of the term.\n\n  Fix \\( \\beta \\in \\alpha \\). Suppose that \\( f \\) is single-valued for all \\( \\gamma < \\beta \\). Since \\( f \\) is total, there exist at least one partial function \\( g \\) in \\( G \\) that is defined at \\( \\beta \\). Let \\( g \\) and \\( h \\) both be such (single-valued partial) functions.\n\n  Then\n  \\begin{equation*}\n    g(\\beta) = T(g\\restr_\\beta) = T(f\\restr_\\beta) = T(h\\restr_\\beta) = h(\\beta),\n  \\end{equation*}\n  hence \\( g \\) and \\( h \\) coincide at \\( \\beta \\), which in turn implies that \\( f \\) is single-valued at \\( \\beta \\).\n\n  Therefore, \\fullref{thm:omega_induction} allows us to conclude that \\( f \\) is a single-valued total function.\n\n  \\SubProofOf[def:function]{uniqueness} Now that it is clear that \\( f \\) satisfies the theorem, we must verify that it is unique.\n\n  Suppose that \\( f_1 \\) and \\( f_2 \\) both satisfy the theorem. Fix some \\( \\beta \\in \\alpha \\) and suppose that for every \\( \\gamma < \\beta \\), we have \\( f_1(\\gamma) = f_2(\\gamma) \\). Then\n  \\begin{equation*}\n    f_2(\\beta) = T(f_1\\restr_\\beta)) = T(f_2\\restr_\\beta) = f_2(\\beta).\n  \\end{equation*}\n\n  Therefore, \\fullref{thm:omega_induction} allows us to conclude that \\( f_1 = f_2 \\). So there is at most one function that satisfies the theorem and we have already shown that \\( f \\) is such a function.\n\\end{proof}\n\n\\begin{theorem}[Transfinite induction]\\label{thm:transfinite_induction}\\mcite[thm. 63.15]{OpenLogicFull}\n  It turns out that \\fullref{thm:bounded_transfinite_recursion} is valid for all ordinals simultaneously.\n\n  For every formula \\( \\varphi \\) in the language of set theory not containing \\( \\eta \\) nor \\( \\zeta \\) as free variables, the following is a theorem of \\logic{ZFC}:\n  \\small\n  \\begin{equation*}\n    \\qforall \\eta\n    \\parens[\\Bigg]\n      {\n        \\ref{eq:def:ordinal/predicate}[\\eta]\n        \\rightarrow\n        \\parens[\\Big]\n        {\n          \\overbrace\n            {\n              \\underbrace{ \\parens[\\Big] { \\qforall {\\zeta \\in \\eta} \\varphi[\\xi \\mapsto \\zeta] } }_{\\mathclap{\\substack{\\T{inductive} \\\\ \\T{hypothesis}}}}\n              \\rightarrow\n              \\underbrace{ \\varphi[\\xi \\mapsto \\eta] }_{\\mathclap{\\substack{\\T{inductive step} \\\\ \\T{conclusion}}}}\n            }^{\\T{inductive step}}\n        }\n      }\n    \\rightarrow\n    \\qforall \\eta \\parens[\\Bigg]\n    {\n      \\ref{eq:def:ordinal/predicate}[\\eta]\n      \\rightarrow\n      \\underbrace{ \\varphi[\\xi \\mapsto \\eta] }_{\\T{conclusion}}\n    }.\n  \\end{equation*}\n  \\normalsize\n\n  This theorem could be a special case of \\fullref{thm:bounded_transfinite_recursion}, but there exists no set of all ordinals due to \\fullref{thm:burali_forti_paradox}.\n\n  See the comments in \\fullref{def:peano_arithmetic/PA3} regarding variables and quantification in axiom schemas and \\fullref{rem:induction} for a general discussion of induction.\n\n  See \\fullref{rem:transfinite_induction} about a reformulation that is often useful in practice.\n\\end{theorem}\n\\begin{proof}\n  The proof is similar to the proof of \\fullref{thm:well_founded_induction}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinals_are_well_ordered}\n  The ordinals are \\hyperref[def:well_ordered_set]{well-ordered}. Since there exists no set of all ordinals due to \\fullref{thm:burali_forti_paradox}, we cannot say that the ordinals form a well-ordered set. We will instead state a more concrete result.\n\n  \\begin{thmenum}\n    \\thmitem{thm:ordinals_are_well_ordered/transitivity} For any three ordinals \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) such that \\( \\alpha < \\beta < \\gamma \\) we have \\( \\alpha < \\gamma \\).\n\n    \\thmitem{thm:ordinals_are_well_ordered/trichotomy} For any two ordinals \\( \\alpha \\) and \\( \\beta \\), exactly one of \\( \\alpha = \\beta \\), \\( \\alpha < \\beta \\) or \\( \\alpha > \\beta \\) holds.\n  \\end{thmenum}\n\n  As discussed in \\fullref{def:ordinal}, irreflexivity and well-foundedness hold by \\fullref{thm:set_membership_is_well_founded}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:ordinals_are_well_ordered/transitivity} Let \\( \\alpha \\), \\( \\beta \\) and \\( \\gamma \\) be ordinals and let \\( \\alpha \\in \\beta \\in \\gamma \\). Since \\( \\gamma \\) is a transitive set, it follows that \\( \\beta \\subseteq \\gamma \\) and thus \\( \\alpha \\in \\gamma \\).\n\n  Therefore, we have used the fact that \\( \\gamma \\) is a transitive set to prove that set membership is a transitive relation, thus obtaining a connection between two distinct concepts both named \\enquote{transitivity}.\n\n  \\SubProofOf{thm:ordinals_are_well_ordered/trichotomy} Let \\( \\alpha \\) and \\( \\beta \\) be ordinals.\n\n  Due to \\fullref{thm:simple_foundation_theorems/member_of_itself}, it is not possible for both \\( \\alpha \\in \\beta \\) and \\( \\alpha = \\beta \\) to hold simultaneously. Due to \\fullref{thm:simple_foundation_theorems/mutual_membership}, it is not possible for both \\( \\alpha \\in \\beta \\) and \\( \\beta \\in \\alpha \\) to hold simultaneously.\n\n  Thus, at most one of \\( \\alpha = \\beta \\), \\( \\alpha \\in \\beta \\) or \\( \\beta \\in \\alpha \\) holds.\n\n  We will use \\fullref{thm:transfinite_induction} on \\( \\beta \\) to show that at least one of them holds. Fix an ordinal \\( \\beta_0 \\). Our inductive hypothesis is that for every ordinal \\( \\alpha \\) and every \\( \\gamma \\in \\beta_0 \\) at least one of \\( \\alpha = \\gamma \\), \\( \\alpha \\in \\gamma \\) or \\( \\gamma \\in \\alpha \\) holds.\n\n  Fix some ordinal \\( \\alpha_0 \\). We will show that at least one of \\( \\alpha_0 = \\beta_0 \\), \\( \\alpha_0 \\in \\beta_0 \\) or \\( \\beta_0 \\in \\alpha_0 \\) holds. Since the case \\( \\beta_0 = \\alpha_0 \\) is trivial, we exclude it from consideration.\n\n  \\begin{itemize}\n    \\item If there exists \\( \\gamma \\in \\beta_0 \\) such that \\( \\gamma = \\alpha_0 \\), clearly \\( \\alpha_0 \\in \\beta_0 \\).\n    \\item If there exists \\( \\gamma \\in \\beta_0 \\) such that \\( \\alpha_0 \\in \\gamma \\), then by transitivity \\( \\alpha_0 \\in \\beta_0 \\).\n    \\item If for every \\( \\gamma \\in \\beta_0 \\) we have \\( \\gamma \\in \\alpha_0 \\), then \\( \\beta_0 \\subsetneq \\alpha_0 \\). Let \\( \\gamma_0 \\) be the smallest member of \\( \\alpha_0 \\setminus \\beta_0 \\). We will show that \\( \\gamma_0 = \\beta_0 \\).\n\n    Our first goal is to show that \\( \\gamma_0 \\subseteq \\beta_0 \\). Aiming at a contradiction, suppose that there exists some \\( \\lambda \\in \\gamma_0 \\setminus \\beta \\). Since \\( \\gamma_0 \\) is a transitive set, we have \\( \\lambda \\in \\alpha \\). Thus, \\( \\lambda \\in \\alpha \\setminus \\beta \\) and \\( \\lambda \\in \\gamma_0 \\), contradicting the minimality of \\( \\gamma_0 \\). Therefore, \\( \\gamma_0 \\subseteq \\beta \\).\n\n    Now we will use the existing inductive hypothesis for \\( \\alpha = \\gamma_0 \\) to show that \\( \\beta_0 \\subseteq \\gamma_0 \\).\n\n    \\begin{itemize}\n      \\item If there exists \\( \\lambda \\in \\beta_0 \\) such that \\( \\lambda = \\gamma_0 \\), clearly \\( \\gamma_0 \\in \\beta_0 \\). But that contradicts our choice of \\( \\gamma_0 \\) as a member of \\( \\alpha_0 \\setminus \\beta_0 \\).\n\n      \\item If there exists \\( \\lambda \\in \\beta_0 \\) such that \\( \\gamma_0 \\in \\lambda \\), then by transitivity \\( \\gamma_0 \\in \\beta_0 \\), which again contradicts our choice of \\( \\gamma_0 \\).\n\n      \\item Finally, if for every \\( \\gamma \\in \\beta_0 \\) we have \\( \\gamma \\in \\gamma_0 \\), then \\( \\beta_0 \\subseteq \\gamma_0 \\).\n    \\end{itemize}\n\n    Thus, both \\( \\gamma_0 \\subseteq \\beta_0 \\) and \\( \\beta_0 \\subseteq \\gamma_0 \\), giving us the equality \\( \\beta_0 = \\gamma_0 \\). This allows us to conclude that \\( \\beta_0 \\in \\alpha_0 \\).\n  \\end{itemize}\n\n  We have shown by transfinite induction that for a fixed ordinal \\( \\beta_0 \\), for every other ordinal \\( \\alpha \\) at least one of \\( \\beta_0 = \\alpha \\), \\( \\beta_0 \\in \\alpha \\) or \\( \\alpha \\in \\beta_0 \\) holds. We have already shown that at most one of the three holds, hence exactly one of the three holds.\n\n  Since \\( \\beta_0 \\) is itself arbitrary, we can conclude that trichotomy holds for any two ordinals \\( \\alpha \\) and \\( \\beta \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinal_ordering_via_subsets}\n  For any two ordinals \\( \\alpha \\) and \\( \\beta \\) we have \\( \\beta \\in \\alpha \\) if and only if \\( \\beta \\subsetneq \\alpha \\).\n\\end{proposition}\n\\begin{proof}\n  \\NecessitySubProof Since \\( \\alpha \\) is a transitive set, from \\( \\beta \\in \\alpha \\) it follows that \\( \\beta \\subseteq \\alpha \\).\n\n  We cannot have \\( \\beta = \\alpha \\) due to \\fullref{thm:simple_foundation_theorems/member_of_itself}, hence \\( \\beta \\subsetneq \\alpha \\).\n\n  \\SufficiencySubProof Suppose that \\( \\beta \\subsetneq \\alpha \\).\n\n  By \\fullref{thm:ordinals_are_well_ordered/trichotomy}, the ordinals \\( \\beta \\) and \\( \\alpha \\) must be related by set membership.\n  \\begin{itemize}\n    \\item If \\( \\alpha = \\beta \\), this directly contradicts our assumption that \\( \\beta \\subsetneq \\alpha \\).\n    \\item If \\( \\alpha \\in \\beta \\), then \\( \\alpha \\in \\alpha \\) which contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n    \\item It remains for \\( \\beta \\in \\alpha \\) to hold.\n  \\end{itemize}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinal_successor_strictly_monotone_on_ordinals}\n  The ordinal successor operation is strictly monotone on ordinals. That is, if \\( \\alpha < \\beta \\), then \\( \\op{succ}(\\alpha) < \\op{succ}(\\beta) \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\alpha \\in \\beta \\) and let \\( \\gamma \\in \\op{succ}(\\alpha) \\).\n  \\begin{itemize}\n    \\item If \\( \\gamma \\in \\alpha \\), clearly \\( \\gamma \\in \\beta \\) because \\( \\beta \\) is a transitive set.\n\n    \\item If \\( \\gamma = \\alpha \\), then \\( \\gamma = \\alpha \\in \\beta \\).\n  \\end{itemize}\n\n  We have shown that \\( \\op{succ}(\\alpha) \\subseteq \\beta \\). Thus, we either have \\( \\op{succ}(\\alpha) = \\beta \\in \\op{succ}(\\beta) \\) or else by \\fullref{thm:ordinal_ordering_via_subsets} we have \\( \\op{succ}(\\alpha) \\in \\beta \\in \\op{succ}(\\beta) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:transitive_set_of_transitive_sets}\\mcite{MathSE:transitive_set_of_transitive_sets}\n  A \\hyperref[def:transitive_set]{transitive set} whose members are transitive sets is an ordinal.\n\n  In particular, a transitive set of ordinals is an ordinal. If a set of ordinals is not transitive, we can instead take its \\hyperref[def:transitive_closure_of_a_set]{transitive closure}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( A \\) be a set whose members are themselves transitive sets.\n\n  We will first show that set membership is transitive on \\( A \\). If \\( x \\), \\( y \\) and \\( z \\) are members of \\( A \\) such that \\( x \\in y \\in z \\), then since \\( z \\) is transitive we have \\( y \\subseteq z \\) and thus \\( x \\in z \\).\n\n  Therefore, we can conclude that set membership is a \\hyperref[def:partially_ordered_set/strict]{strict partial order} on \\( A \\). Now define the set\n  \\begin{equation*}\n    B \\coloneqq \\set{ x \\in A \\given \\qexists {y \\in A} x \\not\\in y \\wedge y \\not\\in x }\n  \\end{equation*}\n  of all members of \\( A \\) which are not related to at least one other member. If \\( B \\) is empty, then set membership is trichotomous on \\( A \\).\n\n  If \\( B \\) is nonempty, let \\( b \\) be a minimal element of \\( B \\). A minimal element must exist by \\fullref{thm:infinite_descent_partial_order} because set membership is a well-founded partial order on \\( A \\). We have chosen \\( b \\), so that every member of \\( b \\) is related to every other member of \\( A \\).\n\n  Define the set\n  \\begin{equation*}\n    C \\coloneqq \\set{ x \\in A \\given x \\neq b \\wedge x \\not\\in b \\wedge b \\not\\in x }\n  \\end{equation*}\n  of all members of \\( A \\) which are not related to \\( b \\) and let \\( c \\) be a minimal element of \\( C \\). We will now show that \\( b = c \\), which is a contradictions with our choice of \\( c \\).\n\n  Let \\( x \\in b \\). As we have already mentioned, \\( x \\) is related to every other member of \\( A \\), including \\( c \\).\n  \\begin{itemize}\n    \\item If \\( c = x \\), then \\( c \\in b \\), which contradicts our choice of \\( c \\).\n\n    \\item Suppose that \\( c \\in x \\). We have chosen \\( x \\) to be a member of \\( b \\) and we thus have \\( c \\in x \\in b \\). The set \\( b \\) is transitive as a member of \\( A \\), hence \\( x \\) is also a member of \\( A \\). Since set membership is a transitive relation on \\( A \\), it follows that \\( c \\in b \\), which contradicts our choice of \\( c \\).\n\n    \\item It remains for \\( x \\in c \\) to hold.\n  \\end{itemize}\n\n  Therefore, \\( b \\subseteq c \\). The converse inclusion \\( c \\subseteq b \\) can be obtained analogously by noting that \\( c \\) is a minimal element of \\( C \\) and hence every \\( x \\in c \\) is related to \\( b \\). Thus, we obtain \\( b = c \\), which contradicts our choice of \\( c \\) as a member of \\( C \\).\n\n  The obtained contradiction shows that the set \\( B \\) is empty and thus every member of \\( A \\) is related to every other member, proving trichotomy of set membership on \\( A \\). This allows us to conclude that \\( A \\) is an ordinal because it is a transitive set and we have already shown in the beginning of the proof that set membership is a transitive relation on \\( A \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:transitive_closure_of_a_set}\\mcite[def. 64.8]{OpenLogicFull}\n  To show that every set has a rank we must introduce additional definitions. We use \\hyperref[rem:natural_number_recursion]{natural number recursion} to define the \\term{transitive closure} of a set \\( A \\) as\n  \\begin{equation*}\n    \\cl^T(A) \\coloneqq \\bigcup \\set{ \\cl_n^T(A) \\given n \\in \\omega },\n  \\end{equation*}\n  where\n  \\begin{equation*}\n    \\cl_n^T(A) \\coloneqq \\begin{cases}\n      A,              &n = 0 \\\\\n      \\bigcup \\cl_{n-1}^T(A), &n > 0\n    \\end{cases}\n  \\end{equation*}\n\n  Note that this is different from the transitive closure of a relation defined in \\fullref{def:relation_closures/transitive}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:transitive_closure_of_a_set}\\mcite[thm. 64.9]{OpenLogicFull}\n  The \\hyperref[def:transitive_closure_of_a_set]{transitive closure} \\( \\cl^T(A) \\) of the set \\( A \\) is the smallest transitive set containing \\( A \\).\n\\end{proposition}\n\\begin{proof}\n  It is clear that \\( A = \\cl_0^T(A) \\) is a subset of \\( \\cl^T(A) \\).\n\n  If \\( x \\in \\cl^T(A) \\), then there exists some natural number \\( n \\) for which \\( x \\in \\cl_n^T(A) \\). Therefore, \\( x \\subseteq \\bigcup \\cl_n^T(A) = \\cl_{n+1}^T(A) \\) and thus \\( x \\subseteq \\cl^T(A) \\).\n\n  Now suppose that \\( B \\) is a transitive subset of \\( \\cl^T(A) \\) which contains \\( A \\). Let \\( x_0 \\in \\cl^T(A) \\).\n\n  Suppose that \\( x_0 \\not\\in B \\). Then there must exist a smallest nonzero number \\( n \\) such that \\( x_0 \\in \\cl_n^T(A) \\). Then \\( x_0 \\) belongs to some member \\( x_1 \\) of \\( \\cl_{n-1}^T(A) \\). If \\( x_1 \\in A \\), then \\( x_0 \\) must belong to \\( B \\) since it is transitive. But this contradicts out choice of \\( x_0 \\). Then \\( x_1 \\not\\in A \\), in which case there exists some \\( x_2 \\in \\cl_{n-2}^T(A) \\) such that \\( x_1 \\in x_2 \\). If \\( x_2 \\in A \\), then again \\( x_0 \\in B \\), which contradicts our choice of \\( x_0 \\). We can thus recursively construct a sequence \\( \\set{ x_k }_{k=0}^\\infty \\) such that for every \\( k \\geq 0 \\) both \\( x_k \\in x_{k+1} \\) and \\( x_k \\not\\in A \\) hold. The existence of such a sequence contradicts \\fullref{thm:set_membership_is_well_founded}.\n\n  Therefore, \\( \\cl^T(A) \\subseteq B \\), hence \\( \\cl^T(A) \\) is the smallest transitive set containing \\( A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ordinal_is_set_of_smaller_ordinals}\n  Every ordinal equals the set of all smaller ordinals.\n\n  This is the unbounded version of \\fullref{thm:initial_segment_of_ordinal}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\alpha \\) be an ordinal and let \\( A \\) be the set of all ordinals smaller than \\( \\alpha \\). We will show that \\( A = \\alpha \\). We will first show that \\( A \\) is a transitive set. Let \\( \\beta \\in A \\) and \\( \\gamma \\in \\beta \\). Since \\( \\alpha \\) is a transitive set that contains \\( \\beta \\), we have \\( \\gamma \\in \\alpha \\). Thus, \\( \\gamma \\) is smaller than \\( \\alpha \\) and hence it belongs to \\( A \\). Therefore, \\( A \\) is a transitive set of ordinals and by \\fullref{thm:transitive_set_of_transitive_sets}, it is itself an ordinal.\n\n  \\Fullref{thm:ordinals_are_well_ordered} implies that \\( \\alpha \\) and \\( A \\) are either equal or related by set membership.\n  \\begin{itemize}\n    \\item If \\( \\alpha \\in A \\), then \\( \\alpha \\) is smaller than itself, which contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n\n    \\item If \\( A \\in \\alpha \\), then \\( A \\) is smaller than itself, which again contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n\n    \\item It remains for \\( A \\) to be equal to \\( \\alpha \\).\n  \\end{itemize}\n\\end{proof}\n\n\\begin{theorem}[Burali-Forti paradox]\\label{thm:burali_forti_paradox}\\mcite[thm. 63.19]{OpenLogicFull}\n  Assuming \\logic{ZFC}, there is no set of all ordinals.\n\\end{theorem}\n\\begin{proof}\n  Aiming at a contradiction, suppose that \\( A \\) is a containing all ordinals. If \\( \\alpha \\in A \\) and \\( \\beta \\in \\alpha \\), transitivity \\( \\beta \\) implies \\( \\beta \\in A \\). Thus, \\( A \\) is a transitive set of ordinals, which \\fullref{thm:transitive_set_of_transitive_sets} is itself an ordinal. Hence, \\( A \\in A \\).\n\n  But this contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}. Hence, there is no set of all ordinals.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:union_of_set_of_ordinals}\\mcite{MathSE:union_of_set_of_ordinals}\n  Let \\( A \\) be a set of ordinals and denote \\( \\alpha \\coloneqq \\bigcup A \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:union_of_set_of_ordinals/is_ordinal} The union \\( \\alpha \\) is itself an ordinal.\n\n    \\thmitem{thm:union_of_set_of_ordinals/supremum} The union \\( \\alpha \\), which is the \\hyperref[def:partially_ordered_set_extremal_points/supremum_and_infimum]{supremum} of \\( A \\) with respect to set inclusion, is also the supremum of \\( A \\) with respect to ordinal ordering.\n\n    That is, either \\( \\alpha = A \\) or \\( \\alpha \\) is the smallest ordinal that is larger than every member of \\( A \\).\n\n    \\thmitem{thm:union_of_set_of_ordinals/ordinal} If \\( A \\) is an ordinal, then \\( \\alpha \\leq A \\). Furthermore, in the case \\( \\alpha < A \\), there is no ordinal between \\( A \\) and \\( \\alpha \\). That is, if \\( \\alpha < A \\), then \\( A \\) is the smallest ordinal strictly larger than \\( \\alpha \\).\n\n    See \\fullref{def:successor_and_limit_ordinal/union} for a further distinction between \\( \\alpha = A \\) and \\( \\alpha < A \\).\n  \\end{thmenum}\n\n  For recursive definitions like \\fullref{def:ordinal_arithmetic/addition} this proposition justifies using \\( \\sup A \\) instead of the more confusing \\( \\bigcup A \\).\n\n  Compare this result to \\fullref{thm:union_of_set_of_cardinals}.\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:union_of_set_of_ordinals/is_ordinal} Let \\( A \\) be a set of ordinals. Denote its union by \\( \\alpha \\coloneqq \\bigcup A \\).\n\n  We will show that \\( \\alpha \\) is a transitive set. Due to \\fullref{thm:transitive_set_of_transitive_sets}, this is sufficient for \\( \\alpha \\) to be an ordinal.\n\n  Let \\( \\beta \\in \\alpha \\). Then there exists an ordinal \\( \\gamma \\) in \\( A \\) such that \\( \\beta \\in \\gamma \\). Since \\( \\gamma \\) is itself a transitive set, we have \\( \\beta \\subseteq \\gamma \\). But \\( \\gamma \\subseteq \\alpha \\), hence \\( \\beta \\subseteq \\alpha \\).\n\n  Therefore, \\( \\alpha = \\bigcup A \\) is a transitive set and thus an ordinal.\n\n  \\SubProofOf{thm:union_of_set_of_ordinals/supremum} For every \\( \\beta \\in A \\) we have \\( \\beta \\subseteq \\alpha \\), which by \\fullref{thm:ordinal_ordering_via_subsets} corresponds to \\( \\beta \\leq \\alpha \\) with respect to ordinal ordering.\n\n  We will show that \\( \\alpha \\) is the smallest ordinal with this property. Let \\( \\lambda_0 \\) be any other ordinal such that \\( \\gamma \\leq \\lambda_0 \\) for any \\( \\gamma \\in A \\). Fix some \\( \\gamma_0 \\in \\alpha \\). Then there exists an ordinal \\( \\beta_0 \\in A \\) such that \\( \\gamma_0 \\in \\beta_0 \\). Since \\( \\beta_0 \\in A \\) and \\( A \\subseteq \\lambda_0 \\), since \\( \\lambda_0 \\) itself is a transitive set we have \\( \\gamma_0 \\in \\lambda_0 \\).\n\n  Therefore, \\( \\alpha \\) is the least upper bound of \\( A \\) with respect to ordinal ordering.\n\n  \\SubProofOf{thm:union_of_set_of_ordinals/ordinal} Assume that \\( A \\) is an ordinal.\n\n  If \\( \\gamma \\in \\alpha \\), by transitivity of \\( \\alpha \\) we have \\( \\gamma \\subseteq \\alpha \\). Thus, \\( \\gamma \\in A \\). Hence, \\( \\alpha \\subseteq A \\).\n\n  Now suppose that there exists some \\( \\gamma \\in A \\) such that \\( \\alpha \\in \\gamma \\). Then\n  \\begin{equation*}\n    \\gamma \\subseteq \\bigcup A = \\alpha \\in \\gamma,\n  \\end{equation*}\n  which contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n\n  Hence, there is not ordinal between \\( \\alpha = \\bigcup A \\) and \\( A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:successor_of_ordinal}\n  The \\hyperref[def:ordinal_successor]{successor} \\( \\alpha \\coloneqq \\op{succ}(\\beta) \\) of an ordinal \\( \\beta \\) is the smallest ordinal larger than \\( \\alpha \\).\n\\end{proposition}\n\\begin{proof}\n  We must show that \\( \\alpha \\) is a transitive set and thus by \\fullref{thm:transitive_set_of_transitive_sets} an ordinal. Note that \\( \\alpha = \\op{succ}(\\beta) = \\beta \\cup \\set{ \\beta } \\).\n\n  Let \\( \\gamma \\in \\alpha \\).\n  \\begin{itemize}\n    \\item If \\( \\gamma \\in \\beta \\), then since \\( \\beta \\) is a transitive set, we have \\( \\gamma \\subseteq \\beta \\). Furthermore, since \\( \\beta \\subseteq \\alpha \\), by transitivity of set inclusion \\( \\gamma \\subseteq \\alpha \\).\n\n    \\item If \\( \\gamma = \\beta \\), then \\( \\gamma \\subseteq \\alpha \\) by definition of successor.\n  \\end{itemize}\n\n  Therefore, \\( \\alpha \\) is a transitive set and thus an ordinal.\n\n  Now suppose that there is another ordinal \\( \\gamma \\) such that \\( \\beta \\in \\gamma \\in \\alpha = \\beta \\cup \\set{ \\beta } \\).\n  \\begin{itemize}\n    \\item If \\( \\gamma \\in \\beta \\), this would contradict \\fullref{thm:simple_foundation_theorems/mutual_membership}.\n\n    \\item If \\( \\gamma = \\beta \\), this would contradict \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n  \\end{itemize}\n\n  The obtained contradictions show that there is no ordinal between \\( \\alpha \\) and \\( \\beta \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:def:ordinal_successor}\n  It follows from \\fullref{thm:ordinal_is_set_of_smaller_ordinals} and \\fullref{thm:successor_of_ordinal} and that for any ordinal \\( \\beta \\) we have\n  \\begin{align*}\n    \\beta            &= \\set{ \\gamma \\given \\gamma \\T{is an ordinal and} \\gamma < \\beta }, \\\\\n    \\op{succ}(\\beta) &= \\set{ \\gamma \\given \\gamma \\T{is an ordinal and} \\gamma \\leq \\beta }.\n  \\end{align*}\n\n  This shows that the \\hyperref[def:ordinal_successor]{ordinal successor} operation is very natural in the context of ordinals.\n\\end{remark}\n\n\\begin{definition}\\label{def:successor_and_limit_ordinal}\n  We say that the ordinal \\( \\alpha \\) is a \\term{successor ordinal} if any of the following equivalent conditions hold:\n\n  \\begin{thmenum}\n    \\thmitem{def:successor_and_limit_ordinal/successor} The ordinal \\( \\alpha \\) is the successor of another ordinal. That is, there exists another ordinal \\( \\beta \\) such that \\( \\alpha = \\op{succ}(\\beta) \\).\n\n    \\thmitem{def:successor_and_limit_ordinal/smaller_successor} There exists some \\( \\beta \\in \\alpha \\) such that \\( \\op{succ}(\\beta) \\) does not belong to \\( \\alpha \\).\n\n    \\thmitem{def:successor_and_limit_ordinal/union} We have \\( \\bigcup \\alpha \\in \\alpha \\).\n  \\end{thmenum}\n\n  If \\( \\alpha \\) is neither zero nor a successor ordinal, we call it a \\term{limit ordinal}. See \\fullref{thm:limit_ordinal_order_topology} for a more involved equivalent condition.\n\n  These notions should not be confused with \\hyperref[def:successor_and_limit_cardinal]{successor and weak/strong limit cardinals}.\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:successor_and_limit_ordinal/successor}{def:successor_and_limit_ordinal/smaller_successor} If \\( \\alpha = \\op{succ}(\\beta) \\), then \\( \\beta \\) satisfies \\fullref{def:successor_and_limit_ordinal/smaller_successor}.\n\n  \\ImplicationSubProof{def:successor_and_limit_ordinal/smaller_successor}{def:successor_and_limit_ordinal/successor} Let \\( \\beta \\in \\alpha \\) be such that \\( \\op{succ}(\\beta) \\not\\in \\alpha \\). Then by trichotomy we have that either \\( \\op{succ}(\\beta) = \\alpha \\) or \\( \\op{succ}(\\beta) > \\alpha \\).\n\n  If \\( \\op{succ}(\\beta) > \\alpha \\), then either \\( \\alpha = \\beta \\), which would contradict \\fullref{thm:simple_foundation_theorems/member_of_itself}, or \\( \\alpha \\in \\beta \\), which would contradict \\fullref{thm:simple_foundation_theorems/mutual_membership}.\n\n  Thus, it remains for \\( \\op{succ}(\\beta) \\) to be equal to \\( \\alpha \\).\n\n  \\ImplicationSubProof{def:successor_and_limit_ordinal/successor}{def:successor_and_limit_ordinal/union} Suppose that \\( \\alpha = \\op{succ}(\\beta) \\).\n\n  We have\n  \\begin{balign*}\n    \\bigcup \\alpha\n    &=\n    \\bigcup (\\beta \\cup \\set{ \\beta })\n    = \\\\ &=\n    \\set{ \\gamma \\given \\qexists \\delta (\\delta \\in \\beta \\T{or} \\delta = \\beta) \\T{and} \\gamma \\in \\delta }\n    \\reloset {\\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join}} = \\\\ &=\n    \\set{ \\gamma \\given \\qexists \\delta (\\delta \\in \\beta \\T{and} \\gamma \\in \\delta) \\T{or} (\\delta = \\beta \\T{and} \\gamma \\in \\delta }\n    = \\\\ &=\n    \\set*{ \\gamma \\given* \\parens[\\Big]{ \\qexists {\\delta \\in \\beta} \\gamma \\in \\delta } \\T{or} \\gamma \\in \\beta }\n    = \\\\ &=\n    \\parens*{ \\bigcup \\beta } \\cup \\beta\n    \\reloset{ \\bigcup \\beta \\subseteq \\beta } = \\\\ &=\n    \\beta.\n  \\end{balign*}\n\n  Thus, \\( \\beta = \\bigcup \\alpha \\in \\alpha \\).\n\n  \\ImplicationSubProof{def:successor_and_limit_ordinal/union}{def:successor_and_limit_ordinal/successor} Let \\( \\bigcup \\alpha \\in \\alpha \\). From \\fullref{rem:def:ordinal_successor} we have that\n  \\begin{equation*}\n    \\op{succ}\\parens*{ \\bigcup \\alpha }\n    =\n    \\set*{ \\gamma \\given* \\gamma \\subseteq \\bigcup \\alpha }\n    =\n    \\set{ \\gamma \\given \\gamma \\subsetneq \\alpha }\n    =\n    \\alpha.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{remark}\\label{rem:transfinite_induction}\n  It is sometimes efficient to reformulate transfinite induction and recursion. Although analogous principles hold for \\fullref{thm:bounded_transfinite_induction} and \\fullref{thm:bounded_transfinite_recursion}, we will only demonstrate them for \\fullref{thm:transfinite_induction}. The original statement is that in order to prove that some formula is satisfied for all sets, it is sufficient to only prove one inductive step.\n\n  More precisely, let \\( \\varphi \\) be a formula in the language of set theory, let \\( \\mscrV = (V, I) \\) be a \\hyperref[rem:standard_model_of_set_theory]{standard} \\hyperref[rem:transitive_model_of_set_theory]{transitive} model of set theory and let \\( v: \\boldop{Var} \\to V \\) be some variable assignment. This allows us to fix any parameters that would otherwise be present in the induction schema. We will say that the set \\( A \\) satisfies \\( \\varphi \\) if \\( \\Bracks{v_{\\xi \\mapsto A}} = T \\).\n\n  \\Fullref{thm:transfinite_induction} states that in order to prove that \\( \\varphi \\) holds for any ordinal, the following is sufficient:\n  \\begin{thmenum}[series=rem:transfinite_induction]\n    \\thmitem{rem:transfinite_induction/single_inductive_step} For every ordinal \\( \\alpha \\), by assuming that every smaller ordinal satisfies \\( \\varphi \\), we must prove that \\( \\alpha \\) does.\n  \\end{thmenum}\n\n  We have just defined in \\fullref{def:successor_and_limit_ordinal} three mutually exclusive types of ordinals. We can now restate the principles of transfinite induction as follows:\n  \\begin{thmenum}[resume=rem:transfinite_induction]\n    \\thmitem{rem:transfinite_induction/base_case} In the \\term{base case}, we must prove that \\( 0 \\) satisfies \\( \\varphi \\).\n\n    \\thmitem{rem:transfinite_induction/successor_case} In the \\term{successor case}, by assuming that \\( \\alpha \\) satisfies \\( \\varphi \\), we must prove that \\( \\op{succ}(\\alpha) \\) does. It is in line with \\fullref{thm:transfinite_induction} assume that every ordinal smaller that or equal to \\( \\alpha \\) satisfies \\( \\varphi \\), however it is often enough to do, so only for \\( \\alpha \\) itself.\n\n    \\thmitem{rem:transfinite_induction/limit_case} In the \\term{limit case}, if \\( \\lambda \\) is a limit ordinal, by assuming that every smaller ordinal satisfies \\( \\varphi \\) we must prove that \\( \\lambda \\) satisfies \\( \\varphi \\).\n  \\end{thmenum}\n\n  We must note that \\fullref{rem:transfinite_induction/limit_case} is essentially the same as the single inductive step \\fullref{rem:transfinite_induction/single_inductive_step} except that it is restricted to limit ordinals. The reasoning for this is that the proofs for zero and every successor ordinal can be different from those for limit ordinals.\n\n  See \\fullref{thm:ordinal_bijection_and_choice} and \\fullref{def:cumulative_hierarchy} for concrete examples.\n\\end{remark}\n\n\\begin{theorem}[Structural recursion]\\label{thm:structural_recursion}\\mimprovised\n  The most general recursion principle we will consider is \\term{structural recursion}. It is sometimes also called \\term{mutual recursion}. See \\fullref{thm:well_founded_induction} for its corresponding induction principle.\n\n  Let \\( X \\) be a set and let \\( T: \\pow(X) \\to \\pow(X) \\) be a transformation. Then \\( T \\) has a \\hyperref[def:partially_ordered_set_extremal_points/maximum_and_minimum]{smallest} \\hyperref[def:fixed_point]{fixed point}. That is, there exists a unique subset \\( A_0 \\subseteq X \\) such that \\( T(A_0) = A_0 \\) and no proper subset of \\( A_0 \\) has this property.\n\n  See \\fullref{rem:structural_recursion_and_induction} for how this theorem is used.\n\\end{theorem}\n\\begin{proof}\n  The result follows by applying \\fullref{thm:knaster_tarski_theorem} to the \\hyperref[thm:boolean_algebra_of_subsets]{Boolean algebra of all subsets} of \\( X \\) with \\( R(A) \\coloneqq A \\cup T(A) \\) as the monotone operator.\n\\end{proof}\n\n\\begin{remark}\\label{rem:structural_recursion_and_induction}\\mimprovised\n  We will now show the connection between \\fullref{thm:well_founded_induction} and \\fullref{thm:structural_recursion}.\n\n  Let \\( \\mscrF \\) be a set of functions, where each function \\( f \\) has a signature \\( f: X^{\\#f} \\to X \\) for some nonnegative integer \\( \\#f \\). Define the operator\n  \\begin{equation*}\n    \\begin{aligned}\n      &T: \\pow(X) \\to \\pow(X) \\\\\n      &T(A) \\coloneqq \\set*{ x \\in X \\given[\\Big] \\qexists{f \\in \\mscrF} \\qexists{t_1, \\ldots, t_{\\#f} \\in A_0} f(t_1, \\ldots, t_{\\#f}) = x }.\n    \\end{aligned}\n  \\end{equation*}\n\n  Now we can use \\fullref{thm:structural_recursion} to obtain the smallest fixed point \\( A_0 \\) of \\( T \\). The set \\( A_0 \\) is closed under all the functions in \\( \\mscrF \\), i.e. \\( f\\bracks*{ A_0^{\\#f} } \\subseteq A_0 \\) for any \\( f \\in \\mscrF \\).\n\n  Define a binary relation \\( \\to \\) on \\( A_0 \\) by declaring that, for every function \\( f \\) in \\( \\mscrF \\), every sequence \\( x_1, \\ldots, x_{\\#f} \\) and every index \\( k = 1, \\ldots, \\#f \\), we have\n  \\begin{equation*}\n    x_k \\to f(x_1, \\ldots, x_{\\#f}).\n  \\end{equation*}\n\n  This relation can be defined by taking unions of smaller relations rather than via recursion.\n\n  If the \\hyperref[def:quiver]{quiver} happens to be \\hyperref[def:well_founded_relation]{well-founded}, we can use \\fullref{thm:well_founded_induction} to prove universal statements about \\( A_0 \\).\n\n  In \\fullref{subsec:first_order_satisfiability}, for example, we use structural recursion to define first-order substitution in \\fullref{def:first_order_substitution} and then use structural induction to prove certain semantic equivalences like \\fullref{thm:renaming_assignment_compatibility} and \\fullref{thm:first_order_substitution_equivalence}.\n\\end{remark}\n\n\\begin{remark}\\label{rem:induction}\n  \\term{Mathematical induction} is a very valuable proof technique for universal statements. The proof of \\fullref{thm:nonzero_natural_numbers_have_predecessors} contains remarks regarding its usage and its difference from deduction principles that are formalized via \\hyperref[def:deductive_system]{deductive systems}. Although it is a logical tool, this remark belongs to this section because it contains several induction and recursion principles.\n\n  More generally, given a \\hyperref[def:first_order_syntax/formula]{first-order formula} \\( \\varphi \\) over some \\hyperref[def:first_order_syntax]{first-order language}, certain \\hyperref[def:first_order_theory]{logical theories} allow us to prove indirectly \\( \\qforall \\xi \\varphi[\\xi \\mapsto \\eta] \\) by proving simpler statements (\\fullref{def:peano_arithmetic/PA3} contains very important remarks regarding the free variables of \\( \\varphi \\)). This can be done in cases where every \\hyperref[def:first_order_semantics/satisfiability]{model} \\( X = (X, I) \\) of the theory allows us to exhaust its universe \\( X \\) in a small finite number of steps. We can sometimes use the same steps to instead build objects. The latter principles is called \\term{recursion}.\n\n  It should be noted that induction and recursion are used interchangeably in the literature, especially regarding \\hyperref[rem:structural_recursion_and_induction]{structural induction}, however we will aim to distinguish between the two.\n\n  Not much more can be said at this level of generality, so we list several induction principles and give examples of their usage:\n  \\begin{thmenum}\n    \\thmitem{rem:induction/peano_arithmetic} The most basic induction principles is the (weak) natural number induction. It is best described via the axiom schema \\eqref{eq:def:peano_arithmetic/PA3}. \\Fullref{thm:nonzero_natural_numbers_have_predecessors} contains detailed commentary regarding its usage and most of the proofs in \\fullref{subsec:natural_numbers} are performed inductively.\n\n    It its set-theoretic form \\fullref{thm:omega_induction} it is important as a tool for introducing a model of Peano arithmetic. It is used directly for proving \\fullref{thm:omega_is_transitive} and \\fullref{thm:omega_recursion}. It is essentially the same as \\fullref{rem:transfinite_induction} without \\fullref{rem:transfinite_induction/limit_case}.\n\n    \\Fullref{thm:omega_recursion} is an important standalone tool that allows us to perform recursive definitions for natural numbers. The latter is used, often implicitly, in a great variety of places, from the ability to define natural number operations in \\fullref{def:omega_operations} to the definition of magma exponentiation in \\fullref{def:magma/exponentiation}. \\Fullref{rem:natural_number_recursion} contains notes regarding its practical usage.\n\n    \\thmitem{rem:induction/well_founded} A vast generalization of natural number induction is \\fullref{thm:well_founded_induction}. It is stated in a very general setting, but is not frequently used. It can be used to prove \\fullref{thm:epsilon_induction}, which however is even less frequently used. We do not use neither in practice, however the special case where \\( X = \\BbbN \\) is called strong induction on natural numbers.\n\n    The usual (weak) natural number induction which is performed by proving the statement for \\( 0 \\) and then proceeding to prove it for \\( n + 1 \\) by assuming that it holds for \\( n \\). Strong induction instead has no base cases and is performed by proving a statement for \\( n \\) by assuming that it holds for all natural numbers strictly smaller than \\( n \\).\n\n    Well-founded induction and epsilon-induction have no corresponding recursion principle.\n\n    \\thmitem{rem:induction/transfinite} Another vast generalization of natural number induction is \\fullref{thm:bounded_transfinite_induction}, which is further generalized by \\fullref{thm:transfinite_induction}.\n\n    Both principles are used to prove fundamental properties of the ordinals. Outside of set theory, transfinite induction is immensely useful, but it is rarely used directly. Instead, it is usually combined with the \\hyperref[def:zfc/choice]{axiom of choice} via \\fullref{thm:zorns_lemma}. \\Fullref{rem:transfinite_induction} contains notes on how it is used directly.\n\n    Only bounded transfinite induction has a corresponding recursion principle --- \\fullref{thm:bounded_transfinite_recursion}. Unbounded transfinite induction cannot define such a principle because that would easily lead to \\fullref{thm:burali_forti_paradox}. \\Fullref{rem:unbounded_transfinite_recursion} shows how to circumvent this, however.\n\n    Transfinite recursion is used to construct the cumulative hierarchy in \\fullref{def:cumulative_hierarchy}.\n\n    \\Fullref{rem:cardinal_transfinite_recursion_and_induction} provides alternative transfinite recursion and induction principles for cardinals rather than for ordinals.\n\n    \\thmitem{rem:induction/structural} A very general recursion principle is \\fullref{thm:structural_recursion}. Inductive proofs can be performed via \\fullref{thm:well_founded_induction} sometimes --- this is discussed in \\fullref{rem:structural_recursion_and_induction}.\n\n    Within this document, we use \\fullref{thm:structural_induction_on_unambiguous_grammars} in certain special cases, for example \\hyperref[def:propositional_syntax/formula]{propositional} and \\hyperref[def:first_order_syntax/formula]{first-order formulas}.\n  \\end{thmenum}\n\\end{remark}\n\n\\begin{proposition}\\label{thm:ordinal_isomorphism}\n  Two ordinals are equal if and only if they are order-isomorphic.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Trivial.\n\n  \\NecessitySubProof Let \\( \\alpha \\) and \\( \\beta \\) be two ordinals. The case \\( \\alpha = \\beta \\) is clear. Without loss of generality, suppose that \\( \\beta < \\alpha \\). \\Fullref{thm:ordinal_ordering_via_subsets} implies that \\( \\beta \\subsetneq \\alpha \\).\n\n  Let \\( f: \\alpha \\to \\beta \\) be an order isomorphism. Let \\( \\gamma_0 \\) be the smallest value in \\( \\alpha \\setminus \\beta \\).\n\n  From \\fullref{thm:well_ordered_embedding_inflationary} it follows that \\( \\gamma_0 \\leq f(\\gamma_0) \\). But \\( f(\\gamma_0) \\in \\beta \\), hence \\( \\gamma_0 < \\beta \\). But this contradicts our choice of \\( \\gamma_0 \\) as a member of \\( \\alpha \\setminus \\beta \\).\n\n  Therefore, \\( \\gamma_0 \\in \\beta \\). Since \\( \\gamma_0 \\) was arbitrary, we conclude that \\( \\beta < \\alpha \\) leads to a contradiction.\n\n  We can obtain an analogous contradiction for \\( \\alpha < \\beta \\), hence it only remains possible for \\( \\alpha \\) and \\( \\beta \\) to be equal.\n\\end{proof}\n\n\\begin{theorem}[Hartogs' lemma]\\label{thm:hartogs_lemma}\n  For every set \\( A \\) there exists a smallest ordinal \\( \\alpha \\) such that no function from \\( \\alpha \\) to \\( A \\) is injective.\n\\end{theorem}\n\\begin{proof}\n  Define the set\n  \\begin{equation*}\n    W \\coloneqq \\set{ (P, \\leq) \\given P \\subseteq A \\T*{and} \\leq \\T*{well-orders} P }.\n  \\end{equation*}\n\n  Let \\( \\beta \\) be an ordinal for which there exists an injective function \\( f: \\beta \\to A \\). At least one such pair of a ordinal and function exists because \\( \\varnothing: 0 \\to A \\) is an injective function.\n\n  The image of \\( f \\) can be well-ordered by\n  \\begin{equation*}\n    f(\\delta) < f(\\gamma) \\T{if and only if} \\delta \\in \\gamma,\n  \\end{equation*}\n  where \\( \\delta \\) and \\( \\gamma \\) are members of \\( \\beta \\). Thus, if we restrict the range of \\( f \\) to its image, it would be an explicit order isomorphism of \\( (\\beta, \\in) \\) and \\( (\\img f, <) \\).\n\n  We have shown that every ordinal \\( \\beta \\) and every injective function \\( f: \\beta \\to A \\) induces a well-ordered set which belongs to \\( W \\). Furthermore, if \\( f_1: \\beta_1 \\to A \\) and \\( f_2: \\beta_2 \\to A \\) are two such injective functions and if the induced well-ordered sets \\( (\\img f_1, \\leq_1) \\) and \\( (\\img f_2, \\leq_2) \\) are order-isomorphic, then \\( \\beta_1 \\) and \\( \\beta_2 \\) are themselves order-isomorphic and thus \\( \\beta_1 = \\beta_2 \\) by \\fullref{thm:ordinal_isomorphism}.\n\n  Therefore, for any well-ordered set in \\( W \\) there exists at most one ordinal that induces it via some function. Let \\( W' \\) be the subset of all well-ordered sets in \\( W \\) induced by exactly one ordinal.\n\n  We have that \\( W' \\) is a set and for each member of \\( W' \\) there corresponds exactly one ordinal. It follows from the \\hyperref[def:zfc/replacement]{axiom schema of replacement} that these ordinals form a set. Denote this set by \\( B \\).\n\n  There is no set of all ordinals by \\fullref{thm:burali_forti_paradox}, hence there must exist an ordinal not in \\( B \\). But every ordinal that has an injective function into \\( A \\) belongs to \\( B \\). Hence, there exists some ordinal \\( \\alpha \\) such that no function from \\( \\alpha \\) to \\( A \\) is injective.\n\n  If \\( \\alpha \\) is not the smallest ordinal with this property, we can now easily take the smallest member of \\( \\alpha \\) with this property.\n\\end{proof}\n\n\\begin{lemma}\\label{thm:ordinal_bijection_and_choice}\\mcite{MathSE:order_type_existence}\n  Let \\( A \\) be a nonempty set and let \\( c \\) be a \\hyperref[def:choice_function]{choice function} on \\( A \\). Then there exists an ordinal \\( \\alpha \\) and a bijection between \\( A \\) and \\( \\alpha \\).\n\\end{lemma}\n\\begin{proof}\n  We will explicitly build the desired ordinal. We will use \\fullref{thm:bounded_transfinite_recursion} in its structured form presented in \\fullref{rem:transfinite_induction} to build a \\hyperref[def:transfinite_sequence]{transfinite sequence} of injective maps from ordinals into \\( A \\).\n\n  Let \\( \\delta \\) be the smallest ordinal such that no function from \\( \\delta \\) to \\( A \\) is injective. Such an ordinal exists by \\fullref{thm:hartogs_lemma}. Note that \\( \\delta \\) cannot be zero because the empty function is always injective.\n\n  Any smaller than \\( \\delta \\) ordinal has at least one injective function into \\( A \\). We will use recursion bounded by \\( \\delta \\) to construct a \\hyperref[def:transfinite_sequence]{transfinite sequence} \\( \\seq{ \\iota_\\beta }_{\\beta < \\delta} \\) satisfying the invariant that for any \\( \\beta \\in \\delta \\), the function \\( \\iota_\\beta \\) is injective and strictly contains \\( \\iota_\\gamma \\) for any \\( \\gamma < \\beta \\).\n\n  \\begin{itemize}\n    \\item The zero ordinal has only one possible injective function into \\( A \\), namely the empty function \\( \\varnothing: 0 \\to P \\).\n\n    \\item Now let \\( \\iota_\\beta: \\beta \\to A \\) be an injective function.\n\n    If \\( \\iota_\\beta \\) is surjective, then it is the desired bijection and the rest of the construction is irrelevant.\n\n    If \\( \\iota_\\beta \\) is not surjective, define\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\iota_{\\op{succ}(\\beta)}: \\op{succ}(\\beta) \\to P \\\\\n        &\\iota_{\\op{succ}(\\beta)}(\\gamma) \\coloneqq \\begin{cases}\n          \\iota_\\beta(\\gamma),         &\\gamma < \\beta \\\\\n          c(A \\setminus \\img(\\iota_\\beta)), &\\gamma = \\beta.\n        \\end{cases}\n      \\end{aligned}\n    \\end{equation*}\n\n    This function is clearly injective.\n\n    \\item Let \\( \\lambda \\) be a limit ordinal and let \\( \\iota_\\beta \\) be an injective function for any \\( \\beta < \\lambda \\). Note that the domain of \\( \\iota_\\beta \\) is not necessarily \\( \\beta \\) --- it may be a smaller ordinal \\( \\gamma \\) in case \\( \\iota_\\gamma \\) is surjective (and thus the desired bijection).\n\n    In any case, we have a family \\( \\set{ \\iota_\\beta }_{\\beta < \\lambda} \\) of functions such that \\( \\iota_\\gamma \\subseteq \\iota_\\beta \\) if and only if \\( \\gamma < \\beta \\). We simply take their union\n    \\begin{equation*}\n      \\iota_\\lambda \\coloneqq \\bigcup \\set{ \\iota_\\beta \\given \\beta < \\lambda }.\n    \\end{equation*}\n\n    This function is injective because each of the constituent functions it injective.\n  \\end{itemize}\n\n  We will now thoroughly build the order isomorphism itself.\n\n  Let \\( \\alpha \\leq \\delta \\) be the (nonstrict) initial segment of \\( \\delta \\) such that \\( \\iota_\\beta \\) is fully defined on \\( \\beta \\) for every \\( \\beta \\in \\alpha \\). More precisely, let\n  \\begin{equation*}\n    \\alpha \\coloneqq \\set{ \\beta \\in \\delta \\given \\dom(\\iota_\\beta) = \\beta }.\n  \\end{equation*}\n\n  We will show that \\( \\alpha \\) is a successor ordinal. Note that \\( \\alpha \\) cannot be zero because \\( \\dom(\\iota_0) = \\varnothing = 0 \\). Aiming at a contradiction, assume that \\( \\alpha \\) is a limit ordinal.\n\n  Since for every \\( \\beta \\in \\alpha \\) the value \\( \\iota_{\\op{succ}(\\beta)}(\\beta) \\) is defined, we can conclude that the union\n  \\begin{equation*}\n    \\bigcup\\set{ \\iota_\\beta \\given \\beta \\in \\alpha }\n  \\end{equation*}\n  is an injective function from \\( \\alpha \\) to \\( A \\).\n\n  If \\( \\alpha = \\delta \\), this contradicts our choice of \\( \\delta \\). If \\( \\alpha \\in \\delta \\), this means that the function \\( \\iota_\\alpha \\) is equal to \\( \\iota_\\gamma \\) for some \\( \\gamma < \\alpha \\). But then \\( \\iota_{\\op{succ}(\\gamma)} \\) is not defined on the entirely of \\( \\gamma \\). This implies that \\( \\gamma \\geq \\alpha \\), which contradicts our assumption that \\( \\gamma < \\alpha \\).\n\n  Therefore, \\( \\alpha \\) cannot be a limit ordinal. It remains for \\( \\alpha \\) to be a successor ordinal. Then there exists \\( \\beta \\) such that \\( \\alpha = \\op{succ}(\\beta) \\).\n\n  Suppose that \\( \\iota_\\beta \\) is not surjective. We can then construct \\( \\iota_{\\op{succ}(\\beta)} \\) as in the corresponding recursion step. This will be an injective function from \\( \\alpha = \\op{succ}(\\beta) \\) to \\( A \\). But then we would have \\( \\alpha \\in \\alpha \\), which contradicts \\fullref{thm:simple_foundation_theorems/member_of_itself}.\n\n  Therefore, \\( \\iota_\\beta \\) is a surjective function.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:well_ordered_order_type_existence}\n  Any \\hyperref[def:well_ordered_set]{well-ordered set} \\( (P, \\leq) \\) is \\hyperref[def:partially_ordered_set/homomorphism]{order-isomorphic} to a unique ordinal. This ordinal is called the \\term{order type} of \\( (P, \\leq) \\) and is denoted by \\( \\ord(P, \\leq) \\) or simply \\( \\ord(P) \\).\n\n  Furthermore, this isomorphism is unique.\n\\end{theorem}\n\\begin{proof}\n  For \\( P = \\varnothing \\), then the empty function \\( \\iota: 0 \\to P \\) is the desired isomorphism.\n\n  We use \\fullref{thm:ordinal_bijection_and_choice} on \\( P \\) with the choice function\n  \\begin{equation*}\n    \\begin{aligned}\n      &c: \\pow(P) \\setminus \\set{ \\varnothing } \\to P \\\\\n      &c(B) \\coloneqq \\min B\n    \\end{aligned}\n  \\end{equation*}\n  to obtain an ordinal \\( \\alpha \\) and a bijection \\( \\iota: \\alpha \\to P \\).\n\n  The function \\( \\iota \\) is directly verified to be an order embedding in each of the recursion cases. Therefore, \\( \\iota \\) is a bijective order homomorphism and it follows from \\fullref{thm:totally_ordered_strict_isomorphisms} that \\( \\iota \\) is an order isomorphism.\n\n  Uniqueness of \\( \\iota \\) follows from \\fullref{thm:well_ordered_isomorphism_is_unique}.\n\\end{proof}\n\n\\begin{theorem}[Zermelo's well-ordering theorem]\\label{thm:well_ordering_theorem}\\mcite[thm. 69.6]{OpenLogicFull}\n  Any \\hyperref[def:set]{set} can be \\hyperref[def:well_ordered_set]{well-ordered}.\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/well_ordering}.\n\\end{theorem}\n\\begin{proof}\n  \\ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:well_ordering_theorem]{well-ordering theorem} The empty set is trivially well-ordered.\n\n  Let \\( A \\) be any nonempty set. By the axiom of choice, there exists a \\hyperref[def:choice_function]{choice function} \\( c \\) for \\( A \\). We use \\fullref{thm:ordinal_bijection_and_choice} on \\( A \\) and \\( c \\) to obtain an ordinal \\( \\alpha \\) and a bijection \\( \\iota: \\alpha \\to A \\). Since \\( \\alpha \\) itself is well-ordered, then the relation\n  \\begin{equation*}\n    x <_A y \\T{if and only if} \\iota^{-1}(x) <_\\alpha \\iota^{-1}(y)\n  \\end{equation*}\n  defines a well-order on \\( A \\).\n\n  \\ImplicationSubProof[thm:well_ordering_theorem]{well-ordering theorem}[def:zfc/choice]{axiom of choice} Let \\( A \\) be any set and suppose that \\( < \\) well-orders \\( A \\).\n\n  Define the function\n  \\begin{equation*}\n    \\begin{aligned}\n      &c: \\pow(A) \\setminus \\set{ \\varnothing } \\to A \\\\\n      &c(B) \\coloneqq \\min B.\n    \\end{aligned}\n  \\end{equation*}\n\n  In the case where \\( A \\) is the empty set, \\( c \\) is the empty function.\n\n  It is clear that \\( c(B) \\in B \\) for every subset \\( B \\) of \\( A \\). Therefore, \\( c \\) is a choice function for \\( A \\).\n\\end{proof}\n", "meta": {"hexsha": "35af7adf56ce41e2fa156c5acb1ed9f84f92873b", "size": 62119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ordinals.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/ordinals.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/ordinals.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": 74.1276849642, "max_line_length": 794, "alphanum_fraction": 0.6918334165, "num_tokens": 18529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.6247108364971616}}
{"text": "\\section{Formulas}\n\\begin{frame}\n\\frametitle{Formulas}\n\\framesubtitle{Use Of Mathematical Formulas}\n\n\\begin{exampleblock}{New packages in this section}\n\\begin{multicols}{2}\n\\begin{itemize}\n\\item amsmath \n\\item amsthm\n\\item amssymb\n\\item mathtools\n\\end{itemize}\n\\end{multicols}\n\\end{exampleblock}\n\n\\begin{block}{New commands in this section}\n\\begin{multicols}{2}\n\\begin{itemize}\n\\item \\color{nounibaredI}\\textbackslash sqrt\\color{black}\\{\\}\n\\item \\color{nounibaredI}\\textbackslash frac\\color{black}\\{\\}\\{\\}\n\\item \\color{nounibaredI}\\textbackslash int\\color{black}\\_X\n\\item \\color{nounibaredI}\\textbackslash sum\\color{black}\\_\\{\\}\n\\item \\color{nounibaredI}\\textbackslash lim\\color{black}\\_\\{\\}\n\\item \\color{nounibaredI}\\textbackslash prod\\color{black}\n\\item \\color{nounibaredI}\\textbackslash limits\\color{black}\\_\\{\\}\n\\item \\color{nounibaredI}\\textbackslash dots\\color{black}\n\\item \\color{nounibaredI}\\textbackslash cdot\\color{black}\n\\item \\color{nounibaredI}\\_\\color{black}\n\\item \\color{nounibaredI}\\^~\\color{black}\n\\end{itemize}\n\\end{multicols}\n\\end{block}\n\n\\end{frame}\n\n%-------------------------------------------------------------------------------\n\\begin{frame}\n\\frametitle{Formulas}\n\\framesubtitle{\\ldots ~A Marvel Of Beauty In \\LaTeX !}\n\n\\begin{columns}\n\\begin{column}{.3\\textwidth}\n{\\huge $2 \\sqrt{\\frac{\\pi ^2}{3}\\cdot c_{2}}$}\n\\end{column}\n\n\\begin{column}{.7\\textwidth}\n\t$\\underbrace{\n\t\\color{unibayellowI}\\text{\\$}\n\t\\color{black}2\n\t\\color{nounibaredI}\\backslash \\text{sqrt}\n\t\\color{black}\\{\n\t\\color{nounibaredI}\\backslash \\text{frac}\n\t\\color{black}\\{\n\t\\color{nounibaredI}\\backslash \\text{pi}\\color{nounibaredI}\n\t~\\hat{}~\\color{black}2\\}\\{3\\color{black}\\}\n\t\\color{nounibaredI}\\backslash\n\t\\color{nounibaredI}\\text{cdot}~\n\t\\color{black} \\text{c}\n\t\\color{nounibaredI}\\_\n\t\\color{black}2\\}\n\t\\color{unibayellowI}\\text{\\$}\n}$\n\\color{black}\n\nThe formula-environment begins and ends with \\color{unibayellowI}\\$ \\color{black} .\n\n\\medskip\n\t$\\underbrace{\n\t\\color{nounibaredI}\\backslash \\text{sqrt}\n\t\\color{black}\\{\n\t\\color{nounibaredI}\\backslash \\text{frac}\n\t\\color{black}\\{\n\t\\color{nounibaredI}\\backslash \\text{pi}\\color{nounibaredI}\n\t~\\hat{}~\\color{black}2\\}\\{3\\color{black}\\}\n\t\\color{nounibaredI}\\backslash\n\t\\color{nounibaredI}\\text{cdot}~\n\t\\color{black} \\text{c}\n\t\\color{nounibaredI}\\_\n\t\\color{black}2\\}\n}$\n\\color{black}\n\n\nThis whole part is the radical.\n\n\\bigskip\n$\\underbrace{\n\t\\color{nounibaredI}\\backslash \\text{frac}\n\t\\color{black}\\{\n\t\\color{nounibaredI}\\backslash \\text{pi}\\color{nounibaredI}\n\t~\\hat{}~\\color{black}2\\}\\{3\\color{black}\\}\n}$\n\nA fraction has always a numerator and a denominator.\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n%-------------------------------------------------------------------------------\n\n\\begin{frame}\n\\frametitle{Formulas}\n\\framesubtitle{\\ldots ~A Marvel Of Beauty In \\LaTeX !}\n\\begin{columns}\n\t\\begin{column}{.4\\textwidth}\n\t\t\\flushright\n\t\t$\\int_0^\\infty$\n\t\\end{column}\n\t\\begin{column}{.6\\textwidth}\n\t\t\\flushleft\n\t\t{\\ttfamily\\color{unibayellowI}\\$\\color{nounibaredI}\\textbackslash\\color{nounibaredI}int\\_\\color{black}0\\color{nounibaredI}\\textasciicircum \\textbackslash infty\\color{unibayellowI}\\$}\n\t\\end{column}\n\\end{columns}\n\\begin{columns}\n\t\\begin{column}{.4\\textwidth}\n\t\t\\flushright\n\t\t$\\sum_{i=1}^n$\n\t\\end{column}\n\t\\begin{column}{.6\\textwidth}\n\t\t\\flushleft\n\t\t{\\ttfamily \\color{unibayellowI}\\$\\color{nounibaredI}\\textbackslash\n\t\t\t\\color{nounibaredI}sum\\_\\color{black}\\{i=1\\}\\color{nounibaredI}\\textasciicircum\n\t\t\t\\color{black}n\\color{unibayellowI}\\$}\n\t\\end{column}\n\\end{columns}\n\n\\begin{columns}\n\t\\begin{column}{.4\\textwidth}\n\t\t\\flushright\n\t\t$\\lim_{n \\rightarrow \\infty}$\n\t\\end{column}\n\t\\begin{column}{.6\\textwidth}\n\t\t\\flushleft\n\t\t{\\ttfamily \\color{unibayellowI}\\$\\color{nounibaredI}\\textbackslash\n\t\t\t\\color{nounibaredI}lim\\_\\color{black}\\{n \\color{nounibaredI}\\textbackslash\n\t\t\t\\color{nounibaredI}rightarrow \\color{nounibaredI}\\textbackslash infty\\color{black}\\}\\color{unibayellowI}\\$}\n\t\\end{column}\n\\end{columns}\n\n\\begin{columns}\n\t\\begin{column}{.4\\textwidth}\n\t\t\\flushright\n\t\t$\\prod\\limits_{i=1}^{n+1}i = 1 \\cdot 2 \\cdot \\ldots \\cdot n \\cdot (n+1)$\n\t\\end{column}\n\t\\begin{column}{.6\\textwidth}\n\t\t\\flushleft\n\t\t{\\ttfamily \\color{unibayellowI}\\$%\n\t\t\t\\color{nounibaredI}\\textbackslash\\color{nounibaredI}prod\\textbackslash  limits\\_\\color{black}\\{i=1\\}\\color{nounibaredI}\\^{}\\color{black}\\{n+1\\} i = 1 \\color{nounibaredI}\\textbackslash \\color{nounibaredI}cdot \\color{black}2 \\color{nounibaredI}\\textbackslash \\color{nounibaredI}cdot \\color{nounibaredI}\\textbackslash \\color{nounibaredI}ldots \\color{nounibaredI}\\textbackslash\\color{nounibaredI}cdot \\color{black}n \\color{nounibaredI}\\textbackslash \\color{nounibaredI}cdot \\color{black}(n+1)\\color{unibayellowI}\\$}\n\t\\end{column}\n\\end{columns}\n\\bigskip\nThe American Mathematical Society has a wonderful guide for the {\\ttfamily amsmath}-package.\\footnote{ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf}\n\\end{frame}", "meta": {"hexsha": "6cfb40060899f75c8c7ec2190925393651977668", "size": 4899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "200+ beamer 模板合集/LaTeX-Tutorial-master(培训课件)/beamer/content/formulas.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": "200+ beamer 模板合集/LaTeX-Tutorial-master(培训课件)/beamer/content/formulas.tex", "max_issues_repo_name": "lemoxiao/Awesome-Beamer-Collection", "max_issues_repo_head_hexsha": "3ab28a23fb60cb0a97fcec883847e2d8728b98c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "200+ beamer 模板合集/LaTeX-Tutorial-master(培训课件)/beamer/content/formulas.tex", "max_forks_repo_name": "lemoxiao/Awesome-Beamer-Collection", "max_forks_repo_head_hexsha": "3ab28a23fb60cb0a97fcec883847e2d8728b98c0", "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": 31.8116883117, "max_line_length": 514, "alphanum_fraction": 0.7109614207, "num_tokens": 1804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6247108364971615}}
{"text": "\\chapter{ELEC 360 CheatSheet}\nSome keywords used can be found in the glossary section including:\n\\begin{itemize}\n\t\\item  \\gls{partFrac}, \\gls{openLoop}, \\gls{SISO}, \\gls{MIMO}, and \\gls{LTI}\n\t\\item  \\gls{conSys}, \\gls{closedLoop}, \\gls{DC Motors}, and \\gls{Op Amps}\n\\end{itemize}\n\n\\begin{multicols}{3}\n\n%\\includegraphics[width=1.77165in,height=0.95669in]{media/image1.png}\n\n\\section{LAPLACE TRANSFORMS}\n\nFinal Value Theorem\n\nIn Control Engineering, the Final Value Theorem is used most frequently to determine the steady-state value of a system. The real part of the poles of the function must be < 0.\n\\begin{align}\n& \\lim\\limits_{t \\rightarrow \\infty} x(t) = \\lim\\limits_{t \\rightarrow 0} sX(s)\n\\end{align}\n%\\includegraphics[width=1.77165in,height=0.92126in]{media/image2.png}\n\n%\\includegraphics[width=1.77165in,height=1.14961in]{media/image3.png}\n\nInitial Value Theorem\n\n\\begin{align}\n& \\lim\\limits_{t \\rightarrow 0} x(t) = \\lim\\limits_{t \\rightarrow \\infty} sX(s)\n\\end{align}\n%\\includegraphics[width=1.77165in,height=0.90551in]{media/image4.png}\n\n%\\includegraphics[width=1.77165in,height=0.77953in]{media/image5.png}\n\n\\section{SOLUTION OF LINEAR DIFFERENTIAL EQUATION}\n\n\\[A\\ddot{y} + B\\dot{y} + Cy = u\\left( t \\right)\\]\n\n\\[\\text{with initial conditions }\\dot{y}\\left( 0 \\right)\\ and \\ y(0)\\]\n\n\\[\\text{is solved by constructing the equation}\\]\n\n%\\[A\\left\\lbrack s^{2}Y\\left( s \\right) - sy\\left( 0 \\right) - \\dot{y}\\left( 0 \\right) \\right\\rbrack + B\\left\\lbrack \\text{sY}\\left( s \\right) - y\\left( 0 \\right) \\right\\rbrack + CY(s)\\]\n\n\\begin{align*}\n &A\\left\\lbrack s^{2}Y\\left( s \\right) - sy\\left( 0 \\right) - \\dot{y}\\left( 0 \\right) \\right\\rbrack + B\\left\\lbrack \\text{sY}\\left( s \\right) - y\\left( 0 \\right) \\right\\rbrack \\\\\n & + CY(s)\n\\end{align*}\n\\[that\\ is\\ to\\ say:\\]\n\n\\[\\mathcal{L}\\left\\{ \\ddot{y} \\right\\} = s^{2}Y\\left( s \\right) - sy\\left( 0 \\right) - \\dot{y}(0)\\]\n\n\\[\\text{and}\\]\n\n\\[\\mathcal{L}\\left\\{ \\dot{y} \\right\\} = sY\\left( s \\right) - y\\left( 0 \\right)\\]\n\n\\section{STATESPACE REPRESENTATIONS}\n\nTo generate from a differential equation:\n\nUse the \\textbf{closed loop transfer function}\n\n\\[\\frac{Y\\left( s \\right)}{U\\left( s \\right)} = \\frac{s + A}{s^{3} + \\text{Bs}^{2} + s + A}\\]\n\nSeparate and take the inverse Laplace transform\n\n\\begin{align*} &s^{3}Y\\left( s \\right) + \\text{Bs}^{2}Y\\left( s \\right) + sY\\left( s \\right) + AY\\left( s \\right) \\\\\n &= sU\\left( s \\right) + AU\\left( s \\right)\n \\end{align*}\n\n\\[= \\dddot{y} + B\\ddot{y} + \\dot{y} + Ay = \\dot{u} + Au\\]\n\nThen define state variables:\n\n\\(x_{1} = y\\) \\(\\dot{x_{1}} = \\dot{y} = x_{2}\\)\n\n\\(x_{2} = \\dot{y}\\) \\(\\dot{x_{2}} = \\ddot{y} = x_{3}\\)\n\n\\(x_{3} = \\ddot{y}\\)\n\\(\\dot{x_{3}} = \\dddot{y} = \\dot{u} + Au - B\\ddot{y} - \\dot{y} - Ay\\)\n\nThen construct the state space matrix\n\n\\[\\begin{bmatrix}\n\\dot{x_{1}} \\\\\n\\dot{x_{2}} \\\\\n\\dot{x_{3}} \\\\\n\\end{bmatrix} = \\begin{bmatrix}\n0 & 1 & 0 \\\\\n0 & 0 & 1 \\\\\n - A & - 1 & - B \\\\\n\\end{bmatrix}\\begin{bmatrix}\nx_{1} \\\\\nx_{2} \\\\\nx_{3} \\\\\n\\end{bmatrix} + \\begin{bmatrix}\n\\beta_{1} \\\\\n\\beta_{2} \\\\\n\\beta_{3} \\\\\n\\end{bmatrix}u\\]\n\nand\n\n\\[y = \\begin{bmatrix}\n1 & 0 & 0 \\\\\n\\end{bmatrix}\\begin{bmatrix}\nx_{1} \\\\\nx_{2} \\\\\nx_{3} \\\\\n\\end{bmatrix} + \\beta_{0}u\\]\n\n\\(\\beta\\) values can be calculated as follows:\n\n\\[\\beta_{0} = b_{0}\\]\n\n\\[\\beta_{1} = b_{1} - a_{1}\\beta_{0}\\]\n\n\\[\\beta_{2} = b_{2} - a_{1}\\beta_{1} - a_{2}\\beta_{0}\\]\n\n\\[\\beta_{3} = b_{3} - a_{1}\\beta_{2} - a_{2}\\beta_{1} - a_{3}\\beta_{0}\\]\n\nWhere the values for \\(a_{x}\\text{\\ and\\ }b_{x}\\)come from:\n\n\\[\\dddot{y} + a_{1}\\ddot{y} + a_{2}\\dot{y} + a_{3}y = b_{0}\\dddot{u} + b_{1}\\ddot{u} + b_{2}\\dot{u} + b_{3}u\\]\n\n\n\\[\\ddot{x}=(F-c\\dot{x_{1}}-kx)/m\\]\nwhere\n\tx=position,$\\dot{x}$=speed/velocity,$\\ddot{x}$=acceleration\n\tc = damping constant,\n\tm = mass,\n\tF = force\n\tk = spring constant,\n\nTo perform inverse (find transfer function from statespace model)\n\n\\[G\\left( s \\right) = d + c{(sI - A)}^{- 1}b\\]\n\n\nwhere\n\n\\[\\begin{bmatrix}\n\\dot{x_{1}} \\\\\n\\dot{x_{2}} \\\\\n\\dot{x_{3}} \\\\\n\\end{bmatrix} = \\begin{bmatrix}\nA_{11} & A_{12} & A_{13} \\\\\nA_{21} & A_{22} & A_{23} \\\\\nA_{31} & A_{32} & A_{33} \\\\\n\\end{bmatrix}\\begin{bmatrix}\nx_{1} \\\\\nx_{2} \\\\\nx_{3} \\\\\n\\end{bmatrix} + \\begin{bmatrix}\nb_{1} \\\\\nb_{2} \\\\\nb_{3} \\\\\n\\end{bmatrix}u\\]\n\nAnd\n\n\\[y = \\begin{bmatrix}\nc_{1} & c_{2} & c_{3} \\\\\n\\end{bmatrix}\\begin{bmatrix}\nx_{1} \\\\\nx_{2} \\\\\nx_{3} \\\\\n\\end{bmatrix} + \\lbrack d\\rbrack u\\]\n\nThe inverse of a square 2x2 matrix is found by:\n\n\\[\\begin{bmatrix}\na & b \\\\\nc & d \\\\\n\\end{bmatrix}^{- 1} = \\frac{1}{ad - bc}\\begin{bmatrix}\nd & - b \\\\\n - c & a \\\\\n\\end{bmatrix}\\]\n\nThe inverse of a square 3x3 matrix is found by:\n%\\includegraphics[width=2.52147in,height=1.02367in]{media/image8.png}\n\nFor a 3×3 matrix\n$$A=\\begin{bmatrix}\n\ta_{11} & a_{12}  & a_{13} \\\\\n\ta_{21} & a_{22}  & a_{23}\\\\\n\ta_{31} & a_{32}  &  a_{33}\n\\end{bmatrix}$$\t\nthe matrix inverse is:\n\n$$A^{-1}= \\frac{1}{|A|}\\begin{bmatrix}\n\\begin{bmatrix} a_{22} & a_{23} \\\\ a_{32} & a_{33}\\end{bmatrix} & \\begin{bmatrix} a_{13} & a_{12} \\\\ a_{33} & a_{32}\\end{bmatrix} & \\begin{bmatrix} a_{12} & a_{13} \\\\ a_{22} & a_{23}\\end{bmatrix} \\\\\n\\begin{bmatrix} a_{23} & a_{21} \\\\ a_{33} & a_{31}\\end{bmatrix}& \\begin{bmatrix} a_{11} & a_{13} \\\\ a_{31} & a_{33}\\end{bmatrix} & \\begin{bmatrix} a_{13} & a_{11} \\\\ a_{23} & a_{21}\\end{bmatrix} \\\\\n\\begin{bmatrix} a_{21} & a_{22} \\\\ a_{31} & a_{32}\\end{bmatrix} & \\begin{bmatrix} a_{12} & a_{11} \\\\ a_{32} & a_{31}\\end{bmatrix} & \\begin{bmatrix} a_{11} & a_{12} \\\\ a_{21} & a_{22}\\end{bmatrix}\t\n\\end{bmatrix}$$\nSolving a three order polynomial, without a fancy calculator\n\\begin{align*}\n& x = \\left[q + \\left[ q^2 + (r-p^2)^3\\right ]^{1/2} \\right]^{1 /3} \\\\\n& \\left[q - \\left[ q^2 + (r-p^2)^3\\right ]^{1/2} \\right]^{1 /3} + p\n\\end{align*}\nWhere \n\\begin{align*}\n& p = \\frac{-b}{3a}, \\ \\ q =p^3 + \\frac{bc-3ad}{3a^2}, \\ \\ r =\\frac{c}{3a}\n\\end{align*}\n\\section{SECOND ORDER SYSTEMS}\n\n\\[G\\left( s \\right) = \\frac{C(s)}{R(s)} = \\frac{\\omega_{n}^{2}}{s^{2} + 2\\zeta\\omega_{n}s + \\omega_{n}^{2}}\\]\n\n\\[K = \\omega_{n}^{2};\\ \\ \\ \\ T = 2\\zeta\\omega_{n} = 2\\sigma;\\ \\ \\ \\ \\ \\zeta = \\frac{T}{2\\sqrt{K}};\\ \\ \\ \\ \\omega_{d} = \\omega_{n}\\sqrt{1 - \\zeta^{2}}\\]\n\n\\[\\zeta = damping\\ ratio; \\sigma = real\\ part\\ of\\ root;\\]\n\n\\(\\ \\ \\ \\omega_{d} = damped\\ natural\\ frequency\\)\n\n\\( omega_{n} = undamped\\ natural\\ frequency \\)\n%\\includegraphics[width=1.96736in,height=1.37361in]{media/image9.png}\n\n\\[ Undamped:\\ \\zeta = 0;\\] \n\\[ Critically\\ Damped: \\zeta = 1 \\] \n\\[ Over\\ Damped:\\ \\zeta > 1\\]\n\nImaginary axis:\n\nFrequency of oscillations\n\nReal axis:\n\nDecay time\n\n\\textbf{UNIT STEP RESPONSE OF A 2\\textsuperscript{ND} ORDER UNDAMPED\nSYSTEM}\n\n$ t_{d}$ = delay time - to reach 50\\% of $c\\left( \\infty \\right) $\\text{for the first time}.\n$ t_{r}$ = rise time - time to reach 100 \\% of $c\\left( \\infty \\right)$ \\text{for first time} . \n$ t_{p}$ = peak time - time to reach first peak. \n$ t_{s}$ = settling time - time to reach \\& stay within 2\\% or 5\\% \n$ M_{p}$ = maximum overshoot. \n%\\[{t_{d} = delay\\ time - to\\ reach\\ 50\\%\\ of\\ c\\left( \\infty \\right)\\text{for\\ the\\ first\\ time}\\backslash n}{t_{r} = rise\\ time - time\\ to\\ reach\\ 100\\%\\ of\\ c\\left( \\infty \\right)\\text{for\\ first\\ time}\\backslash n}{t_{p} = peak\\ time - time\\ to\\ reach\\ first\\ peak\\backslash n}{t_{s} = settling\\ time - time\\ to\\ reach\\ \\&\\ stay\\ within\\ 2\\%\\ or\\ 5\\%\\backslash n}{M_{p} = maximum\\ overshoot\\ \\left( \\% \\right)\\backslash n}\\]\n\\[{t_{r} = \\frac{1}{\\omega_{d}}\\operatorname{}\\left( - \\frac{\\omega_{d}}{\\sigma} \\right);\\ \\ \\ \\ t_{p} = \\frac{\\pi}{\\omega_{d}}\\backslash n}\\]\n\n\\[{M_{p} = e^{- \\frac{\\zeta\\omega_{n}\\pi}{\\omega_{d}}} = e^{- \\frac{\\eta \\pi}{\\sqrt{1 - \\zeta^{2}}}} = e^{- \\frac{\\sigma \\pi}{\\omega_{d}}}}\\]\n\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\nDominant poles are the ones closest to the imaginary axis\n\n\\section{ROUTH-HURWITZ STABILITY TEST}\n\\[a_0s^n + a_1s^{n-1}+ \\cdots + a{n-1} s + a_n = 0\\]\n\\[ \\begin{array}{lllll}\n\\mbox{row n}   & a_0 & a_2 & a_4 & \\cdots \\\\\n\\mbox{row n-1} & a_1 & a_3 & a_5 & \\cdots \\\\\n\\mbox{row n-2} & b_1 & b_2 & b_3 & \\cdots \\\\\n\\mbox{row n-3} & c_1 & c_2 & c_3 & \\cdots \\\\\n\\cdots & \\cdots & \\cdots & \\cdots & \\cdots \\\\\n\\mbox{row 2} & * & * &  & \\cdots \\\\\n\\mbox{row 1} & * &   &  & \\cdots \\\\\n\\mbox{row 0} & * &   &  & \\cdots \\end{array} \\]\n\n\\[ b_1=-\\frac{det\\left[\\begin{array}{cc}a_0&a_2\\\\a_1&a_3\\end{array}\\right]}{a_1}\n=\\frac{a_1a_2-a_0a_3}{a_1} \\]\n\\[ b_2=-\\frac{det\\left[\\begin{array}{cc}a_0&a_4\\\\a_1&a_5\\end{array}\\right]}{a_1}\n=\\frac{a_1a_4-a_0a_5}{a_1} \\]\n\\[ b_3=-\\frac{det\\left[\\begin{array}{cc}a_0&a_6\\\\a_1&a_7\\end{array}\\right]}{a_1}\n=\\frac{a_1a_6-a_0a_7}{a_1} \\]\n\n\\[ c_1=-\\frac{det\\left[\\begin{array}{cc}a_1&a_3\\\\b_1&b_2\\end{array}\\right]}{b_1}\n=\\frac{b_1a_3-a_1b_2}{b_1} \\]\n\\[ c_2=-\\frac{det\\left[\\begin{array}{cc}a_1&a_5\\\\b_1&b_3\\end{array}\\right]}{b_1}\n=\\frac{b_1a_5-a_1b_3}{b_1} \\]\n\\[ c_3=-\\frac{det\\left[\\begin{array}{cc}a_1&a_7\\\\b_1&b_4\\end{array}\\right]}{b_1}\n=\\frac{b_1a_7-a_1b_4}{b_1} \\]\n\\section{STEADY STATE ERROR ANALYSIS}\n\n\\[K_{p} = \\operatorname{}{G\\left( s \\right)H(s)}\\]\n\n\\[K_{v} = \\operatorname{}{\\text{sG}\\left( s \\right);\\ \\ \\ \\ K_{v} = \\operatorname{}{s\\left( \\text{KG}\\left( s \\right) \\right)}}\\]\n\n\\[K_{a} = \\operatorname{}{s^{2}G\\left( s \\right);\\ \\ \\ \\ K_{a} = \\operatorname{}{s^{2}\\left( \\text{KG}\\left( s \\right) \\right)}}\\]\n\nThe type of system is determined by the number of poles at the origin.\nFor example:\n\n%\\includegraphics[width=2.60736in,height=0.52328in]{media/image10.png}\n\n\\section{ROOT LOCUS}\n\nRoot Locus presents the poles of the closed loop system when the gain K\nchanges from zero to infinity.\n\n\\textbf{Construction of the Root Locus}\n\nOpen loop transfer function\n\n\\[\\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\nn: the order of the \\textbf{open-loop} denominator polynomial\n\n\\textbf{Rule 1:} number of branches equals the number of poles of the\nopen-loop transfer function\n\n\\textbf{Rule 2:} If the total number of poles and zeros of the open-loop\nsystem to the right of the s-point on the real axis is odd, then this\npoint lies on the locus.\n\n\\textbf{Rule 3:} The locus starting point (K=0) are at the open-loop\npoles and the locus ending points (K=$\\infty$) are at the open loop zeros and\nn-m branches terminate at infinity.\n\n\\textbf{Rule 4:} Slope of asymptotes of root locus as `s' approaches\ninfinity\n\n\\textbf{Rule 5:} Abscissa of the intersection between asymptotes of root\nlocus and real-axis.\n\n%\\includegraphics[width=2.13497in,height=0.89069in]{media/image11.png}\n\n\\textbf{Rule 6:} Break-away and break-in points. From the characteristic\nequation\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\nThe 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.\nSubtract from 180° the sum of all angles from all other zeros and poles\nof the open-loop system to the complex pole (or zero) with appropriate\nsigns.\n\n\\textbf{Rule 8:} Imaginary-axis crossing points. Use Ruth-Hurwitz table\nto find value of K where system becomes unstable.\n\n\\section{BODE DIAGRAMS}\n\n%\\includegraphics[width=2.08800in,height=1.27279in]{media/image12.png}\n\n\\subsection{1. Gain Factor K:} Horizontal straight line at magnitude:\n\\(20\\log{(K)}\\text{dB}\\)\n\nPhase is zero.\n\n\\subsection{2. Integral or derivative factors}\n\\(\\mathbf{(j\\omega)}^{\\mathbf{\\pm 1}}\\)\n\n\\[\\left( \\text{j}\\omega \\right)^{- 1}\\  \\rightarrow 20\\log{\\left| \\frac{1}{\\text{j}\\omega} \\right| = - 20\\log\\omega}\\]\n\nMagnitude: strait line with slope -20 dB/decade\n\nPhase: -90°\n\n\\[\\left( \\text{j}\\omega \\right) \\rightarrow 20\\log\\left| \\text{j}\\omega \\right| = 20\\log\\omega\\]\n\nMagnitude: straight line with slope 20dB/decade\n\nPhase: +90°\n\n\\subsection{3. First Order Factors}\n\\(\\left( \\mathbf{1 + j\\omega T} \\right)^{\\mathbf{\\pm 1}}\\)\n\n\\begin{align}\n& \\left( 1 + j\\omega T \\right)^{- 1} \\rightarrow 20\\log\\left| \\frac{1}{1 + j\\omega T} \\right| \\\\ \\notag\n&= - 20\\log\\sqrt{1 + \\omega^{2}T^{2}}\\ \\lbrack dB\\rbrack\n\\end{align}\n\nApproximation for Magnitude:\n\n\\[For\\ \\omega\\ between\\ 0\\ and\\ \\frac{1}{T}\\  \\rightarrow 0dB\\]\n\\[For\\ \\omega\\  \\gg \\frac{1}{T} \\  \\rightarrow - 20dB/decade\\]\n\nPhase:\n\n\\[\\omega = 0\\  \\rightarrow \\varphi = 0\\]\n\\[\\omega = \\frac{1}{T} \\rightarrow \\varphi = - 45\\]\n\\[\\omega = \\infty \\rightarrow \\varphi = - 90 \\]\n\n\\[\\left( \\mathbf{1 + j\\omega T} \\right)^{\\mathbf{+ 1}}\\]\n\n\\subsection{4. Quadratic Factors}\n\n\\[G\\left( \\text{j}\\omega \\right) = \\frac{1}{1 + 2\\zeta\\left( \\frac{\\omega}{\\omega_{n}} \\right) + \\left( \\frac{\\text{j}\\omega}{\\omega_{n}} \\right)^{2}}\\ \\ ;\\ \\ 0 < \\zeta < 1\\]\n\nApproximation for magnitude:\n\n\\[\\omega \\ll \\omega_{n} \\rightarrow 0dB\\]\n\n\\[\\omega \\gg \\omega_{n} \\rightarrow - 20\\log\\left( \\frac{\\omega^{2}}{\\omega_{n}^{2}} \\right) = - 40\\log{\\left( \\frac{\\omega}{\\omega_{n}} \\right)\\text{dB}}\\]\n\n\\[Phase:\\]\n\n\\[\\omega = 0\\  \\rightarrow \\varphi = 0\\]\n\\[\\frac{\\omega}{\\omega_{n}} = 1 \\rightarrow \\varphi = - 90\\backslash \\]\n\\[\\omega = \\infty \\rightarrow \\varphi = - 180 \\]\n\n\\[Resonant\\ Frequency:\\]\n\t\\[\\omega_{r} = \\omega_{n}\\sqrt{1 - 2\\zeta^{2}}\\ \\ for\\ 0 < \\zeta < 0.707\\]\n\n\\[Resonant\\ Peak\\ Value:\\]\n\\[M_{r} = \\left| G\\left( \\text{j}\\omega \\right) \\right|_{\\max} = \\frac{1}{2\\zeta\\sqrt{1 - \\zeta^{2}}} \\ for\\ 0 < \\zeta < 0.707 \\]\n\nConsider\n\n\\[ G_{1}\\left( s \\right) = \\frac{1}{1 + Ts} \\ G_{2}\\left( s \\right) = \\frac{1}{1 - Ts} \\ G_{3}\\left( s \\right) = \\frac{1}{Ts - 1} \\]\n\nThen\\ldots{}\n\n\\[\\left| G_{1}(j\\omega) \\right| = \\left| G_{2}(j\\omega) \\right| = \\left| G_{3}(j\\omega) \\right|\\]\n\nAnd\\ldots{}\n\n\\[\\angle G_{2}\\left( \\text{j}\\omega \\right) = - \\angle G_{1}\\left( \\text{j}\\omega \\right) and \\]\n\\[ \\angle G_{3}\\left( \\text{j}\\omega \\right) = 180 - \\angle G_{1}\\left( \\text{j}\\omega \\right)\\]\n\n\\[+ 90\\ and\\ \\angle G_{3}\\left( \\text{j}\\omega \\right)\\ goes\\ from - 180\\ to - 90\\]\n\n\nGenerate based on the Bode Plot.\n\n\\textbf{The Nyquist Stability Criterion:} relates the stability of the\nclosed loop system to the frequency response of the open loop system.\n\n\\[Z = N + P\\]\n\n\\textbf{Z:} Number of zeros of $(1+H(S)G(s))$ in the right half plane =\nnumber of unstable poles of the closed-loop system.\n\n\\textbf{N:} Number of clockwise encirclements of the point $-1+j0$.\n\n\\textbf{P:} Number of poles of $G(s)H(s)$ in the right half plane.\n\nIf the plot makes a counter-clockwise encirclement of the $-1+j0$ point\nthen N becomes -1.\n\nIf Z = 0 the closed loop system is stable. If Z \\textgreater{} 0 the\nclosed loop system has Z unstable poles. If Z \\textless{} 0 a mistake\nhas been made and the calculations need to be rechecked.\n\n\\section{PHASE AND GAIN MARGINS}\n\nA measure for relative stability of the closed-loop system is how close\n\\(G(j\\omega)\\), the frequency response of the open-loop system, comes to\nthe point $-1+j0$. This is represented by the phase and gain margins.\n\n\\textbf{Phase Margin:} The amount of additional phase lag at the Gain\nCrossover Frequency \\(\\omega_{0}\\) required to bring the system to the\nverge of instability.\n\nGain crossover frequency:\n\\(\\omega_{0}\\text{\\ for\\ which\\ }\\left| G\\left( j\\omega_{0} \\right) \\right| = 1\\)\n\nPhase margin:\n\\(\\gamma = 180 + \\angle G\\left( j\\omega_{0} \\right) = 180 + \\phi\\)\n\n\\textbf{Gain Margin:} The reciprocal of the magnitude\n\\(\\left| G(j\\omega_{1}) \\right|\\) at the Phase crossover frequency\n\\(\\omega_{1}\\) required to bring the system to the verge of instability.\n\nPhase crossover frequency:\n\\(\\omega_{1}\\ where\\ \\angle G\\left( j\\omega_{1} \\right) = - 180\\)\n\nGain margin:\n\n\\[K_{g} = \\frac{1}{\\left| G(j\\omega_{1}) \\right|}\\]\n\n\\[K_{g} = - 20\\log\\left| G\\left( j\\omega_{1} \\right) \\right|\\]\n\n\\[K_{g}\\ in\\ dB > 0 = stable\\] for minimum phase systems. \n\t\\[K_{g}in\\ dB < 0\\] = unstable for minimum phase systems. \n\n\\textbf{Minimum phase systems:} all poles and zeros are in the left half\nplane.\n\nIf the open-loop system is minimum phase and has both phase and gain\nmargins positive then the closed-loop system is stable.\n\nFor good relative stability both margins are required to be positive.\n\nGood values for minimum phase system are:\n\nPhase Margin: 30°-60°\n\nGain Margin: above 6dB\n\n\n\\end{multicols}", "meta": {"hexsha": "190311f319af5ebc981373a2878b862fef1c1024", "size": 16307, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/ELEC360Cheat.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/ELEC360Cheat.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/ELEC360Cheat.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": 33.5534979424, "max_line_length": 428, "alphanum_fraction": 0.6294842706, "num_tokens": 6446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936537604181, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6247074777698167}}
{"text": "\\iffalse\nIt's unfair to say that mathematicians aren't real doctors, we perform surgeries all the time. In this class we'll introduce the notion of a topological manifold via simplicial (delta) complexes. Spend a day or two doing examples and go over several notions like orientation, cobordism and of course surgery.\n\nKeywords: simplicial complex, manifold, orientation, cobordism, surgery\n\nType: Lecture\nHomework: Recommended\nPrereqs: None\n\\fi\n\n\n\n\\input{../preamble}\n\n\\rhead{\\scshape Mathcamp 2017 : All things Manifoldy}\n\n\\begin{document}\n\\title{Surfaces}\n\\author{Apurva Nakade}\n\\thispagestyle{fancy}\n\\maketitle\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Real projective space $\\R\\P^2$}\nOne way to define the projective plane is by gluing the antipodal points on the disc. In this section we'll see how this corresponds to lines in $\\R^3$.\n\nConsider the upper hemisphere\n\\begin{align*}\n\tS^2_+ = \\{ (x,y,z) : x^2 + y^2 + z^2 = 1 , z\\ge 0\\}\n\\end{align*}\nEvery line in $\\R^3$ intersects $S^2_+$ in exactly one point, unless the line is along the $x-y$ plane in which case it intersects $S^2_+$ boundary in antipodal points. Thus the set of lines in $\\R^3$ is in 1-1 correspondence with the points on $S^2_+$ but with the antipodal points on the boundary circle glued, but this is precisely $\\R\\P^2$!\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.25\\linewidth]{images/ProjectivePlane}\n\t\\caption{Real projective plane}\n\\end{figure}\n\n\n\\begin{exercise}\n\tDescribe the space $\\R\\P^1$, the space of lines in $\\R^2$.\n\\end{exercise}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Poincar\\'e conjecture}\n\nPoincar\\'e conjecture is perhaps the most celebrated conjecture in the theory of manifolds. It's solution(s) led to creation of a lot of amazing mathematics. For 3 dimensional manifolds the conjecture is as follows.\n\n\\begin{thm}[Poincar\\'e conjecture]\n\tLet $M$ be a compact connected 3 dimensional manifold (without boundary). Suppose every loop on $M$ can be shrunk to a point then $M$ is homeomorphic to the 3 dimensional sphere $S^3$.\n\\end{thm}\n\nThere is a generalization of this conjecture to higher dimensions which requires a little more language to state. Surprisingly the conjecture was first proven to be true for dimensions $\\ge 5$ by Smale, next for dimension 4 by Freedman and finally for dimension 3 by Perelman. The conjecture is \\textbf{false} in the `category' of smooth manifolds i.e. if we replace homeomorphism by something stronger like diffeomorphism. The fact that the conjecture is true in the topological `category' but false in the smooth `category' implies the existence of \\textbf{exotic manifolds}. Exotic spheres were first discovered by Milnor and only exist in dimensions 7 and higher. Freedman proved that $\\R^4$ is the only Euclidean space which supports an exotic structure.\n\nThe Poincar\\'e conjecture in dimension 2 follows from the classification theorem for surfaces.\n\n\\begin{thm}[Classification of surfaces]\n\tEvery compact connected 2-dimensional manifold (without boundary) is homeomorphic to one of the following:\n\t\\begin{enumerate}\n\t\t\\item $S^2$\n\t\t\\item $T^{\\#k}$ for some $k$\n\t\t\\item $(\\R\\P^2)^{\\#k}$ for some $k$\n\t\\end{enumerate}\n\\end{thm}\n\nThe Poincare conjecture for 2 dimensions is an easy consequence of this theorem.\n\n\\begin{exercise}\n\tFind a loop on each of the following spaces $T$, $\\R\\P^2$ and $K$ which cannot be shrunk to a point.\n\\end{exercise}\n\n\\begin{exercise}\n\tShow that for any compact connected manifold $M$ there is a loop in each of the spaces $M \\# T$ and $M \\# \\R\\P^2$ which cannot be shrunk to a point.\n\\end{exercise}\n\n\\begin{exercise}\n\tFor a compact connected 2 dimensional manifold $M$ (without boundary) show that if every loop on $M$ can be shrunk to a point then $M$ is homeomorphic to $S^2$.\n\\end{exercise}\n\n\n\n\n\n\n\n\n\n\n\n\n\\iffalse\nA two dimensional manifold is called a surface. The surface of the earth is an example of a two dimensional manifold. By the above definition a surface is set $S$ such every point $s \\in S$ has a neighborhood homeomorphism to a 2 dimensional disk.\n\n\\begin{figure}[H]\n\t\\centering \\includegraphics[width=0.85\\linewidth]{images/GegusGSurfaces}\n\t\\caption{Surfaces}\n\\end{figure}\n\n\\subsection{Connected sums}\nIt is not hard to see that we can make sense of `addition' of two surfaces, after all when we think of a genus $g$ surface we think of $g$ tori glued to each other.\n\nIf $M_1$ and $M_2$ are two surfaces of genus $g_1$ and $g_2$ then we can `add' $M_1$ and $M_2$ to get a surface of genus $g_1+ g_2$. This is done by removing a small disc from $M_1$ and $M_2$ each and gluing $M_1$ and $M_2$ along the holes. The resulting manifold is denoted by $M_1 \\# M_2$ and is called their \\textbf{connected sum}.\n\nWe will denote a torus by $T$ and a genus $g$ surface by $T \\# \\cdots \\# T$, $g$ times or simply as $T^{\\#g}$.\n\n\\begin{figure}[h]\n\t\\centering \\includegraphics[width=0.40\\linewidth]{images/ConnectedSum}\n\t\\caption{Connected sum}\n\\end{figure}\n\nThus it is possible to add two surfaces but not subtract them. There is also an \\emph{identity element} for this connected sum operation (what is it?). This is more formally expressed by saying that the set of surfaces (up to homeomorphism) is a \\textbf{monoid}.\n\n\\begin{exercise}\n\tDefine connected sum for arbitrary manifolds.\n\\end{exercise}\n\n\\begin{exercise}\n\tIn the definition of connected sum we removed arbitrary discs from the manifolds $M_1$ and $M_2$. Draw pictures to show that if any two such choices can be deformed into each other and hence up to homeomorphism the manifold $M_1 \\# M_2$ is well defined. Can you come up with a rigorous proof for this?\n\\end{exercise}\n\n\\begin{ques}\n\tIs every surface a genus $g$ surface for some integer $g$?\n\\end{ques}\nThe answer is no. The most famous example is perhaps the Klein bottle. The Klein bottle is an example of a non-orientable surface (a surface with only 1 side) and it cannot be embedded in $\\R^3$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.15\\linewidth]{images/KleinBottle}\n\t\\caption{Klein bottle}\n\\end{figure}\n\nThere is an amazing theorem that holds for 2 dimensional manifold but which does not hold in any higher dimension.\n\n\\begin{thm}[Classification of surfaces]\n\tEvery compact connected 2 dimensional manifold is homeomorphic to one of the following\n\t\\begin{enumerate}\n\t\t\\item $S^2$\n\t\t\\item $T^{\\#g}$\n\t\t\\item $(\\R\\P^2)^{\\#g}$\n\t\\end{enumerate}\n\\end{thm}\nWe'll define the surface $\\R\\P^2$, called the \\textbf{real projective plane} below. If we think of a 2 dimensional manifold sitting inside some $\\R^n$ then \\textbf{compact connected} means that as a set the manifold is \\textbf{closed} and \\textbf{bounded}. If you do not know what these words mean then intuitively compact connected means that the manifold has no punctures in it and it does not extend to infinity.\n\nHow might one try to prove such a theorem? We'll use a technique very popular in topology called cutting and pasting!\n\n\\subsection{Gluing diagrams}\n\\begin{ques}\n\tWhat does a connected sum of a Klein bottle and a torus give us? What is the connected sum of two Klein bottles?\n\\end{ques}\n\nTo answer the above question we try to covert the problem into combinatorics by cutting open the surface. If cut a torus once we get a cylinder and we cut the cylinder again we get a square. On the square we label the sides to remember which side should be glued to which to get back the torus. Such a diagram is called a \\textbf{gluing diagram}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.20\\linewidth]{images/GluingDiagramTorus}\n\t\\caption{Gluing diagram for a torus}\n\\end{figure}\n\nCan we find gluing diagrams for other surfaces? The connected sum comes to the rescue. We can use connected sums to construct gluing diagrams using $2g$ sided polygons to construct $g$ genus surfaces, as in figure \\eqref{ConnectedSumGluingDiagram}.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.50\\linewidth]{images/GluingDiagramConnectedSum1}\n\t\\includegraphics[width=0.60\\linewidth]{images/GluingDiagramConnectedSum2}\n\t\\caption{Connected sum and gluing diagrams}\n\t\\label{ConnectedSumGluingDiagram}\n\\end{figure}\n\nThis is an interesting development. Perhaps we can even find a gluing diagram for the Klein bottle. What happens when you cut open the Klein bottle?\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.20\\linewidth]{images/GluingDiagramKleinBottle}\n\t\\caption{Gluing diagram for a Klein bottle}\n\\end{figure}\n\n\\begin{ques}\n\tWhat happens if we do not put arrows on all the edges?\n\\end{ques}\n\n\\begin{ques}\n\tWhat do open sets and line segments look like on the gluing diagrams?\n\\end{ques}\n\n\\begin{ques}\n\tWhen does the gluing diagram give us a manifold?\n\\end{ques}\n\n\\begin{ques}\n\tCan you come up with a gluing diagram for a sphere?\n\\end{ques}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Classifying surfaces}\nNotice that if we flip the directions of both the arrows labelled $a$ on the gluing diagram for a torus we get the torus back, but if we flip only one of the $a$ while keeping the other fixed we get a Klein bottle. This begs the question,\n\n\\begin{ques}\n\tWhat happens when we flip both the arrows on the torus gluing diagram?\n\\end{ques}\nThis gives us the \\textbf{Projective plane} denoted by $\\R\\P^2$. This is the space that we encountered in the classification theorem.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.20\\linewidth]{images/GluingDiagramProjectivePlane}\n\t\\caption{Gluing diagram for the Projective Plane $\\R\\P^2$}\n\\end{figure}\n\nThe proof of the classification theorem has two main steps. First comes from point set topology. First we show that any compact connected surface gives rise to a gluing diagram. This is a highly non-trivial fact that we will assume. The proof of this requires some knowledge of the fundamental group.\n\nThe second step is the showing that any gluing diagram is of one of three types listed in the classification theorem.\n\n\\subsection{The algebra of gluing diagrams}\nWe saw how connected sums allowed us to construct gluing diagrams for genus $g$ surfaces. A connected sum is a cutting and pasting operation. We can do more interesting cutting and pasting operations and produce some non-trivial results about gluing diagrams.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.75\\linewidth]{images/GluingDiagramKleinBottleMobiusStrip}\n\t\\caption{Klein bottle is the connected sum of two Mobius strips}\n\\end{figure}\n\\fi\n\\end{document}\n\n\n\n\n\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Modular origami}\n\n\\subsection{Orientation of surfaces}\nLet us start with surfaces. Roughly speaking a surface is called orientable if has two sides. A sphere or a torus are easily seen to be orientable. In fact any surface that can be \\textit{embedded} in $\\R^3$ is orientable. A Mobius strip on the other hand (which is not a surface as it has a boundary) is not orientable. With a little more mental effort one might be able to see that a Klein bottle or a Projective space are not orientable. We want an equivalent definition which can be used on gluing diagrams.\n\nWe begin by defining orientation of a polygon. An \\textbf{orientation of a polygon} is simply a cyclic ordering of it's vertices. For example this is one of the two possible ways to orient a triangle with vertices $(0,1,2)$.\n\n\\begin{center}\n\t\\begin{tabular}{c}\n\t\t\\centering \\includegraphics[height=3cm]{../noImageAvailable}\n\t\\end{tabular}\n\\end{center}\n\n\\begin{exercise}\n\tThis is related to the fact that the polygon has two sides via the right hand rule in physics. Do you see the connection?\n\\end{exercise}\n\nAn \\textbf{orientation} of (a gluing diagram of) a surface is a compatible choice of orientation for each triangle, where the orientations of two adjacent triangles need to be compatible in the following way,\n\\begin{center}\n\t\\begin{tabular}{c c c}\n\t\t\\centering \\includegraphics[height=3cm]{../noImageAvailable} & \\: & \\centering \\includegraphics[height=3cm]{../noImageAvailable}\n\t\\end{tabular}\n\\end{center}\nThis forces an edge to be directed in two different directions in adjacent triangles.\n\n\\begin{exercise}\n\tAdd the diagonals to the standard gluing diagrams to obtain triangulations and try to find orientations for them. Conclude that $S^2,T$ are orientable and $\\R\\P^2,K$ are not.\n\\end{exercise}\n\n\\begin{exercise}\n\tUse gluing diagrams to show that $T\\#T$ is orientable. Generalize this to argue that $T ^{\\# n}$ are orientable.\n\\end{exercise}\n\nThis same method also allows us to understand manifolds in higher dimensions as well.\n\n\n\n\n\n\n\n\\subsection{Simplices}\nAs we go to higher dimensions polygons (or is it polytopes?) become whacky are themselves quite hard to understand. So instead of looking at arbitrary polygons we look at the simplest polygons: triangles. We'll upgrade the definition of a triangle to a simplex which can live in arbitrary dimensions.\n\n\\begin{definition}\n\tAn $n$ dimensional \\textbf{simplex} $\\Delta^n$ is any set which is homeomorphic to the following region in $\\R^{n}$.\n\t\\begin{align}\n\t\t\\{ (x_0, x_1, \\cdots, x_n) : x_0 + \\cdots + x_n \\le 1 \\mbox{ and each } x_i \\ge 0  \\}\n\t\\end{align}\n\\end{definition}\nA 1 dimensional simplex is a segment and a 2 dimensional simplex is a triangle.\nSimplices are topologists best friend.\n\nNote that by adding extra diagonal lines we could have made the gluing diagrams entirely out of triangles.\nWe represent a simplex by its set of vertices.\n\n\\begin{figure}[h]\n\t\\centering \\includegraphics{../noImageAvailable}\n\t\\caption{Gluing diagram with labeled simplices}\n\t\\label{}\n\\end{figure}\n\nAs with origami you can glue these simplices any way you want and get relaly interesting objects. We're going to glue them to create manifolds.\n\n\\subsection{Manifolds from simplices}\nA delta complex is a collection of simplices glued along the faces.\n\n\\begin{definition}\n\tFaces of a simplex followed by examples.\n\\end{definition}\n\n\\begin{definition}\n\tDefinition of a delta complex followed by several examples.\n\\end{definition}\n\nTalk about spheres, tori and projective spaces in 3 dimensions.\n\n\\begin{ques}\n\tWhen is a delta complex a manifold?\n\\end{ques}\n\nExamples of manifolds and non-manifolds.\n\n\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{More on manifolds}\nThe last day is a little more on the expository side.\n\nWe saw how a Dehn surgery can be used to simplify a knot on a torus. We also saw how a connected sum can be used to build higher genus surfaces out of simpler ones.\n\nIs it possible to simply go the other way? Can one reverse the connected sum operation and go from a more complicated manifold to a simple one?\n\n\\subsection{Orientation of manifolds}\n\nShow that $\\R\\P^1$ and $\\R \\P^3$ are orientable but $\\R\\P^2$ is not using Delta complexes.\n\n\\subsection{Cutting $S^3$ into tori}\n\n\\subsection{Using Dehn twists to create 3 manifolds}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "2b889162e5c8ed35efe795ef3f3c4b3dabf02fd5", "size": 15174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 All things manifoldy/03 - Surfaces.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": "01 All things manifoldy/03 - Surfaces.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": "01 All things manifoldy/03 - Surfaces.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": 44.1104651163, "max_line_length": 759, "alphanum_fraction": 0.7346777382, "num_tokens": 3953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6247074776675321}}
{"text": "\\section{Properties of a Random Sample}\n\n\\begin{definition}[Random Sample]\n    A collection of random variables $X_1, \\dots, X_n$ is a \\emph{random sample of size n from population $f(x)$} if they are iid with pdf/pmf f(x).\n\\end{definition}\n\n\\begin{definition}[Statistic]\n    $Y = T(X_1, \\dots, X_n)$ is a \\emph{statistic} if the domain of $T$ contains the sample space of $(X_1, \\dots, X_n)$. The distribution of $Y$ is the \\emph{sampling distribution of $Y$}.\n\\end{definition}\n\n\\begin{remark}\n    A statistic is any function of the data. The only restriction is that the statistic is not also a function of some other parameters.\n\\end{remark}\n\n\\begin{definition}[Sample Mean and Sample Variance]\n    The \\emph{sample mean} $\\bar{X}$ and \\emph{sample variance} $S^2$ of a random sample $X_1, \\dots, X_n$ are, respectively,\n    \\begin{itemize}\n        \\item $\\bar{X} = \\frac1n \\sum_{i=1}^n X_i$\n        \\item $S^2 = \\frac{1}{n-1}\\sum_{i=1}^n (X_i - \\bar{X})^2$.\n    \\end{itemize}\n    The \\emph{sample standard deviation} is $S = \\sqrt{S^2}$.\n\\end{definition}\n\n\\begin{theorem}[Some facts]\n    Let $X_1, \\dots, X_n$ be a random sample from a population with mean $\\mu$ and finite variance $\\sigma^2$, then\n    \\begin{enumerate}[a.]\n        \\item $\\E{}[\\bar{X}] = \\mu$\n        \\item $\\Var{}[\\bar{X}] = \\frac{\\sigma^2}{n}$\n        \\item $\\E{}[S^2] = \\sigma ^2$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n    Take $x_1, \\dots, x_n \\in \\R{}$ and let $\\bar{x}$ be their mean. Then,\n    \\begin{enumerate}[a.]\n        \\item $\\min_a \\sum_{i=1}^n (x_i - a)^2 = \\sum_{i=1}^n (x_i - \\bar{x})^2$\n        \\item $(n-1)s^2 = \\sum_{i=1}^n(x_i - \\bar{x})^2 = \\sum_{i=1}^n x_i^2 - n\\bar{x}^2$.\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}\n    Let $X_1, \\dots, X_n$ be a random sample from population $f(x\\vert{}\\vec{\\theta})$ belonging to an exponential family\n    \\[\n        f(x \\vert{} \\vec{\\theta}) = h(x)c(\\vec{\\theta}) \\exp\\left(\\sum_{i=1}^k w_i(\\vec{\\theta})t_i(x)\\right).\n    \\]\n    Define the statistics \n    \\[\n        T_i(X_1, \\dots, X_n) = \\sum_{j=1}^n t_i(X_j), \\quad i=1, \\dots, k.\n    \\]\n    Then if the set $\\{(w_1(\\vec{\\theta}), \\dots, w_n(\\vec{\\theta}), \\, \\theta \\in \\Theta\\}$ contains and open subset of $\\R{}^k$ then the distribution of $(X_1, \\dots, X_n)$ is an exponential family of the form\n    \\[\n        f(u_1, \\dots, u_n \\vert{} \\vec{\\theta}) = H(u_1, \\dots, u_n) c(\\vec{\\theta})^n \\exp\\left(\\sum_{i=1}^kw_i(\\vec{\\theta})u_i\\right).\n    \\]\n\\end{theorem}\n\n\\begin{remark}\n    The open condition eliminates curved exponential families from this result.\n\\end{remark}\n\n\\subsection{Sampling from the Normal Distribution}\n\n\\begin{theorem}\n    Let $X_1, \\dots, X_n$ be a random sample from a $\\n(\\mu, \\sigma)$ distribution. Then,\n    \\begin{itemize}\n        \\item $\\bar{X}$ and $S^2$ are independent\n        \\item $\\bar{X} \\sim \\n(\\mu, \\sigma^2/n)$\n        \\item $(n-1)S^2/\\sigma^2 \\sim \\chi^2_{n-1}$.\n    \\end{itemize}\n\\end{theorem}\n\n\\begin{lemma}[Covariance and independence]\n    In the case of samples from a multivariate normal\n    \\begin{itemize}\n        \\item Independence $\\iff$ vanishing covariance\n        \\item Pairwise independence $\\iff$ independence\n    \\end{itemize}\n\\end{lemma}\n\n\n\\subsection{Convergence Concepts}\n\n\\subsubsection{Convergence in Probability}\n\\begin{definition}\n    A sequence of random variables $\\{X_i: i \\in \\N \\}$ \\emph{converges in probability} to a random variable $X$ if $ \\forall \\epsilon > 0$\n    \\[\n        \\lim_{n\\to\\infty}\\P{}(\\abs{X_n - X} \\geq \\epsilon) = 0\n    \\]\n    (or equivalently if $\\lim_{n\\to\\infty}\\P{}(\\abs{X_n - X} < \\epsilon) = 1$).\n\\end{definition}\n\n\\begin{theorem}[Weak Law of Large Numbers]\n    Let $X_1, X_2, \\dots$ be iid RVs with mean $\\mu$ and $\\E{}[\\abs{X_i}] < \\infty$. Define $\\bar{X}_n = \\frac1n \\sum_{i=1}^n$. Then the sequence $\\bar{X}_n$ converges in probability to $\\mu$. That is, $\\forall \\epsilon > 0$\n    \\[\n        \\lim_{n\\to\\infty} \\P{}(\\abs{X_n - \\mu} < \\epsilon) = 1\n    \\]\n\\end{theorem}\n\nProof is using Chebychev's inequality.\n\n\\begin{theorem}\n    If $X_1, X_2, \\dots$ converges in probability to $X$ and $h$ is a continuous function, then $h(X_1), h(X_2), \\dots$ converges in probability to $h(X)$.\n\\end{theorem}\n\n\\subsubsection{Almost Sure Convergence}\n\n\\begin{definition}\n    A sequence of random variables $X_1, X_2, \\dots$ \\emph{converges almost surely} to a random variable $X$ if $ \\forall \\epsilon > 0$\n    \\[\n        \\P{}\\left(\\lim_{n\\to\\infty} \\abs{\\bar{X}_n - X} < \\epsilon\\right) = 1.\n    \\]\n\\end{definition}\n\n\\begin{comments}\n    \\mbox{}\n    \\begin{itemize}[+]\n        \\item Almost sure convergence is much stronger than convergence in probability. Convergence in probability states that the sequence of measures of the sets on which the sequence has finite difference from its the limit converges to 0. Almost sure convergence states that any place where the sequence has finite difference from its limit must have measure 0. It's like a sequence of integrals converging vs. whether the integrands converge.\n        \\item Almost sure convergence implies convergence in probability but not the other way around.\n    \\end{itemize}\n\\end{comments}\n\n\\begin{theorem}\n    If a sequence converges in probability then it is possible to find a subsequence that converges almost surely.\n\\end{theorem}\n\n\\begin{theorem}[Strong Law of Large Numbers]\n    Let $X_1, X_2, \\dots$ be iid RVs with mean $\\mu$ and $\\E{}[\\abs{X_i}] < \\infty$. Define $\\bar{X}_n = \\frac1n \\sum_{i=1}^n$. Then the sequence $\\bar{X}_n$ converges almost surely to $\\mu$. That is, $\\forall \\epsilon > 0$\n    \\[\n         \\P{}\\left(\\lim_{n\\to\\infty}\\abs{\\bar{X}_n - \\mu} < \\epsilon\\right) = 1.\n    \\]\n\\end{theorem}\n    \n\\subsubsection{Convergence in Distribution}\n\n\\begin{definition}\n    A sequence of random variables $X_1, X_2, \\dots$ \\emph{converges in distribution} to a random variable $X$ if\n    \\[\n        \\lim_{n \\to \\infty} F_{X_n}(x) = F_X(x)\n    \\]\n    at all points where $F_X$ is continuous.\n\\end{definition}\n\n\\begin{remark}\n    Here it is really the cdfs that converge, rather than the random variables. In this way convergence in distribution differs from the previous two concepts.\n\\end{remark}\n\n\\begin{theorem}\n    Convergence in probability implies convergence in distribution\n\\end{theorem}\n\n\n\\begin{theorem}[Central Limit Theorem]\n    Let $X_1, X_2, \\dots$ be a sequence of iid random variables with $\\E{}[X_i] = \\mu$ and finite variance $\\Var{}[X_i] = \\sigma^2 < \\infty$. Define $\\bar{X}_n = \\frac1n \\sum_{i=1}^n X_i$. Let $G_n(x)$ denote the cdf of $\\sqrt{n}(\\bar{X}_n - \\mu)/\\sigma$. Then $\\forall x \\in \\R$,\n    \\[\n        \\lim_{n\\to\\infty} G_n(x) = \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^x e^{-y^2/2}\\d{}y.\n    \\]\n    That is, $\\sqrt{n}(\\bar{X}_n - \\mu)/\\sigma$ converges in distribution to the standard normal.\n\\end{theorem}\n\n\\begin{theorem}[Slutsky's Theorem]\n    If $X_n \\to X$ in distribution and $Y_n \\to a$ in probability with $a$ constant, then\n    \\begin{enumerate}[a.]\n        \\item $Y_nX_n \\to aX$ in distribution\n        \\item $X_n + Y_n \\to X + a$ in distribution\n    \\end{enumerate}\n\\end{theorem}\n\n\\begin{remark}\n    This tells us, for instance, that \n    \\[\n        \\frac{\\sqrt{n}(\\bar{X}_n - \\mu)}{S_n} \\to \\n(0, 1)\n    \\]\n    in distribution, since we know that $S_n \\to \\sigma$ in probability.\n\\end{remark}\n\n\\subsubsection{The Delta Method}\nIf we are interested in the convergence of some function of a sequence of RVs, rather than the RVs themselves, then we can use the Delta Method (follows from an application of Taylor's theorem and Slutsky's theorem).\n\n\\begin{theorem}[Delta Method]\n    Let $Y_n$ be a sequence of random variables that satisfies $\\sqrt{n}(Y_n - \\theta) \\to \\n(0, \\sigma^2)$ in distribution. For a given function $g$ and a specific value of $\\theta$, suppose that $g'(\\theta)$ exists and is non-zero. Then\n    \\[\n        \\sqrt{n}[g(Y_n) - g(\\theta)] \\to \\n(0, \\sigma^2g'(\\theta)^2)\n    \\]\n    in distribution.\n\\end{theorem}\n\n\n\\begin{remark}\n    There exists a corresponding multivariate result.\n\\end{remark}\n\nIf $g'(\\theta) = 0$ then we take the next term in the Taylor series.\n\n\\begin{theorem}[Second Order Delta Method]\n    Let $Y_n$ be a sequence of random variables that satisfies $\\sqrt{n}(Y_n - \\theta) \\to \\n(0, \\sigma^2)$ in distribution. For a given function $g$ and a specific value of $\\theta$, suppose that $g'(\\theta) = 0$ and $g''(\\theta)$ exists and is non-zero. Then\n    \\[\n        \\sqrt{n}[g(Y_n) - g(\\theta)] \\to \\n(0, \\sigma^2g'(\\theta)^2)\n    \\]\n    in distribution.\n\\end{theorem}\n\n\n\\subsection{Generating A Random Sample}\n\n\\begin{definition}[Direct Method]\n    A \\emph{Direct Method} of generating a random sample uses the probability integral transform to map draws from a $\\text{uniform}(0, 1)$ random variable to draws from the distribution of interest.\\\\\n    \n    The Probability Integral Transform states that if $X$ has continuous cdf $F_X(x)$ then\n    \\[\n        F_X(X) \\sim \\text{uniform}(0, 1).\n    \\]\n\\end{definition}\n\n\\begin{definition}[Accept-Reject Algorithm]\n    Let $Y \\sim f_Y(y)$ and $V \\sim f_V(v)$ where $f_Y$ and $f_V$ have common support with\n    \\[\n        M = \\sup_y f_Y(y) / f_V(y) < \\infty.\n    \\]\n    To generate a random variable $Y \\sim f_Y$:\n    \\begin{enumerate}[a.]\n        \\item Generate $U \\sim \\text{uniform}(0, 1)$, $V \\sim f_V$ independent.\n        \\item If $U < \\frac 1M f_Y(V)/f_V(V)$, return $V$ as a sample of $Y$; otherwise go back to (a.).\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n    \\mbox{}\n    \\begin{itemize}\n        \\item It is typical to call $V$ the \\emph{candidate density} and $Y$ the \\emph{target density}.\n        \\item One would normally try to choose a candidate density with heavier tails than the target density (e.g. Cauchy and normal) to ensure that the tails of the target are well represented. If the target has heavy tails, however, it can be hard to find a candidate that results in finite $M$. In this case people turn to MCMC methods.\n        \\item Note that $\\P{}(\\texttt{terminate}) = 1/M$. The number of trials to generate one sample of $Y$ is therefore $\\text{geometric}(1/M)$, with $M$ the expected number of trials.\n        \\item The intuition behind this algorithm is that if we consider placing the density of a random variable $Y$ in a box (2d for simplicity) with coordinates $(v,u)$, we express the cdf of $Y$ using $V, U \\sim \\text{uniform}(0, 1)$\n        \\[\n            \\P{}(Y \\leq y) = \\P{}(V \\leq y \\vert{} U \\leq \\frac1c f_Y(V))\n        \\]\n        where $c = \\sup_y f_Y(y)$. In the actual algorithm we take $U \\sim \\text{uniform}(0,1)$ and $V$ to be an RV that has common support with $Y$.\n    \\end{itemize}\n\\end{remark}\n\n\n", "meta": {"hexsha": "a3c2c925d923321995aa3be798979f5ec5720afc", "size": 10658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter5/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/chapter5/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/chapter5/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": 44.4083333333, "max_line_length": 447, "alphanum_fraction": 0.6488084068, "num_tokens": 3431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.624707475947556}}
{"text": "%!TEX root =  ../../master.tex\n\n\\subsection{Results of the dispersion method in three dimensions}\n\n\\begin{figure}[!htb]\n\t\\centering\n    \\scalebox{0.8}{\\input{figure/ere-contact-fitted_a-inv_+0.0_zeta_dispersion_projector_a1g_n-eigs_200.pgf}}\n    \\caption{The same as \\Figref{unimproved spherical}, but tuned and subsequently analyzed using the appropriate latticized \\Luscher function, matching the cutoff on the sum to the lattice scale and accounting for the dispersion relation.\n    We emphasize the results are on a log scale, and the tuning was to $-1/a_3 = 0$.\n    }\n    \\label{fig:unimproved dispersion}\n\\end{figure}\n\nIn this section, we again attempt to tune our contact interaction to unitarity by matching the first zero of the zeta function.\nHowever, the difference is that at each lattice spacing we tune to that spacing's respective $S^{\\dispersion}_3$, leveraging the dispersion relation for that derivative.\nThen, when we extract finite-volume and finite-spacing energy levels, we put them through the dispersion equation \\eqref{dispersion-zeta-contact} using the same $S^{\\dispersion}$ function.\nThe numerical results of said procedure are shown in \\Figref{unimproved dispersion}.\nNote that the results for $p\\cot\\delta$ are now flat across the spectrum, matching the known result for a contact interaction.\nMoreover, comparing the scale to that in, for example, \\Figref{unimproved spherical}, there the deviations were of order~1, while here the results remain within $10^{-8}$ of zero, with the value entirely reflecting how well the contact interaction was tuned.\nPut another way, we have verified that the dispersion zeta function provides exact finite-spacing energy levels for our contact interaction \\eqref{p space hamiltonian}, just as one would hope for a contact interaction in the continuum.\n\n\\begin{figure}[!hbt]\n\t\\centering\n    \\scalebox{0.7}{\\input{figure/contact-scaling-contact-fitted_a-inv_+0.0_zeta_dispersion_projector_a1g_n-eigs_200.pgf}}\n    \\caption{\n        Scaling of the contact interaction strength $C_R^{(n_s)}(\\epsilon)$ fitted using the dispersion method at unitarity.\n        Data points are values of the contact interaction fitted to the first intersection of the phase shifts with the dispersion zeta function.\n        The solid lines are analytic scaling predictions following \\eqref{dispersion-renormalization} and the dashed line corresponds to the spherical counter term $ \\mathcal{L}^{\\spherical}_3 = 2 \\pi$.\n        Bar diagrams below present the absolute error between prediction and extracted value.\n    }\n    \\label{fig:dispersion running of strength}\n\\end{figure}\n\nIn \\Figref{dispersion running of strength} we show how the strength of the contact interaction runs with the lattice scale according to the analytic expectation \\eqref{dispersion-renormalization}.\nNote that the lines are not fits to the data; though the difference is down at $10^{-12}$ or better.\nAgain, this difference depends on the accuracy of the tuning.\n\nWe note that\n\\begin{enumerate}\n\t\\item when matching the contact interaction parameter using spherical \\Luscher data and finite spacing eigenvalues, the data points did not exactly match the analytic spherical contact scaling.\n\tThe error at the smallest lattice spacing had a relative error on the percent scale and it got worse for larger lattice spacings.\n\t\\item even in the limit of $n_s \\to \\infty$ the dispersion counter term $\\mathcal{L}^\\dispersion_3$ will not match the spherical counter term $\\mathcal{L}^{\\spherical}_3$.\nAt any finite $N$ the spherical integral and cartesian integrals differ---if the radius of the sphere is $N/2$, the corners of the lattice's Brillouin zone are absent; the cartesian integral matches the Brillouin zone correctly, critical for any finite-$N$ result.\n\\end{enumerate}\n\n\n\n\\subsection{Momentum-induced terms of  \\texorpdfstring{$S^\\bigcirc_3(x^\\dispersion)$}{S3-spherical} due to discretization\\label{sec:3d induced momenta}}\nThe zeta function in L\\\"uscher's formula, $S^\\bigcirc_3(x)$, is derived in the continuum.\nAs such, it requires continuum energies $x$ for its argument.\nIf one instead feeds discretized energies $x^\\dispersion$ through $S^\\bigcirc_3(x)$ then momentum-dependent terms are subsequently induced.\n\n\\begin{figure}[htb]\n    \\scalebox{0.8}{\\input{figure/3dtuned.pgf}}\n    \\caption{\n        Here we show a contact interaction in three dimensions with the ground state tuned to the first zero of the spherical zeta function $S^{\\spherical}_3$ on cubic lattices with $N=10,$ 20, 40, 80 (squares, diamonds, hexagons, and circles, respectively), with the resulting spectrum analyzed with $S^{\\spherical}_3$ (colored points) and the $N$-appropriate $S^{\\dispersion}_3$ (black points).\n        The gray dashed line is $S^\\spherical_3$ and the thin vertical lines are at the non-interacting $x$s where it diverges.\n        The colored lines are the second-order analytic prediction for the difference between the dispersion and spherical analysis as a function of $x$.\n        For clarity of the continuum limit we show, in the bottom panel, a limited range in $x$ and $pL\\cot\\delta_{30}$, where it is clear that each $N$ hits the zero of $S^\\spherical_3$ but that the flat behavior at any finite $N$ is away from an infinite scattering length when analyzed with $S^\\dispersion_3$.\n    }\n    \\label{fig:3d-corrections}\n\\end{figure}\n\nThis is particularly evident for the contact interaction as was observed, for example, in \\Ref{Endres:2012cw}.\nTo understand the source of these terms, consider\n\\begin{multline}\n\\frac{1}{\\pi L}S^\\bigcirc_3(x^\\dispersion)=\\frac{1}{\\pi L}\\left(S^{\\dispersion}_3(x^\\dispersion)+\\left(S^\\bigcirc_3(x^\\dispersion)-S^{\\dispersion}_3(x^\\dispersion)\\right)\\right)=\\frac{-1}{a_3}+\\frac{1}{\\pi L}\\left(S^\\bigcirc_3(x^\\dispersion)-S^{\\dispersion}_3(x^\\dispersion)\\right)\\\\\n=\\frac{-1}{a_3}+\\lim_{\\eta \\to\\infty}\\frac{1}{\\pi L}\\left(\\sum_{\\bm n\\notin \\mathrm{B.Z.}}^{|\\bm n|<\\eta / 2} \\frac{1}{\\bm n^{2}-x^\\dispersion}-\\mathcal{L}^\\bigcirc_3\\frac{\\eta}{2}+\\mathcal{L}^\\dispersion_3\\frac{N}{2}\\right)\\ .\n\\end{multline}\nIn the first line we added and subtracted $S^\\dispersion_3$ and used the dispersion results~\\eqref{dispersion-zeta-form} and~\\eqref{dispersion-zeta-contact} to introduce the scattering length in the case of a contact interaction.\nFor convenience we assume $n_s=\\infty$\\footnote{\nThe logic of the following derivation remains them same also for $n_s < \\infty$, but, in this case, the expressions $\\bm n^2$ must be replaced with the proper dispersion $\\tilde K^{(n_s)}_{\\bm n \\bm n}$ \\eqref{normalized-kinetic-hamitlonian}, which makes it difficult to obtained closed expressions.  Also, within the Brillouin zone the different dispersion relations cause the two sums differ by \\order{x/N^2} term-by-term.}.\nIn the second line, since $\\bm n$ is now restricted to be \\emph{outside} the Brillouin zone, we can assume that $\\bm n^2\\gg x^\\dispersion$ and expand in small $x^\\dispersion$ under the summation,\n\\begin{align}\n\t\\label{eqn:observable}\n\tS^\\bigcirc_3(x^\\dispersion)\n\t&=\n\t\\frac{-\\pi L}{a_3}\n\t+\\mathcal{L}^\\dispersion_3\\frac{N}{2}\n\t+\\lim_{\\eta \\to\\infty}\\left(\\sum_{\\bm n\\notin \\mathrm{B.Z.}}^{|\\bm n|<\\eta / 2} \\frac{1}{\\bm n^{2}}\n\t-\\mathcal{L}^\\bigcirc_3\\frac{\\eta}{2}\\right)\n\t+x^\\dispersion\\lim_{\\eta \\to\\infty}\\sum_{\\bm n\\notin \\mathrm{B.Z.}}^{|\\bm n|<\\eta / 2} \\frac{1}{\\bm n^{4}}\n\t+(x^\\dispersion)^2\\lim_{\\eta \\to\\infty}\\sum_{\\bm n\\notin \\mathrm{B.Z.}}^{|\\bm n|<\\eta / 2} \\frac{1}{\\bm n^{6}}\n\t+ \\ldots\n\t\\\\\n\t\\label{eq:small x}\n\t&\\equiv \\frac{-\\pi L}{a_3}+\\alpha_1(N)+\\alpha_2(N)x^\\dispersion+\\alpha_3(N)(x^\\dispersion)^2\n\t+\\ldots\n\\end{align}\nThe last line above shows explicitly the induced momentum-dependence in $x^\\dispersion$ and defines the coefficients $\\alpha_i(N)$ in terms of particular lattice summations similar to those of the three-dimensional zeta function.  The dependence of these coefficients on $N$ comes from the \\emph{exclusion} of momentum modes within the Brillouin zone in the summation.   The fact that these coefficients do \\emph{not} depend on $L$ is a unique feature of the contact interaction.  The numerical values of the coefficients $\\alpha_i(N)$ can be determined using standard acceleration techniques (see, for example, Appendix B of~\\Ref{Luu:2011ep}).  We provide values for select cases of $N$ in \\Tabref{slopes}.\n\\begin{table}\n\\caption{Coefficients $\\alpha_i(N)$ as a function of $N$ in 3-D.\\label{tab:slopes}}\n\\center\n\\begin{tabular}{S[table-format=1.0]S[table-format=-1.15,table-auto-round=false]S[table-format=-1.15,table-auto-round=false]S[table-format=-1.15,table-auto-round=false]}\n{$N$} & {$\\alpha_1$} & {$\\alpha_2$} & {$\\alpha_3$} \\\\ \\midrule\n10 & 0.34622847019345 &2.1088361299026 &0.02096728133239\\\\\n20 & 0.17384029798483 &1.0470052482673 &0.00253774588732\\\\\n40 & 0.08701147975728 &0.5225652776531 &0.00031456311910\\\\\n50 & 0.06961796407968 &0.4179620004936 &0.00016089237674\\\\\n80 & 0.04351717442702 &0.2611651268184 &0.00003923695720\\\\\n100 &0.03481483765136 &0.2089208128674 &0.00002008418957\n\\end{tabular}\n\\end{table}\n\nIn \\Figref{3d-corrections} we show the result of tuning a finite-spacing contact interaction to the first zero of the continuum zeta function $S^\\spherical_3$.\nAt each spacing the spectrum is fed through the continuum zeta for analysis, resulting in an apparent spacing-dependent momentum dependence that matches the small-$x$ expansion~\\eqref{small x} discussed in the next section.\nThe same spectrum is also fed through the spacing-appropriate dispersion zeta $S^\\dispersion$, resulting in the flat black lines.\nShown in detail in the bottom panel, it's clear that the continuum limit taken this way results in any finite spacing having a nonzero scattering length that vanishes with the continuum limit.\nIn contrast, tuning to the dispersion function directly, as in \\Figref{unimproved dispersion}, is flat and nearly zero at each individual lattice spacing.\nWe expect that this difference explains the induced momentum dependence of, for example, \\Refs{Endres:2011er,Endres:2012cw}.\n", "meta": {"hexsha": "a2aaf1789bb7532835a3f544dbdd5955ad1f188b", "size": 10034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/luescher-nd/section/three-dimensions/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/three-dimensions/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/three-dimensions/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": 90.3963963964, "max_line_length": 707, "alphanum_fraction": 0.7566274666, "num_tokens": 2815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.624707466436545}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\\usepackage{amsmath,amssymb,wasysym}\n\\usepackage[margin=2cm]{geometry}\n\n\\usepackage{comment}\n\\usepackage{longtable}\n\\usepackage{tabularx,booktabs}\n\\usepackage{listings}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\lstset{basicstyle=\\ttfamily}\n\\newcommand{\\py}{\\lstinline}\n\n% Math notations\n\\newcommand{\\Z}{{\\mathbb{Z}}}                     % set of integers\n\n% MoA notations\n\\newcommand{\\minus}{{}^{\\boldsymbol{\\mbox{-}}\\!}} % scalar negation operator\n\\newcommand{\\rop}[1]{\\,\\mathrm{#1}^*\\,}           % relational operation\n\\newcommand{\\op}[1]{\\,\\mathrm{#1}\\,}              % binary operation\n\\newcommand{\\uop}[1]{\\mathrm{#1}\\,}               % unary operation\n\\newcommand{\\hop}[2]{{{}_{#1}\\!\\Omega_{#2}}\\,}      % higher order operation\n\\newcommand{\\id}[1]{\\mathrm{id}(\\op{#1})}         % identity of operations\n\\newcommand{\\dims}{\\delta\\,}                      % array dimension operator\n\\newcommand{\\shape}{\\rho\\,}                       % array shape operator\n\\newcommand{\\size}{\\tau\\,}                        % array size operator\n\\newcommand{\\reshape}{\\,\\widehat{\\rho}\\,}         % reshape operator\n\\newcommand{\\drop}{\\,\\nabla\\,}                    % drop operator\n\\newcommand{\\take}{\\,\\Delta\\,}                    % take operator\n\\newcommand{\\product}{\\pi\\,}                      % product operator\n\\DeclareMathOperator{\\rav}{rav}\n\\newcommand{\\ravel}{\\rav\\,}                       % ravel operator\n\\newcommand{\\range}{\\iota\\,}                      % range operator\n\\newcommand{\\transpose}{\\bigcirc\\!\\!\\!\\!\\!\\backslash\\;} % transpose operator, need a better symbol\n\\newcommand{\\vc}[1]{<#1>}                         % vector with one component\n\\newcommand{\\vcc}[2]{<#1\\;#2>}                    % vector with two components\n\\newcommand{\\vccc}[3]{<#1\\;#2\\;#3>}               % vector with four components\n\\newcommand{\\outerprod}[1]{\\,\\bullet_{#1}\\,}              % outer product opetation\n\\newcommand{\\innerprod}[2]{\\,{}_{#1}\\!\\!\\bullet_{#2}\\,}   % inner product opetation\n\\DeclareMathOperator{\\red}{red}\n\\newcommand{\\reduce}[1]{{}_{#1}\\!\\red\\,}          % reduce operator\n\\newcommand{\\getitem}[2]{{#2}\\,\\psi\\,{#1}}        % psi operator\n\n\n\\newcommand{\\scan}[1]{{}_{\\op{#1}\\!}\\mathrm{scan}\\,}\n\\newcommand{\\kron}{\\bigcirc\\,\\!\\!\\!\\!\\!\\!\\times\\;}\n\\newcommand{\\cat}{+\\!\\!\\!+}\n\\newcommand{\\gu}{\\mathrm{gu}\\,}\n\\newcommand{\\gd}{\\mathrm{gd}\\,}\n\\newcommand{\\compress}{\\,\\notslash\\,}\n\\newcommand{\\expand}{\\,\\notbackslash\\,}\n\\newcommand{\\reverse}{\\phi\\,}\n\\newcommand{\\rotate}[1]{{#1}\\theta\\,}\n\n\\title{MoA formalism and arrays in software}\n\\author{Pearu Peterson and Hameer and Saul and Lenore and Travis\\\\\nQuansight, Labs}\n\n\\begin{document}\n\\maketitle\n\\section{Introduction}\n\nMoA - Mathematics of Arrays - defines a formalism (based on APL) to\ndescribe multidimensional arrays and operations on these. On the other\nhand, contemporary array processing software (NumPy, Xnd, Apache\nArrow, etc) implement multidimensional array container objects and\ndefine UI to interact with the array objects. The aim of this document\nis to provide a mapping between MoA formalism and UI-s of widely used\narray processing software.\n\n\\section{Basic definitions}\n\nThe MoA formalism is originally defined in ``A Mathematics of Arrays''\nby Lenore Mullin, PhD thesis, 1988\\cite{mul00}.  We use NumPy UI as a\nrepresentative of a software implementing UI for multidimensional\narrays. For brevity, we assume \\verb+from numpy import *+.\n\n\\noindent\nIn general, \\emph{an array is an object that has a mapping to get\n  array items} \\footnote{A mapping $f$ is a set of argument and value\n  pairs,$(i,v)$, and is represented as $f(i)=v$. We consider only\n  single-valued mappings.} . The arguments to the mapping are called\n\\emph{indices}, all valid indices define the so-called \\emph{index\n  set} of an array. The items can be arbitrary objects.\nTwo arrays are \\emph{equal} iff their get items mappings are equal: their shapes and components are equivalent.\n\\emph{Element-wise operations} of two arrays are defined iff the index\nsets of the two arrays are equal.\nArrays can be classified according to how the mappings are defined:\n\\begin{description}\n\\item[Multidimensional arrays:] The index set of\n  an $N$-dimensional array is an $N$-dimensional hyperrectangle in\n  $\\Z^N$: $[0,\\ldots,s_0-1]\\times\\cdots\\times[0,\\ldots,s_{N-1}-1]$\n  where non-negative integers $(s_0,\\ldots,s_{N-1})$ define the shape\n  of an array.\n\\item[Ragged arrays:] The index set of an\n  $N$-dimensional ragged array is a connected subset of an\n  $N$-dimensional hyperrectangle in $\\Z^N$. The concrete\n  representation of the index set may have different forms.\n\\item[Sparse arrays:] The index set of an sparse array is a possibly\n  disconnected subset of $N$-dimensional hyperrectangle in $\\Z^N$ and\n  is extended to the full hyperrectangle by defining the default\n  value.\n\\end{description}\n\nThe MoA deals with multidimensional arrays only.  The NumPy implements\narray object for multidimensional arrays only. There is one-to-one\nrelation between MoA formalism and NumPy UI. Xnd implements a more\ngeneral container object than NumPy ndarray.\n\nThe goal is to extend MoA formalism to ragged arrays and then use this\nto define an UI as well as optimized algorithms to the array object\nimplementation software such as Xnd. \n\nThe current working hypothesis is that the ragged arrays can be\nrepresented as arrays of arrays where the subarrays are\nmultidimensional arrays.\n\n\\section{Optimization of Arrays in NumPy: Dense to Start}\nWe show how the inclusion of MoA and the Psi Calculus for dense arrays\nreduces to a normal form. This is a powerful concept in that programmers may design an algorithm differently, one may be efficient, another may not, even if the answer is the same. \n\\noindent\nWe show that there will not be performance issues for that choice because all algorithms using the MoA algebra will reduce to the same normal form. Another important concept is that all intermediate arrays are eliminated. Performance analysis and graphs will show this.\n\n\\subsection{An example}\n\nIn the following we demonstrate how to reduce a NumPy array expression\nto its normal form using MoA.\n\nConsider the following NumPy arrays\n\\begin{verbatim}\n>>> A = np.arange(30).reshape((2,3,5))\n>>> B = 2 + A\n>>> A\narray([[[ 0,  1,  2,  3,  4],\n        [ 5,  6,  7,  8,  9],\n        [10, 11, 12, 13, 14]],\n\n       [[15, 16, 17, 18, 19],\n        [20, 21, 22, 23, 24],\n        [25, 26, 27, 28, 29]]])\n>>> B\narray([[[ 2,  3,  4,  5,  6],\n        [ 7,  8,  9, 10, 11],\n        [12, 13, 14, 15, 16]],\n\n       [[17, 18, 19, 20, 21],\n        [22, 23, 24, 25, 26],\n        [27, 28, 29, 30, 31]]])\n\\end{verbatim}\nthat in MoA formalism are represented as\n\\begin{align}\n  A^3 &\\equiv \\vccc235\\reshape(\\range30), \\\\\n  B^3 &\\equiv 2+A^3,\n\\end{align}\nand the following array expression as an example case\n\\begin{verbatim}\n>>> r = np.inner(A[1,0,:], np.outer(A[1,0,:], B[0,1,:])[2,:])\n>>> r\n13175\n\\end{verbatim}\nthat in MoA formalism reads\n\\begin{equation}\nr \\equiv (\\vcc10\\psi A^3) \\innerprod+\\times (\\vc2\\psi((\\vcc10\\psi A^3) \\outerprod\\times (\\vcc01\\psi B^3))).\n\\end{equation}\nNote that when evaluating the array expression directly, the\ncomputation involves 30 multiplication and 4 addition\noperations. Using MoA, we reduce the above array expression to its\nnormal form where the number of operations is minimal.\n\nFirst, the items of the left operand of the inner product are\n\\begin{align*}\n  \\getitem{(\\vcc10\\psi A^3)}{\\vc i} = \\getitem{A^3}{\\vccc10i}\n\\end{align*}\nThe items of the right operand of the inner product are\n\\begin{align}\n&\\getitem{\n  (\\getitem{((\\getitem{A^3}{\\vcc10}) \\outerprod\\times (\\getitem{B^3}{\\vcc01}))}{\\vc2})\n}{\\vc i} \\\\\n&\\equiv \\getitem{((\\getitem{A^3}{\\vcc10}) \\outerprod\\times (\\getitem{B^3}{\\vcc01})))}{\\vcc2i} \\\\\n&\\equiv \\getitem{(\\getitem{A^3}{\\vcc10})}{\\vc2} \\times \\getitem{(\\getitem{B^3}{\\vcc01})}{\\vc i}\\\\\n&\\equiv \\getitem{A^3}{\\vccc102} \\times \\getitem{B^3}{\\vccc01i}\n\\end{align}\nAs a result, we have\n\\begin{align*}\n  r &\\equiv ((\\vcc10\\psi A^3) \\innerprod+\\times  \\getitem{B^3}{\\vcc01})\\times\\getitem{A^3}{\\vccc102}\n\\end{align*}\nthat in NumPy syntax reads\n\\begin{verbatim}\n>>> r_nf = np.inner(A[1,0,:], B[0,1,:]) * A[1,0,2]\n\\end{verbatim}\nwhich contains 6 multiplications and 4 additions.\n\n\\subsection{Performance analysis}\n\nNow let us benchmark the original form of this expression against it's reduced normal form.\nFor $n$ in ${\\{1, 10, 20, ..., 200\\}}$ where $\\shape A \\equiv \\vccc2 3 5 \\times n$ we measured the\nexecution of the original expression and the reduced expression.\n\n\\begin{figure}[h]\n  \\includegraphics[width=1\\textwidth]{benchmarks/visualization-ratio.png}\n  \\caption{The ratio of the mean execution time of evaluating the reduced and the original expression comparing decreases as the shape increases.}\n  \\label{fig:plot}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\includegraphics[width=1\\textwidth]{benchmarks/visualization-ratio.png}\n  \\caption{The ratio of the mean execution time of evaluating the reduced and the original expression comparing decreases as the shape increases.}\n  \\label{fig:plot2}\n\\end{figure}\n\nAs seen in Figure \\ref{fig:plot}, the reduced normal form version is takes a third of the time when $n=1$ and a hundredth of the time when\n~$n=80$. So as $n$ increases, so does the proportional time saving from reducing the expression.\n\nTo reproduce the benchmarks and for all the benchmark data as well as machine information, please go to \\href{https://github.com/Quansight-Labs/uarray-docs/tree/fcb6baf8bb7284ac7223de73a70cf47063df9e4b/benchmarks}{github.com/Quansight-Labs/uarray-docs}.\n\n\\section*{Appendix}\n\n\\subsection*{Multidimensional arrays: MoA and NumPy}\n\n\\begin{comment}\n\\newcommand{\\MoADefinition}[1]{\n  \\begin{itemize}\n  #1\n  \\end{itemize}\n}\n\\newcommand{\\MoAItem}[3]{\\item {#1}\n  \\begin{description}\n  \\item[MoA:] {#2}\n  \\item[NumPy:] {#3}\n  \\end{description}\n}  \n\\end{comment}\n%\\begin{comment}\n\\newcommand{\\MoADefinition}[1]{\n\\renewcommand{\\arraystretch}{2}\n\\begin{longtable}{| p{.5\\textwidth} | p{.5\\textwidth} |}\n#1\n\\end{longtable}\n\\renewcommand{\\arraystretch}{1}\n}\n\\newcommand{\\MoAItem}[3]{\n\\multicolumn2{l}{\n  \\begin{minipage}[l]{0.9\\linewidth} \\vspace{2ex}\n  $\\bullet$ #1\\\\[0.1ex]\n  \\end{minipage}\n}\\\\\\hline\n\\begin{minipage}[l]{0.95\\linewidth}\n{#2}  \n\\end{minipage}\n&\n\\begin{minipage}[l]{0.95\\linewidth}\n{#3}  \n\\end{minipage}\\\\\\hline\n}\n%\\end{comment}\n\n\n\n\nWe have the following correspondence table for basic notions:\n\\MoADefinition{\n  \\MoAItem{a multidimensional array}{$\\xi$}{\\py'x=array(...)'}\n  \\MoAItem{a one dimensional array, a vector}{$\\vec v\\equiv<v_0\\, v_1\\, \\ldots>$}{\\py'v=array([v_0, v_1, ...])'}\n  \\MoAItem{total number of array items}{$\\size\\xi$}{\\py'x.size'}\n  \\MoAItem{the shape of an array is a vector of non-negative integers}{$\\shape\\xi\\equiv<s_0\\, \\ldots\\, s_{n-1}>$}{\\py`x.shape==(s_0,...,s_n1)`}\n  \\MoAItem{the dimensionality of an array is non-negative integer}{$\\dims\\xi\\equiv n\\equiv\\size\\shape\\xi$}{\\py'x.ndim==n==len(x.shape)'}\n  \\MoAItem{an array item}{$\\getitem\\xi{\\vec i}\\equiv\\xi[i_0;\\ldots;i_{n-1}]$}{\\py'x[i_0,...,i_n1]'}\n  \\MoAItem{negative of $k$}{$\\minus k$}{\\py'-k'}\n  \\MoAItem{$\\gamma$ function is used to define the mapping between the indices of an array and its ravelled version}{\n  \\begin{eqnarray*}\n\\gamma(<>;<>)&\\equiv&0\\\\\n\\gamma(\\vec a;\\vec b)&\\equiv&a_{-1} + b_{-1}\\gamma({\\minus1}\\drop{\\vec a}; {\\minus1}\\drop{\\vec b})\n  \\end{eqnarray*}\n}{}\n  \\MoAItem{inverse of $\\gamma$ with respect to the first argument}{$\\gamma'\\ldots \\gamma(\\gamma'(n;\\vec x); \\vec x)=n$}{}\n}\n\nMoA defines a number of operators on multidimensional arrays:\n\\MoADefinition{\n  \\MoAItem{collapse an array to one dimension (row ordering is assumed)}{$\\ravel \\xi$}{\\py'x.ravel()'}\n  \\MoAItem{product of vector items}{$\\product\\vec v$}{\\py'v.prod()'}\n\n}\n\nMoA defines array construction operators:\n\\MoADefinition{\n  \\MoAItem{join a sequences of vectors}{$\\vec v,\\vec w,\\ldots$}{\\py'concatenate((v, w, ...))'}\n  \\MoAItem{a range of integers}{$\\range n\\equiv 0,1+\\range(n-1)$}{\\py'arange(n)'}\n  \\MoAItem{compress}{${\\vec v}_l\\compress{\\vec v}_r$}{\\py''}\n  \\MoAItem{}{${\\vec v}_l\\expand{\\vec v}_r$}{\\py''}\n  % \\MoAItem{}{$$}{\\py''}\n  % \\MoAItem{}{$$}{\\py''}\n}\n\n\nMoA defines various slicing operations:\n\\MoADefinition{\n  \\MoAItem{take first $k$ items; take last $k$ items}{$k\\take{\\vec v}\\,;\\,{\\minus k}\\take{\\vec v} $}{\\py'v[:k] ; v[-k:]'}\n  \\MoAItem{drop first $k$ items; drop last $k$ items}{$k\\drop{\\vec v}\\,;\\,{\\minus k}\\drop{\\vec v} $}{\\py'v[k:] ; v[:-k]'}\n  \\MoAItem{}{$\\sigma\\take\\xi$}{\\py''}\n  \\MoAItem{}{$\\sigma\\drop\\xi$}{\\py''}\n  \\MoAItem{}{${\\vec v}\\take\\xi$}{\\py''}\n  \\MoAItem{}{${\\vec v}\\drop\\xi$}{\\py''}\n}\n\nMoA defines the following relational operators,$(\\rop{R}, \\text{\\py'rop'}) \\in \\{(\\rop{>}, \\text{\\py'gt'}), (\\rop{<}, \\text{\\py'lt'}), (\\rop{=}, \\text{\\py'eq'}), \\ldots\\}$ :\n\\MoADefinition{\n  \\MoAItem{element-wise relational operators}{$\\xi_l\\rop{R}\\xi_r$}{\\py'x_l.__<rop>__(x_r).all()'}\n  \\MoAItem{scalar extension of relational operators}{$\\xi\\rop{R}a$}{\\py'x.__<rop>__(a*ones(x.shape)).all()'}\n  \\MoAItem{}{$a\\,R^{*}\\xi$}{\\py''}\n}\n\nMoA defines the following binary and unary operators, $(\\op{op},\\text{\\py'op'})\\in\\{\n(\\op+, \\text{\\py'add'}), (\\op-, \\text{\\py'sub'}), (\\op\\times, \\text{\\py'mul'}), \\ldots\n\\}$:\n\\MoADefinition{\n  \\MoAItem{element-wise binary operators}{$\\xi_l\\op{op}\\xi_r$}{\\py'x_l.__<op>__(x_r)'}\n  \\MoAItem{scalar extension of binary operators}{$\\xi\\op{op}a\\quad;\\quad a\\op{op}\\xi$}{\\py'x.__op__(a*ones(x.shape))'}\n  \\MoAItem{scalar extension of unary operators}{$\\uop{uop}\\xi$}{\\py'x.__<uop>__()'}\n}\n\nMoA defines various array transformation operators:\n\\MoADefinition{\n  \\MoAItem{reshape a vector}{$\\vec s\\reshape\\vec v$}{\\py'v.reshape(s)'}\n  \\MoAItem{reverse vector items}{$\\reverse \\vec v$}{\\py'v[::-1]'}\n  \\MoAItem{}{$\\rotate{\\sigma}\\xi$}{\\py''}\n  \\MoAItem{transpose of an array}{$\\transpose{\\vec v}\\xi$}{\\py''}\n  \\MoAItem{reduction}{$\\red{op}\\xi\\equiv(\\getitem\\xi{<0>})\\op{op}\\red{op}(1\\drop\\xi)$}{}\n}\n\nOperations with arrays\n\\MoADefinition{\n  \\MoAItem{higher order operation}{\n    $\\getitem{\\hop{f}{\\vec d}}{\\vec i} \\equiv f(\\getitem\\xi{\\vec i})$\n  }{}\n  \\MoAItem{outer product $\\xi_l\\outerprod{\\op{op}}\\xi_r$}{\n    \\begin{align*}\n      \\getitem{\\xi_l\\outerprod{\\op{op}}\\xi_r}{(\\vec i\\cat\\vec j)} \\equiv\n      (\\getitem{\\xi_l}{\\vec i}) \\op{op} (\\getitem{\\xi_r}{\\vec j})\n    \\end{align*}\n  }\n  {\\py|outer(x_l, x_r) FIXME|}\n  \\MoAItem{inner product $\\xi_l\\innerprod{\\op{op_0}}{\\op{op_1}}\\xi_r$}{\n    \\begin{align*}\n      \\getitem{\\xi_l\\innerprod{\\op{op_0}}{\\op{op_1}}\\xi_r}{(\\vec i\\cat \\vec j)}\n      \\equiv\\\\ \n      \\reduce{\\op{op_0}} (\\getitem{\\xi_l}{\\vec i}) \\op{op_1} (\\getitem{\\xi_r}{(\\range q\\hop{\\cat}{\\vcc01}\\vec j)})\n    \\end{align*}\n}{\\py|inner(x_l, x_r) FIXME|}\n}\n\nTODO:\\\\\n\\begin{tabularx}{\\textwidth}{lX}\n\\begin{tabular}[m]{m{0.2\\linewidth}|l|m{0.45\\linewidth}|}\n  MoA & Python & Description \\\\\\hline\n$\\vec i\\psi\\xi;\\qquad \\size\\vec i <\\size\\shape\\xi$ & \\verb|x[i+(Ellipsis,)]| & slice of an array\\\\\n$\\xi_l\\psi\\xi_r$ &&\\\\\n\\multicolumn2{l|}{$\\id{op}\\ldots \\sigma\\op{op}\\id{op}\\equiv\\sigma$}& identity of an operator $\\op{op}$\\\\\n$\\scan{op}$ && \\\\\n$\\xi_l,\\xi_r$ & & \\\\\n$\\xi,\\sigma\\equiv \\xi, (1,(1\\drop{\\shape\\xi}))\\shape\\sigma$ &&\\\\\n$\\vec v[\\vec x]$ &&\\\\\n$\\gu\\vec v\\,;\\,\\gd\\vec v$ &&\\\\\n$\\hop{f}{\\vec a}\\xi$&&\\\\\n$\\xi_l(\\hop{f}{\\vec a})\\xi_r$&&\\\\\n\\end{tabular}  \n\\end{tabularx}\n\n\nReferencing Travis \\cite{travis0}, and Mullin \\cite{mul00}.\n\\bibliography{paper}\n\\bibliographystyle{plain}\n\\end{document}\n", "meta": {"hexsha": "d677c7c06b75a6fde9b818bc9adec1b891f36c1a", "size": 15495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notation.tex", "max_stars_repo_name": "Quansight-Labs/uarray-docs", "max_stars_repo_head_hexsha": "8c9f9d766649d34922e3cf670d91da8746fd67aa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-21T17:38:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-30T00:37:25.000Z", "max_issues_repo_path": "notation.tex", "max_issues_repo_name": "Quansight-Labs/uarray-docs", "max_issues_repo_head_hexsha": "8c9f9d766649d34922e3cf670d91da8746fd67aa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-09-27T10:55:22.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-08T19:02:27.000Z", "max_forks_repo_path": "notation.tex", "max_forks_repo_name": "Quansight-Labs/uarray-docs", "max_forks_repo_head_hexsha": "8c9f9d766649d34922e3cf670d91da8746fd67aa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-28T01:47:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-24T15:55:45.000Z", "avg_line_length": 41.4304812834, "max_line_length": 269, "alphanum_fraction": 0.6673765731, "num_tokens": 5255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6247074586455098}}
{"text": "\n\\subsection{Greedy search}\n\nFind absolute distance from goal for each node. choose node with shortest distance.\n\nCost of each is \\(f(n)=h(n)\\), where \\(h(n)\\) is the heuristic cost of node \\(n\\).\n\n", "meta": {"hexsha": "0278978bfc95e6f05d0c8b632ed1dd524e5dc797", "size": 198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/treeHeuristic/01-01-greedy.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/treeHeuristic/01-01-greedy.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/treeHeuristic/01-01-greedy.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.75, "max_line_length": 83, "alphanum_fraction": 0.702020202, "num_tokens": 51, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.6246505607681025}}
{"text": "\\section{Mixture Models for Jet Tagging}\n\\label{sec:tagging}\n\n\\subsection{Gaussian Mixture Models}\n\nAs a first step we pick the boosted top tagging problem. From Figure \\ref{fig:efp-histogram}, it is apparent that the jets are points N-dimentional space (here 1000 dimentional, we have limited to EFPs of degree <= 7) which originate from several multivariate distributions. The obvious choice to model this data is to fit a Bayesian Gaussian Mixture Model, each distribution being a multivariate Gaussian:\n\\begin{equation}\n    f_{pdf}(X) = \\frac{1}{\\sqrt{(2\\pi)^k \\vert \\Sigma \\vert}} e^{-\\frac{1}{2} (x - \\mu)^T \\Sigma^{-1} (x - \\mu)}\n\\end{equation}\nWe train the model using Expectation Maximization algorithm.\nThe performance of the algorithm is at par with that of LDA (89.2\\% on the top tagging dataset).\n\n\n\\subsection{Maxwellian Mixture Models}\n\nThe performance of the GMM is marred by the fact that the distributions of EFPs are actually maxwellian. The skew of the distributions is high for the top quarks even at low degrees and increases as the degree of the EFP increases. Therefore it behooves us to model the data using the Maxwellian distribution, which follows.\n\n\nWe model the multivariate form of the Maxwell-Boltzmann Distribution as follows ~\\cite{maxwellian_multivariate}.\n\\begin{equation}\n    f_{pdf}(X) = \\frac{b^{1 + \\frac{n}{2}} \\vert B \\vert^\\frac{n}{2} \\Gamma(\\frac{n}{2})}{\\pi^{\\frac{n}{2}} \\Gamma(1 + \\frac{n}{2})} [XBX^T] e^{-b(XBX^T)}\n\\end{equation}\nThe parameters being learnt will be the $n \\times n$ sized matrix $B$. $X$ is the input vector to the model of shape $n \\times 1$ and the the constant $b$ is the determinant of the matrix $B$, which together with the Gamma functions serves the task of normalization.\n\n\\textcolor{red}{This distribution will be trained on using the Expectation Maximization algorithm, details of the E- step and M- step will be added here, together with any improvements in performance. ~\\cite{maxwellian_plasma}}\n\n\n\\subsection{Performance of the Models}\n\nFollowing is the performance of the algorithms on the Top Tagging dataset \\cite{data_toptagging}.\n\\begin{table}\n    \\caption{Performance on Top Tagging \\cite{tagging_review}}\n    \\label{tab:1}\n    \\begin{tabular}{lll}\n        \\hline\\noalign{\\smallskip}\n        Model Name                                           & Accuracy & ROC AUC \\\\\n        \\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n        \\textbf{Bayessian Maxwellian Mixture Model with EFP} & UNK      & UNK     \\\\\n        \\textbf{Bayesian Gaussian Mixture Model with EFP}    & 89.224\\% & UNK     \\\\\n        Latent Dirichlet Allocation                          & 89.2\\%   & 0.955   \\\\\n        \\noalign{\\smallskip}\\hline\n        Linear Discriminant Analysis with EFP                & 93.2\\%   & 0.980   \\\\\n        ParticleNet (Graph Neural Net on Point Cloud)        & 93.8\\%   & 0.985   \\\\\n        \\noalign{\\smallskip}\\hline\n    \\end{tabular}\n\\end{table}\n\n\\textcolor{red}{Add accuracy figures on the QCD tagging dataset \\cite{data_qcdtagging}}\n\n\\subsection{Features of probabilistic tagging}\n\nWhile boosted top tagging is solved to a very high accuracy, the following attributes are still sought for:\n\\begin{itemize}\n    \\item To know what confidence we have tagged a single jet with? - As seen from the histograms, some jets are very clearly in the Top or QCD domain, the overlap of the two is the set of jets where most algorithms fail. When tagging, a model should be able to output both the class label and the confidence figure.\n    \\item Resilliance to unseen input, and ability to fail gracefully if the input jet is not unlike what the model has seen before? This may be due to errors by the clustering algorithm which has clustered multiple jets together or because of an unknown decay type.\n\\end{itemize}\nA probabilistic Bayesian generative model is the best attempt at modelling the probability with which we are tagging a jet.\n\n\\textcolor{red}{Show experimental proof that we are indeed resilliant against mutliple-jet in one jet image and against unknown jet types}.\n\\textcolor{yellow}{We need to explore what set of features help models like ParticleNet \\cite{particle_net} perform better in the overlap zone, and it's performance relative to our confidence, as in the Orange comparative scatters.}", "meta": {"hexsha": "0393a9eff19aa637a812316020fcab593c152b2c", "size": 4292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/tex/tagging.tex", "max_stars_repo_name": "Blizzard57/jet-tagging", "max_stars_repo_head_hexsha": "b338b0d55380a6d21e2f78d7098650b0806f7cfc", "max_stars_repo_licenses": ["MIT"], "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/tex/tagging.tex", "max_issues_repo_name": "Blizzard57/jet-tagging", "max_issues_repo_head_hexsha": "b338b0d55380a6d21e2f78d7098650b0806f7cfc", "max_issues_repo_licenses": ["MIT"], "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/tagging.tex", "max_forks_repo_name": "Blizzard57/jet-tagging", "max_forks_repo_head_hexsha": "b338b0d55380a6d21e2f78d7098650b0806f7cfc", "max_forks_repo_licenses": ["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.5333333333, "max_line_length": 406, "alphanum_fraction": 0.7269338304, "num_tokens": 1098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6246505492109432}}
{"text": "%!TEX root = ../OGUSAdoc.tex\n\nThis appendix contains derivations from the theory in the body of this book.\n\n\n\\section{Properties of the CES Production Function}\\label{SecAppDerivCES}\n\n  The constant elasticity of substitution (CES) production function of capital and labor was introduced by \\citet{Solow:1956} and further extended to a consumption aggregator by \\citet{Armington:1969}. The CES production function of aggregate capital $K_t$ and aggregate labor $L_t$ we use in Chapter \\ref{Chap_Firms} is the following,\n  \\begin{equation}\\tag{\\ref{EqFirmsCESprodfun}}\n    Y_t = F(K_t, L_t) \\equiv Z_t\\biggl[(\\gamma)^\\frac{1}{\\ve}(K_t)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}(e^{g_y t}L_t)^\\frac{\\ve-1}{\\ve}\\biggr]^\\frac{\\ve}{\\ve-1} \\quad\\forall t\n  \\end{equation}\n  where $Y_t$ is aggregate output (GDP), $Z_t$ is total factor productivity, $\\gamma$ is a share parameter that represents the capital share of income in the Cobb-Douglas case ($\\ve=1$), and $\\ve$ is the elasticity of substitution between capital and labor. The stationary version of this production function is given in Chapter \\ref{Chap_Stnrz}. We drop the $t$ subscripts, the ``$\\:\\hat{\\,}\\:$''stationary notation, and use the stationarized version of the production function \\eqref{EqStnrzCESprodfun} for simplicity.\n  \\begin{equation}\\tag{\\ref{EqStnrzCESprodfun}}\n    Y =  Z\\biggl[(\\gamma)^\\frac{1}{\\ve}(K)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}(L)^\\frac{\\ve-1}{\\ve}\\biggr]^\\frac{\\ve}{\\ve-1}\n  \\end{equation}\n  The Cobb-Douglas production function is a nested case of the general CES production function with unit elasticity $\\ve=1$.\n  \\begin{equation}\\label{EqAppDerivCES_CobbDoug}\n    Y = Z(K)^\\gamma(L)^{1-\\gamma}\n  \\end{equation}\n\n\n\n  \\subsection{Wages as a function of interest rates}\\label{SecAppDerivCESwr}\n\n    An important property of the CES production function for the solution method of \\ogindia is that the interest rate $r_t$ and wage $w_t$ are functions of the capital labor ratio. This property implies that the wage every period $w_t$ is just a function of the interest rate $r_t$, and vice versa. The first step is to show that the output-capital ratio ($Y/K$) and the output-labor ($Y/L$) ratio are both functions of the capital-labor ratio ($K/L$).\n    \\begin{equation}\\label{EqAppDerivCES_YL}\n      \\begin{split}\n      Y &= Z\\biggl[(\\gamma)^\\frac{1}{\\ve}(K)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}(L)^\\frac{\\ve-1}{\\ve}\\biggr]^\\frac{\\ve}{\\ve-1} \\\\\n      &= Z\\left[(\\gamma)^\\frac{1}{\\ve}(K)^\\frac{\\ve-1}{\\ve}\\left(\\frac{L^\\frac{\\ve-1}{\\ve}}{L^\\frac{\\ve-1}{\\ve}}\\right) + (1-\\gamma)^\\frac{1}{\\ve}(L)^\\frac{\\ve-1}{\\ve}\\right]^\\frac{\\ve}{\\ve-1} \\\\\n      &= ZL\\left[(\\gamma)^\\frac{1}{\\ve}\\left(\\frac{K}{L}\\right)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\right]^\\frac{\\ve}{\\ve-1} \\\\\n      \\Rightarrow\\quad \\frac{Y}{L} &= Z\\left[(\\gamma)^\\frac{1}{\\ve}\\left(\\frac{K}{L}\\right)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\right]^\\frac{\\ve}{\\ve-1}\n      \\end{split}\n    \\end{equation}\n\n    \\begin{equation}\\label{EqAppDerivCES_YK}\n      \\begin{split}\n      Y &= Z\\biggl[(\\gamma)^\\frac{1}{\\ve}(K)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}(L)^\\frac{\\ve-1}{\\ve}\\biggr]^\\frac{\\ve}{\\ve-1} \\\\\n      &= Z\\left[(\\gamma)^\\frac{1}{\\ve}(K)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}(L)^\\frac{\\ve-1}{\\ve}\\left(\\frac{K^\\frac{\\ve-1}{\\ve}}{K^\\frac{\\ve-1}{\\ve}}\\right)\\right]^\\frac{\\ve}{\\ve-1} \\\\\n      &= ZK\\left[(\\gamma)^\\frac{1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\left(\\frac{L}{K}\\right)^\\frac{\\ve-1}{\\ve}\\right]^\\frac{\\ve}{\\ve-1} \\\\\n      \\Rightarrow\\quad \\frac{Y}{K} &= Z\\left[(\\gamma)^\\frac{1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\left(\\frac{L}{K}\\right)^\\frac{\\ve-1}{\\ve}\\right]^\\frac{\\ve}{\\ve-1}\n      \\end{split}\n    \\end{equation}\n\n    Solving for the firm's first order conditions for capital and labor demand from profit maximization \\eqref{EqStnrzProfit} gives the following equations in their respective stationarized forms from Chapter \\ref{Chap_Stnrz}.\n    \\begin{align}\n      w &= (Z)^\\frac{\\ve-1}{\\ve}\\left[(1-\\gamma)\\left(\\frac{Y}{L}\\right)\\right]^\\frac{1}{\\ve} \\tag{\\ref{EqStnrzFOC_L}} \\\\\n      r &= (1 - \\tau^{corp})(Z)^\\frac{\\ve-1}{\\ve}\\left[\\gamma\\left(\\frac{Y}{K}\\right)\\right]^\\frac{1}{\\ve} - \\delta + \\tau^{corp}\\delta^\\tau \\tag{\\ref{EqFirmFOC_K}}\n    \\end{align}\n    As can be seen from \\eqref{EqStnrzFOC_L} and \\eqref{EqFirmFOC_K}, the wage $w$ and interest rate $r$ are functions of $Y/L$ and $Y/K$, respectively. Equations \\eqref{EqAppDerivCES_YL} and \\eqref{EqAppDerivCES_YK} show that both $Y/L$ and $Y/K$ are functions of the capital-labor ratio $K/L$. Substituting \\eqref{EqAppDerivCES_YL} and \\eqref{EqAppDerivCES_YK} into \\eqref{EqStnrzFOC_L} and \\eqref{EqFirmFOC_K}, respectively, gives expressions of the wage $w$ and interest rate $r$ in terms of the capital-labor ratio $K/L$.\n    \\begin{align}\n      w &= (1-\\gamma)^\\frac{1}{\\ve}Z\\left[(\\gamma)^\\frac{1}{\\ve}\\left(\\frac{K}{L}\\right)^\\frac{\\ve-1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\right]^\\frac{1}{\\ve-1} \\label{EqAppDerivCES_FOCL} \\\\\n      r &= (1 - \\tau^{corp})(\\gamma)^\\frac{1}{\\ve}Z\\left[(\\gamma)^\\frac{1}{\\ve} + (1-\\gamma)^\\frac{1}{\\ve}\\left(\\frac{L}{K}\\right)^\\frac{\\ve-1}{\\ve}\\right]^\\frac{1}{\\ve-1} - \\delta + \\tau^{corp}\\delta^\\tau \\label{EqAppDerivCES_FOCK}\n    \\end{align}\n    In the Cobb-Douglas unit elasticity case ($\\ve=1$) of the CES production function, the first order conditions are more easily expressed in terms of the capital-labor ratio.\n    \\begin{align}\n      \\text{if}\\:\\:\\,\\ve=1:\\quad w &= (1-\\gamma)Z\\left(\\frac{K}{L}\\right)^\\gamma \\label{EqAppDerivCES_CDFOCL} \\\\\n      \\text{if}\\:\\:\\:\\ve=1:\\quad r &= (1 - \\tau^{corp})\\gamma Z\\left(\\frac{L}{K}\\right)^{1-\\gamma} - \\delta + \\tau^{corp}\\delta^\\tau \\label{EqAppDerivCES_CDFOCK}\n    \\end{align}\n\n    With $w$ and $r$ expressed in terms of the capital-labor ratio $K/L$ in \\eqref{EqAppDerivCES_FOCL} and \\eqref{EqAppDerivCES_FOCK}, we can write the expressions for the capital-labor ratio as a function of the interest rate and, therefore, the wage as a function of the interest rate. We first solve equation \\eqref{EqAppDerivCES_FOCK} for the capital-labor ratio to get the expression for $K/L$ as a function of the interest rate $r$.\n    \\begin{equation}\\label{EqAppDerivCES_KLr}\n      \\frac{K}{L} = \\left(\\frac{(1-\\gamma)^\\frac{1}{\\ve}}{\\left[\\frac{r + \\delta - \\tau^{corp}\\delta^\\tau}{(1 - \\tau^{corp})\\gamma^\\frac{1}{\\ve}Z}\\right]^{\\ve-1} - \\gamma^\\frac{1}{\\ve}}\\right)^\\frac{\\ve}{\\ve-1}\n    \\end{equation}\n    In the Cobb-Douglas unit elasticity case ($\\ve=1$), we solve equation \\eqref{EqAppDerivCES_CDFOCK} for the capital-labor ration to get the expression for $K/L$ as a function of the interest rate $r$.\n    \\begin{equation}\\label{EqAppDerivCES_CDKLr}\n      \\text{if}\\:\\:\\:\\ve=1:\\quad \\frac{K}{L} = \\left[\\frac{(1 - \\tau^{corp})\\gamma Z}{r + \\delta - \\tau^{corp}\\delta^\\tau}\\right]^\\frac{1}{1-\\gamma}\n    \\end{equation}\n\n    Substituting \\eqref{EqAppDerivCES_KLr} into \\eqref{EqAppDerivCES_FOCL} gives the expression for the wage $w$ as a function of the interest rate $r$ in the general CES case.\n    \\begin{equation}\\label{EqAppDerivCES_wr}\n      w = (1-\\gamma)^\\frac{1}{\\ve}Z\\left[(\\gamma)^\\frac{1}{\\ve}\\left(\\frac{(1-\\gamma)^\\frac{1}{\\ve}}{\\left[\\frac{r + \\delta - \\tau^{corp}\\delta^\\tau}{(1 - \\tau^{corp})\\gamma^\\frac{1}{\\ve}Z}\\right]^{\\ve-1} - \\gamma^\\frac{1}{\\ve}}\\right) + (1-\\gamma)^\\frac{1}{\\ve}\\right]^\\frac{1}{\\ve-1}\n    \\end{equation}\n    In the Cobb-Douglas unit elasticity case ($\\ve=1$), we substitute \\eqref{EqAppDerivCES_CDKLr} into \\eqref{EqAppDerivCES_CDFOCL} gives the expression for the wage $w$ as a function of the interest rate $r$.\n    \\begin{equation}\\label{EqAppDerivCES_CDwr}\n      \\text{if}\\:\\:\\:\\ve=1:\\quad w = (1-\\gamma)Z\\left[\\frac{(1 - \\tau^{corp})\\gamma Z}{r + \\delta - \\tau^{corp}\\delta^\\tau}\\right]^\\frac{\\gamma}{1-\\gamma}\n    \\end{equation}\n", "meta": {"hexsha": "64c832db73c0bf8bda79762e1303788396997433", "size": 7833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/LaTeXsource/Chapters/Chap_Deriv.tex", "max_stars_repo_name": "keshavchoudhary87/OG-India", "max_stars_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-31T11:19:15.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-31T11:19:15.000Z", "max_issues_repo_path": "docs/LaTeXsource/Chapters/Chap_Deriv.tex", "max_issues_repo_name": "keshavchoudhary87/OG-India", "max_issues_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-08-16T15:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T07:07:15.000Z", "max_forks_repo_path": "docs/LaTeXsource/Chapters/Chap_Deriv.tex", "max_forks_repo_name": "keshavchoudhary87/OG-India", "max_forks_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 44, "max_forks_repo_forks_event_min_datetime": "2019-08-16T15:10:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-08T07:03:26.000Z", "avg_line_length": 101.7272727273, "max_line_length": 526, "alphanum_fraction": 0.6565811311, "num_tokens": 2875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326726, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6246295278790287}}
{"text": "\\section{Introduction}\\label{introduction}\n%=========================================\n\nThe aim of this paper is to introduce an approach to 2D and 3D\ncomputational topology and geometry using a \\emph{GraphBLAS} sparse matrix\nrepresentation of \\emph{chain complexes} with linear operators $\\partial_p$ and $\\delta_{p-1} = \\partial_p^\\top$ between linear \\emph{chain} spaces $C_p$:\n\\[ \nC_\\bullet = (C_p, \\partial_p) := \nC_3 \\ \n\\substack{\n\\delta_2 \\\\\n\\longleftarrow \\\\[-1mm]\n\\longrightarrow \\\\\n\\partial_3 \n}\n\\ C_2 \\ \n\\substack{\n\\delta_1 \\\\\n\\longleftarrow \\\\[-1mm]\n\\longrightarrow \\\\\n\\partial_2 \n}\n\\ C_1 \\ \n\\substack{\n\\delta_0 \\\\\n\\longleftarrow \\\\[-1mm]\n\\longrightarrow \\\\\n\\partial_1 \n}\n\\ C_0 .\n\\] \nLet us to remark preliminary that when $p\\in \\{0,1\\}$, a chain complex is a representation of a \\emph{graph}, with $[\\partial_1]$ the \\emph{incidence matrix} between 1-chains (edges) in $C_1$ and 0-chains (vertices) in $C_0$. Also, the multiplication $[\\partial_1][\\delta_0]=[\\partial_1][\\partial_1]^t$ gives the \\emph{adjacency} matrix of the graph, while the diagonal entries provide the degrees of vertices, defined by the number of incident edges on each vertex. The \\emph{GraphBLAS} standard~\\cite{GraphBLAS:standard} provides a small set of matrix primitives to compute graph properties that, combined together, allow for easy implementation of fast algorithms on large graphs.\n\nIn several application of computational geometry and topology---including\ngeo-mapping, building information modeling (BIM), medical imaging, CAD and\nsolid modeling, virtual and augmented reality, finite element modeling\nand simulation (FEM, FEA), etc.---the amount and detail of 2D and/or 3D data\ncontinue to grow. Analogously, the need for an unified approach to\ngraph algorithms and for unified and simplified interfaces, has been\nwell intercepted by the GraphBLAS initiative and the related \nstandardization effort~\\href{http://graphblas.org}{\\texttt{graphblas.org}}. \nThis paper aim is to show that the domaincovering of this standard library on graphs can be greatly extended, to cover the representation of more general \\emph{cellular $d$-complexes} ($1\\leq d\\leq 3$) and their $p$-skeletons ($0\\leq p\\leq 3$).\n\n(Co)chain complexes, as well (co)boundary operators, are well-known\nbasic tools of algebraic topology and homological algebra. In\nparticular, a \\emph{chain complex} is a graded sequence of such linear\noperators between graded linear spaces of ``chains''. A $p$-chain can be seen as a subset of a finite set $\\texttt{V}$ of Euclidean points whose affine hull has dimension $p$.\nChain spaces and sparse matrices are the components of the Linear Algebraic\nRepresentation (\\texttt{LAR})~\\cite{Dicarlo:2014:TNL:2543138.2543294}, that is being used for\nboundary, decompositive, and enumerative\nrepresentations~\\cite{Requicha:1980:RRS:356827.356833} of models of rigid solid objects.\n\nSome numerical methods aiming to integrate domain modeling, differential\ntopology, mathematical modeling, and physical simulations were based on chains and\ncochains, starting with~\\cite{PALMER1995733,Palmer1993}. In particular,\nDiscrete Exterior Calculus (DEC) with simplicial complexes was\nintroduced by \\cite{Hirani:2003:DEC:959640} and made popular by\n\\cite{Desbrun:2006:DDF:1185657.1185665,Elcott:2006:BYO:1185657.1185666}.\nFinite Element Exterior Calculus \n(FEEC) is an advance in the mathematics of finite element \nmethods~\\cite{arnold_falk_winther_2006,Arnold:2010,Arnold:2018} that employs differential\ncomplexes to construct stable numerical schemes. The Cell\nMethod~(CM) is a purely algebraic computational method\nfor modeling and\nsimulation~\\cite{Tonti:1975,Tonti:2013,Ferretti:2014}\nbased on boundary/coboundary maps and a direct discrete formulation of\nfield laws. Our own research in geometrical and physical modeling with\nchain and cochain complexes was introduced in\n\\cite{DiCarlo:2009:DPU:1629255.1629273,ieee-tase,Dicarlo:2014:TNL:2543138.2543294}.\n\nMore recently, we provided---using sparse\nmatrices---an algorithmic pipeline~\\cite{TSAS:19} to compute the \\emph{arrangement} of the\nEuclidean \\(d\\)-space (\\(d=2,3\\)), i.e.~the partition of\nit into a cellular \\(d\\)-complex, starting from a collection of (possibly intersecting) cellular\n(\\(d\\)-1)-complexes embedded in \\(\\E^d\\). In~\\cite{paoluzzi2019finite} we\nhave shown that the \\emph{atoms} of the Boolean algebra generated by\nsuch space partition correspond one-to-one to the columns of the $[\\partial_d]$ matrix\nof the boundary operator \\(\\partial_d : C_d \\to C_{d-1}\\). This allows for fast\nnative reconstruction of every solid expression in the \\emph{solid algebra} of\n\\(d\\)-space generated by the input terms, usually called Constructive Solid Geometry (CSG)\nin solid modeling~\\cite{Requicha:1980:RRS:356827.356833}.\n\nThe topological background of linear chain spaces and chain complexes is summarized in \nSection~\\ref{sec:background}, together with the concepts of boundary and coboundary linear maps between chain spaces.\nIn Section~\\ref{chain-adjacencies-and-incidensies} an operational definition of topological queries through composition of operators corresponding to products of their sparse matrices is discussed.\nIn Section~\\ref{boolean-algebras} an interpretation as a Boolean algebra of the partition of the Euclidean $d$-space produced by a collection of geometric objects is provided.\nThe implementation of such concepts using GraphBLAS is given in Section~\\ref{graphblas-implementation}. Some simple examples of topology computation using linear algebra are shown in  Section~\\ref{examples}.\nIn the Conclusion Section we briefly summarize our main points, state our findings, and propose some possible extension of this approach.\n", "meta": {"hexsha": "45e0df8a2b840817a64e002060035b1e109a87d4", "size": 5696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/introduction.tex", "max_stars_repo_name": "cvdlab/Chain-BLAS", "max_stars_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_stars_repo_licenses": ["MIT"], "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/introduction.tex", "max_issues_repo_name": "cvdlab/Chain-BLAS", "max_issues_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_issues_repo_licenses": ["MIT"], "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/introduction.tex", "max_forks_repo_name": "cvdlab/Chain-BLAS", "max_forks_repo_head_hexsha": "38a2413ccefd1bc47ae404215e3616d21b16a89e", "max_forks_repo_licenses": ["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.0, "max_line_length": 683, "alphanum_fraction": 0.7808988764, "num_tokens": 1518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.624629524973072}}
{"text": "\\section{Transaction Costs Problem}\n\\label{sec:83problem}\n\n\\minitoc[-6mm]{70mm}{4}\n\n\\vspace{-1.5em}\n\n\\paragraph{Description}\n\nIn the \\term{transaction costs problem,}\nthe individual can invest their money risk-free in bonds\n(with a fixed interest rate similar to a bank account)\nor in $m_{\\vstock} \\in \\nat$ different risk-affected stocks\n\\cite{Schober18Solving}.\nEvery stock transaction,\ni.e., buy $\\buy_{t,j}$ or sell $\\sell_{t,j}$,\ninflicts transaction costs $\\tac \\buysell_{t,j}$ ($\\tac \\in \\nonnegreal$)\nproportional to the amount $\\buysell_{t,j}$ bought or sold\n($j = 1, \\dotsc, m_{\\vstock}$).\nThe individual only wants to invest a fixed\namount $\\wealth_0$ in stocks, i.e., we omit the individual's income.\n\n\n\n\\subsection{Unnormalized Problem}\n\\label{sec:831unnormalized}\n\n\\paragraph{Consumption and state transition}\n\nIn the following,\n$\\stock_{t,j}$ denotes the fraction of the total wealth $\\wealth_t$\nthat is invested in the $j$-th stock.\nWe combine these \\term{stock fractions} $\\stock_{t,j}$\nin a vector $\\vstock_t \\ceq (\\stock_{t,1}, \\dotsc, \\stock_{t,m_{\\vstock}})$;\nsimilarly, $\\vbuysell_t \\ceq (\\buysell_{t,1}, \\dotsc, \\buysell_{t,m_{\\vstock}})$\ncombines buy and sell amounts.\nThen, the consumption can be computed as a residual variable\n(i.e., a variable that can be fully computed from $\\state$ and $\\policy$\nand is thus omitted from $\\policy$),\nwhich is given by\n\\begin{equation}\n  \\consume_t\n  \\ceq (1 - \\sumfcn(\\vstock_t)) \\wealth_t - \\bond_t -\n  (1 + \\tac) \\sumfcn(\\vbuy_t) + (1 - \\tac) \\sumfcn(\\vsell_t),\n\\end{equation}\nwhere $\\sumfcn(\\*a) \\ceq \\tr{\\*1} \\*a$\nis the sum of all entries of $\\*a$.\nThe state transition is computed by adding the returns of bonds and stocks:%\n\\begin{equation}\n  \\wealth_{t+1}\n  \\ceq \\bond_t \\bondreturn_t +\n  %\\sum_{j=1}^{m_{\\vstock}}\n  %(\\stock_{t,j} \\wealth_t + \\buy_{t,j} - \\sell_{t,j}) \\stockreturn_{t,j},\\\\\n  \\tr{(\\vstock_t \\wealth_t + \\vbuy_t - \\vsell_t)} \\vstockreturn_t,\\qquad\n  \\vstock_{t+1}\n  \\ceq \\frac{\n    (\\vstock_t \\wealth_t + \\vbuy_t - \\vsell_t) \\compmult \\vstockreturn_t\n  }{\\wealth_{t+1}},\n\\end{equation}\nwhere $\\bondreturn_t \\in \\real$ is the bond interest rate,\n$\n  \\vstockreturn_t\n  = (\\stockreturn_{t,1}, \\dotsc, \\stockreturn_{t,m_{\\vstock}})\n  \\in \\real^{m_{\\vstock}}\n$\nis the vector of (stochastic) stock return rates, and\n$\\compmult$ is component-wise multiplication.\n\n\n\n\\subsection{Normalization}\n\\label{sec:832normalized}\n\n\\paragraph{State transition}\n\nThe above equations can be normalized with respect to the wealth\n$\\wealth_t$:\nBy setting\n$\\normconsume_t  \\ceq \\consume_t/\\wealth_t$,\n$\\normbond_t     \\ceq \\bond_t   /\\wealth_t$, and\n$\\vnormbuysell_t \\ceq \\vbuysell_t/\\wealth_t$, we obtain\n\\begin{subequations}\n  \\label{eq:normalizedTCPStateTransition}\n  \\begin{align}\n    \\normconsume_t\n    &\\mathrel{\\righthphantom{=}{\\ceq}}\n    (1 - \\sumfcn(\\vstock_t)) - \\normbond_t -\n    (1 + \\tac) \\sumfcn(\\vnormbuy_t) + (1 - \\tac) \\sumfcn(\\vnormsell_t),\\\\\n    \\wealthratio_{t+1}\n    &\\ceq \\normbond_t \\bondreturn_t +\n    \\tr{(\\vstock_t + \\vnormbuy_t - \\vnormsell_t)} \\vstockreturn_t,\n    \\qquad(= \\wealth_{t+1}/\\wealth_t)\\\\\n    \\vstock_{t+1}\n    &\\mathrel{\\righthphantom{=}{\\ceq}}\n    \\frac{\n      (\\vstock_t + \\vnormbuy_t - \\vnormsell_t) \\compmult \\vstockreturn_t\n    }{\\wealthratio_{t+1}},\n  \\end{align}\n\\end{subequations}\nwhere $\\normconsume_t$ and $\\wealthratio_{t+1}$ are residual\nvariables that specify \\term{normalized consumption} and\n\\term{wealth ratio,} respectively.\nAll in all, the resulting dynamic portfolio choice model has\nthe following variables:\n\\begin{itemize}\n  \\item\n  $\\centerhphantom{d}{m_{\\stochastic}} = m_{\\vstock}$\n  state variables $\\normstate_t$:\n  Stock fractions $\\stock_{t,1}, \\dotsc, \\stock_{t,m_{\\vstock}}$\n  \n  \\item\n  $\\centerhphantom{m_{\\policy}}{m_{\\stochastic}} = 2m_{\\vstock} + 1$\n  policy variables $\\normpolicy_t$:\n  Normalized bonds $\\normbond_t$,\n  normalized buy amounts $\\normbuy_{t,1}, \\dotsc, \\normbuy_{t,m_{\\vstock}}$ and\n  normalized sell amounts $\\normsell_{t,1}, \\dotsc, \\normsell_{t,m_{\\vstock}}$\n  \n  \\item\n  $m_{\\stochastic} = m_{\\vstock}$\n  stochastic variables $\\stochastic_t$:\n  Stock return rates $\\stockreturn_{t,1}, \\dotsc, \\stockreturn_{t,m_{\\vstock}}$\n\\end{itemize}\nThe state space and policy space constraints are given by\n\\begin{subequations}\n  \\label{eq:normalizedTCPConstraints}\n  \\newcommand*{\\centereqline}[1]{%\n    \\mathclap{\\hphantom{\\mathrm{(8.99a)}}#1}%\n  }%\n  \\begin{gather}\n    \\label{eq:normalizedTCPConstraintsShort}\n    \\centereqline{\n      \\vstock_t \\ge \\*0,\\qquad\n      \\sumfcn(\\vstock_t) \\le 1,\\qquad\n      \\normbond_t \\ge 0,\\qquad\n      \\vnormbuysell_t \\ge \\*0,\\qquad\n      \\vnormsell_t \\le \\vstock_t,\\qquad\n      \\wealthratio_{t+1} \\ge 0,\n    }\\\\\n    \\label{eq:normalizedTCPConstraintsLong}\n    \\centereqline{\n      \\normconsume_{\\min} + \\normbond_t +\n      (1 + \\tac) \\sumfcn(\\vnormbuy_t) - (1 - \\tac) \\sumfcn(\\vnormsell_t)\n      \\le 1 - \\sumfcn(\\vstock_t),\n    }\n  \\end{gather}\n\\end{subequations}\nwhere $\\normconsume_{\\min} \\in \\nonnegreal$ is some minimal consumption\nthat must be maintained.\n\n\\paragraph{Bellman equation}\n\nConsequently, the Bellman equation \\eqref{eq:gridBellmanCET}\nafter the certainty-equiva\\-lent transformation has to be\nnormalized as well.\nBy setting $\\normcetvalueintp_t(\\state_t^{(k)})\n\\ceq \\cetvalueintp_t(\\state_t^{(k)})/\\wealth_t$, we obtain\n\\begin{subequations}\n  \\begin{align}\n    %\\normcetvalueintp_t(\\state_t^{(k)})\n    %&= \\frac{\\cetvalueintp_t(\\state_t^{(k)})}{\\wealth_t}\\\\\n    %&= \\max_{\\policy_t} \\left(\n    %  \\left(\n    %    \\left(\n    %      \\frac{\\consume_t(\\state_t^{(k)}, \\policy_t)}{\\wealth_t}\n    %    \\right)^{1-\\riskav} +\n    %    \\patience \\expectation[t]{\n    %      \\left(\n    %        \\frac{\n    %          \\cetvalueintp_{t+1}(\n    %            \\statefcn_t(\\state_t^{(k)}, \\policy_t, \\stochastic_t)\n    %          )\n    %        }{\n    %          \\wealth_t\n    %        }\n    %      \\right)^{1-\\riskav}\n    %    }\n    %  \\right)^{1/(1-\\riskav)}\n    %\\right)\\\\\n    &\\hphantom{=}\\hspace{0.6em} \\normcetvalueintp_t(\\state_t^{(k)})\n    = \\wealth_t^{-1} \\cetvalueintp_t(\\state_t^{(k)})\\\\\n    &= \\max_{\\policy_t} \\left(\n      \\left(\n        \\left(\n          \\wealth_t^{-1} \\consume_t(\\state_t^{(k)}, \\policy_t)\n        \\right)^{1-\\riskav} +\n        \\patience \\expectation[t]{\n          \\left(\n            \\wealth_t^{-1} \\cetvalueintp_{t+1}(\n              \\statefcn_t(\\state_t^{(k)}, \\policy_t, \\stochastic_t)\n            )\n          \\right)^{1-\\riskav}\n        }\n      \\right)^{1/(1-\\riskav)}\n    \\right)\\\\\n    \\label{eq:normalizedTCPBellmanEquation}\n    &= \\max_{\\normpolicy_t} \\left(\n      \\left(\n        \\normconsume_t(\\state_t^{(k)}, \\normpolicy_t)^{1-\\riskav} +\n        \\patience \\expectation[t]{\n          \\bigl(\n            \\wealthratio_{t+1} \\normcetvalueintp_{t+1}(\n              \\normstatefcn_t(\\state_t^{(k)}, \\normpolicy_t, \\stochastic_t)\n            )\n          \\bigr)^{1-\\riskav}\n        }\n      \\right)^{1/(1-\\riskav)}\n    \\right).\n  \\end{align}\n\\end{subequations}\nThis means that compared with %the unnormalized Bellman equation\n\\eqref{eq:gridBellmanCET},\nthe value function in the expectation has to be multiplied by\nthe wealth ratio $\\wealthratio_{t+1}$ introduced above in\n\\eqref{eq:normalizedTCPStateTransition}.\nSince there is no inheritance, the optimal terminal solution\nis to sell all stocks and consume everything:\n\\begin{equation}\n  \\normcetvalueintp_t(\\state_T^{(k)})\n  = 1 - \\tac \\sumfcn(\\vstock_T^{(k)}),\\quad\n  \\normbond_T^{\\opt}(\\state_T^{(k)})\n  = 0,\\quad\n  \\vnormbuy[\\opt]_T(\\state_T^{(k)})\n  = \\*0,\\quad\n  \\vnormsell[\\opt]_T(\\state_T^{(k)})\n  = \\vstock_T^{(k)}.\n\\end{equation}\n\n\n\n\\subsection{State Space Cropping}\n\\label{sec:833cropping}\n\n\\paragraph{Sparse grids on non-rectangular domains}\n\nUnfortunately, the constraint $\\sumfcn(\\vstock_t) \\le 1$\nfrom \\cref{eq:normalizedTCPConstraints} limits the feasible state space\nregion to a proper subset (which is the unit simplex)\nof the unit hypercube $\\clint{\\*0, \\*1}$,\nwhich impedes the direct application of sparse grids.\nThere are three possible remedies:\ntransforming the unit hypercube to the feasible state space,\napplying extrapolation techniques as discussed in\n\\cref{sec:825interpolation}, or\nchoosing a model-tailored approach to obtain\nfunction values outside the feasible state space.\n\n\\paragraph{Virtual selling of stocks}\n\nWe choose the third remedy and \\term{virtually sell,}\nif $\\sumfcn(\\vstock_t) > 1$,\nas many stocks as needed to meet the constraint $\\sumfcn(\\vstock_t) \\le 1$.\nWe already might need to sell stocks\neven if $\\sumfcn(\\vstock_t)$ is smaller but close to one\nin order to satisfy the minimum consumption requirement\n\\eqref{eq:normalizedTCPConstraintsLong}.\nIn detail, we replace $\\vstock_t$ by $\\normcropfactor \\vstock_t$\nwhenever $\\normcropfactor < 1$,\nwhere $\\normcropfactor \\in \\posreal$ is a \\term{cropping factor}\nthat is determined by\n\\begin{equation}\n  \\label{eq:virtualSelling}\n  \\Bigl[\n    1 - \\tac\\, \\bigl(\n      \\sumfcn(\\vstock_t) - \\sumfcn(\\normcropfactor\\vstock_t)\n    \\bigr)\n  \\Bigr]\n  \\cdot \\bigl(1 - \\sumfcn(\\normcropfactor\\vstock_t)\\bigr)\n  = \\normconsume_{\\min}.\n\\end{equation}\nHere, $\\bigl(\\sumfcn(\\vstock_t) - \\sumfcn(\\normcropfactor\\vstock_t)\\bigr)$\nis the amount of virtually sold stocks.\nHence, the term in square brackets is the fraction of wealth\nthat is still available after deducting the induced transaction costs.\nThe product of this term with\n$\\bigl(1 - \\sumfcn(\\normcropfactor\\vstock_t)\\bigr)$\nis the fraction of wealth that can be consumed after the virtual selling,\nwhich needs to be at least $\\normconsume_{\\min}$.\nSolving \\cref{eq:virtualSelling} for $\\normcropfactor$ and\nchoosing the positive solution, we finally obtain\n\\begin{equation}\n  \\newcommand*{\\sumX}{\\sumfcn(\\vstock_t)}\n  \\newcommand*{\\cMin}{\\normconsume_{\\min}}\n  \\normcropfactor\n  \\ceq \\frac{\n    \\tac\\, \\bigl(1 + \\sumX\\bigr) - 1 +\n    \\sqrt{\n      \\tac^2\\, \\bigl(1 - \\sumX\\bigr)^2\n      - 2 \\tac\\, \\bigl(2 \\cMin - 1 + \\sumX\\bigr) + 1\n    }\n  }{\n    2 \\tac \\sumX\n  }.\n\\end{equation}\n\n\n\n\\subsection{Euler Equation Errors}\n\\label{sec:834eulerErrors}\n\n\\paragraph{Motivation}\n\nDue to the curse of dimensionality,\nreasonably accurate full grid reference solutions\nof the transaction costs problem can only be computed\nif the number $m_{\\vstock}$ of stocks is small.\nMainly (but not only) in higher-dimensional settings,\na different means of assessing the\nquality of sparse grid solutions is desirable.\nWe use Euler equation errors to measure the deviation in\nthe first-order optimality conditions.\n\n\\paragraph{Derivation}\n\nIn the following, we fix the state $\\normstate_t \\in \\clint{\\*0, \\*1}$\nfor which we want to compute the Euler equation error.\nWe abbreviate\nthe\n%normalized and certainty-equivalent-transformed\nvalue function interpolant\n$\n  \\normcetvalueintp_t\n  \\ceq \\normcetvalueintp_t(\\normstate_t)\n$,\nthe state transition function\n$\n  \\normstatefcn_t\n  \\ceq \\normstatefcn_t(\\normstate_t, \\normpolicy_t, \\stochastic_t)\n$,\nthe wealth ratio\n$\n  \\wealthratio_{t+1}\n  \\ceq \\wealthratio_{t+1}(\n    \\normstate_t, \\normpolicy_t, \\stochastic_t\n  )\n$, and\nthe consumption\n$\n  \\normconsume_t\n  \\ceq \\normconsume_t(\\normstate_t, \\normpolicy_t)\n$.\nThe Lagrangian of the optimization problem corresponding\nto the Bellman equation \\eqref{eq:normalizedTCPBellmanEquation}\nof the normalized transaction costs problem\nwith respect to the problem's constraints\n\\eqref{eq:normalizedTCPConstraints} is given by\n{%\n  \\setlength{\\abovedisplayskip}{9pt}%\n  \\setlength{\\belowdisplayskip}{9pt}%\n  \\begin{equation}\n    \\begin{split}\n      \\lagrangian_t(\\normstate_t, \\normpolicy_t, \\*\\multiplier)\n      &\\ceq \\left(\n        (\\normconsume_t)^{1-\\riskav} +\n        \\patience \\expectation[t]{\n          \\bigl(\n            \\wealthratio_{t+1}\\;\n            \\normcetvalueintp_{t+1}(\\normstatefcn_t)\n          \\bigr)^{1-\\riskav}\n        }\n      \\right)^{1/(1-\\riskav)}\\\\\n      &\\hspace*{6mm} {}\n      - \\multiplier_1 \\normbond_t\n      - \\tr{\\*\\multiplier_2} \\vnormbuy_t\n      - \\tr{\\*\\multiplier_3} \\vnormsell_t\n      + \\tr{\\*\\multiplier_4}\\; (\\vnormsell_t - \\vstock_t)\n      + \\multiplier_5\\; (\\normconsume_{\\min} - \\normconsume_t)\n    \\end{split}\n  \\end{equation}%\n}%\nwith $\n\\*\\multiplier \\ceq (\n  \\multiplier_1,\n  \\*\\multiplier_2,\n  \\*\\multiplier_3,\n  \\*\\multiplier_4,\n  \\multiplier_5\n)$,\n$\\multiplier_1, \\multiplier_5 \\in \\real$, and\n$\\*\\multiplier_2, \\*\\multiplier_3, \\*\\multiplier_4 \\in \\real^{m_{\\vstock}}$.\nAccording to the first-order conditions\n\\term{(Karush--Kuhn--Tucker (KKT) conditions),}\nthe partial derivative\n$\n  \\partialderiv{\\partialdiff \\normbond_t}{\\lagrangian_t}(\n    \\normstate_t, \\normpolicy_t, \\*\\multiplier\n  )\n$\nwith respect to $\\normbond_t$\nvanishes in the exact optimum\n$\\normpolicy_t = \\optnormpolicyfcn_t \\ceq \\optnormpolicyfcn_t(\\normstate_t)$,\ni.e.,\n{%\n  \\setlength{\\abovedisplayskip}{9pt}%\n  \\setlength{\\belowdisplayskip}{9pt}%\n  \\begin{equation}\n    \\label{eq:eulerErrorFirstOrderCondition}\n    \\partialderiv{\\partialdiff \\normbond_t}{\n      \\left(\n        (\\normconsume_t^{\\opt})^{1-\\riskav} +\n        \\patience \\expectation[t]{\n          \\bigl(\n            \\wealthratio_{t+1}^{\\opt}\\;\n            \\normcetvalueintp_{t+1}(\\normstatefcn[\\opt]_t)\n          \\bigr)^{1-\\riskav}\n        }\n      \\right)^{1/(1-\\riskav)}\n    }\n    - \\multiplier_1\n    - \\multiplier_5\n    \\partialderiv{\\partialdiff \\normbond_t}{\\normconsume_t^{\\opt}}\n    = 0,\n  \\end{equation}%\n}%\nwhere\n$\n  \\normstatefcn[\\opt]_t\n  \\ceq \\normstatefcn_t(\\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t)\n$,\n$\n  \\wealthratio_{t+1}^{\\opt}\n  \\ceq \\wealthratio_{t+1}(\n    \\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t\n  )\n$, and\n$\n  \\normconsume_t^{\\opt}\n  \\ceq \\normconsume_t(\\normstate_t, \\optnormpolicyfcn_t)\n$.\nWe now neglect binding constraints,\ni.e., we assume that $\\multiplier_1 = \\multiplier_5 = 0$,\notherwise we cannot compute the error.\nAfter calculating the derivatives,\n\\cref{eq:eulerErrorFirstOrderCondition} becomes\n{%\n  \\setlength{\\abovedisplayskip}{9pt}%\n  \\setlength{\\belowdisplayskip}{9pt}%\n  \\begin{equation}\n    \\patience \\bondreturn_t\n    \\cdot \\expectationsign[t]\\Bigl[\n      \\bigl(\n        \\normcetvalueintp_t\n        - \\tr{(\\gradient{\\normstate_t}{\\normcetvalueintp_t})}\n        \\normstatefcn[\\opt]_t\n      \\bigr) \\cdot\n      \\bigl(\n        \\wealthratio_{t+1}^{\\opt}\\; \\normcetvalueintp_t\n      \\bigr)^{-\\riskav}\n    \\Bigr]\n    = (\\normconsume_t^{\\opt})^{-\\riskav}.\n  \\end{equation}%\n}%\nThis equation can be used as an error measure by substituting\n$\\optnormpolicyfcn_t$ for the interpolated optimum\n$\\optnormpolicyintp_t = \\optnormpolicyintp_t(\\normstate_t)$.\nBy multiplying the resulting equation by\n$\n  (\\normconsume_t^{\\opt,\\sparse})^{\\riskav}\n  \\ceq (\\normconsume_t(\\normstate_t, \\optnormpolicyintp_t))^{\\riskav}\n$, we obtain the\n\\term{unit-free Euler equation errors $\\eulererror_t(\\normstate_t)$}\nwith respect to $\\normbond_t$:\n\\begin{equation}\n  \\eulererror_t(\\normstate_t)\n  \\ceq \\Bigl|\n    1 - \\Bigl(\n      \\patience \\bondreturn_t (\\normconsume_t^{\\opt,\\sparse})^{\\riskav}\n      \\cdot \\expectationsign[t]\\Bigl[\n        \\bigl(\n          \\normcetvalueintp_t\n          - \\tr{(\\gradient{\\normstate_t}{\\normcetvalueintp_t})}\n          \\normstatefcn[\\opt,\\sparse]_t\n        \\bigr) \\cdot\n        \\bigl(\n          \\wealthratio_{t+1}^{\\opt,\\sparse}\\;\n          \\normcetvalueintp_t\n        \\bigr)^{-\\riskav}\n      \\Bigr]\n    \\Bigr)^{-1/\\riskav}\n  \\Bigr|\n\\end{equation}\nwith\n$\n  \\normstatefcn[\\opt,\\sparse]_t\n  \\ceq \\normstatefcn_t(\\normstate_t, \\optnormpolicyintp_t, \\stochastic_t)\n$ and\n$\n  \\wealthratio_{t+1}^{\\opt,\\sparse}\n  \\ceq \\wealthratio_{t+1}(\n    \\normstate_t, \\optnormpolicyintp_t, \\stochastic_t\n  )\n$.\n\n%\\begin{equation}\n%  \\begin{split}\n%    \\patience \\bondreturn_t\n%    \\cdot \\expectationsign[t]\\Bigl[\n%      &\\bigl(\n%        \\normcetvalueintp_t%(\\normstate_t)\n%        - \\tr{\n%          (\n%            \\gradient{\\normstate_t}{\\normcetvalueintp_t}%(\\normstate_t)\n%          )\n%        }\n%        \\statefcn_t%(\\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t)\n%      \\bigr)\\\\[-1mm]\n%      &{} \\cdot\n%      \\bigl(\n%        \\wealthratio_{t+1}%(\n%        %  \\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t\n%        %)\n%        \\;\n%        \\normcetvalueintp_t%(\\normstate_t)\n%      \\bigr)^{-\\riskav}\n%    \\Bigr]\n%    = \\normconsume_t%(\\normstate_t, \\optnormpolicyfcn_t)\n%    ^{-\\riskav}\n%  \\end{split}\n%\\end{equation}\n%\n%\\begin{equation}\n%  \\begin{split}\n%    \\eulererror_t(\\normstate_t)\n%    \\ceq \\Bigl|\n%      1 - \\Bigl(\n%        \\patience \\bondreturn_t\n%        \\cdot \\normconsume_t%(\\normstate_t, \\optnormpolicyfcn_t)\n%        ^{\\riskav}\n%        \\cdot \\expectationsign[t]\\Bigl[\n%          &\\bigl(\n%            \\normcetvalueintp_t%(\\normstate_t)\n%            - \\tr{\n%              (\n%                \\gradient{\\normstate_t}{\\normcetvalueintp_t}%(\\normstate_t)\n%              )\n%            }\n%            \\statefcn_t%(\\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t)\n%          \\bigr)\\\\[-2mm]\n%          &{} \\cdot\n%          \\bigl(\n%            \\wealthratio_{t+1}%(\n%            %  \\normstate_t, \\optnormpolicyfcn_t, \\stochastic_t\n%            %)\n%            \\;\n%            \\normcetvalueintp_t%(\\normstate_t)\n%          \\bigr)^{-\\riskav}\n%        \\Bigr]\n%      \\Bigr)^{-1/\\riskav}\n%    \\Bigr|,\n%  \\end{split}\n%\\end{equation}\n\n\\paragraph{Weighted Euler equation errors}\n\nHowever, the state space cropping as introduced above\ndistorts Euler equation errors:\nThe error $\\eulererror_t(\\normstate_t)$ does not vanish\neven for the exact solution and even inside the feasible state space.\nThis is because the cropping already occurs for large stock holdings\n$\\sumfcn(\\normstate_t)$ that are less than one,\nas stocks have to be sold to maintain\nminimum consumption $\\normconsume_{\\min}$.\nNumerical experiments show that due to this issue,\nthe error attains large values in the region near the hyperplane\n$\\sumfcn(\\normstate_t) = 1$.\nEconomically, this region is not significant\nas such large stock fractions are highly unusual,\nwhich is confirmed by Monte Carlo simulations.\nWe therefore use the \\term{weighted Euler equation error}\n\\begin{equation}\n  \\weightedeulererror_t(\\normstate_t)\n  \\ceq \\bigl(1 - \\sumfcn(\\normstate_t)\\bigr) \\cdot\n  \\eulererror_t(\\normstate_t)\n\\end{equation}\ninstead of $\\eulererror_t$,\nalthough other strategies exist\nsuch as restricting the state domain where the error is computed or\nweighting the error with the probability that a given state\noccurs in Monte Carlo simulations.\n", "meta": {"hexsha": "e579fe0115a1b47e4dbc339e2f7d1a66125c98d5", "size": 18416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/83problem.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/83problem.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/83problem.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": 31.8065630397, "max_line_length": 80, "alphanum_fraction": 0.6653453519, "num_tokens": 6050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6246295191611588}}
{"text": "\\documentclass{article}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage[letterpaper, margin=1in]{geometry}\r\n\\usepackage{amsmath}\r\n\\usepackage{tikz}\r\n\\usepackage{pgfplots}\r\n\\usepackage{amssymb }\r\n\r\n\\title{CS5780 HW4}\r\n\\author{Renhao Lu, NetID: rl839}\r\n\t\r\n\\begin{document}\r\n\t\\maketitle\r\n\t\r\n\t\\section{Problem: Linear Regression}\r\n\t\\subsection{Compute the closed form solution for $\\textbf{w}$}\r\n\tUsing the formula in class:\r\n\t\\[\r\n\t\\textbf{w} = \r\n\t\t(\\textbf{X} \\textbf{X}^T) ^{-1}\r\n\t\t\\textbf{X}\r\n\t\t\t\\textbf{y}^T\r\n\t\\]\r\n\twhere $\\textbf{X}=\\begin{pmatrix} 1 & 1 & 1 & 1 & 1 \\\\ -1 & 0 & 1 & 2 & 3\\end{pmatrix}$ and  $\\textbf{y}=\\begin{pmatrix} 4 & 3 & -4& 3 & 7 \\end{pmatrix}$\\\\\r\n\tHence,\r\n\t\\[\\begin{split}\r\n\t\t\\textbf{w}&=(\\textbf{X}\\textbf{X}^T)^{-1}\\textbf{X}\\textbf{y}^T\\\\\r\n\t\t&=\\begin{pmatrix} 5 & 5 \\\\ 5 & 15\\end{pmatrix}^{-1}\\textbf{X}\\textbf{y}^T\\\\\r\n\t\t&=\\begin{pmatrix} 0.3 & -0.1 \\\\ -0.1 & 0.1\\end{pmatrix}\\textbf{X}\\textbf{y}^T\\\\\r\n\t\t&=\\begin{pmatrix} 0.4 & 0.3 & 0.2 & 0.1 & 0 \\\\ -0.2 & -0.1 & 0 & 0.1 & 0.2\\end{pmatrix}\\textbf{y}^T\\\\\r\n\t\t&=\\begin{pmatrix} 2 \\\\ 0.6\\end{pmatrix}\r\n\t\\end{split}\\]\r\n\t\r\n\t\\subsection{Calculate the training loss}\r\n\t\\[\r\n\t\t\\begin{split}\r\n\t\t\tl(\\textbf{w})&=\\sum (y_i-\\textbf{w}^T\\phi(x_i)^2)\\\\\r\n\t\t\t&={||\\textbf{y}-\\textbf{w}^textbf{X}||}_2^2\\\\\r\n\t\t\t&={||\\begin{pmatrix} 2.6 & 1 & -6.6 & -0.2 & 3.2 \\end{pmatrix}||}_2^2\\\\\r\n\t\t\t&=61.6\r\n\t\t\\end{split}\r\n\t\\]\r\n\t\r\n\t\\section{Problem: Linearity of Gaussian Naive Bayes}\r\n\t\\subsection{Show that the decision rule}\r\n\tAccording to the law of total probability:\r\n\t\\[\r\n\t\t\\begin{split}\r\n\t\t\tp(\\textbf{x}) &= p(y=1)p(\\textbf{x}|y=1)+p(y=0)p(\\textbf{x}|y=0)\\\\\r\n\t\t\t&=p(y=1)\\prod_{\\alpha=1}^d {p([\\textbf{x}]_{\\alpha}|y=1)} +p(y=0)\\prod_{\\alpha=1}^d {p([\\textbf{x}]_{\\alpha}|y=0)}\r\n\t\t\\end{split}\r\n\t\\]\r\n\tHence,\r\n\t\\[\r\n\t\t\\begin{split}\r\n\t\t\tp(y=1|\\textbf{x}) &=\\frac{\r\n\t\t\t\tp(y=1) \r\n\t\t\t\t\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t} \r\n\t\t\t}{\r\n\t\t\t\tp(\\textbf{x})\r\n\t\t\t} \\\\\r\n\t\t\t&=\\frac{\r\n\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t}\r\n\t\t\t}{\r\n\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t}\r\n\t\t\t\t+p(y=0)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=0)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\end{split}\r\n\t\\]\r\n\t\r\n\t\\subsection{Show how to rewrite}\r\n\tFrom the formula we got from 1:\r\n\t\\[\r\n\t\t\\begin{split}\r\n\t\t\tp(y=1|\\textbf{x}) \r\n\t\t\t&=\\frac{\r\n\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t}\r\n\t\t\t}{\r\n\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t}\r\n\t\t\t\t+p(y=0)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=0)\r\n\t\t\t\t}\r\n\t\t\t}\\\\\r\n\t\t\t&=\\frac{1}{\r\n\t\t\t\t1 + \\frac{\r\n\t\t\t\t\tp(y=0)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=0)\r\n\t\t\t\t\t}\r\n\t\t\t\t}{\r\n\t\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\\\\\r\n\t\t\t&=\\frac{1}{\r\n\t\t\t\t1 + exp(\r\n\t\t\t\t\t-log(\r\n\t\t\t\t\t\t\\frac{\r\n\t\t\t\t\t\t\tp(y=1)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=1)\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}{\r\n\t\t\t\t\t\t\tp(y=0)\\prod_{\\alpha=1}^d {\r\n\t\t\t\t\t\t\t\tp([\\textbf{x}]_{\\alpha}|y=0)\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t)\r\n\t\t\t\t)\r\n\t\t\t}\\\\\r\n\t\t\\end{split}\r\n\t\\]\r\n\t\\subsection{Show that Naive Bayes is a linear model}\r\n\tBecause\r\n\t\\[\r\n\t\tp([\\textbf{x}]_{\\alpha}|y=1)=\r\n\t\t\\frac{1}{\\sqrt{2\\pi[\\sigma_{\\alpha}]}}\r\n\t\t\\exp\\left({\r\n\t\t\t\\frac{\r\n\t\t\t-([\\textbf{x}]_{\\alpha}-[\\mu_1]_{\\alpha})^2\r\n\t\t\t}{\r\n\t\t\t\t2[\\sigma]_{\\alpha}\r\n\t\t\t}\r\n\t\t}\\right)\r\n\t\\]\r\n\t\\[\r\n\t\tp([\\textbf{x}]_{\\alpha}|y=0)=\r\n\t\t\\frac{1}{\\sqrt{2\\pi[\\sigma_{\\alpha}]}}\r\n\t\t\\exp\\left({\r\n\t\t\t\\frac{\r\n\t\t\t-([\\textbf{x}]_{\\alpha}-[\\mu_0]_{\\alpha})^2\r\n\t\t\t}{\r\n\t\t\t\t2[\\sigma]_{\\alpha}\r\n\t\t\t}\r\n\t\t}\\right)\r\n\t\\]\r\n\tHence,\r\n\t\\[\r\n\t\t\\begin{split}\r\n\t\t\tp(y=1|\\textbf{x})&=\\frac{1}{1+\\frac{p(y=0)}{p(y=1)}\\exp{\\left(\\sum_{\\alpha=1}^d{-\\log{\\frac{p([\\textbf{x}]_\\alpha|y=1)}{p([\\textbf{x}]_\\alpha|y=0)}}}\\right)}}\\\\\r\n\t\t\t&=\\frac{1}{1+\\frac{p(y=0)}{p(y=1)}\\exp{\\left(\\sum_{\\alpha=1}^d{\\frac{([\\textbf{x}]_{\\alpha}-[\\mu_0]_{\\alpha})^2-([\\textbf{x}]_{\\alpha}-[\\mu_1]_{\\alpha})^2}{2[\\sigma]_{\\alpha}}}\\right)}}\\\\\r\n\t\t\t&=\\frac{1}{1+\\frac{p(y=0)}{p(y=1)}\\exp{\\left(\\sum_{\\alpha=1}^d{\\frac{2([\\mu_1]_{\\alpha}- [\\mu_0]_{\\alpha})[\\textbf{x}]_{\\alpha}+([\\mu_0]_{\\alpha}^2-[\\mu_1]_{\\alpha}^2)}{2[\\sigma]_{\\alpha}}}\\right)}}\r\n\t\t\\end{split}\r\n\t\\]\r\n\tWe assume:\r\n\t\\[\\textbf{w}=[w_1, w_2,...,w_b], w_\\alpha=\\frac{[\\mu_1]_{\\alpha}- [\\mu_0]_{\\alpha}}{[\\sigma]_{\\alpha}}\\]\r\n\t\\[b=\\sum{b_\\alpha}+b_0, b_0=\\log{\\frac{p(y=0)}{p(y=1)}}, b_\\alpha=\\frac{[\\mu_0]_{\\alpha}^2-[\\mu_1]_{\\alpha}^2}{2[\\sigma]_{\\alpha}}\\]\r\n\tHence,\r\n\t\\[\\begin{split}\r\n\t\tp(y=1|\\textbf{x})&=\\frac{1}{1+\\exp{\\left(b_0+\\sum_{\\alpha=1}^d {(w_\\alpha[\\textbf{x}]_\\alpha+b_\\alpha)}\\right)}}\\\\\r\n\t\t&=\\frac{1}{1+\\exp{\\left(\\textbf{w}^T\\textbf{x}+b\\right)}}\r\n\t\\end{split}\\]\r\n\tFrom the formula above, whether $p(y=1|\\textbf{x}) > p(y=0|\\textbf{x})$ is decided by whether $\\textbf{w}^T\\textbf{x}+b>0$, hence this Naive Bayes is a linear model.\r\n\t\r\n\t\\section{Problem: Gradient for Logistic Regression}\r\n\t\\subsection{Show the sigmoid function property}\r\n\t\\[\\begin{split}\r\n\t\t\\sigma(s)+\\sigma(-s)&=\\frac{1}{1+e^{-s}}+\\frac{1}{1+e^{s}}\\\\\r\n\t\t&=\\frac{e^s}{1+e^{s}}+\\frac{1}{1+e^{s}}=1\r\n\t\\end{split}\\]\r\n\tHence, $\\sigma(-s)=1-\\sigma(s)$\r\n\t\r\n\t\\subsection{Compute the gradient of the log likelihood function}\r\n\t\\subsubsection{first derivative}\r\n\t\\[\\sigma'(s)=-\\frac{1}{(1+e^{-s})^2}(-e^{-s})=\\frac{1}{1+e^{-s}}\\frac{1}{1+e^s}=\\sigma(s)\\sigma(-s)=\\sigma(s)(1-\\sigma(s))\\]\r\n\r\n\t\\subsubsection{Show the gradient of the log likelihood function}\r\n\t\\[\r\n\t\\begin{split}\r\n\t\t\\nabla_w\\log(\\textbf{y}|X, \\textbf{w})&=\\nabla_w\\sum_{i=1}^n{\\log\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i))}\\\\\r\n\t\t&=\\sum_{i=1}^n {[\\frac{\\partial}{\\partial w_1}\\log\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i))...\\frac{\\partial}{\\partial w_d}\\log\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i))]}\r\n\t\\end{split}\r\n\t\\]\r\n\tConsidering that,\r\n\t\\[\r\n\t\t\\frac{\\partial}{\\partial w_\\alpha}\\log\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i)) = \\frac{1}{\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i))}\\sigma'(y_i(\\textbf{w}^T\\textbf{x}_i))y_i\\frac{\\partial}{\\partial w_\\alpha}\\textbf{w}^T\\textbf{x}_i=(1-\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i)))y_i\\textbf{x}_{i\\alpha}\r\n\t\\]\r\n\tHence,\r\n\t\\[\\nabla_w\\log(\\textbf{y}|X, \\textbf{w})=\\sum_{i=1}^n {(1-\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i)))y_i\\textbf{x}_{i}}\\]\r\n\t\r\n\t\\subsubsection{the weights are in the span of the feature vectors}\r\n\tAssume in $k^{th}$ iteration, the step size is $t_k$\\\\\r\n\tProof by induction:\\par\r\n\tBase case: in the $0^{th}$ iteration, $\\textbf{w}_0=\\textbf{0}=\\sum_{i=1}^n0\\times\\textbf{x}_i$\\par\r\n\tInduction assumption: assume in $k-1^{th}$ iteration, $\\textbf{w}_{k-1}=\\sum_{i=1}^nc_{(k-1)i}\\textbf{x}_i$, then $\\textbf{w}_{k}=\\textbf{w}_{k-1}+t_k\\nabla_w\\log(\\textbf{y}|X, \\textbf{w})=\\textbf{w}_{k-1}+t_k\\sum_{i=1}^n {(1-\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i)))y_i\\textbf{x}_{i}}$. We note $c_{ki}=c_{(k-1)i}+t_k(1-\\sigma(y_i(\\textbf{w}^T\\textbf{x}_i)))y_i$, then $\\textbf{w}_{k}=\\sum_{i=1}^nc_{ki}\\textbf{x}_i$\\par\r\n\tHence, at every iteration of gradient descent, the weights are in the span of the feature vectors.\\par\r\n\t\r\n\t\\section{Problem: Optimization with Gradient Descent}\r\n\t\\subsection{Perform 3 steps of gradient descent}\r\n\t$f'(w)=6(w-3)$, hence $w_k=w_{k-1}-\\frac 1 \\alpha f'(w_{k-1})=w_{k-1}-\\frac 1 2 (w_{k-1}-3)$.\r\n\t\\[\\begin{split}\r\n\t\t&w_0=5, f(w_0)=3\\times2^2=12\\\\\r\n\t\t&w_1=5-\\frac 1 2\\times 2=4, f(w_1)=3\\times1^2=3\\\\\r\n\t\t&w_2=4-\\frac 1 2\\times 1=3.5, f(w_2)=3\\times0.5^2=0.75\\\\\r\n\t\t&w_3=3.5-\\frac 1 2\\times 0.5=3.25, f(w_3)=3\\times0.25^2=0.1875\r\n\t\\end{split}\\]\r\n\t\\begin{center}\r\n\t\t\\begin{tikzpicture}\r\n\t\t\t\\begin{axis}[\r\n\t\t\t\txmin = 0, xmax = 6,\r\n\t\t\t\tymin = -2, ymax = 24,\r\n\t\t\t\txtick distance = 1,\r\n\t\t\t\tytick distance = 3,\r\n\t\t\t\tgrid = both,\r\n\t\t\t\tminor tick num = 1,\r\n\t\t\t\tmajor grid style = {lightgray},\r\n\t\t\t\tminor grid style = {lightgray!25},\r\n\t\t\t\twidth =  .5\\textwidth,\r\n\t\t\t\theight = .5\\textwidth,\r\n\t\t\t\txlabel = {$x$},\r\n\t\t\t\tylabel = {$y$},\r\n\t\t\t\tlegend cell align = {left},\r\n\t\t\t]\r\n\t\t\t\t\\addplot[\r\n\t\t\t\t\tdomain = 0:6,\r\n\t\t\t\t\tsamples = 200,\r\n\t\t\t\t\tsmooth,\r\n\t\t\t\t\tthick,\r\n\t\t\t\t\tblue,\r\n\t\t\t\t] {3*(x-3)^2};\r\n\t\t\t\t\\addplot [only marks, mark=o,mark size=2.9pt] table {\r\n\t\t\t\t\t5 12\r\n\t\t\t\t};\r\n\t\t\t\t\\addplot [only marks, mark=halfcircle*,mark size=2.9pt] table {\r\n\t\t\t\t\t4 3\r\n\t\t\t\t};\r\n\t\t\t\t\\addplot [only marks, mark=square,mark size=2.9pt] table {\r\n\t\t\t\t\t3.5 0.75\r\n\t\t\t\t};\r\n\t\t\t\t\\addplot [only marks, mark=x,mark size=2.9pt] table {\r\n\t\t\t\t\t3.25 0.1825\r\n\t\t\t\t};\r\n\t\t\t\t\\legend{$f(w) = 3(w-3)^2$,$w_0$,$w_1$,$w_2$,$w_3$}\r\n\t\t\t\\end{axis}\r\n\t\t\\end{tikzpicture}\r\n\t\t\\end{center}\r\n\t\r\n\t\\subsection{Gradient descent can sometimes fail to converge}\r\n\t$f'(w)=20(w-11)^3$, hence $w_k=w_{k-1}-\\frac 1 \\alpha f'(w_{k-1})=w_{k-1}-\\frac 1 2 (w_{k-1}-11)^3$.\r\n\t\\[\\begin{split}\r\n\t\t&w_0=13, f(w_0)=5\\times2^4=80\\\\\r\n\t\t&w_1=13-\\frac 1 2\\times 2^3=9, f(w_1)=5\\times2^4=80\\\\\r\n\t\t&w_2=9-\\frac 1 2\\times (-2)^3=13, f(w_2)=5\\times2^4=80\\\\\r\n\t\t&w_3=13-\\frac 1 2\\times 2^3=9, f(w_3)=5\\times2^4=80\\\\\r\n\t\t&...\r\n\t\\end{split}\\]\r\n\tThe gradient descent is bouncing between $9$ and $13$ and will never converge.\r\n\t\\begin{center}\r\n\t\t\\begin{tikzpicture}\r\n\t\t\t\\begin{axis}[\r\n\t\t\t\txmin = 8, xmax = 14,\r\n\t\t\t\tymin = -1, ymax = 116,\r\n\t\t\t\txtick distance = 1,\r\n\t\t\t\tytick distance = 9,\r\n\t\t\t\tgrid = both,\r\n\t\t\t\tminor tick num = 1,\r\n\t\t\t\tmajor grid style = {lightgray},\r\n\t\t\t\tminor grid style = {lightgray!25},\r\n\t\t\t\twidth =  .5\\textwidth,\r\n\t\t\t\theight = .5\\textwidth,\r\n\t\t\t\txlabel = {$x$},\r\n\t\t\t\tylabel = {$y$},\r\n\t\t\t\tlegend cell align = {left}\r\n\t\t\t]\r\n\t\t\t\t\\addplot[\r\n\t\t\t\t\tdomain = 8:14,\r\n\t\t\t\t\tsamples = 200,\r\n\t\t\t\t\tsmooth,\r\n\t\t\t\t\tthick,\r\n\t\t\t\t\tblue,\r\n\t\t\t\t] {5*(x-11)^4};\r\n\t\t\t\t\\addplot [only marks, mark=o,mark size=2.9pt] table {\r\n\t\t\t\t\t13 80\r\n\t\t\t\t};\r\n\t\t\t\t\\addplot [only marks, mark=halfcircle*,mark size=2.9pt] table {\r\n\t\t\t\t\t9 80\r\n\t\t\t\t};\r\n\t\t\t\t\\legend{$f(w) = 5(w - 11)^4$, ${w_0,w_2,...}$,${w_1,w_3,...}$}\r\n\t\t\t\\end{axis}\r\n\t\t\\end{tikzpicture}\r\n\t\t\\end{center}\r\n\t\r\n\t\\section{Problem: Derivation for Hard-margin Linear SVMs}\r\n\t\\subsection{Prove the optimal solution of formulation A is a feasible solution for formulation B}\r\n\tNote the optimal solution of frmulation A is $\\textbf{w}_A$. Then $\\forall_iy_i(\\textbf{w}_A^T\\textbf{x}_i+b)\\geq 0$ and $min_i|\\textbf{w}_A^T\\textbf{x}_i+b|=1$. Because $y_i=1or-1$, $min_iy_i(\\textbf{w}_A^T\\textbf{x}_i+b)=1$. Hence, $\\forall_iy_i(\\textbf{w}_A^T\\textbf{x}_i+b)\\geq 1$. $\\textbf{w}_A$ is a feasible solution for B.$\\blacksquare$\r\n\t\\subsection{Prove the optimal solution of formulation B is a feasible solution for formulation A}\r\n\tNote the optimal solution of frmulation B is $\\textbf{w}_B$, then $\\forall_i,y_i(\\textbf{w}_B^T\\textbf{x}_i+b)\\geq1$. Then obviously $\\forall_iy_i(\\textbf{w}_B^T\\textbf{x}_i+b)\\geq0$. Now we need to consider $min_i|\\textbf{w}_B^T\\textbf{x}_i+b|$\\par\r\n\tWe can prove $min_i|\\textbf{w}_B^T\\textbf{x}_i+b|=1$ by contradiction. We assume $min_i|\\textbf{w}_B^T\\textbf{x}_i+b|=p>1$, then we use a new weight vector $\\textbf{w}_B'=\\frac{\\textbf{w}_B}{p}$. Because $p>1$, $\\textbf{w}_B'^T\\textbf{w}_B'=\\frac{\\textbf{w}_B^T\\textbf{w}_B}{p^2}<\\textbf{w}_B^T\\textbf{w}_B$ And $\\forall_i,y_i(\\textbf{w}_B'^T\\textbf{x}_i+b)\\geq\\frac p p=1$. Then $\\textbf{w}_B$ cannot be optimal because $\\textbf{w}_B'$ is better. $\\blacksquare$\r\n\t\r\n\t\\subsection{Prove that for the optimal solution in formulation A is the optimal solution for formulation B and vice versa}\r\n\tWe note $\\textbf{w}_A$ as the optimal solution in A, and $\\textbf{w}_B$ as the optimal solution in B. From the previous questions, we know that $\\textbf{w}_A$ is a feasible solution for B, so $\\textbf{w}_A\\leq\\textbf{w}_B$. Similiarly, $\\textbf{w}_B$ is also a feasible solution for A, so $\\textbf{w}_B\\leq\\textbf{w}_A$. Hence $\\textbf{w}_B=\\textbf{w}_A\\blacksquare$\r\n\\end{document}", "meta": {"hexsha": "f6dd680a4a261e759e42bd06f58bbd4e65953cec", "size": 11518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CS5780 HW4.tex", "max_stars_repo_name": "lurenhaothu/CS5780", "max_stars_repo_head_hexsha": "2599c6348f76dede29282a8551c18f04e19414a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CS5780 HW4.tex", "max_issues_repo_name": "lurenhaothu/CS5780", "max_issues_repo_head_hexsha": "2599c6348f76dede29282a8551c18f04e19414a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CS5780 HW4.tex", "max_forks_repo_name": "lurenhaothu/CS5780", "max_forks_repo_head_hexsha": "2599c6348f76dede29282a8551c18f04e19414a5", "max_forks_repo_licenses": ["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.0132013201, "max_line_length": 464, "alphanum_fraction": 0.5737107137, "num_tokens": 5008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6245340888245172}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\t\\section{Lattices and crystal structure} \\label{sec:lattice}\n\t\\subsection{Theory} \\label{sec:lattice_theory}\n\tThere are three parts to the description of a crystal structure. First is the lattice. This is the mathematical ``framework'' upon which the physical part of the crystal lies. It can be defined in a number of ways, however the one we will use here is standard and can be found in for example \\cite{simon} or \\cite{kittel}.\n\t\n\t\\textbf{A lattice is defined as the infinite set of points produced by a linear combination of independent \\emph{primitive lattice vectors}, with integer coefficients.}\n\t\n\tThroughout this thesis, the primitive lattice vectors are labelled $ \\V{a}_i $, and the coefficients $ n_i $, so for a $ d $-dimensional lattice, the lattice points $ \\V{R} $ are given by\n\t\\begin{equation}\\label{eq:lattice_points}\n\tR = \\sum_{i = 1}^{d} n_i \\V{a}_i.\n\t\\end{equation}\n\tFor this thesis we will mainly focus on the cases of $ d = 3 $ (visualization of lattices, families of lattice planes and scattering) and $ d = 2 $ (visualization of the band structure).\n\t\n\tA thing to note is that the choice of primitive lattice vectors is not unique. A new set of primitive lattice vectors can be created by taking a linear combination of the original primitive lattice vectors, with integer coefficients. If the original set is ordered in a matrix $ A = \\begin{pmatrix*} \\V{a}_1 & \\V{a}_2 & \\cdots & \\V{a}_n \\end{pmatrix*}$, and the new set in a matrix $ B = \\begin{pmatrix*} \\V{b}_1 & \\V{b}_2 & \\cdots & \\V{b}_n \\end{pmatrix*} $, then $ B = MA $, where $ M $ is the matrix containing the coefficients. This matrix must have integer entries, and its inverse likewise. The integer entries of the direct coefficient matrix $ M $ makes sure that any lattice point generated with the new set of primitive lattice vectors will also have integer coefficients when expressed in the old set of primitive lattice vectors. The integer entries of the inverse matrix $ M\\inverse $ then makes sure that this process will also happen in reverse.\n\t\n\tThe second part is the unit cell. This is the building block of the lattice. It is a region of space which, when stacked will completely tile the space. Like with the choice of primitive lattice vectors, the choice of unit cell is not unique. In particular we distinguish between two type of unit cells: the smallest possible unit cell and everything else. The smallest possible unit cell is called a \\textit{primitive} unit cell, and must contain only one lattice point (it cannot contain zero lattice points, as then it would not recreate the lattice when tiled). Any unit cell containing more than one lattice point is called a \\textit{conventional unit cell}. Usually a conventional unit cell is chosen for ease of calculation (as we will see in the scattering simulation), where the primitive lattice vectors constitute an orthogonal set.\n\t\n\tThe third part of the crystal structure is the basis. This is a description of the physical objects that make up the structure, and their positions in relation to the lattice. In our case the objects are atoms. The basis is specified as a list of vectors that are to be added to the lattice points, specifying the position of the atoms in the crystal.\n\t\n\tThe user can create any type of crystal they want by specifying any set of primitive lattice vector and supplying any desired basis. However a small selection of crystals will be available as presets. These include the 14 Bravais lattices with a 1 atom basis [at $ (0,0,0) $], named in table \\ref{tab:bravais}. Each of these will specify the primitive lattice vectors for a corresponding primitive unit cell. Furthermore five other crystal presets will be available, named in table \\ref{tab:presets}. Specifications of all of these presets are available in the appendix \\ref{app:lattice}.\n\t\\begin{table}[H]\n\t\t\\centering\n\t\t\\begin{tabular}{|l|l|}\n\t\t\t\\hline\n\t\t\tSimple cubic & base centred cubic (bcc) \\\\\n\t\t\t\\hline\n\t\t\tface centred cubic (fcc) & tetragonal \\\\\n\t\t\t\\hline\n\t\t\tbody centred tetragonal & orthorhombic \\\\\n\t\t\t\\hline\n\t\t\tbody centred orthorhombic & face centred orthorhombic \\\\\n\t\t\t\\hline\n\t\t\tbase centred orthorhombic & simple monoclinic \\\\\n\t\t\t\\hline\n\t\t\tbase centred monoclinic & hexaonal \\\\\n\t\t\t\\hline\n\t\t\ttriclinic & rhombohedral \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{The 14 Bravais lattices}\n\t\t\\label{tab:bravais}\n\t\\end{table}\n\t\\begin{table}[H]\n\t\t\\centering\n\t\t\\begin{tabular}{|l|l|}\n\t\t\t\\hline\n\t\t\tfcc, conventional & bcc, conventional \\\\\n\t\t\t\\hline\n\t\t\tzincblende & wurtzite \\\\\n\t\t\t\\hline\n\t\t\tdiamond (zincblende with 1 atom) & \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Other available crystal presets}\n\t\t\\label{tab:presets}\n\t\\end{table}\n\t\n\t\\subsection{Implementation}\t\n\tMathematically speaking, a lattice is infinite. A physical crystal, of course, is not. However, even though a real crystal is finite, plotting all of the atoms would be infeasible, both due to the number of atoms, and the fact that each atom would be way too small. So for the purposes of this program, only a couple of unit cells will be plotted. A good amount seems to be 8 unit cells: 2 in each of the directions specified by the primitive lattice vectors. This keeps the size of the plot relatively small, whilst still showing the important parts of the crystal structure. As such, in the following we assume that $ n_i \\in \\{0, 1, 2\\} $ for all $ n_i $.\n\t\n\tIn creating a program that plots these structures, the thought should always be on how the end product looks. Mainly we want the plot to be as clear and instructive as possible. This constitutes plotting only full unit cells: no unit cell can have missing atoms. There is a caveat to this however. Say we define the unit cell to have atoms on the boundary, then these atoms will be in multiple unit cells. One could say no matter how many unit cells we plot, we would always get some amount of unfinished unit cells. As such we will plot the 8 unit cells along with any atoms on the border of these.\n\t\\begin{wrapfigure}{r}{2in}\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/lattice_unfinished_1.pdf}\n\t\t\\end{center}\n\t\t\\caption{One conventional unit cell for a bcc lattice. If we naively plot all atoms associated with a lattice point, we will end up with atoms outside the unit cells we want to plot.}\n\t\t\\label{fig:lattice_unfinished_1}\n\t\\end{wrapfigure}\n\t\n\tEven with the above considerations we need to remember that the screen is still just a two dimensional projection of the actual three dimensional phenomena. As such without some form of depth perception, the crystal will just look like a weird two dimensional pattern. This is fixed by including grid lines. They, along with the ability to interactively rotate the crystal, give the required depth perception to allow the user to comprehend the crystal as a three dimensional structure, and not as a two dimensional sheet of dots. \n\t\n\tFor the crystals that can be expressed as a lattice with orthogonal primitive lattice vectors and a basis (cubic, tetragonal and orthorhombic), we usually want to plot orthogonal grid lines, whilst for other crystals plotting grid lines along the lattice vectors will be more useful.\n\t\n\tIn the case of plotting primitive unit cells, the ones furthest away from the origin (say with $ n_1 = n_2 = n_3 = 2 $) may not be filled. Say the basis consists of only one atom. Then this atom will just be placed on the lattice points, and there is no problem, as this is the edge of the unit cell. However, if the basis consists of two atoms (or more), where one is placed at $ (0,0,0) $ and the other has some positive coordinates, then this second atom will be in a unit cell which is not supposed to be plotted (it would necessitate plotting the lattice points corresponding to $ n_i = 3 $). An example of this is figure \\ref{fig:lattice_unfinished_1}, which shows one unit cell of a simple cubic lattice, with a two atom basis (corresponding to a conventional bcc unit cell). A way to correct for this is to write each plotted atoms position as a linear combination of the primitive lattice vectors with coefficients $ n'_i $ (where the coefficients here are real numbers, as they do not necessarily align with the lattice points). If the coefficients are $ 0 \\leq n'_i \\leq 2 $ for all $ n'_i $, then we plot the point.\n\t\n\tFor plotting conventional unit cells when the user inputs primitive lattice vectors (for cubic, tetragonal and orthorhombic lattices), we need something similar, otherwise a situation like in figure \\ref{fig:lattice_unfinished_2} may occur. To fix this we calculate the side lengths of the cuboid plot box that just contains the parallelepiped arising from plotting the lattice points with the specified coefficients ($ n_i \\in \\{0, 1, 2\\}$), and fill this plot box completely with atoms.\n\t\n\tTo calculate this, the program creates the 8 possible vectors arising from linear combinations of the primitive lattice vectors, with coefficients from the minimum and maximum coefficients and taking the limits of the plot box as the minimum and maximum values for these 8 vectors. For the specified lattice points, these 8 vectors are:\n\t\\begin{equation}\n\t\t\\begin{array}{llll}\n\t\t\t\\V{v}_1 = \\V{0}, & \\V{v}_2 = 2\\V{a}_1, & \\V{v}_3 = 2\\V{a}_2, & \\V{v}_4 = 2\\V{a}_3, \\\\\n\t\t\t\\V{v}_5 = 2(\\V{a}_1+\\V{a}_2), & \\V{v}_6 = 2(\\V{a}_1+\\V{a}_3), & \\V{v}_7 = 2(\\V{a}_2+\\V{a}_3), &\\V{v}_8 = 2(\\V{a}_1+\\V{a}_2+ \\V{a}_3).\n\t\t\\end{array}\n\t\\end{equation}\n\tThese are the vertices of the aforementioned parallelepiped. The side lengths of the plot box are then taken as the maximum coordinates for these vectors, minus the minimum values (the side length in $ x $ might be $ v_{8,x}-v_{0,x} $ for example). Then we plot atoms for a larger range of coefficients to completely fill out this plot box. If some atoms fall outside of the box we hide them.\n\t\n\t\\begin{wrapfigure}{r}{2in}\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=\\linewidth]{figures/lattice_unfinished_2.pdf}\n\t\t\\end{center}\n\t\t\\caption{An attempt to plot eight conventional unit cells for an FCC lattice, by using primitive lattice vectors with coefficients in the set $ \\{0, 1, 2\\} $. This does not fill out all eight unit cells, so we need to plot more lattice points than this. In practise we need $ \\{-2, -1, 0, 1, 2, 3, 4\\} $}\n\t\t\\label{fig:lattice_unfinished_2}\n\t\\end{wrapfigure}\n\t\n\t\n\t\\subsection{Step-by-step}\n\tWhen the program is run it will either load the chosen crystal preset or plot the user's manually input crystal. If a crystal preset is chosen, the program loads it in such a way as to make the resulting plot as informative as possible (eg. place lattice vectors along cardinal axes for an orthogonal lattice, to make plotting grid lines easier). If the user manually specifies the lattice and basis, the program attempts to classify the lattice according to the specifications in the appendix \\ref{app:lattice} (except for zincblende, diamond and wurtzite). Next the program checks whether or not the crystal should be rotated to make plotting prettier.\n\t\n\tIn general the rotation algorithm tries to align one lattice vector with the $ x $-axis. $ \\V{a}_1 $ is preferred, but is only chosen to lie along the $ x $-axis if it forms an orthogonal pair with at least one other primitive lattice vector. The second primitive lattice vector of the pair ($\\V{a}_2$ being preferred) is then aligned along the $ y $-axis. If the three primitive lattice vectors form an orthogonal set, then the last vector of the set will now be aligned along the $ z $-axis.\n\t\n\tThe actual rotation is done by rotating the whole crystal (each primitive lattice vector and all vectors in the basis) around the cross product between the initial vector and the destination vector. Rotating the crystal such that $ \\V{a}_1 $ lies along the $ x $-axis is done by rotating along $ \\V{a}_1 \\times \\U{x} $, with an angle of $ \\sin \\theta = |\\V{a}_1 \\times \\U{x}| / |\\V{a}_1| $. However, this might rotate the crystal the wrong way, depending on the orientation between the two vectors. Because of this the program checks whether or not the rotated initial vector and the destination vector are parallel (that is, if the rotated $ \\V{a}_1 $ is parallel to $ \\U{x} $). If this is not the case, the whole crystal is rotated about the same vector, with an angle $ -2\\theta $.\n\t\n\tFive of the Bravais lattices have specialised rotation functions: hexagonal, base centred monoclinic and the three face centred lattices.\n\t\n\tFor the hexagonal lattice, the program detects which primitive lattice vectors constitute the triangular lattice and orients them such that one is along the $ x $-axis and the other is in the $ xy $-plane (easily done by rotating the third primitive lattice vector such that it is parallel with the $ z $-axis). The same approach is used for the base centred monoclinic, but here the program always aligns $ \\V{a}_1 $ along the $ x $-axis, and $ \\V{a}_2 $ in the $ xy $-plane. Here however, the easy option of rotating $ \\V{a}_3 $ is not available. Instead the program uses the fact that the vector rejection of $ \\V{a}_2 $ with $ \\V{a}_1 $ is orthogonal to $ \\V{a}_1 $ (the vector rejection of $ \\V{a}_2 $ with $ \\V{a}_1 $ being $ \\V{a}_2 $ minus the projection of $ \\V{a}_2 $ along $ \\V{a}_1 $):\n\t\n\t\\begin{equation}\n\t\t\\V{a}_{2,rej} = \\V{a}_2 - \\V{a}_{2, proj} = \\V{a}_2 - \\frac{\\V{a}_2 \\D \\V{a}_1}{|\\V{a}_1|} \\V{a}_1.\n\t\\end{equation}\n\tThis vector rejection is then in the $ yz $-plane, and the crystal can be rotated around $ \\V{a}_1 $ with the angle the rejection makes with $ \\U{y} $: $ \\cos \\theta = \\V{a}_{2,rej} \\D \\U{y} / |\\V{a}_{2,rej}|$.\n\t\n\tFor the face centred lattices, the ideal, rotated lattice is created from the magnitudes of the primitive lattice vectors: if $ |\\V{a}_1| = a, |\\V{a}_2| = b, |\\V{a}_3| = c $, then $ \\V{a}'_1 = (a/2, b/2, 0), \\V{a}'_2 = (a/2, 0, c/2), \\V{a}'_3 = (0, b/2, c/2) $. First the crystal is rotated such that $ \\V{a}_1 $ aligns with $ \\V{a}'_1 $, by using their cross product. Then the crystal is rotated such that the now rotated $ \\V{a}_2 $ aligns with $ \\V{a}'_2 $, via the vector rejection of $ \\V{a}_2 $ with $ \\V{a}'_2 $. A thing to note is that these 5 rotation functions necessitates primitive lattice vectors of the form specified in the appendix. If the user specifies a lattice unlike those in the appendix, the program will not be able to identify it, and as such may rotate it ``incorrectly''. This could lead to the program not being able to impose grid lines along the cardinal axes for an fcc lattice, for example.\n\t\n\tWith the lattice and basis rotated, the program finds the limits of the plot box as written above, after which the crystal is generated. This is done by looping over the three ranges specified by the minimum and maximum coefficients, creating each lattice point $ \\V{R} $ by Eq. \\eqref{eq:lattice_points}. For each lattice point the program calculates the positions of the $ n $ atoms in the basis, by adding one of the $ n $ vectors in the basis to the lattice point, i.e. $ \\V{r}_{atom, i} = \\V{R} + \\V{r}_{basis, i} $. Lists of the colours and sizes associated with each atom are also created at this point. After creating all the atoms, the program deletes any that may lie outside the limits of the plot box.\n\t\n\tThe only thing missing now is to create the grid lines and plot everything. The program has two ways of creating grid lines: along the primitive lattice vectors and along the cardinal axes.\n\t\n\tCreating grid lines along the primitive lattice vectors works by taking each lattice point $ \\V{R}_n $, and finding the lattice point $ \\V{R}_m $ the furthest away from it, in the (positive) direction of these lattice vectors, such that $ \\V{R}_m = \\V{R}_n + \\alpha \\V{a}_i $, where $ \\alpha > 0 $, for all $ i \\in \\{1,2,3\\}$, and creating lines between $ \\V{R}_n $ and $ \\V{R}_m $. This does create duplicate grid lines, but these do not show on the final plot, since they are all plotted with the same width and colour.\n\t\n\tCreating grid lines along the cardinal axes works by finding the minimum spacing between lattice points on these axes (called $ a_x, a_y$ and $ a_z $), and using these as the spacing between grid lines. The program then finds the maximum and minimum coordinates of lattice points along the cardinal axes (called $x_{min}, x_{max}$, etc.). This is used to create ranges corresponding to each lattice points on the cardinal axes: The range for the $ x $-axis starting at $ x_{min} $  and ending at $ x_{max} $ with steps of $ a_x $.\n\t\n\tThese ranges then specify a grid of lattice points on the $ xy$, $ xz $ and $ yz $-planes. The program then creates lines orthogonal to these planes, stretching from $ z_{min} $ to $ z_{max} $ for the points in the $ xy $-plane, and similarly for the other two planes.\n\t\n\tWith everything calculated a blank figure is created with limits as calculated above. The atoms are plotted with colours and sizes specified by the user. The grid lines are plotted with a uniform size and colour and lastly the primitive lattice vectors are plotted with corresponding labels.\n\t\n\t\\subsection{Examples}\n\tAs an example, we plot a simple cubic lattice with a two atom basis (corresponding to the basis of a bcc lattice with conventional unit cells), where the atoms on the lattice points are grey and the body centred atoms are blue (figure \\ref{fig:lattice_demo_1}), we write the following:\n\\begin{lstlisting}\nLattice(lattice_name=\"conventional bcc\",\n\t\tcolors=[\"xkcd:cement\", \"b\"])\n\\end{lstlisting}\n\tOr we could plot a hexagonal lattice with a one atom basis (figure \\ref{fig:lattice_demo_2}):\n\\begin{lstlisting}\nLattice(lattice_name=\"hexagonal\")\n\\end{lstlisting}\n\tWhen plotted using the program, these plots are interactive and can be rotated.\n\n\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\begin{minipage}{.4\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=2in]{figures/lattice_demo_1.pdf}\n\t\t\t\\captionof{figure}{A simple cubic lattice with a two atom basis: One atom on the lattice points and another in the middle of each unit cell.}\n\t\t\t\\label{fig:lattice_demo_1}\n\t\t\\end{minipage}%\n\t\t\\hfil\n\t\t\\begin{minipage}{.4\\textwidth}\n\t\t\t\\centering\n\t\t\t\\includegraphics[width=2in]{figures/lattice_demo_2.pdf}\n\t\t\t\\captionof{figure}{A hexagonal lattice with a one atom basis. The lattice consists of a series of triangular lattices stacked on top of each other.}\n\t\t\t\\label{fig:lattice_demo_2}\n\t\t\\end{minipage}\n\t\\end{figure}\n\t\n\\end{document}", "meta": {"hexsha": "87c5219157fe5f037eeefdd6334b2dff2814310c", "size": 18438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/lattices.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/lattices.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/lattices.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": 117.4394904459, "max_line_length": 1128, "alphanum_fraction": 0.747315327, "num_tokens": 4905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6245340773103542}}
{"text": "\\documentclass[a4paper,12pt]{article}\n% decent example of doing mathematics and proofs in LaTeX.\n% An Incredible degree of information can be found at\n% http://en.wikibooks.org/wiki/LaTeX/Mathematics\n\n% Use wide margins, but not quite so wide as fullpage.sty\n\\marginparwidth 0.1in \n\\oddsidemargin 0.05in \n\\evensidemargin 0.05in \n\\marginparsep 0.05in\n\\topmargin 0.05in \n\\textwidth 6in \\textheight 8 in\n% That's about enough definitions\n\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\n\\makeatletter\n\\renewenvironment{proof}[1][\\proofname] {\\par\\pushQED{\\qed}\\normalfont\\topsep6\\p@\\@plus6\\p@\\relax\\trivlist\\item[\\hskip\\labelsep\\bfseries#1\\@addpunct{.}]\\ignorespaces}{\\popQED\\endtrivlist\\@endpefalse}\n\\makeatother\n\n\\newtheoremstyle{break}\n  {\\topsep}{\\topsep}%\n  {\\itshape}{}%\n  {\\bfseries}{}%\n  {\\newline}{}%\n\\theoremstyle{break}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{definition}[theorem]{Definition}\n\n\n\\begin{document}\n\n\\title{Linear Algebra Theorems}\n\\author{Hyeonsu Lyu, Department of Electrical Engineering, UNIST}\n\\date{June 29, 2018}\n\\maketitle\n\n\\section{Linear Transformation}\n\\begin{definition} [Linear Transformation from $\\mathbb{R}^n$ to $\\mathbb{R}^m$]\n    A \\textit{linear transformation} $T : \\mathbb{R}^n\\to\\mathbb{R}^m$ is a mapping such that for all scarars $\\textit{a}$ and all $\\overrightarrow{v}, \\overrightarrow{w} \\in \\mathbb{R}^n,$\n\\begin{align}\n    T(\\overrightarrow{v}+\\overrightarrow{w}=T(\\overrightarrow{v}+\\overrightarrow{w})\\ and\\ T(a\\overrightarrow{v})=aT(\\overrightarrow{v})\n\\end{align}\n\\end{definition}\n\n\\begin{theorem} [Matrices and Linear transformations]\\label{thm:mlt}\n    1. Any $m\\times n$ matrix A defines a linear transformation $T:\\mathbb{R}^n\\to\\mathbb{R}^m$ by matrix multiplication:\n    \\begin{align}\n        T(\\overrightarrow{v})=A\\overrightarrow{v}.\n    \\end{align}\n        2. Every linear transformation $T:\\mathbb{R}^n\\to\\mathbb{R}^m$ is given by multiplication by the $m\\times n$ matrix $[T]$:\n    \\begin{align}\n        T(\\overrightarrow{v})=[T]\\overrightarrow{v}\n    \\end{align}\n        ,where the \\textit{i}th column of $[T]$ is $T(\\overrightarrow{e_i}).$\n\\end{theorem}\n\n\\begin{proof}[Proof of theorem \\ref{thm:mlt}] \\hfill \\\\\n1. By definition of \\textit{linear transformation}, mapping (2) is \\textit{linear}.\\\\\n2. For any vector $\\overrightarrow{v}\\in \\mathbb{R}^n$, $v$ can be represented as basis of $\\mathbb{R}^n$, $\\{\\overrightarrow{e_1},\\overrightarrow{e_2}, \\dots, \\overrightarrow{e_n}\\}$.\n\\begin{align}\n    \\overrightarrow{v} = v_1\\overrightarrow{e_1}+v_2\\overrightarrow{e_2}+\\dots+v_n\\overrightarrow{e_n}\n\\end{align}\nSince the linearity of mapping T,\n\\begin{align*}\n    T(\\overrightarrow{v})&=v_1T(\\overrightarrow{e_1})+v_2T(\\overrightarrow{e_2})+\\dots+v_nT(\\overrightarrow{e_n})\\\\\n    &=[T(\\overrightarrow{e_1})|T(\\overrightarrow{e_2})|\\dots|T(\\overrightarrow{e_n})]\\begin{bmatrix}v_1 \\\\ v_2 \\\\ \\vdots \\\\ v_n\\end{bmatrix}\\\\\n    &= [T]\\overrightarrow{v}\n\\end{align*}\n\\end{proof}\n\n\\begin{definition} [Linear Transformation is onto]\n    Let $A$ be $m\\times n$ matrix. The followings are logically equivalent: \\\\\n    \\indent1. The function $Ax=b$ is onto $\\mathbb{R}^m$.\\\\\n    \\indent2. For each $b\\in \\mathbb{R^m}$, the equation Ax=b has a solution.\\\\\n    \\indent3. $b\\in \\mathbb{R^m}$ is a linear combination of the columns of $A$.\\\\\n    \\indent4. The columns of $A$ span $\\mathbb{R^m}$.\\\\\n    \\indent5. $A$ has a pivot position in every row.\\\\\n    \\indent6. $A$ has rank m\\\\\n\\end{definition}\n\n\\begin{definition} [Linear Transformation is 1-1]\n    Let $A$ be an $m\\times n$ matrix. The followings are logically equivalent:\\\\\n    \\indent1. The function $Ax=b$ is $1-1$.\\\\\n    \\indent2. The equation $Ax=b$ has at most on solution for every b.\\\\\n    \\indent3. The equation $Ax=0$ has only the trivial solution.\\\\\n    \\indent4. The columns of A are linearly independent.\\\\\n    \\indent5. A has a pivot posiition in every column.\\\\\n    \\indent6. A has rank n.\\\\\n\\end{definition}\n\nRelated theroems : Inverse function theorem, Implicit function theorem, Tangent space on implicit function.\n\n\\section{Another Section}\n\n\\end{document}\n\n", "meta": {"hexsha": "9bbc70c6240ec5fa4ec234335e6be1e02e098200", "size": 4247, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics/LinearAlgebra.tex", "max_stars_repo_name": "lhs55349780/Latex-Suite", "max_stars_repo_head_hexsha": "3ccd4c123c25571ac21ad2ccbaa5600a7f4c5568", "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": "Mathematics/LinearAlgebra.tex", "max_issues_repo_name": "lhs55349780/Latex-Suite", "max_issues_repo_head_hexsha": "3ccd4c123c25571ac21ad2ccbaa5600a7f4c5568", "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": "Mathematics/LinearAlgebra.tex", "max_forks_repo_name": "lhs55349780/Latex-Suite", "max_forks_repo_head_hexsha": "3ccd4c123c25571ac21ad2ccbaa5600a7f4c5568", "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": 40.8365384615, "max_line_length": 199, "alphanum_fraction": 0.7077937368, "num_tokens": 1442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6245340742997472}}
{"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 2}\n\nConsider the set of points in $\\mathbb{R}^2$ shown in Figure \\ref{fig1}.\nPositive examples are shown as black circles, while negative examples are shown as gray circles.\n\\begin{enumerate}[label=(\\alph*)]\n\\item Find classifiers for the sample using at least four kernels available in the package of $R$ software.\n\\item Graph the total time required by these kernels as a function of the error rate obtained on the training set.\n\\end{enumerate}\n\n\\begin{figure}[H]\\centering\n\\tikzstyle{black}=[circle, draw, fill=black]\n\\tikzstyle{white}=[circle, draw, fill=gray!20]\n\\begin{tikzpicture}\n  \\draw [thick, color=gray, step=0.5cm, dashed] (0,0) grid (5,5);\n  \\draw [<->,thick] (0,5.5) node (yaxis) [left] {$y$} |- (5.5,0) node (xaxis) [below] {$x$};\n  \\foreach \\Point in { (4.5,0.5), (4,1), (3.5,1.5), (3,2), (4,2), (2.5,2.5), (3.5,2.5), (3,3), (4,3), (3.5,3.5), (4,4), (4.5,4.5) } {\n\t\\fill[black] \\Point circle (3pt);\n  }\n  \\foreach \\Point in {(1,0.5), (1,1.5), (1.5,1.5), (1.5,2.5), (1,3), (2,3.5), (2.5,4), (1,4.5), (3, 2.5)} {\n    \\fill[white] \\Point circle (3pt);\n  }\n\\end{tikzpicture}\n\\caption{Training Sample}\\label{fig1}\n\\end{figure}\n\n\\vfill\n\n\\subsection*{Solution}\n\n\\begin{table}[H]\\centering\n\\begin{tabular}{r l c c}\nKernel & Function Name & Training Error & Execution Time\\\\\n\\hline\nLinear & \\texttt{vanilladot} & 4.761905 & 0.01\\\\\nRadial Basis & \\texttt{rbfdot} & 4.761905 & 0.02\\\\\nPolynomial & \\texttt{polydot} & 4.761905 & 0.01\\\\\nANOVA RBF & \\texttt{anovadot} & 4.761905 & 0.02\\\\\nBessel & \\texttt{besseldot} & 4.761905 & 0.00\\\\\nLaplacian & \\texttt{laplacedot} & 4.761905 & 0.02\\\\\nSpline & \\texttt{splinedot} & 9.52381 & 0.01\\\\\nHyperbolic Tangent & \\texttt{tanhdot} & 19.04762 & 0.00\\\\\n\\hline\n\\end{tabular}\n\\caption{Performance of Different Kernel Functions on Training Sample given in Fig \\ref{fig1}}\\label{tab1}\n\\end{table}\n\nThe training dataset shown in Figure \\ref{fig1} is constructed in comma-separated value format.\nUsing R programming-language, the training dataset is imported to workspace and is used to construct classifiers using kernels available in the \\texttt{kernlab} package.\nTable \\ref{tab1} provides the list of kernels used for SVM-based classification as well as their training error and execution time for their construction over given training dataset.\n\nFig \\ref{fig2}, generated by R, presents the training error resulting construction of  classifiers using different kernel functions.\nAs can be seen, \\texttt{splinedot} and \\texttt{tanhdot} kernels have failed to classify the training dataset accurately.\nThe similar training error achieved by other kernel functions can be justified by noting the limited amount of samples in the training dataset as well as the way they are formed  which makes it fairly easy to classify.\n\n\\begin{figure}\\centering\n\\includegraphics[width=0.8\\textwidth]{\\imgDirectory/umb-cs671-2015s-f01-02.png}\n\\caption{Training Error for Different Kernels}\\label{fig2}\n\\end{figure}\n\nAlso, plot of execution time of different kernel functions in constructing classifier for the training dataset is given in Figure \\ref{fig3}.\n\n\\begin{figure}\\centering\n\\includegraphics[width=0.8\\textwidth]{\\imgDirectory/umb-cs671-2015s-f01-03.png}\n\\caption{Execution Time for Different Kernel Functions}\\label{fig3}\n\\end{figure}\n\nFigure \\ref{fig4} depicts the execution time based on training error for different kernel functions.\n\n\\begin{figure}\\centering\n\\includegraphics[width=0.8\\textwidth]{\\imgDirectory/umb-cs671-2015s-f01-04.png}\n\\caption{Execution-Time based on Error-Rate for Different Kernels}\\label{fig4}\n\\end{figure}\n\nIt can be inferred that using kernel functions that promise better performance in terms of training error might necessitate higher computational costs which lead to longer execution times.\nHowever, this particular example does not prove this point as can be seen in Fig \\ref{fig4}.\nIn fact, rerunning the same script would give different results each time.\nThis is due to the limited amount of the training dataset that will make the errors in measurement of the execution time quite considerable.\nTo prove our claim, the same code in R programming language has been applied to the larger database given for letter recognitions, results of which are included in the files attached to this document.\n\nThe code in R data-analysis software to construct and compare classifiers over the training dataset given in \\ref{fig1} has been given as appendix to this report.\n", "meta": {"hexsha": "9a40fc08a7b8d939be7157e71b699c35002edcd8", "size": 4799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/f01/f01q02.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/f01q02.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/f01q02.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": 54.5340909091, "max_line_length": 218, "alphanum_fraction": 0.7284851011, "num_tokens": 1397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6245340732154576}}
{"text": "%\n% CMPT 310: Artificial Intelligence - A Course Overview\n% Section: Search Algorithms\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Search Algorithms}\n\t\\label{sec:search-algorithms}\n\\subsection{Uninformed Algorithms}\n\t\\label{subsec:uninformed-algorithms}\n\\begin{easylist}\n\n& \\textbf{Breadth-first search:} Utilizes a queue\n\t&& Time and space complexity: Bounded by the number of nodes the same distance away from the root as the goal node\n\t&& Complete if branching factor is finite\n\n& \\textbf{Uniform-cost search:} Utilizes a priority queue to follow the path with least cost\n\t&& Time and space complexity: Bounded by the branching factor to the power of the average action cost\n\t&& Complete if branching factor is finite and step costs $\\leq \\epsilon$\n\n& \\textbf{Depth-first search:} Utilizes a stack\n\t&& Time complexity: Bounded by the maximum depth of the tree\n\t&& Space complexity: Bounded by the length of the maximum-length path, and its remaining unexpanded child nodes for each node on the path\n\t&& Not complete\n\t&& More space-efficient than breadth-first search\n\n& \\textbf{Iterative deepening (depth-first) search:} Depth-first search with maximum limited depth, which increases until the goal is found\n\t&& Complete if branching factor is finite\n\t&& Time complexity: Bounded by the number of nodes the same distance away from the root as the goal node\n\t&& Space complexity: Bounded by the length of the goal path, and its remaining unexpanded child nodes for each node on the path\n\n\\end{easylist}\n\\subsection{Informed Algorithms}\n\t\\label{subsec:informed-algorithms}\n\\begin{easylist}\n\n& \\textbf{Admissible heuristic:} Underestimation of the true cost from a given node to the goal\n\t&& Notation for a function evaluating a heuristic: $h(n)$\n\t&& Will provide improved time and space complexity over the worst time\n\t&& To create an admissible heuristic, relax a rule/constraint and find the shortest solution given\n\t&& \\textbf{Manhattan distance:} Number of unrestricted 4-directional moves from the goal state\n\t&& \\textbf{Dominance:} Characteristic of an admissible heuristic which has a result greater than or equal to another admissible heuristic for all $n$\n\t\t&& Given admissible heuristics $h_a(n)$ and $h_b(n)$, $h(n) = \\textrm{max}\\left(h_a(n), h_b(n)\\right)$ is also admissible and dominates $h_a(n)$ and $h_b(n)$\n\n& \\textbf{Greedy search:} Best-first search algorithm which chooses subsequent nodes by minimizing direct cost to the goal\n\t&& Complete: Only if state is checked for repeats\n\t&& Time and space complexity: At worst, bounded by all nodes\n\n& \\textbf{A* search:} Best-first search algorithm which expands only the paths with less cost than the optimal cost to the goal\n\t&& Evaluation function:\n\n\t\\end{easylist}\n\t\\begin{align*}\n\t\tf(n) & = g(n) + h(n) \\\\\n\t\t\\textrm{where }\n\t\t& f(n) = \\textrm{ estimated total cost of the path through } n \\textrm{ to the goal} \\\\\n\t\t& g(n) = \\textrm{ cost so far to reach } n \\\\\n\t\t& h(n) = \\textrm{ heuristic-estimated cost from } n \\textrm{ to the goal}\n\t\\end{align*}\n\t\\begin{easylist}\n\n\t&& Complete: Yes (unless there are infinitely many nodes with $f \\leq f(G)$)\n\n\\end{easylist}\n\\subsection{Complexity of Algorithms}\n\t\\label{subsec:complexity-of-algorithms}\n\n\\begin{figure}[!htb]\n\t\\caption{Complexity of Algorithms}\n\t\\label{fig:algos-complexity}\n\t\\center\n\t\\begin{tabular}{ l | c c p{4cm} }\n\t\t& Time & Space & Is the Goal Path Optimal? \\\\\n\t\t\\hline\n\t\tBreadth-first search & $O(b^{d+1})$ & $O(b^d)$ & Only when $d = 1$ or when paths have no cost \\\\\n\t\tUniform-cost search & $O(b^{\\left\\lfloor \\frac{C^*}{\\epsilon} \\right\\rfloor})$ & $O(b^{\\left\\lfloor \\frac{C^*}{\\epsilon} \\right\\rfloor})$ & Yes \\\\\n\t\tDepth-first search & $O(b^m)$ & $O(b \\cdot m)$ & No \\\\\n\t\tIterative deepening search & $O(b^d)$ & $O(b \\cdot d)$ & Yes \\\\\n\t\t\\hline\n\t\tGreedy search & $O(b^m)$ & $O(b^m)$ & No \\\\\n\t\tA\\textsuperscript{*} search & $O(b^m)$ & $O(b^m)$ & Yes \\\\\n\t\t\\hline\n\t\tMinimax algorithm & $O(b^m)$ (with $\\alpha / \\beta$, $O(b^\\frac{m}{2})$) & $O(b \\cdot m)$ & Yes (with rational adversary) \\\\\n\t\tBacktracking search & & & Yes \\\\\n\t\tHill climbing search & & & No \\\\\n\t\tSimulated annealing search & & & Yes\n\t\\end{tabular}\n\n\t\\begin{align*}\n\t\t\\textrm{where }\n\t\tb &= \\textrm{ branching factor} \\\\\n\t\td &= \\textrm{ depth of the goal} \\\\\n\t\tC^* &= \\textrm{ cost of the optimal solution} \\\\\n\t\t\\epsilon &= \\textrm{ the minimum cost of an action on the goal path} \\\\\n\t\tm &= \\textrm{ maximum depth}\n\t\\end{align*}\n\\end{figure}\n\n\\clearpage\n", "meta": {"hexsha": "51be775460ea8dae340c523b9977c8d8a021a57e", "size": 4449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-310-artificial-intelligence-survey/course-overview/tex/search-algorithms.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-310-artificial-intelligence-survey/course-overview/tex/search-algorithms.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-310-artificial-intelligence-survey/course-overview/tex/search-algorithms.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": 44.0495049505, "max_line_length": 159, "alphanum_fraction": 0.7064508878, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6245340695058242}}
{"text": "\\section{Edge discretization}\\label{edge_discretization}\nWe calculate the location $l$ of the boundary between a significant and nonsignificant portion of an edge analytically.\nFor example, the parabolic MAT edge generated from the outline vertex $(0,1)$ and an outline segment aligned with the X-axis follows $y(x) = \\nicefrac12 x^2$ and $R(x) = y(x)$.\nWe can determine the significant portion $[-x_\\text{bound}, x_\\text{bound}]$ by evaluating $\\frac{\\partial R}{\\partial x} > \\cos(\\alpha_\\text{max} / 2)$, which is $ | x_\\text{bound} | = (\\tan(\\alpha_\\text{max} / 2))^{-1}$.\nSimilarly, a MAT edge generated from two vertices at $(0,0)$ and $(0,1)$ follows $y(x) = \\nicefrac12$ and $R(x) = \\sqrt{\\nicefrac14 + x^2}$.\nThe boundaries of significance are given by $ | x_\\text{bound} | = \\nicefrac12 (\\tan(\\alpha_\\text{max} / 2))^{-1}$.\nFrom these we can derive the locations $l = (\\pm x_\\text{bound}, y(x_\\text{bound}))$.\nThese specific cases can easily be transformed into all possible cases using scaling and rotation operations.", "meta": {"hexsha": "a7b1fa3666c897fa84fffdaea013df038e98b47a", "size": 1029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "19_edge_discretization.tex", "max_stars_repo_name": "BagelOrb/variable_width_paper", "max_stars_repo_head_hexsha": "8b8b7a2b9b913e56267a578d2a15ed7e97fa3503", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-23T10:22:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-23T10:22:42.000Z", "max_issues_repo_path": "19_edge_discretization.tex", "max_issues_repo_name": "BagelOrb/variable_width_paper", "max_issues_repo_head_hexsha": "8b8b7a2b9b913e56267a578d2a15ed7e97fa3503", "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": "19_edge_discretization.tex", "max_forks_repo_name": "BagelOrb/variable_width_paper", "max_forks_repo_head_hexsha": "8b8b7a2b9b913e56267a578d2a15ed7e97fa3503", "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": 128.625, "max_line_length": 222, "alphanum_fraction": 0.7123420797, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.6893056040203135, "lm_q1q2_score": 0.6245038586259679}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\title{Math Proofs}\n\\author{Andrew Archibald}\n\\date{July 2017}\n\n\\begin{document}\n\n\\begin{titlepage}\n\\maketitle\n\\end{titlepage}\n\n\\section{Pi by the sum of inverse squares}\n\n$$\\frac{\\pi^2}{6} = \\sum_{n=1}^{\\infty}\\frac{1}{n^2}$$\n\n\\section{Pi by inverse tangent Taylor series}\n\n\\begin{align*}\n\\arctan x &= x - \\frac{x^3}{3} + \\frac{x^5}{5} - \\frac{x^7}{7} + \\frac{x^9}{9} - \\cdots \\\\\n          &= \\sum_{n=0}^{\\infty} (-1)^n \\frac{x^{2n + 1}}{2n + 1}\n\\end{align*}\n$$x \\in [-1, 1]$$\n$$\\frac{\\pi}{4} = \\arctan 1\n= \\sum_{n=0}^{\\infty} \\frac{(-1)^n}{2n + 1}$$\n\n\\section{Pi by inscribed and circumscribed polygons}\n\n\\subsection{Inscribed}\n\n\\subsubsection{Law of sines}\n\n$$\\frac{\\sin(\\frac{\\pi}{2}-\\frac{\\pi}{n})}{r} = \\frac{\\sin\\frac{2\\pi}{n}}{l}$$\n$$= \\frac{\\cos\\frac{\\pi}{n}}{r} = \\frac{2\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}}{l}$$\n$$l = 2r\\sin\\frac{\\pi}{n}$$\n$$P = ln\n= 2rn\\sin\\frac{\\pi}{n}$$\n\n\\subsubsection{Law of cosines}\n\n$$l^2 = 2r^2 - 2r^2cos\\frac{2\\pi}{n}\n= 2r^2\\left(1 - cos\\frac{2\\pi}{n}\\right)\n= 4r^2\\left(\\frac{1 - cos\\frac{2\\pi}{n}}{2}\\right)\n= 4r^2\\sin^2{\\frac{\\pi}{n}}$$\n$$l = 2r\\sin\\frac{\\pi}{n} = r\\sqrt{2 - 2\\cos\\frac{2\\pi}{n}}$$\n$$P = 2n\\sin\\frac{\\pi}{n}$$\n\n\\subsubsection{Pythagorean theorem}\n\n$$r^2 = \\left(\\frac{l}{2}\\right)^2 + h^2$$\n$$h^2 = r^2 - \\frac{1}{4}l^2\n= r^2 - r^2\\sin^2\\frac{\\pi}{n}\n= r^2\\left(1 - \\sin^2\\frac{\\pi}{n}\\right)\n= r^2\\cos^2\\frac{\\pi}{n}$$\n$$h = r\\cos\\frac{\\pi}{n}$$\n$$A = \\frac{1}{2}lhn\n= \\frac{1}{2}\\left(2r\\sin\\frac{\\pi}{n}\\right)\\left(rcos\\frac{\\pi}{n}\\right)n\n= nr^2\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}\n= \\frac{1}{2}nr^2\\sin\\frac{2\\pi}{n}$$\n\n\\subsubsection{Results}\n\nPerimeter\n\n$$2\\pi{r} = \\lim_{n\\to\\infty} P\n= \\lim_{n\\to\\infty} 2rn\\sin\\frac{\\pi}{n}$$\n\nArea\n\n$$\\pi{r^2} = \\lim_{n\\to\\infty} \\frac{1}{2}nr^2\\sin\\frac{2\\pi}{n}$$\n$$\\pi = \\lim_{n\\to\\infty} \\frac{1}{2}n\\sin\\frac{2\\pi}{n}\n= \\lim_{n\\to\\infty} n\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}$$\n\n\\subsection{Circumscribed}\n\n\\subsubsection{Law of sines}\n\n$$\\frac{\\sin\\frac{\\pi}{n}}{L} = \\frac{\\sin\\left(\\pi - \\frac{2\\pi}{n}\\right)}{l}$$\n$$\\sin\\left(\\pi - \\frac{2\\pi}{n}\\right) = \\sin\\left[2\\left(\\frac{\\pi}{2} - \\frac{\\pi}{n}\\right)\\right]\n= 2\\sin\\left(\\frac{\\pi}{2} - \\frac{\\pi}{n}\\right)\\cos\\left(\\frac{\\pi}{2} - \\frac{\\pi}{n}\\right)\n= 2\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}$$\n$$L = \\frac{l\\sin\\frac{\\pi}{n}}{2\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}}\n= \\frac{1}{2}l\\sec\\frac{\\pi}{n}\n= \\frac{1}{2}\\left(2r\\sin\\frac{\\pi}{n}\\right)\\sec\\frac{\\pi}{n}\n= r\\tan\\frac{\\pi}{n}$$\n\n\\subsubsection{Law of cosines}\n\n$$l^2 = 2L^2 - 2L^2cos\\frac{\\pi - 2\\pi}{n}\n= L^2\\left(2 - 2\\cos\\left(\\pi - \\frac{2\\pi}{n}\\right)\\right)$$\n$$\\cos\\left(\\pi - \\frac{2\\pi}{n}\\right) = \\cos\\left(2\\left(\\frac{\\pi}{2} - \\frac{\\pi}{n}\\right)\\right)\n= 1 - 2\\sin^2\\left(\\frac{\\pi}{2} - \\frac{\\pi}{n}\\right)\n= 1 - 2\\cos^2\\frac{\\pi}{2}$$\n$$l^2 = L^2\\left[2 - 2\\left(1 - 2\\cos^2\\frac{\\pi}{n}\\right)\\right]\n= 4L^2\\cos^2\\frac{\\pi}{n}$$\n$$l = 2L\\cos\\frac{\\pi}{n}$$\n$$2r\\sin\\frac{\\pi}{n} = 2L\\cos{\\pi}{n}$$\n$$L = r\\tan\\frac{\\pi}{n}$$\n\n\\subsubsection{Pythagorean theorem}\n\n$$L^2 = \\left(\\frac{l}{2}\\right)^2 + H^2$$\n$$H^2 = r^2tan^2\\frac{\\pi}{n} - r^2\\sin^2\\frac{\\pi}{n}\n= r^2\\left(\\tan^2\\frac{\\pi}{n} - \\sin^2\\frac{\\pi}{n}\\right)$$\n$$tan^2\\frac{\\pi}{n} - \\sin^2\\frac{\\pi}{n} = tan^2\\frac{\\pi}{n} - \\cos^2\\frac{\\pi}{2}\\tan\\frac{\\pi}{2}\n= \\tan^2\\frac{\\pi}{n}\\left(1 - \\cos^2\\frac{\\pi}{n}\\right)\n= \\sin^2\\frac{\\pi}{n}tan^2\\frac{\\pi}{n}$$\n$$H^2 = R^2sin^2\\frac{\\pi}{n}\\tan^2{\\pi}{n}$$\n$$H = r\\sin\\frac{\\pi}{n}\\tan\\frac{\\pi}{n}$$\n\n\\subsubsection{Results}\n\nPerimeter\n\n$$P = 2nL = 2nr\\tan\\frac{\\pi}{n}$$\n$$2\\pi{r} = \\lim_{n\\to\\infty} 2nr\\tan\\frac{\\pi}{n}$$\n$$\\pi = \\lim_{n\\to\\infty} n\\tan\\frac{\\pi}{n}$$\n\nArea\n\n$$A = nH\\frac{L}{2} + A_l$$\n$$  = n\\left(r\\sin\\frac{\\pi}{n}\\tan\\frac{\\pi}{n}\\right)\\left(r\\sin\\frac{\\pi}{n}\\right) + A_l$$\n$$  = nr^2\\sin^2\\frac{\\pi}{n}\\tan\\frac{\\pi}{n} + A_l$$\n$$  = nr^2\\sin^2\\frac{\\pi}{n}\\tan\\frac{\\pi}{n} + nr^2\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}$$\n$$  = nr^2\\sin\\frac{\\pi}{n}\\left(\\sin\\frac{\\pi}{n}\\tan\\frac{\\pi}{n} + \\cos\\frac{\\pi}{n}\\right)$$\n$$  = nr^2\\tan\\frac{\\pi}{n}\\left(\\sin^2\\frac{\\pi}{n} + \\cos^2\\frac{\\pi}{n}\\right)$$\n$$  = nr^2\\tan\\frac{\\pi}{n}$$\n$$\\pi{r^2} = \\lim_{n\\to\\infty} nr^2\\tan\\frac{\\pi}{n}$$\n$$\\pi = \\lim_{n\\to\\infty} n\\tan\\frac{\\pi}{n}$$\n\n\\subsection{Simplified results}\n\n$$\\pi = \\lim_{n\\to\\infty} n\\sin\\frac{\\pi}{n}$$\n$$\\pi = \\lim_{n\\to\\infty} n\\sin\\frac{\\pi}{n}\\cos\\frac{\\pi}{n}$$\n$$\\pi = \\lim_{n\\to\\infty} n\\tan\\frac{\\pi}{n}$$\n\n\\section{Multi-dimensional spheres}\n\n$$V_1 = \\int\\limits_{-R}^{R} dx = 2R$$\n$$V_2\n= \\int\\limits_{-R}^{R} \\int_{-\\sqrt{R^2-x^2}}^{\\sqrt{R^2-x^2}} dydx\n= \\int\\limits_{-R}^{R} 2\\sqrt{R^2-x^2} dx\n= \\int\\limits_{-R}^{R} 2R\\sin\\arccos\\frac{x}{R} dx$$\n$$V_2\n= \\int\\limits_0^{2\\pi} \\int\\limits_0^{R} r drd\\theta\n= \\int\\limits_0^{2\\pi} \\frac{1}{2}R^2 d\\theta\n= \\pi R^2$$\n\n\\section{Trigonometric integrals}\n\n\\begin{align*}\n\\int \\sin^2{x} dx\n  &= \\int \\frac{1-\\cos{2x}}{2} dx \\\\\n  &= \\frac{1}{2}(x - \\sin{x}\\cos{x}) + C\n\\\\\\\\\n\\int \\cos^2{x} dx\n  &= \\int \\frac{1+\\cos{2x}}{2} dx \\\\\n  &= \\frac{1}{2}(x + \\sin{x}\\cos{x}) + C\n\\end{align*}\n\n\\begin{align*}\n\\int \\sin^3{x} dx\n  &= \\int (1 - \\cos^2{x})\\sin{x} dx \\\\\n  &= \\int (\\sin{x} - \\cos^2{x}\\sin{x}) dx \\\\\n  &= -\\cos{x} + \\frac{1}{3}\\cos^3{x} + C\n\\\\\\\\\n\\int \\cos^3{x} dx\n  &= \\int (1 - \\sin^2{x})\\cos{x} dx \\\\\n  &= \\int (\\cos{x} - \\sin^2{x}\\cos{x}) dx \\\\\n  &= \\sin{x} - \\frac{1}{3}\\sin^3{x} + C\n\\end{align*}\n\n\\begin{align*}\n\\int \\sin^4{x} dx\n  &= \\int \\left(\\frac{1 -\\cos{2x}}{2}\\right)^2 dx \\\\\n  &= \\int \\frac{1}{4}(1 - 2\\cos{2x} + \\cos^2{2x}) dx \\\\\n  &= \\int \\frac{1}{4}\\left(1 - 2\\cos{2x} + \\frac{1 + \\cos{4x}}{2}\\right) dx \\\\\n  &= \\int \\frac{1}{8}(3 - 4\\cos{2x} + \\cos{4x}) dx \\\\\n  &= \\frac{1}{8}\\left(3x - 2\\sin{2x} + \\frac{1}{4}\\sin{4x}\\right) + C\n\\\\\\\\\n\\int \\cos^4{x} dx\n  &= \\int \\left(\\frac{1 +\\cos{2x}}{2}\\right)^2 dx \\\\\n  &= \\int \\frac{1}{4}(1 + 2\\cos{2x} + \\cos^2{2x}) dx \\\\\n  &= \\int \\frac{1}{4}\\left(1 + 2\\cos{2x} + \\frac{1 + \\cos{4x}}{2}\\right) dx \\\\\n  &= \\int \\frac{1}{8}(3 + 4\\cos{2x} + \\cos{4x}) dx \\\\\n  &= \\frac{1}{8}\\left(3x + 2\\sin{2x} + \\frac{1}{4}\\sin{4x}\\right) + C\n\\end{align*}\n\n\\begin{align*}\n\\int \\sin^5{x} dx\n  &= \\int (1 - \\cos^2{x})^2\\sin{x} dx \\\\\n  &= \\int (\\sin{x} - 2\\cos^2{x}\\sin{x} + \\cos^4{x}\\sin{x}) dx \\\\\n  &= -\\cos{x} + \\frac{2}{3}\\cos^3{x} - \\frac{1}{5}\\cos^5{x} + C\n\\\\\\\\\n\\int \\cos^5{x} dx\n  &= \\int (1 - \\sin^2{x})^2\\cos{x} dx \\\\\n  &= \\int (\\cos{x} - 2\\sin^2{x}\\cos{x} + \\sin^4{x}\\cos{x}) dx \\\\\n  &= \\sin{x} - \\frac{2}{3}\\sin^3{x} + \\frac{1}{5}\\sin^5{x} + C\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "f7b1b787de65384fbe100a3112ed80fc4ebfba8c", "size": 6517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math.tex", "max_stars_repo_name": "andrewarchi/math-proofs", "max_stars_repo_head_hexsha": "b259e422258d658e1333d5ecf5745483846c23e0", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "andrewarchi/math-proofs", "max_issues_repo_head_hexsha": "b259e422258d658e1333d5ecf5745483846c23e0", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "andrewarchi/math-proofs", "max_forks_repo_head_hexsha": "b259e422258d658e1333d5ecf5745483846c23e0", "max_forks_repo_licenses": ["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": 102, "alphanum_fraction": 0.5347552555, "num_tokens": 3307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6245019933396161}}
{"text": "% Section with some maths\n\n\\section{Ein Abschnitt mit Matheformeln}\n\\blindmathpaper\n\n\n\\subsection{Formeln inkl. Subequations and Labels}\n\\label{sec:maths-incl-subeq}\n\\blindtext\n\\newcommand{\\iu}{{i\\mkern1mu}}\n\\vspace{-.4cm}\n\\begin{subequations}\n  \\begin{align}\n    \\iu \\hbar \\partial_t \\Psi &= - \\iu \\hbar c \\sum_{i=1}^3 \\alpha_i \\partial_i \\Psi + \\beta m c^2 \\Psi\\\\ &= \\left( c \\vec \\alpha \\cdot \\vec p + \\beta m c^2 \\right) \\Psi \\\\\n    \\Longrightarrow \\quad 0 &= \\left( \\iu \\hbar \\gamma^\\mu \\partial_\\mu - mc \\right) \\Psi\n  \\end{align}\n\\end{subequations}\n\\blindtext\n\\begin{align}\n  F(x,y)=0 ~~\\mbox{and}~~\n  \\left| \\begin{array}{ccc}\n           F''_{xx} & F''_{xy} &  F'_x \\\\\n           F''_{yx} & F''_{yy} &  F'_y \\\\\n           F'_x     & F'_y     & 0\n         \\end{array}\\right| = 0\n\\label{eq:1}\n\\end{align}\n\\blindtext\n\n\n% End of file\n", "meta": {"hexsha": "717a52fe18e830525d27b51aab3abc5e581e6ee0", "size": 838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/maths.tex", "max_stars_repo_name": "kzoch/kLabCourse-template", "max_stars_repo_head_hexsha": "efaffbde3bea7ea826357398414b35bf54b934c2", "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": "tex/maths.tex", "max_issues_repo_name": "kzoch/kLabCourse-template", "max_issues_repo_head_hexsha": "efaffbde3bea7ea826357398414b35bf54b934c2", "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/maths.tex", "max_forks_repo_name": "kzoch/kLabCourse-template", "max_forks_repo_head_hexsha": "efaffbde3bea7ea826357398414b35bf54b934c2", "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.1875, "max_line_length": 172, "alphanum_fraction": 0.5942720764, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.6825737214979745, "lm_q1q2_score": 0.6244873449002296}}
{"text": "% !TEX root = ../../main.tex\n\\subsection{xokker-Planck equation in population genetics}\n\nIn the last section after we performed a Taylor expansion of the master\nequation we ended up with an equally complicated partial differential equation\nof infinite order. So in order to make any progress towards simplifying the\ntreatment of the equation what we will do is trade accuracy for simplicity.\nMore concretely if our assumptions on the shape of the transition probability\n$\\phi_t(x; r)$ being sharply peaked are to be taken seriously, we can then\ntruncate the Kramers-Moyal expansion to include only up to second order\nderivatives. This truncated equation would locally approximate the time\nevolution of the probability distribution $P(x, t)$. \\eref{eq_km_expansion}\nthen is of the form\n\\begin{equation}\n  \\ddt{P(x, t)} = - {\\partial \\over \\partial x}\n  \\left[\n  a^{(1)}(x, t) P(x, t)\n  \\right] +\n  {1 \\over 2}{\\partial^2 \\over \\partial f^2}\n  \\left[\n  a^{(2)}(x, t) P(x, t)\n  \\right].\n  \\label{eq_fokker_planck}\n\\end{equation}\nIn the physics literature this is known as the Fokker-Planck equation, while in\nthe mathematics literature is known as the Kolmogorov forward equation. One\nintriguing aspect of how to arrive to this equation is the seemingly arbitrary\nchoice of truncating up to the second moment. The argument that is often thrown\naround is that the ``art'' of these truncations is to stop at the first\nnon-vanishing moment. But for the specific case of the Kramers-Moyal expansion\nof the master equation there is a theorem - Pawula theorem - that shows that\nfor the solutions of the Kramers-Moyal expansion to be interpreted as\nprobability densities the expansion must either contain one, two or an infinite\nnumber of moments. So two sounds much better than infinite, doesn't it?\n\\mrm{Need to include appendix with the proof of Pawula theorem.}\n\n\\subsubsection{Determination of the Fokker-Planck coefficients}\n\nThe two jump moments in \\eref{eq_fokker_planck}, $a^{(1)}$ and $a^{(2)}$\ndefined by \\eref{eq_jump_mom} have a specific interpretation in population\ngenetics. Here is where a little bit of a terminology conflict between physics\nand evolutionary biology comes into play. The directional term, i.e. the one\nwith the first order derivative in \\eref{eq_fokker_planck} is known in the\nphysics literature as the drift term on a diffusion-like equation. This is\nconfusing because in evolutionary theory the diffusive term, i.e. the one with\nthe second derivative in \\eref{eq_fokker_planck} is known as the genetic drift\nterm. I will try to be as consistent as possible on these notes using the terms\ndirectional and diffusive to avoid confusion.\n\nComing back to the directional term, we define $M(x, t)$ to be\n\\begin{equation}\n  M(x, t) \\equiv \\ee{r(t)} = \\int_{-\\infty}^{\\infty} dr \\; \\phi_t(x; r) r,\n\\end{equation}\ni.e. the mean of the jump distribution. As we will see in coming sections this\nterm captures the effect of directional evolutionary forces such as selection,\nmutation and migration. For the diffusive term we define $V(x, t)$ as the\nsecond moment of the jump distribution\n\\begin{equation}\n  V(x, t) \\equiv \\ee{r^2(t)} = \\int_{-\\infty}^{\\infty} dr \\; \\phi_t(x; r) r^2.\n\\end{equation}\nThis term captures the random sampling of alleles, also known as genetic drift.\nIn all of the population genetics literature I have encounter so far, this term\n$V(x, t)$ is treated as the \\textbf{variance} rather than the second moment.\nThis is partly because computing the specific functional form of the variance\nfor different models of reproduction is much simpler. The variance\n$\\sigma_r^2(t)$ is defined as\n\\begin{equation}\n  \\sigma_r^2(t) = \\ee{\\left( r - \\ee{r} \\right)^2} = \\ee{r^2} - \\ee{r}^2.\n\\end{equation}\nWe can therefore work with this more convenient quantity if we assume that\n$\\ee{r}^2 \\approx 0$. This is a reasonable assumption given that for the\nFokker-Planck equation to be accurate we assumed a tight distribution for the\njumpt size $\\phi_t(x; r)$. The peaked nature of this distribution must imply\nthat $\\ee{r} \\ll 1$, but more importantly, we will assume that\n$\\ee{r}^2 \\ll \\ee{r^2}$. So upon using these two definitions we arrive to one\nof the main results in population genetics, the Kimura diffusion equation\n\\begin{equation}\n  \\ddt{P(x, t)} = - {\\partial \\over \\partial x}\n  \\left[\n  M(x, t) P(x, t)\n  \\right] +\n  {1 \\over 2}{\\partial^2 \\over \\partial f^2}\n  \\left[\n  V(x, t) P(x, t)\n  \\right].\n  \\label{eq_kimura_diffusion}\n\\end{equation}\nThe power of diffusion theory is that in these two terms $M(x, t)$ and $V(x,\nt)$ we can include all evolutionary forces acting simultaneously. The\nfunctional forms of these specific terms depend on the reproduction model used.\nWe will explore that more specifically later on.\n\n\\subsubsection{Equilibrium distribution}\n\nIn the limit when $t \\rightarrow \\infty$ we expect the distribution of allele\nfrequencies to reach a steady-state $P_{ss}(x)$. For the 1D case we have\nstudied so far, i.e. two alleles with frequencies $x$ and $1 - x$ this steady\nstate is equivalent to an equilibrium distribution since detailed balance has\nto be satisfied. To emphasize this point let us rewrite\n\\eref{eq_kimura_diffusion} as a statement of conservation of probability. This\nis\n\\begin{equation}\n  \\ddt{P(x, t)} = - {\\partial J(x, t) \\over \\partial x},\n\\end{equation}\nwhere $J(x, t)$ is the probability flux at point $x$. If we set the time\nderivative to zero there are only two options (in reality there is only one\noption for 1D systems):\n\\begin{enumerate}\n  \\item ${\\partial J \\over \\partial x} = 0; \\; J \\neq 0 \\Rightarrow$ Steady\n  state on a rotating or non-conservative field.\n  \\item ${\\partial J \\over \\partial x} = 0; \\; J = 0 \\Rightarrow$ Equilibrium\n  distribution that satisfies detailed balance.\n\\end{enumerate}\nFor our one-locus two-alleles case the second of these cases must be true.\nWhat this implies is that at steady state the flux $J_{ss}(x)$ takes the form\n\\begin{equation}\n  J_{ss}(x) = - M(x) P_{eq}(x) + {\\partial \\over \\partial x}\n  \\left[ V(x) P_{eq}(x) \\right] = 0,\n  \\label{eq_flux_eq}\n\\end{equation}\nwhere we use $P_{eq}(x)$ to define that this is not only a steady-state\ndistribution, but an equilibrium distribution satisfying detailed balance.\n\\eref{eq_flux_eq} is a first order homogeneous ordinary differential equation.\nWe can solve it using the integration factor method. For this we define\n$G(x) \\equiv V(x)P_{eq}(x)$. Substituting this into \\eref{eq_flux_eq} gives\n\\begin{equation}\n  {- M(x) \\over V(x)} G(x) + {\\partial \\over \\partial x} G(x) = 0.\n  \\label{eq_ode_ss}\n\\end{equation}\nIn this form we define the integration factor to be\n\\begin{equation}\n  h(x) = \\exp \\left( \\int_0^x -{M(x') \\over V(x')} \\; dx' \\right).\n\\end{equation}\nNotice that we chose the limits of integration to be $[0, x]$. This is because\nthe fundamental theorem of calculus states that for any function $f(x)$ defined\nin $[a, b]$, the antiderivative $F(x)$ is defined as\n\\begin{equation}\n  F(x) = \\int_a^x f(x') \\; dx',\n\\end{equation}\nregardless of the lower limit of integration. Multiplying both sides of\n\\eref{eq_ode_ss} by the integration factor $h(x)$ results in\n\\begin{equation}\n  {- M(x) \\over V(x)} G(x)\n  \\exp \\left( \\int_0^x -{M(x') \\over V(x')} \\; dx' \\right)\n  + {\\partial \\over \\partial x} G(x)\n  \\exp \\left( \\int_0^x -{M(x') \\over V(x')} \\; dx' \\right)\n  = 0.\n  \\label{eq_ode_int_fact}\n\\end{equation}\nThe specific form of the integration factor was chosen such that we could\nrewrite \\eref{eq_ode_int_fact} as\n\\begin{equation}\n  {d \\over dx}\n  \\left[\n  \\exp \\left(\n  - \\int_0^x {M(x') \\over V(x')}\n  \\right)G(x) \\; dx'\n  \\right] = 0.\n\\end{equation}\nWritten in this form we can simply integrate both sides with respect to $x$ as\n\\begin{equation}\n  \\int_0^x {d \\over dx''}\\left[\n  \\exp \\left(\n  - \\int_0^{x''} {M(x') \\over V(x')}\n  \\right) G(x'')\\; dx'\n  \\right] =\n  \\int_0^x 0 \\; dx''\n\\end{equation}\nEvaluating these integrals results in\n\\begin{equation}\n  \\exp \\left(\n  - \\int_0^{x} {M(x') \\over V(x')}\n  \\right) G(x)\\; dx' = C,\n\\end{equation}\nwhere $C$ is an integration constant. Notice that for a specific interval\n$[a, b] \\in \\mathbb{R}$ the integral of zero is\n\\begin{equation}\n  \\int_a^b 0 dt = 0,\n\\end{equation}\nbut when we set the upper integration limit as an independent variable, what we\nare asking for is the antiderivative of zero which is a constant $C$.\nSubstituting the definition of $G(x) = V(x) P_{eq}(x)$ gives\n\\begin{equation}\n  \\exp \\left(\n  - \\int_0^x dx' \\; {M(x') \\over V(x')}\\right)\n  V(x) P_{eq}(x) = C.\n\\end{equation}\nWe can then solve for the equilibrium allele distribution $P_{eq}(x)$ obtaining\nthe result we were aiming for\n\\begin{equation}\n  P_{eq}(x) = {C \\over V(x)} \\exp \\left(\n  \\int_0^x dx' \\; {M(x) \\over V(x)}\n  \\right).\n\\end{equation}\nThis is a Boltzmann-like distribution! The analogy with statistical mechanics\nbecomes even more clear when we substitute specific functional forms for the\ndirectional term $M(x)$ and the diffusive term $V(x)$.\n\nIn the next section we will explore how to obtain the coefficients for our\nFokker-Planck equation given the Langevin dynamics that we defined in\n\\secref{sec_langevin_intro}.", "meta": {"hexsha": "df0a47e51a5da83cb9f31edd4fe90f1c886bd31b", "size": 9153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/book_draft/chapters/classic_diffusion/04_fokker_planck.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/04_fokker_planck.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/04_fokker_planck.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": 45.5373134328, "max_line_length": 79, "alphanum_fraction": 0.7263192396, "num_tokens": 2711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6244696113738624}}
{"text": "\n\\subsection{Endomorphisms as group actions}\n\nWe can view each member of the group \\(g\\) as a homomorphim on \\(s\\).\n\nWhere \\(s\\) is a vector space \\(V\\), the representation on each group member is an invertible square matrix.\n\nIf the set we use is the vector space \\(V\\), then we can represent each group element with a square matrix acting on \\(V\\).\n\nFaithful means \\(a\\ne b\\) holds for repesentation too.\n\nRepresentation theory. groups defined by \\(ab=c\\). if we can match each eleemnt to amatrix where this holds we have represented the matrix.\n\n", "meta": {"hexsha": "4149d1732961f462413c1c158d17a73f45158589", "size": 549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/04-02-action.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/04-02-action.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/04-02-action.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.2142857143, "max_line_length": 139, "alphanum_fraction": 0.7395264117, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6244696032010423}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{cubic\\_root -- cubic root, residue, and so on}\\linkedzero{cubic\\_root}\r\n%\r\n  \\subsection{c\\_root\\_p -- cubic root mod p}\\linkedone{cubic\\_root}{c\\_root\\_p}\r\n   \\func{c\\_root\\_p}{\\hiki{a}{integer},\\ \\hiki{p}{integer}}{\\out{list}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the cubic root of \\param{a} modulo prime \\param{p}. (i.e. solutions of the equation $x^3 = \\param{a} \\pmod{\\param{p}}$).\\\\\r\n   \\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   \\quad \\param{p} must be a prime integer.\\\\\r\n   This function returns the list of all cubic roots of \\param{a}.\\\\\r\n%\r\n  \\subsection{c\\_residue -- cubic residue mod p}\\linkedone{cubic\\_root}{c\\_residue}\r\n   \\func{c\\_residue}{\\hiki{a}{integer},\\ \\hiki{p}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Check whether the rational integer \\param{a} is cubic residue modulo prime \\param{p}.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad If $\\param{p}\\ |\\ \\param{a}$, then this function returns $0$,\r\n   elif \\param{a} is cubic residue modulo \\param{p}, then it returns $1$,\r\n   otherwise (i.e. cubic non-residue), it returns $-1$.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{p} must be a prime integer.\\\\\r\n%\r\n  \\subsection{c\\_symbol -- cubic residue symbol for Eisenstein-integers}\\linkedone{cubic\\_root}{c\\_symbol}\r\n   \\func{c\\_symbol}{\\hiki{a1}{integer},\\ \\hiki{a2}{integer},\\ \\hiki{b1}{integer},\\ \\hiki{b2}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the (Jacobi) cubic residue symbol of two Eisenstein-integers $\\left(\\frac{\\param{a1}+\\param{a2}\\omega}{\\param{b1}+\\param{b2}\\omega}\\right)_3$,\r\nwhere $\\omega$ is a primitive cubic root of unity.\\\\\r\n   \\spacing\r\n   % added document\r\n   If $\\param{b1}+\\param{b2}\\omega$ is a prime in $\\mathbb{Z}[\\omega]$, it shows $\\param{a1}+\\param{a2}\\omega$ is cubic residue or not.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad We assume that $\\param{b1}+\\param{b2}\\omega$ is not divisible $1-\\omega$.\\\\\r\n%\r\n  \\subsection{decomposite\\_p -- decomposition to Eisenstein-integers}\\linkedone{cubic\\_root}{decomposite\\_p}\r\n   \\func{decomposite\\_p}{\\hiki{p}{integer}}{(\\out{integer},\\ \\out{integer})}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return one of prime factors of \\param{p} in $\\mathbb{Z}[\\omega]$.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad If the output is (\\param{a},\\ \\param{b}), then $\\frac{\\param{p}}{\\param{a}+\\param{b}\\omega}$ is a prime in $\\mathbb{Z}[\\omega]$.\r\n   In other words, \\param{p} decomposes into two prime factors $\\param{a}+\\param{b}\\omega$ and $\\param{p}/(\\param{a}+\\param{b}\\omega)$ in $\\mathbb{Z}[\\omega]$.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{p} must be a prime rational integer.\r\n   We assume that $\\param{p}\\equiv 1 \\pmod 3$.\\\\\r\n%\r\n  \\subsection{cornacchia -- solve $x^2+dy^2=p$}\\linkedone{cubic\\_root}{cornacchia}\r\n   \\func{cornacchia}{\\hiki{d}{integer},\\ \\hiki{p}{integer}}{(\\out{integer},\\ \\out{integer})}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the solution of $x^2 + \\param{d}y^2 = \\param{p}$.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad This function uses Cornacchia's algorithm. See \\cite{Cohen1}.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{p} must be prime rational integer.\r\n   \\param{d} must be satisfied with the condition $0<\\param{d}<\\param{p}$.\r\n   This function returns (\\param{x},\\ \\param{y}) as one of solutions of the equation $x^2 + \\param{d} y^2 = \\param{p}$.\\\\\r\n%\r\n\\begin{ex}\r\n>>> cubic_root.c_root_p(1, 13)\r\n[1, 3, 9]\r\n>>> cubic_root.c_residue(2, 7)\r\n-1\r\n>>> cubic_root.c_symbol(3, 6, 5, 6)\r\n1\r\n>>> cubic_root.decomposite_p(19)\r\n(2, 5)\r\n>>> cubic_root.cornacchia(5, 29)\r\n(3, 2)\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": "1eb068260b3d74d36d4c4d94e6a98ea63799c2ba", "size": 3956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/cubic_root.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/cubic_root.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/cubic_root.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": 43.9555555556, "max_line_length": 162, "alphanum_fraction": 0.6385237614, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6244341342902953}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\\chapter{Asymptotic Analysis}\n\n\\epigraph{In algorithms, as in life, persistence usually pays off.}{Steven S.\\ Skiena}\n\n\\minitoc\n\n\\section{Introduction}\n\nWhat is an algorithm?\n\n\\begin{defn}[Algorithm]\n\tA recipe/description of a process that accomplishes a goal\n\\end{defn}\n\nWhy study algorithms? First, you will gain tools to \\textit{compare} algorithms. Second, studying algorithms will help you to creatively make \\textit{new} algorithms.\n\nWhy study algorithms in discrete math? Computers are discrete. Computers run programs, which are based on algorithms. Hence, algorithms must be discrete.\n\n\\section{\\(\\Oh\\), \\(\\Omega\\), and \\(\\Theta\\) Notations}\n\nOur motivation here is to describe the \\textit{growth-rate} of functions. The growth-rate class gives us key insights to what the actual function does on large inputs.\n\n\\begin{defn}[Big-Oh]\n\tAn upper-bound on the growth-rate of a function. Formally: \\[f(n) \\in \\Oh(g(n)) \\Leftrightarrow (\\exists n_0 \\in \\N, \\exists c \\in \\R^+, \\forall n \\in \\N^{\\geq n_0})[f(n) \\leq c \\cdot g(n)]\\]\n\\end{defn}\n\n\\begin{defn}[Big-Omega]\n\tA lower-bound on the growth-rate of a function. Formally: \\[f(n) \\in \\Omega(g(n)) \\Leftrightarrow (\\exists n_0 \\in \\N, \\exists c \\in \\R^+, \\forall n \\in \\N^{\\geq n_0})[f(n) \\geq c \\cdot g(n)]\\]\n\\end{defn}\n\n\\begin{defn}[Big-Theta]\n\tAn exact growth-rate of a function. Formally: \\[f(n) \\in \\Theta(g(n)) \\Leftrightarrow f(n) \\in \\Oh(g(n)) \\land f(n) \\in \\Omega(g(n))\\]\n\\end{defn}\n\nInformally, \\(f(n) \\in \\Oh(g(n))\\) just means that \\textbf{eventually} (for big enough \\(n\\)) we have that (some constant-multiple of) \\(g\\) overtakes \\(f\\).\nFor example, \\(2^n \\in \\Oh(n!)\\) since \\(2^n < n!\\) (\\(n!\\) overtakes \\(2^n\\)) for \\(n \\geq 4\\) (\\(n \\in \\N\\)).\nSo the growth-rate of \\(2^n\\) is bounded \\textit{above} by \\(n!\\).\nSimilarly, \\(n! \\in \\Omega(2^n)\\) since \\(n! > 2^n\\) for \\(n \\geq 4\\).\nSo \\(n!\\) is bounded \\textit{below} by \\(2^n\\).\nOftentimes in algorithm analysis we aim to show an algorithm has exact run-time (\\(\\Theta\\)), and we do this by showing it has both \\(\\Oh\\) and \\(\\Omega\\) run-time.\nSometimes, though, this is hard to do.\n\n\\begin{rem}\n\tYou may see \\(\\Oh,\\Omega,\\Theta\\) defined using \\(\\forall n \\in \\N^{> n_0}\\).\n\tIt does not actually matter.\n\tJust consult whichever definition your instructor uses.\n\\end{rem}\n\n\\begin{rem}\n\tYou may see \\(f(n) = \\Oh(g(n))\\) instead of \\(f(n) \\in \\Oh(g(n))\\).\n\tBoth notations represent the same thing.\n\\end{rem}\n\n\\begin{rem}\n\tWe need not use \\(n\\) for our function variable.\n\\end{rem}\n\n\\exproof{\n\tShow that \\(f(x) = x^2 + 2x - 4 = \\Oh(x^2)\\).\n}{\n\tTo show \\(\\Oh\\), it suffices to find a constant \\(c\\) and starting point \\(x_0\\).\n\tA typical way to do this is by selecting a starting point that might help us down the line.\n\tConsider \\(x_0 = 1\\).\n\tThen, \\(x \\geq x_0 = 1\\).\n\tThen \\(x \\leq x^2\\) so \\(2x \\leq 2x^2\\) (this is where our starting point choice helps us).\n\tThus \\(x^2 + 2x - 4 \\leq x^2 + 2x \\leq x^2 + 2x^2 = 3x^2\\).\n\tSo we let \\(c = 3\\) and we are done.\n}\n\n\\exproof{\n\tShow that \\(f(x) = x^2 + 2x - 4 = \\Omega(x^2)\\).\n}{\n\tWe take a similar approach as in the previous example.\n\tLet \\(x_0 = 4\\).\n\tThen \\(x \\geq x_0 = 4\\).\n\tThus \\(x \\geq 4 = \\frac{2}{1-\\frac{1}{2}}\\) so \\((1-\\frac{1}{2}x \\geq 2\\) so \\(x - \\frac{1}{2}x \\geq 2\\) thus \\(x - 2 \\geq \\frac{1}{2}x\\).\n\tSince \\(x+2 \\geq x-2\\) then \\(x+2 \\geq \\frac{1}{2}x\\).\n\tThus \\((x+2)(x-2) \\geq (\\frac{1}{2}x)^2 = \\frac{1}{4}x^2\\).\n\tSince \\((x+2)(x-2) = x^2 - 4\\) and \\(x \\geq 4 > 0\\) so \\(2x > 0\\), then \\(x^2+2x-4 \\geq x^2-4 \\geq \\frac{1}{4}x^2\\).\n\tSo we let \\(c = \\frac{1}{4}\\) and we are done.\n}\n\n\\begin{rem}\n\tWe can conclude that our \\(f(x)\\) defined above is in \\(\\Theta(x^2)\\) since it satisfies both \\(\\Oh\\) and \\(\\Omega\\).\n\tNote that the \\(c,x_0\\) used in the \\(\\Oh\\) proof need not be the same as those in the \\(\\Omega\\) proof (and vice versa).\n\tThey only need to exist.\n\\end{rem}\n\nA picture, to see what is going on.\n\n%\\pgfmathdeclarefunction{bound}{1}{%\n%\t\\pgfmathparse{#1*x^2}%\n%}\n\\begin{boxx}\n\t\\begin{center}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\tmark=none,smooth,\n\t\t\t\taxis x line=bottom, % no box around the plot, only x and y axis\n\t\t\t\taxis y line=left,\n\t\t\t\tevery fill between plot/.append style={fill=gray,fill opacity=0.1},\n\t\t\t\tsamples=50]\n\t\t\t\t\\addplot [name path=up,color=red,domain=4:6.5] {(3)*x^2} node[pos=1] (up) {};\n\t\t\t\t\\addplot [name path=lo,color=blue,domain=4:6.5] {(1/4)*x^2} node[pos=1] (lo) {};\n\t\t\t\t\\addplot [gray] fill between[of=up and lo];\n\t\t\t\t\\addplot [color=black,domain=0:6.5] {x^2+2*x-4} node[pos=1] (func) {};\n\t\t\t\t\\addplot [color=red,domain=0:6.5] {(3)*x^2} node[pos=1] (upper) {};\n\t\t\t\t\\addplot [color=blue,domain=0:6.5] {(1/4)*x^2} node[pos=1] (lower) {};\n\t\t\t\t\\node [label=135:{\\(x_0\\)},circle,fill,inner sep=1pt] at (axis cs:1,3) {};\n\t\t\t\t\\node [label=135:{\\(x_0\\)},circle,fill,inner sep=1pt] at (axis cs:4,4) {};\n\t\t\t\\end{axis}\n\t\t\t\\node [above, color=black] at (func) {\\(f(x)\\)};\n\t\t\t\\node [above, color=red] at (upper) {\\(\\Oh\\)};\n\t\t\t\\node [above, color=blue] at (lower) {\\(\\Omega\\)};\n\t\t\\end{tikzpicture}\n\t\\end{center}\n\\end{boxx}\n\nIt should be easy to see from this picture that we can make tighter bounds by changing \\(c\\).\nIf you change your \\(c\\), then your \\(x_0\\) usually will also change.\nIt should also be easy to see from this picture that for a given \\(c\\), we may be able to find better \\(x_0\\).\nIn this case, we could move our \\(\\Omega\\) \\(x_0\\) closer to 2.\nNote that our function \\(f\\) is still bounded by our \\(\\Oh\\) and \\(\\Omega\\) functions.\nAs long as \\(c,x_0\\) \\textit{exist}, we are good to go.\n\nIt might be confusing seeing these proofs, as we somewhat made everything appear out of nowhere.\nOften, we solve these proofs using scratch work, then cleaning it up for presentation.\n\n\\begin{example}\n\tFor \\(\\Omega\\), we started at the goal of \\(x^2 + 2x - 4 \\stackrel{?}{\\geq} cx^2\\).\n\tNote that \\(x^2 + 2x - 4 \\geq x^2-4 = (x+2)(x-2)\\).\n\tSince \\(x+2 > x-2\\) then if we can find \\(d > 0\\) such that \\(x-2 \\geq dx\\) then we can conclude that \\((x+2)(x-2) \\geq d^2x^2\\).\n\tThen we let \\(c = d^2\\).\n\t\n\tSo now our goal is to solve \\(x-2 \\stackrel{?}{\\geq} dx\\).\n\tRearranging yields \\(x \\stackrel{?}{\\geq} \\frac{2}{(1-d)}\\).\n\tBy letting \\(d = \\frac{1}{2}\\), then we get \\(x \\geq 4\\) and we can thus work backwards for the actual proof to find \\(c = \\frac{1}{4}\\) with \\(x_0 = 4\\).\n\\end{example}\n\n% todo -- limit definitions\n\n\\section{Analyzing Algorithms}\n\nWe can express algorithms in terms of functions. The function input is typically \\(n\\), the number of elements inputted into, or input size for, the algorithm, and the function output is typically time. Usually \\textit{time} will be the number of certain operations performed during the algorithm.\n\n\\exsol{\n\tCome up with a function \\(T(n)\\) that describes the run-time of the following algorithm. Define run-time as the number of conditional evaluations. In the following algorithm, \\(L\\) is a list of integers of length \\(n\\).\n\t\\begin{algorithmic}[1]\n\t\t\\Function{GetMax}{\\(L\\), \\(n\\)\\@}\n\t\t\t\\State \\(M \\gets -\\infty\\)\n\t\t\t\\State \\(i \\gets 0\\)\n\t\t\t\\While{\\(i < n\\)}\n\t\t\t\t\\If{\\(L[i] > M\\)}\n\t\t\t\t\t\\State \\(M \\gets L[i]\\)\n\t\t\t\t\\EndIf\n\t\t\t\t\\State \\(i \\gets i+1\\)\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return \\(M\\)\n\t\t\\EndFunction\n\t\\end{algorithmic}\n}{\n\tWe evaluate the if-statement in line 5 exactly \\(n\\) times, and we evaluate the while-loop condition exactly \\(n+1\\) times (the last time is when we break out of the loop). Thus, \\(T(n) = n + n + 1 = 2n + 1\\)\n}\n\n\\exsol{\n\tNow come up with a function \\(U(n)\\) that outputs the number of \\(\\gets\\) operations. Compare \\(T(n)\\) to \\(U(n)\\).\n}{\n\tWe have two initial stores from lines 1 and 2. Each while-loop iteration has a store command in line 8. The while-loop runs exactly \\(n\\) times, so this gives us \\(n\\) stores. Line 6 has a store command which is run \\(\\leq n\\) times. We can model this using a natural number \\(c \\leq n\\) where \\(c\\) is the number of times line 5 evaluates to true. Our function is thus \\(U(n) = n + c + 2\\)\n\t\n\tSince \\(c \\leq n\\) we have that \\(U(n) \\leq T(n)\\) for all \\(n > 1\\). Note that when \\(n = 1\\) we have \\(T(n) = 3\\) and \\(U(n) = 4\\) (since \\(c = 1\\)). In any case, we have that the growth-rates of both functions are solely dependent on \\(n\\) and are hence the same. Both functions are in \\(\\Theta(n)\\)\n}\n\n\\begin{defn}[The Loop-Heuristic]\n\t(algorithm analysis) For each nested loop in an algorithm, multiply \\(n\\) by the number of nested levels. This can be helpful in an initial analysis, however it will only take you so far.\n\\end{defn}\n\n\\begin{rem}\n\tWe state the loop-heuristic as a definition, however it can be rephrased as a provable theorem.\n\\end{rem}\n\nIt is important to think about what is going on during the algorithm instead of blindly following the loop-heuristic. We present a few related examples.\n\n\\exsol{\n\tAnalyze the following algorithm:\n\t\\begin{algorithmic}[1]\n\t\t\\Function{AnalyzeList}{\\(L\\), \\(n\\)\\@}\n\t\t\t\\State \\(M \\gets 0\\)\n\t\t\t\\For{\\(i \\gets 0\\); \\(i < n\\); \\(i \\gets i + 1\\)}\n\t\t\t\t\\State \\(k \\gets L[i]\\)\n\t\t\t\t\\For{\\(j \\gets i\\); \\(j < n\\); \\(j \\gets j + 1\\)}\n\t\t\t\t\t\\State \\(k \\gets k * L[j]\\)\n\t\t\t\t\\EndFor\n\t\t\t\t\\State \\(M \\gets M + k\\)\n\t\t\t\\EndFor\n\t\t\t\\State \\Return \\(M\\)\n\t\t\\EndFunction\n\t\\end{algorithmic}\n}{\n\tThe algorithm contains 2 nested loops, so by the loop-heuristic our run-time is \\(n^2\\). We examine further. The outer loop goes through the list \\(n\\) times. For each iteration \\(i\\), we have a loop that goes through the list \\(n - i\\) times. The actual \\textit{work} is done in the inner loop. Thus, the amount of work equals \\(1 + 2 + 3 + \\cdots + n = \\frac{n(n+1)}{2} = \\frac{1}{2}n^2 + \\frac{1}{2}n\\) by the Gaussian sum. This has a growth rate of \\(n^2\\), so we see that the loop-heuristic worked and the algorithm runs in \\(\\Oh(n^2)\\). In fact, the amount of work does not change with respect to different input ordering, so the algorithm runs in \\(\\Theta(n^2)\\)\n}\n\n\\exsol{\n\tExamine the following algorithm:\n\t\\begin{algorithmic}[1]\n\t\t\\Function{AnalyzeGraph}{\\(G = (V,E)\\)\\@}\n\t\t\t\\State \\(c \\gets 0\\)\n\t\t\t\\For{\\(v \\in V\\)}\n\t\t\t\t\\For{\\(w \\in \\text{UnvisitedNeighbors}(v)\\)}\n\t\t\t\t\t\\State Visit \\(w\\)\n\t\t\t\t\t\\State \\(c \\gets c + 1\\)\n\t\t\t\t\\EndFor\n\t\t\t\\EndFor\n\t\t\t\\State \\Return \\(c\\)\n\t\t\\EndFunction\n\t\\end{algorithmic}\n}{\n\t\\(G\\) represents a graph, where \\(V\\) is the set of vertices and \\(E\\) is the set of edges. We usually denote \\(|V| = n\\) and \\(|E| = m\\).\n\t\n\tLet us first think about what the algorithm is \\textit{doing}. We instantiate \\(c=0\\), then go through each unvisited vertex we increment \\(c\\). We consider the amount of work in the inner loop \\(\\Theta(1)\\), and we do this exactly \\(|V| = n\\) times. So our algorithm runs in \\(\\Theta(V)\\) (or \\(\\Theta(n)\\)). % todo : undirected or directed? define neighbors?\n}\n\n\\begin{rem}\n\tHow would this change had we instead iterated through the \\textit{neighbors}, instead of \\textit{unvisited neighbors}? We will come back to this % todo\n\\end{rem}\n\nOkay, so how does one determine whether an algorithm is \\textit{good}? Well, it depends on how you define \\textit{good}. Typically we define \\textit{good} as having a low run-time. Unfortunately, an algorithm's run-time can change depending on the input. Remember: when writing algorithms, you cannot predetermine the input! This heeds way to the idea of \\textit{best-case}, \\textit{worst-case}, and \\textit{average-case} analysis.\n\n\\begin{defn}[Best-case Analysis]\n\tAnalyzing an algorithm based on an optimal input that minimizes its run-time.\n\\end{defn}\n\nBest-case analysis is akin to bounding an algorithm's run-time function below, which is just determining the tightest Big-Omega bound. So, \\(\\Omega\\) essentially tells you how fast the algorithm will run in the best case.\n\n\\begin{defn}[Worst-case Analysis]\n\tAnalyzing an algorithm based on a pathological input that maximizes its run-time.\n\\end{defn}\n\nBy contrast, worst-case analysis is akin to bounding an algorithm's run-time function above, which is just determining the tightest Big-Oh bound. So, \\(\\Oh\\) essentially tells you how fast the algorithm will run in the worst case.\n\n\\begin{defn}[Average-case Analysis]\n\tAnalyzing an algorithm's run-time based on typical, expected, input.\n\\end{defn}\n\n\\begin{rem}\n\tYou may be tempted to think that, as the analogy would imply, average-case analysis is akin to \\(\\Theta\\). This is not true. \\(\\Theta\\) tells you the \\textit{exact} run-time, which is when \\(\\Oh\\) and \\(\\Omega\\) agree. If you know your algorithm run-time has a \\(\\Theta\\) bound, then the average-case analysis will be this bound. The converse is not true though. If you have the average-case bound, this does not necessarily mean the worst-case or best-case is the same. An important example of this is the Quicksort algorithm.\n\\end{rem}\n\nWe present a pathological example to explain why these different analysis types are important.\n\n\\exsol{\n\tExamine the following algorithm:\n\t\\begin{algorithmic}[1]\n\t\t\\Function{Pathological}{\\(L\\), \\(n\\)\\@}\n\t\t\\If{\\(n \\equiv 0 \\Mod{2}\\)}\n\t\t\t\\State \n\t\t\\Else\n\t\t\t\\State \\Return \\(L[0]\\)\n\t\t\\EndIf\n\t\t\\State \\(c \\gets 0\\)\n\t\t\\For{\\(v \\in V\\)}\n\t\t\\For{\\(w \\in \\text{UnvisitedNeighbors}(v)\\)}\n\t\t\\State Visit \\(w\\)\n\t\t\\State \\(c \\gets c + 1\\)\n\t\t\\EndFor\n\t\t\\EndFor\n\t\t\\State \\Return \\(c\\)\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t% todo function that takes exponential on if-branch, and constant on else\n}{\n\t\n}\n\n% maybe another that is less pathological\n\n\\subsection{Solving Summations}\n\n% todo\n\n% we did a similar thing during the number theory chapter.\n% i guess make it more explicit here? idk\n% we use the sum of c, i and i^2 here\n\n% recall addition is linear, so blah blah blah\n\n\\subsection{Solving Recurrences}\n\n% todo\n\n% tree table descending example\n\n\\begin{thm}[The Master Theorem]\n\t% todo\n\\end{thm}\n\nProof omitted.\n\n% another example, but use master thm\n\n\\section{Common Complexities}\n\nThere are a handful of common run-time complexities that you should be familiar with. In this book, we give them to you in ascending order of growth rate in Big Theta notation.\n\n\\begin{defn}[Constant]\n\t\\[\\Theta(1)\\]\n\\end{defn}\n\n\\begin{defn}[Logarithmic]\n\t\\[\\Theta(\\log n)\\]\n\\end{defn}\n\n\\begin{defn}[Linear]\n\t\\[\\Theta(n)\\]\n\\end{defn}\n\n\\begin{defn}[Polynomial]\n\t\\[\\Theta(n^c),\\ c > 1\\]\n\tWe call \\(\\Theta(n^2)\\) Quadratic\n\\end{defn}\n\n\\begin{defn}[Exponential]\n\t\\[\\Theta(c^n),\\ c > 1\\]\n\\end{defn}\n\n\\section{P vs NP}\n\nThere exist many YouTube videos discussing the famous P vs.\\ NP problem (\\href{https://www.youtube.com/watch?v=EHp4FPyajKQ}{ex 1}, \\href{https://www.youtube.com/watch?v=YX40hbAHx3s}{ex 2}). Moreover, if you solve it, the Clay Mathematics Institute has \\href{https://www.claymath.org/millennium-problems/p-vs-np-problem}{\\$1,000,000} waiting for you. So what is it?\n\n\\begin{defn}[P]\n\tThe class of computational problems that can be solved in \\textbf{P}olynomial time.\n\\end{defn}\n\n\\begin{defn}[NP]\n\tThe class of computational problems where a given solution can be \\textit{verified} in polynomial time.\n\\end{defn}\n\n\\begin{rem}\n\tNP stands for \\textit{Nondeterministic Polynomial}. It does \\textbf{not} stand for \\textit{non-polynomial} as some people think.\n\\end{rem}\n\n\n\n\\begin{defn}[Reductions]\n\t\n\\end{defn}\n\n\\begin{defn}[NP-Complete]\n\tA computational problem is NP-Complete if it satisfies two conditions:\n\t\\begin{enumerate}\n\t\t\\item The problem is in NP\n\t\t\\item Every problem in NP is reducible to it in polynomial time\n\t\\end{enumerate}\n\\end{defn}\n\n\\begin{rem}\n\tProblems that satisfy the second condition above, and not necessarily the first, are called \\textbf{NP-Hard}.\n\\end{rem}\n\nThe second condition is tricky.\nAs of now, the set of NP-Complete problems is empty.\nSo we need some form of \\textit{starter problem} to which all reductions can be made.\n\n\\begin{thm}[The Cook-Levin Theorem]\n\tThe Boolean satisfiability problem is NP-Complete.\n\\end{thm}\n\n\\begin{rem}\n\tWhile at this point in the course you likely can understand the proof, we omit it for scope.\n\\end{rem}\n\nWe leave this discussion with one final remark.\n\\(\\text{P}=\\text{NP}\\) will render most (all) cryptographic algorithms and services broken.\nThis is because most modern cryptography is built on the observation that factoring very large primes is \\textit{hard}.\nIf you are interested, look into RSA and/or the Diffie-Hellman key exchange.\n\n\\section{The Halting Problem}\n\nInfinite loops are a software developer's worst nightmare. They are hard to find, debug, and (sometimes) fix. If only there were a piece of software that could examine your code and tell you whether there are any infinite loops. More abstractly, if it could tell you whether your program continues forever or eventually stops.\n\nWell, we are sorry to break the news to you, but this piece of software can never exist; sort-of.\n\nThe halting problem is most commonly used as an introduction to computability theory. What problems can we compute? What does it even mean to be computable? These questions are out of scope of this book, but if the following problem interests you, consider taking a course on theory of computation.\n\n\\begin{defn}[The Halting Problem]\n\tA computational problem of determining whether an arbitrary computer program, with input, will stop or run forever.\n\\end{defn}\n\nThink to yourself whether you can come up with a solution program. It is a difficult problem. Alan Turing proved in 1936 that no such algorithm could exist \\textit{for all} pairs of programs and inputs. This proof led to (created) the Turing machine, and arguably all of modern computer science. The proof sketch follows. We call it a sketch because the actual proof is significantly more in-depth.\n\n\\begin{proof}\n\tAssume that such an algorithm (code description, function, method, whatever you want to call it) \\(h\\) exists. The function \\(h : P \\times I \\rightarrow \\mathbb{B}\\) given by \\(h : (p,i) \\mapsto b\\) tells us whether a given input program \\(p \\in P\\) (the set of all programs) with input \\(i \\in I\\) (the set of all program inputs) will halt (stop) or not: \\(b \\in \\mathbb{B} = \\{\\text{True}, \\text{False}\\}\\).\n\t\n\tThen the following procedure \\(\\textsc{g} \\in P\\):\n\t\\begin{algorithmic}[1]\n\t\t\\Function{g}{\\(\\cdot\\)\\@}\n\t\t\t\\If{\\(h(\\textsc{g},\\cdot)\\)}\n\t\t\t\t\\While{True}\n\t\t\t\t\\Comment{loop forever}\n\t\t\t\t\\EndWhile\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\tWe have two cases: \\(h(\\textsc{g},\\cdot)\\) returns True, or \\(h(\\textsc{g},\\cdot)\\) returns False.\n\t\n\tCase 1: \\(h(\\textsc{g},\\cdot) = \\text{True}\\). Then \\textsc{g} stops. But since \\(h\\) returned True, the body of the if-statement will be executed. Then \\textsc{g} will loop forever. But this contradicts the output of \\(h\\).\n\t\n\tCase 2: \\(h(\\textsc{g},\\cdot) = \\text{False}\\). Then \\textsc{g} does not stop. But since \\(h\\) returned False, the body of the if-statement is \\textit{not} executed, so \\textsc{g} will stop. But this contradicts the output of \\(h\\).\n\t\n\tThus, the halting problem is undecidable (impossible to answer for all inputs).\n\\end{proof}\n\n% todo\n\n\\section{Summary}\n\n\\begin{itemize}\n\t\\item \n\t\\item \n\t\\item \n\\end{itemize}\n\n\\section{Practice}\n\n\\begin{enumerate}\n\t\\item Analyze the following algorithm:\n\t\\begin{algorithmic}[1]\n\t\t\\Function{SomeFunc}{\\(n\\)\\@}\n\t\t\t\\State something\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\\item Order the following complexities: \\(\\Theta(n \\log n)\\), \\(\\Theta(n \\log (n^2))\\), \\(\\Theta(n)\\), \\(\\Theta(n^2)\\). Explain why your ordering is correct.\n\t\\item Order the following complexities: \\(\\Theta(\\log (3n))\\), \\(\\Theta(n^n)\\), \\(\\Theta(n!)\\), \\(\\Theta(\\log (\\log n))\\).\n\\end{enumerate}\n\n%\\section{Solutions}\n%\n%\\begin{enumerate}\n%\t\\item \n%\t\\item Since \\(n \\log (n^2) = 2n \\log n\\) we have that \\(n \\log (n^2) \\in \\Theta(n \\log n)\\). So the growth-rate of those two functions are the same. It suffices to order \\(\\Theta(n \\log n)\\), \\(\\Theta(n)\\), \\(\\Theta(n^2)\\). We know \\(n \\in \\Oh(n^2)\\). It should be clear that \\(n \\in \\Oh(n \\log n)\\) (consider \\(1 < \\log_b n \\Rightarrow n < n \\log_b n\\) for all \\(n > b\\)). Similar logic can be applied to show that \\(n \\log n \\in \\Oh(n^2)\\). Thus our ordering is \\(n < n \\log n < n \\log (n^2) < n^2\\) where \\(a <b \\) is shorthand for \\(a \\in \\Oh(b)\\)\n%\t\\item \\(\\log \\log n < \\log (3n) < n! < n^n\\) where \\(a <b \\) is shorthand for \\(a \\in \\Oh(b)\\)\n%\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "a5690fe28acca7a548af1a7d9d44c4df75c6d154", "size": 20176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch-asympt.tex", "max_stars_repo_name": "jugoodma/250-textbook", "max_stars_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-22T03:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T14:39:11.000Z", "max_issues_repo_path": "ch-asympt.tex", "max_issues_repo_name": "jugoodma/250-textbook", "max_issues_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "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": "ch-asympt.tex", "max_forks_repo_name": "jugoodma/250-textbook", "max_forks_repo_head_hexsha": "ebfcd8e9d15079fe8924bf562a194ed057aed302", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-19T22:24:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-19T22:24:49.000Z", "avg_line_length": 45.2376681614, "max_line_length": 670, "alphanum_fraction": 0.6760507534, "num_tokens": 6485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.6243340421981081}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{pgf}\n\\usepackage{tikz}\n\\usepackage{kbordermatrix}\n\\usetikzlibrary{arrows,automata, shapes, petri}\n\\usepackage{placeins}\n\\usepackage{multirow}\n\\usepackage{booktabs}\n\n\\begin{document}\n\n\\title{HIDDEN MARKOV MODELS}\n\\date{}\n\\maketitle\n\nHidden Markov Models(HMMs) are statistical tools to model sequential observations with the assumption that states of the system generating them follow a Markov process but these states are unobservable/hidden. However, an observation at any point is related to the underlying hidden state the system is in at that point.\n\n\\section{Example}\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[initial,state] (I)                    {$$};\n\t\t\\node[state]         (S) [below left of=I] {$S$};\n\t\t\\node[state]         (T) [below right of=I] {$T$};\n\t\t\\node[rectangle]         (SX) [below left of=S,yshift=-1.2cm,xshift=1cm]     {$X$};\n\t\t\\node[rectangle]         (SY) [below of=S]     {$Y$};  \n\t\t\\node[rectangle]         (SZ) [below right of=S,yshift=-1.2cm,xshift=-1cm]     {$Z$};\n\t\t\\node[rectangle]         (TX) [below left of=T,yshift=-1.2cm,xshift=1cm]     {$X$};\n\t\t\\node[rectangle]         (TY) [below of=T]     {$Y$};  \n\t\t\\node[rectangle]         (TZ) [below right of=T,yshift=-1.2cm,xshift=-1cm]     {$Z$};  \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\path (I) edge [bend right]    node {0.6} (S)\n\t\tedge [bend left]     node {0.4} (T)\n\t\t(S) edge [loop left]    node {0.7} (S)\n\t\tedge [bend left]    node {0.3} (T)\n\t\tedge                node {0.1} (SX)\n\t\tedge                node {0.4} (SY)\n\t\tedge                node {0.5} (SZ)\n\t\t(T) edge [loop right]   node {0.6} (T)\n\t\tedge [bend left]    node {0.4} (S)\n\t\tedge                node {0.7} (TX)\n\t\tedge                node {0.2} (TY)\n\t\tedge                node {0.1} (TZ);   \n\t\t\\draw [to-to] (-7,-7) -- (7,-7); \n\t\t\\node at (0, -6.5) {Hidden};\n\t\t\\node at (0, -7.5) {Observable};                   \n\t\\end{tikzpicture}\n\\end{center}\n\nIn this diagram, nodes $\\{S, T\\}$ represent the hidden states and $\\{X, Y, Z\\}$ represent observable states. The unlabelled node is the start node. These states together with the associated probabilities fully characterize the HMM. The state transition probabilites denoted by $A$ can be represented as,\n\n\\[\n\tA = \\kbordermatrix{\n\t\t& S & T \\\\\n\t\tS & 0.7 & 0.3 \\\\\n\t\tT & 0.6 & 0.4 \\\\\n\t}\n\\]\n\nThe emmission probabilities are denoted by $B$.\n\n\\[\n\tB = \\kbordermatrix{\n\t\t& X & Y & Z \\\\\n\t\tS & 0.1 & 0.4 & 0.5 \\\\\n\t\tT & 0.7 & 0.2 & 0.1 \\\\\n\t}\n\\]\n\nLastly, initial state distribution is denoted by $\\pi$.\n\n\\[\n\t\\pi = \\kbordermatrix{\n\t\t& S & T \\\\\n\t\t& 0.6 & 0.4  \n\t}\n\\]\n\n\\section{The three problems of HMM}\n\n\\subsection{The Evaluation Problem}\n\nGiven a HMM, $\\lambda=(A, B, \\pi)$ and a set of observations $O$, find $P(O|\\lambda)$ (probability that the observations were generated by the model).\n\nConsider the HMM in the example above and let $O = (ZXY)$.\n\n\\begin{align*}\n\tP(ZXY|\\lambda) & = P(SSS, ZXY|\\lambda)  \\\\\n\t               & +\\ P(SST, ZXY|\\lambda) \\\\\n\t               & +\\ P(STS, ZXY|\\lambda) \\\\\n\t               & +\\ P(STT, ZXY|\\lambda) \\\\\n\t               & +\\ P(TSS, ZXY|\\lambda) \\\\\n\t               & +\\ P(TST, ZXY|\\lambda) \\\\\n\t               & +\\ P(TTS, ZXY|\\lambda) \\\\\n\t               & +\\ P(TTT, ZXY|\\lambda) \\\\  \n\\end{align*}\n\nEach of the terms on R.H.S. can be calculated using the following law of probability.\n\n\\begin{align*}\n\tP(a, b|c) & = \\frac{P(a, b, c) }{P(c)}                            \\\\ \n\t          & = \\frac{P(a, c) }{P(c)} * \\frac{P(a, b, c) }{P(a, c)} \\\\\n\t          & = P(a|c) * P(b|a,c)                                   \n\\end{align*} \n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{$P(ZXY|\\lambda)$ calculation}\n\t\\label{tab:table1}\n\t\\begin{tabular}{cccc|c}\n\t\t\\toprule\n\t\tHS  & OS  & $P(HS|\\lambda)$   & $P(OS|HS, \\lambda)$ & $P(HS, OS|\\lambda)$ \\\\\n\t\t\\midrule\n\t\tSSS & ZXY & 0.6*0.7*0.7=0.294 & 0.5*0.1*0.4=0.020   & 0.005880            \\\\\n\t\tSST & ZXY & 0.6*0.7*0.3=0.126 & 0.5*0.1*0.2=0.010   & 0.001260            \\\\\n\t\tSTS & ZXY & 0.6*0.3*0.4=0.072 & 0.5*0.7*0.4=0.140   & 0.010080            \\\\\n\t\tSTT & ZXY & 0.6*0.3*0.6=0.108 & 0.5*0.7*0.2=0.070   & 0.007560            \\\\\n\t\tTSS & ZXY & 0.4*0.4*0.7=0.112 & 0.1*0.1*0.4=0.004   & 0.000448            \\\\\n\t\tTST & ZXY & 0.4*0.4*0.3=0.048 & 0.1*0.1*0.2=0.002   & 0.000096            \\\\\n\t\tTTS & ZXY & 0.4*0.6*0.4=0.096 & 0.1*0.7*0.4=0.028   & 0.002688            \\\\\n\t\tTTT & ZXY & 0.4*0.6*0.6=0.144 & 0.1*0.7*0.2=0.014   & 0.002016            \\\\\n\t\t\\midrule\n\t\t    &     &                   & $P(ZXY|\\lambda)$    & 0.030028            \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\nCalculation in this manner is expensive because probabilities corresponding to all permutations of hidden states of the same length as the length of observed sequence have to be calculated. \n\nTo visualize the above calculation, consider the following diagrammatic represntation.\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (Start)                    {$Start$};\n\t\t\\node[state] (S1) [above right of=Start] {$S$};\n\t\t\\node[state] (T1) [below right of=Start] {$T$};\n\t\t\\node[state] (S2) [right of=S1] {$S$};\n\t\t\\node[state] (T2) [right of=T1] {$T$};\n\t\t\\node[state] (S3) [right of=S2] {$S$};\n\t\t\\node[state] (T3) [right of=T2] {$T$};\n\t\t\\node[state] (End) [below right of=S3] {$End$};\n\t\t\\node [rectangle, node distance=2cm] (Z) [above of=S1] {Z};\n\t\t\\node [rectangle, node distance=2cm] (X) [above of=S2] {X};\n\t\t\\node [rectangle, node distance=2cm] (Y) [above of=S3] {Y};\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t                \n\t\t\\path (Start) edge  node {0.6} (S1)\n\t\tedge  node {0.4} (T1)\n\t\t(S1) edge  node {0.5*0.7} (S2)\n\t\tedge  node [pos=0.2] {0.5*0.3} (T2)\n\t\t(T1) edge  node [pos=0.2] {0.1*0.4} (S2)\n\t\tedge  node {0.1*0.6} (T2)\n\t\t(S2) edge  node {0.1*0.7} (S3)\n\t\tedge node [pos=0.2] {0.1*0.3} (T3)\n\t\t(T2) edge node [pos=0.2] {0.7*0.4} (S3)\n\t\tedge node {0.7*0.6} (T3)\n\t\t(S3) edge node {0.4} (End)\n\t\t(T3) edge node {0.2} (End);                     \n\t\\end{tikzpicture}\n\\end{center}\n\nThe arrow from $S$ under $Z$ and $S$ under $X$ is labelled 0.5*0.7 as probability of emitting $Z$ given $S$ is 0.5 and probability of transition from $S$ to $S$ is 0.7. The arrow from $Start$ to $S$ is labelled 0.6 as initial probability of transitioning to $S$ is 0.6. Similarly, the arrow from $S$ to End is labelled 0.4 as probability of emitting $Y$ given $S$ is 0.4.\n\nEvery path in the diagram from $Start$ to $End$ has a special meaning in the sense that the multiplication of all labels on the path (which henceforth shall be called its value) is equal to the joint probability of the observation sequence and the hidden state transition sequence defined by the path given the model.\n\nThe diagram also leads to the fact that $P(ZXY|\\lambda)$ can be thought of as arising out of the enumeration of all paths from $Start$ to $End$ and then summation over their value. \n\nDynamic Programming can be used to circumvent enumeration and speed up the computation as shown below,\n\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (Start)                    {$1$};\n\t\t\\node[state] (S1) [above right of=Start] {$0.6$};\n\t\t\\node[rectangle, node distance=2cm] (D1) [right of=S1] {$=1*0.6$};\n\t\t\\node[state] (T1) [below right of=Start] {$0.4$};\n\t\t\\node[rectangle, node distance=2cm] (D2) [right of=T1] {$=1*0.4$};\t\t \n\t\t\\path (Start) edge  node {0.6} (S1)\n\t\tedge  node {0.4} (T1);                     \n\t\\end{tikzpicture}\n\\end{center}\n\n\\noindent\\rule{\\textwidth}{0.6pt}\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (S1) {$0.6$};\n\t\t\\node[state] (T1) [below of=S1] {$0.4$};\n\t\t\\node[state] (S2) [right of=S1] {$0.226$};\n\t\t\\node[rectangle, node distance=4cm] (D2) [right of=S2] {$=0.6*0.5*0.7 + 0.4*0.1*0.4$};\t\n\t\t\\node[state] (T2) [right of=T1] {$0.114$};\n\t\t\\node[rectangle, node distance=4cm] (D2) [right of=T2] {$=0.6*0.5*0.3 + 0.4*0.1*0.6$};\t\t\t\t\n\t\t\t\t\t\t\t                \n\t\t\\path \n\t\t(S1) edge  node {0.5*0.7} (S2)\n\t\tedge  node [pos=0.2] {0.5*0.3} (T2)\n\t\t(T1) edge  node [pos=0.2] {0.1*0.4} (S2)\n\t\tedge  node {0.1*0.6} (T2);\t\t\n\t\\end{tikzpicture}\n\\end{center}\n\n\\noindent\\rule{\\textwidth}{0.6pt}\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (S2) {$0.226$};\n\t\t\\node[state] (T2) [below of=S2] {$0.114$};\n\t\t\\node[state] (S3) [right of=S2] {$0.04774$};\n\t\t\\node[rectangle, node distance=4cm] (D3) [right of=S3] {$=0.226*0.1*0.7 + 0.114*0.7*0.4$};\n\t\t\\node[state] (T3) [right of=T2] {$0.05466$};\n\t\t\\node[rectangle, node distance=4cm] (D3) [right of=T3] {$=0.226*0.1*0.3 + 0.114*0.7*0.6$};\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t                \n\t\t\\path \n\t\t(S2) edge  node {0.1*0.7} (S3)\n\t\tedge node [pos=0.2] {0.1*0.3} (T3)\n\t\t(T2) edge node [pos=0.2] {0.7*0.4} (S3)\n\t\tedge node {0.7*0.6} (T3);                     \n\t\\end{tikzpicture}\n\\end{center}\n\n\\noindent\\rule{\\textwidth}{0.6pt}\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (S3) {$0.04774$};\n\t\t\\node[state] (T3) [below of=S3] {$0.05466$};\n\t\t\\node[state] (End) [above right of=T3] {$0.030028$};\n\t\t\\node[rectangle, node distance=4cm] (D4) [right of=End] {$=0.04774*0.4 + 0.05466*0.2$};\t\t\t\t                \n\t\t\\path \n\t\t(S3) edge node {0.4} (End)\n\t\t(T3) edge node {0.2} (End);                     \n\t\\end{tikzpicture}\n\\end{center}\n\nIn this algorithm, each node on the right keeps track of sum of values of all paths from $Start$ to that node denoted by $\\alpha_t(state)$.\n\n\\begin{table}[h!]\n\t\\centering\n\t\\begin{tabular}{c|c|c|c}\n\t\t\\toprule\n\t\t              & $t=1$ & $t=2$ & $t=3$   \\\\\n\t\t\\midrule\n\t\t$\\alpha_t(S)$ & 0.6   & 0.226 & 0.04774 \\\\\n\t\t$\\alpha_t(T)$ & 0.4   & 0.114 & 0.05466 \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\nThe same algorithm can be run backwards from the $End$ node and work its way towards the $Start$ node. Now, each node in the left will keep track of sum of values of all paths from $End$ to that node denoted by $\\beta_t(state)$.\n\n\\begin{table}[h!]\n\t\\centering\n\t\\begin{tabular}{c|c|c|c}\n\t\t\\toprule\n\t\t             & $t=1$   & $t=2$ & $t=3$ \\\\\n\t\t\\midrule\n\t\t$\\beta_t(S)$ & 0.0413  & 0.034 & 0.4   \\\\\n\t\t$\\beta_t(T)$ & 0.01312 & 0.196 & 0.2   \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\nIt is apparent that the following relation must hold,\n\n\\begin{align*}\n\t\\sum_{\\text{all states}} \\alpha_t(state)*\\beta_t(state) = 0.030028\\  \\forall\\ t \n\\end{align*}\n \n\\subsection{The Decoding Problem}\n\nGiven a HMM, $\\lambda = (A, B, \\pi)$ and a set of observations $O$, find the most likely sequence of hidden states that led the model to emit $O\n$. The solution to this is straightforward. At each time step, the state corrresponding to maximum value of $\\alpha_t(state)*\\beta_t(state)$ is chosen.\n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{Decoding solution}\n\t\\label{tab:table2}\n\t\\begin{tabular}{c|c|c|c}\n\t\t\\toprule\n\t\t             & $t=1$       & $t=2$       & $t=3$       \\\\\n\t\t\\midrule\n\t\tS            & 0.6*0.0413  & 0.226*0.034 & 0.04774*0.4 \\\\\n\t\tT            & 0.4*0.01312 & 0.114*0.196 & 0.05466*0.2 \\\\\n\t\t\\midrule\n\t\tChosen State & S           & T           & S           \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\subsection{The Learning Problem}\n\nIf only the observation sequence $O$ were given, how can one estimate $\\lambda$? Make a good guess of the number of hidden states and follow:\n\n\\begin{enumerate}\n\t\\item Non uniformly initialize a model $\\lambda = (A, B, \\pi)$.\n\t\\item Compute $\\alpha_t(state)$ and $\\beta_t(state)$ for all times and states using the solution to Problem 1.\n\t\\item Re-estimate the model $\\lambda$.\n\t\\item Go to step 2 if $P(O|\\lambda)$ increases reasonably or if out of iterations. \n\\end{enumerate}\n\nThe only question that remains is: How to re-estimate $\\lambda$?\n\n\\begin{center}\n\t\\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,\n\t\tsemithick]\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\node[state] (S1) {$S$};\n\t\t\\node[] (O1) [above of=S1, node distance=1cm]{$O_t$};\n\t\t\\node[state] (T1) [below of=S1] {$T$};\t\n\t\t\\node[state] (S2) [right of=S1] {$S$};\t\n\t\t\\node[] (O2) [above of=S2, node distance=1cm]{$O_{t+1}$};\t\t\n\t\t\\node[state] (T2) [right of=T1] {$T$};\t\t\t\t\n\t\t\t\t\t\t\t                \n\t\t\\path \n\t\t(S1) edge  node {1} (S2)\n\t\tedge  node [pos=0.2] {2} (T2)\n\t\t(T1) edge  node [pos=0.2] {} (S2)\n\t\tedge  node {} (T2);\t\t\n\t\\end{tikzpicture}\n\\end{center}\n\nRemember that $P(O|\\lambda)$ is the sum of values if all paths from $Start$ to $End$. A fraction of $P(O|\\lambda)$ comes from the sum of values of all paths that contain transtion $(state_t =S \\rightarrow state_{t+1}=S)$ labelled by $1$ in the above figure. Denote it by $\\gamma_t(S \\rightarrow S)$.\n\nA yet another fraction comes from the sum of values of all paths that contain transtion $(state_t =S \\rightarrow state_{t+1}=T)$ labelled by $2$ denoted by $\\gamma_t(S \\rightarrow T)$. Also let, \n\\begin{align*}\n\t\\gamma_t(S) = \\gamma_t(S \\rightarrow S) + \\gamma_t(S \\rightarrow T) \n\\end{align*}\n\nIs $\\frac{\\gamma_t(S \\rightarrow S)}{\\gamma_t(S)}$ a good estimate of $A(S \\rightarrow S)$? Kind of. But remember that only one time $t$ is considered. A better estimate would be,\n\n\\begin{align*}\n\tA(S \\rightarrow S) \\approx \\frac{\\sum_t \\gamma_t(S \\rightarrow S)}{\\sum_t \\gamma_t(S)} \n\\end{align*} \n\nSimilarly, $B(S \\rightarrow OS)$ is estimated by,\n\n\\begin{align*}\n\tB(S \\rightarrow OS) \\approx \\frac{\\sum_{t|O_t = OS} \\gamma_t(S)}{\\sum_t \\gamma_t(S)} \n\\end{align*} \n\nThis completes the discussion of the solution to the learning problem in HMMs.\n\n\\section{Applications}\n\nHMMs are widely used in speech recognition, hand writing recognition, part of speech tagging, DNA sequence analysis etc. Wherever there is sequential aspect to data and the data can be thought of as arising out of an underlying simpler hidden probabilistic process, HMMs may be suited for application.  \n\n\\end{document}\n", "meta": {"hexsha": "ff991a75a56731b8c27cf4f34277cf323ce82d02", "size": 13983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Hidden Markov Models/Hidden Markov Models.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": "Hidden Markov Models/Hidden Markov Models.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": "Hidden Markov Models/Hidden Markov Models.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": 38.6270718232, "max_line_length": 371, "alphanum_fraction": 0.5915039691, "num_tokens": 5253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6243068850322873}}
{"text": "%auto-ignore\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\n\\begin{document}\n\n\\section{Gradings, degree shifts and completions\n%for the \\texorpdfstring{$\\IBLInfty$-theory}{IBL-infinity-theory}\n}\n\\allowdisplaybreaks\n\\label{Sec:Alg1a}\n\nWe will work with vector spaces over $\\R$, possibly infinite-dimensional, graded by the \\emph{degree} $d\\in \\Z$ and the \\emph{weight} $k\\in \\N_0$.\n\n\\begin{Definition}[Weight-graded vector spaces]\\label{Def:Grading}\nA \\emph{graded vector space} is a vector space~$W$ together with a collection  of subspaces $W^d \\subset W$ for all $d\\in \\Z$ such that\n\\[ W=\\bigoplus_{d\\in \\Z} W^d. \\]\nElements of $W^d$ are called \\emph{homogenous} of degree $d$; given $w\\in W^d$, we denote the degree of $w$ by $\\Abs{w} \\coloneqq d$. \n\nA linear map of graded vector spaces $f: W_1 \\rightarrow W_2$ is called homogenous of degree $\\Abs{f} \\in \\Z$ if it holds \n\\begin{equation}\\label{Eq:StdGrading}\nf(W_1^d)\\subset W_2^{d+\\Abs{f}}\\quad\\text{for all }d\\in \\Z.\n\\end{equation}\n\nA \\emph{weight-graded vector space} is a graded vector space $W$ together with a collection of subspaces $W_k^d \\subset W^d$ for all $k\\in \\N_0$ and $d\\in \\Z$ such that\n\\[ W^d=\\bigoplus_{k\\in\\N_0} W_k^d\\quad\\text{for all }d\\in \\Z. \\]\nWe define the \\emph{weight-$k$ component} of $W$ by\n\\[ W_k \\coloneqq \\bigoplus_{d\\in \\Z} W_k^d\\quad\\text{for all }k\\in \\N_0. \\]\nIf $W_0^d = 0$ for all $d\\in \\Z$, we say that $W$ is \\emph{weight-reduced.} We define the \\emph{weight-reduced subspace} $\\widebar{W}$ of a weight-graded vector space $W$ by\n\\[ \\widebar{W} \\coloneqq \\bigoplus_{d\\in \\Z} \\bigoplus_{k\\in\\N} W_k^d. \\] \n\n\nThe superscript $\\,{}^*$ usually denotes the dual in the category we work in, e.g., chain complexes. For a (weight-)graded vector space $W$, we also introduce the following notation to avoid confusion:%\\footnote{This notation is applied only when it is clear that our main focus lies on the way a multi-graded vector space is dualized. Otherwise, ${}^*$ denotes the dualization in whichever category we currently work with and~${}'$ labels objects of the same type.}\n\\begin{equation}\\label{Eq:Duals}\\begin{aligned}\nW^{\\LD} \\coloneqq \\{\\psi: W \\rightarrow \\R \\text{ linear}\\} &\\;\\,\\dots&& \\text{\\emph{linear dual,}}\\\\[2\\jot]\nW^{\\GD}  \\coloneqq \\bigoplus_{d\\in  \\Z} \\prod_{k\\in \\N_0} W_{k}^{d*} &\\;\\,\\dots&& \\text{\\emph{graded dual,}}\\\\\nW^{\\WGD} \\coloneqq \\bigoplus_{d\\in \\Z} \\bigoplus_{k\\in \\N_0} W_k^{d*} &\\;\\,\\dots&& \\text{\\emph{weight-graded dual.}}\n\\end{aligned}\n\\end{equation}\nHere, $W^{\\LD}$ is a vector space, $W^{\\GD}$ a graded vector space and $W^{\\WGD}$ a weight-graded vector space. The grading convention from \\eqref{Eq:Duals} is the \\emph{cohomological grading convention}, which differs from the convention \\eqref{Eq:StdGrading} for maps $f: W \\rightarrow \\R$ by degree reversal (for this, see Definition~\\ref{Def:DegreeShift}).\n\nWe identify $W^{\\GD}$ with the subspace of $W^{\\LD}$ generated by homogenous maps and~$W^{\\WGD}$ with the subspace of $W^{\\LD}$ generated by maps which are non-zero only on finitely many~$W_k^d$; hence, under this identification, we have the tower of inclusions \n\\[ W^{\\WGD} \\subset W^{\\GD} \\subset W^{\\LD}.\\]\n\\end{Definition}\n\n% Pick a forgetful functor from the category of weight-graded to the category of graded. And a functor back by embedding graded vector spaces into weight graded.\n\n\\begin{Definition}[Koszul sign] \\label{Def:Koszul}\nLet $k\\ge 1$, and let $\\sigma\\in \\Perm_k$ be a permutation on~$k$ elements, i.e., a bijection of the set $\\{1,\\dotsc,k\\}$. For $i=1$, $\\dotsc$, $k$,  let $a_i$ and $b_i$ be graded symbols of degrees~$\\Abs{a_i}$ and~$\\Abs{b_i}$, respectively. We denote by \n\\[\\varepsilon(\\sigma,a) \\quad\\text{and}\\quad\\varepsilon(a,b)\\]\nthe \\emph{Koszul signs} of the transformations\n \\[ a_1 \\dots a_k \\longmapsto a_{\\sigma_1^{-1}} \\dots a_{\\sigma_k^{-1}} \\quad \\text{and} \\quad a_1 \\dots a_k b_1 \\dots b_k \\longmapsto a_1 b_1 \\dots a_k b_k, \\]\nrespectively. Here $\\sigma_i^{-1} \\coloneqq \\sigma^{-1}(i)$. The Koszul sign is computed by permuting the left-hand side to the right-hand side via transpositions of two adjacent elements such that whenever we transpose two graded symbols, e.g., $a_i \\longleftrightarrow a_{j}$, we multiply with $(-1)^{\\Abs{a_i}\\Abs{a_{j}}}$.\n\\end{Definition}\n\nWe emphasize that the Koszul sign depends only on the initial and the final order of the graded symbols and not on the sequence of transpositions; this is easy to show.\n\n\n%We have\n%\\[\\begin{aligned} \n%W^{\\WGD} = W^{\\GD} &\\Equiv \\forall d\\in \\Z\\ \\exists I\\subset \\N_0, \\Abs{I}<0\\ \\forall k\\in \\N_0 \\backslash I:  W_k^d = 0, \\\\\n%W^{\\GD} = W^* &\\Equiv \\exists I \\subset \\Z, J \\subset \\N_0, \\Abs{I}, \\Abs{J}<\\infty\\ \\forall (d,k)\\in \\Z\\times \\N_0 \\backslash I\\times J: W_k^d=0.\n%\\end{aligned}\\]\n%In particular, $W^* = W^{\\GD} = W^{\\WGD}$ if $\\Dim(V)<\\infty$. \n\n\\begin{Definition}[Degree shift and grading reversal]\\label{Def:DegreeShift}\nLet $A\\in \\Z$. The \\emph{degree shift by $A$} is a functor which associates to a graded vector space $W$ the graded vector space $W[A]$ with degree-$d$ components\n\\[ W[A]^d \\coloneqq W^{d+A}\\quad \\text{for all }d\\in \\Z.\\]%In the following remark, we discuss two interpretations of the degree shift.\nThere is the canonical degree shift morphism \n\\begin{equation}\\label{Eq:DegreeShift}\n W\\longrightarrow W[A]\n\\end{equation}\nof degree $-A$ mapping $W^d$ identically to $W[A]^{d-A}$. We view this morphism as multiplication from the left with a formal symbol $\\Susp_A$ of degree $\\Abs{\\Susp_A}=-A$, so that~\\eqref{Eq:DegreeShift} can be written as $w\\in W \\longmapsto \\Susp_A w\\in W[A]$.\n\nGiven graded vector spaces $W_1$, $W_2$ and constants $A_1$, $A_2\\in \\Z$, we associate to a morphism $f: W_1 \\rightarrow W_2$ its \\emph{degree shift} $f: W_1[A_1] \\rightarrow W_2[A_2]$ by defining\\footnote{This convention is not optimal; see Remark~\\ref{Rem:BadConvention}.}\n\\begin{equation}\\label{Eq:DegreeShiftConv}\nf(\\Susp_{A_1} w) \\coloneqq \\Susp_{A_2} f(w)\\quad\\text{for all } w \\in W_1.\n\\end{equation} \nNotice that if $f:W_1 \\rightarrow W_2$ has degree $\\Abs{f}$, then $f: W_1[A_1] \\rightarrow W_2[A_2]$ has degree $\\Abs{f} + A_1 - A_2$.\n\nThe \\emph{grading reversal} $r$ is a functor which associates to a graded vector space~$W$ the graded vector space $r(W)$ with\n\\[ r(W)^d \\coloneqq W^{-d}\\quad\\text{for all }d\\in \\Z. \\]\nThere is the canonical morphism $W\\rightarrow r(W)$ mapping $W^d$ identically to $W^{-d}$ for every $d\\in \\Z$. The degree reversal of a morphism $f: W_1 \\rightarrow W_2$ is the morphism $f: r(W_1) \\rightarrow  r(W_2)$ defined by conjugating $f$ with the canonical morphism. If $\\Abs{f}$ is the degree of $f: W_1 \\rightarrow W_2$, then $-\\Abs{f}$ is the degree of $f: r(W_1) \\rightarrow  r(W_2)$.\n\\end{Definition}\n\nIn our main reference \\cite{Cieliebak2015}, they view $W$ and $W[A]$ as one vector space with two different gradings $\\Deg(\\cdot)$ and $\\Abs{\\cdot}$, respectively; these are related by\n\\begin{equation*}\n%\\label{Eq:DegreeRel}\n\\Abs{w} = \\Deg(w) - A \\quad\\text{for all homogenous }w\\in W. \n\\end{equation*}\n%In particular, writing $w\\in W$ and $w\\in W[A]$ is for them equivalent.\n%This is the ``passive'' point of view on degree shifts.\nOn the other hand, we think of $W$ and $W[A]$ as of two different graded vector spaces and never use the same symbol for an element $w\\in W$ and its degree shift $\\Susp_A w \\in W[A]$. %It is the ``active'' point of view.\nIt allows us to use just one notation~$\\Abs{\\cdot}$ for the gradings on both~$W$ and~$W[A]$. However, in order to preserve compatibility with~\\cite{Cieliebak2015}, we will also sometimes use the notation $\\Deg(w)$ (in the exponent just $(-1)^w$) for the degrees on $W$.\n\nFor graded vector spaces $W_1$, $\\dotsc$, $W_k$ and constants $A_1$, $\\dotsc$, $A_k\\in \\Z$, we identify \n\\[ W_1[A_1]\\otimes \\dotsb \\otimes W_k[A_k] \\simeq (W_1\\otimes \\dotsb \\otimes W_k)[A_1+\\dotsb+A_k] \\] using the \\emph{Koszul convention for the tensor product}; for homogenous elements $w_1 \\in W_1$,~$\\dotsc$, $w_k \\in W_k$, it reads\n\\begin{equation} \\label{Eq:KoszulTensor}\n\\Susp_{A_1} w_1 \\otimes \\dotsb \\otimes \\Susp_{A_k} w_k = \\varepsilon(\\Susp_A,w) \\underbrace{\\Susp_{A_1}\\dots\\Susp_{A_k}}_{\\displaystyle \\mathclap{\\eqqcolon \\Susp_{A_1 + \\dotsb + A_k}}\\rule{0ex}{2ex}} w_1 \\otimes \\dotsb \\otimes w_k.\n\\end{equation}\n%We understand the product $\\Susp_{A_1}\\dots\\Susp_{A_k}$ as one formal symbol of degree $-(A_1+\\dotsb+A_k)$.\n%we can abbreviate it by $\\Susp_{\\vec{A}}\\coloneqq \\Susp_{A_1} \\dots \\Susp_{A_k}$, and when $A_1 = \\dotsb = A_k$, then we write $\\Susp_A^k$ instead.\nIf $A_1 = \\dotsb = A_k \\eqqcolon A$ is fixed in the context, which is our usual case, we omit the subscript~$A$ and write just $\\Susp$.\n\nIn the case of the multilinear map $f: W_1\\otimes \\dotsb \\otimes W_k \\rightarrow V_1\\otimes \\dotsb \\otimes V_l$, the combination of~\\eqref{Eq:DegreeShiftConv} and~\\eqref{Eq:KoszulTensor} gives for $f: W_1[A_1]\\otimes \\dotsb\\otimes W_k[A_k] \\rightarrow V_1[B_1]\\otimes \\dotsb\\otimes V_l[B_l]$ the following:\n\\begin{equation}\\label{Eq:DegreeShiftConvII}\n f(\\Susp_{A_1 +\\dotsb + A_k} w_1 \\otimes \\dotsb \\otimes w_k) = \\Susp_{B_1 + \\dotsb + B_l} f(w_1 \\otimes \\dotsb \\otimes w_k).\n\\end{equation}\n\n\\begin{Remark}[Why is this sign convention bad?]\\label{Rem:BadConvention}\nLet us illustrate that \\eqref{Eq:DegreeShiftConvII} is not compatible with the following standard Koszul rule:\n\\begin{equation*}\n(K):\\qquad (f_1 \\otimes f_2)(w_1 \\otimes w_2) = (-1)^{\\Abs{f_2}\\Abs{w_1}} f_1(w_1) \\otimes f_2(w_2).\n\\end{equation*}\nOn one hand, we get \n\\[\\begin{aligned}\n(f_1 \\otimes f_2)(\\Susp^2 w_1 \\otimes w_2) &\\overset{\\eqref{Eq:DegreeShiftConvII}}{=} \\Susp^2 (f_1\\otimes f_2)(w_1 \\otimes w_2) \\\\\n& \\overset{(K)}{=} (-1)^{\\Abs{f_2}\\Abs{w_1}} \\Susp^2 f_1(w_1) \\otimes f_2(w_2)  \\\\\n& \\overset{\\eqref{Eq:KoszulTensor}}{=} (-1)^{\\Abs{f_2}\\Abs{w_1} + A(\\Abs{f_1} + \\Abs{w_1})} \\Susp f_1(w_1) \\otimes \\Susp f_2(w_2).\n\\end{aligned}\\]\nOn the other hand, we get\n\\[\\begin{aligned}\n(f_1 \\otimes f_2)(\\Susp^2 w_1 \\otimes w_2) &\\overset{\\eqref{Eq:KoszulTensor}}{=} (-1)^{A\\Abs{w_1}}(f_1 \\otimes f_2)(\\Susp w_1 \\otimes \\Susp w_2)\\\\\n&\\overset{(K)}{=} (-1)^{A\\Abs{w_1} + \\Abs{f_2}(A+\\Abs{w_1})} f_1(\\Susp w_1) \\otimes f_2(\\Susp w_2)\\\\ &\\overset{\\eqref{Eq:DegreeShiftConvII}}{=}(-1)^{A\\Abs{w_1}+ \\Abs{f_2}(A+\\Abs{w_1})} \\Susp f_1(w_1) \\otimes \\Susp f_2(w_2).\n\\end{aligned}\\]\nThe results differ by $(-1)^{A(\\Abs{f_1}+\\Abs{f_2})}$. Therefore, we can not use (K) to identify the tensor product $\\Hom(W_1,V_1)\\otimes \\Hom(W_2,V_2)$ with a subspace of $\\Hom(W_1\\otimes W_2, V_1\\otimes V_2)$ in general. We will rather define an ad-hoc pairing in the case where we need it (see Definition~\\ref{Def:Pairings}).\n\nAnother caveat is that in the case of the tensor product, the degree shift by $A_1$ followed by the degree shift by~$A_2$ is not the same as the degree shift by $A_1 + A_2$. Indeed, we compute\n\\[\\begin{aligned}\n(\\Susp_{A_1 + A_2}w_1) \\otimes (\\Susp_{A_1 + A_2}w_2) &=\n(\\Susp_{A_2} \\Susp_{A_1}w_1) \\otimes (\\Susp_{A_2}\\Susp_{A_1} w_2) \\\\ &= (-1)^{A_2(A_1 + \\Abs{w_1})}\\Susp_{A_2}^2 (\\Susp_{A_1} w_1) \\otimes (\\Susp_{A_1} w_2) \\\\\n&= (-1)^{A_2 A_1 + (A_1 + A_2)\\Abs{w_1}} \\Susp_{A_2}^2 \\Susp_{A_1}^2 (w_1 \\otimes w_2) \\\\ &= (-1)^{A_2 A_1 + (A_1 + A_2)\\Abs{w_1}} \\Susp_{2(A_1 + A_2)} (w_1 \\otimes w_2),\n\\end{aligned}\\]\nwhich differs by $(-1)^{A_1 A_2}$ from the direct degree shift by $A_1 + A_2$. Therefore, we have to always remember the vector spaces which we started with and the sequence of degree shifts. \n\nNote that we also have the unnatural ``$\\Susp_{A_1} \\Susp_{A_2} = \\Susp_{A_1 + A_2} = \\Susp_{A_2} \\Susp_{A_1}$'' due to \\eqref{Eq:KoszulTensor}.\n\\end{Remark}\n\n\\begin{Remark}[Is there a better sign convention?]\nThe author originally respected the Koszul rule for the algebra with formal symbols and considered the following map $\\Susp^{l}_*\\widebar{\\Susp}^{k*} f: W[A]^{\\otimes k} \\rightarrow V[A]^{\\otimes l}$ as the degree shift of $f: W^{\\otimes k} \\rightarrow V^{\\otimes l}$:\n\\begin{equation}\\label{Eq:AltConv}\n(\\Susp^{l}_*\\widebar{\\Susp}^{k*} f)(\\Susp^{k} w_1 \\otimes \\dotsb \\otimes w_k ) = (-1)^{k \\Abs{f}A + \\frac{1}{2}k(k-1) A} \\Susp^l f(w_1 \\otimes \\dotsb \\otimes w_k).\n\\end{equation}\nHere $\\DeSusp$ denotes the ``inverse'' of $\\Susp$ with $\\Abs{\\widebar{\\Susp}} = - \\Abs{\\Susp}$, $\\Susp_*^l f = \\Susp^l \\circ f$ is the post-composition, $\\DeSusp^{k*}f = (-1)^{k A \\Abs{f}} f\\circ \\DeSusp^k$ the pre-composition, and the sign $ \\varepsilon(\\Susp, \\DeSusp) = (-1)^{\\frac{1}{2}k(k-1)A}$ comes from the ``collision'' $\\DeSusp_1\\dots \\DeSusp_k \\Susp_1 \\dots \\Susp_k \\mapsto \\DeSusp_1 \\Susp_1 \\dots \\DeSusp_k \\Susp_k$. \n\nHowever, the author did not manage to reprove the theory in~\\cite{Cieliebak2015} using~\\eqref{Eq:AltConv} (because of too many ``external'' signs appearing and a problem with disconnected graphs). A~motivation to try a different sign convention was to explain some artificial signs in~\\cite{Cieliebak2015} and formulate their coordinate constructions invariantly in order to generalize them to the ``continuous'' de Rham case.\n\nIt might be possible to deduce a ``universal'' sign convention ``respecting'' the Koszul rules by considering the category of chain complexes and graded morphisms $\\mathcal{C}$ as the category enriched in the closed monoidal category of chain complexes and chain maps of degree~$0$. One can then define the enriched degree shift functor $\\Susp_{A}: \\mathcal{C} \\rightarrow \\mathcal{C}$, embed $\\mathcal{C}^{\\otimes k} \\subset \\mathcal{C}$ using~$(K)$ and study enriched natural transformations in the algebra of functors consisting of tensor products and compositions of $\\Susp_{A}$, $\\Hom(\\cdot, \\cdot)$ and the dual $*$. The question is whether the sign rules for degree shifts, in particular  \\eqref{Eq:AltConv}, are uniquely determined by the requirements on enriched functors and enriched natural transformations.\n\nAnother idea for how to specify the degree shift convention~\\eqref{Eq:AltConv} is the observation that maps $f: W^{\\otimes k}\\rightarrow W^{\\otimes l}$ under consideration usually form an algebra $\\Prop \\rightarrow \\End_W$ of a certain PROP $\\Prop$ over $W$; here $\\End_W$ denotes the endomorphism PROP. Suppose that there is a natural notion of the degree shift $\\Prop[A]$ of a PROP $\\Prop$ and a canonical degree shift morphism $\\Prop \\rightarrow \\Prop[A]$. The PROPs $(\\End_W)[A]$ and $\\End_{W[A]}$ are better to be isomorphic, and any intelligent degree shift convention $\\psi_{k,l}: \\Hom(W^{\\otimes k},W^{\\otimes l})[A(k-l)] \\rightarrow \\Hom(W[A]^{\\otimes k},W[A]^{\\otimes l})$ should induce an isomorphism of the PROPs $(\\End_W)[A]$ and $\\End_{W[A]}$.\n\\end{Remark}\n%We will also use two different formal symbols $\\Susp$ and $\\SuspU$ to shift the degrees.\n%\\begin{Question}\n%Is it possible to reprove \\cite{Wieliebak2015} using \\eqref{Eq:AltWonv}?\n%\\end{Question}\n\n\\begin{Definition}[Standard action of permutations]\\label{Def:Permutations}\nFor $k\\ge 1$ and $\\sigma\\in \\Perm_k$ ($\\coloneqq$\\,the group of permutations on $k$ elements), we define the \\emph{standard action of $\\sigma$} on $W^{\\otimes k}$ by \n\\begin{equation}\\label{Eq:Perm}\n\\sigma(w_1 \\otimes \\dotsb \\otimes w_k) \\coloneqq  \\varepsilon(\\sigma,w) w_{\\sigma_1^{-1}}\\otimes \\dotsb \\otimes w_{\\sigma_k^{-1}}\n\\end{equation}\nfor all homogenous $w_1$, $\\dotsc$, $w_k\\in W$.\n\\end{Definition}\n\nNotice that the $i$-th vector is permuted to the $\\sigma_i$-th place --- this is the ``active'' convention for permutations.\n\n\n\\begin{Definition}[Symmetric algebra]\\label{Def:SymAlgebra}\nLet $\\Ten(V)\\coloneqq \\bigoplus_{k\\ge 0} V^{\\otimes k}$ be the tensor algebra over a graded vector space~$V$. The \\emph{symmetric algebra} over $V$ is defined by $\\Sym(V)\\coloneqq \\bigoplus_{k\\ge 0} \\Sym_k(V)$, where\n\\[ \\Sym_k(V) \\coloneqq V^{\\otimes k} \\bigl/ \\sum_{\\sigma\\in \\Perm_k} \\Im(\\Id-\\sigma)\\quad(\\eqqcolon \\Perm_k\\text{-coinvariants}). \\]\nIt is a weight-graded vector space with components denoted by $(\\Sym_k V)^d$ for all $d\\in \\Z$ and $k\\in \\N_0$. Note that $\\Sym_0 V = \\R$ has degree $0$ by definition. Consider the canonical projection\n\\[\\begin{aligned}\n\\pi : \\Ten(V) &\\longrightarrow \\Sym(V) \\\\\nv_1\\otimes \\dotsb \\otimes v_k &\\longmapsto v_1\\dotsb v_k.\n\\end{aligned}\\]\n%The dot $\\cdot$ indicates the symmetric product.\nIf $v_i\\in V$ are homogenous, we call $v_1 \\dotsb v_k$ a \\emph{generating word}; we have\n\\[ v_1 \\dotsb  v_k = \\varepsilon(\\sigma,v) v_{\\sigma_1^{-1}} \\dotsb v_{\\sigma_k^{-1}}\\quad \\text{for every }\\sigma\\in \\Perm_k. \\]\nLet $\\iota: \\Sym(V) \\rightarrow \\Ten(V)$ be the section of $\\pi$ defined by \n\\[ \\iota(v_1\\dotsb v_k) \\coloneqq \\frac{1}{k!}\\sum_{\\sigma\\in\\Perm_k} \\varepsilon(\\sigma,v) v_{\\sigma_1^{-1}}\\otimes \\ldots \\otimes v_{\\sigma_k^{-1}}. \\]\nWe use it to identify $\\Sym(V)$ with the subspace of symmetric tensors\n\\[ \\iota(\\Sym_k(V)) = \\bigcap_{\\sigma\\in \\Perm_k} \\Ker(\\Id - \\sigma) \\subset \\Ten_k(V)\\quad(\\eqqcolon\\Perm_k\\text{-invariants}). \\]\n\\end{Definition}\n\n\n\\begin{Definition}[Filtrations] \\label{Def:Filtrations}\nLet $W$ be a graded vector space. A filtration of~$W$ is a collection of linear subspaces $\\Filtr^\\lambda W \\subset W$ for $\\lambda\\in \\R$ such that we have either\n\\begin{itemize}\n\\item $\\Filtr^{\\lambda_1}W\\subset \\Filtr^{\\lambda_2}W$ for all $\\lambda_1 \\le \\lambda_2$\\quad$\\Longleftrightarrow:$\\quad\\emph{increasing filtration}, or\n\\item  $\\Filtr^{\\lambda_1}W\\supset \\Filtr^{\\lambda_2}W$ for all $\\lambda_1 \\le \\lambda_2$\\quad$\\Longleftrightarrow:$\\quad\\emph{decreasing filtration.}\n\\end{itemize}\nWe will assume that our filtrations are \\emph{graded} in the following sense:\n\\[ \\forall \\lambda\\in \\R:\\quad \\Filtr^\\lambda W = \\bigoplus_{d\\in \\Z} \\Filtr^\\lambda W^d,\\quad \\text{where}\\quad\\Filtr^\\lambda W^d \\coloneqq \\Filtr^\\lambda W \\cap W^d.\\]\nA filtration $\\Filtr^\\lambda W$ is called:\n\\begin{align*}\n \\text{\\emph{exhaustive}}&\\quad:\\Equiv\\quad\\bigcup_{\\lambda\\in \\R} \\Filtr^\\lambda W = W;\\\\\n \\text{\\emph{Hausdorff}} &\\quad:\\Equiv\\quad\\bigcap_{\\lambda\\in \\R} \\Filtr^\\lambda W = 0;\\\\\n \\text{\\emph{$\\Z$-gapped}} &\\quad:\\Equiv\\quad\\Filtr^\\lambda W = \\Filtr^{\\lfloor\\lambda\\rfloor} W\\text{ for all }\\lambda \\in \\R;\\\\[3\\jot]\n \\text{\\emph{bounded from below}}&\\quad:\\Equiv\\quad\\exists \\lambda \\in \\R: \\Filtr^\\lambda W =0;\\\\[3\\jot]\n \\text{\\emph{bounded from above}}&\\quad:\\Equiv\\quad\\exists \\lambda\\in \\R: \\Filtr^\\lambda W =W.\n\\end{align*} \n\nGiven a graded vector space $W$ filtered by a $\\Z$-gapped filtration $\\Filtr^\\lambda W$, we associate to it the bi-graded vector space \n\\[ \\Gr(W) = \\bigoplus_{d\\in\\Z}\\bigoplus_{\\lambda\\in \\Z} \\Gr(W)_\\lambda^d \\]\ncalled the \\emph{graded module} whose components are given as follows:\\footnote{The definition is made in such a way that if $r$ is the functor which reverses $\\lambda$, i.e., $r(\\Filtr)^\\lambda = \\Filtr^{-\\lambda}$, then it holds $r(\\Gr(\\Filtr)) = \\Gr(r(\\Filtr))$. }\\Modify[caption={DONE Graded module},noline]{Should not the grading of $\\Gr$ be shitfted? I propose $gr_k = F_k/F_{k\\pm 1}$ because $r(gr(\\tilde{F})) = gr(F)$ for the degree reversed filtration.}\n\\[ \\forall d, \\lambda\\in \\Z: \\quad \\Gr(W)_\\lambda^d \\coloneqq \\begin{cases}\n                   \\Filtr^\\lambda W^d /\\Filtr^{\\lambda-1} W^d & \\text{for increasing }\\Filtr^\\lambda W,\\\\\n                   \\Filtr^{\\lambda} W^d / \\Filtr^{\\lambda+1} W^d & \\text{for decreasing } \\Filtr^\\lambda W.\n                 \\end{cases}\\]\nWe naturally extend a filtration over degree shifts, graded duals, direct sums, tensor products and symmetric products as follows: \\allowdisplaybreaks\n\\begin{align*}\n\\Filtr^\\lambda W[A]^d &\\coloneqq \\Filtr^\\lambda W^{d+A},\\\\[3.5\\jot]\n\\Filtr^\\lambda (W^{\\GD})^d &\\coloneqq \\{\\psi\\in W^{d*} \\mid \\Restr{\\psi}{\\Filtr^\\lambda W} = 0\\}, \\\\[3.5\\jot]\n\\Filtr^\\lambda\\bigl(\\bigoplus_{i\\in I} W_i\\bigr)^d &\\coloneqq \\bigoplus_{i\\in I} \\Filtr^{\\lambda} W_i^d, \\\\[2\\jot]\n\\Filtr^{\\lambda}(W_1 \\otimes \\dotsb \\otimes W_k)^d &\\coloneqq \\bigoplus_{\\substack{d_1, \\dotsc, d_k\\in \\Z \\\\ d_1 + \\dotsb + d_k = d}}\\ \\sum_{\\substack{\\lambda_1, \\dotsc, \\lambda_k \\in \\R \\\\ \\lambda_1 + \\dotsb + \\lambda_k = \\lambda}} \\Filtr^{\\lambda_1} W_1^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} W_k^{d_k},\\\\\n\\Filtr^\\lambda (\\Sym_k V)^d &\\coloneqq \\pi(\\Filtr^\\lambda(V^{\\otimes k})^d),\n\\end{align*}\nwhere $\\pi: \\Ten(V) \\rightarrow \\Sym(V)$ is the canonical projection. The ground field $\\R$ is filtered by the trivial filtration:\n\\begin{equation}\\label{Eq:TrivFiltr}\n\\Filtr^\\lambda \\R \\coloneqq \\begin{cases} \\R & \\lambda\\le 0, \\\\ 0 & \\lambda >0. \\end{cases}\n\\end{equation}\nIf $(W,\\Bdd)$ is a filtered chain complex, we filter the homology as follows:\n\\[ \\forall \\lambda \\in \\R, d\\in \\Z: \\quad \\Filtr^\\lambda \\H_d(W,\\Bdd) \\coloneqq \\{\\alpha \\in \\H_d(C,\\Bdd) \\mid \\exists w\\in \\alpha: w\\in \\Filtr^\\lambda W^d \\}. \\]\n\\end{Definition}\n\n\\begin{Definition}[Completions]\\label{Def:Completion}\nLet $W$ be a graded vector space filtered by a decreasing filtration $\\Filtr^\\lambda W$. The \\emph{filtration degree} of $w\\in W$ is defined by\n\\[ \\Norm{w} \\coloneqq \\sup\\{ \\lambda\\in \\R \\mid w\\in \\Filtr^\\lambda W\\}. \\]\nThe filtration degree of a linear map $f: W_1 \\rightarrow W_2$ is defined by\n\\[ \\Norm{f} \\coloneqq \\sup \\{ \\lambda\\in \\R \\mid \\Norm{f(w)} \\ge \\Norm{w} + \\lambda\\ \\forall w\\in W_1\\}. \\]\nWe say that the \\emph{filtration degree is finite} if $\\Norm{f}>-\\infty$. Note that $\\Norm{0} = \\infty$.\n\nThe \\emph{completion} of $W$ is the graded vector space\n\\[ \\hat{W}\\coloneqq \\bigoplus_{d\\in \\Z} \\hat{W}^d, \\]\nwhere for all $d\\in \\Z$  we define\n\\[ \\hat{W}^d \\coloneqq \\Bigl\\{ \\sum_{i=0}^\\infty w_i\\ \\Bigl|\\   \\forall i\\in \\N_0: w_i\\in W^d; \\Norm{w_i} \\to \\infty \\text{ as }i\\to \\infty \\Bigl\\}\\Bigl/\\sim.\n% \\in \\Filtr^{\\lambda_i} W^d, \\lambda_i \\rightarrow \\infty\\text{ as }i\\to \\infty\\Bigr\\} \\Bigl/ \\sim.\n\\]\nHere $\\sum_{i=0}^\\infty w_i \\sim \\sum_{i=0}^\\infty w_i'$ if and only if $\\Norm{\\sum_{i=0}^n (w_i - w_i')}\\to \\infty$ as $n\\to \\infty$.\\footnote{\\label{Footnote:Compl}In fact, $\\hat{W}$ is the inverse limit $\\varprojlim_\\lambda^{\\mathrm{gr}}(W/\\Filtr^\\lambda W)$ in the category of graded vector spaces and~$\\hat{W}^d$ the inverse limit $\\varprojlim_\\lambda(W^d/\\Filtr^\\lambda W^d)$ in the category of vector spaces. As a side-remark, if we forget the grading on $W$, we might also consider $\\varprojlim_\\lambda (W/\\Filtr^\\lambda W)$, which would be a vector space containing~$\\hat{W}$ as a subspace\\vphantom{$W^d$}.}\nThe completion~$\\hat{W}$ is canonically filtered by the filtration $\\Filtr^\\lambda \\hat{W}$ defined as follows:\n\\[ \\forall \\lambda\\in \\R, d\\in \\Z: \\quad \\Filtr^\\lambda\\hat{W}^d\\coloneqq \\Bigl\\{\\sum_{i=0}^\\infty w_i \\in \\hat{W}^d \\ \\Bigr|\\ \\forall i\\in \\N_0: w_i \\in \\Filtr^\\lambda W^d \\Bigr\\}. \\]\nWe denote the completion of $W_1 \\otimes \\dotsb \\otimes W_k$ by $W_1 \\COtimes \\dotsb \\COtimes W_k$ and the completion of $\\Sym_k V$ by $\\hat{\\Sym}_k V$. \n\n\nA map $f: W_1 \\rightarrow W_2$ of finite filtration degree\n\\emph{extends continuously} to a linear map $f: \\hat{W}_1 \\rightarrow \\hat{W}_2$; this continuous extension is defined by\n\\[ f\\Bigl(\\sum_{i=0}^\\infty w_i\\Bigr)\\coloneqq \\sum_{i=0}^\\infty f(w_i)\\quad\\text{for all }\\sum_{i=0}^\\infty w_i \\in \\hat{W}. \\]\n%For all $k\\ge 0$, we denote by $\\hat{E}_k W$ the completion of the graded vector space~$E_k W$ with respect to the filtration\n%\\[ \\Filtr_\\lambda E_k W = \\sum_{\\substack{\\lambda_1, \\dotsc, \\lambda_k\\in \\R \\\\ \\lambda_1+ \\dotsb + \\lambda_k = \\lambda}} \\pi(\\Filtr_{\\lambda_1}W[1] \\otimes \\dotsb \\otimes \\Filtr_{\\lambda_k}W[1]), \\]\n%where $\\pi: W[1]^{\\otimes k} \\rightarrow E_k W$ is the canonical projection. We set $\\hat{E}_0 W \\coloneqq \\R$.\n\\end{Definition}\n\n\\begin{Remark}[Completed tensor product]\\label{Rem:ComplTens}\nUsing Proposition~\\ref{Prop:IsoCrit} below, one can show that the \\emph{completed tensor product} $\\COtimes$ is associative and that $W_1 \\COtimes W_2 \\simeq \\hat{W}_1 \\COtimes \\hat{W}_2$. By refining this argument, one can show that $\\hat{\\Sym}_k V \\simeq \\hat{\\Sym}_k\\hat{V}$ for any $k\\in \\N$.\n\\end{Remark}\n\nA weight-graded vector space $W$ is canonically \\emph{filtered by weights:}\n\\begin{equation}\\label{Eq:FiltrWeights}\n\\forall \\lambda\\in \\R, d\\in \\Z:\\quad\\Filtr^\\lambda W^d \\coloneqq \\bigoplus_{k\\le \\lambda} W_k^d.\n\\end{equation}\nThis filtration is $\\Z$-gapped, exhaustive, Hausdorff, increasing and bounded from below. The induced filtration on the graded dual $W^{\\GD}$ is $\\Z$-gapped, Hausdorff, decreasing and bounded from above (and thus automatically exhaustive). It holds $\\Gr(W) \\simeq W$, and it is easy to see from \\eqref{Eq:Duals} that the canonical map $W^{\\WGD} \\rightarrow W^{\\GD}$ induces the isomorphism\n\\[ \\widehat{W^{\\WGD}} \\simeq W^{\\GD}. \\]\nWe also see that the condition\n\\[ (WG0): \\quad \\forall d\\in \\Z\\ \\exists J\\subset \\N_0, \\Abs{J}<\\infty\\ \\forall k\\in \\N_0\\backslash J: \\quad W_k^d = 0 \\]\nis equivalent to $W^{\\WGD}= W^{\\GD}$.\n\nA useful tool to compare completions is the following proposition:\n\n\\begin{Proposition}[{\\cite[Proposition 7.3.7]{Fresse}}, Isomorphism criterion]\\label{Prop:IsoCrit}\nLet $W_1$ and~$W_2$ be graded vector spaces filtered by $\\Z$-gapped filtrations which are decreasing and bounded from above. Suppose that $f: W_1 \\rightarrow W_2$ is a filtration preserving homogenous linear map. Then the continuous extension $f: \\hat{W}_1 \\rightarrow \\hat{W}_2$ is an isomorphism if and only if the induced map $f: \\Gr(W_1) \\rightarrow \\Gr(W_2)$ is an isomorphism.\n\\end{Proposition}\n\\begin{proof}\nThe implication from the right to the left is obtained from the diagram \n\\[\\begin{tikzcd}\n0 \\arrow{r} & \\Gr(W_1)_\\lambda \\arrow[hook]{r} \\arrow{d}{f} & W_1/\\Filtr^{\\lambda + 1}W_1 \\arrow[two heads]{r} \\arrow{d}{f} & W_1/\\Filtr^{\\lambda} W_1 \\arrow{r}   \\arrow{d}{f} & 0 \\\\\n0 \\arrow{r} & \\Gr(W_2)_\\lambda \\arrow[hook]{r} & W_2/\\Filtr^{\\lambda+1}W_2 \\arrow[two heads]{r} & \\arrow{r}W_2/\\Filtr^{\\lambda} W_2   & 0\n\\end{tikzcd}\\]\nby induction using the definition of $\\hat{W}$ as the inverse limit of $W/\\Filtr^\\lambda W$ (see Footnote \\ref{Footnote:Compl} on page \\pageref{Footnote:Compl}). The other implication follows from $\\Filtr^\\lambda\\hat{W}/\\Filtr^{\\lambda-1}\\hat{W}\\simeq\\Filtr^\\lambda W/\\Filtr^{\\lambda-1}W$.\n\\end{proof}\n\n\nFor a graded vector space $W$ filtered by a $\\Z$-gapped filtration, consider the following conditions:\n\\begin{equation}\\label{Eq:WGs}\n\\begin{aligned}\n(WG1):\\quad& \\forall \\lambda\\in \\Z\\ \\exists I \\subset \\Z, \\Abs{I}<\\infty\\ \\forall d\\in \\Z\\backslash I:& \\Gr(W)_\\lambda^d &= 0, \\\\\n(WG2):\\quad & \\forall d, \\lambda\\in \\Z:& \\dim(\\Gr(W)_\\lambda^d) &< \\infty.\n\\end{aligned}\n\\end{equation}\n\n\\begin{Lemma}[Completion of symmetric powers of the graded dual]\\label{Lem:Terrible}\nLet $W$ be a graded vector space filtered by an exhaustive $\\Z$-gapped filtration~$\\Filtr^\\lambda W$ which is increasing and bounded from below. If (WG1) \\& (WG2) are satisfied, then the natural map $\\Sym_k(W^{\\GD}) \\rightarrow (\\Sym_k W)^{\\GD}$ induces the isomorphism \n\\[ \\hat{\\Sym}_k(W^{\\GD}) \\simeq  (\\Sym_k W)^{\\GD} \\quad\\text{for every }k\\in \\N.\\]\nNote that we filter graded duals by the induced filtration from Definition~\\ref{Def:Filtrations}.\n\\end{Lemma}\n\\begin{proof}\nThe natural map $\\Sym_k(W^{\\GD}) \\rightarrow (\\Sym_k W)^{\\GD}$ is clearly filtration preserving, and hence it extends continuously to a map of completions. The target space $(\\Sym_k W)^{\\GD}$ is already complete (the dual space $W^{\\GD}$ is complete, provided that the filtration of~$W$ is exhaustive), and thus we obtain the map $\\hat{\\Sym}_k(W^{\\GD}) \\rightarrow (\\Sym_k W)^{\\GD}$. According to Proposition~\\ref{Prop:IsoCrit}, this map is an isomorphism if and only if the induced map $\\Gr(\\Sym_k(W^{\\GD})) \\rightarrow \\Gr((\\Sym_k W)^{\\GD})$ is. This is shown by the following computation (the maps involved are natural in at least one direction):\n%We will show that it is an isomorphism in the following paragraph.\n%Let $d$, $\\lambda\\in \\Z$. In the following computation, we will use the notation \n%\\[ \\vec{d} \\coloneqq (d_1, \\dotsc, d_k), \\quad \\bigoplus_{\\Abs{\\vec{d}} = d} \\dotsb = \\bigoplus_{\\substack{d_1, \\dotsc, d_k \\in\\Z \\\\ d_1 + \\dotsb + d_k = d}} \\dotsb\\]\n%and likewise for $\\lambda$ instead of $d$ and $\\sum$ instead of $\\oplus$. We will not write down the maps because every indicated isomorphism is natural at least in one direction. We compute:\n\\allowdisplaybreaks\n\\begin{align*} \n\\frac{\\Filtr^\\lambda ({W^{\\otimes k}}^{\\GD})^d}{\\Filtr^{\\lambda+1} ({W^{\\otimes k}}^{\\GD})^d} &\\simeq \\frac{\\Filtr^\\lambda (W^{\\otimes k})^{d*}}{\\Filtr^{\\lambda+1} (W^{\\otimes k})^{d*}} \\simeq  \\Bigl(\\frac{\\Filtr^{\\lambda+1}(W^{\\otimes k})^d}{\\Filtr^{\\lambda}(W^{\\otimes k})^d}\\Bigr)^* \\\\ \n &\\simeq \\Biggl( \\frac{\\bigoplus_{\\Abs{\\vec{d}}= d} \\sum_{\\Abs{\\vec{\\lambda}}= \\lambda + 1} \\Filtr^{\\lambda_1} W^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} W^{d_k}}{\\bigoplus_{\\Abs{\\vec{d}} = d}\\sum_{\\Abs{\\vec{\\lambda}} = \\lambda} \\Filtr^{\\lambda_1} W^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} W^{d_k}}\\Biggr)^* \\\\\n&\\simeq \\Biggl( \\bigoplus_{\\Abs{\\vec{d}}= d} \\frac{\\sum_{\\Abs{\\vec{\\lambda}} = \\lambda + 1} \\Filtr^{\\lambda_1} W^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} W^{d_k}}{\\sum_{\\Abs{\\vec{\\lambda}} = \\lambda} \\Filtr^{\\lambda_1} W^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} W^{d_k}}\\Biggr)^* \\\\\n&\\simeq\\Bigl( \\bigoplus_{\\Abs{\\vec{d}} = d} \\bigoplus_{\\Abs{\\vec{\\lambda}}=\\lambda} \\frac{\\Filtr^{\\lambda_1 + 1}W^{d_1}}{\\Filtr^{\\lambda_1} W^{d_1}} \\otimes \\dotsb \\otimes \\frac{\\Filtr^{\\lambda_k+1}W^{d_k}}{\\Filtr^{\\lambda_k} W^{d_k}}\\Bigr)^*\\\\\n&\\simeq\\Bigl( \\bigoplus_{\\Abs{\\vec{\\lambda}}=\\lambda} \\bigoplus_{\\Abs{\\vec{d}} = d} \\frac{\\Filtr^{\\lambda_1 + 1} W^{d_1}}{\\Filtr^{\\lambda_1} W^{d_1}} \\otimes \\dotsb \\otimes \\frac{\\Filtr^{\\lambda_k + 1} W^{d_k}}{\\Filtr^{\\lambda_k} W^{d_k}}\\Bigr)^* \\\\\n&\\mathclap{\\substack{\\Z-\\text{gapped}  \\\\[1ex] \\&\\ \\text{bounded below}  \\\\[1ex] \\&\\ (WG1)}\\rightarrow\\rule{7.7em}{0pt}}\\simeq  \\bigoplus_{\\Abs{\\vec{\\lambda}}= \\lambda} \\bigoplus_{\\Abs{\\vec{d}} = d} \\Bigl( \\frac{\\Filtr^{\\lambda_1 + 1} W^{d_1}}{\\Filtr^{\\lambda_1} W^{d_1}} \\otimes \\dotsb \\otimes \\frac{\\Filtr^{\\lambda_k + 1} W^{d_k}}{\\Filtr^{\\lambda_k} W^{d_k}}\\Bigr)^* \\\\\n&\\mathclap{{\\scriptstyle (WG2)}\\rightarrow\\rule{4em}{0pt}}\\simeq  \\bigoplus_{\\Abs{\\vec{\\lambda}}= \\lambda} \\bigoplus_{\\Abs{\\vec{d}} = d}  \\Bigl( \\frac{\\Filtr^{\\lambda_1 + 1} W^{d_1}}{\\Filtr^{\\lambda_1} W^{d_1}}\\Bigr)^* \\otimes \\dotsb \\otimes \\Bigl( \\frac{\\Filtr^{\\lambda_k + 1} W^{d_k}}{\\Filtr^{\\lambda_k} W^{d_k}}\\Bigr)^* \\\\\n&\\simeq \\bigoplus_{\\Abs{\\vec{d}} = d} \\bigoplus_{\\Abs{\\vec{\\lambda}}=\\lambda} \\frac{\\Filtr^{\\lambda_1}(W^{\\GD})^{d_1}}{\\Filtr^{\\lambda_1 + 1}(W^{\\GD})^{d_1}}\\otimes \\dotsb \\otimes \\frac{\\Filtr^{\\lambda_k}(W^{\\GD})^{d_k}}{\\Filtr^{\\lambda_k + 1}(W^{\\GD})^{d_k}} \\\\\n%&\\simeq \\bigoplus_{\\Abs{\\vec{d}} = d} \\frac{\\sum_{\\Abs{\\vec{\\lambda}} = \\lambda} \\Filtr^{\\lambda_1} (W^{\\GD})^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} (W^{\\GD})^{d_k}}{ \\sum_{\\Abs{\\vec{\\lambda}} = \\lambda + 1 } \\Filtr^{\\lambda_1} (W^{\\GD})^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} (W^{\\GD})^{d_k} } \\\\\n%&\\simeq \\frac{\\bigoplus_{\\Abs{\\vec{d}} = d} \\sum_{\\Abs{\\vec{\\lambda}} = \\lambda} \\Filtr^{\\lambda_1} (W^{\\GD})^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} (W^{\\GD})^{d_k}}{\\bigoplus_{\\Abs{\\vec{d}}= d} \\sum_{\\Abs{\\vec{\\lambda}} = \\lambda + 1 } \\Filtr^{\\lambda_1} (W^{\\GD})^{d_1} \\otimes \\dotsb \\otimes \\Filtr^{\\lambda_k} (W^{\\GD})^{d_k} }  \\\\\n&\\simeq \\frac{\\Filtr^{\\lambda} ({W^{\\GD}}^{\\otimes k})^d}{\\Filtr^{\\lambda + 1} ({W^{\\GD}}^{\\otimes k})^d}.\n\\end{align*}\nIn fact, this computation shows that $\\hat{\\Ten}_k(W^{\\GD}) \\simeq (\\Ten_k W)^{\\GD}$. The conclusion for $\\Sym_k$ follows by checking that the maps above are $\\Perm_k$-equivariant.\n%\n%As for $\\Sym_k$,\n%%using the maps~$\\iota$ and~$\\pi$ from Definition~\\ref{Def:SymAlgebra}\n%we have\n%\\[ \\Filtr^\\lambda (\\Sym_k(W^{\\GD})) \\simeq \\Filtr^\\lambda ({W^{\\GD}}^{\\otimes k}) / \\Perm_k \\quad \\text{and}\\quad \\Filtr^\\lambda (\\Sym_k W)^{\\GD} \\simeq \\Filtr^\\lambda ({W}^{\\otimes k})^{\\GD} / \\Perm_k. \\]\n%It is easy to check that the isomorphisms in the computation above are equivariant with respect to the action of $\\Perm_k$. It follows that\n%\\[ \\frac{\\Filtr^\\lambda (\\Sym_k (W^{\\GD}))^d}{\\Filtr^{\\lambda+1} (\\Sym_k (W^{\\GD}))^d} \\simeq \\frac{\\Filtr^\\lambda ({W^{\\GD}}^{\\otimes k})^d }{\\Filtr^{\\lambda+1} ({W^{\\GD}}^{\\otimes k})^d}\\Bigr/ \\Perm_k \\simeq \\frac{\\Filtr^\\lambda (W^{\\otimes k})^{\\GD}}{\\Filtr^{\\lambda +1} (W^{\\otimes  k})^{\\GD}} \\Bigr/ \\Perm_k \\simeq \\frac{\\Filtr^\\lambda {(\\Sym_k W)^{\\GD}}^d}{\\Filtr^{\\lambda+1} {(\\Sym_k W)^{\\GD}}^d}. \\]\n%This proves the lemma.\n%%We used here the general fact that if a group $G$ acts on a vector space $V$ by linear maps and $W\\subset V$ is an invariant subspace, then $(V/G)/(W/G) \\simeq (V/W)/G$.\n%%The only if part holds because $(W\\otimes W)^* = W^* \\otimes W^*$ iff $\\Dim(W)<\\infty$ and $(\\bigoplus_{i\\in I} W_i )^* \\simeq \\bigoplus_{i\\in I} W_i^*$ iff $W_i = 0$ for all but finitely many $i\\in I$.\n\\end{proof}\n\nGiven a chain complex $(W,\\Bdd)$, the boundary operator $\\Bdd$ induces the boundary operator $\\Bdd_k : W^{\\otimes k} \\rightarrow W^{\\otimes k}$ for all $k\\in \\N$; for all $w_1$, $\\dotsc$, $w_k\\in W$, it is defined~by\n\\begin{equation}\\label{Eq:BddExt}\n\\Bdd_k(w_1 \\otimes \\dotsb \\otimes w_k)\\coloneqq \\sum_{i=1}^k (-1)^{\\Abs{w_1} + \\dotsb + \\Abs{w_{i-1}}} w_1 \\otimes \\dotsb \\otimes \\Bdd w_i \\otimes \\dotsb \\otimes w_k.\n\\end{equation}\nThe map $\\Bdd_k$ is clearly $\\Perm_k$-equivariant, and thus induces the boundary operator $\\Bdd_k : \\Sym_k W \\rightarrow \\Sym_k W$.\n\n\\begin{Proposition}[K\\\"unneth formula for completed symmetric cohomology]\\label{Prop:Kuenneth}\nLet $(W,\\Bdd)$ be a $\\Z$-graded chain complex over $\\R$ filtered by an exhaustive $\\Z$-gapped filtration~$\\Filtr^\\lambda W$ which is increasing and bounded from below. Consider the dual cochain complex $(W^{\\GD},\\Dd\\coloneqq \\Bdd^*)$. Suppose that $\\Dd$ has finite filtration degree, so that $\\Dd_k: \\Sym_k(W^{\\GD}) \\rightarrow \\Sym_k(W^{\\GD})$ extends continuously to $\\Dd_k : \\hat{\\Sym}_k(W^{\\GD}) \\rightarrow \\hat{\\Sym}_k(W^{\\GD})$ for every $k\\in \\N$. If (WG1) \\& (WG2) are satisfied, then the natural map $\\Sym_k \\H(W^{\\GD},\\Dd) \\rightarrow \\H(\\hat{\\Sym}_k(W^{\\GD}),\\Dd_k)$ induces the isomorphism\n\\begin{equation*}\n%\\label{Eq:TTerrible}\n\\hat{\\Sym}_k \\H(W^{\\GD},\\Dd) \\simeq \\H(\\hat{\\Sym}_k(W^{\\GD}), \\Dd_k)\\quad \\text{for all }k\\in \\N.\n\\end{equation*}\n\\end{Proposition}\n\\begin{proof}\nThe natural map $\\Sym_k \\H(W^{\\GD},\\Dd) \\rightarrow \\H(\\hat{\\Sym}_k W^{\\GD},\\Dd_k)$ is clearly filtration preserving, and hence it extends continuously to a map of completions. The target space $\\H(\\hat{\\Sym}_k W^{\\GD},\\Dd_k)$ is already complete (the homology of a complete space is complete), and hence we obtain the map $\\hat{\\Sym}_k \\H(W^{\\GD},\\Dd) \\rightarrow \\H(\\hat{\\Sym}_k W^{\\GD},\\Dd_k)$. The following facts are easy to verify:\n\\begin{enumerate}[label=(\\arabic*)]\n \\item The isomorphism from Lemma~\\ref{Lem:Terrible} is an isomorphism of cochain complexes \n \\[ (\\hat{\\Sym}_k W^{\\GD}, \\Dd_k) \\simeq ((\\Sym_k W)^{\\GD}, \\Bdd_k^*). \\]\n\\item If the filtration on~$W$ satisfies (WG1) and (WG2), then the filtration on $\\H(W)$ also satisfies (WG1) and (WG2), respectively. Consequently, Lemma~\\ref{Lem:Terrible} holds for symmetric powers of $\\H(W,\\Bdd)^{\\GD}$ as well.\n\\item The Künneth formula $\\H(W^{\\otimes k}) \\simeq \\H(W)^{\\otimes k}$ implies $\\H(\\Sym_k W) \\simeq \\Sym_k \\H(W)$ for any $\\Z$-graded chain complex $W$ over $\\R$.\n\\item We have $(\\H(W))^{\\GD} \\simeq \\H(W^{\\GD})$ over $\\R$ by the universal coefficient theorem.\n\\end{enumerate}\nNow, we compute\n\\begin{align*}\n\\H(\\hat{\\Sym}_k W^{\\GD},\\Dd_k ) &\n\\underset{\\substack{\\uparrow\\rule{0pt}{1.5ex} \\\\ (1)}}{\\simeq}\n\\H((\\Sym_k W)^{\\GD}, \\Bdd_k^*)\n\\underset{\\substack{\\uparrow\\rule{0pt}{1.5ex} \\\\ (4)}}{\\simeq}\n\\H(\\Sym_k W, \\Bdd_k)^{\\GD} \n\\underset{\\substack{\\uparrow\\rule{0pt}{1.5ex} \\\\ (3)}}{\\simeq}\n(\\Sym_k \\H(W,\\Bdd))^{\\GD} \\\\ \n&\\underset{\\substack{\\uparrow\\rule{0pt}{1.5ex} \\\\ (2)}}{\\simeq}\n\\hat{\\Sym}_k (\\H(W,\\Bdd)^{\\GD}) \n\\underset{\\substack{\\uparrow\\rule{0pt}{1.5ex} \\\\ (4)}}{\\simeq}\n\\hat{\\Sym}_k \\H(W^{\\GD},\\Dd).\n\\end{align*}\n%We did not write the maps because at least one direction of every equivalence is induced by a natural map. \nThis proves the proposition.\n\\end{proof}\n\n\n\\end{document}\n", "meta": {"hexsha": "a9237b8d055ad45ea2a7afa064560efa67aa4ba4", "size": 36111, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/AlgStr_BasicAlg.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/AlgStr_BasicAlg.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/AlgStr_BasicAlg.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": 97.5972972973, "max_line_length": 818, "alphanum_fraction": 0.6797097837, "num_tokens": 13456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6243068835880718}}
{"text": "Our type inference program for the $\\lambda$-calculus imitates \nthe following structure.\n\\begin{gather*}\n    \\texttt{standard I/O} \\xrightarrow{\\text{chars}}\n    \\texttt{lexing} \\xrightarrow{\\text{tokens}} \\texttt{parsing} \\\\\n    \\lhook\\joinrel\\xrightarrow{\\text{terms}} \\texttt{type-inferring} \n    \\xrightarrow{\\text{type}/\\text{error}} \\texttt{pretty-printing}\n\\end{gather*}\nwhere a program as a sequence of characters is first read from the \nstandard input, tokenized by a lexical analyzer, and parsed into \nan abstract syntax tree. The program then infers the type for  \nthe expression. The final \nresult is then printed to the standard output in a readable format. \nThis section mainly focuses on the implementation of the type \ninference component. \nThe details on the lexer, parser, and pretty-printer can be consulted \nin Appendix A, B, and C.\n\nFirst, we represent the abstract syntax for the language defined in Section 2 \nwith data types for expressions, types, and type schemes.  \n\\begin{lstlisting}\n    data Expr = Tru                   \n               | Fls                   \n               | Zero                  \n               | Var String            \n               | If Expr Expr Expr     \n               | Succ Expr             \n               | Pred Expr             \n               | IsZero Expr           \n               | Let String Expr Expr  \n               | Lambda String Expr    \n               | App Expr Expr \n               \n    data Type = TVar Int       \n               | Boolean        \n               | Nat            \n               | Arr Type Type \n    \n    type TVar = Type\n\n    data TypeScheme = ForAll [TVar] TypeScheme\n                      | Scheme Type\n\\end{lstlisting}\nThe type synonym \\lstinline{TVar} for \\lstinline{Type} is used in  \nthe construction of a quantified type scheme to indicate that only \ntype variables are supposed to be quantified. \n\n\\subsection{Unification}\nThe Hindley-Milner type inference algorithm relies on the unification \nsubroutine to compute a substitution that equates two types. The \ndata type for a substitution is defined as a mapping of type variables \nto types.\n\\begin{lstlisting}\n    data Substitution = Subs (Map Int Type)\n\\end{lstlisting}\nHere, we represent a type variable simply as an integer. We also define \na typeclass \\lstinline{Substitutable} to apply a substitution to types, \ntype schemes, and type environments. \n\\begin{lstlisting}\n    instance Substitutable Type where\n        subs s (TVar x)    = case lookUp s x of \n            Just t  -> subs s t \n            Nothing -> TVar x\n        subs s (Arr t1 t2) = subs s t1 `Arr` subs s t2\n        subs s t           = t\n\n    instance Substitutable TypeScheme where \n        subs s (Scheme t)    = Scheme $ subs s t\n        subs s (ForAll xs c) = ForAll xs c'\n          where \n            c' = removeBoundVars s xs `subs` c\n\n    instance Substitutable TypeEnv where \n        subs s (TypeEnv r) = TypeEnv $ subs s `Map.map` r\n\\end{lstlisting}\nWhen applying a substitution to a type variable results in another \ntype variable, we keep repeating the substitution process until the result \nis either a precise type or a type variable that is not mapped to anything else. \nAlso, applying a substitution to a \ntype scheme, $S\\sigma$, only affects free type variables. Therefore, \nwe need to remove all the quantified type variables in $\\sigma$ from $S$ \nbefore performing substitution.\n\nGiven multiple substitutions, we need to be able to compose them into one. \n\\begin{lstlisting}\n    compose :: Substitution -> Substitution -> Substitution\n    compose s1 (Subs s2) \n        | Map.null s2 = s1\n    compose (Subs s1) s2 \n        | Map.null s1 = s2\n    compose (Subs s1) (Subs s2) = \n        Subs $ Map.union s1'' s2  \n      where \n        s1'  = subs (Subs s2) `Map.map` s1\n        s1'' = Map.filterWithKey mirror s1'\n        mirror k a = case a of \n            TVar x \n                | k == x -> False\n            _             -> True \n\\end{lstlisting}\nThe composition of two substitutions $S_1$ and $S_2$ is obtained by \nfirst applying $S_2$ to every type value in $S_1$ and removing any mappings between two \nidentical type variables. Then we take the left-biased union of the new $S_1$ \nand $S_2$ to remove duplicate keys in $S_1$ from $S_2$. If either substitution \nis empty, then we return the non-empty one as the composition. \n\nGiven the definition of a substitution, the unification algorithm is as follows.\n\\begin{lstlisting}\n    unify :: Type -> Type -> GlobalState Substitution\n    unify t1 t2 \n        | t1 == t2                = return Subs.empty\n    unify (TVar x) t2\n        | occurCheck x t2         = throwError $ Occur x t2\n        | otherwise               = return $ Subs.insert Subs.empty x t2\n    unify t1 (TVar x) \n        | occurCheck x t1         = throwError $ Occur x t1\n        | otherwise               = return $ Subs.insert Subs.empty x t1\n    unify (Arr s1 t1) (Arr s2 t2) = do s'  <- unify s1 s2 \n                                       s'' <- unify (subs s' t1) (subs s' t2)\n                                       return $ Subs.compose s'' s'\n    unify t1 t2                   = throwError $ Mismatch t1 t2\n\\end{lstlisting}\nThere are four cases when unifying two types: \n\\begin{enumerate}\n    \\item An empty substitution is returned for two equivalent types.\n    \\item A singleton substitution mapping a type variable $\\alpha$ \n    to another type $T$ is returned only if $\\alpha$ does not occur in $T$. For instance, \n    substitution $[a/(a \\rightarrow \\texttt{Nat})]$ applied to $a$ gives \n    $a \\rightarrow \\texttt{Nat}$ but yields $(a \\rightarrow \\texttt{Nat}) \\rightarrow \\texttt{Nat}$ \n    when applied to $a \\rightarrow \\texttt{Nat}$. Hence, this substitution \n    is invalid.\n    \\item  Unifying two function types involves composing the two substitutions \n    resulted from unifying the argument types and the return types.\n    \\item An error is returned when unifying two inconsistent types. \n\\end{enumerate} \n\nThe unification algorithm plays an important role in type inference for \neither finding substitutions used to specify the final type, or reporting a type \nerror.\n\n\\subsection{Algorithm W}\nGiven a type environment $\\Gamma$ and an expression $e$, algorithm W \nreturns both a substitution $S$ and a type $\\tau$ such that \n\\begin{align*}\n    S\\Gamma \\vdash e : \\tau\n\\end{align*}\nThe return result $(S, \\tau)$ is wrapped inside the \\lstinline{GlobalState} \nmonad, which is defined as \n\\begin{lstlisting}\n    type GlobalState a = ExceptT Error (State Int) a\n\\end{lstlisting}\nThe combination of the \\lstinline{State} and \\lstinline{Except} monads\nallows us to maintain a global counter for generating fresh type variable name \nas well as to return errors during type inference.\n\nAlgorithm W is implemented as follows.\n\\begin{lstlisting}\n    typeInfer' :: TypeEnv -> Expr -> GlobalState (Substitution, Type)\n    typeInfer' r e = case e of \n        -- | Constants\n        Tru         -> return (Subs.empty, Boolean)\n        Fls         -> return (Subs.empty, Boolean)\n        Zero        -> return (Subs.empty, Nat)\n        -- | Arithmetic\n        Succ e'     -> typeInferArith r e' Nat\n        Pred e'     -> typeInferArith r e' Nat\n        IsZero e'   -> typeInferArith r e' Boolean\n        -- | Conditional\n        If e1 e2 e3 -> do (s1, t1) <- typeInfer' r e1\n                          s1' <- unify Boolean t1\n                          let s1'' = Subs.compose s1 s1'\n                          let r1 = subs s1'' r\n                          (s2, t2) <- typeInfer' r1 e2\n                          let r2 = subs s2 r1 \n                          (s3, t3) <- typeInfer' r2 e3\n                          s4 <- unify t2 t3\n                          let s' = Subs.composeList [s4, s3, s2, s1'']  \n                          return (s', subs s4 t2)\n        -- | Variable\n        Var x       -> do c <- TypeEnv.lookUp r x\n                          t <- instantiate c\n                          return (Subs.empty, t)\n        -- | Abstraction\n        Lambda x e' -> do t <- GlobalS.newTVar\n                          let r' = TypeEnv.insert r x $ Scheme t\n                          (s', t') <- typeInfer' r' e'\n                          return (s', subs s' t `Arr` t') \n        -- | Application\n        App e1 e2   -> do (s1, t1) <- typeInfer' r e1\n                          let r' = subs s1 r\n                          (s2, t2) <- typeInfer' r' e2\n                          t <- GlobalS.newTVar\n                          s3 <- subs s2 t1 `unify` Arr t2 t\n                          let s = Subs.composeList [s3, s2, s1]\n                          return (s, subs s3 t)\n        -- | Let expressions\n        Let x e1 e2 -> do (s1, t1) <- typeInfer' r e1\n                          let r1 = subs s1 r \n                          let r2 = TypeEnv.insert r x $ generalize r1 t1\n                          let r3 = subs s1 r2 \n                          (s2, t2) <- typeInfer' r3 e2\n                          let s = Subs.compose s2 s1\n                          return (s, t2)\n\\end{lstlisting}\nIn the case of a constant, we simply return one of the base types. \nArithmetic and boolean operators as constant functions only differ in their \noutput type. We create a subroutine \\lstinline{typeInferArith} to handle \ndifferent output types. \n\\begin{lstlisting}\n    typeInferArith :: TypeEnv -> Expr -> Type -> GlobalState (Substitution, Type)\n    typeInferArith r e retTy = do \n        (s1, t1) <- typeInfer' r e\n        t <- GlobalS.newTVar\n        s2 <- unify (Arr Nat retTy) (Arr t1 t)\n        let s = Subs.compose s2 s1 \n        return (s, subs s2 t)\n\\end{lstlisting}\nThe type $t_1$ of the input expression is first inferred. Then we unify \nthe type of the operator with type $t_1 \\rightarrow \\beta$, where $\\beta$ \nis a new type variable generated using the subroutine \\lstinline{GlobalS.newTVar}. \nThe resulting substitution is applied to $\\beta$ for the final type.\n\nIn the case of a conditional expression, we first compute the type for the condition \nand check if it is of type \\texttt{Bool} through unification. Then we unify \nthe inferred types for the two branches to ensure their equivalence. \nNote that every computed substitution is immediately applied to the type \nenvironment to instantiate all the type schemes containing variables. The final \ntype of a conditional expression is the result of applying the last substitution \nto one of the branch types. The composition of all the substitutions \ncomputed during the process is then returned. \n\nType inference for a variable $x$ is simply the application of rule {\\scriptsize{[TAUT]}} \nto find the type scheme $\\sigma$ for $x$ in $\\Gamma$, and rule {\\scriptsize{[INST]}} \nto instantiate $\\sigma$ with new type variables. \n\nIn the case of a $\\lambda$-abstraction, we generate a new type variable $\\beta$ \nas the type for the bound variable $x$. The type for the body \nexpression is inferred under the assumption that $x$ has type $\\beta$ \nto yield the return type for the $\\lambda$-abstraction. \nApplying the resulting substitution to $\\beta$ gives the input type for \nthe $\\lambda$-abstraction.\n\nTo infer the type of an application, the algorithm first infers the types for the \noperator $e_1$ and the argument $e_2$. A new type variable $\\beta$ is used as the return type \nfor an operator that takes in the computed argument type. Both the original \nand new function types are unified to produce a substitution for $\\beta$ as \nthe final type. All the substitutions are composed and returned.\n\nFinally, in the case of a \\texttt{let}-expression ($\\texttt{let} \\: x = e_1 \\: \\texttt{in} \\: e_2$), \nthe type $t_1$ of $e_1$ along with the substitution $S_1$ used for the inference are computed. \nThe resulting type is generalized with respect to the type environment $\\Gamma$ after \nthe application of $S_1$. The type of a \\texttt{let}-expression is just the type inferred \nfor $e_2$, where all the $x$ occurrences assume the generalized type scheme.\n\nAt the top level, we apply algorithm W to an input expression with an  \nempty type environment and an initial type variable name of 0. The \\lstinline{GlobalState} \nresult is lifted to expose the inner \\lstinline{Either} value that \nrepresents either a type error or the most general type for the expression.\n\\begin{lstlisting}\n    typeInfer :: Expr -> Either Error Type\n    typeInfer e = case GlobalS.runTyInfer $ typeInfer' TypeEnv.empty e of \n        Right (s, t) -> Right t \n        Left err     -> Left err \n\\end{lstlisting}", "meta": {"hexsha": "e0f55b60d956dfb24b361068db22d0dcc005aebc", "size": 12503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project Report/Implementation.tex", "max_stars_repo_name": "thuytien140894/AlgorithmW", "max_stars_repo_head_hexsha": "bb29ec474f2131887d1da4d3d1075f652aeaf251", "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": "Project Report/Implementation.tex", "max_issues_repo_name": "thuytien140894/AlgorithmW", "max_issues_repo_head_hexsha": "bb29ec474f2131887d1da4d3d1075f652aeaf251", "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": "Project Report/Implementation.tex", "max_forks_repo_name": "thuytien140894/AlgorithmW", "max_forks_repo_head_hexsha": "bb29ec474f2131887d1da4d3d1075f652aeaf251", "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.3598484848, "max_line_length": 101, "alphanum_fraction": 0.6286491242, "num_tokens": 3177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6243068804073693}}
{"text": "\\documentclass{article}\n\n\\usepackage{fullpage}\n\\usepackage{amsmath, amsfonts}\n\n\\begin{document}\n\\section{Introduction to Knapsack and Expanding Core}\nConsider a set of items $I = \\{i_1,...,i_n\\}$ where each item is a weight value pair, $i_i = (w_i, v_i)$. Then the knapsack problem is to maximize the value of a subset of these items, which keeping their total weight within some capacity, $c$. In the 0-1 Knapsack problem (KP), we can only have integer solutions, so we describe a solution using $X = \\{x_1,\\ldots,x_n \\ | \\ x_i \\in \\{0,1\\}\\}$, which is called a {\\bf decision vector}.\n\\begin{equation} \\label{knapsackdef}\n\\begin{aligned}\n    \\text{maximize }& z = \\sum\\limits_{j=1}^n v_jx_j \\\\\n    \\text{such that }& \\sum  w_j x_j \\leq c\\\\\n\\end{aligned}\n\\end{equation}\n\nIn the linear knapsack problem (LKP), we are allowed to take fractional items. The optimal solution in this case can be found easily by greedily adding the items with the greatest value / weight ratio, $r_i$, until we can no longer add any complete items. This is known as the {\\bf break solution}. The left over space is filled with a fraction of the remaining item with the greatest ratio, the {\\bf break item}.We define the index $b$ as the index of this break item. Note that we assume $I$ is indexed from highest ratio to lowest. \n\\begin{equation} \\label{breakitemdef}\n    b = \\min \\{j \\ | \\ \\sum\\limits_{j=1}^n wj > c\n\\end{equation}\n\nIt has been observed that the optimal solution to an instance of the KP generally shares most of the items with the break solution, save for some changes around the break item. This suggest looking at a small interval of items about $b$, known as the {\\bf core}. The core is an interval of indices, $[s,t]$, satisfying the following ordering:\n\\begin{equation} \\label{coreOrdering}\n    \\begin{aligned}\n        r_j &\\geq e_{j+1} \\ \\ j = s, \\ldots , t-1\\\\\n        r_j &\\geq e_s \\ \\ j = 1, \\ldots ,s-1\\\\\n        r_j &\\leq e_t \\ \\ j = t+1, \\ldots , n\n    \\end{aligned}\n\\end{equation}\n\nEssentially, we only need a strict ordering of items within $[s,t]$. The interval $[1,s-1]$ has items with a greater ratio that $e_s$ and items in the interval $[t+1, n]$ have a greater ratio than $e_t$. As long as we are only considering items in the core, this ordering on the set of items will be sufficient. \n\nWe will be looking at partial decision vectors based on this core problem. The set of all partial decision vector at any step will be given by:\n\\begin{equation} \\label{partialDec}\n    \\begin{aligned}\n        X_{s,t} &= \\{(x_s,\\ldots,x_t) \\ | \\ x_i \\in \\{0,1\\}\\}\n    \\end{aligned}\n\\end{equation}\nNote that enumerating all possible partial decision vectors would take $O(2^{t-s+1})$, so much of our effort will be spent on keeping tight bounds on $s$ and $t$. Algorithms that solve the knapsack by expanding this core interval are known as {\\bf expanding core} algorithms. \n\n\\section{Finding the Break Item}\nFinding the break item can be done simply in $O(n \\log n)$ time by sorting the list of items and using \\ref{knapsackdef}. However, given our weaker ordering requirements as described in \\ref{coreOrdering}, sorting the entire list may not be necassary. As such, a variety of algorithms for finding the break item in $O(n)$ can be devised. \n\nAt the moment, this topic seems like a distraction, so we will return to it later. Maybe. \n\n\\section{Core Recursion}\nUsing the basic insight behing expanding core algorithms, we can defined a new recusion that solves the core problem first. Assume items adhere to the ordering described in \\ref{coreOrdering}. We will be defining this as the function $f_{s,t}(\\tilde{c})$. Note that $s,t$ are the bounds of our core interval. $\\tilde{c}$ refers to the capacity for the core problem, $0 \\leq \\tilde{c} \\leq 2c$.\n$$\\tilde{c} = \\sum\\limits_{j=1}^{s-1} w_j$$\nNote, that the optimal solution can be expressed as $f_{1,n}(c)$. Then our recurrence is:\n\\begin{equation}\n    \\begin{aligned}\n        f_{s,t}(\\tilde{c}) = \\max \\left\\{\\sum\\limits_{j=1}^{s-1}v_j + \\sum\\limits_{j=s}^t v_j x_j \\ \\bigg| \\  \\sum\\limits_{j=1}^{s-1}w_j + \\sum\\limits_{j=s}^t w_j x_j \\leq \\tilde{c}, \\ x_j \\in \\{0,1\\}\\right\\}\n    \\end{aligned}\n\\end{equation}\nWe can express this in an equivalent way to better enumerate the possible choices.\n\\begin{equation} \\label{reccurence}\n    \\begin{aligned}\n        f_{s,t}(\\tilde{c}) = \\max \\begin{cases} f_{s,t-1}(\\tilde{c}) &  t \\geq b\\\\\n    f_{s,t-1}(\\tilde{c} - w_t) + v_t &  t \\geq b, \\tilde{c} - w_t \\geq 0 \\\\\n    f_{s+1,t}(\\tilde{c}) & s < b\\\\\n    f_{s+1,t}(\\tilde{c} + w_s) - v_s & s < b, \\tilde{c} + w_s \\leq 2c \\end{cases}\n\\end{aligned}\n\\end{equation}\nNow, let $f_{b,b-1}(\\tilde{c}) = -\\infty$ for $0 \\leq \\tilde{c} \\leq \\tilde{w} - 1$, and let $f_{b,b-1}(\\tilde{c}) = \\tilde{p}$ for $\\tilde{w} \\leq \\tilde{c} \\leq 2c$, where $\\tilde{p} = \\sum\\limits_{j=1}^{b-1}p_j$, and $\\tilde{w} = \\sum\\limits_{j=1}^{b-1}w_j$. \n\nThe idea here is that the enumeration starts with $(s,t) = (b, b-1)$, and we either take items out of the sack (lower $s$), or add items to the sack (raise $t$).\n\nWe will represent an undominated state with with the tuple $(\\pi_i, \\mu_i, \\delta_i)$ where $\\pi_i = f_{s,t}(\\mu_i)$, and the \n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "f58687325c0c33a618514ba546ed5ed107fd1fb1", "size": 5193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/minknap.tex", "max_stars_repo_name": "ThermalSpan/cpp-knapsack", "max_stars_repo_head_hexsha": "dcc577a3ef9f9da1f2a85400465f488d91fdd8cf", "max_stars_repo_licenses": ["MIT"], "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/minknap.tex", "max_issues_repo_name": "ThermalSpan/cpp-knapsack", "max_issues_repo_head_hexsha": "dcc577a3ef9f9da1f2a85400465f488d91fdd8cf", "max_issues_repo_licenses": ["MIT"], "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/minknap.tex", "max_forks_repo_name": "ThermalSpan/cpp-knapsack", "max_forks_repo_head_hexsha": "dcc577a3ef9f9da1f2a85400465f488d91fdd8cf", "max_forks_repo_licenses": ["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.1756756757, "max_line_length": 535, "alphanum_fraction": 0.6884267283, "num_tokens": 1694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.624306877226666}}
{"text": "\n\\subsection{Moving between polar and cartesian coordinates}\n\nAll polar numbers can be shown as Cartesian\n\n\\(ae^{i\\theta }=a(\\cos(\\theta )+i\\sin(\\theta ))\\)\n\n\\(ae^{i\\theta }=a\\cos(\\theta )+ia\\sin(\\theta )\\)\n\n\\(z=a+bi\\)\n\n\\(e^{i\\theta }=\\)\n\n\\(e^x=\\sum^{\\infty }_{i=0} \\dfrac{x^i}{i!}\\)\n\n", "meta": {"hexsha": "b2dfbf8796cf12af2a5bc5bbb3bcc5007f6a0415", "size": 285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometryPolar/01-02-polarCartesian.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/trigonometryPolar/01-02-polarCartesian.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/trigonometryPolar/01-02-polarCartesian.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.8125, "max_line_length": 59, "alphanum_fraction": 0.6035087719, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739075, "lm_q2_score": 0.6548947290421275, "lm_q1q2_score": 0.624294799923188}}
{"text": "% !TEX root = index.tex\n\\section{How Curved is a Potato?}\n\\epigraph{The heart of mathematics consists of concrete examples and concrete problems. Big general theories are usually afterthoughts based on small but profound insights; the insights themselves come from concrete special cases.}{Paul Halmos}\n\nSurfaces are much more varied than curves. The standard examples of surfaces are a plane, a cylinder, a saddle, a sphere, a torus etc. It is hard to come up with a single number that completely describes how curved these objects are. So the better question is what's the right amount of information we need to quantify curvature of these objects?\n\n\\subsection{Defining Curvature for Graphs}\nFor us a surface $S$ is just a connected smooth 2-dimensional subset of $\\R^3$. We want our surfaces to be nice, with no sharp edges and no self-intersections.\\footnote{A surface is a connected smooth 2-dimensional submanifold of $ \\R^n$ without a boundary.}\n\nIt is unclear that we can use an approximating sphere or something similar to define curvature. But we know that for curves the curvature measures the \\emph{quadratic behavior} of the curve. As with curves, we'll start by analyzing graphs of functions $f(x,y):\\R^2 \\rightarrow \\R$\n\\begin{align*}\n  S = \\{ (x,y,z) : z = f(x,y)\\}\n\\end{align*}\nWe'll further assume that $p=(0,0)$ is a critical point of $f(x,y)$ i.e.\n\\begin{align*}\n   f_x(p) = 0 = f_y(p)\n\\end{align*}\nOur experience with curves suggests that we should define the curvature of $ S$ at $ p$ to be the triple\n$$\\kappa \\stackrel{?}{=} (f_{xx}(p), f_{xy}(p), f_{yy}(p))$$\nbut there is a catch.\n\n\n\n\n\n\n\\subsection{The Catch}\nWe can rotate $ \\R^3$ about the $ z-\\mbox{axis}$ and the new surface $ S'$ will still satisfy the properties mentioned above. The new surface $ S'$ will be described by a completely different function $ g(x,y)$ and the second derivatives of $ g(x,y)$ will be different from those of $ f(x,y)$. However, the curvatures of $ S$ and $S'$ should be the same. This problem did not arise for curves because there is no way to {rotate $ \\R^2$ about the $ y$-axis}.\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[t]{0.495\\textwidth}\n    \\centering\n    \\includegraphics[width=6cm]{parabola1}\n    \\caption{$ f(x,y) = x^2 $ has second derivatives $ (2,0,0)$}\n  \\end{subfigure}\n  \\begin{subfigure}[t]{0.495\\textwidth}\n    \\centering\n    \\includegraphics[width=6cm]{parabola2}\n    \\caption{$ f(x,y) = y^2 $ has second derivatives $ (0,0,2)$}\n  \\end{subfigure}\n  \\caption{The two surfaces are related to each other by a rotation about the $ z$-axis but they have very different second derivatives.}\n\\end{figure}\n\n\\begin{ques}\n  \\label{ques:paraboloid}\n  Rotate the parabolic cylinder $z=x^2$ about the  $z$-axis by an angle $\\theta$ in the counter-clockwise direction. Describe the new surface as the graph of some function $f_{\\theta}(x,y)$. Find the second derivatives of $f_{\\theta}(x,y)$.\n\\end{ques}\n\n\n\n\n\n\n\\subsection{Rotations and Second Derivatives}\nWe need to understand how the second derivatives change when we rotate the $ xy$-plane about the $ z$-axis. There are two tricks to do this efficiently.\\footnote{In order to avoid clutter we'll stop writing the $ (p)$. All the derivatives are being taken at the critical point $p = (0,0)$.}\n\n\\begin{description}\n  \\item{\\bf Trick \\#1} Instead of analyzing the second derivatives we analyze the degree 2 Taylor polynomial\n  \\begin{align*}\n    2f(x,y) \\approx 2f(p) + f_{xx}\\cdot {x^2} + 2f_{xy} \\cdot {xy} + f_{yy} \\cdot {y^2}\n  \\end{align*}\n\n  \\item{\\bf Trick \\#2} We rewrite the degree 2 Taylor polynomial in matrix form\n  \\begin{align*}\n    2f(x,y)\n    &\\approx 2f(p) +\n    \\begin{bmatrix} x & y \\end{bmatrix}\n    \\begin{bmatrix}\n      f_{xx} & f_{xy} \\\\\n      f_{xy} & f_{yy}\n    \\end{bmatrix}\n    \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n  \\end{align*}\n\\end{description}\nThe rotation or the reflection of the $ xy$-plane about the $z$-axis is a linear transformation and hence can be described by some orthogonal matrix $ A$\n\\begin{align*}\n  \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n    &= A\n  \\begin{bmatrix} x' \\\\ y' \\end{bmatrix}\n\\end{align*}\nPlugging this in the right hand side of the Taylor polynomial we get\n\\begin{align}\n  \\nonumber\n  2f(x,y)\n  &\\approx 2f(p) + f_{xx}{x^2} + 2f_{xy} {xy} + f_{yy}{y^2} \\\\\n  \\nonumber\n  &= 2f(p) +\n  \\begin{bmatrix} x & y \\end{bmatrix}\n  \\begin{bmatrix}\n    f_{xx} & f_{xy} \\\\\n    f_{xy} & f_{yy}\n  \\end{bmatrix}\n  \\begin{bmatrix} x \\\\ y \\end{bmatrix} \\\\\n    \\label{eq:Hessian}\n    &= 2f(p) +\n    \\begin{bmatrix} x' & y' \\end{bmatrix} A^T\n    \\begin{bmatrix}\n      f_{xx} & f_{xy} \\\\\n      f_{xy} & f_{yy}\n    \\end{bmatrix}\n    A \\begin{bmatrix} x' \\\\ y' \\end{bmatrix}\n\\end{align}\nNotice that the right hand side is still quadratic, and not surprisingly this is \\textbf{the Taylor approximation of $ f$ in terms of $ (x',y')$}.\n\\begin{ques}\n  Let $A$ denote reflection of the $xy$-plane about the line $x=y$.\n  \\begin{enumerate}\n    \\item Express $A$ as a $2 \\times 2$ matrix.\n    \\item Expand the right hand side of \\eqref{eq:Hessian} for this $A$ and verify that this is indeed the degree 2 Taylor approximation in the new variables.\n  \\end{enumerate}\n\\end{ques}\n\\begin{ques}\n  Suppose that $A = \\begin{bmatrix} m & 0 \\\\ 0 & n \\end{bmatrix}$ where $m,n$ are non-zero real numbers. This linear transformation corresponds to scaling the $x,y$ axes by $m,n$ respectively. Expand the right hand side of \\eqref{eq:Hessian} for this $A$ and verify that this is indeed the degree 2 Taylor approximation in the new variables.\n\\end{ques}\n\\begin{definition}\n  The matrix $\\begin{bmatrix} f_{xx} & f_{xy} \\\\ f_{xy} & f_{yy} \\end{bmatrix}$ is called the \\textbf{Hessian} of $ f$, denoted $ \\hess(f)(x,y)$.\n\\end{definition}\n\\begin{thm}\n  \\label{thm:change_of_coords_Hessian}\n  At a critical point $p$, if the coordinates change according to the linear transformation $$\\begin{bmatrix} x \\\\ y \\end{bmatrix} = A \\begin{bmatrix} x' \\\\ y' \\end{bmatrix}$$ then the Hessian $ \\hess(f)$ changes as\n  \\begin{align}\n    \\label{eq:2-tensor}\n    \\begin{bmatrix}\n      f_{x'x'} & f_{x'y'} \\\\\n      f_{x'y'} & f_{y'y'}\n    \\end{bmatrix}\n      &=\n       A^T\n      \\begin{bmatrix}\n        f_{xx} & f_{xy} \\\\\n        f_{xy} & f_{yy}\n      \\end{bmatrix}\n      A\n  \\end{align}\n  We say that $\\hess(f)$ is a 2-tensor at a critical point.\n\\end{thm}\n\\begin{remark}\n  The assumption that we're at a critical point i.e. $ f_x = 0 = f_y$ is extremely crucial here and cannot be dropped. If, for example, we further had $ f_x = 0 = f_y$ and $ f_{xx} = 0 = f_{xy} = f_{yy}$ then we will get a similar change of coordinate rule for the third derivatives, which will be a 3-tensor.\n\\end{remark}\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{The Curvatures}\nThe Curvature(s) should be \\emph{invariants} of the matrix $ \\hess(f)$ which remain unchanged when we apply the transformation \\eqref{thm:change_of_coords_Hessian} where $ A$ is either a rotation or a reflection. When $A$ is one of these we further have $A^T = A^{-1}$ so that\n\\begin{align*}\n  \\begin{bmatrix}\n    f_{x'x'} & f_{x'y'} \\\\\n    f_{x'y'} & f_{y'y'}\n  \\end{bmatrix}\n    &=\n     A^{-1}\n    \\begin{bmatrix}\n      f_{xx} & f_{xy} \\\\\n      f_{xy} & f_{yy}\n    \\end{bmatrix}\n    A\n\\end{align*}\nWe say that $\\hess(f)(x,y)$ and $\\hess(f)(x',y')$ are {\\bf similar} or {\\bf conjugate} to each other i.e. they represent the same linear transformation. If two matrices represent the same linear transformation then they have the same \\emph{determinant} and \\emph{trace}.\n\\begin{ques}\n  Let $A$ be an $n\\times n$ matrix and let $P$ be an invertible $n \\times n$ matrix. Prove that\n  \\begin{align*}\n    \\det A = \\det (P A P^{-1}) \\mbox{ \\: and \\: }\\tr A = \\tr(P A P^{-1})\n  \\end{align*}\n\\end{ques}\nWe now have well defined notions of curvature which remain unchanged when we rotate or reflect the $xy$-plane.\n\\begin{definition}\n  If $ S$ is the graph of a smooth function $ f(x,y)$ satisfying $ f_x(p) = 0 = f_y(p)$ then\n  \\begin{enumerate}\n    \\item The \\textbf{Mean Curvature} of $ S$ at $ p$ is defined to be\n    \\begin{align*}\n      H = \\tr(\\hess(f))/2 = (f_{xx} + f_{yy})/2\n    \\end{align*}\n    \\item The \\textbf{Gaussian Curvature} of $ S$ at $ p$ is defined to be \\textbf{determinant}\n    \\begin{align*}\n      K = \\det(\\hess(f)) = f_{xx}f_{yy} - f_{xy}^2\n    \\end{align*}\n  \\end{enumerate}\n\\end{definition}\n\n\n\\begin{ques}\n  Go back to your computation in Question \\ref{ques:paraboloid} and verify that the Gaussian and Mean curvatures for $z=f_\\theta(x,y)$ do not depend on $\\theta$.\n\\end{ques}\n\n\\begin{ques}\n  For each of the following surfaces, find the second order Taylor polynomial, the Hessian, and the Mean and Gaussian curvatures at $(0,0)$.\n  \\begin{description}\n    \\item[The Perfect \\textbf{Potato Chip}: ]  $ z = x^2 - y^2 $\n    \\item[Cylindrical Potato: ] $z = -\\sqrt{r^2 - x^2} $\n    \\item[Spherical Potato: ] $z = -\\sqrt{r^2 - x^2 - y^2}$\n    \\item[Parabolic Cylinder: ] $z =  x^2$\n  \\end{description}\n  (You can use the estimate $-\\sqrt{r^2 - \\alpha} \\approx -r + \\frac{\\alpha}{2r} $. This is called the \\textbf{binomial approximation}.)\n\\end{ques}\n\n\\begin{remark}\n  Although we're only analyzing critical points of graphs of functions, we can always rotate $ \\R^3$ (which should not change curvatures) so that the surface looks like a graph near the point of interest, and the point becomes a critical point. As such, the above method defines curvature in all generality.\n\\end{remark}\n\n\\subsection{Appendix: Taylor approximation}\nTaylor polynomials are a way to approximate functions by polynomials.\n\\begin{definition}\n\tThe degree $ n$ \\textbf{Taylor approximation} of a function $ f: \\R \\rightarrow \\R$ at a point $ x=a$ is defined to be\n\t\\begin{align*}\n\t\tf(a) + \\dfrac{f'(a)}{1!} (x-a) + \\dfrac{f''(a)}{2!} (x-a)^2 + \\cdots + \\dfrac{f^{(n)}(a)}{n!} (x-a)^n\n\t\\end{align*}\n\twhere $f^{(n)}(a)$ denotes the $ n^{th}$ derivative of $ f$ at $ a$.\n\\end{definition}\nWe're only interested in the degree 2 approximation at $ x=0$ i.e. $$ f(x)\n\t\\approx f(0) + f'(0) x + f''(0) \\frac{x^2}{2}$$\nThis generalizes to functions in multiple variables easily.\n\\begin{definition}\n\tThe degree 2 or \\textbf{second order Taylor approximation} of a function $ f: \\R^2 \\rightarrow \\R$ at the point $ p=(0,0)$ is defined to be\n\t\\begin{align*}\n\t\tf(x,y) \\approx f(p) + f_x(p)\\cdot x + f_y(p)\\cdot y + f_{xx}(p)\\cdot \\frac{x^2}{2} + f_{xy}(p) \\cdot xy + f_{yy}(p)\\cdot \\frac{y^2}{2}\n\t\\end{align*}\n\twhere $f_{*}(p)$ denotes the partial derivatives.\\footnote{$f_{xy}$ has coefficient 1 instead of $1/2$ as it is secretly a sum of two terms $f_{xy}$ and $f_{yx}$ which happen to be equal for all twice differential functions.}\n\\end{definition}\n\\begin{ques}\n\tIf $ f(x,y)$ is polynomial in 2 variables $x,y$ find it's the second order Taylor approximation at $(0,0)$.\n\\end{ques}\n\\begin{ques}\n  Let $T_2(f)$ denote the degree 2 Taylor approximation of $f$ at $(0,0)$. Let $P$ denote the vector space of smooth functions $\\R^2 \\rightarrow \\R$ and let $P_2$ denote the vector space of polynomials of degree $\\le 2$ with real coefficients.\n  \\begin{enumerate}\n    \\item Show that $T_2$ defines a linear transformation $P \\rightarrow P_2$.\n    \\item Further show that $T_2(T_2(f)) = T_2(f)$.\n  \\end{enumerate}\n\\end{ques}\nLinear transformations $L$ which satisfy $L \\circ L = L$ are called \\textbf{projections}, and thus taking the degree 2 Taylor approximation is like projecting onto the space of degree 2 polynomials.\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Appendix: Orthogonal Transformations}\n\\begin{ques}$ $\n  \\begin{enumerate}\n    \\item Prove that every rotation of $\\R^2$ about the origin is given by a linear transformation of the form\n    \\begin{align*}\n      \\begin{bmatrix}\n        \\cos \\theta & -\\sin \\theta \\\\\n        \\sin \\theta & \\cos \\theta\n      \\end{bmatrix}\n    \\end{align*}\n    \\item Prove that every reflection of $\\R^2$ about a line passing through the origin is given by a linear transformation of the form\n    \\begin{align*}\n      \\begin{bmatrix}\n        -\\cos \\theta & \\sin \\theta \\\\\n        \\sin \\theta & \\cos \\theta\n      \\end{bmatrix}\n    \\end{align*}\n    \\item Prove that both reflections and rotations satisfy\n    \\begin{align*}\n      A^{-1} = A^T\n    \\end{align*}\n    \\item Show that if $A$ is a $2 \\times 2$ matrix satisfying $A^{-1} = A^T$ then $A$ is either a rotation or a reflection.\n  \\end{enumerate}\n\\end{ques}\nIn higher dimensions it is difficult to give explicit descriptions of rotations and reflections, instead we define \\textbf{orthogonal matrices} to be the ones that satisfy $A^{-1} = A^T$. It is easy to show that orthogonal matrices preserve distances and angles and hence are the correct generalizations of rotations and reflections.\n", "meta": {"hexsha": "675172fed35a10ce06f8c0ed2cdda00afb9c84d3", "size": 12670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02.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": "02.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": "02.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": 46.0727272727, "max_line_length": 457, "alphanum_fraction": 0.6741120758, "num_tokens": 3992, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.731058578630005, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.6242602393701081}}
{"text": "\\section{Point Estimation}\n\n\\begin{definition}[Point Estimator]\n    A \\emph{point estimator} is any function $W(X_1, \\dots, X_n)$ of a sample; that is, any statistic is a point estimator. An \\emph{estimate} is a realised value $w(x_1, \\dots, x_n)$.\n\\end{definition}\n\nNote that there is the implicit restriction that the estimator is not a function of the parameter you are trying to estimate.\n\n\\subsection{Methods of Finding Estimators}\n\n\n\\subsubsection{Method of Moments}\nThe method of moments is performed using a random sample $X_1, \\dots, X_n$ from a population with unknown parameters $\\theta_1, \\dots, \\theta_k$ by computing the first $k$ empirical moments $m_k = \\frac{1}{n}\\sum_{i=1}^nX_i^k$ and matching them with the corresponding moments of the population $\\mu_k' = \\E{}[X^t]$. \n\\begin{align*}\n    m_1 &= \\mu_1'(\\theta_1, \\dots, \\theta_k)\\\\\n        &\\vdotswithin{=} \\\\\n    m_k &= \\mu_k' (\\theta_1, \\dots, \\theta_k)\n\\end{align*}   \nFrom this you get $k$ simultaneous equations that you can use to solve for the parameters of the population.\n\n\n\\subsubsection{Maximum Likelihood Estimators}\n\\begin{definition}[Maximum Likelihood Estimator]\n    For each sample point $\\vec{x}$, let $\\hat{\\theta}(\\vec{x})$ be a parameter value at which the likelihood $L(\\theta \\vert{} \\vec{x})$ attains its maximum as a function of $\\theta$, with $\\vec{x}$ held fixed. A \\emph{maximum likelihood estimator} (MLE) of the parameter $\\theta$ based on a sample $\\vec{X}$ is $\\hat{\\theta}(\\vec{X})$.\n\\end{definition}\n\nSuppose we want to find the MLE for some function of the parameter $\\tau(\\theta)$.\n\n\\begin{definition}[Induced Likelihood]\n    Given some function of the parameter $\\tau(\\theta)$, we define the \\emph{induced likelihood function} $L^*$ by\n    \\[\n        L^*(\\eta \\vert{} \\vec{x}) = \\sup_{\\theta : \\tau(\\theta) = \\eta} L(\\theta \\vert{} \\vec{x}).\n    \\]\n    The value $\\hat{\\eta}$ that maximises $L^*(\\eta \\vert{} \\vec{x})$ will be called the MLE of $\\eta = \\tau(\\theta)$. It can be seen that the maxima of $L^*$ and $L$ coincide.\n\\end{definition}\n\n\\begin{theorem}[Invariance Property of MLEs]\n    IF $\\hat{\\theta}$ is the MLE of $\\theta$, then for any function $\\tau(\\theta)$, the MLE of $\\tau(\\theta)$ is $\\tau(\\hat{\\theta})$.\n\\end{theorem}\n\n\\begin{remark}\n    \\mbox{}\n    \\begin{enumerate}[1)]\n        \\item The MLE can be an unstable function of the data.\n        \\item When verifying maxima for multi-dimensional problems try to avoid going down the hessian route, which can be tedious.\n    \\end{enumerate}\n\\end{remark}\n\n\\subsubsection{Bayes Estimators}\nIf we denote the prior distribution by $\\pi(\\theta)$ and the sampling distribution by $f(\\vec{x} \\vert{} \\theta)$, then the posterior distribution of $\\theta$ given the sample $\\vec{x}$ is\n    \\[\n        \\pi(\\theta \\vert{} \\vec{x}) = \\frac{f(\\vec{x}\\vert{}\\theta)\\pi(\\theta)}{m(\\vec{x})},\n    \\]\n    where $m(\\vec{x})$ is the marginal distribution of the sample $\\vec{X}$\n    \\[\n        m(\\vec{x}) = \\int f(\\vec{x}\\vert{}\\theta) \\pi(\\theta) \\d{}\\theta.\n    \\]\n    \n\\begin{definition}[Conjugate Priors]\n    Let $\\mathcal{F}$ denote the class of pdfs/pmfs $f(\\vec{x} \\vert{} \\theta)$ (indexed by $\\theta$). A class $\\Pi$ of prior distribution is a \\emph{conjugate family} for $\\mathcal{F}$ if, $\\forall f \\in \\mathcal{F}$, $\\forall \\, \\text{priors} \\in \\mathcal{F}$ and $\\forall \\vec{x} \\in \\X{}$, the posterior distribution is in $\\Pi$.\n\\end{definition}\n\nNote that this relation is not said to be symmetric.\n\n\\begin{remark}[Some Examples]\n    \\mbox{}\n    \\begin{itemize}\n        \\item $\\n{}$ is self-conjugate as a family.\n        \\item Beta distribution is conjugate to binomial.\n    \\end{itemize}\n\\end{remark}\n\n\n\\subsection{Methods of Evaluating Estimators}\n\n\\begin{definition}[Mean Squared Error]\n    The \\emph{mean squared error} (MSE) of an estimator $W$ of a parameter $\\theta$ is defined by $\\E{}[(W - \\theta)^2]$.\n\\end{definition}\n\n\\begin{lemma}[Bias-Variance Decomposition]\n    \\[\n        \\E{}[(W - \\theta)^2] = \\Var{}[W] + (\\E{}[W] - \\theta)^2 = \\Var{}[W] + \\text{Bias}[W]^2\n    \\]\n\\end{lemma}\n\n\\begin{definition}[Bias]\n    The \\emph{bias} of a point estimator $W$ of a parameter $\\theta$ is given by\n    \\[\n        \\text{Bias}[W] = \\E{}[W] - \\theta.\n    \\]\n    An estimator whose bias is 0 is called an \\emph{unbiased estimator} and has $\\E{}[W] = \\theta$ $\\forall \\theta$.\n\\end{definition}\n\n\\begin{remark}\n    \\mbox{}\n    \\begin{itemize}\n        \\item Clearly, if an estimator is unbiased, then its MSE is equal to its variance.\n        \\item The MSE makes sense for location parameters but not so much for scale parameters, since it is symmetric and scale parameters have a natural floor at 0.\n        \\item The MSE may be a function of the thing you're trying to estimate. So which estimator you choose as being the `best' may depend on the range you expect the parameter to lie within.\n    \\end{itemize}\n\\end{remark}\n\n\\subsubsection{Best Unbiased Estimators}\n\n\\begin{definition}[Best Unbiased Estimator]\n    An estimator $W^*$ is \\emph{best unbiased estimator} of of $\\tau(\\theta)$ if it satisfies $\\E{}[W^*] = \\tau(\\theta) \\,\\, \\forall \\theta$, and for any other estimator with $\\E{}[W] = \\tau(\\theta) \\,\\, \\forall \\theta$ we have $\\Var{}[W*] \\leq \\Var{}[W] \\,\\, \\forall \\theta$. We also call $W^*$ the \\emph{uniform minimum variance unbiased estimator} (UMVUE) of $\\tau(\\theta)$.\n\\end{definition}\n\n\\begin{remark}\n    Suppose that we are trying to estimate $\\theta$ and consider the class of estimators\n    \\[\n        \\mathcal{C}_\\tau = \\{W: \\E{}[W] = \\tau(\\theta)\\}.\n    \\]\n    All estimators in this class have the same bias, so we can compare their MSEs by comparing their variances alone. (So the best estimator in this class is just the minimum variance one.) This means that the considerations of this chapter can be applied to classes like $\\mathcal{C}_\\tau$, even if $\\tau(\\theta) \\neq \\theta$.\n\\end{remark}\n\nThe best unbiased estimator, if it exists, could be hard to find. The following lower bound at least gives a stopping criterion to our search.\n \n\\begin{theorem}[Cram\\'{e}r-Rao Inequality]\n    Let $X_1, \\dots, X_n$ be a sample with pdf $f(\\vec{x}\\vert{}\\theta)$ and let $W(\\vec{X}) = W(X_1, \\dots, X_n)$ be any estimator with finite variance satisfying\n    \\[\n        \\frac{\\d{}}{\\d{} \\theta} \\E{}[W(\\vec{X})] = \\int_{\\X{}} \\frac{\\pd{}}{\\pd{} \\theta} \\left(W(\\vec{x}) f(\\vec{x}\\vert{}\\theta) \\right)\\d{}\\vec{x}.\n    \\]\n    Then\n    \\[\n        \\Var{}[W(\\vec{X})] \\geq \\frac{\\left(\\frac{\\d{}}{\\d{} \\theta} \\E{}[W(\\vec{X})] \\right)^2}{\\E{}\\left[ \\left(\\frac{\\pd{}}{\\pd{} \\theta} \\log f(\\vec{X} \\vert{} \\theta) \\right)^2 \\right]}.\n    \\]\n\\end{theorem}\n\nThe proof of this considers the correlation between the gradient of the log likelihood and the statistic. Note that the sample in the above theorem is not necessarily iid.\n\n\\begin{remark}\n    This hold for discrete distributions too, replacing integrals with sums.\n\\end{remark}\n\n\\begin{corollary}\n    If the random sample $\\X_1, \\dots, X_n$ is iid then the result becomes\n    \\[\n        \\Var{}[W(\\vec{X})] \\geq \\frac{\\left(\\frac{\\d{}}{\\d{} \\theta} \\E{}[W(\\vec{X})] \\right)^2}{n\\E{}\\left[ \\left(\\frac{\\pd{}}{\\pd{} \\theta} \\log f(X \\vert{} \\theta) \\right)^2 \\right]}.\n    \\]\n\\end{corollary}\n\n\\begin{definition}[Fisher Information]\n    The quantity $\\E{}\\left[ \\left(\\frac{\\pd{}}{\\pd{} \\theta} \\log f(\\vec{X} \\vert{} \\theta) \\right)^2 \\right]$ is called the \\emph{Fisher Information} of the sample $\\vec{X}$.\n\\end{definition}\n\n\\begin{lemma}\n    If $f(x \\vert{} \\theta)$ satisfies\n    \\[\n        \\frac{\\d{}}{\\d{} \\theta} \\E{}\\left[ \\frac{\\pd}{\\pd \\theta} \\log f(X \\vert{} \\theta) \\right] = \\int \\frac{\\pd}{\\pd \\theta} \\left[ \\left( \\frac{\\pd}{\\pd \\theta} \\log f(x \\vert{} \\theta) \\right) f(x \\vert{} \\theta) \\right] \\d{}x\n    \\]\n    (as is true for an exponential family), then the Fisher information can be written\n    \\[\n        \\E{}\\left[ \\left(\\frac{\\pd{}}{\\pd{} \\theta} \\log f(X \\vert{} \\theta) \\right)^2 \\right] = - \\E{}\\left[ \\frac{\\pd^2}{\\pd \\theta^2} \\log f(X \\vert{} \\theta) \\right].\n    \\]\n\\end{lemma}\n\n\\begin{remark}\n    Even if the Cram\\'{e}r-Rao bound is applicable, it may not be sharp -- there may not be an estimator that attains this bound.\n\\end{remark}\n\n\\begin{lemma}[Attainment]\n    Let $X_1, \\dots, X_n$ be iid $X \\sim f(x \\vert{} \\theta)$, where $f(x \\vert{} \\theta)$ satisfies the conditions of the Cram\\'{e}r-Rao Theorem. Let $L(\\theta \\vert{} \\vec{x}) = \\prod_{i=1}^n f(x_i \\vert{} \\theta)$ denote the likelihood function. If $W(\\vec{X})$ is any unbiased estimator of $\\tau(\\theta)$ then $W(\\vec{X})$ attains the Cram\\'{e}r-Rao lower bound if and only if $\\exists a(\\theta)$ such that\n    \\[\n        a(\\theta) [W(\\vec{X}) - \\tau(\\theta)] = \\frac{\\pd}{\\pd \\theta} \\log L(\\theta \\vert{} \\vec{x}).\n    \\]\n\\end{lemma}\n\n\\subsubsection{Sufficiency and Unbiasedness}\n\n\\begin{theorem}[Rao-Blackwell]\n    Let $W$ be any unbiased estimator of $\\tau(\\theta)$ and let $T$ be a sufficient statistic for $\\theta$. Define $\\phi(T) = \\E{}[W \\vert{} T]$. Then $\\E{}[\\phi(T)] = \\tau(\\theta)$ and $\\Var{}[\\phi(T)] \\leq \\Var{}[W] \\,\\, \\forall \\theta$. That is, $\\phi(T)$ is a \\emph{uniformly better unbiased estimator} of $\\tau(\\theta)$.\n\\end{theorem}\n\n\\begin{remark}\n    \\mbox{}\n    \\begin{itemize}\n        \\item Conditioning on any unbiased estimator on a sufficient statistic will result in a uniform improvement, so we need consider only functions of a sufficient statistic when looking for best unbiased estimators.\n        \\item The proof doesn't require that the statistic we condition on is sufficient, but if it isn't then the resulting quantity will probably depend on the parameter we are trying to estimate.\n    \\end{itemize}\n\\end{remark}\n\n\\begin{theorem}\n    If $W$ is a best unbiased estimator of $\\tau(\\theta)$ then $W$ is unique.\n\\end{theorem}\n\nThe following theorem is mostly useful to show that a given estimator \\emph{isn't} best unbiased.\n\n\\begin{theorem}\n    If $\\E{}[W] = \\tau(\\theta)$, then $W$ is the best unbiased estimator of $\\tau(\\theta)$ if and only if $W$ is uncorrelated with all unbiased estimators of 0.\n\\end{theorem}\n\nThe idea comes from considering $\\phi_a = W + aU$ where $\\E{}[U] = 0$, then considering the variance.\n\n\\begin{remark}[Unbiased estimator of 0]\n    Note that an unbiased estimator of 0 is simply noise (one should estimate 0 with 0). If an estimator can be improved by adding noise, then it is probably defective.\n\\end{remark}\n\nWe are now in a position such that, if we can characterise all of the unbiased estimators of 0 then we can check if a given estimator is best unbiased. In general this is not easy and requires conditions on the distribution. However, if a distribution is complete then it admits no unbiased estimators of 0 other than 0 itself (by definition), so we will be done.\\\\\n\nNote that due to the Rao-Blackwell theorem, only the distribution of the sufficient statistic needs to be complete (not the underlying population distribution).\n\n\\begin{theorem}\n    Let $T$ be a complete sufficient statistic for a parameter $\\theta$ and let $\\phi(T)$ be any estimator based only on $T$. Then $\\phi(T)$ is the unique best unbiased estimator of its expected value.\n\\end{theorem}\n\n\\begin{theorem}[Lehmann-Scheff\\'{e}]\n    Unbiased estimators based on complete sufficient statistics are unique.\n\\end{theorem}\n\n", "meta": {"hexsha": "db73b96e5edae0450cda4b1d1617030549c2b0ba", "size": 11309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter7/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/chapter7/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/chapter7/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": 53.5971563981, "max_line_length": 410, "alphanum_fraction": 0.6655760898, "num_tokens": 3411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110202, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6242602375167163}}
{"text": "\\section{Orthogonal Matching Pursuit}\n\\label{JM:sec:GOMP}\n\nIn the following section, preconditioned generalized orthogonal matching pursuit (GOMP) \\cite{JMTongEtAl2020} will be implemented.\nMatching pursuit algorithms are a class of greedy algorithms designed to solve the sparse signal recovery problem\n\n\\begin{equation}\n\\begin{aligned}\n    \\min_x \\quad & \\left\\lVert x \\right\\rVert_0 \\\\\n    \\textrm{s.t.} \\quad & y = \\Psi x\n\\end{aligned}\n\\end{equation}\n\nwhere $x \\in \\mathbb{R}^n$ represents an unknown, $K$ sparse basis for a signal $y \\in \\mathbb{R}^m$ in $\\Psi \\in \\mathbb{R}^{m \\times n}$, also called the sampling matrix.\nThis is done by iteratively reducing the estimation error of the recovered signal by selecting $S$ most similar, new components from the sampling matrix.\\\\\n\nThe main algorithm can be described as follows\n\n\\begin{algorithm}[H]\n    \\SetAlgoLined\n    \\KwResult{$x$}\n    \\KwData{$y$, $\\Psi$, $K$, $S = 1$}\n    Projection onto span\\; \n    $P = \\Psi^T \\left(\\Psi\\Psi^T\\right)$;\n    $\\tilde{y} = P y$;\n    $\\tilde{\\Psi} = P \\Psi$\\;\n    Initialize residual and support\\;\n    $r = y$;\n    $\\Lambda = \\emptyset$\\;\n    \\While{Not converged}{\n        $\\Omega = \\delta_S\\left( \\left| \\tilde{\\Psi}^T~r \\right| \\right)$\\;\n        $\\Lambda = \\Lambda \\cup \\Omega$\\;\n        $x = \\min \\left\\lVert \\tilde{y} - \\tilde{\\Psi}u \\right\\rVert_2~, \\quad supp(u) = \\Lambda$\\;\n        $r = \\tilde{y} - \\tilde{\\Psi} x$\\;\n    };\n\\end{algorithm}\n\nHere $\\delta_S\\left( x \\right) : \\mathbb{R}^n \\mapsto \\lbrace 0, 1 \\rbrace^n$ denotes (with abuse of notation) the mapping of the $S$ largest elements onto a corresponding\nindicator vector. A similar notation to the pseudocode above can be achieved in \\textit{Julia}. For brevity, only necessary elements of the source code will be shown, which can be found in detail in REF. The function is defined as follows\n\n\\lstinputlisting[language=Julia,firstline=4, lastline=6]{../scripts/gomp.jl}\n\nFirst, we will focus on the preconditioning via the matrix $P \\in \\mathbb{R}^{m \\times m}$ mapping onto the\ncolumn span of $\\Psi$\n\n\\lstinputlisting[language=Julia,firstline=22, lastline=26]{../scripts/gomp.jl}\n\nNext, the iterative computation of the support, corresponding coefficients and residuals is performed\n\n\\lstinputlisting[language=Julia,firstline=37, lastline=50]{../scripts/gomp.jl}\n\nAs can be seen from above, the implementation is quite similar to its mathematical counterpart, enhancing the interpretability and readability. \nThe results of the algorithm are shown in Fig. \\ref{JM:fig:GOMP}, where a 100 dimensional sparse vector $x$ has been recovered.\n\n\\begin{figure}\n    \\includegraphics[width = 0.9\\textwidth]{../figures/merged.pdf}\n    \\caption{Performance of GOMP for a single sparse 100 dimensional vector (left) and with different sparsities (right). The signal $y$ is of dimension 300 and has been generated by a random dense sampling matrix.\n    GOMP has been used with $K=50, S=1$ and run for at most 100 iterations with a absolute tolerance $\\epsilon = 0.1$.}\n    \\label{JM:fig:GOMP}\n\\end{figure}\n\n\\newpage", "meta": {"hexsha": "4dfcfff95924658d8d5d21822415a25238f2a691", "size": 3066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/contents/04_matching.tex", "max_stars_repo_name": "AlCap23/ScientificComputingSeminar2021", "max_stars_repo_head_hexsha": "1adf9984f2948d3b990036ffb616fd1b2ffc2ae6", "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/contents/04_matching.tex", "max_issues_repo_name": "AlCap23/ScientificComputingSeminar2021", "max_issues_repo_head_hexsha": "1adf9984f2948d3b990036ffb616fd1b2ffc2ae6", "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/contents/04_matching.tex", "max_forks_repo_name": "AlCap23/ScientificComputingSeminar2021", "max_forks_repo_head_hexsha": "1adf9984f2948d3b990036ffb616fd1b2ffc2ae6", "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.4516129032, "max_line_length": 238, "alphanum_fraction": 0.7106979778, "num_tokens": 902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6242328111252828}}
{"text": "\\chapter{Sort}\n\n\n\\section{Introduction}\nList of general algorithms:\n\\begin{enumerate}\n\\item Selection sort: invariant\n\\begin{enumerate}\n\\item Elements to the left of $i$ (including $i$) are fixed and in ascending order (fixed and sorted).\n\\item No element to the right of $i$ is smaller than any entry to the left of $i$ ($A[i]  \\leq\\min(A[i+1:n])$.\n\\end{enumerate}\n\\item Insertion sort: invariant\n\\begin{enumerate}\n\\item Elements to the left of $i$ (including $i$) are in ascending order (sorted).\n\\item Elements to the right of $i$ have not yet been seen.\n\\end{enumerate}\n\\item Shell sort: h-sort using insertion sort.\n\\item Quick sort: invariant\n\\begin{enumerate}\n\\item $|A_p|..\\leq..|..unseen..|..\\geq..|$ maintain the 3 subarrays.\n\\end{enumerate}\n\\item Heap sort: compared to quick sort it is guaranteed $O(n \\lg n)$, compared to merge sort it is $O(1)$ extra space. \n\\end{enumerate}\n\n\\section{Algorithms}\n\\subsection{Quick Sort}\n\\subsubsection{Normal pivoting}\\label{section:pivot}\nThe key part of quick sort is pivoting:\n\\newpage\n\\begin{python}\ndef pivot(self, A, lo, hi):\n    \"\"\"\n    pivoting algorithm:\n    | p | closed set | open set |\n    | closed set | p | open set |\n    \"\"\"\n    p = lo\n    closed = p\n    for i in xrange(lo, hi):\n        if A[i] < A[p]:\n            closed += 1\n            A[i], A[closed] = A[closed], A[i]\n\n    A[closed], A[p] = A[p], A[closed]\n    return closed\n\\end{python}\n\nNotice that this implementation goes $O(N^2)$ for arrays with all duplicates.\n\n\\textbf{Problem with duplicate keys}: it is important to stop scan at duplicate\nkeys (counter-intuitive); otherwise quick sort will goes $O(N^2)$ for the\narray with all duplicate items, because the algorithm will put all items\nequal to the $A[p]$ on \\textbf{a single side}. \n\nExample: quadratic time to sort random arrays of 0s and 1s.\n\n\\subsubsection{Stop-at-equal pivoting}\nAlternative pivoting implementation with optimization for duplicated keys:\n\\begin{python}\ndef pivot_optimized(self, A, lo, hi):\n    \"\"\"\n    Fix the pivot as the 1st element\n    Scan from left to right and right to left simultaneously\n    Avoid the case that the algo goes O(N^2) with duplicated keys\n    \"\"\"\n    p = lo\n    i = lo\n    j = hi\n    while True:\n        while True:\n            i += 1\n            if i >= hi or A[i] >= A[lo]:\n                break\n        while True:\n            j -= 1\n            if j < lo or A[j] <= A[lo]:\n                break\n\n        if i >= j:\n            break\n\n        A[i], A[j] = A[j], A[i]\n\n    A[lo], A[j] = A[j], A[lo]\n    return j\n\n\\end{python}\n\\subsubsection{3-way pivoting}\nThis problem is also known as \\textit{Dutch national flag problem}.\n\n3-way pivoting: pivot the array into 3 subarrays: \n\n$$|..\\leq..|..=..|..unseen..|..\\geq..|$$\n\\begin{python}\ndef pivot_3way(self, A, lo, hi):\n    lt = lo-1  # pointing to end of array LT\n    gt = hi  # pointing to the end of array GT (reversed)\n\n    v = A[lo]\n    i = lo  # scanning pointer\n    while i < gt:  # not n or hi\n        if A[i] < v:\n            lt += 1\n            A[lt], A[i] = A[i], A[lt]\n            i += 1\n        elif A[i] == v:\n            i += 1\n        else:\n            gt -= 1\n            A[gt], A[i] = A[i], A[gt]\n\n    return lt, gt\n\\end{python}\n\\subsection{Merge Sort}\n\\begin{figure}[!htp]\n\\centering\n\\subfloat{\\includegraphics[scale=.80]{msort}}\n\\caption{Merge Sort}\n\\label{fig:msort}\n\\end{figure}\n\\runinhead{Normal merge} Normal merge sort with extra space\n\\begin{python}\ndef merge_sort(self, A):\n  if len(A) <= 1:\n    return\n\n  mid = len(A)/2\n  L, R = A[:mid], A[mid:]\n  self.merge_sort(L)\n  self.merge_sort(R)\n\n  i, j, k = 0, 0, 0\n  while i < len(L) and j < len(R):\n    if L[i] < R[j]:\n      A[k] = L[i]\n      i += 1\n    else:\n      A[k] = R[j]\n      j += 1\n    k += 1\n\n  if i < len(L):\n    A[k:] = L[i:]\n  if j < len(R):\n    A[k:] = R[j:]\n\\end{python}\n\n\\runinhead{Merge backward.} Merge two arrays in place of one of the arrays.  \n\\begin{python}\ndef merge(self, A, m, B, n):\n  \"\"\"\n  Arrays in asc order.\n  Assume A has enough space.\n  CONSTANT SPACE: starting backward. \n  \"\"\"\n  i = m-1\n  j = n-1\n  closed = m+n\n\n  while i >= 0 and j >= 0:\n    closed -= 1\n    if A[i] > B[j]:\n      A[closed] = A[i]\n      i -= 1\n    else:\n      A[closed] = B[j]\n      j -= 1\n\n  # either-or\n  # dangling\n  if j >= 0: A[:closed] = B[:j+1]\n  # if i >= 0: A[:closed] = A[:i+1]\n\\end{python}\n\\runinhead{In-place merge}\nIn-place merge sort of array without recursive. The basic idea is to avoid the recursive call while using iterative solution.\n\nThe algorithm first merge chunk of length of 2, 4, 8 ... until $2^k$ where $2^k$ is large than the length of the array.\n\\begin{python}\ndef merge_sort(self, A):\n  n = len(A)\n  l = 1\n  while l <= n:\n    for i in range(0, n, l*2):\n      lo, hi = i, min(n, i+2*l)\n      mid = i + l\n      p, q = lo, mid\n      while p < mid and q < hi:\n        if A[p] < A[q]:\n          p += 1\n        else:\n          tmp = A[q]\n          A[p+1:q+1] = A[p:q]\n          A[p] = tmp\n          p, mid, q = p+1, mid+1, q+1\n\n    l *= 2\n\n  return A\n\\end{python}\nThe time complexity may be degenerated to $O(n^2)$. \n\\subsection{Do something while merging}\nDuring the merging, the left half and the right half are both sorted; therefore, we can carry out operations like:\n\\begin{enumerate}\n\\item inversion count \n\\item range sum count \n\\end{enumerate}\n\n\\runinhead{Count of Range Sum.} Make an array $A$ of sums, where \\pyinline{A[i] = sum(nums[:i])}; and then feed to merge sort. Since both the left half and the right half are sorted, we can diff $A$ in $O(n)$ time to find range sum. \n\n\\begin{python}\ndef msort(A, lo, hi):\n  if hi - lo <= 1: return 0\n\n  mid = (lo + hi)/2\n  cnt = msort(A, lo, mid) + msort(A, mid, hi)\n\n  temp = []\n  i = j = r = mid\n  for l in xrange(lo, mid):\n    # range count\n    while i < hi and A[i] - A[l] <  LOWER: i += 1\n    while j < hi and A[j] - A[l] <= UPPER: j += 1\n    cnt += j - i\n\n    # normal merge \n    while r < hi and A[r] < A[l]:\n      temp.append(A[r])\n      r += 1\n\n    temp.append(A[l])\n\n  while r < hi:  # dangling right\n    temp.append(A[r])\n    r += 1\n\n  A[lo:hi] = temp\n  return cnt\n\\end{python}\n\nHere, the implementation of merge sort use: 1 for-loop for the left half and 2 while-loop for the right half.\n\n\\section{Properties}\n\\subsection{Stability}\nDefinition: a stable sort preserves the \\textbf{relative order of items with equal keys} (scenario: sorted by time then sorted by location). \n\nAlgorithms:\n\\begin{enumerate}\n\\item Stable\n\\begin{enumerate}\n\\item Merge sort\n\\item Insertion sort\n\\end{enumerate} \n\\item Unstable\n\\begin{enumerate}\n\\item Selection sort\n\\item Shell sort\n\\item Quick sort\n\\item Heap sort\n\\end{enumerate}\n\\end{enumerate}\n\\textbf{Long-distance swap} operation is the key to find the unstable case during sorting. \n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.50]{stable_sort}}\n\\caption{Stale sort vs. unstable sort}\n\\label{fig:trie} \n\\end{figure}\n\n\\subsection{Sorting Applications}\n\\begin{enumerate}\n\\item Sort\n\\item Partial quick sort (selection), k-th largest elements \n\\item Binary search\n\\item Find duplicates \n\\item Graham scan\n\\item Data compression\n\\end{enumerate}\n\n\\subsection{Considerations}\n\\begin{enumerate}\n\\item Stable?\n\\item Distinct keys?\n\\item Need guaranteed performance?\n\\item Linked list or arrays?\n\\item Caching system? (reference to neighboring cells in the array? \n\\item Usually randomly ordered array?\n(or partially sorted?)\\item Parallel?\n\\item Deterministic?\n\\item Multiple key types?\n\\end{enumerate}\n\n$O(N\\lg N)$ is the lower bound of comparison-based sorting; but for other\ncontexts, we may not need $O(N \\lg N)$:\n\\begin{enumerate}\n\\item Partially-ordered arrays: insertion sort to achieve $O(N)$. \\textbf{Number of inversions}: 1 inversion $=$ 1 pair of keys that are out\nof order.\n\\item Duplicate keys\n\\item Digital properties of keys: radix sort to achieve $O(N)$.\n\\end{enumerate}\n\n\\subsection{Sorting Summary}\nSee Figure \\ref{fig:sortSummary}.\n\\begin{figure*}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=1.2]{sort_summary}}\n\\caption{Sort summary}\n\\label{fig:sortSummary} \n\\end{figure*}\n\\section{Partial Quicksort}\n\\subsection{Find $k$ smallest}\n\\runinhead{Heap-based solution.} $O(n \\log k)$\n\nVersion 1, construct heap with $n$ numbers, and take $k$: $O(n+k\\log n)$, where $O(n)$ is for constructing heap. \n\nVersion 2. construct heap with $k$ numbers, and iterate $n$: $O(k+n\\log k)$. \n\nThe 2nd version is much master than 1st based on emperical analysis; additionally, it has smaller memory impact. \n\nIn python there are:\n\\begin{python}\nheapq.nlargest(n, iterable[, key])\nheapq.nsmallest(n, iterable[, key])\n\\end{python}\n\n\\newpage\n\\runinhead{Partial Quicksort}  Then the $A[:k]$ is sorted $k$ smallest. The algorithm recursively sort the $A[lo:hi]$\n\nThe average time complexity is\n\\begin{eqnarray*}\nF(n) = \\left\\{ \\begin{array}{rl}\n  F(\\frac{n}{2})+O(n) &\\mbox{// if $\\frac{n}{2} \\geq k$} \\\\\n  2F(\\frac{n}{2})+O(n) &\\mbox{// otherwise}\n       \\end{array} \\right.\n\\end{eqnarray*}\nTherefore, the complexity is $O(n+k \\log k)$.\n\\begin{python}\ndef partial_qsort(self, A, lo, hi, k):\n    if lo >= hi: return\n\n    p = self.pivot(A, lo, hi)\n    self.partial_qsort(A, lo, p, k)\n    if k <= p+1: return\n    self.partial_qsort(A, p+1, hi, k)\n\\end{python}\nThe partial quick sort will find the $k$ smallest number in sorted order. If the top $k$ elements are not required to be sorted, then use find $k$-th algorithm \n\n\\subsection{Find $k$-th: Quick Select}\nUse partial quick sort to find $k$-th smallest element in the unsorted array. The algorithm recursively sort the $A[lo:hi]$\n\nThe average time complexity is\n\\begin{align*}\nF(n) &= F(n/2) + O(n) \\\\\n&= O(n)\n\\end{align*}\n\nFind $k$-th with 2-way partitioning\n\\begin{python}\ndef find_kth(self, A, lo, hi, k):\n    if lo >= hi: return\n    \n    p = self.pivot(A, lo, hi)\n    if k == p: return p\n    if k < p:  return self.find_kth(A, lo, p, k)\n    else:      return self.find_kth(A, p+1, hi, k)\n\\end{python}\nFind $k$-th with 3-way partitioning. Pay attention to the indexing. $lt$, $gt$ means the last index of less-than portion and larger-than partion. \n\\begin{python}\ndef find_kth(self, A, lo, hi, k):\n    if lo >= hi: return\n\n    lt, gt = self.pivot(A, lo, hi)\n    if lt < k < gt: return k\n    if k <= lt: return self.find_kth(A, lo, lt+1, k)\n    else:       return self.find_kth(A, gt, hi, k)\n\\end{python}\n\nPivoting see section - \\ref{section:pivot}.\n\n\\runinhead{Find $k$-th in union of two sorted array.} Given sorted two arrays $A, B$, find the $k$-th element (0 based index).\n\nCore clues:\n\\begin{enumerate}\n\\item To reduce the complexity of $O(\\log (m+n))$, need to half the arrays.\n\\item Decide which half of the array to disregard. \n\\item Decide whether to disregard the median (i.e. boundary point).\n\\end{enumerate}\n\\begin{python}\ndef find_kth(self, A, B, k):\n  if not A:  return B[k]\n  if not B:  return A[k]\n  if k == 0: return min(A[0], B[0])\n\n  m, n = len(A), len(B)\n  if A[m/2] >= B[n/2]:\n    if k > m/2 + n/2:\n      return self.find_kth(A, B[n/2+1:], k-n/2-1)  # exclude median\n    else:\n      return self.find_kth(A[:m/2], B, k)  # exclude median\n  else:\n    return self.find_kth(B, A, k)  # swap\n\\end{python}\n\\subsection{Applications}\n\\runinhead{Wiggle Sort.} Given an unsorted array $A$, reorder it such that $A_0 < A_1 > A_2 < A_3$. Do it in $O(n)$ time and $O(1)$ space. \n\nCore clues:\n\\begin{enumerate}\n\\item Quick selection for finding median (Average $O(n)$)\n\\item Three-way partitioning to split the data\n\\item Re-mapping the index to do in-place partitioning\n\\end{enumerate}\n\n\\runinhead{Pre-processing} Sorting can be an important pre-processing step as to:\n\\begin{enumerate}\n\\item Satisfying the output order (e.g. if multiple results are possible, output the one that's smallest in terms of the natural order). \n\\end{enumerate}\n\n\\begin{python}\nclass Solution(object):\n  def wiggleSort(self, A):\n    n = len(A)\n    median_idx = self.find_kth(A, 0, n, n/2)\n    v = A[median_idx]\n    \n    idx = lambda i: (2*i+1)%(n|1)\n    lt = -1\n    hi = n\n    i = 0\n    while i < hi:\n      if A[idx(i)] > v:\n        lt += 1\n        A[idx(lt)], A[idx(i)] = A[idx(i)], A[idx(lt)]\n        i += 1\n      elif A[idx(i)] == v:\n        i += 1\n      else:\n        hi -= 1\n        A[idx(hi)], A[idx(i)] = A[idx(i)], A[idx(hi)]\n\n  def pivot(self, A, lo, hi, pidx=None):\n    lt = lo-1\n    gt = hi\n    if not pidx: pidx = lo\n\n    v = A[pidx]\n    i = lo\n    while i < gt:\n      if A[i] < v:\n        lt += 1\n        A[lt], A[i] = A[i], A[lt]\n        i += 1\n      elif A[i] == v:\n        i += 1\n      else:\n        gt -= 1\n        A[gt], A[i] = A[i], A[gt]\n\n    return lt, gt\n\n  def find_kth(self, A, lo, hi, k):\n    if lo >= hi: return\n\n    lt, gt = self.pivot(A, lo, hi)\n    \n    if lt < k < gt:\n      return k\n    if k <= lt:\n      return self.find_kth(A, lo, lt+1, k)\n    else:\n      return self.find_kth(A, gt, hi, k)\n\\end{python}\n\n\\section{Inversion}\nIf $a_i > a_j$ but $i<j$, then this is considered as 1 Inversion. That is, for an element, the count of other elements that are \\textit{larger} than the element but appear \\textit{before} it. This is the default definition. \n\nThere is also an alternative definition: for an element, the count of other elements that are \\textit{samller} than the element but appear \\textit{after} it. \n\n\\subsection{MergeSort \\& Inversion Pair}\nMergeSort to calculate the reverse-ordered paris. The only difference from a normal\nmerge sort is that - when pushing the 2nd half of the array to the place, you calculate\nthe inversion generated by the element $A_2[i_2]$ compared to $A_1[i_1:]$.\n\nTherefore the Merge-and-count key is \\pyinline{ret += len(A1) - i1}\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=1.20]{mergeAndSort.png}}\n\\caption{Merge and Count}\n\\label{fig:mergeAndSort}\n\\end{figure}\n\n\\begin{python}\ndef merge(A1, A2, A):\n  i1 = i2 =0\n  ret = 0\n  for i in xrange(len(A)):\n    if i1 == len(A1):\n      A[i] = A2[i2]\n      i2 += 1\n    elif i2 == len(A2):\n      A[i] = A1[i1]\n      i1 += 1\n    else:\n      # use array diagram to illustrate\n      if A1[i1] > A2[i2]:  # push the A2 to A\n        A[i] = A2[i2]\n        i2 += 1\n        # number of reverse-ordered pairs\n        ret += len(A1) - i1\n      else:\n        A[i] = A1[i1]\n        i1 += 1\n\n  return ret\n\ndef merge_sort(a):\n  n = len(a)\n  if n == 1:\n    return 0\n\n  a1 = a[:n/2]\n  a2 = a[n/2:]\n\n  ret1 = merge_sort(a1)\n  ret2 = merge_sort(a2)\n  # merge not merge_sort\n  ret = ret1+ret2+merge(a1, a2, a)  \n  return ret\n\\end{python}\n\n\\subsection{Binary Index Tree \\& Inversion Count}\nGiven $A$, calculate each element's inversion number. \n\nConstruct a BIT (\\ref{BIT}) with length $max(A)+1$. Let BIT maintains the index of values. Scan the element from left to right (or right to left depends on the definition of inversion number), and set the index equal val to 1. Use the prefix sum to get the inversion number.\n\n\\pyinline{get(end) - get(a)} get the count of number that appears \\textit{before} $a$ (i.e. already in the BIT) and also \\textit{larger} than $a$. \n\nPossible to extend to handle duplicate number. \n\\\\\nCore clues:\n\\begin{enumerate}\n\\item BIT maintains \\textbf{index of values} to count the number of at each value.\n\\item \\pyinline{get(end) - get(a)} to get the inversion count of $a$.\n\\end{enumerate}\n\\begin{python}\ndef inversion(self, A):\n    bit = BIT(max(A)+1)\n    ret = []\n    for a in A:\n        bit.set(a, 1)  # += 1 if possible duplicate \n        inversion = bit.get(max(A)+1) - bit.get(a)\n        ret.append(inversion)\n\n    return ret\n\\end{python}\n\n\\subsection{Segment Tree \\& Inversion Count}\\label{segmentTreeInversionCount}\nCompared to BIT, Segment Tree can process queries of both $idx \\rightarrow sum$ and $sum \\rightarrow idx$; while BIT can only process $idx \\rightarrow sum$.\n\nCore clues:\n\\begin{enumerate}\n\\item Segment Tree maintains \\textbf{index of values} to count the number of at each value.\n\\item \\pyinline{get(root, end) - get(root, a)} to get the inversion count of $a$.\n\\end{enumerate}\n\\begin{python}\nclass SegmentTree(object):\n  def __init__(self):\n    self.root = None\n\n  def build(self, root, lo, hi):\n    if lo >= hi: return\n    if not root: root = Node(lo, hi)\n\n    root.left = self.build(root.left, lo, (lo+hi)/2)\n    if root.left: \n      root.right = self.build(root.right, (lo+hi)/2, hi)\n\n    return root\n\n  def set(self, root, i, val):\n    if root.lo == i and root.hi-1 == root.lo:\n      root.cnt_this += val\n    elif i < (root.lo+root.hi)/2:\n      root.cnt_left += val\n      self.set(root.left, i, val)\n    else:\n      self.set(root.right, i, val)\n\n  def get(self, root, i):\n    if root.lo == i and root.hi-1 == root.lo:\n      return root.cnt_left\n    elif i < (root.lo+root.hi)/2:\n      return self.get(root.left, i)\n    else:\n      return (\n          root.cnt_left + root.cnt_this +\n          self.get(root.right, i)\n      )\n\n\nclass Solution(object):\n  def _build_tree(self, A):\n    st = SegmentTree()\n    mini, maxa = min(A), max(A)\n    st.root = st.build(st.root, mini, maxa+2)  \n    # maxa+1 is the end dummy\n    return st\n\n  def countOfLargerElementsBeforeElement(self, A):\n    st = self._build_tree(A)\n    ret = []\n    end = max(A)+1\n    for a in A:\n      ret.append(\n          st.get(st.root, end) - st.get(st.root, a)\n      )\n      st.set(st.root, a, 1)\n\n    return ret\n\\end{python}\n\n\\subsection{Reconstruct Array from Inversion Count}\\label{inversionReconstruct}\nGiven a \\textit{sorted} numbers with their associated inversion count (\\# larger numbers before this element). $A[i].val$ is the value of the number, $A[i].inv$ is the inversion number. Reconstruct the original array $R$ that consists of each $A[i].val$.\n\nBrute force can be done in $O(n^2)$. Put the $A[i].val$ into $R$ at slot s.t. the \\# \\textit{empty} slots before it equals to $A[i].inv$.\n\n\\rih{BST}. Possible to use BST to maintain the empty slot indexes in the original array. Each node's rank indicates the count of empty indexes in its left subtree. But need to maintain the deletion.  \n\n\\rih{Segment Tree}. Use a segment tree to maintain the size of empty slots. Each node has a $start$ and a $end$ s.t slot indexes $\\in [start, end)$. Go down to find the target slot, go up to decrement the size of empty slots. \n\nCaveat: need to sort the array in the preprocessing step. \n\nReconstruction of array cannot use BIT since there is no map of $prefixSum \\rightarrow i$.\n\\newpage\n\\begin{python}\nclass Node(object):\n  def __init__(self, lo, hi, cnt):\n    self.lo = lo\n    self.hi = hi\n    self.cnt = cnt  # size of empty slots\n\n    self.left = None\n    self.right = None\n\n  def __repr__(self):\n    return repr(\"[%d,%d)\" % (self.lo, self.hi))\n\n\nclass SegmentTree(object):\n  \"\"\"empty space\"\"\"\n  def __init__(self):\n    self.root = None\n\n  def build(self, lo, hi):\n    \"\"\"a node can have right ONLY IF has left\"\"\"\n    if lo >= hi: return\n    if lo == hi-1: return Node(lo, hi, 1)\n\n    root = Node(lo, hi, hi-lo)\n    root.left = self.build(lo, (hi+lo)/2)\n    root.right = self.build((lo+hi)/2, hi)\n    return root\n\n  def find_delete(self, root, sz):\n    \"\"\"\n    :return: index\n    \"\"\"\n    root.cnt -= 1\n    if not root.left:\n      return root.lo\n    elif root.left.cnt >= sz:\n      return self.find_delete(root.left, sz)\n    else:\n      return self.find_delete(root.right,\n                  sz - root.left.cnt)\n\n\nclass Solution(object):\n  def reconstruct(self, A):\n    st = SegmentTree()\n    n = len(A)\n    st.root = st.build(0, n)\n    A = sorted(A, key=lambda x: x[0])\n    ret = [0]*n\n    for a in A:\n      idx = st.find_delete(st.root, a[1]+1)\n      ret[idx] = a[0]\n\n    return ret\n\n\nif __name__ == \"__main__\":\n  # (val, inv)\n  A = [(5, 0), (2, 1), (3, 1), (4, 1,), (1, 4)]\n  assert Solution().reconstruct(A) == [5, 2, 3, 4, 1]\n\\end{python}\n\n\\runinhead{Duplicate.} What if the array contains duplicate elements? Use a \\pyinline{Counter} to count the duplicate items already in the result. \n", "meta": {"hexsha": "bf72665dcb5888332dd7cb0750c70fabb98a1457", "size": 19868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterSort.tex", "max_stars_repo_name": "algorhythms/Algo-Quicksheet", "max_stars_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 902, "max_stars_repo_stars_event_min_datetime": "2015-08-16T08:25:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T05:23:50.000Z", "max_issues_repo_path": "chapterSort.tex", "max_issues_repo_name": "andysli6590/Algo-Quicksheet", "max_issues_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-06T17:24:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T00:01:38.000Z", "max_forks_repo_path": "chapterSort.tex", "max_forks_repo_name": "andysli6590/Algo-Quicksheet", "max_forks_repo_head_hexsha": "c5d219a96f195adf1d19d2d701986e01fc9b8195", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 92, "max_forks_repo_forks_event_min_datetime": "2015-10-09T03:13:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:57:08.000Z", "avg_line_length": 28.4641833811, "max_line_length": 274, "alphanum_fraction": 0.6306623717, "num_tokens": 6217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.624232794071101}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\title{ My first document}\n\\date{2020/11/09}\n\\author{Steven Huang}\n\n\\begin{document}\n\\pagenumbering{gobble}\n\\maketitle\n\\newpage\n\\pagenumbering{arabic}\n\n\\section{section1}\nHello World!\n\n\\section{section2}\n\n\\begin{equation}\\label{1}\n\\begin{aligned}\nf(x)=x^2 + sigma(x) + log(10) +\\\\ x^3 + 3x^2 + 5x + 1.8\\\\\n\\end{aligned}\n\\end{equation}\n\n\n\\begin{equation}\nf(x)=x^2 + sigma(x) + log(10) + x^3 + 3x^2 + 5x + 1.8\\\\\n\\end{equation}\n\n\\begin{align}\nf(x)=x^2 + 5x + 1.8\\\\\ng(x)=\\lambda*2+3\n\\end{align}\n\n\\begin{equation}\nl(x)=(x^2 + 2*x)/(3+5*x)\n\\end{equation}\n\n\\begin{align}\n  1 + x^2 & + 4*x= 3\\\\\n  1 &= 3 - 2\\\\\n  4*x+8*x^3 &+5&=10\n\\end{align}\n\n\\section{section3-functions}\n\\begin{align}\nf(x)  &= x^2 \\\\\ng(x) &= \\frac{1}{x}\\\\\nF(x) &= \\int^0_x \\frac{1}{3}x^3\\\\\nL(x) = \\int^a_b \\frac{1+x}{1+x^2}\\sqrt{x}e^2\\\\\nf(x) = \\frac{1}{d \\sqrt{2*p}}\\\\\nf(x) = \\left( \\frac{1}{d \\sqrt{2*p}} \\right)\\\\\nf(x) = \\left[ \\frac{1}{d \\sqrt{2*p}} \\right]\\\\\nf(x) = \\left\\{ \\frac{1}{d \\sqrt{2*p}} \\right\\}\\\\\nF(x) = \\int_{a}^{b}\\left( \\sum_{n=1}^{+\\infty}u_{n}(x) \\right)\\,\\mathrm{d}x\n    =\\sum_{n=1}^{+\\infty}\\int_{a}^{b}u_{n}(x)\\,\\mathrm{d}x \\\\\nLoss(y_true, y_pred) = \\frac{1}{x}\\\\\nLoss(y_{true}, y_{pred}) = 1 - \\frac{2\\sum_{pixel}y_{true}y_{pred} + smooth }{\\sum_{pixel}y_{true}^2 + \\sum_{pixel}y_{pred}^2 + smooth}\\\\\n\\\\\nLoss(y_{true}, y_{pred})  = \\log(1+\\exp(-1 * \\sum_{Scoremap}y_{true}y_{pred} ))\\\\\n\\end{align}\n\n\n\\section{section4-matrixs}\n\\begin{equation}\nA_{m,n} = \n\\begin{pmatrix}\na_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\na_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n\\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\na_{m,1} & a_{m,2} & \\cdots & a_{m,n} \n\\end{pmatrix}\n\\end{equation}\n\n\\begin{equation}\nA = \n\\begin{pmatrix}\n1 & 2 & 3 \\\\\n4 & 5 & 6 \\\\\n7 & 8 & 9\n\\end{pmatrix}\n\\end{equation}\n\n\\begin{equation*}\nB = \n\\begin{bmatrix}\na & b & c \\\\\nd & e & f \\\\\ng & h & i\n\\end{bmatrix}\n\\end{equation*}\n\n\\begin{equation}\n   \\begin{matrix} \n   a_{11} & a_{12} & a_{13}  \\\\\n   a_{21} & a_{22} & a_{23}  \\\\\n   a_{31} & a_{32} & a_{33}  \\\\\n   \\end{matrix} \n\\end{equation}\n\n\\begin{equation}\n  \\left[\n   \\begin{matrix} \n   a_{11} & a_{12} & a_{13}  \\\\\n   a_{21} & a_{22} & a_{23}  \\\\\n   a_{31} & a_{32} & a_{33}  \\\\\n   \\end{matrix} \n  \\right]\n\\end{equation}\n\n\\begin{equation}\n  \\left\\{\n   \\begin{matrix} \n   a_{11} & a_{12} & a_{13}  \\\\\n   a_{21} & a_{22} & a_{23}  \\\\\n   a_{31} & a_{32} & a_{33}  \\\\\n   \\end{matrix} \n  \\right\\}\n\\end{equation}\n\n\\end{document}", "meta": {"hexsha": "fc9b436c9441004a52d7e20fb0752ac8388bf823", "size": 2447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/function.tex", "max_stars_repo_name": "StevenHuang2020/LaTex_TeXworks_learning", "max_stars_repo_head_hexsha": "312b22d3afd394cb2490f428c4763a3ad290f090", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-11T12:38:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-11T12:38:42.000Z", "max_issues_repo_path": "tex/function.tex", "max_issues_repo_name": "StevenHuang2020/LaTex_TeXworks_learning", "max_issues_repo_head_hexsha": "312b22d3afd394cb2490f428c4763a3ad290f090", "max_issues_repo_licenses": ["MIT"], "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/function.tex", "max_forks_repo_name": "StevenHuang2020/LaTex_TeXworks_learning", "max_forks_repo_head_hexsha": "312b22d3afd394cb2490f428c4763a3ad290f090", "max_forks_repo_licenses": ["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.2231404959, "max_line_length": 137, "alphanum_fraction": 0.5508786269, "num_tokens": 1163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6242327893864857}}
{"text": "\\documentclass[8 pt]{article}\r\n\r\n\\usepackage[utf8x]{inputenc}\r\n\\usepackage{dsfont}\r\n\\usepackage{amsthm}\r\n\\usepackage{amsfonts}\r\n\\usepackage{amssymb}\r\n\\usepackage{tensor}\r\n\\usepackage{mathtools}\r\n\\usepackage[T1]{fontenc}\r\n%\\usepackage[spanish]{babel}\r\n\\usepackage[cm]{fullpage}\r\n\\usepackage{graphicx}\r\n\\usepackage{float}\r\n\\usepackage{bm}\r\n\\usepackage{setspace}\r\n\\usepackage{enumitem}\r\n\\usepackage{mdwlist}\r\n\\usepackage{parskip}\r\n\\usepackage{listings}\r\n\\usepackage{color}\r\n%\\usepackage{epstopdf}\r\n\\usepackage{tikz,datatool}\r\n\\usepackage{hyperref}\r\n\\usepackage{mathabx}\r\n\\usepackage{multicol}\r\n\\usepackage{eurosym}\r\n\r\n\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}\r\n\r\n\\AtBeginDocument{\r\n  \\let\\myThePage\\thepage\r\n  \\renewcommand{\\thepage}{\\oldstylenums{\\myThePage}}\r\n}\r\n\r\n\\newcommand{\\gra}{$^\\text{o}$}\r\n\\newcommand{\\dif}{\\text{d}}\r\n\\newcommand{\\avg}[1]{\\left\\langle #1 \\right\\rangle}\r\n\\newcommand{\\ket}[1]{\\left| #1 \\right\\rangle}\r\n\\newcommand{\\bra}[1]{\\left\\langle #1 \\right|}\r\n\\newcommand{\\bket}[2]{\\left\\langle #1 \\middle| #2 \\right\\rangle}\r\n\\newcommand{\\der}[2]{\\frac{\\text{d} #1}{\\text{d} #2}}\r\n\\newcommand{\\prt}[2]{\\frac{\\partial #1}{\\partial #2}}\r\n\\newcommand{\\dert}[3]{\\frac{\\text{d}^#3 #1}{\\text{d} #2^#3}}\r\n\\newcommand{\\prtt}[3]{\\frac{\\partial^#3 #1}{\\partial #2^#3}}\r\n\\newcommand{\\dl}{\\mathcal{L}}\r\n\\newcommand{\\dha}{\\mathcal{H}}\r\n\\newcommand{\\vol}{\\text{vol}}\r\n\\renewcommand{\\vec}[1]{\\pmb{#1}}\r\n\r\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\r\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\r\n\r\n\\begin{document}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n    \\centering\r\n    \\Large \\textbf{\\textsc{Homework 1: An option's fair price}}\\\\[0.5cm]\r\n\r\n    \\small \\textsc{Francisco García Flórez, Joris van Lammeren, Wouter Varenkamp}\\\\[0.5cm]\r\n\r\n    \\begin{minipage}{0.6\\textwidth}\r\n      \\textbf{Abstract.} In this first homework we will be computing using a Monte Carlo method the exercise value of a share, which we will then use to determine a fair price for a call option of that share.\r\n    \\end{minipage}\r\n\\end{minipage}\r\n\r\n\\section{Computing the share's value via a Wiener process}\r\n\r\nFirstly, we need to compute the value of the share itself after a certain amount of time. For this purpose we will solve the following stochastic differential equation, known as \\emph{Wiener process} \\cite{Wilmott}:\r\n\r\n\\begin{equation}\r\n  \\frac{\\dif S}{S} = \\sigma \\dif X + \\mu \\dif t ~~~ ,\r\n\\end{equation}\r\n\r\nwhere $\\sigma$ is the volatility, $\\mu$ is the drift and $S(t)$ the value of the option as a function of time. Instead of solving it analytically, we can discretize it as in \\cite{sde} to find\r\n\r\n\\begin{equation}\r\n  S_{i+1} = S_i \\left( 1 + \\sigma \\Delta W_i + \\mu \\Delta t_i \\right) ~~~ ,\r\n\\end{equation}\r\n\r\nwhere $\\Delta W_i = \\sqrt{\\Delta t_i} N(0, 1)$, simulating the random walk. In our case the time step is constant, so every $\\Delta t_i$ will have the same value. The value after $nt$ time steps is the value at expiration date, which we will use to determine the price of the option.\r\n\r\n\\section{Determining fair prices for call options}\r\n\r\nNow that we can compute the exercise value of the share, we can use it to determine how much we can pay for a call option for that share. Since this is not a value that can be derived via an objective procedure, we will consider two approaches to compute the price: the \\emph{risk-free approach} and the \\emph{risky approach}.\r\n\r\n\\subsection{Risk-free approach}\r\n\r\nFor the \\textbf{risk-free approach}, we consider the probability distribution of the value of the share at expiration date, which will be a normal $N(\\mu, \\sigma)$. Now, since buying the call option gives us the \\emph{right} to buy the share at the exercise price, we can choose not to use it if that means losing money. To represent this fact, instead of using the previous normal for our computations, we take every instance with share price lower than the exercise price and assign a profit of zero to it, instead of a negative value.\r\n\r\nIn the following plots we can clearly see that transformation:\r\n\r\n\\begin{figure}[H]\r\n  \\begin{center}\r\n    \\includegraphics[width=0.4\\textwidth]{graphs/ex-normal-1.eps}\r\n    \\includegraphics[width=0.4\\textwidth]{graphs/ex-normal-2.eps}\r\n    \\caption{(a) Example of normal distribution $N(1,1)$. (b) Distribution after applying the mentioned transformation, $\\tilde N(1,1)$.}\r\n    \\label{fig:ex_normal}\r\n  \\end{center}\r\n\\end{figure}\r\n\r\nUsing this new probability distribution we can compute the risk-free price as the \\textbf{average value} of it. This price is the minimum profit that on average we expect to make, so the fair price using this approach would be any amount smaller than the sum of the exercise price plus this value, as much as the writer of the option is willing to accept.\r\n\r\nWe can write this as\r\n\r\n\\begin{equation}\r\n  \\avg{oP}_{rf} \\equiv \\avg{\\tilde N(\\mu, \\sigma)} ~~~ ,\r\n\\end{equation}\r\n\r\nwhere $aE$ is the exercise price and $\\avg{oP}_{rf}$ is the option price computed risk-free, and $\\tilde N(\\mu, \\sigma)$ is the adjusted normal distribution.\r\n\r\n\\subsection{Risky approach}\r\n\r\nOn the other hand, we can take a \\textbf{risky approach} and pay more than the risk-free price with a smaller probability of having profits. For this to be quantitative we have to assign a risk value to a price, in a way that zero corresponds to making the average profit and one corresponds to the impossible case of having profit paying an infinite amount of money.\r\n\r\nSo, assuming the expiry values of the share is a random variable with normal distribution, we can introduce the risk as a value $P \\in [0, 1)$ and compute the probability of making average profit using the cumulative distribution function (cdf) as\r\n\r\n\\begin{equation*}\r\n  \\text{cdf}(\\avg{oP}_{rf}, \\mu, \\sigma) ~~~ ,\r\n\\end{equation*}\r\n\r\nand then computing the final probability using $P$ as\r\n\r\n\\begin{equation*}\r\n  \\text{cdf}(\\avg{oP}_{rf}, \\mu, \\sigma)(1 - P) + P ~~~ .\r\n\\end{equation*}\r\n\r\nNow, what we are doing here is mapping the interval $[\\text{cdf}(\\avg{oP}_{rf}, \\mu, \\sigma), 1)$ to $[0, 1)$, so that by computing the inverse cdf of this probability we can map the expected profits interval, $[\\avg{oP}_{rf}, \\infty)$, to $P \\in [0, 1)$. We can write this calculation as\r\n\r\n\\begin{equation}\r\n  \\avg{oP}_r \\equiv \\text{cdf}^{-1} \\left( \\text{cdf}(\\avg{oP}_{rf}, \\mu, \\sigma)(1 - P) + P \\right) ~~~ .\r\n\\end{equation}\r\n\r\n\\section{Results}\r\n\r\nIn this section we will use the previous theory with the following values: $\\mu = 0.02$, $\\sigma = 0.2$, $S(0) = 14$ and $aE = 15$, over a period of $101$ days. In the following histogram we can see the results of performing $N=10^5$ random walks to compute the price of the option at exercise date. From here we can compute the values of $\\mu$ and $\\sigma$ mentioned in the previous section.\r\n\r\n\\begin{figure}[H]\r\n  \\begin{center}\r\n    \\includegraphics[width=0.6\\textwidth]{graphs/rw-hist.eps}\r\n    \\caption{Histogram showing the distribution of share values after $N=10^5$ random walks.}\r\n    \\label{fig:rw_hist}\r\n  \\end{center}\r\n\\end{figure}\r\n\r\nFrom this plot we can see that a drift ratio of $0.02$ is not enough to increase the value of the share significantly, however the volatility increases the width of the normal, and therefore for some value there will be a profit. Now we can proceed to compute the risk-free and risky value for the option. The two graphs below show the profit-risk relation in absolute profit and in percentage given these values.\r\n\r\n\\begin{figure}[H]\r\n  \\begin{center}\r\n    \\includegraphics[width=0.4\\textwidth]{graphs/P-oP.eps}\r\n    \\includegraphics[width=0.4\\textwidth]{graphs/P-Profit.eps}\r\n    \\caption{(a) Expected profit at the exercise date of the option. (b) Expected profit over exercise value of the option.}\r\n    \\label{fig:oP_plots}\r\n  \\end{center}\r\n\\end{figure}\r\n\r\nAs we can see in Figure \\ref{fig:oP_plots}a, the risk-free approach gives a value for the option of $\\sim 0.25$\\euro, however it can be increased by taking more risk as we explained before. In this case we can consider a risk $P = 0.5$ acceptable for a profit\\% of around $\\sim 5\\%$, although still very small. If this were a real option, we would advise against buying it in the first place, and find others with greater expected profits.\r\n\r\n\\begin{thebibliography}{28}\r\n\\raggedright\r\n\\addcontentsline{toc}{section}{Bibliography}\r\n\r\n\\bibitem{Wilmott} P. Wilmott et al, \\emph{The Mathematics of Financial Derivatives}, 1995.\r\n\r\n\\bibitem{sde} Timothy Sauer, \\emph{Handbook of Computational Statistics}, Springer, pp 529-550, July 2011.\r\n\r\n\\end{thebibliography}\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "ae23d05082f2c201d7b2823675a7818766acd568", "size": 8564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homeworks/hw1/tex/report.tex", "max_stars_repo_name": "Milias/FinancialStuff", "max_stars_repo_head_hexsha": "b072d376161c9c041b876b98aa3623c3725080a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-01-30T16:29:35.000Z", "max_stars_repo_stars_event_max_datetime": "2017-01-30T16:29:35.000Z", "max_issues_repo_path": "Homeworks/hw1/tex/report.tex", "max_issues_repo_name": "Milias/FinancialStuff", "max_issues_repo_head_hexsha": "b072d376161c9c041b876b98aa3623c3725080a6", "max_issues_repo_licenses": ["MIT"], "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/hw1/tex/report.tex", "max_forks_repo_name": "Milias/FinancialStuff", "max_forks_repo_head_hexsha": "b072d376161c9c041b876b98aa3623c3725080a6", "max_forks_repo_licenses": ["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.3764705882, "max_line_length": 538, "alphanum_fraction": 0.7191732835, "num_tokens": 2468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6242048346766351}}
{"text": "\nIn Magma a tensor space is a parent type for tensors.  It behaves as a module\nbut also maintains an interpretation of its elements as a multilinear map.  Each\ntensor space further maintains a tensor category which is also assigned to its\ntensors.  Note that in \\cite{FMW:densors}*{Section~7} tensors do not explicitly\nrequire a parent tensor space type.  This deviation is in accordance with\nMagma's design patterns for vectors and vector spaces, matrices and matrix\nspaces.  Consequently, the pattern here is more verbose and all primitive data\ntypes representing tensors are afforded as tensor spaces of specific types,\ne.g. \\texttt{KTensorSpace} for tensor spaces for fields $K$, \n\\texttt{RTensorSpace} for commutative ring $R$ and free modules, and \n\\texttt{TensorSpace} for black-box tensor spaces.  Sparse and dense representations\nare indeed handled by system level types to remain efficient.\n\n\n\\section{Constructions of tensor and cotensor spaces}\n\n\\subsection{Universal tensor spaces}\n\nConstruction of universal tensor spaces is modeled after construction of free \nmodules and matrix spaces. For efficiency reasons, the actual representation \nmay \nvary based on the parameters, e.g. it may be a space of structure constants, \nblack-box functions, or systems of forms. So access to the tensors in these \ntensor space should be made through the provided functions.\n\n\\index{KTensorSpace}\n\\begin{intrinsics}\nKTensorSpace(K, S) : Fld, [RngIntElt] -> TenSpc\nKTensorSpace(K, S, C) : Fld, [RngIntElt], TenCat -> TenSpc\n\\end{intrinsics}\n\nFor a field $K$ and sequence $S=[d_{\\vav},\\ldots, d_0]$, returns the universal\ntensor space $K^{d_0}\\oslash \\cdots\\oslash K^{d_{\\vav}}$ with covariant tensor\ncategory given by $C$. The default category is the homotopism category.\n\n\\index{RTensorSpace}\n\\begin{intrinsics}\nRTensorSpace(R, S) : Rng, [RngIntElt] -> TenSpc\nRTensorSpace(R, S, C) : Rng, [RngIntElt], TenCat -> TenSpc\n\\end{intrinsics}\n\nFor a commutative ring $R$ and sequence $S=[d_{\\vav},\\cdots, d_0]$, returns the\nuniversal tensor space $R^{d_0}\\oslash\\cdots\\oslash R^{d_{\\vav}}$ with covariant tensor\ncategory given by $C$. The default category is the homotopism category.\n\n\\begin{example}[UniversalKTenSpc]\n\nWe demonstrate how to construct universal tensor spaces from a field\n$K=\\mathbb{Q}$ and a sequence of nonnegative integers $[6,5,4,3]$. The resulting\ntensor space is isomorphic to the space of multilinear maps with frame \n\\[ \n    \\mathbb{Q}^6\\times \\mathbb{Q}^5\\times\\mathbb{Q}^4\\rightarrowtail\\mathbb{Q}^3.\n\\]\n\\begin{code}\n> K := Rationals();\n> S := [6, 5, 4, 3];\n> T := KTensorSpace(K, S);\n> T;\nTensor space of dimension 360 over Rational Field with valence 4\nU3 : Full Vector space of degree 6 over Rational Field\nU2 : Full Vector space of degree 5 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n\\end{code}\n\nBecause tensor spaces act like modules, we can construct tensors in the same way we construct vectors.\n\\begin{code}\n> t := T![Random([-1, 0, 1]) : i in [1..Dimension(T)]];\n> t;\nTensor of valence 4, U3 x U2 x U1 >-> U0\nU3 : Full Vector space of degree 6 over Rational Field\nU2 : Full Vector space of degree 5 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n> Parent(t);\nTensor space of dimension 360 over Rational Field with valence 4\nU3 : Full Vector space of degree 6 over Rational Field\nU2 : Full Vector space of degree 5 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n\\end{code}\n\\end{example}\n\n\n\\index{TensorSpace}\n\\begin{intrinsics}\nTensorSpace(S) : SeqEnum -> TenSpc, List\nTensorSpace(S) : List -> TenSpc, List\nTensorSpace(S, C) : SeqEnum, TenCat -> TenSpc, List\nTensorSpace(S, C) : List, TenCat -> TenSpc, List\n\\end{intrinsics}\n\nGiven a sequence $S=[U_{\\vav},\\dots, U_0]$ of $R$-modules returns a universal tensor \nspace equivalent to $U_0\\oslash \\cdots\\oslash U_{\\vav}$ with covariant tensor \ncategory given by $C$ and a list of maps into the vector spaces in the frame. \nThe default category is the homotopism category. \n\n\\begin{example}[UniversalTenSpc]\n\nWe will construct a similar tensor space as the previous example. \nHowever, the objects will be different, according to Magma.\n\\begin{code}\n> R := Integers();\n> S := [* RMatrixSpace(R, 2, 3), RSpace(R, 5), RMatrixSpace(R, 2, 2), \\\n>     RSpace(R, 3) *];\n> T := TensorSpace(S);\n> T;\nTensor space of dimension 360 over Integer Ring with valence 4\nU3 : Full RSpace of degree 6 over Integer Ring\nU2 : Full RSpace of degree 5 over Integer Ring\nU1 : Full RSpace of degree 4 over Integer Ring\nU0 : Full RSpace of degree 3 over Integer Ring\n\\end{code}\n\nEven though the frame of $T$ does not include matrix spaces, like with tensors,\nit can still evaluate matrices. For example, we evaluate $T$ at $(0,0,0)$, which\nis the trivial subspace in $\\mathbb{Z}^3$.\n\\begin{code}\n> x := < X!0 : X in S[1..3] >;\n> x;\n<\n    [0 0 0]\n    [0 0 0],\n\n    (0 0 0 0 0),\n\n    [0 0]\n    [0 0]\n>\n> x @ T;\nRSpace of degree 3, dimension 0 over Integer Ring\nGenerators: \n\n\\end{code}\n\\end{example}\n\n\\index{TensorSpace!signatured}\n\\begin{intrinsics}\nTensorSpace(V, p, q) : ModTupFld, RngIntElt, RngIntElt -> TenSpc\nTensorSpace(K, d, p, q) : Fld, RngIntElt, RngIntElt, RngIntElt -> TenSpc\n\\end{intrinsics}\n\nReturns the signatured $(p,q)$-tensor space over the vector space $V=K^d$. The\nfirst $p$ indices are covariant and the last $q$ indices are contravariant. This\nis functionally equivalent to creating a universal tensor space from the\nsequence $[V,\\dots,_p V, V^*,\\dots,_q V^*, K]$ and the tensor category with\narrows $[1,\\dots,_p 1, -1,\\dots,_q -1, 0]$ and duplicates\n$\\{\\{p+q,\\dots,1+q\\},\\{q,\\dots,1\\},\\{0\\}\\}$. The valence of the returned tensor\nspace will be $p+q+1$. \n\n\\begin{example}[SignaturedTenSpc]\n\nHere we simply demonstrate the nuances of the signatured tensor space constructor.\nWe set $V=\\mathbb{F}_5^4$, $p=3$, and $q=2$, and the tensor space we will construct will have frame \n\\[ V\\times V\\times V \\times V^* \\times V^*\\rightarrowtail\\mathbb{F}_5. \\]\nNotice this is equivalent to the frame $V\\times V\\times V\\rightarrowtail V \\times V$. \n\\begin{code}\n> K := GF(5);\n> T := TensorSpace(K, 4, 3, 2);\n> T;\nTensor space of dimension 1024 over GF(5) with valence 6\nU5 : Full Vector space of degree 4 over GF(5)\nU4 : Full Vector space of degree 4 over GF(5)\nU3 : Full Vector space of degree 4 over GF(5)\nU2 : Full Vector space of degree 4 over GF(5)\nU1 : Full Vector space of degree 4 over GF(5)\nU0 : Full Vector space of degree 1 over GF(5)\n> S := KTensorSpace(K, [4, 4, 4, 4, 4, 1]);\n> S;\nTensor space of dimension 1024 over GF(5) with valence 6\nU5 : Full Vector space of degree 4 over GF(5)\nU4 : Full Vector space of degree 4 over GF(5)\nU3 : Full Vector space of degree 4 over GF(5)\nU2 : Full Vector space of degree 4 over GF(5)\nU1 : Full Vector space of degree 4 over GF(5)\nU0 : Full Vector space of degree 1 over GF(5)\n\\end{code}\n\nHowever, the subtleties of this construction lies in the tensor category. \nOn the surface, the spaces $T$ and $S$ look the same, but probing the category reveals their differences.\n\\begin{code}\n> TensorCategory(S); // default category\nTensor category of valence 6 (->,->,->,->,->,->) ({ 1 },{ 2 },{ 0 },{ 3 },{ 4 \n},{ 5 })\n> TensorCategory(T); \nTensor category of valence 6 (<-,<-,<-,->,->,==) ({ 0 },{ 3 .. 5 },{ 1 .. 2 })\n> S eq T;\nfalse\n\\end{code}\n\\end{example}\n\n\n\\subsection{Universal cotensor spaces}~\n\nCurrently, we only consider cotensor spaces over fields.\n\n\\index{KCotensorSpace}\n\\begin{intrinsics}\nKCotensorSpace(K, S) : Fld, [RngIntElt] -> TenSpc\nKCotensorSpace(K, S, C) : Fld, [RngIntElt], TenCat -> TenSpc\n\\end{intrinsics}\n\nFor a field $K$ and sequence $S=[d_{\\vav},\\dots, d_1]$ returns the universal cotensor \nspace $\\bigotimes_{a\\in\\comp{0}}K^{d_a}$ with the given contravariant tensor category $C$.\nThe default category is the homotopism category.\nNotice the sequence $S$ indices do \\emph{not} include 0.\n\n\\index{CotensorSpace}\n\\begin{intrinsics}\nCotensorSpace(S) : SeqEnum -> TenSpc, List\nCotensorSpace(S) : List -> TenSpc, List\nCotensorSpace(S, C) : SeqEnum, TenCat -> TenSpc, List\nCotensorSpace(S, C) : List, TenCat -> TenSpc, List\n\\end{intrinsics}\n\nGiven a sequence $S=[U_{\\vav},\\dots, U_1]$ of $K$-vector spaces returns the universal tensor \nspace equivalent to $\\bigotimes_{a\\in\\comp{0}}U_a$ with contravariant tensor \ncategory given by $C$ and a list of maps into the vector spaces of the frame. \nThe default category is the homotopism category.\nNotice the sequence $S$ indices do \\emph{not} include 0.\n\n\\begin{example}[UniversalCoTenSpc]\n\nConstructing cotensor spaces is nearly the same as constructing tensor spaces.\nWhen providing a sequence of modules or a sequence of dimensions, we do not\ninclude the entry for $U_0$. It is automatically set to $U_0=K$. Furthermore,\nthe black-box construction forgets all other structure of the vector spaces and\nonly builds a frame out of vector spaces. The maps are returned as a\n\\texttt{List} in case they are needed.\n\\begin{code}\n> K := Rationals();\n> S := [* KSpace(K, 3), MatrixAlgebra(K, 3), KMatrixSpace(K, 2, 3) *];\n> S;\n[*\n    Full Vector space of degree 3 over Rational Field,\n    Full Matrix Algebra of degree 3 over Rational Field,\n    Full KMatrixSpace of 2 by 3 matrices over Rational Field\n*]\n> T := CotensorSpace(S);\n> T;\nCotensor space of dimension 162 over Rational Field with valence 4\nU3 : Full Vector space of degree 3 over Rational Field\nU2 : Full Vector space of degree 9 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\n\\end{code}\n\nLike with tensor spaces, cotensors are elements of cotensor spaces, and for many\npurposes in Magma, cotensor and tensor spaces have similar functionality. \n\\begin{code}\n> t := T.3;\n> t;\nCotensor of valence 4, U3 x U2 x U1 >-> K\nU3 : Full Vector space of degree 3 over Rational Field\nU2 : Full Vector space of degree 9 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\n> Eltseq(t);\n[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0 ]\n\\end{code}\n\\end{example}\n\n\\subsection{Some standard constructions}\n\nWe include some subspaces generated by well-known tensors.\n\n\\index{AlternatingSpace}\n\\begin{intrinsics}\nAlternatingSpace(T) : TenSpc -> TenSpc, Map\n\\end{intrinsics}\n\nReturns the sub(co-)tensor space generated by all the alternating (co-)tensors\ncontained in the given (co-)tensor space and an embedding into $T$.\n\n\\index{AntisymmetricSpace}\n\\begin{intrinsics}\nAntisymmetricSpace(T) : TenSpc -> TenSpc, Map\n\\end{intrinsics}\n\nReturns the sub(co-)tensor space generated by all the antisymmetric (co-)tensors\ncontained in the given (co-)tensor space and an embedding into $T$.\n\n\\index{SymmetricSpace}\n\\begin{intrinsics}\nSymmetricSpace(T) : TenSpc -> TenSpc, Map\n\\end{intrinsics}\n\nReturns the sub(co-)tensor space generated by all the symmetric (co-)tensors\ncontained in the given (co-)tensor space  and an embedding into $T$.\n\n\\begin{example}[StandardTenSubspcs]\n\nWe will construct some standard tensor subspaces of the universal tensor space\nwith frame $\\mathbb{F}_3^4\\times \\mathbb{F}_3^4\\rightarrowtail\\mathbb{F}_3^4$.\n\\begin{code}\n> K := GF(3);\n> T := KTensorSpace(K, [4, 4, 4]);\n> T;\nTensor space of dimension 64 over GF(5) with valence 3\nU2 : Full Vector space of degree 4 over GF(5)\nU1 : Full Vector space of degree 4 over GF(5)\nU0 : Full Vector space of degree 4 over GF(5)\n\\end{code}\n\nFirst, we will construct the subspace of $T$ containing all alternating bilinear maps.\nSince $\\binom{4}{2}=6$, we expect the subspace to be 24-dimensional in $T$. \n\\begin{code}\n> Alt := AlternatingSpace(T);\n> Alt;\nTensor space of dimension 24 over GF(3) with valence 3\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n> t := Random(Alt);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n> IsAlternating(t);\ntrue\n\\end{code}\n\nNow we will construct the symmetric subspace of the alternating subspace, which is trivial.\n\\begin{code}\n> S := SymmetricSpace(Alt);\n> S;\nTensor space of dimension 0 over GF(3) with valence 3\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 4 over GF(3)\n\\end{code}\n\\end{example}\n\n\\index{ExteriorCotensorSpace}\n\\begin{intrinsics}\nExteriorCotensorSpace(V, n) : ModTupFld, RngIntElt -> TenSpc\n\\end{intrinsics}\n\nReturns the cotensor space given by the $n$th exterior power of the vector space $V$.\n\n\\index{SymmetricCotensorSpace}\n\\begin{intrinsics}\nSymmetricCotensorSpace(V, n) : ModTupFld, RngIntElt -> TenSpc\n\\end{intrinsics}\n\nReturns the cotensor space given by the $n$th symmetric power of the vector space $V$.\n\n\\begin{example}[StandardCoTenSubspcs]\n\nWe set $V=\\mathbb{F}_5^6$ and we construct the cotensor space of the symmetric\nsquare of $V$, $V\\wedge V$. The frame is $V\\times V\\rightarrowtail\n\\mathbb{F}_5$, so the cotensor space is $\\binom{6}{2}$-dimensional. \n\\begin{code}\n> V := VectorSpace(GF(5), 6);\n> T := ExteriorCotensorSpace(V, 2);\n> T;\nCotensor space of dimension 15 over GF(5) with valence 3\nU2 : Full Vector space of degree 6 over GF(5)\nU1 : Full Vector space of degree 6 over GF(5)\n\\end{code}\n\nThe cotensor space $T$ is generated by all alternating tensors $\\bra{t} :\nV\\times V\\rightarrowtail \\mathbb{F}_5$. We will demonstrate by constructing a\nrandom cotensor from $T$. \n\\begin{code}\n> t := Random(T);\n> t;\nCotensor of valence 3, U2 x U1 >-> K\nU2 : Full Vector space of degree 6 over GF(5)\nU1 : Full Vector space of degree 6 over GF(5)\n> SystemOfForms(t);\n[\n    [0 2 2 2 4 1]\n    [3 0 4 1 0 0]\n    [3 1 0 3 1 1]\n    [3 4 2 0 2 0]\n    [1 0 4 3 0 2]\n    [4 0 4 0 3 0]\n]\n> IsAlternating(t);\ntrue\n\\end{code}\n\nNotice this construction is not $V\\times V\\rightarrowtail V\\wedge V$. \nHowever, if we want this tensor, we can use the intrinsic \\texttt{AsTensor}.\n\\begin{code}\n> s := AsTensor(T);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 6 over GF(5)\nU1 : Full Vector space of degree 6 over GF(5)\nU0 : Full Vector space of degree 15 over GF(5)\n> IsAlternating(s);\ntrue\n\\end{code}\n\\end{example}\n\n\n\\section{Operations on tensor spaces}\n\n\\subsection{Membership and comparison with tensor spaces}\n\nWe define some intuitive functions for tensor spaces, similar to those found for modules.\n\n\\index{in}\n\\begin{intrinsics}\nt in T : TenSpcElt, TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if $t$ is contained in the tensor space $T$.\n\n\\index{IsCoercible!tensor}\\index{BANG!tensor}\n\\begin{intrinsics}\nIsCoercible(T, t) : TenSpc, TenSpcElt -> BoolElt\nT ! t : TenSpc, TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nDecides if the tensor $t$ can be coerced into the tensor space $T$. If so, the\ntensor is returned as an element of $T$.\n\n\\index{IsCoercible!sequence}\\index{BANG!sequence}\n\\begin{intrinsics}\nIsCoercible(T, S) : TenSpc, [RngElt] -> BoolElt\nT ! S : TenSpc, SeqEnum -> TenSpcElt\n\\end{intrinsics}\n\nDecides if the sequence $S$ can be coerced into the tensor space $T$ as a\ntensor. If so, the corresponding tensor is returned. \n\n\\index{IsCoercible!zero}\\index{BANG!zero}\n\\begin{intrinsics}\nIsCoercible(T, n) : TenSpc, RngIntElt -> BoolElt\nT ! n : TenSpc, RngIntElt -> TenSpcElt\n\\end{intrinsics}\n\nThis is a shortcut designed to only work when $n=0$, and thus, return {\\tt true}\nand the zero tensor from the tensor space. Any other integer will yield an\nerror.\n\n\\begin{example}[Coercion]\nWe illustrate that using \\texttt{!} is the same as creating the tensor from scratch.\n\n\\begin{code}\n> T := KTensorSpace( GF(2), [2,3,2] );\n> T;\nTensor space of dimension 12 over GF(2) with valence 3\nU2 : Full Vector space of degree 2 over GF(2)\nU1 : Full Vector space of degree 3 over GF(2)\nU0 : Full Vector space of degree 2 over GF(2)\n> \n> S := [ 1 : i in [1..12] ];\n> t := T!S;\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over GF(2)\nU1 : Full Vector space of degree 3 over GF(2)\nU0 : Full Vector space of degree 2 over GF(2)\n> \n> t eq Tensor(GF(2), [2,3,2], S);\ntrue\n> \n> T!0 in T;\ntrue\n> SystemOfForms(T!0);\n[\n    [0 0 0]\n    [0 0 0],\n\n    [0 0 0]\n    [0 0 0]\n]\n\\end{code}\n\n\\end{example}\n\n\\index{eq!tensor space}\n\\begin{intrinsics}\nS eq T : TenSpc, TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if the tensor spaces $S$ and $T$ are equal.\n\n\\index{subset}\n\\begin{intrinsics}\nS subset T : TenSpc, TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if $S$ is a subset of the tensor space $T$.\n\n\\index{IsCoercible!tensor space}\\index{BANG!tensor space}\n\\begin{intrinsics}\nIsCoercible(T, S) : TenSpc, TenSpc -> BoolElt\nT ! S : TenSpc, TenSpc -> TenSpc\n\\end{intrinsics}\n\nDecides if the tensor space $S$ can be coerced into the tensor space $T$ as a\nsubspace. If so, the corresponding subspace is returned. \n\n\\begin{example}[TenSpcContainment]\n\nWe construct the universal tensor space $T$ with the frame $\\mathbb{F}_2^4\\times\n\\mathbb{F}_2^4\\rightarrowtail \\mathbb{F}_2^4$. We also create a tensor space\n$T_2$ with frame $\\mathbb{F}_2^4\\times \\mathbb{F}_2\\times\n\\mathbb{F}_2^4\\times\\mathbb{F}_2\\rightarrowtail \\mathbb{F}_2^4$.\n\n\\begin{code}\n> T := KTensorSpace(GF(2), [4,4,4]);\n> T;\nTensor space of dimension 64 over GF(2) with valence 3\nU2 : Full Vector space of degree 4 over GF(2)\nU1 : Full Vector space of degree 4 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n> \n> T2 := KTensorSpace(GF(2), [4,1,4,1,4]);\n> T2;\nTensor space of dimension 64 over GF(2) with valence 5\nU4 : Full Vector space of degree 4 over GF(2)\nU3 : Full Vector space of degree 1 over GF(2)\nU2 : Full Vector space of degree 4 over GF(2)\nU1 : Full Vector space of degree 1 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n> \n> S := sub< T | T.2, T.4, T.8 >;\n> S;\nTensor space of dimension 3 over GF(2) with valence 3\nU2 : Full Vector space of degree 4 over GF(2)\nU1 : Full Vector space of degree 4 over GF(2)\nU0 : Full Vector space of degree 4 over GF(2)\n\\end{code}\n\nWe verify that $S$ is a subset of $T$ and not $T_2$. Since the tensors of $T$\nnaturally embed into $T_2$, the subspace $S$ can be coerced into $T_2$, which we\nlabel as $S_2$. We then verify that $S_2$ is a subset of $T_2$ and not $T$. \n\\begin{code}\n> S subset T2;\nfalse\n> S2 := T2!S;\n> S2 subset T2;\ntrue\n> S2 subset T;\nfalse\n\\end{code}\n\\end{example}\n\n\\subsection{Tensor spaces as modules}\n\nWe view a tensor space as a $K$-module, so we have notions of generators, \ndimension (if it is free), and cardinality.\n\n\\index{Generators}\\index{Basis}\n\\begin{intrinsics}\nBasis(T) : TenSpc -> SeqEnum\nGenerators(T) : TenSpc -> SeqEnum\n\\end{intrinsics}\n\nReturns a basis for the tensor space $T$. \n\n\\index{.!tensor space}\n\\begin{intrinsics}\nT.i : TenSpc, RngIntElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the $i$th basis tensor of the tensor space $T$.\n\n\\index{NumberOfGenerators}\\index{Ngens}\n\\begin{intrinsics}\nNumberOfGenerators(T) : TenSpc -> RngIntElt\nNgens(T) : TenSpc -> RngIntElt\n\\end{intrinsics}\n\nReturns the number of generators of the tensor space $T$.\n\n\\index{Dimension}\n\\begin{intrinsics}\nDimension(T) : TenSpc -> RngIntElt\n\\end{intrinsics}\n\nReturns the dimension of the tensor space $T$ as a free $K$-module.\n\n\\index{\\#}\n\\begin{intrinsics}\n# T : TenSpc -> RngIntElt\n\\end{intrinsics}\n\nReturns the size of the tensor space, provided $T$ is finite.\n\n\\begin{example}[BasicModule]\n\nWe demonstrate the basic module functions of tensor spaces. We construct the\nuniversal tensor space $T$ with frame\n$\\mathbb{F}_8^3\\times\\mathbb{F}_8^5\\rightarrowtail\\mathbb{F}_8^7$.\n\\begin{code}\n> K := GF(8);\n> T := KTensorSpace(K, [3,5,7]);\n> T;\nTensor space of dimension 105 over GF(2^3) with valence 3\nU2 : Full Vector space of degree 3 over GF(2^3)\nU1 : Full Vector space of degree 5 over GF(2^3)\nU0 : Full Vector space of degree 7 over GF(2^3)\n\\end{code} \n\nNow we obtain module properties of $T$.\n\\begin{code}\n> Dimension(T);\n105\n> #Basis(T);\n105\n> T.100 in Basis(T);\ntrue\n> T.100;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 3 over GF(2^3)\nU1 : Full Vector space of degree 5 over GF(2^3)\nU0 : Full Vector space of degree 7 over GF(2^3)\n> #T eq 8^(3*5*7);\ntrue\n\\end{code}\n\\end{example}\n\n\\index{Random}\n\\begin{intrinsics}\nRandom(T) : TenSpc -> TenSpcElt\n\\end{intrinsics}\n\nProvided the base ring has a random algorithm in Magma, it returns a random \nelement of the tensor space $T$.\n\n\\index{RandomTensor}\\index{RandomCotensor}\n\\begin{intrinsics}\nRandomTensor(R, S) : Rng, [RngIntElt] -> TenSpcElt\nRandomTensor(R, S, C) : Rng, [RngIntElt], TenCat -> TenSpcElt\nRandomCotensor(K, S) : Fld, [RngIntElt] -> TenSpcElt\n\\end{intrinsics}\n\nProvided $R$ has a random algorithm in Magma, it returns a random (co)tensor from \nthe universal (co)tensor space $\\rversor_{s\\in S} R^{s}$, with category $C$.\nThe default category is the homotopism category.\n\n\\begin{example}[RandomTensors]\n\nWe create some random tensors, which works similarly to \\texttt{RandomMatrix} in\nMagma. There are two main ways to obtain a random tensor: from a given tensor\nspace or from a ring and a dimension sequence (the universal tensor space).\nFirst we will construct the alternating tensor space of the universal tensor\nspace with frame $\\mathbb{F}_3^4\\times\\mathbb{F}_3^4\\rightarrowtail\n\\mathbb{F}_3^2$.\n\\begin{code}\n> T := KTensorSpace(GF(3), [4,4,2]);\n> T;\nTensor space of dimension 32 over GF(3) with valence 3\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n> S := AlternatingSpace(T);\n> S;\nTensor space of dimension 12 over GF(3) with valence 3\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n\\end{code}\n\nNow we construct a random alternating tensor from $S$.\n\\begin{code}\n> t := Random(S);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over GF(3)\nU1 : Full Vector space of degree 4 over GF(3)\nU0 : Full Vector space of degree 2 over GF(3)\n> SystemOfForms(t);\n[\n    [0 0 0 1]\n    [0 0 1 2]\n    [0 2 0 0]\n    [2 1 0 0],\n\n    [0 2 1 2]\n    [1 0 1 2]\n    [2 2 0 0]\n    [1 1 0 0]\n]\n\\end{code}\n\\end{example}\n\n\\index{RandomAlternatingTensor}\n\\begin{intrinsics}\nRandomAlternatingTensor(R, d, n, c) : Rng, RngIntElt, RngIntElt, RngIntElt -> TenSpcElt\nRandomAlternatingTensor(R, S) : Rng, [RngIntElt] -> TenSpcElt\n\\end{intrinsics}\n\nReturns a random alternating tensor from the universal tensor space $\\prod_{k=1}^n R^d \\rightarrowtail R^c$. \nIf $S$ is given instead, then we assume $S=[d,\\dots,d,c]$.\nThe returned tensor has the homotopism category but fuses every module in the domain.\nAn error is raised if $R$ does not have a random algorithm in Magma.\n\n\\index{RandomAntisymmetricTensor}\n\\begin{intrinsics}\nRandomAntisymmetricTensor(R, d, n, c) : Rng, RngIntElt, RngIntElt, RngIntElt -> TenSpcElt\nRandomAntisymmetricTensor(R, S) : Rng, [RngIntElt] -> TenSpcElt\n\\end{intrinsics}\n\nReturns a random antisymmetric tensor from the universal tensor space $\\prod_{k=1}^n R^d \\rightarrowtail R^c$. \nIf $S$ is given instead, then we assume $S=[d,\\dots,d,c]$.\nThe returned tensor has the homotopism category but fuses every module in the domain.\nAn error is raised if $R$ does not have a random algorithm in Magma.\n\n\\index{RandomSymmetricTensor}\n\\begin{intrinsics}\nRandomSymmetricTensor(R, d, n, c) : Rng, RngIntElt, RngIntElt, RngIntElt -> TenSpcElt\nRandomSymmetricTensor(R, S) : Rng, [RngIntElt] -> TenSpcElt\n\\end{intrinsics}\n\nReturns a random symmetric tensor from the universal tensor space $\\prod_{k=1}^n R^d \\rightarrowtail R^c$. \nIf $S$ is given instead, then we assume $S=[d,\\dots,d,c]$.\nThe returned tensor has the homotopism category but fuses every module in the domain.\nAn error is raised if $R$ does not have a random algorithm in Magma.\n\n\\begin{example}[RandomSymTen]\n\nWe just demonstrate how to use the \\texttt{RandomSymmetricTensor}. The other two\nintrinsics are the same. This is almost equivalent to constructing a random\ntensor whose category fuses all the modules in the domain and then applying\n\\texttt{SymmetricTensor}. In characteristic 2, all entries on the diagonal will\nbe 0, but with \\texttt{RandomSymmetricTensor} this is not the case.\n\\begin{code}\n> t := RandomSymmetricTensor(GF(2), 4, 2, 3);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over GF(2)\nU1 : Full Vector space of degree 4 over GF(2)\nU0 : Full Vector space of degree 3 over GF(2)\n> \n> TensorCategory(t);\nTensor category of valence 3 (->,->,->) ({ 0 },{ 1 .. 2 })\n> \n> SystemOfForms(t);\n[\n    [1 0 0 1]\n    [0 1 1 1]\n    [0 1 1 0]\n    [1 1 0 0],\n\n    [1 0 0 0]\n    [0 1 0 1]\n    [0 0 0 0]\n    [0 1 0 1],\n\n    [0 0 0 0]\n    [0 0 1 0]\n    [0 1 0 0]\n    [0 0 0 1]\n]\n> IsSymmetric(t);\ntrue\n\\end{code}\n\\end{example}\n\n\\subsection{Properties of tensor spaces}\n\nWe define some functions to access basic properties of tensor spaces.\n\n\\index{Valence!tensor space}\n\\begin{intrinsics}\nValence(T) : TenSpc -> RngIntElt\n\\end{intrinsics}\n\nReturns the valence of the tensor space.\n\n\\index{Frame!tensor space}\n\\begin{intrinsics}\nFrame(T) : TenSpc -> List\n\\end{intrinsics}\n\nReturns the list of modules in the frame of the tensor space.\n\n\\index{BaseRing!tensor space}\\index{BaseField!tensor space}\n\\begin{intrinsics}\nBaseRing(T) : TenSpc -> Rng\nBaseField(T) : TenSpc -> Fld\n\\end{intrinsics}\n\nReturns the base ring (or field) of the tensor space.\n\n\\begin{example}[TenSpcProperties]\n\nAs with tensors, we can obtain the basic tensor properties from a tensor space.\n\\begin{code}\n> T := KTensorSpace(Rationals(), [7,5,3,2]);\n> T;\nTensor space of dimension 210 over Rational Field with valence 4\nU3 : Full Vector space of degree 7 over Rational Field\nU2 : Full Vector space of degree 5 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> Valence(T);\n4\n> Frame(T);\n[*\n    Full Vector space of degree 7 over Rational Field,\n\n    Full Vector space of degree 5 over Rational Field,\n\n    Full Vector space of degree 3 over Rational Field,\n\n    Full Vector space of degree 2 over Rational Field\n*]\n> BaseRing(T);\nRational Field\n\\end{code}\n\\end{example}\n\n\n\\index{TensorCategory!tensor space}\n\\begin{intrinsics}\nTensorCategory(T) : TenSpc -> TenCat\n\\end{intrinsics}\n\nReturns the underlying tensor category of the tensor space.\n\n\\index{IsCovariant!tensor space}\\index{IsContravariant!tensor space}\n\\begin{intrinsics}\nIsCovariant(T) : TenSpc -> BoolElt\nIsContravariant(T) : TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if the underlying tensor category is covariant or contravariant.\n\n\\index{ChangeTensorCategory!tensor space}\n\\begin{intrinsics}\nChangeTensorCategory(T, C) : TenSpc, TenCat -> TenSpc\nChangeTensorCategory(~T, C) : TenSpc, TenCat -> \n\\end{intrinsics}\n\nReturns the tensor category with the given tensor category.\n\n\\begin{example}[TenSpcCategories]\n\nAgain, like with tensors, we can obtain categorical information from tensor spaces.\n\\begin{code}\n> T := KTensorSpace(Rationals(), [4,4,4]);\n> T;\nTensor space of dimension 64 over Rational Field with valence 3\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 4 over Rational Field\n> \n> TensorCategory(T);\nTensor category of valence 3 (->,->,->) ({ 1 },{ 2 },{ 0 })\n> C := TensorCategory([1,1,-1], {{0},{1,2}});\n> C;\nTensor category of valence 3 (->,->,<-) ({ 0 },{ 1, 2 })\n> \n> ChangeTensorCategory(~T, C);\n> T;\nTensor space of dimension 64 over Rational Field with valence 3\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 4 over Rational Field\n> TensorCategory(T);\nTensor category of valence 3 (->,->,<-) ({ 0 },{ 1, 2 })\n\\end{code}\n\\end{example}\n\n\n\\index{IsAlternating!tensor space}\n\\begin{intrinsics}\nIsAlternating(T) : TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if every tensor in the tensor space is an alternating tensor.\n\n\\index{IsAntisymmetric!tensor space}\n\\begin{intrinsics}\nIsAntisymmetric(T) : TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if every tensor in the tensor space is an antisymmetric tensor.\n\n\\index{IsSymmetric!tensor space}\n\\begin{intrinsics}\nIsSymmetric(T) : TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if every tensor in the tensor space is a symmetric tensor.\n\n\\index{UniversalTensorSpace}\\index{UniversalCotensorSpace}\\index{Generic}\n\\begin{intrinsics}\nUniversalTensorSpace(T) : TenSpc -> TenSpc\nUniversalCotensorSpace(T) : TenSpc -> TenSpc\nGeneric(T) : TenSpc -> TenSpc\n\\end{intrinsics}\n\nReturns the universal (co-)tensor space with the same frame and category as $T$.\n\n\\begin{example}[UniversalConst]\n\nWe construct the subspace of alternating tensors $S$ of the tensor space $T$\nwith the frame $\\mathbb{Q}^6\\times\\mathbb{Q}^6\\rightarrowtail \\mathbb{Q}^2$. We\nverify that the space is in fact alternating (i.e.\\ every tensor is\nalternating).\n\\begin{code}\n> T := KTensorSpace(Rationals(), [6,6,2]);\n> S := AlternatingSpace(T);\n> S;\nTensor space of dimension 30 over Rational Field with valence 3\nU2 : Full Vector space of degree 6 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> IsAlternating(S);\ntrue\n\\end{code}\n\nFrom $S$, we construct the universal tensor space $U$, which in this example is equal to $T$. \n\\begin{code}\n> U := UniversalTensorSpace(S);\n> U;\nTensor space of dimension 72 over Rational Field with valence 3\nU2 : Full Vector space of degree 6 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> U eq T;\ntrue\n\\end{code}\n\\end{example}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%=============================================================================\n\n\n\n\\chapter{Tensor categories}\\label{ch:tensor-categories}\n\nFollowing \\cite{FMW:densors}*{Section~5.7 \\& Section~7}, Magma allows tensors\nand tensor spaces to change categories. Unless a user specifies otherwise, all\ntensors are assigned a category that is natural to the method by which it was\ncreated. For example a tensor created from an algebra will be assigned an\nalgebra category, whereas a tensor created by structure constants will be\nassigned the homotopism category \\citelist{\\cite{Albert:Fundamentals}\n\\cite{Wilson:division} \\cite{FMW:densors}*{Section~5.7}}. Tensor categories\ninfluence the behavior of commands such as kernels and images as well as the\nalgebraic invariants such as derivation algebras of a tensor.  \n\nOur conventions follow \\citelist{\\cite{FMW:densors}*{Section~5.7} \\cite{Wilson:division}}.  In particular given\na tensor $t$ framed by $[U_{\\vav},\\dots,U_0]$ then a tensor category for\n$t$ will specify a function $A:\\zrange{\\vav}\\to \\{-1,0,1\\}$ along with\na partition $\\mathcal{P}$ of $\\zrange{\\vav}$ such that the following \nrules apply to the tensors and morphisms in the category.\n\\begin{enumerate}\n\\item for each tensor $t$ framed by $[U_{\\vav},\\dots,U_0]$, if\n$X\\in\\mathcal{P}$, then \n$$\\forall i,j\\in X,\\quad U_i=U_j.$$\n\n\\item Given a second tensor $s$ framed by $[V_{\\vav},\\dots,V_0]$,\na morphism $f:t\\to s$ (Magma type {\\tt Hmtp}) will be a list\n$[f_{\\vav},\\dots,f_0]$ of homomorphisms as follows:\n\\begin{itemize}\n\\item (Covariant) if $A(i)=1$ then $f_i:U_i\\to V_i$;\n\\item (Constant) if $A(i)=0$ then $U_i=V_i$ and $f_i=1_{U_i}$; or else\n\\item (Contravariant) $A(i)=-1$ and $f_i:U_i\\leftarrow V_i$.\n\\end{itemize}\nSo if $A(0)=1$ then\n\\begin{align*}\n\t\\left\\langle \\sum_{i\\in A^{-1}(1)} u_i f_i\n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j\\right\\rangle_S\n\t\t& = \\left\\langle  \\sum_{i\\in A^{-1}(1)} u_i \n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j f_j\\right\\rangle_T f_0;\n\\end{align*}\nif $A(0)=0$ then\n\\begin{align*}\n\t\\left\\langle \\sum_{i\\in A^{-1}(1)} u_i f_i\n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j\\right\\rangle_S\n\t\t& = \\left\\langle  \\sum_{i\\in A^{-1}(1)} u_i \n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j f_j\\right\\rangle_T;\n\\end{align*}\nelse $A(0)=-1$ and \n\\begin{align*}\n\t\\left\\langle \\sum_{i\\in A^{-1}(1)} u_i f_i\n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j\\right\\rangle_S f_0\n\t\t& = \\left\\langle  \\sum_{i\\in A^{-1}(1)} u_i \n\t\t+\\sum_{j\\not\\in A^{-1}(-1)} v_j f_j\\right\\rangle_T.\n\\end{align*}\n\\end{enumerate}\n\nMagma manages internally the differences between \nvectors and covectors and more generally tensors and cotensors.\nBoth types are issued the Magma type {\\tt TenSpcElt}.\nFor operations sensitive to the difference, Magma stores a value of\nco/contra-variance of the tensor as a property of the tensor category.\nThis the third general property stored in Magma's tensor category type\n{\\tt TenCat}.\n\nWe use the phrase tensor category exclusively for categories that describe tensors and tensor spaces.\nIn other words, the data structure of a tensor category is a function \n$A:\\zrange{\\vav}\\rightarrow \\{-1,0,1\\}$ and a partition $\\mathcal{P}$ of $\\zrange{\\vav}$.\nIt is useful to distinguish from tensors and cotensors at the categorical level,\nso a tensor category is either covariant or contravariant as well \n(in the latter case, referred to as a cotensor category).\n\n\\section{Constructing tensor categories}~\n\n\\index{TensorCategory!constructor}\n\\begin{intrinsics}\nTensorCategory(A, P) : [RngIntElt], {SetEnum} -> TenCat\nTensorCategory(A, P) : Map, {SetEnum} -> TenCat\n\\end{intrinsics}\n\nSets up a covariant tensor space category with specified direction of\narrows $A$, and a partition $\\mathcal{P}$ indicating variables to be treated as\nequivalent.  The fiber $A^{-1}(1)$ denotes the covariant variables,\n$A^{-1}(0)$ identifies the constant variables, and $A^{-1}(-1)$ marks\nthe contra-variant variables.  \n\n\\index{CotensorCategory!constructor}\n\\begin{intrinsics}\nCotensorCategory(A, P) : [RngIntElt], {SetEnum} -> TenCat\nCotensorCategory(A, P) : Map, {SetEnum} -> TenCat\n\\end{intrinsics}\n\nSets up a contra-variant tensor space category with specified direction of\narrows $A$, and a partition $\\mathcal{P}$ indicating variables to be treated as\nequivalent.  The fiber $A^{-1}(1)$ denotes the covariant variables,\n$A^{-1}(0)$ identifies the constant variables, and $A^{-1}(-1)$ marks\nthe contra-variant variables.  \n\n\\begin{example}[BasicCatConst]\n\nWe demonstrate the basic tensor category constructor. The only difference\nbetween \\texttt{TensorCategory} and \\texttt{CotensorCategory} is that the former\nis covariant and the latter is contravariant.\n\\begin{code}\n> C := TensorCategory([1,0,-1], {{0},{1},{2}});\n> C;\nTensor category of valence 3 (->,==,<-) ({ 1 },{ 2 },{ 0 })\n> IsCovariant(C);\ntrue\n> \n> arrows := map< {1..5} -> {1} | x :-> 1 >;\n> C := CotensorCategory(arrows, {{1..5}});\n> C;\nCotensor category of valence 6 (->,->,->,->,->,==) ({ 0 },{ 1 .. 5 })\n> IsContravariant(C);\ntrue\n\\end{code}\n\\end{example}\n\n\n\\index{HomotopismCategory}\n\\begin{intrinsics}\nHomotopismCategory(v : parameters) : RngIntElt -> TenCat\n    Contravariant : BoolElt : false\n\\end{intrinsics}\n\nReturns Albert's homotopism category -- all modules categories are covariant and\nno duplicates considered. Set the optional parameter {\\tt Contravariant} to {\\tt\ntrue} to make it a cotensor category.\n\n\\index{CohomotopismCategory}\n\\begin{intrinsics}\nCohomotopismCategory(v) : RngIntElt -> TenCat\n\\end{intrinsics}\n\nReturns the cohomotopism category -- all domain modules categories are \ncovariant, the codomain is contravariant, and no duplicates considered.\n\n\\index{AdjointCategory}\\index{LinearCategory}\n\\begin{intrinsics}\nAdjointCategory(v, s, t) : RngIntElt, RngIntElt, RngIntElt -> TenCat\nLinearCategory(v, s, t) : RngIntElt, RngIntElt, RngIntElt -> TenCat\n\\end{intrinsics}\n\nReturns the tensor category where all modules are constant except in position \n$s$ and $t$.  Both $s$ and $t$ are in $[v]$.\nPosition $s$ is covariant, position $t$ is contravariant.\n\n\\begin{example}[TenCatSpecial]\n\nNow we look at a few special tensor category constructors. The default tensor\ncategory is the homotopism category, so we construct the homotopism category\nusing \\texttt{TensorCategory} and verify they are equivalent.\n\\begin{code}\n> C := TensorCategory([1,1,1,1], {{i} : i in [0..3]});\n> C;\nTensor category of valence 4 (->,->,->,->) ({ 1 },{ 2 },{ 0 },{ 3 })\n> HomotopismCategory(4) eq C;\ntrue\n\\end{code}\n\nThe other special tensor categories can be constructed using\n\\texttt{TensorCategory} as well, but we just construct a few to show their\nproperties.\n\\begin{code}\n> CohomotopismCategory(3);\nTensor category of valence 3 (->,->,<-) ({ 1 },{ 2 },{ 0 })\n> \n> AdjointCategory(5, 4, 1);\nTensor category of valence 5 (<-,==,==,->,==) ({ 1 },{ 0, 2, 3 },{ 4 })\n\\end{code}\n\\end{example}\n\n\\section{Operations on tensor categories}\n\nWe have basic operations for tensor categories.\n\n\\index{eq!tensor category}\n\\begin{intrinsics}\nC1 eq C2 : TenCat, TenCat -> BoolElt\n\\end{intrinsics}\n\nDecides if the tensor categories are the same.\n\n\\index{Valence!tensor category}\n\\begin{intrinsics}\nValence(C) : TenCat -> RngIntElt\n\\end{intrinsics}\n\nReturns the valence of the tensor category.\n\n\\index{Arrows}\n\\begin{intrinsics}\nArrows(C) : TenCat -> SeqEnum\n\\end{intrinsics}\n\nReturns the sequence of arrows of the tensor category. A $-1$ signifies an a\ncontravariant index, a $0$ signifies a constant index, and a $1$ signifies a\ncovariant index.\n\n\\index{RepeatPartition}\n\\begin{intrinsics}\nRepeatPartition(C) : TenCat -> SetEnum\n\\end{intrinsics}\n\nReturns the repeat partition for the tensor category.\n\n\\index{IsCovariant!tensor category}\\index{IsContravariant!tensor category}\n\\begin{intrinsics}\nIsCovariant(C) : TenCat -> BoolElt\nIsContravariant(C) : TenCat -> BoolElt\n\\end{intrinsics}\n\nDecides if the tensor category is covariant or contravariant.\n\n\\begin{example}[TenCatProperties]\n\nWe obtain basic properties of tensor categories.\n\\begin{code}\n> C := CotensorCategory([1,0,-1,1],{{4,3},{1},{2}});\n> C;\nCotensor category of valence 5 (->,==,<-,->,==) ({ 1 },{ 2 },{ 0 },{ 3, 4 })\n> \n> Valence(C);\n5\n> Arrows(C);\n[ 1, 0, -1, 1 ]\n> IsContravariant(C);\ntrue\n> RepeatPartition(C);\n{\n    { 1 },\n    { 2 },\n    { 3, 4 }\n}\n\\end{code}\n\\end{example}\n\n\n\n\\section{Categorical operations}\n\nIn this section, we define subtensors, local ideals, ideals, and quotients of\ntensors. For the following definitions fix a tensor $t\\in T$, with frame\n$U_0\\oslash \\cdots\\oslash U_{\\vav}$---that is $U_{\\vav}\\times\\cdots\\times\nU_1\\rightarrowtail U_0$. \n\\begin{defn}\nA tensor $s:V_{\\vav}\\times \\cdots\\times V_1\\rightarrowtail V_0$ is a\n\\emph{subtensor} of $t$ if for all $a$, $V_a\\leq U_a$.\n\\end{defn}\n\n\\begin{defn}\nFor $A\\subseteq \\range{\\vav}$, a tensor $s:V_{\\vav}\\times \\cdots\\times\nV_1\\rightarrowtail V_0$ is an \\emph{$A$-local ideal} of $t$ if $s$ is a\nsubtensor of $t$ and for each $a\\in A$, \n\\[ \\langle s \\,|\\, V_{\\vav},\\dots, V_{a+1}, U_a, V_{a-1},\\dots, V_1\\rangle \\leq V_0 .\\]\n\\end{defn}\n\n\\begin{defn}\nA tensor $s$ is an \\emph{ideal} of $t$ if it is a $\\{1,\\dots,\\vav\\}$-local ideal of $t$. \n\\end{defn}\n\n\\begin{defn}\nThe \\emph{$A$-local quotient} of a tensor $t$ by an $A$-local ideal $s$ is the\ntensor $q:U_{\\vav}/V_{\\vav} \\times \\cdots \\times U_1/V_1\\rightarrowtail U_0/V_0$\nwhere for all $\\ket{\\overline{v}}$,\n\\[ \\langle q \\,|\\, \\overline{v}\\rangle \\equiv \\langle q \\,|\\, v\\rangle \\mod V_0. \\]\n\\end{defn}\n\n\\begin{defn}\nThe \\emph{quotient} of a tensor $t$ by an ideal $s$ is the $\\{1,\\dots,\\vav\\}$-local quotient of $t$ by $s$.\n\\end{defn}\n\n\\subsection{Categorical operations on tensors}\n\nWe include functions defined for the category of tensors.\nMost functions are currently defined only for the homotopism category.\n\n\\index{Subtensor}\n\\begin{intrinsics}\nSubtensor(t, S) : TenSpcElt, List -> TenSpcElt\nSubtensor(t, S) : TenSpcElt, SeqEnum -> TenSpcElt\n\\end{intrinsics}\n\nReturns the smallest submap of $t$ containing $S$.\n\n\\index{Subtensor}\n\\begin{intrinsics}\nSubtensor(t, D, C) : TenSpcElt, List, Any -> TenSpcElt\nSubtensor(t, D, C) : TenSpcElt, SeqEnum, Any -> TenSpcElt\n\\end{intrinsics}\n\nReturns the smallest submap of $t$ containing $D$ in the domain and $C$ in the \ncodomain.\n\n\\index{IsSubtensor}\n\\begin{intrinsics}\nIsSubtensor(t, s) : TenSpcElt, TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides whether $s$ is a subtensor of $t$.\n\n\\begin{example}[Subtensors]\n\nWe construct the tensor $t$ given by octonion multiplication. The quaternions\n$H=\\mathbb{H}$ are a subalgebra of $A=\\mathbb{O}$ generated by the first four\nbasis elements. However, $H$ cannot be coerced into $A$ because of how Magma\norganizes algebras. \n\\begin{code}\n> A := OctonionAlgebra(Rationals(), -1, -1, -1);\n> t := Tensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over Rational Field\nU1 : Full Vector space of degree 8 over Rational Field\nU0 : Full Vector space of degree 8 over Rational Field\n> H := sub< A | A.1, A.2, A.3, A.4 >;\n> H;\nAlgebra of dimension 4 with base ring Rational Field\n\\end{code}\n\nThere are multiple ways to get the subtensor of multiplication from $H$. We will\ncreate $H\\times H\\rightarrowtail H$ as a subtensor of $A\\times A\\rightarrowtail\nA$. \n\\begin{code}\n> H_gens := [A.i : i in [1..4]];\n> s := Subtensor(t, [*H_gens, H_gens, A!0*]);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 8, dimension 4 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nU1 : Vector space of degree 8, dimension 4 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nU0 : Vector space of degree 8, dimension 4 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\n\\end{code}\n\nNote that because $H$ cannot be coerced into $A$ (i.e.\\ \\texttt{A!H} produces an\nerror), a subtensor of \\texttt{AlgGen} cannot be done by \\texttt{Subtensor(t,\n[H, H, H])}. Now we will construct the tensor straight from $H$. There is a\nsubtle difference between the subtensor from $A$ and the tensor from\n$H$---namely, the frame is different.\n\\begin{code}\n> s2 := Tensor(H);\n> s2;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 4 over Rational Field\n> s eq s2;\nfalse\n> Eltseq(s) eq Eltseq(s2);\ntrue\n\\end{code}\n\\end{example}\n\n\n\\index{LocalIdeal}\n\\begin{intrinsics}\nLocalIdeal(t, S, A) : TenSpcElt, List, {RngIntElt} -> TenSpcElt\nLocalIdeal(t, S, A) : TenSpcElt, SeqEnum, {RngIntElt} -> TenSpcElt\n\\end{intrinsics}\n\nReturns the local ideal of $t$ at $A$ constraining $S$.\n\n\\index{LocalIdeal}\n\\begin{intrinsics}\nLocalIdeal(t, D, C, A) : TenSpcElt, List, Any, {RngIntElt} -> TenSpcElt\nLocalIdeal(t, D, C, A) : TenSpcElt, SeqEnum, Any, {RngIntElt} -> TenSpcElt\n\\end{intrinsics}\n\nReturns the local ideal of $t$ at $A$ constraining $D$ in the domain and $C$ \nin the codomain.\n\n\\index{LocalIdeal}\n\\begin{intrinsics}\nLocalIdeal(t, s, A) : TenSpcElt, TenSpcElt, {RngIntElt} -> TenSpcElt\n\\end{intrinsics}\n\nReturns the local ideal of $t$ at $A$ constraining $s$ as a submap.\n\n\n\\index{IsLocalIdeal}\n\\begin{intrinsics}\nIsLocalIdeal(t, s, A) : TenSpcElt, TenSpcElt, {RngIntElt} -> BoolElt\n\\end{intrinsics}\n\nDecides if $s$ is a local ideal of $t$ at $A$.\n\n\\begin{example}[LocalIdeals]\n\nWe use the same tensor $t$ as the previous example, multiplication in\n$A=\\mathbb{O}$, and we construct the subtensor $t_2$ given by multiplication in\n$\\mathbb{H}$. We construct a subtensor $s$ of $t$ as the submap containing\n$\\langle A_2\\rangle \\times \\langle A_1, A_4\\rangle \\rightarrowtail \\langle\n0\\rangle$, which is equal to  $\\langle A_2\\rangle \\times \\langle A_1, A_4\\rangle\n\\rightarrowtail \\langle A_2A_1, A_2A_4\\rangle$.\n\\begin{code}\n> A := OctonionAlgebra(Rationals(), -1, -1, -1);\n> t := Tensor(A);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over Rational Field\nU1 : Full Vector space of degree 8 over Rational Field\nU0 : Full Vector space of degree 8 over Rational Field\n> H_gens := [A.i : i in [1..4]];\n> t2 := Subtensor(t, [*H_gens, H_gens, H_gens*]);\n> s := Subtensor(t, [* A.2, [A.1, A.4], A!0 *]);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 8, dimension 1 over Rational Field\nGenerators:\n(0 1 0 0 0 0 0 0)\nEchelonized basis:\n(0 1 0 0 0 0 0 0)\nU1 : Vector space of degree 8, dimension 2 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nU0 : Vector space of degree 8, dimension 2 over Rational Field\nGenerators:\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\nEchelonized basis:\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n\\end{code}\n\nThe quaternions are a subalgebra of $A$ generated by $\\{A_1,A_2,A_3,A_4\\}$.\nTherefore, the $\\{2\\}$-local ideal of $s$ in $t$ must contain $A$ in the\ncodomain. However, the $\\{2\\}$-local ideal of $s$ in $t_2$ must only contain\n$\\langle A_1, A_2, A_3, A_4\\}$ in the codomain.\n\\begin{code}\n> s1 := LocalIdeal(t, s, {2});\n> Codomain(s1);\nFull Vector space of degree 8 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\n(0 0 0 0 1 0 0 0)\n(0 0 0 0 0 1 0 0)\n(0 0 0 0 0 0 1 0)\n(0 0 0 0 0 0 0 1)\n> s2 := LocalIdeal(t2, s, {2});\n> Codomain(s2);\nVector space of degree 8, dimension 4 over Rational Field\nGenerators:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0 0 0 0)\n(0 1 0 0 0 0 0 0)\n(0 0 1 0 0 0 0 0)\n(0 0 0 1 0 0 0 0)\n\\end{code}\n\\end{example}\n\n\n\\index{Ideal}\n\\begin{intrinsics}\nIdeal(t, S) : TenSpcElt, List -> TenSpcElt\nIdeal(t, S) : TenSpcElt, SeqEnum -> TenSpcElt\n\\end{intrinsics}\n\nReturns the ideal of $t$ containing $S$.\n\n\\index{Ideal}\n\\begin{intrinsics}\nIdeal(t, D, C) : TenSpcElt, List, Any -> TenSpcElt\nIdeal(t, D, C) : TenSpcElt, SeqEnum, Any -> TenSpcElt\n\\end{intrinsics}\n\nReturns the ideal of $t$ containing $D$ in the domain and $C$ in the codomain.\n\n\\index{Ideal}\n\\begin{intrinsics}\nIdeal(t, s) : TenSpcElt, TenSpcElt -> TenSpcElt\n\\end{intrinsics}\n\nReturns the ideal of $t$ containing $s$ as a submap.\n\n\\index{IsIdeal}\n\\begin{intrinsics}\nIsIdeal(t, s) : TenSpcElt, TenSpcElt -> BoolElt\n\\end{intrinsics}\n\nDecides if $s$ is an ideal of $t$.\n\n\\begin{example}[Ideals]\n\nFirst we will construct the tensor from the $\\mathbb{Q}$-algebra, $\\mathbb{Q}^5$. \n\\begin{code}\n> T := KTensorSpace(Rationals(), [5,5,5]);\n> A := VectorSpace(Rationals(), 5);\n> t := T!0;\n> for i in [1..5] do\nfor>   Assign(~t, [i,i,i], 1);\nfor> end for;\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 5 over Rational Field\nU1 : Full Vector space of degree 5 over Rational Field\nU0 : Full Vector space of degree 5 over Rational Field\n> SystemOfForms(t);\n[\n    [1 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0],\n\n    [0 0 0 0 0]\n    [0 1 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0],\n\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 1 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0],\n\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 1 0]\n    [0 0 0 0 0],\n\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 0]\n    [0 0 0 0 1]\n]\n\\end{code}\n\nNow we will construct the ideal tensor from the subtensor containing $\\langle\nA_1\\rangle \\times \\langle A_2\\rangle \\rightarrowtail \\langle A_3\\rangle$. Note\nthat the $\\{2\\}$-local ideal must include $\\langle A_2,A_3\\rangle$ in the\ncodomain, and the $\\{1\\}$-local ideal must contain $\\langle A_1,A_3\\rangle$ in\nthe codomain. \n\\begin{code}\n> s := Ideal(t, [A.1, A.2, A.3]);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 5, dimension 1 over Rational Field\nGenerators:\n(1 0 0 0 0)\nEchelonized basis:\n(1 0 0 0 0)\nU1 : Vector space of degree 5, dimension 1 over Rational Field\nGenerators:\n(0 1 0 0 0)\nEchelonized basis:\n(0 1 0 0 0)\nU0 : Vector space of degree 5, dimension 3 over Rational Field\nGenerators:\n(1 0 0 0 0)\n(0 1 0 0 0)\n(0 0 1 0 0)\nEchelonized basis:\n(1 0 0 0 0)\n(0 1 0 0 0)\n(0 0 1 0 0)\n\\end{code}\n\nFinally, we verify that the subtensor containing $\\langle A_1\\rangle \\times\n\\langle A_2\\rangle \\rightarrowtail \\langle A_2, A_3\\rangle$ is not an ideal. \n\\begin{code}\n> r := Subtensor(t, [A.1, A.2], [A.2, A.3]);\n> IsIdeal(t, r);\nfalse\n\\end{code}\n\\end{example}\n\n\\index{LocalQuotient}\n\\begin{intrinsics}\nLocalQuotient(t, s, A : parameters) : TenSpcElt, TenSpcElt, {RngIntElt} -> TenSpcElt, Hmtp\n    Check : BoolElt : true\n\\end{intrinsics}\n\nReturns the local quotient of $t$ by $s$ at $A\\subseteq\\range{\\vav}$. If you know $s$ is a local \nideal of $t$ at $A$, set {\\tt Check} to {\\tt false} to skip the verification.\nA homotopism is also returned, mapping from $t$ to $t/s$.\n\n\\index{Quotient!tensor}\\index{/!tensor}\n\\begin{intrinsics}\nQuotient(t, s : parameters) : TenSpcElt, TenSpcElt -> TenSpcElt, Hmtp\n    Check : BoolElt : true\nt / s : TenSpcElt, TenSpcElt -> TenSpcElt, Hmtp\n\\end{intrinsics}\n\nReturns the quotient of $t$ by $s$. If you know $s$ is an ideal of $t$, \nset {\\tt Check} to {\\tt false} to skip the verification.\nA homotopism is also returned, mapping from $t$ to $t/s$.\n\n\\begin{example}[Quotients]\n\nWe will demonstrate one of the most common uses of taking a quotient of tensors:\nconstructing the associated fully nondegenerate tensor. We first construct a\ntensor with a nontrivial radical given by matrix multiplication:\n$\\mathbb{M}_{3\\times 2}(\\mathbb{Q})\\times \\mathbb{Q}^3\\rightarrowtail\n\\mathbb{Q}^3$, where we take a projection of $\\mathbb{Q}^3$ onto $\\mathbb{Q}^2$\nin the 1 coordinate.\n\\begin{code}\n> K := Rationals();\n> F := [*KMatrixSpace(K, 3, 2), VectorSpace(K, 3), VectorSpace(K, 3)*];\n> mult := function(x)\nfunction>   return Transpose(x[1]*Matrix(2, 1, Eltseq(x[2])[2..3]));\nfunction> end function;\n> t := Tensor(F, mult);\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 6 over Rational Field\nU1 : Full Vector space of degree 3 over Rational Field\nU0 : Full Vector space of degree 3 over Rational Field\n> s := Subtensor(t, [*[F[1].1, F[1].4], F[2], F[3]*]);\n> s;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 6, dimension 2 over Rational Field\nGenerators:\n(1 0 0 0 0 0)\n(0 0 0 1 0 0)\nEchelonized basis:\n(1 0 0 0 0 0)\n(0 0 0 1 0 0)\nU1 : Full Vector space of degree 3 over Rational Field\nGenerators:\n(1 0 0)\n(0 1 0)\n(0 0 1)\nU0 : Full Vector space of degree 3 over Rational Field\nGenerators:\n(1 0 0)\n(0 1 0)\n(0 0 1)\n> IsFullyNondegenerate(s);\nfalse\n\\end{code}\n\nNow we will construct the ideal $r$ that evaluates to 0 and the largest subspace\nof $\\mathbb{Q}^3$ not contained in the image.\n\\begin{code}\n> r := Ideal(t, [*F[1]!0, F[2].1, F[3].3*]);\n> r;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 6, dimension 0 over Rational Field\nGenerators:\n\nU1 : Vector space of degree 3, dimension 1 over Rational Field\nGenerators:\n(1 0 0)\nEchelonized basis:\n(1 0 0)\nU0 : Vector space of degree 3, dimension 1 over Rational Field\nGenerators:\n(0 0 1)\nEchelonized basis:\n(0 0 1)\n> IsIdeal(t, r);\ntrue\n\\end{code}\n\nFinally, we quotient $s$ by $r$ to obtain a fully nondegenerate tensor.\n\\begin{code}\n> q := s/r;\n> q;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 2 over Rational Field\n> IsFullyNondegenerate(q);\ntrue\n\\end{code}\n\\end{example}\n\n\\subsection{Categorical operations on tensor spaces}\n\nWe have categorical notions for tensor spaces as well, and these are inherited\nfrom the module structure on tensor spaces.\n\n\\index{SubConstructor!tensor space}\\index{sub!tensor space}\n\\begin{intrinsics}\nSubConstructor(T, L) : TenSpc, Any -> TenSpc, Map\nsub< T | L > : TenSpc, Any -> TenSpc, Map\n\\end{intrinsics}\n\nReturns the subtensor space of $T$ generated by the tensors in the sequence $L$.\n\n\\index{IsSubtensorSpace}\n\\begin{intrinsics}\nIsSubtensorSpace(T, S) : TenSpc, TenSpc -> BoolElt\n\\end{intrinsics}\n\nDecides if the tensor space $S$ is a subtensor space of $T$.\n\n\\begin{example}[SubtensorSpaces]\n\nWe will construct the subspace $S$ of symmetric forms from the tensor space $T$\nwith frame $\\mathbb{Q}^2\\times\\mathbb{Q}^2\\rightarrowtail \\mathbb{Q}$.\n\\begin{code}\n> K := Rationals();\n> T := KTensorSpace(K, [2,2,1]);\n> T;\nTensor space of dimension 4 over Rational Field with valence 3\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> S := sub< T | T.1, T.2+T.3, T.4 >;\n> S;\nTensor space of dimension 3 over Rational Field with valence 3\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> IsSymmetric(S);\ntrue\n\\end{code}\n\nNow we will construct the subspace $A$ of alternating forms from $T$.\n\\begin{code}\n> A := sub< T | T.2-T.3 >;\n> A;\nTensor space of dimension 1 over Rational Field with valence 3\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> IsAlternating(A);\ntrue\n\\end{code}\n\nNow we verify that $A$ is not a subtensor space of $S$, and thus, we have\nconstructed a direct decomposition of $T$ into its symmetric and alternating\nspace.\n\\begin{code}\n> IsSubtensorSpace(S, A);\nfalse\n\\end{code}\n\\end{example}\n\n\\index{QuoConstructor!tensor space}\\index{quo!tensor space}\\index{/!tensor space}\n\\begin{intrinsics}\nQuoConstructor(T, X) : TenSpc, Any -> TenSpc, Map\nquo< T | X > : TenSpc, Any -> TenSpc, Map\nT / S : TenSpc, TenSpc -> TenSpc, Map\n\\end{intrinsics}\n\nReturns the quotient tensor space of $T$ by $S$.\n\n\\begin{example}[QuotientTensorSpaces]\n\nWe pick up with the same tensor spaces as the previous example: $T$ has frame\n$\\mathbb{Q}^2\\times\\mathbb{Q}^2\\rightarrowtail \\mathbb{Q}$, $S$ is the symmetric\nsubspace, and $A$ is the alternating subspace.\n\\begin{code}\n> K := Rationals();\n> T := KTensorSpace(K, [2,2,1]);\n> T;\nTensor space of dimension 4 over Rational Field with valence 3\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> S := sub< T | T.1, T.2+T.3, T.4 >;\n> A := sub< T | T.2-T.3 >;\n\\end{code}\n\nNow we construct the quotient of $T$ by $A$. The result is not a symmetric\ntensor space. Note that $Q_2$ is equivalent to a symmetric tensor modulo $A$,\nbut this choice is arbitrary.\n\\begin{code}\n> Q := T/A;\n> Q;\nTensor space of dimension 3 over Rational Field with valence 3\nU2 : Full Vector space of degree 2 over Rational Field\nU1 : Full Vector space of degree 2 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> SystemOfForms(Q.1);\n[\n    [1 0]\n    [0 0]\n]\n> SystemOfForms(Q.2);\n[\n    [0 0]\n    [1 0]\n]\n> SystemOfForms(Q.3);\n[\n    [0 0]\n    [0 1]\n]\n\\end{code}\n\\end{example}\n\n\\section{Homotopisms}\n\nMagma provides functions for homotopisms, i.e.\\ morphisms of tensors,\nsee definition in \\cite{FMW:densors}*{Sections~5.7 \\& 7}.\nHomotopisms are also equipped with a tensor category. Because homotopisms can\ncontain multiple maps between modules, it is not really clear what is meant by\nthe domain or codomain of a given homotopism. In this context, the \\emph{domain}\nof a homotopism $H$ will refer to the tensor, $\\bra{t}:U_{\\vav}\\times \\cdots \\times\nU_1\\rightarrowtail U_0$, where an arrow equal to $1$ at coordinate $a$ will mean\nthat the corresponding map at coordinate $a$ has domain equal to $U_a$. And in\nthe same vain, the tensor $\\bra{s}:V_{\\vav} \\times\\cdots \\times V_1\\rightarrowtail\nV_0$ is the \\emph{codomain} of $H$ if an arrow equal to $1$ at coordinate $a$\nimplies that the corresponding map at coordinate $a$ has codomain equal to\n$V_a$. \n\n\\subsection{Constructions of Homotopisms}~\n\n\\index{Homotopism}\n\\begin{intrinsics}\nHomotopism(t, s, M : parameters) : TenSpcElt, TenSpcElt, List -> Hmtp\n    Check : BoolElt : true\nHomotopism(t, s, M : parameters) : TenSpcElt, TenSpcElt, SeqEnum -> Hmtp\n    Check : BoolElt : true\nHomotopism(t, s, M, C : parameters) : TenSpcElt, TenSpcElt, List, TenCat -> Hmtp\n    Check : BoolElt : true\nHomotopism(t, s, M, C : parameters) : TenSpcElt, TenSpcElt, SeqEnum, TenCat -> Hmtp\n    Check : BoolElt : true\n\\end{intrinsics}\n\nReturns the homotopism from $t$ to $s$ given by the list of maps $M$ and the category $C$. \nThe default tensor category is the same as tensor categories for $t$ and $s$.\nIf the maps $M$ will produce a homotopism, then set \\texttt{Check} to \\texttt{false} to skip the verification.\n\n\\index{Homotopism}\n\\begin{intrinsics}\nHomotopism(M, C) : List, TenCat -> Hmtp\nHomotopism(M, C) : SeqEnum, TenCat -> Hmtp\n\\end{intrinsics}\n\nReturns the homotopism given by the maps in $M$ with tensor category $C$. \n\n\\index{IsHomotopism}\n\\begin{intrinsics}\nIsHomotopism(t, s, H) : TenSpcElt, TenSpcElt, Hmtp -> BoolElt\nIsHomotopism(t, s, M) : TenSpcElt, TenSpcElt, List -> BoolElt\nIsHomotopism(t, s, M) : TenSpcElt, TenSpcElt, SeqEnum -> BoolElt\nIsHomotopism(t, s, M, C) : TenSpcElt, TenSpcElt, List, TenCat -> BoolElt\nIsHomotopism(t, s, M, C) : TenSpcElt, TenSpcElt, SeqEnum, TenCat -> BoolElt\n\\end{intrinsics}\n\nDecides if the list of maps $M$ induces a homotopism from $t$ to $s$ in the tensor category $C$. \nThe default tensor category is the homotopism category. \nIf it does induce a homotopism, it is also returned.\n\n\\begin{example}[HomotopismConst]\n\nWe will construct two symmetric tensors\n$t,s:\\mathbb{F}_3^3\\times\\mathbb{F}_3^3\\rightarrowtail\\mathbb{F}_3^3$ and apply\npermutations to the bases.\n\\begin{code}\n> T := KTensorSpace(GF(3), [3,3,3]);\n> t := T.1+T.14+T.27;\n> SystemOfForms(t);\n[\n    [1 0 0]\n    [0 0 0]\n    [0 0 0],\n\n    [0 0 0]\n    [0 1 0]\n    [0 0 0],\n\n    [0 0 0]\n    [0 0 0]\n    [0 0 1]\n]\n> s := (T.4+T.10)+(T.8+T.20)+(T.18+T.24);\n> SystemOfForms(s);\n[\n    [0 1 0]\n    [1 0 0]\n    [0 0 0],\n\n    [0 0 1]\n    [0 0 0]\n    [1 0 0],\n\n    [0 0 0]\n    [0 0 1]\n    [0 1 0]\n]\n\\end{code}\n\nNow we construct a homotopism from $t$ to $t$ given by apply a permutation matrix in every coordinate.\n\\begin{code}\n> P := PermutationMatrix(GF(3), [2,1,3]);\n> H := Homotopism(t, t, [*P, P, P*]);\n> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: \n[0 1 0]\n[1 0 0]\n[0 0 1]\nU1 -> V1: \n[0 1 0]\n[1 0 0]\n[0 0 1]\nU0 -> V0: \n[0 1 0]\n[1 0 0]\n[0 0 1]\n\\end{code}\n\nNote that this permutation matrix does not induce a homotopism of $s$.\n\\begin{code}\n> IsHomotopism(s, s, [*P, P, P*]);\nfalse\n\\end{code}\n\\end{example}\n\n\\begin{example}[MixedHomotopisms] Homotopisms can take mixed categories of maps.\nTo reuse the above example, we can encode the permutation as a \\texttt{Map} and\nconstruct homotopisms from these types.\n\\begin{code}\n> V := VectorSpace(GF(3), 3);\n> T := TensorSpace([V, V, V]);\n> t := T.1+T.14+T.27;\n> P := PermutationMatrix(GF(3), [2,1,3]);\n> f := hom< V -> V | [<V.1, V.2>, <V.2, V.1>, <V.3, V.3>] >;\n> H := Homotopism(t, t, [*f, f, f*]);\n> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: Mapping from: Full Vector space of degree 3 over GF(3) to Full \nVector space of degree 3 over GF(3)\nU1 -> V1: Mapping from: Full Vector space of degree 3 over GF(3) to Full \nVector space of degree 3 over GF(3)\nU0 -> V0: Mapping from: Full Vector space of degree 3 over GF(3) to Full \nVector space of degree 3 over GF(3)\n\\end{code}\n\nFurthermore, we can input lists with types \\texttt{Mtrx} and \\texttt{Map} included.\n\\begin{code}\n> H2 := Homotopism(t, t, [*P, f, P*]);\n> H2;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: \n[0 1 0]\n[1 0 0]\n[0 0 1]\nU1 -> V1: Mapping from: Full Vector space of degree 3 over GF(3) to Full \nVector space of degree 3 over GF(3)\nU0 -> V0: \n[0 1 0]\n[1 0 0]\n[0 0 1]\n\\end{code}\n\\end{example}\n\n\n\\subsection{Basic Operations with Homotopisms}\n\nWe provide some operations for homotopisms.\n\n\\index{$*$!homotopism}\n\\begin{intrinsics}\nH1 * H2 : Hmtp, Hmtp -> Hmtp\n\\end{intrinsics}\n\nReturns the composition of the homotopisms $H_1$ and $H_2$.\n\n\\index{.!homotopisms}\n\\begin{intrinsics}\nH.a : Hmtp, RngIntElt -> Map\n\\end{intrinsics}\n\nReturns the map on the $a$th coordinate.\n\n\\begin{example}[HomotopismOps]\n\nWe construct a nondegenerate alternating form $t$ on $V=\\mathbb{Q}^6$. \nThe group of isometries are isomorphic to $\\Sp(6, \\mathbb{Q})$, the group generated by all transvections.\nWe construct a transvection $L$ and a corresponding matrix.\n\\begin{code}\n> V := VectorSpace(Rationals(), 6);\n> T := KTensorSpace(Rationals(), [6, 6, 1]);\n> t := T.2-T.7+T.16-T.21+T.30-T.35;\n> t;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 6 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> \n> u := V.2+2*V.3-V.5;\n> L := map< V -> V | x :-> x + (x*t*u)[1]*u >;\n> L;\nMapping from: ModTupFld: V to ModTupFld: V given by a rule [no inverse]\n> M := Matrix(6, 6, [V.i @ L : i in [1..6]]);\n> M;\n[ 1  1  2  0 -1  0]\n[ 0  1  0  0  0  0]\n[ 0  0  1  0  0  0]\n[ 0 -2 -4  1  2  0]\n[ 0  0  0  0  1  0]\n[ 0  1  2  0 -1  1]\n\\end{code}\n\nWe construct a homotopism from the transvection.\n\\begin{code}\n> H := Homotopism(t, t, [*L, L, IdentityMatrix(Rationals(), 1)*]);\n> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: Mapping from: Full Vector space of degree 6 over Rational Field to \nFull Vector space of degree 6 over Rational Field given by a rule [no inverse]\nU1 -> V1: Mapping from: Full Vector space of degree 6 over Rational Field to \nFull Vector space of degree 6 over Rational Field given by a rule [no inverse]\nU0 -> V0: \n[1]\n\\end{code}\n\nSince $H$ is an isometry of $t$, $H^2$ is also an isometry of $t$. \nWe verify that the 2-coordinate map of $H^2$ is exactly $M^2$.\n\\begin{code}\n> H2 := H*H;\n> H2;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: Mapping from: Full Vector space of degree 6 over Rational Field to \nFull Vector space of degree 6 over Rational Field\nComposition of Mapping from: Full Vector space of degree 6 over Rational Field \nto Full Vector space of degree 6 over Rational Field given by a rule [no \ninverse] and\nMapping from: Full Vector space of degree 6 over Rational Field to Full Vector \nspace of degree 6 over Rational Field given by a rule [no inverse]\nU1 -> V1: Mapping from: Full Vector space of degree 6 over Rational Field to \nFull Vector space of degree 6 over Rational Field\nComposition of Mapping from: Full Vector space of degree 6 over Rational Field \nto Full Vector space of degree 6 over Rational Field given by a rule [no \ninverse] and\nMapping from: Full Vector space of degree 6 over Rational Field to Full Vector \nspace of degree 6 over Rational Field given by a rule [no inverse]\nU0 -> V0: \n[1]\n> M2 := Matrix(6, 6, [V.i @ H2.2 : i in [1..6]]);\n> M2;\n[ 1  2  4  0 -2  0]\n[ 0  1  0  0  0  0]\n[ 0  0  1  0  0  0]\n[ 0 -4 -8  1  4  0]\n[ 0  0  0  0  1  0]\n[ 0  2  4  0 -2  1]\n> M^2 eq M2;\ntrue\n\\end{code}\n\\end{example}\n\n\\index{Precompose}\n\\begin{intrinsics}\nPrecompose(t, f, a) : TenSpcElt, Map, RngIntElt -> TenSpcElt\nPrecompose(t, M, a) : TenSpcElt, Mtrx, RngIntElt -> TenSpcElt\n\\end{intrinsics}\n\nIf $a>0$, then the tensor returned is the tensor that has been pre-composed by the map $f$ or matrix $M$. \n\n\n\\index{AT!homotopism}\n\\begin{intrinsics}\nt @ H : TenSpcElt, Hmtp -> TenSpcElt\n\\end{intrinsics}\n\nIf $H$ is a cohomotopism (a homotopism in the cohomotopism category), then\neither the domain or codomain of $H$ is returned, depending on the orientation\nof the arrows of $H$.\n\n\n\\subsection{Basic Properties of Homotopisms}~\n\n\\index{Domain!homotopism}\n\\begin{intrinsics}\nDomain(H) : Hmtp -> TenSpcElt\n\\end{intrinsics}\n\nReturns the domain tensor of $H$.\n\n\\index{Codomain!homotopism}\n\\begin{intrinsics}\nCodomain(H) : Hmtp -> TenSpcElt\n\\end{intrinsics}\n\nReturns the codomain tensor of $H$.\n\n\\index{Maps}\n\\begin{intrinsics}\nMaps(H) : Hmtp -> List\n\\end{intrinsics}\n\nReturns the list of maps for the various modules in the domain and codomain \ntensors.\n\n\\index{TensorCategory!homotopism}\n\\begin{intrinsics}\nTensorCategory(H) : Hmtp -> TenCat\n\\end{intrinsics}\n\nReturns the tensor category of $H$.\n\n\\index{ChangeTensorCategory!homotopism}\n\\begin{intrinsics}\nChangeTensorCategory(H, C) : Hmtp, TenCat -> Hmtp\nChangeTensorCategory(~H, C) : Hmtp, TenCat -> \n\\end{intrinsics}\n\nChanges the tensor category of $H$ to the given category.\n\n\\index{Valence!homotopism}\n\\begin{intrinsics}\nValence(H) : Hmtp -> RngIntElt\n\\end{intrinsics}\n\nReturns the valence of the underlying tensor category of the homotopism $H$. \n\n\\index{Kernel}\n\\begin{intrinsics}\nKernel(H) : Hmtp -> TenSpcElt, List\n\\end{intrinsics}\n\nReturns the kernel of $H$ as an ideal of its domain tensor.\n\n\\index{Image!homotopism}\n\\begin{intrinsics}\nImage(H) : Hmtp -> TenSpcElt, List\n\\end{intrinsics}\n\nReturns the image of $H$ as a submap of the codomain tensor.\n\n\\begin{example}[HomotopismProps]\n\nWe demonstrate how to access properties of a homotopism. We construct tensors\n$\\bra{t}:\\mathbb{Q}^4\\times\\mathbb{Q}^4\\rightarrowtail \\mathbb{Q}$ and\n$\\bra{s}:\\mathbb{Q}^6\\times\\mathbb{Q}^6\\rightarrowtail\\mathbb{Q}$ given by the dot\nproduct.\n\\begin{code}\n> t := Tensor(IdentityMatrix(Rationals(), 4), 2, 1);\n> s := Tensor(IdentityMatrix(Rationals(), 6), 2, 1);\n> Z := ZeroMatrix(Rationals(), 4, 6);\n> M := InsertBlock(Z, IdentityMatrix(Rationals(), 4), 1, 1);\n> H := Homotopism(t, s, [*M, M, IdentityMatrix(Rationals(), 1)*]);\n> H;\nMaps from U2 x U1 >-> U0 to V2 x V1 >-> V0.\nU2 -> V2: \n[1 0 0 0 0 0]\n[0 1 0 0 0 0]\n[0 0 1 0 0 0]\n[0 0 0 1 0 0]\nU1 -> V1: \n[1 0 0 0 0 0]\n[0 1 0 0 0 0]\n[0 0 1 0 0 0]\n[0 0 0 1 0 0]\nU0 -> V0: \n[1]\n\\end{code}\n\nLike with maps, we can obtain standard properties of homotopisms.\n\\begin{code}\n> Domain(H);\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 4 over Rational Field\nU1 : Full Vector space of degree 4 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> Codomain(H);\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 6 over Rational Field\nU1 : Full Vector space of degree 6 over Rational Field\nU0 : Full Vector space of degree 1 over Rational Field\n> Maps(H);\n[*\n    [1 0 0 0 0 0]\n    [0 1 0 0 0 0]\n    [0 0 1 0 0 0]\n    [0 0 0 1 0 0],\n\n    [1 0 0 0 0 0]\n    [0 1 0 0 0 0]\n    [0 0 1 0 0 0]\n    [0 0 0 1 0 0],\n\n    [1]\n*]\n> TensorCategory(H);\nTensor category of valence 3 (->,->,->) ({ 1 },{ 2 },{ 0 })\n\\end{code}\n\nWhen the image and kernel can be computed for the each of the maps in the\nhomotopism, then the image and kernel can be computed for the homotopism.\n\\begin{code}\n> Im := Image(H);\n> Im;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 6, dimension 4 over Rational Field\nEchelonized basis:\n(1 0 0 0 0 0)\n(0 1 0 0 0 0)\n(0 0 1 0 0 0)\n(0 0 0 1 0 0)\nU1 : Vector space of degree 6, dimension 4 over Rational Field\nEchelonized basis:\n(1 0 0 0 0 0)\n(0 1 0 0 0 0)\n(0 0 1 0 0 0)\n(0 0 0 1 0 0)\nU0 : Full Vector space of degree 1 over Rational Field\n> Ker := Kernel(H);\n> Ker;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Vector space of degree 4, dimension 0 over Rational Field\nU1 : Vector space of degree 4, dimension 0 over Rational Field\nU0 : Vector space of degree 1, dimension 0 over Rational Field\n\\end{code}\n\\end{example}\n\n\n\\index{Shuffle!homotopism}\n\\begin{intrinsics}\nShuffle(H, g) : Hmtp, GrpPermElt -> Hmtp\nShuffle(H, g) : Hmtp, [RngIntElt] -> Hmtp\n\\end{intrinsics}\n\nJust like the shuffle for tensors, this returns the shuffle of the homotopism $H$.\nThis is a functor from one tensor category to another and changes the order of the maps to\n\\[ \\{H_{\\vav^g},\\dots, H_{1^g}, H_{0^g}\\}. \\]\nIn order to be defined, $g\\in\\text{Sym}(\\{0,\\dots,\\vav \\})$. \nIf $0^g\\ne 0$, then both the image and pre-image of $0$ under $g$ will be replaced by their $K$-dual space.\nFor cotensors, $g\\in\\text{Sym}(\\{1,\\dots,\\vav\\})$.\nSequences $[a_1,\\dots,a_{\\vav+1}]$ will be interpreted as \n\\[ \\begin{array}{cccc} 0 & 1 & \\cdots & \\vav \\\\ \\downarrow & \\downarrow & & \\downarrow \\\\ a_1 & a_2 & \\cdots & a_{\\vav+1}. \\end{array}\\]\n\n", "meta": {"hexsha": "e1e005222d6c80dd53d023dd5c7cff539c3ef40a", "size": 68551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tensor-spc-cat.tex", "max_stars_repo_name": "algeboy/TensorSpace", "max_stars_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-14T03:24:16.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-04T01:51:36.000Z", "max_issues_repo_path": "doc/tensor-spc-cat.tex", "max_issues_repo_name": "algeboy/eMAGma", "max_issues_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-06-16T20:19:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-08T22:56:11.000Z", "max_forks_repo_path": "doc/tensor-spc-cat.tex", "max_forks_repo_name": "algeboy/eMAGma", "max_forks_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_forks_repo_licenses": ["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.7128136201, "max_line_length": 136, "alphanum_fraction": 0.6970284897, "num_tokens": 24347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6242048268831647}}
{"text": "\\chapter{Parametric Inference}\n\n\\begin{ex}\n  Recall that if $X\\sim\\text{Gamma}(\\alpha,\\beta)$, then by Exercise 3.12,\n  \\[\n    \\E{X}=\\alpha\\beta,\\quad\n    \\E{X^2} =\\alpha(\\alpha+1)\\beta^2\n    =(\\alpha\\beta)^2+(\\alpha\\beta)\\beta.\n  \\]\n  Recall that $\\alphahat_1=\\frac{1}{n}\\sum_{i=1}^n X_i$ and\n  $\\alphahat_2=\\frac{1}{n}\\sum_{i=1}^n X_i^2$. Then,\n  \\[\n    \\begin{cases}\n      \\alphahat_1 = \\alphahat\\betahat \\\\\n      s = \\alphahat_1^2+\\alphahat_1\\betahat\n    \\end{cases} \\implies\n    \\begin{cases}\n      \\alphahat_1 = \\alphahat\\betahat \\\\\n      \\betahat = (\\alphahat_2 - \\alphahat_1^2)/\\alphahat_1\n    \\end{cases} \\implies\n    \\begin{cases}\n      \\alphahat = \\alphahat_1^2/(\\alphahat_2-\\alphahat_1^2) \\\\\n      \\betahat = (\\alphahat_2-\\alphahat_1^2)/\\alphahat_1\n    \\end{cases}.\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Recall that if $X\\sim\\text{Uniform}(a, b)$,\n          \\[\n            \\E{X}=(a+b)/2,\\text{ and } \\E{X^2}=\\var{X}+\\E{X}^2=(a^2+ab+b^2)/3.\n          \\]\n          Then,\n          \\begin{align*}\n            \\begin{cases}\n              \\alphahat_1 = (\\ahat + \\bhat)/2                 \\\\\n              \\alphahat_2 = (\\ahat^2 + \\ahat\\bhat +\\bhat^2)/3 \\\\\n            \\end{cases}\\implies\n            \\begin{cases}\n              2\\alphahat_1 - \\ahat = \\bhat              \\\\\n              4\\alphahat_1^2 -3\\alphahat_2 = \\ahat\\bhat \\\\\n            \\end{cases}\\implies\n            \\begin{cases}\n              2\\alphahat_1 - \\ahat = \\bhat                            \\\\\n              \\ahat^2-2\\alphahat_1\\ahat+4\\alphahat_1^2-3\\alphahat_2=0 \\\\\n            \\end{cases},\n          \\end{align*}\n          or solving the quadratic equation,\n          \\[\n            \\ahat=\\alphahat_1\\pm \\sqrt{3}\\sqrt{\\alphahat_2-\\alphahat_1^2}.\n          \\]\n          Note that then $\\bhat$ is the other solution to the quadratic\n          equation, and, since $b\\geq a$, we have\n          \\[\n            \\ahat=\\alphahat_1- \\sqrt{3}\\sqrt{\\alphahat_2-\\alphahat_1^2},\n            \\quad\n            \\bhat=\\alphahat_1+ \\sqrt{3}\\sqrt{\\alphahat_2-\\alphahat_1^2}.\n          \\]\n    \\item Let $\\theta=(a,b)$. Note that then\n          \\[\n            \\L_n(\\theta)=\\prod_{i=1}^n \\frac{I_{[a, b]}(x_i)}{b-a}\n            =\\begin{cases}\n              (b-a)^{-n} & \\text{$x_i\\in [a, b]$ for all $i$}, \\\\\n              0          & \\text{otherwise}.\n            \\end{cases}\n          \\]\n          Thus, to maximize $\\L_n(\\theta)$, we must have $a\\leq X_{(1)}$ and\n          $b\\geq X_{(n)}$. Moreover, note that $\\L_n(\\theta)$ increases as $b$\n          increases, and decreases as $a$ increases. Therefore,\n          $\\ahat= X_{(1)}$ and $\\bhat= X_{(n)}$.\n    \\item Let $\\theta=(a, b)$. Note that then\n          $\\tau(\\theta)=\\int\\!x\\,\\d{F}(x)=\\E{X}=(a+b)/2$. However, by the\n          equivariance of the maximum likelihood estimator, $\\tauhat\n            =g(\\thetahat)=(X_{(1)}+X_{(n)})/2$.\n    \\item Recall that the plug-in estimator of the mean is given by the sample\n          average and that, by Example 7.10,\n          \\[\n            \\E{\\widetilde{\\tau}}   = (a + b) / 2,\\quad\n            \\var{\\widetilde{\\tau}} = \\frac{\\sigma^2_X}{n}\n            =\\frac{1}{n}\\frac{(b-a)^2}{12}.\n          \\]\n          Hence,\n          \\[\n            \\mse{\\tauhat}\n            =\\bias{\\tauhat}^2\n            +\\var{\\tauhat}\n            =\\frac{1}{n}\\frac{(b-a)^2}{12}.\n          \\]\n          \\inputminted{python}{../code/09-02.py}\n          \\inputminted{text}{../output/09-02.txt}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Let $X\\sim N(\\mu,\\sigma^2)$. Then\n          \\[\n            0.95\n            =\\P{X<\\tau}\n            =\\P{\\frac{X-\\mu}{\\sigma}<\\frac{\\tau-\\mu}{\\sigma}}\n            =\\Phi\\left(\\frac{\\tau-\\mu}{\\sigma} \\right),\n          \\]\n          or,\n          \\[\n            \\tau=\\Phi^{-1}(0.95)\\sigma+\\mu.\n          \\]\n\n          Recall that by Example 9.11, the maximum likelihood estimators for $X$\n          are\n          \\[\n            \\muhat = \\Xbar,\\text{ and }\n            \\sigmahat = S,\n          \\]\n          and that therefore by the equivariance of the MLE,\n          \\[\n            \\widehat{\\tau}=1.645\\cdot S+\\Xbar.\n          \\]\n    \\item We will use the delta method. Note that by Exercise 9.8,\n          \\[\n            I_n(\\mu,\\sigma)\n            =\\begin{pmatrix}\n              \\frac{n}{\\sigma^2} & 0                   \\\\\n              0                  & \\frac{2n}{\\sigma^2}\n            \\end{pmatrix},\n          \\]\n          and that therefore\n          \\[\n            J_n=I^{-1}_n(\\mu,\\sigma)\n            =\\frac{1}{n}\\begin{pmatrix}\n              \\sigma^2 & 0                  \\\\\n              0        & \\frac{\\sigma^2}{2}\n            \\end{pmatrix}.\n          \\]\n          Let $g(\\mu,\\sigma)=1.645 \\sigma+\\mu$. Note that\n          $\\nabla g=(1, 1.645)$, and that therefore\n          \\begin{align*}\n            \\widehat{\\textsf{se}}(\\widehat{\\tau})\n             & =\\sqrt{\\begin{pmatrix}\n                1 & 1.645 \\\\\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                \\sigmahat^2 & 0                     \\\\\n                0           & \\frac{\\sigmahat^2}{2}\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                1 \\\\ 1.645\n              \\end{pmatrix}}\n            =\\frac{1.534\\sigmahat}{\\sqrt{n}}.\n          \\end{align*}\n\n          Therefore,\n          \\[\n            C_n=\\left(\n            1.645\\cdot S+\\Xbar-z_{\\alpha/2}\\frac{1.534 S}{\\sqrt{n}},\n            1.645\\cdot S+\\Xbar+z_{\\alpha/2}\\frac{1.534 S}{\\sqrt{n}}\n            \\right).\n          \\]\n    \\item~\n          \\inputminted{python}{../code/09-03.py}\n          \\inputminted{text}{../output/09-03.txt}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Uniform}(0,\\theta)$. Recall that the maximum\n  likelihood estimator for $\\theta$ is given by the maximum of the examples, and\n  that therefore, for $0<\\epsilon<\\theta$,\n  \\begin{align*}\n    \\P{\\left|\\widehat{\\theta}_n-\\theta\\right|>\\epsilon}\n     & =\\P{\\widehat{\\theta}_n < \\theta-\\epsilon}                 \\\\\n     & =\\P{X_1 < \\theta-\\epsilon}\\cdots\\P{X_n < \\theta-\\epsilon} \\\\\n     & =\\left(\\frac{\\theta-\\epsilon}{\\theta}\\right)^n            \\\\\n     & =\\left(1-\\frac{\\epsilon}{\\theta}\\right)^n\n  \\end{align*}\n  which goes to $0$ as $n$ goes to infinity. Hence,\n  $\\widehat{\\theta}_n\\xrightarrow{P} \\theta$, and therefore the maximum\n  likelihood estimator is consistent.\n\\end{ex}\n\n% 5\n\\begin{ex}\n  Let $X\\sim\\text{Poisson}(\\lambda)$. Recall that then\n  \\[\n    f_X(x)=\\frac{\\lambda^x e^{-\\lambda}}{x!},\n  \\]\n  and that\n  \\[\n    \\E{X}\n    =\\sum_{x=0}^\\infty x\\frac{\\lambda^x e^{-\\lambda}}{x!}\n    =\\lambda\\sum_{x=1}^\\infty \\frac{\\lambda^{x-1} e^{-\\lambda}}{(x-1)!}\n    =\\lambda.\n  \\]\n  Hence, the method of moments estimator for $\\lambda$ is given by $\\Xbar$.\n\n  Note that\n  \\[\n    \\ell(\\lambda)\n    =\\log\\left(\\frac{\\lambda^X e^{-\\lambda}}{X!}\\right)\n    =X\\log{\\lambda}-\\lambda-\\log{X!},\n  \\]\n  and that therefore\n  \\[\n    \\frac{\\pd}{\\pd\\lambda}\\ell(\\lambda)\n    =X/\\lambda-1.\n  \\]\n  Hence,\n  \\[\n    0=\\ell_n(\\lambda)=\\sum_{i=1}^n(X_i/\\lambda -1)\n  \\]\n  implies that\n  \\[\n    n=(n/\\lambda)\\Xbar\n  \\]\n  or\n  \\[\n    \\lambda=\\Xbar.\n  \\]\n  This is a maximum since the second derivative is negative. Hence,\n  $\\widehat{\\lambda}=\\Xbar$.\n\n  Finally, note that\n  \\[\n    I(\\lambda)=-\\E{\\frac{\\pd^2}{\\pd\\lambda^2}\\ell(\\lambda)}\n    =-\\E{-X/\\lambda^2}=\\lambda^{-1}.\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item We have\n          \\[\n            \\psi=\\P{Y_1=1}=\\P{X_1>0}=\\P{X_1-\\theta>-\\theta}=1-\\Phi(-\\theta)\n            =\\Phi(\\theta).\n          \\]\n          Recall that the maximum likelihood estimator for $\\theta$ is\n          $\\overline{X}=\\frac{1}{n}\\sum_{i=1}^nX_i$. Therefore, by the\n          equivariance of the maximum likelihood, it follows that\n          $\\widehat{\\psi}=\\Phi(\\overline{X})$.\n    \\item We will use the delta method. Note that\n          $\\psi=g(\\theta)=\\Phi(\\theta)$, and that therefore\n          $g'(\\theta)=\\phi(\\theta)$. By Exercise 9.8, $I_n(\\theta)=n$, and\n          thus $\\widehat{\\textsf{se}}(\\widehat{\\theta})=\\sqrt{1/n}$. Hence,\n          \\[\n            \\widehat{\\textsf{se}}(\\widehat{\\psi})=\\phi(\\overline{X})/\\sqrt{n}.\n          \\]\n          Therefore, a $95\\%$ confidence interval for $\\psi$ is\n          \\[\n            C_n=\\left(\n            \\Phi(\\overline{X})-z_{0.05/2}\\phi(\\overline{X})/\\sqrt{n},\n            \\Phi(\\overline{X})+z_{0.05/2}\\phi(\\overline{X})/\\sqrt{n}\n            \\right).\n          \\]\n    \\item Since $\\E{Y_i}=\\P{Y_i=1}=\\P{Y_1=1}=\\psi$, and $\\psihat$ is an\n          average of $Y_i$'s, the result follows by the law of large numbers.\n    \\item We have\n          \\[\n            \\var{\\psihat}\n            =\\var{\\frac{1}{n}\\sum_{i=1}^n Y_i}\n            =\\frac{1}{n^2}\\sum_{i=1}^n \\var{Y_i}\n            =\\frac{\\Phi(\\theta)(1-\\Phi(\\theta))}{n}.\n          \\]\n          Thus,\n          \\[\n            \\textsc{are}(\\widehat{\\psi},\\widetilde{\\psi})\n            =\n            \\frac{\\var{\\widetilde{\\psi}}}{\\var{\\widehat{\\psi}}}\n            =\\frac{\\Phi(\\theta)(1-\\Phi(\\theta))}{\\phi^2(\\theta)}.\n          \\]\n    \\item We have that $\\E{\\overline{X}}=\\E{X_i}=\\mu_X$, and therefore\n          $\\widehat{\\psi}$ still converges to $\\Phi(\\mu_X)$ by\n          the law of large numbers. However, $\\psi=\\P{Y_1=1}=\n            \\P{X_i>0}=1-F_X(0)$, where\n          $\\Phi(\\mu_X)\\neq 1-F_X(0)$ for an arbitrary $F_X$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Let $X\\sim\\text{Binomial(n, p)}$. Note that then\n          \\[\n            f_{X}(x)=\\binom{n}{x}p^x(1-p)^{n-x}\n          \\]\n          and that therefore\n          \\[\n            \\ell_X(p)=\\log\\left[\\binom{n}{X}\\right]+X\\log{p}+(n-X)\\log(1-p),\n          \\]\n          and\n          \\[\n            \\frac{\\pd}{\\pd p}\\ell(p)=X/p-(n-X)/(1-p).\n          \\]\n          Setting $\\frac{\\pd}{\\pd p}\\ell(p)$ equal to $0$ and solving for $p$,\n          we get that $\\widehat{p}=X/n$ is the maximum likelihood estimator\n          for a Binomial distribution.\n\n          Next, let $X_1\\sim\\text{Binomial}(n_1, p_1)$ and\n          $X_2\\sim\\text{Binomial}(n_1, p_1)$ as in the problem. Since $X_1$ and\n          $X_2$ are independent, it follows that the maximum likelihood\n          estimator for $(p_1,p_2)$ is $(X_1/n_1, X_2/n_2$. Hence, by the\n          equivariance of the maximum likelihood estimator, since\n          $\\psi=g(p_1,p_2)=p_1-p_2$, $\\widehat{\\psi}=X_1/n_1-X_2/n_2$.\n    \\item The density for the joint distribution is\n          \\[\n            f_{X_1,X_2}(x_1,x_2)=\n            \\left[\\binom{n_1}{x_1}p_1^{x_1}(1-p_1)^{n_1-x_1}\\right]\n            \\left[\\binom{n_2}{x_2}p_2^{x_2}(1-p_2)^{n_2-x_2}\\right],\n          \\]\n          and therefore\n          \\begin{align*}\n            \\ell_{X_1,X_2}(p_1,p_2)\n             & =\\log\\left[\\binom{n_1}{X_1}\\right]+X_1\\log{p_1}+(n_1-X_1)\\log(1-p_1)       \\\\\n             & \\quad+\\log\\left[\\binom{n_2}{X_2}\\right]+X_2\\log{p_2}+(n_2-X_2)\\log(1-p_2).\n          \\end{align*}\n          Hence,\n          \\begin{align*}\n            H_{11}\n            =\\frac{\\pd^2 \\ell_{X_1,X_2}}{\\pd p_1^2}\n            =-\\frac{X_1}{p_1^2}-\\frac{n_1-X_1}{(1-p_1)^2},\n          \\end{align*}\n          and\n          \\begin{align*}\n            -\\E{H_{11}}\n            =\\frac{np_1}{p_1^2}+\\frac{n_1-n_1p_1}{(1-p_1)^2}\n            =\\frac{n_1}{p_1}+\\frac{n_1}{1-p_1}\n            =\\frac{n_1}{p_1(1-p_1)}.\n          \\end{align*}\n          By symmetry, we also have\n          \\[\n            -\\E{H_{22}}\n            =\\frac{n_2}{p_2(1-p_2)},\n          \\]\n          and by independence, it follows that\n          \\[\n            H_{12}=H_{21}=0.\n          \\]\n\n          Therefore,\n          \\begin{align*}\n            I(p_1, p_2)\n             & =\\begin{pmatrix}\n              \\frac{n_1}{p_1(1-p_1)} & 0                      \\\\\n              0                      & \\frac{n_2}{p_2(1-p_2)}\n            \\end{pmatrix}.\n          \\end{align*}\n    \\item Recall that $\\psi=g(p_1,p_2)=p_1-p_2$, and therefore\n          $\\nabla g=(1,-1)$. Hence, by the multiparameter delta method\n          \\[\n            \\widehat{\\textsf{se}}(\\widehat{\\psi})\n            =\\sqrt{\n              \\begin{pmatrix}\n                1 & -1\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                \\frac{p_1(1-p_1)}{n_1} & 0                      \\\\\n                0                      & \\frac{p_2(1-p_2)}{n_2}\n              \\end{pmatrix}\n              \\begin{pmatrix}\n                1 \\\\ -1\n              \\end{pmatrix}\n            }\n            =\\sqrt{\\frac{p_1(1-p_1)}{n_1} + \\frac{p_2(1-p_2)}{n_2}}.\n          \\]\n    \\item\n          \\inputminted{python}{../code/09-07.py}\n          \\inputminted{text}{../output/09-07.txt}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $X\\sim N(\\mu,\\sigma^2)$. Let $\\theta=(\\mu,\\sigma)$. Note that then\n  \\[\n    \\ell(\\theta)\n    =-\\frac{1}{2}\\frac{(x-\\mu)^2}{\\sigma^2}+\\log{\\frac{1}{\\sigma\\sqrt{2\\pi}}},\n  \\]\n  and, therefore\n  \\[\n    H_{11}\n    =\\frac{\\pd^2\\ell_n}{\\pd\\mu^2}\n    =-\\frac{n}{\\sigma^2},\\quad\n    \\E{H_{11}} =-\\frac{n}{\\sigma^2},\n  \\]\n  \\[\n    H_{22}\n    =\\frac{\\pd^2\\ell_n}{\\pd\\sigma^2}\n    =\\frac{n}{\\sigma^2}-\\frac{3n(x-\\mu)^2}{\\sigma^4},\\quad\n    \\E{H_{22}}=\\frac{n}{\\sigma^2}-\\frac{3n\\E{(x-\\mu)^2}}{\\sigma^4}\n    =-\\frac{2n}{\\sigma^2},\n  \\]\n  \\[\n    H_{12}\n    =\\frac{\\pd^2\\ell_n}{\\pd\\mu\\pd\\sigma}\n    =\\frac{\\pd}{\\pd\\mu}\\left[\\frac{n(x-\\mu)^2-n\\sigma^2}{\\sigma^2}\\right]\n    =-\\frac{2n(x-\\mu)}{\\sigma^3},\\quad\n    \\E{H_{12}} = 0,\n  \\]\n  \\[\n    H_{21}\n    =\\frac{\\pd^2\\ell_n}{\\pd\\sigma\\pd\\mu}\n    =\\frac{\\pd}{\\pd\\sigma}\\left[-\\frac{n(x-\\mu)}{\\sigma^2}\\right]\n    =-\\frac{2n(x-\\mu)}{\\sigma^3},\\quad\n    \\E{H_{21}} = 0.\n  \\]\n\n  Hence,\n  \\[\n    I_n(\\mu,\\sigma)\n    =\\begin{pmatrix}\n      \\frac{n}{\\sigma^2} & 0                   \\\\\n      0                  & \\frac{2n}{\\sigma^2}\n    \\end{pmatrix}.\n  \\]\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item Recall that for $X_1,\\ldots,X_n\\sim N(0,\\sigma^2)$,\n          $I_n(\\mu)=n/\\sigma^2$, and therefore, since $g(\\mu)=e^\\mu$,\n          $g'=e^\\mu$ and by the delta method,\n          \\[\n            \\widehat{\\textsf{se}}(\\widehat{\\theta})\n            =\\frac{e^{\\Xbar}S}{\\sqrt{n}},\n          \\]\n          and\n          \\[\n            C_n=\\left(\n            e^{\\Xbar}-z_{\\alpha/2}\\frac{e^{\\Xbar}S}{\\sqrt{n}},\n            e^{\\Xbar}+z_{\\alpha/2}\\frac{e^{\\Xbar}S}{\\sqrt{n}}\n            \\right),\n          \\]\n          is a $1-\\alpha$ confidence interval for $\\widehat{\\theta}$.\n\n          \\inputminted{python}{../code/09-09.py}\n          \\inputminted{text}{../output/09-09.txt}\n    \\item~\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.53]{../images/09-09}\n            \\caption{A comparison of a histogram of the true distribution of\n              $\\widehat{\\theta}$ (upper left), non-parametric bootstrap\n              replicates (lower left), parametric bootstrap replicates\n              (lower right) and a plot of the delta method distribution\n              (upper right).}\n          \\end{figure}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}~\n  \\begin{enumerate}[(a)]\n    \\item We have\n          \\begin{align*}\n            \\P{\\widehat{\\theta}\\leq x}\n             & =\\P{X_{(n)}\\leq x}                               \\\\\n             & =\\P{X_{1}\\leq x}\\P{X_2\\leq x}\\cdots\\P{X_n\\leq x} \\\\\n             & =x^n,\n          \\end{align*}\n          and therefore\n          \\[\n            f_{\\widehat{\\theta}}(x)=nx^{n-1}. \\\\\n          \\]\n\n          \\inputminted{python}{../code/09-10.py}\n\n          \\begin{figure}[H]\n            \\centering\n            \\includegraphics[scale=0.53]{../images/09-10}\n            \\caption{\n              A comparison of a histogram of the non-parametric bootstrap\n              (left), the parametric bootstrap (center) and the true\n              distribution of $\\widehat{\\theta}$ (right).}\n          \\end{figure}\n    \\item Let $B$ be a random variable given by uniformly randomly sampling\n          from $\\{X_1,X_2,\\ldots,X_n\\}$, and let $B^n$ be a sample (with\n          replacement) of $n$ elements. Then,\n          \\begin{align*}\n            \\P{\\widehat{\\theta}^*=\\widehat{\\theta}}\n             & =\\P{X_{(n)}\\in B^n}              \\\\\n             & =1-\\P{X_{(n)}\\not\\in B^n}        \\\\\n             & =1-(1-\\P{B = X_{(n)}})^n         \\\\\n             & =1-\\left(1-\\frac{1}{n}\\right)^n,\n          \\end{align*}\n          and therefore\n          \\[\n            \\lim_{n\\to\\infty}\\P{\\widehat{\\theta}^*\n              =\\widehat{\\theta}}\n            =1-e^{-1}\n            \\approx 0.632.\n          \\]\n          However, since $\\widehat{\\theta}$ has a continuous distribution, the\n          probability that it takes on any particular value is $0$. Therefore,\n          we cannot use the bootstrap to obtain an arbitrarily good\n          approximation of $\\widehat{\\theta}$, no matter how many samples we\n          use.\n  \\end{enumerate}\n\\end{ex}", "meta": {"hexsha": "9bc807344401d33a1e87e70eaa81c79d6ddca71b", "size": 16819, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch09.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/ch09.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/ch09.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": 34.0465587045, "max_line_length": 92, "alphanum_fraction": 0.4722040549, "num_tokens": 5865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7154239957834734, "lm_q1q2_score": 0.6240982492520769}}
{"text": "\n\\subsection{Quasi-hyperbolic discounting}\n\n\\subsubsection{Introduction}\n\nWe have:\n\n\\(U_T=\\sum_[t=T]^{\\infty }d_tU(x_t)\\)\n\n\\subsubsection{Quasi-hyperbolic discounting}\n\n\\(d_0=1\\)\n\n\\(d_t=\\beta \\delta^t\\)\n\n\\(U_T=U(x_0)+\\sum_[t=T+1]^{\\infty }\\beta \\delta ^tU(x_t)\\)\n\n\\(\\delta \\) is the discount rate.\n\n", "meta": {"hexsha": "a6327dcdbcad1d934179865bf4521288e195140f", "size": 299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/intertemporal/02-03-quasiHyperbolic.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-03-quasiHyperbolic.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-03-quasiHyperbolic.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.95, "max_line_length": 58, "alphanum_fraction": 0.6655518395, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6240982439590834}}
{"text": "\\section{The Choice of Abella}\n\nWe have chosen the Abella (v2.0.5) proof assistant~\\citep{AbellaDesc} to\ndevelop our formalization.\n% Our development is only based on the reasoning logic of Abella, and does not make use of its specification logic.\nAlthough Abella takes a two-level logic approach,\nwhere the specification logic can be expressed separately from the\nreasoning logic, we only make use of its reasoning logic, due to the\ndifficulty of expressing our algorithmic rules with only the specification.\nAbella is particularly helpful due to its built-in support for variable bindings, and\nits $\\lambda$-tree syntax~\\citep{miller2000abstract} is a form of HOAS,\nwhich helps with the encoding and reasoning about substitutions.  For\ninstance, the type $\\forall x. x \\to a$ is encoded as \\abellae{all (x\\  arrow x a)}, where \\abellae{x\\ arrow x a} is a lambda abstraction in\nAbella. An opening $[b/x](x\\to a)$ is encoded as an application\n\\abellae{(x\\ arrow x a) b}, which can be simplified(evaluated) to\n\\abellae{arrow b a}.\nName supply and freshness conditions are controlled by the\n$\\nabla$-quantifier.  The expression \\abellae{nabla x, F} means that\n\\abellae{x} is a unique variable in \\abellae{F}, i.e. it is different\nfrom any other names occurring elsewhere.  Such variables are called\nnominal constants.  They can be of any type, in other words, every\ntype may contain an unlimited number of such atomic nominal constants.\n\n%\\subsection{Encoding of Declarative System}\n\n\\paragraph{Encoding of the Declarative System}\nAs a concrete example, our declarative context (well-formedness relation)\nand well-formedness rules are encoded as follows.\n\\begin{abella}\n\tKind ty     type.\n\tType i      ty.                % the unit type\n\tType all    (ty -> ty) -> ty.    % forall-quantifier\n\tType arrow  ty -> ty -> ty.      % function type\n\tType bound  ty -> o.            % variable collection in contexts\n\t\n\tDefine env : olist -> prop by\n\t\tenv nil;\n\t\tnabla x, env (bound x ::E) := env E.\n\t\n\tDefine wft : olist -> ty -> prop by\n\t\twft E i;\n\t\tnabla x, wft (E x) x := nabla x, member (bound x) (E x);\n\t\twft E (arrow A B) := wft E A /\\ wft E B;\n\t\twft E (all A) := nabla x, wft (bound x ::E) (A x).\n\\end{abella}\n\nIn the above code, we first define the syntax of types and contexts in our type system.\nA type of our system has type \\abellae{ty}, and the context is of type \\abellae{olist}.\nWe use the type \\abellae{olist} just as normal list of \\abellae{o} with two constructors,\nnamely \\abellae{nil : olist} and \\abellae{(::) : o -> olist -> olist},\nwhere \\abellae{o} purely means ``the element type of \\abellae{olist}'',\nand both are built-in types of Abella.\nThe \\abellae{member : o -> olist -> prop} relation is also pre-defined.\n\nNote that in Abella, the symbol (\\abellae{:=}) used in definitions\nis similar to the (\\abellae{:-}) symbol in Prolog,\nwhere we write the condition to its right and the conclusion to its left.\nThe second case of the relation \\abellae{wft} states Rule $\\mathtt{wf_d var}$.\nThe encoding \\abellae{(E x)} basically means that the context \\emph{may} contain \\abellae{x}.\nIf we write \\abellae{(E x)} as \\abellae{E}, then the context should not contain \\abellae{x}, and both \\abellae{wft E x} and \\abellae{member (bound x) E} make no sense.\nInstead, we treat \\abellae{E : ty -> olist} as an \\emph{abstract structure} of a context, such as \\abellae{x\\ bound x ::bound a ::nil}.\nFor the fourth case of the relation \\abellae{wft}, the type $\\forall x. A$ in our target language is expressed as \\abellae{(all A)}, and its opening $A$, \\abellae{(A x)}.\n\n\\paragraph{Encoding of the Algorithmic System}\nIn terms of the algorithmic system, notably, Abella handles the\n$\\mathtt{{\\le_a}instL}$ and $\\mathtt{{\\le_a}instR}$ rules in a nice way:\n\\begin{abella}\n\t% sub_alg_list : enva -> [subty_judgment] -> prop\n\tDefine subal : olist -> olist -> prop by\n\t\tsubal E nil;\n\t\tsubal E (subt i i ::Exp) := subal E Exp;\n\t\t% some cases omitted ...\n\t\t% <: instL\n\t\tnabla x, subal (E x) (subt x (arrow A B) ::Exp x) :=\n\t\t\texists E1 E2 F, nabla x y z, append E1 (exvar x ::E2) (E x) /\\\n\t\t\t\tappend E1 (exvar y ::exvar z ::E2) (F y z) /\\\n\t\t\t\tsubal (F y z) (subt (arrow y z) (arrow A B) ::Exp (arrow y z));\n\t\t% <: instR is symmetric to <: instL, omitted here\n\t\t% other cases omitted ...\n\\end{abella}\nIn this piece of code, we use \\abellae{Exp} to denote the worklist $\\Om$.\nAn algorithmic existential variable $\\al$ is constructed by applying \nthe Abella term \\abellae{exvar} to an actual nabla quantified variable.\nThanks to the way Abella deals with nominal constants, the pattern \n\\abellae{subt x (arrow A B)} implicitly states that $x\\notin FV(A) \\land x\\notin FV(B)$.\nIf the condition were not required, we would have encoded the pattern as \n\\abellae{subt x (arrow (A x) (B x))} instead.\n\n\\subsection{Statistics and Discussion}\\label{subsection:discussion}\n\\begin{figure}[t]\n\t\\centering\\begin{tabular}{|c|c|c|l|}\\hline\n\t\tFile(s) & SLOC & \\# of Theorems & Description\\\\\\hline\n\t\tolist.thm, nat.thm      &  303 & 55  & Basic data structures\\\\\\hline\n\t\thigher.thm, order.thm   &  164 & 15  & Declarative system\\\\\\hline\n\t\thigher\\_alg.thm         &  618 & 44  & Algorithmic system\\\\\\hline\n\t\ttrans.thm               &  411 & 46  & Transfer\\\\\\hline\n\t\tsound.thm               &  166 & 2   & Soundness theorem\\\\\\hline\n\t\tdepth.thm               &  143 & 12  & Definition of depth\\\\\\hline\n\t\tcomplete.thm            &  626 & 28  & Lemmas and Completeness theorem\\\\\\hline\n\t\tdecidable.thm           & 1077 & 53  & Lemmas and Decidability theorem\\\\\\hline\n\t\tTotal                   & 3627 & 267 & (33 definitions in total)\\\\\\hline\n\t\\end{tabular}\n\t\\caption{Statistics for the proof scripts}\\label{fig:SLOC}\n\\end{figure}\n\nSome basic statistics on our proof script are shown in Figure~\\ref{fig:SLOC}.\nThe proof consists of 3627 lines of code with a total of 33 definitions and 267 theorems.\nWe have to mention that Abella provides few built-in tactics and does not support user-defined ones, and we would reduce significant lines of code if Abella provided more handy tactics%\n\\footnote{We do extend Abella with some handy tactics after this work,\nwhich boosts our development and reduce some boilerplate codes.\nOne may find the modified version in \\url{https://github.com/JimmyZJX/abella}.}\nMoreover, the definition of natural numbers, the plus operation and less-than relation are defined within our proof due to Abella's lack of packages.\nHowever, the way Abella deals with name bindings\nis very helpful for type system formalizations and substitution-intensive formalizations, such as this one.\n", "meta": {"hexsha": "ab87dfb9208fa93531be9be11f05d8f6fedf3279", "size": 6575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Sources/ITP/abella.tex", "max_stars_repo_name": "JimmyZJX/Dissertation", "max_stars_repo_head_hexsha": "823bfe90e4b5cc5b7d90c045670bdf4b087877cf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Sources/ITP/abella.tex", "max_issues_repo_name": "JimmyZJX/Dissertation", "max_issues_repo_head_hexsha": "823bfe90e4b5cc5b7d90c045670bdf4b087877cf", "max_issues_repo_licenses": ["MIT"], "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/ITP/abella.tex", "max_forks_repo_name": "JimmyZJX/Dissertation", "max_forks_repo_head_hexsha": "823bfe90e4b5cc5b7d90c045670bdf4b087877cf", "max_forks_repo_licenses": ["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.1739130435, "max_line_length": 185, "alphanum_fraction": 0.7093536122, "num_tokens": 1937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6240982397549374}}
{"text": "\\chapter{Equations and Algorithm}\n\\label{sec-figures}\n\n\\section{Equations and Algorithm}\nLet us assume $\\gamma_{ij}$ is the number of matched keypoints among two keyframes, $i$ and $j$. These matches yield a distinct scale difference $\\sigma_{ij} $ depending on the number of matched keypoints $\\gamma_{ij}$. The optimal scale difference $\\sigma^*$ will be\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\sigma^* &= \\operatorname*{argmax}_{\\gamma} \\frac{1}{2}|\\gamma(\\sigma_{ij}), \\gamma(\\sigma_{i'j'}) | ,\n\t\\end{aligned}\n\t\\label{eqa-1}\n\\end{equation} \nwhere $\\sigma_{ij} $ and $\\sigma_{i'j'}$ are the two nearest points such that\\\\\n\\begin{equation}\n\t\\begin{split}\n\t\t\\quad |\\sigma_{ij} - \\sigma_{i'j'}| \\leq \\Delta^* \\quad \\forall \\quad i, j, i' \\text{ and } j' \\in \\mathds{Z}^+, \\quad \\Delta^* \\in \\mathbb{R}.\n\t\\end{split}\n\t\\label{eqa-1}\n\\end{equation} \nThe estimation is further explained in Algorithm \\ref{algorithm-1}.\\\\\n\n\\begin{algorithm}[!h]\n\t\\SetKwInput{KwData}{Input}\n\t\\SetKwInput{KwResult}{Output}\n\t\\KwData{Matched keyframes $\\mathbf{K}_{r_{ID}} = \\{\\mathbf{K}^i_{s},\\mathbf{K}^j_{t}\\}$ , poses $^w\\mathbf{T}_{r_{ID}} = \\{^w\\mathbf{T}_{s}, \\, ^w\\mathbf{T}_{t} \\}$, point clouds $P_{r_{ID}}^\\mathcal{F} = \\{P^{\\mathcal{F}_s^i}_{s(i)},P^{\\mathcal{F}_t^j}_{t(j)}$\\} with $i,j \\in \\mathds{Z}^+$ }\n\t\\KwResult{Optimal scale difference $\\sigma^*$, initial guess relative transformation $^{si}\\mathbf{T}_{ti}^{IG}$ }\n\tinitialization\\;\n\t\\For{$z = -1:1$} {\n\t\t$ P_{s(i+z)}^{\\mathcal{F}_w} = \\,^w\\mathbf{T}_{s(i+z)} (P^{\\mathcal{F}_{s(i+z)}}_{s(i+z)}) $ \\;\n\t\t$ P_{t(j+z)}^{\\mathcal{F}_w} = \\,^w\\mathbf{T}_{t(j+z)} (P^{\\mathcal{F}_{t(j+z)}}_{t(j+z)}) $ \\;\n\t\t\\SetKwFunction{FMain}{ PCR-Pro \\cite{Bhutta2018}}\n\t\t\\SetKwProg{Fn}{Function}{:}{}\n\t\t\\Fn{\\FMain{$\\mathbf{K}_{r_{ID}}$,$P_{r_{ID}}^{\\mathcal{F}_w}$}}{\n\t\t\tEstimate volume ratio $r_{vol}$ of $P_{s(i+z)}^{\\mathcal{F}_w}, P_{t(j+z)}^{\\mathcal{F}_w}$ \\;\n\t\t\t$^{s(i+z)}\\mathbf{T}_{t(j+z)}^{RC} \\longleftarrow \\gamma_z \\longleftarrow \\mathbf{K}^{i+z}_{s},\\mathbf{K}^{j+z}_{t} $ \\; \n\t\t\t$ \\sigma_z \\longleftarrow ^{s(i+z)}\\mathbf{T}_{t(j+z)}^{RC} , \\gamma_z, ^w\\mathbf{T}_{s(i+z)} , ^w\\mathbf{T}_{t(j+z)} $\\;\n\t\t\t$^{s(i+z)}\\mathbf{T}_{t(j+z)}^{IG} \\longleftarrow \\sigma_z, P_{s(i+z)}^{\\mathcal{F}_w},P_{t(j+z)}^{\\mathcal{F}_w} $ \\;\n\t\t\t\\KwRet $\\sigma_z, ^{s(i+z)}\\mathbf{T}_{t(j+z)}^{IG} $ \\; }\n\t}\n\t\\eIf{$r_{vol} > 0.5$}{\n\t\t$\\Delta^* = 5 $\\;\n\t\t\\For{$x = -1: 1$}{\n\t\t\t\\For{$y = -1: 1$}{\n\t\t\t\t\\If{$x \\neq y$}{\n\t\t\t\t\t$ \\Delta = |\\sigma_x - \\sigma_y| $\\;\n\t\t\t\t\t\\If{$\\gamma^* < \\gamma_{xy}$ \\&\\& $\\Delta^* > \\Delta$ \\&\\& $\\Delta^* \\neq 0$ }{\n\t\t\t\t\t\t$\\sigma^* = avg(\\sigma_x,\\sigma_y)$ \\;\n\t\t\t\t\t\t$\\Delta^* = \\Delta$ \\;\n\t\t\t\t\t\t$\\gamma^* = \\gamma_{xy}$ \\;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}{ $\\sigma^* =\\sigma_{xy=00} $ \\; } \n\t\\caption{Finest Tuning for Optimal Scale Estimation}\n\t\\label{algorithm-1}\n\\end{algorithm}\n\n\\newpage\n\n\\section{Appendix}\n\n\\newpage\n\\renewcommand*{\\bibname}{\\section{References}}\n\\bibliographystyle{ieeetr}\n\\bibliography{Thesis}\t\n", "meta": {"hexsha": "0879968187703f4d62d8b423792d98ebb6942b01", "size": 2958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4.tex", "max_stars_repo_name": "UsmanMaqbool/hkust-phd-mphil-thesis", "max_stars_repo_head_hexsha": "eb7beb0d00cd1a0ac04fda6c7c378bb6ebd4f29c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-17T03:10:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-17T03:10:07.000Z", "max_issues_repo_path": "chapter4.tex", "max_issues_repo_name": "UsmanMaqbool/hkust-phd-mphil-thesis", "max_issues_repo_head_hexsha": "eb7beb0d00cd1a0ac04fda6c7c378bb6ebd4f29c", "max_issues_repo_licenses": ["MIT"], "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": "UsmanMaqbool/hkust-phd-mphil-thesis", "max_forks_repo_head_hexsha": "eb7beb0d00cd1a0ac04fda6c7c378bb6ebd4f29c", "max_forks_repo_licenses": ["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.8181818182, "max_line_length": 294, "alphanum_fraction": 0.5902636917, "num_tokens": 1250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6240982392105138}}
{"text": "\\section{Stability Analysis}\n\nWith regards to the stability analysis, we aim to try and prove some results on\nthe \"stability function\" $R(z)$ as seen in Levecue's \\cite{levecue} chapter five\nthrough eight by following the arguments in Staff \\cite{staff}.\n\nSuppose we have the following ordinary differential equation:\n\\begin{equation} \\label{eq:lode}\n  \\begin{cases}\n    u' = \\mu u, \\quad \\mu < 0, t > 0 \\\\\n    u(0) = u_0\n  \\end{cases}\n\\end{equation}\nWe would like to analyze the stability of parareal on this system with a \ncoarse operator $\\coarse$ and a fine operator $\\fine$.\n\n\\subsection{Deriving a Stability Function}\n\nWith respect to Parareal, let's try and write our iteration in the form\n$\\lambda_n^k = H(n,k)\\lambda_0$. Suppose that we have some integrators $\\coarse$\nand $\\fine$, such that they're actually the same method, but with different time\nscales. In addition, suppoes that they're iteration can be described by they're\nown stability function $R(z)$. Then our parareal iteration goes to:\n\\begin{align*}\n  \\lambda_{n+1}^{k+1} & = \\coarse(t^{n+1},t^n,\\lambda_n^{k+1}) +\n  \\fine(t^{n+1},t^n,\\lambda_n^k) -\n  \\coarse(t^{n+1},t^n,\\lambda_n^k) \\\\\n  & = R(\\mu\\Delta t)\\lambda_n^{k+1} + \n  R(\\mu\\delta t)^s \\lambda_n^k -\n  R(\\mu\\Delta t)\\lambda_n^k \\\\\n\\end{align*}\nwhere we say $s = \\Delta t/ \\delta t$, i.e. how many fine steps are needed to\nmake one coarse step. Combining like terms results in:\n\\[\n  \\lambda_{n+1}^{k+1} = \n  R(\\mu\\Delta t)\\lambda_n^{k+1} + \n  \\left( R(\\mu\\delta t)^s - R(\\mu\\Delta t)\\right) \\lambda_n^k \n\\]\nNow, if we were to note the terms on $\\lambda$, we note that we have something\nvery similar to the recurrence relation on combinations $\\binom{n}{k} =\n\\binom{n}{k-1} + \\binom{n-1}{k-1}$. Exploiting that relationship, we can unroll\nour recursion into:\n\\[\n  \\lambda_{n+1}^{k+1} = \\left( \\sum_{i=0}^k \\binom{n}{i} \\left[R(\\mu \\delta t)^s -\n    R(\\mu \\Delta t)\\right]^i R(\\mu \\Delta t)^{n-i} \\right) \\lambda_0 =\n    H(\\mu, n,k,\\delta t, \\Delta t) \\lambda_0\n\\]\nWe would like to see when it's true that $\\abs{H} \\leq 1$. As it turns out, this\nfunction is very difficult to analyze by itself, none of my plots of $H$ by\nitself generated useful stability regions. Instead we try to analyze this under\na few easy cases, and see exactly how parareal transforms the stability region\nof known temporal integrators.\n\n\\subsection{Trivial case: $k = 0$}\n\nFirst, we make a sanity check, suppose we make no Parareal iterations. We would\nassume that in this case that the stability function of Parareal should devolve\nto the stability function of $\\coarse$, since that's the only thing computed.\nIndeed:\n\\begin{align*}\n  H & = \\left( \\sum_{i=0}^0 \\binom{n}{i} \\left[ R(\\mu \\delta t)^s -\n    R(\\mu \\Delta t) \\right]^i R(\\mu \\Delta t)^{n-i} \\right) \\lambda_0 \\\\\n  & = \\binom{n}{0} \\left[ R(\\mu \\delta t)^s - R(\\mu \\Delta t) \\right]^0 R(\\mu\n  \\Delta t)^{n} \\lambda_0 \\\\\n  & = R(\\mu \\Delta t)^{n} \\lambda_0\n\\end{align*}\nwhich is precisely the stability function of $\\coarse$.\n\n\\subsection{Trivial case $\\coarse = \\fine$.}\n\nSuppose we were to choose $\\coarse = \\fine$, time scales and all. This implies\nthat $s = 1$. We would expect that in this case, our parareal algorithm should\nresult in the stability region of $\\coarse$, since the corrector step should\nresult in a correction of $0$. Indeed we see that all parareal iterations with\n$k > 0$ are canceled to zero by the term $[R(\\mu \\delta t)^s - R(\\mu \\Delta\nt)]$. Otherwise we're just left with $\\binom{n}{0} R(\\mu \\Delta t)^n \\lambda_0 =\nR(\\mu \\Delta t)^n \\lambda_0$, which is exactly the stability region of\n$\\coarse$, as expected.\n\n\\subsection{Parareal Under Explicit Euler}\n\nThe most iconic temporal integrator is the Euler methods, and we would like to\nsee how Parareal changes they're stability regions.  Suppose now that we are\nusing explicit Euler for our coarse and fine integrators.  Recall, that this\nimplies that the stability function for our integrators $\\coarse$ and $\\fine$\nare $(1+z)$ and $(1+z)^s$ respectively, and remember that original the\nregion of stability for explicit Euler on the given ODE is for $z$ in the unit\ndisk centered around $-1$. \n\nSuppose $\\fine = \\coarse$ but with the time scale squared, i.e. $\\delta t =\n\\Delta t^2$ . So for example, if $\\coarse$ has a time step of $1/10$, then\n$\\fine$ has a time step of $1/100$.  Then, $s = \\frac{\\Delta t}{\\delta t} =\n\\Delta t^{-1}$. As an example, suppose that $\\Delta t = 1/2$. Then $s = 2$, and\n(let $z = \\Delta t$) our stability region goes to:\n\\begin{align*}\n  H & = \\sum_{i=0}^k \\binom{n}{i} \\left[ R(\\mu \\delta t)^s -\n    R(\\mu \\Delta t) \\right]^i R(\\mu \\Delta t)^{n-i} \\\\\n  & = \\sum_{i=0}^k \\binom{n}{i} \\left[ (1+\\mu z^2)^2 -\n    (1+\\mu z) \\right]^i (1+\\mu z)^{n-i} \\\\\n  & = \\sum_{i=0}^k \\binom{n}{i} \n    \\left[ \n      \\mu^2 z^4 + 2\\mu z^2 - \\mu z \n    \\right]^i (1+\\mu z)^{n-i} \\\\\n  & = \\sum_{i=0}^k \\binom{n}{i} \n    \\left[ \n      \\mu z(\\mu z^3 + 2 z - 1)\n    \\right]^i (1+\\mu z)^{n-i} \\\\\n\\end{align*}\nAt this point the roots of the cubic are ugly, so I don't take the general case\nany further. Now we examine interesting cases under $k$. Recall, by arguments\nmade above, we already know that $k = 0 \\implies$ that we just have stability\nregion $(1 + \\mu z)$. For the following analysis, suppose we take $n = 2$ too.\n\n\\subsubsection{One Parareal Iteration: $k = 1$}\n\nSuppose we only make one parareal iteration. Then the above goes to:\n\\[\n  (1 + \\mu z)^2 + 2\\mu z(\\mu z^3 + 2z - 1)(1+\\mu z) = (1+\\mu z)(2\\mu^2 z^4 +\n  4\\mu z^2  - \\mu z + 1)\n\\]\n\n\\subsubsection{Two Parareal Iteration: $k = 2$}\n\nSuppose we make two parareal iteration. This is a little more painful to\ncompute:\n\\[\n  (1 + \\mu z)^2 + 2\\mu z(\\mu z^3 + 2z - 1)(1+\\mu z) + \\mu z(\\mu z^3 + 2 z - 1) =\n  (\\mu z^2 + 1)^4\n\\]\nSo the stability region $(1 + \\mu z)^2$ transformed to $(1 + \\mu z^2)^4$ under\ntwo parareal iteration, which is exactly the same region.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\begin{subfigure}{\\textwidth}\n    \\centering\n    \\includegraphics[width=.49\\textwidth]\n      {./resources/parareal_stability1}\n    \\includegraphics[width=.49\\textwidth]\n      {./resources/parareal_stability2}\n  \\end{subfigure}%\n  \\caption{On the left we have the stability region for $k = 1$, and\n  on the right we have it for $k = 2$. It's a little bit difficult to see, but\n  for $k = 1$, the stability region is a bit smaller in $\\Delta t$, but larger\n  in $\\mu$.}\\label{fig:parareal_stability}\n\\end{figure}\n", "meta": {"hexsha": "dbf783b500c7db624f34f587ae511f97e414464e", "size": 6427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TeXsrc/src/stability.tex", "max_stars_repo_name": "abhijit-c/Parareal", "max_stars_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-01T19:31:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-08T13:54:15.000Z", "max_issues_repo_path": "Report/TeXsrc/src/stability.tex", "max_issues_repo_name": "abhijit-c/Parareal", "max_issues_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_issues_repo_licenses": ["MIT"], "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/TeXsrc/src/stability.tex", "max_forks_repo_name": "abhijit-c/Parareal", "max_forks_repo_head_hexsha": "e64c8ae44577da7e92720aa12b12f28acb3fc473", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-25T00:02:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T00:02:33.000Z", "avg_line_length": 43.7210884354, "max_line_length": 82, "alphanum_fraction": 0.666407344, "num_tokens": 2179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914997895581, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6240971306695736}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 6}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\nThis lecture we study the expectation of the average of $n$ i.i.d. random variables $X_i$, $i=1,\\dots, n$, \\ie, the expectation of $Q_n = \\frac{1}{n} (X_1 + \\dots + X_n)$. As $n \\to \\infty$, we will introduce the central limit theorem and show that $Q_n$ converges to a normal distribution provided $\\Var(X_i)$ exists.\n\n\n\\section{Sums of Discrete Random Variables}\nSuppose $X$ and $Y$ are two independent discrete random variables with distribution functions $p_X(x)$ and $p_Y(y)$. Let $Z = X + Y$, we want to find the the distribution function of $Z$. \n\nSuppose that $X = k$, where $k$ is some integer. Then $Z = z$ if and only if $Y = z-k$. So the event $Z = z$ is the union of the pairwise disjoint events\n\\begin{equation*}\n    (X=k) \\quad  \\text { and } \\quad  (Y=z-k)\n\\end{equation*}\nwhere $k$ runs over the integers. Since these events are pairwise disjoint, we have\n\\begin{equation}\n    \\label{eq:6.1}\n    \\tag{6-1}\n    \\Prob(Z=z)=\\sum_{k=-\\infty}^{\\infty} \\Prob(X=k)  \\Prob(Y=z-k)\n\\end{equation}\nwhich is the \\textbf{distribution function of the random variable $Z$}.\n\n\\begin{definition}\nLet $X$ and $Y$ be two independent integer-valued random variables, with distribution functions $p_X(x)$ and $p_Y(y)$ respectively. Then the \\textbf{convolution} of $p_X(x)$ and $p_Y(y)$ is the distribution function $p_Z = p_X * p_Y$ given by\n\\begin{equation*}\n    p_Z(z) = \\sum_{x} p_X(x) p_Y(z-x)\n\\end{equation*}\nfor $x\\in \\Z$. The function $p_Z(z)$ is the distribution function of the random variable $Z = X + Y$.\n\\end{definition}\n\n\n\\section{Sums of Continuous Random Variables}\n\\begin{definition}\nLet $X$ and $Y$ be two continuous random variables with density functions $f_X(x)$ and $f_Y(y)$ respectively. Assume that both $f_X(x)$ and $f_Y(y)$ are defined for all real numbers. Then the \\textbf{convolution} $f * g$ of $f$ and $g$ is the function given by\n\\begin{equation}\n    \\label{eq:6.2}\n    \\tag{6-2}\n    (f_X * f_Y)(z) = \\int_{-\\infty}^{+\\infty} f_X(z-y) f_Y(y) d y = \\int_{-\\infty}^{+\\infty} f_Y(z-x) f_X(x) d x.\n\\end{equation}\n\\end{definition}\n\n\\begin{theorem}\nLet $X$ and $Y$ be two independent random variables with density functions $f_X(x)$ and $f_Y(y)$ defined for all $x$ and $y$. Then the sum $Z = X + Y$ is a random variable with density function $f_Z(z)$, where $f_Z$ is the convolution of $f_X$ and $f_Y$.\n\\end{theorem}\n\n\\begin{theorem}\nLet $\\{X_i\\}$, $i=1,\\dots, n$ be a sequence of independent random variables with density functions $f_{X_1}(x), \\dots, f_{X_n}(x)$ respectively, then we have \n\\begin{equation*}\n    f_{X_1 + \\cdots + X_n}(x) = f_{X_1} * \\left( f_{X_2} * ( \\cdots * f_{X_n}) \\right)(x).\n\\end{equation*}\n\\end{theorem}\n\n\\begin{example}[Sum of two independent uniform random variables]\nLet $X$ and $Y$ be random variables describing our choices and $Z = X + Y$ their sum. Then we have\n\\begin{equation*}\n    f_{X}(x)=f_{Y}(x)=\\left\\{\\begin{array}{ll}{1} & {\\text { if } 0 \\leq x \\leq 1} \\\\ {0} & {\\text { otherwise }}\\end{array}\\right.\n\\end{equation*}\nand the density function for the sum is given by\n\\begin{equation*}\n    f_{Z}(z)=\\int_{-\\infty}^{+\\infty} f_{X}(z-y) f_{Y}(y) d y = \\int_{0}^{1} f_{X}(z-y) d y.\n\\end{equation*}\nNow the integrand is $0$ unless $0 \\leq z-y \\leq 1$ and then it is $1$. So if $0 \\leq z \\leq 1$, we have \n\\begin{equation*}\n    f_{Z}(z)=\\int_{0}^{z} d y=z,\n\\end{equation*}\nwhile if $1 < z \\leq 2$, we have\n\\begin{equation*}\n    f_{Z}(z)=\\int_{z-1}^{1} d y=2-z, \n\\end{equation*}\nand if $z < 0$ or $z > 2$ we have $f_Z(z) = 0$. Hence\n\\begin{equation*}\n    f_{Z}(z)=\\left\\{\\begin{array}{ll}{z,} & {\\text { if } 0 \\leq z \\leq 1} \\\\ {2-z,} & {\\text { if } 1<z \\leq 2} \\\\ {0,} & {\\text { otherwise }}\\end{array}\\right.\n\\end{equation*}\n\\end{example}\n\n\\begin{example}[Sum of two independent exponential random variables]\nLet $X, Y$, and $Z = X + Y$ denote the relevant random variables, and $f_X$ , $f_Y$ , and $f_Z$ their densities. Then\n\\begin{equation*}\n    f_{X}(x)=f_{Y}(x)=\\left\\{\\begin{array}{ll}{\\lambda e^{-\\lambda x},} & {\\text { if } x \\geq 0} \\\\ {0,} & {\\text { otherwise }}\\end{array}\\right.\n\\end{equation*}\nIf $z > 0$,\n\\begin{equation*}\n    f_{Z}(z)=\\int_{-\\infty}^{+\\infty} f_{X}(z-y) f_{Y}(y) d y =\\int_{0}^{z} \\lambda e^{-\\lambda(z-y)} \\lambda e^{-\\lambda y} d y =\\int_{0}^{z} \\lambda^{2} e^{-\\lambda z} d y =\\lambda^{2} z e^{-\\lambda z},\n\\end{equation*}\nwhile if $z < 0$, $f_Z(z) = 0$. Hence \n\\begin{equation*}\n    f_{Z}(z)=\\left\\{\\begin{array}{ll}{\\lambda^{2} z e^{-\\lambda z},} & {\\text { if } z \\geq 0} \\\\ {0,} & {\\text { otherwise }}\\end{array}\\right.\n\\end{equation*}\n\\end{example}\n\n\n\\section{Generating functions}\nA sequence $a = \\{a_i \\spacevert i = 0, 1 , 2, \\dots \\}$ of real numbers may contain a lot of information. One concise way of storing this information is to wrap up the numbers together in a ``generating function\". For example, the (ordinary) \\textbf{generating function} of the sequence $a$ is the function $G_a$ defined by \n\\begin{equation*}\n    G_{a}(s)=\\sum_{i=0}^{\\infty} a_{i} s^{i} \\quad \\text { for } s \\in \\mathbb{R} \\text { for which the sum converges. }\n\\end{equation*}\nIn many circumstances it is easier to work with the generating function $G_a$ than with the original sequence $a$.\n\n\\begin{theorem}[Abel's theorem]\nIf $a_i \\geq 0$ for all $i$ and $G_a(s)$ is finite for $\\abs{s} < 1$, then $\\lim_{s \\uparrow 1} G_a (s) = \\sum_{i=1}^ \\infty a_i$, whether the sum is finite or equals $+\\infty$. This standard result is useful when the radius of convergence $R$ satisfies $R = 1$, since then one has no a priori right to take the limit as $s \\uparrow 1$.\n\\end{theorem}\n\n\n\\subsection{Moment generating function}\n\\begin{definition}\nThe \\textbf{moment generating function} of the random variable $X$ is the function $M: \\R \\mapsto [0, \\infty)$ given by the Laplace transform of the corresponding p.d.f. $f_X(s)$:\n\\begin{equation*}\n    M_X(t) = \\Exp \\left( e^{tX} \\right) = \\int_{-\\infty}^\\infty e^{tx} f_X(x) dx,\n\\end{equation*}\nor corresponding p.m.f. $p_X(k)$:\n\\begin{equation*}\n    M_X(t) = \\sum_{k} e^{t k} \\Prob(X=k) \n    = \\sum_k \\sum_{n=0}^{\\infty} \\frac{(t k)^{n}}{n !} \\Prob(X=k)\n    = \\sum_{n=0}^{\\infty} \\frac{t^{n}}{n !}\\left(\\sum_k k^{n} \\Prob(X=k)\\right) \n    = \\sum_{n=0}^{\\infty} \\frac{t^{n}}{n !} \\Exp\\left(X^{n}\\right).\n\\end{equation*}\n$M_X(-t)$ is so called \\textbf{bilateral} Laplace transform of $f_X(x)$ or $p_X(k)$.\n\\end{definition}\n\nUnder the assumption that $M_X(t)$ is infinitely differentiable at $t=0$, the following statements are true. \n\\begin{enumerate}[(a)]\n    \\item $M^\\prime(0) = \\Exp(0) = \\mu$.\n    \\item $M^{(n)}(0) = \\Exp(X^n)$.\n    \\item Using Taylor's theorem, $M_X(t) = \\sum_{k=0}^\\infty \\frac{t^k}{k!} \\Exp(X^k)$.\n\\end{enumerate}\n\n\\begin{theorem}\nIf $X$ and $Y$ are independent, then\n\\begin{equation*}\n    \\begin{split}\n        M_{X+Y}(t) &= \\int_{-\\infty}^\\infty e^{tz} f_{x+y}(z) dz \\\\\n        &= \\int_{-\\infty}^\\infty e^{tz} \\int_{-\\infty}^\\infty f_X(x) f_Y(z-x) dx dz \\\\\n        &= \\int_{-\\infty}^\\infty e^{t(x+y)} \\int_{-\\infty}^\\infty f_X(x) f_Y(y) dx dy \\\\\n        &= M_X(t) M_Y(t).\n    \\end{split}\n\\end{equation*}\n\\end{theorem}\n\n\\subsection{Characteristic functions}\nSometimes $\\Exp(e^{tX})$ may blow up. So we consider some transformations in the complex domain, which usually perform better.\n\n\\begin{definition}\nThe \\textbf{characteristic function} of $X$ is the function $\\phi: \\R \\mapsto \\C$ defined by\n\\begin{equation*}\n    \\phi(t)=\\Exp\\left(e^{i t X}\\right) \\quad \\text { where } \\quad i=\\sqrt{-1}.\n\\end{equation*}\nWe often write $\\phi_x$ for the characteristic function of the random variable $X$. Characteristic functions are related to Fourier transforms. \n\\end{definition}\n\n\\begin{theorem}\nThe characteristic function $\\phi$ satisfies:\n\\begin{enumerate}[(a)]\n    \\item $\\phi(0) = 1$, $\\abs{\\phi(t)} \\leq 1$ for all $t$.\n    \\item $\\phi$ is uniformly continuous on $\\R$ w.r.t. $t$.\n    \\item If $X \\sim \\mathcal{N}(0,1)$, then $\\phi_{X}(t) = e^{-t^2/2}$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nWe only prove the first statement.\n\\begin{equation*}\n    \\begin{split}\n        \\abs{\\phi(t)} &= \\abs{\\int_{-\\infty}^\\infty e^{itx} f(x)dx } \\\\\n        &\\leq \\int_{-\\infty}^\\infty \\abs{e^{itx}} f(x) dx \\quad \\text{(triangle inequality)} \\\\\n        &= \\int_{-\\infty}^\\infty f(x) dx \\quad (\\abs{e^{itx}}=1) \\\\\n        &= 1\n    \\end{split}\n\\end{equation*}\n\\end{proof}\n\n\\begin{example}[Cauchy distribution]\nIf $f(x) = \n\\frac{1}{\\pi(1+x^2)}$, then the corresponding characteristic function is \n\\begin{equation*}\n    \\phi(t)=\\frac{1}{\\pi} \\int_{-\\infty}^{\\infty} \\frac{e^{i t x}}{1+x^{2}} d x = e^{-\\abs{t}}.\n\\end{equation*}\n\\end{example}\n\n\\begin{theorem}\nThe following statements are true.\n\\begin{enumerate}[(a)]\n    \\item If $\\phi^{(k)}(0)$ exists, then \n    \\begin{equation*}\n        \\left\\{\\begin{array}{ll}{\\Exp\\left|X^{k}\\right|<\\infty} & {\\text { if $k$}  \\text { is even }} \\\\ {\\Exp\\left|X^{k-1}\\right|<\\infty} & {\\text { if $k$ } \\text { is odd }}\\end{array}\\right.\n    \\end{equation*}\n    \n    \\item If $\\Exp(\\abs{X^k}) < \\infty$, then \n    \\begin{equation*}\n        \\phi(t)=\\sum_{j=0}^{k} \\frac{\\mathbb{E}\\left(X^{j}\\right)}{j !}(i t)^{j}+\\mathrm{o}\\left(t^{k}\\right)\n    \\end{equation*}\n    and so $\\phi^{(k)}(0)=i^{k} \\mathbb{E}\\left(X^{k}\\right)$.\n\\end{enumerate}\n\\end{theorem}\n\\begin{theorem}\nIf $X$ and $Y$ are independent then \n\\begin{equation*}\n    \\phi_{X+Y}(t)=\\phi_{X}(t) \\phi_{Y}(t).\n\\end{equation*}\nSimilarly, if $X_1, \\dots, X_n$ are independent, then \n\\begin{equation*}\n    \\phi_{X_1 + \\cdots + X_n}(t)= \\prod_{i=1}^n \\phi_{X_i}(t).\n\\end{equation*}\n\\end{theorem}\n\n\\begin{theorem}\nIf $a, b \\in \\R$ and $Y = aX+b$, then $\\phi_{Y}(t)=e^{i t b} \\phi_{X}(a t)$.\n\\end{theorem}\n\\begin{proof}\n\\begin{equation*}\n    \\phi_{Y}(t)=\\Exp\\left(e^{i t(a X+b)}\\right)=\\Exp\\left(e^{i t b} e^{i(a t) X}\\right) = e^{i t b} \\Exp\\left(e^{i(a t) X}\\right)=e^{i t b} \\phi_{X}(a t).\n\\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\nRandom variables $X$ and $Y$ are independent if and only if\n\\begin{equation*}\n    \\phi_{X, Y}(s, t)=\\phi_{X}(s) \\phi_{Y}(t) \\quad \\text { for all } s \\text { and } t.\n\\end{equation*}\n\\end{theorem}\n\n\\begin{definition}\nWe say that the sequence $F_1 , F_2, \\dots $ of distribution functions converges to the distribution function $F$, written $F_n \\to F$, if $F(x) = \\lim_{n\\to\\infty} F_n(x)$ at each point $x$ where $F$ is continuous.\n\\end{definition}\n\n\\begin{theorem}[Continnity theorem]\nSuppose that $F_1 , F_2, \\dots $ is a sequence of distribution functions \nwith corresponding characteristic functions $\\phi_1 , \\phi_2, \\dots $.\n\\begin{enumerate}[(a)]\n    \\item If $F_n \\to F$ for some distribution function $F$ with characteristic function $\\phi$, then $\\phi_n(t) \\to \\phi(t)$ for all $t$.\n    \\item Conversely, if $\\phi(t) \\lim_{n\\to\\infty} \\phi_n(t)$ exists and is continuous at $t=0$, then $\\phi$ is the characteristic function of some distribution function $F$, and $F_n \\to F$.\n\\end{enumerate}\n\\end{theorem}\n\n\n\\section{Central limit theorem}\n\\begin{definition}\nIf $X, X_1 , X_2 , \\dots$ is a sequence of random variables with respective distribution functions $F, F_1, F_2, \\cdots$, we say that $X_n$ converges in distribution to $X$, written $X_{n} \\stackrel{\\mathrm{D}}{\\rightarrow} X$, if $F_n \\to F$ as $n \\to\\infty$.\n\\end{definition}\n\n\\begin{theorem}[Central limit theorem]\nLet $X_1 , X_2, \\dots$ be a sequence of independent identically distributed random variables with finite mean $\\mu$ and finite nonzero variance $\\sigma^2$, and let $S_n = X_1 + X_2 + \\cdots + X_n$. Then\n\\begin{equation*}\n    \\frac{S_{n}-n \\mu}{\\sqrt{n \\sigma^{2}}} \\stackrel{\\mathrm{D}}{\\rightarrow} N(0,1) \\quad \\text { as } \\quad n \\rightarrow \\infty.\n\\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\nFirst, write $Y_i = \\frac{X_i - \\mu}{\\sigma}$, and let $\\phi_Y$ be the characteristic function of the $Y_i$. We have that \n\\begin{equation*}\n    \\phi_{Y}(t)=1-\\frac{1}{2} t^{2}+o\\left(t^{2}\\right).\n\\end{equation*}\nNote that $Y_i$ are i.i.d. So the characteristic function of $\\sum_{i=1}^n Y_i$ is\n\\begin{equation*}\n    \\phi_n = [\\phi_{Y}(t)]^n = \\left[ 1-\\frac{1}{2} t^{2}+o\\left(t^{2}\\right) \\right]^n.\n\\end{equation*}\nAlso, the characteristic function $\\psi_n$ of\n\\begin{equation*}\n    U_{n}=\\frac{S_{n}-n \\mu}{\\sqrt{n \\sigma^{2}}}=\\frac{1}{\\sqrt{n}} \\sum_{i=1}^{n} Y_{i}\n\\end{equation*}\nsatisfies\n\\begin{equation*}\n    \\psi_{n}(t)=\\left\\{\\phi_{Y}(t / \\sqrt{n})\\right\\}^{n}=\\left\\{1-\\frac{t^{2}}{2 n}+o\\left(\\frac{t^{2}}{n}\\right)\\right\\}^{n} \\rightarrow e^{-\\frac{1}{2} t^{2}} \\quad \\text { as } \\quad  n \\rightarrow \\infty,\n\\end{equation*}\nwhere we used \n\\begin{equation*}\n    \\lim_{n\\to\\infty} \\left( 1 + \\frac{a}{n} \\right)^n = e^a.\n\\end{equation*}\nThe last function is the characteristic function of the $\\mathcal{N}(0, 1)$ distribution, and an application of the continuity theorem completes the proof.\n\\end{proof}\n\n\\begin{corollary}\n$Q_n = \\frac{1}{n}S_n \\to \\mathcal{N} \\left(\\mu, \\frac{\\sigma^2}{n} \\right)$, $S_n \\to \\mathcal{N}(\\mu, n \\sigma^2)$. The sampling error is proportional to $\\frac{1}{\\sqrt{n}}$.\n\\end{corollary}\nThere is a generalization. If $X_i$ is not i.i.d., we can still use the central limit theorem.\n\n\\end{document}", "meta": {"hexsha": "e4f703bf1885daa58ae2e74532817f0f70c21861", "size": 13355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_6.tex", "max_stars_repo_name": "yuhan-zhao/freshman21-v1", "max_stars_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_drafts/MATH 2901/notes_6.tex", "max_issues_repo_name": "yuhan-zhao/freshman21-v1", "max_issues_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_drafts/MATH 2901/notes_6.tex", "max_forks_repo_name": "yuhan-zhao/freshman21-v1", "max_forks_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_forks_repo_licenses": ["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.0246478873, "max_line_length": 336, "alphanum_fraction": 0.6368401348, "num_tokens": 4902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6240971296103388}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Fisher information}\\label{sec:fisher}\n\n\nLet $X$ be a continuous random variable and let $\\mathcal{M}=\\{f(x;\\theta):\\theta\\in\\Theta\\}$ be a statistical model for its distribution. How can we quantify the amount of information that $X$ carries about $\\theta$?\n\nWe assume that our statistical model $\\mathcal{M}$ satisfies Condition~\\ref{cond:regularity1} along with the following additional requirements:\n\\begin{condition}\\label{cond:regularity2}\n\\ben\n\\setcounter{enumi}{3}\n\\it The PDFs $f(x;\\theta)$ are twice differentiable as functions of $\\theta$.\n\\it The integral $\\displaystyle\\int f(x;\\theta)\\,dx$ is twice differentiable under the integral sign as a function of $\\theta$.\n\\een\n\\end{condition}\nWe shalll not consider these in detail.\n\n%----------------------------------------------------------------------\n\\subsection{The score function}\n\nLet $X$ be a single observation.% and consider the log-likelihood function $\\ell(\\theta) = \\ell(\\theta;X) = \\log f(X;\\theta)$.\n\n% defn: score function\n\\begin{definition}\nThe first derivative of the log-likelihood function is called the \\emph{score function}, \n\\[\nu(\\theta;x) = \\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\n\\]\n\\end{definition}\n\n\\bit\n\\it Given a fixed observation $X=x$, we think of $u(\\theta;x)$ as a function of $\\theta$.\n\\it Given a fixed value of $\\theta$, we think of $u(\\theta;X)$ as a random variable. This is a transformation of $X$ which we denote by \n\t\\[\n\t\tU = \\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\n\t\\]\n\\eit\n% random variable (a transformation of $X$):\n%\\[\n%U(X) = u(\\theta,X) = = \\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\n%\\]\n%\n%For a fixed realisation $X=x$, we think of $u(\\theta;x)$ as a function of $\\theta$. If $X$ is allowed to vary on the other hand, and $\\theta$ is fixed, we think of $u(\\theta;X)$ as a transformation of $X$:\n%\\[\n%U(X) = u(\\theta,X) = = \\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\n%\\]\n\n\n%\n%\\begin{remark}\n%The score function $u(\\theta;\\mathbf{X})$ is the gradient of the log-likelihood function $\\ell(\\theta;\\mathbf{X})$ at $\\theta$, and thus quantifies the extent to which the log-likelihood depends on $\\theta$. \n%\\end{remark}\n\n%\\begin{remark}\n%\\bit\n%\\it If $\\theta$ is a vector of parameters, $u(\\theta)$ is a vector of partial derivatives (one for each component).\n%\\it Given $\\theta$, we can think of u(\\theta;\\boldX) as a random variable (a transformation of $\\boldX$).\n%%\\it $V$ is the gradient of the log-likelihood function at $\\theta$\n%%\\it Thus it quantifies the extent to which the log-likelihood depends on $\\theta$.\n%\\eit\n\n% lemma: expected score is zero\n\\begin{lemma}\\label{lem:expe_score_function}\n%Let $X$ be a random variable, and let $f(x;\\theta)$ be its PMF/PDF, where $\\theta$ is an unknown parameter. Under the regularity conditions stated above, the expected value of the score function $u(\\theta;X)$ is zero:\n%\\[\n%\\expe\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right) = 0.\n%\\]\nUnder the regularity conditions stated above,\n%\\[\n%%\\expe\\big[u(\\theta,X)\\big] = 0.\n%\\expe\\big[U] = 0.\n%\\]\n\\[\n\\expe(U) = \\expe\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right) = 0.\n\\]\n\\begin{proof}\nWe prove the lemma for the case where $X$ is a continuous random variable. For every value of $\\theta$, the integral of $f(x;\\theta)$ with respect to $x$ satisfies\n\\[\n\\int_{-\\infty}^{\\infty} f(x;\\theta)\\,dx = 1.\n\\]\nTaking the derivative with respect to $\\theta$ (and applying the regularity conditions), we see that\n\\[\n\\frac{\\partial}{\\partial\\theta}\\left(\\int_{-\\infty}^{\\infty} f(x;\\theta)\\,dx\\right)\n\t= \\int_{-\\infty}^{\\infty} \\frac{\\partial f(x;\\theta)}{\\partial\\theta} \\,dx \n\t= 0.\n\\]\nBy the chain rule, the first partial derivative of $\\log f(x;\\theta)$ with respect to $\\theta$ is given by\n\\[\n\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)  \n\t= \\frac{1}{f(x;\\theta)}\\frac{\\partial}{\\partial\\theta} f(x;\\theta).\n\\]\nHence\n\\begin{align*}\n\\expe\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right)\n\t= \\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial}{\\partial\\theta}f(x;\\theta)\\right) f(x;\\theta)\\,dx \n\t= \\int_{-\\infty}^{\\infty} \\frac{\\partial}{\\partial\\theta}f(x;\\theta)\\,dx \n\t= 0\n\\end{align*}\nas required.\n\\end{proof}\n\\end{lemma}\n\n% example: geometric\n\\begin{example}\\label{ex:score_geometric}\nFind the score function of a single observation from the $\\text{Geometric}(\\theta)$ distribution whose PMF is $\\prob(X=k)=\\theta(1-\\theta)^{k-1}$ for $k=1,2,3,\\ldots$ where $0<\\theta<1$ is unknown. \n\\begin{solution}\n\\bit\n\\it The likelihood function is $L(\\theta;x) = \\theta(1-\\theta)^{x-1}$.\n\\it The log-likelihood function is $\\ell(\\theta;x) = \\log\\theta + (x-1)\\log(1-\\theta)$.\n\\eit\nThe score function is therefore equal to\n\\begin{align*}\nu(\\theta;x) = \\ell'(\\theta,x)\n\t& = \\frac{\\partial}{\\partial\\theta} \\big(\\log\\theta + (x-1)\\log(1-\\theta)\\big) \\\\\n\t& = \\frac{1}{\\theta} - \\frac{x-1}{1-\\theta}\n\t= \\frac{1-\\theta x}{\\theta(1-\\theta)}\n\\end{align*}\nso $U = \\displaystyle\\frac{1-\\theta X}{\\theta(1-\\theta)}$. Note that because $\\expe(X)=1/\\theta$,\n\\[\n\\expe(U)\n\t= \\expe\\left(\\frac{1-\\theta X}{\\theta(1-\\theta)}\\right)\n\t= \\frac{1-\\theta\\expe(X)}{\\theta(1-\\theta)}\n\t= 0,\n\\]\nwhich verifies Lemma~\\ref{lem:expe_score_function}.\n\\end{solution}\n\\end{example}\n\n%----------------------------------------------------------------------\n\\subsection{Fisher information}\n%----------------------------------------------------------------------\n% defn\n\\begin{definition}\nThe variance of the score function is called the \\emph{Fisher information}, \n\\[\nI(\\theta) = \\var(U) = \\var\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right).\n\\]\n\\end{definition}\n\nThe following lemma gives a conveient way of computing $I(\\theta)$ in terms of the derivative of the score function.\n% lemma\n\\begin{lemma}\\label{lem:fisher}\nUnder the regularity conditions stated above, the Fisher information satisfies\n\\[\nI(\\theta) = -\\expe(U')= -\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(X;\\theta)\\right).\n\\]\n\\end{lemma}\n\n\\begin{proof}\nBy Lemma~\\ref{lem:expe_score_function}, the expected value of the score function is zero:\n\\[\n\\expe(U) = \\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\\right) f(x;\\theta) \\,dx = 0.\n\\]\nTaking the derivative of both sides with respect to $\\theta$,\n\\[\n\\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\\right)\\,f(x;\\theta) \\,dx \n+\n\\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\\right)\\,\\frac{\\partial f(x;\\theta)}{\\partial\\theta} \\,dx \n= 0.\n\\]\nBy the chain rule, \n\\[\n\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)  = \\frac{1}{f(x;\\theta)}\\frac{\\partial}{\\partial\\theta}f(x;\\theta).\n%\\frac{\\partial f(x;\\theta)}{\\partial\\theta} = \\frac{\\partial\\log f(x;\\theta)}{\\partial\\theta}\\,f(x;\\theta).\n\\]\nThus we have\n\\[\n\\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\\right)\\,f(x;\\theta) \\,dx \n+\n\\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\\right)^2 f(x;\\theta)\\,dx \n= 0.\n\\]\nThis can be written as\n\\[\n\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\\right)\n+\n\\expe\\left[\\left(\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\\right)^2 \\right]\n= 0.\n\\]\n\nBecause the expected value of the score function is zero, the second term is the variance of the score function. Hence\n\\[\n\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(x;\\theta)\\right)\n+\nI(\\theta) = 0\n\\]\nand the result follows.\n%\n%\\[\n%I(\\theta) + \\int_{-\\infty}^{\\infty} \\left(\\frac{\\partial\\log f(x;\\theta)}{\\partial\\theta}\\right)^2\\,f(x;\\theta)\\,dx = 0.\n%\\]\n%Hence\n%\\[\n%I(\\theta)\t= -\\expe\\left(\\frac{\\partial^2\\log f(X;\\theta)}{\\partial\\theta^2}\\right),\n%\\]\n%as required.\n\\end{proof}\n\n% example: bernoulli\n\\begin{example}\nFind the Fisher information of an observation from the $\\text{Bernoulli}(\\theta)$ distribution.\n\\begin{solution}\nLet $X\\sim\\text{Bernoulli}(\\theta)$. The PMF of $X$ can be written as\n\\[\nf(x;\\theta)=\\theta^x(1-\\theta)^{1-x} \\text{\\quad for $x\\in\\{0,1\\}$, and zero otherwise.}\n\\]\nTo compute the Fisher information, we need the following:\n\\begin{align*}\n\\log f(x;\\theta)\n\t& = \\ x\\log\\theta + (1-x)\\log(1-\\theta), \\\\[2ex]\n%\\frac{\\partial}{\\partial\\theta} \\log f(x;\\theta),\n%\t& = \\ \\frac{x}{\\theta} - \\frac{1-x}{1-\\theta} \\\\[2ex]\n%\\frac{\\partial^2}{\\partial\\theta^2} \\log f(x;\\theta),\n%\t& = \\ -\\frac{x}{\\theta^2} - \\frac{1-x}{(1-\\theta)^2}.\n\\frac{\\partial}{\\partial\\theta}\\log f(x;\\theta)\n\t& = \\ \\frac{x}{\\theta} - \\frac{1-x}{1-\\theta}, \\\\[2ex]\n\\frac{\\partial^2}{\\partial\\theta^2} \\log f(x;\\theta)\n\t& = \\ -\\frac{x}{\\theta^2} - \\frac{1-x}{(1-\\theta)^2}.\n\\end{align*}\n%\\bit\n%\\it $\\displaystyle\\log f(x;\\theta)\n%\t= x\\log\\theta + (1-x)\\log(1-\\theta)$.\n%\\it $\\displaystyle\\frac{\\partial}{\\partial\\theta} \\log f(x;\\theta)\n%\t= \\frac{x}{\\theta} - \\frac{1-x}{1-\\theta}$.\n%\\it $\\displaystyle\\frac{\\partial^2}{\\partial\\theta^2} \\log f(x;\\theta)\n%\t= -\\frac{x}{\\theta^2} - \\frac{1-x}{(1-\\theta)^2}$.\n%\\eit\nNote that because $\\expe(X)=\\theta$, the expected value of the score is zero:\n\\[\n\\expe(U) = \\expe\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X;\\theta)\\right) \n\t= \\expe\\left(\\frac{X}{\\theta} - \\frac{1-X}{1-\\theta}\\right)\n\t= \\frac{\\theta}{\\theta} - \\frac{1-\\theta}{1-\\theta}\n\t= 0.\n\\]\nThe Fisher information is \n\\begin{align*}\nI(\\theta)\n\t& = -\\expe\\left(-\\frac{X}{\\theta^2}-\\frac{1-X}{(1-\\theta)^2}\\right) \\\\\n\t& = \\frac{\\theta}{\\theta^2}+\\frac{1-\\theta}{(1-\\theta)^2}\n\t= \\frac{1}{\\theta}+\\frac{1}{1-\\theta}\n\t= \\frac{1}{\\theta(1-\\theta)}\n\\end{align*}\nRecall that if $X\\sim\\text{Bernoulli}(\\theta)$, then $\\var(X)=\\theta(1-\\theta)$:\n\\bit\n\\it If the variance is small ($\\theta\\approx 0 \\text{ or } \\theta\\approx 1$), $X$ carries a lot of information about $\\theta$.\n\\it If the variance is large ($\\theta\\approx 1/2$), $X$ carries relatively little information about $\\theta$.\n\\eit\n\\end{solution}\n\\end{example}\n\n\n%%% example\n%\\begin{example}\n%Find the Fisher information of an observation $X\\sim\\text{Geometric}(\\theta)$.\n%\\begin{solution}\n%From Example~\\ref{ex:score_geometric}, the score function of $X$ is\n%\\[\n%u(\\theta;x) = \\frac{1-\\theta x}{\\theta(1-\\theta)}\n%\\]\n%The derivative of $u(\\theta;x)$ with respect to $\\theta$ (which is also the second derivative of the log-likelihood function), is\n%\\begin{align*}\n%\\frac{\\partial}{\\partial\\theta} u(\\theta,X)\n%\t& = \\frac{\\theta(1-\\theta)(-X) - (1-\\theta X)(1-2\\theta)}{\\theta^2(1-\\theta)^2} \\\\\n%\t& = -\\frac{1 - 2\\theta +\\theta^2X}{\\theta^2(1-\\theta)^2}\n%\\end{align*}\n%Because $\\expe(X)=1/\\theta$, the Fisher information is therefore\n%\\begin{align*}\n%I(\\theta)\n%\t& = -\\expe\\left(\\frac{\\partial}{\\partial\\theta} u(\\theta,X)\\right) \\\\\n%\t& = \\frac{1 - 2\\theta +\\theta^2\\expe(X)}{\\theta^2(1-\\theta)^2} \\\\\n%\t& = \\frac{1 - \\theta}{\\theta^2(1-\\theta)^2} \\\\\n%\t& = \\frac{1}{\\theta^2(1-\\theta)}\n%\\end{align*}\n%Note that $I(\\theta)$ reaches a mainimum at $\\theta=2/3$, which \n%\\end{solution}\n%\\end{example}\n%\n\n\n% example: normal\n\\begin{example}\\label{example:fisher_information_normal}\nFind the Fisher information of an observation from the $N(\\theta,\\sigma^2)$ distribution, whose mean $\\theta$ is unknown but whose variance $\\sigma^2$ is known. \n\n\\begin{solution}\nLet $X\\sim N(\\theta,\\sigma^2)$. Then\n\\begin{align*}\nf(x;\\theta) \n\t& = \\ \\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left(-\\frac{(x-\\theta)^2}{2\\sigma^2}\\right), \\\\\n\\log f(x;\\theta) \n\t& = \\ -\\frac{1}{2}\\log(2\\pi\\sigma^2) - \\frac{(x-\\theta)^2}{2\\sigma^2}, \\\\\n\\frac{\\partial}{\\partial\\theta} \\log f(x;\\theta)\n\t& = \\ \\frac{x-\\theta}{\\sigma^2}, \\\\\n\\frac{\\partial^2}{\\partial\\theta^2} \\log f(x;\\theta)\n\t& = \\ -\\frac{1}{\\sigma^2}.\n\\end{align*}\nHence the Fisher information of $X\\sim N(\\theta,\\sigma^2)$ is \n\\[\nI(\\theta)\n\t= -\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log f(X;\\theta)\\right)\n\t= \\frac{1}{\\sigma^2}.\n\\]\n\\bit\n\\it If the variance is small, $X$ carries a lot of information about $\\theta$.\n\\it If the variance is large, $X$ carries relatively little information about $\\theta$.\n\\eit\n\\end{solution}\n\\end{example}\n\n%----------------------------------------------------------------------\n\\subsection{Random samples}\n%----------------------------------------------------------------------\nThe score function and Fisher information of a single observation extend naturally to random samples $X_1,X_2,\\ldots,X_n$ from the distribution of $X$.\n\n%Given a random sample $X_1,X_2,\\ldots,X_n$, the log-likelihood function of $\\theta$ is\n%\\[\n%\\ell(\\theta;X_1,X_2,\\ldots,X_n) = \\prod_{i=1}^n f(X_i;\\theta).\n%\\]\n\n% defn: scores\n\\begin{definition}\nThe \\emph{score function} of a random sample $X_1,X_2,\\ldots,X_n$ is the first partial derivative of its log-likelihood function with respect to $\\theta$. By independence,\n\\[\nu(\\theta;\\mathbf{X}) \n\t= \\frac{\\partial}{\\partial\\theta} \\log L(\\theta;\\mathbf{X})\n\t= \\sum_{i=1}^n \\frac{\\partial}{\\partial\\theta} \\log L(\\theta;X_i)\n\t= \\sum_{i=1}^n u(\\theta;X_i)\n\\]\n\\end{definition}\n\n% fisher information for random samples\n\\begin{definition}\nThe \\emph{Fisher information} of a random sample $X_1,X_2,\\ldots,X_n$ is the variance of its score function:\n\\[\nI_n(\\theta) \n\t= \\var\\left(\\frac{\\partial}{\\partial\\theta}\\log L(\\theta;\\mathbf{X})\\right)\n\t= \\sum_{i=1}^n\\var\\left(\\frac{\\partial}{\\partial\\theta}\\log L(\\theta;X_i)\\right)\n\t= nI(\\theta),\n%\t= -\\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log L(\\theta;\\mathbf{X})\\right)\n%\t= -\\sum_{i=1}^n \\expe\\left(\\frac{\\partial^2}{\\partial\\theta^2}\\log L(\\theta;X_i)\\right)\n\\]\nwhere $I(\\theta)$ is the Fisher information of a single observation.\n\\end{definition}\n\n%By independence, the Fisher information of a random sample is the total Fisher information of the individual observations.\n\n%% lemma\n%\\begin{lemma}\\label{lem:fisher_random_sample}\n%The Fisher information of a random sample $X_1,X_2,\\ldots,X_n$ is the total Fisher information of the individual observations,\n%\\[\n%I_n(\\theta) = nI(\\theta)\n%\\]\n%where $I(\\theta)$ is the Fisher information of a single observation.\n%\\end{lemma}\n%\n%% proof\n%\\begin{proof}\n%\\begin{align*}\n%I_n(\\theta) \n%\t& = \\var\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X_1,X_2,\\ldots,X_n;\\theta)\\right) \\\\\n%\t& = \\var\\left(\\frac{\\partial}{\\partial\\theta}\\log \\prod_{i=1}^n f(X_i;\\theta)\\right) \\\\\n%\t& = \\var\\left(\\frac{\\partial}{\\partial\\theta}\\sum_{i=1}^n \\log f(X_i;\\theta)\\right) \\\\\n%\t& = \\var\\left(\\sum_{i=1}^n \\frac{\\partial}{\\partial\\theta}\\log f(X_i;\\theta)\\right) \\\\\n%\t& = \\sum_{i=1}^n \\var\\left(\\frac{\\partial}{\\partial\\theta}\\log f(X_i;\\theta)\\right) \\quad\\text{(because the $X_i$ are independent)} \\\\\n%\t& = nI(\\theta).\n%\\end{align*}\n%\\end{proof}\n\n\\begin{remark}\n$I_n(\\theta)$ increases with the sample size: the more data we have, the more information we have about $\\theta$.\n\\end{remark}\n\n%----------------------------------------------------------------------\n\\begin{exercise}\n\\begin{questions}\n\\question % <<< Poisson\nFind the score function of an observation from the $\\text{Poisson}(\\theta)$ distribution, and verify that its expected value is zero.\n\\begin{answer}\nThe PMF of the $\\text{Poisson}(\\theta)$ distribution is\n\\[\nf(x;\\theta) = \\displaystyle\\frac{\\theta^x\\exp(-\\theta)}{x!} \\text{for $x=0,1,2,3,\\ldots$ (zero otherwise)}\n\\]\nLet $X\\sim\\text{Poisson}(\\theta)$. The score function for a single observation $X=x$ is\n\\[\nu(\\theta;x)\n\t= \\frac{\\partial}{\\partial\\theta}\\log f(x,\\theta)\n\t= \\frac{\\partial}{\\partial\\theta}(x\\log\\theta - \\theta - \\log x!)\n\t= \\frac{x-\\theta}{\\theta}.\n\\]\nSince $\\expe(X)=\\theta$, by the linearity of expectation we have\n\\[\n\\expe\\big[u(\\theta;X)\\big]\n\t= \\expe\\left(\\frac{X-\\theta}{\\theta}\\right)\n\t= \\frac{\\expe(X)-\\theta}{\\theta}\n\t= \\frac{\\theta-\\theta}{\\theta}\n\t= 0 \\quad\\text{as required.}\n\\]\n\\end{answer}\n\\question % <<< Geometric\nFind the Fisher information $I(\\theta)$ of an observation from the $\\text{Geometric}(\\theta)$ distribution, and find the value of $\\theta$ for which $I(\\theta)$ is minimum.\n\\begin{answer}\nFrom Example~\\ref{ex:score_geometric}, the score function of $X$ is\n\\[\nu(\\theta;X) = \\frac{1-\\theta X}{\\theta(1-\\theta)}\n\\]\nThe derivative of $u(\\theta;X)$ with respect to $\\theta$ is\n\\begin{align*}\n\\frac{\\partial}{\\partial\\theta} u(\\theta,X)\n\t= \\frac{\\theta(1-\\theta)(-X) - (1-\\theta X)(1-2\\theta)}{\\theta^2(1-\\theta)^2}\n\t= -\\frac{1 - 2\\theta +\\theta^2X}{\\theta^2(1-\\theta)^2}\n\\end{align*}\nBecause $\\expe(X)=1/\\theta$, the Fisher information is therefore\n\\begin{align*}\nI(\\theta)\n\t= -\\expe\\left(\\frac{\\partial}{\\partial\\theta} u(\\theta,X)\\right)\n\t& = \\frac{1 - 2\\theta +\\theta^2\\expe(X)}{\\theta^2(1-\\theta)^2} \\\\\n\t& = \\frac{1 - \\theta}{\\theta^2(1-\\theta)^2} \\\\\n\t& = \\frac{1}{\\theta^2(1-\\theta)}\n\\end{align*}\nTo find the minimum, we differentiate $I(\\theta)$ and set the resulting expression to zero:\n\\[\nI'(\\theta) = \\frac{3\\theta-2}{\\theta^3(1-\\theta)^2}\t= 0.\n\\]\nThis shows that $I(\\theta)$ has a turning point at $\\theta=2/3$. The second derivative of $I(\\theta)$ is\n\\[\nI''(\\theta) = \\frac{9\\theta^2 - 16\\theta + 9}{\\theta^4(1-\\theta)^3}.\n\\]\nThe discriminant of the quadratic expression on the numerator is negative, which shows that $I''(\\theta)>0$ for all $\\theta$, and hence $I(\\theta)$ has a minimum at $\\theta=2/3$.  \n\\par\\smallskip\nNote that for the $\\text{Bernoulli}(\\theta)$ distribution, $I(\\theta)$ reaches its minimum at $\\theta=1/2$:\n\\[\nI(\\theta) = \\frac{1}{\\theta(1-\\theta)},\n\\qquad\nI'(\\theta) = \\frac{2\\theta -1}{\\theta^2(1-\\theta)^2},\n\\qquad\nI''(\\theta) = \\frac{2\\big[\\theta(1-\\theta)+(2\\theta-1)^2\\big]}{\\theta^3(1-\\theta)^3}.\n\\]\n\\end{answer}\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n", "meta": {"hexsha": "ffb139f4f2a3ea706e57c8b7c7f29da36272bc43", "size": 17491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/08C_fisher_information.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/08C_fisher_information.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/08C_fisher_information.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.57239819, "max_line_length": 218, "alphanum_fraction": 0.6408438626, "num_tokens": 5950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6240971231641758}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\\usepackage{float}\n\\usepackage{ulem}\n\\usepackage{bm}\n\\usepackage{anysize}\n\n\\marginsize{2cm}{2cm}{0.9cm}{1.8cm}\n\n\\title{EECE 5639 Computer Vision\\\\ [2ex] \\begin{large} Homework \\#1 \\end{large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\\begin{document}\n\\maketitle\n%%---------------------------------------------------------------\n%% Question 1\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) The equations of the image of the given line is:\n\\begin{equation*}\nx = f\\frac{X_0 + \\lambda(X_1 - X_0)}{Z_0 + \\lambda(Z_1 - Z_0)}\n\\end{equation*}\n\\begin{equation*}\ny = f\\frac{Y_0 + \\lambda(Y_1 - Y_0)}{Z_0 + \\lambda(Z_1 - Z_0)}\n\\end{equation*}\n\\begin{equation*}\nz = f\n\\end{equation*}\n\\noindent(b) As $|\\lambda| \\to \\infty$:\n\\begin{equation*}\n\\lim\\limits_{\\lambda\\to\\infty}x = f\\frac{X_1 - X_0}{Z_1 - Z_0}\n\\end{equation*}\n\\begin{equation*}\n\\lim\\limits_{\\lambda\\to\\infty}y = f\\frac{Y_1 - Y_0}{Z_1 - Z_0}\n\\end{equation*}\n\\begin{equation*}\n\\lim\\limits_{\\lambda\\to\\infty}z = f\n\\end{equation*}\n\\noindent If the 3D line is not parallel to the image plane, $Z_0 \\neq Z_1$. The image of $P$ will converge to a point which depends on the relative position of $P_0$ and $P_1$.\\\\\\\\\n(c) Let $\\lambda = 1/2$, the image of the midpoint of the segment $P_0P_1$ is \n\\begin{equation*}\nx_{midP_0P_1} = f\\frac{X_0 + X_1}{Z_0 + Z_1}\n\\end{equation*}\n\\begin{equation*}\ny_{midP_0P_1} = f\\frac{Y_0 + Y_1}{Z_0 + Z_1}\n\\end{equation*}\n\\begin{equation*}\nz_{midP_0P_1} = f\n\\end{equation*}\n\\noindent However the midpoint of the image segment $p_0p_1$ is\n\\begin{equation*}\nx_{midp_0p_1} = \\frac{f}{2}\\left ( \\frac{X_0}{Z_0} + \\frac{X_1}{Z_1} \\right )\n\\end{equation*}\n\\begin{equation*}\ny_{midp_0p_1} = \\frac{f}{2}\\left ( \\frac{Y_0}{Z_0} + \\frac{Y_1}{Z_1} \\right )\n\\end{equation*}\n\\begin{equation*}\nz_{midp_0p_1} = f\n\\end{equation*}\n\\noindent If the 3D line is not parallel to the image plane, $Z_0 \\neq Z_1$. Then $x_{midp_0p_1} \\neq x_{midP_0P_1},\\ y_{midp_0p_1} \\neq y_{midP_0P_1}$,  the image of the midpoint of the segment $P_0P_1$ is not the midpoint of the image segment $p_0p_1$.\n\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Question 2\n%%---------------------------------------------------------------\n\\section{Solution:}\nFrom the picture we have\n\\begin{equation*}\n\\begin{aligned}\nx_c &= - y_w + 2\\\\\ny_c &= z_w - 2\\\\\nz_c &= - x_w + 10\n\\end{aligned}\n\\end{equation*}\nAnd thus\n\\begin{equation*}\nM_{ext} = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 2\\\\\n0 & 0 & 1 & -2\\\\\n-1 & 0 & 0 & 10\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right ]\n\\end{equation*}\nLine equation for those sides of the floor tiles parallel to the camera optical axis can be given in world coordinate:\n\\begin{equation*}\nP_w = \\left[ \\begin{array}{c}\n-\\lambda\\\\\nn\\\\\n0\\\\\n1\n\\end{array} \\right ]\n\\end{equation*}\nwhere $n \\in \\{ 0,\\ 0.5,\\ 1,\\ 1.5,\\ 2,\\ 2.5,\\ 3,\\ 3.5,\\ 4 \\}$ denotes each line of tiles, and $\\lambda \\in R$ denotes the points on line. World coordinate to camera coordinate is given by\n\\begin{equation*}\nP_c = M_{ext} \\cdot P_w = \\left[ \\begin{array}{cccc}\n0 & -1 & 0 & 2\\\\\n0 & 0 & 1 & -2\\\\\n-1 & 0 & 0 & 10\\\\\n0 & 0 & 0 & 1\n\\end{array} \\right ]\\left[ \\begin{array}{c}\n-\\lambda\\\\\n0.5n\\\\\n0\\\\\n1\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\n-n+2\\\\\n-2\\\\\n\\lambda + 10\\\\\n1\n\\end{array} \\right ]\n\\end{equation*}\nAnd accordingly on the image plane,\n\\begin{equation*}\n\\left[ \\begin{array}{c}\nx'\\\\\ny'\\\\\nz'\n\\end{array} \\right ] = \\left[ \\begin{array}{cccc}\nf & 0 & 0 & 0\\\\\n0 & f & 0 & 0\\\\\n0 & 0 & 1 & 0\n\\end{array} \\right ]  \\left[ \\begin{array}{c}\n-n+2\\\\\n-2\\\\\n\\lambda + 10\\\\\n1\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\n(-n+2)f\\\\\n-2f\\\\\n\\lambda + 10\n\\end{array} \\right ]\n\\end{equation*}\n\\begin{equation*}\nP_i = \\left[ \\begin{array}{c}\nx\\\\\ny\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\nx'/z'\\\\\ny'/z'\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\n\\frac{-n+2}{\\lambda + 10}f\\\\\n-\\frac{2}{\\lambda + 10}f\n\\end{array} \\right ]\n\\end{equation*}\nAs $|\\lambda| \\to \\infty$,\n\\begin{equation*}\n\\lim\\limits_{\\lambda\\to\\infty}P_i = \\lim\\limits_{\\lambda\\to\\infty}\\left[ \\begin{array}{c}\n\\frac{-n+2}{\\lambda + 10}f\\\\\n-\\frac{2}{\\lambda + 10}f\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\n0\\\\\n0\n\\end{array} \\right ]\n\\end{equation*}\nTherefore, the images of the sides of the floor tiles parallel to the camera optical axis intersect at a single point $[0,\\ 0]'$, i.e. the origin.\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Question 3\n%%---------------------------------------------------------------\n\\section{Solution:}\nSuppose a point on the line is $P_0 = (x_0,\\ y_0,\\ z_0)$, and a vector parallel to the line is $v = (v_x\\  v_y,\\ v_z)$. Then the line equation in 3D under camera coordinate is \n\\begin{equation*}\nP = P_0 + \\lambda v = \\left[ \\begin{array}{c}\nx_0 + \\lambda v_x\\\\\ny_0 + \\lambda v_y\\\\\nz_0 + \\lambda v_z\n\\end{array} \\right ]\n\\end{equation*}\nThe image of the 3D line is \n\\begin{equation*}\n\\left[ \\begin{array}{c}\nx'\\\\\ny'\\\\\nz'\n\\end{array} \\right ] = \\left[ \\begin{array}{cccc}\nf & 0 & 0 & 0\\\\\n0 & f & 0 & 0\\\\\n0 & 0 & 1 & 0\n\\end{array} \\right ] \\left[ \\begin{array}{c}\nx_0 + \\lambda v_x\\\\\ny_0 + \\lambda v_y\\\\\nz_0 + \\lambda v_z\\\\\n1\n\\end{array} \\right ] = \\left[ \\begin{array}{c}\n(x_0 + \\lambda v_x)f\\\\\n(y_0 + \\lambda v_y)f\\\\\nz_0 + \\lambda v_z\n\\end{array} \\right ]\n\\end{equation*}\n\\begin{equation*}\nx = \\frac{x'}{z'} = \\frac{x_0 + \\lambda v_x}{z_0 + \\lambda v_z}f, \\ y = \\frac{y'}{z'} = \\frac{y_0 + \\lambda v_y}{z_0 + \\lambda v_z}f\n\\end{equation*}\nAs $|\\lambda| \\to \\infty$,\n\n\\begin{equation*}\n\\begin{aligned}\n\\lim\\limits_{\\lambda\\to\\infty}x &= \\lim\\limits_{\\lambda\\to\\infty}\\frac{x_0 + \\lambda v_x}{z_0 + \\lambda v_z}f = \\frac{v_x}{v_z}f\\\\\n\\lim\\limits_{\\lambda\\to\\infty}y &= \\lim\\limits_{\\lambda\\to\\infty}\\frac{y_0 + \\lambda v_y}{z_0 + \\lambda v_z}f = \\frac{v_y}{v_z}f\n\\end{aligned}\n\\end{equation*}\nSince the vanishing point under camera coordinate is $(10, 0, f)$, we have\n\\begin{equation*}\n\\left[ \\begin{array}{c}\n\\frac{v_x}{v_z}f=10\\\\\n\\frac{v_y}{v_z}f=0\n\\end{array} \\right ]\n\\end{equation*}\nLet $v_z = 1$, we have the orientation vector\n\\begin{equation*}\nv = \\left[ \\begin{array}{c}\n10/f\\\\\n0\\\\\n1\n\\end{array} \\right ]\n\\end{equation*}\nwith respect to the camera coordinate system.\n%%---------------------------------------------------------------\n%% Question 4\n%%---------------------------------------------------------------\n\\section{Solution:}\n\\noindent Suppose $Z_{face} - Z_{nose} = \\Delta Z$. When taken frontally, from the perspective equation:\n\\begin{equation*}\nx_{nose} = f\\frac{X_{nose}}{Z_{nose}},\\ x_{face} = f\\frac{X_{face}}{Z_{face}}\n\\end{equation*}\n\\noindent The ratio nose appears to be is \n\\begin{equation*}\n\\frac{x_{nose}}{x_{face}} = \\frac{X_{nose}Z_{face}}{Z_{nose}X_{face}} = \\frac{X_{nose}}{X_{face}} \\left(1 + \\frac{\\Delta Z}{Z_{nose}}\\right )\n\\end{equation*}\n\\noindent where $X_{face},\\ X_{nose}$ and $\\Delta Z$ keep the same. When taken from a small distance, the nose is closer to the camera and $\\Delta Z / Z_{nose}$ can be rather large. Therefore the nose appears to be much larger than the rest of the face.\\\\\\\\\nThis cannot be reduced by using another focal length, because $f$ has no effect in the ratio. However this can be reduced by changing object distance, i.e. to take picture in a larger distance.\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Question 5\n%%---------------------------------------------------------------\n\\section{Solution:}\nRed and magenta appear almost the same to person with a blue receptor deficiency.\n%%---------------------------------------------------------------\n%% Question 6\n%%---------------------------------------------------------------\n\\section{Solution:}\n(a) CMY system\\\\\n\\begin{equation*}\n{\\left[ \\begin{array}{c}\nC\\\\\nM\\\\\nY\n\\end{array} \n\\right]} = {\\left[ \\begin{array}{c}\n1\\\\\n1\\\\\n1\n\\end{array} \n\\right]} - \n{\\left[ \\begin{array}{c}\nR\\\\\nG\\\\\nB\n\\end{array} \n\\right]} = \n{\\left[ \\begin{array}{c}\n1\\\\\n1\\\\\n1\n\\end{array} \n\\right]} - \\frac{1}{255}\n{\\left[ \\begin{array}{c}\n200\\\\\n50\\\\\n100\n\\end{array} \n\\right]} \n={\\left[ \\begin{array}{c}\n0.216\\\\\n0.804\\\\\n0.608\n\\end{array} \n\\right]}\n\\end{equation*}\n\n\\noindent(b) YIQ system\n\\begin{equation*}\n{\\left[ \\begin{array}{c}\nY\\\\\nI\\\\\nQ\n\\end{array} \n\\right]} = {\\left[ \\begin{array}{ccc}\n0.299 & 0.587 & 0.114\\\\\n0.596 & -0.275 & -0.321\\\\\n0.212 & -0.532 & 0.311\n\\end{array} \n\\right]}  \n{\\left[ \\begin{array}{c}\nR\\\\\nG\\\\\nB\n\\end{array} \n\\right]} = \n\\frac{1}{255}\n{\\left[ \\begin{array}{ccc}\n0.299 & 0.587 & 0.114\\\\\n0.596 & -0.275 & -0.321\\\\\n0.212 & -0.532 & 0.311\n\\end{array} \n\\right]} {\\left[ \\begin{array}{c}\n200\\\\\n50\\\\\n100\n\\end{array} \n\\right]} \n={\\left[ \\begin{array}{c}\n0.394\\\\ \n0.288\\\\\n0.184\n\\end{array} \n\\right]}\n\\end{equation*}\n\n\\noindent(c) HSI system\n\\begin{equation*}\n\\theta = cos^{-1}\\left(\\frac{[(R-G)+(R-B)]/2}{[(R-G)^2+(R-B)(G-B)]^{1/2}}\\right)=cos^{-1}\\frac{125}{\\sqrt{17500}}=19.107\n\\end{equation*}\n\\begin{equation*}\nH = 360 - \\theta = 340.893\n\\end{equation*}\n\\begin{equation*}\nS = 1-\\frac{3}{R+G+B}[min(R, G, B)] = 1- \\frac{3\\times50}{350} = 0.571\n\\end{equation*}\n\n\\begin{equation*}\nI = 1-\\frac{R+G+B}{3} = 1-\\frac{350}{3\\times255} = 0.673\n\\end{equation*}\n\\begin{equation*}\n{\\left[ \\begin{array}{c}\nH\\\\ \nS\\\\\nI\n\\end{array} \n\\right]} = {\\left[ \\begin{array}{c}\n340.893\\\\ \n0.571\\\\\n0.673\n\\end{array} \n\\right]}\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "2760e4a3024f7a7bc01082dd7852493bec06a658", "size": 9421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5639-Computer-Vision/Homework-1/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": "EECE5639-Computer-Vision/Homework-1/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": "EECE5639-Computer-Vision/Homework-1/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": 26.538028169, "max_line_length": 257, "alphanum_fraction": 0.5848636026, "num_tokens": 3716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117812622843, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6240971180534003}}
{"text": "\n\n    \\filetitle{\\{...\\}}{Lag or lead}{modellang/laglead}\n\n\t\\paragraph{Syntax}\\label{syntax}\n\n\\begin{verbatim}\nVariableName{-lag}\nVariableName{lead}\nVariableName{+lead}\n\\end{verbatim}\n\n\\paragraph{Description}\\label{description}\n\nTo create a lag or a lead of a variable, use a pair of curly brackets.\n\n\\paragraph{Example}\\label{example}\n\n\\begin{verbatim}\n!transition_equations\n    x = rho*x{-1} + epsilon_x;\n    pi = 1/2*pie{-1} + 1/2*pie{1} + gamma*y + epsilon_pi;\n\\end{verbatim}\n\n\n", "meta": {"hexsha": "64188680046c6a898d0b816a7cbd1ba1e6fc07fd", "size": 482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "-help/modellang/laglead.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/laglead.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/laglead.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": 18.5384615385, "max_line_length": 70, "alphanum_fraction": 0.6991701245, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6240634276653916}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n% \\section{Methodology}\n%-----------------------DESCRIPTION OF THE METHOD---------------------------------%\n\\section{Description of the method}\nIn order to apply a clustering algorithm on a physical advection-diffusion problem, we have to define how the problem can be considered as a graph. For the next, we consider a two-dimensional problem in the coordinate system $(y,z)$. Let us partition the domain into $\\nby \\times \\nbz$ grid cells, and denote $N_{cell} = \\nby\\nbz$ the total number of grid cells. Figure~\\ref{fig:box_scheme} represents an example of such a domain decomposition of the rectangular domain $[0,\\,L]\\times[0,\\,H]$ with $\\nby = 15$ and $\\nbz = 10$. For any time $T$, the corresponding directed graph is build as follows: each node represents a grid cell, and the weight of the edge between nodes $i$ and $j$ is the probability $m_{i,j}(T)$ that a particle ends up in grid cell $j$ after a time $T$ if it was initially in grid cell $i$. If $m_{i,j}(T) = 0$, one can equivalently consider that there is no edge between nodes $i$ and $j$. We restrict ourselves to stationary velocity field and diffusivity tensor, hence $m_{i,j}(T)$ depends only on the elapsed time $T$, not on the initial time. Hence, the initial time can indifferently be considered as being zero. The adjacency matrix $\\b M(T)$ of the graph is build from the weights $m_{i,j}(T)$: $[\\b M(T)]_{i,j} = m_{i,j}(T)$. It is thus precisely the transition probability matrix introduced in chapter~\\ref{chap:clustering} which is needed to apply the stability clustering method. Since we consider passive tracer's particles in a domain with no-through boundary condition, we have that for any time $T$, $\\b M(T)\\b 1 = \\b 1$, where $\\b 1$ is the $N_{cell}$-dimensional unit column vector. The latter has a straightforward physical interpretation: every particle remains in the domain and particles are neither created nor destructed.\n\n\\begin{figure}[!htp]\n\t\\centering\n\t\\input{fig/clusters/box_scheme}\n\t\\caption{Illustration of the decomposition of a rectangular domain into grid cells with $\\nby = 15$ and $\\nbz = 10$.}\n\t\\label{fig:box_scheme}\n\\end{figure}\n\nTo estimate the probabilities $m_{i,j}(T)$, a Lagrangian simulation is run for a time $T$ with each grid cell containing initially $P_0$ uniformly distributed particles. Let $P_{i \\rightarrow j}(T)$ denote the number of particles in grid cell $j$ at time $T$, which were initially in grid cell $i$. Using that notation, $m_{i,j}(T)$ is then numerically estimated as \n\\begin{equation}\n\tm_{i,j}(T) = \\frac{P_{i \\rightarrow j}(T)}{P_0},\n\\end{equation}\ni.e. the number of particles having started in grid cell $i$ and ending up in grid cell $j$ after time $T$, divided by $P_0$. This is exactly the \\textit{box counting} method introduced in section~\\ref{boxcounting_kernel} for the computation of the concentration, but instead of dividing the tracer's mass in a grid cell by the volume of that grid cell, we divide it by $P_0$. This yields an adimensional quantity that can be interpreted as a transition probability. Note that the box counting method is more adapted than a density kernel estimation for this problem because the volume average over grid cells is precisely what we want.\n\n\\section{Dealing with the time scales} \\label{sec:timescales}\nAn important feature of the stability method for detecting community structures is that it is \\textit{dynamic}: community structures are revealed as a function of the Markov time $t_M$. For the problems that we consider, this Markov time is intrinsically linked to the physical time: for a given time $T$, suppose that the stability method is applied on the adjacency matrix $\\b M(T)$. In the discrete framework, a particle jumps from one node to another at every integer Markov time, and in the continuous framework, the expected time between jumps is $\\langle \\langle \\b q \\rangle/\\b q \\rangle = 1$ (cfr. page \\pageref{expectedtimebetweenjumps}). Hence, a Markov time step of $1$ corresponds to a physical time step of $T$.\n\nFrom the above discussion, two possibilities arise for dealing with the time scales: either we compute the adjacency matrix at one unique time $T$ and then compute the stability on the desired range of Markov times, or we compute the adjacency matrix at different times and then compute the stability on each adjacency matrix but for the Markov time $t_M = 1$ only. The advantage of the first method is that we do not have to fix \\textit{a priori} the time scales at which we compute clusterings: such times scales arise naturally as plateaux in the community curve, with a low corresponding variation of information. Hence the relevant time scales are deduced from the stability curve as being the ones at which robust clusterings arise. At the contrary, the second method imposes that we choose the time scales beforehand; doing so, we lose one of the most appealing features of the stability approach. Furthermore, the first method is computationally lest costly. Even for a relatively coarse partitioning of the domain, say of about $300$ grid cells, if we release $10\\,000$ particles in each grid cell there is a total of $3\\e{6}$ trajectories to simulate. For long $T$, the simulation time might become restrictive, especially in the case where one does not have access to supercomputers to run the code in parallel. The same situation leads to a $300$ nodes network, which is a relatively small network size that can easily be handled by the stability software. The first method has however one important drawback: the errors in the adjacency matrix are spread and even amplified across the Markov times. If those errors become too important, the community structures found at large Markov times might become irrelevant. In other words, simulating the transition probability matrix for a time $T$ and taking the $n$th power of that matrix is not necessarily equivalent to simulating the transition probability matrix for a time $nT$. The ideal methodology is thus probably to use the first method to detect the interesting time scales and compute the corresponding community structures, and then to check that we get similar community structures at the same time scales using the second method.\n\n%-------------------------USE OF THE TOOLBOX----------------------------%\n\\section{Use of the stability software}\n% \\newcommand\\localFontSize@mlpr{10}\nWe present here briefly how the \\textit{PartitionStability} software is used to compute the partitions. Every concept appearing here has been presented in chapter~\\ref{chap:clustering}. The \\mtlb{stability} function is simply called as follows : \\vspace{-.2cm}\n\\begin{center}\n\t\\mtlb{[S,N,VI,C] = stability(M,Markov_T,'directed','plot','teleport',tau);}\n\\end{center} %style = Matlab-bw for black and white\nHere, \\mtlb{M} is the matrix $\\b M(T)$ at the desired time $T$; \\mtlb{Markov_T} is the vector containing every Markov times at which the optimal stability partition has to be computed (ideally, the sampling should be exponential); the \\mtlb{'directed'} option specifies that we consider a directed graph; \\mtlb{'plot'} asks the program to plot the stability, number of communities and variation of information as a function of the Markov time; and \\mtlb{'teleport',tau} allows to specify the value of the teleportation probability $\\tau$ to \\mtlb{tau}, the default value being $0.15$. In most cases, we will choose \\mtlb{tau} $= 0$. This choice is motivated by the fact that if our approximation of the transition probability matrix is close enough the the exact one, then if the diffusivities are everywhere strictly positive the graph is ergodic (notice that there can be no dangling node whatever the precision of our approximation). Further in this work, one example where the graph is not ergodic will be encountered. In that case, the value of \\mtlb{tau} must be chosen strictly positive in order to ensure ergodicity. A small value is then preferred, in order to minimize the impact of random teleportations on the dynamics of the graph. We will typically choose \\mtlb{tau} $=10^{-3}$ in such a case.\n\nUnfortunately, the software does not handle discrete-time stability. Instead, it allows to choose which type of laplacian should be used to calculate the (continuous-time) stability. However, the question does not arise here since both laplacians are equivalent in our case. Indeed, the total outgoing weight is the same at every node and is precisely equal to the number of particles $P_0$ released in each grid cell. Hence, $k_i = P_0$ for every node $i$ and $\\langle \\b k \\rangle = P_0$, so that $\\bs \\lambda_{combi}(\\b k) = \\b k/ \\langle \\b k \\rangle = \\b 1 = \\bs \\lambda_{norm}(\\b k)$. We let thus the program run with the default normalized Laplacian, since it does not make any difference in our case.\n\nThe output arguments \\mtlb{S}, \\mtlb{N}, \\mtlb{VI} and \\mtlb{C} contain respectively the stability, the number of communities, the variation of information, and the optimal partition for each Markov time contained in \\mtlb{Markov_T}. If the latter is of size $n$, then \\mtlb{S}, \\mtlb{N} and \\mtlb{VI} are $n$-dimensional vectors and \\mtlb{C} is a $N_{cell} \\times n$ matrix. At the $j$th Markov time, communities are labeled by consecutive integers between $0$ and \\mtlb{N(j)}$-1$ such that \\mtlb{C(i,j)} $= k$ means that node $i$ belongs to community $k$ at Markov time \\mtlb{Markov_T(j)}.  ", "meta": {"hexsha": "a34c4c8196e41f4cf8eada826de61cd68ad5a94b", "size": 9442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/method/generalmethod.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/method/generalmethod.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/method/generalmethod.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": 262.2777777778, "max_line_length": 2201, "alphanum_fraction": 0.7610675704, "num_tokens": 2303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6240634205192357}}
{"text": "\\documentclass[fleqn]{article}\n\n%% Language and font encodings\n%\\usepackage[english]{babel}\n%\\usepackage[utf8x]{inputenc}\n%\\usepackage[T1]{fontenc}\n\n%% Sets page size and margins\n\\usepackage[margin=1in]{geometry}\n\n%% Useful packages\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n%\\usepackage{mathrsfs}\n\\usepackage{amsfonts,amssymb}\n%\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\n\\usepackage{parskip}\n\\usepackage{ragged2e}\n\n\\newcommand{\\mat}[1]{\\mathbf{#1}}\n\\newcommand{\\tr}{^\\intercal}\n\\newcommand{\\real}{\\mathbb{R}}\n\\newcommand{\\vect}[1]{\\begin{pmatrix}#1\\end{pmatrix}}\n\\newcommand{\\nablax}{\\nabla_{\\!\\mat x}}\n\n\\DeclareMathOperator{\\Lagr}{\\mathcal{L}}\n\n%\\setlength{\\parindent}{0pt}\n\n\\title{Homework 2}\n\\author{Group L\\\\\nYang Li, Jimmy Jusuf, Zhirong Zhang, Tiangang Zhang}\n\n\\begin{document}\n\\maketitle\n\n\n\\section{Problem 1}\n\n\\section{Problem 2}\n\nLet\n\\begin{equation}\n\\mat A = \\begin{pmatrix}\n  13 & 12 & -2 \\\\\n  12 & 17 & 6 \\\\\n  -2 & 6 & 12 \\\\\n  \\end{pmatrix} = \\mat A\\tr,\\quad \n\\mat a = \\begin{pmatrix} -22 \\\\ -14.5 \\\\ 13 \\\\ \\end{pmatrix},\\quad\nb = 1.\n\\end{equation}\n\\begin{equation}\n\\textnormal{objective function to be minimized }f:\\real^3\\rightarrow\\real,\n\\enskip f(\\mat x)=\\frac12 \\mat x\\tr \\mat A \\mat x + \\mat a\\tr x + b,\n\\end{equation}\n\\begin{equation}\\label{eq3}\n\\textnormal{subject to } {-1}\\leq x_i\\leq 1, i=1,2,3\n\\enskip\\textnormal{ or } \\begin{pmatrix} -1\\\\-1\\\\-1 \\end{pmatrix}\n  \\leq \\mat x\\leq \\begin{pmatrix} 1\\\\1\\\\1 \\end{pmatrix},\n  \\mat x\\in\\real^3.\n\\end{equation}\n\nWrite inequality constraints \\eqref{eq3} as \n$h_1(\\mat x)=-\\mat x+\\begin{pmatrix} -1\\\\-1\\\\-1 \\end{pmatrix}\\leq 0$\nand\n$h_2(\\mat x)=\\mat x+\\begin{pmatrix} -1\\\\-1\\\\-1 \\end{pmatrix}\\leq 0$,\n$h_1, h_2:\\real^3\\rightarrow\\real$.\nNote that\n$\\nablax f(\\mat x)=\\mat A\\mat x + \\mat a=\n  \\vect{21\\\\14.5\\\\-11} + \\vect{-22\\\\14.5\\\\13} = \\vect{-1\\\\0\\\\2}$,\n$\\nablax h_1(\\mat x)=\\vect{-1\\\\-1\\\\-1}$, \n$\\nablax h_2(\\mat x)=\\vect{1\\\\1\\\\1}$.\n\nLet $\n\\Lambda_1=\\begin{pmatrix}\\lambda_1\\\\ \\lambda_2\\\\ \\lambda_3\\end{pmatrix},\\enskip \n\\Lambda_2=\\begin{pmatrix}\\lambda_4\\\\ \\lambda_5\\\\ \\lambda_6\\end{pmatrix}$ be the Lagrange multipliers\nfor constraints $h_1(\\mat x)$ and $h_2(\\mat x)$ respectively.\n\nDefine Lagrangian\n\\begin{gather}\n\\Lagr(\\mat x, \\mat\\Lambda)=f(\\mat x)+ \\Lambda_1\\tr\\cdot h_1(\\mat x) + \n  \\Lambda_2\\tr\\cdot h_2(\\mat x)\n\\end{gather}\n\n%    Given $\\mat x^* = \\vect{1 \\\\ 0.5 \\\\ -1}$\n%and $\\lambda =\n%\\begin{pmatrix} \\lambda_1 - \\lambda_2 \\\\ \\lambda_3 - \\lambda_4 \\\\ \\lambda_5 - \\lambda_6 \\\\ \\end{pmatrix}$\n\nFor $\\mat x^*$ to be a local minimum, we want to show\nthe following KKT Necessary Conditions are met.\n\\begin{gather}\n\\nablax \\Lagr(\\mat x^*, \\Lambda^*) = \n  \\nablax f(\\mat x) + (\\Lambda_1^*)\\tr\\cdot\\nablax h_1(\\mat x)\n  + (\\Lambda_2^*)\\tr\\cdot\\nablax h_2(\\mat x) = 0 \\label{eq5}\\\\\n%  &= (\\mat A\\mat x + \\mat a) + (\\Lambda_1^*)\\tr\\cdot\\vect{-1\\\\-1\\\\-1}\n%    + (\\Lambda_2^*)\\tr\\cdot\\vect{1\\\\1\\\\1}\n(\\Lambda_1^*)\\tr \\cdot h_1(\\mat x^*) = 0 \\label{eq6}\\\\\n(\\Lambda_2^*)\\tr \\cdot h_2(\\mat x^*) = 0 \\label{eq7}\\\\\n\\Lambda_1^* \\geq 0 \\label{eq8}\\\\\n\\Lambda_2^* \\geq 0 \\label{eq9}\n% d^T \\nabla_{xx}^2 L(x^*, \\lambda^*) d > 0\n\\end{gather}\n\nPlugging in $\\mat x^* = \\vect{1 \\\\ 0.5 \\\\ -1}$,\\enskip\n\\begin{gather}\n\\nabla_{\\!\\mat x} \\Lagr(\\mat x^*, \\Lambda^*) = \\vect{-1\\\\0\\\\2}\n  +\\vect{-\\lambda_1\\\\-\\lambda_2\\\\-\\lambda_3}\n  +\\vect{\\lambda_4\\\\ \\lambda_5\\\\ \\lambda_6}=0 \\tag{\\ref{eq5}a}\\label{eq5a}\\\\\n\\vect{\\lambda_1&\\lambda_2&\\lambda_3} \\vect{-2\\\\-1.5\\\\0} = 0\n  \\implies \\lambda_1=\\lambda_2=0 \\tag{\\ref{eq6}a}\\label{eq6a}\\\\\n\\vect{\\lambda_4&\\lambda_5&\\lambda_6} \\vect{0\\\\-0.5\\\\-2} = 0\n  \\implies \\lambda_5=\\lambda_6=0 \\tag{\\ref{eq7}a}\\label{eq7a}\n%\\Lambda_2^* \\cdot h_2(\\mat x^*) = 0 \\\\\n%\\Lambda_1^* \\geq 0 \\\\\n%\\Lambda_2^* \\geq 0 \\\\\n\\end{gather}\nThe \\emph{complementary slackness condition} forces\n$\\lambda_1,\\lambda_2,\\lambda_5,\\lambda_6$ to be zero as\n$h_1(x_1), h_1(x_2), h_2(x_2), h_2(x_3) \\leq 0$ in\nequations \\eqref{eq6a} and \\eqref{eq7a}.\nBack-substitution into \\eqref{eq5a} yields $\\lambda_4=1$ and \n$\\lambda_3=-2$. All the $\\lambda$'s satisfy conditions \\eqref{eq8}\nand \\eqref{eq9}.\n\nWe have shown the KKT Necessary Conditions are met and there is\na unique vector of Lagrange multipliers for all the constraints.\n\n%From the constraints and the given solution, we have\n%\\begin{gather}\n%\\lambda_2 = \\lambda_3 = \\lambda_4 = \\lambda_5 = 0 \\\\\n%\\lambda_1 = 1 \\\\\n%\\lambda_6 = 2\n%\\end{gather}\n\n%As all the leading principal minor of \\(A\\) is positive, the second\n%order condition is met.\n\n\\end{document}", "meta": {"hexsha": "4b001a2c285c9654eab7938ca9b15281d0ca91fa", "size": 4512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/hw3.tex", "max_stars_repo_name": "jjusuf/MTH-9842", "max_stars_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW3/hw3.tex", "max_issues_repo_name": "jjusuf/MTH-9842", "max_issues_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW3/hw3.tex", "max_forks_repo_name": "jjusuf/MTH-9842", "max_forks_repo_head_hexsha": "476a089b7d49089c6edad2a0f2c9257c283aa6d3", "max_forks_repo_licenses": ["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.4604316547, "max_line_length": 106, "alphanum_fraction": 0.6564716312, "num_tokens": 1865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.6240634145578073}}
{"text": "The evaluation is divided into three parts: testing, performance, and expressive power. In all parts, Souffle\\cite{SouffleHome} is the implementation evaluated against.\n\n\\subsection{Testing}\nThe Souffle pretty-printer (SPP) is used to output a Datalog program that may be executed by Souffle. The process of comparing Souffle output to that of the internal interpreter has been automated and a range of tests written. If the tests agree, then the SPP is said to be correct for the given test program. Assuming that the Souffle result is correct, the internal interpreter too is concluded to be correct for the given test program. The test cases are selected to cover mutual recursion, negation, meta-predicates, and the other various language extensions.\n\n\\subsection{Performance}\nSouffle implements semi-naive evaluation\\cite{Green:2013:DRQ:2688167.2688168} which is essentially the same as naive evaluation except that it utilizes the following key-insight. An instantiation of the terms of a rule may derive new tuple(s) if and only if at least one tuple that was derived in the previous iteration is used in the instantiation. Thus the number of tuples to consider can be greatly decreased. \n\nThe performance is evaluated against two examples shown in figures \\ref{figure:nat} and \\ref{figure:ancestor}.\n\\vspace*{-15pt}\n\\begin{figure}[!ht]\n\\begin{minipage}[b]{.5\\textwidth}\n\\caption{Upper bounded Natural Numbers example.}\n\\begin{minted}{text}\nNat(0).\nNat(y) :- Nat(x), BIND(y, x + 1), y <= N.\n\\end{minted}\n\\label{figure:nat}\n\\end{minipage}\n\\begin{minipage}[b]{.5\\textwidth}\n\\caption{Ancestor relation example.}\n\\begin{minted}{text}\nr1: Ancestor(p, c) :- Parent(p, c).                            \nr2: Ancestor(a, c) :- Parent(p, c), Ancestor(a, p).\n\\end{minted}\n\\label{figure:ancestor}\n\\end{minipage}\n\\end{figure}\n\\noindent\n\\vspace*{-15pt}\n\\subsubsection{Theoretical Prediction}\n\n\\paragraph{NAT Example}\\NL\nFor the internal naive algorithm, at step $k$ in the iteration, the $Nat$-relation contains $k$ tuples. The internal implementation uses a tree-set to store the tuples and so each step takes $\\mathcal{O}(k \\cdot log(k))$ time (there is no join (Appendix A) between Nat and BIND). There are a total of $N$ steps in the algorithm, thus we get the following upper-bound for the worst-case running time:\n\\begin{align*}\n\\sum_{k = 1}^{N}k \\cdot log (k) \\leq N^2 log(N) = \\mathcal{O}(N^2 log(N))\n\\end{align*}\nFor semi-naive evaluation, each iteration gives a single new element to consider. The corresponding time complexity thus reduces to the order of:\n\\begin{align*}\n\t\\sum_{k = 1}^{N} log (k) \\leq N log(N) = \\mathcal{O}(N log(N))\n\\end{align*}\n\n\\paragraph{Ancestor Example}\\NL\nAssume the initial parent relation: \n\\begin{align*}\nParent(P_i, P_{i + 1}), i = 1\\ldots N - 1\n\\end{align*}\n\\noindent\nThen at the $k:th$ iteration of rule $r_2$, the \\textit{Ancestor} relation contains $\\sum_{l = 1}^{k} (N - l)$ elements. The parent relation is constant with $N$ elements. The dominating (non-indexed) \\textit{join}-operation thus has accumulated time complexity:\n\\begin{align*}\n\\sum_{k = 1}^{N - 1} \\Big (N \\cdot \\sum_{l = 1}^{k} (N - l)\\Big) = \\mathcal{O}(N^4)\n\\end{align*}\n\\noindent\nSimilarly, the semi-naive algorithm has expected time-complexity:\n\\begin{align*}\n\\sum_{k = 1}^{N - 1} N \\cdot (N - k) = \\mathcal{O}(N^3)\n\\end{align*}\n\n\n\\subsubsection{Experimental Results}\n\n\\paragraph{NAT Example}\\NL\nThe NAT example was measured for inputs in range 100 to 10000 for the internal evaluation, and in range 4096 to 536870912 for Souffle. The theoretical results was confirmed as $O(N^2 log(N))$ for the internal evaluation. For Souffle, the experimental results show $\\mathcal{O}(N)$ behavior. The $log(N)$ does not show in Souffle, most likely due to a more sophisticated relation representation\\cite{Scholz:2016:FLP:2892208.2892226}.\n\n%; Souffle better relation data structure as opposed to an ordered set.\n%\\begin{figure*}%[!ht]\n%\t\\hspace*{-25pt}\n%\t\\begin{minipage}[b]{.5\\textwidth}\n%\t\t\\includegraphics[scale=0.33]{img/internalloglog.png}\n%\t\\end{minipage}%\n%\t\\hspace*{-40pt}\n%\t\\begin{minipage}[b]{.5\\textwidth}\n%\t\t\\includegraphics[scale=0.35]{img/souffleloglog.png}\n%\t\\end{minipage}\n%\t\\label{figure:natExperimental}\n%\t\\caption{Nat Example, \\textbf{Left: } Internal (Naive), \\textbf{Right: } Souffle (Optimized Semi-Naive)}\n%\\end{figure*}\n\\paragraph{Ancestor Example}\\NL\nThe ancestor example was measured for inputs in range 5 to 260 for the internal evaluation, and in range 50 to 16384 for Souffle. The theoretical results was again confirmed as $O(N^4)$ for the internal evaluation. Souffle performed better than expected at about $O(N^{2.33})$. Again, this is most likely due to better \\textit{join}-performance which can be achieved by storing separate index data structures, thus removing the need to explicitly form the Cartesian product\\cite{Scholz:2016:FLP:2892208.2892226}.\n%\\begin{figure*}%[!ht]\n%\t\\hspace*{-70pt}\n%\t\\begin{minipage}[b]{.5\\textwidth}\n%\t\t\\includegraphics[scale=0.345]{img/ancestorInternal.png}\n%\t\\end{minipage}%\n%\\hspace*{-70pt}\n%\t\\begin{minipage}[b]{.5\\textwidth}\n%\t\t\\includegraphics[scale=0.35]{img/ancestorSouffle.png}\n%\t\\end{minipage}\n%\t\\label{figure:ancestorExperimental}\n%\t\\caption{Ancestor Example, \\textbf{Left: } Internal (Naive), \\textbf{Right: } Souffle (Optimized Semi-Naive)}\n%\\end{figure*}\n\\vspace*{-5pt}\n\\subsection{Expressive Power}\nSouffle supports all the implemented language extensions except meta-predicates and type-inference\\cite{SouffleHome}. The current set of meta-predicates offered by \\datalogM does not extend the expressive power in any meaningful way, but rather permits more compact and (admittedly subjectively) more beautiful descriptions of Datalog programs. \n\nSouffle contains a number of language extensions that are not currently supported by \\datalogM. For example, aggregate functions (such as $COUNT$, $MIN$, $MAX$), union types (i.e. stating that a term has type $A$ OR type $B$), and inbuilt functions (e.g. string operations), and more\\cite{SouffleHome}.\n\n", "meta": {"hexsha": "ca59129578af83979c0ad288299784f3605f8e1a", "size": 6028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/src/evaluation.tex", "max_stars_repo_name": "HampusBalldin/EDAN70Datalog", "max_stars_repo_head_hexsha": "f288d96b2b7923a717617412358fb40d07d6ee20", "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": "report/src/evaluation.tex", "max_issues_repo_name": "HampusBalldin/EDAN70Datalog", "max_issues_repo_head_hexsha": "f288d96b2b7923a717617412358fb40d07d6ee20", "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/src/evaluation.tex", "max_forks_repo_name": "HampusBalldin/EDAN70Datalog", "max_forks_repo_head_hexsha": "f288d96b2b7923a717617412358fb40d07d6ee20", "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": 61.5102040816, "max_line_length": 563, "alphanum_fraction": 0.74601858, "num_tokens": 1787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6240293145628152}}
{"text": "\\chapter{\\proj Edge Detection}\n\\label{ch_edge}\n\\index{edge detection}\n% \\chapterhead{Programs}\n\\markright{Edge detection}\n\n\\section{Introduction}\n% An edge in an image  corresponds to a discontinuity in the intensity\n% surface of the underlying scene.\nAn edge is defined as a local variation of image intensity. Edges can\nbe detected by the computation of a local derivative operator. \n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=fig_inflex.ps,bbllx=3.5cm,bblly=4cm,bburx=19.5cm,bbury=12cm,width=12cm,height=6cm,clip=} \n}}\n\\caption{First and second derivative of  $G_\\sigma * f$. (a) Original signal,\n(b) signal convolved by a Gaussian, (c) first derivative of (b), (d) second\nderivative of (b).}\n\\label{fig_inflex}\n\\end{figure}\n\nFigure~\\ref{fig_inflex} shows how the inflection point of a signal can be\nfound from its first and second derivative.\nTwo methods\ncan be used for generating first order derivative edge gradients.\n\n\\section{First Order Derivative Edge Detection}\n\n\\subsection{Gradient}\nThe gradient of an image $f$ at location $(x,y)$, along the line\nnormal to the edge slope, is the vector \\cite{ima:pratt91,ima:gonzalez93,ima:jain89}:\n\\begin{eqnarray}\n\\bigtriangledown f = & \n\\left[ \\begin{array}{c}\nf_x  \\\\\nf_y\n\\end{array} \\right] & = \n\\left[ \\begin{array}{c}\n \\partial f \\over \\partial x  \\\\\n \\partial f \\over \\partial y\n\\end{array} \\right]\n\\end{eqnarray}\n\n% The gradient of an image $f$ along $r$ in a direction $\\alpha$ is\n%\\begin{eqnarray}\n%{\\partial f \\over \\partial r} & = &{\\partial f \\over \\partial x} \\cos{\\alpha} +\n%{\\partial f \\over \\partial y} \\sin{\\alpha} \\\\\n%  & = & f_x \\cos{\\alpha} + f_y \\sin{\\alpha}\n%\\end{eqnarray}\n%The maximum value of ${\\partial f \\over \\partial r}$ is obtained when $\n\nThe spatial gradient amplitude is given by:\n\\begin{eqnarray}\nG(x,y) = \\sqrt{f_x^2 + f_y^2}\n\\end{eqnarray}\nand the gradient direction with respect to the row axis is\n\\begin{eqnarray}\n\\Theta(x,y) = \\arctan{\\frac{f_y}{f_x}}\n\\end{eqnarray}\n\nThe first oder derivative edge detection can be carried out either by using\n two orthogonal directions in an image or by using a set of\ndirectional derivatives. \n \n\\subsection{Gradient mask operators}\n% details dans le Jain, p348 et dans le pratt p504\n\nGradient estimates can be obtained by using gradient operators of the form:\n\\begin{eqnarray}\nf_x & = f & \\otimes  \\ \\ H_x \\nonumber \\\\\nf_y & = f & \\otimes \\ \\ H_y \n\\end{eqnarray}\nwhere $\\otimes$ denotes the convolution product, and $H_x$ and $H_y$ are $3\n\\times 3$\nrow and column operators, called gradient masks. Table \\ref{tab_grad1} shows \nthe main gradient masks proposed in the literature. Pixel difference is\nthe simplest one, which consists just of making the difference of   pixels\nalong rows and columns of the image:\n\\begin{eqnarray}\nf_x(x_m, y_n) & = & f(x_m , y_n) - f(x_m-1, y_n) \\nonumber \\\\\nf_y(x_m, y_n) & = & f(x_m , y_n )- f(x_m, y_n-1)\n\\end{eqnarray}\n\nThe Roberts gradient masks \\cite{edge:roberts65} are more sensitive \nto diagonal edges. Using these masks,\nthe orientation must be calculated by\n\\begin{eqnarray}\n\\Theta(x_m, y_n) = {\\pi \\over 4} + \\arctan \\left[ \n{f_y(x_m, y_n) \\over f(x_m , y_n)} \\right]\n\\end{eqnarray}\n\nPrewitt \\cite{edge:prewitt70}, Sobel, and Frei-Chen \\cite{edge:frei77} produce\nbetter results than the pixel difference, separated pixel difference and \nRoberts\noperator, because the mask is larger, and provides averaging of small luminance\nfluctuations. The Prewitt operator is more sensitive to \nhorizontal and vertical edges  than diagonal edges, and the \nreverse is true for the Sobel operator. The Frei-Chen  edge detector has the \nsame sensitivity for diagonal, vertical, and horizontal edges.\n\n% table\n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{lllc}\nOperator &    $H_x $     & $H_y$   & Scale factor\\\\\n         &              &        \\\\\nPixel difference&\n\\( \\left[ \\begin{array}{ccc}\n0 & 0 & 0\\\\\n0 & 1 & -1\\\\\n0 & 0 & 0\n\\end{array}\\right]  \\) &\n\\( \\left[ \\begin{array}{ccc}\n0 & -1 & 0\\\\\n0 & 1 & 0\\\\\n0 & 0 & 0\n\\end{array}\\right]  \\) & 1\\\\\n\n\\begin{tabular}{l}\nSeparated \\\\\npixel difference \\\\\n\\end{tabular} &\n\n\\( \\left[ \\begin{array}{ccc}\n0 & 0 & 0\\\\\n1 & 0 & -1\\\\\n0 & 0 & 0\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n0 & -1 & 0\\\\\n0 & 0 & 0\\\\\n0 & 1 & 0\n\\end{array}\\right]  \\) & 1\\\\ \nRoberts&\n\\( \\left[ \\begin{array}{ccc}\n0 & 0 & -1\\\\\n0 & 1 & 0\\\\\n0 & 0 & 0\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & 0 & 0\\\\\n0 & 1 & 0\\\\\n0 & 0 & 0\n\\end{array}\\right]  \\) & 1 \\\\\nPrewitt&\n\\( \\left[ \\begin{array}{ccc}\n1 & 0 & -1\\\\\n1 & 0 & -1\\\\\n1 & 0 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -1 & -1\\\\\n0 & 0 & 0\\\\\n1 & 1 & 1\n\\end{array}\\right]  \\) & 1\\\\\nSobel&\n \\( \\left[ \\begin{array}{ccc}\n1 & 0 & -1\\\\\n2 & 0 & -2\\\\\n1 & 0 & -1\n\\end{array}\\right]  \\)&\n \\( \\left[ \\begin{array}{ccc}\n-1 & -2 & -1\\\\\n0 & 0 & 0\\\\\n1 & 2 & 1\n\\end{array}\\right]  \\) & $ \\frac{1}{4} $ \\\\ \nFei-Chen&\n \\( \\left[ \\begin{array}{ccc}\n1 & 0 & -1\\\\\n\\sqrt{2} & 0 & \\sqrt{2}\\\\\n1 & 0 & -1\n\\end{array}\\right]  \\)&\n \\( \\left[ \\begin{array}{ccc}\n-1 & -\\sqrt{2} & -1\\\\\n0 & 0 & 0\\\\\n1 & \\sqrt{2} & 1\n\\end{array}\\right]  \\) & $\\frac{1}{2+\\sqrt{2}}$ \\\\\n \\end{tabular}\\par\n\\caption{Gradient edge detector masks.}\n\\label{tab_grad1}\n  \\end{center}\n\\end{table}\n\\vspace{0.3cm}\n\n\n\\subsection{Compass operators}\nCompass operators measure gradients in a selected number of directions.\nThe directions are $\\Theta_k = k {\\pi \\over 4}$,  $k = 0,...,7$. The edge\ntemplate gradient is defined as:\n\\begin{eqnarray}\nG(x_m, y_n) = \\max_{k=0}^7 { \\mid f(x_m, y_n) \\otimes H_k(x_m, y_n) \\mid }\n\\end{eqnarray}\n\nTable~\\ref{tab_grad2} shows the principal template gradient operators.\n\n\\begin{table}[htb]\n\\begin{center} \n\n\\begin{tabular}{lllll}\n\\begin{tabular}{c}\n Gradient \\\\\n direction \\\\\n \\end{tabular} &\n\\begin{tabular}{c}\n Prewitt \\\\\n compass   \\\\\n gradient \\\\\n\\end{tabular} &\nKirsch&\n\\begin{tabular}{c}\nRobinson \\\\\n3-level \\\\\n\\end{tabular}&\n\\begin{tabular}{c}\nRobinson \\\\\n5-level\\\\\n\\end{tabular} \\\\\nEast&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & -1\\\\\n1 & -2 & -1\\\\\n1 & 1 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n5 & -3 & -3\\\\\n5 & 0 & -3\\\\\n5 & -3 & -3\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n1 & 0 & -1\\\\\n1 & 0 & -1\\\\\n1 & 0 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n1 & 0 & -1\\\\\n2 & 0 & -2\\\\\n1 & 0 & -1\n\\end{array}\\right]  \\)\\\\\n Northeast&\n\\( \\left[ \\begin{array}{ccc}\n1 & -1 & -1\\\\\n1 & -2 & -1\\\\\n1 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-3 & -3 & -3\\\\\n5 & 0 & -3\\\\\n5 & 5 & -3\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n0 & -1 & -1\\\\\n1 & 0 & -1\\\\\n1 & 1 & 0\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n0 & -1 & -2\\\\\n1 & 0 & -1\\\\\n2 & 1 & 0\n\\end{array}\\right]  \\)\\\\\n North&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -1 & -1\\\\\n1 & -2 & 1\\\\\n1 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-3 & -3 & -3\\\\\n-3 & 0 & -3\\\\\n5 & 5 & 5\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -1 & -1\\\\\n0 & 0 & 0\\\\\n1 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -2 & -1\\\\\n0 & 0 & 0\\\\\n1 & 2 & 1\n\\end{array}\\right]  \\)\\\\\n Northwest&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -1 & 1\\\\\n-1 & -2 & 1\\\\\n1 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-3 & -3 & -3\\\\\n-3 & 0 & 5\\\\\n-3 & 5 & 5\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & -1 & 0\\\\\n-1 & 0 & 1\\\\\n0 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-2 & -1 & 0\\\\\n-1 & 0 & 1\\\\\n0 & 1 & 2\n\\end{array}\\right]  \\)\\\\\n West&\n\\( \\left[ \\begin{array}{ccc}\n-1 & 1 & 1\\\\\n-1 & -2 & 1\\\\\n-1 & 1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-3 & -3 & 5\\\\\n-3 & 0 & 5\\\\\n-3 & -3 & 5\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & 0 & 1\\\\\n-1 & 0 & 1\\\\\n-1 & 0 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-1 & 0 & 1\\\\\n-2 & 0 & 2\\\\\n-1 & 0 & 1\n\\end{array}\\right]  \\)\\\\\n Southwest&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n-1 & -2 & 1\\\\\n-1 & -1 & 1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n-3 & 5 & 5\\\\\n-3 & 0 & 5\\\\\n-3 & -3 & -3\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n0 & 1 & 1\\\\\n-1 & 0 & 1\\\\\n-1 & -1 & 0\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n0 & 1 & 2\\\\\n-1 & 0 & 1\\\\\n-2 & -1 & 0\n\\end{array}\\right]  \\)\\\\\n South&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n1 & -2 & 1\\\\\n-1 & -1 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n5 & 5 & 5\\\\\n-3 & 0 & -3\\\\\n-3 & -3 & -3\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n0 & 0 & 0\\\\\n-1 & -1 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n1 & 2 & 1\\\\\n0 & 0 & 0\\\\\n-1 & -2 & -1\n\\end{array}\\right]  \\)\\\\\n Southeast&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & 1\\\\\n1 & -2 & -1\\\\\n1 & -1 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n5 & 5 & -3\\\\\n5 & 0 & -3\\\\\n-3 & -3 & -3\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n1 & 1 & 0\\\\\n1 & 0 & -1\\\\\n0 & -1 & -1\n\\end{array}\\right]  \\)&\n\\( \\left[ \\begin{array}{ccc}\n2 & 1 & 0\\\\\n1 & 0 & -1\\\\\n0 & -1 & -2\n\\end{array}\\right]  \\)\\\\\n \\begin{tabular}{c}\n Scale  \\\\\n factor    \\\\\n \\end{tabular} &  \n \\begin{tabular}{c}\n\\( \\frac{1}{5} \\) \\\\\n \\end{tabular}&\n \\begin{tabular}{c}\n\\( \\frac{1}{15} \\) \\\\\n \\end{tabular}&\n \\begin{tabular}{c}\n \\( \\frac{1}{3} \\) \\\\\n  \\end{tabular} &\n  \\begin{tabular}{c}\n\\( \\frac{1}{4} \\) \\\\\n\\end{tabular} \\\\\n \\end{tabular} \n\\caption{Template gradients.}\n\\label{tab_grad2}\n\\end{center}\n\\end{table}\n\n\n\\clearpage\n\n\\subsection{Derivative of Gaussian}\nThe previous methods are relatively sensitive to the noise.  A solution \ncould be to extend the window size of the gradient mask operators.\nAnother approach is to use  the derivative of the \nconvolution of the image by a Gaussian.\nThe derivative of a Gaussian (DroG) operator is\n\\begin{eqnarray}\n\\bigtriangledown (g \\otimes f) & =  & {\\partial  (g \\otimes f) \\over \\partial x} +\n {\\partial  (g \\otimes f) \\over \\partial y} \\nonumber \\\\\n  & =  & f_x + f_y\n\\end{eqnarray}\nwith $g = \\exp{- {x^2+y^2 \\over {2\\sigma^2}}}$. Partial derivatives of the\nGaussian function are\n\\begin{eqnarray}\ng_x(x,y) & = {\\partial  g  \\over \\partial x} = & - {x \\over \\sigma^2} \\exp{- {x^2+y^2 \\over {2\\sigma^2}}} \\nonumber \\\\\ng_y(x,y) & = {\\partial  g  \\over \\partial y} = & - {y \\over \\sigma^2} \\exp{- {x^2+y^2 \\over {2\\sigma^2}}}\n\\end{eqnarray}\nThe filters are separable so we have\n\\begin{eqnarray}\ng_x(x,y) & = & g_x(x) * g(y) \\nonumber \\\\\ng_y(x,y) & = & g_y(y) * g(x)  \n\\end{eqnarray}\nThen\n\\begin{eqnarray}\nf_x & = & g_x (x) \\otimes g(y) \\otimes f \\nonumber \\\\\nf_y & = & g_y (y) \\otimes g(x) \\otimes f\n\\end{eqnarray}\n \n\\subsection{Thinning the contour}\nFrom the gradient map, we may want to consider only pixels which belong to the\ncontour. This can be done by looking for each pixel in the direction of \ngradient. For each point P0 in the gradient map, we determine the two \nadjacent pixels P1,P2\nin the direction orthogonal to the gradient. If P0 is not a maximum in \nthis direction (i.e.\\ P0 $<$ P1, or P0 $<$ P2), then we threshold P0 to \nzero.\n \n\\section{Second Order Derivative Edge Detection}\nSecond derivative operators allow us to accentuate the \nedges. The most frequently\nused operator is the Laplacian one, defined by \n\\begin{eqnarray}\n\\bigtriangledown^2 f = {\\partial^2  f  \\over \\partial x^2} \n                     + {\\partial^2  f  \\over \\partial y^2}\n\\end{eqnarray}\n\nTable~\\ref{tab_laplacian} gives three discrete approximation of this operators.\n \n\\begin{table}[htb]\n\\begin{center}\n\\begin{tabular}{ccc}\n Laplacian 1 &   Laplacian 2 &   Laplacian 3\\\\\n             &           &    \\\\\n\\( {1 \\over 4} \\left[ \\begin{array}{ccc}\n0 & -1 & 0\\\\\n-1 & 4 & -1\\\\\n0 & -1 & 0\n\\end{array}\\right]  \\) &\n\\( {1 \\over 8} \\left[ \\begin{array}{ccc}\n-1 & -1 & -1\\\\\n-1 & 8 & -1\\\\\n-1 & -1 & -1\n\\end{array}\\right]  \\) &  \n\\( {1 \\over 8} \\left[ \\begin{array}{ccc}\n-1 & -2 & -1\\\\\n-2 & 4 & -2\\\\\n-1 & -2 & -1\n\\end{array}\\right]  \\) \\\\\n\\end{tabular}\n\\caption{Laplacian operators.}\n\\label{tab_laplacian}\n\\end{center}\n\\end{table}\n\nMarr and Hildreth \\cite{edge:marr80} have proposed the Laplacian of Gaussian (LoG) edge detector operator.\nIt is defined as\n\\begin{eqnarray}\nL(x,y) = {1 \\over{\\pi s^4}} \n\t  \\left[ 1 - {{x^2+y^2} \\over {2s^2}} \\right] \n\\exp \\left( - {{x^2+y^2}\\over {2s^2}} \\right)\n\\end{eqnarray}\nwhere $\\sigma$ controls the width of the Gaussian kernel. \n\nZero-crossings of a given image $f$ convolved with $L$  \ngive its edge locations.\n\nA simple algorithm for zero-crossings is:\n\\begin{enumerate}\n\\item For all pixels i,j do\n\\item ZeroCross(i,j) = 0\n\\item P0 = G(i,j); P1 =  G(i,j-1); P2 =  G(i-1,j); P3 =  G(i-1,j-1)\n\\item If (P0*P1 $<$  0) or  (P0*P2 $<$  0) or (P0*P3 $<$ 0) then ZeroCross(i,j) = 1\n\\end{enumerate} \n\n\n\\section{Edge Detection Program: im\\_edge}\n\\index{im\\_edge}\nThe program {\\em im\\_edge} detects the edges in an image by the\nmethods previously described.\n{\\bf\n\\begin{center}\n     USAGE: im\\_edge option file\\_name\\_in file\\_name\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\item {\\bf [-M edge\\_detection\\_method}\n{\\small\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item Derivative of a Gaussian (DroG) \n\\item Pixel difference \n\\item Separated pixel difference \n\\item Sobel \n\\item Prewitt \n\\item Roberts \n\\item Frei Chen \n\\item Laplacian: filter 1 \n\\item Laplacian: filter 2 \n\\item Laplacian: filter 3 \n\\item Marr and Hildreth: Laplacian of Gaussian (LoG) \n\\item Prewitt compass gradient \n\\item Kirsch \n\\item Robinson 3-level \n\\item Robinson 5-level \n\\end{enumerate}}\nDefault is Sobel method\n\\item {\\bf [-k]} \\\\\nSelect local maxima in gradient direction for first derivative methods,\nand zero-crossings for second derivative methods. \\\\\nDefault is not to do these operations.\n\\item {\\bf [-t ThresholdValue]} \\\\\nThreshold all values in the edge map lower than {\\em ThresholdValue}.\n\\item {\\bf [-S Sigma]} \\\\\nScale parameter. Only used for DroG and LoG methods. \\\\\nDefault value is ${1 \\over \\sqrt{3}}$.\n\\end{itemize}\n\n\\clearpage\n\\newpage\n\n\\section{Wavelets and Edge Detection}\nThe LoG operator, also called the Mexican hat, is a well-known \nwavelet function\n(even if wavelets did not exist when the LoG operator was proposed!).\nFurthermore, a scale parameter ($\\sigma$) in this method leads to \na multiscale approach when $\\sigma$ is varying. The advantage of using\nthe wavelet framework is the existence of very fast WT, such as the \\`a trous\nalgorithm, which furnishes us with a  way to get the edges directly at all \ndyadic scales, even for large scales.\n\n\\subsection{Multiscale first derivative}\n\nGeneralizing the concept of multiscale edge detection, \nMallat \\cite{edge:mallat92a,edge:mallat92b,ima:mallat98} showed that \nthe DroG operators can be easily associated with a wavelet\ntransform.\nIf $\\phi(x)$ is a smoothing function (i.e. $\\int \\phi(x) dx = 1$), \nconverges to zero at infinity, and is differentiable, we denote\n\\begin{eqnarray}\n\\psi^{1}(x,y) = {{d \\phi(x,y)} \\over {dx}} \\quad \\mbox{ and } \\quad\n\\psi^{2}(x,y) = {{d \\phi(x,y)} \\over {dy}} \\quad \\mbox{     } \\quad\n \\end{eqnarray}\nBy definition, $\\psi^x$ and $\\psi^y$ are wavelets\n(their integral is equal to zero). The local extrema of the wavelet coefficients\nusing $\\psi^{x_1},\\psi^{y_1}$ correspond to the inflection points of $f*\\phi_s$ \n(with $\\phi_s = {1 \\over s} \\phi({x\\over s})$).\n\nUsing the directional \\`a trous algorithm, sometimes also called dyadic wavelet\ntransform, we have at each scale $j$ and at pixel location $(x,y)$ two wavelet\ncoefficients $w_{j,x}, w_{j,y}$. The modulus of the gradient is then defined by\n\\begin{eqnarray}\nG_j(x,y) = \\sqrt{ w_{j,x}^2 + w_{j,y}^2}\n\\end{eqnarray}\nand the directional angle $\\theta_j$ is\n\\begin{eqnarray}\n\\theta_j(x,y) = \\left\\{ \\begin{array}{cc}\n \\arctan({w_{j,y} \\over w_{j,x}})  & \\mbox{ if } w_{j,x} \\ge 0 \\\\\n \\pi - \\arctan({w_{j,y} \\over w_{j,x}})  & \\mbox{ if } w_{j,x} < 0\n\\end{array}\\right.\n\\end{eqnarray}\n  \nMultiscale edge points, also called modulus maxima, are points where \nthe modulus is locally maximum with respect to its neighbors along the\ndirection $\\theta_j$.\n\nA similar approach can be developed for the\n LoG operator \\cite{edge:mallat92a}.\n\n\n\\subsection{Image reconstruction from its multiscale edges}\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\psfig{figure=fig_project.ps,bbllx=4cm,bblly=16cm,bburx=20.5cm,bbury=26cm,width=12cm,height=8cm,clip=} \n\\caption{Approximation of the wavelet transform of $f$.}\n}}\n\\label{fig_project}\n\\end{figure}\n\nAn image can be reconstructed (approximately) from its multiscale edges\n\\cite{ima:mallat98} using an iterative algorithm. It does not\nconverge exactly towards the image, but in practice the error is very\nsmall. The algorithm consists of searching for an image $h$\nsuch that its wavelet transform has the same modulus maxima (i.e.\\ \nsame number of modulus maxima, same positions, and same amplitudes) as \nthose of the original image $f$.\nDenoting as $w_j(X)$ the wavelet coefficients of an image $X$ at a scale $j$,\nand $w^m_j(X)$ its modulus maxima, \nwe require that $w^m_j(h) = w^m_j(f)$.\nThe algorithm is the following:\n\\begin{enumerate}\n\\itemsep=0.1truecm\n\\item Set $w^m_j(h)$  to zero.\n\\item Loop:\n\\item Calculate the difference $w^m_j(f) - w^m_j(h)$, and\ninterpolate between the maxima: we get $w_j^d$.\n\\item Update $w_j(h)$: $w_j(h) = w_j(h) + w_j^d$.\n\\item Assign in $w_j(h)$ the correct values at maxima positions.\n\\item Reconstruct $h$  from  $w_j(h)$\n\\item Do a wavelet transform of $h$: $w_j(h)$ is then updated.  \n\\item Goto 2\n\\item Assign in $w_j(h)$ the correct values at maxima positions.\n\\item Reconstruct $h$  from  $w_j(h)$.\n\\end{enumerate}\nThe algorithm converges quickly to the solution after a few iterations.\nThe interpolation \\cite{edge:mallat92a} can be viewed \nas a projection on an affine space\n$\\Gamma$, and the inverse and forward wavelet transform as a projection\non the space V of all possible wavelet transform signals. The two \nprojections are visualized in Figure~\\ref{fig_project} ($Wh$ and $Wf$ \nare respectively the wavelet transform of $h$ and $f$).\n\n\n\\section{Multiscale Edge Detection Program}\n\\subsection{First derivative: mr\\_edge}\n\\index{mr\\_edge}\nThe program {\\em mr\\_edge} detects the edges in an image by the\nmethods previously described. The wavelet transform used is \nthe Mallat dyadic wavelet transform. The output file is a multiresolution\nfile (``.mr''). For each scale, two bands are stored, one \nthe maxima map and the second the gradient angle map. \n\n{\\bf\n\\begin{center}\n     USAGE: mr\\_edge option file\\_name\\_in file\\_name\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nNumber of scales used in the multiresolution transform.\nDefault is 4.\n\\end{itemize} \n\\subsubsection*{Examples:}\n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_edge image.d med.mr \\\\\nBuild the multiscale edge detection file.\n\\item mr\\_extract -B -s 1 med.mr mod1 \\\\\nCreate an image which contains the detected edge map (maxima) \nof the first scale.\n\\item mr\\_extract -B -s 2 med.mr ang1 \\\\\nCreate an image which contains the  gradient angle map\nof the previous edge map.\n\\item mr\\_extract -B -s 5 med.mr mod3 \\\\\n\\item mr\\_extract -B -s 6 med.mr ang3 \\\\\nDitto for scale 3.\n\\end{itemize} \n\n\\subsection{Second derivative: mr\\_at\\_edge}\n\\index{mr\\_at\\_edge}\nThe program {\\em mr\\_at\\_edge} detects the edges in an image by the\nmethods previously described. The wavelet transform used is \nthe \\`a trous algorithm. Only zero crossings of each scale are\nkept (i.e.\\ not thresholded).\nThe output file is a multiresolution\nfile (``.mr''). \n{\\bf\n\\begin{center}\n     USAGE: mr\\_at\\_edge option file\\_name\\_in file\\_name\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nNumber of scales used in the multiresolution transform.\nDefault is 4.\n\\end{itemize} \n\\subsubsection*{Examples:}\n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_at\\_edge image.d med.mr \\\\\nBuild the multiscale edge detection file.\n\\item mr\\_extract -s 1 med.mr zero1 \\\\\nCreate an image which contains the detected edge map of the first scale.\n\\item mr\\_extract -s 2 med.mr zero2 \\\\\nDitto for scale 2.\n\\end{itemize} \n\n\\subsection{Image reconstruction: mr\\_rec\\_edge}\n\\index{mr\\_rec\\_edge}\nThe program {\\em mr\\_rec\\_edge} reconstructs an image from its multiscale\nedges. \nThe multiscale edge file must have been obtained from the {\\em mr\\_edge}\nprogram. \n{\\bf\n\\begin{center}\n     USAGE: mr\\_rec\\_edge option file\\_name\\_in file\\_name\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\item {\\bf [-i number\\_of\\_iterations]} \\\\\nNumber of iterations.\nDefault is 10.\n\\end{itemize} \n\n\\newpage\n\n\\section{Contrast Enhancement}\n\\label{sec_contrast}\n\n\\subsection{Introduction}\nBecause some features are hardly detectable by eyes in a image, we\noften transform it before visualization. Histogram equalization is\ncertainly one the most well known method for contrast enhancement.\nSuch an approach is general useful for images\nwith a poor  intensity distribution. As edges play a fundamental \nrole in image understanding, a way to enhance the contrast is to \nenhance the edges. For example, we can add to the original image its Laplacian\n($I^{'}= I + \\gamma \\Delta I$, where $\\gamma$ is a parameter). Only\nfeatures at the finest scale are enhanced (linearly). For a high \n$\\gamma$ value, only the high frequencies are visible.\nMultiscale edge enhancement \\cite{col:velde99} can be seen \nas a generalization of this approach to all resolution levels.  \nImages with a high dynamic range are also \ndifficult to analyze. For example, astronomers generally visualize their\nimages using a logarithmic transformation. We see in the next\nsection that wavelet can also be used to compress the dynamic range\nat all scales, and therefore allows us to clearly see some very faint\nfeatures.\n\n\\subsection{Multiscale Edge Enhancement}\n\\subsubsection{Gray Images}\nVelde has proposed the following algorithm \\cite{col:velde99}:\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item The image  $L$ is mapped nonlinearly according to:\n\\begin{eqnarray}\n   L(i) \\rightarrow L(i)^{1-q} 100^q\n\\end{eqnarray}\n\\item The $L$ image is decomposed into a multiscale gradient\npyramid by using the dyadic wavelet transform (two directions per scale).\nThe gradient at the scale $j$, the pixel position $i$  is\ncalculated by: $G_j(i) = \\sqrt{ (w_j^{(h)}(i))^2 + (w_j^{(v)}(i))^2}$ where \n$w_j^{(h)}$ and $w_j^{(v)}$ are the wavelet coefficients in both \nvertical and diagonal directions\nat pixel position $i$. \n\\item The two wavelet coefficients at scale $j$ and at position $i$ \nare multiplied by  $y(G_j(i))$, \nwhere $y$ is defined by:\n\\begin{eqnarray}\n  y(x) & = & ({m \\over c})^p \\mbox{ if } \\mid x \\mid < c \\nonumber \\\\\n  y(x) & = & ({m \\over \\mid x \\mid })^p  \\mbox{ if } c \\le \\mid x \\mid < m \\nonumber \\\\\n  y(x) & = & 1  \\mbox{ if } \\mid x \\mid \\ge m\n\\end{eqnarray}\n\\item The $\\tilde L$image is reconstructed \nfrom the modified wavelet coefficients.\n\\item the $\\tilde L$ image is mapped nonlinearly according to:\n\\begin{eqnarray}\n  \\tilde L(i) \\rightarrow \\tilde L(i)^{1 \\over 1-q} 100^{- {q \\over {1-q}}}\n\\end{eqnarray}\n\\end{enumerate}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{  \n\\hbox{\n\\psfig{figure=fig_velde.ps,bbllx=3cm,bblly=13cm,bburx=20cm,bbury=25.cm,width=11cm,height=8cm,clip=}\n}}\n}\n\\caption{Enhanced coefficients versus  original coefficients.  \nParameters are m=30,c=3,p=0.5, and q=0.\n}\n\\label{fig_velde1}\n\\end{figure}\n\nFour parameters are needed $p$,$q$,$m$,$c$. \n$p$ determines the degree of non-linearity in the nonlinear rescaling\nof the luminance, and must be in $]0,1[$. $q$ must be in $[-0.5,0.5]$.\nWhen $q > 0$, then darker parts are less enhanced than the lighter parts.\nWhen $ q < 0$, then the dark parts are more enhanced than lighter parts.\nCoefficients larger than $m$ are not modified by the algorithm.\nThe $c$ parameter corresponds to the noise level.  \n\nFigure~\\ref{fig_velde1} shows the modified wavelet coefficients versus\nthe original wavelet coefficients for a given set parameters \n(m=30,c=3,p=0.5, and q=0).\n\n\n\\subsection{The LOG-Wavelet Representation of Gray Images}\n\nBy using the \\`a trous wavelet transform algorithm, an image $I$ \n\\index{a trous wavelet transform}\n\\index{wavelet transform}\ncan be defined as the sum of its $J$ wavelet scales and the last smooth \narray:\n\\begin{eqnarray}\nI(x,y) = c_{J}(x,y) + \\sum_{j=1}^{J} w_j(x,y) \n\\label{resid}\n\\end{eqnarray}\nwhere the first term on the right is the last smoothed array, \nand $w$ denotes a wavelet scale. See \\cite{starck:book98} more\ndetails about this algorithm.\nThe wavelet-log representations consists in replacing $w_j(x,y)$\nby $\\log(\\mid w_j(x,y)\\mid)$:\n\\begin{eqnarray}\nI_w(x,y) = \\log(c_{J}(x,y)) +  \\sum_{j=1}^{J} \\mathrm{sgn}(w_j(x,y)) \\log(\\mid w_j(x,y)\\mid) \n\\end{eqnarray}\n\n\\begin{figure}[htb]\n\\vbox{\n\\centerline{  \n\\hbox{\n\\psfig{figure=fig_comet.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=9cm,height=9cm,clip=}\n}}\n\\centerline{ \n\\hbox{\n\\psfig{figure=comet_wlog_m8.ps,bbllx=1.8cm,bblly=12.7cm,bburx=14.5cm,bbury=25.4cm,width=9cm,height=9cm,clip=}\n}}}\n\\caption{Hale-Bopp Comet image and its wavelet log representation.}\n\\label{fig_halebopp_wavelet}\n\\end{figure}\nFigure~\\ref{fig_halebopp_wavelet} left shows  the  logarithm of \nHale-Bopp comet image and right its wavelet log representation. The jets\nclearly appears in the last representation. \n\n\n\\subsection{Contrast Enhancement Program: mr\\_contrast}\n\\index{mr\\_contrast}\nThe program {\\em mr\\_contrast} enhances the contrast of a gray image. \nSeveral methods are available. \n{\\bf\n\\begin{center}\n USAGE: mr\\_contrast option in\\_image out\\_image\n\\end{center}}\nwhere options are:\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-m contrast\\_enhancement\\_method]} \n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item Histogram Equalization \n\\item Wavelet Coefficients Enhancement \n\\item Wavelet-Log function: $f(w) = log(\\mid w \\mid +L) $\n\\item Wavelet-Log function: $f(w) = sgn(w).log(\\mid w \\mid+L)$ \n\\item K-Sigma clipping.\n\\item Add to the image its Laplacian. \n\\end{enumerate}\nDefault is Wavelet Coefficients Enhancement.\n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nNumber of scales used in the wavelet transform.\nDefault is 4. \n\\item {\\bf [-M M\\_parameter]} \\\\\nM Parameter. Only used if ``-e'' option is set. \nCoefficients larger than M are not enhanced. \nDefault is 100.\n\\item {\\bf [-P P\\_parameter]} \\\\\nP Parameter. Only used if ``-e'' option is set. \nP must be in the interval $]0,1[$.\nDefault is $0.5$.\n\\item {\\bf [-Q Q\\_parameter]} \\\\ \nQ Parameter. Only used if ``-e'' option is set. \nQ must be in the interval $[-0.5,0.5]$. When $Q > 0$,\ndarker part are less enhanced than lighter part.\nWhen $Q < 0$, darker part are more enhanced than lighter part.\nDefault is $0$.\n\\item {\\bf [-C C\\_parameter]} \\\\  \nC Parameter. Only used if ``-e'' option is set. \nDefault is $0$.\n\\item {\\bf [-K ClippingValue]} \\\\\nClipping value. Default is 3.\n\\item {\\bf [-L Param]} \\\\\nParameter for for the Laplacian or the log method. Default is 0.1.\n\\end{itemize}\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item mr\\_contrast image.fits image\\_out.fits\\\\\nEnhance the contrast by multiscale edge method.\n\\item mr\\_contrast -n6 -m4 image.fits image\\_out.fits\\\\\nEnhance the contrast by wavelet log representation using six\nresolution levels.\n\\end{itemize}\n", "meta": {"hexsha": "5ec708691108fb4f2962fa57ef38dde1c4611943", "size": 27290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/ch_edge.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_mr1/ch_edge.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_mr1/ch_edge.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": 29.8904709748, "max_line_length": 118, "alphanum_fraction": 0.6714181019, "num_tokens": 9586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6240293115254864}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{fontspec} \n%\\XeTeXlinebreaklocale \"zh\" \n%\\XeTeXlinebreakskip = 0pt plus 1pt \n%\\setmainfont[Mapping=tex-text]{DejaVu Serif} % rm\n\\usepackage{graphicx}\n\\usepackage[a4paper]{geometry}\n%\\setlength{\\textwidth}{5in}\n%\\setlength{\\hoffset}{0.6in}\n%header\n\\usepackage{fancyhdr}\n%math package\n\\usepackage[fleqn]{amsmath}\n%\\usepackage{amsmath,amssymb}\n%code package\n%\\usepackage{minted}\n\\usepackage{listings}\n\\usepackage{minted}\n\\usepackage[lined,boxed]{algorithm2e}\n\n\n\\newcommand{\\horrule}[1]{\\rule{\\linewidth}{#1}} \n\\title{\t\n\\normalfont \\normalsize \\vspace{-13em} % Your university, school and/or department name(s)\n\\horrule{1pt} \\\\[0.5cm] % Thick bottom horizontal rule\n\\huge Neural Network\n\\\\ % The assignment title\n\\vspace{1em}\n\\large Assignment 1\n\\horrule{2pt} \\\\[0.5cm] % Thick bottom horizontal rule\n}\n\\author{Zhao Shenjian 5110309748}\n\\date{}\n\\pagestyle{fancy}\n\\rhead{Two Spiral Problem}\n\n\n\\begin{document}   \n\\maketitle\n\\thispagestyle{empty}\n\\setcounter{page}{1}\n\\section*{Part I: Back-propagation Algorithms}\n  \\subsection*{1.1 On-line learning} \n  \\subsubsection*{Case 1: Neuron j is an Output Node} \n  \\paragraph{} Because I don't have enough time to write the entire derivation, I only write the final result. It's definitely right, because I have check\n  it using my program.\\\\\n  \\begin{align*}\n    \\delta_{j}(n) &= e_j(n)f^{\\prime}_j(net_j) =  e_j(n)f(net_j)(1-f(net_j))\\\\\n     \\Delta u_{ji}(n) &= \\eta \\delta_j(n)x^{2}_i(n) \\\\\n     \\Delta v_{ji}(n) &= \\eta \\delta_j(n)x_i(n) \\\\\n     \\Delta b_j(n) &= \\eta \\delta_j(n)\n  \\end{align}\n\n  $f$ is sigmoid activation function, $net_j = \\Sigma  u_{kji}x^{2}_{k-1,i} + v_{kji}x_{k-1,i} + b_{kj}$\n\n  \\subsubsection*{Case 2: Neuron j is a Hidden Node} \n  \\begin{align*}\n    \\delta_{j}(n) &= f^{\\prime}_j(net_j) \\varSigma_{k}(\\delta_{k}(n)(2u_{kj}(n)x_j + v_{kj}(n)))\\\\\n     \\Delta u_{ji}(n) &= \\eta \\delta_j(n)x^{2}_i(n) \\\\\n     \\Delta v_{ji}(n) &= \\eta \\delta_j(n)x_i(n) \\\\\n     \\Delta b_j(n) &= \\eta \\delta_j(n)\n  \\end{align}\n  \n  \n  \n  \\subsection*{1.2 Batch learning}\n  \\subsubsection*{Case 1: Neuron j is an Output Node} \n   \\begin{align*}\n    \\delta_{j}(n) &= e_j(n)f^{\\prime}_j(net_j) =  e_j(n)f(net_j)(1-f(net_j))\\\\\n     \\Delta u_{ji}(n) &= \\cfrac{\\eta}{N} \\Sigma_n(\\delta_j(n)x^{2}_i(n)) \\\\\n     \\Delta v_{ji}(n) &= \\cfrac{\\eta}{N} \\Sigma_n(\\delta_j(n)x_i(n)) \\\\\n     \\Delta b_j(n) &= \\cfrac{\\eta}{N}\\Sigma_n\\delta_j(n)\n  \\end{align}\n  \n   \\subsubsection*{Case 2: Neuron j is a Hidden Node} \n    \\begin{align*}\n    \\delta_{j}(n) &= f^{\\prime}_j(net_j) \\varSigma_{k}(\\delta_{k}(n)(2u_{kj}(n)x_j + v_{kj}(n)))\\\\\n    \\Delta u_{ji}(n) &= \\cfrac{\\eta}{N} \\Sigma_n(\\delta_j(n)x^{2}_i(n)) \\\\\n     \\Delta v_{ji}(n) &= \\cfrac{\\eta}{N} \\Sigma_n(\\delta_j(n)x_i(n)) \\\\\n     \\Delta b_j(n) &= \\cfrac{\\eta}{N}\\Sigma_n\\delta_j(n)\n  \\end{align}\n  \n \\section*{Part II: C++ implementation}\n \\paragraph{}In order to master every detail of neural network and gain efficiency, I use c++ to solve this problem.\n The source code is in src folder. Please read the README to build and run the program. \n \\paragraph{}However I use matlab to plot the result image, it doesn't matter.\n\n \\section*{Part III: Test results}\n \\subsection*{3.1 Correctness}\n  \\paragraph{}\n First to say, my result is correct. The misclassification is 0 for both online learning and batch learning. The following two pictures\n shows the results.\n\n \n \\begin{figure}[h]\n\\centering\n\\subfigure{\n\\includegraphics[width=.35\\textwidth]{batch_result}\n}\n\\subfigure{\n\\includegraphics[width=.35\\textwidth]{seq_result}\n}\n\n\\caption{Batch result(left) and Online result(right)}\n\\label{fig:result}\n\\end{figure}\n\n\\subsection*{3.2 Efficiency}\n  \\paragraph{} Although the results are both correct, the online learning is more efficient according to my test result.\n  The learning rate in batch mode should be much larger than online learning. I don't why. And I have tried many learning rate,\n  the total epochs of batch mode is 10 times  more than online learning. \n\n\\begin{figure}[h!]\n      \\centering\n      \\includegraphics{running_time}\n      \\caption{Running time comparison}\n      \\end{figure}\n      \n      \n \n\n\\end{document} \n", "meta": {"hexsha": "e767130d595276e326bf115622755c237cf85a34", "size": 4195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nn/two_spiral/A1.tex", "max_stars_repo_name": "SwordYork/MachineLearning", "max_stars_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2015-02-09T20:07:27.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-10T06:40:54.000Z", "max_issues_repo_path": "nn/two_spiral/A1.tex", "max_issues_repo_name": "SwordYork/MachineLearning", "max_issues_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "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": "nn/two_spiral/A1.tex", "max_forks_repo_name": "SwordYork/MachineLearning", "max_forks_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2015-07-08T13:10:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:10:53.000Z", "avg_line_length": 33.8306451613, "max_line_length": 154, "alphanum_fraction": 0.6753277712, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146849, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6240293103706246}}
{"text": "\\subsection{\\textcolor{cyan}{Parity Inversion}}\\label{sec:inversion}\n\n\\Figure[tb](topskip=0pt, botskip=0pt, midskip=0pt){figures/tikz/build/main-figure6.pdf}{\n    The node delays $\\delta_N$ for nodes for 3 odd node-trees $\\{\\nset_1, \\nset_2, \\nset_3\\}$ of 3 nodes that grow and join into a single node-tree. \\emph{(a)} Node delays are calculated via \\Cref{eq:nodedelay}. In step 1, the growth in each of the three node-trees' outer nodes is prioritized, since their delay are zero, and the node-trees merge with new edges. In step 2, the recalculation of the joined node-tree is performed. Parities within the subtree of $\\nset_2$ are now inverted, and the maximum node delay in $\\nset_2$ has doubled compared to before growth. \\emph{(b)} Node delays are calculated with \\Cref{eq:pmwdifnew} instead of \\Cref{eq:pmwdif}. Now the increase in $\\delta_N$ after parity inversion is halved.\\label{fig:partialdfs}}\n\nAn unfortunate effect, which we dub \\textbf{parity inversion}, causes a decrease in the algorithm's performance as the lattice size is increased. We will demonstrate this effect through the example in \\Cref{fig:partialdfs}\\emph{a}. Consider three instances of the node-tree of \\Cref{fig0}; $\\nset_a, \\nset_b, \\nset_c$, positioned near each other on the lattice. For each node-tree, if the middle node is suspended from growth for two iterations, all nodes have the same Potential Matching Weight. However, in the example, the node-trees $\\nset_a, \\nset_b, \\nset_c$ merge after one iteration. The combined node-tree is odd. Thus, we recalculate the node parities and delays to find that the parities in the partition of the node-tree containing the nodes of $\\nset_b$ have been inverted, and the node suspensions in this partition have doubled with respect to their value before the merger. If the next merging event occurs on the node with the doubled node suspension, the matching weight may be large, in contrast with the goal of decreasing the matching weight. Moreover, the effect of parity inversion accumulates if subsequent mergers occur before zero node suspension has been reached. %Nevertheless, as more inversions occur, the maximum node suspension in the node-tree increases, and it becomes more and more unlikely for a cluster to actually reach zero node suspension in all nodes. The number of inversions is directly related to the number of merging events, and thus to the size of the lattice. The performance to improve the heuristic for minimum weight matching thus decreases for larger lattices. \n\n%Parity inversion defines a trade-off in the Partitioned-Growth data structure: `A node must wait as many iterations as it is suspended to reach equilibrium in Potential Matching Weight in the node-tree. However, after Parity Inversion, the node suspension for previously prioritized nodes increases linearly with the number of iterations waited by the suspended nodes pre-inversion.' As a compromise, \nTo compensate the effect of parity inversion, we redefine the node delay as \\textbf{half} the number of growth iterations needed for all nodes in the node-tree to reach equal PMW. This changes \\Cref{eq:nodedelay} to:\n\\begin{equation}\\label{eq:pmwdifnew}\n  \\delta_N = \\frac{1}{2}\\left(\\text{PWM}(N) - \\min_{N\\in\\nset}{\\text{PWM}(N) }\\right)\n\\end{equation}", "meta": {"hexsha": "40d59ece47f77fc5baca4e2923a9a9e049335223", "size": 3281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_algo_f_inversion.tex", "max_stars_repo_name": "watermarkhu/tqe_paper_ufbb", "max_stars_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_f_inversion.tex", "max_issues_repo_name": "watermarkhu/tqe_paper_ufbb", "max_issues_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "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": "sec_algo_f_inversion.tex", "max_forks_repo_name": "watermarkhu/tqe_paper_ufbb", "max_forks_repo_head_hexsha": "f9b171049e028ace58be3ab4a01cddac94f7e01e", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-11T15:53:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-11T15:53:16.000Z", "avg_line_length": 273.4166666667, "max_line_length": 1613, "alphanum_fraction": 0.7857360561, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6240293001037762}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{numprint}\n\n\\author{Daniel Fernandes Martins (danielfmt)}\n\\title{Question \\#10 Solution}\n\n\\begin{document}\n\n\\maketitle\n\n\\textbf{Disclaimer.} This is the reasoning I used to solve the problem; it\nmay be wrong though. This is intended just as food for thought.\n\n\\section{Parameters Of Neural Network}\n\nGiven a neural network with 10 input units (including the constant $x_0^{(0)}$\nunit), one output unit, and 36 hidden units (including the necessary number of\nconstant units for a fully-connected network), this question asks what is the\nmaximum possible number of weights that such a network can have.\n\n\\subsection{Solution By Trial And Error}\n\nI found the solution by trying different configurations until I got a number of\nweights equal to the highest number given in the alternatives.\n\nThe configuration I found has $L=3$; $d^{(0)}=10$, $d^{(1)}=22$, $d^{(2)}=14$,\n$d^{(3)}=1$. The number of weights in this network is given by:\n\n\\begin{equation*}\n(21 \\cdot 10) + (13 \\cdot 22) + (14) = 510\n\\end{equation*}\n\n\\end{document}\n", "meta": {"hexsha": "8133f1f15b9ef2e75765fa2e96e21ae8a3865d23", "size": 1082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-06/math/q10.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-06/math/q10.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-06/math/q10.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": 30.0555555556, "max_line_length": 79, "alphanum_fraction": 0.7421441774, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6240292971415345}}
{"text": "% arara: indent: {overwrite: true, trace: on}\n% A sample chapter file- it contains a lot of\n% environments, including tabulars, align, etc\n%\n% Don't try and compile this file using pdflatex etc, just\n% compare the *format* of it to the format of the\n% sampleAFTER.tex\n%\n% In particular, compare the tabular and align-type\n% environments before and after running the script\n\n\\section{Polynomial functions}\n \\reformatstepslist{P} % the steps list should be P1, P2, \\ldots\n In your previous mathematics classes you have studied \\emph{linear} and\n \\emph{quadratic} functions. The most general forms of these types of\n functions can be represented (respectively) by  the functions $f$\n and $g$ that have formulas\n \\begin{equation}\\label{poly:eq:linquad}\n\t f(x)=mx+b, \\qquad g(x)=ax^2+bx+c\n \\end{equation}\n We know that $m$ is the slope of $f$, and that $a$ is the \\emph{leading coefficient}\n of $g$. We also know that the \\emph{signs} of $m$ and $a$ completely\n determine the behavior of the functions $f$ and $g$. For example, if $m>0$\n then $f$ is an \\emph{increasing} function, and if $m<0$ then $f$ is\n a \\emph{decreasing} function.  Similarly, if $a>0$ then $g$ is\n \\emph{concave up} and if $a<0$ then $g$ is \\emph{concave down}. Graphical\n representations of these statements are given in \\cref{poly:fig:linquad}.\n\n \\begin{figure}[!htb]\n\t \\setlength{\\figurewidth}{.2\\textwidth}\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t framed,\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t xtick={-11},\n\t\t\t\t\t ytick={-11},\n\t\t\t\t ]\n\t\t\t\t \\addplot expression[domain=-10:8]{(x+2)};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{$m>0$}\n\t \\end{subfigure}\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t framed,\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t xtick={-11},\n\t\t\t\t\t ytick={-11},\n\t\t\t\t ]\n\t\t\t\t \\addplot expression[domain=-10:8]{-(x+2)};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{$m<0$}\n\t \\end{subfigure}\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t framed,\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t xtick={-11},\n\t\t\t\t\t ytick={-11},\n\t\t\t\t ]\n\t\t\t\t \\addplot expression[domain=-4:4]{(x^2-6)};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{$a>0$}\n\t \\end{subfigure}\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t framed,\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t xtick={-11},\n\t\t\t\t\t ytick={-11},\n\t\t\t\t ]\n\t\t\t\t \\addplot expression[domain=-4:4]{-(x^2-6)};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{$a<0$}\n\t \\end{subfigure}\n\t \\caption{Typical graphs of linear and quadratic functions.}\n\t \\label{poly:fig:linquad}\n \\end{figure}\n\n Let's look a little more closely at the formulas for $f$ and $g$ in\n \\cref{poly:eq:linquad}. Note that the \\emph{degree}\n of $f$ is $1$ since the highest power of $x$ that is present in the\n formula for $f(x)$ is $1$. Similarly, the degree of $g$ is $2$ since\n the highest power of $x$ that is present in the formula for $g(x)$\n is $2$.\n\n In this section we will build upon our knowledge of these elementary\n functions. In particular, we will generalize the functions $f$ and $g$ to a function $p$ that has\n any degree that we wish.\n\n %===================================\n %   Author: Hughes\n %   Date:   March 2012\n %===================================\n \\begin{essentialskills}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Quadratic functions]\n\t Every quadratic function has the form $y=ax^2+bx+c$; state the value\n\t of $a$ for each of the following functions, and hence decide if the\n\t parabola that represents the function opens upward or downward.\n\t \\begin{multicols}{2}\n\t\t \\begin{subproblem}\n\t\t\t $F(x)=x^2+3$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $a=1$; the parabola opens upward.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $G(t)=4-5t^2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $a=-5$; the parabola opens downward.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $H(y)=4y^2-96y+8$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $a=4$; the parabola opens upward.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $K(z)=-19z^2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m=-19$; the parabola opens downward.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t Now let's generalize our findings for the most general quadratic function $g$\n\t that has formula $g(x)=a_2x^2+a_1x+a_0$. Complete the following sentences.\n\t \\begin{subproblem}\n\t\t When $a_2>0$, the parabola that represents $y=g(x)$ opens $\\ldots$\n\t\t \\begin{shortsolution}\n\t\t\t When $a_2>0$, the parabola that represents the function opens upward.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t When $a_2<0$, the parabola that represents $y=g(x)$ opens $\\ldots$\n\t\t \\begin{shortsolution}\n\t\t\t When $a_2<0$, the parabola that represents the function opens downward.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n \\end{essentialskills}\n\n \\subsection*{Power functions with positive exponents}\n\t The study of polynomials will rely upon a good knowledge\n\t of power functions| you may reasonably ask, what is a power function?\n\t \\begin{pccdefinition}[Power functions]\n\t\t Power functions have the form\n\t\t \\[\n\t\t\t f(x) = a_n x^n\n\t\t \\]\n\t\t where $n$ can be any real number.\n\n\t\t Note that for this section we will only be concerned with the\n\t\t case when $n$ is a positive integer.\n\t \\end{pccdefinition}\n\n\t You may find assurance in the fact that you are already very comfortable\n\t with power functions that have $n=1$ (linear) and $n=2$ (quadratic). Let's\n\t explore some power functions that you might not be so familiar with.\n\t As you read \\cref{poly:ex:oddpow,poly:ex:evenpow}, try and spot\n\t as many patterns and similarities as you can.\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[Power functions with odd positive exponents]\n\t\t \\label{poly:ex:oddpow}\n\t\t Graph each of the following functions, state their domain, and their\n\t\t long-run behavior as $x\\rightarrow\\pm\\infty$\n\t\t \\[\n\t\t\t f(x)=x^3,   \\qquad  g(x)=x^5, \\qquad h(x)=x^7\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t The functions $f$, $g$, and $h$ are plotted in \\cref{poly:fig:oddpow}.\n\t\t\t The domain of each of the functions $f$, $g$, and $h$ is $(-\\infty,\\infty)$. Note that\n\t\t\t the long-run behavior of each of the functions is the same, and in particular\n\t\t\t \\begin{align*}\n\t\t\t\t f(x)\\rightarrow\\infty                           & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t \\mathllap{\\text{and }}   f(x)\\rightarrow-\\infty & \\text{ as } x\\rightarrow-\\infty\n\t\t\t \\end{align*}\n\t\t\t The same results hold for $g$ and $h$.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t \\begin{figure}[!htb]\n\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-1.5,xmax=1.5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t xtick={-1.0,-0.5,...,1.0},\n\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t legend pos=north west,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-1.5:1.5]{x^3};\n\t\t\t\t\t \\addplot expression[domain=-1.379:1.379]{x^5};\n\t\t\t\t\t \\addplot expression[domain=-1.258:1.258]{x^7};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-1,-1)} node[axisnode,anchor=north west]{$(-1,-1)$};\n\t\t\t\t\t \\addplot[soldot]coordinates{(1,1)} node[axisnode,anchor=south east]{$(1,1)$};\n\t\t\t\t\t \\legend{$f$,$g$,$h$}\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{Odd power functions}\n\t\t\t \\label{poly:fig:oddpow}\n\t\t \\end{minipage}%\n\t\t \\hfill\n\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-2.5,xmax=2.5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t xtick={-2.0,-1.5,...,2.0},\n\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t legend pos=south east,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.236:2.236]{x^2};\n\t\t\t\t\t \\addplot expression[domain=-1.495:1.495]{x^4};\n\t\t\t\t\t \\addplot expression[domain=-1.307:1.307]{x^6};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-1,1)} node[axisnode,anchor=east]{$(-1,1)$};\n\t\t\t\t\t \\addplot[soldot]coordinates{(1,1)} node[axisnode,anchor=west]{$(1,1)$};\n\t\t\t\t\t \\legend{$F$,$G$,$H$}\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{Even power functions}\n\t\t\t \\label{poly:fig:evenpow}\n\t\t \\end{minipage}%\n\t \\end{figure}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[Power functions with even positive exponents]\\label{poly:ex:evenpow}%\n\t\t Graph each of the following functions, state their domain, and their\n\t\t long-run behavior as $x\\rightarrow\\pm\\infty$\n\t\t \\[\n\t\t\t F(x)=x^2, \\qquad G(x)=x^4, \\qquad H(x)=x^6\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t The functions $F$, $G$, and $H$ are plotted in \\cref{poly:fig:evenpow}. The domain\n\t\t\t of each of the functions is $(-\\infty,\\infty)$. Note that the long-run behavior\n\t\t\t of each of the functions is the same, and in particular\n\t\t\t \\begin{align*}\n\t\t\t\t F(x)\\rightarrow\\infty                          & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t \\mathllap{\\text{and }}   F(x)\\rightarrow\\infty & \\text{ as } x\\rightarrow-\\infty\n\t\t\t \\end{align*}\n\t\t\t The same result holds for $G$ and $H$.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t \\begin{doyouunderstand}\n\t\t \\begin{problem}\n\t\t Repeat \\cref{poly:ex:oddpow,poly:ex:evenpow} using (respectively)\n\t\t \\begin{subproblem}\n\t\t\t $f(x)=-x^3,   \\qquad  g(x)=-x^5, \\qquad h(x)=-x^7$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t The functions $f$, $g$, and $h$ have domain $(-\\infty,\\infty)$ and\n\t\t\t\t are graphed below.\n\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-1.5,xmax=1.5,\n\t\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t\t xtick={-1.0,-0.5,...,0.5},\n\t\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t\t legend pos=north east,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-1.5:1.5]{-x^3};\n\t\t\t\t\t\t \\addplot expression[domain=-1.379:1.379]{-x^5};\n\t\t\t\t\t\t \\addplot expression[domain=-1.258:1.258]{-x^7};\n\t\t\t\t\t\t \\legend{$f$,$g$,$h$}\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\n\t\t\t\t Note that\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t f(x)\\rightarrow-\\infty                         & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}   f(x)\\rightarrow\\infty & \\text{ as } x\\rightarrow-\\infty\n\t\t\t\t \\end{align*}\n\t\t\t\t The same is true for $g$ and $h$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $F(x)=-x^2,   \\qquad  G(x)=-x^4, \\qquad H(x)=-x^6$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t The functions $F$, $G$, and $H$ have domain $(-\\infty,\\infty)$ and\n\t\t\t\t are graphed below.\n\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-2.5,xmax=2.5,\n\t\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t\t xtick={-1.0,-0.5,...,0.5},\n\t\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t\t legend pos=north east,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-2.236:2.236]{-x^2};\n\t\t\t\t\t\t \\addplot expression[domain=-1.495:1.495]{-x^4};\n\t\t\t\t\t\t \\addplot expression[domain=-1.307:1.307]{-x^6};\n\t\t\t\t\t\t \\legend{$F$,$G$,$H$}\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\n\t\t\t\t Note that\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t F(x)\\rightarrow-\\infty                          & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}   F(x)\\rightarrow-\\infty & \\text{ as } x\\rightarrow-\\infty\n\t\t\t\t \\end{align*}\n\t\t\t\t The same is true for $G$ and $H$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\end{problem}\n\t \\end{doyouunderstand}\n\n \\subsection*{Polynomial functions}\n\t Now that we have a little more familiarity with power functions,\n\t we can define polynomial functions. Provided that you were comfortable\n\t with our opening discussion about linear and quadratic functions (see\n\t $f$ and $g$ in \\cref{poly:eq:linquad}) then there is every chance\n\t that you'll be able to master polynomial functions as well; just remember\n\t that polynomial functions are a natural generalization of linear\n\t and quadratic functions. Once you've studied the examples and problems\n\t in this section, you'll hopefully agree that polynomial functions\n\t are remarkably predictable.\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccdefinition}[Polynomial functions]\n\t\t Polynomial functions have the form\n\t\t \\[\n\t\t\t p(x)=a_nx^n+a_{n-1}x^{n-1}+\\ldots+a_1x+a_0\n\t\t \\]\n\t\t where $a_n$, $a_{n-1}$, $a_{n-2}$, \\ldots, $a_0$ are real numbers.\n\t\t \\begin{itemize}\n\t\t\t \\item We call $n$ the degree of the polynomial, and require that $n$\n\t\t\t       is a non-negative integer;\n\t\t\t \\item $a_n$, $a_{n-1}$, $a_{n-2}$, \\ldots, $a_0$ are called the coefficients;\n\t\t\t \\item We typically write polynomial functions in descending powers of $x$.\n\t\t \\end{itemize}\n\t\t In particular, we call $a_n$ the \\emph{leading} coefficient, and $a_nx^n$ the\n\t\t \\emph{leading term}.\n\n\t\t Note that if a polynomial is given in factored form, then the degree can be found\n\t\t by counting the number of linear factors.\n\t \\end{pccdefinition}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[Polynomial or not]\n\t\t Identify the following functions as polynomial or not; if the function\n\t\t is a polynomial, state its degree.\n\t\t \\begin{multicols}{3}\n\t\t\t \\begin{enumerate}\n\t\t\t\t \\item $p(x)=x^2-3$\n\t\t\t\t \\item $q(x)=-4x^{\\nicefrac{1}{2}}+10$\n\t\t\t\t \\item $r(x)=10x^5$\n\t\t\t\t \\item $s(x)=x^{-2}+x^{23}$\n\t\t\t\t \\item $f(x)=-8$\n\t\t\t\t \\item $g(x)=3^x$\n\t\t\t\t \\item $h(x)=\\sqrt[3]{x^7}-x^2+x$\n\t\t\t\t \\item $k(x)=4x(x+2)(x-3)$\n\t\t\t\t \\item $j(x)=x^2(x-4)(5-x)$\n\t\t\t \\end{enumerate}\n\t\t \\end{multicols}\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{enumerate}\n\t\t\t\t \\item $p$ is a polynomial, and its degree is $2$.\n\t\t\t\t \\item $q$ is \\emph{not} a polynomial, because $\\frac{1}{2}$ is not an integer.\n\t\t\t\t \\item $r$ is a polynomial, and its degree is $5$.\n\t\t\t\t \\item $s$ is \\emph{not} a polynomial, because $-2$ is not a positive integer.\n\t\t\t\t \\item $f$ is a polynomial, and its degree is $0$.\n\t\t\t\t \\item $g$ is \\emph{not} a polynomial, because the independent\n\t\t\t\t       variable, $x$, is in the exponent.\n\t\t\t\t \\item $h$ is \\emph{not} a polynomial, because $\\frac{7}{3}$ is not an integer.\n\t\t\t\t \\item $k$ is a polynomial, and its degree is $3$.\n\t\t\t\t \\item $j$ is a polynomial, and its degree is $4$.\n\t\t\t \\end{enumerate}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[Typical graphs]\\label{poly:ex:typical}\n\t\t \\Cref{poly:fig:typical} shows graphs of some polynomial functions;\n\t\t the ticks have deliberately been left off the axis to allow us to concentrate\n\t\t on the features of each graph. Note in particular that:\n\t\t \\begin{itemize}\n\t\t\t \\item \\cref{poly:fig:typical1} shows a degree-$1$ polynomial (you might also\n\t\t\t       classify the function as linear) whose leading coefficient, $a_1$, is positive.\n\t\t\t \\item \\cref{poly:fig:typical2} shows a degree-$2$ polynomial (you might also\n\t\t\t       classify the function as quadratic) whose leading coefficient, $a_2$, is positive.\n\t\t\t \\item \\cref{poly:fig:typical3} shows a degree-$3$ polynomial whose leading coefficient, $a_3$,\n\t\t\t       is positive| compare its overall\n\t\t\t       shape and long-run behavior to the functions described in \\cref{poly:ex:oddpow}.\n\t\t\t \\item \\cref{poly:fig:typical4} shows a degree-$4$ polynomial whose leading coefficient, $a_4$,\n\t\t\t       is positive|compare its overall shape and long-run behavior to the functions described in \\cref{poly:ex:evenpow}.\n\t\t\t \\item \\cref{poly:fig:typical5} shows a degree-$5$ polynomial whose leading coefficient, $a_5$,\n\t\t\t       is positive| compare its overall\n\t\t\t       shape and long-run behavior to the functions described in \\cref{poly:ex:oddpow}.\n\t\t \\end{itemize}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{figure}[!htb]\n\t\t \\begin{widepage}\n\t\t \\setlength{\\figurewidth}{\\textwidth/6}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-10:8]{(x+2)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$a_1>0$}\n\t\t\t \\label{poly:fig:typical1}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4:4]{(x^2-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$a_2>0$}\n\t\t\t \\label{poly:fig:typical2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-7.5:7.5]{0.05*(x+6)*x*(x-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$a_3>0$}\n\t\t\t \\label{poly:fig:typical3}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.35:5.35,samples=100]{0.2*(x-5)*x*(x-3)*(x+2)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$a_4>0$}\n\t\t\t \\label{poly:fig:typical4}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-5.5:6.3,samples=100]{0.01*(x+2)*x*(x-3)*(x+5)*(x-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$a_5>0$}\n\t\t\t \\label{poly:fig:typical5}\n\t\t \\end{subfigure}\n\t\t \\end{widepage}\n\t\t \\caption{Graphs to illustrate typical curves of polynomial functions.}\n\t\t \\label{poly:fig:typical}\n\t \\end{figure}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{doyouunderstand}\n\t\t \\begin{problem}\n\t\t Use \\cref{poly:ex:typical} and \\cref{poly:fig:typical} to help you sketch\n\t\t the graphs of polynomial functions that have negative leading coefficients| note\n\t\t that there are many ways to do this! The intention with this problem\n\t\t is to use your knowledge of transformations- in particular, \\emph{reflections}-\n\t\t to guide you.\n\t\t \\begin{shortsolution}\n\t\t\t $a_1<0$:\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-10:8]{-(x+2)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $a_2<0$\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4:4]{-(x^2-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $a_3<0$\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-7.5:7.5]{-0.05*(x+6)*x*(x-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $a_4<0$\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.35:5.35,samples=100]{-0.2*(x-5)*x*(x-3)*(x+2)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $a_5<0$\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t xtick={-11},\n\t\t\t\t\t\t ytick={-11},\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-5.5:6.3,samples=100]{-0.01*(x+2)*x*(x-3)*(x+5)*(x-6)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t\t \\end{problem}\n\t \\end{doyouunderstand}\n\n\t \\fixthis{poly: Need a more basic example here- it can have a similar\n\t\t format to the multiple zeros example, but just keep it simple; it should\n\t\t be halfway between the 2 examples surrounding it}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Multiple zeros]\n\t\t Consider the polynomial functions $p$, $q$, and $r$ which are\n\t\t graphed in \\cref{poly:fig:moremultiple}.\n\t\t The formulas for $p$, $q$, and $r$ are as follows\n\t\t \\begin{align*}\n\t\t\t p(x) & =(x-3)^2(x+4)^2       \\\\\n\t\t\t q(x) & =x(x+2)^2(x-1)^2(x-3) \\\\\n\t\t\t r(x) & =x(x-3)^3(x+1)^2\n\t\t \\end{align*}\n\t\t Find the degree of $p$, $q$, and $r$, and decide if the functions bounce off or cut\n\t\t through the horizontal axis at each of their zeros.\n\t\t \\begin{pccsolution}\n\t\t\t The degree of $p$ is 4. Referring to \\cref{poly:fig:bouncep},\n\t\t\t the curve bounces off the horizontal axis at both zeros, $3$ and $4$.\n\n\t\t\t The degree of $q$ is 6. Referring to \\cref{poly:fig:bounceq},\n\t\t\t the curve bounces off the horizontal axis at $-2$ and $1$, and cuts\n\t\t\t through the horizontal axis at $0$ and $3$.\n\n\t\t\t The degree of $r$ is 6. Referring to \\cref{poly:fig:bouncer},\n\t\t\t the curve bounces off the horizontal axis at $-1$, and cuts through\n\t\t\t the horizontal axis at $0$ and at $3$, although is flattened immediately to the left and right of $3$.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t \\setlength{\\figurewidth}{0.25\\textwidth}\n\t \\begin{figure}[!htb]\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-6,xmax=5,\n\t\t\t\t\t\t ymin=-30,ymax=200,\n\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-5.63733:4.63733,samples=50]{(x-3)^2*(x+4)^2};\n\t\t\t\t\t \\addplot[soldot]coordinates{(3,0)(-4,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=p(x)$}\n\t\t\t \\label{poly:fig:bouncep}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-3,xmax=4,\n\t\t\t\t\t\t xtick={-2,...,3},\n\t\t\t\t\t\t ymin=-60,ymax=40,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot+[samples=50] expression[domain=-2.49011:3.11054]{x*(x+2)^2*(x-1)^2*(x-3)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-2,0)(0,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=q(x)$}\n\t\t\t \\label{poly:fig:bounceq}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-2,xmax=4,\n\t\t\t\t\t\t xtick={-1,...,3},\n\t\t\t\t\t\t ymin=-40,ymax=40,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-1.53024:3.77464,samples=50]{x*(x-3)^3*(x+1)^2};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-1,0)(0,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=r(x)$}\n\t\t\t \\label{poly:fig:bouncer}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\label{poly:fig:moremultiple}\n\t \\end{figure}\n\n\t \\begin{pccdefinition}[Multiple zeros]\\label{poly:def:multzero}\n\t\t Let $p$ be a polynomial that has a repeated linear factor $(x-a)^n$. Then we say\n\t\t that $p$ has a multiple zero at $a$ of multiplicity $n$ and\n\t\t \\begin{itemize}\n\t\t\t \\item if the factor $(x-a)$ is repeated an even number of times, the graph of $y=p(x)$ does not\n\t\t\t       cross the $x$ axis at $a$, but `bounces' off the horizontal axis at $a$.\n\t\t\t \\item if the factor $(x-a)$ is repeated an odd number of times, the graph of $y=p(x)$ crosses the\n\t\t\t       horizontal axis at $a$, but it looks `flattened' there\n\t\t \\end{itemize}\n\t\t If $n=1$, then we say that $p$ has a \\emph{simple} zero at $a$.\n\t \\end{pccdefinition}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Find a formula]\n\t\t Find formulas for the polynomial functions, $p$ and $q$, graphed in \\cref{poly:fig:findformulademoboth}.\n\t\t \\begin{figure}[!htb]\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[framed,\n\t\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t\t minor xtick={-3,-1,...,3},\n\t\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t grid=both]\n\t\t\t\t\t\t \\addplot expression[domain=-3.25842:2.25842,samples=50]{-x*(x-2)*(x+3)*(x+1)};\n\t\t\t\t\t\t \\addplot[soldot]coordinates{(1,8)}node[axisnode,inner sep=.35cm,anchor=west]{$(1,8)$};\n\t\t\t\t\t\t \\addplot[soldot]coordinates{(-3,0)(-1,0)(0,0)(2,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{$p$}\n\t\t\t\t \\label{poly:fig:findformulademo}\n\t\t\t \\end{subfigure}\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[framed,\n\t\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t\t minor xtick={-3,-1,...,3},\n\t\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t grid=both]\n\t\t\t\t\t\t \\addplot expression[domain=-4.33:4.08152]{-.25*(x+2)^2*(x-3)};\n\t\t\t\t\t\t \\addplot[soldot]coordinates{(2,4)}node[axisnode,anchor=south west]{$(2,4)$};\n\t\t\t\t\t\t \\addplot[soldot]coordinates{(-2,0)(3,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{$q$}\n\t\t\t\t \\label{poly:fig:findformulademo1}\n\t\t\t \\end{subfigure}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:findformulademoboth}\n\t\t \\end{figure}\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{enumerate}\n\t\t\t\t \\item We begin by noting that the horizontal intercepts of $p$ are $(-3,0)$, $(-1,0)$, $(0,0)$ and $(2,0)$.\n\t\t\t\t       We also note that each zero is simple (multiplicity $1$).\n\t\t\t\t       If we assume that $p$ has no other zeros, then we can start by writing\n\t\t\t\t       \\begin{align*}\n\t\t\t\t\t       p(x) & =(x+3)(x+1)(x-0)(x-2) \\\\\n\t\t\t\t\t            & =x(x+3)(x+1)(x-2)     \\\\\n\t\t\t\t       \\end{align*}\n\t\t\t\t       According to \\cref{poly:fig:findformulademo}, the point $(1,8)$ lies\n\t\t\t\t       on the curve $y=p(x)$.\n\t\t\t\t       Let's check if the formula we have written satisfies this requirement\n\t\t\t\t       \\begin{align*}\n\t\t\t\t\t       p(1) & = (1)(4)(2)(-1) \\\\\n\t\t\t\t\t            & = -8\n\t\t\t\t       \\end{align*}\n\t\t\t\t       which is clearly not correct| it is close though. We can correct this by\n\t\t\t\t       multiplying $p$ by a constant $k$; so let's assume that\n\t\t\t\t       \\[\n\t\t\t\t\t       p(x)=kx(x+3)(x+1)(x-2)\n\t\t\t\t       \\]\n\t\t\t\t       Then $p(1)=-8k$, and if this is to equal $8$, then $k=-1$. Therefore\n\t\t\t\t       the formula for $p(x)$ is\n\t\t\t\t       \\[\n\t\t\t\t\t       p(x)=-x(x+3)(x+1)(x-2)\n\t\t\t\t       \\]\n\t\t\t\t \\item The function $q$ has a zero at $-2$ of multiplicity $2$, and zero of\n\t\t\t\t       multiplicity $1$ at $3$ (so $3$ is a simple zero of $q$); we can therefore assume that $q$ has the form\n\t\t\t\t       \\[\n\t\t\t\t\t       q(x)=k(x+2)^2(x-3)\n\t\t\t\t       \\]\n\t\t\t\t       where $k$ is some real number. In order to find $k$, we use the given ordered pair, $(2,4)$, and\n\t\t\t\t       evaluate $p(2)$\n\t\t\t\t       \\begin{align*}\n\t\t\t\t\t       p(2) & =k(4)^2(-1) \\\\\n\t\t\t\t\t            & =-16k\n\t\t\t\t       \\end{align*}\n\t\t\t\t       We solve the equation $4=-8k$ and obtain $k=-\\frac{1}{4}$ and conclude that the\n\t\t\t\t       formula for $q(x)$ is\n\t\t\t\t       \\[\n\t\t\t\t\t       q(x)=-\\frac{1}{4}(x+2)^2(x-3)\n\t\t\t\t       \\]\n\t\t\t \\end{enumerate}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\n\t \\fixthis{Chris: need sketching polynomial problems}\n\t \\begin{pccspecialcomment}[Steps to follow when sketching polynomial functions]\n\t\t \\begin{steps}\n\t\t\t \\item \\label{poly:step:first} Determine the degree of the polynomial,\n\t\t\t its leading term and leading coefficient, and hence determine\n\t\t\t the long-run behavior of the polynomial| does it behave like $\\pm x^2$ or $\\pm x^3$\n\t\t\t as $x\\rightarrow\\pm\\infty$?\n\t\t\t \\item Determine the zeros and their multiplicity. Mark all zeros\n\t\t\t and the vertical intercept on the graph using solid circles $\\bullet$.\n\t\t\t \\item \\label{poly:step:last}  Deduce the overall shape of the curve, and sketch it. If there isn't\n\t\t\t enough information from the previous steps, then construct a table of values.\n\t\t \\end{steps}\n\t\t Remember that until we have the tools of calculus, we won't be able to\n\t\t find the exact coordinates of local minimums, local maximums, and points\n\t\t of inflection.\n\t \\end{pccspecialcomment}\n\t Before we demonstrate some examples, it is important to remember the following:\n\t \\begin{itemize}\n\t\t \\item our sketches will give a good representation of the overall\n\t\t       shape of the graph, but until we have the tools of calculus (from MTH 251)\n\t\t       we can not find local minimums, local maximums, and inflection points algebraically. This\n\t\t       means that we will make our best guess as to where these points are.\n\t\t \\item we will not concern ourselves too much with the vertical scale (because of\n\t\t       our previous point)| we will, however, mark the vertical intercept (assuming there is one),\n\t\t       and any horizontal asymptotes.\n\t \\end{itemize}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}\\label{poly:ex:simplecubic}\n\t\t Use \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $p$\n\t\t that has formula\n\t\t \\[\n\t\t\t p(x)=\\frac{1}{2}(x-4)(x-1)(x+3)\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{steps}\n\t\t\t\t \\item $p$ has degree $3$. The leading term of $p$ is $\\frac{1}{2}x^3$, so the leading coefficient of $p$\n\t\t\t\t is $\\frac{1}{2}$. The long-run behavior of $p$ is therefore similar to that of $x^3$.\n\t\t\t\t \\item The zeros of $p$ are $-3$, $1$, and $4$; each zero is simple (i.e, it has multiplicity $1$).\n\t\t\t\t This means that the curve of $p$ cuts the horizontal axis at each zero. The vertical\n\t\t\t\t intercept of $p$ is $(0,6)$.\n\t\t\t\t \\item We draw the details we have obtained so far on \\cref{poly:fig:simplecubicp1}. Given\n\t\t\t\t that the curve of $p$ looks like the curve of $x^3$ in the long-run, we are able to complete a sketch of the\n\t\t\t\t graph of $p$ in \\cref{poly:fig:simplecubicp2}.\n\n\t\t\t\t Note that we can not find the coordinates of the local minimums, local maximums, and inflection\n\t\t\t\t points| for the moment we make reasonable guesses as to where these points are (you'll find how\n\t\t\t\t to do this in calculus).\n\t\t\t \\end{steps}\n\n\t\t\t \\begin{figure}[!htbp]\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-10,ymax=15,\n\t\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(1,0)(4,0)(0,6)}node[axisnode,anchor=south west]{$(0,6)$};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:simplecubicp1}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\hfill\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-10,ymax=15,\n\t\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(1,0)(4,0)(0,6)}node[axisnode,anchor=south west]{$(0,6)$};\n\t\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-3.57675:4.95392,samples=100]{.5*(x-4)*(x-1)*(x+3)};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:simplecubicp2}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\caption{$y=\\dfrac{1}{2}(x-4)(x-1)(x+3)$}\n\t\t\t\t \\label{poly:fig:simplecubic}\n\t\t\t \\end{figure}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}\\label{poly:ex:degree5}\n\t\t Use \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $q$\n\t\t that has formula\n\t\t \\[\n\t\t\t q(x)=\\frac{1}{200}(x+7)^2(2-x)(x-6)^2\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{steps}\n\t\t\t\t \\item $q$ has degree $4$. The leading term of $q$ is\n\t\t\t\t \\[\n\t\t\t\t\t -\\frac{1}{200}x^5\n\t\t\t\t \\]\n\t\t\t\t so the leading coefficient of $q$ is $-\\frac{1}{200}$. The long-run behavior of $q$\n\t\t\t\t is therefore similar to that of $-x^5$.\n\t\t\t\t \\item The zeros of $q$ are $-7$ (multiplicity 2), $2$ (simple), and $6$ (multiplicity $2$).\n\t\t\t\t The curve of $q$ bounces off the horizontal axis at the zeros with multiplicity $2$ and\n\t\t\t\t cuts the horizontal axis at the simple zeros. The vertical intercept of $q$ is $\\left( 0,\\frac{441}{25} \\right)$.\n\t\t\t\t \\item We mark the details we have found so far on \\cref{poly:fig:degree5p1}. Given that\n\t\t\t\t the curve of $q$ looks like the curve of $-x^5$ in the long-run, we can complete \\cref{poly:fig:degree5p2}.\n\t\t\t \\end{steps}\n\n\t\t\t \\begin{figure}[!htbp]\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-10,ymax=40,\n\t\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t\t ytick={-5,0,...,35},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-7,0)(2,0)(6,0)(0,441/25)}node[axisnode,anchor=south west]{$\\left( 0, \\frac{441}{25} \\right)$};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:degree5p1}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\hfill\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-10,ymax=40,\n\t\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t\t ytick={-5,0,...,35},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-7,0)(2,0)(6,0)(0,441/25)}node[axisnode,anchor=south west]{$\\left( 0, \\frac{441}{25} \\right)$};\n\t\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-8.83223:7.34784,samples=50]{1/200*(x+7)^2*(2-x)*(x-6)^2};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:degree5p2}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\caption{$y=\\dfrac{1}{200}(x+7)^2(2-x)(x-6)^2$}\n\t\t\t\t \\label{poly:fig:degree5}\n\t\t\t \\end{figure}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}\n\t\t Use \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $r$\n\t\t that has formula\n\t\t \\[\n\t\t\t r(x)=\\frac{1}{100}x^3(x+4)(x-4)(x-6)\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{steps}\n\t\t\t\t \\item $r$ has degree $6$. The leading term of $r$ is\n\t\t\t\t \\[\n\t\t\t\t\t \\frac{1}{100}x^6\n\t\t\t\t \\]\n\t\t\t\t so the leading coefficient of $r$ is $\\frac{1}{100}$. The long-run behavior of $r$\n\t\t\t\t is therefore similar to that of $x^6$.\n\t\t\t\t \\item The zeros of $r$ are $-4$ (simple), $0$ (multiplicity $3$), $4$ (simple),\n\t\t\t\t and $6$ (simple). The vertical intercept of $r$ is $(0,0)$. The curve of $r$\n\t\t\t\t cuts the horizontal axis at the simple zeros, and goes through the axis\n\t\t\t\t at $(0,0)$, but does so in a flattened way.\n\t\t\t\t \\item We mark the zeros and vertical intercept on \\cref{poly:fig:degree6p1}. Given that\n\t\t\t\t the curve of $r$ looks like the curve of $x^6$ in the long-run, we complete the graph\n\t\t\t\t of $r$ in \\cref{poly:fig:degree6p2}.\n\t\t\t \\end{steps}\n\n\t\t\t \\begin{figure}[!htbp]\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-5,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-20,ymax=10,\n\t\t\t\t\t\t\t\t xtick={-4,-2,...,8},\n\t\t\t\t\t\t\t\t ytick={-15,-10,...,5},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-4,0)(0,0)(4,0)(6,0)};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:degree6p1}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\hfill\n\t\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t\t xmin=-5,xmax=10,\n\t\t\t\t\t\t\t\t ymin=-20,ymax=10,\n\t\t\t\t\t\t\t\t xtick={-4,-2,...,8},\n\t\t\t\t\t\t\t\t ytick={-15,-10,...,5},\n\t\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t \\addplot[soldot] coordinates{(-4,0)(0,0)(4,0)(6,0)};\n\t\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-4.16652:6.18911,samples=100]{1/100*(x+4)*x^3*(x-4)*(x-6)};\n\t\t\t\t\t\t \\end{axis}\n\t\t\t\t\t \\end{tikzpicture}\n\t\t\t\t\t \\caption{}\n\t\t\t\t\t \\label{poly:fig:degree6p2}\n\t\t\t\t \\end{subfigure}%\n\t\t\t\t \\caption{$y=\\dfrac{1}{100}(x+4)x^3(x-4)(x-6)$}\n\t\t\t \\end{figure}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[An open-topped box]\n\t\t A cardboard company makes open-topped boxes for their clients. The specifications\n\t\t dictate that the box must have a square base, and that it must be open-topped.\n\t\t The company uses sheets of cardboard that are $\\unit[1200]{cm^2}$. Assuming that\n\t\t the base of each box has side $x$ (measured in cm), it can be shown that the volume of each box, $V(x)$,\n\t\t has formula\n\t\t \\[\n\t\t\t V(x)=\\frac{x}{4}(1200-x^2)\n\t\t \\]\n\t\t Find the dimensions of the box that maximize the volume.\n\t\t \\begin{pccsolution}\n\t\t\t We graph $y=V(x)$ in \\cref{poly:fig:opentoppedbox}. Note that because\n\t\t\t $x$ represents the length of a side, and $V(x)$ represents the volume\n\t\t\t of the box, we necessarily require both values to be positive; we illustrate\n\t\t\t the part of the curve that applies to this problem using a solid line.\n\n\t\t\t \\begin{figure}[!htb]\n\t\t\t\t \\centering\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[framed,\n\t\t\t\t\t\t\t xmin=-50,xmax=50,\n\t\t\t\t\t\t\t ymin=-5000,ymax=5000,\n\t\t\t\t\t\t\t xtick={-40,-30,...,40},\n\t\t\t\t\t\t\t minor xtick={-45,-35,...,45},\n\t\t\t\t\t\t\t minor ytick={-3000,-1000,1000,3000},\n\t\t\t\t\t\t\t width=.75\\textwidth,\n\t\t\t\t\t\t\t height=.5\\textwidth,\n\t\t\t\t\t\t\t grid=both]\n\t\t\t\t\t\t \\addplot[pccplot,dashed,<-] expression[domain=-40:0,samples=50]{x/4*(1200-x^2)};\n\t\t\t\t\t\t \\addplot[pccplot,-] expression[domain=0:34.64,samples=50]{x/4*(1200-x^2)};\n\t\t\t\t\t\t \\addplot[pccplot,dashed,->] expression[domain=34.64:40,samples=50]{x/4*(1200-x^2)};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(20,4000)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{$y=V(x)$}\n\t\t\t\t \\label{poly:fig:opentoppedbox}\n\t\t\t \\end{figure}\n\n\t\t\t According to \\cref{poly:fig:opentoppedbox}, the maximum volume of such a box is\n\t\t\t approximately $\\unit[4000]{cm^2}$, and we achieve it using a base of length\n\t\t\t approximately $\\unit[20]{cm}$. Since the base is square and each sheet of cardboard\n\t\t\t is $\\unit[1200]{cm^2}$, we conclude that the dimensions of each box are $\\unit[20]{cm}\\times\\unit[20]{cm}\\times\\unit[30]{cm}$.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n \\subsection*{Complex zeros}\n\t There has been a pattern to all of the examples that we have seen so far|\n\t the degree of the polynomial has dictated the number of \\emph{real} zeros that the\n\t polynomial has. For example, the function $p$ in \\cref{poly:ex:simplecubic}\n\t has degree $3$, and $p$ has $3$ real zeros; the function $q$ in \\cref{poly:ex:degree5}\n\t has degree $5$ and $q$ has $5$ real zeros.\n\n\t You may wonder if this result can be generalized| does every polynomial that\n\t has degree $n$ have $n$ real zeros? Before we tackle the general result,\n\t let's consider an example that may help motivate it.\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{pccexample}\\label{poly:ex:complx}\n\t\t Consider the polynomial function $c$ that has formula\n\t\t \\[\n\t\t\t c(x)=x(x^2+1)\n\t\t \\]\n\t\t It is clear that $c$ has degree $3$, and that $c$ has a (simple) zero at $0$. Does\n\t\t $c$ have any other zeros, i.e, can we find any values of $x$ that satisfy the equation\n\t\t \\begin{equation}\\label{poly:eq:complx}\n\t\t\t x^2+1=0\n\t\t \\end{equation}\n\t\t The solutions to \\cref{poly:eq:complx} are $\\pm i$.\n\n\t\t We conclude that $c$ has $3$ zeros: $0$ and $\\pm i$; we note that \\emph{not\n\t\t\t all of them are real}.\n\t \\end{pccexample}\n\t \\Cref{poly:ex:complx} shows that not every degree-$3$ polynomial has $3$\n\t \\emph{real} zeros; however, if we are prepared to venture into the complex numbers,\n\t then we can state the following theorem.\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{pccspecialcomment}[The fundamental theorem of algebra]\n\t\t Every polynomial function of degree $n$ has $n$ roots, some of which may\n\t\t be complex, and some may be repeated.\n\t \\end{pccspecialcomment}\n\t \\fixthis{Fundamental theorem of algebra: is this wording ok? do we want\n\t\t it as a theorem?}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{pccexample}\n\t\t Find all the zeros of the polynomial function $p$ that has formula\n\t\t \\[\n\t\t\t p(x)=x^4-2x^3+5x^2\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t We begin by factoring $p$\n\t\t\t \\begin{align*}\n\t\t\t\t p(x) & =x^4-2x^3+5x^2 \\\\\n\t\t\t\t      & =x^2(x^2-2x+5)\n\t\t\t \\end{align*}\n\t\t\t We note that $0$ is a zero of $p$ with multiplicity $2$. The other zeros of $p$\n\t\t\t can be found by solving the equation\n\t\t\t \\[\n\t\t\t\t x^2-2x+5=0\n\t\t\t \\]\n\t\t\t This equation can not be factored, so we use the quadratic formula\n\t\t\t \\begin{align*}\n\t\t\t\t x & =\\frac{2\\pm\\sqrt{(-2)^2}-20}{2(1)} \\\\\n\t\t\t\t   & =\\frac{2\\pm\\sqrt{-16}}{2}          \\\\\n\t\t\t\t   & =1\\pm 2i\n\t\t\t \\end{align*}\n\t\t\t We conclude that $p$ has $4$ zeros: $0$ (multiplicity $2$), and $1\\pm 2i$ (simple).\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{pccexample}\n\t\t Find a polynomial that has zeros at $2\\pm i\\sqrt{2}$.\n\t\t \\begin{pccsolution}\n\t\t\t We know that the zeros of a polynomial can be found by analyzing the linear\n\t\t\t factors. We are given the zeros, and have to work backwards to find the\n\t\t\t linear factors.\n\n\t\t\t We begin by assuming that $p$ has the form\n\t\t\t \\begin{align*}\n\t\t\t\t p(x) & =(x-(2-i\\sqrt{2}))(x-(2+i\\sqrt{2}))                           \\\\\n\t\t\t\t      & =x^2-x(2+i\\sqrt{2})-x(2-i\\sqrt{2})+(2-i\\sqrt{2})(2+i\\sqrt{2}) \\\\\n\t\t\t\t      & =x^2-4x+(4-2i^2)                                              \\\\\n\t\t\t\t      & =x^2-4x+6\n\t\t\t \\end{align*}\n\t\t\t We conclude that a possible formula for a polynomial function, $p$,\n\t\t\t that has zeros at $2\\pm i\\sqrt{2}$ is\n\t\t\t \\[\n\t\t\t\t p(x)=x^2-4x+6\n\t\t\t \\]\n\t\t\t Note that we could multiply $p$ by any real number and still ensure\n\t\t\t that $p$ has the same zeros.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\t \\investigation*{}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a graph]\n\t For each of the polynomials in \\cref{poly:fig:findformula}\n\t \\begin{enumerate}\n\t\t \\item count the number of times the curve turns round, and cuts/bounces off the $x$ axis;\n\t\t \\item approximate the degree of the polynomial;\n\t\t \\item use your information to find the linear factors of each polynomial, and therefore write a possible formula for each;\n\t\t \\item make sure your polynomial goes through the given ordered pair.\n\t \\end{enumerate}\n\t \\begin{shortsolution}\n\t\t \\Vref{poly:fig:findformdeg2}:\n\t\t \\begin{enumerate}\n\t\t\t \\item the curve turns round once;\n\t\t\t \\item the degree could be 2;\n\t\t\t \\item based on the zeros, the linear factors are $(x+5)$ and $(x-3)$; since the\n\t\t\t       graph opens downwards, we will assume the leading coefficient is negative: $p(x)=-k(x+5)(x-3)$;\n\t\t\t \\item $p$ goes through $(2,2)$, so we need to solve $2=-k(7)(-1)$ and therefore $k=\\nicefrac{2}{7}$, so\n\t\t\t       \\[\n\t\t\t\t       p(x)=-\\frac{2}{7}(x+5)(x-3)\n\t\t\t       \\]\n\t\t \\end{enumerate}\n\t\t \\Vref{poly:fig:findformdeg3}:\n\t\t \\begin{enumerate}\n\t\t\t \\item the curve turns around twice;\n\t\t\t \\item the degree could be 3;\n\t\t\t \\item based on the zeros, the linear factors are $(x+2)^2$, and $(x-1)$;\n\t\t\t       based on the behavior of $p$, we assume that the leading coefficient is positive, and try $p(x)=k(x+2)^2(x-1)$;\n\t\t\t \\item $p$ goes through $(0,-2)$, so we need to solve $-2=k(4)(-1)$ and therefore $k=\\nicefrac{1}{2}$, so\n\t\t\t       \\[\n\t\t\t\t       p(x)=\\frac{1}{2}(x+2)^2(x-1)\n\t\t\t       \\]\n\t\t \\end{enumerate}\n\t\t \\Vref{poly:fig:findformdeg5}:\n\t\t \\begin{enumerate}\n\t\t\t \\item the curve turns around 4 times;\n\t\t\t \\item the degree could be 5;\n\t\t\t \\item based on the zeros, the linear factors are $(x+5)^2$, $(x+1)$, $(x-2)$, $(x-3)$;\n\t\t\t       based on the behavior of $p$, we assume that the leading coefficient is positive, and try $p(x)=k(x+5)^2(x+1)(x-2)(x-3)$;\n\t\t\t \\item $p$ goes through $(-3,-50)$, so we need to solve $-50=k(64)(-2)(-5)(-6)$ and therefore $k=\\nicefrac{5}{384}$, so\n\t\t\t       \\[\n\t\t\t\t       p(x)=\\frac{5}{384}(x+5)^2(x+1)(x-2)(x-3)\n\t\t\t       \\]\n\t\t \\end{enumerate}\n\t \\end{shortsolution}\n\t \\end{problem}\n\n\n\t \\begin{figure}[!htb]\n\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-2,ymax=5,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4.5:3.75]{-1/3*(x+4)*(x-3)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-4,0)(3,0)(2,2)} node[axisnode,above right]{$(2,2)$};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:findformdeg2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-3,xmax=2,\n\t\t\t\t\t\t ymin=-2,ymax=4,\n\t\t\t\t\t\t xtick={-2,...,1},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.95:1.75]{1/3*(x+2)^2*(x-1)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-2,0)(1,0)(0,-1.33)}node[axisnode,anchor=north west]{$(0,-2)$};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:findformdeg3}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-100,ymax=150,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4.5:3.4,samples=50]{(x+4)^2*(x+1)*(x-2)*(x-3)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-4,0)(-1,0)(2,0)(3,0)(-3,-60)}node[axisnode,anchor=north]{$(-3,-50)$};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:findformdeg5}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\label{poly:fig:findformula}\n\t \\end{figure}\n\n\n\n\n\t \\begin{exercises}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Prerequisite classifacation skills]\n\t Decide if each of the following functions are linear or quadratic.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $f(x)=2x+3$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $f$ is linear.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $g(x)=10-7x$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $g$ is linear\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $h(x)=-x^2+3x-9$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $h$ is quadratic.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $k(x)=-17$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $k$ is linear.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $l(x)=-82x^2-4$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $l$ is quadratic\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $m(x)=6^2x-8$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m$ is linear.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Prerequisite slope identification]\n\t State the slope of each of the following linear functions, and\n\t hence decide if each function is increasing or decreasing.\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $\\alpha(x)=4x+1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m=4$; $\\alpha$ is increasing.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\beta(x)=-9x$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m=-9$; $\\beta$ is decreasing.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\gamma(t)=18t+100$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m=18$; $\\gamma$ is increasing.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\delta(y)=23-y$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m=-1$; $\\delta$ is decreasing.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t Now let's generalize our findings for the most general linear function $f$\n\t that has formula $f(x)=mx+b$. Complete the following sentences.\n\t \\begin{subproblem}\n\t\t When $m>0$, the function $f$ is $\\ldots$\n\t\t \\begin{shortsolution}\n\t\t\t When $m>0$, the function $f$ is $\\ldots$  \\emph{increasing}.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t When $m<0$, the function $f$ is $\\ldots$\n\t\t \\begin{shortsolution}\n\t\t\t When $m<0$, the function $f$ is $\\ldots$  \\emph{decreasing}.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Polynomial or not?]\n\t Identify whether each of the following functions is a polynomial or not.\n\t If the function is a polynomial, state its degree.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=2x+1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial (you might also describe $p$ as linear). The degree of $p$ is 1.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=7x^2+4x$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial (you might also describe $p$ as quadratic). The degree of $p$ is 2.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=\\sqrt{x}+2x+1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is not a polynomial; we require the powers of $x$ to be integer values.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=2^x-45$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is not a polynomial; the $2^x$ term is exponential.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=6x^4-5x^3+9$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial, and the degree of $p$ is $6$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=-5x^{17}+9x+2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial, and the degree of $p$ is 17.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=4x(x+7)^2(x-3)^3$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial, and the degree of $p$ is $6$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=4x^{-5}-x^2+x$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is not a polynomial because $-5$ is not a positive integer.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=-x^6(x^2+1)(x^3-2)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p$ is a polynomial, and the degree of $p$ is $11$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Polynomial graphs]\n\t Three polynomial functions $p$, $m$, and $n$ are shown in \\crefrange{poly:fig:functionp}{poly:fig:functionn}.\n\t The functions have the following formulas\n\t \\begin{align*}\n\t\t p(x) & = (x-1)(x+2)(x-3)           \\\\\n\t\t m(x) & = -(x-1)(x+2)(x-3)          \\\\\n\t\t n(x) & = (x-1)(x+2)(x-3)(x+1)(x+4)\n\t \\end{align*}\n\t Note that for our present purposes we are not concerned with the vertical scale of the graphs.\n\t \\begin{subproblem}\n\t\t Identify both on the graph {\\em and} algebraically, the zeros of each polynomial.\n\t\t \\begin{shortsolution}\n\t\t\t $y=p(x)$ is shown below.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.5:3.5,samples=50]{(x-1)*(x+2)*(x-3)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-2,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $y=m(x)$ is shown below.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.5:3.5,samples=50]{-1*(x-1)*(x+2)*(x-3)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-2,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t $y=n(x)$ is shown below.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-90,ymax=70,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4.15:3.15,samples=50]{(x-1)*(x+2)*(x-3)*(x+1)*(x+4)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-4,0)(-2,0)(-1,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\n\t\t\t The zeros of $p$ are $-2$, $1$, and $3$; the zeros of $m$ are $-2$, $1$, and $3$; the zeros of $n$ are\n\t\t\t $-4$, $-2$, $-1$, and $3$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Write down the degree, how many times the curve of each function `turns around',\n\t\t and how many zeros it has\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item The degree of $p$ is 3, and the curve $y=p(x)$ turns around twice.\n\t\t\t\t \\item The degree of $q$ is also 3, and the curve $y=q(x)$ turns around twice.\n\t\t\t\t \\item The degree of $n$ is $5$, and the curve $y=n(x)$ turns around 4 times.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t \\begin{figure}[!htb]\n\t\t \\begin{widepage}\n\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.5:3.5,samples=50]{(x-1)*(x+2)*(x-3)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-2,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=p(x)$}\n\t\t\t \\label{poly:fig:functionp}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-2.5:3.5,samples=50]{-1*(x-1)*(x+2)*(x-3)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-2,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=m(x)$}\n\t\t\t \\label{poly:fig:functionm}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-90,ymax=70,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4.15:3.15,samples=100]{(x-1)*(x+2)*(x-3)*(x+1)*(x+4)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-4,0)(-2,0)(-1,0)(1,0)(3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=n(x)$}\n\t\t\t \\label{poly:fig:functionn}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\end{widepage}\n\t \\end{figure}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Horizontal intercepts]\\label{poly:prob:matchpolys}%\n\t State the horizontal intercepts (as ordered pairs) of the following polynomials.\n\t \\begin{multicols}{2}\n\t\t \\begin{subproblem}\\label{poly:prob:degree5}\n\t\t\t $p(x)=(x-1)(x+2)(x-3)(x+1)(x+4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $(-4,0)$, $(-2,0)$, $(-1,0)$, $(1,0)$, $(3,0)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $q(x)=-(x-1)(x+2)(x-3)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $(-2,0)$, $(1,0)$, $(3,0)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(x)=(x-1)(x+2)(x-3)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $(-2,0)$, $(1,0)$, $(3,0)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\\label{poly:prob:degree2}\n\t\t\t $s(x)=(x-2)(x+2)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $(-2,0)$, $(2,0)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Minimums, maximums, and concavity]\\label{poly:prob:incdec}\n\t Four polynomial functions are graphed in \\cref{poly:fig:incdec}. The formulas\n\t for these functions are (not respectively)\n\t \\begin{gather*}\n\t\t p(x)=\\frac{x^3}{6}-\\frac{x^2}{4}-3x, \\qquad q(x)=\\frac{x^4}{20}+\\frac{x^3}{15}-\\frac{6}{5}x^2+1\\\\\n\t\t r(x)=-\\frac{x^5}{50}-\\frac{x^4}{40}+\\frac{2x^3}{5}+6, \\qquad s(x)=-\\frac{x^6}{6000}-\\frac{x^5}{2500}+\\frac{67x^4}{4000}+\\frac{17x^3}{750}-\\frac{42x^2}{125}\n\t \\end{gather*}\n\t \\begin{figure}[!htb]\n\t\t \\begin{widepage}\n\t\t \\setlength{\\figurewidth}{.23\\textwidth}\n\t\t \\centering\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t grid=major,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-5.28:4.68,samples=50]{-x^5/50-x^4/40+2*x^3/5+6};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:incdec3}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xmin=-10,xmax=10,ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t grid=major,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-6.08:4.967,samples=50]{x^4/20+x^3/15-6/5*x^2+1};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:incdec2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xmin=-6,xmax=8,ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-4,-2,...,6},\n\t\t\t\t\t\t ytick={-8,-4,4,8},\n\t\t\t\t\t\t minor ytick={-6,-2,...,6},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-4.818:6.081,samples=50]{x^3/6-x^2/4-3*x};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:incdec1}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t xmin=-10,xmax=10,ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-4,4,8},\n\t\t\t\t\t\t ytick={-8,-4,4,8},\n\t\t\t\t\t\t minor xtick={-6,-2,...,6},\n\t\t\t\t\t\t minor ytick={-6,-2,...,6},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-9.77:8.866,samples=50]{-x^6/6000-x^5/2500+67*x^4/4000+17/750*x^3-42/125*x^2};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:incdec4}\n\t\t \\end{subfigure}\n\t\t \\caption{Graphs for \\cref{poly:prob:incdec}.}\n\t\t \\label{poly:fig:incdec}\n\t\t \\end{widepage}\n\t \\end{figure}\n\t \\begin{subproblem}\n\t\t Match each of the formulas with one of the given graphs.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ is graphed in \\vref{poly:fig:incdec1};\n\t\t\t\t \\item $q$ is graphed in \\vref{poly:fig:incdec2};\n\t\t\t\t \\item $r$ is graphed in \\vref{poly:fig:incdec3};\n\t\t\t\t \\item $s$ is graphed in \\vref{poly:fig:incdec4}.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Approximate the zeros of each function using the appropriate graph.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ has simple zeros at about $-3.8$, $0$, and $5$.\n\t\t\t\t \\item $q$ has simple zeros at about $-5.9$, $-1$, $1$, and $4$.\n\t\t\t\t \\item $r$ has simple zeros at about $-5$, $-2.9$, and $4.1$.\n\t\t\t\t \\item $s$ has simple zeros at about $-9$, $-6$, $4.2$, $8.1$, and a zero of multiplicity $2$ at $0$.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Approximate the local maximums and minimums of each of the functions.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ has a local maximum of approximately $3.9$ at $-2$, and a local minimum of approximately $-6.5$ at $3$.\n\t\t\t\t \\item $q$ has a local minimum of approximately $-10$ at $-4$, and $-4$ at $3$; $q$ has a local maximum of approximately $1$ at $0$.\n\t\t\t\t \\item $r$ has a local minimum of approximately $-5.5$ at $-4$, and a local maximum of approximately $10$ at $3$.\n\t\t\t\t \\item $s$ has a local maximum of approximately $5$ at $-8$, $0$ at $0$, and $5$ at  $7$; $s$ has local minimums\n\t\t\t\t       of approximately $-3$ at $-4$, and $-1$ at $3$.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Approximate the global maximums and minimums of each of the functions.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ does not have a global maximum, nor a global minimum.\n\t\t\t\t \\item $q$ has a global minimum of approximately $-10$; it does not have a global maximum.\n\t\t\t\t \\item $r$ does not have a global maximum, nor a global minimum.\n\t\t\t\t \\item $s$ has a global maximum of approximately $5$; it does not have a global minimum.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Approximate the intervals on which each function is increasing and decreasing.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ is increasing on $(-\\infty,-2)\\cup (3,\\infty)$, and decreasing on $(-2,3)$.\n\t\t\t\t \\item $q$ is increasing on $(-4,0)\\cup (3,\\infty)$, and decreasing on $(-\\infty,-4)\\cup (0,3)$.\n\t\t\t\t \\item $r$ is increasing on $(-4,3)$, and decreasing on $(-\\infty,-4)\\cup (3,\\infty)$.\n\t\t\t\t \\item $s$ is increasing on $(-\\infty,-8)\\cup (-4,0)\\cup (3,5)$, and decreasing on $(-8,-4)\\cup (0,3)\\cup (5,\\infty)$.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Approximate the intervals on which each function is concave up and concave down.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{itemize}\n\t\t\t\t \\item $p$ is concave up on  $(1,\\infty)$, and concave down on  $(-\\infty,1)$.\n\t\t\t\t \\item $q$ is concave up on $(-\\infty,-1)\\cup (1,\\infty)$, and concave down on $(-1,1)$.\n\t\t\t\t \\item $r$ is concave up on $(-\\infty,-3)\\cup (0,2)$, and concave down on $(-3,0)\\cup (2,\\infty)$.\n\t\t\t\t \\item $s$ is concave up on $(-6,-2)\\cup (2,5)$, and concave down on $(-\\infty,-6)\\cup (-2,2)\\cup (5,\\infty)$.\n\t\t\t \\end{itemize}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t The degree of $q$ is $5$. Assuming that all of the real zeros of $q$ are\n\t\t shown in its graph, how many complex zeros does $q$ have?\n\t\t \\begin{shortsolution}\n\t\t\t \\Vref{poly:fig:incdec2} shows that $q$ has $3$ real zeros\n\t\t\t since the curve of $q$ cuts the horizontal axis $3$ times.\n\t\t\t Since $q$ has degree $5$, $q$ must have $2$ complex zeros.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Long-run behaviour of polynomials]\n\t Describe the long-run behavior of each of polynomial functions in\n\t \\crefrange{poly:prob:degree5}{poly:prob:degree2}.\n\t \\begin{shortsolution}\n\t\t $\\dd\\lim_{x\\rightarrow-\\infty}p(x)=-\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow\\infty}p(x)=\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow-\\infty}q(x)=\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow\\infty}q(x)=-\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow-\\infty}r(x)=-\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow\\infty}r(x)=\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow-\\infty}s(x)=\\infty$,\n\t\t $\\dd\\lim_{x\\rightarrow\\infty}s(x)=\\infty$,\n\t \\end{shortsolution}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[True of false?]\n\t Let $p$ be a polynomial function.\n\t Label each of the following statements as true (T) or false (F); if they are false,\n\t provide an example that supports your answer.\n\t \\begin{subproblem}\n\t\t If $p$ has degree $3$, then $p$ has $3$ distinct zeros.\n\t\t \\begin{shortsolution}\n\t\t\t False. Consider $p(x)=x^2(x+1)$ which has only 2 distinct zeros.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t If $p$ has degree $4$, then $\\dd\\lim_{x\\rightarrow-\\infty}p(x)=\\infty$ and $\\dd\\lim_{x\\rightarrow\\infty}p(x)=\\infty$.\n\t\t \\begin{shortsolution}\n\t\t\t False. Consider $p(x)=-x^4$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t If $p$ has even degree, then it is possible that $p$ can have no real zeros.\n\t\t \\begin{shortsolution}\n\t\t\t True.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t If $p$ has odd degree, then it is possible that $p$ can have no real zeros.\n\t\t \\begin{shortsolution}\n\t\t\t False. All odd degree polynomials will cut the horizontal axis at least once.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a description]\n\t In each of the following problems, give a possible formula for a polynomial\n\t function that has the specified properties.\n\t \\begin{subproblem}\n\t\t Degree 2 and has zeros at $4$ and $5$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $p(x)=(x-4)(x-5)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Degree 3 and has zeros at $4$,$5$ and $-3$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $p(x)=(x-4)(x-5)(x+3)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Degree 4 and has zeros at $0$, $4$, $5$, $-3$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $p(x)=x(x-4)(x-5)(x+3)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Degree 4, with zeros that make the graph cut at $2$, $-5$, and a zero that makes the graph touch at $-2$;\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $p(x)=(x-2)(x+5)(x+2)^2$. Note we could multiply $p$ by any real number, and still meet the requirements.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Degree 3, with only one zero at $-1$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $p(x)=(x+1)^3$. Note we could multiply $p$ by any real number, and still meet the requirements.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{problem}[\\Cref{poly:step:last}]\n\t \\pccname{Saheed} is graphing a polynomial function, $p$.\n\t He is following \\crefrange{poly:step:first}{poly:step:last} and has so far\n\t marked the zeros of $p$ on \\cref{poly:fig:optionsp1}. Saheed tells you that\n\t $p$ has degree $3$, but does \\emph{not} say if the leading coefficient\n\t of $p$ is positive or negative.\n\t \\begin{figure}[!htbp]\n\t\t \\begin{widepage}\n\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t height=.5\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:optionsp1}\n\t\t \\end{subfigure}%\n\t\t \\hfill\n\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t height=.5\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{poly:fig:optionsp2}\n\t\t \\end{subfigure}%\n\t\t \\caption{}\n\t\t \\end{widepage}\n\t \\end{figure}\n\t \\begin{subproblem}\n\t\t Use the information in \\cref{poly:fig:optionsp1} to help sketch $p$, assuming that the leading coefficient\n\t\t is positive.\n\t\t \\begin{shortsolution}\n\t\t\t Assuming that $a_3>0$:\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-6.78179:8.35598,samples=50]{1/20*(x+5)*(x-2)*(x-6)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Use the information in \\cref{poly:fig:optionsp1} to help sketch $p$, assuming that the leading coefficient\n\t\t is negative.\n\t\t \\begin{shortsolution}\n\t\t\t Assuming that $a_3<0$:\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-6.78179:8.35598,samples=50]{-1/20*(x+5)*(x-2)*(x-6)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t Saheed now turns his attention to another polynomial function, $q$. He finds\n\t the zeros of $q$ (there are only $2$) and marks them on \\cref{poly:fig:optionsp2}.\n\t Saheed knows that $q$ has degree $3$, but doesn't know if the leading\n\t coefficient is positive or negative.\n\t \\begin{subproblem}\n\t\t Use the information in \\cref{poly:fig:optionsp2} to help sketch $q$, assuming that the leading\n\t\t coefficient of $q$ is positive. Hint: only one of the zeros is simple.\n\t\t \\begin{shortsolution}\n\t\t\t Assuming that $a_4>0$ there are $2$ different options:\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-8.68983:7.31809,samples=50]{1/20*(x+5)^2*(x-6)};\n\t\t\t\t\t \\addplot expression[domain=-6.31809:9.68893,samples=50]{1/20*(x+5)*(x-6)^2};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Use the information in \\cref{poly:fig:optionsp2} to help sketch $q$, assuming that the leading\n\t\t coefficient of $q$ is negative.\n\t\t \\begin{shortsolution}\n\t\t\t Assuming that $a_4<0$ there are $2$ different options:\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-15},\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-8.68983:7.31809,samples=50]{-1/20*(x+5)^2*(x-6)};\n\t\t\t\t\t \\addplot expression[domain=-6.31809:9.68893,samples=50]{-1/20*(x+5)*(x-6)^2};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-5,0)(6,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{problem}[Zeros]\n\t Find all zeros of each of the following polynomial functions, making\n\t sure to detail their multiplicity. Note that\n\t you may need to use factoring, or the quadratic formula, or both! Also note\n\t that some zeros may be repeated, and some may be complex.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=x^2+1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\pm i$ (simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $q(y)=(y^2-9)(y^2-7)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\pm 3$, $\\pm \\sqrt{7}$ (all are simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(z)=-4z^3(z^2+3)(z^2+64)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $0$ (multiplicity $3$), $\\pm\\sqrt{3}$ (simple), $\\pm\\sqrt{8}$ (simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $a(x)=x^4-81$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\pm 3$, $\\pm 3i$ (all are simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $b(y)=y^3-8$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $2$, $-1\\pm i\\sqrt{3}$ (all are simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $c(m)=m^3-m^2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $0$ (multiplicity $2$), $1$ (simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $h(n)=(n+1)(n^2+4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-1$, $\\pm 2i$ (all are simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $f(\\alpha)=(\\alpha^2-16)(\\alpha^2-5\\alpha+4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-4$ (simple), $4$ (multiplicity $2$), $1$ (simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $g(\\beta)=(\\beta^2-25)(\\beta^2-5\\beta-4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\pm 5$, $\\dfrac{5\\pm\\sqrt{41}}{2}$ (all are simple).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{problem}[Given zeros, find a formula]\n\t In each of the following problems you are given the zeros of a polynomial.\n\t Write a possible formula for each polynomial| you may leave your\n\t answer in factored form, but it may not contain complex numbers. Unless\n\t otherwise stated, assume that the zeros are simple.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $1$, $2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)=(x-1)(x-2)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $0$, $5$, $13$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)=x(x-5)(x-13)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $-7$, $2$ (multiplicity $3$), $5$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)=(x+7)(x-2)^3(x-5)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $0$, $\\pm i$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)=x(x^2+1)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\pm 2i$, $\\pm 7$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)=(x^2+4)(x^2-49)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $-2\\pm i\\sqrt{6}$\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{problem}[Composition of polynomials]\n\t Let $p$ and $q$ be polynomial functions that have formulas\n\t \\[\n\t\t p(x)=(x+1)(x+2)(x+5), \\qquad q(x)=3-x^4\n\t \\]\n\t Evaluate each of the following.\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $(p\\circ q)(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $160$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(q\\circ p)(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-9997$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(p\\circ q)(1)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $84$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(p\\circ p)(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $1980$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   June 2012\n\t %===================================\n\t \\begin{problem}[Piecewise polynomial functions]\n\t Let $P$ be the piecewise-defined function with formula\n\t \\[\n\t\t P(x)=\\begin{cases}\n\t\t\t (1-x)(2x+5)(x^2+1), & x\\leq -3 \\\\\n\t\t\t 4-x^2,              & -3<x < 4 \\\\\n\t\t\t x^3                 & x\\geq 4\n\t\t \\end{cases}\n\t \\]\n\t Evaluate each of the following\n\t \\begin{multicols}{5}\n\t\t \\begin{subproblem}\n\t\t\t $P(-4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-255$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $P(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $4$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $P(4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $64$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $P(-3)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-40$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(P\\circ P)(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $64$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   July 2012\n\t %===================================\n\t \\begin{problem}[Function algebra]\n\t Let $p$ and $q$ be the polynomial functions that have formulas\n\t \\[\n\t\t p(x)=x(x+1)(x-3)^2, \\qquad q(x)=7-x^2\n\t \\]\n\t Evaluate each of the following (if possible).\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $(p+q)(1)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $14$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(p-q)(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $7$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(p\\cdot q)(\\sqrt{7})$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $0$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\left( \\frac{q}{p} \\right)(1)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\frac{3}{4}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\begin{subproblem}\n\t\t What is the domain of the function $\\frac{q}{p}$?\n\t\t \\begin{shortsolution}\n\t\t\t $(-\\infty,-1)\\cup (-1,0)\\cup (0,3)\\cup (3,\\infty)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   July 2012\n\t %===================================\n\t \\begin{problem}[Transformations: given the transformation, find the formula]\n\t Let $p$ be the polynomial function that has formula.\n\t \\[\n\t\t p(x)=4x(x^2-1)(x+3)\n\t \\]\n\t In each of the following\n\t problems apply the given transformation to the function $p$ and\n\t write a formula for the transformed version of $p$.\n\t \\begin{multicols}{2}\n\t\t \\begin{subproblem}\n\t\t\t Shift $p$ to the right by $5$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x-5)=4(x-5)(x-2)(x^2-10x+24)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $p$ to the left by $6$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x+6)=4(x+6)(x+9)(x^2+12x+35)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $p$ up by $12$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)+12=4x(x^2-1)(x+3)+12$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $p$ down by $2$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(x)-2=4x(x^2-1)(x+3)-2$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Reflect $p$ over the horizontal axis.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-p(x)=-4x(x^2-1)(x+3)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Reflect $p$ over the vertical axis.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $p(-x)=-4x(x^2-1)(3-x)$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a table]\\label{poly:prob:findformula}\n\t \\Crefrange{poly:tab:findformulap}{poly:tab:findformulas} show values of polynomial functions, $p$, $q$,\n\t $r$, and $s$.\n\n\t \\begin{table}[!htb]\n\t\t \\centering\n\t\t \\begin{widepage}\n\t\t \\caption{Tables for \\cref{poly:prob:findformula}}\n\t\t \\label{poly:tab:findformula}\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=p(x)$}\n\t\t\t \\label{poly:tab:findformulap}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\\n\t\t\t\t \\afterheading\n\t\t\t\t $-4$          & $-56$         \\\\\\normalline\n\t\t\t\t $-3$          & $-18$         \\\\\\normalline\n\t\t\t\t $-2$          & $0$           \\\\\\normalline\n\t\t\t\t $-1$          & $4$           \\\\\\normalline\n\t\t\t\t $0$           & $0$           \\\\\\normalline\n\t\t\t\t $1$           & $-6$          \\\\\\normalline\n\t\t\t\t $2$           & $-8$          \\\\\\normalline\n\t\t\t\t $3$           & $0$           \\\\\\normalline\n\t\t\t\t $4$           & $24$          \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=q(x)$}\n\t\t\t \\label{poly:tab:findformulaq}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\ \\afterheading\n\t\t\t\t $-4$          & $-16$         \\\\\\normalline\n\t\t\t\t $-3$          & $-3$          \\\\\\normalline\n\t\t\t\t $-2$          & $0$           \\\\\\normalline\n\t\t\t\t $-1$          & $-1$          \\\\\\normalline\n\t\t\t\t $0$           & $0$           \\\\\\normalline\n\t\t\t\t $1$           & $9$           \\\\\\normalline\n\t\t\t\t $2$           & $32$          \\\\\\normalline\n\t\t\t\t $3$           & $75$          \\\\\\normalline\n\t\t\t\t $4$           & $144$         \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=r(x)$}\n\t\t\t \\label{poly:tab:findformular}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\ \\afterheading\n\t\t\t\t $-4$          & $105$         \\\\\\normalline\n\t\t\t\t $-3$          & $0$           \\\\\\normalline\n\t\t\t\t $-2$          & $-15$         \\\\\\normalline\n\t\t\t\t $-1$          & $0$           \\\\\\normalline\n\t\t\t\t $0$           & $9$           \\\\\\normalline\n\t\t\t\t $1$           & $0$           \\\\\\normalline\n\t\t\t\t $2$           & $-15$         \\\\\\normalline\n\t\t\t\t $3$           & $0$           \\\\\\normalline\n\t\t\t\t $4$           & $105$         \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=s(x)$}\n\t\t\t \\label{poly:tab:findformulas}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\ \\afterheading\n\t\t\t\t $-4$          & $75$          \\\\\\normalline\n\t\t\t\t $-3$          & $0$           \\\\\\normalline\n\t\t\t\t $-2$          & $-9$          \\\\\\normalline\n\t\t\t\t $-1$          & $0$           \\\\\\normalline\n\t\t\t\t $0$           & $3$           \\\\\\normalline\n\t\t\t\t $1$           & $0$           \\\\\\normalline\n\t\t\t\t $2$           & $15$          \\\\\\normalline\n\t\t\t\t $3$           & $96$          \\\\\\normalline\n\t\t\t\t $4$           & $760$         \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\end{widepage}\n\t \\end{table}\n\n\t \\begin{subproblem}\n\t\t Assuming that all of the zeros of $p$ are shown (in \\cref{poly:tab:findformulap}), how many zeros does $p$ have?\n\t\t \\begin{shortsolution}\n\t\t\t $p$ has 3 zeros.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t What is the degree of $p$?\n\t\t \\begin{shortsolution}\n\t\t\t $p$ is degree 3.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Write a formula for $p(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $p(x)=x(x+2)(x-3)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Assuming that all of the zeros of $q$ are shown (in \\cref{poly:tab:findformulaq}), how many zeros does $q$ have?\n\t\t \\begin{shortsolution}\n\t\t\t $q$ has 2 zeros.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Describe the difference in behavior of $p$ and $q$ at $-2$.\n\t\t \\begin{shortsolution}\n\t\t\t $p$ changes sign at $-2$, and $q$ does not change sign at $-2$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Given that $q$ is a degree-$3$ polynomial, write a formula for $q(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $q(x)=x(x+2)^2$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Assuming that all of the zeros of $r$ are shown (in \\cref{poly:tab:findformular}), find a formula for $r(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $r(x)=(x+3)(x+1)(x-1)(x-3)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Assuming that all of the zeros of $s$ are shown (in \\cref{poly:tab:findformulas}), find a formula for $s(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $s(x)=(x+3)(x+1)(x-1)^2$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t \\end{exercises}\n\n\\section{Rational functions}\n \\subsection*{Power functions with negative exponents}\n\t The study of rational functions will rely upon a good knowledge\n\t of power functions with negative exponents. \\Cref{rat:ex:oddpow,rat:ex:evenpow} are\n\t simple but fundamental to understanding the behavior of rational functions.\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Power functions with odd negative exponents]\\label{rat:ex:oddpow}\n\t\t Graph each of the following functions on your calculator, state their domain in interval notation, and their\n\t\t behavior as $x\\rightarrow 0^-$ and $x\\rightarrow 0^+$.\n\t\t \\[\n\t\t\t f(x)=\\frac{1}{x},\\qquad g(x)=\\dfrac{1}{x^3},\\qquad h(x)=\\dfrac{1}{x^5}\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t The functions $f$, $g$, and $k$ are plotted in \\cref{rat:fig:oddpow}.\n\t\t\t The domain of each of the functions $f$, $g$, and $h$ is $(-\\infty,0)\\cup (0,\\infty)$. Note that\n\t\t\t the long-run behavior of each of the functions is the same, and in particular\n\t\t\t \\begin{align*}\n\t\t\t\t f(x)\\rightarrow 0                         & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t \\mathllap{\\text{and }}  f(x)\\rightarrow 0 & \\text{ as } x\\rightarrow-\\infty\n\t\t\t \\end{align*}\n\t\t\t The same results hold for $g$ and $h$. Note also that each of the functions\n\t\t\t has a \\emph{vertical asymptote} at $0$. We see that\n\t\t\t \\begin{align*}\n\t\t\t\t f(x)\\rightarrow -\\infty                         & \\text{ as } x\\rightarrow 0^- \\\\\n\t\t\t\t \\mathllap{\\text{and }}   f(x)\\rightarrow \\infty & \\text{ as } x\\rightarrow 0^+\n\t\t\t \\end{align*}\n\t\t\t The same results hold for $g$ and $h$.\n\n\t\t\t The curve of a function that has a vertical asymptote is necessarily separated\n\t\t\t into \\emph{branches}| each of the functions $f$, $g$, and $h$ have $2$ branches.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t \\begin{figure}[!htb]\n\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-3,xmax=3,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t xtick={-2,-1,...,2},\n\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t legend pos=north west,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-3:-0.2]{1/x};\n\t\t\t\t\t \\addplot expression[domain=-3:-0.584]{1/x^3};\n\t\t\t\t\t \\addplot expression[domain=-3:-0.724]{1/x^5};\n\t\t\t\t\t \\addplot expression[domain=0.2:3]{1/x};\n\t\t\t\t\t \\addplot expression[domain=0.584:3]{1/x^3};\n\t\t\t\t\t \\addplot expression[domain=0.724:3]{1/x^5};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-1,-1)}node[axisnode,anchor=north east]{$(-1,-1)$};\n\t\t\t\t\t \\addplot[soldot]coordinates{(1,1)}node[axisnode,anchor=south west]{$(1,1)$};\n\t\t\t\t\t \\legend{$f$,$g$,$h$}\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:oddpow}\n\t\t \\end{minipage}%\n\t\t \\hfill\n\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-3,xmax=3,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t xtick={-2,-1,...,2},\n\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t legend pos=south east,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot expression[domain=-3:-0.447]{1/x^2};\n\t\t\t\t\t \\addplot expression[domain=-3:-0.668]{1/x^4};\n\t\t\t\t\t \\addplot expression[domain=-3:-0.764]{1/x^6};\n\t\t\t\t\t \\addplot expression[domain=0.447:3]{1/x^2};\n\t\t\t\t\t \\addplot expression[domain=0.668:3]{1/x^4};\n\t\t\t\t\t \\addplot expression[domain=0.764:3]{1/x^6};\n\t\t\t\t\t \\addplot[soldot]coordinates{(-1,1)}node[axisnode,anchor=south east]{$(-1,1)$};\n\t\t\t\t\t \\addplot[soldot]coordinates{(1,1)}node[axisnode,anchor=south west]{$(1,1)$};\n\t\t\t\t\t \\legend{$F$,$G$,$H$}\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:evenpow}\n\t\t \\end{minipage}%\n\t \\end{figure}\n\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Power functions with even negative exponents]\\label{rat:ex:evenpow}%\n\t\t Graph each of the following functions, state their domain, and their\n\t\t behavior as $x\\rightarrow 0^-$ and $x\\rightarrow 0^+$.\n\t\t \\[\n\t\t\t f(x)=\\frac{1}{x^2},\\qquad g(x)=\\frac{1}{x^4},\\qquad h(x)=\\frac{1}{x^6}\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t The functions $F$, $G$, and $H$ are plotted in \\cref{rat:fig:evenpow}.\n\t\t\t The domain of each of the functions $F$, $G$, and $H$ is $(-\\infty,0)\\cup (0,\\infty)$. Note that\n\t\t\t the long-run behavior of each of the functions is the same, and in particular\n\t\t\t \\begin{align*}\n\t\t\t\t F(x)\\rightarrow 0                           & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t \\mathllap{\\text{and }}    f(x)\\rightarrow 0 & \\text{ as } x\\rightarrow-\\infty\n\t\t\t \\end{align*}\n\t\t\t As in \\cref{rat:ex:oddpow}, $F$ has a horizontal asymptote  that\n\t\t\t has equation $y=0$.\n\t\t\t The same results hold for $G$ and $H$. Note also that each of the functions\n\t\t\t has a \\emph{vertical asymptote} at $0$. We see that\n\t\t\t \\begin{align*}\n\t\t\t\t F(x)\\rightarrow \\infty                          & \\text{ as } x\\rightarrow 0^- \\\\\n\t\t\t\t \\mathllap{\\text{and }}   F(x)\\rightarrow \\infty & \\text{ as } x\\rightarrow 0^+\n\t\t\t \\end{align*}\n\t\t\t The same results hold for $G$ and $H$. Each of the functions $F$, $G$, and $H$\n\t\t\t have $2$ branches.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{doyouunderstand}\n\t\t \\begin{problem}\n\t\t Repeat \\cref{rat:ex:oddpow,rat:ex:evenpow} using (respectively)\n\t\t \\begin{subproblem}\n\t\t\t $k(x)=-\\dfrac{1}{x}$, $ m(x)=-\\dfrac{1}{x^3}$, $ n(x)=-\\dfrac{1}{x^5}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t The functions $k$, $m$, and $n$ have domain $(-\\infty,0)\\cup (0,\\infty)$, and\n\t\t\t\t are graphed below.\n\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-3,xmax=3,\n\t\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t\t xtick={-2,-1,...,2},\n\t\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t\t legend pos=north east,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.2]{-1/x};\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.584]{-1/x^3};\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.724]{-1/x^5};\n\t\t\t\t\t\t \\addplot expression[domain=0.2:3]{-1/x};\n\t\t\t\t\t\t \\addplot expression[domain=0.584:3]{-1/x^3};\n\t\t\t\t\t\t \\addplot expression[domain=0.724:3]{-1/x^5};\n\t\t\t\t\t\t \\legend{$k$,$m$,$n$}\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\n\t\t\t\t Note that\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t k(x)\\rightarrow 0                                & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}    k(x)\\rightarrow 0      & \\text{ as } x\\rightarrow-\\infty \\\\\n\t\t\t\t\t \\intertext{and also}\n\t\t\t\t\t k(x)\\rightarrow \\infty                           & \\text{ as } x\\rightarrow 0^-    \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}   k(x)\\rightarrow -\\infty & \\text{ as } x\\rightarrow 0^+\n\t\t\t\t \\end{align*}\n\t\t\t\t The same are true for $m$ and $n$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $ K(x)=-\\dfrac{1}{x^2}$, $ M(x)=-\\dfrac{1}{x^4}$, $ N(x)=-\\dfrac{1}{x^6}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t The functions $K$, $M$, and $N$ have domain $(-\\infty,0)\\cup (0,\\infty)$, and\n\t\t\t\t are graphed below.\n\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-3,xmax=3,\n\t\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t\t xtick={-2,-1,...,2},\n\t\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t\t\t legend pos=north east,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.447]{-1/x^2};\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.668]{-1/x^4};\n\t\t\t\t\t\t \\addplot expression[domain=-3:-0.764]{-1/x^6};\n\t\t\t\t\t\t \\addplot expression[domain=0.447:3]{-1/x^2};\n\t\t\t\t\t\t \\addplot expression[domain=0.668:3]{-1/x^4};\n\t\t\t\t\t\t \\addplot expression[domain=0.764:3]{-1/x^6};\n\t\t\t\t\t\t \\legend{$K$,$M$,$N$}\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\n\t\t\t\t Note that\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t K(x)\\rightarrow 0                                & \\text{ as } x\\rightarrow\\infty  \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}    K(x)\\rightarrow 0      & \\text{ as } x\\rightarrow-\\infty \\\\\n\t\t\t\t\t \\intertext{and also}\n\t\t\t\t\t K(x)\\rightarrow -\\infty                          & \\text{ as } x\\rightarrow 0^-    \\\\\n\t\t\t\t\t \\mathllap{\\text{and }}   K(x)\\rightarrow -\\infty & \\text{ as } x\\rightarrow 0^+\n\t\t\t\t \\end{align*}\n\t\t\t\t The same are true for $M$ and $N$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\end{problem}\n\t \\end{doyouunderstand}\n\n \\subsection*{Rational functions}\n\t \\begin{pccdefinition}[Rational functions]\\label{rat:def:function}\n\t\t Rational functions have the form\n\t\t \\[\n\t\t\t r(x) = \\frac{p(x)}{q(x)}\n\t\t \\]\n\t\t where both $p$ and $q$ are polynomials.\n\n\t\t Note that\n\t\t \\begin{itemize}\n\t\t\t \\item the domain or $r$ will be all real numbers, except those that\n\t\t\t       make the \\emph{denominator}, $q(x)$, equal to $0$;\n\t\t\t \\item the zeros of $r$ are the zeros of $p$, i.e the real numbers\n\t\t\t       that make the \\emph{numerator}, $p(x)$, equal to $0$.\n\t\t \\end{itemize}\n\n\t\t \\Cref{rat:ex:oddpow,rat:ex:evenpow} are particularly important because $r$\n\t\t will behave like $\\frac{1}{x}$, or $\\frac{1}{x^2}$ around its vertical asymptotes,\n\t\t depending on the power that the relevant term is raised to| we will demonstrate\n\t\t this in what follows.\n\t \\end{pccdefinition}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Rational or not]\n\t\t Identify whether each of the following functions is a rational or not. If\n\t\t the function is rational, state the domain.\n\t\t \\begin{multicols}{3}\n\t\t\t \\begin{enumerate}\n\t\t\t\t \\item $r(x)=\\dfrac{1}{x}$\n\t\t\t\t \\item $f(x)=2^x+3$\n\t\t\t\t \\item $g(x)=19$\n\t\t\t\t \\item $h(x)=\\dfrac{3+x}{4-x}$\n\t\t\t\t \\item $k(x)=\\dfrac{x^3+2x}{x-15}$\n\t\t\t\t \\item $l(x)=9-4x$\n\t\t\t\t \\item $m(x)=\\dfrac{x+5}{(x-7)(x+9)}$\n\t\t\t\t \\item $n(x)=x^2+6x+7$\n\t\t\t\t \\item $q(x)=1-\\dfrac{3}{x+1}$\n\t\t\t \\end{enumerate}\n\t\t \\end{multicols}\n\t\t \\begin{pccsolution}\n\t\t\t \\begin{enumerate}\n\t\t\t\t \\item $r$ is rational; the domain of $r$ is $(-\\infty,0)\\cup(0,\\infty)$.\n\t\t\t\t \\item $f$ is not rational.\n\t\t\t\t \\item $g$ is not rational; $g$ is constant.\n\t\t\t\t \\item $h$ is rational; the domain of $h$ is $(-\\infty,4)\\cup(4,\\infty)$.\n\t\t\t\t \\item $k$ is rational; the domain of $k$ is $(-\\infty,15)\\cup(15,\\infty)$.\n\t\t\t\t \\item $l$ is not rational; $l$ is linear.\n\t\t\t\t \\item $m$ is rational; the domain of $m$ is $(-\\infty,-9)\\cup(-9,7)\\cup(7,\\infty)$.\n\t\t\t\t \\item $n$ is not rational; $n$ is quadratic (or you might describe $n$ as a polynomial).\n\t\t\t\t \\item $q$ is rational; the domain of $q$ is $(-\\infty,-1)\\cup (-1,\\infty)$.\n\t\t\t \\end{enumerate}\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Match formula to graph]\n\t\t Each of the following functions is graphed in \\cref{rat:fig:whichiswhich}.\n\t\t Which is which?\n\t\t \\[\n\t\t\t r(x)=\\frac{1}{x-3}, \\qquad q(x)=\\frac{x-2}{x+5}, \\qquad k(x)=\\frac{1}{(x+2)(x-3)}\n\t\t \\]\n\t\t \\begin{figure}[!htb]\n\t\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)/(x+5);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-6.37]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-3.97:10]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({-5},{x});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:which1}\n\t\t\t \\end{subfigure}\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=1/(x-3);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-5,ymax=6,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-4,4},\n\t\t\t\t\t\t\t minor ytick={-3,...,5},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:2.8]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=3.17:10]{f};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:which2}\n\t\t\t \\end{subfigure}\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=1/((x-3)*(x+2));}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-4,4},\n\t\t\t\t\t\t\t minor ytick={-3,...,3},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-2.03969]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.95967:2.95967]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=3.03969:10]{f};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({-2},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({3},{x});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:which3}\n\t\t\t \\end{subfigure}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:whichiswhich}\n\t\t \\end{figure}\n\n\t\t \\begin{pccsolution}\n\t\t\t Let's start with the function $r$. Note that domain of $r$ is $(-\\infty,3)\\cup(0,3)$, so\n\t\t\t we search for a function that has a vertical asymptote at $3$. There\n\t\t\t are two possible choices: the functions graphed in \\cref{rat:fig:which2,rat:fig:which3},\n\t\t\t but note that the function in \\cref{rat:fig:which3} also has a vertical asymptote at $-2$\n\t\t\t which is not consistent with the formula for $r(x)$. Therefore, $y=r(x)$\n\t\t\t is graphed in \\cref{rat:fig:which2}.\n\n\t\t\t The function $q$ has domain $(-\\infty,-5)\\cup(-5,\\infty)$, so we search\n\t\t\t for a function that has a vertical asymptote at $-5$. The only candidate\n\t\t\t is the curve shown in \\cref{rat:fig:which1}; note that the curve also goes through $(2,0)$,\n\t\t\t which is consistent with the formula for $q(x)$, since $q(2)=0$, i.e $q$\n\t\t\t has a zero at $2$.\n\n\t\t\t The function $k$ has domain $(-\\infty,-2)\\cup(-2,3)\\cup(3,\\infty)$, and\n\t\t\t has vertical asymptotes at $-2$ and $3$. This is consistent with\n\t\t\t the graph in \\cref{rat:fig:which3} (and is the only curve that\n\t\t\t has $3$ branches).\n\n\t\t\t We note that each function behaves like $\\frac{1}{x}$ around its vertical asymptotes,\n\t\t\t because each linear factor in each denominator is raised to the power $1$; if (for example)\n\t\t\t the definition of $r$ was instead\n\t\t\t \\[\n\t\t\t\t r(x)=\\frac{1}{(x-3)^2}\n\t\t\t \\]\n\t\t\t then we would see that $r$ behaves like $\\frac{1}{x^2}$ around its vertical asymptote, and\n\t\t\t the graph of $r$ would be very different. We will deal with these cases in the examples that follow.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Repeated factors in the denominator]\n\t\t Consider the functions $f$, $g$, and $h$ that have formulas\n\t\t \\[\n\t\t\t f(x)=\\frac{x-2}{(x-3)(x+2)}, \\qquad g(x)=\\frac{x-2}{(x-3)^2(x+2)}, \\qquad h(x)=\\frac{x-2}{(x-3)(x+2)^2}\n\t\t \\]\n\t\t which are graphed in \\cref{rat:fig:repfactd}. Note that each function has $2$\n\t\t vertical asymptotes, and the domain of each function is\n\t\t \\[\n\t\t\t (-\\infty,-2)\\cup(-2,3)\\cup(3,\\infty)\n\t\t \\]\n\t\t so we are not surprised to see that each curve has $3$ branches. We also note that\n\t\t the numerator of each function is the same, which tells us that each function has\n\t\t only $1$ zero at $2$.\n\n\t\t The functions $g$ and $h$ are different from those that we have considered previously,\n\t\t because they have a repeated factor in the denominator. Notice in particular\n\t\t the way that the functions behave around their asymptotes:\n\t\t \\begin{itemize}\n\t\t\t \\item $f$ behaves like $\\frac{1}{x}$ around both of its asymptotes;\n\t\t\t \\item $g$ behaves like $\\frac{1}{x}$ around $-2$, and like $\\frac{1}{x^2}$ around $3$;\n\t\t\t \\item $h$ behaves like $\\frac{1}{x^2}$ around $-2$, and like $\\frac{1}{x}$ around $3$.\n\t\t \\end{itemize}\n\t \\end{pccexample}\n\t \\begin{figure}[!htb]\n\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)/((x+2)*(x-3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-4,ymax=4,\n\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t ytick={-2,2},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-2.201]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.802:2.951]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.052:5]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({-2},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{x-2}{(x+2)(x-3)}$}\n\t\t\t \\label{rat:fig:repfactd1}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)/((x+2)*(x-3)^2);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-4,ymax=4,\n\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t ytick={-2,2},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-2.039]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.959:2.796]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.243:5]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-4:4]({-2},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-4:4]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{x-2}{(x+2)(x-3)^2}$}\n\t\t\t \\label{rat:fig:repfactd2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)/((x+2)^2*(x-3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-4,ymax=4,\n\t\t\t\t\t\t xtick={-4,-2,...,2},\n\t\t\t\t\t\t ytick={-2,2},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-2.451]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.558:2.990]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.010:6]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-4:4]({-2},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-4:4]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{x-2}{(x+2)^2(x-3)}$}\n\t\t\t \\label{rat:fig:repfactd3}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\label{rat:fig:repfactd}\n\t \\end{figure}\n\n\t \\Cref{rat:def:function} says that the zeros of\n\t the rational function $r$ that has formula $r(x)=\\frac{p(x)}{q(x)}$ are\n\t the zeros of $p$. Let's explore this a little more.\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}[Zeros] Find the zeros of each of the following functions\n\t\t \\[\n\t\t\t \\alpha(x)=\\frac{x+5}{3x-7}, \\qquad \\beta(x)=\\frac{9-x}{x+1}, \\qquad \\gamma(x)=\\frac{17x^2-10}{2x+1}\n\t\t \\]\n\t\t \\begin{pccsolution}\n\t\t\t We find the zeros of each function in turn by setting the numerator equal to $0$. The zeros of\n\t\t\t $\\alpha$ are found by solving\n\t\t\t \\[\n\t\t\t\t x+5=0\n\t\t\t \\]\n\t\t\t The zero of $\\alpha$ is $-5$.\n\n\t\t\t Similarly, we may solve $9-x=0$ to find the zero of $\\beta$, which is clearly $9$.\n\n\t\t\t The zeros of $\\gamma$ satisfy the equation\n\t\t\t \\[\n\t\t\t\t 17x^2-10=0\n\t\t\t \\]\n\t\t\t which we can solve using the square root property to obtain\n\t\t\t \\[\n\t\t\t\t x=\\pm\\frac{10}{17}\n\t\t\t \\]\n\t\t\t The zeros of $\\gamma$ are $\\pm\\frac{10}{17}$.\n\t\t \\end{pccsolution}\n\t \\end{pccexample}\n\n \\subsection*{Long-run behavior}\n\t Our focus so far has been on the behavior of rational functions around\n\t their \\emph{vertical} asymptotes. In fact, rational functions also\n\t have interesting long-run behavior around their \\emph{horizontal} or\n\t \\emph{oblique} asymptotes. A rational function will always have either\n\t a horizontal or an oblique asymptote| the case is determined by the degree\n\t of the numerator and the degree of the denominator.\n\t \\begin{pccdefinition}[Long-run behavior]\\label{rat:def:longrun}\n\t\t Let $r$ be the rational function that has formula\n\t\t \\[\n\t\t\t r(x) = \\frac{a_n x^n + a_{n-1}x^{n-1}+\\ldots + a_0}{b_m x^m + b_{m-1}x^{m-1}+\\ldots+b_0}\n\t\t \\]\n\t\t We can classify the long-run behavior of the rational function $r$\n\t\t according to the following criteria:\n\t\t \\begin{itemize}\n\t\t\t \\item if $n<m$ then  $r$ has a horizontal asymptote with equation $y=0$;\n\t\t\t \\item if $n=m$ then $r$ has a horizontal asymptote with equation $y=\\dfrac{a_n}{b_m}$;\n\t\t\t \\item if $n>m$ then $r$ will have an oblique asymptote as $x\\rightarrow\\pm\\infty$ (more on this in \\cref{rat:sec:oblique})\n\t\t \\end{itemize}\n\t \\end{pccdefinition}\n\t We will concentrate on functions that have horizontal asymptotes until\n\t we reach \\cref{rat:sec:oblique}.\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}[Long-run behavior graphically]\\label{rat:ex:horizasymp}\n\t\t \\pccname{Kebede} has graphed the following functions in his graphing calculator\n\t\t \\[\n\t\t\t r(x)=\\frac{x+1}{x-3}, \\qquad s(x)=\\frac{2(x+1)}{x-3}, \\qquad t(x)=\\frac{3(x+1)}{x-3}\n\t\t \\]\n\t\t and obtained the curves shown in \\cref{rat:fig:horizasymp}. Kebede decides\n\t\t to test his knowledgeable friend \\pccname{Oscar}, and asks him\n\t\t to match the formulas to the graphs.\n\n\t\t \\begin{figure}[!htb]\n\t\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=2*(x+1)/(x-3);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-15,xmax=15,\n\t\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t\t xtick={-12,-8,...,12},\n\t\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-15:2]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=5:15]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-1,0)};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-15:15]({x},{2});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:horizasymp1}\n\t\t\t \\end{subfigure}\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x+1)/(x-3);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-15,xmax=15,\n\t\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t\t xtick={-12,-8,...,12},\n\t\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-15:2.42857,samples=50]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=3.8:15,samples=50]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-1,0)};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-15:15]({x},{1});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:horizasymp2}\n\t\t\t \\end{subfigure}\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=3*(x+1)/(x-3);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-15,xmax=15,\n\t\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t\t xtick={-12,-8,...,12},\n\t\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-15:1.6666,samples=50]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=7:15]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-1,0)};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-15:15]({x},{3});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:horizasymp3}\n\t\t\t \\end{subfigure}\n\t\t\t \\caption{Horizontal asymptotes}\n\t\t\t \\label{rat:fig:horizasymp}\n\t\t \\end{figure}\n\n\t\t Oscar notices that each function has a vertical asymptote at $3$ and a zero at $-1$.\n\t\t The main thing that catches Oscar's eye is that each function has a different\n\t\t coefficient in the numerator, and that each curve has a different horizontal asymptote.\n\t\t In particular, Oscar notes that\n\t\t \\begin{itemize}\n\t\t\t \\item the curve shown in \\cref{rat:fig:horizasymp1} has a horizontal asymptote with equation $y=2$;\n\t\t\t \\item the curve shown in \\cref{rat:fig:horizasymp2} has a horizontal asymptote with equation $y=1$;\n\t\t\t \\item the curve shown in \\cref{rat:fig:horizasymp3} has a horizontal asymptote with equation $y=3$.\n\t\t \\end{itemize}\n\t\t Oscar is able to tie it all together for Kebede by referencing \\cref{rat:def:longrun}. He says\n\t\t that since the degree of the numerator and the degree of the denominator is the same\n\t\t for each of the functions $r$, $s$, and $t$, the horizontal asymptote will be determined\n\t\t by evaluating the ratio of their leading coefficients.\n\n\t\t Oscar therefore says that $r$ should have a horizontal asymptote $y=\\frac{1}{1}=1$, $s$ should\n\t\t have a horizontal asymptote $y=\\frac{2}{1}=2$, and $t$ should have a horizontal asymptote\n\t\t $y=\\frac{3}{1}=3$. Kebede is able to finish the problem from here, and says that $r$ is\n\t\t shown in \\cref{rat:fig:horizasymp2}, $s$ is shown in \\cref{rat:fig:horizasymp1}, and\n\t\t $t$ is shown in \\cref{rat:fig:horizasymp3}.\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{pccexample}[Long-run behavior numerically]\n\t\t \\pccname{Xiao} and \\pccname{Dwayne} saw \\cref{rat:ex:horizasymp} but are a little confused\n\t\t about horizontal asymptotes. What does it mean to say that a function $r$ has a horizontal\n\t\t asymptote?\n\n\t\t They decide to explore the concept by\n\t\t constructing a table of values for the rational functions $R$ and  $S$ that have formulas\n\t\t \\[\n\t\t\t R(x)=\\frac{-5(x+1)}{x-3}, \\qquad S(x)=\\frac{7(x-5)}{2(x+1)}\n\t\t \\]\n\t\t In \\cref{rat:tab:plusinfty} they model the behavior of $R$ and $S$ as $x\\rightarrow\\infty$,\n\t\t and in \\cref{rat:tab:minusinfty} they model the behavior of $R$ and $S$ as $x\\rightarrow-\\infty$\n\t\t by substituting very large values of $|x|$ into each function.\n\t\t \\begin{table}[!htb]\n\t\t\t \\begin{minipage}{.5\\textwidth}\n\t\t\t\t \\centering\n\t\t\t\t \\caption{$R$ and $S$ as $x\\rightarrow\\infty$}\n\t\t\t\t \\label{rat:tab:plusinfty}\n\t\t\t\t \\begin{tabular}{crr}\n\t\t\t\t\t \\beforeheading\n\t\t\t\t\t $x$            & $R(x)$     & $S(x)$    \\\\ \\afterheading\n\t\t\t\t\t $1\\times 10^2$ & $-5.20619$ & $3.29208$ \\\\\\normalline\n\t\t\t\t\t $1\\times 10^3$ & $-5.02006$ & $3.47902$ \\\\\\normalline\n\t\t\t\t\t $1\\times 10^4$ & $-5.00200$ & $3.49790$ \\\\\\normalline\n\t\t\t\t\t $1\\times 10^5$ & $-5.00020$ & $3.49979$ \\\\\\normalline\n\t\t\t\t\t $1\\times 10^6$ & $-5.00002$ & $3.49998$ \\\\\\lastline\n\t\t\t\t \\end{tabular}\n\t\t\t \\end{minipage}%\n\t\t\t \\begin{minipage}{.5\\textwidth}\n\t\t\t\t \\centering\n\t\t\t\t \\caption{$R$ and $S$ as $x\\rightarrow-\\infty$}\n\t\t\t\t \\label{rat:tab:minusinfty}\n\t\t\t\t \\begin{tabular}{crr}\n\t\t\t\t\t \\beforeheading\n\t\t\t\t\t $x$             & $R(x)$     & $S(x)$    \\\\ \\afterheading\n\t\t\t\t\t $-1\\times 10^2$ & $-4.80583$ & $3.71212$ \\\\\\normalline\n\t\t\t\t\t $-1\\times 10^3$ & $-4.98006$ & $3.52102$ \\\\\\normalline\n\t\t\t\t\t $-1\\times 10^4$ & $-4.99800$ & $3.50210$ \\\\\\normalline\n\t\t\t\t\t $-1\\times 10^5$ & $-4.99980$ & $3.50021$ \\\\\\normalline\n\t\t\t\t\t $-1\\times 10^6$ & $-4.99998$ & $3.50002$ \\\\\\lastline\n\t\t\t\t \\end{tabular}\n\t\t\t \\end{minipage}\n\t\t \\end{table}\n\n\t\t Xiao and Dwayne study \\cref{rat:tab:plusinfty,rat:tab:minusinfty} and decide that\n\t\t the functions $R$ and $S$ never actually touch their horizontal asymptotes, but they\n\t\t do get infinitely close. They also feel as if they have a better understanding of\n\t\t what it means to study the behavior of a function as $x\\rightarrow\\pm\\infty$.\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}[Repeated factors in the numerator]\n\t\t Consider the functions $f$, $g$, and $h$ that have formulas\n\t\t \\[\n\t\t\t f(x)=\\frac{(x-2)^2}{(x-3)(x+1)}, \\qquad g(x)=\\frac{x-2}{(x-3)(x+1)}, \\qquad h(x)=\\frac{(x-2)^3}{(x-3)(x+1)}\n\t\t \\]\n\t\t which are graphed in \\cref{rat:fig:repfactn}. We note that each function has vertical\n\t\t asymptotes at $-1$ and $3$, and so the domain of each function is\n\t\t \\[\n\t\t\t (-\\infty,-1)\\cup(-1,3)\\cup(3,\\infty)\n\t\t \\]\n\t\t We also notice that the numerators of each function are quite similar| indeed, each\n\t\t function has a zero at $2$, but how does each function behave around their zero?\n\n\t\t Using \\cref{rat:fig:repfactn} to guide us, we note that\n\t\t \\begin{itemize}\n\t\t\t \\item $f$ has a horizontal intercept $(2,0)$, but the curve of\n\t\t\t       $f$ does not cut the horizontal axis| it bounces off it;\n\t\t\t \\item $g$ also has a horizontal intercept $(2,0)$, and the curve\n\t\t\t       of $g$ \\emph{does} cut the horizontal axis;\n\t\t\t \\item $h$ has a horizontal intercept $(2,0)$, and the curve of $h$\n\t\t\t       also cuts the axis, but appears flattened as it does so.\n\t\t \\end{itemize}\n\n\t\t We can further enrich our study by discussing the long-run behavior of each function.\n\t\t Using the tools of \\cref{rat:def:longrun}, we can deduce that\n\t\t \\begin{itemize}\n\t\t\t \\item $f$ has a horizontal asymptote with equation $y=1$;\n\t\t\t \\item $g$ has a horizontal asymptote with equation $y=0$;\n\t\t\t \\item $h$ does \\emph{not} have a horizontal asymptote| it has an oblique asymptote (we'll\n\t\t\t       study this more in \\cref{rat:sec:oblique}).\n\t\t \\end{itemize}\n\t \\end{pccexample}\n\n\t \\begin{figure}[!htb]\n\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)^2/((x+1)*(x-3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t ytick={-8,-4,...,8},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t width=\\figurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-1.248,samples=50]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-0.794:2.976,samples=50]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.026:5,samples=50]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({-1},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{(x-2)^2}{(x+1)(x-3)}$}\n\t\t\t \\label{rat:fig:repfactn1}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)/((x+1)*(x-3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-4,-2,...,4},\n\t\t\t\t\t\t ytick={-8,-4,...,8},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t width=\\figurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-1.075]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-0.925:2.975]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.025:5]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({-1},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-6:6]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{x-2}{(x+1)(x-3)}$}\n\t\t\t \\label{rat:fig:repfactn2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-2)^3/((x+1)*(x-3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t %                    framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t %                    grid=both,\n\t\t\t\t\t\t ymin=-30,ymax=30,\n\t\t\t\t\t\t width=\\figurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-1.27]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-0.806:2.99185]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.0085:5]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(2,0)};\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-30:30]({-1},{x});\n\t\t\t\t\t %                 \\addplot[asymptote,domain=-30:30]({3},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{(x-2)^3}{(x+1)(x-3)}$}\n\t\t\t \\label{rat:fig:repfactn3}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\label{rat:fig:repfactn}\n\t \\end{figure}\n\n \\subsection*{Holes}\n\t Rational functions have a vertical asymptote at $a$ if the denominator is $0$ at $a$.\n\t What happens if the numerator is $0$ at the same place? In this case, we say that the rational\n\t function has a \\emph{hole} at $a$.\n\t \\begin{pccdefinition}[Holes]\n\t\t The rational function\n\t\t \\[\n\t\t\t r(x)=\\frac{p(x)}{q(x)}\n\t\t \\]\n\t\t has a hole at $a$ if $p(a)=q(a)=0$. Note that holes are different from\n\t\t a vertical asymptotes. We represent that $r$ has a hole at the point\n\t\t $(a,r(a))$ on the curve $y=r(x)$ by\n\t\t using a hollow circle, $\\circ$.\n\t \\end{pccdefinition}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}\n\t\t \\pccname{Mohammed} and \\pccname{Sue} have graphed the function $r$ that has formula\n\t\t \\[\n\t\t\t r(x)=\\frac{x^2+x-6}{(x-2)}\n\t\t \\]\n\t\t in their calculators, and can not decide if the correct graph\n\t\t is \\cref{rat:fig:hole} or \\cref{rat:fig:hole1}.\n\n\t\t Luckily for them, Oscar is nearby, and can help them settle the debate.\n\t\t Oscar demonstrates that\n\t\t \\begin{align*}\n\t\t\t r(x) & =\\frac{(x+3)(x-2)}{(x-2)} \\\\\n\t\t\t      & = x+3\n\t\t \\end{align*}\n\t\t but only when $x\\ne 2$, because the function is undefined at $2$. Oscar\n\t\t says that this necessarily means that the domain or $r$ is\n\t\t \\[\n\t\t\t (-\\infty,2)\\cup(2,\\infty)\n\t\t \\]\n\t\t and that $r$ must have a hole at $2$.\n\n\t\t Mohammed and Sue are very grateful for the clarification, and conclude that\n\t\t the graph of $r$ is shown in \\cref{rat:fig:hole1}.\n\t\t \\begin{figure}[!htb]\n\t\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-8,-4,...,8},\n\t\t\t\t\t\t\t ytick={-8,-4,...,8},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-10:7]{x+3};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:hole}\n\t\t\t \\end{minipage}%\n\t\t\t \\hfill\n\t\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-8,-4,...,8},\n\t\t\t\t\t\t\t ytick={-8,-4,...,8},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot expression[domain=-10:7]{x+3};\n\t\t\t\t\t\t \\addplot[holdot] coordinates{(2,5)};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:hole1}\n\t\t\t \\end{minipage}%\n\t\t \\end{figure}\n\t \\end{pccexample}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{pccexample}\n\t\t Consider the function $f$ that has formula\n\t\t \\[\n\t\t\t f(x)=\\frac{x(x+3)}{x^2-4x}\n\t\t \\]\n\t\t The domain of $f$ is $(-\\infty,0)\\cup(0,4)\\cup(4,\\infty)$ because both $0$ and $4$\n\t\t make the denominator equal to $0$. Notice that\n\t\t \\begin{align*}\n\t\t\t f(x) & = \\frac{x(x+3)}{x(x-4)} \\\\\n\t\t\t      & = \\frac{x+3}{x-4}\n\t\t \\end{align*}\n\t\t provided that $x\\ne 0$. Since $0$ makes the numerator\n\t\t and the denominator 0 at the same time, we say that $f$ has a hole at $(0,-\\nicefrac{3}{4})$.\n\t\t Note that this necessarily means that $f$ does not have a vertical intercept.\n\n\t\t We also note $f$ has a vertical asymptote at $4$; the function is graphed in \\cref{rat:fig:holeex}.\n\t\t \\begin{figure}[!htb]\n\t\t\t \\centering\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x+3)/(x-4);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:3.36364,samples=50]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=4.77:10]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t\t \\addplot[holdot]coordinates{(0,-0.75)};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{$y=\\dfrac{x(x+3)}{x^2-4x}$}\n\t\t\t \\label{rat:fig:holeex}\n\t\t \\end{figure}\n\t \\end{pccexample}\n\n\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{pccexample}[Minimums and maximums]\n\t\t \\pccname{Seamus} and \\pccname{Trang} are discussing rational functions. Seamus says that\n\t\t if a rational function has a vertical asymptote, then it can\n\t\t not possibly have local minimums and maximums, nor can it have\n\t\t global minimums and maximums.\n\n\t\t Trang says this statement is not always true. She plots the functions\n\t\t $f$ and $g$ that have formulas\n\t\t \\[\n\t\t\t f(x)=-\\frac{32(x-1)(x+1)}{(x-2)^2(x+2)^2}, \\qquad g(x)=\\frac{32(x-1)(x+1)}{(x-2)^2(x+2)^2}\n\t\t \\]\n\t\t in \\cref{rat:fig:minmax1,rat:fig:minmax2} and shows them to Seamus. On seeing the graphs,\n\t\t Seamus quickly corrects himself, and says  that $f$ has a local (and global)\n\t\t maximum of $2$ at $0$, and that $g$ has a local (and global) minimum of $-2$ at $0$.\n\n\t\t \\begin{figure}[!htb]\n\t\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=-32*(x-1)*(x+1)/(( x-2)^2*(x+2)^2);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-3.01]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.45:1.45]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=3.01:10]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-1,0)(1,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{$y=f(x)$}\n\t\t\t\t \\label{rat:fig:minmax1}\n\t\t\t \\end{minipage}%\n\t\t\t \\hfill\n\t\t\t \\begin{minipage}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=32*(x-1)*(x+1)/(( x-2)^2*(x+2)^2);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t framed,\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-3.01]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.45:1.45]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=3.01:10]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-1,0)(1,0)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{$y=g(x)$}\n\t\t\t\t \\label{rat:fig:minmax2}\n\t\t\t \\end{minipage}%\n\t\t \\end{figure}\n\n\t\t Seamus also notes that (in its domain) the function $f$ is always concave down, and\n\t\t that (in its domain) the function $g$ is always concave up. Furthermore, Trang\n\t\t observes that each function behaves like $\\frac{1}{x^2}$ around each of its vertical\n\t\t asymptotes, because each linear factor in the denominator is raised to the power $2$.\n\n\t\t \\pccname{Oscar} stops by and reminds both students about the long-run behavior; according\n\t\t to \\cref{rat:def:longrun} since the degree of the denominator is greater than the\n\t\t degree of the numerator (in both functions), each function has a horizontal asymptote\n\t\t at $y=0$.\n\t \\end{pccexample}\n\n\n\t \\investigation*{}\n\t %===================================\n\t %   Author: Pettit/Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[The spaghetti incident]\n\t The same Queen from \\vref{exp:prob:queenschessboard} has recovered from\n\t the rice experiments, and has called her loyal jester for another challenge.\n\n\t The jester has an $11-$inch piece of uncooked spaghetti that he puts on a table;\n\t he uses a book to cover $\\unit[1]{inch}$ of it so that\n\t $\\unit[10]{inches}$ hang over the edge. The jester then produces a box of $\\unit{mg}$\n\t weights that can be hung from the spaghetti.\n\n\t The jester says it will take $\\unit[y]{mg}$ to break the spaghetti when hung\n\t $\\unit[x]{inches}$ from the edge, according to the rule $y=\\frac{100}{x}$.\n\t \\begin{margintable}\n\t\t \\centering\n\t\t \\captionof{table}{}\n\t\t \\label{rat:tab:spaghetti}\n\t\t \\begin{tabular}{cc}\n\t\t\t \\beforeheading\n\t\t\t \\heading{$x$} & \\heading{$y$} \\\\\n\t\t\t \\afterheading\n\t\t\t $1$           &               \\\\\\normalline\n\t\t\t $2$           &               \\\\\\normalline\n\t\t\t $3$           &               \\\\\\normalline\n\t\t\t $4$           &               \\\\\\normalline\n\t\t\t $5$           &               \\\\\\normalline\n\t\t\t $6$           &               \\\\\\normalline\n\t\t\t $7$           &               \\\\\\normalline\n\t\t\t $8$           &               \\\\\\normalline\n\t\t\t $9$           &               \\\\\\normalline\n\t\t\t $10$          &               \\\\\\lastline\n\t\t \\end{tabular}\n\t \\end{margintable}\n\t \\begin{subproblem}\\label{rat:prob:spaggt1}\n\t\t Help the Queen complete \\cref{rat:tab:spaghetti}, and use $2$ digits after the decimal\n\t\t where appropriate.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{tabular}[t]{ld{2}}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\\n\t\t\t\t \\afterheading\n\t\t\t\t $1$           & 100           \\\\\\normalline\n\t\t\t\t $2$           & 50            \\\\\\normalline\n\t\t\t\t $3$           & 33.33         \\\\\\normalline\n\t\t\t\t $4$           & 25            \\\\\\normalline\n\t\t\t\t $5$           & 20            \\\\\\normalline\n\t\t\t\t $6$           & 16.67         \\\\\\normalline\n\t\t\t\t $7$           & 14.29         \\\\\\normalline\n\t\t\t\t $8$           & 12.50         \\\\\\normalline\n\t\t\t\t $9$           & 11.11         \\\\\\normalline\n\t\t\t\t $10$          & 10            \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t What do you notice about the number of $\\unit{mg}$ that it takes to break\n\t\t the spaghetti as $x$ increases?\n\t\t \\begin{shortsolution}\n\t\t\t It seems that the number of $\\unit{mg}$ that it takes to break the spaghetti decreases\n\t\t\t as $x$ increases.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\\label{rat:prob:spaglt1}\n\t\t The Queen wonders what happens when $x$ gets very small| help the Queen construct\n\t\t a table of values for $x$ and $y$ when $x=0.0001, 0.001, 0.01, 0.1, 0.5, 1$.\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{tabular}[t]{d{2}l}\n\t\t\t\t \\beforeheading\n\t\t\t\t \\heading{$x$} & \\heading{$y$} \\\\\n\t\t\t\t \\afterheading\n\t\t\t\t 0.0001        & $1000000$     \\\\\\normalline\n\t\t\t\t 0.001         & $100000$      \\\\\\normalline\n\t\t\t\t 0.01          & $10000$       \\\\\\normalline\n\t\t\t\t 0.1           & $1000$        \\\\\\normalline\n\t\t\t\t 0.5           & $200$         \\\\\\normalline\n\t\t\t\t 1             & $100$         \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t What do you notice about the number of $\\unit{mg}$ that it takes to break the spaghetti\n\t\t as $x\\rightarrow 0$? Would it ever make sense to let $x=0$?\n\t\t \\begin{shortsolution}\n\t\t\t The number of $\\unit{mg}$ required to break the spaghetti increases as $x\\rightarrow 0$.\n\t\t\t We can not allow $x$ to be $0$, as we can not divide by $0$, and we can not\n\t\t\t be $0$ inches from the edge of the table.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Plot your results from \\cref{rat:prob:spaggt1,rat:prob:spaglt1} on the same graph,\n\t\t and join the points using a smooth curve| set the maximum value of $y$ as $200$, and\n\t\t note that this necessarily means that you will not be able to plot all of the points.\n\t\t \\begin{shortsolution}\n\t\t\t The graph of $y=\\frac{100}{x}$ is shown below.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-2,xmax=11,\n\t\t\t\t\t\t ymin=-20,ymax=200,\n\t\t\t\t\t\t xtick={2,4,...,10},\n\t\t\t\t\t\t ytick={20,40,...,180},\n\t\t\t\t\t\t grid=major,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot+[-] expression[domain=0.5:10]{100/x};\n\t\t\t\t\t \\addplot[soldot] coordinates{(0.5,200)(1,100)(2,50)(3,33.33)\n\t\t\t\t\t\t\t (4,25)(5,20)(16.67)(7,14.29)(8,12.50)(9,11.11)(10,10)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Using your graph, observe what happens to $y$ as $x$ increases. If we could somehow\n\t\t construct a piece of uncooked spaghetti that was $\\unit[101]{inches}$ long, how many\n\t\t $\\unit{mg}$ would it take to break the spaghetti?\n\t\t \\begin{shortsolution}\n\t\t\t As $x$ increases, $y\\rightarrow 0$. If we could construct a piece of spaghetti\n\t\t\t $\\unit[101]{inches}$ long, it would only take $\\unit[1]{mg}$ to break it $\\left(\\frac{100}{100}=1\\right)$. Of course,\n\t\t\t the weight of spaghetti would probably cause it to break without the weight.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t The Queen looks forward to more food-related investigations from her jester.\n\t \\end{problem}\n\n\n\n\t %===================================\n\t %   Author: Adams (Hughes)\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Debt Amortization]\n\t To amortize a debt means to pay it off in a given length of time using\n\t equal periodic payments. The payments include interest on the unpaid\n\t balance. The following formula gives the monthly payment, $M$, in dollars\n\t that is necessary to amortize a debt of $P$ dollars in $n$ months\n\t at a monthly interest rate of $i$\n\t \\[\n\t\t M=\\frac{P\\cdot i}{1-(1+i)^{-n}}\n\t \\]\n\t Use this formula in each of the following problems.\n\t \\begin{subproblem}\n\t\t What monthly payments are necessary on a credit card debt of \\$2000 at\n\t\t $\\unit[1.5]{\\%}$ monthly if you want to pay off the debt in $2$ years?\n\t\t In one year? How much money will you save by paying off the debt in the\n\t\t shorter amount of time?\n\t\t \\begin{shortsolution}\n\t\t\t Paying off the debt in $2$ years, we use\n\t\t\t \\begin{align*}\n\t\t\t\t M & = \\frac{2000\\cdot 0.015}{1-(1+0.015)^{-24}} \\\\\n\t\t\t\t   & \\approx 99.85\n\t\t\t \\end{align*}\n\t\t\t The monthly payments are \\$99.85.\n\n\t\t\t Paying off the debt in $1$ year, we use\n\t\t\t \\begin{align*}\n\t\t\t\t M & = \\frac{2000\\cdot 0.015}{1-(1+0.015)^{-12}} \\\\\n\t\t\t\t   & \\approx 183.36\n\t\t\t \\end{align*}\n\t\t\t The monthly payments are \\$183.36\n\n\t\t\t In the $2$-year model we would pay a total of $\\$99.85\\cdot 12=\\$2396.40$. In the\n\t\t\t $1$-year model we would pay a total of $\\$183.36\\cdot 12=\\$2200.32$. We would therefore\n\t\t\t save $\\$196.08$ if we went with the $1$-year model instead of the $2$-year model.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t To purchase a home, a family needs a loan of \\$300,000 at $\\unit[5.2]{\\%}$\n\t\t annual interest.  Compare a $20$ year loan to a $30$ year loan and make\n\t\t a recommendation for the family.\n\t\t (Note: when given an annual interest rate, it is a common business practice to divide by\n\t\t $12$ to get a monthly rate.)\n\t\t \\begin{shortsolution}\n\t\t\t For the $20$-year loan we use\n\t\t\t \\begin{align*}\n\t\t\t\t M & = \\frac{300000\\cdot \\frac{0.052}{12}}{1-\\left( 1+\\frac{0.052}{12} \\right)^{-12\\cdot 20}} \\\\\n\t\t\t\t   & \\approx 2013.16\n\t\t\t \\end{align*}\n\t\t\t The monthly payments are \\$2013.16.\n\n\t\t\t For the $30$-year loan we use\n\t\t\t \\begin{align*}\n\t\t\t\t M & = \\frac{300000\\cdot \\frac{0.052}{12}}{1-\\left( 1+\\frac{0.052}{12} \\right)^{-12\\cdot 30}} \\\\\n\t\t\t\t   & \\approx 1647.33\n\t\t\t \\end{align*}\n\t\t\t The monthly payments are \\$1647.33.\n\n\t\t\t The total amount paid during the $20$-year loan is $\\$2013.16\\cdot 12\\cdot 20=\\$483,158.40$.\n\t\t\t The total amount paid during the $30$-year loan is $\\$1647.33\\cdot 12\\cdot 30=\\$593,038.80$.\n\n\t\t\t Recommendation: if you can afford the payments, choose the $20$-year loan.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t \\pccname{Ellen} wants to make monthly payments of \\$100 to pay off a debt of \\$3000\n\t\t at \\unit[12]{\\%} annual interest. How long will it take her to pay off the\n\t\t debt?\n\t\t \\begin{shortsolution}\n\t\t\t We are given $M=100$, $P=3000$, $i=0.01$, and we need to find $n$\n\t\t\t in the equation\n\t\t\t \\[\n\t\t\t\t 100 = \\frac{3000\\cdot 0.01}{1-(1+0.01)^{-n}}\n\t\t\t \\]\n\t\t\t Using logarithms, we find that $n\\approx 36$. It will take\n\t\t\t Ellen about $3$ years to pay off the debt.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t \\pccname{Jake} is going to buy a new car. He puts \\$2000 down and wants to finance the\n\t\t remaining \\$14,000. The dealer will offer him \\unit[4]{\\%} annual interest for\n\t\t $5$ years, or a \\$2000\n\t\t rebate which he can use to reduce the amount of the loan and \\unit[8]{\\%}\n\t\t annual interest for 5 years. Which should he choose?\n\t\t \\begin{shortsolution}\n\t\t\t \\begin{description}\n\t\t\t\t \\item[Option 1:] $\\unit[4]{\\%}$ annual interest for $5$ years on \\$14,000.\n\t\t\t\t This means that the monthly payments will be calculated using\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t M & = \\frac{14000\\cdot \\frac{0.04}{12}}{1-\\left( 1+\\frac{0.04}{12} \\right)^{-12\\cdot 5}} \\\\\n\t\t\t\t\t   & \\approx 257.83\n\t\t\t\t \\end{align*}\n\t\t\t\t The monthly payments will be $\\$257.83$. The total amount paid will be\n\t\t\t\t $\\$257.83\\cdot 5\\cdot 12=\\$15,469.80$, of which $\\$1469.80$ is interest.\n\t\t\t\t \\item[Option 2:] $\\unit[8]{\\%}$ annual interest for $5$ years on \\$12,000.\n\t\t\t\t This means that the monthly payments will be calculated using\n\t\t\t\t \\begin{align*}\n\t\t\t\t\t M & = \\frac{12000\\cdot \\frac{0.08}{12}}{1-\\left( 1+\\frac{0.08}{12} \\right)^{-12\\cdot 5}} \\\\\n\t\t\t\t\t   & \\approx 243.32\n\t\t\t\t \\end{align*}\n\t\t\t\t The monthly payments will be $\\$243.32$. The total amount paid\n\t\t\t\t will be $\\$243.32\\cdot 5\\cdot 12 =\\$14,599.20$, of which $\\$2599.2$ is\n\t\t\t\t interest.\n\t\t\t \\end{description}\n\t\t\t Jake should choose option 1 to minimize the amount of interest\n\t\t\t he has to pay.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t \\begin{exercises}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Rational or not]\n\t Decide if each of the following functions are rational or not. If\n\t they are rational, state their domain.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $r(x)=\\dfrac{3}{x}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r$ is rational; the domain of $r$ is $(-\\infty,0)\\cup (0,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $s(y)=\\dfrac{y}{6}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $s$ is not rational ($s$ is linear).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $t(z)=\\dfrac{4-x}{7-8z}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $t$ is rational; the domain of $t$ is $\\left( -\\infty,\\dfrac{7}{8} \\right)\\cup \\left( \\dfrac{7}{8},\\infty \\right)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $u(w)=\\dfrac{w^2}{(w-3)(w+4)}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $u$ is rational; the domain of $w$ is $(-\\infty,-4)\\cup(-4,3)\\cup(3,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $v(x)=\\dfrac{4}{(x-2)^2}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $v$ is rational; the domain of $v$ is $(-\\infty,2)\\cup(2,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $w(x)=\\dfrac{9-x}{x+17}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $w$ is rational; the domain of $w$ is $(-\\infty,-17)\\cup(-17,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $a(x)=x^2+4$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $a$ is not rational ($a$ is quadratic, or a polynomial of degree $2$).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $b(y)=3^y$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $b$ is not rational ($b$ is exponential).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $c(z)=\\dfrac{z^2}{z^3}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $c$ is rational; the domain of $c$ is $(-\\infty,0)\\cup (0,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $d(x)=x^2(x+3)(5x-7)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $d$ is not rational ($d$ is a polynomial).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $e(\\alpha)=\\dfrac{\\alpha^2}{\\alpha^2-1}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $e$ is rational; the domain of $e$ is $(-\\infty,-1)\\cup(-1,1)\\cup(1,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $f(\\beta)=\\dfrac{3}{4}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $f$ is not rational ($f$ is constant).\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Function evaluation]\n\t Let $r$ be the function that has formula\n\t \\[\n\t\t r(x)=\\frac{(x-2)(x+3)}{(x+5)(x-7)}\n\t \\]\n\t Evaluate each of the following (if possible); if the value is undefined,\n\t then state so.\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $r(0)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(0) & =\\frac{(0-2)(0+3)}{(0+5)(0-7)} \\\\\n\t\t\t\t\t\t      & =\\frac{-6}{-35}                \\\\\n\t\t\t\t\t\t      & =\\frac{6}{35}\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(1)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(1) & =\\frac{(1-2)(1+3)}{(1+5)(1-7)} \\\\\n\t\t\t\t\t\t      & =\\frac{-4}{-36}                \\\\\n\t\t\t\t\t\t      & =\\frac{1}{9}\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(2)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(2) & =\\frac{(2-2)(2+3)}{(2+5)(2-7)} \\\\\n\t\t\t\t\t\t      & = \\frac{0}{-50}                \\\\\n\t\t\t\t\t\t      & =0\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(4) & =\\frac{(4-2)(4+3)}{(4+5)(4-7)} \\\\\n\t\t\t\t\t\t      & =\\frac{14}{-27}                \\\\\n\t\t\t\t\t\t      & =-\\frac{14}{27}\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(7)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(7) & =\\frac{(7-2)(7+3)}{(7+5)(7-7)} \\\\\n\t\t\t\t\t\t      & =\\frac{50}{0}\n\t\t\t\t\t \\end{aligned}$\n\n\t\t\t\t $r(7)$ is undefined.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(-3)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(-3) & =\\frac{(-3-2)(-3+3)}{(-3+5)(-3-7)} \\\\\n\t\t\t\t\t\t       & =\\frac{0}{-20}                     \\\\\n\t\t\t\t\t\t       & =0\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r(-5)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r(-5) & =\\frac{(-5-2)(-5+3)}{(-5+5)(-5-7)} \\\\\n\t\t\t\t\t\t       & =\\frac{14}{0}\n\t\t\t\t\t \\end{aligned}$\n\n\t\t\t\t $r(-5)$ is undefined.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $r\\left( \\frac{1}{2} \\right)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t\t r\\left( \\frac{1}{2} \\right) & = \\frac{\\left( \\frac{1}{2}-2 \\right)\\left( \\frac{1}{2}+3 \\right)}{\\left( \\frac{1}{2}+5 \\right)\\left( \\frac{1}{2}-7 \\right)} \\\\\n\t\t\t\t\t\t                             & =\\frac{-\\frac{3}{2}\\cdot\\frac{7}{2}}{\\frac{11}{2}\\left( -\\frac{13}{2} \\right)}                                              \\\\\n\t\t\t\t\t\t                             & =\\frac{-\\frac{21}{4}}{-\\frac{143}{4}}                                                                                       \\\\\n\t\t\t\t\t\t                             & =\\frac{37}{143}\n\t\t\t\t\t \\end{aligned}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   March 2012\n\t %===================================\n\t \\begin{problem}[Holes or asymptotes?]\n\t State the domain of each of the following rational functions. Identify\n\t any holes or asymptotes.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $f(x)=\\dfrac{12}{x-2}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $f$ has a vertical asymptote at $2$; the domain of $f$ is $(-\\infty,2)\\cup (2,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $g(x)=\\dfrac{x^2+x}{(x+1)(x-2)}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $g$ has a vertical asymptote at $2$, and a hole at $-1$; the domain of $g$ is $(-\\infty,-1)\\cup(-1,2)\\cup(2,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $h(x)=\\dfrac{x^2+5x+4}{x^2+x-12}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $h$ has a vertical asymptote at $3$, and a whole at $-4$; the domain of $h$ is $(-\\infty,-4)\\cup(-4,3)\\cup(3,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $k(z)=\\dfrac{z+2}{2z-3}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $k$ has a vertical asymptote at $\\dfrac{3}{2}$; the domain of $k$ is $\\left( -\\infty,\\dfrac{3}{2} \\right)\\cup\\left( \\dfrac{3}{2},\\infty \\right)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $l(w)=\\dfrac{w}{w^2+1}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $l$ does not have any vertical asymptotes nor holes; the domain of $w$ is $(-\\infty,\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $m(t)=\\dfrac{14}{13-t^2}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $m$ has vertical asymptotes at $\\pm\\sqrt{13}$; the domain of $m$ is $(-\\infty,\\sqrt{13})\\cup(-\\sqrt{13},\\sqrt{13})\\cup(\\sqrt{13},\\infty)$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a graph]\n\t Consider the rational functions graphed in \\cref{rat:fig:findformula}. Find\n\t the vertical asymptotes for each function, together with any zeros, and\n\t give a possible formula for each.\n\t \\begin{shortsolution}\n\t\t \\begin{itemize}\n\t\t\t \\item \\Vref{rat:fig:formula1}: possible formula is $r(x)=\\dfrac{1}{x+5}$\n\t\t\t \\item \\Vref{rat:fig:formula2}: possible formula is $r(x)=\\dfrac{(x+3)}{(x-5)}$\n\t\t\t \\item \\Vref{rat:fig:formula3}: possible formula is $r(x)=\\dfrac{1}{(x-4)(x+3)}$.\n\t\t \\end{itemize}\n\t \\end{shortsolution}\n\t \\end{problem}\n\n\t \\begin{figure}[!htb]\n\t\t \\begin{widepage}\n\t\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=1/(x+4);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-4.16667,samples=50]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-3.83333:10,samples=50]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({-4},{x});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:formula1}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x+3)/(x-5);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-6,ymax=6,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:3.85714]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=6.6:10]{f};\n\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)};\n\t\t\t\t\t \\addplot[asymptote,domain=-6:6]({5},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{1});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:formula2}\n\t\t \\end{subfigure}\n\t\t \\hfill\n\t\t \\begin{subfigure}{\\figurewidth}\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=1/((x-4)*(x+3));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-3,ymax=3,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t minor ytick={-4,-3,...,4},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-3.0473]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-2.95205:3.95205]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=4.0473:10]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-3:3]({-3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-3:3]({4},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{0});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t\t \\caption{}\n\t\t\t \\label{rat:fig:formula3}\n\t\t \\end{subfigure}\n\t\t \\caption{}\n\t\t \\label{rat:fig:findformula}\n\t\t \\end{widepage}\n\t \\end{figure}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a description]\n\t In each of the following problems, give a formula of a rational\n\t function that has the listed properties.\n\t \\begin{subproblem}\n\t\t Vertical asymptote at $2$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $r(x)=\\dfrac{1}{x-2}$. Note that we could multiply the\n\t\t\t numerator or denominator by any real number and still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Vertical asymptote at $5$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $r(x)=\\dfrac{1}{x-5}$. Note that we could multiply the\n\t\t\t numerator or denominator by any real number and still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Vertical asymptote at $-2$, and zero at $6$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $r(x)=\\dfrac{x-6}{x+2}$. Note that we could multiply the\n\t\t\t numerator or denominator by any real number and still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Zeros at $2$ and $-5$ and vertical asymptotes at $1$ and $-7$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $r(x)=\\dfrac{(x-2)(x+5)}{(x-1)(x+7)}$. Note that we could multiply the\n\t\t\t numerator or denominator by any real number and still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Given formula, find horizontal asymptotes]\n\t Each of the following functions has a horizontal asymptote. Write the equation\n\t of the horizontal asymptote for each function.\n\t \\begin{multicols}{3}\n\t\t \\begin{subproblem}\n\t\t\t $f(x) = \\dfrac{1}{x}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=0$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $g(x) = \\dfrac{2x+3}{x}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=2$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $h(x) = \\dfrac{x^2+2x}{x^2+3}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=1$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $k(x) = \\dfrac{x^2+7}{x}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=1$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $l(x)=\\dfrac{3x-2}{5x+8}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=\\dfrac{3}{5}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $m(x)=\\dfrac{3x-2}{5x^2+8}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=0$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $n(x)=\\dfrac{(6x+1)(x-7)}{(11x-8)(x-5)}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=\\dfrac{6}{11}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $p(x)=\\dfrac{19x^3}{5-x^4}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=0$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $q(x)=\\dfrac{14x^2+x}{1-7x^2}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $y=-2$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2012\n\t %===================================\n\t \\begin{problem}[Given horizontal asymptotes, find formula]\n\t In each of the following problems, give a formula for a function that\n\t has the given horizontal asymptote. Note that there may be more than one option.\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $y=7$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{7(x-2)}{x+1}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $7$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=-1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{5-x^2}{x^2+10}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $10$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=53$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{53x^3}{x^3+4x^2-7}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $53$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=-17$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{34(x+2)}{7-2x}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $-17$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=\\dfrac{3}{2}$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{3x+4}{2(x+1)}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $\\dfrac{3}{2}$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=0$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{4}{x}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is less than the degree\n\t\t\t\t of the denominator.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=-1$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{10x}{5-10x}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $-1$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $y=2$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Possible option: $f(x)=\\dfrac{8x-3}{4x+1}$. Note that there\n\t\t\t\t are other options, provided that the degree of the numerator is the same as the degree\n\t\t\t\t of the denominator, and that the ratio of the leading\n\t\t\t\t coefficients is $2$.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a description]\n\t In each of the following problems, give a formula for a function that\n\t has the prescribed properties. Note that there may be more than one option.\n\t \\begin{subproblem}\n\t\t $f(x)\\rightarrow 3$ as $x\\rightarrow\\pm\\infty$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $f(x)=\\dfrac{3(x-2)}{x+7}$. Note that\n\t\t\t the zero and asymptote of $f$ could be changed, and $f$ would still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $r(x)\\rightarrow -4$ as $x\\rightarrow\\pm\\infty$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $r(x)=\\dfrac{-4(x-2)}{x+7}$. Note that\n\t\t\t the zero and asymptote of $r$ could be changed, and $r$ would still have the desired properties.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $k(x)\\rightarrow 2$ as $x\\rightarrow\\pm\\infty$, and $k$ has vertical asymptotes at $-3$ and $5$.\n\t\t \\begin{shortsolution}\n\t\t\t Possible option: $k(x)=\\dfrac{2x^2}{(x+3)(x-5)}$. Note that the denominator\n\t\t\t must have the given factors; the numerator could be any degree $2$ polynomial, provided the\n\t\t\t leading coefficient is $2$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   Feb 2011\n\t %===================================\n\t \\begin{problem}\n\t Let $r$ be the rational function that has\n\t \\[\n\t\t r(x) = \\frac{(x+2)(x-1)}{(x+3)(x-4)}\n\t \\]\n\t Each of the following questions are in relation to this function.\n\t \\begin{subproblem}\n\t\t What is the vertical intercept of this function? State your answer as an\n\t\t ordered pair. \\index{rational functions!vertical intercept}\n\t\t \\begin{shortsolution}\n\t\t\t $\\left(0,\\frac{1}{6}\\right)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\\label{rat:prob:rational}\n\t\t What values of $x$ make the denominator equal to $0$?\n\t\t \\begin{shortsolution}\n\t\t\t $-3,4$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Use your answer to \\cref{rat:prob:rational} to write the domain of the function in\n\t\t both interval, and set builder notation. %\\index{rational functions!domain}\\index{domain!rational functions}\n\t\t \\begin{shortsolution}\n\t\t\t Interval notation: $(-\\infty,-3)\\cup (-3,4)\\cup (4,\\infty)$.\n\t\t\t Set builder: $\\{x|x\\ne -3, \\mathrm{and}\\, x\\ne 4\\}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t What are the vertical asymptotes of the function? State your answers in\n\t\t the form $x=$\n\t\t \\begin{shortsolution}\n\t\t\t $x=-3$ and $x=4$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\\label{rat:prob:zeroes}\n\t\t What values of $x$ make the numerator equal to $0$?\n\t\t \\begin{shortsolution}\n\t\t\t $-2,1$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Use your answer to \\cref{rat:prob:zeroes} to write the horizontal intercepts of\n\t\t $r$ as ordered pairs.\n\t\t \\begin{shortsolution}\n\t\t\t $(-2,0)$ and $(1,0)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Holes]\n\t \\pccname{Josh} and \\pccname{Pedro} are discussing the function\n\t \\[\n\t\t r(x)=\\frac{x^2-1}{(x+3)(x-1)}\n\t \\]\n\t \\begin{subproblem}\n\t\t What is the domain of $r$?\n\t\t \\begin{shortsolution}\n\t\t\t The domain of $r$ is $(-\\infty,-3)\\cup(-3,1)\\cup(1,\\infty)$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Josh notices that the numerator can be factored- can you see how?\n\t\t \\begin{shortsolution}\n\t\t\t $(x^2-1)=(x-1)(x+1)$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Pedro asks, `Doesn't that just mean that\n\t\t \\[\n\t\t\t r(x)=\\frac{x+1}{x+3}\n\t\t \\]\n\t\t for all values of $x$?' Josh says, `Nearly\\ldots but not for all values of $x$'.\n\t\t What does Josh mean?\n\t\t \\begin{shortsolution}\n\t\t\t $r(x)=\\dfrac{x+1}{x+3}$ provided that $x\\ne -1$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Where does $r$ have vertical asymptotes, and where does it have holes?\n\t\t \\begin{shortsolution}\n\t\t\t The function $r$ has a vertical asymptote at $-3$, and a hole at $1$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Sketch a graph of $r$.\n\t\t \\begin{shortsolution}\n\t\t\t A graph of $r$ is shown below.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-8,-6,...,8},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-3.25]{(x+1)/(x+3)};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-2.75:10]{(x+1)/(x+3)};\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({-3},{x});\n\t\t\t\t\t \\addplot[holdot]coordinates{(1,0.5)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   July 2012\n\t %===================================\n\t \\begin{problem}[Function algebra]\n\t Let $r$ and $s$ be the rational functions that have formulas\n\t \\[\n\t\t r(x)=\\frac{2-x}{x+3}, \\qquad s(x)=\\frac{x^2}{x-4}\n\t \\]\n\t Evaluate each of the following (if possible).\n\t \\begin{multicols}{4}\n\t\t \\begin{subproblem}\n\t\t\t $(r+s)(5)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\frac{197}{8}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(r-s)(3)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $\\frac{53}{6}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $(r\\cdot s)(4)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t Undefined.\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t $\\left( \\frac{r}{s} \\right)(1)$\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-\\frac{3}{4}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   July 2012\n\t %===================================\n\t \\begin{problem}[Transformations: given the transformation, find the formula]\n\t Let $r$ be the rational function that has formula.\n\t \\[\n\t\t r(x)=\\frac{x+5}{2x-3}\n\t \\]\n\t In each of the following problems apply the given transformation to the function $r$ and\n\t write a formula for the transformed version of $r$.\n\t \\begin{multicols}{2}\n\t\t \\begin{subproblem}\n\t\t\t Shift $r$ to the right by $3$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r(x-3)=\\frac{x+2}{2x-9}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $r$ to the left by $4$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r(x+4)=\\frac{x+9}{2x+5}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $r$ up by $\\pi$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r(x)+\\pi=\\frac{x+5}{2x-3}+\\pi$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Shift $r$ down by $17$ units.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r(x)-17=\\frac{x+5}{2x-3}-17$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Reflect $r$ over the horizontal axis.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $-r(x)=-\\frac{x+5}{2x-3}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t\t \\begin{subproblem}\n\t\t\t Reflect $r$ over the vertical axis.\n\t\t\t \\begin{shortsolution}\n\t\t\t\t $r(-x)=\\frac{x-5}{2x+3}$\n\t\t\t \\end{shortsolution}\n\t\t \\end{subproblem}\n\t \\end{multicols}\n\t \\end{problem}\n\n\n\t %===================================\n\t %   Author: Hughes\n\t %   Date:   May 2011\n\t %===================================\n\t \\begin{problem}[Find a formula from a table]\\label{rat:prob:findformula}\n\t \\Crefrange{rat:tab:findformular}{rat:tab:findformulau} show values of rational functions $r$, $q$, $s$,\n\t and $t$. Assume that any values marked with an X are undefined.\n\n\t \\begin{table}[!htb]\n\t\t \\begin{widepage}\n\t\t \\centering\n\t\t \\caption{Tables for \\cref{rat:prob:findformula}}\n\t\t \\label{rat:tab:findformula}\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=r(x)$}\n\t\t\t \\label{rat:tab:findformular}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t $x$  & $y$                \\\\ \\afterheading\n\t\t\t\t $-4$ & $\\nicefrac{7}{2}$  \\\\\\normalline\n\t\t\t\t $-3$ & $-18$              \\\\\\normalline\n\t\t\t\t $-2$ & X                  \\\\\\normalline\n\t\t\t\t $-1$ & $-4$               \\\\\\normalline\n\t\t\t\t $0$  & $\\nicefrac{-3}{2}$ \\\\\\normalline\n\t\t\t\t $1$  & $\\nicefrac{-2}{3}$ \\\\\\normalline\n\t\t\t\t $2$  & $\\nicefrac{-1}{4}$ \\\\\\normalline\n\t\t\t\t $3$  & $0$                \\\\\\normalline\n\t\t\t\t $4$  & $\\nicefrac{1}{6}$  \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=s(x)$}\n\t\t\t \\label{rat:tab:findformulas}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t $x$  & $y$                 \\\\ \\afterheading\n\t\t\t\t $-4$ & $\\nicefrac{-2}{21}$ \\\\\\normalline\n\t\t\t\t $-3$ & $\\nicefrac{-1}{12}$ \\\\\\normalline\n\t\t\t\t $-2$ & $0$                 \\\\\\normalline\n\t\t\t\t $-1$ & X                   \\\\\\normalline\n\t\t\t\t $0$  & $\\nicefrac{-2}{3}$  \\\\\\normalline\n\t\t\t\t $1$  & $\\nicefrac{-3}{4}$  \\\\\\normalline\n\t\t\t\t $2$  & $\\nicefrac{-4}{3}$  \\\\\\normalline\n\t\t\t\t $3$  & X                   \\\\\\normalline\n\t\t\t\t $4$  & $\\nicefrac{6}{5}$   \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=t(x)$}\n\t\t\t \\label{rat:tab:findformulat}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t $x$  & $y$               \\\\ \\afterheading\n\t\t\t\t $-4$ & $\\nicefrac{3}{5}$ \\\\\\normalline\n\t\t\t\t $-3$ & $0$               \\\\\\normalline\n\t\t\t\t $-2$ & X                 \\\\\\normalline\n\t\t\t\t $-1$ & $3$               \\\\\\normalline\n\t\t\t\t $0$  & $3$               \\\\\\normalline\n\t\t\t\t $1$  & X                 \\\\\\normalline\n\t\t\t\t $2$  & $0$               \\\\\\normalline\n\t\t\t\t $3$  & $\\nicefrac{3}{5}$ \\\\\\normalline\n\t\t\t\t $4$  & $\\nicefrac{7}{9}$ \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\hfill\n\t\t \\begin{subtable}{.2\\textwidth}\n\t\t\t \\centering\n\t\t\t \\caption{$y=u(x)$}\n\t\t\t \\label{rat:tab:findformulau}\n\t\t\t \\begin{tabular}{rr}\n\t\t\t\t \\beforeheading\n\t\t\t\t $x$  & $y$                \\\\ \\afterheading\n\t\t\t\t $-4$ & $\\nicefrac{16}{7}$ \\\\\\normalline\n\t\t\t\t $-3$ & X                  \\\\\\normalline\n\t\t\t\t $-2$ & $-\\nicefrac{4}{5}$ \\\\\\normalline\n\t\t\t\t $-1$ & $-\\nicefrac{1}{8}$ \\\\\\normalline\n\t\t\t\t $0$  & $0$                \\\\\\normalline\n\t\t\t\t $1$  & $-\\nicefrac{1}{8}$ \\\\\\normalline\n\t\t\t\t $2$  & $-\\nicefrac{4}{5}$ \\\\\\normalline\n\t\t\t\t $3$  & X                  \\\\\\normalline\n\t\t\t\t $4$  & $\\nicefrac{16}{7}$ \\\\\\lastline\n\t\t\t \\end{tabular}\n\t\t \\end{subtable}\n\t\t \\end{widepage}\n\t \\end{table}\n\t \\begin{subproblem}\n\t\t Given that the formula for $r(x)$ has the form $r(x)=\\dfrac{x-A}{x-B}$, use \\cref{rat:tab:findformular}\n\t\t to find values of $A$ and $B$.\n\t\t \\begin{shortsolution}\n\t\t\t $A=3$ and $B=-2$, so $r(x)=\\dfrac{x-3}{x+2}$.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Check your formula by computing $r(x)$ at the values specified in the table.\n\t\t \\begin{shortsolution}\n\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t r(-4) & = \\frac{-4-3}{-4+2} \\\\\n\t\t\t\t\t       & = \\frac{7}{2}       \\\\\n\t\t\t\t \\end{aligned}$\n\n\t\t\t $r(-3)=\\ldots$ etc\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t The function $s$ in \\cref{rat:tab:findformulas} has two vertical asymptotes and one zero.\n\t\t Can you find a formula for $s(x)$?\n\t\t \\begin{shortsolution}\n\t\t\t $s(x)=\\dfrac{x+2}{(x-3)(x+1)}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Check your formula by computing $s(x)$ at the values specified in the table.\n\t\t \\begin{shortsolution}\n\t\t\t $\\begin{aligned}[t]\n\t\t\t\t\t s(-4) & =\\frac{-4+2}{(-4-3)(-4+1)} \\\\\n\t\t\t\t\t       & =-\\frac{2}{21}\n\t\t\t\t \\end{aligned}$\n\n\t\t\t $s(-3)=\\ldots$ etc\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Given that the formula for $t(x)$ has  the form $t(x)=\\dfrac{(x-A)(x-B)}{(x-C)(x-D)}$, use \\cref{rat:tab:findformulat} to find the\n\t\t values of $A$, $B$, $C$, and $D$; hence write a formula for $t(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $t(x)=\\dfrac{(x+3)(x-2)}{(x+2)(x+1)}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t Given that the formula for $u(x)$ has  the form $u(x)=\\dfrac{(x-A)^2}{(x-B)(x-C)}$, use \\cref{rat:tab:findformulau} to find the\n\t\t values of $A$, $B$, and $C$; hence write a formula for $u(x)$.\n\t\t \\begin{shortsolution}\n\t\t\t $u(x)=\\dfrac{x^2}{(x+3)(x-3)}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\end{problem}\n\t \\end{exercises}\n\n\\section{Graphing rational functions (horizontal asymptotes)}\n \\reformatstepslist{R} % the steps list should be R1, R2, \\ldots\n We studied rational functions in the previous section, but were\n not asked to graph them; in this section we will demonstrate the\n steps to be followed in order to sketch graphs of the functions.\n\n Remember from \\vref{rat:def:function} that rational functions have\n the form\n \\[\n\t r(x)=\\frac{p(x)}{q(x)}\n \\]\n In this section we will restrict attention to the case when\n \\[\n\t \\text{degree of }p\\leq \\text{degree of }q\n \\]\n Note that this necessarily means that each function that we consider\n in this section \\emph{will have a horizontal asymptote} (see \\vref{rat:def:longrun}).\n The cases in which the degree of $p$ is greater than the degree of $q$\n is covered in the next section.\n\n Before we begin, it is important to remember the following:\n \\begin{itemize}\n\t \\item Our sketches will give a good representation of the overall\n\t       shape of the graph, but until we have the tools of calculus (from MTH 251)\n\t       we can not find local minimums, local maximums, and inflection points algebraically. This\n\t       means that we will make our best guess as to where these points are.\n\t \\item We will not concern ourselves too much with the vertical scale (because of\n\t       our previous point)| we will, however, mark the vertical intercept (assuming there is one),\n\t       and any horizontal asymptotes.\n \\end{itemize}\n \\begin{pccspecialcomment}[Steps to follow when sketching rational functions]\\label{rat:def:stepsforsketch}\n\t \\begin{steps}\n\t\t \\item \\label{rat:step:first} Find all vertical asymptotes and holes, and mark them on the\n\t\t graph using dashed vertical lines and open circles $\\circ$ respectively.\n\t\t \\item Find any intercepts, and mark them using solid circles $\\bullet$;\n\t\t determine if the curve cuts the axis, or bounces off it at each zero.\n\t\t \\item Determine the behavior of the function around each asymptote| does\n\t\t it behave like $\\frac{1}{x}$ or $\\frac{1}{x^2}$?\n\t\t \\item \\label{rat:step:penultimate} Determine the long-run behavior of the function, and mark the horizontal\n\t\t asymptote using a dashed horizontal line.\n\t\t \\item \\label{rat:step:last}  Deduce the overall shape of the curve, and sketch it. If there isn't\n\t\t enough information from the previous steps, then construct a table of values\n\t\t including sample points from each branch.\n\t \\end{steps}\n\t Remember that until we have the tools of calculus, we won't be able to\n\t find the exact coordinates of local minimums, local maximums, and points\n\t of inflection.\n \\end{pccspecialcomment}\n\n The examples that follow show how \\crefrange{rat:step:first}{rat:step:last} can be\n applied to a variety of different rational functions.\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:1overxminus2p2}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $r$\n\t that has formula\n\t \\[\n\t\t r(x)=\\frac{1}{x-2}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $r$ has a vertical asymptote at $2$; $r$ does not have any holes. The curve of\n\t\t\t $r$ will have $2$ branches.\n\t\t\t \\item $r$ does not have any zeros since the numerator is never equal to $0$. The\n\t\t\t vertical intercept of $r$ is $\\left( 0,-\\frac{1}{2} \\right)$.\n\t\t\t \\item $r$ behaves like $\\frac{1}{x}$ around its vertical asymptote since $(x-2)$\n\t\t\t is raised to the power $1$.\n\t\t\t \\item Since the degree of the numerator is less than the degree of the denominator,\n\t\t\t according to \\vref{rat:def:longrun} the horizontal asymptote of $r$ has equation $y=0$.\n\t\t\t \\item We put the details we have obtained so far on \\cref{rat:fig:1overxminus2p1}. Notice\n\t\t\t that there is only one way to complete the graph, which we have done in \\cref{rat:fig:1overxminus2p2}.\n\t\t \\end{steps}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\begin{figure}[!htbp]\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-5:5]({2},{x});\n\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(0,-0.5)}node[axisnode,anchor=north east]{$\\left( 0,-\\frac{1}{2} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:1overxminus2p1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}[/pgf/declare function={f=1/(x-2);}]\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[pccplot] expression[domain=-5:1.8,samples=50]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=2.2:5]{f};\n\t\t\t\t \\addplot[asymptote,domain=-5:5]({2},{x});\n\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(0,-0.5)}node[axisnode,anchor=north east]{$\\left( 0,-\\frac{1}{2} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:1overxminus2p2}\n\t \\end{subfigure}%\n\t \\caption{$y=\\dfrac{1}{x-2}$}\n \\end{figure}\n\n The function $r$ in \\cref{rat:ex:1overxminus2p2} has a horizontal asymptote which has equation $y=0$.\n This asymptote lies on the horizontal axis, and you might (understandably) find it hard\n to distinguish between the two lines (\\cref{rat:fig:1overxminus2p2}). When faced\n with such a situation, it is perfectly acceptable to draw the horizontal axis\n as a dashed line| just make sure to label it correctly. We will demonstrate this\n in the next example.\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:1overxp1}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $v$\n\t that has formula\n\t \\[\n\t\t v(x)=\\frac{10}{x}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $v$ has a vertical asymptote at $0$. $v$ does not have\n\t\t\t any holes. The curve of $v$ will have $2$ branches.\n\t\t\t \\item $v$ does not have any zeros (since $10\\ne 0$). Furthermore, $v$\n\t\t\t does not have a vertical intercept since $v(0)$ is undefined.\n\t\t\t \\item $v$ behaves like $\\frac{1}{x}$ around its vertical asymptote.\n\t\t\t \\item $v$ has a horizontal asymptote with equation $y=0$.\n\t\t\t \\item We put the details we have obtained so far in \\cref{rat:fig:1overxp1}.\n\t\t\t We do not have enough information to sketch $v$ yet (because $v$ does\n\t\t\t not have any intercepts), so let's pick a sample\n\t\t\t point in either of the $2$ branches| it doesn't matter where our sample point\n\t\t\t is, because we know what the overall shape will be. Let's compute $v(2)$\n\t\t\t \\begin{align*}\n\t\t\t\t v(2) & =\\dfrac{10}{2} \\\\\n\t\t\t\t      & = 5\n\t\t\t \\end{align*}\n\t\t\t We therefore mark the point $(2,5)$ on \\cref{rat:fig:1overxp2}, and then complete the sketch using\n\t\t\t the details we found in the previous steps.\n\t\t \\end{steps}\n\n\t\t \\begin{figure}[!htbp]\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-5,5},\n\t\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t\t axis line style={color=white},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[asymptote,<->,domain=-10:10]({0},{x});\n\t\t\t\t\t\t \\addplot[asymptote,<->,domain=-10:10]({x},{0});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:1overxp1}\n\t\t\t \\end{subfigure}%\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=10/x;}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t\t\t xtick={-5,5},\n\t\t\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t\t\t axis line style={color=white},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-1]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=1:10]{f};\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(2,5)}node[axisnode,anchor=south west]{$(2,5)$};\n\t\t\t\t\t\t \\addplot[asymptote,<->,domain=-10:10]({0},{x});\n\t\t\t\t\t\t \\addplot[asymptote,<->,domain=-10:10]({x},{0});\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:1overxp2}\n\t\t\t \\end{subfigure}%\n\t\t\t \\caption{$y=\\dfrac{10}{x}$}\n\t\t \\end{figure}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:asympandholep1}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $u$\n\t that has formula\n\t \\[\n\t\t u(x)=\\frac{-4(x^2-9)}{x^2-8x+15}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item We begin by factoring both the numerator and denominator of $u$ to help\n\t\t\t us find any vertical asymptotes or holes\n\t\t\t \\begin{align*}\n\t\t\t\t u(x) & =\\frac{-4(x^2-9)}{x^2-8x+15}     \\\\\n\t\t\t\t      & =\\frac{-4(x+3)(x-3)}{(x-5)(x-3)} \\\\\n\t\t\t\t      & =\\frac{-4(x+3)}{x-5}\n\t\t\t \\end{align*}\n\t\t\t provided that $x\\ne 3$. Therefore $u$ has a vertical asymptote at $5$ and\n\t\t\t a hole at $3$. The curve of $u$ has $2$ branches.\n\t\t\t \\item $u$ has a simple zero at $-3$. The vertical intercept of $u$ is $\\left( 0,\\frac{12}{5} \\right)$.\n\t\t\t \\item $u$ behaves like $\\frac{1}{x}$ around its vertical asymptote at $4$.\n\t\t\t \\item Using \\vref{rat:def:longrun} the equation of the horizontal asymptote of $u$ is $y=-4$.\n\t\t\t \\item We put the details we have obtained so far on \\cref{rat:fig:1overxminus2p1}. Notice\n\t\t\t that there is only one way to complete the graph, which we have done in \\cref{rat:fig:1overxminus2p2}.\n\t\t \\end{steps}\n\n\t\t \\begin{figure}[!htbp]\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-20,ymax=20,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-10,10},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[asymptote,domain=-20:20]({4},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{-4});\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(0,2.4)}node[axisnode,anchor=south east]{$\\left( 0,\\frac{12}{5} \\right)$};\n\t\t\t\t\t\t \\addplot[holdot] coordinates{(3,12)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:asympandholep1}\n\t\t\t \\end{subfigure}%\n\t\t\t \\hfill\n\t\t\t \\begin{subfigure}{.45\\textwidth}\n\t\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=-4*(x+3)/(x-5);}]\n\t\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t\t ymin=-20,ymax=20,\n\t\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t\t ytick={-10,10},\n\t\t\t\t\t\t\t width=\\textwidth,\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:3.6666,samples=50]{f};\n\t\t\t\t\t\t \\addplot[pccplot] expression[domain=7:10]{f};\n\t\t\t\t\t\t \\addplot[asymptote,domain=-20:20]({5},{x});\n\t\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{-4});\n\t\t\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(0,2.4)}node[axisnode,anchor=south east]{$\\left( 0,\\frac{12}{5} \\right)$};\n\t\t\t\t\t\t \\addplot[holdot] coordinates{(3,12)};\n\t\t\t\t\t \\end{axis}\n\t\t\t\t \\end{tikzpicture}\n\t\t\t\t \\caption{}\n\t\t\t\t \\label{rat:fig:asympandholep2}\n\t\t\t \\end{subfigure}%\n\t\t\t \\caption{$y=\\dfrac{-4(x+3)}{x-5}$}\n\t\t \\end{figure}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\Cref{rat:ex:1overxminus2p2,rat:ex:1overxp1,rat:ex:asympandholep1} have focused on functions\n that only have one vertical asymptote; the remaining examples in this section\n concern functions that have more than one vertical asymptote. We will demonstrate\n that \\crefrange{rat:step:first}{rat:step:last} still apply.\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:sketchtwoasymp}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $w$\n\t that has formula\n\t \\[\n\t\t w(x)=\\frac{2(x+3)(x-5)}{(x+5)(x-4)}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $w$ has vertical asymptotes at $-5$ and $4$. $w$ does not have\n\t\t\t any holes. The curve of $w$ will have $3$ branches.\n\t\t\t \\item $w$ has simple zeros at $-3$ and $5$. The vertical intercept of $w$\n\t\t\t is $\\left( 0,\\frac{3}{2} \\right)$.\n\t\t\t \\item $w$ behaves like $\\frac{1}{x}$ around both of its vertical\n\t\t\t asymptotes.\n\t\t\t \\item The degree of the numerator of $w$ is $2$ and the degree of the\n\t\t\t denominator of $w$ is also $2$. Using the ratio of the leading coefficients\n\t\t\t of the numerator and denominator, we say that $w$ has a horizontal\n\t\t\t asymptote with equation $y=\\frac{2}{1}=2$.\n\t\t\t \\item We put the details we have obtained so far on \\cref{rat:fig:sketchtwoasymptp1}.\n\n\t\t\t The function $w$ is a little more complicated than the functions that\n\t\t\t we have considered in the previous examples because the curve has $3$\n\t\t\t branches. When graphing such functions, it is generally a good idea to start with the branch\n\t\t\t for which you have the most information| in this case, that is the \\emph{middle} branch\n\t\t\t on the interval $(-5,4)$.\n\n\t\t\t Once we have drawn the middle branch, there is only one way to complete the graph\n\t\t\t (because of our observations about the behavior of $w$ around its vertical asymptotes),\n\t\t\t which we have done in \\cref{rat:fig:sketchtwoasymptp2}.\n\t\t \\end{steps}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\begin{figure}[!htbp]\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(5,0)};\n\t\t\t\t \\addplot[soldot] coordinates{(0,1.5)}node[axisnode,anchor=north west]{$\\left( 0,\\frac{3}{2} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:sketchtwoasymptp1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}[/pgf/declare function={f=2*(x+3)*(x-5)/( (x+5)*(x-4));}]\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(5,0)};\n\t\t\t\t \\addplot[soldot] coordinates{(0,1.5)}node[axisnode,anchor=north west]{$\\left( 0,\\frac{3}{2} \\right)$};\n\t\t\t\t \\addplot[pccplot] expression[domain=-10:-5.56708]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=-4.63511:3.81708]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=4.13511:10]{f};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:sketchtwoasymptp2}\n\t \\end{subfigure}%\n\t \\caption{$y=\\dfrac{2(x+3)(x-5)}{(x+5)(x-4)}$}\n \\end{figure}\n\n The rational functions that we have considered so far have had simple\n factors in the denominator; each function has behaved like $\\frac{1}{x}$\n around each of its vertical asymptotes. \\Cref{rat:ex:2asympnozeros,rat:ex:2squaredasymp}\n consider functions that have a repeated factor in the denominator.\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:2asympnozeros}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $f$\n\t that has formula\n\t \\[\n\t\t f(x)=\\frac{100}{(x+5)(x-4)^2}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $f$ has vertical asymptotes at $-5$ and $4$. $f$ does not have\n\t\t\t any holes. The curve of $f$ will have $3$ branches.\n\t\t\t \\item $f$ does not have any zeros (since $100\\ne 0$). The vertical intercept of $f$\n\t\t\t is $\\left( 0,\\frac{5}{4} \\right)$.\n\t\t\t \\item $f$ behaves like $\\frac{1}{x}$ around $-5$ and behaves like $\\frac{1}{x^2}$\n\t\t\t around $4$.\n\t\t\t \\item The degree of the numerator of $f$ is $0$ and the degree of the\n\t\t\t denominator of $f$ is $2$. $f$ has a horizontal asymptote with\n\t\t\t equation $y=0$.\n\t\t\t \\item We put the details we have obtained so far on \\cref{rat:fig:2asympnozerosp1}.\n\n\t\t\t The function $f$ is similar to the function $w$ that we considered in \\cref{rat:ex:sketchtwoasymp}|\n\t\t\t it has two vertical asymptotes and $3$ branches, but in contrast to $w$ it does not have any zeros.\n\n\t\t\t We sketch $f$ in \\cref{rat:fig:2asympnozerosp2}, using the middle branch as our guide\n\t\t\t because we have the most information about the function on the interval $(-5,4)$.\n\n\t\t\t Once we have drawn the middle branch, there is only one way to complete the graph\n\t\t\t because of our observations about the behavior of $f$ around its vertical asymptotes (it behaves like $\\frac{1}{x}$),\n\t\t\t which we have done in \\cref{rat:fig:2asympnozerosp2}.\n\n\t\t\t Note that we are not yet able to find the local minimum of $f$ algebraically on the interval $(-5,4)$,\n\t\t\t so we make a reasonable guess as to where it is| we can be confident that it is above the horizontal axis\n\t\t\t since $f$ has no zeros. You may think that this is unsatisfactory, but once we have the tools of calculus, we will\n\t\t\t be able to find local minimums more precisely.\n\t\t \\end{steps}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\begin{figure}[!htbp]\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(0,1.25)}node[axisnode,anchor=south east]{$\\left( 0,\\frac{5}{4} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:2asympnozerosp1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}[/pgf/declare function={f=100/( (x+5)*(x-4)^2);}]\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(0,1.25)}node[axisnode,anchor=south east]{$\\left( 0,\\frac{5}{4} \\right)$};\n\t\t\t\t \\addplot[pccplot] expression[domain=-10:-5.12022]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=-4.87298:2.87298,samples=50]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=5:10]{f};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:2asympnozerosp2}\n\t \\end{subfigure}%\n\t \\caption{$y=\\dfrac{100}{(x+5)(x-4)^2}$}\n \\end{figure}\n\n %===================================\n %   Author: Hughes\n %   Date:   May 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:2squaredasymp}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $g$\n\t that has formula\n\t \\[\n\t\t g(x)=\\frac{50(2-x)}{(x+3)^2(x-5)^2}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $g$ has vertical asymptotes at $-3$ and $5$. $g$ does\n\t\t\t not have any holes. The curve of $g$ will have $3$ branches.\n\t\t\t \\item $g$ has a simple zero at $2$. The vertical intercept of $g$ is\n\t\t\t $\\left( 0,\\frac{4}{9} \\right)$.\n\t\t\t \\item $g$ behaves like $\\frac{1}{x^2}$ around both of its\n\t\t\t vertical asymptotes.\n\t\t\t \\item The degree of the numerator of $g$ is $1$ and the degree of the denominator\n\t\t\t of $g$ is $4$. Using \\vref{rat:def:longrun}, we calculate that\n\t\t\t the horizontal asymptote of $g$ has equation $y=0$.\n\t\t\t \\item The details that we have found so far have been drawn in\n\t\t\t \\cref{rat:fig:2squaredasymp1}. The function $g$ is similar to the functions\n\t\t\t we considered in \\cref{rat:ex:sketchtwoasymp,rat:ex:2asympnozeros} because\n\t\t\t it has $2$ vertical asymptotes and $3$ branches.\n\n\t\t\t We sketch $g$ using the middle branch as our guide because we have the most information\n\t\t\t about $g$ on the interval $(-3,5)$. Note that there is no other way to draw this branch\n\t\t\t without introducing other zeros which $g$ does not have.\n\n\t\t\t Once we have drawn the middle branch, there is only one way to complete the graph\n\t\t\t because of our observations about the behavior of $g$ around its vertical asymptotes| it\n\t\t\t behaves like $\\frac{1}{x^2}$.\n\n\t\t \\end{steps}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\begin{figure}[!htbp]\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-3},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(2,0)(0,4/9)}node[axisnode,anchor=south west]{$\\left( 0,\\frac{4}{9} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:2squaredasymp1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}[/pgf/declare function={f=50*(2-x)/( (x+3)^2*(x-5)^2);}]\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-5,5},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-3},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{0});\n\t\t\t\t \\addplot[soldot] coordinates{(2,0)(0,4/9)}node[axisnode,anchor=south west]{$\\left( 0,\\frac{4}{9} \\right)$};\n\t\t\t\t \\addplot[pccplot] expression[domain=-10:-3.61504]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=-2.3657:4.52773]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=5.49205:10]{f};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:2squaredasymp2}\n\t \\end{subfigure}%\n\t \\caption{$y=\\dfrac{50(2-x)}{(x+3)^2(x-5)^2}$}\n \\end{figure}\n\n Each of the rational functions that we have considered so far has had either\n a \\emph{simple} zero, or no zeros at all. Remember from our work on polynomial\n functions, and particularly \\vref{poly:def:multzero}, that a \\emph{repeated} zero\n corresponds to the curve of the function behaving differently at the zero\n when compared to how the curve behaves at a simple zero. \\Cref{rat:ex:doublezero} details a\n function that has a non-simple zero.\n\n %===================================\n %   Author: Hughes\n %   Date:   June 2012\n %===================================\n \\begin{pccexample}\\label{rat:ex:doublezero}\n\t Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of the function $g$\n\t that has formula\n\t \\[\n\t\t h(x)=\\frac{(x-3)^2}{(x+4)(x-6)}\n\t \\]\n\t \\begin{pccsolution}\n\t\t \\begin{steps}\n\t\t\t \\item $h$ has vertical asymptotes at $-4$ and $6$. $h$ does\n\t\t\t not have any holes. The curve of $h$ will have $3$ branches.\n\t\t\t \\item $h$ has a zero at $3$ that has \\emph{multiplicity $2$}.\n\t\t\t The vertical intercept of $h$ is\n\t\t\t $\\left( 0,-\\frac{3}{8} \\right)$.\n\t\t\t \\item $h$ behaves like $\\frac{1}{x}$ around both of its\n\t\t\t vertical asymptotes.\n\t\t\t \\item The degree of the numerator of $h$ is $2$ and the degree of the denominator\n\t\t\t of $h$ is $2$. Using \\vref{rat:def:longrun}, we calculate that\n\t\t\t the horizontal asymptote of $h$ has equation $y=1$.\n\t\t\t \\item The details that we have found so far have been drawn in\n\t\t\t \\cref{rat:fig:doublezerop1}. The function $h$ is different\n\t\t\t from the functions that we have considered in previous examples because\n\t\t\t of the multiplicity of the zero at $3$.\n\n\t\t\t We sketch $h$ using the middle branch as our guide because we have the most information\n\t\t\t about $h$ on the interval $(-4,6)$. Note that there is no other way to draw this branch\n\t\t\t without introducing other zeros which $h$ does not have| also note how\n\t\t\t the curve bounces off the horizontal axis at $3$.\n\n\t\t\t Once we have drawn the middle branch, there is only one way to complete the graph\n\t\t\t because of our observations about the behavior of $h$ around its vertical asymptotes| it\n\t\t\t behaves like $\\frac{1}{x}$.\n\n\t\t \\end{steps}\n\t \\end{pccsolution}\n \\end{pccexample}\n\n \\begin{figure}[!htbp]\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-3,3},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({6},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{1});\n\t\t\t\t \\addplot[soldot] coordinates{(3,0)(0,-3/8)}node[axisnode,anchor=north west]{$\\left( 0,-\\frac{3}{8} \\right)$};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:doublezerop1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{.45\\textwidth}\n\t\t \\begin{tikzpicture}[/pgf/declare function={f=(x-3)^2/((x+4)*(x-6));}]\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t ytick={-3,3},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({6},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{1});\n\t\t\t\t \\addplot[soldot] coordinates{(3,0)(0,-3/8)}node[axisnode,anchor=north west]{$\\left( 0,-\\frac{3}{8} \\right)$};\n\t\t\t\t \\addplot[pccplot] expression[domain=-10:-5.20088]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=-3.16975:5.83642,samples=50]{f};\n\t\t\t\t \\addplot[pccplot] expression[domain=6.20088:10]{f};\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:doublezerop2}\n\t \\end{subfigure}%\n\t \\caption{$y=\\dfrac{(x-3)^2}{(x+4)(x-6)}$}\n \\end{figure}\n \\begin{exercises}\n %===================================\n %   Author: Hughes\n %   Date:   June 2012\n %===================================\n \\begin{problem}[\\Cref{rat:step:last}]\\label{rat:prob:deduce}\n \\pccname{Katie} is working on graphing rational functions. She\n has been concentrating on functions that have the form\n \\begin{equation}\\label{rat:eq:deducecurve}\n\t f(x)=\\frac{a(x-b)}{x-c}\n \\end{equation}\n Katie notes that functions with this type of formula have a zero\n at $b$, and a vertical asymptote at $c$. Furthermore, these functions\n behave like $\\frac{1}{x}$ around their vertical asymptote, and the\n curve of each function will have $2$ branches.\n\n Katie has been working with $3$ functions that have the form given\n in \\cref{rat:eq:deducecurve}, and has followed \\crefrange{rat:step:first}{rat:step:penultimate};\n her results are shown in \\cref{rat:fig:deducecurve}. There is just one\n more thing to do to complete the graphs| follow \\cref{rat:step:last}.\n Help Katie finish each graph by deducing the curve of each function.\n \\begin{shortsolution}\n\t \\Vref{rat:fig:deducecurve1}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=3*(x+4)/(x+5);}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(-4,0)(0,12/5)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{3});\n\t\t\t \\addplot[pccplot] expression[domain=-10:-5.42857]{f};\n\t\t\t \\addplot[pccplot] expression[domain=-4.76923:10,samples=50]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n\n\t \\Vref{rat:fig:deducecurve2}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=-3*(x-2)/(x-4);}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(2,0)(0,-3/2)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{-3});\n\t\t\t \\addplot[pccplot] expression[domain=-10:3.53846,samples=50]{f};\n\t\t\t \\addplot[pccplot] expression[domain=4.85714:10]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n\n\t \\Vref{rat:fig:deducecurve4}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=2*(x-6)/(x-4);}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(6,0)(0,3)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t \\addplot[pccplot] expression[domain=-10:3.5,samples=50]{f};\n\t\t\t \\addplot[pccplot] expression[domain=4.3333:10]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n \\end{shortsolution}\n \\end{problem}\n\n \\begin{figure}[!htb]\n\t \\begin{widepage}\n\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(-4,0)(0,12/5)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{3});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducecurve1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(2,0)(0,-3/2)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{-3});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducecurve2}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(6,0)(0,3)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducecurve4}\n\t \\end{subfigure}\n\t \\caption{Graphs for \\cref{rat:prob:deduce}}\n\t \\label{rat:fig:deducecurve}\n\t \\end{widepage}\n \\end{figure}\n\n %===================================\n %   Author: Hughes\n %   Date:   June 2012\n %===================================\n \\begin{problem}[\\Cref{rat:step:last} for  more complicated rational functions]\\label{rat:prob:deducehard}\n \\pccname{David} is also working on graphing rational functions, and\n has been concentrating on functions that have the form\n \\[\n\t r(x)=\\frac{a(x-b)(x-c)}{(x-d)(x-e)}\n \\]\n David notices that functions with this type of formula have simple zeros\n at $b$ and $c$, and vertical asymptotes at $d$ and $e$. Furthermore,\n these functions behave like $\\frac{1}{x}$ around both vertical asymptotes,\n and the curve of the function will have $3$ branches.\n\n David has followed \\crefrange{rat:step:first}{rat:step:penultimate} for\n $3$ separate functions, and drawn the results in \\cref{rat:fig:deducehard}.\n Help David finish each graph by deducing the curve of each function.\n \\begin{shortsolution}\n\t \\Vref{rat:fig:deducehard1}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=(x-6)*(x+3)/( (x-4)*(x+1));}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(-3,0)(6,0)(0,9/2)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({-1},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t \\addplot[pccplot] expression[domain=-10:-1.24276]{f};\n\t\t\t \\addplot[pccplot] expression[domain=-0.6666:3.66667]{f};\n\t\t\t \\addplot[pccplot] expression[domain=4.24276:10]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n\n\t \\Vref{rat:fig:deducehard2}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=3*(x-2)*(x+3)/( (x-6)*(x+5));}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(-3,0)(2,0)(0,3/5)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({6},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{3});\n\t\t\t \\addplot[pccplot] expression[domain=-10:-5.4861]{f};\n\t\t\t \\addplot[pccplot] expression[domain=-4.68395:5.22241]{f};\n\t\t\t \\addplot[pccplot] expression[domain=7.34324:10]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n\n\t \\Vref{rat:fig:deducehard3}\n\n\t \\begin{tikzpicture}[/pgf/declare function={f=2*(x-7)*(x+3)/( (x+6)*(x-5));}]\n\t\t \\begin{axis}[\n\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t ]\n\t\t\t \\addplot[soldot] coordinates{(-3,0)(7,0)(0,1.4)};\n\t\t\t \\addplot[asymptote,domain=-10:10]({-6},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({5},{x});\n\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t \\addplot[pccplot] expression[domain=-10:-6.91427]{f};\n\t\t\t \\addplot[pccplot] expression[domain=-5.42252:4.66427]{f};\n\t\t\t \\addplot[pccplot] expression[domain=5.25586:10]{f};\n\t\t \\end{axis}\n\t \\end{tikzpicture}\n\n \\end{shortsolution}\n \\end{problem}\n\n \\begin{figure}[!htb]\n\t \\begin{widepage}\n\t \\setlength{\\figurewidth}{0.3\\textwidth}\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(6,0)(0,9/2)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-1},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({4},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducehard1}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(2,0)(0,3/5)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({6},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{3});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducehard2}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\begin{subfigure}{\\figurewidth}\n\t\t \\begin{tikzpicture}\n\t\t\t \\begin{axis}[\n\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t ymin=-10,ymax=10,\n\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t width=\\textwidth,\n\t\t\t\t ]\n\t\t\t\t \\addplot[soldot] coordinates{(-3,0)(7,0)(0,1.4)};\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({-6},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({5},{x});\n\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{2});\n\t\t\t \\end{axis}\n\t\t \\end{tikzpicture}\n\t\t \\caption{}\n\t\t \\label{rat:fig:deducehard3}\n\t \\end{subfigure}%\n\t \\hfill\n\t \\caption{Graphs for \\cref{rat:prob:deducehard}}\n\t \\label{rat:fig:deducehard}\n\t \\end{widepage}\n \\end{figure}\n %===================================\n %   Author: Adams (Hughes)\n %   Date:   March 2012\n %===================================\n \\begin{problem}[\\Crefrange{rat:step:first}{rat:step:last}]\n Use \\crefrange{rat:step:first}{rat:step:last} to sketch a graph of\n each of the following functions\n \\fixthis{need 2 more subproblems here}\n \\begin{multicols}{4}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{4}{x+2}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept: $(0,2)$; vertical asymptote: $x=-2$, horizontal asymptote: $y=0$.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-2.8]{4/(x+2)};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-1.2:5]{4/(x+2)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(0,2)};\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({-2},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{0});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{2x-1}{x^2-9}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept:$\\left( 0,\\frac{1}{9} \\right)$;\n\t\t\t horizontal intercept: $\\left( \\frac{1}{2},0 \\right)$;\n\t\t\t vertical asymptotes: $x=-3$, $x=3$, horizontal asymptote: $y=0$.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-3.23974]{(2*x-1)/(x^2-9)};\n\t\t\t\t\t \\addplot[pccplot,samples=50] expression[domain=-2.77321:2.83974]{(2*x-1)/(x^2-9)};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.17321:5]{(2*x-1)/(x^2-9)};\n\t\t\t\t\t \\addplot[soldot]coordinates{(0,1/9)(1/2,0)};\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({-3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{0});\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{x+3}{x-5}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept $\\left( 0,-\\frac{3}{5} \\right)$; horizontal\n\t\t\t intercept: $(-3,0)$; vertical asymptote: $x=5$; horizontal asymptote: $y=1$.\n\n\t\t\t \\begin{tikzpicture}\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t minor ytick={-3,-1,...,3},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:3.666]{(x+3)/(x-5)};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=7:10]{(x+3)/(x-5)};\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({5},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{1});\n\t\t\t\t\t \\addplot[soldot]coordinates{(0,-3/5)(-3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{2x+3}{3x-1}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept: $(0,-3)$; horizontal intercept: $\\left( -\\frac{3}{2},0 \\right)$;\n\t\t\t vertical asymptote: $x=\\frac{1}{3}$, horizontal asymptote: $y=\\frac{2}{3}$.\n\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(2*x+3)/(3*x-1);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:0.1176]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=0.6153:5]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({1/3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{2/3});\n\t\t\t\t\t \\addplot[soldot]coordinates{(0,-3)(-3/2,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{4-x^2}{x^2-9}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept: $\\left( 0,-\\frac{4}{9} \\right)$;\n\t\t\t horizontal intercepts: $(2,0)$, $(-2,0)$;\n\t\t\t vertical asymptotes: $x=-3$, $x=3$; horizontal asymptote: $y=-1$.\n\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(4-x^2)/(x^2-9);}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-5,xmax=5,\n\t\t\t\t\t\t ymin=-5,ymax=5,\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-5:-3.20156]{f};\n\t\t\t\t\t \\addplot[pccplot,samples=50] expression[domain=-2.85774:2.85774]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=3.20156:5]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({-3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({3},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-5:5]({x},{-1});\n\t\t\t\t\t \\addplot[soldot] coordinates{(-2,0)(2,0)(0,-4/9)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $y=\\dfrac{(4x+5)(3x-4)}{(2x+5)(x-5)}$\n\t\t \\begin{shortsolution}\n\t\t\t Vertical intercept: $\\left( 0,\\frac{4}{5} \\right)$;\n\t\t\t horizontal intercepts: $\\left( -\\frac{5}{4},0 \\right)$, $\\left( \\frac{4}{3},0 \\right)$;\n\t\t\t vertical asymptotes: $x=-\\frac{5}{2}$, $x=5$; horizontal asymptote: $y=6$.\n\n\t\t\t \\begin{tikzpicture}[/pgf/declare function={f=(4*x+5)*(3*x-4)/((2*x+5)*(x-5));}]\n\t\t\t\t \\begin{axis}[\n\t\t\t\t\t\t framed,\n\t\t\t\t\t\t xmin=-10,xmax=10,\n\t\t\t\t\t\t ymin=-20,ymax=20,\n\t\t\t\t\t\t xtick={-8,-6,...,8},\n\t\t\t\t\t\t ytick={-10,0,...,10},\n\t\t\t\t\t\t minor ytick={-15,-5,...,15},\n\t\t\t\t\t\t grid=both,\n\t\t\t\t\t\t width=\\solutionfigurewidth,\n\t\t\t\t\t ]\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-10:-2.73416]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=-2.33689:4.2792]{f};\n\t\t\t\t\t \\addplot[pccplot] expression[domain=6.26988:10]{f};\n\t\t\t\t\t \\addplot[asymptote,domain=-20:20]({-5/2},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-20:20]({5},{x});\n\t\t\t\t\t \\addplot[asymptote,domain=-10:10]({x},{6});\n\t\t\t\t\t \\addplot[soldot]coordinates{(0,4/5)(-5/4,0)(4/3,0)};\n\t\t\t\t \\end{axis}\n\t\t\t \\end{tikzpicture}\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n \\end{multicols}\n \\end{problem}\n %===================================\n %   Author: Hughes\n %   Date:   March 2012\n %===================================\n \\begin{problem}[Inverse functions]\n Each of the following rational functions are invertible\n \\[\n\t F(x)=\\frac{2x+1}{x-3}, \\qquad G(x)= \\frac{1-4x}{x+3}\n \\]\n \\begin{subproblem}\n\t State the domain of each function.\n\t \\begin{shortsolution}\n\t\t \\begin{itemize}\n\t\t\t \\item The domain of $F$ is $(-\\infty,3)\\cup(3,\\infty)$.\n\t\t\t \\item The domain of $G$ is $(-\\infty,-3)\\cup(-3,\\infty)$.\n\t\t \\end{itemize}\n\t \\end{shortsolution}\n \\end{subproblem}\n \\begin{subproblem}\n\t Find the inverse of each function, and state its domain.\n\t \\begin{shortsolution}\n\t\t \\begin{itemize}\n\t\t\t \\item $F^{-1}(x)=\\frac{3x+1}{x-2}$; the domain of $F^{-1}$ is $(-\\infty,2)\\cup(2,\\infty)$.\n\t\t\t \\item $G^{-1}(x)=\\frac{3x+1}{x+4}$; the domain of $G^{-1}$ is $(-\\infty,-4)\\cup(-4,\\infty)$.\n\t\t \\end{itemize}\n\t \\end{shortsolution}\n \\end{subproblem}\n \\begin{subproblem}\n\t Hence state the range of the original functions.\n\t \\begin{shortsolution}\n\t\t \\begin{itemize}\n\t\t\t \\item The range of $F$ is the domain of $F^{-1}$, which is $(-\\infty,2)\\cup(2,\\infty)$.\n\t\t\t \\item The range of $G$ is the domain of $G^{-1}$, which is $(-\\infty,-4)\\cup(-4,\\infty)$.\n\t\t \\end{itemize}\n\t \\end{shortsolution}\n \\end{subproblem}\n \\begin{subproblem}\n\t State the range of each inverse function.\n\t \\begin{shortsolution}\n\t\t \\begin{itemize}\n\t\t\t \\item The range of $F^{-1}$ is the domain of $F$, which is $(-\\infty,3)\\cup(3,\\infty)$.\n\t\t\t \\item The range of $G^{-1}$ is the domain of $G$, which is $(-\\infty,-3)\\cup(-3,\\infty)$.\n\t\t \\end{itemize}<++>\n\t \\end{shortsolution}\n \\end{subproblem}\n \\end{problem}\n %===================================\n %   Author: Hughes\n %   Date:   March 2012\n %===================================\n \\begin{problem}[Composition]\n Let $r$ and $s$ be the rational functions that have formulas\n \\[\n\t r(x)=\\frac{3}{x^2},\\qquad s(x)=\\frac{4-x}{x+5}\n \\]\n Evaluate each of the following.\n \\begin{multicols}{3}\n\t \\begin{subproblem}\n\t\t $(r\\circ s)(0)$\n\t\t \\begin{shortsolution}\n\t\t\t $\\frac{75}{16}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $(s\\circ r)(0)$\n\t\t \\begin{shortsolution}\n\t\t\t $(s\\circ r)(0)$ is undefined.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $(r\\circ s)(2)$\n\t\t \\begin{shortsolution}\n\t\t\t $\\frac{147}{4}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $(s\\circ r)(3)$\n\t\t \\begin{shortsolution}\n\t\t\t $192$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $(s\\circ r)(4)$\n\t\t \\begin{shortsolution}\n\t\t\t $(s\\circ r)(4)$ is undefined.\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $(s\\circ r)(x)$\n\t\t \\begin{shortsolution}\n\t\t\t $\\dfrac{4x^2-3}{1+5x^2}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n \\end{multicols}\n \\end{problem}\n %===================================\n %   Author: Hughes\n %   Date:   March 2012\n %===================================\n \\begin{problem}[Piecewise rational functions]\n The function $R$ has formula\n \\[\n\t R(x)=\n\t \\begin{dcases}\n\t\t \\frac{2}{x+3},    & x<-5     \\\\\n\t\t \\frac{x-4}{x-10}, & x\\geq -5\n\t \\end{dcases}\n \\]\n Evaluate each of the following.\n \\begin{multicols}{4}\n\t \\begin{subproblem}\n\t\t $R(-6)$\n\t\t \\begin{shortsolution}\n\t\t\t $-\\frac{2}{3}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $R(-5)$\n\t\t \\begin{shortsolution}\n\t\t\t $\\frac{3}{5}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $R(-3)$\n\t\t \\begin{shortsolution}\n\t\t\t $\\frac{7}{13}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n\t \\begin{subproblem}\n\t\t $R(5)$\n\t\t \\begin{shortsolution}\n\t\t\t $-\\frac{1}{5}$\n\t\t \\end{shortsolution}\n\t \\end{subproblem}\n \\end{multicols}\n \\begin{subproblem}\n\t What is the domain of $R$?\n\t \\begin{shortsolution}\n\t\t $(-\\infty,10)\\cup(10,\\infty)$\n\t \\end{shortsolution}\n \\end{subproblem}\n \\end{problem}\n \\end{exercises}\n\n\\section{Graphing rational functions (oblique asymptotes)}\\label{rat:sec:oblique}\n \\begin{subproblem}\n\t $y=\\dfrac{x^2+1}{x-4}$\n\t \\begin{shortsolution}\n\t\t \\begin{enumerate}\n\t\t\t \\item $\\left( 0,-\\frac{1}{4} \\right)$\n\t\t\t \\item Vertical asymptote: $x=4$.\n\t\t\t \\item A graph of the function is shown below\n\n\t\t\t       \\begin{tikzpicture}[/pgf/declare function={f=(x^2+1)/(x-4);}]\n\t\t\t\t       \\begin{axis}[\n\t\t\t\t\t\t       framed,\n\t\t\t\t\t\t       xmin=-20,xmax=20,\n\t\t\t\t\t\t       ymin=-30,ymax=30,\n\t\t\t\t\t\t       xtick={-10,10},\n\t\t\t\t\t\t       minor xtick={-15,-5,...,15},\n\t\t\t\t\t\t       minor ytick={-10,10},\n\t\t\t\t\t\t       grid=both,\n\t\t\t\t\t\t       width=\\solutionfigurewidth,\n\t\t\t\t\t       ]\n\t\t\t\t\t       \\addplot[pccplot,samples=50] expression[domain=-20:3.54724]{f};\n\t\t\t\t\t       \\addplot[pccplot,samples=50] expression[domain=4.80196:20]{f};\n\t\t\t\t\t       \\addplot[asymptote,domain=-30:30]({4},{x});\n\t\t\t\t       \\end{axis}\n\t\t\t       \\end{tikzpicture}\n\t\t \\end{enumerate}\n\t \\end{shortsolution}\n \\end{subproblem}\n \\begin{subproblem}\n\t $y=\\dfrac{x^3(x+3)}{x-5}$\n\t \\begin{shortsolution}\n\t\t \\begin{enumerate}\n\t\t\t \\item $(0,0)$, $(-3,0)$\n\t\t\t \\item Vertical asymptote: $x=5$, horizontal asymptote: none.\n\t\t\t \\item A graph of the function is shown below\n\n\t\t\t       \\begin{tikzpicture}[/pgf/declare function={f=x^3*(x+3)/(x-5);}]\n\t\t\t\t       \\begin{axis}[\n\t\t\t\t\t\t       framed,\n\t\t\t\t\t\t       xmin=-10,xmax=10,\n\t\t\t\t\t\t       ymin=-500,ymax=2500,\n\t\t\t\t\t\t       xtick={-8,-6,...,8},\n\t\t\t\t\t\t       ytick={500,1000,1500,2000},\n\t\t\t\t\t\t       grid=both,\n\t\t\t\t\t\t       width=\\solutionfigurewidth,\n\t\t\t\t\t       ]\n\t\t\t\t\t       \\addplot[pccplot,samples=50] expression[domain=-10:4]{f};\n\t\t\t\t\t       \\addplot[pccplot] expression[domain=5.6068:9.777]{f};\n\t\t\t\t\t       \\addplot[asymptote,domain=-500:2500]({5},{x});\n\t\t\t\t       \\end{axis}\n\t\t\t       \\end{tikzpicture}\n\t\t \\end{enumerate}\n\t \\end{shortsolution}\n \\end{subproblem}\n", "meta": {"hexsha": "7b01acc3d65c9e6d631171350f1415c550369d28", "size": 205189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-default.tex", "max_stars_repo_name": "digorithm/latex-linter", "max_stars_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_stars_repo_licenses": ["MIT"], "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/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-default.tex", "max_issues_repo_name": "digorithm/latex-linter", "max_issues_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_issues_repo_licenses": ["MIT"], "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/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-default.tex", "max_forks_repo_name": "digorithm/latex-linter", "max_forks_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_forks_repo_licenses": ["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.2558419244, "max_line_length": 163, "alphanum_fraction": 0.5875217482, "num_tokens": 69383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6239804401424772}}
{"text": "\\documentclass[11pt]{article}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Packages\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\usepackage{oke-header-math}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Mathematics\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\newcommand{\\vbf}{\\boldsymbol{v}}\n\\newcommand{\\hbf}{\\boldsymbol{h}}\n\\newcommand{\\abf}{\\boldsymbol{a}}\n\\newcommand{\\bbf}{\\boldsymbol{b}}\n\\newcommand{\\Vbf}{\\boldsymbol{V}}\n\\newcommand{\\Hbf}{\\boldsymbol{H}}\n\\newcommand{\\qt}{\\tilde{q}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Title\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\title{RBMs}\n\\author{Oliver K. Ernst}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Begin document\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Theory}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\nThe objective function is the KL divergence:\n%---------------\n\\begin{equation}\n\\dkl (p || \\pt) = \\int dx \\; p(x) \\ln \\frac{p(x)}{\\pt(x, \\nu)}\n\\end{equation}\n%---------------\nwhere $p(x)$ is the true data distribution and $\\pt(x,\\nu)$ is the model distribution:\n%---------------\n\\begin{equation}\n\\begin{split}\n\\pt(x,\\nu) &= \\frac{1}{Z(\\nu)} \\exp [ - E(x, \\nu) ] \\\\\nZ(\\nu) &= \\int dy \\; \\exp [ - E(y, \\nu) ]\n\\end{split}\n\\end{equation}\n%---------------\nfor some energy function $E(x,\\nu)$ with interactions $\\nu$. The gradients are\n%---------------\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial \\dkl}{\\partial \\nu} \n&=\n- \\int dx \\; p(x) \\left ( \\frac{\\pt(x,\\nu)}{p(x)} \\right ) p(x) \\left ( \\pt(x,\\nu) \\right )^{-2} \\frac{\\partial \\pt(x,\\nu)}{\\partial \\nu}\n=\n- \\int dx \\; \\frac{p(x)}{\\pt(x,\\nu)} \\frac{\\partial \\pt(x,\\nu)}{\\partial \\nu} \\\\\n%%%%\n\\frac{\\partial \\pt(x,\\nu)}{\\partial \\nu}\n&=\n- \\frac{\\partial E(x,\\nu)}{\\partial \\nu} \\pt(x, \\nu) - \\frac{1}{Z(\\nu)^2} \\exp[-E(x,\\nu)] \\frac{\\partial Z(\\nu)}{\\partial \\nu} \\\\\n&=\n- \\frac{\\partial E(x,\\nu)}{\\partial \\nu} \\pt(x, \\nu) + \\frac{1}{Z(\\nu)} \\pt(x,\\nu) \\int dy \\; \\frac{\\partial E(y,\\nu)}{\\partial \\nu} \\exp[-E(y,\\nu)] \\\\\n&=\n- \\frac{\\partial E(x,\\nu)}{\\partial \\nu} \\pt(x, \\nu) + \\pt(x,\\nu) \\int dy \\; \\frac{\\partial E(y,\\nu)}{\\partial \\nu} \\pt(y,\\nu) \\\\\n&=\n- \\frac{\\partial E(x,\\nu)}{\\partial \\nu} \\pt(x, \\nu) + \\pt(x,\\nu) \\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_{\\pt} \\\\\n%%%%\n\\frac{\\partial \\dkl}{\\partial \\nu} \n&=\n\\int dx \\; \\frac{p(x)}{\\pt(x,\\nu)} \\frac{\\partial E(x,\\nu)}{\\partial \\nu} \\pt(x, \\nu)\n- \\int dx \\; \\frac{p(x)}{\\pt(x,\\nu)} \\pt(x,\\nu) \\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_{\\pt} \\\\\n&=\n\\int dx \\; p(x) \\frac{\\partial E(x,\\nu)}{\\partial \\nu}\n- \\int dx \\; p(x) \\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_{\\pt} \\\\\n&=\n\\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_p\n- \\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_{\\pt}\n\\end{split}\n\\end{equation}\n%---------------\nwhere the second integral is unity because $p$ is normalized by definition.\n%---------------\n\\begin{equation}\n\\boxed{\n\\frac{\\partial \\dkl}{\\partial \\nu} \n=\n\\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_p\n- \\left \\langle \\frac{\\partial E}{\\partial \\nu} \\right \\rangle_{\\pt}\n}\n\\end{equation}\n%---------------\nThe first term is often called the \\textit{awake phase} moment, or moment under the \\textit{data distribution} $p$; the second term is often called the \\textit{asleep phase} moment, or moment under the \\textit{model distribution} $\\pt$.\n\nFor the discrete case on a lattice with visible units $\\vbf$ and hidden units $\\hbf$:\n%---------------\n\\begin{equation}\n\\dkl (p || \\pt) = \\sum_{\\vbf} \\sum_{\\hbf} p(\\vbf, \\hbf) \\ln \\frac{p(\\vbf, \\hbf)}{\\pt(\\vbf,\\hbf)}\n\\end{equation}\n%---------------\nand a common energy function is:\n%---------------\n\\begin{equation}\n\\begin{split}\nE(\\vbf, \\hbf) = - \\abf^\\intercal \\vbf - \\bbf^\\intercal \\hbf - \\vbf^\\intercal W \\hbf\n\\end{split}\n\\end{equation}\n%---------------\nfor biases $\\abf,\\bbf$ and weight matrix $W$, which play the role of $\\nu$. The gradients are:\n%---------------\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial E}{\\partial \\abf} &= - \\vbf \\\\\n\\frac{\\partial E}{\\partial \\bbf} &= - \\hbf \\\\\n\\frac{\\partial E}{\\partial W} &= - \\vbf \\otimes \\hbf\n\\end{split}\n\\end{equation}\n%---------------\nleading to the gradients:\n%---------------\n\\begin{equation}\n\\boxed{\n\\begin{split}\n\\frac{\\partial \\dkl}{\\partial \\abf} \n&=\n\\left \\langle \\vbf \\right \\rangle_{\\pt}\n- \\left \\langle \\vbf \\right \\rangle_p \\\\\n%%%\n\\frac{\\partial \\dkl}{\\partial \\bbf} \n&=\n\\left \\langle \\hbf \\right \\rangle_{\\pt}\n- \\left \\langle \\hbf \\right \\rangle_p \\\\\n%%%\n\\frac{\\partial \\dkl}{\\partial W} \n&=\n\\left \\langle \\vbf \\otimes \\hbf \\right \\rangle_{\\pt}\n- \\left \\langle \\vbf \\otimes \\hbf \\right \\rangle_p \n\\end{split}\n}\n\\end{equation}\n%---------------\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Implementation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\n\\subsection{Gradients}\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\n\nIn practice, concerning the moments $\\langle \\dots \\rangle$:\n\\begin{itemize}\n\\item In the continuous case, we usually cannot analytically perform the integral $\\int dx$.\n\\item In the discrete case, we usually cannot enumerate all possible states appearing in the sum $\\sum_x$.\n\\end{itemize}\nTherefore, these moments are estimated using batches. In the continuous case, let the batch be $X_{\\pt}$ of size $N$, typically small ($N\\sim 5 -10$). For some observable $\\chi(x)$:\n%---------------\n\\begin{equation}\n\\langle \\chi(x) \\rangle_{\\pt} = \\int dx \\; \\pt(x, \\nu) \\chi(x) \\sim \\frac{1}{N} \\sum_{i=1}^N \\chi(X_{\\pt,i})\n\\end{equation}\n%---------------\nand similarly for moments with respect to $p$. In the discrete case, with the batch represented as $\\Vbf_{\\pt}, \\Hbf_{\\pt}$:\n%---------------\n\\begin{equation}\n\\langle \\chi(\\vbf, \\hbf) \\rangle_{\\pt} = \\sum_{\\vbf} \\sum_{\\hbf} \\; \\pt(\\vbf, \\hbf) \\chi(\\vbf, \\hbf) \\sim \\frac{1}{N} \\sum_{i=1}^N \\chi(\\Vbf_{\\pt,i}, \\Hbf_{\\pt,i} )\n\\end{equation}\n%---------------\n\nThe gradients are therefore estimated as:\n%---------------\n\\begin{equation}\n\\boxed{\n\\begin{split}\n\\frac{\\partial \\dkl}{\\partial \\abf} \n&=\n\\frac{1}{N} \\sum_{i=1}^N \\Vbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Vbf_{p, i} \\\\\n%%%\n\\frac{\\partial \\dkl}{\\partial \\bbf} \n&=\n\\frac{1}{N} \\sum_{i=1}^N \\Hbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Hbf_{p, i} \\\\\n%%%\n\\frac{\\partial \\dkl}{\\partial W} \n&=\n\\frac{1}{N} \\sum_{i=1}^N \\Vbf_{\\pt, i} \\otimes \\Hbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Vbf_{p, i} \\otimes \\Hbf_{p, i}\n\\end{split}\n}\n\\label{eq:grads}\n\\end{equation}\n%---------------\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\n\\subsection{Sampling}\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\n\nWhere do such batches come from? They should be samples of the distributions $p$ or $\\pt$ as appropriate.\n\\begin{itemize}\n\\item For sampling the model distribution $\\pt$, we have several options:\n\\begin{itemize}\n\\item In the continuous case, without knowing further about $\\pt(x)$, we can always perform Markov Chain Monte Carlo (MCMC) to sample the distributions (other sampling methods \\textit{may} be possible).\n\\item In the discrete case, we can use \\textit{Gibbs sampling}, which works by iteratively sampling $\\pt(v_i | \\hbf)$ and $\\pt(h_i | \\vbf)$. These are derived as follows:\n%---------------\n\\begin{equation}\n\\begin{split}\n\\pt(h_i | \\vbf) &= \\frac{\\pt(h_i, \\vbf)}{\\pt(\\vbf)} \\\\\n\\pt(\\vbf) &= \\sum_{\\hbf} \\pt(\\vbf,\\hbf) \\propto \\exp [ \\abf^\\intercal \\vbf ] \\\\\n\\pt(\\hbf, \\vbf) &= \\prod_i \\pt(h_i, \\vbf)\n\\end{split}\n\\end{equation}\n%---------------\nwhere the last line follows because in an RBM, the hidden variables are conditionally independent of all other hidden variables, and similarly for visible-visibles, then:\n%---------------\n\\begin{equation}\n\\begin{split}\n\\pt(h_i, \\vbf) \\propto \\exp [ \\abf^\\intercal \\vbf + b_i h_i + \\vbf^\\intercal \\text{col}_i(W) h_i ]\n\\end{split}\n\\end{equation}\n%---------------\nthen it follows:\n%---------------\n\\begin{equation}\n\\boxed{\n\\pt(h_i | \\vbf) \\propto \\exp [ b_i h_i + \\vbf^\\intercal \\text{col}_i(W) h_i ]\n}\n\\end{equation}\n%---------------\nand similarly\n%---------------\n\\begin{equation}\n\\boxed{\n\\pt(v_i | \\hbf) \\propto \\exp [ a_i v_i + v_i \\text{row}_i(W) \\hbf ]\n}\n\\end{equation}\n%---------------\nIn \\textit{contrastive divergence}, this procedure of iteratively sampling $\\pt(v_i | \\hbf)$ and $\\pt(h_i | \\vbf)$ is performed only a few times (or even only once!), starting from an initial data vector $\\vbf$. This greatly improves computational efficiency; alternatively, you can run this sampler for a long time to let the \\textit{chain converge}.\n\nAfter sampling, we obtain the desired samples for the batch $\\Vbf_{\\pt,i}, \\Hbf_{\\pt,i}$. The sampling can be performed in \\textit{parallel} for higher efficiency, evaluating all $N$ items in the batch $\\Vbf_{\\pt}, \\Hbf_{\\pt}$.\n\nIn \\textit{persistent contrastive divergence}, we do not throw out the hidden states $\\Vbf_{\\pt}, \\Hbf_{\\pt}$ after one gradient step and restart from new data vectors $\\vbf$. Instead, we keep these states, and use them in the next gradient step again as the starting point for sampling $\\pt(v_i | \\hbf)$ and $\\pt(h_i | \\vbf)$ for a few more steps.\n\n\\item The samples $\\Vbf_p$ from the data distribution $p$ are obvious; they are provided as training data. The samples $\\Hbf_p$ are obtained by \\textit{clamping the visible units to the data vectors $\\Vbf_p$} and sampling \\textit{only} $\\pt(h_i | \\vbf)$. Note that this is similarly possible with MCMC for the general continuous case; assuming we partition $x$ into observed and latent variables, we can sample only the latent variables, keeping the observed variables clamped.\n\n\\end{itemize} \n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\n\\subsection{Objective function}\n\n%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%\n\nIt would be great if we could code up the objective function $\\dkl$ onto a computer, but this is \\textbf{not trivial}. Instead, we can make an important restriction:\n%---------------\n\\begin{equation*}\n\\text{Assume that our \\textbf{optimizer only uses first-order gradients.}}\n\\end{equation*}\n%---------------\n\\textbf{If} we make this restriction, we can consider the following objective function\n%---------------\n\\begin{equation}\n\\begin{split}\nS\n=&\n\\abf^\\intercal \\left ( \n\\frac{1}{N} \\sum_{i=1}^N \\Vbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Vbf_{p, i}\n\\right ) \\\\\n%%%\n& +\n\\bbf^\\intercal \\left ( \n\\frac{1}{N} \\sum_{i=1}^N \\Hbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Hbf_{p, i} \n\\right ) \\\\\n%%%\n& +\n\\left (\n\\frac{1}{N} \\sum_{i=1}^N \\Vbf_{\\pt, i}^\\intercal W \\Hbf_{\\pt, i}\n- \\frac{1}{N} \\sum_{i=1}^N \\Vbf_{p, i}^\\intercal W \\Hbf_{p, i}\n\\right )\n\\end{split}\n\\end{equation}\n%---------------\nwhich has the same \\textbf{first-order} gradients as~(\\ref{eq:grads}). \n\n\\textbf{Note that the second-order gradients will obviously be incorrect!}\n\nThis trick allows us to easily implement an RBM in TensorFlow.\n\n\n\\end{document}", "meta": {"hexsha": "c4bd6f568fdfd0150e5adb006ee12b3ec9a44a27", "size": 11317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/rbms.tex", "max_stars_repo_name": "smrfeld/rbm-tensorflow-2", "max_stars_repo_head_hexsha": "6b6b8dccc2dfdca458efc20c3514db6d67f809ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-12T09:44:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-12T09:44:22.000Z", "max_issues_repo_path": "docs/rbms.tex", "max_issues_repo_name": "smrfeld/rbm-tensorflow-2", "max_issues_repo_head_hexsha": "6b6b8dccc2dfdca458efc20c3514db6d67f809ae", "max_issues_repo_licenses": ["MIT"], "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/rbms.tex", "max_forks_repo_name": "smrfeld/rbm-tensorflow-2", "max_forks_repo_head_hexsha": "6b6b8dccc2dfdca458efc20c3514db6d67f809ae", "max_forks_repo_licenses": ["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.4764890282, "max_line_length": 477, "alphanum_fraction": 0.559070425, "num_tokens": 3523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6239804386236526}}
{"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 11}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 4b.1}\n\\begin{align*}\nF &= \\frac{n-p}{q}\\frac{(Y-c1_n)'(P-P_H)(Y-c1_n)}{(Y-c1_n)'(I_n-P)(Y-c1_n)}\\\\\n\\end{align*}\n\nAlso, $X = \\begin{pmatrix} 1 & x_{1,1} & x_{1,2} & \\dots & x_{1,p-1}\\\\ \n1 & x_{2,1} & x_{2,2} & \\dots & x_{2,p-1}\\\\\n\\vdots & \\vdots & \\vdots \\\\\n1 & x_{n,1} & x_{n,2} & \\dots & x_{n,p-1}\\\\\n\\end{pmatrix}$\n\nThus, $1_n \\in \\mathcal{C}(X)$ and hence $(I-P)1_n = 1_n'(I-P) = (P-P_H)1_n = 1_n'(P-P_H) = 0$ \nand hence $(Y-c1_n)'(P-P_H)(Y-c1_n) = Y'(P-P_H)Y-c1_n'(P-P_H)Y+cY'(P-P_H)1_n+c^21_n'(P-P_H)1_n = Y'(P-P_H)Y$\n\nSimilarly $(Y-c1_n)'(I-P)(Y-c1_n) = Y'(I-P)Y$\nand hence $F$ statistic is the same as $F = \\frac{n-p}{q}\\frac{Y'(P-P_H)Y}{Y'(I_n-P)Y}$\n\n\n\n\n\\section*{Problem 4b.4}\n\n\\begin{align*}\n\\begin{pmatrix}\nY_1\\\\Y_2\\\\Y_3\n\\end{pmatrix} &= \\begin{pmatrix}\n1 & 1 \\\\\n0 & 2 \\\\\n-1 & 1\\\\\n\\end{pmatrix} \\begin{pmatrix}\\theta_1 \\\\ \\theta_2 \\end{pmatrix}+\\begin{pmatrix}\\epsilon_1\\\\ \\epsilon_2\\end{pmatrix}\\\\\n&= X\\beta+\\epsilon\\\\\nH:\\ \\theta_1 &= 2\\theta_2\\\\\n\\implies \\begin{pmatrix}1 & -2 \\end{pmatrix}\\\\\n&= A\\beta = 0\\\\\nF &= \\frac{\\frac{RSS_H-RSS}{q}}{\\frac{RSS}{n-p}}\\\\\n\\end{align*}\n\nNow,\n\\begin{align*}\n\\hat{\\beta} &= (X'X)^{-1}X'Y\\\\\nX'X = \\begin{pmatrix} 2 & 0\\\\\n0 & 6\n\\end{pmatrix}\\\\\n(X'X)^{-1} &= \\begin{pmatrix} 1/2 & 0\\\\\n0 & 1/6\n\\end{pmatrix}\\\\\n\\hat{\\beta} &= \\begin{pmatrix} 1/2 & 0\\\\ 0 & 1/6 \\end{pmatrix}\\begin{pmatrix}\\frac{Y_1-Y_3}{2}\\\\\n\\frac{Y_1+2Y_2+Y_3}{6}\n\\end{pmatrix}\\\\\n\\end{align*}\n\n\\begin{align*}\n\\hat{Y} &= X\\hat{\\beta}\\\\\n&= \\begin{pmatrix}\n1 & 1 \\\\\n0 & 2 \\\\\n-1 & 1\\\\\n\\end{pmatrix}\\begin{pmatrix}\\frac{3Y_1-3Y_3}{6}\\\\\n\\frac{Y_1+2Y_2+Y_3}{6}\n\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\n\\frac{4Y_1+2Y_2-2Y_3}{6}\\\\\n\\frac{Y_1+2Y_2+Y_3}{3}\\\\\n\\frac{-2Y_1+2Y_2+4Y_3}{6}\\\\\n\\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\nRSS &= (Y-\\hat{Y})'(Y-\\hat{Y})\\\\\n&= \\begin{pmatrix}\\frac{2Y_1-2Y_2+2Y_3}{6} &\n\\frac{-Y_1+Y_2-Y_3}{3} & \\frac{2Y_1-2Y_2+2Y_3}{6}\n\\end{pmatrix}'.\\begin{pmatrix}\\frac{2Y_1-2Y_2+2Y_3}{6} \\\\\n\\frac{4y_1-4Y_2-2Y_3}{6} \\\\ \\frac{2Y_1-2Y_2+2Y_3}{6}\n\\end{pmatrix}\\\\\n&= \\frac{1}{9}(Y_1-Y_2+Y_3)^2 + \\frac{1}{9}(-Y_1+Y_2-Y_3)^2 + \\frac{1}{9}(Y_1-Y_2+Y_3)^2\\\\\n&= \\frac{1}{3}(Y_1-Y_2+Y_3)^2\n\\end{align*}\n\n\\begin{align*}\nA(X'X)^{-1}A' &= \\begin{pmatrix}1/2 & -1/3 \\end{pmatrix}\\begin{pmatrix}\n1 \\\\ -2\n\\end{pmatrix}\\\\\n&= \\frac{7}{6}\\\\\nRSS_H-RSS &= [A\\hat{\\beta}]'[A(X'X)^{-1}A']^{-1}[A'\\hat{\\beta}]\\\\ \n&= \\frac{6}{7}(\\hat{\\beta_1}-2\\hat{\\beta_2})^2\n\\end{align*}\n\nThus,\n\\begin{align*}\nF &= \\frac{\\frac{6}{7}(\\hat{\\beta_1}-2\\hat{\\beta_2})^2}{\\frac{1}{3}(Y_1-Y_2+Y_3)^2}\n\\end{align*}\n\n\\section*{Problem 4b.5}\n$Y=I\\theta+\\epsilon$\n\n$H: \\theta_1 =\\theta_3 $ or $\\begin{pmatrix} 1 & 0 & -1 & 0 \\end{pmatrix}\\theta=0$\n\n\\begin{align*}\nA &= \\begin{pmatrix}\n1 & 0 & -1 & 0\n\\end{pmatrix}\\\\\n\\hat{\\beta} = \\begin{pmatrix}\nY_1\\\\\nY_2\\\\\nY_3\\\\\nY_4\n\\end{pmatrix}\\\\\nA\\beta &= \\begin{pmatrix} 1 & 0 & -1 & 0 \\end{pmatrix} \\begin{pmatrix}\nY_1\\\\Y_2\\\\Y_3\\\\Y_4\n\\end{pmatrix}\\\\\n&= Y_1-Y_3\\\\\nRSS_H-RSS &= \\begin{pmatrix} Y_1 & -Y_3 \\end{pmatrix}\\frac{1}{2}\\begin{pmatrix} Y_1 \\\\\n-Y_3\n\\end{pmatrix}\\\\\n&= \\frac{1}{2}(Y_1-Y_3)^2\\\\\nRSS = 3S^2\\\\\n&= 3(Y_1+Y_2+Y_3+Y_4-0)^2\\\\\nF &= \\frac{RSS_H-RSS}{3S^2}\\frac{3}{1}\\\\\n&= \\frac{(Y_1-Y_3)^2}{2(Y_1+Y_2+Y_3+Y_4)^2}\n\\end{align*}\n\n\\section*{Problem 4MISC.2}\n\\begin{align*}\n\\begin{pmatrix}\nY_{11}\\\\\nY_{12}\\\\\n\\vdots\\\\\nY_{1n}\\\\\nY_{21}\\\\\nY_{22}\n\\vdots\\\\\nY_{2n}\n\\end{pmatrix}&= \\begin{pmatrix}x_1 & 0\\\\\nx_2 & 0 \\\\\n\\vdots \\\\\nx_n & 0\\\\\n0 & x_1\\\\\n0 & x_2\\\\\n\\vdots\\\\\n0 & x_n\n\\end{pmatrix}\\begin{pmatrix}\\beta_1 \\\\ \\beta_2\\end{pmatrix} + \\epsilon\\\\\nH: A\\hat{\\beta} &=0 \\implies \\begin{pmatrix} 1 & -1 \\end{pmatrix} = 0\\\\\nA &= \\begin{pmatrix} 1 & -1 \\end{pmatrix}\\\\\nX'X^{-1} &= \\begin{pmatrix}\\frac{1}{\\sum_i x_i^2} & 0\\\\\n0 & \\frac{1}{\\sum_i x_i^2}\\end{pmatrix}\\\\\n\\hat{\\beta} &= (X'X)^{-1}X'Y\\\\\n&= \\begin{pmatrix}\\frac{1}{\\sum_i x_i^2} & 0\\\\\n0 & \\frac{1}{\\sum_i x_i^2}\\end{pmatrix}  \\begin{pmatrix}\\sum_ix_i y_{i1}\\\\ \\sum_i x_iy_{i2}\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\\frac{\\sum_ix_i y_{i1}}{\\sum_i x_i^2}\\\\ \\frac{\\sum_i x_iy_{i2}}{\\sum x_i^2}\\end{pmatrix}\\\\\n&= \\begin{pmatrix}\\hat{\\beta_1} \\\\ \\hat{\\beta_2}\\end{pmatrix}\\\\\nRSS &= \\sum_j\\sum_i(y_{ji}-x_{ji}\\beta_i)^2\\\\\n&= \\sum_i (y_{i1}^2-2y_{i1}x_i\\hat{\\beta_1} + x_{i1}^2\\beta_1^2 + y_{i2}^2-2y_{2i}x_i + x_{2i}\\beta_2^2)\\\\\nRSS_H-RSS &= (A\\beta)'[A'(X'X)^{-1}A]^{-1}(A\\beta)\\\\\n&= (\\hat{\\beta_1}-\\hat{\\beta_2}) [\\begin{pmatrix} \\frac{1}{\\sum_i x_i^2} & \\frac{-1}{\\sum_i{x_i^2}} \\end{pmatrix} \\begin{pmatrix} 1\\\\ -1\\end{pmatrix}]^{-1}\\begin{pmatrix}\\hat{\\beta_1} \\\\ -\\hat{\\beta_2}\\end{pmatrix}\\\\\n&= (n-1)S^2\nRSS_H-RSS &= (A\\hat{\\beta})'[A'(X'X)^{-1}A]^{-1}A\\hat{\\beta}\\\\\n&= \\frac{n}{n+1}(\\bar{Y_n}-Y_{n+1})^2\\\\\n&= \\sum_i x_i^2 \\frac{(\\hat{\\beta_1}-\\hat{\\beta_2})^2}{2}\\\\\nF &= \\frac{\\frac{RSS_H-RSS}{1}}{\\frac{(n-1)S^2}{n-1}}\\\\\n&= \\frac{\\sum_i x_i^2\\frac{(\\beta_1-\\beta_2)^2}{2}}{S^2}\\\\\n&= \\frac{(\\beta_1-\\beta_2)^2}{2S^2(\\sum_x x_i^2)^{-1}}\n\\end{align*}\n\n\\section*{Problem 4MISC.4}\n\\begin{align*}\n\\begin{pmatrix} \nY_1\\\\\nY_2\\\\\n\\vdots\\\\\nY_n\\\\\nY_{n+1}\n\\end{pmatrix}&= \\begin{pmatrix}\n1 & 0\\\\\n1 & 0\\\\\n\\vdots & \\vdots\\\\\n1 & 0\\\\\n0 & 1\n\\end{pmatrix}\\begin{pmatrix}\\mu_1 \\\\ \\mu_2\n\\end{pmatrix}+ \\begin{pmatrix} \\epsilon_1\\\\\n\\epsilon_2\\\\\n\\vdots\\\\\n\\epsilon_n\\\\\n\\epsilon_{n+1}\n\\end{pmatrix}\\\\\nH &:  A\\hat{\\beta} = 0 \\implies \\begin{pmatrix}1 & -1\\end{pmatrix}\\begin{pmatrix}\\mu_1\\\\\n\\mu_2\n\\end{pmatrix} = 0 \\\\\nX'X &= \\begin{pmatrix}n & 0 \\\\ 0 & 1 \\end{pmatrix}\\\\\n(X'X)^{-1} &= \\begin{pmatrix}1/n & 0 \\\\ 0 & 1 \\end{pmatrix}\\\\\n\\begin{pmatrix}\\hat{\\mu_1}\\\\\n\\hat{\\mu_2}\n\\end{pmatrix} &= \\begin{pmatrix}\\frac{1}{n}\\sum_{i=1}^nY_i\\\\\nY_{n+1}\n\\end{pmatrix} = \\begin{pmatrix} \\bar{Y_n} \\\\ Y_{n+1}\\end{pmatrix}\\\\ \n\\begin{pmatrix} \n\\hat{Y_1}\\\\\n\\hat{Y_2}\\\\\n\\vdots\\\\\n\\hat{Y_n}\\\\\n\\hat{Y_{n+1}}\n\\end{pmatrix}&= \\begin{pmatrix} \n\\bar{Y_n}\\\\\n\\bar{Y_2}\\\\\n\\vdots\\\\\n\\bar{Y_n}\\\\\n\\bar{Y_{n+1}}\n\\end{pmatrix}\\\\\nRSS &= (Y-\\hat{Y})'(Y-\\hat{Y})\\\\\n&= \\begin{pmatrix}Y_1-\\bar{Y_n} & Y_2-\\bar{Y_n} & \\dots Y_n-\\bar{Y_n}& 0 \\end{pmatrix}\\begin{pmatrix}Y_1-\\bar{Y_n} \\\\ Y_2-\\bar{Y_n} \\\\ \\vdots\\\\ Y_n-\\bar{Y_n} \\\\ 0 \\end{pmatrix}\\\\\n&= \\sum_{i=1}^n(Y_i-\\bar{Y_n})^2\\\\\n&= (n-1)S_n^2\\\\\nF &= \\frac{\\frac{RSS_H-RSS}{1}}{\\frac{RSS}{n+1-2}}\\\\\n&= \\frac{n}{n+1}\\frac{(Y_{n+1}-\\bar{Y_n})^2}{S_n^2}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "b3d8730d8ea85e2b4a317af8a5d0c24708094d85", "size": 6380, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW11/hw11.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/HW11/hw11.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/HW11/hw11.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": 27.8602620087, "max_line_length": 216, "alphanum_fraction": 0.5827586207, "num_tokens": 3359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.623980435833707}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{fullpage}\n\\usepackage{systeme}\n\\usepackage{blindtext}\n\\usepackage{graphicx}\n\\graphicspath{{./fig/}}\n\\setlength{\\parskip}{1em}\n% This gives us a full line break when we write a new paragraph\n\n\\title{MATH 308 Conceptual Problems, Week 4 \\vspace{1em}\\\\\\normalsize{SUPPLEMENTARY CONCEPTUAL PROBLEMS, 8d \\& 8e}}\n\\author{Jai Broome}\n\\date{28 January 2020}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question prompt}\n\nIn each of the following, $\\bar{x}$ is the vector whose components are the coefficients\nin $f(t)$, and $\\bar{y}$ is the vector whose components are the coefficients in $f'(t)$. Taking\nthe derivative of $f(t)$ in the usual way, you can find formulas for the $y$'s in terms\nof the $x$'s. Then find a matrix $A$ such that $\\bar{y}=A\\bar{x}$.\n\n\\section{8d}\n\\textit{Question prompt}: $f(t) = x_1\\sin(t) + x_2\\cos(t) + x_3t\\sin(t) + x_4t\\cos(t)$,\nand $f'(t)$ has the same form with coefficients $y_1$, $y_2$, $y_3$, $y_4$.\n\nThe reason we can approach this problem this way is because\n\\begin{itemize}\n  \\item we can differentiate $f(t)$ in its general form, \n    % that is, we don't need to know specific values for \\bar{x}\n  \\item and because the prompt tells us that $f'(t)$ will have a $\\sin(t)$ term,\n    a $\\cos(t)$ term, a $t\\sin(t)$ term and a $t\\cos(t)$ term.\n\\end{itemize}\n% could be any function g_i(t) that appears in the function and derivative\n% could be zeroes\n% and because we can tell by looking at each term\n\nThis second point means that the plot of $f'(t)$ will have some visual\nsimilarity to the plot of $f(t)$, since they're both composed of a series of\nthe same functions functions multiplied by constants. \\\\\n\nThe tricky thing about this type of problem is that $f(t)$ and it's derivatives are 1-dimensional\nmappings $\\mathbb{R} \\rightarrow \\mathbb{R}$; \\textit{however}, our goal here is to find a mapping\n$\\mathbb{R}^4 \\rightarrow \\mathbb{R}^4$ that takes our 4-dimensional $\\bar{x}$ and produces a\n4-dimensional $\\bar{y}$\n% the function takes one value $t$ and returns one value $f(t)$.\n\nFind the derivative the usual way, treating the $x_i$s as constants, and making use of the product\nrule:\n\n\\[\nf'(t) = (-x_2 + x_3)\\sin(t) + (x_1 + x_4)\\cos(t) + (-x_4)t\\sin(t) + (x_3)t\\cos(t)\n\\]\n\nLet's pick a vector $\\bar{x}=(2,4,6,8)$ to visualize $f(t)$ and $f'(t)$, and to later check our\nwork. Inserting our values for the $x_i$s:\n\n\\includegraphics[width=8cm]{plot_8d_f} \\includegraphics[width=8cm]{plot_8d_derivative} \\\\\n\\includegraphics[width=17cm]{plot_8d_both} \\\\\n\\newpage\nDefine the $y_i$s in $f'(t)$ so that they correspond to same positions as the $x_i$s in $f(t)$:\n% that is, y_1 is in front sin(t) etc\n\n\\[\n\\systeme{-x_2 + x_3 = y_1, x_1 + x_4 = y_2, -x_4 = y_3,x_3 = y_4}\n\\]\n\nIn matrix form, this is our solution $A$:\n\n\\[\n\\begin{bmatrix}\n  0 & -1 & 1 & 0 \\\\\n  1 & 0 & 0 & 1 \\\\\n  0 & 0 & 0 & -1 \\\\\n  0 & 0 & 1 & 0 \n\\end{bmatrix}\n\\]\n\nWe can check our work by seeing if we get the same solution by plugging\n$\\bar{x}$ into $f(t)$ and differentiating; and computing $A\\bar{x}$. \n\\[\n  \\frac{d}{dt}(2\\sin(t)+4\\cos(t)+6t\\sin(t)+8t\\cos(t)) = \n\\]\n\\[\n  2\\sin(t)+10\\cos(t)-8t\\sin(t)+6t\\cos(t)\n\\]\n\\bigbreak{}\n\\[\n  \\bar{y} = A\\bar{x} = \n  \\begin{bmatrix}\n    0 & -1 & 1 & 0 \\\\\n    1 & 0 & 0 & 1 \\\\\n    0 & 0 & 0 & -1 \\\\\n    0 & 0 & 1 & 0 \n  \\end{bmatrix}\n  \\begin{bmatrix} 2 \\\\ 4 \\\\ 6 \\\\ 8\\end{bmatrix} = \n  \\begin{bmatrix} 2 \\\\ 10 \\\\ -8 \\\\ 6 \\end{bmatrix}\n\\]\n\n\\newpage\n\nBriefly, this lets us quickly calculate $f''(t)$. Let $\\bar{z}$ be the coefficients in $f''(t)$.\n\n\\[\n  \\bar{z} = A\\bar{y} = \n  \\begin{bmatrix}\n    0 & -1 & 1 & 0 \\\\\n    1 & 0 & 0 & 1 \\\\\n    0 & 0 & 0 & -1 \\\\\n    0 & 0 & 1 & 0 \n  \\end{bmatrix}\n  \\begin{bmatrix} 2 \\\\ 10 \\\\ -8 \\\\ 6 \\end{bmatrix} = \n  \\begin{bmatrix} -18 \\\\ 8 \\\\ -6 \\\\ -8 \\end{bmatrix}\n\\]\n\\[\n  \\rightarrow f''(t) = -18\\sin(t) + 8\\cos(t) - 6t\\sin(t) - 8t\\cos(t)\n  % all that entailed was multiplying a 4x4 matrix by a vector\n\\]\n\n\\section{8e}\n\n\\textit{Question prompt}: $f(t) = (x_1 + x_2t + x_3t^2)e^{-kt}$, and $f'(t)$ has the same\nform with coefficients $y_1$, $y_2$, $y_3$.\n\nAs before, our first step is to differentiate the general form of $f(t)$.\n\n\\[\n  f'(t) = (-kx_1 + x_2 + (-kx_2+2x_3)t - kx_3t^2)e^{-kt}\n\\]\n\nWe have $k$ terms in here, but that's okay. $k$ is a parameter in our equation, not an unkown and\nis \\textit{not} in $\\bar{x}$. It appears in our solution, but that's alright. We can do matrix\nmultiplication that includes constant terms.\n\nNext, define the $y_i$s so that they correspond to the constant, $t$ and $t^2$ terms\n\n\\[\n  \\systeme{-kx_1 + x_2 = y_1, -kx_2+2x_3 = y_2, -kx_3 = y_3}\n\\]\n\nIn matrix form, this is our solution $A$:\n\n\\[\n  \\begin{bmatrix}\n    -k & 1 & 0 \\\\\n    0 & -k & 2 \\\\\n    0 & 0 & -k\n  \\end{bmatrix}\n\\]\n\n\\newpage\n\nUsing $\\bar{x} = (5, 10, 15)$, we can compare our solution differentiating $f(t)$ and computing $A\\bar{x}$.\n\n\\[\n  \\frac{d}{dt}((5+10t+15t^2)e^{-kt}) = \n\\]\n\\[\n  (10-5k + (30-10k)t -15kt^2)e^{-kt}\n\\]\n\\medbreak{}\n\\[\n  \\bar{y} = A\\bar{x} = \n  \\begin{bmatrix}\n    -k & 1 & 0 \\\\\n    0 & -k & 2 \\\\\n    0 & 0 & -k\n  \\end{bmatrix}\n  \\begin{bmatrix} 5 \\\\ 10 \\\\ 15 \\end{bmatrix} = \n  \\begin{bmatrix} 10-5k \\\\ 30-10k \\\\ -15k \\end{bmatrix}\n\\]\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\\bigbreak{}\n\n\\textit{presentation materials avalable at} github.com/broomej/m308\\_w4\\_cp\n\\end{document}\n", "meta": {"hexsha": "7033edde8947f82efcf07bf34ee050d9f6fac4c8", "size": 5471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation.tex", "max_stars_repo_name": "broomej/m308_w4_cp", "max_stars_repo_head_hexsha": "7f8cf2f4734b312b7e709feeb5af2242fa022de9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "presentation.tex", "max_issues_repo_name": "broomej/m308_w4_cp", "max_issues_repo_head_hexsha": "7f8cf2f4734b312b7e709feeb5af2242fa022de9", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "broomej/m308_w4_cp", "max_forks_repo_head_hexsha": "7f8cf2f4734b312b7e709feeb5af2242fa022de9", "max_forks_repo_licenses": ["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.4947916667, "max_line_length": 115, "alphanum_fraction": 0.6311460428, "num_tokens": 2107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.6239804345625853}}
{"text": "\\subsection{Definitions}\n\\begin{itemize}\n\\item $\\lambda$ : intrinsic coordinate, including masses and spins.\n\n\\item $\\theta$ : extrinsic coordinate, including $d,RA,DEC,\\iota,\\psi_L,t,\\phi_{\\rm orb}$\n\n\\item $p_s(\\theta)$: (joint) sampling prior in extrinsic dimensions\n\n\\item $p(\\theta)$ : prior on extrinsic parameters\n\n\\item $\\Like(\\lambda,\\theta)$ : likelihood.  In terms of individual detector strains $H_k$ and power spectra, provided by\n\\begin{eqnarray}\n\\ln L &\\equiv \\sum_k \\ln L_k  = \\ln L_{\\rm model} + \\ln L_{\\rm data} \\\\\n\\ln L_{\\rm model} &\\equiv -\\frac{1}{2} \\sum_k \\qmstateproduct{H_k}{H_k}_k  \\\\\n\\ln L_{\\rm data} &\\equiv  \\sum_k \\text{Re} \\qmstateproduct{H_k}{\\hat{H}_k}_k \n\\end{eqnarray}\n\n\\item $Z(\\lambda) \\equiv L_{\\rm red}(\\lambda,\\theta)$ : reduced or integrated likelihood, derived from $L$ via\n\\begin{eqnarray}\nZ(\\lambda) = L_{\\rm red}(\\lambda) = \\int d\\theta \\; p(\\theta) L(\\lambda,\\theta)\n\\end{eqnarray}\n\n\\item \n$w=Lp/p_s$ : weight\n\n\\item \n$n_{\\rm eff}$ : ``effective number of samples''\n\\begin{eqnarray}\nn_{\\rm eff} \\equiv  \\frac{\\sum_k w_k}{\\text{max}_k w_k}\n\\end{eqnarray}\n\n\\item \n$h(t|\\lambda,x)=h_+-i h_\\times$ : complex gravitational wave strain\n\n\\item \n$h_{lm}(t)$: coefficients of a spin-weighted spherical harmonic decomposition\n\\begin{eqnarray}\n\\label{eq:def:hSpinWeightEmissionDirection}\nh(t|\\lambda,\\theta) = \\sum_{lm} h_{lm}(t|\\lambda) e^{-2i\\psi}\\Y{-2}_{lm}(\\theta_{JN}\\phi_{JN})\n\\end{eqnarray}\n\n\\item \n$\\tilde{h}(f)$ : two-sided Fourier transform of the complex function $h(t)$\n\\begin{eqnarray}\nh(t) = \\int_{-\\infty}^{\\infty} \\frac{d \\omega}{2\\pi} \\; e^{-i\\omega t} \\tilde{h}(\\omega) \n\\end{eqnarray}\n\n%% \\item\n%% ${\\cal I}$ : complex conjugation in time.  Provided to avoid confusion with $\\tilde{h}^*$.  \\textbf{Hopefully we won't\n%%   need it.}\n\n\n\\item \n$\\vec{x}_k$ : Position of the $k$th detector\n\n\\item \n$F_{+}$, $F_{\\times},F$ : detector response function  to the $+,\\times$ polarizations for sources visible in the\n  $\\hat{n}$ direction relative to detector\n\\begin{eqnarray}\nF(\\hat{n}) = F_+(\\hat{n}) +i F_\\times(\\hat{n})\n\\end{eqnarray}\n\n\\item \n$\\hat{H}_k$ : measured strain in  the $k$th detector\n\n\\item \n$H_k$ : strain response of the $k$th detector to an incident strain $h$\n\\begin{align}\nH_k(t) &=F_{+,k}(t) h_+(t-\\vec{x}_k(t)\\cdot \\hat{k}) + F_\\times(t) h_\\times(t-\\vec{x}_k(t)\\cdot \\hat{k}) \\\\\n &=  \\frac{F h(t-\\vec{x}_k\\cdot \\hat{k}) }{2} + \\frac{F^*h^*(t-\\vec{x}_k\\cdot \\hat{k})}{2}\n\\end{align}\n\n\\item \n$S_k$ : noise power spectrum for the $k$th detector\n\n\\item \n$\\qmstateproduct{a}{b}_k$ : complex-valued inner product defined by the $k$th detector's noise power spectrum:\n\\begin{eqnarray}\n\\qmstateproduct{a}{b}_k \\equiv 2 \\int_{-\\infty}^{\\infty} df \\frac{[\\tilde{a}(f)]^*\\tilde{b}(f)}{S_h(|f|) }\n\\end{eqnarray}\n\n\\end{itemize}\n", "meta": {"hexsha": "3d90c7fa023e5737cc2fa56a943ee761ecbf1d8c", "size": 2781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MonteCarloMarginalizeCode/Notes/paper/notation_etc.tex", "max_stars_repo_name": "spfanning/research-projects-RIT", "max_stars_repo_head_hexsha": "34afc69ccb502825c81285733dac8ff993f79503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-10-23T01:18:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-09T18:24:36.000Z", "max_issues_repo_path": "MonteCarloMarginalizeCode/Notes/paper/notation_etc.tex", "max_issues_repo_name": "spfanning/research-projects-RIT", "max_issues_repo_head_hexsha": "34afc69ccb502825c81285733dac8ff993f79503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-01-03T14:38:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-17T16:57:02.000Z", "max_forks_repo_path": "MonteCarloMarginalizeCode/Notes/paper/notation_etc.tex", "max_forks_repo_name": "spfanning/research-projects-RIT", "max_forks_repo_head_hexsha": "34afc69ccb502825c81285733dac8ff993f79503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-10-23T01:19:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T23:35:39.000Z", "avg_line_length": 33.5060240964, "max_line_length": 121, "alphanum_fraction": 0.6627112549, "num_tokens": 1018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6239416955449731}}
{"text": "\\chapter{Calculating Amplitudes}\nThere are a number of possible approaches to calculating an amplitude for a given interaction. These include relativistic generalisations of the Born approximation (Feynman-Stueckelberg) or perturbation theory (Halzen and Martin), and the mathematically heavy canonical field theory or the path integral approach. The idea of the propagator is common to some of these approaches and this is what we will consider in our treatment of amplitude calculations.\n\n\\section{Single scattering potential}\n\\begin{figure}[hb]\n\\centering\n\\include{figures/singleScatter}\n\\caption{Scattering of a plane wave off a localised potential $V$.\\label{fig:singleScatter}}\n\\end{figure}\n\n\nConsider a particle $\\psi(\\vec{r},t)$ that scatters off some potential $V(\\vec{r},t)$, where $V$ acts only at a position $\\vec{r_1}$ and for a short time $\\Delta t$. In the interaction picture the Schr{\\\"o}dinger equation is\n\\begin{equation}\n\\left(\\hat{H}_0 + V\\right)\\psi(\\vec{r},t) = i \\pdv{\\psi}{t}\n\\end{equation}\nwhere the interaction is large, $V \\gg \\hat{H}_0$. Ignoring the free $\\hat{H}_0$ term and solving the separable differential equation,\n\\begin{equation}\ni\\int\\limits_{\\phi}^{\\phi+\\Delta\\psi} \\dd{\\psi} = \\int\\limits_{-\\infty}^{+\\infty} V(\\vec{r},t)\\, \\psi(\\vec{r},t) \\, \\dd{t}\n\\end{equation}\nwhere $\\phi$ is the original, unscattered plane wavefunction and $\\psi=\\phi+\\Delta\\psi$ is the scattered wavefunction. Since the potential $V$ only acts at position $\\vec{r_1}$ and has constant value $V$ for time $\\Delta t$, this evaluates to give\n\\begin{align}\n\\Delta\\psi(\\vec{r_1},t_1) &= -i V(\\vec{r_1},t_1) \\, \\psi(\\vec{r_1},t_1) \\, \\Delta{t} \\\\\n&= -i V({x}_1) \\left[ \\phi({x}_1) + \\Delta\\psi({x}_1) \\right] \\Delta{t} \\\\\n&\\approx -iV(x_1) \\, \\phi(x_1) \\, \\Delta t\\label{eq:scatter}\n\\end{align}\nwhere ${x}_1$ is the event at $(\\vec{r_1}, t_1)$.\n\nWe wish to know the wavefunction after scattering at some event $x^\\prime$. Using the formalism of Green's functions,\n\\begin{equation}\\boxed{\n\\Psi(x^\\prime) = i \\int G(x^\\prime, x) \\, \\Psi(x) \\, \\dd[3]{\\vec{r}} \\quad \\text{for $t^\\prime > t$}\n}\\end{equation}\nwhere $G(x^\\prime, x)$ is the Green's function of the Schr{\\\"o}dinger equation, and is called the propagator from $x$ to $x^\\prime$. Applying this to the change in wavefunction caused by the scattering potential, \\eqref{eq:scatter},\n\\begin{align}\n\\Delta\\psi(x^\\prime) &= i \\int G(x^\\prime, x_1) \\, \\Delta\\psi(x_1) \\, \\dd[3]{\\vec{r}_1} \\\\\n&= \\int G(x^\\prime, x_1) \\, V(x_1) \\, \\phi(x_1) \\, \\Delta{t} \\, \\dd[3]{\\vec{r}_1}.\n\\end{align}\nSo overall, the particle's wavefunction at the event $x^\\prime$ is, to first order,\n\\begin{equation}\n\\psi(x^\\prime) = \\phi(x^\\prime) +  \\int G(x^\\prime, x_1) \\, V(x_1) \\, \\phi(x_1) \\, \\Delta{t} \\, \\dd[3]{\\vec{r}_1}\n.\\end{equation}\nIn the limit of a continuous interaction, we can integrate over the time interval $\\Delta t$,\n\\begin{equation}\\boxed{\n\\psi(x^\\prime) = \\phi(x^\\prime) +  \\int G(x^\\prime, x_1) \\, V(x_1) \\, \\phi(x_1) \\, \\dd[4]{x_1}\n}.\\end{equation}\n\n\\section{Two scattering potentials}\nThe above result may be easily generalised to multiple scattering potentials. A long-range force can be modelled, to first order, by a particle scattering from two localised potentials.\n\\begin{figure}[hb]\n\\centering\n\\include{figures/doubleScatter}\n\\caption{A particle undergoing double scattering in the propagator approach.\\label{eq:doubleScatter}}\n\\end{figure}\n\nConsider two localised scattering potentials, each with strength $V$, at events $x_1$ and $x_2$. Then extending the above result gives that the post-scattering wavefunction is\n\\begin{align}\n\\psi(x^\\prime) = \\phi(x^\\prime) &+ \\int G(x^\\prime, x_1) \\, V(x_1) \\, \\phi(x_1)  \\dd[4]{x_1} \\nonumber \\\\\n&+ \\int G(x^\\prime, x_2) \\, V(x_2) \\, \\phi(x_2) \\, \\dd[4]{x_2} \\nonumber \\\\\n&+ \\int \\int G(x^\\prime, x_2) \\, V(x_2) \\, G (x_2, x_1) \\, V(x_1) \\, \\phi(x_1) \\, \\dd[4]{x_1} \\, \\dd[4]{x_2}\\label{eq:doubleScatter}\n\\end{align}\n\n\\section{Free particle propagator}\nStart from\n\\begin{equation}\n\\psi(x^\\prime) = i \\int \\dd[3]{\\vec{r}} \\, G(x^\\prime; x) \\, \\psi(x)\n\\end{equation}\nfor $t^\\prime > t$. This condition can be encapsulated mathematically by the Heaviside function,\n\\begin{equation}\n\\theta(t^\\prime - t)\\, \\psi(x^\\prime) = i \\int \\dd[3]{\\vec{r}} \\, G(x^\\prime, x) \\, \\psi(x). \\label{eq:start}\n\\end{equation}\nNow multiply both sides by $\\left[ i \\pdv{t} - \\hat{H} \\right]$. The left-hand side becomes,\n\\begin{align}\n\\left[ i \\pdv{t} - \\hat{H} \\right]\\theta(t^\\prime - t)\\, \\psi(x^\\prime) &= i \\pdv{\\theta}{t} \\psi(x^\\prime) + \\theta(t^\\prime-t) \\underbrace{\\left( i\\pdv{\\psi}{t} - \\hat{H}\\psi(x^\\prime) \\right)}_{0\\text{ by TDSE}} \\nonumber \\\\\n&= i \\delta(t^\\prime - t) \\, \\psi(x^\\prime) \\\\\n&= i \\int \\dd[3]{\\vec{r}} \\, \\delta(x^\\prime - x) \\, \\psi(x) \\\\\n&= i \\int \\dd[3]{\\vec{r}} \\int \\frac{\\dd[4]{p}}{(2\\pi)^4} \\, e^{i(x^\\prime-x)p} \\,\\psi(x) \\label{eq:LHS73}\n\\end{align}\nNow consider the right-hand side of \\eqref{eq:start}. Upon multiplication by $\\left[ i \\pdv{t} - \\hat{H} \\right]$ it becomes\n\\begin{equation}\ni \\int \\dd[3]{\\vec{r}} \\, \\left[ i \\pdv{t} - \\hat{H} \\right] \\, G(x^\\prime, x) \\, \\psi(x) = i \\int \\dd[3]{\\vec{r}} \\, \\left[ E - \\frac{p^2}{2m} \\right] \\, G(x^\\prime, x) \\, \\psi(x)\n\\end{equation}\nwhere the operators have been applied to the free plane wavefunction. Taking the Fourier transform to 4-momentum space, the right hand side becomes\n\\begin{equation}\ni \\int \\dd[3]{\\vec{r}} \\int \\frac{\\dd[4]{p}}{(2\\pi)^4} \\, \\left[ E - \\frac{p^2}{2m} \\right] \\, \\mathcal{G}(p^\\prime, p) \\, e^{i(x^\\prime-x)p} \\, \\psi(x).\\label{eq:RHS73}\n\\end{equation}\nwhere $\\mathcal{G}$ is the momentum-space propagator. Now we can compare the integrands of \\eqref{eq:LHS73} and \\eqref{eq:RHS73} to give an expression for the momentum-space free particle propagator:\n\\begin{equation}\\boxed{\n\\mathcal{G}(p^\\prime, p) = \\frac{1}{E - \\frac{p^2}{2m}}\n}.\\end{equation}\n\nThis is used as the propagator for off-mass shell virtual particles. As the particle approaches its mass shell, this expression diverges. To allow for integration over momentum, a small complex factor may be added to the denominator,\n\\begin{equation}\n\\mathcal{G}(p^\\prime, p) = \\frac{1}{E - \\frac{p^2}{2m} + i\\epsilon}\n\\end{equation}\nand the result taken in the limit where $\\epsilon \\rightarrow 0$.\n", "meta": {"hexsha": "c9a866379e08eb590f51cf9669fd3c2056e3fe8f", "size": 6264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/7_Calculating_Amplitudes.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/7_Calculating_Amplitudes.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/7_Calculating_Amplitudes.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": 65.9368421053, "max_line_length": 456, "alphanum_fraction": 0.6743295019, "num_tokens": 2238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.623763692688454}}
{"text": "\\chapter{Linear Algebra}\n\\addcontentsline{toc}{section}{Introduction}\n\\section*{Introduction}\nVSIPL specifies support for standard matrix operations such as matrix products,\rmethods to solve the standard matrix equation $A \\vec{x} = \\vec{b}$, and methods to solve least squares problems. VSIPL hides the decomposition of matrices in objects. So in addition to standard matrix products, special functions for doing matrix products with decomposition matrices are provided.\n\rWe note that although vectors are treated as column vectors in equations, VSIPL vector views have only one stride and so the action of the vector within the function is defined only by the function definition.\n\rIn general all matrix views passed into a function are defined as type const. This means that the area of the block mapped by the view does not change inside of the function call. For some of the defined in place operations where the input and output are defined by the same view the input matrix size may be different than that required by the output data. For these cases the strides of the input view define where the output data is placed. The first element of the output data replaces the first element of the input data. The author recommends defining a view of the output data space for convenience. For a couple of cases the output data space may be bigger than the input data space. Defining an output data view will ensure that the strides of the input view and the size of the block are sufficient to hold the output data. \n\\addcontentsline{toc}{section}{Simple Matrix-Matrix and Vector-Matrix Operations}\n\\section*{Simple Matrix-Matrix and Vector-Matrix Operations}\n\\section*{Simple Solvers}\\addcontentsline{toc}{section}{Simple Solvers}\n\\section*{LU Decomposition}\\addcontentsline{toc}{section}{LU Decomposition}\n\\section*{Cholesky Decompostion}\\addcontentsline{toc}{section}{Cholesky Decompostion}\n\\section*{QR Decompostion}\\addcontentsline{toc}{section}{QR Decompostion}\n\\section*{Singular Value Decomposition}\\addcontentsline{toc}{section}{Singular Value Decomposition}\n\n", "meta": {"hexsha": "b18f1a80f67c011ebb9366257d36bdef3731fa38", "size": 2071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/jvsip_book/c7.tex", "max_stars_repo_name": "rrjudd/jvsip", "max_stars_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-01-16T04:10:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T02:17:44.000Z", "max_issues_repo_path": "doc/jvsip_book/c7.tex", "max_issues_repo_name": "rrjudd/jvsip", "max_issues_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-11T04:48:03.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-11T13:44:29.000Z", "max_forks_repo_path": "doc/jvsip_book/c7.tex", "max_forks_repo_name": "rrjudd/jvsip", "max_forks_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-06-13T21:48:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-26T15:07:44.000Z", "avg_line_length": 138.0666666667, "max_line_length": 835, "alphanum_fraction": 0.8116851762, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.623763674330912}}
{"text": "\\section{Introduction}\\label{sec:intro}\nGravitational Lensing provides us a way to see how dark matter along with \nvisible matter is distributed in universe. This theory of gravitational lensing is supported by Einstein's general theory of relativity which predicts the deflection of light in a gravitational field if any massive object is present there (\\cite{hartle03}).\n%\n%\n%```````````````````````````````````````````````````````````````````````````````\n%         Subsection : Einstein's Deflection Angle\n%```````````````````````````````````````````````````````````````````````````````\n%\n\\subsection{Einstein's Deflection Angle}\n  % aug 14, sch06  page 64\n  \\begin{figure}[ht!]\n      \\centering\n      \\includegraphics[width=0.5\\textwidth]{grav_lensing}\n      \\caption[Simple sketch to gravitational lensing.] {Simple sketch to gravitational lensing ~\\protect\\cite{barSch_01}} %{~\\protect\\cite{barSch_01} } % \\protect ~\\cite{barSch_01}\n      \\label{[fig:lensing] }% \\protect \\cite{barSch_01}\n  \\end{figure} % (Bartelmann and Schneider 2001)}\n  \n\n  General Relativity predicts that when the beam of light passes through near\n  the massive objects, the rays of light undergo deflection from their original path.\n  This angle of deflection was predicted by Einstein's theory of General Relativity.\n  According to this theory if the massive object of mass $M$ is located at a\n  perpendicular distance $\\xi$ (called \\textbf{impact parameter}) from the line of sight\n  of source and the observer then the deflection caused by that mass is given by\n  \\cite{sch07}\n  \\begin{equation}\n    \\hat{\\alpha} = \\frac{4GM}{c^2\\xi}.\n    \\label{[eq:deflection]}\n  \\end{equation}\n\n  This equation (\\ref{[eq:deflection]} ) is valid only when the angle\n  $\\hat{\\alpha} <<1  $ . In  case of gravitational lensing, the product of mass of the\n  deflector and the Gravitational Constant is always the much smaller than the\n  squared of velocity of light, thus making the deflection angle very small.\n\n  For quantitative purpose,\n  we can calculate the value of deflection angle for distant stars appearing near to the\n  solar limb by setting the mass $M = M_{\\odot}$ and radius $ R = R_{\\odot}$ in the above equation to obtain the angle of deflection $\\hat{\\alpha} = 1.74''$. This value was tested\n  in famous solar eclipse experiment in May 29, 1991 which was conceived by Sir Frank Watson Dyson, Astronomer Royal of Britain in 1917 and led by Sir Arthur Stanley Eddington\n  two years later in 1919 (\\cite{eclipse19}). The experiment was designed to test following hypotheses:\n\n\n\n  \\begin{itemize}\n\n    \\item{The light path is uninfluenced by gravitations.}\n    \\item{The law of gravitation will follow Newtonian law and will produce\n            0''.87 apparent displacement}\n    \\item{The course of ray of light will follow Einsteins generalized\n            relativity and lead to apparent displacement of 1.74''.}\n  \\end{itemize}\n  The experiment concluded that the results were close to the Einsteins predicted\n  deflection angle and thus supporting the gravitational lensing theory.\n\n  %capranico 63 and schBar 327\n  This was the deflection due to point source. We can also define the delfection\n  for the extended mass with certain surface mass density $\\Sigma$ as\n  \\begin{equation}\\label{[eq:alphaHat]}\n    \\hat{\\boldsymbol{\\alpha}} (\\boldsymbol{\\xi} ) = \\frac{4G}{c^2} \\int d^2 \\boldsymbol{\\xi\\prime}\\quad  \\Sigma (\\boldsymbol{\\xi\\prime}) \\quad  \\frac{\\boldsymbol{\\xi} - \\boldsymbol{\\xi\\prime}}{|\\boldsymbol{\\xi} - \\boldsymbol{\\xi\\prime} |^2}\n  \\end{equation}\n  Here, the \\textit{surface mass density} $\\boldsymbol{\\Sigma}$ is defined as,\n  \\begin{equation}\\label{[eq:surface_mass_density]}\n    \\boxed{\n    \\Sigma(\\boldsymbol{\\xi}) \\equiv \\int dr_3 \\ \\rho(\\xi_1, \\xi_2, r_3)} \\quad (\\text{Surface Mass Density})\n  \\end{equation}\n  which is the mass density projected onto the lens plane, perpendicular to the\n  light ray, and $r_3$ is the coordinate along the line of sight, and\n  $\\xi_1$, $\\xi_2$ the other two perpendicular coordinates.\n\n\n  %\n  %\n  %```````````````````````````````````````````````````````````````````````````````\n  %         Subsubsection : Lens equation\n  %```````````````````````````````````````````````````````````````````````````````\n  %\n\\subsection{Lens equation}\n  We consider a simplistic lensing model in which lens and the source objects are\n  point objects. The observer observes the rays of light from the source at a\n  distance $D_s$ which pass through the gravitational influence field of a massive\n  object of mass M and distance $D_d$ located perpendicularly $\\boldsymbol{\\xi}$ distance away\n  from line of sight (also called impact parameter).\n\n\n  Let  $\\boldsymbol{\\eta}$  denotes the true, two-dimensional position of the\n  source in the source plane and $\\boldsymbol{\\beta}$ is the true angular position\n  of the source. This means in absence of light deflection we would have,\n  \\begin{equation}\\label{[eq:beta]}\n    \\boldsymbol{\\beta} = \\frac{\\boldsymbol{\\eta} }{D_s}.\n  \\end{equation}\n  The relation between position $\\boldsymbol{\\xi}$ and $\\boldsymbol{\\theta}$  is\n  given by,\n  \\begin{equation}\\label{[eq:theta]}\n    \\boldsymbol{\\theta} = \\frac{\\boldsymbol{\\xi} }{D_d}.\n  \\end{equation}\n  This means $\\boldsymbol{\\theta}$ is the observed position of the source on the\n  sphere relative to the position of center of the lens which is the origin of\n  the coordinate system with $\\boldsymbol{\\xi} = 0$. Where, $D_{ds}$ is the distance of\n  the source plane from the lens plane.\n\n\n  Here we adopt the relation,\n  \\begin{equation}\\label{[eq:D_ds]}\n    D_{ds} = D_s - D_d.\n  \\end{equation}\n  This relation holds true as long as the relevant distances are much smaller\n  than the radius of the universe ($c/H_0$) and this is always the case for\n  distances within our Galaxy and in Local Group. However, this relation no longer\n  holds true for cosmological distances between source and lenses.\n\n  From the figure (\\ref{[fig:lensing]}), we can relate $\\boldsymbol{\\eta}$ with\n  deflection angle $\\boldsymbol{\\alpha}$ as\n  \\begin{equation}\\label{[eq:eta]}\n    \\boldsymbol{\\eta} = \\frac{D_s}{D_d} \\boldsymbol{\\xi} - D_{ds} \\hat{\\boldsymbol{\\alpha} } (\\boldsymbol{\\xi} ).\n  \\end{equation}\n\n  Using equation (\\ref{[eq:beta]}) we can write $\\boldsymbol{\\beta}$ as\n  \\begin{equation}\\label{[eq:beta2]}\n    \\boldsymbol{\\beta} = \\boldsymbol{\\theta} - \\frac{D_{ds}}{D_s}\\  \\hat{\\boldsymbol{\\alpha} } (D_d \\boldsymbol{\\theta} ).\n  \\end{equation}\n\n  In this equation (\\ref{[eq:beta2]}) we have some factor multiplying the\n  deflection angle, so we define \\textit{reduced deflection angle}\n  \\begin{equation}\\label{[eq:alphaReduced]}\n    \\boxed{\\boldsymbol{\\alpha} (\\boldsymbol{\\theta} ) = \\frac{D_{ds}}{D_s}\\  \\hat{\\boldsymbol{\\alpha}} (D_d \\boldsymbol{\\theta} )} \\quad (\\text{Reduced Deflection Angle})\n  \\end{equation}\n\n  and then rewrite the lens equation (\\ref{[eq:beta2]}) as\n  \\begin{equation}\\label{[eq:beta3]}\n     \\boldsymbol{\\beta} = \\boldsymbol{\\theta} - \\boldsymbol{\\alpha} (\\boldsymbol{\\theta} ).\n  \\end{equation}\n\n  For a point mass object, using the equations (\\ref{[eq:alphaHat]}) and (\\ref{[eq:theta]}) the equation of reduced deflection angle (\\ref{[eq:alphaReduced]})\n  becomes\n  \\begin{equation}\\label{[eq:alphaAbs]}\n    \\abs{\\boldsymbol{\\alpha} (\\boldsymbol{\\theta} )} = \\frac{D_{ds}}{D_s}\\  \\frac{4GM}{c^2 D_d \\abs{\\boldsymbol{\\theta}  }}.\n  \\end{equation}\n\n\n%\n%\n%```````````````````````````````````````````````````````````````````````````````\n%         Subsubsection : Convergence and Deflection Potential\n%```````````````````````````````````````````````````````````````````````````````\n% \\texorpdfstring{$math$}{alternative} is to avoid Hyperref warning \n%                                      Token not allowed in a PDF string\n\\subsection{Convergence \\texorpdfstring{$\\kappa$ and deflection potential $\\psi$}{kappaDefletionPotential}}\n  % sch bar 328 Aug 22, 2017 Tue\n  Then convergence is defined as the ratio of the surface mass density of the lens\n  and the critical surface mass density as like\n\n  \\begin{equation}\\label{[eq:kappa]}\n    \\boxed{\\kappa (\\boldsymbol{\\theta} ) \\equiv \\frac{\\Sigma (D_d \\boldsymbol{\\theta} )}{\\Sigma_{cr}}} \\quad (\\text{Convergence}).\n   \\end{equation}\n  Where, the critical surface mass density is given by\n  \\begin{equation}\\label{[eq:crit_surf_mass_density]}\n    \\Sigma_{cr} = \\frac{c^2}{4\\pi G} \\frac{D_s}{D_d D_{ds}}.\n  \\end{equation}\n  The critical density depends on the redshift of source and lens.\n  If the convergence $\\kappa \\geq 1$ i.e. surface density is less than critical\n  surface density then we can see the multiple images of the source. If the\n  value of $\\kappa$ is very large it is called \"strong gravitational lensing\"\n  and if it is only slightly greater than one, it is called \"weak gravitational lensing\".\n  So, the value of critical mass density plays the role in distinguishing weak\n  vs. strong gravitational lensing.\n\n  Moreover, we can define scaled deflection angle in terms of convergence as\n  \\begin{equation}\\label{[eq:alpah_kappa]}\n    \\boldsymbol{\\alpha}(\\boldsymbol{\\theta} ) = \\frac{1}{\\pi}\\ \\int d^2 \\theta\\prime \\ \\kappa(\\boldsymbol{\\theta}\\prime) \\ \\frac{\\boldsymbol{\\theta} - \\boldsymbol{\\theta\\prime} }{\\abs{\\boldsymbol{\\theta} - \\boldsymbol{\\theta\\prime} }^2}\\  .\n  \\end{equation}\n  and the \\textit{deflection potential} can be defined as\n  \\begin{equation}\\label{[eq:psi]}\n    \\psi(\\boldsymbol{\\theta}) = \\frac{1}{\\pi}\\  \\int d^2 \\theta\\prime \\ \\kappa(\\boldsymbol{\\theta\\prime} ) \\ ln\\abs{\\boldsymbol{\\theta} - \\boldsymbol{\\theta\\prime}}.\n  \\end{equation}\n  \n\n%\n%\n%```````````````````````````````````````````````````````````````````````````````\n%         Subsubsection : Multiple Images\n%```````````````````````````````````````````````````````````````````````````````\n%\n\\subsection{Multiple Images}\n  We can see the multiple images of the source at different places\n  $\\boldsymbol{\\theta}_i $ if the equation (\\ref{[eq:beta3]})\n  holds true for different values of the deflection angles.\n\n  \\begin{figure}[ht!]\n      \\centering\n      \\includegraphics[width=0.5\\textwidth]{multiple_images}\n      \\caption[Multiple images of single source]{Multiple images of single source ~\\protect\\cite{sch07}}\n      \\label{[fig:multiple_images]}\n  \\end{figure}\n\n  This figure illustrates a typical situation in which there are two images $S_1$\n  and $S_2$ of the single source $S$ which is lensed by the point massive object\n  $L$.\n\n  Here, if we take direction of deflection angle as pointing towards the source,\n  we can write the deflection angle for the point mass (\\ref{[eq:alphaAbs]}) as\n  \\begin{equation}\\label{[eq:alpha_point_mass]}\n    \\boxed{\\boldsymbol{\\alpha} (\\boldsymbol{\\theta}  ) \\equiv \\frac{4GM}{c^2}\\  \\frac{D_{ds}}{D_s D_d}\\  \\frac{\\boldsymbol{\\theta} }{\\abs{\\boldsymbol{\\theta}}^2}} \\quad (\\text{Reduced Deflection Angle})\n  \\end{equation}\n\n  Now, we define \\textit{Einstein angle} as\n  \\begin{equation}\\label{[eq:einstein_angle]}\n    \\boxed{\\theta_E = \\sqrt{\\frac{4GM}{c^2}\\  \\frac{D_{ds}}{D_s D_d}}} \\quad (\\text{Einstein Angle}).\n  \\end{equation}\n  Then, we can rewrite the equation (\\ref{[eq:alpha_point_mass]}) as\n  \\begin{equation}\\label{[eq:beta_einstein]}\n    \\boldsymbol{\\beta} = \\boldsymbol{\\theta} - {\\theta_E}^2 \\ \\frac{\\boldsymbol{\\theta} }{\\abs{\\boldsymbol{\\theta}  }^2 }\n  \\end{equation}\n\n  To solve this equation (\\ref{[eq:beta_einstein]}) we define two scaling factors\n  \\begin{equation}\\label{[eq:x_y_lens]}\n    y = \\frac{\\boldsymbol{\\beta} }{\\theta_E}\\  ; \\  x = \\frac{\\boldsymbol{\\theta} }{\\theta_E}\n  \\end{equation}\n\n  Then we get\n  \\begin{equation}\\label{[eq:y_lens]}\n    \\textbf{y} = \\textbf{x} - \\frac{\\textbf{x}  }{\\abs{\\textbf{x}  }^2}.\n  \\end{equation}\n\n  This is a quadratic equation and the solutions are given by,\n  \\begin{equation}\\label{[eq:x_lens]}\n    \\textbf{x} = \\frac{1}{2} (\\abs{\\textbf{y}} \\pm \\sqrt{4+ \\abs{\\textbf{y} }^2}) \\\n    \\frac{\\textbf{y} }{\\abs{\\textbf{y} }}.\n  \\end{equation}\n\n  Following information can be drawn from the solution of lens equation:\n  \\begin{easylist}\n\n    & {Except for the divergence condition $\\theta \\rightarrow 0$ any source at position $y$ has two images.}\n    & {The two images are on the opposite sides of the source position when viewed from observer position.}\n    & {If the source is exactly behind the lens ($\\textbf{y} = 0$), we see the circular \\textit{Einstein ring}. }\n    & { \\textit{Einstein ring} has the angular diameter $2 \\theta_E $ and it gives the characteristic images separation.}\n  \\end{easylist}\n\n  %\n  %\n  %```````````````````````````````````````````````````````````````````````````````\n  %         Subsubsection : Magnification and Shear\n  %```````````````````````````````````````````````````````````````````````````````\n  %\n\\subsection{Magnification $\\mu$ and shear $\\gamma$ }\n  The light rays in gravitational are not bent uniformly, the ones near to the\n  lens are deviated more and the ones that are farther are bent in smaller\n  proportion. This differential deflection gives rise to the distorted and\n  magnified images of the source object.\n\n  Let $\\textbf{I}^s(\\boldsymbol{\\beta} )$  be the surface-brightness distribution\n  of the source, then following the conservation of total surface brightness\n  the observed surface-brightness distribution in the lens\n  plane is given by\n  \\begin{equation}\\label{[eq:I_theta]}\n    \\boldsymbol{I(\\theta)} =  \\textbf{I}^s \\ [\\boldsymbol{\\beta}(\\boldsymbol{\\theta})].\n  \\end{equation}\n\n\n  Now we expand the \\textit{true angular position} of the source $\\boldsymbol{\\beta}$\n  in terms of \\textit{observed angular position} of the source $\\boldsymbol{\\theta}$\n  using Taylor expansion around the central observed position $\\boldsymbol{\\theta_0}$\n  we get\n\n  \\begin{eqnarray}\\label{[eq:beta_taylor]}\n    \\boldsymbol{\\beta}(\\boldsymbol{\\theta} ) = \\boldsymbol{\\beta}_0 + ( \\boldsymbol{\\theta} - \\boldsymbol{\\theta}_0 ) \\frac{\\partial\\boldsymbol{\\beta} }{\\partial\\boldsymbol{\\theta}  }\n  \\end{eqnarray}\n\n  Here, the term differential of $\\boldsymbol{\\beta}$ w.r.t. $\\boldsymbol{\\theta}$ is called \\textit{distortion matrix}\n\n  \\begin{eqnarray}\\label{[eq:dist_matrix]}\n    \\boxed{ \\mathscr{A}(\\boldsymbol{\\theta} ) \\equiv \\frac{\\partial \\boldsymbol{\\beta} }{ \\partial \\boldsymbol{\\theta} }} \\quad (\\text{Distortion Matrix}).\n  \\end{eqnarray}\n\n  Now we can write the observed surface brightness $\\boldsymbol{I(\\theta)}$ in terms of\n  distortion matrix as\n  \\begin{eqnarray}\\label{[eq:I_taylor]}\n    \\boxed{\\boldsymbol{I}(\\boldsymbol{\\theta}) = \\boldsymbol{I}^s[\\beta_0 + \\mathscr{A}(\\boldsymbol{\\theta}) (\\theta - \\theta_0 ) ]} \\quad (\\text{Observed Surface Brightness})\n  \\end{eqnarray}\n\n  In terms of deflection potential $\\psi$  \\textit{Jacobian matrix} $\\mathscr{A}$\n  can be written as\n  \\begin{align}\\label{[eq:jacobian]}\n    \\mathscr{A}(\\boldsymbol{\\theta} ) & = \\frac{\\partial \\boldsymbol{\\beta} }{ \\partial \\boldsymbol{\\theta} } \\\\\n      & = (\\delta_{ij} - \\frac{\\partial^2 \\psi(\\boldsymbol{\\theta})}{\\partial \\theta_i \\partial \\theta_j}) \\nonumber \\\\\n      & = {  \\begin{pmatrix}\n               1 - \\psi{,11}  &-\\psi_{,12}  \\\\\n               -\\psi{,21}  & 1 - \\psi_{,22} \\ .\n            \\end{pmatrix}\n          }\n  \\end{align}\n\n  From these deflection potential terms, we define shear components\n  \\begin{eqnarray}\\label{[eq:shear_comps]}\n    \\gamma_1 &=& \\frac{1}{2} (\\psi_{,11} + \\psi_{,22} ) \\\\\n    \\gamma_2 &=& \\psi_{,12}\n  \\end{eqnarray}\n\n  Here, the two components tensor $\\gamma$ is called \\textit{shear} and is\n  given by\n  \\begin{eqnarray}\\label{[eq:shear]}\n    \\boxed{\\gamma \\equiv \\gamma_1 + i \\gamma_2\n           = \\lvert\\gamma\\rvert e^{2i \\phi}} \\quad (\\text{Shear})\n  \\end{eqnarray}\n\n  Here, $\\gamma_1$ and $\\gamma_2$ are two components of shear as given in equation\n  (\\ref{[eq:shear_comps]}) and $\\phi$ is the phase angle.\n\n  The shear has two components $\\gamma_1$ and $\\gamma_1$ which can be expressed as\n  \\begin{equation}\\label{[eq:shear]}\n    \\gamma \\equiv \\gamma_1 + i \\gamma_2 = \\lvert\\gamma\\rvert e^{2i \\phi}.\n  \\end{equation}\n  Also, in terms of deflection potential the shear components can be expressed as\n  \\begin{eqnarray}\\label{[eq:shear_comp]}\n    \\gamma_1 &=& \\frac{1}{2} (\\psi_{,11} - \\psi_{,22} ) \\\\\n    \\gamma_2 &=& \\psi_{,12} \\nonumber\n  \\end{eqnarray}\n\n  Also, the convergence $\\kappa$ is related to the deflection potential through\n  Poisson equation\n  \\begin{eqnarray}\\label{[eq:kappa_psi]}\n    \\nabla^2 \\psi(\\theta) = 2 \\kappa(\\theta).\n  \\end{eqnarray}\n\n  In terms of matrix elements of deflection potential $\\psi$ we can write $\\kappa$ as\n  \\begin{eqnarray}\\label{[eq:kappa_psi]}\n    \\boxed{\\kappa = \\frac{1}{2} (\\psi_{,11} + \\psi_{,22})} \\quad (\\text{Convergence})\n  \\end{eqnarray}\n\n  Now we can write the distortion matrix $\\mathscr{A}$ in terms of\n  shear components $\\gamma_1$ and $\\gamma_2$ and convergence $\\kappa$ as\n  \\begin{eqnarray}\\label{[eq:A_theta]}\n    \\mathscr{A}(\\boldsymbol{\\theta}) =\n    \\begin{pmatrix}\n      1 - \\kappa - \\gamma_1 & - \\gamma_2  \\\\\n      - \\gamma_2 & 1 - \\kappa + \\gamma_1\n    \\end{pmatrix}\n  \\end{eqnarray}\n\n  If we solve this matrix we get the eigenvalues\n  \\begin{eqnarray}\\label{[eq:eigen]}\n    eig(\\mathscr{A}) = 1 - \\kappa \\pm \\lvert g \\rvert .\n  \\end{eqnarray}\n\n  The equation \\ref{[eq:I_taylor]} has the shape of an ellipse. This means that\n  if a circular galaxy is lensed then the resulting observed image will be an\n  ellipse. The semi-major and semi-minor axes of the ellipse are given by\n  \\begin{eqnarray}\\label{[eq:semi_axes]}\n    a &=& \\frac{R}{1 - \\kappa  - \\lvert g \\rvert } \\\\\n    b &=& \\frac{R}{1 - \\kappa  + \\lvert g \\rvert }\n  \\end{eqnarray}\n\n  Here, $R$ is the radius of circular source, $a$ is the semi-major axis, $b$ is semi-minor axis, and $g$ is the reduced shear\n  defined as\n  \\begin{eqnarray}\\label{[eq:g]}\n    \\boxed{g(\\boldsymbol{\\theta} ) \\equiv \\frac{\\gamma(\\boldsymbol{\\theta} )}{1 - \\kappa(\\boldsymbol{\\theta} )}} \\quad (\\text{Reduced Shear}).\n  \\end{eqnarray}\n\n  The inverse of the determinant of the matrix $\\mathscr{\\alpha}$ gives the\n  magnification tensor. Then we define magnification as\n  \\begin{eqnarray}\\label{[eq:magnification]}\n    \\boxed{\\mu(\\boldsymbol{\\theta}) \\equiv \\frac{1}{det \\lvert \\mathscr{A} \\rvert }} \\quad (\\text{Magnification}).\n  \\end{eqnarray}", "meta": {"hexsha": "0f8fc4b2268a8eb2ad63c75e33987d4a9c0bb889", "size": 18249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Prospectus/prospectus/sections/chap1_introduction.tex", "max_stars_repo_name": "bhishanpdl/Research", "max_stars_repo_head_hexsha": "7868d6b01cb58dd295971a62bce8178dd673ed8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Prospectus/prospectus/sections/chap1_introduction.tex", "max_issues_repo_name": "bhishanpdl/Research", "max_issues_repo_head_hexsha": "7868d6b01cb58dd295971a62bce8178dd673ed8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Prospectus/prospectus/sections/chap1_introduction.tex", "max_forks_repo_name": "bhishanpdl/Research", "max_forks_repo_head_hexsha": "7868d6b01cb58dd295971a62bce8178dd673ed8c", "max_forks_repo_licenses": ["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.1346153846, "max_line_length": 257, "alphanum_fraction": 0.6639267905, "num_tokens": 5694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672089305841, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6237014252709566}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 6.2 Evaluate on an expression (not a rule)}\n\n\\begin{cadabra}\n   {\\theta, \\varphi}::Coordinate.\n   {a,b,c,d,e,f,g,h#}::Indices(values={\\theta, \\varphi}, position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   V  := { V_{\\theta} = f(\\theta,\\varphi), V_{\\varphi} = g(\\theta,\\varphi) }.  # cdb(ex-0602.100,V)\n   dV := \\partial_{b}{V_{a}} + \\partial_{a}{V_{b}}.                            # cdb(ex-0602.101,dV)\n\n   evaluate (dV, V)                                                            # cdb(ex-0602.102,dV)\n\\end{cadabra}\n\n\\begin{align*}\n   V_{a} &= \\Cdb{ex-0602.100}\\\\[10pt]\n   & \\Cdb{ex-0602.101}\\\\[10pt]\n   & \\Cdb{ex-0602.102}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "4908ef3167c3ff02e0149ae3f725f05b95b8bebd", "size": 895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0602.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-0602.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-0602.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": 29.8333333333, "max_line_length": 100, "alphanum_fraction": 0.5027932961, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672043084051, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6237014174624416}}
{"text": "\\chapter{Robust linear regression}\n\\label{chap:robreg}\n\nThis chapter is devoted to the estimation of the parameters of linear\nregression models. Let us first precise some notations.\n\n\\section{The linear regression model}\n\nIn a linear regression model, we try to explain a variable $y$---the\n\\emph{dependent} variable---as a linear function of some \\emph{explanatory}\nvariables (or \\emph{predictors}) $x_1, \\dots, x_p$: we assume that\n%\n\\begin{equation}\n    \\label{eq:linear_regr_model}\n    y = \\beta_0 + \\beta_1x_1 + \\dots + \\beta_px_p + \\varepsilon\n\\end{equation}\n%\nwhere $\\beta_0, \\beta_1, \\dots, \\beta_p$ are unknown regression\ncoefficients---$\\beta_0$ is called the \\emph{intercept} and $\\beta_1,\n\\dots, \\beta_p$ are the \\emph{slopes}---that have to be estimated and\n$\\varepsilon$ is a random error term (the error of the statistical model, due\nto omitted factors, errors of measurement, random effects, etc.).\n\nTo estimate the regression coefficients, we need a random sample of\nrealizations of $(y_i, x_{i1}, \\ldots, x_{ip})$, $i=1, \\dots, n$, where $n$\nis the sample size. We have\n%\n\\begin{equation}\n    \\label{eq:linear_regr_model_sample}\n    y_i = \\beta_0 + \\beta_1x_{i1} + \\dots + \\beta_px_{ip} + \\varepsilon_i,\n    \\qquad i = 1, \\dots, n\n\\end{equation}\n%\nwhere $\\varepsilon_i$'s are generally assumed to be i.i.d.\\ random variables.\nThat is,\n\\[\n    \\varepsilon_i \\stackrel{\\text{i.i.d.}}{\\sim} F_{0, \\sigma}\n\\]\nwhere distribution $F_{0, \\sigma}$ has a location (centrality) parameter equal\nto zero and a scale parameter equal to $\\sigma$.\n\nDenoting by $\\stvec{x}_i$ and $\\boldsymbol\\beta$ the $(p+1)$ dimensional\ncolumn vectors with coordinates $(1, x_{i1}, \\dots, x_{ip})$ and $(\\beta_0,\n\\beta_1, \\dots, \\beta_p)$, respectively, equation\n(\\ref{eq:linear_regr_model_sample}) can be more compactly written as\n%\n\\begin{equation}\n    \\label{eq:linear_regr_model_sample_bis}\n    y_i = \\stvec{x}_i^t\\boldsymbol\\beta + \\varepsilon_i,\n    \\qquad i = 1, \\dots, n.\n\\end{equation}\n%\nFurthermore, letting $\\stvec{y} = (y_1, \\dots, y_n)^t$,\n$\\boldsymbol\\varepsilon = (\\varepsilon_1, \\dots, \\varepsilon_n)^t$ and\n\\[\n    \\stmat{X} = \n    \\begin{pmatrix}\n        1       & x_{11} & \\dots & x_{1p} \\\\\n        1       & x_{21} & \\dots & x_{2p} \\\\\n        \\vdots  & \\vdots & \\dots & \\vdots \\\\\n        1       & x_{n1} & \\dots & x_{np}\n    \\end{pmatrix}\n    = \n    \\begin{pmatrix}\n        \\stvec{x}_1^t \\\\\n        \\stvec{x}_2^t \\\\\n        \\vdots         \\\\\n        \\stvec{x}_n^t\n    \\end{pmatrix}\n\\]\nequations (\\ref{eq:linear_regr_model_sample_bis}) takes the matrix-notation form\n\\[\n    \\stvec{y} = \\stmat{X}\\boldsymbol\\beta + \\boldsymbol\\varepsilon.\n\\]\n\nLet us note here that, \\emph{conditionally to the predictors}, the linear\nregression model (\\ref{eq:linear_regr_model_sample_bis}) may be considered as a\nlocation-scale model. Indeed, under the assumption of homoscedasticity---an\nidentical scale parameter $\\sigma$ for each error term\n$\\varepsilon_i$---regression model (\\ref{eq:linear_regr_model_sample_bis})\nmay be formulated as follows:\n%\n\\begin{equation}\n    \\label{eq:location_scale_regr_model}\n    y_i = \\stvec{x}_i^t\\boldsymbol\\beta + \\sigma\\nu_i, \n    \\qquad i = 1, \\dots, n\n\\end{equation}\n%\nwhere the $\\nu_i$'s are i.i.d.\\ with distribution function $F_{0,1}$ (a\ndistribution with a location parameter equal to zero and a scale parameter\nequal to one). In this case, the conditional distribution of $y_i$ given\n$\\stvec{x}_i$ is of the form:\n%\n\\begin{equation}\n    \\label{eq:distr_function_yi}\n    F_{y_i | \\stvec{x}_i}(y) \n    = \\Pr(y_i \\leq y | \\stvec{x}_i) \n    = \\Pr\\left(\\nu_i \\leq \\frac{y - \\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma} \\bigg| \\stvec{x}_i\\right)\n    = F_{0,1}\\left(\\frac{y - \\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma}\\right)\n\\end{equation}\n%\nFurthermore, if $f_{0,1}$ denotes the density function of the error terms \n$\\nu_i$, that is,\n\\[\n    f_{0,1}(u) = \\frac{d F_{0,1}(u)}{d u} = F_{0,1}'(u)\n\\]\nthen\n%\n\\begin{equation}\n    \\label{eq:dens_function_yi}\n    f_{y_i | \\stvec{x}_i}(y) \n    = \\frac{1}{\\sigma} f_{0,1}\\left(\\frac{y - \\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma}\\right).\n\\end{equation}\n%\nHence, $\\stvec{x}_i^t\\boldsymbol\\beta$ corresponds to the unknown location\nparameter of the distribution of $y_i$ and $\\sigma$ is the scale parameter of\nthe distribution of $y_i$. For simplicity, we will consider that the\ndistribution $F_{0,1}$ is continuous and symmetric around zero (and exception\nis Section \\ref{sec:inference}).\n\n\\begin{stremark}\nThe classic \\emph{location-scale model} may be seen as a particular case of\nregression model (\\ref{eq:location_scale_regr_model}). It suffices to set\n$\\beta_1 = \\dots = \\beta_p = 0$ and to assume that the $\\nu_i$'s are\ni.i.d.\\ with distribution $F_{0,1}$ (such that $E(\\nu_i)=0$). In this case,\nthe observations\n%\n\\begin{equation}\n    \\label{eq:location_scale_model}\n    y_i = \\beta_0 + \\sigma\\nu_i,\n    \\qquad i=1, \\dots, n,\n\\end{equation}\n%\nare i.i.d.\\ with a common distribution $F$ characterized by mean $\\mu =\n\\beta_0$ and scale parameter $\\sigma$.\n\\end{stremark}\n\n\\begin{stremark}\nMost textbook presentations of the linear regression model assume the\nexplanatory variables to be fixed (and measured without error). That is, the\nexplanatory variables are not assumed to be random variables. In the context of\na \\emph{designed experiment}, this assumption is reasonable since the values of\nthe experimental factors are determined \\emph{a priori} by the researchers. In\nother contexts such as, for example, when using social-science survey data, the\nassumption makes no sense. \n    \\todo{Say here what the consequence is: The fact that the $X$'s are random\n    doesn't really change anything. (unlike measurement error which attenuates\n    the estimates)}\n\nNonetheless, since we focus on the problem of outlying values, we will ignore\nthe issue in this chapter and consider $x_{ij}$, $i = 1, \\dots, n$, $j = 1,\n\\dots, p$, as predetermined. That is, results will always be conditional on the\nparticular \\emph{values} taken by the explanatory variables.\n    \\todo{I'm not sure whether this remark makes sense. First, LS results are\n    valid also if the $X$'s are random. Second, if we talk about $X$ outliers\n    it makes not much sense to assume $X$ fixed.}\n\\end{stremark}\n\n\n\\section{Different types of outliers}\n\nModel (\\ref{eq:linear_regr_model}) assume that \\emph{all} units of the\npopulation and, \\emph{de facto}, all units of the sample are consistent with\nthe supposed linear model. If a unit has a behavior that does not respect the\nunderlying theoretical model, we define it as an \\emph{outlying} unit with\nrespect to the model.\n\nOf course, in the case of \\emph{simple} linear regression model ($p=1$), a\nvisual inspection of the scatterplot is generally sufficient to detect the\noutliers. But, when the number of explanatory variables is greater than two,\nit becomes impossible to visualize all the data set and the use of robust\nmethods to estimate the regression parameters is then essential. More\nprecisely, we aim at developing procedures that provide a good fit to the bulk\nof the data without being perturbed by a small proportion of outliers, and\nthat do not require deciding previously which observations are outliers.\nMoreover, the comparison between the estimations provided by the classical\nleast squares estimator and those obtained using a robust estimation procedure\nwill allow to bring to the fore the outlyingness of some data.\n\nIn cross-sectional regression analysis, three types of outliers may influence\nthe estimations. \\citet{rousseeuw:leroy:1987} define them as \\emph{vertical\noutliers}, \\emph{good leverage points} and \\emph{bad leverage points}. To\nillustrate this terminology, consider a simple linear regression as shown in\nfigure~\\ref{fig:outlier_types} (the generalization to higher dimensions is\nstraightforward). \\emph{Vertical outliers} are those observations that have\noutlying values for the corresponding error term (that is, in the\n$y$-dimension) but are not outlying in the space of explanatory variables (in\nthe $x$-dimension). \\emph{Good leverage points} are observations that are\noutlying in the space of explanatory variables but that are located close to\nthe regression hyperplane. Finally, \\emph{bad leverage points} are observations\nthat are both outlying in the space of explanatory variables and located far\nfrom the true regression hyperplane.\n\n\n\\begin{figure}[h!]\n    \\centering\n    \\epsfig{file=eps/4/1}\n    \\caption{Vertical outlier, good leverage point and bad leverage point}\n    \\label{fig:outlier_types}\n\\end{figure}\n\nAll these types of outliers risk to affect the estimation of the regression\nhyperplane but their effect changes according to the estimator we will\nconsider and the type of outlyingness. For the classical least squares\nestimation method, for instance, the bad leverage points are considered as the\nmost dangerous outliers because their presence can change the sign of the\nslope of the regression line (in simple regression); the good leverage points\nhave little influence on the estimation of the regression coefficients but\nthey have an impact on the variances and covariances of the regression\ncoefficients' estimators and, consequently, risk to influence the inferential\nprocedures (tests and confidence intervals).\n\nThe most popular estimation method in linear regression is certainly the\n\\emph{least squares} (\\stsc{LS}) method introduced in 1805 by Legendre.          \\todo{Please provide citation details!}\nOne of its principal advantage is the simplicity of the\ncomputation of the \\stsc{LS}~estimates. Its popularity has also be reinforced\nby the fact that, under the normality of the error terms, \\stsc{LS}~estimates\nof the regression coefficients coincide with the maximum likelihood estimates.\nWe will first briefly review the logic behind least squares (\\stsc{LS})\nestimation and recall why the \\stsc{LS}~estimator is particularly affected by\nthe presence of atypical individuals. We will thereafter introduce some\nalternative estimation methods that have been proposed to try to cope with\noutliers.\n\n\n\\section{LS estimation}\n\nLet us denote by $\\sthat{y}_i(\\boldsymbol\\beta)$ the value fitted by the\nregression model for the $i$th statistical unit of the sample when taking\n$\\boldsymbol\\beta$ as value for the vector of regression coefficients:\n\\[\n    \\sthat{y}_i(\\boldsymbol\\beta)  = \\stvec{x}_i^t\\boldsymbol\\beta, \n    \\qquad i = 1, \\dots, n\n\\]\nThe difference between the observed value $y_i$ and the fitted value\n$\\sthat{y}_i(\\boldsymbol\\beta)$ is the residual $r_i(\\boldsymbol\\beta)$:\n\\[\n    r_i(\\boldsymbol\\beta) = y_i - \\sthat{y}_i(\\boldsymbol\\beta),\n    \\qquad i = 1, \\dots, n.\n\\]\n\nAlthough $\\boldsymbol\\beta$ can be estimated in several ways, the underlying\nidea is often to take an estimate $\\sthat{\\boldsymbol\\beta}$ in such a way that\nthe fitted values $\\sthat{y}_i(\\sthat{\\boldsymbol\\beta})$ for the dependent\nvariable are as close as possible to the observed values $y_i$ ($i = 1,\n\\dots, n$), i.e., in such a way that we minimize globally the magnitude of the\nresiduals $r_i(\\sthat{\\boldsymbol\\beta})$. This idea leads to try to find the\nestimate $\\sthat{\\boldsymbol\\beta}$ that minimizes a specific aggregate\nprediction error.\n\nIn the case of the well-known ordinary least squares (\\stsc{LS}), this\naggregate prediction error is defined as the sum of squared residuals:\n%\n\\begin{equation}\\label{eq:LS_min}\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS} = \\argmin_{\\boldsymbol\\beta} \n    \\sum_{i=1}^{n} r_i(\\boldsymbol\\beta)^2\n\\end{equation}\n%\nwhere “$\\argmin$” stands for “the value minimizing”. In other terms,\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ is solution of the so called\n\\emph{normal equations} system---we will also call it the \\emph{estimating\nequations} system---obtained by differentiating the function $\\sum_{i=1}^{n}\nr_i(\\boldsymbol\\beta)^2$ to minimize with respect to each component of\n$\\boldsymbol\\beta$, that is, $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ is the\nsolution of\n%\n\\begin{equation}\\label{eq:LS_equations}\n    \\sum_{i=1}^{n}  r_i(\\boldsymbol\\beta)\\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\nwhich is equivalent to the linear equations system\n\\[\n    \\stmat{X}^t\\stmat{X}\\boldsymbol\\beta = \\stmat{X}^t\\stvec{y}.\n\\]\nIf $\\stmat{X}$ has full rank\\footnote{The matrix of predictors $\\stmat{X}$ is\nsaid to have \\emph{full rank} if its columns are linearly independent (absence\nof multicollinearity), that is, if $\\stmat{X}\\stvec{a}\\neq\\stvec{0}$ for all\n$\\stvec{a}\\neq\\stvec{0}$. This is equivalent to the nonsingularity of\n$\\stmat{X}'\\stmat{X}$.}, then the solution of (\\ref{eq:LS_equations}) is unique\nand is given by\n%\n\\begin{equation}\\label{eq:LS_estimator}\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS}\n    = \\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X}, \\stvec{y})\n    = (\\stmat{X}^t\\stmat{X})^{-1} \\stmat{X}^t\\stvec{y}.\n\\end{equation}\n%\nThis estimate can be computed in Stata using the \\stcmd{regress} command (see\n\\rref{regress}).\n\nNote here that, if the model contains a constant term $\\beta_0$, that is, if\nthe first component of the vectors $\\stvec{x}_i$, $i = 1, \\dots, n$, is equal\nto one, it follows from (\\ref{eq:LS_equations}) that the residuals\n$r_i(\\sthat{\\boldsymbol\\beta}_\\stsc{LS})$, $i = 1, \\dots, n$, have zero\naverage.\n\nIt is easy to verify that the \\stsc{LS}~estimator satisfies \n(see \\citealp[92]{maronna:etal:2006})\n%\n\\begin{align}\n    \\label{eq:regression_equivariance}\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X},\\stvec{y}+\\mathbf{X}\\boldsymbol\\gamma) \n        &= \\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X},\\stvec{y})+\\boldsymbol\\gamma\n        \\qquad\\text{for all $\\boldsymbol\\gamma\\in\\mathbb{R}^{p+1}$} \\\\\n    \\label{eq:scale_equivariance}\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X},\\lambda\\stvec{y})\n        &= \\lambda\\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X}, \\stvec{y})\n        \\qquad\\text{for all $\\lambda\\in\\mathbb{R}$}\n\\end{align}\n%\nand, for any nonsingular $(p+1) \\times (p+1)$ matrix $\\stmat{A}$,\n%\n\\begin{equation}\\label{eq:affine_equivariance}\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X}\\stmat{A},\\stvec{y})\n    = \\stmat{A}^{-1}\\sthat{\\boldsymbol\\beta}_\\stsc{LS}(\\stmat{X},\\stvec{y}).\n\\end{equation}\n%\nThe properties (\\ref{eq:regression_equivariance}),\n(\\ref{eq:scale_equivariance}) and (\\ref{eq:affine_equivariance}) are called\n\\emph{regression}, \\emph{scale} and \\emph{affine equivariance} of\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$, respectively. In the sequence, it will\nbe desirable that every other estimator of $\\boldsymbol\\beta$ also satisfies\nthese natural properties.\n\nIt is also well known that the \\stsc{LS}~estimator of $\\boldsymbol\\beta$ coincides\nwith the maximum likelihood estimator in case of normally distributed error\nterms in (\\ref{eq:linear_regr_model_sample}). Hence, $\\widehat\n{\\boldsymbol\\beta}_\\stsc{LS}$ is the most efficient estimator of\n$\\boldsymbol\\beta$ in the Gaussian regression model.\n\nHowever, an important drawback of \\stsc{LS} is that, by considering squared\nresiduals, it tends to award an excessive importance to observations with large\nresiduals and, consequently, distort parameters estimation when outliers exist.\n\n\\section{M estimation}\n\n\\subsection{Least Absolute Deviation (LAD) estimation}\n\n\\citet{edgeworth:1887} realized that due to the squaring of the residuals,\n\\stsc{LS} becomes extremely vulnerable to the presence of outliers. To cope\nwith this, he proposed a method consisting in minimizing the sum of the\nabsolute values of the residuals rather than the sum of their squares. More\nprecisely, his method defines the $L_1$ or \\emph{least absolute deviation}\n(\\stsc{LAD}) estimate as\n%\n\\begin{equation}\\label{eq:L1_min}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}} \n        = \\argmin_{\\boldsymbol\\beta} \\sum_{i=1}^{n} |r_i(\\boldsymbol\\beta)|.\n\\end{equation}\n%\nThis estimate is solution of the estimating equations system obtained by\ndifferentiating the sum of the absolute values of the residuals with respect\nto each component of $\\boldsymbol\\beta$:\n%\n\\begin{equation}\\label{eq:L1_equations}\n    \\sum_{i=1}^{n}\\sign(r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}})) \n    \\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\nIf the model contains an intercept term, (\\ref{eq:L1_equations}) implies that\nthe residuals $r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}})$, $i = 1, \\dots,\nn$, have a median equal to zero; this motivates the fact that the \\stsc{LAD}\nregression estimator is also sometimes called the \\emph{median regression\nestimator}.\n\nUnlike for $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$, there is no explicit\nexpression for $\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}}$.\\footnote{Note also that\nthe \\stsc{LAD}~estimate of $\\boldsymbol\\beta$ may not be unique and has the\nproperty that at least $(p+1)$ residuals are equal to zero.} However, there\nexist very fast algorithms to compute it and\n$\\sthat{\\boldsymbol{\\beta}}_{\\stsc{LAD}}$ is available in Stata via the\n\\stcmd{qreg} command as a standard function (see \\rref{qreg}).\n\nFinally, it can easily be seen from (\\ref{eq:L1_min}) and\n(\\ref{eq:L1_equations}) that this estimator does protect against vertical\noutliers (but not against bad leverage points). However, this gain in\nrobustness with respect to the \\stsc{LS}~estimator comes with an important loss\nof efficiency: the asymptotic relative efficiency of\n$\\sthat{\\boldsymbol{\\beta}}_{\\stsc{LAD}}$ with respect to\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ is equal to $2/\\pi = 63.7\\%$ at a\nGaussian error distribution (see \\citealp{huber:1981}).\n\n\\subsection{The principle of M estimation}\n\n\\citet{huber64} hence generalized median regression to a wider class of\nestimators, called \\stsc{M}~estimators, by considering other functions than\nthe absolute value in (\\ref{eq:L1_min}) in order to find a reasonable balance\nbetween robustness and Gaussian efficiency.\n\nAn \\stsc{M}~estimate $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ of\n$\\boldsymbol\\beta$ is defined by\n%\n\\begin{equation}\n    \\label{eq:M_min}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho} \n        = \\argmin_{\\boldsymbol\\beta}\\sum_{i=1}^{n} \n            \\rho\\left(\\frac{y_i - \\stvec{x}_i^t\\boldsymbol\\beta}{\\sthat{\\sigma}}\\right)\n        = \\argmin_{\\boldsymbol\\beta}\\sum_{i=1}^{n}\n            \\rho\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right)\n\\end{equation}\n%\nwhere $\\rho(u)$ is a loss function that is positive, even such that $\\rho(0) =\n0$, and non decreasing for positive values $u$, and $\\sthat{\\sigma}$ is an\nauxiliary estimate of the scale parameter $\\sigma$ required to standardize the\nresiduals and to make $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ scale\nequivariant; see (\\ref{eq:scale_equivariance}). In most situations,\n$\\sthat{\\sigma}$ is computed in advance, but it can also be computed\nsimultaneously through a scale \\stsc{M} estimating equation. This problem will\nbe discussed in more details later.\n\n\\begin{stremark}\nThe \\stsc{LS}~estimate and the \\stsc{LAD}~estimate correspond respectively to\n$\\rho(u) = u^2$ and $\\rho(u) = |u|$. In these two cases, $\\sthat{\\sigma}$\nbecomes a constant factor outside the summation sign in (\\ref{eq:M_min}) and\n\\[\n    \\argmin_{\\boldsymbol\\beta} \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right)\n    = \\argmin_{\\boldsymbol\\beta}\\sum_{i=1}^{n}\\rho(r_i(\\boldsymbol\\beta)).\n\\]\nThus neither the \\stsc{LS} nor the \\stsc{LAD}~estimate require an auxiliary\nscale estimate.\n\\end{stremark}\n\nOf course, if we want a \\stsc{M}~estimator more robust against vertical\noutliers than the \\stsc{LS}~estimator, we have to take a loss function $\\rho$\nthat is less rapidly increasing than the square function in order to give less\nweight to big (in absolute value) residuals in the minimization problem. In\norder to combine robustness and efficiency under a Gaussian error distribution,\n\\citet{huber64} has suggested to use for $\\rho$ a function of the form (see\nfigure~\\ref{fig:rho_psi_Huber}):\n\\[\n    \\rho_{\\kappa}^{\\stsc{H}}(u) = \n    \\begin{cases}\n        u^2                    & \\text{if $|u| \\leq \\kappa$}\\\\\n        2\\kappa |u| - \\kappa^2 & \\text{if $|u| > \\kappa$}\n    \\end{cases}\n\\]\nwhere $\\kappa$ is a constant determining the trade-off between robustness and\nefficiency. These functions of Huber are convex on the whole real line and may\nbe seen as intermediate functions between the quadratic function (leading to\nthe non robust but efficient \\stsc{LS}~estimate) and the absolute value function\n(associated with the robust but poorly efficient \\stsc{LAD}~estimate).\n\nAnother class of loss functions $\\rho$ widely used in the literature is the\nclass of the Tukey-Biweight                                                     \\todo{Please provide citation!} \nfunctions (see figure~\\ref{fig:rho_psi_Biweight})\n%\n\\begin{equation}\n    \\label{eq:Tukey_Biweight_function}\n    \\rho_\\kappa^\\stsc{B}(u) = \n        \\begin{cases}\n            \\frac{\\kappa^2}{6} \\left[1 - \\left(1 - \\left(\\frac{u}{\\kappa}\\right)^{2}\\right)^{\\!3}\\right] \n                & \\text{if $|u| \\leq \\kappa$}\\\\\n            \\frac{\\kappa^2}{6} \n                & \\text{if $|u| > \\kappa$}\n        \\end{cases}\n\\end{equation}\n%\nThese functions are bounded. Once again, the constant $\\kappa$ allows the\ntrade-off between robustness and Gaussian efficiency. We will show the\nadvantage and disadvantage to use a bounded function $\\rho$ hereafter.\n\nWe may also characterize $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ as a\nsolution of the estimating equations system obtained by differentiating the\nfunction to minimize in (\\ref{eq:M_min}) with respect to each component of\n$\\boldsymbol\\beta$, that is, as a solution of the equations system\n%\n\\begin{equation}\\label{eq:M_equations}\n    \\sum_{i=1}^{n} \\psi\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right) \\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\nwhere $\\psi(u) = d\\rho(u) / du = \\rho'(u)$. For instance, taking\n$\\rho(u)=\\rho_{\\kappa}^{\\stsc{H}}(u)$, we have\n\\[\n    \\psi_{\\kappa}^{\\stsc{H}}(u) = \n    \\begin{cases}\n        -2\\kappa    & \\text{if $u<-\\kappa$}\\\\\n        2u          & \\text{if $-\\kappa\\leq u\\leq\\kappa$}\\\\\n        2\\kappa     & \\text{if $u>\\kappa$}\n    \\end{cases}\n\\]\nfor $\\rho(u) = \\rho_{\\kappa}^{\\stsc{B}}(u)$, we obtain\n\\[\n    \\psi_{\\kappa}^{\\stsc{B}}(u) =\n    \\begin{cases}\n        u\\left(1 - \\left(\\frac{u}{\\kappa}\\right)^2\\right)^{\\!2} & \\text{if $|u| \\leq \\kappa$}\\\\\n        0                                                       & \\text{if $|u| > \\kappa$}\n    \\end{cases}\n\\]\n(see figures \\ref{fig:rho_psi_Huber} and \\ref{fig:rho_psi_Biweight}). If the\nloss function $\\rho$ is convex on $\\mathbb{R}$---this is the case for\n$\\rho_{\\kappa}^{\\stsc{H}}$---the score function $\\psi$ is monotone (non\ndecreasing) on $\\mathbb{R}$ and $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is\ncalled a \\emph{monotone} regression \\stsc{M}~estimator; if $\\rho$ is\nbounded---this is the case for $\\rho_{\\kappa}^{\\stsc{B}}$---the score function\n$\\psi$ vanishes out of a certain interval of $\\mathbb{R}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is then called a \\emph{redescending}\nregression \\stsc{M}~estimator.\n\n\n\\begin{figure}[h!]\n    \\centering\n    \\epsfig{file=eps/4/2}\n    \\caption{Huber loss function $\\rho_{\\kappa}^{\\stsc{H}}$ and score function $\\psi_{\\kappa}^{\\stsc{H}}$}\n    \\label{fig:rho_psi_Huber}\n\\end{figure}\n\n\\begin{figure}[h!]\n    \\centering\n    \\epsfig{file=eps/4/3}\n    \\caption{Tukey-Biweight loss function $\\rho_{\\kappa}^{\\stsc{B}}$ and score function $\\psi_{\\kappa}^{\\stsc{B}}$}\n    \\label{fig:rho_psi_Biweight}\n\\end{figure}\n\nThe main advantage of monotone score functions $\\psi$ is that all solutions of\n(\\ref{eq:M_equations}) are solutions of (\\ref{eq:M_min}). In the case of\nredescending score functions $\\psi$, the estimating equations\n(\\ref{eq:M_equations}) may have multiple solutions corresponding to multiple\nlocal minima of $\\sum_{i=1}^{n}\\rho(r_i(\\boldsymbol\\beta)/\\sthat{\\sigma})$,\nand generally only one of them (the “good” solution) corresponds to the global\nminimizer $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ defined by\n(\\ref{eq:M_min}), which makes the computation of the \\stsc{M}~estimate\nconsiderably more complex.\n\n\\begin{stremark}\nApplying the \\stsc{M}~estimation procedure in the particular case of the\nlocation-scale model (\\ref{eq:location_scale_model}) leads to the\n\\stsc{M}~\\emph{estimators of location and scale}---we just mentioned the\nexistence of these estimators in the previous chapter. The interested reader\nwill find some results relative to these specific estimators in appendix\n\\ref{sec:robreg:appendix1} at the end of this chapter.\n\\end{stremark}\n\n\\subsection{M estimation as a generalization of maximum likelihood (ML) estimation}\n\nThe \\stsc{M}~estimation as defined above may be seen, as already explained, as\na generalization of the \\stsc{LS} or \\stsc{LAD}~estimation, but also as a\ngeneralization of the maximum-likelihood (\\stsc{ML}) estimation (see, for\ninstance, \\citealp{maronna:etal:2006}). Indeed, assuming model\n(\\ref{eq:location_scale_regr_model}) with fixed $\\stvec{x}_i$ and with\n$\\nu_i$, $i = 1, \\dots, n$, i.i.d.\\ of density $f_{0,1}$, the likelihood of\nthe sample $\\{y_1, \\dots, y_n\\}$ is given by                                \\todo{Couldn't we also just use unspecified $f$ instead of $f_{0,1}$?}\n\\[\n    \\frac{1}{\\sigma^{n}}\\prod\\limits_{i=1}^{n}\n    f_{0,1}\\left(\\frac{y_i-\\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma}\\right).\n\\]\nHence, maximum likelihood estimation of the parameters $\\boldsymbol\\beta$\nand $\\sigma$ consists in looking for\n%\n\\begin{align}\n    \\left(\\sthat{\\boldsymbol\\beta}_{\\stsc{ML}}^t,\\sthat{\\sigma}_{\\stsc{ML}}\\right)^{\\!t}\n    &= \\arg\\max_{\\boldsymbol\\beta,\\sigma} \\frac{1}{\\sigma^{n}} \\prod\\limits_{i=1}^{n}\n        f_{0,1}\\left(\\frac{y_i-\\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma}\\right)\n    \\nonumber\\\\\n    &= \\arg\\max_{\\boldsymbol\\beta,\\sigma} \\left[\\sum_{i=1}^{n}\n        \\ln f_{0,1}\\left(\\frac{y_i-\\stvec{x}_i^t\\boldsymbol\\beta}{\\sigma}\\right) - n\\ln\\sigma\\right]\n    \\nonumber\\\\\n    & = \\argmin_{\\boldsymbol\\beta,\\sigma} \\left[\\sum_{i=1}^{n}\n        \\rho_{\\stsc{ML}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right) + n\\ln\\sigma\\right]\n    \\label{eq:ML_beta_sigma_min}\n\\end{align}\n%\nwhere $\\rho_{\\stsc{ML}}(u) = -\\ln f_{0,1}(u)$. If $\\sigma$ is known, the\nminimization problem simply becomes\n%\n\\begin{equation}\\label{eq:ML_beta_min}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{ML}} \n        = \\argmin_{\\boldsymbol\\beta}\\sum_{i=1}^{n} \n            \\rho_{\\stsc{ML}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right)\n\\end{equation}\n%\nand $\\sthat{\\boldsymbol\\beta}_{\\stsc{ML}}$ is solution of the estimating\nequations system\n\\[\n    \\sum_{i=1}^{n} \\psi_{\\stsc{ML}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right) \\stvec{x}_i = \\stvec{0}\n\\]\nwhere $\\psi_{\\stsc{ML}}(u) = \\rho_{\\stsc{ML}}'(u) = - (1/f_{0,1}(u))\nf_{0,1}'(u)$. If $f_{0,1}$ is the standard normal density function,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{ML}}$ coincides with\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$. If $f_{0,1}$ is the density function of\nthe Laplace distribution, that is, if $f_{0,1}(u) =\n\\frac{1}{\\sqrt{2}}\\exp(-\\sqrt{2}|u|)$, $u\\in\\mathbb{R}$, then\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{ML}}$ is equal to\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}}$.\n\nIf $\\sigma$ is not known but is estimated beforehand and fixed in\n(\\ref{eq:ML_beta_min}), the estimating equations system becomes\n\\[\n    \\sum_{i=1}^{n} \\psi_{\\stsc{ML}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right) \\stvec{x}_i = \\stvec{0}\n\\]\nNote that, if $\\boldsymbol\\beta$ and $\\sigma$ are estimated simultaneously,\nthe estimating equations system related to (\\ref{eq:ML_beta_sigma_min}) is\n%\n\\begin{equation}\\label{eq:ML_beta_sigma_equations}\n    \\begin{aligned}\n        \\sum\\limits_{i=1}^{n} \\psi_{\\stsc{ML}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right) \\stvec{x}_i \n        & = \\stvec{0}\n        \\\\\n        \\frac{1}{n} \\sum\\limits_{i=1}^{n} \\rho_{\\stsc{ML};\\mathrm{scale}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right) \n        & = \\delta\n    \\end{aligned}\n\\end{equation}\n%\nwhere $\\rho_{\\stsc{ML};\\mathrm{scale}}(u) = u\\psi_{\\stsc{ML}}(u)$ and\n$\\delta=1$.\n\n\\subsection{Practical implementation of M estimates}\n\\label{subsec:practical_implementation_Mestimate}\n\nLet us first assume, for simplicity, that the scale parameter $\\sigma$ is\nknown. In that case, the regression M-estimate\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is solution of the estimating\nequations system (\\ref{eq:M_equations}) where $\\sthat{\\sigma}$ is replaced by\n$\\sigma$. Defining the weight function $w$ by\n\\[\n    w(u) = \n    \\begin{cases}\n        \\frac{\\psi(u)}{u} & \\text{if $u\\neq0$}\\\\\n        \\psi'(0)          & \\text{if $u=0$}\n    \\end{cases}\n\\]\nthe estimating system (\\ref{eq:M_equations}) can be rewritten as\n%\n\\begin{equation}\\label{eq:weighted_LS_equations}\n    \\sum_{i=1}^{n} w_i r_i(\\boldsymbol\\beta) \\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\nwhere $w_i = w(r_i(\\boldsymbol\\beta)/\\sigma)$. Hence, the equations to solve in\nthe \\stsc{M}~estimation procedure appear as \\emph{weighted} versions of the\nnormal equations (\\ref{eq:LS_equations}) related to \\stsc{LS}~estimation, and\nif the $w_i$'s were known, the equations (\\ref{eq:weighted_LS_equations}) could\nbe solved by applying \\stsc{LS} to $\\sqrt{w_i}y_i$ and $\\sqrt{w_i}\\stvec{x}_i$.\nBut the weights $w_i$ are functions of $\\boldsymbol\\beta$ and depend upon the\ndata, and hence are not known. So we have to use an iterative procedure. Using\nan initial estimate $\\sthat{\\boldsymbol\\beta}_0$ for $\\boldsymbol\\beta$ (for\ninstance, the \\stsc{LAD}~estimate of $\\boldsymbol\\beta$), the weights can be\ncomputed and serve as the start of an \\emph{iteratively reweighted least\nsquares algorithm} (\\stsc{IRWLS}). Note however that the latter is guaranteed\nto converge to the global minimum of (\\ref{eq:M_min}) only if the loss function\n$\\rho$ is convex on the whole real line $\\mathbb{R}$ (which is the case for the\n$\\rho_{c}^{\\stsc{H}}$ functions introduced by Huber).\\footnote{In the case of a\nconvex loss function $\\rho$, the convergence of the algorithm to the global\nminimum of (\\ref{eq:M_min}) is guaranteed whatever the starting point\n$\\sthat{\\boldsymbol\\beta}_0$.}\n\nIf $\\sigma$ is not known, it can be estimated (in a robust way) beforehand\nusing the residuals $r_i(\\sthat{\\boldsymbol\\beta}_0)$, $i = 1, \\dots, n$,\nand then fixed in the iterative procedure described above. It is of course\nalso possible to estimate simultaneously $\\boldsymbol\\beta$ and $\\sigma$ in\nthis procedure, by updating $\\sthat{\\sigma}$ at each iteration (see\n\\citealp{maronna:etal:2006} for more details).\n\n\\subsubsection{Regression M estimate with preliminary scale estimation}\n\nIn practice, we may take the \\stsc{LAD}~estimate as initial estimate\n$\\sthat{\\boldsymbol\\beta}_0$ for $\\boldsymbol\\beta$ (recall that the\n\\stsc{LAD}~estimate does not require estimating a scale). Then we may estimate\n$\\sigma$ using normalized \\stsc{MAD} of the residuals\n$r_i(\\sthat{\\boldsymbol\\beta}_0)$. More precisely, we may take\n\\[\n    \\sthat{\\sigma} = 1.4826 \\cdot \n    \\med_i\\left(\\left|r_i(\\sthat{\\boldsymbol\\beta}_0)\\right|; r_i(\\sthat{\\boldsymbol\\beta}_0) \\neq 0\\right).\n\\]\nThe reason for using only \\emph{non null} residuals is that, since at least\n$(p+1)$ residuals $r_i(\\sthat{\\boldsymbol\\beta}_0) =\nr_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}})$ are equal to zero, determining\nthe \\stsc{MAD} of the $n$ residuals could lead to underestimating $\\sigma$ when\n$p$ is large.\n\nSince $\\sthat{\\boldsymbol\\beta}_{\\stsc{LAD}}$ is regression, scale and\naffine equivariant, it is easy to show that\n%\n\\begin{align*}\n    \\sthat{\\sigma}(\\stmat{X}, \\stvec{y} + \\stmat{X}\\boldsymbol\\gamma)\n        &= \\sthat{\\sigma}(\\stmat{X}, \\stvec{y})\n        &&\\text{for all $\\boldsymbol\\gamma \\in \\mathbb{R}^{p+1}$}\n    \\\\\n    \\sthat{\\sigma}(\\stmat{X}\\stmat{A}, \\stvec{y})\n        &= \\sthat{\\sigma}(\\stmat{X}, \\stvec{y})\n        &&\\text{for any nonsingular $\\stmat{A} \\in \\mathbb{R}^{(p+1)\\times(p+1)}$}\n    \\\\\n\\intertext{and}\n    \\sthat{\\sigma}(\\stmat{X}, \\lambda\\stvec{y}) \n        &= |\\lambda| \\sthat{\\sigma} (\\stmat{X}, \\stvec{y})\n        &&\\text{for all $\\lambda\\in\\mathbb{R}$.}\n\\end{align*}\nHence, $\\sthat{\\sigma}$ is regression and affine invariant, as well as scale\nequivariant, which ensures the regression, scale end affine equivariance of\nthe \\stsc{M}~estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$.\n\n\n\\subsection{Regression quantiles as regression M estimates}\n\nLet\n\\[\n    \\rho_{\\alpha}(u)=\n    \\begin{cases}\n        \\alpha u     & \\text{if $u\\geq0$}\\\\\n        -(1-\\alpha)u & \\text{if $u<0$}\n    \\end{cases}\n\\]\nfor $\\alpha \\in (0,1)$. \\citet{Koenker:1978} defined the \\emph{regression $\\alpha$-quantile} \n$\\sthat{\\boldsymbol\\beta}_{\\alpha}$ as follows:\n%\n\\begin{equation}\\label{eq:quantile_regr_min}\n    \\sthat{\\boldsymbol\\beta}_{\\alpha} \n    = \\argmin_{\\boldsymbol\\beta} \\sum_{i=1}^{n} \\rho_{\\alpha}(y_i-\\stvec{x}_i^t\\boldsymbol\\beta)\n\\end{equation}\n\nThe case $\\alpha=0.5$ corresponds to the \\stsc{LAD}~estimate. Assume the model\n\\[\n    y_i = \\stvec{x}_i^t \\boldsymbol\\beta_{\\alpha} + \\epsilon_i,\n    \\qquad i = 1, \\dots, n\n\\]\nwhere the $\\stvec{x}_i$'s are fixed and the $\\alpha$-quantile of\n$\\epsilon_i$ is zero; this is equivalent to assuming that the\n$\\alpha$-quantile of $y_i$ is, conditionally to $\\stvec{x}_i$, equal to\n$\\stvec{x}_i^t\\boldsymbol\\beta_{\\alpha}$. Then $\\widehat\n{\\boldsymbol\\beta}_{\\alpha}$ defined by (\\ref{eq:quantile_regr_min}) is an\nestimate of $\\boldsymbol\\beta_{\\alpha}$. It may be seen as a generalization of\nthe \\stsc{LAD}~estimate as well as a specific case of \\stsc{M}~estimate.\n\nRegression quantiles are especially useful with heteroskedastic data. There is\na very large literature on regression quantiles; see, for instance,\n\\citet{Koenker:2005}.\n\n\\subsection{Monotone vs. redescending M estimators}\n\nAs already mentioned, taking a loss function $\\rho(u)$ in the minimization\nproblem (\\ref{eq:M_min}) that is less rapidly increasing than the square\nfunction provides a certain robustness of the regression \\stsc{M}~estimate with\nrespect to the vertical points. But what about the robustness of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ with respect to leverage points? To\nanswer to this question, let us recall that\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is solution of the estimating\nequations system (\\ref{eq:M_equations}).\n\nIt is easy to see that \\emph{monotone} \\stsc{M}~estimates break down in\npresence of a single bad leverage point. Indeed, if $\\psi(u)$ is a monotone\nfunction, an $\\stvec{x}$-outlier will dominate the solution of\n(\\ref{eq:M_equations}) in the following sense: if for some $i$, $\\stvec{x}_i$\nis “much larger than the rest”, then in order to make the sum in the left part\nof (\\ref{eq:M_equations}) to zero, the residual\n$r_i(\\sthat{\\boldsymbol\\beta}) = y_i -\n\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}$ must be near zero, that is, the\nregression hyperplane has to fit the point $(\\stvec{x}_i, y_i)$ as well as\npossible, and hence $\\sthat{\\boldsymbol\\beta}$ is essentially determined by\nthis leverage point $(\\stvec{x}_i, y_i)$.\n\nThis does not happen with the \\emph{redescending} \\stsc{M}~estimate since the\nuse of a function $\\psi$ that vanishes for “outlying” residuals allows to find\na solution $\\widehat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ of\n(\\ref{eq:M_equations}) which is not affected by the presence of a bad leverage\npoint $(\\stvec{x}_i, y_i)$ in the data set. Hence, from the robustness\npoint of view, the redescending regression \\stsc{M}~estimators are more interesting\nthan the monotone \\stsc{M}~estimators. Unfortunately, as already explained, the\npractical implementation of \\stsc{M}~estimators is less easy for the\nredescending than for the monotone ones.\n\n\\subsection{GM estimation}\n\nOther approaches have been considered to limit the influence of leverage points\non the estimation of the regression coefficients. For instance, defining\n$\\underline{\\stvec{x}}_i = (x_{i1}, \\ldots, x_{ip})'$ such that\n$\\stvec{x}_i = (1,\\underline{\\stvec{x}}_i')'$, a simple way to robustify a\nmonotone \\stsc{M}~estimate is to downweight the influential\n$\\underline{\\stvec{x}}_i$'s to prevent them from dominating the estimating\nequations. Hence we may define an estimate as solution of\n\\begin{equation}\\label{eq:GM_equations_1}\n    \\sum_{i=1}^{n} \\psi\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right) \n    \\widetilde{w}(d(\\underline{\\stvec{x}}_i)) \\stvec{x}_i = \\stvec{0}\n\\end{equation}\nwhere $\\widetilde{w}$ is a weight function and $d(\\underline{\\stvec{x}}_i)$\nis some measure of the “largeness” of $\\underline{\\stvec{x}}_i$. Here $\\psi$\nis monotone and $\\sthat{\\sigma}$ is simultaneously estimated by an \n\\stsc{M}~estimating equation of the form\n\\[\n    \\frac{1}{n}\\sum_{i=1}^{n} \\rho_{\\mathrm{scale}}\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sigma}\\right)  = \\delta.\n\\]\nIn order to bound the effect of influential points, $\\widetilde{w}$ must be\nsuch that $\\widetilde{w}(t)t$ is bounded.\n\nMore generally, we may let the weights depend on the residuals as well as on\nthe predictor variables, and use a \\emph{generalized} \\stsc{M}~estimate\n(\\stsc{GM}~estimate) $\\sthat{\\boldsymbol\\beta}_{\\stsc{GM}}$ defined as solution\nof\n%\n\\begin{equation}\\label{eq:GM_equations_2}\n    \\sum_{i=1}^{n}\\eta\\left(d(\\underline{\\stvec{x}}_i), \\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}}\\right)\n    \\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\nwhere for each $s$, $\\eta(s,u)$ is a nondecreasing and bounded $\\psi$-function\nof $u$. The estimating equations system (\\ref{eq:GM_equations_1}) may be seen\nas a particular case of (\\ref{eq:GM_equations_2}) when choosing $\\eta(s,u) =\n\\widetilde{w}(s) \\psi(u)$. This particular choice corresponds to the class of\n\\emph{Mallows estimates} (see \\citealp{Mallows:1975}) which has been\nextensively studied in the literature.\n\nThe most usual way to measure the “largeness” of $\\underline{\\stvec{x}}_i$,\n$i=1, \\dots, n$, is to take the \\emph{leverage} of $\\underline{\\stvec{x}}_i$,\nthat is, to consider\n%\n\\begin{equation}\n    \\label{eq:leverage}\n    d(\\underline{\\stvec{x}}_i) = \n    \\sqrt{\\left(\\underline{\\stvec{x}}_i - \\sthat{\\boldsymbol\\mu}_{\\underline{\\stvec{x}}}\\right)^t\n    \\sthat{\\boldsymbol\\Sigma}_{\\underline{\\stvec{x}}}^{-1}\n    \\left(\\underline{\\stvec{x}}_i - \\sthat{\\boldsymbol\\mu}_{\\underline{\\stvec{x}}}\\right)}\n\\end{equation}\n%\nwhere $\\sthat{\\boldsymbol\\mu}_{\\underline{\\stvec{x}}}$ and\n$\\sthat{\\boldsymbol\\Sigma}_{\\underline{\\stvec{x}}}$ are a robust location\nvector and robust dispersion matrix of the $\\underline{\\stvec{x}}_i$'s,\nrespectively (see chapter~\\ref{chap:mv}). If\n$\\sthat{\\boldsymbol\\mu}_{\\underline{\\stvec{x}}}$ and\n$\\sthat{\\boldsymbol\\Sigma}_{\\underline{\\stvec{x}}}$ are the sample mean and\ncovariance matrix, $d(\\cdot)$ is known as the Mahalanobis distance.\n\nAs stated in \\citet{rousseeuw:leroy:1987}, the \\stsc{GM}~estimators were\nconstructed in the hope of bounding the influence of a single outlying\nobservation. Relying on this, optimal choices of $\\psi$ and $\\widetilde{w}$\nwere made (see, among others, \\citealp{Ronchetti:Rousseeuw:1985} for a survey).\nHowever, \\citet{Maronna:1979} have proven that the breakdown point of all\n\\stsc{GM}~estimators is non-zero but decreases as a function of $p$ (i.e., the\nbreakdown point is less or equal to $1/(p+1)$) pointing out that a\n\\stsc{GM}~estimator is interesting to be used only when the number of\nexplanatory variables is very small. Furthermore, \\citet{maronna:etal:2006}\nshow that, to obtain affine equivariance of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{GM}}$, it is necessary that\n$\\sthat{\\boldsymbol\\mu}_{\\underline{\\stvec{x}}}$ and\n$\\sthat{\\boldsymbol\\Sigma}_{\\underline{\\stvec{x}}}$ used in (\\ref{eq:leverage})\nare affine equivariant, which presents the same computational difficulties as\nfor redescending \\stsc{M}~estimates and reduce substantially the appeal of this\nestimator.\n\n\\section{Robust regression with a high breakdown point}\n\nAs explained previously, \\stsc{LS}~regression is now being criticized more and\nmore for its dramatic lack of robustness. Indeed, one single outlier can have\nan arbitrarily large effect on the estimate: the breakdown point\n$\\varepsilon^*$ of $\\sthat{\\beta}_\\stsc{LS}$ is clearly equal to zero.\nAlthough \\stsc{LAD}~regression protects against outlying $y_i$, it cannot\ncope with grossly aberrant values of $\\stvec{x}_i$: \\stsc{LAD}~regression\nyields the same value $\\varepsilon^*=0$ as \\stsc{LS}. \\stsc{M}~estimation\nprovides a certain robustness with respect to vertical points, but not with\nrespect to bad leverage points when the loss function $\\rho$ is unbounded: the\nbreakdown point $\\varepsilon^*$ associated with a monotone \\stsc{M}~estimator\nis then still equal to zero.\n\nBecause of this vulnerability to bad leverage points, generalized \n\\stsc{M}~estimators (\\stsc{GM}~estimators) were introduced, with the basic purpose of\nbounding the influence of outlying $\\stvec{x}_i$. It turns out, however, that\nthe GM-estimators now in use have a breakdown point of at most $1/(p+1)$, where\n$(p+1)$ is the dimension of $\\stvec{x}_i$. Various other estimators have been\nproposed by \\citet{Theil:1950}, \\citet{Brown:1951}, \\citet{Sen:1968},\n\\citet{Jaeckel:1972}, and \\citet{Andrews:1974}, but none of them achieves\n$\\varepsilon^*=30\\%$ in the case of simple regression ($p=1$).\n\nAll of this raises the question whether robust regression with a high breakdown\npoint is at all possible. The affirmative answer was given by\n\\citet{Siegel:1982}, who proposed an estimator (the \\emph{repeated median})\nwith a 50\\% breakdown point. Note that 50\\% is the best that can be expected:\nfor larger amounts of contamination, it becomes impossible to distinguish\nbetween the “good” and the “bad” parts of the sample. Siegel's estimator can be\ncalculated explicitly but is not equivariant for linear transformations of the\n$\\stvec{x}_i$ (it is not affine equivariant). This explains why we do not\nstudy this estimator in more details and prefer to present other estimators\nintroduced by Rousseeuw and Yohai, and all based on a robust scale measure.\n\n\\subsection{LTS and LMS estimation}\n\nRobustness can be achieved by tackling the estimation of the regression\nparameters vector $\\boldsymbol\\beta$ from a different perspective. We know that\n\\stsc{LS}~estimation is based on the minimization of the variance of the\nresiduals. However, since the variance is highly sensitive to outliers,\nL\\stsc{S}~estimate will be sensitive to them as well. An interesting idea would then\nconsist in minimizing a measure of the residual dispersion\n$s(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))$ that is less\nsensitive to extreme residuals.\n\nRelying on this idea, \\citet{Rousseeuw:1983} introduced the \\emph{Least Trimmed\nSum of Squares} (\\stsc{LTS}) estimator which is based on the minimization of a\ntrimmed variance of the residuals:\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{LTS}}\n     = \\argmin_{\\boldsymbol\\beta}s_{\\stsc{LTS}}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n\\]\nwith\n\\[\n    s_{\\stsc{LTS}}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n    = \\sqrt{\\frac{1}{\\lceil\\alpha n\\rceil} \n      \\sum_{i=1}^{\\lceil\\alpha n\\rceil}r_{(i)}(\\boldsymbol\\beta)^2}\n\\]\nwhere $1/2 \\leq \\alpha \\leq 1$ and $r_{(1)}(\\boldsymbol\\beta)^2 \\leq \\dots\n\\leq r_{(n)}(\\boldsymbol\\beta)^2$ are the ordered squared residuals. The\nconstant $\\alpha$ determines the trade-off between the robustness and the\nefficiency of the estimator. Indeed, if $\\alpha$ tends to one, the \n\\stsc{LTS}~estimator tends to the \\stsc{LS}~estimator. In contrast, if $\\alpha = 1/2$, the\n\\stsc{LTS}~estimator will resist up to 50\\% of outlying data and, consequently,\nwill have a breakdown point equal to 50\\%. Unfortunately, even if\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{LTS}}$ converges to $\\boldsymbol\\beta$ at a\nrate of $1/\\sqrt{n}$, its efficiency is low (under Gaussian conditions, the\nasymptotic relative efficiency of $\\sthat{\\boldsymbol\\beta}_{\\stsc{LTS}}$ with\nrespect to $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ reaches only 7\\% when 50\\% of\nthe data are trimmed).\n\nDespite its relatively low efficiency, the \\stsc{LTS}~estimator is quite popular\nbecause it can be quickly computed using the \\emph{Fast-lts algorithm}\ndeveloped by \\citet{rousseeuw&vdriessen99}; this estimator is available in\nStata through the command \\stcmd{robreg lts}.\n\nFollowing the same idea, \\citet{rousseeuw:1984} introduced the \\emph{Least Median\nSquares} (\\stsc{LMS}) estimator based on the minimization of the median of\nthe squared residuals:\\footnote{The variance of the residuals corresponds to\nthe arithmetic mean of the squared residuals; why not replace the mean by the\nmore robust median?}\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{LMS}} \n    = \\argmin_{\\boldsymbol\\beta} s_{\\stsc{LMS}}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n\\]\nwith\n\\[\n    s_{\\stsc{LMS}}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta)) \n    = \\sqrt{\\mathrm{med}_i\\;r_i(\\boldsymbol\\beta)^2}.\n\\]\n\\stsc{LMS} satisfies $\\varepsilon^* = 50\\%$ but has unfortunately a very low\nefficiency because of its $1/\\sqrt[3]{n}$ convergence rate. The \n\\stsc{LMS}~estimator is available in Stata through the command \\stcmd{robreg lms}.        \\todo{Add paragraph on LQS, as this is also supported by robreg.}\n\n\\subsection{S estimation}\n\nFollowing always the same principle, \\citet{rousseeuw:yohai:1984} have\nintroduced a more general class of estimators: the regression\n\\stsc{S}~estimators.\n\nIn order to well understand the basic intuition behind the \\stsc{S}~estimation,\nlet us consider once again the \\stsc{LS}~estimation. For \\stsc{LS}~estimation,\nwe actually are looking for the value of the regression coefficients vector\n$\\boldsymbol{\\beta}$ that minimizes the variance (or standard deviation) of the\nresiduals $r_i(\\boldsymbol\\beta)$, $i = 1, \\dots, n$. More formally, we have\n\\[\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS} \n    = \\argmin_{\\boldsymbol\\beta} s_\\stsc{LS}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n\\]\nwith\n\\[\n    s_\\stsc{LS}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta)) \n    = \\sqrt{\\frac{1}{n}\\sum_{i=1}^{n} r_i(\\boldsymbol\\beta)^2}.\n\\]\nThe dispersion measure $s_\\stsc{LS}$ may be characterized as follows: given\nthe realizations $e_1, \\dots, e_n$ of $n$ i.i.d.\\ random variables whose\ndistribution is characterized by a mean equal to zero and a scale parameter\n$\\sigma$, the dispersion measure $s_\\stsc{LS}(e_1, \\dots, e_n)$ of the\nsample is an estimate of $\\sigma$ satisfying the equality\n\\[\n    \\frac{1}{n}\\sum_{i=1}^{n} \\left(\\frac{e_i}{s_\\stsc{LS}(e_1, \\dots, e_n)}\\right)^{\\!\\!2} = 1\n\\]\nor, taking $\\rho(u) = u^2$,\n\\[\n    \\frac{1}{n}\\sum_{i=1}^{n} \\rho\\left(\\frac{e_i}{s_\\stsc{LS}(e_1, \\dots, e_n)}\\right) = 1.\n\\]\nMoreover, if $u \\sim \\mathcal{N}(0,1)$, then $E(\\rho(u)) = E(u^2) = 1$.\n\nThe \\stsc{S}~estimation procedure proposed by \\citet{rousseeuw:yohai:1984}\nrelies on the same philosophy as the one underlying the \\stsc{LS}~estimation,\nbut introduces robustness by using specific robust residual dispersion measures\nwhich correspond to \\stsc{M}~estimators of the scale parameter $\\sigma$. More\nformally, given the realizations $e_1, \\dots, e_n$ of $n$ i.i.d.\\ random\nvariables with scale parameter $\\sigma$ (and a location parameter equal to\nzero), the \\stsc{M}~estimate $\\sthat{\\sigma}_{\\rho}$ of $\\sigma$ is the\nmeasure of dispersion $s_{\\rho}(e_1, \\dots, e_n)$ defined as the solution\nof the equation\n%\n\\begin{equation}\\label{eq:M_scale_equation}\n    \\frac{1}{n}\\sum_{i=1}^{n} \\rho\\left(\\frac{e_i}{s_{\\rho}(e_1, \\dots, e_n)}\\right) = \\delta\n\\end{equation}\n%\nwhere\n\\begin{itemize}\n    \\item the function $\\rho(\\cdot)$ is positive, even (such that\n    $\\rho(0) = 0$), non decreasing for positive values and bounded;\n\n    \\item the constant $\\delta$ is defined such that $\\sthat{\\sigma}_{\\rho} =\n    s_{\\rho}(e_1, \\dots, e_n)$ is a consistent estimate of $\\sigma$ for the\n    Gaussian regression model (generally $\\delta$ is defined by $\\delta =\n    E(\\rho(u))$ for $u \\sim \\mathcal{N}(0,1)$; the consistency parameter\n    $\\delta$ would therefore be nothing else than the population counterpart of\n    the lefthand side of equation (\\ref{eq:M_scale_equation})).\n\\end{itemize}\n\nThen \\citet{rousseeuw:yohai:1984} defined an \\stsc{S}~estimate of\n$\\boldsymbol\\beta$ by\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho} \n    = \\argmin_{\\boldsymbol\\beta}s_{\\rho} (r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol{\\beta}))\n\\]\nwhere $s_{\\rho}$ is a measure of dispersion defining a scale \\stsc{M}~estimator, that is,\nsatisfying\n%\n\\begin{equation}\\label{eq:M_scale_equation_res}\n    \\frac{1}{n}\\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\boldsymbol{\\beta})}%\n        {s_{\\rho}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))}\\right) = \\delta\n    \\qquad\\text{for all $\\boldsymbol\\beta \\in \\mathbb{R}^{p+1}$.}\n\\end{equation}\n\nOne important fact is that an \\stsc{S}~estimate of $\\boldsymbol\\beta$ is also an\n\\stsc{M}~estimate. More precisely, $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$\nis an \\stsc{M}~estimate (in the sense of \\ref{eq:M_min}) in that\n%\n\\begin{equation}\\label{eq:S_Minequality_1}\n    \\sum_{i=1}^{n}\\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho})}{\\sthat{\\sigma}_{\\rho}}\\right) \n    \\leq \\sum_{i=1}^{n}\\rho\\left(\\frac{r_i(\\widetilde{\\boldsymbol\\beta})}{\\sthat{\\sigma}_{\\rho}}\\right)\n    \\qquad\n    \\text{for all $\\widetilde{\\boldsymbol\\beta} \\in \\mathbb{R}^{p+1}$}\n\\end{equation}\n%\nwhere the residuals are standardized by the same scale \\stsc{M}~estimate\n$\\sthat{\\sigma}_{\\rho} =\ns_{\\rho}(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}),\\allowbreak\n\\dots,\\allowbreak r_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}))$ of $\\sigma$\non both sides of the inequality (\\ref{eq:S_Minequality_1}). Indeed,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ minimizes the residual dispersion\nmeasure $s_{\\rho}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))$\nwhich satisfies (\\ref{eq:M_scale_equation_res}). This means that, if we denote\n$\\sthat{\\sigma}_{\\rho} =\ns_{\\rho}(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}), \\dots,\nr_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}))$ and\n$\\widetilde{\\sigma}_{\\rho} = s_{\\rho}(r_1(\\widetilde{\\boldsymbol\\beta}),\n\\dots, r_n(\\widetilde{\\boldsymbol\\beta}))$ for $\\widetilde{\\boldsymbol\\beta}\n\\in \\mathbb{R}^{p+1}$, we have $\\sthat{\\sigma}_{\\rho} \\leq\n\\widetilde{\\sigma}_{\\rho}$ and\n\\[\n    \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho})}{\\sthat{\\sigma}_{\\rho}}\\right) \n    = n\\delta\n    = \\sum_{i=1}^{n}\\rho\\left(\\frac{r_i(\\widetilde{\\boldsymbol\\beta})}{\\widetilde{\\sigma}_{\\rho}}\\right)\n\\]\nThen, since $\\rho$ is monotone and $\\sthat{\\sigma}_{\\rho} \\leq\n\\widetilde{\\sigma}_{\\rho}$, we necessarily have\n\\[\n    \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho})}{\\sthat{\\sigma}_{\\rho}}\\right)\n    = \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\widetilde{\\boldsymbol\\beta})}{\\widetilde{\\sigma}_{\\rho}}\\right)\n    \\leq \\sum_{i=1}^{n}\\rho\\left(\\frac{r_i(\\widetilde{\\boldsymbol\\beta})}{\\sthat{\\sigma}_{\\rho}}\\right)\n\\]\nwhich proves (\\ref{eq:S_Minequality_1}).\n\nIf $\\rho$ has a derivative $\\psi$, it follows that\n$\\sthat{\\boldsymbol{\\beta}}_{\\stsc{S};\\rho}$ is also an \\stsc{M}~estimate in\nthe sense of (\\ref{eq:M_equations}), but with the condition that the scale\nparameter $\\sigma$ is estimated simultaneously with $\\boldsymbol\\beta$. More\nformally, $\\boldsymbol\\beta$ is estimated by\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ and $\\sigma$ by\n$\\sthat{\\sigma}_{\\rho}=s_{\\rho}(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}),\n \\dots, r_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}))$, with\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ and $\\sthat{\\sigma}_{\\rho}$ such that\n\\[\n    \\begin{aligned}\n        \\sum_{i=1}^{n} \n        \\psi\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho})}{\\sthat{\\sigma}_{\\rho}}\\right) \\stvec{x}_i \n        & = \\stvec{0}\n        \\\\\n        \\frac{1}{n} \\sum_{i=1}^{n}\n        \\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho})}{\\sthat{\\sigma}_{\\rho}}\\right)\n        & = \\delta\n    \\end{aligned}\n\\]\nNote that, taking $\\rho(u) = u^2$ and $\\delta=1$, we retrieve\nthe standard \\stsc{LS}~minimization problem.\n\nThe choice of $\\rho(\\cdot)$ is crucial to have good robustness\nproperties\\footnote{Note that the function $\\rho$ defining the \n\\stsc{S}~estimator needs to be \\emph{bounded} to get a positive breakdown point for the\nregression estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$.} and a high\nGaussian efficiency. The Tukey-Biweight function defined in\n(\\ref{eq:Tukey_Biweight_function}), with $\\kappa = 1.547$, is a common choice.\nThis \\stsc{S}~estimator resists to a contamination of up to 50\\% of outliers\nand, hence, has a breakdown point of 50\\%. Unfortunately, this \n\\stsc{S}~estimator has a Gaussian efficiency of only 28.7\\%. If $\\kappa = 5.182$, the\nGaussian efficiency raises to 96.6\\% but the breakdown point drops to 10\\%.\nActually an \\stsc{S}~estimator cannot simultaneously have a high breakdown\npoint and a high efficiency. In particular, \\citet{Hossjer:1992} has shown that the\nmaximum Gaussian asymptotic efficiency of an \\stsc{S}~estimator with a\nbreakdown point of 50\\% is 33\\%.\n\n\\subsection{MM estimation}\n\\label{subsec:MM_estimation}\n\nWe have just seen that \\stsc{S}~estimation does not allow to reach jointly a\nhigh breakdown point and a high Gaussian efficiency. How should we then\nestimate the parameters of the regression model if we aim to combine high\nefficiency under normal errors with a high breakdown point? Several proposals\nhave been made: the \\stsc{MM}~estimators of \\citet{yohai:1987}, the $\\tau$\nestimators of \\citet{Yohai:1988}, the constrained \\stsc{M} (\\stsc{CM})\nestimators of \\citet{Mendes:1996}. All these estimators can have a Gaussian\nasymptotic efficiency as close to 1 as desired, and simultaneously a breakdown\npoint of 50\\%. Furthermore, \\citet{Gervini:2002} proposed one estimator that\nhas a breakdown point of 50\\% and an efficiency equal to 1.\n\nLet us here focus our attention on the regression \\stsc{MM}~estimators since\nthey are based on the \\stsc{M} and \\stsc{S}~estimation procedures studied in\nthe previous sections. An \\stsc{MM}~estimator is defined in two successive\nsteps:\n\n\\begin{enumerate}\n    \\item Take an \\stsc{S}~estimate $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$\n    with high breakdown point (but possibly low Gaussian efficiency) where the scale\n    measure $s_{\\rho_0}$ is defined by\n    \\[\n        \\frac{1}{n} \\sum_{i=1}^{n}\\rho_0\\left(\\frac{r_i(\\boldsymbol\\beta)}\n            {s_{\\rho_0}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))}\\right) \n            = \\delta\n        \\qquad\\text{for all $\\boldsymbol\\beta\\in\\mathbb{R}^{p+1}$}\n    \\]\n    ($s_{\\rho_0}$ is associated with the function $\\rho_0(\\cdot)$ and the\n    constant $\\delta$). Let $\\sthat{\\sigma}_{\\rho_0} =\n    s_{\\rho_0}(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}),\\allowbreak\n    \\dots,\\allowbreak r_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}))$.\n\n    \\item Take any other function $\\rho(\\cdot) \\leq \\rho_0(\\cdot)$ and find\n    the \\stsc{MM}~estimate $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$\n    as a local minimum of\n    %\n    \\begin{equation}\\label{eq:MM_min}\n        \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}_{\\rho_0}}\\right)\n    \\end{equation}\n    %\n    such that\n    %\n    \\begin{equation}\\label{eq:MM_inequality}\n        \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right)\n     \\leq \\sum_{i=1}^{n}\\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})}\n         {\\sthat{\\sigma}_{\\rho_0}}\\right).\n    %\n    \\end{equation}\n    %\n\\end{enumerate}\n\nThe key result is given in \\citet{yohai:1987}. Recall that all local minima of\n(\\ref{eq:MM_min}) are solutions of the estimating equations\n(\\ref{eq:M_equations}) with $\\psi(u) = \\rho'(u)$ and $\\sthat{\\sigma} =\n\\sthat{\\sigma}_{\\rho_0}$:\n%\n\\begin{equation}\\label{eq:MM_equations}\n    \\sum_{i=1}^{n} \\psi\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}_{\\rho_0}}\\right)\n    \\stvec{x}_i = \\stvec{0}\n\\end{equation}\n%\n\\citeauthor{yohai:1987} shows that if $\\rho(u) \\leq \\rho_0(u)$ for all $u \\in\n\\mathbb{R}$ and if (\\ref{eq:MM_inequality}) is satisfied, then\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ is consistent. Moreover,\nit can be shown that the \\stsc{MM}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ has the same breakdown\npoint than the \\stsc{S}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ of the first step, determined by\nthe function $\\rho_0(\\cdot)$. If, furthermore,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ is any solution of\n(\\ref{eq:MM_equations}), then it has the same efficiency---this efficiency is\ndetermined by the choice of the function $\\rho(\\cdot)$---as the global minimum\nof (\\ref{eq:MM_min}). In conclusion, it is not necessary to find the absolute\nminimum of (\\ref{eq:MM_min}) to ensure consistency, a high breakdown point and\na high efficiency.\n\nIt is common to use a Tukey-Biweight $\\rho_{\\kappa}^{\\stsc{B}}(\\cdot)$ function\nfor both the preliminary \\stsc{S}~estimator and the final \\stsc{MM}~estimator.\nThe tuning constant $\\kappa$ can be set to 1.547 for the preliminary \n\\stsc{S}~estimator to guarantee a 50\\% breakdown point, and it can be set to 4.685 for\nthe second step \\stsc{MM}~estimator to guarantee a 95\\% asymptotic Gaussian\nefficiency of this final estimator. Note, however, that though not\nbreaking-down, an \\stsc{MM}~estimator with a very high efficiency may have a\nhigh bias \\emph{under moderate contamination}: the larger the efficiency, the\nlarger the bias. It is therefore important to choose the efficiency so as to\nmaintain reasonable bias control. Results in Section 5.9 of\n\\citet{maronna:etal:2006} show that an efficiency of 0.95 yields too high a\nbias, and hence it is safer to choose an efficiency of 0.85 which gives a\nsmaller bias while retaining a sufficiently high efficiency. We will raise once\nagain this problem of bias in section~\\ref{subsec:Hausman}.\n\n\\subsubsection{Numerical computation of the S and MM estimate}\n\nThe numerical computation of the estimate\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ at the second step of the\nprocedure follows the approach described in\nsection~\\ref{subsec:practical_implementation_Mestimate}: starting with\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$, we use the iteratively\nreweighted least squares (\\stsc{IRWLS}) algorithm to attain a solution of the\nequation (\\ref{eq:MM_equations}). It may be shown (see\n\\citet{maronna:etal:2006} that (\\ref{eq:MM_min}) decreases at each iteration,\nwhich insures (\\ref{eq:MM_inequality}). Hence, once the initial \n\\stsc{S}~estimate is computed, $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$\ncomes at almost no additional computational cost.\n\nWe programmed an \\stsc{S} and an \\stsc{MM}~estimator in Stata (with\nTukey-Biweight loss function) using the fast algorithm of\n\\citet{salibian:yohai:2006} for computing the \\stsc{S}~estimator. Explicit\nformulas for the estimators are not available and it is necessary to call on\nnumerical optimization to compute them. We present just below a sketch of the\nfast algorithm for regression \\stsc{S}~estimates we implemented in Stata.\n\nConsider an estimate $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ defined as\n%\n\\begin{equation}\\label{eq:S_min}\n    \\argmin_{\\boldsymbol\\beta\\in\\mathbb{R}^{p+1}}\n    s_{\\rho}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta)).\n\\end{equation}\n%\nAn approximate solution of (\\ref{eq:S_min}) can be obtained by finding\n$\\sthat{\\boldsymbol\\beta}$ equal to\n\\[\n    \\argmin_{\\boldsymbol\\beta\\in\\mathcal{D}_{N}}\n    s_{\\rho}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n\\]\nwhere\n\\[\n    \\mathcal{D}_{N} = \\{\\sthat{\\boldsymbol\\beta}_1, \\dots, \\sthat{\\boldsymbol\\beta}_{N}\\}\n\\]\nis a finite set of well selected candidates for\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$. One way to select these candidates\nis by subsampling elementary sets among the sample $(\\stvec{x}_1, y_1),\n\\dots, (\\stvec{x}_n,y_n)$ (see \\citealp{rousseeuw:1984}). More formally,\ntake a first random subsample of $(p+1)$ observations\\footnote{Recall that\n$(p+1)$ is the number of regression parameters to estimate, that is the\ndimension of the regression coefficients vector $\\boldsymbol\\beta$ to estimate.}\n\\[\n    (\\stvec{x}_{i_1}, y_{i_1}), \\dots, (\\stvec{x}_{i_{(p+1)}}, y_{i_{(p+1)}});\n\\]\nthen the candidate $\\sthat{\\boldsymbol\\beta}_1$ is obtained by fitting a\nhyperplane containing these $(p+1)$ points:\n\\[\n    \\stvec{x}_{i_{j}}^t \\sthat{\\boldsymbol\\beta}_1 = y_{i_j},\\quad j = 1, \\dots, p+1.\n\\]\nTaking $N$ subsamples we obtain the $N$ candidates. Note that if a subsample\nis collinear, it is replaced by another.\n\nHow large should $N$ be? We have to guarantee that $\\mathcal{D}_{N}$ includes\nat least one “good” candidate with high probability, say $(1 - \\alpha)$ (with,\nfor example, $\\alpha = 0.01$). A necessary condition to have a “good” candidate\nis that it comes from a clean subsample, i.e., a subsample without outliers.\n\nThe probability of getting a clean subsample depends on the fraction of\noutliers in the sample and on $p$. When the fraction of outliers in the sample\nincreases, the probability of getting a clean subsample decreases. Suppose the\nsample contains a proportion $\\xi$ of outliers. Then the probability of an\noutlier-free subsample is $\\gamma = (1-\\xi)^{p+1}$, and the probability of at\nleast one clean subsample among the $N$ selected subsamples is equal to\n$1-(1-\\gamma)^N$. If we want this probability to be larger than $(1-\\alpha)$,\nwe must have\n\\[\n    \\log\\alpha \\geq N\\log(1-\\gamma) \\approx -N\\gamma\n\\]\nand hence\n%\n\\begin{equation}\\label{eq:N}\n    N \\geq \\frac{|\\log\\alpha|}{|\\log(1 - (1-\\xi)^{p+1})|}\n    \\approx \\frac{|\\log\\alpha|}{(1-\\xi)^{p+1}}\n\\end{equation}\n%\nfor $p$ not too small (see \\citealp{Salibian-Barrera:2004}). Therefore $N$\nmust grow exponentially with $p$.\n\nThe following observation allows to save much computing time. Suppose we have\nexamined $(M-1)$ subsamples and\n\\[\n    \\sthat{\\sigma}_{\\rho;M-1} = \n    s_{\\rho} \\left(r_1(\\widehat{\\boldsymbol\\beta}_{M-1}), \\dots,\n    r_n(\\widehat{\\boldsymbol\\beta}_{M-1})\\right)\n\\]\nis the current minimum of the residual dispersion measure $s_{\\rho}$. Now we\ndraw the $M$-th subsample which yields the candidate\n$\\widehat{\\boldsymbol\\beta}_{M}$. Let us consider $\\sthat{\\sigma}_{\\rho;M} =\ns_{\\rho}(r_1(\\sthat{\\boldsymbol\\beta}_{M}),\\allowbreak \\dots,\\allowbreak\nr_n(\\sthat{\\boldsymbol\\beta}_{M}))$. Since $\\rho$ is a monotone function, the\ninequality $\\sthat{\\sigma}_{\\rho;M} < \\sthat{\\sigma}_{\\rho;M-1}$ implies that\n%\n\\begin{equation}\\label{eq:S_algorithm}\n    n\\delta = \\sum_{i=1}^{n} \n    \\rho\\left(\\frac{r_i(\\widehat{\\boldsymbol\\beta}_{M})}{\\sthat{\\sigma}_{\\rho;M}}\\right)\n    \\geq \\sum_{i=1}^{n}\n    \\rho\\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta}_{M})}{\\sthat{\\sigma}_{\\rho;M-1}}\\right).\n\\end{equation}\n%\nConsequently, if we observe that $\\sum_{i=1}^{n}\n\\rho(r_i(\\sthat{\\boldsymbol\\beta}_{M})/\\sthat{\\sigma}_{\\rho;M-1}) > n\\delta$,\nthis necessarily means that $\\sthat{\\sigma}_{\\rho;M} \\geq\n\\sthat{\\sigma}_{\\rho;M-1}$ and we may spare the effort of computing the scale\nestimate $\\sthat{\\sigma}_{\\rho;M}$ and discard\n$\\widehat{\\boldsymbol\\beta}_{M}$. Therefore $\\sthat{\\sigma}_{\\rho}$ has to be\ncomputed only for those subsamples that verify the inequality\n(\\ref{eq:S_algorithm}).\n\nAlthough the $N$ given by (\\ref{eq:N}) ensures that the approximation\n$\\sthat{\\boldsymbol\\beta}$ of $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ \nhas the desired breakdown point, it does not imply that it is a good\napproximation to the exact \\stsc{S}~estimate. To solve this problem, \n\\citet{salibian:yohai:2006} have proposed a procedure based on a “local\nimprovement” step of the resampling initial candidates. This\nallows for a substantial reduction of the number of candidates required to\nobtain a good approximation to the optimal solution.\n\nThis algorithm can be called in Stata either directly using the \\stcmd{robreg\ns} function\\footnote{The default values that are used in Stata for the\nimplementation of the fast \\stsc{S}~algorithm are $\\xi = 0.2$ and $\\alpha =\n0.01$.} or indirectly using the \\stcmd{robreg mm} function developed to compute\n\\stsc{MM}~estimate, and invoking the \\stcmd{initial} option. Once the \n\\stsc{S}~estimate is obtained, the \\stsc{MM}~estimate directly follows by applying the\niteratively reweighted least squares algorithm up to convergence. As far as\ninference is concerned, standard errors robust to heteroskedasticity (and\nasymmetric errors) are computed according to the formulas available in the\nliterature (see Section \\ref{sec:inference}).\n\n\\subsection{MS estimation}\n\nExplicit formulas for $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho}$ are generally\nnot available and, as explained in the previous section, empirical\nimplementation of \\stsc{S}~estimation requires numerical optimization based on\na subsampling algorithm. But this method presents an Achille's heel: it becomes\ninapplicable in practice when several \\emph{dummy} explanatory variables are\ninvolved in the regression model (\\ref{eq:linear_regr_model}). Indeed, when\nseveral of the explanatory variables are binary, there is a high probability\nthat random selection of subsamples yields collinear subsamples.\n\nTo cope with this, \\citet{maronna:yohai:2000} have introduced the \\stsc{MS}~estimator.\nThe intuition behind this estimator is simple. For the sake of clarity, let us\nseparate continuous and dichotomous variables in (\\ref{eq:linear_regr_model})\nand rewrite the regression model equation as follows:\n%\n\\begin{equation}\\label{eq:linear_regr_model_MS}\n    y = (\\beta_0 + \\beta_1x_1 + \\dots + \\beta_{p_1}x_{p_1})\n    + (\\beta_1^*x_1^* + \\dots + \\beta_{p_2}^*x_{p_2}^*) + \\varepsilon\n\\end{equation}\n%\nwhere $x_1, \\dots, x_{p_1}$ are $p_1$ continuous explanatory variables and\n$x_1^*, \\dots, x_{p_2}^*$ are $p_2$ dichotomous explanatory variables ($p = p_1\n+ p_2$). If $\\boldsymbol\\beta = (\\beta_0, \\beta_1, \\dots, \\beta_{p_1})^t$ was\nknown in equation (\\ref{eq:linear_regr_model_MS}), then $\\boldsymbol\\beta^*% =\n(\\beta_1^*, \\dots, \\beta_{p_2}^*)^t$ would be robustly estimated using a\nmonotone \\stsc{M}~estimator (since $x_1^*, \\dots, x_{p_2}^*$ are all dummy\nvariables, the data set can only contain, at worst, vertical outliers). On the\nother hand, if $\\boldsymbol\\beta^*$ was known, then $\\boldsymbol\\beta$ should\nbe estimated using an \\stsc{S}~estimator\\footnote{Since $x_1, \\dots, x_{p_1}$\nare continuous explanatory variables, we cannot assume that there are no\nleverage points.} and the subsampling algorithm should not generate collinear\nsubsamples since all explanatory variables are continuous. The idea is then to\nalternate these two estimators till convergence.\n\nTechnically speaking, an \\stsc{MS}~regression estimate is obtained iteratively;\nat the $k$-th step, we define $\\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{(k)}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{*(k)}$ as follows. Let $s_\\rho$ be a\nmeasure of dispersion satisfying (\\ref{eq:M_scale_equation_res}), $\\stvec{x}_i\n= (1, x_{i1}, \\dots, x_{ip_1})^t$ and $\\stvec{x}_i^* = (x_{i1}^*, \\dots,\nx_{ip_2}^*)^t$:\n\\[\n    \\begin{aligned}\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{(k)} \n        & = \\argmin_{\\boldsymbol\\beta \\in \\mathbb{R}^{p_1 + 1}}\n        s_\\rho\\left(\\left[y_i - (\\stvec{x}_i^*)^t \\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{*(k-1)}\\right] \n        - \\stvec{x}_i^t \\boldsymbol\\beta; i = 1, \\dots, n\\right)\n        \\\\\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{*(k)} \n        & = \\argmin_{\\boldsymbol\\beta^* \\in \\mathbb{R}^{p_2}}\n        \\sum_{i=1}^{n} \\rho\\left(\\frac{\\left[y_i - \\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{(k-1)}\\right] \n        - \\left(\\stvec{x}_i^*\\right)^t \\boldsymbol\\beta^*}{\\sthat{\\sigma}^{(k-1)}}\\right)\n    \\end{aligned}\n\\]\nwhere \n\\[\n    \\sthat{\\sigma}^{(k-1)} = s_\\rho \n    \\left(y_i - \\stvec{x}_i^t \\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{(k-1)}\n    - (\\stvec{x}_i^*)^t \\sthat{\\boldsymbol\\beta}_{\\stsc{MS}}^{*(k-1)}\n    ; i = 1, \\dots, n\\right).\n\\]\nNote that \\stcmd{robreg s} and \\stcmd{robreg mm} automatically recognize the\npresence of dummy variables among the explanatory variables and, if\nappropriate, automatically apply the \\stsc{MS}~procedure.\n\nUnfortunately, as stated above, the price to pay for robustness is efficiency.\nHowever this \\stsc{MS}~estimator can be particularly helpful in the fixed\neffects panel data models, as suggested by \\citet{bramati:croux:2007}.\n\n\\section{Robust inference for M, S and MM estimators}\n\\label{sec:inference}\n\nConsistency and asymptotic normality of \\stsc{M}~estimators under the\nassumption of i.i.d.\\ error terms have been studied by \\citet{Yohai:1979} and\nfor \\stsc{MM}~estimators by \\citet{yohai:1987}. Under fairly general\nconditions, allowing also for heteroskedasticity, asymptotic normality for\n\\stsc{S} and \\stsc{MM}~estimators has been shown by\n\\citet{Salibian-Barrera:2004} in the location case. Some of these results are\nsummarized in \\citet{maronna:etal:2006} with a distinction made between the\ncase of \\emph{fixed} predictors and the case of \\emph{random} predictors.\n\n\\citet{Croux:2003} have established the asymptotic normality of \\stsc{M},\n\\stsc{S} and \\stsc{MM}~estimators in the regression case under quite general\nconditions: they only assume that the observations $(\\stvec{x}_1, y_1), \\dots,\n(\\stvec{x}_n, y_n)$ are generated by a \\emph{stationary} and \\emph{ergodic}\nprocess $H$.\\footnote{A \\emph{stationary} process is a stochastic process whose\njoint probability distribution does not change when shifted in time or space.\nConsequently, parameters such as the mean and the variance, if they exist, also\ndo not change over time or position. Hence, the mean and the variance of the\nprocess do not follow trends. Furthermore, a stochastic process is said to be\n\\emph{ergodic} if its statistical properties (such as its mean and variance)\ncan be estimated consistently from a single, sufficiently long sample\n(realization) of the process.} Under this assumption, the observations do not\nneed to be independent, we may have heteroskedasticity (the processes\n$\\stvec{x}_i$ and $\\varepsilon_i$ are not necessarily independent) and the\ndistribution of the error terms is not necessarily symmetric. In this context,\nthe authors of \\citet{Croux:2003} have showed that the \\stsc{M}, \\stsc{S} and\n\\stsc{MM}~estimators of the regression parameters $\\boldsymbol\\beta$ and of the\nscale parameter $\\sigma$ are first-order equivalent with exactly-identified \\stsc{GMM}\n(Generalized Method of Moments) estimators and have then deduced the asymptotic\nvariance matrix of the \\stsc{M}, \\stsc{S} and \\stsc{MM}~estimators of\n$\\boldsymbol\\beta$ from results established for \\stsc{GMM} (see\n\\citealp{Hansen:1982}). The interest of the results of \\citet{Croux:2003} is\nmultiple. They propose explicit formulas for the asymptotic variance matrices\nof the robust regression estimators, so recourse to bootstrap techniques is not\nnecessary. Moreover, these variances are valid in the presence of\nautocorrelation and heteroskedasticity; as we will show it, if we impose the\nindependence between the observations, the absence of heteroskedasticity or the\nsymmetry of the distribution of the error terms, the expressions of the\nvariances become much simpler and coincide with the results previously proved\nby other authors. The robustness with respect to outliers of the estimates of\nthe variance matrices is also taken into account. Finally, the results of\n\\citet{Croux:2003} may be used to develop robust confidence intervals and\nrobust tests for the regression parameters; they are also on the basis of the\nextension of the Hausman test presented at the end of this section, which\nallows to check for the presence of outliers---by comparing the regression\ncoefficients estimated by least squares and by a robust \n\\stsc{S}~procedure---and to fix the maximal efficiency that may have an \n\\stsc{MM}~estimator without suffering of significant bias in the presence of\ncontamination of the data set by (moderately) bad leverage points---by\ncomparing an \\stsc{S}~estimate of $\\boldsymbol\\beta$ with several \n\\stsc{MM}~estimates of different efficiencies.\n\n\\subsection{Asymptotic distribution of M, S and MM estimators}\n\\label{subsec:asymptotic_distr_M_S_MM_estimators}\n\nLet us here present some of the fundamental results established by\n\\citet{Croux:2003} for the asymptotic distribution of \\stsc{M}, \\stsc{S} and\n\\stsc{MM}~estimators. The interested reader will find some details about the\nmain steps of the approach used to demonstrate these results in Appendix~2\n(Section~\\ref{sec:robreg:appendix2}) at the end of this chapter.\n\nLet $y$ be the scalar dependent variable and $\\stvec{x} = (1, x_1, \\dots,\nx_p)^t$ be the $(p+1)$-vector of covariates. Consider once again the regression\nmodel (\\ref{eq:location_scale_regr_model}). Here, the observations\n$(\\stvec{x}_1, y_1), \\dots, (\\stvec{x}_n, y_n)$ are assumed to be generated by\na \\emph{stationary} and \\emph{ergodic} process. To avoid too much\ntechnicalities, we also assume that the observations $(\\stvec{x}_i, y_i)$, $i =\n1, \\dots, n$, are \\emph{independent}.\\footnote{The interested reader can find\nvery general results, valid in presence of \\emph{autocorrelation}, in\n\\citet{Croux:2003}.}\n\nLet us denote by $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ the\n\\stsc{S}~estimator of $\\boldsymbol\\beta$ associated with the loss function\n$\\rho_0$:\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} = \n    \\argmin_{\\boldsymbol{\\beta}} s_{\\rho_0}(r_1(\\boldsymbol\\beta), \\dots, \n    r_n(\\boldsymbol\\beta))\n\\]\nwhere $s_{\\rho_0}$ is a measure of dispersion satisfying\n\\[\n    \\frac{1}{n} \\sum_{i=1}^{n} \n    \\rho_0\\left(\\frac{r_i(\\boldsymbol\\beta)}{s_{\\rho_0}(r_1(\\boldsymbol\\beta), \n        \\dots, r_n(\\boldsymbol\\beta))}\\right) \n    = \\delta\\quad\\text{for all $\\boldsymbol\\beta \\in \\mathbb{R}^{p+1}$.}\n\\]\nThis leads to the scale \\stsc{M}~estimator\n\\[\n    \\sthat{\\sigma}_{\\rho_0} = \n    s_{\\rho_0} \\left(r_1(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}), \\dots, \n    r_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\\right).\n\\]\n\nLet $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ be the \n\\stsc{MM}~estimator of $\\boldsymbol\\beta$ associated with the loss function $\\rho_0$ for\nthe first step of the estimation procedure (\\stsc{S}~estimation) and with the\nloss function $\\rho$ for the second step (\\stsc{M}~estimation):\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ is a (local) minimum of\n\\[\n    \\sum_{i=1}^{n} \\rho\\left(\\frac{r_i(\\boldsymbol\\beta)}{\\sthat{\\sigma}_{\\rho_0}}\\right).\n\\]\n\nTo avoid any ambiguity in the formulation of the results, we will denote the\nvector of regression parameters by $\\boldsymbol\\beta$ when it is estimated by\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and by $\\boldsymbol\\beta_0$\nwhen it is estimated by $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$. Moreover,\nwe will use the generic notations $u_0 =\n(y-\\stvec{x}^t\\boldsymbol\\beta_0)/\\sigma$ and $u =\n(y-\\stvec{x}^t\\boldsymbol\\beta)/\\sigma$, and we will simply replace $\\psi(u) =\n\\rho'(u)$ by $\\psi$, and $\\rho_0(u_0)$ by $\\rho_0$.\n\nUsing these notations, we may formulate the results shown by \\citet{Croux:2003}\nas follows.\n\n\\begin{stproposition}\nIf the observations $(\\stvec{x}_i, y_i)$, $i = 1, \\dots, n$, are generated \nby a stationary and ergodic process, and are independent (Assumption A), then\n\\[\n    \\sqrt{n} \\left(\n    \\begin{bmatrix}\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}\\\\\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}      \\\\\n        \\sthat{\\sigma}_{\\rho_0}\n    \\end{bmatrix}\n    - \n    \\begin{bmatrix}\n        \\boldsymbol\\beta\\\\\n        \\boldsymbol\\beta_0\\\\\n        \\sigma\n    \\end{bmatrix}\n    \\right) \\rightarrow^d \\mathcal{N}(\\stvec{0},\\stmat{V}_\\stsc{MM})\n\\]\nwhere\n%\n\\begin{equation}\\label{eq:V_MM}\n    \\stmat{V}_\\stsc{MM} = \\stmat{G}_\\stsc{MM}^{-1}\n    \\boldsymbol\\Omega_\\stsc{MM} \\left(\\stmat{G}_\\stsc{MM}^t\\right)^{-1}\n%\n\\end{equation}\n%\nwith the matrices $\\stmat{G}_\\stsc{MM}$ and $\\boldsymbol\\Omega_\\stsc{MM}$ given \nby:\n%\n\\begin{equation}\\label{eq:G_MM}\n    \\stmat{G}_\\stsc{MM} = - \\frac{1}{\\sigma} \n    E\\begin{pmatrix}\n        \\psi'\\stvec{x}\\stvec{x}^t & \\stvec{0}                    & \\psi'u\\stvec{x}\\\\\n        \\stvec{0}                 & \\rho_0''\\stvec{x}\\stvec{x}^t & \\rho_0''u_0\\stvec{x}\\\\\n        \\stvec{0}                 & \\stvec{0}                    & \\rho_0'u_0\n    \\end{pmatrix}\n\\end{equation}\n%\nand\n%\n\\begin{equation}\\label{eq:Omega_MM}\n    \\boldsymbol\\Omega_\\stsc{MM} = \n    E\\begin{pmatrix}\n        \\psi^2\\stvec{x}\\stvec{x}^t      & \\psi\\rho_0'\\stvec{x}\\stvec{x}^t & \\psi\\rho_0\\stvec{x} \\\\\n        \\psi\\rho_0'\\stvec{x}\\stvec{x}^t & (\\rho_0')^2\\stvec{x}\\stvec{x}^t & \\rho_0\\rho_0'\\stvec{x}\\\\\n        \\psi\\rho_0\\stvec{x}^t           & \\rho_0\\rho_0'\\stvec{x}^t        & \\rho_0^2-\\delta^2\n    \\end{pmatrix}.\n\\end{equation}\n\\end{stproposition}\n\nIn particular, this result establishes the consistency of the regression\n\\stsc{MM}~estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and\n\\stsc{S}~estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$, and of the\nscale \\stsc{M}~estimator $\\sthat{\\sigma}_{\\rho_0}$.\n\nMoreover, it allows to derive explicit formulas for the asymptotic variances\nof $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$---denoted hereafter by\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ and \n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$, respectively---, and for the asymptotic\ncovariance of $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$---denoted by\n$\\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$:\n%\n\\begin{align}\n    \\label{eq:Avar_betahat_MM}\n    \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n    & = \\frac{1}{n} \\big[ \\stmat{A} E(\\psi^2\\stvec{x}\\stvec{x}^t)\\stmat{A} \n        - \\stmat{a} E(\\psi\\rho_0\\stvec{x}^t) \\stmat{A}\n    \\\\\\nonumber & \\qquad \n        - \\stmat{A} E(\\psi\\rho_0\\stvec{x}) \\stmat{a}^t \n        + E(\\rho_0^2 - \\delta^2)  \\stmat{a}\\stmat{a}^t \\big]\n    \\\\\n    \\label{eq:Avar_betahat_S}\n    \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n    & = \\frac{1}{n} \\big[ \\stmat{A}_\\stsc{S} E((\\rho_0')^2 \\stvec{x}\\stvec{x}^t) \\stmat{A}_\\stsc{S} \n        - \\stmat{a}_\\stsc{S} E(\\rho_0\\rho_0'\\stvec{x}^t) \\stmat{A}_\\stsc{S}\n    \\\\\\nonumber & \\qquad \n        - \\stmat{A}_\\stsc{S} E(\\rho_0\\rho_0'\\stvec{x}) \\stmat{a}_\\stsc{S}^t \n        + E(\\rho_0^2 - \\delta^2) \\stmat{a}_\\stsc{S}\\stmat{a}_\\stsc{S}^t \\big]\n    \\\\\n    \\label{eq:Acov_betahat_MM_S}\n    \\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n    & = \\frac{1}{n} \\big[ \\stmat{A} E(\\psi\\rho_0'\\stvec{x}\\stvec{x}^t) \\stmat{A}_\\stsc{S}\n        - \\stmat{a} E(\\rho_0\\rho_0'\\stvec{x}^t) \\stmat{A}_\\stsc{S}\n    \\\\\\nonumber & \\qquad \n        - \\stmat{A} E(\\psi\\rho_0\\stvec{x}) \\stmat{a}_\\stsc{S}^t\n        + E(\\rho_0^2 - \\delta^2) \\stmat{a}\\stmat{a}_\\stsc{S}^t \\big]\n\\end{align}\n%\nwith\n%\n\\begin{align}\n    \\label{eq:A}\n    \\stmat{A} &  = \\sigma \\left[ E(\\psi'\\stvec{x}\\stvec{x}^t)\\right]^{-1}\n    \\\\\n    \\label{eq:a}\n    \\stmat{a} &  = \\stmat{A} \\frac{E(\\psi'u\\stvec{x})}{E(\\rho_0'u_0)}\n    \\\\\n    \\label{eq:A_S}\n    \\stmat{A}_\\stsc{S} & = \\sigma\\left[E(\\rho_0''\\stvec{x}\\stvec{x}^t)\\right]^{-1}\n    \\\\\n    \\label{eq:a_S}\n    \\stmat{a}_\\stsc{S} & = \\stmat{A}_\\stsc{S}\\frac{E(\\rho_0''u_0\\stvec{x})}{E(\\rho_0'u_0)}.\n\\end{align}\n\n\\begin{stremark}\nNote that \\citet{Croux:2003} have also considered the case where we estimate\nthe parameters $\\boldsymbol\\beta$ and $\\sigma$ simultaneously by an \n\\stsc{M}~estimation procedure. Some results about the asymptotic distribution of\n$(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}^t, \\sthat{\\sigma}_{\\rho_0})^t$ are\npresented in Appendix~2 (Section~\\ref{sec:robreg:appendix2}) at the end of this\nchapter.\n\\end{stremark}\n\nThe authors have also shown that the asymptotic variances and covariances can\nbe estimated consistently by taking their empirical counterpart. More\nprecisely, the estimates are obtained by applying the following two rules:\n\\begin{enumerate}\n    \\item Replace, in $u$ and $u_0$, the parameters $\\boldsymbol\\beta$,\n    $\\boldsymbol\\beta_0$ and $\\sigma$ by the estimates\n    $\\widehat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$,\n    $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and $\\sthat{\\sigma}_{\\rho_0}$.\n\n    \\item Replace $E(\\cdot)$ by $\\frac{1}{n}\\sum_{i=1}^{n}(\\cdot)$.\n\\end{enumerate}\nFor example, the first term of\n$\\sthat{\\mathrm{Avar}}(\\widehat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is\ngiven by\n\\[\n    \\frac{1}{n} \\left(\\sthat{\\stmat{A}}\\left[\n    \\frac{1}{n} \\sum_{i=1}^{n} \\psi\\left(\n    \\frac{y_i - \\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n    {\\sthat{\\sigma}_{\\rho_0}}\\right)^{\\!\\!2} \\stvec{x}_i\\stvec{x}_i^t\\right]\n    \\widehat{\\stmat{A}}\\right)\n\\]\nwith\n\\[\n    \\sthat{\\stmat{A}} = \\sthat{\\sigma}_{\\rho_0}\n    \\left[\\frac{1}{n} \\sum_{i=1}^{n} \n    \\psi'\\left(\\frac{y_i-\\stvec{x}_i^t\\widehat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n    {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i\\stvec{x}_i^t\\right]^{-1}.\n\\]\nIt is interesting to note that the estimate $\\sthat{\\mathrm{Avar}}\n(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ of the asymptotic variance\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is robust\nwith respect to bad leverage points and vertical outliers. Indeed, if there are\nobservations yielding large residuals with respect to the robust \\stsc{MM}~fit,\nthen\n$\\psi((y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})/\\sthat{\\sigma}_{\\rho_0})$\nhas a small value when $\\psi$ is a redescending function.\\footnote{Recall that,\nif $\\psi$ is redescending, it has the property to be equal to zero for large\narguments.} Hence, if there are bad leverage points in the sample, then their\n$\\stvec{x}_i$-value is large, but at the same time\n$\\psi((y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})/\\sthat{\\sigma}_{\\rho_0})$ \nwill be zero. This explains intuitively why vertical outliers and bad leverage\npoints have only a limited influence on the estimate\n$\\sthat{\\mathrm{Avar}}(\\widehat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$.\n\n\\begin{stremark}\nAs previously explained, the \\stsc{LS}~estimator\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ may be seen as a particular \n\\stsc{S}~estimator of $\\boldsymbol{\\beta}$ associated with the loss function\n$\\rho_0(u_0) = u_0^2$ (such that $\\rho_0'(u_0) = 2 u_0$ and $\\rho_0''(u_0) =\n2$) and with the constant $\\delta = 1$. The expression of the asymptotic\nvariance matrix of $\\widehat{\\boldsymbol\\beta}_\\stsc{LS}$ may then be simply\nderived from the one obtained for\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$:\n%\n\\begin{align}\n    \\label{eq:Avar_betahat_LS}\n    \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS})\n    & = \\frac{1}{n} \\big[ \\stmat{A}_\\stsc{LS} E(4 u_0^2\\stvec{x}\\stvec{x}^t) \\stmat{A}_\\stsc{LS}\n        -\\stmat{a}_\\stsc{LS} E(2 u_0^3 \\stvec{x}^t) \\stmat{A}_\\stsc{LS}\n    \\\\\\nonumber & \\qquad \n        - \\stmat{A}_\\stsc{LS} E(2 u_0^3 \\stvec{x}) \\stmat{a}_\\stsc{LS}^t\n        + E(u_0^4 - 1) \\stmat{a}_\\stsc{LS}\\stmat{a}_\\stsc{LS}^t \\big]\n\\end{align}\n%\nwith\n%\n\\begin{equation}\\label{eq:A_a_LS}\n    \\stmat{A}_\\stsc{LS} = \\frac{\\sigma}{2} E(\\stvec{x}\\stvec{x}^t)^{-1}\n    \\qquad\\text{and}\\qquad\n    \\stmat{a}_\\stsc{LS} = \\stmat{A}_\\stsc{LS} \\frac{E(u_0\\stvec{x})}{E(u_0^2)}.\n\\end{equation}\n%\nIf, in addition, there is homoskedasticity\\footnote{There is\n\\emph{homoskedasticity} when the processes $\\stvec{x}_i$ and $(u_i, u_{0i})$\nare independent.} and if the distribution $F_{0,1}$ of the error terms is\nsymmetric (around 0), we retrieve the well-known asymptotic variance matrix\n\\[\n    \\frac{\\sigma^2}{n} E(\\stvec{x}\\stvec{x}^t)^{-1}\n\\]\nthat we may estimate by\n\\[\n    \\frac{\\sthat{\\sigma}_{\\rho_0}^2}{n} \n    \\left(\\frac{1}{n} \\sum_{i=1}^{n} \\stvec{x}_i\\stvec{x}_i^t\\right)^{\\!\\!-1}.\n\\]\nNote that this latter estimator is absolutely not robust with respect to\nleverage points.\n\nFinally, since the \\stsc{LS}~estimation can be considered as the special case of the\n\\stsc{MM}~estimation associated with $\\rho(u) = u^2$, it can be shown that:\n%\n\\begin{equation}\n    \\label{eq:Acov_betahat_LS_S}\n    \\begin{split}\n    \\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS},\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n    & = \\frac{1}{n} \\big[ \\stmat{A} E(2 u \\rho_0'\\stvec{x}\\stvec{x}^t) \\stmat{A}_\\stsc{S}\n        - \\stmat{a} E(\\rho_0\\rho_0'\\stvec{x}^t) \\stmat{A}_\\stsc{S}\n    \\\\\n    & \\qquad \n        - \\stmat{A} E(2 u \\rho_0\\stvec{x}) \\stmat{a}_\\stsc{S}^t\n        + E(\\rho_0^2 - \\delta^2) \\stmat{a}\\stmat{a}_\\stsc{S}^t \\big]\n    \\end{split}\n\\end{equation}\n%\nwith%\n\\[\n    \\stmat{A} = \\stmat{A}_\\stsc{LS} = \\frac{\\sigma}{2} E(\\stvec{x}\\stvec{x}^t)^{-1}\n    \\qquad\\text{and}\\qquad\n    \\stmat{a} = \\stmat{A}_\\stsc{LS} \\frac{E(2 u \\stvec{x})}{E(\\rho_0'u_0)}\n\\]\nwhile $\\stmat{A}_\\stsc{S}$ and $\\stmat{a}_\\stsc{S}$ remain unchanged with\nrespect to (\\ref{eq:A_S}) and (\\ref{eq:a_S}).\n\\end{stremark}\n\nOf course, in absence of heteroskedasticity or if the distribution $F_{0,1}$ of\nthe error terms is symmetric (around 0), the expressions of the asymptotic\nvariances and covariances simplify quite considerably, as shown in Appendix~2\n(Section~\\ref{sec:robreg:appendix2}). Unfortunately, their estimates---their\nempirical counterparts---are not robust anymore with respect to (good and bad)\nleverage points. Hence, \\citet{Croux:2003} do advise against the use of these\nsimplified variances and covariances, even when the assumptions of absence of\nheteroskedasticity and symmetry hold.\n\n\\subsection{Robust confidence intervals and tests with robust regression estimators}\n\nAs just explained, we may consider that, under the model\n(\\ref{eq:location_scale_regr_model}) and Assumption A,\\footnote{Recall that\nAssumption A specifies that the observations $(\\stvec{x}_i, y_i)$, $i = 1,\n\\dots, n$, are generated by a stationary and ergodic process, and are mutually\nindependent.} a robust \\stsc{M}, \\stsc{S} or \\stsc{MM}~estimator\n$\\sthat{\\boldsymbol\\beta}$ is, for large $n$, approximately normally\ndistributed with mean $\\boldsymbol\\beta$ and variance\n$\\widehat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})$, where\n$\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})$ corresponds to the empirical\ncounterpart of the asymptotic matrix $\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta})$\nspecified in the previous subsection. This result underlies the inference\nprocedures developed for linear combinations of the regression parameters.\n\n\\subsubsection{Inference for a single linear combination of the regression parameters}\n\nLet $\\gamma$ be a linear combination of the regression coefficients:\n\\[\n    \\gamma = \\stvec{b}^t \\boldsymbol\\beta\n\\]\nwith $\\stvec{b}$ a constant (non random) vector. Then the natural estimate of\n$\\gamma$ is $\\sthat{\\gamma} = \\stvec{b}^t\\sthat{\\boldsymbol\\beta}$, which is,\nunder Assumption A and for large $n$, approximately $\\mathcal{N}(\\gamma,\n\\sthat{\\sigma}_\\gamma^2)$ where\n\\[\n    \\sthat{\\sigma}_\\gamma^2 = \n    \\stvec{b}^t \\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta}) \\stvec{b}.\n\\]\nHence an approximate two-sided confidence interval for $\\gamma$ with\nconfidence level $(1- \\alpha)$ is given by\n\\[\n    \\left[\\sthat{\\gamma} \\pm z_{1-\\alpha/2} \\sthat{\\sigma}_\\gamma\\right]\n\\]\nwhere $z_{1-\\alpha/2}$ is the $(1-\\alpha/2)$-quantile of the standard normal \ndistribution.\n\nSimilarly, the test of level $\\alpha$ for the null hypothesis $\\mathcal{H}_0:\n\\gamma = \\gamma_0$ against the two-sided alternative $\\mathcal{H}_1: \\gamma\n\\neq \\gamma_0$ has the rejection region\n\\[\n    |\\sthat{\\gamma}-\\gamma_0| > z_{1-\\alpha/2}\\sthat{\\sigma}_\\gamma\n\\]\nor equivalently, since the approximate normal distribution of\n$\\widehat{\\gamma}$ implies that\n$((\\sthat{\\gamma}-\\gamma)/\\widehat{\\sigma}_\\gamma)^2 \\approx \\chi_1^2$, rejects\n$\\mathcal{H}_0$ when\n\\[\n    T > \\chi_{1; 1-\\alpha}^2\n\\]\nwhere\n\\[\n    T = \\left(\\frac{\\sthat{\\gamma}-\\gamma_0}{\\sthat{\\sigma}_\\gamma}\\right)^{\\!2}\n\\]\nand $\\chi_{1;1-\\alpha}^2$ is the $(1-\\alpha)$-quantile of the chi-square\ndistribution with one degree of freedom.\n\nIn particular, if $\\mathbf{b} = (0, \\dots, 0, 1, 0, \\dots, 0)^t$, that is, if\nall the components of $\\mathbf{b}$ are equal to zero except the $j$th component\nequal to 1, we have $\\gamma = \\beta_j$ and $\\sthat{\\sigma}_\\gamma^2 =\n[\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})]_{jj}$. Then, the two-sided\nconfidence interval for $\\beta_j$ with confidence level $(1-\\alpha)$ is given by\n\\[\n    \\left[\\sthat{\\beta}_j \\pm \n    z_{1-\\alpha/2} \\sqrt{[\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})]_{jj}}\\right]\n\\]\nand the test of level $\\alpha$ for the null hypothesis $\\mathcal{H}_0: \\beta_j =\n0$ against the alternative $\\mathcal{H}_1: \\beta_j \\neq 0$ has the rejection\nregion\n\\[\n    \\frac{\\sthat{\\beta}_j^2}{[\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})]_{jj}} \n    > \\chi_{1;1-\\alpha}^2.\n\\]\n\n\\subsubsection{Inference for several linear combinations of the regression parameters}\n\nLet us now consider several linear combinations of the $\\beta_{j}$'s\nrepresented by the vector $\\boldsymbol{\\gamma} = \\stmat{B}\\boldsymbol\\beta$\nwhere $\\stmat{B}$ is a $q \\times (p+1)$ matrix of rank $q$. Then\n$\\widehat{\\boldsymbol{\\gamma}} = \\stmat{B}\\sthat{\\boldsymbol\\beta}$ is, under\nAssumption A and for large $n$, approximately\n$\\mathcal{N}_q(\\boldsymbol{\\gamma},\n\\sthat{\\boldsymbol\\Sigma}_{\\boldsymbol\\gamma})$ with\n\\[\n    \\sthat{\\boldsymbol\\Sigma}_{\\boldsymbol\\gamma} \n    = \\stmat{B}\\widehat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta})\\stmat{B}^t.\n\\]\nThis implies that\n\\[\n    (\\sthat{\\boldsymbol\\gamma} - \\boldsymbol\\gamma)^t \n    \\sthat{\\boldsymbol\\Sigma}_{\\boldsymbol\\gamma}^{-1} \n    (\\widehat{\\boldsymbol\\gamma} - \\boldsymbol\\gamma)  \\approx \\chi_q^2\n\\]\nwhere $\\chi_q^2$ is the chi-square distribution with $q$ degrees of freedom.\nHence, to test the linear hypothesis $\\mathcal{H}_0: \\boldsymbol\\gamma =\n\\boldsymbol\\gamma_0$ for a given $\\boldsymbol\\gamma_0$, with level $\\alpha$, we\nmay use the test that rejects $\\mathcal{H}_0$ if\n\\[\n    T > \\chi_{q;1-\\alpha}^2\n\\]\nwhere\n\\[\n    T = (\\sthat{\\boldsymbol\\gamma} - \\boldsymbol\\gamma_0)^t\n    \\sthat{\\boldsymbol\\Sigma}_{\\boldsymbol\\gamma}^{-1}\n    (\\sthat{\\boldsymbol\\gamma} - \\boldsymbol\\gamma_0)\n\\]\nand $\\chi_{q;1-\\alpha}^2$ is the $(1-\\alpha)$-quantile of the $\\chi_q^2$\ndistribution. The most common application of this test is when $\\mathcal{H}_0$\nis the hypothesis that some of the coefficients $\\beta_j$ are equal to zero.\nIf, for example, the null hypothesis is\n\\[\n    \\mathcal{H}_0: \\beta_1 = \\beta_2 = \\dots = \\beta_q = 0\n\\]\nthen $\\boldsymbol\\gamma = \\stmat{B}\\boldsymbol\\beta$ with $\\stmat{B} =\n(\\stmat{I}_{q\\times q}, \\stmat{0}_{q\\times(p+1-q)})$, where $\\stmat{I}_{q\\times\nq}$ is the $(q\\times q)$ identity matrix, and $\\mathcal{H}_0$ takes the form\n$\\mathcal{H}_0: \\stmat{B}\\boldsymbol\\beta = 0$.\n\n\\subsection{Robust R-squared}\n\nThe coefficient of determination or $R^2$ is a very simple tool---probably\nthe one most used by practitioners---to assess the quality of fit in a multiple\nlinear regression. It provides an indication of the suitability of the chosen\nexplanatory variables in predicting the response. In the classical setting,\n$R^2$ is usually presented as the quantity that estimates the percentage of\nvariance of the response variable explained by its (linear) relationship with\nthe explanatory variables. It is defined as the ratio\n%\n\\begin{equation}\n    \\label{eq:R2_classic_SS}\n    R^2 = \\frac{\\stsc{ESS}}{\\stsc{TSS}} = 1-\\frac{\\stsc{RSS}}{\\stsc{TSS}}\n          = 1 - \\frac{\\sum_{i=1}^{n} (y_i - \\sthat{y}_i)^2} \n                {\\sum_{i=1}^{n} (y_i - \\overline{y})^2}\n\\end{equation}\n%\nwhere $stsc{ESS}$, $stsc{TSS}$ and $stsc{RSS}$ are the explained, total, and\nresidual sum of squares, respectively. Note that $y_i - \\sthat{y}_i =\nr_i(\\sthat{\\boldsymbol\\beta}_\\stsc{LS})$ are the \\stsc{LS}~residuals. Moreover,\n$\\overline{y}$ is the \\stsc{LS}~estimate of $\\mu = E(y)$, that is the \n\\stsc{LS}~estimate of the intercept $\\beta_0$ in the linear regression model\n(\\ref{eq:linear_regr_model}) in which $\\beta_1 = \\dots = \\beta_p = 0$.\n\nWhen there is an intercept term in the linear model, this coefficient of\ndetermination $R^2$ is actually equal to the square of the correlation\ncoefficient between the observed $y_i$'s and the predicted $\\sthat{y}_i$'s \n(see, e.g., \\citealp{Greene:1997}), that is,\n%\n\\begin{equation}\n    \\label{eq:R2_classic_corr}\n    R^2 = \\left(\\frac{\\sum_{i=1}^{n} (y_i - \\overline{y})(\\sthat{y}_i - \\overline{\\sthat{y}})}\n          {\\sqrt{\\sum_{i=1}^{n} (y_i - \\overline{y})^2} \n           \\sqrt{\\sum_{i=1}^{n} (\\sthat{y}_i - \\overline{\\sthat{y}})^2}}\\right)^{\\!\\!2}\n\\end{equation}\n%\nwith $\\overline{\\sthat{y}}$ as the arithmetic mean of the predicted responses.\nEquation (\\ref{eq:R2_classic_corr}) has a nice interpretation in that $R^2$\nmeasures the goodness of fit of the regression model by its ability to predict\nthe response variable, ability measured by the correlation. Note that $R^2$ is\na consistent estimator of the population parameter\n%\n\\begin{equation}\n    \\label{eq:phi2}\n    \\phi^2 = \\max_{\\boldsymbol\\beta} \\mathrm{Corr}(y, \\stvec{x}^t\\boldsymbol\\beta)^2\n\\end{equation}\n%\nthat is, of the squared correlation between $y$ and the best linear\ncombination of the $\\stvec{x}$ (cf.\\ \\citealp{Anderson:1984}). In finite\nsamples, $R^2$ is biased upward and is generally adjusted as in\n%\n\\begin{equation}\n    \\label{eq:R2_adj}\n    R_{\\mathrm{adj}}^2 = 1 - \\left(1-R^2\\right) \\left(\\frac{n-1}{n-(p+1)}\\right).\n\\end{equation}                                                              \\todo{maybe also give other formula with residual variance}\n\nIt is rather obvious that the $R^2$ given by (\\ref{eq:R2_classic_SS}) can be\ndriven by extreme observations, not only through the \\stsc{LS}~estimator\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ used to compute the predicted responses\n$\\sthat{y}_i$, but also through the average response $\\overline{y}$ and the\npossible large residuals $y_i - \\sthat{y}_i$ or deviations $y_i -\n\\overline{y}$. Several robust $R^2$ variants have then been proposed in the\nliterature (see \\citealp{Renaud:VictoriaFeser:2010}). A \\emph{robust} $R^2$ should give an\nindication of the fit for the \\emph{majority} of the data, possibly leaving\naside a few outlying observations. In other words, the (robust) goodness-of-fit\ncriterion is used to choose a good model for the majority of the data rather\nthan an “average” model for all the data. Let us focus our attention here on\nthe two robust coefficients of determination available in Stata: $R_\\rho^2$ and\n$R_w^2$.\n\nIf instead of the \\underbar{LS} estimate we use an \\underbar{M} estimate (associated with the loss\nfunction $\\rho$) with general scale, defined as in (\\ref{eq:M_min}), a robust\ncoefficient of determination can be defined by\n%\n\\begin{equation}\\label{eq:R2_rho}\n    R_\\rho^2 = 1 - \\frac{\\sum_{i=1}^{n} \n    \\rho\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}}{\\sthat{\\sigma}}\\right)}\n    {\\sum_{i=1}^{n} \\rho\\left(\\frac{y_i-\\sthat{\\mu}_{\\stsc{M};\\rho}}{\\sthat{\\sigma}}\\right)}\n\\end{equation}\nwhere $\\sthat{\\mu}_{\\stsc{M};\\rho}$ is the \\stsc{M}~estimate of the location\nparameter $\\mu = E(y)$, solution of\n\\[\n    \\argmin_\\mu \\sum_{i=1}^{n} \\rho\\left(\\frac{y_i-\\mu}{\\sthat{\\sigma}}\\right)\n\\]\nand $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ and $\\sthat{\\sigma}$ are robust\nestimates of $\\boldsymbol\\beta$ and $\\sigma$ for the full model (see\n\\citealp{maronna:etal:2006}).\n\nNote that, independently, \\citet{croux:dehon:2003} have proposed a class of\nrobust $R^2$ which generalizes (\\ref{eq:R2_classic_SS}) given by\n%\n\\begin{equation}\\label{eq:R2_S}\n    R_{\\stsc{S}}^2 = 1 - \\frac{s(y_i-\\stvec{x}_i^t\\widehat{\\boldsymbol\\beta}; i = 1, \\dots, n)}\n    {s(y_i-\\sthat{\\mu}; i = 1, \\dots, n)} \n\\end{equation}\n%\nwhere $s(\\cdot)$ is a robust dispersion measure.\n\nAlthough (\\ref{eq:R2_rho}) and (\\ref{eq:R2_S}) are direct generalizations of\n(\\ref{eq:R2_classic_SS}) to the robust framework, they suffer from an important\ndrawback: in practice, they are often biased. One possible reason why this\nphenomenon happens is that the computation of $R_\\rho^2$ or $R_\\stsc{S}^2$\nrequires and uses the estimation of two models: the full regression model and a\nlocation model. The associate residuals $y_i -\n\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}$ and $y_i - \\sthat{\\mu}$ are not\ninfluenced by model deviation (as presence of outliers, for instance) in the\nsame way, so that bounding these quantities directly and separately is not\nnecessarily appropriate in the regression model framework.\n\nTo remedy this problem, \\cite{Renaud:VictoriaFeser:2010} have proposed to\n“robustify” the expression (\\ref{eq:R2_classic_corr}) of the coefficient of\ndetermination. Suppose $\\boldsymbol\\beta$ has been estimated by an \\stsc{M},\n\\stsc{S} or \\stsc{MM}~estimate $\\sthat{\\boldsymbol\\beta}$ using a loss function\n$\\rho(\\cdot)$, and let $\\sthat{\\sigma}$ be the final robust estimate of the\nscale parameter $\\sigma$. Let, as usual, $\\psi(u) = \\rho'(u)$ for\n$u\\in\\mathbb{R}$. Define, as in section\n\\ref{subsec:practical_implementation_Mestimate}, the weight function $W$ by\n\\[\n    W(u) = \n    \\begin{cases}\n        \\frac{\\psi(u)}{u} & \\text{if $u \\neq 0$} \\\\\n        \\psi'(0)          & \\text{if $u = 0$}\n    \\end{cases}\n\\]\nand the weights\n\\[\n    w_i = W \\left(r_i(\\sthat{\\boldsymbol\\beta})/\\sthat{\\sigma}\\right),\n    \\quad i = 1, \\dots, n.\n\\]\nNote that these weights $w_i$ coincide with those used in the last iteration\nof the \\emph{iteratively reweighted least squares algorithm} used to implement\nthe \\stsc{M}~estimation procedure. In particular, if $\\rho(\\cdot)$ is the\nTukey-Biweight function $\\rho_{\\kappa}^{B}(\\cdot)$ given by\n(\\ref{eq:Tukey_Biweight_function}), we have\n\\[\n    w_i =\n    \\begin{cases}\n        \\left(1 - \\left(\\frac{r_i(\\sthat{\\boldsymbol\\beta})}{\\kappa\\sthat{\\sigma}}\\right)^{\\!2}\\right)^{\\!\\!2} \n        & \\text{if $|r_i(\\sthat{\\boldsymbol\\beta})/\\sthat{\\sigma}| \\leq \\kappa$}\\\\\n        0 \n        & \\text{if $|r_i(\\sthat{\\boldsymbol\\beta})/\\sthat{\\sigma}| > \\kappa$}.\n    \\end{cases}\n\\]\nThen a robust version of (\\ref{eq:R2_classic_corr}) is given by\n%\n\\begin{equation}\n    \\label{eq:R2_w}\n    R_w^2 = \\left(\\frac{\\sum_{i=1}^{n} w_i(y_i-\\overline{y}_w) (\\sthat{y}_i-\\overline{\\sthat{y}}_w)}\n    {\\sqrt{\\sum_{i=1}^{n} w_i(y_i-\\overline{y}_w)^2}\n     \\sqrt{\\sum_{i=1}^{n} w_i(\\sthat{y}_i-\\overline{\\sthat{y}}_w)^2}}\\right)^{\\!\\!2}\n\\end{equation}\n%\nwhere $\\sthat{y}_i = y_i - \\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}$,\n$\\overline{y}_w = (1/\\sum w_i)\\sum w_i y_i$ and $\\overline{\\sthat{y}}_w =\n(1/\\sum w_i)\\sum w_i\\sthat{y}_i$.\n\nWith the same weights and predictions, another robust coefficient of\ndetermination can be defined from (\\ref{eq:R2_classic_SS}):\n%\n\\begin{equation}\n    \\label{eq:Rtilde2_w}\n    \\widetilde{R}_w^2 = 1 - \\frac{\\sum_{i=1}^{n} w_i(y_i - \\sthat{y}_i)^2}\n    {\\sum_{i=1}^{n} w_i(y_i - \\overline{y}_w)^2}\n\\end{equation}\n%\nIt is shown in \\citet{Renaud:VictoriaFeser:2010} that\n\\[\n    R_w^2 = \\widetilde{R}_w^2.\n\\]\n\n\n\\citet{Renaud:VictoriaFeser:2010} have also proposed the following more\ngeneral formulation for a robust coefficient of determination in order to take\ninto account consistency considerations:\n%\n\\begin{equation}\n    \\label{eq:Rtilde2_w_a}\n    \\widetilde{R}_{w,a}^2 = \\frac{\\sum_{i=1}^{n} w_i (\\sthat{y}_i - \\overline{\\sthat{y}}_w)^2}\n    {\\sum_{i=1}^{n} w_i (\\sthat{y}_i - \\overline{\\sthat{y}}_w)^2 + \n    a\\sum_{i=1}^{n} w_i (y_i - \\sthat{y}_i)^2}\n\\end{equation}\n%\nwhere $a$ is a constant factor. It has been shown that $R_w^2$ and\n$\\widetilde{R}_w^2$ are both equal to $\\widetilde{R}_{w,a}^2$ with\n$a=1$. Moreover, with no assumption on the distribution of the explanatory\nvariables, but under the assumption of normality of the errors and for a\nconsistent estimator $\\sthat{\\sigma}$ of the residual scale, $\\widetilde{R}_{w,a}^2$ \nis a consistent estimator of the population coefficient of\ndetermination (\\ref{eq:phi2}) if we take\n\\[\n    a = \\frac{E[\\psi(u)/u]}{E[\\psi(u)]},\n    \\quad\\text{with $u \\sim \\mathcal{N}(0,1)$}.\n\\]\nFor example, choosing $\\psi(u) = \\psi_{\\kappa}^B(u) = \\rho_{\\kappa}^{B}{'}(u)$,\nwhere $\\rho_{\\kappa}^B$ is the Tukey-Biweight loss function with\n$\\kappa=4.685$, leads to $a=1.2076$.\n\nAs shown by a simulation study in \\citet{Renaud:VictoriaFeser:2010}, for\nsmall samples and a relatively large number of covariates, using the same\nrationale than for the classical $R^2$, the robust coefficient might benefit\nof being adjusted, hence leading to the adjusted coefficient\n%\n\\begin{equation}\n    \\label{eq:Rtilde2_w_a_adj}\n    \\widetilde{R}_{w,a;\\mathrm{adj}}^2 = 1 - \\left(1 - \\widetilde{R}_{w,a}^2\\right) \n    \\left(\\frac{n-1}{n - (p+1)}\\right).\n\\end{equation}\n\n\n\\subsection{Extension of the Hausman test to check for the presence of outliers}\n\\label{subsec:Hausman}\n\nIn practice, it is usual to ask oneself if it is necessary to use a robust\nregression estimator or if it is preferable to use a classical estimator that\nis more efficient under the model and more easy to compute. When the data are\nnot contaminated by outliers, classical and robust estimations of the\nregression coefficients are quite similar, while a moderate contamination of\nthe sample may imply a possible clear difference between classical and robust\nestimations. Hence, no significant difference between the classical and robust\nestimations of $\\boldsymbol\\beta$ may lead us to conclude that the data do\nnot contain outliers or that the influence of the outliers is rather limited:\nin such a case, we will prefer to retain the classical estimator given its\nhigher efficiency (its higher statistical precision). On the contrary, a\nsignificant difference between the classical and robust estimations of\n$\\boldsymbol\\beta$ indicates that the data are contaminated by outliers in\nsuch a way that it biases the classical estimator: a robust estimator should\nthen be preferred.\n\nBut which tool may we use to compare adequately two regression estimators and\nto judge if their values are significantly different or not?\n\nTo solve this question, \\citet{Dehon:2009,Dehon:2012} have proposed a\nstatistical test, based on the methodology developed by \\citet{Hausman:1978}.\nTheir testing procedure allows to compare a robust \\stsc{S}~estimate and the\nclassical \\stsc{LS}~estimate (in order to detect the presence of outliers). But\nit also allows to compare an \\stsc{S}~estimator with an \\stsc{MM}~estimator\nwith a given efficiency level; repeating this test by considering different\nefficiency levels for the \\stsc{MM}~estimator may be seen as a procedure\nallowing, in the presence of moderate contamination of the sample, to find in\nan appropriate way the maximum efficiency level that may have this \n\\stsc{MM}~estimator without suffering from too large bias.\n\nIn all the cases, the problem of test may be formalized as follows. Consider\nthe regression model (\\ref{eq:linear_regr_model}). The null hypothesis\n$\\mathcal{H}_0$ is that this model is valid for the entire population. Thus,\nat the sample level, under the null, no outliers are present. The alternative\nhypothesis $\\mathcal{H}_1$ is that the model is misspecified for a\nminority of the population, implying a potentially moderate contamination of\nthe sample. Note that we will also systematically consider that, under the\nnull hypothesis $\\mathcal{H}_0$, Assumption~A1 is satisfied.\n\nBefore to describe the test statistics and the decision rules, let us precise a\nlast point: since \\citet{Gervini:2002} showed that, \\emph{in the presence of\noutliers}, only the $p$ slopes $\\beta_1, \\dots, \\beta_p$ of the regression\nmodel can be satisfactorily estimated when the error distribution is\nasymmetric, the test will be based on the comparison of the slopes estimations\nand the estimations of the intercept $\\beta_0$ will be disregarded. Hence, in\nthe sequel of this section, we will use the following notations to take this\ncharacteristic into account: $\\underline{\\boldsymbol\\beta} = (\\beta_1, \\dots,\n\\beta_p)^t$ and $\\underline{\\sthat{\\boldsymbol\\beta}} = (\\sthat{\\beta}_1,\n\\dots, \\sthat{\\beta}_p)^t$, such that $\\boldsymbol\\beta = (\\beta_0,\n\\underline{\\boldsymbol\\beta}^t)^t$ and $\\sthat{\\boldsymbol\\beta} = (\\beta_0,\n\\underline{\\sthat{\\boldsymbol\\beta}}^t)^t$.\n\n\\subsubsection{Some preliminary results}\n\nThe development of the tests proposed in \\citet{Dehon:2012} relies on the\nresults presented in Subsection~\\ref{subsec:asymptotic_distr_M_S_MM_estimators}\nproviding the asymptotic distribution of $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ under $\\mathcal{H}_0$ and\nAssumption~A. In Subsection~\\ref{subsec:asymptotic_distr_M_S_MM_estimators}, to\navoid any ambiguity, the regression parameters vector was denoted by\n$\\boldsymbol\\beta_0$ if it was estimated by the \\stsc{S}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$, and by $\\boldsymbol\\beta$ if it\nwas estimated by the \\stsc{MM}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$. From now on, we will\nexclusively denote the regression parameters vector in model\n(\\ref{eq:location_scale_regr_model}) by $\\boldsymbol\\beta$ as soon as there is\nno risk of confusion anymore.\n\nWe have seen that, under $\\mathcal{H}_0$ and Assumption~A, for large $n$,\n%\n\\begin{align*}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho} & \\approx \n        \\mathcal{N}_{p+1}\\left(\\boldsymbol\\beta, \n        \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\\right)\n    \\\\\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} &  \\approx\n    \\mathcal{N}_{p+1}\\left(\\boldsymbol\\beta, \n        \\mathrm{Avar}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\\right)\n    \\\\\n    \\sthat{\\boldsymbol\\beta}_\\stsc{LS} & \\approx\n        \\mathcal{N}_{p+1}\\left(\\boldsymbol\\beta,\n        \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS})\\right)\n\\end{align*}\n%\nwhere the matrices\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$,\n$\\mathrm{Avar}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$ and\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS})$ are given by\n(\\ref{eq:Avar_betahat_MM}), (\\ref{eq:Avar_betahat_S}) and\n(\\ref{eq:Avar_betahat_LS}), respectively. Moreover,\n%\n\\begin{align*}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} \n        - \\widehat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}\n     & \\approx \\mathcal{N}_{p+1}\\left(\\stvec{0},\n         \\mathrm{Avar}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n       + \\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n     - 2 \\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n             \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\\right)\n\\end{align*}\n%\nwhere $\\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$ is given by\n(\\ref{eq:Acov_betahat_MM_S}). Since\n$\\mathrm{Avar}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$,\n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ and\n$\\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$ may be consistently estimated by\ntheir empirical counterparts\n$\\sthat{\\mathrm{Avar}}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$,\n$\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ and\n$\\sthat{\\mathrm{Acov}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$,\\footnote{As explained in\nSubsection~\\ref{subsec:asymptotic_distr_M_S_MM_estimators}, these empirical\ncounterparts are simply obtained by replacing, in $u$ and $u_0$, the parameters\n$\\boldsymbol\\beta$, $\\boldsymbol\\beta_0$ and $\\sigma$ by the estimates\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and $\\sthat{\\sigma}_{\\rho_0}$, and\n$E(\\cdot)$ by $\\frac{1}{n} \\sum_{i=1}^{n} (\\cdot)$.} we have, under\n$\\mathcal{H}_0$ and Assumption~A, for large $n$:\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}\n    \\approx \\mathcal{N}_{p+1}\\left(\\stvec{0},\n    \\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}\n    \\right)\n\\]\nwhere\n%\n\\begin{align}\n    \\label{eq:Hausman_sigmahat_S-MM}\n    \\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})} \n    &  = \\sthat{\\mathrm{Avar}}(\\widehat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n       + \\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n     - 2 \\sthat{\\mathrm{Acov}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho},\n             \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n\\end{align}\n%\nIf we only consider the slopes estimates, we simply have, under $\\mathcal{H}_0$ \nand Assumption~A, for large $n$:\n%\n\\begin{equation}\n    \\label{eq:Hausman_normality_S-MM}\n    \\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{MM};\\rho_0,\\rho}\n    \\approx \\mathcal{N}_p\\left(\\underline{\\stvec{0}},\n    \\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}\n    \\right)\n\\end{equation}\n%\nwhere\n$\\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} \n- \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}$ is the matrix\n$\\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} -\n\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}$ without its first line and\nits first column.\n\nFollowing a similar approach, we have, under $\\mathcal{H}_0$ and Assumption~A, \nfor large $n$:\n\\[\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} \n        - \\sthat{\\boldsymbol\\beta}_\\stsc{LS}\n    \\approx\\mathcal{N}_{p+1} \\left(\\stvec{0},\n        \\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}\n    \\right)\n\\]\nwith\n%\n\\begin{align}\n    \\label{eq:Hausman_sigmahat_S-LS}\n    \\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n        - \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}\n    & = \\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n      + \\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol{\\beta}}_\\stsc{LS})\n    - 2 \\sthat{\\mathrm{Acov}}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS},\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n\\end{align}\n%\nwhere \n$\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$, \n$\\sthat{\\mathrm{Avar}}(\\sthat{\\boldsymbol{\\beta}}_\\stsc{LS})$ and \n$\\sthat{\\mathrm{Acov}}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$ are the\nempirical counterparts of the matrices \n$\\mathrm{Avar}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$, \n$\\mathrm{Avar}(\\sthat{\\boldsymbol{\\beta}}_\\stsc{LS})$ and \n$\\mathrm{Acov}(\\sthat{\\boldsymbol\\beta}_\\stsc{LS},\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})$ \ngiven by (\\ref{eq:Avar_betahat_S}), (\\ref{eq:Avar_betahat_LS}) and\n(\\ref{eq:Acov_betahat_LS_S}), respectively. As a consequence, under\n$\\mathcal{H}_0$ and Assumption~A, for large $n$:\n%\n\\begin{equation}\n    \\label{eq:Hausman_normality_S-LS}\n    \\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0} \n        - \\sthat{\\underline{\\boldsymbol\\beta}}_\\stsc{LS}\n    \\approx\\mathcal{N}_p \\left(\\underline{\\stvec{0}},\n        \\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}\n    \\right)\n\\end{equation}\n%\nwhere \n$\\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n- \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}$\nis the matrix \n$\\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n- \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}$ \nwithout its first line and its first column.\n\n\\subsubsection{Comparison of LS and S}\n\nLet us consider the classical \\stsc{LS}~estimator\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ and the \\stsc{S}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ associated with the loss function\n$\\rho_0(\\cdot)$. As already mentioned, the choice of $\\rho_0$ is crucial to\nguarantee robustness. The function $\\rho_0$ usually used in the present context\nis the Tukey-Biweight function (\\ref{eq:Tukey_Biweight_function}): if the\ntuning constant $\\kappa$ is set at 1.547,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ has a breakdown point equal to\n50\\% (but a rather low Gaussian efficiency of only 28\\%). Under the null\nhypothesis (and Assumption~A), $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ and\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ are both consistent estimators of\n$\\boldsymbol\\beta$, but $\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ has a higher\nGaussian efficiency. Under the alternative hypothesis of a moderate\ncontamination, $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ still converges to\n$\\boldsymbol\\beta$ (see \\citealp{Omelka:2010}) but it is not the case for\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ anymore (the outliers distort the LS\nestimate and introduce a bias, in such a way that\n$\\sthat{\\boldsymbol\\beta}_\\stsc{LS}$ possesses another limit in probability\nthan $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$).\n\nThe test statistics proposed by \\citet{Dehon:2012} to check whether the\n\\stsc{LS} and \\stsc{S}~estimates of the regression coefficients are\nstatistically different is defined as\n\\begin{equation}\n    \\label{Hausman_SvsLS}\n    H = \\left(\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\underline{\\boldsymbol\\beta}}_\\stsc{LS}\\right)^{\\!t} \n        \\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}^{-1}\n        \\left(\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\underline{\\boldsymbol\\beta}}_\\stsc{LS}\\right)\n%\n\\end{equation}\nwith \n$\\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n- \\sthat{\\boldsymbol\\beta}_\\stsc{LS})}$ computed from\n(\\ref{eq:Hausman_sigmahat_S-LS}). It follows from\n(\\ref{eq:Hausman_normality_S-LS}) that $H$ is, under the null hypothesis\n$\\mathcal{H}_0$ (and Assumption~A), asymptotically distributed as a\n$\\chi_p^2$ (a chi-square distribution with $p$ degrees of freedom).\nConsequently, we may consider that the classical estimate and the \n\\stsc{S}~estimate of the regression slopes are significantly different, and hence decide\nto reject the null hypothesis $\\mathcal{H}_0$, if\n\\[\n    H > \\chi_{p;1-\\alpha}^2,\n\\]\nwhere $\\alpha$ is the given significance level and $\\chi_{p;1-\\alpha}^2$ is the\n$(1-\\alpha)$-quantile of the $\\chi_p^2$ distribution.\n\n\\subsubsection{Comparison of S and MM}\n\nSuppose now that the previous test has rejected the null hypothesis\n$\\mathcal{H}_0$: the significant difference between\n$\\sthat{\\underline{\\boldsymbol\\beta}}_\\stsc{LS}$ and\n$\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}$ indicates the presence\nof influential outliers in the sample and a robust regression estimator should\nthen be preferred. In this case, it might be a good strategy to replace the\n\\stsc{S}~estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ by an \n\\stsc{MM}~estimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$, since a good\nchoice of the loss function $\\rho(\\cdot)$ allows this \\stsc{MM}~estimator to\nreach a much higher efficiency than the initial \\stsc{S}~estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$. \\footnote{Recall here that\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ possesses the same breakdown\npoint as $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$.}. For instance, if we\ntake for $\\rho$ the Tukey-Biweight function (\\ref{eq:Tukey_Biweight_function})\nwith the tuning constant $\\kappa$ equal to 4.685, the Gaussian efficiency of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ attains 95\\%, and for\n$\\kappa=6.256$, the Gaussian efficiency of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ is equal to 99\\%. However,\nas already mentioned when we have studied the \\stsc{MM}~estimation procedure,\nit is not advised to consider too highly efficient \\stsc{MM}~estimators:\nindeed, a moderate contamination of the sample induces a bias for\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and, for a fixed sample,\nthis bias grows when the efficiency of the estimator raises (see\n\\citealp{maronna:etal:2006} and \\citealp{Omelka:2010}). As a consequence, it is\nof the utmost importance to find the highest efficiency we may fix for the\n\\stsc{MM}~estimator without paying the price of an excessive bias.\n\nThe statistical comparison of $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and \n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$\n(with a fixed value of the tuning constant $\\kappa$ for the loss function\n$\\rho$, hence a fixed Gaussian efficiency for the \\stsc{MM}~estimator) can be made\nusing the statistics\n%\n\\begin{equation}\n    \\label{Hausman_MMvsS}\n    H = \\left(\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{MM};\\rho_0,\\rho}\\right)^{\\!t}\n        \\sthat{\\underline{\\boldsymbol\\Sigma}}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}^{-1}\n        \\left(\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}\n            - \\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{MM};\\rho_0,\\rho}\\right)\n\\end{equation}\n%\nwith $\\sthat{\\boldsymbol\\Sigma}_{(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} -\n\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})}$ given by\n(\\ref{eq:Hausman_sigmahat_S-MM}). Under the null hypothesis $\\mathcal{H}_0$,\n$\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}$ and \n$\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{MM};\\rho_0,\\rho}$ are both \nconsistent estimators of \\underline{$\\boldsymbol\\beta$} and $H \\approx\n\\chi_p^2$. Under the alternative hypothesis $\\mathcal{H}_1$, that is, under a\nmoderate contamination of the sample, the bias of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ risks to be large (the\nmagnitude of the bias depends of the fixed efficiency of the \n\\stsc{MM}~estimator) and a potentially significant difference may appear between the\n\\stsc{S}~estimate and the \\stsc{MM}~estimate of the regression slopes. As a\nconsequence, we will decide to reject $\\mathcal{H}_0$---that is, in practice,\nwe will conclude that the contamination of the sample by outliers significantly\nbiases $\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{MM};\\rho_0,\\rho}$ and hence\ndistorts the \\stsc{MM}~estimation with respect to the \\stsc{S}~estimation---if\n\\[\n    H > \\chi_{p;1-\\alpha}^2,\n\\]\nwhere $\\alpha$ is the chosen significance level. \\citet{Dehon:2012}\npropose to repeat this test by considering successively different values for\nthe constant $\\kappa$ in function $\\rho$ (that is, different levels for the\nefficiency of $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$) and\nto retain ultimately the \\stsc{MM}~estimator that, while not being significantly\ndifferent from $\\sthat{\\underline{\\boldsymbol\\beta}}_{\\stsc{S};\\rho_0}$ \nand hence not rejecting the null, has the highest efficiency. This way of\nproceeding allows to find heuristically the highest efficiency that may have\nthe \\stsc{MM}~estimator without suffering from an excessive bias in presence of\nmoderate contamination of the sample by outliers.\n\n\n\\section{Examples}\n\n\\subsection{Comparing estimators} \n\nIn the first example, we will use a dataset made available by\n\\citet{rousseeuw:leroy:1987}. The dataset contains 47 stars in the direction of\nCygnus. The explanatory variable is the logarithm of the effective temperature\nat the surface of the star ($T_e$), and the dependent variable is the logarithm\nof its light intensity ($L/L_0$). In the scatterplot of\nfigure~\\ref{fig:stars_scatterplot}, it is evident that some stars (represented\nby hollow circles) have a very different behavior than the bulk of the data. To\nillustrate graphically the influence that these stars have on the estimation of\nthe regression line, we superpose to the scatterplot two lines estimated by (1)\nordinary least squares (solid line) and (2) a robust regression estimation\nmethod (more precisely, \\stsc{S}~estimation; dashed line).                  \\todo{Graph-Ex-1.do was missing; I recreated the graph from the description.}\n\n\n\\begin{figure}[h!]\n    \\centering\n    \\epsfig{file=eps/4/4}\n    \\caption{Effective temperatures and light intensities in star cluster CYG OB1}\n    \\label{fig:stars_scatterplot}\n\\end{figure}\n\n\nTo obtain the \\stsc{LS}~estimates for the intercept and slope of the regression\nof log intensity on log temperature in Stata, without making any difference \nbetween stars, we can type:\n\n\\begin{stlog}\n\\input{dof/4/5.log.tex}\n\\end{stlog}\n\nThe results of the \\stsc{LS}~estimation (solid line in\nfigure~\\ref{fig:stars_scatterplot}) indicate that, against intuition, if the\ntemperature of a star increases, its light intensity decreases in average\n(although the effect is not significantly different from zero). If instead of\nusing a classical estimator we use a robust estimator, the result changes\ndrastically. For illustrative purposes we will estimate the above model using\n\\stsc{LTS}, \\stsc{LMS}, \\stsc{M}, \\stsc{GM}, \\stsc{S} and \\stsc{MM} (with an\nefficiency fixed at 95\\%) estimators. However, since it has now been widely\naccepted that \\stsc{S} and \\stsc{MM}~estimators are preferable to \\stsc{LTS}\nand \\stsc{LMS} because of their higher efficiency and to \\stsc{M} and \n\\stsc{GM}~estimator because of their higher robustness with respect to outliers (see\nabove), in the subsequent examples we will focus exclusively on \\stsc{S} and\n\\stsc{MM}~estimates.\n\n\\subsubsection{LTS}\n\nA robust \\stsc{LTS}~estimator can be easily fit using the \\stcmd{robreg} package \nrunning the following command:\n\n\\begin{stlog}\n\\input{dof/4/6.log.tex}\n\\end{stlog}\n\nThe results from the \\stsc{LTS}~estimator are very different from those\nobtained for the \\stsc{LS}~estimation. Indeed what we observe here is that if\nthe log of the temperature of a star increases, its luminosity will increase as\nwell. In term of size of effect, the \\stsc{LTS}~estimator suggests that an\nincrease of 100\\% of the temperature is associated to an increase of the\nluminosity of approximately 473\\%.\n\n\\subsubsection{LMS}\n\nIf instead of the \\stsc{LTS}~estimator we wish to use the \\stsc{LMS}~estimator,\nwe can type:\n\n\\begin{stlog}\n\\input{dof/4/7.log.tex}\n\\end{stlog}\n\nEven if the size of effect seems to be slightly smaller than with \\stsc{LTS},\nthe sign of the relation is the same pointing towards a positive association\nbetween log-temperature and lightness of stars.\n\n\\subsubsection{M estimator}\n\nIf we use the \\stsc{M}~estimator (with a Huber\nloss function), we do not expect the estimation to resist to outliers. Indeed, \nin the theoretical section it has been shown how this\nestimator resists to vertical outliers but not to bad leverage points (i.e.\npoints outlying in the space of the explanatory variables). As expected, the\n\\stsc{M}~estimation provides results very similar to those of \\stsc{LS} and we can conclude\nthat the estimator breaks down.\n\nThe command to run the \\stsc{M}~estimator is:\n\n\\begin{stlog}\n\\input{dof/4/8.log.tex}\n\\end{stlog}\n\n\\subsubsection{GM estimator}\n\nThe Generalized \\stsc{M}~estimate is slightly more complicated to compute than\nthe \\stsc{M}~estimate. We first need to estimate the outlyingness of each\nindividual in the x-dimension, and then downweight leverage points while\nestimating the model using an \\stsc{M}~estimator. In this example, given that\nthere is a single explanatory variable, the outlyingness in the horizontal\ndimension can be measured by centering the data around a robustly estimated\nlocation parameter (e.g.\\ the Hodges-Lehman estimate or the median) and reducing\nit using a robustly estimated measure of dispersion (e.g.\\ the Croux and\nRousseeuw $Q_n$ estimate). In the case of multiple explanatory variables, the\noutlyingness in the space of the explanatory variables will have to be measured\nusing robust multivariate estimates of location and scatter described in\nchapter \\alert{XXX}. As far as the down-weighting scheme for outliers is\nconcerned, several alternatives have been proposed in the literature. In this\nexample we award a weight equal to zero to any star associated to a leverage\nlarger than 2.5 and equal to one otherwise. Given that there is one single\nexplanatory variable, the \\stsc{GM}~estimator should behave satisfactory.\n\nThe commands used for \\stsc{GM}~estimation are:                                 \\todo{To be updated}\n\n\\begin{stlog}\n\\input{dof/4/9.log.tex}\n\\end{stlog}\n\n\n\\subsubsection{S estimator}\n\nIf we estimate the model using an \\stsc{S}~estimator, we do not expect to have\nlarge differences with respect to \\stsc{LTS}, \\stsc{LMS} and \\stsc{GM} in terms\nof point estimates. However, its higher efficiency makes it theoretically more\nappealing. The command to run the \\stsc{S}~estimator is:\n\n\\begin{stlog}\n\\input{dof/4/10.log.tex}\n\\end{stlog}\n\nThe results indicate that if the temperature of a star doubles, its light\nintensity increases by approximately 329\\%. As stated in the theoretical\nsection, the gaussian efficiency of the \\stsc{S}~estimator with a 50\\%\nbreakdown point (and a Tukey biweight loss function) is only 28\\%. In order to\nincrease the efficiency while keeping the breakdown point at 50\\%, we can use\n\\stsc{MM}~estimators.\n\n\\subsubsection{MM estimator}\n\nIt is well-known that even if an \\stsc{MM}~estimator has a breakdown point of 50\\%,\nit can be associated to a relatively large bias if its efficiency is set too\nhigh. As explained in Subsection \\ref{subsec:Hausman}, a general procedure is\ntherefore to compare the \\stsc{MM}~estimate with a given level of efficiency to the\n\\stsc{S}~estimate, and see if there is a significant difference. If the difference\nis small, this means that the bias should not be too big.\n\nWe compute here an \\stsc{MM}~estimator with an efficiency set at 95\\%:\n\n\\begin{stlog}\n\\input{dof/4/11.log.tex}\n\\end{stlog}\n\nWe see that the \\stsc{MM}~estimation leads to results comparable to the\n\\stsc{S}~estimation in terms of point estimates but is associated to a much\nhigher efficiency. As explained above, a formal test could have been used but\nwe leave this for another example. The \\stsc{MM}~estimated model suggests that\nan increase of 100\\% of the temperature of a star is associated with an\nincrease of its luminosity by approximately 225\\%. In terms of the quality of\nthe fit, if we rely on the robust $R^2_w$ described previously, we see that\nthe model is pretty good in predicting the luminosity of stars for the vast\nmajority of the observations. Indeed close to 42\\% of the variations in terms\nof light intensity for the vast majority of the observations can be explained\nby the differences in temperatures.\n\n\n\\subsection{Identifying outliers} \n\nIn this second example where the objective is\nto unmask outliers, we use a dataset made available by Jeffrey D. Sachs and\nAndrew M. Warner in their article “Natural Resource Abundance\nand Economic Growth” (\\citeyear{sachs:warner:1997}). In this paper, the authors show\nthat economies with a high ratio of natural resource exports to GDP in 1970\n(the base year) tended to grow slowly during the subsequent 20 year period\n1970--1990. In the article the authors acknowledge the existence of outliers and\ntry to deal with them working with differences in fits. More precisely, they\nlook at how the predicted value for each observation varies when this specific\nobservation is removed from the sample when fitting the model and compare the\nresults with the model estimated using all of the observations. They expect to\nsee big differences in fits for outlying observations. However, if there are\nclusters of outliers, atypical observations will mask one another and will\nmost probably not be detected with this approach. The outliers they identify\nare Chad, Gabon, Guyana, and Malaysia.\n\nWe propose here to use another procedure to identify the outliers. This\nprocedure is simply based on the examination of the standardized residuals\nrelated to a regression \\stsc{S}~estimator. That is, to identify the outliers,\nwe first estimate the regression model by running the following command:\n\n\\begin{stlog}\n\\input{dof/4/12.log.tex}\n\\end{stlog}\n\nTo compute the standardized residuals, we then obtain the predicted values from\nthe model and divide the difference between observed values and predictions by\nthe scale parameter from the regression \\stsc{S}~estimate:\n\n\\begin{stlog}\n\\input{dof/4/13.log.tex}\n\\end{stlog}\n\nAfter that we can plot the standardized residuals and identify those that are\nlarger or smaller than two given cut-off points corresponding to two specific\nquantiles of the normal distribution. We use here the percentiles 2.5 and 97.5\nwhich are respectively equal to $-1.96$ and $1.96$.\n\n\\begin{stlog}\n\\input{dof/4/14.log.tex}\n\\end{stlog}\n\n\\begin{figure}[h!]\n    \\centering\n    \\epsfig{file=eps/4/14}\n    \\caption{Outliers in the Sachs and Warner data}\n    \\label{fig:countries_S_standardized_res}\n\\end{figure}\n\nWe see in Figure \\ref{fig:countries_S_standardized_res} that, among the four\ncountries identified as outliers by Sachs and Warner, only Malaysia is still\nemerging as outlier when using the \\stsc{S}~estimation procedure. On the other\nhand, other countries such as Hong Kong, Ecuador or Iran seem to be atypical\ncountries in the \\stsc{S}~regression but were not detected by the original\nauthors.\n\n\\subsection{Testing for the presence of outliers and setting the efficiency for MM estimation}\n\nFor this example, we again use the dataset relating the logarithm of the\neffective temperature at the surface of the star (explanatory variable $T_{e}$)\nand the logarithm of its light intensity (dependent variable $L/L_0$). The\nfirst question one might raise is: is there a significant difference between\nthe classic estimate and the robust one? To answer this question we simply\ncompute an \\stsc{S}~estimate using the \\stcmd{robreg s} command and apply the\n\\stcmd{hausman} option. This implies that the testing procedure comparing the\n\\stsc{S}~estimate with the \\stsc{LS}~estimate (see Subsection\n\\ref{subsec:Hausman}) is carried out.\n\n\\begin{stlog}\n\\input{dof/4/15.log.tex}\n\\end{stlog}\n\nThe results of the Hausman test indicate that the difference between the\n\\underbar{S} estimate and the \\stsc{LS}~estimate is significant (p-value $<\n.05$) and thus that outliers distort the \\stsc{LS}~estimation. We should\ntherefore use a robust estimator.\n\n\nAs stated previously \\stsc{S}~estimators are very robust against outlier\ncontamination but are relatively inefficient. \\stsc{MM}~estimators on the other\nhand are more efficient than \\stsc{S}~estimators but might be associated with a\nlarge bias if efficiency is set too high. To choose the level of efficiency to\nuse in practice we have to apply the testing procedure described in Subsection\n\\ref{subsec:Hausman} that compares the \\stsc{MM}~estimates related to some\ngiven levels of efficiency with respect to an \\stsc{S}~estimate. We can then\nfinally set the efficiency of the \\stsc{MM}~estimator at the highest efficiency\nlevel that does not lead to a rejection of the equality between the \n\\stsc{MM}~estimate and the \\stsc{S}~estimate. Doing this in practice is very simple as\nthe testing procedure is implemented in the \\stcmd{robreg mm} command. For\nexample, if the \\stcmd{robreg mm} command is run with the efficiency set at\n75\\% , the \\stcmd{hausman} option compares the \\stsc{MM}~estimate with 75\\%\nefficiency to the \\stsc{S}~estimate obtained at the first step of the \n\\stsc{MM}~estimation procedure. Similarly, if the efficiency is set at 85\\%, the\n\\texttt{hausman} option compares the \\stsc{MM}~estimate with 85\\% efficiency to\nthe \\stsc{S}~estimate, and so on. In this example we check whether we can set\nthe efficiency at 75\\%, 85\\%, 95\\%, and 99\\%. We obtain the following results:\n\n\\subsubsection{MM estimation with 75\\% efficiency}\n\n\\begin{stlog}\n\\input{dof/4/16.log.tex}\n\\end{stlog}\n\nThe results of the Hausman test indicate that there is no significant\ndifference between the \\stsc{MM}~estimate and the \\stsc{S}~estimate. It would\ntherefore be preferable to work with the \\stsc{MM}~estimator with an efficiency\nequal to 75\\% as it provides results comparable to the \\stsc{S}~estimator in\nterms of bias but has a much higher efficiency.\n\n\\subsubsection{MM estimation with 85\\% efficiency}\n\n\\begin{stlog}\n\\input{dof/4/17.log.tex}\n\\end{stlog}\n\nHere again the Hausman test statistics takes a low value which tells us that\nthere is no significant difference between the \\stsc{MM}~estimate and the\n\\stsc{S}~estimate.\n\n\\subsubsection{MM estimation with 95\\% efficiency}\n\n\\begin{stlog}\n\\input{dof/4/18.log.tex}\n\\end{stlog}\n\nIf we set the efficiency of the \\stsc{MM}~estimator to 95\\%, we still do not\nobserve any significant difference between the \\stsc{MM}~estimate and the\n\\stsc{S}~estimate.\n\n\\subsubsection{MM estimation with 99\\% efficiency}\n\n\\begin{stlog}\n\\input{dof/4/19.log.tex}\n\\end{stlog}\n\nIn the case of an efficiency of the \\stsc{MM}~estimator equal to 99\\%, the\nHausman test rejects the null hypothesis of equality between the \n\\stsc{MM}~estimate and the \\stsc{S}~estimate, which means that for this very high level\nof efficiency, the \\stsc{MM}~estimator suffers from a too large bias.\n\nTo summarize, it is clear that a classic estimator cannot be used in the\nexample because the \\stsc{LS}~estimates are clearly distorted. A robust\nestimator should be preferred. We may use an \\stsc{MM}~estimator with an\nefficiency equal to 95\\% instead of the less efficient \\stsc{S}~estimator since\ndespite the bias from which the \\stsc{MM}~estimator potentially suffers, the\n\\stsc{MM}~estimates of the regression parameters appear no significantly\ndifferent from the \\stsc{S}~estimates. It is not recommended to consider a\nhigher level of efficiency for the \\stsc{MM}~estimator (99\\%, for instance),\nsince the statistical test indicates that the bias becomes too big in that case.\n\n\\subsection{Recognizing the type of outliers}\n\nFor this example, we will use the famous auto dataset available from Stata.\nThis dataset contains the price of a set of cars as well as a series of\ncharacteristics. To see if outliers are present in the dataset, we regress the\nprice on all the available characteristics and compute the robust standardized\nresiduals. Obviously this will not allow to recognize the types of outliers. To\ndo so, we will use the graphical tool of \\citet{rousseeuw:zomeren:1990}. The\nidea here is to use a scatter plot considering on the vertical dimension the\nstandardized residuals and on the horizontal dimension the leverage of the\nobservations measured using the robust Mahalanobis distance (as described in\n(\\ref{eq:leverage})). For gaussian data it is well known that the standardized\nresiduals are normally distributed while the robust distances are distributed\nas a $\\chi_p^2$ where $p$ is the number of continuous explanatory variables. It\nis then natural to compare the standardized residuals and the leverages to some\nspecific quantiles of the $\\mathcal{N}(0,1)$ or $\\chi_p^2$ distributions in\norder to detect if an individual has to be considered as an outlier and, if it\nis the case, to which type of outlier it corresponds. We decide to choose here\nthe 2.5th and 97.5th percentiles of the $\\mathcal{N}(0,1)$ distribution, and\nthe 95th percentile of the $\\chi_p^2$ distribution. Those individuals leading\nto small robust standardized residuals in absolute value and small leverages\nare considered as standard individuals; those giving large standardized\nresiduals in absolute value and large leverages are defined as bad leverage\npoints; those that coincide with large standardized residuals in absolute value\nbut small leverages are considered as vertical outliers and, finally, those\nthat give small standardized residuals in absolute value but large leverages\nare good leverage points.\n\n\\alert{\\todo{Example will be fixed later.}\n\\begin{stlog}\n\\input{dof/4/20.log.tex}\n\\end{stlog}\n}\n\nFigure \\textbf{???} %\\ref{fig:autos_res_leverages} \nclearly shows, for example, that the Cadillac Seville is a bad leverage point.\nThis auto is indeed associated with a very large positive robust standardized\nresidual and has a big leverage effect which means that its characteristics in\nthe space of the explanatory variables are very different from the bulk of the\ndata. On the other hand, the Cadillac Eldorado, the Lincoln Versaille and some\nother cars have a small leverage effect---their characteristics do not appear\nas different from the vast majority of the observations---but are highly\noverpriced given their large positive residuals; these cars are identified as\nvertical outliers. Finally some other cars such as the Plymouth Arrow or the\nVolkswagen (VW Diesel) \\emph{inter alia} are not outliers in terms of prices\nbut have characteristics very different from the others. They are thus good\nleverage points. Note that even if these good leverage points do not have major\neffect on the estimation of the slope parameter and the constant, they might\naffect inference and shrink standard errors. It is hence important for\nresearchers to identify them.\n\n\n\\subsection{Dealing with dummies}\n\nFor this example, we use the \\stcmd{fertil1.dta} data set provided provided by\n\\cite{Wooldridge:2001} which is a pooled cross section on more than a thousand\nU.S.\\ women for the even years between 1972 and 1984. These data are used to\nstudy the relationship between women's education and fertility. We estimate a\nmodel relating the number of children ever born to a woman (kids) to the years\nof education, age, age squared, regional dummies, race dummies, the type of\nenvironment in which the women have been reared and year dummies, using an\n\\stsc{MS}~estimator. Given the large number of dummy variables, it is very\nlikely that the subsampling algorithm described in Subsection\n\\ref{subsec:MM_estimation} leads to perfectly collinear subsamples. Using an\n\\stsc{MS}~estimator should tackle the problem.\n\n\\alert{\\todo{Example will be fixed later.}\n\\begin{stlog}\n\\input{dof/4/21.log.tex}\n\\end{stlog}\n}\n\nThe results clearly point towards a robust and statistically significant\nnegative relationship between education and fertility. Indeed, each additional\nyear of schooling is associated to an average reduction of fertility (i.e.\\\nnumber of children) equal to 0.19. To identify the outliers and recognize their\ntype, we again call on the graphical tool proposed by\n\\citet{rousseeuw:zomeren:1990}. The only difference with the previous example\nis that dummy explanatory variables cannot create any leverage effect and\nshould therefore be treated differently from the other explanatory variables.\nTo estimate robust distances, we rely on the Stahel and Donoho multivariate\nestimator of location and scatter (this estimator will be described in details\nin Chapter \\textbf{???}). The latter is a projection based estimator that allows\nthe pratialling out of dummy variables to calculate leverage effects. As before\nwe can choose a quantile above which individuals can be seen as potentially\noutlying. We use here the 0.5th and 99.5th percentiles of the\n$\\mathcal{N}(0,1)$ distribution as cut-off points for the robust standardized\nresiduals, and the 99th percentile of the chi-square distribution with $p_1$\ndegrees of freedom, where $p_1$ is the number of continuous explanatory\nvariables, as cut-off point for the robust distances.\nIn Figure \\textbf{???}%\\ref{fig:fertil1_res_leverages}\n, we highlight the women for which the robust standardized residuals and (or)\nthe robust distances exceed the cut-off points.\n\nIt is evident that individuals such as 565 have more children that one would\nexpect given their characteristics (which are not quite different\nfrom the bulk of the data). On the other hand individuals such as 706, 767 or\n1063 have characteristics that are very different from the vast majority of\nthe individuals; however their number of children is in accordance with her\ncharacteristics. Finally individual such as 519, or 490 or 967 have\ncharacteristics that are very different from the others. The first one has a\nnumber of children that is much smaller than one would expect according to the\nestimated model while the two others have more children than expected.\n\n\n\\section{Appendix 1: M estimators of location and scale}\n\\label{sec:robreg:appendix1}\n\nThe application of the \\stsc{M}~estimation approach in the particular case of the\nlocation-scale model (\\ref{eq:location_scale_model}) leads to the \\stsc{M}~estimators\nof location and scale.\n\n\\subsection{M estimator of location}\n\nAn \\stsc{M}~estimate $\\sthat{\\mu}_{\\stsc{M};\\rho}$ of $\\mu$ is defined by\n\\[\n    \\sthat{\\mu}_{\\stsc{M};\\rho} \n    = \\argmin_\\mu \\sum_{i=1}^{n}\\rho\\left(\\frac{y_i-\\mu}{\\sthat{\\sigma}}\\right)\n\\]\nwhere $\\rho(\\cdot)$ is a loss function that is positive, even (such that\n$\\rho(0) = 0$) and not decreasing for positive values $u$, and $\\sthat{\\sigma}$\nis a preliminary robust estimate of $\\sigma$ if this scale parameter is unknown\n(the \\stsc{MADN}, for example). We may also characterize\n$\\sthat{\\mu}_{\\stsc{M};\\rho}$ as a solution of the following estimating\nequation:\n%\n\\begin{equation}\n    \\label{eq:M_location_equation}\n    \\sum_{i=1}^{n} \\psi\\left(\\frac{y_i-\\mu}{\\sthat{\\sigma}}\\right) = 0\n\\end{equation}\n%\nwhere $\\psi(u) = \\rho'(u)$.\n\nTaking $\\rho(u) = u^2$, we obtain $\\psi(u) = 2u$ and hence\n\\[\n    \\sum_{i=1}^{n} (y_i-\\sthat{\\mu}_{\\stsc{M};\\rho}) = 0\n\\]\nimplying that $\\sthat{\\mu}_{\\stsc{M};\\rho} = \\frac{1}{n}\\sum_{i=1}^{n} y_i =\n\\sthat{\\mu}_\\stsc{LS}$. Taking $\\rho(u) = |u|$, we have $\\psi(u) = \\sign(u)$\nand $\\sum_{i=1}^{n} \\sign(y_i-\\sthat{\\mu}_{\\stsc{M};\\rho}) = 0$; this leads to\n$\\sthat{\\mu}_{\\stsc{M};\\rho} = \\med\\{ y_i\\} = \\sthat{\\mu}_\\stsc{LAD}$.\n\nIn general, if $\\psi$ is not redescending, the equation\n(\\ref{eq:M_location_equation}) may be solved using the Newton-Raphson algorithm\nwith a robust estimate of $\\mu$---the empirical median $\\med\\{ y_i\\}$, for\ninstance---as initial value for $\\mu$.\n\nThe influence function of the functional $T$ associated to the location\n\\stsc{M}~estimator $\\sthat{\\mu}_{\\stsc{M};\\rho}$ under the distribution $F_{0,1}$\nof the error term $\\nu$ in the location-scale model---recall here that\n$F_{0,1}$ is assumed to be symmetric around zero---takes the form:\n\\[\n    \\stsc{IF}(u;T,F_{0,1}) = \\frac{\\psi(u)}{E_{F_{0,1}}[\\psi'(\\nu)]}.\n\\]\nConsequently, the choice of the function $\\rho$, and hence of the function\n$\\psi$, completely conditions the form of the influence function.\n\nMoreover, it has been proven that an univariate location \\stsc{M}~estimator has\nan asymptotic breakdown point equal to 50\\% whenever the function $\\psi$ is\n\\emph{non decreasing}, bounded and symmetric, and the preliminary estimator of\nthe scale parameter $\\sigma$ is the \\stsc{MADN} (see\n\\citealp[54]{Huber:2009}).\\footnote{The breakdown point of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is actually equal to the breakdown\npoint of the preliminary estimator of the scale parameter $\\sigma$.} The\nasymptotic breakdown point is null if $\\psi$ is unbounded. If $\\psi$ is equal\nto the function $\\psi_{\\kappa}^{\\stsc{B}}$ and hence is redescending, the\nbreakdown point of $\\sthat{\\mu}_{\\stsc{M};\\rho}$ is strictly smaller than 50\\%\nand depends upon the breakdown point of the preliminary scale estimator, upon\nthe constant $\\kappa$, but also upon the configuration of the sample (see\n\\citealp[78]{maronna:etal:2006}).\\footnote{Note however that it is possible to\nprove that, using the \\stsc{MADN} as initial scale estimator, the breakdown\npoint of $\\sthat{\\mu}_{\\stsc{M};\\rho_{\\kappa}^{\\stsc{B}}}$ is strictly greater\nthan 0.49 in the Gaussian case.}\n\n\\subsection{M estimator of scale}\n\nA \\stsc{M}~estimate $\\sthat{\\sigma}_{\\stsc{M};\\rho}$ of the scale parameter\n$\\sigma$ is defined as the solution of the equation\n%\n\\begin{equation}\n    \\label{eq:M_scale_loc_equation}\n    \\frac{1}{n} \\sum_{i=1}^{n} \\rho\\left(\\frac{y_i-\\sthat{\\mu}}{\\sigma}\\right) = \\delta\n\\end{equation}\n%\nwhere $\\rho(\\cdot)$ is a loss function that is positive, even, not decreasing\nfor positive values and bounded, and $\\sthat{\\mu}$ is a preliminary robust\nestimate of $\\mu$ if this location parameter is unknown (the median, for\ninstance). To ensure the consistency of $\\sthat{\\sigma}_{\\stsc{M};\\rho}$ for\n$\\sigma$, we have to take $\\delta = E_{F_{0,1}}[\\rho(\\nu)]$. An usual choice\nfor the loss function $\\rho$ is the Tukey-Biweight function $\\rho_{\\kappa}^{B}$\ndefined by (\\ref{eq:Tukey_Biweight_function}).\n\nThe \\stsc{M}~estimators of scale are translation invariant and scale\nequivariant. The influence function of the functional $S$ associated to the\nscale \\stsc{M}~estimator $\\sthat{\\sigma}_{\\stsc{M};\\rho}$ under the\ndistribution $F_{0,1}$ of the error term $\\nu$ of the location-scale model is\ngiven by\n\\[\n    \\stsc{IF}(u;S,F_{0,1}) = \\frac{\\rho(u) -\\delta}{E_{F_{0,1}}[\\rho'(\\nu)\\nu]}.\n\\]\nHence, the choice of a bounded function $\\rho$ implies that the influence\nfunction is also bounded. The asymptotic breakdown point of the scale\n\\stsc{M}~estimator is:\n\\[\n    \\varepsilon^*(S,F_{0,1}) = \\min\\left(\\frac{\\delta}{\\rho(\\infty)},\n        1-\\frac{\\delta}{\\rho(\\infty)}\\right)\n\\]\nwhich is strictly positive but not always equal to 50\\%, even if $\\rho$ is\nbounded.\n\n\\begin{stremark}\nWe may try to jointly estimate $\\mu$ and $\\sigma$ by solving simultaneously two\nequations of the type (\\ref{eq:M_location_equation}) and\n(\\ref{eq:M_scale_loc_equation}) (see, for example, \\citealp{Huber:2009},\nchapter 6). This makes computations more complicated. Moreover, as explained in\n\\cite{maronna:etal:2006}, it generally provides for\n$\\sthat{\\mu}_{\\stsc{M};\\rho}$ an asymptotic breakdown point smaller than\n50\\%---hence, smaller than the breakdown point attainable by using the\n\\stsc{MADN} as preliminary estimator of $\\sigma$. Consequently, the joint\nestimation of $\\mu$ and $\\sigma$ is not recommended, especially when the scale\nparameter $\\sigma$ is considered as a nuisance parameter in the location-scale\nmodel.\n\\end{stremark}\n\n\\section{Appendix 2: Generalized Method of Moments (GMM) and asymptotic distributions of regression M, S and MM estimators}\n\\label{sec:robreg:appendix2}\n\n\\subsection{GMM estimation principle}\n\nFor simplicity, let us consider immediately the context of the regression model\n(\\ref{eq:linear_regr_model}). Let $y$ be the scalar dependent variable and\n$\\stvec{x} = (1, x_1, \\dots, x_p)^t$ be the $(p+1)$-vector of covariates. We\nassume here that the observations $(\\stvec{x}_1, y_1), \\dots, (\\stvec{x}_n,\ny_n)$ are generated by a \\emph{stationary} and \\emph{ergodic} process\n$H$.\\footnote{A \\emph{stationary} process is a stochastic process whose joint\nprobability distribution does not change when shifted in time or space.\nConsequently, parameters such as the mean and the variance, if they exist, also\ndo not change over time or position. Hence, the mean and the variance of the\nprocess do not follow trends. Furthermore, a stochastic process is said to be\n\\emph{ergodic} if its statistical properties (such as its mean and variance)\ncan be estimated consistently from a single, sufficiently long sample\n(realization) of the process.\\alert{THIS FOOTNOTE IS A REPETITION}} We also\nassume, to avoid too much technicalities, that there is \\emph{no\nautocorrelation}, that is, that the observations $(\\stvec{x}_i, y_i)$, $i = 1,\n\\dots, n$, are \\emph{independent}.\\footnote{The interested reader can find very\ngeneral results, valid in presence of autocorrelation, in \\cite{Croux:2003}.}\n\nSuppose that our objective is to estimate the functional $\\boldsymbol\\theta =\n\\boldsymbol\\theta(H)$ that is implicitly defined by the equation\n%\n\\begin{equation}\n    \\label{Eq:GMM_moments_conditions}\n    E_H[\\stvec{m}(y, \\stvec{x}, \\boldsymbol\\theta)] = \\stvec{0}\n\\end{equation}\n%\nwhere $\\stvec{m}$ is a known $k$-valued function, and $E_H[\\cdot]$ denotes the\nmathematical expectation with respect to $H$. If $k$ equals the dimension of\nthe parameter $\\boldsymbol\\theta$ to estimate, that is, if the number of\nmoments conditions specified by (\\ref{Eq:GMM_moments_conditions}) coincides\nwith the dimension of $\\boldsymbol\\theta$, then the \\stsc{GMM}~estimation\nproblem is said to be \\emph{exactly-identified}. Note that it is the case in\nthe setting studied hereafter. The \\stsc{GMM}~estimator\n$\\sthat{\\boldsymbol\\theta}_\\stsc{GMM}$ of $\\boldsymbol\\theta$ is then simply\nobtained by solving the sample analogue of (\\ref{Eq:GMM_moments_conditions}),\nthat is,\n%\n\\begin{equation}\n    \\label{Eq:GMM_equations}\n    \\frac{1}{n} \\sum_{i=1}^{n} \\stvec{m}(y_i, \\stvec{x}_i, \n    \\sthat{\\boldsymbol\\theta}_\\stsc{GMM}) = \\stvec{0}.\n\\end{equation}\n\nUnder regularity conditions detailed in \\citet{Hansen:1982}, the \n\\stsc{GMM}~estimator $\\sthat{\\boldsymbol\\theta}_\\stsc{GMM}$ defined by\n(\\ref{Eq:GMM_equations}) has a limiting normal distribution:\n%\n\\begin{equation}\n    \\label{Eq:GMM_estimator_normality}\n    \\sqrt{n}(\\sthat{\\boldsymbol\\theta}_\\stsc{GMM} - \\boldsymbol\\theta)\n    \\rightarrow^d \\mathcal{N}(\\stvec{0},\\stmat{V})\n\\end{equation}\n%\nwhere, in the exactly-identified case,\n%\n\\begin{equation}\n    \\label{Eq:GMM_estimator_V}\n    \\stmat{V} = \\stmat{G}^{-1} \\boldsymbol\\Omega (\\stmat{G}^t)^{-1}\n\\end{equation}\n%\nwith\\footnote{Here and later, we simply write $E[\\cdot]$ for $E_H[\\cdot]$.}\n%\n\\begin{equation}\n    \\label{Eq:GMM_estimator_G_Omega}\n    \\stmat{G} = E\\left(\\frac{\\partial\\stvec{m}(y, \\stvec{x}, \\boldsymbol\\theta)}\n                            {\\partial\\boldsymbol\\theta^t}\\right)\n    \\quad\\text{and}\\quad\n    \\boldsymbol\\Omega = E\\left[\\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)\n                        \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)^t\\right]\n\\end{equation}\n\n\n\\subsection{M, S and MM estimators as GMM estimators}\n\nLet us first consider the case where we estimate the parameters\n$\\boldsymbol\\beta$ and $\\sigma$ simultaneously by an \\stsc{M}~estimation\nprocedure. Let us denote by $\\rho(\\cdot)$ and $\\rho_0(\\cdot)$ the loss\nfunctions used for the \\stsc{M}~estimation of $\\boldsymbol\\beta$ and $\\sigma$,\nrespectively. Then the \\stsc{M}~regression estimator\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ and the \\stsc{M}~scale estimator\n$\\sthat{\\sigma}_{\\rho_0}$ are such that\n%\n\\begin{equation}\n    \\label{Eq:GMM_equations_M}\n    \\begin{aligned}\n        \\frac{1}{n} \\sum_{i=1}^{n} \n            \\psi\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i \n        & = \\stvec{0}\n        \\\\\n        \\frac{1}{n}\\sum_{i=1}^{n}\n            \\rho_0\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right) - \\delta\n        & = 0\n    \\end{aligned}\n\\end{equation}\n%\nwhere $\\psi(u) = \\rho'(u)$, $\\delta$ is a selected constant and, using similar\nnotations as in the previous sections, $\\sthat{\\sigma}_{\\rho_0} =\ns_{\\rho_0}(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}), \\dots,\nr_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}))$. This shows that the \n\\stsc{M}~estimator $(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}^t,\n\\sthat{\\sigma}_{\\rho_0})^t$ is an exactly-identified \\stsc{GMM}~estimator for\n$\\boldsymbol\\theta = (\\boldsymbol\\beta^t, \\sigma)^t$, with\n%\n\\begin{equation}\n    \\label{Eq:GMM_moment_function_M}\n    \\stvec{m}(y, \\stvec{x}, \\boldsymbol\\theta) =\n    \\begin{pmatrix}\n        \\psi\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta}{\\sigma}\\right) \\stvec{x}\n        \\\\[1ex]\n        \\rho_0\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta}{\\sigma}\\right) - \\delta\n    \\end{pmatrix}\n\\end{equation}\n\n\\stsc{S}~estimators of regression and scale depend only on a chosen loss function\n$\\rho_0$ and on a constant $\\delta$. We have defined the \\stsc{S}~regression\nestimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ as follows:\n%\n\\begin{equation}\n    \\label{eq:S_min_rho0}\n    \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0} = \\argmin_{\\boldsymbol\\beta} \n    s_{\\rho_0}(r_1(\\boldsymbol\\beta), \\dots, r_n(\\boldsymbol\\beta))\n\\end{equation}\n%\nwhere $s_{\\rho_0}$ is a measure of dispersion satisfying\n\\[\n    \\frac{1}{n} \\sum_{i=1}^{n} \n    \\rho_0\\left(\\frac{r_i(\\boldsymbol\\beta)}{s_{\\rho_0}(r_1(\\boldsymbol\\beta), \n        \\dots, r_n(\\boldsymbol\\beta))}\\right)\n    - \\delta =0 \n    \\quad\\text{for all $\\boldsymbol\\beta \\in \\mathbb{R}^{p+1}$}.\n\\]\nThe scale estimator is then simply given by\n\\[\n    \\sthat{\\sigma}_{\\rho_0} = \n    s_{\\rho_0}\\left(r_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}), \\dots,\n    r_n(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\\right).\n\\]\nAs previously explained, $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$\nand $\\sthat{\\sigma}_{\\rho_0}$ satisfy the first order conditions\n%\n\\begin{equation}\n    \\label{Eq:GMM_equations_S}\n    \\begin{aligned}\n        \\frac{1}{n} \\sum_{i=1}^{n}\n            \\rho_0'\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i \n        & = \\stvec{0}\n        \\\\\n        \\frac{1}{n} \\sum_{i=1}^{n}\n            \\rho_0\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right) - \\delta \n        & = 0.\n    \\end{aligned}\n\\end{equation}\n%\nNote that the equations (\\ref{Eq:GMM_equations_S}) are of the same form as\n(\\ref{Eq:GMM_equations_M}). Hence an \\stsc{S}~estimator is first-order\nequivalent with an M-estimator where $\\rho(\\cdot) =\\rho_0(\\cdot)$, and has the\nsame asymptotic distribution (see \\citealp{rousseeuw:yohai:1984}). Note however\nthat the function $\\rho_0$ defining the \\stsc{S}~estimator needs to be bounded\nto get a positive breakdown point for the regression estimator. But if $\\rho_0$\nis bounded, $\\rho_0'$ is redescending and the first set of equations in\n(\\ref{Eq:GMM_equations_S})---the set of equations involving $\\rho_0'$---may\nhave multiple solutions. Therefore one usually uses (\\ref{eq:S_min_rho0}) to\ncompute the \\stsc{S}~estimate but (\\ref{Eq:GMM_equations_S}) to determine its\nasymptotic distribution. Actually, (\\ref{Eq:GMM_equations_S}) implies that\n$(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}^t,\\sthat{\\sigma}_{\\rho_0})^t$\n is first-order equivalent with the \\stsc{GMM}~estimator for $\\boldsymbol\\theta\n= (\\boldsymbol\\beta^t,\\sigma)^t$,\nwith\n\\[\n    \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta) = \n    \\begin{pmatrix}\n        \\rho_0'\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta}{\\sigma}\\right) \\stvec{x}\n        \\\\[1ex]\n        \\rho_0\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta}{\\sigma}\\right) - \\delta\n    \\end{pmatrix}\n\\]\n\n\nLet us now focus on \\stsc{MM}~estimators of regression. First one needs to\ncompute \\stsc{S}~estimators\n$(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}^t,\\sthat{\\sigma}_{\\rho_0})^t$ for\na given function $\\rho_0$ and a constant $\\delta$. Secondly, for a given\nfunction $\\psi=\\rho'$, the \\stsc{MM}~estimator of regression solves\n\\[\n    \\frac{1}{n} \\sum_{i=1}^{n}\n    \\psi\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n        {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i = \\stvec{0}.\n\\]\nNote that $\\rho$ needs to be different from $\\rho_0$, otherwise the\n\\stsc{MM}~estimator would be equivalent with an \\stsc{S}~estimator and share\nthe low efficiency of the latter. In this \\stsc{MM}~estimation procedure,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$,\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and $\\sthat{\\sigma}_{\\rho_0}$ are\nsuch that\n%\n\\begin{equation}\n    \\label{Eq:GMM_equations_MM}\n    \\begin{aligned}\n        \\frac{1}{n} \\sum_{i=1}^{n}\n            \\psi\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n                {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i\n        & = \\stvec{0}\n        \\\\\n        \\frac{1}{n} \\sum_{i=1}^{n}\n            \\rho_0'\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}}\n            {\\sthat{\\sigma}_{\\rho_0}}\\right) \\stvec{x}_i\n        & = \\stvec{0}\n        \\\\\n        \\dfrac{1}{n} \\sum_{i=1}^{n}\n            \\rho_0\\left(\\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}}\n                {\\sthat{\\sigma}_{\\rho_0}}\\right) - \\delta\n        & = 0.\n    \\end{aligned}\n\\end{equation}\n%\nDefining $\\boldsymbol\\theta =\n(\\boldsymbol\\beta^t,\\boldsymbol\\beta_0^t,\\sigma)^t$, where the first parameter\n$\\boldsymbol\\beta$ will be estimated by\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ and the latter two by\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and $\\sthat{\\sigma}_{\\rho_0}$,\nequations (\\ref{Eq:GMM_equations_MM}) show that\n$(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}^t,\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}^t,\\sthat{\\sigma}_{\\rho_0})^t$ is\nfirst-order equivalent with the \\stsc{GMM}~estimator for $\\boldsymbol\\theta$,\nwith\n\\[\n    \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta) =\n    \\begin{pmatrix}\n        \\psi\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta}{\\sigma}\\right) \\stvec{x}\n        \\\\[1ex]\n        \\rho_0'\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta_0}{\\sigma}\\right) \\stvec{x}\n        \\\\[1ex]\n        \\rho_0\\left(\\frac{y-\\stvec{x}^t\\boldsymbol\\beta_0}{\\sigma}\\right) - \\delta\n    \\end{pmatrix}\n\\]\nUsing the generic notations $u_0 = (y-\\stvec{x}^t\\boldsymbol{\\beta}_0)/\\sigma$\nand $u = (y-\\stvec{x}^t\\boldsymbol\\beta)/\\sigma$, the moment function\n$\\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)$ takes the simpler form\n\\[\n    \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta) =\n    \\begin{pmatrix}\n        \\psi(u) \\stvec{x}       \\\\\n        \\rho_0'(u_0) \\stvec{x}  \\\\\n        \\rho_0(u_0) - \\delta\n    \\end{pmatrix}\n\\]\nor still more shortly,\n%\n\\begin{equation}\n    \\label{Eq:GMM_moment_function_MM}\n    \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta) =\n    \\begin{pmatrix}\n        \\psi\\stvec{x}       \\\\\n        \\rho_0'\\stvec{x}    \\\\\n        \\rho_0-\\delta\n    \\end{pmatrix}\n\\end{equation}\n%\nif we simply replace $\\psi(u)$ by $\\psi$, $\\rho_0(u_0)$ by $\\rho_0$, and\n$\\rho_0'(u_0)$ by $\\rho_0'$. This compact notation for the moment function will\nbe more practice to use in the sequel.\n\n\\subsection{Asymptotic variance matrix of an MM estimator}\n\n\\subsubsection{Assumption A1: The observations are generated by a stationary and ergodic process and are independent}\n\nThe first-order equivalence of\n$(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}^t,\n\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}^t, \\sthat{\\sigma}_{\\rho_0})^t$ with\na \\stsc{GMM}~estimator for $\\boldsymbol\\theta = (\\boldsymbol\\beta^t,\n\\boldsymbol\\beta_0^t, \\sigma)^t$ allows us to conclude that, if the\nobservations $(\\stvec{x}_1, y_1), \\dots, (\\stvec{x}_n, y_n)$ are generated by a\n\\emph{stationary} and \\emph{ergodic} process, and are \\emph{independent}\n(Assumption~A1),\\footnote{This Assumption~A1 coincides with Assumption~A in\nSection~\\ref{subsec:asymptotic_distr_M_S_MM_estimators}. We add here an number\nto the letter “A” in order to clearly distinguish the various assumptions we\nwill consider in the sequel of this appendix.}\n\\[\n    \\sqrt{n}\\left(\n    \\begin{bmatrix}\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}\\\\\n        \\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}\\\\\n        \\sthat{\\sigma}_{\\rho_0}\n    \\end{bmatrix}\n    -\n    \\begin{bmatrix}\n        \\boldsymbol\\beta\\\\\n        \\boldsymbol\\beta_0\\\\\n        \\sigma\n    \\end{bmatrix}\n    \\right)  \\rightarrow^{d} \\mathcal{N}(\\stvec{0}, \\stmat{V}_\\stsc{MM})\n\\]\nwhere\n\\[\n    \\stmat{V}_\\stsc{MM} = \\stmat{G}_\\stsc{MM}^{-1} \\boldsymbol\\Omega_\\stsc{MM}\n        (\\stmat{G}_\\stsc{MM}^t)^{-1}\n\\]\nwith the matrices $\\stmat{G}_\\stsc{MM}$ and $\\boldsymbol\\Omega_\\stsc{MM}$\nobtained by applying relations (\\ref{Eq:GMM_estimator_G_Omega}) to the moment\nfunction (\\ref{Eq:GMM_moment_function_MM}):\n\\[\n    \\stmat{G}_\\stsc{MM} = -\\frac{1}{\\sigma} E\n    \\begin{pmatrix}\n        \\psi'\\stvec{x}\\stvec{x}^t & \\stvec{0}                    & \\psi'u\\stvec{x}      \\\\\n        \\stvec{0}                 & \\rho_0''\\stvec{x}\\stvec{x}^t & \\rho_0''u_0\\stvec{x} \\\\\n        \\stvec{0}                 & \\stvec{0}                    & \\rho_0'u_0  \n    \\end{pmatrix}\n\\]\nand\n\\[\n    \\boldsymbol\\Omega_\\stsc{MM} = E\n    \\begin{pmatrix}\n        \\psi^2\\stvec{x}\\stvec{x}^t      & \\psi\\rho_0'\\stvec{x}\\stvec{x}^t & \\psi\\rho_0\\stvec{x}   \\\\\n        \\psi\\rho_0'\\stvec{x}\\stvec{x}^t & (\\rho_0')^2\\stvec{x}\\stvec{x}^t & \\rho_0\\rho_0'\\stvec{x}\\\\\n        \\psi\\rho_0\\stvec{x}^t           & \\rho_0\\rho_0'\\stvec{x}^t        & \\rho_0^2-\\delta^2\n    \\end{pmatrix}\n\\]\nIn particular, this result establishes the consistency of the \\stsc{MM}~regression\nestimator $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$.\nMoreover, using the upper left $(p+1) \\times (p+1)$ submatrix of\n$\\stmat{V}_\\stsc{MM}$, we obtain that the asymptotic variance of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ is equal to\n%\n\\[\n    \\mathrm{Avar}_1 (\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n        = \\frac{1}{n} \\left[\\stmat{A} E(\\psi^2\\stvec{x}\\stvec{x}^t) \\stmat{A}\n        - \\stmat{a} E(\\psi\\rho_0\\stvec{x}^t) \\stmat{A} \n        - \\stmat{A} E(\\psi\\rho_0\\stvec{x}) \\stmat{a}^t\n        + E(\\rho_0^2-\\delta^2) \\stmat{a}\\stmat{a}^t \\right]\n\\]\n%\nwhere\n\\[\n    \\stmat{A} = \\sigma E(\\psi'\\stvec{x}\\stvec{x}^t)^{-1}\n    \\quad\\text{and}\\quad\n    \\stmat{a} = \\stmat{A}\\frac{E(\\psi'u\\stvec{x})}{E(\\rho_0'u_0)}.\n\\]\n\nThis expression of\n$\\mathrm{Avar}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is then\nestimated by its empirical counterpart\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$, by\napplying the following two rules:\n\\begin{enumerate}\n    \\item Replace, in $u$ and $u_0$, the parameters $\\boldsymbol\\beta$,\n    $\\boldsymbol\\beta_0$ and $\\sigma$ by the estimates \n    $\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$, \n    $\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ and $\\sthat{\\sigma}_{\\rho_0}$.\n\n    \\item Replace $E(\\cdot)$ by $\\frac{1}{n}\\sum_{i=1}^{n}(\\cdot)$.\n\\end{enumerate}\n\nFor example, the first term of\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is\ngiven by\n\\[\n    \\frac{1}{n} \\left(\\sthat{\\stmat{A}}\\left[\n        \\frac{1}{n}\\sum_{i=1}^{n}\\psi\\left(\n            \\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n            {\\sthat{\\sigma}_{\\rho_0}}\n            \\right)^{\\!\\!2} \\stvec{x}_i\\stvec{x}_i^t\n    \\right] \\sthat{\\stmat{A}}\\right)\n\\]\nwith\n\\[\n    \\sthat{\\stmat{A}} = \\sthat{\\sigma}_{\\rho_0}\\left[\n        \\frac{1}{n}\\sum_{i=1}^{n}\\psi'\\left(\n            \\frac{y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}}\n            {\\sthat{\\sigma}_{\\rho_0}}\n    \\right) \\stvec{x}_i\\stvec{x}_i^t\\right]^{-1}.\n\\]\n\nUsing standard asymptotic arguments, it can be shown that\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is\na consistent estimate of\n$\\mathrm{Avar}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$. From\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$,\nstandard errors for the regression coefficients are obtained in the usual way:\nfor $j = 0, 1, \\dots, p$,\n\\[\n    \\mathrm{SE}\\left(\\big[\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}\\big]_j\\right) \n    = \\sqrt{\\big[\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\\big]_{jj}}.\n\\]\n\n\nMoreover, the estimate\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ of\nthe asymptotic variance\n$\\mathrm{Avar}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$ is robust\nwith respect to bad leverage points and vertical outliers. Indeed, if there are\nobservations yielding large residuals with respect to the robust \\stsc{MM}~fit,\nthen\n$\\psi[(y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})/\\sthat{\\sigma}_{\\rho_0}]$\nhas a small value when $\\psi$ is a redescending function.\\footnote{Recall that,\nif $\\psi$ is redescending, it has the property to be equal to zero for large\narguments.} Hence, if there are bad leverage points in the sample, then their\n$\\stvec{x}_i$-value is large, but at the same time\n$\\psi[(y_i-\\stvec{x}_i^t\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})/\\sthat{\\sigma}_{\\rho_0}]$\nwill be zero. This explains intuitively why vertical outliers and bad leverage\npoints have only a limited influence on the estimate\n$\\sthat{\\mathrm{Avar}}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$.\n\n\\subsubsection{Assumption A2: Absence of heteroskedasticity}\n\nA simplification of the asymptotic variance of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ occurs when, in addition to\nAssumption~A1, we assume that there is \\emph{no heteroskedasticity}, that is,\nwe assume that the processes $\\stvec{x}_i$ and $(u_i,u_{0i})$ are independent\n(Assumption~A2). In that case, the asymptotic variance of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ becomes\n\\[\n\\begin{split}\n    \\mathrm{Avar}_{12}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n    & = \\frac{1}{n} \\big[ E(\\psi^2)\\stmat{A}_2 E(\\stvec{x}\\stvec{x}^t) \\stmat{A}_2\n      - E(\\psi\\rho_0) \\stmat{a}_2 E(\\stvec{x}^t) \\stmat{A}_2\n    \\\\\n    & \\qquad\n      - E(\\psi\\rho_0) \\stmat{A}_2 E(\\stvec{x}) \\stmat{a}_2^t\n      + E(\\rho_0^2-\\delta^2)  \\stmat{a}_2\\stmat{a}_2^t \\big]\n\\end{split}\n\\]\nwhere\n\\[\n    \\stmat{A}_2 = \\sigma \\frac{E(\\stvec{x}\\stvec{x}^t)^{-1}}{E(\\psi')}\n    \\quad\\text{and}\\quad\n    \\stmat{a}_2 = \\stmat{A}_2 \\frac{E(\\psi'u) E(\\stvec{x})}{E(\\rho_0'u_0)}.\n\\]\nTaking the empirical counterpart yields\n$\\sthat{\\mathrm{Avar}}_{12}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$.\nHowever, \\citet{Croux:2003} do advise against the use of this variance matrix\nestimator in practice, even when assumptions A1 and A2 hold. The reason is that\nthis estimator will not be robust with respect to (good and bad) leverage\npoints. Indeed, $\\sthat{\\stmat{A}}_2$, for example, is proportional to the\ninverse of an empirical second moment matrix of the observations $\\stvec{x}_i$.\nLeverage points are outlying in the covariates' space, and will then have a\nstrong influence on $\\sthat{\\stmat{A}}_2$. This can even lead\n$\\sthat{\\mathrm{Avar}}_{12}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$\nto break down, where breakdown of a variance matrix estimator means that the\nlatter has a determinant close to zero or enormously large.\n\n\\subsubsection{Assumption A3: The distribution of the error terms is symmetric around zero}\n\nA condition often imposed in the literature is that the distribution of $u_i =\n(y_i-\\stvec{x}_i^t\\boldsymbol\\beta)/\\sigma$, given $\\stvec{x}_i$, is symmetric\n(Assumption~A3). If this condition is met, the regression parameter estimator\nand the estimator of residual scale are asymptotically independent, and the\ndifferent expressions simplify considerably, due to the fact that $\\stmat{a} =\n\\stvec{0}$.\n\nUnder Assumptions A1 and A3, the asymptotic variance of \n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ becomes\n\\[\n    \\mathrm{Avar}_{13}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n    = \\frac{1}{n} \\stmat{A} E(\\psi^2\\stvec{x}\\stvec{x}^t) \\stmat{A}\n    = \\frac{\\sigma^2}{n} E(\\psi'\\stvec{x}\\stvec{x}^t)^{-1}\n        E(\\psi^2\\stvec{x}\\stvec{x}^t)\n        E(\\psi'\\stvec{x}\\stvec{x}^t)^{-1}.\n\\]\n\nThe empirical counterpart of the latter expression,\n$\\sthat{\\mathrm{Avar}}_{13}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$,\nis an estimate of the asymptotic variance of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ that is robust against\nvertical outliers and bad leverage points. But it relies on symmetry of the\nerrors distribution, a quite strong assumption. A simulation study in\n\\cite{Croux:2003} shows that, even when symmetry is present, there is no gain\nin using $\\sthat{\\mathrm{Avar}}_{13}$ compared to $\\sthat{\\mathrm{Avar}}_1$:\nthe authors of \\cite{Croux:2003} then recommend to use\n$\\sthat{\\mathrm{Avar}}_1$ in any case.\n\nWhen all of Assumptions A1, A2 and A3 hold, then \n$\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho}$ has asymptotic variance\n\\[\n    \\mathrm{Avar}_{123}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})\n    = \\frac{\\sigma^2}{n} \\frac{E(\\psi^2)}{E(\\psi')^2}\n      E(\\stvec{x}\\stvec{x}^t)^{-1}.\n\\]\nThis corresponds to the expression for the variance of the \\stsc{MM} regression\nestimator that was derived in \\cite{yohai:1987}. The empirical counterpart\n$\\sthat{\\mathrm{Avar}}_{123}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$\nis an estimate of this asymptotic variance that, as\n$\\sthat{\\mathrm{Avar}}_{12}(\\sthat{\\boldsymbol\\beta}_{\\stsc{MM};\\rho_0,\\rho})$,\nlacks robustness with respect to leverage points.\n\n\\subsection{Asymptotic variance matrix of an S estimator}\n\nIf Assumption~A1 holds, the asymptotic variance matrix of \n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ is simply derived from the central\n$(p+1) \\times (p+1)$ submatrix of $\\stmat{V}_\\stsc{MM}$ (cf.\n(\\ref{eq:V_MM}), (\\ref{eq:G_MM}) and (\\ref{eq:Omega_MM})):\n\\[\n\\begin{split}\n    \\mathrm{Avar}_1(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n    & = \\frac{1}{n} \\big[ \n        \\stmat{A}_{\\stsc{S}} E[(\\rho_0')^2\\stvec{x}\\stvec{x}^t] \\stmat{A}_{\\stsc{S}}\n        - \\stmat{a}_{\\stsc{S}} E(\\rho_0\\rho_0'\\stvec{x}^t) \\stmat{A}_{\\stsc{S}}\n    \\\\\n    & \\qquad\n        - \\stmat{A}_{\\stsc{S}} E(\\rho_0\\rho_0'\\stvec{x}) \\stmat{a}_{\\stsc{S}}^t\n        + E(\\rho_0^2-\\delta^2) \\stmat{a}_{\\stsc{S}}\\stmat{a}_{\\stsc{S}}^t\n    \\big]\n\\end{split}\n\\]\nwhere\n\\[\n    \\stmat{A}_{\\stsc{S}} = \\sigma E(\\rho_0''\\stvec{x}\\stvec{x}^t)^{-1}\n    \\quad\\text{and}\\quad\n    \\stmat{a}_{\\stsc{S}} = \\stmat{A}_{\\stsc{S}}\n        \\frac{E(\\rho_0''u_0\\stvec{x})}{E(\\rho_0'u_0)}.\n\\]\nIf, in addition, Assumption~A2 holds, then the asymptotic variance matrix of\n$\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0}$ takes the form\n\\[\n\\begin{split}\n    \\mathrm{Avar}_{12}(\\sthat{\\boldsymbol\\beta}_{\\stsc{S};\\rho_0})\n    & = \\frac{\\sigma^2}{n}\\frac{E\\left[(\\rho_0')^2\\right]}\n            {E(\\rho_0'')^2} E(\\stvec{x}\\stvec{x}^t)^{-1}\n        + \\frac{\\sigma^2}{n} \\frac{E(\\rho_0''u_0)}{E(\\rho_0'')^2\n              E(\\rho_0'u_0)}\n    \\\\\n    & \\qquad\n    \\times \\left(\\frac{E(\\rho_0''u_0) E(\\rho_0^2-\\delta^2)}{E(\\rho_0'u_0)}\n        - 2 E(\\rho_0\\rho_0')\\right)\n    \\\\\n    & \\qquad\n    \\times E(\\stvec{x}\\stvec{x}^t)^{-1} E(\\stvec{x}) \n        E(\\stvec{x}^t) E(\\stvec{x}\\stvec{x}^t)^{-1}.\n\\end{split}\n\\]\nUnder Assumption~A3, the expressions are the same as those for the\n\\stsc{MM}~estimator, with $\\psi$ replaced by $\\rho_0'$.\n\n\\subsection{Asymptotic variance matrix of an M estimator}\n\nHere the expressions are less explicit. Under Assumption A1, the asymptotic\nvariance of $\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho}$ is derived from the\nupper left $(p+1) \\times (p+1)$ block of $\\stmat{G}_\\stsc{M}^{-1}\n\\boldsymbol\\Omega_\\stsc{M} (\\stmat{G}_\\stsc{M}^t)^{-1}$ where\n\\[\n    \\stmat{G}_\\stsc{M} = \n    E\\left(\\frac{\\partial\\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)}\n                {\\partial\\boldsymbol\\theta^t}\\right)\n    \\quad\\text{and}\\quad\n    \\boldsymbol\\Omega_\\stsc{M} = \n    E\\left[\\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta) \n           \\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)^t\\right]\n\\]\nwith $\\stvec{m}(y,\\stvec{x},\\boldsymbol\\theta)$ given by\n(\\ref{Eq:GMM_moment_function_M}). Defining $u =\n(y-\\stvec{x}^t\\boldsymbol\\beta)/\\sigma$, and denoting $\\rho'(u) =\n\\psi(u)$ by $\\psi$ and $\\rho_0(u)$ by $\\rho_0$, we have\n\\[\n    \\stmat{G}_\\stsc{M} = - \\frac{1}{\\sigma} E\n    \\begin{pmatrix}\n        \\psi'\\stvec{x}\\stvec{x}^t & \\psi'u\\stvec{x}\\\\\n        \\rho_0'\\stvec{x}^t        & \\rho_0'u\n    \\end{pmatrix}\n    \\quad\\text{and}\\quad\n    \\boldsymbol\\Omega_\\stsc{M} = E\n    \\begin{pmatrix}\n        \\psi^2\\stvec{x}\\stvec{x}^t & \\psi\\rho_0\\stvec{x}\\\\\n        \\psi\\rho_0\\stvec{x}^t      & \\rho_0^2-\\delta^2\n    \\end{pmatrix}.\n\\]\n\nIf in addition Assumption~A2 holds, then\n\\[\n    \\stmat{G}_\\stsc{M} = -\\frac{1}{\\sigma} \n    \\begin{pmatrix}\n        E(\\psi') E(\\stvec{x}\\stvec{x}^t) & E(\\psi'u) E(\\stvec{x}) \\\\\n        E(\\rho_0') E(\\stvec{x}^t)        & E(\\rho_0'u)\n    \\end{pmatrix}\n\\]\nand\n\\[\n    \\boldsymbol\\Omega_\\stsc{M} = \n    \\begin{pmatrix}\n        E(\\psi^2) E(\\stvec{x}\\stvec{x}^t) & E(\\psi\\rho_0) E(\\stvec{x}) \\\\\n        E(\\psi\\rho_0) E(\\stvec{x}^t)      & E(\\rho_0^2) - \\delta^2\n    \\end{pmatrix}\n\\]\nUnder Assumption~A3, the expressions of \n$\\mathrm{Avar}_{13}(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho})$ and \n$\\mathrm{Avar}_{123}(\\sthat{\\boldsymbol\\beta}_{\\stsc{M};\\rho})$ are\nexactly similar to those for the \\stsc{MM}~estimator.\n\n\n\\endinput\n", "meta": {"hexsha": "9aa0d1a5cab42fd10aff32935e60b30206f11444", "size": 171739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "stbook/chapter4.tex", "max_stars_repo_name": "benjann/robregbk", "max_stars_repo_head_hexsha": "8bda32e4ce56fc354c3f469ba52ca7163e53b43f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-25T14:21:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T14:21:56.000Z", "max_issues_repo_path": "stbook/chapter4.tex", "max_issues_repo_name": "benjann/robregbk", "max_issues_repo_head_hexsha": "8bda32e4ce56fc354c3f469ba52ca7163e53b43f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stbook/chapter4.tex", "max_forks_repo_name": "benjann/robregbk", "max_forks_repo_head_hexsha": "8bda32e4ce56fc354c3f469ba52ca7163e53b43f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-19T07:27:04.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-26T02:04:46.000Z", "avg_line_length": 48.472763195, "max_line_length": 155, "alphanum_fraction": 0.7087266142, "num_tokens": 56160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6236524144784485}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsfonts, graphicx}\n\\title{Synthesizing neural-network stabilizing controller for learned dynamics model}\n\\begin{document}\n\\section{Problem statement}\nAssume that we are given dynamics model represented as neural networks\n\\begin{align}\n\t\\text{discrete time } x[n+1] = f(x[n], u[n]) , u[n]\\in\\mathcal{U}\\\\\n\t\\text{continuous time } \\dot{x} = f(x) + G(x)u, u\\in\\mathcal{U}\n\\end{align}\nwhere $f, G$ contain neural networks which we will describe later, our goal is to synthesize a controller $u=\\pi(x)$, also represented by a neural network, and a Lyapunov function $V(x)$, represented by a third neural network, such that we can prove that the closed-loop system is Lyapunov stable. Namely we want to find a controller, such that the closed loop system is Lyapunov exponentially (or asymptotically) stable within a set $\\mathcal{S}$, i.e., for the equilibrium state/control $x^*, u^*$, all the states start within $\\mathcal{S}$ would eventually converge to equilibrium state.\n\nWe assume the set of admissible inputs $\\mathcal{U}$ is a box in the input space, namely we have input bounds $u_{min}(i)\\leq u(i)\\leq u_{max}(i)$ for each dimension of the input.\n\nNotice that we assume the continuous-time system is control affine. We will exploit this property later.\n\n\\section{Approach}\nWe consider the discrete-time and continuous-time system separately. Let's first consider the discrete-time case. In this project, all the neural networks are feed-forward neural network with leaky Relu units, hence the output of the network is a piecewise affine function of the input.\n\\subsection{Discrete time system}\nFirst we assume that our forward dynamical system is represented by a neural network\n\\begin{align}\n\tx[n+1] = \\phi_{dyn}(x[n], u[n]) - \\phi_{dyn}(x^*, u^*) + x^* \\label{eq:discrete_forward_dyn}\n\\end{align}\nwhere $\\phi_{dyn}$ is a feed-forward neural network with (leaky) ReLU activation units. Notice that by construction \\eqref{eq:discrete_forward_dyn} guarantees that with $x[n]=x^*, u[n]=u^*$ the next state is still the equilibrium state $x^*$. This neural network $\\phi_{dyn}$ is given and fixed.\n\nThe Lyapunov function for exponetial stability is\n\\begin{subequations}\n\\begin{align}\n\tV(x) > 0 \\;\\forall x\\neq x^*, V(x^*) = 0\\\\\n\tV(x[n+1]) - V(x[n]) \\le -\\epsilon_2 V(x[n])\\\\\n\tx \\rightarrow \\infty \\Rightarrow V(x)\\rightarrow \\infty\n\\end{align}\n\\end{subequations}\n \nSince we will certify the Lyapunov condition through MILP, which cannot handle strict inequality constraint $V(x) > 0$, we consider the following necessary and sufficient condition\n\\begin{subequations}\n\\begin{align}\n\tV(x) \\ge \\epsilon_1 |R(x-x^*)|_1\\\\\n\tV(x[n+1]) - V(x[n]) \\le -\\epsilon_2V(x[n])\n\\end{align}\n\\label{eq:lyapunov_discrete}\n\\end{subequations}\nwhere $R$ is a matrix with full column rank, $|R(x-x^*)|_1$ is the 1-norm of the vector $R(x-x^*)$.\n\nWe design our Lyapunov function as\n\\begin{align}\n\tV(x) = \\phi_{V, \\theta}(x) -\\phi_{V, \\theta}(x^*) + \\lambda|R(x-x^*)|_1 \\label{eq:lyapunov}\n\\end{align}\nwhere $\\phi_{V, \\theta}$ is a feedforward neural network with (leaky) ReLU activation functions. $\\lambda$ is a given positive constant (with $\\lambda > \\epsilon_1$). The reason to add the term  $\\lambda|R(x-x^*)|_1$ to the Lyapunov function \\eqref{eq:lyapunov}, is that it is very hard for the neural network $\\phi_{V, \\theta}$ to attain its minimum at $x^*$ (Since the neural network $\\phi_{V, \\theta}$ is a piecewise affine function of $x$. If it were to attain minimal at $x^*$, it implies that $x^*$ is the common vertex of all the neighbouring linear pieces, which is almost impossible to satisfy by gradient descent approach. See fig. \\ref{fig:lyapunov_add_l1_3} as a visual explanation.) By adding the function $\\lambda|R(x-x^*)|_1$ which has its global minimal at $x^*$, it is much easier to make the Lyapunov function to attain global minimal at $x^*$. Also by construction of \\eqref{eq:lyapunov} we have $V(x^*) = 0$.\n\\begin{figure}\n\t\\includegraphics[width=0.8\\textwidth]{/home/hongkaidai/Dropbox/talks/pictures/neural_network_controller/lyapunov_add_l1_3.pdf}\n\t\\caption{Adding the term $\\lambda |x-x^*|_1$ helps the neural network to attain (local) minimal at $x^*$.}\n\t\\label{fig:lyapunov_add_l1_3}\n\\end{figure}\n\nOur controller is also represented by a neural network as\n\\begin{align}\n\tu[n] = saturate(\\phi_{u, \\eta}(x[n]) - \\phi_{u, \\eta}(x^*) + u^*)\\label{eq:controller}\n\\end{align}\nwhere $\\phi_{u, \\eta}$ is a feedforward neural network with (leaky) ReLU activation functions. The weights/biases of this network is denoted by $\\eta$. $saturate$ is the saturation function that clamp the control within the input limits. Again by construction of \\eqref{eq:controller}, the control action at the equilibrium state $x^*$ is $u^*$.\n\nWe could solve the following two optimization problem as MILP\n\\begin{align}\n\t\\max_{x} \\epsilon_1|R(x-x^*)|_1 - V(x)\\\\\n\t\\max_{x[n]} V(x[n+1]) - V(x[n]) + \\epsilon_2V(x[n])\n\\end{align}\nWhen the maximal cost of either the function is larger than 0, we find a counter example that violates the Lyapunov condition \\eqref{eq:lyapunov_discrete}. Our goal is to find the neural network for controller and Lyapunov function, such that the violation is 0. Namely we solve the following min-max problem.\n\\begin{align}\n\t\\min_{\\theta, \\eta, R} \\left(\\max_{x}\\epsilon_1|R(x-x^*)|_1 - V(x) + \\max_{x[n]} V(x[n+1]) - V(x[n]) + \\epsilon_2V(x[n])\\right)\n\\end{align}\nAfter solving the inner maximization problem, we then compute the gradient of the maximal cost w.r.t $\\theta, \\eta, R$, and then use gradient descent to minimize the loss.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Continuous-time system}\nWe assume that the continuous time system forward dynamics is\n\\begin{align}\n\t\\dot{x} = f(x) + G(x)u\n\\end{align}\nWithout loss of generality we can assume that the bounds on the control input $u$ is \n\\begin{align}\n\t-\\mathbf{1}\\le u \\le \\mathbf{1}\n\\end{align}\n\nDue to the control-affine property of the continuous-time system, we will show that we can search for a control Lyapunov function, instead of a controller and a Lyapunov function as in the discrete-time case. The control Lyapunov function satisfies\n\\begin{subequations}\n\\begin{align}\n\tV(x) \\ge \\epsilon_1|R(x-x^*)|_1\\\\\n\t\\min_{-\\mathbf{1}\\le u\\le \\mathbf{1}} \\dot{V}\\le -\\epsilon_2V(x)\\label{eq:lyapunov_condition_Vdot_continuous}\n\\end{align}\n\\label{eq:lyapunov_condition_continuous}\n\\end{subequations}\n\nNote that the left-hand side of the condition \\eqref{eq:lyapunov_condition_Vdot_continuous} can be rewritten as\n\\begin{subequations}\n\\begin{align}\n\t&\\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\dot{V}\\\\\n\t=&\\min_{-\\mathbf{1}\\le u \\le\\mathbf{1}}\\frac{\\partial V}{\\partial x}(f(x) + G(x)u)\\\\\n\t=&\\frac{\\partial V}{\\partial x}f(x) + \\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\frac{\\partial V}{\\partial x}G(x)u\\label{eq:control_lyapunov3}\\\\\n\t=&\\frac{\\partial V}{\\partial x}f(x) - \\left|\\frac{\\partial V}{\\partial x}G(x)\\right|_1\\label{eq:control_lyapunov4}\n\\end{align}\n\\end{subequations}\nFrom \\eqref{eq:control_lyapunov3} to \\eqref{eq:control_lyapunov4} we use the fact that $\\min_{|x|_{\\infty}\\le 1} a^Tx = -|a|_1$, namely 1-norm is the \\textit{dual norm} of $\\infty$-norm.\n\nWe represent the control-Lyapunov function through a neural network as\n\\begin{align}\n\tV(x) = \\phi_{V, \\theta}(x) - \\phi_{V, \\theta}(x^*) + \\lambda|R(x-x^*)|_1\n\\end{align}\n\nAnd we solve the following two MILPs to either certify the control-Lyapunov condition, or find the counter-examples.\n\\begin{align}\n\t\\max_{x} \\epsilon_1|R(x-x^*)|_1 - V(x)\\\\\n\t\\max_{x} \\underbrace{\\frac{\\partial V}{\\partial x}f(x) - \\left|\\frac{\\partial V}{\\partial x}G(x)\\right|_1}_{\\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\dot{V}} + \\epsilon_2V(x)\n\\end{align}\n\nWe then compute the gradient of each MILP cost w.r.t $\\theta, R$, and then use gradient descent on $\\theta, R$ to minimize the loss.\n\n\\subsubsection{subgradient in control Lyapunov function}\nOne tricky thing is that when we compute $\\dot{V}$ in the control Lyapunov function, it requires the gradient $\\frac{\\partial V}{\\partial x}$. But as we use the (leaky) ReLU unit (and $l_1$ norm), the Lyapunov function $V$ is not differentiable everywhere. Specifically both the leaky ReLU unit and the $l_1$ norm function have kinks at input equal to 0. Hence we will need to think about the subgradient of the Lyapunov function. We denote the set of subgradient at $x$ as $\\mathcal{D}_V(x)$.\n\nOur goal is that for each state, there exists a control action $u$, such that $\\dot{V} < 0$ for all subgradient. Namely\n\\begin{align}\n\t\\max_x \\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\max_{d\\in\\mathcal{D}_V(x)} d^T(f(x) + G(x)u) < 0\\label{eq:max_min_max_subgradient}\n\\end{align}\nThis max-min-max problem is really hard. The problem would be a lot easier if we could switch the inner minimization and maximization, such that we end up with the following max-min problem\n\\begin{align}\n\t\\max_{x, d\\in\\mathcal{D}_V(x)} \\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} d^T(f(x)+G(x)u) < 0 \\label{eq:max_min_subgradient}\n\\end{align}\nwhich we know is equivalent to the following condition with only maximization.\n\\begin{align}\n\t\\max_{x, d\\in\\mathcal{D}_V(x)}d^Tf(x) - |d^TG(x)|_1 < 0 \\label{eq:max_subgradient}\n\\end{align}\nSo the question is, what is the condition such that we can switch the inner minimization and maximization from \\eqref{eq:max_min_max_subgradient} to \\eqref{eq:max_min_subgradient}?\n\nFrom \\textit{mini-max} theorem we know that if the set of subgradient $\\mathcal{D}_V(x)$ is a convex compact set, then we can switch the order of the min-max. We will next describe some conditions such that the subgradient set $\\mathcal{D}_V(x)$ is a convex compact set.\n\nNote that\n\\begin{align}\n\tV(x) = \\phi_V(x) - \\phi_V(x^*) + \\lambda |R(x-x^*)|_1\n\\end{align}\nHence the subgradient set $\\mathcal{D}_V(x)$ can be written as the Minkowski sum $\\mathcal{D}_\\phi(x) \\oplus \\mathcal{D}_l(x)$, where $\\mathcal{D}_\\phi(x)$ is the set of subgradient for the neural-network $\\phi_V(x)$, and $\\mathcal{D}_l(x)$ is the set of subgradient for the $l_1$ norm function $l(x) = \\lambda |R(x-x^*)|_1$. Let's first analyze the subgradient for the $l_1$ norm function. The set $\\mathcal{D}_l(x)$ can be described as\n\\begin{align}\n\t\\mathcal{D}_l(x) = \\{\\lambda y^TR\\}\n\\end{align}\nwhere the i'th entry of $y$ has the following form\n\\begin{align}\n\ty(i)\\begin{cases}\n\t\t= 1 & \\text{ if } e_i^TR(x - x^*) > 0\\\\\n\t\t= -1 & \\text{ if }e_i^TR(x - x^*) < 0\\\\\n\t\t\\in [-1, 1] &\\text { if } e_i^TR(x - x^*) = 0\n\t\\end{cases}\n\\end{align}\nHence for a fixed $x$, the set $\\mathcal{Y} = \\{y\\}$ is a convex compact set. As a result, $\\mathcal{D}_l(x)$, which is a linear transformation of $\\mathcal{Y}$, also becomes a convex compact set.\n\nSimilarly if we consider the ReLU network. The set of subgradient for each individual ReLU unit is also a convex set. Hence if only one layer of neurons has non-unique subgradient, while all other layers have unique gradient, then the set of subgradient $\\mathcal{D}_V(x)$ for the entire neural network is also a convex compact set.\n\nTo summarize, a sufficient condition for the subgradient set $\\mathcal{D}_V(x)$ to be convex and compact, is that for the given state $x$, the (leaky) ReLU units with input being 0 are all in the same layer of the neural network.\n\n\\subsubsection{Computing subgradient}\nWe use the $l_1$ norm function $|R(x-x^*)|_1$ to denote how to use the subgradient. We will have the terms $\\frac{\\partial |R(x-x^*)|_1}{\\partial x}f(x)$ and $\\frac{\\partial |R(x-x^*)|_1}{\\partial x}G(x)$ when computing $\\dot{V}$. If we denote a valid subgradient as $g$, then these two terms are written as $g^TRf, g^TRG$, where the value of $g$ is\n\\begin{align}\n\tg_i  \\begin{cases}\n\t\t=1 \\text{ if } R[i, :](x-x^*) > 0\\\\\n\t\t=-1 \\text{ if } R[i, :](x-x^*) < 0\\\\\n\t\t\\in[-1, 1] \\text{ if } R[i, :](x-x^*)=0\n\t\\end{cases}\n\\end{align}\nNotice that when the gradient is unique, then we only need to consider the discrete value $\\pm1$ multiplying the continuous value $Rf, RG$, and this product can be captured by mixed-integer linear constraints. But when we have subgradient, then we need to consider the continuous variable in the range $[-1, 1]$ multiplying continuous value $Rf, RG$. This product between continuous variables can't be captured by mixed-integer linear constraints.\n\nWe propose two approaches to remedy this\n\\subsubsection{sampled subgradient}\nIn the first approach, we only consider a finite number of sampled subgradients. For example if we only consider the sub-gradient $-1, 0, 1$, then we can write the subgradient as\n\\begin{align}\n\tg_i = \\beta_0*-1+\\beta_1 * 0 + \\beta_2 * 1, \\beta_i \\text{ is binary}, \\beta_0 + \\beta_1 + \\beta_2 = 1 \\text{ if } R[i, :] (x-x^*)=0\n\\end{align}\n\\subsubsection{all subgradients}\nIn the second approach, we do consider all subgradients. The key thing is to note that when the subgradient $g_i \\in [-1, 1]$,  the term $g_i z$ can be replaced by a new term $t$ with the constraint $-|z| \\le t \\le |z|$ if $z$ is a scalar. It is very important to aggregate anything that multiplies $g_i$ to a single slack variable $z$ when we use this trick.\n\nWe will have the term $g^TRf - |g^TRG|_1$. We denote $\\bar{f}=Rf, \\bar{G}=RG$\n\\begin{align}\n\tg^TRf - |g^TRG|_1 = g^T\\bar{f} - |g^T\\bar{G}|_1\\\\\n\t= \\sum_{i=1}^{n_x} g_i \\bar{f}_i - \\sum_{j=1}^{n_u}|\\sum_{i=1}^{n_x}g_i \\bar{G}_{ij}|\n\\end{align}\n\n\\section{Control barrier function}\nWe aim at finding a control barrier function $h(x)$ satisfying\n\\begin{align}\n\t\\forall x\\;\\sup_{-\\mathbf{1}\\le u\\le\\mathbf{1}} \\frac{\\partial h}{\\partial x}(f(x) + G(x)u) \\ge -\\epsilon h(x)\n\\end{align}\nwith $\\epsilon > 0$ a small positive constant. This control barrier function certifies that the superlevel set $\\{x | h(x) \\ge 0\\}$ is an invariant set.\n\nWe suppose $x^*$ is a safe state, and the set of unsafe state is denoted as $\\mathcal{C}_u$. Then if $h(x)$ satisfies\n\\begin{subequations}\n\\begin{align}\n\th(x^*) > 0\\\\\n\th(x) < 0 \\forall x\\in\\mathcal{C}_u\\\\\n\t\\forall x\\;\\sup_{-\\mathbf{1}\\le u\\le\\mathbf{1}} \\frac{\\partial h}{\\partial x}(f(x) + G(x)u) \\ge -\\epsilon h(x)\n\\end{align}\n\\end{subequations}\nThen we certify that there exists a safe set $\\mathcal{C}$ as the super-level set of $h(x)$, $x^*\\in\\mathcal{C}$ and $\\mathcal{C} \\cup \\mathcal{C}_u=\\emptyset$.\n\nWe design our control barrier function as\n\\begin{align}\n\th(x) = \\phi_h(x) - \\phi_h(x^*) + 1\n\\end{align}\nwhich trivially satisfies the condition $h(x^*) > 0$.\n\nBy formulating the verification as MILP, we only verify the barrier function condition on a bounded set of state $\\mathcal{B}$. To ensure that the invariant safe set is contained within the verified region $\\mathcal{B}$, we need to add another condition\n\\begin{align}\n\th(x) < 0 \\forall x \\in \\partial\\mathcal{B}\n\\end{align}\nThis condition can also be checked through an MILP.\n\n\\end{document}\n", "meta": {"hexsha": "a312fa1bb1fb0f74e3c4be08d9d0a358b6c85960", "size": 14775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/stabilizing_controller.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": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/stabilizing_controller.tex", "max_issues_repo_name": "hongkai-dai/neural-network-lyapunov-1", "max_issues_repo_head_hexsha": "8843c13f69f7f39cbb939ab250413e76f61843f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-21T22:54:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-28T19:39:25.000Z", "max_forks_repo_path": "doc/stabilizing_controller.tex", "max_forks_repo_name": "hongkai-dai/neural-network-lyapunov-1", "max_forks_repo_head_hexsha": "8843c13f69f7f39cbb939ab250413e76f61843f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-30T23:45:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-30T23:45:43.000Z", "avg_line_length": 69.0420560748, "max_line_length": 928, "alphanum_fraction": 0.7129610829, "num_tokens": 4758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6236524010883903}}
{"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 \\#1}}\n\\author{@all.about.mathematics}\n\n\\begin{document}\n\\large\n\\maketitle\n\\pagecolor{black}\n\\section{Problem}\nEvaluate the integral \n$$\\int_{0}^{\\infty}\\frac{1}{{\\sqrt[\\leftroot{-1}\\uproot{1}4]{x}}\\:(1+x^3)}dx$$\n\\newpage\n\\section{Solution}\nConsider the generalized integral where $\\frac m n \\not \\in \\mathbb{Z}$\n$$I(m,n)=\\int_{0}^{\\infty}\\frac{x^{m-1}}{1+x^n}dx$$\nTherefore our desired integral is $I(\\frac{3}{4},3)$. Let\n$$u=\\frac{1}{1+x^n}\\implies x=\\left(\\frac{1-u}{u}\\right)^\\frac{1}{n}\\implies dx=-\\left(\\dfrac{1-u}{u}\\right)^{\\large\\frac1n-1}\\ \\dfrac{du}{nu^2}$$\nBesides, $x=\\infty\\implies u=0$ and $x=0\\implies u=1$. Therefore,\n$$I(m,n)=\\int_{1}^{0}\\left({\\left(\\frac{1-u}{u}\\right)^\\frac{1}{n}}\\right)^{m-1}\\left(-u\\left(\\dfrac{1-u}{u}\\right)^{\\large\\frac1n-1}\\right) \\dfrac{du}{nu^2}$$\n\\begin{equation}\n=\\frac1n \\int_{0}^{1}u{\\left(\\frac{1-u}{u}\\right)^{\\frac{m}{n}-1}}{du}=\\frac1n\\int_0^1u^{1-\\frac{m}{n}-1}(1-u)^{\\frac{m}{n}-1} du\n\\end{equation}\nRecall the definition of the Beta function and its special property\n$$\\text{B}(a,b)=\\int_0^1t^{a-1}(1-t)^{b-1} dt=\\frac{\\Gamma(a)\\cdot\\Gamma(b)}{\\Gamma(a+b)}$$\nHence the last integral in $(1)$ becomes\n\\begin{equation}\n\\frac{ B\\left(1-\\frac mn , \\frac m n\\right)}{n}= \\frac 1 n \\frac{\\Gamma(1-\\frac mn)\\cdot\\Gamma(\\frac m n)}{\\Gamma(1-\\frac mn + \\frac m n)} = \\frac 1 n\\: \\Gamma\\left(1-\\frac mn\\right)\\cdot\\Gamma\\left(\\frac m n\\right) \n\\end{equation}\nRecall the Euler's reflection formula \n$$\\Gamma(z)\\cdot\\Gamma(1-z)=\\frac{\\pi}{\\sin(\\pi z)}\\:\\:\\:\\:\\: z\\not\\in\\mathbb{Z}$$\nGiven that $\\frac m n \\not\\in \\mathbb{Z}$, we use the Euler's reflection formula for $(2)$\n$$I(m,n)= \\frac{\\pi}{n \\sin(\\frac {m\\pi}{n} )}$$\nTherefore, our desired integral \n$$I\\left(\\frac{3}{4},3\\right)= \\frac{\\pi}{3 \\sin \\left(\\frac {\\frac 3 4\\pi}{3}\\right)}= \\frac{\\sqrt{2}\\pi}{3}$$\n\\newpage\n\\section{Method 2}\n\n\\end{document}", "meta": {"hexsha": "3a89ea48b95107c34481d59b3369a43f639cce07", "size": 2357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/all.about.mathematics' questions/Calculus 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": "Calculus/all.about.mathematics' questions/Calculus 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": "Calculus/all.about.mathematics' questions/Calculus 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": 43.6481481481, "max_line_length": 216, "alphanum_fraction": 0.6610097582, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.623652399414633}}
{"text": "\\lab{Iterative Solvers}{Iterative Solvers}\n\\label{lab:iter_methods}\n\n\\objective{In this lab, we will talk about the benefits to using iterative solvers\nand also implement three popular algorithms: 1) Jacobi, 2) Gauss-Seidel, 3)\n Successive Over-Relaxation.}\n\nIn introductory linear algebra classes, we solve linear systems of the form\n$A\\mathbf{x} = \\mathbf{b}$ by using the inverse, $\\mathbf{x} = A^{-1}\\mathbf{b}$.\nWhile this is a simple analytic solution, computing $A^{-1}$ is expensive for\nlarge systems.\nIn linear algebra classes, we solve linear systems that are no bigger than 4 or 5\ndimensions. However in real-world applications, linear systems can sometimes have\ntens of thousands of parameters. We will present such a problem in\nProblem \\ref{prob:application}.\n\nWith problems of this size, it is no longer feasible to calculate the inverse of\na matrix. Calculating the inverse of a matrix is a $O(n^3)$ problem.\nThat means it requires somewhere on the order\nof 1 trillion floating point operations (FLOPS) to calculate the inverse of a\n$10000 \\times 10000$ matrix. Performing such a large number of operations also\nintroduces a high probability of accumulating floating point errors. For these\nreasons, large linear systems are never solved directly.\n\nLuckily, additional methods have been developed to solve systems of this size.\nThough finding an exact solution is either very time intensive or unstable,\niterative methods can give us sufficiently close approximations while taking\nmuch less time.\n% TODO talk about LU-decomposition a bit and why we don't want to use it in this case.\n\n\\section*{Iterative Methods} % ================================================\n\n% TODO use some of the description from V1 Krylov section.\nThe general idea behind any iterative method is make an initial guess, apply some\neasy computations to give you a better approximate answer,\nand repeat this process until convergence.\n\nIn this lab, we will discuss three different methods used to solve large linear\nsystems of equations. These are the Jacobi Method, the Gauss-Seidel method, and\nSuccessive Over-Relaxation.\n\n\\section*{The Jacobi Method} % ================================================\n\nTo explain the Jacobi Method, we will examine a $ 3 \\times 3 $ system.\n$$\n\\begin{matrix}\n2x_1 &   &      & - & x_3  & = & 3 \\\\\n-x_1 & + & 3x_2 & + & 2x_3 & = & 3 \\\\\n     & + & x_2  & + & 3x_3 & = & -1 \\\\\n\\end{matrix}\n$$\n\n\\begin{comment}\n$$\n\\begin{matrix}\na_{11}x_1 + a_{12}x_2 + a_{13}x_3 = b_1 \\\\\na_{21}x_1 + a_{22}x_2 + a_{23}x_3 = b_2 \\\\\na_{31}x_1 + a_{32}x_2 + a_{33}x_3 = b_3 \\\\\n\\end{matrix}\n$$\n\\end{comment}\n\nTo complete the first iteration of Jacobi Method, we begin with an initial guess\n$(x^{(0)}_1, x^{(0)}_2, x^{(0)}_3) = (0,0,0)$. Throughout this lab, we will use\n the notation $x^{(k)}_i$ to denote the $k^{th}$ iteration of the algorithm and\n the $i^{th}$ element of $\\mathbf{x}$.\n\nWe then compute the next approximation $(x^{(1)}_1, x^{(1)}_2, x^{(1)}_3)$.\nFor the first step, we take each of the three equations and solve for $x_1$,\n$x_2$, and $x_3$, respectively. This gives us the following.\n\n$$\n\\begin{matrix}\nx_1 & = & \\frac{1}{2} ( 3 + x_3) \\\\\nx_2 & = & \\frac{1}{3} ( 3 + x_1 - 2x_3) \\\\\nx_3 & = & \\frac{1}{3} ( -1 - x_2) \\\\\n\\end{matrix}\n$$\nWe then use these equations for our approximation of $(x^{(1)}_1, x^{(1)}_2, x^{(1)}_3)$.\n\n$$\n\\begin{matrix}\nx^{(1)}_1 & = & \\frac{1}{2} ( 3 + x^{(0)}_3)  & = & \\frac{1}{2} (3 + 0)     & = & \\frac{3}{2} \\\\\nx^{(1)}_2 & = & \\frac{1}{3} ( 3 + x^{(0)}_1 - 2x^{(0)}_3) & = & \\frac{1}{3} (3 + 0 - 0) & = & 1 \\\\\nx^{(1)}_3 & = & \\frac{1}{3} ( -1 - x^{(0)}_2)       & = & \\frac{1}{3} (-1 - 0)    & = & -\\frac{1}{3} \\\\\n\\end{matrix}\n$$\nSo $\\mathbf{x}^{(1)} = (\\frac{3}{2}, 1, -\\frac{1}{3})$. This concludes one iteration of\nthe Jacobi method. Computing $\\mathbf{x}^{(2)}$ follows similarly.\n\n$$\n\\begin{matrix}\nx^{(2)}_1 & = & \\frac{1}{2} ( 3 + x^{(1)}_3)  & = & \\frac{1}{2} (3 - \\frac{1}{3})     & = & \\frac{4}{3} \\\\\nx^{(2)}_2 & = & \\frac{1}{3} ( 3 + x^{(1)}_1 - 2x^{(1)}_3) & = & \\frac{1}{3} (3 + \\frac{3}{2} + \\frac{2}{3}) & = &  \\frac{31}{18} \\\\\nx^{(2)}_3 & = & \\frac{1}{3} ( -1 - x^{(1)}_2)       & = & \\frac{1}{3} (-1 - 1)    & = & -\\frac{2}{3} \\\\\n\\end{matrix}\n$$\n\n\n\\begin{comment}\n$$\n\\begin{matrix}\nx^{(1)}_1 = ( b_1 - a_{12}x^{(0)}_2 - a_{13}x^{(0)}_3) / a_{11} \\\\\nx^{(1)}_2 = ( b_1 - a_{21}x^{(0)}_1 - a_{23}x^{(0)}_3) / a_{22} \\\\\nx^{(1)}_3 = ( b_1 - a_{31}x^{(0)}_1 - a_{32}x^{(0)}_2) / a_{33} \\\\\n\\end{matrix}\n$$\n\\end{comment}\n\nTo find $\\mathbf{x}^{(k)}$, we repeat the same process of solving for each\n$x^{(k)}_i$ until convergence is reached. For this particular problem,\nconvergence to 8 decimal places is reached in 29 iterations.\n\n\\begin{center}\n\\begin{tabular}{ c|c c c  }\n          & $x^{(k)}_1$ & $x^{(k)}_2$ & $x^{(k)}_3$ \\\\\n    \\hline\n    $x^{(0)}$ & 0 & 0 & 0 \\\\\n    %\\hline\n    $x^{(1)}$ & 1.5 & 1 & -0.33333 \\\\\n    %\\hline\n    $x^{(2)}$ & 1.33333333 & 1.72222222 & -0.66666667 \\\\\n    $x^{(3)}$ & 1.16666667 & 1.88888889 & -0.90740741 \\\\\n    $x^{(4)}$ & 1.0462963 & 1.99382716 & -0.96296296 \\\\\n    \\vdots    & \\vdots    & \\vdots     & \\vdots     \\\\\n    $x^{(28)}$ & 0.99999999 & 2.00000001 & -0.99999999 \\\\\n    $x^{(29)}$ & 1 & 2 & -1 \\\\\n\\end{tabular}\n\\end{center}\n\n\n\\subsection*{Matrix Representation of Jacobi Method} % ------------------------\n\nThough it may not be immediately obvious, the iterative steps performed above\ncan be expressed in matrix form. First, we use the fact that\n$A = D + L + U$ where,\n\n$$\nD = \\begin{bmatrix}\na_{11} & 0 & \\ldots & 0 \\\\\n0 & a_{22} & \\ldots & 0 \\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\n0 & 0 & \\ldots & a_{nn} \\\\\n\\end{bmatrix}\n$$\n$$\nL = \\begin{bmatrix}\n0 & 0 & \\ldots & 0 \\\\\na_{21} &  0 & \\ldots & 0\\\\\n \\vdots & \\ddots & \\ddots & \\vdots \\\\\na_{n1} & \\ldots & a_{n,n-1} & 0 \\\\\n\\end{bmatrix}\n$$\n$$\nU = \\begin{bmatrix}\n0 & a_{12} & \\ldots & a_{1n} \\\\\n0 & 0 & \\ddots & \\vdots \\\\\n \\vdots & \\vdots & \\ddots & a_{n-1,n} \\\\\n0 & 0 & \\ldots & 0 \\\\\n\\end{bmatrix}.\n$$\n\nNow we can make substitutions to get,\n$$ A\\mathbf{x} = \\mathbf{b} $$\n$$ (D + L + U)\\mathbf{x} = \\mathbf{b} $$\n$$ D\\mathbf{x} = \\mathbf{b} - (L+U)\\mathbf{x} $$\n$$ \\mathbf{x} = D^{-1}\\mathbf{b} - D^{-1}(L+U)\\mathbf{x} $$\n\nWith this, we can express our algorithm for iteratively updating $\\mathbf{x}$ as,\n\n\\begin{equation} \\label{eq:trad_jacobi}\n\\mathbf{x}^{(k+1)} = D^{-1}b - D^{-1}(L+U)\\mathbf{x}^{(k)}\n\\end{equation}\n\nAt this point, notice that we have $D^{-1}$ in Equation \\ref{eq:trad_jacobi}. However, in\nthis case, it is okay that we are calculating an inverse. Since $D$ is a diagonal\nmatrix, $D^{-1}$ is very easy to compute. It is easily verifiable that $D^{-1}$\nis just,\n\n$$\n\\begin{bmatrix}\n\\frac{1}{a_{11}} & 0 & \\ldots & 0 \\\\\n0 & \\frac{1}{a_{22}} & \\ldots & 0 \\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\\n0 & 0 & \\ldots & \\frac{1}{a_{nn}} \\\\\n\\end{bmatrix}.\n$$\n\nIt is common to see the matrix representation of the Jacobi Method as expressed in\nEquation \\ref{eq:trad_jacobi}.\nHowever, we can manipulate this equation slightly to make it easier to compute\nin Python. Since $A = D + L + U$,\n\n$$\\mathbf{x}^{(k+1)} = D^{-1}b - D^{-1}(A-D)\\mathbf{x}^{(k)} $$\n\n\\begin{equation} \\label{eq:jacobi}\n    \\mathbf{x}^{(k+1)} = D^{-1}(b - (A-D)\\mathbf{x}^{(k)})\n\\end{equation}\n\nNotice that for this algorithm to\nwork, the matrix $A$ must have nonzero diagonal entries. Additionally, with the\nhelp of array broadcasting we can make a few other adjustments that make it even\nmore efficient. Note that this algorithm will not always converge. We will talk\nmore about the requirements for convergence in the next section.\n\n\\begin{problem} % Implement the Jacobi Method.\nUsing Equation \\ref{eq:jacobi}, implement the Jacobi Method. Avoid using\n\\li{la.inv}. Your function should accept a matrix \\li{A}, a vector \\li{b}, and\nan optional parameter \\li{tol} with a default value of \\li{1e-8}. Additionally,\naccept an optional parameter \\li{maxiters} to help you catch nonconvergent\nsystems. Set \\li{maxiters} to $100$ as default. Your function should return the\nsolution vector \\li{x} as well as a list of all the approximations of \\li{x}\nat each iteration. Stop iterating when \\li{maxiters} is reached or\n$||\\mathbf{x}^{(k)} - \\mathbf{x}^{(k+1)}||_{\\infty} < $ \\li{tol}. In Python, you\ncan calculate $||x||_{\\infty}$ in two ways.\n\\begin{lstlisting}\n>>> la.norm(x, ord=np.inf)\n<<or>>\n>>> np.max(np.abs(x))\n\\end{lstlisting}\nFor more information about the $\\infty$-norm see Chapter ?? of Volume 1.\n\nIf \\li{maxiters} is hit, return the current solution. Your function should flexible enought\nto be able to handle systems of any size. If your\nsystem is non-convergent, you will find that your approximations have increasingly\nlarge entries. Test your function on the $3 \\times 3$ linear system above. Then\ntest your function on a random $3 \\times 3$ matrix. Chances are the random matrix\nyou generate will not converge, i.e. \\li{maxiters} will be hit.\nWe will discuss why in the next section.\n\n\\begin{info}\nRemember that NumPy arrays are mutable. Therefore, to check convergence, you\nwill need to have two copies of the array you are testing,\ni.e. a ``before'' version and an ``after'' version.\n\\end{info}\n\\label{prob:jacobi}\n\\end{problem}\n\n\\subsection*{Convergence of the Jacobi Method} % ------------------------------\n\n\\begin{definition}\n    A matrix $A \\in M_n(\\mathbb{R})$ is \\emph{strictly diagonally dominant} if\n    $|a_{ii}| > \\sum_{j \\neq i} |a_{ij}|$ for all $i = 1,2,\\hdots,n$.\n\\end{definition}\n\n\\begin{theorem}\nThe Jacobi method converges for a matrix $A$ if it is strictly diagonally\ndominant.\n\\end{theorem}\n\nAlthough this seems like a strong requirement, most real-world linear systems\nare represented by strictly diagonally dominant matrices.\nWe will discuss a class of problems that satisfy this condition at the end of\nthis lab.\n\n\\begin{problem}\nTo visualize the speed of convergence of the Jacobi method, plot the error at each\niteration. Use the list of approximations that you returned in Problem \\ref{prob:jacobi}\nto calculate the errors. The error can be computed by calculating\n$||A\\mathbf{x}^{(k)} - \\mathbf{b}||$\nfor each approximation, $x^{(k)}$. Your plot should be similar to the figure below.\nTo plot with a logrithmic scale on the $y$-axis, run \\li{plt.semilogy()}.\n\\end{problem}\n\n\\begin{figure} \\label{fig:jacobi_convergence}\n\\includegraphics[width=.7\\textwidth]{jacobi_convergence.pdf}\n\\label{fig:jacobi_convergence}\n\\end{figure}\n\n\\section*{The Gauss-Seidel Method} % ==========================================\n\nThe Gauss-Seidel Method is quite similar to the Jacobi Method. We will examine\nthe same system as before. The main difference between Gauss-Seidel and Jacobi\nis that in Gauss-Seidel, any new information is used immediately. As with Jacobi,\n\n$$\n\\begin{matrix}\nx^{(1)}_1 & = & \\frac{1}{2} ( 3 + x^{(0)}_3)  & = & \\frac{1}{2} (3 + 0)     & = & \\frac{3}{2} \\\\\n\\end{matrix}\n$$\n\nBut now, we use this updated value of $x^{(1)}_1$ in our calculation of\n$x^{(1)}_2$ as follows\n$$\n\\begin{matrix}\nx^{(1)}_2 & = & \\frac{1}{3} ( 3 + x^{(1)}_1 - 2x^{(0)}_3) & = & \\frac{1}{3} (3 + \\frac{3}{2} - 0) & = & \\frac{3}{2} \\\\\n\\end{matrix}\n$$\n\nWe now can use the updated values of $x^{(1)}_1$ and $x^{(1)}_2$ in our\ncalculation of $x^{(1)}_3$,\n$$\n\\begin{matrix}\nx^{(1)}_3 & = & \\frac{1}{3} ( -1 - x^{(1)}_2)       & = & \\frac{1}{3} (-1 - \\frac{3}{2})    & = & -\\frac{5}{6}\n\\end{matrix}.\n$$\n\nThis process of using what we have calculated immediately is called\n\\emph{forward substitution}. Using forward substitution causes the algorithm to\nconverge much faster.\n\n\\begin{center}\n    \\begin{tabular} {c | c c c}\n        & $x^{(k)}_1$ & $x^{(k)}_2$ & $x^{(k)}_3$ \\\\\n        \\hline\n          $x^{(0)}$ & 0 & 0 & 0 \\\\\n          %\\hline\n          $x^{(1)}$ & 1.5 & 1.5 & -0.833333 \\\\\n          %\\hline\n          $x^{(2)}$ & 1.08333333 & 1.91666667 & -0.97222222 \\\\\n          $x^{(3)}$ & 1.01388889 & 1.98611111 & -0.99537037 \\\\\n          $x^{(4)}$ & 1.00231481 & 1.99768519 & -0.9992284 \\\\\n          \\vdots    & \\vdots    & \\vdots     & \\vdots     \\\\\n          $x^{(11)}$ & 1.00000001 & 1.99999999 & -1 \\\\\n          $x^{(12)}$ & 1 & 2 & -1 \\\\\n        \\end{tabular}\n\\end{center}\nNotice that Gauss-Seidel converged in less than half as many iterations.\n\nAs shown above, Gauss-Seidel updates one element of the solution vector at a time.\nThis process is more generally described by the following equation.\n\n\\begin{equation} \\label{eq:gauss_seidel_full}\nx^{(k+1)}_i = \\frac{1}{a_{ii}} \\left (b_i - \\sum_{j < i}a_{ij}x^{(k+1)}_j - \\sum_{j > i}a_{ij}x^{(k)}_j \\right )\n\\end{equation}\n\nNotice that the two sums closely resemble an inner product without the\n$i^{\\text{th}}$ term. If we update the entries of the vector $\\mathbf{x}$ in place,\nthis equation can be represented as,\n\n$$\nx^{(k+1)}_i = \\frac{1}{a_{ii}} \\left ( b_i - \\left < A_i, \\mathbf{x}^{(k)} \\right > + a_{ii}x^{(k)}_i \\right )\n$$\nwhere $A_i$ is the $i^{th}$ row of $A$. This can be simplified further to\n\n\\begin{equation} \\label{eq:gauss_seidel}\nx^{(k+1)}_i = x^{(k)}_i + \\frac{1}{a_{ii}} \\left ( b_i - \\left < A_i, \\mathbf{x}^{(k)}\\right >\\right)\n\\end{equation}\n\nMaking one sweep through all the entries of $x$ completes one iteration. We\ncontinue this same process until convergence is attained.\n\n\\begin{problem} \\label{prob:gauss_seidel}\nImplement the Gauss-Seidel Method using Equation \\ref{eq:gauss_seidel}. Your\nfunction should accept a matrix \\li{A}, a vector \\li{b}, an optional parameter\n\\li{tol} that defaults to \\li{1e-8} and an optional parameter \\li{maxiters} that\ndefaults to $100$. Your function should return the solution vector \\li{x} as\nwell as a list of all the approximations of \\li{x} at each iteration. HINT: It is\neasiest to implement this algorithm if you update the approximation vector, $x^{(k)}$, in-place.\n\\end{problem}\n\n\\subsection*{Convergence of Gauss-Seidel} % -----------------------------------\n\n\\begin{definition}\n    A matrix $A \\in M_n(\\mathbb{R})$ is \\emph{positive definite} if all its\n    eigenvalues are positive.\n\\end{definition}\n\n\\begin{theorem}\n    The Gauss-Seidel method converges for a matrix $A$ if it is strictly\n    diagonally dominant or positive definite.\n\\end{theorem}\n\nFor a treatment on the theory of positive definite matrices, see Chapter ?? of\nVolume 1 of the textbook.\n\n\\begin{problem}\nAs we have described up to this point in the lab, we can take advantage of the\nsparsity of a linear system by using iterative methods like Jacobi and Gauss-Seidel.\nFor this problem, compare the runtimes between your \\li{gauss_seidel()} function and\n\\li{la.solve()} for a strictly diagonally dominant system of 5000 parameters. Use the following\ncode to generate a strictly diagonal dominant matrix:\n\\begin{lstlisting}\ndef diag_dom(n, num_entries=None):\n    \"\"\"Generate a strictly diagonally dominant nxn matrix.\n\n    Inputs:\n        n (int) - dimension.\n        vals (list) - range of values for off-diagonal entries.\n        num_entries (int) - number of nonzero values. If None, num_entries\n                    defaults to n^(1.5) - n.\n\n    Returns:\n        A (array) - nxn strictly diagonally dominant matrix.\n    \"\"\"\n    if num_entries is None:\n        num_entries = int(n**1.5) - n\n    A = np.zeros((n,n))\n    i = np.random.choice(np.arange(0,n), size=num_entries)\n    j = np.random.choice(np.arange(0,n), size=num_entries)\n    data = np.random.randint(-4,4,size=num_entries)\n    for c in xrange(num_entries):\n        A[ i[c], j[c] ] = data[c]\n    for i in xrange(n):\n        A[i,i] = np.sum(np.abs(A[i,:])) + 1\n    return A\n\\end{lstlisting}\nWhat difference do you see between these two functions? Explain why there is such a big difference.\n\\end{problem}\n\n\\section*{Sparse Systems} % ===================================================\n\nSome linear systems may have tens of thousands of parameters.\nHowever, in applications where systems of this size arise, it is also common\nthat such matrices are sparse.\nThe tools in SciPy's \\li{sparse} library make it possible to work with even these very large systems.\n\n\\begin{comment}\nThe following is a quick example of how the different types of sparse matrices\ncan be used to optimize performance.\n\n\\begin{lstlisting}\n# Initialize the matrix using a coo_matrix.\n>>> rows = np.array([0,1,2,3,0,2])\n>>> cols = np.array([0,1,2,3,1,0])\n>>> values = np.array([3,5,4,1,2,1])\n>>> A = spar.coo_matrix((values, (rows,cols)), shape=(4,4))\n\n# To visualize the matrix, use .todense(). Keep in mind doing\n#   operations on this dense matrix forfeits all sparse-related\n#   optimizations.\n>>> print A.todense()\nmatrix([[3, 2, 0, 0],\n        [0, 5, 0, 0],\n        [1, 0, 4, 0],\n        [0, 0, 0, 1]])\n\n# perform matrix multiplicaton after converting to a csr_matrix.\n>>> Acsr = A.tocsr()\n>>> x = np.array([1,0,-1,2])\n>>> b = Acsr.dot(x)\narray([3,0,-3,2])\n\n# access rows of a csr_matrix. The syntax for slicing a csr_matrix\n#  (and csc_matrix) is identical to slicing NumPy arrays. For row slicing,\n#  use a csr_matrix. For column slicing, use a csc_matrix.\n>>> Acsr[0,:].todense()\nmatrix([[3, 2, 0, 0]])\n\n>>> Acsc = A.tocsc()\n>>> Acsc[:,2].todense()\nmatrix([[0],\n        [0],\n        [4],\n        [0]])\n\n# access individual elements of the matrix after converting to a dok_matrix.\n>>> Adok = A.todok()\n>>> print Adok[2,0]\n1\n>>> print Adok[1,1]\n5\n\\end{lstlisting}\n\nSince the \\li{coo_matrix} type allows for fast sparse matrix type conversion, it is usually worth the time and memory to convert to the sparse matrix type that corresponds with the operations you are performing.\n\\end{comment}\n\n\n\\begin{problem} % Gauss-Seidel with Sparse matrices.\nTo be able to use the Gauss-Seidel method on sparse matrices, you must translate\nthe code you wrote in Problem \\ref{prob:gauss_seidel} from \\li{numpy} to \\li{scipy.sparse}.\nThe algorithm is the same, but there are some functions that are named differently\nbetween these two packages.\n\nWrite a new function that accepts a sparse matrix \\li{A}, a NumPy array \\li{b},\nan optional parameter \\li{tol} that defauls to \\li{1e-8}, and an optional parameter\n\\li{maxiters} that defaults to 100. Your function should return the solution\nvector \\li{x} as well as a list of all the approximations of \\li{x} at each\niteration.\n\nWe want this function to run as quickly as possible. The Gauss-Seidel method calls for us to extract rows from the matrix $A$ then multiply by the vector $x$. There are many ways to do this that cause some fairly serious runtime issues, so we will provide the code for this specific portion of the algorithm.\n\n\\begin{lstlisting}\n# Slice the i-th row of A and dot product the vector x\nrowstart = A.indptr[i]\nrowend = A.indptr[i+1]\nAix = np.dot(A.data[rowstart:rowend], x[A.indices[rowstart:rowend]])\n\\end{lstlisting}\n\nTo test your function, you can create a strictly diagonally dominant matrix with\nthe following code. In this code, also note how different types of sparse matrices\nhave been used to optimize performance.\n\n\\begin{lstlisting}\ndef spar_diag_dom(n, num_entries=None):\n    \"\"\"Generate a strictly diagonally dominant sparse nxn matrix.\n\n    Inputs:\n        n (int) - dimension\n        num_entries (int) - number of nonzero values. If None, num_entries\n                    defaults to n^(1.5) - n.\n\n    Returns:\n        A (spar.csr_matrix) - strictly diagonally dominant sparse nxn matrix.\n    \"\"\"\n    return spar.csr_matrix(diag_dom(n, num_entries=num_entries))\n\\end{lstlisting}\n\n\\end{problem}\n\n\\subsection*{Successive Over-Relaxation (SOR)} % ------------------------------------\n\nThere are some systems that meet the requirements for convergence in the\nGauss-Seidel method that do not converge very quickly. A slightly altered version\nof the Gauss-Seidel method has been developed that can result in faster convergence.\nThis is achieved by introducting a relaxation factor, $\\omega$. This method is\ncalled Successive Over-Relaxation. In fact, for many slowly converging iterative processes, convergence can be improved by introducing a relaxation factor.\n\nThe iterative equation for Gauss-Seidel, Equation \\ref{eq:gauss_seidel_full},\nwith the introduction of a relaxing factor $\\omega$ becomes,\n\n$$\nx_i^{(k+1)} = (1 - \\omega)x_i^{(k)} + \\frac{\\omega}{a_{ii}} \\left (b_i - \\sum_{j < i}a_{ij}x^{(k+1)}_j - \\sum_{j > i}a_{ij}x^{(k)}_j \\right )\n$$\n\nUpdating the solution vector $x$ inplace as we did with Gauss-Seidel, this\nequation becomes,\n\n\\begin{equation} \\label{eq:sor}\nx^{(k+1)}_i = x^{(k)}_i + \\frac{\\omega}{a_{ii}} \\left ( b_i - \\left < A_i, \\mathbf{x}^{(k)} \\right > \\right )\n\\end{equation}\n\nEquation \\ref{eq:sor} follows by simplifying the full analytic equation in the\nsame way we simplified the Gauss-Seidel method. Notice that when $\\omega = 1$,\nSuccessive Over-Relaxation is equivalent to Gauss-Seidel.\n\n\\begin{problem}\nImplement Successive Over-Relaxation. You should be able to write\nthis function by changing one line of your code from your Gauss Seidel\nfunction. Your function should be able to handle sparse matrices.\n\nWe will examine how varying the values of $\\omega$ affects convergence in Problem \\ref{prob:application}\n\\end{problem}\n\n\\section*{Application: Finite Difference Method} % ======================================================\n\nThroughout this lab, we have said there are sparse linear systems that arise in applications that have tens of thousands of parameters. Systems of this size\noften arise in Finite Difference problems. The underlying theory behind such problems will be addressed in Volume 4 of the textbook. We now present one such problem.\n\n\n\\begin{problem} \\label{prob:application}\n\nA common equation that occurs in both pure and applied mathematics is Laplace's equation.\n\n\\[ \\frac{\\partial^2 u}{\\partial x^2}+ \\frac{\\partial^2 u}{\\partial y^2}= 0.\\]\n\nWe can use Laplace's Equation to model steady-state heat flow. Imagine we have a square metal plate where the top and bottom sides are fixed at 0 degrees Celcius and the left and right sides are fixed at 100 degrees Celcius. We can use Laplace's Equation to approximate the temperature of the interior of the metal plate at any given point.\n\nFor this problem we will solve Laplace's equation numerically using a technique called \\textit{the finite difference method}.  The derivation of the finite difference method will be saved until the lab on Numerical Differentiation, but the relevant equations will be given here.\n\nThe finite difference method can be reduced to solving a sparse system of linear equations. We will describe how to initialize this linear system, but again, all the derivation will be saved for the lab on Numerical Differentiation.\n\nIn Figure \\ref{fig:application} we have the basic set up of the problem described above. The metal plate being represented is $10 in \\times 10 in$. The points $u_{i,j}$ are the discretized grid points we will use to approximate the temperature across the plate.\n\nThen at an interior point of the grid, Laplace's equation can be approximated by\n\\begin{equation} \\label{eq:laplace}\n\\begin{split}\n    \\frac{\\partial^2 u_{i,j}}{\\partial x^2}+ \\frac{\\partial^2 u_{i,y}}{\\partial y^2} \\approx \\frac{1}{h^2}\\left[-4u_{i,j} + u_{i+1,j} + u_{i-1,j} + u_{i,j+1} +  u_{i,j-1}\\right]\n\\end{split}\n\\end{equation}\nwhere $h$ is the distance between gridlines.\n\nWriting Equation \\ref{eq:laplace} for the $9$ interior points of the grid in Figure \\ref{fig:application}result in a $9 \\times 9$ system, $A \\mathbf{x} = b$.\n\n$$\n\\begin{bmatrix}\n-4 & 1  &  0 &  1 &  0 &  0 &  0 &  0 & 0 \\\\\n 1 & -4 &  1 &  0 &  1 &  0 &  0 &  0 & 0 \\\\\n 0 & 1  & -4 &  0 &  0 &  1 &  0 &  0 & 0 \\\\\n 1 & 0  &  0 & -4 &  1 &  0 &  1 &  0 & 0 \\\\\n 0 & 1  &  0 &  1 & -4 &  1 &  0 &  1 & 0 \\\\\n 0 & 0  &  1 &  0 &  1 & -4 &  0 &  0 & 0 \\\\\n 0 & 0  &  0 &  1 &  0 &  0 & -4 &  1 & 0 \\\\\n 0 & 0  &  0 &  0 &  1 &  0 &  1 & -4 & 1 \\\\\n 0 & 0  &  0 &  0 &  0 &  1 &  0 &  1 & -4 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nu_{1,1} \\\\\nu_{1,2} \\\\\nu_{1,3} \\\\\nu_{2,1} \\\\\nu_{2,2} \\\\\nu_{2,3} \\\\\nu_{3,1} \\\\\nu_{3,2} \\\\\nu_{3,3} \\\\\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n-100 \\\\\n 0  \\\\\n-100 \\\\\n-100 \\\\\n 0  \\\\\n-100 \\\\\n-100 \\\\\n 0  \\\\\n-100 \\\\\n\\end{bmatrix}\n$$\nFor any positive integer n, the corresponding system $A \\mathbf{x} = b$ can be expressed as,\n$$\nA = \\begin{bmatrix}\nB_1 & I &      &        & \\\\\nI & B_2 &  I   &        & \\\\\n  & I & \\ddots & \\ddots & \\\\\n  &   & \\ddots & \\ddots & I \\\\\n  &   &        &    I   & B_n\n\\end{bmatrix}\n$$\nwhere $B_i$, is an $n \\times n$ matrix,\n$$\nB_i = \\begin{bmatrix}\n-4 &  1 &      &        & \\\\\n 1 & -4 &  1   &        & \\\\\n   &  1 & \\ddots & \\ddots & \\\\\n   &    & \\ddots & \\ddots & 1 \\\\\n   &    &        &    1   & -4\n\\end{bmatrix}.\n$$\nSo the resulting matrix $A$ ends up being of size $n^2 \\times n^2$.\n\nFor the vector $b$, all nonzero entries correspond to interior points that touch the left or right boundaries. The vector $b$ will be $n^2 \\times 1$.\n\nFor this problem, do the following:\n\\begin{enumerate}\n    \\item Write a function \\li{finite_difference()} that accepts an integer $n$ for the number of interior gridlines. Your function should return the corresponding sparse matrix $A$ and NumPy array $b$. For example, a value of $n = 3$ should result in the matrix $A$ and vector $b$ described above. HINT: Consider using \\li{scipy.sparse.block_diag} and the \\li{setdiag()} method of scipy sparse matrices for dynamically creating the matrix $A$.\n    \\item To demonstrate how convergence is affected by the value of $\\omega$, time your \\li{sparse_sor()} function for values of $\\omega = [1, 1.05, 1.1, \\dots , 1.9, 1.95 ]$. Plot your timings as a function of $\\omega$. Generate the system $A \\mathbf{x} = b$ using your \\li{finite_difference()} function and a value of $n = 20$. Remember that $\\omega = 1$ corresponds to the Gauss-Seidel method. How does Gauss-Seidel compare to SOR with the optimal $\\omega$?\n\n    NOTE: Notice that the matrix $A$ is not strictly diagonally dominant. However, this matrix is positive definite, so the algorithm will converge. Unfortunately, convergence for these kinds of systems require many more iterations. When using the \\li{sparse_sor()} function in this problem, set \\li{maxiters = 10000} and \\li{tol=10**-2}.\n    \\item Using \\li{plt.pcolormesh}, create a heatmap to visualize your solution. The solution vector you get from your \\li{sparse_sor()} function will need to be reshaped to properly visualize the result.\n\\end{enumerate}\n\n\\begin{comment}\nThe following code generates a heatmap to help you visualize the steady-state heat flow across the interior of the plate:\n\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\nimport numpy as np\n\nn = 50\nA,b = finite_difference(n)\nx = sparse_sor(A,b,1.9,maxiters=10000,tol=10**-2)[0]\nU = x.reshape(n,n)\nx,y = np.linspace(0,10,n), np.linspace(0,10,n)\nX,Y = np.meshgrid(x,y)\n\nplt.pcolormesh(X,Y,U,cmap='RdBu_r')\nplt.show()\n\\end{lstlisting}\n\\end{comment}\n\n\n\\end{problem}\n\n%\\newpage\n\n%\\section*{Additional Material} % ==============================================\n\n\n\n\\begin{comment} % Migrated from NumPy lab. vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n\\begin{algorithm} % Laplace's equation procedure.\n\\begin{algorithmic}[1]\n\\Procedure{Jacobi}{$n$, tol}\n\\State $U \\gets$ an $n\\times n$ array of zeros.\n\\State Set the boundaries of $U$.\n\\State $U^\\prime \\gets$ a copy of $U$.\n\\State diff $\\gets$ tol\n\\While {diff $\\ge$ tol}\n    \\State Set all interior points of $U^\\prime$ equal to the average of their neighbors.\n    \\State diff $\\gets$ the maximum of the absolute value of $U - U^\\prime$.\n    \\State Interior of $U \\gets$ interior of $U^\\prime $.\n\\EndWhile\n\\State \\pseudoli{return} $U$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Jacobi method for solving Laplace's equation.}\n\\label{alg:jacobi}\n\\end{algorithm}\n\n\\begin{problem}\nLaplace's equation is used to model steady-state heat flow on a square plate.\nThe plate can be approximated by a matrix, where each entry of the matrix represents the average temperature over a small square portion of the plate.\nSuppose the plate starts at $0^\\circ$ Celsius everywhere except on the east and west boundaries, which are held at a constant temperature of $100^\\circ$.\nIn addition, the north and south boundaries are held constant at $0^\\circ$.\n\n\\[\nU = \\left[\\begin{array}{ccccc}\n\\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}\\cdots & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0\\\\\n\\textcolor[rgb]{1.,0.,0.}{100} & 0 & \\cdots & 0 & \\textcolor[rgb]{1.,0.,0.}{100}\\\\\n\\textcolor[rgb]{1.,0.,0.}\\vdots & \\vdots & \\ddots & \\vdots & \\textcolor[rgb]{1.,0.,0.}\\vdots \\\\\n\\textcolor[rgb]{1.,0.,0.}{100} & 0 & \\cdots & 0 & \\textcolor[rgb]{1.,0.,0.}{100}\\\\\n\\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}\\cdots & \\textcolor[rgb]{0.,0.,1.}0 & \\textcolor[rgb]{0.,0.,1.}0\\\\\n\n\\end{array}\\right]\n\\]\n\nThe non-boundary, interior portion of the matrix (with black text) can be accessed with the slice \\li{U[1:-1,1:-1]}.\nTo find the steady state of the hot plate, set each entry of the interior of $U$ equal to the average of its 4 immediate neighbors (the entries above, below, and to the left and right).\nThis step should take only \\emph{one line} and should be based entirely on array slicing.\n\nContinue updating the interior entries of $U$ until they stop changing significantly.\nThe entire procedure is summarized in Algorithm \\ref{alg:jacobi}.\n\n(Hint: The slice \\li{U[:-2,1:-1]} references the upper neighbors of the interior points of $U$ and \\li{U[1:-1,2:]} references the right neighbors. How can you reference the lower and left neighbors?)\n\nUse the following code to visualize your results.\n%% This does 3D visualization, but it's easier (and better) as a heat map.\n% from mpl_toolkits.mplot3d import Axes 3D\n\n%     x, y = np.linspace(0, 1, n), np.linspace(0, 1, n)\n%     X, Y = np.meshgrid(x, y)\n%     fig = plt.figure()\n%     ax = fig.gca(projection='3d')\n%     ax.plot_surface(X, Y, U, rstride=5)\n%     plt.show()\n\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\n\ndef jacobi(n=100, tol=1e-8):\n\n    # Perform the algorithm, storing the result in the array 'U'.\n\n    # Visualize the results.\n    plt.imshow(U)\n    plt.show()\n\\end{lstlisting}\n\nThis Jacobi iteration is a \\emph{finite difference method}, and is similar to many of the methods that we will use to find numerical solutions to differential equations in Volume IV.\n\\end{problem}\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{jacobi_small.pdf}\n    \\caption{$10\\times 10$ approximation.}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{jacobi_big.pdf}\n    \\caption{$100\\times 100$ approximation.}\n\\end{subfigure}\n\\caption{Hot plates in steady state with different resolutions.}\n\\end{figure}\n\\end{comment} % Used to be in NumPy ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", "meta": {"hexsha": "3f50567e18cd284dfa9675210b550ce4e9bf0d1f", "size": 30751, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1A/IterativeSolvers/IterativeSolvers.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/IterativeSolvers/IterativeSolvers.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/IterativeSolvers/IterativeSolvers.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": 41.0560747664, "max_line_length": 461, "alphanum_fraction": 0.6614744236, "num_tokens": 9799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6235933839771028}}
{"text": "% !TeX spellcheck = en_US\n\\section{Preliminaries}\\label{sec:prelim}\nIn this section, the algorithms used for solving each problem and the basis criteria for the theoretical comparison between them will be formally introduced. \n\n\\subsection{The Davis-Putnam-Logemann-Loveland algorithm (DPLL)}\nOne technique to solve the satisfiability problem is the Davis-Putnam-Logemann-Loveland (DPLL) algorithm, which is a refinement of the original resolution-based Davis-Putnam (DP) algorithm. DPLL is based on four rules:\n\\begin{enumerate}\n\t\\item Tautology elimination\n\t\\item One Literal (Unit clause)\n\t\\item Pure Literal\n\t\\item Branching or splitting\n\\end{enumerate}\nFor our purposes, just the one literal and the branching rules will be considered as they are sufficient for the completeness and soundness of the algorithm, and none of the other rules affect the efficiency.\n\n%%% Important rules (2+4) quick explanation\n\\textit{One Literal:} This rule eliminates unit clauses (any clause contains a single unassigned literal) by assigning the only possible value to make this literal true. Thus, no choice is necessary. By applying this rule, a large part of the entire search space can be pruned, leading to a more efficient SAT instance that is equivalent to the original problem.\n\n\\textit{Branching:} When no other rule is applicable, branching is used to assign a truth value to a variable. This assignment is non-deterministic and depending on the used branching-heuristics a variable is chosen. \n\nAn unsatisfiable SAT problem will lead to apply branching and unit propagation to all branches until no variable is left. For this reason, it is usually harder to detect unsatisfiability, since all branches must be traversed.\n\n\\subsection{Arc consistency and the forward checking algorithm (FC)}\nA standard approach to solve the constraint satisfaction problems is maintaining arc consistency (MAC) or forward checking (FC). Both algorithms are built around the idea of enforcing some level of arc consistency (AC) at each step and branch when needed. The main difference between FC and MAC is the fact that MAC tries to maintain AC on each node at every level while FC tries to avoid the extra work by maintaining AC only between the most recently instantiated variables and those that are still not instantiated.\n\nWhile FC do in general much less work at each node, it needs to branch much more to exclude all wrong paths. On the other hand, MAC usually have smaller number of branches and spends in return more time at each node. This trade-off leads to different characteristics of each algorithm, which in turn prioritize one over another depending on the problem at hand.\n% TODO where to cont. ....one can better than the other\n\n\\subsection{Analysis approach}\nTo determinate that an encoding is good enough or rather better than another (see below \\ref{subsec:branching_for_comparing}), we will compare solving a given problem with its standard algorithm to solving the encoded version of the same problem with its respective standard algorithm. For example: A CSP problem can be solved directly using MAC or it can be encoded as SAT problem (using order encoding for instance) and solved using DPLL. Note that the encoding process cannot take longer time than solving the problem itself. In concrete terms, the encoding procedure (which can be considered as a type of reduction) can be done in polynomial time since both problems are NP complete.\n\n\\subsubsection{Branching for comparing}\\label{subsec:branching_for_comparing}\nSince both MAC/FC and DPLL are backtracking based approaches, we will use the number of visited branches as indicator for the efficiency of each algorithm and in this way compare the impact of achieving arc-consistency from FC on the CSP with unit propagation from DPLL on the SAT problem. So, one algorithm outperforms (dominates) another if and only if it visits less number of branches assuming equivalent branching heuristics \\cite{walsh2000sat}.\n\nThis criterion has been chosen because it serves as a good indicator for the performance of these algorithms in real world applications. This comparison will be aided with examples and comparisons at the end of the paper.\nNotice that FC is always dominated by MAC regarding this criterion, which does not always reflect the real performance but gives a good clue about the efficiency of each algorithm without diving too deep into the exact implementation.\n", "meta": {"hexsha": "69056888ab78dc0e0978749485d42f4946a03d64", "size": 4437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "preliminaries.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": "preliminaries.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": "preliminaries.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": 123.25, "max_line_length": 687, "alphanum_fraction": 0.8106828938, "num_tokens": 911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581684030623, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.6235933719345917}}
{"text": "\\section{Example EBNF}\nFormulae of kind \\texttt{U a, b E c pred(a, b) and not (pred(a) or pred(c))} with precedence order.\n\n\\newcommand{\\nont}[1]{\\;\\langle \\text{#1} \\rangle\\;}\n\\begin{align*}\n    \\nont{LANG} &\\rarr \\nont{FORM} (; \\nont{FORM})^+ . \\\\\n    \\nont{FORM} &\\rarr \\nont{QUANT} \\nont{EXPR} \\\\\n    \\nont{QUANT} &\\rarr (U \\nont{VARL} |\\; E \\nont{VARL})^* \\\\\n    \\nont{EXPR} &\\rarr \\nont{TERM} (or \\nont{TERM})^* \\\\\n    \\nont{TERM} &\\rarr \\nont{FACT} (and \\nont{FACT})^* \\\\\n    \\nont{FACT} &\\rarr [not] \\nont{OBJ} \\\\\n    \\nont{OBJ} &\\rarr \\nont{PRED} |\\; '(' \\nont{EXPR} ')' \\\\\n    \\nont{PRED} &\\rarr id\\; '(' \\nont{VARL} ')' \\\\\n    \\nont{VARL} &\\rarr id (, id)^*\n\\end{align*}\n", "meta": {"hexsha": "41bc54bbabcb1ca4d056c6afd44c3940d87ea01e", "size": 682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grammars/EBNF.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": "grammars/EBNF.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": "grammars/EBNF.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": 42.625, "max_line_length": 99, "alphanum_fraction": 0.5454545455, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.6893056040203135, "lm_q1q2_score": 0.623580687068997}}
{"text": "\\def\\baselinestretch{1}\r\n\r\n\\chapter{Appendix Numerical Linear Algebra}\r\n$M_{m,n}(\\field{F})$ denotes the vector space of matrices over\r\nthe field $\\field{F}$.\r\n\r\n\\[A \\in M_{n,n}(\\dblf) \\; b \\in \\dblf^n,  \\exts x  \\ni \\; Ax=b \\,\r\n\\;\\texttt{iff}\\; det(A)=0\\]\r\n\r\n$\\mathbf{X} \\in M_{mn}(\\field{R})$ is positive definite if $\r\nv^{t} X v > 0 \\fall v \\in \\field{R}^n$.  We can construct\r\npositive definite symmetric matrices by by forming\r\n$\\mathbf{X}^{t} \\mathbf{X}$ where $\\mathbf{X}$ is an orthogonal\r\n(full rank) matrix.\r\n\r\nHorner's rule is a method for evaluating a polynomial at a\r\npoint in $O(n)$ time. Straightforward evaluation of a n degree\r\npolynomial is done in $O(n^{2})$ time. Simply rewrite the\r\nfunction $f(x)= \\sum\\limits_{i=0}^{n-1} {a}_i x^{i}$ as\r\n$f(x)=(\\ldots (a_{n-1}x + a_{n-2} )x +  \\ldots + a_1)x+a_0$\r\n\r\n\\section*{The min max characterization of eigenvalues}\r\nThis is a variational characterization of the eigenvalues of compact operators on a Hilbert space. Let $H \\st H=H^\\dag$ The Rayleigh quotient is defined by $R(x) =  \\frac{<Hx,x>}{\\norm{x}^2}$ Let $\\sigma(H) ={\\lambda_i}$, then $\\forall S_k \\in \\dblr^n$ we have\r\n\\begin{equation*}\r\n  \\underset{x \\in S_k \\norm{x}=1}{max} <Hx,x> \\geq \\lambda_k\r\n\\end{equation*}\r\nwhich implies\r\n\\begin{equation*}\r\n\\underset{S_k}{inf}  \\underset{x \\in S_k \\norm{x}=1}{max} <Hx,x> \\geq \\lambda_k\r\n\\end{equation*}\r\nEquality above is achieved when $S_k = spn{\\mu_k}$ where $\\mu_k$ is the kth eigenvector of $H$.\r\n\r\nThe min max theorem is that\r\n\\begin{equation*}\r\n\\lambda_1 \\leq R(x) \\leq \\lambda_n\r\n\\end{equation*}\r\n\r\n\r\n\r\n\r\n\\section*{The Discrete Fourier Transform on $\\ell^2(\\dblz_{N_1})$} Let $z \\in \\dblz_{N_1} ,\\!\r\nz=(z(0),z(1),\\ldots,z(N_1-1))$.  We index from 0 instead of 1\r\nfor convenience of presenting the FFT. Define\r\n\\begin{equation*}\r\n\\widehat{z(m)}=\\sum\\limits_{k=0}^{N_1-1} z(k)e^{ \\frac{-2 \\pi\r\n\\imath k m}{N_1}}\r\n\\end{equation*}\r\nThe map $\\hat \\!: \\ell^2(\\dblz_{N_1}) \\rightarrow\r\n\\ell^2(\\dblz_{N_1})$ is the Fourier Transform. The vectors\r\n\\begin{equation*}\r\nE_0,E_1, \\ldots,E_{N_1 -1}  :\\!  E_m(n)=\\frac{e^\\frac{-2 \\pi\r\n\\imath m n}{N_1}}{\\sqrt{N_1}}\r\n\\end{equation*}\r\nform an orthonormal basis for $\\ell^2(\\dblz_{N_1})$. The\r\nvectors $ \\frac{E_0}{N_1},\\frac{E_1}{N_1}, \\ldots,\\frac{E_{N_1\r\n-1}}{N_1}$ form an orthogonal basis called the Fourier Basis.\r\n\r\nExtend the indices over $\\dblz_{N_1}$ to $\\dblz$ by considering\r\n$\\dblz_{N_1}$ to be the algebraic group $\\dblz mod N_1$.  Then\r\nwe can define the translation operator\r\n\\begin{equation*}\r\n(R_l z)(n)=z(n-l).\r\n\\end{equation*}\r\nWe can also define the convolution operator with this extended\r\nnotion of $\\dblz_{N_1}$;\r\n\\begin{equation*}\r\nz * w = \\sum \\limits_{k=0}^{N_1-1} z(m-n)W(n)\r\n\\end{equation*}\r\nThe Fourier Multiplier Operator $T_{(m)}$ where $m \\in\r\n\\ell_2{\\dblz_{N_1}}$ is given by\r\n\\begin{equation*}\r\nT_{(m)}=(m\\hat z)\\check{}\r\n\\end{equation*}\r\n\r\nFourier Inversion Formula:\r\n\\begin{equation*}\r\nz(m)=\\frac {1}{N_1}\\sum\\limits_{k=0}^{N_1-1} \\hat{z(k)} e^{\r\n\\frac{2 \\pi \\imath k m}{N_1}}\r\n\\end{equation*}\r\n\r\nParsevall's Relation:\r\n\\begin{equation*}\r\n<z,w>=\\frac{1}{N_1}<\\hat z,\\hat w>\r\n\\end{equation*}\r\n\r\nPlancherel's Formula: Parsevall's relation with $w=z$.\r\n\r\nRepresentation in the Fourier Basis:\r\n\\begin{equation*}\r\nz=\\sum \\limits_{k=0}^{N_1-1} \\hat{z(k)} F_k\r\n\\end{equation*}\r\n\r\nThe effect of the translation operator is to rotate the phase\r\nof the Fourier Transform:\r\n\\begin{equation*}\r\n(R_l z)\\hat(k)=e^{ \\frac{2 \\pi \\imath k l}{N_1}}\\widehat{z(k)}\r\n\\end{equation*}\r\n\r\nThe effect of conjugation is to reflect the Fourier Transform:\r\n\\begin{equation*}\r\n(\\overline{z})\\hat(k)=\\overline{\\hat z(-k)}\r\n\\end{equation*}\r\n\r\n\r\nThe Convolution Operator is equivalent to a Fourier Multiplier\r\nOperator:\r\n\\begin{equation*}\r\nb * z=(m \\hat z )\\check{} \\! : m=\\hat b\r\n\\end{equation*}\r\n\r\n\\section*{Multiresolution analysis} Basis functions of a linear\r\nsubspace $V_j \\subset L^2(\\Omega)$ are\r\ndefined by a scaling function $\\phi$ \r\n\r\n%bbcrevisit - insert the class of admissable scaling fn's for prefect reconstruction, then address frames\r\nvia the following procedure;\r\n\\begin{gather*}\r\n\\phi_{ij}(x) = \\phi(2^{-j} x-i)  \\\\\r\nV_j = span \\{ \\phi_{ij} \\} \\\\\r\nW_{j+1}= V_j \\ V_{j+1}^\\bot \\\\\r\n\\hdots V_{j+1} \\subset V_j \\subset \\hdots \\subset V_0 \\subset \\hdots V_{-j}  \\subset \\hdots \\\\\r\nV_j=V_{j+1} \\oplus W_{j+1} x \\in W_{j+1} \\Rightarrow \\exts\r\n{a_l} \\;\\; x=\\sum_l \\{a_l\\} \\phi_{jl}\r\n\\end{gather*}\r\nA basis for $W_{ij}$ is constructed from a mother wavelet\r\n$\\psi$.\r\n\r\n\\section*{Voroni Tesselations}\r\nA centroidal Voronoi tessellation is a Voronoi tessellation where the\r\ngenerating points are the centroids of the corresponding regions.\r\nApplications Voronoi tessellations can be found in image compression,\r\nclustering, quadrature, and finite difference methods. distribution of\r\nresources.  The dual of the Voroni tessellation in $\\dblr^2$ is the Delaunay\r\ntriangulation.\r\n\r\nThe example below is a simulated example of resource allocation in $\\dblr^2$\r\nA partition of a Random walk in $\\dblr^2$ obtained by calculating the Voroni\r\ntessellation and associated Delaunay triangulation on the k-means centroids.\r\n\r\n\\includegraphics[width=8.0cm,height=8.0cm]{Figures/ClusteringRW/rw_10000_delauney_kmens_convex_hull.pdf}\r\n\r\n\r\n\\section*{The Matrix Exponential}\r\nThe matrix exponential of a matrix $\\mat{A}$ is defined as\r\n\\begin{align*}\r\n  e^{\\mat{A}}\r\n  &= \\mat{I} + \\mat{A} + \\frac{\\mat{A}^2}{2!} + \\dots \\\\\r\n  &= \\sum_{k = 0}^\\infty \\frac{\\mat{A}^k}{k!}.\r\n\\end{align*}\r\n\r\nThe Pade approximation to\r\n$e^{\\mat{A}}$ is\r\n\\begin{displaymath}\r\n  e^{\\mat{A}} \\approx R(\\mat{A}),\r\n\\end{displaymath}\r\nwith\r\n\\begin{align*}\r\n  R_{pq} (\\mat{A})\r\n  &= (D_{pq}(\\mat{A}))^{-1} N_{pq}(\\mat{A}) \\\\\r\n  \\intertext{where}\r\n  D_{pq}(\\mat{A})\r\n  &= \\sum_{j=1}^p \\frac{(p+q-j)! p!}{ (p+q)!j!(p-j)!}\\, \\mat{A}^j \\\\\r\n  \\intertext{and}\r\n  N_{pq}(\\mat{A})\r\n  &= \\sum_{j=1}^q \\frac{(p+q-j)! q!}{ (p+q)!j!(q-j)!}\\, \\mat{A}^j.\r\n\\end{align*}\r\nSee \\cite{Moler78nineteendubious} for a detailed accounting of this and other matters regarding the calculation of the matrix exponential.\r\n%\\citet{Moler78nineteendubious} \\citep*{Moler78nineteendubious} \\citep{Moler78nineteendubious} \\citet*{Moler78nineteendubious}\r\n", "meta": {"hexsha": "756f57761af722b19c843a39e7a8a4921bfacd30", "size": 6203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix_Numerical.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": "Appendix_Numerical.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": "Appendix_Numerical.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": 36.7041420118, "max_line_length": 261, "alphanum_fraction": 0.6664517169, "num_tokens": 2278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6233868450681287}}
{"text": "\\documentclass[12pt]{article}\n\\input{preamble.tex}\n\\addbibresource{bibliography.bib}\n\n\\renewcommand{\\DocTitle}{Barycenters vs. Model Averages in Gaussian Models}\n\\renewcommand{\\DocAuthors}{Gabriel Arpino}\n\n\\setcounter{tocdepth}{4} % Show subsections in the TOC\n\\setcounter{secnumdepth}{4}\n\n\\begin{document}\n\\title\n\\tableofcontents\n\\section{Problem Description}\n\nIt is of importance in machine learning to be able to combine models, be it as a\nmeans of reducing uncertainty in predictions or hedging risk during prediction time.\nThe machine learning community has been exploring this topic in various forms,\nfrom ensembling techniques (\\cite{NIPS2017_7219}) to stochastic optimal transport\n(\\cite{DBLP:journals/corr/abs-1802-05757}). A recent paper, \\cite{NIPS2017_7149},\nexplores the idea of averaging Gaussian Process models using Wasserstein Barycenters,\nand show that it produces clearer and more representative results than the \"naive average\",\nwhich is equivalent to calculating the average and standard deviation of the mean of\nthese gaussian processes. They propose a tractable fixed point iteration method for\ncalculating the barycenter distribution, and display experimental results. A question\nto ask is whether this is required for Gaussian Processes at all, because averaging\nfinite dimensional representations of these is equivalent to adding up Gaussian measures.\nIdentifying similarities and differences between these two approaches can help\nthe community understand when the $O(n^3)$ complexity of calculating the barycenter\nis a requirement, or when a simple sum of gaussian moments could be used.\n\nThe probability of a predicted function $f$ from a model within a set of models\n$M$ of size $N$ is as follows:\n\n\\begin{equation} \\label{eq:1}\n    p(f) = \\int p(f | M)p(M) dM\n\\end{equation}\n\nwhich follows from marginalization. This method of reasoning about the \"average\"\nof model predictions will be termed \\textit{Model Averaging}. For the case of\ngaussian process models, the integral in \\ref{eq:1} is tractable, as the sum becomes\ndiscrete and gaussians are closed under addition:\n\n\\begin{equation} \\label{eq:2}\n    p(f) = \\sum_{i=1}^N \\xi_i p(f | M_i)\n\\end{equation}\n\nwhere $\\xi$ are the discrete probabilities of each model (assuming $p(M)$ is a\ndiscrete measure). For gaussian finite dimensional distributions (the stochastic processes\nevaluated at discrete input points) $X_i$, $p(f)$ has the following moments:\n\n\\begin{align*}\n    \\mathbb{E}[X^*] &= \\sum_{i=1}^N \\xi_i \\mathbb{E}[X_i], &\n    \\mathbb{E}[X^*X^{*T}] &= \\sum_{i=1}^N \\xi_i \\mathbb{E}[X_iX_i^T],\n\\end{align*}\n\nWhere $X^*$ is the random variable denoting $p(f)$ in \\ref{eq:2}. It is not always\nthe case, however, that \\ref{eq:1} is analytically tractable, and in such cases\nthe integral and moments of the distribution can be approximated using Monte Carlo.\n\nThe barycenter $\\mu^*$ of $N$ gaussian distributions $\\mu _i$ is defined as follows:\n\n\\begin{align*} \\label{barycenter:1}\n    \\mu^* = \\inf_{\\mu \\in P_2(H)} \\sum_{i=1}^{N} \\xi_i W_2^2(\\mu_i, \\mu)\n\\end{align*}\n\nwhere $W_2^2(\\mu_1, \\mu_2)$ denotes the 2-Wasserstein metric between gaussian\nmeasures $\\mu_1$, $\\mu_2$ \\cite{NIPS2017_7149}.\n\nIt is unclear whether, for their use in GPs, barycenters provide a reduced uncertainty\nensemble of models compared to standard model averaging. The text explores this idea,\nand states certain scenarios where these two methods of averaging are equal, and where\nthey diverge.\n\n\\section{Theoretical Observations}\n\n\\subsection{Equivalent Covariance Matrices}\n\nFor the finite dimensional distribution representation of Gaussian Processes, it\ncan be shown that the barycenter distribution is a Gaussian distribution with\nmean $\\bar{m}$ and covariance matrix $\\bar{K}$ denoted as follows \\cite{NIPS2017_7149}:\n\n\\begin{align*}\n    \\bar{m} &= \\sum_{i=1}^{N} \\xi_i m_i, &\n    \\bar{K} &= \\sum_{i=1}^{N} \\xi_i (\\bar{K}^{\\frac{1}{2}} K_i \\bar{K}^{\\frac{1}{2}}),\n\\end{align*}\n\nAssume there is some data $\\textbf{y}$ and some time points we would like to predict\n$t_*$ with function values $y_*$. This can be modelled with a GP:\n\n\\begin{align}\n  \\begin{bmatrix}\n    \\textbf{y} \\\\\n    y_*\n\\end{bmatrix} \\sim \\mathcal{N} \\bigg( 0,\\begin{bmatrix}\n      K & K_*^T \\\\\n      K_* & K_{**}\n  \\end{bmatrix} \\bigg)\n\\end{align}\n\nConditioning this GP on a training set $\\textbf{y}$ and evaluating on the finite set $T^*$ produces\na finite dimensional gaussian distribution with moments \\cite{1505.02965}:\n\n\\begin{align*}\n    \\mathbb{E}[\\bar{y}_*] &= K_* K^{-1} \\textbf{y}, &\n    \\hat{K} &= var(\\bar{y}_*) = K_{**} - K_{*} K^{-1} K_*^T\n\\end{align*}\n\nLet us consider the case where we are averaging GPs with equivalent\nkernel functions $k(t, t^\\prime)$ and means $\\mu_i$. Assume that our prior\ndistribution over these models is uniform, so $\\xi_i = 1/N$. The model average $p(f)$ can\nbe calculated from \\ref{eq:2} and the fact that gaussians are closed under addition:\n\n\\begin{equation} \\label{eq:3}\n    p(f) \\sim \\mathcal{N}(\\frac{1}{2} \\mu_1 + \\frac{1}{2} \\mu_2, \\frac{1}{2} K_1 + \\frac{1}{2} K_2)\n\\end{equation}\n\nWhere $K_i$ denotes the covariance matrix that is the gram matrix produced from a GP's\nrespective kernel function $k(t, t^\\prime)$. According to our assumption that both GPs\ncontain equivalent kernel functions, their covariance matrices $K_i$ are equivalent,\nso \\ref{eq:3} reduces to:\n\n\\begin{equation} \\label{eq:4}\n    p(f) \\sim \\mathcal{N}(\\frac{1}{2} \\mu_1 + \\frac{1}{2} \\mu_2, K)\n\\end{equation}\n\nwhere $K = K_1 = K_2$. Now, since we currently care about averaging the predictions\nof GPs that have been conditioned on data (they are not as informative otherwise),\nwe can note that the posterior kernels of these two GPs are also equivalent, which\nfollows from the equivalence of their kernel functions and the equivalent formulations\nfor $\\hat{K}$, the posterior covariance matrix. Let us denote this common posterior covariance matrix\n$\\hat{K}$, and consider the following proposition:\n\n\\begin{proposition} \\label{prop:1}\n    The barycenter of gaussian processes with equivalent kernel functions $k(t, t^{\\prime})$\n    is equivalent to their model average.\n\\end{proposition}\n\n\\begin{proof}\n    In order to show this is true, we have to show that both the moments of both\n    distributions (the barycenter and the model average) are equivalent, since gaussian\n    measures are entirely defined by their first two moments. We start with the\n    means which follow trivially from \\ref{eq:2} and \\ref{barycenter:1}:\n\n    \\begin{equation}\n        \\mathbb{E}[p(f)] = \\sum \\xi_i \\mathbb{E}[p(f | M)] = \\sum \\xi_i \\mu_i = \\bar{m}\n    \\end{equation}\n\n    We now work to show that $\\bar{K} = \\hat{K}$. This can be shown by proving that\n    $\\hat{K}$ is a solution to the fixed point iteration equation \\ref{eq:2}. This\n    equation is shown to be convex in \\cite{NIPS2017_7149}, so finding a solution\n    ensures that it is optimal:\n\n    \\begin{equation} \\label{OTkern}\n        \\bar{K} = \\sum_{i=1}^{N} \\xi_i (\\bar{K}^{\\frac{1}{2}} K_i \\bar{K}^{\\frac{1}{2}})\n    \\end{equation}\n\n    Substitute $\\hat{K}$ into the right hand side:\n\n    \\begin{equation}\n        \\sum_{i=1}^{N} \\xi_i (\\hat{K}^{\\frac{1}{2}} K_i \\hat{K}^{\\frac{1}{2}})\n    \\end{equation}\n\n    but keeping in mind that, since all gaussian processes possess the same kernel\n    function, $\\hat{K} = K_i$, so:\n\n    \\begin{equation} \\label{lolwow}\n        = \\sum_{i=1}^{N} \\xi_i (\\hat{K}^{\\frac{1}{2}} \\hat{K} \\hat{K}^{\\frac{1}{2}})^(\\frac{1}{2})\n    \\end{equation}\n\n    We have to show that \\ref{lolwow} equals $\\hat{K}$ for the implicit equation\n    to be satisfied. Keeping in mind that covariance matrices are symmetric, hence\n    positive semidefinite, diagonalizable, and possess orthogonal eigenvectors, we apply\n    the diagonal decomposition to each matrix:\n\n    \\begin{equation}\n        \\hat{K} = U \\Lambda U^T\n    \\end{equation}\n\n    which leads to\n\n    \\begin{equation}\n        &= \\sum_{i=1}^{N} \\xi_i ((U \\Lambda U^T)^{\\frac{1}{2}} (U \\Lambda U^T) (U \\Lambda U^T)^{\\frac{1}{2}}).\n    \\end{equation}\n\n    Recall that, for orthogonal matrices $U$, $U U^T = I$ and\n\n    \\begin{equation}\n        (U \\Lambda ^{\\frac{1}{2}} U^T) (U \\Lambda ^{\\frac{1}{2}} U^T) = U \\Lambda U^T\n    \\end{equation}\n\n    so, $(U \\Lambda ^{\\frac{1}{2}} U^T) = (U \\Lambda U^T)^{\\frac{1}{2}}$. Plugging this into \\ref{lolwow}:\n\n    \\begin{align*} \\label{k_deriv}\n        &= \\sum_{i=1}^{N} \\xi_i ((U \\Lambda^{\\frac{1}{2}} U^T) (U \\Lambda U^T) (U \\Lambda^{\\frac{1}{2}} U^T))^{\\frac{1}{2}} \\\\\n        &= \\sum_{i=1}^{N} \\xi_i (U \\Lambda^{\\frac{1}{2}} \\Lambda \\Lambda^{\\frac{1}{2}} U^T)^{\\frac{1}{2}} \\\\\n        &= \\sum_{i=1}^{N} \\xi_i (U \\Lambda^2 U^T)^{\\frac{1}{2}} \\\\\n        &= U \\Lambda U^T \\\\\n        &= \\hat{K}\n    \\end{align*}\n\n    Therefore, $\\hat{K}$ is the unique solution to the fixed point iteration equation and we\n    have shown that the gaussian distributions created by model averaging and calculating\n    the barycenter of gaussian processes with prior probabilities $x_i$ are equivalent\n    given that they possess the same kernel function $k(t, t^\\prime)$.\n\\end{proof}\n\nThis result entails that conclusions achieved in \\cite{NIPS2017_7149} could have\nbeen achieved through simple model averaging, as the paper used the same kernels\nfor fitting the gaussian processes, but different samples of data.\n\n\\subsection{Covariance Matrices differing by a constant}\n\nFor the case of covariance matrices differing by a constant, we analyze the following finite dimensional GPs:\n\n\\begin{align}\n    \\textbf{y} \\sim \\mathcal{N} \\big(0, \\Sigma \\big), &\n    \\textbf{y} \\sim \\mathcal{N} \\big(0, \\alpha \\Sigma \\big)\n\\end{align}\n\nwhere $\\alpha$ is a positive constant. Analyzing these two gaussians for now, we can attempt to derive what a solution to the\nfixed point iteration barycenter equation could be, suppose it is of the form $\\beta \\Sigma$, $\\beta$ a positive constant. Then\nfrom \\ref{OTkern} and assuming a uniform average of distributions ($\\xi = 1/N$) we expand:\n\n\\begin{align}\n    \\beta \\Sigma = \\frac{1}{2} ((\\beta \\Sigma)^{\\frac{1}{2}}  \\Sigma (\\beta \\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} +\n    \\frac{1}{2} ((\\beta \\Sigma)^{\\frac{1}{2}} \\alpha \\Sigma (\\beta \\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}}\n\\end{align}\n\nAnd, taking into account that $\\Sigma$ is a positive definite matrix, we use orthogonality to simplify:\n\n\\begin{align}\n    \\beta \\Sigma &= \\frac{1}{2} ((\\beta \\Sigma)^{\\frac{1}{2}}  \\Sigma (\\beta \\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} +\n    \\frac{1}{2} ((\\beta \\Sigma)^{\\frac{1}{2}} \\alpha \\Sigma (\\beta \\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} \\\\\n    \\beta \\Sigma &= \\frac{1}{2} \\beta^{\\frac{1}{2}}((\\Sigma)^{\\frac{1}{2}}  \\Sigma (\\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} +\n    \\frac{1}{2} \\beta^{\\frac{1}{2}} \\alpha^{\\frac{1}{2}} ((\\Sigma)^{\\frac{1}{2}} \\Sigma (\\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} \\\\\n    \\beta \\Sigma &= ((\\Sigma)^{\\frac{1}{2}}  \\Sigma (\\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} * (\\frac{1}{2} \\beta^{\\frac{1}{2}} +\n    \\frac{1}{2} \\beta^{\\frac{1}{2}} \\alpha^{\\frac{1}{2}}) \\\\\n    \\frac{\\beta}{(\\frac{1}{2} \\beta^{\\frac{1}{2}} + \\frac{1}{2} \\beta^{\\frac{1}{2}} \\alpha^{\\frac{1}{2}})} \\Sigma &=\n    ((\\Sigma)^{\\frac{1}{2}}  \\Sigma (\\Sigma)^{\\frac{1}{2}})^{\\frac{1}{2}} \\\\\n    \\frac{\\beta}{(\\frac{1}{2} \\beta^{\\frac{1}{2}} + \\frac{1}{2} \\beta^{\\frac{1}{2}} \\alpha^{\\frac{1}{2}})} &= 1 \\\\\n    \\beta^{\\frac{1}{2}} (\\beta^{\\frac{1}{2}} - (\\frac{1}{2} + \\frac{1}{2} \\alpha^{\\frac{1}{2}})) &= 0 \\\\\n\\end{align}\n\nsimplifying taking into account the relation shown earlier, $K = (K^{\\frac{1}{2}} K K^{\\frac{1}{2}})^{frac{1}{2}}$ for positive definite\nmatrices. Ignoring the trivial solution $\\beta^{frac{1}{2}} = 0$, we get that:\n\n\\begin{equation} \\label{OT_scalar}\n    \\beta^{\\frac{1}{2}} &=  (\\frac{1}{2} + \\frac{1}{2} \\alpha^{\\frac{1}{2}})\n\\end{equation}\n\nAnd if we do the same procedure with the euclidean average, calculating $\\beta_{EU}$ for $\\Sigma_{EU}$ (also called the euclidean barycenter):\n\n\\begin{align}\n    \\beta_{EU} \\Sigma_{EU} = \\frac{1}{2} \\Sigma_{EU}  +\\frac{1}{2}  \\alpha \\Sigma_{EU}\n\\end{align}\n\\begin{equation} \\label{EU_scalar}\n    \\beta_{EU} &= \\frac{1}{2} + \\frac{1}{2} \\alpha\n\\end{equation}\n\nNow, if we analyze equations \\label{OT_scalar}, and \\label{EU_scalar}, we see that the first grows sublinearly with $\\alpha$,\nwhile the second grows linearly with $\\alpha$. This makes sense, and it shows that, for gaussians whose covariance matrices differ\nby a constant, the barycenter always has lower variance. The two $\\beta$'s are equal when $\\alpha = 1$, which is the first case we\nanalyzed, in all other cases,  $(\\frac{1}{2} + \\frac{1}{2} \\alpha^{\\frac{1}{2}}) < \\frac{1}{2} + \\frac{1}{2} \\alpha$.\n\n\n\n\\subsection{Entropy}\n\nNow, we can formulate the same problem using the notion of entropy, and finding which type of barycenter (euclidean or wassserstein)\nwill yield averages with less entropy (more certainty). The entropy of a gaussian distribution of dimension $k$ is:\n\n\\begin{equation} \\label{ENTROPY}\n    H = \\frac{k}{2} + \\frac{k}{2} log(2\\pi) + \\frac{1}{2} log{|\\Sigma|}\n\\end{equation}\n\nNow we can analyze the entropy of the euclidean and wasserstein barycenters, denoted $H_{EU}$ and $H_{OT}$ respectively. Consider the simple\ncase of computing the barycenter of two normal distributions of dimension $k$ with $\\xi_i = \\frac{1}{2}$:\n\n\\begin{align}\n    H_{EU} &= \\frac{k}{2} + \\frac{k}{2} log(2\\pi) + \\frac{1}{2} log{|K_{EU}|} \\\\\n    H_{OT} &= \\frac{k}{2} + \\frac{k}{2} log(2\\pi) + \\frac{1}{2} log{|K_{OT}|} \\\\\n\\end{align}\n\nThe only terms that differ at the covariance matrix determinants, so let's analyze those.\n\n% \\begin{align}\n\\begin{eqnarray*}\n    |K_{OT}| = |\\frac{1}{2} (K_{OT}^{\\frac{1}{2}}K_1K_{OT}^{\\frac{1}{2}})^{\\frac{1}{2}} +\n                    \\frac{1}{2} (K_{OT}^{\\frac{1}{2}}K_1K_{OT}^{\\frac{1}{2}})^{\\frac{1}{2}}| \\\\\n    |K_{OT}| \\geq |\\frac{1}{2} (K_{OT}^{\\frac{1}{2}}K_1K_{OT}^{\\frac{1}{2}})^{\\frac{1}{2}}|\n                    + |\\frac{1}{2} (K_{OT}^{\\frac{1}{2}}K_1K_{OT}^{\\frac{1}{2}})^{\\frac{1}{2}}| \\\\\n    |K_{OT}| \\geq \\frac{1}{2}^{k} |K_{OT}|^{\\frac{1}{2}}|K_1|^{\\frac{1}{2}}\n                        + \\frac{1}{2}^{k} |K_{OT}|^{\\frac{1}{2}}|K_2|^{\\frac{1}{2}} \\\\\n    (|K_{OT}|^{\\frac{1}{2}})(|K_{OT}|^{\\frac{1}{2}} - (\\frac{1}{2}^{k} |K_1|^{\\frac{1}{2}} + \\frac{1}{2}^{k} |K_2|^{\\frac{1}{2}})) \\geq 0 \\\\\n    (|K_{OT}|^{\\frac{1}{2}} - (\\frac{1}{2}^{k} |K_1|^{\\frac{1}{2}} + \\frac{1}{2}^{k} |K_2|^{\\frac{1}{2}})) \\geq 0 \\\\\n\\end{eqnarray*}\n% \\end{align}\n\nUsing the fact that $K_{OT}$ is positive definite and $|A + B| \\geq |A| + |B|$ for matrices $A$ and $B$. Now if we analyze\nthe euclidean barycenter covariance matrix:\n\n\\begin{eqnarray*}\n    |K_{EU}| = |\\frac{1}{2} K_1 + \\frac{1}{2} K_2| \\\\\n    |K_{EU}| \\geq \\frac{1}{2}^{k} |K_1| + \\frac{1}{2}^{k} |K_2| \\\\\n\\end{eqnarray*}\n\nIt can also be shown through KKT optimization that both matrix determinants can be upper\nbounded by $|K_j|$ where $K$\n\n\n\n\n\\begin{todo}\n\n    \\begin{itemize}\n        \\item Loosen the restriction a little bit, and can start looking at covariance matrices that are simultaneously diagonalizable\n        (same eigenvectors, but different eigenvalues)\n\n        \\item Start looking at the entropy of $K$, and how that changes. This has been started, and calculating the entropy actually\n        gives you a lower bound on the $K$ derived from both methods. This is yet to be typed into Latex.\n\n        \\item Properly calculate the computational complexity of barycentering vs\n                calculating the model average\n\n        \\item Comparing with the case where kernels produce covariance functions with the same eigenvectors,\n                but potentially different eigenvalues and what that means\n\n        \\item Is there any case where the variance of the barycenter is larger?\n\n        \\item Any proofs for non-gaussian models?\n    \\end{itemize}\n\n\\end{todo}\n\n\n%\n% \\begin{align*}\n%     \\MEC_i \\cond \\hat{\\MEC}_i &= f^{-1} \\circ \\hat{\\MEC}_i, &\n%     \\hat{\\MEC}_i &\\sim p(\\hat{\\MEC} \\cond \\mathcal{D}),\n% \\end{align*}\n\n\n\\appendix\n\n\n\\printbibliography\n\n\n\\end{document}\n", "meta": {"hexsha": "68cc1ad73bb2d99f897e2ef7b36ef35d8ceb2ac6", "size": 16020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/writeup/theoretical-findings.tex", "max_stars_repo_name": "gabrielarpino/bary", "max_stars_repo_head_hexsha": "2f0adc1cbc57d6691c3190e6e2a653a6888e3e53", "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": "reports/writeup/theoretical-findings.tex", "max_issues_repo_name": "gabrielarpino/bary", "max_issues_repo_head_hexsha": "2f0adc1cbc57d6691c3190e6e2a653a6888e3e53", "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": "reports/writeup/theoretical-findings.tex", "max_forks_repo_name": "gabrielarpino/bary", "max_forks_repo_head_hexsha": "2f0adc1cbc57d6691c3190e6e2a653a6888e3e53", "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": 45.641025641, "max_line_length": 142, "alphanum_fraction": 0.6619850187, "num_tokens": 5263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.6233868404834555}}
{"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\\title{Common Functions on Tensors}\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\\newenvironment{where}{\\noindent{}where\\begin{itemize}}{\\end{itemize}}\n  \n\\section{Introduction}\n  This document describes some of the standard tensor operations\n  that are relevant for machine learning.\n  The rigorous mathematician may note \n  that this document uses the term \\emph{tensor}\n  merely as a substitute for \\emph{multi-dimensional arrays}.\n  \n\\section{Definitions}\n  \\begin{itemize}\n  \n  \\item\n  A \\emph{tensor} $T$ of \\emph{dimensionality} $d_1, d_2, ..., d_o$ is\n  a multi-dimensional array of real numbers in\n  $R^{d_1 \\times d_2 \\times ... \\times d_o}$.\n  \n  \\item\n  In the above definition,\n  the number of dimensions $o$ is also called\n  the \\emph{order} of $T$.\n  \n  \\item\n  The number of elements in $T$, i.e.,\n  $d_1 \\times d_2 \\times ... \\times d_o$\n  is called the size of T.\n  \n  \\item\n  For brevity, we introduce the following notations:\n  \\begin{eqnarray*}\n    \\overrightarrow{d_n} & \\equiv & d_1, d_2, ..., d_n \\\\\n    \\Pi d_n              & \\equiv & d_1 \\times d_2 \\times ... \\times d_n \n  \\end{eqnarray*}\n  \n  \\item\n  A single argument \\emph{tensor function} \n  \\[f: \\R^{\\Pi a_m} \n       \\rightarrow \n       \\R^{\\Pi b_n}\n  \\]\n  is a function that maps a tensor to another tensor.\n  \n  \\item\n  The \\emph{gradient} of the above mentioned $f$\n  at some point $x \\in \\R^{\\Pi a_m}$\n  is a tensor \n  \\[\\nabla f(x) \\in \\R^{\\Pi a_m \\times \\Pi b_n} \n  \\]\n  that gives the rate of change of each element of $f(x)$\n  with respect to each element of $x$.\n  \\[ \\frac{\\partial f(x)[\\overrightarrow{j_n}]}\n          {\\partial x[\\overrightarrow{i_m}]}\n     = \\nabla f(x)[\\overrightarrow{i_m}, \\overrightarrow{j_n}]\n  \\]\n  \n  \\item\n  A multiple argument tensor function\n  takes multiple input tensors, and hence, \n  has a separate gradient tensor with respect to each input.\n  Note that, in general,\n  it is impossible to combine all these gradients into a single tensor,\n  since the various inputs may have different dimensionalities.\n  \n  \\end{itemize}\n\n\\section{Grouping of co-ordinates}\n  The tensors are implemented as a row-major one dimentional array\n  with zero based indexing.\n  For example, the three dimensional tensor \n  $X \\in \\R^{2 \\times 3 \\times 4}$\n  is stored as a one dimensional array of size \n  $2 \\times 3 \\times 4 = 24$.\n  The elements may be accessed by the formula:\n  \\[ X[i, j, k] = X[i \\times 3 \\times 4 + j \\times 4 + k] \\]\n  where $i \\in \\{0, 1\\}$, \n        $j \\in \\{0, 1, 2\\}$ and \n        $k \\in \\{0, 1, 2, 3\\}$.\n    \n  An interesting consequence of this \n  is that consecutive dimensions may be squashed together \n  without affecting the contents of the tensor.\n  For example, \n  $X \\in \\R^{2 \\times 3 \\times 4}$ \n  can be seen to be in\n  $\\R^{2 \\times 12}$,\n  $\\R^{6 \\times 4}$ and $\\R^{24}$,\n  as long as the correct formulae are used to interconvert\n  the coordinates between these various forms.\n  \n  To further clarify, \n  we temporarily introduce the notation of left superscripting\n  the dimensionality of $X$ to denote which format it is in.\n  Thus:\n  \\begin{eqnarray*}\n    X[i, j, k] & = & {}^{2 \\times 3 \\times 4}X[i, j, k]\\\\ \n               & = & {}^{2 \\times 12}X[i, 4j+k] \\\\\n               & = & {}^{6 \\times 4}X[3i + j, k] \\\\\n               & = & {}^{24}X[12i + 4j+k]\n  \\end{eqnarray*}\n  \n  We now state again the above equivalence\n  in even crisper notation by introducing\n  the grouping of co-ordinates:\n  \\begin{eqnarray*}\n    X[i, j, k] & = & X[[i], [j], [k]] \\\\ \n               & = & X[[i, j], k] \\\\\n               & = & X[i, [j, k]] \\\\\n               & = & X[[i, j, k]]\n  \\end{eqnarray*}\n  \n\\section{Identity}\n  The identity tensor function $\\mathbb{I}$ maps each tensor to itself,\n  and hence, is usually not useful in an efficient computation graph.\n  However, it is mentioned here as an example\n  of how the gradient of simple tensor functions\n  can be remarkably sparse.\n  \n  Consider an input \n  $x \\in \\R^{\\Pi a_n}$.\n  The gradient of $\\mathbb{I}$ would then be\n  \\begin{eqnarray*}\n    \\nabla \\mathbb{I}(x)[i_1, i_2, ..., i_n, j_1, j_2, ..., j_n]\n    & = & \\frac{\\partial (\\mathbb{I}(x)[j_1, j_2, ..., j_n])}\n               {\\partial x[i_1, i_2, ..., i_n]} \\\\\n    & = & \\frac{\\partial (\\mathbb{I}(x)[\\overrightarrow{j}])}\n               {\\partial x[\\overrightarrow{i}]} \\\\\n    & = & \\frac{\\partial x[\\overrightarrow{j}]}\n               {\\partial x[\\overrightarrow{i}]} \\\\\n    & = & \\begin{cases}\n            1, & \\text{if } \\overrightarrow{i} == \\overrightarrow{j}\\\\\n            0, & \\text{otherwise}\n          \\end{cases}\n  \\end{eqnarray*}\n  \n  Thus, $\\nabla \\mathbb{I}(x)$ is a \\emph{diagonal} tensor with\n  very few non-zero elements.\n  \n\\section{Back Propagation}\n  A common goal in machine learning is\n  to minimize an objective with respect to some parameters.\n  The back propagation algorithm is a \\emph{gradient descent} algorithm\n  implemented on a computation graph, i.e.,\n  it computes the gradient of the objective\n  with respect to each parameter,\n  and then shifts the parameters to the direction\n  where the objective seems to be \\emph{descending}.\n  \n  The algorithm starts off by computing the value of the each node\n  in the computation graph,\n  starting with the values of the nodes directly defined on the parameters, \n  and ultimately the value of the final objective.\n  \n  Then, to compute the gradient of the objective\n  with respect to the parameters,\n  it starts applying the \\emph{backward propagation} step\n  on each computation node, starting from the objective,\n  and ending at the parameters.\n  \n  Thus, the algorithm uses \\emph{forward propagation}\n  for computing the value of the objective,\n  and then a \\emph{backward propagation} to compute the gradient.\n  \n  As an example, suppose a given node $f$ has an input tensor $x$.\n  $x$ might be a parameter to the overall graph, \n  or it might be the output of some other node.\n  Also, suppose $f$ feeds into some other nodes $g$ and $h$.\n  We will demonstrate the application of the backward propagation step\n  to $f$.\n  \n  Assume that the objective of the graph is $o$.\n  The backward propagation step on $f$ assumes \n  that $g^*(f(x))$ and $h^*(f(x))$ are given, and computes $f^*(x)$,\n  where\n  \\[ g^* = \\frac{\\partial o}{\\partial g},\n     h^* = \\frac{\\partial o}{\\partial h}, \n     f^* = \\frac{\\partial o}{\\partial f} \n  \\]\n  by using the simple relationship:\n  \\[ f^* = \\frac{\\partial o}{\\partial f} \n         =   \\frac{\\partial o}{\\partial g} \\cdot \\frac{\\partial g}{\\partial f}\n           + \\frac{\\partial o}{\\partial h} \\cdot \\frac{\\partial h}{\\partial f}\n         = g^* \\cdot g' + h^* \\cdot h'\n  \\]\n  The operator $\\cdot$ in the above equation is a generalization \n  of the \\emph{vector dot product} to tensors.\n  We discuss this \\emph{tensor dot product} operator\n  in a later section.\n  \n  Also, note that in general, $f$ could have more than one inputs,\n  and could have any number of outputs,\n  some of which might be repeated,\n  in case $f$ is a parameter to them more than once.\n  These generalisations, being somewhat simple,\n  are left to the reader.\n  \n\\section{Tensor Dot Product}\n  Tensor dot product is a generalization of vector dot product\n  and matrix multiplication.\n  Given two tensors \n  \\[ L \\in \\R^{\\Pi a_m \\times \\Pi b_n} \\]\n  \\[ R \\in \\R^{\\Pi b_n \\times \\Pi c_o} \\]\n  the \\emph{tensor dot product of $L$ with $R$ on $n$ dimensions}\n  \\[ L \\cdot_n R = M \\in \\R^{\\Pi a_m \\times \\Pi c_o} \\]\n  is computed as \\footnote{\n   The astute reader will note how\n   the bounds of the \\emph{loop variable} $\\overrightarrow i$\n   are element-wise from \n   $[0, 0 ... (n \\text{ times})]$ to \n   $[b_1 - 1, b_2 - 1, ... b_n - 1]$.\n   This is consistent with the low level storage details\n   discussed in an earlier section.\n  }:\n  \\[ M[\\overrightarrow{a}, \\overrightarrow{c}] \n     = \\sum_{\\overrightarrow{i} = \\overrightarrow{0}_n}\n           ^{\\overrightarrow{i} < \\overrightarrow{b}_n}\n            {L[\\overrightarrow{a}, \\overrightarrow{i}] \n             \\times R[\\overrightarrow{i}, \\overrightarrow{c}]\n            }\n  \\]\n  Thus, matrix multiplication and vector dot product, \n  can be seen as tensor dot products, \n  of matrices and vectors, respectively,\n  on 1 dimension.\n  \n  To revisit how the tensor dot product is connected \n  with the backward propagation algorithm,\n  suppose we have two tensor functions\n  \\[ f: \\R^{\\Pi a_m} \\rightarrow \\R^{\\Pi b_n} \\]\n  \\[ g: \\R^{\\Pi b_n} \\rightarrow \\R^{\\Pi c_o} \\]\n  with gradients\n  \\[ \\nabla f: \\R^{\\Pi a_m} \\rightarrow \\R^{\\Pi a_m \\times \\Pi b_n} \\]\n  \\[ \\nabla g: \\R^{\\Pi b_n} \\rightarrow \\R^{\\Pi b_n \\times \\Pi c_o} \\]\n  then the gradient of\n  \\[ g \\circ f = g(f(\\cdot)): \\R^{\\Pi a_m} \\rightarrow \\R^{\\Pi c_o} \\]\n  denoted by\n  \\[ \\nabla (g \\circ f): \n               \\R^{\\Pi a_m} \\rightarrow \\R^{\\Pi a_m \\times \\Pi c_o} \\]\n  is computed by the \\emph{chain rule}:\n  \\[ \\nabla (g \\circ f) (x) = \\nabla g(f(x)) \\cdot_n \\nabla f(x)\n     \\text{, }\\forall x \\in \\R^{\\Pi a_m}\n  \\]\n  Or in short:\n  \\[ \\nabla(g \\circ f) = \\nabla g \\cdot \\nabla f \\]\n  \n  \n  We now look at the gradients of the dot product product,\n  which can of course be seen as a binary tensor,\n  with a dimensionality in the above example of:\n  \\[ (\\cdot_n): \\R^{\\Pi a_m \\times \\Pi b_n} \n                \\times \n                \\R^{\\Pi b_n \\times \\Pi c_o}\n                \\rightarrow\n                \\R^{\\Pi a_m \\times \\Pi c_o}\n  \\]\n  There are of course two partial gradients, \n  one with respect to each of the two arguments:\n  \\[ \\nabla_L M = \\frac{\\partial M}\n                       {\\partial L}\n                \\in \\R^{\\Pi a_m \\times \\Pi b_n \\times \n                        \\Pi a_m \\times c_o           }\n  \\]\n  \\[ \\nabla_R M = \\frac{\\partial M}\n                       {\\partial R}\n                \\in \\R^{\\Pi b_n \\times \\Pi c_o \\times\n                        \\Pi a_m \\times \\Pi c_o       }\n  \\]\n  These are defined as:\n  \\begin{eqnarray*}\n    \\nabla_L M[\\overrightarrow{a}, \n               \\overrightarrow{b},\n               \\overrightarrow{a'},\n               \\overrightarrow{c}]\n    & = & \\frac{\\partial M[\\overrightarrow{a'}, \n                           \\overrightarrow{c}]}\n               {\\partial L[\\overrightarrow{a},\n                           \\overrightarrow{b}]} \\\\\n    & = & \\frac{\\partial \n                \\sum_{\\overrightarrow{i} \\leftarrow \\overrightarrow{b}}\n                     {L[\\overrightarrow{a'}, \\overrightarrow{i}] \n                      \\times R[\\overrightarrow{i}, \\overrightarrow{c}]\n                     }}\n               {\\partial L[\\overrightarrow{a},\n                           \\overrightarrow{b}]} \\\\\n    & = & \\begin{cases}\n            R[\\overrightarrow{b}, \\overrightarrow{c}], \n               & \\text{if } \\overrightarrow{a'} == \\overrightarrow{a} \\\\\n            0  & \\text{otherwise}\n          \\end{cases}\n  \\end{eqnarray*}\n  \\begin{eqnarray*}\n    \\nabla_R M[\\overrightarrow{b}, \n               \\overrightarrow{c},\n               \\overrightarrow{a},\n               \\overrightarrow{c'}]\n    & = & \\frac{\\partial M[\\overrightarrow{a}, \n                           \\overrightarrow{c'}]}\n               {\\partial R[\\overrightarrow{b},\n                           \\overrightarrow{c}]} \\\\\n    & = & \\frac{\\partial \n                \\sum_{\\overrightarrow{i} \\leftarrow \\overrightarrow{b}}\n                     {L[\\overrightarrow{a}, \\overrightarrow{i}] \n                      \\times R[\\overrightarrow{i}, \\overrightarrow{c'}]\n                     }}\n               {\\partial R[\\overrightarrow{b},\n                           \\overrightarrow{c}]} \\\\\n    & = & \\begin{cases}\n            L[\\overrightarrow{a}, \\overrightarrow{b}], \n               & \\text{if } \\overrightarrow{c'} == \\overrightarrow{c} \\\\\n            0  & \\text{otherwise}\n          \\end{cases}\n  \\end{eqnarray*}\n  \n\\section {Add scalar}\n  The core of a perceptron revolves around the formula:\n  \\[\n      p = w \\cdot x + b \\overrightarrow u\n  \\]\n  \\begin{where}\n    \\item $p$ is the \\emph{output}\n    \\item $w$ are the \\emph{weights} of the perceptron\n    \\item $x$ is the \\emph{input}\n    \\item $b$ is the \\emph{bias}\n    \\item $u$ is a unit tensor created to add $b$\n              to every element of $p$\n  \\end{where}\n  \n  We define the scalar addition function $\\boxplus$ to encapsulate\n  the addition of $b$ to each element in the output\n  \\[\n      z \\boxplus b = z + b.\\overrightarrow{u}\n  \\]\n  Thus,\n  \\begin{eqnarray*}\n    \\frac{\\partial (z \\boxplus b) }{\\partial z} \n      & = & \\nabla \\mathbb{I}(z)\n    \\\\\n    \\frac{\\partial (z \\boxplus b) }{\\partial b} \n      & = & \\nabla \\mathbb{I}(z)\n  \\end{eqnarray*}\n  \n\\section {Sigmoid}\n  The sigmoid function on a scalar is defined as:\n  \\[\n    \\text{sigmoid}(x) = \\frac{e^x}{1 + e^x}\n  \\]\n  The derivative is therefore given as:\n  \\[\n    \\frac{\\partial \\text{sigmoid}(x)}\n         {\\partial x}\n    =\n    \\frac{e^x}{(1 + e^x)^2}\n    =\n    \\text{sigmoid}(x)(1 - \\text{sigmoid}(x))\n  \\]\n  We extend this to tensors as \n  an element wise application of the scalar version\n  \\[\n    \\text{sigmoid}(z) = \\text{map}(z, \\text{sigmoid}(.))\n  \\]\n  And therefore, for an input $z \\in \\R^{\\Pi a_n}$,\n  the gradient \n  $\\nabla \\text{sigmoid}(z) \\in \\R^{\\Pi a_n \\times \\Pi a_n}$ \n  is defined as:\n  \\[\n    \\nabla \\text{sigmoid}(z)[\\overrightarrow{i_n}, \\overrightarrow{j_n}]\n    =\n    \\begin{cases}\n      \\text{sigmoid}(z[\\overrightarrow{i_n}])\n      \\cdot\n      (1 - \\text{sigmoid}(z[\\overrightarrow{i_n}]))\n         & \\text{if } \\overrightarrow{i_n} == \\overrightarrow{j_n}\n      \\\\\n      0  & \\text{otherwise}\n    \\end{cases}\n  \\]\n  \n\\end{document}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "303003e9dc76c79d63c5ba4f8acc4d5586172667", "size": 14314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/TensorFunctions.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/TensorFunctions.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/TensorFunctions.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": 33.8392434988, "max_line_length": 78, "alphanum_fraction": 0.599622747, "num_tokens": 4372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6233724130910978}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{tikz}\n\\usetikzlibrary{datavisualization}\n\\usetikzlibrary{datavisualization.formats.functions}\n\\usetikzlibrary{shapes}\n\\usepackage{multirow}\n\\usepackage{commath}\n\\usepackage{amsmath}\n\\usepackage{booktabs}\n\\usepackage{placeins}\n\n\\begin{document}\n\n\\title{DECISION TREES}\n\\date{}\n\\maketitle\n\nOne of the most widely used and effective learning method to approximate discrete valued target functions.\n\n\\section{Algorithm}\n\n\\begin{enumerate}\n\t\\item Use a heuristic to select an attribute for the root node.\n\t\\item Create branches for each possible value of the attribute.\n\t\\item Split the instances having a particular attribute value to the corresponding branch's node.\n\t\\item Repeat recursively for each branch and stop recursion for a branch if all instances have the same class.\n\\end{enumerate}\n\n\\section{Attribute Selection Heuristic}\n\nPrefer attribute which splits the data into purest successor nodes. Entropy is such a measure of disorder. For a set of items belonging to two classes positive and negative, \n\n\\begin{align*}\n\t\\mathbf{E}(p, n) = -\\frac{p}{p + n} \\times log_2(\\frac{p}{p + n}) -\\frac{n}{p + n} \\times log_2(\\frac{n}{p + n}) \n\\end{align*}\n\n\\begin{figure}\n\t\\centering\n\t\\resizebox{20em}{10em}{\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[step = 0.2 cm, gray, very thin] (0, 0) grid ( 1, 1);\n\t\t\t\\datavisualization [school book axes,\n\t\t\t\tvisualize as smooth line,\n\t\t\t\ty axis={label={$y=\\mathbf{E}(p, n)$}},\n\t\t\tx axis={label={$x=\\frac{p}{p + n}$}} ]\n\t\t\t\n\t\t\tdata [format=function] {\n\t\t\t\tvar x : interval [0.001:1] samples 100;\n\t\t\t\tfunc y = -\\value x * log2(\\value x) - (1 -\\value x) * log2(1 -\\value x);\n\t\t\t};\n\t\t\\end{tikzpicture}\n\t}\n\t\\caption{Entropy in two class distribution}\n\\end{figure}\n\nGenerally for $n$ classes,\n\n\\begin{align*}\n\t\\mathbf{E}(S) = \\mathbf{E}(p_1,\\ p2,\\ ...,\\ p_n) = -\\sum_{i=1}^{n} p_i \\times log_2(p_i) \\\\\n\t                                                                                         \\\\\n\\end{align*}\n\nEntropy only calculates the quality of a single split sub-set. To calculate the quality of the entire split over the attribute $A$, \n\n\\begin{align*}\n\t\\mathbf{Gain}(S, A) = \\mathbf{E}(S) -\\sum_i \\frac{\\abs{S_i}}{\\abs{S}} \\times \\mathbf{E}(S_i) \n\\end{align*}\n\nThe attribute that maximizes the information gain is selected.\n\n\\section{Example}\n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{Training data}\n\t\\label{tab:table1}\n\t\\begin{tabular}{c|cccc|c}\n\t\t\\toprule\n\t\t\\textbf{Sr.} & \\textbf{Outlook} & \\textbf{Temperature} & \\textbf{Humidity} & \\textbf{Windy} & \\textbf{PlayGolf} \\\\\n\t\t\\midrule\n\t\t1            & Sunny            & Hot                  & High              & False          & No                \\\\\n\t\t2            & Sunny            & Hot                  & High              & True           & No                \\\\\n\t\t3            & Overcast         & Hot                  & High              & False          & Yes               \\\\\n\t\t4            & Rainy            & Cool                 & Normal            & False          & Yes               \\\\\n\t\t5            & Overcast         & Cool                 & Normal            & True           & Yes               \\\\\n\t\t6            & Sunny            & Mild                 & High              & False          & No                \\\\\n\t\t7            & Sunny            & Cool                 & Normal            & False          & Yes               \\\\\n\t\t8            & Rainy            & Mild                 & Normal            & False          & Yes               \\\\\n\t\t9            & Sunny            & Mild                 & Normal            & True           & Yes               \\\\\n\t\t10           & Overcast         & Mild                 & High              & True           & Yes               \\\\\n\t\t11           & Overcast         & Hot                  & Normal            & False          & Yes               \\\\\n\t\t12           & Rainy            & Mild                 & High              & True           & No                \\\\\n\t\t13           & Rainy            & Cool                 & Normal            & True           & No                \\\\\n\t\t14           & Rainy            & Mild                 & High              & False          & Yes               \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n~\\\\\nAll four attributes - \\textbf{Outlook}, \\textbf{Temperature}, \\textbf{Humidity} and \\textbf{Windy} are candidates for evaluation to choose the best splitting attribute.\n~\\\\\n\n\\begin{align*}\n\t\\textbf{E}(S) & = -\\frac{9}{14}\\times log2(\\frac{9}{14}) - \\frac{5}{14} \\times log2(\\frac{5}{14}) \\\\\n\t              & = 0.940\\ \\textbf{bits}                                                            \n\\end{align*}\n\n\\subsection*{Outlook Gain}\n\n\\FloatBarrier\n\\begin{table}[h]\n\t\\centering\n\t\\label{tab:table2}\n\t\\begin{tabular}{c|cc|c|c}\n\t\t\\toprule\n\t\t\\textbf{Outlook}        & \\textbf{Yes} & \\textbf{No} & \\textbf{Split\\ Entropy}                                                              & \\textbf{Split Weight} \\\\\n\t\t\\midrule\n\t\t\\rule{0pt}{1ex}Rainy    & 3            & 2           & $-\\frac{3}{5}\\times log_2(\\frac{3}{5})-\\frac{2}{5}\\times log_2(\\frac{2}{5}) = 0.971$ & $\\frac{5}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}Overcast & 4            & 0           & $-\\frac{4}{4}\\times log_2(\\frac{4}{4})-\\frac{0}{4}\\times log_2(\\frac{0}{4}) = 0$     & $\\frac{4}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}Sunny    & 2            & 3           & $-\\frac{2}{5}\\times log_2(\\frac{2}{5})-\\frac{3}{5}\\times log_2(\\frac{3}{5}) = 0.971$ & $\\frac{5}{14}$        \\\\ [1ex]\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\begin{align*}\n\t\\textbf{Gain}(S, Outlook) & = \\mathbf{E}(S) - (\\frac{5}{14}\\times 0.971 + \\frac{4}{14} \\times 0 + \\frac{5}{14} \\times 0.971) \\\\   \n\t                          & = 0.940 - 0.694                                                                                  \\\\\n\t                          & = 0.246\\ \\textbf{bits}                                                                           \\\\  \n\\end{align*}\n\n\\subsection*{Temperature Gain}\n\n\\FloatBarrier\n\\begin{table}[h]\n\t\\centering\n\t\\label{tab:table3}\n\t\\begin{tabular}{c|cc|c|c}\n\t\t\\toprule\n\t\t\\textbf{Temperature} & \\textbf{Yes} & \\textbf{No} & \\textbf{Split\\ Entropy}                                                              & \\textbf{Split Weight} \\\\\n\t\t\\midrule\n\t\t\\rule{0pt}{1ex}Cool  & 3            & 1           & $-\\frac{3}{4}\\times log_2(\\frac{3}{4})-\\frac{1}{4}\\times log_2(\\frac{1}{4}) = 0.811$ & $\\frac{4}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}Hot   & 2            & 2           & $-\\frac{2}{4}\\times log_2(\\frac{2}{4})-\\frac{2}{4}\\times log_2(\\frac{2}{4}) = 1$     & $\\frac{4}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}Mild  & 4            & 2           & $-\\frac{4}{6}\\times log_2(\\frac{4}{6})-\\frac{2}{6}\\times log_2(\\frac{2}{6}) = 0.918$ & $\\frac{6}{14}$        \\\\ [1ex]\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\begin{align*}\n\t\\textbf{Gain}(S, Temperature) & = \\mathbf{E}(S) - (\\frac{4}{14}\\times 0.811 + \\frac{4}{14} \\times 1 + \\frac{6}{14} \\times 0.918) \\\\   \n\t                              & = 0.940 - 0.911                                                                                  \\\\\n\t                              & = 0.029\\ \\textbf{bits}                                                                           \\\\  \n\\end{align*}\n\n\\subsection*{Humidity Gain}\n\n\\FloatBarrier\\clearpage\n\\begin{table}[h]\n\t\\centering\n\t\\label{tab:table4}\n\t\\begin{tabular}{c|cc|c|c}\n\t\t\\toprule\n\t\t\\textbf{Humidity}     & \\textbf{Yes} & \\textbf{No} & \\textbf{Split\\ Entropy}                                                              & \\textbf{Split Weight} \\\\\n\t\t\\midrule\n\t\t\\rule{0pt}{1ex}High   & 3            & 4           & $-\\frac{3}{7}\\times log_2(\\frac{3}{7})-\\frac{4}{7}\\times log_2(\\frac{4}{7}) = 0.985$ & $\\frac{7}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}Normal & 6            & 1           & $-\\frac{6}{7}\\times log_2(\\frac{6}{7})-\\frac{1}{7}\\times log_2(\\frac{1}{7}) = 0.592$ & $\\frac{7}{14}$        \\\\ [1ex]\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\begin{align*}\n\t\\textbf{Gain}(S, Humidity) & = \\mathbf{E}(S) - (\\frac{7}{14}\\times 0.985 + \\frac{7}{14} \\times 0.592) \\\\   \n\t                           & = 0.940 - 0.789                                                          \\\\\n\t                           & = 0.151\\ \\textbf{bits}                                                   \\\\  \n\\end{align*}\n\n\\subsection*{Windy Gain}\n\n\\FloatBarrier\n\\begin{table}[h]\n\t\\centering\n\t\\label{tab:table5}\n\t\\begin{tabular}{c|cc|c|c}\n\t\t\\toprule\n\t\t\\textbf{Windy}       & \\textbf{Yes} & \\textbf{No} & \\textbf{Split\\ Entropy}                                                              & \\textbf{Split Weight} \\\\\n\t\t\\midrule\n\t\t\\rule{0pt}{1ex}False & 6            & 2           & $-\\frac{6}{8}\\times log_2(\\frac{6}{8})-\\frac{2}{8}\\times log_2(\\frac{2}{8}) = 0.811$ & $\\frac{8}{14}$        \\\\ [1ex]\n\t\t\n\t\t\\rule{0pt}{1ex}True  & 3            & 3           & $-\\frac{3}{6}\\times log_2(\\frac{3}{6})-\\frac{3}{6}\\times log_2(\\frac{3}{6}) = 1$     & $\\frac{6}{14}$        \\\\ [1ex]\n\t\t\n\t\\end{tabular}\n\\end{table}\n\n\\begin{align*}\n\t\\textbf{Gain}(S, Windy) & = \\mathbf{E}(S) - (\\frac{8}{14}\\times 0.811 + \\frac{6}{14} \\times 1) \\\\   \n\t                        & = 0.940 - 0.892                                                      \\\\\n\t                        & = 0.048\\ \\textbf{bits}                                               \\\\  \n\\end{align*}\n\nSince $\\textbf{Gain}(S, Outlook)$ represents the highest information gain, the root is split by \\textbf{Outlook} as visualized below.\n\n\\FloatBarrier\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}[scale = 3] \n\t\t\n\t\t\\node (v0) at (0,0) [shape=ellipse, draw] {\\begin{tabular}{c} \\textbf{Outlook} \\\\ 9 Yes, 5 No\\end{tabular}};\n\t\t\\node (v1) at (210 : 1.80)[shape=ellipse, draw] {3 Yes, 2 No};\n\t\t\\node (v2) at (270 : 1)[shape=ellipse, draw] {4 Yes, 0 No};\n\t\t\\node (v3) at (330 : 1.70)[shape=ellipse, draw] {2 Yes, 3 No};\n\t\t\n\t\t\\draw \n\t\t(v0) -- (v1) node[draw=none,fill=none, midway, left] {Rainy};\n\t\t\\draw\n\t\t(v0) -- (v2) node[draw=none,fill=none, midway, left] {Overcast};\n\t\t\\draw\n\t\t(v0) -- (v3) node[draw=none,fill=none, midway, left] {Sunny};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\n\\FloatBarrier\n\\section{Gain Ratio}\n\nInformation gain favours attributes with many values over those with few values. If an attribute is highly branching, the splits generally tend to be small and heterogeneous causing the split entropies to be close to zero and thus resulting in very high information gain.\n\nTo avoid this difficulty, information gain is divided by a quantity called intrinsic information that is sensitive to highly branching attribues to give the gain ratio which is maximized instead.\n\n\\begin{align*}\n\t\\textbf{IntrinsicInfo}(S, A) & = \\sum_{i} \\frac{|S_i|}{|S|} \\times log_2(\\frac{|S_i|}{|S|}) \\\\\n\t\\textbf{GainRatio}(S, A)     & = \\frac{\\textbf{Gain}(S, A)}{\\textbf{IntrinsicInfo}(S, A)}   \n\\end{align*}\n\\section{Refinements}\n\n\\subsection{Continuous Attributes} \n\nFor a continuous attribute $\\textbf{A}$, define a boolean attribute $\\textbf{A}_c$ which is $True$ if $\\textbf{A} < c$ and $False$ otherwise. To pick the optimal value of the threshold $c$ that maximizes the information gain, values of $\\textbf{A}$ are sorted and candidate thresholds are generated midway of each consecutive pair.  \n\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c|cccccc}\n\t\t\\toprule\n\t\t\\textbf{Temperature} & 40 & 48 & 60  & 72  & 80  & 90 \\\\\n\t\t\\midrule\n\t\t\\textbf{PlayGolf}    & No & No & Yes & Yes & Yes & No \\\\\n\t\\end{tabular}\n\\end{table}\n\nCandidate thresholds and their information gain is computed as below. It is clear from the table below that $\\textbf{Temperature} = 54$ is the optimal value for the threshold $c$.\n\n\\FloatBarrier\n\\begin{table}\n\t\\centering\n\t\\begin{tabular}{ |c|c|c|c| }\n\t\t\\hline\n\t\t\\textbf{Split} & \\textbf{Yes} & \\textbf{No} & \\textbf{Gain}                     \\\\ \n\t\t\\hline\n\t\t$< 44$         & 0            & 1           & \\multirow{2}{*}{0.191}            \\\\\n\t\t$>= 44$        & 3            & 2           &                                   \\\\\n\t\t\\hline\n\t\t$< 54$         & 0            & 2           & \\multirow{2}{*}{$\\mathbf{0.459}$} \\\\\n\t\t$>= 54$        & 3            & 1           &                                   \\\\\n\t\t\\hline\n\t\t$< 66$         & 1            & 2           & \\multirow{2}{*}{0.082}            \\\\\n\t\t$>= 66$        & 2            & 1           &                                   \\\\\n\t\t\\hline\n\t\t$< 76$         & 2            & 2           & \\multirow{2}{*}{0}                \\\\\n\t\t$>= 76$        & 1            & 1           &                                   \\\\\n\t\t\\hline\n\t\t$< 85$         & 3            & 2           & \\multirow{2}{*}{0.191}            \\\\\n\t\t$>= 85$        & 0            & 1           &                                   \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\FloatBarrier\\clearpage\n\n\\subsection{Overfitting}\n\nA hypothesis is said to overfit the training data if it performs very accurately on the training data but fares poorly on unseen test data. Two major approaches to avoid overfitting in decision tree learning are as follows:\n\n\\begin{itemize}\n\t\\item Stop growing the tree before it starts to overfit.\n\t\\item Grow tree fully but post prune it.\n\\end{itemize}\n\n\\subsubsection{Reduced Error Pruning}\nData is divided into training and validation sets. The training set is used to form the decision tree. Now, each decision node is considered for pruning. \n\nPruning a decision tree consists of removing the subtree rooted at that node, making it a leaf node, and assigning it the most common classification of the training examples affiliated with that node. Nodes are removed only if the resulting tree performs no worse than the original tree over the validation set. \n\nNodes are pruned iteratively, always choosing the node whose removal most increases the accuracy over the validation set. Pruning continues until further removal of nodes is harmful.\n\nIn case of limited data, the prospects of this pruning scheme are relatively dim. \n\n\\subsubsection{Rule Post Pruning}\n\n\\begin{enumerate}\n\t\\item Infer the decision tree from the training set allowing overfitting.\n\t\\item Convert tree into equivalent set of rules by creating one rule per one path from root to a leaf node.\n\t\\item Prune each rule by removing any preconditions that results in improving its estimated accuracy on the validation set. If a rule is of the form \n\t      \\begin{align*}\n\t      \t  & IF\\ (\\textbf{Outlook}=Sunny)\\wedge(\\textbf{Humidity}=High) \\\\\n\t      \t  & THEN\\ \\textbf{PlayGolf} = No                               \n\t      \\end{align*}    \n\t      then $(\\textbf{Outlook}=Sunny)$ and $(\\textbf{Humidity}=High)$ are preconditions. \n\t\\item Sort the pruned rules by their estimated accuracy, and consider them in this sequence when classifying subsequent instances.\n\\end{enumerate}\n\n\n\\subsection{Missing Attributes Values}\n\n\\FloatBarrier\\clearpage\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}[scale = 3] \n\t\t\n\t\t\\node (v0) at (0,0) [shape=ellipse, draw] {\\begin{tabular}{c}\n\t\t\t14 instances \\\\ \n\t\t\t6 \\textbf{Windy} = True \\\\ \n\t\t\t7 \\textbf{Windy} = False \\\\\n\t\t\t1 \\textbf{Windy} = Unknown \\\\\n\t\t\t\\end{tabular}};\n\t\t\\node (v1) at (220 : 1.60)[shape=ellipse, draw] {$6 + \\frac{6}{13}$ instances};\n\t\t\\node (v2) at (320 : 1.60)[shape=ellipse, draw] {$7 + \\frac{7}{13}$ instances};\n\t\t\n\t\t\\draw \n\t\t(v0) -- (v1) node[draw=none,fill=none, midway, left] {True};\n\t\t\\draw\n\t\t(v0) -- (v2) node[draw=none,fill=none, midway, left] {False};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\n\n\\subsection{Attribute With Differing Costs}\nInstead of maximizing information gain ratio, a quantity like $\\frac{f(\\textbf{Gain}(S, A))}{g(\\textbf{Cost}(S, A))}$ is maximized where $f$ and $g$ are chosen on a case by case basis.\n\n\\section{Comments}\n\n\\begin{itemize}\n\t\\item Decision trees provide a practical method for concept learning and for learning other discrete-valued functions.\n\t\\item A complete hyphothesis space is searched because the space of decision trees can represent any dicsrete-valued function defined over discrete valued instances. It therby avoids major difficulty associated with approaches that consider only restricted sets of hypothesis.\n\\end{itemize}\n\n\\end{document}", "meta": {"hexsha": "2f1c131aa3cdbeb60ec1cac817bf6b8d15e09383", "size": 16064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Decision trees/Decision trees.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": "Decision trees/Decision trees.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": "Decision trees/Decision trees.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": 45.7663817664, "max_line_length": 333, "alphanum_fraction": 0.531623506, "num_tokens": 4913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6233724051461842}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Principal Component Analysis (PCA)}\n\\author{Tara Mirmira }\n\\date{July 2017}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problem}\nWe want to build a linear model for the variable $\\boldsymbol{y}$ using the explanatory variables $\\boldsymbol{x_1}, \\ldots, \\boldsymbol{x_p}$. The coefficient for the explanatory variable $x_j$ is $\\hat{\\boldsymbol{\\beta_j}}$. The standard error for the coefficient is:\n$$\nSE(\\hat{\\boldsymbol{\\beta_j}}) = \\dfrac{1}{\\sqrt{1 - {R_j}^2}}\\dfrac{\\sigma}{\\sqrt{\\sum_{i=1}^n (x_{ji} - \\overline{x_j})^2}}\n$$\nwhere\n\\begin{itemize}\n    \\item $R$ is the multiple correlation coefficient from regressing $\\boldsymbol{x_j}$ on the other explanatory variables $\\boldsymbol{x_1}, \\ldots, \\boldsymbol{x_{j-1}}, \\boldsymbol{x_{j+1}}, \\ldots, \\boldsymbol{x_p}$\n    \\item $n$ is the number of observations in the data set\n    \\item $\\sigma$ is the standard deviation of the residuals from fitting the full model to the data\n    \\item $Var(x_{ji}) = \\frac{1}{n-1}\\sum_{i=1}^n (x_{ji} - \\overline{x_j})^2$ so $\\sum_{i=1}^n (x_{ji} - \\overline{x_j})^2 = (n-1)*Var(x_{ji})$\n\\end{itemize}\n\nIf the explanatory variables are collinear, the fit from regressing $\\boldsymbol{x_j}$ on the other explanatory variables improves, which means $R_j$ becomes larger. When $R_j$ increases, the term $\\frac{1}{\\sqrt{1-{R_j}^2}}$, also called the Variance Inflation Factor (VIF), increases so $SE(\\hat{\\boldsymbol{\\beta_j}})$ increases. As the variance of the coefficients increases, the the coefficients become unstable, meaning they can vary greatly. In the most extreme case where one explanatory variable is perfectly collinear with another, there is no unique solution $\\boldsymbol{\\hat{\\beta}}$ for the coefficients.\n\n\\section{Solution}\n\nTo remedy the problem described above, we will try to find a new set of vectors $\\boldsymbol{W} = \\{\\boldsymbol{w_1}, \\ldots, \\boldsymbol{w_p}\\}$ that spans the same vector space as the columns of the design matrix $\\boldsymbol{X}$. Recall that  \n$$\n\\boldsymbol{X} = \\begin{bmatrix}\n    \\boldsymbol{1}       & \\boldsymbol{x_1} & \\dots & \\boldsymbol{x_p}\n\\end{bmatrix}\n$$\n\n\\noindent We will replace the design matrix $\\boldsymbol{X}$ with $\\boldsymbol{W}$ to build the model. The $\\boldsymbol{w_i} \\in \\boldsymbol{W}$ are called principal components. There are two special features about the vectors in $\\boldsymbol{W}$:\n\\begin{itemize}\n    \\item The vectors are orthogonal\n    \\item The vectors are in order of decreasing variance for their respective coefficient. This means: \n    \\begin{itemize}\n        \\item The coefficient for $\\boldsymbol{w_1}$ has the greatest variance \n        \\item The coefficient for $\\boldsymbol{w_p}$ has the smallest variance\n    \\end{itemize}\n\\end{itemize}\n\n\\begin{figure}[hbtp]\n        \\centering\n        \\includegraphics[width=4.5in]{pca.png}\n        \\caption{principal Components Diagram}\n        \\label{Newton Raphson}\n    \\end{figure}\n\n\\noindent In the above picture, we can see that the two principal components are orthogonal. The first component, PC1, covers more spread, showing that PC1 has the greatest variability. In two dimensions, PC1 is the major axis of an ellipse and PC2 is the minor axis.\n\n\\section{How to Find $\\boldsymbol{W}$}\n\nNote: the method described here is not efficient for data with many explanatory variables (large $p$). \n\n\\begin{enumerate}\n    \\item Standardize the data. \n    $$\n    \\boldsymbol{X} = \n    \\begin{bmatrix}\n    \\boldsymbol{x_1} & \\dots & \\boldsymbol{x_p}\n\\end{bmatrix} \\rightarrow \n\\boldsymbol{Z} = \n    \\begin{bmatrix}\n    \\boldsymbol{z_1} & \\dots & \\boldsymbol{z_p}\n\\end{bmatrix} \n    $$\n    \n    $$\n    \\text{where } \\boldsymbol{z_i} = \\frac{\\boldsymbol{x_i} - \\overline{x_i}\\boldsymbol{1}}{SD(x_i)\\boldsymbol{1}} \\text{and} SD(x_i) = \\sqrt{\\frac{1}{n-1}\\sum_{j=1}^n (x_ij - \\overline{x_i})^2}\n    $$\n    \n   If the original data had variances that are very different, we will lean towards including the variables with larger variances in the first few principal components. To eliminate this effect, the data should first be standardized.\n   \n   \\item Find a new set of basis vectors for $span\\{\\boldsymbol{z_1}, \\ldots, \\boldsymbol{z_p}\\}$ \n\n    The first principal component $\\boldsymbol{w_1}$ can be written as a linear combination of the $\\boldsymbol{z_i}'s$. \n    $$\n    \\boldsymbol{w_1} = a_{11}\\boldsymbol{z_1} + a_{12}\\boldsymbol{z_2} + \\ldots + a_{1p}\\boldsymbol{z_p}\n    $$\n    \n    \\noindent We want to find the $a_{1i}'s$ such that $Var(\\boldsymbol{w_1})$ is the greatest of all the $\\boldsymbol{w_i}'s$.\\\\\n    \n    $\\overline{\\boldsymbol{w_1}} = 0$ because all the $\\boldsymbol{z_i}'s$ have mean $0$ since they have been standardized\\\\\n    \n    $$Var(\\boldsymbol{w_1}) = \\frac{1}{n-1}\\sum_{i=1}^n (w_{1i} - \\overline{\\boldsymbol{w_1}})^2 = \\frac{1}{n-1}\\sum_{i=1}^n w_{1i}^2 = \\frac{1}{n-1}\\boldsymbol{w_1^T w_1}$$\n    \n\n\nCalculations:\n\n$$\n\\boldsymbol{Z^T}\\boldsymbol{Z} = \n\\begin{bmatrix}\n\\sum z_{1i}^2 & \\sum z_{1i}z_2i & \\ldots \\\\\n\\sum z_{2i}z_{1i} & \\sum z_{2i}^2 & \\ldots \\\\\n\\vdots & \\vdots & \\ddots \\\\\n\\end{bmatrix}\n$$\n\n$\\sum z_{1i}^2 = \\dfrac{\\sum (x_{1i} - \\overline{x_1})^2}{s_1^2}$ \\\\\n\n$\\frac{1}{n-1}\\sum z_{1i}^2 = \\frac{1}{n-1}\\dfrac{\\sum (x_{1i} - \\overline{x_1})^2}{s_1^2} = 1$ because $\\boldsymbol{z_1}$ is standardized $\\boldsymbol{x_1}$\n\nUsing the above calculation:\n\n$$\n\\frac{1}{n-1}\\boldsymbol{Z^T}\\boldsymbol{Z} = \n\\begin{bmatrix}\n1 & r_{12} & \\ldots & r_{1p}\\\\\nr_{21} & 1 & \\ldots & r_{2p}\\\\\n\\vdots & \\vdots & \\ddots \\\\\nr_{p1} & r_{p2} & \\ldots & 1 \\\\\n\\end{bmatrix} = \\boldsymbol{R_{xx}} \\text{ (the correlations of the $\\boldsymbol{x_i}'s$)}\n$$\n\nwhere $$r_{ij} = \\frac{1}{n-1}\\sum_{k=1}^n \\frac{z_{ik} - \\overline{z_i}}{SD(z_i)}\\frac{z_{jk} - \\overline{z_j}}{SD(z_j)} = \\frac{1}{n-1}\\sum_{k=1}^n \\frac{z_{ik} - 0}{1}\\frac{z_{jk} - 0}{1} = \\frac{1}{n-1}\\sum_{k=1}^n z_{ik}z_{jk}$$ is the correlation coefficient between $\\boldsymbol{z_i}$ and $\\boldsymbol{z_j}$\\\\\n\n\\noindent Note that $\\boldsymbol{R_{xx}}$ is also the Variance-Covariance matrix for the matrix $\\boldsymbol{Z}$.\n\\\\\\\\\n$\n\\max_{\\boldsymbol{a_1}} (\\boldsymbol{a_1}^t\\boldsymbol{R_{xx}}\\boldsymbol{a_1}) \\text{ where } \\boldsymbol{a_1}^t\\boldsymbol{a_1} = 1 \\quad (1)\n$\n\\\\\\\\\n\\noindent We include the constraint $\\boldsymbol{a_1}^t\\boldsymbol{a_1} = 1$ so that when taking the maximum with respect to $\\boldsymbol{a_1}$, $\\boldsymbol{a_1}$ does not increase to infinity.\\\\\\\\\n\n\\noindent Equation $(1)$ above is equivalent to:\\\\\\\\\n\n$\\max_{\\boldsymbol{a_1}, \\lambda} \\boldsymbol{a_1}^t\\boldsymbol{R_{xx}}\\boldsymbol{a_1} - \\lambda(\\boldsymbol{a_1}^t\\boldsymbol{a_1} - 1)$\\\\\\\\\n\n\\noindent Taking the derivative with respect to $\\boldsymbol{a_1}$:\\\\\\\\\n\n$\n2\\boldsymbol{R_{xx}} - 2\\lambda \\boldsymbol{a_1} = 0\n$\\\\\\\\\n\n$\n\\boldsymbol{R_{xx}a_1} = \\lambda \\boldsymbol{a_1}\n$\n\\\\\\\\\nWhat the above calculation shows is that the principal components are the eigenvectors of the matrix $\\boldsymbol{R_{xx}}$. The first principal component is the eigenvector corresponding to the largest eigenvector. We order the eigenvalues $\\lambda_1 \\geq \\lambda_2 \\geq \\ldots \\geq \\lambda_p > 0$ and the corresponding eigenvectors $\\boldsymbol{w_1}, \\ldots, \\boldsymbol{w_p}$ are the orthogonal principal components in order of decreasing variance.\n\n\\item Find the eigenvectors and eigenvalues of $\\boldsymbol{R_{xx}}$, the variance-covariance matrix for $\\boldsymbol{Z}$.\n\\end{enumerate}\n\nSummary of the calculations and steps:\n\\begin{enumerate}\n    \\item Standardize the input: $\\boldsymbol{X} \\rightarrow \\boldsymbol{Z}$\n    \\item Find the $\\boldsymbol{R_{xx}}$, the variance-covariance matrix for $\\boldsymbol{Z}$\n    \\item Find the eigenvectors and eigenvalues of $\\boldsymbol{R_{xx}}$\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "629fc6f9afe84d43d8fdf07f1490432e3d3b04da", "size": 7830, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OPERATORS/PCA/docs/main.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": "OPERATORS/PCA/docs/main.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": "OPERATORS/PCA/docs/main.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": 48.6335403727, "max_line_length": 618, "alphanum_fraction": 0.6913154534, "num_tokens": 2608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6233233250813031}}
{"text": "\n% This LaTeX was auto-generated from MATLAB code.\n% To make changes, update the MATLAB code 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\\section*{Gradient Descent}\n\n\n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Gradient\n   \\item Gradient Descent\n   \\item Fail situation\n   \\item Plot contour\n   \\item Reference\n\\end{itemize}\n\n\n\\subsection*{Gradient}\n\n\\begin{par}\nGradient descent method is based on gradient\n\\end{par} \\vspace{1em}\n\\begin{par}\n$$ \\nabla f  = \\frac{\\partial f}{\\partial x_1 }\\mathbf{e}_1 + \\cdots +\n\\frac{\\partial f}{\\partial x_n }\\mathbf{e}_n $$\n\\end{par} \\vspace{1em}\n\\begin{par}\ngradient always point to the asent direction\n\\end{par} \\vspace{1em}\n\n\n\\subsection*{Gradient Descent}\n\n\\begin{par}\nf is object function, and this is unconstrained\n\\end{par} \\vspace{1em}\n\\begin{par}\n$$\\min_{x} f $$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nf = (@(X) (exp(X(1,:)-1) + exp(1-X(2,:)) + (X(1,:) - X(2,:)).^2));\n%f = (@(X) (sin(0.5*X(1,:).^2 - 0.25 * X(2,:).^2 + 3) .* cos(2*X(1,:) + 1 - exp(X(2,:))) ))\n\\end{verbatim}\n\n\n\\subsection*{Fail situation}\n\n\\begin{par}\nRosenbrock function Gradient descent/ascent algorithm zig-zags, because the gradient is nearly orthogonal to the direction of the local minimum in these regions. It's hard to convergence\n\\end{par} \\vspace{1em}\n\\begin{par}\n$$ f(x, y) = (1-x)^2 + 100 * (y - x^2) ^ 2 $$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\n%f = (@(X) (1-X(1,:)).^2 + 100 * (X(2,:) - X(1,:).^2).^2);\n\\end{verbatim}\n\n\n\\subsection*{Plot contour}\n\n\\begin{verbatim}\n[X, Y] = meshgrid(-2:0.1:2);\nXX = [reshape(X, 1, numel(X)); reshape(Y, 1, numel(Y))];\n%surf(X, Y, reshape(f(XX), length(X), length(X)))\ncontour(X, Y, reshape(f(XX), length(X), length(X)), 50);\n\nhold on;\n\\end{verbatim}\n\n\\includegraphics [width=4in]{test_01.eps}\n\\begin{par}\nplot gradient of function\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nfor i=1:5:length(XX)\n    tmp = XX(:,i);\n    g = gradient_of_function(f, tmp);\n    %plot([tmp(1),tmp(1)+g(1)*0.02],[tmp(1),tmp(2)+g(1)*0.02]);\n    quiver(tmp(1),tmp(2),g(1)*0.02,g(2)*0.02);\nend\n\\end{verbatim}\n\n\\includegraphics [width=4in]{test_02.eps}\n\\begin{par}\ncalculation\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nx0 = [-1; -1];\n[x, v, h] = gradient(f, x0)\n\n% built-in method\n[x_in, v_in] = fminunc(f, x0)\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\nx =\n\n    0.7960\n    1.2038\n\n\nv =\n\n    1.7974\n\n\nh =\n\n  Columns 1 through 7\n\n   -1.0000   -1.0271   -0.4515    0.6432    0.8185    0.7755    0.7859\n   -1.0000    0.4778    0.2130    1.0809    1.1279    1.1801    1.2059\n\n  Columns 8 through 12\n\n    0.7925    0.7963    0.7956    0.7959    0.7960\n    1.2007    1.2024    1.2033    1.2039    1.2038\n\nWarning: Gradient must be provided for trust-region algorithm;\n  using line-search algorithm instead. \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\n\nx_in =\n\n    0.7961\n    1.2039\n\n\nv_in =\n\n    1.7974\n\n\\end{verbatim} \\color{black}\n    \\begin{par}\nplot descent steps\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nfor i=2:length(h)\n    tmp1 = h(:,i-1);\n    tmp2 = h(:,i);\n    quiver(tmp1(1),tmp1(2),tmp2(1)-tmp1(1),tmp2(2)-tmp1(2), 0, 'r','LineWidth',2)\nend\n\\end{verbatim}\n\n\\includegraphics [width=4in]{test_03.eps}\n\n\n\\subsection*{Reference}\n\n\\begin{enumerate}\n\\setlength{\\itemsep}{-1ex}\n   \\item \\begin{verbatim}http://www.onmyphd.com/?p=gradient.descent\\end{verbatim}\n   \\item Convex Optimization\n   \\item \\begin{verbatim}https://en.wikipedia.org/wiki/Gradient\\end{verbatim}\n   \\item \\begin{verbatim}https://en.wikipedia.org/wiki/Gradient_descent\\end{verbatim}\n   \\item \\begin{verbatim}http://stronglyconvex.com/blog/gradient-descent.html\\end{verbatim}\n\\end{enumerate}\n\n\n\n\\end{document}\n    \n", "meta": {"hexsha": "c6647738fd4f42924161191fd5ef477ffd3db825", "size": 3911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "first-order/Gradient_Descent/html/test.tex", "max_stars_repo_name": "SwordYork/MachineLearning", "max_stars_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2015-02-09T20:07:27.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-10T06:40:54.000Z", "max_issues_repo_path": "first-order/Gradient_Descent/html/test.tex", "max_issues_repo_name": "SwordYork/MachineLearning", "max_issues_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "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": "first-order/Gradient_Descent/html/test.tex", "max_forks_repo_name": "SwordYork/MachineLearning", "max_forks_repo_head_hexsha": "a088b4260c48dd320d7b9b63b42f9051b1d740fd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2015-07-08T13:10:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:10:53.000Z", "avg_line_length": 21.2554347826, "max_line_length": 186, "alphanum_fraction": 0.6502173357, "num_tokens": 1436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6233233215606679}}
{"text": "\\section {Gen and Kill Sets}\n\\setlength{\\parindent}{0pt}\n\n(Prepared by Sameer V. Pande)\n\n\\vspace{0.3cm}\n\n\\subsection{Transfer and Meet Functions}\nIn previous module we discussed about how a DFA can be expressed with help of transfer and meet functions.\nTransfer function computes the value of out[s] as a function f(in[s]). And for forward dfa, when there are multiple incoming edges at a node,\nthe meet operator computes the in[s] as a function of outsets of the predecessors.\n\n\\subsection{Using GEN and KILL sets to represent transfer functions}\nIn most cases, it is possible to represent transfer function with help of gen-sets and kill-sets which depend only on the statement (hence, can be computed statically).\nTransfer function 'f' can be written as: \\textbf{f(V) = (V - Kill(s)) $\\bigcup$ Gen(s)}. The first part of expression\n\\textbf{ V - Kill(S)} is called \"propagate\" part and \\textbf{Gen(S)} is called 'generate' part.\n\n\\subsection{Examples of Gen and Kill Sets}\nWe'll see two examples of gen/kill sets \n\\subsubsection{Constant Propataion}\n\\includegraphics[scale=0.5]{images/89_1.png}\n\\newline \nThe gen-set for constant-assignment is just \\{(x,c)\\}. The kill-set ensures that any previous value of the variable x is removed from the set, before new value is added via gen.\nWhen x is assigned a value via a complex function/expression, then gen-set is empty-set but kill-set removes the old value of x, if any.\n\\subsubsection{Available Expressions Analysis}\n\\includegraphics[scale=0.5]{images/89_2.png}\n\\newline \nConsider case when variable x is assigned an expression. The gen-set is similar to that of constant propgation (but now it has expressions as well, instead of just constants). The kill-set takes care of two things \n\\begin{enumerate}\n    \\item Remove the expressions corresponding to variable x \n    \\item Remove the variables which have expressions corresponding to older-value of x.\n\\end{enumerate}\n\n\\subsection{Gen/Kill Summaries for Basic Blocks}\nOne of the advantages of using basic-blocks is that it generates summaries over the entire block. We can take a sequential composition of transfer function of all statements in the basic-block to give us a block-level transfer function.\nA block level transfer function can be represented using block level genset and killset.\n\\includegraphics[scale=0.5]{images/89_3.png}\n\nFor a basic block B, Gen$_B$ and Kill$_B$ can be interpreted as follows:\n\\begin{itemize}\n    \\item Gen$_B$: Locally exposed constant definitions,i.e., the definitions available at the end of basic-block B.\n    \\item Kill$_B$: Set of constant definitions killed by B.\n\\end{itemize}", "meta": {"hexsha": "eb5d8b326b03284384b4968cc050dec52c7d3b80", "size": 2626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module89.tex", "max_stars_repo_name": "arpit-saxena/compiler-notes", "max_stars_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "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": "module89.tex", "max_issues_repo_name": "arpit-saxena/compiler-notes", "max_issues_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "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": "module89.tex", "max_forks_repo_name": "arpit-saxena/compiler-notes", "max_forks_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-16T08:32:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-12T19:11:33.000Z", "avg_line_length": 61.0697674419, "max_line_length": 236, "alphanum_fraction": 0.7745620716, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6233233077003614}}
{"text": "\\section{Universality and descent for pushouts}\\label{chap:descent}\n\nWe begin this lecture with the idea that pushouts can be presented as higher inductive types. The general idea behind higher inductive types is that we can introduce new inductive types not only with constructors at the level of points, but also with constructors at the level of identifications. Pushouts form a basic class of examples that can be obtained as higher inductive types, because they come equipped with the structure of a cocone. The cocone $(i,j,H)$ in the commuting square\n\\begin{equation*}\n  \\begin{tikzcd}\n    S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\n    A \\arrow[r,swap,\"i\"] & C\n  \\end{tikzcd}\n\\end{equation*}\nequips the type $C$ with two \\emph{point constructors}\n\\begin{align*}\n  i & : A \\to C \\\\\n  j & : B \\to C \\\\\n  \\intertext{and a \\emph{path constructor}}\n  H & : \\prd{s:S}i(f(s)) = j(g(s))\n\\end{align*}\nthat provides an identification $H(s):i(f(s))=j(g(s))$ for every $s:S$. The induction principle then specifies how to construct sections of families over $C$. Naturally, it takes not only the point constructors $i$ and $j$, but also the path constructor $H$ into account. \n\nThe induction principle is one of several equivalent characterizations of pushouts. We will prove a theorem providing five equivalent characterizations of homotopy pushouts. Two of those we have already seen in \\cref{thm:pushout_up}: the universal property and the pullback property. The other three are\n\\begin{enumerate}\n\\item the \\emph{dependent pullback property},\n\\item the \\emph{dependent universal property},\n\\item the \\emph{induction principle}.\n\\end{enumerate}\n\nAn implication that is particularly useful among our five characterizations of pushouts, is the fact that the pullback property implies the dependent pullback property. We use the dependent pullback property to derive the \\emph{universality of pushouts} (not to be confused with the universal property of pushouts), showing that for any commuting cube\n\\begin{equation*}\n  \\begin{tikzcd}\n    & S' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n    A' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[d] \\arrow[dl,crossing over] \\\\\n    A \\arrow[dr] & D' \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n    & D\n  \\end{tikzcd}\n\\end{equation*}\nin which the back left and right squares are pullback squares, if the front left and right squares are also pullback squares, then so is the induced square\n\\begin{equation*}\n  \\begin{tikzcd}\n    A'\\sqcup^{\\mathcal{S}'}B' \\arrow[r,densely dotted] \\arrow[d,densely dotted] & D' \\arrow[d] \\\\\n    A\\sqcup^S B \\arrow[r,densely dotted] & D\n  \\end{tikzcd}\n\\end{equation*}\n\nWe then observe that the univalence axiom can be used together with the universal property of pushouts to obtain such families over pushouts in the first place. We prove the descent theorem, which asserts that for any diagram of the form\n\\begin{equation*}\n  \\begin{tikzcd}\n    & S' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n    A' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[d] \\\\\n    A \\arrow[dr] & & B \\arrow[dl] \\\\\n    & C\n  \\end{tikzcd}\n\\end{equation*}\nin which the bottom square is a pushout square and the back left and right squares are pullback squares, there is a unique way of extending this to a commuting cube\n\\begin{equation*}\n  \\begin{tikzcd}\n    & S' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n    A' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[d] \\\\\n    A \\arrow[dr] & C' \\arrow[from=ul,crossing over,densely dotted] \\arrow[from=ur,crossing over,densely dotted] \\arrow[d,densely dotted] & B \\arrow[dl] \\\\\n    & C\n  \\end{tikzcd}\n\\end{equation*}\nin which also the front left and right squares are pullback squares. Thus the converse of the universality theorem for pushouts also follows. The descent property used to show that pullbacks distribute over pushouts, and to compute the fibers of maps out of pushouts (the source of many exercises).\n\nWe note that the computation rules in our treatment for the induction principle of homotopy pushouts are weak. In other words, they are identifications. In this course we have no need for judgmental computation rules. Our focus is instead on universal properties. We refer the reader who is interested in the more `traditional' higher inductive types with judgmental computation rules to \\cite{hottbook}.\n\n\\subsection{Five equivalent characterizations of homotopy pushouts}\n\nConsider a commuting square\n\\begin{equation}\\label{eq:descent-pushout-square}\n  \\begin{tikzcd}\n    S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\n    A \\arrow[r,swap,\"i\"] & H\n  \\end{tikzcd}\n\\end{equation}\nwith $H:i\\circ f \\htpy j \\circ g$, where we will sometimes write $\\mathcal{S}$ for the span $A\\leftarrow S\\rightarrow B$. Our first goal is to formulate the induction\nprinciple for pushouts, which specifies how to construct a section of an arbitrary type family $P$ over $X$. Like the induction principle for the circle, the induction principle of pushouts has to take both the point constructors and the path constructors of $X$ into account. In our case, the point constructors are the maps\n\\begin{align*}\n  i & : A \\to X \\\\\n  j & : B \\to X,\n  \\intertext{and the path constructor is the homotopy}\n  H & : \\prd{s:S}i(f(s))=j(g(s)).\n\\end{align*}\nTherefore, we obtain for any section $h:\\prd{x:X}P(x)$ a triple $(h_A,h_B,h_S)$ consisting of\n\\begin{align*}\n  h_A & : \\prd{a:A}P(i(a)) \\\\\n  h_B & : \\prd{b:B}P(j(b)) \\\\\n  h_S & : \\prd{s:S} \\mathsf{tr}_P(H(s),h(i(f(s))))=h(j(g(s))).\n\\end{align*}\nThe dependent functions $h_A$ and $h_B$ are simply given by\n\\begin{align*}\n  h_A & \\defeq h\\circ i \\\\\n  h_B & \\defeq h\\circ j.\n\\end{align*}\nThe homotopy $h_S$ is defined by $h_S(s)\\defeq\\apd{h}{H(s)}$, using the dependent action on paths of $h$. We call such triples $(h_A,h_B,h_S)$ \\define{dependent cocones} on $P$ over the cocone $(i,j,H)$, and will write $\\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P)$ for this type of dependent cocones. Thus, we have a function\n\\begin{equation*}\n  \\mathsf{ev\\usc{}pushout}(P):\\Big(\\prd{x:X}P(x)\\Big)\\to \\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P).\n\\end{equation*}\nWe are now in position to define the induction principle and the dependent universal property of pushouts.\n\n\\begin{defn}\n  We say that $X$ satisfies the \\define{induction principle of the pushout of $\\mathcal{S}$} if the function\n  \\begin{equation*}\n  \\mathsf{ev\\usc{}pushout}(P):\\Big(\\prd{x:X}P(x)\\Big)\\to \\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P).\n  \\end{equation*}\n  has a section for every type family $P$ over $X$.\n\\end{defn}\n\n\\begin{defn}\n  We say that $X$ satisfies the \\define{dependent universal property of the pushout of $\\mathcal{S}$} if the function\n  \\begin{equation*}\n  \\mathsf{ev\\usc{}pushout}(P):\\Big(\\prd{x:X}P(x)\\Big)\\to \\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P).\n  \\end{equation*}\n  is an equivalence for every type family $P$ over $X$.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:comp-pushout}\n  For $(h_A,h_B,h_S)$ and $(h'_A,h'_B,h'_S)$ in $\\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P)$, the type of identifications $(h_A,h_B,h_S)=(h'_A,h'_B,h'_S)$ is equivalent to the type of triples $(K_A,K_B,K_S)$ consisting of\n  \\begin{align*}\n    K_A & : \\prd{a:A}h_A(a)=h'_A(a) \\\\\n    K_B & : \\prd{b:B}h_B(b)=h'_B(b),\n  \\end{align*}\n  and a homotopy $K_S$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\mathsf{tr}_P(H(s),h_A(f(s))) \\arrow[r,equals,\"\\ap{\\mathsf{tr}_P(H(s))}{K_A(f(s))}\"] \\arrow[d,equals,swap,\"h_S(s)\"] & \\mathsf{tr}_P(H(s),{h'_A(f(s))}) \\arrow[d,equals,\"h'_S(s)\"] \\\\\n      h_B(g(s)) \\arrow[r,equals,swap,\"K_B(g(s))\"] & h_B(g(s))\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes for every $s:S$.\n\n  Therefore we see that the induction principle of the pushout of $\\mathcal{S}$ provides us, for every dependent cocone $(h_A,h_B,h_S)$ of $P$ over $(i,j,H)$, with a dependent function $h:\\prd{x:A}P(x)$ equipped with homotopies\n  \\begin{align*}\n    K_A & : \\prd{a:A}h(i(a))=h_A(a) \\\\\n    K_B & : \\prd{b:B}h(j(b))=h_B(b),\n  \\end{align*}\n  and a homotopy $K_S$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\mathsf{tr}_P(H(s),h(i(f(s)))) \\arrow[r,equals,\"\\ap{\\mathsf{tr}_P(H(s))}{K_A(f(s))}\"] \\arrow[d,equals,swap,\"\\apd{h}{H(s)}\"] & \\mathsf{tr}_P(H(s),{h_A(f(s))}) \\arrow[d,equals,\"h_S(s)\"] \\\\\n      h(j(g(s))) \\arrow[r,equals,swap,\"K_B(g(s))\"] & h_B(g(s))\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes for every $s:S$. These homotopies are the \\define{computation rules} for pushouts\\index{computation rules!for pushouts}. The dependent universal property is equivalent to the assertion that for every dependent cocone $(h_A,h_B,h_S)$, the type of quadruples $(h,K_A,K_B,K_S)$ is contractible.\n\\end{rmk}\n\n\\begin{thm}\\label{thm:dependent-pullback-property-pushout}\n  Consider a commuting square\n  \\begin{equation}\\label{eq:dppp1}\n    \\begin{tikzcd}\n      S \\arrow[d,swap,\"f\"] \\arrow[r,\"g\"] & B \\arrow[d,\"j\"] \\\\\n      A \\arrow[r,swap,\"i\"] & C\n    \\end{tikzcd}\n  \\end{equation}\n  with $H:(i\\circ f) \\htpy (j \\circ g)$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The square in \\cref{eq:dppp1} is a pushout square.\n  \\item The square in \\cref{eq:dppp1} satisfies the pullback property of pushouts.\n  \\item The square satisfies the \\define{dependent pullback property} of pushouts: For every family $P$ over $C$, the square\n    \\begin{equation}\\label{eq:dppp2}\n      \\begin{tikzcd}[column sep=large]\n        \\prd{z:C}P(z) \\arrow[rr,\"h\\mapsto h\\circ j\"] \\arrow[d,swap,\"h\\mapsto h\\circ i\"] & &[1em] \\prd{y:B}P(j(y)) \\arrow[d,\"h\\mapsto h\\circ g\"] \\\\\n        \\prd{x:A}P(i(x)) \\arrow[r,swap,\"{h\\mapsto h \\circ f}\"] & \\prd{s:S}P(i(f(s))) \\arrow[r,swap,\"{\\lam{h}{s}\\mathsf{tr}_P(H(s),h(s))}\" yshift=-2ex] & \\prd{s:S}P(j(g(s))),\n      \\end{tikzcd}\n    \\end{equation}\n    which commutes by the homotopy\n    \\begin{equation*}\n      \\lam{h}\\mathsf{eq\\usc{}htpy}(\\lam{s}\\apd{h}{H(s)}),\n    \\end{equation*}\n    is a pullback square.\n  \\item The type $C$ satisfies the \\define{dependent universal property} of pushouts.\n  \\item The type $C$ satisfies the \\define{induction principle} of pushouts.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  We have already seen in \\cref{thm:pushout_up} that (i) and (ii) are equivalent.\n\n  To see that (ii) implies (iii), note that we have a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      &  \\sm{h:C\\to C}\\prd{c:C}P(h(c)) \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      \\sm{h:A\\to C}\\prd{a:A}P(h(a)) \\arrow[d] & \\big(\\sm{c:C}P(c)\\big)^C \\arrow[dl] \\arrow[dr] & \\sm{h:B\\to C}\\prd{b:B}P(h(b)) \\arrow[d] \\arrow[dl,crossing over] \\\\\n      \\big(\\sm{c:C}P(c)\\big)^A \\arrow[dr] & \\sm{h:S\\to C}\\prd{s:S}P(h(s)) \\arrow[d] \\arrow[from=ul,crossing over] & \\big(\\sm{c:C}P(c)\\big)^B \\arrow[dl] \\\\\n      & \\big(\\sm{c:C}P(c)\\big)^S\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the vertical maps are equivalences. Moreover, the bottom square is a pullback square by the pullback property of pushouts, so we conclude that the top square is a pullback square. Since this is a square of total spaces over a pullback square, we invoke \\cref{lem:fiberwise-pullback} to conclude that for each $h:C \\to C$, the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\prd{c:C}P(h(c)) \\arrow[rr] \\arrow[d] & &[2em] \\prd{b:B} P(h(j(b))) \\arrow[d] \\\\\n      \\prd{a:A}P(h(i(a))) \\arrow[r] & \\prd{s:S}P(h(i(f(s)))) \\arrow[r,swap,\"\\mathsf{tr}_{((k:S\\to C)\\mapsto \\prd{s:S}P(k(s)))}(\\mathsf{eq\\usc{}htpy}(h\\cdot H))\" yshift=-2ex] & \\prd{s:S}P(h(j(g(s))))\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square. Note that the transport with respect to the family $k\\mapsto \\prd{s:S}(Pk(s))$ along the identification $\\mathsf{eq\\usc{}htpy}(h\\cdot H)$ is homotopic to the map\n  \\begin{equation*}\n    \\lam{h}{s}\\mathsf{tr}_{P\\circ h}(H(s),h(s)):\\prd{s:S}P(h(i(f(s)))) \\to \\prd{s:S}P(h(j(g(s)))).\n  \\end{equation*}\n  Therefore we conclude that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\prd{c:C}P(h(c)) \\arrow[rr] \\arrow[d] & &[2em] \\prd{b:B} P(h(j(b))) \\arrow[d] \\\\\n      \\prd{a:A}P(h(i(a))) \\arrow[r] & \\prd{s:S}P(h(i(f(s)))) \\arrow[r,swap,\"{\\lam{h}{s}\\mathsf{tr}_{P\\circ h}(H(s),h(s))}\" yshift=-2ex] & \\prd{s:S}P(h(j(g(s))))\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square for each $h:C\\to C$. Using the case $h\\jdeq\\idfunc : C \\to C$ we conclude that the cocone $(i,j,H)$ satisfies the dependent pullback property.\n\n  To see that (iii) implies (ii) we recall that transport with respect to a trivial family is homotopic to the identity function. Thus we obtain the pullback property from the dependent pullback property using the trivial family $\\lam{c}T$ over $C$.\n\n  To see that (iii) implies (iv) we note that $\\mathsf{ev\\usc{}pushout}(P)$ is an equivalence if and only if the gap map of the square in \\cref{eq:dppp2} is an equivalence.\n\n  It is clear that (iv) implies (v), so it remains to show that (v) implies (iv). If $X$ satisfies the induction principle of pushouts, then the map\n  \\begin{equation*}\n    \\mathsf{ev\\usc{}pushout}:\\Big(\\prd{x:X}P(x)\\Big)\\to\\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P)\n  \\end{equation*}\n  has a section, i.e., it comes equipped with\n  \\begin{align*}\n    \\mathsf{ind\\usc{}pushout} & :\\mathsf{dep\\usc{}cocone}_{(i,j,H)}(P)\\to\\Big(\\prd{x:X}P(x)\\Big) \\\\\n    \\mathsf{comp\\usc{}pushout} & : \\mathsf{ev\\usc{}pushout}\\circ\\mathsf{ind\\usc{}pushout} \\htpy\\idfunc.\n  \\end{align*}\n  To see that $\\mathsf{ev\\usc{}pushout}$ is an equivalence it therefore suffices to construct a homotopy\n  \\begin{equation*}\n    \\mathsf{ind\\usc{}pushout}(\\mathsf{ev\\usc{}pushout}(h))\\htpy h\n  \\end{equation*}\n  for any $h:\\prd{x:X}P(x)$. From the fact that $\\mathsf{ind\\usc{}pushout}$ is a section of $\\mathsf{ev\\usc{}pushout}$ we obtain an identification\n  \\begin{equation*}\n    \\mathsf{ev\\usc{}pushout}(\\mathsf{ind\\usc{}pushout}(\\mathsf{ev\\usc{}pushout}(h)))= \\mathsf{ev\\usc{}pushout}(h).\n  \\end{equation*}\n  Therefore we observe that it suffices to construct a homotopy $h\\htpy h'$ for any two functions $h,h':\\prd{x:X}P(x)$ that come equipped with an identification\n  \\begin{equation*}\n    \\mathsf{ev\\usc{}pushout}(h)=\\mathsf{ev\\usc{}pushout}(h').\n  \\end{equation*}\n  Now we recall from \\cref{rmk:comp-pushout} that this type of identifications is equivalent to the type of triples $(K_A,K_B,K_S)$ consisting of\n  \\begin{align*}\n    K_A & : \\prd{a:A}h(i(a))=h'(i(a)) \\\\\n    K_B & : \\prd{b:B}h(j(b))=h'(j(b))\n  \\end{align*}\n  and a homotopy $K_S$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      \\mathsf{tr}_P(H(s),h(i(f(s)))) \\arrow[r,equals,\"\\ap{\\mathsf{tr}_P(H(s))}{K_A(f(s))}\"] \\arrow[d,equals,swap,\"\\apd{h}{H(s)}\"] & \\mathsf{tr}_P(H(s),{h'(i(f(s)))}) \\arrow[d,equals,\"\\apd{h'}{H(s)}\"] \\\\\n      h(j(g(s))) \\arrow[r,equals,swap,\"K_B(g(s))\"] & h'(j(g(s)))\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes for every $s:S$. Note that from such an identification $K_S(s)$ we also obtain an identification\n  \\begin{equation*}\n    \\mathsf{K'_S(s)} : \\mathsf{tr}_{x\\mapsto h(x)=h'(x)}(H(s),K_A(f(s)))=K_B(g(s)).\n  \\end{equation*}\n  Indeed, by path inducgtion on $p:x=x'$ we obtain an identification $\\mathsf{tr}_{x\\mapsto h(x)=h'(x)}(p,q)=q'$, for any $p:x=x'$, any $q:h(x)=h'(x)$ and any $q':h(x')=h'(x')$ for which the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      \\mathsf{tr}_P(p,h(x)) \\arrow[r,equals,\"\\ap{\\mathsf{tr}_P(p)}{q}\"] \\arrow[d,equals,swap,\"\\apd{h}{p}\"] & \\mathsf{tr}_P(p,h'(x)) \\arrow[d,equals,\"\\apd{h'}{p}\"] \\\\\n      h(x') \\arrow[r,equals,swap,\"{q'}\"] & h'(x')\n    \\end{tikzcd}\n  \\end{equation*}\n  Now we see that the triple $(K_A,K_B,K'_S)$ forms a dependent cocone on the family $x\\mapsto h(x)=h'(x)$. Therefore we obtain a homotopy $h\\htpy h'$ as an application of the induction principle for pushouts at the family $x\\mapsto h(x)=h'(x)$.\n\\end{proof}\n\n\\subsection{Type families over pushouts}\n\nGiven a pushout square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$, and a family $P:X\\to\\UU$, we obtain\n\\begin{align*}\nP\\circ i & : A \\to \\UU \\\\\nP\\circ j & : B \\to \\UU \\\\\n\\lam{x}\\mathsf{tr}_P(H(x)) & : \\prd{x:S} \\eqv{P(i(f(x)))}{P(j(g(x)))}.\n\\end{align*}\nOur goal in the current section is to show that the triple $(P_A,P_B,P_S)$ consisting of $P_A\\defeq P\\circ i$, $P_B\\defeq P\\circ j$, and $P_S\\defeq \\lam{x}\\mathsf{tr}_P(H(x))$ characterizes the family $P$ over $X$.\n\n\\begin{defn}\nConsider a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$, where all types involved are in $\\UU$. The type $\\mathsf{Desc}(\\mathcal{S})$\\index{Desc@{$\\mathsf{Desc}(\\mathcal{S})$}|textbf} of \\define{descent data}\\index{descent data|textbf} for $X$, is defined defined to be the type of triples $(P_A,P_B,P_S)$ consisting of\n\\begin{align*}\nP_A & : A \\to \\UU \\\\\nP_B & : B \\to \\UU \\\\\nP_S & : \\prd{x:S} \\eqv{P_A(f(x))}{P_B(g(x))}.\n\\end{align*}\n\\end{defn}\n\n\\begin{defn}\nGiven a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$, we define the map\\index{desc_fam@{$\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}$}|textbf}\n\\begin{equation*}\n\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}(i,j,H) : (X\\to \\UU)\\to \\mathsf{Desc}(\\mathcal{S})\n\\end{equation*}\nby $P\\mapsto (P\\circ i,P\\circ j,\\lam{x}\\mathsf{tr}_P(H(x)))$.\n\\end{defn}\n\n\\begin{thm}\\label{thm:desc_fam}\nConsider a pushout square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$, where all types involved are in $\\UU$, and suppose we have\n\\begin{align*}\nP_A & : A \\to \\UU \\\\\nP_B & : B \\to \\UU \\\\\nP_S & : \\prd{x:S} \\eqv{P_A(f(x))}{P_B(g(x))}.\n\\end{align*}\nThen the function\\index{desc_fam@{$\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}$}!is an equivalence|textit}\n\\begin{equation*}\n\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}(i,j,H) : (X\\to \\UU)\\to \\mathsf{Desc}(\\mathcal{S})\n\\end{equation*}\nis an equivalence.\n\\end{thm}\n\n\\begin{proof}\nBy the 3-for-2 property of equivalences it suffices to construct an equivalence $\\varphi:\\mathsf{cocone}_{\\mathcal{S}}(\\UU)\\to\\mathsf{Desc}(\\mathcal{S})$ such that the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\n& \\UU^X \\arrow[dl,swap,\"{\\mathsf{cocone\\usc{}map}_{\\mathcal{S}}(i,j,H)}\"] \\arrow[dr,\"{\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}(i,j,H)}\"] & \\phantom{\\mathsf{cocone}_{\\mathcal{S}}(\\UU)} \\\\\n\\mathsf{cocone}_{\\mathcal{S}}(\\UU) \\arrow[rr,densely dotted,\"\\eqvsym\",\"\\varphi\"'] & & \\mathsf{Desc}(\\mathcal{S})\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\nSince we have equivalences\n\\begin{equation*}\n\\mathsf{equiv\\usc{}eq}:\\eqv{\\Big(P_A(f(x))=P_B(g(x))\\Big)}{\\Big(\\eqv{P_A(f(x))}{P_B(g(x))}\\Big)}\n\\end{equation*}\nfor all $x:S$, we obtain by \\cref{ex:equiv_pi} an equivalence on the dependent products\n\\begin{equation*}\n{\\Big(\\prd{x:S}P_A(f(x))=P_B(g(x))\\Big)}\\to{\\Big(\\prd{x:S}\\eqv{P_A(f(x))}{P_B(g(x))}\\Big)}.\n\\end{equation*}\nWe define $\\varphi$ to be the induced map on total spaces. Explicitly, we have\n\\begin{equation*}\n\\varphi\\defeq \\lam{(P_A,P_B,K)}(P_A,P_B,\\lam{x}\\mathsf{equiv\\usc{}eq}(K(x))).\n\\end{equation*}\nThen $\\varphi$ is an equivalence by \\cref{thm:fib_equiv}, and the triangle commutes by \\cref{ex:tr_ap}.\n\\end{proof}\n\n\\begin{cor}\\label{cor:desc_fam}\nConsider descent data $(P_A,P_B,P_S)$ for a pushout square as in \\cref{thm:desc_fam}.\nThen the type of quadruples $(P,e_A,e_B,e_S)$ consisting of a family $P:X\\to\\UU$ equipped with two families of equivalences\n\\begin{samepage}\n\\begin{align*}\ne_A & : \\prd{a:A}\\eqv{P_A(a)}{P(i(a))} \\\\\ne_B & : \\prd{b:B}\\eqv{P_B(a)}{P(j(b))}\n\\end{align*}\n\\end{samepage}%\nand a homotopy $e_S$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nP_A(f(x)) \\arrow[r,\"e_A(f(x))\"] \\arrow[d,swap,\"P_S(x)\"] & P(i(f(x))) \\arrow[d,\"\\mathsf{tr}_P(H(x))\"] \\\\\nP_B(g(x)) \\arrow[r,swap,\"e_B(g(x))\"] & P(j(g(x)))\n\\end{tikzcd}\n\\end{equation*}\ncommutes, is contractible.\n\\end{cor}\n\n\\begin{proof}\nThe fiber of this map at $(P_A,P_B,P_S)$ is equivalent to the type of quadruples $(P,e_A,e_B,e_S)$ as described in the theorem, which are contractible by \\cref{thm:contr_equiv}.\n\\end{proof}\n\n\\subsection{The flattening lemma for pushouts}\n\nIn this section we consider a pushout square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$, descent data\n\\begin{align*}\nP_A & : A \\to \\UU \\\\\nP_B & : B \\to \\UU \\\\\nP_S & : \\prd{x:S} \\eqv{P_A(f(x))}{P_B(g(x))},\n\\end{align*}\nand a family $P:X\\to\\UU$ equipped with \n\\begin{align*}\ne_A & : \\prd{a:A}\\eqv{P_A(a)}{P(i(a))} \\\\\ne_B & : \\prd{b:B}\\eqv{P_B(a)}{P(j(b))}\n\\end{align*}\nand a homotopy $e_S$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nP_A(f(x)) \\arrow[r,\"e_A(f(x))\"] \\arrow[d,swap,\"P_S(x)\"] & P(i(f(x))) \\arrow[d,\"\\mathsf{tr}_P(H(x))\"] \\\\\nP_B(g(x)) \\arrow[r,swap,\"e_B(g(x))\"] & P(j(g(x)))\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\n\n\\begin{defn}\nWe define a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{x:S}P_A(f(x)) \\arrow[d,swap,\"{f'}\"] \\arrow[r,\"{g'}\"] & \\sm{b:B}P_B(b) \\arrow[d,\"{j'}\"] \\\\\n\\sm{a:A}P_A(a) \\arrow[r,swap,\"{i'}\"] & \\sm{x:X}P(x)\n\\end{tikzcd}\n\\end{equation*}\nwith a homotopy $H':i'\\circ f'\\htpy j'\\circ g'$. We will write $\\mathcal{S'}$ for the span\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{a:A}P_A(a) & \\sm{x:S}P_A(f(x)) \\arrow[l,swap,\"{f'}\"] \\arrow[r,\"{g'}\"] & \\sm{b:B}P_B(b).\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nWe define\n\\begin{align*}\nf' & \\defeq \\total[f]{\\lam{x}\\idfunc[P_A(f(x))]} \\\\\ng' & \\defeq \\total[g]{e_S} \\\\\ni' & \\defeq \\total[i]{e_A} \\\\\nj' & \\defeq \\total[j]{e_B}.\n\\end{align*}\nThen it remains to construct a homotopy $H':i'\\circ f'\\htpy j'\\circ g'$. In order to construct this homotopy, we have to construct an identification\n\\begin{equation*}\n(i(f(x)),e_A(y))=(j(g(x)),e_B(e_S(y)))\n\\end{equation*}\nfor any $x:S$ and $y:P_A(f(x))$. Note that have the identification\n\\begin{equation*}\n\\mathsf{eq\\usc{}pair}(H(x),e_S(x,y)^{-1})\n\\end{equation*}\nof this type.\n\\end{constr}\n\n\\begin{lem}[The flattening lemma]\\label{lem:flattening}\nThe commuting square\\index{flattening lemma!for pushouts|textit}\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{x:S}P_A(f(x)) \\arrow[d,swap,\"{f'}\"] \\arrow[r,\"{g'}\"] & \\sm{b:B}P_B(b) \\arrow[d,\"{j'}\"] \\\\\n\\sm{a:A}P_A(a) \\arrow[r,swap,\"{i'}\"] & \\sm{x:X}P(x)\n\\end{tikzcd}\n\\end{equation*}\nis a pushout square.\n\\end{lem}\n\n\\begin{proof}\n  To show that the square of total spaces satisfies the pullback property of pullbacks, note that we have a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & T^{\\sm{x:X}P(x)} \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      T^{\\sm{a:A}P_A(a)} \\arrow[d] & \\prd{x:X}T^{P(x)} \\arrow[dl] \\arrow[dr] & T^{\\sm{b:B}P_B(b)} \\arrow[dl,crossing over] \\arrow[d] \\\\\n      \\prd{a:A}T^{P_A(a)} \\arrow[dr] & T^{\\sm{x:S}P_A(f(x))} \\arrow[from=ul,crossing over] \\arrow[d] & \\prd{b:B}T^{P_B(b)} \\arrow[dl] \\\\\n      & \\prd{x:S}T^{P_A(f(x))}\n    \\end{tikzcd}\n  \\end{equation*}\n  for any type $T$. In this cube, the vertical maps are all equivalences, and the bottom square is a pullback square by the dependent pullback property of pushouts. Therefore it follows that the top square is a pullback square.\n\\end{proof}\n\n\\subsection{The universality theorem}\n\\begin{thm}\n  Consider two pushout squares\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S' \\arrow[r] \\arrow[d] & B' \\arrow[d] & S \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\n      A' \\arrow[r] & C' & A \\arrow[r] & C\n    \\end{tikzcd}\n  \\end{equation*}\n  and a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & S' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      A' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[d] \\arrow[dl,crossing over] \\\\\n      A \\arrow[dr] & D' \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n      & D\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the back left and right squares are pullback squares. The following are equivalent:\n  \\begin{enumerate}\n  \\item The front left and right squares are pullback squares.\n  \\item The induced commuting square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        C' \\arrow[r,densely dotted] \\arrow[d,densely dotted] & D' \\arrow[d] \\\\\n        C \\arrow[r,densely dotted] & D\n      \\end{tikzcd}\n    \\end{equation*}\n    is a pullback square.\n  \\end{enumerate}\n\\end{thm}\n\n\n\\subsection{The descent property for pushouts}\n\nIn the previous section there was a significant role for families of equivalences, and we know by \\cref{thm:pb_fibequiv,cor:pb_fibequiv}: families of equivalences indicate the presence of pullbacks. In this section we reformulate the results of the previous section using pullbacks where we used families of equivalences before, to obtain new and useful results. We begin by considering the type of descent data from the perspective of pullback squares.\n\n\\begin{defn}\nConsider a span $\\mathcal{S}$ from $A$ to $B$, and a span $\\mathcal{S}'$ from $A'$ to $B'$. A \\define{cartesian transformation} of spans\\index{cartesian transformation!of spans|textbf} from $\\mathcal{S}'$ to $\\mathcal{S}$ is a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA' \\arrow[d,swap,\"h_A\"]  & S' \\arrow[l,swap,\"{f'}\"] \\arrow[r,\"{g'}\"] \\arrow[d,swap,\"h_S\"] & B' \\arrow[d,\"h_B\"] \\\\\nA & S \\arrow[l,\"f\"] \\arrow[r,swap,\"g\"] & B\n\\end{tikzcd}\n\\end{equation*}\nwith $F:f\\circ h_S\\htpy h_A\\circ f'$ and $G:g\\circ h_S\\htpy h_B\\circ g'$, where both squares are pullback squares. \n\nThe type $\\mathsf{cart}(\\mathcal{S}',\\mathcal{S})$\\index{cart(S,S')@{$\\mathsf{cart}(\\mathcal{S},\\mathcal{S}')$}|textbf} of cartesian transformation is the type of tuples\n\\begin{equation*}\n(h_A,h_S,h_B,F,G,p_f,p_g)\n\\end{equation*}\nwhere $p_f:\\mathsf{is\\usc{}pullback}(h_S,h_A,F)$ and $p_g:\\mathsf{is\\usc{}pullback}(h_S,h_B,G)$, and we write\n\\begin{equation*}\n\\mathsf{Cart}(\\mathcal{S}) \\defeq \\sm{A',B':\\UU}{\\mathcal{S}':\\mathsf{span}(A',B')}\\mathsf{cart}(\\mathcal{S}',\\mathcal{S}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{lem}\\label{lem:cart_desc}\nThere is an equivalence\\index{cart_desc@{$\\mathsf{cart\\usc{}desc}_{\\mathcal{S}}$}|textit}\n\\begin{equation*}\n\\mathsf{cart\\usc{}desc}_{\\mathcal{S}}:\\mathsf{Desc}(\\mathcal{S})\\to \\mathsf{Cart}(\\mathcal{S}).\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nNote that by \\cref{thm:pb_fibequiv_complete} it follows that the types of triples $(f',F,p_f)$ and $(g',G,p_g)$ are equivalent to the types of families of equivalences\n\\begin{align*}\n& \\prd{x:S}\\eqv{\\fib{h_S}{x}}{\\fib{h_A}{f(x)}} \\\\\n& \\prd{x:S}\\eqv{\\fib{h_S}{x}}{\\fib{h_B}{g(x)}}\n\\end{align*} \nrespectively. Furthermore, by \\cref{thm:fam_proj} the types of pairs $(S',h_S)$, $(A',h_A)$, and $(B',h_B)$ are equivalent to the types $S\\to \\UU$, $A\\to \\UU$, and $B\\to \\UU$, respectively. Therefore it follows that the type $\\mathsf{Cart}(\\mathcal{S})$ is equivalent to the type of tuples $(Q,P_A,\\varphi,P_B,P_S)$ consisting of\n\\begin{align*}\nQ & : S\\to \\UU \\\\\nP_A & : A \\to \\UU \\\\\nP_B & : B \\to \\UU \\\\\n\\varphi & : \\prd{x:S}\\eqv{Q(x)}{P_A(f(x))} \\\\\nP_S & : \\prd{x:S}\\eqv{Q(x)}{P_B(g(x))}.\n\\end{align*}\nHowever, the type of $\\varphi$ is equivalent to the type $P_A\\circ f=Q$. Thus we see that the type of pairs $(Q,\\varphi)$ is contractible, so our claim follows.\n\\end{proof}\n\n\\begin{defn}\nWe define an operation\\index{cart map!{$\\mathsf{cart\\usc{}map}_{\\mathcal{S}}$}|textbf}\n\\begin{equation*}\n\\mathsf{cart\\usc{}map}_{\\mathcal{S}}:{\\Big(\\sm{X':\\UU}X'\\to X\\Big)}\\to \\mathsf{Cart}(\\mathcal{S}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nLet $X':\\UU$ and $h_X:X'\\to X$. Then we define the types\n\\begin{align*}\nA' & \\defeq A\\times_X X' \\\\\nB' & \\defeq B\\times_X X'.\n\\end{align*}\nNext, we define a span $\\mathcal{S'}\\defeq(S',f',g')$ from $A'$ to $B'$. We take\n\\begin{align*}\nS' & \\defeq S\\times_A A' \\\\\nf' & \\defeq \\pi_2.\n\\end{align*}\nTo define $g'$, let $s:S$, let $(a,x',p):A\\times_X X'$, and let $q:f(s)=a$. Our goal is to construct a term of type $B\\times_X X'$. We have $g(s):B$ and $x':X'$, so it remains to show that $j(g(s))=h_X(x')$. We construct such an identification as a concatenation\n\\begin{equation*}\n\\begin{tikzcd}\nj(g(s)) \\arrow[r,equals,\"H(s)^{-1}\"] &[1ex] i(f(s)) \\arrow[r,equals,\"\\ap{i}{q}\"] &[1ex] i(a) \\arrow[r,equals,\"p\"] & h_X(x').\n\\end{tikzcd}\n\\end{equation*}\nTo summarize, the map $g'$ is defined as\n\\begin{equation*}\ng' \\defeq \\lam{(s,(a,x',p),q)}(g(s),x',\\ct{H(s)^{-1}}{(\\ct{\\ap{i}{q}}{p})}).\n\\end{equation*}\nThen we have commuting squares\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times_X X' \\arrow[d] & S\\times_A A' \\arrow[d] \\arrow[l] \\arrow[r] & B\\times_X X' \\arrow[d] \\\\\nA & S \\arrow[l] \\arrow[r] & B.\n\\end{tikzcd}\n\\end{equation*}\nMoreover, these squares are pullback squares by \\cref{thm:pb_pasting}.\n\\end{constr}\n\nThe following theorem is analogous to \\cref{thm:desc_fam}.\n\n\\begin{thm}[The descent theorem for pushouts]\\label{thm:cart_map}\\index{descent theorem!for pushouts|textit}\nThe operation $\\mathsf{cart\\usc{}map}_{\\mathcal{S}}$\\index{cart map!{$\\mathsf{cart\\usc{}map}_{\\mathcal{S}}$}!is an equivalence|textit} is an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{X':\\UU}X'\\to X\\Big)}{\\mathsf{Cart}(\\mathcal{S})}\n\\end{equation*}\n\\end{thm}\n\n\\begin{proof}\nIt suffices to show that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nX\\to \\UU \\arrow[r,\"{\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}(i,j,H)}\"] \\arrow[d,swap,\"\\mathsf{map\\usc{}fam}_X\"] & \\mathsf{Desc}(\\mathcal{S}) \\arrow[d,\"\\mathsf{cart\\usc{}desc}_{\\mathcal{S}}\"] \\\\\n\\sm{X':\\UU}X'\\to X \\arrow[r,swap,\"\\mathsf{cart\\usc{}map}_{\\mathcal{S}}\"] & \\mathsf{Cart}(\\mathcal{S})\n\\end{tikzcd}\n\\end{equation*}\ncommutes. To see that this suffices, note that the operation $\\mathsf{map\\usc{}fam}_X$ is an equivalence by \\cref{thm:fam_proj}, the operation $\\mathsf{desc\\usc{}fam}_{\\mathcal{S}}(i,j,H)$ is an equivalence by \\cref{thm:desc_fam}, and the operation $\\mathsf{cart\\usc{}desc}_{\\mathcal{S}}$ is an equivalence by \\cref{lem:cart_desc}.\n\nTo see that the square commutes, note that the composite\n\\begin{equation*}\n\\mathsf{cart\\usc{}map}_{\\mathcal{S}}\\circ \\mathsf{map\\usc{}fam}_X\n\\end{equation*}\ntakes a family $P:X\\to \\UU$ to the cartesian transformation of spans\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times_X\\tilde{P} \\arrow[d,swap,\"\\pi_1\"] & S\\times_A\\Big(A\\times_X\\tilde{P}\\Big) \\arrow[l] \\arrow[r] \\arrow[d,swap,\"\\pi_1\"] & B\\times_X\\tilde{P} \\arrow[d,\"\\pi_1\"] \\\\\nA & S \\arrow[l] \\arrow[r] & B,\n\\end{tikzcd}\n\\end{equation*}\nwhere $\\tilde{P}\\defeq\\sm{x:X}P(x)$.\n\nThe composite \n\\begin{equation*}\n\\mathsf{cart\\usc{}desc}_{\\mathcal{S}}\\circ \\mathsf{desc\\usc{}fam}_X\n\\end{equation*}\ntakes a family $P:X\\to \\UU$ to the cartesian transformation of spans\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{a:A}P(i(a)) \\arrow[d] & \\sm{s:S}P(i(f(s))) \\arrow[l] \\arrow[r] \\arrow[d] & \\sm{b:B}P(j(b)) \\arrow[d] \\\\\nA & S \\arrow[l] \\arrow[r] & B\n\\end{tikzcd}\n\\end{equation*}\nThese cartesian natural transformations are equal by \\cref{lem:pb_subst}\n\\end{proof}\n\nSince $\\mathsf{cart\\usc{}map}_{\\mathcal{S}}$ is an equivalence it follows that its fibers are contractible. This is essentially the content of the following corollary.\n\n\\begin{cor}\nConsider a diagram of the form \n\\begin{equation*}\n\\begin{tikzcd}\n& S' \\arrow[d,swap,\"h_S\"] \\arrow[dl,swap,\"{f'}\"] \\arrow[dr,\"{g'}\"] \\\\\nA' \\arrow[d,swap,\"h_A\"] & S \\arrow[dl,swap,\"f\"] \\arrow[dr,\"g\"] & B' \\arrow[d,\"{h_B}\"] \\\\\nA \\arrow[dr,swap,\"i\"] & & B \\arrow[dl,\"j\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies\n\\begin{align*}\nF & : f\\circ h_S \\htpy h_A\\circ f' \\\\\nG & : g\\circ h_S \\htpy h_B\\circ g' \\\\\nH & : i\\circ f \\htpy j\\circ g,\n\\end{align*}\nand suppose that the bottom square is a pushout square, and the top squares are pullback squares.\nThen the type of tuples $((X',h_X),(i',I,p),(j',J,q),(H',C))$ consisting of\n\\begin{enumerate}\n\\item A type $X':\\UU$ together with a morphism\n\\begin{equation*}\nh_X : X'\\to X,\n\\end{equation*}\n\\item A map $i':A'\\to X'$, a homotopy $I:i\\circ h_A\\htpy h_X\\circ i'$, and a term $p$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nA' \\arrow[d,swap,\"h_A\"] \\arrow[r,\"{i'}\"] & X' \\arrow[d,\"h_X\"] \\\\\nA \\arrow[r,swap,\"i\"] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item A map $j':B'\\to X'$, a homotopy $J:j\\circ h_B\\htpy h_X\\circ j'$, and a term $q$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nB' \\arrow[d,swap,\"h_B\"] \\arrow[r,\"{j'}\"] & X' \\arrow[d,\"h_X\"] \\\\\nB \\arrow[r,swap,\"j\"] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square,\n\\item A homotopy $H':i'\\circ f'\\htpy j'\\circ g'$, and a homotopy\n\\begin{equation*}\nC : \\ct{(i\\cdot F)}{(\\ct{(I\\cdot f')}{(h_X\\cdot H')})} \\htpy \\ct{(H\\cdot h_S)}{(\\ct{(j\\cdot G)}{(J\\cdot g')})}\n\\end{equation*}\nwitnessing that the cube\n\\begin{equation*}\n\\begin{tikzcd}\n& S' \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\nA' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\nA \\arrow[dr] & X' \\arrow[d] \\arrow[from=ul,crossing over] & B \\arrow[dl] \\\\\n& X,\n\\end{tikzcd}\n\\end{equation*}\ncommutes,\n\\end{enumerate}\nis contractible.\n\\end{cor}\n\nThe following theorem should be compared to the flattening lemma, \\cref{lem:flattening}.\\index{flattening lemma!for pushouts}\n\n\\begin{thm}\nConsider a commuting cube\n\\begin{equation*}\n\\begin{tikzcd}\n& S' \\arrow[dl,swap,\"{f'}\"] \\arrow[dr,\"{g'}\"] \\arrow[d,\"h_S\"] \\\\\nA' \\arrow[d,swap,\"h_A\"] & S \\arrow[dl,swap,\"f\" near start] \\arrow[dr,\"g\" near start] & B' \\arrow[dl,crossing over,\"{j'}\" near end] \\arrow[d,\"h_B\"] \\\\\nA \\arrow[dr,swap,\"i\"] & X' \\arrow[d,\"h_X\" near start] \\arrow[from=ul,crossing over,\"{i'}\"' near end] & B \\arrow[dl,\"j\"] \\\\\n& X.\n\\end{tikzcd}\n\\end{equation*}\nIf each of the vertical squares is a pullback, and the bottom square  is a pushout, then the top square is a pushout.\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{cor:pb_fibequiv} we have families of equivalences\n\\begin{align*}\nF & : \\prd{x:S}\\eqv{\\fib{h_S}{x}}{\\fib{h_A}{f(x)}} \\\\\nG & : \\prd{x:S}\\eqv{\\fib{h_S}{x}}{\\fib{h_B}{g(x)}} \\\\\nI & : \\prd{a:A}\\eqv{\\fib{h_A}{a}}{\\fib{h_X}{i(a)}} \\\\\nJ & : \\prd{b:B}\\eqv{\\fib{h_B}{b}}{\\fib{h_X}{j(b)}}. \n\\end{align*}\nMoreover, since the cube commutes we obtain a family of homotopies\n\\begin{equation*}\nK : \\prd{x:S} I(f(x))\\circ F(x) \\htpy J(g(x))\\circ G(x).\n\\end{equation*}\nWe define the descent data $(P_A,P_B,P_S)$ consisting of $P_A:A\\to\\UU$, $P_B:B\\to\\UU$, and $P_S:\\prd{x:S}\\eqv{P_A(f(x))}{P_B(g(x))}$ by\n\\begin{align*}\nP_A(a) & \\defeq \\fib{h_A}{a} \\\\\nP_B(b) & \\defeq \\fib{h_B}{b} \\\\\nP_S(x) & \\defeq G(x)\\circ F(x)^{-1}.\n\\end{align*}\nWe have\n\\begin{align*}\nP & \\defeq \\fibf{h_X} \\\\\ne_A & \\defeq I \\\\\ne_B & \\defeq J \\\\\ne_S & \\defeq K.\n\\end{align*}\nNow consider the diagram\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{s:S}\\fib{h_S}{s} \\arrow[r] \\arrow[d] & \\sm{s:S}\\fib{h_A}{f(s)} \\arrow[r] \\arrow[d] & \\sm{b:B}\\fib{h_B}{b} \\arrow[d] \\\\\n\\sm{a:A}\\fib{h_A}{a} \\arrow[r] & \\sm{a:A}\\fib{h_A}{a} \\arrow[r] & \\sm{x:X}\\fib{h_X}{x}\n\\end{tikzcd}\n\\end{equation*}\nSince the top and bottom map in the left square are equivalences, we obtain from \\cref{ex:pushout_equiv} that the left square is a pushout square. Moreover, the right square is a pushout by \\cref{lem:flattening}. Therefore it follows by \\cref{thm:pushout_pasting} that the outer rectangle is a pushout square.\n\nNow consider the commuting cube\n\\begin{equation*}\n\\begin{tikzcd}\n& \\sm{s:S}\\fib{h_S}{s} \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\n\\sm{a:A}\\fib{h_A}{a} \\arrow[d] & S' \\arrow[dl] \\arrow[dr] & \\sm{b:B}\\fib{h_B}{b} \\arrow[dl,crossing over] \\arrow[d] \\\\\nA' \\arrow[dr,swap] & \\sm{x:X}\\fib{h_X}{x} \\arrow[d] \\arrow[from=ul,crossing over] & B' \\arrow[dl] \\\\\n& X'.\n\\end{tikzcd}\n\\end{equation*}\nWe have seen that the top square is a pushout. The vertical maps are all equivalences, so the vertical squares are all pushout squares. Thus it follows from one more application of \\cref{thm:pushout_pasting} that the bottom square is a pushout.\n\\end{proof}\n\n%\\begin{cor}\n%For any map $f:A\\sqcup^S B\\to X$, and any $x:X$, the square\n%\\begin{equation*}\n%\\begin{tikzcd}\n%\\fib{f_S}{x} \\arrow[r] \\arrow[d] & \\fib{f_B}{x} \\arrow[d] \\\\\n%\\fib{f_A}{x} \\arrow[r] & \\fib{f}{x}\n%\\end{tikzcd}\n%\\end{equation*}\n%is a pushout square.\n%\\end{cor}\n\n\\begin{thm}\nConsider a commuting cube of types \n\\begin{equation*}\\label{eq:cube}\n\\begin{tikzcd}\n& S' \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\nA' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\nA \\arrow[dr] & X' \\arrow[d] \\arrow[from=ul,crossing over] & B \\arrow[dl] \\\\\n& X,\n\\end{tikzcd}\n\\end{equation*}\nand suppose the vertical squares are pullback squares. Then the commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA' \\sqcup^{S'} B' \\arrow[r] \\arrow[d] & X' \\arrow[d] \\\\\nA\\sqcup^{S} B \\arrow[r] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\end{thm}\n\n\\begin{proof}\nIt suffices to show that the pullback \n\\begin{equation*}\n(A\\sqcup^{S} B)\\times_{X}X'\n\\end{equation*}\nhas the universal property of the pushout. This follows by the descent theorem, since the vertical squares in the cube\n\\begin{equation*}\n\\begin{tikzcd}\n& S' \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\nA' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\nA \\arrow[dr] & (A\\sqcup^{S} B)\\times_{X}X' \\arrow[d] \\arrow[from=ul,crossing over] & B \\arrow[dl] \\\\\n& A\\sqcup^{S} B\n\\end{tikzcd}\n\\end{equation*}\nare pullback squares by \\cref{thm:pb_pasting}.\n\\end{proof}\n\n\\subsection{Applications of the descent theorem}\n\n\\begin{thm}\n  Consider a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & S' \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\n      A' \\arrow[d] & S \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\n      A \\arrow[dr] & C' \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n      & C\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the bottom square is a pushout square. If the vertical sides are pullback squares, then for each $c:C$ the square of fibers\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\fib{i\\circ f\\circ h_S}{c} \\arrow[d] \\arrow[r] & \\fib{j\\circ g\\circ h_S}{c} \\arrow[r] & \\fib{j\\circ h_B}{c} \\arrow[d] \\\\\n      \\fib{i\\circ h_A}{c} \\arrow[rr] & & \\fib{h_C}{c}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pushout square.\n\\end{thm}\n\n\\begin{exercises}\n\\item Use the characterization of the circle\\index{circle} as a pushout given in \\cref{eg:circle_pushout} to show that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n\\sphere{1}+\\sphere{1} \\arrow[r,\"{[\\idfunc,\\idfunc]}\"] \\arrow[d,swap,\"{[\\idfunc,\\idfunc]}\"] & \\sphere{1} \\arrow[d,\"{\\lam{t}(t,\\base)}\"] \\\\\n\\sphere{1} \\arrow[r,swap,\"{\\lam{t}(t,\\base)}\"] & \\sphere{1}\\times\\sphere{1}\n\\end{tikzcd}\n\\end{equation*}\nis a pushout square.\n\\item Let $f:A\\to B$ be a map. The \\define{codiagonal}\\index{codiagonal}\\index{nabla@{$\\nabla_f$}} $\\nabla_f$ of $f$ is the map obtained from the universal property of the pushout, as indicated in the diagram\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r,\"f\"] \\arrow[dr, phantom, \"\\ulcorner\", very near end] & B \\arrow[d,\"\\inr\"] \\arrow[ddr,bend left=15,\"{\\idfunc[B]}\"] \\\\\nA \\arrow[r,\"\\inl\"] \\arrow[drr,bend right=15,swap,\"{\\idfunc[B]}\"] & B\\sqcup^{A} B \\arrow[dr,densely dotted,near start,swap,\"\\nabla_f\"] \\\\\n& & B\n\\end{tikzcd}\n\\end{equation*}\nShow that $\\fib{\\nabla_f}{b}\\eqvsym \\susp(\\fib{f}{b})$ for any $b:B$.\n\\item \\label{ex:fib_join}Consider two maps $f:A\\to X$ and $g:B\\to X$. The \\define{fiberwise join}\\index{fiberwise join} $\\join{f}{g}$ is defined by the universal property of the pushout as the unique map rendering the diagram\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times_X B \\arrow[d,\"\\pi_1\"] \\arrow[r,\"\\pi_2\"] \\arrow[dr, phantom, \"\\ulcorner\", very near end] & B \\arrow[d,\"\\inr\"] \\arrow[ddr,bend left=15,\"g\"] \\\\\nA \\arrow[r,\"\\inl\"] \\arrow[drr,bend right=15,swap,\"f\"] & \\join[X]{A}{B} \\arrow[dr,densely dotted,near start,swap,\"\\join{f}{g}\"] \\\\\n& & X\n\\end{tikzcd}\n\\end{equation*}\ncommutative, where $\\join[X]{A}{B}$ is defined as a pushout, as indicated.\nConstruct an equivalence\n\\begin{equation*}\n\\eqv{\\fib{\\join{f}{g}}{x}}{\\join{\\fib{f}{x}}{\\fib{g}{x}}}\n\\end{equation*}\nfor any $x:X$. \n\\item Consider two maps $f:A\\to B$ and $g:C\\to D$.\nThe \\define{pushout-product}\\index{pushout-product}\n\\begin{equation*}\nf\\square g : (A\\times D)\\sqcup^{A\\times C} (B\\times C)\\to B\\times D\n\\end{equation*}\nof $f$ and $g$ is defined by the universal property of the pushout as the unique map rendering the diagram\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times C \\arrow[r,\"{f\\times \\idfunc[C]}\"] \\arrow[d,swap,\"{\\idfunc[A]\\times g}\"] & B\\times C \\arrow[d,\"\\inr\"] \\arrow[ddr,bend left=15,\"{\\idfunc[B]\\times g}\"] \\\\\nA\\times D \\arrow[r,\"\\inl\"] \\arrow[drr,bend right=15,swap,\"{f\\times\\idfunc[D]}\"] & (A\\times D)\\sqcup^{A\\times C} (B\\times C) \\arrow[dr,densely dotted,swap,near start,\"f\\square g\"] \\\\\n& & B\\times D\n\\end{tikzcd}\n\\end{equation*}\ncommutative. Construct an equivalence\n\\begin{equation*}\n\\eqv{\\fib{f\\square g}{b,d}}{\\join{\\fib{f}{b}}{\\fib{g}{d}}}\n\\end{equation*}\nfor all $b:B$ and $d:D$.\n\\item Let $A$ and $B$ be pointed types with base points $a_0:A$ and $b_0:B$. The \\define{wedge inclusion}\\index{wedge inclusion} is defined as follows by the universal property of the wedge:\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\n\\unit \\arrow[r] \\arrow[d] & B \\arrow[d,\"\\inr\"] \\arrow[ddr,bend left=15,\"{\\lam{b}(a_0,b)}\"] \\\\\nA \\arrow[r,\"\\inl\"] \\arrow[drr,bend right=15,swap,\"{\\lam{a}(a,b_0)}\"] & A\\vee B \\arrow[dr,densely dotted,swap,\"{\\mathsf{wedge\\usc{}in}_{A,B}}\"{near start,xshift=1ex}] \\\\\n& & A\\times B\n\\end{tikzcd}\n\\end{equation*}\nShow that the fiber of the wedge inclusion $A\\vee B\\to A\\times B$ is equivalent to $\\join{\\loopspace{B}}{\\loopspace{A}}$.\n\\item Let $f:X\\vee X\\to X$ be the map defined by the universal property of the wedge as indicated in the diagram\n\\begin{equation*}\n\\begin{tikzcd}\n\\unit \\arrow[d,swap,\"x_0\"] \\arrow[r,\"x_0\"] \\arrow[dr, phantom, \"\\ulcorner\", very near end] & X \\arrow[d,\"\\inr\"] \\arrow[ddr,bend left=15,\"{\\idfunc[X]}\"] \\\\\nX \\arrow[r,\"\\inl\"] \\arrow[drr,bend right=15,swap,\"{\\idfunc[X]}\"] & X\\vee X \\arrow[dr,densely dotted,near start,swap,\"f\"] \\\\\n& & X.\n\\end{tikzcd}\n\\end{equation*}\n\\begin{subexenum}\n\\item Show that $\\eqv{\\fib{f}{x_0}}{\\susp\\loopspace{X}}$. \n\\item Show that $\\eqv{\\mathsf{cof}_f}{\\susp X}$.\n\\end{subexenum}\n\\item Consider a pushout square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X,\n\\end{tikzcd}\n\\end{equation*}\nand suppose that $f$ is an embedding. Show that $j$ is an embedding, and that the square is also a pullback square.\n\\end{exercises}\n", "meta": {"hexsha": "cf4a7cb6dc4c89bfe876107b4872033ff9975aaf", "size": 42462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/descent.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/descent.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/descent.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": 47.3377926421, "max_line_length": 488, "alphanum_fraction": 0.6580471951, "num_tokens": 15910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6233233069313197}}
{"text": "\\subsection{Calculating Vertical Velocities}\n\n\\subsubsection{Grid Velocity}\nThe vertical grid moves as a consequence of using a $\\sigma$--coordinate system. The grid velocity is\n\\begin{equation}\n  \\label{kin.eq.grid_velo}\n  w^{\\text{grid}}(\\sigma)=\\frac{\\pd s}{\\pd t}+\\vec u\\cdot\\vec\\nabla s-\\sigma\\left(\\frac{\\pd H}{\\pd t}+\\vec u\\cdot\\vec\\nabla H\\right)\n\\end{equation}\nThe numerical implementation of Equation \\eqref{kin.eq.grid_velo} is straight--forward.\n\n\\subsubsection{Vertical Velocity}\nThe discretised version of the vertical velocity equation \\eqref{kin.eq.vert_velo_scaled} is slightly more compilicated because the horizontal velocities are calculated on the $(r,s)$ grid. The vertical velocity at the ice base is $w_{i,j,N}=w^{\\text{grid}}_{i,j,N}-b_{i,j}$, where $b_{i,j}$ is the basal melt rate. Integrating from the bottom, the vertical velocity is then\n\\begin{equation}\n  \\label{kin.eq.wvel_unc}\n  \\begin{split}\n  w_{i,j,k}=-\\sum_{\\tilde{k}=N-1}^1\\left\\{\\mathcal{H}_{i,j}\\left(\\frac{u^x_{i,j,k}+u^x_{i,j,k+1}}{2}+\\frac{v^y_{i,j,k}+v^y_{i,j,k+1}}{2}\\right)(\\sigma_{k+1}-\\sigma_k)\\right. \\\\\n     +(\\tilde{u}_{i,j,k+1}-\\tilde{u}_{i,j,k})  \\left(\\tilde{s}^x_{i,j}-\\frac12(\\sigma_{k+1}+\\sigma_k)\\tilde{H}^x_{i,j}\\right)  \\\\\n     \\left.+(\\tilde{v}_{i,j,k+1}-\\tilde{v}_{i,j,k})  \\left(\\tilde{s}^y_{i,j}-\\frac12(\\sigma_{k+1}+\\sigma_k)\\tilde{H}^y_{i,j}\\right)\\right\\} + w_{i,j,N}\n  \\end{split}\n\\end{equation}\nwith the weighted ice thickness\n\\begin{equation*}\n  \\begin{split}\n  \\mathcal{H}_{i,j}=\\frac{4H_{i,j}+2(H_{i-1,j}+H_{i+1,j}+H_{i,j-1}+H_{i,j+1})}{16}\\\\\n  +\\frac{H_{i-1,j-1}+H_{i+1,j-1}+H_{i+1,j+1}+H_{i-1,j+1}}{16}    \n  \\end{split}\n\\end{equation*}\n\nThis scheme produces vertical velocities at the ice divide which are too small. The vertical velocities on the ice surface are given by the upper kinematic boundary condition, Equation \\eqref{kin.eq.upper_bc}. Equation \\eqref{kin.eq.wvel_unc} can be corrected with:\n\\begin{equation}\n  \\label{kin.eq.wvel_cor}\n   w^\\ast_{i,j,k}=w_{i,j,k}-(1-\\sigma_k)(w_{i,j,k}-{w_s}_{i,j}),\n\\end{equation}\nwhere ${w_s}_{i,j}$ is the vertical velocity at the ice surface given by \\eqref{kin.eq.upper_bc}. Figure \\ref{kin.fig.w_profile} shows the different vertical velocities at the ice surface.\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics{\\dir/gnu/w_profile.eps}\n  \\caption{Vertical ice surface velocities of the EISMINT-1 moving margin experiment.}\n  \\label{kin.fig.w_profile}\n\\end{figure}\nThe difference between the vertical velocities calculated by the model and the vertical velocities given by \\eqref{kin.eq.upper_bc} at the ice margin are due to the fact that temperatures and velocities are only calculated when the ice is thicker than a certain threshold value which is not met at the ice margin.\n\nFigure \\ref{kin.fig.wt_sigma} shows vertical profiles of the vertical velocity at the ice divide and a point half--way between the divide and the domain margin. A corresponding temperature profile is also shown since the vertical velocity determines the vertical temperature advection (see Section \\ref{temp.sec.vert_ad}).\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics{\\dir/gnu/wt_sigma.eps}\n  \\caption{Vertical velocity and temperature distribution for columns at the ice divide and a point half--way between the divide and the domain margin.}\n  \\label{kin.fig.wt_sigma}\n\\end{figure}\n", "meta": {"hexsha": "a3776ae555c252986c7b62cbad3ba4a853a41589", "size": 3353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "models/glc/cism/glimmer-cism/doc/num/vert_velo.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/vert_velo.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/vert_velo.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": 67.06, "max_line_length": 374, "alphanum_fraction": 0.7256188488, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6232878941453689}}
{"text": "%---------------------------Shape and Size-----------------------------\n\\section{Shape and Size\\label{s:quad-shape-and-size}}\n\nLet $R$ be the relative size squared as defined in \\S\\ref{s:quad-rel-size-squared}\nand $S$ be the shape as defined in \\S\\ref{s:quad-shape}.\nThe shape and size metric is the product of these two numbers:\n\\[\nq = R S.\n\\]\n\n\\quadmetrictable{shape and size}%\n{$1$}%                                      Dimension\n{$[0.2,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\\_shape\\_and\\_size}%                Verdict function name\n\n", "meta": {"hexsha": "ecc85d585d674cd0dbb135a4e942f1678da4fdd2", "size": 783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadShapeAndSize.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/QuadShapeAndSize.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/QuadShapeAndSize.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.15, "max_line_length": 82, "alphanum_fraction": 0.4763729246, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6232878941453688}}
{"text": "\n\\subsection{The Crank--Nicolson Method}\n\\begin{frame}{The Crank-Nicolson Method}\n\n\\begin{block}{}\n   \\center{symmetry in the construction of difference equations \\\\ $\\rightarrow$\nbetter accurancy} \n \\end{block}\n \n\\begin{equation}\\underline{\\frac{\\partial u}{\\partial t} \\Big \\vert _{A}\\cong \\frac{u(x,t) - u(x,t - h)}{k}}\\end{equation} w oparciu o punkty symetryczne wzgl. A\n \n \\centerline{\\includegraphics[width = 1 \\linewidth]{img/23/crank}}\n\\end{frame}\n\n\\begin{frame}\n\\begin{equation} \\frac{\\partial ^2 u}{\\partial x^2} \\Big \\vert _{4}\\approx \\frac{u(x - h,t - k) - 2 \\cdot u(x,t - h) + u(x + h, t-k)}{h^2}\\end{equation}\n\\begin{equation} \\frac{\\partial ^2 u}{\\partial x^2} \\Big \\vert _{0}\\approx \\frac{u(x - h,t) - 2 \\cdot u(x,t) + u(x + h, t)}{h^2} \\end{equation}\nto:\n\\begin{equation} \\frac{\\partial ^2 u}{\\partial x^2} \\big \\vert _{A} = \\frac{1}{2} \\cdot \\left ( \\frac{\\partial ^2 u}{\\partial x^2} \\Big \\vert _{0} + \\frac{\\partial ^2 u}{\\partial x^2} \\Big \\vert _{4} \\right )\\end{equation}\n\\textbf{W met. ,,Implicit'' wprowadzamy:}\n\\begin{multline} \\lambda \\cdot u(x-h,t) - 2 \\cdot (1+\\lambda)\\cdot u(x,t) + \\lambda \\cdot (x+h,t) = \\\\\n -\\lambda \\cdot (x-h,t-k) - 2 \\cdot (1-\\lambda)u(x,t-k) - \\lambda \\cdot u(x+h,t-k)\\end{multline}\nczyli:\n$$ \\underline{\\lambda \\cdot u_3 - 3\\cdot (1+\\lambda)u_0 + \\lambda u_1 = -\\lambda \\cdot u_7 - 2(1-\\lambda)u_4 - \\lambda u_8}$$\n\\end{frame}", "meta": {"hexsha": "5e271c3c913c9e0f9f1f3416a6bdb9cdc15908e9", "size": 1382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "23_rozniczkowe_czastkowe/23_3_6_crank-nicolson_method.tex", "max_stars_repo_name": "Arkowski24/lectures", "max_stars_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "23_rozniczkowe_czastkowe/23_3_6_crank-nicolson_method.tex", "max_issues_repo_name": "Arkowski24/lectures", "max_issues_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "23_rozniczkowe_czastkowe/23_3_6_crank-nicolson_method.tex", "max_forks_repo_name": "Arkowski24/lectures", "max_forks_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_forks_repo_licenses": ["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.28, "max_line_length": 222, "alphanum_fraction": 0.6360347323, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6231470364838783}}
{"text": "\n\\chapter{Continuous morphisms}\n\nThis chapter uses the apparatus from the section ``Partially ordered\ndagger categories''.\n\n\n\\section{Traditional definitions of continuity}\n\nIn this section we will show that having a funcoid or reloid $\\uparrow f$\ncorresponding to a function $f$ we can express continuity of it by\nthe formula $\\uparrow f\\circ\\mu\\sqsubseteq\\nu\\circ\\uparrow f$ (or\nsimilar formulas) where $\\mu$ and $\\nu$ are some spaces.\n\n\n\\subsection{\\index{continuity!pre-topology}Pretopology}\n\nLet $(A,\\cl_{A})$ and $(B,\\cl_{B})$ be preclosure spaces. Then by\ndefinition a function $f:A\\rightarrow B$ is continuous iff $f\\cl_{A}(X)\\subseteq\\cl_{B}(fX)$\nfor every $X\\in\\subsets A$. Let now $\\mu$ and $\\nu$ be endofuncoids\ncorresponding correspondingly to $\\cl_{A}$ and $\\cl_{B}$. Then the\ncondition for continuity can be rewritten as\n\\[\n\\uparrow^{\\mathsf{FCD}(\\Ob\\mu,\\Ob\\nu)}f\\circ\\mu\\sqsubseteq\\nu\\circ\\uparrow^{\\mathsf{FCD}(\\Ob\\mu,\\Ob\\nu)}f.\n\\]\n\n\n\n\\subsection{\\index{continuity!proximity}Proximity spaces}\n\nLet $\\mu$ and $\\nu$ be proximity spaces (which I consider a special\ncase of endofuncoids). By definition a $\\mathbf{Set}$-morphism~$f$\nis a proximity-continuous map from $\\mu$\nto $\\nu$ iff\n\\[\n\\forall X,Y\\in\\mathscr{T}(\\Ob\\mu):(X\\rsuprel{\\mu}Y\\Rightarrow\\rsupfun fX\\rsuprel{\\nu}\\rsupfun fY).\n\\]\n\n\nEquivalently transforming this formula we get\n\\begin{gather*}\n\\forall X,Y\\in\\mathscr{T}(\\Ob\\mu):(X\\rsuprel{\\mu}Y\\Rightarrow\\supfun f\\uparrow X\\suprel{\\nu}\\supfun f\\uparrow Y);\\\\\n\\forall X,Y\\in\\mathscr{T}(\\Ob\\mu):(X\\rsuprel{\\mu}Y\\Rightarrow\\uparrow X\\suprel{f^{-1}\\circ\\nu\\circ f}\\uparrow Y);\\\\\n\\forall X,Y\\in\\mathscr{T}(\\Ob\\mu):(X\\rsuprel{\\mu}Y\\Rightarrow X\\rsuprel{f^{-1}\\circ\\nu\\circ f}Y);\\\\\n\\mu\\sqsubseteq f^{-1}\\circ\\nu\\circ f.\n\\end{gather*}\n\n\nSo a function $f$ is proximity continuous iff $\\mu\\sqsubseteq f^{-1}\\circ\\nu\\circ f$.\n\n\n\\subsection{\\index{continuity!uniformity}Uniform spaces}\n\nUniform spaces are a special case of endoreloids.\n\nLet $\\mu$ and $\\nu$ be uniform spaces. By definition a $\\mathbf{Set}$-morphism~$f$\nis a uniformly continuous map from $\\mu$ to $\\nu$ iff \n\\[\n\\forall\\varepsilon\\in\\up\\nu\\exists\\delta\\in\\up\\nu\\forall(x,y)\\in\\delta:(fx,fy)\\in\\varepsilon.\n\\]\n\n\nEquivalently transforming this formula we get:\n\\begin{gather*}\n\\forall\\epsilon\\in\\up\\nu\\exists\\delta\\in\\up\\mu\\forall(x,y)\\in\\delta:\\{(fx,fy)\\}\\subseteq\\epsilon;\\\\\n\\forall\\epsilon\\in\\up\\nu\\exists\\delta\\in\\up\\mu\\forall(x,y)\\in\\delta:f\\circ\\{(x,y)\\}\\circ f^{-1}\\subseteq\\epsilon;\\\\\n\\forall\\epsilon\\in\\up\\nu\\exists\\delta\\in\\up\\mu:f\\circ\\delta\\circ f^{-1}\\subseteq\\epsilon;\\\\\n\\forall\\epsilon\\in\\up\\nu:\\uparrow^{\\mathsf{RLD}(\\Ob\\mu,\\Ob\\nu)}f\\circ\\mu\\circ(\\uparrow^{\\mathsf{RLD}(\\Ob\\mu,\\Ob\\nu)}f)^{-1}\\sqsubseteq\\uparrow^{\\mathsf{RLD}(\\Ob\\mu,\\Ob\\nu)}\\epsilon;\\\\\n\\uparrow^{\\mathsf{RLD}(\\Ob\\mu,\\Ob\\nu)}f\\circ\\mu\\circ(\\uparrow^{\\mathsf{RLD}(\\Ob\\mu,\\Ob\\nu)}f)^{-1}\\sqsubseteq\\nu.\n\\end{gather*}\nSo a function $f$ is uniformly continuous iff $f\\circ\\mu\\circ f^{-1}\\sqsubseteq\\nu$.\n\n\n\\section{\\index{continuity!generalized}Our three definitions of continuity}\n\nI have expressed different kinds of continuity with simple algebraic\nformulas hiding the complexity of traditional epsilon-delta notation\nbehind a smart algebra. Let's summarize these three algebraic formulas:\n\nLet $\\mu$ and $\\nu$ be endomorphisms of some partially ordered precategory.\nContinuous functions can be defined as these morphisms $f$ of this\nprecategory which conform to the following formula:\n\\[\nf\\in\\continuous(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land f\\circ\\mu\\sqsubseteq\\nu\\circ f.\n\\]\nIf the precategory is a partially ordered dagger precategory then\ncontinuity also can be defined in two other ways:\n\\begin{gather*}\nf\\in\\continuous'(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f;\\\\\nf\\in\\continuous''(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land f\\circ\\mu\\circ f^{\\dagger}\\sqsubseteq\\nu.\n\\end{gather*}\n\n\\begin{rem}\nIn the examples (above) about funcoids and reloids the ``dagger functor''\nis the reverse of a funcoid or reloid, that is $f^{\\dagger}=f^{-1}$.\\end{rem}\n\\begin{prop}\nEvery of these three definitions of continuity forms a wide sub-precategory\n(wide subcategory if the original precategory is a category).\\end{prop}\n\\begin{proof}\n~\n\\begin{description}\n\\item [{$\\continuous$}] Let $f\\in\\continuous(\\mu,\\nu)$, $g\\in\\continuous(\\nu,\\pi)$.\nThen $f\\circ\\mu\\sqsubseteq\\nu\\circ f$, $g\\circ\\nu\\sqsubseteq\\pi\\circ g$,\n$g\\circ f\\circ\\mu\\sqsubseteq g\\circ\\nu\\circ f\\sqsubseteq\\pi\\circ g\\circ f$.\nSo $g\\circ f\\in\\continuous(\\mu,\\pi)$. $1_{\\Ob\\mu}\\in\\continuous(\\mu,\\mu)$\nis obvious.\n\\item [{$\\continuous'$}] Let $f\\in\\continuous'(\\mu,\\nu)$, $g\\in\\continuous'(\\nu,\\pi)$.\nThen $\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f$, $\\nu\\sqsubseteq g^{\\dagger}\\circ\\pi\\circ g$;\n\\[\n\\mu\\sqsubseteq f^{\\dagger}\\circ g^{\\dagger}\\circ\\pi\\circ g\\circ f;\\quad\\mu\\sqsubseteq(g\\circ f)^{\\dagger}\\circ\\pi\\circ(g\\circ f).\n\\]\nSo $g\\circ f\\in\\continuous'(\\mu,\\pi)$. $1_{\\Ob\\mu}\\in\\continuous'(\\mu,\\mu)$\nis obvious.\n\\item [{$\\continuous''$}] Let $f\\in\\continuous''(\\mu,\\nu)$, $g\\in\\continuous''(\\nu,\\pi)$.\nThen $f\\circ\\mu\\circ f^{\\dagger}\\sqsubseteq\\nu$, $g\\circ\\nu\\circ g^{\\dagger}\\sqsubseteq\\pi$;\n\\[\ng\\circ f\\circ\\mu\\circ f^{\\dagger}\\circ g^{\\dagger}\\sqsubseteq\\pi;\\quad(g\\circ f)\\circ\\mu\\circ(g\\circ f)^{\\dagger}\\sqsubseteq\\pi.\n\\]\nSo $g\\circ f\\in\\continuous''(\\mu,\\pi)$. $1_{\\Ob\\mu}\\in\\continuous''(\\mu,\\mu)$\nis obvious.\n\\end{description}\n\\end{proof}\n\\begin{prop}\nFor a monovalued morphism $f$ of a partially ordered dagger category\nand its endomorphisms $\\mu$ and $\\nu$ \n\\[\nf\\in\\continuous'(\\mu,\\nu)\\Rightarrow f\\in\\continuous(\\mu,\\nu)\\Rightarrow f\\in\\continuous''(\\mu,\\nu).\n\\]\n\\end{prop}\n\\begin{proof}\nLet $f\\in\\continuous'(\\mu,\\nu)$. Then $\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f$;\n\\[\nf\\circ\\mu\\sqsubseteq f\\circ f^{\\dagger}\\circ\\nu\\circ f\\sqsubseteq1_{\\Dst f}\\circ\\nu\\circ f=\\nu\\circ f;\\quad f\\in\\continuous(\\mu,\\nu).\n\\]\n\n\nLet $f\\in\\continuous(\\mu,\\nu)$. Then $f\\circ\\mu\\sqsubseteq\\nu\\circ f$;\n\\[\nf\\circ\\mu\\circ f^{\\dagger}\\sqsubseteq\\nu\\circ f\\circ f^{\\dagger}\\sqsubseteq\\nu\\circ1_{\\Dst f}=\\nu;\\quad f\\in\\continuous''(\\mu,\\nu).\n\\]\n\\end{proof}\n\\begin{prop}\nFor an entirely defined morphism $f$ of a partially ordered dagger\ncategory and its endomorphisms $\\mu$ and $\\nu$\n\\[\nf\\in\\continuous''(\\mu,\\nu)\\Rightarrow f\\in\\continuous(\\mu,\\nu)\\Rightarrow f\\in\\continuous'(\\mu,\\nu).\n\\]\n\\end{prop}\n\\begin{proof}\nLet $f\\in\\continuous''(\\mu,\\nu)$. Then $f\\circ\\mu\\circ f^{\\dagger}\\sqsubseteq\\nu$;\n$f\\circ\\mu\\circ f^{\\dagger}\\circ f\\sqsubseteq\\nu\\circ f$; $f\\circ\\mu\\circ1_{\\Src f}\\sqsubseteq\\nu\\circ f$;\n$f\\circ\\mu\\sqsubseteq\\nu\\circ f$; $f\\in\\continuous(\\mu,\\nu)$.\n\nLet $f\\in\\continuous(\\mu,\\nu)$. Then $f\\circ\\mu\\sqsubseteq\\nu\\circ f$;\n$f^{\\dagger}\\circ f\\circ\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f$;\n$1_{\\Src\\mu}\\circ\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f$; $\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f$;\n$f\\in\\continuous'(\\mu,\\nu)$.\n\\end{proof}\nFor entirely defined monovalued morphisms our three definitions of\ncontinuity coincide:\n\\begin{thm}\\label{cont-eq}\nIf $f$ is a monovalued and entirely defined morphism of a partially\nordered dagger precategory then\n\\[\nf\\in\\continuous'(\\mu,\\nu)\\Leftrightarrow f\\in\\continuous(\\mu,\\nu)\\Leftrightarrow f\\in\\continuous''(\\mu,\\nu).\n\\]\n\\end{thm}\n\\begin{proof}\nFrom two previous propositions.\n\\end{proof}\nThe classical general topology theorem that uniformly continuous function\nfrom a uniform space to an other uniform space is proximity-continuous\nregarding the proximities generated by the uniformities, generalized\nfor reloids and funcoids takes the following form:\n\\begin{thm}\nIf an entirely defined morphism of the category of reloids $f\\in\\continuous''(\\mu,\\nu)$\nfor some endomorphisms $\\mu$ and $\\nu$ of the category of reloids,\nthen $\\mathsf{\\tofcd}f\\in\\continuous'(\\tofcd\\mu,\\tofcd\\nu)$.\\end{thm}\n\\begin{xca}\nI leave a simple exercise for the reader to prove the last theorem.\n\\end{xca}\n\n\\begin{thm}\nLet $\\mu$ and $\\nu$ be endomorphisms of some partially ordered dagger precategory and\n$f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)$ be a monovalued, entirely defined morphism. Then\n\\[ f\\in\\continuous(\\mu,\\nu)\\Leftrightarrow f\\in\\continuous(\\mu^{\\dagger},\\nu^{\\dagger}). \\]\n\\end{thm}\n\n\\begin{proof}\n\\begin{multline*}\nf \\circ \\mu \\sqsubseteq \\nu \\circ f \\Leftrightarrow \\mu\n\\sqsubseteq f^{\\dagger} \\circ \\nu \\circ f \\Rightarrow \\\\ \\mu \\circ\nf^{\\dagger} \\sqsubseteq f^{\\dagger} \\circ \\nu \\circ f \\circ f^{\\dagger}\n\\Rightarrow \\mu \\circ f^{\\dagger} \\sqsubseteq f^{\\dagger} \\circ \\nu\n\\Leftrightarrow \\\\ f \\circ \\mu^{\\dagger} \\sqsubseteq \\nu^{\\dagger} \\circ f\n\\Rightarrow f^{\\dagger} \\circ f \\circ \\mu^{\\dagger} \\sqsubseteq\nf^{\\dagger} \\circ \\nu^{\\dagger} \\circ f \\Rightarrow \\\\ \\mu^{\\dagger}\n\\sqsubseteq f^{\\dagger} \\circ \\nu^{\\dagger} \\circ f \\Leftrightarrow \\mu\n\\sqsubseteq f^{\\dagger} \\circ \\nu \\circ f.\n\\end{multline*}\n\nThus $f \\circ \\mu \\sqsubseteq \\nu \\circ f \\Leftrightarrow \\mu \\Leftrightarrow\nf \\circ \\mu^{\\dagger} \\sqsubseteq \\nu^{\\dagger} \\circ f$.\n\\end{proof}\n\n\\section{Continuity for topological spaces}\n\n\\begin{prop}\n  The following are pairwise equivalent for funcoids $\\mu$, $\\nu$ and\n  a monovalued, entirely defined morphism~$f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)$:\n  \\begin{enumerate}\n    \\item\\label{fcd-cont-unfold} $\\forall A \\in \\mathscr{T} \\Ob \\mu, B \\in \\up\n    \\supfun{\\nu} \\rsupfun{f} A : \\rsupfun{f^{- 1}}\n    B \\in \\up \\rsupfun{\\mu} A$.\n\n    \\item\\label{fcd-cont-main}  $f \\in \\continuous (\\mu, \\nu)$.\n\n    \\item\\label{fcd-cont-rev} $f \\in \\continuous (\\mu^{- 1} , \\nu^{- 1})$.\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  ~\n  \\begin{description}\n  \\item[\\ref{fcd-cont-main}$\\Leftrightarrow$\\ref{fcd-cont-rev}] By general $f \\circ \\mu \\sqsubseteq \\nu \\circ\n  f \\Leftrightarrow f \\circ \\mu^{\\dagger} \\sqsubseteq \\nu^{\\dagger}\n  \\circ f$ formula above.\n\n  \\item[\\ref{fcd-cont-unfold}$\\Leftrightarrow$\\ref{fcd-cont-main}] \\ref{fcd-cont-unfold} is equivalent to\n  $\\rsupfun{\\rsupfun{f^{- 1}}}\n  \\up \\supfun{\\nu} \\rsupfun{f} A \\subseteq \\up\n  \\rsupfun{\\mu} A$ equivalent to $\\supfun{\\nu} \\rsupfun{f}\n  A \\sqsupseteq \\supfun{f} \\rsupfun{\\mu} A$\n  (used ``Orderings of filters'' chapter).\n  \\end{description}\n\\end{proof}\n\n\\begin{cor}\\label{top-cont}\n  The following are pairwise equivalent for topological spaces $\\mu$,\n  $\\nu$ and a monovalued, entirely defined morphism~$f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)$:\n  \\begin{enumerate}\n    \\item\\label{top-cont-unfold} $\\forall x \\in \\Ob \\mu, B \\in \\up \\supfun{\\nu}\n    \\rsupfun{f} \\{x\\} : \\rsupfun{f^{- 1}} B \\in\n    \\up \\rsupfun{\\mu} \\{x\\}$.\n\n    \\item\\label{top-cont-preim} Preimages (by $f$) of open sets are open.\n\n    \\item\\label{top-cont-main} $f \\in \\continuous (\\mu, \\nu)$ that is $\\supfun{f}\n    \\rsupfun{\\mu} \\{ x \\} \\sqsubseteq \\supfun{\\nu}\n    \\rsupfun{f} \\{ x \\}$ for every $x \\in \\Ob \\mu$.\n\n    \\item\\label{top-cont-rev} $f \\in \\continuous (\\mu^{- 1} , \\nu^{- 1})$ that is $\\supfun{f}\n    \\rsupfun{\\mu^{- 1}} A \\sqsubseteq \\supfun{\\nu^{- 1}}\n    \\rsupfun{f} A$ for every $A \\in \\mathscr{T}\n    \\Ob \\mu$.\n  \\end{enumerate}\n\\end{cor}\n\n\\begin{proof}\n  \\ref{fcd-cont-main} from the previous proposition is equivalent to\n  $\\supfun{f}\\rsupfun{\\mu}\\{x\\}\\sqsubseteq\\supfun{\\nu}\\rsupfun{f}\\{x\\}$\n  equivalent to $\\rsupfun{\\rsupfun{f^{- 1}}}\n  \\up \\supfun{\\nu} \\rsupfun{f} \\{ x \\} \\subseteq\n  \\up \\rsupfun{\\mu} \\{ x \\}$ for every $x \\in \\Ob\n  \\mu$, equivalent to \\ref{top-cont-unfold} (used ``Orderings of filters'' chapter).\n\n  It remains to prove \\ref{top-cont-main}$\\Leftrightarrow$\\ref{top-cont-preim}.\n\n  \\begin{description}\n  \\item[\\ref{top-cont-main}$\\Rightarrow$\\ref{top-cont-preim}] Let $B$ be an open set in $\\nu$. For every $x \\in\n  \\rsupfun{f^{- 1}} B$ we have $f (x) \\in B$ that is $B$ is a\n  neighborhood of $f (x)$, thus $\\rsupfun{f^{-1}}B$ is a neighborhood of $x$. We have\n  proved that $\\rsupfun{f^{- 1}} B$ is open.\n\n  \\item[\\ref{top-cont-preim}$\\Rightarrow$\\ref{top-cont-main}] Let $B$ be a neighborhood of $f (x)$. Then there is an\n  open neighborhood $B' \\subseteq B$ of $f (x)$. $\\rsupfun{f^{-1}}\n  B'$ is open and thus is a neighborhood of $x$ ($x \\in \\rsupfun{f^{-1}} B'$ because $f (x) \\in B'$). Consequently\n  $\\rsupfun{f^{-1}} B$ is a neighborhood of $x$.\n  \\end{description}\n\n  Alternative proof of \\ref{top-cont-preim}$\\Leftrightarrow$\\ref{top-cont-rev}:\n  \\url{http://math.stackexchange.com/a/1855782/4876}\n\\end{proof}\n\n\\section{\\texorpdfstring{$\\continuous (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})$}{C(mu o mu\\textasciicircum-1, nu o nu\\textasciicircum-1)}}\n\n\\begin{prop}\n  $f \\in \\continuous (\\mu, \\nu) \\Rightarrow f \\in \\continuous'' (\\mu\n  \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})$ for endofuncoids $\\mu$,\n  $\\nu$ and monovalued funcoid $f \\in \\mathsf{FCD} (\\Ob\n  \\mu, \\Ob \\nu)$.\n\\end{prop}\n\n\\begin{proof}\n  Let $f \\in \\continuous (\\mu, \\nu)$.\n\n\\begin{multline*}\n  X \\mathrel{[f \\circ \\mu \\circ \\mu^{- 1} \\circ f^{- 1}]^{\\ast}}\n  Z \\Leftrightarrow \\\\ \\exists p \\in \\atoms^{\\mathscr{F}} : \\left( X\n  \\mathrel{[\\mu^{- 1} \\circ f^{- 1}]^{\\ast}} p \\wedge p \\mathrel{[f\n  \\circ \\mu]^{\\ast}} Z \\right) \\Leftrightarrow \\\\ \\exists p \\in\n  \\atoms^{\\mathscr{F}} : \\left( p \\mathrel{[f \\circ \\mu]^{\\ast}} X\n  \\wedge p \\mathrel{[f \\circ \\mu]^{\\ast}} Z \\right) \\Rightarrow \\\\ \\exists\n  p \\in \\atoms^{\\mathscr{F}} : \\left( p \\mathrel{[\\nu \\circ f]^{\\ast}} X\n  \\wedge p \\mathrel{[\\nu \\circ f]^{\\ast}} Z \\right) \\Leftrightarrow \\\\ \\exists p\n  \\in \\atoms^{\\mathscr{F}} : \\left( \\rsupfun{f} p\n  \\mathrel{[\\nu]^{\\ast}} X \\wedge \\rsupfun{f} p\n  \\mathrel{[\\nu]^{\\ast}} Z \\right) \\Rightarrow X \\mathrel{[\\nu \\circ \\nu^{-\n  1}]^{\\ast}} Z\n\\end{multline*}\n(taken into account monovaluedness of $f$ and thus that\n  $\\rsupfun{f} p$ is atomic or least). Thus $f \\circ \\mu\n  \\circ \\mu^{- 1} \\circ f^{- 1} \\sqsubseteq \\nu \\circ \\nu^{- 1}$ that is\n  $f \\in \\continuous'' (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{-\n  1})$.\n\\end{proof}\n\n\\begin{prop}\n  $f \\in \\continuous'' (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})\n  \\Rightarrow f \\in \\continuous'' (\\mu, \\nu)$ for complete endofuncoids\n  $\\mu$, $\\nu$ and principal funcoid $f \\in \\mathsf{FCD}\n  (\\Ob \\mu, \\Ob \\nu)$, provided that $\\mu$ is\n  reflexive, and $\\nu$ is $T_1$-separable.\n\\end{prop}\n\n\\begin{proof}\n\\begin{multline*}\n  f \\in \\continuous'' (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})\n  \\Leftrightarrow \\\\ f \\circ \\mu \\circ \\mu^{- 1} \\circ f^{- 1}\n  \\sqsubseteq \\nu \\circ \\nu^{- 1} \\Rightarrow \\text{(reflexivity of\n  $\\mu$)} \\Rightarrow \\\\ f \\circ \\mu \\circ f^{- 1} \\sqsubseteq \\nu\n  \\circ \\nu^{- 1} \\Leftrightarrow f \\circ \\mu^{- 1} \\circ f^{- 1}\n  \\sqsubseteq \\nu \\circ \\nu^{- 1} \\Rightarrow \\\\ \\langle f \\circ \\mu^{- 1}\n  \\circ f^{- 1} \\rangle^{\\ast} X \\sqsubseteq \\supfun{\\nu}^{\\ast}\n  \\langle \\nu^{- 1} \\rangle^{\\ast} X \\Rightarrow \\\\ \\Cor \\left\\langle f\n  \\circ \\mu^{- 1} \\circ f^{- 1} \\right\\rangle^{\\ast} X \\sqsubseteq\n  \\Cor \\supfun{\\nu}^{\\ast} \\langle \\nu^{- 1} \\rangle^{\\ast} X\n  \\Leftrightarrow \\\\ \\langle f \\circ \\mu^{- 1} \\circ f^{- 1} \\rangle^{\\ast}\n  X \\sqsubseteq \\Cor \\supfun{\\nu}^{\\ast} \\langle \\nu^{- 1}\n  \\rangle^{\\ast} X \\Rightarrow \\\\ \\text{($T_1$-separability)} \\Rightarrow \\\\ \\langle\n  f \\circ \\mu^{- 1} \\circ f^{- 1} \\rangle^{\\ast} X \\sqsubseteq \\langle\n  \\nu^{- 1} \\rangle^{\\ast} X$ for any typed set $X$ on $\\Ob \\nu.\n\\end{multline*}\n  Thus\n  \\begin{multline*}\nf \\in \\continuous'' (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})\n  \\Rightarrow f \\circ \\mu^{- 1} \\circ f^{- 1} \\sqsubseteq \\nu^{- 1}\n  \\Leftrightarrow \\\\ f \\circ \\mu \\circ f^{- 1} \\sqsubseteq \\nu\n  \\Leftrightarrow f \\in \\continuous'' (\\mu, \\nu).\n  \\end{multline*}\n\\end{proof}\n\n\\begin{thm}\n  $f \\in \\continuous (\\mu \\circ \\mu^{- 1} , \\nu \\circ \\nu^{- 1})\n  \\Leftrightarrow f \\in \\continuous (\\mu, \\nu)$ for complete endofuncoids\n  $\\mu$, $\\nu$ and principal monovalued and entirely defined funcoid $f\n  \\in \\mathsf{FCD} (\\Ob \\mu, \\Ob \\nu)$, provided that\n  $\\mu$ is reflexive, and $\\nu$ is $T_1$-separable.\n\\end{thm}\n\n\\begin{proof}\n  Two above propositions and theorem~\\ref{cont-eq}.\n\\end{proof}\n\n\\section{\\index{continuity!of restricted morphism}Continuity of a restricted\nmorphism}\n\nConsider some partially ordered semigroup. (For example it can be\nthe semigroup of funcoids or semigroup of reloids on some set regarding\nthe composition.) Consider also some lattice (\\emph{lattice of objects}).\n(For example take the lattice of set theoretic filters.)\n\nWe will map every object $A$ to so called \\emph{restricted identity}\nelement $I_{A}$ of the semigroup (for example restricted identity\nfuncoid or restricted identity reloid). For identity elements we will\nrequire\n\\begin{enumerate}\n\\item $I_{A}\\circ I_{B}=I_{A\\sqcap B}$;\n\\item $f\\circ I_{A}\\sqsubseteq f$; $I_{A}\\circ f\\sqsubseteq f$.\n\\end{enumerate}\nIn the case when our semigroup is ``dagger'' (that is is a dagger\nprecategory) we will require also $(I_{A})^{\\dagger}=I_{A}$.\n\nWe can define restricting an element $f$ of our semigroup to an object\n$A$ by the formula $f|_{A}=f\\circ I_{A}$.\n\n\\index{restricting!rectangular}We can define \\emph{rectangular restricting}\nan element $f$ of our semigroup to objects $A$ and $B$ as $I_{B}\\circ f\\circ I_{A}$.\nOptionally we can define direct product $A\\times B$ of two objects\nby the formula (true for funcoids and for reloids):\n\\[\nf\\sqcap(A\\times B)=I_{B}\\circ f\\circ I_{A}.\n\\]\n\n\n\\index{restricting!square}\\emph{Square restricting} of an element\n$f$ to an object $A$ is a special case of rectangular restricting\nand is defined by the formula $I_{A}\\circ f\\circ I_{A}$ (or by the\nformula $f\\sqcap(A\\times A)$).\n\\begin{thm}\n\\label{rect-cont}For every elements~$f$, $\\mu$, $\\nu$ of our semigroup\nand an object $A$\n\\begin{enumerate}\n\\item \\label{contrestr-C}$f\\in\\continuous(\\mu,\\nu)\\Rightarrow f|_{A}\\in\\continuous(I_{A}\\circ\\mu\\circ I_{A},\\nu)$;\n\\item \\label{contrestr-Ci}$f\\in\\continuous'(\\mu,\\nu)\\Rightarrow f|_{A}\\in\\continuous'(I_{A}\\circ\\mu\\circ I_{A},\\nu)$;\n\\item \\label{contrestr-Cii}$f\\in\\continuous''(\\mu,\\nu)\\Rightarrow f|_{A}\\in\\continuous''(I_{A}\\circ\\mu\\circ I_{A},\\nu)$. \n\\end{enumerate}\n\n(Two last items are true for the case when our semigroup is dagger.)\n\n\\end{thm}\n\\begin{proof}\n~\n\\begin{widedisorder}\n\\item [{\\ref{contrestr-C}}] ~\n\\begin{align*}\nf|_{A}\\in\\continuous(I_{A}\\circ\\mu\\circ I_{A},\\nu) & \\Leftrightarrow\\\\\nf|_{A}\\circ I_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq\\nu\\circ f|_{A} & \\Leftrightarrow\\\\\nf\\circ I_{A}\\circ I_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq\\nu\\circ f|_{A} & \\Leftrightarrow\\\\\nf\\circ I_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq\\nu\\circ f\\circ I_{A} & \\Leftarrow\\\\\nf\\circ I_{A}\\circ\\mu\\sqsubseteq\\nu\\circ f & \\Leftarrow\\\\\nf\\circ\\mu\\sqsubseteq\\nu\\circ f & \\Leftrightarrow\\\\\nf\\in\\continuous(\\mu,\\nu).\n\\end{align*}\n\n\\item [{\\ref{contrestr-Ci}}] ~\n\\begin{align*}\nf|_{A}\\in\\continuous'(I_{A}\\circ\\mu\\circ I_{A},\\nu) & \\Leftrightarrow\\\\\nI_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq(f|_{A})^{\\dagger}\\circ\\nu\\circ f|_{A} & \\Leftarrow\\\\\nI_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq(f\\circ I_{A})^{\\dagger}\\circ\\nu\\circ f\\circ I_{A} & \\Leftrightarrow\\\\\nI_{A}\\circ\\mu\\circ I_{A}\\sqsubseteq I_{A}\\circ f^{\\dagger}\\circ\\nu\\circ f\\circ I_{A} & \\Leftarrow\\\\\n\\mu\\sqsubseteq f^{\\dagger}\\circ\\nu\\circ f & \\Leftrightarrow\\\\\nf\\in\\continuous'(\\mu,\\nu).\n\\end{align*}\n\n\\item [{\\ref{contrestr-Cii}}] ~\n\\begin{align*}\nf|_{A}\\in\\continuous''(I_{A}\\circ\\mu\\circ I_{A},\\nu) & \\Leftrightarrow\\\\\nf|_{A}\\circ I_{A}\\circ\\mu\\circ I_{A}\\circ(f|_{A})^{\\dagger}\\sqsubseteq\\nu & \\Leftrightarrow\\\\\nf\\circ I_{A}\\circ I_{A}\\circ\\mu\\circ I_{A}\\circ I_{A}\\circ f^{\\dagger}\\sqsubseteq\\nu & \\Leftrightarrow\\\\\nf\\circ I_{A}\\circ\\mu\\circ I_{A}\\circ f^{\\dagger}\\sqsubseteq\\nu & \\Leftarrow\\\\\nf\\circ\\mu\\circ f^{\\dagger}\\sqsubseteq\\nu & \\Leftrightarrow\\\\\nf\\in\\continuous''(\\mu,\\nu).\n\\end{align*}\n\\end{widedisorder}\n\\end{proof}\n\n\\section{Anticontinuous morphisms}\n\nLet $\\mu$ and $\\nu$ be endomorphisms of some partially ordered precategory.\n\\emph{Anticontinuous} functions can be defined as these morphisms $f$ of this\nprecategory which conform to the following formula:\n\\[\nf\\in\\continuous_{\\ast}(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land f\\circ\\mu\\sqsupseteq\\nu\\circ f.\n\\]\nIf the precategory is a partially ordered dagger precategory then\n\\emph{anticontinuity} also can be defined in two other ways:\n\\begin{gather*}\nf\\in\\continuous_{\\ast}'(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land\\mu\\sqsupseteq f^{\\dagger}\\circ\\nu\\circ f;\\\\\nf\\in\\continuous_{\\ast}''(\\mu,\\nu)\\Leftrightarrow f\\in\\Hom(\\Ob\\mu,\\Ob\\nu)\\land f\\circ\\mu\\circ f^{\\dagger}\\sqsupseteq\\nu.\n\\end{gather*}\n\nAnticontinuity is the order dual of continuity.\n\n\\begin{thm}\nFor partially ordered dagger categories:\n\\begin{enumerate}\n\\item $f\\in\\continuous_{\\ast}(\\mu,\\nu)\\Leftrightarrow f^{\\dagger}\\in\\continuous(\\nu^{\\dagger},\\mu^{\\dagger})$;\n\\item $f\\in\\continuous_{\\ast}'(\\mu,\\nu)\\Leftrightarrow f^{\\dagger}\\in\\continuous''(\\nu^{\\dagger},\\mu^{\\dagger})$;\n\\item $f\\in\\continuous_{\\ast}''(\\mu,\\nu)\\Leftrightarrow f^{\\dagger}\\in\\continuous'(\\nu^{\\dagger},\\mu^{\\dagger})$.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n~\n\\begin{enumerate}\n\\item $f\\in\\continuous_{\\ast}(f,g)\\Leftrightarrow\nf\\circ\\mu\\sqsupseteq\\nu\\circ f\\Leftrightarrow\n\\mu^{\\dagger}\\circ f^{\\dagger}\\sqsupseteq f^{\\dagger}\\circ\\nu^{\\dagger}\\Leftrightarrow\nf^{\\dagger}\\in\\continuous(\\nu^{\\dagger},\\mu^{\\dagger})$.\n\\item $f\\in\\continuous_{\\ast}'(\\mu,\\nu)\\Leftrightarrow\n\\mu\\sqsupseteq f^{\\dagger}\\circ\\nu\\circ f\\Leftrightarrow\nf^{\\dagger}\\circ\\nu^{\\dagger}\\circ f\\sqsubseteq\\mu^{\\dagger}\\Leftrightarrow\nf^{\\dagger}\\in\\continuous''(\\nu^{\\dagger},\\mu^{\\dagger})$.\n\\item By duality.\n\\end{enumerate}\n\\end{proof}\n\n\\begin{defn}\n\\index{open map}An \\emph{open map} from a topological space to a\ntopological space is a function which maps open sets into open sets.\n\\end{defn}\n\n\\begin{thm}\nFor topological spaces considered as complete funcoids,\na principal anticontinuous morphism is the same as open map.\n\\end{thm}\n\n\\begin{proof}\nBecause $f$,~$\\mu$,~$\\nu$ are complete funcoids, we have\n\\[\nf\\in\\continuous_{\\ast}(\\mu,\\nu)\\Leftrightarrow\nf\\circ\\mu\\sqsupseteq\\nu\\circ f\\Leftrightarrow\n\\Compl(f\\circ\\mu)\\sqsupseteq\\Compl(\\nu\\circ f).\n\\]\nEquivalently transforming further, we get\n\\[\n\\forall x\\in\\Ob\\mu:\\supfun f\\rsupfun{\\mu}@\\{x\\}\\sqsupseteq\\supfun{\\nu}\\rsupfun\nf@\\{x\\};\n\\]\n\\[\n\\forall x\\in\\Ob\\mu,V\\in\\rsupfun{\\mu}\\{x\\}:\\rsupfun\nfV\\sqsupseteq\\supfun{\\nu}\\rsupfun f@\\{x\\},\n\\]\nwhat is the criterion of~$f$ being an open map.\n\\end{proof}", "meta": {"hexsha": "4cc53216ad51689eb0bf83874b9085a48f20b8d3", "size": 22221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-continuity.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-continuity.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-continuity.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "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": 43.0639534884, "max_line_length": 183, "alphanum_fraction": 0.6779622879, "num_tokens": 8275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7248702880639792, "lm_q1q2_score": 0.6231447078640773}}
{"text": "\\begin{document}\n\t\n\t\\subsection{Labelling}\n\t\n\t\n\t\n \n\tThis is the last step of the pipeline and involves assigning of each voxel to the cluster corresponding to the nearest centroids, in this way a hard segmentation is achieved.\n\n\tThe script takes as input the CT scan after the lung extraction and it builds the multichannel image as described before. After that it assigns each voxel to the cluster of nearest centroids, which is the one that minimizes the distance: \n\t\\begin{equation}\n\t\tcluster = \\arg\\min_{S}  \\sum_{i=1}^k \\sum_{S} \\| x - \\mu_i\\|\n\t\\end{equation}\n\t\n\twhere $x$ is the colour vector of the voxel and $\\mu$ is the $ith$ centroid. During this process, the background is automatically assigned to the 0 labels, passing a mask which assumes $0$ on the voxels background and $1$ for the other one. At the end of the assignment, only the cluster corresponding to GGO and CS is selected.To summarize the process, the pseudocode of the script is reported in the algorithm,\\ref{alg:labeling}.\n\tI have tested this algorithm on three different datasets. The results are described in the next chapter.\n\t\\begin{algorithm}\n\t\t\n\t\t\\SetAlgoLined\n\t\t\\DontPrintSemicolon\n\t\t\n\t\t\\SetKwFunction{Flabel}{imlabeling}\n\t\t\\SetKwProg{Fn}{Function}{:}{}\n\t\t\n\t\t\\KwData{CT scan to label, centroids}\n\t\t\\KwResult{GGO label}\n\t\t\n\t\timage$\\leftarrow$build\\_multi\\_channel\\;\n\t\t\\tcc{Compute distances and found the minimum}\n\t\t\\ForEach{$c\\in centroids $}\n\t\t{\n\t\t\tdistances$\\leftarrow\\| image - c\\|^2$\\;\n\t\t}\n\t\t\n\t\tlabels$\\leftarrow\\arg\\min\\,(distances)$\\;\n\t\t\n\t\t\\caption{Pseudo-code for the labeling script}\\label{alg:labeling}\n\t\t\n\t\\end{algorithm}\n\t\n\n \tThe assignment process is performed by the \\textsc{imlabeling} function, which takes care to assign the background to $0$, if the suitable parameter is passed. The function is implemented as follows:\n\n\t\\lstset{style=python}\n\t\\begin{lstlisting}[language=python, caption=imlabeling, label=code:imlabeling]\n\t\t\n\timport numpy as np\n\t\n\tdef imlabeling(image, centroids, weight = None) :\n\n\n\t\tif weight  is not None :\n\t\t\tdistances = np.asarray([np.linalg.norm(image[weight != 0] -c, \n\t\t\t\t\t\t\t\t\taxis = 1) for c in centroids])\n\t\t\n\t\t\tweight[weight != 0] = np.argmin(distances, axis = 0)\n\t\t\treturn weight\n\t\telse :\n\t\t\tdistances = np.asarray([np.linalg.norm(image -c, axis = 3) \n\t\t\t\t\t\t\t\t\tfor c in centroids])\n\t\t\tlabels = np.argmin(distances, axis = 0)\n\t\t\treturn labels\n\t\n\t\n\t\\end{lstlisting}\n\t\n\n\n\n\t\n\t\n\\end{document}", "meta": {"hexsha": "21f0b9017f4a77261199e91c07dad60d0ea8f9e5", "size": 2419, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Chapter2/Implementation/Labeling.tex", "max_stars_repo_name": "RiccardoBiondi/SCDthesis", "max_stars_repo_head_hexsha": "2506df1995e5ba239b28d2ca0b908ba55f81761b", "max_stars_repo_licenses": ["MIT"], "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/Chapter2/Implementation/Labeling.tex", "max_issues_repo_name": "RiccardoBiondi/SCDthesis", "max_issues_repo_head_hexsha": "2506df1995e5ba239b28d2ca0b908ba55f81761b", "max_issues_repo_licenses": ["MIT"], "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/Chapter2/Implementation/Labeling.tex", "max_forks_repo_name": "RiccardoBiondi/SCDthesis", "max_forks_repo_head_hexsha": "2506df1995e5ba239b28d2ca0b908ba55f81761b", "max_forks_repo_licenses": ["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.5972222222, "max_line_length": 432, "alphanum_fraction": 0.7184787102, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6230977691646712}}
{"text": "\\mychapter{16}{Lesson 16} %181121\n\n\\section{\\textsc{Pke} schemes over \\ddh{} assumption}\n\n\\subsection{ElGamal scheme}\n\nLet's define a new $\\Pi = (\\keygen, \\Enc, \\Dec)$. Generate the needed public parameters $(G,g,q) \\pickUAR \\groupgen(1^{\\lambda})$\\footnotemark, then:\n\n\\footnotetext{G could be any valid group such as $\\quadres_p$, or an elliptic curve group}\n\n\\begin{itemize}\n    \\item Key generation: $(\\pk, \\sk) = (g^x, x)$, where $x \\pickUAR \\integer_q$\n    \\item Encryption: $\\Enc(\\pk, m) = (g^r, \\pk^r \\cdot m)$, where $r \\pickUAR \\integer_q$\\footnote{We need $r$ because we want to re-randomize $c$}\n    \\item Decryption: $\\Dec(\\sk, (c_1, c_2))= c_1^{-\\sk} \\cdot c_2$\n\\end{itemize}\n\nThe correctness of the scheme follows from some algebraic steps:\n\\begin{align*}\n    \\hat{m} &= \\Dec(\\sk, \\Enc(\\pk, m))          \\\\\n            &= \\Dec(x, \\Enc(g^x, m))            \\\\\n            &= \\Dec(x, (g^r, (g^x)^r \\cdot m))  \\\\\n            &= (g^r)^{-x} \\cdot (g^x)^r \\cdot m \\\\\n            &= m                                \\\\\n\\end{align*}\n\n\\begin{theorem}\n    Assuming \\textsc{ddh}, the ElGamal scheme is \\textsc{cpa}-secure.\n\\end{theorem}\n\n\\begin{proof}\n    Consider the two following games $\\hybridg{0}(\\lambda, b)$ and $\\hybridg{1}(\\lambda, b)$ defined as follows. Observe that $b$ can be fixed without loss of generality.\n    \n    \\begin{cryptogame}\n        {pke1}\n        {$\\hybridg{0}(\\lambda, b) = \\cryptog{gamal}(\\lambda, b)$}\n        {gamal}\n\n        \\receive{\\shortstack[l]{\n            $x \\pickUAR \\integer_q$ \\\\\n            $\\pk = g^x$\n        }}{$\\pk$}{}\n\n        \\cseqdelay\n        \\send{}{$m_0, m_1$}{}\n        \\cseqdelay\n        \\receive{\\shortstack[l]{\n            $r \\pickUAR \\integer_q$ \\\\\n            $b \\pickUAR \\binary$ \\\\\n            $c = \\Enc(\\pk, m_b) = (g^r, (g^x)^r m_b)$\n        }}{$c$}{}\n        \\cseqdelay\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptogame}\n\n    \\begin{cryptogame}\n        {pke2}\n        {$\\hybridg{1}(\\lambda, b)$}\n        {$\\neg$gamal}\n\n        \\receive{\\shortstack[l]{\n            $x \\pickUAR \\integer_q$ \\\\\n            $\\pk = g^x$\n        }}{$\\pk$}{}\n\n        \\cseqdelay\n        \\send{}{$m_0, m_1$}{}\n        \\cseqdelay\n        \\receive{\\shortstack[l]{\n            $r, z \\pickUAR \\integer_q$ \\\\\n            $c = (g^r, g^z m_b)$\n        }}{$c$}{}\n        \\cseqdelay\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptogame}\n    \n\n    % The reasoning was a bit cloudy, hope now it is clearer\n    %AP190915: Not so sure...\n    \\textbf{Note:} it is important to note that we can measure the advantage of $\\adversary$, so fixed its output $Adv_{\\adversary}(\\lambda) = |\\underbrace{\\Pr[\\overbrace{\\adversary = 1}^{b' = 1} \\knowing b = 0}_{\\adversary\\ loses}] - \\underbrace{\\Pr[\\overbrace{\\adversary = 1}^{b' = 1} \\knowing b = 1]}_{\\adversary\\ wins}|$. Since $b$ is fixed the above formula will give a value $\\lambda \\in negl$, generally the advantage of an adversary is: $\\frac{1}{2}+\\lambda$ (random guessing + a negligible factor). %maybe this is a repetition but I think I never wrote it anywhere else\n\n    \\todo{Here the 1/2 value may refer to how the Katz-Lindell book exposes their proofs by leaving an arbitrary choice of $b$ to the challengers, thus limiting the probability of the adversaries' success by 1/2.\n    \n    Venturi prefers to fix $b$ beforehand, meaning the whole proof can be stated by setting b to either 0 or 1, and maintain its validity without changing anything else. In this way, he somehow bounds the probability of success to be $\\leq \\negl(\\lambda)$}\n\n    We will prove that:\n    \\[\n        \\hybridg{0}(\\lambda, 0) \\compindist \\hybridg{1}(\\lambda, 0) \\equiv \\hybridg{1}(\\lambda, 1) \\compindist \\hybridg{0}(\\lambda, 1)\n    \\]\n\n    \\begin{claim}\n        $\\forall b \\in \\binary \\implies \\hybridg{0}(\\lambda, b) \\compindist \\hybridg{1}(\\lambda, b)$\n    \\end{claim}\n\n    \\begin{proof}\n        This proof reduces to disproving \\ddh. Fix $b$ without loss of generality, and assume there exists a distinguisher $\\distinguisher$ able to distinguish $H_0(\\lambda,b)$ and $H_1(\\lambda,b)$. Consider the game in figure \\ref{cryptoredux:gamalddh}:\n\n        \\begin{cryptoredux}\n            {gamalddh}\n            {---}\n            {ddh}\n            {gamal}\n\n            \\receive{\\shortstack[l]{\n                $X = g^x, Y = g^y$ \\\\\n                $Z_0 = g^{xy}, Z_1 = g^z$ \\\\\n                $b \\pickUAR \\binary$\n            }}{$(X, Y, Z_b)$}{}\n\n            \\invoke{}{$\\pk = X$}{}\n            \\cseqdelay\n            \\return{}{$(m_0, m_1)$}{}\n            \\invoke{$\\boxed{a = 0}$ }{$(Y, Z_b \\cdot m_a)$}{}\n            \\cseqdelay\n            \\return{}{$a'$}{}\n\n            \\cseqdelay\n\n            \\send{$b' = \\begin{cases}\n                    0 & \\textsc{iff} \\boxed{a' = 0} \\\\\n                    1 (coin?) & \\textsc{else} \\\\\n                \\end{cases}\n            $}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n        \\end{cryptoredux}\n\n        If $\\distinguisher^{\\textsc{gamal}}$ is able to break the cipher, then \\adversary{} is in turn able to distinguish a \\textsc{dh} triple from a random one, falsifying \\ddh.\n    \\end{proof}\n\n    \\begin{claim}\n        $\\hybridg{1}(\\lambda, 0) \\equiv \\hybridg{1}(\\lambda, 1)$\n    \\end{claim}\n\n    \\begin{proof}\n        This follows from the fact that:\n        \\[\n            (g^x, (g^r, g^z m_0)) \\equiv (g^x, (g^r, U_\\lambda) \\equiv (g^x, (g^r, g^z m_1)))\n        \\]\n    \\end{proof}\n    \n    Composing the two claims, the proof is complete.\n\n\\end{proof}\n\n\\subsubsection{Properties of of El Gamal \\textsc{pke} scheme}\n\nSome useful observations can be made about this scheme:\n\\begin{itemize}\n    \\item It is \\textbf{homomorphic}: Given two ciphertexts $(c_1, c_2)$ and $(c_1', c_2')$, then doing the product between them yields another valid ciphertext:\n    % I'd like to expand a bit more here, or else it may stay a bit obscure...\n    \\begin{align*}\n        & (c_1 \\cdot c_1', c_2 \\cdot c_2') \\\\\n        =& (g^{r + r'}, h^{r + r'}(m \\cdot m'))\n    \\end{align*}\n    thus, decrypting $c \\cdot c'$, gives $m \\cdot m'$.\n    \n    \\item It is \\textbf{re-randomizable}: Given a ciphertext $(c_1, c_2)$, and $r' \\pickUAR \\integer_q$, then computing $(g^{r'} \\cdot c_1, h^{r'} \\cdot c_2)$ results in a ``fresh'' encryption for the same message: the random value used at the encryption step will change from the original $r$ to $r + r'$\n\\end{itemize}\nThese observations lead to the conclusion that this scheme is not \\cca-secure. However, such properties can be desirable in some use cases, where a message must be kept secret to the second party. In fact, there are some \\pke{} schemes which are designed to be \\textbf{fully homomorphic}, i.e. they are homomorphic for any kind of function.\n\nConsider the following use case: a client $C$ has an object $x$ and wants to apply a function $f$ over it, but it lacks the computational power to execute it. There is another subject $S$, which is able to efficiently compute $f$, so the goal is to let it compute $f(x)$ but the client wishes to keep $x$ secret from him. This can be achieved using a \\textsc{fh-pke} scheme as follows:\n\n% QUESTION: Why use a PKE scheme (and not an SKE)? Are there some advantages-shortcomings?\n\n\\begin{cryptosequence}\n    {delseccomp}\n    {Delegated secret computation}\n\n    \\cseqentity{C}{Client}\n    \\cseqentity[2.2]{S}{Server}\n\n    \\cseqdelay\n\n    % Client encrypts object and sends application request\n    \\cseqmessager{C}{\\shortstack[r]{\n        Object: $x$ \\\\\n        Function: $f$ \\\\\n        $(\\pk, \\sk) \\pickUAR \\mathcal{KG}en$ \\\\\n        $c \\pickUAR \\Enc(\\pk, x)$\n    }}{$f, c$}{S}{}\n\n    \\cseqdelay\n    \\cseqdelay\n\n    \\cseqmessagel{S}{}{$f(c)$}{C}{$f(x) = \\Dec(\\sk, f(c))$}\n\n\\end{cryptosequence}\n\n\nHowever one important consideration must be made: All these useful characteristics expose an inherent malleability of any fully homomorphic scheme: any attacker can manipulate ciphertexts efficiently, and with some predictable results. This compromises even \\textsc{cpa} security of such schemes.\n\n%\\subsection{Cramer-Shoup \\textsc{pke} scheme}\n\\section{Proof systems}\n\n% Not sure if CS is defined over DDH, or this is the DDH variant of CS, making CS more abstract\nThis new scheme assumes \\ddh{} like its ElGamal cousin, and has the advantage of being \\cca-secure. A powerful tool, called \\emph{Designated Verifier Non-Interactive Zero-Knowledge} (\\textsc{dv-nizk} in short), or alternatively \\emph{Hash-Proof System}, is used here.\n\n\n\\todo{the Ali Baba example would be useful here. Also, the coloured balls is a good example too (long live Wikipedia)}\n\nLet $L \\subseteq Y$ be a Turing-recognizable language in \\textsc{np}, and a predicate $V \\in X \\times Y \\to \\binary$ such that:\n\\[\n    L := \\{y \\in Y : \\exists x \\in X \\implies V(x, y) = 1\\}\n\\]\nwhere $x$ is called a \\emph{witness} of $y$.\n\n\\todo{to review and understand/better}\n\n% AP181122-1554: CAUTION FRAGMENTED\nIn our case, let $x = (p, q), y = pq$, and define a scheme $\\Pi$ as follows:\n\n\\[\n    \\Pi = (\\mathcal{S}etup, \\mathcal{P}rove, \\mathcal{V}erify)\n\\]\n\n% AP190914: Is (omega, tau) the (pk, sk) couple?\n\\begin{itemize}\n    \\item Setting up: $(\\omega, \\tau) \\pickUAR \\mathcal{S}etup(1^\\lambda)$, where $\\omega$ is the \\emph{common reference string}, and $\\tau$ is the \\emph{trapdoor}\n    \\item Proving a statement: $\\pi = \\mathcal{P}rove(\\omega, y, x)$\n    \\item Verifying: $\\widehat{\\pi} = \\mathcal{V}erify(\\tau, y)$\n\\end{itemize}\n\nCorrectness is defined as $\\mathcal{P}rove(\\omega, y, x) = \\mathcal{V}erify(\\tau, y)$. Some more observations:\n\n\\begin{itemize}\n    \\item $\\omega$ is public ($ = pk$)\n    \\item $\\tau$ is part of the secret key\n    \\item $\\tau = (x, y) : V(x, y) = 1$ %May be false\n    \\item There is presumably a common third-party, which samples from the setup and publishes $\\omega$, while giving $\\tau$ to only B.\n    \\todo{Why? Can't the verifier do the setup and publish omega directly? Is honesty an issue here?}\n\\end{itemize}\n\n\\begin{cryptosequence}\n    {csoverview}\n    {Overview of Cramer-Shoup operation}\n    \n    \\cseqentity{P}{Prover}\n    \\cseqentity[2.2]{V}{Verifier}\n\n    \\cseqdelay\n\n    \\cseqmessager{P}{\\shortstack[r]{\n        $\\omega$\\\\\n        $(x,y)$ s.t. $R(x,y)=1$\n    }}{$\\pi = \\mathcal{P}rove(\\omega, y, x)$}{V}{\\shortstack[l]{\n        $\\tau, y' \\in L$\\\\\n        $Ver(\\tau,y)=\\tilde{\\pi}\\in P$\\\\\n        check if $\\pi = \\tilde{\\pi}$\n        %Object: $x$ \\\\\n        %Function: $f$ \\\\\n        %$(pk, sk) \\pickUAR \\mathcal{KG}en$ \\\\\n        %$c \\pickUAR Enc(pk, x)$\n    }}\n    \n\\end{cryptosequence}\n\nThe purpose of a proof system is to give a way to convince someone (the ``verifier'') that someone else (the ``prover'') knows something (the ``statement'' $y$), and nothing more, to no one else. The proof can be computed in two different ways, this is the core notion of \\emph{zero-knowledge}, $\\neg \\tau \\implies \\textsc{zk}$\n\n\\subsubsection{Properties}\n\n\\begin{itemize}\n    \\item \\textit{honest people} \\textbf{Completeness}:\n    \\[\n        \\forall y \\in L, \\forall (\\omega, \\tau) \\pickUAR \\mathcal{S}etup(1^\\lambda) \\implies \\mathcal{P}rove(\\omega, y, x) = \\mathcal{V}erify(\\tau, y)\n    \\]\n    \\item \\textit{(stronger, against malicious prover)} \\textbf{Soundness}: It is hard to produce a valid proof for any $y \\notin L$\n    \\item \\textit{(characteristic, against malicious verifier)} \\textbf{Zero-knowledge}: Proof for $x$ can be simulated without knowing $x$ itself\n\\end{itemize}\n\n\n\\begin{definition}[$t$-universality, or $t - 1$ simulation soundness]\n    % Designated verifier non-interactive zero-knowledge\n    Let $\\Pi$ be a \\textsc{dv-nizk} scheme; it is \\textit{t-universal} iff for any distinct $y_{1 \\upto t} \\notin L$ we have: \n    \\[\n        (\\omega, \\mathcal{V}erify(\\tau, y_1), \\ldots, \\mathcal{V}erify(\\tau, y_{t})) = (\\omega, v_1, \\ldots, v_t)\n    \\]\n    where $(\\omega, \\tau) \\pickUAR \\mathcal{S}etup(1^\\lambda)$ and $v_{1 \\upto t} \\pickUAR \\mathcal{P}roof$, where $\\mathcal{P}roof$ is the proofs' space.\n\\end{definition}\n\n\\subsubsection{Enriching a proof system}\n\nWe can ``enrich'' a \\textsc{dv-nizk} scheme with labels $l \\in \\binary^*$. Suppose to have the following:\n\\[\n    L' = L \\| \\binary^* = \\{(y, l) \\in L \\times \\binary^*\\}\n\\]\nThen our scheme changes, because the statements are now compositions of a label $l$ along with te actual statement $y$; for the \\textit{t-universality} property, we can now consider two distinct $(y_i, l_i)$.\n\n\\subsubsection{Membership-hard language}\n\n\\begin{definition}\n    Language $L$ is \\emph{membership-hard} iff there exists a language $\\overline{L}$ such that:\n    \\begin{enumerate}\n        \\item $L \\cap \\overline{L} = \\emptyset$\n        \\item $\\exists \\textsf{\\textup{Sample}} \\in \\ppt$ outputting $y \\pickUAR \\mathcal{Y}$ together with $x \\in \\overline{X}$ such that $R(y, x) = 1$\n        \n        (therefore $(y, x) \\pickUAR \\textsf{\\textup{Sample}}(1^{\\lambda})$)\n        \\item $\\exists \\overline{\\textsf{\\textup{Sample}}} \\in \\ppt$ outputting $y \\pickUAR \\overline{L}$\n        \\item $\\{y : (y, x) \\pickUAR \\textsf{\\textup{Sample}}(1^{\\lambda})\\} \\compindist \\{y : y \\pickUAR \\overline{\\textsf{\\textup{Sample}}}(1^{\\lambda})\\}$\n    \\end{enumerate}\n    \n\\end{definition}\n\n", "meta": {"hexsha": "14dd2b8c0643fcd33a66be93dec54f4e93d0c067", "size": 13164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_16.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_16.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_16.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": 43.0196078431, "max_line_length": 578, "alphanum_fraction": 0.6144788818, "num_tokens": 4289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743735019594, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.6230977651777911}}
{"text": "\\label{s:appendix:tight-binding}\nIn this appendix,\nwe review the assumptions of the tight-binding model\nas derived from Bloch's theorem.\nWe denote the position and momentum operators\nrespectively by $\\vc{Q}$ and $\\vc{P}$.\n\n\\section{Transition operators}\n\nWe first define the position-space translation operator,\n$T \\of{\\vc{r}} = e^{- i \\vc{r} · \\vc{P}}$,\nand the momentum-space translation operator,\n$T_{\\vK} = e^{- i \\vc{k} · \\vc{Q}}$.\nWe assume zero magnetic field.%\n\\footnote{%\n  For nonzero field, much of the following can be recast\n  in terms of the magnetic translation operators~\\cite{PhysRev.133.A1038}.\n}\nEach has a simple inverse:\n$T^{-1} \\of{\\vc{r}} = T \\of{- \\vc{r}}$\nand\n$T_{\\vK}^{-1} = T_{- \\vK}$.\nWe also note the derivatives:\n$∇_{\\vK} T_{\\vK} = - i \\vc{Q} T_{\\vK}$\nand\n$∇_{\\vK} T^{-1}_{\\vK} = i \\vc{Q} T^{-1}_{\\vK}$.\n\nWe can compute a useful commutation relation of these translations operators.\nApplication of the Baker–Campbell–Hausdorff formula gives\n\\begin{subequations}\n  \\begin{align}\n    T \\of{\\vc{r}} T_{\\vK}\n    & = e^{- i \\left( \\vc{r} · \\vc{P} + \\vc{k} · \\vc{Q} \\right)\n      - \\frac{1}{2} \\left[ \\vc{r} · \\vc{P}, \\vc{k} · \\vc{Q} \\right]}, \\\\\n    T_{\\vK} T \\of{\\vc{r}}\n    & = e^{- i \\left( \\vc{r} · \\vc{P} + \\vc{k} · \\vc{Q} \\right)\n      + \\frac{1}{2} \\left[ \\vc{r} · \\vc{P}, \\vc{k} · \\vc{Q} \\right]}.\n  \\end{align}\n\\end{subequations}\nOnly a single commutator appears above since\n$\\left[ \\vc{r} · \\vc{P}, \\vc{k} · \\vc{Q} \\right] = - i \\vc{r} · \\vc{k}$.\nSubstituting this gives\n\\begin{equation}\n  \\label{eq:translations:commutation}\n  T \\of{\\vc{r}} T_{\\vK}\n  = e^{-i \\vc{r} · \\vc{k}} T_{\\vK} T \\of{\\vc{r}}.\n\\end{equation}\n\n\\section{Bloch Hamiltonian}\n\nGiven a Hamiltonian $H$ and a set of $N$ lattice vectors\n$\\left\\{ \\vRn{n} \\right\\}$ such that the Hamiltonian\ncommutes with each $T \\of{\\vRn{n}}$,\nwe may choose a set of common eigenvectors according to Bloch's theorem,\n\\begin{subequations}\n  \\begin{align}\n    H \\Ket{ψ_{n \\vK}}\n    & = E_{n \\vK} \\Ket{ψ_{n \\vK}}, \\\\\n    T \\of{\\vRn{m}} \\Ket{ψ_{n \\vK}}\n    & = e^{-i \\vK · \\vRn{m}} \\Ket{ψ_{n \\vK}}.\n  \\end{align}\n\\end{subequations}\nGiven periodic boundary conditions,\nthe set of allowed $\\vK$ becomes countable\nand may be restricted to the first Brillouin zone\ndue to the periodicity of the eigenvalues\nwith respect to translation by a reciprocal lattice vector $\\vc{G}$.\nFor each $\\vK$, the transformation\n$\\Ket{u_{n \\vK}} = T_{\\vK} \\Ket{ψ_{n \\vK}}$\ngives a set of states which are invariant under lattice translations, i.e.,\nusing \\cref{eq:translations:commutation},\n$T \\of{\\vRn{m}} \\Ket{u_{n \\vK}} = \\Ket{u_{n \\vK}}$.\nA general operator then transforms according to\n$A_{\\vK} = T_{\\vK} A T_{\\vK}^{-1}$.\nNote that the derivative of a transformed operator may be computed as\n\\begin{equation}\n  ∇_{\\vK} A_{\\vK}\n  = ∇_{\\vK} \\left( T_{\\vK} A T_{\\vK}^{-1} \\right)\n  = i \\left[ A_{\\vK}, \\vc{Q} \\right].\n\\end{equation}\n\n\\section{Tight-binding approximation}\n\nIn the tight biding model, one assumes there exists a finite set\n$\\left\\{ \\Ket{φ_ν} \\right\\}$ of relevant atomic orbitals.\nThe corresponding Bloch orbital states,\n\\begin{equation}\n  \\Ket{ϕ_{ν \\vK}}\n  = \\frac{1}{\\sqrt{N}}\n    ∑_{n = 1}^N e^{i \\vK ⋅ \\vRn{n}}\n    T \\of{\\vRn{n}} \\Ket{φ_ν},\n\\end{equation}\nprovide a complete bases for the space\nof Bloch eigenstates $\\left\\{ \\Ket{ψ_{n \\vK}} \\right\\}$, i.e.,\n\\begin{subequations}\n  \\begin{align}\n    \\Ket{ψ_{n \\vK}} & = ∑_ν M_{\\vK}^{ν n} \\Ket{ϕ_{ν \\vK}}, \\\\\n    \\Ket{ϕ_{ν \\vK}} & = ∑_n W_{\\vK}^{n ν} \\Ket{ψ_{n \\vK}},\n  \\end{align}\n\\end{subequations}\nwith $M_{\\vK}^{ν n} = \\cc{W}_{\\vK}^{ν n}$.\nThe second overlap term in\n\\begin{equation}\n  \\Braket{ϕ_{ν' \\vK} | ϕ_{ν \\vK}}\n  = \\Braket{φ_{ν'} | φ_ν}\n  + ∑_{\\vRn{n} ≠ 0}^N e^{i \\vK ⋅ \\vRn{n}}\n    \\Braket{φ_{ν'} | T \\of{\\vRn{n}} | φ_ν}\n\\end{equation}\nis small, thus the states\n$\\left\\{ \\Ket{φ_ν} \\right\\}$ are assumed formally orthonormal.\n\nSince each $\\Ket{ϕ_{n k}}$ satisfies\n\\begin{equation}\n  T \\of{\\vRn{m}} \\Ket{ϕ_{ν \\vK}}\n  = e^{-i \\vK · \\vRn{m}} \\Ket{ϕ_{ν \\vK}},\n\\end{equation}\nthe transformed orbital states\n$\\Ket{v_{n \\vK}} = T_{\\vK} \\Ket{ϕ_{n k}}$\nare invariant under lattice translations.\nOne typically knows the matrix elements\nof an effective Hamiltonian\nin the bases of these periodic Bloch orbitals,\n\\begin{equation}\n  H_{\\vK}^{ν ν'}\n  = \\Braket{v_{ν \\vK} | H_{\\vK} | v_{ν' \\vK}}\n  = ∑_n \\cc{W}_{\\vK}^{n ν} E_{n \\vK} W_{\\vK}^{n ν'},\n\\end{equation}\nwhich determines the coefficients $M_{\\vK}^{ν n}$.\n", "meta": {"hexsha": "1f913dc06c7008436bce0f1088ff50016822fcfa", "size": 4437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/_appendix-tight-binding.tex", "max_stars_repo_name": "razor-x/doctoral-thesis", "max_stars_repo_head_hexsha": "b48dd021d3b796537f2582967a790ca323b9f86d", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-25T23:01:11.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-25T23:01:11.000Z", "max_issues_repo_path": "tex/_appendix-tight-binding.tex", "max_issues_repo_name": "evansosenko/doctoral-thesis", "max_issues_repo_head_hexsha": "b48dd021d3b796537f2582967a790ca323b9f86d", "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": "tex/_appendix-tight-binding.tex", "max_forks_repo_name": "evansosenko/doctoral-thesis", "max_forks_repo_head_hexsha": "b48dd021d3b796537f2582967a790ca323b9f86d", "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": 34.3953488372, "max_line_length": 77, "alphanum_fraction": 0.6256479603, "num_tokens": 1812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6230977477658319}}
{"text": "\n%=======================================================================  solving_equations\n\\section{Solving equations}\n\\label{sec:solving_equations}\n\t\n\tMost math skills boil down to being able to manipulate and solve equations.\n\tSolving an equation means finding the value of the unknown in the equation.  \n\n\tCheck this \\pgt{}{shit} out:\n\t\\[\n\t x^2-4=45.\n\t\\]\n\tTo solve the above equation is to answer\n\tthe question ``What is $x$?''\n\tMore precisely, we want to find the number that can take the \n\tplace of $x$ in the equation so that the equality holds.\n\tIn other words, we're asking,\n\t\\[\n\t  \\text{``Which number times itself minus four gives 45?''}\n\t\\]\n\tThat is quite a mouthful, don't you think? \n\tTo remedy this verbosity, mathematicians often use specialized symbols to describe math operations.\n\tThe problem is that these specialized symbols can be very confusing. \n\tSometimes even the simplest math concepts are inaccessible if you don't know what the symbols mean. \n\n\tWhat are your feelings about math, dear reader? Are you afraid of it? \n\tDo you have anxiety attacks because you think it will be too difficult for you?\n\tChill! Relax, my brothers and sisters. There's nothing to it.\n\tNobody can magically guess the solution to an equation immediately.\n\tTo find the solution, you must break the problem into simpler steps.\n\tLet's walk through this one together.\n\n\tTo find $x$, we can manipulate the original equation, \n\ttransforming it into a different equation (as true as the first) that looks like this:\n\t\\[\n\t  x \\; = \\textrm{ only numbers.}\n\t\\]\n\n\t\\noindent\n\tThat's what it means to \\emph{solve} an equation:\n\tthe equation is solved because the unknown is isolated on one side,\n\twhile the constants are grouped on the other side.\n\tYou can type the numbers on the right-hand side into a calculator and obtain the numerical value of $x$.\n\n\tBy the way, before we continue our discussion,\n\tlet it be noted: the equality symbol ($=$) means that all that is to the left of $=$ \n\tis equal to \n\tall that is to the right of $=$. \n\tTo keep this equality statement true,  \n\t\\textbf{for every change you apply to the left side of the equation, \n\tyou must apply the same change to the right side of the equation}.\n\n\t% Keeping that rule in mind,\n\tTo find $x$,\n\twe need to manipulate the original equation into its final form,\n\tsimplifying it step by step until it can't be simplified any further.\n\tThe only requirement is that the manipulations we make transform one true equation into another true equation.\n\tIn this example,\n\tthe first simplifying step is to add the number four to both sides of the equation:\n\t\\[\n\t \tx^2-4  \\; + 4  \t=\t45    \\; + 4, \t    \\\\\n\t\\]\n\twhich simplifies to\n\t\\[\n\t\tx^2 \t \t\t=\t49.\n\t\\]\n\tNow the expression looks simpler, yes?\n\tHow did I know to perform this operation? \n\tI wanted to ``undo'' the effects of the operation $-4$.\n\tWe undo an operation by applying its \\emphindexdef{inverse}.\n\tIn the case where the operation is the subtraction of some amount,\n\tthe inverse operation is the addition of the same amount.\n\n\tWe're getting closer to our goal of \\emph{isolating} $x$ on one side of the equation,\t\t\t\t\t\t\t\\index{isolate}\n\tleaving only numbers on the other side.\n\tThe next step is to undo the square $x^2$ operation.\n\tThe inverse operation of squaring a number $x^2$ is to take its square root $\\sqrt{\\phantom{a}\\; }$,\n\tso that's what we'll do next. We obtain\n\t\\[ \n\t   \\sqrt{x^2} \t\t= \t\\sqrt{49}.\n\t\\]\n\tNotice how we applied the square root  to both sides of the equation? \n\tIf we don't apply the same operation to both sides, we'll break the equality!\n\n\tThe equation $\\sqrt{x^2}= \\sqrt{49}$ simplifies to \n\t\\[\n\t \t|x|\t= \t7.\n\t \\]\n\tWhat's up with the vertical bars around $x$?\n\tThe notation $|x|$ stands for the \\emph{absolute value} of $x$,\t\t\t\t\t\t\t\t\t\t\t\\index{absolute value}\n\twhich is the same as $x$ except we ignore the sign that indicates whether $x$ is positive or negative. \n\tFor example $|5|=5$ and $|-5|=5$, too.\n\tThe equation $|x|=7$ indicates that both $x=7$ and $x=-7$ satisfy the equation $x^2 = 49$.\n\tSeven squared is 49, $7^2=49$, and negative seven squared is also 49, $(-7)^2 = 49$,\n\tbecause the two negative signs cancel each other out.\n\n\tThe final solutions to the equation $x^2-4=45$ are\t\t\t\t\t\t\t\t\t\t\t\t\t\\index{solution set}\n\t\\[\n\t x  = 7 \\qquad \\textrm{and} \\qquad   x=  - 7.\n\t\\]\n\tYes, there are \\emph{two} possible answers. \n\tYou can check that both of the above values of $x$ satisfy the initial equation $x^2-4=45$.\n\n\t\\bigskip\n\n\tIf you are comfortable with all the notions of high school math\n\tand you feel you could have solved the equation $x^2-4=45$ on your own,\t\t% TODOv6: special comment for readers who expected there to be two solutions\n\tthen you can skim through this chapter quickly.\n\tIf on the other hand you are wondering how the squiggle killed the power two,\n\tthen this chapter is for you!\n\tIn the following sections we will review all the essential concepts from\n\thigh school math that you will need to power through the rest of this book.\n\tFirst, let me tell you about the different kinds of numbers.\n\n", "meta": {"hexsha": "6e10e4120665f8a008a35b910ced0a317431b929", "size": 5051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sources/original/01_math/01.solving_equations.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/01.solving_equations.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/01.solving_equations.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": 43.9217391304, "max_line_length": 150, "alphanum_fraction": 0.7113442883, "num_tokens": 1340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891348788759, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6230503030317363}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\n\\title{\\bf{Drag Polar Analysis}}\n\\author{Nicholas Malaya \\\\ Institute for Computational Engineering and Sciences \\\\ University of Texas at Austin} \\date{}\n\n\\begin{document}\n\\maketitle\n\n\\newpage\n\nThe power extracted by the turbine is, \n\\begin{equation}\n P = \\Omega Q\n\\end{equation}\nwhere the torque, Q, is, \n\\begin{equation}\n Q = A_R \\int_0^{2\\pi} \\int_{r_{\\text{min}}}^{r_{\\text{max}}} F''_{\\tau}\\, r\\, dr d\\theta.\n\\end{equation}\nHere, $A_R$ is the relative area coefficient which is, \n\\begin{equation}\nA_R = \\frac{c B (r_{\\text{max}}-r_{\\text{min}})}{\\pi(r_{\\text{max}}^2-r_{\\text{min}}^2)}\n\\end{equation}\nwhere B is the number of blades, $r_{\\text{max}}$ and $r_{\\text{min}}$\nare the turbine radii, and $F''_{\\tau}$ is the force per unit\narea on the turbine, which is, \n\\begin{equation}\n F''_{\\tau} = \\frac{F_{\\tau}}{cl}= \\frac{1}{2}\\rho U_R^2 \\, C_{\\tau}.\n\\end{equation}\nwith $U_R$ the magnitude of relative velocity and $c$ is the blade chord\nlength, which is assumed to be constant (not a function of the radius,\nfor instance). Finally, $C_{\\tau}$ is the tangential force coefficient,\nwhich depends on the local lift and drap coefficients, as well as the\nflow angle, $\\phi$, \n\\begin{equation}\n C_{\\tau} = C_L \\,\\text{sin}(\\phi) + C_D \\,\\text{cos}(\\phi)\n\\end{equation}\nCombining the equations above results in an expression for the power\nthat explicitly depends on the lift and drag coefficients, \n\\begin{equation*}\n P = \\frac{\\Omega \\rho c B (r_{\\text{max}}-r_{\\text{min}})}{2 \\pi(r_{\\text{max}}^2-r_{\\text{min}}^2)}\n\\int_0^{2\\pi}\n\\int_{r_{\\text{min}}}^{r_{\\text{max}}} U_R(r,\\theta,\\Omega)^2 \\left(C_L\n\t\t\t\t\t\t     \\,\\text{sin}(\\phi)\n\t\t\t\t\t\t     + C_D\n\t\t\t\t\t\t     \\,\\text{cos}(\\phi)\n\t\t\t\t\t\t    \\right) r\\,dr d\\theta. \n\\end{equation*}\nWe lump the constant terms together, $E_{\\tau} = \\frac{\\Omega \\rho c B (r_{\\text{max}}-r_{\\text{min}})}{2 \\pi(r_{\\text{max}}^2-r_{\\text{min}}^2)}$ and separate this equation, \n\\begin{align}\n P_L = E_\\tau\n \\int_0^{2\\pi}\n  \\int_{r_{\\text{min}}}^{r_{\\text{max}}} U_R(r,\\theta,\\Omega)^2 \\, C_L(\\phi,r)\n \\,\\text{sin}(\\phi)\\, r\\,dr d\\theta,  \\label{lift} \\\\\n P_D = E_\\tau\n \\int_0^{2\\pi}\n  \\int_{r_{\\text{min}}}^{r_{\\text{max}}} U_R(r,\\theta,\\Omega)^2 \\, C_D(\\phi,r) \\,\\text{cos}(\\phi)\\, r\\,dr d\\theta. \\label{drag}\n\\end{align}\nNote that we have assumed $C_D = C_D(\\phi,r)$ and $C_L = C_L(\\phi,r)$,\nnamely, that the coefficients vary with the flow direction and may vary\nradially, due to twisting the blade angle. Furthermore, the flow\ndirection, $\\phi$, varies with the location as well as the blade speed,\nin that $\\phi=\\phi(r,\\theta,\\Omega)$. The relative velocity is the\nquantity, $U_R = U - U_\\tau$, e.g. the difference in velocity between\nthe turbine and the flow. The turbine has no axial velocity ($w_\\tau = 0$) and a\nconstant rotation speed, and so the two components of velocity in the\nplane of rotation can be expressed as,\n\\begin{align}\n u_\\tau = \\Omega \\,r\\, \\text{sin}(\\theta)\\\\\n v_\\tau = \\Omega \\,r\\, \\text{cos}(\\theta)\n\\end{align}\n\nOur objective is now to discover what these unknown functions of lift\nand drag are. To do this, we specify an optimization problem such that, \n\\begin{equation*} \n \\text{Max } P(C_L,C_D) \\quad \\text{ subject to: }\n  \\begin{cases}\n   |C_L| < C_L^{\\text{Max}}, \\\\\n   0 < C_D < C_D^{\\text{Max}}. \\\\\n  \\end{cases}\n\\end{equation*}\n\nIn words, the drag must be specified to be greater than zero, but\nthe lift can be negative. For these conditions, we are interested in\nlargest attainable values. For the drag coefficient, $C_D^{\\text{Max}}$\nis two. % refmunson \nThis corresponds to a flat plate perpendicular to the flow.\nThe lift coefficient peak is about 1.75. This design is not necessarily\nphysically realizable, but represents an absolute maximum. \n\n%\n% does this argument still work?!?\n%\nThe integral shown in Equation \\ref{lift} above can be bounded by \nSchwarz's Inequality,  \n\\begin{align*}\n  \\left[\n    \\int_0^{2\\pi}\n    \\int_{r_{\\text{min}}}^{r_{\\text{max}}} C_L(\\phi,r)\\, U_R(r,\\theta,\\Omega)^2\n \\,\\text{sin}(\\phi)\\, r\\,dr d\\theta \\right]^2 \\le \\\\\n  \\int_0^{2\\pi} \\int_{r_{\\text{min}}}^{r_{\\text{max}}} C_L^2(\\phi,r) dr d\\theta\\,\n  \\int_0^{2\\pi} \\int_{r_{\\text{min}}}^{r_{\\text{max}}} U_R(r,\\theta,\\Omega)^4 \n \\,\\text{sin}^2(\\phi)\\, r^2\\,dr d\\theta.\n\\end{align*}\nIn this way the quantity,\n\\begin{equation}\n  \\int_0^{2\\pi}\n \\int_{r_{\\text{min}}}^{r_{\\text{max}}} C_L^2(\\phi,r) dr d\\theta, \n\\end{equation}\nis clearly maximized when $C_L(\\phi,r) = C_L^{\\text{max}}$. \nThe result for Equation \\ref{drag} is identical. \nTherefore, our lift/drag functions may be expressed as,\n\\begin{align*} \n C_D(\\phi) = \\bar C_D \\, \\psi(\\phi) \n  \\begin{cases}\n   \\psi(\\phi) = 1 \\text{ if sin}(\\phi) > 0,   \\\\\n   0 \\text{ else} \\\\\n  \\end{cases} \\\\\n C_L(\\phi) = \\bar C_L \\, \\Psi(\\phi) \n  \\begin{cases}\n   \\Psi(\\phi) = 1 \\text{ if cos}(\\phi) > 0,   \\\\\n   -1 \\text{ else}. \\\\\n  \\end{cases}\n\\end{align*}\nWhere $\\bar C_L = 1.7$ and $\\bar C_D = 2.0$.\n\n%Thus, the drag polars\n%have the form, \n%\\begin{align*} \n% &C_L(\\phi) = \n%  \\begin{cases}\n%    1.75& \\quad 0^{\\circ} \\le \\phi \\le 180^{\\circ}, \\\\\n%   -1.75& \\quad 180^{\\circ} \\le \\phi \\le 360^{\\circ}.  \\\\\n%  \\end{cases}\\\\\n% &C_D(\\phi) = \n%  \\begin{cases}\n%    2.0& \\quad -90^{\\circ} \\le \\phi \\le 90^{\\circ}, \\\\\n%      0& \\quad 90^{\\circ} \\le \\phi \\le 270^{\\circ}.  \\\\\n%  \\end{cases}\\\\\n%\\end{align*}\nThe plot of these drag polars are shown in Figure \\ref{drags}. \n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/drags}\n    \\caption{The idealized drag polars.} \n    \\label{drags}\n  \\end{center}\n\\end{figure}\n\n\n\\newpage\n\\section{Questions}\n\n\\begin{itemize}\n \\item Does this need regularization to ensure well-posedness?\n \\item Boundary conditions are periodic\n \\item What about supporting twist? (e.g. $\\beta = \\beta(r)$)\n \\item Can we constrain $C_L, C_D$?\n \\item Is this just linear programming?\n\\end{itemize}\nBetz limit is 16/27\n\\end{document}\n", "meta": {"hexsha": "fe4e9abed97a5870f5fb808973741acaef3d3fcc", "size": 5979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/causa/drag_polars.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/causa/drag_polars.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/causa/drag_polars.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 36.0180722892, "max_line_length": 175, "alphanum_fraction": 0.6519484864, "num_tokens": 2138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6230502976241328}}
{"text": "\\documentclass{article}\n    % General document formatting\n    \\usepackage[margin=0.7in]{geometry}\n    \\usepackage[parfill]{parskip}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\usepackage{tikz}\n    \\usepackage{fancyhdr}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Edgar Jacob Rivera Rios - A01184125}\n\n\\begin{document}\n\\section*{2.2.1 Propositional Logic.}\nProve the following logical equivalences making use of truth tables:\n\\renewcommand{\\labelenumi}{\\alph{enumi})}\n\\begin{enumerate}\n    \\item $A \\wedge (B \\vee C) \\equiv (A \\wedge B) \\vee (A \\wedge C)$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{C} & \\textbf{$A \\wedge (B \\vee C)$} & \\textbf{$(A \\wedge B) \\vee (A \\wedge C)$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 & 1\\\\\n            \\hline\n            1 & 1 & 0 & 1 & 1\\\\\n            \\hline\n            1 & 0 & 1 & 1 & 1\\\\\n            \\hline\n            1 & 0 & 0 & 0 & 0\\\\\n            \\hline\n            0 & 1 & 1 & 0 & 0\\\\\n            \\hline\n            0 & 1 & 0 & 0 & 0\\\\\n            \\hline\n            0 & 0 & 1 & 0 & 0\\\\\n            \\hline\n            0 & 0 & 0 & 0 & 0\\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n    \\item $A \\vee B \\equiv \\neg(\\neg A \\wedge \\neg B)$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$A \\vee B$} & \\textbf{$\\neg(\\neg A \\wedge \\neg B)$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 1 & 1 \\\\\n            \\hline\n            0 & 1 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 0 & 0 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n    \\item $A \\wedge B \\equiv \\neg(\\neg A \\vee \\neg B)$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$A \\wedge B$} & \\textbf{$\\neg(\\neg A \\vee \\neg B)$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 0 & 0 \\\\\n            \\hline\n            0 & 1 & 0 & 0 \\\\\n            \\hline\n            0 & 0 & 0 & 0 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n    \\item $A \\rightarrow B \\equiv \\neg A \\vee B$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$A \\rightarrow B$} & \\textbf{$\\neg A \\vee B$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 0 & 0 \\\\\n            \\hline\n            0 & 1 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 1 & 1 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n    \\item $A \\rightarrow B \\equiv \\neg(A \\wedge \\neg B)$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$A \\rightarrow B$} & \\textbf{$\\neg(A \\wedge \\neg B)$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 0 & 0 \\\\\n            \\hline\n            0 & 1 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 1 & 1 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n    \\newpage\n\n    \\item $((A \\oplus B) \\oplus B ) \\equiv A$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$((A \\oplus B) \\oplus B )$} & \\textbf{$A$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 1 & 1 \\\\\n            \\hline\n            0 & 1 & 0 & 0 \\\\\n            \\hline\n            0 & 0 & 0 & 0 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n    \\item $((A \\leftrightarrow B) \\leftrightarrow B) \\equiv A$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c||c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$((A \\leftrightarrow B) \\leftrightarrow B)$} & \\textbf{$A$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 1 & 1 \\\\\n            \\hline\n            0 & 1 & 0 & 0 \\\\\n            \\hline\n            0 & 0 & 0 & 0 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n\n\\end{enumerate}\n\n\\section*{2.2.2 Propositional Logic.}\nProve or disprove making use of truth tables:\n\\begin{enumerate}\n    \\item $\\models (A \\rightarrow B) \\vee (B \\rightarrow A)$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$(A \\rightarrow B) \\vee (B \\rightarrow A)$}\\\\\n            \\hline\n            1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 1 \\\\\n            \\hline\n            0 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 1 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n    \\\\As we can see, this is a Tautology, so is proved\n\n    \\item $\\models ((A \\rightarrow B) \\rightarrow B) \\rightarrow B$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$((A \\rightarrow B) \\rightarrow B) \\rightarrow B$}\\\\\n            \\hline\n            1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 0 \\\\\n            \\hline\n            0 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 1 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n    \\\\As we can see, there is a combination that it's not true, so this fails\n\n    \\item $\\models (A \\leftrightarrow B) \\leftrightarrow (A \\leftrightarrow (B \\leftrightarrow A))$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{$ (A \\leftrightarrow B) \\leftrightarrow (A \\leftrightarrow (B \\leftrightarrow A))$}\\\\\n            \\hline\n            1 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 1 \\\\\n            \\hline\n            0 & 1 & 0 \\\\\n            \\hline\n            0 & 0 & 0 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n    \\\\As we can see, there is two combinations that are not true, so this fails\n    \\newpage\n\n    \\item $\\models ((A \\wedge B) \\rightarrow C) \\rightarrow ((A \\rightarrow C) \\vee (B \\rightarrow C))$\n    \\begin{table}[h!]\n        \\centering\n        \\begin{tabular}{|c|c|c|c|}\n            \\hline\n            \\textbf{A} & \\textbf{B} & \\textbf{C}  & \\textbf{$((A \\wedge B) \\rightarrow C) \\rightarrow ((A \\rightarrow C) \\vee (B \\rightarrow C))$}\\\\\n            \\hline\n            1 & 1 & 1 & 1 \\\\\n            \\hline\n            1 & 1 & 0 & 1 \\\\\n            \\hline\n            1 & 0 & 1 & 1 \\\\\n            \\hline\n            1 & 0 & 0 & 1 \\\\\n            \\hline\n            0 & 1 & 1 & 1 \\\\\n            \\hline\n            0 & 1 & 0 & 1 \\\\\n            \\hline\n            0 & 0 & 1 & 1 \\\\\n            \\hline\n            0 & 0 & 0 & 1 \\\\\n            \\hline\n        \\end{tabular}\n    \\end{table}\n    \\\\As we can see, this is a Tautology, so is proved\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "0d827a799b9a2f4d597e2a1047a249cf91447422", "size": 7019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/Homework2_2.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/Homework2_2.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/Homework2_2.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": 28.7663934426, "max_line_length": 148, "alphanum_fraction": 0.413021798, "num_tokens": 2538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145997, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.6230502976241327}}
{"text": "\\section{Measurement Uncertainty Analysis}\n\n\\subsection{Devices Precision}\nThe precision of each devices are shown in Table~\\ref{pres}.\n\\begin{table}\n\t\\centering\n\t\\begin{tabular}{|l|c|c|}\n\t\\hline\n\tDevices & Precision & Unit \t\t\t\t\\\\ \\hline\n\tJolly balance & 0.01 & [cm] \t\t\t\\\\ \\hline\n\tRuler & 0.1 & [cm]\t\t\t\t\t\t\\\\ \\hline\n\tTimer for periods & 0.1 & [ms]\t\t\t\\\\ \\hline\n\tTimer for maximum speed & 0.01 & [ms]\t\\\\ \\hline\n\tCalliper & 0.02 & [mm]\t\t\t\t\t\\\\ \\hline\n\tElectronic scale & 0.01 & [g]\t\t\t\\\\ \\hline\n\t\\end{tabular}\n\t\\caption{Devices precision}\n\\label{pres}\n\\end{table}\n\n\\subsection{Uncertainty in Measurement for Spring Constant}\nFor measuring $L_i$, there is no type-A uncertainty.\nThus, \n$$ u_{L_0} = 0.01 \\quad [cm] $$\n$$ u_{L_i} = 0.01 \\quad [cm] $$\n$$ u_{L_i,r} = \\frac{0.01}{2.01} \\cdot 100 \\% = 0.49 \\quad [cm] $$\nFor measuring $m_i$, there is no type-A uncertainty.\nThus, $$ u_m = 0.01 \\quad [g] $$\n\n$$ u_{\\Delta L}=\\sqrt{(\\frac{\\partial \\Delta L}{\\partial L_i})^2\\cdot (u_{L_i})^2+(\\frac{\\partial \\Delta L}{\\partial L_0})^2\\cdot (u_{L_0})^2}\\approx1.4\\times10^{-4} \\quad m $$\n\nThe uncertainty of the gravity force measurement $u_{W}$ of $W=mg$ is\n$$   \\frac{\\partial W}{\\partial m} = g =9.794 \\quad kg\\cdot m/s^2        $$\n$$   u_m = \\Delta_{dev}=0.01 \\quad g\t\t\t\t                     $$\n$$   u_{W} = \\sqrt{(\\frac{\\partial W}{\\partial m})^2 \\cdot \n(u_m)^2} = \\sqrt{ {(9.794)^2\\times (1\\times10^{-5})^2}} \n \\approx 1 \\times10^{-4} \\quad N\t\t\t\t\t\t\t\t\t\t $$\n\n\n$$ k_1 = 2.3311 \\pm 0.013  N/m , \\quad u_{k_1,r} = 0.55 \\% $$\n$$ k_2 =  2.3206 \\pm 0.0105  N/m , \\quad u_{k_2,r} = 0.45 \\% $$\n$$ k_3 = 1.165 \\pm 0.0380  N/m , \\quad u_{k_3,r} = 3.26 \\% $$\n\nFor $k_{3,theory}$  calculated from theory, \n$$ k_{3,theory} = \\frac{k_1 \\cdot k_2 }{k_1 + k_2} =  1.1629 $$ \n$$ u_{k_{3,theory}}=\\sqrt{\n\t (\\frac{\\partial k_{3,theory} }{\\partial k_1})^2 \\cdot (u_{k_1})^2\n\t+(\\frac{\\partial k_{3,theory} }{\\partial k_2})^2 \\cdot (u_{k_2})^2 }\n\t= 0.0006 \\quad N/m  $$\n$$   u_{k_{3,theory},r} = \\frac{0.0006 }{1.1629} \\cdot 100 \\% =0.05 \\%  $$\n\n\\input{part/6mua1}", "meta": {"hexsha": "c32842075a0e16ced5cc65d5c265adbb4a72bb9a", "size": 2032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E3/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": "E3/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": "E3/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": 39.0769230769, "max_line_length": 176, "alphanum_fraction": 0.5792322835, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6230502973386742}}
{"text": "\\chapter{Coordinate Transformations}\nLet's consider our picture of spacetime as we understand in currently.\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\\end{figure}\n\\noindent\nConsider the point $Q$.\nWe can say that $Q$ has coordinates $(q^0, q^1, q^2, q^3) = (q^\\mu)$.\nRemember that, when dealing with coordinates, the superscript doesn't mean that this transforms like a contravariant vector --- it's just a (canonical) method of indexing the coordinates, and nothing more.\nRight now, we are using the $x^\\mu$ coordinate system, so each $q^\\mu$ is measured with respect to the coordinate lines we've drawn here.\nWe will introduce a shorthand notation to refer to the coordinates of a point with respect to certain coordinates $x^\\mu$:\n\\[ x^\\mu(Q) = x(Q) = (q^0, q^1, q^2, q^3). \\]\nIf it is understood what dimensions we need to represent the coordinates of a point, or we don't care about the distinction, we can simply shorten $x^\\mu(Q)$ to $x(Q)$.\n\n\\subsection{The Tangent and Cotangent Spaces}\nWe begin with a really simple renaming; up until now, we've been creating our picture of spacetime and then assigning to each point $P$ a vector space $V_P$ a dual space $V^*_P$.\nWe defined the basis for $V_P$ to be the collection of differential operators $\\{\\bm{\\partial}_\\mu\\}$, and chose a basis $\\{\\vec{d}x^\\nu\\}$ for $V^*_P$ such that $\\langle \\vec{d}x^\\nu, \\bm{\\partial}_\\mu \\rangle = \\delta^\\nu_\\mu$.\nWe're now going to make the small change of referring to the vector space as the \\emph{tangent space} $T_P$, and the dual space as the \\emph{cotangent space} $T^*_P$.\nWe do this because the coordinate basis $\\{\\bm{\\partial}_\\mu\\},\\{\\vec{d}x^\\nu\\}$ is composed of differential operators, which are fundamentally related to the concept of tangency.\nImagine we have some function $\\phi(x)$ on our space time and some operator $\\mathcal{L} \\in T_P$.\nIf a vector (our operator $\\mathcal{L}$) acts on $\\phi$ at a point $P$, then we get the directional derivative of $\\phi$ at that point.\nAs a more concrete example, let's say that $\\phi(x) = (x^0)^2 + \\sin x^3$, and our vector field is $\\bm{\\partial}_0 + \\bm{\\partial}_3$. Then at a point $Q$, we would see a value\n\\[ [\\bm{\\partial}_0 + \\bm{\\partial}_3]\\phi(x) = {2x^0 + \\cos x^3\\mid_Q} = 2q^0 + \\cos q^3. \\]\nWhenever you see a tangent space, remember that it uses the coordinate basis.\n\nIt's really important to see that none of this makes any sense until we've established a coordinate system.\nBecause the coordinate basis gives us directional derivatives \\emph{in the direction of the coordinate lines}, if we change our coordinate system our vectors change as well.\n\n\\subsection{Arbitrary Change of Bases}\nGiven a spacetime $\\mathcal{S}$, there are an (uncountably) infinite many ways which we can define a coordinate system.\nThe entire purpose of general relativity is to show the equivalence of these systems, regardless of the basis chosen or the motion of an observer.\nAs it stands now, our spacetime has at every point a tangent space $T_P$ with basis $\\{\\bm{\\partial}_\\mu\\}$, a cotangent space $T^*_P$ with basis $\\{\\vec{d}x^\\nu\\}$, and the tensor product spaces $\\tps{T}^p_q$.\nHowever, as long as we choose a set of linearly independent spanning differential operators from $T_P$, we can create our basis however we like.\nJust as with the bases for our regular vector spaces, we can choose a new basis $\\bm{\\partial}_{\\mu'}$ such that\n\\[ \\bm{\\partial}_{\\mu'} = \\tensor{\\Lambda}{_{\\mu'}^\\mu}\\bm{\\partial}_\\mu, \\]\nwhere $\\tensor{\\Lambda}{_{\\mu'}^\\mu}$ is of course the linear transformation matrix for these two bases.\nTechnically, since the tangent spaces are independent for each point, we no longer have a single transformation matrix, but rather a transformation which is itself a function on spacetime, so a more complete equation would read\n\\[ \\bm{\\partial}_{\\mu'} = \\tensor{\\Lambda}{_{\\mu'}^\\mu} (x^\\mu)\\,\\bm{\\partial}_\\mu. \\]\n\n\\subsection{New Coordinate System}\nThese transformations deal with the case that we want to choose a new basis for our tangent spaces, but we can also consider the case that we change the whole coordinate system itself.\nThis can be thought of visually as drawing new lines on our spacetime diagram to represent our new coordinate system.\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        %% Alt Curves\n        \\draw [name path=alt-1, red] (0,2.16) to [bend left=10] (5.5,3.16);\n        \\draw [name path=alt-2, red] (0,0.94) to [bend left=10] (5.5,1.94);\n        \\draw [name path=alt-3, red] (1.75,4)  to [bend left=10] (1.44,-0.3);\n        \\draw [name path=alt-3, red] (2.75,4)  to [bend left=10] (2.44,-0.3);\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        \n        %% Alt-line Labels\n        \\node [label={[red]$x^{1'}$}] at (0,1.25) {};\n        \\node [label={[red]$x^{2'}$}] at (2.1,-0.3) {};\n    \\end{tikzpicture}\n    \\caption{Our spacetime $\\mathcal{S}$ with coordinate systems $x^\\mu$ and $x^{\\mu'}$.}\n\\end{figure}\nIf we change the coordinates from $(x^\\mu)$ to $(x^{\\mu'})$, we will necessarily change the coordinate basis as well, since $\\{\\bm{\\partial}_\\mu\\}$ is defined with respect to $(x^\\mu)$.\nNotice, however, that the points themselves don't change, although their coordinates in the respective systems will be different.\nThe points don't give a damn about which coordinate system is used.\n\nWhen we talk about changing between coordinate systems, what we really mean are a pair of isomorphisms, $f$ and $f^{-1}$, which act such that\n\\begin{align*}\n    f &: x^\\mu \\to x^{\\mu'}, \\\\\n    f^{-1} &: x^{\\mu'} \\to x^\\mu.\n\\end{align*}\nThis means that if we have a point $Q = (q^\\mu)$ in the $x^\\mu$ system, then $Q$'s coordinates in the $x^{\\mu'}$ system will be $f(q^\\mu) = (q^{\\mu'})$, and that $(q^\\mu) = f^{-1} \\circ f (q^\\mu)$ for all points $Q \\in \\mathcal{S}$.\nAs we previously called $x^\\mu (Q) = x(x)$ the coordinates in the $x^\\mu$ system, we can say that $x^{\\mu'}(Q) = x'(Q)$ are the coordinates in the $x^{\\mu'}$ system.\n\nConsider that if we have a function $\\phi : x^\\mu \\to \\mathbb{R}$ on our spacetime (perhaps representing the strength of an electric field at each point), then we will also need to be able to write some function $\\phi' : x^{\\mu'} \\to \\mathbb{R}$ which gives us the same values for the primed coordinates, so that $\\phi(Q) = \\phi'(Q)$ for all points.\nIf we want to write $\\phi$ as a function of the primed coordinates, we can do so using the coordinate transformations we've just established, so \n\\[ \\phi(x^\\mu) = \\phi(f^{-1}(x^{\\mu'})) = \\phi(x(x^{\\mu'})). \\]\n\nEven though we've changed the coordinate system of our spacetime, and consequently the basis for our tangent spaces, the tangent spaces themselves really don't change in much the same way that the points in spacetime don't really change.\nAll we've done is to rename the points, but we haven't changed any of the physics associated with what goes on at those points.\nWhat we have done is change the way that vectors at each point are \\emph{written}.\nSince $\\{\\bm{\\partial}_\\mu\\} \\not= \\{\\bm{\\partial}_{\\mu'}\\}$, vectors in our tangent space will be written differently depending on which coordinate basis we choose.\nWe \\emph{can}, however, write these new basis vectors as linear combinations of the old basis vectors, which is where the transformation matrix $\\tensor{\\Lambda}{_{\\mu'}^{\\mu}}(x)$ comes in.\nThe the previous section, we were free to choose $\\Lambda(x)$ to be whatever we wanted, since we were just defining a new set of basis vectors while the underlying coordinate system remained the same.\nNow, however, we've added a constraint.\nWe need to find the particular $\\Lambda$ which is implied by the transformation $f$ between coordinate systems.\nIf we choose a particular coordinate transformation $f$, we are then \\emph{forced} to use a particular basis transformation $\\Lambda$ to find $\\{\\bm{\\partial}_{\\mu'}\\}$.\n\n\\subsection{Finding $\\Lambda$ from $f$}\nLet's go back to our function $\\phi(x(x^{\\mu'}))$ on our spacetime.\nSince we want the tangent spaces to remain the same under coordinate transformations, we know that we want\n\\[ \\bm{\\partial}_{\\mu'} \\phi = \\bm{\\partial}_\\mu \\phi \\frac{\\partial}{\\partial{x^{\\mu'}}}x(x^{\\mu'}), \\]\nby a simple chain rule expansion.\nSince $\\phi$ is an arbitrary function, all we really care about is this inner differential, so\n\\[ \\bm{\\partial}_{\\mu'} = \\bm{\\partial}_\\mu \\pdv{}{x^{\\mu'}}x(x^{\\mu'}). \\]\nThis means that \n\n\\[ \\Lambda = \\pdv{}{x^{\\mu'}} x\\qty(x^\\mu) = \\pdv{x^\\mu}{x^{\\mu'}}, \\]\nwe we simplify $x^\\mu = x(x^{\\mu'})$.\nAs a  $4\\times 4$ matrix, we would write $\\Lambda(x)$ as \n\\[ \\Lambda = \n    \\begin{bmatrix}\n        \\pdv{x^0}{x^{0'}} & & \\\\\n        & \\ddots & \\\\\n        & & \\pdv{x^3}{x^{3'}}\n    \\end{bmatrix}.\n\\]\n\\subsection{Transforming the Cotangent Space}\nJust as with our ordinary vector space and dual space, we transform the basis of the cotangent space using the inverse transformation as that of the tangent space, so $\\vec{d}x^{\\mu'} = \\pdv{x^{\\mu'}}{x^\\mu} \\vec{d}x^\\mu$, and use the matrix $\\Lambda^{-1}(x)$.\n\n\\subsection{Requisite Formalism}\nWhen we discussed tensors and vector spaces and tensor product spaces, we did so with a very good degree of formalism.\nThe lessons started ``from the ground up,'' so to speak, and so they covered everything in depth.\nBy comparison, the latter parts of the lessons dealing with spacetime and vector fields and such have not really been covered to the same rigor.\nWrapped up in the notion of ``a spacetime $\\mathcal{S}$ with a tangent space $T$, a cotangent space $T^*$, and the associated tensor product spaces $\\tps{T}^p_q$ affixed to every point'' are the notions of a \\emph{manifold}, a \\emph{fiber bundle}, and a good deal of topology.\nWhile understanding all of that isn't technically necessary to understanding the following sections, it does help give a good foundation for why all the hand-wavy arguments we've made so far are correct.\nIf you want to dive into a some (albeit distracting) mathematical formalism for these topics, now would be a good time to pause this lesson and switch to the ``What is a Manifold'' series, and then come back to complete sections 16--39.\n", "meta": {"hexsha": "afd35276f6ddf259920cfc25e3559bd7c11f4396", "size": 12990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/coord_transforms.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/coord_transforms.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/coord_transforms.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": 70.597826087, "max_line_length": 349, "alphanum_fraction": 0.6512702079, "num_tokens": 3871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.6230502968835516}}
{"text": "\n\\chapter{Preconditioning}\n\\label{chap:precond}\n\n% Let us define the matrix of the linear system \\eqref{eq:mhd_saddle} as $\\mathcal{K}$.\n\n\n\n\nThe linear system \\eqref{eq:mhd_saddle} is typically sparse and of large dimension, hence to efficiently solve for it we use a preconditioned iterative approach as proposed in \\cite{li2010numerical}. We start by reviewing some preconditioning strategies for the incompressible Navier-Stokes and Maxwell subproblems in isolation. From these techniques we will then introduce and  numerically test  preconditioners for the full MHD system.\n\n\\section{Navier-Stokes equations}\n\\label{sec:NSprecond}\n\n\nTo start with, consider the steady state incompressible Navier-Stokes equations in isolation. Let\n\\begin{equation}\n\\label{eq:ns_coeff}\n\\mathcal{K}_{\\rm NS}=\n\\begin{pmatrix}\nF & B^T \\\\\nB & 0\n\\end{pmatrix},\n\\end{equation}\nbe the discretised and linearised Navier-Stokes subproblem where $F~=~A~+~O$. Due to the convection term, $O$, this  system is non-symmetric and we will use GMRES to solve this subproblem \\cite{saad1986gmres}. An excellent choice for a preconditioner for a saddle point system like this is to use a block diagonal or block triangular based preconditioner of the form\n\\begin{equation}\n\\label{eq:ns_pc_upper}\n\\mathcal{M}_{\\rm NS} =\n\\begin{pmatrix}\nF & B^T \\\\\n0 & -S\n\\end{pmatrix},\n\\end{equation}\nwhere the Schur complement $S$ is given by $S=B F^{-1} B^T$. It has been proved in \\cite{murphy2000note} that for a suitable Krylov subspace method then the iterative scheme will converge in exactly $2$ iterations when using the block triangular preconditioner or $3$ iterations using a block diagonal where the $B^T$ is dropped from the $(1,2)$ block in $\\mathcal{M}_{\\rm NS}$.\n\nIn practice it is often too expensive to form and solve for the Schur complement, hence, a good approximation to it is needed. Two well known preconditioners for the incompressible Navier-Stokes equations are the Least Squares Commutator (LSC) and the Pressure Convection-Diffusion (PCD) preconditioners. Both can be found in \\cite{elman2005finite} and we will just outline the procedure how these can be applied on the discrete level.\n\n% Both methods (LSC and PCD)  start with the convection-diffusion operator associated with the velocity space $\\uu{V}_h$ given by\n% $$\\mathcal{L} = -\\nu \\Delta +\\uu{w} \\cdot \\nabla\\, .$$\n% As before $\\uu{w}$ is the discrete velocity calculated at the previous non-linear iteration. Suppose that there is a corresponding operator defined in the pressure space\n% $$\\mathcal{L}_p = (-\\nu \\Delta +\\uu{w} \\cdot \\nabla)_p\\, .$$\n% Consider the commutator of the convection-diffusion operator associated with the gradient operator\n% \\begin{equation} \\label{eq:ContCommutator}\n% \\epsilon = (-\\nu \\Delta +\\uu{w} \\cdot \\nabla)\\nabla - \\nabla (-\\nu \\Delta +\\uu{w} \\cdot \\nabla)_p\n% \\end{equation}\n% to be small. In fact, if $\\uu{w}$ was constant then $\\epsilon = 0$. We will be using \\eqref{eq:ContCommutator} to derive both LSC and PCD.\n\n\n\n\\subsection{Pressure Convection-Diffusion (PCD)}\nBefore considering the PCD approach to approximate the Schur complement, we define the velocity mass matrix as $Q=(Q_{i,j})_{i,j=1}^{n_u} \\in{\\mathbb R}^{n_u \\times n_u}$, where in terms of the basis $\\{\\uu{\\psi_i}\\}$\n\\begin{equation}\n\\label{eq:pressure_mass}\nQ_{i,j}=\n\\int_\\Omega\\, \\uu{\\psi_j}\\cdot \\uu{\\psi_i} \\,d\\uu{x}, \\quad 1\\leq i,j \\leq n_u.\n\\end{equation}\nIn \\cite[Chap. 8]{elman2005finite} the discrete commutator of the convection-diffusion operator associated with the gradient operation is introduced and given by\n\\begin{equation} \\label{eq:DisCommutator}\n    \\epsilon_h = (Q^{-1}F)(Q^{-1}B^T)-(Q^{-1}B^T)(W^{-1}F_p)\n\\end{equation}\nIn this equation, $W=(W_{i,j})_{i,j=1}^{m_u} \\in{\\mathbb R}^{m_u \\times m_u}$, $F_p=((F_{p})_{i,j})_{i,j=1}^{m_u} \\in{\\mathbb R}^{m_u \\times m_u}$ and introduce $A_p=((A_{p})_{i,j})_{i,j=1}^{m_u} \\in{\\mathbb R}^{m_u \\times m_u}$ (which will be used later) are mass matrix, convection diffusion operator and Laplacian matrix defined on the pressure space as:\n\\begin{equation}\n\\label{eq:PressureMass}\n \\left. \\begin{aligned}\nW_{i,j}&= \\int_\\Omega\\, \\alpha_j \\alpha_i \\,dx, \\ \\ 1\\leq i,j \\leq m_u, \\\\\n(F_{p})_{i,j}&= \\nu \\int_\\Omega\\, \\grad \\alpha_j \\cdot \\grad \\alpha_i +(\\uu{w} \\cdot \\grad \\alpha_j)\\alpha_i\\,dx,\\ \\ 1\\leq i,j \\leq m_u, \\\\\n(A_{p})_{i,j}&=  \\int_\\Omega\\, \\grad \\alpha_j \\cdot \\grad \\alpha_i \\,dx, \\ \\ 1\\leq i,j \\leq m_u.\n \\end{aligned}\n \\right.\n \\qquad \\text{}\n\\end{equation}\nThese matricies are well-defined since our pressure spaces are continuous. Assuming that the commutator is small then pre and post multiplying \\eqref{eq:DisCommutator} by $B F^{-1} Q$ and $F_p^{-1}W$, respectively, lets us separate the Schur complement to give\n\\begin{equation} \\label{eq:SchurApprox}\n    BF^{-1}B^T \\approx B Q^{-1}B^T F_p^{-1} W.\n\\end{equation}\n\nIn general, $BF^{-1}B$ is both costly to form and usually dense, so it is impractical to use.  Our discretisation is inf-sup stable which means that there is spectral equivalency between $BQ^{-1}B^T$ and the pressure Laplacian, $A_p$, see \\cite[Section 5.5.1]{elman2005finite}. Hence, the Schur complement can be approximated by:\n$$S_{\\rm PCD} =A_p F_p^{-1}W.$$\nApplying the PCD preconditioner to the full Navier-Stokes system involves solving the system\n\\begin{equation} \\nonumber\n% \\label{eq:matrix-system}\n\\left(\n\\begin{array}{cc}\nF & B^T \\\\\n0 & -A_p F_p^{-1}W\n\\end{array}\n\\right)\n\\,\n\\left(\n\\begin{array}{c}\nx \\\\\ny\n\\end{array}\n\\right) =\n\\left(\n\\begin{array}{c}a\\\\b\n\\end{array}\n\\right)\n\\end{equation}\nat each Krylov iteration. This can be solved  efficiently by splitting it into the following two steps\n\\begin{itemize} \\label{it:PCDsolve}\n    \\item[1.] Solve for $y$: $y = -W^{-1}F_p A_p^{-1}b$\n    \\item[2.] Solve for $x$: $x = F^{-1}(a-B^Ty).$\n\\end{itemize}\nThis means that we have one pressure Poisson solve ($A_p^{-1}$), one mass matrix solve ($W^{-1}$) and one convection-diffusion solve ($F^{-1}$) at each Krylov iteration. These solves will be done using direct solver unless specifically stated otherwise.\n\n\\subsection{Least Squares Commutator}\n\nAs for the derivation of the PCD preconditioner we start off with the discrete commutator of the convection-diffusion operator\n\\begin{equation} \\nonumber\n    \\epsilon_h = (Q^{-1}F)(Q^{-1}B^T)-(Q^{-1}B^T)(W^{-1}F_p).\n\\end{equation}\nSuppose that the $Q$-norm is defined by $\\|v\\|_{Q} = (Qv,v)^{\\nicefrac{1}{2}}$. Then this time we minimise $\\epsilon_h$ in the $Q$-norm to try to find an expression for $F_p$. The minimisation is given by\n$$\\min \\|(Q^{-1}F)(Q^{-1}B^T)-(Q^{-1}B^T)(W^{-1}F_p) \\|_Q.$$\nSolving this optimisation problem, as shown in \\cite{elman2005finite}, is equivalent to solving the following normal equations\n$$W^{-1}BQ^{-1}B^TW^{-1}F_p = W^{-1}BQ^{-1} FQ^{-1}B^T.$$\nThis yields the following expression for $F_p$:\n$$F_p = W(BQ^{-1}B^T)^{-1}(BQ^{-1} FQ^{-1}B^T).$$\nBy substitution this into expression \\eqref{eq:SchurApprox} we obtain the LSC approximation to the Schur complement:\n\\begin{equation} \\nonumber\n    S = BF^{-1}B^T \\approx S_{\\rm LSC} = (B Q^{-1} B^T)(BQ^{-1}FQ^{-1}B^T)^{-1}(B Q^{-1} B^T).\n\\end{equation}\nTherefore, applying the LSC preconditioner to the full Navier-Stokes system $\\mathcal{K}_{\\rm NS}$ in \\eqref{eq:ns_coeff} involves solving for the matrix\n\\begin{equation} \\nonumber\n\\left(\n\\begin{array}{cc}\nF & B^T \\\\\n0 & -S_{\\rm LSC}\n\\end{array}\n\\right)\n\\,\n\\left(\n\\begin{array}{c}\nx \\\\\ny\n\\end{array}\n\\right) =\n\\left(\n\\begin{array}{c}a\\\\b\n\\end{array}\n\\right)\n\\end{equation}\nat each Krylov iteration. Again, this can be split up into the following two steps:\n\\begin{itemize}\n    \\item[1.] Solve for $y$: $y = -(B Q^{-1} B^T)^{-1}(BQ^{-1}FQ^{-1}B^T)(B Q^{-1} B^T)^{-1}b$\n    \\item[2.] Solve for $x$: $x = F^{-1}(a-B^Ty).$\n\\end{itemize}\nHence, we have two pressure Poisson solves ($(B Q^{-1} B^T)^{-1}$) and one Convection-Diffusion solve ($F^{-1}$) at each Krylov iteration. In practice, we take the diagonal or lumped diagonal of $Q$ to form $B Q^{-1} B^T$. These solves, as in with the PCD preconditioner, will be done directly.\n\n\n\\section{Maxwell's equations}\n\\label{sec:MaxwellPrecond}\n\nNext, consider the Maxwell subproblem\n\\begin{equation}\n\\label{eq:m_coeff}\n\\mathcal{K}_{\\rm MX}=\n\\begin{pmatrix}\nM & D^T \\\\\nD & 0\n\\end{pmatrix}.\n\\end{equation}\nAs for the Navier-Stokes subproblem in Section \\ref{sec:NSprecond}, we apply a block preconditioning strategy for $\\mathcal{K}_{\\rm MX}$ in  \\eqref{eq:m_coeff}.\n\nRecall that the $(1,1)$ block of $\\mathcal{K}_{\\rm MX}$ is the curl-curl operator, and hence the matrix $M$ is singular with nullity $m_b$ which corresponds to the discrete gradients. Therefore the usual Schur complement does not exist as it involves inverting $M$. To overcome this difficulty, we employ the approach in  \\cite{golub2003solving,greif2006preconditioners} based on  augmentation. More precisely, we replace $M$ by $M+D^T\\mathcal{W}^{-1}D$ where $\\mathcal{W}\\in {\\mathbb R}^{m_b\\times m_b}$ is a symmetric positive definite matrix, see \\cite{golub2003solving,greif2006preconditioners} for more details. The addition of the matrix ($D^T\\mathcal{W}^{-1}D$) removes the singularity of the $(1,1)$ block of $\\mathcal{K}_{\\rm MX}$ without changing the solution (since $Db = 0$). For the Maxwell subproblem the appropriate choice of $\\mathcal{W}$ is the scalar Laplacian on $S_h$ defined as $L=(L_{i,j})_{i,j=1}^{m_b} \\in{\\mathbb R}^{m_b \\times m_b}$ with\n\\begin{equation}\n\\label{eq:scalar_laplace}\nL_{i,j}=\\int_\\Omega\\,\\nabla\\beta_j\\cdot\\nabla\\beta_i\\,d\\uu{x},\n\\end{equation}\nsee  \\cite{greif2007preconditioners}. Therefore we will consider preconditioning the following augmented system:\n\\begin{equation}\n\\label{eq:AugmentMaxwell}\n\\bar{\\mathcal{K}}_{\\rm MX}=\n\\begin{pmatrix}\nM + D^TL^{-1}D & D^T \\\\\nD & 0\n\\end{pmatrix}.\n\\end{equation}\n\n\\subsection{An ideal preconditioner}\n\n\nIt has been shown in \\cite{greif2007preconditioners} that an ideal preconditioner for $\\bar{\\mathcal{K}}_{\\rm MX}$ in \\eqref{eq:AugmentMaxwell} is the block diagonal matrix\n\\begin{equation}\n\\label{eq:maxwell_pc_ideal}\n\\mathcal{M}_{\\rm iMX} =\n\\begin{pmatrix}\nM+D^T L^{-1} D & 0 \\\\\n0 & L\n\\end{pmatrix}.\n\\end{equation}\nApplying \\eqref{eq:maxwell_pc_ideal} as the preconditioner yields exactly two eigenvalues, $1$ and $-1$. Therefore using this matrix as a preconditioner means that MINRES will converge in two iterations  \\cite{paige1975solution}. However, forming the matrix $M+D^T L^{-1} D$ is costly, hence, $\\mathcal{M}_{\\rm iMX}$  is  impractical  for large systems.\n\n\n\\subsection{A practical preconditioner}\n\nA good approximation for $M+D^T L^{-1} D$ is required to make the ideal preconditioner, $\\mathcal{M}_{\\rm iMX}$, suitable in practise. It has been shown in \\cite{greif2007preconditioners}  that $M+D^T L^{-1} D$ is spectrally equivalent to $M+X$  where $X=(X_{i,j})_{i,j=1}^{n_b}\\in{\\mathbb R}^{n_b \\times n_b}$ is the mass matrix on the magnetic space and is defined as\n\\begin{equation}\n\\label{eq:magnetic_mass}\nX_{i,j}=\\int_\\Omega\\, \\uu{\\psi}_j\\cdot\\uu{\\psi}_i\\,d\\uu{x}.\n\\end{equation}\nUsing this approximation leads to the practical preconditioner\n\\begin{equation}\n\\label{eq:maxwell_pc_X}\n\\mathcal{M}_{\\rm MX} =\n\\begin{pmatrix}\nN& 0 \\\\\n0 & L\n\\end{pmatrix},\n\\end{equation}\nwhere $N = M+X$.\n\n\\section{A preconditioner for the MHD problem}\n\\label{sec:MHDprecond}\n\nSections \\ref{sec:NSprecond} and \\ref{sec:MaxwellPrecond} looked briefly at the preconditioning strategies for the Navier-Stokes and Maxwell's equations. Using these techniques we will look at possible scalable preconditioners for the full MHD problem,\n\\begin{equation}\n    {\\mathcal K}_{\\rm MH} = \\left(\n\\begin{array}{cccc}\nA+O & B^T & C^T & 0\\\\\nB & 0 & 0 & 0\\\\\n-C & 0 & M & D^T \\\\\n0 & 0 & D & 0\n\\end{array}\n\\right).\n\\end{equation}\nUsing the Navier-Stokes and Maxwell subproblem preconditioners \\eqref{eq:ns_pc_upper} and \\eqref{eq:maxwell_pc_X} respectively, then we propose the following preconditioner for ${\\mathcal K}_{\\rm MH}$\n\\begin{equation}\n\\label{eq:mhd_pc_ls}\n\\mathcal{M}_{\\rm MH} =\n\\left(\n\\begin{array}{cccc}\nF & B^T & C^T & 0\\\\\n0 & -S & 0 & 0 \\\\\n-C & 0 & N & 0\\\\\n0 & 0 & 0 & L\n\\end{array}\n\\right).\n\\end{equation}\nDue to the coupling terms, $C$, the application of this precondioner is hard. To overcome this, we propose to invert  $\\mathcal{M}_{\\rm MH}$ by means of an inner preconditioner Krylov solver. The inner preconditioner is given by\n\\begin{equation}\n\\label{eq:mhd_pc_inner}\n\\mathcal{M}_{\\rm innerMH} =\n\\left(\n\\begin{array}{cccc}\nF & B^T & 0 & 0\\\\\n0 & -{S} & 0 & 0 \\\\\n0 & 0 & N & 0\\\\\n0 & 0 & 0 & L\n\\end{array}\n\\right).\n\\end{equation}\n\n\\section{Preconditioners for MD and CD}\n\nIn Section \\ref{sec:FEMdecouple} we introduced two decoupling schemes, namely Magnetic Decoupling (MD) and Complete Decoupling (CD). Using the results from sections \\ref{sec:MaxwellPrecond} and \\ref{sec:NSprecond} we will discuss the preconditioning approaches that we imply for these decoupling schemes.\n\n\\subsection{Magnetic decoupling}\n\\label{sec:MDprecond}\n\nFrom section \\ref{sec:FEMmd} the the matrix to be preconditioned is as follows:\n\\begin{equation}\n   \\mathcal{K}_{\\rm MD} =\n    \\left(\n    \\begin{array}{cccc}\n    F& B^T & 0 & 0\\\\\n    B & 0 & 0 & 0 \\\\\n    0 & 0 & M & D^T\\\\\n    0 & 0 & D & 0\n    \\end{array}\n    \\right).\n\\end{equation}\nRecall that removing the coupling terms completely decouples the system. This therefore enables us to use the optimal preconditioners for each of the subproblems separately and in parallel. Using the subproblem preconditioners \\eqref{eq:maxwell_pc_X} and \\eqref{eq:ns_pc_upper} then the optimal preconditioner for $\\mathcal{K}_{\\rm MD}$ is\n\\begin{equation}\n\\label{eq:mhd_pc_explicit}\n\\mathcal{M}_{\\rm MD} =\n\\left(\n\\begin{array}{cccc}\nF & B^T & 0 & 0\\\\\n0 & -{S} & 0 & 0 \\\\\n0 & 0 & N & 0\\\\\n0 & 0 & 0 & L\n\\end{array}\n\\right).\n\\end{equation}\n\n\n\\subsection{Complete decoupling}\n\\label{sec:CDprecond}\n\nTo form an appropriate preconditioner for the CD iteration in \\eqref{eq:matrix_CD} we first need to consider how to deal with the upper $(2,2)$ block matrix which corresponds to the discrete Stokes equations\n\\begin{equation}\\nonumber\n   \\mathcal{K}_{\\rm S} =\n    \\left(\n    \\begin{array}{cc}\n    A& B^T \\\\\n    B & 0\n    \\end{array}\n    \\right)\n\\end{equation}\nAs with the incompressible Navier-Stokes subproblem the idea for the Stokes preconditioner is again to approximate the Schur complement. The Schur complement associated with the Stokes system is\n$$S_{\\rm S} =  BA^{-1}B^T,$$\nrecall that the matrix $A$ is defined with the viscosity $\\nu$ in section \\ref{sec:variation}. It was shown in \\cite{silvester1993fast,silvester1994fast} that the scaled pressure mass matrix, $\\mbox{\\small \\(\\frac{1}{\\nu}\\)} W$ defined in \\eqref{eq:PressureMass}, is spectrally equivalent to the Schur complement (which is also a consequence of the inf-sup stability condition). Therefore the scalable Stokes preconditioner is\n\\begin{equation*}\n\\label{eq:mhd_pc_explicit2_1}\n\\begin{pmatrix}\nA & 0 \\\\\n0 & \\mbox{\\small \\(\\frac{1}{\\nu}\\)} W\n\\end{pmatrix}.\n\\end{equation*}\nUsing \\eqref{eq:mhd_pc_explicit2} together with the Maxwell subproblem preconditioner  \\eqref{eq:maxwell_pc_X} gives the preconditioner\n\\begin{equation}\n\\label{eq:mhd_pc_explicit2}\n\\mathcal{M}_{\\rm CD} =\n\\left(\n\\begin{array}{cccc}\nA & 0 & 0 & 0\\\\\n0 & \\mbox{\\small \\(\\frac{1}{\\nu}\\)} W & 0 & 0 \\\\\n0 & 0 & N & 0\\\\\n0 & 0 & 0 & L\n\\end{array}\n\\right).\n\\end{equation}\nThe biggest advantage of this decoupling approach is that the matrix system is now symmetric. This means that the appropriate choice for the Krylov subspace method is MINRES for each subproblem.\n", "meta": {"hexsha": "483b5758627acf3e2f8b078848bd12468e2ed3fd", "size": 15555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MHD/THESISnew/Preconditioning/Preconditioning.tex", "max_stars_repo_name": "wathen/PhD", "max_stars_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-10-25T13:30:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-10T21:27:30.000Z", "max_issues_repo_path": "MHD/THESISnew/Preconditioning/Preconditioning.tex", "max_issues_repo_name": "wathen/PhD", "max_issues_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MHD/THESISnew/Preconditioning/Preconditioning.tex", "max_forks_repo_name": "wathen/PhD", "max_forks_repo_head_hexsha": "35524f40028541a4d611d8c78574e4cf9ddc3278", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-28T16:12:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-13T13:59:44.000Z", "avg_line_length": 47.8615384615, "max_line_length": 963, "alphanum_fraction": 0.7113468338, "num_tokens": 5159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6230502895396626}}
{"text": "\\documentclass[a4paper,14pt,twoside]{book}\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage{soul}\n\\usepackage[colorlinks=true,linkcolor=red]{hyperref}\n\\usepackage{extsizes}\n\\usepackage{multicol}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\begin{document}\n\\newcommand*{\\REF}[1]{\\hyperref[{#1}]{\\autoref*{#1} \\nameref*{#1}}}\n\\newcommand{\\LIM}[2]{\\lim_{#1 \\to #2}}\n\\newcommand{\\D}{\\F{d}{dx}}\n\\newcommand{\\DD}[2]{\\F{d #1}{d #2}}\n\\newcommand{\\B}[1]{\\left(#1\\right)}\n\\newcommand{\\F}[2]{\\frac{#1}{#2}}\n\\newcommand{\\T}[1]{\\textrm{#1}}\n\\newcommand{\\N}[1]{{\\fontfamily{serif}\\fontsize{10}{1cm}\\selectfont \\rlap{#1}}}\n\\newcommand*{\\QED}{\\hfill\\ensuremath{\\blacksquare}}\n\n\\title{Maths}\n\\author{Patrolin}\n\n{\\fontsize{14.4}{1cm}\\selectfont\n\\maketitle\n\\tableofcontents\n\\chapter{Derivatives}\nThe derivative is the rate of change of a function at a given point$:$ \\\\\n\\begin{align*}\n\t\\T{When } \\overbrace{\\D f(x)}^{\\N{the derivative of f(x)}} & > 0 \\T{, } f(x) \\T{ is increasing.} \\\\\n\t\\T{When } \\D f(x)                                          & < 0 \\T{, } f(x) \\T{ is decreasing.} \\\\\n\t\\T{When } \\D f(x)                                          & = 0 \\T{, } f(x) \\T{ is constant.}\n\\end{align*}\n\\pagebreak\n\\section{Notation}\nIf x is a variable, then $dx$ is a small change in $x$. \\\\\n$dx$ is close to $0$, but not equal to $0$. $0$ is $\\F{1}{\\infty}$, and $\\infty$ is evil! \\\\\n\\begin{align*}\n\t&dx \\to 0 \\\\\n\\end{align*}\nIf y is a function of $x$, then $dy$ and $df(x)$ are the change caused by $dx$. \\\\\n\\begin{align*}\n\t    y &= f(x) \\\\\n\t   dy &= df(x) \\\\\n\tdf(x) &= \\underbrace{f(x) - f(x-dx)}_{\\N{left subderivative}} = \\underbrace{f(x+dx) - f(x)}_{\\N{right subderivative}} \\\\\n\\end{align*}\nIf the function is discontinuous, then the derivative is undefined. \\\\\n\\begin{align*}\n\t\\D f(x) &= \\F{df(x)}{dx} \\\\\n\\end{align*}\nPutting all of these ideas together gives us the equation for a derivative$:$ \\\\\n$$\\begin{rcases*}\n\tf(x)' = \\D f(x) = \\DD{f(x)}{x} \\\\\n\tdf(x) = f(x+dx) - f(x) \\\\\n\tdx \\to 0 \\  (dx \\ne 0) \\\\\n\\end{rcases*} \\D f(x) = \\LIM{h}{0} \\F{f(x+h)-f(x)}{h}$$\n\\section{Elementary derivatives}\n\\subsection{$\\D a = 0$}\n\\begin{align*}\n\t&a \\in R \\\\\n\tf(x)    &= a                               \\\\\n\t\\D f(x) &= \\LIM{h}{0} \\F{f(x+h) - f(x)}{h} \\\\\n\t\\D a    &= \\LIM{h}{0} \\F{a-a}{h}           \\\\\n\t\\D a    &= \\LIM{h}{0} \\F{0}{h}             \\\\\n\t\\D a    &= 0 \\  \\because \\  h \\ne 0\n\\end{align*}\n\\subsection{$\\D x^a = ax^{a-1}$}\n\\begin{align*}\n\td(x^a)        &= (x+dx)^a - x^a \\\\\n\td(x^a)        &= x^a\n\t+ \\  \\underbrace{\\begin{matrix}\n\t\t\t+ (dx + x + x + x + \\ldots) \\\\\n\t\t\t+ (x + dx + x + x + \\ldots) \\\\\n\t\t\t+ (x + x + dx + x + \\ldots) \\\\\n\t\t\t+ (x + x + x + dx + \\ldots) \\\\\n\t\t\t\\vdots\n\t\t\\end{matrix}}_{x^{a-1}dx}\n\t\\left. \\phantom{\\begin{matrix} \\\\ \\\\ \\\\ \\\\ \\\\ \\end{matrix}} \\right\\}\n\t\\T{a times}\n\t+ (\\ldots)dx^2\n\t- x^a \\\\\n\td(x^a)        &= ax^{a-1}dx + (\\ldots)dx^2 \\\\\n\t\\DD{(x^a)}{x} &= ax^{a-1} + (\\ldots)dx \\  \\because \\  dx \\ne 0 \\\\\n\t\\D x^a        &= ax^{a-1} \\  \\because \\  dx \\to 0 \\\\\n\t& \\qquad \\Downarrow \\\\\n\t& \\D x = 1 \\\\\n\t& \\D x^2 = 2x \\\\\n\t& \\D x^3 = 3x^2 \\\\\n\t& \\qquad \\  \\  \\vdots \\\\\n\\end{align*}\n\\subsection{$\\D e^x = e^x$}\nThis is how the value of $e$ is defined. \\\\\n$e = 2.718\\ldots$\n\\subsection{$\\D \\ln{x} = \\F{1}{x}$}\nIf you have a function of one variable, then take the change in that\nfunction with respect to that variable (implicit differentiation). \\\\\n\\begin{align*}\n\ty           &= \\ln{x} \\\\\n\te^y         &= x \\\\\n\td(e^y)      &= d(x) \\\\\n\te^y * dy    &= 1*dx \\\\\n\t\\F{dy}{dx}  &= \\F{1}{e^y} \\\\\n\t\\F{d}{dx} y &= \\F{1}{x} \\\\\n\t\\D \\ln{x}   &= \\F{1}{x} \\\\\n\\end{align*}\nIf you have a function of many variables, apply \\REF{sec:Rules} to\nbreak it down into functions of one variable. \\\\\n\\pagebreak\n\\subsection{Trigonometric functions}\n\\N{see \\url{https://lbry.tv/@3Blue1Brown:b/derivative-formulas-through-geometry}}\n\\begin{align*}\n\t&\\D \\sin{x} = \\cos{x}  \\\\\n\t&\\D \\cos{x} = -\\sin{x}\n\\end{align*}\nPlus \\href{https://www.priklady.eu/cs/matematika/derivace/derivace-funkce.alej}{others} which you probably don't need. \\\\\n\\section{Rules} \\label{sec:Rules}\n\\subsection{The derivative is a linear function}\nThe derivative of a sum is the sum of derivatives. \\\\\n\\begin{align*}\n\t&\\D (f(x) + g(x)) = \\D f(x) \\  + \\  \\D g(x) \\\\\n\\end{align*}\nConstants can be multiplied outside. \\\\\n\\begin{align*}\n\t&a \\in R \\\\\n\t&\\D (a*x) = a * \\D x \\\\\n\\end{align*}\nProof is left as an excercise to the reader. \\\\\n\\pagebreak\n\\subsection{Product rule}\n\\N{see \\url{https://lbry.tv/@3Blue1Brown:b/visualizing-the-chain-rule-and-product}}\nTODO(): put in a picture instead of a link\n\\begin{align*}\n\td(f(x)*g(x))         &= df(x)*g(x) + f(x)*dg(x) + df(x)*dg(x) \\\\\n\t\\F{d(f(x)*g(x))}{dx} &= \\F{df(x)}{dx}*g(x) + f(x)*\\F{dg(x)}{dx} + \\F{df(x)}{dx}*dg(x) \\\\\n\t\\D (f(x)*g(x))       &= \\D f(x) * g(x) + f(x) * \\D g(x) \\  \\because \\  dg(x) \\to 0 \\\\\n\\end{align*}\n\\begin{align*}\n\t&\\D (x \\ln x) = 1*\\ln x + \\F{x}{x} = \\ln x + 1 \\\\\n\t&\\D (\\sin{x} * x^2) = \\cos{x} * x^2 + \\sin{x} * 2x \\\\\n\t&\\D \\F{\\sin{x}}{x} = \\D (\\sin{x} * 1/x) = \\F{\\cos{x}}{x} - \\F{\\sin{x}}{x^2} \\\\\n\\end{align*}\n\\pagebreak\n\\subsection{$\\DD{}{g(x)} f(g(x))$}\nDerivative of $f(g(x))$ with respect to $g(x)$. \\\\\nYou simply treat $g(x)$ as if it was $x$. \\\\\n\\begin{align*}\n\t&\\DD{}{(x^2)} (\\sin{x^2}) = \\DD{}{y} (\\sin{y}) = \\cos{y} = \\cos{x^2} \\\\\n\t&\\DD{}{(\\sin{x})} (\\sin{x})^3 = 3(\\sin{x})^2 \\\\\n\t&\\DD{}{(\\ln{x})} (\\ln{x})^{-1} = -1(\\ln{x})^{-2} \\\\\n\\end{align*}\n\\subsection{Chain rule}\n\\begin{align*}\n\t\\D f(g(x)) &= \\F{df(g(x))}{dx} = \\F{df(g(x))}{g(x)} \\  * \\  \\F{dg(x)}{dx} \\\\\n\t\\D f(g(x)) &= \\DD{}{g(x)} f(g(x)) \\  * \\  \\DD{}{x} g(x) \\\\\n\\end{align*}\n\\begin{align*}\n\t&\\D (\\sin{x^2}) = \\cos{x^2} * 2x \\\\\n\t&\\D \\F{1}{\\sin{x}} = \\D (\\sin x)^{-1} = -1*(\\sin{x})^{-2} \\  * \\  \\cos{x} = -\\F{\\cos{x}}{(\\sin{x})^2} \\\\\n\t&\\D \\ln e^x = \\F{1}{e^x} * e^x = 1\n\\end{align*}\n\\newpage\nThis also leads to a formula for division. \\\\\n\\begin{align*}\n\t\\D \\F{1}{g(x)}    &= -1*g(x)^{-2} * \\D g(x) = -\\F{\\D g(x)}{g(x)^2} \\\\\n\t\\D \\F{f(x)}{g(x)} &= \\F{\\D f(x)}{g(x)} + f(x) * \\D g(x) \\\\\n\t\\D \\F{f(x)}{g(x)} &= \\F{\\D f(x)}{g(x)} - f(x)*\\F{\\D g(x)}{g(x)^2} \\\\\n\t\\D \\F{f(x)}{g(x)} &= \\F{\\D f(x) * g(x) \\  - \\  f(x) * \\D g(x)}{g(x)^2} \\\\\n\\end{align*}\n\\subsection{L'Hopital's rule}\nRelies on geometric proof!\n\\begin{align*}\n\t&\\LIM{x}{a} \\F{g(x)}{h(x)} = \\LIM{x}{a} \\F{dg(x)}{dh(x)}\n\\end{align*}\n\\begin{align*}\n\t\\LIM{x}{0} \\F{\\sin{x}}{x} &= \\LIM{x}{0} \\F{\\cos{x * dx}}{1 * dx} \\\\\n\t\\LIM{x}{0} \\F{\\sin{x}}{x} &= \\LIM{x}{0} \\F{\\cos{x}}{1} \\  \\because \\  dx \\ne 0 \\\\\n\t\\LIM{x}{0} \\F{\\sin{x}}{x} &= 1\n\\end{align*}\n\\subsection{Derivative of inverse function}\nWith $g(x)$ being the inverse of $f(x):$\n\\begin{align*}\n\tg(f(x))           &= x \\\\\n\t\\D f(x) * \\D g(x) &= 1 \\\\\n\t\\D g(x)           &= \\F{1}{\\D f(x)} \\\\\n\\end{align*}\n\\section{Composite derivatives}\n\\subsection{$\\D e^{-x} = -e^{-x}$}\n\\begin{align*}\n\t\\D e^{-x} &= e^{-x} * (-1) \\\\\n\t\\D e^{-x} &= -e^{-x} \\\\\n\\end{align*}\n\\subsection{$\\D a^x = a^x \\ln a$}\nNote that $\\ln a^x = x \\ln a$.\n\\begin{align*}\n\ta^x    &= e^{\\ln a^x} \\\\\n\ta^x    &= e^{x \\ln a} \\\\\n\t\\D a^x &= e^{x \\ln a} * \\ln a \\\\\n\t\\D a^x &= a^x \\ln a \\\\\n\\end{align*}\n\\subsection{$\\D \\log_a{x} = \\F{1}{x \\ln a}$}\n\\begin{align*}\n\ty              &= \\log_a{x} \\\\\n\ta^y            &= x \\\\\n\td(a^y)         &= d(x) \\\\\n\ta^y \\ln a * dy &= 1*dx \\\\\n\t\\DD{y}{x}      &= \\F{1}{a^y \\ln a} \\\\\n\t\\D y           &= \\F{1}{a^{\\log_a{x}} \\ln a} \\\\\n\t\\D \\log_a{x}   &= \\F{1}{x \\ln a} \\\\\n\\end{align*}\n\\subsection{$\\D x^x = x^x * (\\ln x + 1)$}\n\\begin{align*}\n\tf(x)     &= x^x \\\\\n\t\\ln f(x) &= \\ln (x^x) \\\\\n\t\\ln f(x) &= x \\ln x \\\\\n\tf(x)     &= e^{x \\ln x} \\\\\n\t\\D x^x   &= e^{x \\ln x} * (\\ln x + 1) \\\\\n\t\\D x^x   &= x^x * (\\ln x + 1) \\\\\n\\end{align*}\n\\end{document}\n", "meta": {"hexsha": "54be19e4d14324c735902c1fb2158e6612cb146c", "size": 7633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "__latexindent_temp.tex", "max_stars_repo_name": "Patrolin/maths", "max_stars_repo_head_hexsha": "6a3c142019f907328cf065c90a297efc4794c2a2", "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": "__latexindent_temp.tex", "max_issues_repo_name": "Patrolin/maths", "max_issues_repo_head_hexsha": "6a3c142019f907328cf065c90a297efc4794c2a2", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-04-04T16:12:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-03T22:56:44.000Z", "max_forks_repo_path": "maths.tex", "max_forks_repo_name": "Patrolin/maths", "max_forks_repo_head_hexsha": "6a3c142019f907328cf065c90a297efc4794c2a2", "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.5384615385, "max_line_length": 121, "alphanum_fraction": 0.4996724748, "num_tokens": 3317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.623050284587182}}
{"text": "\\subsubsection{Cone}\r\nA cone is a transition state between one-sheet and two-sheet hyperboloids.\r\nWhen the constant term in the hyperboloid's equation is 0, the top and bottom surfaces are only connected at a single point.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.8\\textwidth]{./Images/differentialMultivariableCalculus/cones.png}\r\n\t\\caption{Cones}\r\n\\end{figure}", "meta": {"hexsha": "3f2f68d40e09f43cd3c42327459a1273f4871ca1", "size": 382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/cone.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": "multiCalc/differentialMultivariableCalculus/cone.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": "multiCalc/differentialMultivariableCalculus/cone.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": 42.4444444444, "max_line_length": 125, "alphanum_fraction": 0.780104712, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.6230502730313939}}
{"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 I Notes}\n\\date{June 15, 2020}\n\\author{Michael Brodskiy\\\\ \\small Professor: V. Cherkassky}\n\n\n\\begin{document}\n\n\\maketitle\n\n\n\\section{Chapter 12}\n\n\\subsection{Vectors (12.1)}\n\n\\begin{flushleft}\nBasic Vector manipulations:\n\\end{flushleft}\n\\underline{Multiplication or Division}: some vector, $\\vec{a}$, multiplied or divided by a constant, $k$, is simply the magnitude (length) of the vector multiplied or divided by the scalar\\\\\n\\underline{Addition or Subtraction}: The addition or subtraction of two vectors forms a triangle. Finding the third side of the triangle will give you the magnitude (length) of the resulting vector.\\\\\n\nThe distance between to points, or the magnitude of the vector may be found using the distance formula:}\n$$\\sqrt{(x_1-x_2)+(y_1-y_2)}$$ Or, in three dimensions: $$\\sqrt{(x_1-x_2)+(y_1-y_2)+(z_1-z_2)}$$\n\nThese equations come from the circular or spherical formula for radius: $$(x-h)^2+(y-k)^2=r^2, \\text{and } (x-h)^2+(y-k)^2+(z-c)^2=r^2 $$\n\n\\textit{Practice Problem:\\\\What is the radius and center of the figure?}\n\n$$x^2+y^2+z^2-2x-4y+8z=15\\\\x^2-2x+y^2-4y+z^2+8z=15\\\\(x-1)^2+(y-2)^2+(z+4)^2=36$$\nSphere with center at $(1, 2, -4)$, and radius 6\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "fa26207f0e47ad044af5e41ce921c98f05b664d2", "size": 2360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture1.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/Lecture1.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/Lecture1.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": 31.4666666667, "max_line_length": 200, "alphanum_fraction": 0.6076271186, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6230502730313938}}
{"text": "%============================================================================\n\\chapter{Classical black holes}\n%============================================================================\n\n%----------------------------------------------------------------------------\n\\section{Black holes in Einstein gravitation}\n%----------------------------------------------------------------------------\n\n\\begin{nameddef}{Schwarzschild space-time and black hole}\nBy inserting a spherical-symmetric ansatz, one obtains the Schwarzschild \nsolution of the vacuum Einstein equation. Using the original Schwarzschild \ncoordinates and the holonomic formalism, the metric of the solution can be \nwritten as\n\\begin{equation}\n\\dd s^2 = -\\rbr{1-\\frac{\\rSch}{r}}\\,\\dd t^2+\\rbr{1-\\frac{\\rSch}{r}}^{-1}\n\\,\\dd r^2 + r^2\\,\\dd\\Omega^2,\n\\label{eq:schwarzschild}\n\\end{equation}\nwhere $\\rSch = 2\\nG M$ is the Schwarzschild radius, $M$ can be interpreted \nas the mass of the black hole, and\n\\begin{equation}\n\\dd\\Omega^2 \\coloneqq \\dd\\theta^2 + \\sin^2\\theta\\,\\dd\\phi^2\n\\end{equation}\nis the metric of unit $2$-sphere $S^2$. One recognises $0 < \\theta < \\pp$ and \n$0 < \\phi < 2\\pp$, whereas $-\\infty < t < +\\infty$ is also allowed;\nthe range of $r$ is $\\rbr{0, \\rSch} \\cup \\rbr{\\rSch, +\\infty}$, making the \ncoordinates covering two disjoint patches of the space-time.\n\nTo exploit the Weyl-flatness of $\\mathcal{M}/S^2$, one may transform the\nholonomic co-frame by\n\\begin{equation}\n\\dd r^* \\coloneqq \\rbr{1-\\frac{\\rSch}{r}}^{-1}\\,\\dd r,\n\\label{eq:trsf-dtosc}\n\\end{equation}\nwhich can be integrated to\n\\begin{equation}\n\\ee^{r_*/\\rSch-1} =\n\\rbr{\\frac{r}{\\rSch}-1}\\rfun{\\exp}{\\frac{r}{\\rSch}-1},\n\\label{eq:trsf-gtosc}\n\\end{equation}\ngenerating the transformations\\footnote{$\\rfun{W}{x}$ is known as the Lambert \n$W$-function, satisfying $W(x)\\ee^{W(x)} = x$}\n\\begin{equation}\nr_* = r+\\rSch\\rfun{\\ln}{\\frac{r}{\\rSch}-1},\\qquad\nr = \\rSch\\rbr{1+\\rfun{W}{\\ee^{r_*/\\rSch-1}}}.\n%\\label{eq:trsf-scto}\n\\end{equation}\nTransforming by \\cref{eq:trsf-dtosc} gives the \\emph{Regge and Wheeler's \ntortoise coordinates}, which gives the Schwarzschild metric as\n\\begin{equation}\n\\dd s^2 = \\rbr{1-\\frac{\\rSch}{r}}\\rbr{ -\\dd t^2 + \\dd r_*^2}\n+ \\rfun{r^2}{r_*}\\,\\dd\\Omega^2.\n\\end{equation}\nThe range of $r_*$ is $\\rbr{-\\infty, +\\infty}$, corresponding to\n$r \\in \\rbr{\\rSch, +\\infty}$.\n\nIn order to keep the causal structure in further coordinate transformations,\none switches first to the \\emph{light-cone} coordinates\n\\begin{equation}\nx_\\mp = t\\mp r_*.\n% u; v\n%\\\\t = \\frac{u+v}{2},\\quad r_* = \\frac{-u+v}{2},\n\\label{eq:trsf-tlto}\n\\end{equation}\nSubstituting $t$ in \\cref{eq:schwarzschild} with $x_\\mp$ gives\nthe \\emph{retarded and advanced Eddington--Finklestein coordinates}, the \nSchwarzschild metric in which take the form\n\\begin{align}\n\\dd s^2\n&= -\\rbr{1-\\frac{\\rSch}{r}}\\,\\dd x_-^2 - 2\\,\\dd x_-\\,\\dd r + r^2\\,\\dd\\Omega^2\n\\label{eq:retarded-efc} \\\\\n&= -\\rbr{1-\\frac{\\rSch}{r}}\\,\\dd x_+^2 + 2\\,\\dd x_+\\,\\dd r + r^2\\,\\dd\\Omega^2,\n\\label{eq:advanced-efc}\n\\end{align}\nrespectively. The ranges of $x_\\mp$ and $r$ are now both $\\rbr{-\\infty, \n+\\infty}$. Note that the coordinate singularity at $r=\\rSch$ in \n\\cref{eq:schwarzschild} has been eliminated.\n\nIn \\crefrange{eq:retarded-efc}{eq:advanced-efc} one may further replace $r$ \nwith $x_\\pm$, yielding\n\\begin{equation}\n\\dd s^2 = -\\rbr{1-\\frac{\\rSch}{\\rfun{r}{x_\\mp}}}\\,\\dd x_-\\,\\dd x_+\n+\\rfun{r}{x_\\mp}^2\\,\\dd\\Omega^2,\n\\label{eq:co-sctlo}\n\\end{equation}\nat the expense of recovering the coordinate singularity at $r = \\rSch$. To \nbypass this, using\n\\cref{eq:trsf-gtosc,eq:trsf-tlto} to get\n\\begin{equation}\n1-\\frac{\\rSch}{r} = \\frac{\\rSch}{r}\\rfun{\\exp}{-\\frac{r}{\\rSch}}\n\\rfun{\\exp}{\\frac{-x_-+x_+}{2\\rSch}},\n\\end{equation}\nso \\cref{eq:co-sctlo} becomes\n\\begin{equation}\n\\dd s^2 = -\\frac{\\rSch}{r}\\rfun{\\exp}{-\\frac{r}{\\rSch}}\n\\rfun{\\exp}{\\frac{-x_-+x_+}{2\\rSch}}\\,\\dd x_-\\,\\dd x_+\n+ r^2\\,\\dd\\Omega^2.\n\\end{equation}\nAbsorbing the corresponding exponentials by introducing the\n\\emph{Kruskal--Szekeres} light-cone coordinates,\n\\begin{equation}\nX_- \\coloneqq -\\rSch \\rfun{\\exp}{-\\frac{x_-}{2\\rSch}},\n\\qquad\nX_+ \\coloneqq +\\rSch \\rfun{\\exp}{+\\frac{x_+}{2\\rSch}},\n\\end{equation}\nleads to the new components\n\\begin{equation}\n\\dd s^2 = \n-\\frac{4\\rSch}{\\rfun{r}{X_\\mp}}\\rfun{\\exp}{-\\frac{\\rfun{r}{X_\\mp}}{\\rSch}}\n\\,\\dd X_-\\,\\dd X_+ + \\rfun{r}{X_\\mp}^2\\,\\dd\\Omega^2.\n\\end{equation}\nBy further rotating the light-cone coordinates into time- and space-like ones,\n\\begin{equation}\nX_- \\eqqcolon T-R,\\qquad X_+ \\eqqcolon T+R,\n\\end{equation}\none derives the \\emph{Kruskal--Szekeres coordinates}, the metric in which takes \nthe form\n\\begin{equation}\n\\dd s^2 = \n\\frac{16\\rSch}{\\rfun{r}{T,R}}\\rfun{\\exp}{-\\frac{\\rfun{r}{T,R}}{\\rSch}}\n\\rbr{-\\dd T^2 + \\dd R^2} + \\rfun{r}{T,R}^2\\,\\dd\\Omega^2.\n\\end{equation}\n\nFinally, in order to compactify the coordinates $T$ and $R$ while keeping the \ncausal structure, one may introducing the \\emph{conformal} coordinates of type \nlight-cone and space-time\n\\begin{equation}\n\\chi_- \\coloneqq \\arctan\\frac{X_-}{\\rSch} \\eqqcolon \\eta - \\rho, \\qquad\n\\chi_+ \\coloneqq \\arctan\\frac{X_+}{\\rSch} \\eqqcolon \\eta + \\rho,\n\\end{equation}\nleading to the components\n\\begin{align}\n\\dd s^2\n&= -\\frac{4\\rSch^3}{r}\\ee^{-r/\\rSch}\\sec^2\\chi_-\\sec^2\\chi_+ \n\\,\\dd\\chi_-\\,\\dd\\chi_+ + r^2\\,\\dd\\Omega^2 \\\\\n&= \\frac{16\\rSch^3}{r}\\ee^{-r/\\rSch}\n\\rfun{\\sec^2}{\\eta-\\rho}\\rfun{\\sec^2}{\\eta+\\rho}\n\\rbr{-\\dd\\eta^2+\\dd\\rho^2} + r^2\\,\\dd\\Omega^2.\n\\end{align}\nThis leads to the Carter--Penrose conformal diagram of the maximally extended\nSchwarzschild space-time, \\cref{fig:e-schwarzschild}.\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}%[scale=2]\n\\pgfmathsetmacro\\myunit{3} \n\t\\draw (0,0)\n\t\t\tnode [left] {$i^0$} \n\t\t--++(45:\\myunit)\n\t\t\tnode [above]{$i^+$}\n\t\t\tcoordinate (a)\n\t\t\tnode [below = 1.8 cm] {$P$}\n\t\t\tnode [pos = .5, above left] {$\\mscrI^+$}\n\t\t\t% node [pos=.5, below, sloped] {$\\bar{u}=\\infty$}\n\t\t--++(-45:2*\\myunit)\n\t\t\tnode [pos = .25, above right] {$\\mscrH^+$}\n\t\t\tnode [pos = .75, above, sloped] {$r = \\rSch$}%x_+ \\to -\\infty$}\n\t\t\tcoordinate (d)\t\n\t\t\t%node [below]{$i^-$}\n\t\t--++(45:\\myunit)\n\t\t\tnode [pos = .5, below, sloped] {$x_- \\to -\\infty$}\n\t\t\t% node [right] {$i^0$}\n\t\t--++(135:\\myunit)\n\t\t\t% node [above] {$i^+$}\n\t\t\tnode [below = 1.8 cm] {$U$}\n\t\t\tcoordinate (b)\n\t\t\tnode [pos = .5, above, sloped] {$x_+ \\to +\\infty$}\n\t\t--++(-135:2*\\myunit)\n\t\t\tcoordinate (c)\n\t\t\tnode [pos = .25, below, sloped] {$r = \\rSch$}%x_- \\to +\\infty$}\n\t\t\tnode [pos = .75, below right] {$\\mscrH^-$}\n\t\t\tnode [below] {$i^-$}\n\t\t--cycle\n\t\t\tnode [pos = .5, below left] {$\\mscrI^-$};\n\n \\draw [decorate, decoration=zigzag] (a) -- node [above] {$r=0$} % =6pt\n\t\t\t\t\t\t\t\t\t\t\tnode [below = .75 cm] {$B$}\n\t\t\t\t\t\t\t\t\t\t\t(b) \n\n\t\t\t\t\t\t\t\t\t (c) -- node [above = .75 cm] {$W$}\n\t\t\t\t\t\t\t\t\t\t\t(d);\n\n\\end{tikzpicture}\n\\end{center}\n\\caption[Conformal diagram of the Schwarzschild space-time]{Carter--Penrose \nconformal diagram of the maximally extended Schwarzschild space-time, where \n$\\pm$ means future and past, $\\mscrI^\\pm$ denote the light-like infinities, \n$i^0$ the space-like infinity, $i^\\pm$ the time-like infinities, and \n$\\mscrH^\\pm$ the horizons, respectively. $B$, $U$, $W$ and $P$ denote different \nregions, meaning black hole, universe, white hole and parallel universe, \nrespectively. The space-time structures of $P$ and $U$ are equivalent. \n\\label{fig:e-schwarzschild}}\n\\end{figure}\n\n\\begin{table}\n\\begin{tabular}{l|l@{,}l|l}\n\\toprule\nName & & \\\\\n\\midrule\nSpace-time Sch.\\ & $t \\in \\BbbR$ & $r \\in \\BbbR^+\\backslash \\cbr{\\rSch}$\n\t& $U\\cup B$\\\\\nSpace-time R--W & $t \\in \\BbbR$ & $r_* \\in \\BbbR$ & $U$\\\\\nLight-cone R--W & \\multicolumn{2}{l}{$x_\\mp \\in \\BbbR$} & $U$\\\\\nRetarded E--F & \\\\\nAdvanced E--F & \\\\\nSpace-time K--S & \\\\\nLight-cone K--S & \\\\\nSpace-time Con & \\\\\nLight-cone Con & \\\\\n\\bottomrule\n\\end{tabular}\n\\caption{Range and valid region of different coordinates}\n\\end{table}\n\n\n\n\\end{nameddef}\n\n\n\n\\begin{nameddef}{Further Einsteinian black holes}\n\n\\end{nameddef}\n\n\n\n\\begin{nameddef}{Collapsing body}\n\n\\end{nameddef}\n\n\n%----------------------------------------------------------------------------\n\\section{Black holes in dilaton gravitation}\n%----------------------------------------------------------------------------\n\n%----------------------------------------------------------------------------\n\\section{Thermodynamics of Einsteinian black holes}\n%----------------------------------------------------------------------------\n\n\\begin{nameddef}{Laws of Einsteinian black-hole mechanics}\n\n\\end{nameddef}\n\n\n", "meta": {"hexsha": "c44baa470e001d0b18c808b6c3be03a13ec813b0", "size": 8466, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ubonn-thesis-current/mythesis/sections/thesis_class_bh.tex", "max_stars_repo_name": "cmp0xff/Masterarbeit", "max_stars_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_class_bh.tex", "max_issues_repo_name": "cmp0xff/Masterarbeit", "max_issues_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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": "ubonn-thesis-current/mythesis/sections/thesis_class_bh.tex", "max_forks_repo_name": "cmp0xff/Masterarbeit", "max_forks_repo_head_hexsha": "b29c84f9a29e4a7c9a3499658a1dfa7f87d64c9c", "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.5551020408, "max_line_length": 80, "alphanum_fraction": 0.6034727144, "num_tokens": 3120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6230470554783221}}
{"text": "Finite element method is a classic numerical method for solving partial differential equations. In this chapter, we \nwill give a brief introduction to this method. discuss its basic properties and error estimates. In later chapters, we \nwill show that the neural network functions can be viewed as an extension of finite element function. \nIn this chapter, we discuss the classical linear finite element spaces, the error estimate of the \nfinite element method and adaptivity method to improve the\napproximation. For shape-regular mesh, we will establish both the upper and lower bound of the \napproximation error. \n\n%In particular, we will show that the upper convergence \n%rate is also lower bound of the finite element method. This reveals the approximation\n%of finite element method is optimal. \n\n\\section{Linear finite element spaces}\\label{FEspace}\nIn this section, we introduce linear finite element spaces. We will walk through the basic setup, \nand derive some error estimates. \n%nodal basis functions and interpolation error estimate of linear finite element spaces. \n\n\\subsection{Triangulations}\n\n%-----------notation introduction--------------------------------------------------------------------\n\n%\\subsection{Shape-regular and quai-uniform triangulations}\nGiven a bounded polyhedral domain $\\Om\\subset \\mathbb {R}^d$, a geometric\ntriangulation (also called mesh or grid) $\\mathcal T_h=\\{\\tau\\}$ of $\\Omega$ is a\nset of $d$-simplices such that\n\\begin{enumerate}\n\\item[(1)] $\\overline \\Omega=\\cup \\tau$, where $ \\overline \\Omega$ denotes the closure of $\\Omega$. \n%\\item[(2)] for each $\\tau\\in \\mathcal T_h$, $\\tau$ is a close set with positive volume. \n\\item[(2)]  if $\\tau_1$ and $\\tau_2$ are distinct elements in $\\mathcal T_h$ then $\\stackrel{\\circ}{\\tau _1}\\cap \\stackrel{\\circ}{\\tau _2} = \\varnothing$, where $\\stackrel{\\circ}{\\tau _i}$ denotes the interior of $\\tau_i, i=1,2$ . \n\\end{enumerate}\nExamples of triangulations for $\\Omega=(0,1)$ ($d=1$) and for $\\Omega=(0,1)^2$ ($d=2$) are shown in\nFigure~\\ref{fig:1dpartition} and Figure~\\ref{2duniform}, respectively.\n\n\\begin{figure}\n\\setlength{\\unitlength}{0.14in} % selecting unit length\n\\begin{center} % used for centering Figure\n\\begin{picture}(32,1) % picture environment with the size (dimensions)\n\\put(8,0){\\line(1,0){16}}\n\\put(8,0){\\line(0,1){0.3}}\n\\put(7.5,1){$x_0$}\n\\put(9,0){\\line(0,1){0.3}}\n\\put(10,0){\\line(0,1){0.3}}\n\\put(11,0){\\line(0,1){0.3}}\n\\put(12,0){\\line(0,1){0.3}}\n\\put(13,0){\\line(0,1){0.3}}\n\\put(14,0){\\line(0,1){0.3}}\n\\put(15,0){\\line(0,1){0.3}}\n\\put(16,0){\\line(0,1){0.3}}\n\\put(15.5,1){$x_i$}\n\\put(17,0){\\line(0,1){0.3}}\n\\put(18,0){\\line(0,1){0.3}}\n\\put(19,0){\\line(0,1){0.3}}\n\\put(20,0){\\line(0,1){0.3}}\n\\put(21,0){\\line(0,1){0.3}}\n\\put(22,0){\\line(0,1){0.3}}\n\\put(23,0){\\line(0,1){0.3}}\n\\put(24,0){\\line(0,1){0.3}}\n\\put(23.5,1){$x_{n+1}$}\n\\end{picture}\n\\end{center}\n\\caption{1D uniform grid} % title of the Figure\n\\label{fig:1dpartition}\n\\end{figure}\n\\example Given $\\Omega=(0,1)$, we consider the mesh:\n\\begin{equation}\\label{partitionyx}\n 0=x_0<x_1<\\cdots<x_{n+1}=1, \\quad x_i=\\frac{i}{n+1},\\quad (i=0,\\cdots,n+1)\n \\end{equation}\nwhich is the 1D uniform grid shown in Figure \\ref{fig:1dpartition}.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=.25\\textwidth]{figures/grid1.png} \\qquad  \\includegraphics[width=.25\\textwidth]{figures/u00.pdf}  \\qquad \\includegraphics[width=.25\\textwidth]{figures/2ddiskpartition.pdf}  \n\\end{center}\n\\caption{2D grids}\n\\label{2duniform}\n\\end{figure}\n\nDenote \n$$\nh_\\tau=\\mbox{\\rm diam} (\\tau)\\quad  \\hbox{(diameter of the smallest sphere containing $\\overline{\\tau}$)},\n$$\nand \n$$\n h=\\max_{\\tau\\in\\mathcal T_h} h_\\tau;\\quad\n\\underline{h}=\\min_{\\tau\\in\\mathcal T_h} h_\\tau.\n$$\nA set of triangulations $\\mathscr T$ is called {\\em shape regular} if\nthere exists a constant $c_0$ such that\n\\begin{equation}\\label{shape} \\max _{\\tau \\in \\mathcal T_h} \\frac{h_{\\tau}^d}{|\\tau|}\\leq c_0, \\quad \\forall \\, \\mathcal T_h\\in\n\\mathscr T,\n\\end{equation} \nwhere $|\\tau|$ is the measure of $\\tau$ in $\\mbb R^d$. This assumption can also be represented as\n\\begin{equation}\\Label{A3.1}\n\\max_{\\tau\\in\\ct_h}\\frac{h_\\tau}{\\rho_\\tau}\\le\\sigma_1,\\quad \\forall \\, \\mathcal T_h\\in\n\\mathscr T,\n\\end{equation}\nwhere $\\rho_\\tau$\\index{$\\rho_\\tau$} denotes the radius of the ball\ninscribed in $\\tau$. In two dimensions, it is equivalent\nto the minimal angle of each triange is bounded below uniformly\nin the shape regular class. \n%We shall define $h_{\\tau} = |\\tau|^{1/n}$\n%for any $\\tau \\in \\mathcal T_h\\in \\mathscr T$. By (\\ref{shape}),\n%$h_{\\tau}\\eqsim {\\rm diam}(\\tau)$ represents the size of an element\n%$\\tau \\in \\mathcal T_h$ for a shape regular triangulation $\\mathcal T_h\\in\n%\\mathscr T$.\n\nIn addition to (\\ref{shape}), if\n\\begin{equation}\\Label{A3.2}\n  \\frac{\\max _{\\tau \\in \\mathcal T_h}|\\tau|}{\\min _{\\tau \\in \\mathcal T_h}|\\tau|} \\leq \\rho,\\quad \\forall \\, \\mathcal T_h\\in \\mathscr T,\n\\end{equation}\n$\\mathscr T$ is called {\\em quasi-uniform}. For quasi-uniform grids,\n$h=\\max _{\\tau \\in \\mathcal T_h} h_{\\tau}$, the mesh size of\n$\\mathcal T_h$, is used to measure the approximation rate. \n%In the FEM literature, we often write as $\\mathcal T_h$.\n\n%The triangulation $\\thset$ is said to be quasi-uniform\n%\\index{triangulation, quasi-uniform} if it satisfies \\rf{A3.1} and\n%the following\n%\\begin{eqhttps://gmu.zoom.us/j/97581839555?pwd=ZjlZeFE3Q0JkekdOcGpBZEZxdFJwQT09uation}\\Label{A3.2}\n%h\\le\\sigma_3 \\underline {h}.\n%\\end{equation}\n\nThe assumption \\rf{A3.1} is a local assumption, as is meant by above\ndefinition, for $d=2$ for example, it assures that each triangle will\nnot degenerate into a segment in the limiting case.  \n%A triangulation satisfying this assumption is often called to be {\\it shape regular}.\n\nOn the other hand, the assumption \\rf{A3.2} is a global assumption,\nwhich says that the smallest mesh size is not too small compared with\nthe largest mesh size of the same triangulation.  By the definition, in\na quasi-uniform triangulation, all the elements are about the same size\nasymptotically.\n\nLet $ x_{i}=(x^1_{i}, \\cdots, x^d_{i})^t, i=1,\\cdots, d+1$ be $d+1$ points in $\\mbb R^d$ which do not all lie in one hyper-plane. \nThe {\\it convex hull} of the $d+1$ points $ x_1, \\cdots,  x_{d+1}$ (See Figure \\ref{fig:barycentricCoor})\n\\begin{equation}\n\\tau :=\\{ x=\\sum _{i=1}^{d+1}\\lambda _i x_i \\, | \\, 0\\leq \\lambda_i\\leq 1, i=1:d+1, \\sum _{i=1}^{d+1}\\lambda _i=1 \\}\n\\end{equation}\nis defined as a {\\em geometric $d$-simplex} generated (or spanned) by\nthe vertices $ x_1, \\cdots,  x_{d+1}$. For example, a triangle\nis a $2$-simplex and a tetrahedron is a $3$-simplex. For an integer\n$0\\leq m \\leq d-1$, an $m$-dimensional face of $\\tau$ is any\n$m$-simplex generated by $m+1$ of the vertices of\n$\\tau$. Zero-dimenisonal faces are vertices and one-dimensional faces\nare called edges of $\\tau$. The $(d-1)$-face opposite to the vertex\n$ x_i$ will be denoted by $F_i$.\n\\begin{figure}[hpt]\n%\\subfigure[1d simplex]{\n%\\begin{minipage}[t]{0.33\\linewidth}\n\\centering\n\\includegraphics*[width=2.5cm]{figures/barycentricCoor1D.pdf}\n%\\end{minipage}}%%\n%\\subfigure[2d simplex]{\n%\\begin{minipage}[t]{0.33\\linewidth}\n%\\centering\n\\includegraphics*[width=3cm]{figures/barycentricCoor2D.pdf}\n%\\end{minipage}}%%\n%\\subfigure[3d simplex]\n%{\\begin{minipage}[t]{0.33\\linewidth}\n%\\centering\n\\includegraphics*[width=3.1cm]{figures/barycentricCoor3D.pdf}\n%\\end{minipage}}\n\\caption{Geometric explanation of barycentric coordinates}\n\\label{fig:barycentricCoor}\n\\end{figure}\n%\\paragraph{Barycentric coordinates}\nOn the other hand, for any $ x\\in \\tau$, there exist unique numbers $\\lambda _1,\\cdots, \\lambda _{d+1}$ satisfying $\\displaystyle 0\\leq \\lambda_i\\leq 1, i=1:d+1, \\sum _{i=1}^{d+1}\\lambda _i=1$ such that $\\displaystyle x=\\sum _{i=1}^{d+1}\\lambda _i x_i$, thus we can denote $\\lambda _1,\\cdots, \\lambda _{d+1}$ as $\\lambda _1( x),\\cdots, \\lambda _{d+1}( x)$. In fact,  the numbers $\\lambda _1( x),\\cdots, \\lambda _{d+1}( x)$ are\ncalled {\\em barycentric coordinates} of $ x$ with respect to the\n$d+1$ points $ x_1, \\cdots,  x_{d+1}$. There is a simple\ngeometric meaning of the barycentric coordinates. Given a $ x\\in\n\\tau$, let $\\tau _i( x)$ be the simplex with vertices $ x_i$\nreplaced by $ x$. Then it can be easily shown that\n\\begin{equation}\\label{eq:lambdasolution}\n\\lambda _i( x) = |\\tau _i( x)|/|\\tau|,\n\\end{equation}\nwhere $|\\cdot|$ is the Lebesgure measure in $\\mbb R^d$, namely area in\ntwo dimensions and volume in three dimensions. Note that $\\lambda\n_i( x)$ is affine function of $ x$ and vanishes on the face\n$F_i$. We list the four basic properties of barycentric coordinate below:\n\\begin{enumerate}\n\\item $0\\leq \\lambda_i( x)\\leq 1$;\n\\item $\\displaystyle\\sum_{i=1}^{d+1} \\lambda_i( x)=1$;\n\\item $\\lambda_i( x)\\in P_1(\\tau)$, where $P_1(\\tau)$ denotes the space of polynomials of degree $1$\n(linear) on $\\tau\\in \\mathcal T_h$;\n\\item $\\lambda_i( x_j)=\\delta_{ij}=\\begin{cases}\n1, \\quad &\\text{if}  \\quad  i=j\\\\\n0, \\quad &\\text{if} \\quad i\\neq j\n\\end{cases}.$\n\\end{enumerate}\n\n\\subsection{Continuous linear finite element spaces}\\label{linearFE}\nA conforming linear finite element function in a domain $\\Omega\\subset\n\\mathbb R^d$ is a continuous function that is piecewise linear\nfunction with respect to a grid or mesh consisting of a union of simplices.\n\nGiven a shape regular triangulation $\\mathcal T_h$ of $\\Omega$, we define the \ncontinuous linear finite element space as \n\\begin{equation}\\label{LinFE}\nV_h:=\\{v\\,|\\, v\\in C(\\overline \\Omega), \\,\\hbox{ and }\\, v|_{\\tau}\\in\nP_1(\\tau), \\forall \\tau \\in \\mathcal T_h\\},\n\\end{equation}\nwhere $P_1(\\tau)$ denotes the space of polynomials of degree $1$\n(linear) on $\\tau\\in \\mathcal T_h$. Whenever we need to deal with boundary\nconditions, we further define $V_{h,0}=V_h\\cap H_0^1(\\Omega)$.\n\nWe note here that the global continuity is also necessary in the\ndefinition of $V_h$ in the sense that if $u$ has a square interable\ngradient, that is $u\\in H^1(\\Omega)$, and $u$ is piecewise smooth,\nthen $u$ is continuous. \n\nWe always use $n_h$ to denote the dimension of finite element\nspaces. For $V_h$, $n_h$ is the number of vertices of the\ntriangulation $\\mathcal T_h$ and for $V_{h,0}$, $n_h$ is the number of\ninterior vertices. \n\n\\paragraph{Nodal basis functions and dual basis}\nFor linear finite element spaces, we have the so\ncalled \\emph{a standard nodal basis functions} $\\{\\varphi\n_i,i=1,\\cdots n_h\\}$ such that $\\varphi_i$ is piecewise linear (with\nrespect to the triangulation) and $\\varphi_i(x_j)=\\delta_{i,j}$.  Note\nthat $\\varphi _i|_\\tau$ is the corresponding barycentrical coordinates\nof $x_i$. See Figure \\ref{fig:nodalbasis} for an illustration in 2D.\n\\begin{figure}[hpt]\n%\\subfigure[1d basis function]{\n%\\begin{minipage}[t]{0.49\\linewidth}\n\\centering\n\\includegraphics*[height=4.5cm,width=7cm]{6DL/figures/Dualbasis}\n%\\end{minipage}}\n\\caption{Dual basis functions of $V_h$ in 1D for $n_h=5$.}\n\\label{fig:dualbasis}\n\\end{figure}\nLet $(\\varphi_i^*)_{i=1}^{n_h}$ be the dual basis of $(\\varphi_i)_{i=1}^{n_h}$, namely\n\\begin{equation}\n  \\label{eq:1}\n(\\varphi_i^*, \\varphi_j) =\\delta_{i, j}, \\quad i, j=1,\\ldots, n_h.    \n\\end{equation}\nWe notice that all the nodal basis functions $\\{\\varphi_i\\}$ are locally\nsupported, but their dual basis functions $\\{\\varphi_i^*\\}$ are in general\nnot locally supported (see Figure \\ref{fig:dualbasis}).  The nodal basis functions $\\{\\varphi_i\\}$ are\neasily constructed in terms of barycentric coordinate functions.  The\ndual basis $\\{\\varphi_i^*\\}$ are only interesting for theoretical\nconsideration and it is not necessary to know the actual constructions\nof these functions.\n\n%\n\\begin{figure}[hpt]\n%\\subfigure[1d basis function]{\n%\\begin{minipage}[t]{0.49\\linewidth}\n\\centering\n\\includegraphics*[height=4.5cm,width=7cm]{figures/basisfunction}\n%\\end{minipage}}%%\n%\\subfigure[2d basis function]{\n%\\begin{minipage}[t]{0.49\\linewidth}\n%\\centering\n\\includegraphics[height=5cm,width=7cm]{figures/nodalbasis.pdf}\n%\\end{minipage}}\n\\caption{Nodal basis functions in 1d and 2d}\n\\label{fig:nodalbasis}\n\\end{figure}\nSince $\\{\\varphi_i,i=1,\\cdots n_h\\}$ is a basis of $V_h$, therefore for any $v_h\\in V_h$, we have the representation\n$$\nv_h(x)=\\sum_{i=1}^{n_h}v_h(x_i)\\varphi_i(x). \n$$\n\nLet us see how our construction of continuous linear finite space and the nodal basis looks like  in one spatial dimension. \nAssociated with the mesh\n$$\n\\mathcal T_h=\\{0=x_0<x_1<\\ldots<x_{n_h}<x_{n_h+1}=1\\},\n$$\nby the definition given in \\eqref{LinFE} and the definition  $V_{h,0}=V_{h}\\cap H_0^1(\\Omega)$, we have\n\\[\n\\begin{array}{ll}\nV_{h,0}=\\{v:~\\mbox{$v$ is continuous and piecewise linear}~ \\mbox{w.~r.~t. $\\mathcal T_h$, } v(0)=v(1)=0\\}.\n\\end{array}\n\\]\nA plot of a typical element of $V_{h,0}$ is shown in Fig.~\\ref{fig:1dtypical}.\n\nIt is easily calculated (as we already mentioned), that the dimension\nof $V_{h,0}$ is equal to the number of internal vertices, and the nodal\nbasis functions spanning $V_{h,0}$ (for $i=1,2,\\cdots,n_h$) are (see also\nFig.~\\ref{fig:nodalbasis}):\n\\begin{equation}\\label{1dbasis:function}\n\\varphi_i(x)=\\left\\{\\begin{array}{cl}\n\\displaystyle \\frac{x-x_{i-1}}{h}, & x\\in[x_{i-1},x_i];\\\\\n\\displaystyle \\frac{x_{i+1}-x}{h}, & x\\in[x_{i},x_{i+1}];\\\\\n0 &\\mbox{elsewhere}.\n\\end{array}\\right.\n\\end{equation}\n\n\\begin{figure}[hpt]\n\\centering\n\\includegraphics*[width=2in]{figures/femfunction1.pdf}\n\\caption{Plot of a typical element from $V_{h,0}$.} \n\\label{fig:1dtypical}\n\\end{figure}\n\n\n\n%%%%%%%%%%%%%%%%%%%%END from grid.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%END from grid.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%END from grid.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "554ca7e83d5956d37ea0909ba59c93261ffea3c6", "size": 13626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/6 Finite Element Method/6.1-FEspaces.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/6 Finite Element Method/6.1-FEspaces.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/6 Finite Element Method/6.1-FEspaces.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.9702970297, "max_line_length": 426, "alphanum_fraction": 0.6986643182, "num_tokens": 4668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754371026367, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.6230386168231169}}
{"text": "\\chapter{Ambipolar Diffusion Coefficient}\n\\label{app:adc}\nSeen below is a MATLAB\\textsuperscript{TM} which can calculate the ambipolar diffusion coefficient. \n\n\\begin{verbatim}\n\n\n% Dominic Lunde\n% Validation of ambipolar diffusion\n\nclose all;\nclearvars;\n\n% page 78\n\n%-D_a grad^2 n = 0;\n\ne = 1.6e-19;\nm_e = 9.109e-31;\nm_i = 6.63e-26;\nk = 1.38e-23;\n\nn_e = 10^12;\nT_eV = 100;\nT_i = 5000;\n\n% page 70\nlnV = 23 - 0.5 * log(10^6 * n_e / T_eV^3);\n\nnu = 2.9e-12 * n_e * lnV / T_eV^1.5;\n\n\nmu_e = e / (m_e * nu);\nmu_i = e / (m_i * nu);\n\nD_e = T_eV / (m_e * nu);\nD_i = k * T_i / (m_i * nu);\n\nD_a = (mu_i * D_e + mu_e * D_i) / (mu_i + mu_e);\n\n\\end{verbatim}\n", "meta": {"hexsha": "6d35214ed0a1fb98830d02c97145c982387277f3", "size": 645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/D_acalc.tex", "max_stars_repo_name": "dclunde/thesis-template", "max_stars_repo_head_hexsha": "7f987df93321a6522a784aa9d0dc788608c2166a", "max_stars_repo_licenses": ["MIT"], "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/D_acalc.tex", "max_issues_repo_name": "dclunde/thesis-template", "max_issues_repo_head_hexsha": "7f987df93321a6522a784aa9d0dc788608c2166a", "max_issues_repo_licenses": ["MIT"], "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/D_acalc.tex", "max_forks_repo_name": "dclunde/thesis-template", "max_forks_repo_head_hexsha": "7f987df93321a6522a784aa9d0dc788608c2166a", "max_forks_repo_licenses": ["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.3571428571, "max_line_length": 100, "alphanum_fraction": 0.6170542636, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757596, "lm_q2_score": 0.6688802669716107, "lm_q1q2_score": 0.6230368941526094}}
{"text": "\\section{Limits of Sequences}\n\\subsection{Convergence and limit laws}\n\\declareexercise{6.1.1}\nLet $m=n+q$, then we may induct on $q$.\n\n\\declareexercise{6.1.2}\n\\noindent given any $\\varepsilon>0 \\equiv \\forall \\varepsilon>0$\\\\\neventually $\\varepsilon$-close $\\equiv \\exists N\\geq m(n\\geq N \\to |a_n - L| <\\varepsilon)$\n\n\\declareexercise{6.1.3}\nBase on \\exerciseref{6.1.2}, if $\\{a_n\\}^\\infty_{n=m}$ is convergent, then for any $\\varepsilon>0$, we can find $N$ such that $\\forall n\\geq N( |a_n-L|<\\varepsilon)$. Thus, $\\forall n\\geq \\max(N,m') (|a_n-L|< \\varepsilon)$, which means that $\\{a_n\\}^\\infty_{n=m'}$ is convergent.\n\nIt is easy to prove the converse.\n\n\\declareexercise{6.1.4}\n$\\{a_{n+k}\\}^\\infty_{n=m}$ is essentially $\\{a_{n}\\}^\\infty_{n=m+k}$. So it is immediately derived from the previous exercise.\n\n\\declareexercise{6.1.5}\n\\[\n|a_p-a_q| \\leq |a_p-L| + |L-a_q| \\leq 2\\varepsilon\n\\]\n\n\\declareexercise{6.1.6}\n$\\forall m \\geq 1, a_m = \\LIM a_m$. $a_m - L = \\LIM{a_m} - \\LIM{a_n} = \\LIM{(a_m-a_n)}$. Suppose that $a_m$ is not eventually $\\varepsilon$-close to $L$ for all $\\varepsilon>0$, then $\\exists \\epsilon >0(\\forall N \\geq 1(\\exists M \\geq N(|\\LIM{(a_m-a_n)}|>\\epsilon)))$. Since that $\\{a_n\\}$ is a Cauchy sequence, $\\exists P(\\forall m,n\\geq P(|a_m-a_n|\\leq \\epsilon))$. Given these $m,n$, we have\n\\[\n|\\LIM{(a_m-a_n)}| = \\LIM{|a_m-a_n|} \\leq \\LIM \\epsilon = \\epsilon\n\\]\n, a contradiction.", "meta": {"hexsha": "f20bddf24d98e254b981dd9ce958b52e9f5c3720", "size": 1403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Limit of Sequences.tex", "max_stars_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_stars_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Limit of Sequences.tex", "max_issues_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_issues_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Limit of Sequences.tex", "max_forks_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_forks_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_forks_repo_licenses": ["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.1071428571, "max_line_length": 395, "alphanum_fraction": 0.6550249465, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293653760418, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.6228950739559423}}
{"text": "\n% \\chapter{ANN - Artificial Neural Networks}\n% \\section{Basic Architecture}\n\n\\chapter{DNN --- Deep Neural Networks}\n\\section{ANN --- Artificial Neural Networks}\n\\section{Basic Architecture}\n\n\\section{NN Layers}\n\\subsection{Linear Layers}\n\\subsubsection{Linear}\n\\subsubsection{Bi-Linear}\n\n\\subsection{Convolution Layers}\n\\subsubsection{Convoltion operation}\n\\begin{equation} \\label{eq:conv_operation}\n    \\text{out}(N_i, C_{\\text{out}_j}) = \\text{bias}(C_{\\text{out}_j}) +\n    \\sum_{k = 0}^{C_{in} - 1} \\text{weight}(C_{\\text{out}_j}, k)\n    \\star \\text{input}(N_i, k)\n\\end{equation}\n\nBoth the weights and bias parameters are learnable during the training\nprocess of the network.\n\n\\subsubsection{Convolutional Layer Parameters}\n\\subsection*{Kernel}\nA kernel, or a filter, is a set of values that convolves with\nthe input feature map\nas part of the convolutional neural network.\nThe convolution layer takes the kernel as one operand,\nand ``slides'' it over the second operand.\nAs seen in Equation~\\ref{eq:conv_operation},\nthe convolution operation, sums the dot product of two operands\nover the total number of weight values in the kernel.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm}, on grid]\n        \\draw[fill=base02a,opacity=0.4] (0,0) rectangle (3,3);\n        \\draw[draw=base03,thick] (0,0) grid (3,3);\n        \\node (00) at (0.5,2.5) {\\tiny 0};\n        \\node (01) at (1.5,2.5) {\\tiny 1};\n        \\node (02) at (2.5,2.5) {\\tiny 2};\n        \\node (10) at (0.5,1.5) {\\tiny 3};\n        \\node (11) at (1.5,1.5) {\\tiny 4};\n        \\node (12) at (2.5,1.5) {\\tiny 5};\n        \\node (20) at (0.5,0.5) {\\tiny 6};\n        \\node (21) at (1.5,0.5) {\\tiny 7};\n        \\node (22) at (2.5,0.5) {\\tiny 8};\n    \\end{tikzpicture}\n\\end{figure}\n\nThe kernel above, is of size \\( \\left( \\left[ 3, 3 \\right] \\right) \\).\nPresenting it as a 4D-Tensor, would give: \\( \\left( N, C, k_{H}, k_{W} \\right)  = \\left( \\left[ 1, 1, 3, 3 \\right] \\right)  \\)\n\n\\subsection*{Stride}\nThe stride parameter controls the steps in which the kernel\nmoves across the input feature map.\nIt takes two values, \\( \\left( \\left[ s_{H}, s_{W} \\right] \\right) \\),\nwhere \\( H_{s}, W_{s} \\) are the integer step values for the\nheight and the width movements across the input feature map.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm}, on grid]\n        \\begin{scope}[xshift=0,yshift=0cm]\n            \\begin{scope}[xshift=0cm,yshift=0cm]\n                \\draw[draw=base03,fill=blue,thick] (0,0) grid (5,5) rectangle (0,0);\n                \\draw[fill=base02a, opacity=0.4] (0,2) rectangle (3,5);\n            \\end{scope}\n            % \\begin{scope}[xshift=7cm,yshift=1.5cm]\n            %     \\draw[draw=base03,fill=cyan,thick] (0,0) grid (2,2) rectangle (0,0);\n            % \\end{scope}\n        \\end{scope}\n        \\draw[draw=base03, ->, thick] (2.6,3.5) to  (4.5,3.5);\n        \\draw[draw=base03, ->, thick] (1.5,2.4) to (1.5,0.5);\n        % \\draw[draw=base03, ->, thick] (5.25, 2.5) to (6.75, 2.5);\n        % \\begin{scope}[xshift=12cm,yshift=0cm]\n        %     \\begin{scope}[xshift=0cm,yshift=0cm]\n        %         \\draw[draw=base03,fill=blue,thick] (0,0) grid (5,5) rectangle (0,0);\n        %         \\draw[fill=base02, opacity=0.4] (0,2) rectangle (3,5);\n        %     \\end{scope}\n        %     \\begin{scope}[xshift=7cm,yshift=1cm]\n        %         \\draw[draw=base03,fill=cyan,thick] (0,0) grid (3,3) rectangle (0,0);\n        %         \\draw[draw=base03] (1,0) -- (2,1) -- (2,0) -- (1,1);\n        %         \\draw[draw=base03] (0,1) -- (1,2) -- (1,1) -- (0,2);\n        %         \\draw[draw=base03] (1,1) -- (2,2) -- (2,1) -- (1,2);\n        %         \\draw[draw=base03] (2,1) -- (3,2) -- (3,1) -- (2,2);\n        %         \\draw[draw=base03] (1,2) -- (2,3) -- (2,2) -- (1,3);\n        %     \\end{scope}\n        %     \\begin{scope}[xshift=12cm,yshift=1.5cm]\n        %         \\draw[draw=base03,fill=cyan,thick] (0,0) grid (2,2) rectangle (0,0);\n        %     \\end{scope}\n        % \\end{scope}\n        % \\draw[draw=base03, ->, thick] (14.6,3.5) to  (15.5,3.5);\n        % \\draw[draw=base03, ->, thick] (15.6,3.5) to  (16.5,3.5);\n        % \\draw[draw=base03, ->, thick] (13.5,2.4) to (13.5,1.5);\n        % \\draw[draw=base03, ->, thick] (13.5,1.4) to (13.5,0.5);\n        % \\draw[draw=base03, ->, thick] (17.25, 2.5) to (18.75, 2.5);\n        % \\draw[draw=base03, ->, thick] (22.25, 2.5) to (23.75, 2.5);\n    \\end{tikzpicture}\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm}, on grid]\n        \\tikzmath{\n            let \\strt = 0;\n            let \\stp = 7;\n        }\n\n        \\draw[draw=base03,fill=blue,thick] (\\strt,\\strt) grid (\\stp,\\stp) rectangle (0,0);\n        \\draw[fill=base02a, dashed, opacity=0.4] (\\strt-1,\\strt-1) grid (\\stp+1,\\stp+1);\n        % \\draw[fill=base02a, opacity=0.4] (0,2) rectangle (3,5);\n        % \\draw[draw=base03, ->, thick] (1.5,2.4) to (1.5,0.5);\n    \\end{tikzpicture}\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[\\label{mel_fb_ref}]{\n        \\centering\n        \\begin{tikzpicture}[scale=.35,every node/.style={minimum size=1cm},\n                on grid]\n            \\draw[fill=blue] (0,0) rectangle (5,5);\n            \\draw[draw=base03, thick] (0,0) grid (5,5);\n            \\draw[fill=base02, opacity=0.4] (0,2) rectangle (3,5);\n            \\draw[step=10mm, base03, thick] (0,2) grid (3,5);\n            \\draw[draw=base03, ->, thick] (2.6,3.5) to  (3.5,3.5);\n            \\draw[draw=base03, ->, thick] (3.6,3.5) to  (4.5,3.5);\n            \\draw[draw=base03, ->, thick] (1.5,2.4) to  (1.5,1.5);\n            \\draw[draw=base03, ->, thick] (1.5,1.4) to  (1.5,0.5);\n        \\end{tikzpicture}\n    }\n    \\subfloat[\\label{mel_fb_ref}]{\n        \\centering\n        \\begin{tikzpicture}[scale=.35,every node/.style={minimum size=1cm},\n                on grid]\n            \\draw[fill=blue] (0,0) rectangle (5,5);\n            \\draw[draw=base03, thick] (0,0) grid (5,5);\n            \\draw[fill=base02, opacity=0.4] (0,2) rectangle (3,5);\n            \\draw[step=10mm, base03, thick] (0,2) grid (3,5);\n            \\draw[draw=base03, ->, thick] (2.5,3.5) to  (4.5,3.5);\n            \\draw[draw=base03, ->, thick] (1.5,2.5) to  (1.5,0.5);\n        \\end{tikzpicture}\n    }\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\\subsection*{Padding}\nPadding is a method of extending the input feature map with\nzero values all around in order to control the size dimensions of the\noutput feature map. This parameter takes a 2D-Tensor in the form of:\n\\( \\left( \\left[ p_{H}, p_{W} \\right] \\right) \\), where \\( P_{H}, P_{W} \\),\ndescribes the padding depth in the height and width dimensions of the\ninput feature map.\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm}, on grid]\n        \\draw[draw=base03,fill=blue,thick] (0,0) grid (5,5) rectangle (0,0);\n        \\draw[fill=base02a, dashed, opacity=0.4] (-1,-1) grid (6,6);\n        % \\draw[fill=base02a, opacity=0.4] (0,2) rectangle (3,5);\n        % \\draw[draw=base03, ->, thick] (1.5,2.4) to (1.5,0.5);\n    \\end{tikzpicture}\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\\subsection*{Dilation}\nDilation represents the integer spaces placed between the kernel elements.\nFor a given dilation value \\(d\\),\nthe elements of the kernel are spaced with \\(d - 1\\) in between.\n\nThis parameter takes a 2D-Tensor in the form of:\n\\( \\left( \\left[ d_{H}, d_{W} \\right] \\right) \\),\nwhere \\( d_{H}, d_{W} \\),\ndescribes the \\(d - 1 \\) spaces in between kernel elements.\n\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[\\label{conv2d_dil1}]{\n        \\begin{tikzpicture}[scale=.4,every node/.style={minimum size=1cm}, on grid]\n\n            \\draw[draw=base03,fill=blue,thick] (0,0) grid (7,7) rectangle (0,0);\n            \\draw[fill=base02a, dashed, opacity=0.4] (-1,-1) grid (8,8);\n\n            \\foreach \\x in {0,1,2} {\n                    \\foreach \\y in {4,5,6} {\n                            \\draw[fill=base02a, opacity=0.4] (\\x,\\y) rectangle (\\x+1,\\y+1);\n                            % \\node at (\\x,\\y) [circle,fill=black] {};\n                            %this way circle of nodes will not be transformed\n                        }\n                }\n            % \\draw[draw=base03, ->, thick] (2.5,2.4) to (2.5,0.5);\n            \\draw[draw=base03, ->, thick] (1.5,5.5) to  (3.5,5.5);\n            \\draw[draw=base03, ->, thick] (1.5,5.5) to  (1.5,3.5);\n        \\end{tikzpicture}\n    }\n    \\subfloat[\\label{conv2d_dil2}]{\n        \\begin{tikzpicture}[scale=.4,every node/.style={minimum size=1cm}, on grid]\n            \\draw[draw=base03,fill=blue,thick] (0,0) grid (7,7) rectangle (0,0);\n            \\draw[fill=base02a, dashed, opacity=0.4] (-1,-1) grid (8,8);\n\n            \\foreach \\x in {0,2,4} {\n                    \\foreach \\y in {2,4,6} {\n                            \\draw[fill=base02a, opacity=0.4] (\\x,\\y) rectangle (\\x+1,\\y+1);\n                            % \\node at (\\x,\\y) [circle,fill=black] {};\n                            %this way circle of nodes will not be transformed\n                        }\n                }\n            % \\draw[draw=base03, ->, thick] (2.5,2.4) to (2.5,0.5);\n            \\draw[draw=base03, ->, thick] (2.5,4.5) to  (5.5,4.5);\n            \\draw[draw=base03, ->, thick] (2.5,4.5) to  (2.5,1.5);\n        \\end{tikzpicture}\n    }\n    % \\subfloat[\\label{conv2d_dil3}]{\n    %     \\begin{tikzpicture}[scale=.4,every node/.style={minimum size=1cm}, on grid]\n    %         \\draw[draw=base03,fill=blue,thick] (0,0) grid (9,9) rectangle (0,0);\n    %         \\draw[fill=base02a, dashed, opacity=0.4] (-1,-1) grid (10,10);\n\n    %         \\foreach \\x in {0,3,6} {\n    %             \\foreach \\y in {2,5,8} {\n    %                 \\draw[fill=base02a, opacity=0.4] (\\x,\\y) rectangle (\\x+1,\\y+1);\n    %             }\n    %         }\n    %         \\draw[draw=base03, ->, thick] (3.5,5.5) to  (5.5,5.5);\n    %         \\draw[draw=base03, ->, thick] (3.5,5.5) to  (3.5,3.5);\n    %     \\end{tikzpicture}\n    % }\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\\subsubsection{Convolutional Layer Output}\nA convolutional layer,\nafter convolving a kernel with an input tensor,\noutputs a feature map. The output feature map dimensions\nare set by the different parameters of the convolutional layer.\n\nThe padding \\( p_{H}, p_{W} \\) increases the height and width of\nthe output feature map, while the stride \\( s_{H}, s_{W} \\)\nand dilation \\( d_{H}, d_{W} \\) shrink it.\n\n\\begin{align}\n    H_{out} = & \\left\\lfloor\\frac{H_{in}  + 2 \\times p_{_{H}} - d_{_{H}}\n    \\times (k_{_{H}} - 1) - 1}{s_{_{H}}} + 1\\right\\rfloor                \\\\\n    W_{out} = & \\left\\lfloor\\frac{W_{in}  + 2 \\times p_{_{W}} - d_{_{W}}\n        \\times (k_{_{W}} - 1) - 1}{s_{_{W}}} + 1\\right\\rfloor\n\\end{align}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm}, on grid]\n        \\begin{scope}[xshift=0,yshift=0cm]\n            \\begin{scope}[xshift=0cm,yshift=0cm]\n                \\draw[draw=base03,fill=blue,thick] (0,0) grid (5,5) rectangle (0,0);\n                \\draw[fill=base02, opacity=0.4] (0,2) rectangle (3,5);\n            \\end{scope}\n            \\begin{scope}[xshift=7cm,yshift=1.5cm]\n                \\draw[draw=base03,fill=cyan,thick] (0,0) grid (2,2) rectangle (0,0);\n            \\end{scope}\n        \\end{scope}\n        \\draw[draw=base03, ->, thick] (2.6,3.5) to  (4.5,3.5);\n        \\draw[draw=base03, ->, thick] (1.5,2.4) to (1.5,0.5);\n        \\draw[draw=base03, ->, thick] (5.25, 2.5) to (6.75, 2.5);\n    \\end{tikzpicture}\n    \\caption{(a) Mel Filter-Bank representation}\n\\end{figure}\n\n\n\n\\subsection{Recurrent Layers}\n\\subsubsection{LSTM}\n\\subsubsection{BLSTM}\n\\subsubsection{RNN}\n\n\\subsection{Transformer Layers}\n\\subsubsection{Transformer}\n\\subsubsection{Transformer-Encoder}\n\\subsubsection{Transformer-Decoder}\n\n\n\\section{NN Function Layers}\n\\subsection{Non-linear Activations Functions}\nBasic neuron model is not capable of doing much\nwhen it comes to non-linearity decisions.\n\n\n\n\\subsubsection{ReLU --- Rectified Linear Unit}\nThis activation function rectifies all the negative\nvalues presented in the output feature map, resulted\nfrom the previous in-line CNN layer.\n\nApplying the ReLU activation function\nactually means, in other words, evaluating the following equation: \\(ReLU(x) = {\\left(x\\right)}^{+} = \\max(0, x)\\)\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{ANN/images/relu}\n    \\caption{ReLU activation function and its derivative}\\label{fig:relu_af}\n\\end{figure}\n\n% \\input{images/relu}\n\n\\subsubsection{LeakyReLU}\nA problem that arises whenever a\nReLU activation function is used within a neural-network\nis during the training process.\nThe back-propagation operation\nworks on the derivatives of the activation functions.\nA ReLU function, clamps all the negative values,\nwhich means, a constant zero value for any input value,\nlower than 0. Thus, the derivative of the function\nfor negative \\(x\\) values is constant 0 as well.\n\nThis kind of behavior, although very simple to implement,\nis undesirable and can lead to the nulling of large\nsections of the neural network neurons during training.\n\nA small modification to the\nReLU function can help overcome that\nproblem very easily, while maintaining\nthe ``same'' characteristics of the\noriginal ReLU function.\n\nBy introducing a small negative slope,\nthe activation function outputs are not pure zeroes.\nOn top of that, derivatives are also not zero. In that\nway, a dying ReLU is prevented.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{ANN/images/leakyrelu}\n    \\caption{Leaky-ReLU activation function and its derivative}\\label{fig:leakyrelu_af}\n\\end{figure}\n\n\\subsubsection{Sigmoid}\nAnother activation function that is commonly used,\nis the Sigmoid function. This function is unique\nin the matter that it is bounded between \\((0, 1)\\),\nand both the function and its derivate are continuous.\n\nSigmoid activation functions are usually in use whenever\na network is designed to classify and predict\nvalues between 0 and 1.\n\nAn additional advantage of the Sigmoid function is the\nfact that its derivative can be\nevaluated as \\(g(x)(1-g(x))\\), which makes it very\nefficient in terms of computation efforts, as the result calculated\nwhile forward propagating through the network, is\nused in the back-propagation training process.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{ANN/images/sigmoid}\n    \\caption{Sigmoid activation function and its derivative}\\label{fig:sigmoid_af}\n    % \\source{Adapted from \\citep{ADI_MIMO}}\n\\end{figure}\n\n\\subsubsection{Tanh}\nThe benefits of using the Sigmoid activation function\nwere described above.\nHowever, the Sigmoid function characteristics might not\nbe enough for applications where the difference\nbetween classes is dichotomy. In such cases,\nthe contrast between predicted classes should be\nstrongly emphasized.\n\nThe Tanh, hyperbolic tangent, activation function\nmaintains the continuity characteristics of the\nSigmoid function while extending the range limit to\n\\((-1, 1)\\). That said, the derivative of the Tanh\nfunction is very distinctive in the middle, getting\nthe value of 1.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{ANN/images/tanh}\n    \\caption{Tanh activation function and its derivative}\\label{fig:tanh_af}\n    % \\source{Adapted from \\citep{ADI_MIMO}}\n\\end{figure}\n\n% \\subsubsection{Softplus}\n\n\\subsection{Normalization Functions}\n\\subsubsection{Batch-Normalization}\n\n\\subsection{Pooling Functions}\n\\subsubsection{Min-pooling}\n\\subsubsection{Average-pooling}\n\\subsubsection{Max-pooling}\n\n\\section{Dropout Layers}\n\\subsubsection{p-Dropout}\nTo avoid some redundant feature\\((s)\\) detection by multiple neurons in a network,\na co-adaptation amongst the different neurons in the model should be prevented.\nIn that way, the NN model is much more effective and uses resources more efficiently.\n\nThis holds true especially during training, as described in this paper\n% \\citep{hinton2012improving}.\n\nThe idea is to zero-out, arbitrarily, values of\nthe input feature.\nBased on the \\emph{Bernoulli distribution}, the probability to zero an element gets the\nprobability \\(p\\), while the opposite, non-zeroing probability is set to \\(1-p\\).\n\nRaising the \\(p\\) value too high, may lead to an exhaustive training process, thus\na good balance point should be used to overcome the co-adaptation while not missing\nuseful features. Whenever the training sets are considered large, a small portion\nof zeroed elements should be sufficient for satisfactory results.\n\n\\section{Loss Functions}\n\\subsection{L1 Loss (MAE)}\nL1 loss, also known as MAE (Mean Absolute Error) is a\nloss criterion that measure the quality of the estimation\nof an exemplar compared to the proposed matching target.\n\\begin{align}\n    \\ell(\\hat{x}, x) & = L_{1} = mean\\left\\{ \\left[ l_{1}, l_{2},...,l_{N}\\right]^{T}\\right\\}\n\\end{align}\nWhere each element in \\(L\\) is evaluated as:\n\\[ l_{n} = |\\widehat{x_{_{n}}} - x_{_{n}}| \\]\n\nThe estimated exemplar and the target are denoted as \\(\\hat{x}, x\\) \nrespectively. In turn, that gives:\n\\begin{equation}\n    \\ell(\\hat{x}, x) = L_{1} = \\frac{1}{N} \\sum_{n=1}^{N} |\\widehat{x_{_{n}}} - x_{_{n}}|\n\\end{equation}\n\\subsection{L2 Loss (MSE)}\nL2 loss, in contrast to the L1 loss function, is differentiable. Therefore,\nit is used more frequently in applications where \ngradient decent back-propogation is applied for classification based\npredictions. This technique for optimizing a classifying algorithm,\nis very common in Neural Networks systems.\n\nThe L2 loss, also known as MSE (Mean Square Error), is defined similarly to\nthe L1 loss function but instead of taking the Euclidean distance as \nthe error of prediction, the square error is taken. Thus, \nit can be derived as:\n\\begin{align}\n    \\ell(\\hat{x}, x) & = L_{2} = mean\\left\\{ \\left[ l_{1}, l_{2},...,l_{N}\\right]^{T}\\right\\}\n\\end{align}\nWhere each element in \\(L\\) is evaluated as:\n\\begin{equation*}\n    l_{n} = \\left(\\widehat{x_{_{n}}} - x_{_{n}}\\right)^{2}\n\\end{equation*}\nIn turn, that yields:\n\\begin{equation}\n    \\ell(\\hat{x}, x) = L_{2} = \\frac{1}{N} \\sum_{n=1}^{N} \\left(\\widehat{x_{_{n}}} - x_{_{n}}\\right)^{2}\n\\end{equation}\n\nThe L2 loss can be further extended by introducing the \nRMSE (Root Mean Square Error) criterion which has the same units \nas the target, \\(x_{_{n}}\\).\n\\begin{equation}\n    RMSE = \\sqrt{L_{_{2}}} = \\sqrt{\\frac{1}{N} \\sum_{n=1}^{N} \\left(\\widehat{x_{_{n}}} - x_{_{n}}\\right)^{2}}\n\\end{equation}\n\n\\subsection{Huber Loss}\nThe \\emph{Huber Loss} was developed to overcome \nthe sensitivity of an L2 loss to large errors, which are typical in situations\nsuch as when outliers are present or at the very early stages of a training process,\nwhile maintaining a continuous and differentiable characteristics' nature.\n\\begin{equation}\n    \\ell(\\hat{x}, x) = HL = mean\\left\\{ \\left[ l_{1}, l_{2},...,l_{N}\\right]^{T}\\right\\}\n\\end{equation}\n\nWhere each element in \\(HL\\) is evaluated as follows:\n\\begin{align}\n    l_{n} & = \\begin{cases}\n        \\frac{1}{2}\\left( \\widehat{x_{_{n}}} - x_{_{n}} \\right)^{2}, & |\\widehat{x_{_{n}}} - x_{_{n}}| \\leq \\tau  \\\\\n        \\tau |\\widehat{x_{_{n}}} - x_{_{n}}|-\\frac{1}{2}\\tau, & |\\widehat{x_{_{n}}} - x_{_{n}}| > \\tau\n    \\end{cases}\n\\end{align}\n%\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.95\\linewidth]{ANN/images/l1l2huber_comparison}\n    \\caption{L1 vs. L2 vs. Huber Loss functions comparison}\\label{fig:l1l2huber_comparison}\n\\end{figure}\n\n\n\n\\subsection{Cross-Entropy}\n\\subsection{CTC}\nThe CTC loss is the negative logarithm if the probability.\n\n\\begin{equation}\n    \\hat{\\theta} = arg \\min_{\\theta} - \\sum_{i=1}^{N} \\left[ \\sum p\\left( \\pi | x^{(i)}; \\theta \\right) \\right]\n\\end{equation}\n\nThe generated label is then collapsed, that is, the repeated characters not \nseparated by the ``blank'' character are minimized to a single character.\n\n\\subsubsection{KL-Div}\n\\begin{equation}\n    \\ell(x, y) = L = \\left\\{ \\ell_{_{1}}, \\ell_{_{2}}, ..., \\ell_{_{N}} \\right\\} \n\\end{equation}\n\n\\begin{equation}\n    \\ell_{_{n}} = y_{_{n}} \\left[ \\log \\left( y_{_{n}} \\right) - x_{_{n}} \\right]\n\\end{equation}\n\nThe kldiv loss also can be reduced over the mini-batch size, as follows:\n\\begin{equation}\n    \\ell(x, y) = \\begin{cases}\n        \\frac{\\sum {L}}{batch\\_size}, & red=meanbatch \\\\\n        \\sum {L}, & red=sum\n    \\end{cases}\n\\end{equation}", "meta": {"hexsha": "9732f792e47cb63ddb348d92d8819d951531c3aa", "size": 20618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/ANN/ann.tex", "max_stars_repo_name": "aviadb/research", "max_stars_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Dissertation/ANN/ann.tex", "max_issues_repo_name": "aviadb/research", "max_issues_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Dissertation/ANN/ann.tex", "max_forks_repo_name": "aviadb/research", "max_forks_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_forks_repo_licenses": ["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.26953125, "max_line_length": 126, "alphanum_fraction": 0.6293529925, "num_tokens": 6798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6228950539928075}}
{"text": "% !TeX spellcheck = en_US\n\\documentclass[]{report}\n\\usepackage[utf8]{inputenc}\n\\usepackage{lmodern}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n\n\\section{Array Antennas}\n% TODO: a lot of references to Balanis\nThe radiation characteristic of a complete array antenna is determined from the radiation characteristic of a singular element and the array factor:\n\\begin{equation}\n\tS_{Array}(\\theta, \\phi) = S_{Element}(\\theta, \\phi) \\cdot AF(\\theta, \\phi) \\text{ .}\n\\end{equation}\nThe array factor can be determined by treating every source of radiation in the array as an isotropic radiator and summing their effects as the principle of superposition holds in linear media (e.g. free space).\n\nAs an example, the array factor for an uniform linear array antenna of N elements is determined to be \n\\begin{equation}\n\tAF(\\theta) = \\sum_{n=0}^{N-1}\\exp(inkd\\cos\\theta)\n\\end{equation}\nwhere \\( k \\) refers to the wavenumber (spatial frequency of the wave) and \\( d \\) refers to the inter-element distance. Wavenumbers can contain an imaginary part to model attenuation, but this won't be considered here. The inter-element distance is chosen to be smaller than the wavelength \\( \\lambda \\) to avoid grating lobes [REF] but great enough to avoid physical overlap and mutual coupling in the near-field.\n% TODO: Ref to balanis\n% TODO: Add a plot\n\nFrom the plot [REF, ADD PLOT] it can be seen that an array antenna is useful for achieving an increase in directivity as at point [...] all individual antennas constructively interfere. Highly directive antennas, however, require precise alignment between the transmitter and receiver. Furthermore, if either the transmitter or the receiver is moving, alignment by mechanically orientating antennas becomes too slow and bothersome, therefore techniques for forming and/or steering the beams through other means are interesting.\n\n\\section{Beamforming and Beamsteering}\n\nThe term beamforming will be used to denote the overarching category of techniques that dynamically change the radiation characteristic of an antenna. In this category the technique of beamsteering is very prominent. Beamsteering has the goal of concentrating the maximum directivity of the antenna towards a chosen target.\n\n\n- upper element has to be this earlier in time\n\\begin{equation}\n\tt = \\frac{s}{v_{ph}}\n\\end{equation}\n\n- this equals a phase shift of\n\\begin{equation}\n\t\\Delta \\phi = k t v_{ph} = k s = k d\\sin\\alpha\n\\end{equation}\n\n- illustration for the process in one dimension\n\n- result for array factor in one dimension as plot\n\n- this can be extended to two extensions and NxM elements\n\\begin{equation}\n\t\\phi(m,n) = k\\sin\\theta(md_x\\cos\\phi + nd_y\\sin\\phi)\n\\end{equation}\n- dx, dy refer to inter-element distances in their respective axes\n\n- plot of result for two dimensions\n\n- add profile for focusing the beam (e.g. bessel-beam, Gaussian beam?)\n\n- how to achieve the phase shifts?\n\n\\section{Implementation}\n\n- in the following:\n\n- before radiation is emitted, electrical phase shifting\n\n- after radiation is emitted, optics (e.g. lenses / reflectors)\n\n- combination of both\n\n\\subsection{Electrical}\n\n\\subsection{Optical}\n\n- lenses, change optical path length by refractive index; quite constant across frequency (non-dispersive), therefore don't limit bandwidth, but introduce losses, also consider matching (easier with silicon lenses) and therefore reflections\n\\begin{equation}\n\t\\phi(l) = knl\n\\end{equation}\n- refractive index, length through medium of refractive index\n\n- describe the losses\n\n- extended hemispherical lens (shape of a bullet) puts antenna at focus, cause almost planar wavefronts and therefore high directivity\n\n- do the same for a parabolic reflector\n\n\\subsection{Combined}\n\n- include this?\n\n\\end{document}          \n", "meta": {"hexsha": "6f1d422b4e5f2292ecd1eff909701e7ffa510716", "size": 3835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/phased_arrays/phased_arrays.tex", "max_stars_repo_name": "DGX2000/electromagnetics-notes", "max_stars_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": "notes/phased_arrays/phased_arrays.tex", "max_issues_repo_name": "DGX2000/electromagnetics-notes", "max_issues_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": "notes/phased_arrays/phased_arrays.tex", "max_forks_repo_name": "DGX2000/electromagnetics-notes", "max_forks_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": 41.2365591398, "max_line_length": 527, "alphanum_fraction": 0.7739243807, "num_tokens": 925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.622883512887477}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{klauder}\n\\section*{\\hspace*{-1.6cm} klauder}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nKlauder wavelet in time domain.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nx = klauder(N)\nx = klauder(N,lambda)\nx = klauder(N,lambda,f0)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty klauder} generates the Klauder wavelet in the time domain\\,:\n        \\[K(f) = e^{-2\\pi\\lambda f} f^{2\\pi\\lambda f_0-1/2}.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty N }     & number of points in time   \\\\\n        {\\ty lambda} & attenuation factor or the envelope & {\\ty 10}\\\\\n        {\\ty f0}     & central frequency of the wavelet & {\\ty 0.2}\\\\\n\\hline  {\\ty x }     & time row vector containing the klauder samples\\\\\n\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         x=klauder(150,50,0.1); \n         plot(x);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\naltes, anasing, doppler, anafsk, anastep.\n\\end{verbatim}\n\\end{minipage}\n\n\n", "meta": {"hexsha": "035a93bf762706269eabe45187e9959e22b14d85", "size": 1552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/klauder.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/klauder.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/klauder.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 20.972972973, "max_line_length": 73, "alphanum_fraction": 0.6340206186, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6228835031180681}}
{"text": "\\chapter{Results}\n\\section{Problem 1: Simple network}\nIn order to be able to use our forward propagation function $x_j=f(x_{i}*w_{ij})$(from section 2.1), the given data (from section 1.1) were formulated as matrices resulting in the following data:\n\\begin{itemize}\n  \\item The input vector $x_0=\\left[ \\begin{array}{rr}\n\t\t\t\t\t\t\t\t\t\t\t0.7 & 0.5  \\\\ \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$\n  \\item The weight matrix $w_01=\\left[ \\begin{array}{rr}\n  \t\t\t\t\t\t\t\t\t\t\t1 & 0 \\\\\n\t\t\t\t\t\t\t\t\t\t\t0 & 1  \\\\ \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$\n\\item The weight matrix $w_12=\\left[ \\begin{array}{rrr}\n  \t\t\t\t\t\t\t\t\t\t\t0.9 & 0.3 & 0.9\\\\\n\t\t\t\t\t\t\t\t\t\t\t0.1 & 0.2 & 0.4\\\\\t\t\t\t \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$\n\t\t\t\t\t\t\t\t\t\\item The weight matrix $w_23=\\left[ \\begin{array}{rrr}\n  \t\t\t\t\t\t\t\t\t\t\t0.1 & 0.8 & 0.4\\\\\n\t\t\t\t\t\t\t\t\t\t\t0.5 & 0.1 & 0.6\\\\\n\t\t\t\t\t\t\t\t\t\t\t0.6 & 0.7 & 0.3\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$\n\\item The weight matrix $w_34=\\left[ \\begin{array}{rrr}\n  \t\t\t\t\t\t\t\t\t\t\t0.5 & 0.7 & 0.3\\\\\t\t\t\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$\n\\end{itemize}\n\nThus the final equation can be summarized as:\\\\\n$\\;\\;\\;\\;\\;f(\\,f\\,(\\,f(\\,f(x_0*w_01)*w_12)*w_23)*w_34$\\\\\\\\\nThe output of the neural network is $0.7451673339899871$.\n\\\\\\\\\nAlternatively the input vector $x_0=\\left[ \\begin{array}{rr}\n\t\t\t\t\t\t\t\t\t\t\t0.7 & 0.5  \\\\ \n\t\t\t\t\t\t\t\t\t\\end{array}\\right]$ was used, resulting in the value\\\\ $0.7453676512649436\n$.\n\n\n\\section{Problem 2: Backpropagation}\nUsing the given equations from section 1.2 the following gradients were calculated for a:\n\\begin{itemize}\n\\item  $\\partial sigmoid = sigmoid*(1-sigmoid)$\n\\item  $\\frac {\\partial cost}{\\partial prediction} = -1 $\n\\item  $\\frac {\\partial prediction}{\\partial y} = \\partial sigmoid(y)$ \n\\item  $\\frac {\\partial y}{\\partial w_1}=x_1$\n\\item  $\\frac {\\partial y}{\\partial w_2}=x_2$\n\\item  $\\frac {\\partial y}{\\partial b}=1$\n\\item  $\\frac {\\partial cost}{\\partial w_1}=\\frac {\\partial cost}{\\partial prediction}*\\frac {\\partial prediction}{\\partial y}*\\frac {\\partial y}{\\partial w_1}$\n\\item  $\\frac {\\partial cost}{\\partial w_2}=\\frac {\\partial cost}{\\partial prediction}*\\frac {\\partial prediction}{\\partial y}*\\frac {\\partial y}{\\partial w_2}$\n\\item  $\\frac {\\partial cost}{\\partial b}=\\frac {\\partial cost}{\\partial prediction}*\\frac {\\partial prediction}{\\partial y}*\\frac {\\partial y}{\\partial b}$\n\\end{itemize}\nThis results in the following weights (assuming a learning rate of $1$):\n\\begin{itemize}\n\\item $w1 = w1-\\frac {\\partial cost}{\\partial w_1} = 1.0088313531066455$\n\\item $w2 = w2 - \\frac {\\partial cost}{\\partial w_2}=1.0264940593199368$\\\\\n\\item $b = b - \\frac {\\partial cost}{\\partial b}=2.017662706213291$\n\\end{itemize}\nFor part b only the cost function(see section 1.2 b)is different with its derivative being:\n\\begin{itemize}\n\\item $\\frac {\\partial cost}{\\partial prediction} = -(z'-z)$\n\\item \n\\end{itemize}\nAnd giving the following weight values:\nThis results in the following weights (assuming a learning rate of $1$):\n\\begin{itemize}\n\\item $w1 = w1-\\frac {\\partial cost}{\\partial w_1} = 1.0001588425712256$\n\\item $w2 = w2 - \\frac {\\partial cost}{\\partial w_2}=1.0004765277136765$\\\\\n\\item $b = b - \\frac {\\partial cost}{\\partial b}=2.000317685142451$\n\\end{itemize}\n\\section{Problem 3: Artificial neural network}\nFor Problem three we defined a neural network with only one hidden layer, consisting of 11 neurons. It was trained for 10 thousand epochs with the following parameters:\n\\begin{itemize}\n\\item $batchsize = 8000$\n\\item $learning rate = 1$\n\\end{itemize}\nThe training curve gives the following results:\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[height=12cm]{img/problem3_curves.png}\n\t\\caption{Training curves for problem 3}\n    \\label{problem4_imput_data}\n\\end{figure}\nUnfortunately the testing did not work from scratch and we were not able to fix the Issue: ('CUDA error: an illegal memory access was encountered',)\n\n\\section{Problem 4: Gradient Descent}\n\nUsing the given python code and applying the gradient and weight calculation described in Section~\\ref{ch:methods:sec:4} results in the line shown in Figure~\\ref{problem4_result}.\n\nThe original line is has a $m$ of $3.30$ and a $c$ of $5.3$ and the learned values are $3.28$ for $m$ and $5.27$ for $c$.\n\n\\begin{figure}[h]\n\t\\centering\n    \\includegraphics[width=17cm]{img/problem4_result_160.png}\n\t\\caption{Result of gradient decent after 160 iterations}\n    \\label{problem4_result_160}\n\\end{figure}\n\n\\begin{figure}[h]\n\t\\centering\n    \\includegraphics[width=17cm]{img/problem4_result.png}\n\t\\caption{Result of gradient decent}\n    \\label{problem4_result}\n\\end{figure}\n\nThe loss is also plotted in figure~\\ref{problem4_result_loss}.\n\n\\begin{figure}[h]\n\t\\centering\n    \\includegraphics[width=17cm]{img/problem4_result_loss.png}\n    \\caption{Loss of the gradient decent over the iterations}\n    \\label{problem4_result_loss}\n\\end{figure}\n", "meta": {"hexsha": "fc346d33113f1cb0bafa90d14f24bb3fb5f4a6f0", "size": 4801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_4/content/06_results.tex", "max_stars_repo_name": "worldpotato/Advanced_Remote_Sensing_Methods", "max_stars_repo_head_hexsha": "6f40cf72b2f911b84e0a1f62c229ffe0dde8e060", "max_stars_repo_licenses": ["MIT"], "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/content/06_results.tex", "max_issues_repo_name": "worldpotato/Advanced_Remote_Sensing_Methods", "max_issues_repo_head_hexsha": "6f40cf72b2f911b84e0a1f62c229ffe0dde8e060", "max_issues_repo_licenses": ["MIT"], "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/content/06_results.tex", "max_forks_repo_name": "worldpotato/Advanced_Remote_Sensing_Methods", "max_forks_repo_head_hexsha": "6f40cf72b2f911b84e0a1f62c229ffe0dde8e060", "max_forks_repo_licenses": ["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.2522522523, "max_line_length": 195, "alphanum_fraction": 0.6777754634, "num_tokens": 1534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6228834991813553}}
{"text": "\\chapter{Kernel FDA with Multi-layer Kernels}\n\\label{chap_kfda}\nIn this chapter we study the discriminating power of multi-layer kernels with kernel Fisher Discriminant Analysis(KFDA\\nomenclature{KFDA}{Kernel Fisher Discriminant Analysis}). The analysis in this section was done on binary classification problems. This chapter is organized as follows: section \\ref{chap4_kfda} gives a brief introduction of kernel Fisher discriminant Analysis, section \\ref{chap4_experiment} contains the results of empirical study on \\textit{rectangles-image} and \\textit{convex} datasets(both are binary classification problems studied extensively in deep learning literatures), and section \\ref{chap4_conc} gives the conclusion.  \n\n\\section{Kernel Fisher Discriminant Analysis}\n\\label{chap4_kfda}\nThe working principle of discriminant analysis is to find a set of features that discriminates the classes very well(\\cite{kfda} et al.). Fisher Discriminant Analysis(FDA) was originally proposed for learning a set of discriminating features in the input space. Kernel FDA is a non-linear generalization of FDA, in which the discriminating features are learned in feature space.\n\nLet $X_1 = \\{x_1^1, \\ldots, x_{n_1}^1 \\}$ and $X_2 = \\{x_1^2, \\ldots, x_{n_1}^2 \\}$ be data samples from two classes (class 1 and class 2) and the union of two, denoted as $X = X_1 \\cup X_2$ as the training set.  KFDA find the directions $f$ which maximizes the cost function\n\n\\begin{equation}\n\\mathcal{J}(f) = \\frac{f^TS_B^{\\phi}f}{f^TS_W^{\\phi}f} \n\\label{4_jw}\n\\end{equation}\n\nwhere $f \\in \\mathcal{F}$ and $S_B^{\\phi}$ and $S_W^{\\phi}$ are the between and within class scatter matrices respectively\n\\[ S_B^{\\phi} = (m_1^{\\phi} - m_2^{\\phi})(m_1^{\\phi} - m_2^{\\phi})^T \\]\n\\[ S_W^{\\phi} = \\sum_{i=1,2}\\sum_{x \\in X_i} (\\phi(x)-m_i^{\\phi})(\\phi(x)-m_i^{\\phi})^T  \\]\nwhere $m_i^{\\phi} = \\frac{1}{n_i} \\sum_{j=1}^{n_i} \\phi(x_j^i)$. Intuitively maximizing $\\mathcal{J}(f)$ is equivalent to finding a direction $w$ which maximizes the separation of the two classes while minimizing the within class variance(\\cite{kfda} et al.). We need to transform the formulation in \\ref{4_jw} in terms of kernel function $k(x, y) = \\phi(x) \\cdot \\phi(y)$ in order to use kernels. According to RKHS\\nomenclature{RKHS}{Reproducing Kernel Hilbert Space} theory, any solution to the Tikhnov regularization $f \\in \\mathcal{F}$ must lie in the span of the feature map($\\phi(\\cdot)$) corresponding to training examples. Thus it can be represented as\n\\begin{equation}\nf = \\sum_{i=1}^n \\alpha_i \\phi(x_i)\n\\label{4_wrkhs}\n\\end{equation}\ncombining \\ref{4_wrkhs} and the definition of $m_i^{\\phi}$ we have\n\\[ f^Tm_i^{\\phi} = \\frac{1}{n_i} \\sum_{j=1}^n \\sum_{k=1}^{n_i} \\alpha_j k(x_j, x_k^i) = \\alpha^T M_i \\]\nwhere $(M_i)_j = \\frac{1}{n_i} \\sum_{k=1}^{n_i}  k(x_j, x_k^i)$. Define $M = (M_1-M_2)(M_1-M_2)^T$. The we have\n\\begin{equation}\nf^T S_B^{\\phi} f = \\alpha^T M \\alpha\n\\label{4_wsbw}\n\\end{equation}\nusing similar transformations we have\n\\begin{equation}\nf^T S_W^{\\phi} f = \\alpha^T N \\alpha\n\\label{4_wsww}\n\\end{equation}\nwhere $N = \\sum_{i=1,2} K_i(I - \\bm{1}_{n_i})K_i^T $, $K_i$ is an $n \\times n_i$ matrix with entries $(K_i)_{nm} = k(x_n, x_m^i)$(this is the kernel matrix for class $i$), $I$ is the identity matrix and $\\bm{1}_{n_i}$ is the matrix with with all entries $\\frac{1}{n_i}$. The derivation of this compact forms $M$ and $N$ are shown in Appendix \\ref{derivation2}.\n\nCombining (\\ref{4_wsbw}) and (\\ref{4_wsww}) we will get an objective function in terms of $\\alpha$.\n\\[ \\mathcal{J}(\\alpha) = \\frac{\\alpha^T M \\alpha}{\\alpha^T N \\alpha}  \\]\nThis problem can be solved by finding the leading eigen vectors of $N^{-1}M$. The projection of a new pattern $x$ onto $f$ is given by\n\\[ f \\cdot \\phi(x) = \\sum_{i=1}^n \\alpha_i k(x_i, x) \\]\nThe estimation of $N \\in \\mathbb{R}^{n \\times n}$ from a sample of size $n$ poses an ill-posed problem(since the sample size is not high enough to get an exact covariance structure in $\\mathbb{R}^{n \\times n}$). This problem is solved by replacing $N$ with $N_{\\mu}$ as\n\\[ N_{\\mu} = N + \\mu I \\]\nwhere $\\mu$ is a large positive constant and $I$ is the identity matrix. This has two possible benefits\n\\begin{itemize}\n\\item It makes the problem numerically more stable as for large $\\mu$, $N_{\\mu}$ will become positive definite.\n\\item It decreases the bias in sample based estimation of eigenvalues.\n\\end{itemize}\n\n\n\\section{Experiments}\n\\label{chap4_experiment}\nEmpirical study was conducted on two binary classification datasets namely \\textit{rectangles-image} dataset and \\textit{convex} dataset. A short description about \\textit{rectangles-image} dataset is given in \\autoref{chap_mkm}.\n\\subsection{Convex Dataset}\nThe \\textit{convex} dataset consists of a single convex region in an image. The dataset was constructed by taking the intersection of a number of half-planes whose location and orientation were chosen uniformly at random. The classification task was to identify whether the shape enclosed in the image is convex or not. This dataset consists of 12000 training and 50000 testing samples of size 28$\\times$28.\n\nFigure \\ref{shape} shows some sample images from \\textit{rectangles-image} and \\textit{convex} datasets. In the experiments, KFDA with multi-layer arc-cosine kernels were used for feature extraction and kNN classifier was used for the classification. Table \\ref{kfda_results} shows the results of the empirical study.\n\n\\begin{figure*}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.6]{figures/shapes}\n  \\caption{Sample images from \\textit{rectangles-image}(first row) and \\textit{convex}(second row) datasets.}\n  \\label{shape}\n\\end{figure*}\n\n\\renewcommand{\\arraystretch}{2.3}\n\\begin{table*}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Dataset}} & \\multicolumn{7}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-8}\n  &$\\textrm{SVM}_{\\textrm{RBF}}$ & $\\textrm{SVM}_{\\textrm{Poly}}$ & NNet & DBN-3 & SAA-3 & DBN-1 & \\textbf{KFDA}\\\\\n  \\hline  \n  \\textit{rect-image} & 24.04 & 24.05 & 33.20 & 23.69 & 24.05 & 22.50 & \\textbf{21.96}\\\\\n  \\hline\n  \\textit{convex} & 19.13 & 19.82 & 32.25 & 19.92 & \\textbf{18.41} & 18.63 & 19.02\\\\\n  \\hline\n\\end{tabular}\n\\caption{Experimental Results of KFDA with multi-layer kernels.}\n\\label{kfda_results}\n\\end{table*}\n\\renewcommand{\\arraystretch}{1}\n\n\\renewcommand{\\arraystretch}{2}\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|}\n  \\hline\n  \\textbf{Kernel Parameters} &  \\textbf{Loss in Percentage}\\\\\n  \\hline\n  0 & 23.12\\\\\n  \\hline\n  0,3 & 22.54\\\\\n  \\hline\n  0,3,3 & 22.39\\\\\n  \\hline\n  0,3,3,3 & 22.15\\\\\n  \\hline\n  0,3,3,3,3 & 21.96\\\\\n  \\hline\n  0,3,3,3,3,3 & 22.01\\\\\n  \\hline  \n\\end{tabular}\n\\caption{Change in classifier performance while increasing number of layers for \\textit{rectangles-image} dataset}\n\\label{chap4_tab1}\n\\end{table}\n\\renewcommand{\\arraystretch}{1}\n\n\\renewcommand{\\arraystretch}{2}\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|}\n  \\hline\n  \\textbf{Kernel Parameters} &  \\textbf{Loss in Percentage}\\\\\n  \\hline\n  1 & 21.94\\\\\n  \\hline\n  1 $\\times$ 3 & 21.68\\\\\n  \\hline\n  1 $\\times$ 6 & 21.46\\\\\n  \\hline\n  1 $\\times$ 9 & 19.78\\\\\n  \\hline\n  1 $\\times$ 12 & 19.52\\\\\n  \\hline\n  1 $\\times$ 15 & 19.38\\\\\n  \\hline\n  1 $\\times$ 18 & 19.30\\\\\n  \\hline\n  1 $\\times$ 21 & 19.02\\\\\n  \\hline      \n\\end{tabular}\n\\caption{Change in classifier performance while increasing number of layers for \\textit{convex} dataset}\n\\label{chap4_tab2}\n\\end{table}\n\\renewcommand{\\arraystretch}{1}\n\nFor \\textit{rectangles-image} dataset, the best result was obtained for a five layer KFDA with kernel degree values in each layer was given by [0,3,3,3,3]. For \\textit{convex} dataset the best result was obtained from a model having 20 layers with degree parameter equal to 1 in each layer. The variations in classifier performance as the number of layers were increased is shown in tables \\ref{chap4_tab1} and \\ref{chap4_tab2} for \\textit{rectangles-image} and \\textit{convex} datasets respectively. In table \\ref{chap4_tab2}, 1 $\\times$ $n$ indicates that an arc-cosine kernel of $n$ layers is used with kernel parameter is equal to `1' in each layer.\n\n\n\\section{Conclusion}\n\\label{chap4_conc}\nIn this chapter we experimented on KFDA with multi-layer arc-cosine kernels. The result obtained are very promising. On \\textit{rectangles-image} dataset, the classifier performed even better than a DBN based model. On \\textit{convex} dataset, its performance was better than all shallow models \nand was comparable with that of deep models. One of the striking observation from these results is that, better performance is obtained when using either a highly non-linear arc-cosine kernel(degree $>$ 1) or a multi-layer arc-cosine kernel with very large number of layers (above 10).\n", "meta": {"hexsha": "199dd3fe38b750d311aa626bce52badd8def2269", "size": 8797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter4.tex", "max_stars_repo_name": "akhilpm/Masters-Project", "max_stars_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_stars_repo_licenses": ["MIT"], "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/chapter4.tex", "max_issues_repo_name": "akhilpm/Masters-Project", "max_issues_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_issues_repo_licenses": ["MIT"], "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/chapter4.tex", "max_forks_repo_name": "akhilpm/Masters-Project", "max_forks_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_forks_repo_licenses": ["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.843537415, "max_line_length": 660, "alphanum_fraction": 0.7228600659, "num_tokens": 2877, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6228834914044268}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n\\begin{document}\n\\chapter{Fields and Other Prerequisites}\t\n\\section{Fields}\n\\begin{defn}[Fields]\n\t\nLet $F$ be a field. Then we define $F^{n} = \\left\\{ (x_1, \\ldots,x_n) \\mid x_i \\in F, i=1,\\ldots,n \\right\\}$ and the following properties are true:\n\\begin{itemize}\n\t\\item elements of $F^{n}$ can be added: if $x = (x_1,\\ldots,x_n)$ and $y = (y_1,\\ldots,y_n)$\n\t\\item Has a neutral element: $(0,\\ldots,0) =: \\overline{0}$\n\t\\item Has an additive inverses: $-x = (-x_1,\\ldots,-x_n)$ where $x + (-x) = \\overline{0}$.\n\t\\item Elements of $F^{n}$ can be \"scaled\" by elements of $F$: Let $\\lambda \\in F, x = (x_1,\\ldots,x_n)\\in F^{n}$. Then we define $\\lambda \\cdot x$ as $(\\lambda \\cdot x_1, \\ldots, \\lambda \\cdot x_n)$. \n\\end{itemize}\n\\end{defn}\nWarning: $F^{n}$ is NOT a field, unless $n=1$ (because we cannot well-define a multiplying property).\n\n\\section{Proofs by Induction}\n\n\\begin{thm}[Principle of Mathematical Induction II]\n\tLet $P(n)$ be a statement indexed by $n \\in N$. Suppose that\n\t\\begin{enumerate}\n\t\t\\item $P(1)$ is true. (The \\textit{base case})\n\t\t\\item If $P(k)$ is true for some $k \\in \\N$, then $P(k+1)$ is true. (The \\textit{inductive hypothesis})\n\t\\end{enumerate}\n\tThen $P(n)$ is true for all $n \\in N$.\n\\end{thm}\n\\begin{thm}[Principle of Mathematical Induction III]\n\tLet $Q(n)$ be a statement indexed by $n \\in N$. Suppose that\n\t\\begin{enumerate}\n\t\t\\item $Q(k_0)$ is true for some $k_0 \\in \\N$. (The \\textit{base case})\n\t\t\\item If $Q(k)$ is true for some $k \\in \\N$, then $Q(k+1)$ is true. (The \\textit{inductive hypothesis})\n\t\\end{enumerate}\n\tThen $Q(n)$ is true for all $n \\geq k_0$.\n\n\n\\end{thm}\n\n\\end{document}\n", "meta": {"hexsha": "795a261daea61ab9cfc171c752ce683c6ce8df20", "size": 1671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/08-29-19-Prelim.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/08-29-19-Prelim.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/08-29-19-Prelim.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": 40.756097561, "max_line_length": 201, "alphanum_fraction": 0.6552962298, "num_tokens": 620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6228329227486873}}
{"text": "\\section{Scipy} % (fold)\n\\label{sec:scipy}\n\\begin{questions}\n\\titledquestion{Least squares} % (fold)\n\\label{sub:least_squares}\n\nGenerate matrix $A \\in R^{m \\times n}$ with $m > n$.\nAlso generate some vector $b \\in R^m$.\n\nNow find $x = \\arg\\min_x \\|Ax-b\\|_2$.\n\nPrint the norm of the residual.\n\n% titledquestion least_squares (end)\n\n\\titledquestion{Optimization} % (fold)\n\\label{sub:optimization}\n\nFind the maximum of the function\n\\[\n    f(x) = \\sin^2(x-2)e^{-x^2}\n\\]\n\n% titledquestion optimization (end)\n\n\n\\titledquestion{Pairwise distances} % (fold)\n\\label{sub:pairwise_dists}\n\nLet $X$ be a matrix with $n$ rows and $m$ columns.\nHow can you compute the pairwise distances between every two rows?\n\nAs an example application, consider $n$ cities, and we are given their coordinates\nin two columns.\nNow we want a nice table that tells us for each two cities, how far they\nare apart.\n\nAgain, make sure you make use of Scipy's functionality instead of writing your own routine.\n\n% titledquestion pairwise_dists (end)\n\n\\end{questions}\n\n% section scipy (end)\n", "meta": {"hexsha": "8553a1f803e843fdda5d348ec94040b37f14f4a5", "size": 1052, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/tex/scipy.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/scipy.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/scipy.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": 23.3777777778, "max_line_length": 91, "alphanum_fraction": 0.7262357414, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7853085884247212, "lm_q1q2_score": 0.6228329149956408}}
{"text": "\\documentclass[]{article}\n\n\\usepackage{graphicx}\n\n\\usepackage[margin=1in]{geometry}\n\n\\setlength\\parindent{0pt}\n\n\\usepackage{physics}\n\\usepackage{amsmath, amsfonts, amssymb, amsthm}\n\n\\usepackage{listings}\n\n\\usepackage{enumitem}\n\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\renewcommand*{\\thesection}{Problem \\arabic{section}}\n\\renewcommand*{\\thesubsection}{\\alph{subsection})}\n\\renewcommand*{\\thesubsubsection}{\\quad \\quad \\roman{subsubsection})}\n\n%Custom Commands\n\\newcommand{\\Rel}{\\mathcal{R}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\C}{\\mathbb{C}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\n\\newcommand{\\toI}{\\xrightarrow{\\textsf{\\tiny I}}}\n\\newcommand{\\toS}{\\xrightarrow{\\textsf{\\tiny S}}}\n\\newcommand{\\toB}{\\xrightarrow{\\textsf{\\tiny B}}}\n\n\\newcommand{\\divisible}{ \\ \\vdots \\ }\n\n\n% Theorem Definition\n\\newtheorem{definition}{Definition}\n\\newtheorem{assumption}{Assumption}\n\\newtheorem{theorem}{Theorem}\n\n\n%opening\n\n\\title{MATH 5301 Elementary Analysis - Homework 4}\n\n\\author{Jonas Wagner}\n\n\\date{2021, September 24}\n\n\\begin{document}\n\n\\maketitle\n\n% Problem 1\n\\section{}\nLet $(S_1,d_1)$ and $(S_2,d_2)$ be two metric spaces. \nShow that each of the following determines the metric on $S_1 \\cross S_2$.\\\\\nLet $x_j \\in S_1, y_j \\in S_2$:\n% Part a\n\\subsection{$d((x_1,y_1),(x_2,y_2)) = \\max\\qty{d_1(x_1,x_2),d_2(y_1,y_2)}$}\n\n\\begin{theorem}\n    The metric $$d((x_1,y_1),(x_2,y_2)) = \\max\\qty{d_1(x_1,x_2),d_2(y_1,y_2)}$$ \n    is a metric on $S_1 \\cross S_2$.\n\\end{theorem}\n\\begin{proof}\n    A metric $d: S_1 \\cross S_2 \\to \\R$ must satisfy (i) non-negativity, \n    (ii) Symmetry, and (iii) Triangle Inequality.\n    \\subsubsection{Non-negativy $$d((x_1,y_1), (x_2,y_2)) \\geq 0$$}\n        Since $d_1(x_1,x_2) \\geq 0$ and $d_2(y_1,y_2) \\geq 0$,\n        $$d((x_1,y_1), (x_2,y_2)) = \\max\\qty{d_1(x_1,x_2),d_2(y_1,y_2)} \\geq 0$$\n    \\subsubsection{Symmetry $$d((x_1,y_1),(x_2,y_2))=d((x_1,y_1),(x_2,y_2))$$}\n    \\begin{align*}\n        d((x_1,y_1), (x_2,y_2)) = \\max\\qty{d_1(x_1,x_2),d_2(y_1,y_2)} \n        &= \\max\\qty{d_2(y_1,y_2),d_1(x_1,x_2)} = d((x_2,y_2),(x_1,x_2)\n    \\end{align*}\n    \\subsubsection{Triangle Inequality \n    $$d((x_1,y_1),(x_3,y_3)) \\leq d((x_1,y_1),(x_2,y_2)) + d((x_2,y_2),(x_3,y_3))$$\n    }\n    \\begin{align*}\n        d((x_1,y_1),(x_3,y_3)) &= \\max\\qty{d_1(x_1,x_3), d_2(y_1,y_3)}\\\\\n        d((x_1,y_1),(x_2,y_2)) &= \\max\\qty{d_1(x_1,x_2), d_2(y_1,y_2)}\\\\\n        d((x_2,y_2),(x_3,y_3)) &= \\max\\qty{d_1(x_2,x_3), d_2(y_2,y_3)}\\\\\n        \\max\\qty{d_1(x_1,x_3), d_2(y_1,y_3)} \n            &\\leq \\max\\qty{d_1(x_1,x_2), d_2(y_1,y_2)}\n            + \\max\\qty{d_1(x_2,x_3), d_2(y_2,y_3)}\\\\\n        d((x_1,y_1),(x_3,y_3)) &\\leq d((x_1,y_1),(x_2,y_2)) + d((x_2,y_2),(x_3,y_3))\n    \\end{align*}\n\\end{proof}\n\n\\newpage\n% Part b\n\\subsection{$d((x_1,y_1),(x_2,y_2)) = d_1(x_1,x_2)  + d_2(y_1,y_2)$}\n\n\\begin{theorem}\n    The metric $$d((x_1,y_1),(x_2,y_2)) = d_1(x_1,x_2)  + d_2(y_1,y_2)$$\n    is a metric on $S_1 \\cross S_2$.\n\\end{theorem}\n\\begin{proof}\n    A metric $d: S_1 \\cross S_2 \\to \\R$ must satisfy (i) non-negativity, \n    (ii) Symmetry, and (iii) Triangle Inequality.\n    \\subsubsection{Non-negativy $$d((x_1,y_1), (x_2,y_2)) \\geq 0$$}\n        Since $d_1(x_1,x_2) \\geq 0$ and $d_2(y_1,y_2) \\geq 0$,\n        $$d((x_1,y_1), (x_2,y_2)) = d_1(x_1,x_2)  + d_2(y_1,y_2) \\geq 0$$\n    \\subsubsection{Symmetry $$d((x_1,y_1),(x_2,y_2))=d((x_1,y_1),(x_2,y_2))$$}\n    \\begin{align*}\n        d((x_1,y_1), (x_2,y_2)) = d_1(x_1,x_2)  + d_2(y_1,y_2) \n        &= d_1(x_2,x_1)  + d_2(y_2,y_1) = d((x_2,y_2),(x_1,x_2)\n    \\end{align*}\n    \\subsubsection{Triangle Inequality \n    $$d((x_1,y_1),(x_3,y_3)) \\leq d((x_1,y_1),(x_2,y_2)) + d((x_2,y_2),(x_3,y_3))$$\n    }\n    \\begin{align*}\n        d((x_1,y_1),(x_3,y_3)) &= d_1(x_1,x_3)  + d_2(y_1,y_3)\\\\\n        d((x_1,y_1),(x_2,y_2)) &= d_1(x_1,x_2)  + d_2(y_1,y_2)\\\\\n        d((x_2,y_2),(x_3,y_3)) &= d_1(x_2,x_3)  + d_2(y_2,y_3)\\\\\n        d_1(x_1,x_3)  + d_2(y_1,y_3)\n            &\\leq d_1(x_1,x_2)  + d_2(y_1,y_2)\n            + d_1(x_2,x_3)  + d_2(y_2,y_3)\\\\\n        d((x_1,y_1),(x_3,y_3)) &\\leq d((x_1,y_1),(x_2,y_2)) + d((x_2,y_2),(x_3,y_3))\n    \\end{align*}\n\\end{proof}\n\n\\newpage\n% Part c\n\\subsection{$d((x_1,y_1),(x_2,y_2)) = \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2}$}\n\n\\begin{theorem}\n    The metric $$d((x_1,y_1),(x_2,y_2)) = \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2}$$\n    is a metric on $S_1 \\cross S_2$.\n\\end{theorem}\n\\begin{proof}\n    A metric $d: S_1 \\cross S_2 \\to \\R$ must satisfy (i) non-negativity, \n    (ii) Symmetry, and (iii) Triangle Inequality.\n    \\subsubsection{Non-negativy $$d((x_1,y_1), (x_2,y_2)) \\geq 0$$}\n        Since $d_1(x_1,x_2) \\geq 0$ and $d_2(y_1,y_2) \\geq 0$,\n        $$d((x_1,y_1), (x_2,y_2)) = \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2} \\geq 0$$\n    \\subsubsection{Symmetry $$d((x_1,y_1),(x_2,y_2))=d((x_1,y_1),(x_2,y_2))$$}\n    \\begin{align*}\n        d((x_1,y_1), (x_2,y_2)) = \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2}\n        &= \\sqrt{(d_1(x_2,x_1))^2+(d_2(y_2,y_1))^2} = d((x_2,y_2),(x_1,x_2)\n    \\end{align*}\n    \\subsubsection{Triangle Inequality \n    $$d((x_1,y_1),(x_3,y_3)) \\leq \\sqrt{(d_1(x_1,x_3))^2+(d_2(y_1,y_3))^2}$$\n    }\n    \\begin{align*}\n        d((x_1,y_1),(x_3,y_3)) &= \\sqrt{(d_1(x_1,x_3))^2+(d_2(y_1,y_3))^2}\\\\\n        d((x_1,y_1),(x_2,y_2)) &= \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2}\\\\\n        d((x_2,y_2),(x_3,y_3)) &= \\sqrt{(d_1(x_2,x_3))^2+(d_2(y_2,y_3))^2}\\\\\n        \\sqrt{(d_1(x_1,x_3))^2+(d_2(y_1,y_3))^2}\n            &\\leq \\sqrt{(d_1(x_1,x_2))^2+(d_2(y_1,y_2))^2}\n            + \\sqrt{(d_1(x_2,x_3))^2+(d_2(y_2,y_3))^2}\\\\\n        d((x_1,y_1),(x_3,y_3)) &\\leq d((x_1,y_1),(x_2,y_2)) + d((x_2,y_2),(x_3,y_3))\n    \\end{align*}\n\\end{proof}\n\n\n\\newpage\n% Problem 2\n\\section{}\n% Part a\n\\subsection{A set $A$ in the metric space $(S, d)$ is called bounded, if\n    $\\exists_{R>0} \\land \\exists x \\in S : A \\subset B_R(x)$.\n    Prove that if $A$ is unbounded then there exists a sequence \n    $\\{x_n\\} \\subset A$ such that $\\forall_{m,n\\in\\N} \\implies d(x_n,x_m) > 1$.\n}\n\\begin{assumption}\n    $m \\neq n$, $m > n$\n\\end{assumption}\n\\begin{definition}\n    The open ball set $B_r(x)$ over metric space $(S,d)$ is defined as\n    $$B_r(x) := \\qty{y \\in S : d(x,y) < r}$$\n\\end{definition}\n\\begin{definition}\n    A set $A$ in the metric space $(S, d)$ is called \\underline{bounded}, if\n    $$\\exists_{R>0} \\land \\exists_{x \\in S} : A \\subset B_R(x)$$\n\\end{definition}\n\\begin{definition}\n    A set $A$ in the metric space $(S, d)$ is called \\underline{unbounded}, \n    if it is not bounded, (i.e.)\n    $$\\forall_{R>0} \\land \\forall_{x \\in S} : A \\not \\subset  B_R(x)$$\n\\end{definition}\n\\begin{theorem}\n    If $A \\in (S,d)$ is unbounded, then \n    $$\\exists \\{x_n\\} \\subset A : \\forall_{m,n\\in\\N} \\implies d(x_n,x_m) > 1$$\n\\end{theorem}\n\\begin{proof}\n    $A \\in (S,d)$ being unbounded means that \n    $$\\forall_{R>0} \\land \\forall x \\in S : A \\not\\subset  B_R(x)$$\n    Since $\\forall_{R>0} \\land \\forall_{x \\in S} : A \\not \\subset  B_R(x)$ \n    and $B_R(x) := \\qty{y \\in S : d(x,y) < R}$, \n    $$\\forall_{x \\in A} \\exists_{y \\in A} : d(x,y) \\geq R$$\n    Since it is true for any $R > 0$ a sequence $\\{x_n\\}$ can be constructed \n    with subsequent $x_{n+1}$ so that $d(x_n,x_{n+1})>R=1$.\n\\end{proof}\n\n% \\newpage\n% Part b\n\\subsection{Show that in the normed space $(V,\\abs{\\cdot})$ the open unit ball \n    $B_r = \\qty{x \\in V : \\abs{x} < 1}$ is a convex set. (i.e)\n    $\\forall_{x,y\\in B_r}, \\forall_{t\\in \\qty[0,1]} \\implies t x + (1-t) y \\in B_r$\n}\n\\begin{definition}\n    The \\underline{open unit ball} is defined as: \n    $$B_r := \\qty{x \\in V : \\abs{x} < 1}$$\n\\end{definition}\n\\begin{definition}\n    The set $A$ is convex if and only if \n    $$\\forall_{x,y\\in A}, \\forall_{t\\in \\qty[0,1]} \\implies t x + (1-t) y \\in A$$\n\\end{definition}\n\\begin{theorem}\n    The open unit ball set $B_r$ is convex in $(V,\\abs{\\cdot})$.\n\\end{theorem}\n\\begin{proof}\n    \\begin{align*}\n        \\forall_{x,y\\in B_r}, \\forall_{t\\in \\qty[0,1]}\n            &\\implies t x + (1-t) y \\in B_r\\\\\n        \\forall_{x,y\\in V} : (\\abs{x} < 1) \\land (\\abs{y} < 1), \\forall_{t\\in \\qty[0,1]}\n            &\\implies t x + (1-t) y \\in V : \\abs{t x + (1-t) y}\n        \\intertext{Since\n        $\\forall_{x,y \\in V}, \\forall_{t \\in \\qty[0,1]} \\implies t x + (1-t) y \\in V$\n        }\n        \\qty(\\abs{x} < 1 \\land \\abs{y} < 1 \\implies \\abs{t x + (1-t) y} < 1)\n            &\\iff t x + (1-t) y \\in B_r\n    \\end{align*}\n    Clearly,\n    $$\\forall_{x,y\\in V} \\abs{x},\\abs{y}<1, \\forall_{t\\in[0,1]} t x + (1-t) y < 1$$\n    Therefore, the open unit ball set $B_r$ is convex in $(V,\\abs{\\cdot})$.\n\\end{proof}\n\n\\newpage\n% Problem 3\n\\section{}\nFor $(\\R^2 = (x,y),d=\\sqrt{x^2 + y^2})$,\n% Part a\n\\subsection{Show that $D = \\qty{(x,y) : x^2 + y^2 \\leq 1}$ is a closed set.}\n\\begin{definition}\n    The set $A \\subset V$ is called \\underline{open} if \n    $$\\forall_{x\\in A} \\exists_{\\epsilon>0} : B_\\epsilon(x)\\subset A$$\n\\end{definition}\n\\begin{definition}\n    The set $A \\subset V$ is called \\underline{closed} if $A^c$ is open.\n\\end{definition}\n\\begin{theorem}\n    The set $D = \\qty{(x,y) : x^2 + y^2 \\leq 1}$ is closed.\n\\end{theorem}\n\\begin{proof}\n    By definition, $D$ is closed iff $D^c$ is open.\\\\\n    $D^c$ is defined by\n    $$D^c = \\qty{(x,y) : x^2 + y^2 > 1}$$\n    By definition, $D^c$ is open if\n    $$\\forall_{(x,y) \\in D^c} \\exists_{\\epsilon>0}: B_\\epsilon ((x,y)) \\subset D^c$$\n    This means that every element in $D^c$ must have an associated open ball set centered \n    at that element with a positive radius that is fully contained by $D^c$.\\\\\n    Let $(x_b,y_b) \\in B_\\epsilon ((x,y))$ for $\\epsilon>0$.\n    This means\n    $$d((x,y),(x_b,y_b)) = \\sqrt{x_b^2 + y_b^2} < \\epsilon$$\n    By definition,\n    $$(x,y) \\in D^c \\implies x^2 + y^2 > 1$$\n    and therefore,\n    $$\\sqrt{x^2 + y^2} = d((0,0),(x,y)) > 1$$\n\n    From the triangle inequality, we have\n    \\begin{align*}\n        d((x_b,y_b),(0,0)) &\\leq d((0,0),(x,y)) + d((x,y),(x_b,y_b))\\\\\n        d((x,y),(x_b,y_b)) &\\geq d((x_b,y_b),(0,0)) - d((0,0),(x,y))\\\\\n        d((x,y),(x_b,y_b)) = \\epsilon &> d((x_b,y_b),(0,0)) - 1 > 0\n    \\end{align*}\n    Therefore $D^c$ is open and therefore $D$ is closed.\n\\end{proof}\n\n\\newpage\n% Part b\n\\subsection{Find the infinite collection of open sets \n$\\{A_n\\}$ so that}% $\\bigcap_{n} A_n = \\overline{B_1(0)}$} \n\n$$\\qty{A_n : \\bigcap_n A_n = \\overline{B_1(0)}}$$\nThis means that the intersection of all sets in $\\{A_n\\}$ \nis the closure of the unit ball set.\n\n\\begin{definition}\n    The \\underline{interier} of set $A$ in $(S,d)$ is the union of all open sets \n    contained within $A$. (i.e.)\n    $$\\text{int}(A) = \\qty{x \\in A : \\exists_{\\epsilon>0} B_\\epsilon(x) \\subset A}$$\n\\end{definition}\n\n\\begin{definition}\n    The \\underline{closure} of set $A$ in $(S,d)$ is the intersection of all closed sets \n    containing $A$, (i.e) \n    $$\\overline{A} = \\qty{x \\in S : \n        \\forall_{\\epsilon> 0} B_\\epsilon(x) \\cap A \\neq \\emptyset}$$\n\\end{definition}\nNote: \nThe interior and closures are complementary sets. (i.e.) $\\overline{A} = (\\text{int}(A))^c$\n\n\n$B_1(0)$ is defined as \n$$B_1(0) := \\qty{(x,y) \\in \\R^2 : d((0,0),(x,y)) < 1} = \\qty{(x,y) : \\sqrt{x^2 + y^2} < 1}$$\n\nThe closure of $B_1(0)$, $\\overline{B_1(0)}$ is defined by\n\\begin{align*}\n    \\overline{B_1(0)} &:= \\qty{(x,y) \\in \\R^2 : \n        \\forall_{\\epsilon > 0} B_\\epsilon((x,y)) \\cap B_1(0) \\neq \\emptyset}\\\\\n    &= \\qty{(x,y) \\in \\R^2 : \\forall_{\\epsilon> 0} \n        \\exists_{(x_b,y_b) \\in \\R^2} (d((x,y),(x_b,y_b)) < \\epsilon) \\land (d((0,0),(x,y)) < 1)}\n\\end{align*}\n\nTherefore,\n\\begin{align*}\n    {A_n} &:= \\qty{A_n \\subset \\R^2: \\forall_{(x,y) \\in \\R^2} \\forall_{\\epsilon> 0} \n        B_\\epsilon((x,y)) \\cap B_1(0) \\neq \\emptyset \\implies (x,y) \\in A}\\\\\n    &= \\qty{A \\subset \\R^2: \\qty(\\forall_{(x,y) \\in \\R^2} \n        \\exists_{(x_b,y_b) \\in \\R^2} d((x,y),(x_b,y_b)) < \\epsilon \\implies d((0,0),(x,y)) < 1)}\\\\\n    &= \\qty{A \\subset \\R^2: \\qty(\\forall_{(x,y) \\in \\R^2} \n        \\exists_{(x_b,y_b) \\in \\R^2} \\sqrt{(x-x_b)^2 + (y-y_b)^2} < \\epsilon \n        \\implies \\sqrt{x^2 + y^2} < 1)}\\\\\n\\end{align*}\n\n\\newpage\n% Problem 4\n\\section{}\nLet $S = \\R^2$. Are the following sets open or closed within the metrics below?\n\\begin{align*}\n    A &= \\qty{(x,y) : x^2 + y^2 < 1}\\\\\n    B &= \\qty{(x,y) : x = 0 \\land -1 \\leq y \\leq 1}\\\\\n    C &= \\qty{(x,y) : 1 < x < 2 \\land -1 \\leq y \\leq 1}\\\\\n    D &= \\qty{(x,y) : \\abs{x} + \\abs{y} < 2}\\\\\n    E &= \\qty{(x,y) : x^2 - y^2 < 1 \\land \\abs{x} + \\abs{y} < 4}\n\\end{align*}\n\n% Part a\n\\subsection{Euclidean Metric: \n$d((x_1,y_1),(x_2,y_2)) = \\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$% = \\norm{(x_1,y_1)-(x_2,y_2)}_2$\n}\n\\subsubsection{$A = \\qty{(x,y) : x^2 + y^2 < 1}$}\nOpen\n\\subsubsection{$B = \\qty{(x,y) : x = 0 \\land -1 \\leq y \\leq 1}$}\nClosed\n\\subsubsection{$C = \\qty{(x,y) : 1 < x < 2 \\land -1 \\leq y \\leq 1}$}\nNeither\n\\subsubsection{$D = \\qty{(x,y) : \\abs{x} + \\abs{y} < 2}$}\nOpen\n\\subsubsection{$E = \\qty{(x,y) : x^2 - y^2 < 1 \\land \\abs{x} + \\abs{y} < 4}$}\nOpen\n\n\\subsection{Manhattan Metric: \n$$d((x_1,y_1),(x_2,y_2)) = \\abs{x_1-y_2} + \\abs{y_1-y_2}$$% = \\norm{(x_1,y_1)-(x_2,y_2)}_1$$\n}\n\\subsubsection{$A = \\qty{(x,y) : x^2 + y^2 < 1}$}\nOpen\n\\subsubsection{$B = \\qty{(x,y) : x = 0 \\land -1 \\leq y \\leq 1}$}\nClosed\n\\subsubsection{$C = \\qty{(x,y) : 1 < x < 2 \\land -1 \\leq y \\leq 1}$}\nNeither\n\\subsubsection{$D = \\qty{(x,y) : \\abs{x} + \\abs{y} < 2}$}\nOpen\n\\subsubsection{$E = \\qty{(x,y) : x^2 - y^2 < 1 \\land \\abs{x} + \\abs{y} < 4}$}\nOpen\n\n\n\\subsection{Highway Metric:}\n\\begin{definition}\n    The highway metric is defined as \n    \\begin{displaymath}\n        d_h((x_1,y_1),(x_2,y_2)) := \n        \\begin{cases}\n            \\abs{y_1 - y_2}, &x_1 = x_2\\\\\n            \\abs{y_1} + \\abs{y_2} + \\abs{x_1 - x_2}, &x_1 \\neq x_2\n        \\end{cases}\n    \\end{displaymath}\n\\end{definition}\n\n\\subsubsection{$A = \\qty{(x,y) : x^2 + y^2 < 1}$}\nNeither\n\\subsubsection{$B = \\qty{(x,y) : x = 0 \\land -1 \\leq y \\leq 1}$}\nNeither\n\\subsubsection{$C = \\qty{(x,y) : 1 < x < 2 \\land -1 \\leq y \\leq 1}$}\nNeither\n\\subsubsection{$D = \\qty{(x,y) : \\abs{x} + \\abs{y} < 2}$}\nOpen\n\\subsubsection{$E = \\qty{(x,y) : x^2 - y^2 < 1 \\land \\abs{x} + \\abs{y} < 4}$}\nNeither\n\n\n\n\\newpage\n% Problem 5\n\\section{}\nLet $(S,d)$ be a metric space.\n% Part a\n\\subsection{Show that for all $A \\subset B \\subset S$ \none has $\\text{int}(A)\\subseteq \\text{int}(B)$ and $\\overline{A}\\subseteq\\overline{B}$. \nAlso provide an example of non-strictness.}\n\n\\begin{theorem}\n    For the metric space $(S,d)$, and $\\forall A \\subset B \\subset S$ the following are true: \n    \\subsubsection{$\\text{int}(A) \\subseteq \\text{int}(B)$}\n    \\begin{proof}\n        \\begin{align*}\n            \\text{int}(A) &= \\qty{x \\in A : \\exists_{\\epsilon>0} B_\\epsilon(x) \\subset A}\\\\\n            &= \\qty{x \\in A : \n                \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n                \\land x_b \\in A}\\\\\n            \\text{int}(B) &= \\qty{x \\in B : \\exists_{\\epsilon>0} B_\\epsilon(x) \\subset B}\\\\\n            &= \\qty{x \\in B : \n                \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n                \\land x_b \\in B}\\\\\n        \\end{align*}\n        \n        Since $(\\text{int}(A) \\subset A) \\land (\\text{int}(B) \\subset B) \\land (A \\subset B)$,\n        \\begin{gather*}\n            \\qty{x \\in A\\subset B : \n                \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n                \\land x_b \\in A \\subset B}\\\\\n            \\forall x \\in \\qty{x \\in A : \n                \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n                    \\land x_b \\in A} \n                \\implies x \\in \\qty{x \\in B : \n                    \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n                        \\land x_b \\in B}\n        \\end{gather*}\n        Therefore,\n        $$\\text{int}(A) \\subseteq \\text{int}(B)$$\\\\\n        This cannot be a strict inequality becouse it would be equal when $A = B$.\n    \\end{proof}\n    \\subsubsection{$\\overline{A} \\subseteq \\overline{B}$}\n    \\begin{proof}\n        \\begin{align*}\n            \\overline{A} &= \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} B_\\epsilon(x) \\cap A \\neq \\emptyset}\\\\\n            &= \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : d(x,x_b) < \\epsilon \n                \\land x_b \\in A}\\\\\n            \\overline{B} &= \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} B_\\epsilon(x) \\cap B \\neq \\emptyset}\\\\\n            &= \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : d(x,x_b) < \\epsilon \n                \\land x_b \\in B}\\\\\n        \\end{align*}\n\n        Since $(\\overline{A} \\subset A) \\land (\\overline{A} \\subset B) \\land (A \\subset B)$,\n        \\begin{gather*}\n            \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : d(x,x_b) < \\epsilon \n                \\land x_b \\in A \\subset B}\\\\\n            \\forall x \\in \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : d(x,x_b) < \\epsilon \n                    \\land x_b \\in A}\n                \\implies x \\in \\qty{x \\in S : \n                    \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : d(x,x_b) < \\epsilon \n                        \\land x_b \\in B}\n        \\end{gather*}\n        Therefore,\n        $$\\overline{A} \\subseteq \\overline{B}$$\n        This cannot be a strict inequality becouse it would be equal if $A = B$.\n    \\end{proof}\n\\end{theorem}\n\n\\newpage\n% Part b\n\\subsection{Is the following true:\n$\\text{int}(A\\cup B) = \\text{int}(A) \\cup \\text{int}(B)$?}\n\n\\begin{align*}\n    \\text{int}(A \\cup B) &= \n        \\qty{x \\in A : \\exists_{\\epsilon>0} B_\\epsilon(x) \\subset A \\cup B}\\\\\n    &= \\qty{x \\in A \\cup B : \n        \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n        \\land (x_b \\in A \\lor x_b \\in B)}\\\\\n    &= \\qty{x \\in A \\cup B : \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in A}\\\\\n        &\\ \\cup \\qty{x \\in A \\cup B : \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in B}\\\\\n    &= \\qty{x \\in A: \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in A}\\\\\n        &\\ \\cup \\qty{x \\in A: \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in B}\\\\\n        &\\ \\cup \\qty{x \\in B : \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in A}\\\\\n        &\\ \\cup \\qty{x \\in B : \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in B}\\\\\n    &= \\text{int}(A) \\cup \\text{int}(B)\\\\\n        &\\ \\cup \\qty{x \\in A: \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in B}\\\\\n        &\\ \\cup \\qty{x \\in B : \n            \\exists_{\\epsilon>0} \\forall_{x_b \\in S} d(x,x_b)<\\epsilon \n            \\land x_b \\in B}\n\\end{align*}\nTherefore, $\\text{int}(A\\cup B) \\subseteq \\text{int}(A) \\cup \\text{int}(B)$ \nand $\\text{int}(A\\cup B) = \\text{int}(A) \\cup \\text{int}(B)$ is not true.\n\n% Part c\n\\subsection{Is the following true:\n$\\overline{A\\cap B} = \\overline{A} \\cap \\overline{B}$?}\n\\begin{align*}\n    \\overline{A \\cap B} &= \\qty{x \\in S : \n                \\forall_{\\epsilon> 0} B_\\epsilon(x) \\cap (A \\cap B) \n                \\neq \\emptyset}\\\\\n    &= \\qty{x \\in S :  \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : \n        d(x,x_b) < \\epsilon \\land x_b \\in A \\cap B}\\\\\n    &= \\qty{x \\in S : \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : \n        d(x,x_b) < \\epsilon \\land x_b \\in A \\land x_b \\in B}\\\\\n    &= \\qty{x \\in S : \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : \n            d(x,x_b) < \\epsilon \\land x_b \\in A}\\\\\n        &\\ \\cap \\qty{x \\in S : \\forall_{\\epsilon> 0} \\exists_{x_b \\in S} : \n            d(x,x_b) < \\epsilon \\land x_b \\in B}\\\\\n    &= \\overline{A} \\cap \\overline{B}\n\\end{align*}\nTherefore, $\\overline{A\\cap B} = \\overline{A} \\cap \\overline{B}$ is true.\n\n\\newpage\n% Problem 6\n\\section{}\nGive a topological proof of the infinitude of the set of prime numbers. (H. Furstenberg, 1955)\\\\\nDenote $N_{a,b} := \\{a + nb : b \\in \\Z\\} \\subset \\Z$. Define the topology on $\\Z$ as follows: \nThe set $U$ will be called open if for any $a \\in U$ there exists $b \\in \\Z$ so that \n$N_{a,b} \\in U$. Note that every open set is infinite.\n\n\\begin{definition}\n    $$N_{a,b} := \\{a + nb : b \\in \\Z\\} \\subset \\Z$$\n\\end{definition}\n\\begin{definition}\n    The set $U$ will be called open if\n    $$\\forall_{a\\in U} \\exists_{b\\in\\Z} : N_{a,b} \\subset U$$\n\\end{definition}\n\n% Part a\n\\subsection{Show that it is indeed a topology.}\n(i.e): any union of open sets is open and any finite intersection of open sets is open.\n\\subsubsection{$\\emptyset$ and $\\Z$ are open sets.}\n\\subsubsection{Any union of open sets is an open set}\n\\begin{align*}\n    \\forall_{a\\in U} \\exists_{b\\in\\Z} : N_{a,b} \\in U\\\\\n    \\forall_{a\\in U} \\exists_{b\\in\\Z} : \\{a + nb : b \\in \\Z\\} \\subset Z \\subset U\n\\end{align*}\nTrivially, it can be seen that $\\{U_i\\}_{i\\in I}$ open $\\implies \\bigcup_{i\\in I} U_i$ open.\n\\subsubsection{Finite intersections is open. (i.e.) $U_1, U_2$ open $\\implies U_1 \\cap U_2$ open.}\n$$x \\in U_1 \\cap U2 \\implies \\exists_{a_1,a_2\\in S} N_{a_1,x} \\subset U_1 \\land N_{a_2,x} \\subset U_2$$\nLet $a = \\text{lcm}\\qty{a_1,a_2}$,\n$$(N_{a,x} \\subseteq N_{a_1,x}) \\land (N_{a,x} \\subseteq N_{a_2,x})$$\nTherefore,\n$$x\\in S_{a,x} \\subseteq U_1 \\cap U_2$$\nmeaning that any finite interesection of open sets is open.\n\n% Part b\n\\subsection{Show that $N_{a,b}$ is closed.}\n\\begin{align*}\n    N_{a,b} &= \\{a + nb : b \\in \\Z\\} \\subset \\Z\\\\\n    N_{a,b}^c &= \\Z \\backslash \\{a + nb : b \\in \\Z\\}\\\\\n    N_{a,b} &= \\Z \\backslash (N_{a,b+1} \\cup N_{a,b+2} \\cup \\dots \\cup N_{a,b_a-1})\n\\end{align*}\nSince $N_{a,b}^c$ is open, $N_{a,b}$ is closed.\n\n\n% Part c\n\\subsection{Show that $\\Z \\backslash \\{-1,1\\}$ is open}\n\\begin{align*}\n    &\\forall_{x \\in \\Z \\backslash \\{-1,1\\}} \\exists_{\\epsilon > 0} : \n        B_\\epsilon(x) \\subset \\Z \\backslash \\{-1,1\\}\\\\\n    &\\forall_{x \\in \\Z \\backslash \\{-1,1\\}} \\exists_{\\epsilon > 0} : \n        \\forall_{x_b \\in Z} d(x,x_b) < \\epsilon \\implies x_b \\in \\Z \\backslash \\{-1,1\\}\n\\end{align*}\nWhich is clearly open since the ball sets are always contained within the set itself.\n\n% Part d\n\\subsection{Prove that the set $\\mathbb{P}$ of prime numbers cannot be finite.}\nHint: $\\Z \\backslash \\{-1,1\\} = \\bigcup_{p \\in \\mathbb{P}} N_{0,p}$\\\\\n\nAssume $\\mathbb{P}$ is finite. \nSince $\\forall_{p\\in \\mathbb{p}} N_{0,p}$ closed, the union over $p \\in \\mathbb{P}$ would also be closed.\\\\\n\nHowever, since $\\Z\\backslash \\{-1,1\\}$ is open, this can't be true, so $\\mathbb{P}$ must be infinite.\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "bdc66ab442fa147ac929457c184ab2d2ca7f1f96", "size": 22607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework/HW5/MATH5301-HW5.tex", "max_stars_repo_name": "jonaswagner2826/MATH5301", "max_stars_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-01T05:26:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-01T05:26:53.000Z", "max_issues_repo_path": "Homework/HW5/MATH5301-HW5.tex", "max_issues_repo_name": "jonaswagner2826/MATH5301", "max_issues_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_issues_repo_licenses": ["MIT"], "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/MATH5301-HW5.tex", "max_forks_repo_name": "jonaswagner2826/MATH5301", "max_forks_repo_head_hexsha": "40de090ba1a936b406aa8d4c4383be2cf1418f29", "max_forks_repo_licenses": ["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.7106164384, "max_line_length": 107, "alphanum_fraction": 0.5542973415, "num_tokens": 9488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6228329090180305}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{caption}\n\\usepackage{amsfonts}\n\\usepackage{ucs}\n\\usepackage{amssymb}\n\\usepackage{xcolor}\n\\usepackage{color}\n\n\\title{\\textbf{Functions Notes}}\n\\date{Monday, 28 August, 2021}\n\\author{Keymaster}\n\n\\pagecolor{black}\n\\color{white}\n\n\\begin{document}\n\n    \\maketitle\n\n    \\subsection*{Normal Function}\n    Let, $f : X \\rightarrow Y$ be a function and there exists a set $A$ such that, $A \\subseteq X$ where\n    $f(A) = \\{f(a) \\in Y : a \\in A\\}$.\n    Note that this can be read as,\n    \\emph{set of images in the \\textbf{co-domain} of elements in a subset of the \\textbf{domain}}.\n\n    \\subsection*{Inverse Function}\n    Let, $f : X \\rightarrow Y$ be a function and there exists a set $B$ such that $B \\subseteq Y$ where\n    $f^{-1}(B) = \\{x \\in X : f(x) \\in B\\}$.\n    Again, this can be read as,\n    \\emph{set of all elements of the \\textbf{domain} maps to a specific set in the \\textbf{co-domain}}.\n\n    \\subsection*{More Clarity}\n    When we say $f^{-1}(\\{y\\})$, it works because it is the set of all elements on the domain which is being sent to\n    $y$ by $f$ i.e., under the function.\n    It also makes sense to think that of this set: there might \\textbf{not} be anything to sent to\n    (nothing maps to the set $\\{y\\}$ or, $y$ is not in range from the domain) $f^{-1}(\\{y\\})$, in which case\n    $f^{-1}(\\{y\\}) = \\emptyset$.\n    Or, $f$ might send multiple elements to $y$ (if $f$ is not injective).\n    As a notational convenience, we usually drop the set braces around the $y$ and write\n    $f^{-1}(y)$ instead for this set.\n\n    \\subsection*{Warning!}\n    $f^{-1}(x)$ is not an inverse function.\n    Inverse functions only exist for bijections, but, $f^{-1}(x)$ is defined for any function $f$.\n    The point: $f^{-1}(y)$ is a set not an element of the domain.\n    This is just sloppy notation for $f^{-1}(\\{y\\})$.\n    To help make this distinction, we would call $f^{-1}(y)$ \\textbf{the complete inverse of $y$ under $f$}.\n    It's not the image of $y$ under $f$.\n    It is not the image of $y$ under $f^{-1}$ (since the function $f^{-1}$ might not exist).\n\n\\end{document}\n", "meta": {"hexsha": "7abc0b195e32d0c1e5337c097a4ebae222fb1bc5", "size": 2139, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/maps.tex", "max_stars_repo_name": "pagankeymaster/discrete-math-notes", "max_stars_repo_head_hexsha": "20497ad689ebaa3aeedaf9cf7fce6fab96753d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-04T16:12:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-04T16:12:13.000Z", "max_issues_repo_path": "src/maps.tex", "max_issues_repo_name": "pagankeymaster/discrete-math-notes", "max_issues_repo_head_hexsha": "20497ad689ebaa3aeedaf9cf7fce6fab96753d40", "max_issues_repo_licenses": ["MIT"], "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/maps.tex", "max_forks_repo_name": "pagankeymaster/discrete-math-notes", "max_forks_repo_head_hexsha": "20497ad689ebaa3aeedaf9cf7fce6fab96753d40", "max_forks_repo_licenses": ["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.6111111111, "max_line_length": 116, "alphanum_fraction": 0.6479663394, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6228329087285626}}
{"text": "\\documentclass[onecolumn]{article}\n\\usepackage{amsmath}\n\\usepackage{lscape}\n\\begin{document}\n\\title{01 - Conventions}\n\\author{}\n\\date{}\n\\maketitle\n\\section{Conventions} % (fold)\nFollowing are applicable to calculate the chemical potential of a solution, and for expressing its composition.\n\\label{sec:conventions}\n% section section_name (end)\n\\subsection{Composition}\n\\label{subsec:composition}\n\\begin{table}[h]\n\\begin{tabular}{|lll|l|}\n\\hline\n\t\t      & expression\n\t\t\t\t\t& [=] units\n\t\t\t\t\t& total\\\\\n\\hline\nmole number   & $n_i$ & mol i\n\t\t\t\t\t\t\t& $n = \\sum_i{n_i} = {n_0 + \\sum_{j \\neq 0}{n_j}}$ \\\\\nmass \t\t\t\t\t& $w_i$\t & g i\n\t\t\t\t\t\t\t& $w = \\sum_i{w_i} = {n_0 M_0 + \\sum_{j \\neq 0}{n_j M_j}}$ \\\\\nmolar mass\t\t& $M_i = \\frac{w_i}{n_i}$ & $\\frac{g_i}{mol_i}$\n \t\t\t\t\t\t\t& $M = \\frac{\\sum_i{w_i}}{\\sum_i{w_i/M_i}} =\n\t\t\t\t\t\t\t\\frac{1}{\\sum_i{x_{w, i}/M_i}}$ \\\\\nmolal  conc.  & $m_i = \\frac{n_i}{n_0 M_0} = \\frac{n_i}{n_0 M_0 /\n\\left(1000 \\frac{g}{kg} \\right)}$ & $\\frac{mol_i} {kg_{solvent}}$\n\t\t\t\t\t\t\t& $\\sum_i{m_i} = \\frac{\\sum_i{n_i}}{n_0 M_0} =\n\t\t\t\t\t\t\t\\frac{1}{x_0 M_0} $ \\\\\ndensity \t    & $\\rho_i = w_i/V_r = n_i M_i/V_r = c_i M_i$ &\n\t\t\t\t\t\t\t$\\frac{g_i}{mL}$\n\t\t\t\t\t\t\t& $\\rho = \\sum_i{\\rho_i} = \\frac{\\sum_i{w_i}}{V_r} = w/V_r$ \\\\\nmolar  conc.  & $c_i = n_i/V_r = n_i \\rho_i /w_i = \\rho_i / M_i$\n\t\t\t\t\t\t\t& $\\frac{mol_i}{L}$\n\t\t\t\t\t\t\t& $c_T = \\sum_i{c_i} = \\frac{\\sum_i{n_i}}{V_r} = n/V_r$ \\\\\nmole fraction & $x_i = \\frac{n_i}{\\sum_j{n_j}}$ & [adim.]\n\t\t\t\t\t\t\t& $\\sum_i{x_i}=1$ \\\\\nmass fraction & $x_{w,i} = \\frac{w_i}{\\sum_j{w_j}}$ & [adim.]\n\t\t\t        & $\\sum_i{x_{w, i}} = 1$\\\\\n\\hline\n\\end{tabular}\n\\caption{Conventional expressions of composition. Subscript 0 applied to the\nsolvent, other subscripts applied to solutes.}\n\\label{table:composition_expr}\n\\end{table}\nRelationships are obtained for conversion, such as density of solution $\\rho$ to density of\nsolvent $\\rho_0 = c_0 M_0$, molal concentration to mole fraction and molar concentration to\nmole fraction: \\\\\n\\[\n\\begin{aligned}\n\\frac{\\rho}{\\rho_0} & = \\frac{\\sum_{i}{\\rho_i}}{c_0 M_0} = \\frac{c_0 M_0 + \\sum_{j \\neq 0}{c_j M_j}}{c_0 M_0} = 1 + \\frac{\\sum_{j\\neq0}{n_j M_j/V_r}}{n_0 M_0/V_r} = 1+\\sum_{j\\neq0}{m_j M_j}\\\\\n\\frac{m_i}{x_i} & = \\frac{n_i/(n_0 M_0) \\times (n_0 + \\sum_{j\\neq0}{n_j}) }{n_i} = \\frac{1}{M_0} + \\sum_{j\\neq0}{m_j} = \\frac{1}{M_0} \\times (1 + \\sum_{j\\neq0}{m_jM_0}) \\\\\n\\frac{c_i}{x_i} & = \\frac{n_i \\rho \\times (n_0 + \\sum_{j\\neq0}{n_j}) }{n_i \\times (n_0 M_0 + \\sum_{j\\neq0}{n_j M_j})} = \\frac{ n_0 + \\sum_{j\\neq0}{n_j} }{ n_0 M_0 + \\sum_{j\\neq0}{n_j M_j}} \\rho = \\frac{ \\frac{1}{M_0} + \\sum_{j\\neq0}{m_j} }{ 1 + \\sum_{j\\neq0}{m_j M_j}} \\rho \\\\\n & = \\frac{\\rho_0}{M_0} \\times (1 + \\sum_{j\\neq0}{m_j M_0})\n\\end{aligned}\n\\]\nThese conversions are summarized below:\n\\begin{table}[h]\n\\begin{center}\n\\begin{tabular}{|l|cccc|}\n\\hline\n \t\t\t& $x_i$ & $m_i$ & $c_i$ & $\\rho_i$ \\\\\n\\hline\n$x_i$ & \t1\t\t& $\\frac{x_i}{m_i} = x_0 M_0$\n\t\t\t&\t$\\frac{x_i}{c_i} = \\frac{x_0 M_0}{\\rho_0}$\n\t\t\t& $\\frac{x_i}{\\rho_i} = \\frac{x_0 M_0}{\\rho_0 M_i}$ \\\\\n$m_i$ & $\\frac{x_i}{m_i} = \\frac{M_0}{1 + \\sum_{j\\neq0}{m_jM_0}}$\t& \t1\n\t\t\t&\t$\\frac{m_i}{c_i} = \\frac{1}{\\rho_0}$\n\t\t\t& $\\frac{m_i}{\\rho_i} = \\frac{1}{\\rho_0 M_i} $\\\\\n$c_i$ &\t$\\frac{x_i}{c_i} = \\frac{M_0}{\\rho} \\times\n\t\t\t\\frac{1+\\sum_{j\\neq0}{m_j M_j}}{1 + \\sum_{j\\neq0}{m_j M_0}}$\n\t\t\t& $\\frac{m_i}{c_i} = \\frac{1+\\sum_{j\\neq0}{m_j M_j}}{\\rho}$\n\t\t\t&\t\t1\t\t& $\\frac{c_i}{\\rho_i} = \\frac{1}{M_i}$ \\\\\n$\\rho_i$ & \t$\\frac{x_i}{\\rho_i} = \\frac{M_0}{\\rho M_i} \\times\n\t\t\t\\frac{1+\\sum_{j\\neq0}{m_j M_j}}{1 + \\sum_{j\\neq0}{m_j M_0}}$\n\t\t\t& $\\frac{m_i}{\\rho_i} = \\frac{1 + \\sum_{j\\neq0}{m_j M_j}}{\\rho M_i}$\n\t\t\t&\t$\\frac{c_i}{\\rho_i} = \\frac{1}{M_i}$\t& 1 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Conversion between composition expressions in terms of solvent density\n$\\rho_0$ and solution density $\\rho$}\n\\label{table:composition_expr_conv}\n\\end{table}\n\\subsection{Chemical potential \\cite{Denbigh1968} }\n\\label{subsec:chemical_potential}\nSuitable conventions are applied to different solutions: Convention I is useful for solutions of miscible liquids at T,P (e.g. ethanol/water). Conventions II, III, and IV are useful for solutions of components that are gases or solids at T,P (e.g. oxygen or sugar in water). \\\\\nConvention I: Each component approaches ideality as its mole fraction approaches unity.\n\\begin{equation}\n\\textnormal{component (i): } (\\gamma_i \\rightarrow 1) as  (x_i \\rightarrow 1)\\\\\n\\end{equation}\nConvention II: Ideal solvent as it approaches unit mole fraction; ideal solutes at \\textit{infinite dilution}, expressed in mole fraction.\\\\\n\\begin{equation}\n\\begin{aligned}\n\\textnormal{solvent (0): } & (\\gamma_0 \\rightarrow 1) as  (x_0 \\rightarrow 1)\\\\\n\\textnormal{solute (i): } & (\\gamma_i \\rightarrow 1) as (x_i \\rightarrow 0)\n\\end{aligned}\n\\end{equation}\nConvention III: Ideal solvent as it approaches unit mole fraction; ideal solutes at \\textit{infinite dilution}, expressed in molality. \\\\\n\\begin{equation}\n\\begin{aligned}\n\\textnormal{solvent (0): } & (\\gamma_0 \\rightarrow 1) as  (x_0 \\rightarrow 1)\\\\\n\\textnormal{solute (i): } & (\\gamma_i \\rightarrow 1) as (m_i \\rightarrow 0)\n\\end{aligned}\n\\end{equation}\nConvention IV: Ideal solutes at \\textit{infinite dilution}, expressed in molarity. \\\\\n\\begin{equation}\n\\begin{aligned}\n\\textnormal{solute (i): } & (\\gamma_i \\rightarrow 1) as (c_i \\rightarrow 0)\n\\end{aligned}\n\\end{equation}\nChemical potential expressed under each convention, with $m_i^{\\circ}$ and $c_i^{\\circ}$ selected as reference solute states at unit molality, and molarity respectively: $m_i^{\\circ}=1 \\frac{mol}{kg_{solvent}}$ and $c_i^{\\circ}=1 \\frac{mol}{L}$.\n\\begin{equation}\n\\begin{aligned}\n\\mu_i = & \\mu_i^{*} + RTln(\\gamma_i^{I} x_i) \\\\\n\t= \t& \\mu_i^{*} + RTln(\\gamma_i^{II} x_i) \\\\\n\t=\t& \\mu_i^{\\fbox{}} + RTln(\\gamma_i^{III} m_i/m_i^{\\circ}) \\\\\n\t= \t& \\mu_i^{\\diamond} + RTln(\\gamma_i^{IV} c_i/c_i^{\\circ})\n\\end{aligned}\n\\end{equation}\nNotes on conversion between conventions:\n\\begin{itemize}\n\\item Values of activity coefficients $\\gamma_i^{II}$ and $\\gamma_i^{III}$ vary, but chemical potential does not vary due to convention selection.\n\\item Reference states chemical potentials under each convention $\\mu_i^{*}$ and $\\mu_i^{\\fbox{}}$  are functions of temperature and pressure exclusively. Their difference calculated at infinite dilution does not change at other compositions:\n\\end{itemize}\n\\[\n\\mu_i^{*} - \\mu_i^{\\fbox{}}  =  func(T,P) =  \\lim_{x_0 \\to 1} \\left( \\mu_i^{*} - \\mu_i^{\\fbox{}}\\right)\n\\]\n\\[\nRTln\\left[ \\frac{\\gamma_i^{III} m_i/m_i^{\\circ}}{\\gamma_i^{II} x_i}\\right] = \\lim_{x_0 \\to 1} RTln\\left[ \\frac{\\gamma_i^{III} m_i/m_i^{\\circ}}{\\gamma_i^{II} x_i}\\right]\n\\]\nTherefore, referring back to conventions II and III, $\\gamma_i \\rightarrow 1$ at \\textit{infinite dilution}:\n\\[\n\\begin{aligned}\n\\frac{\\gamma_i^{III} m_i/m_i^{\\circ}}{\\gamma_i^{II} x_i} & = \\lim_{x_0 \\to 1} \\frac{\\gamma_i^{III} m_i/m_i^{\\circ}}{\\gamma_i^{II} x_i} = \\frac{1}{m_i^0} \\times \\lim_{x_0 \\to 1} \\frac{m_i}{x_i} \\\\\n& = \\frac{1}{m_i^0} \\times \\lim_{x_0 \\to 1} \\frac{n_0+\\sum_{j \\neq 0}n_j}{n_0 M_0} = \\frac{1}{m_i^0 M_0} \\times \\lim_{x_0 \\to 1} \\frac{1}{x_0} \\\\\n& = \\frac{1}{m_i^\\circ M_0}\n\\end{aligned}\n\\]\nThis leads to the following relationship between activity coefficients calculated by each convention:\n\\begin{equation}\n\\label{eq:act_coef_m_to_x}\n\\gamma_i^{II} = \\gamma_i^{III} \\times \\frac{m_i M_0}{x_i}\n\\end{equation}\nA standard form of equation \\ref{eq:act_coef_m_to_x} is obtained by assuming complete dissociation of a solute $A$ with molality $m$ into $\\nu$ components, so that for all solutes the sum of molalities can be expressed as $\\sum_{i}m_i = \\nu m $:\n\\[\nA \\rightleftharpoons A_1 + A_2 + A_2 + ... + A_{\\nu}\n\\]\nCombined with Table \\ref{table:composition_expr_conv}, the expression as presented in \\cite{Hamer1968} is obtained:\n\\[\n\\begin{aligned}\n\\gamma_i^{II} & =  \\gamma_i^{III} \\times M_0 \\frac{m_i}{x_i} = \\gamma_i^{III} \\times (1+\\sum_{j\\neq0}{m_j M_0}) = \\gamma_i^{III} \\times \\left(1+\\frac{\\nu m M_0}{1000 \\frac{g}{kg}} \\right)\n\\end{aligned}\n\\]\nEquivalent expressions are obtained to convert activity coefficients expressed in terms of concentration:\n\\[\n\\begin{aligned}\n\\frac{\\gamma_i^{IV} c_i/c_i^{\\circ}}{\\gamma_i^{II} x_i} & = \\lim_{x_0 \\to 1} \\frac{\\gamma_i^{IV} c_i/c_i^{\\circ}}{\\gamma_i^{II} x_i} = \\frac{1}{c_i^0} \\times \\lim_{x_0 \\to 1} \\frac{c_i}{x_i} = \\frac{\\rho_0}{c_i^0} \\times \\lim_{x_0 \\to 1} \\frac{m_i}{x_i} \\\\ & = \\frac{\\rho_0}{c_i^0} \\times \\lim_{x_0 \\to 1}\\frac{n_0+\\sum_{j \\neq 0}n_j}{n_0 M_0} = \\frac{\\rho_0}{c_i^0 M_0}\\\\\n\\end{aligned}\n\\]\nSimilarly, the relationship between calculated activity coefficients is determined:\n\\begin{equation}\n\\label{eq:act_coef_c_to_x}\n\\gamma_i^{II} = \\gamma_i^{IV} \\times \\frac{c_i M_0}{x_i \\rho_0}\n\\end{equation}\nEquation \\ref{eq:act_coef_c_to_x} is represented accordingly with the solute dissociation convention:\n\\[\n\\gamma_i^{II} = \\gamma_i^{IV} \\times \\frac{M_0}{\\rho_0}\\times \\frac{c_i}{x_i} = \\gamma_i^{IV} \\times (1 + \\sum_{j\\neq0}{m_jM_0}) = \\gamma_i^{IV} \\times \\left(1+\\frac{\\nu m M_0}{1000 \\frac{g}{kg}} \\right)\n\\]\nFor the solvent, conversion between conventions is obtained through equation\n\\ref{eq:act_coef_m_to_x}:\n\\[\n\\gamma_0^{II} = \\gamma_0^{III} \\times \\frac{m_0 M_0}{x_0} =\n\\gamma_0^{III} \\times \\frac{1}{x_0}\n\\]\n \\begin{thebibliography}{9}\n \\bibitem{Denbigh1968} Denbigh, Kenneth G.; The principles of chemical equilibrium; 4th ed. Cambridge University Press, UK 1981.\n \\bibitem{Hamer1968} NSRDS 24 Theoretical Mean Activity Coefficients of Strong Electrolytes in Aqueous Solutions from 0 to 100°C - Walter J. Hamer. NSRDS-NBS 24, 271p. (1968). www.nist.gov/data/nsrds/NSRDS-NBS-24.pdf [Apr-2016]\n \\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "138dbe855715bdbab1674c48f5d4f2736b34d9bc", "size": 9643, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/formulation_conventions.tex", "max_stars_repo_name": "santiago-salas-v/literature-implementations-py", "max_stars_repo_head_hexsha": "675155d77b59beae057aca377505da327dd9b963", "max_stars_repo_licenses": ["MIT"], "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/formulation_conventions.tex", "max_issues_repo_name": "santiago-salas-v/literature-implementations-py", "max_issues_repo_head_hexsha": "675155d77b59beae057aca377505da327dd9b963", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-07-06T02:11:43.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-14T19:21:33.000Z", "max_forks_repo_path": "docs/formulation_conventions.tex", "max_forks_repo_name": "santiago-salas-v/literature-implementations-py", "max_forks_repo_head_hexsha": "675155d77b59beae057aca377505da327dd9b963", "max_forks_repo_licenses": ["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.4076086957, "max_line_length": 372, "alphanum_fraction": 0.6597531888, "num_tokens": 3820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6228328973522771}}
{"text": "\\section{Electricity \\& Magnetism}\n\nThis section covers material related to the E\\&M portion of the exam.\nMost of these subsections go into more depth than is required for the PGRE.\nGauss's law, Faraday's law, and radiation originating from charged particles are consistently tested on the practice exams.\nMethod of images is also something to brush up on.\n\n\\subsection{Electrostatics}\n\n\\subsubsection{Coulomb's Law}\nForce Law: \\(\\displaystyle\\mathbf{F}_E=k_e\\frac{q_1q_2}{\\scriptr^2}\\hat{\\scriptr}\\)\\\\\\\\*\nElectric Field:\\\\*\n\\(\\displaystyle\\mathbf{F}_E=q\\mathbf{E}\\)\\\\*\n\\(\\displaystyle\\mathbf{E}=k_e\\sum_i\\frac{q_i}{\\scriptr_i^2}\\hat{\\scriptr}_i\\to k_e\\int\\frac{\\hat{\\scriptr}}{\\scriptr^2}\\mathrm{d}q\\)\\\\\\\\*\nElectric Field Example: E-field along \\(z\\)-axis due to a ring of charge \\(Q\\) centered at the origin and in the \\(x\\)-\\(y\\) plane: \\(\\displaystyle\\mathbf{E}=\\frac{k_eQd}{(R^2+z^2)^{3/2}}\\hat{z}\\)\n\n\\subsubsection{Gauss's Law}\nElectric Flux: \\(\\Phi_E=\\int_S\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{a}\\)\\\\*\nThrough a Closed Surface: \\(\\displaystyle\\Phi_E=\\oint_{\\delta V}\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{a}\\)\\\\*\nDifferential Form: \\(\\nabla\\cdot\\mathbf{E}=\\displaystyle\\frac{\\rho}{\\epsilon_0}\\)\\\\*\nIntegral Form: \\(\\displaystyle\\oint_{\\delta V}\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{a}=\\frac{Q_{enc}}{\\epsilon_0}\\)\\\\\\\\*\nCommon Uses of Gauss's Law:\n\\begin{itemize}\n\\item Spherical Symmetry: Inside uniformly charged sphere of radius \\(a \\to\\) \\(\\displaystyle E=\\frac{k_eQ}{a^3}r=\\frac{\\rho}{3\\epsilon_0}r\\)\n\\item Cylindrical Symmetry: Outside cylinder of radius \\(b\\) with uniform surface charge \\(\\to\\) \\(\\displaystyle E=\\frac{\\sigma b}{\\epsilon_0}\\frac{1}{r}\\)\n\\item Planar Surface: Near plate with uniform surface charge \\(\\to\\) \\(\\displaystyle E=\\frac{\\sigma}{2\\epsilon_0}\\)\n\\end{itemize}\nGauss's law is also useful in showing that all the net charge on a conductor must reside on its surface, as well as that there is no E-field inside a conductor and, therefore, no net force on a particle placed in a conductor.\\\\*\nGauss's law is typically the easiest way to calculate E-fields when enough spatial symmetry is present.\n\n\\newpage\n\\subsubsection{Electric Potential}\n\\(\\nabla\\times\\mathbf{E}=\\vec{0}\\to\\mathbf{E}=-\\nabla V \\to -\\nabla^2 V=\\displaystyle\\frac{\\rho}{\\epsilon_0}\\)\\\\\\\\*\nElectric Potential: \\(\\displaystyle V(\\mathbf{b})-V(\\mathbf{a})= -\\int_\\mathbf{a}^\\mathbf{b}\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{s}\\)\\\\\\\\*\nIf \\(\\mathbf{a}\\) is taken to be a reference where \\(V(\\mathbf{a})=0\\), then \\(\\displaystyle V(\\mathbf{r})= -\\int_\\mathbf{O}^\\mathbf{r}\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{s}\\)\\\\\\\\*\n\\(\\displaystyle V=k_e\\sum_i\\frac{q_i}{\\scriptr_i} \\to k_e\\int\\frac{\\mathrm{d}q}{\\scriptr}\\)\\\\*\nA conductor is an equipotential and the \\(\\mathbf{E}\\) field is \\(\\bot\\) to the surface just above a conductor (else the surface charge would move).\\\\*\nElectric Potential Example: Potential along \\(z\\)-axis due to a ring of charge \\(Q\\) centered at the origin and in the \\(x\\)-\\(y\\) plane \\(\\to\\) \\(\\displaystyle\\ V=\\frac{k_eQ}{\\sqrt{R^2+z^2}}\\)\n\n\\subsubsection{Electrostatic Force on a Conductor}\nForce per unit area: \\(\\mathbf{f}=\\sigma\\mathbf{E}_{ave}=\\frac{1}{2}\\sigma(\\mathbf{E}_{above}-\\mathbf{E}_{below})\\)\\\\*\n(This actually applies to any surface charge.)\\\\\\\\*\nFor a conductor: \\(\\mathbf{f}=\\frac{1}{2\\epsilon_0}\\sigma^2\\hat{\\mathbf{n}}\\)\n\n\\subsubsection{Electric Dipole}\nElectric Dipole Moment: \\(\\mathbf{p}=q\\mathbf{d}\\) where \\(\\mathbf{d}\\) is the displacement vector pointing from the negative charge (\\(-q\\)) to the positive charge (\\(q\\))\\\\*\n\\(\\displaystyle\\mathbf{p}=\\int{\\mathbf{r'}\\rho(\\mathbf{r}')\\mathrm{d}v'}\\)\\\\\\\\*\nThe electric potential from a dipole:\\\\*\n\\(\\displaystyle V(\\mathbf{r})=\\frac{1}{4\\pi\\epsilon_0}=\\frac{\\mathbf{p}\\cdot\\hat{\\mathbf{r}}}{r^2}\\)\\\\\\\\*\nThe field from a dipole:\\\\*\n\\(\\displaystyle E_{dipole}\\propto \\frac{p}{r^3}\\)\\\\*\nSpecifically, \\(\\displaystyle \\mathbf{E}_{dipole}=\\frac{1}{4\\pi\\epsilon_0}\\frac{1}{r^3}\\left[3\\left(\\mathbf{p}\\cdot\\hat{\\mathbf{r}}\\right)\\hat{\\mathbf{r}}-\\mathbf{p}\\right]\\)\\\\\\\\*\nEffect of an external \\(\\mathbf{E}\\) field on a dipole:\\\\*\nForce: \\(\\mathbf{F}=\\left(\\mathbf{p}\\cdot\\nabla\\right)\\mathbf{E}\\)\\\\*\nTorque: \\(\\vec{\\tau}=\\mathbf{p}\\times\\mathbf{E}\\)\\\\*\nPotential Energy: \\(U=-\\mathbf{p}\\cdot\\mathbf{E}\\)\n\n\\subsubsection{Dielectrics}\nThe dipole moment per unit volume is called the polarization \\(\\mathbf{P}\\).\\\\*\n\\(\\mathbf{P}\\cdot\\hat{\\mathbf{n}}=\\sigma_{bound}\\)\\\\*\n\\(-\\nabla\\cdot\\mathbf{P}=\\rho_{bound}\\)\\\\\\\\*\n\\(\\displaystyle V(\\mathbf{r})=\\frac{1}{4\\pi\\epsilon_0}\\int{\\frac{\\hat{\\mathbf{\\scriptr}}\\cdot\\mathbf{P}(\\mathbf{r}')}{\\scriptr^2}\\mathrm{d}v'}\\)\\\\\\\\*\nThe electric displacement is \\(\\mathbf{D}=\\epsilon_0\\mathbf{E}+\\mathbf{P}\\).\\\\*\n\\(\\nabla\\cdot\\mathbf{D}=\\rho_{free}\\to \\displaystyle\\oint_{\\delta V}\\mathbf{D}\\cdot\\,\\mathrm{d}\\mathbf{a}=Q_{free_{enc}}\\)\\\\\\\\*\n\nLinear Dielectrics:\\\\*\nDielectric Constant: \\(\\displaystyle\\kappa=\\frac{\\epsilon}{\\epsilon_0}\\) (note: \\(\\kappa\\geq 1\\) typically)\\\\*\n\\(\\mathbf{P}=(\\epsilon-\\epsilon_0)\\mathbf{E}\\)\\\\*\n\\(\\mathbf{D}=\\epsilon\\mathbf{E}=\\kappa\\epsilon_0\\mathbf{E}\\)\\\\\\\\*\nA convenient way to calculate \\(\\displaystyle\\sigma_{bound}\\) is to use \\(\\mathbf{D}=\\epsilon\\mathbf{E}\\) with \\(\\displaystyle\\oint_{\\delta V}\\mathbf{D}\\cdot\\,\\mathrm{d}\\mathbf{a}=Q_{free_{enc}}\\) to get \\(\\mathbf{P}\\) and finally use the relation \\(\\mathbf{P}\\cdot\\hat{\\mathbf{n}}=\\sigma_{bound}\\).\n\n\\subsubsection{Energy in an Electrostatic Field}\n\\(\\displaystyle U=\\frac{k_e}{2}\\sum_j\\sum_{i\\neq j}\\frac{q_iq_j}{r_{ij}} \\)\\\\*\n\\(\\displaystyle U=\\frac{\\epsilon_0}{2}\\int{E^2\\mathrm{d}v}\\)\\\\*\n\\(\\displaystyle U=\\frac{1}{2}\\int{\\mathbf{D}\\cdot\\mathbf{E}\\hspace{2pt}\\mathrm{d}v}\\)\n\n\\subsubsection{Method of Images}\nForce behaves as if there was an actual image charge present.\\\\*\nEnergy, however, needs to be calculated using only regions ``outside'' the conductor. (\\(\\mathbf{E}=\\mathbf{0}\\) ``inside'')\\\\*\nFor planar conductor, replace the conductor with a mirror image of the charge distribution with opposite charge.\\\\*\nFor spherical conductor of radius \\(R\\), replace the conductor with a charge \\(q'\\) a distance \\(b\\) from the origin.\n(\\(r\\) is the distance \\(q\\) is from the center of the sphere)\n\\begin{eqnarray}\n\\displaystyle q'&=&\\frac{-R}{r}q \\nonumber \\\\\n\\displaystyle b&=&\\frac{R^2}{r} \\nonumber\n\\end{eqnarray}\n\n\\subsubsection{Separation of Variables}\nUsed to solve Laplace's equation: \\(\\nabla^2 V(\\mathbf{r})=0\\)\\\\\\\\*\nDecompose \\(V(\\mathbf{r})\\) into separate, independent functions of the coordinates.\\\\\\\\*\nUse boundary conditions to find relationship between the series coefficients and exploit the orthogonality (or orthonormality) of the trigonometric functions, \\(P_l\\), or \\(Y_l^m\\).\\\\\\\\*\nFor Cartesian coordinates you must set up and solve each scenario from scratch.\\\\*\nIn spherical polar coordinates with azimuthal symmetry, use:\\\\*\n\\(\\displaystyle V(r,\\theta)=\\sum_{l=0}^\\infty\\left(A_lr^l+\\frac{B_l}{r^{l+1}}\\right)P_l(\\cos{\\theta})\\)\n\n\\subsection{Magnetostatics}\n\n\\subsubsection{Current}\n\\(\\displaystyle I=\\frac{\\mathrm{d}q}{\\mathrm{d}t}\\)\\\\\\\\*\nDrift Velocity of Charge Carriers: \\(I=nqv_DA\\)\\\\*\nCurrent Density: \\(J=\\frac{I}{A}=nqv_D\\to \\mathbf{J}=nq\\mathbf{v}_D\\)\\\\\\\\*\nLinear Current: \\(\\mathbf{I}=\\lambda \\mathbf{v}\\)\\\\*\nSurface Current: \\(\\mathbf{K}=\\sigma \\mathbf{v}\\)\\\\*\nVolume Current: \\(\\mathbf{J}=\\rho \\mathbf{v}\\)\n\n\\subsubsection{Biot-Savart's Law}\n\\(\\displaystyle\\mathbf{B}=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{I}\\times\\hat{\\scriptr}}{\\scriptr^2}\\mathrm{d}s'\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{B}=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{K}\\times\\hat{\\scriptr}}{\\scriptr^2}\\mathrm{d}a'\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{B}=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{J}\\times\\hat{\\scriptr}}{\\scriptr^2}\\mathrm{d}v'\\)\\\\\\\\*\nCommon Uses of Biot-Savart's Law:\n\\begin{itemize}\n\\item Circular wire arc at center of curvature: \\(\\displaystyle B=\\frac{\\mu_0I\\theta}{4\\pi R}\\)\n\\item Circular current loop along axis: \\(\\displaystyle B=\\frac{\\mu_0I}{2}\\frac{r^2}{\\left(R^2+z^2\\right)^{3/2}}\\)\n\\end{itemize}\nBoth of these give \\(\\displaystyle B=\\frac{\\mu_0I}{2R}\\) at the center of a current loop.\nFar away from the loop (along the axis) the B-field behaves like \\(\\displaystyle B\\propto\\frac{1}{z^3}\\).\n\n\\subsubsection{Amp\\`ere's Law}\nDifferentialForm: \\(\\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{J}\\)\\\\*\nIntegral Form: \\(\\displaystyle\\oint_{\\delta S}\\mathbf{B}\\cdot\\,\\mathrm{d}\\mathbf{l}=\\mu_0 I_{enc}\\)\\\\\\\\*\nCommon Uses of Amp\\`ere's Law:\n\\begin{itemize}\n\\item Long wire: \\(\\displaystyle B=\\frac{\\mu_0I}{2\\pi r}\\)\n\\item Solenoid/Toroid: \\(\\displaystyle B=\\mu_0 n I\\) where \\(\\displaystyle n=\\frac{N_{turns}}{l}\\) for a solenoid and \\(\\displaystyle\\frac{N_{turns}}{2\\pi R}\\) for a toroid\n\\end{itemize}\n\n\\subsubsection{Magnetic Forces on Objects}\nParticle: \\(\\mathbf{F}_B=q\\mathbf{v}\\times\\mathbf{B}\\)\\\\*\nWire:  \\(\\mathbf{F}_B=I\\mathbf{L}\\times\\mathbf{B}\\) (\\(\\mathbf{L}\\) connects \\emph{endpoints} of wire)\\\\*\nThe net magnetic force acting on any closed current loop in \\emph{uniform} magnetic field is zero (\\(\\mathbf{L}=\\mathbf{0}\\)), but the torque isn't necessarily zero.\\\\*\n\\(\\vec{\\tau}=I\\mathbf{A}\\times\\mathbf{B}\\) where \\(\\mathbf{A}\\) is the area enclosed by the loop\\\\\\\\*\n\\(\\mathbf{F}=\\int I(\\mathrm{d}\\mathbf{s}\\times\\mathbf{B})\\)\\\\*\n\\(\\mathbf{F}=\\int (\\mathbf{K}\\times\\mathbf{B})\\mathrm{d}a\\)\\\\*\n\\(\\mathbf{F}=\\int (\\mathbf{J}\\times\\mathbf{B})\\mathrm{d}v\\)\\\\\\\\*\nCyclotron (angular) frequency:\n\\begin{eqnarray}\nma&=&qvB \\nonumber\\\\\nm\\omega^2R&=&q\\omega RB \\nonumber\\\\\n\\omega_{cyclotron}&=&\\frac{qB}{m} \\nonumber\n\\end{eqnarray}\nForce per length between two current carrying wires separated by a distance \\(a\\): \\(\\displaystyle\\frac{F_B}{l}=\\frac{\\mu_0I_1I_2}{2\\pi a}\\) (currents in the same direction attract while opposite currents repel)\n\n\\subsubsection{Magnetic Flux}\n\\(\\Phi_B=\\int_S\\mathbf{B}\\cdot\\,\\mathrm{d}\\mathbf{a}\\)\\\\\\\\*\n\\(\\displaystyle\\Phi_B=\\oint_{\\delta V}\\mathbf{B}\\cdot\\,\\mathrm{d}\\mathbf{a}=0\\to\\nabla\\cdot\\mathbf{B}=\\mathbf{0}\\)\\\\*\nThis last statement just means there are no magnetic monopoles, or ``magnetic charges.''\n\n\\subsubsection{Magnetic Vector Pontential}\n\\(\\nabla\\cdot\\mathbf{B}=\\mathbf{0}\\to\\mathbf{B}=\\nabla\\times\\mathbf{A}\\)\\\\*\n\\(\\nabla^2\\mathbf{A}=-\\mu_0\\mathbf{J}\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{A}=\\frac{\\mu_0}{4\\pi}\\int\\frac{I}{\\scriptr}\\mathrm{d}\\mathbf{s}'\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{A}=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{K}(\\mathbf{r}')}{\\scriptr}\\mathrm{d}a'\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{A}=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{J}(\\mathbf{r}')}{\\scriptr}\\mathrm{d}v'\\)\n\n\\subsubsection{Magnetic Dipole}\n\\(\\mathbf{m} =\\int I\\mathrm{d}\\mathbf{a}\\)\\\\\\\\*\nThe magnetic vector potential from a dipole:\\\\*\n\\(\\displaystyle\\mathbf{A}_{dipole}=\\frac{\\mu_0}{4\\pi}\\frac{\\mathbf{m}\\times\\hat{\\mathbf{r}}}{r^2}\\)\\\\\\\\*\nThe field from a dipole:\\\\*\n\\(\\displaystyle \\mathbf{B}_{dipole}=\\frac{\\mu_0}{4\\pi}\\frac{1}{r^3}\\left[3\\left(\\mathbf{m}\\cdot\\hat{\\mathbf{r}}\\right)\\hat{\\mathbf{r}}-\\mathbf{m}\\right]\\)\\\\\\\\*\nEffect of an external \\(\\mathbf{B}\\) field on a dipole:\\\\*\nForce: \\(\\mathbf{F}=\\nabla(\\mathbf{m}\\cdot\\mathbf{B})\\)\\\\*\nTorque: \\(\\vec{\\tau}=\\mathbf{m}\\times\\mathbf{B}\\)\\\\*\nPotential Energy: \\(U=-\\mathbf{m}\\cdot\\mathbf{B}\\)\n\n\\subsubsection{Dia-Para-Ferromagnetic Materials}\nThe magnetic dipole moment per unit volume is called the magnetization \\(\\mathbf{M}\\).\\\\*\n\\(\\nabla\\times\\mathbf{M}=\\mathbf{J}_{bound}\\)\\\\*\n\\(\\mathbf{M}\\times\\hat{\\mathbf{n}}=\\mathbf{K}_{bound}\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{A}(\\mathbf{r})=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\mathbf{M}\\times\\hat{\\scriptr}}{\\scriptr^2}\\mathrm{d}v'\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{H}=\\frac{1}{\\mu_0}\\mathbf{B}-\\mathbf{M}\\)\\\\\\\\*\n\\(\\nabla\\times\\mathbf{H}=\\mathbf{J}_{free}\\)\\\\*\n\\(\\displaystyle\\oint\\mathbf{H}\\cdot\\mathrm{d}\\mathbf{l}=I_{free_{enc}}\\)\\\\\\\\*\nFor Linear Materials: \\(\\mathbf{H}=\\mu\\mathbf{B}\\)\n\\begin{itemize}\n\\item Diamagnets: \\(\\mu < \\mu_0\\to\\) no unpaired electrons and field is reduced by Lenz's law acting on electron orbits\n\\item Paramagnets: \\(\\mu > \\mu_0\\to\\) has some unpaired electrons that align with applied field\n\\item Ferromagnets: \\(\\mu \\gg \\mu_0\\to\\) has many unpaired electrons and forms magnetic domains within the material\n\\end{itemize}\n\n\\subsection{Electrodynamics}\n\n\\subsubsection{Displacement Current and the Amp\\`ere-Maxwell Law}\n\\(\\displaystyle I_d=\\epsilon_0\\frac{\\mathrm{d}\\Phi_E}{\\mathrm{d}t}=\\epsilon_0\\frac{\\mathrm{d}}{\\mathrm{d}t}\\int_S\\mathbf{E}\\cdot\\,\\mathrm{d}\\mathbf{a}\\)\\\\*\n\\(\\displaystyle\\oint_{\\delta S}\\mathbf{B}\\cdot\\,\\mathrm{d}\\mathbf{l}=\\mu_0 (I+I_d)=\\mu_0I +\\mu_0\\epsilon_0\\frac{\\mathrm{d}\\Phi_E}{\\mathrm{d}t}\\)\\\\*\n\\(\\displaystyle\\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{J}+\\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\\)\n\n\\subsubsection{Lorentz Force}\n\\(\\mathbf{F}_L=q(\\mathbf{E}+\\mathbf{v}\\times\\mathbf{B})\\)\n\n\\subsubsection{Faraday's Law}\n\\(\\displaystyle{\\cal{E}}_{induced}=-\\frac{\\partial\\Phi_B}{\\partial t}\\)\\\\\\\\*\n\\(\\displaystyle\\nabla\\times\\mathbf{E}=-\\frac{\\partial\\mathbf{B}}{\\partial t}\\)\\\\\\\\*\n\\(\\displaystyle\\oint\\mathbf{E}\\cdot\\mathrm{d}\\mathbf{l}=\\frac{-\\mathrm{d}\\Phi_B}{\\mathrm{d}t}\\)\\\\\\\\*\nExample: Induced voltage in a rotating conducting bar with \\(\\vec{\\omega}\\) parallel to \\(\\mathbf{B}\\)\n\\begin{eqnarray}\n\\mathrm{d}{\\cal E}&=&Bv\\mathrm{d}r \\nonumber\\\\\n{\\cal E}&=&B\\int v\\,\\mathrm{d}r=\\omega B\\int_0^l r\\,\\mathrm{d}r \\nonumber\\\\\n{\\cal E}&=&\\frac{1}{2}\\omega Bl^2 \\nonumber\n\\end{eqnarray}\n\n\\subsubsection{Lenz's Law}\nThe induced current in a loop is in the direction that creates a magnetic field that \\emph{opposes} the change in magnetic flux through the area enclosed by the loop (the negative sign in Faraday's Law).\n\n\\subsection{Maxwell's Equations}\n\n\\subsubsection{Without Matter}\n\\begin{itemize}\n\\item \\(\\displaystyle\\nabla\\cdot\\mathbf{E}=\\frac{\\rho}{\\epsilon_0}\\)\n\\item \\(\\displaystyle\\nabla\\cdot\\mathbf{B}=\\vec{0}\\)\n\\item \\(\\displaystyle\\nabla\\times\\mathbf{E}=-\\frac{\\partial\\mathbf{B}}{\\partial t}\\)\n\\item \\(\\displaystyle\\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{J}+\\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\\)\n\\end{itemize}\n\n\\subsubsection{With Matter}\n\\begin{itemize}\n\\item \\(\\displaystyle\\nabla\\cdot\\mathbf{D}=\\rho_{free}\\)\n\\item \\(\\displaystyle\\nabla\\cdot\\mathbf{B}=\\vec{0}\\)\n\\item \\(\\displaystyle\\nabla\\times\\mathbf{E}=-\\frac{\\partial\\mathbf{B}}{\\partial t}\\)\n\\item \\(\\displaystyle\\nabla\\times\\mathbf{H}=\\mathbf{J}+\\frac{\\partial\\mathbf{D}}{\\partial t}\\)\n\\end{itemize}\n\n\\subsubsection{Conservation of Charge}\nIf you take the divergence of \\(\\displaystyle\\nabla\\times\\mathbf{B}=\\mu_0\\mathbf{J}+\\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}\\) you'll get:\\\\*\n\\(\\displaystyle 0=\\mu_0\\nabla\\cdot\\mathbf{J}+\\mu_0\\epsilon_0\\frac{\\partial}{\\partial t}\\nabla\\cdot\\mathbf{E}\\)\\\\*\nAfter substituting in \\(\\displaystyle\\nabla\\cdot\\mathbf{E}=\\frac{\\rho}{\\epsilon_0}\\), you get the differential expression for the conservation of charge:\\\\\\\\*\n\\(\\displaystyle \\nabla\\cdot\\mathbf{J}=-\\frac{\\partial\\rho}{\\partial t}\\)\n\n\\subsubsection{Boundary Conditions}\nThese are the boundary conditions for the fields in medium 1 and 2\\\\\\\\*\nGeneral Boundary Conditions:\n\\begin{itemize}\n\\item \\(D_{2}^{\\bot}-D_{1}^{\\bot}=\\sigma_{free}\\)\n\\item \\(B_{2}^{\\bot}-B_{1}^{\\bot}=0\\)\n\\item \\(\\mathbf{E}_{2}^{\\parallel}-\\mathbf{E}_{1}^{\\parallel}=\\mathbf{0}\\)\n\\item \\(\\mathbf{H}_{2}^{\\parallel}-\\mathbf{H}_{1}^{\\parallel}=\\mathbf{K}_{free}\\times\\hat{\\mathbf{n}}\\)\n\\end{itemize}\nBoundary Conditions for Linear Media:\n\\begin{itemize}\n\\item \\(\\epsilon_2E_{2}^{\\bot}-\\epsilon_1E_{1}^{\\bot}=\\sigma_{free}\\)\n\\item \\(B_{2}^{\\bot}-B_{1}^{\\bot}=0\\)\n\\item \\(\\mathbf{E}_{2}^{\\parallel}-\\mathbf{E}_{1}^{\\parallel}=\\mathbf{0}\\)\n\\item \\(\\displaystyle\\frac{1}{\\mu_2}\\mathbf{B}_{2}^{\\parallel}-\\frac{1}{\\mu_1}\\mathbf{B}_{1}^{\\parallel}=\\mathbf{K}_{free}\\times\\hat{\\mathbf{n}}\\)\n\\end{itemize}\n\nThese allow you to calculate the induced surface charge when using separation of variables: \\(\\displaystyle \\epsilon_{above}\\left(\\frac{\\partial V}{\\partial n}\\right)_{above}-\\epsilon_{below}\\left(\\frac{\\partial V}{\\partial n}\\right)_{below}=\\sigma_{free}\\)\n\n\\subsubsection{Field Energy}\nEnergy Density in Electric Field: \\(\\displaystyle u_E=\\frac{1}{2}\\epsilon_0E^2\\)\\\\*\nEnergy Density in Magnetic Field: \\(\\displaystyle u_B=\\frac{B^2}{2\\mu_0}\\)\\\\\\\\*\nTotal Energy Density in the Fields: \\(\\displaystyle u_{em}=\\frac{1}{2}\\left(\\epsilon_0E^2+\\frac{B^2}{\\mu_0}\\right)\\)\\\\\\\\*\nTotal Energy  in the Fields: \\(\\displaystyle U_{em}=\\frac{1}{2}\\int\\left(\\epsilon_0E^2+\\frac{B^2}{\\mu_0}\\right)\\mathrm{d}v\\)\n\n\\subsection{Circuits}\n\n\\subsubsection{Kirchhoff's Rules}\n\\begin{itemize}\n\\item Junction Rule: \\(\\displaystyle\\sum I_{in}=\\sum I_{out}\\)\n\\item Loop Rule: \\(\\displaystyle\\sum_{closed loop}\\Delta V=0\\)\n\\end{itemize}\n\n\\subsubsection{Resistors}\nResistance: \\(\\displaystyle R=\\rho\\frac{l}{A}\\)\\\\\\\\*\nConductivity: \\(\\displaystyle\\sigma = \\frac{1}{\\rho}\\)\\\\\\\\*\nOhm's Law: \\(\\mathbf{J}=\\sigma\\mathbf{E}\\to V=IR\\)\\\\\\\\*\n\\(\\displaystyle R_{series}=\\sum_i R_i\\)\\\\*\n\\(\\displaystyle\\frac{1}{R_{parallel}}=\\sum_i \\frac{1}{R_i}\\)\n\n\\subsubsection{Capacitors}\nCapacitance: \\(\\displaystyle C=\\frac{Q}{V}\\)\\\\*\nParallel Plate Capacitor: \\(V=E_{both plates}d=\\displaystyle\\frac{Qd}{\\epsilon_0 A} \\to C=\\frac{\\epsilon_0 A}{d}\\) where \\(A\\) is the area of one plate and \\(d\\) is the distance between the plates\\\\*\nEnergy in a Capacitor: \\(U_C=\\frac{1}{2}CV^2=\\frac{1}{2}\\frac{Q^2}{C}=\\frac{1}{2}QV\\)\\\\*\n\\(\\displaystyle C_{parallel}=\\sum_i C_i\\)\\\\*\n\\(\\displaystyle\\frac{1}{C_{series}}=\\sum_i \\frac{1}{C_i}\\)\\\\*\nCapacitor with Dielectric: \\(C=\\kappa C_0\\)\\\\*\nE-Field Inside Capacitor with Dielectric: \\(\\displaystyle\\mathbf{E}=\\frac{\\mathbf{E}_0}{\\kappa}\\to\\) \\(\\mathbf{E}<\\mathbf{E}_0\\)\n\n\\subsubsection{Inductors}\nSelf-Inductance: \\(\\displaystyle{\\cal E}_L=-\\frac{\\partial\\Phi_B}{\\partial t}=-L\\frac{\\mathrm{d} I}{\\mathrm{d} t}\\)\\\\*\nInductance: \\(\\displaystyle L=-\\frac{{\\cal E}_L}{{\\mathrm{d} I}{/\\mathrm{d} t}}\\)\\\\\\\\*\nSolenoid: \\(\\displaystyle L=\\frac{N\\Phi_B}{I}=\\frac{\\mu_0 N^2 A}{l}\\)\\\\\\\\*\nEnergy in an Inductor: \\(U=\\frac{1}{2}LI^2\\)\\\\\\\\*\nShortcut to Calculating \\(L\\): \\(\\displaystyle \\frac{1}{2}LI^2=\\frac{1}{2\\mu_0}\\int B^2\\mathrm{d}v'\\)\\\\\\\\*\nMutual Inductance: \\(\\displaystyle M=M_{12}=\\frac{N_2\\Phi_{12}}{I_1}=M_{21}=\\frac{N_1\\Phi_{21}}{I_2}\\)\\\\*\n\\(\\displaystyle{\\cal E}_1=-M\\frac{\\mathrm{d}I_2}{\\mathrm{d}t}\\) and \\(\\displaystyle{\\cal E}_2=-M\\frac{\\mathrm{d}I_1}{\\mathrm{d}t}\\)\n\n\\subsubsection{Power}\nPower \\emph{Delivered to} a Capacitor/Inductor: \\(P=IV\\)\\\\*\nPower \\emph{Dissipated by} a Resistor: \\(P=I^2R\\)\n\n\\subsubsection{DC Circuits}\n\n\\paragraph{RC Circuits:}\nTime Constant: \\(\\tau=RC\\)\\\\\\\\*\nCharging: \\(\\displaystyle{\\cal E} - \\frac{q}{C}-R\\frac{\\mathrm{d}q}{\\mathrm{d}t}=0\\)\n\\begin{itemize}\n\\item \\(\\displaystyle q(t)={\\cal E}C\\left(1-e^{-t/\\tau}\\right)\\)\n\\item \\(\\displaystyle I(t)=\\frac{{\\cal E}}{R}e^{-t/\\tau}\\)\n\\end{itemize}\nDischarging: \\(\\displaystyle \\frac{q}{C}+R\\frac{\\mathrm{d}q}{\\mathrm{d}t}=0\\)\n\\begin{itemize}\n\\item \\(\\displaystyle q(t)=q_0e^{-t/\\tau}\\)\n\\item \\(\\displaystyle I(t)=-\\frac{q_0}{RC}e^{-t/\\tau}\\)\n\\end{itemize}\n\n\\paragraph{RL Circuits:}\nTime Constant: \\(\\displaystyle\\tau=\\frac{L}{R}\\)\\\\\\\\*\nWith Driving Voltage: \\(\\displaystyle{\\cal E} - IR-L\\frac{\\mathrm{d}I}{\\mathrm{d}t}=0\\)\n\\begin{itemize}\n\\item \\(\\displaystyle I(t)=\\frac{{\\cal E}}{R}\\left(1-e^{-t/\\tau}\\right)\\)\n\\end{itemize}\nWithout Driving Voltage: \\(\\displaystyle IR+L\\frac{\\mathrm{d}I}{\\mathrm{d}t}=0\\)\n\\begin{itemize}\n\\item \\(\\displaystyle I(t)=I_0e^{-t/\\tau}\\)\n\\end{itemize}\n\n\\paragraph{LC Circuits:}\nAngular Frequency: \\(\\displaystyle\\omega_{0}=\\frac{1}{\\sqrt{LC}}\\)\\\\\\\\*\nWith Charged Capacitor: \\(\\displaystyle \\frac{q}{C}+L\\frac{\\mathrm{d}^2q}{\\mathrm{d}t^2}=0\\)\n\\begin{itemize}\n\\item \\(\\displaystyle q(t)=q_{max}\\cos(\\omega_{0}t+\\phi)\\)\n\\end{itemize}\nThis is just a SHO.\n\n\\paragraph{LRC Circuits:}\nAngular Frequency: \\(\\displaystyle\\omega_{d}=\\sqrt{\\omega_0^2-\\left(\\frac{R}{2L}\\right)^2}\\)\\\\\\\\*\nWithout Driving Voltage: \\(\\displaystyle \\frac{q}{C}+R\\frac{\\mathrm{d}q}{\\mathrm{d}t}+L\\frac{\\mathrm{d}^2q}{\\mathrm{d}t^2}=0\\)\n\\begin{itemize}\n\\item When \\(R\\) is small: \\(\\displaystyle q(t)=q_{max}e^{-Rt/2L}\\cos(\\omega_{d}t)\\)\n\\end{itemize}\nCritically damped at \\(R_c=\\frac{\\sqrt{4L}}{C}\\)\\\\*\nThis is just a damped harmonic oscillator.\n\n\\subsubsection{AC Circuits}\nDriving Voltage: \\(V(t)=V_{max}\\sin(\\omega t)\\)\\\\\\\\*\nCurrent and voltage across a resistor are in phase.\\\\*\nCurrent lags behind voltage by \\(90^{\\circ}\\) in an inductor.\\\\*\nCurrent leads voltage by \\(90^{\\circ}\\) in a capacitor.\\\\\\\\*\nTransformer: \\(\\displaystyle V_2=\\frac{N_2}{N_1}V_1\\)\\\\*\n\\(\\displaystyle P_1=P_2\\to R_{eq}=\\left(\\frac{N_1}{N_2}\\right)^2R_L\\)\\\\\\\\*\nReactance:\n\\begin{itemize}\n\\item Inductive reactance: \\(X_L=\\omega L\\)\n\\item Capacitive reactance: \\(\\displaystyle X_C=\\frac{1}{\\omega C}\\)\n\\end{itemize}\n\\paragraph{LRC Circuits:}\nResonant Angular Frequency: \\(\\displaystyle\\omega_{0}=\\frac{1}{\\sqrt{LC}}\\)\\\\\\\\*\nDriving Current: \\(I(t)=I_{max}\\sin(\\omega t-\\phi)\\)\\\\*\n\\(\\phi =\\mathrm{tan}^{-1}\\left(\\frac{X_L-X_C}{R}\\right)\\)\\\\\\\\*\nVoltage Across\n\\begin{itemize}\n\\item R: \\(v_R=I_{max}R\\sin(\\omega t)\\)\n\\item L: \\(v_L=I_{max}X_L\\sin\\left(\\omega t-\\frac{\\pi}{2}\\right)\\)\n\\item C: \\(v_C=I_{max}X_C\\sin\\left(\\omega t+\\frac{\\pi}{2}\\right)\\)\n\\end{itemize}\nImpedance: \\(Z=\\sqrt{R^2+(X_L-X_C)^2}\\)\\\\*\n\\(V_{max}=I_{max}Z\\)\\\\\\\\*\nImpedance Matching: \\(Z_{source}=Z_{load}^*\\) for maximum power transfer\\\\\\\\*\nThis is just a forced-damped harmonic oscillator.\n\n\\subsection{Electromagnetic Waves}\n\n\\subsubsection{Wave Equations}\n\\(\\displaystyle\\frac{\\partial^2E}{\\partial x^2}=\\frac{1}{c^2}\\frac{\\partial^2E}{\\partial t^2}\\)\\\\\\\\*\n\\(\\displaystyle\\frac{\\partial^2B}{\\partial x^2}=\\frac{1}{c^2}\\frac{\\partial^2B}{\\partial t^2}\\)\\\\*\n\\(\\displaystyle c=\\frac{1}{\\sqrt{\\mu_0\\epsilon_0}}\\)\n\n\\subsubsection{Poynting Theorem}\nPoynting Vector: \\(\\mathbf{S}=\\frac{1}{\\mu_0}\\mathbf{E}\\times\\mathbf{B}\\)\\\\*\nUnits are is \\(W/m^2\\) (same as intensity)\\\\*\nPoints in the direction of wave propagation (for transverse waves).\\\\\\\\*\nPoynting Theorem (\\(W\\) is work): \\(\\displaystyle \\frac{\\mathrm{d}W}{\\mathrm{d}t}=-\\frac{\\mathrm{d}U_{em}}{\\mathrm{d}t}-\\oint_{\\delta V}\\mathbf{S}\\cdot\\mathrm{d}\\mathbf{a}\\)\\\\\\\\*\nFor plane waves: \\(\\displaystyle I=S_{av}=\\frac{1}{2}\\epsilon_0E_{max}^2=\\frac{B_{max}^2}{2\\mu_0}\\)\n\n\\subsubsection{Radiation Pressure}\nPerfect Absorber: \\(\\displaystyle P_A=\\frac{S\\cos^2(\\theta)}{c}\\)\\\\*\nPerfect Reflector: \\(\\displaystyle P_R=2P_A=\\frac{2S\\cos^2(\\theta)}{c}\\)\\\\*\n\\(\\theta\\) is measured from the normal of the surface.\n\n\\subsubsection{Power Radiated from an Accelerating Charge}\nLarmor Formula: \\(\\displaystyle P=\\frac{q^2a^2}{6\\pi\\epsilon_0c^3}=\\frac{\\mu_0q^2a^2}{6\\pi c}\\)\n\n\\subsubsection{Radiation Reaction Force}\n\\(\\displaystyle\\mathbf{F}_{rad}=\\frac{\\mu_0q^2}{6\\pi c}\\dot{\\mathbf{a}}\\)\n\n\\subsubsection{Power Radiated from an Oscillating Charge}\n\\begin{itemize}\n\\item Never radiates in the direction of its oscillation axis\n\\item Polarization is parallel to the oscillation axis\n\\end{itemize}\nIntensity: \\(\\displaystyle I\\propto\\frac{\\sin^2(\\theta)}{r^2}\\)\\\\*\n\\(\\theta\\) is measured from the axis of oscillation.\n\n\\subsubsection{Dipole Radiation}\n\\(\\displaystyle\\mathbf{B}=\\frac{-\\mu_0}{4\\pi cr}[\\hat{\\mathbf{r}}\\times\\ddot{\\mathbf{p}}]\\)\\\\\\\\*\n\\(\\displaystyle\\mathbf{E}=-c\\hat{\\mathbf{r}}\\times\\mathbf{B}\\)\\\\\\\\*\nPower radiated from an electric dipole: \\(\\displaystyle P_p=\\frac{\\mu_0\\ddot{p}^2}{6\\pi c}\\)\\\\\\\\*\nPower radiated from a magnetic dipole: \\(\\displaystyle P_m=\\frac{\\mu_0\\ddot{m}^2}{6\\pi c^3}\\)\n\n\\subsubsection{Cherenkov Radiation}\nRadiation emitted when a charged particle passes through an insulator at a speed greater than the speed of light in that material\\\\*\nIt is due to the charged particles polarizing the molecules of the material, which then fall back rapidly to their ground state, emitting radiation in the process.\nThe spectrum is continuous, and its intensity is proportional to the frequency of the photon.\nThere is also a high frequency cutoff.\n\n\\newpage\n\\section{Optics \\& Wave Phenomena}\nThis section on optics and waves covers material that is taught in a freshman level physics course on electricity and magnetism.\nThe PGRE requires very little advanced knowledge on this topic.\nHowever, this is an important section to study thoroughly as there are many optics questions on the test that are easily solvable in less than sixty seconds.\nKnow how to rapidly draw ray diagrams and find the focal point and image for mirrors and lenses.\nThere is typically as least one question over telescopes as well.\nFor wave phenomena, always keep in mind a wave on a string as it is conceptually similar to reflection and refraction.\n\n\\subsection{General Information}\n\n\\subsubsection{Group and Phase Velocity}\n\\(\\displaystyle v_{phase}=\\frac{\\omega}{k}\\)\\\\\\\\*\n\\(\\displaystyle v_{group}=\\frac{\\mathrm{d}\\omega}{\\mathrm{d}k}\\)\n\n\\subsubsection{Huygen's Principle}\nAll points on a given wave front are taken as point sources for the production of spherical secondary waves, called wavelets, which propagate outward through a medium with speeds characteristic of waves in that medium.\nAfter some time interval has passed, the new position of the wave front is the surface tangent to the wavelets.\n\n\\subsubsection{Fermat's Principle}\nWhen a light ray travels between any two points, its path is the one that requires the smallest time interval.\n\n\\subsubsection{Images}\nA real image is formed when light rays pass through and diverge from the image point.\\\\*\nA virtual image is formed when the light rays \\emph{do not} pass through the image point but only appear to diverge from that point.\\\\\\\\*\nThis equation is useful for both \\emph{thin} lenses and mirrors.\\\\\\\\*\n\\(\\displaystyle \\frac{1}{s_o}+\\frac{1}{s_i}=\\frac{1}{f}\\) where  \\(s_i\\) is the distance from the image to the reflecting/refracting surface, \\(s_o\\) is the distance from the object to the reflecting/refracting surface, and \\(f\\) is the focal length of the lenses/mirror.\n\n\\subsubsection{Magnification}\nLateral Magnification: \\(\\displaystyle M=\\frac{h_{i}}{h_{o}}=-\\frac{s_{i}}{s_{o}}\\) where \\(h_i\\) is the image height and \\(h_o\\) is the object height.\\\\\\\\*\nAngular Magnification: \\(\\displaystyle m=\\frac{\\theta}{\\theta_0}\\) where \\(\\theta_0\\) is defined by \\(\\displaystyle\\tan(\\theta_0)=\\frac{h_o}{.25m}\\) and \\(\\theta\\) is defined by \\(\\displaystyle\\tan(\\theta)=\\frac{h_i}{s_i}\\)\n\n\\subsubsection{Telescope}\nA refracting telescope is an array of two converging lenses placed far enough apart so their focal points are at the same location.\nThe first lens is a weak ``objective'' lens while the second lens is a powerful ``eyepiece'' lens.\nThe total magnification of this array is \\(\\displaystyle m=-\\frac{f_o}{f_e}\\) where \\(f_o\\) is the focal length of the objective lens and \\(f_e\\) is the focal length of the eyepiece.\n\n\\subsubsection{Aberrations}\nSpherical: results from focal point not being the same for rays incident at different positions (affects both mirrors and lenses)\\\\*\nChromatic: results from the dispersion of light within lenses causing different focal points for different wavelengths of light (only affects lenses)\n\n\\subsection{Reflection}\nSpecular reflection is due to a relatively smooth surface (compared to the wavelength of light).\nThis is the type of reflection from an ideal mirror (typically this is the type of reflection is simply called reflection).\\\\*\nDiffuse reflection is due to a relatively rough surface and causes material to scatter light in all directions.\\\\\\\\*\nRetroreflector: A reflector that ``always'' reflects light back to its source. Examples shapes are tiny refractive spheres and the ``inside corner'' of a reflective cube.\\\\\\\\*\nIn general for mirrors: \\(\\displaystyle f=\\frac{R}{2}\\)\n\n\\subsubsection{Flat Mirrors}\n\\begin{center}\n\\includegraphics[scale=0.6]{images/PGRE_Figures_3p2p1_Flat_Mirror.png}\n\\end{center}\n\\(R=\\infty\\)\n\\begin{center}\n  \\begin{tabular}{ c | c  }\n    Object Placement & Image \\\\ \\hline%\\cline{2-2}\n    \\multirow{3}{*}{ anywhere} & virtual \\\\\n    & \\(M=1\\) \\\\\n    & \\(s_o=-s_i\\) \\\\\n    \\hline\n  \\end{tabular}\n\\end{center}\nTwo \\(\\perp\\) flat mirrors produce three virtual images (practice drawing the ray diagram).\n\n\\subsubsection{Concave Mirrors}\n\\begin{center}\n\\includegraphics[scale=0.6]{images/PGRE_Figures_3p2p2_Concave_Mirror.png}\n\\end{center}\nUsing the convention of this document: \\(R>0\\)\n\\begin{center}\n  \\begin{tabular}{ c | c  }\n    Object Placement & Image \\\\ \\hline%\\cline{2-2}\n    \\multirow{3}{*}{ \\(s_o<f\\)} & virtual \\\\\n    & upright \\\\\n    & \\(M>1\\) \\\\ \\hline\n    \\(s_o=f\\) & no image \\\\ \\hline\n    \\multirow{2}{*}{ \\(f<s_o<R\\)} & real \\\\\n    & \\(M<-1\\) \\\\ \\hline\n    \\multirow{2}{*}{  \\(s_o=R\\)} & real \\\\\n    & \\(M=-1\\) \\\\ \\hline\n     \\multirow{2}{*}{  \\(s_o>R\\)} & real \\\\\n    & \\(-1<M<0\\) \\\\\n    \\hline\n  \\end{tabular}\n\\end{center}\n\n\\subsubsection{Convex Mirrors}\n\\begin{center}\n\\includegraphics[scale=0.6]{images/PGRE_Figures_3p2p3_Convex_Mirror.png}\n\\end{center}\nUsing the convention of this document: \\(R<0\\)\n\\begin{center}\n  \\begin{tabular}{ c | c  }\n    Object Placement & Image \\\\ \\hline%\\cline{2-2}\n    \\multirow{2}{*}{ anywhere} & virtual \\\\\n    & \\(0<M<1\\) \\\\\n    \\hline\n  \\end{tabular}\n\\end{center}\n\n\\subsection{Refraction}\nIndex of Refraction: \\(\\displaystyle n=\\frac{c}{v}\\) where \\(v\\) is the speed of light in the material (\\(n>1\\) always)\\\\*\nWhen light travels from one medium to another, the frequency and energy stay constant (but speed and wavelength change).\\\\*\nDispersion: \\(n=n(\\lambda)\\) (the index of refraction depends on the wavelength of light)\\\\\\\\*\nImages from Refraction: \\(\\displaystyle \\frac{n_1}{s_o}+\\frac{n_2}{s_i}=\\frac{n_2-n_1}{R}\\) (single surface)\\\\\\\\*\nThin Lens Equation: \\(\\displaystyle \\frac{1}{f}=(n-1)\\left(\\frac{1}{R_1}-\\frac{1}{R_2}\\right)\\)\\\\\\\\*\nLensmaker's Equation: \\(\\displaystyle \\frac{1}{f}=(n-1)\\left(\\frac{1}{R_1}-\\frac{1}{R_2}+\\frac{(n-1)d}{nR_1R_2}\\right)\\)\\\\\\\\*\nSign convention: \\(R\\) and \\(s_i\\) are negative if measured from the same side as the object and are positive if measured from the opposite side as the object (opposite of mirrors).\\\\*\nThe \\(d\\) in the Lensmaker's equation is the thickness of the lens. For converging lenses it is the thickest width and for diverging lenses it is the smallest width.\\\\\\\\*\nFor a combination of lenses use the image of the first at the object of the second.\\\\*\nFor thin lenses in contact: \\(\\displaystyle\\frac{1}{f}=\\frac{1}{f_1}+\\frac{1}{f_2}\\)\n\n\\subsubsection{Snell's Law}\n\\(n_1\\sin(\\theta_1)=n_2\\sin(\\theta_2)\\)\\\\\\\\*\nCritical Angle: \\(\\displaystyle\\theta_2=90^{\\circ}\\to \\sin(\\theta_c)=\\frac{n_2}{n_1}\\)\n\n\\subsubsection{Flat Refracting Surface}\n\\(\\displaystyle R=\\infty\\to s_i=-\\frac{n_2}{n_1}s_o\\)\n\n\\subsubsection{Converging Lenses}\n\\(f>0\\)\\\\*\nA converging lens is thicker in the middle and thin at the ends.\n\n\\subsubsection{Diverging Lenses}\n\\(f<0\\)\\\\*\nA diverging lens is thinner in the middle and thick at the ends.\n\n\\subsection{Interference \\& Diffraction}\n\n\\subsubsection{ Double-Slit Interference}\nSources must be coherent and monochromatic\\\\*\nScreen must be far from the slits\\\\*\nBright Fringes: \\(d\\sin(\\theta_{bright})=m\\lambda\\), \\(m=0,\\pm1,\\pm2,\\ldots\\)\\\\*\nDark Fringes: \\(d\\sin(\\theta_{dark})=\\left(m+\\frac{1}{2}\\right)\\lambda\\)\\\\\\\\*\nTo get the position on the screen use \\(\\displaystyle\\sin(\\theta)\\approx\\frac{y}{L}\\)\n\n\\subsubsection{Thin Films}\nAn electromagnetic wave undergoes a phase change of \\(\\pi\\) upon reflection from a medium that has a higher index of refraction than the one in which the wave is traveling (wave on a string attached to a wall).\\\\\\\\*\nThis is for near normal incidence. In what follows \\(m=0,1,2,\\ldots\\)\\\\*\nCase: \\(n_1<n_{film}<n_3\\)\\\\*\nConstructive Interference when: \\(2n_{film}t=m\\lambda\\)\\\\*\nDestructive Interference when: \\(2n_{film}t=\\left(m+\\frac{1}{2}\\right)\\lambda\\)\\\\*\nCase: \\(n_1<n_{film}>n_3\\)\\\\*\nConstructive Interference when: \\(2n_{film}t=\\left(m+\\frac{1}{2}\\right)\\lambda\\)\\\\*\nDestructive Interference when: \\(2n_{film}t=m\\lambda\\)\\\\*\n\n\\subsubsection{Single-Slit Diffraction}\nScreen must be far from the slit\\\\*\nDark Fringes: \\(a\\sin(\\theta_{dark})=m\\lambda\\), \\(m=\\pm1,\\pm2,\\pm3,\\ldots\\)\n\n\\subsubsection{Rayleigh Criterion}\nThis comes from the first order diffraction minimum.\\\\*\nFor Slit: \\(\\displaystyle\\sin(\\theta)=\\frac{\\lambda}{d}\\)\\\\*\nFor Circular Aperture:  \\(\\displaystyle\\sin(\\theta)=1.22\\frac{\\lambda}{d}\\)\n\n\\subsubsection{Diffraction (Interference) Grating}\nSame as interference.\\\\*\nBright Fringes: \\(d\\sin(\\theta_{bright})=m\\lambda\\), \\(m=0,\\pm1,\\pm2,\\ldots\\)\n\n\\subsubsection{Bragg's Law}\nThis works for massive particles and photons (both have wave-like properties).\\\\*\nBright Fringes: \\(2d\\sin(\\theta_{bright})=m\\lambda\\), \\(m=1,2,3,\\ldots\\)\n\n\\subsection{Polarization}\n\n\\subsubsection{Polarizers}\nIf unpolarized light passes through a polarizer, the beam's intensity is halved.\nIf (plane) polarized light passes through a polarizer at a relative angle \\(\\phi-\\theta\\), the intensity is given by \\(I_2=I_1\\cos^2(\\phi-\\theta)\\)\n\n\\subsubsection{Brewster's Law}\n\\begin{center}\n\\includegraphics[scale=0.6]{images/PGRE_Figures_3p5p2_Brewsters_Law.png}\n\\end{center}\nA reflected beam can be completely polarized if \\(\\tan(\\theta_p)=n\\)\n\n\\subsection{Rayleigh Scattering}\nThis type of scattering occurs when light elastically scatters off particles much smaller than the wavelength of the light.\nQuantitatively, the intensity of the light that is scatter is related the wavelength of light by \\(\\displaystyle I\\propto\\frac{1}{\\lambda^4}\\).\nThis is the reason the sky looks blue and the sun appears yellow through Earth's atmosphere.\n", "meta": {"hexsha": "dd565f4dbbed150f0efaef9b7b24de6b223bbc68", "size": 33432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/em.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/em.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/em.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": 57.1487179487, "max_line_length": 299, "alphanum_fraction": 0.6964883944, "num_tokens": 11615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6228274099628194}}
{"text": "%% Dominic's material\n%\\chapter{Bootstrap}\n%WORK fuse with earlier material\n%\\comment{\n\n\\section{Empirical distribution function}\n\\work\n\n%\\subsection{\\define} \nLet $x_1,\\ldots,x_n$ be a random sample of size $n$. The {\\it empirical distribution function} (EDF) of $x_1,\\ldots,x_n$ is, for any real number $t$:\n\\begin{equation}\n\\hat{F}_n(t)=\\frac{|\\{x_i:x_i\\leq t\\}|}{n}=\\frac{1}{n}\\sum^n_{i=1}I_{(-\\infty,t]}(x_i),\n\\end{equation}\n\ni.e. the proportion of sample points that are less than or equal to $t$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nNote that the EDF takes values between 0 and 1. Note also that if the sample comes from a continuous distribution, then the EDF takes a step of $1/n$ at each sample value; if the sample comes from a discrete distribution, the EDF may take steps that are multiples of $1/n$ at distinct sample values.\n\n%\\subsection{\\define}\nLet $x_1^*,\\ldots,x_n^*$ be the distinct points in $x_1,\\ldots,x_n$, so that $m \\leq n$, and let:\n\\begin{equation}\nc_=|\\{x_i:x_i=x_j^* \\}|=\\sum^n_{i=1}I_{(x_j^*)}(x_i),\n\\end{equation}\ni.e. $c_j$ is the number of sample values that are equal to $x^*_j$. The EDF can also be regarded as a discrete distribution that assigns a probability mass of $1/n$ to each of the observations, $x_1,\\ldots,x_n$, i.e. with an {\\it empirical mass function} (EMF):\n\\begin{equation}\n\\hat{f}_n(x)=\\frac{1}{n}\\sum^m_{j=1}c_jI_{(x^*_j)}(x)=\\begin{array}{l}\nc_j/n,\\textrm{    if }x=x^*_j,\\\\0,\\textrm{    otherwise.}\\\\\n\\end{array}\n\\end{equation}\n \nIf the sample values are continuous, then $m = n$ and $c_1=\\ldots=c_n=1$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{example}\n{\\it Continuous data.}\nSuppose the observed values of 10 continuous random variables, arranged in increasing order, are:\n$$\\begin{array}{ccccc}\n 1.5937     &   1.4410 &       1.3362&        0.6918 &      0.2944\\\\\n0.5711\t   &    0.7143&        0.8580&        1.2540  &      1.6236\\\\\n\\end{array}$$\n\n%\\includegraphics\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{example}\n\n\\begin{example}\n{\\it Discrete data.}\nSuppose the observed values of 10 discrete random variables, arranged in increasing order, are\n$$\\begin{array}{cccccccccc}\n1 &    2&     2&     2&     2  &   2&     3&     4  &   5 &    5\n\\end{array}$$\n%\\includegraphics\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{example}\n\nThe EDF is an estimator for the distribution function and can therefore be used as a model for the distribution function. The EDF is a {\\it nonparametric} model because its parameters are the sample points, $x_1,\\ldots,x_n$, and so the number of parameters increases as the sample size increases. The following two results show why the EDF is a good estimator for the distribution function.\n\n\\begin{prop}\nFor any real number $t$:\n\\begin{equation}\nE[\\hat{F}_n(t)]=F(t),\n\\end{equation}\nand:\n\\begin{equation}\nVar[\\hat{F}_n(t)]=\\frac{F(t)[1-F(t)]}{n},\n\\end{equation}\n\nand therefore $\\hat{F}_n(t)$ is an unbiased and consistent estimator of $F(t)$.\n\n\\begin{proof}\nConsider a fixed real number $t$. By definition:\n$$\\hat{F}_n(t)=\\frac{1}{n}\\sum^n_{i=1}I_{(-\\infty,t]}(x_i).$$\n\nThe result follows by noting that $I_{(-\\infty,t]}(x_i)$ is a Bernoulli random variable with parameter (\\textquotedblleft success\" probability):\n$$P[I_{(\\infty,t]}(x_i)=1]=P(x_i\\leq t)=F(t),$$\nsince $x_i$ has distribution function $F$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}[Glivenko-Cantelli theorem]\nFor any real number $t$, $\\hat{F}_n(t)$ converges almost certainly (i.e. with a probability of 1) and uniformly to $F(t)$, i.e.:\n\\begin{equation}\nP(\\lim_{n\\rightarrow\\infty}\\sup_t|\\hat{F}_n(t)-F(t)|=0)=1.\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{prop}\n\nThe Glivenko-Cantelli theorem says that the largest absolute difference between $\\hat{F}_x$ and $F$ converges to 0 as $n$ goes to infinity, with a probability of 1.\n\nThe next result allows us to construct a confidence band for the EDF.\n\n\\begin{prop}[Dvoretzky-Kiefer-Wolfowitz inequality]\nFor any  $\\epsilon > 0$:\n\\begin{equation}\nP(\\sup_t|\\hat{F}_n(t)-F(t)|>\\epsilon)\\leq 2 \\exp(-2n\\epsilon^2).\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{prop}\n\nFor $\\alpha\\in (0, 1), a (1-\\alpha)$ confidence band for $F$ should contain $F$ with probability of at least $(1-\\alpha)$. In other words, the probability of $F$ being outside the band is at most $\\alpha$. Hence, the bound in the Dvoretzky-Kiefer-Wolfowitz inequality should be $\\alpha$:\n\\begin{equation}\n2\\exp(-2n\\epsilon^2)=\\alpha\\Leftrightarrow \\epsilon=\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})},\n\\end{equation}\ni.e.:\n$$P(\\sup_t|\\hat{F}_n(t)-F(t)|>\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})})\\leq\\alpha,$$\nor, for all $t$:\n$$P(\\max\\{\\hat{F}_n(t)-\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})},0\\}\\leq F(t)\\leq\\min\\{\\hat{F}_n(t)+\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})},1\\}).$$\nTherefore, a $(1-\\alpha )$ confidence band for $F$ is:\n\\begin{equation}\n[\\max\\{\\hat{F}_n(t)-\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})},0\\},\\min\\{ \\hat{F}_n(t)+\\sqrt{\\frac{1}{2n}\\ln(\\frac{2}{\\alpha})} \\}].\n\\end{equation}\n\n\\begin{example}\nReferring to Example 4.1.3 where $n = 10$, a 0.95 confidence band for $F$ is given by:\n\\begin{displaymath}\\begin{split}\n&[\\max\\{\\hat{F}_10(t)-\\sqrt{\\frac{\\ln 40}{20}},0\\},\\min\\{\\hat{F}_10(t)+\\sqrt{\\frac{\\ln 40}{20}}\\}]\\\\\n=&[\\max\\{\\hat{F}_10(t)-0.4295,0\\},\\min\\{\\hat{F}_10(t)+0.4295\\}]\\\\\n\\end{split}\\end{displaymath}\nThe function edfplot, which is available from the course web-page, produced the figure below:\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{example}\n\n\\section{Nonparametric bootstrap}\n\\work\nLet $x_1,\\ldots,x_n$ be a random sample and suppose that we wish to estimate an unknown quantity, $\\theta$, using an estimator $\\hat{\\theta}$ that is based on $x_1,\\ldots,x_n$. The performance of $\\hat{\\theta}$ as an estimator for $\\theta$ can be assessed by its {\\it bias, variance} and {\\it mean squared error}.\n\n%\\subsection{{\\it Definitions}}\n\\begin{asparaenum}[(a)]\n\\item The {\\it bias} of $\\hat{\\theta}$ is:\n\\begin{equation}\nBias(\\hat{\\theta})=E(\\hat{\\theta})-\\theta.\n\\end{equation}\n\n\\item The {\\it variance} of $\\hat{\\theta}$ is:\n\\begin{equation}\nVar(\\hat{\\theta})=E[(\\hat{\\theta}-E(\\hat{\\theta}))^2]=E(\\hat{\\theta}^2)-E(\\hat{\\theta})^2.\n\\end{equation}\n\n\n\\item The {\\it mean squared error (MSE)} of $\\hat{\\theta}$ is:\n\\begin{equation}\nMSE(\\hat{\\theta})=E[(\\hat{\\theta}-\\theta)^2]=Var(\\hat{\\theta})+Bias(\\hat{\\theta})^2.\n\\end{equation}\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\nWhen the distribution of $x_1,\\ldots,x_n$ is known, one way to estimate the MSE of $\\hat{\\theta}$ is to use Monte Carlo simulation to generate $N$ new random samples, each of size $n$, from which $N$ new estimates of $\\theta$ can be obtained:\n\\begin{displaymath}\n\\begin{split}\n\\textrm{original sample :}\\{x_1,\\ldots,x_n\\}&\\rightarrow\\hat{\\theta}\\\\\n\\textrm{generated samples :}\\{x_{1,1},\\ldots&,x_{1,n}\\}\\rightarrow\\hat{\\theta}_1\\\\\nM&\\\\\n\\{x_{N,1},\\ldots&,x_{N,n}\\}\\rightarrow\\hat{\\theta}_N.\\\\\n\\end{split}\n\\end{displaymath}\nHere, $x_{j,i}$ denotes the $i^{\\textrm{th}}$ value in the $j^{\\textrm{th}}$ sample. An estimate of $MSE(\\hat{\\theta})$ is given by:\n\\begin{equation}\nMES(\\hat{\\theta})\\approx\\frac{1}{N}\\sum^N_{j=1}(\\hat{\\theta}_j-\\hat{\\theta})^2.\n\\end{equation}\n\nFurthermore, if $N$ is large, an approximate $(1-\\alpha)$ confidence interval for $\\theta$ is given by $(\\hat{\\theta}_{(\\lceil N\\alpha/2\\rceil)},\\hat{\\theta}_{(\\lceil N(1-\\alpha/2)\\rceil)})$. For example, if $N = 1000$, then an approximate 0.95 confidence interval is $(\\hat{\\theta}_{(25)},\\hat{\\theta}_{(975)})$.\n\nIf the distribution of $x_1,\\ldots,x_n$ is unknown, the idea behind the {\\it nonparametric bootstrap} is to use the EDF as an estimate of $F$, and then perform Monte Carlo simulation with $\\hat{F}_n$ to estimate the MSE and to get approximate confidence intervals.\n\n\\subsection{Bootstrap estimates of bias, variance and mean squared error}\n\\work\nRecall that the EDF can be regarded as a discrete distribution that assigns a probability mass of $1/n$ to each of the observations, $x_1,\\ldots,x_n$. Thus, using $\\hat{F}_n$ as an estimate of $F$, a random sample can be generated from $\\hat{F}_n$ by {\\it randomly sampling with replacement} from $x_1,\\ldots,x_n$. A random sample of size n obtained in this way is called a {\\it bootstrap sample}. The MSE of an estimator $\\hat{\\theta}$ can be obtained as follows:\n\\begin{asparaenum}[(a)]\n\\item Compute $\\hat{\\theta}$ using $x_1,\\ldots,x_n$.\n\n\\item Obtain $N$ bootstrap samples, each of size $n$, by randomly sampling with replacement from $x_1,\\ldots,x_n$: $\\{x_{1,1},\\ldots,x_{1,n}\\},\\{x_{2,1},\\ldots,x_{2,n}\\},\\ldots,\\{x_{N,1},\\ldots,x_{N,n}\\}$.\n\n\\item\tFor each bootstrap sample, compute the {\\it bootstrap estimate} of $\\theta$:\n\\begin{displaymath}\n\\begin{split}\n\\{x_{1,1},\\ldots&,x_{1,n}\\}\\rightarrow\\hat{\\theta}_1\\\\\nM&\\\\\n\\{x_{N,1},\\ldots&,x_{N,n}\\}\\rightarrow\\hat{\\theta}_N.\\\\\n\\end{split}\n\\end{displaymath}\n  \n\\item\tCompute the mean of the bootstrap estimates:\n\\begin{equation}\n\\bar{\\hat{\\theta}}=\\frac{1}{N}\\sum^N_{j=1}\\hat{\\theta}_j.\n\\end{equation}\n\\item\tEstimate the bias, variance and MSE by:\n\n\\begin{equation}\nBias(\\hat{\\theta})\\approx \\bar{\\hat{\\theta}}-\\hat{\\theta},\n\\end{equation}\n\\begin{equation}\nVar(\\hat{\\theta})\\approx \\frac{1}{N}\\sum^N_{j=1}(\\hat{\\theta}_j-\\bar{\\hat{\\theta}})^2,\nMSE(\\hat{\\theta})\\approx \\frac{1}{N}\\sum^N_{j=1}(\\hat{\\theta}_j-\\bar{\\hat{\\theta}})^2.\n\\end{equation}\n\n\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nThe table below contains the number, rounded to the nearest thousand, of open-close cycles of 20 door latches before they fail. Find the bias, variance and MSE of the sample mean.\n\n\\begin{table}[h]\n%\\caption{Number of open-close cycles until latch failure (thousands).}\n$$\\begin{array}{|cccccccccc|}\n\\multicolumn{10}{|c|}{\\textrm{Sample mean} = 38.65}\\\\\\hline\n7\t&11&\t15&\t16&\t20&\t22&\t24&\t25&\t29&\t33\\\\\n34\t&37\t&41\t&42\t&49\t&57\t&66\t&71\t&84\t&90\\\\\\hline\n\\end{array}$$\n\\end{table}\n\n\\begin{table}[h]\n%\\caption{Bootstrap samples and sample means.}\n$$\\begin{array}{|c|cccccccccc|c|}\n\\multicolumn{1}{|c|}{j}&\\multicolumn{10}{|c|}{j^{\\textrm{th}} \\textrm{bootstrap sample}} &\\multicolumn{1}{|c|}{ \\hat{\\theta}_j}\\\\ \\hline\n1\t&22 & 57 & 42&  16 & 24 & 11 & 20&   7 & 41&  90&\\\\\n&90  &16 & 66 & 25 & 90 & 66 & 25&  24 & 84 & 66\t&44.1\\\\\n&&&&&&&&&&&\\\\\t\t\n2\t&90 & 37 & 15 & 84 & 29 & 57  &57 & 57&  11 & 49&\\\\\n&41&  57 & 84  &71 & 37 & 20 & 29&  84&   7 & 15\t&46.6\\\\\n\t\t&&&&&&&&&&&\\\\\t\n3\t&49 & 84&  29 & 41 & 57 & 11 & 49 & 42  &90 & 34&\\\\\n&71&  33&  41 & 84 & 49 & 66 & 20 & 20 & 29 & 15&\t45.7\\\\\n&&&&&&&&&&&\\\\\t\nM&&&&&&M&&&&&M\\\\\t\n&&&&&&&&&&&\\\\\\hline\n\\end{array}$$\n\\end{table}\n\n%\\Matlab code:\n\\begin{VrbM}\nx = load('latch.txt') % load data from text file and store in x\nn = length(x); % determine number of data values\nN = 100000; % number of bootstrap samples\nnN = n * N;\nxmean = mean(x) % mean of original data\nxboot = randsample(x,nN,true); % sample with replacement nN values from x\nxboot = reshape(xboot,n,N); % organise resampled values into N columns of n\n                                              % values each so that each column is a bootstrap\n                                              % sample of size n\nxbootmean = mean(xboot); % means of bootstrap samples\nbmean = mean(xbootmean); % mean of bootstrap means\nbias = bmean - xmean\nvariance = mean((xbootmean - bmean).^2)\nmse = variance + bias * bias\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nxmean = 38.6500\nbias = 0.0308\nvariance = 27.3295\nmse = 27.3304\n\\end{VrbM}\n %\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Percentile interval} \n\\work\nLet $\\hat{\\theta}_1,\\ldots,\\hat{\\theta}_N$ be the bootstrap estimates of $\\theta$ from $N$ bootstrap samples. An approximate $1-\\alpha$ confidence interval for $\\theta$, known as a $1-\\alpha$ percentile interval, is given by $(\\hat{\\theta}_{(\\lceil N\\alpha/2\\rceil)},\\hat{\\theta}_{(\\lceil N(1-\\alpha/2)\\rceil)})$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\n The sodium contents of single servings from 40 packages of a food product are measured and given in the table below. Find a 0.95 percentile interval for the median amount of sodium in a single serving of this food product.\n\\begin{table}\n%\\caption\n$$\\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|}\n\\multicolumn{11}{|c|}{\\textrm{ \\small{Sodium contents (mg) of single servings from 40 packages of a food product.}}}\\\\\n\\hline\ni\t&1&\t2\t&3&\t4\t&5&\t6&\t7&\t8&\t9&\t10\\\\\nx_{(i)}\t&72.1&\t72.8\t&72.9\t&73.3&\t73.3\t&73.3&\t73.9\t&74.0\t&74.2&74.2\\\\\n\\hline\n\\multicolumn{11}{|c|}{ \\textrm{ }}\\\\\\hline\ni\t&11\t&12\t&13\t&14\t&15\t&16\t&17\t&18\t&19\t&20\\\\\nx_{(i)}\t&\t74.3\t&74.6\t&74.7\t&75.0\t&75.1\t&75.1\t&75.2\t&75.3\t&75.3\t&75.3\\\\\\hline\n\\multicolumn{11}{|c|}{ \\textrm{ }}\\\\\\hline\ni\t&21\t&22\t&23\t&24\t&25\t&26\t&27&28\t&29\t&30\\\\\nx_{(i)}\t\t&75.4&\t76.1\t&76.5\t&76.5\t&76.6\t&76.9&\t77.1\t&77.2&\t77.4&77.4\\\\\\hline\n\\multicolumn{11}{|c|}{\\textrm{ } }\\\\\\hline\ni\t&31\t&32\t&33\t&34\t&35\t&36\t&37\t&38\t&39\t&40\\\\\nx_{(i)}\t\t&77.7&\t78.0\t&78.3&\t78.6\t&78.8\t&78.9\t&79.7\t&80.3&\t80.5\t&81.0\\\\\\hline\n\\end{array}$$\n\\end{table}\n\n\\Matlab code:\n\\begin{VrbM}\nx = load('sodium.txt'); % load data from text file and store in x\nn = length(x); % determine number of data values\nN = 100000; % number of bootstrap samples\nnN = n * N;\nalpha = 0.05;\nalpha2 = alpha / 2;\nalpha21 = 1 - alpha2;\nxmed = median(x) % median of original data\nxboot = randsample(x,nN,true); % sample with replacement nN values from x\nxboot = reshape(xboot,n,N); % organise resampled values into N columns of n\n                                              % values each so that each column is a bootstrap\n                                              % 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(ceil(N*alpha21))] \n\\end{VrbM}\nResults:\n\\begin{VrbM}\nxmed = 75.3500\nans =  75.0500   77.0000\n\\end{VrbM}\nTherefore, a 0.95 percentile interval for the median is $(\\hat{\\theta}_{(2500)},\\hat{\\theta}_{(97500)})= (75.05, 77)$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\subsection{{\\it Properties of the percentile interval.}}\n\\work\n\\begin{asparaenum}[(a)]\n\\item {\\it Transformation-invariant.} Let $g$ be a one-to-one transformation and let $\\psi=g(\\theta)$. Let $(\\hat{\\theta}_{(\\lceil N\\alpha/2\\rceil)},\\hat{\\theta}_{(\\lceil N(1-\\alpha/2)\\rceil)})$ be a $1-\\alpha$ percentile interval for $\\theta$. If $g$ is increasing, then $(g(\\hat{\\theta}_{(\\lceil N\\alpha/2\\rceil)}),g(\\hat{\\theta}_{(\\lceil N(1-\\alpha/2)\\rceil)}))$ is a $1-\\alpha$ percentile interval for $\\psi$. If $g$ is decreasing, then $(g(\\hat{\\theta}_{(\\lceil N(1-\\alpha/2)\\rceil)}),g(\\hat{\\theta}_{(\\lceil N\\alpha/2\\rceil)}))$ is a $1-\\alpha$ percentile interval for $\\psi$.\n\n\\item {\\it Range-preserving.} A percentile interval for $\\theta$ lies within the range of possible values for $\\theta$.\n\n\\item {\\it First-order accurate.} The error in the coverage probability of a percentile interval goes to zero at rate $1/\\sqrt{n}$.\n\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Bias-corrected and accelerated (BCA) interval} \n\\work\nThe BCA interval is an improvement of the percentile interval that corrects for median bias (the difference between $\\hat{\\theta}$ and the median of $\\hat{\\theta}_1,\\ldots,\\hat{\\theta}_N$) and has a coverage probability that is closer to $1-\\alpha$. Like the percentile interval, the BCA interval's end-points are chosen from the ordered values of $\\hat{\\theta}_1,\\ldots,\\hat{\\theta}_N$, and so the interval has the form $(\\hat{\\theta}_{(r)},\\hat{\\theta}_{(s)})$, where $1   r < s   N$. The variables $r$ and $s$ are chosen to correct for median bias and improve coverage probability.\n\nLet $\\Phi$ denote the standard normal distribution function and let $z_p$ be the $p$-quantile of the standard normal distribution. Then:\n\\begin{equation}\nr=round[N\\Phi(z_{\\hat{b}}+\\frac{z_{\\hat{b}}+z_{\\hat{\\alpha/2}}}{1-\\hat{\\alpha}(z_{\\hat{b}}+z_{\\hat{\\alpha/2}})})],\n\\end{equation}\nand:\n\\begin{equation}\ns=round[N\\Phi(z_{\\hat{b}}+\\frac{z_{\\hat{b}}+z_{\\hat{\\alpha/2}}}{1-\\hat{\\alpha}(z_{\\hat{b}}+z_{\\hat{\\alpha/2}})})],\n\\end{equation}\n\nwhere $\\hat{a}$ and $\\hat{b}$ are yet to be defined. Before defining them, observe that if $\\hat{a}=z_{\\hat{b}}=0$, then the BCA interval reduces to the percentile interval.\n\nNow $z_{\\hat{b}}$ is a measure of the median bias of the bootstrap estimates, $\\hat{\\theta}_1,\\ldots,\\hat{\\theta}_N$, and so:\n\\begin{equation}\n\\hat{b}=\\frac{|\\{\\hat{\\theta}_j:\\hat{\\theta}_j<\\hat{\\theta}\\}|}{N}=\\frac{1}{N}\\sum^N_{j=1}I_{(-\\infty,\\hat{\\theta})(\\hat{\\theta}_j)}.\n\\end{equation}\n\nIf the median of $\\hat{\\theta}_1,\\ldots,\\hat{\\theta}_N$ coincides with $\\hat{\\theta}$, then $\\hat{b}=0.5$ and $z_{0.5}=0$, and so there is no median bias.\nThe symbol $\\hat{a}$ signifies the acceleration because it measures the rate of change of the standard deviation of $\\hat{\\theta}$  with respect to $\\theta$. If the standard deviation of $\\hat{\\theta}$ is assumed to be the same for all $\\theta$, then $\\hat{a}$ is 0; this is often unrealistic, so $\\hat{a}$ corrects for this. One way to compute $\\hat{a}$ is:\n\\begin{equation}\n\\hat{a}=\\frac{\\sum^N_{j=1}(\\bar{\\hat{\\theta}}-\\hat{\\theta}_j)^3}{6[\\sum^N_{j=1}(\\bar{\\hat{\\theta}}-\\hat{\\theta}_j)^2]^{3/2}}.\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nContinuing with the previous example, find a 0.95 BCA interval for the median.\n%\\Matlab code: (continued)\n\\begin{VrbM}\n% (1-alpha) BCA interval:\nb = sum(xbootmed < xmed) / N;\nxbootmedmean = mean(xbootmed);\na = sum((xbootmedmean - xbootmed).^3) / (6 * (sum((xbootmedmean -\nxbootmed).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1));\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1));\n[xbootmedsort(r) xbootmedsort(s)]\n\\end{VrbM}\nResults: (continued)\n\\begin{VrbM}\nr = 1188\ns = 95149\nans = 74.8500   76.7500\n\\end{VrbM}\nTherefore, the 0.95 BCA interval for the median is $ (\\hat{\\theta}_{1188},\\hat{\\theta}_{95149})= (74.85, 76.75)$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Properties of the BCA interval}\n\\work\n\\begin{asparaenum}[(a)]\n\\item The BCA interval is transformation-invariant and range-preserving.\n\n\\item {\\it Second-order accurate.} The error in the coverage probability of a BCA interval tends to zero at rate $1/n$.\n\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\section{Extension to multivariate data and linear regression}\n\\work\nThe extension of the nonparametric bootstrap to multivariate data is straightforward. Bootstrap samples are obtained by randomly sampling with replacement from the multivariate data points.\n\n\\begin{labwork}\nThis is an example involving bivariate data. The data in {\\tt shoe.txt} are the shoe sizes (column 1) and heights (column 2, in inches) of 24 college-age men.\n%\\includegraphics\nRepresent each bivariate data point by $(x_i,y_i)$, where $x_i$ is the shoe size and $y_i$ is the height of the $i^{\\textrm{th}}$ man. The correlation between $x$ and $y$ is:\n$$\\rho=\\frac{E\\{[x-E(x)][y-E(y)]\\}}{\\sqrt{E\\{[x-E(x)]^2\\}E\\{[y-E(y)]^2\\}}},$$\n\nwhich can be estimated by the sample correlation:\n\n$$\\hat{\\rho}=\\frac{\\sum_{i=1}^{24}(x_i-\\bar{x})(y_i-\\bar{y})}{\\sqrt{[\\sum^{24}_{i=1}(x_i-\\bar{x})^2][\\sum^{24}_{i=1}(y_i-\\bar{y})^2]}}$$\n\nwhere $\\bar{x}$ and $\\bar{y}$ are the sample means of x and y respectively. Find a 0.95 BCA interval for the correlation.\n\nA bootstrap sample is obtained by randomly sampling with replacement from $(x_1,y_1),\\ldots,(x_{24},y_{24})$. Denoting the $j^{\\textrm{th}}$ bootstrap sample by $(x_{j,1},y_{j,1}),\\ldots,(x_{j,24},y_{j,24})$, the $j^{\\textrm{th}}$ bootstrap estimate of the correlation coefficient is:\n$$\\hat{\\rho}_j=\\frac{\\sum_{i=1}^{24}(x_{j,i}-\\bar{x}_j)(y_{j,i}-\\bar{y}_j)}{\\sqrt{[\\sum^{24}_{i=1}(x_{j,i}-\\bar{x}_j)^2][\\sum^{24}_{i=1}(y_{j,i}-\\bar{y}_j)^2]}}.$$\n\n%\\Matlab code:\n\\begin{VrbM}\ndata = load('shoe.txt'); % load data from text file\nx = data(:,1); % store shoe size in x\ny = data(:,2); % store height in y\nn = length(x); % determine number of data values\nN = 100000; % number of bootstrap samples\nnN = n * N;\nalpha = 0.05;\nalpha2 = alpha / 2;\nalpha21 = 1 - alpha2;\nbootcxy = zeros(1,N); % storage for correlations of bootstrap samples\ncxy = corr(x,y) % sample correlation between x and y\niboot = randsample(n,nN,true); % sample with replacement nN values from the\n                                                   % indices 1,...,n\niboot = reshape(iboot,n,N); % organise resampled values into N columns of n\n                                            % values each so that each column cotains the\n                                            % indices for a bootstrap sample of size n\nfor i = 1:N\n    bootcxy(i) = corr(x(iboot(:,i)),y(iboot(:,i))); % correlation of bootstrap sample i\nend\nbootcxysort = sort(bootcxy); % sort correlations in increasing order\n\n% (1-alpha) BCA interval:\nb = sum(bootcxy < cxy) / N;\nbootcxymean = mean(bootcxy);\na = sum((bootcxymean - bootcxy).^3) / (6 * (sum((bootcxymean -\nbootcxy).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1))\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1))\n[bootcxysort(r) bootcxysort(s)]\n\\end{VrbM}\nResults:\n\\begin{VrbM}\ncxy = 0.7176\nr = 1596\ns = 96198\nans = 0.3647    0.8737\n\\end{VrbM}\nTherefore, the 0.95 BCA interval for the correlation is $ (\\hat{\\rho}_{(1596)},\\hat{\\rho}_{(96198)})= (0.3647, 0.8737)$. For comparison, the usual asymptotic 0.95 confidence interval is $(0.4422, 0.8693)$.\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\subsection{Confidence intervals for regression coefficients}\n\\work\nFor the shoe data, consider a simple linear regression of height on shoe size:\n$$y_i=\\beta_0+\\beta_1x_i+\\epsilon_i$$\n\nwhere the $\\epsilon_1,\\epsilon_2,\\ldots$ are assumed to be IID with mean 0 and variance $\\sigma^2$. Let:\n$$B=\\left( \\begin{array}{c}\\beta_0\\\\\\beta_1\\\\\\end{array} \\right), Y=\\left( \\begin{array}{c}y_1\\\\M\\\\y_{24}\\end{array} \\right) \\textrm{ and } X=\\left( \\begin{array}{cc}1&x_1\\\\ M&M\\\\ 1&x_{24}\\\\\\end{array}\\right).$$\n\n\nThe least-squares estimates of the regression coefficients are given by:\n$$\\hat{B}=(X^TX)^{-1}xTY,$$\nwhich is equivalent to:\n$$\\hat{\\beta}_1=\\frac{\\sum^n_{i=1}(x_i-\\bar{x})(y_i-\\bar{y})}{\\sum^n_{i=1}(x_i-\\bar{x})^2}\\textrm{ ,    }\\hat{\\beta}_0=\\bar{y}-\\hat{\\beta}_1\\bar{x}.$$\n%\\Matlab code:\n\\begin{VrbM}\ndata = load('shoe.txt'); % load data from text file\nx = data(:,1); % store shoe size in x\ny = data(:,2); % store height in y\n \nn = length(x); % determine number of data values\nX = [ones(n,1) x]; % predictor matrix\nbe = regress(y,X) % linear regression of y on x\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nbe = \t59.2285\n\t\t1.1988\n\\end{VrbM}\nTherefore, the least-squares line is $y = 59.23 + 1.2x $.\n\nTo get 0.95 BCA intervals for the regression coefficients, we obtain bootstrap samples of size 24 and recompute the least-squares estimates for each bootstrap sample. As in the previous example, a bootstrap sample is obtained by randomly sampling with replacement from $(x_1,y_1),\\ldots,(x_{24},y_{24})$. Denote the $j^{\\textrm{th}}$ bootstrap sample by $(x_{j,1},y_{j,1}),\\ldots,(x_{j,24},y_{j,24})$ and let:\n$$Y_j=\\left(\\begin{array}{c}y_{j,1}\\\\M\\\\y_{j,24}\\end{array}\\right)\\textrm{ and }X_j=\\left(\\begin{array}{cc}\n1&x_{j,1}\\\\ M&M\\\\1&x_{j,24}\\end{array}\\right).$$\n\n\nThen the $j^{\\textrm{th}}$ bootstrap estimates of the regression coefficients are given by:\n$$\\hat{B}_j=(X^T_jX_j)^{-1}X^T_jY_j.$$\n\\Matlab code: (continued)\n\\begin{VrbM}\nN = 100000; % number of bootstrap samples\nnN = n * N;\nalpha = 0.05;\nalpha2 = alpha / 2;\nalpha21 = 1 - alpha2;\nbootbe = zeros(2,N);\niboot = randsample(n,nN,true); % sample with replacement nN values from the\n                                                  % indices 1,...,n\niboot = reshape(iboot,n,N); % organise resampled values into N columns of n\n                                            % values each so that each column cotains the\n                                            % indices for a bootstrap sample of size n\nfor i = 1:N\n    % regression for bootstrap sample i:\n    bootbe(:,i) = regress(y(iboot(:,i)),[ones(n,1) x(iboot(:,i))]);\nend\nbootbesort = sort(bootbe,2); % sort regression coefficients in increasing order\n \n% (1-alpha) BCA interval for be0:\nb = sum(bootbe(1,:) < be(1)) / N;\nbootbe0mean = mean(bootbe(1,:));\na = sum((bootbe0mean - bootbe(1,:)).^3) / (6 * (sum((bootbe0mean -\nbootbe(1,:)).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1))\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1))\n[bootbesort(1,r) bootbesort(1,s)]\n \n% (1-alpha) BCA interval for be1:\nb = sum(bootbe(2,:) < be(2)) / N;\nbootbe1mean = mean(bootbe(2,:));\na = sum((bootbe1mean - bootbe(2,:)).^3) / (6 * (sum((bootbe1mean -\nbootbe(2,:)).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1))\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1))\n[bootbesort(2,r) bootbesort(2,s)]\n\\end{VrbM}\nResults: (continued)\n\\begin{VrbM}\nr = 2489\ns = 97489\nans = 55.3841   63.9200\n\nr = 2407\ns = 97404\nans = 0.6913    1.5887\n\\end{VrbM}\nTherefore, the 0.95 BCA interval for $\\beta_0$ is $(\\hat{\\beta}_{0,(2489)},\\hat{\\beta}_{0,(97489)}) = (55.38, 63.92)$ and for $\\beta_1$ is $(\\hat{\\beta}_{1,(2407)},\\hat{\\beta}_{1,(97404)}) = (0.6913, 1.5887)$.\n%\\includegraphics\n\n\\subsection{Alternative bootstrap method for regression}\n\\work\n Consider simple linear regression of response $y$ on predictor $x$ with $(x_1,y_1),\\ldots,(x_n,y_n)$, where the predictors $x_1,\\ldots,x_n$ are fixed and deterministic. As in the previous example:\n$$y_i=\\beta_0+\\beta_1x_i+\\epsilon_i,$$\n\nwhere the $\\epsilon_1,\\epsilon_2,\\ldots$ are assumed to be IID with mean 0 and variance $\\sigma^2$. Using the same notations as before, the least-squares estimates of the regression coefficients are given by: \n$$\\left(\\begin{array}{c}\\hat{\\beta}_0\\\\\\hat{\\beta}_1\\end{array}\\right)=(X^TX)^{-1}X^TY.$$\n\nFor $i = 1,\\ldots,n$, compute the residuals:\n$$\\hat{\\epsilon}_i=y_i-\\hat{\\beta}_0+\\hat{\\beta}_1x_i,$$\n\nand then the centred residuals:\n$$\\hat{\\epsilon}^*_i=\\hat{\\epsilon}_i-\\bar{\\hat{\\epsilon}},$$\nwhere $\\bar{\\hat{\\epsilon}}$ is the sample mean of $\\hat{\\epsilon}_1,\\ldots,\\hat{\\epsilon}_n$.\n\nThe $j^{\\textrm{th}}$ bootstrap sample and bootstrap regression coefficients are obtained as follows:\n\\begin{asparaenum}[(a)]\n\\item Randomly sample with replacement from $\\hat{\\epsilon}_1^*,\\ldots,\\hat{\\epsilon}_n^*$ to get $\\hat{\\epsilon}_{j,1},\\ldots,\\hat{\\epsilon}_{j,n}$.\n\n\\item\tFor $i = 1,\\ldots,n$, obtain bootstrap responses by:\n$$y_{j,i}=\\hat{\\beta}_0+\\hat{\\beta}_1x_i+\\hat{\\epsilon}_{j,i}.$$\n\nThe bootstrap sample is $(x_1,y_{j,1}),\\ldots,(x_n,y_{j,n})$.\n\n\\item\tThe bootstrap regression coefficients are given by:\n$$\\left(\\begin{array}{c}\\hat{\\beta}_{j,0}\\\\\\hat{\\beta}_{j,1}\\end{array}\\right)=(X^TX)^{-1}X^TY_j.$$\n\\end{asparaenum}\n\n\\begin{labwork}\nReferring to Example 4.3.2 for the shoe data, obtain 0.95 BCA intervals for the regression coefficients by bootstrapping residuals.\n\n%\\Matlab code:\n\\begin{VrbM}\ndata = load('shoe.txt'); % load data from text file\nx = data(:,1); % store shoe size in x\ny = data(:,2); % store height in y\nn = length(x); % determine number of data values\nX = [ones(n,1) x]; % predictor matrix\n \n% linear regression of y on x:\n[be,beint,res] = regress(y,X); % store residuals in res\nres = res - mean(res); % centred residuals\n \nN = 100000; % number of bootstrap samples\nnN = n * N;\nalpha = 0.05;\nalpha2 = alpha / 2;\nalpha21 = 1 - alpha2;\nbootbe = zeros(2,N);\n \nrboot = randsample(res,nN,true); % sample with replacement nN values from res\nrboot = reshape(rboot,n,N); % organise resampled values into N columns of n\n                                             % values each so that each column contains n\n                                             % bootstrapped residuals\nfor i = 1:N\n    yboot = X * be + rboot(:,i);\n    bootbe(:,i) = regress(yboot,X); % regression for bootstrap sample i\nend\nbootbesort = sort(bootbe,2); % sort regression coefficients in increasing order\n \n% (1-alpha) BCA interval for be0:\nb = sum(bootbe(1,:) < be(1)) / N;\nbootbe0mean = mean(bootbe(1,:));\na = sum((bootbe0mean - bootbe(1,:)).^3) / (6 * (sum((bootbe0mean - bootbe(1,:)).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1))\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1))\n[bootbesort(1,r) bootbesort(1,s)]\n \n% (1-alpha) BCA interval for be1:\nb = sum(bootbe(2,:) < be(2)) / N;\nbootbe1mean = mean(bootbe(2,:));\na = sum((bootbe1mean - bootbe(2,:)).^3) / (6 * (sum((bootbe1mean - bootbe(2,:)).^2)^1.5));\nzb = norminv(b,0,1);\nzalpha2 = norminv(alpha2,0,1);\nzalpha21 = norminv(alpha21,0,1);\nr = round(N * normcdf(zb + ((zb + zalpha2) / (1 - a * (zb + zalpha2))),0,1))\ns = round(N * normcdf(zb + ((zb + zalpha21) / (1 - a * (zb + zalpha21))),0,1))\n[bootbesort(2,r) bootbesort(2,s)]\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nr = 2551\ns = 97550\nans = 54.6419   63.9479\n\nr = 2372\ns = 97366\nans = 0.7148    1.6548\n\\end{VrbM}\nTherefore, the 0.95 BCA interval for $\\beta_0$ is $(\\hat{\\beta}_{0,(2551)},\\hat{\\beta}_{0,(97550)})  = (54.64, 63.95)$; for $\\beta_1$, it is $(\\hat{\\beta}_{1,(2372)},\\hat{\\beta}_{1,(97366)})= (0.7148, 1.6548)$.\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\section{Extension to dependent data}\n\\work\nRecall that the nonparametric bootstrap requires the data values to be IID. We briefly describe how the nonparametric bootstrap can be applied when the data values are not independent, particularly in the context of time series data. The key idea is to divide the data into blocks that are \\textquotedblleft approximately independent\" and then perform random sampling with replacement on these blocks rather than on the individual data values. Hence, this extension of the nonparametric bootstrap to dependent data is sometimes referred to as the {\\it block bootstrap}.\n\n\\subsection{Block bootstrap}\n\\work\nLet $x_1,\\ldots,x_n$ be a sequence of time series measurements, with the indices denoting the times at which the measurements are taken, i.e. $x_1$ is obtained before $x_2$ and so on. The measurements are not independent but have some form of dependence over time. One of the simplest forms of the block bootstrap is as follows:\n\\begin{asparaenum}[(a)]\n\\item Specify a {\\it block length} $b$ ($b$ must be smaller than $n$). Let $m=round(n/b)$.\n\n\\item\t Divide $x_1,\\ldots,x_n$ into blocks as follows:\n$$\\begin{array}{l}\nB_1=\\{x_1,\\ldots,x_b\\}\\\\\nB_2=\\{x_2,\\ldots,x_b+1\\}\\\\\n\\textrm{        M      }\\\\\nB_{n-b+1}=\\{x_{n-b+1},\\ldots,x_n\\}\\\\\n\\end{array} $$\n\n\n\\item Randomly pick $m$ blocks with replacement, calling them $B_1^*,\\ldots,B_m^*$.\n\n\\item Concatenate $B_1^*,\\ldots,B_m^*$ to get a bootstrap sample of the time series.\n\n\\item \tRepeat Steps (c) and (d) to get another bootstrap sample.\n\\end{asparaenum}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\nThe block bootstrap procedure looks simple but the difficulty lies in the choice of the block length. A good block length depends on at least three things: the time series, the statistic of interest and the purpose for bootstrapping the statistic. Unfortunately, further discussion on block length choice involves concepts that are beyond the level of this course and so we shall have to stop here.\n\n\\section{Exercises}\n\\work\n\\begin{exercise}\nDownload the \\Matlab function, {\\tt edfplot.m}, from the course webpage. Use it to obtain the EDF and 0.95 confidence band for:\n\\begin{asparaenum}[(a)]\n\\item the continuous data in Example 4.1.3;\n\n\\item the discrete data in Example 4.1.4.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe sodium data in Example 4.2.5 are given in {\\tt sodium.txt}. Use the nonparametric bootstrap with 100,000 bootstrap samples to find the bias, variance and MSE of the sample median.\n\\end{exercise}\n\n\\begin{exercise}\nThe latch data in Example 4.2.3 are given in {\\tt latch.txt}. Use the nonparametric bootstrap with 100,000 bootstrap samples to find a 0.95 percentile interval and the 0.95 BCA for the standard deviation. (\\Matlab function for standard deviation is {\\tt std}.)\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt hemoglobin.txt} are the haemoglobin levels (in g/dl) of 20 Canadian Olympic ice hockey players.\n\\begin{asparaenum}[(A)]\n\\item\tUse the nonparametric bootstrap with 100000 bootstrap samples to find:\n\\begin{asparaenum}[(i)]\n\\item the bias, variance and MSE of the sample 0.1-quantile;\n\n\\item\ta 0.95 percentile interval and the 0.95 BCA for the 0.1-quantile.\n\\end{asparaenum}\n(\\Matlab function for quantile is {\\tt quantile}.)\n\n\\item\tUsing the BCA interval that you have already found in Part (a), find the 0.95 BCA interval for the square root of the 0.1-quantile.\n\n\\item\tPlot a density histogram for the bootstrap estimates of the 0.1-quantile.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt tar.txt} are the tar contents in a sample of 30 cigars of a particular brand.\n\\begin{asparaenum}[(a)]\n\\item Use the nonparametric bootstrap with 100,000 bootstrap samples to find:\n\\begin{asparaenum}[(i)]\n\\item the bias, variance and MSE of the sample interquartile range;\n\n\\item\ta 0.95 percentile interval and the 0.95 BCA for the interquartile range.\n\\end{asparaenum}\n(\\Matlab function for interquartile range is {\\tt iqr}.)\n\n\\item\tPlot a density histogram for the bootstrap estimates of the interquartile range.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nWork through Examples 4.3.1, 4.3.2 and 4.3.4 for the shoe data.\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt stream.txt} contain chloride concentrations (in mg/l) found at the surface of streams (column 1), and road densities (in \\%) in the vicinities of the streams (column 2).\n\\begin{asparaenum}[(a)]\n\\item Obtain a scatter plot of chloride concentration against road density and find a 0.95 BCA interval (using 100,000 nonparametric bootstrap samples) for the correlation coefficient between road density and chloride concentration. What can you conclude from the scatter plot and the confidence interval?\n\n\\item\tConsider a simple linear regression of chloride concentration ($y$ or response) on road density ($x$ or predictor). Obtain 0.95 BCA intervals for the regression coefficients, using 100,000 nonparametric bootstrap samples and by:\n\\begin{asparaenum}[(i)]\n\\item bootstrapping sample points;\n\n\\item\tbootstrapping residuals.\n\\end{asparaenum}\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe data in salmon.txt contain the number of recruits (column 1) and the number of spawners (column 2) in 40 salmon farms. The units are thousands of fish. Recruits are fish that are big enough to be sold. Spawners are fish that are kept for laying eggs, after which they die.\n\nThe Beverton-Holt model for the relationship between recruits and spawners is:\n$$R=\\frac{1}{\\beta_0+(\\beta_1/S)},$$\nwhere $R$ and $S$ are the numbers of recruits and spawners, and $\\beta_0,\\beta_1\\geq 0$.\n\\begin{asparaenum}[(a)]\n\\item\tUse the data to estimate $\\beta_0$ and $\\beta_1$ for the Beverton-Holt model by using linear regression with the transformed variables $1/R$ and $1/S$.\n\n\\item\tConsider the problem of maintaining a sustainable farm. The salmon population stabilises when $R = S$. Show that the stable population size is given by:\n$$R=S=\\frac{1-\\beta_1}{\\beta_0}.$$\n\nUsing the estimates from Part (a), estimate the stable population size.\n\n\\item\tUse the nonparametric bootstrap with 100,000 bootstrap samples to find 0.95 BCA intervals for the stable population by:\n\\begin{asparaenum}[(i)]\n\\item\tbootstrapping sample points;\n\n\\item\tbootstrapping residuals.\n\\end{asparaenum}\\end{asparaenum}\n\\end{exercise}\n%}% end of comment for Dominic's material\n", "meta": {"hexsha": "20daf772aa1b5b7ecc9494160c60a1ffa1567d31", "size": 36435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/BootstrapByDominicLee.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/BootstrapByDominicLee.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/BootstrapByDominicLee.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.6274509804, "max_line_length": 584, "alphanum_fraction": 0.6743241389, "num_tokens": 12482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.8824278540866547, "lm_q1q2_score": 0.6228043675607037}}
{"text": "The interpretation of $\\lambda ^? _{\\rightarrow}$ involves the following \nsix stages:\n\\begin{gather*}\n    \\texttt{standard I/O} \\xrightarrow{\\text{chars}}\n    \\texttt{lexing} \\xrightarrow{\\text{tokens}} \\texttt{parsing} \\\\\n    \\lhook\\joinrel\\xrightarrow{\\text{terms}} \\texttt{typechecking} \n    \\xrightarrow{\\text{cast terms}} \\texttt{evaluation} \n    \\xrightarrow{\\text{value}/\\text{error}} \\texttt{pretty-printing}\n\\end{gather*}\nwhere a program as a sequence of characters is first read from the \nstandard input, tokenized by a lexical analyzer, and parsed into \nan abstract syntax tree. The program is then typechecked and \nmodified with casts before being evaluated. The final \nresult is then printed in a readable format to the standard output.  We start by \ndefining the abstract syntax for the language.\n\n\\begin{lstlisting}\n    data Term = Zero                       \n               | Tru                        \n               | Fls                        \n               | Var Int Type String        \n               | If Term Term Term          \n               | Succ Term                   \n               | Pred Term                  \n               | IsZero Term                \n               | Lambda Type Term [String]  \n               | App Term Term              \n               | Ref Term                   \n               | Deref Term                 \n               | Loc Int                    \n               | Assign Term Term          \n               | Cast Coercion Term   \n\\end{lstlisting}\n\nVariables (\\lstinline{Var Int Type String}) are represented as nameless terms using de Bruijn indices \nin order to avert the problem of capturing free variables. Accordingly, each variable \nis assigned a number to indicate the position of its binder. For example, \n$\\lambda x. \\: \\lambda y. \\: x \\: y$ is rewritten as $\\lambda. \\: \\lambda. \n\\: 1 \\: 0$. That is, $y$ is bound to the first binder, and $x$ to the second. \nVariables whose de Bruijn indices are greater than the total number of binders \nare considered free. Also, instead of maintaining a global type environment \n$\\Gamma$, we have each variable remember its own bound type. We also \ninclude the original name of a variable for later printing.\n\nNote that this syntax extends upon the one we have formalized in Section 2 \nwith cast terms (\\lstinline{Cast Coercion Term}) and  \nstore locations (\\lstinline{Loc Int}). These terms only arise as intermediate \nresults from type checking and evaluation, and hence are not made available \nto programmers. Likewise, the data types for types and coercions are transcribed \ndirectly from their formal definitions, with one addition of type \\lstinline{TUnit} \nused for free variables.\n\n\\begin{lstlisting}\n    data Type = TUnit         \n               | Dyn            \n               | Boolean          \n               | Nat            \n               | Arr Type Type \n               | TRef Type      \n\\end{lstlisting}\n\n\\begin{lstlisting}\n    data Coercion = Iden Type              \n                  | Project Type Label     \n                  | Inject Type             \n                  | CRef Coercion Coercion  \n                  | Func Coercion Coercion  \n                  | Seq Coercion Coercion   \n                  | Fail Type Type Label\n\\end{lstlisting}  \n\nGiven the syntax definition, the rest of this section will mainly focus on \nimplementing the typechecker and \nevaluator for $\\lambda ^? _{\\rightarrow}$. The details on the \nlexer, parser, and pretty printer can be consulted in \nAppendix A, B, and C.\n\n\\subsection{Intermediate Language and Cast Insertion}\nThe static analysis of $\\lambda ^? _{\\rightarrow}$ both \ntypechecks annotated terms and inserts coercions for \ndynamically-typed terms to ensure type soundness. The cast insertion \nrules, shown in Figure 6 [8], resemble the typing rules in \nFigure 2. \nThe rules for variables, constants, and \nabstractions do not require any cast insertion. Rules {\\scriptsize{[C-SUCC2]}}, \n{\\scriptsize{[C-PRED2]}}, and {\\scriptsize{[C-ISZERO2]}} handle the \ncase when the argument type is dynamic by coercing it to \\texttt{Nat}. \nThe rules for \\texttt{if} expressions make sure that the condition \ntype is coerced to \\texttt{Bool} if dynamic, and the two branch \ntypes are consistent by coercing one to another. Rule \n{\\scriptsize{[C-APP1]}} coerces the argument type to the parameter \ntype given that the operator is a function. Otherwise, we need to \ninsert a function check $\\langle \\texttt{Fun}? ^l \\rangle$ to verify \nthat the operator resolves to a function at runtime. The rules for \nassignment follow the same pattern, casting the right-hand side type \nto the left-hand side type and inserting a reference check \n$\\langle \\texttt{Ref}? ^l \\rangle$ when the left-hand side type is \nunknown. A reference check is also important when dereferencing a \ndynamic term, as in rule {\\scriptsize{[C-DEREF2]}}.\n\\input{figures/CastInsertion}\n\nThe cast insertion process is implemented as part of the typechecker. \nWe also need to incorporate blame tracking whenever an unsafe cast \nis introduced to the original program. To keep it simple, we \nrepresent a blame label as an integer. A new label is obtained \nby simply incrementing the value of the last assigned label by 1. \nAdditionally, the typechecker should be able to report errors on \nill-typed expressions. In order to achieve both blame tracking \nand exception handling, a new monad \\lstinline{TCheckState} is defined \nas follows:\n\\begin{lstlisting} \n    type TCheckState a = ExceptT TypeError (State Label) a\n\\end{lstlisting}\nBy combining the \\lstinline{State} monad and the \\lstinline{Except} monad, \\lstinline{TCheckState} \nhelps maintain a global counter for labeling unsafe coercions \nas well as return errors during type checking. The data type \nfor type errors captures eight possible causes: (1) out-of-bound variables, \n(2) type difference between the two conditional branches, (3) non-boolean condition, \n(4) unexpected argument type for an arithmetic operator or (5) a function, \n(6) assigning to a non-reference term, \n(7) type mismatch between the two sides of an assignment, and (8) derefencing a \nnon-reference term. \n\n\\begin{lstlisting}\n    data TypeError = NotBound Term                 \n                   | Difference Type Type           \n                   | NotBool Type                  \n                   | NotNat Type    \n                   | FunMismatch Type Type Term                  \n                   | NotFunction Term               \n                   | IllegalAssign Term            \n                   | AssignMismatch Type Type Term  \n                   | IllegalDeref Term   \n\\end{lstlisting}\n\nWe transliterate the cast insertion rules in Figure 6 \ninto the \\lstinline{typeCheck'} function that takes in an expression as input \nand returns either a tuple of a modified expression and its type, \nor a type error.\n\n\\input{code/Typecheck.tex}\n\nThere are few slight changes to the formal type system. First is the \nomission of the global type environment for bound variables. Instead, each \nvariable carries its own type, and those with \\lstinline{TUnit} type are \nout of bound. Secondly, the function always checks for type \nconsistency before performing coercions. \\input{figures/Semantics}This sanity check allows the \ntypechecker to handle some errors directly instead of delegating them \nto the evaluator through failure coercions. \nAdditionally, we add another rule for application when the \nargument type is identical to the parameter type. As a result, no casts \nare needed. In this way, we eliminate unnecessary coercions that make \nno changes to the semantics. The same pattern is applied for conditional \nexpressions and assignments by including a check for type equivalence before \ntype consistency. Finally, we call the subroutine \\lstinline{GlobalS.newLabel} \nto generate a new blame label for every unsafe cast inserted. \n\n\\subsection{Operational Semantics}\nFigure 7 formalizes the operational semantics for a typechecked \nprogram with coercions. In addition to the standard rules for \nthe $\\lambda$-calculus with references, the semantics also \ndefines rules for cast expressions. Rule  \n{\\scriptsize{[E-ID]}} removes the identity coercion and \nreturns the inner value. \nRule {\\scriptsize{[E-COMP]}} composes two \nadjacent coercions given that the first coercion is normalized. \nThis restriction makes sure that coercions do not get accumulated \nwithout being reduced. \nThe {\\scriptsize{[E-GROUND]}} rule unwraps a cast value \nwhen its coercion is normalized. Otherwise, we take a small \nstep of evaluation inside the coercion using the reduction rules \nin Figure 5. The combination of {\\scriptsize{[E-CSTEP]}} and \n{\\scriptsize{[E-COMP]}} helps maintain a bounded size on coercions. \nRule {\\scriptsize{[E-CDEREF]}} casts the value read \nfrom a cell, whereas {\\scriptsize{[E-CASSIGN]}} also casts the value \nwritten to it. Rule \n{\\scriptsize{[E-CAPP]}} splits the function coercion \ninto two separate coercions for the argument and the result. \nFinally, we terminate the evaluation and throw a cast error \nimmediately when the coercion $\\texttt{Fail}^l$ is encountered, \nas described in the {\\scriptsize{[E-FAIL]}} rule. The blame \nlabel consequently identifies the responsible coercion.\n\nSimilar to the \\lstinline{typeCheck'} procedure, we define a \nmonad \\lstinline{SEvalState} to provide a global state for a set $\\sigma$ of \nstore locations and also to signal runtime errors.\n\\begin{lstlisting}\n    type SEvalState a = ExceptT RuntimeError (State StoreEnv) a\n\\end{lstlisting}\nThe following implementation describes a small-step evaluator \nbased on the established reduction rules in Figure 7.\n\n\\input{code/Evaluator}\n\nFor the evaluation of a cast expression (\\lstinline{Cast c t'}), \nwe first check if the inner expression \\lstinline{t'} is a value. If not, then \nwe take a small-step of evaluation for \\lstinline{t'}. Otherwise, \nwe consider the next case where \\lstinline{t'} is a cast value   \n\\lstinline{Cast d u}, where \\lstinline{d} is normalized. In this \ncase, we apply rule {\\scriptsize{[E-COMP]}} to combine coercions \\lstinline{c} \nand \\lstinline{d}. The subsequent cases handle cast expressions where \n\\lstinline{t'} is a simple value, and the coercion \\lstinline{c} takes \non different patterns. The \n\\lstinline{unbox} function unwraps a cast expression whose coercion is normalized \nprovided that the target type matches the runtime type.    \nThe subroutines \\lstinline{GlobalS.allocate} and \\lstinline{GlobalS.update} \nmodify the global store $\\sigma$ by allocating a new cell and \nupdating an existing cell, respectively, while \\lstinline{GlobalS.peek} \nreads from a cell. Function \\lstinline{subsFromTop} \nperforms a substitution \noperation $e[x \\mapsto v]$ on nameless terms by renumbering \nfree variables. Appendix D discusses this process in more detail. \nRuntime errors include cast errors and stuckness. Cast expressions \nwith a failure coercion give a cast error. \nA stuck evaluation results when a term has no transition states \nbecause it is either a simple value or meaningless. Hence, a \\lstinline{Stuck} \nexception is simply an indication that an evaluation has \nterminated. Otherwise, \nwe keep applying the small-step \\lstinline{evaluate'} on non-stuck terms \nto reach the final state. The following \nfunction performs the big-step semantics. \n\n\\begin{lstlisting}\n    evaluate :: Term -> Either RuntimeError Term\n    evaluate t = \n        let (res, t') = GlobalS.runBEval $ evaluateToValue t StoreEnv.empty\n        in case res of\n               Right t'' \n                   | isUncoercedVal t'' -> Right t''\n                   | otherwise          -> Left Stuck \n               Left (Blame s1 s2 l)     -> let cause = fromJust $ blame l t\n                                               bres = BlameRes cause t'\n                                           in Left $ CastError s1 s2 bres  \n               Left err                 -> Left err \n\\end{lstlisting}\n\nThe subroutine \\lstinline{GlobalS.runBEval} initializes a global state \nfor evaluation with an empty store. \\lstinline{evaluateToValue} repeatedly \napplies the small-step evaluator until a stuck term or an error is encountered. \nA stuck term is only valid if it is an uncoerced value. Else, an actual error \nof a stuck evaluation is returned. In the case of a cast error, we call the \n\\lstinline{blame} function with a label to search for the erroneous \ncoercion in the input expression. The data type \\lstinline{BlameRes} \nwraps this coercion along with the last evaluated term for the error message. \n\n\\subsection{Overview}\nNow that we have defined the type checking and evaluation procedures, \nour interpreter for $\\lambda ^? _{\\rightarrow}$ works as follows:\n\\begin{lstlisting}\n    interpret :: String -> IO ()\n    interpret line = case parseExpr line of \n        Right validExpr -> case typeCheck validExpr of \n                               Right t  -> case evaluate t of \n                                               Right res -> printMsg res\n                                               Left err  -> printMsg err\n                               Left err -> printMsg err\n        Left err        -> print err   \n\\end{lstlisting}\nThe interpreter first parses the input stream into an abstract syntax tree. \nIf parsing succeeds, then the parsed expression is typechecked; \notherwise, we output a parse error. A well-typed expression is subsequently \nevaluated to a value, or a runtime error is thrown. Function \\lstinline{printMsg} \nprints the result in a readable format (see Appendix C).\n\n\\subsection{Examples}\n\\input{Example}\n\n\n\n", "meta": {"hexsha": "67700e8d9148a6b239245375a235c10ab7329136", "size": 13611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project Report/Interpreter.tex", "max_stars_repo_name": "thuytien140894/GTLC", "max_stars_repo_head_hexsha": "52a2e6f8f14a11eeacd7a12f8f1b3dd722afe691", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-02-01T20:27:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-08T03:53:23.000Z", "max_issues_repo_path": "Project Report/Interpreter.tex", "max_issues_repo_name": "thuytien140894/GTLC", "max_issues_repo_head_hexsha": "52a2e6f8f14a11eeacd7a12f8f1b3dd722afe691", "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": "Project Report/Interpreter.tex", "max_forks_repo_name": "thuytien140894/GTLC", "max_forks_repo_head_hexsha": "52a2e6f8f14a11eeacd7a12f8f1b3dd722afe691", "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.4111111111, "max_line_length": 102, "alphanum_fraction": 0.6935566821, "num_tokens": 3072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6227317526126497}}
{"text": "\\problemname{Get Yer Armor Here}\n\n\\noindent Torbjörn, a small dwarf who excels in creating armor packs from Scrap Metal, is surveying a map representing a\nbattlefield. He has been airdropped into the middle of this battlefield, which is represented by a rectangular N x M 2D\nmatrix. He wishes to collect as much scrap metal as he can before requesting an extraction.\\\\\n\n\\noindent The values of the matrix will represent the number of number of scrap metal available to Torbjörn at each location in the\nbattlefield. If the field doesn’t have an exact center, assume that Torbjörn will start in the square closest to the center \nwith the highest scrap metal count. \\\\\n\n\\noindent On each turn, Torbjörn will collect the scrap metal available on the square that he is currently on, and then move\neither one square up, down, left, or right, choosing the square that has the most available scrap metal. If there is no\nmore scrap metal available in any adjacent squares, Torbjörn will request an extraction and deem the mission complete.\nYou may assume that Torbjörn will never be forced to choose between adjacent squares with the same number of scrap\nmetal. \\\\\n\n\\noindent Write a program that given input representing the map, returns the maximum number of scrap metal that the Torbjörn\ncollect from the battlefield. You may assume that the matrix is rectangular with at least 1 row and 1 column, and it is\npopulated with non-negative integers. \\\\\n\n\\section*{Input}\nYou will be given $1 \\leq N,M \\leq 5000$, followed by $N$ lines, each containing $M$ non-negative integers representing the \navailable scrap metal at each point on the map.\n\\section*{Output}\nOutput the maximum amount of scrap metal Torbjörn will collect from this map before being extracted.\\\\\n", "meta": {"hexsha": "6cfa606b5edd9c31a95fb454c5e3c558fdd84fc7", "size": 1755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "armorhere/problem_statement/problem.en.tex", "max_stars_repo_name": "wlgranados/utscode", "max_stars_repo_head_hexsha": "670c04b8ae911e04a78e67b1e5d3bf03aa07bdb4", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-15T15:08:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-04T19:52:23.000Z", "max_issues_repo_path": "armorhere/problem_statement/problem.en.tex", "max_issues_repo_name": "wlgranados/utscode", "max_issues_repo_head_hexsha": "670c04b8ae911e04a78e67b1e5d3bf03aa07bdb4", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-10-13T07:15:56.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-28T23:29:38.000Z", "max_forks_repo_path": "armorhere/problem_statement/problem.en.tex", "max_forks_repo_name": "wgma00/utscode", "max_forks_repo_head_hexsha": "670c04b8ae911e04a78e67b1e5d3bf03aa07bdb4", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-03-22T19:35:38.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-28T23:16:50.000Z", "avg_line_length": 67.5, "max_line_length": 131, "alphanum_fraction": 0.7937321937, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624890918021, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.622731750957658}}
{"text": "\\section {Family of Transfer Functions}\n\\setlength{\\parindent}{0pt}\n(Prepared by Sanket Gandhi)\n\n\\vspace{0.3cm}\n\\begin{itemize}\n    \\item Recall that a DFA is defined by ($F$, $V$, \\^{}) where ($V$, \\^{}) forms the semilattice and $F$ is family of transfer functions.\n    \\item Family of Transfer Functions $F$ is set of functions. For particular DFA each transfer function for an instruction or a basic block is drawn from the set $F$. \n    \\item If transfer function does not have certain properties then DFA may not terminate. $F$ should have certain properties in order to reason about optimality and convergence of DFA.\n\\end{itemize}\n\n\\subsection{Properties of Family Transfer Functions F}\nFamily of transfer functions $F$ must have following properties.  \n\\begin{itemize}\n    \\item Every function is $F$ takes a value from DFA value set $V$ and returns a value from same set $V$, that is every function $f$ in $F$ have form $f:V \\rightarrow V $\n    \\item F contains the identity function that is, $\\exists \\ f \\in F \\ $ such that $f(x) = x $, $ \\forall \\ x \\in V$. \\\\ This property is needed because in case of NOP instructions the output is equal to input. So identity function should be in $F$.  \n    \\item F is closed under composition, if $f_{1},f_{2} \\in F$ then $f_{1}\\circ f_{2} \\in F$.\\\\ This property will be helpful for defining transfer functions for basic blocks.\n\\end{itemize}\n\n\\subsection{Example}\nMany of the DFAs(Reaching definitions, Constant Propagation etc.) have following structure in transfer function.\n\\[f(x) = (x-kill_{s})\\bigcup gen_{s}\\] for some instruction $s$. $kill_{s}$ and $gen_{s}$ only depends on $s$ and are independent of $x$.\n\\\\$F$ is the set of function which is populated by changing $kill$ and $gen$ set in above structure.\nIn case of reaching definitions if we have $n$ definitions in program then size of $F$ will be $4^{n}$.  Lets check whether $F$ is family of transfer functions or not.\n\\begin{itemize}\n    \\item Every function in $F$ take a set of some kind $x$ input and perform set operations. The output is also set of same kind. $F$ have first property of family of transfer function.\n    \\item In case of $gen = \\emptyset$ and $kill = \\emptyset$, the transfer function will become $f(x) = x$ and $f\\in F$.\n    \\item Consider two functions $f_{1}(x) = (x-kill_{1})\\bigcup gen_{1}$ and $f_{2}(x) = (x-kill_{2})\\bigcup gen_{2}$. Both $f_{1}, f_{2}$ belongs to $F$. \n    \\[f_{2}(f_{1}(x)) = ((x-kill_{1})\\bigcup gen_{1}-kill_{2})\\bigcup gen_{2}\\]\n    By using property $A\\bigcup B - C = (A-C)\\bigcup (B-C)$ the above equation becomes\n    \\[f_{2}(f_{1}(x)) = (x-(kill_{1} \\bigcup kill_{2}))\\bigcup ((gen_{1}-kill_{2})\\bigcup gen_{2})\\]\n    With $kill_{1\\circ 2} = kill_{1} \\bigcup kill_{2}$ and $gen_{1\\circ 2} = (gen_{1}-kill_{2})\\bigcup gen_{2}$ the composite function becomes $f_{2}(f_{1}(x)) = (x - kill_{1 \\circ 2})\\bigcup gen_{1\\circ 2}$. Therefore $f_{1} \\circ f_{2} \\in F$ as $F$ contain transfer functions with all possible $gen$ and $kill$ set. \n\\end{itemize}\n", "meta": {"hexsha": "2738e39dbf163d7f1026d0bfb2669e4fa47dba3a", "size": 3022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module99.tex", "max_stars_repo_name": "arpit-saxena/compiler-notes", "max_stars_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "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": "module99.tex", "max_issues_repo_name": "arpit-saxena/compiler-notes", "max_issues_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "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": "module99.tex", "max_forks_repo_name": "arpit-saxena/compiler-notes", "max_forks_repo_head_hexsha": "af3788cde815a5b1d19f206ec8605c0e372c1833", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-02-16T08:32:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-12T19:11:33.000Z", "avg_line_length": 88.8823529412, "max_line_length": 319, "alphanum_fraction": 0.6922567836, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6227317485791147}}
{"text": "\\documentclass{article}\n\\usepackage[dvipsnames]{xcolor} % for colorful text\n\\usepackage{tikz}             % for graphics\n\\usepackage{amsmath, amssymb} % for math symbols\n\\usepackage{hyperref}         % for creating links\n\\hypersetup{ colorlinks=true, linkcolor=blue}\n\\numberwithin{equation}{section}\n\\pagenumbering{roman}\n\\title{Thermal Physics}\n\\begin{document}\n\n\\maketitle\n\\tableofcontents\n\\pagebreak\n\n\\section{Boyle's Temperature}\nAt Boyle's temperature, $T_b$, $Z \\to 1$\\\\\nUsing Van der Waals' equation,\n$$P\\left(1+\\frac{a}{PV^2}\\right) V\\left(1-\\frac{b}{V}\\right) = RT$$\n$$Z = \\left(1+\\frac{a}{PV^2}\\right)^{-1} \\left(1-\\frac{b}{V}\\right)^{-1}$$\n$$Z = \\left(1 - \\frac{a}{PV^2}\\right) \\left(1+\\frac{b}{V}\\right)$$\n$$Z = 1 + \\frac{b}{V} - \\frac{a}{PV^2} - \\frac{ab}{PV^3}$$\n$\\because$ ab $\\ll$ $V^3$,\nat $T_B$, Z $\\to$ 1,\n$$\\therefore \\frac{b}{V} = \\frac{a}{PV^2}$$\nUsing PV=RT,\n$$b = \\frac{a}{RT_b}$$\n\\begin{equation}\n  \\boxed{\\textcolor{Mulberry}{T_b = \\frac{a}{Rb}}} \\label{eq:b1}\n\\end{equation}\n\n\\section{Critical Coefficients}\nUsing Van der waals' equation,\n$$\\left(P+\\frac{a}{V^2}\\right) \\left(V-b\\right) = RT$$\n\\begin{equation}\n  P = \\frac{RT}{\\left(V-b\\right)} - \\frac{a}{V^2} \\label{eq:c1}\n\\end{equation}\ndifferentianting \\eqref{eq:c1} w.r.t. V,\n\\begin{equation}\n  \\frac{dP}{dV} = - \\frac{RT}{\\left(V-b\\right)^2} + \\frac{2a}{V^3} \\label{eq:c2}\n\\end{equation}\ndifferentiating \\eqref{eq:c2} w.r.t. V,\n\\begin{equation}\n  \\frac{d^2P}{dV^2} = \\frac{2RT}{\\left(V-b\\right)^3} - \\frac{6a}{V^4} \\label{eq:c3}\n\\end{equation}\nAt the critical point,\n$$\\frac{dP}{dV} = 0  ,  \\frac{d^2P}{dV^2} = 0$$\n$\\therefore$ \\eqref{eq:c2} becomes,\n\\begin{equation}\n  \\frac{2a}{V_c^3} = \\frac{RT_c}{\\left(V_c-b\\right)^2} \\label{eq:c4}\n\\end{equation}\nand \\eqref{eq:c3} becomes,\n\\begin{equation}\n  \\frac{6a}{V_c^4} = \\frac{2RT_c}{\\left(V_c-b\\right)^3} \\label{eq:c5}\n\\end{equation}\nDividing \\eqref{eq:c4} by \\eqref{eq:c5},\n$$\\frac{V_c}{3} = \\frac{\\left(V_c-b\\right)}{2}$$\n$$2V_c = 3V_c - 3b$$\n\\subsection{Critical volume}\n\\begin{equation}\n  \\boxed{V_c = 3b} \\label{eq:c6}\n\\end{equation}\nUsing \\eqref{eq:c6} in \\eqref{eq:c4},\n$$\\frac{2a}{27b^3} = \\frac{RT_c}{4b^2}$$\n\\subsection{Critical temperature}\n\\begin{equation}\n  \\boxed{T_c = \\frac{8a}{27Rb}} \\label{eq:c7}\n\\end{equation}\nUsing \\eqref{eq:c6} and \\eqref{eq:c7} in \\eqref{eq:c1},\n$$P_c = \\frac{4Ra}{27Rb^2} - \\frac{a}{9b^2}$$\n\\subsection{Critical pressure}\n\\begin{equation}\n  \\boxed{P_c = \\frac{a}{27b^2}} \\label{eq:c8}\n\\end{equation}\n\\subsection{Critical compressibility factor}\n$$Z = \\frac{P_c V_c}{R T_c} = \\frac{3}{8}$$\n\\subsection{Critical coefficient}\nCritical coefficient is defined as the inverse of critical compressibility factor, i.e.,\n$$K = \\frac{1}{Z} = \\frac{8}{3}$$\n\n\\section{Temperature of Inversion}\n\\begin{tikzpicture}\n  % Outer Box\n  \\draw (-1,-2) rectangle (6.5,1.5);\n  %Container 1\n  \\draw (1,0) node[align=center] {$P_1$,$V_1$,$T_1$};\n  \\draw[thick,->,blue] (0,-1) node[fill=white] {Container I} -- ((0.2,-0.2);\n  \\draw (0,-0.5) rectangle (2,0.5);\n  %Porous Plug\n  \\filldraw[fill=brown] (1.9,-0.5) rectangle (2,0.5);\n  \\draw[thick,->] (1.5,-1.5) node[fill=white] {Porous Plug} -- (1.95,0);\n  %Container 2\n  \\draw (3,0) node[align=center] {$P_2$,$V_2$,$T_2$};\n  \\draw[thick,->,blue] (5,-1) node[fill=white] {Container II} -- (3.5,-0.5);\n  \\draw (2,-1) rectangle (4,1);\n\\end{tikzpicture}\n\\\\\nWhen the temperature of incoming gas($T_1$) in Joule-Thompson effect is, then the temperature of the outcoming gas($T_2$) is,\n\\begin{itemize}\n\\item $T_2 > T_1$ when $T_1 > T_i$\n\\item $T_2 = T_1$ when $T_1 = T_i$\n\\item $T_2 < T_1$ when $T_1 < T_i$\n\\end{itemize}\nWork done in overcoming intermolecular attractions,\n\\begin{align*}\n  w &= \\int_{V_1}^{V_2} P dV\\\\\n  &= \\int_{V_1}^{V_2} \\frac{a}{V^2} dV\\\\\n  &= - \\frac{a}{V_2} + \\frac{a}{V_1}\n\\end{align*}\nTotal work done by the gas,\n$$W = (P_2 V_2 - P_1 V_1) + w$$\n\\begin{equation}\n  W = (P_2 V_2 - P_1 V_1) + \\left(\\frac{a}{V_1} - \\frac{a}{V_2}\\right) \\label{eq:i1}\n\\end{equation}\nfrom Van der waals' equation, we know that\n$$\\left(P+\\frac{a}{V^2}\\right)(V-b) = RT$$\n$$PV = RT + bP - \\frac{a}{V} + \\frac{ab}{V^2}$$\n$$\\because ab \\ll V^2$$\n\\begin{equation}\n  PV = RT + bP - \\frac{a}{V} \\label{eq:i2}\n\\end{equation}\nUsing \\eqref{eq:i2} in \\eqref{eq:i1},\n$$W = RT + bP_2 - \\frac{a}{V_2} - RT - bP_1 + \\frac{a}{V_1} - \\frac{a}{V_2} + \\frac{a}{V_1}$$\n\\begin{equation}\n  W = (P_2 - P_1)b + 2a \\left(\\frac{1}{V_1} - \\frac{1}{V_2}\\right) \\label{eq:i3}\n\\end{equation}\nUsing $PV=RT$,\n\\begin{equation}\n  V_1 = \\frac{RT}{P_1} , V_2 = \\frac{RT}{P_2} \\label{eq:i4}\n\\end{equation}\nUsing \\eqref{eq:i4} in \\eqref{eq:i3},\n$$W = (P_2 - P_1)b + \\frac{2a}{RT}(P_1 - P_2)$$\n$$W = (P_1 - P_2) \\left[ \\frac{2a}{RT} - b \\right]$$\nW = 0 when $T=T_i$\\\\\n\\[ \\therefore \\boxed{T_i = \\frac{2a}{Rb}} \\label{eq:i5} \\tag{3.5} \\]\n\n\\section{Relationship between $T_b$,$T_c$ and $T_i$}\nUsing \\eqref{eq:b1}, \\eqref{eq:c7} and \\eqref{eq:i5},\n$$T_c < T_b < T_i$$\n\n\\section{Maxwell's Relations}\nFrom first law of thermodynamics,\n\\begin{equation}\n  dU = TdS - PdV \\label{eq:m1}\n\\end{equation}\nwe can write\n$$T = \\frac{\\partial U}{\\partial S} , P = -\\frac{\\partial U}{\\partial T} $$\nwe can write U, S and V as functions of x and y where x and y are any of P, V, S or T,\n\\begin{equation}\n  dU = \\frac{\\partial U}{\\partial x}dx + \\frac{\\partial U}{\\partial y}dy \\label{eq:m2}\n\\end{equation}\n\\begin{equation}\n  dS = \\frac{\\partial S}{\\partial x}dx + \\frac{\\partial S}{\\partial y}dy \\label{eq:m3}\n\\end{equation}\n\\begin{equation}\n  dV = \\frac{\\partial V}{\\partial x}dx + \\frac{\\partial V}{\\partial y}dy \\label{eq:m4}\n\\end{equation}\n\nusing \\eqref{eq:m2}, \\eqref{eq:m3} and \\eqref{eq:m4} in \\eqref{eq:m1},\n\\begin{equation}\n\\frac{\\partial U}{\\partial x}dx + \\frac{\\partial U}{\\partial y}dy = T\\left[\\frac{\\partial S}{\\partial x}dx + \\frac{\\partial S}{\\partial y}dy \\right] - P\\left[\\frac{\\partial V}{\\partial x}dx + \\frac{\\partial V}{\\partial y}dy\\right] \\label{eq:m5}\n\\end{equation}\n\nequating $dx$ terms of \\eqref{eq:m5},\n\\begin{equation}\n  \\frac{\\partial U}{\\partial x} = T\\frac{\\partial S}{\\partial x} - P\\frac{\\partial V}{\\partial x} \\label{eq:m6}\n\\end{equation}\ndifferentiating \\eqref{eq:m6} w.r.t. $y$,\n\\begin{equation}\n  \\frac{\\partial^2 U}{\\partial y \\partial x} = \\left(\\frac{\\partial T}{\\partial y}\\right)_x \\left(\\frac{\\partial S}{\\partial x}\\right)_y + T\\frac{\\partial^2 S}{\\partial y \\partial x} - \\left(\\frac{\\partial P}{\\partial y}\\right)_x \\left(\\frac{\\partial V}{\\partial x}\\right)_y - P\\frac{\\partial^2 V}{\\partial y \\partial x} \\label{eq:m7}\n\\end{equation}\n\nequating $dy$ terms of \\eqref{eq:m5},\n\\begin{equation}\n  \\frac{\\partial U}{\\partial y} = T\\frac{\\partial S}{\\partial y} - P\\frac{\\partial V}{\\partial y} \\label{eq:m8}\n\\end{equation}\ndifferentiating \\eqref{eq:m8} w.r.t. $x$,\n\\begin{equation}\n  \\frac{\\partial^2 U}{\\partial x \\partial y} = \\left(\\frac{\\partial T}{\\partial x}\\right)_y \\left(\\frac{\\partial S}{\\partial y}\\right)_x + T\\frac{\\partial^2 S}{\\partial x \\partial y} - \\left(\\frac{\\partial P}{\\partial x}\\right)_y \\left(\\frac{\\partial V}{\\partial y}\\right)_x - P\\frac{\\partial^2 V}{\\partial x \\partial y} \\label{eq:m9}\n\\end{equation}\n\nfor a continuous function, F we have,\n$$\\frac{\\partial^2 F}{\\partial x \\partial y}=\\frac{\\partial^2 F}{\\partial y \\partial x}$$\n$\\therefore$ from \\eqref{eq:m7} and \\eqref{eq:m9},\n\\begin{equation}\n  \\left(\\frac{\\partial T}{\\partial y}\\right)_x \\left(\\frac{\\partial S}{\\partial x}\\right)_y - \\left(\\frac{\\partial P}{\\partial y}\\right)_x \\left(\\frac{\\partial V}{\\partial x}\\right)_y = \\left(\\frac{\\partial T}{\\partial x}\\right)_y \\left(\\frac{\\partial S}{\\partial y}\\right)_x - \\left(\\frac{\\partial P}{\\partial x}\\right)_y \\left(\\frac{\\partial V}{\\partial y}\\right)_x \\label{eq:m10}\n\\end{equation}\n\n\\subsection{Equation I}\nUsing $x=P$ and $y=V$ in \\eqref{eq:m10},\n$$ \\left(\\frac{\\partial T}{\\partial V}\\right)_P \\left(\\frac{\\partial S}{\\partial P}\\right)_V - \\left(\\frac{\\partial P}{\\partial V}\\right)_P \\left(\\frac{\\partial V}{\\partial P}\\right)_V = \\left(\\frac{\\partial T}{\\partial P}\\right)_V \\left(\\frac{\\partial S}{\\partial V}\\right)_P - \\left(\\frac{\\partial P}{\\partial P}\\right)_V \\left(\\frac{\\partial V}{\\partial V}\\right)_P $$\n$$\\boxed{\\left(\\frac{\\partial T}{\\partial P}\\right)_V \\left(\\frac{\\partial S}{\\partial V}\\right)_P - \\left(\\frac{\\partial T}{\\partial V}\\right)_P \\left(\\frac{\\partial S}{\\partial P}\\right)_V = 1}$$\n\n\\subsection{Equation II}\nUsing $x=P$ and $y=S$ in \\eqref{eq:m10},\n$$ \\left(\\frac{\\partial T}{\\partial S}\\right)_P \\left(\\frac{\\partial S}{\\partial P}\\right)_S - \\left(\\frac{\\partial P}{\\partial S}\\right)_P \\left(\\frac{\\partial V}{\\partial P}\\right)_S = \\left(\\frac{\\partial T}{\\partial P}\\right)_S \\left(\\frac{\\partial S}{\\partial S}\\right)_P - \\left(\\frac{\\partial P}{\\partial P}\\right)_S \\left(\\frac{\\partial V}{\\partial S}\\right)_P$$\n$$\\boxed{\\left(\\frac{\\partial T}{\\partial P}\\right)_S = \\left(\\frac{\\partial V}{\\partial S}\\right)_P}$$\n\n\\subsection{Equation III}\nUsing $x=P$ and $y=T$ in \\eqref{eq:m10},\n$$\\left(\\frac{\\partial T}{\\partial T}\\right)_P \\left(\\frac{\\partial S}{\\partial P}\\right)_T - \\left(\\frac{\\partial P}{\\partial T}\\right)_P \\left(\\frac{\\partial V}{\\partial P}\\right)_T = \\left(\\frac{\\partial T}{\\partial P}\\right)_T \\left(\\frac{\\partial S}{\\partial T}\\right)_P - \\left(\\frac{\\partial P}{\\partial P}\\right)_T \\left(\\frac{\\partial V}{\\partial T}\\right)_P$$\n$$\\boxed{\\left(\\frac{\\partial S}{\\partial P}\\right)_T = - \\left(\\frac{\\partial V}{\\partial T}\\right)_P}$$\n\n\\subsection{Equation IV}\nUsing $x=V$ and $y=S$ in \\eqref{eq:m10},\n$$\\left(\\frac{\\partial T}{\\partial S}\\right)_V \\left(\\frac{\\partial S}{\\partial V}\\right)_S - \\left(\\frac{\\partial P}{\\partial S}\\right)_V \\left(\\frac{\\partial V}{\\partial V}\\right)_S = \\left(\\frac{\\partial T}{\\partial V}\\right)_S \\left(\\frac{\\partial S}{\\partial S}\\right)_V - \\left(\\frac{\\partial P}{\\partial V}\\right)_S \\left(\\frac{\\partial V}{\\partial S}\\right)_V$$\n$$\\boxed{\\left(\\frac{\\partial P}{\\partial S}\\right)_V = - \\left(\\frac{\\partial T}{\\partial V}\\right)_S}$$\n\n\\subsection{Equation V}\nUsing $x=V$ and $y=T$ in \\eqref{eq:m10},\n$$\\left(\\frac{\\partial T}{\\partial T}\\right)_V \\left(\\frac{\\partial S}{\\partial V}\\right)_T - \\left(\\frac{\\partial P}{\\partial T}\\right)_V \\left(\\frac{\\partial V}{\\partial V}\\right)_T = \\left(\\frac{\\partial T}{\\partial V}\\right)_T \\left(\\frac{\\partial S}{\\partial T}\\right)_V - \\left(\\frac{\\partial P}{\\partial V}\\right)_T \\left(\\frac{\\partial V}{\\partial T}\\right)_V$$\n$$\\boxed{\\left(\\frac{\\partial S}{\\partial V}\\right)_T = \\left(\\frac{\\partial P}{\\partial T}\\right)_V}$$\n\n\\subsection{Equation VI}\nUsing $x=S$ and $y=T$ in \\eqref{eq:m10},\n$$\\left(\\frac{\\partial T}{\\partial T}\\right)_S \\left(\\frac{\\partial S}{\\partial S}\\right)_T - \\left(\\frac{\\partial P}{\\partial T}\\right)_S \\left(\\frac{\\partial V}{\\partial S}\\right)_T = \\left(\\frac{\\partial T}{\\partial S}\\right)_T \\left(\\frac{\\partial S}{\\partial T}\\right)_S - \\left(\\frac{\\partial P}{\\partial S}\\right)_T \\left(\\frac{\\partial V}{\\partial T}\\right)_S$$\n$$\\boxed{\\left(\\frac{\\partial P}{\\partial T}\\right)_S \\left(\\frac{\\partial V}{\\partial S}\\right)_T - \\left(\\frac{\\partial P}{\\partial S}\\right)_T \\left(\\frac{\\partial V}{\\partial T}\\right)_S = 1}$$\n\n\\section{Statistical Mechanics}\n\\subsection{Fundamental Postulates of Statistical Mechanics}\n\\begin{itemize}\n\\item Any gas under consideration may be considered to be composed of large number of molecules which are constantly in motion and behave like very small elastic spheres.\n\\item All the cells in phase space are of equal size.\n\\item All accessible microstates corresponding to possible macrostates are equally probable.\n\\item The equilibrium state of a gas corresponds to the macrostate of maximum probability.\n\\item The total number of molecules is constant.\n\\item The total energy of the system is constant.\n\\end{itemize}\n\n\\subsection{Types of particles}\n\\subsubsection{Maxwell-Boltzmann Statistics}\nUsed to describe identical, distinguishable particles.\n\\subsubsection{Fermi-Dirac Statistics}\nUsed to describe identical, non-distinguishable particles with half-integral spins, i.e., $\\frac{1}{2}$,$\\frac{3}{2}$,etc...\\\\\nExamples include electron, positron.\n\\subsubsection{Bose-Einstein Statistics}\nUsed to describe identical, non-distinguishable particles with integral spins, i.e., 0,1,2,etc...\\\\\nExamples include photon, W boson.\n\n\\section{Maxwell-Boltzmann Energy Distribution Law}\nSuppose the particles are distributed among $k$ energy levels $E_1,E_2,\\dots,E_i,\\dots,E_k$. Let $n_1,n_2,\\dots,n_i,\\dots,n_k$ be the number of independent quantum states associated with the energy levels. According to the basic statistical postulates\n\\begin{equation}\n  N = n_1 + n_2 + \\dots + n_i + \\dots + n_k = \\sum_i n_i \\label{eq:mb1}\n\\end{equation}\nand since the force of interation between particles are negligible, we have\n\\begin{equation}\n  U = n_1 E_1 + n_2 E_2 + \\dots + n_i E_i + \\dots + n_k E_k \\label{eq:mb2}\n\\end{equation}\nTaking differential of equation \\eqref{eq:mb1} and \\eqref{eq:mb2}, we have\n\\begin{equation}\n  dN = \\sum_i dn_i = 0 \\label{eq:mb3}\n\\end{equation}\nand\n\\begin{equation}\n  dU = \\sum_i E_i dn_i = 0 \\label{eq:mb4}\n\\end{equation}\n\\subsection{Maxwell-Boltzmann Statistical Count}\nThe number of ways of choosing $n_1$ particles for the first energy level($E_1$) is, thus, given by\n$$x_1 = \\frac{N!}{n_1!(N-n_1)!} = {}^NC_{n_1}$$\nFor the second state $E_2$, only $(N-n_1)$ particles are available and $n_2$ particles are in state $E_2$. The number of independent ways of choosing $n_2$ particles for the second energy level is\n$$x_2 = \\frac{(N-n_1)!}{n_2! (N-n_1-n_2)!} = {}^{N-n_1}C_{n_2}$$\nSimilarly for all energy levels. For the $k^{th}$ energy level we have\n$$x_k = \\frac{(N-n_1-n_2-\\dots n_{k-1})!}{n_k! (N-n_1-n_2-\\dots n_k)!} = {}^{(N-n_1-n_2-\\dots n_{k-1})} C_{n_k}$$\nSince these numbers are independent, the number of distinct ways of obtaining the distribution of particles among energy levels is given by\n$$x = x_1 x_2 x_3 \\dots x_i \\dots x_k$$\n\\begin{equation}\n  x = \\frac{N!}{n_1! n_2! \\dots n_k!} \\label{eq:mb5}\n\\end{equation}\nNow our next job is to find the number of independent ways in which the particles in the various energy level can be distributed among the quantum states in the respective levels. For example, in the energy level, containing $n_i$ particles, there are $g_i$ quantum states. Each of the $n_i$ particles can be in any one of the quantum states. Hence there are $g_i^{n_i}$ ways of arranging $n$ particles among $g_i$ quantum states available in the $i^{th}$ energy level.\n$$W = \\frac{N!}{n_1! n_2! \\dots n_k!} \\times g_1^{n_1} \\times g_2^{n_2} \\times \\dots g_k^{n_k}$$\n\\begin{equation}\n  W = N! \\prod_{i=1}^{k} \\left[\\frac{g_i^{n_i}}{n_i!}\\right] \\label{eq:mb6}\n\\end{equation}\n\\subsection{Condition for most probable distribution}\nThe most probable distribution of the particles among the energy states in equilibrium is that for which the probability of occurence is maximum, i.e. for which \\textbf{W is maximum}. For mathematical convenience, we consider the condition for maximum value of $\\log W$. The condition for maximum value of $\\log W$ is\n\\begin{equation}\n  d(\\log W) = 0 \\label{eq:mb7}\n\\end{equation}\nwhere W is a function of $n_1,n_2,\\dots,n_k$.\\\\\nDifferentiating equation \\eqref{eq:mb6}, we get\n\\begin{align*}\n  d(\\log W) &= \\frac{\\partial \\log W}{\\partial n_1}dn_1 + \\frac{\\partial \\log W}{\\partial n_2}dn_2 + \\dots + \\frac{\\partial \\log W}{\\partial n_k}dn_k\\\\\n  &= \\sum_{i=1}^{k} \\frac{\\partial \\log W}{\\partial n_i}dn_i\n\\end{align*}\nApplying the condition from equation \\eqref{eq:mb7}, we get\n\\begin{equation}\n  \\sum_{i=1}^{k} \\frac{\\partial \\log W}{\\partial n_i}dn_i = 0 \\label{eq:mb8}\n\\end{equation}\nThe solution of this equation is subject to the condition laid down by \\eqref{eq:mb3} and \\eqref{eq:mb4}. These conditions are introduced into equation \\eqref{eq:mb8} by using the method of Lagrange's undetermined multipliers.\\\\\nLet $\\alpha$ and $\\beta$ be these multipliers independent of $n_i$'s. We multiply \\eqref{eq:mb3} by $-\\alpha$ and \\eqref{eq:mb4} by $-\\beta$ and adding these equations to \\eqref{eq:mb8}, we have\n\\begin{equation}\n  \\sum_{i=1}^{k}\\left(\\frac{\\partial \\log W}{\\partial n_i} - \\alpha - \\beta E_i\\right)dn_i \\label{eq:mb9}\n\\end{equation}\n\\subsection{M-B Energy Distribution Law in General Form}\nTaking logarithms of \\eqref{eq:mb6}, we have\n\\begin{align*}\n  \\log W &= \\log N! + \\log \\left[\\prod_i \\left(\\frac{g_i^{n_i}}{n_i!}\\right)\\right]\\\\\n  &= \\log N! + \\sum_{i=1}^{k} \\left(n_i \\log g_i - \\log n_i!\\right)\n\\end{align*}\nUsing sterlings formula, $\\log x! = x(\\log x - 1)$\n\\begin{equation}\n  \\log W = N \\log N - N + \\sum_{i=1}^{k}(n_i \\log g_i - n_i \\log n_i + n_i) \\label{eq:mb10}\n\\end{equation}\nDifferentiating \\eqref{eq:mb10} w.r.t. $n_i$,\n$$\\frac{d(\\log W)}{dn_i} = \\sum\\left[\\log g_i - \\log n_i\\right]\\delta n_i$$\n\\begin{equation}\n  \\frac{d(\\log W)}{dn_i} = \\sum\\left[-\\log\\left(\\frac{n_i}{g_i}\\right)\\right]\\label{eq:mb11}\n\\end{equation}\nSubstituting \\eqref{eq:mb11} in \\eqref{eq:mb9},\n$$\\sum\\left[-\\log\\left(\\frac{n_i}{g_i}\\right) - \\alpha - \\beta E_i\\right]\\delta n_i = 0$$\n$$\\log\\left(\\frac{n_i}{g_i}\\right) = -\\alpha -\\beta E_i$$\n$$n_i = g_i e^{-\\alpha-\\beta E_i}$$\n\\begin{equation}\n  n_i = g_i e^{-\\alpha} e^{-\\beta E_i} \\label{eq:mb12}\n\\end{equation}\nwhere $i=1,2,3,\\dots k$\\\\\nThis equation is known as \\textbf{Maxwell-Boltzmann energy distribution law} in the general form.\\\\\nThe value of $\\beta$ is evaluated to be\n$$\\beta = \\frac{1}{kT}$$\nSubstituting in \\eqref{eq:mb12} we get\n$$n_i = g_i e^{-\\alpha} e^{-\\frac{E_i}{kT}}$$\nwhere $k$ is the Boltzmann  constant and T is the absolute temperature. The quantity $e^{-\\frac{E_i}{kT}}$ is known as the \\textbf{Boltzmann factor}.\nFrom the fundamental postulates of statistical mechanics, we write,N, the total number of particles as\n\\begin{align*}\n  N &= \\sum_i n_i\\\\\n  &= \\sum_i g_i e^{-\\alpha} e^{\\frac{-E_i}{kT}}\n\\end{align*}\n\\begin{equation}\n  e^{-\\alpha} = \\frac{N}{\\sum_i g_i e^{\\frac{-E_i}{kT}}} \\label{eq:mb13}\n\\end{equation}\nThe quantity $\\sum_i g_i e^{\\frac{-E_i}{kT}}$ is the sum over all the states of the system and is called the \\textbf{partition function} of the system denoted by Z. Thus\n$$Z = \\sum_i g_i e^{\\frac{-E_i}{kT}}$$\nSubstituting in \\eqref{eq:mb12}, we have\n$$n_i = \\frac{N}{Z} g_i e^{\\frac{-E_i}{kT}}$$\n\\subsection{Maxwell-Boltzmann Speed Distribution Law}\nThe Maxwell-Boltzmann equation for distribution of energy among the molecules of an ideal gas is given by\n$$n(E) dE = \\frac{2\\pi N}{(\\pi kT)^{3/2}} E^{\\frac{1}{2}} e^{\\frac{-E}{kT}}dE$$\n\n\\end{document}\n", "meta": {"hexsha": "2b2b53de61959dab4518d50a46b0a427d5be9120", "size": 18497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thermodynamics/thermodynamics.tex", "max_stars_repo_name": "evans-0/Latex_documents", "max_stars_repo_head_hexsha": "d82b900c5573282daca41609dce3884086a42e20", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thermodynamics/thermodynamics.tex", "max_issues_repo_name": "evans-0/Latex_documents", "max_issues_repo_head_hexsha": "d82b900c5573282daca41609dce3884086a42e20", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thermodynamics/thermodynamics.tex", "max_forks_repo_name": "evans-0/Latex_documents", "max_forks_repo_head_hexsha": "d82b900c5573282daca41609dce3884086a42e20", "max_forks_repo_licenses": ["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.4029411765, "max_line_length": 469, "alphanum_fraction": 0.6718386765, "num_tokens": 6954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6227317445455798}}
{"text": "\\chapter{Type Systems}\n\nA \\textbf{Type System}\\cite{typesystems} for any programming language is a set of rules that associate a property called \"\\textit{Type}\" with the basic grammatical constructs of the language like variables, constants, statements and commands. It is the computer programming equivalent of type theory which uses type safety and type validation to prevent bugs, compiler runtime errors and compiler optimizations. It is very basic for any programming language to have types to actually perform any of \\underline{Higher Order Logic} on the host machine. Note that a type system can work only if the program is run. In other words it is absolutely insignificant to check a program if it is not run or atleast compiled to be run.\\\\\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Dependent Types }\n\\textbf{Dependent Types} \\cite{dependent_types} is the most important kind of Types whose definition depends on a value. It is the conceptual overlap between computer's Type System and Type theory as it allows evaluation by induction. In functional Programming languages, dependent types increases expressivity of a defined type. It's examples include dependent functions and dependent pairs. Introduction of new variable or new values may completely change the overall behaviour. Thus the Structual Type checking would be used and not nominal (defined below). It is considered to be of two types from mathematical point of view : \\\\\n\n\\begin{itemize}\n\t\\item{\n\t\\subsection{ $\\Pi$-Type}\n\tIt is called \\textbf{Dependent Product Type} where given a type space $\\Omega$, we define a family of types B:A$\\rightarrow$ $\\Omega$ that says every term a:A has a type B(a):$\\Omega$. It explains that there is not a fixed co-domain for functions of this type. The name 'pi-type' comes from the idea that these may be viewed as a Cartesian product of types. Pi-types can also be understood as models of universal quantifiers. For an example let's say a function gives tuple of order n for a given natural number input n. Clearly the terms in that tuple does not depend on the value of n. Here also, the Dependent product nature is preserved.\\\\   \n\t}\n\t\\item{\n\t\\subsection{ $\\Sigma$-Type}\n\tIt is called \\textbf{Dependent Sum Type} and is \\underline{categorically dual} to dependent product type where given a type space $\\Omega$, if we have a family of types B:A$\\rightarrow$ $\\Omega$ then there must exist a dependent pair type. It explains that there should be fixed codomain for any function. \\\\ \n\t}\n\\end{itemize}\n\nThey use mathematical operators ($\\rightarrow$) and binders ($\\forall$) to produce complex types. The higher order \\textbf{Dependently Typed Polymorphic lambda calculus} also called \\textbf{Calculus of Inductive Constructions} is the foundational basis of all Proof Assistants.\n\n\\section{Flow-Sensitive Types}\nSuch Type systems determine the type of a variable by controlflow. The type of a variable may change in any of the program's method. The type inference (defined below) is used for checking these type systems.\n\n\\section{Latent Types}\nLatent typing refers to a type system where types are associated with values and not variables.\n\n\\section{Refinement Types}\nThese are a set of some preconditions that define the behaviour of the function or variable. These can be understood as the return types of most of functions which may dpend on some 'if/else' conditions.\n\n\\section{Substructural Types}\nThis is the type system defined depending on the use of a variable. For exmaple, a variable may be used once or many times. It has \\textbf{Linear}, \\textbf{Affine}, \\textbf{Relevant} and \\textbf{Ordered} as subcategories. The Linear system allows the use of object exactly once, Affine system allows use atmost once, Relevant system allows usage any number of times and Order system allows using objects only once in an order.\n\n\\section{Unique Types}\nA Unique type guarantees that an object is used in a single-threaded way only with maximum one reference to it. It mantains the referntial transparency and improves the efficieny of functional languages.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Type Safety \\& Memory Safety }\nType safety refers to type equivalence and behavioural equivalence of all language constructs for a given program written in any programming language. Memory safety on the other hand refers to leakage and corruption of memory by any program. example : stack overflow.\\\\\n\n%% Major Categories in Type Systems %%\nSome Type checking techniques to ensure type safety are :\n\n\\begin{itemize} \n\\item {\\section*{Static vs Dynamic}\n\nA \\textbf{Static} type system refers to compilation time type checking. The source code's type correctness is verified first and then the executable is generated. A \\textbf{Dynamic} type system checks type correctness during the runtime. This is the case when bindings and linking are created so that data passed on from one of the program to other is correct type-wise. Together both create polymorphic type checking where a single interface or a single Type check-pass is capable of doing both kind of type checks and is very portable to use. \\\\}\n\n\\item {\n\\section*{Nominal vs Structural}\nIn a \\textbf{Nominal} or \\textbf{Nominative} type system, the equivalence of data types is determined by explicit declarations or name of types. For example, in C programming language, two \"\\textit{struct} types with different names in the same translation unit are never considered compatible, even if they have identical field declarations. In \\textbf{Structural} type system, the inner structure of a data type are evaluated  to show data equivalence and type safety. }\n\n\\item{\n\\section*{Manifest vs Inferred}\n\\textbf{Manifest} Typing is explicit identification by the software programmer of the type of each variable being declared. For example: if variable X is going to store integers then its type must be declared as integer. Type \\textbf{Inference} refers to the automatic detection of the data type of an expression in a programming language. For example, user may write a float point decimal without having declared that variable as a float point. The compiler technology should be able to detect what program is trying to do and perform further actions accordingly. This is also referred to as \\textbf{Typeless Typeing} where the type is later introduced depending on data passed.\\\\ }\n\n\\item{\n\\section*{Duck Type-ing}\nThis type system got it's name from on of the most common computer engineering practices which says if something behaves like a duck, quacks like aduck then it must be duck. In other words the behaviour determines the data type. For example, adding a float type integer to a double type integer, the answer should have a double type because it is surely to have characteristics of a double type integer.\\\\}\n\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Unified Type System}\nIn the object oriented programming (OOP) context, the abstraction and scope of methods deals with it's derivation from a base class. similar logic can be extended to class objects whose properties and methods depends on a base class. A \\textbf{Unified Type System} states that all the Types of objects are derived from a single root type. Thus that object is capable of performing operations approved by the root type. Example of such a programming language is C\\# developed by Microsoft.  In C\\# the concepts of encapsulation and methods have been decoupled from the reference requirement so that a type can support methods and encapsulation without being a \\textbf{Reference type}. A reference type is also an OOP concept that says all instances of class objects are by reference. \\\\\n\n", "meta": {"hexsha": "8e311544896b3c424be05466d5f3f582bd70545f", "size": 7698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/type-systems.tex", "max_stars_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_stars_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_stars_repo_licenses": ["MIT"], "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/type-systems.tex", "max_issues_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_issues_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_issues_repo_licenses": ["MIT"], "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/type-systems.tex", "max_forks_repo_name": "SatyendraBanjare/Type-Theory-notes", "max_forks_repo_head_hexsha": "2228194ff7debdf414f78d7e190279908c797025", "max_forks_repo_licenses": ["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.5652173913, "max_line_length": 785, "alphanum_fraction": 0.7809820733, "num_tokens": 1631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6227317374432451}}
{"text": "\\section{Other Coordinate Systems}\\label{sec:3Dothercoordsystem}\n\nCoordinate systems are tools that let us use algebraic methods to\nunderstand geometry. While the \\dfont{rectangular} (also called\n\\dfont{Cartesian}) coordinates that we\nhave been discussing are the most common, some problems are easier to\nanalyze in alternate coordinate systems.\\index{Cartesian coordinates}\n\nA coordinate system is a scheme that allows us to identify any point\nin the plane or in three-dimensional space by a set of numbers. In\nrectangular coordinates these numbers are interpreted, roughly\nspeaking, as the lengths of the sides of a rectangular ``box.''\n\nIn two dimensions you may already be familiar with an alternative,\ncalled \\dfont{polar coordinates}\\index{polar coordinates}. In this system, each\npoint in the plane is identified by a pair of numbers $(r,\\theta)$.\nThe number $\\theta$ measures the counter-clockwise angle between the positive\n$x$-axis and a vector with tail at the origin and head at the\npoint, as shown in Figure~\\ref{fig:polar coordinates}; the number\n$r$ measures the distance from the origin to the\npoint. Either of these may be negative; a negative $\\theta$ indicates\nthe angle is measured clockwise from the positive\n$x$-axis instead of counter-clockwise, and a negative $r$ indicates\nthe point at distance $|r|$ in the opposite of the direction given by\n$\\theta$. \n\nThe relationship between polar and rectangular coordinates is given by\\index{polar coordinates!convert to rectangular}\n\\begin{align*}\nx = r \\cos \\theta \\\\\ny = r \\sin \\theta \n\\end{align*}\nand\n\\begin{align*}\nr = \\sqrt{x^2 + y^2} \\\\\n\\tan \\theta = \\frac{y}{x} \n\\end{align*}\n\n\\begin{example}{Rectangular to Polar Coordinates}{}\nConvert the point $(x,y) = (1, \\sqrt3)$ into polar coordinates.\n\\end{example}\n\n\\begin{solution}\nFirst calculate $r$:\n\\[\nr = \\sqrt{x^2 + y^2} = \\sqrt{ 1 + 3} = 2\n\\]\nNow find $\\theta$ such that $\\tan \\theta = \\frac{\\sqrt{3}}{1}$. The required $\\theta$ is $\\frac{\\pi}{3}$. \n\nThe polar coordinates are $(2, \\frac{\\pi}{3})$. \n\\end{solution}\n\nFigure~\\ref{fig:polar coordinates} also shows the point with\nrectangular coordinates $(1,\\sqrt3)$ and polar coordinates \n$(2,\\pi/3)$, 2 units from the origin and $\\pi/3$ radians from the\npositive $x$-axis.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <15truemm,15truemm>\n\\setplotarea x from 0 to 1.3, y from 0 to 2\n\\axis left /\n\\axis bottom /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1 1.73\n\\put {$x$} [l] <3pt,0pt> at 1.3 0\n\\put {$y$} [b] <0pt,3pt> at 0 2\n\\put {$(r,\\theta)$} [l] <3pt,0pt> at 1 1.73\n\\put {$r$} [br] <-2pt,2pt> at 0.5 0.86\n\\put {$\\theta$} [bl] <2pt,0pt> at 0.173 0.1\n\\arrow <4pt> [0.35,1] from 0.5 -0.2 to 0 -0.2\n\\arrow <4pt> [0.35,1] from 0.5 -0.2 to 1 -0.2\n\\put {$r\\cos\\theta$} at 0.5 -0.4\n\\put {$r\\sin\\theta$} [l] <3pt,0pt> at 1 0.86\n%\\put {$\\ds{\\pi\\over 3}$} [bl] <2pt,2pt> at 0.2 0\n\\circulararc 60 degrees from 0.2 0 center at 0 0\n\\setdashes\n\\plot 1 0 1 1.73 /\n\\setsolid\n\\setcoordinatesystem units <15truemm,15truemm> point at -3 0\n\\setplotarea x from 0 to 1.3, y from 0 to 2\n\\axis left /\n\\axis bottom /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1 1.73\n\\put {$x$} [l] <3pt,0pt> at 1.3 0\n\\put {$y$} [b] <0pt,3pt> at 0 2\n\\put {$(2,\\pi/3)$} [l] <3pt,0pt> at 1 1.73\n\\put {$\\pi/3$} [bl] <2pt,0pt> at 0.173 0.1\n\\circulararc 60 degrees from 0.2 0 center at 0 0\n\\setdashes\n\\endpicture}}\n\\caption{Polar coordinates: the general case and\nthe point with rectangular coordinates $(1,\\sqrt3)$. \\label{fig:polar coordinates}}\n\\end{figure}\n\nWe can extend polar coordinates to three dimensions simply by adding a\n$z$ coordinate; this is called \\dfont{cylindrical coordinates}\\index{cylindrical coordinates}.\nEach point in three-dimensional space is represented by three\ncoordinates $(r,\\theta,z)$ in the obvious way: this point is $z$ units\nabove or below the point $(r,\\theta)$ in the $x$-$y$ plane,\nas shown in Figure~\\ref{fig:cylindrical coordinates}. The point\nwith rectangular coordinates $(1,\\sqrt3, 3)$ and cylindrical\ncoordinates $(2,\\pi/3,3)$ is also indicated\nin Figure~\\ref{fig:cylindrical coordinates}.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <10truemm,10truemm>\n\\setplotarea x from 0 to 2, y from -1 to 3.3\n\\axis bottom shiftedto y=0 /\n\\putrule from 0 0 to 0 3.3\n\\plot 0 0 -1 -1 /\n\\arrow <4pt> [0.35,1] from 0 0 to 1.5  -0.7\n\\put {$(r,\\theta,z)$} [l] <3pt,0pt> at 1.5 2.3\n\\put {$\\bullet$} at 1.5 2.3\n\\put {$z$} [b] <0pt,3pt> at 0 3.3\n\\put {$x$} [tr] <-3pt,-3pt> at -1 -1\n\\put {$y$} [l] <3pt,0pt> at 2 0\n\\put {$\\theta$} [t] <0pt,-3pt> at 0 -0.3\n\\put {$z$} [l] <3pt,0pt> at 1.5 1\n\\put {$r$} [tr] <-2pt,-2pt> at 1 -0.467\n\\circulararc 110 degrees from -0.2 -0.2 center at 0 0\n\\setdashes\n\\plot 1.5 -0.7 1.5 2.3 /\n\\setcoordinatesystem units <10truemm,10truemm> point at -5 0\n\\setplotarea x from 0 to 2, y from -1 to 3.3\n\\axis bottom shiftedto y=0 /\n\\putrule from 0 0 to 0 3.3\n\\plot 0 0 -1 -1 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.5 -0.7\n\\put {$(2,\\pi/3,3)$} [l] <3pt,0pt> at 1.5 2.3\n\\put {$\\bullet$} at 1.5 2.3\n\\put {$z$} [b] <0pt,3pt> at 0 3.3\n\\put {$x$} [tr] <-3pt,-3pt> at -1 -1\n\\put {$y$} [l] <3pt,0pt> at 2 0\n\\put {$\\pi/3$} [t] <0pt,-3pt> at 0 -0.3\n\\circulararc 110 degrees from -0.2 -0.2 center at 0 0\n%\\put {$\\ds{\\pi\\over 3}$} [bl] <2pt,2pt> at 0.2 0\n\\setdashes\n\\plot 1.5 -0.7 1.5 2.3 /\n\\endpicture}}\n\\caption{Cylindrical coordinates: the general case\nand the point with rectangular coordinates $(1,\\sqrt3, 3)$. \\label{fig:cylindrical coordinates}}\n\\end{figure}\n\nSome figures with relatively complicated equations in rectangular\ncoordinates will be represented by simpler equations in cylindrical\ncoordinates. For example, the cylinder in Figure~\\ref{fig:cylinder}\nhas equation $x^2+y^2=4$ in rectangular coordinates, but equation\n$r=2$ in cylindrical coordinates.\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{\\epsfxsize7cm\\epsfbox{images/cylinder.eps}}} at 0 0\n\\endpicture}}\n\\caption{The cylinder $r=2$. \\label{fig:cylinder}}\n\\end{figure}\n\nGiven a point $(r,\\theta)$ in polar coordinates, it is easy \nto see  (as in Figure~\\ref{fig:polar coordinates}) that\nthe rectangular coordinates of the same point are\n$(r\\cos\\theta,r\\sin\\theta)$, and so the point $(r,\\theta,z)$ in\ncylindrical coordinates is $(r\\cos\\theta,r\\sin\\theta,z)$ in\nrectangular coordinates. This means it is usually easy to convert any\nequation from rectangular to cylindrical coordinates: simply substitute\\index{cylindrical coordinates!convert to rectangular}\n\\begin{align*}\n  x&=r\\cos\\theta\t\\\\\n  y&=r\\sin\\theta\n\\end{align*}\nand leave $z$ alone.\nFor example,\nstarting with $x^2+y^2=4$ and substituting $x=r\\cos\\theta$,\n$y=r\\sin\\theta$ gives \n\\begin{align*}\n  r^2\\cos^2\\theta+r^2\\sin^2\\theta&=4\t\\\\\n  r^2(\\cos^2\\theta+\\sin^2\\theta)&=4\t\\\\\n  r^2&=4\t\\\\\n  r&=2.\n\\end{align*}\nOf course, it's easy to see directly that this defines a cylinder as\nmentioned above.\n\nCylindrical coordinates are an obvious extension of polar coordinates\nto three dimensions, but the use of the $z$ coordinate means they are\nnot as closely analogous to polar coordinates as another standard\ncoordinate system. In polar coordinates, we identify a point by a\ndirection and distance from the origin; in three dimensions we can do\nthe same thing, in a variety of ways. The question is: how do we\nrepresent a direction? One way is to give the angle of rotation,\n$\\theta$, from the positive $x$ axis, just as in cylindrical\ncoordinates, and also an angle of rotation, $\\phi$, from the positive\n$z$ axis. Roughly speaking, $\\theta$ is like longitude and $\\phi$ is\nlike latitude. (Earth longitude is measured as a positive or negative\nangle from the prime meridian, and is always between 0 and 180\ndegrees, east or west; $\\theta$ can be any positive or negative angle,\nand we use radians except in informal circumstances. \nEarth latitude is measured north or south\nfrom the equator; $\\phi$ is measured from the north pole down.) This\nsystem is called \\dfont{spherical coordinates}\\index{spherical coordinates}; \nthe coordinates are listed in the order\n$(\\rho,\\theta,\\phi)$, where $\\rho$ is the distance from the\norigin, and like $r$ in polar and cylindrical coordinates it may be negative. \nThe general case and an\nexample are pictured in Figure~\\ref{fig:spherical coordinates}; the\nlength marked $r$ is the $r$ of cylindrical coordinates.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <10truemm,10truemm>\n\\setplotarea x from 0 to 2, y from -1 to 3.3\n\\axis bottom shiftedto y=0 /\n\\putrule from 0 0 to 0 3.3\n\\plot 0 0 -1 -1 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.5 -0.7\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.5 2.3\n\\put {$(\\rho,\\theta,\\phi)$} [l] <3pt,0pt> at 1.5 2.3\n\\put {$z$} [b] <0pt,3pt> at 0 3.3\n\\put {$x$} [tr] <-3pt,-3pt> at -1 -1\n\\put {$y$} [l] <3pt,0pt> at 2 0\n\\put {$\\theta$} [t] <0pt,-3pt> at 0 -0.3\n\\put {$\\phi$} [bl] <2pt,2pt> at 0 0.4\n\\put {$\\rho$} [tl] <2pt,2pt> at 0.75 1.15\n\\put {$r$} [tr] <-2pt,-2pt> at 1 -0.467\n\\circulararc 110 degrees from -0.2 -0.2 center at 0 0\n\\circulararc -32 degrees from 0 0.4  center at 0 0\n\\setdashes\n\\plot 1.5 -0.7 1.5 2.3 /\n\\setsolid\n\\setcoordinatesystem units <10truemm,10truemm> point at -5 0\n\\setplotarea x from 0 to 2, y from -1 to 3.3\n\\axis bottom shiftedto y=0 /\n\\putrule from 0 0 to 0 3.3\n\\plot 0 0 -1 -1 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.5 -0.7\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.5 2.3\n\\put {$(\\sqrt{13},\\pi/3,\\arctan(2/3))$} [l] <3pt,0pt> at 1.5 2.3\n\\put {$z$} [b] <0pt,3pt> at 0 3.3\n\\put {$x$} [tr] <-3pt,-3pt> at -1 -1\n\\put {$y$} [l] <3pt,0pt> at 2 0\n\\put {$\\pi/3$} [t] <0pt,-3pt> at 0 -0.3\n\\circulararc 110 degrees from -0.2 -0.2 center at 0 0\n\\circulararc -32 degrees from 0 0.4  center at 0 0\n%\\put {$\\ds{\\pi\\over 3}$} [bl] <2pt,2pt> at 0.2 0\n\\setdashes\n\\plot 1.5 -0.7 1.5 2.3 /\n\\endpicture}}\n\\caption{Spherical coordinates: the general case and the point \nwith rectangular coordinates $(1,\\sqrt3 , 3)$. \\label{fig:spherical coordinates}}\n\\end{figure}\n\nAs with cylindrical coordinates, we can easily convert equations\nin rectangular coordinates to the equivalent in spherical coordinates,\nthough it is a bit more difficult to discover the proper substitutions.\nFigure~\\ref{fig:rectangular to spherical coordinates} shows\nthe typical point in spherical coordinates from \nFigure~\\ref{fig:spherical coordinates},\nviewed now so that the arrow marked $r$ in the original graph appears as\nthe horizontal ``axis'' in the left hand graph. From this diagram it\nis easy to see that the $z$ coordinate is $\\rho\\cos\\phi$, and that \n$r=\\rho\\sin\\phi$, as shown. Thus, in converting from rectangular to\nspherical coordinates we will replace $z$ by $\\rho\\cos\\phi$. To see\nthe substitutions for $x$ and $y$ we now view the same point from\nabove, as shown in the right hand graph. The hypotenuse of the\ntriangle in the right hand graph\nis $r=\\rho\\sin\\phi$, so the sides of the triangle, as shown,\nare $x=r\\cos\\theta=\\rho\\sin\\phi\\cos\\theta$ and \n$y=r\\sin\\theta=\\rho\\sin\\phi\\sin\\theta$. Therefore to convert from rectangular to spherical coordinates,\nwe make these substitutions:\\index{spherical coordinates!convert to rectangular}\n\\begin{align*}\n  x&=\\rho\\sin\\phi\\cos\\theta\t\\\\\n  y&=\\rho\\sin\\phi\\sin\\theta\t\\\\\n  z&=\\rho\\cos\\phi.\n\\end{align*}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <10truemm,10truemm>\n\\setplotarea x from 0 to 2.3, y from -1 to 3.3\n\\axis bottom shiftedto y=0 /\n\\putrule from 0 0 to 0 3.3\n\\plot 0 0 2 3 /\n\\put {$(\\rho,\\theta,\\phi)$} [l] <3pt,0pt> at 2 3\n\\put {$z$} [b] <0pt,3pt> at 0 3.3\n\\put {$\\phi$} [bl] <2pt,2pt> at 0 0.4\n\\put {$\\rho$} [tl] <2pt,2pt> at 1 1.5\n\\circulararc -32 degrees from 0 0.4  center at 0 0\n\\put {$\\rho\\sin\\phi$} [t] <0pt,-3pt> at 1 0\n\\arrow <4pt> [0.35,1] from 0.3 -0.3 to 0 -0.3\n\\arrow <4pt> [0.35,1] from 1.7 -0.3 to 2 -0.3\n\\put {$\\rho\\sin\\phi$} at 1 3\n\\arrow <4pt> [0.35,1] from 0.3 3 to 0 3\n\\arrow <4pt> [0.35,1] from 1.7 3 to 2 3\n\\put {$\\rho\\cos\\phi$} [r] <-3pt,0pt> at 0 1.5\n\\arrow <4pt> [0.35,1] from -0.3 1.8 to -0.3 3\n\\arrow <4pt> [0.35,1] from -0.3 1.2 to -0.3 0\n\\setdashes\n\\plot 2 0 2 3 /\n\\setsolid\n\\setcoordinatesystem units <17truemm,17truemm> point at -3 0\n\\setplotarea x from 0 to 1.3, y from 0 to 2\n\\axis bottom shiftedto y=0 /\n\\axis left /\n\\plot 0 0 1 1.728 /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1 1.728\n%\\put {\\rotstart{-60 rotate}$\\rho\\sin\\phi$\\rotfinish} <3pt,-3pt> at 0.5 0.86\n\\put {$x$} [l] <3pt,0pt> at 1.3 0\n\\put {$y$} [b] <0pt,3pt> at 0 2\n\\put {$\\theta$} [bl] <2pt,2pt> at 0.346 0.2 \n\\put {$\\rho\\sin\\phi\\cos\\theta$} at 0.5 -0.4\n\\arrow <4pt> [0.35,1] from 0.5 -0.1 to 1 -0.1\n\\arrow <4pt> [0.35,1] from 0.5 -0.1 to 0 -0.1\n\\put {$\\rho\\sin\\phi\\sin\\theta$} [l] <3pt,0pt> at 1 0.85\n\\arrow <4pt> [0.35,1] from 1.3 1.1 to 1.3 1.728\n\\arrow <4pt> [0.35,1] from 1.3 0.5 to 1.3 0\n\\circulararc 60 degrees from 0.4 0 center at 0 0\n\\setdashes\n\\plot 1 0 1 1.728 /\n\\endpicture}}\n\\caption{Converting from rectangular to spherical coordinates. \\label{fig:rectangular to spherical coordinates}}\n\\end{figure}\n\nAs the cylinder had a simple equation in cylindrical coordinates, so\ndoes the sphere in spherical coordinates. \n\n\\begin{example}{}{}\nFind an equation for the sphere of radius $2$ in spherical coordinates. \n\\end{example}\n\n\\begin{solution}\nIf we start with the\nCartesian equation of the sphere and substitute, we get the spherical\nequation: \n\\begin{align*}\n  x^2+y^2+z^2&=2^2\t\\\\\n  \\rho^2\\sin^2\\phi\\cos^2\\theta+\n     \\rho^2\\sin^2\\phi\\sin^2\\theta+\\rho^2\\cos^2\\phi&=2^2\t\\\\\n  \\rho^2\\sin^2\\phi(\\cos^2\\theta+\\sin^2\\theta)+\\rho^2\\cos^2\\phi&=2^2\t\\\\\n  \\rho^2\\sin^2\\phi+\\rho^2\\cos^2\\phi&=2^2\t\\\\\n  \\rho^2(\\sin^2\\phi+\\cos^2\\phi)&=2^2\t\\\\\n  \\rho^2&=2^2\t\\\\\n  \\rho&=2\n\\end{align*}\nTherefore, in spherical coordinates, a sphere of radius $2$ is expressed $\\rho=2$.\n\\end{solution}\n\nAlthough not as simple as with cylindrical coordinates, we can use spherical coordinates to describe the equation of a cylinder.\n\n\\begin{example}{Cylinder Equation in Spherical Coordinates}{}\nFind an equation for the cylinder $x^2+y^2=4$ in spherical\ncoordinates.\n\\end{example}\n\\begin{solution}\nProceeding as in the previous example:\n\\begin{align*}\n  x^2+y^2&=4\t\\\\\n  \\rho^2\\sin^2\\phi\\cos^2\\theta+\n     \\rho^2\\sin^2\\phi\\sin^2\\theta=4\t\\\\\n  \\rho^2\\sin^2\\phi(\\cos^2\\theta+\\sin^2\\theta)&=4\t\\\\\n  \\rho^2\\sin^2\\phi&=4\t\\\\\n  \\rho\\sin\\phi&=2\t\\\\\n  \\rho&={2\\over\\sin\\phi}\n\\end{align*}\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:3Dothercoordsystem}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nConvert the following points in rectangular coordinates to\ncylindrical and spherical coordinates:\n\\begin{enumerate}\n\\item $(1,1,1)$\n\\item $(7,-7,5)$\n\\item $(\\cos(1),\\sin(1),1)$\n\\item $(0,0,-\\pi)$\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$\\ds (\\sqrt2,\\pi/4,1)$, $\\ds (\\sqrt3,\\pi/4,\\arccos(1/\\sqrt3))$\n\t\\item\t$\\ds (7\\sqrt2,7\\pi/4,5)$, $\\ds (\\sqrt{123},7\\pi/4,\\arccos(5/\\sqrt{123})$\n\t\\item\t$(1,1,1)$, $\\ds (\\sqrt2,1,\\pi/4)$\n\t\\item\t$(0,0,-\\pi)$, $(\\pi,0,\\pi)$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the sphere $x^2+y^2+z^2=4$ in\ncylindrical coordinates.\n\\begin{sol}\n\t$r^2+z^2=4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the $y$-$z$ plane in cylindrical\ncoordinates. \n\\begin{sol}\n\t$r\\cos\\theta=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation equivalent to $x^2+y^2+2z^2+2z-5=0$ in\ncylindrical coordinates.\n\\begin{sol}\n\t$r^2+2z^2+2z-5=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose the curve $z=e^{-x^2}$ in the $x$-$z$ plane is\nrotated around the $z$ axis. Find an equation for the resulting\nsurface in cylindrical coordinates.\n\\begin{sol}\n\t$z=e^{-r^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:rotate z=x z axis cylindrical}\nSuppose the curve $z=x$ in the $x$-$z$ plane is\nrotated around the $z$ axis. Find an equation for the resulting\nsurface in cylindrical coordinates.\n\\begin{sol}\n\t$z=r$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane $y=0$ in\nspherical coordinates.\n\\begin{sol}\n\t$\\sin\\theta=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane $z=1$ in\nspherical coordinates.\n\\begin{sol}\n\t$1=\\rho\\cos\\phi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the sphere with radius 1 and center at\n$(0,1,0)$ in spherical coordinates.\n\\begin{sol}\n\t$\\rho=2\\sin\\theta\\sin\\phi$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the cylinder $x^2+y^2=4$ in\nspherical coordinates.\n\\begin{sol}\n\t$\\rho\\sin\\phi=2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:rotate z=x z axis spherical}\nSuppose the curve $z=x$ in the $x$-$z$ plane is\nrotated around the $z$ axis. Find an equation for the resulting\nsurface in spherical coordinates.\n\\begin{sol}\n\t$\\cos\\phi=1/\\sqrt2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nPlot the polar equations $r=\\sin(\\theta)$ and $r=\\cos(\\theta)$\nand comment on their similarities.  (If you get stuck on how to plot\nthese, you can multiply both sides of each equation by $r$ and convert\nback to rectangular coordinates).\n\\end{ex}\n\n\\begin{ex}\nExtend Exercises~\\ref{ex:rotate z=x z axis cylindrical} \nand \\ref{ex:rotate z=x z axis spherical} by rotating the curve $z=mx$\naround the $z$ axis and converting to both cylindrical and spherical\ncoordinates.\n\\begin{sol}\n\t$z=mr$; $\\cot\\phi=m$ if $m\\neq0$, $\\phi=0$ if $m=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nConvert the spherical formula $\\rho=\\sin \\theta \\sin \\phi$ to\nrectangular coordinates and describe the surface defined by the\nformula (Hint: Multiply both sides by $\\rho$.)\n\\begin{sol}\n\tA sphere with radius $1/2$, center at $(0,1/2,0)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nWe can describe points in the first octant by $x >0$, $y>0$ and\n$z>0$.  Give similar inequalities for the first octant in cylindrical\nand spherical coordinates.\n\\begin{sol}\n\t$0<\\theta<\\pi/2$, $0<\\phi<\\pi/2$, $\\rho>0$;\n$0<\\theta<\\pi/2$, $r>0$, $z>0$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "461e0fe6d91eb5be324234cf28ef87876b001219", "size": 17918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-three-dimensions/12-6-other-coord-system.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-6-other-coord-system.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-6-other-coord-system.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.3915547025, "max_line_length": 128, "alphanum_fraction": 0.6888045541, "num_tokens": 6837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.9032942106088967, "lm_q1q2_score": 0.6226457729824882}}
{"text": "\\section{Simulation-Based Inference} \\label{sec:sbi}\n% standard bayesian approach and introducing SBI\nThe goal of Bayesian SED modeling, and probabilistic inference more\nbroadly, is to infer the posterior probability distributions\n$p(\\btheta\\given\\bfi{x})$ of galaxy properties, $\\btheta$, given observations, \n$\\bfi{x}$.\nFor a specific $\\btheta$ and $\\bfi{x}$, we typically evaluate the posterior\nusing Bayes' rule, \n$p(\\btheta\\given\\bfi{x}) \\propto p(\\btheta)~p(\\bfi{x}\\given\\btheta)$, where \n$p(\\btheta)$ denotes the prior distribution and $p(\\bfi{x}\\given\\btheta)$ the\nlikelihood, which is typically assumed to have a Gaussian functional form: \n\\beq\n\\label{eq:likelihood}\n    \\ln p(\\bfi{x}\\given\\btheta) = -\\frac{1}{2}\\left(\\bfi{x} - m(\\btheta)\\right)^T {\\bf C}^{-1}\n    \\left(\\bfi{x} - m(\\btheta)\\right).\n\\eeq\n$m(\\btheta)$ is the theoretical model, in our case a galaxy SED model from SPS.\n${\\bf C}$ is the covariance matrix of the observations. \nIn practice, off-diagonal terms are often ignored and measured uncertainties\nare used as estimates of the diagonal terms. \n\n% overview of SBI and mention of ABC\nSimulation-based inference (SBI; also known as ``likelihood-free'' inference)\noffers an alternative that requires no assumptions about the form of the\nlikelihood. \nInstead, SBI uses a generative model, \\emph{i.e.} a simulation $F$, to generate\nmock data $\\bfi{x}'$ given parameters $\\btheta'$: $F(\\btheta') = \\bfi{x}'$. \nIt uses a large number of simulated pairs $(\\btheta', \\bfi{x}')$ to directly estimate\neither the posterior  $p(\\btheta\\given \\bfi{x})$, the likelihood\n$p(\\bfi{x}\\given \\btheta)$, or the joint distribution of the parameters and data $p(\\btheta, \\bfi{x})$. \nSBI has already been successfully applied to a number of Bayesian parameter\ninference problems in astronomy~\\citep[\\emph{e.g.}][]{cameron2012, weyant2013,\nhahn2017b, kacprzak2018, alsing2018, wong2020, huppenkothen2021, zhang2021}\nand in physics~\\citep[\\emph{e.g.}][]{brehmer2019, cranmer2020}.\n\n%One simple and pedagogical example of SBI is Approximate Bayesian Computation~\\citep[ABC;][]{rubin1984, pritchard1999, beaumont2002}, which uses a rejection sampling framework to estimate the posterior.  First, parameter values are sampled from the prior: $\\btheta'\\sim p(\\btheta)$.  The forward model, $F$, is then run on $\\btheta'$ to generate simulated data $F(\\btheta') = \\bfi{x}'$.  If the simulated $\\bfi{x}'$ is `close' to the observed $\\bfi{x}$, usually based on a threshold on some distance criterion $\\rho(\\bfi{x}', \\bfi{x}) < \\epsilon$, $\\btheta'$ is kept.  Otherwise, $\\btheta'$ is rejected.  This process is repeated until there are enough samples to estimate the posterior.  The estimated posterior from ABC can be written as $p(\\btheta \\given \\rho(F(\\btheta), \\bfi{x}) < \\epsilon)$.  In the case where $\\epsilon\\rightarrow 0$, the conditional statement is equivalent to the condition $F(\\btheta) = \\bfi{x}$; thus, the estimated ABC posterior is  equivalent to the true posterior: $p(\\btheta \\given \\rho(F(\\btheta), \\bfi{x}) < \\epsilon\\rightarrow 0) \\equiv p(\\btheta \\given \\bfi{x})$.\n\n\n\\subsection{Amortized Neural Posterior Estimation} \\label{sec:flow}\nSBI provides another a critical advantage over MCMC inference methods --- it\nenables \\emph{amortized inference}. \nFor SED modeling using MCMC, each galaxy requires >$10^5$ model evaluations to\naccurately estimate $p(\\btheta \\given \\bfi{x})$~(\\citealt{hahn2022}, \nKwon~\\etal~in prep.).\nMoreover, model evaluations for calculating the posterior of one galaxy cannot\nbe used for another. \nThis makes MCMC approaches for SED modeling of upcoming surveys computationally\ninfeasible.\n\nWith density estimation SBI, we require a large number (${\\sim}10^6$) of model\nevaluations only initially to train a neural density estimator (NDE), a neural\nnetwork with parameters $\\bphi$ that is trained to estimate the density\n$p_\\phi(\\btheta \\given \\bfi{x}')$.\nIf the training covers the entire or the practically relevant portions of the\n$\\btheta$ and $\\bfi{x}$ spaces, we can evaluate\n$p_\\phi(\\btheta\\given\\bfi{x}_i)$ for each galaxy $i$ with minimal computational\ncost. \nThe inference is therefore amortized and no additional model evaluations are\nneeded to generate the posterior for each galaxy.\nThis technique is called  Amortized Neural Posterior Estimation (ANPE) \nand has recently been applied to a broad range of astronomical applications\nfrom analyzing gravitational waves~\\citep[\\emph{e.g.}][]{wong2020,dax2021} to\nbinary microlensing lensing~\\citep{zhang2021}.\nFor SED modeling, the choice in favor of using ANPE is easy: the entire upfront\ncost for ANPE model evaluations would only yield posteriors of tens of galaxies\nwith MCMC.\n\nANPE makes two important assumptions.\nFirst, the simulator $F$ is capable of generating mock data $\\bfi{x}'$ that is\npractically indistinguishable from the observations.\nIn terms of the expected signal, $m$ in Eq.~\\ref{eq:likelihood}, this is the\nsame requirement as any probabilistic modeling approach. \nBut unlike likelihood-based evaluations, such as conventional MCMC, data\ngenerated for SBI need to include all relevant noise terms as well. \nWe address both aspects in Sections \\ref{sec:training} and \\ref{sec:forward-model}.\nSecond, ANPE assumes that the NDE is well trained: \n$p_\\phi(\\btheta \\given \\bfi{x}')$ is a good approximation of \n$p(\\btheta \\given \\bfi{x}')$, and therefore of $p(\\btheta \\given \\bfi{x})$. \nWe assess this in Section~\\ref{sec:results}.\n\n\nANPE commonly employs so-called ``normalizing flows''~\\citep{tabak2010,\ntabak2013} as density estimators.\nNormalizing flow models use an invertible bijective transformation, $f$, to map\na complex target distribution to a simple base distribution, $\\pi(\\bfi{z})$, that is\nfast to evaluate.\nFor ANPE, the target distribution is $p(\\btheta \\given \\bfi{x})$ and the\n$\\pi(\\bfi{z})$ is typically a simple multivariate Gaussian, or mixture of Gaussians.\nThe transformation $f: \\bfi{z} \\rightarrow \\btheta$ must be invertible and have a\ntractable Jacobian. \nThis is so that we can evaluate the target distribution from $\\pi(\\bfi{z})$ by\na change of variable:  \n\\begin{equation} \\label{eq:normflow}\n    p(\\btheta \\given \\bfi{x}) = \\pi(\\bfi{z}) \\Bigl|{\\rm det} \\left(\\frac{\\partial\n    f^{-1}}{\\partial \\btheta} \\right)\\Bigr|.\n\\end{equation} \nSince the base distribution is easy to evaluate, we can also easily evaluate\nthe target distribution.  \nA neural network is trained to obtain $f$ and the collection of its parameters\nform $\\bphi$.\nThe network typically consists of a series of simple transforms (\\emph{e.g.}\nshift and scale transforms) that are each invertible and whose Jacobians are\neasily calculated. \nBy stringing together many such transforms, $f$ provides an extremely flexible\nmapping from the base distribution.\n%Rather than a single complicated transformation, the network is typically restricted to a series of simple transforms that are each invertible and whose Jacobians are easily calculated. \n\nMany different normalizing flow models are now available in the\nliterature~\\citep[\\emph{e.g.}][]{germain2015, durkan2019}.\nIn this work, we use Masked Autoregressive\nFlow~\\citep[MAF;][]{papamakarios2017}. \nThe autoregressive design~\\citep{uria2016} of MAF is particularly well-suited\nfor modeling conditional probability distributions such as the posterior. \nAutoregressive models exploit chain rule to expand a joint probability of a set\nof random variables as products of one-dimensional conditional\nprobabilities: $p(\\bfi{x}) = \\prod_i p(x_i\\given x_{1:i-1})$. \nThey then use neural networks to describe each conditional probability,\n$p(x_i\\given x_{1:i-1})$. \nIn this context, we can add a conditional variable $y$ on both sides of the\nequation, $p(\\bfi{x}\\given \\bfi{y}) = \\prod_i p(x_i\\given x_{1:i-1}, \\bfi{y})$, so that the\nautoregressive model describes a conditional probability $p(\\bfi{x}\\given \\bfi{y})$. \nOne drawback of autoregressive models is their sensitivity to the ordering of\nthe variables. \nMasked Autoencoder for Distribution Estimation~\\citep[MADE;][]{germain2015}\nmodels address this limitation using binary masks to impose the autoregressive\ndependence and by permutating the order of the conditioning variables.\nA MAF model is built by stacking multiple MADE models.  \nHence, it has the autoregressive structure of MADE but with more flexibility to\ndescribe complex probability distributions.  \nIn practice, we use the MAF implementation in the $\\mathtt{sbi}$ Python\npackage\\footnote{\\url{https://github.com/mackelab/sbi/}}~\\citep{greenberg2019,\ntejero-cantero2020}.\n", "meta": {"hexsha": "e29e0d22f0c51df81edd379c082c431ce2d48309", "size": 8555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/paper/sbi.tex", "max_stars_repo_name": "changhoonhahn/SEDflow", "max_stars_repo_head_hexsha": "4561ecfe3a38cc4c25df263d971a87e8a83f88ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2022-03-16T03:11:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T16:01:42.000Z", "max_issues_repo_path": "docs/paper/sbi.tex", "max_issues_repo_name": "changhoonhahn/SEDflow", "max_issues_repo_head_hexsha": "4561ecfe3a38cc4c25df263d971a87e8a83f88ce", "max_issues_repo_licenses": ["MIT"], "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/paper/sbi.tex", "max_forks_repo_name": "changhoonhahn/SEDflow", "max_forks_repo_head_hexsha": "4561ecfe3a38cc4c25df263d971a87e8a83f88ce", "max_forks_repo_licenses": ["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.3233082707, "max_line_length": 1099, "alphanum_fraction": 0.7599064874, "num_tokens": 2339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.6893056104028797, "lm_q1q2_score": 0.6226457663199026}}
{"text": "\\documentclass[]{article}\r\n\\usepackage{amsmath}\r\n\\usepackage{graphicx}\r\n\r\n\r\n\\begin{document}\r\n\r\nIn this post, I will briefly review the basic theory about ordinary linear regression using frequentist and Bayesian estimation methods. This will lay the terrain for a later post about Gaussian Processes. This post closely follows the presentation in Murphy (2012).\r\n\r\n\\section{Basics of Linear Regression}\r\n\r\nLinear regression used to fit a model that is linear in the parameters to a data set $\\mathcal{D}=\\{\\boldsymbol{X},\\boldsymbol{y}\\}$, where $\\boldsymbol{X}$ represents the independent variables and $\\boldsymbol{y}$ the dependent variable, and has the form\r\n\r\n$p(y|\\boldsymbol{x}, \\boldsymbol{\\beta}) = \\mathcal{N}(y|\\boldsymbol{\\beta}^T\\boldsymbol{x}, \\sigma_{\\epsilon}^2)$\r\n\r\nwhere $\\boldsymbol{\\beta}$ is a vector of model parameters and $\\sigma_{\\epsilon}^2$ is the model error variance. The unusual notation for the normal distribution $\\mathcal{N}$ should be read as \"a normal distribution of $\\boldsymbol{y}$ with (or given) mean $\\boldsymbol{\\beta}^T\\boldsymbol{x}$ and variance $\\sigma_{\\epsilon}^2$.\" The traditional method of estimating the parameters of a linear regression model is by using the frequentist method of maximum likelihood estimation (MLE). MLE provides point estimates $\\boldsymbol{\\hat{\\beta}}$ for each of the regression model parameters $\\boldsymbol{\\beta}$ by maximizing the likelihood function with respect to $\\boldsymbol{\\beta}$ and $\\sigma_{\\epsilon}^2$ by solving the minimization problem\r\n\r\n$\\boldsymbol{\\hat{\\beta}} = arg\\,\\underset{\\boldsymbol{\\beta}}{max}\\;\\mathcal{L}(\\boldsymbol{\\beta})$\r\n\r\nwhere the likelihood function $\\mathcal{L}(\\boldsymbol{\\beta})$ is defined as\r\n\r\n$\\mathcal{L}(\\boldsymbol{\\beta})=p(\\mathcal{D}|\\boldsymbol{\\beta})={\\displaystyle \\prod_{i=1}^{N} p(y_i|\\boldsymbol{x}_i, \\boldsymbol{\\beta}, \\mu, \\sigma_{\\epsilon}^2)} = \\mathcal{N}(\\boldsymbol{y}|\\mu + \\boldsymbol{X}\\boldsymbol{\\beta},\\sigma_{\\epsilon}^2\\boldsymbol{I})$\r\n\r\nwhere $\\mu$ is the mean of the model error ($\\mu=0$ hereafter), $N$ is the number of points in the data set, $\\boldsymbol{I}$ is an identity matrix, and $\\boldsymbol{x}$ is a vector of values of the independent variables for an individual data point of matrix $\\boldsymbol{X}$. If a non-linear function shape is sought, linear regression can be used to fit a model linear in the parameters over a function $\\phi(\\cdot)$ of the data. This procedure is called basis function expansion and has a likelihood function of the form\r\n\r\n$\\mathcal{L}(\\boldsymbol{\\beta}) = \\mathcal{N}(\\boldsymbol{y}|\\mu + \\phi(\\boldsymbol{X})\\boldsymbol{\\beta},\\sigma_{\\epsilon}^2\\boldsymbol{I})$\r\n\r\nwhere $\\phi(\\boldsymbol{x})$ can have, for example, the form\r\n\r\n$\\phi(\\boldsymbol{x})=[1, x_1, x_1^2]$\r\n\r\nfor fitting a parabola to a one-dimensional $\\boldsymbol{X}$ over $\\boldsymbol{y}$. When minimizing the squared residuals we get to the famous Ordinary Least Squares regression. Linear regression can be further developed, for example, into Ridge Regression to better handle multicollinearity by introducing bias to the parameter estimates, and into Kernel Ridge regression to implicitly add non-linear terms to the model. These formulations are beyond the scope of this post.\r\n\r\nWhat is important to notice is that the standard approaches for linear regression described here, although able to fit linear and non-linear functions, do not provide much insight into the model errors. That is when Bayesian methods come to play.\r\n\r\n\\section{Bayesian Linear Regression}\r\n\r\nIn Bayesian Linear regression (and in any Bayesian approach), the parameters $\\boldsymbol{\\beta}$ are treated themselves as random variables. This allows for the consideration of model uncertainty, given that now instead of having the best point estimates for $\\boldsymbol{\\beta}$ we have their full distributions from which to sample models – a sample of  $\\boldsymbol{\\beta}$ corresponds to a model. The distribution of parameters for $\\boldsymbol{\\beta}$, $P(\\boldsymbol{\\beta}|\\mathcal{D})$, called the parameter posterior distribution, is calculated by multiplying the likelihood function used in MLE by a prior distribution for the parameters. A prior distribution is assumed from knowledge prior to analyzing new data. In Bayesian Linear Regression, a Gaussian distribution is commonly assumed for the parameters. For example, the prior on $\\boldsymbol{\\beta}$ can be $\\mathcal{N}(\\boldsymbol{\\beta_0},\\boldsymbol{V}_0)$ for algebraic simplicity. The parameter posterior distribution assuming a known  then has the form\r\n\r\n$p(\\boldsymbol{\\beta}|\\mathcal{D}, \\sigma^2) =\\frac{p(\\mathcal{D}|\\boldsymbol{\\beta}, \\sigma^2)p(\\boldsymbol{\\beta})}{p(\\mathcal{D})} \\propto p(\\mathcal{D}|\\boldsymbol{\\beta}, \\sigma^2)p(\\boldsymbol{\\beta})$  ,        given $p(\\mathcal{D})$ is a constant depending only on the data.\r\n\r\nWe now have an expression from which to derive our parameter posterior for our linear model from which to sample $\\boldsymbol{\\beta}$. If the likelihood and the prior are Gaussian, the parameter posterior will also be a Gaussian, given by\r\n\r\n$p(\\boldsymbol{\\beta}|\\mathcal{D}, \\sigma^2) \\propto \\mathcal{N}(\\boldsymbol{\\beta}|\\boldsymbol{\\beta}_0, \\boldsymbol{V}_0)\\mathcal{N}(\\boldsymbol{y}|\\boldsymbol{X\\beta},\\sigma^2\\boldsymbol{I})=\\mathcal{N}(\\boldsymbol{\\beta}|\\boldsymbol{\\beta}_N,\\boldsymbol{V}_N)$\r\nwhere\r\n$\\boldsymbol{V}_N = \\sigma^2(\\sigma^2\\boldsymbol{V}_0^{-1}+\\boldsymbol{X}^T\\boldsymbol{X})^{-1}$\r\n$\\boldsymbol{\\beta}_N=\\boldsymbol{V}_N\\boldsymbol{V}_0^{-1}\\boldsymbol{\\beta}_0 + \\frac{1}{\\sigma^2}\\boldsymbol{V}_N\\boldsymbol{X}^T\\boldsymbol{y}$\r\n\r\nIf we calculate the parameter posterior (distribution over parameters $\\boldsymbol{\\beta}$) for a simple linear model $f(x) = \\beta_0 + \\beta_1x$ for a data set $\\mathcal{D}$ in which $\\boldsymbol{X}$ and $\\boldsymbol{y}$ are approximately linearly related given some noise $\\sigma_{\\epsilon}^2$, we can use it to sample values for $\\boldsymbol{\\beta}$. This is equivalent to sampling linear models $f(x)$ for data set $\\mathcal{D}$. As the number of data points increase, the variability of the sampled models should decrease, as in the figure below\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{linear_model.png}\r\n\t\\label{fig:linearmodel}\r\n\\end{figure}\r\n\r\nThis is all interesting but the parameter posterior per se is not of much use. We can, however, use the parameter posterior to find the posterior predictive distribution, which can be used to both get point estimates of $y$ and the associated error. This is done by multiplying the likelihood by the parameter posterior and marginalizing the result over $\\boldsymbol{\\beta}$. This is equivalent to performing infinite sampling of blue lines in the example before to form density functions around a point estimate of $\\mu_{y_*}=f(\\boldsymbol{x}_*)$, with $(\\boldsymbol{x}_*,y_*)$ denoting a new point that is not in $\\mathcal{D}$. If the likelihood and the parameter posterior are Gaussian, the posterior predictive then takes the form below and will also be Gaussian (in Bayesian parlance, this means that the Gaussian distribution is conjugate to itself)!\r\n\r\n$\\begin{aligned}p(y_*|x_*,\\mathcal{D}, \\sigma_{\\epsilon}^2) &= \\int_{\\boldsymbol{\\beta}}p(y_*|x_*,\\mathcal{D}, \\sigma_{\\epsilon}^2,\\boldsymbol{\\beta})p(\\boldsymbol{\\beta}|\\mathcal{D}, \\sigma)d\\boldsymbol{\\beta}\\\\\r\n\r\n&=\\mathcal{N}(\\boldsymbol{\\beta}_N^T, \\sigma_N^2(\\boldsymbol{x}_*))\\end{aligned}$\r\n\r\nwhere\r\n\r\n$\\sigma_N^2(\\boldsymbol{x}_*) = \\sigma_{\\epsilon}^2 + x^{*T}\\boldsymbol{V}_Nx_*$\r\n\r\nor, to put it simply,\r\n\r\n$\\boldsymbol{y}_* = f(\\boldsymbol{x}_*) = \\boldsymbol{\\beta}_N(\\boldsymbol{x}_*) \\pm \\sigma_N^2(\\boldsymbol{x}_*)$\r\n\r\nThe posterior predictive, meaning final linear model and associated errors (the parameter uncertainty equivalent of frequentist statistics confidence intervals) are shown below\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{linear_regression.png}\r\n\t\\label{fig:linearregression}\r\n\\end{figure}\r\n\r\nIf, instead of having a data set $\\mathcal{D}$ in which $\\boldsymbol{X}$ and $\\boldsymbol{y}$ are related approximately according to a 4th order polynomial, we use a $\\phi(\\cdot)$ function to artificially create more random variables (or features, in machine learning parlance) corresponding to the non-linear terms of the polynomial function. Our function $\\phi(\\cdot)$ would be $\\phi(x) = [1, x, x^2, x^3, x^4]$ and the resulting $X$ would therefore have five columns instead of two ($[1, x]$), so now the task is to find $\\boldsymbol{\\beta}=[\\beta_0, \\beta_1, \\beta_2, \\beta_3, \\beta_4]$. Following the same logic as before for $X'=\\phi(X)$ and $x_*'=\\phi(x_*)$, where prime denotes the new set random variable $x$ from function $\\phi(\\cdot)$, we get the following plots\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{poly_model.png}\r\n\t\\caption{}\r\n\t\\label{fig:polymodel}\r\n\\end{figure}\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{poly_regression.png}\r\n\t\\caption{}\r\n\t\\label{fig:polyregression}\r\n\\end{figure}\r\n\r\nThis looks great, but there is a problem: what if we do not know the functional form of the model we are supposed to fit (e.g. a simple linear function or a 4th order polynomial)? This is often the case, such as when modeling the reliability of a water reservoir system contingent on stored volumes, inflows and evaporation rates, or when modeling topography based on samples surveyed points (we do not have detailed elevation information about the terrain, e.g. a DEM file). Gaussian Processes (GPs) provide a way of going around this difficulty.\r\n\r\n\\section{References}\r\n\r\nMurphy, Kevin P., 2012. Machine Learning: A Probabilistic Perspective. The MIT Press.\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "b6b04bf646bc14d8cb542173dab8ad6a29ce1863", "size": 9767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "post.tex", "max_stars_repo_name": "bernardoct/BayesianRegressionAndGPs", "max_stars_repo_head_hexsha": "fdf910466ea25382318ff011abe108ae6e733c36", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "post.tex", "max_issues_repo_name": "bernardoct/BayesianRegressionAndGPs", "max_issues_repo_head_hexsha": "fdf910466ea25382318ff011abe108ae6e733c36", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "post.tex", "max_forks_repo_name": "bernardoct/BayesianRegressionAndGPs", "max_forks_repo_head_hexsha": "fdf910466ea25382318ff011abe108ae6e733c36", "max_forks_repo_licenses": ["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.7549019608, "max_line_length": 1027, "alphanum_fraction": 0.746186137, "num_tokens": 2581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6225986184979665}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Toolset}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Unary Math}\n\\label{sec:unarymath}\nUs humans are used to representing numbers in decimal, 0, 1, 9 for the ten\nfirst numbers, followed by 10 to 19, 20 to 29... 90 to 99, then 100 and so\non; yet at early childhood we use our fingers to represent numbers, depending\non the culture we open or close as many fingers as the number we want to\nrepresent.\n\nHere in \\sed* we will thus represent unary numbers by means of a string\ncomposed of a single character repeated as many times as the number being\nrepresented.  \\sed* support for transformations based on Regular Expressions\nmakes working with them quite easy, as we will see here.\n\n\\begin{description}\n\t\\item[Addition: $x^ny^m\\mapsto x^{n+m}$:]\n\t\t\\begin{verbatim}\n\t\t\ts/y/x/g\n\t\t\\end{verbatim}\n\n\t\\item[Duplication: $x^n\\mapsto x^{2n}$:]\n\t\t\\begin{verbatim} s/xx*/&&/ \\end{verbatim}\n\n\t\\item[Assignment: $x^n\\mapsto x^ny^m$:]\n\n\t\tThis can be achieved by an intermediate representation containing a pipe in\n\t\tthe middle of a duplication: $x^n\\texttt{|}x^n$, that way each of the\n\t\t{\\tt x}s after the pipe can be converted one by one into {\\tt y}s.  At the\n\t\ti-th iteration we will have:\n\t\t$x^ny^{i-1}\\texttt{|}xx^{n-i} \\mapsto x^ny^i\\texttt{|}x^{n-i}$.\n\n\t\t\\begin{Verbatim}\n\t\t\ts/x*/&|&/; :a; s/|x/y|/; ta; s/|//\n\t\t\\end{Verbatim}\n\n\t\\item[Multiplication: $x^ny^m\\mapsto x^{n(m+1)}$:]\n\n\t\tSince $n\\cdot m=n(m-1)+n$, this can be solved by consuming one {\\tt y}\n\t\tat a time by repeating the substitution $x^ny^m \\equiv x^nyy^{m-1}\n\t\t\\mapsto\tx^ny^{m-1}x^n$ while there are {\\tt y} availables.  The last\n\t\tsubstitution will then be $x^nyx^{n(m-1)} \\mapsto x^nx^nx^{n(m-1)}\n\t\t\\equiv x^{n(m+1)}$:\n\n\t\t\\begin{Verbatim}\n\t\t\t:a; s/\\(x*\\)y\\(y*\\)/\\1\\2\\1/; ta\n\t\t\\end{Verbatim}\n\n\t\tTo calculate $n\\cdot m$ instead of $n(m+1)$, we can either delete one\n\t\t{\\tt y} if we know there is at least one (\\verb|s/y//|); or we can place\n\t\ta separator between the {\\tt x}s and the {\\tt y}s, then at the iteration\n\t\twe will have $x^n\\texttt{|yx}^{n(m-1)} \\mapsto x^n\\texttt{|x}^{nm}$:\n\n\t\t\\begin{Verbatim}\n\t\t\ts/x*/&|/\n\t\t\t:a; s/\\(x*\\)|y\\(y*\\)/\\1|\\2\\1/; ta\n\t\t\ts/x*|//\n\t\t\\end{Verbatim}\n\n\t\\item[Factorization: $\\texttt{x}^n \\mapsto\n\t\t\\texttt{|x}^{p_1}\\texttt{|x}^{p_2}\\texttt{|}\n\t\t\\ldots\\texttt{|x}^{p_k}\\texttt{|}$:]\n\n\t\tWe can use the following code to compute the prime numbers\n\t\t$p_1, p_2\\ldots p_n$, where $n=\\prod_{i=1}^k p_i$.\n\t\tAdditionally this prime factors will be sorted\n\t\tdecreasingly, assuring a unique decomposition.\n\n\t\t\\begin{Verbatim}\n\t\t\ts/x*/|&|/; :a\n\t\t\t  s/|\\(xxx*\\)\\(\\1\\1*\\)|/|\\1<x>\\2|/\n\t\t\t  s/\\(x*\\)<\\(x*\\)>\\1/\\1<\\2x>/\n\t\t\t  s/<\\(x*\\)>|/|\\1|/\n\t\t\tta\n\t\t\\end{Verbatim}\n\n\t\t\\begin{enumerate}\n\t\t\t\\item On the first line we wrap the {\\tt x}s between pipes just to\n\t\t\t\tmake processing simple, it is not required though.\n\n\t\t\t\\item Then for a block of length $n$ this is when we find a \n\t\t\t\tdivisor $d>1$ of $n$, the backreference is placed twice to ensure\n\t\t\t\t$d<n$.  Since the algorithm for matching regular expressions is\n\t\t\t\tgreedy, \\verb|\\1| will match the largest divisor smaller than $n$,\n\t\t\t\tmeaning that $n/d$ is the smallest prime that divides $n$.\n\n\t\t\t\tThe block $\\texttt{|x}^n\\texttt{|}$ will be converted into\n\t\t\t\t$\\texttt{|x}^d\\texttt{<x>x}^{n-d}\\texttt{|}$.\n\n\t\t\t\\item The next substitution gradually substracts $d$ from the\n\t\t\t\t``number'' after the \\verb|>| symbol, adding one before it.\n\t\t\t\tIn other words we just divided $n$ over $d$ using repeated\n\t\t\t\tsubstraction.\n\t\t\t\tSo after applying this rule as many times as possible, we obtain:\n\t\t\t\t$\\texttt{|x}^d\\texttt{<x}^{n/d}\\texttt{>|}$.\n\n\t\t\t\\item And the final rule, applicable only when the division has\n\t\t\t\tcompleted, is to convert it back to the ``pipe separated\n\t\t\t\tunary format'' so that we can proceed to find newer factors:\n\t\t\t\t$ \\texttt{|x}^n\\texttt{|} \\mapsto \\ldots\n\t\t\t\t\\mapsto \\texttt{|x}^d\\texttt{|x}^{n/d}\\texttt{|}$\n\t\t\\end{enumerate}\n\n\t\\item[Logarithm: $x^n\\mapsto y^{\\lfloor\\log_2 n\\rfloor}$:]\n\n\t\tThe idea here is to divide by 2 repeatedly until {\\tt xx} can no longer\n\t\tbe found.  Note that we divide by 2 rounding down by substituting a\n\t\tsingle (final) {\\tt x} in the pattern at line 2 to an empty string.\n\t\tThere may be a remaining {\\tt x} which we remove at the end.\n\n\t\t% sedcode logarithm:\n\t\t\\begin{Verbatim}\n\t\t\t:a; /xx/ {\n\t\t\t  s/x\\(x\\|\\)/\\1/g\n\t\t\t  s/^/y/\n\t\t\tba }\n\t\t\ts/x//\n\t\t\\end{Verbatim}\n\n\t\\item[Minimum: $\\texttt{x}^n\\texttt{|x}^m \\mapsto\n\t\t\\texttt{x}^{\\min\\{n,m\\}}$:]\n\n\t\t% sedcode minimum:\n\t\tCalculating the minimum between $n$ and $m$ is performed by\n\t\tsubstituting them leaving only the longest common prefix.  Such a\n\t\ttransformation is simply \\verb!s/\\(x*\\)x*|\\1x*/\\1/!.\n\n\t\\item[Maximum: $\\texttt{x}^n\\texttt{|x}^m \\mapsto\n\t\t\\texttt{x}^{\\max\\{n,m\\}}$:]\n\n\t\tTo fully comprehend how the implementation presented here\n\t\twe need to embrace the fact that \\sed* uses a greedy algorithm for\n\t\tsubstitutions. In other words whenever our regular\n\t\texpression is the concatenation of two or more quantified parts, it\n\t\twill try to match as much as possible in the first part, then as\n\t\tmuch as possible in the second and so on, as long the regex matches.\n\n\t\tWhen looking at the implementation for minimum we can see that the\n\t\tonly difference is that we are capturing and keeping the second and\n\t\tthird occurrences of $\\texttt{x}^*$:\n\n\t\t% sedcode maximum:\n\t\t\\begin{Verbatim}\n\t\t\ts/\\(x*\\)\\(x*\\)|\\1\\(x*\\)/\\1\\2\\3/\n\t\t\\end{Verbatim}\n\n\t\tSo, since\n\t\t\\begin{itemize}\n\t\t\t\\item \\verb|\\1| captures $\\min\\{n,m\\}$ number of \\verb|x|s,\n\t\t\t\\item \\verb|\\2| captures $n-\\min\\{n,m\\}$ number of \\verb|x|s, and\n\t\t\t\\item \\verb|\\3| captures $m-\\min\\{n,m\\}$ number of \\verb|x|s;\n\t\t\\end{itemize}\n\t\tthen for \\verb|\\1\\2\\3|: $n+m-\\min\\{n,m\\}=\\max\\{n,m\\}$.\n\n\t\tAnother possibility, though way less elegant, is to abuse the fact\n\t\tthat we can assume the greedy behavior for the alternative operator\n\t\t``\\verb!\\|!'' as well.  If $n<=m$ then \\verb|\\1\\3| will match $n +\n\t\t(m-n)=m$, and if $n>m$, then the second alternative will be selected\n\t\tleaving \\verb|\\3| empty:\n\t\t\\begin{Verbatim}\n\t\t\ts/\\(x*\\)|\\(\\1\\(x*\\)\\|x*\\)/\\1\\3/\n\t\t\\end{Verbatim}\n\n\t\\item[Fibonacci: $\\texttt{x}^n\\mapsto \\texttt{x}^{\\fib n}$:]\n\n\t\tFibonacci is usually defined recursively by $\\fib n = \\fib (n-1) +\n\t\t\\fib (n-2)$ with the base case $\\fib n = n$ when $n<2$.  So in the\n\t\timplementation presented here we first handle the base case first by\n\t\tnot adding pipes (which disables all substitutions on the following\n\t\tlines).\n\n\t\tThe recursive case is handling by having our pattern space with the\n\t\tformat $\\texttt{x}^{n-i}\\texttt{|x}^{\\fib i-1}\\texttt{|x}^{\\fib i}$,\n\t\tand applying the inductive substitution $(a,b)\\mapsto (b,a+b)$\n\t\twhich increases by 1 the value at $i$:\n\t\t$\\texttt{x}^{n-i}\\texttt{|x}^{\\fib i-1}\\texttt{|x}^{\\fib i}$\n\t\t$\\mapsto$\n\t\t$\\texttt{x}^{n-i-1}\\texttt{|x}^{\\fib i}\\texttt{|x}^{\\fib i+1}$.\n\n\t\tWhen $i$ reaches $n$, that is when there are no more {\\tt x}s before\n\t\tthe first pipe, we will have $\\texttt{|x}^{\\fib n-1}\\texttt{|x}^{\\fib n}$,\n\t\tso at that point we just leave the text after the last pipe:\n\n\t\t% sedcode fibonacci:\n\t\t\\begin{Verbatim}\n\t\t\t/xx/ s/x$/||x/\n\t\t\t:a; s/x|\\(x*\\)|\\(x*\\)/|\\2|\\1\\2/; ta\n\t\t\ts/.*|//\n\t\t\\end{Verbatim}\n\n\\end{description}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Binary Math}\n\n\\begin{description}\n\t\\item[XOR: $a_n\\ldots a_1 a_0\\texttt{|}b_m\\ldots b_1 b_0 \\mapsto\n\t\tc_{\\max\\{n, m\\}}\\ldots c_1 c_0$ where $(c_i)=(a_i)\\oplus(b_i)$:]$\\,$\n\n\t\tBit-wise XOR between $(a_i)$ and $(b_i)$, assuming as many leading zeros\n\t\tas needed.\n\n\t\t% sedcode bitwise-xor:\n\t\t\\begin{Verbatim}\n\t\t\ts/$/|/\n\t\t\t:a; s/^|\\(.*\\)|/\\1/; s/||//\n\t\t\t  s/0|\\(.*\\)\\(.\\)|/|\\1|\\2/\n\t\t\t  s/1|\\(.*\\)0|/|\\1|1/\n\t\t\t  s/1|\\(.*\\)1|/|\\1|0/; ta\n\t\t\ts/^0*//; s/^$/0/\n\t\t\\end{Verbatim}\n\n\t\t\\begin{enumerate}\n\t\t\t\\item We start by adding a pipe to the end.\n\t\t\t\tWe will store the result after that pipe.\n\t\t\t\\item At the start of each iteration denoted by the label \\verb|:a| we\n\t\t\t\tdetect the cases where there are no more binary digits left in any\n\t\t\t\tof the operands.\n\n\t\t\t\tIn the following 3 lines we will be processing\n\t\t\t\tone bit at a time starting from the right (least significant bit).\n\t\t\t\\item The rule that we apply here $0\\oplus x = x$.  We just maintain the\n\t\t\t\tleast significant bit of the second number.\n\t\t\t\\item Then we consider $1\\oplus 0=1$.\n\t\t\t\\item And the other case $1\\oplus 1=0$.\n\t\t\t\\item Finally we just remove leading zeroes and place a zero in place of\n\t\t\t\tan empty string.\n\t\t\\end{enumerate}\n\\end{description}\n\n\\todo{Write about binary addition.}\n\n\\todo{Write about truncation.}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Lookup Tables}\n\nMany of the most complex programs written in \\sed* use the power of\nbackreferences in order to do translations which otherwise could be very\ncomplex, here we will focus on two very practical use cases, converting from\ndecimal numbers to unary and viceversa.\n\n\\subsubsection{Decimal to Unary}\n\nLet's say we want to convert the digits of the number {\\tt 42} to unary:\n{\\tt |xxxx|xx}, we can use the following short program composed of just three\nlines:\n\n\\begin{Verbatim}\n\ts/./|0123456789&!/g\n\ts/\\(.\\)[0-9]*\\1//g\n\t:a; s/|!/|/g; s/.!/!x/g; ta\n\\end{Verbatim}\n\n\\begin{enumerate}\n\t\\item with the first substitution we would obtain the seemingly useless\n\t\tstring: {\\tt |01234567894!|01234567892!}, yet there is an interesting\n\t\tpattern going on.\n\t\\item If for each block we were to remove the duplicated numbers and\n\t\teverything in between, we would obtain {\\tt |0123!|01!}, and that's\n\t\twhat the second line does.\n\n\t\tNote that the number of digits left matches the corresponding digit\n\t\tthat we had before.  That's because we inserted all the digits in order.\n\n\t\\item Finally to obtain the {\\tt x}s, we can iterate the exclamation marks\n\t\tto the left substituting the digits by {\\tt x}s until they reach the\n\t\tpipes (when we remove them).\n\\end{enumerate}\n\n\\subsubsection{Unary to Decimal}\n\\todo{Copiar desde la cuadernola la explicaci\\'on de las reverse lookup tables.}\n\n\\subsubsection{Generic Substitutions}\n\\todo{Escribir c\\'omo se podr\\'{\\i}a usar una lookup table en general para\nhacer una substitución arbitraria.}\n% the example usually seen for \"sed lookup tables\" is that of substituting\n% numbers via 0zero1one2two3three4four5five6six7seven8eight9nine, there has\n% to be another simple example.\n%   Maybe converting from hexa to binary requiring only two commands.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Debugging}\n\nWhen developing programs in \\sed*, more often than not we end up with mountains\nof completely unreadable line noise which at a certain point, sometimes even\nway before to be completed, leaves us in a state of absolute confusion.  Is at\nthis point that we really need to understand what's going on.\n\nOne of the simplest ways to try to understand the code, is to print the content\nof the pattern space, in the most simple form we just place the {\\tt p} command\nwhenever we want to, however if we want to print it at several places and\nspecially if there are newlines inside the pattern space, we might want to use\nsomething like this instead:\n\n\\begin{Verbatim}\n\t... lots of code ...\n\ts/.*/At xyz: <<&>>/p;  s/[^<]*<<//;  s/>>$//\n\t... lots of code ...\n\\end{Verbatim}\n\nNote that by using the previous code snippet we ``set to true'' the state of\nwhether a substitution was applied at that point.  If we don't care about its\nstate then we might just use that code, if not we have to maintain it by\nbasically duplicating our code around an ``if then else'':\n\n\\begin{Verbatim}\n\t... lots of code ...\n\ttTxyz; s/.*/At xyz (F): <<&>>/p; s/[^<]*<<//; s/>>$//; tFxyz\n\t:Txyz; s/.*/At xyz (T): <<&>>/p; s/[^<]*<<//; s/>>$//; :Fxyz\n\t... lots of code ...\n\\end{Verbatim}\n\nThis works because if the flag was true, it will jump to the {\\tt (T)} part,\nwith these new substitutions restoring the flag to true.\nOterwise the conditional jump to {\\tt Fxyz} will reset it to false\nbefore continuing.\n\nIf the hold space has to be printed as well, then one simple solution is\nlogging the pattern space, followed by the {\\tt x} command, that logging\nthe hold space and finally switching back the spaces with the {\\tt x}\ncommand once again.\n\n\\todo{add more tools}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Jump Tables}\n\n\\todo{complete jump tables}\n", "meta": {"hexsha": "347faffbec3b7975b3e067294df79227070e6964", "size": 12580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "toolset.tex", "max_stars_repo_name": "fcr--/advanced-sed", "max_stars_repo_head_hexsha": "c812ba83bda1ec3a91132da524b43de53229311e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-21T00:15:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-21T00:15:02.000Z", "max_issues_repo_path": "toolset.tex", "max_issues_repo_name": "fcr--/advanced-sed", "max_issues_repo_head_hexsha": "c812ba83bda1ec3a91132da524b43de53229311e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "toolset.tex", "max_forks_repo_name": "fcr--/advanced-sed", "max_forks_repo_head_hexsha": "c812ba83bda1ec3a91132da524b43de53229311e", "max_forks_repo_licenses": ["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.7777777778, "max_line_length": 80, "alphanum_fraction": 0.6443561208, "num_tokens": 4015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6225800278777761}}
{"text": "\\documentclass[a4paper, 11pt]{article}\n\\usepackage{fullpage, amssymb, amsmath, graphicx} \n\n\\newcommand{\\mytitle}{Cholesky Decomposition of 2D Kernel}\n\n\\begin{document}\n\\noindent\n\\large\\textbf{\\mytitle} \\\\ \\\\ Tyler Gordon \\\\\n\\normalsize \\today \n\\ \\ \\hrulefill\n\\section{}\nIn the 1D case, the cholesky decomposition algorithm for a covariance kernel represented by \na semiseparable matrix with the form\n\\begin{equation}\nK = A + \\text{tril}(UV^T) + \\text{triu}(VU^T)\n\\end{equation}\nwhere U and V are both N x J matrices and A is an N x N diagonal matrix is given in in section \n5.1 of Foreman-Mackey et al, 2017 (FM17). \nIn the 2D case, the covariance matrix is given by\n\\begin{equation}\nK = A' + \\text{tril}(U'V'^T) + \\text{triu}(V'U'^T)\n\\end{equation}\nwhere $U' = U\\otimes Q$, $V' = V\\otimes I_M$, and $A' = (A - \\sigma_n) \\otimes Q + \\sigma_{nM+i}$ \nwhere $Q_{i,j}$ specifies the covariance between \ncoordinates $x_i$ and $x_j$ in the second dimension, and $I_M$ is the identity matrix with $M$ corresponding \nto the size of $Q$. Because $U'$ and $V'$ for $U$ and $V$ does not alter the semiseperable property of the \nmatrices, the decomposition can proceed as in the 1D case with the following alterations to equations 43-45 of \nFM17: \n\\begin{align}\n\\tilde{U}_{(n-1)M+p, (2j-1)M+q} = a_j\\cos(d_jt_n) + b_j\\sin(d_jt_n)Q_{p,q} \\\\\n\\tilde{U}_{(n-1)M+p, (2j)M+q} = a_j\\cos(d_jt_n) + b_j\\sin(d_jt_n)Q_{p,q} \\\\\n\\tilde{V}_{(n-1)M+p, (2j-1)M+q} = a_j\\sin(d_jt_n) - b_j\\cos(d_jt_n)\\delta_{p, q} \\\\\n\\tilde{V}_{(n-1)M+p, (2j)M+q} = a_j\\sin(d_jt_n) - b_j\\cos(d_jt_n)\\delta_{p, q} \\\\\nA_{(n-1)M+p, (n-1)M+p} = \\sigma_{(n-1)M+p} + Q_{p, p}\\sum_{j=1}^J a_j\n\\end{align}\nwhere $p, q = 1, 2...M$. \n\\begin{equation}\n\t\\phi_{(n-1)M+p, (2j-1)M+q} = \\phi_{(n-1)M+p, (2j)M+q} = \n\t \\begin{cases}\n\t\te^{-c_j(t_n-t_{n-1})} & p = 1 \\\\\n\t\t1 & p > 1\n\t\\end{cases}\n\\end{equation}\nStill with the constraint that\n\\begin{equation}\n\t\\phi_{1, (2j-1)M+q} = \\phi_{1, (2j)M+q} = 0\n\\end{equation}\nThe algorithm for computing the cholesky decomposition is unaltered from equation 46 of FM17. \n\n\\end{document}\n", "meta": {"hexsha": "77f6562ee92d5ec38e6fee61ca0320132fd70bda", "size": 2063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/cholesky.tex", "max_stars_repo_name": "tagordon/celerite2d.jl", "max_stars_repo_head_hexsha": "7fa487b1b1283f574559c06398449b6ba1dcf3ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-19T15:43:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-19T15:43:04.000Z", "max_issues_repo_path": "notes/cholesky.tex", "max_issues_repo_name": "tagordon/celerite2d.jl", "max_issues_repo_head_hexsha": "7fa487b1b1283f574559c06398449b6ba1dcf3ee", "max_issues_repo_licenses": ["MIT"], "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/cholesky.tex", "max_forks_repo_name": "tagordon/celerite2d.jl", "max_forks_repo_head_hexsha": "7fa487b1b1283f574559c06398449b6ba1dcf3ee", "max_forks_repo_licenses": ["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.4509803922, "max_line_length": 111, "alphanum_fraction": 0.6650508968, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6225097001806904}}
{"text": "\\section{Convolutional Neural Networks}\n\n\nIn the field of machine learning, especially in the deep learning sector, a CNN is a deep learning algorithm. It can take an input image and reproduce an identification of the object with a certain probability. The special feature of a CNN is that it is able to learn filters of different types (e.g. horizontal lines, vertical lines, etc.). A convolutional neural network has a characteristic structure in terms of its layers. It is structured in convolutional, pooling, and fully connected layers. The arrangement of alternating convolutional and pooling layers allows a more accurate and complex analysis of the image. The first layers focus on shapes and colors, while later layers contribute to the identification of more complex details for the recognition of the overall image.\n\n\\subsection{Convolutional Layer}\nThe convolutional layer is the key component of a CNN. It contains a certain set of filters, also called kernels. The parameters of the filter are learned over the course of the training. The filter interacts with the image and convolves it. From this convolution, an activation map is created which is calculated from the dot product between each element of the filter and the input. The weights in the filter are maintained as the filter moves across the image. However, these weights adjust during backpropagation and the associated gradient descent to achieve the most accurate results. \n\n\\begin{figure}[htb]\n    \\centering\n    \\includegraphics[width=7cm]{images/conv_layer.jpg}\n    \\caption{Convolutional Layer}\n    \\label{fig:convLayer}\n\\end{figure}\n\n\\subsection{Pooling Layer}\nSince a great increase in dimension occurs through the use of a convolutional layer, a dimension reduction is required in the next step to reduce the number of parameters of a CNN. This is achieved by the pooling layer. It has the advantage that the computational cost decreases drastically. Also, unnecessary details are omitted, which is helpful for the later image identification.The most commonly used pooling methods are maximum and average pooling. In figure \\ref{fig:poolingLayer}, you can see how a maximum pooling is performed, leading to a dimension reduction.\n\n\\begin{figure}[htb]\n    \\centering\n    \\includegraphics[width=7cm]{images/maxpooling.jpg}\n    \\caption{Max Pooling Layer}\n    \\label{fig:poolingLayer}\n\\end{figure}\n\n\\subsection{Fully-Connected Layer}\nSince the individual pixel values of the input image are not directly connected to the output layer, a fully-connected layer is required which is directly connected to the output layer. The layer does the classification using the collected features from the previous layers. At the end, a softmax or Sigmoid function (dependent on the problem) is applied, which outputs a classification using probabilities between 0 and 1.\n\n\\begin{figure}[htb]\n    \\centering\n    \\includegraphics[width=10cm]{images/cnn_turtle_pooling.png}\n    \\caption{Turtle Image using CNN}\n    \\label{fig:turtleCNN}\n\\end{figure}", "meta": {"hexsha": "985056a2b9c076dcf26a503b6fe85189ef8b87eb", "size": 3016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/source/sections/ConvolutionalNeuralNetworks.tex", "max_stars_repo_name": "dhesenkamp/turtleRecall", "max_stars_repo_head_hexsha": "fb5cfa7036f1f5a9ed9752413fbabb76355ed97b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T14:54:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T14:54:52.000Z", "max_issues_repo_path": "documentation/source/sections/ConvolutionalNeuralNetworks.tex", "max_issues_repo_name": "dhesenkamp/turtleRecall", "max_issues_repo_head_hexsha": "fb5cfa7036f1f5a9ed9752413fbabb76355ed97b", "max_issues_repo_licenses": ["MIT"], "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/source/sections/ConvolutionalNeuralNetworks.tex", "max_forks_repo_name": "dhesenkamp/turtleRecall", "max_forks_repo_head_hexsha": "fb5cfa7036f1f5a9ed9752413fbabb76355ed97b", "max_forks_repo_licenses": ["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.7058823529, "max_line_length": 784, "alphanum_fraction": 0.799071618, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6225096980685512}}
{"text": "\\chapter{Massive Spin-1 Particles}\n\\section{Polarisations}\nIn chapter 12, we saw that for massless spin-1 particles, the equations of motion (Maxwell's equations) can be expressed in covariant form by \\eqref{eq:MaxwellCovariant}:\n\\begin{equation*}\nj^\\mu = \\partial^2 A^\\mu - \\partial^\\mu \\partial_\\nu A^\\nu.\n\\end{equation*}\nThe term $\\partial^2 A^\\mu$ may be expanded as $(\\pdv[2]{t} - \\nabla^2)A^\\mu = (-E^2 + p^2)A^\\mu$. Now we note that for on-shell massless particles, the combination $-E^2+p^2=0$. Therefore, we replace this combination with the analogous term for massive particles, $(-E^2+p^2+m^2)A^\\mu = \\partial^2A^\\mu + m^2A^\\mu$,\n\\begin{equation}\n\\partial^2A^\\mu + m^2A^\\mu - \\partial^\\mu\\partial_\\nu A^\\nu = j^\\mu \\label{eq:proca}\n\\end{equation}\nwhere $j^\\mu$ is zero for a free massive spin-1 particle and non-zero when it is a virtual propagator. This is the Proca equation.\n\nDifferentiating with $\\partial_\\mu$,\n\\begin{equation}\n\\partial_\\mu \\partial^\\nu \\partial_\\nu A^\\mu + m^2 \\partial_\\mu A^\\mu - \\partial_\\mu \\partial^\\mu \\partial_\\nu A^\\nu = \\partial_\\mu j^\\mu = 0\n\\end{equation}\nwhere the final equality $\\partial_\\mu j^\\mu = 0$ follows from continuity of the 4-current. Now the first and third terms are equal, as can be seen from index contraction (or swap $\\mu \\leftrightarrow \\nu$ and commute $\\partial_\\mu$ and $\\partial_\\nu$ in one term), so we identify\n\\begin{equation}\nm^2 \\partial_\\mu A^\\mu = 0\n\\end{equation}\nwhich is nothing but the Lorenz gauge condition \\eqref{eq:LorentzGauge} for $m^2 \\neq 0$. Therefore, massless spin-1 fields automatically satisfy the Lorenz gauge and we cannot `gauge away' any degrees of freedom as we did in the massless case.\n\nThe field may be expressed in its polarisation states as\n\\begin{equation}\nA^\\mu = \\epsilon^\\mu_i e^{-ipx}\n\\end{equation}\nwith possible spatial polarisations\n\\begin{align*}\n\\epsilon_1 = \\mqty(0\\\\1\\\\0\\\\0)\\,, \\quad  \\epsilon_2 = \\mqty(0\\\\0\\\\1\\\\0)\\,, \\quad \\epsilon_3 = \\mqty(0\\\\0\\\\0\\\\1).\n\\end{align*}\n\nGiven the field now has some mass, we are free to consider its rest frame where $p^\\mu = \\mqty(m,\\,0,\\,0,\\,0)^T$. Therefore the condition $p_\\mu \\epsilon_i^\\mu = 0$ in the rest frame.\n\n\\subsection{Transformation of the polarisation vector}\nNow consider a particle with momentum $p$ along the $z$-axis, without loss of generality, or equivalently a boost of $-p$ from the rest frame. The 4-momentum is $p^\\mu = \\mqty(E,\\,0,\\,0,\\,p)^T$. It is clear that polarisations $\\epsilon_1$ and $\\epsilon_2$ will remain the same since the field is perpendicular to the boost. To determine how $\\epsilon_3$ transforms we use the Lorenz gauge condition,\n\\begin{align}\n0=\\partial_\\mu A^\\mu &= \\partial_\\mu \\left( \\epsilon_3^\\mu e^{-ipx} \\right)\\nonumber \\\\\n&= \\epsilon_3^\\mu (-ip_\\mu) e^{-ipx} = 0 \\nonumber \\\\\n\\Rightarrow \\quad p_\\mu \\epsilon_3^\\mu\n\\end{align}\nNow the covariant (index-down) form of the 4-momentum is $p_\\mu = (E,\\,0,\\,0,\\,-p)$, so the above equation is satisfied by\n\\begin{equation}\n\\epsilon_3^\\mu(p) = \\frac{1}{m}\\mqty(p\\\\0\\\\0\\\\E) = \\frac{1}{m}\\mqty(p\\\\0\\\\0\\\\\\sqrt{p^2+m^2})\n\\end{equation}\nwhere the $1/m$ factor normalises the polarisation vector for free (on-shell) vector bosons.\n\n\\section{Completeness relation}\nFor free massive vector bosons the completeness relation is given by the sum of outer products,\n\\begin{align}\n\\sum_i \\epsilon_i \\epsilon_i^\\dagger &= \\mqty(0\\\\1\\\\0\\\\0)\\mqty(0,\\,1,\\,0,\\,0) + \\mqty(0\\\\0\\\\1\\\\0)\\mqty(0,\\,0,\\,1,\\,0) + \\frac{1}{m^2}\\mqty(p\\\\0\\\\0\\\\E)\\mqty(p,\\,0,\\,0,\\,E) \\\\\n&= \\mqty(\\dmat[0]{\\frac{p^2}{m^2},1,1,\\frac{E^2}{m^2}}) \\\\\n&= -g^{\\mu\\nu} + \\frac{p^\\mu p^\\nu}{m^2}.\n\\end{align}\nVerifying the last equality,\n\\begin{equation}\n-g^{00} + \\frac{p^0 p^0}{m^2} = -1 + \\frac{E^2}{m^2} = \\frac{-m^2+E^2}{m^2} = \\frac{p^2}{m^2}\n\\end{equation}\nand\n\\begin{equation}\n-g^{33} + \\frac{p^3 p^3}{m^2} = 1 + \\frac{p^2}{m^2} = \\frac{m^2+p^2}{m^2} = \\frac{E^2}{m^2}.\n\\end{equation}\n\n\\section{Virtual vector bosons}\n\\subsection{Polarisations}\nFor virtual massive vector bosons there is no longer the constraint that $E^2-p^2=m^2$, so a timelike polarisation is ostensibly allowed. However, imposing the Lorenz gauge condition removes this degree of freedom, just as in the massless case. Now the virtual 4-momentum is $q^\\mu = \\mqty(\\nu,\\vec{q})^T$. Therefore,\n\\begin{equation}\n-Q^2 = q_\\mu q^\\mu = \\nu^2 - \\vec{q}\\cdot\\vec{q},\n\\end{equation}\nwhere $Q^2-m^2$ is the \\emph{virtuality} of the particle. So when travelling along the $z$-axis, $q_z=\\sqrt{\\nu^2+Q^2}$, giving\n\\begin{equation}\nq^\\mu(\\nu) = \\mqty(\\nu\\\\0\\\\0\\\\\\sqrt{\\nu^2+Q^2}).\n\\end{equation}\nTherefore, following the procedure above, the polarisation states of a virtual vector boson are\n\\begin{equation}\n\\epsilon_1 = \\mqty(0\\\\1\\\\0\\\\0)\\,, \\quad  \\epsilon_2 = \\mqty(0\\\\0\\\\1\\\\0)\\,, \\quad \\epsilon_3 = \\frac{1}{Q^2}\\mqty(\\sqrt{\\nu^2+Q^2}\\\\0\\\\0\\\\\\nu).\n\\end{equation}\n\n\\subsection{Propagator}\nFor a massive spin-1 field, we had the Proca equation \\eqref{eq:proca},\n\\begin{equation*}\n\\partial^2A^\\mu + m^2A^\\mu - \\partial^\\mu\\partial_\\nu A^\\nu = j^\\mu\n\\end{equation*}\nand from differentiating,\n\\begin{equation}\nm^2 \\partial_\\mu A^\\mu = \\partial_\\mu j^\\mu.\n\\end{equation}\nSubstituting into the Proca equation,\n\\begin{align}\n(\\partial^2 + m^2)A^\\mu &- \\frac{1}{m^2}\\partial^\\mu \\partial_\\nu j^\\nu = j^\\mu \\nonumber \\\\\n\\Rightarrow \\quad (\\partial^2 + m^2)A^\\mu &= \\frac{1}{m^2}\\partial^\\mu \\partial_\\nu j^\\nu + j^\\mu \\nonumber \\\\\n&= \\frac{1}{m^2}\\partial^\\mu \\partial^\\nu j_\\nu + g^{\\mu\\nu}j_\\nu \\nonumber \\\\\n&= \\left( g^{\\mu\\nu} + \\frac{1}{m^2} \\partial^\\mu \\partial^\\nu \\right)j_\\nu.\n\\end{align}\nNow using that $q^\\mu = i\\partial^\\mu$, $\\partial^\\mu \\partial^\\nu = -q^\\mu q^\\nu$,\n\\begin{equation}\n(\\partial^2 + m^2)A^\\mu = \\left( g^{\\mu\\nu} - \\frac{q^\\mu q^\\nu}{m^2} \\right)j_\\nu\n\\end{equation}\nfrom which we identify the virtual vector boson propagator\n\\begin{equation}\\boxed{\n\\mathcal{G}(q^\\mu) = \\frac{i}{-q^2+m^2} \\left( g^{\\mu\\nu} - \\frac{q^\\mu q^\\nu}{m^2} \\right)\n}.\n\\end{equation}\n\n\\subsubsection{Decay}\nIn an s-channel process, the propagating particle is seen to decay with a characteristic lifetime\n\\begin{equation}\n\\Gamma = \\frac{4\\pi}{m^2} \\frac{1}{32\\pi^2} \\abs{T_{fi}^2} p_f.\n\\end{equation}\nWe therefore modify the wavefunction such that $\\psi^\\dagger \\psi \\sim e^{-\\Gamma t}$,\n\\begin{equation}\n\\psi \\sim e^{-imt -\\frac{\\Gamma}{2}t}.\n\\end{equation}\nBy analogy, we replace $im \\rightarrow im + \\frac{\\Gamma}{2}$ (equivalently $m \\rightarrow m - \\frac{i\\Gamma}{2}$) such that $m^2 \\rightarrow (m - \\frac{i\\Gamma}{2}) \\approx m^2 - i\\gamma m$ where the approximation holds for $\\Gamma \\ll m$ (true for real-world examples),\n\\begin{equation}\n\\mathcal{G}_\\text{decay}(q^\\mu) = \\frac{i}{-q^2+m^2 - i\\Gamma m} \\left( g^{\\mu\\nu} - \\frac{q^\\mu q^\\nu}{m^2 - i\\Gamma m} \\right).\n\\end{equation}\n", "meta": {"hexsha": "fee2eb41a8592c197faf8488e6c63a35c7344206", "size": 6755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/14_Massive_Spin-1_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/14_Massive_Spin-1_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/14_Massive_Spin-1_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": 57.735042735, "max_line_length": 399, "alphanum_fraction": 0.6756476684, "num_tokens": 2481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6225096846742614}}
{"text": "\n\\section{Graph Creation}\n\n\\subsection{Node Pruning}\n\nWe remove all nodes from the graph corresponding to labels with fewer than $t_{seg}$ voxels (Section 3.1).\nFigure \\ref{fig:node-pruning} shows the results of varying $t_{seg}$ on two different quantities for the Kasthuri training volume. \nThe blue line indicates the number of nodes remaining in the graph.\nThe rate of node reduction decreases for larger thresholds since there are fewer labels of larger size. \nThe green line shows the percent of voxels with a label pruned from the graph.\nIdeally this number is low since we want to remove small segments which do not contribute much to the overall volume.\nThis ``volume lost\" grows at an increasing rate as the larger segments are removed. \nBased on these curves we set $t_{seg} = 20,000$ voxels.\nWith this threshold, we prune over half of the labels and only lose $1.5\\%$ of the total volume.\n\n\\subsection{Edge Pruning}\n\nThere are two parameters in the two-pass edge pruning algorithm, $t_{low}$ and $t_{high}$ (Section 3.2). \nThe resulting graph should have a high percentage of the original split errors still present while keeping the number of total edges low. \nWe perform a search over several thresholds from $40\\textrm{nm} \\leq t_{low} \\leq 300 \\textrm{nm}$ and $300 \\textrm{nm} \\leq t_{high} \\leq 800 \\textrm{nm}$ on the Kasthuri training dataset to find the parameter with the highest retention of split errors while keeping the total number of edges less than $6 \\times$ the number of split errors. \n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.95\\linewidth]{./figures/node-threshold.png}\n\t\t\\caption{The number of remaining nodes after increasing the threshold (blue) and the number of voxels with this label as a percent of the total volume (green). }\n\t\t\\label{fig:node-pruning}\n\t\\end{center}\n\\end{figure}\n", "meta": {"hexsha": "7efaaf32f83f1964c47000c936118df4c6c40d23", "size": 1839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/cvpr2018/supplemental/skeletonization.tex", "max_stars_repo_name": "romil797/ibex", "max_stars_repo_head_hexsha": "898134a96e299d8106d9deb7b217671c39bfeca2", "max_stars_repo_licenses": ["MIT"], "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/cvpr2018/supplemental/skeletonization.tex", "max_issues_repo_name": "romil797/ibex", "max_issues_repo_head_hexsha": "898134a96e299d8106d9deb7b217671c39bfeca2", "max_issues_repo_licenses": ["MIT"], "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/cvpr2018/supplemental/skeletonization.tex", "max_forks_repo_name": "romil797/ibex", "max_forks_repo_head_hexsha": "898134a96e299d8106d9deb7b217671c39bfeca2", "max_forks_repo_licenses": ["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.4137931034, "max_line_length": 343, "alphanum_fraction": 0.7705274606, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199795472731, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6224923769388487}}
{"text": "% !TEX root = ../main.tex\n\n\\newpage\n\\appendix\n\\section{Appendix} \\label{sec:Appendix}\n\n\\subsection{Transformation to the QIF model} \\label{app:TransformationToQIF}\nWe prove that the transformation \\eqref{eq:QIFtransformation} holds from the \\QIF model \\eqref{eq:QIFmodel} to the Theta model \\eqref{eq:thetaneuron}.\n\\begin{align*}\nV &\\equiv \\tan \\left( \\frac{\\theta}{2} \\right) \\quad \\longrightarrow \\quad\n\\frac{\\mathop{d V}}{\\mathop{d t}} = \\frac{1}{2 \\cos ^{2}\\left(\\frac{\\theta}{2}\\right)} \\frac{d \\theta}{ \\mathop{d t}}\n\\end{align*}\nInsert into $\\frac{\\mathop{d V}}{\\mathop{d t}}= V^2 + I$:\n\\begin{align*}\n\\frac{\\mathop{d \\theta}}{\\mathop{d t}} &= 2\\left(\\cos ^{2}\\left(\\frac{\\theta}{2}\\right) \\cdot \\tan ^{2}\\left(\\frac{\\theta}{2}\\right)+\\cos ^{2}\\left(\\frac{\\theta}{2}\\right) \\cdot I \\right) = 2\\left(\\sin ^{2}\\left(\\frac{\\theta}{2}\\right)+\\cos ^{2}\\left(\\frac{\\theta}{2}\\right) \\cdot I \\right)\n\\end{align*}\nUsing $\\cos ^{2}\\left(\\frac{\\theta}{2}\\right) = \\frac{1+\\cos \\left(\\frac{\\theta}{2}\\right)}{2}$ and $\\sin ^{2}\\left(\\frac{\\theta}{2}\\right)=\\frac{1-\\cos \\left(\\frac{\\theta}{2}\\right)}{2}$:\n\\begin{align*}\n\\dot{\\theta} &=2\\left(\\frac{1-\\cos \\theta}{2}+\\left(\\frac{1+\\cos \\theta}{2}\\right) \\cdot I \\right) =(1-\\cos \\theta)+(1+\\cos \\theta) \\cdot I\n\\end{align*}\nThis proves that the transformation \\eqref{eq:QIFtransformation} is correct.\n\n \n\\subsection{Solutions to the QIF model} \\label{app:ThetaModelSolutions}\nDepending on the value of $I$, we can distinguish multiple solutions  \\cite{Perez2020}. In all cases we can integrate through the separation of variables. Solutions are bound to start at $V(t_0)$, right after a spike has occured at $t=t_0$. \n\n\\subsubsection{Solving for \\texorpdfstring{$I < 0$}{TEXT}}\n%Change variables: $I = -\\tilde{I}^2$. Separate variables as $\\frac{\\mathop{dv}}{v^2 - \\tilde{I}^2} = \\mathop{dt}$ and integrate from $t = 0$:\n\\begin{align*}\n\\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{v^2 - \\tilde{I}^2} &= \\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{(v+\\tilde{I})(v-\\tilde{I})} \n= \\frac{1}{2 \\tilde{I}} \\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{v-\\tilde{I}}-\\frac{1}{2 \\tilde{I}} \\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{v+\\tilde{I}} \\\\\n%&= \\frac{1}{2 \\tilde{I}} \\log (v-\\tilde{I}) -\\frac{1}{2 \\tilde{I}} \\log (v+\\tilde{I})\\Big \\rvert_{V(t_0)}^{V(t)} \n&= \\frac{1}{2 \\tilde{I}} \\log \\left(1-\\frac{2 \\tilde{I}}{v+\\tilde{I}}\\right) \\Big \\rvert_{V(t_0)}^{V(t)} \n= \\int_{t_0}^t \\mathop{d\\tau} = t - t_0 \\\\\nV(t) &= \\lim_{V(t_0) \\rightarrow -\\infty} \\frac{2 \\sqrt{-I}}{1 - \\left(1-\\frac{2 \\sqrt{-I}}{V(t_0)+\\sqrt{-I}}\\right)\\cdot e^{2 (t - t_0)\\sqrt{-I}}}-\\sqrt{-I}\\\\\n&= \\frac{2 \\sqrt{-I}}{1 - e^{2 (t - t_0) \\sqrt{-I}}}-\\sqrt{-I}\n\\end{align*}\n\n\\subsubsection{Solving for \\texorpdfstring{$I = 0$}{TEXT}}\n\\begin{align*}\n\\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{v^2} &= \\frac{1}{v}\\Big\\rvert_{V(t_0)}^{V(t)} = - \\frac{1}{V(t)} + \\frac{1}{V(t_0)} = \\int_{t_0}^t \\mathop{d\\tau} = t -t_0 \\\\\nV(t) &= \\lim_{V(t_0) \\rightarrow - \\infty} \\frac{V(t_0)}{1-V(t_0)(t - t_0)} \\underset{\\frac{\\infty}{\\infty}}{\\overset{\\mathrm{H}}{=}} \\frac{-1}{t - t_0}\n\\end{align*}\n\n\\subsubsection{Solving for \\texorpdfstring{$I > 0$}{TEXT}}\n%Separate the variables as $\\frac{\\mathop{dv}}{v^2 + I} = \\mathop{dt}$ and integrate from $t=0$:\n\\begin{align*}\n\\int_{V(t_0)}^{V(t)} \\frac{\\mathop{dv}}{v^2 + I} &= \\int_{V(t_0)}^{V(t)} \\frac{I}{\\left(\\frac{v}{\\sqrt{I}}\\right)^2 + 1} \\mathop{dv} \n\\overset{x = \\frac{v}{\\sqrt{I}}}{\\underset{\\mathop{dx} = \\frac{dv}{\\sqrt{I}}}{=}} \n%\\quad \\longrightarrow \\quad x = \\frac{v}{\\sqrt{I}} \\quad \\mathop{dx} = \\frac{\\mathop{dv}}{\\sqrt{I}} \\\\\n\\int_{\\frac{V(t_0)}{\\sqrt{I}}}^{\\frac{V(t)}{\\sqrt{I}}} \\frac{I}{x^2 + 1} \\mathop{dx}= \\frac{1}{\\sqrt{I}} \\arctan(x) \\Big \\rvert_{\\frac{V(t_0)}{\\sqrt{I}}}^{\\frac{V(t)}{\\sqrt{I}}} \\\\\n&= \\frac{1}{\\sqrt{I}} \\left( \\arctan \\left( \\frac{V(t)}{\\sqrt{I}} \\right) - \\arctan \\left( \\frac{V(t_0)}{\\sqrt{I}} \\right) \\right) = \n\\int_{t_0}^t \\mathop{d\\tau} = t - t_0 \\\\\nV(t) &= \\lim_{V(t_0) \\rightarrow -\\infty} \\sqrt{I} \\cdot \\tan \\left( (t - t_0) \\sqrt{I} + \\arctan \\left( \\frac{V(t_0)}{\\sqrt{I}} \\right) \\right) = \\sqrt{I} \\cdot \\tan \\left( (t - t_0) \\sqrt{I} - \\frac{\\pi}{2} \\right) \\\\\n&=  -\\sqrt{I} \\cdot \\cot \\left( (t - t_0) \\sqrt{I} \\right) \n\\end{align*}\n\n\n\\subsection{Frequency response of the Theta model} \\label{app:ThetaModelFrequencyResponse}\nWhat is the relation between spiking period and input current? The integral is solved like before, but now with the conditions of the spike:\n\\begin{align*}\nT - t_0&= \\lim_{a \\rightarrow \\infty} \\int_{-a}^{a} \\frac{I}{\\left(\\frac{v}{\\sqrt{I}}\\right)^2 + 1} \\mathop{dv} \n\\overset{x = \\frac{v}{\\sqrt{I}}}{\\underset{\\mathop{dx} = \\frac{dv}{\\sqrt{I}}}{=}} \n\\lim_{a \\rightarrow \\infty} \\int_{\\frac{-a}{\\sqrt{I}}}^{\\frac{a}{\\sqrt{I}}} \\frac{I}{x^2 + 1} \\mathop{dx}\n= \\lim_{a \\rightarrow \\infty} \\frac{1}{\\sqrt{I}} \\arctan(x) \\Big \\rvert_{\\frac{-a}{\\sqrt{I}}}^{\\frac{a}{\\sqrt{I}}} \\\\\n&= \\frac{1}{\\sqrt{I}} \\left( \\frac{\\pi}{2} - \\left( - \\frac{\\pi}{2} \\right) \\right)\n= \\frac{\\pi}{\\sqrt{I}}\n\\end{align*}\nSo the spiking frequency is proportional to $\\sqrt{I}$. \n\n\n\\subsection{Phase response of the Theta model} \\label{app:ThetaModelPhaseResponse}\nHere we will find an exact expression for the \\PRC. Starting from the analysis in \\ref{app:ThetaModelFrequencyResponse}, we first look for an expression for $T_{\\phi}$. We can resume our normal integration at $\\phi$ with $V \\left( \\phi \\right) + \\varepsilon$:\n\\begin{align*}\nT_{\\phi}=\\frac{1}{\\sqrt{I}}\\left(\\frac{\\pi}{2}-\\arctan \\left(\\frac{V(\\phi)+\\varepsilon}{\\sqrt{I}}\\right)\\right)+\\phi\n\\end{align*}\nAs $V(\\phi)$ is given by \\eqref{eq:ThetaNeuronModelSolutionPeriodic}, we can find:\n\\begin{align*}\nT_{\\phi} = \\frac{1}{\\sqrt{I}}\\left(\\frac{\\pi}{2} - \\arctan \\left(\\frac{\\varepsilon}{\\sqrt{I}} - \\cot \\left(\\phi\\sqrt{I})\\right)\\right)\\right)+\\phi\n\\end{align*}\nThe \\PRC is then simply:\n\\begin{align*}\n\\PRC(\\phi, \\varepsilon) = \\frac{1}{\\sqrt{I}}\\left(\\frac{\\pi}{2} + \\arctan \\left(\\frac{\\varepsilon}{\\sqrt{I}} - \\cot \\left(\\phi \\sqrt{I})\\right)\\right)\\right) - \\phi\n\\end{align*}\n\n\n\\subsection{Newton-Raphson root iteration} \\label{app:NewtonRaphson}\nWe define the equilibria $\\boldsymbol{x^\\ast} \\in \\R^n$ of a multivariate function $\\boldsymbol{f}(\\boldsymbol{x}) : \\R^n \\rightarrow \\R^n$ with $\\boldsymbol{f}(\\boldsymbol{x}) = \\boldsymbol{0}$. Expanding $\\boldsymbol{f}$ as a Taylor series, we obtain:\n\\begin{align*}\nf_i(\\boldsymbol{x} + \\delta \\boldsymbol{x}) =f_{i}(\\boldsymbol{x}) + \\sum_{j=1}^{n} \\frac{\\partial f_{i}(\\boldsymbol{x})}{\\partial x_{j}} \\delta x_{j}+O\\left(\\delta \\boldsymbol{x}^{2}\\right) \\approx f_{i}(\\boldsymbol{x})+\\sum_{j=1}^{n} \\frac{\\partial f_{i}(\\boldsymbol{x})}{\\partial x_{j}} \\delta x_{j}, \\qquad (i=1, \\cdots, n)\n\\end{align*}\nWe can also write this in vector notation, by setting $\\boldsymbol{J}(\\boldsymbol{x}) = \\nabla \\boldsymbol{f}(\\boldsymbol{x}) = \\frac{d}{d\\boldsymbol{x}} \\boldsymbol{f}(\\boldsymbol{x}) \\in \\R^{n \\times n}$ \n\\begin{align*}\n\\boldsymbol{f}(\\boldsymbol{x}+\\delta \\boldsymbol{x}) &\\approx\\left[\\begin{array}{c}f_{1}(\\boldsymbol{x}) \\\\ \\vdots \\\\ f_{N}(\\boldsymbol{x})\\end{array}\\right] \n+ \\left[\\begin{array}{ccc}\\frac{\\partial f_{1}}{\\partial x_{1}} & \\cdots & \\frac{\\partial f_{1}}{\\partial x_{N}} \\\\ \\vdots & \\ddots & \\vdots \\\\ \\frac{\\partial f_{N}}{\\partial x_{1}} & \\cdots & \\frac{\\partial f_{N}}{\\partial x_{N}}\\end{array}\\right]\n\\left[\\begin{array}{c}\\delta x_{1} \\\\ \\vdots \\\\ \\delta x_{N}\\end{array}\\right] \n=\\boldsymbol{f}(\\boldsymbol{x})+\\boldsymbol{J}(\\boldsymbol{x}) \\delta \\boldsymbol{x} \n\\end{align*}\nBy assuming $\\boldsymbol{f}(\\boldsymbol{x}+\\delta \\boldsymbol{x}) = 0$ we can find that $\\delta \\boldsymbol{x} = -\\boldsymbol{J}^{-1}( \\boldsymbol{x}) \\boldsymbol{f}(\\boldsymbol{x})$ so that $\\boldsymbol{x} + \\delta \\boldsymbol{x} =  \\boldsymbol{x} - \\boldsymbol{J}^{-1} (\\boldsymbol{x}) \\boldsymbol{f}(\\boldsymbol{x})$. This expression converges to $\\boldsymbol{x^\\ast}$. When the equations are nonlinear, the equations converge to the real root as $\\boldsymbol{x}_k =  \\boldsymbol{x}_k - \\boldsymbol{J}^{-1} ( \\boldsymbol{x}_k)\\boldsymbol{f}(\\boldsymbol{x}_k)$.\n\n\n\\subsection{Jacobian of the Ott-Antonsen manifold}\nStarting from \\eqref{eq:OttAntonsenSystemFull}, we separate the real and imaginary parts of $z(\\k, t)$ in $x_{\\k} = x(\\k, t)$ and $y_{\\k} = y(\\k, t)$:\n\\begin{align*}\n\\frac{\\partial z_{\\k}}{\\partial t} &= -\\frac{\\ic}{2} \\cdot \\left( x_{\\k}^2 + \\ic 2x_{\\k}y_{\\k} - y_{\\k}^2 - 2x_{\\k} - \\ic 2y_{\\k} +1\\right) + \\frac{1}{2} \\cdot \\left( x_{\\k}^2 + \\ic 2x_{\\k}y_{\\k} - y_{\\k}^2 + 2x_{\\k} + \\ic 2y_{\\k} +1 \\right) \\cdot I_{\\k}\\\\\nI_{\\k} &= -\\sigma_{\\k} + \\ic \\eta_{0, \\k} + \\ic H_{2_{\\k}} \\\\\nH_{2_{\\k}} &= \\frac{\\kappa}{\\kmean} \\sum_{\\kacc \\in \\K} P\\left(\\kacc\\right) \\: a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left( 1 + \\frac{x_{\\k}^2}{3} - \\frac{4}{3} x_{\\k} \\right)\n\\end{align*}\nTaking the dynamics per real and imaginary value yields:\n\\begin{align*}\n\\frac{\\partial x_{\\k}}{\\partial t}\n&=f_{\\k} \\left(x_{\\k}, y_{\\k} \\right) \\\\ \n&=(x_{\\k}-1) y_{\\k}-\\frac{(x_{\\k}+1)^{2}-y_{\\k}^{2}}{2} \\sigma_{\\k} + (x_{\\k}+1) y_{\\k} \\left[\\eta_{0}+ H_{2_{\\k}}\\right] \\\\ \n\\frac{\\partial x_{\\k}}{\\partial t}\n&= g_{\\k} \\left(y_{\\k}, y_{\\k} \\right) \\\\ \n&=-\\frac{(x_{\\k}-1)^{2}-y_{\\k}^{2}}{2}-(x_{\\k}+1) y_{\\k} \\sigma_{\\k} + \\frac{(x_{\\k}+1)^{2}-y_{\\k}^{2}}{2} \\cdot \\left[\\eta_{0} + H_{2_{\\k}} \\right] \n\\end{align*}\nAnd the Jacobian is found from the partial derivatives of $f$ and $g$:\n\\begin{align*}\n\\frac{\\partial f_{\\k}}{\\partial x_{\\k}} &= y_{\\k}-(x_{\\k}+1) \\sigma_{\\k}-y_{\\k} \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] + (x_{\\k}+1) y_{\\k} \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}}\\\\\n\\frac{\\partial f_{\\k}}{\\partial y_{\\k}} &= (x_{\\k}-1)+y_{\\k} \\sigma_{\\k} + (x_{\\k}+1) \\left[\\eta_{0} + H_{2_{\\k}} \\right] \\\\\n\\frac{\\partial g_{\\k}}{\\partial x_{\\k}} &= -(x_{\\k} - 1) - y_{\\k}  \\sigma_{\\k} + (x_{\\k} + 1) \\left[\\eta_{0} + H_{2_{\\k}} \\right] + \\left( \\frac{(x_{\\k} + 1)^2 - y_{\\k}^2}{2} \\right) \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}} \\\\\n\\frac{\\partial g_{\\k}}{\\partial y_{\\k}} &= y_{\\k} - (x_{\\k} + 1) \\sigma_{\\k} - y_{\\k} \\left[\\eta_{0} + H_{2_{\\k}} \\right] \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}} &= \\frac{\\kappa}{\\langle k\\rangle} P\\left(\\k\\right) \\: a\\left(\\k \\rightarrow \\k\\right) (x_{\\k}-2) \\frac{2}{3} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial y_{\\k}} &= 0 \n\\end{align*}\n\nAnd the off-diagonal elements, the nodes represented by degree $\\kacc$:\n\\begin{align*}\n\\frac{\\partial f_{\\k}}{\\partial x_{\\kacc}} &= (x_{\\k}+1) y_{\\k} \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}}\\\\\n\\frac{\\partial f_{\\k}}{\\partial y_{\\kacc}} &= 0 \\\\\n\\frac{\\partial g_{\\k}}{\\partial x_{\\kacc}} &= \\left( \\frac{(x_{\\k} + 1)^2 - y_{\\k}^2}{2} \\right) \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}} \\\\\n\\frac{\\partial g_{\\k}}{\\partial y_{\\kacc}} &= 0\\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}} &= \\frac{\\kappa}{\\langle k\\rangle} P\\left(\\kacc\\right) \\: a\\left(\\kacc \\rightarrow \\k\\right)(x_{\\kacc}-2) \\frac{2}{3} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial y_{\\kacc}} &= 0\n\\end{align*}\n\n\n\\label{LastPage}~\n\n\n\n\n\n", "meta": {"hexsha": "c6d54a88594746b3fca39f9eff8d30286784bb34", "size": 11017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Backmatter/Appendix.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/Backmatter/Appendix.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/Backmatter/Appendix.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": 75.9793103448, "max_line_length": 563, "alphanum_fraction": 0.6098756467, "num_tokens": 4680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199673867852, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6224923631368886}}
{"text": "\\chapter{Swapping order with Lebesgue integrals}\n\\section{Motivating limit interchange}\n\\prototype{$\\mathbf{1}_\\QQ$ is good!}\n\nOne of the issues with the Riemann integral is\nthat it behaves badly with respect to convergence of functions,\nand the Lebesgue integral deals with this.\nThis is therefore often given as a poster child\nor why the Lebesgue integral has better behaviors than the Riemann one.\n\nWe technically have already seen this:\nconsider the indicator function $\\mathbf{1}_\\QQ$,\nwhich is not Riemann integrable by \\Cref{prob:1QQ}.\nBut we can readily compute its Lebesgue integral over $[0,1]$, as\n\\[ \\int_{[0,1]} \\mathbf{1}_\\QQ \\; d\\mu\n\t= \\mu\\left( [0,1] \\cap \\QQ \\right) = 0 \\]\nsince it is countable.\n\nThis \\emph{could} be thought of as a failure of convergence\nfor the Riemann integral.\n\\begin{example}\n\t[$\\mathbf{1}_\\QQ$ is a limit of finitely supported functions]\n\t\\label{ex:1QQindicator}\n\tWe can define the sequence of functions $g_1$, $g_2$, \\dots\\ by\n\t\\[ g_n(x) = \\begin{cases}\n\t\t\t1 & (n!)x \\text{ is an integer} \\\\\n\t\t\t0 & \\text{else}.\n\t\t\\end{cases} \\]\n\tThen each $g_n$ is piecewise continuous\n\tand hence Riemann integrable on $[0,1]$ (with integral zero),\n\tbut $\\lim_{n \\to \\infty} g_n = \\mathbf{1}_\\QQ$ is not.\n\\end{example}\n\nThe limit here is defined in the following sense:\n\\begin{definition}\n\tLet $f$ and $f_1, f_2, \\dots \\colon \\Omega \\to \\RR$ be a sequence of functions.\n\tSuppose that for each $\\omega \\in \\Omega$, the sequence\n\t\\[ f_1(\\omega), \\; f_2(\\omega), \\; f_3(\\omega), \\;, \\dots \\]\n\tconverges to $f(\\omega)$.\n\tThen we say $(f_n)_n$ \\vocab{converges pointwise}\n\tto the limit $f$, written $\\lim_{n \\to \\infty} f_n = f$.\n\n\tWe can define $\\liminf_{n \\to \\infty} f_n$\n\tand $\\limsup_{n \\to \\infty} f_n$ similarly.\n\\end{definition}\nThis is actually a fairly weak notion of convergence, for example:\n\\begin{exercise}\n\t[Witch's hat]\n\tFind a sequence of continuous function on $[-1,1] \\to \\RR$\n\twhich converges pointwise to the function $f$ given by\n\t\\[ f(x) = \\begin{cases}\n\t\t\t1 & x = 0 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases} \\]\n\\end{exercise}\nThis is why when thinking about the Riemann integral\nit is commonplace to work with stronger conditions like\n``uniformly convergent'' and the like.\nHowever, with the Lebesgue integral, we can mostly not think about these!\n\n\\section{Overview}\nThe three big-name results for exchanging\npointwise limits with Lebesgue integrals is:\n\\begin{itemize}\n\t\\ii Fatou's lemma: the most general statement possible,\n\tfor any nonnegative measurable functions.\n\t\\ii Monotone convergence: ``increasing limits'' just work.\n\t\\ii Dominated convergence (actually Fatou-Lebesgue):\n\tlimits that are not too big\n\t(bounded by some absolutely integrable function) just work.\n\\end{itemize}\n\n\\section{Fatou's lemma}\nWithout further ado:\n\\begin{lemma}\n\t[Fatou's lemma]\n\tLet $f_1, f_2, \\dots \\colon \\Omega \\to [0,+\\infty]$\n\tbe a sequence of \\emph{nonnegative} measurable functions.\n\tThen $\\liminf_n \\colon \\Omega \\to [0,+\\infty]$ is measurable and\n\t\\[ \\int_\\Omega \\left( \\liminf_{n \\to \\infty} f_n \\right) \\; d\\mu\n\t\t\\le \\liminf_{n \\to \\infty} \\left( \\int_\\Omega f_n \\; d\\mu \\right).  \\]\n\tHere we allow either side to be $+\\infty$.\n\\end{lemma}\nNotice that there are \\emph{no extra hypothesis}\non $f_n$ other than nonnegative: which makes this quite surprisingly versatile\nif you ever are trying to prove some general result.\n\n\\section{Everything else}\nThe big surprise is how quickly all the ``big-name''\ntheorem follows from Fatou's lemma.\nHere is the so-called ``monotone convergence theorem''.\n\\begin{corollary}\n\t[Monotone convergence theorem]\n\tLet $f$ and $f_1, f_2, \\dots \\colon \\Omega \\to [0,+\\infty]$\n\tbe a sequence of \\emph{nonnegative}\n\tmeasurable functions such that $\\lim_n f_n = f$\n\tand $f_n(\\omega) \\le f(\\omega)$ for each $n$.\n\tThen $f$ is measurable and\n\t\\[ \\lim_{n \\to \\infty} \\left( \\int_\\Omega f_n \\; d\\mu \\right)\n\t\t= \\int_\\Omega f \\; d\\mu. \\]\n\tHere we allow either side to be $+\\infty$.\n\\end{corollary}\n\\begin{proof}\n\tWe have\n\t\\begin{align*}\n\t\t\\int_\\Omega f \\; d\\mu\n\t\t&= \\int_\\Omega \\left( \\liminf_{n \\to \\infty} f_n \\right) \\; d\\mu \\\\\n\t\t&\\le \\liminf_{n \\to \\infty} \\int_\\Omega f_n \\; d\\mu \\\\\n\t\t&\\le \\limsup_{n \\to \\infty} \\int_\\Omega f_n \\; d\\mu \\\\\n\t\t&\\le \\int_\\Omega f \\; d\\mu\n\t\\end{align*}\n\twhere the first $\\le$ is by Fatou lemma,\n\tand the second by the fact that\n\t$\\int_\\Omega f_n \\le \\int_\\Omega f$ for every $n$.\n\tThis implies all the inequalities are equalities and we are done.\n\\end{proof}\n\\begin{remark}\n\t[The monotone convergence theorem does not require monotonicity!]\n\tIn the literature it is much more common\n\tto see the hypothesis $f_1(\\omega) \\le f_2(\\omega) \\le \\dots \\le f(\\omega)$\n\trather than just $f_n(\\omega) \\le f(\\omega)$ for all $n$,\n\twhich is where the theorem gets its name.\n\tHowever as we have shown this hypothesis is superfluous!\n\tThis is pointed out in \\url{https://mathoverflow.net/a/296540/70654},\n\tas a response to a question entitled\n\t``Do you know of any very important theorems that remain unknown?''.\n\\end{remark}\n\n\\begin{example}\n\t[Monotone convergence gives $\\mathbf{1}_\\QQ$]\n\tThis already implies \\Cref{ex:1QQindicator}.\n\tLetting $g_n$ be the indicator function for $\\frac1{n!}\\ZZ$\n\tas described in that example, we have $g_n \\le \\mathbf{1}_\\QQ$\n\tand $\\lim_{n \\to \\infty} g_n(x) = \\mathbf{1}_\\QQ(x)$,\n\tfor each individual $x$.\n\tSo since $\\int_{[0,1]} g_n \\; d\\mu = 0$ for each $n$,\n\tthis gives $\\int_{[0,1]} \\mathbf{1}_\\QQ = 0$ as we already knew.\n\\end{example}\n\nThe most famous result, though is the following.\n\\begin{corollary}\n\t[Fatou–Lebesgue theorem]\n\tLet $f$ and $f_1, f_2, \\dots \\colon \\Omega \\to \\RR$\n\tbe a sequence of measurable functions.\n\tAssume that $g \\colon \\Omega \\to \\RR$ is an\n\t\\emph{absolutely integrable} function for which\n\t$|f_n(\\omega)| \\le |g(\\omega)|$ for all $\\omega \\in \\Omega$.\n\tThen the inequality\n\t\\begin{align*}\n\t\t\\int_\\Omega \\left( \\liminf_{n \\to \\infty} f_n \\right) \\; d\\mu\n\t\t&\\le \\liminf_{n \\to \\infty} \\left( \\int_\\Omega f_n \\; d\\mu \\right) \\\\\n\t\t&\\le \\limsup_{n \\to \\infty} \\left( \\int_\\Omega f_n \\; d\\mu \\right)\n\t\t\\le \\int_\\Omega \\left( \\limsup_{n \\to \\infty} f_n \\right) \\; d\\mu.\n\t\\end{align*}\n\\end{corollary}\n\\begin{proof}\n\tThere are three inequalities:\n\t\\begin{itemize}\n\t\t\\ii The first inequality follows by Fatou on $g + f_n$ which is nonnegative.\n\t\t\\ii The second inequality is just $\\liminf \\le \\limsup$.\n\t\t(This makes the theorem statement easy to remember!)\n\t\t\\ii The third inequality follows by Fatou on $g - f_n$ which is nonnegative.\n\t\t\\qedhere\n\t\\end{itemize}\n\\end{proof}\n\n\\begin{exercise}\n\tWhere is the fact that $g$ is absolutely integrable used in this proof?\n\\end{exercise}\n\n\\begin{corollary}\n\t[Dominated convergence theorem]\n\tLet $f_1, f_2, \\dots \\colon \\Omega \\to \\RR$\n\tbe a sequence of measurable functions\n\tsuch that $f = \\lim_{n \\to \\infty} f_n$ exists.\n\tAssume that $g \\colon \\Omega \\to \\RR$ is an\n\t\\emph{absolutely integrable} function for which\n\t$|f_n(\\omega)| \\le |g(\\omega)|$ for all $\\omega \\in \\Omega$.\n\tThen\n\t\\[ \\int_\\Omega f \\; d \\mu\n\t\t= \\lim_{n \\to \\infty} \\left( \\int_\\Omega f_n \\; d\\mu \\right). \\]\n\\end{corollary}\n\\begin{proof}\n\tIf $f(\\omega) = \\lim_{n \\to \\infty} f_n(\\omega)$,\n\tthen $f(\\omega) = \\liminf_{n \\to \\infty} f_n(\\omega)\n\t= \\limsup_{n \\to \\infty} f_n(\\omega)$.\n\tSo all the inequalities in the Fatou-Lebesgue theorem\n\tbecome equalities, since the leftmost and rightmost sides are equal.\n\\end{proof}\nNote this gives yet another way to verify \\Cref{ex:1QQindicator}.\nIn general, the dominated convergence theorem\nis a favorite clich\\'{e} for undergraduate exams,\nbecause it is easy to create questions for it.\nHere is one example showing how they all look.\n\\begin{example}\n\t[The usual Lebesgue dominated convergence examples]\n\tSuppose one wishes to compute\n\t\\[ \\lim_{n \\to \\infty}\n\t\t\\left( \\int_{(0,1)} \\frac{n\\sin(n\\inv x)}{\\sqrt x} \\right) \\; dx \\]\n\tthen one starts by observing that\n\tthe inner term is bounded by the absolutely integrable function $x^{-1/2}$.\n\tTherefore it equals\n\t\\begin{align*}\n\t\t\\int_{(0,1)} \\lim_{n \\to \\infty}\n\t\t\t\\left( \\frac{n\\sin(n\\inv x)}{\\sqrt x} \\right) \\; dx\n\t\t&= \\int_{(0,1)} \\frac{x}{\\sqrt x} \\; dx \\\\\n\t\t&= \\int_{(0,1)} \\sqrt{x} \\; dx = \\frac23.\n\t\\end{align*}\n\\end{example}\n\n\\section{Fubini and Tonelli}\n\\todo{TO BE WRITTEN}\n\n\\section{\\problemhead}\n\\todo{problems}\n", "meta": {"hexsha": "d59459070d2c14530f3bf99b1f0edd1c60c2a6d6", "size": 8275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/measure/swapsum.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/measure/swapsum.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/measure/swapsum.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.3101851852, "max_line_length": 80, "alphanum_fraction": 0.6958308157, "num_tokens": 2783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.6224923616306743}}
{"text": "\r\n\\subsection{7.1 Curvature and Special Relativity}\r\n\r\n\\subsubsection{7.1.a. Curvature of a Space Curve in $\\mathbb{R}^3$}\r\n\r\n$\\mathbf{x} = \\mathbf{x}(t)$ \\, \\quad $\\left( \\frac{ds}{dt} \\right)^2 = v^2$ \\, \\quad $s(t) = \\int_0^t \\| \\mathbf{x}(u) \\| du$ \\\\\r\n$\\| \\mathbf{v} \\| = v$\\[\r\n\\begin{aligned}\r\n        & \\dot{ \\mathbf{x}} = \\frac{d\\mathbf{x}}{dt} = \\mathbf{v} = \\frac{d\\mathbf{x}}{ds} \\frac{ds}{dt} = \\mathbf{T} v \\\\ \r\n        & \\mathbf{a} = \\ddot{x} = \\mathbf{v} = \\dot{v} \\mathbf{T} + v\\dot{\\mathbf{T}} = \\frac{d^2s}{dt^2} \\mathbf{T} + v \\frac{d\\mathbf{T}}{ds} \\frac{ds}{dt} = \\dot{v} \\mathbf{T} + v^2 \\frac{d\\mathbf{T}}{ds} \\\\ \r\n        & \\mathbf{v} \\times \\mathbf{a} = v^3 \\mathbf{T} \\times \\frac{d\\mathbf{T}}{ds} = v^3 \\kappa(s) \\mathbf{T} \\times \\mathbf{n}\r\n\\end{aligned}\r\n\\]\r\nso \r\n\\[\r\n\\text{unit tangent vector } \\mathbf{T} = \\frac{d\\mathbf{x}}{ds} = \\dot{ \\mathbf{x}} \\left( \\frac{dt}{ds} \\right) = \\frac{ \\mathbf{v}}{v}\r\n\\]\r\nNote that \r\n\\[\r\n\\frac{d\\mathbf{T}}{ds} \\cdot \\mathbf{T} = \\frac{1}{2} \\frac{d}{ds} \\left( \\mathbf{T} \\cdot \\mathbf{T} \\right) = \\frac{1}{2} \\frac{d}{ds} (1) = 0 \r\n\\]\r\n\r\nNow\r\n\\[\r\n\\frac{d\\mathbf{T}}{ds} = \\kappa(s) \\mathbf{n}(s) \\quad \\quad \\, (7.1)\r\n\\]\r\nwhere $\\mathbf{n}$ principal normal, $\\kappa(s) \\geq 0$ curvature of $C$.  \r\n\\[\r\n\\Longrightarrow \\kappa = \\frac{ \\| \\mathbf{v} \\times \\mathbf{a} }{v^3}\r\n\\]\r\n\\paragraph{7.1(1)}\\ \\\\\r\n\\[\r\n\\begin{aligned}\r\n        & x = \\cos{\\omega t} \\\\ \r\n        & y = \\sin{\\omega t} \\\\ \r\n        & z = kt \r\n\\end{aligned} %\\quad \\quad \\dot{x} = \\left( \\begin{matrix} - \\omega s{\\omega t}  \\\\ \\omega c{\\omega t} \\\\ k \\end{matrix} \\right) \\quad \\quad \\mathbf{a} = \\left( \\begin{matrix} - \\omega^2 c{\\omega t} \\\\ - \\omega^2 s{\\omega t} \\\\ 0 \\end{matrix} \\right) \\quad \\, v = \\sqrt{ \\omega^2 + k^2} \r\n\\]\r\n\r\n\\[\r\n\\mathbf{v} \\times \\mathbf{a} = \\left| \\begin{matrix} \\mathbf{e}_x & \\mathbf{e}_y & \\mathbf{e}_z \\\\ -\\omega s{\\omega t} & \\omega c{\\omega t} & k \\\\ - \\omega^2 c{\\omega t} & - \\omega^2 s{\\omega t} & 0 \\end{matrix} \\right| = \\left( \\begin{matrix} k \\omega^2 s{(\\omega t)} \\\\ - k \\omega^2 c{( \\omega t)} \\\\ \\omega^3 \\end{matrix} \\right)\r\n\\]\r\n\\[\r\n\\Longrightarrow \\kappa = \\frac{ \\| \\mathbf{v} \\times \\mathbf{a} \\| }{v^3} = \\frac{ \\sqrt{ k^2 \\omega^4 + \\omega^6} }{ \\sqrt{ ( \\omega^2 + k^2)^3 } } = \\frac{ \\omega^2}{ \\omega^2 + k^2 }\r\n\\]\r\n\r\n\\paragraph{7.1(2)}\\ \\\\\r\n\r\nGiven $\\mathbf{B} = \\mathbf{T} \\times \\mathbf{n}$, \r\n\\[\r\n\\frac{d\\mathbf{B}}{ ds } = \\frac{ d\\mathbf{T} }{ds} \\times \\mathbf{n} + \\mathbf{T} \\times \\frac{d\\mathbf{n}}{ ds} = \\mathbf{T} \\times \\frac{d\\mathbf{n}}{ ds}\r\n\\]\r\nso\r\n\\[\r\n\\mathbf{n} \\times \\frac{d\\mathbf{B}}{ds} = \\mathbf{n} \\times (\\mathbf{T} \\times \\frac{d\\mathbf{n}}{ds} ) = \\left( \\mathbf{n} \\times \\frac{d\\mathbf{n}}{ds} \\right) \\mathbf{T} - (\\mathbf{n} \\times \\mathbf{T}) \\frac{d\\mathbf{n}}{ds} = 0 \r\n\\]\r\nIndeed\r\n\\[\r\n\\begin{aligned}\r\n        & \\mathbf{T} \\cdot \\frac{d\\mathbf{B}}{ds} = 0 \\\\ \r\n        & \\mathbf{B} \\cdot \\frac{d \\mathbf{B}}{ds} = \\frac{d}{ds} ( \\mathbf{B}\\cdot \\mathbf{B}) = \\frac{d}{ds}(1)= 0 \r\n\\end{aligned}\r\n\\]\r\n\r\nThen $\\frac{d\\mathbf{B}}{ds} \\parallel \\mathbf{n}$. \\\\\r\n\r\nDefine torsion $\\frac{d\\mathbf{B}}{ds} = \\tau(s) \\mathbf{n}$\\\\\r\n\r\nUsing $CAB-BAC$,\r\n\\[\r\n\\begin{gathered}\r\n        \\mathbf{n} \\times \\mathbf{B} = \\mathbf{n} \\times (\\mathbf{T} \\times \\mathbf{n} ) = \\mathbf{T} \\\\ \r\n        \\mathbf{T} \\times \\mathbf{B} = \\mathbf{T} \\times (\\mathbf{T} \\times \\mathbf{n} ) = (\\mathbf{n} \\cdot \\mathbf{T} ) \\mathbf{T} - ( \\mathbf{T} \\cdot \\mathbf{T} ) \\mathbf{n} = - \\mathbf{n} \\\\\r\n        \\Longrightarrow \\mathbf{n} = \\mathbf{B} \\times \\mathbf{T}\r\n\\end{gathered}\r\n\\]\r\n\r\nSo\r\n\\[\r\n\\frac{ d \\mathbf{n}}{ d s} = \\frac{ d\\mathbf{B}}{ds} \\times \\mathbf{T}  + \\mathbf{B} \\times \\frac{ d\\mathbf{T}}{ ds} = \\tau \\mathbf{n} \\times \\mathbf{T} + \\mathbf{B} \\times \\kappa \\mathbf{n} = \\boxed{ - \\tau \\mathbf{B} + - \\kappa \\mathbf{T}  = \\frac{ d \\mathbf{n}}{ds} } \r\n\\]\r\n\r\n\r\n\\subsubsection{7.2 Electromagnetism in Minkowski Space}\r\n\r\n\\paragraph{7.2(3)\\quad Field strength 2-Form}\\ \\\\\r\nNotation: \\ieq{\\d x^0 = \\d t}; \\ieq{\\d x^{ij\\cdots} = \\d x^i \\wedge \\d x^j \\wedge \\cdots}. The expansion for \\ieq{*F} was taken from (14.20) combined with (3.41).\r\n\\beq{\r\n\tF \\wedge F\r\n\t\t&= (E_i \\d x^{i0} + B_{J=\\{1,2,3\\}} \\d x^J) \\wedge (E_k \\d x^{k0} + B_{L=\\{1,2,3\\}} \\d x^L) \\\\\r\n\t\t&= -E_iE_k \\bcancel{\\d x^{i0k0}} + B_JB_L \\bcancel{\\d x^{JL}} + E_iB_L \\d x^{i0L} + B_JE_k \\d x^{Jk0} \\\\\r\n\t\t&= -2 E_iB_J \\d x^{0iJ} \\\\\r\n\t\t&= -2 (E_1B_{23}\\d x^{0123} + E_2B_{13}\\d x^{0213} + E_3B_{12}\\d x^{0312}) \\\\\r\n\t\t&= -2 \\underbrace{(E_1B_{23} + E_2B_{31} + E_3B_{12})}_{= \\langle\\vec E, \\vec B\\rangle}\\underbrace{\\d x^{0123}}_{= \\vol^4} \\\\\r\n\t\t&= -2 \\, \\langle\\vec E, \\vec B\\rangle \\vol^4 \\\\\r\n\tF \\wedge *F\r\n\t\t&= (E_i\\d x^{i0}+B_{J=\\{1,2,3\\}}\\d x^J) \\wedge (-(\\vec*B)_k\\d x^{k0} + (\\vec*E)_{L=\\{1,2,3\\}}\\d x^L) \\\\\r\n\t\t&= - E_iB^{\\vec*}_j \\bcancel{\\d x^{i0k0}} + B_JE^{\\vec*}_L \\bcancel{\\d x^{JL}} + E_iE^{\\vec*}_L\\d x^{0iL} - B_JB^{\\vec*}_k\\d x^{0Jk} \\\\\r\n\t\t&= B^{\\vec*}_kB_J \\d x^{0kJ} - E_iE^{\\vec*}_L \\d x^{0iL} \\\\\r\n\t\t&= B^{\\vec*}_kB_J \\d x^{0kJ} - E_kE^{\\vec*}_J \\d x^{0kJ} \\\\\r\n\t\t&= (B^{\\vec*}_kB_J - E_kE^{\\vec*}_J) \\d x^{0kJ} \\\\\r\n\t\t\t&\\qquad\\text{(permute k, J so their combination is in increasing order; } \\\\\r\n\t\t\t&\\qquad\\text{ permuting the double indices of B, E cancels out the minus)} \\\\\r\n\t\t&= (\\|\\vec B\\|^2-\\|\\vec E\\|^2) \\vol^4\r\n}\r\n", "meta": {"hexsha": "1cd18053680032e0f36b41e490d868d6e63c81c0", "size": 5322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX_and_pdfs/the geometry of physics problems/07r3minkowski.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/07r3minkowski.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/07r3minkowski.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.2075471698, "max_line_length": 333, "alphanum_fraction": 0.5338218715, "num_tokens": 2461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6224923606165229}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage{bm}% bold math\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{color}\n\\DeclareMathOperator{\\sgn}{sgn}\n\\renewcommand{\\thefootnote}{\\alph{footnote}}\n\n\\begin{document}\n\n\\subsection{Ideal Gas Model}\n\nFrom (McQuarrie, Statistical mechanics, 2000) the ideal gas method (IGM) for calculating an absolute free energy is outlined below.\n\\begin{equation}\n\tG  = H - TS\n\\end{equation}\n\\begin{equation}\n\tH = U + RT\n\\end{equation}\n\\begin{equation}\n\tU = E_\\text{pot} + E_\\text{ZPE} + E_\\text{trns} + E_\\text{rot} + E_\\text{vib} \\end{equation}\n\\begin{equation}\n\tS = S_\\text{trns} + S_\\text{rot} + S_\\text{vib} + S_\\text{elec}\n\\end{equation}\n\nwhere $T$ is temperature, $R$ the ideal gas constant and $S_\\text{elec}$ is taken to be zero for all molecules. The internal energy components are then\n\n\\begin{equation}\n\tE_\\text{ZPE} = \\frac{N_a}{2}\\sum_i h \\nu_i \n\\end{equation}\n\\begin{equation}\n\tE_\\text{trns} = \\frac{3}{2}RT\n\\end{equation}\n\\begin{equation}\n\tE_\\text{rot} =\n\t\\begin{cases}\n\t\t0 &\\quad \\text{if  } N = 1 \\\\\n\t\tRT &\\quad \\text{if linear} \\\\\n\t\t\\frac{3}{2} RT &\\quad \\text{otherwise} \n\t\\end{cases}\n\\end{equation}\n\\begin{equation}\n\tE_\\text{vib} = R \\sum_i \\frac{\\theta_i}{e^{\\theta_i / T} - 1} \\quad ,\\quad \\theta_i = h\\nu_i / k_B\n\\end{equation}\n\nwhere $N_a$ is Avogadro's's constant, $N$ is the number of atoms in the molecule, $k_B$ Boltzmann's constant, $ \\nu_i$ the $i$-th harmonic frequency and $h$ is Planks constant. The entropic components are \n\n\\begin{equation}\n\tS_\\text{trns} = R  \\ln(q_\\text{trns}) + \\frac{5}{2}R\n\\end{equation}\n\\begin{equation}\n\tS_\\text{rot} = \\begin{cases}\n\t\t0 &\\quad \\text{if  } N = 1 \\\\\n\t\tR  \\ln(q_\\text{rot}) + R &\\quad \\text{if linear} \\\\\n\t\tR  \\ln(q_\\text{rot}) + \\frac{3}{2}R &\\quad \\text{otherwise}\n\t\\end{cases}\n\\end{equation}\n\\begin{equation}\n\tS_\\text{vib}^\\text{HO} = R \\sum_i \\frac{\\theta_i}{T(e^{\\theta_i / T} - 1)} - \\ln(1 - e^{-\\theta_i / T})\n\\end{equation}\n\\begin{equation}\n\tq_\\text{trans} = {\\Big (} \\frac{2\\pi m k_B T}{h^2} {\\Big )}^{3/2}  V_\\text{eff} \\quad , \\quad V_\\text{eff} =  \\begin{cases}\n\t\tk_B T / p^{\\circ} \\quad&\\text{if 1 atm standard state} \\\\\n\t\t1 / c^\\circ N_a \\quad&\\text{if 1 M standard state} \n\t\\end{cases}\n\\end{equation}\n\\begin{equation}\n\tq_\\text{rot} = \\frac{T^{3/2}}{\\sigma_r} \\sqrt{\\frac{\\pi}{\\omega_r}} \\quad,\\quad \\omega_r = \\prod_{k} \\frac{h^2}{8 \\pi^2 k_B I_k}\n\\end{equation}\n\nwhere $q$ are molecular partition functions, $p^{\\circ}$ is the standard pressure (1 atm) and $c^\\circ$ the standard concentration (1 mol dm$^{-3}$), $\\sigma_r$ is the rotational symmetry number for the molecule and $I_k$ a diagonal element of the moment of inertia matrix.\n\\\\\\\\\nDue to the vibrational entropy contribution being overestimated for low frequency modes Thrular proposed a correction, which instead of summing over frequencies in $S_\\text{vib}^\\text{HO}$ does so over $\\max(\\nu_\\text{thresh},\\; \\nu_i)$ to shift all low frequencies to a threshold value (\\emph{J. Phys. Chem. B} 2011, {\\bfseries{115}}, 14556). An alternative method from Grimme (\\emph{Chem. Eur. J.}, 2012, {\\bfseries{18}}, 9955) uses an interpolation between a harmonic oscillator and rigid rotor to scale down the contribution from the low frequency modes as\n\\begin{equation}\n\tS_\\text{vib}^\\text{Grimme} = \\sum_i w_i S_ \\text{vib}^\\text{HO}(i) + (1-w_i) {\\Big (} R\\ln {\\Big (} \\sqrt{\\frac{8 \\pi^3 \\mu_i' k_B T}{h^2}} {\\Big )} + \\frac{R}{2} {\\Big )}\n\\end{equation}\n\\begin{eqnarray}\n\t\\mu_i' = \\frac{\\mu_i \\bar{B}}{\\mu_i + \\bar{B}} \\quad,\\quad \\mu_i = \\frac{h}{8\\pi^2 \\nu_i} \\quad,\\quad \\bar{B} = \\text{Tr}[I] / 3\n\\end{eqnarray}\n\\begin{equation}\n\tw_i = \\frac{1}{1 + (\\omega_0/ \\nu_i)^\\alpha}\n\\end{equation}\nwhere $\\omega_0$ and $\\alpha$ are adjustable parameters.\n\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "9d04d27f750a365abe0fd41d34074331e8e795d7", "size": 3745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "autode/common/thermochemistry.tex", "max_stars_repo_name": "tlestang/autodE", "max_stars_repo_head_hexsha": "56fd4c78e7d7e78c5747428190211ff69dc6d94a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2020-03-13T15:03:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T13:41:04.000Z", "max_issues_repo_path": "autode/common/thermochemistry.tex", "max_issues_repo_name": "skphy/autodE", "max_issues_repo_head_hexsha": "fd80995206ac601299d2f78105d0fe4deee8c2cf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 117, "max_issues_repo_issues_event_min_datetime": "2020-06-13T00:11:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T08:54:16.000Z", "max_forks_repo_path": "autode/common/thermochemistry.tex", "max_forks_repo_name": "skphy/autodE", "max_forks_repo_head_hexsha": "fd80995206ac601299d2f78105d0fe4deee8c2cf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2020-08-14T04:52:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T13:04:17.000Z", "avg_line_length": 41.1538461538, "max_line_length": 560, "alphanum_fraction": 0.6707610147, "num_tokens": 1398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332893, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6224923553597853}}
{"text": "\\appendixchapter{ACESproxy function derivation}{i}\n\\label{appendixD}\n\nThe ACESproxy 10-bit and 12-bit logarithmic encoding and decoding functions have been derived from the single mathematical function described below. A series of parameters are defined and the values for the parameters specified based on the bit depth of the encoding.\n\n\\unnumberedformat\n\\section{Math functions}\nThe following general-use math functions are defined for use within the equations.\n\nROUND$(\\mathbf{a})$ \\tabto{7em}Math function taking a floating-point value $\\mathbf{a}$, and returning the integer value closest to $\\mathbf{a}$.\n\nMAX$(\\mathbf{a,b})$ \\tabto{7em}Math function returning the greater of $\\mathbf{a}$ or $\\mathbf{b}$\n\nMIN$(\\mathbf{a,b})$ \\tabto{7em}Math function returning the lesser of $\\mathbf{a}$ or $\\mathbf{b}$\n\nFLOAT2CV$(\\mathbf{a})$ \\tabto{7em}Math function returning MAX($CVmin$, MIN($CVmax$, ROUND($\\mathbf{a}$)))\n\n\\section{Parameters}\nThe following parameters are defined for each bit-depth.\n\n\\begin{itemize}\n\t\\item $CVmin$ is the minimum code value available for representation of ACES image data.\n\t\\item $CVmax$ is the maximum code value available for representation of ACES image data.\n\t\\item $StepsPerStop$ is the number of code values representing a change of 1 stop in exposure.\n\t\\item $MidCVoffset$ is the integer code value representing the assigned midpoint of the exposure scale for a particular bit-depth encoding. (e.g. the point to which a mid-grey exposure value would be mapped)\n\t\\item $MidLogOffset$ is the base 2 logarithmic value representing the assigned midpoint of the exposure scale in log space, [e.g. $MidLogOffset = \\log_2( 2^{-2.5} ) = -2.5$ ]\n\\end{itemize}\n\n\\begin{center}\n\\begin{tabularx}{0.75\\textwidth}{|l|Y|Y|}\n\\hline\n\t & \\textbf{ACESproxy 10-bit CV} & \\textbf{ACESproxy 12-bit CV} \\\\ \\hline\n\t$CVmin$ & 64 & 256 \\\\ \\hline\n\t$CVmax$ & 940& 3760 \\\\ \\hline\n\t$StepsPerStop$ & 50 & 200 \\\\ \\hline\n\t$MidCVoffset$ & 425 & 1700 \\\\ \\hline\n\t$MidLogOffset$ & -2.5 & -2.5 \\\\ \\hline\n\\end{tabularx}\n\\end{center}\n\n\\note{$MidCVoffset$ is not equal to the ACESproxy value that most closely represents an ACES mid-gray value of 0.18. ACES 0.18 is most closely represented by ACESproxy 426 10-bit CV and 1705 12-bit CV.}\n \n\\newpage\n\\section{Encoding Function}\nThe following floating-point equation is used to convert linear values to integer code values.\n\\begin{equation} \n    \\resizebox{\\textwidth}{!}{$\n    ACESproxy = \\left\\{ \n    \\begin{array}{l l}\n        CVmin;    & lin \\leq 2^{\\left({\\frac{(CVmin-MidCVoffset)}{StepsPerStop}-MidLogOffset}\\right)} \\\\\n        \\mathrm{FLOAT2CV}\\left[\\left(\\log_2(lin)-MidLogOffset\\right)\\times StepsPerStop+MidCVOffset\\right];        & lin > 2^{\\left({\\frac{(CVmin-MidCVoffset)}{StepsPerStop}-MidLogOffset}\\right)} \\\\\n    \\end{array} \\right. $ }\n\\end{equation}\n\nwhere $ACESproxy$ is the resulting integer code value in the range of code values from $CVmin$ to $CVmax$. \n\n\nAn implementation may use mathematically equivalent forms of this encoding equation.\n\n\n\\section{Decoding Function}\nThe following floating-point equation is used to convert ACESproxy integer code values to linear values.\n\n\\begin{center}\n$lin = 2^{\\left( \\dfrac{(ACESproxy-MidCVoffset)}{StepsPerStop} + MidLogOffset\\right)}$\n\n\\end{center}\n\nThe conversion to linear creates the closest value in 16-bit half precision floating-point to the floating-point result of the equation. Linear values resulting from this equation are limited to the range of values that can be encoded in ACESproxy as illustrated in Appendix \\ref{appendixB}. This decoding function does not produce negative values.\n\n\nAn implementation may use mathematically equivalent forms of this decoding equation.", "meta": {"hexsha": "0d8fef94b6b30f7516f16468ccc2a441f9475606", "size": 3699, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/LaTeX/S-2013-001/appendixD.tex", "max_stars_repo_name": "KelSolaar/aces-dev", "max_stars_repo_head_hexsha": "76ea982a988d278dd12b563602771f46a5da3b83", "max_stars_repo_licenses": ["AMPAS"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-01-04T18:12:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-27T06:46:50.000Z", "max_issues_repo_path": "documents/LaTeX/S-2013-001/appendixD.tex", "max_issues_repo_name": "colour-science/aces-dev", "max_issues_repo_head_hexsha": "86284e2f145a89e3612f05ec7ea5a3e9d92cc779", "max_issues_repo_licenses": ["AMPAS"], "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/LaTeX/S-2013-001/appendixD.tex", "max_forks_repo_name": "colour-science/aces-dev", "max_forks_repo_head_hexsha": "86284e2f145a89e3612f05ec7ea5a3e9d92cc779", "max_forks_repo_licenses": ["AMPAS"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.375, "max_line_length": 348, "alphanum_fraction": 0.7466882941, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619959279793, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6224923523473567}}
{"text": "\\chapter{Multiplying Polynomials}\n\nWatch Khan Academy's \\textbf{Multiplying monomials} at \\url{https://youtu.be/Vm7H0VTlIco}.\n\nTo review, when you multiply two monomials, you take the product of\ntheir coefficients and the sum of their degrees:\n\\begin{equation*}\n  (2x^6)(5x^3) = (2)(5)(x^6)(x^3) = 10x^9\n\\end{equation*}\nIf you have a product of more than two monomials, multiply \\emph{all}\nthe coefficients and sum \\emph{all} the exponents:\n\\begin{equation*}\n  (3x^2)(2x^3)(4x) = (3)(2)(4)(x^2)(x^3)(x^1) = 24x^6\n\\end{equation*}\\index{multiplication!polynomials}\n\n\\begin{Exercise}[title={Multiplying monomials}, label=multmonomials]\nMultiply these monomials\n  \\Question $(3x^2)(5x^3)$\n\\vspace{20mm}\n  \\Question $(2x)(4x^9)$\n\\vspace{20mm}\n  \\Question $(-5.5x^2)(2x^3)$\n\\vspace{20mm}\n  \\Question $(\\pi)(-2x^5)$\n\\vspace{20mm}\n  \\Question $(2x)(3x^2)(5x^7)$\n\\vspace{20mm}\n\\end{Exercise}\n\\begin{Answer}[ref=multmonomials]\n  $(3x^2)(5x^3) = 15x^5$\n  \n  $(2x)(4x^9) = 8x^{10}$\n  \n  $(-5.5x^2)(2x^3) = -11x^5$\n\n  $(\\pi)(-2x^5) = -2\\pi x^5$\n  \n  $(2x)(3x^2)(5x^7) = 30x^{10}$\n\\end{Answer}\n\n\\section{Multiplying a monomial and a polynomial}\n\nWatch Khan Academy's \\textbf{Multiplying monomials by polynomials} at \\url{https://youtu.be/pD2-H15ucNE}.\n\nWhen multiplying a monomial and a polynomial, you use the the distributive property. Then it is just multiplying several pairs of monomials:\n\\begin{multline*}\n  (3x^2)(4x^3 - 2x^2 + 3x - 7) \\\\\n  = (3x^2)(4x^3) + (3x^2)(-2x^2) + (3x^2)(3x) + (3x^2)(-7) \\\\\n  = 12x^5 - 6x^4 + 9x^3 -21x^2\n\\end{multline*}\n\n\\begin{Exercise}[title={Multiplying a monomial and a polynomial}, label=multmonopoly]\nMultiply these monomials\n\\Question $(3x^2)(5x^3 - 2x + 3)$\n\\vspace{20mm}\n\\Question $(2x)(4x^9 - 1)$\n\\vspace{20mm}\n\\Question $(-5.5x^2)(2x^3 + 4x^2 + 6)$\n\\vspace{20mm}\n\\Question $(\\pi)(-2x^5 + 3x^4 + x)$\n\\vspace{20mm}\n\\Question $(2x)(3x^2)(5x^7 + 2x)$\n\\end{Exercise}\n\\begin{Answer}[ref=multmonopoly]\n  $(3x^2)(5x^3 - 2x + 3) = 15x^6 - 6x^3 + 6x^2$\n\n  $(2x)(4x^9 - 1) = 8x^{10} - 2x$\n\n  $(-5.5x^2)(2x^3 + 4x^2 + 6) = 11x^5 - 22x^4 + 33x^2$\n\n  $(\\pi)(-2x^5 + 3x^4 + x) = -2\\pi x^5 + 3\\pi x^4 + \\pi x$\n\n  $(2x)(3x^2)(5x^7 + 2x) = 30x^{10} + 12x^4$\n\\end{Answer}\n\n\\section{Multiplying polynomials}\n\nWatch Khan Academy's \\textbf{Multiplying binomials by polynomials} video at \\url{https://youtu.be/D6mivA_8L8U}\n\nWhen you are multiplying two polynomials, you will use the\ndistributive property several times to make it one long\npolynomial. Then you will combine the terms with the same degree. For\nexample,\n\\begin{multline*}\n  (2x^2 - 3)(5x^2 + 2x - 7) \\\\\n  =   (2x^2)(5x^2 + 2x - 7) + (-3)(5x^2 + 2x - 7) \\\\\n  =   (2x^2)(5x^2) + (2x^2)(2x) + (2x^2)(-7) + (-3)(5x^2) + (-3)(2x) + (-3)(-7) \\\\\n  =   10^4 + 4x^3 + -14x^2 + -15x^2 + -6x + 21\n  =   10^4 + 4x^3 + -29x^2 + -6x + 21\n\\end{multline*}\n\nOne common form that you will see is multiplying two binomials together:\n\\begin{multline*}\n(2x + 7)(5x + 3) = (2x)(5x + 3) + (7)(5x+3) = (2x)(5x) + (7)(5x) + (2x)(3) + (7)(3)\n\\end{multline*}\nNotice the product has become the sum of four parts: the firsts, the\ninners, the outers, and the lasts. People sometimes use the mnemonic\nFOIL to remember this pattern, but there is a general rule that works\nfor all product of polynomials, not just binomials.  Here it is: Every\nterm in the first will be multiplied by every term in the second, and\nthen just add them together.\n\nSo, for example, if you have a polynomial $s$ with three terms and you\nmultiply it by a polynomial $t$ with five terms, you will get a sum of\n15 terms -- each term is a product of two monomials, one from $s$ and\none from $t$.  (Of course, several of those terms might have the same\ndegree, so they will be combined together when you simplify. Thus you\ntypically end up with a polynomial with less than 15 terms.)\n\nUsing this rule, here is how I would multiply $2x^2 - 3x + 1$ and\n$5x^2 + 2x - 7$:\n\\begin{multline*}\n  (2x^2 - 3x + 1)(5x^2 + 2x - 7)  = \\begin{matrix}\n  (2x^2)(5x^2)& + &(2x^2)(2x)& + &(2x^2)(-7)& + \\\\\n  (-3x)(5x^2)& + &(-3x)(2x)& + &(-3x)(-7)& + \\\\\n    (1)(5x^2)& + &(1)(2x)& + &(1)(-7)& \n  \\end{matrix} \\\\\n  = 10x^4 + 4x^3 + (-14)x^2 + (-15)x^3 + (-6)x^2 + 21x +5x^2 + 2x + (-7) \\\\\n  = 10x^4 + (4 - 15)x^3 + (-14 - 6 + 5)x^2  + (21 + 2)x + (-7) \\\\\n  = 10x^4 - 11x^3 - 15x^2 + 23x - 7\n\\end{multline*}\nNote that the product (before combining terms with the same degree) has\n$3 \\times 3 = 9$ terms -- every possible combination of a term from the\nfirst polynomial and a term from the second polynomial.\n\nOne common source of error: losing track of the negative\nsigns. You will need to be really careful. I have found that it\nhelps to use + between all terms, and use negative coefficients to\nexpress subtraction. For example, if the problem says $4x^2 - 5x - 3$,\nyou should work with that as $4x^2 + (-5)x + (-3)$\n\n\\begin{Exercise}[title={Multiplying polynomials}, label=multpolys]\n  Multiply the following pairs of polynomials:\n  \\Question{$2x + 1$ and $3x - 2$}\n  \\vspace{15mm}\n  \\Question{$-3x^2 + 5$ and $4x -2$}\n  \\vspace{15mm}\n  \\Question{$-2x - 1$ and $-3x - \\pi$}\n  \\vspace{15mm}\n  \\Question{$-2x^5 + 5x$ and $3x^5 + 2x$}\n  \\vspace{15mm}\n\n\\end{Exercise}\n\\begin{Answer}[ref=multpolys]\n  $(2x + 1)(3x - 2) = 6x^2 - x - 2$\n\n  $(-3x^2 + 5)(4x - 2) = -12x^3 + 6x^2 + 20x - 10$\n\n  $(-2x - 1)(-3x - \\pi) = 6x^2 + (4 + 2\\pi)x + \\pi$ \n\n  $(-2x^5 + 5x)(3x^5 + 2x) = -6x^{10} + 12x^6 + 10x^2$\n\\end{Answer}\n\n\\begin{Exercise}[title={Observations}, label=obsmultpoly]\n  Let's say I have two polynomials, $p_1$ and $p_2$.  $p_1$ has degree\n  23.  $p_2$ has degree 12.  What is the degree of their product?\n\\end{Exercise}\n\\begin{Answer}[ref=obsmultpoly]\n  The degree of the product is determined by the term that is the\n  product of the highest degree term in $p_1$ and the highest degree\n  term in $p_2$. Thus, the product of a degree 23 polynomial and a\n  degree 12 polynomial has degree 35.\n\\end{Answer}\n  \n", "meta": {"hexsha": "5d948f5bfc7dcc40f2b100c5f0d991daf642fb64", "size": 5900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/multiplying-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/multiplying-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/multiplying-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": 35.7575757576, "max_line_length": 140, "alphanum_fraction": 0.6342372881, "num_tokens": 2482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6223986708355136}}
{"text": "%!TEX root =  ../main.tex\n\n\\objective{Find higher derivatives of functions, apply and produce their graphs}\n\n\n\\index{Concavity}\nThe first derivative of a function tell you the slope of the graph at any point.  When the\nderivative function is positive, the original graph slopes up.  When it is negative the original\ngraph slopes down.  When it is zero, the original graph is flat.  \n\nCould you graph the original function if you were given the derivative?  Well, you wouldn't \nknow where to start, but once you picked a beginning, your slope would make it clear\nwhere to go from there.  Practice staying within the graphical realm, drawing the derivative\nof a given function, or a possible function given its derivative graph.\n\n\n\\subsection{Second Derivatives}\nBut what about the derivative of the derivative?\nThe slope of the slope is the rate of change, or acceleration.  Think about what happens when\nyou accelerate, even if you are traveling backwards at first: your velocity becomes more and more\npositive.  On the other hand, deceleration means slowing down and quickly traveling backwards more and\nmore quickly.\n\n\\begin{figure}\n\\begin{centering}\n\\begin{tabular}{ |c|c|l| }\n\\hline\n$f'(x)$ & $f''(x)$ & $f(x)$ \\\\ \\hline \\hline\n\\multirow{3}{*}{ + } & + & right side of a valley \\\\ \\cline{2-3}\n & 0 & top of a peak \\\\ \\cline{2-3}\n & - & left side of a mountain \\\\ \\hline\n\\multirow{3}{*}{ 0 } & + & end of a valley, start of a peak \\\\ \\cline{2-3}\n & 0 & plateau \\\\ \\cline{2-3}\n & - & end of a peak, start of a valley \\\\ \\hline\n\\multirow{3}{*}{ - } & + & ride side of a valley \\\\ \\cline{2-3}\n & 0 & bottom of a valley \\\\ \\cline{2-3}\n & - & right side of a peak \\\\\n\\hline\n\\end{tabular}\n\\caption{Relating first and second derivative signs to a graph}\n\\end{centering}\n\\end{figure}\n\n\nMost of these behaviors can be seen in figure ...  The solid curve is $f(x)=\\frac{1}{6}x^6\n-2x^4+8x^2-20$.  The dashed curve is $f'(x)$ and the dotted is $f''(x)$.\n\n\\begin{figure}\\label{derivativesigns}\n\\begin{centering}\n\\includegraphics[width=\\textwidth]{\\chapdir/pics/derivativesigns}\n\\caption{A function with inflection and turning points}\n\\end{centering}\n\\end{figure}\n\n", "meta": {"hexsha": "5950d9ddd3ca3c2475b7623098ac667514ac14fd", "size": 2154, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch05/0504.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/0504.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/0504.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": 39.1636363636, "max_line_length": 102, "alphanum_fraction": 0.7140204271, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6223986519752581}}
{"text": "\\section{Homotopy pushouts}\n\nA common way in topology to construct new spaces is by attaching cells\\index{attaching cells} to a given space. A $0$-cell is just a point, an $1$-cell is an interval, a $2$-cell is a disc, a $3$-cell is the solid ball, and so forth. Many spaces can be obtained by attaching cells. For example, the circle\\index{circle} is obtained by attaching a $1$-cell to a $0$-cell, so that both end-points of the interval are mapped to the point. More generally, an $n$-sphere is obtained by attaching an $n$-disc to the point, so that its entire boundary gets mapped to the point.\n\nIn type theory we can also consider a notion of $n$-cells. Just as in topology, a $0$-cell is just a point (i.e., a term). A $1$-cell, however, is in type theory an identification, i.e., a term of the identity type. A $1$-cell is then an identification of identifications, and so forth. Then we can attach cells to a type by taking a pushout, which is a process dual to taking a pullback. \n\nThe idea of pushouts is to glue two types $A$ and $B$ together using a mediating type $S$ and maps $f:S\\to A$ and $g:S\\to B$. In other words, we start with a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA & S \\arrow[l,swap,\"f\"] \\arrow[r,\"g\"] & B.\n\\end{tikzcd}\n\\end{equation*}\nWe call such a triple $\\mathcal{S}\\jdeq (S,f,g)$ a \\define{span}\\index{span} from $A$ to $B$.\nA span from $A$ to $B$ can be thought of as a relation\\index{relation} from $A$ to $B$, relating $f(s)$ to $g(s)$ for any $s:S$.\n\nUnlike pullbacks, however, it is not automatically the case that pushouts always exist, and there are several equivalent characterizations of pushouts. Two such characterizations are presented in this lecture, establishing the duality between pullbacks and pushouts. Other characterizations, including the induction principle of pushouts, and the \\emph{dependent universal property} of pushouts, are studied in \\cref{chap:descent}.\n\n\\subsection{The universal property of pushouts}\n\n\\begin{defn}\nConsider a span $\\mathcal{S}\\jdeq (S,f,g)$ from $A$ to $B$, and let $X$ be a type.\nA \\define{cocone}\\index{cocone|textbf} with vertex $X$ on $\\mathcal{S}$ is a triple $(i,j,H)$ consisting of maps $i:A\\to X$ and $j:B\\to X$, and a homotopy $H:i\\circ f\\htpy j\\circ g$ witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X\n\\end{tikzcd}\n\\end{equation*}\ncommutes.\nWe write $\\mathsf{cocone}_{\\mathcal{S}}(X)$\\index{cocone_S(X)@{$\\mathsf{cocone}_{\\mathcal{S}}(X)$}|textbf} for the type of cocones on $\\mathcal{S}$ with vertex $X$.\n\\end{defn}\n\n\\begin{rmk}\\label{rmk:htpy-cocone}\n  Given two cocones $(i,j,H)$ and $(i',j',H')$ with vertex $C$, the type of identifications $(i,j,H)=(i',j',H')$ in $\\mathsf{cocone}_{\\mathcal{S}}(C)$ is equivalent to the type of triples $(K,L,M)$ consisting of\n  \\begin{align*}\n    K : i\\htpy i' \\\\\n    L : j\\htpy j',\n  \\end{align*}\n  and a homotopy $M$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      %  ((pr2 (pr2 c)) ∙h (L ·r g)) ~ ((K ·r f) ∙h (pr2 (pr2 c')))\n      i\\circ f \\arrow[d,swap,\"H\"] \\arrow[r,\"K\\cdot f\"] & i' \\circ f \\arrow[d,\"{H'}\"] \\\\\n      j\\circ g \\arrow[r,swap,\"K_B\\cdot g\"] & j'\\circ g\n    \\end{tikzcd}\n  \\end{equation*}\n  of homotopies commutes.\n\\end{rmk}\n\n\\begin{defn}\nConsider a cocone $(i,j,H)$ with vertex $X$ on the span $\\mathcal{S}\\jdeq (S,f,g)$, as indicated in the following commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X.\n\\end{tikzcd}\n\\end{equation*}\nFor every type $Y$, we define the map\\index{cocone_map@{$\\mathsf{cocone\\usc{}map}$}|textbf}\n\\begin{equation*}\n\\mathsf{cocone\\usc{}map}(i,j,H):(X\\to Y)\\to \\mathsf{cocone}(Y)\n\\end{equation*}\nby $h\\mapsto (h\\circ i,h\\circ j,h\\cdot H)$.\n\\end{defn}\n\n\\begin{defn}\n  A commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\n      A \\arrow[r,swap,\"i\"] & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  with $H:i\\circ f \\htpy j\\circ g$ is said to be a \\define{(homotopy) pushout square}\\index{pushout square} if the cocone $(i,j,H)$ with vertex $X$ on the span $\\mathcal{S}\\jdeq (S,f,g)$\n  satisfies the \\define{universal property of pushouts}\\index{universal property!of pushouts|textbf}, which asserts that the map\n  \\begin{equation*}\n    \\mathsf{cocone\\usc{}map}(i,j,H):(X\\to Y)\\to \\mathsf{cocone}(Y)\n  \\end{equation*}\n  is an equivalence for any type $Y$. Sometimes pushout squares are also called \\define{cocartesian squares}\\index{cocartesian square|textbf}.\n\\end{defn}\n\n\\begin{lem}\\label{lem:unique-mapping-property-pushout}\n  Consider a pushout square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\n      A \\arrow[r,swap,\"i\"] & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  with $H:i\\circ f \\htpy j\\circ g$, and consider a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"{j'}\"] \\\\\n      A \\arrow[r,swap,\"{i'}\"] & X'.\n    \\end{tikzcd}\n  \\end{equation*}\n  with $H':i'\\circ f \\htpy j'\\circ g$. Then the type of maps $h:X\\to X'$ equipped with homotopies\n  \\begin{align*}\n    K & : h\\circ i \\htpy i' \\\\\n    L & : h\\circ j \\htpy j'\n  \\end{align*}\n  and a homotopy $M$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      h\\circ i\\circ f \\arrow[r,\"K\\cdot f\"] \\arrow[d,swap,\"h\\cdot H\"] & i' \\circ f \\arrow[d,\"{H'}\"] \\\\\n      h\\circ j\\circ g \\arrow[r,swap,\"L\\cdot g\"] & j'\\circ g\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, is contractible.\n\\end{lem}\n\n\\begin{proof}\n  For any map $h:X\\to X$', the type of triples $(K,L,M)$ as in the statement of the lemma is equivalent to the type of identifications\n  \\begin{equation*}\n    \\mathsf{cocone\\usc{}map}((i,j,H),h)=(i',j',H'),\n  \\end{equation*}\n  by \\cref{rmk:htpy-cocone}. Therefore it follows that the type of quadruples $(h,K,L,M)$ is equivalent to the fiber of $\\mathsf{cocone\\usc{}map}(i,j,H)$ at $(i',j',H')$. Since we have assumed that the cocone $(i,j,H)$ satisfies the universal property of the pushout of $\\mathcal{S}$, the map $\\mathsf{cocone\\usc{}map}(i,j,H)$ is an equivalence, and therefore it has contractible fibers by \\cref{thm:contr_equiv}.\n\\end{proof}\n\n\\begin{thm}\\label{thm:3-for-2-pushout}\n  Consider two cocones\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"]\n      & & S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"{j'}\"] \\\\\n      A \\arrow[r,swap,\"i\"] & C\n      & & A \\arrow[r,swap,\"{i'}\"] & C'\n    \\end{tikzcd}\n  \\end{equation*}\n  on a span $\\mathcal{S}\\jdeq(S,f,g)$, and let $h:C\\to C'$ be a map equipped with homotopies\n  \\begin{align*}\n    K & : h\\circ i \\htpy i' \\\\\n    L & : h\\circ j \\htpy j'\n  \\end{align*}\n  and a homotopy $M$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      h\\circ i\\circ f \\arrow[r,\"K\\cdot f\"] \\arrow[d,swap,\"h\\cdot H\"] & i' \\circ f \\arrow[d,\"{H'}\"] \\\\\n      h\\circ j\\circ g \\arrow[r,swap,\"L\\cdot g\"] & j'\\circ g\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Then if any two of the following three statements hold, so does the third:\n  \\begin{enumerate}\n  \\item The cocone $(i,j,H)$ satisfies the universal property of the pushout of $\\mathcal{S}$.\n  \\item The cocone $(i',j',H')$ satisfies the universal property of the pushotu of $\\mathcal{S}$.\n  \\item The map $h$ is an equivalence.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  First we observe that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      (X'\\to Y) \\arrow[rr,\"\\blank\\circ h\"]\n      \\arrow[dr,swap,\"{\\mathsf{cocone\\usc{}map}(i',j',H')}\"]\n      & & (X\\to Y) \\arrow[dl,\"{\\mathsf{cocone\\usc{}map}(i,j,H)}\"] \\\\\n      & \\mathsf{cocone}_{\\mathcal{S}}(Y) & \\phantom{(X'\\to Y)}\n    \\end{tikzcd}\n  \\end{equation*}\n  for any type $Y$. Therefore it follows from the 3-for-2 property of equivalences that if any two of the maps in this triangle is an equivalence, so is the third. Now the claim follows from the observation in \\cref{ex:equiv_precomp} that $h$ is an equivalence if and only if the map $\\blank\\circ h:(X'\\to Y)\\to (X\\to Y)$ is an equivalence for any type $Y$.\n\\end{proof}\n\nIn the following corollary we establish the fact that pushouts are \\emph{uniquely unique}.\n\n\\begin{cor}\n  Consider two pushouts\n  \\begin{equation*}\n    \\begin{tikzcd}\n      S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"]\n      & & S \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"{j'}\"] \\\\\n      A \\arrow[r,swap,\"i\"] & C\n      & & A \\arrow[r,swap,\"{i'}\"] & C'\n    \\end{tikzcd}\n  \\end{equation*}\n  of a given span $\\mathcal{S}\\jdeq (S,f,g)$. Then the type of equivalences $e:\\eqv{C}{C'}$ equipped with homotopies\n  \\begin{align*}\n    K & : h\\circ i \\htpy i' \\\\\n    L & : h\\circ j \\htpy j'\n  \\end{align*}\n  and a homotopy $M$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      h\\circ i\\circ f \\arrow[r,\"K\\cdot f\"] \\arrow[d,swap,\"h\\cdot H\"] & i' \\circ f \\arrow[d,\"{H'}\"] \\\\\n      h\\circ j\\circ g \\arrow[r,swap,\"L\\cdot g\"] & j'\\circ g\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, is contractible.\n\\end{cor}\n\n\\begin{proof}\n  This follows from combining \\cref{lem:unique-mapping-property-pushout,thm:3-for-2-pushout}.\n\\end{proof}\n\n\\subsection{Suspensions}\nA particularly important class of examples of pushouts are suspensions.\n\n\\begin{defn}\n  Let $X$ be a type. A \\define{suspension}\\index{suspension|textbf} of $X$ is a type $\\susp X$ equipped with a \\define{north pole} $\\mathsf{N}:\\susp X$, a \\define{south pole} $\\mathsf{S}:\\susp X$, and a \\define{meridian}\n  \\begin{equation*}\n    \\mathsf{merid} : X \\to (\\mathsf{N}=\\mathsf{S}),\n  \\end{equation*}\n  such that the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[r,\"\\mathsf{const}_\\ttt\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & \\unit \\arrow[d,\"{\\mathsf{const}_\\south}\"] \\\\\n      \\unit \\arrow[r,swap,\"\\mathsf{const}_\\north\"] & \\susp X\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pushout square.\n\\end{defn}\n\nWe can use suspensions to present the spheres in type theory. The $2$-sphere is a space which, like the surface of the earth, has a north pole and a south pole. Moreover, for each point of the equator there is a meridian that connects the north pole to the south pool. Of course, the equator is a circle, so we see that the $2$-sphere is just the suspension of the circle.\n\nSimilarly we can see that the $(n+1)$-sphere must be the suspension of the $n$-sphere. The $(n+1)$-sphere is the unit sphere in the vector space $\\mathbb{R}^{n+2}$. This vector space has an orthogonal basis $e_1,\\ldots,e_{n+2}$. Then the north and the south pole are given by $e_{n+2}$ and $-e_{n+2}$, respectively, and for each unit vector in $\\mathbb{R}^{n+1}\\subseteq\\mathbb{R}^{n+2}$ we have a meridian connecting the north pole with the south pole. The unit sphere in $\\mathbb{R}^{n+1}$ is of course the $n$-sphere, so we see that the $(n+1)$-sphere must be a suspension of the $n$-sphere.\n\nThese observations suggest that we can define the spheres by recursion on $n$. Note that the spheres in type theory are defined entirely synthetically, i.e., without reference to the ambient topological space $\\mathbb{R}^{n+1}$. Indeed, from a homotopical point of view each space $\\mathbb{R}^{n}$ is contractible, so in type theory it is just presented as the unit type\\footnote{It is an entirely different matter to define the \\emph{set} $\\mathbb{R}$ rather than the homotopy type of $\\mathbb{R}$. See Chapter 11 of \\cite{hottbook} for definitions of the Dedekind reals and the Cauchy reals.}.\n\n\\begin{defn}\nWe define the \\define{$n$-sphere}\\index{n-sphere@{$n$-sphere}|textbf} $\\sphere{n}$\\index{Sn@{$\\sphere{n}$}|textbf} for any $n:\\N$ by induction on $n$, by taking\n\\begin{align*}\n\\sphere{0} & \\defeq \\bool \\\\\n\\sphere{n+1} & \\defeq \\susp{\\sphere{n}}.\n\\end{align*}\n\\end{defn}\n\n\\begin{rmk}\n  Note that this recursive definition of the spheres only goes through in type theory if we have (or assume) a universe that is closed under suspensions.\n\\end{rmk}\n\nIn the following lemma we give a slight simplification of the universal property of suspensions, making it just a little easier to work with them.\n\n\\begin{lem}\nLet $X$ and $Y$ be types, and let $\\susp X$ be a suspension of $X$. Then the map\\index{universal property!of suspensions|textit}\n\\begin{equation*}\n(\\susp{X}\\to Y)\\to \\sm{y,y':Y} X\\to (y=y')\n\\end{equation*}\ngiven by $f\\mapsto (f(\\north),f(\\south),f\\cdot\\merid)$ is an equivalence.\n\\end{lem}\n\n\\begin{proof}\n  Note that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-1em]\n      \\phantom{\\sm{y,y':Y}X\\to (y=y')} & (\\susp X \\to Y) \\arrow[dl,swap,\"\\mathsf{cocone\\usc{}map}\"] \\arrow[dr,\"{f\\mapsto (f(\\north),f(\\south),f\\cdot\\merid)}\"] &\n      \\phantom{\\mathsf{cocone}_{\\mathcal{S}}(Y)} \\\\\n      \\mathsf{cocone}_{\\mathcal{S}}(Y) \\arrow[rr] & & \\sm{y,y':Y}X\\to (y=y')\n    \\end{tikzcd}\n  \\end{equation*}\n  where $\\mathcal{S}$ is the span $\\unit \\leftarrow X \\rightarrow \\unit$. The bottom map is given by $(i,j,H)\\mapsto (i(\\ttt),j(\\ttt),H)$. This map is an equivalence, and the map on the left is an equivalence by the assumption that $\\susp X$ is a suspension of $X$. Therefore the claim follows by the 3-for-2 property of equivalences.\n\\end{proof}\n\nA slightly slicker version of the universal property of suspensions can be obtained in the case where $X$ is a pointed type. Recall that a pointed type is a pair $(X,x_0)$ consisting of a type $X$ and a point $x_0:X$. The point $x_0:X$ is called the \\define{base point} of the pointed type. In the case of the suspension, we define the base point to be the north pole.\n\n\\begin{defn}\n  Given two pointed types $X$ and $Y$, a pointed map from $X$ to $Y$ is a pair $(f,p)$ consisting of a map $f:X\\to Y$ and a path $p:f(x_0)=y_0$ witnessing that $f$ preserves the base point. We write\n  \\begin{equation*}\n    X\\to_\\ast Y\n  \\end{equation*}\n  for the type of \\define{pointed maps} from $X$ to $Y$. The type $X\\to_\\ast Y$ is itself a pointed type, with base point $(\\mathsf{const}_{y_0},\\refl{y_0})$. \n\\end{defn}\n\nNow suppose that we have a pointed map $f:\\susp X\\to_\\ast Y$ with $p:f(x_0)=y_0$. Then we obtain a map $X\\to\\loopspace{Y}$ that maps $x:X$ to the concatenation\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=6em]\n    f(\\north) \\arrow[r,equals,\"\\ap{f}{\\merid(x)}\"] & f(\\south) \\arrow[r,equals,\"\\ap{f}{\\merid(x_0)}^{-1}\"] & f(\\north).\n  \\end{tikzcd}\n\\end{equation*}\nNote that the function $x\\mapsto\\ct{\\ap{f}{\\merid(x)}}{\\ap{f}{\\merid(x_0)}^{-1}}$ is a pointed map by the right inverse law of path concatenation. Therefore we obtain a map\n\\begin{equation*}\n  \\tau_{X,Y} :(\\susp X \\to_\\ast Y) \\to (X \\to_\\ast \\loopspace{Y}).\n\\end{equation*}\nIt is not hard to see that also $\\tau_{X,Y}$ is pointed. We leave this to the reader. The following theorem is also called the adjointness of the suspension and loop space functors. This is an extremely important relation that pops up in many calculations of homotopy groups.\n\n\\begin{thm}\n  Let $X$ and $Y$ be pointed types. Then the pointed map\n  \\begin{equation*}\n    \\tau_{X,Y} : (\\susp X \\to_\\ast Y) \\to_\\ast (X\\to_\\ast \\loopspace Y)\n  \\end{equation*}\n  is an equivalence. Moreover, $\\tau$ is pointedly natural in $X$ and $Y$. \n\\end{thm}\n\n\\subsection{The duality of pullbacks and pushouts}\n\\begin{lem}\\label{lem:cocone_pb}\nFor any span $\\mathcal{S}\\jdeq (S,f,g)$ from $A$ to $B$, and any type $X$ the square\\index{cocone_S(X)@{$\\mathsf{cocone}_{\\mathcal{S}}(X)$}!as a pullback|textit}\n\\begin{equation*}\n\\begin{tikzcd}\n\\mathsf{cocone}_{\\mathcal{S}}(X) \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & X^B \\arrow[d,\"\\blank\\circ g\"] \\\\\nX^A \\arrow[r,swap,\"\\blank\\circ f\"] & X^S,\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by the homotopy $\\pi_3' \\defeq\\lam{(i,j,H)} \\mathsf{eq\\usc{}htpy}(H)$, is a pullback square.\n\\end{lem}\n\n\\begin{proof}\nThe gap map $\\mathsf{cocone}_{\\mathcal{S}}(X)\\to X^A\\times_{X^S} X^B$ is the function \n\\begin{equation*}\n\\lam{(i,j,H)}(i,j,\\mathsf{eq\\usc{}htpy}(H)).\n\\end{equation*}\nThis is an equivalence by \\cref{thm:fib_equiv}, since it is the induced map on total spaces of the family of equivalences $\\mathsf{eq\\usc{}htpy}$. Therefore, the square is a pullback square by \\cref{thm:is_pullback}.\n\\end{proof}\n\nIn the following theorem we establish the duality between pullbacks and pushouts.\n\n\\begin{thm}\\label{thm:pushout_up}\nConsider a commuting square\\index{universal property!of pushouts|textit}\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\"] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & X,\n\\end{tikzcd}\n\\end{equation*}\nwith $H:i\\circ f\\htpy j\\circ g$. The following are equivalent:\n\\begin{enumerate}\n\\item The square is a pushout square.\n\\item The square\n\\begin{equation*}\n\\begin{tikzcd}\nT^X \\arrow[r,\"\\blank\\circ j\"] \\arrow[d,swap,\"\\blank\\circ i\"] & T^B \\arrow[d,\"\\blank\\circ g\"] \\\\\nT^A \\arrow[r,swap,\"\\blank\\circ f\"] & T^S\n\\end{tikzcd}\n\\end{equation*}\nwhich commutes by the homotopy\n\\begin{equation*}\n\\lam{h} \\mathsf{eq\\usc{}htpy}(h\\cdot H)\n\\end{equation*}\nis a pullback square, for every type $T$.\n%\\item The type $X$ satisfies \\define{span induction} for the span $A\\leftarrow S \\rightarrow B$, in the sense that for any type family $P$ over $X$, the map\n%\\begin{equation*}\n%\\Big(\\prd{x:X}P(x)\\Big)\\to \\Big(\\sm{i':\\prd{a:A}P(i(a))}{j':\\prd{b:B}P(j(b))} i'\\htpy_H j'\\Big)\n%\\end{equation*}\n%given by $s\\mapsto (s\\circ i,s\\circ j,s\\cdot H)$ has a section.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nIt is straightforward to verify that the triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=3em]\n& T^X \\arrow[dl,swap,\"{\\mathsf{cocone\\usc{}map}(i,j,H)}\"] \\arrow[dr,\"{\\mathsf{gap}(\\blank\\circ i,\\blank\\circ j, \\mathsf{eq\\usc{}htpy}(\\blank\\cdot H))}\"] \\\\\n\\mathsf{cocone}(T) \\arrow[rr,swap,\"{\\mathsf{gap}(i,j,\\mathsf{eq\\usc{}htpy}(H))}\"] & & T^A \\times_{T^S} T^B\n\\end{tikzcd}\n\\end{equation*}\ncommutes. Since the bottom map is an equivalence by \\cref{lem:cocone_pb}, it follows that if either one of the remaining maps is an equivalence, so is the other. The claim now follows by \\cref{thm:is_pullback}.\n\\end{proof}\n\n\\begin{eg}\\label{eg:circle_pushout}\nBy \\cref{ex:circle_up_pushout} and the second characterization of pushouts in \\cref{thm:pushout_up} it follows that the circle is a pushout\\index{circle!S1 equiv susp 2@{$\\eqv{\\sphere{1}}{\\susp\\bool}$}|textit}\n\\begin{equation*}\n\\begin{tikzcd}\n\\bool \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\n\\unit \\arrow[r] & \\sphere{1}.\n\\end{tikzcd}\n\\end{equation*}\nIn other words, $\\eqv{\\sphere{1}}{\\susp{\\bool}}$. \n\\end{eg}\n\n\\begin{thm}\\label{thm:pushout_pasting}\nConsider the following configuration of commuting squares:\\index{pushout!pasting property|textit}\\index{pasting property!for pushouts|textit}\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"i\"] \\arrow[d,swap,\"f\"] & B \\arrow[r,\"k\"] \\arrow[d,swap,\"g\"] & C \\arrow[d,\"h\"] \\\\\nX \\arrow[r,swap,\"j\"] & Y \\arrow[r,swap,\"l\"] & Z\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies $H:j\\circ f\\htpy g\\circ i$ and $K:l\\circ g\\htpy h\\circ k$, and suppose that the square on the left is a pushout square. \nThen the square on the right is a pushout square if and only if the outer rectangle is a pushout square.\n\\end{thm}\n\n\\begin{proof}\nLet $T$ be a type. Taking the exponent $T^{(\\blank)}$ of the entire diagram of the statement of the theorem, we obtain the following commuting diagram\n\\begin{equation*}\n\\begin{tikzcd}\nT^Z \\arrow[r,\"\\blank\\circ l\"] \\arrow[d,swap,\"\\blank\\circ h\"] & T^Y \\arrow[d,swap,\"\\blank\\circ g\"] \\arrow[r,\"\\blank\\circ j\"] & T^X \\arrow[d,\"\\blank\\circ f\"] \\\\\nT^C \\arrow[r,swap,\"\\blank\\circ k\"] & T^B \\arrow[r,swap,\"\\blank\\circ i\"] & T^A.\n\\end{tikzcd}\n\\end{equation*}\nBy the assumption that $Y$ is the pushout of $B\\leftarrow A \\rightarrow X$, it follows that the square on the right is a pullback square. It follows by \\cref{thm:pb_pasting} that the rectangle on the left is a pullback if and only if the outer rectangle is a pullback. Thus the statement follows by the second characterization in \\cref{thm:pushout_up}.\n\\end{proof}\n\n\\begin{lem}\nConsider a map $f:A\\to B$. Then the cofiber of the map $\\inr:B\\to \\mathsf{cofib}_f$ is equivalent to the suspension $\\susp{A}$ of $A$. \n\\end{lem}\n\n\\subsection{Fiber sequences and cofiber sequences}\n\n\\begin{defn}\nGiven a map $f:A\\to B$, we define the \\define{cofiber}\\index{cofiber|textbf} $\\mathsf{cofib}_f$\\index{cofib_f@{$\\mathsf{cofib}_f$}|textbf} of $f$ as the pushout\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"f\"] \\arrow[d] & B \\arrow[d,\"\\inr\"] \\\\\n\\unit \\arrow[r,swap,\"\\inl\"] & \\mathsf{cofib}_f. \n\\end{tikzcd}\n\\end{equation*}\nThe cofiber of a map is sometimes also called the \\define{mapping cone}\\index{mapping cone|textbf}.\n\\end{defn}\n\n\\begin{eg}\nThe suspension $\\susp X$ of $X$ is the cofiber of the map $X\\to \\unit$.\\index{suspension!as cofiber} \n\\end{eg}\n\n\\subsection{Further examples of pushouts}\n\n\\begin{defn}\nWe define the \\define{join}\\index{join} $\\join{X}{Y}$\\index{join X Y@{$\\join{X}{Y}$}|textbf} of $X$ and $Y$ to be the pushout \n\\begin{equation*}\n\\begin{tikzcd}\nX\\times Y \\arrow[r,\"\\proj 2\"] \\arrow[d,swap,\"\\proj 1\"] & Y \\arrow[d,\"\\inr\"] \\\\\nX \\arrow[r,swap,\"\\inl\"] & X \\ast Y. \n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nSuppose $A$ and $B$ are pointed types, with base points $a_0$ and $b_0$, respectively. The \\define{(binary) wedge}\\index{wedge@(binary) wedge|textbf} $A\\vee B$ of $A$ and $B$ is defined as the pushout\n\\begin{equation*}\n\\begin{tikzcd}\n\\bool \\arrow[r] \\arrow[d] & A+B \\arrow[d] \\\\\n\\unit \\arrow[r] & A\\vee B.\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nGiven a type $I$, and a family of pointed types $A$ over $i$, with base points $a_0(i)$. We define the \\define{(indexed) wedge}\\index{wedge@{(indexed) wedge}|textbf} $\\bigvee_{(i:I)}A_i$ as the pushout\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nI \\arrow[d] \\arrow[r,\"{\\lam{i}(i,a_0(i))}\"] & \\sm{i:I}A_i \\arrow[d] \\\\\n\\unit \\arrow[r] & \\bigvee_{(i:I)} A_i.\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nLet $X$ and $Y$ be types with base points $x_0$ and $y_0$, respectively.\nWe define the \\define{wedge} $X\\lor Y$ of $X$ and $Y$ to be the pushout\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n\\bool \\arrow[r,\"{\\ind{\\bool}(\\inl(x_0),\\inr(y_0))}\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & X+Y \\arrow[d,\"\\inr\"] \\\\\n\\unit \\arrow[r,swap,\"\\inl\"] & X\\lor Y\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nLet $X$ and $Y$ be types with base points $x_0$ and $y_0$, respectively.\nWe define a map\n\\begin{equation*}\n\\mathsf{wedge\\usc{}incl} : X \\lor Y \\to X\\times Y.\n\\end{equation*}\nas the unique map obtained from the commutative square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n\\bool \\arrow[r,\"{\\ind{\\bool}(\\inl(x_0),\\inr(y_0))}\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & X+Y \\arrow[d,\"{\\ind{X+Y}(\\lam{x}\\pairr{x,y_0},\\lam{y}\\pairr{x_0,y})}\"] \\\\\n\\unit \\arrow[r,swap,\"\\lam{t}\\pairr{x_0,y_0}\"] & X\\times Y.\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nWe define the \\define{smash product} $X\\wedge Y$ of $X$ and $Y$ to be the pushout\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nX\\lor Y \\arrow[r,\"\\mathsf{wedge\\usc{}incl}\"] \\arrow[d,swap,\"\\mathsf{const}_\\ttt\"] & X\\times Y \\arrow[d,\"\\inr\"] \\\\\n\\unit \\arrow[r,swap,\"\\inl\"] & X\\wedge Y.\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\n\\begin{exercises}\n\\item \\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\\item \\label{ex:pushout_equiv}Use \\cref{thm:pushout_up,cor:pb_equiv,ex:equiv_precomp} to show that for any commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r,\"g\"] \\arrow[d,swap,\"f\",\"{\\eqvsym}\"'] & B \\arrow[d,\"j\"] \\\\\nA \\arrow[r,swap,\"i\"] & C\n\\end{tikzcd}\n\\end{equation*} \nwhere $f$ is an equivalence, the square is a pushout square if and only if $j:B\\to C$ is an equivalence.\nUse this observation to conclude the following:\n\\begin{enumerate}\n\\item If $X$ is contractible, then $\\susp X$ is contractible.\n\\item The cofiber of any equivalence is contractible.\n\\item The cofiber of a point in $B$ (i.e., of a map of the type $\\unit\\to B$) is equivalent to $B$.\n\\item There is an equivalence $\\eqv{X}{\\join{\\emptyt}{X}}$.\n\\item If $X$ is contractible, then $\\join{X}{Y}$ is contractible. \n\\item If $A$ is contractible, then there is an equivalence $\\eqv{A\\vee B}{B}$ for any pointed type $B$.\n\\end{enumerate}\n\\item \\label{ex:join_propositions}Let $P$ and $Q$ be propositions.\n\\begin{subexenum}\n\\item Show that $\\join{P}{Q}$ satisfies the \\emph{universal property of disjunction}, i.e., that for any proposition $R$, the map\n\\begin{equation*}\n(\\join{P}{Q}\\to R)\\to (P\\to R)\\times (Q\\to R)\n\\end{equation*}\ngiven by $f\\mapsto (f\\circ \\inl,f\\circ \\inr)$, is an equivalence.\n\\item Use the proposition $R\\defeq\\iscontr(\\join{P}{Q})$ to show that $\\join{P}{Q}$ is again a proposition.\n\\end{subexenum}\n\\item Let $Q$ be a proposition, and let $A$ be a type. Show that the following are equivalent:\n\\begin{subexenum}\n\\item The map $(Q\\to A)\\to(\\emptyt\\to A)$ is an equivalence.\n\\item The type $A^Q$ is contractible.\n\\item There is a term of type $Q\\to\\iscontr(A)$.\n\\item The map $\\inr:A\\to \\join{Q}{A}$ is an equivalence.\n\\end{subexenum}\n\\item Let $P$ be a proposition. Show that $\\susp P$ is a set, with an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\inl(\\ttt)=\\inr(\\ttt)\\Big)}{P}.\n\\end{equation*}\n\\item Show that $\\eqv{A\\sqcup^{\\mathcal{S}} B}{B\\sqcup^{\\mathcal{S}^{\\mathsf{op}}} A}$, where $\\mathcal{S^{\\mathsf{op}}}\\defeq (S,g,f)$ is the \\define{opposite span} of $\\mathcal{S}$. \n\\item Use \\cref{ex:pb_pi} to show that if\n\\begin{equation*}\n\\begin{tikzcd}\nS \\arrow[r] \\arrow[d] & Y \\arrow[d] \\\\\nX \\arrow[r] & Z\n\\end{tikzcd}\n\\end{equation*}\nis a pushout square, then so is\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times S \\arrow[r] \\arrow[d] & A\\times Y \\arrow[d] \\\\\nA\\times X \\arrow[r] & A\\times Z\n\\end{tikzcd}\n\\end{equation*}\nfor any type $A$.\n\\item Use \\cref{ex:pb_prod} to show that if\n\\begin{equation*}\n\\begin{tikzcd}\nS_1 \\arrow[r] \\arrow[d] & Y_1 \\arrow[d] & S_2 \\arrow[r] \\arrow[d] & Y_2 \\arrow[d] \\\\\nX_1 \\arrow[r] & Z_1 & X_2 \\arrow[r] & Z_2\n\\end{tikzcd}\n\\end{equation*}\nare pushout squares, then so is\n\\begin{equation*}\n\\begin{tikzcd}\nS_1+S_2 \\arrow[r] \\arrow[d] & Y_1+ Y_2 \\arrow[d] \\\\\nX_1 +X_2 \\arrow[r] & Z_1+Z_2. \n\\end{tikzcd}\n\\end{equation*}\n\\item \n\\begin{subexenum}\n\\item Consider a span $(S,f,g)$ from $A$ to $B$. Use \\cref{ex:pb_diagonal} to show that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nS+S \\arrow[d,swap,\"{f+g}\"] \\arrow[r,\"{[\\idfunc,\\idfunc]}\"] & S \\arrow[d,\"{\\inr\\circ g}\"] \\\\\nA+B \\arrow[r,swap,\"{[\\inl,\\inr]}\"] & A\\sqcup^\\mathcal{S} B\n\\end{tikzcd}\n\\end{equation*}\nis again a pushout square.\n\\item Show that $\\eqv{\\susp X}{\\join{\\bool}{X}}$.\n\\end{subexenum}\n\\item 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 Construct a map $\\mathsf{cofib}_{(h,H)}: \\mathsf{cofib}_{g}\\to \\mathsf{cofib}_f$.\n\\item Use \\cref{ex:pb_fib} to show that $\\eqv{\\mathsf{cofib}_{\\mathsf{cofib}(h,H)}}{\\mathsf{cofib}_h}$.\n\\end{subexenum}\n\\item \\label{ex:sphere_null}Use \\cref{ex:circle_connected} to show that for $n\\geq 0$, $X$ is an $n$-type if and only if the map\n\\begin{equation*}\n\\lam{x}\\mathsf{const}_x : X \\to (\\sphere{n+1}\\to X)\n\\end{equation*}\nis an equivalence.\n\\item \n\\begin{subexenum}\n\\item Construct for every $f:X\\to Y$ a function\n\\begin{equation*}\n\\susp f : \\susp X\\to \\susp Y.\n\\end{equation*}\n\\item Show that if $f\\htpy g$, then $\\susp f \\htpy \\susp g$. \n\\item Show that $\\susp \\idfunc[X]\\htpy\\idfunc[\\susp X]$\n\\item Show that\n\\begin{equation*}\n\\susp(g\\circ f)\\htpy (\\susp g)\\circ (\\susp f).\n\\end{equation*}\nfor any $f:X\\to Y$ and $g:Y\\to Z$.\n\\end{subexenum}\n\\item Consider a commuting diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA_0 & B_0 \\arrow[l] \\arrow[r] & C_0 \\\\\nA_1 \\arrow[u] \\arrow[d] & B_1 \\arrow[u] \\arrow[r] \\arrow[d] \\arrow[l] & C_1 \\arrow[u] \\arrow[d] \\\\\nA_2 & B_2 \\arrow[l] \\arrow[r] & C_2\n\\end{tikzcd}\n\\end{equation*}\nwith homotopies filling the (small) squares. Use \\cref{ex:pb_3by3} to construct an equivalence\n\\begin{align*}\n& (A_0\\sqcup^{B_0} C_0) \\sqcup^{(A_1\\sqcup^{B_1} C_1)} (A_2 \\sqcup^{B_2} C_2) \\\\\n& \\qquad \\eqvsym (A_0 \\sqcup^{A_1} A_2) \\sqcup^{(B_0\\sqcup^{B_1} B_2)} (C_0\\sqcup^{C_1} C_2).\n\\end{align*}\nThis is known as the \\define{3-by-3 lemma}\\index{3-by-3 lemma!for pushouts} for pushouts.\n\\item \n\\begin{subexenum}\n\\item Let $I$ be a type, and let $A$ be a family over $I$. Construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\bigvee\\nolimits_{(i:I)}\\susp A_i\\Big)}{\\susp\\Big(\\bigvee\\nolimits_{(i:I)}A_i\\Big)}.\n\\end{equation*}\n\\item Show that for any type $X$ there is an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\bigvee\\nolimits_{(x:X)}\\bool\\Big)}{X+\\unit}.\n\\end{equation*}\n\\item Construct an equivalence\n\\begin{equation*}\n\\eqv{\\susp(\\mathsf{Fin}(n+1))}{\\bigvee\\nolimits_{(i:\\mathsf{Fin}(n))}\\sphere{1}}.\n\\end{equation*}\n\\end{subexenum}\n\\item Show that $\\eqv{\\join{\\mathsf{Fin}(n+1)}{\\mathsf{Fin}(m+1)}}{\\bigvee\\nolimits_{(i:\\mathsf{Fin}(n\\cdot m))}\\sphere{1}}$, for any $n,m:\\N$.\n\\item For any pointed set $X$, show that the squares\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\sphere{1} \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\n      \\bigvee_{(x:X)}\\sphere{1} \\arrow[r] & \\susp{X}\n    \\end{tikzcd}\n    \\qquad\\text{and}\\qquad\n    \\begin{tikzcd}\n      X\\times \\sphere{1} \\arrow[d] \\arrow[r] & \\unit \\arrow[d] \\\\\n      \\bigvee_{(x:X)}\\sphere{1} \\arrow[r] & \\susp{X}\n    \\end{tikzcd}\n  \\end{equation*}\n  are pushout squares.\n\\item Show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\sphere{1} \\arrow[r] \\arrow[d] & \\unit \\arrow[d] \\\\\n      \\sphere{1}\\times\\sphere{1} \\arrow[r] & \\sphere{2}\\vee\\sphere{1}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pushout square.\n\\item For any type $X$, show that the mapping cone of the fold map $X+X\\to X$ is the suspension of $X+\\unit$, i.e.~show that the following square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X+X \\arrow[d] \\arrow[r] & \\unit \\arrow[d] \\\\\n      X \\arrow[r] & \\susp{X+\\unit}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pushout square.\n\\end{exercises}\n", "meta": {"hexsha": "42cb79f05f15bf42f2c046ea5ca863b840429116", "size": 30322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/pushout.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/pushout.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/pushout.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": 47.0838509317, "max_line_length": 595, "alphanum_fraction": 0.6697117604, "num_tokens": 11182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6223777862035805}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{tikz}\n\\usepackage[all]{xy}\n\\usetikzlibrary{positioning,chains,fit,shapes,calc}\n\n\\begin{document}\n\n\\title{Homework 11}\n\\author{Josh Cai}\n\n\\maketitle\n\\section*{Section 8.1}\n\n\\noindent\\textbf{2a)} $a_n = n \\times a_{n-1}$, because there are $n$ places to insert the $a_n$th digit into the existing permutation.\n\n\\noindent\\textbf{2b)} $a_n = n \\times a_{n-1} = n \\times a_{n-1} \\times a_{n-2} =  n \\times a_{n-1} \\times a_{n-2} \\times . . . \\times 1 = n!$.\n\\\\\\\\\\noindent\\textbf{4)} The number of ways to pay a bill of $n$ pesos is $a_n = a_{n-1} + a_{n-2}+2a_{n-5}+2a_{n-10}+a_{n-20}+a_{n-50}+a_{n-100}$.\n\\\\\\\\\\noindent\\textbf{8a)} The number of bit strings of length $n$ with three consecutive zeros is $a_{n}=a_{n-1}+a_{n-2}+a_{n-3}+2^{n-3}$, since each ends in either 1 (number is $a_{n-1}$), 10 (number is $a_{n-2}$), 100 (number is $a_{n-3}$), or 000 (number is $2^{n-3}$).\n\n\\\\\\noindent\\textbf{8b)} $a_1 = a_2 = 0, a_3 = 1$\n\n\\\\\\noindent\\textbf{8c)} There are 47 different bit strings of length 7 with three consecutive zeros.\n\\\\\\\\\\noindent\\textbf{14a)} The number of ternary strings with two consecutive zeros is $a_n = 2a_{n-1}+2a_{n-2}+3^{n-2}$.\n\n\\\\\\noindent\\textbf{14b)} $a_1 = 0, a_2 = 1$\n\n\\\\\\noindent\\textbf{14c)} There are 281 different ternary strings of length 6 with two consecutive zeros.\n\\\\\\\\\\noindent\\textbf{30a)} \n\n\\\\\\noindent\\textbf{30b)} $C_2 = C_0C_1+C_1C_0 = 1+1 = 2$. $C_3 = C_0C_2+C_1C_1+C_2C_0 = 2+1+2 = 5$. $C_4 = C_0C_3+C_1C_2+C_2C_1+C_3C_0 = 5+2+2+5 = 14$.\n\n\\\\\\noindent\\textbf{30c)} $C_4 = \\frac{1}{n+1} \\binom{8}{4} = \\frac{1}{5} \\times \\frac{8!}{4!4!} = 14$.\n\n\\section*{Section 8.2}\n\\noindent\\textbf{2a)} Is a linear homogeneous recurrence relation with constant coefficients, degree 2.\n\n\\noindent\\textbf{2b)} Is not homogeneous. \n\n\\noindent\\textbf{2c)} Is not linear.\n\n\\noindent\\textbf{2d)} Is a linear homogeneous recurrence relation with constant coefficients, degree 3.\n\\\\\\\\\\noindent\\textbf{4b)} Is not homogeneous. \n\n\\noindent\\textbf{4d)} Is not linear.\n\n\\noindent\\textbf{4f)} Is a linear homogeneous recurrence relation with constant coefficients, degree 3.\n\\\\\\\\\\noindent\\textbf{6)} Recurrence relation is $a_n = 2a_{n-1}+a_{n-2}$. Characteristic equation is $r^2 -2r-1$.\n\n\n\n\n\\end{document}", "meta": {"hexsha": "7819cf1d52135d30d93549b40a70d3a8d1848077", "size": 2300, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discrete_math/hw11.tex", "max_stars_repo_name": "joshcai/math-hw", "max_stars_repo_head_hexsha": "f896f4d54aca2d6e8c7354f0dbd1c898f21e1f82", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "discrete_math/hw11.tex", "max_issues_repo_name": "joshcai/math-hw", "max_issues_repo_head_hexsha": "f896f4d54aca2d6e8c7354f0dbd1c898f21e1f82", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "discrete_math/hw11.tex", "max_forks_repo_name": "joshcai/math-hw", "max_forks_repo_head_hexsha": "f896f4d54aca2d6e8c7354f0dbd1c898f21e1f82", "max_forks_repo_licenses": ["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.5925925926, "max_line_length": 272, "alphanum_fraction": 0.6808695652, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6223777765276329}}
{"text": "\\subsection{KENN} \\label{kenn_architecture}\nAs anticipated in section~\\ref{nsi_approaches}, KENN is the Neuro-Symbolic Integration approach chosen for this study. It adopts a restricted FOL language with fuzzy semantics and injects the logical knowledge directly into the model structure by adding a special layer. This new layer acts to increase the satisfaction of the logical knowledge by modifying the final predictions of the neural network.\n\nIn this section we go deeper into the details of the framework of KENN by focusing on the most important aspects to better understand its role in this thesis.\n\n\\subsubsection{Language and semantics}\nWe can start by introducing more details about the logical language supported by KENN. This framework allows imposing constraints on predictions by providing a set of logical clauses that constitute our knowledge base. For the sake of brevity, we will refer to a logical knowledge base as KB. Each clause of the KB represents a logical formula generated from a subset of the FOL with the following restrictions:\n\\begin{itemize}\n    \\item \\textit{the only operators allowed are disjunction and negation}\n    \\item \\textit{parentheses are not allowed}\n    \\item \\textit{variables are assumed to be universally quantified}\n    \\item \\textit{only unary and binary predicates are allowed}\n    \\item \\textit{functions are not allowed}\n\\end{itemize}\nEven if we can use only the operators of negation and disjunction, it is possible to use logical equivalence to introduce some other operators into KENN's language. Considering classical logic for simplicity, two examples of logically equivalent formulas are:\n\\begin{itemize}\n    \\item  $ A \\to B = \\neg A \\vee B $\n    \\item  $ \\neg ( A \\wedge B) = \\neg A \\vee \\neg B $ (De Morgan's law)\n\\end{itemize}\nThe mapping between FOL and KENN's restricted language is quite trivial. If we consider the example of logical implication, we can schematize the translation as follows:\n\\begin{enumerate}\n    \\item Starting from the FOL formula:\n    \\begin{gather*}\n        \\forall X, A(X) \\to B(X)\n    \\end{gather*}\n    \\item Remove quantifier (universal assumption):\n    \\begin{gather*}\n        A(X) \\to B(X)\n    \\end{gather*}\n    \\item Remove variables\\footnote{we can remove variables because we are dealing only with unary predicates referred to the same variable}:\n    \\begin{gather*}\n        A \\to B\n    \\end{gather*}\n    \\item Use logical equivalence (when possible) to convert unsupported operators:\n    \\begin{gather*}\n        \\neg A \\vee B\n    \\end{gather*}\n\\end{enumerate}\nNow that we transformed the FOL formula into a clause supported by KENN, we have to convert it using the syntax required by the parser:\n\\begin{enumerate}\n    \\item Use ``n\" as negation symbol and ``,\" to represent disjunctions:\n    \\begin{gather*}\n        nA,B\n    \\end{gather*}\n    \\item Add a positive clause weight; use ``\\_\" in case you want to set it as learnable parameter:\n    \\begin{gather*}\n        0.5:nA,B\n    \\end{gather*}\n\\end{enumerate}\n\nThe semantics of KENN's logic is fuzzy. The authors propose the \\textit{Gödel’s t-conorm} as fuzzy operator to compute the truth degree of a formula. Given a clause $ c $ representing a disjunction of $ n $ literals, the value of the t-conorm is computed by:\n\\begin{equation*} \\label{eq:godel}\n    \\bot(c) = \\max\\limits_{i=1}^{n}(c_{i})\n\\end{equation*}\nAccording to the equation, we can remark that the satisfaction of a clause depends exclusively on the value of the highest literal appearing in it.\n\n\n\\subsubsection{Architecture}\nMoving on to KENN's architecture, we already saw in section \\ref{nsi_approaches} that it differs from most of its competitors that inject knowledge through the loss function. The idea behind this approach is to have an additional layer that is responsible for injecting knowledge. This layer is simply put on top of an arbitrary neural network and becomes an integral part of it, thus influencing both the learning process and the predictions at inference time according to the provided logical knowledge. The architecture of KENN is represented in Figure~\\ref{fig:kenn_architecture} at the maximum abstraction level.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\linewidth]{kenn_architecture.jpg}\n    \\caption{ Architecture of KENN - Features $ x $ are given in input to a neural network (NN), the predictions $ y $ are modified by the Knowledge Enhancer (KE) to satisfy a logical KB ($ \\kappa $), thus obtaining the final predictions $ y'$. (Source:~\\cite{kenn})}\n    \\label{fig:kenn_architecture}\n\\end{figure}\n\n\\paragraphn{Components}\nAs we can see from the Figure~\\ref{fig:kenn_architecture}, the main component of the architecture is the Knowledge Enhancer, which has a specific role and is composed of a set of subcomponents that cooperate:\n\\begin{itemize}\n    \\item \\textbf{Knowledge Enhancer (KE):} The KE is the layer responsible for injecting logical knowledge into the model. Given a logical KB $K$ composed of $n$ clauses, the KE contains $n$ independent \\textit{Clause Enhancers} that produce $n$ variations to modify $y$ accordingly to $K$. These variations, also called deltas, are aggregated by the KE to obtain the enhanced output $y'$.\n    \\item \\textbf{Clause Enhancer (CE):} The CE is the unit responsible for increasing the satisfaction of a clause by applying a \\textit{boost function}, which acts on the predictions of the labels related to the literals of the clause. Each CE is associated to a clause weight $w_c$ that regulates the influence of the clause during the enhancement process.\n    \\item \\textbf{T-conorm boost function (TBF):} The TBF is the function applied by each CE to increase the value of the Gödel t-conorm of its grounded clause. The TBF produces the deltas that will be aggregated by the KE to obtain the final predictions. Since the TBF is based on the Gödel t-conorm, which is non-differentiable, the authors propose the following soft differentiable approximation to compute the deltas:\n    \\begin{equation} \\label{eq:tbf}\n    \t\\delta _{w_{c}}(v)_{i} = w_{c} \\cdot softmax(v)_{i}\n    \\end{equation}\n    where $ w_{c} $ is the weight of the clause $ c $, $ v $ is the preactivation vector (i.e., the output of the base neural network) of the literals belonging to $c$, and $ i $ refers to the \\textit{i-th} literal of the clause.\n\\end{itemize}\n\n\\paragraphn{Clause Enhancer details}\nNow that the high-level architecture has been presented, we can go deeper into the details of the clause enhancement mechanism. Referring to Figure~\\ref{fig:clause_enhancer}, the functioning of a CE can be summarized with the following steps:\n\\begin{enumerate}\n    \\item Receive the preactivations $ z $ of all the grounded literals (i.e., the output $y$ of the base neural network).\n    \\item Apply a pre-elaboration step $ \\phi $ to filter the preactivations: keep only the preactivations of the literals belonging to the clause $ c $ and change the sign of the preactivations of negated literals.\n    \\item Apply the TBF (Equation \\ref{eq:tbf}) to the resulting preactivations to produce the deltas.\n    \\item Apply a post-elaboration step $ \\phi' $ to convert the TBF’s results into changes to be applied to the original preactivations $ z $: expand back the dimensionality by filling with 0s the positions of the previously filtered out preactivations, then change back the sign of the deltas of negated literals.\n\\end{enumerate}\nAn example of clause enhancement that may help to better comprehend the mechanism is shown in Figure~\\ref{fig:example_enhancement}. \n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.35\\linewidth]{clause_enhancer.jpg}\n    \\caption{Clause Enhancer for $ A \\vee \\neg B $. (Source:~\\cite{kenn})}\n    \\label{fig:clause_enhancer}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.75\\linewidth]{example_enhancement.png}\n    \\caption{Example of clause enhancement for $ A \\vee \\neg B $, with $w_{c}=2.0$}\n    \\label{fig:example_enhancement}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.5\\linewidth]{knowledge_enhancer.jpg}\n    \\caption{Knowledge Enhancer producing enhanced predictions. The deltas of each CE are summed to the preactivations of the base neural network. (Source:~\\cite{kenn})}\n    \\label{fig:knowledge_enhancer}\n\\end{figure}\n\n\\paragraphn{Aggregation step}\nOnce understood the enhancement mechanism for a single clause, it is necessary to explain how the outputs of each CE are combined. An illustration of this step is available in Figure~\\ref{fig:knowledge_enhancer}. As we can see, the KE aggregates the initial preactivations to the deltas coming from each CE. The aggregation consists of a simple sum and the resulting value is passed through an activation function to obtain the final predictions $y'$. The authors of KENN motivate the choice of the sum as it leads to faster learning and inference, thus resulting in higher scalability. However, this kind of aggregation may lead to the so-called \\textit{conflicts}.\n\nA conflict occurs when the same literal appears with different signs in two or more clauses, thus leading the CEs to produce for the same literal both positive and negative deltas. The natural consequence is that there could be side effects when performing the aggregation step since the benefits of a clause could be mitigated or completely overwhelmed by the effects of another clause. To better understand this particular situation, imagine having two clauses $ c_{1}: \\neg A \\vee B $ and $ c_{2}: \\neg B \\vee C \\vee D $, where $B$ is the literal involved in possible conflicts. Let us assume that starting from an arbitrary preactivation vector $ z $ the CEs generate $ \\delta (z_{c_{1}})_{B} = 0.7 $ and $ \\delta (z_{c_{2}})_{B} = -0.5 $. At this point, we can aggregate the deltas obtaining $\\delta _{B} = 0.7 - 0.5 = 0.2$. The result is that the final change on $ B $ will reflect the effect of the stronger grounded clause lowered by the effect of the weaker one. It is important to underline that the more literals involved in a clause, the less the probability to encounter relevant conflicts, since the same literal must be dominant in both clauses~\\cite{kenn}.\n\n\\paragraphn{Enhancement of a logical implication}\nAn important aspect to remark and keep in mind is that since the goal of KENN is to increase the Gödel t-conorm of a grounded clause, the action of a CE is always the following: \\textit{produce a positive boost to the preactivations of positive literals and a negative boost to the preactivations of negative literals}. In other words, the sign of a delta computed by the CE reflects the sign of the related literal of the clause. Thus, reminding that a logical implication must be expressed in KENN by using the logical equivalence $ A \\to B = \\neg A \\vee B $, the effect of a CE always results in a decrease of the preactivation of $A$ and an increase of the preactivation of $B$. This means that a violated grounded clause (i.e., $ 1 \\to 0 $) is always pushed by KENN towards its satisfiability (i.e., $ 1 \\to 1 $, $ 0 \\to 0 $, or $ 0 \\to 1 $).\n\nIf we consider again the example in Figure~\\ref{fig:example_enhancement}, which is based on the clause $A \\vee \\neg B $ that can be seen as $ B \\to A $, we can analyze how the knowledge enhancement of an implication would modify the initial predictions. Table~\\ref{tab:example_tbf_values} reports the values obtained at each step of the CE, plus the prediction on $A$ and $B$ before and after the enhancement. If we consider $ threshold = 0.5 $ to assign 1 and 0 to the grounded literals and we compare the columns $ \\sigma (z) $ and $ \\sigma (\\delta _{w_{c}}(z)+ z)$, we can observe that KENN changed $1 \\to 0$ into $1 \\to 1$.\n\n\\begin{table}[h]\n\\centering\n\\caption{Numeric example of the action of KENN for $ A \\vee \\neg B $}\n\\label{tab:example_tbf_values}\n\\begin{tabular}{c|c|c|c|c|c|c|c|}\n\\cline{2-8}\n                                 & $ z $ & $ \\sigma (z) $       & $ z_{c} $ & $ \\delta _{w_{c}}(z_{c}) $ & $ \\delta _{w_{c}}(z) $ & $ \\delta _{w_{c}}(z) + z $ & $ \\sigma (\\delta _{w_{c}}(z)+ z)$ \\\\ \\hline\n\\multicolumn{1}{|c|}{$ A $}      & -0.7  & 0.33 ($ \\approx 0 $) & -0.7      & 1.8                        & 1.8                    & 1.1                        & 0.75 ($ \\approx 1 $)              \\\\ \\hline\n\\multicolumn{1}{|c|}{$ B $}      & 2.9   & 0.95 ($ \\approx 1 $) & -         & -                          & -0.2                   & 2.7                        & 0.94 ($ \\approx 1 $)              \\\\ \\hline\n\\multicolumn{1}{|c|}{$ \\neg B $} & -     & -                    & -2.9      & 0.2                        & -                      & -                          & -                                 \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\n\n\\paragraphn{Considerations on the clause weight}\nIn the example above, KENN with its intervention changed the final predictions leading to a satisfied clause. This is not always the case, since the choice of a different clause weight could lead to another outcome. In Figure~\\ref{fig:sigmoid_example} we can see two examples that start from the same preactivations, but use different clause weights. The examples show in a graphical way the changes introduced by KENN to the initial prediction from the perspective of the sigmoid activation function. Considering that a classification threshold of 0.5 on post-sigmoid values is equivalent to using a 0 threshold directly on preactivations, we can see that the delta produced in Figure~\\ref{fig:sigmoid_example_w2} is not enough to push the prediction over the threshold. On the contrary, Figure~\\ref{fig:sigmoid_example_w1} shows that the prediction changes its sign thanks to a higher clause weight.\n\n\\begin{figure}[h]\n     \\centering\n     \\begin{subfigure}{0.47\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{figures/ex_enhancement_w2.JPG}\n          \\caption{$w=2$,  $\\delta_{Y} = 1.6$,  $Y'=-0.4$}\n         \\label{fig:sigmoid_example_w2}\n     \\end{subfigure}\n     \\hfill\n     \\begin{subfigure}{0.47\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{figures/ex_enhancement_w5.JPG}\n         \\caption{$w=5$,  $\\delta_{Y} = 4$,  $Y'=2$}\n         \\label{fig:sigmoid_example_w1}\n     \\end{subfigure}\n        \\caption{Example of enhancement given $Y = -2$ and $softmax_{Y} = 0.8$, from the perspective of the sigmoid activation function}\n        \\label{fig:sigmoid_example}\n\\end{figure}\n\n% \\begin{table}\n% \\centering\n% \\caption{Truth table of the clause $ A \\vee \\neg B $}\n% \\label{tab:example_tbf_tt}\n% \\begin{tabular}{c|c|c|c|}\n% \\cline{2-4}\n%                         & $ A $ & $ B $ & $ A \\vee \\neg B $ \\\\ \\hline\n% \\multicolumn{1}{|c|}{1} & 0     & 0     & 1                 \\\\ \\hline\n% \\multicolumn{1}{|c|}{2} & 0     & 1     & 0                 \\\\ \\hline\n% \\multicolumn{1}{|c|}{3} & 1     & 0     & 1                 \\\\ \\hline\n% \\multicolumn{1}{|c|}{4} & 1     & 1     & 1                 \\\\ \\hline\n% \\end{tabular}\n% \\end{table}\n\\paragraphn{Relational KENN}\nThe authors of KENN propose also an extended version of the framework to use logical knowledge in relational domains. In that version, it is possible to specify relations between examples in contexts like collective classification by using binary predicates. The architecture of the relational version is slightly different and requires more sophisticated steps to inject logical knowledge into the neural network. The details can be found in~\\cite{daniele2021neural} and will not be discussed here since this thesis focuses on the use of unary predicates.", "meta": {"hexsha": "af5aacaccc3a4b3df1d26917f5aab30ac0819608", "size": 15566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/kenn/kenn_architecture.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/kenn/kenn_architecture.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/kenn/kenn_architecture.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": 91.5647058824, "max_line_length": 1172, "alphanum_fraction": 0.7160477965, "num_tokens": 4018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6223777742453359}}
{"text": "% !TeX root = ../main.tex\n\n\\begin{survey}\n\\label{cha:survey}\n\n\\title{Title of the Survey}\n\\maketitle\n\n写出至少 5000 外文印刷字符的调研阅读报告或者书面翻译 1-2 篇(不少于 2 万外文印刷符)。\n\n\n\\tableofcontents\n\n\n\\section{Single-Objective Programming}\n\nIt is impossible to cover in a single chapter every concept of mathematical\nprogramming\\cite{tex}. This chapter introduces only the basic concepts and techniques of\nmathematical programming such that readers gain an understanding of them\nthroughout the book.~\\cite{abrahams99tex,salomon1995advanced}.\n\nThe general form of single-objective programming (SOP) is written\nas follows,\n\\begin{equation*} % 如果附录中的公式不想让它出现在公式索引中，那就请\n                             % 用 equation*\n\\left\\{\\begin{array}{l}\n\\max \\,\\,f(x)\\\\%[0.1 cm]\n\\mbox{subject to:} \\\\%[0.1 cm]\n\\qquad g_j(x)\\le 0,\\quad j=1,2,\\cdots,p\n\\end{array}\\right.\n\\end{equation*}\nwhich maximizes a real-valued function $f$ of\n$x=(x_1,x_2,\\cdots,x_n)$ subject to a set of constraints.\n\n\\newcommand\\Real{\\mathbf{R}}\n\\newtheorem{mpdef}{Definition}[chapter]\n\\begin{mpdef}\nIn SOP, we call $x$ a decision vector, and\n$x_1,x_2,\\cdots,x_n$ decision variables. The function\n$f$ is called the objective function. The set\n\\begin{equation*}\nS=\\left\\{x\\in\\Real^n\\bigm|g_j(x)\\le 0,\\,j=1,2,\\cdots,p\\right\\}\n\\end{equation*}\nis called the feasible set. An element $x$ in $S$ is called a\nfeasible solution.\n\\end{mpdef}\n\n\\newtheorem{mpdefop}[mpdef]{Definition}\n\\begin{mpdefop}\nA feasible solution $x^*$ is called the optimal\nsolution of SOP if and only if\n\\begin{equation}\nf(x^*)\\ge f(x)\n\\end{equation}\nfor any feasible solution $x$.\n\\end{mpdefop}\n\nOne of the outstanding contributions to mathematical programming was known as\nthe Kuhn-Tucker conditions~\\eqref{eq:ktc}. In order to introduce them, let us give\nsome definitions. An inequality constraint $g_j(x)\\le 0$ is said to be active at\na point $x^*$ if $g_j(x^*)=0$. A point $x^*$ satisfying $g_j(x^*)\\le 0$ is said\nto be regular if the gradient vectors $\\nabla g_j(x)$ of all active constraints\nare linearly independent.\n\nLet $x^*$ be a regular point of the constraints of SOP and assume that all the\nfunctions $f(x)$ and $g_j(x),j=1,2,\\cdots,p$ are differentiable. If $x^*$ is a\nlocal optimal solution, then there exist Lagrange multipliers\n$\\lambda_j,j=1,2,\\cdots,p$ such that the following Kuhn-Tucker conditions hold,\n\\begin{equation}\n\\label{eq:ktc}\n\\left\\{\\begin{array}{l}\n    \\nabla f(x^*)-\\sum\\limits_{j=1}^p\\lambda_j\\nabla g_j(x^*)=0\\\\%[0.3cm]\n    \\lambda_jg_j(x^*)=0,\\quad j=1,2,\\cdots,p\\\\%[0.2cm]\n    \\lambda_j\\ge 0,\\quad j=1,2,\\cdots,p.\n\\end{array}\\right.\n\\end{equation}\nIf all the functions $f(x)$ and $g_j(x),j=1,2,\\cdots,p$ are convex and\ndifferentiable, and the point $x^*$ satisfies the Kuhn-Tucker conditions\n\\eqref{eq:ktc}, then it has been proved that the point $x^*$ is a global optimal\nsolution of SOP.\n\n\\subsection{Linear Programming}\n\\label{sec:lp}\n\nIf the functions $f(x),g_j(x),j=1,2,\\cdots,p$ are all linear, then SOP is called\na \\emph{linear programming}.\n\nThe feasible set of linear is always convex. A point $x$ is called an extreme\npoint of convex set $S$ if $x\\in S$ and $x$ cannot be expressed as a convex\ncombination of two points in $S$. It has been shown that the optimal solution to\nlinear programming corresponds to an extreme point of its feasible set provided\nthat the feasible set $S$ is bounded. This fact is the basis of the \\emph{simplex\n  algorithm} which was developed by Dantzig as a very efficient method for\nsolving linear programming.\n\\begin{table}[ht]\n\\centering\n  \\centering\n  \\caption{This is an example for table}\n  \\label{tab:badtabular2}\n  \\begin{tabular}[c]{|m{1.5cm}|c|c|c|c|c|c|}\\hline\n    \\multicolumn{2}{|c|}{Network Topology} & \\# of nodes &\n    \\multicolumn{3}{c|}{\\# of clients} & Server \\\\\\hline\n    GT-ITM & Waxman Transit-Stub & 600 &\n    \\multirow{2}{2em}{2\\%}&\n    \\multirow{2}{2em}{10\\%}&\n    \\multirow{2}{2em}{50\\%}&\n    \\multirow{2}{1.2in}{Max. Connectivity}\\\\\\cline{1-3}\n    \\multicolumn{2}{|c|}{Inet-2.1} & 6000 & & & &\\\\\\hline\n    \\multirow{2}{1.5cm}{Xue} & Rui  & Ni &\\multicolumn{4}{c|}{\\multirow{2}*{\\thuthesis}}\\\\\\cline{2-3}\n    & \\multicolumn{2}{c|}{ABCDEF} &\\multicolumn{4}{c|}{} \\\\\\hline\n\\end{tabular}\n\\end{table}\n\nRoughly speaking, the simplex algorithm examines only the extreme points of the\nfeasible set, rather than all feasible points. At first, the simplex algorithm\nselects an extreme point as the initial point. The successive extreme point is\nselected so as to improve the objective function value. The procedure is\nrepeated until no improvement in objective function value can be made. The last\nextreme point is the optimal solution.\n\n\\subsection{Nonlinear Programming}\n\nIf at least one of the functions $f(x),g_j(x),j=1,2,\\cdots,p$ is nonlinear, then\nSOP is called a \\emph{nonlinear programming}.\n\nA large number of classical optimization methods have been developed to treat\nspecial-structural nonlinear programming based on the mathematical theory\nconcerned with analyzing the structure of problems.\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics{thu-lib-logo.pdf}\n  \\caption{This is an example for figure.}\n  \\label{tab:badfigure2}\n\\end{figure}\n\nNow we consider a nonlinear programming which is confronted solely with\nmaximizing a real-valued function with domain $\\Real^n$.  Whether derivatives are\navailable or not, the usual strategy is first to select a point in $\\Real^n$ which\nis thought to be the most likely place where the maximum exists. If there is no\ninformation available on which to base such a selection, a point is chosen at\nrandom. From this first point an attempt is made to construct a sequence of\npoints, each of which yields an improved objective function value over its\npredecessor. The next point to be added to the sequence is chosen by analyzing\nthe behavior of the function at the previous points. This construction continues\nuntil some termination criterion is met. Methods based upon this strategy are\ncalled \\emph{ascent methods}, which can be classified as \\emph{direct methods},\n\\emph{gradient methods}, and \\emph{Hessian methods} according to the information\nabout the behavior of objective function $f$. Direct methods require only that\nthe function can be evaluated at each point. Gradient methods require the\nevaluation of first derivatives of $f$. Hessian methods require the evaluation\nof second derivatives. In fact, there is no superior method for all\nproblems. The efficiency of a method is very much dependent upon the objective\nfunction.\n\n\\subsection{Integer Programming}\n\n\\emph{Integer programming} is a special mathematical programming in which all of\nthe variables are assumed to be only integer values. When there are not only\ninteger variables but also conventional continuous variables, we call it \\emph{\n  mixed integer programming}. If all the variables are assumed either 0 or 1,\nthen the problem is termed a \\emph{zero-one programming}. Although integer\nprogramming can be solved by an \\emph{exhaustive enumeration} theoretically, it\nis impractical to solve realistically sized integer programming problems. The\nmost successful algorithm so far found to solve integer programming is called\nthe \\emph{branch-and-bound enumeration} developed by Balas (1965) and Dakin\n(1965). The other technique to integer programming is the \\emph{cutting plane\n  method} developed by Gomory (1959).\n\n\\hfill\\textit{Uncertain Programming\\/}\\quad(\\textsl{BaoDing Liu, 2006.2})\n\n\\bibliographystyle{plainnat}\n\\bibliography{ref/refs,ref/appendix}\n\n\\end{survey}\n", "meta": {"hexsha": "f97039b45c1c50d6a864cade80ce34c8895eec6a", "size": 7483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "data/appendix-survey.tex", "max_stars_repo_name": "hanson-eye/thuthesis", "max_stars_repo_head_hexsha": "13ec4beee396f1db54057a90a3fd347022337d61", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-06T12:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-06T12:04:05.000Z", "max_issues_repo_path": "data/appendix-survey.tex", "max_issues_repo_name": "hanson-eye/thuthesis", "max_issues_repo_head_hexsha": "13ec4beee396f1db54057a90a3fd347022337d61", "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": "data/appendix-survey.tex", "max_forks_repo_name": "hanson-eye/thuthesis", "max_forks_repo_head_hexsha": "13ec4beee396f1db54057a90a3fd347022337d61", "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": 42.76, "max_line_length": 101, "alphanum_fraction": 0.7486302285, "num_tokens": 2228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6223777738114512}}
{"text": "\\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{color}\n\\newcommand{\\comm}{\\textcolor{red}}  % for making comments\n\\renewcommand{\\v}{\\mathbf}\n\\usepackage{amsfonts}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\setlength{\\parindent}{0.5in}\n\\title{How to Raytrace}\n\\begin{document}\n\\maketitle\n\n\\emph{Throughout the following, a color is an element of $[0,1]^3$, with\naddition and multiplication defined componentwise; if, after all other\ncalculations, a component of a color is greater than 1, it is set to 1.\nMoreover, $\\epsilon$ represents an arbitrarily small quantity, used to avoid\nimmediately hitting the current surface at the current point again.}\n\n\\vspace{2ex}\n\nGiven a ``camera'' at point $\\v{o}$ and a ``screen,'' for every point $\\v{s}$\non the screen, let $\\v{v} = (\\v{s}-\\v{o})/\\|\\v{s}-\\v{o}\\|$; the color of the\npixel at $\\v{s}$ is then found by finding the first object that the ray\n$\\v{o}+t\\v{v}$ ($t\\geq 0$) intersects:\n\n\\begin{itemize}\n\\item If it hits nothing, the color of the pixel is black.\n\\item If it hits a light, the color of the pixel is white.\n\\item If it hits a non-light object $Q$, let $\\v{p}$ be the point of intersection and $\\v{n}$ be the unit vector normal to the surface of $Q$ at $\\v{p}$.  The color of the pixel is $C = (0, 0, 0)$ with values added to it as follows:\n \\begin{itemize}\n \\item For every light source in the scene, let $\\v{\\ell}$ be its center and let $\\v{m}=(\\v{\\ell}-\\v{p})/\\|\\v{\\ell}-\\v{p}\\|$.  If the ray $(\\v{p}+\\epsilon\\v{m})+t\\v{m}$ intersects a non-light primitive before intersecting $\\ell$, skip the rest of this step for this light.  Otherwise:\n  \\begin{itemize}\n  \\item If $\\v{n}\\bullet\\v{m}$ and the diffusion of $Q$'s material are both positive, multiply their product by the product of the colors of $Q$ and the light source and add the result to $C$.\n  \\item If $\\v{v}\\bullet(\\v{m} - 2(\\v{m}\\bullet\\v{n})\\v{n})$ and the specularity of $Q$'s material are both positive, calculate the former to the power of 20\\comm{?} multiplied by the product of the latter and the color of the light source, and add the result to $C$.\n  \\end{itemize}\n \\item If the reflectiveness of $Q$'s material is greater than zero, let $\\v{r} = \\v{v} - 2(\\v{v}\\bullet\\v{n})\\v{n}$ (the reflection of $\\v{p}$ after hitting $Q$) and add to $C$ the color corresponding to the ray $(\\v{p}+\\epsilon\\v{r})+t\\v{r}$ multiplied by $Q$'s reflectiveness, multiplied by $Q$'s color.  (The depth of this recursion should be limited to some fixed value.)\n \\item If $Q$'s material permits refraction, let $i$ be the index of refraction of the medium in which $\\v{o}$ is located divided by the index of refraction on the other side of the surface of $Q$, let $c = \\v{v}\\bullet\\v{n}$, and let $s = i^2(1-c^2)$.  If $s$ is less than or equal to 1, let $\\v{t} = i(\\v{v} - (c+\\sqrt{1-s})\\v{n})$ (the refraction of $\\v{v}$ through the surface of $Q$) and add to $C$ the color corresponding to the ray $(\\v{p}+\\epsilon\\v{t})+t\\v{t}$.  (If $s>1$, then total internal reflection occurs, which \\comm{does not need to be handled???})\n \\end{itemize}\n\\end{itemize}\n\n\\section*{Formul\\ae{} for Intersections}\n\\begin{itemize}\n\n\\item Given a sphere of radius $r$ centered at $\\v{c}$, the values of $t$ for\nwhich a vector $\\v{o}+t\\v{v}$ intersects it are all of the solutions of\n$\\|\\v{v}\\|^2 t^2 + 2(\\v{v}\\bullet(\\v{o}-\\v{c})) t + \\|\\v{o}-\\v{c}\\|^2 = r^2$.\n\n\\item Given a plane with normal vector $\\v{n}$ and containing the point\n$d\\v{n}$ for some $d\\in\\R^\\geq$, the value of $t$ for which a (non-coplanar)\nvector $\\v{o}+t\\v{v}$ intersects it is $((d\\v{n}-\\v{o})\\bullet\\v{n}) /\n(\\v{v}\\bullet\\v{n})$.\n\n\\item Given an indexed set of points $\\{\\v{x}_i\\}_{i=0}^n$ forming a polygon\nsuch that each $\\v{x}_i$ is adjacent to both $\\v{x}_{(i-1)\\bmod(n+1)}$ and\n$\\v{x}_{(i+1)\\bmod(n+1)}$, the values of $t$ for which a vector $\\v{o}+t\\v{v}$\nintersects the interior (i.e., not the edges) of this polygon are all the $t$'s\nsuch that $\\v{p} = \\v{o}+t\\v{v}$ is in the plane containing the polygon and\nsuch that the values in $\\{((\\v{x}_{(i+1)\\bmod(n+1)} - \\v{x}_i)\\times(\\v{p} -\n\\v{x}_i))\\bullet\\v{n} : i\\in[0,n]\\cap\\Z\\}$ (where $\\v{n}$ is a vector normal to\nthe plane) are either all positive or all negative.  \\comm{Does this only work\nfor convex polygons?}\n\n\\end{itemize}\n\n\\end{document}\n\nTO ADD:\n - formulae for normals\n - formulae for cylindrical shells\n - descriptions of the relevant properties of materials (color, diffusion,\n   specularity, reflectiveness, index of refraction (in (0, \\infty)?), etc.)\n  - In Bikker's raytracer{1,2} (but not raytracer3), specularity was equal to 1\n    minus the diffusion; look into this.\n - Sources:\n  - <http://www.devmaster.net/articles/raytracing_series/part1.php>\n  - <http://www.devmaster.net/articles/raytracing_series/Reflections%20and%20Refractions%20in%20Raytracing.pdf>\n  - <http://www.itu.dk/courses/IM/Projects/Raytracer/RayNotes.pdf>\n\nAlternative algorithm for checking whether a given point p is inside a polygon:\nPick a point known to be outside the polygon and consider the line segment\nbetween it and p; p is then inside the polygon iff this line segment intersects\nan odd number of edges of the polygon.\n", "meta": {"hexsha": "7c39bb90054cd230c8fc269f0e1af9d160fc6b16", "size": 5188, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "raytrace.tex", "max_stars_repo_name": "jwodder/hsgraphics", "max_stars_repo_head_hexsha": "90eb4564f0fb08f876cb15487454f6c060475838", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "raytrace.tex", "max_issues_repo_name": "jwodder/hsgraphics", "max_issues_repo_head_hexsha": "90eb4564f0fb08f876cb15487454f6c060475838", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "raytrace.tex", "max_forks_repo_name": "jwodder/hsgraphics", "max_forks_repo_head_hexsha": "90eb4564f0fb08f876cb15487454f6c060475838", "max_forks_repo_licenses": ["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.7619047619, "max_line_length": 566, "alphanum_fraction": 0.6860061681, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6221478334802828}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Contractible types and contractible maps}\n\\sectionmark{Contractible types and maps}\n\nIn this lecture we introduce the notions of contractible types and maps. A contractible type is a type which has, up to identification, only one term. In other words, a contractible type is a type that comes equipped with a point, and an identification of this point with any point.\n\nWe may think of contractible types as singletons up to homotopy, and indeed we show that the unit type is an example of a contractible type. Moreover, we show that contractible types satisfy an induction principle that is very similar to the induction principle of the unit type, provided that we formulate the computation rule using the identity type rather than postulating a judgmental computation rule. Another example of a contractible type is the total space of the family of identifications with a fixed starting point.\n\nWe then introduce the notion of fiber of a map, which is the type theoretic analogue of the pre-image of a map, and we say that a map in contractible if all its fibers are contractible. Thus, a map is contractible if the pre-image at any point in the codomain is a singleton. This condition is of course analogous to the set theoretic notion of bijective map, which suggests that on the type theoretical side of things a map should be contractible if and only if it is an equivalence.\n\nThe forward direction of this claim is straightforward, and we prove this direction immediately in \\cref{thm:equiv_contr}. The converse direction can be done directly, but it is certainly more involved. Therefore we prepare the proof of the converse direction by first characterizing the identity type of a fiber of a map. Then we show that any equivalence $e$ can be given the structure of a invertible map with an additional coherence relating the homotopies\n\\begin{equation*}\n  e\\circ e^{-1}\\htpy \\idfunc,\\qquad\\text{and}\\qquad e^{-1}\\circ e\\htpy\\idfunc,\n\\end{equation*}\nand finally we use these observations in \\cref{thm:contr_equiv} to conclude that the fibers of any equivalence must be contractible.\n\n\\subsection{Contractible types}\n\n\\begin{defn}\n  We say that a type $A$ is \\define{contractible}\\index{contractible!type|textbf} if it comes equipped with a term of type\n  \\begin{equation*}\n    \\iscontr(A) \\defeq \\sm{c:A}\\prd{x:A}c=x.\n  \\end{equation*}\n  Given a term $(c,C):\\iscontr(A)$, we call $c:A$ the \\define{center of contraction}\\index{center of contraction|textbf} of $A$, and we call $C:\\prd{x:A}c=x$ the \\define{contraction}\\index{contraction} of $A$.\n\\end{defn}\n\n\\begin{rmk}\nSuppose $A$ is a contractible type with center of contraction $c$ and contraction $C$. Then the type of $C$ is (judgmentally) equal to the type\n\\begin{equation*}\n\\mathsf{const}_c\\htpy\\idfunc[A].\n\\end{equation*}\nIn other words, the contraction $C$ is a \\emph{homotopy} from the constant function to the identity function.\n\\end{rmk}\n\n\\begin{eg}\n  The unit type is easily seen to be contractible. For the center of contraction we take $\\ttt:\\unit$. Then we define a contraction $\\prd{x:\\unit}\\ttt=x$ by the induction principle of $\\unit$. Applying the induction principle, it suffices to construct a term of type $\\ttt = \\ttt$, for which we just take $\\refl{\\ttt}$.\n\\end{eg}\n\n\\begin{defn}\n  For any $a:A$ and any type family $B$ over $A$, we define\n  \\begin{equation*}\n    \\mathsf{ev\\usc{}pt} : \\Big(\\prd{x:A}B(x)\\Big)\\to B(a)\n  \\end{equation*}\n  to be the function $\\lam{f}f(a)$.\n\\end{defn}\n\n\\begin{defn}\n  Suppose $A$ comes equipped with a term $a:A$. Then we say that $A$ satisfies \\define{singleton induction}\\index{singleton induction|textbf} if for every type family $B$ over $A$, the map\n  \\begin{equation*}\n    \\mathsf{ev\\usc{}pt}:\\Big(\\prd{x:A}B(x)\\Big)\\to B(a)\n  \\end{equation*}\n  has a section. In other words, if $A$ satisfies singleton induction we have a function and a homotopy\n  \\begin{align*}\n    \\mathsf{sing\\usc{}ind}_{a} & : B(a)\\to \\prd{x:A}B(x) \\\\\n    \\mathsf{sing\\usc{}comp}_{a} & : \\mathsf{ev\\usc{}pt}\\circ \\mathsf{sing\\usc{}ind}_{a} \\htpy \\idfunc\n  \\end{align*}\n  for any type family $B$ over $A$.\n\\end{defn}\n\n\\begin{eg}\n  Note that the singleton induction principle is almost the same as the induction principle for the unit type, the difference being that the \"computation rule\" in the singleton induction for $A$ is stated using an \\emph{identification} rather than as a judgmental equality. The unit type\\index{unit type!contractibility} $\\unit$ comes equipped with a function\n  \\begin{equation*}\n    \\indunit:B(\\ttt)\\to \\prd{x:\\unit}B(x)\n  \\end{equation*}\n  for every type family $B$ over $\\unit$, satisfying the judgmental equality $\\indunit(b,\\ttt)\\jdeq b$ for every $b:B(\\ttt)$ by the computation rule. Thus we easily obtain the homotopy\n  \\begin{equation*}\n    \\lam{b}\\refl{b}:\\mathsf{ev\\usc{}pt}\\circ\\indunit \\htpy\\idfunc,\n  \\end{equation*}\n  and we conclude that the unit type satisfies singleton induction. \n\\end{eg}\n\n\\begin{thm}\\label{thm:contractible}\nLet $A$ be a type. The following are equivalent:\n\\begin{enumerate}\n\\item The type $A$ is contractible.\n\\item The type $A$ comes equipped with a term $a:A$, and satisfies singleton induction.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nSuppose $A$ is contractible with center of contraction $c$ and contraction $C$. \nFirst we observe that, without loss of generality, we may assume that $C$ comes equipped with an identification $p:C(c)=\\refl{c}$.\nTo see this, note that we can always define a new contraction $C'$ by\n\\begin{equation*}\nC'(x)\\defeq\\ct{C(c)^{-1}}{C(x)},\n\\end{equation*}\nwhich satisfies the requirement by the left inverse law, constructed in \\cref{defn:id_invlaw}.\n\nTo show that $A$ satisfies singleton induction let $B$ be a type family over $A$ equipped with $b:B(a)$. To define $\\mathsf{sing\\usc{}ind}_a(b):\\prd{x:A}B(x)$, let $x:A$. We have an identification $C(x):a=x$, and $b$ is in $B(a)$. Therefore we can transport $b$ along the path $C(x)$ to obtain\n\\begin{equation*}\n  \\mathsf{sing\\usc{}ind}_a(b)\\defeq \\mathsf{tr}_B(C(x),b):B(x).\n\\end{equation*}\nTo see that $\\mathsf{sing\\usc{}ind}(c)=b$ note that we have\n\\begin{equation*}\n\\begin{tikzcd}\n\\mathsf{tr}_B(C(c),b) \\arrow[r,equals,\"\\ap{\\lam{\\omega}\\mathsf{tr}_B(\\omega,b)}{p}\"] &[4em] \\mathsf{tr}_B(\\refl{c},b) \\arrow[r,equals,\"\\refl{b}\"] & b.\n\\end{tikzcd}\n\\end{equation*}\nThis completes the proof that $A$ satisfies singleton induction.\n\nFor the converse, suppose that $a:A$ and that $A$ satisfies singleton induction. Our goal is to show that $A$ is contractible. For the center of contraction we take the term $a:A$. By singleton induction applied to $B(x)\\defeq a=x$ we have the map \n\\begin{equation*}\n\\mathsf{sing\\usc{}ind}_{a} : a=a \\to \\prd{x:A}a=x.\n\\end{equation*}\nTherefore $\\mathsf{sing\\usc{}ind}_{A,a}(\\refl{a})$ is a contraction.\n\\end{proof}\n\n\\begin{thm}\\label{thm:total_path}\nFor any $a:A$, the type\n\\begin{equation*}\n\\sm{x:A}a=x\n\\end{equation*}\nis contractible.\\index{identity type!contractibility of total space|textit}\n\\end{thm}\n\n\\begin{proof}\n  We will prove the statement by showing that $\\sm{y:A}x=y$ satisfies singleton induction, and then use \\cref{thm:contractible} to conclude that $\\sm{x:A}a=x$ is contractible. We will use the term $(a,\\refl{a}):\\sm{x:A}a=x$ as the center of contraction.\n\n  Now let $P$ be a type family over $\\sm{x:A}a=x$. Note that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\prd{t:\\sm{x:A}a=x}P(t) \\arrow[dr,swap,\"\\mathsf{ev\\usc{}pt}\"] \\arrow[rr,\"\\mathsf{ev\\usc{}pair}\"] & & \\prd{x:A}{p:a=x}P(x,p) \\arrow[dl,\"\\mathsf{ev\\usc{}refl}\"] \\\\\n      \\phantom{\\prd{x:A}{p:a=x}P(x,p)} & P(a,\\refl{a})\n    \\end{tikzcd}\n  \\end{equation*}\n  where the maps $\\mathsf{ev\\usc{}pair}$ and $\\mathsf{ev\\usc{}refl}$ are defined as\n  \\begin{align*}\n    f & \\mapsto \\lam{x}{p}f(x,p) \\\\\n    g & \\mapsto g(a,\\refl{a}),\n  \\end{align*}\n  respectively. By the induction principle for $\\Sigma$-types it follows that $\\mathsf{ev\\usc{}pair}$ has a section, and by path induction it follows that $\\mathsf{ev\\usc{}refl}$ has a section. Therefore it follows from \\cref{ex:3_for_2} that the composite $\\mathsf{ev\\usc{}pt}$ has a section.\n\\end{proof}\n\n\\subsection{Contractible maps}\n\\begin{defn}\nLet $f:A\\to B$ be a function, and let $b:B$. The \\define{fiber}\\index{fiber|textbf}\\index{homotopy fiber|see {fiber}} of $f$ at $b$ is defined to be the type\n\\begin{equation*}\n\\fib{f}{b}\\defeq\\sm{a:A}f(a)=b.\n\\end{equation*}\n\\end{defn}\n\nIn other words, the fiber of $f$ at $b$ is the type of $a:A$ that get mapped by $f$ to $b$.\nOne may think of the fiber as a type theoretic version of the pre-image\\index{pre-image|see {fiber}} of a point.\n\nIt will be useful to have a characterization of the identity type of a fiber, so we will make such a characterization immediately.\n\n  \\begin{defn}\n    Let $f:A \\to B$ be a map, and let $(x,p),(x',p'):\\fib{f}{y}$ for some $y:B$.\n    Then we define\n    \\begin{equation*}\n      \\mathsf{Eq\\usc{}fib}_f((x,p),(x',p'))\\defeq \\sm{\\alpha:x=x'}p=\\ct{\\ap{f}{\\alpha}}{p'}\n    \\end{equation*}\n    The relation $\\mathsf{Eq\\usc{}fib}_f:\\fib{f}{y}\\to\\fib{f}{y}\\to\\UU$ is a reflexive relation, since we have\n    \\begin{equation*}\n      \\lam{(x,p)}(\\refl{x},\\refl{p}):\\prd{(x,p):\\fib{f}{y}}\\mathsf{Eq\\usc{}fib}_f((x,p),(x,p)).\n    \\end{equation*}\n  \\end{defn}\n\n  \\begin{lem}\n    Consider a map $f:A\\to B$ and let $y:B$. The canonical map\n    \\begin{equation*}\n      ((x,p)=(x',p'))\\to\\mathsf{Eq\\usc{}fib}_f((x,p),(x',p'))\n    \\end{equation*}\n    induced by the reflexivity of $\\mathsf{Eq\\usc{}fib}_f$ is an equivalence for any $(x,p),(x',p'):\\fib{f}{y}$.\n  \\end{lem}\n\n  \\begin{proof}\n    The converse map\n    \\begin{equation*}\n      \\mathsf{Eq\\usc{}fib}_f((x,p),(x',p'))\\to ((x,p)=(x',p'))\n    \\end{equation*}\n    is easily defined by $\\Sigma$-induction, and then path induction twice. The homotopies witnessing that this converse map is indeed a right inverse as well as a left inverse is similarly constructed by induction.\n  \\end{proof}\n\n  Now we arrive at the notion of contractible map.\n\n\\begin{defn}\nWe say that a function $f:A\\to B$ is \\define{contractible}\\index{contractible!map|textbf} if there is a term of type\n\\begin{equation*}\n\\iscontr(f)\\defeq\\prd{b:B}\\iscontr(\\fib{f}{b}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{thm}\\label{thm:equiv_contr}\nAny contractible map is an equivalence.\\index{contractible!map!is an equivalence|textit}\n\\end{thm}\n\n\\begin{proof}\nLet $f:A\\to B$ be a contractible map. Using the center of contraction of each $\\fib{f}{y}$, we obtain a term of type\n\\begin{align*}\n\\lam{y}\\pairr{g(y),G(y)}:\\prd{y:B}\\fib{f}{y}.\n\\end{align*}\nThus, we get map $g:B\\to A$, and a homotopy $G:\\prd{y:B} f(g(y))=y$. In other words, we get a section of $f$.\n\nIt remains to construct a retraction of $f$. Taking $g$ as our retraction, we have to show that $\\prd{x:A} g(f(x))=x$. Note that we get an identification $p:f(g(f(x)))=f(x)$ since $g$ is a section of $f$. It follows that $(g(f(x)),p):\\fib{f}{f(x)}$. Moreover, since $\\fib{f}{f(x)}$ is contractible we get an identification $q:\\pairr{g(f(x)),p}=\\pairr{x,\\refl{f(x)}}$. The base path $\\ap{\\proj 1}{q}$ of this identification is an identification of type $g(f(x))=x$, as desired.\n\\end{proof}\n\n\\subsection{Equivalences are contractible maps}\n\nIn \\cref{thm:contr_equiv} we will show the converse to \\cref{thm:equiv_contr}, i.i., we will show that any equivalence is a contractible map. We will do this in two steps.\n\nFirst we introduce a new notion of \\emph{coherently invertible map}, for which we can easily show that such maps have contractible fibers. Then we show that any equivalence is a coherently invertible map.\n\n  Recall that an invertible map is a map $f:A\\to B$ equipped with $g:B\\to A$ and homotopies\n  \\begin{equation*}\n    G : f\\circ g \\htpy \\idfunc\\qquad\\text{and}\\qquad H:g\\circ f\\htpy \\idfunc.\n  \\end{equation*}\n  Then we observe that both $G \\cdot f$ and $f \\cdot H$ are homotopies of the same type\n  \\begin{equation*}\n    f\\circ g\\circ f \\htpy f.\n  \\end{equation*}\n  A coherently invertible map is an invertible map for which there is a further homotopy $G \\cdot f\\htpy f\\cdot H$.\n\n  \\begin{defn}\n    Consider a map $f:A\\to B$. We say that $f$ is \\define{coherently invertible} if it comes equipped with\n    \\begin{align*}\n      g & : B \\to A \\\\\n      G & : f \\circ g \\htpy \\idfunc \\\\\n      H & : g \\circ f \\htpy \\idfunc \\\\\n      K & : G \\cdot f \\htpy f \\cdot H.\n    \\end{align*}\n    We will write $\\mathsf{is\\usc{}coh\\usc{}invertible}(f)$ for the type of quadruples $(g,G,H,K)$.\n  \\end{defn}\n\n  Although we will encounter the notion of coherently invertible map on some further occasions, the following lemma is our main motivation for considering it.\n\n  \\begin{lem}\\label{lem:contr-inv}\n    Any coherently invertible map has contractible fibers.\n  \\end{lem}\n\n  \\begin{proof}\n    Consider a map $f:A\\to B$ equipped with\n    \\begin{align*}\n      g & : B \\to A \\\\\n      G & : f \\circ g \\htpy \\idfunc \\\\\n      H & : g \\circ f \\htpy \\idfunc \\\\\n      K & : G \\cdot f \\htpy f \\cdot H,\n    \\end{align*}\n    and let $y:B$. Our goal is to show that $\\fib{f}{y}$ is contractible. For the center of contraction we take $(g(y),G(y))$. In order to construct a contraction, it suffices to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}{p:f(x)=y}\\mathsf{Eq\\usc{}fib}_f((g(y),G(y)),(x,p)).\n    \\end{equation*}\n    By path induction on $p:f(x)=y$ it suffices to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}\\mathsf{Eq\\usc{}fib}_f((g(f(x)),G(f(x))),(x,\\refl{f(x)})).\n    \\end{equation*}\n    By definition of $\\mathsf{Eq\\usc{}fib}_f$, we have to construct a term of type\n    \\begin{equation*}\n      \\prd{x:A}\\sm{\\alpha:g(f(x))=x}G(f(x))=\\ct{\\ap{f}{\\alpha}}{\\refl{f(x)}}.\n    \\end{equation*}\n    Such a term is constructed as $\\lam{x}(H(x),K'(x))$, where the homotopy $H:g\\circ f\\htpy \\idfunc$ is given by assumption, and the homotopy\n    \\begin{align*}\n      K' & : \\prd{x:A}G(f(x))=\\ct{\\ap{f}{H(x)}}{\\refl{f(x)}}\n    \\end{align*}\n    is defined as\n    \\begin{equation*}\n      K'\\defeq \\ct{K}{\\mathsf{htpy\\usc{}right\\usc{}unit}(f\\cdot H)^{-1}}.\\qedhere\n    \\end{equation*}\n  \\end{proof}\n\n  Our next goal is to show that for any map $f:A\\to B$ equipped with\n  \\begin{equation*}\n    g:B\\to A,\\qquad G:f\\circ g \\htpy \\idfunc,\\qquad\\text{and}\\qquad H:g\\circ f\\htpy \\idfunc,\n  \\end{equation*}\n  we can improve the homotopy $G$ to a new homotopy $G':f\\circ g\\htpy \\idfunc$ for which there is a further homotopy\n  \\begin{equation*}\n    f\\cdot H\\htpy G'\\cdot f.\n  \\end{equation*}\n  Note that this situation is analogous to the situation in the proof of \\cref{thm:contractible}, where we improved the contraction $C$ so that it satisfied $C(c)=\\refl{}$. The extra coherence $f\\cdot H\\htpy G'\\cdot f$ is then used in the proof that the fibers of an equivalence are contractible.\n\n\\begin{defn}\\label{defn:htpy_nat}\\index{homotopy!naturality|textbf}\nLet $f,g:A\\to B$ be functions, and consider $H:f\\htpy g$ and $p:x=y$ in $A$. We define identification\n\\begin{equation*}\n\\mathsf{htpy\\usc{}nat}(H,p) \\defeq  :\\ct{\\ap{f}{p}}{H(y)}=\\ct{H(x)}{\\ap{g}{p}}\n\\end{equation*}\nwitnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}\nf(x) \\arrow[r,equals,\"H(x)\"] \\arrow[d,equals,swap,\"\\ap{f}{p}\"] & g(x) \\arrow[d,equals,\"\\ap{g}{p}\"] \\\\\nf(y) \\arrow[r,equals,swap,\"H(y)\"] & g(y)\n\\end{tikzcd}\n\\end{equation*}\ncommutes. This square is also called the \\define{naturality square} of the homotopy $H$ at $p$.\n\\end{defn}\n\n\\begin{constr}\n  By path induction on $p$ it suffices to construct an identification\n  \\begin{equation*}\n    \\ct{\\ap{f}{\\refl{x}}}{H(x)}=\\ct{H(x)}{\\ap{g}{\\refl{x}}}\n  \\end{equation*}\n  since $\\ap{f}{\\refl{x}}\\jdeq \\refl{f(x)}$ and $\\ap{g}{\\refl{x}}\\jdeq\\refl{g(x)}$, and since $\\ct{\\refl{f(x)}}{H(x)}\\jdeq H(x)$, we see that the path $\\mathsf{right\\usc{}unit}(H(x))^{-1}$ is of the asserted type.\n\\end{constr}\n\n\\begin{defn}\\label{defn:retraction_swap}\nConsider $f:A\\to A$ and $H: f\\htpy \\idfunc[A]$. We construct an identification $H(f(x))=\\ap{f}{H(x)}$, for any $x:A$.\n\\end{defn}\n\n\\begin{constr}\nBy the naturality of homotopies with respect to identifications the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\nff(x) \\arrow[d,swap,equals,\"\\ap{f}{H(x)}\"] \\arrow[r,equals,\"H(f(x))\"] & f(x) \\arrow[d,equals,\"H(x)\"] \\\\\nf(x) \\arrow[r,swap,equals,\"H(x)\"] & x\n\\end{tikzcd}\n\\end{equation*}\ncommutes. This gives the desired identification $H(f(x))=\\ap{f}{H(x)}$.\n\\end{constr}\n\n\\begin{lem}\\label{lem:coherently-invertible}\n  Let $f:A\\to B$ be a map, and consider $(g,G,H):\\mathsf{has\\usc{}inverse}(f)$. Then there is a homotopy $G':f\\circ g\\htpy \\idfunc$ equipped with a further homotopy\n  \\begin{equation*}\n    K : G'\\cdot f \\htpy f\\cdot H.\n  \\end{equation*}\n  Thus we obtain a map $\\mathsf{has\\usc{}inverse}(f)\\to\\mathsf{is\\usc{}coh\\usc{}invertible}(f)$.\n\\end{lem}\n\n\\begin{proof}\n  For each $y:B$, we construct the identification $G'(y)$ as the concatenation\n  \\begin{equation*}\n    \\begin{tikzcd}\n      fg(y) \\arrow[r,equals,\"{G(fg(y))}^{-1}\"] &[2.5em] fgfg(y) \\arrow[r,equals,\"\\ap{f}{H(g(y))}\"] &[2.5em] fg(y) \\arrow[r,equals,\"G(y)\"] & y.\n\\end{tikzcd}\n  \\end{equation*}\n  In order to construct a homotopy $G'\\cdot f\\htpy f\\cdot H$, it suffices to show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      fgfgf(x) \\arrow[r,equals,\"{G(fgf(x))}\"] \\arrow[d,equals,swap,\"\\ap{f}{H(gf(x))}\"] & fgf(x) \\arrow[d,equals,\"\\ap{f}{H(x)}\"] \\\\\n      fgf(x) \\arrow[r,equals,swap,\"G(f(x))\"] & f(x)\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes for every $x:A$.\n  Recall from \\cref{defn:retraction_swap} that we have $H(gf(x))=\\ap{gf}{H(x)}$. Using this identification, we see that it suffices to show that the square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=8em]\n      fgfgf(x) \\arrow[r,equals,\"G(fgf(x))\"] \\arrow[d,equals,swap,\"\\ap{fgf}{H(x)}\"] & fgf(x) \\arrow[d,equals,\"\\ap{f}{H(x)}\"] \\\\\n      fgf(x) \\arrow[r,equals,swap,\"G(f(x))\"] & f(x)\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Now we observe that this is just a naturality square the homotopy $Gf:fgf\\htpy f$, which commutes by \\cref{defn:htpy_nat}.\n\\end{proof}\n\nNow we put the pieces together to conclude that any equivalence has contractible fibers.\n\n\\begin{thm}\\label{thm:contr_equiv}\nAny equivalence is a contractible map.\\index{equivalence!is a contractible map|textit}\n\\end{thm}\n\n\\begin{proof}\n  We have seen in \\cref{lem:contr-inv} that any coherently invertible map is a contractible map. Moreover, any equivalence has the structure of an invertible map by \\cref{thm:inv_equiv}, and any invertible map is coherently invertible by \\cref{lem:coherently-invertible}.\n\\end{proof}\n\n\\begin{cor}\\label{cor:contr_path}\nLet $A$ be a type, and let $a:A$. Then the type\n\\begin{equation*}\n\\sm{x:A}x=a\n\\end{equation*}\nis contractible.\n\\end{cor}\n\n\\begin{proof}\nBy \\cref{thm:id_equiv}, the identity function is an equivalence. Therefore, the fibers of the identity function are contractible by \\cref{thm:contr_equiv}. Note that $\\sm{x:A}x=a$ is exactly the fiber of $\\idfunc[A]$ at $a:A$.\n\\end{proof}\n\n\\begin{comment}\n\\begin{proof}\nWe have the term $(a,\\refl{a}):\\sm{x:A}a=x$, which we take for the center of contraction. To construct the contraction, we have to show that\n\\begin{equation*}\n\\prd{p:\\sm{x:A}a=x} (a,\\refl{a})=p.\n\\end{equation*}\nBy the induction principle for dependent pair types it suffices to construct a term of type\n\\begin{equation*}\n\\prd{x:A}{p:a=x} (a,\\refl{a})=(x,p)\n\\end{equation*}\nNote that we may proceed here by path induction on $p$. That is, it suffices to consider the case $p\\jdeq\\refl{a}$, and show that $(a,\\refl{a})=(a,\\refl{a})$. Here we choose $\\refl{(a,\\refl{a})}$.\n\\end{proof}\n\\end{comment}\n\n\\begin{exercises}\n\\item \\label{ex:prop_contr}Show that if $A$ is contractible, then for any $x,y:A$ the identity type $x=y$ is also contractible.\\index{contractible!type!identity types of}\n\\item \\label{ex:contr_retr}Suppose that $A$ is a retract of $B$. Show that\\index{contractible!type!retracts of}\n  \\begin{equation*}\n    \\iscontr(B)\\to\\iscontr(A).\n  \\end{equation*}\n\\item \\label{ex:contr_equiv}\n  \\begin{subexenum}\n  \\item Show that for any type $A$, the map $\\mathsf{const}_\\ttt : A\\to \\unit$ is an equivalence if and only if $A$ is contractible.\\index{contractible!type!equivalence with $\\unit$}\n  \\item Apply \\cref{ex:3_for_2} to show that for any map $f:A\\to B$, if any two of the three assertions\\index{contractible!type!three@{3-for-2}}\n    \\begin{enumerate}\n    \\item $A$ is contractible\n    \\item $B$ is contractible\n    \\item $f$ is an equivalence\n    \\end{enumerate}\n    hold, then so does the third.\n  \\end{subexenum}\n\\item Show that for any two types $A$ and $B$, the following are equivalent:\n  \\begin{enumerate}\n  \\item Both $A$ and $B$ are contractible.\n  \\item The type $A\\times B$ is contractible.\n  \\end{enumerate}\n\\item \\label{ex:contr_in_sigma} Let $C$ be a contractible type with center of contraction $c:C$. Furthermore, let $B$ be a type family over $C$. Show that the map $b\\mapsto\\pairr{c,b}:B(c)\\to\\sm{x:C}B(x)$ is an equivalence.\n\\item \\label{ex:proj_fiber}Let $B$ be a family of types over $A$, and consider the projection map \n  \\begin{equation*}\n    \\proj 1 : \\big(\\sm{x:A}B(x)\\big)\\to A.\n  \\end{equation*}\n  Show that for any $a:A$, the map\n  \\begin{equation*}\n    \\lam{((x,y),p)} \\mathsf{tr}_B(p,y) : \\fib{\\proj 1}{a} \\to B(a),\n  \\end{equation*}\n  is an equivalence. Conclude that $\\proj 1$ is an equivalence if and only if each $B(a)$ is contractible.\n\\item \\label{ex:fib_replacement}Construct for any map $f:A\\to B$ an equivalence $e:\\eqv{A}{\\sm{y:B}\\fib{f}{y}}$ and a homotopy $H:f\\htpy \\proj 1\\circ e$ witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0em]\n      A \\arrow[rr,\"e\"] \\arrow[dr,swap,\"f\"] & & \\sm{y:B}\\fib{f}{y} \\arrow[dl,\"\\proj 1\"] \\\\\n      \\phantom{\\sm{y:B}\\fib{f}{y}} & B\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. The projection $\\proj 1 : (\\sm{y:B}\\fib{f}{y})\\to B$ is sometimes also called the \\define{fibrant replacement}\\index{fibrant replacement} of $f$.\n\\end{exercises}\n", "meta": {"hexsha": "061103b81dbddce268a2219110ba5ed600529a34", "size": 22011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/contractible.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/contractible.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/contractible.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": 52.4071428571, "max_line_length": 526, "alphanum_fraction": 0.6843396484, "num_tokens": 7441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6221250845533373}}
{"text": "% !TEX root = index.tex\n\n\\section{The Topology behind the Algebra}\n\\epigraph{It is my experience that proofs involving matrices can be shortened by 50\\% if one throws the matrices out.}{E. Artin}\n\n Most problems in this section are (*) or harder and hence optional.\n\n\\begin{ques}\n  Show that for a space $X$ if some good cover has dimension $n$ then $\\check H^i(X) = 0$ for $i > n$.\n\\end{ques}\n\n\\begin{definition}\n  The {\\bf Euler characteristic} of a space $X$ is defined as\n  \\begin{align*}\n    \\chi(M) := \\sum \\limits_{i \\in \\Z} (-1)^i \\dim \\check H^i(X)  = \\dim \\check H^0(X) - \\dim \\check H^1(X) + \\dim \\check H^0(X) \\pm \\dots\n  \\end{align*}\n\\end{definition}\n\n\\begin{ques}\n  Let $M$ be a $g$ holed torus.\n  Triangulate $M$ and suppose there are $V$ number of vertices, $E$ number of edges, and $F$ number of faces in the triangulation. Find a good cover of $M$ using this triangulation and prove that\n  \\begin{align*}\n    \\chi(M) = V - E + F\n  \\end{align*} (Recall that we don't need to find the maps $d^i$ to find the Euler characteristic.)\n\\end{ques}\n\n\\begin{ques}\nLet $G$ be a connected graph. Let $T$ be a maximal tree in $G$ i.e. $T$ is a subgraph of $G$ which is a tree such that adding any edge of $G$ to it creates a cycle. Find a cover $\\U$ of $G$ containing $T$ as an element (i.e. $T \\in \\U$). Use this cover to find a topological interpretation of $\\dim \\check H^1(G)$.\n\\end{ques}\n\n\n% \\begin{ques}\n%   By gluing the sides of a square in funky ways we can create the Klein Bottle and the Real Projective Plane. Find their Cech cohomologies. (We can find open covers for torus, Klein bottle, and projective plane containing exactly 3 sets.)\n%   \\begin{figure}[H]\n%   \t\\centering\n%     \\begin{subfigure}[t]{0.3\\textwidth}\n%   \t\t\\centering\n%   \t\t\\includegraphics[height=2.5cm]{Torus}\n%       \\caption{Torus}\n%   \t\\end{subfigure}\n%     \\begin{subfigure}[t]{0.3\\textwidth}\n%   \t\t\\centering\n%   \t\t\\includegraphics[height=2.5cm]{KleinBottle}\n%       \\caption{Klein Bottle}\n%   \t\\end{subfigure}\n%   \t\\begin{subfigure}[t]{0.3\\textwidth}\n%   \t\t\\centering\n%   \t\t\\includegraphics[height=2.5cm]{ProjectivePlane}\n%       \\caption{Projective Plane}\n%   \t\\end{subfigure}\n%   \\end{figure}\n% \\end{ques}\n\n\nWe'll now find a topological interpretation for $\\check H^0$. Let $X$ be a connected space with a good cover $\\U = \\{ U_1, U_2, \\dots, U_n\\}$. Assume that all the non-empty $U_i$ and $U_{\\{i,j\\}}$ are connected (this is simplify to our arguments, the proof works without this simplification). We have\n\\begin{align*}\n  \\L^0 &= \\L(U_1) \\oplus \\L(U_2) \\oplus \\dots \\oplus \\L(U_n) \\\\\n  \\L^1 &= \\L(U_{\\{1,2\\}}) \\oplus \\L(U_{\\{1,3\\}}) \\oplus \\dots \\oplus \\L(U_{\\{n-1,n\\}})\n\\end{align*}\nand $\\check H^0(X)$ is the kernel of the restriction maps $d^0 : \\L^0 \\rightarrow \\L^1$. \\begin{center}\n  \\begin{tabular}{ l | c c  }\n        & $U_l$ & $\\cdots$ \\\\\\hline\n    $U_{\\{i,j\\}}$ &   0 \\mbox{ or } 1    &      \\\\\n    \\vdots &       &\n  \\end{tabular} $ = d^0$\n\\end{center}\n\n\\begin{ques} $ $\n  \\begin{enumerate}\n    \\item As $U_{\\{i,j\\}} = U_i \\cap U_j$, argue that every row of the matrix $d^0$ (in the canonical bases) has exactly 2 non-zero entries.\n    \\item Argue that because $X$ is connected every open set in the cover $U_i$ must intersect some other $U_j$. What does this imply for the matrix $d^0$?\n    \\item Show that\n    \\begin{align*}\n        \\ker d^0 = \\{ [0, 0, \\dots, 0]^T, [1, 1, \\dots, 1]^T\\}\n    \\end{align*}\n    and hence $\\dim \\check H^0(X) = 1$.\n    \\item Suppose $Y$ is another topological space.\n      Find the Cech cohomologies of $X \\sqcup Y$ (the disjoint union of $X$ and $Y$) in terms of  $X$ and $Y$. In particular, what is $\\check H^0(X \\sqcup Y)$?\n    \\item Find a topological interpretation of $\\dim \\check H^0(Z)$ for a general topological space $Z$ (not necessarily connected).\n  \\end{enumerate}\n\\end{ques}\n\n\\begin{ques} Find the Cech cohomologies of $X \\vee Y$ in terms of  $X$ and $Y$. (Assume we have appropriate good covers.)\n\\end{ques}\n\n\\newpage\nWe'll next prove that $\\R^n \\not \\cong \\R^m$ (non-homeomorphic) if $n \\not = m$. Let\n\\begin{align*}\n  S^n &= \\{ (x_0, x_1, \\dots, x_n) \\in \\R^{n+1}: x_0^2 + x_1^2 + \\dots + x_n^2 = 1 \\}\n\\end{align*}\n\\begin{ques} $ $\n  \\begin{enumerate}\n  \\item Let $X, Y$ be topological spaces such that $Y$ is contractible. If $\\U$ is a good cover for $X$, find a good cover for $X \\times Y$. Show that $\\check H^i(X) \\cong \\check H^i(X \\times Y)$ for all $i \\in \\Z$. In particular, this is true when $Y = (0,1)$.\n  \\item Show that $\\R^{n} \\setminus \\{ 0 \\} \\cong S^{n-1} \\times (0,1)$.\n  \\item Let $X, Y$ be topological spaces. Show that if $X \\cong Y$ then $\\check H^i(X) \\cong \\check H^i(Y)$.\n  \\item Conclude that if $\\R^n \\cong \\R^m$ then  $\\check H^i (S^{n-1}) \\cong \\check H^i (S^{m-1})$ for all $i \\in \\Z$.\n\\end{enumerate}\n\\end{ques}\n\\noindent Thus we've reduced the problem to a cohomology computation, which we can do by finding an appropriate good cover of $S^{n}$. Let \\begin{align*}\n  S^n_+ &= \\{ (x_0, x_1, \\dots, x_n) \\in \\R^{n+1}: x_n \\ge 0, x_0^2 + x_1^2 + \\dots + x_n^2 = 1 \\}\\\\\n  S^n_- &= \\{ (x_0, x_1, \\dots, x_n) \\in \\R^{n+1}:  x_n \\le 0, x_0^2 + x_1^2 + \\dots + x_n^2 = 1 \\}\n\\end{align*}\n\n\n\\begin{ques} $ $\n\\begin{enumerate}\n  \\item What is $S^0$?\n  \\item What are the dimensions of the Cech cohomologies of $S^0$, $S^1$, and $S^2$? Based on these make a guess as to what the dimensions of the Cech cohomologies of $S^n$ are.\n\\end{enumerate}\n\\end{ques}\n\\noindent We'll find the cohomologies of $S^n$ using induction.\nFor a non-empty subset $X \\subseteq S^{n-1}$ define the (positive) cone over $X$, denoted $C_+ X$, to be a subspace of $S^{n}_+$ defined as\n\\begin{align*}\n  C_+ X = \\{ (tx_0, tx_1, \\dots, tx_{n-1}, x_n) \\in S^{n}_+ : t \\in \\R_{\\ge 0}, (x_0, x_1, \\dots, x_{n-1}) \\in X \\}\n\\end{align*}\nDefine the cone over the empty set $C_+(\\phi)$ to be the single point $(0,\\dots,0,1)$.\n\n\\begin{ques} Let $X,Y \\subseteq S^{n-1}$.\n\\begin{enumerate}\n  \\item Let $X$ be some subset of $S^1$. Draw the cone $C_+X \\subseteq S^2$.\n  \\item Prove that $C_+ X$ is connected and contractible.\n  \\item Prove that $C_+X \\cap C_+ Y = C_+(X \\cap Y)$ (this is why we need $C_+ \\phi = (0,\\dots,0,1)$).\n  \\item Prove that $C_+X \\cap S^{n}_- \\cong X$.\n\\end{enumerate}\n\\end{ques}\n\\begin{ques} By induction, suppose $S^{n-1}$ has a good cover $\\U = \\{ U_1, \\dots, U_n\\}$ with $n$ elements. (Check the base case.)\n\\begin{enumerate}\n  \\item  Prove that $\\U' = \\{ C_+ U_1, C_+ U_2, \\dots, C_+ U_n, S^n_-\\}$ is a good cover of $S^n$ (this proves the induction step).\n  \\item What is the dimension of this cover? Conclude that $\\check H^{i}(S^n) = 0$ for $i > n$.\n\\end{enumerate}\n\\end{ques}\n\\noindent There are two types of intersections $\\U'_I$:\\\\\n$\\qquad$ (type I) ones obtained by intersecting the sets $\\{ C_+ U_1, C_+ U_2, \\dots, C_+ U_n\\}$  and \\\\$\\qquad$ (type II) ones obtained by intersecting $S^n_-$ with the some of the sets from $\\{ C_+ U_1, C_+ U_2, \\dots, C_+ U_n\\}$.\n\\begin{ques} $ $\n  \\begin{enumerate}\n  \\item Show that the intersections of type I are all contractible and the intersections of type II are the ones that show up in the Cech complex for $S^{n-1}$ and hence the Cech complex for $S^n$ contains a copy of the Cech complex of $S^{n-1}$ \\emph{right} shifted by one.\n  \\item Use this to inductively prove that for $n \\ge 1$\n  \\begin{align*}\n    \\check H^i(S^{n}) \\cong \\begin{cases}\n      \\F & \\mbox{ for } i=0,n \\\\\n      0 & \\mbox{ otherwise }\n  \\end{cases}\n  \\end{align*}\n  \\item Conclude that $S^n \\not \\cong S^m$ and $\\R^n \\not \\cong \\R^m$ if $n \\neq m$.\n\\end{enumerate}\n\\end{ques}\n", "meta": {"hexsha": "4438d144874898ec856374f61760dfe384a83824", "size": 7570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04.tex", "max_stars_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_stars_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_issues_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_forks_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_forks_repo_licenses": ["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.4965986395, "max_line_length": 314, "alphanum_fraction": 0.6336856011, "num_tokens": 2810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.622125078314894}}
{"text": "\\section{Introduction}\n\\subsection{Problem Description}\nThe main goal of the activity described in this report is the following: realizing a network implementing a \\textbf{perceptron} with a \\textbf{sigmoid activation function}.\\\\\nBefore describing the whole design and implementation process a very little introduction about the architecture must be done.\\\\\n\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{img/perceptron.png}\n\t\\caption{Perceptron Architecture}\n\\end{figure}\n\nA \\textbf{Perceptron} is a \\textit{binary classifier that maps his inputs to a specific output y = f(z), where f() is the \\textbf{activation function} of the perceptron.} The inputs are real numbers and the input z of the activation function is obtained as:\\\\\n\\begin{equation}\n\tz = b + \\sum_{i = 0}^{N_{L}-1}w_{i}x_{i}\n\\end{equation}\n\nEvery input $x_{i}$, every weight $w_{i}$ and the bias $b$ are real numbers in the range of $[-1, 1]$. $N_{L}$ represents the number of inputs $x_{i}$ of the perceptron.\\\\\nThe \\textbf{activation function}, in our case, will be a \\textbf{sigmoid function}, described as follows:\n\\begin{figure}[h]\n\t\\centering\n\t\\caption{Sigmoid Function Plot}\n\t\\includegraphics[width=8cm]{img/sigmoid.png}\n\\end{figure}\n\\begin{equation}\n\ty = \\dfrac{1}{1+e^{-z}}\n\\end{equation}\nWhere $z$ is the result of the equation (1.1).\n\\subsection{Applications}\nA single perceptron is the building block of \\textit{artificial neural networks}, in which different layers of perceptrons are connected. The output of the neural network is a real number and could be use to classify \\textit{complex objects}: patterns, human faces (Apple's FaceID), handwritings (Google Keyboard), medical diagnosis, e-mail spams (Gmail) and so on and so forth.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\caption{Neural network example}\n\t\\includegraphics[width=8cm]{img/neural_network.png}\n\\end{figure}\nIn the image above there is a simple schema of a neural network, in which the circles represent the perceptrons.\n\\subsection{Possible Architectures}\n\nThe main architecture will be made up by three main logical parts, from an higher-lever point of view:\n\\begin{itemize}\n\t\\item \\textbf{Multiplication Circuit}: implementation of the multiplication operation between each input $x_{i}$ and each weight $w_{i}$.\n\t\\item \\textbf{Adder Circuit}: implementation of the addition between the results of the former phase and the bias $b$.\n\t\\item \\textbf{Activation Function Circuit}: implementation of the computation of the sigmoid function.\n\\end{itemize}\n\nIn the next chapter the architecture will be documented with more precision.\nDifferent project choices could be made for each logical part of the architecture:\n\n\\begin{itemize}\n\t\\item{\\textbf{Multiplication Circuit}}: could be implemented through a \\textbf{ROM-based solution} in which every possible result is stored and the two inputs represent the addresses for getting the result. This solution is good only with \\textbf{a very low number of bits}, which is not our case: in fact the the ROM will be composed by $2^{(n_{w_{i}} + n_{b_{i}})}$ memory cells ($n_{w_{i}}$ represent the number of bits of $w_{i}$ and the same for $n_{b_{i}}$ and $b_{i}$). In order to implement the multiplication circuit will be implemented through a  \\textbf{Paraller Multiplier}, with some additional logic to handle the signed inputs.\n\t\\item{\\textbf{Adder Circuit}}: different choices could be made to implement the adder circuit. Some possible solutions, starting from the simplest to the more complex solution, that we can exploit are the \\textbf{Serial Adder}, the \\textbf{Parallel Adder} or the \\textbf{Parallel Adder with Pipeline }. The first one needs less logic but requires $n$ clock cycles for computing an $n$ bits result. The second solution improves the first one by computing one result in \\textbf{one clock cycle}, on the other hand it could add some problems due to long logic chains between two register. The third solution is the best from the perspective of the number of clock cycles required and the \\textbf{critical path}, in fact by adding some registers in between the computation of the bits will reduce the logic chains (and increasing the number of clock cycles though). \n\t\\item{\\textbf{Activation Function Circuit}}: As seen during the laboratory class, this part will be implemented by exploiting a \\textbf{Look-Up-Table}. In order to do so, could be necessary a \\textbf{truncation} of the result of the former computation in order to limit the size of the LUT. With $12$ bits are necessary $2^{12} = 4096$ entries, which could be even reduced by performing some optimization by exploiting the sigmoid function symmetry. For further details see next Chapter.\n\\end{itemize} \n", "meta": {"hexsha": "e01b38c33ef845bd54b602fe81f8e6c1cc367a81", "size": 4707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapters/introduction.tex", "max_stars_repo_name": "gerti98/Electronic-Systems-Project", "max_stars_repo_head_hexsha": "0691bbef06eb5a038c1324b3b8aa529d2346dbdc", "max_stars_repo_licenses": ["MIT"], "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/chapters/introduction.tex", "max_issues_repo_name": "gerti98/Electronic-Systems-Project", "max_issues_repo_head_hexsha": "0691bbef06eb5a038c1324b3b8aa529d2346dbdc", "max_issues_repo_licenses": ["MIT"], "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/chapters/introduction.tex", "max_forks_repo_name": "gerti98/Electronic-Systems-Project", "max_forks_repo_head_hexsha": "0691bbef06eb5a038c1324b3b8aa529d2346dbdc", "max_forks_repo_licenses": ["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.8113207547, "max_line_length": 863, "alphanum_fraction": 0.7733163374, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.622084178784621}}
{"text": "% \\chapauthor{J. P. Balthasar Mueller}\n\\chapter{Linear Regression}\n\\label{chap:linearregression}\n\n\\begin{multicols}{2}[\\subsubsection*{Contents of this chapter}]\n   \\printcontents{}{1}{\\setcounter{tocdepth}{2}}\n\\end{multicols}\n\nThere is no escaping from linear regression but hardly anyone seems to agree on how to do it properly. Even worse, people seem to expect you to know things like the normal equations, which you'll never, ever need outside of a job interview. \n\n\n\\section{Least Squares Regression ($L^2$)}\n\n\\subsection{The Normal Equations, Analytical Least Squares Estimator}\nSection \\ref{sec:linearequations} discussed the case of the linear system of equations:\n\n\\begin{equation}\n\\mathbf{A}\\mathbf{x} = \\mathbf{b}\n\\end{equation}\n\n\nWhen $\\mathbf{A}^{m\\times n}$ with $m>n$, so that the system is overdetermined. This is, of course, the starting point for least squares regression, only that the convention is to use different letters:\n\n\\begin{equation}\n\\mathbf{X}\\mathbf{\\beta} = \\mathbf{y}\n\\end{equation}\n\nAnd that, seeing that the system is overdetermined, one looks for an approximate solution $\\mathbf{\\hat{\\beta}}$, so that \n\n\\begin{equation}\n\\mathbf{X}\\mathbf{\\beta} + \\mathbf{\\epsilon} = \\mathbf{y}\n\\end{equation}\n\n\nA natural approach for picking an approximate solution $\\mathbf{\\hat{\\beta}}$ is to look for the projection of $\\mathbf{y}$ in the column space of $\\mathbf{X}$. That is, since the column rank $\\leq n$ of $\\mathbf{X}$ is insufficient to express $m$-dimensional $\\mathbf{y}$ exactly in terms of only $m$ coefficients $\\mathbf{\\beta}$, we look for the $n$-dimensional shadow $\\mathbf{\\hat{\\beta}}$ of some hypothetical higher dimensional exact solution. \n\nThe projection has the property that it maximizes the dot product $(\\mathbf{X}\\mathbf{\\hat{\\beta}})\\cdot \\mathbf{y}$, and hence minimizes the length of the difference vector $\\epsilon$. In turn, the length of the difference vector $\\epsilon$ is $\\sqrt{\\epsilon\\cdot\\epsilon}$, which is monotonic to $\\epsilon\\cdot\\epsilon = \\sum^m_i \\epsilon_i^2$. That means that finding the projection of $\\mathbf{y}$ in the column space of $\\mathbf{X}$ minimizes the  $L_2$ norm of $\\epsilon$, also known as \\textit{least squares error}.\n\nThere are two ways to go about finding $\\mathbf{\\hat{\\beta}}$.\n\n\\subsection{The Quick Way to $\\mathbf{\\hat{\\beta}}$}\n\nBy construction, the vector $\\epsilon$ is orthogonal to the column space of $\\mathbf{X}$. Which means:\n\n\\begin{equation}\n\\begin{array}{rl}\n\\mathbf{X}^T\\epsilon &= 0\\\\\n\\mathbf{X}^T\\left(\\mathbf{X}\\mathbf{\\hat{\\beta}}-\\mathbf{y}\\right) &= 0\\\\\n\\mathbf{X}^T\\mathbf{X}\\mathbf{\\hat{\\beta}} &= \\mathbf{X}^T\\mathbf{y}\\\\\n\\mathbf{\\hat{\\beta}} &= \\left(\\mathbf{X}^T\\mathbf{X}\\right)^{-1}\\mathbf{X}^T\\mathbf{y}\n\\end{array}\n\\end{equation}\n\nMaking use of the fact that $\\mathbf{X}^T\\mathbf{X}$ is square and therefore hopefully invertible.\n\n\\subsection{The Long Way to $\\mathbf{\\hat{\\beta}}$}\n\nLoss functions play a central role in computational statistics (for example when regularization is introduced), and therefore it is of interest to approach finding $\\mathbf{\\hat{\\beta}}$ by instead minimizing the least square error. This requires:\n\n\\begin{equation}\n\\frac{d}{d\\mathbf{\\hat{\\beta}}}L_2(\\epsilon) = 0\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n\\begin{array}{rl}\nL_2(\\epsilon) &= \\left(\\mathbf{X}\\mathbf{\\hat{\\beta}}-\\mathbf{y}\\right)^T\\left(\\mathbf{X}\\mathbf{\\hat{\\beta}}-\\mathbf{y}\\right)\\\\\n&= \\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{X}\\mathbf{\\hat{\\beta}} - \\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{y} - \\mathbf{y}^T\\mathbf{X}\\mathbf{\\hat{\\beta}} + \\mathbf{y}^T\\mathbf{y}\n\\end{array}\n\\end{equation}\n\nTaking derivatives with respect to a vector is covered in section \\ref{sec:derivatives}.\n\nIt follows:\n\n\\begin{equation}\n\\begin{array}{l}\n\\frac{d}{d\\mathbf{\\hat{\\beta}}}\\left(x^T\\mathbf{X}^T\\underbrace{\\mathbf{X}\\mathbf{\\hat{\\beta}}}_{u(\\mathbf{\\hat{\\beta}})}\\right) = \\frac{d}{du}\\left(u^Tu\\right)\\frac{d}{d\\mathbf{\\hat{\\beta}}}u = 2u^T\\frac{d}{d\\mathbf{\\hat{\\beta}}}u = 2\\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{X}\\\\\n\\\\\n\\frac{d}{d\\mathbf{\\hat{\\beta}}}\\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{y} = \\mathbf{y}^T\\mathbf{X}\\\\\n\\\\\n\\frac{d}{d\\mathbf{\\hat{\\beta}}}\\mathbf{y}^T\\mathbf{X}\\mathbf{\\hat{\\beta}} = \\mathbf{y}^T\\mathbf{X}\\\\\n\\\\\n\\frac{d}{d\\mathbf{\\hat{\\beta}}}\\mathbf{y}^T\\mathbf{y} = 0\n\\end{array}\n\\end{equation}\n\nSo that\t\n\n\\begin{equation}\n\\begin{array}{rl}\n\\frac{d}{dx}L_2(\\epsilon) = 0 &= 2\\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{X} - 2\\mathbf{y}^T\\mathbf{X}\\\\\n\\mathbf{\\hat{\\beta}}^T\\mathbf{X}^T\\mathbf{X} &= \\mathbf{y}^T\\mathbf{X}\\\\\n\\mathbf{X}^T\\mathbf{X}\\mathbf{\\hat{\\beta}} &= \\mathbf{X}^T\\mathbf{y}\\\\\n\\mathbf{\\hat{\\beta}} &= \\left(\\mathbf{X}^T\\mathbf{X}\\right)^{-1}\\mathbf{X}^T\\mathbf{y}\n\\end{array}\n\\end{equation}\n\n\n\n\\subsection{Projection Matrix}\n\nIf $\\mathbf{\\hat{y}}=\\mathbf{X}\\mathbf{\\hat{\\beta}}$ is the projection of $\\mathbf{y}$ in the column space of $\\mathbf{X}$, then, based on the result for $\\hat{\\beta}$, the projection matrix is $\\mathbf{P} = \\mathbf{X}\\left(\\mathbf{X}^T\\mathbf{X}\\right)^{-1}\\mathbf{X}^T$. In a fully determined system, $\\mathbf{P}=\\mathbf{I}$. Projection matrices have eigenvalues that are either $1$ or $0$, corresponding to dimensions that are kept or discarded during the projection operation.\n\n\n\\subsection{Bayesian Perspective on Least Squares Regression}\n\n\n\n\n\\subsection{Q-plots}\n\\subsection{Variance Inflation Factor}\n\n\\section{Total Least Squares}\nWhile least squares regression only allows for errors in the dependent variable, total least squares regression allows for measurement errors on both variables.\n\n\\section{Ridge Regression (Tikhonov Regularization, $\\lambda ||\\mathbf{\\beta}||^2$)}\nRidge Regression ads the $L^1$ norm of the weight vector to \n\n\\subsection{Analytical Ridge Estimator}\n\\subsection{Bayesian Perspective on Ridge Regression}\n\n\\section{Least Absolute Shrinkage and Selection Operator Regression (LASSO)}\n\n\n\\section{Least Absolute Deviation Regression (LAD, $L^1$)}\n\n\n\\section{Generalized Linear Models}\n\n\\input{./chapters/sections/reg_countregressions.tex}\n\n\\input{./chapters/sections/reg_logisticregression.tex}\n\n\n\n\n\\chapauthor{}\n\n", "meta": {"hexsha": "a2009fc3f0a86cdeed937cbdbaf97ab0708c3f0b", "size": 6138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/linearregression.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/linearregression.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/linearregression.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": 43.5319148936, "max_line_length": 523, "alphanum_fraction": 0.7137504073, "num_tokens": 2025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.6218885627295196}}
{"text": "\\chapter{Computation}\n\n\\section{Unary algebra}\n\n\\index{unary algebra}%\nA \\emph{unary algebra} is \\((S,f)\\) where \\(f : S \\to S\\).\n\nThe natural graph of a unary algebra \\((V,f)\\) is \\((V,E)\\)\nwhere \\((a,b) \\in E\\) iff \\(f(a) = b\\).\n\n\\section{String}\n\n\\index{language}%\nA \\emph{language} is a set of strings.\n\nTwo\n\\index{string}%\n\\emph{strings}\n\\(x\\) and \\(y\\) can be\n\\index{string concatenation}%\n\\index{concatenation!string}%\n\\emph{concatenated} to \\(xy\\).\n\nTwo languages \\(A\\) and \\(B\\) can be\n\\index{language concatenation}%\n\\index{concatenation!of languages}%\n\\emph{concatenated} to\n\\(AB = \\{ ab ~|~ a \\in A, ~ b \\in B \\}\\).\n\nThe\n\\index{empty string}%\n\\index{string!empty}%\n\\emph{empty string} \\(\\emptystr\\) satisfies \\(\\emptystr a = a \\emptystr = a\\).\n\n\\index{alphabet}%\nAn \\emph{alphabet} is a finite set where each element is a string of length one.\n\n\\paragraph{Power}\nLet \\(A\\) be a language and \\(n\\) be a natural number.\nDefine \\(A^{n+1} = A A^n\\).\nCorollary: \\(A^0 = \\{\\emptystr\\}\\).\n\n\\paragraph{Kleene closure}\nLet \\(A\\) be a language.\nThe\n\\index{Kleene closure}%\n\\index{Kleene operator}%\n\\index{Kleene star}%\n\\emph{Kleene closure}\nof \\(A\\) is \\(A^* = A^0 \\cup AA^*\\).\nAnother nonrecursive definition is\n\\( A^* = \\bigcup_{n \\in \\Nat} A^n \\).\n\n\\(A^*\\) is the smallest superset of \\(A\\)\nclosed under string concatenation.\n\nA\n\\index{formal system}%\n\\emph{formal system} \\(F\\) is a relation \\(F \\subseteq A^* \\times A^*\\)\nmade from finitely many rules where each rule has the form \\(L \\vdash R\\)\nwhere \\(A\\) is the alphabet.\nWhat limits the form of \\(L\\) and \\(R\\)?\n\nA\n\\index{problem}%\n\\emph{problem} \\(P\\) is a relation \\(P \\subseteq A^* \\times A^*\\) where \\(A\\) is the alphabet.\nAn \\emph{instance} of the problem is an element of the problem's relation.\n\nA\n\\index{problem!decision}%\n\\index{decision problem}%\n\\emph{decision problem} is isomorphic to a language\ncontaining the strings representing the yes-instances.\n\n\\(F\\)-unspecifiable problem:\nProof by diagonalization?\n\n\\section{Machine as formal system}\n\n\\paragraph{Example}\nLet \\(M\\) be the language.\nSyntax:\nLiterals are \\(\\{\\emptystr, 1\\}\\).\nEmpty string \\(\\emptystr \\in M\\).\n\\(1 \\in M\\).\n\\(A \\in M, B \\in M \\vdash AB \\in M\\).\nSemantics: \\(S(\\emptystr) = 0\\) and \\(S(1A) = 1 + S(A)\\).\nThe syntax of that formal system can also be described using turnstiles:\n\\begin{align*}\n    &\\vdash \\emptystr\n    \\\\\n    &\\vdash 1\n    \\\\\n    A,B &\\vdash AB\n\\end{align*}\n\nThe expression \\(\\vdash_M A\\) means that \\(A \\in M\\).\nThe expression \\(A \\vdash_M B\\) means that if \\(A \\in M\\), then \\(B \\in M\\).\nIf \\(M\\) is clear from context, we write \\(\\vdash\\) instead of \\(\\vdash_M\\).\n\n\\paragraph{Example}\nSyntax:\nLiterals are \\(\\{z,s,p\\}\\):\n\\begin{align*}\n    &\\vdash z\n    \\\\\n    A &\\vdash s(A)\n    \\\\\n    A,B &\\vdash p(A,B)\n\\end{align*}\nSemantics/interpretation \\(I : M \\to \\Nat\\):\n\\begin{align*}\n    I(z) &= 0\n    \\\\\n    I(s(A)) &= 1 + I(A)\n    \\\\\n    I(p(A,B)) &= I(A) + I(B)\n\\end{align*}\n\nA state \\(A\\) is \\emph{terminal} iff \\(A \\vdash\\).\n\n\\section{Computability with respect to primitives}\n\nLet the \\emph{primitive set} \\(P\\) be a finite set of relations.\nThe set of all \\emph{\\(P\\)-computable} functions is \\(P^*\\).\nA relation \\(f\\) is \\(P\\)-computable iff it is equal to\na constant finite composition of relations in \\(P^*\\).\n\n\\paragraph{Deterministic}\nIff every primitive is a function,\nthen the system is \\emph{deterministic}.\nIff every primitive is a relation,\nthen the system is \\emph{nondeterministic}.\nEvery function is a relation,\nso every deterministic system is also a nondeterministic system,\nbut not the other way around.\n\n\\paragraph{Example}\nLet \\(P = \\{S\\}\\) where \\(S(n) = n+1\\).\nThen \\(g(n) = n + 3\\) is \\(P\\)-computable because \\(g(n) = S(S(S(n)))\\).\nFor every constant \\(k\\), the addition-by-constant function \\(h_k(n) = n+k\\) is \\(P\\)-computable because \\(h_k = S^k\\).\nHowever, \\(n \\to 2n\\) is not \\(P\\)-computable\nbecause there is no \\(k\\) such that \\(S^k(n) = 2n\\) for all \\(n\\).\n\n\\paragraph{Example}\nLet \\(P = \\{f,l\\}\\) where \\(f(a,b) = (a+b,b)\\) and \\(l(a,b) = a\\).\nThen \\(g(x,y) = x+y\\) is \\(P\\)-computable because \\(g(x,y) = l(f(x,y))\\).\n\n\\paragraph{Example}\nLet \\(P = \\{S,r\\}\\) where \\(S(n)=n+1\\), \\(r(0,x) = x\\), and \\(r(S(n),x) = r(n,f(x))\\).\nThen \\(g(x,y) = x+y\\) is \\(P\\)-computable because \\(g(x,y) = r(x,y)\\).\n\nLemma:\nIf \\(r(0,x) = x\\) and \\(r(n+1,x) = f(r(n,x))\\) then \\(r(n+1,x) = r(n,f(x))\\).\n\nLemma:\nIf \\(r(0,x) = x\\) and \\(r(n+1,x) = r(n,f(x))\\) then \\(r(n+1,x) = f(r(n,x))\\).\n\n\\section{Complexity}\n\nThe \\(P\\)-complexity of a \\(P\\)-computable relation \\(f\\)\nis the number of \\(P\\)-relations used to make \\(f\\).\n\n\\section{Circuit size}\n\nThe circuit-size complexity of a zeroth-order logic formula:\n\\begin{align*}\n    C(a) &= 1 \\text{ if \\(a\\) is an axiom}\n    \\\\\n    C(\\neg p) &= 1 + C(p)\n    \\\\\n    C(p \\wedge q) &= 1 + C(p) + C(q)\n    \\\\\n    C(p \\vee q) &= 1 + C(p) + C(q)\n\\end{align*}\n\nThe circuit-depth complexity of a zeroth-order logic formula:\n\\begin{align*}\n    D(a) &= 1 \\text{ if \\(a\\) is an axiom}\n    \\\\\n    D(\\neg p) &= 1 + D(p)\n    \\\\\n    D(p \\wedge q) &= 1 + \\max(D(p),D(q))\n    \\\\\n    D(p \\vee q) &= 1 + \\max(D(p),D(q))\n\\end{align*}\n\nWhat prevents us from ``cheating'' by encoding the input as the solution?\n\n\\section{Primitive recursive functions}\n\n\\section{Program}\n\nLet \\(AB = \\{ ab ~|~ a \\in A, ~ b \\in B \\}\\)\nwhere \\(ab\\) is string concatenation.\n\nLet the \\emph{instruction set} \\(I\\) be a finite set of atoms.\n\nThe set of all \\(I\\)-programs is \\(I^*\\).\n\nA program is a finite element of \\(I^*\\).\n\nLet the \\emph{execution function} \\(f : I^* \\to P^*\\)\nwhere\n\\(f(\\emptystr) = id\\),\n\\(f(ab) = f(b) \\circ f(a)\\),\nand that \\(x \\in I\\) implies \\(f(x) \\in P\\).\nThe set of all \\emph{\\(I\\)-describable} functions are \\(\\{ f(x) ~|~ x \\in I^* \\}\\).\n\n\\section{Fixed point}\n\nIff \\(x = f(x)\\) then \\(x\\) is a \\emph{fixed point} of \\(f\\).\n\nLet \\(F\\) be a set of some functions.\nLet \\(G(F)\\) be the set of all functions that can be made by combining the functions in \\(F\\).\n\nA recursive equation has the form \\(f(x) = g(f,x)\\).\nFor example, iff \\(x^2 = x^4 + 1\\) and \\(f(x) = x^2\\), then \\(g(f,x) = x^4 + 1 = [f(x)]^2 + 1 = f(x^2) + 1 = x^4 + f(1)\\)\nand many more.\n\nThe \\(y\\)-combinator satisfies \\(y(f) = f(y(f))\\).\n\n\\section{Machine}\n\nA \\emph{machine} is \\((S,f)\\)\nwhere \\(S\\) is the \\emph{state set},\nand \\(f \\subseteq S \\times S\\) is the \\emph{transition relation}.\nIff \\(f\\) is a function, then the machine is \\emph{deterministic}.\n\\(I = \\{ a ~|~ a \\in S, ~ (a,b) \\not\\in f \\}\\) is the \\emph{initial state set}.\n\n\\paragraph{Graph}\nSuch machine is also a \\emph{graph} \\((V,E)\\) where \\(V=S\\), \\(E = f\\),\nand \\(I\\) is the set of all \\emph{source} vertices.\nA source vertex is a vertex with zero indegree.\nA sink vertex is a vertex with zero outdegree.\n\nThe \\emph{time complexity} of an instance is the path length from its initial state to its terminal state.\n\n\\(G\\) \\emph{accepts} \\(v\\) iff \\(F^\\infty(\\{v\\}) = \\emptyset\\) where \\(F\\) is the graph's fringe function.\nThe \\emph{language} recognized by \\(G\\) is the largest \\(L \\subseteq V\\) such that \\(F^\\infty(L) = \\emptyset\\).\n\nA Turing machine is \\((C,I,f)\\)\nwhere \\(C\\) is countable\nand \\(f\\) is recursive.\n\nExample: a state of a Turing machine is \\((c,l,h,r)\\)\nwhere \\(c\\) is a configuration,\n\\(l\\) is the tape content to the left of the head,\n\\(h\\) is the tape content at the head,\nand \\(r\\) is the tape content to the right of the head.\n\n\\section{Primitive by distance}\n\nIff \\(d\\) is a distance function and \\(S\\) is the state type,\nthen \\(f\\) is \\emph{\\(d\\)-primitive} iff \\(\\forall x \\in S : d(x,f(x)) \\le 1\\).\n\nLet \\(P\\) be a set of some \\(d\\)-primitive functions.\nLet \\(P^*\\) be the set of all finite compositions of the functions in \\(P\\).\n\n\\paragraph{Example}\nLet \\(S\\) be the set of all infinite \\(\\Nat\\)-indexed \\(E\\)-arrays.\nLet \\(x,y \\in S\\).\nThe \\emph{Hamming distance between \\(x\\) and \\(y\\)} is\n\\(d(x,y) = \\sum_{k\\in\\Nat} [x_k \\neq y_k]\\).\nThe function \\(f(x_0,x_1,\\ldots) = f(0,x_1,\\ldots)\\) is \\(d\\)-primitive,\nwhich in English means that this \\(f\\) does not change more than one element.\n\n\\section{Example stack machine primitive}\n\nLet \\(S = \\Nat^\\infty\\).\nExample:\nInfinite-stack machine:\n\\begin{align*}\n    swap(a,b,c,\\ldots) = (b,a,c,\\ldots)\n    \\\\\n    dup(a,b,\\ldots) = (a,a,b,\\ldots)\n    \\\\\n    push(a,b,\\ldots) = (0,a,b,\\ldots)\n    \\\\\n    pop(a,b,c,\\ldots) = (b,c,\\ldots)\n    \\\\\n    read(k,x_0,x_1,\\ldots) = (x_k,x_0,x_1,\\ldots)\n    \\\\\n    write(k,v,x_0,x_1,\\ldots) = (k,v,x_0,x_1,\\ldots,x_{k-1},v,x_{k+1},\\ldots)\n    \\\\\n    if(0,f,t,a,\\ldots) = (f,a,\\ldots)\n    \\\\\n    if(1,f,t,a,\\ldots) = (t,a,\\ldots)\n    \\\\\n    inc(a,b,\\ldots) = (a+1,b,\\ldots)\n    \\\\\n    dec(a,b,\\ldots) = (a-1,b,\\ldots)\n    \\\\\n    add(a,b,c,\\ldots) = (a+b,c,\\ldots)\n\\end{align*}\n\n\\section{Machine (old)}\n\nA machine that can only change one cell at a time.\nA machine is\n\\((P, f)\\)\nwhere \\(P = (S,A^\\infty)\\)\nand\n\\(d(x,f(x)) \\le 1\\)\nfor all \\(x : P\\).\nThe state set \\(S\\) is finite.\nThe alphabet \\(A\\) is finite.\nDefine the distance between two phases as\n\\begin{align}\n    d~(s,x)~(t,y) = \\sum_{k : \\Nat} ~ [x_k \\neq y_k].\n\\end{align}\nIt ignores the state.\nIt only cares about the memory.\n\nBut unlike Turing machines, this machine cannot approach an infinite number of 1s...\n\nThe machine is free to change its state as long as it only changes at most one cell at a time.\nIf we remove the restriction, we get a nondeterministic machine,\nor even an oracle.\n\nIf \\(S\\) has exactly \\(n\\) elements,\nwe can encode \\(f : S \\to A\\) as \\(g : A^n\\)\nwhere \\(f~s_k = g_k\\) where \\(g = (f~s_1, \\ldots, f~s_n)\\).\n\n\\section{Machine (older)}\n\nThe transition function depends on the set of primitive operations of the machine.\nSeen the other way around, this transition function\ndetermines the set of primitive operations of the machine.\n\nA machine is an embodiment of an algorithm.\n\nA machine performs computation by repeatedly\nmaking a transition from its current configuration\naccording to its transition function\nuntil it reaches a terminal configuration.\n\nA \\emph{primitive operation} maps a configuration to a configuration.\nEvery primitive operation represents a computation that the machine can do in one unit time.\nAn \\emph{architecture} is a set of primitive operations\nand a set of rules for evaluating expressions built using those primitive operations.\nA \\emph{machine} is an architecture and a configuration representing its current state.\n\n\\section{Finite automaton}\n\n\\emph{Automata} is the plural of automaton.\n\n% https://en.wikipedia.org/wiki/Automata_theory#Formal_definition\n\nA\n\\index{finite automaton}%\n\\emph{finite automaton} is \\(M = (Q,A,T,i,F)\\) where\n\\(A\\) is the alphabet,\n\\(T \\subseteq Q \\times A \\times Q\\) is the transition relation,\n\\(i \\in Q\\) is the initial state,\nand \\(F \\subseteq Q\\) is the set of accepting states.\nAnother name of finite automaton is\n\\index{state machine}%\n\\emph{state machine}.\n\nA finite automaton is a formal system.\n\n\\paragraph{Example}\nLet \\(Q = \\{q_0,q_1\\}, A = \\{0,1\\}, i = q_0, F = \\{q_1\\}\\), and:\n\\begin{align*}\n    &\\vdash T(q,0,q)\n    \\\\\n    &\\vdash T(q,1,q_1)\n\\end{align*}\nThen \\(M\\) recognizes \\(\\{ x ~|~ x \\in \\{0,1\\}^*, x \\text{ contains 1}\\}\\).\n\n\\paragraph{Final-state relation}\nThe \\emph{final-state relation} of \\(M\\) is \\(Z \\subseteq A^* \\times Q\\) where:\n\\begin{align*}\n    &\\vdash Z(\\emptystr,i)\n    \\\\\n    Z(p,a), T(a,c,b) &\\vdash Z(pc,b)\n\\end{align*}\nThe \\emph{final states} of \\(M\\) for input \\(w\\) is \\(Y(w) = \\{ q ~|~ Z(w,q) \\}\\).\n\n\\(M\\) \\emph{accepts} \\(w\\) iff \\(F \\subseteq Y(w)\\).\n\nThe \\emph{language recognized by \\(M\\)} is \\(\\{ w ~|~ F \\subseteq Y(w) \\}\\).\n\nThere is a bijection between finite automata and their final-state relations.\n\n\\section{Wang B-machine}\n\n\\(I = \\{ l,r,e,m,n \\} \\cup \\{ c_k ~|~ k \\in \\Nat \\}\\) is \\emph{control alphabet}\nwhere \\(l\\) is left, \\(r\\) is right, \\(e\\) is erase,\n\\(m\\) is mark, \\(n\\) is no-operation,\n\\(c\\) is conditional-absolute-jump-if-marked.\n\n\\(T = \\{0,1\\}\\) is \\emph{data alphabet} where \\(0\\) is blank and \\(1\\) is mark.\n\n\\paragraph{Execution}\nA state is \\(S(a,b,c,d)\\) where \\((a,b)\\) is control tape and \\((c,d)\\) is data tape.\nThe string \\(b\\) ends with infinitely many no-operation symbols (\\(n\\)).\nThe string \\(c\\) begin with infinitely many blanks.\nThe string \\(d\\) ends with infinitely many blanks (\\(0\\)).\nThe leftmost symbol in \\(b\\) is the current instruction.\nThe leftmost symbol in \\(d\\) is the current scanned data tape cell.\n\\begin{align*}\n    \\alpha \\in T, ~ S(A,l B,C \\alpha,D) &\\vdash S(A l,B,C,\\alpha D)\n    \\\\\n    \\alpha \\in T, ~ S(A,r B,C,\\alpha D) &\\vdash S(A r,B,C \\alpha,D)\n    \\\\\n    \\alpha \\in T, ~ S(A,e B,C,\\alpha D) &\\vdash S(A e,B,C,0 D)\n    \\\\\n    \\alpha \\in T, ~ S(A,m B,C,\\alpha D) &\\vdash S(A m,B,C,1 D)\n    \\\\\n    S(A,c_n B,C,0 D) &\\vdash S(A c_n,B,C,0 D)\n    \\\\\n    |A| = n, ~ S(A \\alpha, c_n B, C, 1 D) &\\vdash S(A, \\alpha c_n B, C, 1 D)\n\\end{align*}\n\n\\paragraph{Example}\nThe program \\(e r c_0\\) replaces all marks with blanks.\n\n\\section{Turing machine}\n\nA \\emph{Turing machine} is a finite-state machine with read-write memory.\nHow do we model finite-state machine?\nHow do we model read-write memory?\n\nLet \\(m\\) be a Turing machine.\n\nLet \\(A\\) be the alphabet.\nIt is finite.\n\nLet \\(S\\) be the state type.\nIt is finite.\n\nLet \\(P = (S,T)\\) be the phase type.\n\nLet \\(T = (A^\\infty,A,A^\\infty)\\) be the tape type.\n\nDefine the \\emph{phase} of \\(m\\) as \\((s,t)\\)\nwhere \\(s\\) is the \\emph{state} and \\(t\\) is the \\emph{tape}.\n\nA tape is \\((L,h,R) : (A^\\infty,A,A^\\infty)\\).\n\nDefine the transition function \\(\\after : P \\to P\\).\n\nThe pluggable parts of the machine are\nthe alphabet type \\(A\\),\nthe state type \\(S\\),\nthe next-state function \\(\\jump : (S,A) \\to S\\),\nthe output-symbol function \\(\\fwrite : (S,A) \\to A\\),\nand the direction function \\(\\dir : (S,A) \\to \\{0,1\\}\\).\nThe \\(\\jump\\) computes the next state.\nThe \\(\\fwrite\\) function computes the symbol to write.\nThe \\(\\dir\\) function computes where the head should move after writing that symbol.\n\nThe tape is \\((L,h,R)\\).\nThe string \\(L\\) is the \\emph{reverse} of the string on the left of the head.\nThe symbol \\(h\\) is the symbol at the head.\nThe string \\(R\\) is the string on the right of the head.\n\nHere comes an equational description of a Turing machine.\nFor readability, we don't use the minimum number of equations.\n\n\\section{The fixed parts}\n\nA Turing machine must satisfy all of these.\nThese are the parts we cannot change.\n\nThe types.\n\\begin{align}\n    P &= (S,T)\n    \\\\\n    T &= (\\InfList~A, ~ A, ~ \\InfList~A)\n    \\\\\n    \\after &: P \\to P\n\\end{align}\n\nThe logical constraints.\n\\begin{align}\n    S &\\text{ is finite}\n    \\\\\n    A &\\text{ is finite}\n\\end{align}\n\nThe value definitions:\n\\begin{align}\n    \\after~(s,t) &= (s',t')\n    \\\\\n    t &= (L,h,R)\n    \\\\\n    s' &= \\jump~i\n    \\\\\n    t' &= \\dir~\\stay~\\fleft~\\fright~i~(L,w,R)\n    \\\\\n    i &= (s,h)\n    \\\\\n    w &= \\foutput~i\n    \\\\\n    \\stay~(L,h,R) &= (L,h,R)\n    \\\\\n    \\fleft~(cL,h,R) &= (L,c,hR)\n    \\\\\n    \\fright~(L,h,cR) &= (hL,c,R)\n\\end{align}\n\nWe try to avoid pattern matching:\n\\begin{align}\n    t' &= (L',h',R')\n    \\\\\n    w &= \\foutput~i\n    \\\\\n    L' &= \\dir~\\stay_0~\\fleft_0~\\fright_0~L\n    \\\\\n    h' &= \\dir~\\stay_1~\\fleft_1~\\fright_1~L~w~R\n    \\\\\n    R' &= \\dir~\\stay_2~\\fleft_2~\\fright_2~R\n    \\\\\n    \\stay~(L,h,R) &= (L,h,R)\n    \\\\\n    \\fleft~(L,h,R) &= (\\tail~L, \\head~L, \\cons~h~R)\n    \\\\\n    \\fright~(L,h,R) &= (\\cons~h~L, \\head~R, \\tail~R)\n    \\\\\n    \\stay_0~L &= L\n    \\\\\n    \\fleft_0~L &= \\tail~L\n    \\\\\n    \\fright_0~L &= \\cons~L\n    \\\\\n    \\stay_1~h &= h\n    \\\\\n    \\fleft_1~L &= \\head~L\n    \\\\\n    \\fright_1~R &= \\head~R\n    \\\\\n    \\stay_2~R &= R\n    \\\\\n    \\fleft_2~R &= \\cons~R\n    \\\\\n    \\fright_2~R &= \\tail~R\n    \\\\\n    \\stay_0 &= \\stay_2\n    \\\\\n    \\fleft_0 &= \\fright_2\n    \\\\\n    \\fright_0 &= \\fleft_2\n    \\\\\n    \\fleft_1 &= \\fright_1\n\\end{align}\n\nSome note about the notations:\nWe write \\(A^\\infty\\) for the set of all infinite strings of \\(A\\).\n\n\\section{The pluggable parts}\n\nThere are the parts we can change.\n\\begin{align}\n    s_0 &= \\text{the initial state}\n    \\\\\n    S &= \\text{the set of states}\n    \\\\\n    A &= \\text{the set of symbols}\n    \\\\\n    \\jump &= \\text{a function of type \\((S,A) \\to S\\)}\n    \\\\\n    \\foutput &= \\text{a function of type \\((S,A) \\to A\\)}\n    \\\\\n    \\dir &= \\text{a function of type \\(\\forall a ~.~ a \\to a \\to a \\to (S,A) \\to a\\)}\n\\end{align}\n\nIf you have the pluggable parts,\nthe equations will give you a Turing machine.\n\n\\section{Some definitions}\n\nThe input is the initial phase.\n\nLet \\(x = (s,t)\\).\nWe say that \\(x\\) is an \\emph{initial} phase iff \\(s = s_0\\).\nWe say that \\(x\\) is a \\emph{halting} phase iff \\(\\after~x = x\\).\n\nThe \\emph{phase graph} is defined as follows.\nIts vertex set is the set of all phases.\nAn edge \\((x,y)\\) is in the graph iff \\(\\after~x = y\\).\n\nWe say that \\(x\\) \\emph{eventually leads} to \\(y\\) iff\nthere is a path from \\(x\\) to \\(y\\) in the phase graph.\n\nWe say that the machine \\emph{halts for input \\(t\\)} iff\n\\((s_0,t)\\) eventually leads to a halting phase.\n\nLet the alphabet be \\(A = \\{b,0,1\\}\\) where \\(b\\) is the blank symbol.\nLet \\(B = \\ldots bbb \\ldots\\) be an infinite string of blank symbols.\nWe say that the machine \\emph{accepts the input \\(t\\)} iff\nthe phase \\((s_0,t)\\) eventually leads to the phase \\((s, (B,1,B))\\)\nwhere \\(s\\) can be any state.\n\n\\section{Turing machine as constrained unary algebra}\n\nA Turing machine is a unary algebra with a limited transition function.\nIt can only read and write at the head.\n\nWe can encode an infinite stream of \\(a\\)\nas the infinite type \\(S~a = (a \\to b) \\to (S~a \\to b) \\to b\\).\n\n\\emph{A Turing machine is a finite state machine with memory.}\n\nA finite state machine has input, but no memory.\n\nWe can encode memory as infinite feedforward.\n\nA finite state machine step function is a function \\((S,I) \\to (S,O)\\).\n\n\\section{Logical formulation of Turing machine}\n\nWe can encode a function \\(f : A \\to B\\) as a predicate \\(f' : A \\to B \\to Bool\\) such that \\(f'~a~b\\) iff \\(f~a = b\\).\n\nIf you have the predicates \\(\\jump\\), \\(\\fwrite\\), \\(\\stay\\), \\(\\fleft\\), and \\(\\fright\\),\nand an initial state and initial tape,\nthen the Turing machine generator will give you the following inference rules.\nYou can rewrite the rules in Prolog.\nProlog will then simulate that Turing machine.\n\\begin{align}\n    \\inferrule\n    {\\fwrite~s~h~w \\\\ \\stay~s~h}\n    {\\tape~s~(L,h,R)~(L,w,R)}\n    \\\\\n    \\inferrule\n    {\\cons~h'~L'~L \\\\ \\cons~w~R~R' \\\\ \\fwrite~s~h~w \\\\ \\fleft~s~h}\n    {\\tape~s~(L,h,R)~(L',h',R')}\n    \\\\\n    \\inferrule\n    {\\cons~w~L~L' \\\\ \\cons~h'~R'~R \\\\ \\fwrite~s~h~w \\\\ \\fright~s~h}\n    {\\tape~s~(L,h,R)~(L',h',R')}\n    \\\\\n    \\inferrule\n    {\\jump~s~h~s' \\\\ \\tape~s~(L,h,R)~(L',h',R')}\n    {\\phase~(s,(L,h,R))~(s',(L',h',R'))}\n\\end{align}\n\nThe computation path beginning from \\(p\\).\n\\begin{align}\n    \\inferrule\n    {\\phase~p~q \\\\ p \\neq q \\\\ \\fpath~q~r \\\\ \\cons~p~r~r'}\n    {\\fpath~p~r'}\n    \\\\\n    \\inferrule\n    {\\halting~p}\n    {\\fpath~p~[p]}\n\\end{align}\n\n\\begin{align}\n    \\halting~x &\\equiv \\phase~x~x\n\\end{align}\n\n\\begin{align}\n    \\inferrule\n    {\\forall s ~ \\forall h ~ | \\{ w ~|~ \\fwrite~s~h~w \\} | \\le 1 \\\\ \\forall s ~ \\forall h ~ |[\\stay~s~h] + [\\fleft~s~h] + [\\fright~s~h]| \\le 1}\n    {\\text{the machine is deterministic}}\n\\end{align}\n\n\\section{What}\n\nTuring machine as mono-unary algebra of states (configuration-tape pairs)\n\nUniversal Turing machine\n\nLambda calculus\n\nRecursive functions\n\n\\section{Regex, cfg, Brzozowsky}\n\nIf \\(a\\) is a type, then \\(\\Regex~a\\) is a type.\nUsually we call the \\(a\\) in \\(\\Regex~a\\) the \\emph{alphabet}.\n\n\\begin{align}\n    &\\vdash \\fnull : \\Regex~a\n    \\\\\n    &\\vdash \\fempty : \\Regex~a\n    \\\\\n    x : a &\\vdash x : \\Regex~a\n    \\\\\n    x : \\Regex~a, ~ y : \\Regex~a &\\vdash xy : \\Regex~a\n    \\\\\n    x : \\Regex~a, ~ y : \\Regex~a &\\vdash x|y : \\Regex~a\n    \\\\\n    x : \\Regex~a &\\vdash x^* : \\Regex~a\n\\end{align}\n\nSometimes we parenthesize. The expression \\(x|y^*\\) means \\(x|(y^*)\\),\nwhich is different from \\((x|y)^*\\).\n\nLet there be a function \\(\\match : \\Regex~a \\to \\List~a \\to \\Bool\\).\n\\begin{align}\n    \\match~\\fnull~x &\\vdash\n    \\\\\n    &\\vdash \\match~\\fempty~[]\n    \\\\\n    x : a, ~ y = [x] &\\vdash \\match~x~y\n    \\\\\n    \\match~r~x, ~ \\match~s~y &\\vdash \\match~(rs)~(xy)\n    \\\\\n    \\match~r~x \\vee \\match~s~x &\\vdash \\match~(r|s)~x\n    \\\\\n    &\\vdash \\match~r^*~[]\n    \\\\\n    \\match~r~x, \\match~(r^*)~y &\\vdash \\match~(r^*)~(xy)\n\\end{align}\n\nRecall that a language is a \\emph{set} of strings.\nWe define multiplication slightly differently.\nWe replace ordered pair with string concatenation:\n\\begin{align}\n    Q \\times D &= \\{ qd ~|~ q : Q, ~ d : D \\}.\n\\end{align}\n\n\\section{Laziness}\n\nComplete laziness, full laziness, interaction sets\n\nCompile Java to lambda calculus\n\nHigh level intermediate language\n\n\\section{Descriptive complexity}\n\n% https://en.wikipedia.org/wiki/Fagin%27s_theorem\nFagin's theorem:\nThere is a bijection between second-order logic predicates and NP problems. (?)\n\nSee Neil Immerman's book. (?)\n", "meta": {"hexsha": "d5dd8a543f1eaca9f7d709e6530fcbab8de551df", "size": 20934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/computation.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/computation.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/computation.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": 28.5983606557, "max_line_length": 143, "alphanum_fraction": 0.6105856501, "num_tokens": 7273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.621888553437942}}
{"text": "\\section{Gasses And Thermodynamics}\n\t\\subsection{Temperature}\n\tThe measure of hot and cold. More scientifically this is the measure of microscopic kinetic energy\n\t\\newline\n\tThe temperature scales are Kelvin (K) which has a zero point of absolute 0, Celsius (C), which has a zero point of water freezing and has 100 at the boiling point of water, and fahrenheit (F).\n\t\\newline\n\t\\begin{align*}\n\tT_C &= T_k - 273.15\\\\\n\tT_F &= \\frac{9}{5}T_C+32\n\t\\end{align*}\n\t\\subsection{Thermal Equilibrium}\n\tTwo objects are in thermal equilibrium when, while in direct contact, they have the same temperature. When 2 objects have different temperatures, $T_A$ and $T_B$ are brought into thermal contact and they will exchange energy via heat transfer until they reach thermal equilibrium.\n\t\\newline\n\t\\newline\n\tHeat transfer is the spontaneous exchange of microscopic energy due to molecular or atomic collisions.\n\t\\subsection{Thermal Expansion}\n\tThermal expansion is when a solid object expands when it receives a raise in temperature\n\t\\begin{align*}\n\t\\frac{dL}{dT} = \\alpha L\\\\\n\t\\frac{dA}{dT} = 2\\alpha A\\\\\n\t\\frac{dV}{dT} = 3\\alpha V\n\t\\end{align*}\n\tWhere $\\alpha$ is the coefficient of linear expansion\n\t\\subsection{Calorimetry}\n\tCalorimetry is the science of measuring heat transfer. Internal/Thermal energy is the amoung of energy stored in an object as described by its temperature.\n\tHeat Transfer = Q\n\t\\subsection{First Law of Thermodynamics}\n\t\\begin{align*}\n\t\\Delta E_{int} &= Q-W\\\\\n\tdE_{int} &= dQ-dQ\\\\\n\tQ &=c \\Delta T\\\\\n\tc &= \\frac{C}{M}\\\\\n\tQ &= mc\\Delta T\n\t\\end{align*}\n\tWhere c is the specific heat capacity, m is the mass of the substance, and $\\Delta T$ is the change in temperature.\n\t\\subsection{Phases of Matter}\n\tThe phases of matter (from hottest to coldest) are Plasma, Gas (condenses to, or evaporates from), Liquid (freezes to, or melts from), Solid, and Condensates. During a phase change $Q=mL_v$ or $Q=mL_v$\n\t\\subsubsection{Example 1}\n\tThe U-district bridge has a span of 450ft. How much will it expand in spokane. The bridge is made out of concrete and steel which both have $\\alpha = 12*10^{-6}\\frac{1}{C\\si{\\degree}}$. $T_{high}=110\\si{\\degree}F \\to 120\\si{\\degree}F$, $T_{low}=-30\\si{\\degree}F \\to -40\\si{\\degree}F$\n\t\\begin{align*}\n\tt_{high}&=489\\si{\\degree}C\\\\\n\tT_{low}&=-40\\si{\\degree}C\n\tL&=137m\n\t\\end{align*}\n\t\\newline\n\t\\newline\n\t\\begin{align*}\n\t\\frac{\\Delta L}{\\Delta T}&=\\alpha L\\\\\n\t\\Delta L&=\\alpha L\\Delta T\\\\\n\t&=\\left(12*10^{-6}\\frac{1}{C\\si{\\degree}}\\right)(137m)(48.9\\si{\\degree}C--40\\si{\\degree}C)\\\\\n\t&=0.146m\n\t\\end{align*}\n\t\\subsubsection{Example 2}\n\tYour freezer is set to $23\\si{\\degree}F$, you remove a 26g ice cube and place it in an empty glass. The next day the ice has melted and come to $72\\si{\\degree}F$. Find the change in energy of the ice.\n\t\\begin{align*}\n\t\\Delta E_{int}&=M_{ice}C_{ice} \\Delta T_{01}+M_{ice}L_{f_{ice}}+M_{water}C_{water} \\Delta T_{12}\\\\\n\t&=M_{ice}(C_{ice}\\Delta T_{01}+L_{f_{ice}}+C_{water} \\Delta T_{12})\n\t\\end{align*}\n\n\n\t\\subsection{Molecular Model of Gasses}\n\tWe will describe gasses using state variables. State variables are macroscopic quantities used to describe the state of matter. Relative state variables can be used together to make quantitative predictions. This can be done using equations of state. Pressure $P=\\frac{F}{A}$, Volume V, temperature T, the number of gas particles N, or the number of moles $n=\\frac{N}{N_A}$ where $N_A$ is Avogadros number ($6.022*10^{23}$)\n\t\\subsection{Simplifying Assumptions of Gaseous Behavior}\n\tThese are assumptions for an ideal gas that will make math easier:\n\t\\begin{itemize}\n\t\\item Distance between the gas molecules is much larger than the diameter of the molecules themselves, thus forces between molecules can be ignored.\n\t\\item When gas molecules colide we will assume they are perfectly elastic collisions, thus $P$ can be easily derived.\n\t\\item Due to the large distance between molecules, they are very compressible.\n\t\\item The temperature of the gas is well above boiling point for given $P$ and V.\n\t\\end{itemize}\n\tWhen a gas can be accurately described by these rules, the gas is considered an ideal gas. Most gasses experienced everyday are ideal gasses. The equation of state for an ideal gas is the ideal gas law:\n\t\\begin{equation*}\n\tPV=NK_BT \\to PV=n(N_AK_B)T \\to PV=nRT\n\t\\end{equation*}\n\tBoltons Constant $\\to K_B=1.38*10^{-23}\\frac{J}{K}$\n\t\\newline Gas Constant $\\to R=8.314\\frac{J}{mol*K}$\n\t\\subsection{Finding the Pressure of an Ideal Gas}\n\tAssuming a gas is within a rigid walled cube of length $l$, and when a gas molecule hits a wall it will change direction but conserve kinetic energy:\n\t\\begin{align*}\n\t\\Delta P \\to \\Delta P_x = -2mv_x\n\t\\vec{F}=m\\vec{a}\n\t\\vec{F}=\\frac{d}{dt}\\vec{P} = \\frac{\\Delta \\vec{P}}{\\Delta t}\n\t\\end{align*}\n\tAverage time between colisions is $2L=v_x \\Delta t$\n\t\\begin{align*}\n\t\\left|\\frac{\\Delta P_x}{\\Delta t}\\right| = \\frac{2mv_x}{\\frac{2L}{V_x}}=\\frac{mv^2}{L}=F_x\\\\\n\tP_i=\\frac{F}{A}=\\frac{F_x}{L^2}=\\frac{m_iv_{xi}^2}{L^3}\n\t\\end{align*}\n\tTotal Pressure: $P=\\sum_{i}{P_i}=\\frac{m}{L^3}(\\sum_{i}V_x^2)$\n\t\\begin{align*}\n\t\\shortintertext{We know: } \\vec{v}&=v_x\\vec{i}+v_y\\vec{j}+v_z\\vec{k}\\\\\n\tv^2 &= v_x^2+v_y^2+v_z^2\\\\\n\tv^3 &= v_x^3+v_y^3+v_z^3\n\t\\end{align*}\n\tTherefore we can determine that:\n\t\\begin{align*}\n\tP &= \\frac{m}{L^3}N(v_x^2)_{avg}\\\\\n\tP &= \\frac{m}{3L^3}N(v^2)_{avg}\\\\\n\tPV &= \\frac{m}{3}N(v^2)_{avg}\n\t\\end{align*}\n\tRemember that for ideal gasses, $PV=NK_BT$, therefore  $K_BT=\\frac{1}{3}m(v^2)_{avg}$\n\t\\subsection{Root Mean Squared}\n\tRoot mean squared is the average velocity for any given particle. It is defined by the equation $v_{rms}=\\sqrt{v_{avg}^2}=\\sqrt{\\frac{3K_BT}{m}}$, where M is the mass of the object (particle) and T is the temperature of the particle.\n\t\\subsection{Kinetic Average}\n\t\\begin{equation*}\n\tK_{avg}=\\frac{1}{2}m(v^2)_{avg}=\\frac{3}{2}K_BT\n\t\\end{equation*}\n\t\\newline\n\t\\begin{align*}\n\tE_{int}&=K_{tot}=\\sum{i}K_i=NK_{avg_i}\\\\\n\tE_{int} &= \\frac{3}{2}NK_BT\\\\\n\t\\shortintertext{Or }E_{int}&=\\frac{3}{2}nRT\n\t\\end{align*}\n\t\\subsection{Mean Free Path}\n\tThe mean free path of a gas is the average distance traveled by a gas molecule between collisions. Considering a room of volume V, that is filled with gas with molecules with diameter d.\n\t\\begin{align*}\n\t\\lambda &= \\frac{\\text{Length of path in time}\\Delta T}{\\text{Number of collisions within}\\Delta T}\\\\\n\t\\lambda &= \\frac{v \\Delta T}{N\\frac{V_{Cylinder}}{V}}\\\\\n\t\\lambda &= \\frac{V}{\\sqrt{2}N\\pi d^2}\\\\\n\t\\text{Number Density } \\eta &= \\frac{N}{V}\\\\\n\t\\lambda &=\\frac{1}{\\sqrt{2}\\eta \\pi d^2}\\\\\n\tPV &= nRT = NK_BT \\text{, } P=\\eta K_BT\n\t\\end{align*}\n\t\\subsubsection{Example 1}\n\tFind the RMS speed($v_{rms}$) of a $N_2$ molecule in a room at 20$\\si{\\degree}C$. DiNitrogen has a molecular mass of $14\\frac{g}{mol}$, the R constant = $8.314\\frac{J}{mol*K}$, M = molar mass and m = mass and T=293K.\n\tRecall that $M=mN_A$.\n\t\\begin{align*}\n\tv_{rms}&=\\sqrt{(v^2)_{avg}}\\\\\n\t&=\\sqrt{\\frac{3K_BT}{m}}\\\\\n\t&=\\sqrt{\\frac{3K_BT}{\\frac{M}{N_A}}}\\\\\n\t&=\\sqrt{\\frac{3N_AK_BT}{M}}=\\sqrt{\\frac{3RT}{M}}\\\\\n\tv_{rms}&=\\sqrt{\\frac{3\\left(8.314\\frac{J}{mol*K}\\right)(295K)}{0.028\\frac{Kg}{mol}}}\n\t\\end{align*}\n\n\n\t\\subsection{Work}\n\tHow much work will a gas do on its environment? Recall, $P=\\frac{F}{A}$.\n\t\\begin{align*}\n\tdW&=\\vec{F}d\\vec{x}\\\\\n\t&=Fdx-PAdx\\\\\n\t&=PdV\n\t\\end{align*}\n\t\\subsection{How The First law of Thermodynamics Relates to Work}\n\t\\begin{align*}\n\t\\Delta E_{int} = Q-W \\to dE_{int} &=Q-PdV\\\\\n\td\\left(\\frac{3}{2}NK_BT\\right) &= Q-PdV\\\\\n\t\\left(\\frac{3}{2}NK_BT\\right) &=Q-QdV\n\t\\end{align*}\n\t\\begin{itemize}\n\t\\item Presure thermal equilibrium (quasi-static)\n\t\\begin{align*}\n\t\t\\int{dw}&=\\int{PdV}\\\\\n\t\tW_{1\\to2}&=\\int_{v_1}^{v^2}{PdV}\n\t\\end{align*}\n\t\\item Isoconic case ($\\Delta V = 0$)\n\t\\begin{align*}\n\t\tw=0\n\t\\end{align*}\n\t\\item isoboric ($\\Delta P=0$)\n\t\\begin{align*}\n\t\tw_{1\\to2}&=P\\int_{v_1}^{v_2}{dV}\\\\\n\t\t&=P(V_2-V_1)\n\t\\end{align*}\n\t\\item isothermal ($\\Delta T=0$)\n\t\\begin{align*}\n\t\tw_{1\\to2} &= \\int_{V_1}^{V_2}{PdV}\\\\\n\t\tP=\\frac{NK_BT}{V}\\\\\n\t\tw_{1\\to2} &=\\int_{V_1}^{V_2}{\\frac{NK_BT}{V}dV}\\\\\n\t\t&=NK_BT\\int_{V_1}^{V_2}\\frac{dV}{V}\\\\\n\t\tw_{1\\to2} &= NK_BTln \\left( \\frac{V_2}{V_1} \\right)\n\t\\end{align*}\n\t\\end{itemize}\n\t\\subsection{Pressure / Volume Diagrams}\n\tThis is an easy way to interperate the changes due to temperature, pressure, and volume changes.\n\t\\begin{itemize}\n\t\\item Adiabatic $(Q=0)\\to E_{int}=W$\n\t\\item isothermal $(\\Delta T = 0)$\n\t\\begin{align*}\n\t\t\\Delta E_{int} &= Q-W\\\\\n\t\t\\frac{3}{2}NK_BdT&=Q-PdV \\text{, } PdV=Q\n\t\\end{align*}\n\t\\item Isocloric $(\\Delta V = 0) \\to W=0 \\to \\Delta E_{int}=0$\n\t\\item isoboric $(\\Delta P = 0) \\to W=P\\Delta V \\to \\Delta E_{int}=Q-P\\Delta V$\n\t\\end{itemize}\n\t\\subsubsection{Example 1}\n\tA sealed ideal gas is in a rigid container of $0.6m^3$ initially at room temperature $(T_1=20\\si{\\degree}C\\to 293K)$ and pressure $(P_1=1atm\\cong 10^5pa)$. If the temp ``doubles'' to $T_2=40\\si{\\degree}C\\to313K$,\n\t\\newline A.) what is the new pressure$(P_2)$?\n\t\\begin{align*}\n\t\\newline\n\tPV&=nRT\\\\\n\t\\text{Or, }P_1V_1&=n_1RT_1 \\text{, }P_2V_2=n_2RT_1\\\\\n\t\\frac{P_1}{T_1}&=\\frac{n_1R}{V_1} = const\\\\\n\t\\frac{P_2}{T_2}&=\\frac{n_1R}{V_2} = \\frac{n_1R}{V_1}\\\\\n\t\\text{therefore:}\\\\\n\t\\frac{P_1}{T_1}&=\\frac{P_2}{T_2}\\\\\n\tP_2&=P_1\\frac{T_2}{T_1}\\\\\n\t&=(10^5pa)\\frac{315K}{295K}=1.07*10^5pa\n\t\\end{align*}\n\tB.) How much work did the gas do?\n\t\\begin{align*}\n\tdW&=PdW\\\\\n\tw_{1\\to2}&=\\int_{V_1}^{V^2}{PdV}\\\\\n\tw_{1\\to2}&=0\n\t\\text{There was no change in volume}\n\t\\end{align*}\n\tC.) How much heat was transfered (Not using $mc\\Delta T$)?\n\t\\begin{align*}\n\t\\Delta E_{int}&=Q-W (W=\\int{PdV}=0)\\\\\n\t\\Delta E_{int}&=Q\\\\\n\tQ&=\\frac{3}{2}nR(T_2-T_1)=\\frac{3}{2}NK_B(T_2-T_1)\\\\\n\t&=\\frac{3}{2}(P_2V_2-P_1V_1)\\\\\n\tQ&= \\frac{3}{2}V_1(P_2,P_1)\\\\\n\t&=6,140J\n\t\\end{align*}\n\t\\subsubsection{Example 2}\n\tA sealed ideal gas undergoes an isobaric $(\\Delta P=0)$ expansion during which it triples in volume. Then it is isothermically $(\\Delta T=0)$ compressed to original volume, after which it cools to its original temperature. Find Q and W in terms of initial pressure and volume for each stage of cucle and the full cycle. Draw a PV diagram as well.\n\t\\begin{align*}\n\tPV&=nRT\\\\\n\tP&=\\frac{nRT}{V}\\to T=\\frac{PV}{nR}\\\\\n\t\\Delta E_{int_{cyc}}&=0=Q_{cyc}-W{cyc}\\\\\n\tQ_{cyc}&=W_{cyc}\\\\\n\t\\text{A.) Find the work from 1 to 2:}\\\\\n\tW_{1\\to2}&=\\int_{V_1}^{V_2}{PdV}\\\\\n\t&=\\int_{V_1}^{3V_1}{dV}\\\\\n\t&=P_1(3V_1-V_1)\\\\\n\tw_{1\\to2}&=2P_1V_1\\\\\n\t\\text{B.) Find the work from 2 to 3:}\\\\\n\tW_{2\\to3}&=\\int_{v_2}^{v_3}PdV \\to PV=nRT \\to P=\\frac{nRT}{V}\\\\\n\t&=\\int_{V_2}^{V_1}{\\frac{nRT}{V}dV}\\\\\n\t&=n_2RT_2\\int_{V_2=3V}^{V_1}{\\frac{dv}{V}}\\\\\n\t&=n_2RT_2ln\\left(\\frac{V_1}{3V_1}\\right)=n_2RT_2ln\\left(\\frac{1}{3}\\right)\\\\\n\tw_{2\\to3}&=-n_2RT_2ln(3) \\to PV=nRT\\\\\n\t&=-P_2V_2ln(3)\\\\\n\tw_{2\\to3}&=-3ln(3)P_1V_1=-3.29P_1V_1\\\\\n\t\\text{C.) Find the work from 3 to 1:}\\\\\n\tw_{3\\to1} &= \\int_{v_3}^{v_1}{PdV}=0\\\\\n\tw_{3\\to1} &= 0\\\\\n\t\\text{D.) Find the heat of the cycle}\\\\\n\tw_{cyc}&=w_{1\\to2}+w_{2\\to3}+w{2\\to3}=P_1V_1(2-3ln3)\\\\\n\t&= -1.30P_1V_1\\\\\n\t\\text{Since, } \\Delta E_{int_cyc}=0, \\text{ then } 0&=Q_{cyc}-W_{cyc}\\\\\n\tQ_{cyc}&=W_{cyc}=-1.30P_1V_1\\\\\n\t\\text{And since }2\\to3\\text{ is an isotherm, we know } Q&=W\\\\\n\tQ_{2\\to3}&=W_{2\\to3}=-3ln(3)P_1V_1\\\\\n\t\\text{For }1\\to2 \\text{: }\\\\\n\t\\Delta E_int_{1\\to2} &= Q_{1\\to2}-W_{1\\to2}\\\\\n\tQ_{1\\to2}&=\\frac{3}{2}nR(T_2-T_1)+2P_1V_1\\\\\n\t&=\\frac{3}{2}n_2RT_2-\\frac{3}{2}n_1RT_1+2P_1V_1\\\\\n\t&=\\frac{3}{2}P_2V_2-\\frac{3}{2}P_1V_1+2P_1V_1\\\\\n\t&=\\frac{3}{2}P_13v_2-\\frac{3}{2}P_1V_1+2P_1V_1\\\\\n\t&= \\left(\\frac{9}{2}-\\frac{3}{2}+2\\right)P_1V_1\\\\\n\tQ_{1\\to2}&=5P_1V_1\\\\\n\tQ_{cyc}&=Q_{1\\to2}+Q_{2\\to3}+Q{3\\to1}\\\\\n\tQ{3\\to1}&=Q_{cyc}-Q_{1\\to2}-Q_{2\\to3}\\\\\n\t&=((2-3ln3)-5+3ln3)P_1V_1\\\\\n\tQ_{3\\to1}&=-3P_1V_1\n\t\\end{align*}\n\n\n\t\\subsection{Using $C_V$ and $C_P$}\n\tWhile considering the first law, $dE_{int}=Q-PdV$, consider a constant volume: $dE_{int}=Q$, also: $E_{int}=\\frac{3}{2}nRT$.\n\t\\begin{align*}\n\t\\frac{3}{2}nRdT&=Q\\\\\n\tnC_vdT &=Q\\\\\n\t\\frac{3}{2}R=C_v \\text{ if volume is constant}\\\\\n\tdE_{int}&=nC_vdT\\\\\n\t\\end{align*}\n\twhen $\\Delta V=0$, then $Q=nC_V\\Delta T$, but in all cases, $\\Delta E_{int}= nC_V\\Delta T$.\n\t\\newline\n\t\\begin{align*}\n\t\\text{We have introduced } C_V&=\\frac{3}{2}R\\\\\n\t\\text{But recall: } (v)_{avg}^2&=V_{x_{avg}}^2+V_{y_{avg}}^2+V_{z_{avg}}^2\\\\\n\t\\text{which gives us three degrees of translation, which is also why:}\\\\\n\tk_{avg}&=\\frac{1}{2}m(v^2)_{avg}\\\\\n\t\\text{this leads us to } E_{int}&=\\frac{3}{2}nRT\\\\\n\t\\end{align*}\n\tWe can generalize $C_V=\\frac{3}{2}R$ to be $C_V=\\frac{d}{2}R$ for degrees if freedom. Other degrees of freedom come from both roation and vigration. Most monatomic atoms have 3 degrees of translation, and zero degrees of rotation and vibration. Diatomic atoms on the other hand have 3 degrees of translation, 2 degrees of rotation, and 1 degree of vibration.\n\t\\newline\n\t\\newline\n\tConsider the case when $(\\Delta P=0)$. Let's preserve the form $Q=nC_PdT$\n\t\\begin{align*}\n\tdE_{int}&=Q-Pdv\\\\\n\t\\Delta E_{int}&=Q-P\\Delta V\\\\\n\tnC_V\\Delta T&=Q-P\\Delta V\\\\\n\tnC_V\\Delta T &= nC_P\\Delta T-P\\Delta V\\\\\n\t\\text{Note that } PV=nRT\\\\\n\tdPV=d(nRT) \\text{ therefore }P\\Delta V=nR\\Delta T\\\\\n\tnC_v\\Delta T&=nC_P \\Delta T-nR\\Delta T\\\\\n\tC_V&=C_P-R\\\\\n\tC_P&=C_V+R\\\\\n\t\\end{align*}\n\tNow for $(Q=0)$,\n\t\\begin{align*}\n\tdE_{int}&=Q-PdV\\\\\n\tnC_VdT&=-PdV\\\\\n\tndT&=-\\frac{P}{C_V}dT\\\\\n\t\\text{because }PV=nRT \\text{, we can conclude } ndT&=\\frac{V}{R}+\\frac{P}{R}dV\\\\\n\t-\\frac{P}{C_V}dT&=\\frac{V}{R}dP+\\frac{P}{R}dV\\\\\n\t\\text{divide everything by PV: } -\\frac{1}{C_V}\\frac{D_V}{V} &=\\frac{1}{R}\\frac{dP}{P}+\\frac{1}{R}\\frac{dV}{V}\\\\\n\t\\text{Multiply by }C_VR \\text{ } -R\\frac{dV}{V}&=C_V\\frac{dP}{P}+C_V{dV}{V}\\\\\n\t0&=C_V\\frac{dP}{P}+(C_V+R)\\frac{dV}{V}\\\\\n\t&=C_V\\frac{dP}{P}+C_P\\frac{dV}{V}\\\\\n\t&=\\int{\\frac{dP}{P}}+\\frac{C_P}{C_V}\\int{\\frac{dV}{V}}\\\\\n\t\\text{const}&=ln\\frac{P}{P_o}+\\frac{C_P}{C_V}ln\\frac{V}{V_o}\\\\\n\tPV^{\\left(\\frac{C_P}{C_V}\\right)}&=\\text{const}\\\\\n\tPV^{\\gamma}&=\\text{const for } \\gamma=\\frac{C_P}{C_V}\\\\\n\t\\end{align*}\n\t\\subsubsection{Example 1}\n\t2.2 moles of Ar gas are in a sealed metal container at room temp $(20\\si{\\degree}C=68\\si{\\degree}F)$. We then put the container on the sidewalk on a hot $(35\\si{\\degree}C=95\\si{\\degree}C)$ day. Let the gas come to temp $(95\\si{\\degree}F)$.\n\t\\newline\n\tA.) Was any work done by or on the gas? There was little displacement, so almost 0 work done on the container.\n\t\\newline\n\tB.) was any heat transferred to or from the gas? Heat was transfered to the gas.\n\t\\newline\n\tC.) Find the gass' internal energy. We can always write:\n\t\\newline\n\t\\begin{align*}\n\tE_{int}&=\\frac{3}{2}NK_BT=\\frac{3}{2}nRT\\\\\n\tdE_{int}&=\\frac{3}{2}K_B(TdV+NdT)\\\\\n\tdE_{int}&=\\frac{3}{2}K_BdT\\\\\n\t\\Delta E_{int}&=\\frac{3}{2}NK_B\\Delta T\\\\\n\t\\Delta E_{int}&=nR\\Delta T\\\\\n\t&=\\frac{3}{2}(2.2mol)(8.314\\frac{J}{molK})(35\\si{\\degree}C-20\\si{\\degree}C)\\\\\n\t&=411J\\\\\n\t\\text{More generally } E_{int}=\\frac{d}{2}nRT \\text{Where d=degrees of translation}\\\\\n\t&=nC_VT \\text{for } C_V=\\frac{d}{2}R\\\\\n\t\\end{align*}\n\t\\newline\n\tAround room temperature for monotimic atoms, $C_V=\\frac{3}{2}R$. For diatomic molecules it is $C_V=\\frac{5}{2}R$.\n\t\\subsubsection{Example 2}\n\tSolve the same problem where the only difference is the gas is a 2.2 moles of $H_2$. Given the temperatures, we know that $C_V=\\frac{5}{2}R$.\n\t\\begin{align*}\n\t\\Delta E_{int}&=nC_V\\Delta T\\\\\n\t&=n\\frac{5}{2}R\\Delta T\\\\\n\t&=\\frac{5}{2}nR\\Delta T\\\\\n\t&=\\frac{5}{2}(2.2mol)(8.214\\frac{J}{molK})(15K)\\\\\n\t&=687J\n\t\\end{align*}\n\t\\subsubsection{Example 3}\n\tCalculate work done by a gas during adiabatic expansion from $V_1$ to $V_2=4V_1$ in terms of $V_1$ and $V_2$. Remeber that adiabats result in no heat transfer $(Q=0)$ and $PV^\\gamma{}=constant$, which means $\\gamma{}=\\frac{C_P}{C_V}=const$. Let $PV^\\gamma{}=const$.\n\t\\begin{align*}\n\t\\text{Always: } w&=\\int_{V_1}^{V^2}{PdV}\\\\\n\t&=\\int_{V_1}{V_2}\\frac{b}{V^\\gamma}dv\\\\\n\t&=b\\int_{V_1}^{V_2}{V^{-\\gamma}}dv\\\\\n\t&=\\frac{b}{-\\gamma+1}V^{\\gamma+1}|_{V_1}{V_2=4V_1}\\\\\n\t&=\\frac{b}{1-\\gamma}\\left[(4V_1)^{1-\\gamma}-V_1^{1-\\gamma}\\right]\\\\\n\t&=\\frac{b}{1-\\gamma}\\left[4^{1-\\gamma}V_1^{1-\\gamma}-V_1^{1-\\gamma}\\right]\\\\\n\t&=\\frac{b}{1-\\gamma}V_1^{1-\\gamma}\\left[4^{1-\\gamma}-1\\right]\\\\\n\t&=\\frac{4^{1-\\gamma}-1}{1-\\gamma}bV_1^{1-\\gamma}\\\\\n\t&=\\frac{4^{1-\\gamma}-1}{1-\\gamma}P_1V_1^{\\gamma}V_1^{1-\\gamma}\\\\\n\tW&=\\frac{4^{1-\\gamma}-1}{1-\\gamma}P_1V_1\n\t\\end{align*}\n\tWork done by a gas during an adiabatic expansion from $V_1to4V_1$. Let's find a more simplified answer for monatomic and diatomic gasses. The adiabatic ratio is $\\gamma=\\frac{C_P}{C_V}$, but it also means $C_P=C_V+R$. At room temperature, $C_V=\\frac{3}{2}R$ for monotomic and $C_V=\\frac{5}{2}R$.\n\t\\begin{align*}\n\t\\gamma_{mon}&=\\frac{\\frac{3}{2}R+R}{\\frac{3}{2}R}=\\frac{\\frac{5}{2}R}{\\frac{3}{2}R}=\\frac{5}{3}\\\\\n\t\\gamma_{dia}&=\\frac{\\frac{5}{2}R+R}{\\frac{5}{2}R}=\\frac{\\frac{9}{2}R}{\\frac{5}{2}R}=\\frac{7}{5}\\\\\n\t\\text{We found that } W&=\\frac{4^{1-\\gamma}-1}{1-\\gamma}P_1V_1\\\\\n\tW_{dia}&=\\frac{4^{1-\\gamma}-1}{1-\\gamma}P_1V_1 \\text{ for } \\gamma_{dia}=\\frac{7}{5}\\\\\n\tw_{dia}&=1.06P_1V_1\\\\\n\tW_{mon}&=\\frac{4^{\\frac{3}{3}-\\frac{5}{3}}-1}{\\frac{3}{3}\\frac{5}{3}}P_1V_1\\\\\n\t&=\\frac{-4^{\\frac{-2}{3}}-1}{\\frac{-2}{3}}P_1V_1\\\\\n\t&=\\frac{3}{2}\\left(1-4^{\\frac{-2}{3}}\\right)P_1V_1\\\\\n\t&=.905P_1V_1\\\\\n\t\\Delta{}E_{int}&=-1\\\\\n\t\\end{align*}\n\t\\subsection{Entropy}\n\tReversible processes can have their processes reversed in time. When played inr evers, the behavior still looks physical (like a video). Any real system will have disipative forces and thus will not be perfectly reversible. Considering heat transfer, recording an ice cube melt and playing that video in reverse would look nonsensical. According to the second law of thermodynamics, heat always flows spontaneously from a hotter object to a colder object and vice versa. Irreversible process can happen within a closed system.\n\t\\newline\n\t\\newline\n\tFor a reversible system, entropy is given by $dS=\\frac{dQ}{T}$. For isothermal processes:\n\t\\begin{align*}\n\t\\int{dS}&=\\int{\\frac{dQ}{T}}\\\\\n\t\\int{dS}&=\\frac{1}{T}\\int{dQ}\\\\\n\t\\Delta S &= \\frac{Q}{T}\n\t\\end{align*}\n\tImagine an ice cube melting at $0\\si{\\degree}C$. Then $Q=mL_f$,\n\t\\begin{equation*}\n\t\\Delta S =\\frac{mLf}{T}\n\t\\end{equation*}\n\tIn general for a reversible process, we know:\n\t\\begin{align*}\n\tdE_{int}&=dQ-dW\\\\\n\tdQ&=dE_{int}+dW\\\\\n\t\\text{then entropy is: } ds&=\\frac{dQ}{T}=\\frac{dE_{int}+dW}{T}\\\\\n\t&=\\frac{nC_VdT+PdV}{T}=nC_V\\frac{dT}{T}+P\\frac{dV}{T}\\\\\n\t\\text{from the ideal gas law, } PV&=nRT \\text{ or } \\frac{P}{T}=\\frac{nR}{V}\\\\\n\t\\text{then, } \\int{dS}&=\\int{nC_V\\frac{dT}{T}}+\\int{\\frac{nRdV}{V}}\\\\\n\t\\Delta S_{0\\to1}&=nC_Vln\\frac{T_1}{T_2}+nRln\\frac{V_1}{V_2}\\\\\n\t\\text{For a reversible complete cycle:}\\\\\n\t\\oint dS&=0\n\t\\end{align*}\t\n\\newpage", "meta": {"hexsha": "35d1c44860dc85d28c61ed340580459032012926", "size": 18514, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "physics204/Sections/3Gasses.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/3Gasses.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/3Gasses.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": 47.2295918367, "max_line_length": 527, "alphanum_fraction": 0.6597169709, "num_tokens": 7760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6218885477309042}}
{"text": "\\section{Homotopy groups of types}\n\n\\subsection{Pointed types}\n\n\\begin{defn}\n\\begin{enumerate}\n\\item A pointed type consists of a type $X$ equipped with a base point $x:X$. We will write $\\UU_\\ast$ for the type $\\sm{X:\\UU}X$ of all pointed types.\n\\item Let $(X,\\ast_X)$ be a pointed type. A \\define{pointed family} over $(X,\\ast_X)$ consists of a type family $P:X\\to \\UU$ equipped with a base point $\\ast_P:P(\\ast_X)$. \n\\item Let $(P,\\ast_P)$ be a pointed family over $(X,\\ast_X)$. A \\define{pointed section} of $(P,\\ast_P)$ consists of a dependent function $f:\\prd{x:X}P(x)$ and an identification $p:f(\\ast_X)=\\ast_P$. We define the \\define{pointed $\\Pi$-type} to be the type of pointed sections:\n\\begin{equation*}\n\\Pi^\\ast_{(x:X)}P(x) \\defeq \\sm{f:\\prd{x:X}P(x)}f(\\ast_X)=\\ast_P\n\\end{equation*}\nIn the case of two pointed types $X$ and $Y$, we may also view $Y$ as a pointed family over $X$. In this case we write $X\\to_\\ast Y$ for the type of pointed functions.\n\\item Given any two pointed sections $f$ and $g$ of a pointed family $P$ over $X$, we define the type of pointed homotopies\n\\begin{equation*}\nf\\htpy_\\ast g \\defeq \\Pi^\\ast_{(x:X)} f(x)=g(x),\n\\end{equation*}\nwhere the family $x\\mapsto f(x)=g(x)$ is equipped with the base point $\\ct{p}{q^{-1}}$. \n\\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\nThe circle $\\sphere{1}$ is a pointed type with base point $\\base:\\sphere{1}$.\n\\end{eg}\n\n\\begin{eg}\nIf $X$ is a pointed type, then in the suspension of $X$ we have the canonical identification $\\merid(\\ast_X):\\north=\\south$. Therefore we do not have to worry about whether to choose $\\north$ or $\\south$ as the base point of $\\susp{X}$. \n\\end{eg} \n\n\\begin{rmk}\nSince pointed homotopies are defined as certain pointed sections, we can use the same definition of pointed homotopies again to consider pointed homotopies between pointed homotopies, and so on.\n\\end{rmk}\n\n\\begin{defn}\n\\begin{enumerate}\n\\item For any pointed type $X$, we define the \\define{pointed identity function} $\\mathsf{id}^\\ast_X\\defeq (\\idfunc[X],\\refl{\\ast})$. \n\\item For any two pointed maps $f:X\\to_\\ast Y$ and $g:Y\\to_\\ast Z$, we define the \\define{pointed composite}\n\\begin{equation*}\ng\\mathbin{\\circ_\\ast} f \\defeq (g\\circ f,\\ct{\\ap{g}{p_f}}{p_g}).\n\\end{equation*}\n\\end{enumerate}\n\\end{defn}\n\n\\subsection{Loop spaces}\n\\begin{defn}\nLet $X$ be a pointed type with base point $x$. We define the \\define{loop space} $\\loopspace{X,x}$ of $X$ at $x$ to be the pointed type $x=x$ with base point $\\refl{x}$. \n\\end{defn}\n\n\\begin{defn}\nThe loop space operation $\\loopspacesym$ is \\emph{functorial} in the sense that\n\\begin{enumerate}\n\\item For every pointed map $f:X\\to_\\ast Y$ there is a pointed map\n\\begin{equation*}\n\\loopspace{f}:\\loopspace{X}\\to_\\ast \\loopspace{Y},\n\\end{equation*}\ndefined by $\\loopspace{f}(\\omega)\\defeq \\ct{p_f}{\\ap{f}{\\omega}}{p_f^{-1}}$, which is base point preserving by $\\mathsf{right\\usc{}inv}(p_f)$. \n\\item For every pointed type $X$ there is a pointed homotopy\n\\begin{equation*}\n\\loopspace{\\mathsf{id}_X^\\ast}\\htpy_\\ast \\mathsf{id}^\\ast_{\\loopspace{X}}.\n\\end{equation*}\n\\item For any two pointed maps $f:X\\to_\\ast Y$ and $g:Y\\to_\\ast X$, there is a pointed homotopy witnessing that the triangle\n\\begin{equation*}\n\\begin{tikzcd}\n& \\loopspace{Y} \\arrow[dr,\"\\loopspace{g}\"] \\\\\n\\loopspace{X} \\arrow[rr,swap,\"\\loopspace{g\\circ_\\ast f}\"] \\arrow[ur,\"\\loopspace{f}\"] & & \\loopspace{Z}\n\\end{tikzcd}\n\\end{equation*}\nof pointed types commutes.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{thm}\nConsider two pointed types $(X,x_0)$ and $(Y,y_0)$. Then there is an equivalence\n\\begin{equation*}\n\\eqv{(\\susp X \\to_\\ast Y)}{(X \\to_\\ast \\loopspace Y)}\n\\end{equation*}\n\\end{thm}\n\n\\begin{proof}\nComputing with the universal property of the suspension\n\\begin{align*}\n\\susp X \\to_\\ast Y & \\eqvsym \\sm{y,y':Y} (X \\to (y=y'))\\times (y'=y_0) \\\\\n& \\eqvsym \\sm{y:Y} X\\to (y=y_0) \\\\\n& \\eqvsym \\sm{f:X\\to (y=y_0)}f(x_0)=\\refl{y_0}.\n\\end{align*}\nIn the last equivalence we used \\cref{ex:coh_intro}.\n\\end{proof}\n\n\\subsection{Homotopy groups}\nIn homotopy type theory we use $0$-types to define groups.\n\\begin{defn}\nA \\define{group} $\\mathcal{G}$ consists of a set $G$ with a unit $e:G$, a multiplication $x,y\\mapsto x\\cdot y$, and an inverse operation $x\\mapsto x^{-1}$ satisfying the \\define{group laws}:\n\\begin{align*}\n(x\\cdot y)\\cdot z & =x\\cdot(y\\cdot z) & x^{-1}\\cdot x & = e \\\\\ne\\cdot x & = x & x\\cdot x^{-1} & = e. \\\\\nx\\cdot e & =x\n\\end{align*}\n\\end{defn}\n\n\\begin{defn}\nFor $n\\geq 1$, the \\define{$n$-th homotopy group} of a type $X$ at a base point $x:X$ consists of the type\n\\begin{equation*}\n|\\pi_n(X,x)| \\defeq \\trunc{0}{\\loopspace[n]{X,x}}\n\\end{equation*}\nequipped with the group operations inherited from the path operations on $\\loopspace[n]{X,x}$. \nOften we will simply write $\\pi_n(X)$ when it is clear from the context what the base point of $X$ is.\n\nFor $n\\jdeq 0$ we define $\\pi_0(X,x)\\defeq \\trunc{0}{X}$. \n\\end{defn}\n\n\\begin{eg}\nIn \\cref{cor:circle_loopspace} we established that $\\eqv{\\loopspace{\\sphere{1}}}{\\Z}$. It follows that\n\\begin{equation*}\n\\pi_1(\\sphere{1})=\\Z \\qquad\\text{ and }\\qquad\\pi_n(\\sphere{1})=0\\qquad\\text{for $n\\geq 2$.}\n\\end{equation*}\nFurthermore, we have seen in \\cref{circle_conn} that $\\trunc{0}{\\sphere{1}}$ is contractible. \nTherefore we also have $\\pi_0(\\sphere{1})=0$.\n\\end{eg}\n\n\\subsection{The Eckmann-Hilton argument}\n\nGiven a diagram of identifications\n\\begin{equation*}\n\\begin{tikzcd}[column sep=7em]\nx \\arrow[r,equals,bend left=60,\"p\",\"\"{name=A,below}] \\arrow[r,equals,\"\"{name=B},\"\"{name=E,below},\"{p'}\"{near end}] \\arrow[r,equals,bend right=60,\"{p''}\"{below},\"\"{name=F,above}] \\arrow[from=A,to=B,phantom,\"r\\Downarrow\"] \\arrow[from=E,to=F,phantom,\"{r'\\Downarrow}\"] \n& y\n\\end{tikzcd}\n\\end{equation*}\nin a type $A$, where $r:p=p'$ and $r':p'=p''$,\nwe obtain by concatenation an identification $\\ct{r}{r'}:p=p''$. This operation on identifications of identifications is sometimes called the \\define{vertical concatenation}, because there is also a \\emph{horizontal} concatenation operation.\n\n\\begin{defn}\nConsider identifications of identifications $r:p=p'$ and $s:q=q'$, where $p,p':x=y$, and $q,q':y=z$ are identifications in a type $A$, as indicated in the diagram\n\\begin{equation*}\n\\begin{tikzcd}[column sep=huge]\nx \\arrow[r,equals,bend left=30,\"p\",\"\"{name=A,below}] \\arrow[r,equals,bend right=30,\"\"{name=B,above},\"{p'}\"{below}] \\arrow[from=A,to=B,phantom,\"r\\Downarrow\"] & y \\arrow[r,equals,bend left=30,\"q\",\"\"{name=C,below}] \\arrow[r,equals,bend right=30,\"\"{name=D,above},\"{q'}\"{below}] \\arrow[from=C,to=D,phantom,\"s\\Downarrow\"] & z.\n\\end{tikzcd}\n\\end{equation*}\nWe define the \\define{horizontal concatenation} $\\ct[h]{r}{s}:\\ct{p}{q}=\\ct{p'}{q'}$ of $r$ and $s$.\n\\end{defn}\n\n\\begin{proof}\nFirst we induct on $r$, so it suffices to define $\\ct[h]{\\refl{p}}{s}:\\ct{p}{q}=\\ct{p}{q'}$. \nNext, we induct on $p$, so it suffices to define $\\ct[h]{\\refl{\\refl{y}}}{s}:\\ct{\\refl{y}}{q}=\\ct{\\refl{y}}{q'}$. \nSince $\\ct{\\refl{y}}{q}\\jdeq q$ and $\\ct{\\refl{y}}{q'}\\jdeq q'$, we take $\\ct[h]{\\refl{\\refl{y}}}{s}\\defeq s$. \n\\end{proof}\n\n\\begin{lem}\nHorizontal concatenation satisfies the left and right unit laws.\n\\end{lem}\n\nIn the following lemma we establish the \\define{interchange law} for horizontal and vertical concatenation.\n\n\\begin{lem}\nConsider a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}[column sep=7em]\nx \\arrow[r,equals,bend left=60,\"p\",\"\"{name=A,below}] \\arrow[r,equals,\"\"{name=B},\"\"{name=E,below}] \\arrow[r,equals,bend right=60,\"{p''}\"{below},\"\"{name=F,above}] \\arrow[from=A,to=B,phantom,\"r\\Downarrow\"] \\arrow[from=E,to=F,phantom,\"{r'\\Downarrow}\"] \n& y \\arrow[r,equals,bend left=60,\"q\",\"\"{name=C,below}] \\arrow[r,equals,\"\"{name=G,above},\"\"{name=H,below}] \\arrow[r,equals,bend right=60,\"\"{name=D,above},\"{q''}\"{below}] \\arrow[from=C,to=G,phantom,\"s\\Downarrow\"] \\arrow[from=H,to=D,phantom,\"{s'\\Downarrow}\"] & z.\n\\end{tikzcd}\n\\end{equation*}\nThen there is an identification\n\\begin{equation*}\n\\ct[h]{(\\ct{r}{r'})}{(\\ct{s}{s'})}=\\ct{(\\ct[h]{r}{s})}{(\\ct[h]{r'}{s'})}.\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nWe use path induction on both $r$ and $r'$, followed by path induction on $p$. Then it suffices to show that\n\\begin{equation*}\n\\ct[h]{(\\ct{\\refl{\\refl{y}}}{\\refl{\\refl{y}}})}{(\\ct{s}{s'})}=\\ct{(\\ct[h]{\\refl{\\refl{y}}}{s})}{(\\ct[h]{\\refl{\\refl{y}}}{s'})}.\n\\end{equation*}\nUsing the computation rules, we see that this reduces to\n\\begin{equation*}\n\\ct{s}{s'}=\\ct{s}{s'},\n\\end{equation*}\nwhich we have by reflexivity.\n\\end{proof}\n\n\\begin{thm}\nFor $n\\geq 2$, the $n$-th homotopy group is abelian.\n\\end{thm}\n\n\\begin{proof}\nOur goal is to show that \n\\begin{equation*}\n\\prd{r,s:\\pi_2(X)} r\\cdot s=s\\cdot r.\n\\end{equation*}\nSince we are constructing an identification in a set, we can use the universal property of $0$-truncation on both $r$ and $s$. Therefore it suffices to show that\n\\begin{equation*}\n\\prd{r,s:\\refl{x_0}=\\refl{x_0}} \\tproj{0}r\\cdot \\tproj{0}s=\\tproj{0}s\\cdot \\tproj{0}r.\n\\end{equation*}\nNow we use that $\\tproj{0}{r}\\cdot\\tproj{0}{s}\\jdeq \\tproj{0}{\\ct{r}{s}}$ and $\\tproj{0}{s}\\cdot\\tproj{0}{r}\\jdeq \\tproj{0}{\\ct{s}{r}}$, to see that it suffices to show that $\\ct{r}{s}=\\ct{s}{r}$, for every $r,s:\\refl{x}=\\refl{x}$. Using the unit laws and the interchange law, this is a simple computation:\n\\begin{align*}\n\\ct{r}{s} & = \\ct{(\\ct[h]{r}{\\refl{x}})}{(\\ct[h]{\\refl{x}}{s})} \\\\\n& = \\ct[h]{(\\ct{r}{\\refl{x}})}{(\\ct{\\refl{x}}{s})} \\\\\n& = \\ct[h]{(\\ct{\\refl{x}}{r})}{(\\ct{s}{\\refl{x}})} \\\\\n& = \\ct{(\\ct[h]{\\refl{x}}{s})}{(\\ct[h]{r}{\\refl{x}})} \\\\\n& = \\ct{s}{r}.\\qedhere\n\\end{align*}\n\\end{proof}\n\n\\subsection{Simply connectedness of the $2$-sphere}\n\n\\begin{defn}\nA pointed type $X$ is said to be \\define{$n$-connected} if its homotopy groups $\\pi_i(X)$ are trivial for $i\\leq n$. A $0$-connected type is also just called \\define{connected}, and a $1$-connected type is also called \\define{simply connected}. \n\\end{defn}\n\nWe write $\\ast$ for the base point of the sphere $\\sphere{n}$.\n\n\\begin{thm}\nFor any $n:\\N$ and any family $P$ of $n$-types over the $(n+2)$-sphere $\\sphere{n+2}$, the function\n\\begin{equation*}\n\\Big(\\prd{x:\\sphere{n+2}}P(x)\\Big)\\to P(\\ast)\n\\end{equation*}\ngiven by $f\\mapsto f(\\ast)$, is an equivalence.\n\\end{thm}\n\n\\begin{cor}\nThe $2$-sphere is simply connected.\n\\end{cor}\n\n\\begin{proof}\nOur goal is to show that $\\pi_1(\\sphere{2})$ is contractible. In other words, we have to show that $\\trunc{0}{\\loopspace{\\sphere{2}}}$ is contractible. We do this by constructing a term of type\n\\begin{equation*}\n\\prd{t:\\sphere{2}}\\iscontr(\\trunc{0}{\\ast=t}).\n\\end{equation*}\nFirst we note that\n\\begin{equation*}\n\\prd{t:\\sphere{2}}\\trunc{0}{\\ast=t}\n\\end{equation*}\nis equivalent to the type $\\trunc{0}{\\ast=\\ast}$, of which we have the term $\\tproj{0}{\\refl{\\ast}}$. Thus we obtain a dependent function $\\alpha:\\prd{t:\\sphere{2}}\\trunc{0}{\\ast=t}$ equipped with $\\alpha(\\ast)=\\tproj{0}{\\refl{\\ast}}$. Now we proceed to show that\n\\begin{equation*}\n\\prd{t:\\sphere{2}}{p:\\trunc{0}{\\ast=t}} \\alpha(t)=p\n\\end{equation*}\nby the dependent universal property of $0$-truncation. Therefore it suffices to construct a term of type\n\\begin{equation*}\n\\prd{t:\\sphere{2}}{p:\\ast=t}\\alpha(t)=\\tproj{0}{p}.\n\\end{equation*}\nThis is immediate by path induction and the fact that $\\alpha(\\ast)=\\tproj{0}{\\refl{\\ast}}$.\n\\end{proof}\n\n\\begin{exercises}\n\\item Show that the type of pointed families over a pointed type $(X,x)$ is equivalent to the type\n\\begin{equation*}\n\\sm{Y:\\UU_\\ast} Y\\to_\\ast X.\n\\end{equation*}\n\\item Given two pointed types $A$ and $X$, we say that $A$ is a (pointed) retract of $X$ if we have $i:A\\to_\\ast X$, a retraction $r:X\\to_\\ast A$, and a pointed homotopy $H:r\\circ_\\ast i\\htpy_\\ast \\idfunc^\\ast$. \n\\begin{subexenum}\n\\item Show that if $A$ is a pointed retract of $X$, then $\\loopspace{A}$ is a pointed retract of $\\loopspace{X}$. \n\\item Show that if $A$ is a pointed retract of $X$ and $\\pi_n(X)$ is a trivial group, then $\\pi_n(A)$ is a trivial group.\n\\end{subexenum}\n\\item Construct by path induction a family of maps\n\\begin{equation*}\n\\prd{A,B:\\UU}{a:A}{b:B} (\\id{\\pairr{A,a}}{\\pairr{B,b}})\\to \\sm{e:\\eqv{A}{B}}e(a)=b,\n\\end{equation*}\nand show that this map is an equivalence. In other words, an \\emph{identification of pointed types} is a base point preserving equivalence.\n\\item Let $\\pairr{A,a}$ and $\\pairr{B,b}$ be two pointed types. Construct by path induction a family of maps\n\\begin{equation*}\n\\prd{f,g:A\\to B}{p:f(a)=b}{q:g(a)=b} (\\id{\\pairr{f,p}}{\\pairr{g,q}})\\to \\sm{H:f\\htpy g} p = \\ct{H(a)}{q},\n\\end{equation*}\nand show that this map is an equivalence. In other words, an \\emph{identification of pointed maps} is a base point preserving homotopy.\n\\item Show that if $A\\leftarrow S\\rightarrow B$ is a span of pointed types, then for any pointed type $X$ the square\n\\begin{equation*}\n\\begin{tikzcd}\n(A\\sqcup^S B \\to_\\ast X) \\arrow[r] \\arrow[d] & (B \\to_\\ast X) \\arrow[d] \\\\\n(A\\to_\\ast X) \\arrow[r] & (S\\to_\\ast X)\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item \\label{ex:yoneda_ptd_types}Let $f:A\\to_\\ast B$ be a pointed map. Show that the following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\n\\item For any pointed type $X$, the precomposition map\n\\begin{equation*}\n\\blank\\mathbin{\\circ_\\ast}f:(B\\to_\\ast X)\\to_\\ast (A\\to_\\ast X)\n\\end{equation*}\nis an equivalence. \n\\end{enumerate}\n\\item In this exercise we prove the suspension-loopspace adjunction.\n\\begin{subexenum}\n\\item Construct a pointed equivalence\n\\begin{equation*}\n\\tau_{X,Y}:(\\susp(X)\\to_\\ast Y) \\eqvsym_\\ast (X\\to \\loopspace{Y})\n\\end{equation*}\nfor any two pointed spaces $X$ and $Y$.\n\\item Show that for any $f:X\\to_\\ast X'$ and $g:Y'\\to_\\ast Y$, there is a pointed homotopy witnessing that the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large]\n(\\susp(X')\\to_\\ast Y') \\arrow[r,\"\\tau_{X',Y'}\"] \\arrow[d,swap,\"h\\mapsto g\\circ h\\circ \\susp(f)\"] & (X'\\to_\\ast \\loopspace{Y'}) \\arrow[d,\"h\\mapsto\\loopspace{g}\\circ h\\circ f\"] \\\\\n(\\susp(X)\\to_\\ast Y) \\arrow[r,swap,\"\\tau_{X,Y}\"] & (X\\to_\\ast \\loopspace{Y})\n\\end{tikzcd}\n\\end{equation*}\n\\end{subexenum}\n\\item Show that if\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\nA \\arrow[r] & X\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square of pointed types, then so is\n\\begin{equation*}\n\\begin{tikzcd}\n\\loopspace{C} \\arrow[r] \\arrow[d] & \\loopspace{B} \\arrow[d] \\\\\n\\loopspace{A} \\arrow[r] & \\loopspace{X}.\n\\end{tikzcd}\n\\end{equation*}\n\\item \n\\begin{subexenum}\n\\item Show that if $X$ is $k$-truncated, then its $n$-th homotopy group $\\pi_n(X)$ is trivial for each choice of base point, and each $n> k$.\n\\item Show that if $X$ is $(k+l)$-truncated, and for each $0< i\\leq l$ the $(k+i)$-th homotopy groups $\\pi_{k+i}(X)$ are trivial for each choice of base point, then $X$ is $k$-truncated.\n\\end{subexenum}\nIt is consistent to assume that there are types for which all homotopy groups are trivial, but which aren't contractible nonetheless. Such types are called \\define{$\\infty$-connected}.\n\\end{exercises}\n", "meta": {"hexsha": "767a6eb8dd957cb101440837648c36096dd308eb", "size": 14934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/homotopy_groups.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/homotopy_groups.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/homotopy_groups.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": 47.2594936709, "max_line_length": 320, "alphanum_fraction": 0.6759742869, "num_tokens": 5447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744584140003, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6218885454048898}}
{"text": "\\chapter{Factor analysis}\n\\label{factanal}\n\n\\section{Role of factor analysis}\n\\label{rolefa}\n\nMost of the development of factor analysis has taken place outside the statistical community, most often in terms of Psychometrics which may partly reflect its origins in the study of intelligence.   The earliest cited reference is \\cite{Spearman:1904}.  Factor Analysis and Principal Components Analysis are often confused with each other, just to be really awkward there is one method of performing Factor Analysis called Principal Component Extraction.   The two methods should never be confused.   Principal Components seeks orthogonal projections of the data according the variance maximisation with the hope of achieving some dimension reduction.   Factor analysis is all about studying the co-variance (or correlation) and is based on a statistical model.  We hope to describe the covariance relationships between many variables in terms of a few underlying, unobservable random quantities called factors.   If there is a group of highly correlated variables, which in turn are uncorrelated with other variables, perhaps these represent realisations of some underlying phenomena that is responsible for for the observed correlations.   It is an attempt to approximate the covarariance matrix $\\boldsymbol{\\Sigma}$.  It is not highly regarded by many statisticians, but it is used by many others.   There are currently many variations on a theme (such as Structural Equation Modelling) which are also very common in many applied literatures.\n\n\n\nWhilst we can consider one model for factor analysis, there are two very different fitting methods, neither of which is entirely satisfactory.   Having found a solution there are a large number of possible rotations of the solution each of which aim to give the most interpretable solution.   In other words, don't be surprised if different computer programs give different ``Factor Analysis'' solutions for the same data.\n\n\n\\begin{figure}\n\\begin{picture}(100,200)(0,0)\n\n\\put(0,150){\\fbox{f1}}\n\\put(30,150){\\vector(2,-1){95}} \n\\put(30,150){\\vector(2,1){95}} \n\\put(30,150){\\vector(1,-1){95}} \n\n\\put(0,50){\\fbox{f2}}\n\\put(30,50){\\vector(2,-1){95}} \n\\put(30,50){\\vector(2,1){95}} \n\\put(30,50){\\vector(1,1){95}}  \n\n\\put(150,0){\\fbox{X1}}\n\\put(150,100){\\fbox{X2}}\n\\put(150,200){\\fbox{X3}}\n\n\\end{picture}\n\\caption{Factor analysis, dependence between three variables represented by two latent variables - is this sensible}\n\\end{figure}\n\nFactor Analysis is normally carried out with a view to reification: the investigator usually has a conceptual model of some underlying entity which cannot be measured directly.   These latent, or hidden, variables are the factors in factor analysis.   The aim of factor analysis is that each of the $p$ observed variables can be represented by means of $q<p$ mutually uncorrelated common factors.   This will leave some uncorrelated residual specific to each of the observed variables, the uniqueness, which is not correlated with any of the remaining $p-1$ variables \\footnote{Note that the diagonal of a correlation matrix is 1. This statement implies that only part of this 1 is due to the $q<p$ latent variables - this part is known as the communality.}.   It is possible to rotate the $q$ axes of common factors to new orthogonal or obligue axes to make the factor solution fit with existing theoretical ideas regarding the model.  \n\n\\section{The factor analysis model}\n\\label{factanalmodel}\n\nThe orthogonal model underlying Factor Analysis can be described as follows:\n\n\\begin{displaymath}\n\\label{factanal}\n\\boldsymbol{x} = \\boldsymbol{\\mu} + \\boldsymbol{\\Gamma} \\boldsymbol{\\phi} + \\boldsymbol{\\zeta}\n\\end{displaymath}\n\nWhere $\\boldsymbol{x}$ is an $1 \\times p$ random vector.   $\\boldsymbol{\\mu}$ represents a vector of unknown constants (mean values), $\\boldsymbol{\\Gamma}$ is an unknown $p \\times q$ matrix of constants referred to as the \\textit{loadings}.   $\\boldsymbol{\\phi}$ is a $q \\times 1$ unobserved random vector referred to as the \\textit{scores} assumed to have mean $\\boldsymbol{0}$ and covariance $\\boldsymbol{\\Sigma}_{\\phi}$, it is commonly assumed that $\\boldsymbol{\\Sigma}_{\\phi} = \\boldsymbol{I}$.   $\\boldsymbol{\\zeta}$ is $1 \\times p$ unobserved random error vector having mean $\\boldsymbol{0}$ and by assumption a diagonal covariance $\\boldsymbol{\\psi}$ referred to as the \\textit{uniqueness} or \\textit{specific variance}.   \n\nWith these assumptions, $cov(\\boldsymbol{\\phi}, \\boldsymbol{\\zeta}) = 0$, if $\\boldsymbol{\\Sigma}_{\\phi} = \\boldsymbol{I}$ then $cov(\\boldsymbol{x}, \\boldsymbol{\\phi}) = \\boldsymbol{\\Gamma}$.   It is worth emphasising that unlike many multivariate techniques covered here, factor analysis is a statistical model for our observations, with the following distributional form:\n\n\\begin{displaymath}\n\\boldsymbol{x} \\sim Normal(\\boldsymbol{\\mu}, \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi})\n\\end{displaymath}\n\nIt may be slightly clearer to consider the way a vector of observations $\\boldsymbol{x} = x_{1}, \\ldots, x_{p}$ are modelled in factor analysis:\n\n\\begin{eqnarray*}\nx_{1} &=& \\mu_{1} + \\sum_{k=1}^{q} \\gamma_{1k} \\phi_{k}  + \\zeta_{1}\\\\\nx_{2} &=& \\mu_{2} + \\sum_{k=1}^{q} \\gamma_{2k} \\phi_{k}  + \\zeta_{2}\\\\\n&\\vdots&\\\\\nx_{p} &=& \\mu_{p} + \\sum_{k=1}^{q} \\gamma_{pk} \\phi_{k}  + \\zeta_{p}\n\\end{eqnarray*}\n\nNote that under the terms of this model:\n\n\\begin{equation}\n\\label{communalities}\nvar(x_{j}) = \\gamma_{j1}^{2} + \\gamma_{j2}^{2} + \\ldots + \\gamma_{jq}^{2} + var(\\zeta_{j})\n\\end{equation} \n\nOne potential problem with this model should be immediately obvious, there can be rather more parameters than data.   For example, note that the covariance matrix $\\boldsymbol{\\Sigma}$ has $p(p+1)/2$ parameters, the factor model $ \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi})$ has $qp - q(q-1)/2 + p$ parameters.  One issue arises whereby a factor analsis model must be constrained in order to ensure identifiability.  Clearly, $p(p+1)/2 \\geq qp - q(q-1)/2 + p$, or:\n\n\\begin{equation}\n\\label{qp}\nq \\leq \\frac{2p + 1 - \\sqrt{8p-1}}{2}\n\\end{equation}\n\nThis gives some maximum values of $q$ for given values of $p$:\n\n\n\\begin{tabular}{rr}\n\\hline\n$p$ & max $q$ \\\\\n\\hline\n1 & 0\\\\\n2 & 0\\\\ \n3 & 1\\\\\n4 & 1\\\\\n5 & 2\\\\\n6 & 3\\\\\n7 & 3\\\\\n8 & 4\\\\\n9 & 5\\\\\n10 & 6\\\\\n\\hline\n\\end{tabular}\n\nWhere $q<p$, the right hand side of \\ref{communalities} indicates how much of $var(x_{j}$ is explained by the model, a concept referred to as the communality.   Consideration of the order of the model leads on to a point we will consider later, degrees of freedom after fitting a $q$ factor model:\n\n\\begin{equation}\n\\label{dffact}\ndf = \\frac{p(p+1)}{2} - qp + \\frac{q(q-1)}{2} - p = \\frac{(p-q)^{2} - (d+m)}{2}\n\\end{equation}\n\n\n\\subsection{Centred and standardised data}\n\nIn practice it is often much simpler to centre the data, so that we model:\n\n\\begin{equation}\n\\label{facentre}\nx_{j} - \\mu_{j} = \\sum_{k=1}^{q} \\gamma_{k} \\phi_{k} + \\zeta_{j}; j = 1, \\ldots, p\n\\end{equation}\n\nor even to standardise the variables so that in effect we are modelling the correlation matrix rather than the covariance matrix.   \n\n\\begin{equation}\n\\label{fastandardise}\n\\frac{x_{j} - \\mu_{j}}{\\sigma_{jj}} = \\sum_{k=1}^{q} \\gamma_{k} \\phi_{k} + \\zeta_{j}; j = 1, \\ldots, p\n\\end{equation}\n\n\nRegardless of the data matrix used, factor analysis is essentially a model for $\\boldsymbol{\\Sigma}$, the covariance matrix of $\\boldsymbol{x}$, \n\n\\begin{displaymath}\n\\label{covdecomp}\n\\boldsymbol{\\Sigma} = \\boldsymbol{\\Gamma}\\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi}\n\\end{displaymath}\n\n\\subsection{Factor indeterminacy}\n\nWe now consider another problem with factor analysis.   It is a very indeterminate model, specifically it is unchanged if we replace $\\boldsymbol{\\Gamma}$ by $\\boldsymbol{K} \\boldsymbol{\\Gamma}$ for any orthogonal matrix $\\boldsymbol{K}$.   However, this can be turned to our advantage, with sensible choice of a suitable orthogonal matrix $\\boldsymbol{K}$ we can achieve a rotation that may yield a more interpretable answer.  Factor analysis therefore requires an additional stage, having fitted the model we may wish to consider rotation of the coefficients.  \n\n\\subsection{Strategy for factor analysis}\n\n To fit the model, we therefore need to:\n\n\\begin{itemize}\n\\item Estimate the number of common factors $q$.   \n\\item Estimate the factor loadings $\\boldsymbol{\\Gamma}$\n\\item Estimate the specific variances $\\boldsymbol{\\psi}^{2}$\n\\item On occasion, estimate the factor scores $\\boldsymbol{\\phi}$\n\\end{itemize}\n\n\nWe will now consider fitting methods for factor analysis.   It will be obvious that the preferred method in R is the maximum likelihood method, but we will first consider methods based around principal components to reinforce some ideas about the model.\n\n\\section{Principal component extraction}\n\nWe have already used the spectral decomposition to obtain one possible factoring of the covariance matrix $\\boldsymbol{\\Sigma}$.\n\n\\begin{displaymath}\n\\boldsymbol{\\Sigma} = \\boldsymbol{E} \\boldsymbol{\\Lambda}\\boldsymbol{E}^{T}\n\\end{displaymath}\n\nwhich can be expanded:\n\n\\begin{eqnarray*}\n\\boldsymbol{\\Sigma} &=& \\lambda_{1} \\boldsymbol{e}_{1} \\boldsymbol{e}_{1}^{T} +  \\lambda_{2} \\boldsymbol{e}_{2} \\boldsymbol{e}_{2}^{T} + \\ldots  \\lambda_{p} \\boldsymbol{e}_{p} \\boldsymbol{e}_{p}^{T} \\\\\n &=& \\left( \\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1}, \\sqrt{\\lambda_{2}} \\boldsymbol{e}_{2}, \\ldots, \\sqrt{\\lambda_{p}} \\boldsymbol{e}_{p} \\right) \\left( \\begin{array}{c} \\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1} \\\\  \\sqrt{\\lambda_{2}} \\boldsymbol{e}_{2} \\\\ \\vdots \\\\  \\sqrt{\\lambda_{p}} \\boldsymbol{e}_{p} \\end{array} \\right)\n\\end{eqnarray*}\n\nOf course, in practice we don't know $\\boldsymbol{\\Sigma}$ and we use  $S$ (or we standardise the variables and use $R$ - it should be remembered that this is rather a big decision when working with principal components).   Referring back to our data, it should be remembered that the spectral decomposition yields linear principal components as follows:\n\n\\begin{eqnarray*}\nz_{1} &=& e_{11}x_{1} + e_{12}x_{2} + \\ldots + e_{1p} x_{p}; var(z_{1})=\\lambda_{1}\\\\\nz_{2} &=& e_{21}x_{2} + e_{22}x_{2} + \\ldots + e_{2p} x_{p}; var(z_{2})=\\lambda_{2}\\\\\n&\\vdots&\\\\\nz_{p} &=& e_{p1}x_{1} + e_{p2}x_{1} + \\ldots + e_{1p} x_{p}; var(z_{p})=\\lambda_{p}\n\\end{eqnarray*}\n\nwhich in matrix notation this can be expressed as: \n\n\\begin{equation}\n\\label{pcfact}\n\\boldsymbol{Z} = \\boldsymbol{E}\\boldsymbol{X}\n\\end{equation}\n\nwhere  $\\boldsymbol{Z} = \\left( \\begin{array}{c} z_{1} \\\\ z_{2} \\\\ \\vdots \\\\ z_{p} \\end{array} \\right)$,  $\\boldsymbol{X} = \\left( \\begin{array}{c} X_{1} \\\\ X_{2} \\\\ \\vdots \\\\ X_{p} \\end{array} \\right)$ and  $\\boldsymbol{E} = \\left( \\begin{array}{cccc} e_{11} & e_{12} & \\hdots & e_{1p} \\\\ \ne_{21}& e_{22} & \\hdots & e_{2p} \\\\\n \\vdots & \\vdots & \\ddots & \\vdots \\\\ \ne_{p1} & e_{p2} & \\hdots & e_{pp}  \\end{array} \\right)$.   \n\nMultiplying both sides of \\ref{pcfact} by $\\boldsymbol{E}^{-1}$gives:\n\n\\begin{equation}\n\\boldsymbol{E}^{-1} \\boldsymbol{Z} = \\boldsymbol{X}\n\\end{equation}\n\nWe know orthogonal matrices generally that $\\boldsymbol{E}^{-1} = \\boldsymbol{E}^{T}$ so we can invert the transformation by using\n\n\\begin{equation}\n\\boldsymbol{X} = \\boldsymbol{E}^{T} \\boldsymbol{Z}\n\\end{equation}\n\nwhich can be expanded as:\n\n\\begin{eqnarray*}\nx_{1} &=& e_{11}z_{1} + e_{21} z_{2}  + \\ldots + e_{p} z_{p}  \\\\\nx_{2} &=& e_{12}z_{2} + e_{22} z_{2} + \\ldots + e_{p} z_{p}  \\\\\n&\\vdots& \\\\\nx_{p} &=& e_{1p}z_{1} + e_{2p} z_{2} + \\ldots + e_{pp} z_{p}  \n\\end{eqnarray*}\n\nwhich we could express as;\n\n\\begin{eqnarray*}\nx_{1} &=& (e_{11} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{21} \\sqrt{\\lambda_{2}}) \\frac{z_{2}}{\\sqrt{\\lambda_{2}}} + \\ldots +  (e_{p1} \\sqrt{\\lambda_{p}}) \\frac{z_{p}}{\\sqrt{\\lambda_{p}}} \\\\\nx_{2} &=& (e_{12} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{12} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + \\ldots +  (e_{p2} \\sqrt{\\lambda_{p}}) \\frac{z_{p}}{\\sqrt{\\lambda_{p}}} \\\\\n&\\vdots& \\\\\nx_{p} &=& (e_{1p} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{2p} \\sqrt{\\lambda_{2}}) \\frac{z_{2}}{\\sqrt{\\lambda_{2}}} + \\ldots +  (e_{pp} \\sqrt{\\lambda_{p}}) \\frac{z_{p}}{\\sqrt{\\lambda_{p}}} \n\\end{eqnarray*}\n\nand if we set $\\gamma_{jk} = (e_{jk} \\sqrt{\\lambda_{j}})$ and $\\phi_{j} = z_{j} / \\sqrt{\\lambda_{j}}$ we have a clear link with the factor analysis model given in equation \\ref{factanal}.   If we try writing this in matrix terminology, our loadings matrix $\\boldsymbol{\\Gamma}$ is the $p \\times p$ matrix where the $j$th column is given by  $\\sqrt{\\lambda_{j}} \\boldsymbol{e}_{j}$ we now have:\n\n\\begin{displaymath}\n\\boldsymbol{S} = \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T}\n\\end{displaymath}\n\nwhich is getting us part of the way to our factor analysis model.   Before going any further we will reinforce this procedure by considering how to obtain these values from within R.  Note that under the principal component solution, the estimated loadings do not alter as the number of factors is increased or decreased. We are going to load the economic data, and carry out a decomposition of the correlation matrix $\\boldsymbol{R}$.\n\n\\singlespacing\n\\begin{verbatim}\n> econ <- read.csv(\"econ.csv\", row.names = 1)\n> econ.cor <- cor(econ)\n> econ.ev <- eigen(econ.cor)\n> loadings <- matrix(0,9,9)\n> for (i in 1:9){\n> loadings[,i] <- sqrt(econ.ev$values[i]) * econ.ev$vectors[,i]\n> }\n> econ.cor - loadings %*% t(loadings) ## should equal zero\n\\end{verbatim}\n\\onehalfspacing\n\n\n\nClearly we don't actually want to use a decomposition with with $q=p$ variables.   As might be rather obvious bearing in mind our earlier use of principal components, we wish to partition $\\boldsymbol{\\Lambda}$ into $\\boldsymbol{\\Lambda}_{1} = \\lambda_{1}, \\lambda_{2}, \\ldots, \\lambda_{q}$ and $\\boldsymbol{\\Lambda_{2}} = \\lambda_{q+1}, \\ldots, \\lambda_{p}$ with the corresponding eigenvectors.   As a consequence, we reduce the size of our $\\boldsymbol{\\Gamma}$ matrix, i.e. to neglect the contribution of  $\\lambda_{q+1} \\boldsymbol{e}_{q+1} \\boldsymbol{e}_{q+1}^{T} + \\ldots  \\lambda_{p} \\boldsymbol{e}_{p} \\boldsymbol{e}_{p}^{T}$.   So when considering our model for the data, we wish to partition our factors as follows:\n\n\\begin{eqnarray*}\nx_{1} &=& e_{11}z_{1} + e_{21} z_{2}  + \\ldots + e_{q1} z_{q} +  e_{q+1,1} z_{q+1} + \\ldots +  e_{p1} z_{p} \\\\\nx_{2} &=& e_{12}z_{2} + e_{22} z_{2} + \\ldots + e_{q2} z_{q} +  e_{q+1,2} z_{q+1} + \\ldots + e_{p2} z_{p} \\\\\n&\\vdots& \\\\\nx_{p} &=& e_{1p}z_{1} + e_{2p} z_{2} + \\ldots + e_{qp} z_{q} + e_{q+1,p} z_{q+1} + \\ldots + e_{pp} z_{p} \n\\end{eqnarray*}\n\nand if we set $ e_{q+1,j} z_{q+1} + \\ldots +  e_{pj} z_{p} = \\zeta_{j}; j = 1, \\ldots, p$ we can rewrite this as:\n\n\n\\begin{eqnarray*}\nx_{1} &=& e_{11} z_{1} + e_{21} z_{2} + \\ldots + e_{q1} z_{q} +  \\zeta_{1}\\\\\nx_{2} &=& e_{12} z_{1} + e_{22} z_{2} + \\ldots + e_{q2} z_{q} +  \\zeta_{2}\\\\\n&\\vdots& \\\\\nx_{p} &=& e_{1p} z_{1} + e_{2p} z_{1} + \\ldots + e_{qp} z_{q} + \\zeta_{p}\n\\end{eqnarray*}\n\nAs earlier, we can expressed this as:\n\n\\begin{eqnarray*}\nx_{1} &=& (e_{11} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{21} \\sqrt{\\lambda_{2}}) \\frac{z_{2}}{\\sqrt{\\lambda_{2}}} + \\ldots +  (e_{q1} \\sqrt{\\lambda_{q}}) \\frac{z_{q}}{\\sqrt{\\lambda_{q}}} +  \\zeta_{1}\\\\\nx_{2} &=& (e_{12} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{12} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + \\ldots +  (e_{q2} \\sqrt{\\lambda_{q}}) \\frac{z_{q}}{\\sqrt{\\lambda_{q}}} +  \\zeta_{2}\\\\\n&\\vdots& \\\\\nx_{p} &=& (e_{1p} \\sqrt{\\lambda_{1}}) \\frac{z_{1}}{\\sqrt{\\lambda_{1}}} + (e_{2p} \\sqrt{\\lambda_{2}}) \\frac{z_{2}}{\\sqrt{\\lambda_{2}}} + \\ldots +  (e_{qp} \\sqrt{\\lambda_{q}}) \\frac{z_{q}}{\\sqrt{\\lambda_{q}}} +  \\zeta_{p}\n\\end{eqnarray*}\n\nwhere $\\gamma_{jk} = (e_{jk} \\sqrt{\\lambda_{j}})$ and $\\phi_{i} = z_{i} / \\sqrt{\\lambda_{i}}$ as before, notice as stated at the outset that $var(\\boldsymbol{\\zeta}) = \\boldsymbol{\\psi}$.   If we consider this in terms of the decomposition of the covariance matrix we have:\n\n\\begin{equation}\n\\boldsymbol{\\Sigma} = \\left( \\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1}, \\sqrt{\\lambda_{2}} \\boldsymbol{e}_{2}, \\ldots, \\sqrt{\\lambda_{q}} \\boldsymbol{e}_{q} \\right) \\left( \\begin{array}{r} \\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1} \\\\  \\sqrt{\\lambda_{2}} \\boldsymbol{e}_{2} \\\\ \\vdots \\\\  \\sqrt{\\lambda_{q}} \\boldsymbol{e}_{q} \\end{array} \\right) + \n\\left[ \\begin{array}{rrrr} \\psi_{1} & 0 & \\hdots & 0\\\\\n0 & \\psi_{2} & \\hdots & 0\\\\\n\\vdots & \\vdots & \\ddots & \\vdots\\\\\n0 & 0 & \\hdots & \\psi_{p}\n\\end{array} \\right]\n\\end{equation}\n\nWhere now $\\psi_{j} = var(\\zeta_{j}) =  \\sigma_{jj} - \\sum_{k=1}^{q} \\gamma_{jk}^{2}$ for $k = 1, 2, \\ldots, q$. \n\nEstimates of the specific variances are given by diagonal elements of the matrix $\\boldsymbol{\\hat{\\Sigma}} - \\boldsymbol{\\hat{\\Gamma}}\\boldsymbol{\\hat{\\Gamma}}^{T}$, i.e:\n\n\\begin{equation}\n\\boldsymbol{\\hat{\\psi}} = \n\\left[ \\begin{array}{rrrr} \\psi_{1} & 0 & \\hdots & 0\\\\\n0 & \\psi_{2} & \\hdots & 0\\\\\n\\vdots & \\vdots & \\ddots & \\vdots\\\\\n0 & 0 & \\hdots & \\psi_{p}\n\\end{array} \\right]\n\\mbox{with}  \\psi_{j} = \\sigma_{jj} - \\sum_{k=1}^{q} \\gamma_{jk}^{2}\n\\end{equation}\n\n\n\nSo, when using the principal component solution of $\\boldsymbol{\\hat{\\Sigma}}$, it is specified in terms of eigenvalue-eigenvector pairs ($\\hat{\\lambda}_{1}, \\hat{\\boldsymbol{e}}_{1}$), ($\\hat{\\lambda}_{2}, \\hat{\\boldsymbol{e}}_{2}$), $\\ldots$, ($\\hat{\\lambda}_{p}, \\hat{\\boldsymbol{e}}_{p}$), where $\\hat{\\lambda}_{1} \\geq \\hat{\\lambda}_{2} \\geq \\ldots \\geq \\hat{\\lambda}_{p}$.   If we wish to find a $q<p$ solution of common factors, then the estimated factor loadings are given by:\n\n\\begin{displaymath}\n\\boldsymbol{\\hat{\\Gamma}} = \\left( \\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1}, \\sqrt{\\lambda_{2}} \\boldsymbol{e}_{2}, \\ldots, \\sqrt{\\lambda_{q}} \\boldsymbol{e}_{q} \\right) \n\\end{displaymath}\n\nAs with the factor analysis model given earlier, the factors $\\boldsymbol{\\phi}$ have identity covariance matrix\n\n\\begin{displaymath}\nvar(\\boldsymbol{\\phi}) = var \\left(\\sqrt{\\Lambda_{1}} \\boldsymbol{\\Gamma}_{1}^{T}(\\boldsymbol{x} - \\boldsymbol{\\mu}) \\right) = \\boldsymbol{I}_{q},\n\\end{displaymath}\n\n and are uncorrelated with the residuals:\n\n\\begin{displaymath}\ncov(\\boldsymbol{\\phi}, \\boldsymbol{\\zeta}) = cov \\left( \\sqrt{\\Lambda_{1}} \\boldsymbol{\\Gamma}_{1}^{T}(\\boldsymbol{x} - \\boldsymbol{\\mu}),  \\boldsymbol{\\Gamma}_{2}\\boldsymbol{\\Gamma}_{2}^{T}(\\boldsymbol{x} - \\boldsymbol{\\mu}) \\right) = \\sqrt{\\boldsymbol{\\Lambda_{1}}} \\boldsymbol{\\Gamma}_{1}^{T} \\boldsymbol{\\Sigma} \\boldsymbol{\\Gamma}_{2} \\boldsymbol{\\Gamma}_{2}^{T} = 0\n\\end{displaymath}\n\nHowever, one major objection to this principal component ``solution'' is that it can also be seen that each $\\zeta_{i}$ contains the same $z_{i}$ so they are not mutually unrelated.   Hence the latent variables obtained using the principal component method do not explain all the correlation structure in our data $\\boldsymbol{X}$.   The covariance matrix for the errors is now:\n\n\\begin{displaymath}\nvar(\\boldsymbol{\\zeta}) = \\boldsymbol{\\Gamma}_{2} \\boldsymbol{\\Lambda}_{2} \\boldsymbol{\\Gamma}_{2}^{T}\n\\end{displaymath}\n\n\nThis additional step can be carried out fairly easily in R.   We only need to discard the unwanted components and estimate the uniquenesses:\n\n\\singlespacing\n\\begin{verbatim}\n> loadings4 <- matrix(0,9,4)\n> for (i in 1:4){\n> loadings4[,i] <- sqrt(econ.ev$values[i]) * econ.ev$vectors[,i]\n> }\n> LLt <- loadings4 %*% t(loadings4)\n> unique <- diag(econ.cor - LLt)\n> error <- econ.cor - (LLt + unique)\n\\end{verbatim}\n\\onehalfspacing\n\nand so \\texttt{loadings4} gives us the matrix of loadings, \\texttt{unique} gives us an estimate of the uniquenesses.  It should be noted that the loadings are unaltered as the number of factors $q$ is changed.   It may be noted that the diagonal elements of $\\boldsymbol{\\hat{\\Sigma}}$ are given by the diagonal elements of $\\boldsymbol{\\Gamma}\\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi}$, but this is not true of the off-diagonal elements.  There are error terms associated with our decomposition of the covariance matrix, these can be easily found from \\texttt{error}.  Clearly these are values we wish to see minimised. \n\nWe will consider interpretation of factor structure in more detail later.   However, for now it may be of interest to examine the four factor solution.   It would appear that the first factor represents some kind of contrast between agriculture and other industries (with the exception of finance and mining).\n\n\\singlespacing\n\\begin{verbatim}\n\\loadings4\n                                   [,1]        [,2]        [,3]        [,4]\nAgriculture                -0.978199871 -0.07760625  0.05173168 -0.02899271\nMining                     -0.002342834 -0.90214224 -0.21179672 -0.06592893\nManufacture                 0.645370678 -0.52159027 -0.15703856  0.34982446\nPowerSupplies               0.476333161 -0.37897538 -0.58769654 -0.39731951\nConstruction                0.608061420 -0.07694001  0.15838634  0.66387307\nServiceIndustries           0.707975893  0.51045159 -0.12126845  0.05137022\nFinance                     0.138717720  0.66237521 -0.61559512  0.05147600\nSocialAndPersonalServices   0.723602099  0.32374238  0.32749903 -0.40851903\nTransportAndCommunications  0.684640120 -0.29451591  0.39342807 -0.31637790\n\\end{verbatim}\n\\onehalfspacing\n\n\\subsection{Diagnostics for the factor model}\n\nWe can define a residual matrix as:\n\n\\begin{equation}\n\\boldsymbol{\\epsilon} = \\boldsymbol{{S}} - \\left(\\boldsymbol{L}\\boldsymbol{L}^{T} + \\boldsymbol{\\psi} \\right)\n\\end{equation}\n\nBy construction, the diagonal elements of this residual matrix will be zero.   A decision to retain a particular $q$ factor model could be made depending on the size of the off-diagonal elements.   Rather conveniently, there is an inequality which gives us:\n\n\\begin{equation}\n\\left[ \\boldsymbol{\\epsilon} = \\boldsymbol{\\hat{\\Sigma}} - \\left(\\boldsymbol{L}\\boldsymbol{L}^{T} + \\boldsymbol{\\psi} \\right) \\right] \\leq \\hat{\\lambda}_{q+1}^{2} + \\cdots + \\hat{\\lambda}_{p}^{2}\n\\end{equation}\n\nSo it is possible to check the acceptability of fit in terms of a small sum of squares of neglected eigenvalues.\n\nIn a similar manner to that used in principal components, it is possible to use the eigenvalues to indicate the proportion of variance explained by any given factor.   So instead of examining discarded components we could examine those we intend to retain.   Bearing in mind that $trace(\\boldsymbol{\\Sigma} = \\sigma_{11} + \\sigma_{22} + \\ldots + \\sigma_{pp}$, we know that the amount of variation explained by the first factor $\\gamma_{11}^{2} + \\gamma_{21}^{2} + \\ldots + \\gamma_{p1}^{2} = (\\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1})^{T}(\\sqrt{\\lambda_{1}} \\boldsymbol{e}_{1}) = \\lambda^{1}$.\n\nSo we know that the $j$-th factor explains the following proportion of total sample variance:\n\n\\begin{equation}\n\\frac{\\lambda_{j}}{trace(\\boldsymbol{S})}\n\\end{equation}\n\nwhich reduces to $\\frac{\\lambda_{j}}{p}$ when using standardised variables (the correlation matrix).\n\nIt is actually in the context of factor analysis that the Kaiser criterion was developed.   This is implemented by default in a number of computer programs, basically we retain factors which are explaining more than the average amount of variance; if we are decomposing the correlation matrix we retain all factors where the corresponding eigenvalues are greater than one.   We can consider the number of components to retain from our earlier eigen analysis.   The following R output gives the eigenvalues, and the proportion and cumulating proportion explained by each possible factor.\n\n\\singlespacing\n\\begin{verbatim}\n> econ.ev$values\n[1]  3.482820 2.132332 1.098373 0.9984261 0.5450933\n[6] 0.3836385 0.2224905 0.1367327 0.0000930\n \n> econ.ev$values / 0.09\n[1] 38.698003578 23.692581759 12.204146983 11.093622860  6.056592340\n[6]  4.262650255  2.472116648  1.519252072  0.001033506\n\n> cumsum(econ.ev$values/0.09)\n[1]  38.69800  62.39059  74.59473  85.68836  91.74495  96.00760  98.47971\n[8]  99.99897 100.00000\n\\end{verbatim}\n\\onehalfspacing\n\nConsidering the eigenvalues first, using the Kaiser criterion would lead us to select three components, but it should be noted that the fourth component is only just below 1 (0.998) giving perhaps some warning as to the arbitrariness of this device.   There are 9 variables, so we divide by 9 (and multiply by 100 to express the proportions as a percentage).   Cumulative values are also given.   We require five components to explain over 90\\% of the variation.   Remember that according to formula \\ref{qp} this is the largest value of $q$ that can be contemplated with nine manifest variables.\n\n\n\\subsection{Communalities}\n\nAnother important concept are the communalities.   In the case of standardised variables, these indicate the proportion of variance of a manifest variable explained by its relevant factor structure.   These are simply estimated as:\n\n\\begin{equation}\n\\xi_{jk}^{2} = \\gamma_{j1}^{2} +  \\gamma_{j2}^{2} + \\cdots +  \\gamma_{jq}^{2}\n\\end{equation}\n\nTerminology can now be supplied for the decomposition of the variance of $\\boldsymbol{x}$ given earlier in \\ref{communalities} to reflect the reduced dimensionality.   \n\n\\begin{equation}\n\\label{communality}\nvar(x_{j}) = \\underbrace{\\gamma_{j1}^{2} + \\gamma_{j2}^{2} + \\ldots + \\gamma_{jq}^{2}}_{communality\\ of\\ x_{j}} + \\underbrace{\\psi_{i}}_{specificity\\ of\\ x_{j}}\n\\end{equation} \n\nFor standardised variables, $var(x_{j}) = 1$, therefore: $\\gamma_{i1}^{2} + \\gamma_{i2}^{2} + \\ldots + \\gamma_{i1}^{q} \\leq 1$ and $-1 \\leq \\gamma_{jk} \\leq 1$.\n\nThese are fairly simply extracted from our matrix of loadings by squaring all entries and summing by row:\n\n\\singlespacing\n\\begin{verbatim}\n> row.names(loadings4) <- row.names(econ.cor)\n> apply(loadings4^2, 1, sum)\n               Agriculture                     Mining \n                 0.9664145                  0.8630706 \n               Manufacture              PowerSupplies \n                 0.8355980                  0.8737656 \n              Construction          ServiceIndustries \n                 0.8414721                  0.7791356 \n                   Finance  SocialAndPersonalServices \n                 0.8395906                  0.9025525 \nTransportAndCommunications \n                 0.8103523 \n\\end{verbatim}\n\\onehalfspacing\n\n\nThese appear to be reasonably high for most variables which would suggest a plausible fit for the factor model.\n\n\n\\subsection{Principal Factor solution}\n\nWe might have been worried about the way our model above doesn little to account for the off-diagonal elements of $\\boldsymbol{\\hat{\\Sigma}}$.   Principal factoring (which seems to have rather fewer advocates) considering decomposing a reduced matrix.   We know that the diagonal elements of our covariance matrix are given by $\\sigma_{jj} = \\xi_{j}^{2} + \\psi_{j}$, so having determined the number $q$ of common factors needed, we can decompose the reduced covariance matrix.   If we obtain some initial estimates of $\\boldsymbol{\\psi}$, we can re-estimate the remaining part of the decomposition $\\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T}$.\n\n\\begin{equation}\n\\sigma_{jj} = \\xi_{j}^{2} + \\psi_{j}\n\\end{equation}\n\nIf we had some initial estimate of $\\boldsymbol{\\psi}$, $\\widetilde{\\boldsymbol{\\psi}}$ say,  we could obtained a ``reduced'' covariance matrix\n\n\\begin{displaymath}\n\\boldsymbol{S} = \\left( \\begin{array}{rrrr}\n\\widetilde{\\xi}_{1}^{2} & s_{12} & \\cdots & s_{1p}\\\\\ns_{21} & \\widetilde{\\xi}_{2}^{2} & \\cdots & s_{2p}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\ns_{p1} & s_{p2} & \\cdots & \\widetilde{\\xi}_{p}^{2}\n\\end{array} \\right) \n\\end{displaymath}\nand carry out an eigendecomposition of this matrix, updating our estimates of the uniqueness and repeat until convergence.\n\nSo all we need is an initial estimate of $\\widetilde{\\boldsymbol{\\psi}}$.   Many programs conduct a multiple regression of each manifest variable on each other, and use $s_{jj} r_{j}^{2}$.   We then conduct a principal component analysis on $\\boldsymbol{S} - \\boldsymbol{\\psi}$to find $\\boldsymbol{\\Gamma}$.   $\\boldsymbol{\\psi}$ can then be recalculated as the diagonal of $\\boldsymbol{S} - \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T}$ and we extract a further set of principal components.   These latter steps are repeated until convergence, which can be slow if it happens at all.   As we are working with the correlation matrix, it's easy enough to find these intial values:\n\n\\singlespacing\n\\begin{verbatim}\n> r2s <- vector(\"numeric\", 9)\n> \n> for (i in 1:9){\n+ y <- econ[,i]\n+ x <- econ[,-i]\n+ mod <- lm(y~as.matrix(x))\n+ r2s[i] <- summary(mod)$r.squared\n+ }\n> \n> \n> unique <- diag(1-r2s)\n> diag(unique)\n[1] 0.0001429627 0.0420230140 0.0006887118 0.1325518542 0.0138610514\n[6] 0.0016432160 0.0043879128 0.0007569780 0.0161276459\n\\end{verbatim}\n\\onehalfspacing\n\nAnd all that is now required is to repeatedly implement the loop stage.   This is presented as a function in \\texttt{mvmmisc.R}, but it is worth pasting through this manually to see how the procedure works.   \n\n\\singlespacing\n\\begin{verbatim}\n> new <- econ.cor - unique\n> new.ev <- eigen(new)\n> \n> loadings4pf <- matrix(0,9,4)\n> for (i in 1:4){\n+ loadings4pf[,i] <- sqrt(new.ev$values[i]) * new.ev$vectors[,i]\n+ }\n> \n> LLt <- loadings4pf %*% t(loadings4pf)\n> \n> unique.f <- econ.cor - LLt\n> diag(unique) <- diag(unique.f)\n> \n> diag(unique)\n[1] 0.02890147 0.14965321 0.15824274 0.25101144 0.14818053 0.21896192 0.15269320\n[8] 0.09280381 0.20001567\n> \n> loadings4pf\n              [,1]        [,2]        [,3]         [,4]\n [1,] -0.980556270 -0.06951113  0.06899117 -0.004043332\n [2,] -0.007596438 -0.88584019 -0.20248258  0.156770695\n [3,]  0.644457570 -0.53242421 -0.27602489 -0.258391989\n [4,]  0.453749164 -0.35005068 -0.40926760  0.503055476\n [5,]  0.607710009 -0.08927793 -0.03546047 -0.687953501\n [6,]  0.711408766  0.50862889 -0.12606387 -0.018444548\n [7,]  0.140377243  0.67201322 -0.59955488  0.128581528\n [8,]  0.727082131  0.31778092  0.43171651  0.301966740\n [9,]  0.681111481 -0.30230726  0.45690884  0.189515460\n\\end{verbatim}\n\\onehalfspacing\n\nIt should be noted that in addition to slow (or no) convergence, different results will be obtained depending on whether correlation or covariance matrix is used.  However, this approach does not require any distributional assumptions so may be of some use of multivariate normality cannot be claimed, even by refuge to the central limit theorem.   \\cite{Harmon:1967} does indicate further fundamental differences between the principal component and this solution.\n\nLittle more needs to be said about this method of factor analysis, we now turn our attention to a more promising approach, maximum likelihood.\n\n\n\\section{Maximum likelihood solutions}\n\\label{mlfact}\n\nObvious conclusions might be drawn by noting that R only offers this method of fitting factor analysis models, see the helpfile for the relevant function \\texttt{?factanal} as well as \\cite{Venables+Ripley:2002}.   It should be noted from the outset that this method is invariant to changes in scale, a proof given in \\cite{Seber:1984}.   In other words, it doesn't matter whether the correlation or the covariance matrix are used, or indeed whether any other scale changes are applied.   There are a number of other advantages associated with maximum likelihood fitting, but the problem of Heywood cases still remains, whereby some of the unique variances are estimated with a negative value.   \n\nWe also need to impose an additional assumption over and above the factor analysis assumptions set out earlier, namely that the following matrix:\n\n\\begin{equation}\n\\label{diagconstraint}\n\\boldsymbol{\\Gamma}^{T} \\boldsymbol{\\Psi}^{-1} \\boldsymbol{\\Gamma}\n\\end{equation}\n\nmust be diagonal to enable model fitting.   Having fitted the model, as we will find out later we are free to rotate the solution.\n\n\nIf the maximum likelihood method is so superior, the obvious question arises as to either of the principal component based methods have remained in use for so long.   There is in fact a long and far from trouble free history in terms of trying to develop a maximum likelihood solution for factor analysis, details of an earlier approach to maximum likelihood fitting are given in \\cite{Morrison:1976}.   In any case, we well assume that our data follows a multivariate normal distribution, which will have the following likelihood:\n\n\\begin{equation}\n\\label{mvnlike}\nL(\\boldsymbol{x}; \\boldsymbol{\\mu}, \\boldsymbol{\\Sigma}) = (2 \\pi)^{-\\frac{np}{2}} |\\boldsymbol{\\Sigma}|^{-\\frac{n}{2}} e^{-\\frac{1}{2}tr\\left( \\boldsymbol{\\Sigma}^{-1} ( \\sum_{i=1}^{n}(\\boldsymbol{x}_{i} - \\boldsymbol{\\bar{x}})(\\boldsymbol{x}_{i} - \\boldsymbol{\\bar{x}})^{T} + n(\\boldsymbol{\\bar{x}} - \\boldsymbol{\\mu})(\\boldsymbol{\\bar{x}} - \\boldsymbol{\\mu})^{T} ) \\right)}\n\\end{equation}\nwe wish to solve this in terms of our factor analysis model and therefore need to find an expression for the likelihood of $L((\\boldsymbol{x}; \\boldsymbol{\\mu}, \\boldsymbol{\\Gamma}, \\boldsymbol{\\psi})$.   \n\n$\\boldsymbol{\\mu}$ is a nuisance parameter for our purposes here, we can either get rid of it by using the estimate $\\boldsymbol{\\hat{\\mu}} = \\boldsymbol{\\bar{x}}$ and hence use the profile likelihood to find $\\boldsymbol{\\hat{\\Gamma}}$ and  $\\boldsymbol{\\hat{\\psi}}$ , or we can factorise the likelihood as  $L(\\boldsymbol{S}; \\boldsymbol{\\bar{x}}, \\boldsymbol{\\Sigma}) L(\\boldsymbol{\\bar{x}}; \\boldsymbol{\\mu}, \\boldsymbol{\\Sigma})$.   In this latter case, $\\boldsymbol{bar{x}}$ and $\\boldsymbol{S}$ are the joint sufficient statistics for $\\boldsymbol{\\mu}$ and $\\boldsymbol{\\Sigma}$ respectively, for the purposes of factor analysis we only require the first part of the factorised likelihood which can be estimated by conditional maximum likelihood.   Note that as $\\boldsymbol{bar{x}}$ and $\\boldsymbol{S}$ are independent this is also the marginal likelihood.\n\nTaking logs of \\ref{mvnlike}, and collecting constant terms into $c_{1}$ and $c_{2}$ we can say that we wish to maximise:\n\n\\begin{equation}\n\\label{fall}\n\\ln L = c_{1} - c_{2} \\left( \\ln |\\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi}| + trace(\\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi})^{-1}\\boldsymbol{S} \\right)\n\\end{equation}\n\nBy taking this likelihood, along with the diagonality contraints indicated in \\ref{diagconstraint} all we need is a procedure for estimation.   \n\nAn intial estimate of $\\widetilde{\\boldsymbol{\\psi}}$ has to be made as before, \\cite{Lawley+Maxwell:1971} give maximum likelihood solutions for the uniquenesses.  \\cite{Joreskog:1967}  noted that for fixed $\\boldsymbol{\\psi}>0$, the likelihood equations require:\n\n\\begin{equation}\n\\boldsymbol{\\hat{\\Gamma}} = \\sqrt{\\boldsymbol{\\psi}} \\boldsymbol{E}_{1} \\sqrt{(\\boldsymbol{\\Lambda}_{1} - \\boldsymbol{I})}\n\\end{equation}\n\nwhere $\\boldsymbol{\\Lambda}_{1}$ contains the $q$ largest eigenvalues of $\\sqrt{\\boldsymbol{\\psi}} \\boldsymbol{S} \\sqrt{\\boldsymbol{\\psi}}$, and  $\\boldsymbol{E}_{1}$ the corresponding eigenvectors.   This is used to estimate $\\boldsymbol{\\hat{\\Gamma}}$ given a value of $\\boldsymbol{\\hat{\\psi}}$.   Now, the log likeihood is maximised with respect to $\\boldsymbol{\\hat{\\psi}}$ given an estimate of  $\\boldsymbol{\\hat{\\Gamma}}$.\n\nAs stated, this method is implemented in R, and therefore it is quite easy to try to fit a model to our economics data:\n\n\\singlespacing\n\\begin{verbatim}\n> econ <- read.csv(\"econ.csv\", row.names = 1)\n> econ.fact <- factanal(econ, factors = 4, rotation = \"none\")\n\\end{verbatim}\n\\onehalfspacing\n\n\nWe can consider the residual matrix for our maximum likelihood solution\n\n\\singlespacing\n\\begin{verbatim}\n> loadml <- loadings(econ.fact)\n> class(loadml) <- \"matrix\"\n> uniqueml <- econ.fact$uniquenesses\n> resid <- econ.cor - ( loadml%*% t(loadml) + diag(uniqueml) )\n> resid\n\\end{verbatim}\n\\onehalfspacing\n\nIt will be seen that these are considerably smaller than those residuals obtained from the principal component method used earlier.   One gain from using the maximum likelihood method is that classical multivariate work provide a test for the adequacy of model fit.   If take our null hypothesis as belief that our factor analysis model is an adequate representation of the covariance matrix we will test the following:\n\n\\begin{eqnarray*}\nH_{0}&:& \\boldsymbol{\\Sigma} = \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi}\\\\\nH_{1}&:&  \\boldsymbol{\\Sigma}\\ is\\ any\\ other\\ positive\\ definite\\ matrix\n\\end{eqnarray*}\n\nThis (eventually) yields a likelihood ratio statistic:\n\n\\begin{equation}\n-2 \\ln \\Lambda = -2 \\ln \\left(  \\frac{|\\boldsymbol{\\hat{\\Sigma}}|}{|\\boldsymbol{S}|} \\right) + n \\left( tr(\\boldsymbol{\\hat{\\Sigma}}^{-1}\\boldsymbol{S}) - p \\right)\n\\end{equation}\n\nwith $\\frac{1}{2} \\left( (p-q)^{2} - p - q \\right)$ degrees of freedom.\n\nIt can be shown (not here) that $ tr(\\boldsymbol{\\hat{\\Sigma}}^{-1}\\boldsymbol{S}) - p = 0$ at the maximum likelihood  so this term can be removed and we can consider that\n\n\\begin{equation}\n\\label{faqtest}\n-2 \\ln \\Lambda = n \\ln \\left(  \\frac{|\\boldsymbol{\\hat{\\Sigma}}|}{|\\boldsymbol{S}|} \\right)\n\\end{equation}\n\nAll that remains is to add a correction suggested by \\cite{Bartlett:1951,Bartlett:1954}.   We need to replace $n$ with something slightly more elaborate, the exact formula chosen varies amongst many multivariate tests, in the current R function the correction applied is:\n\n\\begin{displaymath}\nn - 1 - \\frac{2p + 5}{6} - \\frac{2q}{3}\n\\end{displaymath}\n\n%JW $n - 1 - \\frac{(2p + 4q + 5)}{6}$.\n%WK $n - \\frac{2p + 11}{6} - \\frac{2q}{3}$\n\nHence we are going to test:\n\n\\begin{equation}\nn - 1 - \\frac{2p + 5}{6} - \\frac{2q}{3} \\ln  \\left(  \\frac{|\\boldsymbol{\\hat{\\Gamma}} \\boldsymbol{\\hat{\\Gamma}}^{T} + \\boldsymbol{\\hat{\\psi}}|}{|\\boldsymbol{S}|} \\right) > \\chi^{2}_{\\left((p-q)^{2} - p - q \\right) / 2, \\alpha}\n\\end{equation}\n\nThe idea might be to start with $q$ small (anticipating the rejection of $H_{0}$), and increase $q$ until $H_{0}$ is no longer rejected.   As with all such tests, there are many reasons for rejecting $H_{0}$, not all of these may concern us.   In addition, \\cite{Johnson+Wichern:2002} suggest that if $n$ is large and $q$ is small relative to $p$, it will tend to reject $H_{0}$ even though $\\boldsymbol{\\hat{\\Sigma}}$ is close to $\\boldsymbol{S}$.  So the situation can arise whereby we can claim ``statistical significance'' for the inclusion of additional factors in our model, but they actually add little to the model.   This tends to reinforces the exploratory aspects of multiviariate analysis (for some sense of exploratory).\n\nWe can extract the communalities from our model as easily as before:\n\n\\singlespacing\n\\begin{verbatim}\n> apply(loadml^2, 1, sum)\n               Agriculture                     Mining \n                 0.9954167                  0.5937541 \n               Manufacture              PowerSupplies \n                 0.9950263                  0.9950022 \n              Construction          ServiceIndustries \n                 0.4852833                  0.8360147 \n                   Finance  SocialAndPersonalServices \n                 0.4786655                  0.9950786 \nTransportAndCommunications \n                 0.4676025 \n\\end{verbatim}\n\\onehalfspacing\n\nThe R output has already given us information on the proportion of variance explained by each of the factors:\n\n\\singlespacing\n\\begin{verbatim}\n               Factor1 Factor2 Factor3 Factor4\nSS loadings      3.270   1.519   1.189   0.864\nProportion Var   0.363   0.169   0.132   0.096\nCumulative Var   0.363   0.532   0.664   0.760\n\\end{verbatim}\n\\onehalfspacing\n\nsuggesting that 76\\% of variation is explained by our four factors (under the maximum likelihood solution).   We reckoned on 10\\% points more for the principal component solution.   This  would be expected due the variance maximising properties of principal components generally (whether used appropriately or for factor analysis).\n\n\nIt is now important to turn our attention to rotation.   The maximum likelihood solution is constrained by the diagonality constraint, and it is particularly important here that rotations are considered.\n\n\n\\section{Rotation}\n\\label{rotfa}\n\nIt was stated earlier that one of the potential disadvantages of factor analysis was a certain rotational indeterminancy, indeed in the maximum likelihood fitting method it is necessary to add a constraint specifically deal with this.   We are now going to consider one of the benefits of rotation; to yield a more interpretable factor structure.   In short, we seek a rotation: \n\n\\begin{equation}\n\\boldsymbol{\\hat{\\Gamma}}^{(R)} = \\boldsymbol{\\hat{\\Gamma}} \\boldsymbol{T}\n\\end{equation}\nsuch that we obtain easy-to-interpret factor loadings.   One definition of ``easy'' is that where possible some components would be large, others small.   The most obvious way to do this is actually to carry out the exercise by eye, and to rotate the axes around the origin so that some factor loadings become small.   It is also easy to suggest a two dimensional rotation matrix:\n\n\\begin{displaymath}\n\\boldsymbol{T} = \\left( \\begin{array}{rr} \\cos \\phi & \\sin \\phi \\\\\n- \\sin \\phi & \\cos \\phi \\end{array} \\right)\n\\end{displaymath}\n\nfor rotation angle $\\phi; -\\pi \\leq \\phi \\leq \\phi$.   All we need to do is find a suitable value for $\\phi$.   This becomes slightly more difficult in every sense where $q>2$, indeed it is possible to carry out the whole procedure by eye with pencil and paper (do you remember what they are).\n\n\nFor orthogonal rotations, two objective criteria are most commonly used to determine the optimal rotation: the Varimax procedure \\citep{Kaiser:1958} and the Quartimax procedure \\cite{Neuhaus+Wrigley:1954}.   The former is currently available within R and will be considered here, as usual it is worth checking the definitive entry in \\texttt{?varimax}.   This looks for a rotation which maximises the objective V:\n\n\\begin{equation}\nV = \\frac{1}{p^{2}} \\sum_{k=1}^{q} \\left( p \\sum_{j=1}^{p} \\left[\\frac{\\gamma_{jk}^{2}}{\\xi_{j}^{2}} \\right]^{4} - \\left[ \\sum_{j=1}^{p} \\left[\\frac{\\gamma_{jk}^{2}}{\\xi_{j}^{2}}\\right] \\right]^{2} \\right)\n\\end{equation}\n\nwhere $\\xi_{i}^{2} = \\sum_{k=1}^{q} \\gamma_{jk}^{2}$ is the communality for each of the $j$ variables as before.\n\n\n%Another index to be maximised is the so-called quartimax rotation \\cite{Neuhaus+Wrigley:1954}\n%\n%\\begin{equation}\n%Q = \\sum_{j=1}^{p} \\sum_{k=1}^{q} \\gamma_{jk}^{4} - \\frac{1}{pq} \\left(\\sum_{j=1}^{p} \\sum_{k=1}^{q} \\gamma_{jk}^{2} \\right)^{2}\n%\\end{equation}\n\n%It needs to be stressed that this whole point of this exercise is interpretability!.   \n\nEarlier we called \\texttt{factanal()} with the argument \\texttt{rotation = \"none\"}, hence the default is to carry out a rotation.   It is also possible to obtain a promax rotation.   However, it is useful for our purposes to carry out the rotations directly on the loadings matrices we have generated earlier, the following call:\n\\begin{verbatim}\n> varimax(loadings4)\n\\end{verbatim}\nwill supply a varimax rotation of our four principal component factors.\n\nIn many books dealing with topic it is conventional to consider this subject by visually rotating the axis, leaving the loadings in the same position.   However, inverting this procedure we can very simply plot the rotated and unrotated loadings as follows:\n\n\\singlespacing\n\\begin{verbatim}\n> plot(loadings4[,c(1:2)], pch = as.character(c(1:9)), \n    xlab = expression(paste(gamma,\"1\")), ylab = expression(paste(gamma,\"2\")),\n    main = \"First and second loadings\", \n    xlim = c(-1,1), ylim = c(-1,1))\n> points(varimax(loadings4)$loadings[,c(1:2)], \n    pch = letters[c(1:9)], col = \"red\")\n> abline(h = 0)\n> abline(v = 0)\n\\end{verbatim}\n\\onehalfspacing\n\nwhere the numbers 1-9 represent the unrotated loadings for variables 1 to 9, and the letters a-i represent the rotated loadings for variables 1 to 9 on the first two factors.   This is depicted in figure \\ref{farotation}.\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = 0.5\\textwidth]{images/farotation}\n\\caption{Plot overlaying the co-ordinates of factor loadings 1 and 2 before and after rotation optimised by the varimax criterion}\n\\label{farotation}\n\\end{center}\n\\end{figure}\n\nAlthough is is more difficult to see what is going on with $q=4$, we can see for example that the eighth variable (Social and Personal Services) has in increased loading in terms of $\\gamma_{18}$, and a much decreased loading in terms of the second factor ($\\gamma_{28}$ is virtually zero.   Thus we may feel that we have achieved some simplification of our factor structure.\n\n\\section{Factor scoring}\n\nFinally, there are occasions where we may wish to estimate values for $\\boldsymbol{\\phi}_{i}$ for a given individual $i$.   These values are referred to as the scores, the process of estimating them, which has to be carried out after $\\boldsymbol{\\Gamma}$ and $\\boldsymbol{\\psi}$ have been estimated is therefore referred to as scoring.\n\nTwo methods are available in R for scoring, Thomson and Bartlett's.   The default is that no scoring takes place (it requires a data matrix).   By including \\texttt{scores = \"Bartlett\")} or \\texttt{scores = \"regression\"} these estimates are obtained.\n\n\\cite{Bartlett:1937,Bartlett:1938} propsed a method based upon weighted least squares.\n\nOnce we have estimates\n\n\n\\begin{eqnarray*}\nx_{1} - \\bar{x}_{1}  &=& \\sum_{k=1}^{q} \\hat{\\gamma}_{1k} \\phi_{1}  + \\zeta_{1}\\\\\nx_{2} - \\bar{x}_{2} &=&  \\sum_{k=1}^{q} \\hat{\\gamma}_{2k} \\phi_{2}  + \\zeta_{2}\\\\\n&\\vdots&\\\\\nx_{p} - \\bar{x}_{p} &=& \\sum_{k=1}^{q} \\hat{\\gamma}_{pk} \\phi_{p}  + \\zeta_{p}\n\\end{eqnarray*}\n\nwe need to estimate $\\phi_{j}$ for $j=1, \\ldots, q$, however as $var(\\zeta_{j}) = \\psi_{j} $ are not equal he argued that weighted least squares was the most appropriate technique.\n\nThe weighted least squares estimates thus obtained are:\n\n\\begin{equation}\n\\boldsymbol{\\hat{\\phi}}_{i} = (\\boldsymbol{\\Gamma}^{T} \\boldsymbol{\\Psi}^{-1} \\boldsymbol{\\Gamma})\\boldsymbol{\\Gamma}^{T} \\boldsymbol{\\Psi}(\\boldsymbol{x}_{i} - \\boldsymbol{\\bar{x}})\n\\end{equation}\n\n\\cite{Thomson:1951} is based on assuming that both $\\boldsymbol{\\phi}$ and $\\boldsymbol{\\zeta}$ are multivariate normal, thus a concatenation of the manifest ($\\boldsymbol{x}$) and latent ( $\\boldsymbol{\\phi}$) variables $\\boldsymbol{y}^{T} = (\\boldsymbol{\\phi}^{T}, \\boldsymbol{x}^{T})$ will also be normal with dispersion matrix:\n\n\\begin{displaymath}\nvar(\\boldsymbol{y}) = \\left( \\begin{array}{cc} \\boldsymbol{I} & \\boldsymbol{\\Gamma}^{T} \\\\\n\\boldsymbol{\\Gamma} & \\boldsymbol{\\Gamma} \\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\psi} \\end{array} \\right)\n\\end{displaymath}\n\n\nThe mean of $\\boldsymbol{\\phi}$ is zero by definition, therefore:\n\n\\begin{displaymath}\nE(\\boldsymbol{z} | \\boldsymbol{x}_{0}) =  \\boldsymbol{\\Gamma}^{T}(\\boldsymbol{\\Gamma})\\boldsymbol{\\Gamma}^{T} + \\boldsymbol{\\Psi})^{-1}(\\boldsymbol{x}_{o} - \\boldsymbol{\\mu})\n\\end{displaymath}\n\nwhich gives the estimate for the scores as:\n\n\\begin{equation}\n\\boldsymbol{z} =  \\boldsymbol{\\hat{\\Gamma}}^{T}(\\boldsymbol{\\hat{\\Gamma}})\\boldsymbol{\\hat{\\Gamma}}^{T} + \\boldsymbol{\\hat{\\psi}})^{-1}(\\boldsymbol{x}_{i} - \\boldsymbol{\\hat{mu}})\n\\end{equation}\n\nIt might be clear that factor scoring takes no account of uncertainty in the estimates of $\\boldsymbol{\\hat{\\Gamma}}$ and $ \\boldsymbol{\\hat{\\psi}}$, this is one area where Bayesian methods are coming to the fore \\citep{Aitkin+Aitkin:2005}\n\n\n%As stated, Factor Analysis is very common in application areas such as Psychometrics.   The canonical example is an analysis of intelligence testing.  We will use an example from Smith, G. A. and Stanley G. (1983) ``Clocking g: relating intelligence and measures of timed performance''. Intelligence, 7, 353-368 (presented in Bartholomew, 1990).   If we load up the \\texttt{ability.cov} object we have a covariance matrix arising from six tests given to 112 individuals.   The six tests are general: a non-verbal measure of general intelligence using Cattell's culture-fair test, picture: a picture-completion test, blocks: block design, maze: mazes, reading: reading comprehension and finally vocab: vocabulary.   The underlying theory is that there exists some kind of ``general intelligence'' ($g$); the more $g$ an individual has the higher they will tend to score in all of the six tests. \n\n%The following code will fit a Factor Analysis model by maximum likelihood to this covariance matrix; a set of calls to \\texttt{update} will increase the number of latent variables to two, and will also fit different rotations.   Part of the rationale for carrying out the rotations is to produce more readily interpreted factors.   In the case of promax, the rotation yields a number of loadings which are essentially zero.\n\n%Bartholomew gives both covariance and correlation matrices, but these are inconsistent. Neither are in the original paper. \n\n%Barthlomew, D. J. (1987) Latent Variable Analysis and Factor Analysis. Griffin. \n%Barthlomew, D. J. and Knott, M. (1990) Latent Variable Analysis and Factor Analysis. Second Edition, Arnold. \n\n\n%\\singlespacing\n%\\begin{verbatim}\n%> ability.cov ## have a look at the covariance matrix\n%> ?ability.cov ## get some details on the ``data''\n%> ability.FA <- factanal(factors = 1, covmat=ability.cov, rotation = \"none\")\n%> ability.FA ## have a look at the first model\n%> update(ability.FA, factors=2) ## what about two latent variables\n%> update(ability.FA, factors=2, rotation=\"varimax\")\n%> update(ability.FA, factors=2, rotation=\"promax\")\n%\\end{verbatim}\n%\\onehalfspacing\n\n%\\textit{How do you interpret the various models?}   Most of our work in factor analysis will be considered with rotation and reificaton (interpreting the hidden variables).\n\n%%% Local Variables: ***\n%%% mode:latex ***\n%%% TeX-master: \"../book.tex\"  ***\n%%% End: ***", "meta": {"hexsha": "9fe5c1d08fc217c0a64395703c1dad613950ae9c", "size": 49792, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/FactAnal.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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/FactAnal.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "chapters/FactAnal.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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": 62.0847880299, "max_line_length": 1447, "alphanum_fraction": 0.7049526028, "num_tokens": 15124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7718435083355188, "lm_q1q2_score": 0.6218219751713159}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{indentfirst}\n\\usepackage{amssymb}\n\\usepackage{fancyhdr}\n\n\\title{LX331: Assignment 3}\n\\author{Duy Nguyen}\n\\date{17 February 2017}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{Nguyen \\thepage}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{The syntax and semantics of Propositional Logic}\n\\subsection*{A. B.}\n(1) $\\sim s \\& r$ : Stuart is not in the kitchen and Fred left.\n\n\\begin{tabular}{cc|ccccc}\nr & s & $\\sim s$ \\& $\\sim s \\& r$ \\\\\n\\hline \nT & T & F & F \\\\\nT & F & T & T \\\\\nF & T & F & F \\\\\nF & F & T & F \\\\\n\\end{tabular}\n\n(2) $\\sim (p \\lor q)$ : It is not true that Mary or Sue is at home.\n\n\\begin{tabular}{cc|ccccc}\np & q & $p \\lor q$ \\& $\\sim (p \\lor q)$ \\\\\n\\hline \nT & T & T & F \\\\\nT & F & T & F \\\\\nF & T & T & F \\\\\nF & F & F & T \\\\\n\\end{tabular}\n\n(3) $\\sim (p \\& s) \\rightarrow q$ : If it is not true that Marry is at home and Stuart is in the kitchen, then Sue is at home.\n\n\\begin{tabular}{ccc|ccccc}\np & q & s & $p \\& s$ & $\\sim (p \\& s)$ & $\\sim (p \\& s) \\rightarrow q$ \\\\\n\\hline \nT &T & T & T & F & T \\\\\nT &T & F & F & T & T\\\\\nT &F & T & T & F & T\\\\\nT &F & F & F & T & F\\\\\nF &T & T & F & T & T\\\\\nF &T & F & F & T & T\\\\\nF &F & T & F & T & F\\\\\nF &F & F & F & T & F\\\\\n\\end{tabular}\n\n(4) $\\sim q \\& ((s \\lor \\sim r) \\rightarrow \\sim s)$ : Sue isn't at home and if Stuart is in the kitchen or Fred didn't left then Stuart is not in the kitchen. \n\n\\begin{tabular}{ccc|ccccc}\np &r & s & $s \\lor \\sim r$ & $(s \\lor \\sim r) \\rightarrow \\sim s$ & $\\sim q \\& ((s \\lor \\sim r) \\rightarrow \\sim s)$ \\\\\n\\hline \nT &T & T & T & F & F \\\\\nT &T & F & F & T & F\\\\\nT &F & T & T & F & F\\\\\nT &F & F & T & T & F\\\\\nF &T & T & T & F & F\\\\\nF &T & F & F & T & T\\\\\nF &F & T & T & F & F\\\\\nF &F & F & T & T & T\\\\\n\\end{tabular}\n\n\\subsection*{C. D.}\n(5) Stuart is not in the kitchen and Fred didn’t leave. \n\n$\\sim s \\& \\sim r$\n\nWe can rewrite this logic formula as $\\sim (s \\lor r)$ due to DeMorgan's law.\n\n\\begin{tabular}{cc|c}\ns & r & $\\sim s \\& \\sim r \\equiv \\sim (s \\lor r)$ \\\\\n\\hline \nT & T & F  \\\\\nT & F & F \\\\\nF & T & F  \\\\\nF & F & T  \\\\\n\\end{tabular}\n\n(6) If Sue is at home or Fred didn’t leave, then Stuart is not in the kitchen.\n\n$(q \\lor \\sim r) \\rightarrow \\sim s$\n\n\\begin{tabular}{ccc|cc}\np & r & s & $(q \\lor \\sim r)$ & $(q \\lor \\sim r) \\rightarrow \\sim s$ \\\\\n\\hline \nT & T & T & T & F  \\\\\nT & T & F & F & T \\\\\nT & F & T & T & F \\\\\nT & F & F & F & T \\\\\nF & T & T & F & T \\\\\nF & T & F & F & T \\\\\nF & F & T & F & F \\\\\nF & F & F & F & T \\\\\n\\end{tabular}\n\n\n(7) It's not the case that Mary and Sue are both at home.\n\n$\\sim (p \\& q)$\n\n\\begin{tabular}{cc|c}\np & q & $\\sim (p \\& q)$ \\\\\n\\hline \nT & T & F  \\\\\nT & F & T \\\\\nF & T & T  \\\\\nF & F & T  \\\\\n\\end{tabular}\n\n(8) Neither Mary nor Sue is at home.\n\n$\\sim (p \\lor q)$\n\n\\begin{tabular}{cc|c}\np & q & $\\sim (p \\lor q)$ \\\\\n\\hline \nT & T & F  \\\\\nT & F & F \\\\\nF & T & F  \\\\\nF & F & T  \\\\\n\\end{tabular}\n\n\\section{Representing semantic ambiguity in Propositional Logic}\n\n(9) I didn't talk to Fred and Barney\n\nWe can interpret two understanding from (9).\n\n(a) I did not talk to Fred and Barney at the same time. \n\n$\\sim (p \\& q)$\n\n(b) I did not talk to Fred, and I did not talked to Barney\n\n$\\sim p \\& \\sim q$\n\nIf we look into the truth table, we can see that the two interpretations of the English sentence is not equivalent. \n\n\\begin{tabular}{cc|cc}\np & q & $\\sim (p \\& q)$ & $\\sim p \\& \\sim q$\\\\\n\\hline \nT & T & F & F  \\\\\nT & F & T & F\\\\\nF & T & T & F\\\\\nF & F & T & T \\\\\n\\end{tabular}\n\n\\section{A new logical connective}\n\nI can't type the connective arrow so $->$ is a substitution. \n\n\\begin{tabular}{cc|cl}\nA & B & A $->$ B & Comment\\\\\n\\hline \nT & T & F & It's the last week so there can't be homework  \\\\\nT & F & T & It's not the last week so there have to be homework\\\\\nF & T & T & It's the last week, so it is true that there isn't homework\\\\\nF & F & F & It's not the last week, so if there is no homework it is false. \\\\\n\\end{tabular}\n\n\\section{Logical relations between sentences}\n\n\\subsection*{A.}\nSo we have that $p \\rightarrow q \\equiv \\sim p \\lor q \\equiv \\sim (p \\& \\sim q)$. So $p \\rightarrow q$ and $\\sim (p \\& \\sim q)$ should be equivalent. Let's check with the truth table.\n\n\\begin{tabular}{cc|cc}\np & q & $p \\rightarrow q$ & $\\sim (p \\& \\sim q)$ \\\\ \\hline \nT & T & T & T \\\\\nT & F & F & F \\\\\nF & T & T & T \\\\\nF & F & T & T \\\\\n\\end{tabular}\n\n\\subsection*{B.}\nLogical compatible means that there are rows in that both formulae is both true or both false.\n\n\\begin{tabular}{cc|cc}\nr & s & $\\sim r \\& \\sim s$ & $\\sim (r \\lor \\sim s)$ \\\\ \\hline \n\\textbf{T} & \\textbf{T} & \\textbf{F} & \\textbf{F} \\\\\n\\textbf{T} & \\textbf{F} & \\textbf{F} & \\textbf{F} \\\\\nF & T & F & T \\\\\nF & F & T & F \\\\\n\\end{tabular}\n\nAs we can see, the first two row are show that these two formulae are compatible.\n\n\\subsection*{C.}\nOne formula entails the other when the truth of the first \"forces\" the truth of the second. The table for two formulae is as follow:\n\n\\begin{tabular}{cc|cc}\np & s & $ \\sim (p \\& s) $ & $ \\sim (p \\lor s) $ \\\\ \\hline \nT & T & F & F \\\\\nT & F & T & F \\\\\nF & T & T & F \\\\\n\\textbf{F} & \\textbf{F} & \\textbf{T} & \\textbf{T} \\\\\n\\end{tabular}\n\nFrom the truth table, we can see that $ \\sim (p \\& s) $ does not entails $ \\sim (p \\lor s) $. However, the last line show us that $ \\sim (p \\lor s) $ entails $ \\sim (p \\& s) $.\n\n\n\\end{document}\n", "meta": {"hexsha": "0c0027f89f702d2010cabe2f2ec574e34cdb6032", "size": 5320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "unnatural_rubber/hw/LX/LX331_A3.tex", "max_stars_repo_name": "zuik/stuff", "max_stars_repo_head_hexsha": "4bae095f8a857c884b409356a61f56a49b768611", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "unnatural_rubber/hw/LX/LX331_A3.tex", "max_issues_repo_name": "zuik/stuff", "max_issues_repo_head_hexsha": "4bae095f8a857c884b409356a61f56a49b768611", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "unnatural_rubber/hw/LX/LX331_A3.tex", "max_forks_repo_name": "zuik/stuff", "max_forks_repo_head_hexsha": "4bae095f8a857c884b409356a61f56a49b768611", "max_forks_repo_licenses": ["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.0943396226, "max_line_length": 183, "alphanum_fraction": 0.5546992481, "num_tokens": 2028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6218219703170159}}
{"text": "\\section{The image of a map and the replacement axiom}\\label{chap:image}\n\nThe idea of the image of a map $f:A\\to X$ is that it is, in a way, the least subtype of $X$ that contains all the values of $f$. More precisely, the image of $f$ is an embedding $i:\\im(f)\\hookrightarrow X$ that fits in a commuting triangle\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=tiny]\n    A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & \\im(f) \\arrow[dl,hook,\"i\"] \\\\\n    \\phantom{\\im(f)} & X\n  \\end{tikzcd}\n\\end{equation*}\nand satisfies the \\emph{universal property} of the image of $f$. The universal property of the image of $f$ asserts that if a subtype $B\\hookrightarrow X$ contains all the values of $f$, then it contains the image of $f$.\n%In other words, for  asserts that there is a unique map $h:\\im(f)\\to B$ for which the tetrahedron\n%\\begin{equation*}\n%  \\begin{tikzcd}[column sep=large]\n%    A \\arrow[rr] \\arrow[dr,\"q\"] \\arrow[dddr,swap,\"f\"] & & B \\arrow[dddl,\"m\"] \\\\\n%    & \\im(f) \\arrow[ur,densely dotted,\"h\"] \\arrow[dd,\"i\"] \\\\ \\\\\n%    & X\n%  \\end{tikzcd}\n%\\end{equation*}\n%commutes.\nThe image of a map can be constructed using the propositional truncation operation. In fact, we can also go the other way around: The propositional truncation of a type $A$ is the image of the map $A\\to\\unit$.\n\nThe final topic of this section is the type theoretic replacement axiom. A specific instance of the replacement axiom asserts that the image of any map $f:A\\to\\UU$ is equivalent to a type in $\\UU$, provided that $A$ is equivant to a type in $\\UU$. This property will be used to construct quotients in type theory, much in the same way as quotients are constructed in set theory.\n\nWe should note that the existence of the propositional truncation operation and the replacement axiom will be assumed for now. However, once we assume that universes are closed under pushouts, we will be able to construct the propositional truncations and we will be able to prove the replacement axiom. These constructions will be given in \\cref{sec:join-construction}.\n\n\\subsection{The image of a map}\\label{sec:image-construction}\n %Note that there is quite a lot of information in this diagram: not only are there the three small commuting triangles; there is also the large commuting triange in the back, and there is a three-dimensional solid filling the space between the four triangles. We make the following definition, in order to express the universal property of the image efficiently.\n\n\\begin{defn}\n  Let $f:A\\to X$ and $g:B\\to X$ be maps. A \\define{morphism} from $f$ to $g$ over $X$ consists of a map $h:A\\to B$ equipped with a homotopy $H:f\\htpy g\\circ h$ witnessing that the 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*}\ncommutes. Thus, we define the type\n\\begin{equation*}\n\\mathrm{hom}_X(f,g)\\defeq\\sm{h:A\\to B}f\\htpy g\\circ h.\n\\end{equation*}\nComposition of morphisms over $X$ is defined by\n\\begin{equation*}\n  (k,K)\\circ (h,H) \\defeq (k\\circ h,\\ct{H}{(K\\cdot h)}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{defn}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & I \\arrow[dl,\"i\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $H:f\\htpy i\\circ q$, where $i$ is an embedding\\index{embedding}.\nWe say that $i$ has the \\define{universal property of the image of $f$}\\index{universal property!of the image} if the map\n\\begin{equation*}\n\\blank\\circ(q,H) : \\mathrm{hom}_X(i,m)\\to\\mathrm{hom}_X(f,m)\n\\end{equation*}\nis an equivalence for every embedding $m:B\\to X$. \n\\end{defn}\n\n\\begin{rmk}\n  Consider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & I \\arrow[dl,\"i\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $H:f\\htpy i\\circ q$, where $i$ is an embedding. Then it is not hard to see that the embedding $i$ satisfies the universal property of the image inclusion if and only if for every commuting triangle\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=tiny]\n    A \\arrow[dr,swap,\"f\"] \\arrow[rr,\"g\"] & & B \\arrow[dl,\"m\"] \\\\\n    & X\n  \\end{tikzcd}\n\\end{equation*}\nwith $G:f\\htpy m\\circ g$, where $m$ is an embedding, the type of quadruples $(h,K,L,M)$ consisting of\n\\begin{enumerate}\n\\item a map $h:I\\to B$,\n\\item a homotopy $K:i\\htpy m\\circ h$ witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      I \\arrow[rr,\"h\"] \\arrow[dr,swap,\"i\"] & & B \\arrow[dl,\"m\"] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes,\n\\item a homotopy $L:g\\htpy h\\circ q$ witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"g\"] & & I \\arrow[dl,\"h\"] \\\\\n      & B\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes,\n\\item a homotopy $M:\\ct{H}{(K\\cdot q)}\\htpy\\ct{G}{(m\\cdot L)}$ witnessing that the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      f \\arrow[d,swap,\"H\"] \\arrow[r,\"G\"] & m\\circ g \\arrow[d,\"m\\cdot L\"] \\\\\n      i\\circ q \\arrow[r,swap,\"K\\cdot q\"] & m\\circ h\\circ g\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes,\n\\end{enumerate}\nis contractible. However, the situation is in fact much simpler, because the type $\\mathrm{hom}_X(f,m)$ is a proposition whenever $m$ is an embedding.\n\\end{rmk}\n\n\\begin{rmk}\n  Suppose that the map $f:A\\to X$ has a section. Then the identity function\n  \\begin{equation*}\n    \\idfunc:X\\to X\n  \\end{equation*}\n  satisfies the universal property of the image of $f$. \n\\end{rmk}\n\n\\begin{rmk}\n  Suppose that $f:A\\to X$ is already an embedding. Then $f$ itself satisfies the universal property of the image of $f$.\n\\end{rmk}\n\n\\begin{lem}\nFor any $f:A\\to X$ and any embedding\\index{embedding} $m:B\\to X$, the type $\\mathrm{hom}_X(f,m)$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\n  Recall from \\cref{ex:triangle_fib} that the type $\\mathrm{hom}_X(f,m)$ is equivalent to the type\n  \\begin{equation*}\n    \\prd{x:X}\\fib{f}{x}\\to\\fib{m}{x}.\n  \\end{equation*}\n  Therefore it suffices to show that this type is a proposition. Recall from \\cref{cor:prop_emb} that a map is an embedding if and only if its fibers are propositions.\n  Thus we see that the type $\\prd{x:X}\\fib{f}{x}\\to\\fib{m}{x}$ is a product of propositions, hence it is a proposition by \\cref{thm:trunc_pi}.\n\\end{proof}\n\n\\begin{prp}\\label{prp:simplifly-universal-property-image}\n  Consider a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & I \\arrow[dl,\"i\"] \\\\\n      & X\n\\end{tikzcd}\n  \\end{equation*}\n  with $H:f\\htpy i\\circ q$, where $i$ is an embedding. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The embedding $i$ satisfies the universal property of the image inclusion of $f$.\n  \\item For every embedding $m:B\\to X$ there is a map\n    \\begin{equation*}\n      \\mathrm{hom}_X(f,m)\\to\\mathrm{hom}_X(i,m).\n    \\end{equation*}\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\nSince $\\mathrm{hom}_X(f,m)$ is a proposition for every every embedding $m:B\\to X$, the claim follows immediately by \\cref{ex:prop_equiv}.\n\\end{proof}\n\nJust as in the cases for pullbacks and pushouts, the universal property of the image implies that the image is determined uniquely. We will show here that the type of image factorizations of any map is a proposition. In \\cref{sec:image-construction} we will construct the image, after constructing the propositional truncation.\n\n\\begin{prp}\n  Let $f$ be a map, and consider two commuting triangles\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[dr,swap,\"f\"] \\arrow[rr,\"q\"] & & B \\arrow[dl,\"i\"] &[2em] A \\arrow[dr,swap,\"f\"] \\arrow[rr,\"{q'}\"] & & B' \\arrow[dl,\"{i'}\"] \\\\\n      & X & & \\phantom{B'} & X\n    \\end{tikzcd}\n  \\end{equation*}\n  with $I:f\\htpy i\\circ q$ and $I':f\\htpy i'\\circ q'$, in which $i$ and $i'$ are assumed to be embeddings. Moreover, consider\n  \\begin{equation*}\n    (h,H):\\mathrm{hom}_X(i,i')\n  \\end{equation*}\n  equipped with an identification $(h,H)\\circ(q,I)=(q',I')$ in $\\mathrm{hom}_X(f,i')$. Then, if any two of the following properties hold, so does the third:\n  \\begin{enumerate}\n  \\item The embedding $i$ satisfies the universal property of the image inclusion of $f$.\n  \\item The embedding $i'$ satisfies the universal property of the image inclusion of $f$.\n  \\item The map $h$ is an equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  Consider an embedding $m:C\\to X$. Then we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-1em]\n      \\mathrm{hom}_X(i',m) \\arrow[rr,\"{\\blank\\circ(h,H)}\"] \\arrow[dr,swap,\"{\\blank\\circ(q',I')}\"] & & \\mathrm{hom}_X(i,m) \\arrow[dl,\"{\\blank\\circ(q,I)}\"] \\\\\n      & \\mathrm{hom}_X(f,m), & \\phantom{\\mathrm{hom}_X(i',m)}\n    \\end{tikzcd}\n  \\end{equation*}\n  so it follows that if any two of these maps are equivalences, then so is the third. The claim now follows by the observation that $\\blank\\circ(h,H)$ is an equivalence for every embedding $m:C\\to X$ if and only if $h$ is an equivalence.\n\\end{proof}\n\n\\begin{cor}\\label{cor:uniqueness-image}\n  Consider two image factorizations\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[dr,swap,\"f\"] \\arrow[rr,\"q\"] & & B \\arrow[dl,\"i\"] &[2em] A \\arrow[dr,swap,\"f\"] \\arrow[rr,\"{q'}\"] & & B' \\arrow[dl,\"{i'}\"] \\\\\n      & X & & \\phantom{B'} & X\n    \\end{tikzcd}\n  \\end{equation*}\n  of a map $f$, with $I:f\\htpy i\\circ q$ and $I':f\\htpy i'\\circ q'$. Then the type of $(e,H):\\mathrm{hom}_X(i,i')$ in which $e$ is an equivalence, equipped with an identification\n  \\begin{equation*}\n    (e,H)\\circ(q,I)=(q',I')\n  \\end{equation*}\n  in $\\mathrm{hom}_X(f,i')$, is contractible.\n\\end{cor}\n\nThe image of a map $f:A\\to X$ can now be defined using the propositional truncation:\n\n\\begin{defn}\nFor any map $f:A\\to X$ we define the \\define{image}\\index{image} of $f$ to be the type\n\\begin{equation*}\n\\im(f) \\defeq \\sm{x:X}\\brck{\\fib{f}{x}}.\n\\end{equation*}\nFurthermore, we define:\n\\begin{enumerate}\n\\item The \\define{image inclusion}\n  \\begin{equation*}\n    i_f:\\im(f)\\to X\n  \\end{equation*}\n  to be the projection $\\proj 1$.\n\\item The map\n  \\begin{equation*}\n    q_f:A\\to\\im(f)\n  \\end{equation*}\n  to be the map given by $q_f(x)\\defeq(f(x),\\eta(x,\\refl{f(x)}))$.\n\\item The homotopy $I_f:f\\htpy i_f\\circ q_f$ witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"q_f\"] \\arrow[dr,swap,\"f\"] & & \\im(f) \\arrow[dl,\"i_f\"] \\\\\n      \\phantom{\\im(f)} & X\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes, to be given by $I_f(x)\\defeq\\refl{f(x)}$.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{prp}\n  The image inclusion $i_f:\\im(f)\\to X$ of any map $f:A\\to X$ is an embedding.\n\\end{prp}\n\n\\begin{proof}\n  The fiber of $i_f$ at $x:X$ is equivalent to the type $\\brck{\\fib{f}{x}}$. In particular we see that the fibers are propositions, so $i_f$ is an embedding.\n\\end{proof}\n\n\\begin{thm}\n  The image inclusion $i_f:\\im(f)\\to X$ of any map $f:A\\to X$ satisfies the universal property of the image inclusion of $f$.\n\\end{thm}\n\n\\begin{proof}\n  Consider an embedding $m:B\\to X$. Note that we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\mathrm{hom}_X(i_f,m) \\arrow[d] \\arrow[r] & \\mathrm{hom}_X(f,m) \\arrow[d] \\\\\n      \\Big(\\prd{x:X}\\fib{i_f}{x}\\to\\fib{m}{x}\\Big) \\arrow[r,swap,\"h\\mapsto{\\lam{x}h_x\\circ\\varphi_x}\"] & \\Big(\\prd{x:X}\\fib{f}{x}\\to\\fib{m}{x}\\Big)\n    \\end{tikzcd}\n  \\end{equation*}\n  The vertical maps are of the form\n  \\begin{equation*}\n    (h,H) \\mapsto \\lam{x}{(y,p)}(h(y),\\ct{H(y)^{-1}}{p}),\n  \\end{equation*}\n  and they are both equivalences. The map\n  \\begin{equation*}\n    \\varphi_x:\\fib{f}{x}\\to\\fib{i_f}{x}\n  \\end{equation*}\n  given by $\\varphi_x(a,p)\\defeq((h(a),\\eta(a,p)),p)$ is a propositional truncation for every $x:X$. Therefore it follows that the map\n  \\begin{equation*}\n    (\\fib{i_f}{x}\\to\\fib{m}{x})\\to(\\fib{f}{x}\\to\\fib{m}{x})\n  \\end{equation*}\n  is an equivalence, for every $x:X$. Thus we conclude that the bottom map in the above square is an equivalence, which implies that the top map is an equivalence. \n\\end{proof}\n\n\\begin{eg}\n  An important special case of the homotopy image of a map is the image of the terminal projection\n\\begin{equation*}\n  \\const_\\ttt : A \\to \\unit,\n\\end{equation*}\nwhich results in an embedding $I\\hookrightarrow \\unit$. Embeddings into the unit type are in fact just propositions. To see this, note that\n\\begin{align*}\n\\sm{A:\\UU}{f:A\\to\\unit}\\isemb(f)\n& \\eqvsym \\sm{A:\\UU}\\isemb(\\const_\\ttt) \\\\\n& \\eqvsym \\sm{A:\\UU}\\prd{x:\\unit}\\isprop(\\fib{\\const_\\ttt}{x}) \\\\\n& \\eqvsym \\sm{A:\\UU}\\isprop(\\fib{\\const_\\ttt}{\\ttt}) \\\\\n& \\eqvsym \\sm{A:\\UU}\\isprop(A).\n\\end{align*}\nTherefore, the universal property of the image of the map $A\\to\\unit$ is equivalently described as a proposition $P$ satisfying the universal property of the propositional truncation.\n\\end{eg}\n\n\\subsection{Surjective maps}\n\nAnother application of the propositional truncation is the notion of surjective map.\n\n\\begin{defn}\nA map $f:A\\to B$ is said to be \\define{surjective} if there is a term of type\n\\begin{equation*}\n\\issurj(f)\\defeq \\prd{y:B}\\brck{\\fib{f}{b}}.\n\\end{equation*}\n\\end{defn}\n\n\\begin{eg}\nAny equivalence is a surjective map, and so is any map that has a section (those are sometimes called \\define{split epimorphisms}). Other examples include the base point inclusion $\\unit\\to\\sphere{n}$ for any $n\\geq 1$. \n\\end{eg}\n\n\\begin{prp}\\label{prp:surjective}\n  Consider a map $f:A\\to B$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f:A\\to B$ is surjective.\n  \\item For any family $P$ of propositions 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*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  Suppose first that $f$ is surjective, and consider the commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=6em]\n      \\Big(\\prd{y:B}P(y)\\Big) \\arrow[r,\"\\blank\\circ f\"] \\arrow[d,swap,\"h\\mapsto\\lam{y}\\const_{h(y)}\"] & \\Big(\\prd{x:A}P(f(x))\\Big)  \\\\\n      \\Big(\\prd{y:B}\\brck{\\fib{f}{y}}\\to P(y)\\Big) \\arrow[r,swap,\"h\\mapsto\\lam{y}h(y)\\circ\\eta\"] & \\Big(\\prd{y:B}\\fib{f}{y}\\to P(y)\\Big) \\arrow[u,swap,\"{h\\mapsto\\lam{x}h(f(x),(x,\\refl{f(x)}))}\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  In this square, the bottom map is an equivalence by the universal property of the propositional truncation of $\\fib{f}{y}$. The map on the right is also easily seen to be an equivalence. Furthermore, the map on the left is an equivalence by the assumption that $f$ is surjective, from which it follows that the types $\\brck{\\fib{f}{y}}$ are contractible. Therefore it follows that the top map is an equivalence, which completes the proof that (i) implies (ii).\n\n  For the converse, it follows immediately from the assumption (ii) that\n  \\begin{equation*}\n    \\blank\\circ f : \\Big(\\prd{y:B}\\brck{\\fib{f}{y}}\\Big)\\to\\Big(\\prd{x:A}\\brck{\\fib{f}{f(x)}}\\Big)\n  \\end{equation*}\n  is an equivalence. Hence it suffices to construct a term of type $\\brck{\\fib{f}{f(x)}}$ for each $x:A$. This is easy, because we have\n  \\begin{equation*}\n    \\eta(x,\\refl{f(x)}):\\brck{\\fib{f}{f(x)}}.\\qedhere.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{thm}\\label{thm:surjective}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"m\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nin which $m$ is an embedding. Then the following are equivalent:\n\\begin{enumerate}\n\\item The embedding $m$ satisfies the universal property of the image inclusion of $f$.\n\\item The map $q$ is surjective.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  First assume that $m$ satisfies the universal property of the image inclusion of $f$, and consider the composite function\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\Big(\\sm{y:B}\\brck{\\fib{q}{y}}\\Big) \\arrow[r,\"\\proj 1\"] & B \\arrow[r,\"m\"] & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  Note that $m\\circ\\proj 1$ is a composition of embeddings, so it is an embedding. By the universal property of $m$ there is a unique map $h$ for which the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      B \\arrow[dr,swap,\"m\"] \\arrow[rr,densely dotted,\"h\"] & & \\sm{y:B}\\brck{\\fib{q}{y}} \\arrow[dl,\"m\\circ\\proj 1\"] \\\\\n      \\phantom{\\sm{y:B}\\brck{\\fib{q}{y}}} & X\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes. Now note that $\\proj 1\\circ h$ is a map such that $m\\circ (\\proj 1\\circ h)\\htpy m$. The identity function is another map for which we have $m\\circ\\idfunc\\htpy m$, so it follows by uniqueness that $\\proj 1\\circ h\\htpy \\idfunc$. In other words, the map $h$ is a section of the projection map. Therefore we obtain by \\cref{ex:pi_sec} a dependent function\n  \\begin{equation*}\n    \\prd{b:B}\\brck{\\fib{q}{b}},\n  \\end{equation*}\n  showing that $q$ is surjective.\n\n  For the converse, suppose that $q$ is surjective. To prove that $m$ satisfies the universal property of the image factorization of $f$, it suffices to construct an equivalence\n  \\begin{equation*}\n    \\mathrm{hom}_X(f,m')\\to\\mathrm{hom}_X(m,m'),\n  \\end{equation*}\n  for any embedding $m':B'\\to X$. To see that there is such an equivalence, we make the following calculation\n  \\begin{align*}\n    \\mathrm{hom}_X(m,m') & \\simeq \\prd{x:X}\\fib{m}{x}\\to\\fib{m'}{x} \\\\\n                         & \\simeq \\prd{b:B}\\fib{m'}{m(b)} \\\\\n                         & \\simeq \\prd{a:A}\\fib{m'}{m(q(a))} \\\\\n                         & \\simeq \\prd{a:A}\\fib{m'}{f(a)} \\\\\n                         & \\simeq \\prd{x:X}\\fib{f}{x}\\to\\fib{m'}{x} \\\\\n                         & \\simeq \\mathrm{hom}_X(f,m').\n  \\end{align*}\n  In this calculation, the first and last equivalence hold by \\cref{ex:triangle_fib}. The second and second to last equivalences hold by \\cref{ex:pi-fib}. The third equivalence holds by \\cref{prp:surjective}, since $q$ is assumed to be surjective, and the fourth equivalence holds since we have a homotopy $f\\htpy m\\circ f$.\n\\end{proof}\n\n\\begin{cor}\n  Every map factors uniquely as a surjective map followed by an embedding.\n\\end{cor}\n\n\\begin{proof}\n  Consider a map $f:A\\to X$, and two factorizations\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      A \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"i\"] &[3em] A \\arrow[rr,\"{q'}\"] \\arrow[dr,swap,\"f\"] & & B' \\arrow[dl,\"{i'}\"] \\\\\n      & X & & & X\n    \\end{tikzcd}\n  \\end{equation*}\n  of $f$ where $m$ and $m'$ are embeddings, and $q$ and $q'$ are surjective. Then both $m$ and $m'$ satisfy the universal property of the image factorization of $f$ by \\cref{thm:surjective}. Now it follows by \\cref{cor:uniqueness-image} that the type of $(e,H):\\mathrm{hom}_X(i,i')$ in which $e$ is an equivalence, equipped with an identification\n  \\begin{equation*}\n    (e,H)\\circ(q,I)=(q',I')\n  \\end{equation*}\n  in $\\mathrm{hom}_X(f,i')$, is contractible.\n\\end{proof}\n\n\\subsection{Type theoretic replacement}\n\n\\begin{comment}\nWe have constructed the set quotient $A/R$ as the image of the equivalence relation\n\\begin{equation*}\n  R:A\\to \\UU^A.\n\\end{equation*}\nHowever, the type $\\UU^A$ is itself in the next universe $\\UU^+$. Hence the quotient is also in the universe $\\UU^+$. We prove in this section that $A/R$ is nevertheless equivalent to a type in $\\UU$. In other words, we show that $A/R$ is \\emph{essentially} small.\n\\end{comment}\n\n\\begin{defn}\\label{defn:ess_small}\n\\begin{enumerate}\n\\item A type $A$ is said to be \\define{essentially small}\\index{essentially small!type} if there is a type $X:\\UU$ and an equivalence $\\eqv{A}{X}$. We write\\index{ess_small(A)@{$\\mathsf{ess\\usc{}small}(A)$}}\n\\begin{equation*}\n\\mathsf{ess\\usc{}small}(A)\\defeq\\sm{X:\\UU}\\eqv{A}{X}.\n\\end{equation*}\n\\item A map $f:A\\to B$ is said to be \\define{essentially small}\\index{essentially small!map} if for each $b:B$ the fiber $\\fib{f}{b}$ is essentially small.\nWe write\\index{ess_small(f)@{$\\mathsf{ess\\usc{}small}(f)$}}\n\\begin{equation*}\n\\mathsf{ess\\usc{}small}(f)\\defeq\\prd{b:B}\\mathsf{ess\\usc{}small}(\\fib{f}{b}).\n\\end{equation*}\n\\item A type $A$ is said to be \\define{locally small}\\index{locally small!type} if for every $x,y:A$ the identity type $x=y$ is essentially small.\nWe write\\index{loc_small(A)@{$\\mathsf{loc\\usc{}small}(A)$}}\n\\begin{equation*}\n\\mathsf{loc\\usc{}small}(A)\\defeq \\prd{x,y:A}\\mathsf{ess\\usc{}small}(x=y).\n\\end{equation*}\n\\end{enumerate}\n\\end{defn}\n\n\\begin{eg}\n  \\begin{enumerate}\n  \\item Any essentially $\\UU$-small type is also locally $\\UU$-small.\n  \\item Any univalent universe $\\UU$ is locally $\\UU$-small, because by the univalence axiom we have equivalences\n    \\begin{equation*}\n      (A=B)\\simeq (A\\simeq B)\n    \\end{equation*}\n    for each $A,B:\\UU$, and the type $A\\simeq B$ is in $\\UU$.\n  \\item Any proposition is locally small with respect to any universe $\\UU$.\n  \\item For any family $P$ of locally $\\UU$-small types over a essentially $\\UU$-small type $A$, the dependent product $\\prd{x:A}P(x)$ is locally $\\UU$-small. In particular, any type $A\\to B$ of functions from an essentially small type into a locally small type is again locally small.\n  \\end{enumerate}\n\\end{eg}\n\n\\begin{lem}\\label{lem:isprop_ess_small}\nThe type $\\mathsf{ess\\usc{}small}(A)$ is a proposition for any type $A$.\\index{essentially small!is a proposition}\n\\end{lem}\n\n\\begin{proof}\nLet $A$ be a type, not necessarily in $\\UU$. In order to show that $\\mathsf{ess\\usc{}small}(A)$ is a proposition, we will use \\cref{lem:isprop_eq} and show that for any $X:\\UU$ and any equivalence $e:A\\simeq X$, the type\n\\begin{equation*}\n\\sm{Y:\\UU}\\eqv{A}{Y}\n\\end{equation*}\nis contractible. Note that we have an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{Y:\\UU}\\eqv{X}{Y}\\Big)}{\\Big(\\sm{Y:\\UU}\\eqv{A}{Y}\\Big)}\n\\end{equation*}\nbecause precomposing with the equivalence $e:A \\simeq X$ is an equivalence. However, the type $\\sm{Y:\\UU}\\eqv{X}{Y}$ is contractible by \\cref{thm:univalence}. This shows that $\\mathsf{ess\\usc{}small}(A)$ is equivalent to a contractible type, assuming that $A$ is essentially small.\n\\end{proof}\n\n\\begin{cor}\nFor each function $f:A\\to B$, the type $\\mathsf{ess\\usc{}small}(f)$ is a proposition, and for each type $X$ the type $\\mathsf{loc\\usc{}small}(X)$ is a proposition.\n\\end{cor}\n\n\\begin{proof}\nThis follows from the fact that propositions are closed under dependent products, established in \\cref{thm:trunc_pi}.\n\\end{proof}\n\nRecall that in set theory, the replacement axiom asserts that for any family of sets $\\{X_i\\}_{i\\in I}$ indexed by a set $I$, there is a set $X[I]$ consisting of precisely those sets $x$ for which there exists an $i\\in I$ such that $x\\in X_i$. In other words: the image of a set-indexed family of sets is again a set. Without the replacement axiom, $X[I]$ would be a class. In the following corollary we establish a type-theoretic analogue of the replacement axiom: the image of a family of small types indexed by a small type is again (essentially) small.\n\n\\begin{axiom}\\label{axiom:replacement}\n  For any map $f:A\\to B$ from an essentially small type $A$ into a locally small type $B$, the image of $f$ is again essentially small.\n\\end{axiom}\n\n\\begin{eg}\n  For any type $A:\\UU$, the image of the constant map $\\const_A:\\unit\\to \\UU$ is essentially small. This image is called the \\define{connected component} of the universe at $A$. To see why, let us calculate\n  \\begin{align*} \n    \\im(\\const_A) & \\jdeq \\sm{X:\\UU}\\Brck{\\fib{\\const_A}{X}} \\\\\n                  & \\jdeq \\sm{X:\\UU}\\Brck{\\sm{t:\\unit}A=X} \\\\\n                  & \\simeq \\sm{X:\\UU}\\brck{A=X}.\n  \\end{align*}\n  We see that the image of $\\const_A:\\unit\\to\\UU$ is the type of all types that are \\emph{merely} equal to $A$. In other words, they are equal to $A$ in an unspecified way.\n\\end{eg}\n\n\\begin{eg}\n  The type $\\F$ of all finite types is defined to be the image of the map\n  \\begin{equation*}\n    \\Fin : \\N\\to\\UU_0\n  \\end{equation*}\n  By the replacement axiom, this type is essentially small. \n\\end{eg}\n\n\\begin{exercises}\n  \\exercise Consider a map $f:A\\to P$ into a proposition $P$. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is a propositional truncation of $A$.\n  \\item The map $f$ is surjective.\n  \\end{enumerate}\n  \\exercise Consider a map $f:A\\to B$. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item $f$ is an equivalence.\n  \\item $f$ is both surjective and an embedding.\n  \\end{enumerate}\n  \\exercise 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$, and assume that $h$ is surjective. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is surjective.\n  \\item The map $g$ is surjective.\n  \\end{enumerate}\n  \\exercise \\label{ex:surjective-precomp}Consider a map $f:A\\to B$. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is surjective.\n  \\item For every set $C$, the precomposition function\n    \\begin{equation*}\n      \\blank\\circ f:(B\\to C)\\to (A\\to C)\n    \\end{equation*}\n    is an embedding.\n  \\end{enumerate}\n  Hint: To show that (ii) implies (i), use the assumption with the set $C\\jdeq\\prop_\\UU$, where $\\UU$ is a univalent universe containing both $A$ and $B$.\n  \\exercise Let us say that a type family $B$ over $A$ is \\define{univalent} if the map\n  \\begin{equation*}\n    (x=y)\\to (B(x)\\simeq B(y))\n  \\end{equation*}\n  is an equivalence, for every $x,y:A$.\n  \\begin{subexenum}\n  \\item Show that a family $B:A\\to\\UU$ is univalent if and only if the map $B:A\\to\\UU$ is an embedding.\n  \\item For any family $B:A\\to\\UU$, show that the type family $\\hat{B}:\\hat{A}\\to\\UU$ defined by\n    \\begin{align*}\n      \\hat{A} & \\defeq \\im(B) \\\\\n      \\hat{B}(X,p) & \\defeq X\n    \\end{align*}\n    is univalent.\n  \\item For any two families $B:A\\to\\UU$ and $D:C\\to\\mathcal{V}$, define the type of \\define{cartesian morphisms}\n    \\begin{equation*}\n      \\carthomFam((A,B),(C,D)) \\defeq \\sm{f:A\\to C}\\prd{x:A}B(x)\\simeq D(f(x)).\n    \\end{equation*}\n    Construct a cartesian morphism\n    \\begin{equation*}\n      (\\eta,\\alpha) : \\carthomFam((A,B),(\\hat{A},\\hat{B})).\n    \\end{equation*}\n  \\item Show that for any family $B:A\\to\\UU$ and any \\emph{univalent} family $D:C\\to\\mathcal{V}$, the map\n    \\begin{equation*}\n      \\carthomFam((\\hat{A},\\hat{B}),(C,D))\\to\\carthomFam((A,B),(C,D))\n    \\end{equation*}\n    given by\n    \\begin{equation*}\n      (f,e)\\mapsto (f\\circ\\eta,\\lam{x}e_x\\circ \\alpha_x)\n    \\end{equation*}\n    is an equivalence. This is the \\define{universal property} of the univalent completion of $A$.\n  \\end{subexenum}\n  %\\exercise \\label{also}(Mart\\'in Escard\\'o) For any two propositions $P$ and $Q$, define\n  %\\begin{equation*}\n  %P\\boxplus Q \\defeq ((P\\to Q)\\to Q)\\times ((Q\\to P)\\to P).\n  %\\end{equation*}\n  %\\begin{subexenum}\n  %\\item Show that $P\\lor Q\\to P\\boxplus Q$ and $P\\boxplus Q\\to\\neg(\\neg P\\land \\neg Q)$.\n  %\\end{subexenum}\n  %\\item \\label{ex:brck_comp} Formulate the computation rule corresponding to the path constructor $\\mu$. That is, compute the type of $\\apd{\\rec{\\brck{\\blank}}(f,g)}{\\mu(x,y)}$, and find a canonical element in it.\n  %\\exercise Let $f:A\\to X$ be a map. Construct an equivalence\n  %\\begin{equation*}\n  %\\eqv{\\Big(\\sm{y:\\mathsf{join\\usc{}power}_X(n,A)}f(x)=f^{\\ast n}(y)\\Big)}{\\Big(\\sm{y:A}f(x)=f(y)\\Big)^{\\ast n}}\n  %\\end{equation*}\n  %for any $x:A$.\n\\end{exercises}\n\n\\endinput\n\n\\begin{thm}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=small]\nA \\arrow[rr,\"i\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"m\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $I:f\\htpy m\\circ i$, where $m$ is an embedding. The following are equivalent:\n\\begin{enumerate}\n\\item $m$ satisfies the universal property of the image of $f$.\n\\item for each $x:X$, the proposition $\\fib{m}{x}$ satisfies the universal property of the propositional truncation of $\\fib{f}{x}$.\n\\end{enumerate}\n\\end{thm}\n", "meta": {"hexsha": "c8d4473c5017542cb43e1c929f9297a1c2728d31", "size": 27919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/image.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/image.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/image.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": 47.5621805792, "max_line_length": 556, "alphanum_fraction": 0.6723020165, "num_tokens": 9489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6218219667150426}}
{"text": "%\n% CMPT 473: Software Quality Assurance - A Course Overview\n% Section: Performance\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Performance}\n\t\\label{sec:performance}\n\\begin{easylist}\n\n& Performance areas include:\n\t&& Speed/runtime\n\t&& Resource management\n\t&& Throughput\n\t&& Responsiveness\n\t\n& Analyzed differently depending on component granularity (e.g. system-level, instruction-level)\n\n& Strategies of measuring performance:\n\t&& Identify area of interest\n\n& Evaluating results:\n\t&& Be aware of:\n\t\t&&& Warm-up time\n\t\t&&& Caching\n\t&& Measure and compare across changes\n\t&& Run many executions and take the average\n\t\n& Measurement of results:\n\n\t&& \\textbf{Arithmetic mean:} Average of measurements which measure the same value\n\t\t&&& Equation:\n\\begin{equation}\n\\frac{ \\displaystyle \\sum_{i=1}^N r_i }{N}\n\\end{equation}\n\n\t&& \\textbf{Harmonic mean:} Average of measurements which report rates (e.g. throughput for multiple tasks)\n\t\t&&& Represents the constant rate required for the same amount of time\n\t\t&&& Calculated by dividing the total number of rates by the rate per unit (inversion of the rate)\n\t\t&&& Equation:\n\\begin{equation}\n\\frac{N}{ \\displaystyle \\sum_{i=1}^N \\frac{1}{r_i} }\n\\end{equation}\n\t&& \\textbf{Geometric mean:} Average of measurements which represent different values\n\t\t&&& A change in any benchmark affects the final value proportionally\n\t\t&&& Represents a multiplied score of performance\n\t\t&&& Equation:\n\\begin{equation}\n\\sqrt[N]{ \\prod_{i=1}^N r_i }\n\\end{equation}\n\t&& \\textbf{Standard deviation:} Measure of confidence in the mean\n\t\t&&& Large values imply needing more samples or correction of methodological error\n\n\\end{easylist}\n\\clearpage\n", "meta": {"hexsha": "b9bb83277a888466de5bbf85f04f0c2433b65396", "size": 1658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-473-software-testing-reliability-security/tex/performance.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-473-software-testing-reliability-security/tex/performance.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-473-software-testing-reliability-security/tex/performance.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": 29.0877192982, "max_line_length": 107, "alphanum_fraction": 0.7352231604, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6218219667150425}}
{"text": "\\documentclass[pre,aps,superscriptaddress,nofootinbib]{revtex4}\n\n\\usepackage{amsmath,amsfonts,amssymb,bm,graphicx,hyperref,listings,xcolor,float,mathrsfs}\n\\usepackage{fontawesome}\n\\setlength{\\parindent}{0pt}\n\n\\begin{document}\n\n\\title{Polarisation-biased trajectories of independent Brownian rotors\\\\{\\small Analytic considerations with Mathieu functions}}\n\n\\author{Yann-Edwin Keta}\n\\maketitle\n\n\\section{Scaled cumulant generating function and rate function}\n\nWe wish to bias the trajectories of the system with respect to the mean vectorial polarisation over a trajectory,\n\\begin{equation}\n\\bm{p}_{\\tau} = \\frac{1}{\\tau} \\int_0^{\\tau} \\text{d}t \\, \\bm{p}(t) = \\frac{1}{N \\tau} \\int_0^{\\tau} \\text{d}t \\, \\sum_i \\bm{u}(\\theta_i(t)),\n\\end{equation}\nand therefore need to compute the scaled cumulant generating function (SCGF)\n\\begin{equation}\nN \\psi_{\\bm{p}}(\\bm{s}) = \\lim_{\\tau \\rightarrow \\infty} \\frac{1}{\\tau} \\log\\left<\\exp\\left(- \\bm{s} \\cdot N \\int_0^{\\tau} \\text{d}t \\, \\bm{p}(t)\\right)\\right>_0\n\\end{equation}\nwhere we will assume that $\\bm{s}$ is along the $x$-axis, and compute\n\\begin{equation}\n\\psi_ {p}(s) = \\lim_{\\tau \\rightarrow \\infty} \\frac{1}{\\tau} \\log\\left<\\exp\\left(- s N \\int_0^{\\tau} \\text{d}t \\, p_x(t)\\right)\\right>_0,\n\\end{equation}\nfrom which we can recover\n\\begin{equation}\n\\psi_{\\bm{p}}(\\bm{s}) = \\psi_{p}\\left(\\sqrt{s_x^2 + s_y^2}\\right)\n\\end{equation}\nfrom the fact that $\\psi_{\\bm{p}}(\\bm{s})$ has to be cylindrically symmetric. We then have that $N \\psi_s(p)$ is the largest eigenvalue of the eigenproblem\n\\begin{equation}\nN \\psi_{p}(s) P[\\{\\theta_i\\}] = \\mathscr{W}_{s, p} P[\\{\\theta_i\\}],\n\\end{equation}\nwhere we introduced the tilted generator \\cite{touchette2018introduction}\n\\begin{equation}\n\\mathscr{W}_{s, p} = \\mathcal{L} - s N p = D_r \\sum_i \\frac{\\partial^2}{\\partial \\theta_i^2} - s \\sum_i \\cos\\theta_i,\n\\end{equation}\nusing here $s \\equiv s_x$ and $p \\equiv p_x$, so that\n\\begin{equation}\n\\sum_i \\left(\\prod_{j \\neq i} P(\\theta_j)\\right) \\left[\\psi_{p}(s) P(\\theta_i) - \\left(D_r \\frac{\\partial^2}{\\partial \\theta_i^2} P(\\theta_i) - s \\cos(\\theta_i) P(\\theta_i)\\right)\\right] = 0,\n\\end{equation}\nis equivalent to the $1$-particle eigenproblem,\n\\begin{equation}\n\\psi_{p}(s) P(\\theta) - \\left(D_r \\frac{\\partial^2}{\\partial \\theta^2} P(\\theta) - s \\cos\\theta P(\\theta)\\right) = 0 \\Leftrightarrow \\frac{\\partial^2}{\\partial \\theta^2} \\tilde{P}(\\theta^{\\prime}) + (a - 2 q \\cos 2 \\theta^{\\prime}) \\tilde{P}(\\theta^{\\prime}) = 0,\n\\label{1P_eigenproblem}\n\\end{equation}\nwith $2 \\theta^{\\prime} = \\theta$, $\\tilde{P}(\\theta/2) = P(\\theta)$, and\n\\begin{equation}\na = - \\frac{4 \\psi_{p}(s)}{D_r},~ q = \\frac{2 s}{D_r},\n\\end{equation}\nand which solutions are known as the Mathieu functions \\cite{mathieu}.\\\\\n\nMost notably, we have that for any $q \\in \\mathbb{R}$ there is a countable infinity of $a$. Inspired by \\cite{grandpre2018current} we will choose $a_{\\mathrm{Mathieu}, 0}(q)$ the characteristic value of the $0$-th Mathieu function which is $\\pi$-periodic and even. We thus have the SCGF\n\\begin{equation}\nN \\psi_{\\bm{p}}(\\bm{s}) = N \\psi_{p}\\left(\\sqrt{s_x^2 + s_y^2}\\right) = - N \\frac{D_r}{4} a_{\\mathrm{Mathieu}, 0}\\left(\\frac{2}{D_r} \\sqrt{s_x^2 + s_y^2}\\right),\n\\end{equation}\nand by Legendre transform\n\\begin{equation}\n\\begin{aligned}\nN I(\\bm{p}) &= \\sup_{\\bm{s} \\in \\mathbb{R}^2} \\{- \\bm{s} \\cdot N \\bm{p} - N \\psi_{\\bm{p}}(s)\\}\\\\\n&= \\sup_{\\bm{s} \\in \\mathbb{R}^2} \\left\\{- \\bm{s} \\cdot N \\bm{p} + N \\frac{D_r}{4} a_{\\mathrm{Mathieu}, 0}\\left(\\frac{2}{D_r} \\sqrt{s_x^2 + s_y^2}\\right)\\right\\},\n\\end{aligned}\n\\end{equation}\nwe obtain the rate function. We note that both $\\psi_{\\bm{p}}(\\bm{s})$ and $I(\\bm{p})$ are cylindrically symmetric.\\\\\n\nWe have the following expansion of the SCGF for small $s$ \\cite{abramowitz1948handbook},\n\\begin{equation}\n\\begin{aligned}\n\\psi_{\\bm{p}}(\\bm{s}) &= - \\frac{D_r}{4} \\left(-\\frac{1}{2} \\left(\\frac{2}{D_r} \\sqrt{s_x^2 + s_y^2}\\right)^2 + \\mathcal{O}(|\\bm{s}|^4)\\right),~ s \\to 0\\\\\n&= \\frac{1}{2} (s_x^2 + s_y^2) \\frac{1}{D_r} + \\mathcal{O}(|\\bm{s}|^4) ,~ s \\to 0,\n\\end{aligned}\n\\end{equation}\nand thus with\n\\begin{equation}\n\\begin{aligned}\n\\left(\\frac{\\partial^2}{\\partial s_x^2} + \\frac{\\partial^2}{\\partial s_y^2}\\right) \\psi_{\\bm{p}}(\\bm{s}) &= N \\tau \\left(\\left<p_{x,\\tau}^2 + p_{y,\\tau}^2\\right>_{\\bm{s}} - \\left<p_{x,\\tau}\\right>^2_{\\bm{s}} - \\left<p_{y,\\tau}\\right>^2_{\\bm{s}}\\right) = N \\tau \\left(\\left<\\bm{p}_{\\tau}^2\\right>_{\\bm{s}} - \\left<\\bm{p}_{\\tau}\\right>^2_{\\bm{s}}\\right)\\\\\n&= N \\tau \\mathrm{Var}(\\bm{p}_{\\tau})_{\\bm{s}},\n\\end{aligned}\n\\end{equation}\nwe get\n\\begin{equation}\n\\mathrm{Var}(\\bm{p}_{\\tau})_0 = \\frac{2}{N \\tau D_r},\n\\end{equation}\nand thus\n\\begin{equation}\n\\begin{aligned}\nI(\\bm{p}) &= \\frac{1}{2} \\bm{p} \\cdot \\begin{pmatrix} \\left. \\frac{\\partial^2 I}{\\partial p_x^2} \\right|_0 & \\left. \\frac{\\partial^2 I}{\\partial p_x \\partial p_y}  \\right|_0 \\\\ \\left. \\frac{\\partial^2 I}{\\partial p_x \\partial p_y}  \\right|_0 & \\left. \\frac{\\partial^2 I}{\\partial p_y^2} \\right|_0 \\end{pmatrix} \\bm{p} + \\mathcal{O}(\\bm{p}^4)\\\\\n&= \\frac{1}{2} D_r \\bm{p}^2 + \\mathcal{O}(\\bm{p}^4),\n\\end{aligned}\n\\end{equation}\nthe rate function (see Fig. \\ref{mathieu_rate_fig} \\textbf{(left)}), considering $I(0) = 0$ and $I(\\bm{p}) = I(-\\bm{p})$.\\\\\n\nWe can compare the rate function to numerical results from the cloning simulations of Brownian rotors biased with respect to their squared polarisation, and the semi-analytical upper bound $-\\inf_s \\tilde{B}_{s,p^2}$ obtained in this case \\cite{brownian_rotors_ldp} (see Fig. \\ref{mathieu_rate_fig} \\textbf{(centre)}).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.32\\textwidth]{mathieu_rate.eps}\n\\includegraphics[width=0.32\\textwidth]{rate_cloning.eps}\n\\includegraphics[width=0.32\\textwidth]{polarisation_x.eps}\n\\caption{\\textbf{(left)} Rate function. -- Using \\textsc{Mathieu} in \\href{https://github.com/yketa/active_work/blob/master/rotors.py}{\\faGithub~ yketa/active\\_work/rotors.py}. \\textbf{(centre)} Comparison to numerics -- $N_{\\mathrm{clones}} = 10^3$, $t_{\\mathrm{max}} = 10^2$. \\textbf{(right)} Biased average of the polarisation along the x-axis.}\n\\label{mathieu_rate_fig}\n\\end{figure}\n\n\\section{Optimal control potential}\n\nWe have that the tilted generator is self-adjoint (hermitian), so that the left and right eigenfunctions are identical. We thus have the eigenfunction for the $\\bm{s} \\parallel \\bm{e}_x$ problem,\n\\begin{equation}\n\\mathcal{F}_s(\\theta) \\propto y_{Mathieu, 0}\\left(\\frac{\\theta}{2}, \\frac{2s}{D_r}\\right)\n\\end{equation}\nwith $y_{Mathieu, 0}$ the $0$-th Mathieu function, even and $\\pi$-periodic, so that $\\mathcal{F}_s(\\theta)$ is $2\\pi$-periodic, associated to the eigenvalue $\\psi_{p}(s)$. We can thus compute the optimal control potential \\cite{jack2019ergodicity}\n\\begin{equation}\n\\phi_s(\\theta) = - 2 \\log \\mathcal{F}_s(\\theta)\n\\label{control_potential}\n\\end{equation}\nto achieve the fluctuations characteristic to the biased trajectories. We can compute the curvature of this potential at $\\theta = 0$,\n\\begin{equation}\n\\left. \\frac{\\partial^2}{\\partial \\theta^2} \\phi_s(\\theta) \\right|_{s=0} = 2 \\left(\\mathcal{F}(\\theta = 0)^{-2} \\left(\\frac{\\partial}{\\partial \\theta} \\mathcal{F}(\\theta = 0)\\right)^2 - \\mathcal{F}(\\theta = 0)^{-1}\\frac{\\partial^2}{\\partial\\theta^2} \\mathcal{F}(\\theta = 0)\\right),\n\\end{equation}\nwhere\n\\begin{equation}\n\\frac{\\partial}{\\partial \\theta} \\mathcal{F}(\\theta = 0) = 0,\n\\end{equation}\nby parity of $y_{Mathieu, 0}$, and\n\\begin{equation}\n\\begin{aligned}\n- \\mathcal{F}(\\theta = 0)^{-1}\\frac{\\partial^2}{\\partial\\theta^2} \\mathcal{F}(\\theta = 0) &= \\left. - y_{Mathieu, 0}\\left(\\frac{\\theta}{2}, \\frac{2s}{D_r}\\right)^{-1}\\frac{\\partial^2}{\\partial\\theta^2} y_{Mathieu, 0}\\left(\\frac{\\theta}{2}, \\frac{2s}{D_r}\\right) \\right|_{\\theta=0}\\\\\n&= \\frac{1}{4} \\left(a_{\\mathrm{Mathieu}, 0}\\left(\\frac{2s}{D_r}\\right) - 2 \\frac{2s}{D_r}\\right)\n\\end{aligned}\n\\end{equation}\nfrom the differential equation defining $y_{Mathieu, 0}$ (Eq. (\\ref{1P_eigenproblem})), therefore\n\\begin{equation}\n\\left. \\frac{\\partial^2}{\\partial \\theta^2} \\phi_s(\\theta) \\right|_{s=0} = \\frac{1}{2} \\left(a_{\\mathrm{Mathieu}, 0}\\left(\\frac{2s}{D_r}\\right) - 2 \\frac{2s}{D_r}\\right),\n\\end{equation}\nso we can compare this optimal potential to a potential $\\phi^{(g)}_s \\propto g (1 - \\cos\\theta)$,\n\\begin{equation}\n\\phi^{(g)}_s(\\theta) = \\left. \\frac{\\partial^2}{\\partial \\theta^2} \\phi_s(\\theta) \\right|_{s=0} (1 - \\cos\\theta) = \\frac{1}{2} \\left(a_{\\mathrm{Mathieu}, 0}\\left(\\frac{2s}{D_r}\\right) - 2 \\frac{2s}{D_r}\\right) (1 - \\cos\\theta),\n\\end{equation}\nof identical curvature at $\\theta = 0$ (see Fig. \\ref{mathieu_potential_fig} \\textbf{(left)}).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.32\\textwidth]{mathieu_potential.eps}\n\\includegraphics[width=0.32\\textwidth]{distribution_g.eps}\n\\caption{\\textbf{(left)} Optimal control potential. \\textbf{(Right)} Torque parameter, where the factor $1/2$ stems from Eq. (\\ref{control_potential}). -- Using \\textsc{Mathieu} in \\href{https://github.com/yketa/active_work/blob/master/rotors.py}{\\faGithub~ yketa/active\\_work/rotors.py}.}\n\\label{mathieu_potential_fig}\n\\end{figure}\n\n\\bibliographystyle{unsrt}\n{\\renewcommand{\\bibname}{References}\\bibliography{ref}}\n\n\\end{document}\n", "meta": {"hexsha": "94598ad823ee38e0a1f69299c63c7c7aaf7b05c1", "size": 9228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Summaries/Mathieu/main.tex", "max_stars_repo_name": "yketa/DAMTP_2019_Wiki", "max_stars_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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": "Summaries/Mathieu/main.tex", "max_issues_repo_name": "yketa/DAMTP_2019_Wiki", "max_issues_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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": "Summaries/Mathieu/main.tex", "max_forks_repo_name": "yketa/DAMTP_2019_Wiki", "max_forks_repo_head_hexsha": "9995202a586d5f301f2bdffe868b1fcec6fbb990", "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.9220779221, "max_line_length": 353, "alphanum_fraction": 0.6801040312, "num_tokens": 3514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6218219654627157}}
{"text": "\n\n\n\\chapter{Measures of distance}\n\\label{dist}\n\nWe take a little time out here to consider some ideas regarding multivariate distance and introduce some properties of multivariate distance matrices.   These concepts are most obviously relevant when considering multivariate technique such as cluster analysis and scaling methods, where we wish to examine the difference between individuals.   In doing this, we need to find some definition of the concept of ``difference between individuals'', and will therefore consider a range of proximity measures.   We also provide some discussion of difference between variables.   These are currently important concepts in bio-informatic applications but earlier work in multivariate statistics involved consideration of variables which may be carrying similar information where cluster analysis of variables could be used as a preliminary data analytical exercise.   We start by considering one particular measure, the Mahalanobis distance.\n\n\\section{Mahalanobis Distance}\n\\label{standarddist}\n\nThe Mahalanobis distance has an important role in multivariate theory, albeit this is often an implied consideration rather than an explicit one.   For example, development of forms of discriminant analysis considered in chapter \\ref{discriminant} involve this measure.   There are however a number of important distributional properties of the Mahalanobis distance which could be more used in determining multivariate normality.    It should be noted that use of standard distance requires a parametric view of the world, and in particular it is most applicable for symmetric distributions.   We follow \\cite{Flury:1997} in providing the following exposition of the standard distance.  \n\nFirstly, if we consider the \\emph{univariate} standard distance we see that this is a measure of the absolute distance between two observations in units of their standard deviation.\n\\marginnote{The standardisation is important; this measure it is invariant under non-degenerate linear transformations.   A univariate example would be given by considering $Y = \\alpha  + \\beta X$, where $\\beta \\neq 0$ and $\\alpha$ are fixed constants.   Consider transforming $x_{1}$ and $x_{2}$ to $y_{i} = \\alpha + \\beta x_{i}; i = 1,2$. Then considering the standard distance between these two transformed variables we find:\n\n\\begin{eqnarray*}\nd(y_{1},y_{2}) &=& \\frac{|y_{1} - y_{2}|}{\\sqrt{var(Y)}}\\\\\n &=&  \\frac{|\\beta(x_{1} - x_{2}|)}{\\sqrt{\\beta^{2}\\sigma^{2}}}\\\\\n &=& d(x_{1},x_{2})\n\\end{eqnarray*}\n}\nGiven $X$, a random variable with mean $\\mu$ and variance $\\sigma^{2} > 0$, the \\emph{standard distance}, between two numbers $x_{1}$ and $x_{2}$ is defined as follows:\n\n\\begin{displaymath}\nd(x_{1}, x_{2}) = \\frac{|x_{1} - x_{2}|}{\\sigma}\n\\end{displaymath}\n\n\\marginnote{Where $\\sigma = 1$, this standard distance is the same as the Euclidean distance given later in section \\ref{euclidean}}.\n\nThe univariate standard distance has a straightforward generalisation to a multivariate setting.   Considering now two vectors  $\\boldsymbol{x}_{1}$ and $\\boldsymbol{x}_{2}$, with a common covariance matrix $\\boldsymbol{\\Sigma}$ the multivariate standard distance is given by:\n\n\\begin{displaymath}\nd(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2}) = \\sqrt{(\\boldsymbol{x}_{1} - \\boldsymbol{x}_{2})^{T}\\boldsymbol{\\Sigma}^{-1}(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2}) }\n\\end{displaymath}\n\nDepending on whichever textbook is consulted, this multivariate standard distance may be referred to as the \\emph{statistical distance}, the \\emph{elliptical distance} or the \\emph{Mahalanobis distance}.   \\cite{Flury:1997} notes that the squared Mahalanobis distance $d(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2})^{2}$ is sometimes simply referred to as the Mahalanobis distance, although it is not a valid distance measure.   We refer here to the multivariate standard distance,  $d(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2})$ as the Mahalanobis distance, and where necessary, to  $d(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2})^{2}$ as the \\emph{squared} Mahalanobis distance.\n\n\nIt is worth noting that this measure was originally proposed by\n\\cite{Mahalanobis:1930} as a measure of distance between two populations:\n\n\\begin{displaymath}\n\\Delta(\\boldsymbol{\\mu}_{1},\\boldsymbol{\\mu}_{2}) = \\sqrt{(\\boldsymbol{\\mu}_{1} - \\boldsymbol{\\mu}_{2})^{T}\\boldsymbol{\\Sigma}^{-1}(\\boldsymbol{\\mu}_{1},\\boldsymbol{\\mu}_{2}) }\n\\end{displaymath}\nwhich has an obvious sample analogue as the distance between two mean vectors:\n\n\\begin{displaymath}\n\\Delta(\\boldsymbol{\\bar{x}}_{1},\\boldsymbol{\\bar{x}}_{2}) = \\sqrt{(\\boldsymbol{\\bar{x}}_{1} - \\boldsymbol{\\bar{x}}_{2})^{T}\\boldsymbol{S}^{-1}(\\boldsymbol{\\bar{x}}_{1},\\boldsymbol{\\bar{x}}_{2}) }\n\\end{displaymath}\nwhere $\\boldsymbol{S}$ is the pooled estimate of $\\boldsymbol{\\Sigma}$ given by $\\boldsymbol{S} = \\left[ (n_{1}-1) \\boldsymbol{S}_{1} +  (n_{2}-1) \\boldsymbol{S}_{2} \\right] / (n_{1} + n_{2} - 2)$.\n\nHere, we are going to consider the distance between $\\boldsymbol{x}$, a vector of random variables with mean $\\boldsymbol{\\mu}$ and covariance matrix $\\boldsymbol{\\Sigma}$ and its mean:\n\n\\begin{displaymath}\n\\Delta(\\boldsymbol{x},\\boldsymbol{\\mu}) = \\sqrt{(\\boldsymbol{x} - \\boldsymbol{\\mu})^{T}\\boldsymbol{\\Sigma}^{-1}(\\boldsymbol{x},\\boldsymbol{\\mu}) }\n\\end{displaymath}\nand clearly we can find a sample analogue by estimating $\\boldsymbol{\\mu}$ by $\\hat{\\boldsymbol{x}}$ and $\\boldsymbol{\\Sigma}$ by $\\boldsymbol{S} = \\frac{1}{n-1} \\boldsymbol{X}^{T}\\boldsymbol{X}$.  We note that in \\textbf{R}, the \\verb+mahalanobis()+ function is intended to returns the \\emph{squared} multivariate distance between a matrix $\\boldsymbol{X}$ and a mean vector $\\boldsymbol{\\mu}$, given a user-supplied covariance matrix $\\boldsymbol{\\Sigma}$, i.e. we wish to calculate: \n\n\\begin{displaymath}\nd(\\boldsymbol{x}_{i},\\hat{\\boldsymbol{\\mu}})^{2} \n= (\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}})^{T}\n\\hat{\\boldsymbol{\\Sigma}}^{-1}\n(\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}}) \n\\end{displaymath}\n\nWe could also consider the Mahalanobis angle $\\theta$ between two vectors at the origin:\n\n\\begin{displaymath}\n\\cos \\theta = \\frac{\\boldsymbol{x}_{1}^{T} \\boldsymbol{S}^{-1} \\boldsymbol{x}_{2}}\n{d(\\boldsymbol{x}_{1},\\boldsymbol{0})d(\\boldsymbol{x}_{2},\\boldsymbol{0})}\n\\end{displaymath}\n\nThis can be extracted from within $\\boldsymbol{R}$ using the following:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> mahangle <- function(x1, x2, covmat){\n+   zero <- vector(\"numeric\", length(x1) )  \n+   num <- t(x1) %*% solve(covmat) %*% x2\n+   denom <- sqrt(mahalanobis(x1, zero, covmat)) * \n+      sqrt(mahalanobis(x2, zero, covmat)) \n+   angle <- acos(num / denom)\n+   return(angle)\n+ }\n\\end{Sinput}\n\\end{Schunk}\n\n\\subsection{Distributional properties of the Mahalanobis distance}\n\nRemembering that where $z_{1}, \\ldots, z_{p} \\sim N(0,1)$, if we form $y = \\sum_{j=1}^{p} z_{j}^{2}$ then $y \\sim \\chi_{p}^{2}$ \\citep{Bilodeau+Brenner:1999}; for multivariate normal data, with $p$ variables, the squared Mahalanobis distance can be considered against a $\\chi_{p}^{2}$ distribution:\n\n\\begin{equation}\n(\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}})^{T}\n\\hat{\\boldsymbol{\\Sigma}}^{-1}\n(\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}}) = \\boldsymbol{z}^{T}\\boldsymbol{z} \\sim \\chi^{2}_{p}\n\\end{equation}\n\nThis immediately affords one method for assessing multivariate normality, quantiles of the Mahalanobis distance of $\\boldsymbol{x}_{i}$, $i = 1, \\ldots, n$ with respect to $\\boldsymbol{\\mu}$ can be plotted against quantiles of the $\\chi^{2}_{p}$ distribution as an assessment of multivariate normality.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = 0.5\\textwidth]{images/DistChiPlot}\n\\caption{QQ plot of squared Mahalahobis distance plotted against $\\chi^{2}$ distribution}\n\\label{qqchimahlanobis}\n\\end{center}\n\\end{figure}\n\nWe can also define contours as a set of points of equal probility in terms of equal Mahalanobis distance:\n\n\\begin{equation}\n(\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}})^{T}\n\\hat{\\boldsymbol{\\Sigma}}^{-1}\n(\\boldsymbol{x}_{i} - \\hat{\\boldsymbol{\\mu}}) = \\boldsymbol{z}^{T}\\boldsymbol{z} = c^{2}\n\\end{equation}\n\nfor any constant $c > 0$.  We will also find later in section \\ref{mahalpca} that the squared Mahalanobis distance is equivalent to the sum of squared prinicipal component scores.   However, this chapter on distance is implicitly geared towards presentations in the chapter \\ref{clustan} on cluster analysis as well as  chapter \\ref{mds} on scaling methods.   In that context it is worth noting that Mahalanobis distance is rarely used in cluster analysis, certainly \\cite{Kendall:1975} points out its limitations in this context.  Sporadic reports in the literature include \\cite{Maronna+Jacovkis:1974} who report use of a particular clustering algorithm, $k$-means, with the Mahalanobis distance whereas \\cite{Gnanadesikan+etal:1993} use it with hierarchical cluster analysis.   This latter work may illustrate one of the difficulties in using the Mahalanobis distance in the requirement to assume a common covariance.     However, whilst not proposing it's use in an automatic clustering algorithm, \\cite{Atkinson+etal:2004} report use of Mahalanobis distance within the forward search to reliably identify subgroups within the data.   They propose a small modification to the Mahalanobis distance for use in cluster analysis as follows.   The Mahalanobis distance is multiplied by $(|\\hat{\\boldsymbol{\\Sigma}}^{-1}_{k}|^{1/2})^{r}$ for group $k$.   Where $r=0$ we have the usual distance, when $r=1$ we have what they call the \\emph{standardised} Mahalanobis distance which eliminates the different variance between groups.\n\nHaving provided an overview of one distributionally important distance measure, before considering further measures we consider a few definitions.   \\cite{Flury:1997} notes that the squared Mahalanobis distance does not satisfy the axioms of distance.\n\n\\section{Definitions}\n\\label{distdefinitions}\n\nWe now formalise our idea of a proximity measure.  This term encapsulates both similarity and disssimilarity measures which have the obvious interpretation (measuring similarity and dissimilarity between entities), and can be found from each other by means of an appropriate monotonic transformation.   We usually assume that these measures are symmetic.\n\nA \\emph{distance} can be defined as a function $d(\\cdot)$ that satisfies the following properties:\n\n\\begin{itemize}\n\\item[(1)] Non-negative, that is $d(\\boldsymbol{x},\\boldsymbol{y}) \\geq 0$ for all $\\boldsymbol{x},\\boldsymbol{y} \\in \\mathbb{R}^{p}$ and \n\\item[(2)] Identified, that is $d(\\boldsymbol{x},\\boldsymbol{x}) = 0$ for all $\\boldsymbol{x} \\in \\mathbb{R}^{p}$;\n\\item[(3)] Symmetric, that is $d(\\boldsymbol{x},\\boldsymbol{y}) = d(\\boldsymbol{y},\\boldsymbol{x})$ for all $\\boldsymbol{x},\\boldsymbol{y} \\in \\mathbb{R}$;\n\\end{itemize}\n\nIn addition to satisfying these three properties, a \\emph{metric} also satisfies the following two properties:\n\\begin{itemize}\n\\item[(4)] Definite, that is $d(\\boldsymbol{x},\\boldsymbol{y}) = 0$ if and only if $\\boldsymbol{x} = \\boldsymbol{y}$ for all $\\boldsymbol{x},\\boldsymbol{y} \\in \\mathbb{R}^{p}$;\n\\item[(5)] Triange inequality $d(\\boldsymbol{x},\\boldsymbol{y}) + d(\\boldsymbol{y},\\boldsymbol{z}) \\geq d(\\boldsymbol{x},\\boldsymbol{z})$ for all $\\boldsymbol{x},\\boldsymbol{y},\\boldsymbol{z} \\in \\mathbb{R}$  \n\\end{itemize}\n\n\nIt is worth noting that it is possible to compute a similarity measure, often denoted $s$, where $0 \\leq S \\leq 1$.   A \\emph{similarity} function $s(\\cdot,\\cdot)$ satisfies (1) non-negativity $s(\\boldsymbol{x}, \\boldsymbol{y}) \\geq 0$, (2) symmetry $S(\\boldsymbol{x},\\boldsymbol{y}) = s(\\boldsymbol{y},\\boldsymbol{x})$ as well as:\n\n\\begin{itemize}\n\\item[(3)] $s(\\boldsymbol{x}, \\boldsymbol{y})$ increases in a monotone fashion as $\\boldsymbol{x}$ and $\\boldsymbol{y}$ become more similar.   A \\emph{dissimilarity} function satisfies the first two but clearly 3 is reversed, i.e. it decreases as  $\\boldsymbol{x}$ and $\\boldsymbol{y}$ become more similar.  \n\\end{itemize}\n\nDissimilarity is the opposite of similarity, therefore any monotonically decreasing transformation of $s$ can provide a dissimilarity measure.   The most obvious tranform would be to take $d = 1 - s$ but we will consider a few alternatives later.\n\n\\section{Distance between points}\n\\label{pointdistance}\n\nTwo \\textbf{R} packages are needed to provide most of the distance functions considered here.   In addition to the default \\verb+stats+ library, which provides the \\verb+dist()+ function, we require the \\verb+cluster+ package for the \\verb+daisy()+ function.   Some further correlation based measures can be found in the \\verb+Dist()+ function in the \\verb+amap+ package as well as \\verb+BioBase+ from Bioconductor.\n\nWe now consider a range of ways in which a multivariate distance can be measured.  In conducting an analysis, some decision needs to be made as to whether to scale variables, or whether to remove highly correlated variables from the analysis.   For example, \\cite{Gnanadesikan:1997} gives an artificial example which illustrates how rescaling variables can subsequently alter impression of groupings.\n\n\n\\subsection{Quantitative variables - Interval scaled}\n\\label{distancequant}\n\nIt is reasonably straightforward to suggest a number of dissmilarity measures $d_{ij}$ which measure the distance between individual $i$ and $j$.\n\n%\\begin{itemize}\n%\\item \n\\subsection{Euclidean distance}.\n\\label{euclidean}\n\nThe Euclidean distance, or the $l_{2}$ norm, is perhaps the most commonly used distance measure.   As mentioned in section \\ref{standarddist}, this distance could be considered simply as the Mahalanobis distance where $\\sigma$ = 1.   Especially in the context of cluster analysis, where we hope to identify distinct sub-groups within the data, it is not clear how we might determine the covariance matrix hence the Mahalanobis distance has seen little use.   The Euclidean distance, which is quite simply the square root of the squared distance between any two vectors, which can be quite simply interpreted as the physical distance between two $p$-dimensional points is also a convenient measure to understand.  Formally, we can express this measure as:\n\n\\begin{displaymath}\n\\label{euclideanF}\nd_{ij} =  \\left( \\Sigma_{k=1}^{p} (x_{ik} - x_{jk})^2 \\right)^{\\frac{1}{2}}\n\\end{displaymath}\n\nwhere we are trying to measure the distance between observations in row $i$ and row $j$, in other words $x_{ik}$ is the $k$th observation in row $i$, and $x_{jk}$ is the corresponding $k$th observation in row $j$.   Euclidean distance can be readily calculated in \\textbf{R} using the \\verb+dist()+ function with the default \\verb+method = \"euclidean\"+, as well as by \\verb+daisy()+ with the default \\verb+metric = \"euclidean\"+, although in \\verb+daisy()+ it is possible to standardise the data within the calculations by adding \\verb+stand = TRUE+ to the function call.\n \n\n\\subsection{Scaled Euclidean distance}\n\\label{scaledeuclidean}\n\nIt is possible to introduce a suitable weight $w_{k}$ such as the inverse of the standard deviation of the $k$th variable, i.e. $w_{k} = s_{k}^{-1}$, or even the inverse of the range of the data.\n\n\\begin{displaymath}\n\\label{scaledeuclideanF}\nd_{ij} = \\sqrt{\\left( \\Sigma_{k=1}^{p} w_{k}^{2}(x_{ik} - x_{jk})^2 \\right)}\n\\end{displaymath}\n\nNo explicit routines are available to compute this measure, but clearly if the co-ordinates are rescaled by $\\sqrt{w_{k}}$ this can be calculated implicitly.\n\n\\subsection{City Block metric}\n\\label{cityblock}\n\nThe City Block metric, formally referred to as an $l_{1}$ norm, measures the absolute difference between two vectors.   It is so-named because it measures the distance between two points in terms of movements parallel to the axis and therefore resembles the distance between two points in a city.   \\cite{Krause:1975} (who had obviously never been in a London taxi) called this distance the \\emph{taxicab} distance, \\cite{Brandeau+Chiu:1988} used the term \\emph{rectilinear}, but perhaps the most common alternative name is \\emph{Manhattan}, suggested by \\cite{Larson+Sadiq:1983} reflecting the famous city block layout in Manhattan.   Formally, we can express this distance as:\n\n\\begin{displaymath}\n\\label{cityblockF}\nd_{ij} =  \\left( \\Sigma_{k=1}^{p} |x_{ik} - x_{jk}| \\right)\n\\end{displaymath}\n\nIt can be calculated in R using the \\verb+dist()+ function with \\verb+method = \"manhattan\"+\n\n\n\n\\subsection{Minkowski metric}\n\\label{minkowski}\n\nThe Minkowski metric, or the $l_{r}$ norm, is a generalisation of the Manhattan and Euclidean distances.\n\n\\begin{displaymath}\n\\label{minkowskiF}\nd_{ij} =  \\left( \\Sigma_{k=1}^{p} |x_{ik} - x_{jk}|^\\lambda \\right)^{1/\\lambda}\n\\end{displaymath}\n\nWhere $\\lambda = 1$ we have the Manhattan metric, where $\\lambda = 2$ we have the Euclidean distance.   It can be noted that increasing $\\lambda$ exaggerates dissimilar units relative to similar ones.   This metric can be calculated in R using the \\verb+dist()+ function with \\verb+method = \"minkowski\"+ but additionally requires an argument to \\verb+p+ to set $\\lambda$, the power of this distance.   Therefore, for example \\verb+dist(x, method = \"minkowski\", p=2)+ gives the Euclidean distance for matrix \\verb+x+. \n\n\\subsection{Canberra metric}\n\\label{canberra}\n\nThe Canberra metric \\citep{Lance+Williams:1966} can be regarded as a generalisation of binary dissimilarity measures, and is very sensitive to small changes close to $x_{ik} = x_{jk} = 0$.   It can be scaled by division by $p$, the number of variables to ensure it lies in the range (0,1).   Terms with zero numerator and denominator are omitted from the sum and treated as if the values were missing.\n\n\\begin{displaymath}\n\\label{canberraF}\nd_{ij} = \\left\\{ \\begin{array}{ll} 0 & for\\ x_{ik} = x_{jk} = 0\\\\\n  \\Sigma\\left( \\frac{|x_{ik} - x_{jk}|}{ |x_{ik} + x_{jk}|} \\right) & for\\  x_{ik} \\neq 0\\ or\\  x_{jk} \\neq 0 \\end{array} \\right.\n\\end{displaymath}\n\nThis metric can be calculated in \\textbf{R} using the \\verb+dist()+ function with \\verb+method = \"canberra\"+\n\n\\subsection{Czekanowski Coefficient}\n\\label{czekanowski}\n\nFinally, we mention the Czekanowski Coefficient, which for continuous variables can be given as:\n\n\\begin{displaymath}\n\\label{czekanowskiF}\nd_{ij} = 1 - \\frac{2 \\sum_{k=1}^{p} min(x_{ik},x_{jk})}{\\sum_{k=1}^{p}(x_{ik} + x_{jk})}\n\\end{displaymath}\n\n%\\end{itemize}\n\n\n\\subsection{Distance between variables}\n\\label{corrdist}\n\nWe next consider a number of correlation based distance measures.   Note that when used conventionally for calculating the correlation between two variables we work with standardised columns.  In order to measure the similarity between two individuals we must therefore work with standardised rows, this may not be a sensible procedure.   For example, if variables are measured on different scales the idea of a row mean may not be clear.   There is further material in the literature questioning the use of these measures \\citep{Jardine+Sibson:1971,Fleiss+Zubin:1969} and \\cite{Everitt+etal:2001} note that correlation measures cannot distinguish the size of two different observations, giving the example $\\boldsymbol{x}^{T}_{1} = c(1,2,3)$ and $\\boldsymbol{x}^{T}_{2} = c(1,2,3)$ have correlation $\\rho_{12} = 1$ yet $\\boldsymbol{x}^{T}_{2}$ is three times the size of $\\boldsymbol{x}^{T}_{1}$.   Nevertheless, correlation based measures have become particular popular in a bio-informatics setting where some of the noted limitations do not apply (all variables are measured on a comparable scale) and in fact it is not always clear what a row and a column mean in that application area.   \n\nWe therefore consider four four distances that can be obtained a correlation measure.  Some thought needs to be given to determining the transformation from a correlation coefficient to a distance measure.   The Pearson correlation coefficient is defined in the range $-1 \\leq \\rho_{ij} \\leq 1$.   \\cite{Everitt+etal:2001} suggest using $d_{ij} = \\frac{1 - \\rho_{ij}}{2}$.  \\cite{Gentleman+etal:2005} suggest that it may be appropriate under some circumstances to use the absolute value of the correlation, that is $d_{ij} = 1 - |\\rho_{ij}|$ which means that there will be little distance between rows having strong positive and strong negative correlation.   In terms of measuring the dissimilarity between variables, \\cite{Krzanowski:2000} suggests a further alternative using  $d_{ij} = 1 - (\\rho_{ij})^{2}$.   Examining pre-Bioinformatics data, \\cite{Lance+Williams:1979} who compared a number of transformations and expressed a strong preference for the first transformation, and a strong disdain for the third.\n\nIt should be noted that these measures are quite badly affected by outliers.   As a result, non-parametric versions may often be preferred.   Conversely, these measures are invariant to change of location or scale transformation which is rather useful.   It should be noted in bio-informatics practice that they tend to group genes whose expression patterns are linearly related, there is some empirical support from that application for their use in a particular context.\n\n\\subsection{Pearson correlation distance}\n\\label{pearsondist}\n\n\\begin{displaymath}\n\\label{pearsondistF}\nd(x_{ij},x_{ik}) = 1 - \\rho_{ij} = 1 - \\frac{\\sum_{i=1}^{p} (x_{ij} - \\bar{x}_{\\cdot j}) (x_{ik} - \\bar{x}_{\\cdot k}}{\\sqrt{\\sum_{i=1}^{p} (x_{ij} - \\bar{x}_{\\cdot j})^{2} \\sum_{i=1}^{p} (x_{ik} - \\bar{x}_{\\cdot k})^{2}}}\n\\end{displaymath}\n\nWhere data are scaled, i.e. mean centred and standardised by the variance so that $\\boldsymbol{x}_{\\cdot j}$ and $\\boldsymbol{x}_{\\cdot k}$ are $p$ variable vecotres with zero mean and unit variance the relationship between the Euclidean distance and the Pearson correlation is given by:\n\n\\begin{displaymath}\nd_{ij}^{(Euclidean)} = \\sqrt{2p(1-\\rho_{ij})}\n\\end{displaymath}\n\nThe pearson based distance measure can apparently be obtained from \\verb+Dist()+ in the \\verb+amap+ package, where it is referred to as the ``Centred Pearson'' by specifying \\verb+method = \"correlation\"+ in the function call.  \n\n\\subsection{Cosine correlation coefficient}\n\\label{cosinedist}\n\nThis is similar to the Pearson Correlation coefficient based distance measure but without the mean standardisation\n\n\\begin{displaymath}\n\\label{cosinedistF}\nd(x_{ij},x_{ik}) = 1 - \\frac{\\boldsymbol{x}_{\\cdot j}^{T} \\boldsymbol{x}_{\\cdot k}}{||\\boldsymbol{x}_{\\cdot j}|| ||\\boldsymbol{x}_{\\cdot k}||} = 1 - \\frac{|\\sum_{i=1}^{p} (x_{ij}) x_{ik} }{\\sqrt{\\sum_{i=1}^{p} x_{ij}^{2} \\sum_{i=1}^{p} x_{ik}^{2}}}\n\\end{displaymath}\n\n\nThe cosine correlation based distance measure, referred to as the ``Not-centred Pearson  can be obtained from \\verb+Dist()+ in the \\verb+amap+ package by specifying \\verb+method = \"pearson\"+ in the function call.    It is not clear from the help file how the correlation measure is transformed into a distance measure.\n\n\\subsection{Spearman sample correlation distance}\n\\label{spearmandist}\n\n\\begin{displaymath}\n\\label{spearmandistF}\nd(x_{ij},x_{ik}) = 1 - \\rho_{ij} = \n1 - \\frac{\\sum_{i=1}^{p} (rank(x)_{ij} - rank(\\bar{x})_{\\cdot j}) (rank(x)_{ik} - rank(\\bar{x})_{\\cdot k})}\n{\\sqrt{\\sum_{i=1}^{p} (rank(x)_{ij} - rank(\\bar{x})_{\\cdot j})^{2} \\sum_{i=1}^{p} ( rank(x)_{ik} - rank(\\bar{x})_{\\cdot k})^{2}}}\n\\end{displaymath}\n\nThis requires \\verb+spearman.dist()+ in package \\verb+bioDist+, and can be computed via \\verb+Dist()+ in the \\verb+amap+ package with a call containing \\verb+method=\"spearman\"+.\n\n\n\\subsection{Kendall's $\\tau$ sample correlation distance}\n\\label{kendalltaudist}\n\n\\begin{displaymath}\n\\label{kendalltaudistF}\nd(x_{ij},x_{ik}) = 1 - \\tau_{ij} = 1 - \\frac{\\sum_{i=1}^{p} sign(x_{ij} - \\bar{x}_{\\cdot j}) sign(x_{ik} - \\bar{x}_{\\cdot k})}{p(p-1)}\n\\end{displaymath}\n\nThis requires \\verb+tau.dist()+ in package \\verb+bioDist+\n\n\n\\subsection{Quantitative variables: Ratio Scaled}\n\n\\cite{Kaufman+Rousseeuw:1989} briefly discuss ratio scaled variables, and give examples including micro-organism growth which follows and exponential power law.   Clearly, we could just consider these as interval scale variables and use any of the previous measures.   They discuss the possibility of taking a logarithmic transformation of such data where it may be appropriate, obviously having the exponential growth application in mind.  The logarithmic transformation can be dealt with in \\verb+daisy()+ by using the \\verb+type=\"logratio\"+ command.   Alternatively, it would be possible to treat such variables as being continuous ordinal data and use rank-based non-parametric procedures.   As discussed further in section \\ref{qualitative}, using the  \\verb+type=\"ordratio\"+ command within \\verb+daisy()+ generates standardised variates from the ranks which are subsequently analysed with a scaled City Block metric, alternativly, the two non-parameteric correlation derived measures described in section \\ref{spearmandist} and \\ref{kendalltaudist} may also be useful.\n\n\\subsection{Dichotomous data}\n\\label{dichotomousdist}\n\nWhere $x_{ik}$ can only take one of two values, these are coded as $0$ and $1$:\n\n\\begin{tabular}{lr|cc}\n & & Object & Two \\\\\n & & 1 & 0\\\\\n\\hline\n & 1 & a & b\\\\\nObject 2 & & & \\\\\n & 0 & c & d\\\\\n\\end{tabular}\nwhere $p = a + b + c + d$, some common dissimilarity measures are:\n\nIn this table, $a$ denotes an agreement (both objects have a zero in the same position), $d$ shows an agreement where both objects have a one, $c$ and $d$ denote the two possible disagreements.    We should firstly comment in more detail on the nature of dichotomous data.   \\cite{Gower:1971} distinguishes two types of binary variables, symmetric and assymetric.   Binary variables such as gender (male and female) or handedness (left or right) are clearly symmetric and the distance measure should not change depending on the way we code these two levels as 0 and 1.   In other words, $a$ and $d$ should act the same way in the table.   \n\nWe can therefore consider the following symmetric measures.\n\n\\subsection{(Based on the) simple matching coefficient}\n\nThe \\emph{simple matching coefficient}, also known as the \\emph{M-coefficient} or the \\emph{affinity index}, is quite simply the proportion of variables in agreement in two objects.   The distance measure is found by subtracting this value from 1 (or calculating the proportion of disagreements):\n\n\\begin{equation}\n\\label{simplematch}\nd_{ij} = 1 - \\frac{a + d}{a + b + c + d} = \\frac{b + c}{a + b + c + d}\n\\end{equation}\n\nThis measure can be calculated in \\verb+daisy()+ by providing a list indicating those variables to be regarded as symmetric, i.e. \\verb+(list(\"symm\", \"symm\", \"symm\")+.   It may be noted in passing that if we force a calculation of Manhattan distance we get estimate $b+c$ we omit standardisation and simply calculate the sum of disagreements.   Also, the Euclidean distance is the square root of the dissimilarity derived from the simple matching coefficient.   Two further symmetric measures include \\cite{Rogers+Tanimoto:1960} which doubles the weight of the disagreements:\n\n\\begin{displaymath}\nd_{ij} = 1 - \\frac{a + d}{(a + d) + 2(b + c)} = \\frac{2(b + c)}{(a + d) + 2(b + c)}\n\\end{displaymath}\n\nand the \\cite{Sokal+Sneath:1963} measure which doubles the weight of the agreements:\n\n\\begin{displaymath}\nd_{ij} = 1 - \\frac{2(a + d)}{2(a + d) + (b + c)} = \\frac{b + c}{2(a + d) + (b + c)}\n\\end{displaymath}\n\nAll three measures are monotonically related and there seems little imperative to use anything other than the simple matching coefficient based dissimilarity measure.   Life does however get rather more interesting if we want to work with assymetric binary variables.   Some care is needed in analysis in determining whether binary variables are symmetric or assymetric.   A classical example would concern variables measuring presence or absence.   The thought is that if two individuals share the presence of some attribute we can consider them similar, but if they share the absence of an attribute we do not know whether they can be considered similar.   For example, if we collect data on individuals who travelled to a particular location, we can consider them similar if they both drove by car, but if neither drove by car it is clear there are a range of reasons, which could include not owning a car, preferring another form of transport, living within walking distance and so on.\n\n\\subsection{Jaccard coefficient}\n\nPerhaps the most common assymetric measure of distance is the Jaccard Coefficient \\cite{Sneath:1957}, which measures the proportion of agreements on the variable coded 1 among all such agreements and disagreements (i.e. ignoring all possible agreements on variable coded 0).  Formally, this can be set out as:\n\n\\begin{displaymath}\nd_{ij} = 1 - \\frac{a}{a + b + c} =  \\frac{b + c}{a + b + c}\n\\end{displaymath}\n\nThis seems to be the value calcuated by \\textbf{R}, when \\verb+method=\"binary\"+ is used in the call to \\verb+dist()+, it is also available in \\verb+daisy()+ when the a list is supplied which indicates those variables to be considered as binary assymetric variables, i.e. \\verb+list(\"asym\", \"asym\")+\n\nAs with symmetric measures, there are a few alternatives which alter the weightings.     \n\n\\subsection{Czekanowski coefficient}\n\nThe Czekanowski coefficient \\citep{Dice:1945} increases the weight of the agreements\n\n\\begin{displaymath}\nd_{ij} = 1 - \\frac{2a}{2a + b + c} = \\frac{b + c}{2a + b + c}\n\\end{displaymath}\n\nwhearas the \\cite{Sokal+Sneath:1963} coefficient increases the weight of the disagreements:\n\n\\begin{displaymath}\nd_{ij} = 1 - \\frac{a}{a +2(b + c)} = \\frac{2(b + c)}{a + 2(b + c)}\n\\end{displaymath}\n\n\nWe extract a small part of an example given by \\cite{Kaufman+Rousseeuw:1989} to illustrate the non-monotonicity of the symmetric and asymmetric measures.\n\n\\begin{tabular}{l|rrrrrrrrrr}\nName & $x_{1}$ & $x_{2}$ & $x_{3}$ & $x_{4}$ & $x_{5}$ & $x_{6}$ & $x_{7}$ & $x_{8}$ & $x_{9}$ & $x_{10}$  \\\\\n\\hline\nIlan       & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 0\\\\\nJacqueline & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\\\\nLieve      & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0\\\\\nPeter      & 1 & 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0\\\\\n\\end{tabular}\n\nwhere $x_{1}$ = Sex(Male = 1, Female = 0), $x_{2}$ = Married(Yes = 1, No = 0), $x_{3}$ = Hair(Fair = 1, Dark = 1), $x_{4}$ = Eyes (Blue = 1, Brown = 0), $x_{5}$ = Wears Glasses(Yes = 1, No = 1), $x_{6}$ = Face (Round = 1, Oval = 0), $x_{7}$ = Outlook(Pessimist = 1, Optimist = 0), $x_{8}$ = Type(Evening = 1, Morning = 0) $x_{9}$ = Only Child (1 = Yes, 0 = No) $x_{10}$ = Handedness (1 = Left, 0 = Right).\n\nUsing the symmetric, simple matching coefficient based distance measure they note that:\n\\begin{displaymath}\nd(Jacqueline, Lieve) = 0.300\\ d(Ila, Peter) = 0.500\n\\end{displaymath}  \n\nwhereas for the asymmetric, Jaccard coefficient we have:\n\n\\begin{displaymath}\nd(Jacqueline, Lieve) = 0.750\\ d(Ila, Peter) = 0.714\n\\end{displaymath}  \n\n Although \\cite{Kaufman+Rousseeuw:1989} state that the Jaccard coefficient is inappropriate, it could be argued that some of these variables are assymetric (there are a variety of reasons why someone might record that they were not-married).   Nevertheless, the point of their illustration was to highight the non-monotonicity.   Whilst we expect the measures to be different, note that for the symmetric coefficient $d(Jacqueline, Lieve) < d(Ila, Peter)$, whereas for the assymetric coefficient $d(Jacqueline, Lieve) > d(Ila, Peter)$.  \n\n\n\\subsection{Similarities between variables}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{cccc}\n && \\multicolumn{2}{c}{Variable 1} \\\\\n&& + & - \\\\\nVariable & + & a & b\\\\\n & - & c & d\\\\\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\n\\begin{displaymath}\n\\chi^{2} = \\frac{(ad-bc)^{2} (a + b + c + d)}\n{(a + b)(a + c) (c + d) (b + d)}\n\\end{displaymath}\n\nwhich may require some standardisation:\n\n\\begin{displaymath}\nd_{kl} = 1 - \\sqrt{\\frac{\\chi^{2}}{a  + b + c + d}}\n\\end{displaymath}\n\n\n\\subsection{Qualitative variables}\n\\label{qualitative}\n\nFollowing \\cite{Kaufman+Rousseeuw:1989} we consider a variable where we have $m = 1, \\ldots, M$ states.   It would be possible to create a set of $M$ binary variables, with 0 indicating absence of a particular category within a variable and 1 indicating presence.   Alternatively, a nominal variable could be collapsed in some suitable manner.   However, \\cite{Sokal+Michener:1958} suggest a simple matching coefficient, a corresponding distance can be found by substracting this from 1.   Denoting the number of variables on which objects $i$ and $i$ agree by u, and the total number of variables by $p$ this can be expressed as:\n\n\\begin{displaymath}\nd(x_{ij},x_{ik}) = 1 - \\frac{u}{p} = \\frac{p-u}{p}\n\\end{displaymath}\nThis measure is invariant to the codings used or the order of the variables, and can be extended in the same way as that suggested for binary variables by \\cite{Rogers+Tanomoto:1960} and \\cite{Sokal+Sneath:1963} by doubling the weight of disagreements and agreements respectively.   \\cite{Kaufman+Rousseeuw:1989} review proposals to weight the measure depending on the size of $M$.   \n\nThe simple matching coefficient is available in \\textbf{R} by using \\verb+daisy()+ having specified that the variable concerned is a factor, by ensuring the elements of \\verb+x+ supplied to the function have class \\verb+factor+.\n\nIt's also obvious that such variables can be ordered, and also that ordered variables may be derived from continuous data.   We can either obtain the ranks and treat the ranks as continuous variables applying any of the quantitative distance measures discussed above.   A possible derivation, having first scaled the ranks is given by:\n\n\\begin{displaymath}\n\\label{daisyrank}\nz_{ij} = \\frac{r_{ij} - 1}{M_{j} - 1}\n\\end{displaymath}\n\nWhen using \\verb+daisy()+, if a discrete variable has the class set to \\verb+\"ordered\"+, or if a continuous variable is supplied with the argument \\verb+type = \"ordratio\"+ $z_{ij}$ will be computed as in figure \\ref{daisyrank} and treated as a continuous variable.   Distance will subsequently be computed by means of the City Block distance, which will be scaled by the number of such variables analysed.\n\nAlternative, one of the non-parametric correlation measures in section \\ref{spearmandist} or section \\ref{kendalltaudist} could be used, especially where we are measuring distance between variables rather than between individuals.\n\n\n\\subsection{Different variable types}\n\\label{gowers}\n\nFinally, we consider the possibility that a particular data set contains a variety of variable types.   It might be possible to treat all variables as interval scaled continuous variables, or somehow recode them all as binary or ordinal variables.  It may be better to find some way of combining distance that has been measured in the most appropriate way for each type of variable.  As a result, possibly the most popular method for measuring dissimilarity in this situation has been derived from Gower's coefficient of similarity \\cite{Gower:1971}.   In its original incarnation, this measure could combine interval, nominal and binary data.   Consider the following, where we basically sum the individual similarities however calculated and divide them by the total number of applicable comparisons:\n\n\\begin{equation}\nd(x_{ij},x_{jk}) = 1 - \\frac\n{\\sum_{k=1}^{p} \\delta_{ijk} s_{ijk}}\n{\\sum_{k=1}^{p} \\delta_{ijk}}\n\\end{equation}\n\nThe indicator  $\\delta_{ijk}$ is set to 1 when both measurements for $x_{ij}$ and $x_{ik}$ are non-missing, it is zero otherwise.   It is also zero for binary variables where there is a $0-0$ match, i.e. the original measure assumed assymetric dichotomous variables.   We briefly consider how similarities for each of the three variable types is calculated:\n\n\\begin{itemize}\n\\item Quantitative (interval scaled) variables.\n\nThe similarity measure is given by:\n\\begin{equation}\n\\label{gowercont}\ns_{ijk} = 1 - \\frac{|x_{ik} - x_{jk}|}{range\\ of\\ variable\\ k}\n\\end{equation}\nThis is essentially the City Block distance with the extra assumption that all variables had first been standardised by dividing by their range.   If there are mixed variables within the data frame or matrix \\verb+x+ supplied to \\verb+daisy()+, this standardisation is applied by default (regardless of any arguments supplied to \\verb+stand+.\n\n\\item Qualitative (nominal) variables.\nThese are derived from the simple matching coefficient, the similarity is therefore the proportion of matches among all possible matches:   \n\\begin{displaymath}\ns_{ijk} = \\left\\{ \\begin{array}{r} 1\\ \\mbox{if i and i agree on variable k} \\\\ 0\\ \\mbox{otherwise} \\end{array} \\right.\n\\end{displaymath}\n\n\n\\item Dichotomous variables\nThe original incantation assumed asymmetric variables, hence the Jaccard coeffcient is used.   If we consider $k = 1, \\ldots, 4$ variables for individuals $i$ and $j$, we can see the possible outcomes:\n\\begin{tabular}{rcccc}\n$i$ & 1 & 1 & 0 & 0\\\\\n$j$ & 1 & 0 & 1 & 0\\\\\n\\hline\n$s_{ijk}$ & 1 & 0 & 0 & 0\\\\\n$\\delta_{ijk}$ & 1 & 1 & 1 & 0\\\\\n\\end{tabular}\n\\end{itemize}\n\nThe original measure has been extended by \\cite{Kaufman+Rousseeuw:1989} (who set out the calculations as distances rather than similarities) to incorporate symmetric binary and ordinal and ratio variables.   Ordinal variables are ranked, and the ranks used in \\ref{gowercont}, ratio variables are either ranked or logged and then \\ref{gowercont} is used.   As has been noted earlier, this is achieved by setting the class of the variables to be \"numeric\", \"factor\" or \"ordered\", or providing the arguments \\verb+type =  \"asymm\", \"symm\", \"ordratio\", \"logratio\"+ to estimate appropriate measures for assymetric binary variables (Jaccard), symmetric binary, ordinal ratio variables or log transformed ratio variables respectively.\n\nIt should be noted that \\cite{Gower:1971} shows, provided there are no missing values the $n \\times n$ similarity matrix obtained from an $n \\times p$ data matrix $\\boldsymbol{X}$ is positive semi-definite.   If we obtain a dissimilarity matrix from this measure using $d(x_{ik},x_{jk}) = \\sqrt{(1 - s(x_{ik},x_{jk})}$ the resultant matrix:\n\n\\begin{displaymath}\n\\Delta = \\left( \\begin{array}{rrrr} \n0 & d(\\boldsymbol{x}_{1},\\boldsymbol{x}_{2}) & \\cdots & d(\\boldsymbol{x}_{1},\\boldsymbol{x}_{p})\\\\\nd(\\boldsymbol{x}_{2},\\boldsymbol{x}_{1}) & 0  & \\cdots & d(\\boldsymbol{x}_{2},\\boldsymbol{x}_{p})\\\\\n\\vdots & \\vdots & \\cdots & \\vdots \\\\\nd(\\boldsymbol{x}_{p},\\boldsymbol{x}_{1})  & d(\\boldsymbol{x}_{p},\\boldsymbol{x}_{2}) & \\cdots  & 0 \\end{array} \\right)\n\\end{displaymath}\nis Euclidean.   We will next consider this important property of proximity matrices, it will particularly inform later developments in terms of metric scaling.\n\n\\section{Properties of proximity matrices}\n\nA few words are placed here concerning proximity matrices, the $n \\times n$ matrix comparing every individual with each other.   It is possible that the only information available in a particular study is such a matrix, as happens with sensory experiments or the rather famous study comparing matched judgements on morse code characters \\citep{Rothkopf:1957}.  Some properties of these matrices will be important in later developments, particularly scaling as discussed in chapter \\ref{mds}.   Earlier, in section \\ref{gowers}, we rather glibly stated that a dissimilarity matrix obtained from Gower's coefficient of similarity can be Euclidean.   As might be anticipated, a matrix where the elements have been derived from the Euclidean distance (section \\ref{euclidean}) is also Euclidean, but the concept requires further examination.   \\cite{Gower:1966} demonstrated that Euclidean properties could be met by transforming for the elements $s(x_{i},x_{j})$ of a similarity matrix $\\boldsymbol{S}$ to the elements $d(x_{i},x_{j})$ of a dissimilarity matrix $\\boldsymbol{D}$:\n\n\\begin{displaymath}\nd(x_{i},x_{j}) = \\sqrt{1 - s(x_{i},x_{j})}\n\\end{displaymath}\n\nDenoting the distance between two points by $d(x_{i},x_{j})$ and the proximity between two individuals by $\\delta(x_{i},x_{j})$, we are ultimately interested in the proximity matrix $\\boldsymbol{\\Delta}$\n\nWhen forming a  matrix $\\boldsymbol{\\Delta}$ from a dissimilarity matrix $\\boldsymbol{D}$, \\cite{Lingoes:1971} suggested tranforming the elements by $\\delta(x_{i},x_{j}) = \\sqrt{d(x_{i},x_{j})^{2} + c_{1}}$, \\cite{Cailliez:1983} suggested  $\\delta(x_{i},x_{j}) = d(x_{i},x_{j}) + c_{1}$, both providing methods for finding the constants $c_{1}$ and $c_{2}$.  \n\n\n\nIn general, when considering the $n \\times n$ dissimilarity matrix, $\\Delta$, containing elements $d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot})$.   This matrix can be considered Euclidean if the $n$ individuals can be represented as points in space such that the Euclidean distance between points $i$ and $j$ is $d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot})$.   In general, $\\boldsymbol{\\Delta}$ is Euclidean if and only if the following matrix is positive semi-definite:\n\\begin{displaymath}\n(\\boldsymbol{I} - \\boldsymbol{1}\\boldsymbol{s}^{T}) \\boldsymbol{\\Gamma} (\\boldsymbol{I} - \\boldsymbol{1}\\boldsymbol{s}^{T})\n\\end{displaymath}\nwhere  $\\boldsymbol{\\Gamma}$ has elements $\\frac{1}{2}d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot})^{2}$, $\\boldsymbol{I}$ is the identity matrix, $\\boldsymbol{1}$ is a vector of $n$ ones and $\\boldsymbol{s}$ is an $n$-element vector such that $\\boldsymbol{s}^{T}\\boldsymbol{1} = 1$.   \n\nImportant special cases are where $\\boldsymbol{s} = \\frac{1}{n}\\boldsymbol{1}$ which centres at the origin (proof is given in \\cite{Mardia+etal:1979} regarding the Euclidian property) and where $\\boldsymbol{s}$ which has 1 in its $i$th position and 0 elsewhere (proof is given by \\cite{Gower:1984} of the Euclidean property).   The significance of the Euclidean property will be discussed in chapter \\ref{mds} when we consider scaling methods.\n\n\nIn addition to the Euclidean property, a matrix can be considered \\emph{metric}, if the metric inequality holds for all triplets $i$, $j$, $k$ within $\\boldsymbol{\\Delta}$\n\n\\begin{equation}\n\\label{triangleinequality}\nd(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot}) + d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{k\\cdot}) \\geq d(\\boldsymbol{x}_{j\\cdot}, \\boldsymbol{x}_{k\\cdot})d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot})\n\\end{equation}\n\nIf $\\boldsymbol{Delta}$ is metric, then so are matrices with elements \n$d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot}) + c^{2}$ as well as $d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot}) /( d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot}) + c^{2})$ where $c$ is any real constant and $i\\neq j$, as is  $d(\\boldsymbol{x}_{i\\cdot}, \\boldsymbol{x}_{j\\cdot})^{1/r}$ for $r \\geq 1$ with again $i \\neq j$.    In the case that $\\boldsymbol{\\Delta}$ is non-metric, \\cite{Krzanowski+Marriott:1994I} indicate that where $c \\geq max_{i,j,k} |\\delta(x_{i},x_{j}) + \\delta(x_{i},x_{k}) - \\delta(x_{j},x_{k})|$, the matrix with elements $\\delta(x_{i},x_{j}) + c$ is metric.\n\n%If $\\boldsymbol{\\Delta}$ is metric then so are matrices with elements $\\delta(x_{i},x_{j}) + c^{2}$,  $\\delta(x_{i},x_{j})^{1/r}$ for $r geq 1$ and  $\\delta(x_{i},x_{j}) / ( \\delta(x_{i},x_{j}) + c^{2})$   krz and marriot vol 1\n\nAgain, the significance of the metric property will be discussed in chapter \\ref{mds} when we consider scaling methods.\n\n\n\n%%% Local Variables: ***\n%%% mode:poly-noweb+r-mode ***\n%%% TeX-master: \"../book.tex\"  ***\n%%% End: ***\n", "meta": {"hexsha": "bc7eb3803d0e8eef7971996f32012b4c2e71ce78", "size": 43405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/distance-woven.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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/distance-woven.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "chapters/distance-woven.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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.9181818182, "max_line_length": 1527, "alphanum_fraction": 0.7346158277, "num_tokens": 12244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.6218219613120822}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath, amssymb, graphicx, float, dsfont}\n\n%opening\n\\title{Notes on Least Squares Optimization}\n\\author{Delbert Yip}\n\n\\newcommand{\\norm}[1]{\\lvert #1 \\rvert}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\n\tThese notes were taken from Chapter 8 from Strang's \"Computational Science and Engineering,\" \\cite{strang_computational_2012} and cover ordinary, weighted, and regularized least squares (Sections 8.1-8.3 of \\cite{strang_computational_2012}). Some background material has been taken from Lay's \"Linear algebra and its applications\" \\cite{lay_linear_2012}.\n\\end{abstract}\n\n\\section{Least Squares}\nConsider a matrix A of size $m x n$ with $n$ independent columns, and $m > n$. \n$A^T A$ is symmetric positive definite, as Rank(A) = $n$. \nWe wish to solve $Au = b$ for some vector $b$ with $m$ components. The solution $\\hat{u}$ has $n$ components. \n\nThis gives rise to the \\textbf{least squares problem}:\n\\begin{equation}\n\\min \\parallel Au - b \\parallel ^2 \n\\end{equation}\n\nBelow are the normal equations, which give the solution $\\hat{u}$:\n\\begin{align} \nAu &= b \\nonumber \\\\\nA^T A \\hat{u} &= A^T b \n\\end{align}\n\nThe residual of the cost function is $e = b - Au$, and has dimensions $m \\times 1$. Thus, \n\\begin{equation}\nA^T e = A^T b - A^T A u\n\\end{equation}\nTherefore, $A^T e = 0$ when $u = \\hat{u}$. \n\n$e$ is in the nullspace of $A^T$, and is therefore perpendicular to the columns (column space) of $A$ (equivalently, $e$ is perpendicular to the rows/rowspace of $A^T$). Recall that orthogonality means that the dot product of two vectors is 0. \n\n\\subsection{Refresher on Orthogonality}\nBefore we start on the next section, let's review some concepts from linear algebra. Specifically, the orthogonality of vectors and vector spaces. \n\n Orthogonal Vectors \nThere is an analogue between geometry in Euclidean space and in $\\mathds{R}^n$. \n\nFirst, *two vectors $\\mathbf{u}$ and $\\mathbf{v}$ are perpendicular i.f.f. the distance between $\\mathbf{u}$ and $\\mathbf{-v}$ is the same as the distance between $\\mathbf{u}$ and $\\mathbf{+v}$.* \n\nFirst, the distance between $\\mathbf{u}$ and $\\mathbf{-v}$:\n\\begin{align}\n[\\textrm{dist}(\\mathbf{u}, \\mathbf{-v})]^2 &= \\parallel \\mathbf{u}-(-\\mathbf{v}) \\parallel ^2 = \\parallel \\mathbf{u} +\\mathbf{v} \\parallel ^2 \\\\\n&= (\\mathbf{u} + \\mathbf{v}) \\cdot (\\mathbf{u} + \\mathbf{v}) \\\\ \n&= \\parallel \\mathbf{u} \\parallel^2 + \\parallel \\mathbf{v} \\parallel^2 + 2\\mathbf{u} \\cdot \\mathbf{v}\n\\end{align}\n\nNext, the distance between $\\mathbf{u}$ and $\\mathbf{+v}$:\n\\begin{align}\n[\\textrm{dist}(\\mathbf{u}, \\mathbf{v})]^2 &= \\parallel \\mathbf{u} -\\mathbf{v} \\parallel ^2 \\\\\n&= (\\mathbf{u} - \\mathbf{v}) \\cdot (\\mathbf{u} - \\mathbf{v}) \\\\ \n&= \\parallel \\mathbf{u} \\parallel^2 + \\parallel \\mathbf{v} \\parallel^2 - 2\\mathbf{u} \\cdot \\mathbf{v}\n\\end{align}\n\nTherefore, \n\n\\begin{align}\n\t[\\textrm{dist}(\\mathbf{u}, \\mathbf{-v})]^2 = [\\textrm{dist}(\\mathbf{u}, \\mathbf{v})]^2 &\\iff - 2\\mathbf{u} \\cdot \\mathbf{v} = 2\\mathbf{u} \\cdot \\mathbf{v} \\\\\n\t&\\implies \\quad \\mathbf{u} \\cdot \\mathbf{v} = 0 \\\\\n\t&\\implies \\parallel \\mathbf{u} + \\mathbf{v} \\parallel ^2 = \\parallel \\mathbf{u} \\parallel^2 + \\parallel \\mathbf{v} \\parallel^2\n\\end{align}\n\n\\subsection{Orthogonal Complements in $\\mathds{R}^n$}\nIf a vector $\\mathbf{z}$ is orthogonal to every vector in a subspace $W$ of $\\mathds{R}^n$, then $\\mathbf{z}$ is orthogonal to $W$. The set of all such vectors $\\mathbf{z}$ is the \\textbf{orthogonal complement} of $W$ and denoted by $W^\\bot$. Let's go through the relation between nullspace, orthogonal complements, and the columns and rows of a $m \\times n$ matrix $A$. \n\nWe have the folllowing theorem: \n\\begin{equation}\n(\\textrm{Row}(A))^\\bot = \\textrm{Nul}(A) \\quad \\textrm{and} \\quad (\\textrm{Col}(A))^\\bot = \\textrm{Nul}(A)^\\bot \n\\end{equation}\n\nIf $Ax = 0$ for some $n \\times 1$ vector $x$, then $x \\in \\textrm{Nul}(A)$, which means $x$ is orthogonal to the rows of $A$. The rows of $A$ span its row space, so $x$ is orthogonal to Row($A$). This is a consequence of how matrix multiplication works, as shown below: \n\\begin{align}\n\tA &= \\begin{pmatrix} a & b & c \\\\ d & e & f \\end{pmatrix}, \\quad u = \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}. \\\\\n\tAu &= \\begin{pmatrix}\ta \\\\ d\t\\end{pmatrix} x + \\begin{pmatrix}\tb \\\\ e\t\\end{pmatrix} y + \\begin{pmatrix}\tc \\\\ f\t\\end{pmatrix} z, \\quad \\textrm{ linear combination of the columns}\\\\\n\t\t&= \\begin{pmatrix} ax + by + cz \\\\ dx + ey + fz \\end{pmatrix}, \\quad \\textrm{ dot product of the rows}\\\\\n\t\t&= \\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix} \n\\end{align}\n\nThe elements of the product $Au$ are dot products between $u$ and the row vectors of $A$; the product $Au$ can also be thought of as a linear combination of the columns of $A$. Since $Au = 0$, $u$ is in the nullspace of A, and from the above, we see that $u$ is orthogonal to the rows of $A$.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figs/Lay_fundamental_subspaces}\n\t\\caption{Fundamental subspaces of $A$. From Lay.}\n\t\\label{fig:layfundamentalsubspaces}\n\\end{figure}\n\n\n\\subsection{Primal and Dual Problems}\nIn the 'primal' problem, we find the solution $\\hat{u}$ by projecting $b$ onto the column space of $A$, i.e. $A\\hat{u}$ is the closest point to $b$ in the column space of $A$. In general, the product $Au$ yields a linear combination of the columns of $A$. The column space of $A$ contains all such products. \n\n\\begin{equation}\nAu = y \\quad \\implies \\quad y \\in \\textrm{Col}(A), \\quad \\forall u\n\\end{equation}\nWhere, Col($A$) refers to the column space of $A$. \n\nThe 'dual' problem solves $A^T e = 0$ for $e$, which is the projection of $b$ onto the nullspace of $A^T$. Recall from above: \n$$ \\textrm{Nul}(A^T) = (\\textrm{Row}(A^T))^\\bot = (\\textrm{Col}(A))^\\bot $$\nThus, $e$ is contained in (Col($A$))$^\\bot$, which contains \\textit{all vectors perpendicular to the columns of $A$}. The dimension of (Col($A$))$^\\bot$ is given by the Rank-Nullity Theorem: \n\n\\begin{align}\n\t&\\textrm{Rank}(A) + \\textrm{Nullity}(A) = n, \\quad \\textrm{ where } n \\textrm{ is the number of columns in } A. \\\\\n\t&\\textrm{Rank}(A^T) + \\textrm{Nullity}(A^T) = m \\\\ \n\t&\\textrm{Rank}(A) = \\textrm{Rank}(A^T) \\quad \\implies \\quad \\textrm{Nullity}(A^T) = m - n \\\\\n\t&\\textrm{Nullity}(A^T) = \\textrm{dim(Row(}A^T))^\\bot = \\textrm{dim(Col(}A)^\\bot) = m - n\n\\end{align}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figs/Strang_projection_lsq}\n\t\\caption{Ordinary least squares. From Strang.}\n\t\\label{fig:strangprojectionlsq}\n\\end{figure}\n\n$e$ and $\\hat{u}$ solve the two linear equations shown by the figure above:\n\\begin{align}\ne + A \\hat{u} &= b \\rightarrow m \\textrm{ equations} \\\\\nA^T e &= 0 \\rightarrow n \\textrm{ equations}\n\\end{align}\n\nThese are called the \"Primal-Dual\", \"Saddle Point\", and \"Kuhn-Tucker (KKT)\" equations. \n\n\\subsubsection{\"Saddle Point\" Equations}\nThe Saddle Point, or KKT, matrix is a block matrix that represents the Primal-Dual equations:\n$$ S = \\begin{bmatrix} I & A \\\\ A^T & 0 \\end{bmatrix} \\quad \\implies \\quad S \\begin{bmatrix} e \\\\ \\hat{u} \\end{bmatrix} = \\begin{bmatrix} Ie + A\\hat{u} \\\\ A^T e + 0 \\end{bmatrix} $$ \nWhere, $I$ is an $m \\times m$ identity matrix. Thus, $I$ constitutes the first $m$ pivot columns of $S$. Thus, to reduce $S$, we need to make the lower left hand corner of $S$ a $n \\times n$ matrix of zeroes. To do this, let's review elimination on block matrices: \n\n\\textbf{Elimination of block matrices}: \n\n\\begin{align}\n\\begin{bmatrix} I & 0 \\\\ -CA^{-1} & I \\end{bmatrix} \\begin{bmatrix} A & B \\\\ C & D \\end{bmatrix} &= \\begin{bmatrix} A + 0 & B + 0 \\\\ -CA^{-1}A + C & -CA^{-1}B + D \\end{bmatrix} \\\\\n&= \\begin{bmatrix} A & B \\\\ 0 & D - CA^{-1}B \\end{bmatrix} \n\\end{align}\n\nThe first matrix, $\\begin{bmatrix} I & 0 \\\\ -CA^{-1} & I \\end{bmatrix}$, is also known as the Gaussian elimination matrix, often represented using the symbol $E$. If $A$ was not an identity matrix, then we can also reduce $A$ into a matrix of pivots: \n\n\\begin{align}\n\\begin{bmatrix} A^{-1} & 0 \\\\ -CA^{-1} & I \\end{bmatrix} \\begin{bmatrix} A & B \\\\ C & D \\end{bmatrix} &= \\begin{bmatrix} AA^{-1} + 0 & BA^{-1} + 0 \\\\ -CA^{-1}A + C & -CA^{-1}B + D \\end{bmatrix} \\\\\n&= \\begin{bmatrix} I & BA^{-1} \\\\ 0 & D - CA^{-1}B \\end{bmatrix} \n\\end{align}\n\n\nWe now reduce our Primal-Dual matrix $S$ with $E = \\begin{bmatrix} I & 0 \\\\ -A^T & I \\end{bmatrix}$:\n\n\\begin{align}\nES &= \\begin{bmatrix} I & 0 \\\\ -A^T & I \\end{bmatrix} \\begin{bmatrix} I & A \\\\ A^T & 0 \\end{bmatrix} \\\\\n\t&= \\begin{bmatrix} I + 0 & A + 0 \\\\ -A^T + A^T & -AA^T + 0 \\end{bmatrix} \\\\\n\t&= \\begin{bmatrix} I & A \\\\ 0 & -AA^T \\end{bmatrix}\n\\end{align}\n\nBy convention, the lower right-hand block remaining after elimination is known as the \\textbf{Schur complement}. More importantly, the first $m$ pivots are positive (=1), but the final $n$ pivots, determined by $-AA^T$, are negative. When a matrix has pivots of both signs, it is \\textbf{indefinite}. For such matrices, \\textit{there is no maximum or minimum, positive or negative definite}. Instead, there is a \\textbf{saddle point, $(\\hat{u}, e)$}.\n\n\\subsubsection{\"Primal-Dual\" Equations}\nThe \\textit{primal} problem is to minimize $\\frac{1}{2} \\parallel Au - b \\parallel^2$. The \\textit{dual} problem is to minimize $\\frac{1}{2} \\parallel e - b \\parallel^2$ with the constraint $A^T e = 0$. In the dual problem, $u$ acts a Lagrange multiplier to enforce the constraint $A^T e = 0$. Solutions to the primal and dual problems are found simultaneously, and add to $b$. \n\nLet's do an example!\n\n\\subsubsection{An Example}\n\\begin{equation}\nA = \\begin{bmatrix}2 \\\\ 1 \\end{bmatrix}, \\quad b = \\begin{bmatrix}3 \\\\ 4\\end{bmatrix}, \\quad A^T A = 5, \\quad A^T b = 10 \n\\end{equation}\n\\begin{align}\n\t&\\textrm{Projection: } A\\hat{u} = \\begin{bmatrix}4 \\\\ 2\\end{bmatrix} \\\\ \n\t&\\textrm{Error: } e = b - A\\hat{u} = \\begin{bmatrix}3 \\\\ 4 \\end{bmatrix} - \\begin{bmatrix}4 \\\\ 2\\end{bmatrix} = \\begin{bmatrix}-1 \\\\ 2\\end{bmatrix} \n\\end{align}\n\nLet's verify that $A\\hat{u}$ and $e$ are perpendicular. First, $A\\hat{u}$ and $e$ sum to $b$:\n\n\\begin{equation}\nA\\hat{u} + e = A\\hat{u} + (b - A\\hat{u}) = b\n\\end{equation}\n\n\\begin{align}\n\\parallel b \\parallel^2 &= \\parallel A\\hat{u} \\parallel^2 + \\parallel e \\parallel^2 \\\\\n&= 20 + 5 = 25 \\\\\nA \\hat{u} \\cdot e &= \\parallel A \\hat{u} \\parallel \\parallel e \\parallel \\cos \\theta \\\\\n0 &= \\sqrt{20} \\sqrt{5} \\cos \\theta \\\\\n\\therefore \\cos \\theta &= 0 \\quad \\implies \\quad \\theta = \\frac{\\pi}{2} \n\\end{align}\n\nThe normal equation is: $A^T A \\hat{u} = A^T b$, so $\\hat{u} = 2$. This solves the primal problem. The dual minimizes $\\frac{1}{2}\\parallel e-b \\parallel^2$ under the constraint $A^T e = 0$. The solution to the dual problem gives $e$ and $\\hat{u}$:\n\nThe \\textbf{Lagrange} function is:\n\n\\begin{align}\nL &= \\frac{1}{2}\\parallel e-b \\parallel^2 + u(A^T e) \\\\\nL(e_1, e_2, u) &= \\frac{1}{2}(e_1 - b_1 )^2 + \\frac{1}{2}(e_2 - b_2 )^2 + u(A^{T}_{1} e_1 + A^{T}_{2} e_2) \\\\\n\\frac{\\partial L}{\\partial (e_1, e_2, u)} &= \\begin{bmatrix}\n\te_1 - b_1 + 2\\hat{u} = 0 \\\\\n\te_2 - b_2 + \\hat{u} = 0 \\\\\n\t2e_1 + e_2 = 0 \n\\end{bmatrix} = \\begin{bmatrix}\n\te_1 & e_2 & \\hat{u} \\\\\n\t1 & 0 & 2 \\\\\n\t0 & 1 & 1 \\\\\n\t2 & 1 & 0 \n\\end{bmatrix} \\begin{bmatrix} e_1 \\\\ e_2 \\\\ \\hat{u} \\end{bmatrix} = \\begin{bmatrix} b_1 \\\\ b_2 \\\\ 0 \\end{bmatrix}\n\\end{align}\n\nThe matrix $\n\\begin{bmatrix}\n1 & 0 & 2 \\\\\n0 & 1 & 1 \\\\\n2 & 1 & 0 \n\\end{bmatrix} $\nis the saddle point matrix $S$, whose columns correspond to $e_1$, $e_2$, and $u$, respectively. \n\n\\section{Weighted Least Squares} \\label{Weighted Least Squares}\nThe weighted least squares equation is:\n\\begin{equation}\n\\min \\parallel WAu - Wb \\parallel^2 \n\\end{equation}\n\nwith normal equations:\n\\begin{align}\n(WA)^T (WA) \\hat{u}_W &= (WA)^T (Wb) \\\\\nA^T W^T W A \\hat{u}_W &= A^T W^T W b \\\\\nA^T C A \\hat{u}_W &= A^T C b, \\quad C = W^T W \\\\\n\\implies 0 &= A^T C b - A^T C A \\hat{u}_W \\\\\n\t&= A^T C (b - A \\hat{u}_W ) = A^T C e, \\quad e = (b - A \\hat{u}_W )\n\\end{align}\n\nWhere, $\\hat{u}_W$ is the solution, and changes with the weight matrix $W$. Let's consider the geometric effects of introducing $W$. \n\\begin{itemize}\n\t\\item First, $A^T e = 0$ becomes $A^T C e = 0$. So, $e$ is perpendicular to $A^T C$ now, not $A^T$ by itself. So, $e$ is in the nullspace of $A^T C$, not that of $A^T$.\n\t\\item With $W$, $e$ is now in the orthogonal complement to the rows of $A^T C$, or equivalently, the columns of $C^T A$. Thus, $e$ is not orthogonal to the column space of $A$. We say that $e$ is \"$C$-orthogonal\" to the columns of $A$. \n\t\\item Consequently, solving weighted least squares involves finding a projection of $b$ that is orthogonal to Col($C^T A)$, but not Col($A$).\n\t\\item We still split $b$ into two components: $A\\hat{u}_W \\in \\textrm{Col}(A)$, and $e \\in \\textrm{Nul}(A^T C)$.\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figs/Strang_projection_wlsq}\n\t\\caption{Weighted least squares.}\n\t\\label{fig:strangprojectionwlsq}\n\\end{figure}\n\n\nSo, we have the following primal-dual equations to solve:\n\\begin{align}\ne + A \\hat{u}_W &= b \\\\ \nA^T C e &= 0 \n\\end{align}\n\nThe saddle point matrix is: \\begin{equation}\n\\begin{bmatrix}\n\tI & A \\\\\n\tA^T C & 0\n\\end{bmatrix}, \n\\end{equation} where the columns represent coefficients of $e$ and $\\hat{u}_W$, respectively. Ideally, we'd like that the equations be symmetric. However, we have a factor of $C$ in the bottom-left that is not in the top-right, so our current matrix is not symmetric. To make it symmtric, introduce $w = Ce$ and $e = C^{-1}w$, and let $\\hat{u}_W = u$:\n\n\\begin{align}\nC^{-1}w + Au &= b \\label{wlsq1} \\\\\nA^T w &= 0 \\label{wlsq2}\n\\end{align}\n\nThis gives rise to a symmetric matrix: \\begin{equation}\nS = \\begin{bmatrix}\n\tC^{-1} & A \\\\ A^T & 0\n\\end{bmatrix},\n\\end{equation} where columns represent coefficients for $w$ and $u$, respectively. Since $C = W^T W$, which is the vector analogue to squaring, the elements of $C$, and thus $C^{-1}$, are positive. $W$ is a $m \\times n$ matrix, so $C^{-1}$ contributes $m$ \\textit{positive} pivot columns. The remaining pivots are found by elimination on $S$:\n\n\\begin{align}\nE &= \\begin{bmatrix} I & 0 \\\\ -A^T C & I  \\end{bmatrix} \\\\\nES &= \\begin{bmatrix} I & 0 \\\\ -A^T C & I  \\end{bmatrix} \\begin{bmatrix} C^{-1} & A \\\\ A^T & 0 \\end{bmatrix} \\\\\n\t&= \\begin{bmatrix} C^{-1} + 0 & A + 0 \\\\ -A^T C C^{-1} + A & -A^T C A + 0 \\end{bmatrix} \\\\\n\t&= \\begin{bmatrix} C^{-1} & A \\\\ -A^T + A & -A^T C A \\end{bmatrix} = \\begin{bmatrix} C^{-1} & A \\\\ 0 & -A^T C A \\end{bmatrix}\n\\end{align}\n\nThe Schur complement is $-A^T C A$, which is negative like before. So, we have $n$ negative pivots from this block and $m$ positive pivots from $C^{-1}$, making $S$ indefinite. The equations to solve are:\n\\begin{align}\n\\begin{bmatrix} C^{-1} & A \\\\ A^T & 0 \\end{bmatrix} \\begin{bmatrix} w \\\\ u \\end{bmatrix} &= \\begin{bmatrix} b \\\\ 0 \\end{bmatrix} \\\\\n\\begin{bmatrix} C^{-1} & A \\\\ 0 & -A^T C A \\end{bmatrix} \\begin{bmatrix} w \\\\ u \\end{bmatrix} &= \\begin{bmatrix} b \\\\ -A^T C b \\end{bmatrix} \\quad \\textrm{after elimination.}\n\\end{align}\n\nDue to the constraint that $A^T w = 0$, $Au$ and $w$ are perpendicular: \n\\begin{equation}\n(Au)^T w = u^T (A^T w) = 0\n\\end{equation}\n\n\\subsubsection{Duality and Weak Duality}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\linewidth]{figs/Strang_wsq_weakduality}\n\t\\caption{Geometric interpretation of weak duality. From Strang.}\n\t\\label{fig:strangwsqweakduality}\n\\end{figure}\n\nImagine we have a rectangle, where the perpendicular sides are $Au$ and $w$. The remaining corners of this rectangle are $0$ and $Au + w$. Lines from $b$ to the four corners of this rectangle are vectors $b - X + a$ where $X$ is a corner of the rectangle and $a$ is some offset (since the lines don't all start from 0). \n\nWe can ignore the offset by comparing the vectors' magnitudes. In particular, the diagonal distance starting from either the lower-left or lower-right corner of the rectangle (right side of Fig. \\ref{fig:strangwsqweakduality}) is the same, but involve different vectors. The magnitude of each diagonal is the sum of two vectors that meet at $b$. One diagonal connects points $(0, b, Au + w)$, and has magnitude $\\parallel b \\parallel^2 + \\parallel b - (Au + w) \\parallel^2$. The other diagonal connects points $(Au, b, w)$, and has magnitude $\\parallel b - Au \\parallel^2 + \\parallel b - w \\parallel^2$. Equating these yields the following relationship:\n\n\\begin{equation}\n\\parallel b - Au \\parallel^2 + \\parallel b-w \\parallel^2 = \\parallel b \\parallel^2 + \\parallel b - Au - w \\parallel^2 \n\\end{equation}\n\nAt the minimum, we have that $\\parallel b \\parallel^2 = \\parallel b - Au \\parallel^2 + \\parallel b-w \\parallel^2$. This is summarized by the image on the right of Fig. \\ref{fig:strangwsqweakduality}, which clearly shows how $Au$ and $w$ are projections of $b$ under this condition:\n\\begin{align}\n\\parallel b - Au - w \\parallel^2 &= 0 \\\\\nb - Au - w &= 0 \\\\\nAu - w &= b \n\\end{align}\n\nThe solution $u = \\hat{u}$ and $w = e$ gives \\textbf{duality}: $\\parallel b - A\\hat{u} \\parallel^2 + \\parallel b-e \\parallel^2 = \\parallel b \\parallel^2$. \\textbf{Weak duality} is when $\\parallel b - A\\hat{u} \\parallel^2 + \\parallel b-e \\parallel^2 > \\parallel b \\parallel^2$. In this scenario, we have a \"duality gap\" $\\parallel b - Au - w \\parallel^2$. Duality is achieved when the gap is zero. When this is true, $b = Au - w$, and $b$ becomes a corner of the rectangle, as shown in the right side of Fig. \\ref{fig:strangwsqweakduality}. Finally, by Pythagoras' rule: \n\\begin{equation}\n\\parallel b-w \\parallel^2 + \\parallel b-Au \\parallel^2 = \\parallel b \\parallel^2 = \\parallel Au + w \\parallel^2,\n\\end{equation}\nwhich is exactly what happens when we have perfect duality! \n\nTo summarize this section, weighted least squares involves solving two problems:\n\\begin{enumerate}\n\t\\item Project $b$ onto the column space of $A\\hat{u}$:\n\t\\begin{align*}\n\t\\centering\n\t\\min \\parallel b-Au \\parallel^2\n\t\\end{align*}\n\t\\item Project $b$ across to $e$: \\begin{align*}\n\t\t\\min &\\quad \\parallel b-w \\parallel^2 \\\\\n\t\t\\textrm{s.t.} &\\quad A^T w = 0\n\t\\end{align*}\n\\end{enumerate}\n\nThe solutions to these problems converge at optimality, as we showed above. At optimality, $\\hat{w} = C(b - A\\hat{u})$. $C$ is the bridge between the two dual problems and identiies the solutions $\\hat{u}$ and $\\hat{w}$. Alternatively, we can see the problem as a maximization problem, simply by attaching a negative sign: \n\\begin{align}\n\t\\parallel b - e \\parallel^2 + \\parallel b - A \\hat{u} \\parallel^2 &= \\parallel b \\parallel^2 \\\\\n\t\\parallel b - e \\parallel^2 - \\parallel b \\parallel^2 &= -\\parallel b - A \\hat{u} \\parallel^2 \\\\\n\t\\therefore \\quad \\min (\\parallel b-e \\parallel^2 - \\parallel b \\parallel^2) \\quad &\\equiv \\quad \\max (-\\parallel b - A \\hat{u} \\parallel^2)\n\\end{align}\n\n\\subsection{Minimizing with Constraints using Lagrange's Method}\nImagine we have a line of two springs and one mass and that we wish to minimize the energy in the springs. The constraint is $A^T w = f$, where we have forces $w_1$ and $w_2$, and a mass that exerts external force $f$. The springs are vertically arranged with the mass in between, which causes spring 1 (top) to stretch, and spring 2 (bottom) to compress (Fig. \\ref{fig:strangconstrainedsprings}). \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{figs/Strang_constrained_springs}\n\t\\caption{System with two linear springs and one mass.}\n\t\\label{fig:strangconstrainedsprings}\n\\end{figure}\n\nTo solve the force balance equation $w_1 + w_2 = f$, we won't use calculus (setting derivatives to zero), because while we have an energy function $E(w_1 , w_2)$, it is unclear which derivatives we should adjust to achieve force balance. We could make the substitution: $w_2 = w_1 - f$, so that we only minimize over one variable, $w_1$. Here, we will use Lagrange multipliers to \\textit{build constraints into the function} by adding an unknown $u$ that enforces our constraint. \n\nWith $n$ constraints on $m$ unknowns, this method has $m + n$ unknowns. We will add a Lagrange multiplier for each constraint. The Lagrange function is:\n\\begin{equation}\nL(w_1, w_2, u) = E_1 (w_1) + E_2 (w_2) - u(w_1 - w_2 - f) = E_1 + E_2 - u (w_1 - w_2 - f)\n\\end{equation}\n\nWhere, $u$ takes a negative sign by convention. $w_2$ takes a negative sign as well, to distinguish the compression of spring 2 from the stretching of spring 1. Note that constraints, the term multiplied by $u$, must equal zero. The Lagrange multiplier $u$ has a special meaning: here, the displacement of the mass. In economics, the selling price for maximal profit. In all problems, $u$ measures the answer's sensitivity (here, the minimum energy $E_{\\textrm{min}}$) to changes in constraints. \n\nHooke's law tells us that the force in a linear spring is proportional to elongation $e$, so $w = ce$. Work = force $\\times$ displacement, and the integral of work is energy. Thus, Work = $ce$, and energy $E$ = $\\int$ Work = $\\frac{1}{2} ce^2$. Substituting $e = \\frac{w}{c}$, we get $E = \\frac{w^2}{2c}$. The resulting minimization problem is then:\n\\begin{align}\n\\min &\\quad E(w) = \\frac{w_{1}^2}{2c} + \\frac{w_{2}^2}{2c} \\\\\n\\textrm{s.t. } &\\quad w_1 - w_2 = f \\nonumber \n\\end{align}\n\n\\subsubsection{Geometry of the method}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\linewidth]{figs/Strang_constrained_geo}\n\t\\caption{Geometric depiction of $E(w_1, w_2)$ and constraint $w_1 - w_2 = f$.}\n\t\\label{fig:strangconstrainedgeo}\n\\end{figure}\n\nNotice that $E(w)$ is the equation of an ellipse. We can think of the constraint geometrically in the plane with axes $w_1$ and $w_2$: $E(w)$ is some ellipse in this plane, and $w_1 - w_2 = f$ is a line with positive slope and negative y-intercept (Fig. \\ref{fig:strangconstrainedgeo}). The solution is achieved when the line meets the ellipse at a right-angle. At this point $(w_1 , w_2)$, there are two vectors of interest that describe the rate of change of the ellipse and line with respect to $w_1$ and $w_2$. One is perpendicular to the line: \\begin{equation*}\n\\begin{bmatrix}\n\\partial l / \\partial w_1 \\\\ \\partial l / \\partial w_1 \n\\end{bmatrix} = \\begin{bmatrix}\n1 \\\\ -1 \n\\end{bmatrix}, \\quad l = w_1 - w_2 - f = 0\n\\end{equation*}\n\nThe second is perpendicular to the ellipse, and arises from the gradient of $E(w)$:\n\\begin{align*}\nL(w_1, w_2, u) &= E_1 + E_2 - u (w_1 - w_2 - f) \\\\ \n\\frac{\\partial L}{\\partial w_1} &= \\frac{\\partial E}{\\partial w_1} - u = 0 \\\\\n\\frac{\\partial L}{\\partial w_2} &= \\frac{\\partial E}{\\partial w_2} + u = 0 \\\\\n\\begin{bmatrix}\n\\partial E / \\partial w_1 \\\\ \\partial E / \\partial w_2 \n\\end{bmatrix} &= \\begin{bmatrix}\nu \\\\ -u\n\\end{bmatrix}\n\\end{align*}\n\nThe above gives us $w_1$ and $w_2$ as follows:\n\\begin{align}\n\\frac{\\partial E}{\\partial w_1} &= \\frac{\\partial}{\\partial w_1} \\frac{w^{2}_{1}}{2c_{1}} = \\frac{w_{1}}{c_{1}} \\\\\n\\therefore \\begin{bmatrix}\n\\partial E / \\partial w_1 \\\\ \\partial E / \\partial w_2 \n\\end{bmatrix} &= \\begin{bmatrix}\nw_1 / c_1 \\\\ w_2 / c_2 \n\\end{bmatrix} = \\begin{bmatrix}\nu \\\\ -u\n\\end{bmatrix} \\\\ \nw_1 = c_1 u, &\\quad w_2 = -c_2 u \\\\\nw_1 - w_2 &= f = c_1 u + c_2 u = (c_1 + c_2)u \n\\end{align}\n\n$c_1 + c_2$ is the stiffness matrix $A^T C A$, which we discussed in Section \\ref{Weighted Least Squares}. Since the problem is small, $K = A^T C A$ is just $1 \\times 1$: \n\\begin{equation*}\nA^T = \\begin{bmatrix}\n1 \\\\ -1\n\\end{bmatrix}, \\quad K = A^T C A = \\begin{bmatrix}\n1 \\\\ -1\n\\end{bmatrix}\\begin{bmatrix}\nc_1 & \\\\ & c_2 \n\\end{bmatrix} \\begin{bmatrix}\n1 \\\\ -1 \n\\end{bmatrix} = \\begin{bmatrix}\nc_1 + c_2\n\\end{bmatrix}\n\\end{equation*}\n\nWe now find the forces $w_1$ and $w_2$:\n\\begin{align*}\nKu &= f \\quad \\implies \\quad u = \\frac{f}{c_{1} + c_{2}} \\\\\nw_1 &= c_1 u = \\frac{c_1 f}{c_1 + c_2}, \\quad w_2 = -c_2 u = -\\frac{c_2 f}{c_1 + c_2} \\\\ \nE_{\\textrm{min}} &= \\frac{w_{1}^2}{2c} + \\frac{w_{2}^2}{2c} = \\frac{c_1 f^2}{2 (c_1 + c_2)^2} + \\frac{c_2 f^2}{2 (c_1 + c_2)^2} \\\\\n &= \\frac{f^2}{2 (c_1 + c_2)}\n\\end{align*}\n\nAbove, we mentioned that $u$ measures the sensitivity of $E_{\\textrm{min}}$ to changes in the constraint, $f$. We can show this by computing the derivative $\\frac{dE_{\\textrm{min}}}{df}$:\n\\begin{align}\n\\frac{dE_{\\textrm{min}}}{df} &= \\frac{d}{df} \\left(\\frac{f^2}{2 (c_1 + c_2)}\\right) \\nonumber \\\\\n&= \\frac{f}{c_1 + c_2} = u\n\\end{align}\n\n\\subsection{The Fundamental Problem}\nThis is what Strang describes as the \\textit{fundamental problem of scientific computing}: the full linear case with $m$ springs. Each spring experiences a force $w_i$, which we can represent as $w = (w_1, \\dotsm, w_m)$. We have $n$ constraints for force balance, $A^{T}w = (f_1, \\dotsm, f_n)$, enforced by $n$ Lagrange multipliers $u = (u_1, \\dotsm, u_n)$.\n\nLet $C$ be a matrix with masses $c_1, \\dotsm, c_m$ on the diagonal and zeroes everywhere else. Then, the total energy function for $m$ springs is given by: $E(w) = \\frac{1}{2}w^T C^{-1} w$. Our Lagrange function is thus:\n\\begin{equation}\nL(w, u) = \\frac{1}{2}w^T C^{-1} w - u^{T}(A^{T}w - f)\n\\end{equation}\n\nThe minimizer $w$ is found by setting the $m+n$ partial derivatives of $L$ to zero:\n\\begin{align}\n\\frac{\\partial L}{\\partial w} &= C^{-1}w - Au = 0 \\label{fundamental_pLpw}\\\\\n\\frac{\\partial L}{\\partial u} &= -A^{T}w + f = 0 \\label{fundamental_pLpu}\n\\end{align}\n\nFrom Eq. \\ref{fundamental_pLpw}, we have that $w = Ce = CAu$, which implies that $e = Au$. Eq. \\ref{fundamental_pLpu} indicates that $f = A^{T}w$. Together, we have that:\n\\begin{equation}\nA^T C A u = A^T C e = A^T w = f\n\\end{equation}\n\nLeast squares problems have $e = b - Au$, which appears in $E$ as:\n\\begin{equation*}\nE(b, w) = \\frac{1}{2}w^T C^{-1} w - b^T w\n\\end{equation*}\n\nThe derivatives of $L$ (with $u$ positive) are:\n\\begin{align}\n\\frac{\\partial L}{\\partial w} &= C^{-1}w + Au - b = 0 \\\\\n\\frac{\\partial L}{\\partial u} &= -A^{T}w - f = 0 \\\\\n\\begin{bmatrix}\nC^{-1} & A \\\\ A^{T} & 0 \n\\end{bmatrix} &\\begin{bmatrix}\nw \\\\ u\n\\end{bmatrix} = \\begin{bmatrix}\nb \\\\ f\n\\end{bmatrix}\n\\end{align}\n\nThe vector $(w, u)^{T}$ has size $m + n$, since $w$ has $m$ components and $u$ has $n$. If $C$ is positive definite, and $A$ has full column rank (all columns are independent, Rank($A$) = $n$), then $A^{T}CA$ and $S$ are invertible. We can factor $S$ into three parts as follows:\n\\begin{equation*}\nS = \\begin{bmatrix}\nC^{-1} & A \\\\ A^{T} & 0 \n\\end{bmatrix} = \\begin{bmatrix}\nI & 0 \\\\ A^{T}C & I\n\\end{bmatrix} \\begin{bmatrix}\nC^{-1} & 0 \\\\ 0 & -A^{T}CA\n\\end{bmatrix}\\begin{bmatrix}\nI & CA \\\\ 0 & I\n\\end{bmatrix}\n\\end{equation*}\n\n$S$ is invertible when both block columns have full rank. Otherwise, it can be singular. \n\n\\section{Regularized Least Squares}\n\nRegularized least squares is a special case of weighted least squares:\n\\begin{align*}\n\\textrm{\\textbf{Ordinary LSQ}} \\quad & \\min \\parallel Au - b \\parallel^2 \\\\\n\\textrm{Solve: } & A^TA\\hat{u} = A^T b \\\\\n\\textrm{\\textbf{Weighted LSQ}} \\quad & \\min (b-Au)^{T} C (b-Au) \\\\\n\\textrm{Solve: } & A^T C A\\hat{u} = A^T C b \\\\\n\\textrm{\\textbf{Regularized LSQ}} \\quad & \\min \\parallel Au - b \\parallel^2 + \\alpha \\parallel Bu-d \\parallel^2 \\\\\n\\textrm{Solve: } & (A^T A + \\alpha B^{T}B)\\hat{u} = A^{T}b + \\alpha B^{T}d\n\\end{align*}\n\nWe can rewrite the regularized LSQ equations to resemble those for weighted LSQ by replacing $A$ in the latter by $[A \\ B]^T$:\n\\begin{equation}\n\\begin{bmatrix}\nA^T & B^T\n\\end{bmatrix} \\begin{bmatrix}\nI & 0 \\\\ 0 & \\alpha I \n\\end{bmatrix} \\hat{u} = \\begin{bmatrix}\nA^T & B^T\n\\end{bmatrix}  \\begin{bmatrix}\nI & 0 \\\\ 0 & \\alpha I \n\\end{bmatrix} \\begin{bmatrix}\nb \\\\ d\n\\end{bmatrix}\n\\end{equation}\n\nWhere, the weighting matrix $C =  \\begin{bmatrix}\nI & 0 \\\\ 0 & \\alpha I \n\\end{bmatrix}$. There are two important applications that lead to this sum of two squares $(A^T A, B^{T}B)$:\n\\begin{enumerate}\n\t\\item If $A^{T}A$ is ill-conditioned, e.g. very large ratio of largest to smallest eigenvalues, $m < n$, $A^{T}A$ is singular. \\\\\n\tRegularization acts to 'reduce the noise.' Normally, as $\\alpha$ is increased, $\\parallel \\hat{u} \\parallel$ decreases and $\\parallel A\\hat{u} - b \\parallel$ increases. The \\textbf{Discrepancy Principle} selects $\\alpha$ so that $\\parallel \\hat{u} \\parallel$ decreases and $\\parallel A\\hat{u} - b \\parallel \\approx $ expected noise (uncertainty in $b$).\n\t\\item As $\\alpha \\rightarrow \\infty$, $Bu \\rightarrow d$. The limiting $\\hat{u}_{\\infty}$ solves \n\t\\begin{align}\n\t\\min &\\quad \\parallel Au-b \\parallel^2 \\\\\n\t\\textrm{s.t.} &\\quad Bu=d \\nonumber \n\t\\end{align}\n\\end{enumerate}\n\n\\subsection{Example: Large Penalty Enforced $Bu=d$}\n\\begin{align*}\n\\textrm{Problem:} \\quad \\min &\\quad \\parallel Au \\parallel^2 = u_{1}^{2}+u_{2}^{2} \\\\\n\\textrm{s.t.} &\\quad Bu = u_1 - u_2 = 8\n\\end{align*}\nLet $A = \\begin{bmatrix}\n1 & 0 \\\\ 0 & 1\n\\end{bmatrix}, \\quad b = \\begin{bmatrix}\n0 \\\\ 0\n\\end{bmatrix}, \\quad B = \\begin{bmatrix}\n1 & -1\n\\end{bmatrix}, \\quad d = \\begin{bmatrix}\n8\n\\end{bmatrix}$.\n\n\\begin{align*}\nA^T A = I, \\quad B^T B = \\begin{bmatrix}\n1 & -1 \\\\ -1 & 1\n\\end{bmatrix}, \\quad &\\begin{bmatrix}\n1+\\alpha & -\\alpha \\\\ -\\alpha & 1+\\alpha\n\\end{bmatrix}\\begin{bmatrix}\nu_1 \\\\ u_2 \n\\end{bmatrix} = \\begin{bmatrix}\n8\\alpha \\\\ -8\\alpha\n\\end{bmatrix} = \\alpha B^T d \\\\\nu_1 + u_2 = 0, \\quad &(1 + 2\\alpha)u_1 = 8\\alpha \\\\\n&u_1 = \\frac{8\\alpha}{1+2\\alpha} = \\frac{4}{1 + \\frac{\\alpha}{2}} = 4 - \\frac{4}{2\\alpha} + \\dotsm \\rightarrow u_1 = 4\n\\end{align*}\n\nThe order is of order $1/\\alpha$, so we need large $\\alpha$.\n\n\\subsection{The Pseudoinverse}\nSuppose $A$ is $m \\times n$ and $b$ has $m$ components. The normal equations $A^{T}A\\hat{u} = A^{T}b$ only give $\\hat{u}$ when $A^{T}A$ is invertible. Otherwise, we can use the pseudoinverse to find the best solution $u^{+}$. This works even when $A$ is not full rank and $A^{T}A$ is singular\n\n\\subsubsection{What is $u^{+}$?}\n$u^{+} = A^{+}b$ provides the \\textbf{shortest} vector that solves $A^{T}Au^{+} = A^{T}b$. \n\nOther solutions, longer than $u^{+}$, have components in the nullspace of $A$. $u^{+}$ is \\textbf{the particular solution with no nullspace component}. The \\textbf{pseudoinverse} of $A$ is a matrix $A^{+}$, which produces $u^{+} = A^{+}b$. If $A$ is square and invertible, then $u^{+} = u = A^{-1}b$, and $A^{+} = A^{-1}$. \n\nIf $A$ has independent columns, but $m < n$, then $\\hat{u} = (A^{T}A)^{-1}A^{T}b$ is the only solution, where $A^{+} = (A^{T}A)^{-1}A^{T}$. If $A$ has dependent columns and thus a nonzero nullspace: any $Au$ is a linear combination of the columns of $A$, but if the columns are dependent, then there exists a nonzero vector $x$ such that $Ax = 0$, and so $x \\in \\textrm{Nul}(A)$ and Nul($A$) $\\neq \\{0\\}$.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{figs/Strang_pseudoinverse}\n\t\\caption{$Au$ takes vectors $u = u_{\\textrm{row}} + u_{\\textrm{null}}$ to the column space of $A$. Since $u_{\\textrm{row}}$ and $u_{\\textrm{null}}$ are orthogonal, a non-zero $u_{\\textrm{null}}$ increases $\\norm{u}^{2}$. Thus, $u^{+} = u_{\\textrm{row}}$}. \n\t\\label{fig:strangpseudoinverse}\n\\end{figure}\n\n$u^{+}$ solves $Au^{+} = p$, where $p$ is the projection of $b$ onto the column space of $A$. The error $\\norm{e} = \\norm{b-p} = \\norm{b-Au^{+}}$ is minimized by $u^{+}$. In summary, $u^{+}$ is in the row space (to be as short as possible), and $Au^{+} = p$ (to be as close to $b$ as possible); $u^{+}$ minimizes $e$ and solves $A^T A u^{+} = A^T b$. \n\n\\subsubsection{Singular Value Decomposition (SVD)}\nOne method to compute $u^{+}$ is by SVD. Let's review diagonalization and SVD. \n\nRecall the \\textbf{Diagonalization Theorem}:\n\\begin{itemize}\n\t\\item An $n \\times n$ matrix $A$ is diagonalization if and only if $A$ has $n$ linearly independent eigenvectors.\n\t\\item $A = PDP^{-1}$ with $D$ being a diagonal matrix, if and only if the columns of $P$ are $n$ linearly independent eigenvectors of $A$. Then, the entries of $D$ are the corresponding eigenvalues of $A$ for the eigenvectors in $P$. \n\\end{itemize}\n\n\\paragraph{Diagonalization of Symmetric Matrices \\\\}\nFurthermore, if $A$ is symmetric, then:\n\\begin{itemize}\n\t\\item $A^{T} = A$\n\t\\item All eigenvectors from different eigenspaces (i.e. corresponding to different eigenvalues) are \\textbf{orthogonal} to each other.\n\t\\item $A = PDP^{-1}$, but $P$ is square and has orthonormal columns $\\implies$ $P$ is an \\textit{orthogonal matrix}, and $P^{-1} = P^{T}$.\n\t\\item $A$ is orthogonally diagonalizable if and only if $A$ is symmetric. \n\\end{itemize}\n\nWe can prove that, for symmetric $A$, two given eigenvectors $v_1$ and $v_2$ are orthogonal:\n\\begin{align*}\n\\lambda_1 v_1 \\cdot v_2 &= (\\lambda_1 v_1)^{T} v_2 = (Av_1)^{T}v_2 \\quad \\leftarrow \\lambda_1 v_1 = A v_1 \\\\\n&= (v_{1}^{T}A^{T})v_2 = v_{1}^{T}(Av_2) = v^{T}_{1}(Av_{2}) \\quad \\leftarrow A^T = A \\\\\n&= v_{1}^{T} \\lambda_{2}v_{2} = \\lambda_{2}v_{1}^{T}v_{2} = \\lambda_{2}v_{1} \\cdot v_{2} \\\\\n(\\lambda_{1} - \\lambda_{2})v_{1}\\cdot v_{2} &= 0 \\\\\n\\lambda_{1} - \\lambda_{2} &\\neq 0 \\quad \\implies \\quad v_{1} \\cdot v_{2} = 0\n\\end{align*}\n\nAn $n \\times n$ matrix $A$ is \\textit{orthogonally diagonalizable} if there are an orthogonal matrix $P$ with $P^{-1} = P^{T}$, and a diagonal matrix $D$ such that\n\\begin{equation}\nA = PDP^{T} = PDP^{-1}\n\\end{equation}\n\nThis requires $n$ linearly independent and orthonormal eigenvectors. This is possible when $A$ is symmetric:\n\\begin{equation*}\nA^{T} = (PDP^{T})^{T} = P^{TT}D^{T}P^{T} = PDP^{T} = A\n\\end{equation*}\n\n\\paragraph{Spectral decomposition of a Symmetric Matrix \\\\}\n\\textbf{Spectral decomposition} is possible when $A$ is symmetric:\n\\begin{align*}\nA = PDP^{T} &= \\begin{bmatrix}\nu_1 \\dotsm u_n\n\\end{bmatrix} \\textrm{diag}(\\lambda_1 , \\dotsm, \\lambda_n) \\begin{bmatrix}\nu_{1}^{T} \\\\ \\vdots \\\\ u_{n}^{T}\n\\end{bmatrix} \\\\\n&= \\begin{bmatrix}\n\\lambda_{1}u_{1} \\dotsm \\lambda_{n}u_{n} \n\\end{bmatrix}\\begin{bmatrix}\nu_{1}^{T} \\\\ \\vdots \\\\ u_{n}^{T}\n\\end{bmatrix} \\\\\n&= \\lambda u_{1} u_{1}^{T} + \\dotsm + \\lambda_{n}u_{n}u_{n}^{T}\n\\end{align*}\n\nHere, each matrix $u_{i}u_{i}^{T}$ is $1 \\times 1$ and is a \\textbf{projection matrix} in the sense that, $u_{i}u_{i}^{T}x$, for all $x \\in \\mathds{R}^{n}$, is the orthogonal projection of $x$ onto the subspace spanned by $u_{i}$.\n\n\\paragraph{SVD of an $m \\times n$ matrix $A$ \\\\}\n\nLet's finally talk about SVD. The key insight is that, even if we can't factorize an $m \\times n$ matrix $A$ as $A = PDP^{-1}$, \\textbf{we can always perform SVD to get $\\mathbf{A = QDP^{-1}}$. }\n\nLet $A$ be an $m \\times n$ matrix. Then, $A^{T}A$ is symmetric, and can be orthogonally diagonalized as $A^{T}A = PDP^{T}$. Let $\\{v_1, \\dotsm v_{n} \\}$ be an orthonormal basis for $\\mathds{R}^{n}$ consisting of eigenvectors of $A^{T}A$. Let $\\lambda_{1}, \\dotsm, \\lambda_{n}$ be the corresponding eigenvalues. Then,\n\\begin{align*}\n\\norm{Av_i}^{2} &= (Av_i)^{T}(Av_i) = v_{i}^{T}A^{T}Av_{i} \\\\\n&= v_{i}^{T} (\\lambda_{i}v_{i}) \\quad \\leftarrow Av_{i} = \\lambda_{i}v_{i} \\\\\n&= \\lambda_{i} v_{i}^{T}v_{i} = \\lambda_{i} \\quad \\leftarrow v_{i}^{T}v_{i} = 1 \\\\\n\\implies \\quad \\lambda_{i} \\geq 0\n\\end{align*}\n\nThe \\textbf{singular values} of $A$ are the square roots of the eigenvalues of $A^{T}A$: $\\sigma_{i} = \\sqrt{\\lambda_{i}} = \\sqrt{\\norm{Av_i}^{2}} = \\norm{Av_i}$. Therefore, we can also see that $\\sigma_{i}$ is the length of the vector $Av_{i}$. \n\nSince $v_i$ and $\\lambda_{j}v_j$ are orthogonal while $i \\neq j$,\n\\begin{equation*}\n(Av_i)^{T}(Av_j) = v_{i}^{T}A^{T}Av_{j} = v_{i}^{T}(\\lambda_j v_{j}) = 0\n\\end{equation*}\n\nThis shows that $\\{Av_{1}, \\dotsm, Av_{n} \\}$ is an \\textbf{orthogonal set}. The lengths of $Av_{i}$ is given by the corresponding singular values of $A$. Typically, we arrange the singular values in order of decreasing magnitude, so that:\n\\begin{align*}\n&\\lambda_{1} \\geq \\lambda_{2} \\geq \\dotsm \\lambda_{n} \\geq 0 \\\\\n&\\sigma_{1} \\geq \\sigma_{2} \\geq \\dotsm \\sigma_{n} \\geq 0 \n\\end{align*}\n\nIf $A$ has $r$ non-zero singular values, then Rank($A$) = $r$, and $\\{Av_{1}, Av_{2}, \\dotsm, Av_{r} \\}$ is an \\textbf{orthogonal basis} for Col($A$). To show that the basis is $r-$dimensional, rather than $n-$dimensional, we will show that a vector $y$ in Col($A$) can be expressed as a linear combination of $\\{Av_{1}, \\dotsm, Av_{r} \\}$:\n\\begin{align*}\nx &= c^{T}v = c_{1}v_{1} + \\dotsm + c_{n}v_{n} \\\\\ny &= Ax = c_{1}Av_{1} + \\dotsm c_{r}Av_{r} + c_{r+1}Av_{r+1} + \\dotsm + c_{n}Av_{n} \\\\\n&= c_{1}Av_{1} + \\dotsm + c_{r}Av_{r} + 0 + \\dotsm + 0\n\\end{align*}\n\nThus, $y$ is in Span$\\{Av_{1}, \\dotsm, Av_{r} \\}$. Hence, Rank($A$) = dim(Col($A$)) = $r$.\n\n\\paragraph{SVD \\\\}\nLet $A$ be an $m \\times n$ matrix of rank $r$. Then, there is an $m \\times n$ matrix $\\Sigma$,\n\\begin{equation*}\n\\Sigma = \\begin{bmatrix}\nD & 0 \\\\ 0 & 0\n\\end{bmatrix}\n\\end{equation*}\nfor which the diagonal entries in $D$ are the first $r$ (i.e. the non-zero) singular values of $A$, where\n\\begin{equation*}\n\\sigma_{1} \\geq \\sigma_{2} \\geq \\dotsm \\geq \\sigma_{r} > 0\n\\end{equation*}\nFinally, there is an $m \\times m$ orthogonal matrix $U$ and an $n \\times n$ matrix $V$ such that:\n\\begin{equation}\nA = U \\Sigma V^{T}\n\\end{equation}\n\n$U$ and $V$ are not uniquely determined by $A$, and are referred to as the left- and right-singular vectors of $A$, respectively. We prove SVD below, starting with the assumption that $A$ is a $m \\times n$ matrix with eigenvalues $\\lambda_{i}$, corresponding eigenvectors $v_{i}$, and $r$ non-zero singular values $\\sigma_{i}$. As shown above, $\\{Av_{1}, \\dotsm, Av_{r} \\}$ will be an orthogonal basis for Col($A$). \n\nNormalize each $Av_{i}$ to obtain an orthonormal basis $U$:\n\\begin{align*}\nU &= \\{u_{1}, \\dotsm, u_{r} \\}, \\textrm{ where} \\\\\n u_{i} &= \\frac{Av_{i}}{\\norm{Av_{i}}} = \\frac{Av_{i}}{\\sigma_{i}} \\\\\n Av_{i} &= \\sigma_{i}u_{i}, \\quad 1 \\leq i \\leq r \n\\end{align*}\n\nExtend $U$ to a basis of $\\mathds{R}^{m}$: \n\\begin{equation*}\nU = \\begin{bmatrix}\nu_{1} & u_{2} & \\dotsm & u_{m} \n\\end{bmatrix} \n\\end{equation*}\nLet $V = \\begin{bmatrix}\n\tv_{1} & v_{2} & \\dotsm & v_{n}\n\\end{bmatrix}$. Then, $U$ and $V$ are both orthogonal matrices. We also have that\n\\begin{align*}\nAV &= \\begin{bmatrix}\nAv_{1} & \\dotsm & Av_{r} & 0 & \\dotsm & 0\n\\end{bmatrix} = \\begin{bmatrix}\n\\sigma_{1}u_{1} & \\dotsm & \\sigma_{r}u_{r} & 0 & \\dotsm & 0\n\\end{bmatrix}\n\\end{align*}\n\nLet $D$ be a diagonal matrix with diagonal entries $\\sigma_{1}, \\dotsm, \\sigma_{r}$. Then,\n\\begin{align*}\nU\\Sigma &= \\begin{bmatrix}\nu_{1} & u_{2} & \\dotsm & u_{m}\n\\end{bmatrix} \\begin{bmatrix}\nD & \\textrm{$n - r$ columns of $0$} \\\\\n\\textrm{$m-r$ rows of $0$} & 0 \\\\\n\\end{bmatrix} \\\\\n&= \\begin{bmatrix}\n\\sigma_{1}u_{1} & \\sigma_{2}u_{2} & \\dotsm & \\sigma_{r}u_{r} & 0 & \\dotsm & 0\n\\end{bmatrix} \\\\\n&= AV \\\\\nV^{-1} = V^{T} \\quad \\implies &\\quad U\\Sigma V^{T} = AVV^{T} = A \n\\end{align*}\n\n\\subsubsection{Computing $u^{+}$ with SVD}\n\n\\begin{equation}\n\\textrm{\\textbf{SVD:}} \\quad A = U\\Sigma V^T = \\begin{bmatrix}\nU_{\\textrm{col}} & U_{\\textrm{null}}\n\\end{bmatrix} \\begin{bmatrix}\n\\Sigma_{\\textrm{pos}} & 0 \\\\ 0 & 0\n\\end{bmatrix} \\begin{bmatrix}\nV_{\\textrm{row}} & V_{\\textrm{null}}\n\\end{bmatrix}^{T}\n\\end{equation}\n\n$U$ and $V$ are square matrices that have orthonormal columns: $U^{T}U = I$ and $V^{T}V = I$. $U_{\\textrm{col}}$ and $V_{\\textrm{row}}$ are bases for the column and row spaces of $A$, respectively, and have dimensions $r = \\textrm{Rank}(A)$. The other 'null' columns are in the nullspaces of $A^T$ ($U_{\\textrm{null}}$) and $A$ ($V_{\\textrm{null}}$). \n\nThe pseudoinverse of $A$ is computed as:\n\\begin{equation}\nA^{+} = V_{row}(\\Sigma_{pos})^{-1}U_{col}^{T}\n\\end{equation}\n\nWhere, $\\Sigma_{pos}$ is a diagonal matrix containing the \\textit{positive} singular values of $A$. $A^{+}b = u^{+}$ puts $u^{+}$ in the row space of $A^{+}$. \n\n\\subsubsection{Computing $u^{+}$ with Tychonov Regularization}\nSVD may not always be the most practical approach for solving the normal equations. When $A^{T}A$ is singular (the problem here), we can add a small multiple of $\\alpha I$, producing what is known as \\textbf{Tychonov Regularization}:\n\\begin{align}\n\\min &\\quad \\norm{Au-b}^{2} + \\alpha \\norm{u}^{2} \\\\\n\\textrm{s.t.} &\\quad (A^{T}A + \\alpha I)\\hat{u}_{\\alpha} = A^{T}b \\nonumber \n\\end{align}\n\nThis is similar to our original formulation of regularized LSQ, with $B = I$, $d=0$, and $\\alpha \\norm{u}^{2}$ as the regularizing term. When $\\alpha$ is small, we prioritize the minimization of $\\norm{Au-b}^{2}$. In the limit that $\\alpha \\rightarrow 0$, we have that \n\\begin{align*}\n\\lim\\limits_{\\alpha \\rightarrow 0} \\hat{u}_{\\alpha} &= \\lim\\limits_{\\alpha \\rightarrow 0} (A^{T}A + \\alpha I)^{-1} A^{T}b \\\\\n&= (A^{T}A)^{-1}A^{T}b = A^{+}b \\\\\n&= u^{+} \n\\end{align*}\n\nWe don't get $u^{+}$ exactly, with small $\\alpha > 0$. There is also uncertainty in $b$. The presence of a small $\\alpha$ in $(A^{T}A + \\alpha I)^{-1}A^{T}$ introduces small, non-zero singular values along the diagonal of our singular values matrix $\\Sigma$ in SVD. Importantly, $\\frac{\\sigma}{\\sigma^{2} + \\alpha} \\rightarrow \\frac{1}{\\sigma}$ while $\\alpha > 0$, but stays zero if $\\sigma = 0$. \n\n\\subsection{Tychonov Regularization}\nThis section discusses how to choose $\\alpha$. The key ideas are as follows:\n\\begin{enumerate}\n\t\\item There is noise in measurement of $b$, represented by an error $e$. \n\t\\item $e$ is amplified when $A$ is ill-conditioned (e.g. singular $A^{T}A$) and $\\alpha = 0$ (no regularization). This is why we use regularization. \n\t\\item Choosing an appropriate $\\alpha$, we can stabilize the problem by adding $\\alpha I$. However, if $\\alpha$ is too small, then $e$ will still grow with $A^{-1}$. If $\\alpha$ is too large, we lose accuracy on $\\hat{u}$. \n\\end{enumerate}\n\nWe will refer to multiple versions of the solution using the notation $\\hat{u}_{i}^{j}$, where $i$ represents our choice of $\\alpha$, and $j$ the expected size of uncertainty in $b$. For instance, $\\hat{u}_{0}^{0}$ refers to the solution without regularization or measurement error. On the other hand, $\\hat{u}_{\\alpha}^{e}$ is the solution attained from data with measurement error $e$, using regularization parameter $\\alpha$. \n\n\\subsubsection{Error bounds in $\\hat{u}$}\n\\paragraph{Error bounds when $A$ is a scalar. \\\\ }\nLet's first see how different we expect the solution $\\hat{u}$ to be in the two extreme cases: $\\hat{u}_{0}^{0}$ (no error, no regularization) and $\\hat{u}_{\\alpha}^{e}$ (error and regularization).\n\\begin{align}\n\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{e} &= \\hat{u}_{0}^{0} - \\hat{u}_{0}^{0} + \\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{e} \\\\\n\\norm{\\hat{u}_{0}^{0} - \\hat{u}_{0}^{\\alpha}} \\leq C\\alpha\\norm{b} &\\qquad \\norm{\\hat{u}_{\\alpha}^{0} - \\hat{u}_{\\alpha}^{e}} \\leq \\frac{\\norm{e}}{2\\sqrt{\\alpha}} \\label{errorbounds}\n\\end{align}\n\nWhere, $C$ is a constant that we will define below. Let's first prove the error bounds in Eq. \\ref{errorbounds} when $A$ is a scalar $s$. Then, $A^{T}A = s^{2}$. When noise is absent from measurements:\n\\begin{align}\n\\textrm{Without regularization:} &\\quad s^2 \\hat{u}_{0}^{0} = sb \\\\\n\\textrm{With regularization:} &\\quad (s^{2}+\\alpha)\\hat{u}_{\\alpha}^{0} = sb \\\\\n\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{0} &= \\frac{b}{s} - \\frac{sb}{s^{2}+\\alpha} \\nonumber \\\\\n&= \\frac{b(s^{2}+\\alpha)-s^{2}b}{s(s^{2}+\\alpha)} \\nonumber \\\\\n&= \\frac{\\alpha b}{s(s^{2}+\\alpha)} \\leq C \\alpha b, \\quad C = \\frac{1}{s^{3} + s\\alpha} \\label{errorbounds_scalar_nonoise}\n\\end{align}\n\nEq. \\ref{errorbounds_scalar_nonoise} shows that, in the absence of measurement noise, the error associated with regularization is proportional to $\\alpha$, i.e. $O(\\alpha)$. $C$ scales steeply with $1/s^{3}$. We perform the same procedure to compare the effect of measurement noise:\n\n\\begin{align}\n\\textrm{Without noise:} &\\quad (s^{2} + \\alpha)\\hat{u}_{\\alpha}^{0} = sb \\\\\n\\textrm{With noise:} &\\quad (s^{2} + \\alpha)\\hat{u}_{\\alpha}^{e} = s(b-e) \\\\ \n\\hat{u}_{\\alpha}^{0} - \\hat{u}_{\\alpha}^{e} &= \\frac{sb}{s^{2}+\\alpha} - \\frac{s(b-e)}{s^{2} + \\alpha} \\nonumber \\\\ \n&= \\frac{s}{s^{2}+\\alpha}e \n\\end{align}\n{The maximum value of $s/(s^{2}+\\alpha)$ will determine the bound. We can find this value by setting its derivative to zero.\n\\begin{align}\n0 &= \\frac{d}{ds}\\frac{s}{s^{2}+\\alpha} = (s^{2}+\\alpha)^{-1} - s(s^{2}+\\alpha)^{-2}(2s) \\nonumber \\\\\n&= \\frac{1}{s^{2}+\\alpha} - \\frac{2s^{2}}{(s^{2}+\\alpha)^{2}} \\nonumber \\\\\n\\frac{2s^{2}}{(s^{2}+\\alpha)^{2}} &= \\frac{1}{s^{2}+\\alpha} \\implies 2s^{2} = s^{2} + \\alpha, \\quad \\therefore s = \\sqrt{\\alpha} \\nonumber \\\\\n\\therefore \\frac{s}{s^{2}+\\alpha} &\\leq  \\frac{1}{2\\sqrt{\\alpha}} \\label{errorbound_scalar_withnoise} \n\\end{align}\n\n\\paragraph{Error bounds when $A$ is a matrix. \\\\}\nSVD of $A$ produces orthonormal bases $\\{u_{1}, u_{2}, \\dotsm \\}$ and $\\{v_{1}, v_{2}, \\dotsm \\}$, with $Av_{j} = \\sigma_{j}u_{j}$ and $A^{T}u_{j} = \\sigma_{j}v_{j}$. Note that, unlike before, we are not using $v_i$ to refer to the eigenvectors of $A$; instead, they are the right-singular vectors of $A$. \n\nWe can apply SVD to rewrite the regularized LSQ problem in terms of $u_{j}$ and $v_{j}$:\n\\begin{align}\n(A^{T}A + \\alpha I)\\hat{u}^{0}_{\\alpha} &= A^{T}b \\nonumber \\\\\nb = B_{1}u_{1} + B_{2}u_{2} + \\dotsm, &\\quad \\hat{u}^{0}_{\\alpha} = U_{1}v_{1} + U_{2}v_{2} + \\dotsm \\nonumber \\\\ \n(A^{T}A + \\alpha I)U_{j}v_{j} &= A^{T}B_{j}u_{j}  \\\\\nU_{j} A^{T}A v_{j} + U_{j} \\alpha I v_{j} &= \\sigma_{j}B_{j}v_{j} \\nonumber \\\\\nU_{j} \\sigma_{j} A^{T} u_{j} + U_{j} \\alpha v_{j} &=  \\nonumber \\\\\nU_{j} \\sigma_{j} (\\sigma_{j}v_{j}) + U_{j} \\alpha v_{j} &= \\nonumber \\\\\nU_{j}v_{j}(\\sigma_{j}^{2}+\\alpha) &= \\nonumber \\\\\nU_{j}(\\sigma_{j}^{2}+\\alpha) &= \\sigma_{j}B_{j} \\\\\n\\implies U_{j} &= \\frac{\\sigma_{j}}{\\sigma_{j}(\\sigma_{j}^{2}+\\alpha)}B_{j} = \\frac{\\sigma_{j}}{\\sigma_{j}^{3}+\\sigma_{j}\\alpha}B_{j} \\label{errorbound_matrix_nonoise}\n\\end{align}\n\nEq. \\ref{errorbound_matrix_nonoise} is identical to what we saw for the scalar case (Eq. \\ref{errorbounds_scalar_nonoise}) if $s = \\sigma_{j}$. Likewise, the results in the presence of noise are also similar to the scalar case. To get the total difference between either solution group, we need to sum each of the $U_{j}$ coefficients:\n\\begin{align}\n\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{0} &= \\sum_{j=1}^{\\infty} \\frac{\\alpha B_{j}}{\\sigma_{j}(\\sigma_{j}^{2}+\\alpha)} v_{j} \\\\\n\\hat{u}_{\\alpha}^{0} - \\hat{u}_{\\alpha}^{e} &= \\sum_{j=1}^{\\infty} \\frac{s_{j} E_{j}}{s_{j}^{2} + \\alpha} v_{j}\n\\end{align}\n\nWhere, in the presence of noise, we replace $b$ with $e = E_{1}v_{1} + E_{2}v_{2} \\dotsm$. The norm of either sum is a sum of squares wherein the $v_{j}$ terms disappear because they are orthonormal: $\\sum_{j=1}^{\\infty} v_{j}^{2} = 1$. Hence,\n\n\\begin{align}\n\\norm{\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{0}}^{2} &= \\sum_{j=1}^{\\infty} \\left(\\frac{\\alpha B_{j}}{\\sigma_{j}(\\sigma_{j}^{2}+\\alpha)}\\right)^{2} \\\\\n\\norm{\\hat{u}_{\\alpha}^{0} - \\hat{u}_{\\alpha}^{e}}^{2} &= \\sum_{j=1}^{\\infty} \\left(\\frac{s_{j} E_{j}}{s_{j}^{2} + \\alpha}\\right)^{2}\n\\end{align}\n\nThe $u_{j}$ terms are also orthonormal, so \n\\begin{align*}\n\\norm{b^{2}} = B_{1}^{2}u_{1}^{2} + B_{2}^{2}u_{2}^{2} + \\dotsm = \\sum_{j=1} \\norm{B_{j}}^{2} \\\\\n\\norm{e^{2}} = E_{1}^{2}u_{1}^{2} + E_{2}^{2}u_{2}^{2} + \\dotsm = \\sum_{j=1} \\norm{E_{j}}^{2} \n\\end{align*}\n\nThis gives\n\\begin{align}\n\\norm{\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{0}} &\\leq \\left( \\sum_{j=1}^{\\infty} \\frac{1}{\\sigma_{j}(\\sigma_{j}^{2}+\\alpha)}\\right) \\alpha \\norm{b} \\approx \\frac{\\alpha}{\\sum \\sigma_{j}^{3}} \\norm{b} = \\frac{\\alpha}{s_{min}^{3}} \\norm{b} \\\\\n\\norm{\\hat{u}_{\\alpha}^{0} - \\hat{u}_{\\alpha}^{e}} &\\leq \\left(\\sum_{j=1}^{\\infty}\\frac{s_{j}}{s_{j}^{2} + \\alpha}\\right)^{2} \\norm{e} = \\frac{\\norm{e}}{2\\sqrt{\\alpha}} \\label{errorbound_matrix_noise_final}\n\\end{align}\n\nIn Eq. \\ref{errorbound_matrix_noise_final}, we made the substitution $s_{j} = \\sqrt{\\alpha}$, by analogy with the scalar case (see Eq. \\ref{errorbound_scalar_withnoise}). \n\n\\paragraph{What is a good $\\alpha$? \\\\}\nWe can find a possible $\\alpha$ by finding the value that equalizes the two parts of overall error (Eq. \\ref{errorbounds}):\n\\begin{align}\nC\\alpha \\norm{b} &= \\frac{\\norm{e}}{2\\sqrt{\\alpha}} \\\\\n2\\alpha^{3/2} = \\frac{\\norm{e}}{C\\norm{b}} &\\implies \\alpha = \\left(\\frac{\\norm{e}}{2C\\norm{b}}\\right)^{2/3}\n\\end{align}\n\nThen, the overall error is found by plugging this value into the two parts of error, and summing them:\n\\begin{align*}\n\\norm{\\hat{u}_{0}^{0} - \\hat{u}_{\\alpha}^{e}} &\\leq C\\alpha \\norm{b} + \\frac{\\norm{e}}{2\\sqrt{\\alpha}} \\\\\n&\\leq \\frac{\\norm{e} + 2C \\alpha^{3/2} \\norm{b} }{2\\sqrt{\\alpha}} \\\\\n&\\leq \\frac{\\norm{e} + C\\norm{b}\\left(\\frac{\\norm{e}}{C\\norm{b}}\\right) }{2 \\left(\\frac{\\norm{e}}{2C\\norm{b}}\\right)^{1/3}} \\\\\n&\\leq \\frac{2\\norm{e} \\left(2C\\norm{b}\\right)^{1/3} }{2\\norm{e}^{1/3}} = \\frac{\\norm{e} \\left(2C\\norm{b}\\right)^{1/3} }{\\norm{e}^{1/3}} \\\\\n&\\leq \\norm{e}^{2/3} \\left(2C\\norm{b}\\right)^{1/3} = \\left[\\norm{e}^{2} \\norm{b}C\\right]^{1/3} \n\\end{align*}\n\nStrang writes that this rule suggests that \"we know more than we really do.\" I'm not sure what to make of this, but my guess is that this is due to the exponent of $\\norm{e}$ being 2/3, rather than $\\geq 1$. Perhaps, this means that this choice of $\\alpha$ underestimates how much error there really is in our measurements.\n\n\\medskip \n\\bibliographystyle{unsrt}\n\\bibliography{./bib/strang_and_lay_linalg}\n\n\\end{document}\n", "meta": {"hexsha": "8f9f8fb29edab8ffd40e9340f420a7922821d712", "size": 49046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_posts/Strang_c8_notes.tex", "max_stars_repo_name": "haganenoneko/website.github.io", "max_stars_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_posts/Strang_c8_notes.tex", "max_issues_repo_name": "haganenoneko/website.github.io", "max_issues_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_posts/Strang_c8_notes.tex", "max_forks_repo_name": "haganenoneko/website.github.io", "max_forks_repo_head_hexsha": "fcb72e2ba797f22f262d54d82a0b0b4b4d9b4a69", "max_forks_repo_licenses": ["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.3747126437, "max_line_length": 653, "alphanum_fraction": 0.6516739388, "num_tokens": 18269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6217759775024279}}
{"text": "\\chapter{Wilson loops}\\label{ch:WilsonLoops}\n\n\nA Wilson loop is a gauge-invariant observable, \ndefined as the expectation value of the character of the representation $\\mathcal{R}$ of the gauge group \n($U(N)$ in our case):\n\\begin{equation}\n  W_{\\mathcal{R}}(C) =  \\left\\langle \\text{tr}_{\\mathcal{R}} U \\right\\rangle, \\quad U \\in U(N)\n  %\\dfrac{1}{\\text{dim}\\, \\mathcal{R}}\n\\end{equation}\nwhere $U$ is a path-ordered exponential of the gauge connection $A_\\mu$, \ntransported along an arbitrary curve $C$ parametrized by $s$:\n\\begin{equation}\n U = \\mathop{\\mathrm{P}}\\exp \n    \\left[ \n\ti \\int_C ds\\,\t\n\t  \\dot{x}^\\mu A_\\mu\n    \\right],\n\\end{equation}\nwhere the dot denotes derivative respect $s$.\n\nPhysically, the Wilson loop operator measures the phase associated with moving a probe particle with charge\n$\\mathcal{R}$ around a curve $C$ in spacetime.\nIn particular, the long rectangular Wilson loop in the fundamental representation, the path shown in the figure \\ref{fig:WLrectangle},\ndetermines the static quark and antiquark potential:\n\\begin{equation}\n V_{q\\bar{q}} (L) = -\\dfrac{1}{T} \\lim_{T\\rightarrow\\infty} \\log W_1(C).\n\\end{equation}\nIn confined theories such as QCD, the potential is linear,\n% $V_{q\\bar{q}} (L) \\propto L$, \nwhich is referred as the \\emph{area law} in terms of the Wilson loop,\n$\\log W \\propto L\\times T$,\nwhile in the deconfined phase, the Wilson loop follows the \\emph{perimeter law},  $\\log W \\propto L$.\n\n\n\\begin{figure}[t]\n\\begin{center}\n \\centerline{\\includegraphics[width=4cm]{Images/WLrectangle.png}}\n\\end{center}\n\\caption{\\label{fig:WLrectangle} Trajectory of a probe quark and antiquark separated by distance $L$, and travel $T$ distance in time. }\n\\end{figure}\n\n\nWe are interested in a supersymmetric extension of the Wilson loop,\nsuch that it is computable through localization, see conditions \\eqref{loc:susyCondition}.\nWe will study the so-called Maldacena-Wilson loop \\cite{Maldacena:1998im},\nwhere we add a coupling to the scalars of the vector multiplet:\n\\begin{equation} \\label{maldacenaWL}\n U = \\mathop{\\mathrm{P}}\\exp \n    \\left[ \n\t\\int_C ds\\,\n\t\\left(\n\t  i\\dot{x}^\\mu A_\\mu +|\\dot{x}|n^I\\Phi_I \n\t\\right)\n    \\right], \\quad I=0,9.\n\\end{equation}\n% where $n^I$ are components of the unit vector that parametrizes $S^5$.\nLet us start by reviewing some known results in $\\mathcal{N}=4$ SYM and then generalize them to $\\mathcal{N}=2^*$.\n\n\n\n\\section{Wilson loops in $\\mathcal{N}=4$ SYM}\n\nThe simplest Wilson loop is an infinite straight line. \nIt is a half-BPS object, meaning it commutes with half of the 32 supercharges of $\\mathcal{N}=4$ SYM.\nThis fact protects the Wilson line from quantum corrections and its value is simply one:\n\\begin{equation}\n \\braket{W_\\text{line}} = 1.\n\\end{equation}\n\n\nBy conformal transformation, the Wilson line can be mapped to a circular Wilson loop.\nThe result, however, is not the same. \nThis is often referred to as a conformal anomaly, \nand it is due to the fact that large conformal transformations such as inversion are not symmetries in the flat space\n(infinity is not a point of $\\mathbb{R}^d$). \nOn the sphere, these are symmetries, hence there is no distinction between a circle and a line, and the\nexpectation value of either is the same as for a circle on $\\mathbb{R}^4$ \\cite{Drukker:2000rr}.\nThe circular Wilson loop, which is also half-BPS, is exactly computable using the localized partition function for the theory on $S^4$,\nwhere the path is the equator of sphere, see figure \\ref{fig:equatorWL}.\n\n\\begin{figure}[t]\n\\begin{center}\n \\centerline{\\includegraphics[width=4cm]{Images/equatorWL.png}}\n\\end{center}\n\\caption{\\label{fig:equatorWL} The contour of the circular Wilson loop we study is the equator of the hypersphere the theory is defined on.}\n\\end{figure}\n\n\n\\subsection{Fundamental representation}\nThe circular Wilson loop in the fundamental representation is mapped to a matrix model expectation value:\n\\begin{equation}\\label{eq:W1mm}\n W_1 = \\left< \\dfrac{1}{N}\\sum_{i=1}^N e^{2\\pi a_i} \\right>_\\text{matrix model},\n%  \\overset{N \\gg 1}{\\approx} \\int_{-\\mu}^{\\mu} dx\\, \\rho(x) \\,e^{2\\pi x}\n\\end{equation}\nwhich can be solved exactly for GUE \\cite{Drukker:2000rr}:\n\\begin{equation}\n W_1 = \\dfrac{1}{N} L_{N-1}^1 (-\\lambda/(4N)) e^\\frac{\\lambda}{8N},\n\\end{equation}\nwhere $L$ is the generalized Laguerre polynomial:\n\\begin{equation}\n L_n^m(x)=\\dfrac{x^{-m}  e^x}{n!}\\,  \\dfrac{d^n}{dx^n}(e^{-x} x^{n+m}).\n\\end{equation}\n\nIn the large $N$ limit and fixed 't Hooft coupling, \n\\eqref{eq:W1mm} can be written as:\n\\begin{eqnarray}\n W_1 &=& \\int_{-\\mu}^{\\mu} dx\\, \\rho(x) \\,e^{2\\pi x} \\label{eq:W1continuous} \\\\\n     &=& \\dfrac{2}{\\sqrt{\\lambda}} I_1 (\\sqrt{\\lambda}), \\quad (N\\rightarrow \\infty \\quad \\text{and} \\quad \\lambda \\text{ - fixed})\n\\end{eqnarray}\nwhere for the last equality, we used the semicircle distribution \\eqref{semicircle},\nsince the Wilson loop insertion to the partition function is subleading in $N$.\n$I_1(x)$ is the modified Bessel function:\n\\begin{equation}\n I_1(x) = \\sum_{n=0}^\\infty  \\dfrac{1}{n! (n+1)!} \\left(\\dfrac{x}{2}\\right)^{2n+1}.\n\\end{equation}\n\n\nHistorically, the large-$N$ result was initially obtained by Erickson-Semenoff-Zarembo \\cite{Erickson:2000af},\nby summing over rainbow diagrams in perturbation theory, and they conjectured the Gaussian matrix model structure for $\\mathcal{N}=4$ SYM.\nEventually Pestun's work in localization \\cite{Pestun:2007rz} proved it.\n\n\n\nIn the 't Hooft limit, which is the holographic regime, \n\\begin{equation}\\label{W1holographic}\n W_1 = \\sqrt{\\frac{2}{\\pi}} \\lambda^{-3/4} e^{\\sqrt{\\lambda}}, \n \\quad (N\\rightarrow \\infty \\quad \\text{and} \\quad \\lambda \\rightarrow \\infty).\n\\end{equation}\n% which matches with the minimal surface of the worldsheet with boundary $C$, drawn by the classical string on the supergravity background.\n% We will discuss more on the holographic dual in another chapter.\n% The subleading order term comes from the measure of the path integral, and so far, \n% it is still an open problem that many attempted to solve (cite Papers). \n\n% The equatorial Wilson loops can be generalized to latitude Wilson loops, \n% though the latter are less supersymmetric, and belongs to the family of 1/4 BPS.\n% Their exact result can be obtained by just rescaling the 1/2 BPS, by \n% $\\lambda \\rightarrow \\lambda \\cos^2\\theta_0$, \n% where the angle $\\theta_0$ is the polar angle of the latitude.\n\n\n\\subsection{Higher rank representations}\n\nExact results for arbitrary representation of $U(N)$ can also be obtained \\cite{Fiol:2013hna}.\nThese are very generic, though, \nbut the generating function of $k$-antisymmetric representation \n\\begin{equation}\\label{eq:generatingFunctionAk}\n \\braket{G_{A_k}(t)}=\\sum_{k=0}^{N} t^k \\, W_{A_k}\n%  G_{A_k} same as G^{-} defined few lines below\n\\end{equation}\nhas a nice compact form:\n\\begin{equation}\n \\braket{G_{A_k}(t)}=\\text{det}\\left(t \\delta_{ij}+ L_{i-1}^{j-i}(-\\lambda/(4N)) e^{\\frac{\\lambda}{8N}}\\right).\n\\end{equation}\n\nWe study the 't Hooft limit\nfor the symmetric (+) and the antisymmetric (-) representations. \nThe generating functions\\footnote{\nHere, unlike in \\eqref{eq:generatingFunctionAk}, \nwe use the expansion parameter $e^{-\\nu}$ instead of $t$.}\nfor the character of these representations are explicitly known:\n\\begin{equation}\n G^{\\pm}(\\nu) = \\prod_{i=1}^N (1\\mp e^{a_i - \\nu})^{\\mp}.\n% Wilson loop in terms of the generating function: \n% \\left<G^{\\pm}(t)\\right>=\\sum_{k=0}^{N} t^k \\, W^{\\pm}_k\n\\end{equation}\nNotice that these are also the Bose (+) and Fermi (-) distributions, in terms of the eigenvalues $a_i$.\n\nThe standard procedure is to derive the character by inverting the generating function using Cauchy's integral formula:\n\\begin{equation}\\label{eq:characterIntegral}\n \\chi_k^\\pm \\equiv \\text{tr}_\\pm \\,U = \\int_{C-i\\pi}^{C+i\\pi} \\dfrac{d\\nu}{2\\pi i} \\, e^{\\nu k} G^\\pm(\\nu),\n\\end{equation}\nwhere $C>a_i, \\forall i$, for the symmetric case, and $C$ is arbitrary for the antisymmetric case.\n\n\nAll we need to do now is to compute the expectation value of the above integral. \nWe can still employ the semicircle distribution \\eqref{semicircle}, \nand we further take the large representation limit $k \\sim N$,\nwhich allows us to use the saddle-point method in \\eqref{eq:characterIntegral}, \\cite{Hartnoll:2006is}.\nThe saddle-point equation to solve for $\\nu_*$ is\n\\begin{equation}\\label{eq:saddlePointDensity}\n \\dfrac{k}{N} = \\int_{-\\mu}^\\mu dx \\, \\dfrac{\\rho(x)}{e^{L(\\nu_*-x)}\\mp 1}, \n \\quad (N\\rightarrow \\infty \\quad \\text{and} \\quad \\frac{k}{N} \\text{ - fixed}),\n\\end{equation}\nwhich is analogous to the particle density equation in a Bose/Fermi system.\n\nThe final leading solutions for the antisymmetric representation is\n\\begin{equation}\\label{solW-}\n \\log W_{k}^-= N \\frac{2\\sqrt{\\lambda }}{3\\pi}\\,\\sin^3\\theta, \n\\end{equation}\nwhere $\\cos \\theta\\equiv \\nu_*/\\mu$ satisfies the transcendental equation\n\\begin{equation}\\label{eqThetaAntisym}\n \\theta -\\frac{1}{2}\\,\\sin 2\\theta =\\pi \\frac{k}{N},\n\\end{equation}\nresulting from \\eqref{eq:saddlePointDensity}\nafter the step-function approximation of the Fermi distribution.\n\nFor the symmetric representation, however, \nthere is no saddle-point solution for \\eqref{eq:saddlePointDensity}. \nThis is the same phenomenon as the Bose-Einstein condensation.\nIt is possible to analytically continue the solution to the second Riemann sheet, though, \nas done in \\cite{Hartnoll:2006is},\nand the final result is:\n\\begin{equation}\\label{solW+}\n \\log W_{k}^+ = 2 N  f\\left(\\kappa\\right),  \n \\quad  \\kappa \\equiv \\frac{\\sqrt{\\lambda }\\,k}{4 \\,N}\n\\end{equation}\nwhere \n\\begin{equation}\\label{eqfSym}\n f(x) = x\\sqrt{1+x^2}+\\mathop{\\mathrm{arcsinh}}x.\n\\end{equation}\n\nThe drawback of the analytic continuation was that computing large-$N$ corrections became less clear, as attempted in \\cite{Faraggi:2014tna}.\nIn Paper II and Paper IV, we used a more systematic approach.\nPaper IV focused exclusively on the symmetric Wilson loop in $\\mathcal{N}=4$ SYM, \nwhere subleading corrections in $N$ were computed.\nThis result is consistent with the expansion of the known exact result for the multiply wrapped fundamental Wilson loop \\cite{Kawamoto:2008gp},\nwhich helped to clarify the apparent mismatch observed in \\cite{Faraggi:2014tna},\nand agrees with the analysis by \\cite{Yamaguchi:2007ps} that symmetric representations and the multiply-wound fundamental ones \ndiffer by exponentially-suppressed terms in strong coupling.\nPaper IV also derived the strong-coupling corrections, \nin response to the strong-coupling expansion done for the antisymmetric case in \\cite{Horikoshi:2016hds},\nwhere the Sommerfeld expansion of the Fermi distribution was used.\n%k-fundamental obtained by relplacing $\\lambda \\rightarrow k^2 \\lambda$.\n\n\n\n\n\\section{Wilson loops in $\\mathcal{N}=2^*$ SYM}\n\nThe story can be extended to $\\mathcal{N}=2^*$ SYM on $S^4$.\nHere we have an extra parameter: the scale $MR$.\nWe will take the decompactification limit $MR \\rightarrow \\infty$, where interesting phase transitions were seen, \nand also, the dual theory is fully known on $\\mathbb{R}^4$ \\cite{Pilch:2000ue}.\n% (the dual on $S^4$ is partially known, \\cite{Bobev:2013cja}).\n\n% We work with the equatorial circular Wilson loop and reasonably assume that results in the decompactification limit is universal for any large contour.\n\n\n\\subsection{Fundamental representation}\n\nSince the fundamental Wilson loop is basically an exponentially-weighted integral \\eqref{eq:W1continuous},\nits value in the strong coupling limit is determined by the largest eigenvalue $\\mu$\n(recall $\\mu\\sim\\sqrt{\\lambda}$, see \\eqref{semicircleN=2*}). \nThus, we do not expect its strong coupling corrections to probe the cusps region.\nIn Paper I, we computed the subleading correction to the endpoint $\\mu$,\nwhich lead to the same correction to the Wilson loop (in terms of the perimeter $l=2\\pi R$):\n\\begin{equation}\\label{WLFundN2}\n \\log W_1= P(\\lambda) Ml, \\quad P(\\lambda) = \\frac{\\sqrt{\\lambda}}{2 \\pi} -\\frac{1}{2} + \\mathcal{O}\\left(\\dfrac{1}{\\sqrt{\\lambda}}\\right), \n \\quad (MR\\rightarrow \\infty).\n\\end{equation}\nThe leading order term is the same as its homologous case in $\\mathcal{N}=4$, only rescaled by $MR$ \\cite{Buchel:2013id},\nas a direct consequence of the semicircle behavior of the bulk distribution \\eqref{semicircleN=2*}.\nAs a consistent check, when $M\\rightarrow 0$, the Wilson loop goes to 1, as expected for the $\\mathcal{N}=4$ case.\nMoreover, we clearly see the perimeter law here since the theory is not confining neither conformal.\n\n\n\n\\subsection{Symmetric and antisymmetric representations}\nIn Paper II, result for symmetric and antisymmetric representations were computed,\nup to the next-to-leading order in the strong coupling expansion.\nThe decompactified results at the leading order in $N$ are also the same as the ones in the $\\mathcal{N}=4$ case,\nbut rescaled differently:\n\\begin{eqnarray}\n \\log W_{k}^- &=& N M R\\frac{2\\sqrt{\\lambda }}{3\\pi}\\,\\sin^3\\theta,\\\\\n \\log W_{k}^+ &=& 2 N (MR)^2 f\\left(\\frac{\\kappa}{M R}\\right),\n\\end{eqnarray}\nwhere $\\theta$ and  $f$ satisfy the same equation as in \\eqref{eqThetaAntisym} and \\eqref{eqfSym}, respectively.\n\nNow, the interesting part lays in the subleading terms. \nUnlike the fundamental representation, the higher rank representations do probe the endpoint distribution of the eigenvalues, \nwhich has periodic cusps with period $MR$, see figure \\ref{fig:phaseDiagram}.\nThe results are:\n\\begin{equation}\\label{WantisymPW}\n \\delta \\log W_{k}^- = -\\dfrac{2\\pi^2}{3} \\dfrac{N M R}{\\lambda^{3/4}}\n\\begin{cases}\n 4\\tilde{f}^3 & {\\rm }0<\\tilde{f}\\leq 1\n\\\\\n \\tilde{f}^3+6\\tilde{f}-\\frac{3}{\\tilde{f}} & {\\rm } 1<\\tilde{f}\\leq 1+\\sqrt{2}\n \\\\\n \\vdots &\n\\end{cases}, \\quad \n\\tilde{f} = \\dfrac{\\lambda^{3/4} k }{ 4\\sqrt{\\pi} N}\n\\end{equation}\nand\n\\begin{equation}\\label{WsymPW}\n \\delta \\log W_{k}^+ = \\dfrac{2^5\\pi^{3/2}}{5}\\dfrac{N (M R)^2}{\\lambda^{3/4}} \\left(v^{5/2}+\\Theta(v-1)\\left(v+\\dfrac{2}{3}\\right)(v-1)^{3/2}\\right), \n\\end{equation}\nwhere $\\Theta(x)$ is the Heaviside function and $v$ is written in terms of the scaling parameter $\\tilde{f}$ as\n\\begin{equation}\n  \\dfrac{3}{2}\\tilde{f} = v^{3/2}-\\Theta(v-1)(v-1)^{3/2}, \\quad \\tilde{f} = \\dfrac{\\lambda^{3/4} k}{8\\sqrt{\\pi} M R N}.\n\\end{equation}\nThe solutions are plotted in figure \\ref{fig:plotsCorrection}.\nThe phase transitions are of second and third order for the antisymmetric and symmetric representations, respectively,\nin the sense that the derivatives of the free energy $F=-\\frac{1}{N}\\log W$ with respect to $\\tilde{f}$ exhibit discontinuity at these orders.\n\n% \\begin{figure}[t]\n% \\begin{center}\n%   \\includegraphics[width=0.49\\textwidth]{Images/AntisymBlack.pdf} \n%   \\includegraphics[width=0.49\\textwidth]{Images/SymBlack.pdf} \n% \\end{center}\n% \\caption{\\label{fig:plotsCorrection} Strong coupling correction for the (rescaled) log of Wilson loops in \n% antisymmetric representation (left) with the critical points at $\\{1, 1+\\sqrt{2}, 1+\\sqrt{2}+\\sqrt{3},\\ldots\\}$,\n% and in symmetric representation (right) with the critical point at $2/3$.}\n% \\end{figure}\n\n\\begin{figure}[t]\n\\begin{center}\n \\centerline{ \\includegraphics[width=0.8\\textwidth]{Images/AntisymBlack.pdf} }\n \\centerline{ \\includegraphics[width=0.8\\textwidth]{Images/SymBlack.pdf} }\n\\end{center}\n\\caption{\\label{fig:plotsCorrection} Strong coupling correction for (rescaled) log of Wilson loops in \nantisymmetric representation (up) with the critical points at $\\{1, 1+\\sqrt{2}, 1+\\sqrt{2}+\\sqrt{3},\\ldots\\}$,\nand in symmetric representation (down) with the critical point at $2/3$.}\n\\end{figure}\n\n", "meta": {"hexsha": "ebe63f50f72ada3afc9dca081dd1425cfd0837fa", "size": 15532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/WilsonLoops.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/WilsonLoops.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/WilsonLoops.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": 48.9968454259, "max_line_length": 153, "alphanum_fraction": 0.7298480556, "num_tokens": 4800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324587033253, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6217759729408957}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Lagrangians for EM fields, Uniqueness}\n\\begin{p}\nFrom the form of the Lagrangian for a charged particle in an electromagnetic field, find the generalized momentum $\\v{p}$.\n\\end{p}\n\\begin{s}\nAs discussed in the lecture, we generalize the potential \\[U' = qV - q\\dot{\\v{r}}\\cdot\\v{A}\\]\nand hence construct the Lagrangian:\n\\[\\LL = T - U' = \\frac{1}{2}m\\dot{\\v{r}}^2 - qV + q\\dot{\\v{r}}\\cdot\\v{A}\\]\nThe generalized momentum is then given by:\n\\[\\v{p} = \\dpd{\\LL}{\\dot{\\v{r}}} = m\\dot{\\v{r}} + q\\v{A}\\]\n\\end{s}\n\n\\begin{p}\nFind the generalized force for the above system in the x-direction, and the total time derivative of the generalized momentum, $\\od{\\v{p}}{t}$ (Recall that $\\v{A} = \\v{A}(x,y,z,t)$)).\n\\end{p}\n\\begin{s}\nThe generalized force in the x direction is given by:\n\\[F_x = \\dpd{\\LL}{x} = -q\\left(\\dpd{V}{x} - \\dot{x}\\dpd{A_x}{x} - \\dot{y}\\dpd{A_y}{x} - \\dot{z}\\dpd{A_z}{x}\\right)\\]\nThe total time derivative of the generalized momentum is given by:\n\\[\\dod{}{t}p_x = m\\ddot{x} + q\\left(\\dot{x}\\dpd{A_x}{x} + \\dot{y}\\dpd{A_x}{y} + \\dot{z}\\dpd{A_x}{z} + \\dpd{A_x}{t}\\right)\\]\nWhere we have used the chain rule. \n\\end{s}\n\n\\begin{p}\nWrite the equations of motion in terms of the electric and magnetic fields.\n\\end{p}\n\\begin{s}\nCombining the two equations above (EL equation), we have:\n\\[m\\ddot{x} = -q\\left(\\dpd{V}{x} + \\dpd{A_x}{t}\\right) + q\\dot{y}\\left(\\dpd{A_y}{x} - \\dpd{A_x}{y}\\right) + q\\dot{z}\\left(\\dpd{A_z}{x} - \\dpd{A_x}{z}\\right)\\]\nRecognizing the first term as the electric field term and the second/third terms as $B_z$ and $-B_y$ respectively, we recognize this as the x component of $\\dot{\\v{r}}\\times \\left(\\curl{\\v{A}}\\right)$, or the Lorentz Force! The y and z components follow similarly and we recover:\n\\[m\\ddot{\\v{r}} = q(\\v{E} + \\dot{\\v{r}}\\times\\v{B})\\]\nWhich matches up with Newton's Law. Hence, we have been able to extend the Lagrangian formalism to charged particles in electromagnetic fields.\n\\end{s}\n\n\\begin{p}\nConsider a charged, relativistic particle in an electric field $\\v{E}$. Show that the Lagrangian $\\mathcal{L}=-m c^{2} \\sqrt{1-v^{2} / c^{2}}-q V+q \\v{v} \\cdot \\v{A},$ with $m$ given by the rest mass, gives the correct (relativistic) equations of motion.\n\\end{p}\n\\begin{s}\nIf we recall from PHYS 200, the momentum generalized to the relativistic case has a Lorentz factor of $\\gamma = \\frac{1}{\\sqrt{1- \\frac{v^2}{c^2}}}$, given by:\n\\[\\v{p} = m_0\\gamma\\v{v}\\]\nSo we require that we get this back from the Lagrangian expression. Checking the generalized momentum, we see:\n\\[\\v{p} = \\dpd{\\LL}{\\v{v}} = -m_0c^2\\frac{1}{2}\\frac{1}{\\sqrt{1-\\frac{v^2}{c^2}}}\\left(-2\\frac{\\v{v}}{c^2}\\right) = m_0\\gamma\\v{v}\\]\nWhich lines up with our expectation.\n\\end{s}\n\n\\begin{p}\nShow that $\\LL = T - U +x^2\\dot{x}$ also gives the Newton’s equations of motion. What is the implication for the uniqueness of the Lagrangian then?\n\\end{p}\n\\begin{s}\nShowing that this satisfies Newton's equations of motion:\n\\[\\dpd{\\LL'}{x} = -\\dpd{U}{x} + 2x\\dot{x}\\]\n\\[\\dpd{\\LL'}{\\dot{x}} = m\\dot{x} + x^2 \\implies \\dod{}{t}\\dpd{\\LL'}{\\dot{x}} = m\\ddot{x} + 2x\\dot{x}\\]\nTherefore by the EL equation:\n\\[\\dpd{\\LL'}{x} = \\dod{}{t}\\dpd{\\LL}{\\dot{x}}\\]\n\\[-\\dpd{U}{x} + 2x\\dot{x} = m\\ddot{x} + 2x\\dot{x}\\]\nSo we recover Newton's law:\n\\[-\\dpd{U}{x} = m\\ddot{x}\\]\nThis shows that the Lagrangian is not unique. In general, we can always add a total derivative of the form:\n\\[\\dod{}{t}G(q,t)\\]\nto $\\LL$ without changing the equations of motion. To see that this is the case, consider the modified Lagrangian:\n\\[\\LL'(q, \\dot{q}, t) = \\LL(q, \\dot{q}, t) + \\dod{}{t}G(q,t)\\]\nAnd now computing the action, we have:\n\\[S'(q, \\dot{q}, t) = \\int_{t_1}^{t_2}\\LL(q, \\dot{q}, t)dt + \\int_{t_1}^{t_2}\\dod{}{t}G(q, t)dt\\]\nThe second term we compute to be $G(q_2, t_2) - G(q_1, t_1)$ which are independent of the trajectory (as the start and endpoints are the same). So this does not affect the overall action, or the trajectory that minimizes the action, or in other words:\n\\[\\delta S' = \\delta S\\]\n\\end{s}\n\n\\end{document}", "meta": {"hexsha": "454d6fb82232d2f3c88bdcc7131f08e307e047c6", "size": 4091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-6/Worksheet-6.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-6/Worksheet-6.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-6/Worksheet-6.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": 57.6197183099, "max_line_length": 279, "alphanum_fraction": 0.6572965045, "num_tokens": 1520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6217759650055953}}
{"text": "% !TEX root = ../bachlor-arbeit.tex\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_basic_nn}\n    \\caption{The most simple kind of NN is called densely connected or multilayer perceptron. For clarity only connections to the top most node of each layer are shown.}\n    \\label{fig:bg:basic_nn}\n\\end{figure}\n\nArtificial Neural Networks (ANN's or short NN's) are a kind of data structure inspired by the biological neurons found in nature. They can be used to find a wide range of input output relations. One classic example is mapping pictures of hand written digits to the actual digits. Rather than explicitly programmed, NN's are trained on a dataset $(X, \\, Y)$ of correct input output pairs.\n\n\n\\paragraph{Multilayer Perceptron}\nThis kind of classic NN consist of single nodes or neurons which are organized into layers. The terms node and neuron can be used interchangeably. Every node is connected to all the nodes of the previous and the next layer. For this reason the network is called dense or densely connected. Each node holds a value called activation $a$ where the activation to the first layer is the input to the network, here:\n$(x_1, \\, x_2, \\, x_3)$.\nThe nodes are connected by weights $w$ which specify how much one node should influence the next and every node has a bias $b$ to control at what total input activation the node itself should become active.\nTo calculate the activation of a node, one has to multiply all the activations of the previous layer with their respective weights $w$, add the bias $b$ and finally apply a non-linear activation function $\\sigma$.\nIn order to describe this process mathematically, we are going to use the usual index notation where superscripts specify the layer and subscripts the node. So $a^2_1$ is the activation of the first node in the second layer. To characterize each weight two subscripts are needed, for the end and beginning of the connection. For the example in figure \\ref{fig:bg:basic_nn} that gives\n\n\\begin{equation} \\label{eq:bg:activation_example}\n    a^2_1 = \\sigma \\qty(\\sum_i w^2_{1i} \\, x_i + b^2_1)\n\\end{equation}\n\n\\noindent\nHowever, it is more convenient to stop considering every node individually and to view the involved quantities as vectors and matrices. So that \\eqref{eq:bg:activation_example} can be written as\n\n\\begin{equation} \\label{eq:bg:activation}\n    \\vb{a}^l = \\sigma \\underbrace{\n    \\qty(\\vu{w}^l \\vb{a}^{l-1} + \\vb{b}^l)\n    }_{\n    \\textstyle\n    := \\vb z^l\n    }.\n\\end{equation}\n\nThat means the activation function $\\sigma$ maps the total input of a neuron $\\vb z^l$ to the output/activation of that neuron $\\vb a^l$. Two examples for activation functions can be seen in Figure \\ref{fig:al:act}.\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{bg_relu}\n    \\caption{rectified linear unit (ReLu)}\n    \\label{}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{bg_sigmoid}\n    \\caption{sigmoid}\n    \\label{}\n\\end{subfigure}\n\\caption{Two examples of activation functions $\\sigma$. Especially the ReLu function has a destinct on and off state similar to a biological neurons.}\n\\label{fig:al:act}\n\\end{figure}\n\n\\paragraph{Training}~\\\\\n\\label{par:training}During training the networks output $\\s{NN}(\\vb x) := \\vb{y}' $ is calculated through repeated use of \\eqref{eq:bg:activation} and is then compared with the known correct output $\\vb y$ by a cost function $C = C(\\vb y, \\, \\vb y')$. The goal of the training is to minimize this function $C$. The cost function might simply be the mean squared difference between $\\vb y$ and $\\vb y'$\n\n\\begin{equation}\n    C_\\s{mse}(\\vb y, \\, \\vb y') = \\sum_i \\qty(y_i - y_i')^2\n\\end{equation}\n\n\\noindent\nbut there are different cost functions for different kind of outputs. For example, a network which predicts continuous values needs a different cost function than one predicting categories. More on this in section \\ref{sec:NN}. Now we can quantify how well the NN is performing and are able to use this information to train the network.\n\\\\\n\n\\indent\nAs stated before, the goal of the training is to minimize the cost function $C$ by changing the weights and biases. This means we are looking for the partial derivatives $\\partial C / \\partial \\hat w^l_{j,k}$ and\n$\\partial C / \\partial b^l_j$. To find these we need the concept of the \\textit{error of a single neuron} $\\delta^l_j$, where\n\n\\begin{equation} \n    \\delta^l_j := \\pdv{C}{z^l_j}.\n\\end{equation}\n\nThis property expresses how much the final cost is affected by a change to the input of neuron $j$ in layer $l$. For the last layer $L$, we can find a simple expression for this property by using the chain rule\n\n\\begin{equation} \\label{eq:bg:back_prop}\n    \\delta^L_j = \\pdv{C}{z^L_j} = \\pdv{C}{a^L_j} \\ \\pdv{a^L_j}{z^L_j}\n    \\stackrel{\\eqref{eq:bg:activation}}{=}\n    \\pdv{C}{a^L_j} \\ \\sigma'(z^L_j).\n\\end{equation}\n\nRemember, $z^l_j$ is the input to a neuron and $a^l_j$ is the output. That means $\\delta^L_j$ is determined by a combination of how much the last output changes the cost function and how much the last input changes the last output. Notice how both these terms are easily accessible. $z^l_j$ was already calculated on the forward pass and the derivatives of the cost and activation functions can be found analytically. By using the gradient operator $\\grad$ and the Hadamard product $\\odot$, where\n\n\\begin{equation}\n    \\vb a \\odot \\vb b :=\n    \\begin{pmatrix}\n        a_1 \\, b_1 \\\\\n        a_2 \\, b_2 \\\\\n        \\vdots\n    \\end{pmatrix},\n\\end{equation}\n\nwe can return to the more convenient vector notation and write\n\n\\begin{equation} \\label{eq:bg:back1}\n    \\boldsymbol \\delta^L = \\grad_a C  \\odot \\sigma'(\\vb z^L).\n\\end{equation}\n\nNow we know $\\boldsymbol \\delta$ for the last layer but not for the rest of the network. However, we can express the error of an arbitrary layer $\\boldsymbol \\delta^l$ by the error in the next layer $\\boldsymbol \\delta^{l+1}$ through\n\n\\begin{equation} \\label{eq:bg:back2}\n    \\boldsymbol \\delta^l =\n    \\qty[(\\hat w^{l+1})^\\top \\, \\boldsymbol \\delta^{l+1}]\n    \\odot \\sigma'(\\vb z^l).\n\\end{equation}\n\nThis equation can be intuitively understood as moving the error\n$\\boldsymbol \\delta^{l+1}$ back one layer by applying $(\\hat w^{l+1})^\\top$ and then through the activation function of layer $l$ by applying $\\sigma'$. In a sense its again \"simply\" a chain rule. With these two equations, \\eqref{eq:bg:back1} and \\eqref{eq:bg:back2}, all the errors $\\boldsymbol \\delta$ in the network are known. Just start with the last layer and work your way backwards. This idea of moving the error backwards is the reason why the algorithm is called \\textit{Backpropagation}. \\\\\n\n\\indent\nThe last thing to do is to relate $\\boldsymbol \\delta$ back to the original derivatives $\\partial C / \\partial \\hat w^l_{j,k}$ and $\\partial C / \\partial b^l_j$. Using equation \\eqref{eq:bg:activation} gives\n\\begin{align}\n    \\partial C / \\partial b^l_j &= \\delta^l_j \\qq{and} \\\\[5pt]\n    \\partial C / \\partial \\hat w^l_{j,k} &= a^{l-1}_k \\, \\delta^l_j.\n\\end{align}\n\nNow we could modify the weights after every forward pass by\n\n\\begin{equation}\n    \\hat w^l_{j,k} \\leftarrow \n    \\hat w^l_{j,k} - \\eta \\  \\partial C / \\partial \\hat w^l_{j,k} \\,,\n\\end{equation}\n\nwith the learning rate $\\eta$ \\label{hyp:learnigrate}.\nThis method is called \\textit{stochastic gradient descent} and because the weights and biases are updated on every training sample the cost function can oscillate strongly. \nThis is why in practice updates are performed on small \\textit{mini-batches}\\label{hyp:minibatch} of training samples. This concludes the training of a Multilayer Perceptron. Other Neural Networks are trained in a similar manner. An excellent comprehensive explanation of Backpropergation was published by Nielsen \\cite{backprop}.\n\n\\paragraph{Convolutional Neural Networks}~\\\\\nAn area where NNs have been very successful is image recognition or more general computer vision but the described multilayer perceptron has a number of weaknesses for this kind of task. Let's say our input is a $n$ by $n$ gray scale image. This can be expressed as a $n \\cp n$ matrix, flattened and fed into the input layer as seen in figure \\ref{fig:bg:flatten}. But now the number of weights to the next layer $\\vu{w}^2$ is $n \\cdot n \\cdot l^2$\nwhich soon becomes unfeasible. As described in the section on \\hyperref[sec:notation]{Notation}, $l^2$ is here the number of nodes in the second layer and not $l$ squared.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.45\\linewidth]{bg_flatten}\n    \\caption{Flattening of a $3\\cp3$ matrix to fit the input of a multilayer perceptron.}\n    \\label{fig:bg:flatten}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_convnet_T}\n    \\caption{Two pictures of a T at different positions where the red color signifies a high value in the grayscale image. After the flatten operation seen in figure \\ref{fig:bg:flatten} very different nodes are active.}\n    \\label{fig:bg:convnet_T}\n\\end{figure}\n\n\\indent\nComputational limits aside, there is another problem. Imagine an image with the letter T in the top right corner. If this letter moves to a different position, as in figure \\ref{fig:bg:convnet_T}, the networks reaction will be completely different because the weights and biases involved are completely different. So the NN cannot learn the concept \"letter T\" independent of its position in the picture. The information about the distance between pixels is lost.\nThese problems led to the development of a new kind of layer called \\textit{Convolution}. A fixed size squared matrix called \\textit{kernel} is shifted over the matrix and at every position the point wise product between kernel and matrix is calculated and summed as shown in figure \\ref{fig:bg:conv_example}.\n\\\\\n\n\\indent\nThe result of this operation, called \\textit{feature map} of that kernel, is shown in figure \\ref{fig:bg:convolution}. Notice how the greatest value of the feature map is at the position of the letter T. So with only a small number of weights the convolution is able to detect the T independent of its position in the image.\nThis is still slightly misleading because this \"T kernel\" was intentionally constructed to find the T. In a real convolutional layer the kernel values are trained via Backpropagation similar to the weights of a Multilayer Perceptron as described in the paragraph \\hyperref[par:training]{Training}.\n\\\\\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_convolution_example}\n    \\caption{Example of a convolution. The $3 \\times 3$ kernel is shifted over the image one step at the time. The red color in the image represents a pixel value of 1. For example in picture (a) the point wise product between kernel and image is zero everywhere except at two positions where a one in the kernel meets a one in the image. Because there are less valid positions for the kernel than pixels in the image the result is smaller in size.}\n    \\label{fig:bg:conv_example}\n\\end{figure}\n\n\n \n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_convolution}\n    \\caption{Example of a convolution where white pixel are 0 and red pixel are 1. The $3 \\times 3$ kernel is shifted over the image and the point wise product between kernel and image is calculated at every step as described in figure \\ref{fig:bg:conv_example}. The result is the greatest when the kernel is directly over the letter T.}\n    \\label{fig:bg:convolution}\n\\end{figure}\n\nOne convolutional layer contains not only one but a number of different kernels $k$. The resulting $k$ feature maps are stacked in the \"$z$ direction\" so that the shape of the $n \\times n$ matrix transforms to $(n-2) \\times (n-2) \\times k$ when convolved with a $3 \\times 3$ kernel. In a convolutional network, short ConvNet, multiple of these layers are used so that it can find \"patterns in patterns\". For the letter detection example, one could imagine the first layer to detect various edges and the next layer to detect letters in the position of these edges.\n\n\\paragraph{Pooling Layers}~\\\\\nFor a big image and a large number of kernels the output shape of a convolutional layers is still $\\order{(n)^2 \\cdot k}$, so quite large. Also, notice how in figure \\ref{fig:bg:convolution} the \"T kernel's\" feature map is not only active at the exact position of the T but in the general region. The solution to this is to downsample the output with a \\textit{Pooling Layer}. Here a smaller kernel, usually $2 \\times 2$ is shifted over the matrix two steps at a time and at every position an operation is performed to reduce the number of values to one. This could be taking the maximum or the average of that $2 \\times 2$ region. This operation reduces the matrix in the x and y dimension by a factor of 2 as shown in figure \\ref{fig:bg:pooling}.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_pooling}\n    \\caption{Example of a Max Pooling Layer. For every 2 by 2 field the maximum is calculated. After applying first the convolution and then the pooling layer the information \"T in the top right corner\" is still there and size of the resulting matrix is very manageable.}\n    \\label{fig:bg:pooling}\n\\end{figure}\n\\vspace{1cm}\n\n\\paragraph{Example Network Architecture}~\\\\\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.8\\linewidth]{bg_example_convnet.png}\n    \\caption{Example for a complete ConvNet. Note that the input is an RGB image so there are three layers in the $z$ dimension corresponding to the different colors. In this case the first layer has 64 kernels of size $3 \\times 3 \\times 3$. The next convolution then has 128 kernels of size $3 \\times 3 \\times 64$. The final softmax activation rescales the output so that its sum is 1. \\cite{cat}}\n    \\label{fig:bg:NN_example}\n\\end{figure}\n\nNow all the building blocks for a complete ConvNet are available. Repeatedly alternating convolution and pooling layers changes the input from wide in x and y dimension and narrow in z to a long z-strip. At the very end this strip is fed into one densely connected layer which is in turn connected to the output neurons. An example architecture of this kind is shown in figure \\ref{fig:bg:NN_example}. This network could for example choose one of 1000 labels for the input image like car, human, cat...\n\n\n\n\\paragraph{1D ConvNets}~\\\\\nThe input to the desired algorithm is a target spectrum to which the Network should output some parameters (more on this in the section \\ref{sec:NN}). This input data is a function $I(\\lambda)$, so only one dimensional, in contrast to an image which is a function $f(x, \\, y)$ but all the same ideas apply. Convolutional kernels are sized $1 \\times 3 \\times z$ and pooling kernels are $1 \\times 2 \\times z$. Both are  only shifted in one direction as see in figure \\ref{fig:bg:1D_conv}. These 1D convolutions might detect features like rising and falling edges and the later layers might combine these features into concepts like peaks and troughs. However, as always in machine learning what the network actually does to reach its objective is not controlled by the programmer.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.4\\linewidth]{bg_1D_conv}\n    \\caption{Example of a 1D convolution. A $1 \\times 3$ kernel is shifted over a spectrum $I$ discretized at 7 wavelengths}\n    \\label{fig:bg:1D_conv}\n\\end{figure}\n\\vspace{1.5cm}\n\n\\paragraph{Dropout Layer} ~\\\\\nIn 2014 Srivastava et al.\\cite{Srivastava2014} presented a method to prevent overfitting and speed up the training process of large Neural Networks. During training, for each step, they randomly drop a number of neurons in a layer along with all connections to and from these neurons. This prevents the neurons from co-adapting \\cite{Srivastava2014} and because there are less weights and biases to tune for each step the training becomes overall faster.\nThese layers are characterized by their \\textit{drop rate} \\label{hyp:dropout} that determines what fraction of neurons should be dropped. The process of dropping neurons is shown in figure \\ref{fig:bg:dropout}.\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=.9\\linewidth]{bg_no_dropout}\n    \\caption{no dropout}\n    \\label{}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=.9\\linewidth]{bg_dropout}\n    \\caption{with dropout}\n    \\label{}\n\\end{subfigure}\n\\caption{Example of a dropout applied to the bottom layer. Only two of the neurons remain active and only their weights and biases are modified during this training step. \\cite{Srivastava2014}}\n\\label{fig:bg:dropout}\n\\end{figure}\n", "meta": {"hexsha": "fb737d00a11d7d93081f911a618d0c86c4452182", "size": 16816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/background/neural_networks_background.tex", "max_stars_repo_name": "TimLucaTuran/bachlor-arbeit", "max_stars_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "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/background/neural_networks_background.tex", "max_issues_repo_name": "TimLucaTuran/bachlor-arbeit", "max_issues_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-17T15:04:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-17T15:04:05.000Z", "max_forks_repo_path": "tex/background/neural_networks_background.tex", "max_forks_repo_name": "TimLucaTuran/bachlor-arbeit", "max_forks_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "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": 73.1130434783, "max_line_length": 778, "alphanum_fraction": 0.751724548, "num_tokens": 4391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768094082276, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6217706003512989}}
{"text": "\n\\subsection{Interaction between agents}\n\n\\subsubsection{Introduction}\n\nPreviously actions map to states. Not now.\n\n\\subsubsection{More intro}\n\nPreviously we modelled utility as a function of variables in control of the agent, or constants. We now add another type of term: variables controlled by other agents.\n\nConsider a simple pair of agents:\n\n\\(u_a=f_a(x_a,y_a)\\)\n\n\\({actions_a}=\\{x_a,y_a\\}\\)\n\n\\(u_b=f_b(x_b,y_b)\\)\n\n\\({actions_b}=\\{x_b,y_b\\}\\)\n\nEach agent’s decision does not affect the other agent. Consider now a utility function:\n\n\\(u_a=f_a(x_a,y_a)\\)\n\n\\({actions_a}=\\{{x offer}; {y offer}\\}\\)\n\n\\(u_b=f_b(x_b,y_b)\\)\n\n\\({actions_b}=\\{accept; reject\\}\\)\n\nWhere \\(a\\) offers a trade to \\(b\\) and \\(b\\) accepts or rejects. This is an example of a sequential game. There are many types of game, with differing implications.\n\n", "meta": {"hexsha": "490fa42c6f75af3d23e296303ab6763464e46181", "size": 828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/gameTheory/01-01-gameMotivation.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/gameTheory/01-01-gameMotivation.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/gameTheory/01-01-gameMotivation.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.3529411765, "max_line_length": 167, "alphanum_fraction": 0.7125603865, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6217705875192904}}
{"text": "\\chapter{Computational complexity}\n\nThere are two computational resources we concern ourselves with:\ntime and space.\nThe unit of time is arbitrary.\nNumber of steps. Each step takes the same amount of time.\nEach configuration transition uses the same amount of time.\n\nThe time used by that computation is the length of the corresponding path.\nFormally the time required by the machine\nto move from configuration $a$ to $b$ is\nthe smallest natural number $n$ such that $\\beta^n a = b$.\nBy definition, the machine \\emph{moves in one unit time} from configuration $x$ to $y$ iff $\\beta x = y$\nso $\\beta$ depends on the set of primitive operations we equip the machine with.\n\nThe \\emph{time-to-termination} of a configuration $x$,\nwritten $\\TC \\beta x$,\nis the smallest natural number $n$ such that $\\beta^n x$ is terminal.\nThe time-to-termination of $x$ is the length of the shortest path from $x$ to a terminal configuration.\n\nThe maximum space usage of a computation is\nthe maximum of the space usages of the vertexes of the corresponding path.\nNow suppose that we write $s x$ as the \\emph{space usage} of configuration $x$.\nThe space usage of an initial configuration is the size of the input.\nWe define $\\SC \\beta x$,\nthe \\emph{maximum-space-to-termination} of a computation from $x$\nas follows:\n\\begin{equation}\n    \\SC \\beta x = \\max_{c \\in C \\beta x} s c\n\\end{equation}\nwhere we define\n$C \\beta x = \\{ \\beta^k x \\,|\\, k \\in \\mathbb N \\}$\nas the set of all configurations\nthat can be reached from $x$ by following $\\beta$.\n\n\\section{Time class}\n\nWhat can a machine compute in a given number of steps?\nGiven more time, does a machine compute more?\n\nWhat is the relationship between the size of the input and the running time?\nWhat is the relation between the size of\nan initial configuration and its time-to-termination?\nHow fast does the time-to-termination grow?\n\nWe are talking about a special kind of problems\nwhose time usage depends only on the length of the input.\n\nA \\emph{time class} is a set of all initial configurations that have the same time-to-termination.\nDefine the \\emph{time class $n$ of machine $D$},\nwritten $\\Teq D n$ (or just $\\Teq n$ when the machine is clear in the context),\nas the set of every initial $D$-configuration\nwhose time-to-termination equals $n$.\nThen define $\\Teqsum n$, the \\emph{max-time class $n$},\nas the set of every initial configuration whose time-to-termination is less than $n$:\n\\begin{equation}\n    \\Teqsum n = \\bigcup_{k = 0}^{n - 1} \\Teq k\n\\end{equation}\n\nFor example, if the machine ignores its input and runs in constant time,\n$\\Teqsum 1 = I$.\n\n\\newcommand{\\Cset}{\\mathbf{C}}\nDefine $\\Cset n$ as the set of every initial configuration whose size is less than $n$.\nThe \\emph{time simplicity function of the machine} is\n\\begin{equation}\n    K n = \\frac{\\mu(\\Teqsum n)}{\\mu(\\Cset n)}\n\\end{equation}\n(Find a better name?)\nHigher $K n$ means faster computation.\nThe \\emph{space simplicity function} of the machine is defined analogously:\n\\begin{equation}\n    J n = \\frac{\\mu(\\mathbf S n)}{\\mu(\\Cset n)}\n\\end{equation}\n\nIf the alphabet used is the binary alphabet $\\{ 0, 1 \\}$\nand the input is a natural number encoded using the usual binary positional encoding,\nthen $\\mu (C n) = 2^n$ and thus $\\mu (\\Cset n) = 2^{n + 1} - 1$.\n\nIf every instance $x$ of size $\\mu x$ is solved by machine\n(if the time-to-termination of each initial configuration $x$ of size $\\mu x$ is less than $f(\\mu x)$)\nthen we say that the problem is size-bounded by $f$.\n\nIs there an $m$ such that for all $n > m$, we have $\\Teq n = \\varnothing$?\nOnly if the machine does not read all its input?\n\nNow we examine the relation between the size of the initial configuration\nand the time to termination of that configuration.\nIntuitively, when the problem is non-trivial, as the initial configuration grows larger,\nthe machine should require more time to arrive at the related terminal configuration.\nIf the problem is non-trivial then a bigger initial configuration\nshould imply a higher time to termination of that configuration.\n\nThe minimum time-to-termination of every initial configuration of size $n$.\n\nThe maximum size of every initial configuration with time-to-termination of $n$.\n\nThe sets of functions computable by deterministic and nondeterministic machines are the same?\n\n$\\Teq n$ may be empty?\n\n$\\Teq n$ and the length of.\n\nDefine space equivalence class $n$ as $\\Seq n$ as the set of\nevery configuration that has a maximum-space-to-termination of $n$.\n\nBoth $\\TC$ and $\\SC$ are functions.\nAre they computable?\n$C \\beta$ is also a function.\n\nEvery configuration following $x_0$ is fully determined by $x_0$.\nThe computation is fully determined by its first configuration.\nA machine is deterministic in the sense that given a configuration,\nthe computation that proceeds from that configuration is always the same.\nWhat can graph theory say about computation?\nWhat result in graph theory helps us discover something in computation theory?\nWeighted graph can model computation with nonuniform transition time.\nBut for what?\nModeling modern machines with speculative execution?\n\nWe say that an algorithm $a$ is in $\\TIME(O(f n))$ where $n$ is the length of the input iff\nfor infinitely many (but not necessarily every) $i$ in each initial configuration\n$x \\equiv (a,i)$ that eventually terminates, we have $\\TC x \\in O(f(s x))$.\n\nDetermining if a number is divisible by $m$ is a constant-time operation in a machine with alphabet of size $m$,\nbut is it also constant-time operation in a machine with another base that is coprime to $m$?\n\n\\section{Fair coding scheme}\n\nHow to code almost anything into a bit string?\n\nHow to code members of type $t$ into bits?\n\nHow do we constrain the coding function so that meticulous mathematicians\ncannot cheat by shifting the computation into the coding function?\n\nLet $\\mu t : t \\to \\Nat$ be the \\emph{canonical measure} of an element of the countable type $t$.\n\nLet $c t : t \\to \\Bits$ be the coding function.\nThis coding function must be measure-preserving, size-preserving.\nFormally the coding function must satisfy\n\\[\n    \\mu t x \\le \\mu t y \\iff \\mu \\Bits (c t x) \\le \\mu \\Bits (c t y)\n\\]\nfor each $x : t$ and $y : t$.\n\n\\section{Terminology and notation}\n\nA \\emph{list} $x$ of $X$ of length $n$ is $[x_0,x_1,\\ldots,x_{n-1}]$\nwhere each $x_k$ has the type $X$.\nThe list $x$ has type $X^*$ (the Kleene closure of $X$).\nThe empty list is written $[]$.\nLists are also known as \\emph{strings}.\n\nAn \\emph{instance} is a string.\nA \\emph{problem} is a set of instances.\nA problem is also called a \\emph{language}.\n\nA \\emph{complexity class} is a set of problems.\n\nWe write $\\TC_M e$ to mean the number of time units required by machine $M$\nto evaluate expression $e$.\nSometimes $M$ is omitted so we write only $\\TC e$\nsuch as when the machine is not too relevant\nor is clear in the context.\n\nTo evaluate an expression is to reduce it until it becomes a value.\nA value is an expression that reduces to itself.\n\nAn \\emph{$X$-decider} is an implementation of a function having the type $X \\to \\mathbb B$.\nWe say that the decider \\emph{accepts} the input $x$ iff $fx$ is true.\nThe \\emph{language} recognized by the decider is the set\n\\begin{align*}\n    \\langset f = \\{ x ~|~ x : X, ~ fx \\}\n\\end{align*}\n\nWe say that $b$ is a time usage lower bound of decider $f$ iff $fx \\in \\Omega b$.\nWe say that $b$ is the time usage infimum of that decider iff\nfor all $c$ that is a time usage lower bound of $f$,\n$b$ is a time usage lower bound of $f$ and $b \\in \\Omega c$.\n\nThe \\emph{decider set} of a language \\(L\\) is \\(\\decset L = \\decset L = \\{ f ~|~ \\langset f = L \\}\\).\nIt is the set of all deciders whose language is \\(L\\).\nWe say $f \\leTC g$ iff $\\forall x \\in X^* ~ \\TC(fx) \\in O(\\TC(gx))$.\n\n$f$ is a \\emph{minimum-time decider} of $L$ iff for each $g \\in \\decset L$,\nit holds that $\\forall x \\in X^* ~ \\TC(fx) \\in O(\\TC(gx))$.\nIn other words, such $f$ is an infimum of $\\decset L$ according to $\\leTC$.\n\n\\begin{msco}[nonexistence of time usage supremum]\n    $\\decset L$ has no supremum according to $\\leTC$.\n    For each decider $f \\in \\decset L$, there exists an asymptotically slower $g \\in \\decset L$.\n    \\begin{align}\n        \\forall f \\in \\decset L ~ \\exists g \\in \\decset L ~ \\forall x \\in X^* ~ \\TC(fx) \\in o(gx)\n    \\end{align}\n\\end{msco}\n\n\\begin{mcor}[decider set equivalence class]\n    We can define two deciders as $f$ and $g$\n    as equivalent iff for all input $x$,\n    their time usage is asymptotically similar.\n    \\begin{align}\n        \\mathcal E m p L = \\{ f ~|~ \\langset f = \\decset L, ~ \\forall x \\in X^* ~ \\TC_m(fx) \\in \\Theta(\\TC_m(px)) \\}\n    \\end{align}\n\\end{mcor}\n\n\\begin{msco}[NTIME upper bound]\n    Let $N$ be a nondeterministic machine.\n    The number of time units required by $N$\n    to evaluate $\\SDP fx$ is bounded above as follows\n    where $n$ is the length of $x$:\n    \\begin{align}\n        \\TC_N(\\SDP fx) \\in O\\left(n + \\max_{s \\sqsubseteq x} (\\TC(fs))\\right)\n    \\end{align}\n\\end{msco}\n\n\\begin{msco}[DTIME upper bound]\n    Let $D$ be a deterministic machine.\n    The number of time units required by $D$\n    to evaluate $\\SDP fx$ is bounded above as follows\n    where $n$ is the length of $x$:\n    \\begin{align}\n        \\TC_D(\\SDP fx) \\in O \\left( \\sum_{s \\sqsubseteq x} \\TC(fs) \\right)\n    \\end{align}\n\\end{msco}\n\nA \\emph{$g$-transformer} of a decider $f$ is a function $g : X^* \\to X^*$\nsuch that $fx = f(gx)$ for all $x : X^*$.\nIf $\\TC(fx) \\in o(\\TC(f(gx)))$ then\nwe call the $g$-transformer a \\emph{$g$-speedup}.\nOn the other hand if $\\TC(fx) \\in \\omega(\\TC(f(gx)))$ then\nwe call the $g$-transformer a \\emph{$g$-slowdown}.\n\n\\begin{mcon}[DTIME lower bound]\n    For each deterministic machine $D$,\n    $\\TC_D(\\SDP fx) \\in \\Omega(m^n)$ for all $f : X^* \\to \\mathbb B$\n    and $x : X^*$\n    where $|X| = m$\n    and $|x| = n$.\n\\end{mcon}\n\n\\begin{mcon}[existence of a certain decider]\nThere exists an alphabet $X$\nand an $X^*$-decider $f$ such that\nfor each list $x : X^*$ of length $n$,\nthe following two statements hold\n\\begin{align}\n    \\TC_D(\\SDP fx) &\\in \\Omega 2^n\n    \\\\\n    \\TC_N(\\SDP fx) &\\in O n\n\\end{align}\nwhere $D$ and $N$ are the deterministic machine\nand the nondeterministic machine from the two previous conjectures.\nIf such $f$ exists, then $\\PTIME \\neq \\NPTIME$.\n\\end{mcon}\n\n\\begin{mcon}\n    If $f = f \\circ g$ for all $f$ then $g = \\id$.\n\\end{mcon}\n\n\\begin{mcon}[existence of a PNP decider]\nSuch decider cannot have overlapping subproblem\nand cannot have optimal substructure.\nThere is no mathematical identity that allows decider to be computed faster.\nIf\n\\begin{align}\n    \\neg\\exists p ~ \\forall x \\in \\{ a | a \\in X^*, p a \\} ~ \\exists y ~ fx = fy\n\\end{align}\nthen $f$ exists.\n\\end{mcon}\n\nProof by contradiction:\nsuppose that for every decider,\nthere exists a mathematical identity that allows it to be computed faster.\n\\begin{align}\n    \\forall f ~ \\exists p ~ \\forall x \\in \\{ a | a \\in X^*, p a \\} ~ \\exists y ~ fx = fy\n\\end{align}\nThen what?\n\n\\section{Machines}\n\n\\begin{mdef}[standard machine]\n    The standard machine with alphabet $X$\n    has the following primitive operation set:\n\n    Every constant of type $X$.\n\n    Every unary operation of type $X \\to X$.\n\n    Every binary operation of type $X \\to X \\to X$.\n\n    Every ternary operation of type $X \\to X \\to X \\to X$.\n    One of these ternary operations is the three-way branch operation:\n    $pctf$ is $t$ iff $c \\neq 0$; $f$ otherwise.\n\n    Function application.\n\n    Function composition.\n\n    Some list operations: $\\fnull : X^* \\to X$,\n    $\\fhead : X^* \\to X$,\n    $\\ftail : X^* \\to X^*$,\n    and $\\fcons : X \\to X^* \\to X^*$.\n\n    A fixed-point combinator $y : \\forall a ~ (\\alpha \\to \\alpha) \\to \\alpha$ satisfying $yf = f(yf)$\n    such that the expression $yf$ reduces to $f(yf)$ in one time unit.\n\\end{mdef}\n\n\\section{Recursion}\n\n\\begin{mlem}\n    The type of the Y-combinator is $\\forall a ~ (\\alpha \\to \\alpha) \\to \\alpha$.\n    \\begin{proof}\n        The definition is $yf = f(yf)$.\n        \\begin{align}\n            f &: \\alpha\n            \\\\\n            r &: \\alpha \\to \\beta\n            \\\\\n            yf &: \\beta\n            \\\\\n            f &: \\beta \\to \\gamma\n            \\\\\n            f(yf) &: \\gamma\n            \\\\\n            yf : \\beta, \\ f(yf) : \\gamma, \\ yf = f(yf) &\\implies \\beta = \\gamma\n            \\\\\n            f : \\alpha, \\ yf : \\beta, \\ f(yf) : \\gamma &\\implies f : \\beta \\to \\gamma, \\ \\alpha = \\beta \\to \\gamma\n        \\end{align}\n    \\end{proof}\n\\end{mlem}\n\nRecursive has to do with fixpoints.\n\n\\section{Nondeterminism}\n\nIn a nondeterministic machine, $\\ambc x y$\nhas the same effect as reducing $x$ and $y$ in parallel in one unit time.\nLet the accepting computation be $z$ where $z$ is either $x$ or $y$.\n\\begin{align}\n    \\TC(\\ambc xy) &= \\TC z\n\\end{align}\n\n\\section{Notation}\n\n$a : A$ or $a \\in A$ means the type of $a$ is $A$,\nor $a$ is in $A$,\nor $a$ is an element of $A$.\n\n$A \\to B$ is the type of every function\nthat takes any $a \\in A$ and returns any $b \\in B$.\n\nConcatenation means function application:\n$fx$ means $f(x)$ in standard mathematical notation.\n$fxy$ means $f(x,y)$ in standard mathematical notation,\nbut the former one is with currying.\n$f0$ can mean $f(0,y)$ which is a function of $y$ only.\n\nIf $f : A\\to B$ and $x:A$, then $fx : B$.\n\nIf $f : A\\to B\\to C$, $x:A$, and $y:B$, then $fxy : C$.\n\n\n\n\n\n\\begin{mcor}[number of deciders]\n    Let $|X| = m$.\n    The number of total mappings of type $X^n \\to \\mathbb B$ is\n    \\begin{align}\n        2^{m^n}\n    \\end{align}\n    The number of total mappings of type $(X^0 \\cup X^1 \\cup \\ldots \\cup X^n) \\to \\mathbb B$ is:\n    \\begin{align}\n        \\sum_{n=0}^{\\infty} 2^{m^n}\n    \\end{align}\n    There are $m^n$ boxes and each box can contain either $\\syes$ or $\\sno$.\n\\end{mcor}\n\n\n\n\n\n\\begin{mdef}[Ambiguous operator]\n    The \\emph{ambiguous operator} $\\amb : A^* \\to A$\n    takes a list and returns an element of that list\n    such that the decider containing the amb-expression is led to $\\syes$.\n\\end{mdef}\n\n    The following is a nondeterministic algorithm:\n    \\begin{align}\n        \\SDP fx &= gfx[] & \\text{where}\n        \\\\\n        gfxy &= \\fite{\\fnull x}{fy}{gf(\\ftail x)(\\amb[y, \\ftail y])}\n    \\end{align}\n\n\n\n\n\n\n\\begin{mlem}[existence of decider bounded below by LIN]\nThere exists a decider that cannot be computed\nin less than linear time\nby the standard machine.\nFormally there exists an $X^*$-decider $f$ such that\nfor each list $x : X^*$ of length $n$,\n$\\TC(fx) \\in \\Theta n$.\n\\begin{proof}\n    Consider the decider that decides whether zero\n    is the modulo-$m$ sum of all elements in the input list of $X$s\n    where $X$ is a finite subset of $\\mathbb N$ of size $m$.\n\n    $f x = [\\sum_{k=0}^{n-1} x_k = 0]$\n\\end{proof}\n\\end{mlem}\n\n    \\begin{align}\n        \\ambc y &= \\fite{\\fnull y}{y}{\\amb[\\fhead y :: \\ambc (\\ftail y), \\ambc (\\ftail y)]}\n    \\end{align}\n\n\\begin{mcon}\nCorollary:\nIf $\\TC_D(\\SDP fx) \\in \\Omega(2^n \\cdot n)$ and $\\TC_N(\\SDP fx) \\in O n$,\nthere exists a problem that is in NP but not in P;\ntherefore $P \\subset NP$.\n\\end{mcon}\n\nProve that the only $g$ that satisfies $fx = f(gx)$ is $\\text{id}$.\n\nTo prove that $\\TC (fx) \\in O(gn)$,\nwrite an algorithm that is in that time complexity class.\n\nTo prove that $\\TC (fx) \\in \\Omega(gn)$, ...\n\n\nFunction Constancy Check Problem/Function Constancy Decider.\n\nGiven an almost constant $X^n$-decider, find the only $x$ that differ.\n\nAn $X$-decider is almost constant iff $f^{-1}\\syes = \\{\\}$.\n\nThis will also prove P neq NP:\nFind $f$ and $g$ such that $\\forall x \\in X^* ~ fx = gx$ but $\\TC_D(fx) \\subset \\TC_N(gx)$\n\n\n\n\n\n\n\n\n\n\\section{Computational complexity}\n\nA set is \\emph{computable} iff there is an algorithm (a finite description)\nfor its indicator function.\n\n\\section{Lax monoidal functors}\n\nA category $C$ is defined by $\\ob C : \\Set\\alpha$ and $\\hom C : \\Set(\\alpha, \\alpha))$ such that\nassociative and preserve identity\n\\begin{enumerate}\n    \\item $(f \\circ g) \\circ h = f \\circ (g \\circ h)$ for all $f,g,h : \\hom C$.\n    \\item $1_C \\circ f = f \\circ 1_C = f$ for all $f : \\hom C$.\n\\end{enumerate}\n\nFunctor is $F$:\n\\begin{enumerate}\n    \\item $f : (A \\to B) \\to (FA \\to FB)$.\n\\end{enumerate}\n\nAlso known as `monad' in Haskell.\n\nA lax monoidal functor $F$ takes a set.\n\\begin{enumerate}\n    \\item Zero element $F_0 : FA$.\n    \\item Lifting morphism $F_1 : A \\to FA$.\n    \\item Internal operation on Kleisli category $f : FA \\to (A \\to FB) \\to FB$.\n\\end{enumerate}\n\n\\section{Monads}\n\nLet there be the following type functions:\n\\begin{align}\n    \\mM A &= \\{ \\mM_0 \\} \\cup \\{ \\mM_1 a ~|~ a \\in A \\}\n \\\\ \\mL A &= \\{ \\mL_0 \\} \\cup \\{ \\mL_1 h t ~|~ h \\in A, ~ t \\in \\mL A \\}\n \\\\ \\mP A &= \\{ \\mP X ~|~ X \\subseteq A \\}\n\\\\ \\mE AB &= \\{ \\mE_0 a ~|~ a \\in A \\} \\cup \\{ \\mE_1 b ~|~ b \\in B \\}\n\\end{align}\nIn Haskell, $\\mM$, $\\mM_0$, and $\\mM_1$ are known as Maybe, Nothing, and Just;\nand $\\mL$, $\\mL_0$, and $\\mL_1$ are known as list type function ([]), the empty list ([]), and the list constructor (:).\n\n\\begin{align}\n    \\sigma_M &: MA \\to (A \\to MB) \\to MB\n\\end{align}\n\nFor \\mM, $\\sigma$ is defined as\n\\begin{align}\n    \\sigma \\mM_0 f &= \\mM_0\n    \\\\ \\sigma (\\mM_1 a) f &= fa\n\\end{align}\n\nFor \\mL, $\\sigma$ is defined as\n\\begin{align}\n    \\sigma \\mL_0 f &= \\mL_0\n    \\\\ \\sigma (\\mL_1 h t) f &= [\\amb (fh \\cdot \\sigma tf)]\n\\end{align}\nwhere $\\amb : \\mL A \\to A$ is McCarthy's ambiguous operator\nand $\\cdot$ is list concatenation.\nThe operator $\\amb$ picks an element leading to accepting path\nin zero time without computing the other elements.\n\nFor \\mP, $\\sigma$ is defined as\n\\begin{align}\n    \\sigma (\\mP S) f &= \\{ \\amb \\{ f x ~|~ x \\in S \\} \\}\n\\end{align}\n\n\\section{\\mM-extended string}\n\n\\begin{align*}\n    x_n' &= \\begin{cases}\n \\mM_1 x_n &: n \\text{ is a valid index into input string}\n  \\\\ \\mM_0 &: \\text{otherwise}\n\\end{cases}\n\\end{align*}\n\n\\section{Definition of computation via expression reduction}\n\nThe grammar for expression:\n\\begin{align}\n    Exp &::= X\n      \\\\ &| -Exp\n      \\\\ &| (Exp)\n      \\\\ &| Exp + Exp\n      \\\\ &| Exp \\cdot Exp\n\\end{align}\n\nA finite countable set $X$.\n\nThere are $n^{n \\cdot n}$ possible binary operations on a set of $n$ elements.\nWe assume using space-time-tradeoff that some of them can be performed in constant time.\n\nA \\emph{primitive expression} is an expression whose time cost is one unit.\nWe assume that these are the \\emph{only} primitive operations:\n\\begin{enumerate}\n    \\item modulo-$m$ arithmetic operations:\n            negation ($-a$),\n            addition ($a + b$),\n            subtraction ($a - b$),\n            and multiplication ($a \\cdot b$).\n    \\item every unary operation in $N_m$ and every binary operation in $N_m$\n    \\item every unary operation in $\\mathbb B = \\{0,1\\}$ and every binary operation in $\\mathbb B$\n    \\item comparison: comparing equality $(=) : X \\to X \\to \\mathbb B$\n        and (unsigned) ordering $(<) : X \\to X \\to \\mathbb B$,\n        and three-way conditional ($Cctf$: if $c$ then $t$ else $f$ where $t,f:\\alpha$ and $c:\\mathbb B$).\n    \\item primitive list operations:\n        \\begin{enumerate}\n            \\item \\fnull: determining whether a list is empty\n            \\item \\fhead: taking the first element (partial function)\n            \\item \\ftail: taking all but the first element (partial function)\n            \\item constructing a list by prepending one element to a list (::)\n        \\end{enumerate}\n\\end{enumerate}\nFor each constant expression $e$, $\\tau e = 0$.\n\nA \\emph{primitive value} is a value whose space cost is one unit.\n\\begin{align}\n    \\forall x \\in X \\quad \\sigma x &= 1\n    \\\\ \\forall x \\in (A,B) \\quad \\sigma x &= \\sigma a + \\sigma b\n     \\\\ \\forall fx \\in \\{L a | a \\in A\\} \\cup \\{R b | b \\in B\\} \\quad \\sigma (fx) &= 1 + \\sigma x\n\\end{align}\nExample:\n\\begin{align}\n    \\sigma[1,2,3] &= \\sigma(1::2::3::[])\n               \\\\ &= \\sigma (L1(L2(L3L_0)))\n               \\\\ &= 1 + \\sigma 1 + \\sigma (L2(L3L_0))\n               \\\\ &= 1 + 1 + 1 + \\sigma 2 + \\sigma (L3L_0)\n               \\\\ &= 3 + 1 + 1 + \\sigma 3 + \\sigma L_0\n               \\\\ &= 5 + 1 + 1\n               \\\\ &= 7\n\\end{align}\n\nFor example, the following $f$ performs modulo-$m$ summation:\n\\begin{align}\n     fx &= C (\\fnull x) 0 (\\fhead x + f(\\ftail x))\n\\end{align}\n\nThe space and time cost for reducing an expression is $\\sigma E$ and $\\tau E$ respectively.\n\n\\section{Definitions}\n\nA \\emph{problem} is a set of its instances.\nAn instance is a pair of question and answer.\nThe question is a string of the input alphabet.\nThe answer is a string of the output alphabet.\nA question may have more than one answer.\nEach question must have at least one answer.\n\nAn \\emph{$\\alpha$-machine} has a \\emph{transition function}\n$t : (S,\\mM X) \\to \\alpha S$\nwhere $S$ is the \\emph{state type},\n$X$ is the \\emph{input alphabet},\nand $\\alpha$ determines the way the machine performs computation.\n$X$ must be finite and countable.\n$S$ must be countable.\n$S$ may contain a special elements:\nthe accepting state \\syes.\nFormally, a \\emph{machine} is a 4-tuple $(\\alpha,X,S,t)$ where\n\\begin{align}\n    X &: \\Fin\n \\\\ S &: \\Set\n \\\\ t &: (S,\\mM X) \\to \\alpha S\n\\end{align}\n\nOnce something is accepted or rejected, it is final:\n\\begin{align}\n    \\forall x \\quad t (\\syes,x) &= \\pi \\syes\n  \\\\ \\forall x \\quad t (\\sno,x) &= \\pi \\sno\n\\end{align}\nwhere $\\pi : S \\to \\alpha S$ is the $\\alpha$-lifting function.\n\nThe transition function must be total\nand it must be an semi-algorithm;\nit must be able to be described\nin a finite number of (what?) elementary operations.\nIt must go into an infinite loop when the answer is no.\n\nA \\emph{path} of that machine for input $x = [x_0,\\ldots] \\in X^*$ is $s = [s_0,\\ldots] \\in S^*$.\nThe computation performed by that machine is a repeated application of the transition function:\n\\begin{align*}\n    s_n &= \\sigma (t (s_{n-1}, x_n'))\n\\end{align*}\nwhere $\\sigma$ is defined according to $\\alpha$\nand $x'$ is \\mM-extended $x$.\nThe initial state is $s_0 \\in S$.\nThe path is an \\emph{accepting path} iff $\\syes$ is in that path.\nThe machine \\emph{accepts} an input iff the path for that input is an accepting path.\n\nThe \\emph{running time} for that input is the length of the corresponding path.\n\nThe \\emph{maximum space usage} is: (maximum or supremum?)\n\\begin{align}\n    \\max_{x \\in s} (\\mu x)\n\\end{align}\n\nDeterministic transition function type is $(S,\\mM X) \\to S$.\nNondeterministic transition function type is $(S,\\mM X) \\to \\mP S$.\n\nNondeterministic machine can \\emph{look into the future}\nto \\emph{guess an accepting path};\ndeterministic machine cannot.\nGiven the same input, a deterministic machine\nwill always go through the same path of computation.\nGiven the same input, a nondeterministic machine\nmight go through another path of computation.\n\n\nWe say that a language is in $\\aTIME f$ iff\nthere exists a constant $k$ and an $\\alpha$-machine\nsuch that the length of the shortest path of that machine\nfor each acceptable input $x$ is in $O(f(\\mu x))$.\n\n\\begin{align}\n    \\DTIME &= \\idTIME\n \\\\ \\NTIME &= \\mPTIME\n\\end{align}\n\n\\section{Example machines}\n\nThis machine accepts all inputs:\n\\begin{align*}\n    S &= \\{ \\syes \\}\n    \\\\ s_0 &= \\syes\n \\\\ t(s,x) &= \\pi s\n\\end{align*}\nThis machine does not accept any input:\n\\begin{align*}\n    S &= \\{ \\sno \\}\n    \\\\ s_0 &= \\sno\n \\\\ t(s,x) &= \\pi s\n\\end{align*}\nThis machine accepts the language $\\{1\\}^*$:\n\\begin{align*}\n    S &= \\{ s_0, \\syes, \\sno \\}\n    \\\\ t(s,x) &= \\text{case $(s,x)$ of} \\begin{cases}\n      (s_0, \\mM_1 1) &\\pi s_0\n        \\\\ (s_0, \\mM_0) &\\pi \\syes\n \\\\ \\text{otherwise} &\\pi \\sno\n\\end{cases}\n\\end{align*}\n\nAssume that $X = \\{0,1\\}$.\n\\begin{enumerate}\n    \\item How many languages can an $\\alpha$-machine with $n$ states accept?\n    \\item How many states are needed for an $\\alpha$-machine to recognize a given language?\n    \\item How many transition functions are possible for a machine with $n$ state?\n\\end{enumerate}\n\n\\section{Languages accepted by a machine}\n\nLet $\\mu X = \\mu Y = 2$.\n\nTypes are measurable:\n\\begin{align}\n    \\mu(A\\to B) &= \\mu A \\cdot \\mu B\n    \\\\ \\mu(A,B) &= \\mu A \\cdot \\mu B\n    \\\\ \\mu(\\mM A) &= 1 + \\mu A\n    \\\\ \\mu(\\mL A) &= 1 + \\mu A \\cdot \\mu(\\mL A)\n    \\\\ \\mu(\\mP A) &= \\mu(2^A) & \\text{if $A$ is countable}\n\\end{align}\nHypernatural measures:\n\\begin{align}\n    \\mu A = \\omega &\\implies \\mu(\\mM A) = \\omega\n    \\\\ \\mu A > 0 &\\implies \\mu(\\mL A) = \\omega\n    \\\\ \\mu A < \\omega &\\implies \\mu(\\mP A) = 2^{\\mu A}\n\\end{align}\n\nHow many transition functions does a \\mM-machine have?\n\nHow many languages can be accepted by \\mM-machine with $\\mu S = 2$?\n\nSuppose that a problem is in NP.\nThen there exists a constant $k$ such that\nthe length of the shortest nondeterministic path\nfor valid input whose size is in $O(n)$ is in $O(n^k)$.\n\nThe time complexity measure of a computation is\nthe length of the path of that computation.\n\nThe set of regular languages is $\\DSPACE(O(n)) \\cap \\DTIME(O(n))$.\n\n\\section{Speedup theorem?}\n\nAlphabet size can be exchanged with state size.\nSpace can be traded for time?\n\n\\section{Example: modulo-$m$ subset-sum problem}\n\n$X = \\{0,1,2,3,\\ldots,m-1\\}$.\n$\\syes$ iff there exists $N \\subseteq \\mathbb N$ such that\n\\begin{align}\n    \\sum_{k \\in N} x_k &= 0\n\\end{align}\nwhere addition is done modulo-$m$.\n\nThe modulo-$m$ subset-sum problem is in $\\NTIME(O(n))$ and is in $\\NSPACE(O(m))$\nwhere $n$ is the length of the input.\n\n\\begin{align}\n    S &= \\{ S_0 \\} \\cup \\{ S_1 n ~|~ n \\in X \\}\n    \\\\ s_0 &= S_0\n\\end{align}\n$t$:\n\\begin{align}\n    (S_1 0, x) &\\to \\{ \\syes \\}\n    \\\\ (S_1 s, \\mM_1 x) &\\to \\{ S_1 s, S_1 (s+x) \\}\n    \\\\ (S_0, \\mM_1 x) &\\to \\{ S_0, S_1 x \\}\n\\end{align}\n\n\\section{Some Haskell code}\n\n\\begin{verbatim}\ntype Tr s x y = (s, Maybe x) -> (Maybe s, Maybe y)\n\nrun :: Tr s x y -> s -> [x] -> [y]\nrun tr state input =\n    let\n        run' s xs =\n            let\n                (mx,xs') = case xs of\n                    [] -> (Nothing, [])\n                    x : t -> (Just x, t)\n                (ms',my) = tr (s,mx)\n                ys = case ms' of\n                    Just s' -> run' s' xs'\n                    Nothing -> []\n            in\n                maybe id (:) my ys\n    in\n        run' state input\n\\end{verbatim}\n\n\\section{Example: 3-SAT in NP}\n\nEncode a boolean expression.\n\n$X = \\{ T, F, A, 0, 1, 2, N, C, D \\}$\n\nThe grammar for the input is \\verb@inp@:\n\\begin{verbatim}\ninp     ::=     asgs A exp\nasgs    ::=     empty | asg asgs\nasg     ::=     T | F\nexp     ::=     0 | 1 | 2\n        |       N exp\n        |       C exp exp\n        |       D exp exp\n\\end{verbatim}\n\n$A$ separates the assignment and the expression.\n\nThe state type is a tuple of three boolean values.\n\nFor example, the expression $v_0 \\wedge v_1 \\vee \\neg v_2$ with truth assignment $(v_0,v_1,v_2) = (T,F,F)$ is encoded as TFFDC01N2.\n\nThere are $n$ variables.\n\nSAT is in NP iff SAT is verifiable in P.\n\nConstant space. Linear time.\n\n\\section{Is there a bijection?}\n\n\\begin{align}\n    \\mathbb N &\\iff 2^\\mathbb N\n    \\\\ 0 &\\iff \\{\\}\n    \\\\ 1 &\\iff \\{0\\}\n    \\\\ 2 &\\iff \\{1\\}\n    \\\\ 3 &\\iff \\{0,1\\}\n    \\\\ 4 &\\iff \\{2\\}\n    \\\\ 5 &\\iff \\{0,2\\}\n    \\\\ 6 &\\iff \\{1,2\\}\n    \\\\ 7 &\\iff \\{0,1,2\\}\n\\end{align}\nwill enumerate all of $2^\\mathbb N$?\n\nBut Cantor's theorem.\n\nWe can construct $x \\in 2^\\mathbb N$ that has no counterpart in the above bijection.\nCounterintuition of infinity.\n\nBinary numbering of $2^\\mathbb N$.\n", "meta": {"hexsha": "10a03cf1b87c51b152d6eb6497281d4f2395b319", "size": 27267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/complexity.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/complexity.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/complexity.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.6942446043, "max_line_length": 131, "alphanum_fraction": 0.6459456486, "num_tokens": 8664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.6959583250334525, "lm_q1q2_score": 0.6217061219278005}}
{"text": "%\\documentclass{book}\n%\\usepackage{amsmath}\n%\\usepackage{bm}\n%\\begin{document}\n\n\\chapter{Map factor}\n\\label{chap: map factor}\n{\\bf \\Large \n\\begin{tabular}{ccc}\n\\hline\n  Corresponding author & : & Seiya Nishizawa\\\\\n\\hline\n\\end{tabular}\n}\n\n\\newcommand{\\pd}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\n\\section{Coordinate transform}\nA orthogonal rectangular coordinate $(x, y, z)$.\nA orthogonal curvilinear coordinate $(\\xi, \\eta, \\zeta)$.\n\n\nThe transform is defined by\n\\begin{align}\n  \\bm{e}_\\xi &= \\pd{x}{\\xi}\\bm{e}_x + \\pd{y}{\\xi}\\bm{e}_y + \\pd{z}{\\xi}\\bm{e}_z, \\\\\n  \\bm{e}_\\eta &= \\pd{x}{\\eta}\\bm{e}_x + \\pd{y}{\\eta}\\bm{e}_y + \\pd{z}{\\eta}\\bm{e}_z, \\\\\n  \\bm{e}_\\zeta &= \\pd{x}{\\zeta}\\bm{e}_x + \\pd{y}{\\zeta}\\bm{e}_y + \\pd{z}{\\zeta}\\bm{e}_z.\n\\end{align}\nReverse transform is\n\\begin{align}\n  \\bm{e}_x &= \\pd{\\xi}{x}\\bm{e}_\\xi + \\pd{\\eta}{x}\\bm{e}_\\eta + \\pd{\\zeta}{x}\\bm{e}_\\zeta, \\\\\n  \\bm{e}_y &= \\pd{\\eta}{y}\\bm{e}_\\xi + \\pd{\\eta}{y}\\bm{e}_\\eta + \\pd{\\zeta}{y}\\bm{e}_\\zeta, \\\\\n  \\bm{e}_z &= \\pd{\\zeta}{z}\\bm{e}_\\xi + \\pd{\\eta}{z}\\bm{e}_\\eta + \\pd{\\zeta}{z}\\bm{e}_\\zeta.\n\\end{align}\n\nThe Jacobian matrix is $\\{\\pd{\\xi^k}{x^i}\\}$.\n\n\nThe reverse transform after the transform of the transform after the reverse transform make a vector to the original vector;\n\\begin{align}\n  \\pd{\\xi^k}{x^i}\\pd{x^i}{\\xi^l} &= \\delta_l^k, \\\\\n  \\pd{x^i}{\\xi^k}\\pd{\\xi^k}{x^j} &= \\delta_j^i,\n\\end{align}\nwhere index which appares upper and lower suffix in a single term implies summation of the term over set ${1,2,3}$ (Einstein notation).\n\n\nSpatial parial derivative is tranformed with the Jacobian matrix (covariant transform);\n\\begin{align}\n  \\pd{}{\\xi^k} &= \\pd{x^i}{\\xi^k}\\pd{}{x^i}, \\\\\n  \\pd{}{x^i} &= \\pd{\\xi^k}{x^i}\\pd{}{\\xi^k}.\n\\end{align}\n\n\nVelocity is transformed with the inverse of the Jacobian matrix (cotravariant transform);\n\\begin{align}\n  d\\xi^k &= \\pd{\\xi^k}{x^i} dx^i, \\\\\n  dx^i &= \\pd{x^i}{\\xi^k} d\\xi^k.\n\\end{align}\n\n\n\nThe metric tensor, $g_{kl}$ is defined by\n\\begin{equation}\n  g_{kl} = \\bm{e}_k \\cdot \\bm{e}_l\n  = \\left(\\pd{x^i}{\\xi_k}\\bm{e}_i\\right) \\cdot \\left(\\pd{x^j}{\\xi_l}\\bm{e}_j\\right)\n  = \\pd{x^i}{\\xi_k}\\pd{x^j}{\\xi_l} (\\bm{e}_i\\cdot\\bm{e}_j).\n\\end{equation}\n\nFor orthogonal curvilinear coordinates, the matrix ${g_{kl}}$ is diagonal.\nMetric factor, $h_k$ is defined as\n\\begin{equation}\n  h_k^2 = g_{kk} = \\sum_i \\left(\\pd{x^i}{\\xi_k}\\right)^2.\n\\end{equation}\n\nHere we define the matrix, $\\bm{E}_\\xi$ is\n\\begin{equation}\n  \\bm{E}_\\xi =\n  (\\bm{e}_\\xi \\bm{e}_\\eta \\bm{e}_\\zeta)\\cdot \\bm{H}^{-1}\n  = \\bm{E}_x \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\} \\cdot \\bm{H}^{-1},\n\\end{equation}\nwhere $\\bm{E}_x = (\\bm{e}_x \\bm{e}_y \\bm{e}_z)$, and\n\\begin{equation}\n  \\bm{H} = \\left(\\begin{array}{ccc} h_1 & 0 & 0\\\\ 0 & h_2 & 0\\\\ 0 & 0 & h_3\\end{array}\\right).\n\\end{equation}\nThe vector $\\frac{1}{h_k}\\bm{e}_k$ is unit vector and orthogonal each other,\nso the inverse of the $\\bm{E}_\\xi$ is $\\bm{E}_\\xi^T$.\n\\begin{align}\n  \\left( \\bm{E}_x \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\} \\cdot \\bm{H}^{-1} \\right)^{-1} &= \\left( \\bm{E}_x \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\} \\cdot \\bm{H}^{-1} \\right)^T, \\nonumber\\\\\n  \\bm{H} \\cdot \\left\\{\\pd{\\xi^k}{x^i}\\right\\} \\cdot \\bm{E}_x^{-1} &= \\bm{H}^{-1} \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\}^T \\cdot \\bm{E}_x^T, \\nonumber\n\\end{align}\n\\begin{align}\n  \\left\\{\\pd{\\xi^k}{x^i}\\right\\} &= \\bm{H}^{-2} \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\}^T \\cdot \\bm{E}_x^T \\cdot \\bm{E}_x \\nonumber \\\\\n  &= \\bm{H}^{-2} \\cdot \\left\\{\\pd{x^i}{\\xi^k}\\right\\}^T.\n\\end{align}\nThat is\n\\begin{equation}\n  \\pd{\\xi^k}{x^i} = \\frac{1}{h_k^2} \\pd{x^i}{\\xi^k}.\n\\end{equation}\n\n\n\\section{Governing equations}\n\n\\subsection{Continuous equiation}\n\nDivergence of $\\rho \\bm{u}$ is\n\\begin{align}\n  \\pd{}{x^i}(\\rho dx^i)\n  &= \\pd{\\xi^k}{x^i}\\pd{}{\\xi^k}\\left(\\rho \\pd{x^i}{\\xi^l}d\\xi^l\\right) \\nonumber \\\\\n  &= \\pd{\\xi^k}{x^i}\\pd{x^i}{\\xi^l}\\pd{}{\\xi^k}(\\rho d\\xi^l)\n    +\\rho d\\xi^l \\pd{\\xi^k}{x^i} \\frac{\\partial^2 x^i}{\\partial \\xi^k \\partial \\xi^l} \\nonumber\\\\\n  &= \\pd{}{\\xi^k} (\\rho d\\xi^k) + \\sum_k\\frac{1}{h_k^2}\\rho d\\xi^l \\pd{x^i}{\\xi^k}\\frac{\\partial^2 x^i}{\\partial \\xi^k \\partial \\xi^l} \\nonumber\\\\\n  &= \\pd{}{\\xi^k} (\\rho d\\xi^k) + \\sum_k \\frac{1}{2h_k^2}\\rho d\\xi^l \\pd{}{\\xi^l}\\left(\\pd{x^i}{\\xi^k}\\right)^2 \\nonumber\\\\\n  &= \\pd{}{\\xi^k} (\\rho d\\xi^k) + \\sum_k \\frac{1}{2h_k^2}\\rho d\\xi^l \\pd{}{\\xi^l}h_k^2 \\nonumber\\\\\n  &= \\pd{}{\\xi^k} (\\rho d\\xi^k) + \\sum_k \\frac{1}{2}\\rho d\\xi^l \\pd{}{\\xi^l}\\ln h_k^2 \\nonumber\\\\\n  &= \\pd{}{\\xi^k} (\\rho d\\xi^k) + \\rho d\\xi^k \\pd{}{\\xi^k}\\ln (\\prod_l h_l) \\nonumber\\\\\n  &= J \\left\\{ J^{-1}\\pd{}{\\xi^k} (\\rho d\\xi^l) + \\rho d\\xi^k \\pd{}{\\xi^k}J^{-1}\\right\\} \\nonumber\\\\\n  &= J \\pd{}{\\xi^k} (J^{-1}\\rho d\\xi^k),\n\\end{align}\nwhere $J$ is the Jacobian of the Jacobian matrix and\n\\begin{equation}\n  J = \\frac{1}{\\prod_k h_k}.\n\\end{equation}\n\nThe continuous equation is\n\\begin{equation}\n\\pd{\\rho}{t} + J \\pd{}{\\xi^k}\\frac{\\rho d\\xi^k}{J} = 0.\n\\end{equation}\n\n\n\n\\subsection{Momentum equation}\n\n\\begin{equation}\n  \\pd{\\rho d\\xi^k}{t} = \\pd{\\xi^k}{x^i} \\pd{\\rho dx^i}{t}.\n\\end{equation}\n\n\\begin{description}\n\n\\item[Advection term]\n\\begin{align}\n  & \\pd{\\xi^k}{x^i}\\pd{\\rho dx^idx^j}{x^j} \\nonumber\\\\\n  &= \\pd{\\xi^k}{x^i}\\left(dx^j\\pd{\\rho dx^i}{x^j} + \\rho dx^i\\pd{dx^j}{x^j}\\right) \\nonumber\\\\\n  &= \\pd{\\xi^k}{x^i}\\left(\\pd{x^j}{\\xi^l}d\\xi^l\\right)\\pd{\\xi^m}{x^j}\\pd{}{\\xi^m}\\left(\\rho \\pd{x^i}{\\xi^n}d\\xi^n\\right)\n  + \\pd{\\xi^k}{x^i}\\rho \\left(\\pd{x^i}{\\xi^l}d\\xi^l\\right)\\pd{\\xi^m}{x^j}\\pd{}{\\xi^m}\\left(\\pd{x^j}{\\xi^n}d\\xi^n\\right) \\nonumber\\\\\n  &= d\\xi^l\\pd{\\xi^k}{x^i}\\pd{}{\\xi^l}\\left(\\rho \\pd{x^i}{\\xi^n}d\\xi^n\\right)\n  + \\rho d\\xi^k\\pd{\\xi^m}{x^j}\\pd{}{\\xi^m}\\left(\\pd{x^j}{\\xi^n}d\\xi^n\\right) \\nonumber\\\\\n  &= d\\xi^l\\pd{\\xi^k}{x^i}\\left\\{\\pd{x^i}{\\xi^n}\\pd{}{\\xi^l}\\left(\\rho d\\xi^n\\right) + \\rho d\\xi^n \\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^n}\\right\\}\n  + \\rho d\\xi^k\\pd{\\xi^m}{x^j} \\left( \\pd{x^j}{\\xi^n}\\pd{d\\xi^n}{\\xi^m} + d\\xi^n\\frac{\\partial^2 x^j}{\\partial \\xi^m \\partial \\xi^n} \\right) \\nonumber\\\\\n  &= d\\xi^l\\pd{}{\\xi^l}\\left(\\rho d\\xi^k\\right) + \\rho d\\xi^l d\\xi^n\\pd{\\xi^k}{x^i} \\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^n}\n  + \\rho d\\xi^k\\pd{d\\xi^m}{\\xi^m} + \\rho d\\xi^kd\\xi^n\\pd{\\xi^m}{x^j}\\frac{\\partial^2 x^j}{\\partial \\xi^m \\partial \\xi^n} \\nonumber\\\\\n  &= \\pd{}{\\xi^l}\\left(\\rho d\\xi^k d\\xi^l\\right) + \\rho d\\xi^l d\\xi^n\\pd{\\xi^k}{x^i} \\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^n}\n   + \\rho d\\xi^kd\\xi^l\\pd{\\xi^m}{x^i}\\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^m} \\nonumber\\\\\n  &= J\\left\\{ J^{-1}\\pd{}{\\xi^l}(\\rho d\\xi^k d\\xi^l) + \\rho d\\xi^k d\\xi^l\\pd{J^{-1}}{\\xi^l} \\right\\}\n   + \\rho d\\xi^ld\\xi^m\\pd{\\xi^k}{x^i}\\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^m} \\nonumber\\\\\n  &= J \\pd{}{\\xi^l}{J^{-1}\\rho d\\xi^k d\\xi^l} + \\rho d\\xi^l d\\xi^m\\Gamma^k_{lm},\n\\end{align}\nwhere $\\Gamma$ is the Christoffel symbols of the second kind, and\n\\begin{align}\n  \\Gamma_{lm}^k\n  &= \\pd{\\xi^k}{x^i} \\frac{\\partial^2 x^i}{\\partial \\xi^l \\partial \\xi^m} \\nonumber\\\\\n  &= \\frac{1}{2}g^{kn}\\left( \\pd{g_{mn}}{\\xi^l} + \\pd{g_{ln}}{\\xi^m} - \\pd{g_{lm}}{\\xi^n}\\right) \\nonumber\\\\\n  &= \\frac{1}{h_k^2}\\left( h_k\\pd{h_k}{\\xi^l}\\delta_{km}+h_k\\pd{h_k}{\\xi^m}\\delta_{kl}-h_l\\pd{h_l}{\\xi^k}\\delta_{lm}\\right),\n\\end{align}\nwhere $\\{g^{kn}\\}$ is inverse matrix of $\\{g_{kn}\\}$.\n\n\n\\item[Coriolis term]\n\\begin{align}\n  \\pd{\\xi^k}{x^i} \\epsilon^{ijp} f^j \\rho dx^p\n  &= \\epsilon^{klm} \\frac{1}{h_kh_lh_m}\\hat{f}^l d\\xi^m,\n\\end{align}\nwhere $\\epsilon$ is the Levi-Civita symbol,\nand\n\\begin{equation}\n  \\hat{f}^l = \\pd{\\xi^l}{x^j} f^j.\n\\end{equation}\n\n\\item[Pressure gradient term]\n\\begin{align}\n  \\pd{\\xi^k}{x^i} \\pd{p}{x^i}\n  &= \\pd{\\xi^k}{x^i}\\left(\\pd{\\xi^l}{x^i}\\pd{p}{\\xi^l}\\right)\\nonumber\\\\\n  &= \\frac{1}{h_k^2}\\pd{x^i}{\\xi^k}\\pd{\\xi^l}{x^i}\\pd{p}{\\xi^l} \\nonumber\\\\\n  &= \\frac{1}{h_k^2}\\pd{p}{\\xi^k}.\n\\end{align}\n\n\\end{description}\n\nAfter all, momentum equation is\n\\begin{align}\n  \\pd{}{t} \\rho d\\xi^k + J\\pd{}{\\xi^l} \\left( J^{-1} \\rho d\\xi^k d\\xi^l \\right)\n  + \\rho d\\xi^l d\\xi^m \\Gamma_{lm}^k\n  + \\epsilon^{klm} \\frac{1}{h_kh_lh_m}\\hat{f}^l \\rho d\\xi^m = -\\frac{1}{h_k^2}\\pd{p}{\\xi^k} + \\rho g^p \\pd{\\xi^k}{x^p}.\n\\end{align}\n\n\n\n\\section{Map factor}\nWe introduce Map factor $m, n$.\n\\begin{align}\n  \\frac{1}{m}\\frac{a+z}{a} &= h_1, \\\\\n  \\frac{1}{n}\\frac{a+z}{a} &= h_2, \\\\\n  1 &= h_3,\n\\end{align}\nwhere is $a$ is radius of the planet.\nAssuming shallow atmospher,\n\\begin{align}\n  m &= h_1, \\\\\n  n &= h_2.\n\\end{align}\n\nNormalized velocity is defined as\n\\begin{align}\n  \\hat{u} &= h_1\\frac{d \\xi}{dt} = \\frac{1}{m}\\frac{d \\xi}{dt}, \\\\\n  \\hat{v} &= h_2\\frac{d \\eta}{dt} = \\frac{1}{n}\\frac{d \\eta}{dt}, \\\\\n  \\hat{w} &= h_3\\frac{d \\zeta}{dt} = \\frac{d \\zeta}{dt}.\n\\end{align}\n\nThe continuous equation becomes\n\\begin{equation}\n  \\pd{\\rho}{t} + mn\\pd{}{\\xi}\\frac{\\rho \\hat{u}}{n} + mn\\pd{}{\\eta}\\frac{\\rho \\hat{v}}{m} + \\pd{}{\\zeta}\\rho \\hat{w} = 0\n\\end{equation}\n\nThe momentum equations are\n\\begin{equation}\n  \\pd{\\rho\\hat{u}^k}{t}\n  + mn\\pd{}{\\xi}\\frac{\\rho \\hat{u} \\hat{u}^k}{n}\n  + mn\\pd{}{\\eta}\\frac{\\rho \\hat{v} \\hat{u}^k}{m}\n  + \\pd{}{\\zeta}\\rho \\hat{w} \\hat{u}^k\n  + m m_k \\rho \\hat{u} \\hat{u}^k \\pd{}{\\xi}\\frac{1}{m_k}\n  + n m_k \\rho \\hat{v} \\hat{u}^k \\pd{}{\\eta}\\frac{1}{m_k}\n  - m m_k \\rho \\hat{u}^2 \\pd{}{\\xi^k}\\frac{1}{m}\n  - n m_k \\rho \\hat{v}^2 \\pd{}{\\xi^k}\\frac{1}{n}\n  + \\epsilon^{klm} m_l \\hat{f}^l \\rho \\hat{u}^m\n  = -m_k \\pd{p}{\\zeta^k} + \\rho g \\delta_{3k}\n\\end{equation}\n\n\\begin{align}\n  \\pd{\\rho u}{t} &+ mn\\pd{}{\\xi}\\frac{\\rho uu}{n} + mn\\pd{}{\\eta}\\frac{\\rho uv}{m} + \\pd{}{\\zeta}\\rho uw \\\\\n  &- f\\rho v - mn \\rho v\\left\\{v\\pd{}{\\xi}\\left(\\frac{1}{n}\\right) - u\\pd{}{\\eta}\\left(\\frac{1}{m}\\right)\\right\\} = -m\\pd{p}{\\xi}, \\\\\n  \\pd{\\rho v}{t} &+ mn\\pd{}{\\xi}\\frac{\\rho uv}{n} + mn\\pd{}{\\eta}\\frac{\\rho vv}{m} + \\pd{}{\\zeta}\\rho vw \\\\\n  &+f\\rho u + mn \\rho u\\left\\{v\\pd{}{\\xi}\\left(\\frac{1}{n}\\right) - u\\pd{}{\\eta}\\left(\\frac{1}{m}\\right)\\right\\} = -n\\pd{p}{\\eta}, \\\\\n  \\pd{\\rho w}{t} &+ mn\\pd{}{\\xi}\\frac{\\rho uw}{n} + mn\\pd{}{\\eta}\\frac{\\rho vw}{m} + \\pd{}{\\zeta}\\rho ww = -\\pd{p}{\\zeta} -\\rho g.\n\\end{align}\n\nThe thermodynamical and tracer equations\n\\begin{equation}\n  \\pd{\\rho \\phi}{t} + mn\\pd{}{\\xi}\\frac{\\rho \\hat{u}\\phi}{n} + mn\\pd{}{\\eta}\\frac{\\rho \\hat{v}\\phi}{m} + \\pd{\\rho \\hat{w}\\phi}{\\zeta} = 0.\n\\end{equation}\n\n\n%\\end{document}\n", "meta": {"hexsha": "17949840f4e53726c5edf9d2cdefe285d6e0653f", "size": 10221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scalelib/doc/descriptions/dynamical_process_mapfactor.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/dynamical_process_mapfactor.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/dynamical_process_mapfactor.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": 40.3992094862, "max_line_length": 182, "alphanum_fraction": 0.5684375306, "num_tokens": 4869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.6893056104028797, "lm_q1q2_score": 0.6216989788357309}}
{"text": "\\documentclass[12pt]{rudin}\n\\usepackage[]{amsmath}\n\\usepackage[]{exercise}\n\\usepackage[]{enumitem}\n\\usepackage[colorlinks=true, linkcolor=blue, urlcolor=blue]{hyperref}\n\n\\newcommand{\\floor}[1]{\\left\\lfloor #1 \\right\\rfloor}\n\n\\renewcommand{\\ExerciseName}{Problem}\n\\renewcommand{\\ExerciseHeader}{\\noindent\\textbf{\\ExerciseName\\ \\ExerciseHeaderNB}\\ \\ExerciseHeaderTitle\\ \\ExerciseHeaderOrigin\\smallskip}\n\\renewcommand{\\ExerciseHeaderOrigin}{(\\ExerciseOrigin)}\n\\renewcommand{\\AnswerHeader}{\\bigskip\\noindent\\textbf{Solution \\ExerciseHeaderNB}\\newline}\n\n\\DeclareMathOperator{\\lcm}{lcm}\n\\let\\set\\mathbf\n\n\\title{Number Theory Midterm I}\n\\author{RDB}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{centering}\n    \\emph{I feel fine today modulo a slight headache. \\\\ \\hfill --- The\n    Hacker's Dictionary}\n\\end{centering}\n\n\\paragraph{INSTRUCTIONS} No outside materials (notes, textbook, internet) or\nresources (calculators). Leave your webcam on until you submit and I confirm\nthat I have your exam.\n\nGood luck!\n\n% 1.\n\\begin{Exercise}\n    Use the Euclidean algorithm to compute the greatest common divisor of 153\n    and 64. (5 points)\n\\end{Exercise}\n\n% 2\n\\begin{Exercise}\n    \\begin{enumerate}[label=(\\textbf{\\alph*})]\n        \\item State Euclid's lemma. (3 points)\n        \\item Show that, if a prime $p$ divides $a^2$ for some integer $a$,\n            then $p$ divides $a$. (5 points)\n    \\end{enumerate}\n\\end{Exercise}\n\n\\begin{Answer}\n    \\begin{enumerate}[label=(\\textbf{\\alph*})]\n        \\item If $p | ab$ for a prime $p$ and integers $a$ and $b$, then $p |\n            ab$.\n        \\item If $p | a^2 = a \\cdot a$, then $p | a$ or $p | a$. So $p | a$,\n            clearly.\n    \\end{enumerate}\n\\end{Answer}\n\n% 3.\n\\begin{Exercise}\n    Find the general solution to\n    \\[\n        42x + 35y = 2,\n    \\]\n    if any solutions exist. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    The gcd of 42 and 35 is 7, which does not divide 2, so there are no\n    solutions.\n\\end{Answer}\n\n% 4\n\\begin{Exercise}\n    List three solutions to the congruence $2x \\equiv 4 \\pmod{101}$. Your\n    solutions may be congruent mod 101. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    An obvious solution is $x = 2$, but there are no others in $\\{0, 1, 2,\n    \\dots, 100\\}$, because $\\gcd(2, 101) = 1$. We can still get other solutions\n    by adding multiples of 101. In particular, $2 + 101 = 103$ and $2 + 202 =\n    204$ are also solutions.\n\\end{Answer}\n\n% 5.\n\\begin{Exercise}\n    Find the general solution to\n    \\[\n        38x + 15y = 1,\n    \\]\n    if any solutions exist. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    The gcd of 38 and 15 is 1, so solutions \\emph{do} exist. The Euclidean\n    algorithm will give $x_0 = 2$ and $y_0 = -5$, so the general solution is\n    \\[\n        x = 2 + 15t; \\qquad y = -5 - 38t\n    \\]\n    for an integer $t$.\n\\end{Answer}\n\n% 6\n\\begin{Exercise}\n    Does the congruence $25 x \\equiv 1 \\pmod{1000}$ have solutions? If so, how\n    many solutions in $\\{0, 1, 2, 3, \\dots, 999\\}$ are there? (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    No, because $\\gcd(25, 1000) = 25$, which does not divide $1$.\n\\end{Answer}\n\n% 7\n\\begin{Exercise}\n    Show that $\\gcd(a, b) = \\gcd(a - b, b)$ for any integers $a$ and $b$. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    If $d$ is a common divisor of $a$ and $b$, say $a = dk$ and $b = dj$, then\n    $a - b = d(k - j)$, so $d$ is a common divisor of $a - b$ and $b$.\n    Conversely, if $d$ is a common divisor of $a - b$ and $b$, then it also\n    divides $a = (a - b) + b$ by the same argument. Therefore the common\n    divisors of $(a, b)$ are the same as the common divisors of $(a - b, b)$,\n    and in particular the \\emph{greatest} one of them is the same.\n\\end{Answer}\n\n% 8\n\\begin{Exercise}\n    Show that $2^n \\equiv -1 \\pmod{3}$ for $n$ odd. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    Note that $2 \\equiv -1 \\pmod{3}$, so $2^n \\equiv (-1)^n | \\pmod{3}$. If $n$\n    is odd $(-1)^n = -1$, so $2^n \\equiv -1 \\pmod{3}$ for odd $n$.\n\n    Nearly everyone used induction, which was fine, but gross. Here's the best\n    induction you could do, I think: If $2^n \\equiv -1 \\pmod{3}$, then\n    \\[\n        3^{n + 2} \\equiv -4 \\pmod{3} \\equiv -1 \\pmod{3}.\n    \\]\n\\end{Answer}\n\n% 9\n\\begin{Exercise}\n    Fix integers $a$ and $b$. Suppose that $ax + by = p$ for some integers $x$\n    and $y$ and a prime $p$. Prove that $\\gcd(a, b)$ is either $1$ or $p$. (10 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    By a theorem in class (or writing $a = \\gcd(a, b)k$ and $b = \\gcd(a, b)j$),\n    we see that $\\gcd(a, b)$ divides $p$, so it is either $1$ or $p$ since $p$\n    is prime.\n\\end{Answer}\n\n% 10\n\\begin{Exercise}\n    Write $76$ in base $3$. (5 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    The largest power to begin with is $3^3 = 27$, and we can fit $2$ of them in:\n    \\[\n        76 - 2 \\cdot 3^3 = 22.\n    \\]\n    Repeating:\n    \\[\n        22 - 2 \\cdot 3^2 = 4\n    \\]\n    Again:\n    \\[\n        4 - 1 \\cdot 3 = 1\n    \\]\n    Finally:\n    \\[\n        1 = 1 \\cdot 3^0.\n    \\]\n    So\n    \\begin{align*}\n        76 &= 2 \\cdot 3^3 + 2 \\cdot 3^2 + 1 \\cdot 3^1 + 1 \\cdot 3^0 \\\\\n           &= (2211)_3.\n    \\end{align*}\n\\end{Answer}\n\n% 11\n\\begin{Exercise}\n    Translate the following numbers from binary into base $10$:\n    \\begin{enumerate}[label=(\\textbf{\\alph*})]\n        \\item $(1)_2$ (1 point)\n        \\item $(11)_2$ (1 point)\n        \\item $(111)_2$ (1 point)\n        \\item $(1111)_2$ (1 point)\n        \\item Prove, by induction, that\n        \\[\n            (\\underbrace{11\\cdots 1}_{n})_2 = 2^n - 1\n        \\]\n        for all positive integers $n$. (5 points)\n    \\end{enumerate}\n\\end{Exercise}\n\n% 12\n\\begin{Exercise}\n    Write $(1024)_5$ in base 10. (5 points)\n\\end{Exercise}\n\n\\begin{Answer}\n    \\begin{align*}\n        (1024)_5 &= 1 \\cdot 5^3 + 0 \\cdot 5^2 + 2 \\cdot 5^1 + 4 \\cdot 5^0 \\\\\n                 &= 125 + 10 + 4 \\\\\n                 &= 139.\n    \\end{align*}\n\\end{Answer}\n\n\\paragraph{BONUS PROBLEM} The exam is graded out of 102 points, all accounted\nfor in the previous problems. The following problem is worth an additional 10\npoints.\n\n\\begin{Exercise}\n    \\begin{enumerate}[label=(\\textbf{\\alph*})]\n        \\item Find the general solution to the diophantine equation\n            \\begin{equation*}\n                10x + 11y = 200.\n            \\end{equation*}\n            (2 points)\n\n        \\item Show that there exists only a single solution with $x$ and $y$\n            both positive. (5 points)\n\n        \\item Find that positive solution. (3 points)\n    \\end{enumerate}\n\\end{Exercise}\n\n\\end{document}\n", "meta": {"hexsha": "0fde97918bc57b5f64dfad4db4f7c86db649ae2d", "size": 6540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/2021/summer/nt/exams/1.tex", "max_stars_repo_name": "rwbogl/rwbogl.github.io", "max_stars_repo_head_hexsha": "4bfba4b851a17652b2a9a1b25ab84f77cb41f7ea", "max_stars_repo_licenses": ["MIT"], "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/2021/summer/nt/exams/1.tex", "max_issues_repo_name": "rwbogl/rwbogl.github.io", "max_issues_repo_head_hexsha": "4bfba4b851a17652b2a9a1b25ab84f77cb41f7ea", "max_issues_repo_licenses": ["MIT"], "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/2021/summer/nt/exams/1.tex", "max_forks_repo_name": "rwbogl/rwbogl.github.io", "max_forks_repo_head_hexsha": "4bfba4b851a17652b2a9a1b25ab84f77cb41f7ea", "max_forks_repo_licenses": ["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.829787234, "max_line_length": 137, "alphanum_fraction": 0.6012232416, "num_tokens": 2220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6216976608059768}}
{"text": "\\section{Technical Approach}\n\n\\subsection{Theoretical Background}\n\nThe full derivation of the micromorphic constitutive equations is very detailed with full derivations being presented in Regueiro~\\cite{bib:regueiro_micro10} and the theory manual for the code~\\cite{bib:miller17}. Briefly, the equations of motion which must be solved are the balance of linear momentum\n\n\\begin{equation}\n\\sigma_{ji,j} + \\rho \\left(f_i - a_i\\right) = 0\\\\\n\\end{equation}\n\nand the balance of the, ``first moment of momentum''\n\n\\begin{equation}\n\\sigma_{ij} - s_{ij} + m_{kji,k} + \\rho \\left(l_{ji} - \\omega_{ji}\\right) = 0\\\\\n\\end{equation}\n\nwhere the $\\left(\\cdot\\right)_{,j}$ indicates the derivative with respect to $x$ in the current coordinate system. We note that the terms in the balance equations are volume and area averages of quantities defined in the micro scale (indicated by $\\left(\\cdot\\right)'$) via\n\\begin{align*}\n\\rho dv &\\defeq \\int_{dv} \\rho' dv'\\\\\n\\sigma_{ji}n_j da &\\defeq \\int_{da} \\sigma_{ji}'n_j'da'\\\\\n\\rho f_i dv &\\defeq \\int_{dv} \\rho' f_i' dv'\\\\\n\\rho a_i dv &\\defeq \\int_{dv} \\rho' a_i' dv'\\\\\ns_{ij} dv &\\defeq \\int_{dv} \\sigma_{ij}' dv'\\\\\nm_{ijm} n_i da &\\defeq \\int_{da} \\sigma_{ij}' \\xi_m n_i' da'\\\\\n\\rho l_{ij} dv &\\defeq \\int_{dv} \\rho' f_i' \\xi_j dv'\\\\\n\\rho \\omega_{ij} dv &\\defeq \\int_{dv} \\rho' \\ddot{\\xi}_i \\xi_j dv'\\\\\n\\end{align*}\n\nThe most striking of the results of these equations is that the Cauchy stress is no longer symmetric. This arises because while we assert that classical continuum mechanics are obeyed at the micro-scale, at the macro scale we must handle moments applied pointwise due to the higher order stress $m_{ijk}$. This couple, along with the micro body couple and micro-spin, results in a generally asymmetric nature.\n\nConceptually, we can understand the balance of first moment of momentum in the absence of body couples and micro-spin as the statement that the total stress of the body is the volume average of all the micro stresses ($s_{ij}$) added to the couple produced by the micro stresses acting on the lever arm $\\xi_i$. The body couple results from a heterogeneous distribution of the body force per unit density and the micro-spin inertia results from the acceleration of the micro position vectors.\n\nWe define a mapping between the current and reference configurations for the position of $dv$ and $dv'$ as\n\\begin{align*}\nF_{iI} &\\defeq \\frac{\\partial x_i}{\\partial X_I}\\\\\n\\xi_i  &\\defeq \\chi_{iI}\\Xi_I = \\left(\\delta_{iI}+\\phi_{iI}\\right)\\Xi_I\\\\\n\\end{align*}\n\nwhere we note the difference that $F_{iI}$ maps $dX_I$ into $dx_i$ through the differential relationship whereas $\\chi_{iI}$ is purely a linear map between the configurations and is not defined through the differential elements.\n\n\\subsection{Algorithms}\n\nThe equations of motion will be solved using the finite element method in a so-called, ``Total Lagrangian,'' configuration. We do this by mapping the stresses back to the reference configuration (for details see Regueiro~\\cite{bib:regueiro_micro10} or the theory manual~\\cite{bib:miller17}) to find the balance of linear momentum for a single element $e$\n\n\\begin{align*}\n\\sum_{n=1}^{N^{nodes,e}} c^{n,e}_j \\bigg\\{&\\int_{\\partial \\hat{\\mathcal{B}}^{0,t,e}} \\hat{N}^{n,e} F_{jJ} S_{IJ} \\hat{J} \\left(\\frac{\\partial X_{I}}{\\partial \\xi_{\\hat{i}}}\\right)^{-1} \\hat{N}_{\\hat{i}} d\\hat{A}& + \\int_{\\hat{\\mathcal{B}}^{0,e}} \\big\\{- \\hat{N}^{n,e}_{,I} S_{IJ} F_{jJ} + \\hat{N}^{n,e} \\rho^0 \\left(f_j - a_j\\right) \\big\\} \\hat{J} d\\hat{V} = \\mathcal{F}_j^{n,e}\\bigg\\}\\\\\n\\end{align*}\n\nwhere we have transformed the equations into the element basis $e_\\xi$ (indicated by $\\hat{\\left(\\cdot\\right)}$), $N$ is the shape function, $S_{IJ}$ is the second Piola Kirchhoff stress, and $\\mathcal{F}_j^{n,e}$ is the residual. Note that this $\\xi$ is not the same as the micro-position vector detailed above.\n\nWe also write the balance of the first moment of momentum as\n\\begin{align*}\n\\sum_{n=1}^{N^{nodes,e}} \\eta_{ij}^{n,e} &\\bigg\\{\\int_{\\mathcal{B}^{0,e}}  \\bigg\\{\\hat{N}^{n,e} \\left(F_{iI} \\left(S_{IJ}-\\Sigma_{IJ}\\right) F_{jJ} + \\rho^0\\left(l_{ji} - \\omega_{ji} \\right)\\right)  - \\frac{\\partial \\hat{N}^{n,e}}{\\partial \\xi_{\\hat{i}}} \\left(\\frac{\\partial X_{K}}{\\partial \\xi_{\\hat{i}}}\\right)^{-1} F_{jJ} \\chi_{iI}  M_{KJI} \\bigg\\} \\hat{J} d\\hat{V}\\\\\n& + \\int_{\\partial \\mathcal{B}^{0,t,e}} F_{jJ} \\chi_{iI}  M_{KJI} \\hat{N}^n \\hat{J} \\left(\\frac{\\partial X_{K}}{\\partial \\xi_{\\hat{i}}}\\right)^{-1} \\hat{N}_{\\hat{i}} d\\hat{A} = \\mathcal{M}_{ij}^{n,e} \\bigg\\}\\\\\n\\end{align*}\n\nWe will organize these residuals into the residual vector using the following approach for a linear 8 noded hex element\n\\begin{align*}\n\\mathcal{R}^e &= \\left\\{\\begin{array}{c}\n\\mathcal{F}_j^{1,e}\\\\\n\\mathcal{M}_j^{1,e}\\\\\n\\mathcal{F}_j^{2,e}\\\\\n\\mathcal{M}_j^{2,e}\\\\\n\\vdots\\\\\n\\mathcal{F}_j^{8,e}\\\\\n\\mathcal{M}_j^{8,e}\\\\\n\\end{array}\\right\\}\n\\end{align*}\n\nwhere\n\\begin{align*}\n\\mathcal{M}_J^{n,e} = \\left\\{\\begin{array}{c}\n\\mathcal{M}_{11}^{n,e}\\\\\n\\mathcal{M}_{22}^{n,e}\\\\\n\\mathcal{M}_{33}^{n,e}\\\\\n\\mathcal{M}_{23}^{n,e}\\\\\n\\mathcal{M}_{13}^{n,e}\\\\\n\\mathcal{M}_{12}^{n,e}\\\\\n\\mathcal{M}_{32}^{n,e}\\\\\n\\mathcal{M}_{31}^{n,e}\\\\\n\\mathcal{M}_{21}^{n,e}\n\\end{array}\\right\\}\n\\end{align*}\n\nWe solve the nonlinear equations using Newton Raphson which means we require the Jacobian. We write the element tangent as\n\\begin{align*}\n\\mathcal{J}_{IJ}^e  = \\frac{\\partial \\mathcal{R}_I}{\\partial \\mathcal{U}_J} &= -\\left[\\begin{array}{cccccc}\n\\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial u_1^{1,e}} & \\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial u_2^{1,e}} & \\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial u_3^{1,e}} & \\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial \\phi_{11}^{1,e}} & \\cdots & \\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial \\phi_{21}^{8,e}}\\\\\n\\frac{\\partial \\mathcal{F}_{2}^{1,e}}{\\partial u_1^{1,e}} & \\frac{\\partial \\mathcal{F}_{2}^{1,e}}{\\partial u_2^{1,e}} & \\frac{\\partial \\mathcal{F}_{2}^{1,e}}{\\partial u_3^{1,e}} & \\frac{\\partial \\mathcal{F}_{2}^{1,e}}{\\partial \\phi_{11}^{1,e}} & \\cdots & \\frac{\\partial \\mathcal{F}_{1}^{1,e}}{\\partial \\phi_{21}^{8,e}}\\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots\\\\\n\\frac{\\partial \\mathcal{M}_{2}^{8,e}}{\\partial u_1^{1,e}} & \\frac{\\partial \\mathcal{M}_{2}^{8,e}}{\\partial u_2^{1,e}} & \\frac{\\partial \\mathcal{M}_{2}^{8,e}}{\\partial u_3^{1,e}} & \\frac{\\partial \\mathcal{M}_{2}^{8,e}}{\\partial \\phi_{11}^{1,e}} & \\cdots & \\frac{\\partial \\mathcal{M}_{1}^{8,e}}{\\partial \\phi_{21}^{8,e}}\\\\\n\\end{array}\\right]\n\\end{align*}\n\nwhere the superscript numbers indicate the node number. This is a $96 \\times 96$ matrix. We then assemble the individual Jacobian and residual for an element to form the global Jacobian and residual.\n\nWe write the linearized form of the residual as\n\n\\begin{equation}\n\\mathcal{R}_I^{n+1,k+1} \\approx \\mathcal{R}_I^{n,k} + \\frac{\\partial \\mathcal{R}_I}{\\partial \\mathcal{U}_J} \\Delta \\mathcal{U}_J\n\\end{equation}\n\nwhere $n$ is the current pseudo-timestep and $k$ is the iteration number.\n\nWe desire the residual at the next iteration to be zero so we write\n\\begin{equation}\n\\begin{aligned}\n0 &= \\mathcal{R}_I^k + \\frac{\\partial \\mathcal{R}_I}{\\partial \\mathcal{U}_J} \\Delta \\mathcal{U}_J\\\\\n\\Rightarrow\\ -\\frac{\\partial \\mathcal{R}_I}{\\partial \\mathcal{U}_J} \\Delta \\mathcal{U}_J &= \\mathcal{R}_I^k\\\\\n\\end{aligned}\n\\end{equation}\n\nwhere $\\Delta \\hat{t}$ is an increment in pseudo-time and $k$ indicates the sub-iteration. We now introduce\n\\begin{align*}\n\\Delta \\mathcal{U}_J &= \\Delta \\hat{t} \\dot{\\mathcal{U}}_J\\\\\n\\dot{\\mathcal{U}}_J &= \\alpha \\dot{\\mathcal{U}}_J^{k+1} + \\left(1-\\alpha\\right) \\dot{\\mathcal{U}}_J^{k}\n\\end{align*}\n\n$\\alpha = 0$ indicates an explicit method and $\\alpha = 1$ indicates an implicit method. Once a good initial condition has been established, Newton-Raphson iteration is performed to compute the proper value of $\\dot{\\mathcal{U}}_J^{k+1}$. Iterations will continue until the convergence of the residual vector is achieved.\n\nWe note that boundary conditions are enforced by either removing the relevant rows and columns in the residual and Jacobian in the case of a zero boundary condition or by first computing the resultant force, subtracting it from the residual, and then removing the rows and columns in the case of a non-zero boundary condition.\n\nThe matrix equation will be solved, at least initially, by using the Newton-Krylov solver contained in the C++ repository. This solver does not use the tangent but rather uses the residual to compute the required steps in the solution. Further efforts should involve implementing the code in a Newton-Raphson solver so that the tangent can be tested as well.\n\n\\FloatBarrier\n", "meta": {"hexsha": "8d00086989664604946cf8046db5a18cf2f02629", "size": 8655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Report/tex/technical_approach.tex", "max_stars_repo_name": "lanl/tardigrade-micromorphic-element", "max_stars_repo_head_hexsha": "dafc66df8a308e9fef8af4907de902464b84302b", "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/Report/tex/technical_approach.tex", "max_issues_repo_name": "lanl/tardigrade-micromorphic-element", "max_issues_repo_head_hexsha": "dafc66df8a308e9fef8af4907de902464b84302b", "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/Report/tex/technical_approach.tex", "max_forks_repo_name": "lanl/tardigrade-micromorphic-element", "max_forks_repo_head_hexsha": "dafc66df8a308e9fef8af4907de902464b84302b", "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": 68.6904761905, "max_line_length": 492, "alphanum_fraction": 0.6942807626, "num_tokens": 2937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6216533924078165}}
{"text": "\\section{The baseline model}\n\nThe utility function is defined as:\n\\[ u(c_{h,t},l_{h,t}) = \\frac{M^{1-\\gamma}_{h,t}}{1 - \\gamma} \\exp{( \\pi z_{h,t} + \\zeta_{h,t} )} .\\]\nThe preference aggregator (why aggregator) for hours of leisure and consumption is\n\\[ M_{h,t}(c_{h,t},l_{h,t};z_{h,t},\\chi_{h,t}) = \\left( \\frac{(c_{h,t}^{1 - \\phi} - 1)}{1 - \\phi} + (\\alpha_{h,t}(z_{h,t},\\chi_{h,t})) \\frac{(l_{h,t}^{1 - \\theta} -1)}{ 1 - \\theta}\\right) \\]\n$\\alpha_{h,t}= \\exp{(\\psi_0 + \\psi_z z_{h,t} + \\chi_{h,t})}$\n\nSuppose for now there is no random discrete choice, the inter-temporal budget constraint:\n\\[ A_{h,t+1} = (1 + r_{t+1}) \\left( A_{h,t} + (w_{h,t}^f(H-l_{h,t}) + y_{h,t}^m - c_{h,t} \\right)\\]\n$A_{h,t}$ is the beginning asset holding, $r_t$ is the risk-free interest rate, $F$ is the fixed cost of work, dependent on the age of the youngest child, $a_{h,t}$. Female wages are given by $w_{h,t}^f$ and husband earning $y_{h,t}^m$.\n\nThe maximization is done with respect to the following payoffs:\n\\[\\begin{split} \\max_{c_t,l_t} & u(c_t,l_t) + \\beta V(A_{t+1}) \\\\\n\\text{subject to } & A_{t+1} = (1 + r_{t+1}) \\left( A_{t} + w_{h,t}^f(H-l_{t}) + y_{h,t}^m - c_{t} \\right)\n\\end{split}\\]\nThe first order condition with respect to $c_t, l_t and A_t$ are \\[ \\begin{split}\n  u_c(c_t,l_t) + \\beta (1+r_{t+1}) V'(A_{t+1}) = 0 \\\\\n  u_l(c_t,l_t) + \\beta w_{h,t} (1+r_{t+1}) V'(A_{t+1}) = 0 \\\\\n  V'(A_t) = \\beta (1+r_{t+1}) V'(A_{t+1}) \\\\\n\\end{split} \\]\nFrom the model we can have two conditions\n\\[ \\begin{split}\n  \\textbf{MRS condition:}& \\quad w_{ht} u_{c,ht} = l_{c,ht}\\\\\n  \\textbf{Euler Equation:}& \\quad u_{c,ht} = \\beta u_{c,ht+1}, \\quad \\text{in addition:}\\quad u_{l,ht} = u_{l,ht+1} \\frac{w_{h,t}}{w_{h,t+1}}\n\\end{split} \\]\n\n\\textbf{The regression from MRS}\nTherefore from the MRS condition, we have that\n\\[\\begin{split}\n   w_{h,t}c_{h,t}^{-\\phi} &= \\alpha_{h,t}(z_{h,t},\\chi_{h,t})) l_{h,t}^{-\\theta}  \\\\\n   \\log(w_{h,t})& + \\phi \\log(c_{h,t})  = \\psi_0 + \\psi_1 z_{h,t} + \\xi_{h,t} - \\theta \\log(l_{h,t})\n\\end{split} \\]\n\\textbf{The parameters can be identified from MRS:}\n\\begin{itemize}\n  \\item We observe the wages, consumptions, leisure time and the exogenous variables: $\\{w,c,l,z\\}$\n  \\item From the reduced form regression, we have the preference shocks identified ($\\psi_0,\\psi_1$) with the assumption that $\\xi_{h,t}$ is normal.\n  \\item We also identify the structural preference parameter $\\phi$ and $\\theta$.\n  \\item After we obtain $\\hat{\\phi},\\hat{\\theta},\\hat{\\psi}_0,\\hat{\\psi}_1$ we cam back out $\\hat{M}(c_{h,t},l_{h,t})$\n  \\item[Question:] {\\color{red} Then $\\log M(c_{h,t}, l_{h,t}) - \\log \\hat{M}(c_{h,t},l_{h,t})$ follows the assumed distribution of $\\xi_{h,t}$? Is there potential endogeneity problem? ($\\xi$ correlated with wage? other explainatory variables?)}\n\\end{itemize}\n\\textbf{The Euler equation and what can be identified from it?}\nThe Euler equation condition is that\n\\[ \\begin{split}\n  & \\exp{( \\pi z_{h,t} + \\zeta_{h,t} )} M(c_{h,t},l_{h,t})^{-\\gamma} c_{h,t}^{-\\phi} \\\\\n  & = \\beta (1+r_{t+1}) \\exp{( \\pi z_{h,t+1} + \\zeta_{h,t+1} )} M(c_{h,t+1},l_{h,t+1})^{-\\gamma} c_{h,t+1}^{-\\phi} \\\\\n  M(c_{h,t},l_{h,t}) & = \\left( \\frac{(c_{h,t}^{1 - \\phi} - 1)}{1 - \\phi} + (\\alpha_{h,t}(z_{h,t},\\chi_{h,t})) \\frac{(l_{h,t}^{1 - \\theta} -1)}{ 1 - \\theta}\\right)\n\\end{split} \\]\nLog-linearize and plug in the estimated utility to have that\n\\[ \\begin{split}\n  \\pi z_{h,t} & + \\zeta_{h,t} - \\phi c_{h,t} - \\gamma \\log(\\hat{M}(c_{h,t},l_{h,t})) \\\\ & = \\log(\\beta) + \\log(1+r_{t+1}) + \\pi z_{h,t+1} + \\zeta_{h,t+1} - \\gamma \\log(\\hat{M}(c_{h,t+1},l_{h,t+1})) - \\phi c_{h,t+1} \\\\\n  \\text{Then we have}& \\quad  \\pi \\Delta z_{h,t} + \\Delta \\zeta_{h,t} - \\hat{\\phi} \\Delta c_{h,t} - \\gamma \\Delta \\log \\hat{M}(c_{h,t},l_{h,t}) + \\beta + \\log(1+r_t)= 0\n\\end{split} \\]\nWhat parameters we can estimate from the Euler equation\n\\begin{itemize}\n  \\item It feels wierd that no transition of $z_{h,t}$ is assumed? But may be we don't need this assumption.\n  \\item We can estimate the parameters $\\pi,\\gamma,\\beta$ from the data?\n  \\item {\\color{red} The $r_{t}$ is observed? The paper uses group aggregate labour supply or taxation as an IV for this step's identification}\n  \\item [Comment:] not sure what harm this would bring to estimation...But is this neccesary if we want to aggregate the $M_{h,t}$?\n  \\item [Question:] Page 16 of paper \\cite{Attanasio2015AggregatingSupply}, lower part $M_{h,t}$ is non-linear function and unobserved parameters, so cannot be aggregated??\n\\end{itemize}\n\n\\section{Section with discrete choice}\nThe additional parameters are $\\xi$ and $F(a_{h,t})$ where $F(a_{h,t})$\nIf there is a discrete choice to participate in labour market, then the utility function is defined as:\n\\[ u(c_{h,t},l_{h,t},P_{h,t}) = \\frac{M^{1-\\gamma}_{h,t}}{1 - \\gamma} \\exp{(\\xi P_{h,t} + \\pi z_{h,t} + \\zeta_{h,t} )} .\\]\n\\[ M_{h,t}(c_{h,t},l_{h,t};z_{h,t},\\chi_{h,t}) = \\left( \\frac{(c_{h,t}^{1 - \\phi} - 1)}{1 - \\phi} + (\\alpha_{h,t}(z_{h,t},\\chi_{h,t})) \\frac{(l_{h,t}^{1 - \\theta} -1)}{ 1 - \\theta}\\right) \\]\n$\\alpha_{h,t}= \\exp{(\\psi_0 + \\psi_z z_{h,t} + \\chi_{h,t})}$\nThe intertemporal budget constraint is defined as:\n\\[ A_{h,t+1} = (1 + r_{t+1}) \\left( A_{h,t} + \\left(w_{h,t}^f(H-l_{h,t}) - F(a_{h,t}) \\right)P_{h,t} + y_{h,t}^m - c_{h,t} \\right)\\]\n\\textbf{The parameters that we can get from MRS and Euler Equation}\n\\begin{itemize}\n  \\item Similarly, estimate the parameters within $M(c_{h,t},l_{h,t})$ function and obtain $\\hat{M}(c_{h,t},l_{h,t})$.\n  \\item The Euler equation is slightly different: \\[ \\xi \\Delta P_{h,t}  \\pi \\Delta z_{h,t} + \\Delta \\zeta_{h,t} - \\hat{\\phi} \\Delta c_{h,t} - \\gamma \\Delta \\log \\hat{M}(c_{h,t},l_{h,t}) + \\beta + \\log(1+r_t)= 0\\]\n  \\item $\\xi$ is the entry cost?\n\\end{itemize}\n\\tbf{Random shocks: what's confusing to me.}\n\\begin{itemize}\n  \\item No entry cost of labour market.\n  \\item The shock $\\zeta$ induce increase of current period consumption/labour.\n  \\item Are $\\zeta$ and $\\chi$ correlated?\n\\end{itemize}\n\n\\section{My estimation strategy?}\nI would propose a 3-step estimation strategy.\n\n\\textbf{In the first step}, in addition to estimating $MRS$, I will need to estimate the transition of $z_{it}$ as well.(So that the agents have a prior about the future events.)\nFrom the first step, we obtain the estimator of $\\log \\hat{M}(c,h)$, and we also have the estimator of $w_{h,t}$. Non-parametrically estimate $c^*(\\cdot),l^*(\\cdot)$ as functions of $z_{h,t}$.\n\n\\textbf{The estimator:}\n\\begin{itemize}\n  \\item $c^{*}(z,w,y,A),l^{*}(z,w,y,A)$ with Nadaya-Watson estimator.\n  \\item $p(z,w,y,A) = Pr(P=1|z,w,y,z)$ with non-parametric estimate.\n  \\item $f(w'|w,P)$, $f(w'|w)$ estimator: can test whether the wage grows with participation decision(but may be correlated with unobserved variables, not sure what to do with it yet...HELP).\n\\end{itemize}\n\n\n\\textbf{In the second step}, estimate the entry decision of the labour market.\nThe agent will choose $P_{h,t}=1$ when $E_{\\zeta_{h,t},\\xi_{h,t}} v(1,c^*(\\cdot),l^*(\\cdot),z_{h,t},(\\zeta_{h,t},\\xi_{h,t})) > E_{\\zeta_{h,t},\\xi_{h,t}} v(0,c^*(\\cdot),l^*(\\cdot),z_{h,t},(\\zeta_{h,t},\\xi_{h,t}))$\nAssume that $v(\\cdot)$ is the continuation value associated with the parameters.\n\n\\textbf{In the third step}, estimate the forward looking continuous choice.\nIt follows that $c^*(),l^*()$ are the optimal rule.\n", "meta": {"hexsha": "cd2496e349af697690d39391e3800d8036a5f214", "size": 7316, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Labour Lit Review/sandbox.tex", "max_stars_repo_name": "JasmineHao/DCDC.jl", "max_stars_repo_head_hexsha": "32732f3a65029294a2dc5c14f241b0e3642ed894", "max_stars_repo_licenses": ["MIT"], "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/Labour Lit Review/sandbox.tex", "max_issues_repo_name": "JasmineHao/DCDC.jl", "max_issues_repo_head_hexsha": "32732f3a65029294a2dc5c14f241b0e3642ed894", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-11-26T22:17:43.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-26T22:17:43.000Z", "max_forks_repo_path": "doc/Labour Lit Review/sandbox.tex", "max_forks_repo_name": "JasmineHao/DCDC.jl", "max_forks_repo_head_hexsha": "32732f3a65029294a2dc5c14f241b0e3642ed894", "max_forks_repo_licenses": ["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.3461538462, "max_line_length": 245, "alphanum_fraction": 0.6323127392, "num_tokens": 2754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6215795311897556}}
{"text": "\\chapter{The Collatz Tree}\n\n\\section{The Connection between Groups and Graphs}\n\\label{sec:groups_graphs}\nLet $(a_k)$ be a numerical sequence with $a_k=g^{(k)}(m)$, then a reversion produces an infinite number of sequences of reversely-written Collatz members \\cite{Ref_Klisse_2010}.\n\n\\par\\medskip\nLet $S$ be a set containing two elements $q$ and $r$, which are bijective \nfunctions over $\\mathbb{Q}$:\n\\begin{equation}\n\\begin{array}{l}\nq(x)=2x \\\\ \nr(x)=\\frac{1}{3}(x-1)\n\\end{array}\n\\end{equation}\n\nLet a binary operation be the right-to-left composition of functions\n$q\\circ r$, where $q\\circ r(x)=q(r(x))$. Composing functions is an\nassociative operation. All compositions of the bijections $q$ and $r$\nand their inverses $q^{-1}$ and $r^{-1}$ are again bijective. The set,\nwhose elements are all these compositions, is closed under that operation.\nIt forms a free group $F$ of rank 2 with respect to the free generating set $S$, where the group's binary operation $\\circ$ is the function composition and the group's identity element is the identity function $id_{\\mathbb{Q}}=e$. We call $e$ an \\textit{empty string}. $F$ consists of all expressions (strings) that can be concatenated from the generators $q$ and $r$. The corresponding Cayley graph $Cay(F,S)=G$ is a regular tree whose vertices have four neighbors \\cite[p.~66]{Ref_Loeh}. A tree is called \\textit{regular} or \\textit{homogeneous} when every vertex has the same degree, in this case, $d(v)=4$ for every vertex $v$ in $G$. The Cayley graph's set of vertices is $V(G)=F$, and its set of edges is $E(G)=\\left\\{\\left\\{f,f\\circ s\\right\\}\\mid f\\in F,s\\in\\left(S\\cup S^{-1}\\right)\\setminus\\left\\{e\\right\\}\\right\\}$ \\cite[p.~57]{Ref_Loeh}. More precisely, the vertices are \\textit{labeled} by the elements (strings) of $F$.\n\n\\par\\medskip\nIn conformance with graph-theoretical precepts \\cite{Ref_Bondy_Murty},\n\\cite{Ref_Bonnington_Little}, \\cite{Ref_Bender_Williamson}\nwe specify a subgraph $H$ of $G$ as a triple\n$\\left(V(H),E(H),\\psi_{H}\\right)$ consisting of a set $V(H)$ of vertices,\na set $E(H)$ of edges, and an incidence function $\\psi_{H}$. The latter\nis, in our case, the restriction $\\psi_{G}\\vert_{E(H)}$ of the Cayley\ngraph's incidence function to the set of edges that only join vertices,\nwhich are labeled by a string over alphabet $\\{r,q\\}$ without the inverses:\n$E(H)=\\left\\{\\left\\{f,f\\circ s\\right\\}\\mid f\\in F,s\\in S\\setminus\\left\\{e\n\\right\\}\\right\\}$.\n\n\\par\\medskip\nThis subgraph corresponds to the monoid $S^*$, which is freely generated\nby $S$ follows related thoughts \\cite{Ref_Truemper_2014} that examine\nthe Collatz problem in terms of a free semigroup on the set $S^{-1}$ of\ninverse generators. Note that this semigroup is not to be confused with an\n\\textit{inverse semigroup} \"in which every element has a unique inverse\"\n\\cite[p.~26]{Ref_Almeida}, \\cite[p.~22]{Ref_Loeh}.\n\n\\par\\medskip\nLet $Y^X=\\{f\\mid f\\text{ is a map }X\\rightarrow Y\\}$ be the set of functions, which in category theory is referred to as the \\textit{exponential object} for any sets $X$, $Y$. The evaluation function $ev:Y^X\\times X\\to Y$ sends the pair $(f,x)$ to $f(x)$. For a detailed description of this concept, see \\cite[p.~127]{Ref_Johnsonbaugh}, \\cite[p.~155]{Ref_MacLane_Birkhoff}, \\cite[p.~54]{Ref_Novak_etal} and \\cite[p.~188]{Ref_Pellissier}. We define the evaluation function $ev_{S^*}:S^*\\times\\{1\\}\\rightarrow\\mathbb{Q}$ that evaluates an element of $S^*$, id est a composition of $q$ and $r$, for the given input value $1$. Furthermore we define the corestriction ${ev^0_{S^*}}$ of $ev_{S^*}$ to $\\mathbb{N}$. Since a corestricion of a function resricts the function's codomain \\cite[p.~3]{Ref_Helemskii}, the function $ev^0_{S^*}$ operates on a subset $T\\subset S^*$ that contains only those compositions of $q$ and $r$, which return a natural number when inputting the value $1$.\n\n\\par\\medskip\nThe set $T$ forms not a monoid under function composition, for example $ev_{S^*}(qrq^4,1)=10$ and $ev_{S^*}(rq^6,1)=21$, but the composition $qrq^4rq^6$ does not lie in $T$, because the evaluation $ev_{S^*}(qrq^4rq^6,1)$ yields a value outside the codomain $\\mathbb{N}$. However, each element of this set labels a vertex of a tree $H_{T}\\subset H$, which is a proper subtree of $H$.\n\n\\par\\medskip\nLet $U\\subset T$ be a subset of $T$, which does not contain a reduced word with two or more successive characters $r$. The corresponding tree $H_{U}\\subset H_{T}$ reflects Collatz sequences as demonstrated in figure~\\ref{fig:1}.\n\n\\begin{remark}\nWhen talking about trees having a root (\"rooted trees\"), another important concept should be explained: the \\textbf{level of a vertex} or often called \\textbf{depth of a vertex} is the length of the path from the root to this vertex \\cite[p.~804]{Ref_Rosen}. In other words, it is the vertex's distance (the number of edges in the path) from the root. The \\textbf{height of a vertex} is its level plus one $level(v)+1=height(v)$, see \\cite[p.~169]{Ref_Makinson}.\n\\end{remark}\n\n% trim=left top right bottom\n\\begin{figure}\n\t\\includegraphics[trim=2.3cm 5.8cm 5.9cm 4.8cm, \n\twidth=1.00\\textwidth,page=1]{figures/caytree.pdf}\n\t\\caption{Small section of $H_T$ with darkly highlighted subtree $H_U$}\n\t\\label{fig:1}\n\\end{figure}\n\n\\section{Defining the Tree}\nThe starting point for specifying our tree is $H_U$. Due to its\nsignificance, we first concertize $H_U$ by the definition~\\ref{def:H_U}\nbelow, which establishes four essential characteristics.\n\n\\pagebreak\n\\begin{definition}\nThe graph $H_U$ possess the following key properties:\n\\begin{itemize}\n\t\\item \\mbox{\\boldmath$H_U$} \\textbf{is a directed graph (digraph):} Fundamentally, when we consider the more general case, an undirected graph as a triple $(V,E,\\psi)$, the incidence function maps an edge to an arbitary vertex pair $\\psi : E\\rightarrow\\{X\\subseteq V:\\left|X\\right|=2\\}$. In a digraph, the set $V\\times V$ represents ordered vertex pairs. Accordingly the incidence function is more specifically defined, namely as a mapping of the edges to that set $\\psi : E\\rightarrow\\{(v,w)\\in V\\times V:v\\neq w\\}$, see \\cite[p.~15]{Ref_Korte_Vygen}.\n\t\\item \\mbox{\\boldmath$H_U$} \\textbf{is a rooted tree:} According to Rosen \\cite[p.~747]{Ref_Rosen}, a rooted tree is \"a tree in which one vertex has been designated as the root and every edge is directed away from the root.\" Peculiarly, this definition considers the directionality as an inherent part of rooted trees. Unlike Mehlhorn and Sanders \\cite[p.~52]{Ref_Mehlhorn_Sanders}, for example, who distinguish between an undirected and directed rooted tree.\n\t\\par\\smallskip\n\t\\textit{Note: As long as we do not stipulate that vertices may collapse, it is absolutely guaranteed that the graph is a tree.}\n\t\\item \\mbox{\\boldmath$H_U$} \\textbf{is an out-tree:} There is exactly one\tpath from the root to every other node \\cite[p.~52]{Ref_Mehlhorn_Sanders}, which means that edge directions go from parents to children \\cite[p.~108]{Ref_Du_Ko_Hu}. This property is implied in Rosen's definition for a rooted tree as well by saying \"every edge is directed away from the root.\" An out-tree is sometimes designated as \\textit{out-arborescence} \\cite[p.~108]{Ref_Du_Ko_Hu}.\n\t\\item \\mbox{\\boldmath$H_U$} \\textbf{is a labeled tree:} For defining a labeled graph, Ehrig et al. \\cite[p.~23]{Ref_Ehrig_etal} use a label alphabet consisting of a vertex label set and an edge label set. Since we only label the vertices, in our case the specification of a vertex label set $L_V$ together with the vertex label function $l_V:V\\rightarrow L_V$ is sufficient. Originally, we said vertex labels are strings over the alphabet $S=\\{q,r\\}$, through which the free monoid $S^*$ is generated. We illustrate labeling $H_U$ by defining $l_{V(H_U)}(v)=ev^0_{S^*}(l_{V(G)}(\\iota(v)),1)$, whereby $\\iota:V(H_U)\\hookrightarrow V(G)$ is the inclusion map \\cite[p.~142]{Ref_Childs} from the set of vertices of $H_U$ to the set of vertices from the previously defined Cayley graph $G$.\n\\end{itemize}\n\\label{def:H_U}\n\\end{definition}\n\n\\par\\medskip\nWe define a tree $H_C$ by taking the tree $H_U$ as a basis and for every\nvertex $v\\in V(H_U)$ satisfying $2\\mid l_{V(H_U)}(v)$, we contract the\nincoming edge. We attach the label of the parent of $v$ to the new\nvertex, which results by replacing (merging) the two overlapping\nvertices that the contracted edge used to connect. Visually, we\nobtain $H_C$ by contracting all edges in $H_U$ that have an even-labeled \ntarget vertex, which (due to contraction) gets \"merged into its parent.\" \nEdge contraction is occasionally referred to as \\textit{collapsing an \nedge}. For more details and examples on edge contraction, one can see\nVoloshin \\cite[p.~27]{Ref_Voloshin} and Loehr \\cite{Ref_Loehr}.\n\n\\par\\medskip\nThe tree $H_C$ is a \\textit{minor of $H_U$}, since it can be obtained\nfrom $H_U$ \"by a sequence of any vertex deletions, edge deletions and\nedge contractions\" \\cite[p.~32]{Ref_Voloshin}. The sequence of contracting\nthe edges between adjacent (in our case even-labeled) vertices is called\n\\textit{path contraction}.\n\n\\par\\medskip\nA small section of the tree $H_C$ is shown in figure~\\ref{fig:2}. Other\ndefinitions of the same tree exist, see for example Conrow \n\\cite{Ref_Conrow} or Bauer \\cite[p.~379]{Ref_Bauer}.\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_c.png}\n\t\\caption{Small section of $H_C$ (displaying the trivial cycle is waived)}\n\t\\label{fig:2}\n\\end{figure}\n\n\\section{Relationship of successive nodes in \\mbox{$H_C$}}\n\nLet $v_1$ and $v_{n+1}$ be two vertices of $H_C$, where $v_1$ is reachable from $v_{n+1}$ with $level(v_1)-level(v_{n+1})=n$. Hence, a path $(v_{n+1},\\ldots,v_1)$ exists between these two vertices. Theorem~\\ref{theo:1} specifies the following relationship between $v_1$ and $v_{n+1}$.\n\n\\par\\medskip\n\\begin{theorem}\n\t\\label{theo:1}\n\t$l_{V(H_C)}(v_{n+1})=3^nl_{V(H_C)}(v_1)\\prod_{i=1}^{n}\\left(1+\\frac{1}{3l_{V(H_C)}(v_{i})}\\right)2^{-\\alpha_i}$.\n\tIn order to simplify readability, we waive writing down the vertex label function and put it shortly:\\\\\n\t$v_{n+1}=3^nv_1\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_{i}}\\right)2^{-\\alpha_i}$.\n\tThe value $\\alpha_i\\in\\mathbb{N}$ is the number of edges which have been contracted between $v_i$ and $v_{i+1}$ in $H_U$.\n\\end{theorem}\n\nIn order to demonstrate the construction produced by theorem~\\ref{theo:1} in an illustrative fashion, example~\\ref{ex:vertices} runs through a concrete path in $H_C$.\n\n\\par\\medskip\n\\begin{example}\n\t\\label{ex:vertices}\n\tFor example, the two vertices $v_1=45$ and $v_{1+3}=v_4=5$ are \n\tconnected\n\tvia the path $(5,13,17,45)$, see figure~\\ref{fig:2}. Furthermore, one\n\tcan retrace in figure~\\ref{fig:3} the uncontracted path between these\n\ttwo nodes within $H_U$. When applied to this example,\n\ttheorem~\\ref{theo:1} produces the following:\t\n\t\\begin{center}\n\t\t$5=v_{1+3}=3^3*45*\\left(1+\\frac{1}{3*45}\\right)*2^{-3}\n\t\t*\\left(1+\\frac{1}{3*17}\\right)*2^{-2}\n\t\t*\\left(1+\\frac{1}{3*13}\\right)*2^{-3}$\n\t\\end{center} \n\\end{example}\n\\begin{proof}\n\t\\label{proof:1}\n\tThis relationship of successive nodes can simply be proven inductively. For the base case, we set $n=1$ and retrieve\n\t\\begin{center}\n\t\t$v_{1+1}=3v_1\\left(1+\\frac{1}{3v_1}\\right)2^{-\\alpha_1}\n\t\t=\\left(3v_1+1\\right)2^{-\\alpha_1}=v_2$\n\t\\end{center}\n\tThe path from $v_2$ to $v_1$ can conformly be expressed by a string $rq\\cdots q$ of $S^*$, because of $v_1=r\\circ q^{\\alpha_1}\\left(v_2\\right)$. We set $n=n+1$ for the step case, which leads to\n\t\\begin{equation*}\n\t\\begin{array}{cl}\n\tv_{n+2} &\n\t=3^{n+1}v_1\\prod_{i=1}^{n+1}\\left(1+\\frac{1}{3v_i}\\right)2^{-\\alpha_i}\\\\\n\t&\n\t=3^{n+1}v_1\\left(1+\\frac{1}{3v_{n+1}}\\right)2^{-\\alpha_{n+1}}\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_i}\\right)2^{-\\alpha_i}\\\\\n\t&\n\t=3\\left(1+\\frac{1}{3v_{n+1}}\\right)2^{-\\alpha_{n+1}}3^nv_1\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_i}\\right)2^{-\\alpha_i}\\\\\n\t&\n\t=3\\left(1+\\frac{1}{3v_{n+1}}\\right)2^{-\\alpha_{n+1}}v_{n+1}\\\\\n\t&\n\t=\\left(3v_{n+1}+1\\right)2^{-\\alpha_{n+1}}\n\t\\end{array}\n\t\\end{equation*}\n\tIn this case the path from $v_{n+2}$ to $v_{n+1}$ is conformly \n\texpressable by a string $rq\\cdots q$ of $S^*$ too, since\n\t$v_{n+1}=r\\circ q^{\\alpha_{n+1}}\\left(v_{n+2}\\right)$.\n\\end{proof}\n\nEven though the tree may theoretically contain two or more identically labeled vertices, it is essential to emphasize that we only consider such paths $(v_{n+1},\\ldots,v_1)$ whose vertices are all labeled differently. Later in section~\\ref{sec:cycles}, we even require that identically labeled nodes are one and the same. In order to correctly determine successive nodes using theorem~\\ref{theo:1}, we must consider the halting conditions. These are specified in Definition~\\ref{def:halting_condition}.\n\n\\begin{definition}\n\t\\label{def:halting_condition}\n\tWhen determining successive nodes starting at $v_1$ according to theorem~\\ref{theo:1}, we halt if one of the following two conditions is fulfilled:\n\t\\begin{enumerate}\n\t\t\\item $v_{n+1}=1$\n\t\t\\item $v_{n+1}\\in\\{v_1,v_2,\\ldots,v_n\\}$\n\t\\end{enumerate}\n\tIf the first condition applies, the Collatz conjecture is true for a specific sequence. When the second condition is fulfilled, the sequence has led to a cycle. For every starting node, except the root node (labeled with $1$), the Collatz conjecture is consequently falsified. Let us consider the example $v_1=13$, where the algorithm halts after two iterations, because the first condition is met:\n\t\\[\n\tv_{n+1}=3^2\\cdot\\left(1+\\frac{1}{3\\cdot13}\\right)\\left(1+\\frac{1}{3\\cdot5}\\right)\\cdot2^{-7}=1\n\t\\]\n\t\n\tIf we examine the case $v_{1}=1$, we realize that the algorithm finishes after the first iteration, since both halting conditions are true. The sequence stops because the final node labeled with $1$ is reached. Furthermore, the sequence has led to a cycle:\n\t\\[\n\tv_{n+1}=3\\cdot\\left(1+\\frac{1}{3}\\right)2^{-2}=1\n\t\\]\n\t\n\tThe trivial cycle is the only sequence where both conditions are fulfilled.\n\\end{definition}\n\n\\noindent\nTheorem~\\ref{theo:1} can be used for specifying the condition of a cycle as follows:\n\n\\begin{equation}\n\\label{eq:func_cycle}\n\\begin{array}{l}\nv_{1}=3^nv_1\\prod_{i=1}^{n}\\left(1+\\frac{1}{3v_i}\\right)2^{-\\alpha_i}\n\\\\[\\medskipamount]\n2^{\\alpha_1+\\cdots+\\alpha_n}=\\prod_{i=1}^{n}\\left(3+\\frac{1}{v_i}\\right)\n\\end{array}\n\\end{equation}\n\nA similar condition has been formulated by Hercher \\cite{Ref_Hercher} and Eric Roosendaal \\cite{Ref_Roosendaal_2020}. Taking a first look at equation~\\ref{eq:func_cycle}, we are able to recognize the trivial cycle for $n=1$. One might easily come to the false conclusion that the term only results in a natural number for this trivial cylce, since we are multiplying fractions. The following counterexample, starting at $v_1=31$, disproves this assumption:\n\\begin{equation*}\n20480=\\left(3+\\frac{1}{31}\\right)\\left(3+\\frac{1}{47}\\right)\n\\left(3+\\frac{1}{71}\\right)\\left(3+\\frac{1}{107}\\right)\\left(3+\\frac{1}{161}\\right)\\left(3+\\frac{1}{121}\\right)\\left(3+\\frac{1}{91}\\right)\\left(3+\\frac{1}{137}\\right)\\left(3+\\frac{1}{103}\\right)\n\\end{equation*}\n\nAccording to OESIS \\cite{Ref_OESIS}, the integer $v_1=31$ is called \\textit{self-contained}. The term self-contained is based on the fact that the node $v_{n+1}=v_{10}=155$ is divisible by the starting node $v_1=31$. Moreover, $v_{10}$ results from applying one and the same function (in this case the Collatz function) using $v_1$ as input, see also Guy \\cite[p.~332]{Ref_Guy}. For such a case equation~\\ref{eq:func_cycle} leads to a natural number, but not necessarily to a cycle. A cycle only occurs if the term results in a power of two. One example is the trivial cycle. We find another case when we choose the factor $5$ instead of $3$:\n\\begin{center}\n\t$128=2^7=\\left(5+\\frac{1}{13}\\right)\\left(5+\\frac{1}{33}\\right)\n\t\\left(5+\\frac{1}{83}\\right)$\n\\end{center}\n\nThe above example shows that non-trivial cycles can be found if we generalize the Collatz conjecture by replacing the factor $3$ with the variable $k$. We study this generalized form and the occurance of cycles in section~\\ref{sec:cycles}. A detailed elaboration of the divisibility and a deeper understanding of the tree $H_C$ needs to be performed in order to get towards any proof of the Collatz conjecture.\n\n%\\par\\medskip\\noindent\n%Generally, for any variant $kx+1$ it applies that if $v_1\\mid v_{n+1}$, the the product is natural:\n%\\begin{equation*}\n%\t\\prod_{i=1}^n\\left(k+\\frac{1}{v_i}\\right)\\in \\mathbb{N}\n%\\end{equation*}\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_u.png}\n\t\\caption{Section of $H_U$ containing the path from $5$ to $45$}\n\t\\label{fig:3}\n\\end{figure}\n\n\\section{Relationship of sibling nodes in \\mbox{$H_C$}}\nIn a rooted tree, vertices which have the same parent are called \"siblings\" \\cite[p.~702]{Ref_Johnsonbaugh}, \\cite[p.~747]{Ref_Rosen}. Sibling vertices accordingly have the same level.\n\n\\par\\medskip\nLet $w$ be a vertex, from which a path exists to the vertex $v_1$. Let $v_2$ be the immediate right-sibling of $v_1$, then $l_{V\\left(H_C\\right)}\\left(v_2\\right)=4*l_{V\\left(H_C\\right)}\\left(v_1\\right)+1$. This fact has been expressed differently by Kak \\cite{Ref_Kak_2014} as follows: \"If an odd number $a$ leads to another odd number (after several applications of the Collatz transformation) $b$, then $4a+1$ also leads to $b$.\"\n\n\\par\\medskip\nApplied to our approach, consider $w$ as the parent of $v_1$ and $v_2$. Suppose, in $H_U$, a path consisting of $n+1$ edges goes from $w$ to $v_1$. Then we can straightforwardly show that $n$ edges in $H_U$ have been contracted between both nodes $w$ and $v_1$ and $n+2$ edges between $w$ and $v_2$ (for simplicity we again omit writing the label function):\n\\begin{equation*}\n\\begin{array}{l}\n\t\tv_1=\\frac{w*2^n-1}{3}\n\t\t\\\\[\\medskipamount]\n\t\tv_2=\\frac{w*2^{n+2}-1}{3}=4*v_1+1\n\\end{array}\n\\end{equation*}\n\nFor example, $n=3$ edges in $H_U$ have been contracted between $w=5$ and $v_1=13$ and $n+2=5$ edges between $w$ and $v_2=53$, whereby in $H_C$, the vertex $v_2$ is the right-sibling of $v_1$ and these two sibling vertices are immediate children of $w$.\n\n\\section{A vertex's \\mbox{$n$}-fold left-child and right-sibling in \\mbox{$H_C$}}\nReferring to the \"left-child, right-sibling representation\" of rooted trees \\cite[p.~246]{Ref_Cormen_Leiserson_Rivest_Stein}, the function $\\textit{left-child}:V\\rightarrow V$ returns the leftmost child of a vertex $v$. Nesting this function $n$ times leads to the definition of a vertex's $n$-fold left-child, which is given by $\\textit{left-child}^n(v)$. As shown in figure~\\ref{fig:2}, for example $\\textit{left-child}^3(13)=7$.\n\n\\par\\medskip\nThe function $\\textit{right-sibling}:V\\rightarrow V$ points to the sibling of a vertex $v$ immediately to its right \\cite[p.~246]{Ref_Cormen_Leiserson_Rivest_Stein}. If this function is nested $n$ times, we get a vertex's $n$-fold right-sibling defined by $\\textit{right-sibling}^n(v)$. One example is $\\textit{right-sibling}^2(113)=1813$ which has been demonstrated in figure~\\ref{fig:2} too.\n\n\\par\\medskip\nLet $w$ be a vertex in $H_C$ and $v_0$ the left-child of $w$. The $n$-fold right-sibling of $v_0$ can be calculated as follows:\n\\begin{equation}\n\\label{eq:nfold_right_sibling}\n\tv_n=\\textit{right-sibling}^n(v_0)=\\frac{1}{3}*\\left(w*2^{2*n+\\pi_3(w\\bmod 3)}-1\\right)\n\\end{equation}\n\nThe function $\\pi_3$ is the self-inverse permutation (involution):\n\\begin{equation}\n\\label{eq:pi_3}\n\t\\pi_3=\\left(\\begin{array}{cc}\n\t1 & 2\\\\\n\t2 & 1\n\t\\end{array}\\right)\n\\end{equation}\nWe consider permutations of the set $\\{1,2\\}$ and not of $\\{0,1,2\\}$, due to the fact that $w\\bmod 3$ cannot be zero. A node $w$ in $H_C$, which is labeled by an integer divisible by $3$ is a leaf; and therefore such node has no left-child, more specifically it has no children at all.\n\n\\par\\medskip\n\\noindent\nWhen setting $n=0$, we trivially retrieve the vertex's $w$ left-child:\n\\begin{center}\n\t$v_0=\\textit{left-child}(w)=\\frac{1}{3}*\\left(w*2^{\\pi_3(w\\bmod 3)}-1\\right)$\n\\end{center}\n\n\\begin{example}\n\t\\label{ex:siblings}\n\tLet us refer to figure~\\ref{fig:2} again and pick out $w=5$. Then the\n\tvertex's $w$ left-child is $v_0=3$ and the threefold right-sibling\n\t$v_3=213$:\n\n\t\\begin{equation*}\n\t\\begin{array}{l}\n\t\tv_0=\\frac{1}{3}*\\left(5*2^{\\pi_3(5\\bmod 3)}-1\\right)=3\n\t\t\\\\[\\medskipamount]\n\t\tv_3=\\frac{1}{3}*\\left(5*2^{2*3+\\pi_3(5\\bmod 3)}-1\\right)=213\n\t\\end{array}\n\t\\end{equation*}\n\\end{example}\n\n\\section{Left-child and right-sibling in the \\mbox{$5x+1$} variant of \\mbox{$H_C$}}\nIn the following we take a look at the $5x+1$ variant of $H_C$. We name this graph $H_{C,5}$ and must note that it is not a tree and moreover that not all of its vertices are reachable from the root. We define the permutation $\\pi_5$ as follows:\n\\begin{center}\n\t$\\pi_5=\\left(\\begin{array}{cccc}\n\t\t1 & 2 & 3 & 4\\\\\n\t\t4 & 3 & 1 & 2\n\t\\end{array}\\right)$\t\n\\end{center}\n\nNext, by letting $w$ be a vertex in $H_{C,5}$ and $v_0$ the left-child of $w$\nwe obtain the $n$-fold right-sibling of $v_0$ by the function that\nis slightly different to the one defined by \\ref{eq:nfold_right_sibling}:\n\\begin{equation}\n\\label{eq:nfold_right_sibling_5}\n\tv_n=\\textit{right-sibling}^n(v_0)=\\frac{1}{5}*\\left(w*2^{4*n+\\pi_5(w\\bmod 5)}-1\\right)\n\\end{equation}\n\nAnalogous to \\ref{eq:pi_3} only permutations on the set without zero\n\\{1,2,3,4\\} need to be considered, since $w\\bmod 5$ cannot be zero.\nOtherwise, if $w\\equiv 0 (\\bmod 5)$ which means that $w$ were labeled\nby an integer divisible by 5, then the node $w$ has no successor in $H_{C,5}$.\n\n\\par\\medskip\n\\noindent\nBy setting $n=0$, the function (above given by \\ref{eq:nfold_right_sibling_5}) returns the left child of $w$:\n\\begin{center}\n\t$v_0=\\textit{left-child}(w)=\\frac{1}{5}*\\left(w*2^{\\pi_5(w\\bmod 5)}-1\\right)$\n\\end{center}\n\n\\begin{figure}\n\t\\includegraphics[width=1.00\\textwidth]{figures/h_c5b.png}\n\t\\caption{Section of the graph $H_{C,5}$ starting at its root (without branches that reflect a subsequence containing the trivial cycle)}\n\t\\label{fig:4}\n\\end{figure}\n\nFigure~\\ref{fig:4} illustrates a small section of $H_{C,5}$ starting at its root. The particularly interesting thing about the graph $H_{C,5}$ is that it contains three cycles, the trivial cycle starting from the root $1,3$ and two non-trivial cycles $43,17,27$ and $83,33,13$. To be precise, three cycles are known (as it will become apparent later in section~\\ref{sec:non_trivial_cycles}), and on the basis of present knowledge it cannot be ruled out with any certainty that other cycles exist.\n", "meta": {"hexsha": "3c5435157b9dd56c735302b1da7de09c77a7d94d", "size": 22363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v4.1/chapter/02_collatz_tree_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/v4.1/chapter/02_collatz_tree_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/v4.1/chapter/02_collatz_tree_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": 67.7666666667, "max_line_length": 980, "alphanum_fraction": 0.7248580244, "num_tokens": 7344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6215795157866514}}
{"text": "\\documentclass[../main.tex]{subfiles}\n \\begin{document}\n  \\chapter{$ L^p $ Spaces}\n  \\begin{exercise}\n    Prove that the supremum of any collection of convex funtions on $ (a, b) $ is convex on $ (a, b) $ (if it is finite) and that pointwise limits of sequences of convex functions are convex. What can you say about the upper and lower limits of sequences of convex functions.\n    \\paragraph{Solution. }\n    If $ f_n $ is a sequence of convex functions, and $ f $ is its supremum. For any $ x, y \\in (a, b) $, $ n \\in \\mathbb{N} $,\n    \\begin{align*}\n      \\lambda f(x) + (1 - \\lambda) f(y) \\ge \\lambda f_n(x) + (1 - \\lambda) f_n(y) \\ge f_n(\\lambda x  + (1 - \\lambda) y)\n    \\end{align*}\n    Taking supremum on the right side gives the result.\n\n    Now take $ f = \\lim f_n $, if that exists and $ \\{\\infty, -\\infty \\} \\not \\subset f[(a, b)] $. Then $ f $ is convex by observing\n    \\begin{align*}\n      f_n(\\lambda x + (1 - \\lambda) y) \\to f(\\lambda x + (1 - \\lambda y)),\\\\\n      \\lambda f_n(x) + (1 - \\lambda) f_n(y) \\to \\lambda f(x) + (1 - \\lambda) f(y).\n    \\end{align*}\n\n    Notice $ \\limsup f_n = \\lim _{n = 1} \\sup _{k \\ge n} f_n $ is convex by the above arguments.\n\n    However, $ \\liminf f_n $ may not be convex. Take $ (a, b) = (0, 1) $. Define\n    \\begin{align*}\n      f_n (x) = \\begin{cases}\n        x, \\text{$ n $ is odd}\\\\\n        1 - x, \\text{$ n $ is even}\n    \\end{cases}.\n    \\end{align*}\n    Clearly $ \\liminf f(x) = \\begin{cases}\n      x, 0 < x \\le 1/2\\\\\n      1 - x, 1/2 \\le x < 1\n    \\end{cases}. $\n    That $ f $ is not convex is by verifying $ f(1/2) > 1/2f(1/4) + 1/2f(3/4) $\n  \\end{exercise}\n\n  \\setcounter{exercise}{3}\n  \\begin{exercise}\n    Suppose $ f $ is a complex measurable function on $ X $, $ \\mu $ is a positive measure on $ X $, and\n    \\begin{align*}\n      \\phi(p) = \\int_X |f ^{p} | d\\mu = || f ||^p_p, (0 < p < \\infty).\n    \\end{align*}\n    Let $ E = \\{p: \\phi(p) < \\infty\\} $. Assume $ ||f||_\\infty > 0 $.\n\n    \\begin{enumerate}\n      \\item If $ r < p < s, r\\in E $ and $ s \\in E $, prove that $ p \\in E $.\n      \\item Prove that $ \\log \\phi $ is convex in the interior of $ E $ and that $ \\phi $ is continuous on $ E $.\n      \\item By a), $ E $ is connected. Is $ E $ necessarily open? Closed? Can $ E $ consist of a single point? Can $ E $ be any connected subset of $ (0, \\infty) $?\n      \\item if $ r < p < s $, prove that $ ||f||_p \\le \\max(||f||_r, ||f||_s) $. Show that this implies the inclusion $ L^r(\\mu) \\cap L^s(\\mu) \\subset L^p(\\mu) $.\n      \\item Assume that $ ||f||_r < \\infty $ for some $ r < \\infty $ and prove that\n      \\begin{align*}\n        ||f||_p \\to ||f||_\\infty, \\text{as $ p \\to \\infty.$}\n      \\end{align*}\n    \\end{enumerate}\n\n  \\end{exercise}\n\n  \\begin{exercise}\n    Assume, in addition to the hypothesis of Exercise 4, that\n    \\begin{align*}\n      \\mu(X) = 1.\n    \\end{align*}\n    \\begin{enumerate}\n      \\item Prove that $ ||f||_r \\le ||f||_s $, if $ 0 < r < s \\le \\infty $.\n      \\item Under what conditions does it happen that $ 0 < r < s \\le \\infty $ and $ ||f||_r = ||f||_s < \\infty $?\n      \\item Prove that $ L^r(\\mu) \\subset L^s(\\mu) $ if $ 0 < r < s $. Under what conditions do these two spaces contain the same functions?\n      \\item Assume that $ ||f||_r < \\infty $ for some $ r > 0 $, and prove that\n      \\begin{align*}\n        \\lim _{p \\to 0} ||f||_p = \\exp \\left \\{\\int_X \\log |f| d\\mu \\right \\}\n      \\end{align*}\n      if $ \\exp \\{-\\infty\\} $ is defined to be $ 0 $.\n\n    \\end{enumerate}\n\n    \\paragraph{Solution. }\n    \\begin{enumerate}\n      \\item\n      \\item\n      \\item\n      \\item By definition of Lebesgue integral,\n      \\begin{align*}\n        \\int \\log |f| d\\mu = \\int _{|f| \\ge 1} \\log |f| d\\mu - \\int _{|f| \\le 1} -\\log|f| d\\mu\n      \\end{align*}\n      since the above is essentially decomposing a integral of a function into that of its positive and negative parts. Note the integral of the positive part cannot be $ \\infty $, because otherwise by the inequality $ \\log t \\le t - 1 $,\n      \\begin{align*}\n        \\infty = \\int _{|f| \\ge 1} \\log |f| d\\mu = \\int _{|f| \\ge 1} \\frac {1}{p} (|f|^p - 1) d\\mu \\le \\frac {1}{p} \\int _{|f| \\ge 1} (|f|^p - 1)\n      \\end{align*}\n      showing $ ||f||_p = \\infty $ for any $ p > 0 $, a contradition to the hypothesis in the question. Therefore $ \\int \\log |f| = -\\infty $ or it is finite.\n\n      Frist consider the finite case.\n      Take any $ p_n \\to 0 $, define $ f_n = \\frac {|f|^{p_n} - 1}{p_n} $. Notice $ \\lim f_n = \\frac {d}{d|f|} |f|^p| _{|f| = 0} $ = $ \\log |f| $. Further for any $ 0 < p_n < r $, if $ |f| \\ge 1 $,\n      \\begin{align*}\n        |f_n| = \\left | \\frac {|f|^{p_n}  - 1}{p_n} \\right| = \\int _{1} ^{|f|} s ^{p_n-1} ds \\le \\int _{1} ^{|f|} s ^{r - 1}  ds \\le \\frac {|f|^r - 1}{r} ,\n      \\end{align*}\n      and if $ |f| \\le 1 $,\n      \\begin{align*}\n        |f_n| = \\left | \\frac {|f|^{p_n} - 1}{p_n} \\right| = \\int _{|f|} ^{1} s ^{p_n-1} ds \\le \\int _{1} ^{|f|} s ^{-1} ds \\le -\\log|f|.\n      \\end{align*}\n      Therefore $ |f_n| \\le \\frac {|f|^r - 1}{r}\\mathcal{X} _{|f| \\ge 1} - \\log |f|\\mathcal{X} _{|f| \\le 1} $. By Dominated Convergence,\n      \\begin{align*}\n        \\int f_n \\to \\int \\log |f|.\n      \\end{align*}\n      Observe, by the inequality $ \\log t \\le t -1$ again,\n      \\begin{align*}\n        \\frac {1}{p} \\log \\int |f|^p \\le \\int \\frac {|f|^p - 1}{p} \\to \\int \\log |f|,\n      \\end{align*}\n      as $ p \\to 0 $.\n      By Jensen,\n      \\begin{align*}\n        \\frac {1}{p} \\log \\int |f|^p \\ge \\int \\log |f|,\n      \\end{align*}\n      for any $ p \\le r $, since $ \\log $ is concave over $ \\mathbb{R} $.\n      Finally the result is obtained by sandwich theorem.\n\n      Now if $ \\int \\log |f| d\\mu = -\\infty $, take $ f_n = |f|\\mathcal{X}_{|f| > 1/n} + \\mathcal{X}_{|f| \\le 1/n} $, where $ n $ starts at $ 1 $. Clearly,\n      \\begin{enumerate}\n        \\item $ ||f||_p \\le ||f_n||_p$.\n        \\item $ \\log |f_n| = \\log |f| \\mathcal{X}_{|f| > 1/n} $.\n        \\item $ -\\log |f_n| < \\log n $\n      \\end{enumerate}\n      Notice the positive and negative part of $ \\log|f_n| $, by b), both converges increasingly to those of $ \\log |f| $. By Monotone Convergence, $ \\lim\\limits _{n\\to \\infty} \\exp \\{\\int \\log |f_n|\\} \\to \\exp \\{\\int \\log |f|\\} = 0  $. By c) $ \\int \\log |f_n| \\ne -\\infty $.\n      Obviously $ f_n \\in L ^{r}(\\mu) $, therefore $ \\log |f_n| $ can only have finite integral by the same proof as in $ \\log |f| $.     Now together with previous arguments, $ \\lim\\limits _{p \\to 0}  ||f_n||_p \\to \\exp \\{\\int \\log |f_n|\\} $.\n      Therefore by a),\n      \\begin{align*}\n        \\limsup _{p\\to 0} ||f||_p = \\lim _{n\\to \\infty} \\limsup _{p \\to 0} ||f||_p \\le \\lim _{n\\to \\infty} \\lim _{p \\to 0} ||f_n||_p = \\lim _{n\\to \\infty} \\exp\\left \\{\\int \\log |f_n|\\right \\} = 0.\n      \\end{align*}\n      Since $ ||f||_p \\ge 0$, $ ||f||_p \\to 0 $, as $ p \\to 0 $.\n    \\end{enumerate}\n\n\n  \\end{exercise}\n \\end{document}\n", "meta": {"hexsha": "7f57dde9549629b3ad0350cff3e6b1816bf74642", "size": 6881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_3/chapter_3.tex", "max_stars_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_stars_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_stars_repo_licenses": ["MIT"], "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/chapter_3.tex", "max_issues_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_issues_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_issues_repo_licenses": ["MIT"], "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/chapter_3.tex", "max_forks_repo_name": "AstrickHarren/Solutions-to-Real-and-Complex-Analysis", "max_forks_repo_head_hexsha": "a5433af43fa833c76779e925da3925208607f69b", "max_forks_repo_licenses": ["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.5267175573, "max_line_length": 275, "alphanum_fraction": 0.5317541055, "num_tokens": 2662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6215495567729987}}
{"text": "\\documentclass[12pt]{amsart}\n\\usepackage[margin=1.5in]{geometry}\n%\\usepackage{graphicx}\n\\usepackage{txfonts}\n\\pagestyle{plain}\n\\nofiles\n\\begin{document}\n\n\\begin{center}\n  \\textbf{Adding/Deleting Elements/Relations To/From a Poset}\n\\end{center}\n\nLet $P=(X,\\le)$ be a partially order set (or poset). Here $X$ is a set\nof \\emph{elements} and $\\le$ is a reflexive, antisymmetric, transitive\n\\emph{relation} on $X$.\n\nWe wish to consider the following four operations: (1)~add an element\nto a poset, (2)~delete an element from a poset, (3)~add a relation\nto a poset, and (4)~delete a relation from a poset. \n\n\\section*{Adding/Deleting Elements}\n\nOperations on elements are relatively simple to describe. Let\n$P=(X,\\le)$ be a poset. \n\nIf $a\\notin X$, then to add the element $a$ to $P$ results in a new\nposet that includes $a$ in which $a$ is related only to\nitself. Formally, let $P'= P+a$ be the poset $P'=(X',\\le')$ where we\nhave the following:\n\\begin{enumerate}\n\\item $X' = X \\cup \\{a\\}$.\n\\item $\\mathord{\\le'} = \\mathord{\\le} \\cup \\{(a,a)\\}$. That is, \n  \\begin{itemize}\n  \\item $\\forall x,y \\in X, x\\le'y\\iff x\\le y$,\n  \\item $\\forall x \\in X,\\ x\\not\\le'a$ and $a \\not\\le' x$, and\n  \\item $a\\le' a$.\n  \\end{itemize}\n\\end{enumerate}\n\nElement deletion is also easy to describe. Deleting an element $a$\nfrom $P$ deletes $a$ from the set $X$ and all remaining elements have\nthe same relations they had before. Formally, for $a \\in X$, let\n$P'=P-a$ be the poset $P'=(X',\\le')$ where we have the following:\n\\begin{enumerate}\n\\item $X' = X - \\{a\\}$.\n\\item $\\forall x,y \\in X',\\ x \\le' y \\iff x\\le y$.\n\\end{enumerate}\n\nNote that element addition and deletion operations need not\ncommute. While it is true that $(P+a)-a=P$, in general we have\n$(P-a)+a\\not=P$. \n\n\n\\section*{Adding/Deleting Relations}\n\nAdding a relation to a poset requires us to include additional\nrelations implied by transitivity. Let $P=(X,\\le)$ be a poset\ncontaining incomparable elements $a$ and $b$.\n\nWe define $P+(a<b)$ to be the poset $P' = (X',\\le')$ in which we have\nthe following:\n\\begin{itemize}\n\\item $X' = X$.\n\\item $\\forall x,y \\in X', \\ x \\le' y \\iff (x \\le y) \\text{ or } \n  (x \\le a \\text{ and } b \\le y)$.\n\\end{itemize}\nStated differently, $\\le'$ is the minimal superset of $\\le$ that\nincludes the pair $(a,b)$ and that is reflexive, antisymmetric, and\ntransitive. \n\nThere does not appear to be ``best'' way to define relation\ndeletion. Suppose $P=(X,\\le)$ is a poset in which $a<b$; we want to\ndefine $P' = P-(a<b)$.  For example, suppose $P=([3],\\le)$ is the\ntotal order $1<2<3$. How shall we define $P-(1<3)$? Since we delete\n$(1,3)$ from the relation, we cannot have both $1<2$ and $2<3$, so one\nof those must be deleted as well.  This leads to two possible choices\nfor $\\le'$ are these:\n\\begin{itemize}\n\\item $\\mathord{\\le'} = \\{(1,1),(2,2),(3,3), (1,2) \\}$ and\n\\item $\\mathord{\\le'} = \\{(1,1),(2,2),(3,3), (2,3) \\}$.\n\\end{itemize}\nThere's no reasonable way to choose between these alternatives. Both\nare derived from $\\le$ with a minimum number of changes. So we take\nanother approach by deleting both $1<2$ and $2<3$. This results in the\nantichain on $[3]$. \n\nMore generally, when we delete $a<b$ from $P$ we need to delete other\nrelations. In particular, if there is an $x$ with $a<x<b$, we cannot\nkeep both $a<x$ and $x<b$. Our solution is to delete \\emph{both}. \n\nThus we define $P-(a<b)$ to be the poset $P' = (X',\\le')$ in which \n$X'=X$ and\n\\[\n\\mathord{\\le'} = \\mathord{\\le} \n- \\bigl\\{ (a,b) \\bigr\\}\n- \\bigl\\{(a,x),(x,b) : a<x<b \\bigr\\} .\n\\]\n\n\\noindent\\textbf{Claim}. \\emph{$P'$ is a poset.}\n\n\\begin{proof}\n  We need to check that $\\le'$ is reflexive, antisymmetric, and\n  transitive. \n\n  Since we have not deleted any relation of the form $(x,x)$ from\n  $\\le$, it follows that $\\le'$ is reflexive.\n\n  Since $\\mathord{\\le'} \\subset \\mathord{\\le}$ it follows that \n  \\[\n  (x \\le' y \\text{ and } y \\le' x) \\Rightarrow\n  (x \\le y \\text{ and } y \\le x) \\Rightarrow x=y .\n  \\]\n\n  Finally, we must show that $\\le'$ is transitive. Suppose $x <' y <'\n  z$ but we do not have $x <' z$. This means that $(x,z)$ was a\n  relation deleted from $\\le$ and so we have one of the following:\n  \\begin{enumerate}\n  \\item $(x,z) = (a,b)$,\n  \\item $a=x < z < b$, or\n  \\item $a<x<z=b$.\n  \\end{enumerate}\n  \n  Case (1) cannot hold because then we have $x=a<y<b=z$ in which case\n  neither $x<'y$ nor $y<'z$ contradicting the supposition that\n  $x<'y<'z$. \n\n  In case (2) we have that $a=x < y < z < b$ contradicting $x <' y$,\n  and a similar contradiction holds in case~(3). \n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "8d311239c45a146a1a47539ce5fe6cba688d17a7", "size": 4567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/addition-deletion.tex", "max_stars_repo_name": "UnofficialJuliaMirrorSnapshots/SimplePosets.jl-b2aef97b-4721-5af9-b440-0bad754dc5ba", "max_stars_repo_head_hexsha": "95f1c5d1d761b2f0a54ee6fa968e28d812b51705", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-06-17T16:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-21T17:25:40.000Z", "max_issues_repo_path": "doc/addition-deletion.tex", "max_issues_repo_name": "UnofficialJuliaMirrorSnapshots/SimplePosets.jl-b2aef97b-4721-5af9-b440-0bad754dc5ba", "max_issues_repo_head_hexsha": "95f1c5d1d761b2f0a54ee6fa968e28d812b51705", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-11T14:03:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T20:17:10.000Z", "max_forks_repo_path": "doc/addition-deletion.tex", "max_forks_repo_name": "UnofficialJuliaMirrorSnapshots/SimplePosets.jl-b2aef97b-4721-5af9-b440-0bad754dc5ba", "max_forks_repo_head_hexsha": "95f1c5d1d761b2f0a54ee6fa968e28d812b51705", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-07-10T22:12:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-14T01:13:09.000Z", "avg_line_length": 34.5984848485, "max_line_length": 70, "alphanum_fraction": 0.6507554193, "num_tokens": 1595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.621549549351231}}
{"text": "\\section*{Exercise 26.3-2}\r\nProof of Theorem 26.10.\r\n\\\\\r\n\\\\\r\nThe proof is by induction. \r\n\r\n\\emph{The base case, the first iteration}\r\n\r\nFirst, the Ford-Fulkerson method initializes the flow to 0 on all edges. Hence at iteration 0, no iteration have run, all flow values are 0 and the outgoing flow is 0. Hence the induction base case is valid.\r\n\r\nNow assume that for iteration $n$ the theorems statement is true, we now want to show that for iteration $n+1$ the statement is also true.\r\n\r\nAt the beginning of iteration $n+1$ two things can happen.\r\n\r\n1) There is no path from $s$ to $t$ in $G_f$.\r\n\r\nIf there is no path, then the Ford-Fulkerson method finishes with the values found from iteration $n$. Those values are true by the induction step assumptions.\r\n\r\n2) There is a path from $s$ to $t$ in $G_f$.\r\n\r\nIn this case the algorithm determines $c_f(p)$ which is an integer, since that value is chosen from the integer residual capacities that is the outcome of the  $n$'th iteration. All existing flow on path $p$ are updated with the $c_f(p)$. The existing flow is integer because of the induction assumption and adding or subtracting the integer $c_f(p)$ will yield an integer. Since the flow $f$ is only updated with the integer capacity $c_f(p)$, the new $\\abs{f}$ that yields from the iteration will also only be updated with that integer value. Thus $\\abs{f}$ is also integer after iteration $n+1$.", "meta": {"hexsha": "fbfdae2da55aaf5a9f0b8a7fa56ba04d3e589a12", "size": 1410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/26.3-2.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": "Uge1/26.3-2.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": "Uge1/26.3-2.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": 67.1428571429, "max_line_length": 598, "alphanum_fraction": 0.7397163121, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.6214685312778948}}
{"text": "\\documentclass[11pt, numbers=endperiod, parskip=half]{scrartcl}\n\n\\usepackage{amsmath}\n\\usepackage{color}\n\\usepackage{semantic}\n\\usepackage{minted}\n\n\\title{Assignment 3}\n\\subtitle{COS30023 - Languages in Software Development}\n\\author{Daniel Parker - 971328X}\n\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\section{Problem 1}\n\\subsection{String specification}\n\\begin{align*}\nS ::=& \\ \\ \\ \\epsilon \\\\\n&|\\ \\ aS\n\\end{align*}\n\\subsection{String Length Specification}\n\n\\begin{align*}\nlength(\\ \\epsilon\\ ) &= 0 \\\\\nlength(\\ aS\\ ) &= 1 + length(\\ S\\ )\n\\end{align*}\n\n\\subsection{String Concatenation Specification}\n\\begin{align*}\ns_1 &= \\epsilon: & \\epsilon \\oplus s_2 & &= &s_2 &\\\\\ns_1 &= as'_1: & as'_1 \\oplus s_2 & &= &a(s'_1 \\oplus s_2)\n\\end{align*}\n\\clearpage\n\\subsection{a)}\nShow that if \\(s \\in S\\), then \\(s \\oplus \\epsilon = s\\)\\\\\n\\textbf{Base Case 1}\\\\\n\\[\ns \\equiv \\epsilon\n\\]\n\\[\n\\epsilon \\oplus \\epsilon = \\epsilon\n\\]\nThe first base case is when s is structurally equivalent to the empty string \\(\\epsilon\\) and it's a fact that concatenating two empty strings will yield another empty string.\n\n\\textbf{Base Case 2}\\\\\nif \\(length(s) = 1\\) then\n\\[\ns \\oplus \\epsilon = s\n\\]\n\nIn this second base case we take s to be any string of length 1 and again it is a fact that any string concatenated with the empty string \\(\\epsilon\\) will be the original first string. In this case the string will still be of length 1.\n\n\\textbf{Inductive Step}\\\\\nWe assume that the base case holds for all lengths of s greater than 1, therefore:\n\nif \\(length (s) > 1\\)\n\\[\ns \\oplus \\epsilon = s\n\\]\n\\textbf{Q.E.D.}\n\\subsection{b)}\nShow that if \\(s_1, s_2 \\in S\\) then \\(length(s_1 \\oplus s_2) = length(s_1) + length(s_2)\\)\\\\\n\\textbf{Base Case 1}\\\\\n\\(s_1, s_2 \\equiv \\epsilon\\)\n\nGiven that \\(length(\\epsilon) = 0\\) then it goes to say that \\(length(\\epsilon \\oplus \\epsilon) = 0\\).\\\\\n\n\\textbf{Base Case 2}\\\\\n\\(s_1 \\neq \\epsilon\\), where \\(length(s_1) = 1\\) and \\(s_2 \\equiv \\epsilon\\).\n\\[\nlength(s_1 \\oplus \\epsilon) = length(s_1)\n\\]\n\nFor the case where \\(s_1\\) is a string of length 1 and \\(s_2\\) is an empty string, the concatenated length will be the length of \\(s_1\\).\\\\\n\n\\textbf{Base Case 3}\\\\\n\\(s_1, s_2 \\neq \\epsilon\\), where \\(length(s_1) = 1\\) and \\(length(s_2) = 1\\).\n\\[\nlength(s_1 \\oplus s_2) = length(s_1) + length(s_2) = 2\n\\]\n\nFor the case where both \\(s_1\\) and \\(s_2\\) are strings of length 1, the concatenated length will be the sum of the individual lengths, which is 2.\n\n\\textbf{Inductive Step} \\\\\n\\(length(s_1) > 1\\) and \\(length(s_2) > 1\\)\n\\[\nlength(s_1 \\oplus s_2) = length(s_1) + length(s_2)\n\\]\n\nWe assume the base case 3 holds for strings \\(s_1, s_2\\) of any length greater than 1.\\\\\n\n\\textbf{Q.E.D.}\n\\section{Problem 2}\n\\inputminted{prolog}{list_check.pl}\n\\end{document}\n", "meta": {"hexsha": "4042e018862052f6e14abefee5eb0332d4a77c31", "size": 2765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/3/assignment3.tex", "max_stars_repo_name": "rlgod/languages-in-software-development", "max_stars_repo_head_hexsha": "4a936667f22d2783521c917d60861249a2ae6671", "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/3/assignment3.tex", "max_issues_repo_name": "rlgod/languages-in-software-development", "max_issues_repo_head_hexsha": "4a936667f22d2783521c917d60861249a2ae6671", "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/3/assignment3.tex", "max_forks_repo_name": "rlgod/languages-in-software-development", "max_forks_repo_head_hexsha": "4a936667f22d2783521c917d60861249a2ae6671", "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.2142857143, "max_line_length": 236, "alphanum_fraction": 0.6755877034, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6214685291672398}}
{"text": "% Copyright 2018 Markus J. Pflaum, licensed under GNU FDL v1.3\n% main author: \n%   Markus J. Pflaum\n%\n\\section{Projection-valued measures and spectral integrals}\n\\para\n  In this section $\\hilbertH$ will always denote a fixed complex Hilbert space. \n\\begin{definition}\n  By a \\emph{projection-valued measure} or a \\emph{spectral measure} on a \n  measurable space $(\\Omega,\\mathscr{A})$ one understands a map \n  $E: \\mathscr{A} \\to \\blinOps(\\hilbertH)$ having the following properties:\n  \\begin{axiomlist}[SM]\n  \\setcounter{enumi}{-1}\n  \\item For each $\\Delta \\in \\mathscr{A}$ the operator $E(\\Delta)$ is an orthogonal projection \n        that is $E(\\Delta)^2 = E(\\Delta)$ and $E(\\Delta)^* = E(\\Delta)$.\n  \\item $E(\\Omega) = \\id_\\hilbertH$.\n  \\item For every sequence $(\\Delta_n)_{n\\in \\N}$ of pairwise disjoint elements of $\\mathscr{A}$ \n        one has \n        \\[ E\\left(\\bigcup_{n\\in\\N} \\Delta_n \\right) =   \\strong\\sum_{n=0}^\\infty E(\\Delta_n) \\ , \\] \n        where convergence is with respect to the strong operator toplogy.\n  \\end{axiomlist}\n\\end{definition}\n\n\\begin{remark}\n  Recall that \\emph{convergence}  of a sequence of operators \n  $(A_n)_{n\\in \\N} \\subset \\blinOps(\\hilbertH)$ in the \\emph{strong operator topology} to some $A $ means \n  that for every $v\\in \\hilbertH$ the sequence $(A_nv)_{n\\in\\N}$ converges in $\\hilbertH$ to $Av$. \n  One denotes this by $A =\\strong\\lim\\limits_{n\\to\\infty} A_n$. \n  Likewise, $B = \\strong\\sum\\limits_{n=0}^\\infty A_n$ means that the sequence of partial sums \n  $\\left( \\sum\\limits_{k=0}^n A_n \\right)_{n\\in \\N}$ converges  in the strong operator topology \n  to some $B  \\in \\blinOps (\\hilbertH)$.\n\\end{remark}\n\n\\begin{proposition}\n  A spectral measure $E : \\mathscr{A} \\to \\blinOps (\\hilbertH)$   has the following properties\n  in addition to the defining axioms:\n  \\begin{axiomlist}[SM]\\setcounter{enumi}{1}\n  \\item[\\textup{{\\sffamily (SM1')}}\\hspace{-1mm}]\\itemlabel{ite:spectral-measure-empty-set}\n     $E(\\emptyset) = 0$.\n  \\item[\\textup{{\\sffamily (SM2')}}\\hspace{-1mm}]\\itemlabel{ite:spectral-measure-finite-additivity}\n     \\textup{(Finite additivity)}  One has for all disjoint $\\Delta_1,\\Delta_2 \\in \\mathscr{A}$\n      \\[ E( \\Delta_1  \\cup \\Delta_2) = E(\\Delta_1) + E(\\Delta_2) \\ . \\]\n  \\setcounter{enumi}{2}\n  \\item\\label{ite:spectral-measure-finite-multiplicativity}\n     One has for all $\\Delta_1,\\Delta_2 \\in \\mathscr{A}$ \n     \\[ E( \\Delta_1  \\cap \\Delta_2) = E(\\Delta_1)\\cdot E(\\Delta_2) \\ . \\]\n  \\end{axiomlist}\n\\end{proposition}\n\n\\begin{proof}\n  {\\itshape ad} \\hyperref[ite:spectral-measure-empty-set]{\\textup{\\sffamily (SM1')}}.\n\n  {\\itshape ad} \\hyperref[ite:spectral-measure-finite-additivity]{\\textup{\\sffamily (SM2')}}.\n\n  {\\itshape ad} \\ref{ite:spectral-measure-finite-multiplicativity}.\n\\end{proof}\n\n", "meta": {"hexsha": "35e7ed7408565c1546b7ae57a60e9bdf23404651", "size": 2774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/projection-valued-measures-spectral-integrals.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/projection-valued-measures-spectral-integrals.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/projection-valued-measures-spectral-integrals.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": 47.8275862069, "max_line_length": 106, "alphanum_fraction": 0.6780821918, "num_tokens": 967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6214685284451541}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=2cm]{geometry}\n\\usepackage{amsmath}\n\n\\title{Fermion Operators}\n\\date{}\n\\author{}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Anticommutation}\nConsider the following eigenstates of a hypothetical quantum system.\\footnote{\nAdapted from problem 16.1.1 of ``Quantum Mechanics for Scientists and Engineers.''\\\\\n{\\tt https://ee.stanford.edu/{\\textasciitilde}dabm/QMbook.html}}\n\\begin{align*}\n|00\\rangle&=(\\text{1 0 0 0})\\qquad\\text{no fermions}\\\\\n|10\\rangle&=(\\text{0 1 0 0})\\qquad\\text{one fermion in state 1}\\\\\n|01\\rangle&=(\\text{0 0 1 0})\\qquad\\text{one fermion in state 2}\\\\\n|11\\rangle&=(\\text{0 0 0 1})\\qquad\\text{two fermions, one in state 1, one in state 2}\n\\end{align*}\n\n\\noindent\nCreation and annihilation operators are formed from outer products of state vectors.\nSign changes make the operators antisymmetric.\n\\begin{align*}\n\\hat{b}_1^\\dag&=|10\\rangle\\langle00|-|11\\rangle\\langle01| \\qquad\\text{Create one fermion in state 1}\n\\\\\n\\hat{b}_1&=|00\\rangle\\langle10|-|01\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state 1}\n\\\\\n\\hat{b}_2^\\dag&=|01\\rangle\\langle00|+|11\\rangle\\langle10| \\qquad\\text{Create one fermion in state 2}\n\\\\\n\\hat{b}_2&=|00\\rangle\\langle01|+|10\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state 2}\n\\end{align*}\n\n\\noindent\nThe operators in matrix form.\n\\begin{equation*}\n\\hat{b}_1^\\dag=\\begin{pmatrix}0&0&0&0\\\\1&0&0&0\\\\0&0&0&0\\\\0&0&-1&0\\end{pmatrix}\n\\quad\n\\hat{b}_1=\\begin{pmatrix}0&1&0&0\\\\0&0&0&0\\\\0&0&0&-1\\\\0&0&0&0\\end{pmatrix}\n\\quad\n\\hat{b}_2^\\dag=\\begin{pmatrix}0&0&0&0\\\\0&0&0&0\\\\1&0&0&0\\\\0&1&0&0\\end{pmatrix}\n\\quad\n\\hat{b}_2=\\begin{pmatrix}0&0&1&0\\\\0&0&0&1\\\\0&0&0&0\\\\0&0&0&0\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nVerify anticommutation relations of the operators.\n\\begin{align*}\n\\hat{b}_j\\hat{b}_k+\\hat{b}_k\\hat{b}_j&=0\n\\\\[2ex]\n\\hat{b}_j^\\dag\\hat{b}_k^\\dag+\\hat{b}_k^\\dag\\hat{b}_j^\\dag&=0\n\\\\[2ex]\n\\hat{b}_j\\hat{b}_k^\\dag+\\hat{b}_k^\\dag\\hat{b}_j&=\\delta_{jk}\n\\end{align*}\n\n\\newpage\n\n\\section{Wavefunction operator}\nConsider the following eigenstates of a hypothetical quantum system.\\footnote{\nAdapted from problem 16.2.1 of ``Quantum Mechanics for Scientists and Engineers.''\\\\\n{\\tt https://ee.stanford.edu/{\\textasciitilde}dabm/QMbook.html}}\n\\begin{align*}\n|00\\rangle&=(\\text{1 0 0 0})\\qquad\\text{no fermions}\\\\\n|10\\rangle&=(\\text{0 1 0 0})\\qquad\\text{one fermion in state $\\phi_1$}\\\\\n|01\\rangle&=(\\text{0 0 1 0})\\qquad\\text{one fermion in state $\\phi_2$}\\\\\n|11\\rangle&=(\\text{0 0 0 1})\\qquad\\text{two fermions, one in state $\\phi_1$, one in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nLet fermion states $\\phi_n$ be modeled by a one dimensional box of length $L$.\n\\begin{equation*}\n\\phi_n(x)=\\sqrt{\\frac{2}{L}}\\sin\\left(\\frac{n\\pi x}{L}\\right)\n\\end{equation*}\n\n\\noindent\nCreation and annihilation operators are formed from outer products of state vectors.\nSign changes make the operators antisymmetric.\n\\begin{align*}\n\\hat{b}_1^\\dag&=|10\\rangle\\langle00|-|11\\rangle\\langle01| \\qquad\\text{Create one fermion in state $\\phi_1$}\n\\\\\n\\hat{b}_1&=|00\\rangle\\langle10|-|01\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state $\\phi_1$}\n\\\\\n\\hat{b}_2^\\dag&=|01\\rangle\\langle00|+|11\\rangle\\langle10| \\qquad\\text{Create one fermion in state $\\phi_2$}\n\\\\\n\\hat{b}_2&=|00\\rangle\\langle01|+|10\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nGiven the wavefunction operator\n\\begin{equation*}\n\\hat{\\psi}=\\frac{1}{\\sqrt{2}}\\sum_{n,m}\\phi_n(x)\\phi_m(y)\\hat{b}_n\\hat{b}_m\n\\end{equation*}\n\n\\noindent\nshow that\n\\begin{equation*}\n\\hat{\\psi}|11\\rangle=\\frac{1}{\\sqrt{2}}\\big(\\phi_1(x)\\phi_2(y)-\\phi_1(y)\\phi_2(x)\\big)|00\\rangle\n\\end{equation*}\n\n\\newpage\n\n\\section{Position operator}\nConsider the following eigenstates of a hypothetical quantum system.\n\\begin{align*}\n|00\\rangle&=(\\text{1 0 0 0})\\qquad\\text{no fermions}\\\\\n|10\\rangle&=(\\text{0 1 0 0})\\qquad\\text{one fermion in state $\\phi_1$}\\\\\n|01\\rangle&=(\\text{0 0 1 0})\\qquad\\text{one fermion in state $\\phi_2$}\\\\\n|11\\rangle&=(\\text{0 0 0 1})\\qquad\\text{two fermions, one in state $\\phi_1$, one in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nLet fermion states $\\phi_n$ be modeled by a one dimensional box of length $L$.\n\\begin{equation*}\n\\phi_n(x)=\\sqrt{\\frac{2}{L}}\\sin\\left(\\frac{n\\pi x}{L}\\right)\n\\end{equation*}\n\n\\noindent\nCreation and annihilation operators are formed from outer products of state vectors.\nSign changes make the operators antisymmetric.\n\\begin{align*}\n\\hat{b}_1^\\dag&=|10\\rangle\\langle00|-|11\\rangle\\langle01| \\qquad\\text{Create one fermion in state $\\phi_1$}\n\\\\\n\\hat{b}_1&=|00\\rangle\\langle10|-|01\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state $\\phi_1$}\n\\\\\n\\hat{b}_2^\\dag&=|01\\rangle\\langle00|+|11\\rangle\\langle10| \\qquad\\text{Create one fermion in state $\\phi_2$}\n\\\\\n\\hat{b}_2&=|00\\rangle\\langle01|+|10\\rangle\\langle11| \\qquad\\text{Annihilate one fermion in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nLet $\\hat{r}$ be the position operator\n\\begin{equation*}\n\\hat{r}=\\sum_{n,m}r_{nm}\\hat{b}_n^\\dag\\hat{b}_m\n\\end{equation*}\n\n\\noindent\nwhere\n\\begin{equation*}\nr_{nm}=\\int_0^L\\phi_n^*(x)x\\phi_m(x)\\,dx\n\\end{equation*}\n\n\\noindent\nNote that for a one dimensional box\n\\begin{equation*}\nr_{nn}=\\langle x\\rangle=\\tfrac{1}{2}L\n\\end{equation*}\n\n\\noindent\nVerify that\n\\begin{align*}\n\\langle10|\\hat{r}|10\\rangle&=r_{11}\\\\\n\\langle10|\\hat{r}|01\\rangle&=r_{12}\\\\\n\\langle01|\\hat{r}|10\\rangle&=r_{21}\\\\\n\\langle01|\\hat{r}|01\\rangle&=r_{22}\n\\end{align*}\n\n\\newpage\n\n\\section{Exchange energy}\nLet $\\psi(x,y)$ be the antisymmetrized wave function for two electrons in a box of length $L$.\n\\begin{align*}\n\\psi(x,y)&=\\frac{1}{\\sqrt{2}}\n\\big(\\phi_1(x)\\phi_2(y)-\\phi_1(y)\\phi_2(x)\\big)\n\\\\[2ex]\n\\phi_n(x)&=\\sqrt{\\frac{2}{L}}\\sin\\left(\\frac{n\\pi x}{L}\\right)\n\\end{align*}\n\n\\noindent\nFor $L=10^{-9}$ meter the expected potential energy is\n\\begin{equation*}\nV=\\frac{e^2}{4\\pi\\epsilon_0}\\int_0^L\\int_0^L\\frac{\\psi^*(x,y)\\psi(x,y)}{|x-y|}\\,dx\\,dy\n=4.67\\,\\text{eV}\n\\end{equation*}\n\n\\noindent\nNext calculate the potential energy for a wave function that is not antisymmetrized.\n\\begin{equation*}\nV_0=\\frac{e^2}{4\\pi\\epsilon_0}\n\\int_0^L\\int_0^L\\frac{\\phi_1^*(x)\\phi_2^*(y)\\phi_1(x)\\phi_2(y)}{|x-y|}\\,dx\\,dy\n=12.80\\,\\text{eV}\n\\end{equation*}\n\n\\noindent\nThe difference is the exchange energy.\n\\begin{equation*}\nV_{ex}=V-V_0=-8.13\\,\\text{eV}\n\\end{equation*}\n\n\\noindent\nNote that the formula for $V_0$ has a singularity at $x=y$.\nThe computed value shown above is the result of an arbitrary cutoff in numerical integration.\nThe actual value of $V_0$ goes to infinity.\n\n\\bigskip\n\\noindent\nNote also that there is a singularity at $x=y$ in the formula for $V$.\nHowever, due to antisymmetry we have $\\psi(x,x)=0$ and hence the integral converges.\n\n\\newpage\n\n\\section{Energy matrix}\nConsider a system with the following eigenstates.\n\\begin{align*}\n|0\\rangle&=(\\text{1 0 0 0})\\qquad\\text{no electrons}\\\\\n|1\\rangle&=(\\text{0 1 0 0})\\qquad\\text{one electron in state $\\phi_1$}\\\\\n|2\\rangle&=(\\text{0 0 1 0})\\qquad\\text{one electron in state $\\phi_2$}\\\\\n|3\\rangle&=(\\text{0 0 0 1})\\qquad\\text{two electrons, one in state $\\phi_1$, one in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nLet electron states $\\phi_n$ be modeled by a one dimensional box of length $L$.\n\\begin{equation*}\n\\phi_n(x)=\\sqrt{\\frac{2}{L}}\\sin\\left(\\frac{n\\pi x}{L}\\right)\n\\end{equation*}\n\n\\noindent\nLet $|\\xi\\rangle$ be an arbitrary normalized state vector.\n\\begin{equation*}\n|\\xi\\rangle=c_0|0\\rangle+c_1|1\\rangle+c_2|2\\rangle+c_3|3\\rangle,\\qquad\\langle\\xi|\\xi\\rangle=1\n\\end{equation*}\n\n\\noindent\nLet us determine an energy matrix $\\hat{E}$ such that the expected\nenergy $\\langle E \\rangle$ in state $|\\xi\\rangle$ is\n\\begin{equation*}\n\\langle E\\rangle=\\langle\\xi|\\hat{E}|\\xi\\rangle\n\\end{equation*}\n\n\\noindent\nEnergy matrix $\\hat{E}$ is the sum of kinetic and potential energy matrices.\n\\begin{equation*}\n\\hat{E}=\\hat{K}+\\hat{V}\n\\end{equation*}\n\n\\noindent\nKinetic energy matrix $\\hat{K}$ can be computed from energy eigenvalues of the box model.\n\\begin{equation*}\n\\hat{K}=\\begin{pmatrix}\n0 & 0 & 0 & 0\\\\\n0 & E_1 & 0 & 0\\\\\n0 & 0 & E_2 & 0\\\\\n0 & 0 & 0 & E_1+E_2\n\\end{pmatrix},\n\\qquad\nE_n=\\frac{n^2\\pi^2\\hbar^2}{2mL^2}\n\\end{equation*}\n\n\\noindent\nPotential energy matrix $\\hat{V}$ has one entry due to Coulomb interaction in the two electron state.\n\\begin{equation*}\n\\hat{V}=\n\\begin{pmatrix}\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & V\n\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nLet $\\psi(x,y)$ be the antisymmetrized wavefunction of the two electrons.\n\\begin{equation*}\n\\psi(x,y)=\\frac{1}{\\sqrt{2}}\\big(\\phi_1(x)\\phi_2(y)-\\phi_1(y)\\phi_2(x)\\big)\n\\end{equation*}\n\n\\noindent\nThen\n\\begin{equation*}\nV=\\frac{e^2}{4\\pi\\epsilon_0}\\int_0^L\\int_0^L\n\\psi^*(x,y)\\left(\\frac{1}{|x-y|}\\right)\\psi(x,y)\\,dx\\,dy\n\\end{equation*}\n\n\\noindent\nLet us now choose $L=10^{-9}$ meters and compute numerical values.\nFor $\\hat{K}$ we have\n\\begin{equation*}\n\\hat{K}=\\begin{pmatrix}\n0 & 0 & 0 & 0\\\\\n0 & 0.38\\,\\text{eV} & 0 & 0\\\\\n0 & 0 & 1.50\\,\\text{eV} & 0\\\\\n0 & 0 & 0 & 1.88\\,\\text{eV}\n\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nComputing $V$ by numerical integration we have\n\\begin{equation*}\n\\hat{V}=\\begin{pmatrix}\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 4.67\\,\\text{eV}\n\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nHence\n\\begin{equation*}\n\\hat{E}=\\hat{K}+\\hat{V}=\\begin{pmatrix}\n0 & 0 & 0 & 0\\\\\n0 & 0.38\\,\\text{eV} & 0 & 0\\\\\n0 & 0 & 1.50\\,\\text{eV} & 0\\\\\n0 & 0 & 0 & 6.55\\,\\text{eV}\n\\end{pmatrix}\n\\end{equation*}\n\n\\newpage\n\n\\section{Superposition of eigenstates}\nConsider a system with the following eigenstates.\n\\begin{align*}\n|0\\rangle&=(\\text{1 0 0 0})\\qquad\\text{no electrons}\\\\\n|1\\rangle&=(\\text{0 1 0 0})\\qquad\\text{one electron in state $\\phi_1$}\\\\\n|2\\rangle&=(\\text{0 0 1 0})\\qquad\\text{one electron in state $\\phi_2$}\\\\\n|3\\rangle&=(\\text{0 0 0 1})\\qquad\\text{two electrons, one in state $\\phi_1$, one in state $\\phi_2$}\n\\end{align*}\n\n\\noindent\nThen for the wavefunction basis\n\\begin{equation*}\n\\phi_n(x)=\\sqrt{\\frac{2}{L}}\\sin\\left(\\frac{n\\pi x}{L}\\right)\n\\end{equation*}\n\n\\noindent\nand for $L=10^{-9}$ meters we have\n\\begin{equation*}\n\\hat{E}=\\begin{pmatrix}\n0&0&0&0\\\\\n0&0.38\\,\\text{eV}&0&0\\\\\n0&0&1.50\\,\\text{eV}&0\\\\\n0&0&0&6.55\\,\\text{eV}\n\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nLet $|\\xi\\rangle$ be the state vector\n\\begin{equation*}\n|\\xi\\rangle\n=\\frac{1}{2}|0\\rangle+\\frac{1}{2}|1\\rangle+\\frac{1}{2}|2\\rangle+\\frac{1}{2}|3\\rangle\n=\\begin{pmatrix}1/2\\\\1/2\\\\1/2\\\\1/2\\end{pmatrix}\n\\end{equation*}\n\n\\noindent\nThe expected energy is\n\\begin{equation*}\n\\langle\\xi|\\hat{E}|\\xi\\rangle\n=\\frac{0\\,\\text{eV}}{4}+\\frac{0.38\\,\\text{eV}}{4}+\\frac{1.50\\,\\text{eV}}{4}+\\frac{6.55\\,\\text{eV}}{4}\n=2.11\\,\\text{eV}\n\\end{equation*}\n\n\\noindent\nFor the system we are considering, the result of a single measurement is either\n0~eV, 0.38~eV, 1.50~eV, or 6.55~eV.\n%The probability of observing each eigenvalue is 0.25 when the system is in state $|\\xi\\rangle$.\nThe value 2.11 eV is the expected average across multiple measurements.\nRecall that a measurement causes the system to exit state $|\\xi\\rangle$\nand enter an eigenstate $|0\\rangle$, $|1\\rangle$, $|2\\rangle$, or $|3\\rangle$\ncorresponding to the measured eigenvalue.\nThe system must be put back in state $|\\xi\\rangle$ before the next measurement.\n\n\\bigskip\n\\noindent\nTo use a slot machine analogy, state $|\\xi\\rangle$ is like the wheels spinning.\nObserving the system makes the wheels stop.\nThe stopped wheels are in an eigenstate $|0\\rangle$, $|1\\rangle$, $|2\\rangle$, or $|3\\rangle$.\nOnce they are stopped the wheels don't change, they remain in the same eigenstate.\nYou have to pull the lever to get the wheels spinning again.\n\n\\end{document}\n", "meta": {"hexsha": "15f905db09a8151ca652383dbd98d2b181388089", "size": 11650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fermion-operators.tex", "max_stars_repo_name": "georgeweigt/georgeweigt.github.io", "max_stars_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "fermion-operators.tex", "max_issues_repo_name": "georgeweigt/georgeweigt.github.io", "max_issues_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": "fermion-operators.tex", "max_forks_repo_name": "georgeweigt/georgeweigt.github.io", "max_forks_repo_head_hexsha": "94fc6dfbc8dee95cca58c9822533699e8ed79a51", "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": 30.9018567639, "max_line_length": 107, "alphanum_fraction": 0.6905579399, "num_tokens": 4693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6214685270009824}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage[UKenglish]{babel}\n\\usepackage{enumitem}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{graphicx}\n\\usepackage[utf8]{inputenc}\n\\usepackage{stmaryrd}\n\n\\newtheorem{n}{}\n\n\\theoremstyle{plain}\n\\newtheorem{corollary}[n]{Corollary}\n\\newtheorem{lemma}[n]{Lemma}\n\\newtheorem{proposition}[n]{Proposition}\n\\newtheorem{theorem}[n]{Theorem}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}[n]{Definition}\n\\newtheorem{remark}[n]{Remark}\n\n\\newcommand{\\function}[5][]{\n  \\begin{array}{crcl}\n    #1 : & #2 & \\to     & #3 \\\\\n         & #4 & \\mapsto & #5\n  \\end{array}\n}\n\n\\newcommand{\\ab}[1]{\\left\\langle #1 \\right\\rangle}\n\\newcommand{\\rb}[1]{\\left( #1 \\right)}\n\\renewcommand{\\sb}[1]{\\left[ #1 \\right]}\n\\newcommand{\\cb}[1]{\\left\\{ #1 \\right\\}}\n\n\\renewcommand{\\P}{\\mathbb{P}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\N}{\\mathbb{N}}\n\n\\renewcommand{\\AA}{\\mathcal{A}}\n\\newcommand{\\II}{\\mathcal{I}}\n\\newcommand{\\LL}{\\mathcal{L}}\n\\newcommand{\\OO}{\\mathcal{O}}\n\\newcommand{\\PP}{\\mathcal{P}}\n\n\\title{Group law}\n\\author{David Kurniadi Angdinata}\n\\date{Winter 2019}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Statement}\n\nLet $ K $ be an algebraically closed field and let $ E $ be an \\emph{elliptic curve} over $ K $ defined by the \\emph{Weierstrass equation}\n$$ E : y^2 = x^3 + Ax + B, \\qquad A, B \\in K, $$\nin \\emph{dehomogenised} form. Then the following theorem holds.\n\n\\begin{theorem}[Group law]\n\\label{thm:grouplaw}\n$ \\rb{E, \\OO, +} $ is an abelian group.\n\\end{theorem}\n\nRather than providing the conventional geometric proof using \\emph{B\\'ezout's theorem} and \\emph{the Cayley-Bacharach theorem}, this algebraic proof using the theory of \\emph{divisors} establishes Theorem \\ref{thm:grouplaw} more naturally.\n\n\\section{Restatement}\n\nLet the \\emph{coordinate ring} $ R $ of $ E $ be\n$$ R = \\dfrac{K\\sb{x, y}}{I}, $$\nwhere $ I $ is the ideal generated by the Weierstrass equation of $ E $,\n$$ I = \\ab{y^2 - x^3 - Ax - B}. $$\nLet $ \\AA\\rb{R} $ be the \\emph{ideal class group} of $ R $, defined as the quotient\n$$ \\AA\\rb{R} = \\dfrac{\\II\\rb{R}}{\\PP\\rb{R}}, $$\nwhere $ \\II\\rb{R} $ is the group of \\emph{fractional ideals} of $ R $ and $ \\PP\\rb{R} $ is the subgroup of \\emph{principal fractional ideals} of $ R $.\n\n\\begin{definition}\n\\label{def:picard}\nThe \\textbf{Picard group} of $ E $ is\n$$ Pic^0\\rb{E} = \\AA\\rb{R}. $$\n\\end{definition}\n\n\\begin{remark}\nStrictly speaking, Definition \\ref{def:picard} is that of the \\emph{degree zero} subgroup of the actual \\emph{Picard group}, but this terminology will be used for the sake of brevity.\n\\end{remark}\n\nIt is then sufficient to prove the following theorem, which implies Theorem \\ref{thm:grouplaw}.\n\n\\begin{theorem}\n\\label{thm:bijection}\nThere is a set bijection\n$$ Pic^0\\rb{E} \\leftrightarrow E. $$\n\\end{theorem}\n\nIn fact, the following stronger theorem will be proven as well, assuming the geometric group law.\n\n\\begin{theorem}\n\\label{thm:isomorphism}\nThere is a group isomorphism\n$$ Pic^0\\rb{E} \\cong E. $$\n\\end{theorem}\n\nThe proof involves defining $ Pic^0\\rb{E} $ in detail, which requires the notion of a \\emph{divisor} of $ E $.\n\n\\pagebreak\n\n\\section{Divisors}\n\nA \\emph{divisor} is defined as follows.\n\n\\begin{definition}\n\\label{def:divisor}\nA \\textbf{divisor} of $ E $ is a free abelian group generated by a finite basis $ C \\subseteq E $ of formal symbols of the form $ \\sb{P} $ for some point $ P \\in E $, denoted\n$$ D = \\sum_{P \\in C} n_P\\sb{P}, $$\nfor some $ n_P \\in \\Z $.\n\\end{definition}\n\nIt can be easily shown that the set of divisors forms an additive group $ Div\\rb{E} $, called the \\textbf{divisor group} of $ E $. Let $ D, D' \\in Div\\rb{E} $ be divisors as in Definition \\ref{def:divisor} throughout.\n\n\\begin{definition}\nThe \\textbf{degree} of $ D $ is\n$$ \\deg\\rb{D} = \\sum_{P \\in C} n_P \\in \\Z. $$\n\\end{definition}\n\nIt follows easily that the set of divisors of $ E $ of degree zero forms a subgroup $ Div^0\\rb{E} $ of $ Div\\rb{E} $, which is precisely the group of fractional ideals $ \\II\\rb{R} $. Now divisors can also be defined for \\emph{functions} $ f \\in K\\rb{E}^* $. Let $ P \\in E $ be a point throughout. With some commutative algebra, it can be shown that there is a function $ u_P \\in K\\rb{E}^* $ that is zero at $ P $, called the \\textbf{uniformiser} at $ P $, such that any other function $ f \\in K\\rb{E}^* $ can be written in the form $ f \\equiv u_P^{d_P}g $, for some $ d_P \\in \\Z $, and some function $ g \\in K\\rb{E}^* $ such that $ g\\rb{P} \\notin \\cb{0, \\infty} $. In fact, it can be shown that simply choosing\n$$ u_P =\n\\begin{cases}\nx - a & P = \\rb{a, b} \\\\\ny & P = \\rb{a, 0} \\\\\n\\tfrac{x}{y} & P = \\OO\n\\end{cases}\n$$\nworks as a uniformiser at $ P $.\n\n\\begin{remark}\nThe functions $ f, g, u_P \\in K\\rb{E}^* $ must take values in $ K \\cup \\cb{\\infty} $.\n\\end{remark}\n\nThe \\textbf{valuation} of $ f $ at $ P $ is\n$$ ord_P\\rb{f} = d_P \\in \\Z. $$\nThen $ f $ has a \\textbf{zero} at $ P $ if $ ord\\rb{P} > 0 $, which corresponds to the multiplicity of $ f\\rb{P} = 0 $. Similarly, $ f $ has a \\textbf{pole} at $ P $ if $ ord\\rb{P} < 0 $, which corresponds to the multiplicity of $ f\\rb{P} = \\infty $. With some algebraic geometry, the following proposition can be shown.\n\n\\begin{proposition}\n\\label{prop:ag}\n\\hfill\n\\begin{itemize}\n\\item $ f $ has only finitely many zeroes and poles, that is $ ord_P\\rb{f} \\ne 0 $ for only finitely many points $ P \\in E $.\n\\item $ f $ has an equal number of zeroes and poles counted with multiplicity, that is $ \\deg\\rb{div\\rb{f}} = 0 $.\n\\item if $ f $ has no zeroes or poles, that is $ div\\rb{f} = 0 $, then $ f $ is constant.\n\\end{itemize}\n\\end{proposition}\n\nThe following definition is then well-defined.\n\n\\begin{definition}\n$ D $ is \\textbf{principal} if\n$$ D = div\\rb{f} = \\sum_{P \\in E} ord_P\\rb{f}\\sb{P}, $$\nfor some function $ f \\in K\\rb{E}^* $.\n\\end{definition}\n\nIt follows that the subset of principal divisors of $ E $ forms a subgroup $ Prin\\rb{E} $ of $ Div^0\\rb{E} $, which is precisely the subgroup of principal fractional ideals $ \\PP\\rb{R} $. Definition \\ref{def:picard} can now be restated as\n$$ Pic^0\\rb{E} = \\dfrac{Div^0\\rb{E}}{Prin\\rb{E}}. $$\nAlternatively, $ Pic^0\\rb{E} $ can also be thought of as $ Div^0\\rb{E} $ modulo an equivalence relation $ \\sim $, where\n$$ D \\sim D' \\qquad \\iff \\qquad D - D' \\ \\text{is principal}. $$\n\n\\pagebreak\n\n\\section{The Riemann-Roch theorem}\n\nBefore proceeding to the proof in the next section, a fundamental result in algebraic geometry concerning divisors will be stated in this section in its full generality. Although it is possible to complete the proof without this theorem, its statement allows for a simpler argument. Let $ C $ be an algebraic curve throughout. The notion of a \\emph{divisor} $ D \\in Div\\rb{C} $ and the results that follow can be defined analogously. Now let $ \\le $ be a partial order on $ Div\\rb{C} $ defined by\n$$ \\sum_{P \\in C} n_P\\sb{P} \\le \\sum_{P' \\in C'} n'_{P'}\\sb{P'} \\qquad \\iff \\qquad \\forall P \\in C \\cup C', \\ n_P \\le n'_{P'}. $$\nFor any divisor $ D \\in Div\\rb{C} $, define a finite-dimensional $ K $-vector space of functions by\n$$ \\LL\\rb{D} = \\cb{f \\in K\\rb{C}^* \\mid div\\rb{f} \\ge -D} \\cup \\cb{0}, $$\ndenoting its dimension as\n$$ l\\rb{D} = \\dim_K\\rb{\\LL\\rb{D}}. $$\nThe theorem can then be stated as follows.\n\n\\begin{theorem}[Riemann-Roch]\n\\label{thm:riemannroch}\nLet $ D \\in Div\\rb{C} $ be a divisor. There is a divisor $ K_C \\in Div\\rb{C} $ such that\n$$ l\\rb{D} - l\\rb{K_C - D} = \\deg\\rb{D} - g_C + 1, $$\nwhere $ g_C $ is the genus of $ C $.\n\\end{theorem}\n\n\\begin{remark}\nThe divisor $ K_C $ in Theorem \\ref{thm:riemannroch} is called a \\emph{canonical divisor}. It is the divisor $ div\\rb{\\omega} $ of some \\emph{meromorphic differential} $ \\omega $ in the \\emph{$ K\\rb{C} $-vector space of meromorphic differential forms} $ \\Omega_C $. In turn, it is a divisor of the \\emph{canonical divisor class} subgroup $ div\\rb{\\Omega_C} $ of $ Pic\\rb{C} $.\n\\end{remark}\n\nThe proof of Theorem \\ref{thm:riemannroch} can be found in basic algebraic geometry books. Fortunately, the argument in the next section does not require formally defining $ K_C $, leaving the following corollary sufficient for purposes of the proof.\n\n\\begin{corollary}[Roch]\n\\label{thm:roch}\nLet $ D \\in Div\\rb{C} $ be a divisor such that $ \\deg\\rb{D} > 2g_C - 2 $. Then\n$$ l\\rb{D} = \\deg\\rb{D} - g_C + 1. $$\nFurthermore, if $ C = E $ and $ \\deg\\rb{D} > 0 $, then\n$$ l\\rb{D} = \\deg\\rb{D}. $$\n\\end{corollary}\n\n\\begin{proof}\nLet $ f \\in \\LL\\rb{0}^* $ be a function, so\n$$ div\\rb{f} = \\sum_{P \\in C} n_P\\sb{P}, $$\nfor some finite basis $ C \\subseteq E $, and some $ n_P \\in \\Z $. Then $ div\\rb{f} \\ge 0 $, so $ n_P \\ge 0 $ for all $ P \\in C $. Since $ \\deg\\rb{div\\rb{f}} = 0 $, it holds that $ n_P = 0 $ for all $ P \\in C $, so $ div\\rb{f} = 0 $. Proposition \\ref{prop:ag} gives that $ f $ is constant, so $ \\LL\\rb{0} = K $. Hence $ l\\rb{0} = 1 $, so letting $ D = 0 $ in Theorem \\ref{thm:riemannroch} gives\n$$ l\\rb{0} - l\\rb{K_C - 0} = \\deg\\rb{0} - g_C + 1 \\qquad \\implies \\qquad l\\rb{K_C} = g_C. $$\nSimilarly, letting $ D = K_C $ in Theorem \\ref{thm:riemannroch} gives\n$$ l\\rb{K_C} - l\\rb{K_C - K_C} = \\deg\\rb{K_C} - g_C + 1 \\qquad \\implies \\qquad \\deg\\rb{K_C} = 2g_C - 2. $$\nNow let $ D $ be the given divisor. If $ l\\rb{K_C - D} \\ne 0 $, then let $ f \\in \\LL\\rb{K_C - D}^* $ be a function, so $ div\\rb{f} \\ge K_C - D $. Then\n$$ 0 = \\deg\\rb{div\\rb{f}} \\ge \\deg\\rb{K_C - D} = \\deg\\rb{K_C} - \\deg\\rb{D} < \\rb{2g_C - 2} - \\rb{2g_C - 2} = 0, $$\nwhich is a contradiction. Hence $ l\\rb{K_C - D} = 0 $. Thus Theorem \\ref{thm:riemannroch} gives\n$$ l\\rb{D} = \\deg\\rb{D} - g_C + 1. $$\nThe final part follows by virtue of the genus $ g_E = 1 $ of elliptic curves.\n\\end{proof}\n\n\\section{Summation}\n\nThe required bijection is defined as follows.\n\n\\begin{definition}\nLet $ D \\in Div\\rb{E} $ be a divisor as in Definition \\ref{def:divisor}. Then the \\textbf{sum} of $ D $ is\n$$ sum\\rb{D} = \\sum_{P \\in C} n_PP \\in E. $$\nDefine the \\textbf{summation} map as the restriction of $ sum $ onto the subgroup $ Div^0\\rb{E} $,\n$$ \\function[\\sigma]{Div^0\\rb{E}}{E}{\\sum_{P \\in C} n_P\\sb{P}}{\\sum_{P \\in C} n_PP}, $$\nand denote its inverse by\n$$ \\function[\\kappa]{E}{Div^0\\rb{E}}{P}{\\sb{P} - \\sb{\\OO}}. $$\n\\end{definition}\n\nWith the first isomorphism theorem, Theorem \\ref{thm:bijection} is equivalent to the following two propositions and an application of forgetful functors.\n\n\\begin{proposition}\n\\label{prop:image}\n$ Im\\rb{\\sigma} = E $.\n\\end{proposition}\n\nProposition \\ref{prop:image} is practically trivial, considering $ \\kappa $.\n\n\\begin{proof}\nIt is sufficient to verify that $ \\kappa $ is well-defined. Let $ P \\in E $ be a point. Then $ \\deg\\rb{\\sb{P} - \\sb{\\OO}} = 1 - 1 = 0 $, so $ \\sb{P} - \\sb{\\OO} \\in Div^0\\rb{E} $. Now $ \\sigma\\rb{\\sb{P} - \\sb{\\OO}} = P - \\OO = P $, so $ P \\in Im\\rb{E} $. Hence $ E \\subseteq Im\\rb{E} \\subseteq E $. Thus $ Im\\rb{\\sigma} = E $.\n\\end{proof}\n\n\\begin{proposition}\n\\label{prop:kernel}\n$ Ker\\rb{\\sigma} = Prin\\rb{E} $.\n\\end{proposition}\n\nProposition \\ref{prop:kernel} requires more work, starting with the following lemma that utilises Theorem \\ref{thm:roch}.\n\n\\begin{lemma}\nLet $ P, Q \\in E $ be points. Then\n$$ P = Q \\qquad \\iff \\qquad \\sb{P} \\sim \\sb{Q}. $$\n\\end{lemma}\n\n\\begin{proof}\nThe forward direction is clear. Conversely, assume that $ \\sb{P} \\sim \\sb{Q} $. Then there is some function $ f \\in K\\rb{E}^* $ such that $ div\\rb{f} = \\sb{P} - \\sb{Q} $, so $ f \\in \\LL\\rb{\\sb{Q}} $. Hence Theorem \\ref{thm:roch} gives\n$$ l\\rb{\\sb{Q}} = \\deg\\rb{\\sb{Q}} = 1, $$\nso $ f $ is constant. Thus $ P - Q = \\OO $, so $ P = Q $.\n\\end{proof}\n\nThe following lemma relates the group law definition with linear equivalence of divisors.\n\n\\begin{lemma}\nLet $ P, Q \\in E $ be points. Then\n$$ \\sb{P} + \\sb{Q} \\sim \\sb{P + Q} + \\sb{\\OO}. $$\n\\end{lemma}\n\n\\begin{proof}\nLet $ L : f\\rb{x, y} = 0 $ be the unique line through $ P $, $ Q $, and $ -\\rb{P + Q} $. Then $ f $ has exactly three zeroes at these points. Since $ \\deg\\rb{div\\rb{f}} = 0 $ and $ f $ has no affine poles, it holds that $ f $ has exactly one triple pole at $ \\OO $. Hence\n$$ div\\rb{f} = \\sb{P} + \\sb{Q} + \\sb{-\\rb{P + Q}} - 3\\sb{\\OO}. $$\nNow let $ L' : g\\rb{x, y} = 0 $ be the unique line through $ P + Q $, $ -\\rb{P + Q} $, and $ \\OO $. Similarly,\n$$ div\\rb{g} = \\sb{P + Q} + \\sb{-\\rb{P + Q}} - 2\\sb{\\OO}. $$\nHence\n$$ div\\rb{\\dfrac{f}{g}} = div\\rb{f} - div\\rb{g} = \\sb{P} + \\sb{Q} - \\sb{P + Q} - \\sb{\\OO}. $$\nThus\n$$ \\sb{P} + \\sb{Q} \\sim \\sb{P + Q} + \\sb{\\OO}. $$\n\\end{proof}\n\nThe following lemma consequently hinges on this observation.\n\n\\begin{lemma}\nLet $ D \\in Div^0\\rb{E} $ be a divisor of degree zero. Then\n$$ D \\sim \\sb{P} - \\sb{Q}, \\qquad \\sigma\\rb{D} = P - Q, $$\nfor some points $ P, Q \\in E $.\n\\end{lemma}\n\n\\begin{proof}\nLet\n$$ D = \\sum_{P \\in C} n_P\\sb{P} - \\sum_{P' \\in C'} n'_{P'}\\sb{P'}, $$\nfor some finite subsets $ C, C' \\subseteq E $ such that $ C \\cup C' \\subseteq E $ is a finite basis, and some $ n_P, n'_{P'} \\in \\N $ such that\n$$ \\sum_{P \\in C} n_P - \\sum_{P' \\in C'} n'_{P'} = \\deg\\rb{D} = 0. $$\nThen for any $ P, P' \\in C $ or any $ P, P' \\in C' $,\n$$ \\sb{P} + \\sb{P'} = \\sb{P + P'} + \\sb{\\OO} + div\\rb{f}, $$\nfor some function $ f \\in K\\rb{E}^* $ such that\n$$ \\sigma\\rb{div\\rb{f}} = \\sigma\\rb{\\sb{P} + \\sb{P'} - \\sb{P + P'} + \\sb{\\OO}} = P + P' - \\rb{P + P'} + \\OO = \\OO. $$\nHence by induction,\n$$ D = \\rb{\\sb{P} + \\rb{\\sum_{P \\in C} n_P - 1}\\sb{\\OO}} - \\rb{\\sb{Q} + \\rb{\\sum_{P' \\in C'} n'_{P'} - 1}\\sb{\\OO}} + div\\rb{g} = \\sb{P} - \\sb{Q} + div\\rb{g}, $$\nfor some function $ g \\in K\\rb{E}^* $ such that $ \\sigma\\rb{div\\rb{g}} = 0 $, where\n$$ P = \\sum_{P \\in C} n_PP, \\qquad Q = \\sum_{P' \\in C'} n'_{P'}P'. $$\nThus\n$$ \\sigma\\rb{D} = \\sigma\\rb{\\sb{P} - \\sb{Q} + div\\rb{g}} = P - Q. $$\n\\end{proof}\n\n\\begin{proof}[Proof of Proposition \\ref{prop:kernel}]\nLet $ D \\in Div^0\\rb{E} $ be a divisor of degree zero. Then\n\\begin{align*}\nD \\in Ker\\rb{\\sigma} \\qquad\n& \\iff \\qquad \\sigma\\rb{D} = \\OO \\\\\n& \\iff \\qquad P = Q & \\text{for some points} \\ P, Q \\in E \\\\\n& \\iff \\qquad \\sb{P} \\sim \\sb{Q} \\\\\n& \\iff \\qquad D \\sim 0 & \\iff \\qquad D \\in Prin\\rb{E}.\n\\end{align*}\nThus $ Ker\\rb{\\sigma} = Prin\\rb{E} $.\n\\end{proof}\n\nHence Theorem \\ref{thm:bijection} follows. The observation that for any points $ P, Q, R \\in E $,\n$$ P + Q = R \\qquad \\iff \\qquad \\rb{\\sb{P} - \\sb{\\OO}} + \\rb{\\sb{Q} - \\sb{\\OO}} \\sim \\rb{\\sb{R} - \\sb{\\OO}}, $$\nis clear from the definition of $ \\kappa $. Thus Theorem \\ref{thm:isomorphism} follows as well.\n\n\\begin{remark}\nIn fact, the following fundamental \\emph{exact sequence} in algebraic number theory, applied to elliptic curves, would provide a succinct summary.\n$$ 1 \\rightarrow K^* \\xrightarrow{\\subseteq} K\\rb{E}^* \\xrightarrow{div} Div^0\\rb{E} \\xrightarrow{\\sigma} E \\cong Pic^0\\rb{E} \\rightarrow 1. $$\n\\end{remark}\n\n\\section{References}\n\n\\begin{enumerate}[label={[\\arabic*]}]\n\\item J Silverman's 1986 book \\emph{The arithmetic of elliptic curves} \\label{gtm}\n\\item L Washington's 2003 book \\emph{Elliptic curves: number theory and cryptography} \\label{ntc}\n\\item R Hartshorne's 1977 book \\emph{Algebraic geometry} \\label{ag}\n\\end{enumerate}\n\n\\end{document}", "meta": {"hexsha": "3b42d627274c1d2416600e18d72a984c32030711", "size": 15117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "group-law/GroupLaw.tex", "max_stars_repo_name": "Multramate/EllipticCurves", "max_stars_repo_head_hexsha": "f46652e975c1d7af5977fc0f2b5b845972eec63d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-04-19T17:04:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T08:58:48.000Z", "max_issues_repo_path": "group-law/GroupLaw.tex", "max_issues_repo_name": "Multramate/EllipticCurves", "max_issues_repo_head_hexsha": "f46652e975c1d7af5977fc0f2b5b845972eec63d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "group-law/GroupLaw.tex", "max_forks_repo_name": "Multramate/EllipticCurves", "max_forks_repo_head_hexsha": "f46652e975c1d7af5977fc0f2b5b845972eec63d", "max_forks_repo_licenses": ["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.8090909091, "max_line_length": 710, "alphanum_fraction": 0.6361050473, "num_tokens": 5731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6214685270009824}}
{"text": "% \\subsection{Proof of Proposition~\\ref{prop:41:Lagrangian}}\n% \\label{sec:5:proofLagrangian}\n\nWe include here the missing details of the proof of Proposition~\\ref{prop:41:Lagrangian}.\n%\nFirst, we need to justify that the objective function is quasi-convex, in each of its coordinates.\n%\nThen, we develop the computation of $D_i^*(\\lambda)$, as a closed form expression of the system parameters ($K, p$), the distribution of static devices ($S_1,\\dots,S_{K}$) and the Lagrange multiplier $\\lambda$.\n\n\\paragraph{Quasi-convexity.}\n\n\\begin{itemize}\n\t\\item\n\tFor $0 < \\gamma < 1$, the function $g(x) \\eqdef x \\gamma^x$ is quasi-convex on $[0,\\infty)$, \\ie, $g(\\eta x + (1-\\eta)y) \\leq \\max(g(x), g(y))$ for any $x,y \\in [0,\\infty)$ and $\\eta \\in [0,1]$ (definition from \\cite{Luenberger68}).\n    Indeed, $g(\\eta x + (1-\\eta)y) = \\eta \\left[ x (\\gamma^x)^{\\eta} \\right] \\gamma^{((1-\\eta)y)} + (1-\\eta)\\left[ y (\\gamma^y)^{1-\\eta}\\right] \\gamma^{\\eta x}$, and $\\gamma^{((1-\\eta)y)} \\leq 1$ and $\\gamma^{\\eta x} \\leq 1$. But also $(\\gamma^x)^{\\eta} \\leq \\gamma^x$ as $\\eta \\leq 1$, and the same holds for $(\\gamma^y)^{1-\\eta} \\leq \\gamma^y$. So $g(\\eta x + (1-\\eta)y) \\leq \\eta (x \\gamma^x) + (1 - \\eta) (y \\gamma^y)$ which is a convex combination of $x \\gamma^x$ and $y \\gamma^y$, so smaller than the larger of the two values, and so $g(\\eta x + (1-\\eta)y) \\leq \\max(x \\gamma^x, y \\gamma^y)$.\n\n    \\item\n    The function $f(D_1, \\dots, D_{K}) \\eqdef \\sum\\limits_{i=1}^{K} D_i (1 - p)^{S_i + D_i -1}$ is quasi-convex in each of its coordinates, on $[0,\\infty)^{K}$, as a sum of component-wise quasi-convex functions (with $\\gamma = (1 - p) \\in (0, 1)$, thanks to the first point).\n    \\hfill{}$\\square$\n\\end{itemize}\n\n\n\n\\paragraph{Derivation of the Lagrange multiplier solution.}\n\nLet us now prove the expression for $D_i^*$ given above in \\eqref{eq:41:Dilambda}.\n\n\\begin{itemize}\n\t\\item\n\tIf $\\boldsymbol{D} \\eqdef (D_1,\\dots,D_{K})$,\n    the Lagrangian is denoted $\\mathcal{L}(\\boldsymbol{D}, \\lambda) \\eqdef f(\\boldsymbol{D}) + \\lambda(D - \\sum\\limits_{i=1}^{K} D_i)$, and its derivative w.r.t. $D_i$ is\n    $\\frac{\\partial}{\\partial D_i} \\mathcal{L}(\\boldsymbol{D}, \\lambda) = (1-p)^{S_i + D_i - 1} + \\log(1 - p) D_i (1-p)^{S_i + D_i - 1} - \\lambda$.\n\n    \\item\n    So the gradient is zero $\\frac{\\partial}{\\partial D_i} \\mathcal{L}(\\boldsymbol{D}, \\lambda) |_{D_i=D_i^*} = 0$\n    iff $D_i^*$ satisfies $(1-p)^{D_i^*}( 1 + \\log(1-p) D_i^*) = \\lambda / (1-p)^{S_i - 1}$. Let $x = \\log(1-p) D_i^*$ this is equivalent to $\\e^{x}(1 + x) = \\lambda / (1-p)^{S_i - 1}$\n    and with $y = 1 + x$, we get $\\e^{y}y = \\lambda\\e / (1-p)^{S_i - 1}$.\n\n\t\\item\n    By using the $\\mathcal{W}$-Lambert function $\\mathcal{W}$ \\cite{Corless96}, reciprocal of $y \\mapsto \\e^{y}y$, we get $x = y - 1 = \\mathcal{W}(\\lambda\\e / (1-p)^{S_i - 1}) - 1$.\n    So the gradient of the Lagrangian is zero iff $D_i^* = \\max(0, x/\\log(1-p)) = \\left[ \\frac{1}{\\log(1-p)}\\mathcal{W}(\\lambda\\e / (1-p)^{S_i - 1}) - 1\\right]^{+}$, because $D_i^*$ has to be non-negative.\n    This gives the $i$-th coordinate of the unique saddle point of $f(\\boldsymbol{D})$,\n    and so the unique solution to the maximization problem \\eqref{eq:41:optPb}, thanks to \\cite[Theorem 1]{Luenberger68}.\n    \\hfill{}$\\square$\n\\end{itemize}\n\n", "meta": {"hexsha": "4516792c38184f6013697a011693febfa222d0e0", "size": 3273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-Chapters/4-Chapter/CrownCom_17/IoT_slotted_appendix.tex", "max_stars_repo_name": "Naereen/phd-thesis", "max_stars_repo_head_hexsha": "0fa93ca0d738771f4215bc4aeb66157f2026ba00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-11-18T12:22:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T19:29:48.000Z", "max_issues_repo_path": "2-Chapters/4-Chapter/CrownCom_17/IoT_slotted_appendix.tex", "max_issues_repo_name": "Naereen/phd-thesis", "max_issues_repo_head_hexsha": "0fa93ca0d738771f4215bc4aeb66157f2026ba00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-11-18T09:19:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-08T14:13:08.000Z", "max_forks_repo_path": "2-Chapters/4-Chapter/CrownCom_17/IoT_slotted_appendix.tex", "max_forks_repo_name": "Naereen/phd-thesis", "max_forks_repo_head_hexsha": "0fa93ca0d738771f4215bc4aeb66157f2026ba00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-28T20:56:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-13T11:11:57.000Z", "avg_line_length": 69.6382978723, "max_line_length": 598, "alphanum_fraction": 0.6186984418, "num_tokens": 1269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6214685213355009}}
{"text": "\\section{\\fluidity Model}\n\\label{fluid_dynamics_section}\n\nThe state of a moving fluid can be described mathematically through means of functions which give the distribution of velocity $\\bmu=\\bmu(\\bmx,t)$ and any two thermodynamics quantities (such as the pressure $p(\\bmx,t)$ and density $\\rho(\\bmx,t)$) within the fluid. All thermodynamic quantities are determined by the values of any two such quantities together with the equation of state. \\citet{batchelor_1967} is the ultimate reference to much of this material. \\fluidity can solve the equations of motion in varying forms, and with various approximations. These forms and approximations are discussed in the following sections.\n\n%%%\n%%%  SUB - SECTION: CONSERVATION EQUATIONS\n%%%\n\\subsection{Conservation Equations: Mass, Momentum and Energy} \nA starting point for describing the physics of a continuum are the conservation equations. Fluid volumes deform in time as the fluid moves. If $\\theta(\\bmx,t)$ is the density of some quantity (\\eg Temperature) associated with the fluid, the time evolution of that quantity in a fluid volume $V(t)$ is \n\\begin{equation}\\label{RTT}\n \\ddt{}\\left[\\int_{V(t)}\\theta(\\bmx,t)\\right]=\n \\int_{V(t)}\\left(\\DDt{\\theta}+\\theta\\nabla\\cdot\\bmu\\right),\n\\end{equation}\n\\index{Reynolds Transport theorem}\n\\noindent\nwhich is the Reynolds' Transport theorem. In Eqn. \\ref{RTT} $\\bmx=(x,y,z)^T$ and $\\bmu=(u,v,w)^T$ are three dimensional position and velocity vectors respectively and \n\\begin{equation}\\label{MatDiv}\n \\DDt{}\\equiv\\frac{\\partial}{\\partial{t}}+\\bmu\\cdot\\nabla,\n\\end{equation}\nis the \\textit{material derivative}.\n\n%%%\n%%% SUB - SUB - SECTION: MASS CONSERVATION\n%%% \n\\subsubsection{Mass conservation}\\index{\\fluidity Module ! Conservative Equations! Mass }\n\\index{Conservation!Mass}\nSince matter is neither created nor destroyed, substituting $\\theta=\\rho$ in Eqn. \\ref{RTT} gives that the \\lhs\\ is zero. Then, as the volume $V(t)$ is arbitrary, it is seen that the mass density satisfies\n\\begin{equation}\\label{mass_conservation}\n \\DDt{\\rho}=-\\rho\\nabla\\cdot\\bmu,\n\\end{equation}\nor equivalently\n\\begin{equation}\\label{mass_conservation_2}\n \\frac{\\partial\\rho}{\\partial{t}}+\\nabla\\cdot(\\rho\\bmu)=0.\n\\end{equation}\nThe quantity $\\rho\\bmu$ is called the \\textit{mass flux} or \\textit{momentum} and Eqn. \\ref{mass_conservation_2} is termed the \\textit{equation of continuity}.\n\n%%%\n%%% SUB - SUB - SECTION: MOMENTUM CONSERVATION\n%%% \n\\subsubsection{Momentum conservation}\\index{\\fluidity Module ! Conservative Equations! Momentum } \n\\index{Conservation!Momentum}\nThe momentum associated with a unit volume of fluid is given by $\\rho\\bmu$. Initially, the fluid will be considered \\textit{ideal}, that is, viscosity and conductivity are assumed to be unimportant. Then, the rate of change of momentum is given by\n\\begin{equation}\\label{mom_cons_1}\n \\frac{\\partial}{\\partial{t}}(\\rho\\bmu)=\\rho\\frac{\\partial\\bmu}{\\partial{t}}+\\frac{\\partial\\rho}{\\partial{t}}\\bmu.\n\\end{equation}\nUsing the equation of continuity -- Eqn. \\ref{mass_conservation_2} and Euler's equation \\citep{batchelor_1967,ferziger_2002}, which is the force equation for an inviscid fluid, in the form\n\\begin{equation}\\label{mom_cons_2}\n \\frac{\\partial\\bmu}{\\partial{t}}=-\\bmu\\cdot\\nabla\\bmu-\\frac{1}{\\rho}\\nabla{p},\n\\end{equation}\ngives\n\\begin{equation}\\label{mom_cons_3}\n \\frac{\\partial}{\\partial{t}}(\\rho\\bmu)=-\\nabla{p}-\\nabla\\cdot(\\rho\\bmu\\bmu),\n\\end{equation}\nwhere $\\bmu\\bmu$ is a tensor which represents the dyadic product of vectors which can be written $[\\bmu\\bmu]_{ij}=u_{i}u_{j}$. Writing $\\tensor{\\Pi}=p\\mathbf{I}+\\rho\\bmu\\bmu$ Eqn. \\ref{mom_cons_3} can finally be written as\n\\begin{equation}\\label{mom_cons_4}\n \\frac{\\partial}{\\partial{t}}(\\rho\\bmu)+\\nabla\\cdot\\tensor{\\Pi}=0,\n\\end{equation}\nwhere $\\tensor{\\Pi}$ is clearly a symmetric tensor and is termed the \\textit{momentum flux density tensor}.\n\n%%%\n%%% SUB - SUB - SECTION: ENERGY CONSERVATION\n%%% \n\\subsubsection{Energy conservation} \\index{\\fluidity Module ! Conservative Equations! Energy }\n\\index{Conservation!Energy}\nThe effect of energy conservation within the fluid is now considered. Consider some volume of \\textit{ideal} fluid which is fixed in space such that the energy contained within this volume varies in time. The energy per unit volume of the fluid is given by\n\\begin{equation}\\label{e_cons_1}\n \\frac{1}{2}\\rho{\\modu}^{2}+\\rho \\inte,\n\\end{equation}\nwhere the two terms represent the kinetic and internal energy respectively, $\\inte$ being the internal energy per unit mass of the fluid. The change in energy at a fixed point in space is then given by the partial derivative of Eqn. \\ref{e_cons_1} \\wrt\\ time\n\\begin{equation}\\label{e_cons_2}\n \\frac{\\partial}{\\partial{t}}\\left(\\frac{1}{2}\\rho{\\modu}^{2}+\\rho\\inte\\right).\n\\end{equation}\nIn order to calculate this quantity the kinetic energy is first considered. Expanding the kinetic energy term of Eqn. \\ref{e_cons_2} gives\n\\begin{equation}\\label{e_cons_3}\n \\frac{\\partial}{\\partial{t}}\\left(\\frac{1}{2}\\rho{\\modu}^{2}\\right)=\\frac{1}{2}\\modu^{2}\\frac{\\partial\\rho}{\\partial{t}}+\n                                                                 \\rho\\bmu\\cdot\\frac{\\partial\\bmu}{\\partial{t}}.\n\\end{equation}\nUsing Eqns. \\ref{mass_conservation_2} and \\ref{mom_cons_2},\n\\begin{equation}\\label{e_cons_4}\n \\frac{\\partial}{\\partial{t}}\\left(\\frac{1}{2}\\rho{\\modu}^{2}\\right)=-\\frac{1}{2}{\\modu}^{2}\\nabla\\cdot(\\rho\\bmu)\n                                                                  -\\bmu\\cdot\\nabla{p}\n                                                                  -\\rho\\bmu\\cdot(\\bmu\\cdot\\nabla)\\bmu.\n\\end{equation}\nReplacing $\\bmu\\cdot(\\bmu\\cdot\\nabla)\\bmu$ by $\\half\\bmu\\cdot\\nabla{\\modu}^{2}$ and using the thermodynamic relation for the change in heat function per unit mass of the fluid (enthalpy), $w(=\\inte+p/\\rho)$,  given by \\citep{michelsen_2007}\n\\begin{equation}\\label{e_cons_5}\n dw=Tds+\\frac{1}{\\rho}dp,\n\\end{equation}\nwhere $T$ is the temperature and $s$ is the entropy per unit mass, to replace $\\nabla{p}$ by $\\rho\\nabla{w}-\\rho{T}\\nabla{s}$, Eqn. \\ref{e_cons_4} becomes\n\\begin{equation}\\label{e_cons_6}\n \\frac{\\partial}{\\partial{t}}\\left(\\frac{1}{2}\\rho{\\modu}^{2}\\right)=-\\half{\\modu}^{2}\\nabla\\cdot(\\rho\\bmu)\n                                                                 -\\rho\\bmu\\cdot\\nabla\\left(\\half{\\modu}^{2}+w\\right)\n                                                                 +\\rho{T}\\bmu\\cdot\\nabla{s}.\n\\end{equation}\nIt is now required to transform the derivative of the internal energy. To do this, use is made of the thermodynamic relation\n\\begin{equation}\\label{e_cons_7}\n d\\inte=Tds-pdV=Tds+(p/\\rho^{2})d\\rho,\n\\end{equation}\nwhere $V=1/\\rho$. Therefore \n\\begin{equation}\\label{e_cons_8}\n \\frac{\\partial}{\\partial{t}}(\\rho\\inte)=w\\frac{\\partial\\rho}{\\partial{t}}+\\rho{T}\\frac{\\partial{s}}{\\partial{t}}\n                                            =-w\\nabla\\cdot(\\rho\\bmu)-\\rho{T}\\bmu\\cdot\\nabla{s},\n\\end{equation}\nwhere Eqn. \\ref{RTT} has been used for the entropy $s$. Combining Eqns. \\ref{e_cons_6} and \\ref{e_cons_8} gives\n\\begin{equation}\\label{e_cons_9}\n \\frac{\\partial}{\\partial{t}}\\left(\\half\\rho{\\modu}^{2}+\\rho\\inte\\right)+\\nabla\\cdot\\left[\\rho\\bmu\\left(\\half{\\modu}^{2}+w\\right)\\right]=0,\n\\end{equation}\nwhere $\\rho\\bmu\\left(\\half{\\modu}^{2}+w\\right)$ is known as the \\textit{energy flux density} vector.\n\n%%%\n%%% SUB - SUB - SECTION: INTERNAL FRICTION & THERMAL CONDUCTION\n%%% \n\\subsubsection{Internal friction and thermal conduction}\\label{Sect:stressed}\\index{\\fluidity Module ! Internal friction }\\index{\\fluidity Module ! Thermal conduction}\n\\index{viscosity}\nThe effects of viscosity on the motion of a fluid are now considered. To express the equations of motion governing a viscous fluid, some additional terms are required. The equation of continuity (conservation of mass) is equally valid for any viscous as well as inviscid fluid. However, Euler's equation (Eqn. \\ref{mom_cons_2}) and hence Eqn. \\ref{mom_cons_4} and Eqn. \\ref{e_cons_9} require modification.\n\nBy adding $-\\tautens$ to the previously introduced \\textit{momentum flux density tensor}, $\\tensor{\\Pi}$, so that\n\\begin{equation}\n \\tensor{\\Pi}=p\\mathbf{I}+\\rho\\bmu\\bmu-\\tautens=-\\sigtens+\\rho\\bmu\\bmu,\n\\end{equation}\nwhere $\\sigtens=-p\\mathbf{I}+\\tautens$, the viscous transfer of momentum in the fluid can be taken into account. $\\sigtens$ is called the stress tensor and gives the part of the momentum flux which is not due to direct transfer of momentum with the mass of the fluid. $\\tautens$ is termed the viscous stress tensor. The most general form of the equations of motion of a compressible viscous fluid may be written as\n\\begin{equation}\\label{viscous_fluids_1}\n \\rho\\left(\\frac{\\partial\\bmu}{\\partial{t}}+\\bmu\\cdot\\nabla\\bmu\\right)=\\nabla\\cdot\\sigtens+\\rho\\bmF,\n\\end{equation}\nwhere $\\bmF$ is the internal or volume force per unit mass (\\eg gravity). The introduction of the stress tensor also modifies the form of the energy flux density. Conservation of energy of course still holds, that is: the change per unit time in the total energy of the fluid in any volume must still be equal to the total flux of energy through the surface enclosing the volume. In addition to the flux owing to the transfer of mass by the motion of the fluid, $\\rho\\bmu(\\half{\\modu}^{2}+w)$, additional terms are required. These additional terms are the flux due to processes of internal friction, $\\bmu\\cdot\\tautens$, and the transfer of energy through \\textit{thermal conduction}, denoted $\\bmq$.\nThe complete energy flux density in a fluid with internal stress and thermal conduction therefore takes the form $\\rho\\bmu(\\half{\\modu}^{2}+w)-\\bmu\\cdot\\tautens+\\bmq$ and thus, including terms owing to volume forces $\\bmF$, the general law of conservation of energy can be expressed by the equation\n\\begin{equation}\\label{viscous_fluids_2}\n \\frac{\\partial}{\\partial{t}}\\left(\\half\\rho{\\modu}^{2}+\\rho\\inte\\right)\n +\\nabla\\cdot\\left[\\rho\\bmu\\left(\\half{\\modu}^{2}+w\\right)-\\bmu\\cdot\\tautens+\\bmq\\right]=\\rho\\bmF\\cdot\\bmu.\n\\end{equation}\n\n\n%%%\n%%% SUB - SECTION: COMPRESSIBLE EQNS. IN CONSERVATIVE FORM\n%%% \n\\subsection{Compressible equations in conservative form}\nUsing the conservation laws outlined above the following pointwise PDE system governing the motion of a compressible fluid is obtained\n% Conservation of mass, Newton's second law and the first law of\n% thermodynamics allows one to derive integral relations governing the\n% properties of material volumes of fluid, for background material see\n% \\cite{batchelor1967}. These conservation laws represent the most fundamental\n% description of the properties of fluids. Since the integral relations hold\n% for arbitrary volumes of fluid the following pointwise PDE system is\n% obtained\n\\begin{subeqnarray}\n\\frac{\\pp\\rho}{\\pp t} + \\nabla\\cdot(\\rho\\bmu) &=& 0,\\slabel{conmass}\\\\\n\\frac{\\pp}{\\pp t}(\\rho\\bmu) + \\nabla\\cdot(\\rho\\bmu\\bmu-\\sigtens) &=& \\rho\\bmF,\\slabel{conmom}\\\\\n\\frac{\\pp}{\\pp t}(\\rho \\tote) + \\nabla\\cdot(\\rho E\\bmu - \\sigtens\\bmu +\n\\bmq) &=& \\rho\\bmF\\cdot\\bmu,\\slabel{conenergy}\n\\label{conservativesystem}\n\\end{subeqnarray}\nwhere $\\tote\\equiv\\inte+\\modu^2/2$ is the total specific energy. Eqn. \\ref{conmass} is exactly the conservative form of the continuity equation given in Eqn. \\ref{mass_conservation_2}, Eqn. \\ref{conmom} is Eqn. \\ref{mom_cons_4} with the internal stress of the fluid and volume forces taken into account and Eqn. \\ref{conenergy} is obtained from making the substitutions $w=\\inte+p/\\rho$ and $\\tote\\equiv\\inte+\\modu^2/2$ in Eqn. \\ref{viscous_fluids_2}.\n\n% where $\\bmu$ represents the three-dimensional (3-D) velocity, $\\rho$\n% is the density, $\\sigtens$ is a stress tensor, $\\bmF$ is the\n% internal or volume force per unit mass \\footnote{Note that surface\n% forces come in via the stress tensor.}, $\\tote\\equiv \\inte+\\bmu^2/2$ where\n% $E$ is the total specific energy and $e$ is the specific internal\n% energy, and $\\bmq$ is the heat flux. Note that $\\bmu\\bmu$ represent\n% the dyadic product of vectors which has components\n% $[\\bmu\\bmu]_{ij}=\\bmu_i\\bmu_j$.\n\n%%%\n%%% SUB - SECTION: COMPRESSIBLE EQNS. IN NON-CONSERVATIVE FORM\n%%% \n\\subsection{Compressible equations in non-conservative form}\nExpanding terms in Eqn. \\ref{conservativesystem} yields the non-conservative form of the compressible equations\\footnote{Eqn. \\ref{nonconmass} is trivial to obtain. Eqn. \\ref{nonconmom} makes use of Eqn. \\ref{conmass} and the divergence of the dyadic product, given by\n\\begin{equation}\n\\nabla\\cdot(\\bmu\\bmu) = \\bmu\\cdot\\nabla\\bmu + \\bmu\\nabla\\cdot\\bmu,\n\\end{equation}\nalong with Eqn. \\ref{MatDiv}. Eqn. \\ref{nonconenergy} makes use of both Eqn. \\ref{nonconmass} and Eqn. \\ref{nonconmom} and note that substituting for $\\tote\\equiv\\inte+\\modu^2/2$ results in the cancellation of kinetic energy terms.}\n\\begin{subeqnarray}\\label{nonconform}\n\\DDt{\\rho} + \\rho\\nabla\\cdot\\bmu &=& 0,\\slabel{nonconmass}\\\\\n\\rho\\DDt{\\bmu} -\\nabla\\cdot\\sigtens &=& \\rho\\bmF,\\slabel{nonconmom}\\\\\n\\rho\\DDt{\\inte} - \\sigtens\\cdot\\nabla\\bmu + \\nabla\\cdot\\bmq &=&\n0.\\slabel{nonconenergy} \\label{nonconservativesystem}\n\\end{subeqnarray}\nNote that, provided the fields (\\eg density and pressure) vary smoothly, that is, the fields are differentiable functions, Eqns. \\ref{conservativesystem} and Eqn. \\ref{nonconservativesystem} are identical.\n\n%The CFD code \\fluidity\\ can solve compressible equations in both\n%conservative, non-conservative and mixed form as defined by the\n%scalar BETA in $[0,1]$, in an analogous manner to theta time\n%stepping defined later, \\ie the weighted combination\n%BETA*(\\ref{conservativesystem})+($1-$BETA)*(\\ref{nonconservativesystem})\n%is discretised\\footnote{Check that BETA and ($1-$BETA) don't need to be swapped here.}.\n%This BETA has absolutely no connection with the haline contraction coefficient\n%or the parameter in the beta-plane approximation.\n\n%%%\n%%% SUB - SECTION: THERMODYNAMICS AND FOURIER'S LAW OF HEAT CONDUCTION\n%%% \n\\subsection{Some more thermodynamics and Fourier's law of heat conduction} \\index{\\fluidity Module !Fourier's law of heat conduction}\nClassical thermodynamics \\cite[Eqns (1.5.8) and (1.5.20)]{batchelor_1967} says that\n\\begin{equation}\nT\\DDt{s} = \\DDt{\\inte} + \\frac{p}{\\rho}\\nabla\\cdot\\bmu,\n\\end{equation}\nand\n\\begin{equation}\nT\\DDt{s} = c_p\\DDt{T} -\\frac{\\alpha T}{\\rho}\\DDt{p},\n\\end{equation}\nwhere $s\\equiv s(p,T)$ is the entropy, $T$ is temperature, $c_p$ is the specific heat constant $c_p=T(\\pp S/\\pp T)_p$, and $\\alpha$ is the thermal expansion coefficient\n\\begin{equation}\\label{thermalexpansioncoeff}\n\\alpha = -\\frac{1}{\\rho}\\frac{\\pp \\rho}{\\pp T}.\n\\end{equation}\n\nAdditionally, Fourier's law states that heat flux at a point is directly proportional to the temperature gradient there, \\ie\n\\begin{equation}\n\\bmq = -\\ktens\\nabla T,\n\\end{equation}\nwhere $\\ktens$ is the coefficient of thermal conductivity in the medium.\n\nIt is now possible to replace the internal energy equation \\ref{nonconenergy} with a prognostic equation for temperature\n\\begin{equation}\n\\rho c_p \\DDt{T} =\\alpha T\\DDt{p} + p\\nabla\\cdot\\bmu\n+\\sigtens\\cdot\\nabla\\bmu + \\nabla\\cdot(\\ktens\\nabla T).\n\\end{equation}\nMessing around with the stress tensor allows one to cancel the second term of the \\rhs\\ and hence\n\\begin{equation}\n\\DDt{T} =\\frac{\\alpha T}{\\rho c_p}\\DDt{p} +\n\\frac{\\Phi}{c_p} + \\nabla\\cdot(\\kaptens\\nabla T),\n\\end{equation}\nwhere $\\kaptens = \\ktens/(\\rho c_p)$ is the heat diffusivity tensor and\n\\begin{equation}\n\\Phi \\equiv \\frac{2\\mu}{\\rho}\\left(\\strt_{ij}\\strt_{ij}\n-\\frac{1}{3}(\\nabla\\cdot\\bmu)^2\\right),\n\\end{equation}\nis the rate of dissipation of mechanical energy, per unit mass, due to viscous effects, see \\cite[Sections 3.4 and 3.6]{batchelor_1967}. This term corresponds to the generation of heat by viscous damping, and in the sequel shall be assumed to be of negligible importance.\n\n%%%\n%%%  SUB - SECTION: SCALAR EQUATIONS\n%%%\n\\subsection{Scalar equations}\\index{\\fluidity Module ! Scalar fields}\nThe general form the equation that governs the evolution of a scalar fields $c$ (\\eg passive tracer, species concentration, temperature, salinity) is\n\\begin{equation}\\label{eq:general_scalar_eqn}\n\\ppt{T} + \\nabla\\cdot(\\bmu c) = \\nabla\\cdot(\\kaptens\\nabla c) - \\sigma c + F.\n\\end{equation}\n\n%%%\n%%%  SUB - SUB - SECTION: ADVECTION\n%%%\n\\subsubsection{Advection}\\index{\\fluidity Module ! Scalar fields ! Advection}\nThe advection term in Eqn. \\ref{eq:general_scalar_eqn} expresses the transport of the scalar quantity $c$ with the flow field $\\bmu$. The term convection is often used for this process where the motion is largely vertical and as the results of temperature (density) differences.\nThe advection term in Eqn. \\ref{eq:general_scalar_eqn} may be written\n\\begin{equation}\\label{eq:scalar_advection}\n\\nabla\\cdot(\\bmu c) = \\bmu\\cdot\\nabla c + (\\nabla\\cdot\\bmu)c.\n\\end{equation}\nNote that for incompressible flow the second term on the \\rhs\\ is zero. However, there may be numerical reasons why the discrete velocity field is not exactly divergence free, in which case this term may be included in the discretisation. Note also that the second term on the \\rhs\\ of Eqn. \\ref{eq:scalar_advection} may be interpreted as a source term for $c$.\n\n%%%\n%%%  SUB - SUB - SECTION: DIFFUSION\n%%%\n\\subsubsection{Diffusion}\\index{\\fluidity Module ! Scalar fields ! Diffusion}\nThe diffusion term in Eqn. \\ref{eq:general_scalar_eqn} represents the mixing of $c$ and may be due to molecular mixing of individual particles via Brownian motion, or mixing via large (compared to the molecular scale) eddies in the flow.  The diffusion term\n\\begin{equation}\\label{eq:scalar_diffusion}\n\\nabla\\cdot(\\kaptens\\nabla c),\n\\end{equation}\ntakes some convenient simpler forms for tensor diffusivities often encountered. Often an isotropic diffusivity, $\\kaptens = \\mathrm{diag}(\\kappa,\\kappa,\\kappa)$ in which case the diffusion term may be written as\n\\begin{equation}\\label{eq:scalar_isotropic_diffusion}\n\\nabla\\cdot(\\kaptens\\nabla c) = \\kappa\\nabla\\cdot\\nabla c = \\nabla^2 c = \\kappa\\Delta c.\n\\end{equation}\nIn domains with high aspect ratio dynamics one often uses a smaller value of diffusivity in the $\\lq$thin' direction. For example, in the atmosphere or ocean we may choose a horizontal diffusivity $\\kappa_H$ and a vertical diffusivity $\\kappa_V$ so that $\\kaptens = \\mathrm{diag}(\\kappa_H,\\kappa_H,\\kappa_V)$ with $\\kappa_V < \\kappa_H$.  In this case the diffusion term may be written as\n\\begin{equation}\\label{eq:scalar_isotropic_diffusion}\n\\nabla\\cdot(\\kaptens\\nabla c) = \\kappa_H \\left(\\pptt[x]{c} + \\pptt[y]{c}\\right) + \\kappa_V \\pptt[z]{c}.\n\\end{equation}\nNote that this second order term is often termed Laplacian diffusion, the 4th order version is sometimes termed hyper-diffusion. Hyper-diffusion acts in a similar manner to Laplacian diffusion but is more\nscale selective.\n\n%%%\n%%%  SUB - SUB - SECTION: ABSORPTION\n%%%\n\\subsubsection{Absorption}\\index{\\fluidity Module ! Scalar fields ! Absorption}\nThe absorption term in Eqn. \\ref{eq:general_scalar_eqn} \n\\begin{equation}\\label{eq:scalar_absorption}\n-\\sigma c,\n\\end{equation}\nhas the effect of decreasing the magnitude of $c$ (note the minus sign and the fact that $\\sigma$ would typically be positive). It is sometimes termed Rayleigh friction. \n\n\\subsubsection{Reaction and source}\nThe remaining term in Eqn. \\ref{eq:general_scalar_eqn}\n\\begin{equation}\\label{eq:scalar_source}\nF = \\sum_i F_i,\n\\end{equation}\ncan encompasses a number of source and reaction terms. Those terms where $F_i$ are a given function of time, location or a-priori known fields are termed sources (and sometime sinks if they are negative). Those terms which are also functions of other prognostic fields are termed reactions and are common when dealing with chemistry or biology.\n\n\n\n\n\\subsection{The Boussinesq approximation} \\label{sect:boussinesq_approximation}\\index{\\fluidity Module ! Boussinesq approximation}\n\\index{density!reference}\n\\index{Boussinesq!approximation}\nAs previously noted, for many problems, one is able to assume that density does not vary greatly about a mean reference state \n\\begin{equation}\\label{eq:densref}\n\\rho(\\bmx,t) = \\rho_0 + \\rho'(\\bmx,t),\\qquad \\rho'\\ll\\rho_0.\n\\end{equation}\nThe Boussinesq approximation involves two steps. The first makes use of this assumption in Eqn. \\ref{nonconmass}, yielding \n\\begin{equation}\\label{eq:divfree}\n\\nabla\\cdot\\bmu=0.\n\\end{equation}\nmass conservation thus becomes volume conservation and sound waves are filtered. The second part of the Boussinesq approximation follows by replacing $\\rho$ by $\\rho_0$ in all terms of Eqn. \\ref{nonconmom}, except where density is multiplied by gravity (i.e. in the buoyancy term where full density must be retained --- these are the density variations that drive natural convection). This yields\n\\begin{equation}\n\\rho_0\\DDt{\\bmu} -\\nabla\\cdot\\sigtens = -\\rho g\\bmk +\n\\rho_0\\bmF,\n\\end{equation}\nwhere buoyancy has explicitly been removed from the forcing term $\\bmF$.\n\n\\subsection{The non-hydrostatic Boussinesq equations}\\label{sect:typical_ICOM_equations}\n\\index{Boussinesq!equations}\n\\index{momentum equation}\n\\index{continuity equation}\nCombining the various steps above yields the three-dimensional\nnon-hydrostatic Boussinesq equations, as follows, which are\ndiscretised in a domain $\\Omega\\subset\\mathbb{R}^3$ to yield a\nfinite element numerical ocean model,\n%\n\\begin{subeqnarray}\n\\frac{\\pp\\bmu}{\\pp t} + (\\bmu -\\hat{\\bmu})\\cdot\\nabla \\bmu + 2 \\bmOmega \\times \\bmu\n&=& - \\nabla p - g\\nabla\\eta - \\rho g \\bmk + \\nabla\\cdot \\tautens + \\bmF,\n\\slabel{mtm}\\\\\n\\nabla\\cdot {\\bmu}&=&0,\\slabel{conty}\\\\\n\\frac{\\pp T}{\\pp t} + (\\bmu-\\hat{\\bmu})\\cdot\\nabla  T  &=&\n\\nabla . \\left ( \\kaptens_T  \\nabla T\\right),\\slabel{heat}\\\\\n\\frac{\\pp S}{\\pp t} + (\\bmu-\\hat{\\bmu})\\cdot\\nabla  S  &=&\n\\nabla . \\left ( \\kaptens_S  \\nabla S\\right),\\slabel{salt}\\\\\n\\rho &=& -\\alpha(T-T_0)+\\beta (S-S_0).\\slabel{state}\n\\label{boussinesq}\n\\end{subeqnarray}\n%\nHere, $\\bmu$ is the three-dimensional velocity vector,\n$\\hat{\\bmu}$ is a term used to account for a moving reference\nframe, for example in this work it takes the form of node velocities\nfor numerical discretisations on moving meshes (\\eg to account for a moving free surface).\n$t$ represents time, $p$ is the\nperturbation pressure, $g$ is the acceleration due to gravity,\n$\\rho$ is the perturbation density,\n$T$ is the temperature and $S$ is salinity. In this work $T,S$ and hence $\\rho$ are all\nconstant. $\\eta$ is the free surface height, whose evolution is described in a section below.\n$\\tautens,\\kaptens_T,\\kaptens_S$ are the viscosity, thermal diffusivity and saline\ndiffusivity tensors respectively. $\\alpha$ is the thermal expansion coefficient\nand $\\beta$ is the saline contraction coefficient.\nThe rotation vector is $\\bmOmega$, and $\\bmF$ contains additional source terms such as the astronomical tidal forcing.\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%                                 %%%%\n%%%%     FLUID TRANSPORT METHODS     %%%%\n%%%%                                 %%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Numerical Formulation -- Transport Methods in the \\fluidity Module}%\\index{\\fluidity Module! Transport methods}\n\\label{fluid_transport_methods_section}\n\n\\subsection{Non-linear Petrov-Galerkin methods}\\index{\\fluidity Module! Transport methods ! Petrov-Galerkin}\n\nA non-linear Petrov-Galerkin method is applied here to discretize the momentum equations. This involves the usual $\\lq$linear' streamline upwind weighting of the equations and an additional non-linear diffusion term which operates in the direction of the gradient of the solution. This method is applied separately to each velocity component in the momentum equations \\citep[see][for further details]{pain_2001b,hughes_1986}.\n\n\\subsection{Mixed formulation}\\index{\\fluidity Module! Transport methods ! Mixed formulation }\nA transient mixed finite element formulation is used to discretize the equations. Additionally, the finite volume discretization of the continuity equations and field variables and a continuous Petrov-Galerkin \\citep{claes_1987} discretization of the momentum equations are employed. Within each time step the equations are iterated upon using a projection-based pressure determination method until all equations balance simultaneously. As a result the non-linear continuity equations are strictly satisfied, ensuring mass conservation. In the mixed formulation hexahedral $\\lq$brick' elements in 3-D and rectangular elements in 2-D are employed here which have a bi-linear variation of velocity and a piecewise variation of pressure, density and all other advected quantities. This element has a single pressure associated with each element and a velocity node (collocation point) at the corners of the element with $C^0$ variation of velocity between elements.\n\\medskip\n\n\\noindent\n\\textbf{FEM/CV Discretization of Spatial Derivatives: } Here the transport equation is solved\\index{\\fluidity ! Transport methods ! CV/FEM  Discretization of Spatial Derivatives}\n\\begin{equation}\n\\displaystyle\\frac{\\partial \\text{T}(\\mathbf{r},t) }{\\partial t} + \\nabla\\cdot \\textbf{a}\n\\text{T}(\\mathbf{r},t) +\\nabla\\cdot \\kappa \\nabla \\text{T}(\\mathbf{r},t)  - S = 0\n\\label{traneq}\n\\end{equation}\nover domain $V$ with a source term \\textit{S}, advection velocity vector $\\left(\\mathbf{a}\\right)$, diffusivity $\\left(\\kappa\\right)$ and time $\\left(\\textit{t}\\right)$.  This equation is solved by averaging the equations over each control volume $i$ in turn with the use of the function $M_{i}$ which is unity over control volume $i$ and zero otherwise, that is\n\\begin{equation}\n\\int_{V} M_{i} \\left( \\frac{\\partial T }{\\partial t} +\n\\nabla\\cdot \\textbf{a} T +\\nabla\\cdot \\kappa \\nabla T - s \\right)\\,d V\n= 0, \\quad \\forall i \\in \\{1,2,..., \\mathcal{M}\\}\n\\label{CV1}\n\\end {equation}\n\\noindent\nin which $\\mathcal{M}$ is the number of CVs which is not necessarily equal to the number of nodes $\\mathcal{N}$ of the FEM mesh and $s$ is the discretized source. This is combined with an expansion of the approximate solution \\textit{T} to $\\text{T}$ in terms of the control volume basis functions $M_{j}$ with:\n\\begin{equation}  \nT\\left(\\mathbf{r},t\\right)=\\sum\\limits_{j=1}^{\\mathcal{M}} M_{j}\\left(\\mathbf{r}\\right) T_{j}(t) \\approx \\text{T}.\n\\end{equation}\n\nThe advection term (second term in integrand of Eqn. \\ref{CV1}) is discretized by applying Greens theorem to obtain\n\\begin{equation}\n\\int_{V} M_{i} \\left( \\nabla \\cdot \\mathbf{a} T+\\nabla\\cdot \\kappa \\nabla T \\right)\\,d V = \\int_{\\Gamma_{CV_i}} \\left(\\mathbf{a}\\cdot \\mathbf{n}\\widetilde{T}+\\mathbf{n}\\cdot \\kappa \\nabla T \\right) \\,d \\Gamma\n\\label{a}\n\\end{equation}\n\\noindent\nin which the vector $\\mathbf{n}$ is the outward pointing normal to the surface of the control volume \\textit{i} (CV$_{i}$).  This allows a value of $\\widetilde{T}$ at the quadrature integration points on the surface of the control volume to be calculated from the solution \\textit{T}. Gaussian quadrature is used to perform the surface integration over each face of the control volume \\textit{i} in the above equation.  These faces are lines in 2-D spatial discretizations and rectangles in 3-D.\n\nThe value of $\\widetilde{T}$ is calculated, guided by a high order FEM interpolation $\\widehat T$ of the CV solution $T$, in fact $\\widetilde{T}$ is equal to the flux limited value of $\\widehat{T}$ over control volume faces, see Fig. \\ref{fem_cv_represent_a}. These high order fluxes are then subject to limiting to obtain the final fluxes used at the Gaussian quadrature points on the control volume faces at element boundaries.  Figures \\ref{fem_cv_represent_b} shows a 2-D element with the centred positions of the key variables indicated. In 3-D the element variables are also centred on the nodes and on the elements, however the value of $\\theta$ used for the transport terms are centred on the faces of the hexahedral elements.\n\n%%%==============================================\n%%% FIGURE 01 - Discretization \n%%%==============================================\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=15.0cm,height=10.cm]{./doc_figures/1D_FEM_CV}\n\\end{center}\n\\vspace{-5cm}}\n\\caption{1-D finite element showing CVs {\\it u, c, d} and face {\\it f}.}\n\\label{fem_cv_represent_a}\n\\end{figure}\n\n%%%==============================================\n%%% FIGURE 01 - Discretization \n%%%==============================================\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=9.0cm,height=7.0cm]{./doc_figures/FEM_elem}\n\\end{center}\n\\vspace{-1cm}}\n\\caption{Finite element used to discretize the fluids equations.  The central position of key solution variables are indicated here.}\n\\label{fem_cv_represent_b}\n\\end{figure}\n\nSuppose that each element $i$ of our finite element mesh has a control volume and a solution variable $\\hat T_i$ associated with it. Then the FEM solution $\\widehat{T}$ is related to the CV solution \\textit{T} by\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\int_{V} N_{i} (\\widehat{T} - T) \\,d V = 0, \\quad\n\\forall i\\in \\{1,2,...,{\\mathcal N}\\}\n\\end{displaymath}\nin which $N_{i}$ is the finite element basis function associated with node \\textit{i} and $M_{i}$ is the finite volume basis function (top hat function), which in our formulation is unity over element $i$ and zero elsewhere. In addition, the FEM representation of \\textit{T} is given by $\\widehat{T} = \\sum\\limits_{j=1}^{\\mathcal{N}} N_{j} \\widehat{T}_{j}$. Thus,\n%%\n%% - begin equation\n%%\n\\begin{equation}\nB \\underline{\\widehat{T}} = Q \\underline{T}\n\\label{BQ}\n\\end{equation}\nwith $B = \\int\\limits_{V} N_{i} N_{j} \\,d V$ and $Q =\\int\\limits_{V} N_{i} M_{j} \\,d V$. The vectors $\\underline{\\widehat{T}} = \\left(\\widehat{T}_{1}, \\widehat{T}_{2}, \\ldots, \\widehat{T}_{\\mathcal{N}} \\right)^{T}$, $\\underline{T} =\\left(T_{1}, T_{2}, \\ldots,  T_\\mathcal{M} \\right)^{T}$ contain the unknown finite element and CV values of $T$, respectively. Both matrices \\textit{B} and \\textit{Q} have sparse structure.\n\n%%\n%%********************************************************\n%%********************************************************\n%%\n\n\\subsection{Extrema detecting}\n\nTo determine where to apply first order instead of high order fluxes, extremas must be detected and if there is a smooth transition between the high and low order fluxes, the closeness to an extrema must be quantified. This is achieved using the normal variable diagram NVD approach \\index{\\fluidity Module! Transport methods! NVD approach} as follows. Suppose $T_{u}, T_{c}, T_{d}$ are ordered consecutively and $T_{f}$ is the face value between CVs \\textit{c} and \\textit{d} (see Fig. \\ref{fem_cv_represent_a}). In which case for a monotonic solution\n%%\n%% - begin equation\n%%\n\\begin{equation}\n\\mathcal{T}_{f} = \\frac{T_{f} - T_{u}}{T_{d} - T_{u}}  \\in [0,1]\n\\label{p4a}\n\\end{equation}\nwhere $\\mathcal{T}_{f}$ is the non-dimensional high order face value.  The non-dimensional upwind face value is\n\\begin{equation}\n\\mathcal{T}_{c} = \\frac{T_{c} - T_{u}}{T_{d} - T_{u}}\n\\label{p4b}\n\\end{equation}\nThe idea is to obtain a linear combination $\\widetilde{\\mathcal{T}}_{f}$ of $\\mathcal{T}_{f}$ and $\\mathcal{T}_{c}$ such that $\\widetilde{\\mathcal{T}}_{f}$ equals $\\mathcal{T}_{c}$ when there is a local extrema ($\\mathcal{T}_{c} \\notin [0,1]$ and the scheme becomes first order) and $\\widetilde{\\mathcal{T}}_{f}$ moves smoothly between this and the high order flux $\\mathcal{T}_{f}$ according to the curve shown on the NVD diagram \\citep[see][]{gomes_2008}. $\\widetilde{T}_{f}$ is calculated from\n\\begin{equation}\n\\widetilde{\\mathcal{T}}_{f} = \\frac{\\widetilde{T}_{f} - T_{u}}{T_{d} - T_{u}}.\n\\label{2.1a}\n\\end{equation}\nThe flux limited solution is\n\\begin{equation}\n\\widetilde{T}_{f} = \\widetilde{\\mathcal{T}}_{f} (T_{d} - T_{u}) + T_{u}.\n\\label{2.1b}\n\\end{equation}\n$\\widetilde{\\mathcal{T}}_{f}$ (see Fig. \\ref{fem_cv_represent_a}) in this equation is calculated from:% (see Fig. \\ref{nvddiag}):\n\\begin{equation}\n\\widetilde{\\mathcal{T}}_{f} =\n  \\begin{cases}\n    \\min \\{ \\widetilde{\\gamma} {\\cal T}_{c}, \\max \\{ 0, {\\cal T}_f\\} \\}, & \\text{if} \\\n    \\mathcal{T}_{c} \\in (0,1); \\\\\n    \\mathcal{T}_{f},  & \\text{otherwise},\n  \\end{cases}\n\\label{2.1c}\n\\end{equation}\nwith $\\widetilde{\\gamma} = 2.0$. Thus, at an extrema the first order non-oscillatory method will be applied.  The curve $\\mathcal{T}_{f} = 2\\mathcal{T}_{c}$ has been chosen as an upper bound on $\\widetilde{\\mathcal{T}}_{f}$ as this corresponds to a TVD condition in 1-D \\index{\\fluidity Module! Transport methods! TVD condition} with equally spaced cells/elements \\citep[see][]{hirsch_1990}.  One can use larger values of the gradient $\\widetilde{\\gamma}$ but convergence of the resulting non-linear iteration can suffer.  However, a larger gradient can help maintain sharper features in the solution, as reported by \\citet{jasak_1999}.  They recommend the use of a gradient of 6 ($\\widetilde{\\gamma} = 6$, Eqn. \\ref{2.1c}), they also recommend that the gradient should not be greater than 10 and not less than 2.  \\citet{piperno_1998} explain some useful criteria for constructing limiting functions.  In addition, they use a maximum NVD curve with C$^{1}$ continuity, which is claimed to improve convergence, and use a quotient of gradients as opposed to the quotient of differences used here in Eqns. \\ref{p4a}-\\ref{2.1a}. \n\n\n\\subsection{Extrema detection in multi-dimensions and isotropic limiting}\n\nWhen integrating over a face of a CV in multi-dimensions we denote the cell from which the velocity is coming from as \\textit{c} and the cell to which the velocity is pointing to \\textit{d} (as in the previous section) with corresponding solution variables of $T_{c}$ and $T_{d}$ and the far field upwind value $T_{u}$. The value of $T_{u}$, for multi-dimensional  problems, is not well defined and thus it is this the the remainder of this section concerns.\n\nThe surface integral in Eqn. \\ref{a} is calculated by summing the surface integrals over each face of CV \\textit{i}. This face surface integral is evaluated using Gaussian quadrature. The values of $\\widehat{T}$ at the Gauss points are limited using the NVD approach as described in the previous section, so that no new extrema are introduced into the solution \\textit{T}. This is achieved by considering the velocity at the Gauss points on the face of an element. Out of the two CVs sharing this face, the CV from which the velocity is pointing away from is chosen as CV $c$ and the other CV denoted as \\text{d}.\n\n\nThe minimum and maximum value of $T$ of the six CVs in 3-D and four CVs in 2-D, sharing a face with (less than this if near a boundary) with CV $c$ and CV \\textit{c} itself, which we denote as $T_{\\min}$ and $T_{\\max}$. A non-dimensional temperature is then obtained at the Gaussisn integration point from the high order temperature $T_{f}$, via Eqn. \\ref{2.1b} with the value of $T_{u}$ obtained from\n%%\n%% - begin equation\n%%\n\\begin{equation}\nT_{u} =\n\\begin{cases}\n   T_{\\max}, & \\text{if} \\ T_{d} \\leq T_{c}; \\\\\n   T_{\\min}, & \\text{if} \\ T_{d} > T_{c}.\n\\end{cases}\n\\label{rr}\n\\end{equation}\n\nThis then allows the flux limiting, Eqns. \\ref{2.1a}-\\ref{2.1c} to be applied. This approach is the recommended isotropic limiting method.  One can amend $T_{\\max}$ and $T_{\\min}$ to take into account variable grid resolution using instead:\n\n\\begin{equation}\nT_u = T_c + \\frac{\\Delta_{cd}}{\\Delta_{uc}} ( T_{\\max} - T_c) \n\\end{equation}\n\\noindent\nor\\\\ \n\\begin{equation}\nT_u = T_c + \\frac{\\Delta_{cd}}{\\Delta_{uc}} ( T_{\\min} - T_c) \n\\end{equation}\ndepending on the criteria in Eqn. \\ref{rr}. $\\Delta_{cd}$ is proportional to the distance between the CV cells $c$ and $d$ and $\\Delta_{uc}$ is proportional to the distance between the CV cells $u$ and $c$. For example, $\\Delta_{cd} = \\frac{1}{2}(V_c + V_d)$ and  $\\Delta_{uc} = \\frac{1}{2}(V_{max} + V_c)$ or  $\\Delta_{uc} = \\frac{1}{2}(V_{min} + V_c)$ again  depending on criteria expressed by Eqn. \\ref{rr}. $V_{min}$ is the volume of  the cell surrounding CV $c$ that has a minimum value of $T$,  $V_{max}$ is the volume of  the cell surrounding CV $c$ that has a maximum value of $T$, and $V_c$ and $V_d$ are the volumes of cells $c$ and $d$.  The alternative would be to use geometrical distances to define $\\Delta_{cd}$ and $\\Delta_{uc}$. \n\nThe most relaxed form of limiting is obtained from\n\\begin{equation}\n\\mathcal{T}_{f} = \\frac{T_{f} - T_{\\min}}{T_{\\max} - T_{\\min}}\n\\label{r}\n\\end{equation}\n\\noindent\nand\n\\begin{equation}\n\\mathcal{T}_{c} = \\frac{T_{c} - T_{\\min}}{T_{\\max} - T_{\\min}}\n\\label{r_p}\n\\end{equation}\nwhich results in useful bounded schemes. Moreover the scheme defined by Eqns. \\ref{r} and \\ref{r_p} introduce less dissipation than other bounded\nschemes. These two flux limiting methods will prevent any new extrema from forming, however for a given direction new extrema can form along this direction results in oscillations in the solution. However, by choosing a control volume value in the upwind direction from face $f$ and just upwind from CV $c$ then this problem can be circumvented.\n\n\n\\subsection{Time Discretization} \\label{time_discretisation}\\index{\\fluidity Module! Transport methods ! Time discretisation}\nA new time discretisation method is developed here. When high order discretization in time \nis sought then the method is based on Crank-Nicholson time stepping.  The Crank-Nicholson method was chosen, because it has the simplicity of a two level time stepping method, is unconditionally stable and second order accurate. \nHowever, if interface capturing then the scheme is based on explicit forward Euler time stepping which \nintroduces negative dissipation and is thus a compressive scheme which helps maintain sharp interfaces. \nMoreover, the use of time steps of the order of the grid Courant number and above can result in numerical oscillations and unphysical solutions. Thus, a parameter $\\theta$ is introduced, in which $\\theta$ = 0 corresponds to the forward Euler time stepping method, \n$\\theta$ = $\\frac{1}{2}$ corresponds to the Crank-Nicholson time stepping method and $\\theta$ = 1 backward-Euler.\nThen using Eqns. \\ref{CV1} and \\ref{a} the time stepping for Eqn. \\ref{traneq} takes the form:\n%%\n%% - begin equation\n%%\n\\begin{eqnarray}\n\\int M_i \\left( \\frac{T_{i}^{n+1} -T_{i}^{n}}{\\Delta t} - s \\right) \\,dV= \\nonumber \\\\\n\\int_{\\Gamma_{CV_{i}}} \\left[\\theta\\left(\\mathbf{a}^{n+1}\\cdot \\mathbf{n} \\widetilde{T}^{n+1}\n+\\mathbf{n}\\cdot k^{n+1}\\nabla \\widetilde{T}^{n+1}   \\right)+\\left(1-\\theta\\right)\\left(\\mathbf{a}^{n}\\cdot \\mathbf{n} \\widetilde{T}^{n}\n+\\mathbf{n}\\cdot k^{n}\\nabla \\widetilde{T}^{n}\n \\right)  \\right]d\\Gamma\n \\label{theta}\n\\end{eqnarray}\nFor each time step a value of $\\theta$ is calculated at each CV face based on the satisfaction of a TVD criteria. In 1-D, assuming the flux limiting values of the flux at the $i-{\\frac{1}{2}}$ and $i+{\\frac{1}{2}}$ boundaries (see Fig. \\ref{fem_cv_represent_c}) are $h^{n}_{i-{\\frac{1}{2}}}$ and $h^{n}_{i+{\\frac{1}{2}}}$ at time level \\textit{n},  the time discretization becomes:\n%%\n%% - begin equation\n%%\n\\begin{equation}\n\\Delta x_i \\left( \\frac{T_{i}^{n+1} - T_{i}^{n}}{\\Delta t} \\right)\n= \\theta_{i-\\frac{1}{2}}^{n+{\\frac{1}{2}}} h_{i-\\frac{1}{2}}^{n+1}\n+(1-\\theta_{i-\\frac{1}{2}}^{n+{\\frac{1}{2}}}) h_{i-\\frac{1}{2}}^n\n-\\theta_{i+\\frac{1}{2}}^{n+\\frac{1}{2}} h_{i+\\frac{1}{2}}^{n+1}\n-(1-\\theta_{i+\\frac{1}{2}}^{n+\\frac{1}{2}}) h_{i+\\frac{1}{2}}^n\n\\label{thetareq1}\n\\end{equation}\nwith\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\nh_{i-\\frac{1}{2}}^{n} = a_{i-\\frac{1}{2}}^{n}\nT_{i-\\frac{1}{2}}^{n}\n +k_{i-\\frac{1}{2}}^n \\frac{\\partial\nT^n}{\\partial x}\\left\\vert_{i-\\frac{1}{2}}\\right.\n\\end{displaymath}\n\n%%%==============================================\n%%% FIGURE 01 - Discretization issues\n%%%==============================================\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=10.0cm,height=7.5cm]{./doc_figures/FEM_elem2}\n\\end{center}\n\\vspace{-3.cm}}\n\\caption{Positioning of variables in and on the boundary of CV {\\it i}.}\n\\label{fem_cv_represent_c}\n\\end{figure}\n%%%==============================================\n%%%                 FIGURE 01 \n%%%==============================================\n\n\n\n%%%==============================================\n%%%             FIGURE - P1DGP2\n%%%==============================================\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{0.cm}\n\\includegraphics[width=7.0cm,height=7.cm]{./doc_figures/p1dg-p2-elepic}\n\\hspace{-0.cm}\n\\includegraphics[width=7.0cm,height=7.cm]{./doc_figures/p1dg-p2-dgsat-elepic}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{6.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{p1dgp2_ele-dgsat_pics}\n\\caption{2D finite element containing control volumes is shown. The circles represent the underlying finite element nodes and dashed lines the boundaries of the control volumes. The crosses show typical quadrature points used to integrate around the control volumes. (a) Continuous pressure and tracer solution between the elements. (b) Discontinuous pressure and tracer between elements.  }\n\\end{figure}\n%%%==============================================\n%%%             FIGURE - P1DGP2\n%%%==============================================\n\n\\noindent\n$\\Delta x_{i}$ is the width of the $i^{th}$ CV and $\\theta_{i+\\frac{1}{2}}^{n+\\frac{1}{2}}$ is the value of $\\theta$ associated with face $i+\\frac{1}{2}$ and the time step from time level $n$ to $n+1$.  The representation of $k_{i-\\frac{1}{2}}^n \\frac{\\partial T^n}{\\partial x}\\vert_{i-\\frac{1}{2}}$ is considered in a following section.% a simple example of which is $\\frac{T_i^{n+1}-T_{i-1}^n}{\\Delta x}$ in which $\\Delta x$ is the size of the control volumes.  \n\nRe-arranging Eqn. \\ref{thetareq1}:\n%%\n%% - begin displaymath\n%%\n\\begin{eqnarray}\n\\left( \\Delta x_i - \\Delta t \\frac{\\left[\n-\\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}(\n-h_{i-\\frac{1}{2}}^{n+1}+h_{i-\\frac{1}{2}}^{n})\n+\\widehat{\\theta}_{i+\\frac{1}{2}}^{n+\\frac{1}{2}}(\n-h_{i+\\frac{1}{2}}^{n+1}+h_{i+\\frac{1}{2}}^{n}) \\right]}\n{T_i^{n+1}-T_i^n} \\right)\n\\left(\\frac{T_i^{n+1} - T_i^n}{\\Delta t} \\right) =\\nonumber\\\\\nh_{i-\\frac{1}{2}}^{n+1}-h_{i+\\frac{1}{2}}^{n+1}\\nonumber\n\\end{eqnarray}\nwith\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}  = 1-\\theta_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}.\n\\end{displaymath}\nNow since backward Euler time stepping is TVD in the same way that first order upwind scheme is spatially, a positive definite mass matrix is a sufficient condition for the backward Euler scheme above to be TVD \\citep[see][]{hirsch_1990}\\index{\\fluidity Module! Transport methods! TVD condition}.  Thus, the diagonal mass matrix (the term in brackets) must be non-negative, after re-arranging this requirement becomes\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\frac{\\Delta t}{\\Delta x_{i}\\left(T_i^{n+1} - T_i^{n}\\right)} \\left[ \\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}\\left(h_{i-\\frac{1}{2}}^{n} - h_{i-\\frac{1}{2}}^{n+1}\\right)-\\hat\\theta_{i+\\frac{1}{2}}^{n+\\frac{1}{2}}\\left(h_{i+\\frac{1}{2}}^{n}-h_{i+\\frac{1}{2}}^{n+1}\\right) \\right] \\leq 1\n\\end{displaymath}\nand thus\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\left(\\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}\np_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}\n-\\widehat{\\theta}_{i+\\frac{1}{2}}^{n+\\frac{1}{2}}\nq_{i+\\frac{1}{2}}^{n+\\frac{1}{2}} \\right) \\leq 1\n\\end{displaymath}\nwith\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\np_{i-\\frac{1}{2}}^{n+\\frac{1}{2}} = \\left( \\frac{h_{i-\\frac{1}{2}}^{n}\n- h_{i-\\frac{1}{2}}^{n+1}}{T^{n+1}_{i} - T_{i}^{n}} \\right)\n\\frac{\\Delta t}{\\Delta x_{i}}  \\quad \\text{and} \\quad\nq_{i+\\frac{1}{2}}^{n+\\frac{1}{2}} = \\left(\n\\frac{h_{i+\\frac{1}{2}}^n-h_{i+\\frac{1}{2}}^{n+1}}{T^{n+1}_{i} - T_{i}^{n}}\n\\right) \\frac{\\Delta t}{\\Delta x_{i}}\n\\end{displaymath}\nwhich is satisfied if\n%%\n%% - begin equation\n%%\n\\begin{equation}\n- \\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}\np_{i-\\frac{1}{2}}^{n+\\frac{1}{2}} \\leq \\frac{1}{2} \\quad \\text{and} \\quad\n- \\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}\nq_{i-\\frac{1}{2}}^{n+\\frac{1}{2}} \\geq\n\\frac{1}{2}\n\\label{half}\n\\end{equation}\nThus, to make the value of $\\theta_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}= 1 - \\widehat{\\theta}_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}$ as close to $\\theta_{aim}$ as possible we choose\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\theta_{i-\\frac{1}{2}}^{n+\\frac{1}{2}} = \\max \\left\\{ \\theta_{aim},\n1 - \\beta \\min \\left\\{ \\left|\\frac{1}{p_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}}\\right|,\n\\left|\\frac{1}{q_{i-\\frac{1}{2}}^{n+\\frac{1}{2}}} \\right| \\right\\} \\right\\}\n\\end{displaymath}\nwith $\\beta=\\frac{1}{2}$ and $\\theta_{aim}=\\frac{1}{2}$ is the base scheme and is the \nhigh order accurate Crank Nickolson scheme and $\\theta_{aim}=0$ if it is forward Euler time \nstepping which is favoured when interface capturing. \n\n\\subsection{Multi-dimensional temporal limiting}\n\\label{multidimtemplim}\n\nThe high resolution $\\theta$ method can be extended to multi-dimensions by replacing $h_{i-\\frac{1}{2}}^{n}$ with the integral of $\\tilde{h}_{f}^{n}$ over face \\textit{f} and $\\Delta x_{i}$ replaced by the volume $L_{i}$ (contribution from diagonal mass matrix) of the $i^{th}$ CV. Using similar arguments to the 1-D case the following expression for $\\theta_f^{n+\\frac{1}{2}}$ of face \\textit{f} is obtained:\n%%\n%% - begin equation\n%%\n\\begin{equation}\n\\theta_f^{n+\\frac{1}{2}}=\\max \\left\\{ \\theta_{aim}, 1 - \\beta \\min\\left\\{\n\\left|\\frac{1}{p_{f}^{n+\\frac{1}{2}}}\\right|,\\left|\n\\frac{1}{q_{f}^{n+\\frac{1}{2}}} \\right| \\right\\} \\right\\}\n\\label{thet1}\n\\end{equation}\nwith\n%%\n%% - begin equation\n%%\n\\begin{equation}\np_f^{n+\\frac{1}{2}} =\n\\frac{g_f^{n+\\frac{1}{2}}\\Delta t}{(T^{n+1}_{c} - T_{c}^{n}) L_{c}}\n\\quad \\text{and} \\quad q_f^{n+\\frac{1}{2}} =\n\\frac{g_f^{n+\\frac{1}{2}}\\Delta t}{(T^{n+1}_{d} - T_{d}^{n}) L_{d}}\n\\label{thet2}\n\\end{equation}\nand\n%%\n%% - begin equation\n%%\n\\begin{equation}\ng_f^{n+\\frac{1}{2}}= (\\tilde{h}_{f}^{n} - \\tilde{h}_f^{n+1})\n\\label{gf}\n\\end{equation}\nCVs \\textit{c} and \\textit{d} in these equations refer to the two CVs that are adjacent to face \\textit{f}, (see Fig. \\ref{fem_cv_represent_b}). Extensions of this method to differential equations with time-dependent terms like $\\frac{\\partial \\rho T}{\\partial t}$ are realized by replacing, in Eqn. \\ref{thet2}, $T_j^n$ and $T_j^{n+1}$ by $T_{j}^{n} \\rho_{j}^{n}$ and $T_{j}^{n+1} \\rho_j^{n+1}$ respectively for $j = c$ and $j = d$.\n\n\n\n\n\\subsection{Essentially Non-Oscillatory Based Advection Method}\n\\label{Essentially Non-Oscillatory Based Advection Method}\nHere we use the ideals behind the Essentially Non-Oscillatory ENO advection methods to produce a \nCV advection method that is high order. However, the methods described are are not necesserily oscillation \nfree but do surpress oscillations greatly. \nThis is achieved by forming a number of high order \ninterpolations of the CV solutions and choosing a weighted sum of these (with positive weights) \nas the solution at the CV boundary quadrature points, see Fig \\ref{p1dgp2_ele-dgsat_pics}. \n\nHere, one first forms the FEM interpolation of the \nCV solution $\\psi_{fem}$, then interpolated the current element \nsolution to find that quadrature point value of $\\psi_{fem}$. \nIn addition, one extrapolates the solution from some of the surrounding elements. \nOne chooses as the CV quadrature value the closest of these to the upwind CV solution at that \nquadrature point. \nIf the CV upwind solution is contained within the maximum and minimum of these quadrature values \nthen one chooses the CV upwind solution as the CV quadrature value. \n\nIt remains to select which elements one considers. The default option is \nto choose the current element and the element in the upwind direction - the 1st element met by a line drawn \nnormal to the CV face at the quadrature point in the upwind direction. \nThis is extended in the ENOEXT option \nto also include the element met in the downwind direction - opposite direct to the former direction. \nFor quadratic elements the default amends this slightly for the quadrature points on the CV \nin the corners of the tetrahedra to include only the current element and out of the other two elements the \none that is closes to this quadrature point. \nFor quadrature points between elements (used only in fully discontinuous elements) one simply considers the two \nelements neighbouring this quadrature point to form the ENO solution.  \n\n\n\n\n\\subsection{Control Volume Diffusion Discretization}\n\\label{section_diff_discretisation}\\index{\\fluidity ! Transport methods ! Diffusion discretisation}\n\nThe high resolution $\\theta$ method can also be used with diffusion by adding to $g_{f}^{n+\\frac{1}{2}}$ in Eqn. \\ref{gf} the flux limited discretized contribution, integrated along face $i-\\frac{1}{2}$.\nIn 1-D this might lead to\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\ng_{i-\\frac{1}{2}}^{n+\\frac{1}{2}} = h_{i-\\frac{1}{2}}^n-h_{i-\\frac{1}{2}}^{n+1}\n= a_{i-\\frac{1}{2}}^n T_{i-\\frac{1}{2}}^n -\na_{i-\\frac{1}{2}}^{n+1} T_{i-\\frac{1}{2}}^{n+1} + \\kappa \\left(\n\\frac{T_{i}^n-T_{i-1}^n}{\\frac{1}{2}(\\Delta x_{i-1}+\\Delta x_i )}\n- \\frac{T_{i}^{n+1}-T_{i-1}^{n+1}}{\\frac{1}{2}(\\Delta\nx_{i-1}+\\Delta x_i )}\\right)\n\\end{displaymath}\nin which $\\kappa$ is the diffusion coefficient. In multi-dimensions this becomes\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\ng_{f}^{n+\\frac{1}{2}} = \\tilde h_{f}^n-\\tilde h_{f}^{n+1}\n\\end{displaymath}\nin which\n%%\n%% - begin displaymath\n%%\n\\begin{equation}\n\\tilde{h}_{f}^{n} = \\int_{\\Gamma_f} \\left( a \\cdot n T^{n}\n+ \\kappa \\frac{\\partial T^n}{\\partial n_x} \\right) \\,d\\Gamma\n\\label{16a}\n\\end{equation}\nwhere $n_x$ is the normal to the control volume. Now if the underlying scheme that calculates $\\frac{\\partial T^n}{\\partial n_x}$ is non-oscillatory then the advection-diffusion scheme will be non-oscillatory. A simple example of this is\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\frac{\\partial T^n}{\\partial n_x}\\Big\\vert_{no_f} = \\frac{\\partial T^n}{\\partial n_x} \\Big\\vert_{f} = \\frac{T_{c}^{n} - T_{d}^{n}}{\\Delta x_{f}}\n\\end{displaymath}\nin which, as before, the subscripts denote cells that share face \\textit{f} (see Fig. \\ref{fem_cv_represent_b}), $\\Delta x_{f}$ is a measure of the component of distance between the centres of the CVs \\textit{c} and \\textit{d} in the normal direction to face $f$. This equation also serves as a definition of $\\frac{\\partial T^{n}}{\\partial n_x}\\vert_{no_f}$. The accuracy of this approximation can be improved, but once again non-linearity must be used to ensure boundedness of the scheme. Suppose the underlying non-oscillatory approximation to $\\frac{\\partial T}{\\partial n_x}$ is $\\frac{\\partial T^n}{\\partial n_x}\\vert_{no_f}$ then any positive multiple of this will result in a bounded scheme and as such the TVD condition is\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n{\\frac{\\partial \\widetilde{T}^{n}}{\\partial n_x}\\Big\\vert_{f}\n\\frac{\\partial T^{n}}{\\partial n_x}\\Big\\vert_{no_f}} \\geq 0\n\\end{displaymath}\nThe scheme is bounded if the high order limited derivative $\\frac{\\partial \\widetilde{T}^{n}}{\\partial n_x}\\vert_{f}$ has the same sign as $\\frac{\\partial T^{n}}{\\partial n_x}\\vert_{no_f}$. However, to avoid difficulties with the non-linear convergence the derivative of $\\frac{\\partial \\widetilde{T}^{n}}{\\partial n_x}\\vert_{f}$ from the high order approximation $\\frac{\\partial T^{n}}{\\partial n_x}\\vert_{f}$ is limited with\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\ns_f \\frac{\\partial \\widetilde{T}^{n}}{\\partial n_x}\\Big\\vert_f\n= \\max \\left\\{ \\gamma_2 s_f \\frac{\\partial T^{n}}{\\partial n_x}\\Big\\vert_{no_f},\n\\min \\left\\{ s_f \\frac{\\partial T^{n}}{\\partial n_x}\\Big\\vert_{f},\n\\gamma_{1} s_{f} \\frac{\\partial T^{n}}{\\partial n_x}\\Big\\vert_{no_f} \\right\\}\n\\right\\}\n\\end{displaymath}\nwith\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\n\\gamma_1 \\geq 1 \\geq \\gamma_2 \\geq 0\n\\end{displaymath}\nand\n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\ns_f =\n  \\begin{cases}\n     1 & \\ \\text{if} \\ \\frac{\\partial T^n}{\\partial n_x}\\vert_{no_f} \\geq 0; \\\\\n    -1 & \\ \\text{otherwise} \\\n\\end{cases}\n\\end{displaymath}\nand $\\frac{\\partial T^{n}}{\\partial n_x}\\vert_{f}$ is the high order flux, which as with the advection scheme can be obtained from any high order representation of \\textit{T}. The authors recommended that  $\\gamma_{1} = 2, \\ \\ \\gamma_2 = \\frac{1}{2}$.  An example, using the FEM discretization would be to use the derivative along a face $f$ of a control volume from the FEM representation. For derivatives along the boundaries of an element one would use a finite element average of the derivative of the FEM representation of one element and the other sharing this face. \n\nIn the case of a diffusion tensors ${\\underline{\\underline k}}$ this approach using the approximation: \n\n\\begin{equation}\nn\\cdot {\\underline{\\underline k}} \\nabla T = \n\\min\\left\\{ \\beta_{max}\\frc{k_{norm}}{{\\Delta x}_{f}} , \\max\\left\\{ \\beta_{min}\\frc{k_{norm}}{{\\Delta x}_{f}} , \\left( \\frc{k}{\\Delta x} \\right)_{\\text{eff}} \\right\\} \\right\\}\\left(T_{current}-T_{neighbour}\\right)\n\\label{non-lin-diff}\n\\end{equation}\nwhere \n%\\help\n\\begin{equation}\n\\left( \\frc{k}{\\Delta x} \\right)_{\\text{eff}} =  \n- \\frc{1}{2} \\frc{ n\\cdot \\left[ \\left({\\underline{\\underline k}} \\nabla T\\right)_{neighbour} + \\left({\\underline{\\underline k}} \\nabla T\\right)_{current} \\right] }{T_{current}-T_{neighbour}} \n\\label{non-lin-diff-eff} \n\\end{equation}\nand where $T_{current}$ is the solution in the current control volume and $T_{neighbour}$ is the solution in the neighbouring control volume between which the surface integral around the current control volume is being performed. $k_{norm}$ is the normal component of the tensor ${\\underline{\\underline k}}$ (normal to the boundary of the control volume) and is approximated here with $k_{norm} =n^T {\\underline{\\underline k}} n $.  It is obtained from equation \n\\ref{non-lin-diff-eff} using the approximation:\n\n\\begin{equation}\n\\frac{k_{norm}}{{\\Delta x}_f}=  \n \\frac{ n\\cdot {\\underline{\\underline k}} n (T_{current}-T_{neighbour})}{{\\Delta x}_f(T_{current}-T_{neighbour})}\n= \\frac{n^T {\\underline{\\underline k}} n}{{\\Delta x}_f}. \n\\label{non-lin-diff-eff-approx} \n\\end{equation}\n${\\Delta x}_f$ is the distance between the centre of the control volumes associated with $T_{current}$ and $T_{neighbour}$.  $\\beta_{min}$ is the minimum fraction of the $\\frac{k_{norm}}{{\\Delta x}_{f}}$ to use $\\left(\\right.$we use $\\beta_{min}=0.05\\left.\\right)$ and $\\beta_{min}$ defines the upper bound on the value of the effective diffusivity $\\left(\\right.$we use $\\beta_{max}=100\\left.\\right)$.  Without $\\beta_{max}$ as $T_{current}$ and $T_{neighbour}$ become close this would make  $n\\cdot {\\underline{\\underline k}} \\nabla T$ large. \n\nThere are three main advantages of the non-linear diffusion scheme above: \n\\begin{enumerate}[1)]\n\\item the method does not introduce oscillations due to the high order representation of diffusion; \n\\item the method is high order accurate most of the time; \n\\item the method always result in a symmetric positive definite discretisation matrix (a property not shared with many high order diffusion control volume discretisations); \n\\item the method results in a compact stencil and thus the resulting matricies are sparse. \n\\end{enumerate}\n\nFinally, it is noted that the FEM discretization using linear triangle, tetrahedra, rectangles or hexahedra of the diffusion term can also be bounded with restrictions on the distortion of the elements \\citep[see][]{mizukami_1985}.\n\n\n%%%==============================================\n%%% FIGURE 01 - Discretization \n%%%==============================================\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=15.0cm,height=10.0cm]{./doc_figures/CVFEM_1D}\n\\end{center}\n\\vspace{-1cm}\n}\n\\caption{1-D finite element }\n\\label{fem_cv_represent_c}\n\\end{figure}\n\n\\subsection{Discontinuous Galerkin diffusion discretisation}\n\nA simple form the DG discretised equations for diffusion is: \n\n\\begin{equation}\n\\int_{V_{ele}} \\nabla N_i {\\underline {\\underline k}} \\nabla T_{fem}^n d\\Omega \n+\\int_{\\Gamma_{ele}} N_i \\alpha \\left({T_{fem}^n}_{current}-{T_{fem}^n}_{neighbour} \\right)  d\\Gamma . \n\\label{dg-variational-diff-low} \n\\end{equation}\nThis has an underlying variational principle behind it. That is \n\\begin{equation}\n\\frac{1}{2}\n\\int_{V_{ele}} \\nabla T_{fem}^n {\\underline {\\underline k}} \\nabla T_{fem}^n d\\Omega \n+\\frac{1}{2} \n\\int_{\\Gamma_{ele}} \\alpha \\left({{T_{fem}^n}_{current}-{T_{fem}^n}_{neighbour}} \\right)^2 \nd\\Gamma, \n\\label{variational-prin} \n\\end{equation}\n and \nthus the discretised equations are guaranteed to be symmetric and positive definite as long as ${\\underline {\\underline k}}$ is sym-pos-def and scalar $\\alpha$ is positive. The first term in Eqn. \\ref{variational-prin} attempts to flatter the solution within an element and the latter surface integral attempts to produce continuity of the solution between elements. This is very similar to the way Robin boundary condition are typically applied using FEM: \n%%\n%% - begin displaymath\n%%\n\\begin{displaymath}\nk \\frac{\\partial T^{n}}{\\partial n} = \\alpha (T - T_{0})\n\\end{displaymath}\ncan be applied directly in Eqn. \\ref{16a}.\n\nTesting with DG basis function $N_i$ and applying Greens theory to the diffusion term one obtains: \n\n\\begin{equation}\n\\int_{V_{ele}} \\nabla N_i \\underline {\\underline k} \\nabla T_{fem}^n d\\Omega \n-\\int_{\\Gamma_{ele}} N_i n\\cdot \\underline {\\underline k} \\nabla T_{fem}^n d\\Gamma . \n\\label{dg-variational-diff-high} \n\\end{equation}\nIf one can turn this into the same form as Eqn. \\ref{dg-variational-diff-low} (with a suitable chosen $\\alpha$) then the stencil will be very compact and the method of evaluating the diffusion term for DG will have the same advantages as for CV as listed in Section \\ref{section_diff_discretisation}.  The first term in Eqn. \\ref{dg-variational-diff-high} is formed simply by placing  $T_{fem}^n=\\sum_j Q_j {T_{fem}^n}_j$ into this equation. However, the term $n\\cdot \\underline {\\underline k} \\nabla T_{fem}^n $ is approximated as described in the next section from derivatives both sides of the element interface. That is the diffusion operator between elements is formed in the same manner as for the control volume discretisation using:\n\\begin{equation}\n\\left( \\frac{k}{\\Delta x} \\right)_{eff} =  \n- \\frac{1}{2} \\frac{ n\\cdot \\left[\\left({\\underline{\\underline k}} \\nabla T_{fem}\\right)_{neighbour} + \\left({\\underline{\\underline k}} \\nabla T_{fem}\\right)_{current} \\right] }{{T_{fem}}_{current}-{T_{fem}}_{neighbour}} . \n\\label{dg-non-lin-diff-eff} \n\\end{equation}\nThis is bounded from above and below using an equation similar to Eqn. \\ref{non-lin-diff}, but with a length scale $\\Delta x_f$ being the distance between the centroids of the neighbouring elements. Therefore:\n\\begin{equation}\n\\alpha=\\min\\left\\{  \\beta_{max}\\frac{k_{norm}}{{\\Delta x}_{f}} , \\max\\left\\{ \\beta_{min}\\frac{k_{norm}}{{\\Delta x}_{f}} , \n\\left( \\frac{k}{\\Delta x} \\right)_{eff}\n\\right\\} \\right\\} \n\\label{dg-alpha-def} \n\\end{equation} \nand is a positive scaler. In addition, it is easy to see from equation \n\\ref{dg-non-lin-diff-eff}, that:\n\\begin{equation}\n\\left( \\frac{k}{\\Delta x} \\right)_{eff} \\approx  \n  \\frac{ n\\cdot {\\underline{\\underline k}} n({T_{fem}}_{current}-{T_{fem}}_{neighbour}) }\n{{\\Delta x}_{f}({T_{fem}}_{current}-{T_{fem}}_{neighbour})} \n=\\frac{1}{{\\Delta x}_{f}} { n}^T {\\underline{\\underline k}} { n}. \n\\label{k-norm-full} \n\\end{equation}\nand thus\n\\begin{equation}\nk_{norm}={ n}^T {\\underline{\\underline k}} { n}. \n\\label{k-norm} \n\\end{equation} \nIn this work we use a distance $\\Delta x_f=\\frac{1}{8} d_{nab\\;cur}$ in \nwhich $d_{nab\\;cur}$ is the distance between the centroids of the two neighbouring elements and $n$ is the normal to the element surface.\n \n\n\\subsection{DG discretization of viscocity in stress form} \nIn tensor form the viscocity discretization proceeds as described in the \nprevious section, but for each velocity component $u$, $v$ and $w$ seperately (or $u_1$, $u_2$, $u_3$). \nFor the stress form of viscocity, consider the momentum equation:\n\\begin{equation}\n\\rho \\frac{ D u_i}{D t} = \\frac{\\partial \\sigma_{i\\,k}}{\\partial x_k} +s_{mom}\n\\end{equation}\nwith \n\\begin{equation}\n\\sigma_{i\\, k}=\\mu_{i\\, k} \\left( \n\\frac{\\partial u_k}{\\partial x_i} +  \\frac{\\partial u_i}{\\partial x_k} \n-\\delta_{i\\, k} \\frac{2}{3} \\nabla\\cdot {\\bf u} \\right)  +  \\mu_{vol} \\delta_{i\\, k} \\nabla\\cdot {\\bf u}. \n\\end{equation}\nin which $\\mu_{vol} $ is the volumetric viscocity.  \n\nThe viscous term expanded becomes:\n\n\\begin{equation}\n\\frac{\\partial ( \\mu_{xx}\n(\n\\frac{\\partial u}{\\partial x}+\\frac{\\partial u}{\\partial x})\n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial x}\n+\n\\frac{\\partial \\mu_{xy}\n(\n\\frac{\\partial v}{\\partial x}+\\frac{\\partial u}{\\partial y})\n}\n{\\partial y}\n+\n\\frac{\\partial \\mu_{xz}\n(\n\\frac{\\partial w}{\\partial x}+\\frac{\\partial u}{\\partial z})\n}\n{\\partial z}, \n\\label{visc-stress-u} \n\\end{equation}\n\n\n\n\\begin{equation}\n\\frac{\\partial \\mu_{yx}\n(\n\\frac{\\partial u}{\\partial y}+\\frac{\\partial v}{\\partial x}\n)}\n{\\partial x}\n+\n\\frac{\\partial (\\mu_{yy}\n(\n\\frac{\\partial v}{\\partial y}+\\frac{\\partial v}{\\partial y})\n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial y}\n+\n\\frac{\\partial \\mu_{yz}\n(\n\\frac{\\partial w}{\\partial y}+\\frac{\\partial v}{\\partial z})\n)}\n{\\partial z}, \n\\label{visc-stress-v} \n\\end{equation}\n\n\n\n\\begin{equation}\n\\frac{\\partial \\mu_{zx}\n(\n\\frac{\\partial u}{\\partial z}+\\frac{\\partial w}{\\partial x})\n}\n{\\partial x}\n+\n\\frac{\\partial \\mu_{zy}\n(\n\\frac{\\partial v}{\\partial z}+\\frac{\\partial w}{\\partial y})\n}\n{\\partial y}\n+\n\\frac{\\partial ( \\mu_{zz}\n(\n\\frac{\\partial w}{\\partial z}+\\frac{\\partial w}{\\partial z})\n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial z}. \n\\label{visc-stress-w} \n\\end{equation}\n\nThe DG discretization of these becomes \nfor u:\n% U: \n\\begin{equation}\n\\int_E \n\\frac{\\partial N_i}{\\partial x} (2\\mu_{xx}\n\\frac{\\partial u}{\\partial x}\n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n\\frac{\\partial N_i}{\\partial y} \\mu_{xy}\n(\n\\frac{\\partial v}{\\partial x}+\\frac{\\partial u}{\\partial y})\n+\n\\frac{\\partial N_i}{\\partial z} \\mu_{xz}\n(\n\\frac{\\partial w}{\\partial x}+\\frac{\\partial u}{\\partial z})\n dV+\n\\label{visc-stress-u-Ni} \n\\end{equation}\n\\begin{equation}\n\\int_{\\Gamma_E} \nN_i (n_x (2\\mu_{xx}\n\\frac{\\partial u}{\\partial x}\n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n {n_y} \\mu_{xy}\n(\n\\frac{\\partial v}{\\partial x}+\\frac{\\partial u}{\\partial y})\n+\n{n_z} \\mu_{xz}\n(\n\\frac{\\partial w}{\\partial x}+\\frac{\\partial u}{\\partial z})\n )\\d\\Gamma,\n\\label{visc-stress-u-n} \n\\end{equation}\nfor v:\n% V: \n\\begin{equation}\n\\int_E \n\\frac{\\partial N_i}{\\partial x} \\mu_{yx}\n(\n\\frac{\\partial u}{\\partial y}+\\frac{\\partial v}{\\partial x}\n)\n+\n\\frac{\\partial N_i} {\\partial y}(2\\mu_{yy}\n\\frac{\\partial v}{\\partial y}\n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n\\frac{\\partial N_i}{\\partial z} \\mu_{yz}\n(\n\\frac{\\partial w}{\\partial y}+\\frac{\\partial v}{\\partial z})\n dV+\n\\label{visc-stress-v-Ni} \n\\end{equation}\n\\begin{equation}\n\\int_{\\Gamma_E} \nN_i({n_x} \\mu_{yx}\n(\n\\frac{\\partial u}{\\partial y}+\\frac{\\partial v}{\\partial x}\n)\n+\n{n_y}(2\\mu_{yy}\n\\frac{\\partial v}{\\partial y}\n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n{n_z} \\mu_{yz}\n(\n\\frac{\\partial w}{\\partial y}+\\frac{\\partial v}{\\partial z})\n )d\\Gamma,\n\\label{visc-stress-v-n} \n\\end{equation}\nfor w:\n% W: \n\\begin{equation}\n\\int_E \n\\frac{\\partial N_i}{\\partial x} \\mu_{zx}\n(\n\\frac{\\partial u}{\\partial z}+\\frac{\\partial w}{\\partial x})\n+\n\\frac{\\partial N_i}{\\partial y} \\mu_{zy}\n(\n\\frac{\\partial v}{\\partial z}+\\frac{\\partial w}{\\partial y})\n+\n\\frac{\\partial N_i}{\\partial z} (\\mu_{zz}\n2\\frac{\\partial w}{\\partial z}\n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n) dV  +\n\\label{visc-stress-w-Ni} \n\\end{equation}\n\\begin{equation}\n\\int_{\\Gamma_E} \nN_i ({n_x} \\mu_{zx}\n(\n\\frac{\\partial u}{\\partial z}+\\frac{\\partial w}{\\partial x})\n+\n{n_y} \\mu_{zy}\n(\n\\frac{\\partial v}{\\partial z}+\\frac{\\partial w}{\\partial y})\n+\n{n_z}  (\\mu_{zz}\n2\\frac{\\partial w}{\\partial z}\n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)  )d\\Gamma. \n\\label{visc-stress-w-n} \n\\end{equation}\nFor simplicity the surface integrals in the above are \nexpressed as for u:\n\\begin{equation}\n\\int_{\\Gamma_E} \\alpha_{xx} (u_{cur}-u_{nab}) d\\Gamma,\n\\end{equation}\nfor v:\n\\begin{equation}\n\\int_{\\Gamma_E} \\alpha_{yy} (v_{cur}-v_{nab}) d\\Gamma,\n\\end{equation}\nfor w:\n\\begin{equation}\n\\int_{\\Gamma_E} \\alpha_{zz} (w_{cur}-w_{nab}) d\\Gamma,\n\\end{equation}\n\nwith\n\\begin{equation}\n\\alpha_{xx}=\n\\min\\left\\{  \\beta_{max}\\frac{\\mu_{norm-xx}}{{\\Delta x}_{f}} , \\max\\left\\{ \\beta_{min}\\frac{\\mu_{norm-xx}}{{\\Delta x}_{f}} , \n\\left( \\frac{\\mu_{xx}}{\\Delta x} \\right)_{eff}\n\\right\\} \\right\\} , \n\\label{dg-alpha-xx-def} \n\\end{equation} \n\\begin{equation}\n\\alpha_{yy}=\n\\min\\left\\{  \\beta_{max}\\frac{\\mu_{norm-yy}}{{\\Delta x}_{f}} , \\max\\left\\{ \\beta_{min}\\frac{\\mu_{norm-yy}}{{\\Delta x}_{f}} , \n\\left( \\frac{\\mu_{yy}}{\\Delta x} \\right)_{eff}\n\\right\\} \\right\\} , \n\\label{dg-alpha-yy-def} \n\\end{equation} \n\\begin{equation}\n\\alpha_{zz}=\n\\min\\left\\{  \\beta_{max}\\frac{\\mu_{norm-zz}}{{\\Delta x}_{f}} , \\max\\left\\{ \\beta_{min}\\frac{\\mu_{norm-zz}}{{\\Delta x}_{f}} , \n\\left( \\frac{\\mu_{zz}}{\\Delta x} \\right)_{eff}\n\\right\\} \\right\\} , \n\\label{dg-alpha-zz-def} \n\\end{equation} \nand is a positive scaler and with\n\\begin{equation}\n\\mu_{norm-xx}=2n_x \\mu_{xx}  n_x + n_y \\mu_{xy} n_y + n_z \\mu_{xz} n_z, \n\\end{equation}\n\\begin{equation}\n\\mu_{norm-yy}=n_x \\mu_{yx}  n_x + 2n_y \\mu_{yy}  n_y + n_z \\mu_{yz} n_z, \n\\end{equation}\n\\begin{equation}\n\\mu_{norm-zz}=n_x \\mu_{zx}  n_x + n_y \\mu_{zy} n_y + 2n_z \\mu_{zz}  n_z, \n\\end{equation}\nand\n\n\n\\begin{equation}\n\\left( \\frac{\\mu_{xx}}{\\Delta x} \\right)_{eff}=\n\\frac{\n({n_x} (2\\mu_{xx}\n\\frac{\\partial u}{\\partial x}\n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n {n_y} \\mu_{xy}\n(\n\\frac{\\partial v}{\\partial x}+\\frac{\\partial u}{\\partial y})\n+\n{n_z} \\mu_{xz}\n(\n\\frac{\\partial w}{\\partial x}+\\frac{\\partial u}{\\partial z})\n )\n}\n{ u_{cur}-u_{nab}}, \n\\end{equation}\n\\begin{equation}\n\\left( \\frac{\\mu_{yy}}{\\Delta x} \\right)_{eff}=\n\\frac{({n_x} \\mu_{yx}\n(\n\\frac{\\partial u}{\\partial y}+\\frac{\\partial v}{\\partial x}\n)\n+\n{n_y}(2\\mu_{yy}\n\\frac{\\partial v}{\\partial y}\n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n)\n+\n{n_z} \\mu_{yz}\n(\n\\frac{\\partial w}{\\partial y}+\\frac{\\partial v}{\\partial z})\n )\n}\n{ v_{cur}-v_{nab}}, \n\\end{equation}\n\\begin{equation}\n\\left( \\frac{\\mu_{zz}}{\\Delta x} \\right)_{eff}=\n\\frac{({n_x} \\mu_{zx}\n(\n\\frac{\\partial u}{\\partial z}+\\frac{\\partial w}{\\partial x})\n+\n{n_y} \\mu_{zy}\n(\n\\frac{\\partial v}{\\partial z}+\\frac{\\partial w}{\\partial y})\n+\n{n_z} (2 \\mu_{zz}\n\\frac{\\partial w}{\\partial z}\n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol})\\nabla\\cdot{\\bf u} \n) )\n}\n{ w_{cur}-w_{nab}}. \n\\end{equation}\n\nIf one is looking for a particularly simple linear scheme then this can \nbe provided by:\n\\begin{equation}\n\\alpha_{xx}=\\frac{\\mu_{norm-xx}}{\\Delta x_f},\n\\end{equation} \n\\begin{equation}\n\\alpha_{yy}=\\frac{\\mu_{norm-yy}}{\\Delta x_f},\n\\end{equation} \n\\begin{equation}\n\\alpha_{zz}=\\frac{\\mu_{norm-yy}}{\\Delta x_f},\n\\end{equation} \nwhich simply penalizes the jump in each component of velocity, but care \nmust be taken in applying boundary conditions using this approach as \nfor example no slip conditions may not be enforced correctly through the \nstress conditions in which case one may simply use the more complex expressions \njust on the boundaries of the domain. \n\nNotice that we have chosen a simple way of linking the \nelements with a jump condition simply involving the \nvariable that is being solved for and not combinations \nof them. This is done to ensure that the \nresulting system of equations is symmetric positive semi-definite. \n\n\n\n\n\\subsection{High order linear DG viscosity scheme} \nHere we describe the high order linear scheme. This forms the first order derivatives \non the boundaries of the elements and as such has advantages over the, linear at least, \ninterior penalty function method. Although its disadvantages are that it does not have \na maximum principle like the interior penalty function method for linear elements and also \nresults in non-symmetric matrices. It does however result in a compact stencil with \nan element coupling only to its surrounding elements. Its performance has been very impressive \nin terms of accuracy and has a null space that is not easily excited. \nThe method has the same volume treatment as the interior penalty function method \nand differers only in the surface integral around each element in which the first order derivatives \nare evaluated. \nFor example:\n\n\\begin{equation}\n\\int_E N_i \\frac{\\partial \\mu    \\frac{\\partial u}{\\partial x}\n}{\\partial x} dV \n=\n- \\int_E \\frac{\\partial N_i}{\\partial x} \\mu \\frac{\\partial u}{\\partial x} dV\n+ \\int_{\\Gamma_E} N_i n_x \\mu \\frac{\\partial u}{\\partial x} d\\Gamma, \n\\label{visc-deriv} \n\\end{equation} \nin order to evaluate the derivative $\\frac{\\partial u}{\\partial x}$ \non the boundary of the element ${\\Gamma_E}$ we integrate over the volume \nof two neighbouring elements in order to calculate the derivative on the element \nface between the two elements using: \n\n\n\\begin{equation}\n\\int_{2E} N_i  u_x  dV \n=\n\\int_{2E} N_i  \\frac{\\partial u}{\\partial x} dV \n- \\frac{1}{2} \\int_{\\Gamma_{E1}} N_i n_x (u-u_{bc}) d\\Gamma\n- \\frac{1}{2} \\int_{\\Gamma_{E2}} N_i n_x (u-u_{bc}) d\\Gamma, \n\\end{equation} \nin which ${\\Gamma_{E1}}$ is the the shared face but within element $1$ and \nsimilarly ${\\Gamma_{E2}}$ is the the shared face but within element $2$ \nand $u_{bc}$ is the value of $u$ in the neighbouring element along the face. \nAlso\n\\begin{equation}\nu_x =\\sum_j N_j {u_x}_j  \\approx \n \\frac{\\partial u}{\\partial x} . \n\\end{equation} \nThen the derivative used within equation \\ref{visc-deriv} is:\n\\begin{equation}\n\\frac{1}{2} (\\frac{\\partial u}{\\partial x}+\\frac{\\partial u}{\\partial x}\\vert_{bc} ).\n\\end{equation} \n\n\n\n\\subsection{Stress form DG discretization when dividing though by volume fraction} \nWhen dividing the governing equations through by volume fraction - one of \nthe options for treating zero void fraction along with adjustment of drag terms - \none must treat the discretization of diffusion. \n\nThe discretization is of the term:\n \\begin{equation}\n\\frac{1}{S_k} \\nabla \\cdot (S_k S_k \\hat\\tau_k ) =\n\\hat\\tau_k \\cdot \\nabla S_k + \\nabla \\cdot (S_k \\hat\\tau_k). \n\\label{form-derivs-dg-visc}\n\\end{equation}\nIt will be useful to use the discretization of these two terms on the rhs:\n \\begin{equation}\n\\int_V N_i \\hat \\tau_k \\cdot \\nabla S_k dV \n=\\int_V N_i \\hat \\tau_k \\cdot \\nabla S_k dV \n+\\frac{1}{2}\\int_{\\Gamma_E} N_i \\hat\\tau {\\bf n} ( {S_k}_{nab} - S_k ) d\\Gamma, \n\\end{equation}\nand \n \\begin{equation}\n\\int_V N_i \\nabla \\cdot (S_k \\hat \\tau_k)  dV \n=\n- \\int_V (\\nabla N_i) \\cdot (S_k \\hat \\tau_k)  dV \n+\\frac{1}{2}\\int_{\\Gamma_E} N_i \\hat\\tau {\\bf n} ( {S_k}_{nab} + S_k ) d\\Gamma. \n\\end{equation}\nSumming these discretizations, we obtain the discretization of the viscouse terms: \n \\begin{equation}\n\\int_V (-(\\nabla N_i)S_k + N_i \\nabla S_k)\\cdot \\hat \\tau dV \n+\\int_{\\Gamma_E} N_i \\hat\\tau {\\bf n}  {S_k}_{nab}  d\\Gamma. \n\\end{equation}\nIn which $S_k$ is the volume fraction of phase $k$ and ${S_k}_{nab}$ is the \nvolume fraction on the boundary of an element on the other side of the boundary or on the \nneighbouring element.  \nThus, the surface integrals for the viscouse terms given in the previous section \nbecome: \nfor velocity component of phase $k$ that is $u_k$:\n\\begin{equation}\n\\int_{\\Gamma_E} {\\alpha_{xx}}_k ({u_k}_{cur}-{u_k}_{nab}) {S_k}_{nab} d\\Gamma,\n\\end{equation}\nfor $v_k$:\n\\begin{equation}\n\\int_{\\Gamma_E} {\\alpha_{yy}}_k ({v_k}_{cur}-{v_k}_{nab}) {S_k}_{nab} d\\Gamma,\n\\end{equation}\nfor $w_k$:\n\\begin{equation}\n\\int_{\\Gamma_E} {\\alpha_{zz}}_k ({w_k}_{cur}-{w_k}_{nab}) {S_k}_{nab} d\\Gamma. \n\\end{equation}\n\n\n\n\n\\subsection{Finite element interpolation of the control volume solution} \nTo obtain the finite element solution $T_{fem}^n$ we use a Galerkin projection of $T_{fem}^n$ onto the control volume solution $T^n$. This is tested with the finite element basis functions $N_i$. $N_i$ is discontinuous between elements only when $T$ is. Thus, when there is no discontinuity of solution between all elements then a global mass matrix system needs to be solved:\n \\begin{displaymath}\n \\int_V N_i (T_{fem}^n- T^n) d\\Omega =0, \n\\end{displaymath}\nto form the high order solution $T_{fem}^n$.  \n\n\n\\subsection{Calculating the high order derivatives}\n\nIn order to obtain the high order derivatives used in the calculation of the limited diffusion term, Eqn. \\ref{non-lin-diff-eff}, the finite element solution within each element is used along with boundary conditions from the finite element solution of the surrounding elements or the boundary conditions on the domain, if the elements are next to the domain boundaries. \nThat is $\\frac{\\partial T^n}{\\partial x}$ is calculated from\n \\begin{equation}\n B {\\underline T_{fem}^n}_x = \\underline v_x^n, \\;\\;\n B {\\underline T_{fem}^n}_y = \\underline v_y^n, \\;\\;\n B {\\underline T_{fem}^n}_z = \\underline v_z^n, \n\\label{form-derivs}\n\\end{equation}\nwith $B_{ij}=\\int Q_i Q_j dV$, ${T_{fem}}_x=\\sum_j Q_j {{T_{fem}}_x}_j$ and is discontinuous as the basis functions $Q_i$ are discontinuous between elements. In addition,\n \\begin{eqnarray}\n&& \\underline v_x^n=\\int Q_{i} \\frac{\\partial T_{fem}^n}{\\partial x} d\\Omega \n-\\int_{\\Gamma_{ele}} n_x Q_i ({T_{fem}^n}_{current}-{T_{fem}^n}_{nab})d\\Gamma, \\nonumber \\\\\n%\\end{equation}\n% \\begin{equation}\n&& \\underline v_y^n=\\int Q_{i} \\frac{\\partial T_{fem}^n}{\\partial y} d\\Omega \n-\\int_{\\Gamma_{ele}} n_y Q_i ({T_{fem}^n}_{current}-{T_{fem}^n}_{nab})d\\Gamma, \\nonumber \\\\\n%\\end{equation}\n %\\begin{equation}\n&& \\underline v_z^n=\\int Q_{i} \\frac{\\partial T_{fem}^n}{\\partial z} d\\Omega \n-\\int_{\\Gamma_{ele}} n_z Q_i ({T_{fem}^n}_{current}-{T_{fem}^n}_{nab})d\\Gamma. \n\\end{eqnarray}\nDirichlet boundary conditions are applied through the surface integral around each element ${\\Gamma_{ele}}$.  \n\nThe values of the derivatives either side of the control volume face are placed into Eqn. \\ref{non-lin-diff-eff}. These may be the same value for example within an element or when there is continuity of solution $T^n$ or $T_{fem}^n$ between elements. The same approach is also used to form the diffusion operator for DG based on equation \\ref{}.  The solution of equations \\ref{form-derivs} are local to each element as \nthe matrix is a Discontinuous Galerkin mass matrix $B$ and \nthus does not couple the elements. \n\n\n\n\n\\subsection{Time limiting for the non-conservative advection equation}\n\nThe transport term is often expressed in non-conservative form. Due to the fact that the equations for inviscid single phase flow are not necessarily well posed, solving the internal energy equation in non-conservative form is often a recourse.  One can obtain imaginary eigenvalues when the problem is posed as a Riemann problem and thus the solutions tend to diverge exponentially. A common solution is to solve for conservative variables e.g.$\\rho$, $\\rho\\mathbf{a}$, $\\rho T$ or to use a non-conservative form of the internal energy equation. This has the form \n%%\n%% - begin equation 34\n%%\n\\begin{equation}\n\\rho \\left( \\frac{\\partial T}{\\partial t} + \\mathbf{a}\\cdot\\nabla\nT \\right) + \\nabla \\cdot \\kappa\\nabla T  = S\n\\end{equation}\nor in the more general multi-phase form is:\n%%\n%% - begin equation 35\n%%\n\\begin{equation}\n{C_p}_k \\alpha_k \\rho_k \\left( \\frac{\\partial T_k}{\\partial t} + \\mathbf{a}_k\\cdot\\nabla\nT_k \\right) + \\nabla \\cdot \\kappa_k \\nabla T_k  = S_k\n\\label{multiT}\n\\end{equation}\nin which $k$ is the fluid phase, ${C_p}_k$ the specific heat capacity at constant pressure, $\\alpha_k$ is the volume fraction of phase $k$, $T_k$ is the temperature of phase $k$, $S_k$ the energy source or sink and $\\mathbf{a}_k$ is the velocity of phase $k$. To solve this equation it is divided by the heat capacity ${C_p}_k$.\n\nIntegrating this equation over the $i^{th}$ CV, using\n%%\n%% - begin equation 36\n%%\n\n\\begin{eqnarray}\n\\alpha_k \\rho_k\n\\mathbf{a}_k \\cdot \\nabla T_k = \\nabla \\cdot \\alpha_k\\rho_k \\mathbf{a}_k T_k - T_k\\nabla\\cdot \\alpha_k \\rho_k \\mathbf{a}_k\n\\label{parts}\n\\end{eqnarray}\nand applying the divergence theorem to the spatial derivative to obtain\n\n%%\n%% - begin equation 37\n%%\n\\begin{eqnarray}\n&&\\int M_{i} {\\alpha_k}_i^{n+1} {\\rho_k}_{i}^{n+1} \\left(\n\\frac{{T_k}_{i}^{n+1}-{T_k}_{i}^{n}}{\\Delta t} \\right)  dV +\n\\nonumber\\\\\n&&\\int_{\\Gamma_{CV_{i}}} \\left(\\theta^{n+\\frac{1}{2}} \\left[\n\\mathbf{a}^{n+1}_k \\cdot \\mathbf{n} {\\widetilde{\\alpha}}_k^{n+1}\n{\\widetilde{\\rho}}_k^{n+1} (\\widetilde{T_k}^{n+1}-{T_k}_i^{n+1})\n+\\kappa_k \\mathbf{n}\\cdot \\nabla T^{n+1}_k \\right]\\right. +\\nonumber\\\\\n&&\\left.(1-\\theta^{n+\\frac{1}{2}} )\\left[ \\mathbf{a}^{n}_k \\cdot\n\\mathbf{n} {\\widetilde{\\alpha}}_k^{n} {\\widetilde{\\rho}}_k^{n}\n(\\widetilde{T}^{n}_k-{T_k}_i^{n}) +\\kappa_k \\mathbf{n}\\cdot \\nabla\nT^{n}_k \\right]\\right)\\nonumber\\\\\n&&d\\Gamma = \\int M_{i} s_k^{n+\\frac{1}{2}}/{C_p}_k dV\n\\label{nocons}\n\\end{eqnarray}\n\n\nWith a value of $\\theta^{n+\\frac{1}{2}}={\\frac{1}{2}}$ the above scheme is second order accurate in time. However, in order for the scheme to be non-oscillatory $\\theta_{f}^{n+\\frac{1}{2}}$ will be defined as explained in Section \\ref{multidimtemplim}, with $\\tilde{h}^{n}_{f}$ defined by\n%%\n%% - begin equation 38\n%%\n\n\\begin{equation}\n\\tilde{h}^{n}_{f}=\\int_{\\Gamma_{f}}\n\\left(\\mathbf{a}_k\\cdot \\mathbf{n}\\alpha_k \\rho_k \\widetilde{T}^{n}_k\n+\\kappa_k \\mathbf{n}\\cdot \\nabla  T^{n}_k  \\right)d\\Gamma\n\\end{equation}\nHere the terms involving $T_i^{n+1}$ and $T_i^n$ in Eqn. \\ref{nocons} have not been included in the derivation of the value of $\\theta$. They have not been included here in an attempt to achieve consistency with the multi-phase thermal energy equation in conservative form. If they are included then the values of $\\theta_f^{n+\\frac{1}{2}}$ on the CV faces (used in Eqn. \\ref{nocons}) can be easily derived based on the derivation in the previous section.\n\nThe variables $\\alpha_k$, $\\rho_k$ and $T_k$ are spatially limited individually as explained in the previous section to obtain a scheme that is bounded in all these variables. In addition, on the boundaries of the domain appropriate boundary conditions (e.g. specified values resulting from incoming fluid) for each of these variables are required and are placed in the surface integrals of Eqn. \\ref{nocons} on the boundary of the domain.\n\n\n\\subsection{Time discretisation of multi-phase reaction terms}\nA coupled set of multi-phase flow equations containing the exchanges between the phases is of the form: \n\\begin{equation}\nD \\frac{\\partial \\Psi}{\\partial t} + H \\Psi = s_\\psi. \n\\label{w-rho-e-prob}\n\\end{equation}\nFor positive diagonal matrix $D$. Using $\\hat \\Psi = D^{-\\frac{1}{2}} \\Psi$ and $\\hat H=D^{-\\frac{1}{2}} H D^{-\\frac{1}{2}}$ then this equation becomes: \n\n\\begin{equation}\n\\frac{\\partial \\hat \\Psi}{\\partial t} + \\hat H \\hat \\Psi = \\hat s_\\psi\n\\label{w-rho-e-prob}\n\\end{equation} \nwith \n\\begin{equation}\n\\hat H\n= L \\Lambda R. \n\\label{stab_matrix}\n\\end{equation}\nwhich is the eigen-value decomposition into matrices of left $L$ and right $R$ eigen vectors and diagonal matrix of eigen-values $\\Lambda$. Typically if there are no losses then (e.g. conservation of mass) then $\\hat H$ is a discrete Laplacian. Thus, we obtain the diagonal system: \n\\begin{equation}\n\\frac{\\partial \\hat {\\hat \\Psi}}{\\partial t} + \\Lambda \\hat{\\hat\\Psi} = \\hat{\\hat s}_\\psi\n\\label{e-prob}\n\\end{equation} \nwith $\\hat\\Psi=R\\Psi$ the solution will grow (ignoring other losses) if any of the eigen-values in $\\Lambda$ are negative. In general their values will be non-negative (based on the physics and conservation) and $H$ sym-pos-semi-definite.  Thus, this can be treated as a set of independent equations and an optimal values for the contributions in the diagonal matrix $\\Theta$ chosen. So the time discretisation becomes:\n\n\n\\begin{equation}\n\\frac{\\hat {\\hat \\Psi}^{n+1}-\\hat {\\hat \\Psi}^{n}}{\\Delta t} + \\Lambda \\Theta\\hat{\\hat\\Psi}^{n+1} +\\Lambda(I-\\Theta) \\hat{\\hat\\Psi}^n= \\hat{\\hat s}_\\psi\n\\label{e-prob-time-term-opt-theta}\n\\end{equation} \nwhich becomes on mapping to original variables: \n\n\\begin{equation}\nD\\frac{ { \\Psi^{n+1}}- {\\Psi^{n}}}{\\Delta t} \n+ D^{\\frac{1}{2}} L\\Lambda \\Theta R D^{\\frac{1}{2}} {\\Psi^{n+1}}\n+ D^{\\frac{1}{2}} L\\Lambda (I-\\Theta) R D^{\\frac{1}{2}} {\\Psi^{n}} \n= \\hat{\\hat s}_\\psi\n\\label{e-prob-time-term-opt-theta-orig-var}\n\\end{equation} \n\nNow considering just one variable. That is any one of \nthe equations in equation set \\ref{e-prob} takes on the form: \n\n%%\n%% - begin equation\n%%\n\\begin{equation}\n\\displaystyle\\frac{\\partial {T}\\left({r},t\\right)} {\\partial t}+{\\sigma}\\left(t\\right){T}\\left({r},t\\right)={s}\\left({r},t\\right)\n\\label{eqn57}\n\\end{equation}\nDiscretising Eqn. \\ref{eqn57} in time using the $\\theta$-time stepping method yields:\n\\begin{eqnarray}\n&&\\left(\\displaystyle\\frac{{{T}}^{n+1}\\left({r},t\\right)-{{T}}^{n}\\left({r},t\\right)}{\\Delta t}\\right)+{\\theta}^{n+\\frac{1}{2}}\\left({r}\\right){\\sigma}^{n+\\frac{1}{2}}\\left(t\\right){{T}}^{n+1}\\left({r}\\right)+   \\nonumber \\\\\n&& \\left({I}-{\\theta}\\left({r},t\\right)\\right){\\sigma}^{n+\\frac{1}{2}}\\left(t\\right){{T}}^{n}\\left({r},t\\right)=  {\\theta}^{n+\\frac{1}{2}}\\left({r}\\right){s}^{n+1}\\left({r}\\right)+\\left[{I}-{\\theta}^{n+\\frac{1}{2}}\\left({r}\\right)\\right]{s}^{n}\\left({r}\\right)\n\\label{eqn60}\n\\end{eqnarray}\nNow suppose ${s}\\left({r}\\right)$ is spatially and time invariant then we can match our numerical solution with the analytical solution by choosing and appropriate matrix ${\\theta}^{n+\\frac{1}{2}}\\left({r}\\right)$; the diagonal values of this matrix are\n\\begin{eqnarray}\n{\\theta}^{n+\\frac{1}{2}}\\left({r}\\right) = \\max \\left\\{ \n0.5,\n\\left(\\displaystyle\\frac\n{{\\sigma}^{n+\\frac{1}{2}}\\left(t,n+\\frac{1}{2}\\right)\\Delta t-1.0+\\exp\\left(-\\Delta{\\sigma}^{n+\\frac{1}{2}}\\left(t,n+\\frac{1}{2}\\right)\\right)} \n{{\\sigma}^{n+\\frac{1}{2}}\\left(t,n+\\frac{1}{2}\\right)\\Delta t\\left(1.0-\\exp\\left(-\\Delta t{\\sigma}^{n+\\frac{1}{2}}\\left(t,n+\\frac{1}{2}\\right) \\right)\\right) }\n\\right)\n\\right\\}. \n\\label{eqn61}\n\\end{eqnarray} \nHowever, if the most important attribute of the scheme is that it achieves physical realism then it is appropriate to use the TVD criteria for ${\\theta}\\left({r}\\right)$, which is\n%%\n%% - begin equation 62\n%%\n\\begin{equation}\n{\\theta}^{n+\\frac{1}{2}} \\left({r}\\right) \\geq 1-\\displaystyle\\frac{1}{\\Delta t {\\sigma}^{n+\\frac{1}{2}}\\left({r}\\right)}\n\\label{eqn62}\n\\end{equation}\nThis criteria is easily derived by ensuring that the scheme is a positive multiple of the backward Euler scheme.  In fact, Eqn. \\ref{eqn61} for $\\theta^{n+\\frac{1}{2}}$ tends to this expression from below, thus $\\theta^{n+\\frac{1}{2}}$, given by Eqn.\\ref{eqn61} satisfies the TVD criteria.\n\nThis expression has assumed that the material properties have been evaluated at time level ${n+{\\frac{1}{2}}}$ and are thus constant through out the time step. This method of time discretisating \ninvolving material properties has been used elsewhere \\cite{ChrisNSE}.\n\n\n\n\n\\subsection{Mass conservation and volume fraction advection}\\index{\\fluidity Module! Transport methods ! Volume fraction advection} \n\nThe multi-phase continuity equation is\n\\begin{eqnarray}\n\\frac{\\partial \\rho_k\\alpha_k}{\\partial t}\n+ \\nabla \\cdot \\mathbf{a}_k \\rho_k \\alpha_k = {S_c}_k\n\\label{cty}\n\\end{eqnarray}\n\nand the corresponding discretized continuity equation becomes\n\n\\begin{eqnarray}\n&&\\int M_{i}  \\left( {\\rho_k}_{i}^{n}\n\\left(\\displaystyle\\frac{{\\alpha_k}_{i}^{n+1}-{\\alpha_k}_{i}^{n}}{\\Delta\nt}\\right) + {\\alpha_k}_{i}^{n}\n\\left(\\displaystyle\\frac{{\\rho_k}_{i}^{n+1}-{\\rho_k}_{i}^{n}}{\\Delta\nt}\\right) \\right)dV + \\nonumber\\\\\n&&\\int_{\\Gamma_{CV_{i}}}\\left( \\theta^{n+\\frac{1}{2}}\n \\mathbf{a}^{n+1}_k \\cdot \\mathbf{n}\\widetilde{\\alpha}_k^{n+1} \\widetilde{\\rho}_k^{n+1}\n\\widetilde{\\alpha}^{n+1}_k\n+\n(1-\\theta^{n+\\frac{1}{2}} )\n \\mathbf{a}^{n}_k \\cdot \\mathbf{n}\\widetilde{\\alpha}_k^{n} \\widetilde{\\rho}_k^{n}\n\\widetilde{\\alpha}^{n}_k\n  \\right) d\\Gamma\n=\n\\int M_{i} {{s_c}_k}^{n+\\frac{1}{2}} dV\n\\label{disc-cty}\n\\end{eqnarray}\nin which ${{s_c}_k}^{n+\\frac{1}{2}}$ is the mass source/sink for fluid phase $k$. To enhance stability it is beneficial to treat the term involving ${\\rho_k}_i^{n+1}$ implicitly in pressure (this allows the CFL condition associated with acoustic waves to be exceeded) and this is absorbed into the discretized equation for pressure \\citep[see][for more details]{pain_2001b}.  The continuity equation, Eqn. \\ref{cty} and discretized continuity equation, Eqn. (\\ref{disc-cty}), are embedded in the energy Eqns. \\ref{multiT} and \\ref{nocons} respectively.\n\n\n\n\\subsection{The Internal Energy Equation Discretization of Sources} \n\\label{thermal-sources}\nThe equation for internal energy $E$ is of the form: \n\\begin{eqnarray}\n\\rho_k (\\frac{\\partial E_k}{\\partial t} + u_k\\cdot\\nabla E_k )\n= (\\tau_k + I p_{CV}):  (I\\frac{\\partial\\alpha_k}{\\partial t}+ \\nabla \\alpha_k u_k )\n\\end{eqnarray}\nwith a source of:\n\\begin{eqnarray}\n(\\tau_k + Ip_{CV}) :  (I\\frac{\\partial\\alpha_k}{\\partial t}+ \\nabla \\alpha_k u_k )= \\underline{\\underline {a_k}} :  \\underline{\\underline {b_k}}\n\\end{eqnarray}\nwith\n\\begin{eqnarray}\n\\underline{\\underline {a_k}}=\\tau_k + p_{CV} I,  \\;\\;\\;\\;\n\\underline{\\underline {b_k}}=I\\frac{\\partial\\alpha_k}{\\partial t}+ \\nabla \\alpha_k u_k \n\\end{eqnarray}\nThe way this is discretized is to seperately discretize using a CV method \nfor each of these terms $\\underline{\\underline {a_k}}$ and $\\underline{\\underline {b_k}}$ and apply the divergence terms to the first order \nderivatives within these. Here ':' represents the double product for for control volume \nrepresentation of pressure $p_{CV} = \\sum_j M_j {p_{CV}}_j$.  \nFor example if one considers the term:\n\\begin{eqnarray}\nIp_{CV} :  \\nabla \\alpha_k u_k = p_{CV} \\nabla \\cdot \\alpha_k u_k \n\\end{eqnarray}\nand discretize this then one obtains for control volume (CV) $i$:\n\\begin{eqnarray}\n \\int_V M_i p_{CV}\\nabla \\cdot \\alpha_k u_k dV = \\int_{\\Gamma_{CVi}} {p_{CV}}_i {\\bf n}\\cdot \\alpha_k u_k d\\Gamma. \n\\end{eqnarray}\nAlternatively, the source can be placed (lumped by add all the $\\underline{\\underline {b_k}}$'s for each phase $l$) into just one of the internal energy equations, $k$ say, which becomes:\n\\begin{eqnarray}\n\\rho_k (\\frac{\\partial E_k}{\\partial t} + u_k\\cdot\\nabla E_k )\n= (\\tau_k + I p_{CV}):  \\sum_l \\nabla \\alpha_l u_l . \n\\end{eqnarray}\n\n\n\n\\subsection{Solving the Linear Equations}\\index{\\fluidity Module! Transport methods ! Linear solvers}\n\nOne of the main advantages of the finite element high resolution method (HRFEM) that it shares with most other FEM methods, is that the equations involve diagonal dominant mass matrixes which are well conditioned and have a condition number independent of the grid size.\n\nIn contrast to first order discretization methods, the HRFEM equations have coupling in all directions. The HRFEM method used here is obtained by making each element a CV and using a mapping between the CV and the FEM solution. The FEM solution is then used as the high order flux along the CV faces. The HRFEM method requires the inverse of the consistent mass matrix in order to calculate incoming control volume fluxes accurately - this inverse is a full matrix. Thus, this coupling in practice can only be realized explicitly in the iterative scheme.  The HRFEM method has been generalised with a bi-jective mapping between the FEM and CV solutions. The discontinuous HRFEM method also uses consistent mass matrices, but these are local to an element so they are more manageable and can be treated implicitly.\n\nThere are a number of options available for solving the non-linear HRFEM equations. One can linearize the global equation set, treating implicitly or explicitly the down stream element coupling (inclusion of down stream coupling may result in poorer conditioned matrices from the discretization). Then a global set of linear equations would be solved each non-linear iteration by for example using SSOR preconditioning for GMRES \\citep{saad_1986}.  Alternatively, one can sweep through each CV, resolving all the non-linear equations local to each CV with a suitable liberalization procedure.\n\nThe global or local to an element liberalization can be achieved using the Newton-Raphson method, although this has quadratic convergence properties it is prone to failure when there does not exist a good initial guess. The most robust method reported for other flux limiting methods is to linearize on the first-order equations \\citep[see][]{darwish_1993}.  This involves solving a matrix equation with a matrix obtained from the underlying first order spatial discretization and the deviation of the high order scheme from this, would be treated explicitly as a source term. This has the advantage that the resulting matrix is well conditioned and also the non-linear convergence to a solution is usually monotonic, due to the dissipative characteristics of the first order scheme and is thus the approach adapted here.\n\n\\subsection{Boundary Conditions}\\index{Boundary conditions}\n\\label{boundary_conditions_section}\nTo form a well-posed system upon which to attempt a numerical discretisation the set of equations (taken for the discussion above) describing the behaiour of the system must be supplemented with appropriate boundary conditions.\n\n%%%\n\n\\subsubsection{Dirichlet condition for a scalar field}\\label{sect:bc_scalar_dirichlet}\\index{\\fluidity Module!Boundary conditions ! Dirichlet condition }\n\\index{Boundary conditions!Dirichlet}\nFor a scalar field, $T$ say, a Dirichlet condition on the boundary $\\partial\\Omega$ takes the form\n\\begin{equation}\nT=\\tilde{T},\\quad \\textrm{on}\\quad \\partial\\Omega.\n\\end{equation}\n\n%%%\n\n\\subsubsection{Neumann condition for a scalar field}\\label{sect:bc_scalar_neumann}\\index{\\fluidity Module! Boundary conditions !Neumann  condition }\n\\index{Boundary conditions!Neumann}\n\\index{Advection-diffusion equation}\nThe weak form (applying Green's Theorem to the diffusion term) of the advection-diffusion equation leads to a surface integral of the form\n\\begin{equation}\n\\int_{\\partial\\Omega} N_i (\\tensor{\\kappa}\\nabla T)\\cdot\\bmn \\;d\\Gamma.\n\\end{equation}\nThe Neumann condition is specified by assigning a value to $(\\tensor{\\kappa}\\nabla T)\\cdot\\bmn$, \\eg\n\\begin{equation}\n(\\tensor{\\kappa}\\nabla T)\\cdot\\bmn = q,\\quad \\textrm{on}\\quad \\partial\\Omega,\n\\end{equation}\nand adding in this surface integral to the discretised equation.\n\n%%\n\n\\subsubsection{Robin condition for a scalar field}\\label{sect:bc_scalar_robin}\\index{\\fluidity Module! Boundary conditions ! Robin condition }\n\\index{Boundary conditions!Robin}\nThe Robin condition is like the Neumann condition but takes the form\n\\begin{equation}\n(\\tensor{\\kappa}\\nabla T)\\cdot\\bmn + \\alpha T = q,\\quad \\textrm{on}\\quad \\partial\\Omega.\n\\end{equation}\n\n%%\n\n\\subsubsection{Prescribed Dirichlet condition for momentum --- no-slip as a special case}\\label{sect:bc_vector_dirichlet}\\index{\\fluidity Module! Boundary conditions ! Dirichlet condition }\n\\index{Boundary conditions!Dirichlet}\\index{\\fluidity Module ! Conservative Equations!Momentum }\nThis condition for momentum is set by simply prescribing all three components of velocity. For example, we might specify an inflow boundary where the normal component of velocity is non-zero, but the two tangential directions are zero. A special case is where all three components are zero and this is referred to as no-slip.\n\n%%\n\n\\subsubsection{Prescribed stress condition for momentum --- free-stress as a special case}\\label{sect:bc_scalar_stress}\n\\index{\\fluidity Module! Boundary conditions!Prescribed stress}\\index{\\fluidity Module ! Conservative Equations!Momentum } \n\\index{Traction force}\nAs for the scalar equation, applying Green's theorem to the stress term and the pressure gradient in Eqn. \\ref{mtm} results in a surface integral of the form\n\\begin{equation}\\label{StressBC}\n\\tautens\\cdot\\bmn - p\\bmn = \\bmF,\\quad \\textrm{on}\\quad \\partial\\Omega,\n\\end{equation}\nwhere $\\bmF$ is an applied 'traction' force (actually a force per unit area or stress, it becomes a force when the surface integral in the weak form is performed). An example of this might be were we set the vertical component to zero (in the presence of a free surface) and impose the two tangential directions (\\eg a wind stress).\n\n\\index{Boundary conditions!Free stress}\nThe free-stress condition is the case where we take $\\bmF\\equiv\\vec{0}$.\n\n\n\\subsubsection{Traction boundary condition for momentum --- free-stress as a special case}\\label{sect:bc_scalar_traction}\n\\index{Boundary conditions!Traction}\\index{\\fluidity Module ! Conservative Equations!Momentum } \nIn this case the normal component of velocity can be prescribed (\\eg inflow or no-flow ($g=0$) through the boundary)\n\\begin{equation}\n\\bmu\\cdot\\bmn = g,\\quad \\textrm{on}\\quad \\partial\\Omega.\n\\end{equation}\nThe remaining two degrees of freedom are imposed by taking the tangential component of Eqn. \\ref{StressBC} and specifying the tangential component of the force $\\bmF_{\\tau}$, \\ie\n\\begin{equation}\n\\bmtau\\cdot(\\tautens\\cdot\\bmn - p\\bmn) = \\bmtau\\cdot\\tautens\\cdot\\bmn = \\bmF_{\\tau},\\quad \\textrm{on}\\quad \\partial\\Omega,\n\\end{equation}\nAn example of this might be where a rigid lid is used (so normal component is zero) and the tangential components are a prescribed wind stress (in which case we take the two tangential directions to correspond to the available stress or wind velocity information, \\ie east-west and north-south) or bottom drag. Also, what we often term free-slip where the tangential components of stress are set to zero.\n\n\n\\section{Discretisation of force balance} \n\n\n\\subsection{Discretisation of force balance - continuous pressure formulation} \n\nThe force balance equation is:\n\\begin{equation}\n{\\underline {\\underline \\sigma}}_k {\\mathbf u}_k = - \\nabla p + {\\mathbf s}_u, \n\\label{force-bal}\n\\end{equation}\nwith boundary conditions of either\n${{\\mathbf u}_k}\\cdot {\\mathbf n} = {{ u}_k}_{bc}$ (applied through the continuity  \nor saturation \nequation below) or $p = p_{bc}$. \n\nThe basic force balance equation is obtained by \nusing the discontinuous basis function ${\\mathbf Q}_i$ for velocity and \n$M_i$ for pressure and in which in 3D ${\\mathbf Q}_i$ becomes:\n\\begin{equation}\n{\\mathbf Q}_i = \n  \\begin{pmatrix}\n    Q_i   & 0 & 0 \\\\\n    0   & Q_i & 0 \\\\\n    0 & 0 & Q_i\n  \\end{pmatrix}\n\\label{m_sigma_matrix}\n\\end{equation}\n\n Thus, the discretete force balance becomes:\n\n\\begin{equation}\n\\int_\\Omega {\\mathbf Q}_i ({\\underline {\\underline \\sigma}}_k {\\mathbf u}_k - \\nabla p -{\\mathbf s}_u) dV \n+  \\int_{\\Gamma_{\\Omega}} {\\mathbf Q}_i {\\mathbf n} (p - p_{bc}) d\\Gamma =0\n\\label{force-semi-disc}\n\\end{equation}\nwhere ${\\mathbf n}$ is the normal to the surface \nand $\\Omega$ is the domain of solution and \n${\\Gamma_{\\Omega}}$ the surface of the domain, ${\\mathbf s}_u$ is \nthe source and the velocity ${\\mathbf u}_k = \\phi {\\mathbf v}_k$, \n$\\phi$ is the \nelement-wise \nporosity and ${\\mathbf v}_k$ is the interstitial fluid velocity of phase $k$. \n\nSince $p$ is continuous between elements this becomes:\n\n\\begin{equation}\n{\\mathbf M}_\\sigma \\underline {\\mathbf u} = {\\mathbf C} \\underline {\\bf p} \n+ \\underline {\\bf s}_u. \n\\label{force-balance-matrix-form}\n\\end{equation}\nThe pressure vector is $\\underline{\\bf p} =(p_1\\; p_2 \\; p_3\\; ...\\; p_{\\cal M})^T$, \nthe velocity vector is decomposed into phases, thus for two phases, \n$\\underline{\\mathbf u}=(\\underline{\\mathbf u}_1^T \\;\\; \\underline{\\mathbf u}_2^T)^T$ \nand $\\underline{\\mathbf u}_k=({{\\mathbf u}_k}_1\\; {{\\mathbf u}_k}_2\\; {{\\mathbf u}_k}_3\\; ...\\; {{\\mathbf u}_k}_{\\cal Q}) $ \nand ${\\mathbf u}_k = \\sum_{j=1}^{\\cal Q} {\\mathbf Q}_j{{\\mathbf u}_k}_j$ and \n$p=\\sum_{j=1}^{\\cal M} M_j{p}_j$. Also \n\n\n\\begin{equation}\n{{\\mathbf M}_\\sigma}^{kk}_{ij} =  \\int_\\Omega {\\mathbf Q}_i \n{\\underline {\\underline \\sigma}}_k {\\mathbf Q}_j dV, \n\\end{equation}\nand for two phase flow\n\n\\begin{equation}\n{{\\mathbf M}_\\sigma} = \n  \\begin{pmatrix}\n    {{\\mathbf M}_\\sigma}^{11}   & 0 \\\\\n    0   & {{\\mathbf M}_\\sigma}^{22} \n  \\end{pmatrix}\n\\label{m_sigma_matrix}\n\\end{equation}\nand \n\n\\begin{equation}\n{\\mathbf C}_{ij}=\\int_\\Omega {\\mathbf Q}_i \\nabla M_j dV \n+ \\int_\\Gamma \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n}  M_j d\\Gamma,\n\\end{equation} \nand \n\n\\begin{equation}\n{{\\bf s}_u}_i= \\int_\\Omega {\\mathbf Q}_i {\\mathbf s}_u dV \n- \\int_\\Gamma \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} p_{bc} d\\Gamma. \n\\end{equation}\nwhere ${\\mathbf n}$ is the surface normal. \n\nThus, as usual with mixed formulations, not specifying a \nboundary condition for pressure corresponds to a no \nnormal flow condition which is realized through the continuity \nequation by weakly appling a Dirichlet no normal \nflow boundary condition. \n\n\n\n\\subsection{Discretisation of force balance - discontinuous pressure formulation} \n\nThe only difference between this formulations (as far as the force balance \nis concerned) and the continuous formulation is the treatment of pressure \nwhich is discontinuous along with saturation and density at element \nboundaries. The descret force balance becomes:\n\\begin{equation}\n\\int_{\\Omega_E} {\\mathbf Q}_i ( {\\underline {\\underline \\sigma}}_k \n{\\mathbf u}_k - \\nabla p -{\\mathbf s}_u) dV \n+  \\int_{\\Gamma_{E}} \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} (p - p_{nab}) d\\Gamma \n+  \\int_{\\Gamma_{E}-\\Gamma} {\\mathbf Q}_i {\\mathbf n} (p - p_{bc}) d\\Gamma =0\n\\end{equation}\nand thus: \n\n\\begin{equation}\n{\\mathbf C}_{ij}=\\int_{\\Omega_E} {\\mathbf Q}_i \\nabla M_j dV \n+ \\int_{\\Gamma_{E}-\\Gamma} \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} M_j d\\Gamma \n+ \\int_\\Gamma {\\mathbf Q}_i {\\mathbf n} M_j d\\Gamma .\n\\end{equation}\nThis corresponds to a central difference discretisation for pressure \non the boundaries of each finite element, that is for example:\n\n\\begin{equation}\n\\int_{\\Omega_E} {\\mathbf Q}_i \\nabla p dV = -\\int_{\\Omega_E} \\nabla {\\mathbf Q}_i  p dV \n+ \\int_{\\Gamma_E} {\\mathbf Q}_i {\\mathbf n} p_{nab} dV \n= \\int_{\\Omega_E} {\\mathbf Q}_i \\nabla p dV \n+ \\frac{1}{2} \\int_{\\Gamma_E} {\\mathbf Q}_i {\\mathbf n} (p-p_{nab}) dV\n\\label{dg-sat-form}\n\\end{equation}\nwhere $p_{nab}$ is the pressure from the neighbouring \nelement and ${\\mathbf n}$ is the surface normal. \n\n\n\\subsection{The overlapping finite element method for multi-phase Darcy Flow} \n\nSo far for uniform ${\\underline{\\underline \\sigma}}_k$ within each element and the use of the P1DG-P2 element type \nand its equivalent in one dimensional the Darcy flow equation is \nexactly enforced. Although this is not true of the DG variants \nfor pressure it is observed that it is close \nas the pressure does not have large discontinuities \nbetween elements at least in one dimension. \n\nHowever, ${\\underline{\\underline \\sigma_k}}$ depends on the saturation $S_k$ which has \na control volume (CV) distribution and is a non-linear function of $S_k$. \nThus, \t\t\t\n\n\\begin{equation}\n{\\underline {\\underline \\sigma}}_k \n= \\frac{1}{{Rel}_k} {\\underline{\\underline K}}^{-1} \t\n\\end{equation}\nin which the permeability tensor \n${\\underline{\\underline K}}$ has an element wise variation \nand ${Rel}_k$ is the relative permeability. \nThus, in general ${\\underline {\\underline \\sigma}}_k$ varies between elements and within each element \ndepending on the same variation as the CV saturation $S_k$ that is $Rel_k$. \nThus, ${\\underline {\\underline \\sigma}}_k$ is piecewise constant \nwithin each element and a natural \nway to obtain an exact solution would be to use basis functions \nlocal to each CV within each element. \nThus, if for quadratic pressure variation there will be \na piecewise \nlinear velocity field with simple discontinuity between \nelements and one could then use linear basis functions \nand test functions within each control volume. Thus, in one dimension \nthere would be $2\\times 3$ velocity nodal values associated with \neach phase.  \n\nHowever, such an approach is cumbersome especially in multi-dimensions. \nIn fact it may become inpracticle. To overcome this \nproblem overlapping basis functions are used. The approach is derived \nbased on the observation \nthat the only difference between the velocities \nwithin each CV is a multiplication factor \nand this multiplication factor is ${\\underline {\\underline \\sigma}}_k^{-1}$. \nThus, one can discretise  \nusing: \n\\begin{equation}\n\\int_\\Omega {\\mathbf Q}_i^\\mu ({\\underline{\\underline\\sigma}}_k^\\mu {\\mathbf u}_k^\\mu - \\nabla p -s^\\mu) dV + \n\\int_{\\Gamma}\\gamma {\\mathbf Q}_i^\\mu {\\mathbf n} (p-p_{bc}) d\\Gamma =0 \n\\label{overlap-eqn} \n\\end{equation}\nin which ${\\mathbf Q}_i^\\mu$ are the weighting functions. \n${\\mathbf Q}_i^\\mu$ are also the  \nvelocity basis functions which span the whole \nelement that they belong to \nand also ${\\mathbf Q}_i^\\mu={\\mathbf Q}_i^1\\;\\; \\forall \\mu\\in\\{1,2,...,{\\cal N}_{locCV}\\}$\nwhere ${\\cal N}_{locCV}$ is the number of local control volumes within each \nfinite element and ${\\mathbf u}_k =\\sum_\\mu \\sum_j H^\\mu {{\\mathbf u}_k}_j^\\mu$ where \n$H^\\mu=1$ in local control volume $o$ and $=0$ otherwise. \nIt also enables relatively low order quadrature rules to be used \nacross each finite element.  \nFor 2D quadatric pressure triangular elements (see figure \\ref{p1dgp2_ele-dgsat_pics}) \nthere are $3\\times6=18$ velocity basis \nfunctions for each of the two directions and each phase. \nFor 3D quadatric pressure \ntetrahedra elements there are $4\\times 10=40$ velocity basis \nfunctions for each of the two directions and each phase.\n\nThe result is again the recovery of the exact enforcement of \nthe differential equation at least away from the boundaries. \nNow including in the previous formulation $\\gamma=1$ however \nwe now need to take into account the difference in the \nvolumes of the elements as we integrate right \nacross the whole element. This is taken into account \nusing \n\n\\begin{equation}\n\\gamma^\\mu = \\frac{V^\\mu_E}{V_E} \\frac{S^\\mu_E}{S_E}\n\\label{overlap-eqn-gamma}\n\\end{equation}\nin which $V_E$ is the volume of element $E$ \nand $V^\\mu_E$ is the volume of control volume $\\mu$ \nin element $E$ and $S_E$ is the surface area of the element \non the boundary and $S^\\mu_E$ is the surface \narea of element $E$ of CV $\\mu$ in element $E$ on the boundary \nof the domain. \n\nThe discontinuous formulation is also easily extended \nto this overlapping finite element approach and becomes: \n\n\\begin{equation}\n\\int_{\\Omega_E} \\hat{\\mathbf Q}_i^\\mu ({\\underline{\\underline{\\sigma}}}_k^\\mu {\\mathbf u}_k^\\mu - \\nabla p -{\\mathbf s}_u^\\mu) dV \n+  \\frac{1}{2}\\int_{\\Gamma_{E-\\Omega}} \\gamma^\\mu_E {\\mathbf Q}_i^\\mu {\\mathbf n} (p - p_{nab}) d\\Gamma \n+  \\int_{\\Gamma_{\\Omega}}  \\gamma^\\mu_E \\hat{\\mathbf Q}_i^\\mu {\\mathbf n} (p - p_{bc}) d\\Gamma =0. \n\\label{overlap-eqn-dg}\n\\end{equation}\nand given that \n\\begin{equation}\n{\\mathbf Q}_j=\\hat{\\mathbf Q}_i^\\mu \n\\end{equation}\nfor a suitable index $j$ the discretisation can be expressed \nsimilar to equation \\ref{force-semi-disc} for the continuous formulation and \nequation \\ref{dg-sat-form} for the discontinuouse \nbetween elements pressure/saturation formulation. \n\n\n\\subsubsection{Efficient expansions for velocity represented by the overlapping finite element method}  \nThe main problem with the overlapping FEM is the large number of velocity unknowns. \nHowever, these may be reduced if one considers other expansions. \nFor example a simple alternative is to use within an element the expansion:\n\n\\begin{equation}\n {\\mathbf u}_k^\\mu = ({\\underline{\\underline{\\sigma}}}_k^\\mu)^{-1}  ({\\mathbf u}_k + \\Delta{\\mathbf u}_k^\\mu)\n\\end{equation}\nIn which $\\Delta{\\mathbf u}_k^\\mu$ is a constant across each control volume $\\mu$ and to avoid singularities \nin the equations it is convenient to assume:  \n\\begin{equation}\n\\Delta{\\mathbf u}_k^1={\\mathbf 0}. \n\\end{equation}\nIn addition, \n${\\mathbf u}_k =\\sum_j {\\mathbf Q}_j {{\\mathbf u}_k}_j$ is a \nstandard finite element representation, across an element, of the \nvelocity and ${\\mathbf u}_k^\\mu$ is the velocity across control volume $\\mu$. \nThe following are some examples of finite element representations. \nAn example of elements is given by \nPNDG(B,C)-PMDG. \nThis has for triangles \nN=0 (then 1 unknown associated with a constant variation)\nN=1 (3 variables with a linear variation in velocity)\nN=2 (6 variables with a linear variation in velocity)\nAdd 1 if a bubble B is also used for velocity. \nC is used if a constant is applied also across each CV appart from the 1st cvof the element. \nSome examples are listed below for fully discontinuous elements.\n\n\\noindent\n\\noindent\nLinear pressure: \n\n\\noindent\nP1DG(B)-P1DG(also P1) has for triangles 3+1=4 velocities and 3 pressures and \nfor tetrahedra 4+1=5 velocities and 4 pressures. \n\n\\noindent\nP2DG-P1DG(also P1) has for triangles 6 velocities and 3 pressures and \nfor tetrahedra 10 velocities and 4 pressures. \n\n\\noindent\nP1DG(C)-P1DG(also P1) has for triangles 3+2=5 velocities and 3 pressures and \nfor tetrahedra 4+3=7 velocities and 4 pressures. \n\n\\noindent\nP0DG(C)-P1DG(also P1) has for triangles 1+2=3 velocities and 3 pressures and \nfor tetrahedra 1+3=4 velocities and 4 pressures. \n\n\n\\noindent\n\\noindent\nQuadratic pressure: \n\n\\noindent\nP2DG(B)-P2DG(also P2) has for triangles 6+1=7 velocities and 6 pressures and \nfor tetrahedra 10+1=11 velocities and 10 pressures. \n\n\\noindent\nP3DG-P2DG(also P2) has for triangles 10 velocities and 6 pressures and \nfor tetrahedra 20 velocities and 10 pressures. \n\n\\noindent\nP1DG(C)-P2DG(also P2) has for triangles 3+5=8 velocities and 6 pressures and \nfor tetrahedra 4+9=13 velocities and 10 pressures. \n\n\\noindent\nP2DG(C)-P2DG(also P2) has for triangles 6+5=11 velocities and 6 pressures and \nfor tetrahedra 10+9=19 velocities and 10 pressures. \n\n\\noindent\nP1DG-P2DG (also P2)has for triangles 3 velocities and 6 pressures and \nfor tetrahedra 4 velocities and 10 pressures. \n\n\\noindent\nP1DG(C)-P2DG (also P2)has for triangles 3+5=8 velocities and 6 pressures and \nfor tetrahedra 4+9=13 velocities and 10 pressures. \n\n\n\n\n\\subsection{Implicit treatment of buoyancy} \nGiven that the saturation/density equation for phase \n$k$ (equation \\ref{detail-sat-eqn-k}) can be expressed as:\n\n\\begin{equation}\n \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {\\Delta t} ) \n + {v_z}_k {S_k}_i^n \\frac{\\partial \\tilde \\rho_k^n }{ \\partial z}  \n= {{s_k}_{rest}}_i\n\\label{sat-part} \n\\end{equation}\nwhere $z$ is the vertical direction in which gravity points. \n\nThe force balance equation with gravity is at time level $n+1$: \n\n\\begin{equation}\n{\\underline {\\underline\\sigma}}_k^{n+1} {\\mathbf u}_k^{n+1} = \\nabla p^{n+1} - \\rho_k^{n+1} {\\mathbf g} \n\\end{equation}\nin which ${\\mathbf g}$ is the gravitational vector with a \nmagnitude $\\vert{\\mathbf g}\\vert$ \nequal to the stength of gravity and the direction in which gravity acts. \nThus, this becomes on inserting \\ref{sat-part} into this equation \nfor $\\rho_k$:\n\n\n\\begin{equation}\n{\\underline {\\underline\\sigma}}_k^{n+1} {\\mathbf u}_k^{n+1} \n+  {{\\underline {\\underline\\sigma}}_k}_{relax} \n({\\mathbf u}_k^{n+1} - {\\tilde {\\mathbf u}}_k^{n+1}) \n= \\nabla p^{n+1} \n-\n{\\tilde \\rho}_k^{n+1} {\\mathbf g} \n\\end{equation}\nin which the matrix has a 'vertical' component: \n\n\\begin{equation}\n{{\\sigma_k}_{relax}}_{zz} = \\vert{\\mathbf g}\\vert  \\Delta t \n\\frac{1}{ \\phi } \n\\max\\{ \\frac{\\partial  {\\tilde \\rho}_k^{n+1}}{\\partial z}, 0\\} \n\\end{equation}\nall other components of the matrix ${{\\sigma_k}_{relax}}$ are zero. \nIn addition the tildes represent the best guess of \nthe variables they are associated with. \n\nThis allows much larger time steps to be used in stratified \nflows and also increases accuracy in these environments. \n\n\n\n\\subsection{Discretisation of inertia terms using DG} \nConsidering a single phase $k$ the inertial \nterms in conservative form are: \n\n\\begin{equation}\n\\frac{\\partial \\hat\\rho_k u_k}{\\partial t} \n+ \\nabla \\cdot \\hat\\rho_k \\tilde u_k  u_k \n\\label{inertia-eqns-cons} \n\\end{equation}\nand in non-conservative form: \n\n\\begin{equation}\n\\hat\\rho_k \\left(\\frac{\\partial u_k}{\\partial t} \n+  \\tilde u_k\\cdot \\nabla u_k \\right) \n\\label{inertia-eqns-non-cons} \n\\end{equation}\nin which $\\hat\\rho_k= \\phi S_k \\rho_k$ for porous \nmedia and $\\hat\\rho_k= \\alpha_k \\rho_k$ for inertia dominant \nflows. \nDiscretising in conservative form this becomes: \n\n\n\\begin{equation}\n\\frac{\n\\int_{V_e} N_i \\hat\\rho^{n+1} u^{n+1}_k -\n\\int_{V_e} N_i \\hat\\rho^{n} u^{n}_k }\n{\\Delta t} \n- \n\\int_{V_e} \\nabla N_i \n(\\theta \\hat\\rho_k^{n+1} \\cdot \\tilde u_k^{n+1} u_k^{n+1} +\n(1-\\theta) \\hat\\rho_k^{n} \\cdot \\tilde u_k^{n} u_k^{n} ) dV \n\\label{inertia-disc-cons-1} \n\\end{equation}\n\\begin{equation}\n+ \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n+1}<0)} \n N_i \\theta ( \\hat\\rho_k^{n+1} n\\cdot \\tilde u_k^{n+1}  \nu_k^{n+1})_{nab}  d\\Gamma \n+ \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n}<0)} \n N_i(1-\\theta) (\\hat\\rho_k^{n} n\\cdot \\tilde u_k^{n} \nu_k^{n})_{nab}  d\\Gamma \n\\label{inertia-disc-cons-2} \n\\end{equation}\n\\begin{equation}\n+ \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n+1}>0)} N_i \n\\theta  \\hat\\rho_k^{n+1} \nn\\cdot \\tilde u_k^{n+1}    u_k^{n+1}  d\\Gamma\n+ \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n}>0)} N_i \n (1-\\theta) \\hat\\rho_k^{n} n\\cdot \\tilde u_k^{n}  u_k^{n} d\\Gamma ,\n\\label{inertia-disc-cons-3} \n\\end{equation}\nin which $nab$ refers to variables associated \nwith neighbouring elements and the surface \n$\\Gamma_e (n\\cdot \\tilde u_k^{n+1}<0)$ is \nthe incoming surface to \nelement $e$ in which \n$n\\cdot \\tilde u_k^{n+1}<0$. \nIn non-conservative form: \n\n\n\\begin{equation}\n\\frac{\n\\int_{V_e} N_i \\hat\\rho^{n+\\theta_\\rho} u^{n+1}_k -\n\\int_{V_e} N_i \\hat\\rho^{n+\\theta_\\rho} u^{n}_k }\n{\\Delta t} \n+ \n\\int_{V_e} N_i \\hat\\rho_k^{n+\\theta_\\rho}\n(\\theta  \\tilde u_k^{n+1} \\cdot\\nabla u_k^{n+1} +\n(1-\\theta)  \\tilde u_k^{n} \\cdot\\nabla u_k^{n} ) dV \n\\label{inertia-disc-non-cons-1} \n\\end{equation}\n\\begin{equation}\n- \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n+1}<0)} \nN_i \\theta \\hat\\rho_k^{n+\\theta_\\rho} n\\cdot \\tilde u_k^{n+1} (u_k^{n+1} - (u_k^{n+1})_{nab} ) d\\Gamma \n\\label{inertia-disc-non-cons-2} \n\\end{equation}\n\\begin{equation}\n- \n\\int_{\\Gamma_e (n\\cdot \\tilde u_k^{n}<0)} N_i (1-\\theta)\\hat\\rho_k^{n+\\theta_\\rho} n\\cdot \\tilde u_k^{n}  (u_k^{n+1} - (u_k^{n+1})_{nab} ) d\\Gamma . \n\\label{inertia-disc-non-cons-3} \n\\end{equation}\n\n\t\t\t\t\t\t\t\t\t\t\n\\subsection{Discretisation of capillary pressure} \n\nThis subsection explains how to deal with the capillary pressure. We treat the capillary pressure to introduce it as a right hand side term in the momentum equation. We will consider only two phases.\n\nWe define the capillary pressure as:\n\\begin{equation}\nP_c = P_{non-wetting} - P_{wetting},\n\\end{equation}\nwhere $P_c $ is the capillary pressure.\n \nFor simplicity we are going to calculate $P_c $ by using the Brooks-Corey model, which can be written as follows:\n\\begin{equation}\nP_c = P_e (S_w)^{-a},\n\\end{equation}\nhere $P_e$ is the entry pressure, $S_w $ is the normalised water saturation, and $a $ is the inverse of the pore size distribution. Note that the saturation is dividing, therefore we have to limit the minimum normalised water saturation to avoid dividing by zero.\n\nUsing finite elements, the capillary pressure term is as follows:\n\\begin{equation}\n\\int_V N_i \\nabla P_c dV.\n\\label{Cap_pressure_initial}\n\\end{equation}\nThis previous formula is enough if using continuous pressure. However, when considering discontinuous pressure we need to proceed similarly to the discretisation of the Pressure in the momentum equation. In that case we needed to add a continuity term in the pressure discretisation to account from the pressure jump between elements. For that purpose, there are two possibilities. The first one is integrating by parts, in which we consider an average of the capillary pressures at both sides of the element in the surface term:\n\\begin{equation}\n-\\int_V P_c \\nabla N_{i} dV + \\int_S 0.5 (P_{Ccurrent} + P_{Cneigh})  N_{i} \\mathbf{n} dS,\n\\label{cappressure_intbyparts1}\n\\end{equation}\nin this formula $ 0.5 (P_{ci} + P_{cj})$ is the term that accounts for the average capillary pressure between elements, $i$ is the present element node and $j$ is the neighbouring element node. The second option is by integrating by parts twice, which also takes into account the discontinuous pressure in the surface term:\n\\begin{equation}\n\\int_V N_{i} \\nabla P_c dV - \\int_S 0.5 (P_{Ccurrent} + P_{Cneigh})  N_{i} \\mathbf{n} dS,\n\\label{cappressure_intbyparts2}\n\\end{equation}\n\nDepending on the element pair we may consider different approaches to obtain the capillary pressure. For element pairs $P_nDGP_n(DG) $ the $P_c$ can be calculated by using the control volume wise saturation. This calculation yields a control volume capillary pressure. For this reason equation \\ref{cappressure_intbyparts1} is recommended as we do not need the derivatives of control volume shape functions. \nOn the other hand, when the element order of the velocity and pressure does not match, the calculation of the capillary pressure at the velocity nodes is difficult by using a control volume wise saturation, for example, some velocity nodes might fall between two control volumes making difficult deciding which saturation should be used to calculate the capillary pressure. For this reason, the capillary pressure have to be calculated by using a finite element projection of the saturation. In this way, we obtain a finite element capillary pressure that can be easily evaluated across the element. When using a finite element capillary pressure both formulas can be applied, however, to be consistent with the discretisation of the pressure, equation \\ref{cappressure_intbyparts2} is recommended.\n\n\\subsubsection*{Capillary pressure as a source term}\n\nThe capillary pressure can be introduced into the advection equation as a diffusion coefficient. This option has not been included in the code and its description has to be considered as a draft.\n\nIn this approach the velocity to be considered in the advection equation is modified to contain the effects of the capillary pressure:\n\\begin{equation}\nV_w = f_w + \\frac{\\lambda_w\\lambda_o}{\\lambda_w+\\lambda_o} \\frac{1}{V} \\nabla P_c = f_w + \\left(  f_w \\lambda_o \\frac{1}{V} \\frac{\\partial P_c}{\\partial S_w} \\right) \\nabla S_w.\n\\end{equation}\nThe variables within the parenthesis conform the ''diffusion coefficient'' and the derivative of the saturation is the diffusion term because in the advection equation we have to calculate the divergence of the velocity, making the last term of the equation a second order derivative.\n\n\n\n\\subsection{Artificial diffusion as a capillary pressure term to increase stability } \nFrom the Darcy equation we create the following potential function:\n\\begin{equation}\n\\mathbf{F} = \\mathbf{u} + \\underline {\\underline\\sigma}^{-1} \\nabla P_c \\underline ,\n\\end{equation}\n\n and we pass it to the advection equation instead of just the velocity, obtaining the following:%rewrite equation following the convention of the manual\n\\begin{equation}\n\\phi \\frac{\\partial  \\rho_k S_k}{\\partial t} + \\nabla \\cdot \\rho_k S_k (\\mathbf{u} +  \\frac{\\partial  P_c}{\\partial \\tilde{S}_k}  \\mathbf{n}\\cdot \\underline {\\underline\\sigma}^{-1} \\cdot \\mathbf{n} \\nabla (S_k - \\tilde{S}_k) ) = S_{cty} \n\\end{equation}\nwhere the new variable $  \\tilde{S}_k$ is the Saturation calculated at the previous non-linear iteration. \nFor stability within a large time stepping method this equation may be amended (based on non-dimensional analysis) to:\n\\begin{equation}\n\\phi \\frac{\\partial  \\rho_k S_k}{\\partial t} + \\nabla \\cdot \\rho_k S_k (\\mathbf{u}_k +  {\\underline{\\underline k}}_{stab}  \\nabla (S_k - \\tilde{S}_k) ) = S_{cty}, \n\\end{equation} \nwith the diagonals of the tensor ${\\underline{\\underline k}}_{stab}$ equal to:\n\\begin{equation}\n k_{atab}  =  \\beta_{stab} ( (\\mathbf{u}_k)^T (\\underline{\\underline {\\Delta x}})^2\\mathbf{u}_k )^{\\frac{1}{2}}\n\\end{equation} \nwith the scalar $\\beta_{stab}=O(1)$ and in which $\\underline{\\underline {\\Delta x}}$ contains the \nlength scales across an anisotropic element. \n\nThe capillary pressure term acts a diffusion term that stabilizes the system. Despite the diffusion has a positive value, as the derivative of the capillary pressure is always negative, the sign of the diffusion term is the usual one. The artificial diffusion does not affect the whole domain in the same grade it varies depending on the variation of saturation between two non-linear iteration. In the extreme case $ (S_k - \\tilde{S}_k) $ is zero and then no diffusion is added.\n\n\\section{Discretised saturation equation and global mass balance} \n\nThis section outlines the discrete saturation equations and derives the global mass balance equations from the saturation equations. The resulting equation can then be solved simultaneously with equation \\ref{force-balance-matrix-form}. \n\t\t\t\t\t\t\t\t\t\t\n\n\\subsection{Discretised saturation equation} \n\nThe saturation equation \n\n\\begin{equation}\n\\phi\\frac{\\partial \\rho_k S_k }{\\partial t} \n+ \\nabla \\cdot {\\mathbf u}_k \\rho_k S_k = {s_{cty}}_k, \n\\end{equation}\ndiscretised by testing it with CV basis functions \n $M_i$ is and discretising in time using the \n $\\theta-$method is:\n \n\\begin{equation}\n\\int_\\Omega M_i (\\frac{\\phi{\\rho_k}_i^n ({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {\\Delta t} ) dV\n+ \\int_{\\Gamma_{CV_i}} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} \nd\\Gamma \n= \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV.\n\\label{detail-sat-eqn-k}\n\\end{equation}\n \n \n\\subsection{Discretised global continuity equation} \n \nDividing equation \\ref{detail-sat-eqn-k} by ${\\rho_k}^n_i $ and summing \nover all phases one obtains the global continuity equation: \n\n \n\\begin{equation}\n \\sum_k \\left(\n\\int_\\Omega M_i (\\frac{ \\phi({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {{\\rho_k}_i^n\\Delta t} ) dV\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} \n{\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta}   S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV \\right) =0,\n\\label{detail-sat-eqn-k-sum}\n\\end{equation}\n\nThe saturations and densities are flux limited in space and \ntime as explained in section \\ref{fluid_transport_methods_section}. This uses a finite element \ninterpolation of the saturations and densities which are limited. \n\t\t\t\n\n\nUsing $\\sum_{k=1}^{\\cal K} {S_k}_i^n =1, \\;\\; \\forall n$ and linear \n$\\rho_k^{n+1}$ about the CV pressure variation $P_{CV}^{n+1}$ then \n\n\\begin{equation}\n \\sum_k ( \\int_{\\Omega} M_i \n( \\frac{{S_k}_i^n \\frac{\\partial \\tilde{\\rho_k}_i^{n+1}}{\\partial \\tilde{ p_{CV}}_i^{n+1}}({p_{CV}}_i^{n+1}-\\tilde{p_{CV}}_i^{n+1})\n} {{\\rho_k}_i^n\\Delta t} \n+ \\frac{{S_k}_i^n( \\tilde{\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} \n{{\\rho_k}_i^n \\Delta t} ) dV\n\\end{equation}\n\\begin{equation}\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k dV ) =0.\n\\label{detail-global-cty}\n\\end{equation}\nIn matrix form this becomes:\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} \n= \\underline{\\bf s}_p. \n\\label{glob-cty-matrix}\n\\end{equation}\n\nNotice that in equation \\ref{detail-global-cty} the \ncontrol volume-wise variation of pressure ${p_{CV}}_i^n$ has been \nused and in order to get to the equation  \\ref{glob-cty-matrix} \nabove the finite element variation of pressure with basis \nfunctions $N_i$ has been used. Thus, to get to equation \n\\ref{glob-cty-matrix} the Galerkin projection\n\n\\begin{equation}\n\\int_{\\Omega} M_i (p_{CV}^n-p^n) dV =0\n\\end{equation}\nfor $p^n$ is used. This results in solving the matrix \nequation for ${\\bf p}^n$: \n\n\\begin{equation}\n{\\mathbf M}_{CV} \\underline{\\bf p}_{CV}^n = {\\mathbf N}_{CVfem} \\underline {\\bf p}^n\n\\end{equation}\nin which the matrix ${\\mathbf M}_{CV}$ is diagonal and thus \nthis can easily help form the matrix ${\\mathbf M}_p$ in equation \n\\ref{glob-cty-matrix}. \n\n\\subsection{Compressibility - CV and FEM pressure variations}\n\nHaving both a CV and FEM variation of pressure allows us to \nsimultaneously have an exact representation of the force balance \nequation as well as ensuring robustness of the the scheme \ne.g. positive densities from potentially complex equations \nof state. When using complex EoS's $\\frac{\\partial \\tilde { \\rho_k}_i^{n+1}}{\\partial \\tilde {p_{CV}}_i^{n+1}}$ is formed \nusing a pertabation approach, that is \nperturbing the pressure $\\tilde {p_{CV}}_i^{n+1}$ and looking how \nit effects the densities $\\tilde {\\rho_k}_i^{n+1}$. This \navoids differentiating complex EoS's. \n\n\t\t\t\t\n\n\\subsection{Upwind velocity/relative permeability} \n\\label{opt-up} \n\nIt remains to us to determine the velocity to be used \nat the interface between control volumes in the \nsaturation \\ref{detail-sat-eqn-k} and therefore \nthe global continuity equations \\ref{detail-global-cty}. \n\nThe problem is that the on a CV boundary it is unclear \nwhich side of the control volume boundary the velocity \nshould be taken from as there is a discontinuity \nof velocity at the CV boundary. The discontinuity \nis due to the differing relative permeabilities of \n$\\sigma_k$'s in each CV and is the only way that \nequation \\ref{force-semi-disc} can be strongly enforced. \nThis discontinuity happens between elements for the DG \nformulation and as well as between CVs within each element. \n\nOne way to determine the value of the velocity \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ \non the interface between two control volumes \nis to dermine the value of ${\\sigma_k}_{int}$ on this boundary \nand then one can obtain the value of \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ that \ncorresponds to this from equation \\ref{force-semi-disc}. \n\nWhen $({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ \nis determined one can turn this \ninto the proportion of each of the surrounding control \nvolumes goes up to make \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$. Here any downwind \nbiased averages are simply set to a central difference \n(which may not just be a simple average if we have \nunequal CV sizes or are using the FEM saturation \non the control volume boundary) and in the case \nwhen there is an upwind bias then this is accepted. \nThis choice is used in order to maintain consistency \nwith the characteristics of the BL equations. \n\n\\subsubsection{Upwind fraction $w_k$} \nThe upwind parameter $w_k$ is \ndetermined from the velocity \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ using:\n\n\\begin{equation}\nw_k= \\frac{({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int} - {{\\mathbf n}\\cdot{\\mathbf u}_k}_{right}}{{{\\mathbf n}\\cdot{\\mathbf u}_k}_{left} - {{\\mathbf n}\\cdot{\\mathbf u}_k}_{right}}\n\\label{w_k} \n\\end{equation}\nfor example:\n\n\\begin{equation}\n({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}= \\frac{{a_k}_{left} {\\sigma_k}_{left} {{\\mathbf n}\\cdot{\\mathbf u}_k}_{left} + {a_k}_{right} {\\sigma_k}_{right} {{\\mathbf n}\\cdot{\\mathbf u}_k}_{right}}{\\sigma_{int}}\n\\end{equation}\nwith ${a_k}_{left}+{a_k}_{right}=1$. \nNotice that internal to an element and with a uniform \nsource in each element then  \n\n\\begin{equation}\n{\\sigma_k}_{left} {{\\mathbf n}\\cdot{\\mathbf u}_k}_{left} =  {\\sigma_k}_{right} {{\\mathbf n}\\cdot{\\mathbf u}_k}_{right}\n\\label{u_int} \n\\end{equation}\nor for the case when equal sized CVs then a simple mean may be used:\n\n\\begin{equation}\n({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}= \\frac{\\frac{1}{2} {\\sigma_k}_{left}{{\\mathbf n}\\cdot{\\mathbf u}_k}_{left}  \n+ \\frac{1}{2}{\\sigma_k}_{right} {{\\mathbf n}\\cdot{\\mathbf u}_k}_{right}}{{\\sigma_k}_{int}}\n\\end{equation}\nUsing equation \\ref{u_int} then equation \\ref{w_k} becomes:\n\n\\begin{equation}\nw_k=\\left( \\frac{{\\sigma_k}_{left}}{{\\sigma_k}_{int}} \\right) \n\\frac{ {\\sigma_k}_{int} - {\\sigma_k}_{right}} \n{ {\\sigma_k}_{left} - {\\sigma_k}_{right}} \n\\label{w-eqn}. \n\\end{equation}\n\nIn equation \\ref{w-eqn} we assume the velocity goes from $left$ to $right$ \ncontrol volumes at the surface quadatruee point \nwhere we are evaluating the velocity. Now limiting \n$w_k$ so we have not down-winding using the \ngeometrically centered value of $w_k$ that is ${w_k}_{geom}$ \n(${w_k}_{geom}$ may equal $\\frac{1}{2}$ for same sized CVs) \nthen\n\n\\begin{equation}\n\\tilde w_k=\\beta (max\\{ w_k, {w_k}_{geom} \\}-{w_k}_{geom}) + {w_k}_{geom}\n\\end{equation}\n\nThe relaxation coefficient $\\beta$ allows one to \nexadurate the upwinding. We generally use $\\beta=1$ apart \nfrom with the approach outlined in section \nthe section '{Determining interface saturations  }' \nand approach 3 of that section in which case $\\beta=2$ is \nused to exadurate the unwinding.  \n\n\n\n\\subsubsection{Determining the interface absorption ${\\sigma_k}_{int}$ }\n\nFirst of all the value of that saturations ${S_k}_{int}$ \nare determined on the intefrcae between the CVs. \nFrom these we can then determine the values of ${\\sigma_k}_{int}$ \nusing the relative permeability equations. However, \nthis may be expensive and thus we store \nin each CV the values of $\\sigma_k$ as well \nas the derivatives $\\frac{\\partial \\sigma_k}{\\partial S_k}$. We then \ncan use a first order tailer series to determine \n(by projecting the gradient \nto the CV quadrature point. In fact this is done for \nboth CVs surrounding the interface to give the \ntwo values of predicted interface ${\\sigma_k}$. \nWe then choose the value in a conservative way that \nis associated with the most unwinding. \n\nThus, using a Taylor series about the $left$ CV:\n\n\\begin{equation}\n{{\\sigma_k}_{left}}_{int}\n=\n\\left( \n\\frac{\\partial \\sigma_k}{\\partial {S_k}}\n\\right)_{left}\n\\left( \n\\frac{ \n {S_k}_{int} - {S_k}_{right} } \n{{\\sigma_k}_{left} - {\\sigma_k}_{right} }\n\\right) \n\\end{equation}\nand about the $right$ CV:\n\n\\begin{equation}\n{{\\sigma_k}_{right}}_{int}\n=\n\\left( \\frac{\\partial \\sigma_k}{\\partial {S_k}}\n\\right)_{right}\n\\left( \n\\frac{ \n {S_k}_{int} - {S_k}_{left} } \n{{\\sigma_k}_{right} - {\\sigma_k}_{left} }\n\\right) \n\\end{equation}\nthen ${{\\sigma_k}}_{int}$ is chosen to be the one \nof ${{\\sigma_k}_{left}}_{int}$ and ${{\\sigma_k}_{right}}_{int}$\nthat is associated with the most unwinding as described above.\n\n\nFor multi-dimensional problems ${\\underline {\\underline \\sigma}}_k$ as well \nas the gradients $\\frac{\\partial {\\underline {\\underline \\sigma}}_k}{\\partial S_k}$ \nare tensors. We thus project their values \nonto the normal of the CV interface:\n\\begin{equation}\n{\\sigma_k}_{left} = {\\mathbf n}^T {{\\underline {\\underline \\sigma}}_k}_{left} {\\mathbf n},\n\\end{equation}\n\n\\begin{equation}\n{\\sigma_k}_{right} = {\\mathbf n}^T {{\\underline {\\underline \\sigma}}_k}_{right} {\\mathbf n}, \n\\end{equation}\n\n\\begin{equation}\n\\left({\\frac{\\partial \\sigma_k}{\\partial S_k}}\\right)_{left} = \n{\\mathbf n}^T \\left( {\\frac{\\partial {\\underline {\\underline \\sigma}}_k}{\\partial S_k}}\\right)_{left} {\\mathbf n}, \n\\end{equation}\n\n\\begin{equation}\n\\left({\\frac{\\partial \\sigma_k}{\\partial S_k}}\\right)_{right} = {\\mathbf n}^T \n\\left( \\frac{\\partial {\\underline {\\underline \\sigma}}_k}{\\partial S_k}\\right)_{right} {\\mathbf n}, \n\\end{equation}\n\n(where ${\\mathbf n}$ is the normal to the boundary) \nbefore determining ${\\sigma_k}_{int}$.  \n\n\n\n\n\\subsubsection{Determining the advection velocity at control volume boundaries}  \nIn the situation when you have a fully discontinuous method (e.g. the P2DG-P1DG element pair) then \none needs an averaging procedure to obtain the interface velocity between the elements. \nWithin an element is the same as for the continuous element.   \n\n\n\nFirstly, one needs to average the velocity contribution either side of the control volume \ninterface \nfrom the pressure and source terms in:\n\n\n\\begin{equation}\n\\sigma_k(S_k){\\bf u}_k =  \\nabla p + \\rho_k {\\bf g}\n\\label{force-o}  \n\\end{equation} \nin which $\\bf g$ is the gravity direction and magnitude and the bulk \ndensity $\\rho_k$. \n\nThis averaging  can be done with: \n\n\n\\begin{equation}\n{{\\bf v}}_k = \\frac{1}{2} ( {\\sigma_k}_i(S_k){{\\bf u}_k}_i + {\\sigma_k}_j(S_k){{\\bf u}_k}_j ) . \n\\end{equation} \nThen the interface velocities either side of the interface can be obtained from: \n\n\\begin{equation}\n{\\tilde{\\bf u}_k}\\:_i=   {\\sigma_k}_i^{-1}  {{\\bf v}}_k  , \\;\\;\\;\\; \n{\\tilde{\\bf u}_k}\\:_j =  {\\sigma_k}_j^{-1}  {{\\bf v}}_k    . \n\\label{two-vels}\n\\end{equation} \nNotice that these velocities point in the same direction and are just different in magnitude. \nThus, using them to define an upwind direction is not ambiguous and a good approach or alternative \nto Roe averaging. \nSo an alternative to using Roe averaging is to use: \n\\begin{equation}\n{\\bf a}_k= \\frac{1}{2} \\left( \\frac{\n {\\sigma_k}_i(S_k){{\\bf u}_k}_i + {\\sigma_k}_j(S_k){{\\bf u}_k}_j \n}\n{ {\\sigma_k}_i(S_k)+{\\sigma_k}_j(S_k)} \\right),\n\\end{equation} \nto determine if information is leaving or going into a CV. This defintiion of ${\\bf a}_k$ can be used \nwithin an element or between DG finite elements. \n\n\n\nThe two values of velocity provide, in equation \\ref{two-vels}, provide the two extremes within which the final interface \nvelocity is obtained. Notice that if the saturation and density are equal in \nCVs $i$ and $j$ then these velocities will be identical. This is important in order to \nsolve the elliptic nature of the resulting pressure equation. \n\nIf we are to apply an upwind method of calculating the interface velocity then \nthe interface velocity becomes, for ${\\bf n}\\cdot {\\bf a}_k>0$ - CV $i$ outgoing information:\n\\begin{equation}\n{\\tilde{\\bf u}}_k = {\\tilde{\\bf u}}_k\\:_i ,\n\\end{equation} \nand, for ${\\bf n}\\cdot {\\bf a}_k<0$ - CV $i$ incoming information:\n\\begin{equation}\n{\\tilde{\\bf u}}_k = {\\tilde{\\bf u}}_k\\:_j. \n\\end{equation} \n\nHowever, this upwind method will result in dissipative solutions even when the saturation in the transport equation \\ref{tran-S}\nhas a high order value. \nOut of numerous heuristic's for obtaining this interface velocity ${\\tilde{\\bf u}}_k$ we choose \na method based on a limited high order saturation $\\tilde S_k$.  \nThe high order flux-limited value of saturation $\\tilde S_k$ is obtained using a DG FEM upwind approximation to \nobtain the high order value - again using the \nsign of ${\\bf n}\\cdot {\\bf a}_k$ to determine the upwind direction. \n\nFrom this saturation $\\tilde S_k$ we can obtain \n$\\tilde\\sigma_k = \\sigma_k (\\tilde S_k)$ knowing $\\tilde S_k$ or avoiding referring back to the relative \npermeability functions \nwe can estimate the corresponding interface value of $\\sigma_k$ that is \n$\\tilde\\sigma_k$ from the second order Taylor series for ${\\bf n}\\cdot {\\bf a}_k>0$ - CV $i$ outgoing information: \n\n\\begin{equation}\n\\tilde\\sigma_k =   {\\sigma_k}_i + (\\tilde S_k - {S_k}_i) \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_i \n+\\frac{1}{2} (\\tilde S_k - {S_k}_i)^2   \n\\left(  \\frac{  \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_i - \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_j  }  \n{{S_k}_i - {S_k}_j}  \\right) , \n\\label{sigma-out}\n\\end{equation} \nand for ${\\bf n}\\cdot {\\bf a}_k<0$ - CV $i$ incoming information:\n\n\\begin{equation}\n\\tilde\\sigma_k =  {\\sigma_k}_j + (\\tilde S_k - {S_k}_j) \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_j \n+\\frac{1}{2} (\\tilde S_k - {S_k}_j)^2   \n\\left(  \\frac{  \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_i - \\left(\\frac{\\partial\\sigma_k}{\\partial S_k}\\right)_j  }  \n{{S_k}_i - {S_k}_j} \\right), \n\\label{sigma-in}\n\\end{equation} \nand $\\tilde\\sigma_k$ is also adjusted to ensure that it lies between ${\\sigma_k}_i$, ${\\sigma_k}_j$ - since \nin general $\\tilde\\sigma_k$ is a tensor on the boundaries of the CVs we only require its \nnormal component ${\\bf n}^T\\tilde\\sigma_k {\\bf n}$ which is then subject to this boundedness constraint. \nIt should be noted that for high order elements it may be advantageous to use $\\tilde\\sigma_k = \\sigma_k (\\tilde S_k)$ \ndirectly so as to maintain the high order convergence. In addition, for robustness, one can \nchoose to only add the second order terms in equations  \\ref{sigma-out}, \\ref{sigma-in} if the resulting \n$\\tilde\\sigma_k $ is closer to the upwind value of $\\sigma_k$, either ${\\sigma_k}_i$ or ${\\sigma_k}_j$ \ndepending on the direction of the velocity ${\\bf a}_k$. \n\nThus, the final interface velocity is obtained from:\n\\begin{equation}\n{\\tilde{\\bf u}_k} = {\\tilde\\sigma_k}^{-1}  \\frac{1}{2} ( {\\sigma_k}_i {{\\bf u}_k}_i + {\\sigma_k}_j {{\\bf u}_k}_j ), \n\\label{mean_int_vel}  \n\\end{equation} \nwhich is in addition bounded to ensure it lies between the velocities ${\\tilde{\\bf u}_k}\\:_i$ and ${\\tilde{\\bf u}_k}\\:_j$ \nor more precisely its normal component ${\\tilde{\\bf u}_k}\\cdot {\\bf n}$ is bounded to ensure it lies between \n${\\tilde{\\bf u}_k}\\:_i\\cdot {\\bf n}$ and ${\\tilde{\\bf{u}}_k}\\:_j\\cdot {\\bf n}$. \nThe result of this is also bounded between the velocities \n${{\\bf u}_k}_i\\cdot {\\bf n}$ and ${{\\bf u}_k}_j\\cdot {\\bf n}$. \nNotice that inside an element without discontinuous sources (in force balance equation \\ref{force-o}) ${\\tilde{\\bf u}_k}\\:_i={{\\bf u}_k}\\:_i$, ${\\tilde{\\bf u}_k}\\:_j={{\\bf u}_k}\\:_j$, \n${\\sigma_k}_i {{\\bf u}_k}_i = {\\sigma_k}\\:_j {{\\bf u}_k}\\:_j $ and \nequation \\ref{mean_int_vel} simply takes on the upwind value of velocity if we choose the upwind value of $\\sigma_k$ for \ninterface value $\\tilde\\sigma_k$.\n\nIn practice we have found that for CV boundaries inside an element equation \\ref{mean_int_vel} \ncan be used to obtain the interface velocities. \n\nThe upwind approach now becomes: \nfor ${\\bf n}\\cdot {\\bf a}_k>0$, \n\\begin{equation}\n{\\tilde{\\bf u}_k} ={{\\bf u}_k}_i \n\\end{equation} \nand for ${\\bf n}\\cdot {\\bf a}_k<0$,\n\\begin{equation}\n{\\tilde{\\bf u}_k} ={{\\bf u}_k}_j \n\\end{equation} \nto determine the velocities. \n\nIn regions of the domain when the saturation have \nno spacial variation then at the time level in which this occurs an average of the velocity \nis obtained in a similar approach to the Harmonic averaging procedure commonly used to \nobtain interface absolute permeabilities. \n\n\n\\subsubsection{Determining velocity between discontinuous finite elements} \n\nDetermining the velocity between finite elements in a fully discontinuous is needed \n to determine these in order to advect the saturations, and other variables, \nbetween the elements. It is also needed in order to obtain the discretised \nnon-symmetric pressure equation which has elliptic like properies. These properties \nmean it is necessary to propogate information in all directions across the domain. \nThus, taking the upwind velocity (as commonly done within an element) is not necesserily \na good idea. \nA simple way of obtaining the interface velocity is to choose as the interface velocity the mean \nvelocity of velocities either side of the interface: \n\n\\begin{equation}\n{\\tilde{\\bf u}_k} = \\frac{1}{2} ({{\\bf u}_k}_i+{{\\bf u}_k}_j). \n\\end{equation} \nHowever, more accurate velocities may be obtained. \nFor the two neibouring CVs $i$ and $j$ which have an interface \nbetween finite elements a way of determining a field ${\\bf u}_k$ is by using a volume \nweighting or in one dimension this is equivalent to simple interpolation to the interface, that is: \n\n\\begin{equation}\n{\\tilde{\\bf u}_k} = \\frac{ V_j {{\\bf u}_k}_i + V_i {{\\bf u}_k}_j  } {V_i +V_j} \n\\end{equation} \nin which $V_i$, $V_j$ are the volumes of control volumes $i$ and $j$. \nHowever, from the force balance equation \n\\ref{force-o}  we see that there is also a $\\sigma_k$ weighting of the \nvelocities in an analogious way to the volume weighting in the above equation. \nIn fact the volume of the control volume and $\\sigma_k$ act on the velocity ${\\bf u}_k$ in a very similar \nway and thus: \n\\begin{equation}\n{\\tilde{\\bf u}_k} = \\frac{ V_j \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{kj} \\cdot \\mathbf{n} {{\\bf u}_k}_i + V_i \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n} {{\\bf u}_k}_j }\n{ V_i \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n} + V_j  {\\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{kj} \\cdot \\mathbf{n} }}. \n\\end{equation} \nNow some Discontinuous Galerkin DG methods dispense with the volume weighting \nin faviour of weighting the solution equally either side of a between element interface (e.g. Bassey Rabi) \nand thus: \n\\begin{equation}\n{\\tilde{\\bf u}_k} = \\frac{ \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n}{{\\bf u}_k}_i + \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n} {{\\bf u}_k}_j }\n{ \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n} + \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{kj} \\cdot \\mathbf{n} }. \n\\end{equation} \nMoreover, we may be able to improve on simple linear interpolation in the above equation \nby using the interface value $\\tilde\\sigma_k$ from say equations \\ref{sigma-out},\\ref{sigma-in} for \nexample: \nIf ${\\bf a}_k\\cdot {\\bf n}<0$ -incomming information, \n\\begin{equation}\n{\\tilde{\\bf u}_k} = w {{\\bf u}_k}_i + (1-w) {{\\bf u}_k}_j\n\\end{equation} \nand if ${\\bf a}_k\\cdot {\\bf n}>0$ -outgoing information, \n\\begin{equation}\n{\\tilde{\\bf u}_k} = (1-w) {{\\bf u}_k}_i + w {{\\bf u}_k}_j\n\\end{equation} \nwith\n\\begin{equation}\nw=\\frac{\\tilde{\\sigma_k}}{ \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{ki} \\cdot \\mathbf{n} + \\mathbf{n}\\cdot \\underline {\\underline\\sigma}_{kj} \\cdot \\mathbf{n} }. \n\\end{equation} \n\n\n\\subsubsection{Modifications to ensure boundedness of saturation} \nSaturation is bounded between $S_w\\in \\left[ S_{wir}, 1-S_{sor} \\right]$ \nfor example $S_w\\in \\left[ 0.2, 0.8 \\right]$. \nThe basic equations and boundary conditions ensure that saturation is $S_w\\in \\left[0, 1\\right]$. \nEnsuring that the former $S_w\\in \\left[ S_{wir}, 1-S_{sor} \\right]$ is realized through the relative \npermeability functions. In the continuum they ensure that as these limits are reached \nno flow can occur for the phase in question and thus its saturation can not change and go \nbeyond its limits. \nNumerically, this is realized with the CVFEM approach when the velocities are $\\it upwinded$. \nThat is the upwind value of the discontinuous velocity (either side of a control volume interface) \nis chosen. Thus, if the relative permeability approaches zero for the upwind cell, the \ncorresponding velocity also approaches zero and thus saturation can not exit this cell - that is \nno flux of that saturation can occur from the upwind cell and thus the saturation can \nnever decrease. However, since we are taking the upwind velocities (within this argument)  \nwe can still advect into this cell so the cell saturation can increase. \nIn practise we use a flux limiting procedure to choose combination of \nupwind and downwind velocities to use, but this resorts to using the upwind velocity if \nthere is an oscillation and thus the high order limited velocities also ensures  \nboundedness between $S_w\\in\\left[ S_{wir}, 1-S_{sor} \\right]$. \n\nFor the discontinuous method above we do not have this property that the upwind velocity is \nnecessarily chosen as the velocity to us. However, we can choose this velocity if \nthe method detects that there is a rapid variation in the relative permeability functions \nassociated with both neighbouring cells. \n\nThus, a variable $h$ is introduced either side of the interface for \nneighbouring cells $i$ and $j$, that is ${h_k}_{i}$, ${h_k}_{j}$: \n\n\\begin{equation}\n{h_k}_{i} = min\\{ 1,  \\frac{\\tilde{\\sigma_k}_i}{{\\sigma_k}_i} \\}, \\;\\;\\;\n{h_k}_{j} = min\\{ 1,  \\frac{\\tilde{\\sigma_k}_j}{{\\sigma_k}_j} \\}, \n\\end{equation} \nin which $\\tilde{\\sigma_k}_i$ is the extrapolated (using a first order Taylor series, see equations \n\\ref{sigma-in}, \\ref{sigma-out}) \nvalue of $\\sigma_k$ from cell $i$ to the \nface value of $\\sigma_k$. \nNow the interface velocity is:  \n\n\\begin{equation}\n{\\tilde{\\bf u}_k} = {{\\cal I}_k}_i  {{\\bf u}_k}_i + {{\\cal I}_k}_j {{\\bf u}_k}_j. \n\\end{equation} \n\nWe form an interface value of variables ${h_k}_{i}$ and ${h_k}_{j}$ using their upwind values (based on the sign of \n${\\bf a}_k\\cdot {\\bf n}$) to form ${h_k}_{ij}$. That is for cell $i$ if ${\\bf a}_k\\cdot {\\bf n}>0$ (outgoing information) \nthen \n${h_k}_{ij}= {h_k}_{i}$ and if ${\\bf a}_k\\cdot {\\bf n}<0$ (incomming information) then\n${h_k}_{ij}= {h_k}_{j}$.   \n\nThus,  there are a number of schemes:\n\n\\noindent\n{\\it Scheme 1: Simple combined average and upwind method} \n\n\\noindent\nFor ${\\bf a}_k\\cdot {\\bf n}>0$ (outgoing information) for cell $i$: \n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) 1 + {h_k}_{ij}\\frac{1}{2},   \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) 0 + {h_k}_{ij}\\frac{1}{2};\n\\end{equation} \nelse if ${\\bf a}_k\\cdot {\\bf n}>0$ (outgoing information) for cell $i$: \n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) 0 + {h_k}_{ij}\\frac{1}{2},   \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) 1 + {h_k}_{ij}\\frac{1}{2}.   \n\\end{equation} \n\n\n\\vspace{1cm}\n\\noindent\n{\\it Scheme 2: Simple upwind combined with high order method} \n\n\\noindent\nFor ${\\bf a}_k\\cdot {\\bf n}>0$ (outgoing information) for cell $i$: \n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) 1 + {h_k}_{ij}\\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j },  \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) 0 + {h_k}_{ij}\\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j };\n\\end{equation} \nelse if ${\\bf a}_k\\cdot {\\bf n}<0$ (incomming information) for cell $i$:\n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) 0 + {h_k}_{ij}\\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j },  \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) 1 + {h_k}_{ij}\\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }.   \n\\end{equation} \n\n\\vspace{1cm}\n\\noindent\n{\\it Scheme 3: High order upwind combined with high order method} \n\n\\noindent\nFor ${\\bf a}_k\\cdot {\\bf n}>0$ (outgoing information) for cell $i$: \n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) min\\{ 1, \\frac{{\\sigma_k}_i}{\\tilde{\\sigma_k}_i}  \\} \n+ {h_k}_{ij}\\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j },  \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) min\\{ 1, \\frac{{\\sigma_k}_j}{\\tilde{\\sigma_k}_i}  \\}\n+ {h_k}_{ij}\\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }; \n\\end{equation} \nelse if ${\\bf a}_k\\cdot {\\bf n}<0$ (incomming information) for cell $i$:\n\\begin{equation}\n{{\\cal I}_k}_i = (1-{h_k}_{ij}) min\\{ 1, \\frac{{\\sigma_k}_j}{\\tilde{\\sigma_k}_j}  \\} \n+ {h_k}_{ij}\\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j },  \\;\\;\\;\\; \n{{\\cal I}_k}_j = (1-{h_k}_{ij}) min\\{ 1, \\frac{{\\sigma_k}_i}{\\tilde{\\sigma_k}_j}  \\}\n+ {h_k}_{ij}\\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }.   \n\\end{equation} \n\n\n\\vspace{1cm}\n\\noindent\n{\\it Scheme 4: Bi-directional high order upwind combined with high order method} \n\n\\noindent\nFor cell $i$: \n\\begin{equation}\n{{\\cal I}_h}_i = (1-{h_k}_{ij}) \\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }\n+ {h_k}_{ij}\\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j },  \\;\\;\\;\\; \n{{\\cal I}_h}_j = (1-{h_k}_{ij}) \\frac{ V_j{\\sigma_k}_j }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }\n+ {h_k}_{ij}\\frac{ V_i{\\sigma_k}_i }{ V_i{\\sigma_k}_i + V_j{\\sigma_k}_j }.   \n\\end{equation} \n\n\n\n\\vspace{1cm}\n\\noindent\n{\\it Reasons for violating boundedness and the upwind velocity} \n\nWe have found that using the high order method to obtain the saturation advection \nvelocity (as well as the saturation) at the CV boundaries does not perfectly preserve \nthe boundedness of the saturation $S_w\\in \\left[ S_{wir}, 1-S_{sor} \\right]$. \nIt can deviate from boundedness by approximately 0.01. \nThese is because the underlying method that ensures boundedness is the upwind \nvelocity method which is almost universely used through the reservoir \nmodelling communities. However, this is not necessarily accurate so it \nis worth trying to use a high order value of velocity. \nTo overcome this difficulty we introduce,  within a CV face criteria:\n\\begin{equation}\n\\frac{ \\min\\{ {\\sigma_k}_i, {\\sigma_k}_j \\}  }{{\\sigma_k}_i +{\\sigma_k}_j} < \\epsilon_\\sigma \n\\end{equation} \nonce satisfied the method switches to using an upwind velocity rather than \nthan the high order value. \nFor the discontinuous between element boundaries velocity we use a similar criteria \nbut simply set the velocity to zero once this criteria:\n\\begin{equation}\n{\\sigma_k}_{upwind} > \\infty\n\\end{equation} \nis met. Here $\\infty=10^{10}$ and $\\epsilon_\\sigma=0.001$ and \n${\\sigma_k}_{upwind}$ is the upwind value - either ${\\sigma_k}_i$ or ${\\sigma_k}_j$. \nBoth these modification, effectively set the velocity to zero or a small value \nfor outcomming velocities of a CV which is close to violating the boundedness \ncondition  $S_w\\in \\left[ S_{wir}, 1-S_{sor} \\right]$. \nThus, if there is no velocity or mass flux going out of a CV close to \nthe minimum value of saturation then there can be no further reduction of this saturation and no \nviolation of the boundedness criteria. \nThis is essentially why the upwind method works to ensure boundedness as the \nupwind CV will have a large value of ${\\sigma_k}_{upwind}$ and thus a small \nvelocity. \n\n\n\n\n\\subsection{Boundary conditions for saturation, pressure and relative permeability} \n\\label{bcs-rel-perm} \nSuitable boundary conditions can be guided by the \ndiscontinuous formulations above as well as the up-winding in \nthe continuous formulations. In fact, exactly the same \nboundary condition implementations can be applied as used in \nthe discontinuous formulations but across the boundaries \nof the domain and taking information from just outside the domain \nrather than in the neighbouring elements. \n\nSaturation boundary conditions are relatively straightforward. \nOne typically takes the saturation from just outside the domain \n(the saturation boundary condition ${S_k}_{bc}$) \nas part of the incoming flux \n(when ${\\bf n}\\cdot {\\bf u}_k<0$) for phase $k$:\n\n\\begin{equation}\n{\\bf n}\\cdot {\\bf u}_k {S_k}_{bc} .\n\\end{equation}\n\nWhen in addition the velocity \n${\\bf n}\\cdot {{\\bf u}_k}_{bc}$ is \nspecified then this too must be part of the \nincoming flux (when ${\\bf n}\\cdot {{\\bf u}_k}_{bc}<0$) for phase $k$:\n\n\\begin{equation}\n{\\bf n}\\cdot {{\\bf u}_k}_{bc} {S_k}_{bc} .\n\\end{equation}\n\nSimilar, boundary conditions can be applied using Riemann \nvariables to work out if information is travelling into \nor out of the domain although most models do not follow this \nmore rigorous approach. \n\nSpecified pressure boundary conditions for outlet \nflux (when ${\\bf n}\\cdot {\\bf u}_k>0$) for phase $k$ are:\n\n\\begin{equation}\n{\\bf n}\\cdot {\\bf u}_k {S_k},\n\\end{equation}\nin which neither ${\\bf u}_k$, ${S_k}$ are specified. \n\nSpecified pressure boundary conditions for the inlet \nflux (when ${\\bf n}\\cdot {\\bf u}_k<0$) for phase $k$ are:\n\n\\begin{equation}\n{\\bf n}\\cdot {{\\bf u}_k}_{rel} {S_k}_{bc},\n\\label{flux-adjust-rel} \n\\end{equation}\nin which the relative permeability is up-winded and thus taken \nfrom outside the domain resulting in a value of ${\\underline {\\underline \\sigma}}_k$ of \n${{\\underline {\\underline \\sigma}}_k}_{outside}$. The latter is calculated from \nthe saturation boundary condition value ${S_k}_{bc}$. \nThis means that the \nsolution velocity ${{\\bf u}_k}$ needs to be adjusted in \nequation \\ref{flux-adjust-rel} to apply this upwind permeability \nvia:\n\n\\begin{equation}\n{{\\bf u}_k}_{rel}={{\\underline {\\underline \\sigma}}_k}_{outside}^{-1}{{\\underline {\\underline \\sigma}}_k}_{inside} {{\\bf u}_k}. \n\\label{u-orig-interface} \n\\end{equation}\n\nA second approach for determining this velocity is to base it on the discontinuous element theory \nthat is used to determine the velocity between the elements. That is,\n\n\\begin{equation}\n{{\\bf u}_k}_{rel}=   \n({{\\underline {\\underline \\sigma}}_k}_{inside}+{{\\underline {\\underline \\sigma}}_k}_{outside})^{-1}\n (   {{\\underline {\\underline \\sigma}}_k}_{outside} {{\\bf u}_k}_{inside} \n+{{\\underline {\\underline \\sigma}}_k}_{inside} {{\\bf u}_k}_{outside}    ), \n\\label{interface-vel-1}\n\\end{equation}\nin which the subscripts $inside$ and $outside$ represent the indicated variables just inside \nand just outside of the domain. We can use the velocity given by equation \\ref{u-orig-interface} \nas the velocity just outside the domain, ${{\\bf u}_k}_{outside}$, and thu equation \\ref{interface-vel-1} \nbecomes: \n\n\\begin{equation}\n{{\\bf u}_k}_{rel}=   \n({{\\underline {\\underline \\sigma}}_k}_{inside}+{{\\underline {\\underline \\sigma}}_k}_{outside})^{-1}\n (   {{\\underline {\\underline \\sigma}}_k}_{outside}  \n+{{\\underline {\\underline \\sigma}}_k}_{inside}   {{\\underline {\\underline \\sigma}}_k}_{inside}^{-1} \n{{\\underline {\\underline \\sigma}}_k}_{outside}  ){{\\bf u}_k}_{inside},\n\\label{interface-vel-2}\n\\end{equation}\nwhich becomes simply: \n\\begin{equation}\n{{\\bf u}_k}_{rel}=   2\n({{\\underline {\\underline \\sigma}}_k}_{inside}+{{\\underline {\\underline \\sigma}}_k}_{outside})^{-1}\n{{\\underline {\\underline \\sigma}}_k}_{outside}   {{\\bf u}_k}_{inside}. \n\\label{interface-vel-3}\n\\end{equation}\n\nA third approach for up-winding the \nrelative permeability on incoming specified pressure \nboundaries is to simply adjust the value of ${{\\underline {\\underline \\sigma}}_k}_{inside}$ \njust inside the domain by setting it to the \nvalue just outside the domain \n\\begin{equation}\n{{\\underline {\\underline \\sigma}}_k}_{inside}={{\\underline {\\underline \\sigma}}_k}_{outside} ,\n\\end{equation}\nand the flux \ncondition then becomes: \n\n\n\\begin{equation}\n{\\bf n}\\cdot{{\\bf u}_k} {S_k}_{bc}.\n\\end{equation}\nIt should be noted that the flux conditions above \nmust be used in both the discretised saturation equations \nas well as the global continuity equation - since the latter \nis a summation of the former. \n\nThe specified pressure condition becomes a surface flux \ncondition in the force balance equation of \n\n\\begin{equation}\n{\\bf n} (p-p_{bc}),\n\\end{equation}\nwhich effectively relaxes the pressure $p$ to its boundary \nvalue $p_{bc}$ at the boundary. \n\n\n\n\\pagebreak\n\t\t\n\n\\section{Projection method of solution} \n\\label{Projection method of solution}\n\nThe  \nglobal mass balance equation \\ref{glob-cty-matrix} and \nforce balance equations \\ref{force-balance-matrix-form} are solved here \nby using a projection method. This effectively eliminates \nout velocity and solves a system of equations for \npressure or pressure correction. \n\nThe force balance (at time level $n+1$) \nand global continuity equations are:\n\n\\begin{equation}\n({\\mathbf M}_\\sigma +{\\mathbf A}) \\underline{\\bf u}^{n+1} = {\\mathbf C} \\underline{\\bf p}^{n+1} + \\underline{\\bf s}_u^{n+1},\n\\label{force-balance-matrix-form2}\n\\end{equation}\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} = \\underline{\\bf s}_p^{n+1}. \n\\label{glob-cty-matrix2}\n\\end{equation}\n\nFor generality we have introduced a matrix ${\\mathbf A}$ which may be \ndistributed and thus can not be easily inverted. \nThis allows the method to be applied to inertia dominated \nor viscous dominated flows without modification. \nUsing the discontinuous velocity within an element \nformulation the matrix ${\\mathbf M}_\\sigma$ is block diagonal \nand thus easily inverted - each block being local to an element. \n\nThe solution method proceeds by first solving for \nan intermediate velocity $\\underline{\\bf u}^{n+1}_*$ using a \nguessed pressure $\\underline{\\bf p}^{n+1}_*$ on the first iteration \nwithin a time step one may use $\\underline{\\bf p}^{n+1}_*=\\underline{\\bf p}^n$ say. \nThe equation is: \n\n\\begin{equation}\n({\\mathbf M}_\\sigma +{\\mathbf A}) \\underline{\\bf u}^{n+1}_* = {\\mathbf C} {\\bf p}^{n+1}_* + \\underline{\\bf s}_u^{n+1}. \n\\label{force-balance-matrix-form2-guess}\n\\end{equation}\nThe matrix equation for velocity to be satisifed is: \n\\begin{equation}\n{\\mathbf M}_\\sigma\\underline{\\bf u}^{n+1} +{\\mathbf A} \\underline{\\bf u}^{n+1}_* = {\\mathbf C} \\underline{\\bf p}^{n+1} + \\underline{\\bf s}_u^{n+1}. \n\\label{force-balance-matrix-form2-guess-2}\n\\end{equation}\nSubtracting these two equations the   \nvelocity correction equation is obtained:\n\\begin{equation}\n{\\mathbf M}_\\sigma ( \\underline{\\bf u}^{n+1} -\\underline{\\bf u}^{n+1}_*) \n= {\\mathbf C} (\\underline{\\bf p}^{n+1} - \\underline{\\bf p}^{n+1}_*). \n\\label{force-balance-matrix-form2-guess}\n\\end{equation}\nMultiplying this equation by ${\\mathbf B}^T {\\mathbf M}_\\sigma^{-1}$ \n(see global continuity \nequation \\ref{glob-cty-matrix2}) and using the global comntinuity \nequation to eliminate out $ \\underline{\\mathbf u}^{n+1} $ one obtains \nthe pressure correction equation:\n\n\\begin{equation}\n({\\mathbf B}^T {\\mathbf M}_\\sigma^{-1} {\\mathbf C} + {\\mathbf M}_p) (\\underline{\\bf p}^{n+1} - \\underline{\\bf p}^{n+1}_*) \n= - {\\mathbf M}_p \\underline{\\bf p}^{n+1}_* - {\\mathbf B}^T \\underline{\\bf u}^{n+1}_* + \\underline{\\bf s}_p^{n+1}.\n\\end{equation}\nthis equation is solved for the pressure  $\\underline{\\bf p}^{n+1}$ and the \nvelocity is corrected using equation \\ref{force-balance-matrix-form2-guess}.\n\n\n\\subsection{Continuity equation projection after an adapt or mesh to mesh interpolation} \n\nAfter an adapt or more specifically mesh to mesh interpolation it may be found that the \nresulting velocity and pressure pairs do not closely enough satisfy the descrete continuity equation. \nThe result of this can be that the algorithm (particularly for interface capturing methods) \ncan go unstable and the velocity and pressure magnitudes rise sharply after an adapt because of this. We have found this is especially true of 3D flows and with P1DG-P2 simulations. \n\nHowever, one can simply project to a descrete continuity satisfying space by \nsimply performing a time step but missing out the velocity solution (solving the \ndescret momentum equations) and then at the end of the first iteration of the first time step \nafter an adapt set the old velocity and pressure equal to the new velocity and pressure. \nThis will work for multi-phase flow problems as well as compressible flows. For compressible \nflows one needs to solve for temperature/internal-energy/energy before \nthis projection so we have an approximation to the density derivative in time to use in \nthe new continuity equation. \n\n\n\\subsection{High order hydrostatic or source term balanced pressure solver} \n\nTo incease accuracy one may be able to seperate out the hydrostatic (or source based) \npressure and solve for it seperately using a polynomial of one higher degree than the rest of the pressure say. \nSuppose the momentum source if ${\\bf f}$ and the hydraustic \npressure $p_h$ (or source based pressure) which is part of the full pressure $p=p_{nh} + p_h$. \nThis is calulcated using the weak equations: \n\n\\begin{equation}\n\\int_V \\nabla {M_h}_i \\cdot \\frac{1}{\\rho} \\nabla p_h dV =  \\int_V \\nabla {M_h}_i \\cdot \\frac{1}{\\rho} {\\bf f} dV, \n\\end{equation}\nwith corresponding weak boundary conditon:\n\\begin{equation}\n \\int_{\\Gamma} {M_h}_i {\\bf n}\\cdot\\frac{1}{\\rho} \\nabla p_h d\\Gamma = \\int_{\\Gamma} {M_h}_i {\\bf n}\\cdot \\frac{1}{\\rho}{\\bf f} d\\Gamma, \n\\end{equation}\nin which ${\\bf n}$ is the normal to the surface and ${M_h}_i$ is the basis function for hydraustatic pressure \nand thus $p_h =\\sum_j {M_h}_j {p_h}_j$. \nThe result residual \n\\begin{equation}\n\\int_V {N}_i ( \\nabla p_h - {\\bf f} ) dV, \n\\end{equation}\nis then placed into the right hand side of the discretized momentum equation. \n\n\n\n\n\t\t\t\n\n\\pagebreak\t\n\n\n\\section{A Compositional Flow \nMethod based on Non-Equilibrium \nEquations}\n\\label{Compositional}\n\n\\subsection{Summary}\nHere a new method of solving the compositional multi-phase flow \nequations is proposed. The method described here is applied to equilibrium equations; however it does not presume equilibrium assumptions. \nIt is shown how bounded saturations and compositional phase fractions \nresult and that the phase summed saturations and \ncomponent summed (for each phase) unity constraints are \nnaturally enforced. Although the resulting equations can \nbe solved using any number of approaches \n(e.g. finite difference methods) they are solved \nhere using a new overlapping \nfinite element method which uniquely ensures that the force balance \nequations (Darcy's law) are strongly/exactly enforced.  \nThe focus of the work is on reservoir simulations. \n\n\n\\subsection{Introduction}\nIn compositional flow, a number of components exist in three phases (gas, oil, water).\n{\\it We assume no mass interchange between the water and the hydrocarbon phases}. \nLet $y_i^{o}$ and $y_i^{g}$ are the mass fractions of component $i$ \nwithin phase $j$ \nwhere $i = 1,2,..,{\\cal N}_c$ and ${\\cal N}_c$ is the number of components and ${\\cal N}_p$ is the \nnumber of phases. \nThe density of phase $j$ and component $i$ is $\\rho_i^j$. \nA constraint on the system is: \n\\begin{equation}\n\\sum_{i=1}^{{\\cal N}_c} y_i^j = 1, ~~~ j = o,g .\n\\end{equation}\nThe compositional mass fraction $y_i^j$ is not conserved within each phase partly due to mass interchange between phases. \nHowever, we assume no mass interchange between water and hydrocarbon phases\nand thus the mass conservation equation for the water phase is unchanged. \nFor each hydrocarbon component $i$ the mass conservation\nequation is of the form, \n\\begin{equation}\n\\phi \\frac{\\partial}{\\partial t}(y_i^o \\rho_i^o S^o + y_i^g \\rho_i^g S^g) + \\nabla \\cdot (y_i^o \\rho_i^o S^o  \\mathbf{u}^{o} + y_i^g \\rho_i^g S^g  \\mathbf{u}^{g}) - Q_i = 0, ~~i = 1,2,..,{\\cal N}_c ,  \n\\label{saturation_2phases}\n\\end{equation}\nwith a component $i$ mass source of $Q_i$. \nThe force balance equations are based on Darcy's flow equations: \n\\begin{equation}\n \\sigma^j {\\mathbf u}^j = - \\nabla p^j, ~~~~~ j = o,g,w .\n\\label{force-bal}\n\\end{equation}\nIn the current formulation, the capillary pressures are set to zero and thus $ p_o = p_g = p_w  = p $.\nAnother constraint on the saturation fields is added because the porous medium is saturated with fluids: \n\\begin{equation}\n S^o + S^g + S^w = 1. \n\\end{equation}\nIn the above example it may be that \n$\\rho_i^o=\\rho_1^o$ and $\\rho_i^g=\\rho_1^g$ $\\forall i$. \nHowever, in general this is not true. \n\n\n\n\\subsubsection{Equations for saturation}\n\n The saturation equation (see equation \\ref{saturation_2phases}) can be rewritten \n in general as\n\\begin{equation}\n\\displaystyle\\frac{\\partial}{\\partial t}\\left(\\phi\\rho^{j}S^{j}\\right) + \\nabla\\cdot\\left(\\rho^{j}S^{j}\\mathbf{u}^{j}\\right) -m^{j} = 0,\\;\\;\\;\\;\\; j = 1,2,...~, {\\cal N}_p .\n\\label{saturation_compositional_1}\n\\end{equation}\nAssuming a three phase problem ({\\it j=} oil, gas, water)  \nequation \\ref{saturation_compositional_1} becomes,\n\\begin{eqnarray}\n\\displaystyle\\frac{\\partial}{\\partial t}\\left(\\phi\\rho^{w}S^{w}\\right) + \\nabla\\cdot\\left(\\rho^{w}S^{w}\\mathbf{u}^{w}\\right) -m^{w} = 0, \\nonumber \\\\\n\\displaystyle\\frac{\\partial}{\\partial t}\\left(\\phi\\rho^{o}S^{o}\\right) + \\nabla\\cdot\\left(\\rho^{o}S^{o}\\mathbf{u}^{o}\\right) -m^{o} = 0, \\\\\n\\displaystyle\\frac{\\partial}{\\partial t}\\left(\\phi\\rho^{g}S^{g}\\right) + \\nabla\\cdot\\left(\\rho^{g}S^{g}\\mathbf{u}^{g}\\right) -m^{g} = 0, \\nonumber \\\\\n\\label{saturation_compositional_2}\n\\end{eqnarray}\nin which $m^j$ are the mass source terms. Conservation of \nmass ensures that $\\sum_{j=1}^{{\\cal N}_p} m^j=m^{w}+m^{o}+m^{g}=0$. \n\n\n\\subsection{New multi-component formulation}\nUsing the general formulation for multi-component (${\\cal N}_c$ is the number of components), multi-phase (${\\cal N}_p$ is the number of phases) the mass conservation equation of component $i$ is\n\\begin{equation}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(\\sum\\limits_{j=1}^{{\\cal N}_p}y_{i}^{j}\\rho_{i}^{j}S^{j}\\right) + \\nabla\\cdot\\left(\\sum\\limits_{j=1}^{{\\cal N}_p}y_{i}^{j}\\rho_{i}^{j}S^{j}\\mathbf{u}^{j}\\right) - Q_{i} = 0, ~~~~~ i = 1,2,...~ , {\\cal N}_c . \n\\label{saturation_compositional_4}\n\\end{equation}\n\nFor simplification we assume a two phase system (for example water and oil), the mass conservation equation for component $i$ is \n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{o}\\rho_i^{o}S^{o} + y_{i}^{w}\\rho_i^{w}S^{w}  \\right) + \n\\nabla\\cdot\\left(y_{i}^{o}\\rho_i^{o}S^{o}\\mathbf{u}^{o} + y_{i}^{w}\\rho_i^{w}S^{w}\\mathbf{u}^{w}  \\right) - Q_{i} = 0 . \n\\end{eqnarray}\nThis equation can be de-coupled into \ntwo equations (neglecting the component source/sink term $Q_i$) into,\n\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{o}\\rho_i^{o}S^{o} \\right) + \n\\nabla\\cdot\\left(y_{i}^{o}\\rho_i^{o}S^{o}\\mathbf{u}^{o}  \\right) - K_i  = 0, \\\\\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{w}\\rho_i^{w}S^{w}  \\right) + \n\\nabla\\cdot\\left( y_{i}^{w}\\rho_i^{w}S^{w}\\mathbf{u}^{w}  \\right) + K_i = 0. \n\\end{eqnarray}\n The term $K_i$ is selected as $K_i=\\alpha_i \\left(y_i^w - E_i y_i^o\\right)$ (for positive $\\alpha_i$), in an attempt to enforce the Equation of State (EoS):\n\\begin{eqnarray}\ny_i^w - E_i y_i^o=0. \n\\label{simple-EoS}\n\\end{eqnarray}\nThe final form of the\nmass conservation equations for each component $i$ is, \n\\begin{eqnarray}\n\\phi  \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{o}\\rho_i^{o}S^{o} \\right) + \n\\nabla\\cdot\\left(y_{i}^{o}\\rho_i^{o}S^{o}\\mathbf{u}^{o}  \\right) - \\alpha_i (y_i^w - E_i y_i^o)  = 0 ,\n\\label{oil-comp-i} \n\\end{eqnarray}\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{w}\\rho_i^{w}S^{w}  \\right) + \n \\nabla\\cdot\\left( y_{i}^{w}\\rho_i^{w}S^{w}\\mathbf{u}^{w}  \\right) + \\alpha_i (y_i^w - E_i y_i^o) = 0 . \n\\label{water-comp-i}\n\\end{eqnarray}\nThese coupled equations are solved for $y_i^o$  and $y_i^w$. \nTo obtain the oil saturation equation, equation \\ref{oil-comp-i} is summed \nover all components $i$: \n\\begin{eqnarray}\n\\sum\\limits_{i=1}^{{\\cal N}_{c}} \\bigg( \n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{o}\\rho_i^{o}S^{o} \\right) + \n\\nabla\\cdot\\left(y_{i}^{o}\\rho_i^{o}S^{o}\\mathbf{u}^{o}  \\right) - \\alpha_i (y_i^w - E_i y_i^o)\\bigg)  = 0 , \n\\end{eqnarray}\nresulting in: \n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left( \\rho_i^{o} S^{o} \\right) + \n\\nabla\\cdot\\left(\\rho_i^{o} S^{o}\\mathbf{u}^{o}  \\right) = m^{o} ,\n\\end{eqnarray}\nand for the water phase: \n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left( \\rho_i^{w} S^{w} \\right) + \n\\nabla\\cdot\\left(\\rho_i^{w} S^{w}\\mathbf{u}^{w}  \\right) =m^{w} ,\n\\end{eqnarray}\nwith the equal and opposite mass flow rate between the phases: \n\\begin{eqnarray}\n-m^{w} = m^{o}= \\sum\\limits_{i=1}^{{\\cal N}_{c}}\\alpha_i (y_i^w - E_i y_i^o) , \n\\end{eqnarray}\nthus preserving mass. Notice that both equations \\ref{oil-comp-i} \nand  \\ref{water-comp-i} are well posed independent of \ntheir corresponding saturations because of the \npresence of the inter-phase coupling terms involving $\\alpha$. \n\nThe relaxation coefficient $\\alpha$ might be chosen such that \non the time scale of the time step size $\\Delta t$ the EoS \n$y_i^w - E_i y_i^o=0$ is enforced. \nBased on dimensional arguments this leads to: \n\\begin{eqnarray}\n\\alpha_i= \\beta \\frac{\\phi (\\rho_i^o S^o \n\\frac{1}{E_i} \n+\\rho_i^w S^w )}{\\Delta t} ,\n\\end{eqnarray}\nin which $\\beta$ is an order one scalar e.g. $\\beta=1$. \n\n\\subsubsection{Three phase multi-component equations} \n\\label{Three phase system} \nThe above approach provides complete flexibility in the EoS used \nand is easily extended to an arbitrary number of phases. \nFor example three phases: \n\n\\begin{eqnarray}\n\\phi  \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{1}\\rho_i^{1}S^{1} \\right) +\n\\nabla\\cdot\\left(y_{i}^{1}\\rho_i^{1}S^{1}\\mathbf{u}^{1}  \\right) &-& \\alpha_i^{1\\;2} (y_i^2 - E_i^{1\\;2} y_i^1)  = Q_i^1 ,\n\\label{phase1-comp-i}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{2}\\rho_i^{2}S^{2}  \\right) + \n \\nabla\\cdot\\left( y_{i}^{2}\\rho_i^{2}S^{2}\\mathbf{u}^{2}  \\right) + \\alpha_i^{1\\;2} (y_i^2 - E_i^{1\\;2} y_i^1)   - \\alpha_i^{2\\;3} (y_i^3 - E_i^{2\\;3} y_i^2) = Q_i^2 ,\n\\label{phase2-comp-i}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{3}\\rho_i^{3}S^{3}  \\right) + \n \\nabla\\cdot\\left( y_{i}^{3}\\rho_i^{3}S^{3}\\mathbf{u}^{3}  \\right) &+&  \\alpha_i^{2\\;3} (y_i^3 - E_i^{2\\;3} y_i^2) = Q_i^3  ,\n\\label{phase3-comp-i}\n\\end{eqnarray}\nwith \n\\begin{eqnarray}\n \\alpha_i^{j\\;k} = \\beta \\frac{\\phi (\\rho_i^j S^j \n \\frac{1}{E_i^{j\\;k}} \n +\\rho_i^k S^k )}{\\Delta t} , \n\\end{eqnarray}\nand in which $Q_i^j$ is the component $i$ source for phase $j$ \nand the overall component $i$ source is given by $Q_i=\\sum_{j=1}^{{\\cal N}_p} Q_i^j$. \nThe resulting constraint \nis the intersection of the lines $y_i^2 - E_i^{1\\;2} y_i^1=0$ and \n$y_i^3 - E_i^{2\\;3} y_i^2= 0$ on the phase diagram represented as a triangle \nwith $y_i^j, \\; j =1,2,3$ at each of the three corners of the triangle. \nThe three $y_i^j, \\; j =1,2,3$ for a given component $i$ represents a point (in area coordinates) \non this diagram. Notice that the sign alternates on the \nterms involving the $\\alpha^{1\\;2}$ and $\\alpha^{2\\;3}$. \nThe sign is choosen so \nthat the diagonal coupling term between \nthe phases is positive and thus it provides  \na relaxation of $y_i^j$ to satisfy the EoS. This is \nakin to non-equilibrium theormodynamics which are therefore easily \napplied using this approach. \nEliminating the terms involving $\\alpha^{1\\;2}$ \nand $ \\alpha^{2\\;3} $ (in equations \\ref{phase1-comp-i}, \\ref{phase2-comp-i}, \\ref{phase3-comp-i}) results in the conservation equation \nwhich is typically applied in equilibrium satisfying composition models: \n\\begin{eqnarray}\n\\sum_{j=1}^{{\\cal N}_p}  \\left( \n\\phi  \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{j}\\rho_i^{j}S^{j} \\right) + \n\\nabla\\cdot\\left(y_{i}^{j}\\rho_i^{j}S^{j}\\mathbf{u}^{j}  \\right)  \\right) = Q_i, \n\\end{eqnarray}\nbut is also satisfied by non-equilibium models such as described here. \n\nThe application of the EoS's may not necessary result in a unique \napproach. For example, a third EoS may be generated by \ncombining $y_i^2 - E_i^{1\\;2} y_i^1=0$ and \n$y_i^3 - E_i^{2\\;3} y_i^2= 0$ to form $y_i^3 - E_i^{2\\;3} E_i^{1\\;2} y_i^1= 0$ \nor $y_i^3 - E_i^{1\\;3}y_i^1= 0$ which links the first and third phases \ndirectly and thus may be prefered. In this case the component $i$ equations become: \n\n\\begin{eqnarray}\n\\phi  \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{1}\\rho_i^{1}S^{1} \\right) +\n\\nabla\\cdot\\left(y_{i}^{1}\\rho_i^{1}S^{1}\\mathbf{u}^{1}  \\right) - \\alpha_i^{1\\;2} (y_i^2 - E_i^{1\\;2} y_i^1) \n- \\alpha_i^{1\\;3} (y_i^3 - E_i^{1\\;3} y_i^1) = Q_i^1 ,\n\\label{phase1-comp-i'}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{2}\\rho_i^{2}S^{2}  \\right) + \n \\nabla\\cdot\\left( y_{i}^{2}\\rho_i^{2}S^{2}\\mathbf{u}^{2}  \\right) + \\alpha_i^{1\\;2} (y_i^2 - E_i^{1\\;2} y_i^1)   - \\alpha_i^{2\\;3} (y_i^3 - E_i^{2\\;3} y_i^2) = Q_i^2 ,\n\\label{phase2-comp-i'}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\phi \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{3}\\rho_i^{3}S^{3}  \\right) + \n \\nabla\\cdot\\left( y_{i}^{3}\\rho_i^{3}S^{3}\\mathbf{u}^{3}  \\right) +  \\alpha_i^{2\\;3} (y_i^3 - E_i^{2\\;3} y_i^2) \n + \\alpha_i^{1\\;3} (y_i^3 - E_i^{1\\;3} y_i^1)= Q_i^3  . \n\\label{phase3-comp-i'}\n\\end{eqnarray}\n\n\n\n\\subsubsection{Component source partitioning between the phases} \n\\label{Component phase source partitioning} \nOne way to choose \nthe component $i$ source for phase $j$ ($Q_i^j$) is simply \nto place all the component $i$ source $Q_i$ into phase one, \nthat is $Q_i^1=Q_i$ and  $Q_i^k=0, \\; k=2,...,{\\cal N}_p$, \nbearing in mind that mass balance \nleads to  $Q_i=\\sum_{j=1}^{{\\cal N}_p} Q_i^j$. \nHowever, one is reliant on the terms involving \n$\\alpha_i^{j\\;k}$ in order to re-distribute the \nsource between the phases so that the equilibrium conditions \n$y_i^j=E_i^{j\\;k} y_i^k$ are satisfied. \nAn alternative is to distribute the source in such a way that \nit is consistent with the equilibrium conditions which leads to:\n\n\\begin{eqnarray}\nQ_i^1= \\frac{\\rho_i^1 S^1 Q_i}\n{\\rho_i^1 S^1 +\\sum_{k=1}^{{\\cal N}_p} \\rho_i^k S^k E_i^{1\\; k} }, \n\\label{Qi1}\n\\end{eqnarray}\n\\begin{eqnarray}\nQ_i^j= \\frac{\\rho_i^j S^j E_i^{1\\; j} Q_i}\n{\\rho_i^1 S^1 +\\sum_{k=1}^{{\\cal N}_p} \\rho_i^k S^k E_i^{1\\; k} }, \\;\\; j=2,3,..., {{\\cal N}_p}. \n\\label{Qi2}\n\\end{eqnarray}\n\n\n\\subsection{The multi-component solution method}\nHere we comment on the main issues that need to be \nconsidered when developing \na multi-component solution method based on \nthe equations above. \n\\subsubsection{Structure of the $y_i^j$ equations:} Notice that there \nare no explicit \ncoupling terms between the different components within the equations \nfor $y_i^j$ (e.g. equations \\ref{phase1-comp-i}, \\ref{phase2-comp-i}, \\ref{phase3-comp-i}). \nThis means that for each component $i$ a coupled system of ${\\cal N}_p$ (= number of phases) equations need to be solved. \n\\subsubsection{Solving the discretised linear equations:} When the \nequations for $y_i^j$ are discretised (in space and time) the \nresult is a system of linear  equations that need to be solved at each time level where a block structure strongly coupling the phases due to the presence of terms involving $\\alpha^{j\\;k}$ that enforce the EoS's. \nThe larger the values of $\\alpha^{j\\;k}$ the \nstronger this coupling. The strength of this coupling is easily \nhandled in the matrix equation solver used to solve the linear system of equations, by simply using a block type iterative matrix solver e.g. GMRES with BFBGS preconditioning. \nIf explicit methods are to be used then it is suggested \nthat all but the inter-phase coupling terms are treated explicitly. \n\n\n\\subsubsection{Counting the number equations and unknowns $y_i^j$:} \nIt is easy to see that the number of equations equals the number of unknowns, for example in the 2-component problem where we had two equations \\ref{oil-comp-i}, \\ref{water-comp-i} for each component $i$ and two unknowns $y_1^j$, $y_2^j$ for a given phase $j$. \nThese two equations could equally be seen \nas the EoS, equation \\ref{simple-EoS}, and the phase summed component $i$ \nequation. \n\\ref{saturation_compositional_4}. \nSimilarly for the three phase system above in section \\ref{Three phase system}, \nwe had the \nphase summed equation for component $i$ plus two equations \nof state for each phase $j$. The equation counts for the saturation, pressure \nand velocity equations are the same as for a non-multi-component system. \n\n\n\\subsubsection{Well posed equations for $y_i^j$ at zero saturations $S^j$:} \nDue to the presence of the terms involving $\\alpha^{jk}$ the systems of \nequations for $y_i^j$ always remain well posed. When the saturations \nbecome zero then the resulting equation set is simply replaced by the \nEoS e.g. $y_i^3 - E_i^{2\\;3} y_i^2 = 0$.\n\n\\subsubsection{Diffusion in the $y_i^j$ equations:} \nThe general form the the $y_i^j$ equations including diffusion is: \n\\begin{eqnarray}\n\\phi  \\displaystyle\\frac{\\partial}{\\partial t}\\left(y_{i}^{j}\\rho_i^{j}S^{j} \\right) + \n\\nabla\\cdot\\left(y_{i}^{j}\\rho_i^{j}S^{j}\\mathbf{u}^{j}  \\right) \n+ \\nabla \\cdot \\rho_i^{j}S^{j} \\tau^j \\nabla y_i^j \n+ \\sum_{k=1}^{{\\cal N}_p} a_i^{j\\;k} y_i^k   = Q_i^j. \n\\label{diff-phasej-comp-i}\n\\end{eqnarray}\nSumming this equation over all components $i$ and using $\\sum_i y_i^j=1$ one \ncan see that the diffusion term disappears from the \nresulting saturation equation. However, for space and or time \nlimiting the summation may not enable the diffusion terms to \nbe elliminated from the saturation equations \nand thus the diffusion \nflux around each control volume also need to appear in the \nsaturation equation - see next section. \n\n\\subsubsection{Discretisation consistency and flux limiting:} \n\nTesting equation \\ref{diff-phasej-comp-i} with a top hat basis \nfunction $M_m$ and applying integration by parts over each control volume $m$,  \nresults in (ignoring diffusion and source terms for the time being, using backward Euler on the inter-phase coupling terms and using $\\theta$-time stepping for the advection terms):\n \n\n\\begin{eqnarray}\n\\int_{V_m} M_m \\phi_m \\left( \\frac{ {y_{i}^{j}}_m^{n+1}\n\\tilde{\\rho_i^{j}}_m^{n+1} \\tilde{S^{j}}_m^{n+1}  -\n{y_{i}^{j}}_m^n {\\rho_i^{j}}_m^n {S^{j}}_m^n   } \n{\\Delta t} \\right) dV \\\\\n+\n\\int_{\\Gamma_{V_m}} \\left( {\\theta_i^j}^{n+\\frac{1}{2}}  \\hat{y_{i}^{j}}^{n+1} \n\\hat{\\rho_i^{j}}^{n+1} \\hat{S^{j}}^{n+1} \\mathbf{n}\\cdot{\\mathbf{u}^{j}}^{n+1}\n+(1-{\\theta_i^j}^{n+\\frac{1}{2}}) \\hat{y_{i}^{j}}^n  \n\\hat{\\rho_i^{j}}^n \\hat{S^{j}}^n \\mathbf{n}\\cdot{\\mathbf{u}^{j}}^n \\right)  d\\Gamma \\\\\n+ \\int_{\\Gamma_{V_m}}  \\mathbf{n}\\cdot{\\mathbf{g}_i^{j}}^{n+\\frac{1}{2}}d\\Gamma\n+ \\int_{V_m} M_m \\sum_{k=1}^{{\\cal N}_p} {a_i^{j\\;k}}_m \\; \n(\\tilde\\theta_a {y_i^k}_m^{n+1} +(1-\\tilde\\theta_a) \\tilde{y_i^k}_m^{n+1}) dV  = 0. \n\\label{disc-phasej-comp-i}\n\\end{eqnarray}\nThe hat represents flux limited values of the indicated solution variables at  the quadrature points on the surface of the control volumes, and the tilde  represents the latest value of the associated variable within the iteration  process, so on the first iteration this might be from the previous time step. The flux \n$\\mathbf{n}\\cdot{\\mathbf{g}_i^{j}}^{n+\\frac{1}{2}}$ is the result of \nthe diffusion discretisation. \nIn general, the values of the time flux limiting functions  ${\\theta_i^j}^{n+\\frac{1}{2}}$ are also determined at each quadrature point on  the control volume surfaces using a non-linear iteration as described in the  reservoir simulation manual. Dividing equation \\ref{disc-phasej-comp-i} by ${\\rho_i^{j}}_m^{n+1}$ then summing the result over all components, $i$ results in the equation for saturation: \n\n\n\\begin{eqnarray}\n\\int_{V_m} M_m \\phi_m \\left( \\frac{ \n\\tilde{ S^{j}}_m^{n+1} -\n {S^{j}}_m^n } \n{\\Delta t} \\right) dV \\\\\n+\n\\int_{\\Gamma_{V_m}} \\left( \n%{\\widehat{\\Theta}^j}^{n+\\frac{1}{2}}\n\\widehat{{\\Theta}^j}_m^{n+\\frac{1}{2}}\n \\hat{S^{j}}^{n+1} \\mathbf{n}\\cdot {\\mathbf{u}^{j}}^{n+1}\n+   \n\\widehat{{(1-\\Theta)}^j}_m^{n+\\frac{1}{2}} \n \\hat{S^{j}}^n \\mathbf{n}\\cdot {\\mathbf{u}^{j}}^{n}\n \\right)  d\\Gamma \\\\\n= \\int_{V_m} M_m {m^j_m}^{n+\\frac{1}{2}} dV , \n\\label{disc-phasej-sat-i}\n\\end{eqnarray}\nwhich has also used the summation constraints:  \n\\begin{eqnarray}\n\\sum_{i=1}^{{\\cal N}_c} {y_{i}^{j}}_m^n=\\sum_{i=1}^{{\\cal N}_c} {y_{i}^{j}}_m^{n+1}=1, \n\\label{sum-constraint} \n\\end{eqnarray}\nand the inter-phase mass exchange is:\n\\begin{eqnarray}\n{m^j_m}^{n+\\frac{1}{2}}= -\\sum_{i=1}^{{\\cal N}_c} \n\\frac{1}{ \\tilde{\\rho_{i}^{j}}_m^{n+1}\\int_{V_m}M_m dV}  \n\\int_{\\Gamma_{V_m}}  \\mathbf{n}\\cdot{\\mathbf{g}_i^{j}}^{n+\\frac{1}{2}}d\\Gamma\n-\\sum_{i=1}^{{\\cal N}_c} \\sum_{k=1}^{{\\cal N}_p}{a_i^{j\\;k}}_m \\; \n\\frac{ {y_i^k}_m^{n+1} }{  \\tilde{\\rho_{i}^{j}}_m^{n+1}  } \n\\\\\n-w_c \\phi_m\\frac{\\tilde{ S^j}_m^{n+1}}{\\Delta t} ( \n1- \\sum_{i=1}^{{\\cal N}_c} { y_{i}^{j}}_m^{n+1}   ) \n+ {h^j_m}^{n+\\frac{1}{2}}\n, \n\\label{disc-mass-exchange}\n\\end{eqnarray}\nin which the term involving $w_c\\in [0, 1 ]$ helps enforce the constraint \n$\\sum_{i=1}^{{\\cal N}_c} {y_{i}^{j}}_m^{n+1}=1$ and $w_c=1$ is the full correction \nand $w_c=0$ is no correction - generally $w_c=\\frac{1}{2}$ is used. The full correction \n$w_c=1$ can be unstable. One can see that the term involving $w_c$ applies the summation\nconstraint $\\sum_i {y_i^k}_m^{n+1}=1$ as $w_c=1$ effectively replaces the summation \nof the time implicit term on \nthe right hand side of equation \\ref{disc-phasej-comp-i}, that is:\n\\begin{eqnarray}\n\\phi_m  \\frac{ {y_{i}^{j}}_m^{n+1}\n\\tilde{\\rho_i^{j}}_m^{n+1} \\tilde{S^{j}}_m^{n+1}  } \n{\\Delta t} ,\n\\end{eqnarray}\nwith\n\\begin{eqnarray}\n\\phi_m \\frac{{ S^j}_m^{n+1}}{\\Delta t}. \n\\end{eqnarray}\nThat is applying the summation constraint, $\\sum_i {y_i^k}_m^{n+1}=1$. \nWe have found that ensuring positivity of the effective absorption \nin the saturation equation associated with the term involving $w_c$ can enhance \nstability, that is we replace this term with: \n\\begin{eqnarray}\n-w_c \\phi_m\\frac{\\tilde{ S^j}_m^{n+1}}{\\Delta t}  \\max{ \\{\n1- \\sum_{i=1}^{{\\cal N}_c} { y_{i}^{j}}_m^{n+1} , 0\\} }  . \n\\end{eqnarray} \nAlso\n\\begin{eqnarray}\n\\phi_m \\sum_{i=1}^{{\\cal N}_c} \\left(\n\\frac{ {y_{i}^{j}}_m^{n+1} {\\rho_{i}^{j}}_m^{n+1} { S^j}_m^{n+1}\n- {y_{i}^{j}}_m^{n} {\\rho_{i}^{j}}_m^{n} { S^j}_m^{n}\n}\n{\\tilde{\\rho_{i}^{j}}_m^{n+1} \\Delta t} \n\\right)\n= -{h^j_m}^{n+\\frac{1}{2}} + \\phi_m \\frac{{ S^j}_m^{n+1}-{ S^j}_m^{n}}{\\Delta t} , \n\\end{eqnarray}\nand thus using $\\sum_i {y_{i}^{j}}_m^{n+1}=1$: \n\\begin{eqnarray}\n{h^j_m}^{n+\\frac{1}{2}} =\n\\phi_m { S^j}_m^{n+1} \\sum_{i=1}^{{\\cal N}_c} \\left(\n\\frac{ {y_{i}^{j}}_m^{n+1} \\tilde{\\rho_{i}^{j}}_m^{n+1} \n- {y_{i}^{j}}_m^{n+1} {\\rho_{i}^{j}}_m^{n+1} \n}\n{\\tilde{\\rho_{i}^{j}}_m^{n+1} \\Delta t}\n\\right)\n- \n\\phi_m { S^j}_m^{n} \\sum_{i=1}^{{\\cal N}_c} \\left(\n\\frac{ {y_{i}^{j}}_m^{n} \\tilde{\\rho_{i}^{j}}_m^{n+1} \n- {y_{i}^{j}}_m^{n} {\\rho_{i}^{j}}_m^{n} \n}\n{\\tilde{\\rho_{i}^{j}}_m^{n+1} \\Delta t}\n\\right). \n\\end{eqnarray}\nNow using ${\\rho_{i}^{j}}_m^{n+1}=\\tilde{\\rho_{i}^{j}}_m^{n+1} + {b_i^j}_m (p^{n+1}-\\tilde{p})$ \nwith ${b_i^j}_m =\\frac{\\partial{\\rho_{i}^{j}}_m (\\tilde{p}) }{\\partial p} $ and \n\\begin{eqnarray}\nB^j_m=\\sum_{i=1}^{{\\cal N}_c} \\left(\n\\frac{ \n{y_{i}^{j}}_m^{n+1} {b_i^j}_m   }\n{\\tilde{\\rho_{i}^{j}}_m^{n+1}}\n\\right), \n\\end{eqnarray}\nthen\n\\begin{eqnarray}\n{h^j_m}^{n+\\frac{1}{2}} =\n-\\phi_m { S^j}_m^{n+1} \\frac{ B^j_m (p^{n+1}-\\tilde{p})}{\\Delta t} \n- \n\\phi_m { S^j}_m^{n} \\sum_{i=1}^{{\\cal N}_c} \\left(\n\\frac{ {y_{i}^{j}}_m^{n} (\\tilde{\\rho_{i}^{j}}_m^{n+1} \n-  {\\rho_{i}^{j}}_m^{n} )\n}\n{\\tilde{\\rho_{i}^{j}}_m^{n+1} \\Delta t}\n\\right).\n\\end{eqnarray}\nIn the above equations \\ref{disc-phasej-sat-i} the space/time flux limiting functions are: \n\n\n\n\n\n\\begin{eqnarray}\n\\widehat{{\\Theta}^j}_m^{n+\\frac{1}{2}}\n=\\sum_{i=1}^{{\\cal N}_c} {\\theta_i^j}^{n+\\frac{1}{2}}\\hat{y_{i}^{j}}^{n+1}\n\\frac{\\hat{\\rho_i^{j}}^{n+1}}{ \\tilde{\\rho_i^{j}}^{n+1}_m} , \n\\label{disc-phasej-X-i}\n\\end{eqnarray}\n\\begin{eqnarray}\n\\widehat{{(1-\\Theta)}^j}_m^{n+\\frac{1}{2}}\n= \\sum_{i=1}^{{\\cal N}_c} (1-{\\theta_i^j}^{n+\\frac{1}{2}}) \n\\hat{y_{i}^{j}}^n \\frac{\\hat{\\rho_i^{j}}^{n}}{\\tilde{\\rho_i^{j}}^{n+1}_m}  . \n\\label{disc-phasej-Y-i}\n\\end{eqnarray}\nAn initial estimate of the iteration within a \ntime step might be \n$\\widehat{{\\Theta}^j}_m^{n+\\frac{1}{2}}=1$ \nand  \n$\\widehat{{(1-\\Theta)}^j}_m^{n+\\frac{1}{2}}=0$. \nThe summations must be realized \nat the discrete level which includes the treatment of the spatial derivatives. \nThus, the simplest way to achieve consistency and therefore bounded \nand conservative solutions is to use upwind differencing. \nHowever, this may not be efficient and when more accurate \nflux limiting methods are used then something like equations \\ref{disc-phasej-X-i}, \\ref{disc-phasej-X-i} may be used as the \nlimiting functions. \nSome ways \nto achieve this consistency are: \n\\par\\noindent\n1) to use the limiting functions, \nequations \\ref{disc-phasej-X-i} and \\ref{disc-phasej-Y-i}; \n\\par\\noindent\n2) to use the same flux limiting \nfunctions in the equations for the $y_i^j$'s as used in \nthe equations for the $S^j$'s - so if  $S^j$ uses upwinding \nthen so does the $y_i^j$'s; \n\\par\\noindent\n3) use a \nspecified value of ${\\theta_i^j}^n$ (e.g. $1$ or $\\frac{1}{2}$) and \nflux limiting methods that have the inbuilt property that ensure \n$\\sum_i \\hat{y_{i}^{j}}^n=1$ at each quadrature point on the control \nvolume boundaries; \n\\par\\noindent\n4) apply no flux limiting on the $y_i^j$'s (a central \ndifference, upwind or other linear scheme will normally \nobay the summation criteria $\\sum_i \\hat{y_{i}^{j}}^n=1$ \non the CV boundaries) and use a specified $\\theta$. \nThis may cause the $y_i^j$'s to \nbecome unbounded then, but the saturations $S^j$ if limited will \nbe bounded. \n\n\n\n\\subsubsection{Satisfying the equations } \nNotice that equation \\ref{disc-phasej-comp-i} is divided through by the \ncompositional density ${\\rho_i^j}_m^{n+1}$ before summing to obtain equation \n\\ref{disc-phasej-sat-i}. This is key otherwise it will not form a \nlinearly independent system of equations. A simple example is \nprovided by single phase, two component incompressible flow. \nThe density equations might be a linear combination of the \ntwo components and thus the conservation of \nmass equation is simply a combination of these two compositional \nequations. However, the incompressability constraint $\\nabla \\cdot {\\bf u}^n=0$ \nmust also be satisfied. This is in fact the result of \nequation \\ref{disc-phasej-sat-i} but it would not be enforced \nif equation \\ref{disc-phasej-comp-i} was not divided through by the \ncompositional density ${\\rho_i^j}_m^{n+1}$ before summing. \n\n\n\n\n\\subsubsection{Satisfying summation constraints $\\sum_i y_i^j=1$, $\\sum_j S^j=1$:} \nThe constraint $\\sum_j S^j=1$ is satisfied in the usual way by \nforming a global continuity equation which is a weighted \nsum of the saturation equations and then applying the $\\sum_j S^j=1$ at \nthe unknown future time level. The application of \nthe summation constraints (equations \\ref{sum-constraint}) \nin forming the saturation equations \\ref{disc-phasej-sat-i} ensure \nthat on convergence, within a time step of the iterative process,  \nthe summation constraints are satisfied \\ref{sum-constraint}. \nThat only way equations \\ref{disc-phasej-comp-i} \nand \\ref{disc-phasej-sat-i} can both be satisfied, is if the \nsummation constraints are applied (equations \\ref{sum-constraint}). \nIf one is unwilling to iterate within a time step then the \nsummation constraints can still be enforced in a similar \nway to the IMPES method. \nThat is IMPES plus explicit compositional $y_i^j$ solution \n(solved for sequencially after the saturation equations are solved) or IMPESEC. \nAnother approach would be to solve the equations as implicitly \nas possible (e.g. using the non-linear $\\theta$-method) and on the \nfinal iteration within a time step, use the latest guess for \nall variables in the terms, other than the time \nterms (last iteration is explicit). This ensures that \nall the summations constraints are exactly enforced and \none can achieve second order or higher accuracy in time. \nA draw back of this approach (also shared with IMPESEC) is \nthat for near zero or zero \nsaturations one may need a small amount of \nimplicitness in order to ensure well posedness of the \nsystem of equations for $y_i^j$. This may be realised using  \n$\\tilde\\theta_a=1\\times 10^{-4}$, say, \nin equation \\ref{disc-phasej-comp-i}. \n\n\n\n\n\\subsubsection{Implicit treatment of velocity} \nOften, in for example incompressible flows, it is important to treat velocity \nimplicitly in the continuity equation which is formed from the compositional \nequations above. However, if we treat composition explicitly using forward Euler, then \none would treat velocity explicitly also in the compositional, and therefore, the \ncontinuity equations. This is a system that can not be solved for incompressible \nflows because of the infinite compressive wave speed. One way avoid this issue \nby treating velocity in the compositional equations more implicitly. \n\nSo, for example, the surface term may contain:\n\\begin{eqnarray}\n\\theta S^{n+1} u^{n+1} + (1-\\theta) S^n u^n \\label{adv-part} \n\\end{eqnarray}\nNow if we replace $u^n$ with \n\\begin{eqnarray}\n\\tilde u^n = \\theta_v u^{n+1} + (1-\\theta_v) u^n \n\\end{eqnarray}\nand thus equation \\ref{adv-part} becomes\n\\begin{eqnarray}\n(\\theta S^{n+1} +(1-\\theta) S^{n}\\theta_v ) u^{n+1} + ((1-\\theta) S^n (1-\\theta_v)) u^n . \n\\label{adv-part-implicit-vel}\n\\end{eqnarray}\nNow if we want to treat velocity fully implicitly we choose $\\theta_v=1$ and choose \n$\\theta_v=0$ if we dont wish to alter the original discretization. \nA criteria (assuming the saturation does not change in time and we wish to use \nat least a 50$\\%$ of the value of $u^{n+1}$ then \n\\begin{eqnarray}\n\\theta+(1-\\theta)\\theta_v\\ge \\frac{1}{2} \n\\end{eqnarray}\nand thus if $\\theta\\ge\\frac{1}{2}$ then $\\theta_v = \\hat\\theta_v$ otherwise,  \n\\begin{eqnarray}\n\\theta_v =\\max\\{ \\frac{\\frac{1}{2}-\\theta}{1-\\theta}, \\hat\\theta_v \\} , \n\\end{eqnarray}\nin which $\\hat\\theta_v$ is the value we might aim for e.g.  $\\hat\\theta_v=0$ - that is avoid changing the \nvalue of $\\theta$, or time stepping method, whenever possible. \n\n\n\n\\subsubsection{Order of solving the global system of equations:} In order to have access to \nthe future saturation to help form the time derivatives in the $y_i^j$ \nequations \n\\ref{phase1-comp-i}, \\ref{phase2-comp-i}, \\ref{phase3-comp-i} then one must first solve \n(during an iteration within a time level) for the coupled saturation/velocity and \npressure. When the velocity/pressure equations are solved for, then an improved \nvalue of the future density ${\\rho^j_i}^{n+1}$ can be determined and used in \nthe equations to calculate the saturations. Thus, the final step in the iteration \nfor a time step is to determine $y_i^j$. \n\n\n\n\\pagebreak\n\n\n\n\n\\section{Well modelling using extended multi-phase flow equations \nand imbedded one-dimensional pipe models} \n\\label{Well modelling using extended multi-phase flow equations}\nHere we outline an approach for modelling wells based on extending the number of \nfluid phases one solves for. The new phases include each of the phases (e.g. water, oil, gas) \nwithin the wells/pipes. There are five main reasons why this approach is desirable:\n\\par\\noindent\n1) Having more phases can incur little extra CPU overhead. \nThe implementation of the multi-phase flow model is such that the inner most loops \nare over phases with no indirect addressing associated with this. The outer loops \nare over CVs and FEM nodes with indirect addressing associated with the unstructured meshes \nwhich is the CPU intensive part of the \ncomputation.  \n\\par\\noindent \n2) One can use the discretization infrastructure of the fluids model so that we can solve the \nmulti-phase \nNavier Stokes or Darcy's equations within the wells and given very substantial numerical \nresolution one could resolve the 3D multi-phase equations within the wells/pipes. \n\\par\\noindent\n3) One can use the adaptivity and parallel methods without the re-coding necessary \nto use this technology with embedded one dimensional pipe/well models. \n\\par\\noindent\n4) The well and reservoir equations are solved in a fully coupled fashion. \n\\par\\noindent\n5) With the use of mesh adaptivity one can start to resolve the flows locally, around the \nwells, that are important or important parts of these wells.   \n\\par\\noindent\n6) One can replace the multi-phase flow equations with one dimensional imbeded pipe models that \nfollow the edges of elements and have variables collocated at the FEM nodes without \neffecting the solvers or rest of the formulation. \n\nThe main disadvantage of this approach is that one needs to solve for two or more \ncoupled pressure fields as opposed to one in the conventional approach. \nHowever, again the indirect addressing can be associated with CVs and not \nextra fields within the linear solvers if they are chosen carefully.   \n\nThere can be a need to have multiple well phase sets (a phase set may comprise oil, water and gas say) \nin order to keep the \npipes going through the reservoir distinct when there is inadequate spatial resolution \nbetween the wells to do that. So one does not normally have a different phase set for each well and to minimize the \nnumber of phase sets pipe colouring methods can be used. The pipes may be assumed connected (in the graph colouring algorithm) if they share the same fluid finite element. \n\n\n\\subsection{Continuity equations for well modelling} \n\\label{Continuity equation for well modelling} \nUsing the general formulation for multi-wells (${\\cal N}_{well}$ is the number of wells, plus the reservoir, \nthat are represented as different phases), multi-phase's (${\\cal N}_{phase}$ is the number of phases within each well or reservoir phase set) the mass conservation equation of each well or reservoir $j$ and for phase $i$ is: \n\\begin{equation} \n\\phi^j \\displaystyle\\frac{\\partial}{\\partial t}\\left( \\rho_{i}^{j}S_i^{j}\\right) + \\nabla\\cdot\\left(\\rho_{i}^{j}S_i^{j}\\mathbf{u}_i^{j}\\right) - Q_{i}^j = 0,\n~~~~~ \\forall i \\in\\{ 1,2,...~ , {\\cal N}_{phase}\\}, \\;\\;\\; \n\\forall j \\in\\{ 1,2,...~ , {\\cal N}_{well} \\}, \n\\label{saturation_wells_1}\n\\end{equation}\nin which $\\phi^j$ is the porocity of well or reservoir $j$. \nNow discretizing in time: \n\\begin{equation}\n\\phi^j \\displaystyle \\left( \\frac{  \n {\\rho_{i}^{j}}^{n+1} {S_i^{j}}^{n+1} - {\\rho_{i}^{j}}^n {S_i^{j}}^n\n}{\\Delta t} \\right) + \\nabla\\cdot\\left(\\rho_{i}^{j}S_i^{j}\\mathbf{u}_i^{j}\\right) - Q_{i}^j = 0, \n~~~~~ \\forall i \\in\\{ 1,2,...~ , {\\cal N}_{phase}\\}, \\;\\;\\; \n\\forall j \\in\\{ 1,2,...~ , {\\cal N}_{well} \\}. \n\\label{saturation_wells_2}\n\\end{equation}\nDividing through by the density  $\\tilde{\\rho_{i}^{j}}^{n+1}$ and summing to get the global continuity for each well \nfor the reservoir: \n\\begin{equation}\n\\sum\\limits_{i=1}^{{\\cal N}_{phase}} \n\\phi^j \n\\left(  \\frac{  \n \\frac{   {\\rho_{i}^{j}}^{n+1} }\n{  \\tilde{\\rho_{i}^{j}}^{n+1}  }\n{S_i^{j}}^{n+1} \n-  \n\\frac{ {\\rho_{i}^{j}}^{n} }\n{  \\tilde{\\rho_{i}^{j}}^{n+1}  }\n{S_i^{j}}^n\n}\n{\\Delta t}\n\\right) \n+ \n\\sum\\limits_{i=1}^{{\\cal N}_{phase}}\n\\frac{1}{  \\tilde{\\rho_{i}^{j}}^{n+1}   }\n\\nabla\\cdot\\rho_{i}^{j}S_i^{j}\\mathbf{u}_i^{j} \n- \\hat Q^j = 0, \n~~~~~ \\forall j \\in\\{ 1,2,...~ , {\\cal N}_{well}\\}, \n\\label{saturation_wells_3}\n\\end{equation}\nwith \n\\begin{equation}\n\\hat Q^j= \\sum\\limits_{i=1}^{{\\cal N}_{phase}} \\frac{Q_i^j}{\\tilde{\\rho_{i}^{j}}^{n+1}}. \n\\label{saturation_wells_3b}\n\\end{equation}\nApplying the summation constraint \n\n\\begin{equation}\n\\sum\\limits_{i=1}^{{\\cal N}_{phase}} \n{S_i^{j}}^{n+1}\n= 1\n\\label{saturation_wells_3c}\n\\end{equation}  \nequation \n\\ref{saturation_wells_3} becomes: \n\n\\begin{equation}\n\\phi^j\n\\left(  \\frac{  \n1\n-  \n\\sum\\limits_{i=1}^{{\\cal N}_{phase}} \n\\frac{ {\\rho_{i}^{j}}^{n} }\n{  \\tilde{\\rho_{i}^{j}}^{n+1}  }\n{S_i^{j}}^n\n}\n{\\Delta t}\n\\right) \n+ \n\\sum\\limits_{i=1}^{{\\cal N}_{phase}}\n\\frac{1}{  \\tilde{\\rho_{i}^{j}}^{n+1}   }\n\\nabla\\cdot\\rho_{i}^{j}S_i^{j}\\mathbf{u}_i^{j} \n-\\hat Q^j = 0, \n~~~~~ \\forall j \\in\\{ 1,2,...~ , {\\cal N}_{well}\\}, \n\\label{saturation_wells_4}\n\\end{equation}\nin which $Q^j$ exchanges mass between the \nwells and the reservoir allowing a perforated well,  \nfor example, to be modelled and will take on the general form:\n\\begin{equation}\n\\hat Q^j = - \\sum_{k=1, k\\neq j}^{{\\cal N}_{well}} \n\\hat\\gamma^{j \\, k} (p^j - p^k)\n+\\sum_{k=1}^{{\\cal N}_{well}} \n\\hat q^{j \\, k}\n\\label{saturation_wells_5}\n\\end{equation}\nor equivalently, \n\\begin{equation}\n\\hat Q^j = - \\sum_{k=1}^{{\\cal N}_{well}} \n\\hat a^{j \\, k} p^k\n+\\sum_{k=1}^{{\\cal N}_{well}} \n\\hat q^{j \\, k}\n\\label{saturation_wells_5-a}\n\\end{equation}\nin which $p^j$ is the pressure of well or reservoir $j$ and \nsuperscript $k$ refers to the other wells or the reservoir. \nThus, the reservoir and the wells have different pressures within \ntheir phases, $p^k, \\forall k\\in\\{1,2,...,{\\cal N}_{well}\\}$. It is worth noting that the \n'$1$' needs to be retained in equation \\ref{saturation_wells_4} during the computation to \nensure satisfaction of equation \\ref{saturation_wells_3c}. \n$\\gamma^{j\\,k}$ is made up of phase contributions\n\n\\begin{equation}\n\\hat\\gamma^{j\\,k}=\\sum_{i=1}^{ {\\cal N}_{phase} }  \\frac{ \\gamma^{j\\,k}_i }{ \\tilde{\\rho_i^j}^{n+1} },\n\\label{saturation_wells_6}\n\\end{equation}\nand\n\\begin{equation}\n\\hat a^{j\\,k}=\\sum_{i=1}^{ {\\cal N}_{phase} }  \\frac{ a^{j\\,k}_i }{ \\tilde{\\rho_i^j}^{n+1} },\n\\label{saturation_wells_6-a}\n\\end{equation}\nand\n\\begin{equation}\n\\hat q^{j\\,k}=\\sum_{i=1}^{ {\\cal N}_{phase} }  \\frac{ q^{j\\,k}_i }{ \\tilde{\\rho_i^j}^{n+1} },\n\\label{saturation_wells_6b}\n\\end{equation}\nand\n\\begin{equation}\nQ_i^{j} = \n-\\sum_{k=1, k\\neq j}^{{\\cal N}_{well}}\\gamma^{j\\,k}_i  (p^j - p^k)   \n+ \\sum_{k=1}^{{\\cal N}_{well}} q^{j\\,k}_i, \n\\label{saturation_wells_7}\n\\end{equation}\nor \n\\begin{equation}\nQ_i^{j} = \n-\\sum_{k=1}^{{\\cal N}_{well}} a^{j\\,k}_i  p^k \n+ \\sum_{k=1}^{{\\cal N}_{well}} q^{j\\,k}_i, \n\\label{saturation_wells_7-a}\n\\end{equation}\nand \n\\begin{equation}\na^{j\\,j}_i= \\sum_{k=1}^{ {\\cal N}_{well} }  \\gamma^{j\\,k}_i , \\;\\;\\;\\;\na^{j\\,k}_i=  -  \\gamma^{j\\,k}_i \\;\\; \\forall k\\neq j , \n\\label{saturation_wells_8-a}\n\\end{equation}\nin which $\\gamma^{j\\,k}_i=\\gamma^{k\\,j}_i$ and $q^{j\\,k}_i$ are from source terms, like gravity, in the \nforce balance equations. For simplicity here we will assume $q^{j\\,k}_i=0$ unless otherwise stated. \nFrom conservation of mass $\\sum_i\\sum_j Q^j_i=0$ but here the mass exchanges are between the wells and \nthe reservoir and thus $\\sum_j Q^j_i=0, \\forall i \\in\\{ 1,2,...~ , {\\cal N}_{phase}\\}$. \n\n\n\\subsection{Mass flow rate between the reservoir and the wells} \n\\label{Mass flow rate between the reservoir and the wells} \nIn order to determine $\\gamma^{j\\,k}_i$ we will first determine the \nvelocity through the porous pipe wall based on Darcy's equation using:\n\\begin{equation}\n{\\sigma_{wall}}_i v_i = \\frac{ p_{well} - p_{reservoir} }{{\\Delta x}_{wall}} +\\alpha_g g \\rho_i^{wall}\n\\label{saturation_wells_8}\n\\end{equation}\nin which $v_i$ is the velocity of phase $i$ through the pipe wall of thickness ${\\Delta x}_{wall}$ and normal to the pipe, \n$g$ is gravity, $\\alpha_g$ is the component of gravity (for a vertical pipe $\\alpha_g=0$),  \n${\\sigma_{wall}}_i$ is related to the permeability of the well wall for phase $i$ \nand \n$p_{well}$,  $p_{reservoir}$ are the pipe and reservoir pressures. \nThe flux of phase through the wall (assuming thin walls - relative to the well diameter) \nfor $p_{well}>p_{reservoir}$ for phase $i$: \n\n\\begin{equation}\nA_{pipe-wall} \\rho_i^{well} S_i^{well} v_i = \\frac{A_{pipe-wall} \\rho_i^{well} S_i^{well} }{{\\sigma_{wall}}_i} \n\\left( \\frac{ p_{well} - p_{reservoir} }{{\\Delta x}_{wall}}  +\\alpha_g g \\rho_i^{wall}  \\right)\n\\end{equation}\n\\begin{equation}\n=\\gamma_i^{well\\, reservoir} (p_{well} - p_{reservoir}) + q_i^{well\\, reservoir}\n\\label{saturation_wells_9}\n\\end{equation}\nand for $p_{well}\\leq p_{reservoir}$ for phase $i$: \n\\begin{equation}\nA_{pipe-wall}  \\rho_i^{reservoir} S_i^{reservoir} v_i = \\frac{A_{pipe-wall}  \\rho_i^{reservoir} S_i^{reservoir} }{{\\sigma_{wall}}_i} \\left(\\frac{ p_{well} - p_{reservoir} }{{\\Delta x}_{wall}} +\\alpha_g g \\rho_i^{wall}\\right)\n\\end{equation}\n\\begin{equation}\n=\\gamma_i^{well\\, reservoir} (p_{well} - p_{reserviour}) + q_i^{well\\, reservoir}. \n\\label{saturation_wells_10}\n\\end{equation}\nThus, if $p_{well}>p_{reservoir}$ then for phase $i$ the value of $\\gamma_i^{well\\, reservoir}$ is: \n\\begin{equation}\n\\gamma_{up_i}^{well\\, reservoir}=\\frac{A_{pipe-wall}  \\rho_i^{well} S_i^{well} }{{{\\Delta x}_{wall}\\sigma_{wall}}_i} \n\\;\\;\\;\n\\end{equation}\n\\begin{equation}\n\\text{and} \n\\;\\;\\;\nq_{i}^{well\\, reservoir}=\\frac{A_{pipe-wall}  \\rho_i^{well} S_i^{well} \\alpha_g g \\rho_i^{wall}    }\n{{\\sigma_{wall}}_i} ,\n\\label{saturation_wells_11}\n\\end{equation}\nand for $p_{well}\\leq p_{reservoir}$ for phase $i$ the value of $\\gamma_i^{well\\, reservoir}$ is:\n\\begin{equation}\n\\gamma_{up_i}^{well\\, reservoir}=\\frac{A_{pipe-wall}  \\rho_i^{reservoir} S_i^{reservoir}   }\n{{\\Delta x}_{wall}{\\sigma_{wall}}_i} \n\\;\\;\\;\n\\label{saturation_wells_12-gamma}\n\\end{equation}\n\\begin{equation}\n\\text{and} \n\\;\\;\\;\nq_{i}^{well\\, reservoir}=\\frac{A_{pipe-wall}  \\rho_i^{reservoir} S_i^{reservoir} \\alpha_g g \\rho_i^{wall}}\n{{\\sigma_{wall}}_i} ,\n\\label{saturation_wells_12}\n\\end{equation}\nin which $A_{pipe-wall}$ is the surface area density of the surface of the well or pipe - cross section area of pipe per unity volume which has dimensions of $m^{-1}$. Thus, for CV $l$ the $A_{pipe-wall}$ is:\n\\begin{equation}\n{A_{pipe-wall}}_l =  \\frac{  {\\Gamma_{pipe-wall}}_l  }{ {\\cal V}_l }\n\\label{saturation_wells_12b}\n\\end{equation}\nin which ${\\Gamma_{pipe-wall}}_l$ is the outer surface area of the well/pipe inside CV $l$ \nand the volume of CV $l$ is ${\\cal V}_l$. \nFor stability (avoiding moving mass to or from phases with near zero porocity) it is useful to use $\\widehat{A_{pipe-wall}}_l$ rather than ${A_{pipe-wall}}_l$ in which \n\\begin{equation}\n{A_{pipe-wall}}_l =  \\phi^{well}_l \\phi^{reservoir}_l \\widehat{ A_{pipe-wall}}_l. \n\\label{saturation_wells_12b-hat}\n\\end{equation}\nAlternatively combining equations \\ref{saturation_wells_11} and \\ref{saturation_wells_12} \none can obtain a high order accurate method analogous to central difference discretisation \nof advection, the value of $\\gamma_i^{well\\, reservoir}$ is:\n\n\\begin{equation}\n\\gamma_{cent_i}^{well\\, reservoir}=\n\\frac{\\frac{1}{2} A_{pipe-wall}  (\\rho_i^{well}  S_i^{well} + \\rho_i^{reservoir}  S_i^{reservoir}) }{{{\\Delta x}_{wall}\\sigma_{wall}}_i}, \n\\label{saturation_wells_14}\n\\end{equation}\nor one may take an average of the two expressions for $\\gamma_i^{well\\, reservoir}$ given by equations \n\\ref{saturation_wells_11}, \\ref{saturation_wells_12} and \n\\ref{saturation_wells_14}. For example:\n\\begin{equation}\n{\\gamma_{}}_i^{well\\, reservoir}=\nw_{well}{\\gamma_{up_i}^{well\\, reservoir}}+ \n(1-w_{well}){\\gamma_{cent_i}^{well\\, reservoir}} , \n\\label{saturation_wells_14b}\n\\end{equation}\nand similarly for ${q_{}}_i^{well\\, reservoir}$ and \nin which $w_{well}\\in\\left[0,1\\right]$ controls the averaging e.g. $w_{well}=\\frac{1}{2}$. \nThe recommended upwind scheme is given by $w_{well}=1$. \n$Q^j$ for a problem with one well, $j=well$, and one reservoir  $k=reservoir$ then \n\\begin{equation}\nQ^{well}=\\gamma^{well\\, reservoir} (p^{well}-p^{reservoir}) + q^{well\\, reservoir}. \n\\label{saturation_wells_14bb}\n\\end{equation}\nIt should be pointed out that the saturation's $S_i^{reservoir}, \\forall i$ and \nreservoir pressure $p^{reservoir}$ may be modified, in the above, \nto include submodel information \nand take into account their local changes around the wells which may be on a scale (10's of cm's) \nnot resolvable on the mesh. \n\n\n\n\n\\subsection{Mass flow rate between wells} \n\\label{Mass flow rate between wells}\nIf two pipes or wells (well 1 and well 2) are connected then we can use an arbitrary large value of \n$\\gamma_i^{well1\\, well2}$ which will instantly equalize the pressures between the two pipes \nwhere they meet and freely exchange mass between them. If however one considers that \ntheir exchange occurs over a distance equal to the size of the CVs ${\\Delta x}_{grid}$ at the intersection then, \nanalogous to equation \\ref{saturation_wells_14}, one obtains: \n\n\\par\\noindent\nif $p_{well1}>p_{well2}$ then for phase $i$ the value of $\\gamma_i^{well1\\, well2}$ is: \n\\begin{equation}\n\\gamma_{i}^{well1\\, well2}=\\frac{A_{well12}  \\rho_i^{well1} S_i^{well1} }{{{\\Delta x}_{grid}\\sigma_{well1}}_i},\n\\label{saturation_wells_11}\n\\end{equation}\nand for $p_{well1}\\leq p_{well2}$ for phase $i$ the value of $\\gamma_i^{well\\, well2}$ is:\n\\begin{equation}\n\\gamma_{i}^{well1\\, well2}=\\frac{A_{well12}  \\rho_i^{well2} S_i^{well2} }{{{\\Delta x}_{grid}\\sigma_{well2}}_i} ,\n\\label{saturation_wells_12}\n\\end{equation}\nin which $A_{well12}$ is the cross-section area density of the pipes at their join and $\\sigma_{well1}$,  $\\sigma_{well2}$ \nare the volumetric drag coefficients for wells 1 and 2.  Thus, for CV $l$ the $A_{well12}$ is:\n\\begin{equation}\n{A_{well12}}_l =  \\frac{  {\\Gamma_{well1-well2}}_l  }{ {\\cal V}_l }\n\\label{saturation_wells_12b}\n\\end{equation}\nin which ${\\Gamma_{well1-well2}}_l$ is the cross sectional at the pipe/well join inside CV $l$ \nand the volume of CV $l$ is ${\\cal V}_l$. Notice that $\\gamma_i^{well1 \\, well2}=0$ when \nneither well is present. \n\nThere are two basic ways of dealing with a situation when there are multiple wells close to one \nanother. One way is to use a well colouring method in which we assign different colours to wells  \nclose to one another in terms of numbers of CVs. The other is to use an anisotropic permeability \nguiding the well flows along the direction of the pipes and minimizing mixing between the \npipes. This is achieved with a low permeability orthogonal to the pipes. \n\n\n\n\\subsection{Open wells} \n\\label{Mass flow rate between wells}\nIf when the well ends the fluid is allowed to flow freely into the reservoir \nthen equations \\ref{saturation_wells_11}, \\ref{saturation_wells_12}  \nmay also be used to help work out the flow rate out of the well but with $reservoir$ replacing $well2$: \n\n\\par\\noindent\nif $p_{well}>p_{reservoir}$ then for phase $i$ the value of $\\gamma_i^{well\\, reservoir}$ is: \n\\begin{equation}\n\\gamma_{i}^{well\\, reservoir}=\\frac{ A_{open}  \\rho_i^{well} S_i^{well} }{{{\\Delta x}_{grid}\\sigma_{well}}_i} ,\n\\label{saturation_wells_11}\n\\end{equation}\nand for $p_{well}\\leq p_{reservoir}$ for phase $i$ the value of $\\gamma_i^{well\\, reservoir}$ is:\n\\begin{equation}\n\\gamma_{i}^{well\\, reservoir}=\\frac{ A_{open}  \\rho_i^{reservoir} S_i^{reservoir} }{{{\\Delta x}_{grid}\\sigma_{reservoir}}_i} ,\n\\label{saturation_wells_15-well10reservoir}\n\\end{equation}\nin which $A_{open}$ is the cross section area density of the open pipe. One can include  \ngravitational forces for each phase in the above calculations which would provide non-zero values \nof $q_i^{j\\,k}$ in equations \\ref{saturation_wells_7}. \nFor open wells at the larger scale a similar adjustment to the   \nPeacman correction is needed, but this time for a point source rather than a linear source. \nHowever, with loss of accuracy, the Peacman correction may still be applied, see below. \n\n\n\n\n\\subsection{Cylindrical geometry and skin effect adjustment} \n\nNow assuming the well is cylindericial and a cyclindrically symmetric analytical solution \nas well as the intorduction of the skin effect coefficient $Skin$ (an adjustment for fracturing of the porious media by the introduction of the well) the result is that the maximum total mass flux can \nbe written as: \n\n\\begin{equation}\nq_{total}^k = \\frac{2 S_i^k \\pi h}{\\tilde\\sigma_i^{k} }\\frac{(p_{reservior}- p_{well})}{ ( log(\\frac{r_p}{r_e}) + Skin)} \n\\label{saturation_wells_11-cyl-skin}\n\\end{equation}\nin which the Peacman correction is:\n\\begin{equation}\nr_p= 0.14 \\Delta x_{norm-well} \n\\end{equation}\nand $h$ is the length of the completion - length over which the well is perforated. Also $\\Delta x_{norm-well}$ \nis  the length scale of the elements normal to the well - for CV-FEM it may be calculated from the determinant of the FEM Jacobian. \nAssuming the length of pipe/well in CV $i$ is ${\\Delta x_{well}}_i$ then ${\\Delta x_{norm-well}}_i$ is \ncalculated from the CV volume $V_i$, that is: \n\\begin{equation}\n {\\Delta x_{norm-well}}_i = \\left(  \n\\frac{V_i}{ {\\Delta x_{well}}_i }\n\\right)^\\frac{1}{2} . \n\\end{equation}\nThe main drawback of this expresssion is that it does not take into account \nthe anisotropy in the permability in the plane normal to the well. However, its simplicity means that it is commonly \nused, see ***. \nComplex expression exist for the skin effect coefficient $Skin$. \nFrom equation \\ref{saturation_wells_11-cyl-skin} then:\n\n\\begin{equation}\n\\gamma_{i}^{well\\, reservoir}\n=\\frac{2 S_i^k \\pi h}{ \\tilde\\sigma_i^k h\\pi r_e^2} \\frac{1}{ ( log(\\frac{r_p}{r_e}) + Skin)}\n=\\frac{2 S_i^k }{\\tilde\\sigma_i^k r_e^2} \\frac{1}{ ( log(\\frac{r_p}{r_e}) + Skin)}\n . \n\\label{saturation_wells_15-well10reservoir-cyl-skin}\n\\end{equation}\nThe scalar $\\tilde\\sigma_i$ reflects the permeability normal to the wells \nand is obtained from forming an orthornal system ${\\bf b}={\\bf t}\\times {\\bf n}$ in which $\\bf n$ is the direction \nalong the wells and $\\bf t$ and $\\bf b$ are orthonormal vectors to $\\bf n$ and themselves; then: \n\\begin{equation}\n\\tilde\\sigma_i^k = \\left( det\\left( ({\\bf b} \\; {\\bf t})^T \\underline{\\underline\\sigma}_i^k ({\\bf b} \\; {\\bf t}) \\right) \\right)^{\\frac{1}{2}}. \n\\label{perm-well-orthogonal}\n\\end{equation}\nIt will also be useful to consider the permability of the reservior along the well: \n\\begin{equation}\n\\hat\\sigma_i^k =  {\\bf n}^T \\underline{\\underline\\sigma}_i^k {\\bf n} . \n\\label{perm-well-orthogonal}\n\\end{equation}\n\n\n\n\n\\subsection{Modelling rather than resolving laterals} \n\\label{Modelling rather than resolving laterals}  \nThe previous section describes a method of one dimensional based modelling of wells and laterals \n(micro-laterals and nano-laterals) which necessitates substantial parameterization \ndue to the lack of resolution near the well within the reserviour. Using the same approach \nwe can model laterals emanating from a well simply by exchanging the mass between \nthe reservoir and laterals at a point or CV of the well. \nThis works well when there is not enough resolution within the reservoir to be able to \nhold the unresolved laterals. \n\nThe approach works by repeating the above and again assuming the well is cylindericial and a cylindrically symmetric analytical solution \nas well as the introduction of the skin effect coefficient $\\widehat{Skin}$ (an adjustment for fracturing of the porous media by the introduction of the well) the result is that the maximum total mass flux can \nbe written as: \n\n\\begin{equation}\n\\hat{q}_{total}^k = \\frac{2 S_i^k \\pi \\hat{h}}{\\hat\\sigma_i^{k} }\\frac{(p_{reservior}- p_{well})}{ ( log(\\frac{\\hat{r}_p}{\\hat{r}_e}) + \\widehat{Skin})} \n\\label{saturation_wells_11-cyl-skin-model-lat}\n\\end{equation}\nin which the Peacman correction is:\n\\begin{equation}\n\\hat{r}_p= 0.14 \\Delta x_{well} \n\\end{equation}\nand $\\hat h$ is the length of the modelled (rather than resolved) completion - length over which the well is perforated and modelled. \nFrom equation \\ref{saturation_wells_11-cyl-skin-model-lat} then:\n\n\\begin{equation}\n\\hat\\gamma_{i}^{well\\, reservoir}\n=\\frac{2 S_i^k \\pi \\hat{h}}{ \\hat\\sigma_i^k h\\pi {r}_e^2} \\frac{1}{ ( log(\\frac{\\hat{r}_p}{\\hat{r}_e}) + \\widehat{Skin})}\n=\\frac{2 S_i^k \\hat{h}}{\\hat\\sigma_{i}^k  h\\pi {r}_e^2} \\frac{1}{ ( log(\\frac{\\hat{r}_p}{\\hat{r}_e}) + \\widehat{Skin})}\n . \n\\label{saturation_wells_15-well10reservoir-cyl-skin-model-lat}\n\\end{equation}\nNotice that the resolved well radius ${r}_e$ that the modelled lateral comes from is used in this expression. \nThis value of $\\hat\\gamma_{i}^{well\\, reservoir}$ is then added to $\\gamma_{i}^{well\\, reservoir}$ \nin equation \\ref{saturation_wells_15-well10reservoir-cyl-skin} to get the overall mass exchange terms with the pipes. \nIt should be pointed out that the modelling of the laterals described here tends to produce less production than the resolved laterals do. The reason is that the pressure difference is increased with the resolved modelling away from the mother pipe that \nthe unresolved laterals come from. This pressure difference is directly related to \nthe production rate hence we get less production. This effect is small if the \nmodelled lateral lengths are of the order of the element size or less which is \nwhat the method above is designed for. If this is not the case then there is \ngood argument to resolve the laterals. \n\n\n\n\n\n\\subsubsection{Simple analytical well models} \n\\label{Simple analytical well models}\nAs well as enabling imbedding of analytical models \nsuch as the above for modelled rather than resolved laterals, \nsimple analytical expressions can help validate forward models and \nprovide insights into the physics involved. \nBy dividing up the pipes into a number of pipe sets, one of the simplest models can be obtained: \n\nVolume production rate = \n\\begin{equation}\n\\sum\\limits_{{pipe}=1}^{{\\cal NPIPE}} \n\\frac{2 S_{pipe}^k \\pi {h}_{pipe} }{\\sigma_{pipe}^k } \\frac{\\Delta p_{pipe}}{ ( log(\\frac{ {r_p}_{pipe} }{ {r_e}_{pipe} }) + {Skin}_{pipe})}\n\\end{equation}\nin which ${r_p}_{pipe} = 0.14 * dx-normal2pipe_{pipe}$ - it is suggested that $dx-normal2pipe_{pipe}$  \nis some length scale across the reservoir and is the cell width normal to the wells in the simulator; \n\\par\\noindent\n${\\cal NPIPE}$ is the number of pipe sets that have rather different properties e.g. different \npressure differences or permeabilities in their local vicinities; \n\\par\\noindent\n${r_e}_{pipe}$ is the pipe or well internal diameter for pipe set $pipe$; \n\\par\\noindent\n$S_{pipe}^k $ is the saturation of phase $k$ near the well or pipe set $pipe$; \n\\par\\noindent\nsimilarly $\\sigma_{pipe}^k$ is a result of the permeability and relative permeability for \nphase $k$  near the well or pipe set $pipe$; \n\\par\\noindent\n ${Skin}_{pipe}$ is the skin effect adjustment for pipe set $pipe$ which takes into account \nthe fracturing of the porous media around this pipe set resulting from the drilling of the pipes \n(${Skin}_{pipe}=0$ is \noften used); \n\\par\\noindent\n$\\Delta p_{pipe}$ is pressure difference between the reservoir and the well/pipe set $pipe$ - this \nas a first approximation can be assumed to be the pressure difference between the know well pressure \nand the known reservoir pressure before extracting oil from the wells. This is where the biggest \napproximation lies as when extracting oil/water/gas the pressure difference will be substantially less \nand making this assumption will result in estimated values \ngreater than those obtained by a detailed reservoir model. However, if one has some experience from \nmore detailed modelling one may be able to estimate $\\Delta p_{pipe}$ which will greatly enhance the accuracy of the \npredictions using the above equation.  \n\nWhen there are a number of smaller in diameter laterals coming from a larger diameter motherbore \nthen generally the mass production rate increase will be greater than suggested by the surface area ratio \nof the motherbore to the motherbore plus the laterals.    This is due to the fact that even fairly thin \nwells/laterals/pipes can be effective at producing. \n\n\n\n\n\n\\subsection{Friction and pressure drop of the flows within wells} \n\\label{Friction and pressure drop of the flows within wells} \n\nWithin the approach outlined here we solve simultaneously (coupled through mass echannge \nterms in the continuity equation) for the pressure in the reservoir and the pressure \nin the wells. There can be substantial differences between the \npipe and reservoir pressures. \nThe pressure drop across the pipes is determined through the pipes friction - assuming \na multi-phase Darcy equation governs the force balance with the pipes. That is: \n\n\\begin{equation}\n\\sigma^k u^k = -\\nabla p_w - \\rho^k g \n\\end{equation}\nin which $\\sigma^k $ determines the frictional losses. \nTo this aim we define the friction factor for phase $k$ as:\n\\begin{equation}\nf^k = (1-w^k) \\frac{16}{Re} + w^k \\left( -3.6 log_{10}\\left(  \\frac{6.9}{Re^k} + \\left(\\frac{e}{3.7D}\\right)^{\\frac{10}{9}} \\right) \\right)^{-\\frac{1}{2}} \n\\end{equation}\nin which \n\\begin{equation}\nw^k= max(0,  min(1,(Re^k-2000)/2000)  ) , \n\\end{equation}\nand $e\\in\\left[1 \\times 10^{-6}, 0.1 \\right] $ m is the absolute roughness of the inside of the pipe  \nand the pipe Reynolds number for phase $k$ is: \n\\begin{equation}\nRe^k= \\frac{ \\rho^k \\vert u^k\\vert 2 r_e }{\\mu} \n\\end{equation}\nwhere $\\rho^k$ and $\\mu^k$ are the density and viscosity of phase $k$. \nThe resulting $\\sigma^k$ is then: \n\n\\begin{equation}\n\\sigma^k \n    = \\frac{f}{2r_e} 2 \\rho^k \\vert u^k \\vert  = \\frac{f}{r_e}  \\rho^k \\vert u^k \\vert. \n\\end{equation}\n\n\n\n\n\n\\subsection{The sum to one constraint within the continuity equations for well modelling} \n\\label{Continuity equation for well modelling} \nThe sum of the saturation constraint\n\\begin{equation}\n\\sum\\limits_{i=1}^{{\\cal N}_{phase}} \n{S_i^{j}}^{n+1}\n= 1, \n\\label{saturation_wells_3c--}\n\\end{equation}\ncan be enforced more strongly through the continuity equation using:\n\\begin{equation}\n\\phi^j \\displaystyle \\left( \\frac{  \n {\\rho_{i}^{j}}^{n+1} {S_i^{j}}^{n+1} - {\\rho_{i}^{j}}^n {S_i^{j}}^n\n}{\\Delta t} \\right) + \\nabla\\cdot\\left(\\rho_{i}^{j}S_i^{j}\\mathbf{u}_i^{j}\\right) + \\sum_{k=1}^{{\\cal N}_{well}} \\nu_{i}^{j\\;k}  {S_i^{k}}^{n+1}= 0, \n\\label{saturation_wells_2--}\n\\end{equation}\n\\begin{equation}\n~~~ \\forall i \\in\\{ 1,2,...~ , {\\cal N}_{phase}\\}, \\;\\;\\; \n\\forall j \\in\\{ 1,2,...~ , {\\cal N}_{well} \\}, \n\\label{saturation_wells_2--all}\n\\end{equation}\nwith:\n\\begin{equation}\n\\nu_{i}^{j\\;k} = \\phi^j \\phi^k \\frac{ \\widehat A_{j\\;k}  \\rho_i^{j}  }{{{\\Delta x}_{grid}\\sigma_{j}}_i}  H(p_{i}^{k}-p_{i}^{j}) (p_{i}^{j}-p_{i}^{k}), \n~~~j\\neq k ;  \n\\label{saturation_wells_H1}\n\\end{equation}\n\\begin{equation}\n\\nu_{i}^{j\\;j} = \\sum_{k=1, k\\neq j}^{{\\cal N}_{well}} \\phi^j \\phi^k \\frac{ \\widehat A_{j\\;k}  \\rho_i^{k}  }{{{\\Delta x}_{grid}\\sigma_{k}}_i} H(p_{i}^{j}-p_{i}^{k}) (p_{i}^{j}-p_{i}^{k}), \n\\label{saturation_wells_H2}\n\\end{equation}\nin which $H(z)=1$ if $z>0$ else $H(z)=0$.  \nNotice that $\\nu_{i}^{j\\;k}\\le 0$ when $j\\neq k$ and $\\nu_{i}^{j\\;j}\\ge 0$.  \nWhen fully discretized in space, equation \\ref{saturation_wells_2--} is relatively easy to solve (even when the quantity \nof fluid exchanged with the wells is large) with a suitable choice of solver e.g. GMRES with a \nBSSOR preconditioner, or some multi-grid methods. \n\nAnalogous to equations \\ref{saturation_wells_3} and \\ref{saturation_wells_4} we normalize equations \n\\ref{saturation_wells_2--},  \nbut because of the strength of the coupling of the well-reserviour terms, we need to \ntreat the coupling of the two pressures implicitly. Equation \\ref{saturation_wells_2--} may be re-written \nas:\n\n\\begin{equation}\\displaystyle\n  \\left( \\frac{  \n \\underline{\\underline{\\rho}}^{n+1}\\underline{\\underline \\phi} {\\underline S}^{n+1} - \\underline{\\underline\\phi} \\; \\underline{\\underline{\\rho}}^{n}   {\\underline S}^n\n}{\\Delta t} \\right) + \\nabla\\cdot\\left( \\underline{\\underline\\rho} \\mathbf{u} {\\underline{S}} \\right) +  K\\underline{\\underline \\phi} \\underline{S}^{n+1}= 0, \n~~~~~ \\forall i \\in\\{ 1,2,...~ , {\\cal N}_{phase}\\},\n\\label{saturation_wells_2--++}\n\\end{equation}\nMultiplying this equation by $B^{-1}$ with\n\\begin{equation}\nB= \\underline{\\underline{\\rho^{}}}^{n+1} +\\Delta t K, \n\\label{saturation_wells_2--++--}\n\\end{equation}\none obtains by \napplying the summation constraint \n\n\\begin{equation}\n\\sum\\limits_{i=1}^{{\\cal N}_{phase}} \n{S_i^{j}}^{n+1}\n= 1,\n\\label{saturation_wells_3c-}\n\\end{equation}  \nor equivalently: \n\\begin{equation}\n J \n\\underline{S}^{n+1}\n= \\underline{b},\n\\label{saturation_wells_3c-b}\n\\end{equation}  \nwith $\\underline{b}$ being the unity vector then \nequation \n\\ref{saturation_wells_2--++} becomes: \n\n\\begin{equation}\n\\left(  \\frac{  \nI \\hat{ \\underline{\\underline \\phi} }\n-  \nJ\nB^{-1} \\underline{\\underline{\\rho^{}}}^{n} \\; \\underline{\\underline \\phi}\n\\underline{S}^n\n}\n{\\Delta t}\n\\right) \n+ \nJ \nB^{-1} \n\\nabla\\cdot \\underline{\\underline\\rho} \\mathbf{u} {\\underline S}\n= 0, \n\\label{saturation_wells_4-----}\n\\end{equation}\nwhich is then manipulated to obtain the pressure equation. \nThe use of the indentity matrix in equation \\ref{saturation_wells_4-----} \nis key to impossing the sum to unity constaint, equation \\ref{saturation_wells_3c-} \nat time level $n+1$.\n\n\n\n\\subsection{Pressure matrix sparcity and formation} \n\\label{Pressure matrix sparcity}\nThe pressure matrix has now has to store information associated with a number of pressures. \nHowever, although the coupling between the pressure variables associated with different phases only occures \ndue to  differences in pressures, and not pressure gradients, due to the fact that the representation of \npressure is FEM (and there therefore exists a distributed mass matrix associated with this coupling) \nthe coupling is full and thus if the number of non-zeros in the pressure matrix \nfor one pressure variables is ${\\cal M}_p$ then the number of non-zeros in the pressure \nmatrix with ${\\cal P}$ pressures is  ${\\cal P}\\times{\\cal P}\\times{\\cal M}_p$. \nIn principle this means that efficient methods can be used for solving with the extra degrees of \nfreedom for pressure, but these are not supported (generally) in the current generation of \nmulti-grid solvers which are needed to solve for pressure. \n\nThe formation of the pressure matrix equation is as described in section \\ref{Projection method of solution} and the matrix ${\\bf B}$ in the continuity equation \\ref{glob-cty-matrix2} (a discretization of equation \\ref{saturation_wells_4}) is formed from the terms involving $\\hat\\gamma^{j\\, k}$ which couple the phases. \n\n\n\n\n\\subsection{Imbedded one-dimensional pipe model} \n\\label{1d-well-dicsretization}\nA key advantage of the formulation above, that is described in differential equation \nform, is that one can use with one dimensional imbedded pipe models that \nfollow the edges of elements and have variables collocated at the FEM nodes without \neffecting the solvers or rest of the formulation. \n\nThis is achieved by using discretizing the equations along the edges of elements along which the \npipes are placed. So for a P1DG-P1 formulation there would be a linear pressure variation \nalong the edges of the elements with corresponding 2 control-volumes with a cylindrical \ncross-section with a diameter equal to the diameter of the pipe along that edge. The velocity \nis then linear discontinuous along that edge and within each volume element. \nA number of volume elements surround an edge so the DG velocities are calculated within \neach of these volume elements. Whenever there is no pipe we place on the diagonal unity and \nzero the r.h.s. and the rest of the non-zero's in the associated rows. \nThis allows the solvers to be unchanged as they simple assume the number of pressure variables \nat each pressure node is uniform across space and similarly for all the other variables. \n\n\n\n\n\n\\subsubsection{Discretisation of force balance - continuous pressure formulation} \n\n\n\nThe force balance equation is:\n\\begin{equation}\n{\\underline {\\underline \\sigma}}_k {\\mathbf u}_k = - \\nabla p + {\\mathbf s}_u, \n\\label{pipe-force-bal}\n\\end{equation}\nwith boundary conditions of either\n${{\\mathbf u}_k}\\cdot {\\mathbf n} = {{ u}_k}_{bc}$ (applied through the continuity  \nor saturation \nequation below) or $p = p_{bc}$. \n\nThe basic force balance equation is obtained by \nusing the discontinuous basis function ${\\mathbf Q}_i$ for velocity and \n$M_i$ for pressure and in which in 3D ${\\mathbf Q}_i$ becomes:\n\\begin{equation}\n{\\mathbf Q}_i = \n  \\begin{pmatrix}\n    Q_i   & 0 & 0 \\\\\n    0   & Q_i & 0 \\\\\n    0 & 0 & Q_i\n  \\end{pmatrix}\n\\label{pipe-m_sigma_matrix}\n\\end{equation}\n\nThus, the discretete force balance becomes:\n\n\\begin{equation}\n\\int_\\Omega {\\mathbf Q}_i ({\\underline {\\underline \\sigma}}_k {\\mathbf u}_k - \\nabla p -{\\mathbf s}_u) dV \n+  \\int_{\\Gamma_{\\Omega}} {\\mathbf Q}_i {\\mathbf n} (p - p_{bc}) d\\Gamma =0\n\\label{pipe-force-semi-disc}\n\\end{equation}\nwhere ${\\mathbf n}$ is the normal to the surface \nand $\\Omega$ is the domain of solution and \n${\\Gamma_{\\Omega}}$ the surface of the domain, ${\\mathbf s}_u$ is \nthe source and the velocity ${\\mathbf u}_k = \\phi {\\mathbf v}_k$, \n$\\phi$ is the \nelement-wise \nporosity and ${\\mathbf v}_k$ is the interstitial fluid velocity of phase $k$. \n\nSince $p$ is continuous between elements this becomes:\n\n\\begin{equation}\n{\\mathbf M}_\\sigma \\underline {\\mathbf u} = {\\mathbf C} \\underline {\\bf p} \n+ \\underline {\\bf s}_u. \n\\label{pipe-force-balance-matrix-form}\n\\end{equation}\nThe pressure vector is $\\underline{\\bf p} =(p_1\\; p_2 \\; p_3\\; ...\\; p_{\\cal M})^T$, \nthe velocity vector is decomposed into phases, thus for two phases, \n$\\underline{\\mathbf u}=(\\underline{\\mathbf u}_1^T \\;\\; \\underline{\\mathbf u}_2^T)^T$ \nand $\\underline{\\mathbf u}_k=({{\\mathbf u}_k}_1\\; {{\\mathbf u}_k}_2\\; {{\\mathbf u}_k}_3\\; ...\\; {{\\mathbf u}_k}_{\\cal Q}) $ \nand ${\\mathbf u}_k = \\sum_{j=1}^{\\cal Q} {\\mathbf Q}_j{{\\mathbf u}_k}_j$ and \n$p=\\sum_{j=1}^{\\cal M} M_j{p}_j$. Also \n\n\n\\begin{equation}\n{{\\mathbf M}_\\sigma}^{kk}_{ij} =  \\int_\\Omega {\\mathbf Q}_i \n{\\underline {\\underline \\sigma}}_k {\\mathbf Q}_j dV, \n\\end{equation}\nand for two phase flow\n\n\\begin{equation}\n{{\\mathbf M}_\\sigma} = \n  \\begin{pmatrix}\n    {{\\mathbf M}_\\sigma}^{11}   & 0 \\\\\n    0   & {{\\mathbf M}_\\sigma}^{22} \n  \\end{pmatrix}\n\\label{pipe-m_sigma_matrix}\n\\end{equation}\nand \n\n\\begin{equation}\n{\\mathbf C}_{ij}=\\int_\\Omega {\\mathbf Q}_i \\nabla M_j dV \n+ \\int_\\Gamma \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n}  M_j d\\Gamma,\n\\end{equation} \nand \n\n\\begin{equation}\n{{\\bf s}_u}_i= \\int_\\Omega {\\mathbf Q}_i {\\mathbf s}_u dV \n- \\int_\\Gamma \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} p_{bc} d\\Gamma. \n\\end{equation}\nwhere ${\\mathbf n}$ is the surface normal. \n\nThus, as usual with mixed formulations, not specifying a \nboundary condition for pressure corresponds to a no \nnormal flow condition which is realized through the continuity \nequation by weakly appling a Dirichlet no normal \nflow boundary condition. \n\n\n\n\\subsubsection{Discretisation of force balance - discontinuous pressure formulation} \n\nThe only difference between this formulations (as far as the force balance \nis concerned) and the continuous formulation is the treatment of pressure \nwhich is discontinuous along with saturation and density at element \nboundaries. The descrete force balance becomes:\n\\begin{equation}\n\\int_{\\Omega_E} {\\mathbf Q}_i ( {\\underline {\\underline \\sigma}}_k \n{\\mathbf u}_k - \\nabla p -{\\mathbf s}_u) dV \n+  \\int_{\\Gamma_{E}} \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} (p - p_{nab}) d\\Gamma \n+  \\int_{\\Gamma_{E}-\\Gamma} {\\mathbf Q}_i {\\mathbf n} (p - p_{bc}) d\\Gamma =0\n\\end{equation}\nand thus: \n\n\\begin{equation}\n{\\mathbf C}_{ij}=\\int_{\\Omega_E} {\\mathbf Q}_i \\nabla M_j dV \n+ \\int_{\\Gamma_{E}-\\Gamma} \\frac{1}{2}{\\mathbf Q}_i {\\mathbf n} M_j d\\Gamma \n+ \\int_\\Gamma {\\mathbf Q}_i {\\mathbf n} M_j d\\Gamma .\n\\end{equation}\nThis corresponds to a central difference discretisation for pressure \non the boundaries of each finite element, that is for example:\n\n\\begin{equation}\n\\int_{\\Omega_E} {\\mathbf Q}_i \\nabla p dV = -\\int_{\\Omega_E} \\nabla {\\mathbf Q}_i  p dV \n+ \\int_{\\Gamma_E} {\\mathbf Q}_i {\\mathbf n} p_{nab} dV \n= \\int_{\\Omega_E} {\\mathbf Q}_i \\nabla p dV \n+ \\frac{1}{2} \\int_{\\Gamma_E} {\\mathbf Q}_i {\\mathbf n} (p-p_{nab}) dV\n\\label{pipe-dg-sat-form}\n\\end{equation}\nwhere $p_{nab}$ is the pressure from the neighbouring \nelement and ${\\mathbf n}$ is the surface normal. \n\n\n\\subsubsection{The overlapping finite element method for multi-phase Darcy Flow} \n\nSo far for uniform ${\\underline{\\underline \\sigma}}_k$ within each element and the use of the P1DG-P2 element type \nand its equivalent in one dimension the Darcy flow equation is \nexactly enforced. Although this is not true of the DG variants \nfor pressure it is observed that it is close \nas the pressure does not have large discontinuities \nbetween elements at least in one dimension. \n\nHowever, ${\\underline{\\underline \\sigma_k}}$ depends on the saturation $S_k$ which has \na control volume (CV) distribution and is a non-linear function of $S_k$. \nThus, \t\t\t\n\n\\begin{equation}\n{\\underline {\\underline \\sigma}}_k \n= \\frac{1}{{Rel}_k} {\\underline{\\underline K}}^{-1} \t\n\\end{equation}\nin which the permeability tensor \n${\\underline{\\underline K}}$ has an element wise variation \nand ${Rel}_k$ is the relative permeability. \nThus, in general ${\\underline {\\underline \\sigma}}_k$ varies between elements and within each element \ndepending on the same variation as the CV saturation $S_k$ that is $Rel_k$. \nThus, ${\\underline {\\underline \\sigma}}_k$ is piecewise constant \nwithin each element and a natural \nway to obtain an exact solution would be to use basis functions \nlocal to each CV within each element. \nThus, if for quadratic pressure variation there will be \na piecewise \nlinear velocity field with simple discontinuity between \nelements and one could then use linear basis functions \nand test functions within each control volume. Thus, in one dimension \nthere would be $2\\times 3$ velocity nodal values associated with \neach phase.  \n\nHowever, such an approach is cumbersome especially in multi-dimensions. \nIn fact it may become inpracticle. To overcome this \nproblem overlapping basis functions are used. The approach is derived \nbased on the observation \nthat the only difference between the velocities \nwithin each CV is a multiplication factor \nand this multiplication factor is ${\\underline {\\underline \\sigma}}_k^{-1}$. \nThus, one can discretise  \nusing: \n\\begin{equation}\n\\int_\\Omega {\\mathbf Q}_i^\\mu ({\\underline{\\underline\\sigma}}_k^\\mu {\\mathbf u}_k^\\mu - \\nabla p -s^\\mu) dV + \n\\int_{\\Gamma}\\gamma {\\mathbf Q}_i^\\mu {\\mathbf n} (p-p_{bc}) d\\Gamma =0 \n\\label{pipe-overlap-eqn} \n\\end{equation}\nin which ${\\mathbf Q}_i^\\mu$ are the weighting functions. \n${\\mathbf Q}_i^\\mu$ are also the  \nvelocity basis functions which span the whole \nelement that they belong to \nand also ${\\mathbf Q}_i^\\mu={\\mathbf Q}_i^1\\;\\; \\forall \\mu\\in\\{1,2,...,{\\cal N}_{locCV}\\}$\nwhere ${\\cal N}_{locCV}$ is the number of local control volumes within each \nfinite element and ${\\mathbf u}_k =\\sum_\\mu \\sum_j H^\\mu {{\\mathbf u}_k}_j^\\mu$ where \n$H^\\mu=1$ in local control volume $o$ and $=0$ otherwise. \nIt also enables relatively low order quadrature rules to be used \nacross each finite element.  \nFor 2D quadatric pressure triangular elements (see figure \\ref{pipe-p1dgp2_ele-dgsat_pics}) \nthere are $3\\times6=18$ velocity basis \nfunctions for each of the two directions and each phase. \nFor 3D quadatric pressure \ntetrahedra elements there are $4\\times 10=40$ velocity basis \nfunctions for each of the two directions and each phase.\n\nThe result is again the recovery of the exact enforcement of \nthe differential equation at least away from the boundaries. \nNow including in the previous formulation $\\gamma=1$ however \nwe now need to take into account the difference in the \nvolumes of the elements as we integrate right \nacross the whole element. This is taken into account \nusing \n\n\\begin{equation}\n\\gamma^\\mu = \\frac{V^\\mu_E}{V_E} \\frac{S^\\mu_E}{S_E}\n\\label{pipe-overlap-eqn-gamma}\n\\end{equation}\nin which $V_E$ is the volume of element $E$ \nand $V^\\mu_E$ is the volume of control volume $\\mu$ \nin element $E$ and $S_E$ is the surface area of the element \non the boundary and $S^\\mu_E$ is the surface \narea of element $E$ of CV $\\mu$ in element $E$ on the boundary \nof the domain. \n\nThe discontinuous formulation is also easily extended \nto this overlapping finite element approach and becomes: \n\n\\begin{equation}\n\\int_{\\Omega_E} \\hat{\\mathbf Q}_i^\\mu ({\\underline{\\underline{\\sigma}}}_k^\\mu {\\mathbf u}_k^\\mu - \\nabla p -{\\mathbf s}_u^\\mu) dV \n+  \\frac{1}{2}\\int_{\\Gamma_{E-\\Omega}} \\gamma^\\mu_E {\\mathbf Q}_i^\\mu {\\mathbf n} (p - p_{nab}) d\\Gamma \n+  \\int_{\\Gamma_{\\Omega}}  \\gamma^\\mu_E \\hat{\\mathbf Q}_i^\\mu {\\mathbf n} (p - p_{bc}) d\\Gamma =0. \n\\label{pipe-overlap-eqn-dg}\n\\end{equation}\nand given that \n\\begin{equation}\n{\\mathbf Q}_j=\\hat{\\mathbf Q}_i^\\mu \n\\end{equation}\nfor a suitable index $j$ the discretisation can be expressed \nsimilar to equation \\ref{pipe-force-semi-disc} for the continuous formulation and \nequation \\ref{pipe-dg-sat-form} for the discontinuouse \nbetween elements pressure/saturation formulation. \n\n\n\n\n\\subsubsection{Discretised saturation equation and global mass balance} \n\nThis section outlines the discrete saturation equations and derives the global mass balance equations from the saturation equations. The resulting equation can then be solved simultaneously with equation \\ref{pipe-force-balance-matrix-form}. \n\t\t\t\t\t\t\t\n\nThe saturation equation \n\n\\begin{equation}\n\\phi\\frac{\\partial \\rho_k S_k }{\\partial t} \n+ \\nabla \\cdot {\\mathbf u}_k \\rho_k S_k = {s_{cty}}_k, \n\\end{equation}\ndiscretised by testing it with CV basis functions \n $M_i$ is and discretising in time using the \n $\\theta-$method is:\n \n\\begin{equation}\n\\int_\\Omega M_i (\\frac{\\phi{\\rho_k}_i^n ({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {\\Delta t} ) dV\n+ \\int_{\\Gamma_{CV_i}} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} \nd\\Gamma \n= \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV.\n\\label{pipe-detail-sat-eqn-k}\n\\end{equation}\n \n \n\\subsubsection{Discretised global continuity equation} \n \nDividing equation \\ref{pipe-detail-sat-eqn-k} by ${\\rho_k}^n_i $ and summing \nover all phases one obtains the global continuity equation: \n\n \n\\begin{equation}\n \\sum_k \\left(\n\\int_\\Omega M_i (\\frac{ \\phi({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {{\\rho_k}_i^n\\Delta t} ) dV\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} \n{\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta}   S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV \\right) =0,\n\\label{pipe-detail-sat-eqn-k-sum}\n\\end{equation}\n\nThe saturations and densities are flux limited in space and \ntime as explained in section \\ref{pipe-fluid_transport_methods_section}. This uses a finite element \ninterpolation of the saturations and densities which are limited. \n\t\t\t\n\n\nUsing $\\sum_{k=1}^{\\cal K} {S_k}_i^n =1, \\;\\; \\forall n$ and linear \n$\\rho_k^{n+1}$ about the CV pressure variation $P_{CV}^{n+1}$ then \n\n\\begin{equation}\n \\sum_k ( \\int_{\\Omega} M_i \n( \\frac{{S_k}_i^n \\frac{\\partial \\tilde{\\rho_k}_i^{n+1}}{\\partial \\tilde{ p_{CV}}_i^{n+1}}({p_{CV}}_i^{n+1}-\\tilde{p_{CV}}_i^{n+1})\n} {{\\rho_k}_i^n\\Delta t} \n+ \\frac{{S_k}_i^n( \\tilde{\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} \n{{\\rho_k}_i^n \\Delta t} ) dV\n\\end{equation}\n\\begin{equation}\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k dV ) =0.\n\\label{pipe-detail-global-cty}\n\\end{equation}\nIn matrix form this becomes:\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} \n= \\underline{\\bf s}_p. \n\\label{pipe-glob-cty-matrix}\n\\end{equation}\n\nNotice that in equation \\ref{pipe-detail-global-cty} the \ncontrol volume-wise variation of pressure ${p_{CV}}_i^n$ has been \nused and in order to get to the equation  \\ref{pipe-glob-cty-matrix} \nabove the finite element variation of pressure with basis \nfunctions $N_i$ has been used. Thus, to get to equation \n\\ref{pipe-glob-cty-matrix} the Galerkin projection\n\n\\begin{equation}\n\\int_{\\Omega} M_i (p_{CV}^n-p^n) dV =0\n\\end{equation}\nfor $p^n$ is used. This results in solving the matrix \nequation for ${\\bf p}^n$: \n\n\\begin{equation}\n{\\mathbf M}_{CV} \\underline{\\bf p}_{CV}^n = {\\mathbf N}_{CVfem} \\underline {\\bf p}^n\n\\end{equation}\nin which the matrix ${\\mathbf M}_{CV}$ is diagonal and thus \nthis can easily help form the matrix ${\\mathbf M}_p$ in equation \n\\ref{pipe-glob-cty-matrix}. \n\n\\subsubsection{Compressibility - CV and FEM pressure variations}\n\nHaving both a CV and FEM variation of pressure allows us to \nsimultaneously have an exact representation of the force balance \nequation as well as ensuring robustness of the the scheme \ne.g. positive densities from potentially complex equations \nof state. When using complex EoS's $\\frac{\\partial \\tilde { \\rho_k}_i^{n+1}}{\\partial \\tilde {p_{CV}}_i^{n+1}}$ is formed \nusing a pertabation approach, that is \nperturbing the pressure $\\tilde {p_{CV}}_i^{n+1}$ and looking how \nit effects the densities $\\tilde {\\rho_k}_i^{n+1}$. This \navoids differentiating complex EoS's. \n\n\t\t\t\t\n\n\\subsubsection{Upwind velocity/relative permeability} \n\\label{pipe-opt-up} \n\nIt remains to us to determine the velocity to be used \nat the interface between control volumes in the \nsaturation \\ref{pipe-detail-sat-eqn-k} and therefore \nthe global continuity equations \\ref{pipe-detail-global-cty}. \n\nThe problem is that on a CV boundary it is unclear \nwhich side of the control volume boundary the velocity \nshould be taken from as there is a discontinuity \nof velocity at the CV boundary. The discontinuity \nis due to the differing relative permeabilities of \n$\\sigma_k$'s in each CV and is the only way that \nequation \\ref{pipe-force-semi-disc} can be strongly enforced. \nThis discontinuity happens between elements for the DG \nformulation and as well as between CVs within each element. \n\nOne way to determine the value of the velocity \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ \non the interface between two control volumes \nis to dermine the value of ${\\sigma_k}_{int}$ on this boundary \nand then one can obtain the value of \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ that \ncorresponds to this from equation \\ref{pipe-force-semi-disc}. \n\nWhen $({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$ \nis determined one can turn this \ninto the proportion of each of the surrounding control \nvolumes goes up to make \n$({{\\mathbf n}\\cdot{\\mathbf u}_k})_{int}$. Here any downwind \nbiased averages are simply set to a central difference \n(which may not just be a simple average if we have \nunequal CV sizes or are using the FEM saturation \non the control volume boundary) and in the case \nwhen there is an upwind bias then this is accepted. \nThis choice is used in order to maintain consistency \nwith the characteristics of the BL equations. \n\n\n\n\n\n\n\n\\subsubsection{Boundary conditions for saturation, pressure and relative permeability} \n\\label{pipe-bcs-rel-perm} \nSuitable boundary conditions can be guided by the \ndiscontinuous formulations above as well as the up-winding in \nthe continuous formulations. In fact, exactly the same \nboundary condition implementations can be applied as used in \nthe discontinuous formulations but across the boundaries \nof the domain and taking information from just outside the domain \nrather than in the neighbouring elements. \n\nSaturation boundary conditions are relatively straightforward. \nOne typically takes the saturation from just outside the domain \n(the saturation boundary condition ${S_k}_{bc}$) \nas part of the incoming flux \n(when ${\\bf n}\\cdot {\\bf u}_k<0$) for phase $k$:\n\n\\begin{equation}\n{\\bf n}\\cdot {\\bf u}_k {S_k}_{bc} .\n\\end{equation}\n\nWhen in addition the velocity \n${\\bf n}\\cdot {{\\bf u}_k}_{bc}$ is \nspecified then this too must be part of the \nincoming flux (when ${\\bf n}\\cdot {{\\bf u}_k}_{bc}<0$) for phase $k$:\n\n\\begin{equation}\n{\\bf n}\\cdot {{\\bf u}_k}_{bc} {S_k}_{bc} .\n\\end{equation}\n\nSimilar, boundary conditions can be applied using Riemann \nvariables to work out if information is travelling into \nor out of the domain although most models do not follow this \nmore rigorous approach. \n\nSpecified pressure boundary conditions for outlet \nflux (when ${\\bf n}\\cdot {\\bf u}_k>0$) for phase $k$ are:\n\n\\begin{equation}\n{\\bf n}\\cdot {\\bf u}_k {S_k},\n\\end{equation}\nin which neither ${\\bf u}_k$, ${S_k}$ are specified. \n\nSpecified pressure boundary conditions for the inlet \nflux (when ${\\bf n}\\cdot {\\bf u}_k<0$) for phase $k$ are:\n\n\\begin{equation}\n{\\bf n}\\cdot {{\\bf u}_k}_{rel} {S_k}_{bc},\n\\label{pipe-flux-adjust-rel} \n\\end{equation}\nin which the relative permeability is up-winded and thus taken \nfrom outside the domain resulting in a value of ${\\underline {\\underline \\sigma}}_k$ of \n${{\\underline {\\underline \\sigma}}_k}_{outside}$. The latter is calculated from \nthe saturation boundary condition value ${S_k}_{bc}$. \n\n\n\nA third approach for up-winding the \nrelative permeability on incoming specified pressure \nboundaries is to simply adjust the value of ${{\\underline {\\underline \\sigma}}_k}_{inside}$ \njust inside the domain by setting it to the \nvalue just outside the domain \n\\begin{equation}\n{{\\underline {\\underline \\sigma}}_k}_{inside}={{\\underline {\\underline \\sigma}}_k}_{outside} ,\n\\end{equation}\nand the flux \ncondition then becomes: \n\n\n\\begin{equation}\n{\\bf n}\\cdot{{\\bf u}_k} {S_k}_{bc}.\n\\end{equation}\nIt should be noted that the flux conditions above \nmust be used in both the discretised saturation equations \nas well as the global continuity equation - since the latter \nis a summation of the former. \n\nThe specified pressure condition becomes a surface flux \ncondition in the force balance equation of \n\n\\begin{equation}\n{\\bf n} (p-p_{bc}),\n\\end{equation}\nwhich effectively relaxes the pressure $p$ to its boundary \nvalue $p_{bc}$ at the boundary. \n\n\n\n\\subsubsection{Projection method of solution} \n\\label{pipe-Projection method of solution}\n\nThe  \nglobal mass balance equation \\ref{pipe-glob-cty-matrix} and \nforce balance equations \\ref{pipe-force-balance-matrix-form} are solved here \nby using a projection method. This effectively eliminates \nout velocity and solves a system of equations for \npressure or pressure correction. \n\nThe force balance (at time level $n+1$) \nand global continuity equations are:\n\n\\begin{equation}\n({\\mathbf M}_\\sigma +{\\mathbf A}) \\underline{\\bf u}^{n+1} = {\\mathbf C} \\underline{\\bf p}^{n+1} + \\underline{\\bf s}_u^{n+1},\n\\label{pipe-force-balance-matrix-form2}\n\\end{equation}\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} = \\underline{\\bf s}_p^{n+1}. \n\\label{pipe-glob-cty-matrix2}\n\\end{equation}\n\nFor generality we have introduced a matrix ${\\mathbf A}$ which may be \ndistributed and thus can not be easily inverted. \nThis allows the method to be applied to inertia dominated \nor viscous dominated flows without modification. \nUsing the discontinuous velocity within an element \nformulation the matrix ${\\mathbf M}_\\sigma$ is block diagonal \nand thus easily inverted - each block being local to an element. \n\nThe solution method proceeds by first solving for \nan intermediate velocity $\\underline{\\bf u}^{n+1}_*$ using a \nguessed pressure $\\underline{\\bf p}^{n+1}_*$ on the first iteration \nwithin a time step one may use $\\underline{\\bf p}^{n+1}_*=\\underline{\\bf p}^n$ say. \nThe equation is: \n\n\\begin{equation}\n({\\mathbf M}_\\sigma +{\\mathbf A}) \\underline{\\bf u}^{n+1}_* = {\\mathbf C} {\\bf p}^{n+1}_* + \\underline{\\bf s}_u^{n+1}. \n\\label{pipe-force-balance-matrix-form2-guess}\n\\end{equation}\nThe matrix equation for velocity to be satisifed is: \n\\begin{equation}\n{\\mathbf M}_\\sigma\\underline{\\bf u}^{n+1} +{\\mathbf A} \\underline{\\bf u}^{n+1}_* = {\\mathbf C} \\underline{\\bf p}^{n+1} + \\underline{\\bf s}_u^{n+1}. \n\\label{pipe-force-balance-matrix-form2-guess-2}\n\\end{equation}\nSubtracting these two equations the   \nvelocity correction equation is obtained:\n\\begin{equation}\n{\\mathbf M}_\\sigma ( \\underline{\\bf u}^{n+1} -\\underline{\\bf u}^{n+1}_*) \n= {\\mathbf C} (\\underline{\\bf p}^{n+1} - \\underline{\\bf p}^{n+1}_*). \n\\label{pipe-force-balance-matrix-form2-guess}\n\\end{equation}\nMultiplying this equation by ${\\mathbf B}^T {\\mathbf M}_\\sigma^{-1}$ \n(see global continuity \nequation \\ref{pipe-glob-cty-matrix2}) and using the global comntinuity \nequation to eliminate out $ \\underline{\\mathbf u}^{n+1} $ one obtains \nthe pressure correction equation:\n\n\\begin{equation}\n({\\mathbf B}^T {\\mathbf M}_\\sigma^{-1} {\\mathbf C} + {\\mathbf M}_p) (\\underline{\\bf p}^{n+1} - \\underline{\\bf p}^{n+1}_*) \n= - {\\mathbf M}_p \\underline{\\bf p}^{n+1}_* - {\\mathbf B}^T \\underline{\\bf u}^{n+1}_* + \\underline{\\bf s}_p^{n+1}.\n\\end{equation}\nthis equation is solved for the pressure  $\\underline{\\bf p}^{n+1}$ and the \nvelocity is corrected using equation \\ref{pipe-force-balance-matrix-form2-guess}.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Non-dimensional scaling of the equations with wells} \n\\label{well-scaling}\n\nOne can scale the equations with wells in order to make the numbers generated on the \ncomputer easier to deal with in terms of round off error as well as for the iterative \nsolvers. \nConsider the force balance equation in the reservior:\n\n\\begin{equation}\n\\sigma u = -\\nabla p. \n\\end{equation}\n\nUsing the new non-dimensional variables $\\sigma=\\Sigma \\sigma^*$, $u=U u^*$ , $p=\\Sigma U L p^*$, \n$x=L x^*$ \nand $t=\\frac{L}{U} t^*$ in which $L$ is a length scale \none \nobtains:\n\\begin{equation}\n\\Sigma U \\sigma^* u^* = -\\frac{1}{L} \\nabla^*  \\Sigma U L p^*. \n\\end{equation}\nHere $\\Sigma,\\; U,\\; L$ are dimensional scalar constants. \nThus,  \n\\begin{equation}\n\\sigma^* u^* = -\\nabla^* p^*. \n\\end{equation}\nA simplified saturation equation in the reservior with exchange of mass with wells (the term involving pressure the reservior pressure $p$ and the well pressure $p_w$) is:\n\\begin{equation}\n\\phi_i \\frac{\\partial S_k}{\\partial t} \n+ \\nabla \\cdot u_k S_k\n+ \\gamma (p-p_w)=0,\n\\end{equation}\nand thus:\n\\begin{equation}\n\\frac{U}{L} \\phi_i \\frac{\\partial S_k}{\\partial t^*} \n+ \\frac{U}{L} \\nabla^* \\cdot u_k^* S_k\n+ \\gamma \\Sigma U L  (p^*-p^*_w)=0, \n\\end{equation}\nalso:\n\\begin{equation}\n\\phi_i \\frac{\\partial S_k}{\\partial t^*} \n+ \\nabla^* \\cdot u_k^* S_k\n+ \\gamma \\Sigma  L^2  (p^*-p^*_w)=0, \n\\end{equation}\nand:\n\\begin{equation}\n\\phi_i \\frac{\\partial S_k}{\\partial t^*} \n+ \\nabla^* \\cdot u_k^* S_k\n+ \\gamma^* (p^*-p^*_0)=0. \n\\end{equation}\nThe key non-dimensional parameter governing the exchange of mass between \nthe well and the reservoir is thus: \n\\begin{equation}\n\\gamma^* = \\gamma  \\Sigma L^2.  \n\\end{equation}\nFor the key well producing situation (ignoring density for the time being) from equation  \n\\ref{saturation_wells_12-gamma}, \nfor $p_{well}< p_{reservior}$: \n\\begin{equation}\n\\gamma^* = \\gamma_{up_i}^{well\\, reservoir}\n  \\Sigma L^2 \n=\\frac{A_{pipe-wall}  S_i^{reservoir}   }\n{{\\Delta x}_{wall}{\\sigma_{wall}}_i}\n  \\Sigma L^2\n\\end{equation}\n\n\n\n\\subsection{Methods of enhancing production rate from perforated wells:} \n\\label{Methods of enhancing production rate from perforated wells:} \n\\par\\noindent\n1) Changing the diameter of the wells does have an increased \neffect on production but it may be more effective (see Peacman correction \nfor example) to have more numerous or longer wells. \n\\par\\noindent\n2) Having deeper wells: The deeper the wells often the greater the reservoir pressure \nand thus the greater the pressure difference which governs the production rate. \nHowever, this has to more than compensate for the hydrostatic pressure within the wells. \n\\par\\noindent\n3) Having longer wells away from the main motherbore: This may be more effective \nthan having more numerous wells of the same length from the motherbore as the \ngreater the distance from the motherbore the greater the pressure within the \nreservoir is likely to be or, more specifically, the pressure difference between the \nwell pressure and the reservoir. This can have a substantial effect on production. \n\\par\\noindent\n4) Methods of increasing fracturing around the wells increases production rate (making the effective \ndiameter of the wells greater) and is modelled here through the skin effect. \n\\par\\noindent\n5) Increasing the permeability of well casing with numerous holes will increase production   \nbut perhaps not greatly, after a certain point, as its often the pressure gradients \nacross the porous media that is the critical factor. So even a highly perforated well may only \nproduce slightly more than one with a casing with a few holes, say. This effect, however, \nneeds to be understood better. \n\\par\\noindent\n6) Taking into account the heterogeneous geology of the reservoir: From the modelling \nperspective this is the major strength of IC-FERST and will need to be developed in the future. \nAnother strength of IC-FERST is its unique capability for combined modelling and resolving of laterals \nwhich can make the modelling highly efficient. \n\\par\\noindent\n7) Taking into account anisotropy in the permeabilities of the reservoir: Generally speaking drilling \nthe wells in the direction of lowest permeability will take the wells to areas where \nlarger pressure gradients between the reservoir and the well can be achieved enhancing production. \n\\par\\noindent\n8) Confinement of the reservoir: If for example the reservoir has limited extent in the \nvertical then it may be more benefitical to drill horizontally so that the wells enter \nareas of higher pressure. In this case there may be little variation (other than hydrostatic) \nof pressure gradient in the vertical. \n\\par\\noindent\n9) Reducing the friction within the well/pipe: The friction can be reduced by polishing the \ninside surfaces or increasing the diameter of the pipes. However, this, generally, has only a \nsmall effect on production rate as the pressure drop across the pipes due to friction is \nrelatively small compared to the pressure drop across the reservior. \n\\par\\noindent\n10) Formal optimization methods of the placement and length of the motherbore, the laterals, \nmicro-laterals and nano-laterals could substantially increase production. This may involve \nrapid reduced order or analytical models to help speed up the optimization process.\n\n\n\\pagebreak\n\n\n\n\n\\section{LES and Q-Scheme Modelling} \n\\label{LES and Q-Scheme Modelling} \n\n\n\n\\subsection{Theory of new SFS model}\n\\label{SFSm} In the standard formalism of LES, the separation of\nscales into resolved and sub-filter scales (usually but\ninappropriately called sub-grid scales) is achieved using a\nspatial filtering operation:\n\\begin{equation}\n\\mathbf{\\tilde{u}}(\\mathbf{x},t)= \\int_{R} \\mathbf{u}(\\mathbf{x}')\nG(\\mathbf{x}-\\mathbf{x}')\\,\\mathrm{d}\\mathbf{x}'\n\\label{eq:Les-filter}\n\\end{equation}\nwhere the tilde denotes a filtered quantity and $G$ represents the\n(arbitrarily defined) filter. The filter has the effect of\nremoving (or suppressing) those scales of motion smaller than the\nfilter width $\\Delta$. Provided the filter $G$ is invariant in\nspace and time\\label{homo}, the filtered continuity and\nNavier-Stokes equations can be written:\n\\begin{equation}\n\\frac{\\partial \\tilde{u}_i}{\\partial x_i}=0\n\\end{equation}\n\\begin{equation}\n\\frac{\\partial \\tilde{u}_i}{\\partial t}+ \\tilde{u}_j\n\\frac{\\partial \\tilde{u}_i}{\\partial x_j}= -\\frac{1}{\\rho}\n\\frac{\\partial \\tilde{p}}{\\partial x_i}+ \\frac{\\partial}{\\partial\nx_j} \\left[\\nu\\left(\\frac{\\partial \\tilde{u}_i}{\\partial x_j}+\n\\frac{\\partial \\tilde{u}_j}{\\partial x_i}\\right)+\\tau_{ij}\\right]\n\\label{eq:Les-NS2}\n\\end{equation}\nThe quantity $\\tau_{ij}$ is called the SFS tensor. It represents\nthe effect of the unresolved scales on the resolved flow-field,\nand is given by\n\\begin{equation}\n\\tau_{ij} = \\tilde{u}_i \\tilde{u}_j - \\widetilde{u_i u_j}\n\\end{equation}\nThe scalar field equation is treated in a similar fashion. Like\nReynolds' stresses in the RANS equations, the presence of the SFS\ntensor means that the filtered Navier-Stokes equations are not\nclosed. A model for this tensor is required, to account for the\neffects of the unresolved fluctuations on the filtered field. Such\na model is called a sub-filter scale or SFS model.\n\nThe large variety of models proposed for the sub-filter scale\ntensor has been reviewed extensively -- for example, see\n\\cite{LnM96} or \\cite{MnK00}. The models most frequently used in\ncomplex flows are based on the eddy viscosity assumption, i.e.~the\nassumption that the unresolved scales act primarily to drain\nenergy from the resolved scales, in the same way that molecular\nviscosity removes energy from laminar flow. If this assumption is\nmade, the filtered Navier-Stokes equation can be written in the\nfollowing form (cf Equation \\ref{eq:Les-NS2}):\n\\begin{equation}\n\\frac{\\partial \\tilde{u}_i}{\\partial t}+ \\tilde{u}_j\n\\frac{\\partial \\tilde{u}_i}{\\partial x_j}= -\\frac{1}{\\rho}\n\\frac{\\partial \\tilde{p}}{\\partial x_i}+ \\frac{\\partial}{\\partial\nx_j} \\left[2\\left(\\nu+\\nu_{\\textrm{t}}\\right)\n\\tilde{S}_{ij}\\right]\n\\end{equation}\nwhere\n\\begin{equation}\n\\tilde{S}_{ij}=\\frac{1}{2} \\left(\\frac{\\partial\n\\tilde{u}_i}{\\partial x_j}+ \\frac{\\partial \\tilde{u}_j}{\\partial\nx_i}\\right)\n\\end{equation}\nis the strain rate and $\\nu_{\\textrm{t}}$ is the eddy or turbulent\nviscosity. This eddy viscosity can be modelled in various ways,\nbut the simplest and most popular is the mixing-length-type model\nproposed by \\cite{Sma63}:\n\\begin{equation}\n\\nu_{\\textrm{t}}=l_{\\textrm{S}}^2\\,\\vert\\tilde{\\mathcal{S}}\\vert=\n\\left(C_{\\textrm{S}}\\Delta\\right)^2\\vert\\tilde{\\mathcal{S}}\\vert\n\\label{eq:Smag}\n\\end{equation}\nwhere $l_{\\textrm{S}}$ is a length-scale, taken to be the product\nof the filter width and a constant, and the local strain rate is\ndefined by $ |\\tilde{\\mathcal{S}}|=\n(2\\tilde{S}_{ij}\\tilde{S}_{ij})^{1/2} $. The value of the\nSmagorinsky constant $C_{\\textrm{S}}$ can be found from global\nenergy balance considerations and is $\\sim$ 0.1 (see for example\n\\cite{LnM96}).\n\nThe Smagorinsky model has been criticised for being too\ndissipative of turbulent kinetic energy, and too simplistic in\nassuming that the same length-scale can be employed throughout the\nflow. An improvement to this basic model has been proposed by\nGermano et al.~\\cite{GPM91}, as mentioned in Section \\ref{intro}.\nTheir dynamic model allows the length-scale to vary by tuning the\n`constant' according to local flow attributes. Although\nundoubtedly more accurate than the Smagorinsky model, the dynamic\nmodel requires a double filtering operation, which adds\ncomputational expense, and suffers from problems of stability\n\\cite{LnM96}. In this paper two new SFS models are presented,\nwhich allow the length-scale to vary both in space and direction\nby introducing a length-scale tensor, without requiring an\nexplicit filtering operation.\n\n\\subsection{SFS-a1 model}\nSFS-a1 is based on the eddy-viscosity assumption and is similar to\nthe Smagorinsky model (Equation \\ref{eq:Smag}). The advantage of\nSFS-a1 is that the length-scale $l_{\\textrm{S}}$ is related\ndirectly to the local length-scale of the flow, and is allowed to\nvary in space and direction, rather than being fixed and\npre-determined. SFS-a1 is also implemented somewhat differently\nfrom Smagorinsky's model. In the filtered Navier-Stokes equations,\nthe SFS tensor term from Equation \\ref{eq:Les-NS2} is modelled as\n\\begin{equation}\n\\frac{\\partial \\tau_{ij}}{\\partial x_j} = \\frac{\\partial}{\\partial\nx_i} \\left[\\nu_{jk} \\frac{\\partial u_j}{\\partial x_k}\\right]\n\\label{eq:Tlike}\n\\end{equation}\nwhere $\\nu_{jk}$ is a tensorial eddy-viscosity. This\nimplementation involves treating each velocity component as an\nindependent scalar, in the same way as the temperature or\nconcentration can be treated, but is equivalent to solving the\nfiltered Navier-Stokes momentum equations.\n\nThe local length-scale of the flow in each direction is already\ncalculated as part of the mesh adaptivity routine in the FLUIDITY\ncode used for these simulations (see \\cite{PUO01}) -- it is\nrelated to the size of the mesh elements. This fact was used to\ndevelop a novel tensorial model for the eddy viscosity, as\nfollows. (Matrix notation is used in the derivation because it is\nclearer.) Consider a matrix of eddy viscosities, equivalent to the\ntensor $\\nu_{jk}$ in Equation \\ref{eq:Tlike}:\n\\begin{equation}\n\\mbox{\\boldmath$\\nu$}_{\\textrm{t}} = \\left[ \\begin{array}{ccc}\n\\nu_{\\textrm{t}xx} & \\nu_{\\textrm{t}xy} & \\nu_{\\textrm{t}xz} \\\\\n\\nu_{\\textrm{t}yx} & \\nu_{\\textrm{t}yy} & \\nu_{\\textrm{t}yz} \\\\\n\\nu_{\\textrm{t}zx} & \\nu_{\\textrm{t}zy} & \\nu_{\\textrm{t}zz}\n\\end{array} \\right] =\n\\mathbf{V}^{\\textrm{T}} \\left[ \\begin{array}{ccc}\n\\nu_{\\textrm{t}\\zeta\\zeta} & 0 & 0 \\\\\n0 & \\nu_{\\textrm{t}\\eta\\eta} & 0 \\\\\n0 & 0 & \\nu_{\\textrm{t}\\xi\\xi}\n\\end{array} \\right] \\mathbf{V}\n\\end{equation}\nwhere the multiplication by $\\mathbf{V}^{\\textrm{T}}$ and\n$\\mathbf{V}$ represents a rotation from the local element\nco-ordinate system $(\\zeta,\\eta,\\xi)$ to the global simulation\nco-ordinates. Employing the Smagorinsky model in each direction:\n\\begin{equation}\n\\mbox{\\boldmath$\\nu$}_{\\textrm{t}} =\nC_{\\textrm{S}}^2|\\tilde{\\mathcal{S}}| \\mathbf{V}^{\\textrm{T}}\n\\left[ \\begin{array}{ccc}\n\\Delta_\\zeta^2 & 0 & 0 \\\\\n0 & \\Delta_\\eta^2 & 0 \\\\\n0 & 0 & \\Delta_\\xi^2\n\\end{array} \\right] \\mathbf{V}\n\\end{equation}\nThe filter width for separation into resolved and unresolved\nscales is set to twice the local element size\n$(h_\\zeta,h_\\eta,h_\\xi)$; this allows a truer representation of\nthe resolved scales than the usual convention of setting the\nfilter equal to element size -- see \\cite{Pop00} for details.\n\\begin{equation}\n\\mbox{\\boldmath$\\nu$}_{\\textrm{t}} =\n4C_{\\textrm{S}}^2|\\tilde{\\mathcal{S}}| \\mathbf{V}^{\\textrm{T}}\n\\left[ \\begin{array}{ccc}\nh_\\zeta^2 & 0 & 0 \\\\\n0 & h_\\eta^2 & 0 \\\\\n0 & 0 & h_\\xi^2\n\\end{array} \\right] \\mathbf{V}\n\\end{equation}\nIn the mesh adaptivity process (see Section \\ref{adapt}) a term\nknown as the metric $\\mathcal{M}$ is used. This metric can be\nexpressed as\n\\begin{equation}\n\\mathcal{M} = \\mathbf{V}^{\\textrm{T}} \\mbox{\\boldmath$\\Lambda$}\n\\mathbf{V} = \\mathbf{V}^{\\textrm{T}} \\left[ \\begin{array}{ccc}\n\\lambda_\\zeta & 0 & 0 \\\\\n0 & \\lambda_\\eta & 0 \\\\\n0 & 0 & \\lambda_\\xi\n\\end{array} \\right] \\mathbf{V}\n\\end{equation}\nwhere $\\mathbf{V}$ is a rotation matrix containing the normalised\neigenvectors of $\\mathcal{M}$ and {\\boldmath$\\Lambda$} is a\ndiagonal matrix containing its eigenvalues. The eigenvalues\n$\\lambda_i$ correspond to $h_i^{-2}$, where $h_i$ is the size of\nthe element in each of its principal directions. The rotations\n$\\mathbf{V}^{\\textrm{T}}$ and $\\mathbf{V}$ transform from the\nlocal co-ordinate system of the element (with axes aligned with\nits principal directions) to the global system. It is easy to show\nthat\n\\begin{equation}\n\\mathcal{M}^{-1} = \\mathbf{V}^{-1}\\mbox{\\boldmath$\\Lambda$}^{-1}\n\\left(\\mathbf{V}^{\\textrm{T}} \\right)^{-1} =\n\\mathbf{V}^{\\textrm{T}} \\mbox{\\boldmath$\\Lambda$}^{-1} \\mathbf{V}\n= \\mathbf{V}^{\\textrm{T}} \\left[ \\begin{array}{ccc}\nh_\\zeta^2 & 0 & 0 \\\\\n0 & h_\\eta^2 & 0 \\\\\n0 & 0 & h_\\xi^2\n\\end{array} \\right] \\mathbf{V}\n\\end{equation}\nand so we can write\n\\begin{equation}\n\\mbox{\\boldmath $\\nu$}_{\\textrm{t}} =\n4C_{\\textrm{S}}^2|\\tilde{\\mathcal{S}}| \\mathcal{M}^{-1}\n\\end{equation}\nwhich is the desired anisotropic viscosity matrix (or tensor).\n\n\\subsection{SFS-a2 model}\nSFS-a2 is very similar to SFS-a1 in conception, except that the\nNavier-Stokes equations are solved in stress form:\n\\begin{equation}\n\\left[ \\begin{array}{c}\n\\sigma_x \\\\ \\sigma_y \\\\ \\sigma_z \\\\\n\\tau_{xy} \\\\ \\tau_{xz} \\\\ \\tau_{yz}\n\\end{array} \\right] =\n\\rho \\begin{bmatrix} \\frac{4}{3}\\nu_{xx} & -\\frac{2}{3}\\nu_{xy} &\n-\\frac{2}{3}\\nu_{xz} & 0 & 0 & 0 \\\\\n-\\frac{2}{3}\\nu_{xy} & \\frac{4}{3}\\nu_{yy} &\n-\\frac{2}{3}\\nu_{yz} & 0 & 0 & 0 \\\\\n-\\frac{2}{3}\\nu_{xz} & -\\frac{2}{3}\\nu_{yz} &\n\\frac{4}{3}\\nu_{zz} & 0 & 0 & 0 \\\\\n0 & 0 & 0 & \\nu_{xy} & 0 & 0 \\\\\n0 & 0 & 0 & 0 & \\nu_{xz} & 0 \\\\\n0 & 0 & 0 & 0 & 0 & \\nu_{xy} \\end{bmatrix} \\left[ \\begin{array}{c}\n\\epsilon_x \\\\ \\epsilon_y \\\\ \\epsilon_z \\\\\n\\gamma_{xy} \\\\ \\gamma_{xz} \\\\ \\gamma_{yz}\n\\end{array} \\right]\n\\end{equation}\nwhere $\\sigma$ is a plane stress, $\\tau$ a shear stress,\n$\\epsilon$ a plane strain and $\\gamma$ a shear strain. This can be\nwritten more concisely as\n\\begin{equation}\n\\mbox{\\boldmath $\\sigma$} = \\mathbf{E} \\mbox{\\boldmath $\\epsilon$}\n\\end{equation}\nwhere $\\mathbf{E}$ is known as the stiffness matrix. The\ncomponents of viscosity are calculated using the Smagorinsky model\nas in SFS-a1, with the filter width again set to twice the local\nelement size. Cross terms such as $\\nu_{xy}$ are based on the\nassumption that $\\nu_{xy}\\approx\\sqrt{\\nu_{xx}\\nu_{yy}}$, and thus\nare modelled as follows:\n\\begin{equation}\n\\nu_{xy}=\\sqrt{\\nu_{xx}}\\sqrt{\\nu_{yy}}= \\sqrt{4 C_{\\textrm{S}}^2\nh_x^2 |\\tilde{\\mathcal{S}}|} \\sqrt{4 C_{\\textrm{S}}^2 h_y^2\n|\\tilde{\\mathcal{S}}|} = 4 C_{\\textrm{S}}^2 |\\tilde{\\mathcal{S}}|\nh_x h_y\n\\end{equation}\nThe element size in each direction is already known in the\ncoordinate system local to the element -- this information is\ncontained in the metric $\\mathcal{M}$. If we denote the local\ncoordinate system $(\\zeta,\\eta,\\xi)$ with a dash $'$ we can write:\n\\begin{equation}\n\\mbox{\\boldmath $\\sigma$} = \\mathbf{R}^{\\textrm{T}} \\mathbf{E}'\n\\mathbf{R} \\mbox{\\boldmath $\\epsilon$} \\label{eq:Stress-shortr}\n\\end{equation}\nwhere $\\mathbf{R}$ is a rotation matrix which transforms the\nstiffness matrix from global to local coordinates. The local\nstiffness matrix $\\mathbf{E}'$ is given by:\n\\begin{equation}\n\\mathbf{E}' = 4\\rho C_{\\textrm{S}}^2 |\\tilde{\\mathcal{S}}|\n\\begin{bmatrix}\n\\frac{4}{3}h_\\zeta^2 & -\\frac{2}{3}h_\\zeta h_\\nu &\n-\\frac{2}{3}h_\\zeta h_\\xi & 0 & 0 & 0 \\\\\n-\\frac{2}{3}h_\\zeta h_\\nu & \\frac{4}{3}h_\\nu^2 &\n-\\frac{2}{3}h_\\nu h_\\xi & 0 & 0 & 0 \\\\\n-\\frac{2}{3}h_\\zeta h_\\xi & -\\frac{2}{3}h_\\nu h_\\xi &\n\\frac{4}{3}h_\\xi^2 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & h_\\zeta h_\\nu & 0 & 0 \\\\\n0 & 0 & 0 & 0 & h_\\zeta h_\\xi & 0 \\\\\n0 & 0 & 0 & 0 & 0 & h_\\nu h_\\xi \\end{bmatrix}\n\\end{equation}\nso we know all the terms in Equation \\ref{eq:Stress-shortr} except\nthe rotation matrix $\\mathbf{R}$. However, this can be calculated\nfrom the components of the known rotation matrix $\\mathbf{V}$ (the\neigenvectors of $\\mathcal{M}$), after a straightforward but\ntedious expansion and gathering of terms -- see \\cite{CMP89} for\ndetails. If the components of $\\mathbf{V}$ are given by:\n\\begin{equation}\n\\mathbf{V}=\\left[ \\begin{array}{ccc}\nl_1 & m_1 & n_1 \\\\\nl_2 & m_2 & n_2 \\\\\nl_3 & m_3 & n_3\n\\end{array} \\right]\n\\end{equation}\nthen the components of $\\mathbf{R}$ are: {\\small\n\\begin{equation}\n\\mathbf{R}= \\begin{bmatrix}\nl_1^2 & m_1^2 & n_1^2 & l_1 m_1 & m_1 n_1 & n_1 l_1 \\\\\nl_2^2 & m_2^2 & n_2^2 & l_2 m_2 & m_2 n_2 & n_2 l_2 \\\\\nl_3^2 & m_3^2 & n_3^2 & l_3 m_3 & m_3 n_3 & n_3 l_3 \\\\\n2l_1 l_2 & 2m_1 m_2 & 2n_1 n_2 &\nl_1m_2+l_2m_1 & m_1n_2+m_2n_1 & n_1l_2+n_2l_1 \\\\\n2l_2 l_3 & 2m_2 m_3 & 2n_2 n_3 &\nl_2m_3+l_3m_2 & m_2n_3+m_3n_2 & n_2l_3+n_3l_2 \\\\\n2l_3 l_1 & 2m_3 m_1 & 2n_3 n_1 & l_3m_1+l_1m_3 & m_3n_1+m_1n_3 &\nn_3l_1+n_1l_3\n\\end{bmatrix}\n\\end{equation}\n}\nWe therefore have another model, SFS-a2, which is similar to\nSFS-a1 but formulated for the Navier-Stokes equations in stress\nform.\n\n\\subsection{SFS-i isotropic model}\nSFS-i is an isotropic variant of SFS-a1, in which the filter width\nis allowed to vary in space but not direction. The purpose of this\nmodel is to allow the effects of anisotropy in the SFS model to be\nseen. Local eddy viscosity $\\nu_{\\textrm{t}}$ is calculated as\nfollows:\n\\begin{equation}\n\\nu_{\\textrm{t}} = 4 C_{\\textrm{S}}^2 |\\tilde{\\mathcal{S}}|\n\\left(\\frac{h_{\\zeta}^2+h_{\\eta}^2+h_\\xi^2}{3}\\right)^\\frac{1}{2}\n\\end{equation}\nThis is the formula recommended by Bardina et al.~\\cite{BFR80} for\na scalar viscosity to be used with an anisotropic mesh.\n\n\\subsection{Commutation errors in LES}\nCommutation errors are error terms which appear in the filtered\nNavier-Stokes equations as a result of the filtering operation not\ncommuting with differentiation. These errors occur as follows.\nRecall the definition of a filtered variable (Equation\n\\ref{eq:Les-filter}). If the filter is applied to a differential:\n\\begin{align}\n\\widetilde{\\frac{\\partial u}{\\partial x}}&= \\int_{R}\n\\frac{\\partial u(\\mathbf{x}',t)}{\\partial x}\n\\,G(\\mathbf{x}-\\mathbf{x}')\\,\\mathrm{d}\\mathbf{x}'\\nonumber\\\\\n&=\\frac{\\partial}{\\partial x}\\int_{R}u(\\mathbf{x}',t)\nG(\\mathbf{x}-\\mathbf{x}')\\,\\mathrm{d}\\mathbf{x}' -\\int_{R}\nu(\\mathbf{x}',t)\\frac{\\partial}{\\partial x}\n\\left(G(\\mathbf{x}-\\mathbf{x}')\\right)\\,\\mathrm{d}\\mathbf{x}'\\nonumber\\\\\n&=\\frac{\\partial \\tilde{u}}{\\partial x}\\:- \\int_{R}\nu(\\mathbf{x}',t)\\frac{\\partial}{\\partial x}\n\\left(G(\\mathbf{x}-\\mathbf{x}')\\right)\\,\\mathrm{d}\\mathbf{x}'\n\\end{align}\nIf the filter is invariant in space (or time, if the differential\nin question is with respect to time), the second term on the\nright-hand side is zero. Therefore the equations for the filtered\nvariables (i.e.~the LES equivalents of the mass conservation and\nNavier-Stokes equations) will resemble their unfiltered\ncounterparts only if the filter is constant in space and time. If\nthe filter is allowed to vary, error terms of the form:\n\\begin{equation}\n\\epsilon_r= \\int_{R} u(\\mathbf{x}',t)\\frac{\\partial}{\\partial r}\n\\left(G(\\mathbf{x}-\\mathbf{x}')\\right)\\,\\mathrm{d}\\mathbf{x}'\n\\label{eq:Error-term}\n\\end{equation}\nappear in both equations, where $r$ is any dimension over which\nthe filter varies. These terms are known as `commutation errors'.\n\nThe LES approach adopted in this paper takes advantage of the\nadaptive mesh capability of the FLUIDITY code by linking the\nfilter width to the local element size. The filter varies\ntherefore in both space and time. However, Ghosal \\& Moin\n\\cite{GnM95} have shown that, for an arbitrary filter, the\nmagnitude of the commutation error is second order in $\\Delta$,\nthe filter width. The numerical scheme used by FLUIDITY to solve\nthe LES equations is second-order accurate (on regular meshes), so\ncommutation error will not reduce the accuracy of these\nsimulations.\n\n\n\\subsection{Q-Scheme}\nFor the resulting viscocity to be used within the \nQ-Scheme it must be in stress form. In this way it \nmay act on the internal energy equation in much the same way \nas fluid viscocity does. However, the LES viscocity in tensor \nform must be diagonal and in this case the off diagonal \nstress terms can be obtained from \n\\begin{eqnarray}\n\\mu_{xy}=\\sqrt{\\mu_x}\\sqrt{\\mu_y}. \n\\end{eqnarray}\nIn which $\\mu_x$ is the diagonal tensor for the $u-$ momentum equation \nand  $\\mu_y$ the diagonal tensor for the $v-$ momentum equation. \nThis is also the approach taken when the viscocity is determined \nfrom the non-linear Petrov-Galerkin method in the next section. \n\n\\subsubsection{Original Q-Scheme}\nThe original Q-scheme used a volumetric viscocity of \n\\begin{eqnarray}\n\\mu_{vol}=- c_q h^2 \\rho \\; min\\{0, \\nabla\\cdot {\\bf u}\\} \\;\\; - \\;\\;c \\;c_l  h \\rho \\; min\\{0, \\nabla\\cdot {\\bf u}\\},\n\\label{original-q}\n\\end{eqnarray}\nor\n\\begin{eqnarray}\n\\mu_{vol}=- c_q h^2 \\rho \\; min\\{0, \\nabla\\cdot {\\bf u}\\} \\;\\; + \\;\\;c \\;c_l  h \\rho,\n\\label{original-q-b}\n\\end{eqnarray}\nand is often modified to: \n\\begin{eqnarray}\n\\mu_{vol}= c_q h^2 \\rho \\vert \\nabla\\cdot {\\bf u}\\vert \\;\\;-\\;\\; c\\; c_l  h \\rho \\; min\\{0, \\nabla\\cdot {\\bf u}\\}, \n\\label{original-q2}\n\\end{eqnarray}\nor\n\\begin{eqnarray}\n\\mu_{vol}= c_q h^2 \\rho \\vert \\nabla\\cdot {\\bf u}\\vert \\;\\;-\\;\\; c\\; c_l  h \\rho, \n\\label{original-q2-b}\n\\end{eqnarray}\nin which $c_q, c_l$ are scalar and in $c_q=1, c_l=0.05$ are used here, \nand $h$ is a length scale measured across each element. \nAlso the speed of sound $c$ is obtained from:\n\n\\begin{eqnarray}\n\\frac{1}{c^2} = \\frac{\\partial p}{\\partial \\rho}. \n\\label{c-def}\n\\end{eqnarray}\n\n\n\n\n\n\n\n\n\n\n\n\\vfill\\eject\n\n\n\n\\section{Non-linear Petrov Galerkin methods demonstrated using Compressibility} \n\n\n\n\n\n\n\n\n\n\n\\subsection{Summary}\nHere new methods of solving the compressible flow equations \nwhich are being developed for multi-phase flow are \napplied to simple benchmark test cases. Some of the one dimensional \ntest case results are compared against an explicit linear Discontinuous \nGalerkin (DG) Riemann solver with Roe-averaging of \nthe fluxes between the elements. \nThis method  \nis believed to be among the best performing methods  \ncurrently in the literature for these class of problems. \nThe new method has comparable accuracy grid-point for grid-point \n(although \nincreased flexibility) compared with the explicit DG methods. \n\n\n\n\\subsection{Introduction}\n\nThe Navier Stokes or Force balance (Darcy equations) and continuity \nequations are solved by using a pressure projection method. \nThe solution method is centered around a mixed finite element formulation \nthat uses the new triangle/tetrahedra element PNDG-PN+1 which has a discontinuous $N^{\\rm th}$ order polynomial for velocity and a continuous $N+1$ order polynomial for pressure. The applications use P1DG-P2. \nSaturation/volume fraction \nand density are represented on a control volume mesh - with CVs centered on the pressure nodes. \nUsing a projection method we solve for the FEM representation of \npressure and establish a mapping between this FEM representation \nand the CV representation of pressure using a mixed CV-FEM mass \nmatrix. The CV representation of pressure then allows \n the EoS's to be evaluated CV-wise. \nThe time stepping is based on the $\\theta$- method with \n$\\theta$ chosen to be as close to $\\frac{1}{2}$ as possible \nwhile ensuring a Total Variational Diminishing (TVD) \ncondition in time is satisfied. \nThis helps ensures high order \naccuracy in time while achieving physically realistic (bounded) \nsolutions. Flux limiting methods based on the Normalized Variable \nDiagram (NVD) approach \nare used to limit the fluxes of the solution \non the CV boundaries to also \nhelp ensure physical realism of the solution. \nThe high order representation on the CV boundaries is \nobtained using a consistent FEM mapping of the CV \nsolution to a FEM solution and using this FEM solution \nto represent the solution (subject to NVD flux limited) on the CV boundaries.  \n\n\n\n\\subsection{Discretised saturation equation and global mass balance} \n\nThis section outlines the discrete saturation equations and derives the global mass balance equations from the saturation equations. The resulting equation can then be solved simultaneously with the force balance or momentum equations. \n\t\t\t\t\t\t\t\t\t\t\n\n\\subsubsection{Discretised saturation equation} \n\nThe saturation equation \n\n\\begin{equation}\n\\phi\\frac{\\partial \\rho_k S_k }{\\partial t} \n+ \\nabla \\cdot {\\mathbf u}_k \\rho_k S_k = {s_{cty}}_k, \n\\end{equation}\ndiscretised by testing it with CV basis functions \n $M_i$ is and discretising in time using the \n $\\theta-$method is:\n \n\\begin{equation}\n\\int_\\Omega M_i (\\frac{\\phi{\\rho_k}_i^n ({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {\\Delta t} ) dV\n+ \\int_{\\Gamma_{CV_i}} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} \nd\\Gamma \n= \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV.\n\\label{detail-sat-eqn-k}\n\\end{equation}\n \n \n\\subsubsection{Discretised global mass balance equation} \n \nDividing equation \\ref{detail-sat-eqn-k} by ${\\rho_k}^n_i $ and summing \nover all phases one obtains the global mass balance equation: \n\n \n\\begin{equation}\n \\sum_k \\left(\n\\int_\\Omega M_i (\\frac{ \\phi({S_k}_i^{n+1}-{S_k}_i^n) }{\\Delta t} \n+ \\frac{\\phi{S_k}_i^n( {\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} {{\\rho_k}_i^n\\Delta t} ) dV\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} \n{\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta}   S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k^{n+\\theta} dV \\right) =0,\n\\label{detail-sat-eqn-k-sum}\n\\end{equation}\n\nThe saturations and densities are flux limited in space and \ntime. This uses a finite element \ninterpolation of the saturations and densities which are then limited. \n\t\t\t\n\n\nUsing $\\sum_{k=1}^{\\cal K} {S_k}_i^n =1, \\;\\; \\forall n$ and linear \n$\\rho_k^{n+1}$ about the CV pressure variation $P_{CV}^{n+1}$ then \n\n\\begin{equation}\n \\sum_k ( \\int_{\\Omega} M_i \n( \\frac{{S_k}_i^n \\frac{\\partial \\tilde{\\rho_k}_i^{n+1}}{\\partial \\tilde{ p_{CV}}_i^{n+1}}({p_{CV}}_i^{n+1}-\\tilde{p_{CV}}_i^{n+1})\n} {{\\rho_k}_i^n\\Delta t} \n+ \\frac{{S_k}_i^n( \\tilde{\\rho_k}_i^{n+1}-{\\rho_k}_i^n)} \n{{\\rho_k}_i^n \\Delta t} ) dV\n\\end{equation}\n\\begin{equation}\n+ \\frac{1}{{\\rho_k}_i^n}\\int_{{\\Gamma_{CV}}_i} {\\mathbf n} \\cdot {\\mathbf u}_k^{n+\\theta} \\rho_k^{n+\\theta} S_k^{n+\\theta} d\\Gamma\n- \\frac{1}{{\\rho_k}_i^n} \\int_\\Omega M_i {s_{cty}}_k dV ) =0.\n\\label{detail-global-cty}\n\\end{equation}\nIn matrix form this becomes:\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} \n= \\underline{\\bf s}_p. \n\\label{glob-cty-matrix}\n\\end{equation}\n\nNotice that in equation \\ref{detail-global-cty} the \ncontrol volume-wise variation of pressure ${p_{CV}}_i^n$ has been \nused and in order to get to the equation  \\ref{glob-cty-matrix} \nabove the finite element variation of pressure with basis \nfunctions $N_i$ has been used. Thus, to get to equation \n\\ref{glob-cty-matrix} the Galerkin projection\n\n\\begin{equation}\n\\int_{\\Omega} M_i (p_{CV}^n-p^n) dV =0\n\\end{equation}\nfor $p^n$ is used. This results in solving the matrix \nequation for ${\\bf p}^n$: \n\n\\begin{equation}\n{\\mathbf M}_{CV} \\underline{\\bf p}_{CV}^n = {\\mathbf N}_{CVfem} \\underline {\\bf p}^n\n\\end{equation}\nin which the matrix ${\\mathbf M}_{CV}$ is diagonal and thus \nthis can easily help form the matrix ${\\mathbf M}_p$ in equation \n\\ref{glob-cty-matrix}. \n\n\\subsubsection{Compressibility - CV and FEM pressure variations}\n\nHaving both a CV and FEM variation of pressure allows us to \nsimultaneously have an exact representation of the force balance \nequation as well as ensuring robustness of the the scheme \ne.g. positive densities from potentially complex equations \nof state. When using complex EoS's $\\frac{\\partial \\tilde { \\rho_k}_i^{n+1}}{\\partial \\tilde {p_{CV}}_i^{n+1}}$ is formed \nusing a pertabation approach, that is \nperturbing the pressure $\\tilde {p_{CV}}_i^{n+1}$ and looking how \nit effects the densities $\\tilde {\\rho_k}_i^{n+1}$. This \navoids differentiating complex EoS's. \n\n\t\t\t\t\n\n\n\n\\subsubsection{Pressure matrix equation} \n\nThe  \nglobal mass balance equation \\ref{glob-cty-matrix} and \nforce balance equations  are solved here by eliminating  \nout velocity and solving a system of equations for \npressure. \nThe force balance (at time level $n+1$) \nand global continuity equations are:\n\n\\begin{equation}\n{\\mathbf M}_\\sigma  \\underline{\\bf u}^{n+1} = {\\mathbf C} \\underline{\\bf p}^{n+1} + \\underline{\\bf s}_u^{n+1},\n\\label{force-balance-matrix-form2}\n\\end{equation}\n\n\\begin{equation}\n{\\mathbf M}_p \\underline{\\bf p}^{n+1} + {\\mathbf B}^T \\underline{\\bf u}^{n+1} = \\underline{\\bf s}_p^{n+1}. \n\\label{glob-cty-matrix2}\n\\end{equation}\n\nUsing the discontinuous velocity within an element \nformulation the matrix ${\\mathbf M}_\\sigma$ is block diagonal \nand thus easily inverted - each block being local to an element.  \nMultiplying this equation by ${\\mathbf B}^T {\\mathbf M}_\\sigma^{-1}$ \n(see global continuity \nequation \\ref{glob-cty-matrix2}) and using the global continuity \nequation to eliminate out $ \\underline{\\mathbf u}^{n+1} $ one obtains \nthe pressure equation:\n\n\\begin{equation}\n({\\mathbf B}^T {\\mathbf M}_\\sigma^{-1} {\\mathbf C} + {\\mathbf M}_p) \\underline{\\bf p}^{n+1} \n=  \\underline{\\bf s}_p^{n+1}\n- {\\mathbf B}^T {\\mathbf M}_\\sigma^{-1}\\underline{\\bf s}_u^{n+1}.\n\\end{equation}\nthis equation is solved for the pressure  $\\underline{\\bf p}^{n+1}$ and then \nthe  \nvelocity is obtained by solving \nequation \\ref{force-balance-matrix-form2}. \n\n\n\t\t\n\\subsection{Shock capturing}\n\\label{shock} \t\t\n\nSuppose the differential equation to be solved is:  \n\n\\begin{equation}\n{\\bf A}_{xt} \\cdot {\\nabla_{xt}} \\Psi \n+ {\\bf H} \\Psi ={\\bf s} \n\\label{differential-eqn-def-matrix-compact} \n\\end{equation}\nin which ${\\bf H}$ is a positive semi-definite and diagonal \nscattering-removal matrix operator. \nThus, for one dimension ${\\bf A}_{xt}=({\\bf A}_t \\;\\; {\\bf A}_x)^T$ and 3D \n${\\bf A}_{xt}=({\\bf A}_t \\;\\; {\\bf A}_x\\;\\; {\\bf A}_y\\;\\; {\\bf A}_z)^T$ and in \none dimension this equation becomes: \n\n\\begin{equation}\n {\\bf A}_t \\frac{\\partial \\Psi}{\\partial t} +\n{\\bf A}_x \\frac{\\partial \\Psi}{\\partial x}  \n+ {\\bf H} \\Psi ={\\bf s}.\n\\label{differential-eqn-def-matrix} \n\\end{equation}\nFor coupled equations \nthe projection of ${\\bf A}_{xt}$ onto ${\\nabla_{xt}} \\Psi$ may be written: \n \n \n\\begin{equation}\n {\\bf A}_{xt}^* = {{\\bf V}({\\bf A}_{xt}\\cdot{\\nabla_{xt}} \\Psi)}\n {\\bf V}({\\vert\\vert{\\nabla_{xt}} \\Psi\\vert\\vert^2_2})^{-1} {\\nabla_{xt}} \\Psi. \n\\label{a*-def-matrix} \n\\end{equation}\n Thus, \n \n\\begin{equation}\n {\\bf A}_{xt}^* \\cdot {\\nabla_{xt}} \\Psi = {\\bf A}_{xt} \\cdot {\\nabla_{xt}} \\Psi \n\\label{a*-equiv-matrix} \n\\end{equation}\n or\n\\begin{equation}\n \\left({{\\bf V}({\\bf A}_{xt}\\cdot{\\nabla_{xt}} \\Psi)}\n {\\bf V}({\\vert\\vert{\\nabla_{xt}} \\Psi\\vert\\vert^2_2})^{-1} {\\nabla_{xt}} \\Psi\n    \\right) \\cdot {\\nabla_{xt}} \\Psi = {\\bf A}_{xt} \\cdot {\\nabla_{xt}} \\Psi . \n\\label{equiv-matrix} \n\\end{equation}\nin which ${\\bf V}({\\bf g})$ is a diagonal matrix \nin which ${\\bf V}({\\bf g})_{\\mu\\mu}={\\bf g}_\\mu$ and the vector \n$\\vert\\vert{\\nabla_{xt}} \\Psi\\vert\\vert^2_2$ is such that the $\\mu^{\\rm th}$ \nentry is ${\\vert\\vert{\\nabla_{xt}} \\Psi\\vert\\vert^2_2}_\\mu = (\\nabla_{xt} \\Psi_\\mu)\\cdot (\\nabla_{xt} \\Psi_\\mu)$. \nSince the matrix ${\\bf A}_{xt}^*$ has a block diagonal structure \nthe transport equations \n${\\bf A}_{xt}^*\\cdot{\\nabla_{xt}} \\Psi+{\\bf H}\\Psi -{\\bf s}=0$ \nare a set of ${\\cal M}$ independent scalar equations \nin which the $\\mu^{\\rm th}$ scalar equation is: \n\\begin{equation}\n{a^*_t}_\\mu \\frac{\\partial \\Psi_\\mu}{\\partial t} + \n{a^*_x}_\\mu \\frac{\\partial \\Psi_\\mu}{\\partial x} + \n{a^*_y}_\\mu \\frac{\\partial \\Psi_\\mu}{\\partial y} + \n{a^*_z}_\\mu \\frac{\\partial \\Psi_\\mu}{\\partial z} + \n\\sigma_\\mu \\Psi_\\mu\n={\\bf s}_\\mu\n\\label{gov-scalar-equiv-matrix} \n\\end{equation}\nand \n${a^*_t}_\\mu={{\\bf A}^*_t}_{\\mu\\mu}$, \n${a^*_x}_\\mu={{\\bf A}^*_x}_{\\mu\\mu}$, \n${a^*_y}_\\mu={{\\bf A}^*_y}_{\\mu\\mu}$, \n${a^*_z}_\\mu={{\\bf A}^*_z}_{\\mu\\mu}$, \n$\\sigma_\\mu={\\bf H}_{\\mu\\mu}$ and $\\Psi_\\mu$ is the $\\mu^{\\rm th}$ scalar \nin the vector $\\Psi$. In equation \\ref{gov-scalar-equiv-matrix} it is \nassumed that ${\\bf H}$ is a diagonal. If it is not then the system of \nequations can be easily manipulated so as to diagonalise ${\\bf H}$, see \nsection \\ref{optimal-matrix-section}. Since the equations have been \nuncoupled then the scalar equation methods described in the \nprevious section can now be applied. This is effectively done below. \n    \n The Petrov-Galerkin's modified form of the \n differential equation is: \n \n\\begin{equation}\n ({\\bf I}- ({\\nabla_{xt}} \\cdot{{\\bf A}_{xt}^*})^T {\\bf P}_{xt}^* )({\\bf A}_{xt} \\cdot {\\nabla_{xt}} \\Psi +{\\bf H}  \\Psi -{\\bf s})={\\bf 0}. \n\\label{disc-matrix} \n\\end{equation}\n Testing equation \\ref{disc-matrix} with a diagonal matrix of \n space-time basis function ${{\\bf N}_{xt}}_i$ (this has the basis \n function ${N_{xt}}_i$ along\nits main diagonal),  \n integrating over a single element $V_E$ and applying integration \n by parts results in: \n\\begin{equation}\n \\int_{V_E} \n {{\\bf N}_{xt}}_i {\\bf r} d V_{xt} - \\int_{\\Gamma_E} {{\\bf N}_{xt}}_i \n ({\\bf n}_{xt}\\cdot{{\\bf A}_{xt}} )^- (\\Psi-\\Psi_{bc}) d \\Gamma_{xt} \n\\label{disc2-matrix-1} \n\\end{equation}\n\\begin{equation}\n +\n \\int_{V_E} (({\\nabla_{xt}} {{\\bf N}_{xt}}_i ) \\cdot{{\\bf A}_{xt}^*})^T {\\bf P}_{xt}^*  {\\bf r} d V_{xt} \n +\\int_{\\Gamma_E} {{\\bf N}_{xt}}_i {\\bf n}_{xt}\\cdot{{\\bf A}_{xt}^*}  {\\bf P}_{xt}^* {\\bf r}  d \\Gamma_{xt} \n ={\\bf 0}, \n\\label{disc2-matrix-2} \n\\end{equation}\n with a finite element expansion $\\Psi=\\sum_{j=1}^{\\cal N} {{\\bf N}_{xt}}_j \n {\\mathbf \\Psi}_j$ (where ${\\mathbf \\Psi}_j$ is the order $\\cal M$ vector of \n unknowns at node $j$) \n and ${\\bf r}={\\bf A}_{xt} \\cdot {\\nabla_{xt}} \\Psi +{\\bf H} \\Psi -{\\bf s}$. \n Using the eigen-decomposition \n ${\\bf n}_{xt}\\cdot{{\\bf A}_{xt}}={\\bf L}_{xt} {\\mathbf \\Lambda}_{xt} {\\bf R}_{xt}$ then\n $({\\bf n}_{xt}\\cdot{{\\bf A}_{xt}})^-={\\bf L}_{xt} {\\mathbf \\Lambda}_{xt}^- {\\bf R}_{xt}$  \n with ${{\\mathbf \\Lambda}_{xt}^-}_{kk} = min\\{ 0, {{\\mathbf \\Lambda}_{xt}}_{kk} \\}$. This eigen \n decomposition enables the boundary condition to be applied to incoming \n information only. \n   We apply a zero boundary \n condition for the residual ${\\bf r}={\\bf 0}$ which results in: \n \n\\begin{equation}\n \\int_{V_E}\n {{\\bf N}_{xt}}_i {\\bf r} d V_{xt} \n - \\int_{\\Gamma_E} {{\\bf N}_{xt}}_i ({\\bf n}_{xt}\\cdot{{\\bf A}_{xt}})^- (\\Psi-\\Psi_{bc}) \n d \\Gamma_{xt} \n +\n  \\int_{V_E} (({\\nabla_{xt}} {{\\bf N}_{xt}}_i ) \\cdot{{\\bf A}_{xt}^*})^T {\\bf P}_{xt}^*  {\\bf r} d V_{xt} \n ={\\bf 0}.\n\\label{disc3-matrix} \n\\end{equation}\n ${\\bf P}^*_{xt}$ is a function of ${\\bf A}^*_{xt}$ and the size and shape of the \n elements, for example: \n \n\\begin{equation}\n {\\bf P}^*_{xt} = \\frac{1}{4} (\\vert {\\bf A}_{xt}^* \\cdot {\\nabla_{xt}} {{\\bf N}_{xt}}_i \\vert )^{-1}, \n\\label{P*-matrix} \n\\end{equation} \nor using the 2 matrix norm and the space-time Jacobian matrix ${\\bf J}_{xt}$: \n\\begin{equation}\n {\\bf P}^*_{xt} = \\frac{1}{4} (\\vert\\vert {\\bf J}_{xt}^{-1} {\\bf A}_{xt}^* \\vert\\vert_2 )^{-1} .  \n\\label{p*-matrix-j} \n\\end{equation}       \nSince the matrices ${\\bf A}^*_t$,  ${\\bf A}^*_x$,    ${\\bf A}^*_y$,    ${\\bf A}^*_z$ \nthat go to make up ${\\bf A}_{xt}^* = ({{\\bf A}^*_t}^T,  {{\\bf A}^*_x}^T,    {{\\bf A}^*_y}^T,    {{\\bf A}^*_z}^T )^T$  \nare diagonal the matrix ${\\bf P}^*_{xt}$ is also diagonal. \nIn the traditional Petrov Galerkin method ${\\bf A}_{xt}^*={\\bf A}_{xt}$ in the \n above and ${\\bf P}_{xt}$ replaces ${\\bf P}_{xt}^*$. \n The finite element space-time Jacobian matrix for 3D time dependent problems \n is: \n\\begin{equation}\n {\\bf J}_{xt} =\n  \\begin{pmatrix}\n {\\bf I} \\frac{\\partial t}{\\partial t^\\prime} &\n {\\bf I} \\frac{\\partial x}{\\partial t^\\prime} &\n {\\bf I} \\frac{\\partial y}{\\partial t^\\prime} &\n {\\bf I} \\frac{\\partial z}{\\partial t^\\prime} \\\\\n {\\bf I} \\frac{\\partial t}{\\partial x^\\prime} &\n {\\bf I} \\frac{\\partial x}{\\partial x^\\prime} &\n {\\bf I} \\frac{\\partial y}{\\partial x^\\prime} &\n {\\bf I} \\frac{\\partial z}{\\partial x^\\prime} \\\\\n {\\bf I} \\frac{\\partial t}{\\partial y^\\prime} &\n {\\bf I} \\frac{\\partial x}{\\partial y^\\prime} &\n {\\bf I} \\frac{\\partial y}{\\partial y^\\prime} &\n {\\bf I} \\frac{\\partial z}{\\partial y^\\prime} \\\\\n {\\bf I} \\frac{\\partial t}{\\partial z^\\prime} &\n {\\bf I} \\frac{\\partial x}{\\partial z^\\prime} &\n {\\bf I} \\frac{\\partial y}{\\partial z^\\prime} &\n {\\bf I} \\frac{\\partial z}{\\partial z^\\prime} \n  \\end{pmatrix},\n\\label{J-matrix} \n\\end{equation}\n where the variables with $\\prime$ are the local variables and \n where ${\\bf I}$ is the ${\\cal M}\\times {\\cal M}$ identity matrix \n in which ${\\cal M}$ is the number solution variables at each DG node. \n For uniform space-time resolution with a time step size of $\\Delta t$ \n and an element size of \n $\\Delta x$ (in the x-direction), \n $\\Delta y$ (in the y-direction),\n $\\Delta z$ (in the z-direction), then: \n\\begin{equation}\n {\\bf J}_{xt} =\n  \\begin{pmatrix}\n {\\bf I} \\frac{1}{2}\\Delta t &\n {\\bf 0}  &\n {\\bf 0}  &\n {\\bf 0}  \\\\\n {\\bf 0}  &\n {\\bf I} \\frac{1}{2}\\Delta x &\n {\\bf 0}  &\n {\\bf 0}  \\\\\n {\\bf 0}  &\n {\\bf 0}  &\n {\\bf I} \\frac{1}{2}\\Delta y &\n {\\bf 0} \\\\\n {\\bf 0}  &\n {\\bf 0}  &\n {\\bf 0}  &\n {\\bf I} \\frac{1}{2}\\Delta z \n  \\end{pmatrix}.\n\\label{J-matrix-uniform} \n\\end{equation}\n In a similar way to the scalar equation, the value of \n${\\bf P}_{xt}^*$ can be adjusted to ensure \nthat the resulting value of ${\\bf P}_{xt}^* $\nis not so large that there is \nmore transport backwards than forwards in the resulting discrete\nsystem of equations by: \n\\begin{equation}\n {\\bf P}_{xt}^* = min\\{ ({\\bf H}+{\\bf E})^{-1}, \n \\frac{1}{4} (\\vert\\vert {\\bf J}_{xt}^{-1} {\\bf A}_{xt}^* \\vert\\vert_2 )^{-1} \\}.  \n\\label{p*-def-j-lim} \n\\end{equation}   \nin which the diagonal entries of the matrix ${\\bf H}+{\\bf E}$ are positive and ${\\bf E}$ \ncontains small positive numbers to avoid dividing by zero or near zero \nwhen one or more of the \ndiagonals of ${\\bf H}$ is zero or very small e.g. $1\\times 10^{-10}$. \n \nIn the above we can work with the stabilization in diffusion form with: \n \n \n\\begin{equation}\n \\int_{V_E}\n {{\\bf N}_{xt}}_i {\\bf r} d V_{xt} \n - \\int_{\\Gamma_E} {{\\bf N}_{xt}}_i ({\\bf n}_{xt} \\cdot {\\bf A}_{xt})^-  (\\Psi-\\Psi_{bc}) \n d \\Gamma_{xt} \n +\n  \\int_{V_E} ({\\nabla_{xt}} {{\\bf N}_{xt}}_i )^T {\\bf K}  {\\nabla_{xt}} \\Psi d V_{xt} \n ={\\bf 0}\n\\label{disc-xt-matrix} \n\\end{equation} \n in which the ${\\cal M}\\times {\\cal M}$ diagonal matrix containing \n the diffusion coefficients is: \n \n\\begin{equation}\n {\\bf K} = {{\\bf V}({\\bf A}_{xt}\\cdot {\\nabla_{xt}} \\Psi) {\\bf P}_{xt}^* }{\\bf V}({\\vert\\vert {\\nabla_{xt}} \\Psi \\vert\\vert^2_2})^{-1} {\\bf V}({\\bf r}).  \n\\label{nu-matrix} \n\\end{equation} \nThe resulting diagonal matrix ${\\bf K}$ can be modified to ensure \nnon-negative diffusion \nby setting any of its negative entries to zero \nor taking their absolute values. \nAlternatively one can work with the residual only, by \n replacing ${\\bf A}_{xt}\\cdot {\\nabla_{xt}} \\Psi$ with the residual ${\\bf r}$,  \n which results in: \n \n\\begin{equation}\n {\\bf K} = {{\\bf V}({\\bf r})^T {\\bf P}_{xt}^* \n {\\bf V}({\\vert\\vert {\\nabla_{xt}} \\Psi \\vert\\vert^2_2})^{-1} {\\bf V}({\\bf r})}\n\\label{nu-matrix-r2} \n\\end{equation} \n which is always positive because ${\\bf P}_{xt}^*$ is positive semi-definite \n (as well as diagonal) \n and in which ${\\bf V}({\\bf r})$ is the diagonal matrix \n containing the residual of the governing equations on its diagonal. \n Equation \\ref{nu-matrix-r2} for the diffusivity can be derived by \n re-defining ${\\bf A}_{xt}^*$ in equation \\ref{a*-def-matrix} to:\n\\begin{equation}\n {\\bf A}_{xt}^* = {{\\bf V}({\\bf r})}\n {\\bf V}({\\vert\\vert{\\nabla_{xt}} \\Psi\\vert\\vert^2_2})^{-1} {\\nabla_{xt}} \\Psi. \n\\label{a*-def-matrix-r} \n\\end{equation}\n\n\n\n \n\\subsubsection{Simplified coupled equations} \n\nAssuming time is discretised \nusing the two level $\\theta$-method: \n \n\\begin{equation}\n{\\bf r} = {\\bf A}_t \\frac{\\Psi^{n+1}-\\Psi^{n}}{\\Delta t} +\n{\\bf A} \\cdot {\\nabla} \\Psi^{n+\\theta}  \n+ {\\bf H} \\Psi^{n+\\theta}  \n-{\\bf s}^{n+\\theta} , \n\\label{eqn-def-time-disc-mat} \n\\end{equation}\nwith ${\\bf A} = ({\\bf A}_x \\;\\; {\\bf A}_y\\;\\; {\\bf A}_z)^T$ and \n$\\Psi^{n+\\theta}=\\Theta\\Psi^{n+1} + ({\\bf I}-\\Theta)\\Psi^n$ in \nwhich $\\Theta$ is a diagonal matrix containing the time \nstepping parameters and \nalso defining \n\\begin{equation}\n{\\nabla_{xt}} \\Psi= (\\frac{\\Psi^{n+1}-\\Psi^n}{\\Delta t},\\;( \\nabla  \\Psi^{n+\\theta})^T)^T. \n\\label{nabla_xt_theta-mat} \n\\end{equation}  \nUsing this definition (equation \\ref{nabla_xt_theta-mat}) \nenables the application of the \nmechanics of space-time discretisation, developed here, \nfor example:   \n\\begin{equation}\n{\\bf A}_{xt}^*= ({{\\bf A}_t^*}^T ,\\; {{\\bf A}^*}^T )^T=\n {{\\bf V}({\\bf A}_{xt}\\cdot{\\nabla_{xt}} \\Psi) }\n { {\\bf V}(\\vert\\vert {\\nabla_{xt}} \\Psi \\vert\\vert^2_2)^{-1}} {\\nabla_{xt}} \\Psi\n\\label{a*-def-simp-mat} \n\\end{equation} \nand\n \n\\begin{equation}\n {\\bf P}_{xt}^* = min\\{ ({\\bf H}+{\\bf E})^{-1}, \n \\frac{1}{4} (\\vert\\vert {\\bf J}^{-1} {\\bf A}^* \\vert\\vert_2 )^{-1} \\}. \n\\label{p*-def-simp-mat} \n\\end{equation} \n By applying diffusion only in Cartesian space \n the stabilized discrete equations in diffusion form can be written: \n\\begin{equation}\n \\int_{V_E} \n {\\bf N}_i {\\bf r} d V - \\int_{\\Gamma_E} {\\bf N}_i ({\\bf n}\\cdot {\\bf A})^- (\\Psi^{n+\\theta}-\\Psi_{bc}^{n+\\theta}) \n d \\Gamma\n +\n \\int_{{V_{E}}} ({\\nabla} {\\bf N}_i )^T {\\bf K}  {\\nabla} \\Psi^{n+1} d V\n ={\\bf 0}. \n\\label{discrete-eqn-diff-nu-simple-cartesian-mat} \n\\end{equation}\n\n\n\n\n\\subsubsection{Force balance equations}\n\\label{NS} \nThe force balace equations plus continuity can be define \nwith\n\\begin{equation}\nA_t=\n  \\begin{pmatrix}\n\\rho  &  0     & 0\\\\\n0     &  \\rho  & 0 \\\\\n0     &  0     & \\frac{\\partial \\rho}{\\partial p} \n  \\end{pmatrix}, \\;\\;\\;\nA_x=\n  \\begin{pmatrix}\n\\rho u &  0  &  1\\\\\n0     &  \\rho u & 0 \\\\ \n1     &  0  & 0 \n  \\end{pmatrix}, \\;\\;\\;\nA_y=\n  \\begin{pmatrix}\n\\rho v &  0  &  0  \\\\\n0     &  \\rho v &  1 \\\\\n0     &  1      &  0 \n  \\end{pmatrix}, \n\\label{A-matrix} \n\\end{equation}\nin which the solution vector is $\\Psi=(u \\;\\; v \\;\\; p)^T$. \n\nThe above matrices are used with the above theory \nwhich results in a diffusion matrix for each each variable. \nHowever, we set the diffusion for pressure to zero so \nas not to compromise conservation of mass and other advected variables. \nEven when we solve the governing equations in conservative form \nwe form the above matrices in order to from the resulting diffusion. \n\n \n \n\n\n\n\\subsection{Applications}\n\\label{Applications-comp} \n\nIn all the below the solution variables are \npressure, internal energy and velocity. \nThere is no flow going into or out of the domains.  \n\n\\subsubsection{Sod-Shock tube problem} \nHere the domain size is $1$ unity long and $0.1$ unit wide. \nThe domain is discretized in 2D with one triangle element in \nthe vertical and $2E$ is the horizontal in which \n$E$ represents the number of elements in the horizontal \nfor comparison purposes with the DG explicit method.  \nFor the DG explicit method a one dimension discretization is used. \nThe line out for the 2D triangular element simulation is \ntaken through the middle of the domain. \n\nThe initial conditions are $\\rho=1, p=1$ for $x\\le 0.5$ \nand $\\rho=0.125, p=0.1$ for $x> 0.5$ and the fluid \nis initially at rest. \n\nThe time step size is $1\\times 10^{-3}$ and when the \nsmall time step (CFL) is used then the \ntime step is $1\\times 10^{-4}$. The explicit DG method \nuses a time step of  $1\\times 10^{-4}$. \nOne can overstep the CFL restriction due to the implicitness \nof the schemes which is important when adaptive meshes \nwith very small elements \nare used in future applications.  \n\nThe use of conservative form of momentum is found to be important \nfor this case as seen in the convergence plots \nin figure \\ref{sod-converg-density}. \nIn the rest of the document conservative momentum options  \nare used. \n\nNotice that the accuracy of the new method is comparable \nand even slightly better than the DG solution, see figures \n\\ref{sod-40ele-density}, \\ref{sod-dg-density}. This is \nparticularly remarkable considering the fact that the new \nmethod is using triangular elements which tend to reduce \nthe solution accuracy. \n\n\\subsubsection{Modified Sod-Shock tube problem} \n\nThe time step size is $1\\times 10^{-3}$ for all applications \nhere, but otherwise has the same set up as for the Sod-shock tube problem.\nThe initial conditions are $\\rho=1, p=1, u=1$ for $x\\le 0.5$ \nand $\\rho=0.125, p=0.1, u=0$ for $x> 0.5$. \n\n\\subsubsection{123 problem} \n\nAnother test case called the 123 problem has initial \nconditions $\\rho=1, p=0.4$ and $u=-2$ for $x< 0.5$ and \n$u=2$ otherwise in a domain \n$x \\in [0,1]$ \nand \nwith boundary conditions of $u=-2$ (left) and $u=2$ right. \nThe results using 100 control volumes using state \nof the art methods are shown in \nfigure \\ref{Screenshot-123prob-res} along with the \nexact results. Notice that the total energy is \nnot as accurate as the resulting total \nenergy from the methods developed here shown in figures \n\\ref{123-prob-pd},\\ref{123-prob-ve}. In these figures we \ncompare 40 elements with 200 elements and with a time step of $1\\times 10^{-5}$ \nat $t=0.15$. \n\n\n\n\\subsubsection{Blast wave problem} \n\n\nThe initial conditions are $\\rho=1, p=0.1$. \nHowever, $p=1000$ for $x< 0.1$, $p=100$ for $x> 0.9$ and the fluid \nis initially at rest. \nThe time step size is $7.5\\times10^{-6}$ for all applications \nhere, but otherwise has the same set up as for the Sod-shock tube problem.\nThe boundary conditions are no flow into or out of the domain - that is \nwalls are present. \n\nThe results from the current state of the art solvers are shown \nin figure *** at $t=0.38$. Figures ***, *** show the results \nfrom the new method at $t=0.038$ and $t=0.039$. \n\n\n\n\\subsubsection{2D problem}\nHere we show the results of a shock problem with \nan ideal gas equation of state and initiated with \na small region in which a high pressure region is \nin the $0.25\\times0.25$ bottom corner of the \ndomain and the domain is $1\\times 1$. The \nmesh used has $40\\times40$ $\\times 2$ triangular elements \nas shown in figure \\ref{2d-pressure-mesh}. \nThe time step size if $1\\times 10^{-3}$ which has a \nCourant number based on the fastest wave speed of $0.5$. \nFigures \\ref{2d-pressure-mesh}, \nshow the pressure, the pressure and the fluid velocity, \nthe density, and internal energy at various time levels \ninto the simulation. It should be noted that much of the oscillations \nin pressure and density and due to the fact that we are \nlooking at the FEM interpolation of the CV density and pressure. \n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n%\\includegraphics[width=16.0cm]{./doc_figures/shock/sod-conv-eval}\n\\includegraphics[width=16.0cm]{./doc_figures/shock/test-sod}\n}\n\\vspace{-0.cm}\n\\vspace{-0.cm}}\n\\label{sod-converg-density}\n\\caption{ Sod shock tube density again resolution at $t=0.08$ \nfor both DG Riemann method and new P1DG-P2 scheme. \nThe reference case is an explicit DG solution with 500 elements. \nNotice that the two methods \nhave comparable accuracy with 40 elements. The \nP1DG-P2 results show the FEM interpolation of the CV density solution.}\n\\end{figure}\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=16.0cm]{./doc_figures/shock/sod-dg-0-08}\n}\n\\vspace{-0.cm}\n\\vspace{-0.cm}}\n\\label{sod-40ele-density}\n\\caption{ Sod shock tube density at $t=0.08$ for the \nreference case which is an explicit DG solution.  }\n\\end{figure}\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n%\\includegraphics[width=16.0cm]{./doc_figures/shock/sod-shock-mod-density}\n\\includegraphics[width=16.0cm]{./doc_figures/shock/test_mod}\n}\n\\vspace{-0.cm}\n\\vspace{-0.cm}}\n\\label{sod-dg-density}\n\\caption{ Modified Sod shock tube density at $t=0.25$ for the \nreference solution method which uses an explicit DG method. The \nP1DG-P2 results show the FEM interpolation of the CV density solution.  }\n\\end{figure}\n\n% ************123 problem *****************\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n%\\includegraphics[width=16.0cm]{./doc_figures/shock/sod-shock-mod-density}\n\\includegraphics[width=16.0cm]{./doc_figures/shock/Screenshot-123prob-res}\n}\n\\vspace{-0.cm}\n\\vspace{-0.cm}}\n\\label{Screenshot-123prob-res}\n\\caption{ Results at $t=0.15$ from state of the art models \nwith 100 CVs compared with the exact solution.   }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/pressure-123prob}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/density-123prob}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{123-prob-pd}\n\\caption{ 123 problem pressure and density at $t=0.15$ for \n40 and 200 elements. }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/velocity-123prob}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/int_energy-123prob}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{123-prob-ve}\n\\caption{ 123 problem velocity and internal energy \nat $t=0.15$ for 40 and 200 elements. }\n\\end{figure}\n\n\n% ************blast wave problem *****************\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n%\\includegraphics[width=16.0cm]{./doc_figures/shock/sod-shock-mod-density}\n\\includegraphics[width=16.0cm]{./doc_figures/shock/Screenshot-blast-wave-prob-res}\n}\n\\vspace{-0.cm}\n\\vspace{-0.cm}}\n\\label{Screenshot-blast-wave-prob-res}\n\\caption{ Results at $t=0.038$ from state of the art models \nwith 100 CVs compared with the exact solution.   }\n\\end{figure}\n\n%%%\n%%%   COMMENTED ... FIGURES ARE MISSING FROM THE REPO\n%%%\n\\begin{comment}\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/pressure-blast-wave-prob}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/density-blast-wave-prob}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{blast-wave--prob-pd}\n\\caption{ Blast wave problem pressure and density at $t=0.038$ for \n40 and 200 elements. }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/velocity-blast-wave-prob}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/int_energy-blast-wave-prob}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{blast-wave--prob-ve}\n\\caption{ Blast wave problem velocity and internal energy \nat $t=0.038$ for 40 and 200 elements. }\n\\end{figure}\n\n\n% ***t=0.039***\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/pressure-blast-wave-prob39}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/density-blast-wave-prob39}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{blast-wave--prob-pd39}\n\\caption{ Blast wave problem pressure and density at $t=0.039$ for \n40 and 200 elements. }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/velocity-blast-wave-prob39}\n\\hspace{-1.cm}\n\\includegraphics[width=10.0cm]{./doc_figures/shock/int_energy-blast-wave-prob39}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{blast-wave--prob-ve39}\n\\caption{ Blast wave problem velocity and internal energy \nat $t=0.039$ for 40 and 200 elements. }\n\\end{figure}\n% ******************2D************************\n\\end{comment}\n\n%%%\n%%%   COMMENTED ... FIGURES ARE MISSING FROM THE REPO\n%%%\n\n\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n%\\includegraphics[width=6.0cm,height=6.cm]{./doc_figures/shock/2d-shock-p0}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-p0}\n\\hspace{-1.cm}\n%\\includegraphics[width=6.0cm,height=6.cm]{./doc_figures/shock/2d-shock-p60}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-p60}\n\\hspace{-1.cm}\n%\\includegraphics[width=6.0cm,height=6.cm]{./doc_figures/shock/2d-shock-p90}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-p90}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)\\hspace{4.5cm}(c)}\n\\vspace{-0.cm}}\n\\label{2d-pressure-mesh}\n\\caption{ 2D shock problem showing the pressure results a) \nt=0 b) t=$6\\times 10^{-2}$ c) t=$9\\times 10^{-2}$ }\n\\end{figure}\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-pv0}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-pv60}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-pv90}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)\\hspace{4.5cm}(c)}\n\\vspace{-0.cm}}\n\\label{2d-pressure-vel}\n\\caption{ 2D shock problem showing the pressure and velocity results a) \nt=0 b) t=$6\\times 10^{-2}$ c) t=$9\\times 10^{-2}$ }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-d0}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-d60}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-d90}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)\\hspace{4.5cm}(c)}\n\\vspace{-0.cm}}\n\\label{2d-density-mesh}\n\\caption{ 2D shock problem showing the density results a) \nt=0 b) t=$6\\times 10^{-2}$ c) t=$9\\times 10^{-2}$ }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-e0}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-e60}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-e90}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)\\hspace{4.5cm}(c)}\n\\vspace{-0.cm}}\n\\label{2d-internal-energy-mesh}\n\\caption{ 2D shock problem showing the internal energy results a) \nt=0 b) t=$6\\times 10^{-2}$ c) t=$9\\times 10^{-2}$ }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-g0}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-g60}\n\\hspace{-1.cm}\n\\includegraphics[width=7.0cm]{./doc_figures/shock/2d-shock-g90}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{4.5cm}(b)\\hspace{4.5cm}(c)}\n\\vspace{-0.cm}}\n\\label{2d-graphs}\n\\caption{ 2D shock problem showing all the results on a \ngraph plotted through the diagonal from bottom left to top right \ncorners of the domain at a) \nt=0 b) t=$6\\times 10^{-2}$ c) t=$9\\times 10^{-2}$ }\n\\end{figure}\n\n\n\n\n\n\n\\subsection{Conclusions} \nThe new multi-phase flow numerical methods have been \ntested for compressible applications using the \nnew P1DG-P2 element. Their performance \nis comparable with the best methods currently available \nfor these class of problems. \n\n\n\n\n\\vfill\\eject\n\n\n\n\\section{The discrete free surface equations}\n\\noindent The momentum equation are tested with the velocity \nbasis functions $N_i$ (see equation \\ref{ns-dis-2}) and the continuity equation tested \nwith the pressure basis functions $M_i$. All test functions/matrices \nshown here and surface normals are evaluated at a best guess to \ntime level $n+\\frac{1}{2}$ mid way \nbetween time level $n$ and $n+1$. At the start of the time \nstep these are evaluated at time level $n$. \nThe resulting discrete momentum equation using $\\theta$-time stepping then becomes: \n\n\\begin{equation}\n\\frac{M_u}{\\Delta t}u_*^{n+1}+Au_*^{n+1}=  C_{\\theta_c} {\\hat p}_*^{n+1}\n+C_{1-\\theta_c} {\\hat p}^n+s_u\n\\label{eq1}\n\\end{equation}\n\\begin{equation}\n\\frac{M_u}{\\Delta t}u^{n+1}+Au_*^{n+1}=C_{\\theta_c} {\\hat p}^{n+1}\n+C_{1-\\theta_c} {\\hat p}^n+s_u\n\\label{eq2}\n\\end{equation}\nwhere $M_u$ dependent on the type of elements is the velocity mass matrix (can be consistent \nfor the $P1_{DG}-P2$ element because of its block structure), \n$u$ and $p$ is the velocity and pressure variables respectively, \n$u_*$ is an approximation to $u$ and calculated from the \npressure at the previous time level, \n$s_u$ is the source term, $n$ is the time level, $\\theta_c$ controls \nthe time stepping method for the pressure term/continuity equation \n($\\theta_c=\\frac{1}{2}$ is Crank-Nickolson time stepping and \n$\\theta_c=1$ is backward Euler) \nand $\\Delta t$ is the time step size. $M_u$ will also contain the \nimplicit treatment of the absorption matrix and possibly the diagonal or block-diagonal \npart of \nthe viscosity matrix which are to be treated implicitly in pressure. See \nthe next section on conditioning of the system of equations. \n\n\\noindent Subtracting (\\ref{eq1}) from (\\ref{eq2}), yields\n\\begin{equation}\n\\frac{M_u}{\\Delta t}(u^{n+1}-u_*^{n+1})= C_{\\theta_c} ({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{u-eqn}\n\\end{equation}\n\\noindent Multiplying (\\ref{eq3}) by $C_{\\theta_c}^T (\\frac{M_u}{\\Delta t})^{-1}$, yields\n\\begin{equation}\nC_{\\theta_c}^T (u^{n+1}-u_*^{n+1})=\nC_{\\theta_c}^T \\left(\\frac{M_u}{\\Delta t}\\right)^{-1} \nC_{\\theta_c} ({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{eq3}\n\\end{equation}\n\n\\noindent The free surface kinematic boundary conditions are\n\\begin{equation}\n n_g\\frac{\\partial \\xi}{\\partial t} = \\bmn \\cdot \\bmu\n\\label{FSeq1-1}\n\\end{equation}\n\\noindent The discrete form of (\\ref{FSeq1-1}) is written\n\\begin{equation}\n M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t} = \nG_{{\\theta_{pf}}}^T u^{n+1}  +G_{{1-\\theta_{pf}}}^T u^{n} \n\\label{FSeq2}\n\\end{equation}\nwhere $n_g=\\bmn\\cdot \\bmn_z$,  \n$M_{s,ij}=\\int_{\\Gamma_{Free Surface}}n_gM_iM_j d \\Gamma$ \n and $G_{\\theta_{pf} ij}=\\int_{\\Gamma_{Free Surface}}\\theta_{pf} \\bmn  N_iM_j d \\Gamma $, \n $G_{(1-\\theta_{pf}) ij}=\\int_{\\Gamma_{Free Surface}}(1-\\theta_{pf}) \\bmn  N_iM_j d \\Gamma $, \n ${C_{\\theta_c}}_{ij}=-\\int_\\Omega N_i \\theta_c \\nabla M_j d V$, \n ${C_{(1-\\theta_c)}}_{ij}=-\\int_\\Omega N_i (1-\\theta_c) \\nabla M_j d V$, \n and $\\theta_{pf}$ is the time stepping parameter associated with the free surface. We have \n also used the fact that the pressure is zero on the free surface \n and thus ${\\hat p}=g\\xi$. \n$\\Gamma_{Free Surface}$ is the free surface. \nIf $G_{\\theta_{pf}}=G_{(1-\\theta_{pf})}=0$ then the system \nof equations would enforce incompressibility with weakly enforced no normal flow \nboundary conditions. \n\n\\noindent  \nThe discrete continuity equation can be written: \n\\begin{equation}\nC_{\\theta_c}^T u^{n+1}+C_{1-\\theta_c}^T u^{n}\n +G_{{\\theta_{pf}}}^T u^{n+1}  +G_{{1-\\theta_{pf}}}^T u^{n} =0\n\\label{Ceq2}\n\\end{equation}\nor using equation \\ref{FSeq2}: \n\\begin{equation}\nC_{\\theta_c}^T u^{n+1}+C_{1-\\theta_c}^T u^{n}\n+M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t}=0\n\\label{Ceq3}\n\\end{equation}\nSubstituting (\\ref{Ceq3}) into (\\ref{eq3}), yields       \n\\begin{equation}\n-C_{1-\\theta_c}^T u^{n}\n-M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t}-C_{\\theta_c}^T u_*^{n+1}\n=\nC_{\\theta_c}^T \\left(\\frac{M_u}{\\Delta t}\\right)^{-1}C_{\\theta_c} \n({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{Ceq4}\n\\end{equation}\nRe-arranging (\\ref{Ceq4}): \n\n\\begin{eqnarray}\n&&\\left(C_{\\theta_c}^T \nM_u^{-1}C_{\\theta_c}  \n+ \\frac{M_s}{g (\\Delta t)^2}\\right) \\Delta {\\hat p} =  \\nonumber\\\\ \n&& -\\frac{\nC_{\\theta_c}^T u^{n+1}_*+C_{1-\\theta_c}^T u^{n}\n}{\\Delta t}\n-\\frac{M_s}{g (\\Delta t)^2}({\\hat p}_*^{n+1}-{\\hat p}^{n})\n\\label{Ceq5}\n\\end{eqnarray}\nand ${\\hat p}^{n+1}={\\hat p}_*^{n+1}+\\Delta {\\hat p}$. This algorithm \nis repeated until $\\Delta {\\hat p}$ is sufficiently small. \nOnce ${\\hat p}^{n+1}$ is calculated then equation \\ref{u-eqn} \nis used to solve for the velocity $u^{n+1}$.\n\n\n\n\n\n\n\\vfill\\eject\n\n\n\n\\section{Solid-fluid coupling using the immersed body method} \n\n\n\n\\subsection{Fluid velocity or moment equation} \nHere our aim continues to be to solve a set of equations \nfor pressure even within the solid and in these situations \nthe pressure matrix must not disappear and be well possed. \nWe will thus proceed by writing the momentum equation \nacross the entire domain and then divide through by the \nfluid volume fraction before discretizing the momentum equation. \n\nThe momentum equation partially discretized in time is:\n\n\\begin{eqnarray}\n\\alpha_f ( \\rho_f (\\frac{u_f^{n+1}-u_f^n}{\\Delta t})\n+ \\rho_f u_f\\cdot \\nabla u_f \n+\\nabla (p+\\tau)  -s_c -\\rho_f g k)=0\n\\label{mom-for-div-by-apha}\n\\end{eqnarray}\n\nin which $s_c$ contains exchange forces between the \nsolid and fluid due to the viscous terms. \n\nFor Gidaspow's model B the momentum equations written in conservative form are: \n\n\\begin{eqnarray}\n(\\frac{\\alpha_f^{n+1} \\rho_f^{n+1} u_f^{n+1}-\\alpha_f^{n} \\rho_f^{n} u_f^n}{\\Delta t})\n+ \\nabla \\alpha_f \\rho_f u_f\\cdot u_f \n+\\nabla (p+\\tau)  -s_c -\\rho_f g k=0. \n\\label{mom-for-div-by-apha-modelB}\n\\end{eqnarray}\nThis is the system of equations used for momentum. \n\nFor $\\alpha_f^{n+1}=1-\\alpha_s^{n+1}$ we may use the expression, suitable for incompressible solids: \n\\begin{eqnarray}\n\\alpha_s^{n+1}= \\alpha_s^{n} - \\Delta t \\nabla \\cdot \\alpha_s u_s\n\\end{eqnarray}\nto obtain: \n\\begin{eqnarray}\n(\\frac{\\alpha_f^{n} \\rho_f^{n+1} u_f^{n+1}-\\alpha_f^{n} \\rho_f^{n} u_f^n}{\\Delta t})\n+\\rho_f^{n+1} u_f^{n+1} (\\nabla \\cdot \\alpha_s u_s) \n+ \\nabla \\alpha_f \\rho_f u_f\\cdot u_f \n+\\nabla (p+\\tau)  -s_c -\\rho_f g k=0, \n\\label{mom-for-div-by-apha-modelB-with-grad}\n\\end{eqnarray}\nor: \n\\begin{eqnarray}\n(\\frac{\\alpha_f^{n} \\rho_f^{n+1} u_f^{n+1}-\\alpha_f^{n} \\rho_f^{n} u_f^n}{\\Delta t})\n+\\rho_f^{n+1} u_f^{n+1} (\\nabla \\cdot (\\hat u - \\alpha_f u_f)) \n+ \\nabla \\alpha_f \\rho_f u_f\\cdot u_f \n+\\nabla (p+\\tau)  -s_c -\\rho_f g k=0. \n\\label{mom-for-div-by-apha-modelB-with-grad-or}\n\\end{eqnarray}\n\n\\subsubsection{Form of the solid-fluid coupling source term $s_c$}\nIn order to write equation \\ref{mom-for-div-by-apha} \nthe solid-fluid coupling source term must be expressed \nas $\\alpha_f s_c$. \nThis source term has the form expressed as a discretized equation \nfor the solid as: \n\n\\begin{eqnarray}\n\\int_{V_s} N_i^s (\\alpha_f s_c)^s dV= \\int_{\\Gamma_s} N_i^s \\tau d\\Gamma = \\int_{\\Gamma_s} N_i^s \\gamma (u^s_f - u^s_s) d\\Gamma\n\\end{eqnarray}\nwith say $(\\alpha_f s_c)^s=\\sum_j N_j^s (\\alpha_f s_c)^s_j$ \nand $\\tau$ just contains the viscous components of force \non the surface of the solid. The force $(\\alpha_f s_c)^s$ is \nthen mapped onto the fluids mesh forming $(\\alpha_s(\\alpha_f s_c))^f$ \nin which $\\alpha_s$ acknowledges the volume fraction of the \nsolid which is automatically incorporated into \na field if it is mapped from the solid mesh \nto the fluid mesh. \n\nWe need to determine $s_c^f$ (assuming it has a FEM expansion \n$s_c^f=\\sum_j N_j^f {s_c^f}_j$ on the fluids mesh and we \ndo this simply with: \n\n\\begin{eqnarray}\n{s_c^f}_i= \\frac{(\\alpha_s(\\alpha_f s_c))^f_i}{{\\alpha_f}_i}\n\\label{divid-f-by-alpha-f}\n\\end{eqnarray}\n\nHowever, it is important to note that the integral we \nmust conserve is: \n\n\\begin{eqnarray}\n\\int_V (\\alpha_s(\\alpha_f s_c))^f dV.\n\\end{eqnarray}\nThus, one can move the interface slightly as long as this expression \nis conserved so that it moves into a area in which there is a \nlarger volume fraction of fluid $\\alpha_f$ and thus we \ncan divide through $(\\alpha_s(\\alpha_f s_c))^f$ by $\\alpha_f$ as in equation \n\\ref{divid-f-by-alpha-f}. If the force is moved to a neighbouring cell/node \nthen one must adjust its force according to the volume ration \nof the two cells/nodes. That is if the force is moved \nfrom cell/node $k$ to $i$ then: \n\\begin{eqnarray}\n{s_c^f}_i= \\frac{{M_l}_i}{{M_l}_k} \\frac{(\\alpha_s(\\alpha_f s_c))^f_k}{{\\alpha_f}_i}. \n\\label{divid-f-by-alpha-f-moved}\n\\end{eqnarray}\nAnother possible way to approx the surface integral that we want on the \nfluids mesh is to map it onto a thin shell of elements surrounding the solid. \nWe then map this thin shell to the fluids. \nThis also has the advantage that we can always divide the resulting force by the \nvolume fraction of the fluid as the fluid volume fraction will be non-zero. \nThis then avoids the need to use equation \\ref{divid-f-by-alpha-f-moved}. \n\n\nIn addition where there there is no fluid $\\alpha^f_f=0$ then \nwe can apply the zero force $\\alpha^f_f s_c^f$ with:\n\\begin{eqnarray}\n{s_c^f}_i= \\hat\\sigma ({u^f_f}_i-u^f_i)\n\\label{zero-f}\n\\end{eqnarray}\nand bearing in mind that \n\\begin{eqnarray}\n\\hat\\sigma (u_f-u)\n= \\hat\\sigma (u_f - (\\alpha_f u_f +\\alpha_s u_s) ) \n= \\hat\\sigma \\alpha_s(u_f-u_s) \n\\end{eqnarray}\nthis has the effect of relaxing \nthe fluid velocity to the solid velocity. \nThe zero condition \\ref{zero-f} \nmay be used to provide an upper bound \non ${s_c^f}_i$ in equation \\ref{divid-f-by-alpha-f-moved} using: \n\\begin{eqnarray}\n{s_c^f}_i= min_{abs}\\{ \\frac{{M_l}_i}{{M_l}_k} \\frac{(\\alpha_s(\\alpha_f s_c))^f_k}{{\\alpha_f}_i},  \\hat\\sigma \\alpha_s(u_f-u_s)  \\} \n\\label{divid-f-by-alpha-f-moved-limited}\n\\end{eqnarray}\nin which $min_{abs}$ chooses the number with the \nminimum absolute value and uses that number. \nWithin equation \\ref{divid-f-by-alpha-f-moved-limited} we choose \nwithin the solid when ${\\alpha_f}_i$ the limiting case: \n\\begin{eqnarray}\n{s_c^f}_i=  \\hat\\sigma \\alpha_s(u_f-u_s). \n\\label{s-c-simple}\n\\end{eqnarray}\n\n\nWe can treat $s_c$ implicitly simply by using:\n\n\\begin{eqnarray}\ns_c= s_c \\left( \\frac{u^f_f - u^f}{u^f_f - u^f}\\right). \n\\label{imp-s-c}\n\\end{eqnarray} \nThis may then be treated implicitly in pressure or \nexplicitly in pressure and implicitly in momentum. \n\n\n\n\\subsection{Solids equation} \nThe solid equation discretised \non the immersed solid mesh is:\n\n\n\\begin{eqnarray}\n\\int_{V_s} N_i ({\\cal L} u - \\rho_s g k)\n+\\int_{\\Gamma_s} N_i n (p+\\tau)d\\Gamma=0\n\\label{solids-forced}\n\\end{eqnarray}\nand for model B this equation becomes:\n\\begin{eqnarray}\n\\int_{V_s} N_i ({\\cal L} u - (\\rho_s-\\rho_f) g k)\n+\\int_{\\Gamma_s} N_i n (p+\\tau)d\\Gamma=0\n\\label{solids-forced-modelB}\n\\end{eqnarray}\n\nin which the surface integral contain the forces \nexerted by the fluid on the solid and is also \nused to form the source $s_c$ after mapping to the fluid mesh. \n\n\\subsection{Supplementary equation}\nSince it is difficult to imbed the solids equations into \nthe fluids equations. Hee we achieve the coupling with the \nintroduction of the equation:\n\n\\begin{eqnarray}\n\\hat\\sigma (\\hat u^f - u_f^f) = \\hat\\sigma( u_s^s-u_f^s)\n\\label{sigma-hat-eqn}\n\\end{eqnarray}\n\nin which $\\hat\\sigma=\\frac{\\rho_f}{\\Delta t}$. \n\nThe continuity equation can then expressed as \n\n\\begin{eqnarray}\n\\nabla \\cdot \\hat u^f=0\n\\end{eqnarray}\n\nwith as before the bulk velocity defined:\n\n\\begin{eqnarray}\n\\hat u^f=\\alpha_f u_f^f + \\alpha_s u_s^f= \\hat u_f^f + \\hat u_s^f\n\\end{eqnarray}\n\nNotice that if $u_s^s$ is mapped from the solids mesh to \nthe fluids mesh we get $\\hat u_s^f$. \n\nThus, from equation \\ref{sigma-hat-eqn} when $\\alpha_f=1$, $\\alpha_s=0$ \nthen $\\hat u^f=u_f^f$ and when $\\alpha_f=0$, \n$\\alpha_s=1$ then $\\hat u^f=u_s^f$.  \n\n\n\\subsection{Pressure equation}\nHere we derive the pressure equation. \n\nIt will be useful to remind ourselves that if:\n\\begin{equation}\nA=\n\\begin{pmatrix}\n a & b \\\\ c & d\n\\end{pmatrix} \n\\end{equation}\n\nthen\n\\begin{eqnarray}\nA^{-1} =\\frac{1}{ad-bc}\n\\begin{pmatrix}\n  d & -b \\\\ -c & a \n\\end{pmatrix} \n\\end{eqnarray}\n\nThe coupling matrix $M_c$ between between $u_f^f$ and $\\hat u$ is\n\n\\begin{eqnarray}\nM_c \n\\begin{pmatrix}\nu_f^f \\\\ \\hat u^f\n\\end{pmatrix}  \n=\n\\begin{pmatrix}\n\\frac{\\rho_f}{\\Delta t}  & 0 \\\\ \n-\\hat\\sigma  &\\hat\\sigma \n\\end{pmatrix} \n\\begin{pmatrix}\nu_f^f \\\\ \\hat u^f\n\\end{pmatrix}  \n\\end{eqnarray}\n\nand thus:\n\n\\begin{eqnarray}\nM_c^{-1}=\\frac{1}{ \\frac{\\hat\\sigma\\rho_f}{\\Delta t}} \n\\begin{pmatrix}\n\\hat\\sigma  & 0 \\\\ \n \\hat\\sigma  & \\frac{\\rho_f}{\\Delta t} \n\\end{pmatrix}  \n\\end{eqnarray}\n\nThus, the pressure equation becomes:\n\n\\begin{eqnarray}\n(0 \\;\\; C^T) {\\bf M}_c^{-1} \n\\begin{pmatrix}\n C \\\\ 0  \n\\end{pmatrix}  \n\\underline{\\Delta p} \n= \\frac{1}{\\Delta t} \nC^T M_{\\rho L}^{-1} C \\underline{\\Delta p}= - C^T \\underline{ \\hat u^f }\n\\label{delt-p-classic27}\n\\end{eqnarray} \nwith diagonal entries of ${M_{\\rho L}}_{ii}=\\int_V N_i \\rho_f dV$.\n\nThus, this equation is identical to the previous pressure equation. \n\n\\subsection{Traditional immersed boundary forcing} \nIf one is willing to use the traditionally used \nsource term for momentum of the immersed boundary \napproach then we obtain a formulation very similar to the \nimmersed boundary approach but with the correct \nrepresentation of inertia and viscosity. \nThis force is:\n\n\\begin{eqnarray}\n\\alpha_f^f s_c^f = \\alpha_f \\hat\\sigma (u^f_f -u^f)\n\\label{immersed-bc-force-traditional}\n\\end{eqnarray}\nand thus $\\alpha_f^f s_c^f = \\alpha_f^f \\hat\\sigma \\alpha_s^f (u^f_f -u^f_s)$  \nand for the solids the source term becomes \n(replacing the term involving $\\tau$ in equation \\ref{solids-forced}): \n\n\\begin{eqnarray}\n\\alpha_f^s s_c^s=\\hat \\sigma (u_s^s -u^s)\n\\label{immersed-bc-force}\n\\end{eqnarray}\nand thus \n$ \\alpha_f^s s_c^s=\\hat \\sigma \\alpha_f^s(u_s^s -u^s_f)$.\n\nThe latter equation \\ref{immersed-bc-force} on mapping to the fluids becomes:\n\\begin{eqnarray}\n\\alpha_f^f s_c^f=\\hat \\sigma \\alpha_s^f (u_s^f -u^f)\n=\\hat\\sigma \\alpha_s^f \\alpha_f^f(u_s^f -u^f_f)\n\\end{eqnarray} which \nis equal and opposite to the force applied to the fluids \\ref{immersed-bc-force-traditional}. \n\nNotice that we can divide equation \\ref{immersed-bc-force-traditional} \nthus making it compatible with equation \\ref{mom-for-div-by-apha} in which we need to \ndivide by the volume fraction $\\alpha_f^f$ in order to solve this equation \nwithin the solid. \nNotice that from equation \\ref{sigma-hat-eqn} in the solid $u^f=u^f_s$ and thus this \nin the solid the force applied by equation \\ref{immersed-bc-force} is zero. \n\n\n\\subsection{The continuity equation and mass balance} \n\nHere we develop the equations so that the fluid feels the presence of the solid through \nthe solids displacement. \nThe continuity equation for incompressible solid is: \n\n\\begin{eqnarray}\n\\frac{ \\alpha_s^{n+1} -\\alpha_s^n}{\\Delta t} + \\nabla\\cdot \\alpha_s^{n+1} u_s^{n+1} =0\n\\label{solid-cty-excat}\n\\end{eqnarray} \nand for each fluid phase, $k$ with $ k\\in\\{1,2,...,{\\cal P}\\}$, is: \n\n\n\\begin{eqnarray}\n\\frac{ \\rho_k^{n+1} \\alpha_k^{n+1} -\\rho_k^{n}\\alpha_k^n}{ \\rho_k^{n+1}\\Delta t} \n+ \\frac{1}{\\rho_k^{n+1} } \\nabla\\cdot (\\theta \\rho_k^{n+1} \\alpha_k^{n+1} u_k^{n+1}+(1-\\theta) \\rho_k^{n} \\alpha_k^{n} u_k^{n}) =0. \n\\end{eqnarray} \n\nSumming all these equations the global continuity equation is and using the fact that $ \\alpha_s^{n+1}+\\sum_k\\alpha_k^{n+1}=1$ in the time \nderivative and using $\\alpha_s^{n+1} u_s^{n+1}=\\hat u_f^{n+1} - \\sum_k\\alpha_k^{n+1} u_k^{n+1}$, then: \n\\begin{eqnarray}\n{\\cal{R}}_{cty} =\\frac{1-\\alpha_s^n}{\\Delta t} + \n\\frac{1}{\\Delta t} \\sum_k\\{ \n\\frac{  - \\alpha_k^n\\rho_k^{n}} {\\rho_k^{n+1}} \n-  \\frac{\\partial \\rho_k^{n+1}}{\\partial p_{CV}^{n+1}} (p_{CV}^{n+1}-\\tilde{p}_{CV}^{n+1}) \\alpha_k^{n+1} \\}\n\\\\\n+ \n\\{ \n\\frac{1}{\\rho_k^{n+1} } \\nabla\\cdot (\\theta \\rho_k^{n+1} \\alpha_k^{n+1} u_k^{n+1}+(1-\\theta) \\rho_k^{n} \\alpha_k^{n} u_k^{n}) \n+\\left[ \\nabla\\cdot\\alpha_s^{n+1} u_s^{n+1} \\right] \\} \n=0, \n\\end{eqnarray} \nor in an alternative form using $\\alpha_s^{n+1} u_s^{n+1}=\\hat u_f^{n+1} - \\sum_k\\alpha_k^{n+1} u_k^{n+1}$, then:\n\\begin{eqnarray}\n{\\cal{R}}_{cty} =\\frac{1-\\alpha_s^n}{\\Delta t} + \n\\frac{1}{\\Delta t} \\sum_k\\{ \n\\frac{  - \\alpha_k^n\\rho_k^{n}} {\\rho_k^{n+1}} \n-  \\frac{\\partial \\rho_k^{n+1}}{\\partial p_{CV}^{n+1}} (p_{CV}^{n+1}-\\tilde{p}_{CV}^{n+1}) \\alpha_k^{n+1} \\}\n\\\\\n+ \n\\{ \n\\frac{1}{\\rho_k^{n+1} } \\nabla\\cdot (\\theta \\rho_k^{n+1} \\alpha_k^{n+1} u_k^{n+1}+(1-\\theta) \\rho_k^{n} \\alpha_k^{n} u_k^{n}) \n+\\left[ \\nabla\\cdot\\hat u_f^{n+1} - \\sum_k \\nabla\\cdot \\alpha_k^{n+1} u_k^{n+1} \\right] \\} \n=0. \n\\label{cty-solid-impl-fluid} \n\\end{eqnarray} \nin which $\\tilde{p}_{CV}^{n+1}$ is the best guess for ${p}_{CV}^{n+1}$, for example on the first iteration of a \ntime step  $\\tilde{p}_{CV}^{n+1} ={p}_{CV}^{n}$. \nThe first term on the left and the last terms on the right are the new terms introduced into the solid-fluid coupling equations. \nAlternatively, one may assume that the solid phase continuity equation \\ref{solid-cty-excat}  has been enforced \nby the solid mechanics model or a compromise defined by the variable $\\theta_{solid-cty}$ in which \n$\\theta_{solid-cty}=1$ is the method outlined by equation \\ref{cty-solid-impl-fluid} and $\\theta_{solid-cty}=0$ \nenforces this new method where:\n\n\\begin{eqnarray}\n{\\cal{R}}_{cty} =\\frac{1-\\theta_{solid-cty}\\alpha_s^n  -(1-\\theta_{solid-cty})\\alpha_s^{n+1} }{\\Delta t} + \n\\frac{1}{\\Delta t} \\sum_k\\{ \n\\frac{  - \\alpha_k^n\\rho_k^{n}} {\\rho_k^{n+1}} \n-  \\frac{\\partial \\rho_k^{n+1}}{\\partial p_{CV}^{n+1}} (p_{CV}^{n+1}-\\tilde{p}_{CV}^{n+1}) a_k^{n+1} \\}\n\\\\\n+ \n\\{ \n\\frac{1}{\\rho_k^{n+1} } \\nabla\\cdot (\\theta \\rho_k^{n+1} \\alpha_k^{n+1} u_k^{n+1}+(1-\\theta) \\rho_k^{n} \\alpha_k^{n} u_k^{n}) \n+\\theta_{solid-cty}\\left[ \\nabla\\cdot\\hat u_f^{n+1} - \\sum_k \\nabla\\cdot \\alpha_k^{n+1} u_k^{n+1} \\right] \\} \n=0. \n\\label{cty-solid-half-impl-fluid} \n\\end{eqnarray} \nin which $a_k^{n+1}=\\alpha_k^{n+1}$. \nHowever, in the limit as the volume fraction of a compressible \nfluid approaches 0 and we get a pure solid and that is the sytem of equations for density/pressure \nof the fluid can become ill posed. This can be seen if one considers the system of equations of an ideal gas \nin which case the negative pressures that could form in the solid will result in negative densities. This is easily \navoided by setting: \n\\begin{eqnarray}\na_k^{n+1}=\\frac{\\alpha_k^{n+1}}{1-\\alpha_s^{n+1}}\n\\label{a-1} \n\\end{eqnarray} \nFor single phase flow this becomes: \n\\begin{eqnarray}\na_k^{n+1}=1. \n\\label{a-2} \n\\end{eqnarray} \nThen the system of equation become well posed and there is no longer this issue. \n\n\n\n\n\nIn matrix form equation \\ref{cty-solid-half-impl-fluid} becomes: \n\\begin{eqnarray}\n{r}_{cty}^* =M_p \\frac{p^{n+1}}{\\Delta t} + \\tilde B^T \\hat u_f^{n+1} + B^T u^{n+1} + res_{cty} . \n\\end{eqnarray} \n\nThus, in this multi-phase flow case the coupling matrix $M_c$ between between $u_f^f$ and $\\hat u$: \n\n\\begin{eqnarray}\nM_c \n\\begin{pmatrix}\nu^{n+1} \\\\ \\hat u_f^{n+1}\n\\end{pmatrix}  \n=\n\\begin{pmatrix}\nM_\\rho  & 0 \\\\ \n-\\hat N  & I \n\\end{pmatrix} \n\\begin{pmatrix}\nu^{n+1} \\\\ \\hat u_f^{n+1} \n\\end{pmatrix}  , \n\\end{eqnarray}\nand $u^{n+1}$ is the vector containing the solution variables for each phase $u_k^{n+1}$, that is: \n\n\\begin{eqnarray}\nu^{n+1}= \n\\begin{pmatrix}\nu^{n+1}_1 \\\\ u^{n+1}_2 \\\\ \\vdots \\\\ u^{n+1}_{\\cal P}\n\\end{pmatrix}  , \n\\end{eqnarray}\nand thus:\n\n\\begin{eqnarray}\nM_c^{-1}=\n\\begin{pmatrix}\nM_\\rho^{-1}  & 0 \\\\ \n\\hat N M_\\rho^{-1}   & I \n\\end{pmatrix}  . \n\\end{eqnarray}\nThus, the pressure equation becomes:\n\n\\begin{eqnarray}\n\\left( M_p + (B^T \\;\\; \\hat B^T) { M}_c^{-1} \n\\begin{pmatrix}\n C \\\\ 0  \n\\end{pmatrix}  \\right) \n\\underline{\\Delta p} \n= \n\\left( M_p +(B^T+ \\tilde B^T \\hat N) M_{\\rho}^{-1} C \\right) \\underline{\\Delta p}= -{r}_{cty}^*  .\n\\label{delt-p-classic27-phase}\n\\end{eqnarray} \nHere we replace $\\tilde B^T \\hat N$ with $\\hat B^T$ which is an approximation and thus the \npressure matrix equation becomes:\n\\begin{eqnarray}\n\\left( M_p +(B^T+ \\hat B^T) M_{\\rho}^{-1} C \\right) \\underline{\\Delta p}= -{r}_{cty}^{*} ,\n\\label{delt-p-classic27-phase}\n\\end{eqnarray} \nin which $\\hat B^T u^{n+1}$ is a discretization of $\\sum_k ( \\nabla\\cdot \\hat\\alpha_k^{n+1} u_k^{n+1} )$ \nand $\\hat\\alpha_k^{n+1} =\\frac{max( \\epsilon, \\alpha_k^{n+1}) } {\\sum_k max( \\epsilon, \\alpha_k^{n+1}) }$ \nand thus $\\sum_{k=1}^{\\cal P} \\hat\\alpha_k^{n+1} =1$. \nHere $\\epsilon=1\\times 10^{-7}$. In addition, \n\n\\begin{eqnarray}\n\\hat N = \\left( \\underline{\\underline{\\hat\\alpha_1^{n+1}}} \\;\\;\\; \\underline{\\underline{\\hat\\alpha_2^{n+1}} } \\;\\;\\;... \\;\\;\\;  \\underline{\\underline{\\hat\\alpha_{\\cal P}^{n+1}} }  \\right) , \n\\end{eqnarray} \nin which $ \\underline{\\underline{\\hat\\alpha_k^{n+1}}}, \\forall k\\in\\{1,2,...,{\\cal P}\\} $ \nare diagonal matricies with entries equal to the control volume values of   ${\\hat\\alpha_k^{n+1}} $ \nand $\\cal P$ is the number of phases. For a single phase system $\\hat N = I$.\n\n\n\n\n\n\n\\subsection{Implementation of solid-fluid velocity coupling boundary conditions through viscocity}\n\n\nThe stress conditions discretized is: \n\n\\begin{eqnarray}\n\\int N_i \\nabla \\cdot \\underline{\\underline{\\tau}} dV = \n-\n\\int N_i \\nabla \\cdot \\underline{\\underline{\\tau}} dV \n+ \\int_{\\Gamma_{solid}} N_i n\\cdot \\underline{\\underline{\\tau}}_{solid} d\\Gamma\n=\\int N_i \\nabla \\cdot \\tau dV\n+ \\int_{\\Gamma_{solid}} N_i n\\cdot (\\underline{\\underline{\\tau}}_{solid} - \\underline{\\underline{\\tau}}) d\\Gamma\n\\label{visc-stress-original} \n\\end{eqnarray} \n\nConsider for example the part of the $\\underline{\\underline{\\tau}}$ term: \n\n\\begin{eqnarray}\n\\int_\\Gamma N_i n_x \\mu ( \\frac{\\partial u}{\\partial x}\\vert_{solid} - \\frac{\\partial u}{\\partial x} ) d\\Gamma. \n\\label{visc-stress-original-solid-bc} \n\\end{eqnarray} \nWe can approximate the fluid derivatives next to the solid boundary using: \n\n\\begin{eqnarray}\n\\int_V {N_{wall}}_i \\frac{\\partial u}{\\partial x} \\vert_{solid} dV \n= \n- \\int_V \\frac{\\partial {N_{wall}}_i }{\\partial x} u dV \n+\\int_{\\Gamma_{solid}} {N_{wall}}_i  u d\\Gamma.\n\\label{solid-gam1} \n\\end{eqnarray} \nUsing the solid velocity $u_s$ at the boundary: \n\\begin{eqnarray}\n\\int_V {N_{wall}}_i \\frac{\\partial u}{\\partial x} \\vert_{solid} dV \n= \n- \\int_V \\frac{\\partial {N_{wall}}_i }{\\partial x} u dV \n+\\int_{\\Gamma_{solid}} {N_{wall}}_i  u_s d\\Gamma.\n\\label{solid-gam2} \n\\end{eqnarray} \nThen using equation \\ref{solid-gam1} in equation \\ref{solid-gam2} to obtain: \n\\begin{eqnarray}\n\\int_V {N_{wall}}_i \\frac{\\partial u}{\\partial x} \\vert_{solid} dV \n= \\int_V {N_{wall}}_i \\frac{\\partial u}{\\partial x} dV \n-\\int_{\\Gamma_{solid}} {N_{wall}}_i  n_x (u-u_s) d\\Gamma.\n\\label{solid-gam3} \n\\end{eqnarray} \nUsing very simplest constant basis functions ${N_{wall}}_i$ with $\\Delta x_{wall}$ being the \nfluid element length scale around the wall and normal to it, then: \n\\begin{eqnarray}\n \\frac{\\partial u}{\\partial x} \\vert_{solid} \n= \\frac{\\partial u}{\\partial x} \n-\\frac{ n_x (u-u_s) }{\\Delta x_{wall}}.\n\\label{solid-gam4} \n\\end{eqnarray} \nWe can evaluate the terms in equation \\ref{visc-stress-original-solid-bc} over a thin shell $V_{shell}$ using equation \\ref{solid-gam4} to obtain: \n\n\\begin{eqnarray}\n\\int_\\Gamma  N_i n_x \\mu \\frac{\\partial u}{\\partial x} \\vert_{solid} d\\Gamma\n\\approx \n\\int_{V_{shell}}  N_i n_x \\frac{1}{\\Delta r} \\mu \\frac{\\partial u}{\\partial x} \\vert_{solid}  dV\n\\label{visc-stress-original-practical-a} \n\\end{eqnarray} \n\\begin{eqnarray}\n\\approx\n\\int_{V_{shell}}  N_i n_x \\frac{1}{\\Delta r}\\mu \\frac{\\partial u}{\\partial x}  dV\n+\n\\int_{V_{shell}}  N_i n_x n_x \\frac{1}{\\Delta r \\Delta x_{wall}}\\mu (u_{solid} -u)  dV.\n\\label{visc-stress-original-practical} \n\\end{eqnarray} \nThus\n\n\\begin{eqnarray}\n\\int_\\Gamma N_i n_x \\mu ( \\frac{\\partial u}{\\partial x}\\vert_{solid} - \\frac{\\partial u}{\\partial x} ) d\\Gamma\n\\approx\n\\int_{V_{shell}}  N_i n_x n_x \\frac{1}{\\Delta r \\Delta x_{wall} }\\mu (u_{solid} -u)  dV, \n\\end{eqnarray} \nin which $\\Delta r$ is the width of the thin shell surrounding the solid. \n\n\nThe viscous term expanded becomes:\n\n\\begin{equation}\n\\frac{\\partial ( \\mu_{xx}\n(\n\\frac{\\partial u}{\\partial x}+\\frac{\\partial u}{\\partial x})\n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial x}\n+\n\\frac{\\partial \\mu_{xy}\n(\n\\frac{\\partial v}{\\partial x}+\\frac{\\partial u}{\\partial y})\n}\n{\\partial y}\n+\n\\frac{\\partial \\mu_{xz}\n(\n\\frac{\\partial w}{\\partial x}+\\frac{\\partial u}{\\partial z})\n}\n{\\partial z}, \n\\label{visc-stress-u-2} \n\\end{equation}\n\n\n\n\\begin{equation}\n\\frac{\\partial \\mu_{yx}\n(\n\\frac{\\partial u}{\\partial y}+\\frac{\\partial v}{\\partial x}\n)}\n{\\partial x}\n+\n\\frac{\\partial (\\mu_{yy}\n(\n\\frac{\\partial v}{\\partial y}+\\frac{\\partial v}{\\partial y})\n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial y}\n+\n\\frac{\\partial \\mu_{yz}\n(\n\\frac{\\partial w}{\\partial y}+\\frac{\\partial v}{\\partial z})\n)}\n{\\partial z}, \n\\label{visc-stress-v-2} \n\\end{equation}\n\n\n\n\\begin{equation}\n\\frac{\\partial \\mu_{zx}\n(\n\\frac{\\partial u}{\\partial z}+\\frac{\\partial w}{\\partial x})\n}\n{\\partial x}\n+\n\\frac{\\partial \\mu_{zy}\n(\n\\frac{\\partial v}{\\partial z}+\\frac{\\partial w}{\\partial y})\n}\n{\\partial y}\n+\n\\frac{\\partial ( \\mu_{zz}\n(\n\\frac{\\partial w}{\\partial z}+\\frac{\\partial w}{\\partial z})\n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol})(\\frac{\\partial u}{\\partial x}+\\frac{\\partial v}{\\partial y}+\\frac{\\partial w}{\\partial z})\n)}\n{\\partial z}. \n\\label{visc-stress-w-2} \n\\end{equation}\n\n\nDiscretizing these equations (see also the DG discretized viscocity equations \\ref{visc-stress-u-Ni},\\ref{visc-stress-v-Ni},\\ref{visc-stress-w-Ni}) the solid boundary conditions can be expressed  \nfor fluid velocity component u:\n% U: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}} \n({n_x} \n(\n2 n_x \\mu_{xx}u_s \n-(\\frac{2}{3} \\mu_{xx}-\\mu_{vol}){\\bf n}\\cdot{\\bf u}_s \n)\n+\n {n_y} \\mu_{xy}\n( n_x  v_s + n_y u_s) \n+\n{n_z} \\mu_{xz}\n( n_x w_s + n_z u_s ) \n )d V\n\\label{visc-stress-u-n-2-solid} \n\\end{equation}\n\\begin{equation}\n- \\int_{V_{shell}} \nN_i\\frac{1}{\\Delta r \\Delta x_{wall} } ({n_x}   (2\\mu_{xx}\nn_x u \n-(\\frac{2}{3}\\mu_{xx}-\\mu_{vol}) {\\bf n}\\cdot{\\bf u} \n)\n+\n {n_y} \\mu_{xy}\n( n_x  v + n_y u) \n+\n{n_z} \\mu_{xz}\n( n_x w + n_z u ) \n )d V,\n\\label{visc-stress-u-n-2-fluid} \n\\end{equation}\n\n\nfor v:\n% V: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i\\frac{1}{\\Delta r \\Delta x_{wall}}\n({n_x} \\mu_{yx}\n(n_y u_s + n_x v_s) \n+\n{n_y}(2\\mu_{yy}\nn_y v_s \n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol}) {\\bf n} \\cdot{\\bf u}_s \n)\n+\n{n_z} \\mu_{yz}\n(n_y w_s + n_z v_s )\n )dV\n\\label{visc-stress-v-n-2-solid} \n\\end{equation}\n\\begin{equation}\n-  \\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}}\n({n_x} \\mu_{yx}\n(n_y u + n_x v) \n+\n{n_y}(2\\mu_{yy}\nn_y v \n-(\\frac{2}{3}\\mu_{yy}-\\mu_{vol}) {\\bf n} \\cdot{\\bf u}\n)\n+\n{n_z} \\mu_{yz}\n(n_y w + n_z v )\n )d V,\n\\label{visc-stress-v-n-2-fluid} \n\\end{equation}\n\n\nfor w:\n% W: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}}\n({n_x} \\mu_{zx}\n( n_z u_s + n_x w_s )\n+\n{n_y} \\mu_{zy}\n( n_z v_s + n_y w_s )\n+\n{n_z} \\mu_{zz}\n(\n2 n_z w_s \n-\\frac{2}{3} {\\bf n} \\cdot{\\bf u}_s \n) )d V \n\\label{visc-stress-w-n-2-solid} \n\\end{equation}\n\\begin{equation}\n-\\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}}\n({n_x} \\mu_{zx}\n( n_z u + n_x w )\n+\n{n_y} \\mu_{zy}\n( n_z v + n_y w )\n+\n{n_z} (2\\mu_{zz}\nn_z w \n-(\\frac{2}{3}\\mu_{zz}-\\mu_{vol}) {\\bf n} \\cdot{\\bf u}\n) )d V. \n\\label{visc-stress-w-n-2-fluid} \n\\end{equation}\n\nNow assuming the volumetric viscocity is zero, $\\mu_{vol}=0$, \nand using the slip velocity ${\\bf u}_{sl} = {\\bf u}_{s} -{\\bf u}$ and gathering the \ncontributions to each velocity component $u$, $v$ and $w$ then: \nFor the $u_{sl}$ equation:\n\n% U: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}} \n(\n({n_x} \\mu_{xx}\n(2-\\frac{2}{3}) n_x +n_y \\mu_{xy} n_y + n_z\\mu_{xz} n_z) u_{sl} \n+\n(-n_x \\mu_{xx}\\frac{2}{3} n_y + n_y \\mu_{xy} n_x\n)v_{sl} \n+\n(-n_x \\mu_{xx}\\frac{2}{3} n_z + n_z \\mu_{xz} n_x\n)w_{sl} \n )d V\n\\label{visc-stress-u-n-2-sl} \n\\end{equation}\n\nFor the $v_{sl}$ equation:\n% V: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{1}{\\Delta r \\Delta x_{wall}} \n(\n({n_x} \\mu_{yx} n_y -n_x\\mu_{yy}\\frac{2}{3} n_x ) u_{sl} \n+\n(n_x \\mu_{yx}n_x + n_y\\mu_{yy} (2-\\frac{2}{3}) n_y + n_z\\mu_{yz} n_z) v_{sl} \n+\n( - n_y\\mu_{yy} \\frac{2}{3}) n_z + n_z\\mu_{yz} n_y\n)w_{sl} \n )d V\n\\label{visc-stress-v-n-2-sl} \n\\end{equation}\n\n\n\nFor the $w_{sl}$ equation:\n% W: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{\\mu}{\\Delta r \\Delta x_{wall}} \n(\n({n_x} \\mu_{zx} n_z -n_z\\mu_{zz}\\frac{2}{3} n_x ) u_{sl} \n+\n(n_y \\mu_{zy}n_z - n_z\\mu_{zz} \\frac{2}{3} n_y ) v_{sl} \n+\n(n_x \\mu_{zx}n_x +n_y \\mu_{zy}n_y+ n_z\\mu_{zz} (2-\\frac{2}{3}) n_z \n)w_{sl} \n )d V. \n\\label{visc-stress-u-n-2-sl-mu} \n\\end{equation}\nOr assuming the viscocity is isotropic $\\mu=\\mu_{xx}=\\mu_{xy}...$ then for the $u_{sl}$ equation:\n\n\n\n\n% U: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{\\mu}{\\Delta r \\Delta x_{wall}} \n(\n({n_x} \n(2-\\frac{2}{3}) n_x +n_y n_y + n_z n_z) u_{sl} \n+\n(-n_x \\frac{2}{3} n_y + n_y  n_x\n)v_{sl} \n+\n(-n_x \\frac{2}{3} n_z + n_z  n_x\n)w_{sl} \n )d V\n\\label{visc-stress-u-n-2-sl-mu} \n\\end{equation}\n\nFor the $v_{sl}$ equation:\n% V: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{\\mu}{\\Delta r \\Delta x_{wall}} \n(\n({n_x}  n_y -n_x \\frac{2}{3} n_x ) u_{sl} \n+\n(n_x n_x + n_y (2-\\frac{2}{3}) n_y + n_z n_z) v_{sl} \n+\n( - n_y \\frac{2}{3}) n_z + n_z n_y\n)w_{sl} \n )d V\n\\label{visc-stress-v-n-2-sl-mu} \n\\end{equation}\n\n\nFor the $w_{sl}$ equation:\n% W: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i \\frac{\\mu}{\\Delta r \\Delta x_{wall}} \n(\n({n_x}  n_z -n_z\\frac{2}{3} n_x ) u_{sl} \n+\n(n_y n_z - n_z \\frac{2}{3} n_y ) v_{sl} \n+\n(n_x n_x +n_y n_y+ n_z (2-\\frac{2}{3}) n_z \n)w_{sl} \n )d V. \n\\label{visc-stress-u-n-2-sl-mu} \n\\end{equation}\n\n\n\n\nOr in more condensed form - also serving as a definition of $a_{xx}, a_{xy},...$ - \nfor $u$:\n\n\\begin{equation}\n\\int_{V_{shell}} \nN_i ( a_{xx} u_{sl} + a_{xy} v_{sl} + a_{xz} w_{sl} ) dV\n\\label{as-for-x} \n\\end{equation}\nfor $v$: \n\\begin{equation}\n\\int_{V_{shell}} \nN_i ( a_{yx} u_{sl} + a_{yy} v_{sl} + a_{yz} w_{sl} ) dV\n\\label{as-for-y} \n\\end{equation}\nfor $w$:\n\\begin{equation}\n\\int_{V_{shell}} \nN_i ( a_{zx} u_{sl} + a_{zy} v_{sl} + a_{zz} w_{sl} ) dV. \n\\label{as-for-z} \n\\end{equation}\nDefining, \n\\begin{equation}\nf_x=a_{xx} u_{s} + a_{xy} v_{s} + a_{xz} w_{s}, \\;\\;  \nf_y=a_{yx} u_{s} + a_{yy} v_{s} + a_{yz} w_{s}, \\;\\;  \nf_z=a_{zx} u_{s} + a_{zy} v_{s} + a_{zz} w_{s}, \n\\label{as-for-f} \n\\end{equation}\nthen in order to evaluate the rhs source force contribution on the \nfluid each of $f_x, f_y, f_z$ is mapped to the fluids velocity mesh \nto form $f_x^f, f_y^f, f_z^f$. In addition, each of $a_{xx}$, $a_{xy}$, ... \nare mapped to the fluids mesh in order to form the implicit treatment \nof the fluid velocity. \nThe matrix: \n\\begin{eqnarray}\n\\begin{pmatrix}\na_{xx} & a_{xy} & a_{xz} \\\\ \na_{yx} & a_{yy} & a_{yz} \\\\ \na_{zx} & a_{zy} & a_{zz} \n\\end{pmatrix},  \n\\end{eqnarray}\nis symmetric-positive-semi-definite for the same reasons why the viscocity term \nis. That is, it has a variational principle behind it with a non-negative functional. \nIf this matrix is not positive-semi-definite then this term can enable the \ndifference between the velocity of the fluid $u$ and the velocity of the solid $u_s$ to grow \nexponentially (if one of the negative eigen-values is $\\lambda$ then part of the equation looks like \n- in Riemann space with a Riemann variable $v_\\lambda$: $\\frac{\\partial v_\\lambda}{\\partial t} +\\lambda v_\\lambda=0$ which diverges exponentially). \nMoreover, one needs to take care to interpolate this matrix as well as $f_x, f_y, f_z$ \nto ensure the  matrix preserves this property and $f_x, f_y, f_z$  is consistent with this matrix. \nA method of obtaining this consistency is to use the overlapping control-volume Grundy interpolation which \ntends to be dissipative. \n\n\n\n\n\n\n\n\n\\subsection{Solid stress boundary condition or force on the solid} \n\nThe discretized force on the solid is evaluated from:\n\\begin{eqnarray}\n\\int_{\\Gamma_{solid}} N_i n\\cdot (\\underline{\\underline{\\tau}}_{solid} + I p) d\\Gamma\n\\end{eqnarray} \nin which $\\underline{\\underline{\\tau}}_{solid}$ contains just the viscouse contributions \nto the stress term. \n\nAs shown in equation \\ref{visc-stress-original-practical}  the \nindividual gradients (that make up the viscous stress tensor  $\\underline{\\underline{\\tau}}_{solid}$) can be calculated from:\n\\begin{eqnarray}\n\\int_{\\Gamma_{solid}}  N_i n_x \\mu \\frac{\\partial u}{\\partial x} \\vert_{solid} d\\Gamma\n\\approx \n\\int_{V_{shell}}  N_i n_x \\frac{1}{\\Delta r}\\mu \\frac{\\partial u}{\\partial x}  dV\n+\n\\int_{V_{shell}}  N_i n_x n_x \\frac{1}{\\Delta r \\Delta x_{wall} }\\mu (u_{solid} -u)  dV \\\\\n\\approx \n\\int_{\\Gamma_{solid}}  N_i n_x \\mu \\frac{\\partial u}{\\partial x}  d\\Gamma\n+\n\\int_{\\Gamma_{solid}}  N_i n_x n_x \\frac{1}{\\Delta x_{wall}}\\mu (u_{solid} -u)  d\\Gamma. \n\\label{visc-stress-original-practical-solid-bc} \n\\end{eqnarray} \nThis integral is used as a discretized surface force in the solids equations. \n \n\n\n\n\n\n\\subsection{Parameterized solid stress boundary condition or force on the solid} \nSometimes the velocity in the local vacinity is not resolved and thus \nneeds to be parameterized. A good example is the log law of the wall for turbulent \nflows.  \n\nThis parameterized stress typically takes on the form:  \n\\begin{eqnarray}\n\\int_{\\Gamma_{solid}} N_i n\\cdot \n(  \\underline{\\underline{\\tau}}_{solid} - \\underline{\\underline{\\tau}} )\nd\\Gamma \n\\approx\n\\int_{\\Gamma_{solid}} N_i \\lambda (u_{solid}-u)  d\\Gamma \n\\end{eqnarray} \nand for turbulent flows, with a log law, it might for example take on the form: \n\\begin{eqnarray}\n\\lambda = \\frac{ \\vert u_{solid}-u\\vert k^2 } { (log(0.5\\Delta y E)-1)^2}  \n\\end{eqnarray} \nin which $\\Delta y$ is the wall-normal distance\nof the first off-wall node, $k$ is the von Karman constant and $E$ is the dimensionless wall roughness. \nThus, in the equations above \\ref{as-for-x},\\ref{as-for-y},\\ref{as-for-z},\\ref{as-for-f}: \n\\begin{eqnarray}\na_{xx}=a_{yy}=a_{zz}=\\lambda\n\\end{eqnarray} \nwhile the other components of $a$ are zero e.g. $a_{xy}=0$. \n\n\n\n\n\n\\pagebreak\n\n\n\\section{Free surface and large scale flows}\n\\label{Free surface and large scale flows}\n\n\nThis section  details a free surface and large scale flow formulation \nfor ocean and atmospheric flows. \nIt uses a combined pressure/free-surface \nvariable and thus treats the free surface height with a \nhigh level of implicitness. It also ensures numerical \nconsistency when using a fully unstructured mesh in the horizontal \nand vertical as free surface height or its derivatives do not \nneed to be interpolated from the free surface to the internal volume \nof the domain. \nAt the free surface the no normal flow boundary \ncondition is enforced weakly. \n\nThe implicitness and accuracy of the discretised equations is enhanced \nhere which also enhances both the stability and conditioning \nof the discretised equations. \nThe conditioning of the 3-D discrete \nLaplacian for the combined pressure/free-surface variable is \nenhanced. Suitable vertical momentum \nabsorption terms are used to control the \nconditioning of this 3-D equation in a high aspect ratio \ndomain. \n\n\n\n\\subsection{Governing equations and time discretisation/linearisation}\n\\noindent \nThe momentum equation and continuity equations can be written at \ntime level $n$: \n\n\\begin{equation}\n\\nabla \\cdot u^{n+1}=0\n\\label{d1eqn}\n\\end{equation}\n\n\\begin{equation}\n\\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t}= R^{n+1} - \\nabla p^{n+1} - \\rho^{n+1} k g \n\\label{ns}\n\\end{equation}\nwhere $k$ is the upward direction along which gravity acts.  \nIn this equation for density is: \n\\begin{equation}\n\\frac{\\rho^{n+1} -\\rho^n}{\\Delta t} + {\\tilde u}^{n+1}\\cdot \\nabla \\rho^{n+1}=0 \n\\label{d2eqn}\n\\end{equation}\nwhich can be written using a slightly different linearisation in the form:\n \n\\begin{equation}\n\\frac{\\rho^{n+1} -\\rho^n}{\\Delta t} \n+ w^{n+1} \\frac{\\partial {\\tilde \\rho}^{n+1}}{\\partial z} +  {\\tilde s}_\\rho^{n+1}=0 \n\\label{d2eqn-sim}\n\\end{equation}\n\nNow placing this equation into \\ref{ns} to obtain:\n\\begin{equation}\n\\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t}= R^{n+1} - \\nabla p^{n+1} \n+ g k \\Delta t \\frac{\\partial {\\tilde \\rho}^{n+1}}{\\partial z} (w^{n+1}- {\\tilde w}^{n+1})\n- {\\tilde \\rho}^{n+1} k g \n\\label{ns-2}\n\\end{equation}\nwhere the tilde (e.g. ${\\tilde w}^{n+1}$) represents the best guess so far of a variable. \nNotice that we do not actually need to solve an equation for density we are \nsimply assuming the equation for density has the form of \\ref{d2eqn-sim}. \n\nNow testing the equation \\ref{ns-2} with velocity basis functions \n$N_i$ and applying integration by parts twice at the surface \nof the ocean to obtain:\n\n\\begin{equation}\n\\int_\\Omega N_i \\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t} d V= \n\\int_\\Omega N_i (R^{n+1} - \\nabla p^{n+1} \n+ g k \\Delta t \\frac{\\partial {\\tilde \\rho}^{n+1}}{\\partial z} (w^{n+1}- {\\tilde w}^{n+1})\n- {\\tilde \\rho}^{n+1} k g ) dV\n\\end{equation}\n\\begin{equation}\n- \\int_\\Gamma n_z N_i g k \\Delta t (\\rho^{n+1}-\\rho_{air})(w^{n+1}-\\tilde\nw^{n+1}) d\\Gamma\n\\label{ns-dis-b}\n\\end{equation}\nin which $\\rho_{air}$ is the density of the air just above th ocean \nwhich will be neglected. If there is a density variation in the water \nthen retaining the term involving $\\frac{\\partial \\rho}{\\partial z}$ \nenhances the stability of the formulation at least for stably stratified \nfluids in other circumstances it can be ignored for stability. \nThus, \\ref{ns-dis} becomes:\n\n\\begin{equation}\n\\int_\\Omega N_i \\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t} d V= \n\\int_\\Omega N_i (R^{n+1} - \\nabla p^{n+1} \n+ g k \\Delta t \\frac{\\partial {\\tilde \\rho}^{n+1}}{\\partial z} (w^{n+1}- {\\tilde w}^{n+1})\n- {\\tilde \\rho}^{n+1} k g ) dV\n\\end{equation}\n\\begin{equation}\n- \\int_\\Gamma N_i n_z g k \\Delta t {\\tilde \\rho}^{n+1}(w^{n+1}-\\tilde\nw^{n+1}) d\\Gamma\n\\label{ns-dis-2-b}\n\\end{equation}\nAssuming that for shallow waters the vertical velocity $w$ \nis linearly related to distance from the bottom of the ocean \nor in a depth averaged sense (care must be taken not to destroy the \n3-D dynamics with this) and ignoring the density variation of $\\rho$ \nfrom $\\rho_0$ ($\\rho=\\rho_0+\\hat \\rho$) in the surface integral above: \n\n\\begin{equation}\n\\int_\\Omega N_i \\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t} d V= \n\\int_\\Omega N_i (R^{n+1} - \\nabla p^{n+1} \n- \\sigma (u^{n+1}-\\tilde\nu^{n+1}) \n- {\\tilde \\rho}^{n+1} k g ) dV\n\\label{ns-dis-2}\n\\end{equation}\nwhere the inverse time scale for the vertical velocity \nrelaxation is:\n\n\\begin{equation}\n\\sigma=  \n  \\begin{pmatrix}\n    0   & 0 & 0 \\\\\n    0   & 0 & 0 \\\\\n    0 & 0 & \\sigma_{zz}\n  \\end{pmatrix}\n\\label{sigma_matrix}\n\\end{equation}\nwith\n\\begin{equation}\n\\sigma_{zz}= g \\Delta t \\max\\{-\\frac{\\partial {\\tilde \\rho}^{n+1}}{\\partial z},\n0\\} \n+ \\frac{n_z g \\Delta t}{d} \\rho_0 \n\\label{sigma_z}\n\\end{equation}\nand where $d$ is the depth of the ocean. \nNow the hydrostatic $p_0$ which makes up the total \npressure $p=p_0+\\hat p $ with $\\hat p = p_{nh} + g\\xi$\ncan be calculated from \n\n\\begin{equation}\np_0=(z_0-z)\\rho_0 g \\;\\;{\\rm therefore}\\;\\; \n\\frac{\\partial p_0}{\\partial z}= -\\rho g \\rho_0\n\\label{p_h}\n\\end{equation}\nSubtracting out the pressure hydrostic pressure level $p_0$ one obtains:\n\n\\begin{equation}\n\\rho_0 \\frac{u^{n+1}- u^n}{\\Delta t} = \nR^{n+1} - \\nabla \\hat p^{n+1} \n- \\sigma (u^{n+1}-\\tilde u^{n+1}) - kg{\\tilde{\\hat\\rho}}^{n+1}\n\\label{ns-dis-3}\n\\end{equation}\nand $g \\xi$ is the boundary condition for $\\hat p$ on the free \nsurface boundary $\\Gamma_{free\\; surface}$. \n\n\n\n\n\n\\subsection{The discrete free surface equations}\n\\noindent The momentum equation are tested with the velocity \nbasis functions $N_i$ (see equation \\ref{ns-dis-2}) and the continuity equation tested \nwith the pressure basis functions $M_i$. All test functions/matrices \nshown here and surface normals are evaluated at a best guess to \ntime level $n+\\frac{1}{2}$ mid way \nbetween time level $n$ and $n+1$. At the start of the time \nstep these are evaluated at time level $n$. \nThe resulting discrete momentum equation using $\\theta$-time stepping then becomes: \n\n\\begin{equation}\n\\frac{M_u}{\\Delta t}u_*^{n+1}+Au_*^{n+1}=  C_{\\theta_c} {\\hat p}_*^{n+1}\n+C_{1-\\theta_c} {\\hat p}^n+s_u\n\\label{eq1}\n\\end{equation}\n\\begin{equation}\n\\frac{M_u}{\\Delta t}u^{n+1}+Au_*^{n+1}=C_{\\theta_c} {\\hat p}^{n+1}\n+C_{1-\\theta_c} {\\hat p}^n+s_u\n\\label{eq2}\n\\end{equation}\nwhere $M_u$ dependent on the type of elements is the velocity mass matrix (can be consistent \nfor the $P1_{DG}-P2$ element because of its block structure), \n$u$ and $p$ is the velocity and pressure variables respectively, \n$u_*$ is an approximation to $u$ and calculated from the \npressure at the previous time level, \n$s_u$ is the source term, $n$ is the time level, $\\theta_c$ controls \nthe time stepping method for the pressure term/continuity equation \n($\\theta_c=\\frac{1}{2}$ is Crank-Nickolson time stepping and \n$\\theta_c=1$ is backward Euler) \nand $\\Delta t$ is the time step size. $M_u$ will also contain the \nimplicit treatment of the absorption matrix and possibly the diagonal or block-diagonal \npart of \nthe viscosity matrix which are to be treated implicitly in pressure. See \nthe next section on conditioning of the system of equations. \n\n\\noindent Subtracting (\\ref{eq1}) from (\\ref{eq2}), yields\n\\begin{equation}\n\\frac{M_u}{\\Delta t}(u^{n+1}-u_*^{n+1})= C_{\\theta_c} ({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{u-eqn}\n\\end{equation}\n\\noindent Multiplying (\\ref{eq3}) by $C_{\\theta_c}^T (\\frac{M_u}{\\Delta t})^{-1}$, yields\n\\begin{equation}\nC_{\\theta_c}^T (u^{n+1}-u_*^{n+1})=\nC_{\\theta_c}^T \\left(\\frac{M_u}{\\Delta t}\\right)^{-1} \nC_{\\theta_c} ({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{eq3}\n\\end{equation}\n\n\\noindent The free surface kinematic boundary conditions are\n\\begin{equation}\n n_g\\frac{\\partial \\xi}{\\partial t} = \\bmn \\cdot \\bmu\n\\label{FSeq1-1}\n\\end{equation}\n\\noindent The discrete form of (\\ref{FSeq1-1}) is written\n\\begin{equation}\n M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t} = \nG_{{\\theta_{pf}}}^T u^{n+1}  +G_{{1-\\theta_{pf}}}^T u^{n} \n\\label{FSeq2}\n\\end{equation}\nwhere $n_g=\\bmn\\cdot \\bmn_z$,  \n$M_{s,ij}=\\int_{\\Gamma_{Free Surface}}n_gM_iM_j d \\Gamma$ \n and $G_{\\theta_{pf} ij}=\\int_{\\Gamma_{Free Surface}}\\theta_{pf} \\bmn  N_iM_j d \\Gamma $, \n $G_{(1-\\theta_{pf}) ij}=\\int_{\\Gamma_{Free Surface}}(1-\\theta_{pf}) \\bmn  N_iM_j d \\Gamma $, \n ${C_{\\theta_c}}_{ij}=-\\int_\\Omega N_i \\theta_c \\nabla M_j d V$, \n ${C_{(1-\\theta_c)}}_{ij}=-\\int_\\Omega N_i (1-\\theta_c) \\nabla M_j d V$, \n and $\\theta_{pf}$ is the time stepping parameter associated with the free surface. We have \n also used the fact that the pressure is zero on the free surface \n and thus ${\\hat p}=g\\xi$. \n$\\Gamma_{Free Surface}$ is the free surface. \nIf $G_{\\theta_{pf}}=G_{(1-\\theta_{pf})}=0$ then the system \nof equations would enforce incompressibility with weakly enforced no normal flow \nboundary conditions. \n\n\\noindent  \nThe discrete continuity equation can be written: \n\\begin{equation}\nC_{\\theta_c}^T u^{n+1}+C_{1-\\theta_c}^T u^{n}\n +G_{{\\theta_{pf}}}^T u^{n+1}  +G_{{1-\\theta_{pf}}}^T u^{n} =0\n\\label{Ceq2}\n\\end{equation}\nor using equation \\ref{FSeq2}: \n\\begin{equation}\nC_{\\theta_c}^T u^{n+1}+C_{1-\\theta_c}^T u^{n}\n+M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t}=0\n\\label{Ceq3}\n\\end{equation}\nSubstituting (\\ref{Ceq3}) into (\\ref{eq3}), yields       \n\\begin{equation}\n-C_{1-\\theta_c}^T u^{n}\n-M_s\\frac{{\\hat p}^{n+1}-{\\hat p}^n}{g \\Delta t}-C_{\\theta_c}^T u_*^{n+1}\n=\nC_{\\theta_c}^T \\left(\\frac{M_u}{\\Delta t}\\right)^{-1}C_{\\theta_c} \n({\\hat p}^{n+1}-{\\hat p}_*^{n+1})\n\\label{Ceq4}\n\\end{equation}\nRe-arranging (\\ref{Ceq4}): \n\n\\begin{eqnarray}\n&&\\left(C_{\\theta_c}^T \nM_u^{-1}C_{\\theta_c}  \n+ \\frac{M_s}{g (\\Delta t)^2}\\right) \\Delta {\\hat p} =  \\nonumber\\\\ \n&& -\\frac{\nC_{\\theta_c}^T u^{n+1}_*+C_{1-\\theta_c}^T u^{n}\n}{\\Delta t}\n-\\frac{M_s}{g (\\Delta t)^2}({\\hat p}_*^{n+1}-{\\hat p}^{n})\n\\label{Ceq5}\n\\end{eqnarray}\nand ${\\hat p}^{n+1}={\\hat p}_*^{n+1}+\\Delta {\\hat p}$. This algorithm \nis repeated until $\\Delta {\\hat p}$ is sufficiently small. \nOnce ${\\hat p}^{n+1}$ is calculated then equation \\ref{u-eqn} \nis used to solve for the velocity $u^{n+1}$.\n\n\n\n\\subsection{Simple open boundary conditions}\n\\noindent \nSimple open boundary conditions at a boundary $\\Gamma_{p_{bc}}$ can be applied by specifying \n$\\hat p_{bc}^{n+\\theta_{pbc}}$ in the above formulation and using $\\beta=1$ \non this boundary else $\\beta=0$. \n$M_s$ is zero where there is a combined pressure/free-surface condition at the \nincoming/outgoing boundary, that is where \n${\\hat p}_{bc}=g \\times$ free surface height at the inlet + hydrostatic pressure. \nThe hydrostatic pressure is calculated by integrating the density \ndownwards on the incoming/outgoing boundary. \nA simple boundary condition on potential temperature and salinity is  \nto specify its value when there is an incoming velocity component \non the incoming/outgoing boundary and otherwise use natural diffusivity \nboundary conditions. \n\nAlong with these conditions one may need to apply some sort \nof spung to reduce spurious boundary effects such as \ninternal and external wave reflection. This may take \non the form of anisotropic viscosity, momentum absorption or enhanced magnitude \nof the time term similar to absorption. The magnitude of these \ncan for example be chosen based on the time scales on which \nparticular physics (e.g. internal and external waves) \nneed to be relaxed ramping the magnitude up \ntowards the boundary. \n\nOne can segregate the free surface height and pressure by solving a wave equation for the free surface height and then \nusing a Dirichlet b.c at the surface (as described here) for the free surface height. \nThis approach would allow the time step for the internal mode to be much longer \nthan the external mode and it may also be used to help design boundary conditions \nas there is a well developed body of literature for wave equation boundary \nconditions. \n\n\\subsection{Multiphase flows}\n\\noindent\nFor liquid, the momentum equation is:\n\\begin{equation}\n\\alpha_l\\rho_l\\dfrac{Du}{Dt} + \\sigma_l\\alpha_l u = - \\alpha_l\\nabla p_c + \\alpha_l\\rho_l g k\n\\label{mf-eq1}\n\\end{equation}\nFor gas,\n\\begin{equation}\n\\alpha_g\\rho_g\\dfrac{Du}{Dt} = - \\alpha_g\\nabla p_c + \\alpha_g\\rho_ggk\n\\label{mf-eq2}\n\\end{equation}\nIn the equations above, $ \\alpha_l + \\alpha_g =1$ and $\\sigma_l=\\sigma_l(\\alpha_l,u)$. When the surface is dry, $\\alpha_l = 0$. Combine the two equations above,\n\\begin{equation}\n\\hat \\rho \\dfrac{Du}{Dt} + \\hat \\sigma u = -\\nabla p_c+\\hat \\rho g k\n\\label{mf-eq3}\n\\end{equation}\nwhere $\\hat \\rho=(\\alpha_l\\rho_l + \\alpha_g\\rho_g)$, and $\\hat\\sigma=\\sigma_l\\alpha_l +\\sigma_g\\alpha_g $.\nThe conservative form of continuity equation for liquid becomes:\n\\begin{equation}\n\\frac{\\partial \\alpha_l}{\\partial t} + \\nabla \\cdot \\alpha_l u = 0\n\\label{mf-eq4}\n\\end{equation}\nThe non-conservative form is:\n\\begin{equation}\n\\frac{\\partial \\alpha_l}{\\partial t} + u \\cdot \\nabla \\alpha_l = 0\n\\label{mf-eq5}\n\\end{equation}\nSimilarly, the conservative form of continuity equation for gas is:\n\\begin{equation}\n\\frac{\\partial \\alpha_g}{\\partial t} + \\nabla \\cdot \\alpha_g u = 0\n\\label{mf-eq6}\n\\end{equation}\nNow testing the continuity equation with test functions $M_i$ and applying integration by parts twice at the \nsurface of the ocean to obtain:\n\\begin{equation}\n\\int_\\Omega M_i \\nabla \\cdot u dV = \\int_\\Omega \\nabla M_i n \\cdot u dV + \\int_\\Gamma M_i n \\cdot u d\\Gamma\n\\label{mf-eq7}\n\\end{equation}\nIn order to release air, boundary condition need to be changed. Multiply the second term of the R.H.S in \nequation (\\ref{mf-eq7}) to obtain:\n\\begin{equation}\n\\int_\\Omega M_i \\nabla \\cdot u dV = \\int_\\Omega \\nabla M_i n \\cdot u dV +\n \\int_\\Gamma \\varepsilon M_i n \\cdot u d\\Gamma\n\\label{mf-eq8}\n\\end{equation}    \nIf $\\xi \\leq d_0$, then $\\varepsilon = 1$;\nIf $\\xi > d_0$ and $\\alpha_l = 1$, then $\\varepsilon = 0$;\nIf $\\xi > d_0$ and $\\alpha_l < 1$, then $\\varepsilon = \\alpha_g$.\nThe free surface kinematic boundary condition can be written:\n\\begin{equation}\nn_g\\frac {\\partial \\xi}{\\partial t} = \\alpha_l {\\bf n} \\cdot {\\bf u}\n\\label{mf-eq9}\n\\end{equation} \nIn this case, the pressure term is unchanged. The algorithm can be used in \"Breaking waves\".\n\n\n\n\n\\subsection{Conditioning of the discretised equations in \nhigh aspect ratio domains} \n\\noindent \nWithout the stabilization terms involving either \nvertical density gradients or free surface or an implicit treatment \nof vertical velocity the conditioning of the matrix equation \nwill vary as $\\frac{\\Delta x^2}{\\Delta z^2}$ where \n${\\Delta x}, {\\Delta z}$ are the finite element length scales \nin the horizontal and vertical respectively. This condition \nassumes a rigid lid which is an extreme case of the free surface equations \ndeveloped here. \n\nThe requirements for vertical density variation, free surface stabilization \nor vertical viscosity produce a well conditioned  \npressure Laplacian is that one or more of the following three \nconditions hold:\n\n\n\\noindent \n{\\it i) vertical density variation}\n\n\\begin{equation}\n\\frac{\\Delta x^2}{\\Delta z^2} \\leq \\Delta t^2 a^2 g \n\\max\\{\\frac{\\partial \\tilde \\rho^{n+1}}{\\partial z}, 0\\} \n\\label{vert-den}\n\\end{equation}\n\n\\noindent \n{\\it ii) free surface stabilization}\n\n\\begin{equation}\n\\frac{\\Delta x^2}{\\Delta z^2} \\leq \\frac{ \\Delta t^2 a^2 g }{d} \n\\label{vert-fs}\n\\end{equation}\n\n\\noindent \n{\\it iii) vertical viscosity}\n\n\\begin{equation}\n\\frac{\\Delta x^2}{\\Delta z^2} \\leq \\frac{ \\Delta t a^2 \\nu_{zz} }{\\Delta z^2} \n\\label{vert-vis}\n\\end{equation}\nwhere $a=7$ is the tolerable aspect ratio of the element length scales. \nIf $ii)$ is to be used as the basis to control the stability/conditioning \nof the equations and is not satisfied then an artificial time step size $\\Delta t_{art}$ \nmay be used in the last term of \nequation \\ref{sigma_z} for $\\sigma_{zz}$ instead of $\\Delta t$ and from \nequation \\ref{vert-fs} would take on the form:\n\\begin{equation}\n\\Delta t_{art} = \\max\\{ \\frac{\\sqrt{d}\\Delta x}{a \\sqrt{g} \\Delta z}, \\Delta t \\}. \n\\label{vert-fs-art}\n\\end{equation}\n$\\nu_{zz}$ in the above equation \\ref{vert-vis} is the kinematic viscosity which must be treated implicitly \nor semi-implicitly (e.g. the diagonal or block diagonal) \nin pressure in order to control the condition \nnumber of the pressure Laplacian. Stress form of viscosity seems \nappropriate as tensor forms directly smooth horizontal velocities \nin the vertical. \n\nAlternatively, vertical viscosity can be used to stabilize the \nwhole system of equations with the choice:\n\n\n\\begin{equation}\n\\nu_{zz}=\\min\\{\\max\\{\\frac{(\\Delta x)^2}{\\Delta t a^2}, \n\\Delta t g \\max\\{\\frac{\\partial \\tilde \\rho^{n+1}}{\\partial z}, 0\\} \n \\Delta z^2 \\}, \n\\frac{\\Delta t g \\Delta z^2}{d} \\}. \n\\label{nu}     \n\\end{equation}\n\nIn order to make the resulting pressure matrix feel like an $O(a)$ \naspect ratio domain one needs:\n\\begin{equation}\n\\sigma_{zz}= \\frac{(\\Delta x)^2}{\\Delta t a^2 (\\Delta z)^2}, \n\\label{sigma_z_for_order_one}\n\\end{equation}\nor:\n\\begin{equation}\n\\nu_{zz}= \\frac{(\\Delta x)^2}{\\Delta t a^2 }. \n\\label{nu_z_for_order_one}\n\\end{equation}\n\n\n\n\n\\subsection{Compressibility}\n\\noindent \nIn this section we formulate the equations which include compressibility. \nIn an ocean model for example including compressibility \nof sea water is the only way we can satisfying a conservation \nequation for both potential temperature and salinity \nas well as satisfying conservation of mass. Conservation of \nmass is realized through a \nconservative discretisation of the continuity equation which \nwhen discretised in time is:  \n\\begin{eqnarray}\n&&\n\\frac{\\rho^{n+1}( T^{n+1}, S^{n+1}, p^{n+1}) - \\rho^{n}( T^{n}, S^{n}, p^{n})} \n{\\Delta t} \n \\nonumber\\\\ \n&& \n+\n\\nabla \\cdot \\theta_{\\rho} \\tilde  \\rho^{n+1}\n( \\tilde T^{n+1}, \\tilde S^{n+1}, \\tilde p^{n+1}) u^{n+1}\n+\n\\nabla \\cdot (1-\\theta_{\\rho}) \\rho^{n}\n(  T^{n},  S^{n},  p^{n}) u^{n} =0. \n\\label{div-u-row-time-disc} \n\\end{eqnarray}   \nWhen discretised in space by multiplying by the basis \nfunction for pressure $M_i$ and integrating over the domain \nto obtain: \n\\begin{equation}\n\\left(\\frac{M_{s(1-\\alpha)}}{g (\\Delta t)^2}+\\frac{M_{\\rho}}{\\Delta t}\\right)  p^{n+1} + (C_{\\theta_\\rho \\rho} +G_{\\beta\\theta_{pbc}} )^T u^{n+1} = s_{\\theta\\rho}, \n\\label{div-u-row-time-disc-space}     \n\\end{equation}\nin which \n\\begin{equation}\n{M_{\\rho}}_{ij}\n=\\int_V M_i \\frac{\\partial \\tilde\\rho^{n+1}}{\\partial \\tilde p^{n+1}}M_j d \\Omega\n\\label{m-rho}     \n\\end{equation}\nand \n\\begin{equation}\n{C_{\\theta_\\rho \\tilde  \\rho^{n+1}}}_{ij}\n=-\\int_V  (\\nabla M_i )\\cdot \\theta_{\\rho} \\tilde  \\rho^{n+1}\n( \\tilde T^{n+1}, \\tilde S^{n+1}, \\tilde p^{n+1})  N_j d \\Omega, \n\\label{c-rho}     \n\\end{equation}\nand \n\\begin{equation}\n{C_{\\theta_c}}_{ij}\n=-\\int_V  (\\nabla M_i )\\cdot \\theta_{c}  N_j d \\Omega. \n\\label{c-c}  \n\\end{equation}   \n\nUsing the projection method described above the pressure \nmatrix becomes an equation to solve for ${\\hat p}^{n+1}$: \n\\begin{eqnarray}\n&&\\left( ( C_{\\theta_\\rho \\tilde \\rho^{n+1}} +G_{\\beta\\theta_{pbc}})^T \n{M_u}^{-1} (  C_{\\theta_c} +G_{\\beta\\theta_{pbc}}) \n+ \\frac{M_{s(1-\\alpha)}}{g (\\Delta t)^2} \n+ \\frac{M_{\\rho}}{\\Delta t} \\right) \\Delta {\\hat p} =  \\nonumber\\\\ \n&& -\\frac{\n( C_{\\theta_\\rho \\tilde \\rho^{n+1}} +G_{\\beta\\theta_{pbc}})^T u^{n+1}_*\n+( C_{(1-\\theta_\\rho)\\rho^n}+G_{\\beta(1-\\theta_{pbc})})^T u^{n}\n}{\\Delta t} \\nonumber\\\\ \n&& \n-\\left(\\frac{M_{s(1-\\alpha)}}{g (\\Delta t)^2}+\\frac{M_{\\rho}}{\\Delta t}\\right)({\\hat p}_*^{n+1}-{\\hat p}^{n}). \n\\label{Ceq5-wet-and-compress}\n\\end{eqnarray}\nFor use in the potential temperature equation for example it \nis convenient to project the density $\\rho^n(  T^{n},  S^{n},  p^{n}) $ \nonto the pressure basis functions \nin order to form $\\hat \\rho^n$. \nThe corresponding momentum equations discretised are: \n\\begin{equation}\n\\frac{M_u}{\\Delta t}u^{n+1}+Au_*^{n+1}=\n( C_{\\theta_c } +G_{\\beta\\theta_{pbc}})\n{\\hat p}^{n+1}\n+\n( C_{(1-\\theta_c)} +G_{\\beta(1-\\theta_{pbc})})\n{\\hat p}^n\n-G_\\beta {\\hat p}_{bc}^{n+\\theta_{pbc}} +s_u. \n\\label{WD-eq1-comp}\n\\end{equation}\nIn the above the advection of tracers as well as \n$T^n$ and $S^n$ may be done by a discontinuous \nfinite element method and the EoS for density $\\rho^n=\\rho^{n}\n(  T^{n},  S^{n},  p^{n})$ may be a \ncomplex function. Thus, $\\rho^{n}\n(  T^{n},  S^{n},  p^{n})$ may be a complex function within \nan element and discontinuous between the elements. \n\nFor the pressure matrix above to be symmetric then \nin general $\\theta_\\rho=\\theta_c$. The only way to \nmeet the TVD requirements above as well as the producing \na symmetric pressure matrix is to use a combined \n$\\theta_{c\\rho}=max\\{ \\theta_c, \\theta_\\rho \\}$. \n\n\n\n\\subsection{A simple mixing scheme \nin the vertical when there is negative buoyancy} \nSuppose the vertical moment equation is: \n\\begin{equation}\n\\frac{\\partial w}{\\partial t} -  \n \\frac{\\partial }{\\partial z} \\left( \n \\frac{ k  \\partial w}{\\partial z} \\right) \n= - \\rho g + s_w, \n\\label{w-mom}\n\\end{equation}\nand density equation:\n\\begin{equation}\n\\frac{\\partial \\rho}{\\partial t} + w\\frac{\\partial \\rho}{\\partial z} = s_\\rho.\n\\label{rho-vert-dif}\n\\end{equation}\nDiscretised in time this becomes: \n\\begin{equation}\n\\frac{ \\rho^{n+1} -\\rho^n}{\\Delta t} \n+w \\frac{\\partial \\rho^{n+\\theta}}{\\partial z} = S_\\rho.\n\\label{rho-vert-dif-time-disc}\n\\end{equation}\nPlacing this on to the r.h.s. of the vertical momentum equation \\ref{w-mom}\nthe buoyancy terms become: \n\n\\begin{equation}\n(w^{n+1}-\\tilde w^{n+1}) \\frac{\\partial \\rho}{\\partial z} g \\Delta t -\\rho g\n\\label{w-boy}\n\\end{equation}\n\nWe will now choose $k$ such that the diagonal of the diffusion \nterm (when discretised using a 3 point finite difference scheme) \nequals the unstable truncation term involving buoyancy: \n\n\\begin{equation}\n2\\frac{k}{(\\Delta z)^2} = \\max{ \\{ \\frac{\\partial \\rho}{\\partial z}, 0\\} } \\Delta t g.\n\\label{k-eqn}\n\\end{equation}\nwhere $\\Delta z$ is the element length scale in the vertical direction. \nThat is we apply the diffusion/viscosity only when dense fluid is on top of \nlight and the momentum equation becomes unstable, i.e. \n\\begin{equation}\nk= \\frac{1}{2}\\Delta t g (\\Delta z)^2 \\max{ \\{ \\frac{\\partial \\rho}{\\partial z}, 0\\} }.\n\\label{k-value}\n\\end{equation} \n\nWe now apply this diffusion to the vertical density as well as \nall other scalar fields in order to mix the fluid in the vertical. \nIn practice one may ignore the vertical viscosity but the vertical \nthis diffusion for density has the effect of mixing the dense fluid \non top of light within one time step so at the end of the time step \nthere is no negative bouancy forces. \n\nThe problem may also be viewed as a simple eigen-value problem:\n\\begin{equation}\n\\frac{\\partial w}{\\partial t} + \\rho g + 2\\frac{k_w}{(\\Delta z)^2} w= s_w,\n\\label{w-e-prob}\n\\end{equation} \n\\begin{equation}\n\\frac{\\partial \\rho}{\\partial t} - \n\\frac{\\partial \\rho}{\\partial z} w + 2\\frac{k_\\rho}{(\\Delta z)^2} \\rho= s_\\rho,\n\\label{rho-e-prob}\n\\end{equation} \nthat is:\n\\begin{equation}\n\\frac{\\partial \\Psi}{\\partial t} + H \\Psi = s_\\psi\n\\label{w-rho-e-prob}\n\\end{equation} \nwith \n\\begin{equation}\nH=  \\begin{pmatrix}\n   2\\frac{k_w}{(\\Delta z)^2}  &  g \\\\\n-\\frac{\\partial \\rho}{\\partial z}   &  2\\frac{k_\\rho}{(\\Delta z)^2} \n\\end{pmatrix} \n= L \\Lambda R, \n\\label{stab_matrix}\n\\end{equation}\nwith is the eigen-value decomposition into matrices \nof left $L$ and right $R$ eigen vectors and \ndiagonal matrix of eigen-values $\\Lambda$. For simplicity one may assume \n$k_w=0.$. \nThus, assuming homogeneous material properties: \n\\begin{equation}\n\\frac{\\partial \\hat \\Psi}{\\partial t} + \\Lambda \\hat\\Psi = \\hat s_\\psi, \n\\label{e-prob}\n\\end{equation} \nwith $\\hat\\Psi=R\\Psi$ and the instability will grow if any of the \neigen-values in $\\Lambda$ are negative. \n\n\n\n\\subsection{Non-symmetric pressure matrix}\nRather than testing the continuity equation with a finite element basis \nfunction $M_i$ we also have developed an option to test it with the \ncontrol volume basis function ${M_{CV}}_i$. The reason why this may be appropriate \nis that it is a natural partner to robust control-volume based \nadvection methods for temperature or density or passive tracer say. \nHowever, this is at the cost of having a non-symmetric pressure matrix. \n\n\n\n\n\\pagebreak\n\n\n\n\\section{Computational Implementation of the Multi-Phase flow Model}\n\\label{Computational Implementation} \n\nThis section outlines the issues associated with the \ncomputational implementation of the multi-phase flow model. \nThis includes ordering of the variables to achieve good computational \nperformance, the sparcity of the matrices. \n\n\\subsection{Ordering of the variables}\n\\label{Ordering} \nOur aim is to produce good CPU performance for multi-phase flow \nproblems with potentially a large number of phases. The ordering of \nthe variables reflects this aim. Here the inner loop represents variables that \nchange most rapidly. \nIn general these are order as follows: \n\n\\par\\noindent\nidim,iphase,iloc,ele\n\n\\par\\noindent\nor:\n\n\n\\par\\noindent\nidim, iphase, icv-nod\n\n\\par\\noindent\nin which:\n\\par\\noindent\n idim is the dimension index (from 1 to 3 for 3-D), \n\\par\\noindent\niphase is the phase index (from 1 to nphase - the number of phases), \n\\par\\noindent\nele is the element number, \n\\par\\noindent\niloc is the local node number for an element, \n\\par\\noindent\nicv-nod is the CV index.\n\nThe ele index comes before the local node number to help reduce indirect addressing \nas discontinuous element variations do not need indirect addressing when refering \nto information within an element - only between elements. \n\n\\subsubsection{CV variables} \nTracers, pressure, saturations/volume fractions are all CV centred variables. \nThe fastest loop of variables is from left(fastest) to right(slowest) is: \n\n\\par\\noindent\niphase, icv-nod\n\n\\par\\noindent\n{\\it CV matrix spacrities} \n\nThe sparcity patttern of the matrices for CV variables if the variables were written \nin the ordering: cv-inod, iphase, is for a 3 phase system: \n\n\\begin{equation}\n  \\begin{pmatrix}\n\\widetilde {ACV}_{11}  &  \\widetilde {DCV}_{12}  &  \\widetilde {DCV}_{13} \\\\\n\\widetilde {DCV}_{21}  &  \\widetilde {ACV}_{22}  &  \\widetilde {DCV}_{23} \\\\\n\\widetilde {DCV}_{31}  &  \\widetilde {DCV}_{32}  &  \\widetilde {ACV}_{33} \n  \\end{pmatrix}\n\\label{CV-mat-spar}\n\\end{equation}\n\nin which the matricies $\\widetilde {DCV}_{iphase\\; jphase}$ are diagonal and represent the \ncoupling between the phases and the matricies $\\widetilde {ACV}_{iphase\\; jphase}$ represent \na typical sparcity pattern of a CV single variable matrix i.e. in which control volumes are \ndirectly connected only to CVs next to them within the matrix structure. \n\nNor rearranging this ordering in the form of our prefered ordering:  iphase, icv-nod, \nthe matrix sparcity for 3-phase and a 2 CV system:\n\\begin{equation}\n  \\begin{pmatrix}\nACV_{11}  &  DCV_{12}   \\\\\nDCV_{21}  &  ACV_{22} \n  \\end{pmatrix}\n\\label{CV-mat-spar}\n\\end{equation}\nin which the matrices $ACV_{inode\\; jnode}$ and $DCV_{inode\\; jnode}$ are $nphase \\times nphase$ matrices and $DCV_{inode\\; jnode}$ \nis a diagonal matrix. \nFor \na two CV problem the matrix structure is (*-potentially a non-zero value): \n\n\\begin{equation}\n  \\begin{pmatrix}\n*  &  *  &  *      &   *   &  0  &  0  \\\\ \n*  &  *  &  *      &   0   &  *  &  0  \\\\ \n*  &  *  &  *      &   0   &  0  &  *  \\\\ \n%\n*  &  0  &  0      &   *   &  *  &  *  \\\\\n0  &  *  &  0      &   *   &  *  &  *  \\\\\n0  &  0  &  *      &   *   &  *  &  *  \n  \\end{pmatrix},\n\\label{optimal-CV-mat-spar}\n\\end{equation}\nand for three 1D CVs the matrix would typically look like: \n\n\\begin{equation}\n  \\begin{pmatrix}\n*  &  *  &  *      &   *   &  0  &  0    &   0   &  0  &  0   \\\\ \n*  &  *  &  *      &   0   &  *  &  0    &   0   &  0  &  0  \\\\ \n*  &  *  &  *      &   0   &  0  &  *    &   0   &  0  &  0  \\\\ \n%\n*  &  0  &  0      &   *   &  *  &  *    &   *   &  0  &  0  \\\\\n0  &  *  &  0      &   *   &  *  &  *    &   0   &  *  &  0  \\\\\n0  &  0  &  *      &   *   &  *  &  *    &   0   &  0  &  *  \\\\\n%\n0  &  0  &  0      &   *   &  0  &  0    &   *   &  *  &  *  \\\\\n0  &  0  &  0      &   0   &  *  &  0    &   *   &  *  &  *  \\\\\n0  &  0  &  0      &   0   &  0  &  *    &   *   &  *  &  *  \n  \\end{pmatrix},\n\\label{optimal-CV-mat-spar-3CV}\n\\end{equation}\nwith no coupling between CVs 1 and 3 and 2 couples directly with CVs \n1 and 3. \n\n\n\n\\subsubsection{Velocity variables} \nThe velocities are stored in the order: \n\\par\\noindent\nidim,iphase,iloc,ele\n\n\n\\par\\noindent\n{\\it Velocity matrix spacrities} \n\nThe sparcity patttern of the matrices for CV variables if the variables were written \nin the ordering: cv-inod, iphase, is for a 3 phase system:\n\\begin{equation}\n  \\begin{pmatrix}\nAV_{11}  &  DV_{12}  &  DV_{13} \\\\ \nDV_{21}  &  AV_{22}  &  DV_{23} \\\\\nDV_{31}  &  DV_{32}  &  AV_{33} \n  \\end{pmatrix}\n\\label{Vel-mat-spar}\n\\end{equation}\nin which the matricies $DV_{iphase\\; jphase}$ are block diagonal (each block representing \nthe coupling between variables of the same type within an element) and represent the \ncoupling between the phases and the matricies $AV_{iphase\\; jphase}$ represent \na typical sparcity pattern of a phase velocity matrix i.e. in which elements are \ndirectly connected only to elements next to them within the matrix structure. \nOrdering the variables for velocity: inode, idim, then the structure of the matricies $AV_{iphase\\; jphase}$ is \nfor a 3D problem:\n\\begin{equation}\n  \\begin{pmatrix}\nK_{11}  &  0  &  0 \\\\ \n0 &  K_{22}  &  0 \\\\\n0  &  0  &  K_{33} \n  \\end{pmatrix}\n\\label{Vel-1phase-mat-spar}\n\\end{equation}\nwhen there is no coupling between the velocitiy variables e.g. if tensor form of velocity is used and \nif there is this coupling then  $AV_{iphase\\;jphase}$ has the form: \n\\begin{equation}\n  \\begin{pmatrix}\nK_{11}  &  K_{12}  &  K_{13} \\\\ \nK_{21}  &  K_{22}  &  K_{23} \\\\ \nK_{31}  &  K_{32}  &  K_{33}  \n  \\end{pmatrix}\n\\label{Vel-1phase-stress-mat-spar}\n\\end{equation}\nin which the stctucutre of each of the matricies $K_{idim\\; jdim}$ is the same as \nfor a typical finite element system. So for continuous FEM nodes are connected in the sparcity \nif they share a finite element. For DG discretizations $K_{idim\\; jdim}$ has a block structure \neach block representing the variables within an element. Thus, one only needs an element connectivity \nlist to manipulate the matrices $K_{idim\\; jdim}$. \n\n\nNow rearranging this ordering in the form of our prefered ordering: idim, iphase, iloc, ele\n, \nthe matrix sparcity for 3-phase and a 2 element system system:\n\n\\begin{equation}\n  \\begin{pmatrix}\n*  &  *  &  *      &   *   &  0  &  0  \\\\ \n*  &  *  &  *      &   0   &  *  &  0  \\\\ \n*  &  *  &  *      &   0   &  0  &  *  \\\\ \n%\n*  &  0  &  0      &   *   &  *  &  *  \\\\\n0  &  *  &  0      &   *   &  *  &  *  \\\\\n0  &  0  &  *      &   *   &  *  &  *  \n  \\end{pmatrix}\n\\label{Vel-Mphase-mat-spar}\n\\end{equation}\nin which the matrix entries above represent block matricies of size (ndim$\\times$nphase$\\times$nloc) \n$\\times$  (ndim$\\times$nphase$\\times$nloc).  \n\n\n\\par\\noindent\n{\\it Overlapping FEM velocity representation} \n\\par\\noindent\nWhen we use an overlapping FEM approach we have a FEM representation of \nvelocity associated with each CV of the element. All of these velocities are stored \ntogether for a given element. So the same ordering: \n\\par\\noindent\nidim,iphase,iloc,ele\n\n\\par\\noindent\nstill applies. However the local node iloc now is formed from \na local node number for the velocity nodes, say veliloc, and \na control volume node, cviloc say, and  \n\\par\\noindent\niloc=(cviloc-1)*velnloc + veliloc\n\n\\par\\noindent\nin which velonloc equals the number of velocity nodes that are used \nto describe the velocity distribution for a given control volume. \nThus, for a P1DG-P2 element in 2D velnloc=3 and in 3D velnloc=4. \n\n\n\n\\pagebreak\n\n\n\n\\section{Mesh to mesh interpolation}\n\\label{Mesh to mesh interpolation}\n\nThis section outlines how mesh to mesh interpolation is performed. \n\n\n\\subsection{Galerkin projections}\n\\label{Galerkin projections}\nFor the velocity field, generally, a standard conservative Galerkin projection \nfrom the old mesh solution $\\psi^{old}$ to the new mesh solution $\\psi^{new}$ is applied:\n\n\\begin{equation}\n\\int N_i^{new} ( \\psi^{new} -\\psi^{old} ) dV=0, \\forall i \\in\\{1,2,...,\\cal{N} \\}\n\\label{Vel-interpolation}\n\\end{equation}\nin which $N_i^{new}$ is the basis functions associated with velocity and $\\psi$ is one \nof the velocity components say. The superscript $new$ indicates the variables are formed on the new mesh and \nsuperscript $old$ indicates the variables are formed on the old mesh. \nAlso $\\psi^{new}=\\sum_j N_j^{new} \\psi_j^{new}$,  $\\psi^{old}=\\sum_j N_j^{old} \\psi_j^{old}$. Other variables that live on the velocity mesh are interpolated \nin the same way and in fact all FEM fields are interpolated in this way. \n\nFor other variables like saturatuation/volume fraction or interface indicator fields which \nhave a control volume CV representation are interpolated by first mapping them to \na DG FEM representation within an element (even if they have a continuous between \nelements representation): \n\\begin{equation}\n\\int {M_{CVDG}^{old}}_i (\\psi_{DG}^{old} - \\psi_{CV}^{old} ) dV =0, \n\\label{cv-old 2 dg-old}\n\\end{equation}\nin which the test function ${M_{CVDG}^{old}}_i$ is a CV test function that is discontinuous between elements. \nThe number of test functions ${M_{CVDG}^{old}}_i, \\forall i \\in\\{1,2,...,{\\cal{M}_{DG}} \\}$ is equal to the number of \nDiscontinuous Galerkin DG basis functions ${M_{DG}^{old}}_j, \\forall j \\in\\{1,2,...,{\\cal{M}_{DG}} \\}$ thus resulting in a solvable system \nof equations, \\ref{cv-old 2 dg-old}. \nThe resulting FEM representation $\\psi_{DG}^{old} =\\sum_j {M_{DG}^{old}}_j {\\psi_{DG}^{old}}_j$ interpolating \nthe control volume field $\\psi_{CV}^{old} =\\sum_j {M_{CV}^{old}}_j {\\psi_{CV}^{old}}_j$  can \nthen be used within a strictly FEM mapping from the old mesh to the new mesh (greatly simplifying  \nthe implementation of this mapping): \n\\begin{equation}\n\\int {M_{DG}^{new}}_i (\\psi_{DG}^{new} - \\psi_{DG}^{old} ) dV =0. \n\\label{dg-old 2 dg-new}\n\\end{equation}\nThe resulting DG FEM representation, $\\psi_{DG}^{new}=\\sum_j {M_{DG}}^{new}_j {\\psi_{DG}}_j^{new}$, on the new mesh \nis mapped back to the CV representation,  \n$\\psi_{CV}^{new}=\\sum_j {M_{CV}}^{new}_j {\\psi_{CV}}_j^{new}$, \non the new mesh with: \n\\begin{equation}\n\\int {M_{CV}^{new}}_i (\\psi_{CV}^{new} - \\psi_{DG}^{new} ) dV =0. \n\\label{cv-new 2 dg-new}\n\\end{equation}\nA DG FEM representation, within the mapping, is used \nrather then a continuous FEM representation as it is more accurate and does not \npropergate Gibbs oscillations beyond an element. The use of the local variables and basis \nfunctions (local to an element) in equation \\ref{cv-old 2 dg-old} means that these equations can be solved local to each element. \nSimilarly, in equation \\ref{cv-new 2 dg-new}, the resulting diagonal mass matrix means there is only a trival \nmatrix equation to solve. \nIts worth noting that the above mapping procedure (equations \\ref{cv-old 2 dg-old}, \\ref{dg-old 2 dg-new}, \\ref{cv-new 2 dg-new}) does not change the interpolant (that is $\\psi_{CV}^{new} = \\psi_{CV}^{old}$) if the \nold and the new mesh happen to be the same or are locally the same or unchanged. \nThis is easy to see (using equations \\ref{cv-old 2 dg-old}, \\ref{dg-old 2 dg-new}, \\ref{cv-new 2 dg-new}),    \nwhen the new and the old meshes are the same, because:\n\\begin{equation}\n\\int {M_{CV}^{new}}_i \\psi_{CV}^{new} dV = \n\\int {M_{CV}^{new}}_i \\psi_{DG}^{new} dV =\n\\int  {M_{CV}^{old}}_i \\psi_{DG}^{old} dV \n\\end{equation}\n\\begin{equation}\n=\n\\sum_{k\\in CVDGcontain\\{i\\} } \\int  {M_{CVDG}^{old}}_k \\psi_{DG}^{old} dV =\n\\sum_{k\\in CVDGcontain\\{i\\} } \\int  {M_{CVDG}^{old}}_k \\psi_{CV}^{old} dV =\n\\int  {M_{CV}^{old}}_i \\psi_{CV}^{old}  dV\n\\label{proof-of-being-cv-unchanged}\n\\end{equation}\nand thus $\\int {M_{CV}^{new}}_i \\psi_{CV}^{new} dV =\\int  {M_{CV}^{old}}_i \\psi_{CV}^{old} ) dV$ \nor ${\\psi_{CV}^{new}}_i={\\psi_{CV}^{old}}_i$. \nIn equations \\ref{proof-of-being-cv-unchanged} the set $CVDGcontain\\{i\\}$ contains all the \nCVDG's that are inside CV $i$. \n\n\n\n\\subsection{Bounded solution corrections}\n\\label{Bounded solution corrections}\nTo measure the deviation from boundedness, define \nfield ${{\\psi_{CV}^{new}}_{dev}}_k$ CV-wise such that at each CV $k\\in\\{1,2,...,{\\cal M}^{new}_{\\cal CV}\\}$: \n\\begin{equation}\n{{\\psi_{CV}}^{new}_{dev}}_k=\n  \\begin{cases}\n    {\\psi_{CV}^{new}}_k - {{\\psi_{CV}^{new}}_{max}}_k, & \\text{if} \\\n    {\\psi_{CV}^{new}}_k> {{\\psi_{CV}^{new}}_{max}}_k; \\\\\n    {\\psi_{CV}^{new}}_k -{{\\psi_{CV}^{new}}_{min}}_k, & \\text{if} \\\n    {\\psi_{CV}^{new}}_k< {{\\psi_{CV}^{new}}_{min}}_k; \\\\\n    0,  & \\text{otherwise},\n  \\end{cases}\n\\label{q_dev}\n\\end{equation}\nso that boundedness is achieved when ${{\\psi_{CV}^{new}}_{dev}}_k=0, \\forall k\\in\\{1,2,...,{\\cal M}^{new}_{\\cal CV}\\}$. Here, \na CV, $k$ say, has absorptive capacity if ${{\\psi_{CV}^{new}}}_k$\nlies strictly within the solution bounds $({{\\psi_{CV}^{new}}_{min}}_k,{{\\psi_{CV}^{new}}_{max}}_k)$. \nThe algorithm effectively applies diffusion to the deviation field to \nspread it to the CV with absorptive capacity. This is done in such a \nway that maintains the integral of the interpolant ${\\psi_{CV}^{new}}$. \n\nAt each iteration, a new vector ${\\underline\\psi_{CV}^{new}}_{alt} =( {{\\psi_{CV}^{new}}_{alt}}_1,{{\\psi_{CV}^{new}}_{alt}}_2, ...,  {{\\psi_{CV}^{new}}_{alt}}_{\\cal M_{CV}})^T$ is solved for such that: \n\\begin{equation}\n{\\bf M}_L {\\underline\\psi_{CV}^{new}}_{alt} = {\\bf M} {\\underline\\psi_{CV}^{new}}_{dev} .\n\\label{q_alt}\n\\end{equation}\nThis operation is trivial due to the use of the diagonal mass matrix ${\\bf M}_L$. \nSince the distributed mass matrix $\\bf M$ is not diagonally dominant (see below) \na relaxation coefficient $w=\\frac{1}{2}$ is introduced such that: \n\\begin{equation}\n{\\underline\\psi_{CV}^{new}}_{alt} \\leftarrow w {\\underline\\psi_{CV}^{new}}_{alt}+(1-w) {\\underline\\psi_{CV}^{new}}_{dev}. \n\\label{q_alt_relax}\n\\end{equation}\nThe interpolant vector $\\underline\\psi_{CV}^{new}$ is then modified using: \n\\begin{equation}\n\\underline\\psi_{CV}^{new} \\leftarrow \\underline\\psi_{CV}^{new} - {\\underline\\psi_{CV}^{new}}_{dev} + {\\underline\\psi_{CV}^{new}}_{alt} . \n\\label{q_update}\n\\end{equation}\nThis operation has no effect on the integral of $\\psi_{CV}^{new}$. \nSuppose ${m_{CV}}_i$ is the volumes of CV $i$  \nand ${m_{SUR}}_i$ contains the sum of the volumes of the surrounding control volumes such that:\n\\begin{equation}\n{m_{SUR}}_i = \\sum_{k\\in neig\\{i\\}} {m_{CV}}_k\n\\label{m_sur}\n\\end{equation}\nwith $neig\\{i\\}$ defining the control volumes that share a face with control volume $i$ including CV $i$, \nand the  \nmass matrix is defined here as: \n\\begin{equation}\n{\\bf M}_{ij} =  \n  \\begin{cases}\n   \\frac{  {m_{CV}}_i }{ {m_{SUR}}_j} {m_{CV}}_j, & \\text{if} \\\n    j\\in neig\\{i\\}; \\\\\n    0,  & \\text{otherwise},\n  \\end{cases}\n\\label{M-def}\n\\end{equation}\nand\n\\begin{equation}\n{{\\bf M}_L}_{ij} =  \n  \\begin{cases}\n   {m_{CV}}_i, & \\text{if} \\\n    i=j ; \\\\\n    0,  & \\text{otherwise}.\n  \\end{cases}\n\\label{ML-def}\n\\end{equation}\n\nThe major problem with this iterative scheme is that it substantially adjusts the CVs \nthat are bounded. This tendancy can be reduced by sweeping though each CV $k$, say, \nand finding the neighbouring CVs, to CV $k$, with the maximum +ve defect adjustment needed and \nthe minium -ve defect adjustment needed, $i$ and $j$ say and exchanging masses between theses \n(repeating this process until no mass adjustment can be made for this CV $k$ and \nmove onto next next CV):  \n\n\\par\\noindent\n1) Form ${{\\psi_{CV}}^{new}_{dev}}_i$ and ${{\\psi_{CV}}^{new}_{dev}}_j$ from equation \n\\ref{q_dev}. \n\n\\par\\noindent\n2) For CVs $i$ and $j$ set: \n\\begin{equation}\n{\\psi^{new}_{alt}}_i \\leftarrow {\\psi^{new}_{dev}}_i, \\;\\;\\;  {\\psi^{new}_{alt}}_j \\leftarrow {\\psi^{new}_{dev}}_j .\n\\end{equation}\n\n\\par\\noindent\n3) If $\n{\\psi^{new}_{alt}}_i\n{\\psi^{new}_{alt}}_j  < 0 $ (share mass if the necessary mass adjustments in both CVs have opposit signs) \n\\begin{equation}\n\\text{then} \\;\\;\\; \n  \\begin{cases}\n {\\psi^{new}_{alt}}_i \\leftarrow \\frac{({\\psi^{new}_{alt}}_i {m_{CV}}_i+ {\\psi^{new}_{alt}}_j {m_{CV}}_j)}{{m_{CV}}_i} \n\\;\\;\\;\n\\text{and} \\ {\\psi^{new}_{alt}}_j \\leftarrow 0\n, \n& \\text{if} \\\n{{\\psi^{new}_{alt}}_i {m_{CV}}_i> {\\psi^{new}_{alt}}_j {m_{CV}}_j}\n; \\\\\n{\\psi^{new}_{alt}}_j \\leftarrow\\frac{({\\psi^{new}_{alt}}_i {m_{CV}}_i+ {\\psi^{new}_{alt}}_j {m_{CV}}_j)}{{m_{CV}}_j}\n\\;\\;\\;\n\\text{and} \\ {\\psi^{new}_{alt}}_i \\leftarrow 0,\n     &  \\text{otherwise}, \n  \\end{cases}\n\\label{a_ij -alt}\n\\end{equation}\n\\begin{equation}\n\\text{and}\\;\\;\\; \n{\\psi_{CV}^{new}}_i \\leftarrow {\\psi_{CV}^{new}}_i - {{\\psi_{CV}^{new}}_{dev}}_i + {{\\psi_{CV}^{new}}_{alt}}_i, \n\\end{equation}\n\\begin{equation}\n\\text{and}\\;\\;\\;\n{\\psi_{CV}^{new}}_j \\leftarrow {\\psi_{CV}^{new}}_j - {{\\psi_{CV}^{new}}_{dev}}_j + {{\\psi_{CV}^{new}}_{alt}}_j. \n\\end{equation}\nThe mass adjustment associated with step 3 above takes the CV with the minimal needed mass adjustment, \nthat is CV $j$ if ${{\\psi^{new}_{alt}}_i {m_{CV}}_i> {\\psi^{new}_{alt}}_j {m_{CV}}_j}$ and CV $i$ otherwise, \nand adds its mass deficiency (-ve or +ve mass) to the other CV reducing the other CVs mass deficiency and \neliminating the first CVs mass deficiency, hence \neither ${\\psi^{new}_{alt}}_i \\leftarrow 0$  or ${\\psi^{new}_{alt}}_j \\leftarrow 0$.\n\nThis algorithm may not be abe to eliminate all the mass deficiencies and \nthus needs to be combined with the \nsimilar mass adjustment shown in equation \\ref{q_alt}. \nFor the parallel implementation of this mass adjustment algorithm it is suggested that \none ignores the CVs that are not stictly on the current processor, iterate on the above, then exchange halo CV information.  \n\n\n\\pagebreak\n\\section{A backtracking two-fixed point iteration solver with acceleration}\n\\label{Non-linear_solver_backtracking}\nTo solve the non-linear system of equations formed by the momentum equation, the saturation equation and saturations sum to one, a FPI method is considered. First an estimated pressure solution is obtained, then an estimated velocity, and finally an estimated saturation. The solver iterates until a certain pre-defined saturation tolerance is reached, in which case the size of the next time step may be increased, or until a pre-determined maximum number of non-linear iterations is reached, in which case the current solution is disposed of, the time step size is decreased and the time-level is repeated with the new time step size.\n\nThe fact that the pressure field change is slower than the saturation field has been used to artificially obtain Courant numbers over unity using IMPES (implicit pressure explicit saturation) formulations. Here, an equivalent approach is used in order to reduce the computational cost. As the pressure field change is slower than the saturation field, recalculating ${\\underline {\\underline \\sigma}}_{\\alpha}$ with the new estimation of the saturation ${S^\\prime_k}$ provides a good approximation to recalculate the velocity.\nThis implies that an extra FPI can be performed in order to increase the speed of the method. Fig.~\\ref{fig:flow_chart} shows the algorithm used to solve a problem. Three loops are considered. The solid-line loop is the time loop. The dotted-line loop is the classical FPI loop. The dashed-line loop is another FPI loop, whose computational cost is approximately a third of a conventional FPI. The last one, only loops over the saturation. Thus, it is denoted as Saturation Fixed Point Iteration (SFPI). \n\n\\begin{figure}[h!]\n  \\begin{center}\n    \\includegraphics[width=0.50\\textwidth]{figures/high_courant.png}\n    \\caption{Flow chart showing the steps of the algorithm. There are three main loops in total. The solid-line loop is the time loop. The dotted-line loop is the fixed point iteration method, which is used to solve the non-linear system of equations, the dashed-line loop is the saturation fixed point iteration, which is used to accelerate the FPI. \\label{fig:flow_chart}}\n  \\end{center}\n\\end{figure}\n\nThe non-linearity of this system of equations depends only on the saturation equation. Thus, only a post-processing step is required in order to stabilize the equations and increase the resilience and convergence of the non-linear solver.\n\nIn the post-processing step, after calculating the saturation fields, a solution is sought in a trust region by forcing the solution to fulfil the physical restrictions of the solution. Instead of seeking for a solution in the whole spectrum of $\\cal R$, a solution is sought in the normalized saturation range, $[0,1]$. This is done by forcing the values obtained after solving the saturation equation to be in that range.\n\nThe common lore claims that a relaxation parameter can be used to increase the convergence of a solver, moreover, for non-linear solvers, like in the Newton-Armijo solver, it is a common procedure to obtain global convergence instead of local convergence. Thus, a relaxation parameter is used in order to improve the convergence of the FPI. However, a relaxation parameter may lead to slower convergences, therefore, acceleration techniques are necessary to alleviate this issue. A modified Anderson acceleration is considered here.\nThe new value of saturation obtained after solving the saturation equation is relaxed using the last two values of saturation inside the SFPI using the following formula:\n\\begin{equation}\n{S^\\prime_k} = \\varphi S_k + (1-\\varphi) [ (1-(1-\\varphi)^\\beta \\varphi) S_{k_1} + (1-\\varphi)^\\beta \\varphi S_{k_2}],\n\\label{eq:relax_method}\n\\end{equation}\nin which $\\varphi$ is the relaxation parameter, $S_{k}$ is the value of saturation obtained at this SFPI before relaxing it, $S_{k_1}$ and $S_{k_2}$ are the saturations obtained in the previous SPFI and the saturation obtained before $S_{k_1}$ respectively. \nNormally, the weights for previous $S_{k_i}$ to obtain ${S^\\prime_k}$ are obtained by solving an optimization problem. However, this implies solving an extra system and the storage of more data. \nHere, Eq.~\\ref{eq:relax_method} is used to obtain the different weights for $S_{k_i}$ without having to find an optimal of a system. \n$\\beta$ is the exponent that change the relative importance of $S_{k_1}$ and $S_{k_2}$ depending on the input $\\varphi$. For small values of $\\beta$ the relative importance of $S_{k_2}$ is increased even over $S_{k_1}$ (see Fig.~\\ref{fig:alpha_ratio} (left)), for medium values Fig.~\\ref{fig:alpha_ratio} (center) $S_{k_2}$ is always below $S_{k_1}$ and for high values of $\\beta$ $S_{k_2}$ tends to be less important. The shape of the curve formed for the weight of $S_{k_2}$ (see Fig.~\\ref{fig:alpha_ratio}), is asymmetric, being higher for smaller values of $\\varphi$, when convergence is slow, and the system is more likely to be oscillating, than for high values of $\\varphi$ when the system is converging nicely and no acceleration is required. Also, Eq.~\\ref{eq:relax_method} guarantees a small contribution of $S_{k_2}$ which is important as this acceleration technique diverge. Moreover, in order to encourage an stable behaviour of the solution, the last iteration of the SFPI is always performed without acceleration, i.e. the weight of $S_{k_2}$ is zero.\n\n\n\\begin{figure}[h!]\n{\\includegraphics[width=0.33\\textwidth]{figures/phi_ratio_0.png}}\n{\\includegraphics[width=0.33\\textwidth]{figures/phi_ratio_04.png}}\n{\\includegraphics[width=0.33\\textwidth]{figures/phi_ratio_5.png}}\n\\caption{Weight of the different saturations, $S_{k_i}$, used to obtain the new ${S^\\prime_k}$ depending on the relaxation parameter $\\varphi$ for different values of $\\beta.$ left)Shows a big importance of $S_{k_2}$, even more important than $S_{k_1}$. center) $S_{k_2}$ is always less important than $S_{k_1}$ right) $S_{k_2}$ is barely considered}\n    \\label{fig:alpha_ratio}\n\\end{figure} \n\nRegarding the calculation of the relaxation parameter $\\varphi$ to optimize convergence, some authors calculate it in advance based on information about the flow and the gravity number, other options are based on using the history of the convergence to calculate the optimal parameter. Here, the interest is in moderately large Courant numbers and therefore a method based on the history of convergence provides good results. \n\nThe relaxation parameter $\\varphi$ is re-started every FPI to be the value prescribed by the user and within the SFPI it is calculated as the value that yields the best convergence ratio based on the residual. To this end, the last three values of the ratio of convergence of the residual are stored together with their corresponding $\\varphi$ value. Next a minima is searched using the history of convergence. The main disadvantage of this algorithm is that it is bounded between the value introduced by the user and a minimum value. To avoid this, when no minima can be obtained, the algorithm calculates the new $\\varphi$ solely based on the last value and its consequent convergence. In this way, $\\varphi$ is increased if the convergence improves and if otherwise, decreased. This guarantees that the algorithm goes through all the possible values between $1$ and $0.1$. \n\nTo check convergence the $L_2^2$ norm of the size of the correction over all the elements is tested: \n\\begin{equation}\nf(S) = \\sum_i^N \\left( \\frac{{S^\\prime_k} - S_{k_1}}{\\varphi N} \\right)^2,\n\\label{eq:functional}\n\\end{equation}\nwhere $N$ is the total number of nodes. This criterion works for FPI, specially for spiral-wise convergence, and it requires less computations than calculating the residual.\nAs stopping criteria for the main FPI, the solver iterates until the functional defined in Eq.~\\ref{eq:functional} reaches the tolerance defined by the user, as shown in Fig.~\\ref{fig:flow_chart}, or the maximum number of FPI is reached.\nThe stopping criterion for the SPFI is the same as for the FPI in terms of tolerance, however, the number of iterations is very restricted as it may not be converging to the ''real'' solution, since the pressure is not updated.\n\n\\pagebreak\n\n\n\\section{Advection-diffusion applications}\n\\label{Advection-diffusion applications} \n\nThe aim of this section is to demonstrate the performance of the \ncontrol volume FEM approach to solving advection diffusion equations. \nThree control volumes are within each finite element \nand these are interpolating using a quadratic finite element \nmethod basis function. The fem provides the high order \nflux which is limited as described previously.  \nTo this end we solve the one dimensional advection diffusion equation:\n\n\\begin{equation} \n\\frac{\\partial T}{\\partial t} + \\frac{\\partial u T}{\\partial x} \n- \\frac{\\partial k \\frac{\\partial T }{\\partial x}}{\\partial x} =0\n\\end{equation}\n\nwith a domain $x\\in \\left[0,1\\right]$ boundary condition of $T=1$ on the left hand boundary \n$k\\frac{\\partial T }{\\partial x}=0$ on the right boundary and $u=1$. \nMost simulations will use $k=0$ appart from one in which $k=0.01$ \nand use an initial $T$ of $T=1 \\forall x\\in \\left[ 0.2, 0.4 \\right]$ \notherwise $T=0$.  \n\nThe results hsown in figure \\ref{compar-dg} show the spatial accuracy \nwith a small (converged) time step size. The advection results at \nthe end of the simulation in which a profile has been advected a distance \nof 0.2 are shown in this figure for both both the continuous between \nthe elements approach and the discontinuous approach and 5 elements. \nThe discontinuous approach uses the default upwind flux between \nthe elements. The accuracy can be gauged by comparing with a 50 \ndiscontinuous between element solution. \nThe control volume solutions are shown as well as the consistent finite \nelement interpolation of this solution which is used to obtain the \nhigh order fluxes - between the elements and within each element. \nBoth the discontinuous between elements (DG) and continuous \nperform well with the DG solution better able to represent \nthe discontinuouties. \n\nIn figure \\ref{compar-dg-bdt} we have increased the Courant number ($\\frac{u \\Delta t}{\\Delta x}$)  based on the \nelement size to ${\\Delta x}=0.5$. The Courant number based on the smallest \ncontrol volume is $2$. Thus, this represents and large time step. \nAnd we perform two time steps which is a difficult test \nof the non-linear $\\theta$ time stepping method. \nNotice that due to the large time \nsteps the solution is more dissipative, but again the \ndiscontinuous between element solution is more accurate. \nWe the same problem we introduce a diffusion coefficient \nof $k=0.01$ and the results are shown in figure \n\\ref{compar-dg-bdt-diff} and \nas one might exepect this result is more dissipative. \nThe result without diffusion is also shown on the same graph. \nThis tests the non-linear diffusion scheme. \nFor this large time step problem and for the continuous between \nelements, discontinuous between elements and the problem with diffusion \nthe value of $\\theta$ on the faces of the control volumes is shown \nat the end of the two time steps in figure \\ref{theta-bdt}. \nNotice that the value of $\\theta$ is smaller and closer to $0.5$ \n(second order accuracy in time) when using the continuous approach. \nWe speculate that this is due to the larger control volumes and \nthus smaller Courant number based on the control volume size. \nThe addition of diffusion seems to increase the value of $\\theta$ \naway from 0.5. \n\nFor the advection of an initial Gaussian \nprofile $\\exp{( \\frac{(x-0.6)}{0.2} )^2}$ \nwith a left boundary condition of $T=1$ a convergence study was performed using \nthe discontinuous between element approach. Both the \ncontrol volume solutions and interpolated finite element solutions \nare shown in figure \\ref{converg} for various numbers of elements. \nThe method rapidly converges to the exact solution. However, it tends \nto round off the top of the Gaussian due to the limiting detecting an \nextrema here which results in a dissipative first order upwind scheme \nin this region. \n\nThe finite element interpolations for three schemes and \n5 and 20 elements are shown in \\ref{converg-compare-fem}. \nThe first two schemes are the continuous and discontinuous between \nthe elements approaches. \nThe third scheme uses a central difference (mean of the solutions \neither side of an element boundary) method to calculate the \nflux between the elements and has a discontinuous solution between \nthe elements. This figure provides a gauge of the accuracy between \nthe methods and shows that although all method perform similarly, \nthe central difference approach with discontinuoity between \nelements is best able to represent the discontinuous analytical solution. \n\n\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/compar-dg}\n\\end{center}\n\\vspace{0.cm}}\n\\caption{Comparison of discontinuous and continuous (between elements) \ncontrol volume solution for a pure advection problem (from left to right) - 5 finite elements are used and the Courant number (based on the element width of 0.2) \nis 0.005. The solution has been advected a distance of 0.2 with 200 time steps. The 50 element solution is shown to give an indication of the accuracy of the solutions.}\n\\label{compar-dg}\n\\end{figure}\n\n\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/compar-dg-bdt}\n\\end{center}\n\\vspace{0.cm}}\n\\caption{Comparison of discontinuous and continuous (between elements) \ncontrol volume solution for a pure advection problem (from left to right) - 5 finite elements are used and the Courant number (based on the element width of 0.2) \nis 0.5 (2 based on the minimum width of a control volume). \nThe solution has been advected a distance of 0.2 with 2 time steps. The 50 element solution is shown to give an indication of the accuracy of the solutions and has a Courant number (based on the element width) of 0.005. }\n\\label{compar-dg-bdt}\n\\end{figure}\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/compar-dg-bdt-diff}\n\\end{center}\n\\vspace{0.cm}}\n\\caption{The effect of diffusion using a discontinuous (between elements) \ncontrol volume solution for an advection problem (from left to right) - 5 finite elements are used and the Courant number (based on the element width of 0.2) \nis 0.5 (2 based on the minimum width of a control volume). \nThe solution has been advected a distance of 0.2 with 2 time steps. The 50 element solution is for pure advection and is shown to give an indication of the accuracy of the solutions and has a Courant number (based on the element width) of 0.005. }\n\\label{compar-dg-bdt-diff}\n\\end{figure}\n\n\n\n\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/theta-bdt}\n\\end{center}\n\\vspace{0.cm}}\n\\caption{Value of the $\\theta$ 'theta' time stepping parameter on the faces of the control volumes at the end of the \nsimulation  - 5 finite elements are used and the Courant number (based on the element width of 0.2) \nis 0.5 (2 based on the minimum width of a control volume). \nThe solution has been advected a distance of 0.2 with 2 time steps.  }\n\\label{theta-bdt}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\hbox{\n\\hspace{-1.cm}\n\\includegraphics[width=9.0cm,height=9.cm]{./doc_figures/converg-cv}\n\\hspace{-1.cm}\n\\includegraphics[width=9.0cm,height=9.cm]{./doc_figures/converg-fem}\n}\n\\vspace{-0.cm}\n\\hbox{\\hspace{4.cm}(a) \\hspace{6.5cm}(b)}\n\\vspace{-0.cm}}\n\\label{converg}\n\\caption{Convergence of the solutions with discontinuity between elements and with increased resolution. A pure advection problem (from left to right) - the Courant number  \nis 0.005. The solution has been advected a distance of 0.2. (a) the control volume solutions are shown. (b) the FEM interpolation of the control volume solutions are shown. }\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\vbox{\n\\begin{center}\n\\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/converg-compare-fem}\n\\end{center}\n\\vspace{0.cm}}\n\\caption{Comparison of convergence of the solutions with and without discontinuity between elements and with an upwind and central difference flux between the elements and with increased resolution. A pure advection problem (from left to right) - the Courant number  \nis 0.005. The solution has been advected a distance of 0.2. The FEM interpolation of the control volume solutions are shown.  }\n\\label{converg-compare-fem}\n\\end{figure}\n\n\n", "meta": {"hexsha": "395b834c106fc96efc8112038b78a5f05f2c0445", "size": 385771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "software/multifluids_icferst/legacy_reservoir_prototype/doc/model_description.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/legacy_reservoir_prototype/doc/model_description.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/legacy_reservoir_prototype/doc/model_description.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": 43.5948694768, "max_line_length": 1126, "alphanum_fraction": 0.7031736445, "num_tokens": 125847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6213787328680396}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{``Undo''}\n\n\\objective{Find and graph function inverses and their derivatives.}\n\n\nWe have seen that functions can be redefined as the composition of other, simpler\nfunctions.  For example, $\\frac{x^2+1}{2}$ can be seen as 1) squaring, 2) adding 1\n, and 3) dividing by 2.  What if we wanted to ``undo'' the effects of this function?\nWe cannot simply do the opposite of each operation ($\\frac{\\sqrt{x} -1}{2}$ is not\nthe inverse) but must do the opposites \\emph{backwards}.  This is called the\n\\textbf{inverse} of the function.  \n\n\\subsection{Swap $x$ and $y$}\nIn the example already mentioned, the inverse is $\\pm\\sqrt{2x-1}$.  What is wrong with \nthis inverse?  It is not a function.  No even power has an inverse which is a function, because\nthere are infinitely many places where a particular output is reached from two different inputs.\nAnother way to think of inverses is reversing $x$ and $y$, making the output the input and\nvisa versa.  Only \\textbf{one-to-one} functions --- where every $x$ has a \\emph{unique}\n$y$ --- will have inverses which are themselves functions.\n\nNumerically, this shows how easy it is to construct an inverse of data: simply swap the\ncolumn labels for input and output!   This can be done algebraically too.  Staying with\nthe same example, we could follow the procedure of 1) swapping $x$ and $y$, and then\n2) solving for $y$ to find the inverse of a function.\n\n\\begin{align*}\n\ty &= (x^2+1)/2 \\\\\n\tx &= (y^2+1)/2\\\\\n\t2x &= y^2+1\\\\\n\t2x - 1 &= y^2 \\\\\n\t\\pm\\sqrt{2x-1} &= y\\\\\n\\end{align*}\n\n\\subsection{S.I.F.T.}\nBut such examples fail when there are multiple places where $x$ appears in the equation\nof $y$.  How can we find the inverse of $y=\\sqrt{\\frac{x-1}{2-x}}$  A helpful acronym to \nremember is such cases is S.I.F.T., which standard for\n\\begin{itemize}\n\\item[\\textbf{S}pread] Clear the fractions, exponentiate the roots away, distribute the parentheses, etc.\n\\item[\\textbf{I}solate] Move all the terms with the desired variable onto one side of the equation, and move all the other terms to the opposite side.\n\\item[\\textbf{F}actor] Factor out the desired variable from all the terms on its side\n\\item[\\textbf{T}ransfer] Divide off the term in parentheses, leaving the variable alone.\n\\end{itemize}\nReturning to our hard example:\n\n\\begin{align*}\n\ty  &= \\sqrt{\\frac{x-1}{2-x}}\\\\\n\tx  &= \\sqrt{\\frac{y-1}{2-y}}\\\\\n\tx^2 &= \\frac{y-1}{2-y}\\\\\n\tx^2(2-y) &= y-1 \\\\\n\t2x^2-x^2y &= y-1 &\\text{finally spread out}\\\\\n\t2x^2 + 1 &= y + x^2y & \\text{$y$ is isolated on the right}\\\\\n\t2x^2 + 1 &= y(1+x^2) & \\text{factored out $y$}\\\\\n\t\\frac{2x^2+1}{1+x^2} &= y & \\text{transferred}\n\\end{align*}\n\n\n\\subsection{Graphically}\nInverses --- whether they are a function or not --- are a reflection across the line $y=x$.\nThis leads to some amazing properties of there derivatives.\n\nConsider the function $f(x) = (x-1)^3+4$, a simple cubic function, shift right 1 and up 4.\nIt's derivative is easy to calculate: $f'(x)=3(x-1)^2$.  It's inverse somewhat more complicated,\nbut perhaps it is enough to sketch it, swapping $x$ and $y$ at every point, reflecting it over\nthe line $y=x$.\n\n\\begin{figure}[h]\n\\begin{centering}\n\\begin{tikzpicture}[scale=0.3]\n\\draw[help lines] (-10,-10) grid (10,10);\n\\draw[<->] (-10.2,0) -- (10.2,0) node[anchor=west] {$x$};\n\\draw[<->] (0,-10.2) -- (0,10.2) node[anchor=south] {$y$};\n\\draw[dashed] (-10,-10) -- (10,10);\n\\draw[domain=-1.45:2.85,ultra thick,<->,samples=200,smooth,blue] plot (\\x,{(\\x-1)^3+4});\n\\draw[<->,domain=-1.44:2.85,samples=200,smooth,red,ultra thick]plot({(\\x-1)*(\\x-1)*(\\x-1)+4},\\x);\n\\end{tikzpicture}\n\\caption[Graphical example of inverses]{A function and its inverse, which are clearly reflections of each other across the line $y=x$.}\n\\end{centering}\n\\end{figure}\n\nThis can be done easily on the TI-8*.   First, enter the original function in $Y_1$ and graph\nit.  Be sire you have a window appropriate to the function and it's inverse!  Next, select DRAW\nand choose option 8: DrawInv, passing it the argument $Y_1$.  Press ENTER and \nyou will be able to see the inverse.  Unfortunately, we cannot TRACE along it or any of the \nother tools we are used to for functions, but that hardly matters.  \n\nConsider the tangent line through (2,5) on the original graph.  Hopefully, it is easy for\nyou to calculate that it follows the equation $y-5=3(x-2)$.  Enter this as $Y_2$.\nHave the TI-8* draw its inverse.  This second line will pass through the point (5,2)\nand have a reciprocal slope: $\\frac{1}{3}$.\n\nThis shows that the derivative of the inverse is equal to the reciprocal of the derivate,\nfor every point $(x,y)$ which has been mapped onto $(y,x)$.\n\\index{derivative!of the inverse}\n", "meta": {"hexsha": "9507671f4fd7733b37d478fb5759db33436ac01c", "size": 4680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch04/0405.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": "ch04/0405.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": "ch04/0405.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": 48.2474226804, "max_line_length": 150, "alphanum_fraction": 0.7004273504, "num_tokens": 1467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.621378722331014}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Update}\nThe operation $update$ will return a Collection $coll!$ which is the same as the input Collection $coll?$\nexcept for at index $idx?$. The existing member $coll?_{idx?}$ is replaced by the provided Value $v?$ at $idx?$ in $coll!$\nsuch that\n$$idx? \\mapsto v? \\in coll! ~ \\land ~ idx? \\mapsto coll?_{idx?} \\not \\in coll!$$\nwhich is equivalent to $remove ~\\pipe ~append$\n\\begin{zed}\n  update(coll?, v?, idx?) \\equiv append(remove(coll?, idx?), v?, idx?)\n\\end{zed}\nThe functionality of $update$ is further explained in the following schema.\n\\begin{schema}{Update[Collection, V, \\nat]}\n  idx? : \\nat \\\\\n  coll?, coll! : Collection \\\\\n  v? : V \\\\\n  update~\\_ : Collection \\cross V \\cross \\nat \\bij Collection\n  \\where\n  1 = \\#~idx? \\\\\n  coll! = update(coll?, v?, idx?) @ \\\\\n  \\t1 let ~ ~ coll' == \\{~ i : \\nat ~| ~ i \\in 0~..~idx?\\} \\extract coll? \\\\\n  \\t1 \\ \\ \\ ~~~ coll'' == head(coll') ~\\cat ~ v?\\\\\n  \\t1 \\ \\ \\ ~~~ coll''' == \\{~ j : \\nat ~| ~ j \\in idx?+1~..~\\#~coll?\\} \\extract coll? \\\\\n  \\t1 =  coll'' ~\\cat ~coll'' \\implies \\\\\n  \\t2 (append(remove(coll', idx?), v?, idx?) \\cat  coll'') ~ \\land \\\\\n  \\t2 (~ v? \\mapsto idx? \\in coll!) ~\\land \\\\\n  \\t2 (~\\#~ coll! = \\#~ coll?) ~\\land\n\\end{schema}\nThe value which previously existed at $idx? \\in coll?$ is replaced with $v?$ to result in $coll!$\n\\begin{itemize}\n\\item $coll'$ is the items in $coll?$ up to and including $idx?$\n\\item $coll''$ is the items in $coll?$ except the item at $idx?$ has been replaced with $v?$\n\\item $coll'''$ is the items in $coll?$ from $idx?+1$ to $\\#~coll? \\implies coll?_{idx?} \\not \\in coll''$\n\\end{itemize}\nThe following example illustrates these properties.\n\\begin{argue}\n  X = \\langle x_{0}, x_{1}, x_{2} \\rangle \\\\\n  \\t1 x_{0} = 0 \\\\\n  \\t1 x_{1} = foo \\\\\n  \\t1 x_{2} = \\langle a, b, c \\rangle \\\\\n  \\t1 v? = bar \\\\\n  update(X, v?, 0) = \\langle bar, foo, \\langle a, b, c \\rangle \\rangle \\\\\n  update(X, v?, 1) = \\langle 0, bar, \\langle a, b, c \\rangle \\rangle \\\\\n  update(X, v?, 2) = \\langle 0, foo, bar \\rangle \\\\\n  update(X, v?, 3) = \\langle 0, foo, \\langle a, b, c \\rangle, bar \\rangle \\\\\n  update(X, v?, 4) = append(X, v?, 3) = update(X, v?, 3) \\iff 3 \\not \\in \\dom X\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "7d1fbb67174e6ce970e6507aef92dae5add1bcc5", "size": 2259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/collections/update.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/collections/update.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/collections/update.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 46.1020408163, "max_line_length": 122, "alphanum_fraction": 0.5887560868, "num_tokens": 817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6213138820117484}}
{"text": "\\section{Matrix Product States}\nMPS closed chain.\n\\begin{align}\n    \\ket{\\psi} &=\n    \\sum_{i_1,\\ldots,i_N} \\Tr\\left( \n    A_{i_1}\\cdots A_{i_N}\n    \\right)\n    \\ket{i_1,\\ldots,i_N}\n\\end{align}\nwhere $A_i$ are $D\\times D$ matrices, and $i=1,\\ldots, d$ where\n$d$ is the dimension of the site Hilbert space.\nThere are $dND^2$ parameters here to describe a quantum state.\n\nGapped ground states of local Hamiltonians satisfy the area law for entanglement\nentropy.\n\nCan approximate gapped ground states to accuracy $1/\\poly(N)$\nwith MPS with $D$ sublinear in $N$.\n\nA MPS is injective if there exists finite $L_0$ such that\n\\begin{align}\n    \\tilde{A}_I &=\n    A_{i_1} A_{i_2} \\cdots A_{i_N}\n\\end{align}\nspans the whole space of $D\\times D$ matrices.\n\nThe question is if these matrices span the entire space of $D\\times D$\nmatrices.\n\nThe reason injectivity is important is that you can show that an injective MPS\nhas the following properties.\n\\begin{enumerate}\n    \\item Finite correlation length.\n    \\item There are unique gapped ground states of a frustration-free parent\n        Hamiltonian.\n\\end{enumerate}\n\nThere is a book by Xiao-Gang Wen, Xie Chen, Bei Zeng and one other author which\nhas a nice discussion of MPS and in particular the relation between MPS and SPT\nphases.\n\nThere's another formulation called PEPS,\nprojected entangled pair states.\n\nConsider a chain of maximally entangled pairs which are then projected.\nSo you have on each site,\nimagine you have two kinds of spins.\nAnd then you put the spins on nearby states into singlets,\nand then you do a projection.\n\nSo here, \nthis singlet bond,\nwhat that really means,\nyou can think of it as a maximally entangled state between the Hilbert space on\nthe two sides.\n\\begin{align}\n    \\frac{1}{\\sqrt{D}} \\sum_{\\alpha=1}^{D} \\ket{\\alpha}\\ket{\\alpha}\n\\end{align}\nwhere $D$ is some internal bond dimension.\nThe idea is that each of these are some virtual spin,\nand $D$ would be the dimension of the virtual spin.\n\nAnd then the projection projects from two virtual spins to a physical degree of\nfreedom of dimension $D$.\n\nSo this projection,\nif you write it in the following way\n\\begin{align}\n    P &= \\sum_{i,\\alpha,\\beta} A_{i,\\alpha\\beta} \\ket{i}\\bra{\\alpha\\beta}\n\\end{align}\nThen this state is actually equivalent to the MPS $\\ket{\\psi}$.\n\nSo the MPS is exactly equivalent to this PEPS when the projection is written\nlike above.\n\nSomething that happened in 2010,\nthat led to people thinking all 1D phases are classified by $H^2(G, U(1))$,\nis that if you take the bond dimension,\nand what can be analysed by constant depth circuits,\nis the following.\n\nOne can show that any MPS with fixed bond dimension can be disentangled\nto exponential accuracy by local constant depth circuit.\n\nThe fact you can do this is evidence for no bosonic topological order,\nmeaning no topologically ordered phases of bosons without any symmetry.\n\nDisentangle means toke to the direct product state.\n\nIt doesn't prove it of course,\nbecause the bond dimension is assumed to be fixed,\nbut in general you should consider the bond dimension to grow with system size.\n\nLast time in the paper,\nthey show the bond dimension is sublinear in $N$,\nbut not necessarily constant in $N$.\nThis discovery of disentanglement with fixed bond dimension doesn't prove there\nis no topological order in 1D but it does strongly suggest there is no bosonic\ntopological order in 1D.\n\nThen you could add symmetry in the circuit,\nand let the circuit be symmetric,\nand then you can show from there that you basically get this PEPS form.\nThat is,\nyou can show that any MPS with a fixed bond dimension and symmetry $G$\ncan be converted into an entangled pair form via a symmetric constant depth\ncircuit.\n\nFurthermore, each virtual spin is in projective representation of $G$\ncharacterized by this cocycle\n$[w] \\in H^2(G,U(1))$.\n\nThis again,\nis evidence that the classification of gapped phases should be\n$H^2(G,U(1))$.\nThe caveat is that we're considering MPS,\nand constant depth local circuits that disentangle,\nor take any generic MPS to this fixed point form.\n\nI'm not going to go through the exact construction,\nbut this book has s nice account of it.\n\nI want to describe a different model for thinking about SPT states in terms of\npath integrals,\nstate sums and wave functions that can generalize to every dimension.\nThis whole discussion about MPS is limited to 1D.\nWhile it's interesting and illuminated,\nI'm not going to dwell more on it because it's so specific to 1D.\nThis is the overview of what happened 10 years ago in 1D that led people to go\nfurther and classify higher dimensions.\n\n\\begin{question}\n    Experimental tests of AKLT?\n\\end{question}\nThe spin-1 Heisenberg chain is gapped phase of matter with dangling gapped edge\nmodes,\nand there are experiments.\nThe Haldane chain is half the reason why Haldane won the Nobel prize,\neven though he didn't realize it's an SPT state at the time.\n\n\\begin{question}\n    Is it because of ground state degeneracy?\n\\end{question}\nEvery 1D bosonic topological phase is a trivial phase,\nif you forget about symmetry.\nFor fermions,\nit's not the case because we have Majorana chains.\nEven though it has no edge modes on a ring,\nit's still topological.\n\nIt's not exactly because of ground state degeneracy,\nbecause the Majorana chain does not have ground state degeneracy on a closed\nchain either.\n\n\\begin{question}\n    Why is the second statement evidence?\n\\end{question}\nEvery sate,\nyou can run it through some constant depth symmetric circuit,\nand take it not a form like this,\nwhere every one is a projective representation,\nwith a dangling edge state.\nYou could run some RG procedure that takes a constant number of steps,\nbut takes you to this idealized fixed-point form to good accuracy.\n\n\\begin{qeustion}\n    Is the second statement still true for $d=1$.\n\\end{qeustion}\nYou can actually get from PEPS to the trivial product state by disentangling\neach of these guys,\nbut he only way to do that is break the symmetry $G$.\nBut to fully disentangle,\nyou need that one extra step to break the symmetry.\n\nI encourage to read the relevant chapter in the book by X.G. Wen.\nThere's also a book by Ignacio Cirac.\n\n\\section{Group Cohomology Model (Dijkgraaf-Witten theory)}\nI want to turn to a model for SPT state,\nfirst in 1D,\nbut this model actually generalized to higher dimensions as well.\n\nThe idea is that we're going to construct a TQFT that gives SPT states\nby constructing the path integral.\nConstruct a path integral fora TQFT\n\\begin{align}\n    Z(M^2, A)\n\\end{align}\nWe have a symmetry $G$, so there is a gauge field $A$ for that $G$ symmetry.\n\nThe first step is to triangulate spacetime.\n\nThen the next step is define a branching structure.\nA branching structure is a local ordering of the vertices.\nAnother way of saying what it is is to make all edges directed in a way such\nthat there are no closed loops.\nThat's all a branching structure is.\n\nFor example, take some triangle,\nwith vertices labelled 0, 1, 2.\nThen arrows pointing from lower to higher number vertices on edge,\nand you see there're no loops.\n\nThen we introduce an orientation.\nYou can reverse the arrows,\nand you notice you can't rotate one to make it look like the other,\nbecause if you follow two of the arrow,\nyour thumb points down,\nbut it points up on the other orientation.\nYou call one the $+$ orientation and you call the other the $-$ orientation.\n\nThe next thing to do is to assign group elements to vertices.\n\nIt effectively introduces a gauge field into the problem,\nbecause if I draw a triangle with\n$g_0$, $g_1$ and $g_2$ on vertices,\nthe links between them will be $g_0^{-1}g_1$ from $g_0$ to $g_1$,\n$g_{0}^{-1}g_2$ from $g_0$ to $g_2$ and\n$g_1^{-1}g_2$ from $g_1$ to $g_2$.\n\n[picture]\n\nThis defines a special kind of gauge field,\nit's a \\emph{flat} gauge field.\nThat is,\nthere is no net flux through a plaquette.\n\nFor example,\nthe flux through one triangle is\n$A_{01}A_{12}A_{20}=1$\nand in fact the product of any loop is 1 with\n\\begin{align}\n    \\prod_{\\textrm{loop}} A = 1\n\\end{align}\nso in fact $A$ is a \\emph{trivial} flat gauge.\n\nThen for each 2-simplex (triangle),\nwe're going to associate a phase factor,\nwhich is an amplitude,\nthat depends on the group elements.\n\nTo each 2-simplex $\\Delta^2$, define\n\\begin{align}\n    \\left[ \\nu_2\\left( g_0, g_1, g_2 \\right) \\right]^{S\\left( \\Delta^2 \\right)}\n\\end{align}\nwhere $\\nu_2 \\in U(1)$.\nI assume the labels are labelled $g_0,g_1,g_2$.\n$S$ is the orientation of $\\Delta^2$.\n\n\\begin{question}\n    Is this an invertible TQFT?\n\\end{question}\nThis will be an invertible TQFT,\nand the fact that this is just a $U(1)$ phase is important why it's invertible.\nYou can generalize it,\nbut it's significantly more complex to make $U(1)$ not just a phase.\n\nThe path integral that we're going to define is defined as follows.\n\\begin{align}\n    Z &=\n    \\frac{1}{|G|^{N_V}}\n    \\sum_\\left\\{ {g_i \\right\\}}\n    \\prod_{\\Delta_2 \\ni (i, j, k)}\n    \\left[ \n    \\nu_2 \\left( g_i, g_j, j_k \\right)^{S(\\Delta_2)}\n    \\right]\n\\end{align}\nwe're taking the product over all 2-simplices $\\Delta_2$\neach of which have vertices $i,j,k$ in order.\nAnd I'm going to take the product of all these phases $\\nu_2$\nand I'm going to raise it to the orientation $S\\left( \\Delta_2 \\right)$.\nAnd then I'm going to sum over all possible choices of vertices $\\left\\{ g_i\n\\right\\}$\nand then I'm going to average by dividing by $|G|^{N_V}$\nwhere $N_V$ is the number of vertices and $|G|$ is the number of elements in\n$G$.\n\nWe'll come to this,\nbut if you're a mathematician and see this,\nyou might think we're crazy,\nbecause you'll see the sum is completely useless for defining the path integral,\nbut the sum is here for physics.\nWhat you find here is that every term is here is the same.\nI haven't told you what $\\nu_2$ are.\nIt turns out every term in the term is the same.\n\nWe're just summing over all possible labellings.\n\n\\begin{question}\n    $G$ survives permutations?\n\\end{question}\nWe have some crazy triangulation,\nand I'm just summing over every possible value of $G$.\nEvery vertex has a group element attached to it,\nand each vertex has a different group element.\n\n\\begin{question}\n    Are there as many group elements as vertices?\n\\end{question}\nThere are $N_V$ group elements,\nwhich is different from $|G|$.\nFor example $G=\\mathbb{Z}_2$,\nthen there are $2^{N_V}$.\n\n\n\\begin{question}\n    How does it connect to the system we're trying to study?\n\\end{question}\nMaybe you should wait.\nIf you remember in TQFT,\nyou can define a path integral for spacetime.\nIf your spacetime has a boundary,\nyou have a state on the boundary.\nThis path integral can give a wave function state on the boundary.\n\n\nAny boundary is going to be a circle,\nor a bunch of disconnected circles,\nso we can get a wave function on circles that describes SPTs.\nAnd from those circles,\nwe deduce an exactly solvable Hamiltonian as well.\n\nThis gives a topologically invariant path integral,\nform which we extract topological invariants.\n\n\\begin{question}\n    Is branching structure the same as consistent orientation?\n\\end{question}\nNo, it's more than that.\nIt's even more than a specific set of orientations.\nIt's a specific set of ordering of vertices.\n\n\\begin{question}\n    Should neighbouring vertices have the same ordering?\n\\end{question}\nNot necessarily.\n\n\\begin{question}\n    We take all gauge-equivalent into one term?\n\\end{question}\nYes, this is going to wind up being an average over gauge transformations.\n\nIt's gauge equivalent to no $G$,\nwe haven't defined $\\nu_2$ yet.\nWe'll be able to relax this product of $A=1$ condition,\nso we can introduce twists and things wrap around,\nand it won't be gauge-equivalent to nothing.\n\nIt's also useful to think of $Z$ in the following way,\nas a sum over all $g$s normalized\nover the exponential of some topological action.\n\\begin{align}\n    Z &=\n    \\frac{1}{|G|^{N_V}}\n    \\sum_\\left\\{ {g_i \\right\\}}\n    e^{i S_{\\mathrm{top}}\\left( \\left\\{ g_i \\right\\} \\right)}\n\\end{align}\nI'm being a bit sloppy here,\nwhen I say $A$,\nI really mean equivalence classes of $[A]$,\nby gauge equivalence.\nBut if we know $ZA$ is gauge invariant,\nI don't really need to write the square brackets.\n\\begin{align}\n    Z = Z\\left( M^2 , [A] \\right)\n\\end{align}\n\nThis has a global symmetry,\nand what I mean is that the amplitude should be the same as if multiplied by\nsome global $g$.\nEvery term in the sum is explicitly the same if I change all $g_j$'s at once by\nsome global $g$.\n\\begin{align}\n    e^{iS\\left( \\left\\{ g_i \\right\\} \\right)}\n    =\n    e^{iS\\left( \\left\\{ gg_i \\right\\} \\right)}\n\\end{align}\nwhich also means\n\\begin{align}\n    \\nu_2\\left( gg_0, gg_1, gg_2 \\right) &=\n    \\nu_2\\left( g_0, g_1, g_2 \\right)\n\\end{align}\nWe're assuming $g$ is unitary,\nbut if it's anti-unitary,\nyou just introduce a complex conjugate in the above equation.\n\nWhat this allows is to do is define a 2-cochain.\nThe reason it defines a 2-cochain is because I can define the usual 2-cochain,\nwhich I introduced last lecture,\nwhich is\n\\begin{align}\n    \\omega_2(g_1, g_2) &=\n    \\nu_2 (1, g_1, g_1 g_2)\n\\end{align}\nFurthermore,\nI can multiply every element by $g_0^{-1}$ so\n\\begin{align}\n    \\nu_2 (g_0, g_1, g_2) &=\n    \\nu_2 \\left( \n    1, g_0^{-1},g_1, g_{0}^{-1} g_1 g_1^{-1} g_2\n    \\right)\\\\\n    &= \\omega_2\\left( g_0^{-1} g_1, g_1^{-1} g_2 \\right)\n\\end{align}\nWe thought of 2-cochains as something that takes in 2 group elements and splits\nout a phase factor.\nBut here,\nwe can think of it as taking 3 group elements and spits out a factor,\nbut it has some symmetry in the inputs.\n$\\nu_2$ is called a homogeneous 2-cochain,\nwhereas $\\omega_2$ is an inhomogeneous 2-cochain.\n\n\\begin{question}\n    What's inhomogeneous about it?\n\\end{question}\nIf you think about it,\n\n\\begin{question}\n    What is symmetric?\n\\end{question}\nI want the action to be symmetric.\nUsually when you talk about a symmetric system,\nI say the path integral is a sum over all field configurations.\nBut I say my system is symmetric if my action has the symmetry.\n\n\\begin{question}\n    Can't we have each equality up to a phase\n    so the phases cancel instead?\n\\end{question}\nI haven't thought about that too more carefully.\nI'm saying that this implies this,\nbut not the other way around.\nYou could relax things and consider it more general,\nbut I'm not sure how to do that in a way that's compatible with locality.\nAt the very least,\nit gives us a way of getting a symmetric path integral.\n\n\\begin{question}\n    Every group element can be mapped to another group element by another group\n    element.\n    Why are not all the vertices not connected to each other.\n    You can always form a side that connects $g_1$ to $g_3$.\n    What is the point of triangulation?\n    All group elements are connected to each other.\n\\end{question}\nI don't understand the question.\nThat's the graph of the group.\nYou can think if this as defining a gauge field on a manifold.\n\n\\begin{question}\n    We're assuming $\\nu_2$ to have a global $g$ symmetry,\n    not a local $g$ symmetry.\n\\end{question}\nWe have a global $g$ symmetry,\nwhich means we want every amplitude independent of $g$,\nbut there's also a gauge symmetry,\nin that I can do a gauge transformation $A$ and not change the path integral.\nThere's something much stronger that's happening here in that there's also a\nlocal gauge symmetry.\n\n\n\\section{Topological invariance of the path integral}\nNow we get to the topological invariance of $Z$.\nSo far, \nwe had to triangulate spacetime and add a branching structure.\nThat's just geometry.\nBut for topological invariance,\nwe need it to be independent of geometry and choice of branching structure.\n\nThe point is,\nthat we want $Z$ to be independent of triangulation and branching structure.\nthat's what we want to demand,\nbut actually we want to demand something even stringer,\nthat is the action $e^{iS}$ is topological,\nmeaning independent of triangulation.\n\nAnd the way that you can require that something be independent of triangulation,\nis given any triangulation,\nyou can always get to another triangulation by a series of moves,\nand these moves are called \\emph{Pacher moves}.\n\nSuppose I have two triangles like this.\nOne Pacher move is to have a rhombus with a diagonal,\nand change the diagonal to the other diagonal. This is a 2-2 move.\n\nThere is a 1-3 move which inserts a vertex on a triangle,\nand draws rays from the new vertex.\n\nIt's just pasting a simplex of one higher dimension.\nIn 2D you have a 2-simplex that is a triangle.\nBut in one-higher dimension,\nyou have a tetrahedron.\nThink of pasting a tetrahedron onto a triangle and flattening it.\n\nSo one way of thinking about Pachner moves is pasting $D+1$-simplices onto your\n$D$ simplices and flattening it out.\n\n\nBut we actually need branched Pachner moves,\nwhich also deals with the ordering.\n\nI need some extra conditions.\nFor example,\nin the 2-2 Pachner move,\nthere would be\n\\begin{align}\n    \\nu_2 (g_0, g_1, g_2)\n    \\nu_2 (g_0, g_2, g_3)\n    =\n    \\nu_2 (g_0, g_1, g_3)\n    \\nu_2 (g_1, g_2, g_3)\n\\end{align}\n[picutre]\n\nTo be careful,\nyou should also check the orientation and make sure you put the right complex\nconjugation.\nFor the 1-3 Pachner move,\nyou would have\n\\begin{align}\n    \\nu_2(g_0, g_1, g_2) =\n    \\nu_2(g_0, g_1, g_3)\n    \\nu_2(g_1, g_2, g_3)\n    \\nu_2(g_0, g_2, g_3)\n\\end{align}\n\nBut secretly,\nthey are the same equation,\nin fact they are just the 2-cocycle equation that\n\\begin{align}\n    d\\nu_2 = 1\n\\end{align}\n\nTo make the topological action re-triangulation invariant,\nwe require that $\\nu_2$ to be a 2-cocycle.\n\nAnd finally,\nlet's look at the invariant under 2-coboundaries\n\n\\subsection{Invariance under coboundaries}\nSuppose that we take\n\\begin{align}\n    \\nu_2 (g_0, g_1, g_2)\n    \\to\n    \\nu_2 \\cdot \n    b_1 (g_0, g_1)\n    b_1 (g_1, g_2)\n    \\left[ b_1 (g_0, g_2) \\right]^*\n\\end{align}\nand I'm going to require\n\\begin{align}\n    b_1 (g_1, g_2) &= b_1 (gg_1, gg_2)\n\\end{align}\nAnd $e^{iS}$ is invariant because each edge (1-simplex) appears in exactly two\n2-simplices with opposite induced orientation.\n\nThe reason it's invariant, is every single 1-simplex appears with 2 neighbouring\ntriangles.\nFor example, if I have a triangulation,\nevery 1-simplex has 2 neighbouring triangles.\nAnd every 1-simplex has opposite orientation relative to each triangle.\nThat means that if one triangle changes by this factor $b_1(g_1,g_2)$,\nthe neighbour is going to change by a similar factor,\nbut it's going to appear complex conjugated in the neighbour so they're all\ngoing to cancel out.\n\nIn terms of inhomogeneous 2-cocycles,\napplying $g_0^{-1}$ to each term,\nwe get\n\\begin{align}\n    \\nu_2(1, g_0^{-1} g_1, g_{0}^{-1} g_2)\n    &\\to\n    \\nu_2 \\cdot\n    \\frac{b_1(1, g_{01}) b_1(1, g_{12})}{b_1(1, g_{02})}\n\\end{align}\nand\n\\begin{align}\n    \\omega_2(g_{01}, g_{12}) \\to\n    \\omega_2\n    \\frac{\\epsilon_1(g_{01}) \\epsilon_1_1\\left( g_{12} \\right)}{\\epsilon_1\\left(\n    g_{02} \\right)}\n\\end{align}\n\nThat means, if we change our 2-coboundary by 2-cocycles,\nthe topological boundary doesn't change.\nThat is,\ndistinct $G$-symmetric path integrals are classified by\n\\begin{align}\n    [\\nu_2] \\in\n    H^2\\left( G, U(1) \\right)\n    = \\frac{\\mathbb{Z}^2}{B^2}\n\\end{align}\nActually,\nthe last step is a bit of a jump.\n\nLet me give more details.\n\nOn closed manifolds,\nwhat we defined so far always gives us one with\n$Z(M^2)=1$.\nThat's because what we have is a trivial $G$-bundle,\nmeaning that\n$\\prod_{\\textrm{loop}}A=1$.\n\nTo get non-trivial results we non-trivial flat bundles with\n$\\prod_{\\textrm{loop}}A \\ne 1$.\nWe want it to be flat but we want holomony over non-contractible loops.\n\nOne way of doing this is this construction we've defined,\nis we can cut our manifold along whatever loop we're interested with having\nholomony,\nthen inserting some $G$-twist when we glue them back together.\n\nLet me draw a picture.\nSuppose w have a cylinder,\nand we want to put a $h$ branch cut along the cylinder axis.\nSo then this loop at the end of the cylinder is $\\gamma$,\nwith $\\prod_\\gamma A = h$.\n\nThen if you roll out the cylinder flat,\nyou can draw a triangulation like this.\n\n[picture of unrolled cylinder sheet]\n\nThe point is that if we have $g_1,g_2,\\ldots$ on the bottom edge of the cut,\nwhich we identify with the vertices on the top edge of the cut to get a\ncylinder.\nTo do the twist,\njust make the top edge vertices labelled $hg_1, hg_2, \\ldots$.\n\nFor a closed $M^2$\nnon-trivial flat bundle,\n\\begin{align}\n    |Z(M^2, A)| = 1\n\\end{align}\nbut the phase is going to be non-trivial,\nwith $Z(M^2, A)$ being a gauge-invariant polynomial in $\\omega_2$.\nFor every element of $H^2$,\nwe're going to get a path integral that will spit out a $U(1)$ phase and if we\nlook at al possible closed manifolds and all possible closed bundles,\nwe find that all elements of $H^2(G, U(1))$ corresponds to a distinct path\nintegral $Z(M^2, A)$.\n\nSo there is a one-to-one correspondence between this group and these TQFTs by\npicking appropriate fluxes along non-contractible cycles.\n\\begin{align}\n    H^2(G, U(1)) \\leftrightarrow Z(M^2, A)\n\\end{align}\nI didn't prove that $Z(M^2)=1$ if it's flat and trivial,\nbecause I didn't prove that the sum over $G$ is actually invariant yet.\n\n\\begin{question}\n    What is the definition of $\\prod A$?\n\\end{question}\nIf you have a torus.\nIf you take a product of lops on a contractible bundle,\nyou get 1.\nBut you get a holomony over a non-contractible loop?\n\n\\begin{question}\n    What if we generalize to cellulations?\n\\end{question}\nwell this $\\nu_2(g_0, g_1, g_2)$ only makes sense over triangles because it has\n3 inputs,\nbut you could consider cellulations,\nbut the framework will be a different,\nbut ultimately you get the same answer.\n", "meta": {"hexsha": "52e09f191d153715d4cf96e8ba9fcdc3c0d531f2", "size": 21640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys733/lecture19.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/lecture19.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/lecture19.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": 32.4437781109, "max_line_length": 80, "alphanum_fraction": 0.7400184843, "num_tokens": 6115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6213138737184798}}
{"text": "\\documentclass{lucky}\n\n\\title{MAST Diagnostic}\n\\author{Dennis Chen}\n\\date{Season 1}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Instructions}\nTake as long as you need on these problems and do as many as you can. For computational problems, provide numerical answers and include a short sketch of your solution. For proof problems, include a full solution. Once done, submit it through the MAST Diagnostic Form.\n\nYou may use books as reference/ask me or other people for help. (In particular, if you need reading to learn the material, please contact me.) All of these are my problems so I do think it'll be difficult to google them, but please don't try this all the same.\n\n\\section{Problems}\n\n\\subsection{Computational}\n\n\\begin{enumerate}\n\n\\item How many integer values of $1\\leq x\\leq 100$ makes $x^2+8x+5$ divisible by $10?$\n\n\\item In the following diagram, $m\\angle BAC=m\\angle BFC=40^{\\circ}$, $m\\angle ABF=80^{\\circ}$, and $m\\angle FEB=2m\\angle DBE=2m\\angle FBE$. What is $m\\angle ADB$?\n\n    \\begin{center}\n        \\begin{asy}\n        import olympiad;\n        size(4cm);\n    draw((0,0)--(-14,0)--(2,8)--(0,0)--(-9,2.5)--(-5.5,0)--(-6,4)--cycle);\n    draw((-5.5,0)--(2,8));\n    label(\"A\", (2,8), NE);\n    label(\"B\", (0,0), SE);\n    label(\"C\", (-5.5,0), S);\n    label(\"D\", (-14,0), SW);\n    label(\"E\", (-9,2.5), NNW);\n    label(\"F\", (-6,4), NNW);\n        \\end{asy}\n    \\end{center}\n\n\\item Consider parallelogram $ABCD$ with $AB=7,$ $BC=6.$ Let the angle bisector of $\\angle DAB$ intersect $BC$ at $X$ and $CD$ at $Y.$ Let the line through $X$ parallel to $BD$ intersect $AD$ at $Q.$ If $QY=6,$ find $\\cos\\angle DAB.$\n\n\\item Consider unit circle $O$ with diameter $AB.$ Let $T$ be on the circle such that $TA<TB.$ Let the tangent line through $T$ intersect $AB$ at $X$ and intersect the tangent line through $B$ at $Y.$ Let $M$ be the midpoint of $YB,$ and let $XM$ intersect circle $O$ at $P$ and $Q.$ If $XP=MQ,$ find $AT.$\n\n\\item A secret spy organization needs to spread some secret knowledge to all of its members. In the beginning, only $1$ member is \\textit{informed}. Every informed spy will call an uninformed spy such that every informed spy is calling a different uninformed spy. After being called, an uninformed spy becomes informed. The call takes $1$ minute, but since the spies are running low on time, they call the next spy directly afterward. However, to avoid being caught, after the third call an informed spy makes, the spy stops calling. How many minutes will it take for every spy to be informed, provided that the organization has $600$ spies?\n\n\\item Andy the unicorn is on a number line from $1$ to $2019.$ He starts on $1.$ Each step, he randomly and uniformly picks an integer greater than the integer he is currently on, and goes to it. He stops when he reaches $2019.$ What is the probability he is ever on $1984?$\n\n\\item Find \\[\\sum\\limits_{a=1}^{\\infty}\\frac{32a}{16a^4+24a^2+25}.\\]\n\n\\item Find the sum of all odd $n$ such that $\\frac{1}{n}$ expressed in base $8$ is a repeating decimal with period $4.$\n\n\\item Santa Claus is putting $n$ identical toy trains into a red stocking, a green stocking, and a white stocking such that the amount of trains in the green stocking is divisible by $3$ and the amount of trains in the white stocking is even. Mrs. Claus is putting $n$ identical elves into a red stocking, a green stocking, and a white stocking such that the amount of elves in the green stocking is divisible by $3$ and the amount of elves in the white stocking is odd. Find, in terms of $n,$ the positive difference between the amount of ways Santa Claus can put his trains in the stockings and the amount of ways Mrs. Claus can put her elves in the stockings.\n\n\\item Find the maximum value of $k$ such that $(x+1)^4\\geq kx^3$ for all $x.$\n\n\\end{enumerate}\n\n\\subsection{Proof}\n\n\\begin{enumerate}\n    \\item Consider $\\triangle ABC,$ and let the feet of the $B$ and $C$ altitudes of the triangle be $X,Y.$ Let $XY$ intersect $BC$ at $P.$ Then prove that the circumcircles of $\\triangle PBY$ and $\\triangle PCX$ concur with $AP.$\n\n    \\item Consider $\\triangle ABC$ with $D$ on line $BC.$ Let the circumcenters of $\\triangle ABD$ and $\\triangle ACD$ be $M,N,$ respectively. Let the circumcircle of $\\triangle MND$ intersect the circumcircle of $\\triangle ACD$ again at $H\\neq D.$ Prove that $A,M,H$ are collinear.\n\n    \\item Let $f(x)=x^2-12x+36.$ In terms of $k$, for $k\\geq 2,$ find the sum of all real $n$ such that $f^{k-1}(n)=f^k(n).$\n    \n    \\item Consider scalene $\\triangle ABC$ with incenter $I.$ Let the $A$ excircle of $\\triangle ABC$ intersect the circumcircle of $\\triangle ABC$ at $X,Y.$ Let $XY$ intersect $BC$ at $Z.$ Then choose $M,N$ on the $A$ excircle of $\\triangle ABC$ such that $ZM,ZN$ are tangent to the $A$ excircle of $\\triangle ABC.$ Prove $I,M,N$ are collinear.\n\\end{enumerate}\n\n\\end{document}\n\n", "meta": {"hexsha": "a6b0b88d5b7bec803ff01693d596820f8710857c", "size": 4859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/diagnostic/season1.tex", "max_stars_repo_name": "mathadvance/mast-web", "max_stars_repo_head_hexsha": "13fa77893395334125c978d2d850508f1865d50a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-09T19:54:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-09T19:54:00.000Z", "max_issues_repo_path": "public/diagnostic/season1.tex", "max_issues_repo_name": "mathadvance/mast-web", "max_issues_repo_head_hexsha": "13fa77893395334125c978d2d850508f1865d50a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-07T20:27:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-09T18:05:00.000Z", "max_forks_repo_path": "public/diagnostic/season1.tex", "max_forks_repo_name": "mathadvance/mast-web", "max_forks_repo_head_hexsha": "13fa77893395334125c978d2d850508f1865d50a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T04:23:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T04:23:09.000Z", "avg_line_length": 66.5616438356, "max_line_length": 662, "alphanum_fraction": 0.6991150442, "num_tokens": 1430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.62131056730541}}
{"text": " \n\n\nOne of the most surprising outcomes of the revolution in computing\ntechnology has been the discovery of diverse uses for randomness \nin the analysis of data and in science generally.  Most young people\nhave little trouble with the idea of a computer generating random data;\nthey see it in computer games and simulations.  Older people,\nraised with the idea that computers do mathematical operations and\nthat such operations are completely deterministic, sometimes find \ncomputer-generated randomness suspect.  Indeed, conventional algebraic\nnotation ($+$, $-$, $\\sqrt{}$, $\\cos$, and so on) has no\nnotation for ``generate at random.''\n\n\\index{C}{resampling}\n\\index{P}{resample@\\texttt{resample}*}\n\\index{P}{Resampling!resample@\\texttt{resample}*}\n\\index{C}{coin flip!simulation}\n\\index{P}{Simulations!coin flip}\nOne of the simplest operators for generating random events is\n\\code{resample}.  This takes two arguments: the first is a set of\nitems to choose from at random, the second is how many events\nto generate.  Each item is equally likely to be\nchoosen.  For example, here is a simulation of a coin flip:\n\\begin{Schunk}\n\\begin{Sinput}\n> coin = c(\"H\",\"T\")\n> resample(coin, 5)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"H\" \"T\" \"T\" \"T\" \"H\"\n\\end{Soutput}\n\\begin{Sinput}\n> resample(coin, 5)\n\\end{Sinput}\n\\begin{Soutput}\n[1] \"H\" \"H\" \"H\" \"T\" \"T\"\n\\end{Soutput}\n\\end{Schunk}\nThe first command creates an object holding the possible outcome of\neach event, called \\code{coin}.  The next command generated five\nevents, each event being a random choice of the outcomes in\n\\code{coin}.\n\nAnother example is rolling dice.  First, construct a set of the\npossible outcomes: the numbers 1, 2, 3, 4, 5, 6.\n\\begin{Schunk}\n\\begin{Sinput}\n> die = seq(1,6)\n> die\n\\end{Sinput}\n\\begin{Soutput}\n[1] 1 2 3 4 5 6\n\\end{Soutput}\n\\end{Schunk}\nThen generate random events.  Here is a roll of two dice.\n\\begin{Schunk}\n\\begin{Sinput}\n> resample(die,2)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 4 5\n\\end{Soutput}\n\\end{Schunk}\n\nThe \\function{resample} function is also useful for selecting cases at\nrandom from a data frame.  This use will be the basis for statistical\nmethods introduced in later chapters. \n\n\n\\subsection{Random Draws from Probability Models}\n\nAlthough \\function{resample} is useful for random sampling, it can work\nonly with finite sets of possible outcomes such as H/T or 1/2/3/4/5/6\nor the cases in a data frame.  By default in \\function{resample}, the \nunderlying probability model is\n\\newword{equiprobability} --- each possible outcome is equally likely.\nYou can specify another probability model by using the \\code{prob=} argument\nto \\function{resample}. For instance, to flip coins that are very likely to come up heads:\n\\begin{Schunk}\n\\begin{Sinput}\n> resample( coin, 10, prob=c(.9,.1))\n\\end{Sinput}\n\\begin{Soutput}\n [1] \"H\" \"H\" \"H\" \"H\" \"H\" \"H\" \"H\" \"H\" \"H\" \"T\"\n\\end{Soutput}\n\\end{Schunk}\n\nR provides other operators that allow\ndraws to be made from outcome sets that are infinite.\n\n\\index{C}{probability model!sampling from}\n\nFor example, the \\function{rnorm} function makes random draws from a\nnormal probability distribution.  The required argument tells how many\ndraws to make.  Optional, named arguments let you specify the mean and\nstandard deviation of the particular normal distribution that you\nwant.  To illustrate, here is a set of 15 random numbers from a normal\ndistribution with mean 1000 and standard deviation 75:\n\\begin{Schunk}\n\\begin{Sinput}\n> samps = rnorm(15, mean=1000, sd=75)\n> samps\n\\end{Sinput}\n\\begin{Soutput}\n [1]  977  941 1000  996  934 1029  995 1079  969  935 1017\n[12]  992 1023 1022 1046\n\\end{Soutput}\n\\end{Schunk}\nIn this example, the output was assigned to an object \\code{samps}\nto facilitate some additional computations to the\nvalues.  For instance, here is the mean and standard deviation of the\nsample:\n\\begin{Schunk}\n\\begin{Sinput}\n> mean(samps)\n\\end{Sinput}\n\\begin{Soutput}\nmean \n 997 \n\\end{Soutput}\n\\begin{Sinput}\n> sd(samps)\n\\end{Sinput}\n\\begin{Soutput}\n  sd \n41.5 \n\\end{Soutput}\n\\end{Schunk}\nDon't be surprised that the mean and standard deviation of the sample\ndon't match exactly the parameters that were set with the arguments\n\\code{mean=1000, sd=75}.  The sample was drawn at random and so the\nsample statistics are going to vary from one sample to the next.  Part\nof the statistical methodology to be studied in later chapters has to\ndo with determining how close the statistics calculated from a sample\nare likely to be to the parameters of the underlying population.\n\nOften you will generate very large samples.  In these situations you\nusually don't want to display all the samples, just do calculations\nwith them.  The practical limits of ``large'' depend on the computer\nyou are using and how much time you are willing to spend on a\ncalculation.   For an operator like \\code{rnorm} and the others to be\nintroduced in this chapter, it's feasible to generate samples of size\n10,000 or 100,000 on an ordinary laptop computer.  \n\\begin{Schunk}\n\\begin{Sinput}\n> samps = rnorm(100000, mean=1000, sd=75)\n> mean( samps )\n\\end{Sinput}\n\\begin{Soutput}\nmean \n1000 \n\\end{Soutput}\n\\begin{Sinput}\n> sd( samps )\n\\end{Sinput}\n\\begin{Soutput}\n  sd \n75.3 \n\\end{Soutput}\n\\end{Schunk}\nNotice that the sample mean and standard deviation are quite close to\nthe population parameters in this large sample.  (Remember not to put commas in as punctuation in large numbers: it's \\code{100000} not 100,000.)\n\nThe simulations that you will do in later chapters\nwill be much more elaborate than the simple draws here.  Even with \ntoday's computers, you will want to use only a few hundred trials.\n\n\\subsection{Standard Probability Models}\n\nR provides a large set of operators like \\code{rnorm} for different\nprobability models.  All of these operators work in the same way:\n\\begin{itemize}\n\\item Each has a required first argument that gives the number of\ndraws to make.\n\n\\item Each has an optional set of parameters that specify the\nparticular probability distribution you want.\n\\end{itemize}\n\nAll the operators start with the letter \\code{r} --- standing for\n``random'' --- followed by the name of the probability model:\n\n\\bigskip\n\\centerline{\\begin{tabular}{llp{2.3in}l}\nFamily & R name & Parameters & \\\\\\hline\nNormal & \\texttt{rnorm} & \\texttt{mean},\\texttt{sd} & continuous\\\\\nUniform & \\texttt{runif} & \\texttt{min},\\texttt{max} & continuous\\\\\nBinomial & \\texttt{rbinom}& \\texttt{size},\\texttt{prob} & discrete\\\\\nPoisson & \\texttt{rpois}& Average rate (written \\texttt{lambda})& discrete \\\\\nExponential & \\texttt{rexp}& Same rate as in poisson but the parameter\nis called \\texttt{rate}.& continuous \\\\\nLognormal & \\texttt{rlnorm}& Mean and sd of the natural\nlogarithm. \\texttt{meanlog}, \\texttt{sdlog}& continuous \\\\\n$\\chi^2$ & \\texttt{rchisq} & Degrees of freedom (\\texttt{df})&continuous \\\\\nt & \\texttt{rt} & Degrees of freedom (\\texttt{df})&continuous\\\\\nF & \\texttt{rf} & Degrees of freedom in the numerator and in the\ndenominator (\\texttt{df1}, \\texttt{df2})&continuous\\\\\n\\end{tabular}}\n\\bigskip\n\\index{P}{rnorm@\\texttt{rnorm}}\n\\index{P}{runif@\\texttt{runif}}\n\\index{P}{rpois@\\texttt{rpois}}\n\\index{P}{rexp@\\texttt{rexp}}\n\\index{P}{rlnorm@\\texttt{rlnorm}}\n\\index{P}{rchisq@\\texttt{rchisq}}\n\\index{P}{rf@\\texttt{rf}}\n\\index{P}{rt@\\texttt{rt}}\n\\index{P}{rbinom@\\texttt{rbinom}}\n\\index{P}{Probability!random generators}\n\n\nTo use these operators, you first must choose a particular probability\nmodel based on the setting that applies in your situation.  This\nsetting will usually indicate what the population parameters should\nbe.  Some examples:\n\\begin{itemize}\n\n\\item You are in charge of a hiring committee \nthat is  going to interview three candidates selected from a\npopulation of job applicants that is 63\\% female.  How many of the\ninterviewees will be female?  Modeling this as random selection from\nthe applicant pool, a binomial model is appropriate.  The \\code{size}\nof each trial is 3, the probability of being female is 63\\%:\n\\begin{Schunk}\n\\begin{Sinput}\n> samps = rbinom(40, size=3, prob=0.63)\n> samps\n\\end{Sinput}\n\\begin{Soutput}\n [1] 1 3 2 2 1 2 3 1 1 1 1 2 2 2 2 1 2 1 2 2 2 1 3 1 2 1 2 1\n[29] 2 2 1 3 1 3 2 2 2 2 2 2\n\\end{Soutput}\n\\end{Schunk}\nThere are 40 trials here, since the first argument was set to 40.\nRemember, each of the trials is a simulation of one hiring event.  In\nthe first simulated event, two of the interviewees were female; in the\nthird only one was female.  Typically, you will be summarizing all the\nsimulations, for example to see how likely each possible outcome is.\n\\begin{Schunk}\n\\begin{Sinput}\n> table(samps)\n\\end{Sinput}\n\\begin{Soutput}\nsamps\n 1  2  3 \n14 21  5 \n\\end{Soutput}\n\\end{Schunk}\n\n\\item You want to simulate the number of customers who come into a\nstore over the course of an hour.  The average rate is 15 per hour.\nTo simulate a situation where customers arrive randomly, the poisson\nmodel is appropriate:\n\\begin{Schunk}\n\\begin{Sinput}\n> rpois(25, lambda=15)\n\\end{Sinput}\n\\begin{Soutput}\n [1] 18 15 13 15 14 15 19 10 17 25 13 13  8 19 14 13  8 19\n[19] 13 23 12 16 13 11 19\n\\end{Soutput}\n\\end{Schunk}\n\n\\item You want to generate a simulation of the interval between\nearthquakes as in Example \\ref{example:earthquake-intervals}.  To\nsimulate the random intervals with a typical rate of 0.03 earthquakes\nper year, you would use\n\\begin{Schunk}\n\\begin{Sinput}\n> rexp( 15, rate=0.03 )\n\\end{Sinput}\n\\begin{Soutput}\n [1]  16.48  13.43  18.74  44.05 129.50  66.52  39.94   5.31\n [9]  14.65  21.42  72.14  45.95  21.64  14.64  26.51\n\\end{Soutput}\n\\end{Schunk}\n\nNotice the huge variation in the intervals, from less than half a year\nto almost 90 years between earthquakes.\n\n\\end{itemize}\n\n\\subsection{Coverage Intervals}\n\n\\index{C}{coverage interval!computing}\n\nYou will often need to compute coverage intervals in order to describe \nthe range of likely outcomes from a random process.  R provides a\nseries of operators for this purpose; a separate operator for each\nnamed probability model.  The operators all begin with \\code{q},\nstanding for \\newword{quantiles}.  In all cases, the first argument is\nthe set of quantiles you want to calculate for the particular\nprobability model.  The optional named arguments are the parameters.\n\n\\index{C}{coverage interval!level}\nRemember\nthat to find a 95\\% coverage interval you need the 0.025 and 0.975\nquantiles.  For a 99\\% interval, you need the 0.005 and 0.995\nquantiles.\n\nTo illustrate, here are 95\\% coverage intervals for a few\nprobability models. \n\\begin{itemize}\n\\item A normal distribution with mean 0 and standard deviation 1:\n\\begin{Schunk}\n\\begin{Sinput}\n> qnorm( c(0.025, 0.975), mean=0, sd=1)\n\\end{Sinput}\n\\begin{Soutput}\n[1] -1.96  1.96\n\\end{Soutput}\n\\end{Schunk}\n> \n\n\\item The hiring committee situation modelled by a binomial\ndistribution with \\code{size=3} and \\code{prob=0.63}:\n\\begin{Schunk}\n\\begin{Sinput}\n> qbinom( c(0.025, 0.975), size=3, prob=0.63)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 0 3\n\\end{Soutput}\n\\end{Schunk}\n\nPerhaps you are surprised to see that the coverage interval includes\nall the possible outcomes.  That's because the number of cases in each\ntrial ($n=3$) is quite small. \n\n\\item The number of customers entering a store during an hour \nas modelled by a poisson\ndistribution with an average rate of 15 per hour.\n\\begin{Schunk}\n\\begin{Sinput}\n> qpois( c(0.025, 0.975), lambda=15)\n\\end{Sinput}\n\\begin{Soutput}\n[1]  8 23\n\\end{Soutput}\n\\end{Schunk}\n\n\\item The interval between earthquakes modelled by an exponential\ndistribution with a typical rate of 0.03 earthquakes per year:\n\\begin{Schunk}\n\\begin{Sinput}\n> qexp( c(.025, .975), rate=0.03)\n\\end{Sinput}\n\\begin{Soutput}\n[1]   0.844 122.963\n\\end{Soutput}\n\\end{Schunk}\n\\end{itemize}\n\n\\index{P}{quantiles!q-functions}\n\\index{P}{Probability!q operators}\n\\index{C}{quantiles!computing}\n\nYou can also use the \\code{q} operators to find the value that would\nbe at a particular percentile.  For example, the exponential model with \\code{rate=0.03} \ngives the 25th percentile of\nthe interval between earthquakes as:\n\\begin{Schunk}\n\\begin{Sinput}\n> qexp( .25, rate=0.03)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 9.59\n\\end{Soutput}\n\\end{Schunk}\nA quarter of the time, the interval between earthquakes will be 9.59\nyears or less.\n\nIt's entirely feasible to calculate percentiles and \ncoverage intervals by combining\nthe random-number generators with \\code{quantile}.  For example, here\nis the 95\\% coverage interval from a normal distribution with mean 0\nand standard deviation 1:\n\\begin{Schunk}\n\\begin{Sinput}\n> samps = rnorm(10000, mean=0, sd=1)\n> qdata( c(.025, .975), samps )\n\\end{Sinput}\n\\begin{Soutput}\n 2.5% 97.5% \n-1.99  1.95 \n\\end{Soutput}\n\\end{Schunk}\nThe disadvantage of this approach is that it is a simulation and the\nresults will vary randomly.  By making the sample size large enough\n--- here it is $n=10000$ --- you can reduce the random variation. \nUsing the \\code{q} operators uses mathematical analysis to give \nyou what is effectively an\ninfinite sample size.  For this reason, it's advisable to use the\n\\code{q} operators when you can.  However, for many of the techniques to\nbe introduced in later chapters you will have to generate a random\nsample and then apply \\code{quantile} to approximate the coverage intervals.\n\n\\subsection{Percentiles}\n\n\\index{P}{percentile!p-functions}\n\\index{C}{percentile!computing}\n\\index{P}{Probability!p operators}\n\\index{P}{Probability!q operators}\n\nA percentile computation applies to situations where you have a\nmeasured value and you want to know where that value ranks relative to\nthe entire set of possible outcomes.  You have already seen\npercentiles computed from samples; they also apply to probability models.\n\nIt's easy to confuse percentiles with quantiles because they are so\nclosely related.\nMathematically, the percentile operators are the inverse of the\nquantile operators. \nTo help you remember which is which, it's helpful to distinguish them\nbased on the type of argument that you give to the operator:\n\\begin{description}\n\\item[Percentile] The input \nargument is a measured value, something that could be the\noutput of a single draw from the probability distribution. The output\nis always a number between 0 and 1 --- a percentile. \n\n\\item[Quantile] The input is a percentile, a number between 0 and 1.\nThe output is on the scale of the measured variable.\n\\end{description}\n\n\nExample:  You have just gotten your score, 670, on a professional school\nadmissions test.  According to the information published by the\ntesting company, the scores are normally distributed with a mean of\n600 and a standard deviation of 100.  So, your ranking on the test, as\nindicated by a percentile, is:\n\\begin{Schunk}\n\\begin{Sinput}\n> pnorm(670, mean=600, sd=100)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 0.758\n\\end{Soutput}\n\\end{Schunk}\nYour score is at about the 75th percentile.  \n\nExample: Unfortunately, the professional school that you want to go to\naccepts only students with scores in the top 15 percent.  Your score,\nat 75.8\\%, isn't good enough.  So, you will study some more and take\npractice tests until your score is good enough.\nHow well will you need to score to reach the 85th percentile?\n\\begin{Schunk}\n\\begin{Sinput}\n> qnorm(0.85, mean=600, sd=100)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 704\n\\end{Soutput}\n\\end{Schunk}\n\n\n", "meta": {"hexsha": "beec0af53c4c51164972b1fa7f081fe09dcfc9b4", "size": 15242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ComputationalTechnique-Orig/RandomVars/computer-random.tex", "max_stars_repo_name": "dtkaplan/SM3", "max_stars_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-01T01:28:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T01:28:07.000Z", "max_issues_repo_path": "ComputationalTechnique-Orig/RandomVars/computer-random.tex", "max_issues_repo_name": "BriannaBarry/SM3", "max_issues_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "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": "ComputationalTechnique-Orig/RandomVars/computer-random.tex", "max_forks_repo_name": "BriannaBarry/SM3", "max_forks_repo_head_hexsha": "56fef8d4368e7afa7ccce006d8f4acc6cf6c1fd1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-02-14T05:22:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T12:42:15.000Z", "avg_line_length": 33.2794759825, "max_line_length": 145, "alphanum_fraction": 0.7508201023, "num_tokens": 4586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.6213105583358103}}
{"text": "\\documentclass{article}\n\\usepackage{parskip}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{cancel}\n\\usepackage{algorithmic}\n\n\\setlength{\\parindent}{0cm}\n\n\\begin{document}\n\n\\title{CPSC 413 \\\\ Assignment 4 - Dynamic Programming}\n\\author{Andrew Helwer}\n\\date{March 2011}\n\\maketitle\n\n\\section{Design a Divide and Conquer Algorithm}\n\nDefine a function $\\omega:v \\rightarrow \\mathbb{R}$ which returns the real\nweight of any vertex $v$.\n\nDefine a function $\\alpha:S \\rightarrow \\mathbb{R}$, which for\nany set of vertices $S$ has the following action:\n\\begin{equation*}\n\\alpha(S) = \\sum_{v \\in S} \\omega(v)\n\\end{equation*}\n\nWithin this document, the term \\textit{minimal vertex cover} will be synonymous\nwith a vertex cover $V \\subset T$ such that for any vertex cover $V'\n\\subset T$, $\\alpha(V) < \\alpha(V')$.\n\n$\\{nil\\} \\cup S = S$ for any set $S$, where $nil$ is the value of $v.left$ or\n$v.right$ if $v$ does not have a left or right child.\n\n\\textbf{1) Describe how to solve trivial instances:}\n\nOne trivial instance of this problem occurs when $|T| = 0$, that is when\n$cover(nil)$ is called. $\\emptyset$ should be returned in this instance.\n\nThe other trivial instance occurs when $|T| = 1$. $\\emptyset$\nwill be returned, as a graph with a single vertex $v$ has no edges and thus the\nvertex cover will either be $v$ or $\\emptyset$. Since $\\alpha(\\{v\\}) > 0$ and\n$\\alpha(\\emptyset) = 0$, $\\alpha(\\emptyset) < \\alpha(\\{v\\})$ and so $\\emptyset$\nis the vertex cover with minimal $\\alpha$.\n\n\\textbf{2) Describe how sub-instances should be formed from nontrivial ones:}\n\nDefine the function $\\pi(v)$ for any $v \\in T$, where:\n\\begin{displaymath}\n\\pi(v) = \\left\\{\n\t\\begin{array}{lr}\n\t\\emptyset & : v = nil \\\\\n\t\\{cover(v.left) \\cup cover(v.right)\\} & : v \\neq nil\n\t\\end{array}\n\t\\right.\n\\end{displaymath} \nConsider the case of a tree $T$ of arbitrary size. Given the root of $T$, $v$,\nsplit the problem as follows:\n\\begin{equation*}\nS_1 := \\{v\\} \\cup \\pi(v)\n\\end{equation*}\n\\begin{equation*}\nS_2 := \\{v.left\\} \\cup \\{v.right\\} \\cup \\pi(v.left) \\cup \\pi(v.right)\n\\end{equation*}\nThis will find the minimal vertex cover that includes $v$, $S_1$, and the\nminimal vertex cover that does not include $v$, $S_2$.\n\n\\textbf{3) Describe how a solution is formed from sub-instance solutions:}\n\nThe set of $V$ of all vertex covers for $T$ may be partitioned into two\nsubsets, where the root of $T$ is $v$:\n\\begin{itemize}\n\\item The set $V_1$ of all vertex covers for $T$ that include $v$\n\\item The set $V_2$ of all vertex covers for $T$ that do not include $v$\n\\end{itemize}\nSince $V_1 \\sqcup V_2 = V$, the minimal element of $V$ may be found by taking\nthe lesser of the minimal element in $V_1$ and the minimal element in $V_2$.\nSince the minimal element in $V_1$ is $S_1$ and the minimal element in $V_2$ is\n$S_2$, if $\\alpha(S_1) \\leq \\alpha(S_2)$, the minimal element of $V$ will be\n$S_1$. Otherwise, it will be $S_2$. So $cover(v)$ should return $S_1$ if\n$\\alpha(S_1) \\leq \\alpha(S_2)$ and $S_2$ otherwise.\n\n\\textbf{4) Describe a recursive algorithm implementation:}\n\n$cover(v)$\n\\begin{algorithmic}[1]\n\\IF {($v.left=nil$ and $v.right=nil$) or $v=nil$}\n\t\\RETURN $\\emptyset$\n\\ELSE\n\t\\STATE $S_1\\gets\\{v\\}\\cup\\pi(v)$\n\t\\STATE $S_2\\gets\\{v.left\\}\\cup\\{v.right\\}\\cup\\pi(v.left)\\cup\\pi(v.right)$\n\t\\IF {$\\alpha(S_1) \\leq \\alpha(S_2)$}\n\t\t\\RETURN $S_1$\n\t\\ELSE\n\t\t\\RETURN $S_2$\n\t\\ENDIF\n\\ENDIF\n\\end{algorithmic}\n\n\\textbf{5) Prove correctness of the algorithm using induction:}\n\nBase Cases: $|S|=1$ and $|S|=0$\n\nIn both cases, the If statement in Instruction 1 will evaluate to True, and so\ninstruction 2 will be executed, returning $\\emptyset$ as was shown to be\ncorrect in Part 1. Thus the Base Cases hold.\n\nInductive Case:\n\nInductive Hypothesis - assume $cover(v)$ is correct for the root $v$ of all\ntrees $T$ of size greater than 1 to $n$. Consider the case where $|T|=n+1$, $v$\nis the root of $T$, and $cover(v)$ is called:\n\nThe If statement in Instruction 1 will evaluate to False, and so Instructions 4\nand 5 will be executed. These split the problem into sets $S_1$ and $S_2$ as\nwas defined in Part 2. Since all recursive calls of $cover(u)$ will have $u$ as\none of $v.left$, $v.right$, $v.left.left$, $v.left.right$, $v.right.left$, or\n$v.right.right$, the tree for which $u$ is the root is guaranteed to be of size\nless than or equal to $n$. Thus $cover(u)$ will return correct output by the\nInductive Hypothesis, and so the values of $S_1$ and $S_2$ will be the minimal\nelements of $V_1$ and $V_2$. As was proved in Part 3, whichever of $S_1$ and\n$S_2$ have the smaller value of $\\alpha$ will be the minimal vertex cover of\n$T$, which will be decided by Instructions 6, 7, and 9. Therefore $cover(v)$\nreturns correct output.\n\nThus the correctness of $cover(v)$ has been proved by induction. $\\square$\n\n\\section{Design a Dynamic Programming Algorithm}\n\n\\textbf{6) Identify smaller instances that must be solved in nontrivial cases:}\n\nUsing the same procedure as in the Divide and Conquer algorithm, for a tree $T$\nwith root $v$, in order for $cover(v)$ to be solved we must know the minimal\nvertex covers for the subtrees of $T$ for which the following are roots:\n\\begin{itemize}\n\\item $v.left$\n\\item $v.right$\n\\item $v.left.left$\n\\item $v.left.right$\n\\item $v.right.left$\n\\item $v.right.right$\n\\end{itemize}\n\n\\textbf{7) Identify an ordering on these smaller instances:}\n\nSince we may represent instances of the problem as vertices in $T$ upon which\n$cover(v)$ is called, for any $u,w \\in T$, $u<w$ if and only if $u$ is visited\nbefore $w$ during a Postorder Traversal of $T$. This traversal is defined using\nthe following function, with $v$ the root of $T$:\n\n$postorder(v)$\n\\begin{algorithmic}[1]\n\\IF {$v.left \\neq nil$}\n\t\\STATE $postorder(v.left)$\n\\ENDIF\n\\IF {$v.right \\neq nil$}\n\t\\STATE $postorder(v.right)$\n\\ENDIF\n\\STATE visit $v$ and return\n\\end{algorithmic}\n\nClaim 7.1: For any $v \\in T$, if $postorder(v)$ recursively calls\n$postorder(v.left)$ or $postorder(v.right)$, then $v.left$ and $v.right$ will\nbe visited before $v$.\n\nProof: This follows from the structure of the algorithm above; if\n$postorder(v.left)$ is called from Instruction 2 inside $postorder(v)$, then no\nother instructions in $postorder(v)$ may be executed until $postorder(v.left)$\nreturns in Instruction 7, so $v.left$ will have been visited. So $v.left$ is\nvisited before $v$. By symmetry, $v.right$ will be visited before $v$ as\nwell, and so Claim 7.1 is true. $\\square$\n\nClaim 7.2: For any vertex $v \\in T$, all of the following are less than $v$ (if\nthey exist):\n\\begin{itemize}\n\\item $v.left$\n\\item $v.right$\n\\item $v.left.left$\n\\item $v.left.right$\n\\item $v.right.left$\n\\item $v.right.right$\n\\end{itemize}\nProof: Consider a call to $postorder(v)$. If $v.left$ exists,\n$postorder(v.left)$ is immediately called, so $v.left$ is visited before $v$ by\nClaim 7.1, and equivalently $v.left < v$. By symmetry, $v.right < v$ as\nwell. Inside the call to $postorder(v.left)$, if $v.left.left$ exists,\n$postorder(v.left.left)$ is called, so $v.left.left$ is visited before $v.left$\nby Claim 7.1, and equivalently $v.left.left < v.left$. Therefore by the\ntransitive property of an order relation, $v.left.left < v$. The proof is\nsymmetric for $v.left.right$, $v.right.left$, and $v.right.right$. Thus Claim\n7.2 is true. $\\square$\n\n\\textbf{8) Choose a data structure}\n\nThe data structure of choice will be a hash table, $H$, so that for any $v \\in\nT$, $H(v)$ returns the minimal vertex cover for the subtree of $T$ with $v$ as\nits root in $O(1)$ time. $H(nil)$ will return $\\emptyset$.\n\n\\textbf{9) Describe a dynamic programming implementation:}\n\nFirst redefine the function $\\pi(v)$ from above:\n\\begin{displaymath}\n\\pi(v) = \\left\\{\n\t\\begin{array}{lr}\n\t\\emptyset & : v = nil \\\\\n\t\\{H(v.left) \\cup H(v.right)\\} & : v \\neq nil\n\t\\end{array}\n\t\\right.\n\\end{displaymath}\n\n$cover(v)$\n\\begin{algorithmic}[1]\n\\IF {$v.left \\neq nil$}\n\t\\STATE $cover(v.left)$\n\\ENDIF\n\\IF {$v.right \\neq nil$}\n\t\\STATE $cover(v.right)$\n\\ENDIF\n\\IF {$v.left = nil$ and $v.right = nil$}\n\t\\STATE $H(v) \\gets \\emptyset$\n\\ELSE\n\t\\STATE $S_1\\gets\\{v\\}\\cup\\pi(v)$\n\t\\STATE $S_2\\gets\\{v.left\\}\\cup\\{v.right\\}\\cup\\pi(v.left)\\cup\\pi(v.right)$\n\t\\IF {$\\alpha(S_1) \\leq \\alpha(S_2)$}\n\t\t\\STATE $H(v) \\gets S_1$\n\t\\ELSE\n\t\t\\STATE $H(v) \\gets S_2$\n\t\\ENDIF\n\\ENDIF\n\\RETURN $H(v)$\n\\end{algorithmic}\n\n\\textbf{10) Prove correctness of the algorithm using induction:}\n\nNote that $cover(v)$ is simply a modified version of $postcover(v)$, with the\nvisit and return instruction replaced by a number of other instructions.\n\nBase Case:\n\nIf $cover(v)$ is called where $v$ is the only vertex in its tree, then both\nInstructions 1 and 4 will not be satisfied but Instruction 7 will be, so\nInstruction 8 will be executed and $H(v)$ set to $\\emptyset$, as it should be.\nThus the Base Case holds.\n\nInductive Step:\n\nInductive Hypothesis - assume $cover(v)$ is correct for the root $v$ of all\ntrees $T$ of size greater than 1 to $n$. Consider the case where $|T|=n+1$, $v$\nis the root of $T$, and $cover(v)$ is called:\n\nAt least one of Instructions 1 and 4 will be satisfied, so $cover(v.left)$\nor $cover(v.right)$ will be called, and since the subtree of $T$ for which\n$v.left$ or $v.right$ is a root is guaranteed to be of size at most $n$, by the\nInductive Hypothesis $cover(v.left)$ and $cover(v.right)$ will be correct.\nInstruction 7 will not be satisfied, so Instructions 10 and 11 will be executed.\nBy Claim 7.2, all of the vertices\nrequired to form sets $S_1$ and $S_2$ will have been visited, and by the\nInductive Hypothesis their values in the hash table $K$ will be correct, so\nthe values of $S_1$ and $S_2$ will be the minimal elements of $V_1$ and $V_2$.\nAs\nwas proved in Part 3, whichever of $S_1$ and $S_2$ have the smaller value of\n$\\alpha$ will be the minimal vertex cover of $T$, which will be decided by\nInstructions 12, 13, and 15. So $H(v)$ will contain the minimal vertex cover of\n$T$, which is returned in Instruction 18. Therefore $cover(v)$ returns correct\noutput.\n\nThus the correctness of $cover(v)$ has been proved by induction. $\\square$\n\n\\textbf{11) Define a bounding recurrence relation}\n\nAnalysis of $cover(v)$ will be simplified if we first perform some analysis of\n$postorder(v)$. Observe that in the worst case, five instructions will be\nexecuted on a single level of recursion in $postcover(v)$, two of which are\nrecursive calls. As this is a traversal, each vertex will be visited exactly\nonce, so Instruction 7 will be executed exactly $|V|$ times on different levels\nof recursion. We may therefore bound the number of instructions executed by\n$postorder(v)$ on a tree of size $n$ as follows:\n\\begin{equation*}\nT(n) \\leq 5n\n\\end{equation*}\nIn order to convert this equation into a form useful for analysis of\n$cover(v)$, define the number of instructions necessary to visit a vertex as\nthe variable $c$. So:\n\\begin{equation*}\nT(n) \\leq 4n + cn\n\\end{equation*}\nAs was noted in the proof of correctness, $cover(v)$ is simply a modified\nversion of $postorder(v)$ whereby the visit instruction is replaced with a\nnumber of operations. Looking at $cover(v)$, we see in the worst case there will\nbe six instructions executed when visiting a vertex, for example Instructions\n7, 10, 11, 12, 15, and 18. So, we can set $c=6$ in the above equation to bound\nthe number of instructions executed by $cover(v)$ on a tree of size $n$:\n\\begin{equation*}\nT(n) \\leq 4n + 6n\n\\end{equation*}\n\\begin{equation*}\nT(n) \\leq 10n\n\\end{equation*}\nThus $T(n)$ is of order $n$, and so $cover(v)$ runs in $O(n)$ time.\n\n\\end{document}\n", "meta": {"hexsha": "f6a32c58c21338ec869ca2491e4df9b88d46ba7d", "size": 11524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cpsc413/as4/cpsc413as4.tex", "max_stars_repo_name": "edwardchen123/UofC", "max_stars_repo_head_hexsha": "ecc49eee798772e560397fb00ad692e6f664c19b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-11T10:17:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-11T10:17:41.000Z", "max_issues_repo_path": "cpsc413/as4/cpsc413as4.tex", "max_issues_repo_name": "edwardchen123/UofC", "max_issues_repo_head_hexsha": "ecc49eee798772e560397fb00ad692e6f664c19b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cpsc413/as4/cpsc413as4.tex", "max_forks_repo_name": "edwardchen123/UofC", "max_forks_repo_head_hexsha": "ecc49eee798772e560397fb00ad692e6f664c19b", "max_forks_repo_licenses": ["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.1589403974, "max_line_length": 80, "alphanum_fraction": 0.7080874696, "num_tokens": 3603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.6213105499984488}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% BASED ON Hodge-King's\n%   IBL Week 4 Day 1 \"Derivative Matching Revised\"\n% DIRECTIONS: typeset twice to get positioning right\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\documentclass[letterpaper,10pt]{article}\n\\usepackage{pgfplots}\n\\pgfplotsset{compat=1.13}\n\\thispagestyle{empty}\n\\pagestyle{empty}\n\n\\newcounter{card}\n\\newcommand\\content[4]{\n\\begin{tikzpicture}[remember picture, overlay]\n\\draw (current page.north west)\n++({(floor(\\arabic{card}/5)+1/2)*1/3*8.5in},{(mod(\\arabic{card},5)+1/2)*-1/5*11in}) coordinate (center);\n\\draw (center) node {\n\t\\begin{tikzpicture}\n\t\\begin{axis}[\n\t\taxis equal image=false,\n\t\twidth=3in, height=2.4in,\n\t\tgrid=major, axis lines=center,\n\t\txmin=-3.1, xmax=3.1, xtick={-3,...,3},\n\t\tymin=-2.5, ymax=2.5, ytick={-2,...,2},\n\t\tmajor tick length={0},\n\t\tsamples=299,\n\t\tdomain=-3:3,\n\t\t% #4 = options for this particular graph, eg, xmax, ytick\n\t\t#4\n\t\t]\n\t\t% #2 = list of functions/options to plot = {fn1/op1, fn2/op2, etc}\n\t\t% global var \\fncolor = color of plot & title\n\t\t\\foreach \\function/\\options in {#2}{\n\t\t\t\\edef\\temp{\\noexpand\n\t\t\t\t\\addplot[ultra thick, smooth, \\fncolor, \\options]{\\function};\n\t\t\t\t}\n\t\t\t\\temp\n\t\t\t}\n\t\t% #3 = coordinates of open circles = {(x1,y1) (x2,y2), etc}, note no comma btw pts\n\t\t\\addplot [\\fncolor, only marks, very thick, mark=*, mark options={scale=1, fill=white}]\n\t\t\tcoordinates{#3};\n\t\t% global var \\titlef = title = f or f'\n\t\t% global var \\titlex = relative x position for title = number btw 0, 1\n\t\t\\node[\\fncolor] at (axis description cs: \\titlex,0.8) {\\huge$\\titlef$};\n\t\t% #1 = card ID number/letter\n\t\t\\node at (axis description cs: 0.95,0.05) {\\footnotesize#1};\n\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t};\n\t% cut guides\n\t\\foreach \\x/\\y in {1/1, 1/-1, -1/1, -1/-1}\n\t\\draw[gray] (center) ++(\\x*1/2*1/3*8.5in, \\y*1/2*1/5*11in)\n\t\tedge[-] ++(left:5mm)\n\t\tedge[-] ++(right:5mm)\n\t\tedge[-] ++(up:5mm)\n\t\tedge[-] ++(down:5mm)\n\t\t;\n\t\\end{tikzpicture}\n\t\\stepcounter{card}\n\t}\n\\newcommand\\contentb[2]{\\content{#1}{{#2}/{}}{}{restrict y to domain=-2.5:2.5,}}\n\\newcommand\\contentc[2]{\\content{#1}{{#2}/{}}{}{\n\txmin=-6.3, xmax=6.3, xtick={-6.28319,-3.14159,3.14159, 6.28319},\n\txticklabels={$-2\\pi$,$-\\pi$,$\\pi$, $2\\pi$},\n\tymin=-1.25, ymax=1.25, ytick={-1,-0.5,0.5,1}, \n\tdomain=-6.2:6.2\n\t}}\n\n\\begin{document}\n% FUNCTION CARDS\n\\def\\fncolor{black}\n\\def\\titlef{f}\n\\def\\titlex{0.2}\n\\contentb 1{2*x-1}\n\\contentb 2{-2*x+1}\n\\contentb 3{abs(x)}\n\\contentb 4{x^2+2*x}\n%\\contentc 5{sin(deg(x)}\n\\contentb 5{-x^3/3+0.5}\n\\contentb 6{x^3-x}\n\\contentb 7{(x+1)^4-1}\n\\content 8{ln(x)/domain=0.01:3}{}{samples=300}\n\\contentb 9{x^3/3+1}\n\\contentb {10}{x^(-1)}\n\\contentb {11}{2/(1+2.7182818^(-4*x+4))}\n\\contentb {12}{(x+1)/abs(x+1)*abs(x+1)^(1/3)}\n\\contentb {13}{2.7182818^(-x^2)}\n\\content {14}{0.333*x^3+1/domain=-3:1, x+0.333/{samples=99, domain=1:3}}{}{}\n\\content {15}{-x^4+4*x^2/{}}{}\n\t{ymin=-7.5, ymax=7.5, restrict y to domain=-7.5:7.5, ytick={-6,-3,...,6}}\n\n% DERIVATIVE CARDS\n\\newpage\n\\def\\fncolor{red}\n\\def\\titlef{f'}\n\\def\\titlex{0.8}\n\\setcounter{card}0\n\\contentb I2\n\\contentb E{-2}\n\\content O{-1/domain=-3:0, 1/domain=0:3}{(0,1) (0,-1)}{samples=2}\n\\contentb D{2*x+2}\n%\\contentc F{cos(deg(x))}\n\\contentb F{-x^2}\n\\contentb A{3*x^2-1}\n\\contentb M{4*(x+1)^3}\n\\content N{{1/x}/domain=0.1:3}{}{samples=30}\n\\contentb J{x^2}\n\\contentb K{-1*x^(-2)}\n\\contentb C{8*2.7182818^(-4*x+4)/(1+2.7182818^(-4*x+4))^2}\n\\content H{\n\t{(1/3)*1/(x+1)^2^(1/3)}/domain=-3:-1.01,\n\t{(1/3)*1/(x+1)^2^(1/3)}/domain=-0.99:3\n\t}{}{}\n\\contentb B{-2*x*2.7182818^(-x^2)}\n\\content G{x^2/domain=-3:1, 1/domain=1:3}{}{}\n\\content L{-4*x^3+8*x/{}}{}\n\t{ymin=-7.5, ymax=7.5, restrict y to domain=-7.5:7.5, ytick={-6,-3,...,6}}\n\n% SOLUTIONS\n\\newpage\n\\section*{Solutions}\n\\begin{tabular}{rl}\n1 & I %& $\\div$\n\\\\ 2 & E %& $\\star$\n\\\\ 3 & O %& =\n\\\\ 4 & D %& $\\triangle$\n\\\\ 5 & F %& $\\infty$\n\\\\ 6 & A %& \\&\n\\\\ 7 & M %& @\n\\\\ 8 & N %& $\\square$\n\\\\ 9 & J %& \\#\n\\\\ 10 & K %& \\%\n\\\\ 11 & C %& ?\n\\\\ 12 & H %& !\n\\\\ 13 & B %& $+$\n\\\\ 14 & G %& $\\heartsuit$\n\\\\ 15 & L %& $\\Rightarrow$\n\\end{tabular}\n\\end{document}\n", "meta": {"hexsha": "7704462f2d14a75062cf899bad7b2ffa0aa961cd", "size": 4015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc42-matching.tex", "max_stars_repo_name": "gatewaycat/latex", "max_stars_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-11T12:20:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T12:20:40.000Z", "max_issues_repo_path": "calc42-matching.tex", "max_issues_repo_name": "gatewaycat/byzorn", "max_issues_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc42-matching.tex", "max_forks_repo_name": "gatewaycat/byzorn", "max_forks_repo_head_hexsha": "ae8c701522875dcd6df5919378dff3550002e06a", "max_forks_repo_licenses": ["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.475177305, "max_line_length": 104, "alphanum_fraction": 0.5828144458, "num_tokens": 1806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6210648442207375}}
{"text": "\\subsection{Motion of a Point that moves relative to a Rigid Body}\n\\begin{frame}{Introduction}\\vskip -8mm\n\t\\begin{figure}[ht]\n\t\t\\centering\n\t\t\\includegraphics[width=80mm]{images/v_a_2.png}\n\t\\end{figure}\\vskip-4mm\n\tPosition of point $N$ in rigid body $(R_2)$:\n\t\\[\\vb{r}{N}=\\vb{r}{O}+\\vb{r}{NO}=\\vb{r}{O}+x\\ih+y\\jh+z\\kh\\]\n\\end{frame}\n\\begin{frame}\n\tVelocity vector $\\vb{v}{N}$ of point $N$:\\vskip1.25mm\n\t$\\displaystyle\\vb{v}{N}=\\vb{v}{O}+[\\dot{x}\\ih+\\dot{y}\\jh+\\dot{z}\\kh]+[x\\frac{d\\ih}{dt}+y\\frac{d\\jh}{dt}+z\\frac{d\\kh}{dt}]$\\\\\n\t$\\hskip 6.5mm\\displaystyle=\\vb{v}{O}+\\vb{v}{N(xyz)}^{\\bm r}+\\vb{\\omega}{}\\times\\vb{r}{}$\\vskip2.5mm\n\twhere $\\vb{v}{N(xyz)}^{\\bm r}$ is the relative velocity of point $N$ with respect to the reference frame of rigid body $(R_1)$.\\vskip 5mm\n\tAcceleration vector $\\vb{a}{N}$ of point $N$:\\vskip1.25mm\n\t$\\displaystyle\\vb{a}{N}=\\vb{a}{O}+[\\ddot{x}\\ih+\\ddot{y}\\jh+\\ddot{z}\\kh]+2\\vb{\\omega}{}\\times\\vb{v}{N(xyz)}^{\\bm n}+\\vb{\\alpha}{}\\times\\vb{r}{}+\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{})$\\\\\n\t$\\hskip6.25mm\\displaystyle= \\vb{a}{O}+\\vb{a}{N(xyz)}^{\\bm r}+\\vb{a}{N(xyz)}^{\\bm c}+\\vb{\\alpha}{}\\times\\vb{r}{}+\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{})$\\\\\n\twhere:\\\\\n\t$\\vb{a}{N(xyz)}^{\\bm r}$ is the relative acceleration of point $N$ with respect to the reference frame of rigid body $(R_1)$.\\\\\n\t$\\vb{a}{N(xyz)}^{\\bm c}$ is referred to as \\textit{Coriolis acceleration}.\\vskip2.5mm\n\tFor planar motions: $\\displaystyle \\vb{a}{O}= \\vb{a}{O}+\\vb{a}{N(xyz)}^{\\bm r}+\\vb{a}{N(xyz)}^{\\bm c}+\\vb{\\alpha}{}\\times\\vb{r}{}-\\vb{\\omega}{}^2\\vb{r}{}$\n\\end{frame}\n\\begin{frame}\n\t\\begin{block}{Formulas}\n\t\tFor any point $N$, its velocity and acceleration relative to a reference frame $O$ of a rigid body are:\n\t\t\\[\\begin{cases}\n\t\t\\vb{v}{N}=\\vb{v}{O}+\\vb{v}{NO}^{\\bm r}+\\vb{\\omega}{}\\times\\vb{r}{{NO}}\\\\\n\t\t\\vb{a}{N}=\\vb{a}{O}+\\vb{a}{NO}^{\\bm r}+2\\vb{\\omega}{}\\times\\vb{v}{NO}^{\\bm r}+\\vb{\\alpha}{}\\times\\vb{r}{{NO}}+\\vb{\\omega}{}\\times(\\vb{\\omega}{}\\times\\vb{r}{NO})\n\t\t\\end{cases}\\]\n\t\\end{block}\n\\end{frame}", "meta": {"hexsha": "738fd2fb4cd53fe3895763ebd868d4fe466a80cc", "size": 2021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Point_motion_relative_to_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/Point_motion_relative_to_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/Point_motion_relative_to_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": 65.1935483871, "max_line_length": 195, "alphanum_fraction": 0.6061355764, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789040926008, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6210648320614353}}
{"text": "\\section*{Web Appendix B}\n\n\\begin{proof}[Rest of the proof of Proposition 1]\nFor the random effects model, let us start from\n\\[\nf(x_{i}\\mid\\theta_{0},\\tau,\\sigma_{i})\\propto\\sum_{j=1}^{J}\\rho_{j}\\int1_{[\\alpha_{j-1},\\alpha_{j})}(u_{i})\\phi(x_{i}\\mid\\theta_{i},\\sigma_{i}^2)\\phi(\\theta_{i}\\mid\\theta_{0},\\tau^2)d\\theta_{i}.\n\\]\nTo calculate the normalizing constant, substitute $1_{[\\alpha_{j-1},\\alpha_{j})}(u_{i})=1_{[c_{j-1},c_{j})}(x_{i})$\nfirst. This is done since the \\emph{p}-value is calculated with respect\nto $\\sigma_{i}$, not the unknown ${\\tau^{2}+\\sigma_{i}^{2}}$.\nThen the normalizing constant is\n\\begin{eqnarray*}\n\\sum_{j=1}^{J}\\rho_{j}\\int1_{[c_{j-1},c_{j})}(x_{i})\\phi(x_{i}\\mid\\theta_{i},\\sigma_{i}^2)\\phi(\\theta_{i}\\mid\\theta_{0},\\tau)d\\theta_{i}dx_{i} & =\\\\\n\\sum_{j=1}^{J}\\rho_{j}\\int1_{[c_{j-1},c_{j})}(x_{i})\\phi(x_{i}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})dx_{i} & =\\\\\n\\sum_{j=1}^{J}\\rho_{j}\\left[\\Phi(c_{j-1}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})-\\Phi(c_{j}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})\\right]\n\\end{eqnarray*}\nUse that,\n\\[\n\\frac{\\phi(x_{i}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})1_{[\\alpha_{j-1},\\alpha_{j})}(u_{i})}{\\Phi(c_{j-1}\\mid\\theta,{\\tau^{2}+\\sigma_{i}^{2}})-\\Phi(c_{j}\\mid\\theta,{\\tau^{2}+\\sigma_{i}^{2}})}=\\phi_{[c_{j},c_{j-1})}(x_{i}\\mid\\theta,{\\tau^{2}+\\sigma_{i}^{2}}),\n\\]\nand we are done.\n%\\[\n%\\sum_{j=1}^{J}\\rho_{j}\\left[\\Phi(c_{j-1}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})-\\Phi(c_{j}\\mid\\theta_{0},{\\tau^{2}+\\sigma_{i}^{2}})\\right].\n%\\]\n\\end{proof}", "meta": {"hexsha": "dd43a755f899a0e5ee4a8223f14ba0db039be57c", "size": 1505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WebAppendix_B.tex", "max_stars_repo_name": "JonasMoss/p-hacking", "max_stars_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-14T23:18:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-14T23:18:58.000Z", "max_issues_repo_path": "WebAppendix_B.tex", "max_issues_repo_name": "JonasMoss/p-hacking", "max_issues_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-07-29T11:31:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-06T14:38:26.000Z", "max_forks_repo_path": "WebAppendix_B.tex", "max_forks_repo_name": "JonasMoss/p-hacking", "max_forks_repo_head_hexsha": "38c4e854cb9b6f8675ca384c3031db0d5ff9e642", "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": 60.2, "max_line_length": 260, "alphanum_fraction": 0.5980066445, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6210648312436025}}
{"text": "\\section{Quantum Field Theory}\r\n{\\bf Reminder:} To find extrema functional $x(t)$, \r\nsolve $\\delta \\int_{t_1}^{t_2} L(x, \\dot{x}) dt= 0$ by solving\r\n${\\frac {\\partial L} {\\partial x}}- {\\frac {d} {dt}} \r\n({\\frac {\\partial L} {\\partial {\\dot x}}})= 0$.\r\n$L=T-V$, $H= \\sum_i p_i {\\dot q}_i -L$, $p_i= {\\frac {\\partial L}{\\partial {\\dot{q}_i}}}$.  \r\nCanonical quantization replaces\r\nscalars with operators (e.g. - $p$, etc).  \r\n\\\\\r\n\\\\\r\n{\\bf Infinite degrees of freedom:}\r\nQuantum Field Theory describes quantum systems with an infinite number of degrees of freedom.  Here is an example:\r\nConsider $n$ particles of mass $m$ connected by identical springs with spring \r\nconstant $k$.  Let $y_i$ be the displacement of the\r\nparticles from their equilibrium position.\r\n$L\r\n= {\\frac 1 2} \\sum_{i=1}^n [m \\dot{y_i}-k(y_{i+1}-y_i)^2]\r\n= {\\frac 1 2} \\sum_{i=1}^n a [{\\frac m a} \\dot{y_i}-k {\\frac {(y_{i+1}-y_i)^2} a}]\r\n= a \\sum_{i=1}^n L_i $.  Let \r\n$n \\rightarrow \\infty$ then ${\\frac m a} \\rightarrow \\mu$, the linear density,\r\n${\\frac {y_{i+1}-y_i} a}= {\\frac {\\partial y} {\\partial x}}$ and $ka= Y$.\r\n$\\delta \\int_{t_1}^{t_2} dt \\int_{x_0}^{x_1} dx ({\\frac 1 2} \r\n[\\mu {\\dot{y}}^2 - Y ({\\frac {\\partial y}{\\partial x}})^2])= 0$ gives\r\n$\r\n{\\frac {\\partial} {\\partial x}} {\\frac {\\partial {\\cal L}} {\\partial {\\frac {\\partial y} {\\partial x}}}} +\r\n{\\frac {\\partial} {\\partial t}} {\\frac {\\partial {\\cal L}} {\\partial {\\frac {\\partial y} {\\partial t}}}} -\r\n{\\frac {\\partial {\\cal L}} {\\partial y}}$; where the term in the second integral \r\nis called the Lagrangian density denoted ${\\cal L}$.  The corresponding Hamiltonian density is\r\n${\\cal H}= \\dot{y} {\\frac {\\partial {\\cal L}} {\\partial {\\dot{y}}}}- {\\cal L}\r\n$.\r\n\\\\\r\n\\\\\r\n{\\bf Maxwell's equations as four vectors:}  \r\n$b_{\\mu}= ( {\\vec b}, i b_0)$; Lorentz transform is $x_{\\mu}'= a_{\\mu, \\nu} x_{\\nu}$ and\r\n$\\partial_{\\mu}' F = \\partial_{\\mu}' (x_{\\nu}) \\partial_{\\nu} (F)$.\r\nLet $j_{\\mu}$ be the four-vector\r\n$j_{\\mu}= ({\\vec j}, ic \\rho)$ and\r\n$$F_{\\mu, \\nu}=\r\n\\left(\r\n\\begin{array}{cccc}\r\n0 & B_3 & -B_2 & -iE_1 \\\\\r\n-B_3 & 0 & B_1 & -iE_2 \\\\\r\nB_2 & -B_1 & 0 & -iE_3 \\\\\r\niE_1 & iE_2 & iE_3 & 0 \\\\\r\n\\end{array}\r\n\\right).$$  \r\nMaxwell's equations become ${\\frac {\\partial F_{\\mu \\nu}} {\\partial x_{\\nu}}} = {\\frac {j_{\\mu}} c}$.\r\nNote the matrix is anti-symmetric.\r\nThis is also written as $\\partial_{\\nu} F_{\\mu \\nu}= {\\frac {j_{\\mu}} c}$.\r\n$F_{\\mu \\nu} F_{\\mu \\nu} = 2(|B|^2-|E|^2)$ is a scalar.  $F_{uv}= \\partial_u A_v- \\partial_v A_u$.\r\nKlein Gordon in four vector format:\r\n${\\cal L}= {\\frac 1 2} \\eta^{uv} \\partial_u \\partial_v \\phi - {\\frac 1 2} m \\phi^2$ where\r\n$\\eta_{uv}=\r\n\\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\n0 & -1 & 0 & 0 \\\\\r\n0 & 0 & -1 & 0 \\\\\r\n0 & 0 & 0 & -1 \\\\\r\n\\end{array}\r\n\\right)\r\n$; this is Minkowski's metric.\r\nA tensor, $v_i$ is \\emph{covariant} if it transforms as $(v_i)'= {\\frac {\\partial x_j} {\\partial x_i}} v_j$.\r\nA tensor, $v^i$ is \\emph{contravariant} if it transforms as $(v^i)'= {\\frac {\\partial x^i} {\\partial x^j}} v^j$.\r\nDifferentials are contravariant, $\\nabla$ is covariant.\r\n\\\\\r\n\\\\\r\nLorentz rotation by $\\theta$ followed by boost of $v$ along $x$ is\r\n$$\r\n\\left(\r\n\\begin{array}{cccc}\r\n\\gamma & -\\gamma v & 0 & 0 \\\\\r\n-\\gamma v & \\gamma & 0 & 0 \\\\\r\n0 & 0 & 1 & 0 \\\\\r\n0 & 0 & 0 & 1 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{cccc}\r\n1 & 0 & 0 & 0 \\\\\r\n0 & cos(\\theta) &  -sin(\\theta) & 0 \\\\\r\n0 &  sin(\\theta) &  cos(\\theta) & 0 \\\\\r\n0 & 0 & 0 & 1 \\\\\r\n\\end{array}\r\n\\right), \\gamma= {\\frac 1 {\\sqrt {1-v^2/c^2)}}}.$$\r\n\\\\\r\n\\\\\r\n{\\bf Yukawa potential:}  Neutral scalar field, ${\\cal L}= - ({\\frac 1 2} ({\\frac {\\partial \\phi} {\\partial x_{\\mu}}})^2\r\n+ \\mu^2 \\phi^2)$.  $E^2- |p|^2 c^2= m^2 c^4$.  \r\n$E \\rightarrow i \\hbar {\\frac {\\partial} {\\partial t}}$ and\r\n$p \\rightarrow - i \\hbar {\\frac {\\partial} {\\partial x_{\\mu}}}$, $\\mu \\leftrightarrow {\\frac {mc} {\\hbar}}$.\r\nUse the usual Fourier correspondance\r\n$\\tilde{\\phi}(k)= {\\frac 1 {(2 \\pi)^{3/2}}} \\int d^3 x (e^{- k \\cdot x} \\phi(x))$ and\r\n${\\phi}(x)= {\\frac 1 {(2 \\pi)^{3/2}}} \\int d^3 k (e^{k \\cdot x} \\tilde{\\phi}(k))$.\r\nNow consider a scalar potential field, $\\phi$, with a point source, $G$, satisfying the Klein-Gordon equation\r\n$\\Box^2 \\phi = G \\delta^{(3)}(x)$.  Multiply both sides by\r\n${\\frac 1 {(2 \\pi)^{3/2}}} (e^{- i k \\cdot x})$ \r\nand integrate remembering that $\\phi$ and its derivatives\r\nvanish at the limits of integration.  We get $(-|k|^2-\\mu^2) \\tilde{\\phi}(k)= G {\\frac 1 {(2 \\pi)^{3/2}}}$,\r\nso $\\phi(x)= {\\frac {e^{- \\mu r}} r}$ and ${\\cal H}_{int}= - {\\cal L}_{int}$.\r\n\\\\\r\n\\\\\r\n{\\bf Transformations:}\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n\\phi_1' \\\\\r\n\\phi_2' \\\\\r\n\\end{array}\r\n\\right)\r\n=\r\n\\left(\r\n\\begin{array}{cc}\r\ncos(\\lambda) & - sin(\\lambda)\\\\\r\nsin(\\lambda) &  cos(\\lambda)\\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{c}\r\n\\phi_1 \\\\\r\n\\phi_2 \\\\\r\n\\end{array}\r\n\\right)\r\n$ for free fields of identical mass.\r\nConsider $n$ scalar fields $\\phi_a$ with the same mass and ${\\cal L}$.\r\n${\\cal L}= {\\frac 1 2} \\sum_{i=1}^n \\partial_{\\mu} \\phi_a \\partial_{\\mu} \\phi_a - {\\frac 1 2} \\sum_{i=1}^n\r\nm^2 \\phi_a^2 - g (\\sum_{i=1}^n \\phi_a^2)^2$,  ${\\cal L}$ is invariant under $G= SO_n$.  Non-abelian symmetries\r\nare global symmetries.\r\nTranslation invariance gives \\emph{conservation of momentum}.\r\nTime invariance gives \\emph{conservation of energy}.\r\n\\emph{First quantization} promotes values (position, momentum, energy) to operators \r\n($E \\rightarrow i \\hbar {\\frac {\\partial}{\\partial t}}$,\r\n$p \\rightarrow -i \\hbar \\nabla$) and impose commutator realtionships.\r\n\\emph{Second quantization} position, momentum, energy etc. remain scalar but\r\nfields like potential and conjugate momentum become operators; commutator relations imposed on field operators.\r\n\\\\\r\n\\\\\r\n{\\bf Invariance and conserved quantities:}  \r\nIf $i \\hbar {\\frac {d O(t)}{dt}}= [O(t),H]=0$, $O$ is a constant of the motion.   Now let\r\n$|\\Phi\\rangle \\rightarrow |\\Phi'\\rangle= U |\\Phi\\rangle$ so\r\n$O= U^{\\dagger} O U$; often $U= e^{i \\alpha T}$ where $\\alpha$ is a continuous parameter.  For an\r\ninfinitesimal translation, $U= I+i \\delta \\alpha T$ and $\\delta O= i \\delta \\alpha [T, O]$.\r\nInvariance of the Lagrangian under a transformation,\r\nleads to \r\n${\\frac {\\partial f^{\\alpha}}{\\partial x^{\\alpha}}}=0$ and\r\n$F^{\\alpha}(t)= \\int d^3 x \\thinspace {\\frac {\\partial f^{\\alpha}}{\\partial x^{\\alpha}}}$ \r\nis a conserved quantity.\r\nFor example, suppose $\\phi_r(x) \\rightarrow \\phi_r'(x)= \\phi_r(x)+ \\delta \\phi_r(x)$.  The Lagrangian transforms\r\nas \r\n$\\delta({\\cal L})= {\\frac {\\partial {\\cal L}} {\\partial \\phi_r}} \\delta \\phi_r +\r\n{\\frac {\\partial {\\cal L}} {\\partial \\phi_{r, \\alpha}}} \\delta \\phi_{r, \\alpha}$ which applying the\r\nminimum condition becomes\r\n$\\delta({\\cal L})= {\\frac {\\partial } {\\partial x^{\\alpha}}} \r\n{\\frac {\\partial {\\cal L}} {\\partial \\phi_{r, \\alpha}}} \\delta \\phi$; here,\r\n$f^{\\alpha}= {\\frac {\\partial {\\cal L}} {\\partial \\phi_{r, \\alpha}}} \\delta \\phi$.\r\nThis gives $Q= {\\frac {-i q}{\\hbar}} \\int d^3 x [\\pi_r(x)\\phi_r(x)-\\pi^{\\dagger} \\phi^{\\dagger}]$ as a conserved\r\nquantity.  $Q$ is charge.  If instead we consider translation invariance we get conservation of energy/momentum.\r\nRotational invariance gives conservation of angular momentum.\r\n\\\\\r\n\\\\\r\n{\\bf Standard script for classical $\\rightarrow$ quantum field theory:}\r\nPromote conjugate variables to operators $\\langle \\phi_r, \\pi_s \\rangle$ and \\emph{quantize} as\r\n$[\\phi_r(j,t), \\pi_s(j',t)]= i \\hbar \\delta_{rs} \\delta_{jj'}$,\r\n$[\\phi_r(j,t), \\phi_s(j',t)]= [\\pi_r(j,t), \\pi_s(j',t)]= 0$, and\r\n$[\\phi_r(x,t), \\pi_s(x',t)]= i \\hbar \\delta_{rs} \\delta(x-x')$.\r\n\\\\\r\n\\\\\r\n{\\bf The complex potential:}  Consider two real scalar fields \r\n$\\phi_1$, \r\n$\\phi_2$ and put\r\n$\\phi = {\\frac 1 {\\sqrt 2}} (\\phi_1 + i \\phi_2)$.  If \r\n$\\phi$ is the solution to the Klein Gordon\r\nequation in the presence of a potential $A_{\\mu}$ with charge $e$, then\r\n$\\phi^*$ is the solution to the Klein Gordon\r\nequation in the presence of a potential $A_{\\mu}$ with charge $-e$.\r\nThe \\emph{charge current density}, $s_{\\mu}= i(\r\n{\\frac {\\partial \\phi^*} {\\partial {x_{\\mu}}}} \\phi -\r\n\\phi^*{\\frac {\\partial \\phi} {\\partial {x_{\\mu}}}})$ \r\nsatisfies ${\\frac {\\partial s_{\\mu}} {\\partial x_{\\mu}}}= 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Creation and annihilation operators:}  We look at photons.\r\nLet $\\mu_{k, \\alpha}(x)= \\epsilon^{(\\alpha)}(k) e^{i k \\cdot x}$ where $\\alpha$ is the linear polarization\r\nselected so that $ \\epsilon^{(1)}, \\epsilon^{(2)}, k $ form an oriented orthogonal triad.  Consider the\r\npotential bounded in space by a cube of side length $L$, $V= L^3$.\r\n$A(x, t)= {\\frac 1 {V^{1/3}}} \\sum_k \\sum_{\\alpha=1,2} (\r\nc_{k,\\alpha} \\mu_{k, \\alpha}(x)+ c_{k,\\alpha}^* \\mu_{k, \\alpha}^*(x))$. \r\nWe have $H= {\\frac 1 2} \\int (|B|^2+|E|^2) d^3x$, $H= \\sum_k \\sum_{\\alpha} \r\n2({\\frac {\\omega} c})^2 c_{k,\\alpha}^* c_{k,\\alpha} $.  Put\r\n$Q_{k, \\alpha}= {\\frac 1 c} \r\n(c_{k, \\alpha}+\r\nc_{k, \\alpha}^*)$,\r\nand\r\n$P_{k, \\alpha}= -{\\frac {\\omega} c} (c_{k, \\alpha}- c_{k, \\alpha}^*)$.\r\n${\\frac {\\partial H} {\\partial Q_{k, \\alpha}}}= - \\dot{P}_{k, \\alpha}$ and\r\n${\\frac {\\partial H} {\\partial P_{k, \\alpha}}}= \\dot{Q}_{k, \\alpha}$,\r\nWe get\r\n$ {\\frac 1 {V^{1/3}}} \\int d^3 x \r\n(\\mu_{k, \\alpha} \\cdot\r\n\\mu_{k', \\alpha'}^*) = \\delta_{k, k'} \\delta_{\\alpha. \\alpha'}$, $k_x, k_y, k_z= {\\frac {2 \\pi n} L}$ and\r\n$\\omega= |k|c$.  Make\r\n$P_{k, \\alpha}$ and\r\n$Q_{k, \\alpha}$ \r\noperators as usual giving\r\n$[Q_{k, \\alpha}, P_{k', \\alpha'}]= \\pm i \\hbar \\delta_{k, k'} \\delta_{\\alpha, \\alpha'}$,\r\n$[Q_{k, \\alpha}, Q_{k', \\alpha'}]= 0$,\r\n$[P_{k, \\alpha}, P_{k', \\alpha'}]= 0$.\r\nThe \\emph{annihilation operator} is \r\n$a_{k, \\alpha}= {\\frac 1 {\\sqrt {2 \\hbar \\omega}}} ( \\omega Q_{k, \\alpha} + i P_{k, \\alpha})$.\r\nThe \\emph{creation operator} is \r\n$a_{k, \\alpha}^{\\dagger}= {\\frac 1 {\\sqrt {2 \\hbar \\omega}}} ( \\omega Q_{k, \\alpha} - i P_{k, \\alpha})$.\r\n$N_{k, \\alpha}= a_{k, \\alpha}^{\\dagger} a_{k, \\alpha}$.\r\n$N |n \\rangle= n |n \\rangle$,\r\n$N a^{\\dagger} |n \\rangle= (n+1) |n \\rangle$,\r\n$N a |n \\rangle= (n-1) |n \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Aharonov Bohm:}\r\nFor double slit setup with puddle of $B \\neq 0$ completely inside the strip of the two slits.\r\n$\\phi= \r\n\\phi_1^{(0)} exp[{\\frac {ie} {\\hbar c}} \\int_{\\small path 1} A(x') \\cdot dx'] +\r\n\\phi_2^{(0)} exp[{\\frac {ie} {\\hbar c}} \\int_{\\small path 2} A(x') \\cdot dx'] $.  \r\n$\r\n\\int_{\\small closed \\; path} A(x') \\cdot dx'=\r\n\\int_{\\small surface} B \\cdot n \\; dS= {\\frac {e \\Phi} {\\hbar c}}$.  For superconducting ring, with Cooper pair\r\nquasi-particle,\r\n$\\phi= \\phi^{(0)} exp[{\\frac {2ie} {\\hbar c}} \\int_{\\small closed \\; path} A(x') \\cdot dx']$.  Since $\\phi$ is\r\nthe same whether or not the path encloses the flux;\r\n${\\frac {2e}{\\hbar c}} \r\n\\int_{\\small closed \\; path} A(x') \\cdot dx'\r\n= 2n \\pi$, so $\\Phi= {\\frac {n \\pi \\hbar c}{e}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Pauli matricies and the Dirac equation:}\r\n$\\sigma_1=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -i\\\\\r\ni & 0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\sigma_2=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0 & -1\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\sigma_3=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & 1\\\\\r\n1 & 0\\\\\r\n\\end{array}\r\n\\right)$.\r\n\\begin{center}\r\n\\begin{tabular} {|c|c||c|c|}\r\n\\hline\r\nParticle & Mass & Particle & Mass\\\\\r\n\\hline\r\n1 & 2 & $\\ldots$ & n\\\\\r\n\\hline\r\nNeutrino & $10^{-2} eV$ & Proton/Neutron & $1 GeV$\\\\\r\nElectron & $.5 MeV$ & $\\tau$ & $ 2 GeV$ \\\\\r\nMuon & $100 MeV$ & $W, Z$ Boson & $80-90 GeV$ \\\\\r\nPion & $140 MeV$ & $W, Z$ Higgs & $120-200 GeV$ \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Particles from the vacuum:}\r\n$ [H, a_p^{\\dagger}] = \\omega_p a_p^{\\dagger}$,\r\n$ [H, a_p] = - \\omega_p a_p$, $|p \\rangle = a_p^{\\dagger} |0 \\rangle$ and\r\n$ H |p \\rangle =  \\omega_p |p \\rangle$, $\\omega_p^2= p^2 + m^2$.  $P|p \\rangle = p | p \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf The Dirac equation:}\r\n$(i \\gamma^u \\partial_u- {\\frac {mc}{\\hbar}}) \\phi = 0$.\r\nTime reversal transformation is $T: x^0 \\rightarrow -x^0$; $x^i \\rightarrow x^i$.\r\nParity reversal transformation is $P: x^0 \\rightarrow x^0$; $x^i \\rightarrow -x^i$.\r\n$\\gamma_k=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -i\\sigma_k\\\\\r\ni \\sigma_k  & 0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\gamma_0=\r\n\\left(\r\n\\begin{array}{cc}\r\nI & 0\\\\\r\n0  & -I\\\\\r\n\\end{array}\r\n\\right)$.\r\nDirac wanted to find a field equation with linear operators:\r\n$E= \\alpha \\cdot p + \\beta m$, $i {\\frac {\\partial \\phi} {\\partial t}} (-i \\alpha \\cdot \\nabla + \\beta m) \\phi$\r\nand require $E^2 = m^2 + |p|^2$.\r\n$\\alpha=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & \\sigma\\\\\r\n\\sigma  & 0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\beta=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0  & -1\\\\\r\n\\end{array}\r\n\\right)$.  \r\nUnder spacetime transformation, spinor transforms as $\\delta \\phi = \\epsilon^u \\partial_u \\phi$.\r\n$T^{\\mu \\nu} \\partial^{\\mu} \\phi \\partial^{\\nu} \\phi - \\eta^{\\mu, \\nu} {\\cal L}$.\r\n\\\\\r\n\\\\\r\n{\\bf Angular momentum:}\r\n$L= r \\times p$.  If $[H, L]= 0$, angular momentum is conserved.\r\n$[H, L] = [\\alpha \\cdot p, r \\times p]= i \\alpha \\times p$.\r\n$\\Sigma= \\left(\r\n\\begin{array}{cc}\r\n\\sigma & 0\\\\\r\n0  & \\sigma\\\\\r\n\\end{array}\r\n\\right)$, $[H, \\Sigma] = [\\alpha \\cdot p, -i\\alpha_1 \\alpha_2 \\alpha_3 \\alpha]= 2i \\alpha \\times p$.\r\n$J= L + {\\frac 1 2} \\Sigma$ is conserved, $[H,J]= 0$.\r\nLagrangian for free Dirac field is ${\\cal L}= {\\overline {\\phi}} (i \\gamma^u \\partial_u -m) \\phi=\r\n\\phi_i(i[\\gamma^u]_{ij} \\partial_u - m \\delta_{ij}) \\phi_j$.\r\n\\\\\r\n\\\\\r\n{\\bf Solving the Dirac equation for a free scalar field:}\r\n$(i \\gamma^0 \\partial_t-m ) \\phi=0$, gives\r\n$i \\gamma^0 \\partial_t \\phi= i \r\n\\left(\r\n\\begin{array}{cc}\r\nI & 0\\\\\r\n0  & -I\\\\\r\n\\end{array}\r\n\\right) $ or\r\n$ \\left(\r\n\\begin{array}{cc}\r\n{\\frac {\\partial u} {\\partial t}} \\\\\r\n{\\frac {\\partial u} {\\partial t}}\\\\\r\n\\end{array}\r\n\\right) =\r\nm\r\n\\left(\r\n\\begin{array}{cc}\r\nu \\\\\r\nv \\\\\r\n\\end{array}\r\n\\right)\r\n$, where\r\n$u=\r\n\\left(\r\n\\begin{array}{cc}\r\n\\phi_1 \\\\\r\n\\phi_2 \\\\\r\n\\end{array}\r\n\\right)\r\n$ and\r\n$u=\r\n\\left(\r\n\\begin{array}{cc}\r\n\\phi_3 \\\\\r\n\\phi_4 \\\\\r\n\\end{array}\r\n\\right)\r\n$.  Note $u$ and $v$ correspond to spin states;\r\n$ \\left(\r\n\\begin{array}{cc}\r\n1\\\\\r\n0\\\\\r\n\\end{array}\r\n\\right) $ is spin up and\r\n$ \\left(\r\n\\begin{array}{cc}\r\n0\\\\\r\n1\\\\\r\n\\end{array}\r\n\\right) $ is spin down.\r\nThus $i {\\dot{u}}= mu$ and\r\n$-i {\\dot{v}}= mv$, so\r\n$u(t)= u(0)e^{-imt}$ and\r\n$v(t)= v(0)e^{imt}$.\r\n\\\\\r\n\\\\\r\n{\\bf Free field solution of Klein-Gordon:}\r\nHere $\\hbar=1$.  $\\varphi(x, t) = A e^{Et-p \\cdot x} = A e^{\\omega_k x^0- k \\cdot x}$ leading to\r\n$\\varphi(x) = \\int {\\frac {d^3k}{(2 \\pi)^{3/2} {\\sqrt {2 \\omega_k}}}}\r\n(\\tilde{\\varphi}(k) e^{\\omega_k x^0- k \\cdot x} +\r\n\\tilde{\\varphi}(k)^* e^{\\omega_k x^0- k \\cdot x} )\r\n$.  Promote\r\n$\\tilde{\\varphi}(k) \\rightarrow \\hat{a}$ and\r\n$\\tilde{\\varphi}(k)^* \\rightarrow \\hat{a}^{\\dagger}$.\r\n${\\cal L}= {\\frac 1 2} \\partial_{\\mu} \\partial^{\\mu} \\varphi - {\\frac 1 2} m^2 \\varphi^2$ and\r\n$\\pi(x)= {\\frac {\\partial {\\cal L}} {\\partial ({\\partial_0 \\varphi)}}}$.\r\n$\\hat{\\pi}(x) = -i \\int {\\frac {d^3k}{(2 \\pi)^{3/2}}} {\\sqrt {\\frac {\\omega_k}{2}}}\r\n[(\\tilde{a}(k) e^{-(\\omega_k x^0- k \\cdot x)} -\r\n\\tilde{a}^{\\dagger}(k)^* e^{\\omega_k x^0- k \\cdot x} ) $.  \r\n$[x_i, p_j]= i \\delta_{ij}$,\r\n$[x_i, x_j]= 0$,\r\n$[p_i, p_j]= 0$.  \r\n$|k_1, k_2\\rangle=\r\n\\tilde{a}^{\\dagger}(k_1)\r\n\\tilde{a}^{\\dagger}(k_2) |00\\rangle $.\r\nEach $\\hat{a}^{\\dagger}(k_i)$ creates a single particle of\r\nmomentum $\\hbar k_i$ and energy $\\hbar \\omega_k$.\r\n$\\varphi^+(x)=\r\n\\int {\\frac {d^3k}{(2 \\pi)^{3/2}}} {\\sqrt {\\frac {\\omega_k}{2}}} \\hat{a}^{\\dagger}(k) e^{-(\\omega_k x^0 - k \\cdot x)}$ \r\nand positive frequency corresponds to annihilation.\r\n$\\varphi^-(x)=\r\n\\int {\\frac {d^3k}{(2 \\pi)^{3/2}}} {\\sqrt {\\frac {\\omega_k}{2}}} \\hat{a}^{\\dagger}(k) e^{(\\omega_k x^0 - k \\cdot x)}$ \r\nand negative frequency corresponds to creation.\r\n\\\\\r\n\\\\\r\n{\\bf Normalization:}\r\n$\\langle 0| 0 \\rangle= 1$,\r\n$\\langle k| k' \\rangle= \\delta(k-k')$ for bosons.\r\n$\\langle 0| \\hat{H}|0 \\rangle= \\langle0| \\int d^3k (N(k)+ {\\frac 1 2})\r\n|0\\rangle = {\\frac {\\omega_k} 2} \\int d^3k$.  \\emph{Renormalized:}\r\n$\\hat{H}_R= \\hat{H} -\\int d^3k= \\int d^3k (\\omega_k \\hat{a}^{\\dagger}(k) \\hat{a}(k)$ and\r\n$\\langle k | \\hat{H}_R | k\\rangle= \\omega_k$.\r\n\\\\\r\n\\\\\r\n{\\bf Propagators:}\r\n$\\hat{P}= \\int d^3k (k[\\hat{a}^{\\dagger}(k) \\hat{a}(k) + \\hat{b}^{\\dagger}(k) \\hat{b}(k)])$.\r\n$\\hat{Q}= \\int d^3k [\\hat{a}^{\\dagger}(k) \\hat{a}(k) + \\hat{b}^{\\dagger}(k) \\hat{b}(k)]$.\r\n$\\hat{H}= \\int d^3k (\\omega_k [\\hat{a}^{\\dagger}(k) \\hat{a}(k) + \\hat{b}^{\\dagger}(k) \\hat{b}(k)])$.\r\nThe number of particles is $\\hat{N}_a= \\int d^3k [\\hat{a}^{\\dagger}(k) \\hat{a}(k)]$;\r\nthe number of anti-particles is $\\hat{N}_b= \\int d^3k [\\hat{b}^{\\dagger}(k) \\hat{b}(k)]$.\r\n$[\\hat{\\psi}(x), \\hat{\\psi}(h)]= i \\Delta(x-y)$ is a \\emph{propagator}.  Feynman propagator is\r\n$\\Delta_F(x-y)= \\langle 0 | T \\psi(x) \\psi(y) | 0 \\rangle = D(x-y), x^0>y^0$, $T$ is the time ordering operation.\r\nNote that an events are \\emph{causal} if $[O_1(x), O_2(y)]=0$ when $(x-y)^2<0$.\r\n\\\\\r\n\\\\\r\n{\\bf Momentum space:}\r\n$\\langle x' | \\alpha \\rangle= \\psi_{\\alpha}(x')$, $\\langle \\beta | \\alpha \\rangle= \\int dx' \\langle \\beta | x' \\rangle\r\n\\langle x' | \\alpha \\rangle$.  \r\n$| \\alpha \\rangle = \\sum_{a'}  |a'\\rangle \\langle a' | \\alpha\\rangle$,\r\n$\\langle x'| \\alpha \\rangle = \\sum_{a'}  \\langle x'|a'\\rangle \\langle a' | \\alpha\\rangle$.\r\n$p | \\alpha \\rangle = \\int dx' | x' \\rangle (\\langle x' | \\alpha \\rangle - \r\n\\Delta x' {\\frac {\\partial} {\\partial x'}} \\langle x' | \\alpha \\rangle$.\r\n$p | \\alpha \\rangle = \\int dp | p' \\rangle (\\langle p' | \\alpha \\rangle$,\r\n$\\langle p' | \\alpha \\rangle = \\int dp \\langle p | p' \\rangle (\\langle p' | \\alpha \\rangle$, $\\langle p' | \\alpha \\rangle=\r\n\\psi_{\\alpha}(p)$.  $p' \\langle x' |p \\rangle \\langle p' | \\alpha \\rangle$ and thus\r\n$p' \\langle x' | p \\rangle = - i \\hbar {\\frac {\\partial} {\\partial x'}} \\langle x' | p' \\rangle$\r\nand $\\langle x' | p' \\rangle = N e^{i (p' \\cdot x')/ \\hbar}$.\r\n$\\psi_{a}(x')= {\\frac 1 {\\sqrt {2 \\pi \\hbar}}} \\int dp' exp({\\frac {i (p' \\cdot x')} {\\hbar}}) \\phi_{a}(p')$;\r\n$\\phi_{a}(p') \\rangle)= {\\frac 1 {\\sqrt {2 \\pi \\hbar}}} \\int dx' exp({\\frac {-i (p' \\cdot x')} {\\hbar}}) \\psi_{a}(x')$.\r\n\\\\\r\n\\\\\r\n{\\bf Derivation of Hamiltonian from creation and annihilation operators:}\r\n$\\hat{a} \\hat{a}^{\\dagger}= ( {\\frac {m \\omega}{2 \\hbar}}) [ \\hat{x}^2 + {\\frac {\\hat{p}^2} {(m \\omega)^2}}\r\n- {\\frac {i \\hat{x} \\cdot \\hat{p}} {(m \\omega)}} + {\\frac {i \\hat{x} \\cdot \\hat{p}} {(m \\omega)}} ] =\r\n({\\frac {m \\omega}{2 \\hbar}}) [ \\hat{x}^2 + {\\frac {\\hat{p}^2} {(m \\omega)^2}}\r\n- {\\frac {i} {(m \\omega)}} + {\\frac {i \\hat{x} \\cdot \\hat{p}} {(m \\omega)}} ] =\r\n({\\frac {m \\omega}{2 \\hbar}}) [ \\hat{x}^2 + {\\frac {\\hat{p}^2} {(m \\omega)^2}} + {\\frac {\\hbar} {(m \\omega)}} ]$.  Similarly,\r\n$ \\hat{a}^{\\dagger} \\hat{a} = ({\\frac {m \\omega}{2 \\hbar}}) [ \\hat{x}^2 + {\\frac {\\hat{p}^2} {(m \\omega)^2}}\r\n- {\\frac {\\hbar} {(m \\omega)}} ] $.  Combining, $\\hat{H}={\\frac 1 2} \\hbar \\omega [ \\hat{a}^{\\dagger} \\hat{a} + \\hat{a} \\hat{a}^{\\dagger} ] =\r\n\\hbar \\omega ( \\hat{a}^{\\dagger} \\hat{a} + {\\frac 1 2})$.  Note, $[\\hat{a}, \\hat{a}^{\\dagger}]= 1$.\r\nNow, put $N= \\hat{a}^{\\dagger} \\hat{a}$ then $[\\hat{a}^{\\dagger}, N]= -\\hat{a}^{\\dagger}$ and\r\n$[\\hat{a}, N]= \\hat{a}$.  Thus, $N \\hat{a} = \\hat{a}N - \\hat{a}= \\hat{a} (N-1)$ and\r\n$N \\hat{a}{\\dagger} = \\hat{a}{\\dagger} (N+1)$.  Now, $\\langle \\psi | N | \\psi \\rangle \\geq 0$ and is $0$ iff\r\n$\\hat{a} | \\psi \\rangle= 0$.  Now suppose $\\lambda$ is an eignevalue of $N$:\r\n$N |\\psi \\rangle = \\lambda | \\psi \\rangle$.  By the above,\r\n$N \\hat{a}^{\\dagger} | \\psi \\rangle = \\hat{a}^{\\dagger} (\\lambda +1) | \\psi \\rangle$ and\r\n$N \\hat{a} | \\psi \\rangle = (\\lambda -1) \\hat{a} | \\psi \\rangle$,\r\nso $\\lambda+1$ and $\\lambda-1$ are also an eigenvalues of $N$ corresponding with eigenvectors\r\n$\\hat{a}{\\dagger}| \\psi \\rangle$ and $\\hat{a} | \\psi \\rangle$ respectively.  Repeated application yields\r\n$\\hat{a}^n | \\psi \\rangle$ is an eigenvector of $N$ with eigenvalue $(\\lambda -1) \\ldots (\\lambda -n)$\r\nIf $\\lambda \\notin {\\mathbb Z}^{+}$, $\\lambda -n$ is eventually negative and is never $0$  but then,\r\n$\\langle \\psi | N | \\psi \\rangle \\leq 0$ eventually which is impossible, so $\\lambda \\in {\\mathbb Z}^{+}$.\r\nPutting $| n \\rangle= c_n \\hat{a}^{\\dagger} | 0 \\rangle$ with $\\langle n | n \\rangle = 1$.  We get\r\n$c_n = {\\frac {c_{n-1}} {\\sqrt n}}$.\r\n$0= \\langle x | \\hat{a} | 0 \\rangle =\r\n({\\frac {(m \\omega)}{2 \\hbar}})^{1/2} (\\hat{x} + {\\frac {\\hbar}{m \\omega}} {\\frac {\\partial} {\\partial x}}) \\langle x | 0 \\rangle$.\r\n$\\psi_0(x) = \\langle x | 0 \\rangle$ satisfies $({\\frac {\\partial} {\\partial x}} +{\\frac {m \\omega} {\\hbar}}) \\psi_0(x) =0$ and\r\n$\\psi_0(x)= N e^{{\\frac {m \\omega} {2 \\hbar}} x^2}$ while \r\n$\\psi_1(x)= \\langle x | 1 \\rangle= ({\\frac {2m \\omega} {\\hbar}})^{1/2} x \\psi_0(x)$.\r\n\\\\\r\n\\\\\r\n{\\bf Multiple particles:}  For a two particle SHO,\r\n$H= H_1 + H_2$ with $H_i= {\\frac  {\\hat{p}_i^2}{2m}} + {\\frac 1 2} m \\omega^2 \\hat{x}_i^2$ with\r\n$H_i |n \\rangle_i = \\hbar \\omega (n + {\\frac 1 2}) |n\\rangle_i$ and \r\n$ |n_1, n_2\\rangle= |n_1\\rangle  \\otimes |n_2\\rangle $ and $H |n_1, n_2 \\rangle= \\hbar \\omega (n_1 + n_2 + 1) |n_1 , n_2 \\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Identical particles:}\r\n$U x_i U^{-1}= x_{\\sigma(i)}$, $U p_i U^{-1}= p_{\\sigma(i)}$ and $U H U^{-1}= H$ with $H= \\sum_i H_i$ and\r\n$H_i | \\psi_r \\rangle = E_r | \\psi_r \\rangle$.  A basis for ${\\cal H}_1 \\otimes {\\cal H}_2$ is\r\n$ |\\psi_r\\rangle_1 |\\psi_s\\rangle_2; {\\frac 1 {\\sqrt 2}} ( |\\psi_r\\rangle_1 |\\psi_s\\rangle_2 + |\\psi_s\\rangle_1 |\\psi_r\\rangle_2), r \\neq s $.\r\n\\\\\r\n\\\\\r\n{\\bf Spinless Bosons:}\r\nFor $N$ spinless bosons, $H= \\sum_i H_i$.  The symmetric basis is\r\n${\\frac 1 {\\sqrt {N!}}}  \\sum_{\\sigma} ( | \\psi_{\\sigma(1)} \\rangle_1 | \\psi_{\\sigma(2)} \\rangle_2 \\ldots | \\psi_{\\sigma(N)} \\rangle_N)$.  \r\nNote that spinless bosons are fully characterized by $x, p$.\r\n\\\\\r\n\\\\\r\n{\\bf Spin ${\\frac 1 2}$ Fermions:}\r\nState includes spin $| s \\rangle$, the full state is $|x\\rangle | s \\rangle$ with\r\n$\\psi(x,s)= | x, s \\rangle$ and $\\psi_s(x)= \\langle x, s | \\psi \\rangle$.  The basis for two particles is\r\n$\\chi_A(s_1 , s_2)= {\\frac 1 {\\sqrt {2}}} ( \\chi_{1/2}(s_1) \\chi_{-1/2}(s_2) - \\chi_{-1/2}(s_1) \\chi_{1/2}(s_2))$. \r\n\\\\\r\n\\\\\r\n{\\bf Bell's argument restated:}\r\nConsider two spin-${\\frac 1 2}$ electrons.\r\n$|\\uparrow\\rangle$ and $|\\downarrow\\rangle$ are eigenvectors of $S_3= {\\frac 1 2} \\hbar \\sigma_3$.\r\n$\\chi_{\\uparrow}=\r\n\\left(\r\n\\begin{array}{c}\r\n1\\\\\r\n0\\\\\r\n\\end{array}\r\n\\right)$, \r\n$\\chi_{\\downarrow}=\r\n\\left(\r\n\\begin{array}{c}\r\n0\\\\\r\n1\\\\\r\n\\end{array}\r\n\\right)$.\r\n$\\sigma \\cdot n=\r\n\\left(\r\n\\begin{array}{cc}\r\ncos(\\theta) & sin(\\theta)\\\\\r\nsin(\\theta) & -cos(\\theta)\\\\\r\n\\end{array}\\right)$ and $n= ( sin(\\theta), 0, cos(\\theta))$.\r\n$ \\chi_{\\uparrow;n}= cos({\\frac {\\theta} 2}) \\chi_{\\uparrow}+\r\nsin({\\frac {\\theta} 2}) \\chi_{\\downarrow} $ and\r\n$ \\chi_{\\downarrow;n}= -sin({\\frac {\\theta} 2}) \\chi_{\\uparrow}+\r\ncos({\\frac {\\theta} 2}) \\chi_{\\downarrow}$, \r\nset $| \\Phi \\rangle= {\\frac 1 {\\sqrt 2}} [ \r\n| \\uparrow \\rangle_1 | \\downarrow \\rangle_2 + | \\downarrow \\rangle_1 | \\uparrow \\rangle_2 ]$.  If there are\r\n``hidden variables,'' we'd expect a distribution $0 \\leq\r\np(S_z^{(1)}, S_n^{(1)}, S_m^{(1)}, S_z^{(2)}, S_n^{(2)}, S_m^{(2)}) \\leq 1$.  Define\r\n$p_{bc}(b,c)= \\sum_a p(a,b,c)$, $p_{ac}(a,c)= \\sum_b p(a,b,c)$, $p_{ab}(a,b)= \\sum_c p(a,b,c)$.\r\n$ p_{bc}(1, -1) \\leq p_{ab}(1, 1) + p_{ac}(-1, -1) $.  Applying this to two electrons,\r\n$\r\nP( S_n^{(1)}=1, S_m^{(2)}=1) \\leq\r\nP( S_z^{(1)}=1, S_n^{(2)}=-1)+\r\nP( S_z^{(1)}=-1, S_m^{(2)}=1)\r\n$.\r\n$P( S_n^{(1)}=1, S_n^{(2)}=-1) = cos^2({\\frac {\\theta} 2})$ and\r\n$ P( S_z^{(1)}=1, S_m^{(2)}=-1)= cos^2({\\frac {\\phi+\\theta} 2}) $ which is not generally true.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nThe \\emph{Compton wavelength} is  $\\Delta x \\geq {\\frac {\\hbar} {mc}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Lie Groups:}\r\n$R(\\theta, \\hat{z})=\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos(\\theta) & sin(\\theta) & 0\\\\\r\n-sin(\\theta) & cos(\\theta) & 0\\\\\r\n0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right).$\r\n$v'= R(\\theta, \\hat{z})$.  $L_z= {\\frac 1 i} {\\frac {\\partial R(\\theta, \\hat{z})} {\\partial \\theta}}_{|\\theta= 0}$.\r\n$R(\\theta, \\hat{z})= 1 + \\delta \\theta L_z$.  $SO(3)$ is generated by \r\n$\\langle L_x , L_y , L_z \\rangle$, $R(\\theta, \\hat{z})=\r\nlim_{N \\rightarrow \\infty} R({\\frac {\\theta} {N}}, \\hat{z})$.  $[L_i, L_j]= i \\epsilon_{ijk} L_k$.\r\n$J^2 | j, m\\rangle= j(j+1) |j, m \\rangle$, $J_z |j,m\\rangle= m |j, m \\rangle$.  $SU(2)$ acts on spinors.\r\n$A= A(\\theta, \\hat{n})= exp(i {\\frac {\\theta} 2} \\sigma \\cdot n)= 1+ i \\theta J \\cdot n$.  $J \\cdot n=\r\n{\\frac 1 i} {\\frac {\\partial A(\\theta, \\hat{n})} {\\partial \\theta}}_{| \\theta=0}= {\\frac {\\sigma} 2} \\cdot n$.\r\n$\\langle {\\frac {\\sigma_x} 2}, {\\frac {\\sigma_y} 2}, {\\frac {\\sigma_z} 2}, \\rangle$ is a basis for $SU(2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Representations of symmetry groups:}  \r\nLet $G$ be the symmetry group of a physical system with Hamiltonian $H$, if $g \\in G$ then\r\n$[g,H]=0$ (Note: it is sufficient if this holds on generators.).  \r\n$\\Phi: G \\rightarrow V_n(F)$ is a representation of the system.  Given a Hermitian representation,\r\n$\\Phi(g)$ of $G$, $\\Phi'(g)= exp(i \\Phi(g))$ is a unitary representation.  These are called $D$ functions.  \r\n$\\langle j,m' | U(\\phi, \\theta, \\chi ) | j, m \\rangle= D^{(j)}_{m', m} (\\phi, \\theta, \\chi)=\r\ne^{im \\phi} d^{(j)}_{m', m}(\\theta) e^{-i m \\chi}$.  $J^2$ acts on a $2j+1$ dimensional Hilbert space.\r\n$J_{\\pm}= J_x \\pm i J_y$ and $J_{\\pm} | j, m \\rangle=\r\n{\\sqrt {j(j+1)-m(m \\pm 1)}} | j, m \\pm 1 \\rangle$.  Spin\r\nis a representation of $SU(2)$.  There is a homomorphism of $SU(2) \\rightarrow SO(3)$ with kernel $\\{ \\pm 1\\}$\r\ngiven by $A(\\theta, \\hat{n}) \\mapsto R(\\theta, \\hat{n})$ or\r\n$\r\n\\left(\r\n\\begin{array}{cc}\r\ne^{-i \\alpha/2} & 0\\\\\r\n0 & e^{i \\alpha/2}\\\\\r\n\\end{array}\r\n\\right) \r\n\\mapsto\r\n\\left(\r\n\\begin{array}{ccc}\r\ncos(\\alpha) & sin(\\alpha) & 0\\\\\r\n-sin(\\alpha) & cos(\\alpha) & 0\\\\\r\n0 & 0 & 1\\\\\r\n\\end{array}\r\n\\right)$.  \r\nThe Klein Gordon equation is invariant under the Lorentz group.  The \\emph{Poincare group} is the Lorentz group plus\r\ntranslations $T(x)= \\Lambda x+a$.  $|\\Lambda_0^0| \\ge 1$.\r\n\\begin{center}\r\n\\begin{tabular} {|c||c|c|}\r\n\\hline\r\nSubgroup & $det$ & $\\Lambda_0^0$\\\\\r\n\\hline\r\n$L_+^{\\uparrow}$ & $1$ & $\\geq 1$\\\\\r\n$L_+^{\\downarrow}$ & $1$ & $\\leq -1$\\\\\r\n$L_-^{\\uparrow}$ & $-1$ & $\\geq 1$\\\\\r\n$L_-^{\\downarrow}$ & $-1$ & $\\leq -1$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nTwo fundamental transformations are ``rotations'' and ``boosts''(time change).  \r\nRotations, $(J_1, J_2, J_3)$: $\\Lambda_R(\\theta, \\hat{z})= exp(i \\theta)$. \r\nBoosts, $(K_1, K_2, K_3)$: $\\Lambda_B(\\theta, \\hat{z})= exp(\\theta)$. \r\n$[J^i, J^j]= i \\epsilon^{ijk} J^k$,\r\n$[J^i, K^j]= i \\epsilon^{ijk} K^k$,\r\n$[K^i, K^j]= i \\epsilon^{ijk} J^k$.\r\n$M= exp({\\frac i 2} \\theta \\cdot \\sigma) exp(\\pm {\\frac 1 2} \\phi \\cdot \\sigma)$, \r\n$\\hat{\\phi}= \\phi \\cdot n$,\r\n$\\hat{\\sigma}= \\sigma \\cdot n$.  \r\nType I representation ($M$): $J= {\\frac {\\sigma} 2}$, $K= -i {\\frac {\\sigma} 2}$.\r\nType II representation ($\\overline{M}$): $J= {\\frac {\\sigma} 2}$, $K= -i {\\frac {\\sigma} 2}$.\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n\\xi\\\\\r\n\\eta\\\\\r\n\\end{array}\r\n\\right)\r\n\\rightarrow\r\n\\left(\r\n\\begin{array}{cc}\r\nM(\\Lambda) & 0\\\\\r\n0 & {\\overline M}(\\Lambda)\\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{cc}\r\n\\xi\\\\\r\n\\eta\\\\\r\n\\end{array}\r\n\\right)\r\n$, ${\\overline M}(\\Lambda)= \\epsilon M^* \\epsilon^{-1}, \\epsilon= i \\sigma^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Symmetries and fields:}\r\n$(t,x) \\rightarrow (t, -x)$ is the \\emph{parity} symmetry.\r\n$\\phi \\rightarrow {\\overline \\phi}^T$ is the \\emph{charge conservation} symmetry.\r\nSpin $0$ scalar fields have Lagrangian ${\\cal L}= {\\frac 1 2} \\partial_{\\mu} \\phi \\partial_{\\nu} \\phi - {\\frac 1 2} M^2 \\phi^2$.\r\nSpin ${\\frac 1 2}$ Dirac fields have Lagrangian ${\\cal L}= {\\overline \\phi}(i\\partial_{\\mu} \\partial_{\\nu} - M) \\phi$.\r\nSpin $1$ vector fields have Lagrangian \r\n${\\cal L}= -{\\frac 1 4} F_{\\mu, \\nu} F^{\\mu, \\nu} + {\\frac 1 2} m^2 V_{\\mu} V^{\\mu}=\r\n{\\frac {\\lambda} 2} (\\partial_{mu} V^{\\mu})^2$.  The \\emph{Poisson Bracket} \r\nis $[A, B]_P= {\\frac {dA} {dq}} {\\frac {dB} {dp}} - {\\frac {dA} {dp}} {\\frac {dB} {dq}}$.\r\n${\\frac {dO}{dt}}= [O, H]_P$ and\r\n${\\frac {dO}{dq}}= [O, p]_P$.\r\n\\\\\r\n\\\\\r\n{\\bf Summary:}  \r\n\\\\\r\n(1) Spin $0$ boson, Klein Gordon equation.\r\n${\\cal L}= {\\frac 1 2} (\\dot{\\phi}_{\\alpha} \\dot{\\phi}_{\\alpha} - \\mu^2 \\phi^2)$,\r\n$\\pi(x)= {\\frac {\\partial {\\cal L}} {\\partial {\\dot{\\phi}}}}$.\r\n$[\\phi, \\phi^+]= i \\hbar c^2 \\delta(x-x')$.\r\n$\\phi^+= \\sum_k ({\\frac {\\hbar c^2}{2 V \\omega_k}})^{1/2} a+(k) e^{-ikx/\\hbar}$.\r\n$H= \\sum_k \\hbar \\omega_k (a^{\\dagger} a(k) + {\\frac 1 2})$.\r\n$P= \\sum_k \\hbar k (a^{\\dagger} a(k) + {\\frac 1 2})$.\r\nPropagator: \r\n$[\\phi^+, \\phi]= i \\hbar c \\Delta(x-y)$\r\n$\\Delta(x)= {\\frac {i c}{(2 \\pi)^3}} \\int d^4 k \\thinspace \\delta(k^2-\\mu^2) \\epsilon(k) e^{-ikx}$.\r\n\\\\\r\n(2)\r\nSpin $1/2$ fermion, Dirac equation.\r\n${\\cal L}= c {\\overline {\\phi}}[c \\alpha \\cdot (i \\hbar \\nabla) + \\beta m c^2]\\phi$,\r\n$\\pi(x)= {\\frac {\\partial {\\cal L}} {\\partial {\\dot{\\phi}}}}$.\r\n$\\{ a_r, a_s^{\\dagger} \\}= \\delta_{rs}$, $\\{ a_r, a_s \\}= 0$.\r\n$H= c \\int d^3x {\\overline {\\phi}} \r\n[-i \\hbar c \\gamma^j {\\frac{\\partial}{\\partial x^j}}+mc^2]\r\n\\phi$.\r\n$P= -i \\hbar \\int  (\\phi^{\\dagger} \\nabla \\phi(k) $.\r\nPropagator: \r\n$S_F(x)= {\\frac {- \\hbar}{(2 \\pi \\hbar)^4}} \\int d^4 p \\;\r\ne^{-ip \\cdot x/ \\hbar} {\\frac {\\gamma^{\\mu} p_{\\mu} + mc} {p^2-m^2c^2+1\\epsilon}}$.\r\n\\\\\r\n(3)\r\nSpin $1$ photon, Maxwell's equation.\r\n${\\cal L}= -{\\frac 1 4} (F_{\\mu \\nu} F^{\\mu \\nu} - {\\frac 1 c} s_{\\mu}(x) A^{\\mu}(x))$.\r\n$[ A^{\\mu}(x), A^{\\mu}(x')]= i \\hbar x D^{\\mu \\nu}(x-x')$, \r\n$H= \\sum_{k, r} d^3 x \\thinspace \\hbar \\omega_k \\eta_r a_r^{\\dagger}(k) a_r(k)$.\r\n\\section{More on Dirac and QED}\r\n{\\bf The equations:}  \r\nSpin $0$ particles are characterized by Klein-Gordon.\r\nSpin ${\\frac 1 2}$ particles are characterized by Dirac.\r\nSpin $1$ particles are characterized by Proca.\r\n\\\\\r\n\\\\\r\n{\\bf Dirac:} $(i \\hbar \\gamma^{\\mu} {\\partial}_{\\mu} - mc= 0)$.  The time\r\nindependent solution is \r\n$\\psi(x) = a e^{- i k \\cdot x} u(k)$ for particles and \r\n$\\psi(x) = a e^{i k \\cdot x} u(k)$ for antiparticles.\r\n$u u^{\\dagger} = {\\frac {2E} {c}}$.  $N= {\\sqrt {\\frac \r\n{E+mc^2} {2}}}$. \r\n$\\gamma^0= \r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0 & -1\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\gamma^i= \r\n\\left(\r\n\\begin{array}{cc}\r\n0 & \\sigma^i\\\\\r\n-\\sigma^i & 0\\\\\r\n\\end{array}\r\n\\right)$.\r\n$\\psi=\r\n\\left(\r\n\\begin{array}{c}\r\nu^{(1)}\\\\\r\nu^{(2)}\\\\\r\nv^{(1)}\\\\\r\nv^{(2)}\\\\\r\n\\end{array}\r\n\\right)$.\r\n$u^{(1)}= N\r\n\\left(\r\n\\begin{array}{c}\r\n1 \\\\\r\n0 \\\\\r\n{\\frac {c p_z} {E+mc^2}} \\\\\r\n{\\frac {c (p_x + i p_y)} {E+mc^2}} \\\\\r\n\\end{array}\r\n\\right)$.\r\n$u^{(2)}= N\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n1 \\\\\r\n{\\frac {c (p_x + i p_y)} {E+mc^2}} \\\\\r\n{\\frac {c p_z} {E+mc^2}} \\\\\r\n\\end{array}\r\n\\right)$.\r\n$v^{(1)}= N\r\n\\left(\r\n\\begin{array}{c}\r\n{\\frac {c (p_x - i p_y)} {E+mc^2}} \\\\\r\n{\\frac {-c p_z} {E+mc^2}} \\\\\r\n0 \\\\\r\n1 \\\\\r\n\\end{array}\r\n\\right)$.\r\n$v^{(2)}= N\r\n\\left(\r\n\\begin{array}{c}\r\n{\\frac {-c p_z} {E+mc^2}} \\\\\r\n{\\frac {c (p_x - i p_y)} {E+mc^2}} \\\\\r\n1 \\\\\r\n0 \\\\\r\n\\end{array}\r\n\\right)$.\r\nFor photon, $A_{\\mu}= ae^{i p \\cdot x / \\hbar} \\epsilon^{\\mu}(p)$, $\\epsilon^{\\mu}$ is the polarization vector.\r\n$\\epsilon^0 = 0$ so $\\epsilon \\cdot p = 0$,\r\n$\\epsilon^1 = (1, 0, 0)$,\r\n$\\epsilon^2 = (0, 1, 0)$.\r\n\\begin{center}\r\n\\begin{tabular} {|c|c|c|}\r\n\\hline\r\nSpinor component & Particle & Spin\\\\\r\n\\hline\r\n$u^{(1)}$ & $e^-$ & up\\\\\r\n$u^{(2)}$ & $e^-$ & down\\\\\r\n$v^{(1)}$ & $e^+$ & up\\\\\r\n$v^{(2)}$ & $e^+$ & down\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n$S= {\\frac {\\hbar} 2}\r\n\\left(\r\n\\begin{array}{cc}\r\n\\sigma & 0 \\\\\r\n0 & \\sigma\\\\\r\n\\end{array}\r\n\\right)$.\r\n\\\\\r\n\\\\\r\n{\\bf The vacuum:}  The \\emph{Casimir effect} is the force between two plates seperated \r\nby $d$ due to vacuum fluctuation of the EM field.   In QFT,\r\n$P= \\int {\\frac {d^3p} {(2 \\pi)^3}} p a_p^{\\dagger} a_p$.\r\nWe can recover the position operator by \r\n$X= \\int d^3 x (x \\phi^{\\dagger}(x)\\phi(x)$ giving $X |x\\rangle= x |x\\rangle$.\r\n\\\\\r\n\\\\\r\n{\\bf Summary:}\r\n\\begin{center}\r\n\\begin{tabular} {|c|c|c|c|}\r\n\\hline\r\nCharacteristic & Electrons & Positrons & Photons\\\\\r\n\\hline\r\nKet & \r\n$ae^{-i p \\cdot x / \\hbar} u^{(s)}(p)$ & $ae^{i p \\cdot x / \\hbar} v^{(s)}(p)$ & $A_{\\mu}= a e^{-i \\epsilon \\cdot x/ \\hbar} \\epsilon_{\\mu}^{(s)}$\\\\\r\nEOS & \r\n$(\\gamma^{\\mu} p_{\\mu} -mc)u=0$ & $(\\gamma^{\\mu} p_{\\mu} +mc)v=0$ &  $\\Box^2 A^{\\mu}= 0$\\\\\r\nAdjoint & ${\\overline u}(\\gamma^{\\mu} p_{\\mu} -mc)=0$ & ${\\overline v}(\\gamma^{\\mu} p_{\\mu} +mc)=0$ & - \\\\\r\nConstraints &\r\n${\\overline u}^{(1)} \\cdot u^{(2)} = 0$, ${\\overline u} u = 2mc$ &\r\n${\\overline v}^{(1)} \\cdot v^{(2)} = 0$ , ${\\overline v} v = -2mc$ & $p^{\\mu} \\epsilon_{\\mu}= 0$\\\\\r\nBasis & $\\sum_s {\\overline u}^{(s)} \\cdot u^{(s)} = (\\gamma^{\\mu} p_{\\mu} +mc)$ &\r\n$\\sum_s {\\overline v}^{(s)} \\cdot v^{(s)} = (\\gamma^{\\mu} p_{\\mu} -mc)$ &\r\n$\\sum_s \\epsilon_i^{(s)} (\\epsilon_j^{(s)})^*= \\delta_{ij} - \\hat{p}_i \\hat{p}_j $\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Feynman rules for QED:}  The rules for QED.\r\nTo calculate ${\\cal M}$: (1) To eac external line, draw directed segment labeled by momentum,(2) for electron into (out of)\r\nvertex use $u$ (${\\overline u}$) switch for positron, (3) use vertex coupling $ig_e \\gamma^{\\mu}$, $g_e= e {\\sqrt {\\frac {4 \\pi} {\\hbar c}}}$,\r\n(4) Use propagators ${\\frac {i(\\gamma^{\\mu} q_{\\mu} + mc)} {q^2-m^2 c^2}}$ for $e^+, e^-$ and ${\\frac {ig_{\\mu, \\nu}} {q^2}}$ for\r\n$\\gamma$, (5) apply $\\delta$ function $\\delta^{(4)}(k_1+k_2+k_3)$ (inwards) at each vertex, (6) integrate over internal momentum\r\n${\\frac {d^4 q} {(2 \\pi)^4}}$, (7) cancel the $\\delta$'s replacing them wiht $i$, (8) do anti-symmetrization in diagrams interchanging only\r\ndirection.  Example: \\emph{electron-electron} scattering ${\\cal M}= \r\n- {\\frac {g_e^2}{(p_1-p_3)^2}} [{\\overline u}(3) \\gamma^{\\mu}u(1)] [{\\overline u}(3) \\gamma_{\\mu} u(2)]\r\n+ {\\frac {g_e^2}{(p_1-p_4)^2}} [{\\overline u}(4) \\gamma^{\\mu}u(1)] [{\\overline u}(3) \\gamma_{\\mu} u(2)] $.\r\n\\chapter{Quantum Computing}\r\n\\section{Basics}\r\n${\\cal G}= \\langle CNOT, X,Y,Z,H,T \\rangle$ can be efficiently simulated on a probabalistic\r\ncomputer if there is little entanglement.  This is the theorem of \\emph{Gottesman-Knill}.\r\n\\\\\r\n\\\\\r\n$CNOT:\r\n{\\frac {(| 0 \\rangle + |1 \\rangle)} {\\sqrt 2}}\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n\\mapsto\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$.  Note that\r\n${\\frac {(| 0 \\rangle + |1 \\rangle)} {\\sqrt 2}}$ and\r\n${\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}$ are eigenvectors of $CNOT$.\r\n$CNOT: |b \\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = (-1)^b |b \\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$\r\nand\r\n$CNOT: \r\n(\\alpha_0 |0 \\rangle +\r\n(\\alpha_1 |1 \\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = \r\n(\\alpha_0 |)\\rangle-\\alpha_1 |1\\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$.\r\n\\\\\r\n\\\\\r\nLet \r\n$U_f: |x\\rangle \r\n|y\\rangle \\mapsto\r\n|x\\rangle |y \\oplus f(x)\\rangle $.\r\n$U_f: |x\\rangle {\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = \r\n|x\\rangle=\r\n{\\frac {(| 0  \\oplus f(x)\\rangle - |1 \\oplus f(x) \\rangle)} {\\sqrt 2}} = \r\n(-1)^{f(x)}\r\n|x\\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} $ and\r\n$U_f: \r\n(\\alpha_0 |0 \\rangle+\r\n(\\alpha_1 |1 \\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} \\mapsto\r\n((-1)^{f(0)}\\alpha_0 |0\\rangle-(-1)^{f(1)}\\alpha_1 |1\\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$. $H$ decodes information encoded in the phase.\r\n\\\\\r\n\\\\\r\n{\\bf Proof of no-cloning theorem:}  Suppose such a unitary transforamtion exists.\r\n$U(|\\psi\\rangle |0\\rangle)= |\\psi\\rangle |\\psi \\rangle$ and\r\n$U(|\\phi\\rangle |0\\rangle)= |\\phi\\rangle |\\phi \\rangle$. \r\nOn one hand,\r\n$U( a | \\phi \\rangle + b | \\psi \\rangle )= a | \\phi \\rangle | \\phi \\rangle + b | \\psi \\rangle \\psi \\rangle )$.\r\nOn the other hand,\r\n$U( a | \\phi \\rangle + b | \\psi \\rangle |0\\rangle )= (a | \\phi \\rangle + b | \\psi \\rangle )\r\n(a | \\phi \\rangle + b | \\psi \\rangle )$.  This is a contradiction.  There is no ``approximate cloning'' either.\r\n\\\\\r\n\\\\\r\n{\\bf Phase Estimation Problem:}  \r\nGiven \r\n$|\\psi\\rangle= {\\frac 1 {{\\sqrt {2^n}}}} \\sum_{|y\\rangle} e^{2 \\pi i \\omega y} |y\\rangle$.\r\n($\\omega= \\{0,1\\}$.\r\n$QFT=\r\n(|0>+e^{2 \\pi i 2^{n-1} \\omega}|1\\rangle) \\otimes\r\n(|0>+e^{2 \\pi i 2^{n-2} \\omega}|1\\rangle) \\otimes \\ldots A.$\r\n$R_n=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0 & e^{2 \\pi i/ 2^n}\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n\\\\\r\n\\\\\r\n{\\bf Hidden subgroup problem:}  Let $f: G \\rightarrow X$,\r\n$\\exists S<G$ with $f(x)=f(y)$ iff $x+S=y+S$.\r\n\\\\\r\n\\\\\r\n\\begin{quote}\r\n\\emph{Deutsch:}\r\n$G= {\\mathbb Z}_2$, $X= \\{ 0, 1 \\}$.  \r\n$S= \\{ 0 \\}$ if $f$ is balenced.\r\n$S= \\{ 0,1 \\}$ if $f$ is constant.\r\n\\\\\r\n\\\\\r\n\\emph{Order Finding:}\r\n$G= {\\mathbb Z}$, $X= H<G$, $r=|a|, a \\in H$.\r\n$S= r{\\mathbb Z}$ so $S$ gets $r$.\r\n\\\\\r\n\\\\\r\n\\emph{Discrete Log:}\r\n$G= {\\mathbb Z}_r \\times {\\mathbb Z}_r$, $X= H<G$, $a:a^r=1$,\r\n$b=a^k$, $f(x_1, x_2) =a^{x_1} b^{x_2}$.\r\n$f(x_1, x_2)= f(y_1 , y_2)$ iff\r\n$a^{x_1-y_1}b^{x_2-y_2}=1$ iff\r\n$\\langle z_1-y_1, x_2-y_2\\rangle= (t,-tk), t= 0,1, \\ldots, r-1$.\r\n$S=\\langle 1, -k \\rangle$, $k= log(b)$.\r\n\\\\\r\n\\\\\r\n\\emph{Hidden Linear function:}\r\n$G= {\\mathbb Z} \\times {\\mathbb Z}$, $g \\in S_n$.\r\n$h:\r\n{\\mathbb Z} \\times {\\mathbb Z}\r\n\\rightarrow\r\n{\\mathbb Z}_n\r\n$ by $h(x,y)= x+ya \\jmod{n}$.  $f= g \\circ h$,\r\n$G= {\\mathbb Z}$, $X= \\{ 0, 1 \\}$.  \r\n$S= \\langle -a, r \\rangle$.\r\n\\\\\r\n\\\\\r\n\\emph{Abelian Stabilizer:}\r\n$G$ acts on $X$, $f_x: g \\rightarrow X$ by $f_x(g)=x^g$.  $S= G_x$.\r\n\\\\\r\n\\\\\r\n\\emph{Graph Isomorphism:}\r\n$G= S_n$ and ${\\cal G}_n$ is a graph on $n$ vertices.  For $\\sigma \\in G$,\r\n$f_{\\cal G}(\\sigma({\\cal G}))$.  The hidden subgroup is the automorphisms of ${\\cal G}_n$.\r\n\\end{quote}\r\n${\\cal G}= \\langle CNOT, X,Y,Z,H,T \\rangle$ can be efficiently simulated on a probabalistic\r\ncomputer if there is little entanglement.  This is the theorem of \\emph{Gottesman-Knill}.\r\n\\\\\r\n\\\\\r\n$CNOT:\r\n{\\frac {(| 0 \\rangle + |1 \\rangle)} {\\sqrt 2}}\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n\\mapsto\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$.  Note that\r\n${\\frac {(| 0 \\rangle + |1 \\rangle)} {\\sqrt 2}}$ and\r\n${\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}$ are eigenvectors of $CNOT$.\r\n$CNOT: |b \\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = (-1)^b |b \\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$\r\nand\r\n$CNOT: \r\n(\\alpha_0 |0 \\rangle +\r\n(\\alpha_1 |1 \\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = \r\n(\\alpha_0 |)\\rangle-\\alpha_1 |1\\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$.\r\n\\\\\r\n\\\\\r\nLet \r\n$U_f: |x\\rangle \r\n|y\\rangle \\mapsto\r\n|x\\rangle |y \\oplus f(x)\\rangle $.\r\n$U_f: |x\\rangle {\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} = \r\n|x\\rangle=\r\n{\\frac {(| 0  \\oplus f(x)\\rangle - |1 \\oplus f(x) \\rangle)} {\\sqrt 2}} = \r\n(-1)^{f(x)}\r\n|x\\rangle\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} $ and\r\n$U_f: \r\n(\\alpha_0 |0 \\rangle+\r\n(\\alpha_1 |1 \\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}} \\mapsto\r\n((-1)^{f(0)}\\alpha_0 |0\\rangle-(-1)^{f(1)}\\alpha_1 |1\\rangle)\r\n{\\frac {(| 0 \\rangle - |1 \\rangle)} {\\sqrt 2}}\r\n$. $H$ decodes information encoded in the phase.\r\n", "meta": {"hexsha": "8b05baaad0fe1522abad9a03d55462381545c784", "size": 38785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/qc.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/qc.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/qc.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": 39.4156504065, "max_line_length": 148, "alphanum_fraction": 0.5578445275, "num_tokens": 16023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.621064160905652}}
{"text": "%!TEX root = ../../report.tex\n\n\\subsubsection{Fractals} % (fold)\n\\label{ssub:fractals}\n\n\nA fractal is defined in \\cite{Ebert2002} as ``a geometrically complex object, the complexity of which arises through the repetition of a given form over a range of scales''.\nThis concept is observed in some forms that exist in nature. Trees, mountains, coastlines and the network of neurons on a human cortex can be seen as examples of fractals. Natural shapes tend to be irregular and fragmented and exhibit a complexity incomparable to regular geometry \\cite{mandelbrot1984fractal}.\nFractals were proposed to be seen as a new form of symmetry \\cite{Ebert2002}, \\emph{Dilation Symmetry}, which is when an object is invariant over a change of scale. This invariance might be only qualitatively and not exact. For instance, a river network exhibit dilation symmetry if \\textit{zooming in} in some part looks the same as the whole image. As this example, many others show dilated symmetry such as clouds, tree branches and some vegetables as shown in Figure~\\ref{fig:NFractals}. \n\n\\begin{figure}\n        \\centering\n        %\\begin{subfigure}[b]{0.4\\textwidth}\n                \\includegraphics[width=0.45\\textwidth]{img/Theory/Fractals/Leaf.png}\n        %        \\label{fig:Fleaf}\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.4\\textwidth}\n                \\includegraphics[width=0.45\\textwidth]{img/Theory/Fractals/Fractal_Broccoli.jpg}\n        %        \\label{fig:Fbrocoli}\n        %\\end{subfigure}\n        \\caption{Fractals in Nature}\n        \\label{fig:NFractals}\n\\end{figure}\n\n\nThis idea was applied in maths and resulted in a new area in this science called fractal mathematics. The objective of this field is to describe very complex shapes with simple rules such as repeating a substitution pattern. \n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.7\\textwidth]{img/Theory/Fractals/Fractal1_1000.png}\n\t\\caption{Geometric Fractals}\n\t\\label{fig:GFractals}\n\\end{figure}\n\nIn Figure~\\ref{fig:GFractals} there are four examples of Geometric Fractals, with the first five iterations of each one. All of them are built by the substitution of a part of the image by another one. \n\nThe example of the second row is known as the Koch snowflake. In this example, at each iteration, all the line segments are replaced by four segments with 1/3 of the size of the original one with the two in the middle being placed in a angle forming a equilateral triangle with the original line that is removed.\n\nIt is clear that the detail that is presented in each iteration increases as the scale changes. There is the concept of \\emph{Fractal Dimension} that tries to measure this evolution, in which the detail in a pattern changes in comparison with the scale in which it is measured.\n\nAs stated before, the world is visually very complex, so when synthesizing worlds, ``\\emph{complexity} equals \\emph{work}''\\cite{Ebert2002}. This work can be done by the programmer/artist or by a computer. Fractals as being defined as a simple mathematical function, it is relatively easy to implement a procedure that model one fractal. \n\nThis technique is used to model many natural forms that present fractal properties. Mountains, for instance, are usually modeled using of fractals. Other natural forms that present fractal properties are trees, river systems, lightning or vascular systems in living beings.\n\n\n\n\n% subsection fractals (end)\n", "meta": {"hexsha": "09ec2eed995c15ac896735b1cadbbcf34d3795db", "size": 3579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Overview/1-Fractals.tex", "max_stars_repo_name": "arturalkaim/v2ProceduralGeneration", "max_stars_repo_head_hexsha": "496ecd2bf9885b6fa634cb958b696dad7a2166b7", "max_stars_repo_licenses": ["MIT"], "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/Overview/1-Fractals.tex", "max_issues_repo_name": "arturalkaim/v2ProceduralGeneration", "max_issues_repo_head_hexsha": "496ecd2bf9885b6fa634cb958b696dad7a2166b7", "max_issues_repo_licenses": ["MIT"], "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/Overview/1-Fractals.tex", "max_forks_repo_name": "arturalkaim/v2ProceduralGeneration", "max_forks_repo_head_hexsha": "496ecd2bf9885b6fa634cb958b696dad7a2166b7", "max_forks_repo_licenses": ["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.1764705882, "max_line_length": 492, "alphanum_fraction": 0.7560771165, "num_tokens": 888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.8840392725805822, "lm_q1q2_score": 0.621064160905652}}
{"text": "\\documentclass[modern]{aastex61}\n\n\\input{stylez}\n\\usepackage{graphicx}\n\n\\begin{document}%\\raggedbottom\\sloppy\\sloppypar\\frenchspacing\n\n\\setlength{\\abovedisplayskip}{1.5em}\n\\setlength{\\belowdisplayskip}{1.5em}\n\n\\title{%\nAnalytic Transit Light Curves for Stars with Polynomial Limb-Darkening\n}\n\n\n\\author[0000-0002-0802-9145]{Eric Agol}\\altaffiliation{Guggenheim Fellow}\n\\author[0000-0002-0296-3826]{Rodrigo Luger}\n\\affil{Department~of~Astronomy, University~of~Washington, Seattle, WA}\n\n\\keywords{methods: analytic --- techniques: photometric}\n\n\\begin{abstract}\n We derive analytic, closed-form solutions for the light curve of a planet\n transiting a star with a limb darkening profile which is a polynomial function\n up to arbitrary integer order.  We provide updated analytic expressions for the\n uniform and linear limb darkened cases, as well as new expressions\n for higher order integer powers of limb darkening.  The formulae are crafted to be numerically\n stable over the expected range of usage.  We additionally present formulae for\n the partial derivatives of instantaneous flux with respect to the radius ratio,\n impact parameter, and limb-darkening coefficients.  Our expressions are rapid to\n evaluate and can be used to accurately compute the first partial derivatives of\n transit light curves.\n\\end{abstract}\n\n% ------------------------------------------------------------------------------\n%\n\\section{Introduction}\n\\label{sec:intro}\n% ------------------------------------------------------------------------------\n\nThe precise measurement of the transits of an exoplanet offers a host of information\nabout the planet's properties.  To start with, the times of transit give\nthe planet's orbital ephemeris.  The depth of transit, corrected for stellar\nlimb-darkening, gives the planet's radius relative to that of the star.   The\nshape of the transit, especially the duration of ingress and egress relative to\nthe full transit duration, yields the orbital impact parameter of the planet.\nBeyond these basic properties, if the transit depth is seen to vary with wavelength,\nthe presence of spectral features may be used to constrain the chemical composition\nof the planet's atmosphere.  If the transit times are seen to vary, a dynamical\nmodel can constrain the masses of the planet companions (and vice versa).  If\nthe planet is seen in eclipse, its temperature, emission spectrum, and atmospheric\ncirculation pattern can be constrained.  When combined with radial velocity\nmeasurements, the bulk density of a planet can be inferred, yielding constraints\non its bulk composition.\n\nAnd yet, all of these inferences are predicated on the precise computation of models\nof the planetary transit.  Stars are non-uniform in brightness, with the general\ntrend of growing dimmer towards the limb, and so limb-darkening must be accounted\nfor to accurately infer the planetary parameters.  Indeed, fast and accurate computation\nof limb-darkened transit light curve models has enabled the detection and\ncharacterization of thousands of transiting exoplanets \\citep{MandelAgol2002}.\nThe most important ingredient to these models has been a description of the\nlimb-darkening model which is flexible enough and accurate enough to describe the\nemission from a stellar photosphere.  Linear and quadratic limb-darkening laws\nwere sufficient for lower-precision measurements; however, the measurement of\ntransit light curves has steadily improved in precision.  Higher order terms or non-linear laws\nhave become necessary to describe higher precision measurements \\citep{Claret2000,\nGimenez2006}, which tend to involve more computational burden.\n\nIn addition to computing transit light curves, the derivatives of these light\ncurves with respect to the model parameters are also beneficial for accurate\ncharacterization of exoplanets.   The derivatives enable fast and stable\noptimization of the transit light curve parameters, which is critical for\nobtaining initial estimates for a markov chain Monte Carlo simulation (MCMC),\nfor looking for multi-modal solutions, for initializing the multi-nest\nalgorithm, or for computing the Fisher information matrix.\nIn some cases, MCMC can be slow to converge, and derivatives can accelerate\nconvergence by adding an artificial momentum term to the log likelihood,\nand then allowing the sampler to follow contours of constant ``energy.\"\nThis so-called ``hybrid\" or ``Hamiltonian\" MCMC approach holds great promise,\nbut its application has been hampered by the lack of models with derivatives,\nas derivatives are in general more difficult to compute.\n\nFinally, the analytic computation of transit light curves with quadratic\nlimb-darkening is limited by numerical round-off error for limiting\nvalues near some special cases.  In\nparticular, when the radius equals the impact-parameter, which corresponds to\nthe edge of the planet crossing the center of the star, the computation of the\nelliptic integrals becomes unstable.  At the second and third points of\ncontact, when the radius of the planet plus the impact parameter equals\nthe radius of the star, the elliptic integrals diverge logarithmically.  In the\nlimit that the impact parameter approaches zero, the equations can also\ndiverge.  All of these special cases are in principle encountered rarely,\nbut in practice with thousand of planets with tens to thousands of\ntransits each, along with hundreds to hundreds of thousands of light\ncurves with time sub-sampled for each exposure, these rare cases can\nbe encountered with some frequency.\n\nBased on these considerations, the primary goals of the current paper are\nthreefold:\n\\begin{enumerate}\n\\item To extend the analytic quadratic limb-darkened transit model to higher order.\n\\item To compute the derivatives of the model analytically.\n\\item To stabilize the analytic light curve computation (and its derivatives)\nin all limits near special cases.\n\\end{enumerate}\nSecondary goals include modeling eclipsing binaries, for which the same\nconsiderations apply, and integrating the light curve model, and its\nderivatives, quickly and accurately over time to account for finite\nexposure times.\n\nSome progress has been made already towards these goals.  To describe this\nprogress, we pause first to introduce some notation.  Limb-darkening models are\nparameterized with the cosine of the angle measured from the sub-stellar point,\n$\\upmu = \\cos{\\theta}$, where $\\theta$ is the polar angle on the photosphere,\nwith $\\theta=0$ at the center of the observed stellar disk, and $\\theta=\\pi/2$\nat the limb.  In terms of $b$, the normalized radius projected onto the sky,\nthis parameter is given by $\\upmu = \\cos{\\theta} =\\sqrt{1-b^2}$, where\n$0\\le b \\le 1$ within the stellar disk.  We also introduce the radius ratio,\n$r$, which is the radius of the occultor divided by the radius of the source.\nAs much as possible we will follow the notation of the \\starry package\nintroduced by Luger et al. (2018).\n\nUniform limb-darkening scales as $\\upmu^0$ and linear as $\\upmu^1$;\nthese are the two most important cases which can be integrated analytically,\nwhich we describe in detail below in sections \\ref{sec:uniform} and\n\\ref{sec:reparam}.  We show that higher order powers of $\\upmu^n$ with integer\n$n$ can be integrated analytically when expressed as recursion relations with\nthese first two cases.  Linear combinations of these laws can be constructed,\nwith various parameterizations, to describe stellar limb-darkening more precisely.\n\nThe first goal, of modelling higher-order limb-darkening, was accomplished\nby \\citet{Gimenez2006}, who derived transit light curves for a limb-darkening\nfunction\n\\begin{equation}\nI(\\upmu) = I(1) \\left[1-\\sum_{n=1}^N a_n (1-\\upmu^n) \\right],\n\\end{equation}\nwhere $a_n$ is a limb-darkening coefficient.  \\cite{Gimenez2006}\nfound an infinite series expansion for computing the limb-darkened light curve\nfor each $a_n$ term.  Here we present closed-form expressions for these terms\nwhich can be easily computed with recursion relations, although for purposes\nof numerical stability we need to revert to series solutions in some limits.\n\nThe second goal, of computing dervatives of the light curve with respect to\nthe model parameters, was accomplished by \\cite{Pal2008} for the quadratic\nlimb-darkening case.  He derived the partial derivatives of the quadratic\nlimb-darkening model with respect to $b$, $r$, and the two quadratic\nlimb-darkening coefficients.  In this work, we give modified expressions\nfor the quadratic limb-darkened flux and its derivatives which are\nmore numerically stable, as well as extend the computation of derivatives\nto higher order limb-darkening.\n\nThe third goal, of numerical stability, has yet to be addressed in the literature.\nAlthough some numerical approaches are numerically stable, such as \\cite{Gimenez2006}\nand \\cite{Kreidberg2015}, these approaches tend to be slower, they have precisions\nwhich depend upon the tolerance of the computation, and, in addition, they do not\nyield derivatives of the light curves.\n\nA disadvantage of our approach is that it requires linear powers of the limb-darkening\nexpansion.  \\citet{Claret2000} has shown that a non-linear limb-darkening law,\nwith half-integer powers of $\\upmu$, gives an accurate description of stellar\nlimb-darkening models.  More recently, the power-law model, $I(\\upmu) = 1-\nc_\\alpha(1-\\upmu^\\alpha)$ \\citep{Hestroffer1997} was shown to be an accurate\nlimb-darkening law despite only using two parameters \\citep{Maxted2018,\nMorello2017}.  We were unable to find an analytic solution for these limb-darkening\nlaws, but we will compare with these models below in \\S \\ref{sec:comparison}.\n\nWe turn now towards presenting formulae for more accurate limb-darkening transit,\noccultation, and eclipse models, starting with the simplest case:  a source\nof uniform surface brightness.\n\n\n% ==============================================================================\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n%\n\n\\section{Uniform brightness}\\label{sec:uniform}\n\nThe transit light curve of a uniformly bright star amounts to computing the\narea of overlap of two disks \\citep{MandelAgol2002}.  This has a well-known\nanalytic solution \\citep[e.g.][]{Weisstein2018};  however, we find that the\nstandard formula leads to round-off error which is larger than desirable.  In\nthis section we present a new formula which we demonstrate yields machine precision\nfor the area of overlap, along with its derivatives.\n\nFigure \\ref{fig:circle_overlap} shows how the area of overlap can be computed\nfor two circles.  The sums of the areas of the sectors of each circle which span\nthe area of overlap, minus the area of a kite-shaped region which connects the\ncenters of the circles with their points of intersection gives the area of the\nlens-shaped region of overlap of the two circles.\n\nTaking the radius of the larger circle to be unity, the formula for\nthe lens-shaped overlap area is given by\n\\begin{align} \\label{eq:MAuniform}\nA_{lens} = \\pi \\Lambda^e(r,b) &=\n\\begin{dcases}\n0 & \\qquad 1+r \\le b,\\\\\nr^2 \\kappa_0 + \\kappa_1 -\\sqrt{\\frac{4b^2-(1+b^2-r^2)^2}{4}} & \\qquad \\vert 1-r\\vert < b \\le 1+r,\\\\\n\\pi r^2 & \\qquad b \\le 1-r,\\\\\n\\pi & \\qquad b \\le r-1,\\\\\n\\end{dcases}\n\\end{align}\n\\citep[e.g.][]{MandelAgol2002}, where\n\\begin{eqnarray}\\label{eq:cosine_formulation}\n\\cos{\\kappa_0} &=& \\left(\\frac{(r-1)(r+1)+b^2}{2br}\\right),\\\\\n\\cos{\\kappa_1} &=& \\left(\\frac{(1-r)(1+r)+b^2}{2b}\\right),\n\\end{eqnarray}\nwhere $\\kappa_0$ and $\\kappa_1$ are the angles defined in Figure \\ref{fig:circle_overlap}.\nThis is the same as the standard formula for the area of overlap of two circles,\nbut with one of the circles scaled to a radius of unity \\citep{Weisstein2018}.\n\nWe find that numerical round-off error limits the precision of this formula when\n$b \\approx 0$, $b+r \\approx 1$, or $b \\approx 1+r$;  these are the cases in which\nthe kite-shaped region becomes thin, in which the sum of two sides becomes similar\nin length to the spine of the kite.  The square root term in this formula (equation\n\\ref{eq:MAuniform}) is computing the area of the kite-shaped region, which in this\nform causes round-off error when the kite is flattened.  The same issue occurs when\ncomputing the area of a triangle in which two of the sides are of similar length;\nthe kite has an area that is twice the area of the triangle connecting the centers\nof both circles and one of the intersection points.  \\cite{Goldberg1991} gives a\nformula for precisely computing the area of a triangle, based on a method developed\nby \\citet{Kahan2000}, which we reproduce here,\n\\begin{eqnarray}\nA_{kite} &=& \\frac{1}{2}\\sqrt{(a+(b+c))(c-(a-b))(c+(a-b))(a+(b-c))},\\\\\na &\\ge& b \\ge c,\n\\end{eqnarray}\nwhere the tuple $\\{a,b,c\\}$ equals $\\{1,r,b\\}$ sorted from from greatest to least.\n\nNext, the inverse cosine formulae are also imprecise when $\\cos{\\kappa_0} = x_0 \\approx\n1$ or $\\cos{\\kappa_1} = x_1 \\approx 1$.  The approximate solution in this limit\nis $\\kappa_0 \\approx [2(1-x_0)]^{1/2}$ and $\\kappa_1 \\approx [2(1-x_1)]^{1/2}$, and so round-off\nerror can occur both in taking the difference of two numbers close to one,\nand in taking the square root.\n\nInstead, we use the function $\\theta = \\mathrm{atan2}(y,x)$ with $y=\\sin{\\theta}$ and\n$x=\\cos{\\theta}$ to compute $\\kappa_0$ and $\\kappa_1$, which avoids the quadrant and\ndivision-by-zero problems of the $\\theta = \\tan^{-1}(y/x)$ function.  In addition\nto the cosine values above, we require the sine terms, which are given by\n\\begin{eqnarray}\n\\sin{\\kappa_0} &=& \\frac{A_{kite}}{br},\\\\\n\\sin{\\kappa_1} &=& \\frac{A_{kite}}{b},\n\\end{eqnarray}\nwhich can be derived from the area of the triangles formed by the centers of\nthe circles and one intersection point.\nNote that both $\\sin{\\kappa_0}$ and $\\cos{\\kappa_0}$ are divided by $br$, and\n$\\sin{\\kappa_1}$ and $\\cos{\\kappa_1}$ are divided by $b$, so that\nin the arctangent formula these denoninator terms cancel, which can improve\nnumerical stability for small values of $b$ or $r$; this cancellation doesn't happen\nin the arccosine case given in equation \\ref{eq:cosine_formulation}.\n\nThis gives the equations:\n\\begin{eqnarray} \\label{eq:area_of_overlap}\nA_{lens} &=& \\kappa_1 + r^2\\kappa_0 - A_{kite},\\\\\n\\kappa_0 &=& \\mathrm{atan2}(2A_{kite},(r-1)(r+1)+b^2),\\\\\n\\kappa_1 &=& \\mathrm{atan2}(2A_{kite},(1-r)(1+r)+b^2).\n\\end{eqnarray}\n\nThe performance of this formula relative to the standard formula is profiled\nin Figure \\ref{fig:overlap_precision} for $r=0.1$, a typical\nvalue for transiting exoplanets.  We have carried out\nthe computation in the \\texttt{Julia} language, both in double-precision\n(\\texttt{Float64}), and 256-bit precision (\\texttt{BigFloat}), and\nsubtracted the results to measure the numerical errors of the computation.\n\nWe find that the standard\nformula (equation \\ref{eq:MAuniform}) approaches errors of $10^{-8}$\nin the limit of $b \\rightarrow 1-r$. This error exceeds the value\nof the area of the smaller circle minus the area of overlap for\nvalues of $1-r < b < 1-r+10^{-8}$.  Thus, even though this calculation\nis carried out in double precision, the precision achieved is of\norder single precision.  Likewise, for $b \\rightarrow 1+r$,\nthe error of the standard formula approaches $10^{-8}$, with the\nerror exceeding the value of the area of overlap for $1+r-10^{-8} <\nb < 1+r$.\n\nIn contrast, equation \\ref{eq:area_of_overlap} gives a precision\nthat is double-precision in both limits.  Figure\n\\ref{fig:overlap_precision} shows that equation \\ref{eq:area_of_overlap}\ngives a precision of $\\approx 10^{-17}$ in the limit $b \\rightarrow\n1-r$ for $r=0.1$; this limit is due to the limiting precision of\nrepresenting $\\pi r^2$ in double-precision, which in this case\nis $\\pi r^2 / 2^{53} = 10^{-17.4}$, indicated with a dash-dot\ngrey line in the left hand panels of Figure \\ref{fig:overlap_precision}.\nAt the beginning of ingress/end of egress when $b \\approx 1+r$,\neven higher precision is achieved since the area of overlap approaches\nzero, as shown in the right hand panels of Figure \\ref{fig:overlap_precision}.\n\nThe final modification we make when computing the uniform light\ncurve is that we require the visible area of the disk, $S_0$, defined as\n\\begin{eqnarray} \\label{eq:uniform}\nS_0(r,b) &=& \\pi-A_{lens}\\\\\n&=&\\pi -\\kappa_1 - r^2\\kappa_0 + A_{kite},\n\\end{eqnarray}\nrather than the obscured area, $A_{lens}$.  So, instead of computing $\\kappa_1$,\nwe compute $\\pi-\\kappa_1 = -\\mathrm{atan2}(\\sin{\\kappa_1},\\cos{\\kappa_1})$.\nWe find that this leads to machine-precision as well.  Note that $S_0=s_0$,\nthe first basis function in the \\starry implementation from Luger et al. (2018).\n\nThe partial derivatives of this formula with respect to the radius\nratio, $r$, and impact parameter, $b$, turn out to be straightforward:\n\\begin{eqnarray}\n\\frac{\\partial S_0(r,b)}{\\partial r} &=& -2r \\kappa_0,\\\\\n\\frac{\\partial S_0(r,b)}{\\partial b} &=& \\frac{A_{kite}}{b},\n\\end{eqnarray}\nwhich can be computed from the quantities already used in calculating $S_0$.\nAt the contact points, when $b = \\vert 1\\pm r\\vert$, the derivatives are undefined.\nIn practice this can be a problen when taking finite-differences across\nthe discontinuous boundary, but with the analytic formulae, these points\nare a set of measure zero, and so we simply set the derivatives to zero\nat these points.\n\nIn the remainder of this paper we will need to use these formulae in computing\nthe higher order limb-darkened light curves.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/overlap.pdf}\n    \\caption{The area of overlap of two circles can be computed as the sum of\n    the area of the sectors formed by the centers of each circle and the\n    boundary between the points of intersection, minus the area of the kite-shaped\n    region formed by the centers of the circles and the intersection points.}\\label{fig:circle_overlap}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/area_of_overlap_r01.pdf}\n    \\caption{Precision of formulae for the area of overlap of two circles with\n    radius ratio $r$.  Plotted are the regions near $b=1-r$ (second and third\n    points of contact) and $b=1+r$ (first and fourth points of contact) for\n    the standard formula (equation \\ref{eq:MAuniform}, blue) and our new formula\n    (equation \\ref{eq:area_of_overlap}, orange dots).\n    The high-precision calculation is shown in green dashed for comparison; this\n    is limited by the conversion of the result to double-precision. The\n    solid and empty circles (top) indicate the positions of the circles at the left\n    hand side of the axes.  In the left panels the dash-dot grey line indicates the\n    limiting precision for representing $\\pi r^2$.}\\label{fig:overlap_precision}\n    \\end{centering}\n\\end{figure}\n\n\\section{Linear Limb-Darkening}\n\\label{sec:reparam}\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n% ==============================================================================\n\nIn this section we turn to the case of linear limb-darkening, $I(\\upmu) = \\upmu$\n\\citep{Russell1912a,Russell1912b}.\nNote that since $\\upmu = \\sqrt{1-x^2-y^2}$, this problem is equivalent to\ncomputing the volume of intersection between a sphere and a cylinder, which was\nsolved in terms of elliptic integrals by \\citet{Lamarche1990}.\nA similar solution was found by \\citet{MandelAgol2002}, who show that the total\nflux visible during the occultation of a body whose surface map is given by\n$I(x, y) = \\sqrt{1 - \\x^2 -\\y^2}$ may be computed as\n%\n\\begin{align}\n    \\label{eq:s2}\n    S_1 = \\frac{2\\pi}{3} \\left(1 - \\frac{3\\Lambda(r,b)}{2} - \\Theta(r - b) \\right)\n\\end{align}\n%\nwhere $\\Theta(\\bigdot)$ is the Heaviside step function and\n%\n\\begingroup\\makeatletter\\def\\f@size{10}\\check@mathfonts\n\\def\\maketag@@@#1{\\hbox{\\m@th\\large\\normalfont#1}}%\n\\begin{align}\n    \\label{eq:biglam}\n    \\Lambda(r,b) &=\n    \\begin{dcases}\n          % I don't think we need this: the k^2>1 term is stable as b --> 0!\n          %-\\frac{2}{3}\\left(1 - r^2\\right)^\\frac{3}{2}\n          %& \\qquad b = 0\n          %\n          %\\\\[1.5em]\n          %\n          \\frac{1}{9 \\pi \\sqrt{b r}} \\Bigg[\n                \\frac{(r + b)^2 - 1}{r + b}\n                \\Big(\n                    -2r \\,\n                    \\big(\n                        2 (r + b)^2 + (r + b)(r - b) - 3\n                    \\big)\n                    K(k^2)\n                    &\\\\ \\phantom{XXXX}\n                    + 3 (b - r) \\, \\Pi\\big(k^2 (b + r)^2, \\, k^2\\big)\n                \\Big)\n                - 4 b r (4 - 7 r^2 - b^2) E(k^2)\n          \\Bigg]\n          %\n          & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2}{9 \\pi} \\Bigg[\n                \\big(1 - (r + b)^2\\big)\n                \\Bigg(\n                    \\sqrt{1 - (b - r)^2} \\,\n                    K\\left(\\frac{1}{k^2}\\right)\n                    + 3 \\left(\\frac{b-r}{(b+r)\\sqrt{1 - (b - r)^2}}\\right)\n                    &\\\\ \\phantom{XX}\n                    \\times \\Pi\\left(\\frac{1}{k^2(b+r)^2}, \\, \\frac{1}{k^2}\\right)\n                \\Bigg)\n                - \\sqrt{1 - (b - r)^2}\n                (4 - 7 r^2 - b^2)\n                E\\left(\\frac{1}{k^2}\\right)\n          \\Bigg]\n          %\n          & \\qquad k^2 \\ge 1\n    \\end{dcases}\n\\end{align}\n\\endgroup\n%\nwith\n%\n\\begin{align}\n    \\label{eq:k2}\n    k^2 &= \\frac{1 - r^2 - b^2 + 2 b r}{4 b r}\n    \\quad.\n\\end{align}\nNote that $S_1(r,b) = s_2(r,b)$ in the spherical harmonic expansion used in \\starry as\ndescribed in Luger et al. (2018).\nFor the cases $b=r$, $b=1-r$, $b=0$, $r=0$, or $\\vert r-b\\vert \\ge 1$, there are special\nexpressions for $\\Lambda(r,b)$ given below.\n%\nIn the expressions above, $K(\\bigdot)$, $E(\\bigdot)$, and $\\Pi(\\bigdot, \\bigdot)$\nare the complete elliptic integrals of the first, second kind, and third kind,\nrespectively, defined as\n%\n\\begin{align}\n    \\label{eq:elliptic}\n    K(k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\frac{\\dd \\varphi}{\\sqrt{1 - k^2 \\sin^2 \\varphi}}\n    \\nonumber \\\\[0.5em]\n    E(k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\sqrt{1 - k^2 \\sin^2 \\varphi} \\, \\dd \\varphi\n    \\nonumber \\\\[0.5em]\n    \\Pi(n, k^2) &\\equiv \\int_0^{\\frac{\\pi}{2}} \\frac{\\dd \\varphi}{(1 - n \\sin^2 \\varphi)\\sqrt{1 - k^2 \\sin^2 \\varphi}}\n    \\quad.\n\\end{align}\nIn these expressions we have transformed the formulae from \\citet{MandelAgol2002} using\nequation 17.7.17 from \\citet{Abramowitz1970} which yields equations that are better\nbehaved in the vicinity of $b=r$.\\footnote{Note that we corrected several typos\nin \\citet{MandelAgol2002}, which are listed in the Appendix.}  However, these elliptic\nintegrals are still subject to numerical instability as $r \\rightarrow 1-b$ and $r \\gg 1$.\nThe main issue is the logarithmic divergence of $K$ and $\\Pi$ as $k \\rightarrow 1$, as\nwell as numerical cancellations leading to round-off errors which occur in the\nlimit $k \\rightarrow 0$.\n\nThrough trial and error, we have found that these instabilities can be removed by combining\nelliptic integrals into a general complete elliptic integral defined by \\citet{Bulirsch1969} as\n\\begin{equation}\n{\\rm cel}(k_c,p,a,b) = \\int_0^{\\pi/2} \\frac{a\\cos^2{\\phi} + b\\sin^2{\\phi}}{\\cos^2{\\phi}+p\\sin^2{\\phi}} \\frac{d\\phi}{\\sqrt{\\cos^2{\\phi}+k_c^2\\sin^2{\\phi}}},\n\\end{equation}\nwhere $k_c = \\sqrt{1-m}$, and for $b+r \\ge 1$,\n$m=k^2$, while for $b+r \\le 1$, $m=1/k^2$.  Although $k_c$ can be computed from\n$m$, we have found better numerical stability in computing $k_c$ analytically\nfrom $b$ and $r$:\n\\begin{align}\n    k_c &=\n    \\begin{dcases}\n     \\sqrt{\\frac{(b+r)^2-1}{4br}} & \\qquad k^2 \\le 1\\\\\n     \\sqrt{\\frac{1-(b+r)^2}{1-(b-r)^2}} & \\qquad k^2 > 1.\n   \\end{dcases}\n\\end{align}\nIn practice, we let the subroutine that computes ${\\rm cel}$ accept both\n$m$ and $k_c$ as input for numerical precision.\n\nTo transform the elliptic integrals in equation \\ref{eq:biglam},\nwe used the following relations from \\citet{Bulirsch1969}:\n\\begin{eqnarray}\n\\lambda K(m) + q E(m) &=& {\\rm cel}(k_c,1,\\lambda+q,\\lambda+q k_c^2)\\\\\n\\lambda K(m) + q \\Pi(n,m) &=& {\\rm cel}(k_c,1-n,\\lambda+q,\\lambda+q k_c^2)\\\\\nE(m) &=& {\\rm cel}(k_c,1,1,1-m)\\\\\nE(m)-(1-m)K(m) &=& m \\, {\\rm cel}(k_c,1,1,0)\\\\\n\\Pi(n,m)-K(m)  &=& n \\, {\\rm cel}(k_c,1-n,0,1),\n\\end{eqnarray}\nnoting that \\citet{Bulirsch1969} uses a different sign convention for $\\Pi(n,m)$.\nIn particular, the expressions for $\\Pi(n,m)-K(m)$ and $E(m)-(1-m)K(m)$ are useful for eliminating\nthe singularities and cancellations which occur at $m=1$ when $b+r=1$ and $m=0$ when\n$r \\rightarrow \\infty$.  The general complete elliptic integral is evaluated\nwith the approach of \\citet{Bartky1938}, which uses recursion to approximate the\nintegral to a specified precision.\n\nThese elliptic integral transformations lead to the following numerically-stable\nexpression for the linear limb-darkening flux, $S_1(r,b) = s_2(r,b)$, in which\n\\begin{align}\n    \\label{eq:biglam_stable}\n    \\Lambda &=\n    \\begin{dcases}\n          0 & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          -\\tfrac{2}{3}(1-r^2)^{3/2} & \\qquad b = 0\\\\\n          \\tfrac{1}{3} - \\tfrac{4}{9\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\tfrac{1}{3} + \\tfrac{2}{9\\pi} {\\rm cel}\\left(k_c,1,m-3,(1-m)(2m-3)\\right) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          \\tfrac{1}{3} + \\tfrac{1}{9\\pi r} {\\rm cel}\\left(k_c,1,m-3,1-m\\right) & \\qquad b= r > \\tfrac{1}{2}\\\\  % I think this equation may have a mistake [ ]  EA 7/17/2018\n          \\tfrac{2}{9\\pi}\\left[3\\cos^{-1}(1-2r) -2(3+2r-8r^2)\\sqrt{rb}-3\\pi\\Theta(r-\\tfrac{1}{2})\\right] & \\qquad b+r =1\\\\\n          \\frac{1-(b-r)^2}{9 \\pi \\sqrt{b r}} \\Bigg[\n                \\frac{(b+r)^2-1}{4br}(b^2-r^2){\\rm cel}(k_c,(b-r)^2(1-m),0,3)\n                &\\\\ \\phantom{XXXX}\n               - (3-6r^2-2br){\\rm cel}(k_c,1,1,0)-4brE(m)\n          \\Bigg]\n          %\n          & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2\\sqrt{1-(b-r)^2}}{9 \\pi} \\Bigg[\n                \\big(1 - (r + b)^2\\big)\n                {\\rm cel}(k_c,p,1+q,p+q) &\\\\ \\phantom{XXXX}\n                - (4 - 7 r^2 - b^2)\n                E\\left(m\\right)\n          \\Bigg]\n          %\n          & \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{align}\nwhere\n\\begin{eqnarray}\nq &=& 3\\frac{b-r}{(b+r)(1-(b-r)^2)}\\\\\np &=& \\left(\\frac{b-r}{b+r}\\right)^2 \\frac{1-(b+r)^2}{1-(b-r)^2}\n\\end{eqnarray}\nin the $k^2 > 1$ case.  Note that in this equation the conditions\nshould be evaluated in the order they appear.\n\nThe $S_1(r,b)$ function is plotted in Figure \\ref{s2_plot}.  The\nfunction varies smoothly from the lower right where the disk is\nunocculted to the upper left where it is completely occulted.\nThere are several points which need to be handled separately as\nthe equation \\ref{eq:biglam} expressions become singular or are\nno longer valid;  the solid lines in Figure \\ref{s2_plot} show\nthese points.  When $b=0$, the integral over the center of the\ndisk simplifies greatly.  When $b=r=1/2$, at the intersection of\n$b=r$ and $b=1-r$, another simplification occurs.  For $b=r$,\nthe disk of the occultor crosses the center of the source;\nthis needs to be computed separately in the $r<1/2$, $r=1/2$,\nand $r>1/2$ limits.  The first and fourth contacts occur at\n$b=1+r$, where $S_1=1$;  this is the upper bound to the $k^2 < 1$\nregion for $b+r >1$.\nFor $r \\ge 1$, the second and third contacts (at the start and\nend of complete occultation) occur when $b=1-r$, which is the\nlower  bound to the $k^2<1$ region when $b+r >1$.\nFor $r < 1$, the second and third contacts occur when $r=1-b$.\n\nNear these boundaries, the standard \\citet{MandelAgol2002} expressions\ncan become singular, and so we paid particular care to the accuracy of these\nnew expressions in these regions.  Figure \\ref{s2_machine} shows\nthat equation \\ref{eq:biglam_stable} is accurate to machine\nprecision in all of these regimes.\nWe tested the accuracy by computing the equations with 256 bit\narithmetic, which is much less subject to round-off error, and\nhence gives more precise expressions than double precision.  We implemented the\npseudocode from \\citet{Bulirsch1969} to compute ${\\rm cel}(k_c,p,a,b)$,\nwhich has a termination test that scales as the square root of\nthe machine precision.  We find that the transformed expressions\nare accurate to $\\la \\times 10^{-14}$ when computed in double precision\nwithin $10^{-8}$ of the vicinity of $b=r$ and $b=1-r$.\n\n\\begin{figure}\\label{transit_linear}\n    \\begin{centering}\n    \\includegraphics[width=0.85\\linewidth]{figures/julia/transit_linear.pdf}\n    \\caption{The intensity of a linearly limb-darkened star ($u_1=1$) being\n    eclipsed, $S_1(r,b)$.\n    In the limit $b > r+1$, no eclipse occurs, so $S_1=1$.  For $b < r-1$, the star\n    is completely eclipsed and $S_1=0$.  In the limits $b=r$ and $b=1-r$, special\n    expressions must be used.}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\\label{s2_plot}\n    \\begin{centering}\n    \\includegraphics[width=0.85\\linewidth]{figures/julia/s2_residuals.pdf}\n    \\caption{The numerical error in computing the flux of an eclipsed,  linearly\n    limb-darkened star ($u_1=1$), $S_1(r,b)$.}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\\label{s2_machine}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/s2_machine.pdf}\n    \\caption{The accuracy of $S_1(r,b)$ near $b=r$ (left panel) and\n    $b=1-r$ (right panel). The x-axese are impact parameter b,\n    while the y axes in the top panels show $S_1(r,b)$, with $r$\n    given in the legend of each panel. The middle panels plot\n    the difference $(S_1(b,b\\pm\\epsilon)-S_1(b,b))/\\epsilon$\n    and $(S_1(b,1-b\\pm\\epsilon)-S_1(b,1-b))/\\epsilon$. The bottom\n    panels show the numerical precision by the comparing double precision\n    computation with \\texttt{BigFloat} precision (256-bit).}\n    \\end{centering}\n\\end{figure}\n\n\nFrom \\citet{MandelAgol2002}, the total flux visible during the occultation of a\nbody whose surface map is given by $I(\\upmu)/I(1) = 1 - u_1(1 - \\upmu)$ may be computed\nas\n\\begin{eqnarray}\n\\frac{F(u_1,r,b)}{F_0} &=& \\frac{\\pi(1-u_1)(1-\\Lambda^e)+ u_1 S_1(r,b)}{\\frac{2\\pi}{3}u_1 + \\pi(1-u_1)},\\\\\n&=& 1-(1-u_1/3)^{-1}\\left[(1-u_1)\\Lambda^e(r,b) + u_1\\left(\\Lambda(r,b)+\\tfrac{2}{3}\\Theta(r-b)\\right)\\right],\n\\end{eqnarray}\nwhere\nand $F_0$ is the total unocculted flux.  % Note:  I'm not using this in\n% transit_poly since it is not as precise as the starry expressions.\n\n\\subsection{Derivatives of linear limb-darkening}\n\nIt turns out that the expressions for the derivatives of the linear limb-darkening\nlight curve with respect to $r,b$ are particularly simple:\n\\begin{align}\n    \\label{eq:dbiglam_dr}\n    \\frac{\\partial \\Lambda}{\\partial r} &=\n    \\begin{dcases}\n          0 & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          2 r\\sqrt{1-r^2} & \\qquad b = 0\\\\\n           \\frac{2}{\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\frac{4r}{\\pi} E(4r^2) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          \\frac{2}{\\pi} \\mathrm{cel}(k_c,1,1,0) & \\qquad b= r > \\tfrac{1}{2}\\\\\n          \\frac{8r}{\\pi}\\sqrt{r(1-r)} & \\qquad b+r =1\\\\\n          \\frac{8br^2 E(k^2) + 2r(1-(b+r)^2)K(k^2)}{\\pi\\sqrt{br}}\n                    &\\\\ \\phantom{XX}\n          = \\frac{1}{\\pi\\sqrt{br}}\\mathrm{cel}(k_c,1,2r(1-(b-r)^2),0) & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} E(k^{-2})\n                    &\\\\ \\phantom{XX}\n          = \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} \\mathrm{cel}(k_c,1,1,k_c^2)& \\qquad k^2 > 1\\\\\n    \\end{dcases}\n\\end{align}\nand\n\\begin{align}\n    \\label{eq:dbiglam_db}\n    \\frac{\\partial \\Lambda}{\\partial b} &=\n    \\begin{dcases}\n          0 & \\qquad  r = 0\\\\\n          0 & \\qquad  \\vert r- b\\vert \\ge 1\\\\\n          0 & \\qquad b = 0\\\\\n           -\\frac{2}{3\\pi} & \\qquad b = r = \\tfrac{1}{2}\\\\\n          \\frac{4r}{3\\pi}\\mathrm{cel}(k_c,1,-1,k_c^2) & \\qquad b= r < \\tfrac{1}{2}\\\\\n          -\\frac{2}{3\\pi} \\mathrm{cel}(k_c,1,1,2k_c^2) & \\qquad b= r > \\tfrac{1}{2}\\\\\n          -\\frac{8r}{3\\pi}\\sqrt{r(1-r)} & \\qquad b+r =1\\\\\n           \\frac{4r(r^2+b^2-1) E(k^2) + 2r(1-(b+r)^2)K(k^2)}{3\\pi\\sqrt{br}}\n                    &\\\\ \\phantom{XX}\n          = \\frac{1-(b-r)^2}{3\\pi \\sqrt{br}} \\mathrm{cel}(k_c,1,-2r,(1-(b+r)^2)/b) & \\qquad k^2 < 1\n          %\n          \\\\[1.5em]\n          %\n          \\frac{2}{3b\\pi}\\sqrt{1-(b-r)^2}\\left[(r^2+b^2-1) E(k^{-2}) +(1-(b+r)^2)K(k^{-2})\\right]\n                    &\\\\ \\phantom{XX}\n          =\\frac{4r}{3\\pi}\\sqrt{1-(b-r)^2}\\mathrm{cel}(k_c,1,-1,k_c^2) & \\qquad k^2 > 1,\\\\\n    \\end{dcases}\n\\end{align}\nwhere we have given some of the expressions in terms of both the standard elliptic integrals\nand the general elliptic integral.\n\nNote that if we had included the radius of the source star in these formulae,\nthen the derivatives with respect to the radius of the star yield the\ntransit light curve of a uniform, thin emission shell \\citep{Schlawin2010}.\n\nWe have tested these formulae with finite-difference derivatives evaluated at\n256-bit precision, and, as with the total flux term, we find that these are accurate\nto $\\la 2 \\times 10^{-15}$, close to machine precision.\n\nFinally, we turn our attention to the general polynomial limb-darkening case,\n$\\upmu^n$ with $n \\ge 2$.  These terms may be expressed as the sum of\nspherical harmonics with $m=0$, and thus they are a special case of the \\starry\ncomputation (written in C and Python), which we describe next in \\S \\ref{sec:quad}.\nWe have also derived a new approach exploiting the azimuthal symmetry of the\nlimb-darkening problem, which we describe below in \\S \\ref{sec:power_law},\nwhich is implemented in \\texttt{Julia}.\n\n%\\begin{eqnarray}\n%\\frac{\\partial \\Lambda}{\\partial r} &=& \\frac{8br^2 E(k^2) + 2r(1-(b+r)^2)K(k^2)}{\\pi\\sqrt{br}}\\\\\n%&=& \\frac{1}{\\pi\\sqrt{br}}\\mathrm{cel}(k_c,1,2r(1-(b-r)^2),0)\\\\\n%\\frac{\\partial \\Lambda}{\\partial b} &=& \\frac{4r(r^2+b^2-1) E(k^2) + 2r(1-(b+r)^2)K(k^2)}{3\\pi\\sqrt{br}}\\\\\n%&=& \\frac{1-(b-r)^2}{3\\pi \\sqrt{br}} \\mathrm{cel}(k_c,1,-2r,(1-(b+r)^2)/b)\\\\\n%\\frac{\\partial \\Lambda}{\\partial r} &=& \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} E(k^{-2})\\\\\n%&=& \\frac{4r}{\\pi}\\sqrt{1-(b-r)^2} \\mathrm{cel}(k_c,1,1,k_c^2)\\\\\n%\\frac{\\partial \\Lambda}{\\partial b} &=& \\frac{2}{3b\\pi}\\sqrt{1-(b-r)^2}\\left[(r^2+b^2-1) E(k^{-2}) +(1-(b+r)^2)K(k^{-2})\\right]\\\\\n%&=& \\frac{4r}{3\\pi}\\sqrt{1-(b-r)^2}\\mathrm{cel}(k_c,1,-1,k_c^2)\n%\\end{eqnarray}\n\n% ==============================================================================\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n%\n\\clearpage\n\\section{Polynomial Limb-Darkening}\n\\label{sec:quad}\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n% ==============================================================================\n\nIn analogy with the linear and quadratic\nlimb-darkening laws, let us define the polynomial limb-darkening law of\norder $l_\\mathrm{max}$ as\n%\n%\n\\begin{align}\n    \\label{eq:polynomialld}\n    \\frac{I(\\upmu)}{I(1)} &= 1 - u_1 (1 - \\upmu) - u_2 (1 - \\upmu)^2 - ... - u_{l_\\mathrm{lmax}}(1 - \\upmu)^{l_\\mathrm{lmax}} \\nonumber \\\\\n                          &= \\sum_{l=0}^{l_\\mathrm{lmax}} \\sum_{k=0}^l u_l {l \\choose k} (-1)^k \\upmu^k\n    \\quad,\n\\end{align}\n%\nwhere $u_0 \\equiv 1$. For convenience, this can be expressed as the matrix equation\n%\n\\begin{align}\n    \\label{eq:polynomialldmatrix}\n    \\frac{I(\\upmu)}{I(1)} &= \\bvec{u}^\\top \\, \\bvec{L} \\, \\pmb{\\upmu}\n    \\quad,\n\\end{align}\n%\nwhere $\\bvec{u}^\\top$ is a row vector whose value at index\n$l$ is $u_l$, $\\pmb{\\upmu}$ is a column vector whose value at index $k$ is $\\upmu^k$,\nand $\\bvec{L}$ is the lower triangular matrix with components given by\n%\n\\begin{align}\n    \\label{eq:Llk}\n    L_{lk} = {l \\choose k} (-1)^k\n    \\quad.\n\\end{align}\n%\nIt is straightforward to show that this law can be\nexpressed exactly as a sum over the $m = 0$ spherical harmonics, which also\nform a complete basis of radially symmetric functions on the sphere.\n%\nBased on the relations in \\citet{starry} for the spherical harmonics in Cartesian\nform, the spherical harmonics of order $m = 0$ may be written\n%\n\\begin{align}\n    \\label{eq:Ylzero}\n    Y_{l,0}(\\upmu) = \\sqrt{\\frac{2l + 1}{4\\pi}}\n              \\sum_{k=0}^l {l \\choose k} \\frac{(k + l - 1)!!}{(k - l - 1)!!} \\upmu^k\n\\end{align}\n%\nwhere $\\upmu = z = \\sqrt{1 - x^2 - y^2}$, $\\binom{\\bigdot}{\\bigdot}$ is a binomial\ncoefficient, and $!!$ denotes the double factorial.\n\nOur task now is to express the specific intensity function (\\ref{eq:polynomialldmatrix})\nin the basis of spherical harmonics (\\ref{eq:Ylzero}). We therefore wish to find\nthe coefficients $c_l$ for which we may write\n%\n\\begin{align}\n    \\label{eq:sphharmld}\n    \\frac{I(\\upmu)}{I(1)} &= \\sum_{l=0}^{l_\\mathrm{lmax}} c_l Y_{l,0}(\\upmu)\n    \\quad.\n\\end{align}\n%\nAs before, we can write this as the matrix equation\n%\n\\begin{align}\n    \\label{eq:sphharmldmatrix}\n    \\frac{I(\\upmu)}{I(1)} &= \\bvec{c}^\\top \\, \\bvec{M} \\, \\pmb{\\upmu}\n    \\quad,\n\\end{align}\n%\nwhere $\\bvec{c}^\\top$ is a row vector whose value at index\n$l$ is $c_l$ and $\\bvec{M}$ is the lower triangular matrix with components given by\n%\n\\begin{align}\n    \\label{eq:Mlk}\n    M_{lk} = \\sqrt{\\frac{2l + 1}{4\\pi}} {l \\choose k} \\frac{(k + l - 1)!!}{(k - l - 1)!!}\n    \\quad.\n\\end{align}\n%\nEquating Equations~(\\ref{eq:polynomialldmatrix}) and (\\ref{eq:sphharmldmatrix}), we see\nthat we must have\n%\n\\begin{align}\n    \\bvec{c}^\\top \\, \\bvec{M} = \\bvec{u}^\\top \\, \\bvec{L} \\quad,\n\\end{align}\n%\nor\n%\n\\begin{align}\n    \\bvec{c} = (\\bvec{M}^{-1} \\, \\bvec{L})^\\top \\bvec{u} \\quad.\n\\end{align}\n%\nIn \\citet{starry} we described how to compute analytic transit and occultation light curves\nfor bodies whose surfaces are expressed as a sum over spherical harmonic coefficients. We\ndefined a body's surface map as the vector of spherical harmonic coefficients $\\bvec{y}$.\nThe vector $\\bvec{y}$ corresponding to our coefficients for the $Y_{l,0}$ harmonics is\nrelated to $\\bvec{c}$ via\n%\n\\begin{align}\n    y_{l(l + 1)} &= c_l\n\\end{align}\n%\nfor $0 \\leq l \\leq l_\\mathrm{max}$, where the values at all other indices in $\\bvec{y}$ are zero.\n\n\\begin{figure}[t!]\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/high_order_ld.pdf}\n    \\caption{\\label{fig:high_order_ld} Tenth order limb-darkening example with \\starry. }\n    \\end{centering}\n\\end{figure}\n\n\\begin{align}\n    \\label{eq:PGnI}\n    \\mathcal{P}(\\bvec{G}_n) &=\n    \\begin{dcases}\n        %\n        r^{l+2} \\sum\\displaylimits_{i=0}^{\\frac{l}{2}}\n                {\\frac{l}{2} \\choose i}\n                \\left(\\frac{b}{r}\\right)^{\\frac{l-2i}{2}}\n                \\mathcal{I}_{\\frac{l+4}{2}, i}\n            %\n            & \\qquad \\frac{l}{2} \\, \\mathrm{even}\n        \\\\[1em]\n        %\n        -r^{l-2} \\left( b \\mathcal{J}_{l-3,1} + r \\mathcal{J}_{l-3,2} \\right)\n        %\n        & \\qquad l = 1\n        \\\\[1em]\n        %\n        r^{l-1} \\sum\\displaylimits_{i=0}^{\\frac{l-1}{2}}\n                {\\frac{l-1}{2} \\choose i}\n                \\left(\\frac{b}{r}\\right)^{\\frac{l-2i-1}{2}}\n                \\mathcal{J}_{\\frac{l-1}{2}, i}\n            & \\qquad \\frac{l-1}{2} \\, \\mathrm{even}\n        \\\\[1em]\n        %\n        0 & \\qquad \\mathrm{otherwise}\n    \\end{dcases}\n%\n\\end{align}\n%\n\\begin{align}\n%\n    \\nonumber \\\\\n    \\label{eq:QGnI}\n    \\mathcal{Q}(\\bvec{G}_n) &=\n    \\begin{dcases}\n        \\mathcal{H}_{\\frac{l+4}{2}, \\frac{l}{2}}\n        & \\qquad \\qquad \\qquad \\qquad \\quad \\quad \\quad \\quad \\frac{l}{2} \\, \\mathrm{even}\n        \\\\[1em]\n        %\n        0\n        & \\qquad \\qquad \\qquad \\qquad \\quad \\quad \\quad \\quad \\mathrm{otherwise} \\quad.\n    \\end{dcases}\n\\end{align}\n\nWe have computed derivatives of these expressions using automatic\ndifferentiation within the \\starry code base.\n\n\\section{Alternative Green's function expansion} \\label{sec:power_law}\n\nAlthough the foregoing analysis takes advantage of the existing formalism\ndeveloped for occultation of spheres with arbitrary spherical harmonic\nbrightness, the problem can be simplified somewhat for the limb-darkening\ncase due to the azimuthal symmetry assumed for a star.  This simplification\nleads to analytic expressions for the derivatives, which we find can be\nevaluated with greater speed and accuracy compared with automatic differentiation.\n\nSince the polynomial expansion only depends on $\\upmu = z =\\sqrt{1-x^2-y^2}$,\nwhere $(x,y,z)$ are the coordinates of the unit sphere, then we only require\nGreen's functions whose curl has dependence on $z$ for axially-symmetric\nlimb-darkening.  Following Luger et al. (2018), we choose a Green's function\nof the form\n\\begin{equation}\n\\mathbf{G}_n = f(z) (-y \\xhat + x \\yhat)\n\\end{equation}\ngiving\n\\begin{eqnarray}\n\\gbasisn(x,y) &=& \\frac{\\dd {G_n}_y}{\\dd \\x} - \\frac{\\dd {G_n}_x}{\\dd \\y}\\\\\n&=& 2 f(z) + \\frac{df}{dz} \\frac{z^2-1}{z}.\n\\end{eqnarray}\nThis yields particularly simple form for the primitive integrals of\n\\begin{align}\n    \\label{eq:primitiveP}\n    \\mathcal{P}(\\bvec{G}_n) &=\n    \\int\\displaylimits_{\\pi-\\phi}^{2\\pi + \\phi} f(z) (r+b \\sin{\\varphi}) r d\\varphi\n    %\n\\intertext{and}\n    %\n    \\label{eq:primitiveQ}\n    \\mathcal{Q}(\\bvec{G}_n) &=\n    \\int\\displaylimits_{\\pi-\\lambda}^{2\\pi + \\lambda} f(z) d \\varphi\n\\end{align}\n\nWe choose $f(z) = z^n$, so that\n\\begin{equation}\n\\gbasisn(x,y) =  (n+2)z^n-n z^{n-2},\n\\end{equation}\nis the basis set for the surface brightness of the polynomial limb-darkening,\nalong with the uniform, $\\tilde{g}_0 = z^0$,\nand linear, $\\tilde{g}_1 = z^1$, terms which we have derived in \\S \\ref{sec:reparam}.\nNote that the total flux of each term in this basis set, $\\tilde{g}_n$, integrates\nto zero for $n \\ge 2$.\n\nAlso, with this choice of basis, the primitive integral $\\mathcal{Q}(\\bvec{G}_n) = 0$ for\n$n \\ge 1$ since $z=0$ at the boundary of the star.   The $n=0$ case we have already\nsolved for uniform limb-darkening, and so it remains to find $\\mathcal{P}(\\bvec{G}_n)$.\n\nThe primitive integral\n$\\mathcal{P}(\\bvec{G}_n)$ can be rewritten as\n\\begin{equation}\n\\mathcal{P}(\\bvec{G}_n) =\n\\int_{\\pi-\\phi}^{2\\pi + \\phi} \\left(1-r^2-b^2-2br s_\\varphi\\right)^{\\frac{n}{2}} (r+b s_\\varphi) r d\\varphi,\n\\end{equation}\nwhere $s_\\varphi = \\sin{\\varphi}$.\nWe make the transformation $\\xi = \\tfrac{1}{2} \\left(\\varphi - \\tfrac{3\\pi}{2}\\right)$, yielding\n\\begin{equation}\n\\mathcal{P}(\\bvec{G}_n) =\n2r (4br)^{\\frac{n}{2}}\\int\\displaylimits_{-\\tfrac{\\kappa}{2}}^{\\tfrac{\\kappa}{2}}\n(k^2-\\sin^2\\xi)^{\\tfrac{n}{2}} (r-b + 2b \\sin^2 \\xi) d\\xi,\n\\end{equation}\nfor even values of $n$ and\n\\begin{equation}\n\\mathcal{P}(\\bvec{G}_n) =\n2r (4br)^{\\frac{n}{2}} k^3 \\int\\displaylimits_{-\\tfrac{\\kappa}{2}}^{\\tfrac{\\kappa}{2}}\n(k^2-\\sin^2\\xi)^{\\tfrac{n-3}{2}} (1-k^{-2} \\sin^2 \\xi)^{3/2} (r-b + 2b \\sin^2 \\xi) d\\xi,\n\\end{equation}\nfor odd values of $n \\ge 3$, where $\\kappa = 2 \\sin^{-1}k$ for $k^2 \\le 1$ and\n$\\kappa = \\pi$ for $k^2 > 1$.  Note that $\\kappa = \\kappa_0$, so in practice we\nreuse the value of $\\kappa_0$ which was computed in the uniform limb-darkening\ncase (\\S \\ref{sec:uniform}).\n\nEach of the terms $(k^2-\\sin^2\\xi)^c$ can be expanded with the binomial theorem,\nand then expressed in terms of the integrals $\\mathcal{I}_v(k)$ and $\\mathcal{J}_v(k)$\n(defined in Luger et al. 2018) as\n\\begin{eqnarray}\n\\mathcal{P}(\\mathbf{G}_n)\n= 2r(4br)^{n_0} \\sum_{i=0}^{n_0} \\binom{n_0}{i}(-1)^{n_0-i} k^{2i} \\left[(r-b)\\mathcal{I}_{n_0-i} + 2b \\mathcal{I}_{n_0-i+1}\\right],\n\\end{eqnarray}\nfor even $n$, where $n_0 = n/2$, and\n\\begin{eqnarray}\n\\mathcal{P}(\\mathbf{G}_n)\n= \\mathcal{F}(4br)^{n_0} \\sum_{i=0}^{n_0} \\binom{n_0}{i} (-1)^{n_0-i} k^{2i} \\left[(r-b)\\mathcal{J}_{n_0-i} + 2b \\mathcal{J}_{n_0-i+1}\\right],\n\\end{eqnarray}\nfor odd $n \\ge 3$, where $n_0 = (n-3)/2$ and\n $\\mathcal{F} = 2r(1-(b-r)^2)^{3/2}$.\n\nFor completeness we list the expressions for the functions $\\mathcal{I}_v(k)$ and $\\mathcal{J}_v(k)$:\n\\begin{eqnarray}\n\\mathcal{I}_{v} &=& \\int_{-\\kappa/2}^{\\kappa/2} s_\\varphi^{2v} d\\varphi \\quad,\\\\\n\\mathcal{J}_v &=& \\int_{-\\kappa/2}^{\\kappa/2} d\\varphi s^{2v}_\\varphi\\left(1-k^{-2}s^2_\\varphi\\right)^{3/2},\n\\end{eqnarray}\nwhere, again, we note that $\\kappa$ is a simple function of $k$.\n\n\\subsection{Limb-darkening coefficients}\n\nOur expansion for limb-darkening in terms of $u_n(1-\\upmu)^n$ (equation \\ref{eq:polynomialld}) needs to\nbe re-expressed in terms of the Green's basis terms $d_n \\left[(n+2)\\upmu^n -n \\upmu^{n-2}\\right]$,\nwhere $d_n$ are constants.\nWe accomplish this by first transforming $u_n$ to coefficients of $a_n \\upmu^n$,\nand then transforming from $a_n$ to $d_n$.\n\nWe rewrite $I(\\upmu)$ in terms of these three expansions\n\\begin{eqnarray}\n\\frac{I(\\upmu)}{I(1)} &=& 1 - \\sum_{i=1}^N u_i \\sum_{j=0}^i \\binom{i}{j} (-1)^j \\upmu^j,\\\\\n&=& \\sum_{n=0}^N a_n \\upmu^n,\\\\\n&=& d_0 + d_1 \\upmu + \\sum_{n=2}^N d_n \\left[(n+2)\\upmu^n -n \\upmu^{n-2}\\right].\n\\end{eqnarray}\nNote that $a_0= 1-\\sum_{n=1}^N a_n = 1 - \\sum_{i=1}^N u_i$ in the formalism of \\citet{Gimenez2006}.\nThe transformation between $u_n$ and $a_n$ is straightforward based on\nlooping over the binomial expansion of each of the $u_n$ terms (equation \\ref{eq:polynomialld}),\nfor example $a_1 = \\sum_{n=1}^N n u_n$.\nThen, with the computed $a_n$ values, we can find $d_n$ from downward recursion\nusing the relation\n\\begin{equation}\nd_n = \\frac{a_n}{n+2} + d_{n+2},\n\\end{equation}\nstarting with $n=N$, with $d_{N+1}=d_{N+2}=0$.\n\nThe total light curve is computed from\n\\begin{eqnarray}\n\\frac{F}{F_0} &=& \\frac{1}{F_0}\\sum_{n=0}^N d_n S_n,\\\\\nF_0 &=& \\pi(d_0+ \\tfrac{2}{3} d_1),\n\\end{eqnarray}\nwhere $F_0$ is the unobscured flux, $S_0$ is given for uniform limb-darkening\nin section \\ref{eq:uniform}, $S_1=s_2$ is given by the linear limb-darkened\nsolution from section \\ref{sec:reparam}, and  $S_n = \\mathcal{Q}(\\bvec{G}_n)\n- \\mathcal{P}(\\bvec{G}_n)$ for $n \\ge 2$.\n\nWe note that the unobscured flux for each basis function (for $b \\ge 1+r$ or $r=0$) is zero for\nall $S_n(r,b)$ with $n \\ge 2$, which is why the total unobscured flux,\n$F_0$, only depends upon $d_0$ and $d_1$.\n\n\\subsection{Analytic derivatives}\n\nFor computing the derivatives of $\\mathcal{P}(\\bvec{G}_n)$, we find it more numerically\nstable to express the $k^{2i}$ terms in terms of $b$ and $r$.  For compactness, we define\n\\begin{eqnarray}\nT_i &=&  \\binom{n_0}{i}(-4br)^{n_0-i}(1-(b-r)^2)^{i},\\\\\nU_i &=&  \\left[(r-b)\\mathcal{I}_{n_0-i} + 2b \\mathcal{I}_{n_0-i+1}\\right],\\\\\nV_i &=&  \\left[(r-b)\\mathcal{J}_{n_0-i} + 2b \\mathcal{J}_{n_0-i+1}\\right],\n\\end{eqnarray}\nso that we can rewrite the primitive integral as\n\\begin{eqnarray}\n\\mathcal{P}(\\mathbf{G}_n) &=& 2r \\sum_{i=0}^{n_0} T_i U_i\\\\\n&=& \\mathcal{F} \\sum_{i=0}^{n_0} T_i V_i,\n\\end{eqnarray}\nwhere the first line is for even $n$ and the second for odd $n \\ge 3$.\n\nWe then express the derivatives as\n\\begin{eqnarray}\n\\frac{d \\mathcal{P}}{d r} = \\frac{\\partial \\mathcal{P}}{\\partial r}  +  \\frac{\\partial \\mathcal{P}}{\\partial k} \\frac{\\partial k}{\\partial r},\\\\\n\\frac{d \\mathcal{P}}{d b} = \\frac{\\partial \\mathcal{P}}{\\partial b}  +  \\frac{\\partial \\mathcal{P}}{\\partial k} \\frac{\\partial k}{\\partial b}.\n\\end{eqnarray}\n\nThen, these partial derivatives are given by:\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{P}}{\\partial r}  &=& 2r\\sum_{i=0}^{n_0} T_i  \\left[\\left(\\frac{2i(b-r)}{1-(b-r)^2} + \\frac{n_0+1-i}{r}\\right) U_i + \\mathcal{I}_{n_0-i}\\right],\\\\\n\\frac{\\partial \\mathcal{P}}{\\partial b}  &=& 2r\\sum_{i=0}^{n_0} T_i  \\left[\\left(\\frac{2i(r-b)}{1-(b-r)^2} + \\frac{n_0-i}{b}\\right) U_i - \\mathcal{I}_{n_0-i} + 2\\mathcal{I}_{n_0-i+1}\\right],\\\\\n\\frac{\\partial \\mathcal{P}}{\\partial k}  &=& 0,\n\\end{eqnarray}\nfor even $n$ and\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{P}}{\\partial r}  &=& \\mathcal{F}\\sum_{i=0}^{n_0} T_i \\left[\\left(\\frac{(2i+3)(b-r)}{1-(b-r)^2} + \\frac{n_0+1-i}{b}\\right) V_i + \\mathcal{J}_{n_0-i}\\right],\\\\\n\\frac{\\partial \\mathcal{P}}{\\partial b}  &=& \\mathcal{F}\\sum_{i=0}^{n_0} T_i \\left[\\left(\\frac{(2i+3)(r-b)}{1-(b-r)^2} + \\frac{n_0-i}{b}\\right) V_i - \\mathcal{J}_{n_0-i} + 2\\mathcal{J}_{n_0-i+1}\\right],\\\\\n\\frac{\\partial \\mathcal{P}}{\\partial k}  &=& \\mathcal{F}\\sum_{i=0}^{n_0} T_i \\left[(r-b) \\frac{\\partial\\mathcal{J}_{n_0-i}}{\\partial k} + 2b \\frac{\\partial \\mathcal{J}_{n_0-i+1}}{\\partial k}\\right],\n\\end{eqnarray}\nfor odd $n \\ge 3$.\n\nThe partial derivatives of $k$ are given by\n\\begin{eqnarray}\n\\frac{\\partial k}{\\partial r} &=& \\frac{b^2-r^2-1}{8 k b r^2},\\\\\n\\frac{\\partial k}{\\partial b} &=& \\frac{r^2-b^2-1}{8 k b^2 r}.\n\\end{eqnarray}\n\nFinally, we need the derivatives of the function $\\mathcal{I}_v$ and $\\mathcal{J}_v$\nwith respect to $k$.  This is given by recursion relations\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{J}_v}{\\partial k} &=& -3 k^{-1} \\mathcal{J}_v +k^2 \\frac{\\partial \\mathcal{J}_{v-1}}{\\partial k},\\\\\n&=& 3 k^{2v} \\int_0^1 u^{v+\\tfrac{1}{2}} (1-u)^{1/2} (1-k^2u)^{-1/2}du,\\\\\n&=& 3 k^{2v} \\frac{\\sqrt{\\pi}}{2} \\Gamma(v+\\tfrac{3}{2}) \\,_2{\\tilde F}_1(\\tfrac{1}{2},v+\\tfrac{3}{2},3+v,k^2),\\\\\n\\frac{\\partial \\mathcal{J}_0}{\\partial k} &=& \\frac{2}{k^4}\\left[(2-k^2)E(k^2)+2(k^2-1)K(k^2)\\right],\n\\end{eqnarray}\nfor $k^2 < 1$ ($b+r > 1$) and an expression for $I_v$\n\\begin{equation}\n\\frac{\\partial \\mathcal{I}_v}{\\partial k} = 2k^{2v} k_c^{-1}.\n\\end{equation}\n\nFor $k^2 > 1$ ($b+r <1$), we have\n\\begin{eqnarray}\n\\frac{\\partial \\mathcal{J}_0}{\\partial k} &=& k^{-3} \\left[2(2-k^2)E(k^{-2}) + 2(k^2-1) K(k^{-2})\\right]\\\\\n\\frac{\\partial \\mathcal{J}_v}{\\partial k} &=& (-1)^{v+1} \\frac{3k^{-3}\\pi^{3/2}}{\\Gamma(-(v+\\tfrac{1}{2}))} \\,_2\\tilde{F}_1(-\\tfrac{1}{2},v+\\tfrac{3}{2},v+2,k^{-2})\n\\end{eqnarray}\nwhile the same recursion relation applies for $\\partial \\mathcal{J}_v/\\partial k$ as in the $k^2 < 1$ case,\nand $d\\mathcal{I}_v/dk = 0$.\n\nAs with \\starry, we find that upward recursion in $v$ is more stable for $\\tfrac{1}{2} < k^2 < 2$,\nwhile downward recursion is more stable for $k^2 < \\tfrac{1}{2}$ and $k^2 > 2$.  This\nrequires computing the derivatives, $\\frac{\\partial \\mathcal{J}_v}{\\partial k}$, first\nfor large values of $v$. Rather than using the integral or Hypergeometric functions given\nabove, we accomplish this by differentiating each term the series expansion for\n$\\mathcal{J}_v$ with respect to $k$.  This is given by\n\\begin{equation}\n    \\label{eq:Jlargek}\n\\frac{\\partial \\mathcal{J}_v}{\\partial k}\n=             \\pi \\sum_{j=0}^\\infty (-1)^j \\binom{3/2}{j} \\frac{(2j+2v-1)!!}{2^{j+v} (j+v)!} (-2j)k^{-2j-1}.\n\\end{equation}\n\nWith the computation of $S_n = -\\mathcal{P}(\\bvec{G}_n)$ for $n \\ge 2$, we then\ncompute the derivatives of the light curve as\n\\begin{eqnarray}\n\\frac{\\partial S_n}{\\partial r} &= & -\\frac{\\partial \\mathcal{P}(\\bvec{G}_n)}{\\partial r},\\\\\n\\frac{\\partial S_n}{\\partial b} &= & -\\frac{\\partial \\mathcal{P}(\\bvec{G}_n)}{\\partial b},\n\\end{eqnarray}\nfor $n \\ge 2$, while the $n=0$ and $n=1$ terms must be handled separately as in\nsection \\ref{sec:reparam}.\n\nThe light curve derivatives are then computed as\n\\begin{eqnarray}\n\\frac{\\partial F/F_0}{\\partial r} &=& \\sum_{n=0}^N\\frac{ d_n}{F_0} \\frac{\\partial S_n}{\\partial r},\\\\\n\\frac{\\partial F/F_0}{\\partial b} &=& \\sum_{n=0}^N\\frac{ d_n}{F_0} \\frac{\\partial S_n}{\\partial b},\\\\\n\\frac{\\partial F/F_0}{\\partial d_0} &=&  -\\frac{\\pi F}{F_0^2} + \\frac{S_0}{F_0},\\\\\n\\frac{\\partial F/F_0}{\\partial d_1} &=&  -\\frac{2\\pi F}{3F_0^2} +\\frac{S_1}{F_0},\\\\\n\\frac{\\partial F/F_0}{\\partial d_n} &=&  \\frac{S_n}{F_0},\n\\end{eqnarray}\nwhere the last line is for $n \\ge 2$.\n\nThe derivatives of the coefficients, $\\frac{\\partial u_i}{\\partial d_j}$, are\ncomputed by differentiating each term, and propagating the derivatives via the\nchain rule.  Then, the light curve derivatives are given by\n\\begin{eqnarray}\n\\frac{\\partial F/F_0}{\\partial u_i} =  \\sum_{j} \\frac{\\partial F/F_0}{\\partial d_j}\\frac{\\partial d_j}{\\partial u_i}.\n\\end{eqnarray}\n\n\\section{Benchmarking}\\label{sec:benchmark}\n\nWe have measured the performance of the limb-darkened light curves\nwith derivatives as a function of the number of computed data points\nand as a function of the number of limb-darkening coefficients.  We\nhave computed the timing for $r=0.1$ and for a number of impact\nparameters ranging from $10^2$ to $10^6$, and the number of limb-darkening\ncoefficients ranging from $1$ to $89$.  For each set of timing benchmark\nparameters, we carried out nine measurements  of the timing, and\nwe use the median of these for plotting purposes.  The benchmarking\nfor the \\texttt{Julia} code was carried out with \\texttt{v0.7} of\nJulia on a MacBook Pro with 2.8 GHz Intel Core i7.\nNo sub-sampling was carried out in this computation.\n\nFigure \\ref{fig:ncoeff} shows that the time dependence is linear with the\nnumber of $b$ values (which is equivalent to the number of data points\nin the light curve).  The linear scaling with time holds for each value of\nthe number of limb-darkening coefficients.\n\nFigure \\ref{fig:nlimb} shows that the time dependence scales approximately\nas $n^{1/3-3/8}$.  As with the number of light-curve points, we have taken\nthe median over nine measurements for each set of parameters.  We then\nscaled the timing to the single-coefficient case, and took a second\nmedian over the number of light curve points as the cube-root scaling scales\nabout the same with different numbers of points in the light curve.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/benchmark_transit_poly.pdf}\n    \\caption{Scaling of the computation time in seconds with the number of\n    data points in the light curve for $r=0.1$ with $b$ ranging from $0$ to $1.2$.}\n    \\label{fig:ncoeff}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/benchmark_limbdark_timing.pdf}\n    \\caption{Scaling of the computation time with the number of\n    limb-darkening coeffients.  The $y$-axis scales the timing with respect\n    to the timing for a single limb-darkening coefficient.}\n    \\label{fig:nlimb}\n    \\end{centering}\n\\end{figure}\n\n\\section{Non-linear limb-darkening}\n\n\\citet{Claret2000} introduced a ``non-linear\" limb-darkening model which\nhe found to be an effective model for describing the limb-darkening functions\nwhich are produced by models of stellar atmospheres.\nAlthough we can only model limb-darkening which is integer powers of $\\upmu$,\nwe can use the polynomial model as an alternative limb-darkening model.\n\n\\begin{itemize}\n\\item Compare polynomial models to non-linear light curves. [x]\n\\item Fit polynomial model to stellar limb-darkening models.\n\\end{itemize}\n\nWe have computed an example non-linear light curve with $r=0.1$ and\n$c_1=c_2=c_3=c_4=0.2$, and then fit it with successive orders of the\npolynomial approximation.  The model we compute with a ``layer-cake\"\nmodel in which sums of layers of surface brightness with different\nradii are added together to approximate the lightcurve;  this\nis the approach taken in the numerical model used to compute the\nnon-linear limb-darkening light curves in the code of \\citet{MandelAgol2002},\nand it is also the approach taken by \\citet{Kreidberg2015} for\ncomputing models with arbitrary limb-darkening profiles.\n\nWe find that the fit improves steadily up until $N=6$ (a sextic\npolynomial), while beyond sextic, the RMS improves impercetibly.\nThe RMS of the sextic fit for this example is $<5 \\times 10^{-7}$\nrelative to a depth of transit of about 1.4\\% (Figure \\ref{fig:nonlinear}).\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/occult_nonlinear_poly.pdf}\n    \\caption{Comparison of the non-linear limb-darkening with polynomial\n    fits of various orders.  The maximum deviation ceases to improve\n    beyond a sextic fit.}\n    \\label{fig:nonlinear}\n    \\end{centering}\n\\end{figure}\n\nSince the non-linear model is just an effective model of stellar\natmospheres, we next turn to fitting the non-linear model to\ncomputed stellar atmospheres, and comparing these fits with\npolynomial limb-darkening to different orders.\n\n\\citet{Claret2018} discusses a precise means for fitting limb-darkening\nmodels to spherically-symmetric models for stellar atmospheres.  The\nstellar surface brightness drops rapidly from a finite value to zero surface\nbrightness over a few scale heights of the stellar atmosphere.\nThe scale height of an atmosphere is small compared with the size of a star,\nand so the limb-darkening model can treat the radius of the star as a\nfree parameter, and then treat the drop in surface brightness as a step-\nfunction near the limb of the star.  This gives a more precise model\nfor the limb-darkening, and \\citet{Claret2018} finds good precision\nusing the non-linear limb-darkening model.\n\nWe used the same set of atmospheres as \\citet{Claret2018}, but fit these\nwith the polynomial model, varying the order of the polynomial until the\nfit no longer improves. TBD\n\n\\section{Examples}\n\nGive some examples of the usage: non-linear optimization, HMC.\n\n\\section{Comparison with other work} \\label{sec:comparison}\n\nIn this section we compare our computations with existing code in terms\nof accuracy and speed.\n\n\\subsection{Comparison with Mandel \\& Agol}\n\nFor uniform, linear or quadratic limb-darkening, the widely used computation\nby \\citet{MandelAgol2002} has been improved in speed by utilizing the\n\\citet{Bulirsch1965a,Bulirsch1965b} expressions for the complete elliptic\nintegral of the third kind which is needed for the linear case, as implemented\nin the \\texttt{EXOFAST} routines \\citep{Eastman2013}.\n\nWe have carried out a numerical comparison of the \\citet{MandelAgol2002}\nfor the linear case ($u_1=1$), and find that the most severe errors\noccur for $b = r \\pm \\epsilon$.  Figure \\ref{fig:compareMA} shows\nthe computed models and the errors as a function of $r$ for $b=1-r-\\epsilon$\nand $b=r-\\epsilon$, with $\\epsilon = 10^{-12}$ (the results look very\nsimilar with $+\\epsilon$, so we have only plotted one case for clarity).\nIn the $b\\approx 1-r$ case (near second and third contacts), the errors\nare larger than our new expression, reaching $\\approx 10^{-10}$ for\n$r = 1$.  However, the errors become much more severe in the $b \\approx r$\ncase.  For $b=r \\pm 10^{-12}$, the errors grow to $10^{-4}$, and continue\nto grow as $b$ gets closer to $r$.  No such instability occurs for\nour new expressions, demonstrating their utility in all regions of\nparameter space.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/compare_MA2002.pdf}\n    \\caption{Comparison of Mandel \\& Agol (2002) with Agol \\& Luger (2018).}\n    \\label{fig:compareMA}\n    \\end{centering}\n\\end{figure}\n\n\\subsection{Derivative comparison with P\\'al}\n\nWe have computed the quadratic limb-darkened light curve using the \\texttt{F77}\ncode written by Andr\\'as P\\'al, \\texttt{ntiq\\_fortran.f}.\nFigure \\ref{fig:Pal_comparison} shows the results of this comparison.\nThe light curve models agree quite well, as do the derivatives, which is\na good check on both codes.  However, we find that the P\\'al model only\nachieves single precision for the computation, with errors reaching as\nmuch as a few $\\times 10^{-8}$ for the flux and the derivatives with\nrespect to the limb-darkening parameters.  \\citet{Pal2008} uses the\nCarlson implementation of elliptic integrals \\citep{Carlson1979},\nwhich in practice we find can be both less precise and slower to\nevaluate than the \\citet{Bulirsch1965a} code for computing elliptic\nintegrals.\n\nWe have also compared the evaluation speed of our code with P\\'al's as well.\nWe compiled P\\'al's code using \\texttt{gfortrans -O3}, and found that\nthe computation of quadratic limb-darkened light curves and\nderivatives takes an average of 0.52 seconds to compute $10^6$ models,\nwhile the \\texttt{transit\\_poly\\_struct.jl} takes an average of 0.29 seconds,\ngiving our Julia code a 44\\% speed advantage over the Fortran code;\nwe have yet to optimize all aspects of the code, so there may be room\nfor improvement on this benchmark.\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/julia/compare_pal.pdf}\n    \\caption{Comparison of \\citet{Pal2008} with Agol \\& Luger (2018).  The\n    coefficients are $u_1=0.2$ and $u_2=0.3$.}\n    \\label{fig:Pal_comparison}\n    \\end{centering}\n\\end{figure}\n\n\\subsection{Comparison to batman}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/compare_to_batman.pdf}\n    \\caption{Comparison of \\citet{Kreidberg2015} with Agol \\& Luger (2018) for\n             a transit across a quadratically limb-darkened star.}\n    \\label{fig:batman_comparison}\n    \\end{centering}\n\\end{figure}\n\n\\begin{figure}\n    \\begin{centering}\n    \\includegraphics[width=\\linewidth]{figures/python/compare_to_batman_nonlinear.pdf}\n    \\caption{Comparison of \\citet{Kreidberg2015} with Agol \\& Luger (2018) for\n             a transit across a nonlinearly limb-darkened star.}\n    \\label{fig:batman_nonlinear_comparison}\n    \\end{centering}\n\\end{figure}\n\n\\begin{itemize}\n\\item Compare with Gimenez for speed and accuracy for higher order limb-darkening. [ ]\n\\item Compare with Batman for speed and accuracy. [ ]\n\\item Compare derivatives with Pal for speed and accuracy. [x]\n\\item Show the scaling with the number of points in the light curve\nand with the number of limb-darkening components. [x]\n\\end{itemize}\n\n\\section{Discussion}\n\nWe have presented formulae for the transit (or occultation/eclipse) of a\nlimb-darkened body with a limb-darkening profile which is given by a polynomial\nin $\\upmu$.  These formulae have multiple assumptions built in:  both bodies\nare treated as spherical \\citep{Seager2002,Hui2002}, so that their projected\nsufaces are assumed to be circular \\citep{Barnes2003,Barnes2004,Barnes2009b};  limb-\ndarkening is treated as azimuthally-symmetric \\citep{Barnes2009a}; refraction\nand any relativistic effects are ignored \\citep{Sidis2010}; the edges of both\nbodies are assumed to have a sharp boundary.\nAll of these assumptions are violated in every transit event to some extent,\nbut in many cases can yield an adequate approximation given a particular\nsignal-to-noise ratio.\n\nHowever, any model for the surface brightness of a star can only be approximate:\nmost stars are convective, rotationally-oblate, spotted, oscillating, flaring,\netc.  The model we have presented, then, will only resemble any given star to\na precision which is limited by the lack of uniformity of the actual stellar\nsurface.  This begs the question of why a numerically precise model is required\nfor modelling transit light curves.  The answer is computational accuracy\nand stability: this more accurate model can be used over all of parameter space,\nand the high precision enables computation of derivatives which are beneficial\nwhen optimizing model parameters, computing the Fisher information matrix, or\nderiving parameter posteriors with MCMC.\n\nSince we are limited in the knowledge of the properties of any given star,\nthe discrepancies of an azimuthally-symmetric limb-darkened model can be\ntreated as a source of noise.\nThe deviation of the star from the model can be absorbed into noise models that\naccount for outliers, account for correlations in the noise, or actually\ntry to model the deviations of the star from azimuthal symmetry\n\\citep[e.g.][]{SanchisOjeda2011}.\n\nIn additional to the variability and inhomogeneity of stars, the limb-darkening model\ncan only describe the variation of surface brightness with a limited accuracy.\nOur analytic model can be thought of as a Taylor series with which the\nlimb-darkening can be expanded to as high an order as the data require.\nIn fact, for planetary transits in which $r$ is small, an arbitrary limb-darkening\nmodel could be treated as a Taylor series about the location of the planet,\nusing the analytic formulae to compute an approximate light curve.  This\nwould require varying the polynomial limb-darkening coefficients as the\nplanet moved across the disk of the star, which would need to be propagated\nthrough the derivatives properly.  Such a model could be a faster, and\nperhaps, more accurate way to treat arbitrary limb-darkening laws, such\nas ``non-linear\" limb-darkening \\citep{Claret2000} or power-law limb-darkening\n\\citep{Maxted2018}.\n\nOne question is what order of the limb-darkening model to choose to\nfit the data?  Here we suggest several possibile solutions.  The order of the\nlimb-darkening can be varied until the chi-square no longer improves (subject\nto a penalty for the greater freedom in the model, such as Bayesian Information\nCriterion).  A high-order limb-darkening model can be chosen, with the\ncoefficients regularized to favor small values;  should the data require\na higher-order model, then the coefficients will increase to acommodate\nthe data.  The parameterization of the limb-darkening with terms with\n$d_n ((n+2)\\upmu^n-\\upmu^{n-2})$ for $n \\ge 2$ may be particularly\nconvenient for this model in that these terms do not contribute to the\ntotal flux of the star.  A third possibility is to fit stellar atmosphere\nmodels with the polynomial limb-darkening model until a sufficient precision\nis reached given that warranted by the data, and then to place priors\non the limb-darkening parameters.\n\nExample applications:\n\\begin{enumerate}\n\\item optimization with and without analytic derivatives;\n\\item fitting to stellar limb-darkening models;\n\\item time integrated model with derivatives;\n\\item HMC.\n\\end{enumerate}\n\nThe detection of transit-timing variations with low-amplitude sinusoidal\nvariations can make use of the fact that small variations in transit time\ncan be expanded as a Taylor series to linear order so that perturbations\nin the transit time are the sum of a periodic component and a constant\ntimes the derivative of the limb-darkened light curve \\citep{Ofir2018}.\nThis approach requires derivatives of the light curve with respect to\ntime, for which the \\citet{MandelAgol2002} computation is too\nimprecise near the points of contact, $b \\approx r$ and $b \\approx 1-r$,\nwithin an impact parameter distance of $10^{-4}$, as shown by \\citet{Ofir2018}.\nThey extrapolated over these regions with polynomials.\nHowever, our new precise formulae, with derivatives, will be useful\nfor the perturbative approach to the detection of transit timing\nvariations, avoiding the numerical errors inherent in the \\citet{MandelAgol2002}\nmodel.\n\n\\section{Conclusions}\n\nWe have presented an analytic model for the transits, occultations, and\neclipses of limb-darkened bodies with a polynomial dependence of the limb-darkening\non the $z$ component of the stellar surface (or, alternatively, the\ncosine of the angle from the sub-stellar point).  The model is more precise\nand accurate than prior models that we have compared to, especially in near\nspecial limits such as the points of contact and the coincidence of the edge\nof the occultor with the center of the source.  The model also compares favorably in\nspeed of evaluation, about a factor of two faster than the code due\nto \\citet{Pal2008}, XXX faster than Gimenez, YYY faster than batman,\nand ZZZ faster than ExoFast.\n\nWe expect that this code may be used both as a workhorse model for\ngeneral fitting of transit models, as well as a tool for more\nspecialized applications, such as photodynamical modeling of\ninteracting planets, triple stars, and transiting circumbinary planets.\n{\\color{red} Add references for these use cases.}\n\nThe code is open source, and has two versions:  one of which is a part\nof the \\starry package, \\texttt{http://github.com/luger/starry/}, written\nin a combination of C++ and Python, and a new code written in Julia as\npart of the development of the equations in this paper,\n\\texttt{http://github.com/luger/limbdark/}.\n\n\\acknowledgements\n\nWe thank Andr\\'as P\\'al for sharing his Fortran code, \\texttt{ntiq-fortran.f}.\nWe thank Andr\\'as P\\'al, Kevin Stevenson, Kai Ueltzh\\\"offer, Mario Damasso,\nMatthew Heising, Robert Morehead, and Laura Kreidberg for pointing out\nerrors or inaccuracies in the Mandel \\& Agol paper and code, which we have\nhopefully rectified in this paper.\nE.A. acknowledges NSF grant AST-1615315, NASA grant NNX14AK26G and from\nthe NASA Astrobiology Institute's Virtual Planetary Laboratory Lead Team,\nfunded through the NASA Astrobiology Institute under solicitation NNH12ZDA002C\nand Cooperative Agreement Number NNA13AA93A.\n\n\\bibliography{limbdark}\n\n\\appendix\n\nHere are a list of errata for \\citet{MandelAgol2002}:\n\\begin{enumerate}\n\\item In equation 7, $\\lambda_3$ and $\\lambda_4$ should have $2k \\rightarrow\n2p$ in arguments of the elliptic integrals.\n\n\\item In equation 7, $\\lambda_5$ should have $- \\frac{2}{3}\\Theta(p-1/2)$\nat the end.\n\n\\item For Case 11 in Table 1, $\\eta^d$ should be 1/2, not 1, and\n$\\lambda^d$ should be zero, not 1.  This mistake affects the code,\nbut it is never encountered for planets that transit main-sequence\nstars since $p<1$.  This typo was discussed in \\citet{Eastman2013}.\n\n\\item The case $z=1-p$ is missing for $z<p$ (as pointed out by\nPal 2008).\n\n\\item There is a $\\pi$ missing in the denominator of the second term\non the right hand side of equation (8).\n\\end{enumerate}\n\nWith the exception of 3, none of these errors affected the publicly\navailable code.\n\\end{document}\n", "meta": {"hexsha": "80ab80902643e66162ca18d4ec9914dd899022f0", "size": 69293, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/limbdark.tex", "max_stars_repo_name": "tagordon/limbdark", "max_stars_repo_head_hexsha": "275ba17a767c585461515ea0d25dd9546032f3b2", "max_stars_repo_licenses": ["MIT"], "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/limbdark.tex", "max_issues_repo_name": "tagordon/limbdark", "max_issues_repo_head_hexsha": "275ba17a767c585461515ea0d25dd9546032f3b2", "max_issues_repo_licenses": ["MIT"], "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/limbdark.tex", "max_forks_repo_name": "tagordon/limbdark", "max_forks_repo_head_hexsha": "275ba17a767c585461515ea0d25dd9546032f3b2", "max_forks_repo_licenses": ["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.4227812718, "max_line_length": 204, "alphanum_fraction": 0.6899975466, "num_tokens": 21535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6210228696338955}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Analysis of variance}\\label{sec:anova}\n\nAnalysis of variance is a method for testing hypotheses about means by looking at sample variances.\n\n\\bigskip\nLet $Y$ be a continuous variable, let $X\\in\\{1,2,\\ldots,k\\}$ be a simple random variable representing \\emph{group membership}, and consider the location model\n\\[\nY = \\expe(Y|X=i) + \\epsilon \\qquad\\text{where $\\epsilon\\sim N(0,\\sigma^2)$.}\n\\]\nLet $\\mu = \\expe(Y)$ and $\\mu_i = \\expe(Y|X=i)$. We wish to test the null hypothesis that the conditional means $\\mu_i$ are all equal against the alternative hypothesis that they are not.\n%\\[\n%H_0:\\mu_1=\\mu_2=\\ldots=\\mu_k\n%\\qquad\\text{against}\\qquad\n%H_1:\\mu_i\\neq\\mu_j \\text{ for some $i\\neq j$}.\n%\\]\n\\begin{align*}\n& H_0:\\mu_1=\\mu_2=\\ldots=\\mu_k \\\\\n& H_1:\\mu_i\\neq\\mu_j \\text{ for some $i\\neq j$}.\n\\end{align*}\n\n%-----------------------\n\\subsection{Partition of variance}\n\nGiven that $X=i$ we have $Y\\sim N(\\mu_i,\\sigma^2)$ so\n\\[\n\\expe(Y|X=i) = \\mu_i \\quad\\text{and}\\quad \\var(Y|X=i) = \\sigma^2.\n\\]\nHence\n\\[\n\\var\\big[\\expe(Y|X)] = \\sum_{i=1}^k (\\mu_i-\\mu)^2\\prob(X=i) \\quad\\text{and}\\quad \\expe[\\var(Y|X)\\big] = \\sigma^2.\n\\]\nBy the law of total variance, \n\\begin{align*}\n\\var(Y)\t& = \\expe\\big[\\var(Y|X)\\big] + \\var\\big[\\expe(Y|X)\\big] \\\\\n\t\t& = \\sigma^2 + \\sum_{i=1}^k (\\mu_i-\\mu)^2\\prob(X=i).\n\\end{align*}\n\nThus we have divided the variance of $Y$ into two components,\n\\bit\n\\it an \\emph{explained} component $\\sum_{i=1}^k (\\mu_i-\\mu)^2\\prob(X=i)$ due to variation \\emph{between} groups;\n\\it an \\emph{unexplained} component $\\sigma^2$ due to variation \\emph{within} groups.\n\\eit\n%\\bit\n%\\it If $H_0$ is true, $\\var(Y)=\\sigma^2$. \n%\\it If $H_0$ is false, $\\var(Y) > \\sigma^2$.\n%\\eit\n\n%-----------------------\n\\subsection{Test statistics}\n\n% data\nSuppose we obtain independent random samples from each group.\n\\bit\n\\it $Y_{11},Y_{12},\\ldots,Y_{1n_1}$ where $Y_{1j}\\sim N(\\mu_1,\\sigma^2)$,\n\\it $Y_{21},Y_{22},\\ldots,Y_{2n_2}$ where $Y_{2j}\\sim N(\\mu_2,\\sigma^2)$,\n\\it[] $\\ldots$\n\\it $Y_{k1}, Y_{k2}, \\ldots, Y_{kn_k}$ where $Y_{kj}\\sim N(\\mu_k,\\sigma^2)$.\n\\eit\n\nLet $N=\\sum_{i=1}^k n_i$ be the total number of observations. We estimate the overall mean $\\mu$ and the individual group means $\\mu_i$ by the sample means\n\\[\n\\hat{\\mu} = \\displaystyle\\frac{1}{N}\\sum_{i=1}^k\\sum_{j=1}^{n_i} Y_{ij}\n\\quad\\text{and}\\quad\n\\hat{\\mu}_i = \\displaystyle\\frac{1}{n_i}\\sum_{j=1}^{n_i} Y_{ij}\n\\quad\\text{respectively.}\n\\]\n\nConsider the sum of the squared differences between the $Y_{ij}$ and the overall sample mean $\\hat{\\mu}$,\n\\begin{align*}\n\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu})^2\n\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i + \\hat{\\mu}_i-\\hat{\\mu})^2 \\\\\n\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} \\big[(Y_{ij}-\\hat{\\mu}_i)^2 + 2(Y_{ij}-\\hat{\\mu}_i)(\\hat{\\mu}_i-\\hat{\\mu}) + (\\hat{\\mu}_i-\\hat{\\mu})^2\\big] \\\\\n%\t& = \\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2 + 2(\\sum_{j=1}^{n_i}Y_{ij}-n_i\\hat{\\mu}_i)(\\hat{\\mu}_i-\\hat{\\mu}) + \\sum_{j=1}^{n_i}(\\hat{\\mu}_i - \\hat{\\mu})^2 \\\\\n\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2 + \\sum_{i=1}^k n_i(\\hat{\\mu}_i-\\hat{\\mu})^2 \\\\\n\\end{align*}\n\nWe write this as $SST = SSE + SSG$ where\n\\[\n\\begin{array}{lll}\nSST\t& = \\displaystyle\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu})^2\n\\qquad\\qquad & \\text{is the \\textbf{total sum-of-squares,}} \\\\\nSSE\t& = \\displaystyle\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2\n\\qquad & \\text{is the \\textbf{error sum-of-squares} (due to variation within groups),} \\\\\nSSG\t& = \\displaystyle\\sum_{i=1}^k n_i (\\hat{\\mu}_i-\\hat{\\mu})^2\n\\qquad & \\text{is the \\textbf{groups sum-of-squares} (due to variation between groups).} \\\\\n\\end{array}\n\\]\n\n%If the ratio $SSG/SSE$ is large, we might be inclined to reject the null hypothesis that all group means are equal.\n%\n%Thus\n%\\begin{align*}\n%\\sum_{i=1}^k\\sum_{j=1}^{n_i} \\left(\\frac{Y_{ij}-\\hat{\\mu}}{\\sigma})^2\n%\t& = \\sum_{i=1}^k\\sum_{j=1}^{n_i} \\left(\\frac{Y_{ij}-\\hat{\\mu}_i}{\\sigma}\\right)^2 + \\sum_{i=1}^k n_i\\left(\\frac{\\hat{\\mu}_i-\\hat{\\mu}}{\\sigma}\\right)^2 \\\\\n%\\end{align*}\n\n% lemma: combined\n\\begin{lemma}\nThe error sum-of-squares and groups sum-of-squares both have $\\chi^2$-distribution:\n\\[\\begin{array}{ll}\n\\displaystyle\\frac{1}{\\sigma}\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2 \n\t& \\sim \\chi^2_{N-k} \\\\[2ex]\n\\displaystyle\\frac{1}{\\sigma}\\sum_{i=1}^k n_i (\\hat{\\mu}_i-\\hat{\\mu})^2\t\n\t& \\sim \\chi^2_{k-1}(\\lambda)\\text{ where }\\lambda = \\displaystyle\\sum_{i=1}^k n_i(\\mu_i-\\mu)^2.\n\\end{array}\\]\n%\\begin{align*}\n%\\frac{1}{\\sigma}\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2 \n%\t& \\sim \\chi^2_{N-k} \\\\\n%\\frac{1}{\\sigma}\\sum_{i=1}^k n_i (\\hat{\\mu}_i-\\hat{\\mu})^2\t\n%\t& \\sim \\chi^2_{k-1}(\\lambda)\\text{ where }\\lambda = \\sum_{i=1}^k n_i(\\mu_i-\\mu)^2.\n%\\end{align*}\n%\\begin{align*}\n%\\frac{1}{\\sigma}SSE \t& \\sim \\chi^2_{N-k}. \\\\\n%\\frac{1}{\\sigma}SSG \t& \\sim \\chi^2_{k-1}(\\lambda)\\quad\\text{where}\\quad\\lambda = \\sum_{i=1}^k n_i(\\mu_i-\\mu)^2.\n%\\end{align*}\n\\end{lemma}\n%\\begin{lemma}\n%\\begin{align*}\n%\\sum_{i=1}^k\\sum_{j=1}^{n_i}\\left(\\frac{Y_{ij}-\\hat{\\mu}_i}{\\sigma}\\right)^2 \n%\t& \\sim \\chi^2_{N-k}. \\\\\n%\\sum_{i=1}^k n_i \\left(\\frac{\\hat{\\mu}_i-\\hat{\\mu}}{\\sigma}\\right)^2 \n%\t& \\sim \\chi^2_{k-1}(\\lambda)\\quad\\text{where}\\quad\\lambda = \\sum_{i=1}^k n_i(\\mu_i-\\mu)^2. \\\\\n%\\end{align*}\n%\\end{lemma}\n\\begin{proof}\n\\ben\n\\it % SSE\nBy independence, because $Y_{ij}\\sim N(\\mu_i,\\sigma^2)$ we have\n\\[\n\\sum_{j=1}^{n_i}\\left(\\frac{Y_{ij}-\\mu_i}{\\sigma}\\right)^2 \\sim \\chi^2_{n_i}.\n\\]\nReplacing the unknown expectation $\\mu_i$ by the sample mean $\\hat{\\mu}_i$, we obtain\n\\[\n\\frac{1}{\\sigma^2}\\sum_{j=1}^{n_i}(Y_{ij}-\\hat{\\mu}_i)^2 \\sim \\chi^2_{n_i-1}.\n\\]\nIf $U\\sim\\chi^2_m$ and $V\\sim\\chi^2_n$ then $U+V\\sim\\chi^2_{m+n}$, so\n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\sum_{j=1}^{n_i}(Y_{ij}-\\hat{\\mu})^2 \\sim \\chi^2_{N-k}.\n\\]\n\\it % SSG\nBecause $\\hat{\\mu_i}$ is a sample mean, we have $\\hat{\\mu}_i\\sim N(\\mu_i,\\sigma^2/n_i)$, so\n\\[ \n\\sqrt{n_i}\\left(\\frac{\\hat{\\mu}_i - \\mu}{\\sigma}\\right) \\sim N(\\mu_i-\\mu,1)\n\\]\nBecause all observations are independent, the sample means $\\hat{\\mu}_i$ are also independent so\n\\[\n\\sum_{i=1}^k n_i\\left(\\frac{\\bar{Y}_i - \\mu}{\\sigma}\\right)^2 \\sim \\chi^2_{k}(\\lambda) \n\\quad\\text{where}\\quad \\lambda = \\sum_{i=1}^k(\\mu_i-\\mu)^2.\n\\]\nFinally, replacing the unknown expectation $\\mu$ by the sample mean $\\hat{\\mu}$, we obtain \n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^k n_i (\\hat{\\mu}_i - \\hat{\\mu})^2 \\sim \\chi^2_{k-1}(\\lambda).\n\\]\n\\een\n\\end{proof}\n\n% theorem: test statistic\n\\begin{theorem}[Test Statistic for ANOVA]\nLet $F = s^2_G/s^2_E$ where\n\\[\ns^2_G = \\frac{1}{k-1}\\sum_{i=1}^k n_i (\\hat{\\mu}_i-\\hat{\\mu})^2\n\\quad\\text{and}\\quad\ns^2_E = \\frac{1}{N-k}\\sum_{i=1}^k\\sum_{j=1}^{n_i} (Y_{ij}-\\hat{\\mu}_i)^2.\n\\]\nThen $F\\sim F_{k-1,N-k}$ under $H_0:\\mu_1=\\mu_2=\\ldots=\\mu_k$.\n\\end{theorem}\n\n% remark\n\\begin{remark}\nUnder the alternative hypothesis we have $\\lambda>0$, in which case the $s^2_G$ is likely to be larger than it would be under the null hypothesis. Thus we require an upper-tail test: $H_0$ is rejected whenever $F > F_{\\alpha}$ where $F_{\\alpha}$ is the upper-tail critical value of the $F_{k-1,N-k}$ distribution at significance level $\\alpha$. \n\\end{remark}\n\nThe various statistics computed during a one-way analysis of variance are usually reported in tabular form:\n\\begin{center}\n\\begin{tabular}{|l|c|c|c|c|} \\hline\nSource \t& \\qquad df\\qquad\\mbox{}& \\qquad SS\\qquad\\mbox{}& \\qquad MS\\qquad\\mbox{}& \\qquad F\\qquad\\mbox{}\t\\\\ \\hline\nGroups\t& $k-1$\t\t\t\t\t& $SSG$\t\t\t\t\t& $s^2_G$\t\t\t\t& $F = s^2_G/s^2_E$\t\t\\\\ \\hline\nError \t& $N-k$\t\t\t\t\t& $SSE$\t\t\t\t\t& $s^2_E$\t\t\t\t&\t\t\t\t\t\t\\\\ \\hline\nTotal\t& $N-1$\t\t\t\t\t& $SST$\t\t\t\t\t& \t\t\t\t\t\t& \t\t\t\t\t\t\\\\ \\hline\n\\end{tabular}\\par\n\\end{center}\n\n\\begin{example}\nThe data below are the yields (per hectare) of eight types of wheat, recorded over four independent trials. \n\\[\n\\begin{array}{|c|cccc|}\\hline\n\\text{Type}\t& \\multicolumn{4}{c|}{\\text{Yield}} \\\\ \\hline\n1 &  182 & 214 & 216 & 231 \\\\\n2 &  196 & 202 & 208 & 224 \\\\\n3 &  203 & 212 & 221 & 242 \\\\\n4 &  198 & 203 & 207 & 222 \\\\\n5 &  171 & 192 & 197 & 204 \\\\\n6 &  194 & 218 & 223 & 232 \\\\\n7 &  208 & 216 & 218 & 239 \\\\\n8 &  183 & 188 & 193 & 198 \\\\ \\hline\n\\end{array}\n\\]\nPerform a one-way analysis-of-variance to determine whether there are significant differences among the mean yields of the eight types.\n\\end{example}\n\n\\begin{solution}\n%\\[\n%\\begin{array}{|c|cccc|r|r|}\\hline\n%\\text{Type} (i)\t& \\multicolumn{4}{c|}{\\text{Yield}} & \\sum_j X_{ij} &  \\sum_j X_{ij}^2 \\\\ \\hline\n%1 \t\t\t\t&  182 & 214 & 216 & 231 \t&  843 &  178937 \\\\\n%2 \t\t\t\t&  196 & 202 & 208 & 224 \t&  830 &  172660 \\\\\n%3 \t\t\t\t&  203 & 212 & 221 & 242 \t&  878 &  193558 \\\\\n%4 \t\t\t\t&  198 & 203 & 207 & 222 \t&  830 &  172546 \\\\\n%5 \t\t\t\t&  171 & 192 & 197 & 204 \t&  764 &  146530 \\\\\n%6 \t\t\t\t&  194 & 218 & 223 & 232 \t&  867 &  188713 \\\\\n%7 \t\t\t\t&  208 & 216 & 218 & 239 \t&  881 &  194565 \\\\\n%8 \t\t\t\t&  183 & 188 & 193 & 198 \t&  762 &  145286 \\\\ \\hline\n%\\text{Overall}\t&      &     &     &    \t\t& 6655 & 1392795 \\\\ \\hline\n%\\end{array}\n%\\]\nTedious calculations give the following sums-of-squares:\n\\[\nSST = 8762.97,\\quad SSG = 3848.72 \\text{\\quad and\\quad} SSE = 4914.25.\n\\]\n\n%The sums of squares are computed as follows:\n%\\begin{align*}\n%S_T\n%\t& = \\sum_{i=1}^k \\sum_{j=1}^{n_i} (X_{ij}-\\bar{X}_{\\cdot\\cdot})^2 \\\\\n%\t& = \\sum_{i=1}^k \\sum_{j=1}^{n_i} X_{ij}^2 - \\frac{1}{N}\\left(\\sum_{i=1}^k\\sum_{j=1}^{n_i} X_{ij}\\right)^2 \\\\\n%\t& = (182^2 + 214^2 + \\ldots + 762^2) - \\frac{6655^2}{32} \\\\\n%\t& = 1392795 - 1384032.03125 = 8762.96875 \\\\ \n%\\end{align*}\n%\n%\\begin{align*}\n%S_G\n%\t& = \\sum_{i=1}^k n_i(\\bar{X}_{i\\cdot}-\\bar{X}_{\\cdot\\cdot})^2 \\\\\n%\t& = \\sum_{i=1}^k \\frac{1}{n_i}\\left(\\sum_{j=1}^{n_i} X_{ij}\\right)^2 \n%\t\t\t- \\frac{1}{N}\\left(\\sum_{i=1}^k\\sum_{j=1}^{n_i} X_{ij}\\right)^2 \\\\\n%\t& \\left(\\frac{843^2}{4} + \\frac{830^2}{4} +\\ldots+ \\frac{762^2}{4}\\right) - \\frac{6655^2}{32} \\\\\n%\t& = 1387880.75 - 1384032.03125 = 3848.71875. \n%\\end{align*}\n%\\begin{align*}\n%S_E\n%\t& = \\sum_{i=1}^k \\sum_{j=1}^{n_i} (X_{ij}-\\bar{X}_{i\\cdot})^2  \\\\\n%\t& = \\sum_{i=1}^k \\sum_{j=1}^{n_i} X^2_{ij} - \\sum_{i=1}^k \\frac{1}{n_i}\\left(\\sum_{j=1}^{n_i} X_{ij}\\right)^2 \\\\ \n%\t& = (182^2 + 214^2 + \\ldots + 762^2) - \\left(\\frac{843^2}{4} + \\frac{830^2}{4} +\\ldots+ \\frac{762^2}{4}\\right) \\\\\n%\t& = 1392795 - 1387880.75 = 4914.25 \\\\\n%\\end{align*}\n%Check: $S_G + S_E = 3848.77 + 4914.20 = 8762.9 = S_0$.\n\nThe ANOVA table is:\n\\begin{center}\n\\begin{tabular}{|l|c|c|c|c|} \\hline\nSource\t& df\t& SS\t\t& MS\t\t& F \t\t\t\\\\ \\hline\nGroups\t& 7\t\t& 3848.72\t& 549.8170\t& 2.6852\t\t\\\\ \\hline\nError\t& 24\t& 4914.25\t& 204.7604 \t& \t\t\t\\\\ \\hline\nTotal\t& 31\t& 8762.97 \t& \t\t\t&\t\t\t\\\\ \\hline\n\\end{tabular}\\par\n\\end{center}\n\nFrom tables of the $F_{7,24}$ distribution, \n\\bit\n\\it The 95th percentile is $F_{0.05} = 2.42$.\n\\it The 99th percentile is $F_{0.01} = 3.50$.\n\\eit\nThe observed value of the test statistic lies between these two values: we would reject the null hypothesis at $\\alpha=0.05$, but not at $\\alpha=0.01$.\n\\end{solution}\n", "meta": {"hexsha": "4e9a9a5a356788cfc7057a637753eda4ac090f2e", "size": 10914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/11C_anova.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/11C_anova.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/11C_anova.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": 40.8764044944, "max_line_length": 345, "alphanum_fraction": 0.598314092, "num_tokens": 4816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6210228632873573}}
{"text": "\\section{Duality}\n\n\\subsection*{Theorem 1}\n$x = \\sum_{i=1}^{n} a_i x_i \\implies k_i(x) = a_i$.\n\n\\subsection{Exercise 1}\n$l_1, l_2 \\in Y^{\\perp} \\implies l_1(y) + l_2(y) = 0 = (l_1 + l_2)(y)$.\n\n\\subsection{Exercise 2}\n$\\forall \\xi \\in Y^{\\perp \\perp} \\implies \\forall l \\in Y^{\\perp}, \\: \\xi(l) = 0 = l(y) \\: \\forall y \\in Y$.\n\n", "meta": {"hexsha": "f4066bcab21018723430b42476f09bcf03307748", "size": 327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": 27.25, "max_line_length": 108, "alphanum_fraction": 0.5810397554, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6209497449681146}}
{"text": "\n\\subsection{The Liquidity preference - Money supply (LM) curve}\n\n\\subsubsection{Liquidity preference}\n\nMoney demand is:\n\n\\(L=L(i, Y)\\)\n\nAs income rises, demand for money rises.\n\nAs the nominal interest rate rises, the demand for money falls, due to the opportunity cost.\n\n\\subsubsection{Money supply}\n\nMoney supply is:\n\n\\(\\dfrac{M}{P}\\)\n\n\\subsubsection{The LM curve}\n\nIn equilibrium money supply and demand match. We have:\n\n\\(\\dfrac{M}{P}=L(i,Y)\\)\n\nWe can plot the level of output which corresponds to the nominal interest rate.\n\nThis is the LM curve.\n\n\\subsubsection{The slope of the LM curve}\n\n\n", "meta": {"hexsha": "63289b4e744f0fbfa51248f1f2bcc317eedadb65", "size": 598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/neoKeynesian/02-03-LM.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/neoKeynesian/02-03-LM.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/neoKeynesian/02-03-LM.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.1212121212, "max_line_length": 92, "alphanum_fraction": 0.7357859532, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6209474773859601}}
{"text": "\\subsection{Solution scheme}\n\n\\input{section3/procedure}\n\n\n\\subsection{Stability analysis}\n\\begin{frame}{Linear advection equation of an arbitrary quantity $q$}%{One-dimensional problems}\n  \\begin{block}{Scheme equation (finite difference sense)}\n    \\begin{footnotesize}\n      \\begin{equation*}\n        \\bar{q}^{p,n+1}=\\sum_{k=1}^{N_p}H_{pk}(\\vect{X}^p,\\vect{X}^k,\\text{CFL})\\bar{q}^{k,n}\n      \\end{equation*}\n    \\end{footnotesize}\n  \\end{block}\n  \\begin{block}{von-Neumann linear stability analysis}\n    \\begin{footnotesize}\n      The numerical scheme is stable if:\n      \\begin{equation*}\n        \\sum_{k=1}^{N_p}\\abs{H_{pk}} \\leq 1 \\quad \\forall p\n      \\end{equation*}\n      \\alert{$\\Rightarrow$ find the maximal CFL number ensuring the stability}\n    \\end{footnotesize}\n  \\end{block}\\pause\n  \\metroset{block=fill}\n  \\begin{footnotesize}\n    \\begin{block}{Particular case: one particle per cell}\n      The \\textbf{first-order} FVM is recovered $\\rightarrow$ CFL improved compared to MPM and DGFEM\n    \\end{block}\n  \\end{footnotesize}\n\\end{frame}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../presentation\"\n%%% End:\n", "meta": {"hexsha": "c6fefa013a58bae2d461985485563e9bc923d1c3", "size": 1135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "defense/section3/mainSection3.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": "defense/section3/mainSection3.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": "defense/section3/mainSection3.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": 30.6756756757, "max_line_length": 100, "alphanum_fraction": 0.6713656388, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289388125473628, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6209474602904246}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section*{Thu Nov 14 2019}\n\n\\subsection{Gauss-Seidel}\n\nWe can rewrite \\(\\sum _{j} A_{ij} x_{j} = b_i\\) as \n%\n\\begin{align}\n  x_{i} = \\frac{1}{A_{ii}} \\qty(b_{i} - \\sum _{j \\neq i} A_{ij}x_{j}) \n\\,,\n\\end{align}\n%\nand the algorithm works by starting with and \\emph{ansatz}, updating it with this formula, and iterating.\nThe update can be written more generally as \n%\n\\begin{align}\n    x_{i}^{n+1} = \\frac{\\omega }{A_{ii}} \\qty(b_{i} - \\sum _{j \\neq i} A_{ij}x_{j}^{n}) + (1-\\omega) x_{i}^{n} \n  \\,,\n  \\end{align}\n%\nwith the \\emph{relaxation parameter} \\(\\omega \\).\nDo note that \\(n\\) is not an exponent but an iteration number.\n\nA good choice for \\(\\omega \\) after the \\(5\\)th iteration: \n%\n\\begin{align}\n  \\omega _{\\text{opt}} = \\frac{2}{1 + \\sqrt{1- (\\Delta x^{k+p} / \\Delta x^{k})^{1/p}}}\n\\,,\n\\end{align}\n%\n\n\n\\end{document}", "meta": {"hexsha": "2386b144e58ca4a0df81cb6b974fc46653bdf696", "size": 877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/numerical_methods/14nov.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/numerical_methods/14nov.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/numerical_methods/14nov.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": 25.0571428571, "max_line_length": 111, "alphanum_fraction": 0.6168757127, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835534888481, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6209046581798305}}
{"text": "\\documentclass{report}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\begin{document}\n\\section{Joint Distribution}\n\\subsection{Abstract}\nIn this section, we study Gaussian joint distribution.\n\\subsection{Given}\n$$\nx \\backsim N(x|\\mu, \\Lambda^{-1})\n$$\n$$\ny|x \\backsim N(y|Ax+b, L^{-1})\n$$\n\\subsubsection{Inference}\n$$\ny = Ax+b+\\epsilon, \\quad \\epsilon \\backsim N(0, L^{-1}), \\quad x \\perp \\epsilon\n$$\n\\subsection{To solve}\n$$\n\\begin{cases}\np(y)\\\\\n\\\\\np(x|y)\n\\end{cases}\n$$\n\\subsection{Derivation}\n\\subsubsection{Derive $p(y)$}\n\n$$\nE[y] = A E[x] + b + E[\\epsilon]=A \\mu + b\n$$\n$$\nVar[y] = A \\Lambda^{-1} A^T\n$$\n$$\n\\therefore y \\backsim N(A\\mu +b, A\\Lambda^{-1} A^T)\n$$\n\\subsubsection{Derive $p(x|y)$}\n\\paragraph{Construct dist $z$\\\\}\nHere we construct a distribution:\n$$\nz = \n\\left (\n\\begin{matrix}\nx\\\\\ny\\\\\n\\end{matrix}\n\\right )\n\\backsim N(\n\\left [\n\\begin{matrix}\n\\mu\\\\\nA\\mu+b\\\\\n\\end{matrix}\n\\right ],\n\\left [\n\\begin{matrix}\n\\Lambda^{-1}&\\Delta\\\\\n\\Delta&A\\Lambda^{-1} A^T\\\\\n\\end{matrix}\n\\right ]\n)\n$$\n$$\n\\begin{aligned}\n\\Delta\n&=cov(x,y)\\\\\n&=E[(x-E[x])(y-E[y])^T]\\\\\n&=E[(x-\\mu)(y-A\\mu - b)^T]\\\\\n&=E[(x-\\mu)(Ax+b+ \\epsilon -A\\mu -b)^T)]\\\\\n&=E[(x-\\mu)(Ax-A\\mu + \\epsilon)^T]\\\\\n&=E[(x-\\mu)(x-\\mu)^T A^T + (x-\\mu)\\epsilon^T]\\\\\n&=E[(x-\\mu)(x-\\mu)^T]A^T + E[(x-\\mu)\\epsilon^T] \\\\\n\\because &x \\perp \\epsilon\\\\\n\\therefore &=E[(x-\\mu)(x-\\mu)^T]A^T\\\\\n&=\\Lambda^{-1}A^T\n\\end{aligned}\n$$\n$$\n\\therefore z=\n\\left ( \\begin{matrix}\nx\\\\y\n\\end{matrix} \\right )\n\\backsim N(\n\\left [\n\\begin{matrix}\n\\mu\\\\\nA\\mu+b\\\\\n\\end{matrix}\n\\right ],\n\\left [\n\\begin{matrix}\n\\Lambda^{-1}&\\Lambda^{-1}A^T\\\\\n\\Lambda^{-1}A^T&A\\Lambda^{-1} A^T\\\\\n\\end{matrix}\n\\right ]\n)\n$$\n\\paragraph{Construct dist $x.y$\\\\}\nlet's set \n$$\n\\begin{aligned}\nx.y \n&= x - \\Sigma_{xy} \\Sigma_{yy}^{-1}y\\\\\n&= x - (\\Lambda^{-1} A^T)(A \\Lambda^{-1}A^T)^{-1}y\\\\\n&= x - A^{-1}y\\\\\n&= \n\\left ( \\begin{matrix}\nI& -A^{-1}\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\nx\\\\\ny\n\\end{matrix} \\right )\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nE[x.y] \n&= E[x] - A^{-1} E[y]\\\\\n&= \\mu - A^{-1}(A\\mu+b)\\\\\n&= -A^{-1}b\n\\end{aligned}\n$$\n$$\n\\begin{aligned}\nVar[x.y]\n&= \n\\left ( \\begin{matrix}\nI& -A^{-1}\n\\end{matrix} \\right )\nVar[z]\n\\left ( \\begin{matrix}\nI\\\\\n-(A^{-1})^T\\\\\n\\end{matrix} \\right )\\\\\n&= \n\\left ( \\begin{matrix}\nI& -A^{-1}\n\\end{matrix} \\right )\n\\left (\n\\begin{matrix}\n\\Lambda^{-1}&\\Lambda^{-1}A^T\\\\\n\\Lambda^{-1}A^T&A\\Lambda^{-1} A^T\\\\\n\\end{matrix}\n\\right )\n\\left ( \\begin{matrix}\nI\\\\\n-(A^{-1})^T\\\\\n\\end{matrix} \\right )\\\\\n&=\n\\left ( \\begin{matrix}\n\\Lambda^{-1}-A^{-1} \\Lambda^{-1}A^T & 0\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\nI\\\\\n-(A^{-1})^T\\\\\n\\end{matrix} \\right )\\\\\n&=\\Lambda^{-1}-A^{-1} \\Lambda^{-1}A^T\n\\end{aligned}\n$$\n$$\n\\therefore x.y \\backsim N(-A^{-1}b, \\Lambda^{-1}-A^{-1} \\Lambda^{-1}A^T)\n$$\n\\paragraph{Construct $x|y$\\\\}\nwe got\n$$\nx|y = x.y + A^{-1}y\n$$\nhere, we can see $A^{-1}y$ as constant $C$.\\\\\\\\\nthen:\n$$\nx|y = x.y + C\n$$\n$$\nE[x|y] = A^{-1}y - A^{-1}b\n$$\n$$\nVar[x|y]= Var[x.y]\n$$\n$$\n\\therefore x|y \\backsim N(A^{-1}y - A^{-1}b, \\Lambda^{-1}-A^{-1} \\Lambda^{-1}A^T)\n$$\nNow, according to an edge distribution and conditional distribution, we construct a joint distribution to obtain another edge distribution and conditional distribution.\n\\end{document}", "meta": {"hexsha": "628f6482e3917b0bfd8c823f3d3619a4b1badcc9", "size": 3189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EN-TeX_files/Intro_Math/04_fundamentals-of-math_gaussian-distribution-joint_distribution.tex", "max_stars_repo_name": "btobab/Machine-Learning-notes", "max_stars_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-28T18:47:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T07:36:27.000Z", "max_issues_repo_path": "EN-TeX_files/Intro_Math/04_fundamentals-of-math_gaussian-distribution-joint_distribution.tex", "max_issues_repo_name": "btobab/Machine-Learning-notes", "max_issues_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "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": "EN-TeX_files/Intro_Math/04_fundamentals-of-math_gaussian-distribution-joint_distribution.tex", "max_forks_repo_name": "btobab/Machine-Learning-notes", "max_forks_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-28T18:47:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-28T18:47:22.000Z", "avg_line_length": 17.1451612903, "max_line_length": 168, "alphanum_fraction": 0.5644402634, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6209046395419515}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{bm}\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\\newcommand{\\uvec}[1]{\\boldsymbol{\\hat{\\textbf{#1}}}}\n\n\\title{Lecture 19: Vector Fields}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Definition of Vector Fields}\n\nA vector field can be described with such a formula:\n\\begin{equation*}\n  \\vec{F} = M \\uvec{\\i} + N \\uvec{\\j}\n\\end{equation*}\nwhere $M$ and $N$ are functions of coordinates.\n\nIn a vector field, at each point $(x, y)$ there is a corresponding vector. In \nother words, vectors in a vector field are a function of the position.\n\nReal world examples of a vector field:\n\\begin{itemize}\n  \\item Velocity field in fluid $\\vec{v}$.\n  \\item Force field $\\vec{F}$.\n\\end{itemize}\n\n\\section{Plot of Vector Fields}\n\nPlot of a vector field enables us to understand the vector field in a concrete \nway and probably provides some important insights.\n\n\\begin{example}\n  Plot the vector field $\\vec{F} = 2 \\uvec{\\i} + \\uvec{j}$.\n\n  TODO(jinxinwang): add the graph.\n\\end{example}\n\n\\begin{example}\n  Plot the vector field $\\vec{F} = x \\uvec{\\i}$.\n\n  TODO(jinxinwang): add the graph.\n\n  Notice that we usually use the length of arrows in the graph to relatively \n  indicate the magnitudes of vectors in a vector field.\n\\end{example}\n\n\\begin{example}\n  Plot the vector field $\\vec{F} = x \\uvec{\\i} + y \\uvec{\\j}$.\n\n  TODO(jinxinwang): add the graph.\n\\end{example}\n\n\\begin{example}\n  Plot the vector field $\\vec{F} = -y \\uvec{\\i} + x \\uvec{\\j}$.\n\n  TODO(jinxinwang): add the graph.\n\n  This is the vector field of the uniform rotation at unit angular velocity.\n\\end{example}\n\n\\begin{question}\n  Vectors in mathematics have no starting point. However, in vector fields each \n  vector is associated with a starting point. Is it contradictory with the \n  definition of vectors?\n\\end{question}\n\n\\section{Line Integrals}\n\n\\subsection{Definition of Line Integrals}\n\nThe motivation of introducing line integrals is to calculate the work done along \na trajectory in a force field.\n\nRecall from physics:\n\\begin{equation*}\n  W = \\vec{F} \\cdot \\Delta \\vec{r}\n\\end{equation*}\n\nFor a motion with changing force or curved trajectory, to calculate the total \nwork, we need to apply the idea of integrals. We can divide the trajectory into \nmany small pieces, with each piece as $\\Delta \\vec{r}$. For a piece of small \ntrajectory $\\Delta \\vec{r}_i$, the work is\n\\begin{equation*}\n  \\Delta W = \\vec{F} \\cdot \\Delta \\vec{r}_i\n\\end{equation*}\n\nWith the number of divided pieces approaching infinity and each piece of \ntrajectory approaching infinitesimal, we can add them up to get the total work:\n\\begin{equation*}\n  \\begin{split}\n    W &= \\lim_{\\Delta \\vec{r}_i \\to \\vec{0}} \\sum_i \\vec{F} \\cdot \\Delta \\vec{r}_i \\\\\n      &= \\int_C \\vec{F} \\cdot d\\vec{r} \\\\\n  \\end{split}\n\\end{equation*}\nwhich is the definition of a line integral.\n\n\\subsection{Calculation of Line Integrals}\n\nTo calculate a line integral,\n\\begin{equation*}\n  \\begin{split}\n    W &= \\int_C \\vec{F} \\cdot d\\vec{r} \\\\\n      &= \\int_C \\vec{F} \\cdot \\frac{d\\vec{r}}{dt} \\cdot dt \\\\\n      &= \\int_{t_1}^{t_2} \\vec{F} \\cdot \\frac{d\\vec{r}}{dt} \\cdot dt \\\\\n  \\end{split}\n\\end{equation*}\n\nNotice that in the definition of line integrals, $\\vec{F}$ and the trajectory \n$C$ are independent from each other.\n\n\\begin{example}\n  Suppose that there is a force field as $\\vec{F} = -y \\uvec{\\i} + x \\uvec{\\j}$, \n  and a trajectory $C$ as\n  \\begin{equation*}\n    \\begin{cases}\n      x = t \\\\\n      y = t^2 \\\\\n    \\end{cases}\n  \\end{equation*}\n  where $0 \\leq t \\leq 1$. Calculate the work along the trajectory in the force \n  field.\n\n  Solution:\n\n  We can use the line integral to calculate the total work.\n  \\begin{equation*}\n    \\begin{split}\n      W &= \\int_C \\vec{F} \\cdot d\\vec{r} \\\\\n        &= \\int_0^1 \\vec{F} \\cdot \\frac{d\\vec{r}}{dt} dt \\\\\n    \\end{split}\n  \\end{equation*}\n\n  According to the problem description,\n  \\begin{gather*}\n    \\vec{F} = \\langle -y, x \\rangle = \\langle -t^2, t \\rangle \\\\\n    \\vec{r} = \\langle x, y \\rangle = \\langle t, t^2 \\rangle \\\\\n    \\frac{d\\vec{r}}{dt} = \\langle 1, 2t \\rangle \\\\\n  \\end{gather*}\n\\end{example}\n\nTherefore,\n\\begin{equation*}\n  \\begin{split}\n    W &= \\int_0^1 \\vec{F} \\cdot \\frac{d\\vec{r}}{dt} dt \\\\\n      &= \\int_0^1 \\langle -t^2, t \\rangle \\cdot \\langle 1, 2t \\rangle dt \\\\\n      &= \\int_0^1 t^2 dt \\\\\n      &= \\frac{t^3}{3}|_0^1 \\\\\n      &= \\frac{1}{3} \\\\\n  \\end{split}\n\\end{equation*}\n\n\\subsection{Another Way of Calcuating Line Integrals}\n\nAnother way to look at the calculation of line integrals. For a line integral \n$\\int_C \\vec{F} \\cdot d\\vec{r}$, we have\n\\begin{gather*}\n  \\vec{F} = \\langle M, N \\rangle \\\\\n  d\\vec{r} = \\langle dx, dy \\rangle \\\\\n\\end{gather*}\n\n\\begin{question}\n  Why the following equation holds $d\\vec{r} = \\langle dx, dy \\rangle$?\n\\end{question}\n\nTherefore,\n\\begin{equation*}\n  \\begin{split}\n    \\int_C \\vec{F} \\cdot d\\vec{r} &= \\int_C \\langle M, N \\rangle \\cdot \\langle dx, dy \\rangle \\\\\n                                  &= \\int_C M dx + N dy \\\\\n  \\end{split}\n\\end{equation*}\n\nTo evaluate the expression $\\int_C M dx + N dy$, we need to express $x$ and $y$ \nwith a single variable, and do substitution in the integrand.\n\n\\begin{question}\n  Why is it incorrect to evaluate $\\int_C M dx + N dy$ by the following method:\n  \\begin{equation*}\n    \\begin{split}\n      \\int_C M dx + N dy &= \\int_C M dx + \\int_C N dy \\\\\n                         &= \\int_{x_1}^{x_2} M dx + \\int_{y_1}^{y_2} N dy \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Answer:\n\n  I can think of a counterexample to prove the above method can produce \n  incorrect result. Consider the following case:\n\n  There is a force field as $\\vec{F} = -y \\uvec{\\i} + x \\uvec{\\j}$, and a trajectory as\n  \\begin{equation*}\n    \\begin{cases}\n      x = \\sin t \\\\\n      y = \\cos t \\\\\n    \\end{cases}\n  \\end{equation*}\n  where $0 \\leq t \\leq 2 \\pi$. \n\n  Obviously the total along the described trajectory in the force field is not \n  $0$ because at any points of the trajectory, $\\vec{F}$ and $d\\vec{r}$ have the \n  same direction. However, using the above method\n  \\begin{equation*}\n    \\int_C M dx + N dy = \\int_{x_1}^{x_2} M dx + \\int_{y_1}^{y_2} N dy\n  \\end{equation*}\n  the result would be $0$ because $x_1 = x_2$ and $y_1 = y_2$.\n\n  In summary, the incorrect evaluation method cannot correctly evaluate line \n  integrals with back-and-forth trajectory.\n\\end{question}\n\n\\begin{example}\n  Suppose that there is a force field as $\\vec{F} = -y \\uvec{\\i} + x \\uvec{\\j}$, \n  and a trajectory $C$ as\n  \\begin{equation*}\n    \\begin{cases}\n      x = t \\\\\n      y = t^2 \\\\\n    \\end{cases}\n  \\end{equation*}\n  where $0 \\leq t \\leq 1$. Calculate the work along the trajectory in the force \n  field.\n\n  Solution:\n\n  We can use line intergrals to calculate the total work:\n  \\begin{equation*}\n    \\begin{split}\n      W &= \\int_C \\vec{F} \\cdot d\\vec{r} \\\\\n        &= \\int_C \\langle -y, x \\rangle \\cdot \\langle dx, dy \\rangle \\\\\n        &= \\int_C -ydx + xdy \\\\\n    \\end{split}\n  \\end{equation*}\n\n  According to the problem description,\n  \\begin{gather*}\n    x = t \\\\\n    y = t^2 \\\\\n    dx = 1dt \\\\\n    dy = 2t dt \\\\\n  \\end{gather*}\n\n  Therefore,\n  \\begin{equation*}\n    \\begin{split}\n      W &= \\int_C -ydx + xdy \\\\\n        &= \\int_0^1 -t^2 \\cdot 1 \\cdot dt + t \\cdot 2t \\cdot dt \\\\\n        &= \\int_0^1 t^2 dt \\\\\n        &= \\frac{1}{3} \\\\\n    \\end{split}\n  \\end{equation*}\n\n  Note that the result of a line integral $\\int_C \\vec{F} \\cdot d\\vec{r}$ \n  doesn't depend on the parameterization, in other words, the substitution of \n  any parameters should produce the same results. For the above example, we can \n  also apply the following parameterization, which would yield the same result.\n  \\begin{gather*}\n    x = \\sin\\theta \\\\\n    y = \\sin^2 \\theta \\\\\n    0 \\leq \\theta \\leq \\frac{\\pi}{2} \\\\\n  \\end{gather*}\n\n  Therefore, we should choose the parameterization which is the easiest to \n  calculate.\n\\end{example}\n\n\\subsection{Geometric Approach}\n\n\\begin{gather*}\n  \\vec{v} = \\frac{d\\vec{r}}{dt} = \\vec{T} |\\frac{ds}{dt}| = \\langle \\frac{dx}{dt}, \\frac{dy}{dt} \\rangle \\\\\n  d\\vec{r} = \\vec{T} ds = \\langle dx, dy \\rangle \\\\\n  \\int_C \\vec{F} \\cdot d\\vec{r} = \\int_C \\vec{F} \\cdot \\vec{T} \\cdot ds \\\\\n\\end{gather*}\n\n$\\vec{F} \\cdot \\vec{T}$ is the component of $\\vec{F}$ along $\\vec{T}$, hence a \nline integral is a integral whose integrand is the component of $\\vec{F}$ along \n$\\vec{T}$. The value of $\\vec{F} \\cdot \\vec{T}$ depends on the relationship of \nthe directions of $\\vec{F}$ and $\\vec{T}$. Therefore, we can use this insight to \nderive the result of a line integral by checking the directions of $\\vec{F}$ and \n$\\vec{T}$ geometrically.\n\n\\begin{example}\n  Suppose that there is a force field as $\\vec{F} = x \\uvec{i} + y \\uvec{j}$, \n  and a trajectory $C$ which is a circle of radius $a$ at the origin with \n  counter clockwise direction. Calculate the work along the trajectory in the \n  force field.\n\n  Solution:\n\n  By drawing the diagram of the force field and the trajectory, we can see that \n  at every point of the trajectory, the force is perpendicular to the velocity. \n  Therefore, the total work is $0$.\n\\end{example}\n\n\\begin{example}\n  Suppose that there is a force field as $\\vec{F} = -y \\uvec{i} + x \\uvec{j}$, \n  and a trajectory $C$ which is a circle of radius $a$ at the origin with \n  counter clockwise direction. Calculate the work along the trajectory in the \n  force field.\n\n  Solution:\n\n  By drawing the diagram of the force field and the trajectory, we can see that \n  at every point of the trajectory, the force has the same directory as the \n  velocity. Therefore,\n  \\begin{gather*}\n    \\vec{F} \\cdot \\vec{T} = |\\vec{F}| = \\sqrt{(-y)^2 + x^2} = a \\\\\n    \\int_C \\vec{F} d\\vec{r} = \\int_C |\\vec{F}| ds = 2\\pi a^2 \\\\\n  \\end{gather*}\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "8c1e63342ed4526311e84ff6c400619ba7183106", "size": 10093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture19.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": "lecture19.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": "lecture19.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": 30.6778115502, "max_line_length": 107, "alphanum_fraction": 0.6515406718, "num_tokens": 3267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6209046364976732}}
{"text": "\\documentclass[../main.tex]{subfile}\n\n\\begin{document}\n\n\\section{Classification} \\label{sec:classification}\n\n\\subsection{Feature Extraction} \\label{subsec:features-extraction}\nThere are several ways to represent an image and, for this work, the following ones were chosen: RGB image, grayscale image, and image representation through features.\n\nThe first method to represent the images is in the form of an RGB image. It can be considered the default method, since it does not require any additional computation after the pre-processing phase.\n\nThe second one transforms an image into a grayscale image, as the colors may not only be irrelevant but also misleading, and the difference in lighting between a healthy and a rotten fruit peel may be enough to classify the fruits correctly.\n\nThe third and last one represents an image through some textural properties from a Gray Level Co-occurrence Matrix (GLCM) \\cite{IV-item1}.\nA GLCM is a matrix defined over an image, and it represents the distribution of co-occurring gray values (intensity) at a given offset. In other words, it calculates the spatial distribution of intensity values in a neighborhood from a one-color channel image, like a grayscale image, which is why a GLCM is good to obtain textural information about an image.\n\nFor an image $I$ of size $N \\times N$, a co-occurrence matrix $M$ of order $N_{g} \\times N_{g}$ can be defined as:\n\\begin{equation}\n    M(i,j) = \\sum^{N}_{x=1}\\sum^{N}_{y=1}\n    \\begin{cases}\n        1 & \\mbox{if } I(x,y) = i \\mbox{ and }           \\\\\n          & \\quad I(x + \\Delta_{x}, y + \\Delta_{y}) = j, \\\\\n        0 & \\mbox{otherwise},\n    \\end{cases}\n\\end{equation}\nIn which $i$ and $j$ are the intensity values, $x$ and $y$ are the spatial coordinates. The offset ($\\Delta_{x}, \\Delta_{y}$) specifies the distance between the pixel-of-interest and its neighbors. This offset can also be parameterized in terms of a distance $d$ and an angle $\\theta$. Note that when $d = 1$, it is called a normalized co-occurence matrix. Having that said, $m(i,j)$ will be referenced as the $(i,j)$-th entry in a normalized co-occurence matrix.\n\nIn order to calculate the textural properties yet to be mentioned, the following equations will be needed:\n\\begin{align*}\n    m_{x}(i) = \\sum^{N_{g}}_{j=1} m(i,j),                                 & \\quad\n    m_{y}(j) = \\sum^{N_{g}}_{i=1} m(i,j)                                          \\\\\n    \\mu_{x} = \\sum^{N_{g}}_{i=1} i \\cdot m_{x}(i),                        & \\quad\n    \\mu_{y} = \\sum^{N_{g}}_{j=1} j \\cdot m_{y}(j)                                 \\\\\n    \\sigma^{2}_{x} = \\sum^{N_{g}}_{i=1} (1 - \\mu_{x})^{2} \\cdot m_{x}(i), & \\quad\n    \\sigma^{2}_{y} = \\sum^{N_{g}}_{j=1} (1 - \\mu_{y})^{2} \\cdot m_{y}(j)\n\\end{align*}\n\nConcerning the GLCM method, to calculate the textural information necessary to classify the fruits, the following statistical descriptors will be used:\n\n\\begin{description}\n    \\item[Contrast] --- measures the intensity contrast between a pixel and its neighbours over the whole image:\n          \\begin{equation}\n              Contrast = \\sum^{N_{g}}_{i=1} \\sum^{N_{g}}_{j=1} m(i,j) \\cdot \\lvert i - j \\rvert^{2}\n              \\label{eq:contrast}\n          \\end{equation}\n\n    \\item[Dissimilarity] --- measures the distance between pairs of \\mbox{pixels} in a region of interest:\n          \\begin{equation}\n              Dissimilarity = \\sum^{N_{g}}_{i=1} \\sum^{N_{g}}_{j=1} m(i,j) \\cdot \\lvert i - j \\rvert\n              \\label{eq:dissimilarity}\n          \\end{equation}\n\n    \\item[Homogeneity] --- measures the closeness of the distribution of elements in the GLCM to the GLCM diagonal:\n          \\begin{equation}\n              Homogeneity = \\sum^{N_{g}}_{i=1} \\sum^{N_{g}}_{j=1} \\frac{m(i,j)}{1 + \\lvert i - j \\rvert^{2}}\n              \\label{eq:homogeneity}\n          \\end{equation}\n\n    \\item[Angular Second Moment (ASM)] --- Provides the sum of the squared elements in the GLCM, it is used as a measure of orderliness:\n          \\begin{equation}\n              ASM = \\sum^{N_{g}}_{i=1} \\sum^{N_{g}}_{j=1} m(i,j)^{2}\n              \\label{eq:asm}\n          \\end{equation}\n\n    \\item[Energy] --- Similar to the ASM, however it is considered a better texture measurement:\n          \\begin{equation}\n              Energy = \\sqrt{ASM}\n              \\label{eq:energy}\n          \\end{equation}\n\n    \\item[Correlation] --- measures how correlated a pixel  is to its neighbour over the over whole image:\n          \\begin{equation}\n              Correlation = \\sum^{N_{g}}_{i=1} \\sum^{N_{g}}_{j=1} \\frac{m(i,j) \\left(1 - \\mu_{x}\\right) \\left(1 - \\mu_{y}\\right)}{\\sigma_{x} \\cdot \\sigma_{y}}\n              \\label{eq:correlation}\n          \\end{equation}\n\\end{description}\n\nConsidering that a GLCM uses gray levels values or intensity values, an RGB image cannot be used as an input, neither a grayscale image, as it loses relevant information about each color channel. So far, 3 GLCMs are needed, one for each channel in the RGB color scheme. In addition, as mentioned above, the distance used is one pixel, moreover, four angles were used: $0^{\\circ}$, $45^{\\circ} (\\frac{\\pi}{4})$, $90^{\\circ} (\\frac{2\\pi}{4})$, and $135^{\\circ} (\\frac{3\\pi}{4})$. A combination between an angle and a distance makes an offset. Now, 4 GLCMs are needed for each color channel. Therefore, in total, 12 GLCMs need to be built. Then, as 6 textural descriptors are calculated from one GLCM \\eqref{eq:contrast} to \\eqref{eq:correlation}. To represent a single image, 72 textural descriptors are calculated.\n\nMoreover, for every method discussed above, a Gabor filter is applied. If it is a grayscale image, the Gabor filter is applied after the image is converted into grayscale. If a GLCM is used, the filter is applied to the image before the GLCM is calculated.\n\nA Gabor filter can be defined as a sinusoidal signal of a particular frequency and orientation, modulated by a Gaussian wave. In other words, it allows certain frequencies and rejects others. When a Gabor Filter is applied to an image, it emphasizes the edges and points where texture changes accordingly to the filter pattern, i.e., its parameters. Therefore, these Gabor Filters are well suited for texture analysis. Mathematically, a Gabor Filter has a real and imaginary component representing orthogonal directions. For this work, only the real component was used.\n\n\\subsection{Neural Network} \\label{subsec:neural-network}\n\nThere were 120 samples of each of the six fruits, i.e., 720 images in total, and all the fruit images were split equally into those three classes. In other words, 40 images for each class (A, B, or C). 80\\% of fruit images were used to train the models and the remaining 20\\% for the validation step. Since there were defined very distinct ways to represent the images, it demands different neural networks architectures to fit better the data fed into them.\n\n\\subfile{../figures/cnn-diagram}\n\nThe architecture seen in Figure \\ref{fig:cnn} represents the structure of a Convolution Neural Network (CNN). A CNN is mainly composed of four different layers: Convolution, Pooling, Flattening, and Classification.\n\nConvolutional layers allow one to systematically create and apply a series of filters over an array input (e.g., an image). These filters act like feature detectors, and then the layer outputs a \"feature map\" that summarizes the features detected (e.g., lines and edges) by the filters. Although the Convolutional layers have their limitations, they are translation-invariant, because they are capable of detecting patterns locally rather than globally. It means that if a Convolution layer leaned a certain pattern, and if the same pattern occurs again, but in a different location, they would still be able to detect that same pattern.\n\nA Pooling Layer is used to perform a downsample on feature maps, which reduces their dimensions, but they still carry the main elements. It works by aggregating a group of pixels and applying a pooling operation. The two most commons are Average Pooling, which calculates the average of each group, and Max Pooling, which calculates the maximum value in each group. The purpose of using a Pooling Layer is to decrease the computational power needed to process the data. And as a side-effect, it helps to extract dominant features, making the training process more efficient.\n\nBefore the Pooling layer, an activation function (e.g., ReLU (Rectified Linear Unit)) is used upon the features maps. This function usually breaks the linearity and adds complexity, much like it is done for a Dense Layer.\n\nThe combination between a Convolutional Layer, a Pooling Layer, and an activation function makes a Convolution Group, seen in Figure \\ref{fig:cnn}. When stacking these Convolutional Layers, instead of detecting simple features (e.g., lines and edges), deeper layers learn to detect more abstract features, like shapes or specific objects.\n\nAfter that, a Flattening Layer is used because the output of the combination of multiple Convolutional Groups is multi-dimensional, composed of several features maps. So, it needs to be flattened.\n\nFinally, the Classification part is composed of a sequence of Dense Groups. A Dense Group is made of Dense Layers, also known as Fully Connected Layers, followed by an activation function. Before the Output Layer, a Dropout Layer is used to help reducing overfitting while training (useful for a small dataset). It works by randomly deactivating a percentage of the neurons from the previous layer. Then for the Output Layer, which is also a Dense Layer, the activation function chosen is often different from the ones used in the hidden layers.\n\n\\subfile{../figures/dnn-diagram}\n\nThe other architecture, DNN, seen in Figure \\ref{fig:dnn}, is a simple deep neural network composed of a Flattening Layer at the beginning, a sequence of Dense Groups, and a Dropout Layer right before the Output Layer. This architecture may look very similar to the one used in the Flattening and Classification part inside the CNN. However, in reality, a CNN uses a combination of a convolutional technique to extract useful information from images and passes it as input to a fully connected deep neural network.\n\nData Augmentation technique was used at the beginning of the CNN seen in Figure \\ref{fig:cnn}. Since there was a total of 120 images for each fruit, and each model was trained for only one type of fruit, meaning the models were on a small dataset. It helps by reducing overfitting by generating new images from existing ones by doing simple modifications such as random horizontal and vertical flipping with a random rotation. For the same reason, a Spatial Dropout Layer was used right before the Flattening part. It works similarly to a regular Dropout Layer. However, it is applied to 2D feature maps instead of individual elements.\n\nRegarding the Flattening Layer in the CNN, a Global Average Filter was used. It uses an average pooling to reduce the size of feature maps, and then it flattens and passes it as input to the next part. This Global Average Filter is important because its input came from either RGB or Grayscale image methods. Thus, if it were simply flattened, there would be too much information for the dense neural network, i.e., the Classification part, to process and classify efficiently. That was unnecessary for the DNN since its input came from the GLCM textural properties, and it consisted of only 72 elements, the GLCM descriptors when flattened.\n\nInside the Convolutional Groups, the activation functions used were the ReLU \\eqref{eq:relu} or the swish \\eqref{eq:swish} function, which behaves similarly to the ReLU. Concerning the Dense Groups, they use either the swish or the ELU (Exponential Linear Unit) \\eqref{eq:elu} function, which is also similar to the ReLU.\n\nThe softmax \\eqref{eq:softmax} function is used at the Output Layer because it converts its input into a probability distribution. Useful for classification tasks when there are more than two classes.\n\\begin{align}\n    ReLU(x)        & = max(0, x) \\label{eq:relu}                                                       \\\\\n    swish(x)       & = \\frac{x}{1 + \\mathrm{e}^{-x}} \\label{eq:swish}                                  \\\\\n    ELU(x)         & =\n    \\begin{cases}\n        x                  & \\mbox{if } x > 0, \\\\\n        \\mathrm{e}^{x} - 1 & \\mbox{otherwise},\n    \\end{cases} \\label{eq:elu}                                                           \\\\\n    softmax(x_{i}) & = \\frac{\\mathrm{e}^{x_{i}}}{\\sum^{K}_{j=1} \\mathrm{e}^{x_{j}}} \\label{eq:softmax}\n\\end{align}\n\n\\end{document}", "meta": {"hexsha": "6c52ed2be640bfe9c6a74313b65fc95ff25c86d7", "size": 12593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/9-Classification.tex", "max_stars_repo_name": "henrique-tavares/IET-Image-Processing", "max_stars_repo_head_hexsha": "55e120fa04b3319a4217418f72e8cac33ca94daa", "max_stars_repo_licenses": ["MIT"], "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/9-Classification.tex", "max_issues_repo_name": "henrique-tavares/IET-Image-Processing", "max_issues_repo_head_hexsha": "55e120fa04b3319a4217418f72e8cac33ca94daa", "max_issues_repo_licenses": ["MIT"], "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/9-Classification.tex", "max_forks_repo_name": "henrique-tavares/IET-Image-Processing", "max_forks_repo_head_hexsha": "55e120fa04b3319a4217418f72e8cac33ca94daa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 99.9444444444, "max_line_length": 813, "alphanum_fraction": 0.7139680775, "num_tokens": 3113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070838, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6209046334533946}}
{"text": "\n\\subsection{Dynamic time warping}\n\nWe may want to examine the similarity between two sequences.\n\nWe want to match a sample from one sequence to a sample from the other sequence.\n\nSimply matching at the same time point is naive, as samples may move at different speeds, or have offsets.\n\n", "meta": {"hexsha": "3f2c60bb3fc1b819271bf8c6881da41ee1383db8", "size": 288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/03-01-DTW.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/distance/03-01-DTW.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/distance/03-01-DTW.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.8, "max_line_length": 106, "alphanum_fraction": 0.7881944444, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6208355729910111}}
{"text": "\\documentclass[12pt,letterpaper,oneside,notitlepage,onecolumn]{article}%\n\\usepackage[utf8]{inputenc}%\n\\usepackage{textcomp}%\n\\usepackage{lastpage}%\n\\usepackage[margin=0.69in]{geometry}%\n%\n\\title{Vector{-}Rotation to Euler Angles}%\n\\author{Buck Baskin}%\n\\date{\\today}%\n\\usepackage[english]{babel}%\n\\usepackage[margin=0.69in]{geometry}%\n\\usepackage{parskip}%\n\\usepackage{listings}%\n\\usepackage{color}%\n\\usepackage{verbatim}%\n\\usepackage{soul}%\n\\usepackage{amsmath}%\n\\usepackage{amssymb}%\n\\usepackage{amsthm}%\n\\usepackage{gensymb}%\n\\usepackage{graphicx}%\n\\definecolor{dkgreen}{rgb}{0, 0.6, 0}%\n\\definecolor{gray}{rgb}{0.5, 0.5, 0.5}%\n\\definecolor{mauve}{rgb}{0.58, 0, 0.82}%\n\\lstset{frame=tb,\n  language=Matlab,\n  aboveskip=3mm,\n  belowskip=3mm,\n  showstringspaces=false,\n  columns=flexible,\n  basicstyle={\\small\\ttfamily},\n  numbers=none,\n  numberstyle=\\tiny\\color{gray},\n  keywordstyle=\\color{blue},\n  commentstyle=\\color{dkgreen},\n  stringstyle=\\color{mauve},\n  breaklines=true,\n  breakatwhitespace=true,\n  tabsize=3\n}%\n\\DeclareMathOperator*{\\argmax}{arg\\,max}%\n\\DeclareMathOperator*{\\argmin}{arg\\,min}%\n\\newcommand{\\subsubsubsection}{\\paragraph}%\n\\newcommand{\\bbs}[1]{\\section{#1}}%\n\\newcommand{\\bbbs}[1]{\\subsection{#1}}%\n\\newcommand{\\bbbbs}[1]{\\subsubsection{#1}}%\n\\newcommand{\\bbbbbs}[1]{\\subsubsubsection{#1}}%\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}%\n%\n\\begin{document}%\n\\normalsize%\n\\maketitle%\nSome calculations were verified using Python.%\n\\section{Answer}%\n$R_{BA} = R_{y}(\\alpha) R_{x}(\\beta) R_{y}(\\gamma)$%\n\\subsection{Solving for $\\alpha, \\beta, \\gamma$}%\n\\subsubsection{$\\beta$}%\nUsing the atan method, one can solve for $\\beta$ using the middle column of the matrix. The middle value, $r_{22} = cos(\\beta)$. Using $r_{12}^{2} + r_{32}^{2} = sin^{2}(\\beta)(sin^{2}(\\gamma) + cos^{2}(\\gamma)) = sin^{2}(\\beta)$, $sin(\\beta) = \\sqrt{r_{12}^{2} + r_{32}^{2}}$. Therefore, $\\beta = atan2(\\sqrt{r_{12}^{2} + r_{32}^{2}}, r_{22})$.\n\n%\n\\subsubsection{$\\gamma$}%\nLooking at two elements in the middle row of the matrix, one can solve for $\\gamma$ using the atan method. $r_{21} = sin(\\beta) sin(\\gamma)$, so $sin(\\gamma) = r_{21} / sin(\\beta)$. $r_{23} = -sin(\\beta) cos(\\gamma)$, so $cos(\\gamma) = -r_{23} / sin(\\beta)$. Therefore, $\\gamma = atan2(r_{21} / sin(\\beta), -r_{23} / sin(\\beta))$.\n\n%\n\\subsubsection{$\\alpha$}%\n$r_{12} = sin(\\alpha) sin(\\beta)$, $sin(\\alpha) = r_{12} / sin(\\beta)$\\\\$r_{32} = cos(\\alpha) sin(\\beta)$, $cos(\\alpha) = r_{32} / sin(\\beta)$\\\\$\\alpha = atan2(r_{12} / sin(\\beta), r_{32} / sin(\\beta))$\n\n%\n\\subsection{Conclusion}%\nSubstituting the correct values from $R_{BA}$ calculated by Rodriguez Formula into the spaces allocated by $r_{ij}$ that were solved into an $atan2$ formula using $R_{BA}$ calculated by the rotation matrices gives the solution for the equivalent rotations in radians (rounded to 3 decimal places).%\n\\newline%\n$\\alpha = 1.833, \\beta = 1.231, \\gamma = -2.880$\n\n%\n\\end{document}", "meta": {"hexsha": "268b0923d1f7447cb87afe8fba57522ad251375c", "size": 2945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "generated.tex", "max_stars_repo_name": "buckbaskin/paPYrus", "max_stars_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "generated.tex", "max_issues_repo_name": "buckbaskin/paPYrus", "max_issues_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "generated.tex", "max_forks_repo_name": "buckbaskin/paPYrus", "max_forks_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 345, "alphanum_fraction": 0.6808149406, "num_tokens": 1058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6208355533721632}}
{"text": "\n\\section{Invariants of nonassociative algebras}\n\nConverting an algebra to a tensor enables Magma to compute standard invariants\nof any algebra. We note that there are known errors for $\\mathbb{R}$ and\n$\\mathbb{C}$ due to the numerical stability of the linear algebra involved in\nthe computations.\n\n\\index{Center}\\index{Centre}\n\\begin{intrinsics}\nCenter(A) : Alg -> Alg\nCentre(A) : Alg -> Alg\n\\end{intrinsics}\n\nReturns the center of the algebra $A$.\n\n\\index{Centroid!algebra}\n\\begin{intrinsics}\nCentroid(A) : Alg -> AlgMat\n\\end{intrinsics}\n\nReturns the centroid of the $K$-algebra $A$ as a subalgebra of $\\text{End}_K(A)$.\n\n\\begin{example}[CenterCentroids]\n\nWe will construct a representation of $\\mathfrak{sl}_2(9)$ in $\\mathbb{M}_4(\\mathbb{F}_3)$.\nFirst we construct $\\mathfrak{gl}_2(9)$ from $\\mathbb{M}_4(\\mathbb{F}_3)$.\n\\begin{code}\n> M := MatrixAlgebra(GF(3), 4);\n> f := ConwayPolynomial(3, 2);\n> C := CompanionMatrix(f);\n> I := IdentityMatrix(GF(3), 2);\n> A := sub< M | [InsertBlock(M!0, X, i, j) : \\\n>     X in [I, C], i in [1, 3], j in [1, 3]] >;\n> T := CommutatorTensor(A);\n> T;\nTensor of valence 3, U2 x U1 >-> U0\nU2 : Full Vector space of degree 8 over GF(3)\nU1 : Full Vector space of degree 8 over GF(3)\nU0 : Full Vector space of degree 8 over GF(3)\n> gl2 := HeisenbergAlgebra(T);\n> gl2;\nAlgebra of dimension 8 with base ring GF(3)\n\\end{code}\n\nOur Lie algebra is not simple as it has a nontrivial center, so we will obtain\n$\\mathfrak{sl}_2$ by factoring out the center. Note that our algebras are over\nthe prime field $\\mathbb{F}_3$, so the center is 2-dimensional (over\n$\\mathbb{F}_3$). Notice that $\\mathfrak{sl}_2(9)$ has a trivial center but has a\n2-dimensional centroid.\n\\begin{code}\n> sl2 := gl2/Center(gl2);\n> sl2;\nAlgebra of dimension 6 with base ring GF(3)\n> Center(sl2);\nAlgebra of dimension 0 with base ring GF(3)\n> Centroid(sl2);\nMatrix Algebra of degree 6 with 2 generators over GF(3)\n\\end{code}\n\\end{example}\n\n\\index{LeftNucleus!algebra}\\index{RightNucleus!algebra}\\index{MidNucleus!algebra}\n\\begin{intrinsics}\nLeftNucleus(A) : Alg -> AlgMat\nRightNucleus(A) : Alg -> AlgMat\nMidNucleus(A) : Alg -> AlgMat\n\\end{intrinsics}\n\nReturns the nucleus of the algebra $A$ as a subalgebra of the enveloping algebra\nof right multiplication $\\mathcal{R}(A)$.\n\n\\index{DerivationAlgebra!algebra}\n\\begin{intrinsics}\nDerivationAlgebra(A) : Alg -> AlgMatLie\n\\end{intrinsics}\n\nReturns the derivation algebra of the algebra $A$ as a Lie subalgebra of $\\text{End}_K(A)$.\n\n\\begin{example}[DerivationAlg]\n\nWe will compute the derivation algebra of the (rational) octonions $\\mathbb{O}$\nand also the 27 dimension exceptional Jordan algebra\n$\\mathfrak{H}_3(\\mathbb{O})$. Because the intrinsics use exact linear algebra,\nwe do not use the more familiar field $\\mathbb{C}$ in this context. First we\nconsider $\\mathbb{O}$. We verify that $\\Der(\\mathbb{O})\\cong G_2$.\n\\begin{code}\n> A := OctonionAlgebra(Rationals(), -1, -1, -1);\n> A;\nAlgebra of dimension 8 with base ring Rational Field\n> D := DerivationAlgebra(A);\n> D;\nMatrix Lie Algebra of degree 8 over Rational Field\n> SemisimpleType(D);\nG2\n\\end{code}\n\nNow we will just briefly perform a sanity check and verify that \\texttt{D} acts as it should.\n\\begin{code}\n> a := Random(Basis(A));\n> b := Random(Basis(A));\n> del := Random(Basis(D));\n> (a*b)*del eq (a*del)*b + a*(b*del);\ntrue\n\\end{code}\n\nFinally, we construct $\\mathfrak{H}_3(\\mathbb{O})$ the $3\\times 3$ Hermitian\nmatrices, and we verify that $\\Der(\\mathfrak{H}_3(\\mathbb{O})\\cong F_4$. \n\\begin{code}\n> J := ExceptionalJordanCSA(A);\n> J;\nAlgebra of dimension 27 with base ring Rational Field\n> D_J := DerivationAlgebra(J);\n> Dimension(D_J);\n52\n> SemisimpleType(D_J);\nF4\n\\end{code}\n\\end{example}\n", "meta": {"hexsha": "4bf16fd7ee12d24ee6f9062ce4dad48fed97019e", "size": 3703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/alg-invariants.tex", "max_stars_repo_name": "algeboy/TensorSpace", "max_stars_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-14T03:24:16.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-04T01:51:36.000Z", "max_issues_repo_path": "doc/alg-invariants.tex", "max_issues_repo_name": "algeboy/eMAGma", "max_issues_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-06-16T20:19:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-08T22:56:11.000Z", "max_forks_repo_path": "doc/alg-invariants.tex", "max_forks_repo_name": "algeboy/eMAGma", "max_forks_repo_head_hexsha": "34c7a454c21f067d71914c0aee43f7e52ed6d884", "max_forks_repo_licenses": ["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.1176470588, "max_line_length": 93, "alphanum_fraction": 0.7113151499, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397349, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6208102583985363}}
{"text": "\\subsection{LES}\n\nA means of assessing the quality of grid resolution in LES \\cite{Gant2009}:\n\\begin{itemize}\n\t\\item Estimations based on prior RANS results\n\t\\item Single-grid estimators\n\t\\item Multi-grid estimators\n\\end{itemize} \n\n\\subsubsection{LES filtering}\nIn case instantaneous values of flow is desired and solving all scale turbulent structure by DNS is too expensive. LES filtering is employed to solve only large structure of flow, while universal small ones are still modelled. Using Farve filtering, any quantities $Q$ is decomposed to filtered quantities $\\widetilde{Q}$ and unfiltered quantities $Q''$. Filtering instantaneous Navier-Stokes equations results below equations:\n\\begin{equation} \\label{eq:LES-continuity}\n\\pdv{\\overline{\\rho}}{t}  + \n\\pdv{}{x_i} \\left( \\rho \\widetilde{u_i} \\right) = 0\n\\end{equation}\n\n\\begin{equation} \\label{eq:LES-momentum}\n\\pdv{}{t} \\left( \\overline{\\rho} \\widetilde{u_i} \\right) + \n\\pdv{}{x_j} (\\overline{\\rho} \\widetilde{u_i} \\widetilde{u_j}) =\n-\\pdv{\\overline{p}}{x_i}\n+ \\pdv{\\overline\\tau_{ij}}{x_j}\n+ \\pdv{}{x_j} (-\\overline\\rho (\\widetilde{u_i u_j} - \\widetilde{u_i} \\widetilde{u_j} )) \n+ \\overline b_i  \n\\end{equation}\n\nFarve filtered equation for  species mass fraction $Y_i$:\n\\begin{equation} \\label{eq:LES_species}\n\\pdv{}{t} \\left( \\overline{\\rho} \\widetilde{Y_i} \\right) + \n\\pdv{}{x_j} (\\overline{\\rho} \\widetilde{u_j} \\widetilde{Y_i}) =\n\\pdv{\\overline j_{ij}}{x_j}\n+ \\pdv{}{x_j} \\left[-\\overline\\rho (\\widetilde{ u_j Y_i} - \\widetilde{u_j} \\widetilde{Y_i}) \\right] \n+ \\overline\\omega_i  \n\\end{equation}\n\nUnclosed quantities are \\cite{Poinsot2005}: subgrid (unresolved) Reynold stresses $\\tau_{ij}^s = -\\rho(\\widetilde{u_i u_j} - \\widetilde{u_i} \\widetilde{u_j})$; unresolved species fluxes: $j_{j} = -\\rho (\\widetilde{u_j Y_i} - \\widetilde{u_j} \\widetilde{Y_i}$), filtered laminar diffusion fluxes $\\overline\\tau_{ij}$, $\\overline j_{ij}$  and filtered chemical reaction rate $\\overline\\omega_i$.\n\n\n\\subsubsection{Smagorinsky model}\nWith eddy viscosity assumption, subgrid scale Reynold stresses $\\tau_{ij}^s$ can be modelled as:\n\\begin{equation} \\label{eq:sgs_stress}\n\\tau_{ij}^{s} -\\frac{1}{3}\\tau_{kk}^{s} \\delta_{ij} =  \n2 \\mu_t \\left( \\widetilde{S_{ij}} - \\frac{1}{3}\\widetilde{S_{kk}} \\delta_{ij} \\right) \n\\end{equation}\n\nThe Farve-filtered rate-of-strain tensor $\\widetilde{S_{ij}}$ is defined the same as Equation~\\ref{eq:rate_of_strain_tensor} with velocity field is replaced by filtered velocity:\n\\begin{equation} \\label{eq:sgs_rate_of_strain_tensor}\n\\widetilde{S_{ij}} = \\frac{1}{2} \\left( \\pdv{\\widetilde{u_i}}{x_j} + \\pdv{\\widetilde{u_j}}{x_i} \\right) \n\\end{equation}\nThe second term in LHS is included to ensure that in case of isotropic stress tensor, its trace is equal to minus twice the kinetic energy \\cite{Lilly1992}.\n \n$\\nu_t = \\mu_t/\\rho$ is \\emph{subgrid scale viscosity}. It is modelled using dimensional argument of characteristic length scale and characteristic velocity scale:\n\\begin{equation} \\label{eq:sgs_viscoscity}\n\\nu_t =2 C_\\mu \\Delta^2 (2 \\widetilde{S_{ij}} \\widetilde{S_{ij}})^{1/2} \n\\end{equation}\n\nWith gradient-diffusion assumption, turbulent scalar flux can be written as:\n\\begin{equation} \\label{eq:sgs_turb_scalar}\n-\\bar{\\rho} (\\widetilde{u_j \\phi_i} - \\widetilde{u_j} \\widetilde{\\phi_i}) =\n\\bar{\\rho} \\alpha_t \\pdv{\\phi_i}{x_j}\n\\end{equation}\n$\\alpha_t$ is turbulent diffusivity and calculated from:\n\\begin{equation} \\label{eq:sgs_turb_diffusivity}\n\\bar{\\rho} \\alpha_t  = \nC_\\alpha \\bar{\\rho} \\Delta^2 |\\tilde{S}| \n\\end{equation}\n\n\\subsubsection{Dynamic approach}\nDynamic modelling concept is used to derive dimensionless scaling coefficients in subgrid scale model instead of using constant coefficients as classical models. Assume we have a term $t(u)$ is a function of field variable $u$. A filtered value of $t(u)$ can be decomposed into resolved and modelled parts: $\\overline{t(u)} = t(\\overline{u}) + m(\\overline{u})$. We use another filter, called \\emph{test filter} to examine the variance of $t(\\overline{u})$ and $m(\\overline{u})$. Filtered term calculated at this test filter are denoted by hat symbol: $\\widehat{ \\overline{t(u)}} = t(\\widehat{\\overline{u}}) + m(\\widehat{\\overline{u}})$. If we have subgrid scale identity:\n\\begin{equation} \\label{eq:sgs_identity}\n\\widehat{t({\\overline{u}})} - t(\\widehat{\\overline{u}}) =\nm(\\widehat{\\overline{u}}) - \\widehat{m({\\overline{u}})}\n\\end{equation} \n\nModel for modelled part $m(\\overline{u})$ Equation~\\ref{eq:sgs_modelled_part}. $c$ is dimensionless coefficient, which can vary in both space and time. Substituting to Equation~\\ref{eq:sgs_identity}, we have Equation~\\ref{eq:sgs_identity_final}, where $c^*$ is an coefficient at test filter level. \n\n\\begin{equation} \\label{eq:sgs_modelled_part}\nm(\\overline{u}) = c\\; s(\\overline{u},\\Delta)\n\\end{equation}  \n\n\\begin{equation} \\label{eq:sgs_identity_final}\n\\widehat{t({\\overline{u}})} - t(\\widehat{\\overline{u}}) =\nc^*\\; s(\\widehat{\\overline{u}},\\widehat{\\Delta}) - \\widehat{c\\; s(\\overline{u},\\Delta)}\n\\end{equation} \n\nAssuming $c^* = c$ and allowing $c$ pass through the test filtering operator. Leonard term $\\mathcal{L} = \\widehat{t({\\overline{u}})} - t(\\widehat{\\overline{u}})$ and model term $\\mathcal{M} = s(\\widehat{\\overline{u}}, \\widehat{\\Delta}) - \\widehat{s(\\overline{u},\\Delta)}$. We have $\\mathcal{L} = c \\mathcal{M}$. This relation can be solve by least-square to determine single value of $c$, as Equation~\\ref{eq:sgs_coefficient}.\n\n\\begin{equation} \\label{eq:sgs_coefficient}\nc= \\frac{\\langle \\mathcal{L} \\cdot \\mathcal{M}\\rangle}{\\langle \\mathcal{M} \\cdot \\mathcal{M}\\rangle}\n\\end{equation}\n\nApply dynamic approach to find coefficient $C_\\mu$, $C_\\alpha$, where density-weighted test filtering is denoted as $\\check{\\overline{u}} = \\widehat{\\overline{\\rho}\\widetilde{u}}/\\widehat{\\overline{\\rho}}$.\n\n\\begin{equation} \\label{eq:sgs_turb_stress}\nC_\\mu= \\frac{\\langle \\mathcal{L}_{ij} \\mathcal{M}_{ij} \\rangle}{2 \\langle \\mathcal{M}_{ij} \\mathcal{M}_{ij} \\rangle}\n\\quad\n\\mathcal{L}_{ij} = -\n\\widehat{\\overline{\\rho}\\widetilde{u_i}\\widetilde{u_j}} +\n\\widehat{\\overline{\\rho}} \\check{\\overline{u_i}} \\check{\\overline{u_j}},\n\\quad\n\\mathcal{M}_{ij} = \n\\widehat{\\overline{\\rho}} \\widehat{\\Delta}^2 \\check{| {\\widetilde{S}} |} \\check{\\widetilde{S_{ij}}} - \n\\widehat{\\overline{\\rho} {\\Delta}^2 | {\\widetilde{S}} | \\widetilde{S_{ij}}}\n\\end{equation}  \n\n\\begin{equation} \\label{eq:sgs_turb_diffusivity_dyn}\nC_\\alpha= \\frac{\\langle \\mathcal{L}_{ij} \\mathcal{M}_{ij} \\rangle}{\\langle \\mathcal{M}_{ij} \\mathcal{M}_{ij} \\rangle}\n\\quad\n\\mathcal{L}_i = -\n\\widehat{\\overline{\\rho}\\widetilde{u_i}\\widetilde{\\phi}} +\n\\widehat{\\overline{\\rho}} \\check{\\overline{u_i}} \\check{\\overline{\\phi}},\n\\quad\n\\mathcal{M}_{i} = \n\\widehat{\\overline{\\rho}} \\widehat{\\Delta}^2 \\check{| {\\widetilde{S}} |} \\check{\\widetilde{\\pdv{\\phi}{x_i}}} - \n\\widehat{\\overline{\\rho} {\\Delta}^2 | {\\widetilde{S}} | \\widetilde{\\pdv{\\phi}{x_i}}}\n\\end{equation}  \n\n\\begin{equation} \\label{eq:sgs_scalar_var_dyn}\nC_\\phi= \\frac{\\langle \\mathcal{L} \\mathcal{M} \\rangle}{\\langle \\mathcal{M} \\mathcal{M} \\rangle}\n\\quad\n\\mathcal{L} = \n\\widehat{\\overline{\\rho}\\widetilde{\\phi}\\widetilde{\\phi}} -\n\\widehat{\\overline{\\rho}} \\check{\\widetilde{\\phi}} \\check{\\widetilde{\\phi}},\n\\quad\n\\mathcal{M} = \n\\widehat{\\overline{\\rho}} \\widehat{\\Delta}^2 | \\grad{\\check{\\widetilde{\\phi}}} |^2  - \n\\widehat{ \\overline{\\rho} {\\Delta}^2 | \\grad{\\widetilde{\\phi}} |^2 }\n\\end{equation} \n\n\\subsubsection{Implementation in OpenFOAM}\nThe anisotropic part of turbulence shear stress $\\tau_{ij}$ is approximated by relating it to the resolved rate of strain tensor $D_{ij}$\n\\begin{equation} \n\\tau_{ij} - \\frac{1}{3} \\tau_{kk} \\delta_{ij} \\approx - 2 \\nu_{sgs} \\text{dev}(\\overline{D}_{ij})\n\\end{equation}\n$\\text{dev}(\\overline{D}_{ij})$ is deviatoric part of strain tensor $D_{ij}$.\n\nThe sub-grid scale viscosity is defined as:\n\\begin{equation}\\label{eq:foam_nu_sgs}  \n\\nu_{sgs} = C_{k} \\Delta \\sqrt{k_{sgs}}\n\\end{equation}\n$C_{k}$ is a model constant whose default value is $0.094$ and $\\Delta$ is the filter width that defines the subgrid length scale.\n\nThe SGS kinetic energy $k_{sgs}$ is defined as:\n\\begin{equation} \\label{eq:foam_k_sgs}\nk_{sgs} = \\frac{1}{2} \\tau_{kk} = \n\\frac{1}{2} \\left( \\overline{u_{k}u_{k}} - \n\\overline{u}_{k}\\overline{u}_{k} \\right) \n\\end{equation}\n$k_{sgs}$ is computed with the assumption of balance between the subgrid scale energy production and dissipation Equation~\\ref{eq:foam_k_sgs_equilibrium}:\n\\begin{equation}  \\label{eq:foam_k_sgs_equilibrium} \n\\overline{D} : \\tau_{ij} + C_{\\epsilon} \\frac{k_{sgs}^{1.5}}{\\Delta} = 0\n\\end{equation}\n\n\\subsubsection{SGS models}\nThere are various options of SGS models implementation in OpenFOAM\n\\begin{itemize}\n\t\\item \\bera{Smagorinsky}: Smagorinsky SGS model\n\t\\item \\bera{kEqn}: One equation eddy-viscosity model\n\t\\item \\bera{dynamicLagrangian}: Dynamic SGS model with Lagrangian averaging\n\t\\item \\bera{dynamicKEqn}: Dynamic one equation eddy-viscosity model\n\t\\item \\bera{WALE}: Wall-adapting local eddy-viscosity (WALE) SGS model\n\t\\item \\bera{DeardorffDiffStress}: Differential SGS Stress Equation Model\n\\end{itemize}\n\nFor the dynamic SGS models, the spatial averaging operations of the coefficients are often performed to stabilize the calculation. The \\bera{homogeneousDynSmagorinsky} model that had been implemented in older versions takes the average of the coefficient in the whole computational domain.\n\n\\subsubsection{Calculation of filter width $\\Delta$}\nThe method for calculating the filter width $\\Delta$ is specified in the \\bera{turbulenceProperties} file. Available options in OpenFOAM are as follows:\n\\begin{itemize}\n\t\\item cubeRootVol\n\t\\item maxDeltaxyz\n\t\\item maxDeltaxyzCubeRoot\n\t\\item smooth\n\t\\item vanDriest\n\t\\item Prandtl\n\t\\item IDDESDelta\n\\end{itemize}\n\nThe \\bera{maxDeltaxyz} option calculates  filter width of the $i$ cell $\\Delta_i$ by taking the maximum distance between the cell centre $P_i$ and each face centre $F_j$:\n\\begin{equation}  \\label{eq:deltaxyz} \n\\Delta_i = \\text{deltaCoeff} \\times \\max_{1 \\le j \\le n_i} \\left\\{ \\overline{P_iF_j} \\right\\}\n\\end{equation}\n\\text{deltaCoeff} is the user specified constant of proportion.\n", "meta": {"hexsha": "10ede778016eb35b5a1b792c744088322a947abb", "size": 10176, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LES.tex", "max_stars_repo_name": "stevietran/phdThesis", "max_stars_repo_head_hexsha": "c6ccf59f7fa9b63d6af2ba1f9d48efddbf8980f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LES.tex", "max_issues_repo_name": "stevietran/phdThesis", "max_issues_repo_head_hexsha": "c6ccf59f7fa9b63d6af2ba1f9d48efddbf8980f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LES.tex", "max_forks_repo_name": "stevietran/phdThesis", "max_forks_repo_head_hexsha": "c6ccf59f7fa9b63d6af2ba1f9d48efddbf8980f1", "max_forks_repo_licenses": ["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.606557377, "max_line_length": 671, "alphanum_fraction": 0.7213050314, "num_tokens": 3522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370423, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.6208102564607757}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Local Linearity}\n\n\\objective{Define derivatives and find numerical approximations}\n\n\nWhen two variables grow proportionally to each other, they obey the algebraic relationship\n$y=ax$.  This means when one goes up, the other goes up, and visa versa.  But many things\nin nature are \\emph{inversely} proportional to each.  \\index{proportion!inverse}\nThat is, when one goes up, the other goes\n\\emph{down}.  This is the algebraic relationship $y=\\frac{a}{x}$.\n\n\\personfeature[-1in]{\\chapdir/pics/Henri-Poincare}{Jules Henri Poincar\\'{e}\n    }{1854-1912, French}{was a French mathematician and physicist\n    who discovered many amazing facets of modern physics and non-\n    traditional mathematics.  He was true polymath of his time, and\n    never worked very long on a problem, relying (successfully)\n    on his subconscious to keep working on the ideas.}\n\nThe fundamental postulate of calculus is that smooth, continuous functions are \\textbf{locally\nlinear}, that is, if you zoom in far enough, they all appear as lines.  Algebraically, we should be able\nto construct a tangent line to any function, using the difference quotient.  Chaos Theory, and\nFractal Geometry oppose this precept, in much the same way that Non-Euclidean Geometries\nare build from a rejection of Euclid's Parallel Postulate (i.e., that parallel lines never meet).  Euclidean\nGeometry and Calculus may be two viewpoints among many, but they are certainly useful ones to know!\n\n\\subsection{Derivative}\n\\index{Derivative!definition}\nFor all the aura surrounding calculus as the \\textit{summum bonum} --- highest good --- it is not\nsome process to hard to just grasp.  We just did it graphically.  Algebraically, it is the difference \nquotient, an tiny step away from the point producing a line which therefore touches the\ncurve at only one point.  This line gets more and more accurate, the smaller our step away becomes.\n\n\n\\subsubsection{Theorems of Derivatives}\n\n\\begin{itemize}\n\\item[\\textbf{sum}] the derivative of a sum is the sum of the derivatives \n\\item[\\textbf{scalar}] the derivative of a constant times a function is a constant times a derivative\n\\item[\\textbf{constant}] the derivative of a constant is 0\n\\end{itemize}\n\nDo no assume beyond this!  Note that the first two allow you to build a ``difference property'' too.\n", "meta": {"hexsha": "ce7b3c8acae862ac989c1e893018b6c20a055f5d", "size": 2339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/0302.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": "ch03/0302.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": "ch03/0302.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.9777777778, "max_line_length": 108, "alphanum_fraction": 0.7729799059, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303285397349, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6208102544264044}}
{"text": "\\section{Graph Isomorphism}\n\n\\frame{\n{Part 1: Graph Isomorphism}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-4}]\n}\n\n\\begin{frame}{Directed Graphs and Simple Graphs}\n  \\begin{columns}[T]\n    \\column{0.5\\textwidth}\n    \\begin{center}\n      Directed Graph:\\\\\n\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        \\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (0,0) {a};\n        \\node[vertex] (b) at (2,3) {b};\n        \\node[vertex] (c) at (4,2) {c};\n        \\node[vertex] (d) at (4,0) {d};\n        \\draw[edge] (a) to (b);\n        \\draw[edge] (a) to (c);\n        \\draw[edge] (c) to (b);\n        \\draw[edge] (d) to (c);\n        \\draw[edge] (d) to[bend left] (a);\n        \\draw[edge] (a) to[bend left] (d);\n        \\draw[edge] (a) to[loop left] (a);\n      \\end{tikzpicture}\n    \\end{center}\n    \\column{0.5\\textwidth}\n    \\begin{center}\n      Simple Graph:\\\\\n\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (0,0) {a};\n        \\node[vertex] (b) at (2,3) {b};\n        \\node[vertex] (c) at (4,2) {c};\n        \\node[vertex] (d) at (4,0) {d};\n        \\draw[edge] (a) to (b);\n        \\draw[edge] (a) to (c);\n        \\draw[edge] (c) to (b);\n        \\draw[edge] (d) to (c);\n        \\draw[edge] (d) to (a);\n      \\end{tikzpicture}\n\n      \\vspace{2em}\n    \\end{center}\n    \\begin{itemize}\n    \\item No double edges allowed;\n    \\item No self-loop allowed;\n    \\end{itemize}\n  \\end{columns}\n\\end{frame}\n\n\\begin{frame}{Simple Graphs}{Some definitions}\n  A Simple Graph \\structure{$G$} consists of:\n  \\begin{itemize}\n  \\item A \\emph{non-empty} set \\structure{$V$} of vertices;\n  \\item A set \\structure{$E$} of edges so that:\n    \\begin{itemize}\n    \\item Each edge has \\structure{two endpoints} in $V$:\n      \\hfill (\\alert{not an {\\bf start} and an {\\bf end}})\n\n      \\bigskip\n    \\item The order of the vertices in an edge does not matter:\n      \\hfill $e_1 = \\{v_1,v_2\\} = \\{v_2, v_1\\}$\n\n      \\bigskip\n    \\item Two vertices with an edge between them are\n      \\structure{adjacent}\n\n      \\bigskip\n    \\item An edge that connects two vertices is \\structure{incident}\n      to them.\n      \\hfill Ex: $e_1$ is \\structure{incident} to $v_1$ and $v_2$\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Vertice Degrees}\n\n    The \\structure{degree} of a vertex is the \\structure{number of\n      incident edges}.\n\n    \\begin{center}\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (0,0) {a};\n        \\node[vertex] (b) at (2,3) {b};\n        \\node[vertex] (c) at (4,2) {c};\n        \\node[vertex] (d) at (4,0) {d};\n        \\draw[edge] (a) to (b);\n        \\draw[edge] (a) to (c);\n        \\draw[edge] (c) to (b);\n        \\draw[edge] (d) to (c);\n        \\draw[edge] (d) to (a);\n      \\end{tikzpicture}\n\n      deg(a) = 3 \\hspace{1cm} deg(d) = 2\n    \\end{center}\n\n    \\hfill\n\n    \\alert{Quiz:} Can you build a graph with following vertice degrees?\n    \\begin{itemize}\n    \\item 3, 2, 2, 1 (four vertices)\n    \\item 3, 2, 2, 2 (four vertices)\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Verdice Degrees}{The Handshaking Lemma}\n\n  {\\bf Lemma:} The sum of vertice degrees in a graph is 2x the number of edges.\n  \\begin{equation}\n    2|E| = \\sum_{v\\in V} \\text{deg}(v)\n  \\end{equation}\n\n  \\begin{proof}\n    \\begin{itemize}\n      \\item Every edge in a graph connects two vertices;\n      \\item If we begin with a graph with 0 edges, for every edge $(v_i,v_j)$ that we add to the graph, we add 2 vertice degrees (one for $v_i$, one for $v_j$).\n      \\item So the total of vertices is 2 times the total of edges.\n    \\end{itemize}\n  \\end{proof}\\bigskip\n\n  Because of the lemma, it is impossible to make a graph with vertice degrees 3, 2, 2, 2.\n\\end{frame}\n\n\\subsection{Isomorphism}\n\n\\begin{frame}{Review: Isomorphism in graphs}{Remember: an isomorphism is an edge preserving bijection}\n    \\begin{columns}\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (257) at (0,2) {257};\n        \\node[vertex] (122) at (1,2) {122};\n        \\node[vertex] (145) at (2,2) {145};\n        \\node[vertex] (306) at (0,0) {306};\n        \\node[vertex] (67) at (2,0) {67};\n        \\node[vertex] (99) at (1,-1) {99};\n        \\draw[edge] (257) to (122);\n        \\draw[edge] (257) to (99);\n        \\draw[edge] (122) to (99);\n        \\draw[edge] (306) to (99);\n        \\draw[edge] (67) to (99);\n        \\draw[edge] (306) to (67);\n        \\draw[edge] (306) to (145);\n        \\draw[edge] (145) to (99);\n      \\end{tikzpicture}\n\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (257) at (0,2) {257};\n        \\node[vertex] (122) at (2,2) {122};\n        \\node[vertex] (145) at (2,-1) {145};\n        \\node[vertex] (306) at (1,-1) {306};\n        \\node[vertex] (67) at (0,-1) {67};\n        \\node[vertex] (99) at (1,1) {99};\n        \\draw[edge] (257) to (122);\n        \\draw[edge] (257) to (99);\n        \\draw[edge] (122) to (99);\n        \\draw[edge] (306) to (99);\n        \\draw[edge] (67) to (99);\n        \\draw[edge] (306) to (67);\n        \\draw[edge] (306) to (145);\n        \\draw[edge] (145) to (99);\n      \\end{tikzpicture}\n\n    \\end{columns}\\bigskip\n\n    The left and the right are \\structure{the same graph}, but with different positions for the vertices.\n\\end{frame}\n\n\\begin{frame}{Review: Isomorphism in graphs}{Remember: Isomorphism is an edge preserving vertex bijection}\n    \\begin{columns}\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (257) at (0,2) {257};\n        \\node[vertex] (122) at (1,2) {122};\n        \\node[vertex] (145) at (2,2) {145};\n        \\node[vertex] (306) at (0,0) {306};\n        \\node[vertex] (67) at (2,0) {67};\n        \\node[vertex] (99) at (1,-1) {99};\n        \\draw[edge] (257) to (122);\n        \\draw[edge] (257) to (99);\n        \\draw[edge] (122) to (99);\n        \\draw[edge] (306) to (99);\n        \\draw[edge] (67) to (99);\n        \\draw[edge] (306) to (67);\n        \\draw[edge] (306) to (145);\n        \\draw[edge] (145) to (99);\n      \\end{tikzpicture}\n\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (257) at (0,2) {Aki};\n        \\node[vertex] (122) at (1,2) {Bob};\n        \\node[vertex] (145) at (2,2) {Gus};\n        \\node[vertex] (306) at (0,0) {Lyn};\n        \\node[vertex] (67) at (2,0) {Taro};\n        \\node[vertex] (99) at (1,-1) {Emi};\n        \\draw[edge] (257) to (122);\n        \\draw[edge] (257) to (99);\n        \\draw[edge] (122) to (99);\n        \\draw[edge] (306) to (99);\n        \\draw[edge] (67) to (99);\n        \\draw[edge] (306) to (67);\n        \\draw[edge] (306) to (145);\n        \\draw[edge] (145) to (99);\n      \\end{tikzpicture}\n\n    \\end{columns}\\bigskip\n\n    The left and the right are \\structure{the same graph}, but with different {\\bf labels} for the vertices.\n\\end{frame}\n\n\\begin{frame}{Isomorphism}\n\n    \\begin{itemize}\n    \\item Graph Isomorphism is determined solely by the edges between vertices;\\bigskip\n\n    \\item Two graphs with the same edge connections are \\structure{isomorphic};\\bigskip\n\n    \\item Formally, wwo graphs are isomorphic if there is an \\structure{Edge Preserving Matching Relation} between their vertices;\\bigskip\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Isomorphism}{Are these graphs Isomorphic?}\n\n    \\begin{columns}\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (0,0) {Cow};\n        \\node[vertex] (b) at (2,0) {Cat};\n        \\node[vertex] (c) at (0,2) {Dog};\n        \\node[vertex] (d) at (2,2) {Pig};\n        \\draw[edge] (a) to (b);\n        \\draw[edge] (b) to (d);\n        \\draw[edge] (d) to (c);\n        \\draw[edge] (c) to (a);\n        \\draw[edge] (c) to (b);\n      \\end{tikzpicture}\n      \\column{0.5\\textwidth}\n      \\begin{tikzpicture}[scale=1.5,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (1,2) {Hay};\n        \\node[vertex] (b) at (2,0) {Tuna};\n        \\node[vertex] (c) at (0,0) {Beef};\n        \\node[vertex] (d) at (1,1) {Corn};\n        \\draw[edge] (a) to (b);\n        \\draw[edge] (b) to (d);\n        \\draw[edge] (d) to (c);\n        \\draw[edge] (c) to (a);\n        \\draw[edge] (c) to (b);\n      \\end{tikzpicture}\n    \\end{columns}\\bigskip\n\n    Edge Preserving Bijection:\\\\\n    f(dog) = Beef; \\hspace{2cm} f(cow) = Hay\\\\\n    f(cat) = Tuna; \\hspace{2cm} f(pig) = Corn\n\\end{frame}\n\n\\begin{frame}{Graph Isomorphism}{Edge Preserving Bijection}\n\n    $G_1$ \\structure{isomorphic} to $G_2$ means that $\\exists$\n    Edge Preserving Vertex Matching:\n    \\begin{equation*}\n      \\exists f:V_1 \\rightarrow V_2,\n      (u,v) \\in E_1 \\iff (f(u),f(v)) \\in E_2\n    \\end{equation*}\\bigskip\n\n    It is easy to quickly identify {\\bf \\alert{non-isomorphic}} graphs:\n    \\begin{itemize}\n    \\item Not the same number of vertices;\n    \\item Not the same number of edges;\n    \\item Not the same degree distribution;\n    \\item Differences in Paths, Distances, etc...\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{How to find Graph Isomorphism?}\n    \\begin{itemize}\n      \\item Finding the bijection is very hard:\n      \\begin{itemize}\n        \\item Number of bijections: permutation on $|V|$\n      \\end{itemize}\\bigskip\n\n    \\item If the graph is \"small\", can check the permutations by hand;\\bigskip\n\n    \\item If the graph is \"large\", create random matchings $f: V_1 \\rightarrow V_2$, and check:\n      \\begin{itemize}\n        \\item Quickly prune matchings that are {\\bf not} isomorphic:\n        \\item Vertices in the bijection must have the same degree. (ex: a vertice with edge 4 must match to another vertice with edge 4)\n        \\item \\emph{Adjacent vertices} must match degree as well. (ex: A vertice with degree 3, and neighbors with degree 4, 2, 1)\n      \\end{itemize}\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{How to find Graph Isomorphism?}\n\n  Finding an isomorphism for two graphs is a very expensive, and important, problem. In theory, there is no algorithm that is better than just checking every possible bijection.\n\n  \\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{../img/isomorphism}\n    \\pagenote{Isomorphism image from MIT OCW materials}\n  \\end{center}\n\\end{frame}\n", "meta": {"hexsha": "afe28d468927ea3ee9cee3c332efccefcceb197b", "size": 10558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week05/01_GraphIsomorphism.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/01_GraphIsomorphism.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/01_GraphIsomorphism.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": 33.6242038217, "max_line_length": 177, "alphanum_fraction": 0.5706573215, "num_tokens": 3593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6208102506474932}}
{"text": "\\section{Empirical Risk Minimisation (ERM)}\n\n% ===\n\\emph{Cost:}\\enspace\n$R(c,X,Y) = \\sum_{i\\leq N} \\norm{y_i - c^\\top \\bm x_i}^2$\\quad (regr.) \\\\\n\\quad\\textit{or}\\quad\n$R(c,X,Y) = \\sum_{i\\leq N} \\max(0, -y_i c^\\top \\bm x)$\\quad (class.) \\\\\n\\quad\\textit{or}\\quad\n$R(c,\\theta,X) = \\sum_{i\\leq N} \\norm{\\bm x_i - \\theta_{c(i)}}^2$\\quad (clust.)\n\n\\emph{Goal:}\\enspace\n$\\arg\\min\\limits_c \\E[\\mathcal{X}]{ R(c,\\mathcal{X} } \\approx \\arg\\min\\limits_c \\frac1N R(c, X)$\n\n% ===\n\\subsection{Bayesianism / Frequentism}\n\n\\emph{Bayesianism:}\\enspace\nDefine prior $P(\\theta)$, define likelihood $P(X\\mid\\theta)$, compute posterior $P(\\theta\\mid x_{1...n})$.\n\\\\\n\\textbf{Bayes:}\\enspace\n$P(\\theta\\mid X) = \\frac{P(X\\mid\\theta)P(\\theta)}{P(X)}$,\n{\\footnotesize $P(X) {=} \\sum_\\theta P(X\\vert\\theta_i) P(\\theta_i)$}\n\n\\emph{Frequentism:}\\enspace\n%Define a parametric model $\\theta$ (e.g. $\\Gauss{\\theta,1}$), compute likelihood of data and compute MLE: $\\hat\\theta\\ped{MLE} = \\arg\\max_\\theta P(y_{1...n}\\mid\\theta)$.\nDefine param. model $P(Y\\vert X,\\theta)$, compute likelihood of data $P((X,Y)\\mid\\theta)$ and compute $\\hat\\theta\\ped{MLE}$ via $\\arg\\max_\\theta$ of likelihood.\n\n% ===\n\\subsection{Linear Regression\n\\hfill{\\normalfont\\sffamily model:\\enspace $\\color{subsection-text-color} \\hat{\\mathbf y} = \\bm X \\beta$}}\n\n\\emph{Ridge:}\\enspace\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$ \\\\\\quad\n$\\hat\\beta = (\\bm X^\\top \\bm X {\\color{OrangeRed} + \\lambda \\mathbb I})^{-1} \\bm X^\\top \\bm y$,\n\\quad prior: $\\beta \\sim \\Gauss{0, \\frac{\\sigma^2}{\\lambda} \\mathbb I}$\n\n\\emph{Lasso:}\\enspace\n%$\\epsilon\\ped{RSS}(\\beta,\\lambda) = \\sum_{i\\leq n} (y_i - x_i^\\top \\beta)^2 + \\lambda \\norm{\\beta}_2$ \\\\\\quad\n$\\hat\\beta = \\arg\\min_\\beta \\sum_{i\\leq n} (y_i - x_i^\\top \\beta)^2 \\color{OrangeRed} + \\lambda \\norm{\\beta}_2$ \\\\\\quad\n\\textit{(no closed form)},\n\\quad prior: $p(\\beta_i) = \\frac{\\lambda}{4\\sigma^2} \\exp(-\\abs{\\beta_i} \\frac{\\lambda}{2\\sigma^2})$\n\n\n\n% ===\n% === === === === === === ===\n% ===\n\\iffalse\n    \\subsection{Estimation - MLE Properties}\n    \n    \\emph{Consistency:}\n    $\\forall\\epsilon>0, \\; \\mathbb P\\{ \\abs{\\hat\\theta_n - \\theta^\\ast} > \\epsilon \\} \\overset{n\\to\\infty}{\\longrightarrow} 0$\n    \n    \\emph{Equivariance:}\n    If $\\hat\\theta_n$ is MLE of $\\theta$, then $g(\\hat\\theta_n)$ is MLE of $g(\\theta)$.\n    \n    \\emph{Asympt. normality:}\\\\\n    $\\sqrt{N} (\\hat\\theta_n - \\theta^\\ast) \\to \\Gauss{0,\\, J^{-1}(\\theta^\\ast) I(\\theta^\\ast) J^{-1}(\\theta^\\ast)}$%, where $J = -\\E*[x\\mid\\theta^\\ast]{\\frac{\\partial^2 \\log \\P{x\\mid\\theta}}{\\partial\\theta\\partial\\theta^\\top}}$ and $I(\\theta_0) \\triangleq \\textrm{Fisher info}$.\n    \n    \\emph{Asympt. efficiency:}\n    $\\hat\\theta_n$ minimises $\\E{(\\hat\\theta_n - \\theta^\\ast)^2}$ as $n\\to\\infty$, i.e. $\\E{(\\hat\\theta_n - \\theta^\\ast)^2} = \\frac{1}{I^{(n)}(\\theta^\\ast)}$ (Rao Cr.)\\\\\n    Among all consistent estimators $\\hat\\theta_n$ has \\textit{smallest variance}: $\\lim_{n\\to\\infty} (\\V{\\hat\\theta_n} I^{(n)}(\\theta^\\ast))^{-1} = 1$\n\\fi\n\n% ===\n\\iffalse\n    \\subsection{Rao Cramer inequality \\hfill {\\normalfont\\footnotesize all $\\mathbb E$ w.r.t. $P(x\\mid\\theta^\\ast)$}}\n    %(all $\\E{}$ w.r.t. $\\P{x\\mid\\theta^\\ast}$)\n    \n    Score func.: $\\bm\\Lambda = \\pderiv{\\log\\P{x\\mid\\theta}}{\\theta}$,\\; $\\E[x\\mid\\theta^\\ast]{\\bm\\Lambda} = 0$\\\\\n    Fisher info.: $I^{(n)}(\\theta) = \\V[x\\mid\\theta^\\ast]{\\bm\\Lambda}$\\\\\n    $J(\\theta) = \\E[x\\mid\\theta^\\ast]{\\bm\\Lambda^2} = -\\E*{\\frac{\\partial^2 \\log \\P{x\\mid\\theta}}{\\partial\\theta\\partial\\theta^\\top}} = -\\E*{\\pderiv{\\bm\\Lambda}{\\theta}}$\n    \n    \\emph{General bound:} $\\E{(\\hat\\theta - \\theta^\\ast)^2} \\geq \\frac{\\paren*{ 1 + \\partial \\mathrm{b}_{\\hat\\theta} / \\partial\\theta }^2}{\\E{\\bm\\Lambda^2}} + \\mathrm{b}_{\\hat\\theta}$\n    \n    \\emph{Unbiased case:} $\\E{(\\hat\\theta - \\theta^\\ast)^2} = \\V{\\hat\\theta_n} \\geq \\frac{1}{I^{(n)}(\\theta^\\ast)}$\n    \n    \\emph{Tradeoff:}\n    $\\E{(\\hat\\theta_n - \\theta^\\ast)^2} = \\V{\\hat\\theta_n} + \\mathrm{bias}^2(\\hat\\theta_n)$\n    \n    \\emph{Bias:}\n    $\\mathrm{bias}(\\hat\\theta_n) \\equiv \\mathrm{b}_{\\hat\\theta}(\\theta^\\ast) = \\E{\\hat\\theta_n} - \\theta^\\ast \\overset{\\textrm{unbiased}}{=} 0$\n\\fi\n\n% ===\n", "meta": {"hexsha": "7f926a0648ff66a347c34861bfbe724b7c2efae9", "size": 4257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/02_emp_risk_min.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/02_emp_risk_min.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/02_emp_risk_min.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.5, "max_line_length": 278, "alphanum_fraction": 0.6006577402, "num_tokens": 1720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.620810246578751}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{amsmath}\n\n\\newcommand{\\F}{\\mathbf{F}}\n\\newcommand{\\N}{\\mathbf{N}}\n\\renewcommand{\\S}{\\mathbf{S}}\n\\newcommand{\\D}{\\mathbf{D}}\n\\newcommand{\\X}{\\mathbf{X}}\n\\newcommand{\\f}{\\mathbf{f}}\n\\renewcommand{\\P}{\\mathbf{P}}\n\\newcommand{\\Ds}{\\D_s}\n\\newcommand{\\Dm}{\\D_m}\n\\renewcommand{\\o}{\\mathbf{1}}\n\\newcommand{\\I}{\\mathbf{I}}\n\\newcommand{\\tr}{\\mbox{tr}}\n\\newcommand{\\m}[1]{\\begin{pmatrix}#1\\end{pmatrix}}\n\\newcommand{\\pp}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\\begin{document}\n\n\\section{Finite Elements}\n\n\\begin{tabular}{|c|c|cc|l|}\n\\hline\nSymbol & Definition & Dimensions & Units & Meaning \\\\\n\\hline\n$\\o$ & $\\o = \\m{1 & \\cdots & 1}^T$ & $d$ & $1$ & All ones vector \\\\\n$\\S$ & $\\S = \\m{\\I & -\\o}$ & $d \\times (d+1)$ & $1$ & Scatter matrix \\\\\n\\hline\n$\\X_m$ & $\\m{X_1 & X_2 & X_3 & X_4}_m$ & $d \\times (d+1)$ & $m$ & Material space element node positions \\\\\n$\\X$ & $\\m{X_1 & X_2 & X_3 & X_4}$ & $d \\times (d+1)$ & $m$ & World space element node positions \\\\\n$\\Dm$ & $\\Dm = \\X_m \\S^T$ & $d \\times d$ & $m$ & Material space relative node positions \\\\\n$\\Ds$ & $\\Ds = \\X \\S^T$ & $d \\times d$ & $m$ & World space relative node positions \\\\\n$\\F$ & $\\F = \\Ds \\Dm^{-1}$ & $d \\times d$ & $1$ & Deformation gradient \\\\\n\\hline\n$J$ & $J = \\det(\\F)$ & scalar & $1$ & Jacobian \\\\\n$I_1$ & $I_1 = \\tr(\\F \\F^T)$ & scalar & $1$ & First invariant \\\\\n\\hline\n$V$ & $V = \\frac{1}{d!} \\det(\\Dm)$ & scalar & $m^d$ & Material space element volume \\\\\n$\\N$ & $\\N = V \\Dm^{-T}$ & $d \\times d$ & $m^{d-1}$ & Material space area weighted normals \\\\\n\\hline\n$\\psi$ & - & scalar & $kg \\, m^{2-d} s^{-1}$ & Energy density \\\\\n$\\phi$ & $\\phi = V \\psi$ & scalar & $kg \\, m^2 s^{-1}$ & Potential energy of element \\\\\n$\\f$ & $\\f = -\\pp{\\phi}{\\X}$ & $d \\times (d+1)$ & $kg \\, m s^{-1}$ & Force on element nodes \\\\\n$\\P$ & $\\f = -\\P \\N \\S^T$ & $d \\times d$ & $kg \\, m^{2-d} s^{-1}$ & First Piola-Kirchoff stress \\\\\n\\hline\n\\end{tabular}\n\\vspace{.2in}\n\nConsider that a small position change $\\delta \\X$ is made.  Then\n\\begin{eqnarray*}\n0 & = & \\f : \\delta \\X + \\delta \\phi \\\\\n& = & \\tr(\\f \\delta \\X^T) + \\delta \\phi \\\\\n& = & \\tr(-\\P \\N \\S^T \\delta \\X^T) + V \\delta \\psi \\\\\n& = & -V \\tr(\\P \\Dm^{-T} \\S^T \\delta \\X^T) + V \\delta \\psi \\\\\n\\delta \\psi & = & \\tr(\\P \\Dm^{-T} \\S^T \\delta \\X^T) \\\\\n& = & \\tr(\\P \\delta (\\Dm^{-T} \\S^T \\X^T)) \\\\\n& = & \\tr(\\P \\delta (\\Dm^{-T} \\Ds^T)) \\\\\n& = & \\tr(\\P \\delta \\F^T) \\\\\n& = & \\P : \\delta \\F \\\\\n\\P & = & \\pp{\\psi}{\\F}\n\\end{eqnarray*}\n\n\\section{Potential Energy for Neo Hookean}\n\nLet $\\psi = \\frac{\\mu}{2} (I_1 - d) - \\mu \\ln J + \\frac{\\lambda}{2} \\ln^2 J$.\n\n\\begin{eqnarray*}\n\\pp{J}{\\F} & = & \\pp{}{\\F} \\det(\\F) = \\det(\\F) \\F^{-1} = J \\F^{-1} \\\\\n\\pp{I_1}{\\F} & = & \\pp{}{\\F} \\tr(\\F \\F^T) = 2 \\F \\\\\n\\pp{}{\\F} & = & \\pp{}{\\F} \\ln J = \\F^{-1} \\\\\n\\P = \\pp{\\psi}{\\X} & = & \\pp{}{\\X} \\left( \\frac{\\mu}{2} (I_1 - d) - \\mu \\ln J + \\frac{\\lambda}{2} \\ln^2 J \\right) \\\\\n& = & \\frac{\\mu}{2} \\pp{I_1}{\\X} - \\mu \\pp{}{\\F} \\ln J + \\lambda \\ln J \\pp{}{\\F} \\ln J \\\\\n& = & \\mu (\\F - \\F^{-1}) + \\lambda \\ln J \\F^{-1}\n\\end{eqnarray*}\n\n\n\\end{document}\n", "meta": {"hexsha": "1b144ab169b484e4a713dad5c52b1888a0d64e39", "size": 3064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "applications/physbam/physbam-lib/Public_Library/PhysBAM_Solids/PhysBAM_Deformables/Constitutive_Models/neo_hookean_energy.tex", "max_stars_repo_name": "schinmayee/nimbus", "max_stars_repo_head_hexsha": "170cd15e24a7a88243a6ea80aabadc0fc0e6e177", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2017-07-03T19:09:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T02:53:56.000Z", "max_issues_repo_path": "applications/physbam/physbam-lib/Public_Library/PhysBAM_Solids/PhysBAM_Deformables/Constitutive_Models/neo_hookean_energy.tex", "max_issues_repo_name": "schinmayee/nimbus", "max_issues_repo_head_hexsha": "170cd15e24a7a88243a6ea80aabadc0fc0e6e177", "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": "applications/physbam/physbam-lib/Public_Library/PhysBAM_Solids/PhysBAM_Deformables/Constitutive_Models/neo_hookean_energy.tex", "max_forks_repo_name": "schinmayee/nimbus", "max_forks_repo_head_hexsha": "170cd15e24a7a88243a6ea80aabadc0fc0e6e177", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-09-17T02:05:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-31T00:12:01.000Z", "avg_line_length": 38.3, "max_line_length": 116, "alphanum_fraction": 0.5127284595, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6207342738466815}}
{"text": "\\section{Eigenvectors and eigenvalues}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a vector is an eigenvector of a matrix.\n  \\item Given an eigenvector, find the corresponding eigenvalue.\n  \\item Given an eigenvalue, find the corresponding eigenvectors.\n  \\item Find a basis for the eigenspace of a given eigenvalue.\n  \\end{enumerate}\n\\end{outcome}\n\nWhen we multiply a square matrix $A$ by a non-zero vector $\\vect{v}$,\nwe obtain another vector $A\\vect{v}$. Most of the time, the vectors\n$A\\vect{v}$ and $\\vect{v}$ are unrelated; they could point in\ncompletely different directions. However, sometimes it can happen that\n$A\\vect{v}$ is a scalar multiple of $\\vect{v}$. In that case,\n$\\vect{v}$ is called an \\textbf{eigenvector} of $A$. We will see later\nin this chapter that we can learn a lot about the matrix $A$ by\nconsidering its eigenvectors.\n\n\\begin{definition}{Eigenvalues and eigenvectors}{eigenvalues-and-eigenvectors}\n  Let $A$ be an $n\\times n$-matrix. Suppose that $\\vect{v}\\in\\R^n$ is\n  a non-zero vector such that $A\\vect{v}$ is a scalar multiple of\n  $\\vect{v}$. In other words, suppose that there exists a scalar\n  $\\eigenvar$ such that\n  \\begin{equation*}\n    A\\vect{v}=\\eigenvar\\vect{v}.\n  \\end{equation*}\n  Then $\\vect{v}$ is called an \\textbf{eigenvector}%\n  \\index{eigenvector}%\n  \\index{vector!eigenvector}%\n  \\index{matrix!eigenvector} of $A$, and $\\eigenvar$ is called the\n  corresponding \\textbf{eigenvalue}%\n  \\index{eigenvalue}%\n  \\index{matrix!eigenvalue}.\n\\end{definition}\n\n\\begin{example}{Eigenvalues and eigenvectors}{eigenvalues-and-eigenvectors}\n  Consider the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      3 & -2 &  2 \\\\\n      1 &  2 &  1 \\\\\n      0 &  2 &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Which of the following vectors are eigenvectors of $A$? Find the\n  corresponding eigenvalues.\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 2 \\\\ -1 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{v}_4 = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We compute\n  \\begin{equation*}\n    A\\vect{v}_1 = \\begin{mymatrix}{r} 4 \\\\ -2 \\\\ -4 \\end{mymatrix},\\quad\n    A\\vect{v}_2 = \\begin{mymatrix}{r} 0 \\\\ 3 \\\\ 3 \\end{mymatrix},\\quad\n    A\\vect{v}_3 = \\begin{mymatrix}{r} 3 \\\\ 4 \\\\ 3 \\end{mymatrix},\\quad\n    A\\vect{v}_4 = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{itemize}\n  \\item We see that $A\\vect{v}_1$ is a scalar multiple of\n    $\\vect{v}_1$, namely $A\\vect{v}_1=2\\vect{v}_1$. Therefore,\n    $\\vect{v}_1$ is an eigenvector of $A$ with corresponding\n    eigenvalue $\\eigenvar=2$.\n  \\item Similarly, $A\\vect{v}_2=3\\vect{v}_2$, so $\\vect{v}_2$ is an\n    eigenvector of $A$ with corresponding eigenvalue $\\eigenvar=3$.\n  \\item On the other hand, $A\\vect{v}_3$ is not a scalar multiple of\n    $\\vect{v}_3$. Hence, $\\vect{v}_3$ is not an eigenvector of $A$.\n  \\item Finally, although $A\\vect{v}_4$ is a scalar multiple of\n    $\\vect{v}_4$, the zero vector is not considered an eigenvector.\n  \\end{itemize}\n\\end{solution}\n\n\\begin{example}{Find eigenvectors for the given eigenvalue}{find-eigenvectors-given-eigenvalue}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2  &  0 & 0 \\\\\n      -1 &  3 & 1 \\\\\n      2  & -2 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the eigenvectors corresponding to the eigenvalue $\\eigenvar=2$.\n\\end{example}\n\n\\begin{solution}\n  We have to solve the equation $A\\vect{v}=2\\vect{v}$. We can use\n  algebra to rewrite this as\n  \\begin{eqnarray*}\n    A\\vect{v} = 2\\vect{v}\n    &\\iff& A\\vect{v} - 2\\vect{v} = \\vect{0} \\\\\n    &\\iff& (A-2I)\\vect{v} = \\vect{0} \\\\\n    &\\iff& \\begin{mymatrix}{rrr}\n      0  &  0 & 0 \\\\\n      -1 &  1 & 1 \\\\\n      2  & -2 & -2 \\\\\n    \\end{mymatrix}\\vect{v}\n    = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{eqnarray*}\n  This is a homogeneous system of equations with general\n  solution\n  \\begin{equation*}\n    \\vect{v}\n    ~=~ s \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n  \\end{equation*}\n  where $s$ and $t$ are parameters. These (except the zero vector) are\n  exactly the eigenvectors corresponding to the eigenvalue $\\eigenvar = 2$.\n\\end{solution}\n\nAs the last example shows, the eigenvectors for a given eigenvalue\n$\\eigenvar$, plus the zero vector, form a subspace of $\\R^n$. This is\ncalled the \\textbf{eigenspace} of $\\eigenvar$.\n\n\\begin{definition}{Eigenspace}{eigenspace}\n  Let $A$ be an $n\\times n$-matrix, and let $\\eigenvar$ be an eigenvalue\n  of $A$. The \\textbf{eigenspace}%\n  \\index{eigenspace}%\n  \\index{matrix!eigenspace}%\n  \\index{subspace!eigenspace} of $\\eigenvar$ is the set\n  \\begin{equation*}\n    E_{\\eigenvar} = \\set{\\vect{v} \\mid A\\vect{v}=\\eigenvar\\vect{v}}.\n  \\end{equation*}\n  It is a subspace of $\\R^n$.\n\\end{definition}\n\nInstead of finding {\\em all} eigenvectors for a given eigenvalue, it\nis often sufficient to find a basis for the eigenspace. We also\nsometimes call the basis vectors of the eigenspace \\textbf{basic\n  eigenvectors}%\n\\index{basic eigenvector}%\n\\index{eigenvector!basic}%\n\\index{matrix!eigenvector!basic}.\n\n\\begin{example}{Basis of eigenspace}{basis-eigenspace}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2  &  0 & 0 \\\\\n      -1 &  3 & 1 \\\\\n      2  & -2 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The matrix $A$ has eigenvalues $\\eigenvar=1$ and $\\eigenvar=2$. Find a\n  basis for each eigenspace.\n\\end{example}\n\n\\begin{solution}\n  We already found a basis for the eigenspace $E_2$ in\n  Example~\\ref{exa:find-eigenvectors-given-eigenvalue}.\n  \\begin{equation*}\n    \\mbox{Basis of $E_2$:}\\quad\\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n      \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  To find a basis for the eigenspace $E_1$, we proceed analogously.\n  We must solve the equation $A\\vect{v}=1\\vect{v}$. We have:\n  \\begin{eqnarray*}\n    A\\vect{v} = 1\\vect{v}\n    &\\iff& A\\vect{v} - \\vect{v} = \\vect{0} \\\\\n    &\\iff& (A-I)\\vect{v} = \\vect{0} \\\\\n    &\\iff& \\begin{mymatrix}{rrr}\n      1  &  0 & 0 \\\\\n      -1 &  2 & 1 \\\\\n      2  & -2 & -1 \\\\\n    \\end{mymatrix}\\vect{v}\n    = \\begin{mymatrix}{r} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{eqnarray*}\n  This is a homogeneous system of rank 2, with general solution\n  \\begin{equation*}\n    \\vect{v}\n    ~=~ t \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the following is a basis for the eigenspace $E_1$:\n  \\begin{equation*}\n    \\mbox{Basis of $E_1$:}\\quad\\set{\n      \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 2 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "ec22f4be895d5588104ec923dec327adfced723c", "size": 6781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-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/Eigenvalues-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/Eigenvalues-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": 36.2620320856, "max_line_length": 95, "alphanum_fraction": 0.6445951924, "num_tokens": 2566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6207342738466813}}
{"text": "\\lab{CVXOPT}{CVXOPT}\n\\objective{CVXOPT is a package of Python functions and classes designed for the purpose of convex optimization.\nIn this lab we use these tools for linear and quadratic programming.\nWe will solve various optimization problems using CVXOPT and optimize eating healthily on a budget.}\n\n%\\begin{warn}\n%CVXOPT is not part of the standard library, and it is only included in the Anaconda distribution for Python 3.6 for Linux and Mac.\n%We recommend avoiding Windows machines for this lab.\n%\n%To install CVXOPT, use \\li{conda install cvxopt} or \\li{pip install cvxopt}.\n%\\end{warn}\n\n\\section*{Linear Programs} % ==================================================\n\n%%Cvxopt has linear program solver and can implement integer programming through the Gnu Linear Programming Kit, glpk.\n%CVXOPT is a package of Python functions and classes designed for the purpose of convex optimization.\n%In this lab we will focus on linear and quadratic programming.\nA \\emph{linear program} is a linear constrained optimization problem. Such a problem can be stated in several\ndifferent forms, one of which is\n\\begin{align*}\n\\text{minimize}\\qquad &\\c\\trp \\x \\\\\n\\text{subject to}\\qquad &G\\x \\preceq \\mathbf{h}\\\\\n&A\\x = \\b.\n\\end{align*}\n\nThe symbol $\\preceq$ denotes that the components of $G\\x$ are less than the components of $\\mathbf{h}$. In other words, if $\\x\\preceq\\y$, then $x_i < y_i$ for all $x_i\\in\\x$ and $y_i\\in\\y$. \n\nDefine vector $\\mathbf{s} \\succeq \\0$ such that the constraint $G\\x + \\mathbf{s} = \\mathbf{h}$. \nThis vector is known as a \\emph{slack variable}. \nSince $\\mathbf{s} \\succeq \\0$, the constraint\n$G\\x + \\mathbf{s} = \\mathbf{h}$ is equivalent to $G\\x \\preceq \\mathbf{h}$.\n\nWith a slack variable, a new form of the linear program is found:\n\\begin{align*}\n\\text{minimize}\\qquad &\\c\\trp \\x \\\\\n\\text{subject to}\\qquad &G\\x + \\mathbf{s} = \\mathbf{h}\\\\\n&A\\x = \\b \\\\\n&\\mathbf{s} \\succeq \\0.\n\\end{align*}\n\nThis is the formulation used by CVXOPT.\nIt requires that the matrix $A$ has full row rank,\nand that the block matrix $[G \\quad A]\\trp $ has full column rank.\n\n% \\preceq \\succeq\n\n% Students have not yet learned about the dual problem. May be included in a later lab.\n\\begin{comment}\nThe corresponding \\emph{dual program} for the above linear program has the form\n\\begin{align*}\n\\text{maximize}\\qquad &-h\\trp z - b\\trp y \\\\\n\\text{subject to}\\qquad &G\\trp z + A\\trp y + c = 0\\\\\n &z \\geq 0.\n\\end{align*}\nCVXOPT provides functions to solve both the original (\\emph{primal}) linear program and its dual program.\n\\end{comment}\n\nConsider the following example:\n\\begin{align*}\n\\text{minimize}\\qquad &-4x_1-5x_2 \\\\\n\\text{subject to}\\qquad &x_1+2x_2 \\leq 3 \\\\\n\t        &2x_1+x_2 = 3 \\\\\n\t\t&x_1, x_2 \\geq 0\n\\end{align*}\nRecall that all inequalities must be less than or equal to, so that $G\\x\\preceq \\mathbf{h}$.\nBecause the final two constraints are $x_1, x_2 \\geq 0$, they need to be adjusted to be $\\leq$ constraints.\nThis is easily done by multiplying by $-1$, resulting in the constraints $-x_1, -x_2 \\leq 0$.\nIf we define\n\\[\nG = \\begin{bmatrix}\n  1 & 2\\\\\n  -1 & 0\\\\\n  0 & -1\n\\end{bmatrix} \\text{, } \\qquad\n\\mathbf{h} = \\begin{bmatrix}\n  3\\\\\n  0\\\\\n  0\n\\end{bmatrix} \\text{, } \\qquad\nA = \\begin{bmatrix}\n2 & 1\n\\end{bmatrix} \\text{, } \\quad \\text{and } \\qquad\n\\mathbf{b} = \\begin{bmatrix}\n3\n\\end{bmatrix}\n\\]\nthen we can express the constraints compactly as\n\\[\n\\begin{matrix}\nG\\x \\preceq \\mathbf{h},\\\\\nA\\x = \\mathbf{b},\n\\end{matrix}  \\qquad \\text{where} \\qquad\n\\x = \\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix}.\n\\]\nBy adding a slack variable $\\mathbf{s}$, we can write our constraints as\n\\[\nG\\x + \\mathbf{s} = \\mathbf{h},\n\\]\nwhich matches the form discussed above.\n% In the case of this particular example, we ignore the extra constraint\n%\\[\n%A\\x = \\b,\n%\\]\n%since we were given no equality constraints.\n\nTo solve the problem using CVXOPT, initialize the arrays $\\c$, $G$, $\\mathbf{h}$, $A$, and $\\mathbf{b}$ and pass them to the appropriate function.\nCVXOPT uses its own data type for an array or matrix. \nWhile similar to the NumPy array, it does have a few differences, especially when it comes to initialization.\nBelow, we initialize CVXOPT matrices for $\\mathbf{c}$, $G$, $\\mathbf{h}$, $A$, and $\\mathbf{b}$.\nWe then use the CVXOPT function for linear programming \\li{solvers.lp()}, which accepts $\\c$, $G$, $\\mathbf{h}$, $A$, and $\\b$ as arguments.\n\n\\begin{lstlisting}\n>>> from cvxopt import matrix, solvers\n\n>>> c = matrix([-4., -5.])\n>>> G = matrix([[1., -1., 0.],[2., 0., -1.]])\n>>> h = matrix([ 3., 0., 0.])\n>>> A = matrix([[2.],[1.]])\n>>> b = matrix([3.])\n\n>>> sol = solvers.lp(c, G, h, A, b)\n     pcost       dcost       gap    pres   dres   k/t\n 0: -8.5714e+00 -1.4143e+01  4e+00  0e+00  3e-01  1e+00\n 1: -8.9385e+00 -9.2036e+00  2e-01  3e-16  1e-02  3e-02\n 2: -8.9994e+00 -9.0021e+00  2e-03  3e-16  1e-04  3e-04\n 3: -9.0000e+00 -9.0000e+00  2e-05  1e-16  1e-06  3e-06\n 4: -9.0000e+00 -9.0000e+00  2e-07  1e-16  1e-08  3e-08\nOptimal solution found.\n>>> print(sol['x'])\n[ 1.00e+00]\n[ 1.00e+00]\n>>> print(sol['primal objective'])\n-8.999999939019435\n>>> print(type(sol['x']))\n<<<class 'cvxopt.base.matrix'>>>\n\\end{lstlisting}\n\n\\begin{warn}\nCVXOPT matrices only accept floats. \nOther data types will raise a \\li{TypeError}.\n\nAdditionally, CVXOPT matrices are initialized column-wise rather than row-wise (as in the case of NumPy).\nAlternatively, we can initialize the arrays first in NumPy (a process with which you should be familiar),\nand then simply convert them to the CVXOPT matrix data type.\n\\begin{lstlisting}\n>>> import numpy as np\n\n>>> c = np.array([-4., -5.])\n>>> G = np.array([[1., 2.],[-1., 0.],[0., -1]])\n>>> h = np.array([3., 0., 0.])\n>>> A = np.array([[2., 1.]])\n>>> b = np.array([3.])\n\n# Convert the arrays to the CVXOPT matrix type.\n>>> c = matrix(c)\n>>> G = matrix(G)\n>>> h = matrix(h)\n>>> A = matrix(A)\n>>> b = matrix(b)\n\\end{lstlisting}\nIn this lab we will initialize non-trivial matrices first as NumPy arrays for consistency.\n\n%Finally, be sure the entries in the matrices are floats!\n\\end{warn}\n\n%Having initialized the necessary objects, we are now ready to solve the problem.\n\n\\begin{info}\nAlthough it is often helpful to see the progress of each iteration of the algorithm, you may suppress this output by first running,\n\\begin{lstlisting}\nsolvers.options['show_progress'] = False\n\\end{lstlisting}\n\\end{info}\n\nThe function \\li{solvers.lp()} returns a dictionary containing useful information.\nFor now, we will only focus on the value of $\\x$ and the primal objective value (i.e. the minimum value achieved by the objective function).\n\n\\begin{warn}\nNote that the minimizer \\li{x} returned by the \\li{solvers.lp()} function is a \\li{cvxopt.base.matrix} object.\n\\li{np.ravel()} is a NumPy function that takes an object and returns its values as a flattened NumPy array.\nUse \\li{np.ravel()} to return all minimizers in this lab as flattened NumPy arrays.\n\\end{warn}\n\n\\begin{problem}\nSolve the following convex optimization problem:\n\\begin{align*}\n\\text{minimize}\\qquad &2x_1+x_2+3x_3 \\\\\n\\text{subject to}\\qquad &x_1+2x_2 \\geq 3 \\\\\n\t        &2x_1+10x_2+3x_3 \\geq 10 \\\\\n\t\t&x_1 \\geq 0 \\\\\n\t\t&x_2 \\geq 0 \\\\\n\t\t&x_3 \\geq 0\n\\end{align*}\nReturn the minimizer $\\x$ and the primal objective value.\n\\\\(Hint: make the necessary adjustments so that all inequality constraints are $\\leq$ rather than $\\geq$).\n\\end{problem}\n\n\\subsection*{$l_1$ Norm}\nThe $l_1$ norm is defined \n\\[||\\x||_1=\\sum_{i=1}^n |x_i|.\\]\nA $l_1$ minimization problem is minimizing a vector's $l_1$ norm, while fitting certain constraints. It can be written in the following form:\n\\begin{align*}\n\\text{minimize}\\qquad &\\|\\x\\|_1\\\\\n\\text{subject to} \\qquad &A\\x = \\b.\n\\end{align*}\n\nThis problem can be converted into a linear program by introducing an additional vector $\\u$ of length $n$.\nDefine $\\u$ such that $|x_i|\\leq u_i$. \nThus, $-u_i-x_i\\leq 0$ and $-u_i+x_i\\leq 0$.\nThese two inequalities can be added to the linear system as constraints.\nAdditionally, this means that $||\\x||_1\\leq ||\\u||_1$.\nSo minimizing $||\\u||_1$ subject to the given constraints will in turn minimize $||\\x||_1$.\nThis can be written as follows:\n\\begin{align*}\n\\text{minimize}\\qquad\n&\\begin{bmatrix}\n\\mathbf{1}\\trp & \\0\\trp\n\\end{bmatrix}\n\\begin{bmatrix}\n\\u \\\\\n\\x\n\\end{bmatrix}\\\\\n\\text{subject to}\\qquad\n&\\begin{bmatrix}\n-I & I\\\\\n-I & -I\\\\\n-I & \\0\n\\end{bmatrix}\n\\begin{bmatrix}\n\\u \\\\\n\\x\n\\end{bmatrix}\n\\preceq\n\\begin{bmatrix}\n0\\\\\n0\n\\end{bmatrix},\\\\\n&\\begin{bmatrix}\n\\0 & A\n\\end{bmatrix}\n\\begin{bmatrix}\n\\u \\\\\n\\x\n\\end{bmatrix}\n=\n\\b.\n\\end{align*}\nSolving this gives values for the optimal $\\u$ and the optimal $\\x$, but we only care about the optimal $\\x$.\n\n\\begin{problem}\nWrite a function called \\li{l1Min()} that accepts a matrix $A$ and vector $\\mathbf{b}$ as NumPy arrays and solves the $l_1$ minimization problem.\nReturn the minimizer $\\x$ and the primal objective value.\nRemember to first discard the unnecessary $u$ values from the minimizer.\n\nTo test your function consider the matrix $A$ and vector $\\mathbf{b}$ below.\n\\[\nA = \\begin{bmatrix}\n1 & 2 & 1 & 1\\\\\n0 & 3 & -2 & -1\n\\end{bmatrix} \\qquad\n\\mathbf{b} = \\begin{bmatrix}\n7 \\\\\n4\n\\end{bmatrix}\n\\]\nThe linear system $A\\x = \\b$ has infinitely many solutions.\nUse \\li{l1Min()} to verify that the solution which minimizes $||\\mathbf{x}||_1$ is approximately $\\x = [0., 2.571, 1.857, 0.]^T$ and the minimum objective value is approximately $4.429$.\n\\label{prob:l1}\n\\end{problem}\n\n\\section*{The Transportation Problem}\n\nConsider the following transportation problem:\nA piano company needs to transport thirteen pianos from their three  supply centers (denoted by 1, 2, 3) to two demand centers (4, 5).\nTransporting a piano from a supply center to a demand center incurs a cost, listed in Table \\ref{tab:cost}.\nThe company wants to minimize shipping costs for the pianos while meeting the demand.\n%How many pianos should each supply center send to each demand center?\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|}\nSupply Center & Number of pianos available\\\\\n\\hline\n1 & 7\\\\\n2 & 2\\\\\n3 & 4\\\\\n\\end{tabular}\n\n\\caption{Number of pianos available at each supply center}\n\\label{tab:supply}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|}\nDemand Center & Number of pianos needed\\\\\n\\hline\n4 & 5\\\\\n5 & 8\\\\\n\\end{tabular}\n\n\\caption{Number of pianos needed at each demand center}\n\\label{tab:demand}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|c|c|}\nSupply Center & Demand Center & Cost of transportation & Number of pianos\\\\\n\\hline\n1 & 4 & 4 & $p_1$\\\\\n1 & 5 & 7 & $p_2$\\\\\n2 & 4 & 6 & $p_3$\\\\\n2 & 5 & 8 & $p_4$\\\\\n3 & 4 & 8 & $p_5$\\\\\n3 & 5 & 9 & $p_6$\\\\\n\\end{tabular}\n\\caption{Cost of transporting one piano from a supply center to a demand center}\n\\label{tab:cost}\n\\end{table}\n\nA system of constraints is defined for the variables $p_1,p_2,p_3,p_4,p_5,$ and $p_6$,\nFirst, there cannot be a negative number of pianos so the variables must be nonnegative.\nNext, the Tables \\ref{tab:supply} and \\ref{tab:demand} define the following three supply constraints and two demand constraints:\n\\begin{align*}\np_1 + p_2  &= 7\\\\\np_3 + p_4  &= 2\\\\\np_5 + p_6  &= 4\\\\\np_1 + p_3 + p_5 &= 5\\\\\np_2 + p_4 + p_6 &= 8\n\\end{align*}\n\nThe objective function is the number of pianos shipped from each location multiplied by the respective cost (found in Table \\ref{tab:cost}):\n\\[\n4p_1 + 7p_2 + 6p_3 + 8p_4 + 8p_5 + 9p_6.\n\\]\n\n\\begin{info}\nSince our answers must be integers, in general this problem turns out to be an NP-hard problem.\nThere is a whole field devoted to dealing with integer constraints, called \\emph{integer linear programming}, which is beyond the scope of this lab.\nFortunately, we can treat this particular problem as a standard linear program and still obtain integer solutions.\n\\end{info}\n\nRecall the variables are nonnegative, so $p_1,p_2,p_3,p_4,p_5,p_6\\geq 0$.\nThus, $G$ and $\\mathbf{h}$ constrain the variables to be non-negative.\nBecause CVXOPT uses the format $G\\x \\preceq \\mathbf{h}$, we see that this inequality must be multiplied by $-1$. \nSo, $G$ must be a $6 \\times 6$ identity matrix multiplied by $-1$, and\n\n$\\mathbf{h}$ is a column vector of zeros.\nSince the supply and demand constraints are equality constraints, they are $A$ and $\\b$.\nInitialize these arrays and solve the linear program by entering the code below.\n\\begin{lstlisting}\n>>> c = matrix(np.array([4., 7., 6., 8., 8., 9.]))\n>>> G = matrix(-1*np.eye(6))\n>>> h = matrix(np.zeros(6))\n>>> A = matrix(np.array([[1.,1.,0.,0.,0.,0.],\n                         [0.,0.,1.,1.,0.,0.],\n                         [0.,0.,0.,0.,1.,1.],\n                         [1.,0.,1.,0.,1.,0.],\n                         [0.,1.,0.,1.,0.,1.]]))\n>>> b = matrix(np.array([7., 2., 4., 5., 8.]))\n>>> sol = solvers.lp(c, G, h, A, b)\n     pcost       dcost       gap    pres   dres   k/t\n 0:  8.9500e+01  8.9500e+01  2e+01  2e-16  2e-01  1e+00\n 1:  8.7023e+01  8.7044e+01  3e+00  1e-15  3e-02  2e-01\nTerminated (singular KKT matrix).\n>>> print(sol['x'])\n[ 4.31e+00]\n[ 2.69e+00]\n[ 3.56e-01]\n[ 1.64e+00]\n[ 3.34e-01]\n[ 3.67e+00]\n>>> print(sol['primal objective'])\n87.023\n\\end{lstlisting}\nNotice that some problems occurred. First, CVXOPT alerted us to the fact that the algorithm terminated prematurely (due to a singular matrix).\nSecond, the minimizer and solution obtained do not consist of integer entries.\n\nSo what went wrong? Recall that the matrix $A$ is required to have full row rank, but we can easily see that the rows of $A$\nare linearly dependent. We rectify this by converting the last row of the equality constraints into two \\emph{inequality} constraints, so that\nthe remaining equality constraints define a new matrix $A$ with linearly independent rows.\n\nThis is done as follows:\n\n Suppose we have the equality constraint\n\\[\nx_1 + 2x_2 - 3x_3 = 4.\n\\]\nThis is equivalent to the pair of inequality\nconstraints\n\\begin{align*}\nx_1 + 2x_2 - 3x_3 &\\leq 4, \\\\\nx_1 + 2x_2 - 3x_3 &\\geq 4.\n\\end{align*}\nThe linear program requires only $\\leq$ constraints, so we obtain the pair\nof constraints\n\\begin{align*}\nx_1 + 2x_2 - 3x_3 &\\leq 4, \\\\\n-x_1 - 2x_2 + 3x_3 &\\leq -4.\n\\end{align*}\n\nApply this process to the last equality constraint of the transportation problem.\nThen define a new matrix $G$ with several additional rows (to account for the new inequality\nconstraints), a new vector $\\mathbf{h}$ with more entries, a smaller matrix $A$, and a smaller vector $\\b$.\n\\begin{problem}\nSolve the transportation problem by converting the last equality constraint into an inequality constraint.\nReturn the minimizer $\\x$ and the primal objective value.\n\\end{problem}\n\n\\begin{comment}\n\\section*{Example}\n\nWhy are all of the terms in $G$ and $\\mathbf{h}$ non-positive?\n\n\\begin{lstlisting}\n>>> from cvxopt import matrix, solvers\n>>> G = matrix([ [-1., 0., 0., -1., 0.,  -1., 0., 0., 0., 0., 0.],\n             [-1., 0., 0., 0., -1.,  0., -1., 0., 0., 0., 0.],\n             [0., -1., 0., -1., 0.,  0., 0., -1., 0., 0., 0.],\n             [0., -1., 0., 0., -1.,  0., 0., 0., -1., 0., 0.],\n             [0., 0., -1., -1., 0.,  0., 0., 0., 0., -1., 0.],\n             [0., 0., -1., 0., -1.,  0., 0., 0., 0., 0., -1.] ])\n\n>>> h = matrix([-7., -2., -4., -5., -8.,  0., 0., 0., 0., 0., 0.,])\n>>> c = matrix([4., 7., 6., 8., 8., 9])\n>>> sol = solvers.lp(c,G,h)\n>>> print sol['x']\n>>> print sol['primal objective']\n\\end{lstlisting}\n\nAnother method is to use an integer linear program.\nCvxopt is configured to work with  Gnu, which does have an integer linear program.\nIt will work with either of the methods above.\n\n\\textbf{Example}\n\nglpk.ilp returns a tuple.\nThe first entry describes the optimality of the result, while the second gives the $x$ values.\n\n\\begin{lstlisting}\n>>> from cvxopt import matrix, solvers, glpk\n>>> G = matrix([ [-1., 0., 0., -1., 0.,  -1., 0., 0., 0., 0., 0.],\n             [-1., 0., 0., 0., -1.,  0., -1., 0., 0., 0., 0.],\n             [0., -1., 0., -1., 0.,  0., 0., -1., 0., 0., 0.],\n             [0., -1., 0., 0., -1.,  0., 0., 0., -1., 0., 0.],\n             [0., 0., -1., -1., 0.,  0., 0., 0., 0., -1., 0.],\n             [0., 0., -1., 0., -1.,  0., 0., 0., 0., 0., -1.] ])\n\n>>> h = matrix([-7., -2., -4., -5., -8.,  0., 0., 0., 0., 0., 0.,])\n>>> o = matrix([4., 7., 6., 8., 8., 9])\n>>> sol = glpk.ilp(o,G,h)\n>>> print sol[1]\n\\end{lstlisting}\n\nor\n\\begin{lstlisting}\n>>> from cvxopt import matrix, solvers, glpk\n>>> G = matrix([ [-1., 0., 0., 0., 0., 0.],\n             [0., -1., 0., 0., 0., 0.],\n             [0., 0., -1., 0., 0., 0.],\n             [0., 0., 0., -1., 0., 0.],\n             [0., 0., 0., 0., -1., 0.],\n             [0., 0., 0., 0., 0., -1.] ])\n\n>>> h = matrix([ 0., 0., 0., 0., 0., 0.,])\n>>> o = matrix([4., 7., 6., 8., 8., 9])\n>>> A = matrix([ [1., 0., 0., 1., 0.],\n             [1., 0., 0., 0., 1.],\n             [0., 1., 0., 1., 0.],\n             [0., 1., 0., 0., 1.],\n             [0., 0., 1., 1., 0.],\n             [0., 0., 1., 0., 1.] ])\n>>> b = matrix([7., 2., 4., 5., 8])\n>>> sol = glpk.ilp(o,G,h,A,b)\n>>> print sol[1]\n\\end{lstlisting}\n\n\\textbf{Problem 2}\nChoose one of these methods and compare the optimal values for the integer linear program to the result you received above.\n\n\\textbf{Problem 3}\nCreate the dual problem for the linear program and solve.\nCompare your answer to the dual value cvxopt returned.\n\\end{comment}\n\n\\section*{Quadratic Programming}\n\nQuadratic programming is similar to linear programming, but the objective function is quadratic rather than linear.\nThe constraints, if there are any, are still of the same form.\nThus, $G, \\mathbf{h}, A$, and $\\b$ are optional.\nThe formulation that we will use is\n\\begin{align*}\n\\text{minimize}\\qquad &\\frac{1}{2}\\x\\trp Q\\x + \\mathbf{r}\\trp \\x \\\\\n\\text{subject to}\\qquad &G\\x \\preceq \\mathbf{h}\\\\\n &A\\x = \\b,\n\\end{align*}\nwhere $Q$ is a positive semidefinite symmetric matrix.\nIn this formulation, we require again that $A$ has full row rank and that the block matrix\n$[Q \\quad G \\quad A]\\trp $ has full column rank.\n\nAs an example, consider the quadratic function\n\\[\nf(x_1,x_2) = 2x_1^2 +2x_1x_2 + x_2^2 +x_1 -x_2.\n\\]\nThere are no constraints, so we only need to initialize the matrix $Q$ and the vector $\\mathbf{r}$.\nTo find these, we first rewrite our function to match the formulation given above.\nIf we let\n\\[\nQ = \\begin{bmatrix}\n  a & b\\\\\n  b & c\n\\end{bmatrix}, \\qquad\n\\mathbf{r} = \\begin{bmatrix}\n  d\\\\\n  e\n\\end{bmatrix},\n\\qquad \\text{and} \\qquad\n\\x = \\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix},\n\\]\nthen\n\\begin{align*}\n\\frac{1}{2}\\x\\trp Q\\x + \\mathbf{r}\\trp \\x &=\n\\frac{1}{2}\n\\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix}\\trp\n\\begin{bmatrix}\n  a & b\\\\\n  b & c\n\\end{bmatrix}\n\\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix} +\n\\begin{bmatrix}\n  d\\\\\n  e\n\\end{bmatrix}\\trp\n\\begin{bmatrix}\n  x_1\\\\\n  x_2\n\\end{bmatrix} \\\\\n&= \\frac{1}{2}ax_1^2 + bx_1x_2 + \\frac{1}{2}cx_2^2 + dx_1 + ex_2\n\\end{align*}\nThus, we see that the proper values to initialize our matrix $Q$ and vector $\\mathbf{r}$ are:\n\\begin{align*}\na &= 4  &d = 1 \\\\\nb &= 2  &e = -1 \\\\\nc &= 2\n\\end{align*}\nNow that we have the matrix $Q$ and vector $\\mathbf{r}$, we are ready to use the CVXOPT function for quadratic programming \\li{solvers.qp()}.\n\\begin{lstlisting}\n>>> Q = matrix(np.array([[4., 2.], [2., 2.]]))\n>>> r = matrix([1., -1.])\n>>> sol=solvers.qp(Q, r)\n>>> print(sol['x'])\n[-1.00e+00]\n[ 1.50e+00]\n>>> print sol['primal objective']\n-1.25\n\\end{lstlisting}\n\n\\begin{problem}\nFind the minimizer and minimum of\n\\begin{equation*}\ng(x_1,x_2,x_3) = \\frac{3}{2}x_1^2 +2x_1x_2 + x_1x_3+ 2x_2^2 +2x_2x_3+\\frac{3}{2}x_3^2+3x_1 + x_3\n\\end{equation*}\n\\\\(Hint: Write the function $g$ to match the formulation given above before coding.)\n\\begin{comment}\n\\begin{equation}\nf(x) = \\frac{1}{2}x\\trp Qx - x\\trp p\n\\end{equation}\nwhere\n\n\\begin{center}\n$Q =\n\\begin{bmatrix}\n3 & 2 & 1\\\\\n2 & 4 & 2\\\\\n1 & 2 & 3\\\\\n\\end{bmatrix}\n$\nand $p =\n\\begin{bmatrix}\n3\\\\\n0\\\\\n1\\\\\n\\end{bmatrix}\n$\n\\end{center}\n\\end{comment}\n\n\\end{problem}\n\n\n\\begin{problem}\nThe $l_2$ minimization problem is to\n\\begin{align*}\n\\text{minimize}\\qquad &\\|\\x\\|_2\\\\\n\\text{subject to} \\qquad &A\\x = \\b.\n\\end{align*}\n\nThis problem is equivalent to a quadratic program, since $\\|\\x\\|_2 = \\x\\trp \\x$.\nWrite a function that accepts a matrix $A$ and vector $\\b$ and solves the $l_2$ minimization problem.\nReturn the minimizer $\\x$ and the primal objective value.\n\nTo test your function, use the matrix $A$ and vector $\\b$ from Problem \\ref{prob:l1}. \nThe minimizer is approximately $\\x=[0.966, 2.169, 0.809, 0.888]^T$ and the minimum primal objective value is approximately $7.079$.\n\\end{problem}\n\n\\begin{comment}\n\\section*{Allocation Models}\nAllocation models lead to simple linear programs. An allocation model seeks to allocate a valuable resource among competing needs. Consider the following example taken from ``Optimization in Operations Research\" by Ronald L. Rardin. %%pg 132\n\nThe U.S. Forest service has used an allocation model to deal with the task of managing national forests.\nThe model begins by dividing the land into a set of analysis areas. Several land management policies (also\ncalled prescriptions) are then proposed and evaluated for each area.\nAn \\emph{allocation} is how much land (in acreage) in each unique analysis area will be assigned to each of the possible prescriptions.\nWe seek to find the best possible allocation, subject to forest-wide restrictions on land use.\n\nThe file \\li{ForestData.npy} contains data for a fictional national forest (you can also find the data\nin Table \\ref{tab:forest}). There are 7 areas of analysis and 3 prescriptions for each of them.\n\n\\begin{align*}\n&\\text{Column 1: $i$, area of analysis} \\\\\n&\\text{Column 2: $s_i$, size of the analysis area (in thousands of acres)} \\\\\n&\\text{Column 3: $j$, prescription number} \\\\\n&\\text{Column 4: $p_{i,j}$, net present value (NPV) per acre in area $i$ under prescription $j$} \\\\\n&\\text{Column 5: $t_{i,j}$, protected timber yield per acre in area $i$ under prescription $j$} \\\\\n&\\text{Column 6: $g_{i,j}$, protected animal grazing capability per acre for area $i$ under prescription $j$} \\\\\n&\\text{Column 7: $w_{i,j}$, wilderness index rating (0 to 100) for area $i$ under prescription $j$}\n\\end{align*}\n\n\\begin{table}[H]\n\\centering\n    \\begin{tabular}{c c c c c c c}\n&&&Forest Data&&& \\\\\n\\hline\nAnalysis & Acres &Prescrip-&NPV&Timber&Grazing&Wilderness \\\\\nArea&(1000)'s &tion&(per acre) &(per acre)&(per acre)& Index\\\\\n$i$ &$s_i$&$j$& $p_{i,j}$ & $t_{i,j}$&$g_{i,j}$&$w_{i,j}$ \\\\\\hline\n1&\t75\t&1\t&503\t&310\t&0.01&\t40\\\\\n&&\t\t2&\t140&\t50&\t0.04\t&80\\\\\n&&\t\t3&\t203&\t0&\t0&\t95\\\\ \\hline\n2&\t90&\t1\t&675&\t198&\t0.03&\t55\\\\\n&&\t\t2&\t100&\t46&\t0.06&\t60\\\\\n&&\t\t3&\t45&\t0&\t0&\t65\\\\ \\hline\n3&\t140&\t1\t&630&\t210\t&0.04&\t45\\\\\n&&\t\t2&\t105&\t57&\t0.07&\t55\\\\\n&&\t\t3&\t40\t&0&\t0&\t60\\\\ \\hline\n4\t&60&\t1&\t330&\t112&\t0.01&\t30\\\\\n&&\t\t2\t&40&\t30&\t0.02&\t35\\\\\n&&\t\t3&\t295&\t0&\t0\t&90\\\\ \\hline\n5\t&212&\t1\t&105\t&40\t&0.05&\t60\\\\\n&&\t\t2\t&460&\t32\t&0.08&\t60\\\\\n&& 3\t&120&0&\t0\t&70\\\\ \\hline\n6\t&98\t&1\t&490\t&105\t&0.02\t&35\\\\\n&&\t\t2&\t55\t&25\t&0.03\t&50\\\\\n&&\t\t3\t&180\t&0\t&0\t&75\\\\ \\hline\n7&\t113&\t1\t&705\t&213&\t0.02\t&40\\\\\n&&\t\t2&\t60\t&40\t&0.04&\t45\\\\\n&&\t\t3\t&400\t&0\t&0\t&95\\\\\n\\hline\n    \\end{tabular}\n\\caption{}\n\\label{tab:forest}\n\\end{table}\nLet $x_{i,j}$ be the amount of land in area $i$ allocated to prescription $j$.\nUnder this notation, an allocation is a one-dimensional vector consisting of the $x_{i,j}$'s. \nFor this particular\nexample, there are 7 acres, with 3 prescriptions each.\nSo the allocation vector is a one-dimensional vector with 21 entries.\nOur goal is to find the allocation vector that maximizes net present value, while producing at least 40 million\nboard-feet of timber, at least 5 thousand units of grazing capability, and keeping the average wilderness index at least 70.\nThe allocation vector is also constrained to be nonnegative, and all of the land must be allocated precisely.\n\nSince acres are in thousands, divide the constraints of timber and animal grazing by 1000 in the problem setup, and compensate for this after obtaining a solution.\n\nThe problem can be written as follows:\n\\begin{align*}\n\\text{maximize } &\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 p_{i,j}x_{i,j} \\\\\n\\text{subject to } &\\sum\\limits_{j=1}^3 x_{i,j} = s_i  \\text{ for } i=1,..,7 \\\\\n\t        &\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 t_{i,j}x_{i,j} \\geq 40,000 \\\\\n\t\t&\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 g_{i,j}x_{i,j} \\geq 5 \\\\\n\t\t&\\frac{1}{788} \\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 w_{i,j}x_{i,j} \\geq 70 \\\\\n\t\t&x_{i,j} \\geq 0 \\text{ for } i=1,...,7  \\text{ and } j=1,2,3\n\\end{align*}\n\n\\begin{problem}\nSolve the allocation problem above.\nReturn the minimizing allocation vector of $x_{i,j}$'s and the maximum total net present value.\nRemember to consider the following:\n\\begin{enumerate}\n\\item The allocation vector should be a (21,1) NumPy array.\n\\item Recall that the constraints of timber and animal grazing were divided by 1000.\nTo compensate, the maximum total net value will be equal to the primal objective of the appropriately minimized linear function multiplied by -1000.\n\\end{enumerate}\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Eating on a Budget}\n\nIn 2009, the inmates of Morgan County jail convinced Judge Clemon of the Federal District Court in Birmingham to put Sheriff Barlett in jail for malnutrition.\nUnder Alabama law, in order to encourage less spending, \"the chief lawman could go light on prisoners' meals and pocket the leftover change.\"\\footnote[1]{Nossiter, Adam, 8 Jan 2009, \"As His Inmates Grew Thinner, a Sheriff’s Wallet Grew Fatter\", \\emph{New York Times},\\url{https://www.nytimes.com/2009/01/09/us/09sheriff.html}}.\nSheriffs had to ensure a minimum amount of nutrition for inmates, but minimizing costs meant more money for the sheriffs themselves.\nJudge Clemon jailed Sheriff Barlett one night until a plan was made to use all allotted funds, $1.75$ per inmate, to feed prisoners more nutritious meals.\nWhile this case made national news, the controversy of feeding prisoners in Alabama continues as of 2019\\footnote[2]{Sheets, Connor, 31 January 2019, \"Alabama sheriffs urge lawmakers to get them out of the jail food business\", \\url{https://www.al.com/news/2019/01/alabama-sheriffs-urge-lawmakers-to-get-them-out-of-the-jail-food-business.html}}.\n\nThe problem of minimizing cost while reaching healthy nutritional requirements can be approached as a convex optimization problem.\nRather than viewing this problem from the sheriff's perspective, we view it from the perspective of a college student trying to minimize food cost in order to pay for higher education, all while meeting standard nutritional guidelines.\n\nThe file \\li{food.npy} contains a dataset with nutritional facts for 18 foods that have been eaten frequently by college students working on this text.\nA subset of this dataset can be found in Table \\ref{tab:food-data}, where the \"Food\" column contains the list of all 18 foods.\n\nThe columns of the full dataset are:\n\\begin{align*}\n& \\text{Column 1: $p$, price (dollars)} \\\\\n& \\text{Column 2: $s$, number of servings} \\\\\n& \\text{Column 3: $c$, calories per serving} \\\\\n& \\text{Column 4: $f$, fat per serving (grams)} \\\\\n& \\text{Column 5: $\\hat{s}$, sugar per serving (grams)} \\\\\n& \\text{Column 6: $\\hat{c}$, calcium per serving (milligrams)} \\\\\n& \\text{Column 7: $\\hat{f}$, fiber per serving (grams)} \\\\\n& \\text{Column 8: $\\hat{p}$, protein per serving (grams)}\n\\end{align*}\n\n\n \\begin{table}[H]\n% \\begin{adjustwidth}{-.5in}{-.5in}\n\\begin{tabular}{|c||c|c|c|c|c|c|c|c|c|c|}\n\\hline\n\\textbf{Food} & \\textbf{Price} & \\textbf{Serving Size} & \\textbf{Calories} & \\textbf{Fat} & \\textbf{Sugar} & \\textbf{Calcium} & \\textbf{Fiber} & \\textbf{Protein} \\\\ \n& $p$ & $s$ & $c$ & $f$ & $\\hat{s}$ & $\\hat{c}$ & $\\hat{f}$ & $\\hat{p}$ \\\\ \n& dollars & & & g & g & mg & g & g \\\\ \\hline\\hline\nRamen & 6.88 & 48 & 190 & 7 & 0 & 0 & 0 & 5 \\\\ \\hline\nPotatoes & 0.48 & 1 & 290 & 0.4 & 3.2 & 53.8 & 6.9 & 7.9 \\\\ \\hline\nMilk & 1.79 & 16 & 130 & 5 & 12 & 250 & 0 & 8 \\\\ \\hline\nEggs & 1.32 & 12 & 70 & 5 & 0 & 28 & 0 & 6 \\\\ \\hline\nPasta & 3.88 & 8 & 200 & 1 & 2 & 0 & 2 & 7 \\\\ \\hline\nFrozen Pizza & 2.78 & 5 & 350 & 11 & 5 & 150 & 2 & 14 \\\\ \\hline\nPotato Chips & 2.12 & 14 & 160 & 11 & 1 & 0 & 1 & 1 \\\\ \\hline\nFrozen Broccoli & 0.98 & 4 & 25 & 0 & 1 & 25 & 2 & 1 \\\\ \\hline\nCarrots & 0.98 & 2 & 52.5 & 0.3 & 6.1 & 42.2 & 3.6 & 1.2 \\\\ \\hline\nBananas & 0.24 & 1 & 105 & 0.4 & 14.4 & 5.9 & 3.1 & 1.3 \\\\ \\hline\nTortillas & 3.48 & 18 & 140 & 4 & 0 & 0 & 0 & 3 \\\\ \\hline\nCheese & 1.88 & 8 & 110 & 8 & 0 & 191 & 0 & 6 \\\\ \\hline\nYogurt & 3.47 & 5 & 90 & 0 & 7 & 190 & 0 & 17 \\\\ \\hline\nBread & 1.28 & 6 & 120 & 2 & 2 & 60 & 0.01 & 4 \\\\ \\hline\nChicken & 9.76 & 20 & 110 & 3 & 0 & 0 & 0 & 20 \\\\ \\hline\nRice & 8.43 & 40 & 205 & 0.4 & 0.1 & 15.8 & 0.6 & 4.2 \\\\ \\hline\nPasta Sauce & 3.57 & 15 & 60 & 1.5 & 7 & 20 & 2 & 2 \\\\ \\hline\nLettuce & 1.78 & 6 & 8 & 0.1 & 0.6 & 15.5 & 1 & 0.6 \\\\ \\hline\n\\end{tabular}\n\\caption{Subset of table containing food data}\n\\label{tab:food-data}\n% \\end{adjustwidth}\n\\end{table}\n\n According to the FDA\\footnote[1]{url{https://www.accessdata.fda.gov/scripts/InteractiveNutritionFactsLabel/pdv.html}} and US Department of Health, someone on a $2000$ calorie diet should have no more than 2000 calories, no more than 65 grams of fat, no more than 50 grams of sugar\\footnote[2]{https://www.today.com/health/4-rules-added-sugars-how-calculate-your-daily-limit-t34731}, at least 1000 milligrams of calcium\\footnote[1]{26 Sept 2018, \\url{https://ods.od.nih.gov/factsheets/Calcium-HealthProfessional/}}, at least 25 grams of fiber, and at least 46 grams of protein\\footnote[2]{\\url{https://www.accessdata.fda.gov/scripts/InteractiveNutritionFactsLabel/protein.html}} per day.\n\n We can rewrite this as a convex optimization problem below.\n\n \\begin{align*}\n\\text{minimize } & \\sum_{i=1}^{18}p_ix_i, \\\\\n\\text{subject to }& \\sum_{i=1}^{18} c_ix_i \\leq 2000, \\\\\n\t\t\t& \\sum_{i=1}^{18} f_ix_i \\leq 65, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{s}_ix_i \\leq 50, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{c}_ix_i \\geq 1000, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{f}_ix_i \\geq 25, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{p}_ix_i \\geq 46, \\\\\n\t\t\t& x_i \\geq 0.\n\\end{align*}\n\n \\begin{problem}\nRead in the file \\li{food.npy}.\nUse CVXOPT to identify how much of each food item a college student should each to minimize cost spent each day.\nReturn the minimizing vector and the total amount of money spent.\n\nWhat is the food you should eat most each day? \nWhat are the three foods you should eat most each week?\n\n(Hint: Each nutritional value must be multiplied by the number of servings to get the nutrition value of the whole product).\n\\label{prob:diet}\n\\end{problem}\n\nYou can learn more about CVXOPT at\n\\url{http://cvxopt.org/index.html}.\n", "meta": {"hexsha": "b612553acbf255f4ab93a2eb55c10f06af262c60", "size": 30497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/CVXOPT_Intro/CVXOPT_Intro.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/CVXOPT_Intro/CVXOPT_Intro.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/CVXOPT_Intro/CVXOPT_Intro.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": 38.2647427854, "max_line_length": 687, "alphanum_fraction": 0.6583926288, "num_tokens": 10876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6207342579574906}}
{"text": "\\documentclass[12pt,letterpaper]{article}\n\\usepackage[margin=1.00in]{geometry}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{braket}\n\\usepackage{csquotes}\n\\usepackage{listings}\n\\usepackage{siunitx}\n\\usepackage{tikz}\n\\usepackage{wrapfig}\n\n\\title{Bresenham's Line Algorithm}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\section{Discrete vs. Continuous Values}\nBefore discussing how the line algorithm works, we should have a basic knowledge of what discrete and continuous values are.\nDiscrete data can only take particular distinct values, with no \\enquote{gray area} in between; whereas continuous data occupies any value over a continuous range.\nWhy does this concern us when all we want to do is draw a line?\nWe can picture a raster image as a grid of distinct, discrete pixels that grow larger and larger as we zoom into the image.\nIn contrast, a line is continuous: an infinite number of points in between the two endpoints.\nIn any line algorithm, we try our best to map a continuous object onto a discrete grid of predefined positions such that they look as if they are continuous when zoomed out far enough.\n\n\\section{Assumptions}\nOur goal is to find the pixels that best approximate a target line that can be expressed in the form $y = mx + b$.\nTo help us, we divide the grid into eight octants, with position $(0, 0)$ as the center.\nIn the degree system, octant I consists of \\ang{0} to \\ang{45}; octant II, \\ang{45} to \\ang{90}; and so on.\nBy splitting the coordinate system into eight octants, octant I now only contains lines with a slope $0 < m < 1$; octant II, lines with a slope $1 < m < \\infty$.\nWe also assume that $\\set{x_0, y_0, x_1, y_1} \\in \\mathbb{Z}$ (that is, $x_0$, $y_0$, $x_1$, and $y_1$ are integers).\n\n\\section{Octant I}\nTo keep things simple, we will always plot lines in this octant from left to right.\nThis requires that $x_0 < x_1$, which can be done by swapping $(x_0, y_0)$ with $(x_1, y_1)$ as needed.\nRemember that in this octant, $0 < m < 1$.\nSuppose we want to represent the line shown in the left graph of Figure~\\ref{fig:oct1} as a set of pixels on the grid.\n\n\\begin{figure}\n  \\centering\n  \\begin{minipage}{0.31\\textwidth}\n    \\begin{tikzpicture}\n      \\draw[step=1.0cm,gray,very thin] (0,0) grid (5,3);\n      \\draw[magenta,ultra thick] (0,0) -- (5,3);\n    \\end{tikzpicture}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}{0.31\\textwidth}\n    \\begin{tikzpicture}\n      \\draw[step=1.0cm,gray,very thin] (0,0) grid (5,3);\n      \\fill[blue!40!white] (0,0) rectangle (1,1);\n      \\draw[magenta,ultra thick] (0,0) -- (5,3);\n      \\node at (1.5,1) {\\textbullet};\n    \\end{tikzpicture}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}{0.31\\textwidth}\n    \\begin{tikzpicture}\n      \\draw[step=1.0cm,gray,very thin] (0,0) grid (5,3);\n      \\fill[blue!40!white] (0,0) rectangle (1,1);\n      \\fill[blue!40!white] (1,0) rectangle (2,1);\n      \\fill[blue!40!white] (2,1) rectangle (3,2);\n      \\fill[blue!40!white] (3,2) rectangle (4,3);\n      \\fill[blue!40!white] (4,2) rectangle (5,3);\n      \\draw[magenta,ultra thick] (0,0) -- (5,3);\n      \\node at (1.5,1) {\\textbullet};\n      \\node at (2.5,1) {\\textbullet};\n      \\node at (3.5,2) {\\textbullet};\n      \\node at (4.5,3) {\\textbullet};\n    \\end{tikzpicture}\n  \\end{minipage}\n  \\caption{\\label{fig:oct1} Plotting a line in octant I.}\n\\end{figure}\n\nWe start with the leftmost column (i.e., the smallest $x$-value) and work our way up.\nEarlier on, we said that $x_0$ and $y_0$ are integers, so we can begin by plotting point $(x_0, y_0)$ (see the middle graph of Figure~\\ref{fig:oct1}).\n\nSince we are strictly moving from left to right and down to up, we must move onto the next column.\nFrom here, we have two (logical) choices.\nDo we fill in $(x_0 + 1, y_0)$ or $(x_0 + 1, y_0 + 1)$?\nIt turns out that we can actually figure this out with minimal work.\nAll lines are functions that can be expressed in the form $y_i = f(x_i)$.\nSo for a given $x_i$-value, we can calculate the corresponding $y_i$-value.\nThen, we compare that calculated $y_i$ value to the \\enquote{midway} value $y_j = f\\left(x_i + \\frac{1}{2}\\right)$ to see which pixel contains \\enquote{more} of the line.\nWe can express this like so:\n\n\\begin{quote}\n  If $\\left(x + 1, y + \\frac{1}{2}\\right)$ is above the line, draw the lower pixel.\n  If it is below the line, draw the upper pixel.\n  If it is exactly equivalent to the midpoint, pick either pixel.\n\\end{quote}\n\nWe avoid plotting two pixels for a single column so that the line does not turn thicker at various locations.\n\n\\subsection{Testing $\\left(x + 1, y + \\frac{1}{2}\\right)$}\nWe can manipulate the point-slope equation $y = mx + b$ like so:\n\\begin{align*}\n  0       &= mx - y + b \\\\\n          &= \\frac{\\Delta y}{\\Delta x} x - y + b \\\\\n          &= (\\Delta y) x - (\\Delta x) y + (\\Delta x) b \\\\\n  f(x, y) &= Ax + By + C\n\\end{align*}\nIn this case, $A = \\Delta y$, $B = -\\Delta x$, and $C = (\\Delta x) b$.\nThis gives us the first draft of our algorithm, written in psuedo-code:\n\\begin{lstlisting}[mathescape]\n  $x = x_0$; $y = y_0$\n  $d = f\\left(x + 1, y + \\frac{1}{2}\\right)$\n  while $x \\leq x_1$\n    plot($x$, $y$)\n    $x$++\n    if $d > 0$ then $y$++\n    $d = f\\left(x + 1, y + \\frac{1}{2}\\right)$\n\\end{lstlisting}\nWe realize that if $x$ increases by 1, add $A$ to $d$, and if $y$ increases by 1, add $B$ to $d$.\nWe can revise the algorithm to get our second draft (diff-mode below):\n\\begin{lstlisting}[mathescape]\n   $x = x_0$; $y = y_0$\n   $d = f\\left(x + 1, y + \\frac{1}{2}\\right)$\n   while $x \\leq x_1$\n     plot($x$, $y$)\n-    $x$++\n+    $x$++; $d$ += $A$\n-    if $d > 0$ then $y$++\n+    if $d > 0$ then $y$++; $d$ += $B$\n-    $d = f\\left(x + 1, y + \\frac{1}{2}\\right)$\n\\end{lstlisting}\nWe can further simplify the value of $d$:\n\\begin{align*}\n  d_0   &= f\\left(x_0 + 1, y_0 + \\frac{1}{2}\\right) \\\\\n        &= A(x_0 + 1) + B\\left(y_0 + \\frac{1}{2}\\right) + C \\\\\n        &= f(x_0, y_0) + A + \\frac{1}{2} B \\\\\n        &= A + \\frac{1}{2} B \\\\\n  2 d_0 &= 2A + B\n\\end{align*}\nThis gives us the third draft of the algorithm, which is more or less as optimized as it can be while avoiding division, which might return a floating-point number (diff-mode below):\n\\begin{lstlisting}[mathescape]\n   $x = x_0$; $y = y_0$\n-  $d = f\\left(x + 1, y + \\frac{1}{2}\\right)$\n+  $d = 2A + B$\n   while $x \\leq x_1$\n     plot($x$, $y$)\n-    $x$++; $d$ += $A$\n+    $x$++; $d$ += $2A$\n-    if $d > 0$ then $y$++; $d$ += $B$\n+    if $d > 0$ then $y$++; $d$ += $2B$\n\\end{lstlisting}\n\n\\section{Octant II}\nIn octant II, we essentially just swap $x$- and $y$-values.\nThe midpoint becomes $\\left(x + \\frac{1}{2}, y + 1\\right)$, and so $d_0 = f\\left(x_0 + \\frac{1}{2}, y + 1\\right)$.\nAfter simplification, we get $d = \\frac{1}{2} A + B$, or $2d = A + 2B$.\nThe conditional $d > 0$ is flipped, and becomes $d < 0$.\n\n\\section{Octant VIII}\nNote that we have skipped many octants because one can draw in octant V by switching the points and drawing in octant I, and in octant VI by doing the same in octant II\\@.\nIn octant VIII, the midpoint is $\\left(x + 1, y - \\frac{1}{2}\\right)$, and so $d_0 = f\\left(x_0 + 1, y_0 - \\frac{1}{2}\\right)$.\nAfter simplification, $2d = 2A - B$.\n\n\\end{document}\n\n", "meta": {"hexsha": "a116d766d02c751c53b3dd55e5f2f854d7b703a1", "size": 7160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm/bresenham.tex", "max_stars_repo_name": "AnAverageHuman/graphics2", "max_stars_repo_head_hexsha": "4ad39c86e0e10481859a12851aadbb7071f1eaea", "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": "algorithm/bresenham.tex", "max_issues_repo_name": "AnAverageHuman/graphics2", "max_issues_repo_head_hexsha": "4ad39c86e0e10481859a12851aadbb7071f1eaea", "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": "algorithm/bresenham.tex", "max_forks_repo_name": "AnAverageHuman/graphics2", "max_forks_repo_head_hexsha": "4ad39c86e0e10481859a12851aadbb7071f1eaea", "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.4720496894, "max_line_length": 184, "alphanum_fraction": 0.6441340782, "num_tokens": 2527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.6206829073823021}}
{"text": "\\documentclass[]{article}\n\\usepackage{natbib}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n%opening\n\\title{\\texttt{vsmodel} Derivation}\n\\author{Matt James}\n\n\\begin{document}\n\n\\maketitle\n\nThis document describes the derivation of the model equations for the \\texttt{vsmodel} package.\n\n\\section{Derivation of the Model}\n\nIn this section we derive the components of the Volland-Stern electric field model \\citep{Volland1973,Stern1975} in cylindrical coordinates. The Volland-Stern model starts with an electrostatic potential, $U(r,\\phi)$, from which the electric field is obtained using\n\n\\begin{equation}\n\t\\mathbf{E} = - \\mathbf{\\nabla} U, \\label{EqEField}\n\\end{equation} \n\nwhere\n\n\\begin{equation}\n\t\\mathbf{\\nabla} U = \\frac{\\partial U}{\\partial r} \\mathbf{\\hat{r}} + \\frac{1}{r} \\frac{\\partial U}{\\partial \\phi} \\mathbf{\\hat{\\phi}} + \\frac{\\partial U}{\\partial z}\\mathbf{\\hat{z}}. \\label{EqDelU}\n\\end{equation}\n\nThe coordinate system is such that $z$ lies along the dipole axis of the planet; $x$ points approximately sunward where the magnetic equatorial plane intersects the plane containing both the dipole axis and the Earth-Sun line; the $y$ axis points approximately duskward. In cylindrical coordinates: $r$ is the radial distance from the $z$ axis (i.e. $r = \\sqrt{x^2 + y^2}$); $\\phi$ is the azimuth, equal to 0 at noon where $\\phi = \\arctan{y,x}$.\n\nThe potential, $U$, is made up of a corotational component, $U_{cor}$, and a convection component, $U_{cnv}$. The corotation component used here is defined by\n\n\\begin{equation}\n\tU_{cor} = -\\frac{a}{r},\n\\end{equation}\n\nwhere $a=92.4$~keV is the corotation constant used in \\citet{Zhao2017}.\n\nThe electric field due to corotation, $\\mathbf{E_{cor}}$, is given by:\n\\begin{align}\n\tE_r &= -\\frac{a}{r^2}, \\\\\n\tE_\\phi &= 0,\\\\\n\tE_z &= 0,\n\\end{align}\nwhere $\\mathbf{E_{cor}} = [E_r,E_\\phi,E_z]$.\n\nThere are two options for the convection component of this model - the simpler option is from \\citet{Maynard1975} and is derived in section \\ref{SectMC}; the more complicated option described by \\citet{Goldstein2005} separates the convection component into solar wind electric field (section \\ref{SectSW}) and SAPS (section \\ref{SectSAPS}) parts. The overall electric field is simply obtained by adding the separate components of the model, i.e. $\\mathbf{E} = \\mathbf{E_{cor}} + \\mathbf{E_{cnv}}$.\n\n\n\\section{The \\citet{Maynard1975} $\\mathbf{E}$-field}\n\\label{SectMC}\nThis section describes the electric field due to convection as described by \\citet{Maynard1975}. The potential used is\n\n\\begin{equation}\n\tU_{mc} = -A_{mc} r^\\gamma \\sin{\\phi}, \\label{EqMCPot}\n\\end{equation}\n\nwhere \n\n\\begin{equation}\n\tA_{mc} = \\frac{0.045}{(1.0 - 0.159 Kp + 0.0093 K_p^2)^3} \\text{ (kV $R_E^{-2}$)}\n\\end{equation}\n\nand $\\gamma=2$ is the shielding parameter.\n\nThe electric field components become\n\\begin{align}\n\tE_r &= \\gamma A_{mc} r^{(\\gamma-1)}\\sin{\\phi},\\\\\n\tE_\\phi &= A_{mc} r^{(\\gamma-1)} \\cos{\\phi},\\\\\n\tE_z &= 0.\n\\end{align}\n\n\\section{Solar Wind Electric Field}\n\\label{SectSW}\nThis section uses the electric field due to the solar wind propagation past the Earth as described in \\citet{Goldstein2005}. The electric field due to the solar wind is given by,\n\n\\begin{equation}\n\tE_{sw} = -V_{sw} B_z,\n\\end{equation}\n\nwhere $V_{sw}$ is the $x$ component of the solar wind velocity (negative Sunward), and $B_z$ is the north-south component of the interplanetary magnetic field (IMF). $E_{sw}$ has a minimum value of 0.1~mV~m$^{-1}$, so when the IMF is northward there is still a little bit of a viscous interaction with the magnetosphere.\n\nThe potential is given by \n\\begin{equation}\n\tU_{sw} = -A_{sw} r^2 \\sin{\\phi},\n\\end{equation}\nwhere \n\\begin{equation}\n\tA_{sw} = 0.12 E_{sw} (6.6)^{(1-\\gamma)}, \\text{ (kV $R_E^{-2}$)}\n\\end{equation}\nand $E_{sw}$ in this case should be converted from mV~m$^{-1}$ to kV~$R_E^{-1}$.\n\nThe electric field components become\n\\begin{align}\nE_r &= \\gamma A_{sw} r^{(\\gamma-1)}\\sin{\\phi},\\\\\nE_\\phi &= A_{sw} r^{(\\gamma-1)} \\cos{\\phi},\\\\\nE_z &= 0.\n\\end{align}\n\n\n\\section{SAPS Electric Field}\n\t\\label{SectSAPS}\n\tThis section uses the electrostatic potential due to SAPS as described in \\citet{Goldstein2005},\n\t\n\t\\begin{equation}\n\t\tU_{saps}(r,\\phi,K_p) = -V_s(K_p) F(r,\\phi,K_p) G(\\phi),\n\t\\end{equation}\n\n\twhere\n\t\n\t\\begin{align}\n\t\tV_s(Kp) &= 0.75 K_p^2 \\text{ (in kV)}, \\\\\n\t\tF(r,\\phi,K_p) &= \\frac{1}{2} + \\frac{1}{\\pi}\\arctan{\\left[\\frac{2}{\\alpha(\\phi,K_p)}\\left\\{ r - R_s(\\phi,K_p)\\right\\}\\right]}, \\\\\n\t\tG(\\phi) &= \\sum_{m=0}^{2} \\left\\{A_m \\cos{[m(\\phi - \\phi_0)]} + B_m \\sin{[m(\\phi-\\phi_0)]} \\right\\},\n\t\\end{align}\n\t\n\tand\n\t\n\t\\begin{align}\n\t\t\\alpha(\\phi,K_p) &= 0.15 + (2.55 - 0.27 K_p)\\left[1 + \\cos{\\left(\\phi - \\frac{7\\pi}{12}\\right)}\\right], \\\\\n\t\tR_s(\\phi,K_p) &= R_0(K_p)\\left(\\frac{1+\\beta}{1 + \\beta\\cos{(\\phi-\\pi)}}\\right)^\\kappa, \\\\\n\t\tR_0(K_p) &= 4.4 - 0.6(K_p - 5) \\text{ (in $R_E$)},\\\\\n\t\tA_m &= [0.53,0.37,0.1],\\\\\n\t\tB_m &= [0.0,0.21,-0.1],\\\\\n\t\t\\phi_0 &= \\frac{\\pi}{2}, \\\\\n\t\t\\beta &= 0.97,\\\\\n\t\t\\kappa &= 0.14.\n\t\\end{align}\n\t\n\tThe cylindrical components of the electric field are given by,\n\t\n\t\\begin{align}\n\t\tE_r &= V_s(K_p)\\frac{\\partial F(r,\\phi,K_p)}{\\partial r} G(\\phi),\\\\\n\t\tE_\\phi &= \\frac{1}{r} V_s \\left[ F(r,\\phi,K_p)\\frac{\\text{d} G(\\phi)}{\\text{d} \\phi} + \\frac{\\partial F(r,\\phi,K_p)}{\\partial \\phi} G(\\phi) \\right],\\\\\n\t\tE_z &= 0.\n\t\\end{align}\n\t\n\t\\subsection{Derivatives: $\\frac{\\partial F}{\\partial r}$}\n\t\t\\begin{align}\n\t\t\t\\frac{\\partial F}{\\partial r} &= \\frac{\\partial}{\\partial r} \\left(\\frac{1}{2} + \\frac{1}{\\pi}\\arctan{\\left[\\frac{2}{\\alpha}\\left\\{r - R_s\\right\\}\\right]}\\right) \\\\\n\t\t\t&= \\frac{\\partial}{\\partial r}\\left(\\frac{1}{2} + \\frac{1}{\\pi}\\arctan\\left[f\\right]\\right) \\\\\n\t\t\t&= 0 + \\frac{1}{\\pi}\\left(\\frac{\\partial}{\\partial f}\\arctan{f}\\right)\\frac{\\partial f}{\\partial r},\n\t\t\\end{align}\n\t\t\n\t\twhere\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\frac{\\partial }{\\partial f} \\arctan{f} = \\frac{1}{1 + f^2},\n\t\t\\end{equation}\n\t\t\n\t\tand\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\frac{\\partial f}{\\partial r} = \\frac{2}{\\alpha}.\n\t\t\\end{equation}\n\t\t\n\t\tSo,\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\boxed{\\frac{\\partial F}{\\partial r} = \\frac{2}{\\alpha \\pi} \\left[\\frac{1}{1 + f^2}\\right].}\n\t\t\\end{equation}\n\t\n\t\\subsection{Derivatives: $\\frac{\\partial F}{\\partial \\phi}$}\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\partial F}{\\partial \\phi} &= \\frac{\\partial}{\\partial \\phi} \\left(\\frac{1}{2} + \\frac{1}{\\pi}\\arctan{\\left[\\frac{2}{\\alpha}\\left\\{r - R_s\\right\\}\\right]}\\right) \\\\\n\t\t\t&= \\frac{\\partial}{\\partial \\phi}\\left(\\frac{1}{2} + \\frac{1}{\\pi}\\arctan\\left[f\\right]\\right) \\\\\n\t\t\t&= 0 + \\frac{1}{\\pi}\\left(\\frac{\\partial}{\\partial f}\\arctan{f}\\right)\\frac{\\partial f}{\\partial \\phi},\n\t\t\\end{align}\n\t\t\n\t\twhere\n\n\t\t\\begin{align}\n\t\t\t\\frac{\\partial }{\\partial f} \\arctan{f} &= \\frac{1}{1 + f^2}, \\\\\n\t\t\t\\frac{\\partial f}{\\partial \\phi} &= \\frac{\\partial }{\\partial \\phi} (g(\\phi,K_p) h(\\phi,K_p)), \\\\\n\t\t\t&= \\frac{\\partial g}{\\partial \\phi}h + g\\frac{\\partial h}{\\partial \\phi},\\\\\n\t\t\t\\frac{\\partial g}{\\partial \\phi} &= \\frac{\\partial}{\\partial \\phi} \\left(\\frac{2}{\\alpha}\\right) = \\frac{\\partial g}{\\partial \\alpha} \\frac{\\partial \\alpha}{\\partial \\phi} = -\\frac{2}{\\alpha^2}\\frac{\\partial \\alpha}{\\partial \\phi}, \\\\\n\t\t\t\\frac{\\partial h}{\\partial \\phi} &= -\\frac{\\partial R_s}{\\partial \\phi}.\n\t\t\\end{align}\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\boxed{\\therefore \t\\frac{\\partial F}{\\partial \\phi} = \\frac{1}{\\pi} \\left(\\frac{1}{1+f^2}\\right) \\left[\\frac{-2}{\\alpha^2}\\frac{\\partial \\alpha}{\\partial \\phi} h - g \\frac{\\partial R_s}{\\partial \\phi} \\right].}\n\t\t\\end{equation}\n\n\t\t\n\t\\subsection{Derivatives: $\\frac{\\partial R_s}{\\partial \\phi}$}\n\t\t\n\t\t\\begin{align}\n\t\t\t\\frac{\\partial R_s}{\\partial \\phi} &= R_0 \\frac{\\mathrm{d}}{\\mathrm{d} \\phi} \\left\\{ \\left(\\frac{1+\\beta}{1 + \\beta\\cos{(\\phi-\\pi)}}\\right)^\\kappa \\right\\} = R_0 \\frac{\\mathrm{d}}{\\mathrm{d} S} \\left\\{ S^\\kappa \\right\\} \\frac{\\mathrm{d} S}{\\mathrm{d} \\phi}, \\\\\n\t\t\tS &= \\frac{1+\\beta}{1 + \\beta\\cos{(\\phi-\\pi)}} = \\frac{p}{q}, \\\\\n\t\t\t\\frac{\\mathrm{d}}{\\mathrm{d} S} \\left\\{ S^\\kappa \\right\\} &= \\kappa S^{(\\kappa -1)} = \\kappa \\left(\\frac{1+\\beta}{1 + \\beta\\cos{(\\phi-\\pi)}}\\right)^{\\kappa-1},\\\\\n\t\t\t\\frac{\\mathrm{d} S}{\\mathrm{d} \\phi} &= \\frac{\\frac{\\text{d} p}{\\text{d} \\phi}q - p \\frac{\\mathrm{d} q}{\\mathrm{d} \\phi}}{q^2} = -\\frac{p}{q^2} \\frac{\\mathrm{d} q}{\\mathrm{d} \\phi} = \\frac{1 + \\beta}{(1 + \\beta\\cos{(\\phi - \\pi)})^2} \\cdot \\beta \\sin{(\\phi - \\pi)}, \n\t\t\\end{align}\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\boxed{\\therefore \\frac{\\partial R_s}{\\partial \\phi} = -R_0\\frac{1}{q}\\frac{\\mathrm{d} q}{\\mathrm{d} \\phi} \\kappa \\left( \\frac{p}{q} \\right)^{\\kappa}  = R_0 \\frac{(1 + \\beta)\\beta \\sin{(\\phi - \\pi)}}{(1 + \\beta\\cos{(\\phi - \\pi)})^2} \\kappa \\left(\\frac{1+\\beta}{1 + \\beta\\cos{(\\phi-\\pi)}}\\right)^{\\kappa-1}.}\n\t\t\\end{equation}\n\t\t\t\n\t\t\n\t\t\n\t\\subsection{Derivatives: $\\frac{\\partial \\alpha}{\\partial \\phi}$}\n\t\n\t\t\\begin{equation}\n\t\t\t\\boxed{\\frac{\\mathrm{d} \\alpha}{\\mathrm{d} \\phi} = -(2.55 - 0.27 K_p)\\sin{\\left(\\phi - \\frac{7\\pi}{12}\\right)}}\n\t\t\\end{equation}\n\t\n\t\\subsection{Derivatives: $\\frac{\\mathrm{d} G}{\\mathrm{d} \\phi}$}\n\t\n\t\t\\begin{equation}\n\t\t\t\\boxed{\\frac{\\mathrm{d} G}{\\mathrm{d} \\phi} = \\sum_{m=0}^{2} \\left\\{-m A_m \\sin{[m(\\phi - \\phi_0)]} + m B_m \\cos{[m(\\phi-\\phi_0)]} \\right\\}.}\n\t\t\\end{equation}\n\t\t\n\t\n\\section{SM Model Field}\n\n\tThe previous section describes the model in cylindrical coordinates, here we convert the model to SM coordinates by rotating about the $z$-axis.\n\t\n\tConsidering an Electric field vector $\\mathbf{E}(r,\\phi)$ with components $E_r$ and $E_\\phi$ -- we need to rotate this vector by $\\phi$ to transform into SM coordinates.\n\t\n\tStart by expressing the components of $\\mathbf{E}$ in terms of some polar coordinates $\\rho$ and $\\alpha$:\n\t\n\t\\begin{align}\n\t\tE_r &= \\rho \\cos{\\alpha}, \\label{EqEr}\\\\\n\t\tE_\\phi &= \\rho \\sin{\\alpha}, \\label{EqEp}\n\t\\end{align}\n\t\n\tthen rotate by $\\phi$,\n\t\n\t\\begin{align}\n\t\tE_x &= \\rho \\cos{(\\alpha + \\phi)}, \\label{EqEx0}\\\\\n\t\tE_y &= \\rho \\sin{(\\alpha + \\phi)}. \\label{EqEy0}\t\t\n\t\\end{align}\n\t\n\tUsing the trigonometric identities,\n\t\n\t\\begin{align}\n\t\t\\sin{(\\alpha \\pm \\phi)} &= \\sin\\alpha\\cos\\phi \\pm \\cos\\alpha\\sin\\phi, \\\\\n\t\t\\cos{(\\alpha \\pm \\phi)} &= \\cos\\alpha\\cos\\phi \\mp \\sin\\alpha\\sin\\phi,\n\t\\end{align}\n\t\n\tequations \\ref{EqEx0} and \\ref{EqEy0} become \n\t\n\t\\begin{align}\n\t\tE_x &= \\rho\\cos\\alpha\\cos\\phi - \\rho\\sin\\alpha\\sin\\phi, \\\\\n\t\tE_y &= \\rho\\sin\\alpha\\cos\\phi + \\rho\\cos\\alpha\\sin\\phi.\n\t\\end{align}\n\t\n\tThen, substituting in equations \\ref{EqEr} and \\ref{EqEp}, gives\n\t\n\t\\begin{align}\n\t\tE_x &= E_r\\cos\\phi - E_\\phi\\sin\\phi, \\\\\n\t\tE_y &= E_r\\sin\\phi + E_\\phi\\cos\\phi.\n\t\\end{align}\n\n\\bibliographystyle{agu08}\n\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "6690ba74f41dad4c42d9b227e0e8094d9aec58cc", "size": 10598, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/vsmodel.tex", "max_stars_repo_name": "mattkjames7/vsmodel", "max_stars_repo_head_hexsha": "03e21ba0da2c65919af472eddf93b314f7ce2fd6", "max_stars_repo_licenses": ["MIT"], "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/vsmodel.tex", "max_issues_repo_name": "mattkjames7/vsmodel", "max_issues_repo_head_hexsha": "03e21ba0da2c65919af472eddf93b314f7ce2fd6", "max_issues_repo_licenses": ["MIT"], "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/vsmodel.tex", "max_forks_repo_name": "mattkjames7/vsmodel", "max_forks_repo_head_hexsha": "03e21ba0da2c65919af472eddf93b314f7ce2fd6", "max_forks_repo_licenses": ["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.9189189189, "max_line_length": 497, "alphanum_fraction": 0.6366295527, "num_tokens": 4025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6206828954262618}}
{"text": "\\iffalse\nNoether's theorem says that continuous symmetries of physical systems gives rise to conservation laws. In this class we'll see some examples of low dimensional Lie groups and how they give rise to various phenomenon in physics like time dilation and length contraction in special relativity, spin states of electrons.\n\nKeywords: bilinear forms, signature, SO(2), SO(3), Spin, SO(1,3), Minkowski space and relativity, Noether's theorem, Lie groups.\n\nPrereqs: Linear algebra, Group theory\nHomework: Recommended\n\\fi\n\n\n\\input{../preamble}\n\\DeclareMathOperator{\\re}{Re}\n\n\n\n\\begin{document}\n\\title{Inverses of polynomials}\n\\author{Apurva Nakade}\n\\thispagestyle{fancy}\n\\maketitle\n\n\n\n\nToday's goal is to build Riemann surfaces on which inverses of polynomials $f(z)$ can be well defined.\n\n\\section{Riemann surface for $\\log z$}\nIf we try to define $\\log z$ naively using polar coordinates we get\n\\begin{align}\n\t\\log (re^{i \\theta}) & = \\log r + i \\theta\n\\end{align}\nWe have a discontinuity at $\\theta = 0$ and $\\theta = 2 \\pi$ so we need to make a branch cut, say at $\\theta = 0$, to get a well defined function. For $\\theta$ varying in the range $(0,2\\pi)$ we get one branch function. We get other (distinct) branches by adding multiples of $2 \\pi$ to $\\theta$.\n\\begin{align}\n\t\\log (re^{i \\theta}) & = \\log r + i (\\theta + 2 n \\pi)\n\\end{align}\nTo create a Riemann surface on which $\\log z$ is well defined we need $\\Z$ many copies of $\\C$, on which we make branch cuts and glue them together.\n\n\n\n\n\\section{Winding numbers}\nIn order to generalize the above situation to more complicated functions we analyze what is happening here. For this we need the notions of winding numbers.\n\nConsider a non-constant complex differentiable function $f:\\C \\rightarrow \\C$. Fix a point $p \\in \\C$ be a complex number. Let $\\gamma:[0,2\\pi] \\rightarrow \\C$ with $\\gamma(0) = \\gamma(2\\pi)$ be an embedded loop in $\\C$ (no self intersections) containing $p$ in it's interior that goes counterclockwise. We say that $\\gamma$ is \\textbf{sufficiently close} to $p$ if there are no points $p' \\neq p$ in the interior of $\\gamma$ such that $f(p) = f(p')$.\n\n\\begin{proposition}\n\tFor all points $p \\in \\C$ there exists a loop $\\gamma$ sufficiently close to $p$.\n\\end{proposition}\n\\begin{proof}\n\tConsider the function $g(z) = f(z) - f(p)$. The zeroes of this complex differentiable function are exactly the points $p'$ such that $f(p') = f(p)$. Complex differentiable functions have isolated zeroes and hence $p$ has a neighborhood $U$ which does not contain any other zero of $g$. Any loop $\\gamma$ in $U$ is sufficiently close to $p$.\n\\end{proof}\n\n\n\\begin{definition}\n\tLet $\\gamma$ be a loop sufficiently close to $p$. The composition $f \\circ \\gamma$ is a loop around $f(p)$ (not necessarily embedded). The \\textbf{winding number} $w_f(p)$ is the number of counterclockwise revolutions made by $f \\circ \\gamma$ around $f(p')$ minus the number of clockwise revolutions.\n\\end{definition}\n\n\\begin{proposition}\n\tWithout any loss of generality assume that $p=0$ and $f(p) = 0$. Let $\\gamma(t)$  be a loop sufficiently close to $p$ then the winding number is given by\n\t\\begin{align}\n\t\t\\label{eq:winding}\n\t\tw_f(0) & = \\dfrac{\\log(f ( \\gamma(2 \\pi))) - \\log(f ( \\gamma(0)))}{2 \\pi i}\n\t\\end{align}\n\twhere $\\log(z)$ is any branch of the logarithm.\n\\end{proposition}\n\\begin{proof}\n\tFor every single counterclockwise revolution $\\log(z)$ increases by $2 \\pi i$ and for every single counterclockwise revolution $\\log(z)$ decreases by $ 2 \\pi i$. The result follows.\n\\end{proof}\n\n\\begin{example}\n\tFor the function $f(z) = z^n$ the winding number around 0 is $n$ and the winding number around $p \\neq 0$ is 1.\n\\end{example}\n\n\n\n\\subsection{Points with winding number $> 1$}\nFor the function $z^n$ the only complex number $z$ for which the winding number is bigger than 1 is $z=0$ and this is the point where we've to make a branch cut. This suggests that to define inverses of more complicated functions we need to figure out the points at which the winding number is greater than 1.\n\nLet $f(z)$ be a complex differentiable function. Consider a point $p \\in \\C$ and let $f(z) = \\sum \\limits_{i=0}^\\infty a_i (z-p)^i$ be the Taylor series of near $p$.\n\n\\begin{proposition}\n\t\\label{thm:windingNum}\n\tThe winding number of $w_f(p)$ is the smallest non-zero integer $i$ such that $a_i \\neq 0$.\n\\end{proposition}\n\\begin{proof}\n\tBy shifting origin if necessary assume that $p=0$ and $f(p) = 0$ so that the Taylor expansion looks like $$f(z) = \\sum \\limits_{i=n}^\\infty a_i z^i = z^n \\sum \\limits_{i=n}^\\infty a_i z^{i-n} = z^n g(z) $$ for some $n > 0$ where $a_n \\neq 0$ and $g(z) = \\sum \\limits_{i=n}^\\infty a_i z^{i-n}$. The function $g(z)$ has the property that $g(0) \\neq 0$. If we choose a loop $\\gamma$ sufficiently close to $0$ such that $g(\\gamma(t))$ stays very close to $g(0)$ then $g(z)$ is almost constant non-zero number and hence the winding number $w_f(p) = w_{z^n}(p)$ which equals $n$.\n\\end{proof}\n\nWith this proposition the points with winding number bigger than 1 are easily determined.\n\\begin{cor}\n\t$w_f(p) > 1$ iff $f'(p) = 0$ i.e. the points with winding number bigger than 1 are exactly the critical points of $f$.\n\\end{cor}\n\n\n\\section{Covering spaces}\nConsider the function $f(z) = z^n$. For any non-zero $p$ the set $f^{-1}(p)$ contains exactly $n$ elements $p_1, \\cdots, p_n$. More is true, there exists a neighborhood $U \\ni p$ such that $f^{-1}(U)$ is isomorphic to $n$ non-intersecting neighborhoods of the $n$ points $U_1 \\ni p_1, \\cdots, U_n \\ni p_n$. Furthermore the restriction of the map $f|_{U_i}$ is an isomorphism\\footnote{homeomorphism}. These properties define what is called a covering space.\n\n\\begin{definition}\n\tA map $p: X \\rightarrow Y$ is a \\textbf{covering map} if for every point $y \\in Y$ there exists a neighborhood $U \\ni y$ such that\n\t\\begin{enumerate}\n\t\t\\item $p^{-1}(U)$ is a disjoint union of subsets $\\{ V_i \\}_{i \\in I}$ of $X$ for some indexing set $I$\n\t\t\\item The restriction $p|_{V_i} : V_i \\rightarrow U$ is an isomorphism for each $i \\in I$.\n\t\\end{enumerate}\n\t$X$ is called a \\textbf{covering space} of $Y$.\\\\\n\\end{definition}\n\n\\begin{center}\n\t\\begin{tabular}{ccc}\n\t\t\\includegraphics[width=0.35\\linewidth]{images/covering_space} & $\\qquad \\qquad$ &\n\t\t\\includegraphics[width=0.25\\linewidth]{images/branched_covering_space} \\\\\n\t\t$\\qquad \\qquad \\qquad$ Covering Space                         &                 & Branched Covering Space\n\t\\end{tabular}\n\\end{center}\n\n\nSo the map $z^n : \\C \\setminus \\{ 0\\} \\rightarrow \\C \\setminus \\{ 0 \\}$ is a covering map. A map which is a covering map at all points except some isolate ones is called a \\textbf{branched covering}. So $z^n: \\C \\rightarrow \\C$ is a branched covering.\n\nMore generally every complex differentiable function $f(z):\\C \\rightarrow \\C$ is a branched covering and it's restriction to the complement of critical points of $f(z)$ is a covering map.\n\n\\subsection{Monodromy}\nConsider again the function $z^n: \\C \\rightarrow \\C$. Consider a loop around the origin in the \\textbf{target} complex plane passing through $z=1$. If we traverse the loop once and try to lift the loop back up to the domain $z$ then the loop does not remain a loop but becomes a path connecting 1 to the root of unity $e^{2 \\pi i/n}$. In this we say that the covering $z^n$ has non-trivial \\textbf{monodromy}. Monodromy is the mathematical reason why need to glue complex planes to create Riemann surfaces.\\footnote{There is in fact a monodromy group that is acting upon the various sheets via permuting them.}\n\n\n\n\\subsection{Constructing the Riemann surface}\n\nSo the strategy to define the inverse of a polynomial $f(z)$ is the following:\n\\begin{enumerate}\n\t\\item Find the critical points of $f(z)$\n\t\\item On the non-critical points $f(z)$ is a covering map, find the number of \\emph{sheets} over each point using winding numbers\n\t\\item Make branch cuts at each critical point and glue the sheets of complex plane to get a Riemann surface.\n\\end{enumerate}\n\n\n\n\n\\section{Exercises}\n\n\\begin{exercise}\n\tShow that the winding number of $f(z) = z^n$ at $p \\in \\C$ is equal to\n\t\\begin{align}\n\t\tw_f(p) = \\dfrac{1}{2 \\pi i} \\int_{\\gamma} \\dfrac{f(z)}{(z-p)^{n+1}} dz\n\t\\end{align}\n\t$\\gamma$ is a loop sufficiently close to $p$.\n\n\tProve this formula for an arbitrary complex differentiable function $f(z)$.\n\\end{exercise}\n\n\n\\begin{exercise}\n\tFill in the gaps in the proof of Proposition \\ref{thm:windingNum}.\n\\end{exercise}\n\n\n\\begin{exercise}\n\tConstruct Riemann surfaces for the following polynomials:\n\t\\begin{enumerate}\n\t\t\\item $f(z) = z^2 - 2 z$\n\t\t\\item $f(z) = z^3 - 3z$\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\end{document}\n", "meta": {"hexsha": "f5bfca34b761c30143d605a3ca0dceda46949399", "size": 8658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04 How to define the square root/02.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": "04 How to define the square root/02.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": "04 How to define the square root/02.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": 52.4727272727, "max_line_length": 610, "alphanum_fraction": 0.7120582121, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.6206110042846243}}
{"text": "% !TeX spellcheck = en_US\n\\documentclass[]{report}\n\\usepackage[utf8]{inputenc}\n\\usepackage{lmodern}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{tikz}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\begin{document}\n% TODO: Better section names\n\\section{Maxwell's Equations as Groundwork}\n% TODO: Clarify why we wont look at the other two of Maxwell's equations\nAs with any problem in the field of electro-magnetics we will start with \\textit{Maxwell's equations}. Of interest here are only the time-varying equations, i.e. \\textit{Ampere's circuital law} and \\textit{Faraday's law of induction}:\n\\begin{align}\n\t\\nabla \\times \\mathbf{H} &= \\frac{\\partial \\mathbf{D}}{\\partial t} + \\mathbf{J} \\\\\n\t\\nabla \\times \\mathbf{E} &= -\\frac{\\partial \\mathbf{B}}{\\partial t} \\text{ .}\n\\end{align}\nIt is noticeable that there are five unknown quantities to be determined (electric field \\(\\mathbf{E}\\), magnetic induction \\(\\mathbf{B}\\), electric displacement field \\(\\mathbf{D}\\), magnetic field \\(\\mathbf{H}\\) and current density \\(\\mathbf{J}\\)) with only two equations. The missing three equations are the following \\textit{constitutive} relations\n\\begin{align}\n\t\\mathbf{D} &= \\varepsilon \\mathbf{E} \\\\\n\t\\mathbf{B} &= \\mu \\mathbf{H} \\\\\n\t\\mathbf{J} &= \\sigma \\mathbf{E}\n\\end{align}\n% TODO: Explain epsilon, mu, sigma\nthat lead us to the following formulation of Maxwell's equations:\n\\begin{align}\n\t\\nabla \\times \\mathbf{H} &= \\varepsilon \\frac{\\partial \\mathbf{E}}{\\partial t} + \\sigma \\mathbf{E} \\\\\n\t\\nabla \\times \\mathbf{E} &= -\\mu \\frac{\\partial \\mathbf{H}}{\\partial t} \\text{ .}\n\\end{align}\n% TODO: Describe permittivity and permeability\nAfter unfurling the curl operations we get to the following system of six equations\n\\begin{align}\n\t\\partial_y E_z - \\partial_z E_y &= -\\mu \\partial_t H_x \\\\\n\t\\partial_z E_x - \\partial_x E_z &= -\\mu \\partial_t H_y \\\\\n\t\\partial_x E_y - \\partial_y E_x &= -\\mu \\partial_t H_z \\\\\n\t\\partial_y H_z - \\partial_z H_y &= \\varepsilon \\partial_t E_x + \\sigma E_x \\\\\n\t\\partial_z H_x - \\partial_x H_z &= \\varepsilon \\partial_t E_y + \\sigma E_y \\\\\n\t\\partial_x H_y - \\partial_y H_x &= \\varepsilon \\partial_t E_z + \\sigma E_z\n\\end{align}\nthat will function as basis for any of the following discretizations. Note that \\(\\partial_x\\) is a shorthand for the partial derivation operator \\(\\frac{\\partial}{\\partial x}\\).\n\n\\section{Plane Wave as First Example}\nTo gain an understanding of the \\textit{FDTD} (finite-difference time-domain) method, we will work through progressively harder examples starting from a simple one-dimensional plane wave in free space. The electric and magnetic field are perpendicular to the direction of propagation in a plane wave, a property known as \\textit{TEM} (transverse electro-magnetic).\n% TODO: Image for demonstration\n\nIf we pick the \\(z\\)-axis as direction of propagation and assume a linear polarization of the electric field in the direction of the \\(x\\)-axis, we can strike any component of the electric field in the \\(y,z\\)-axis as well as the perpendicular magnetic field in the \\(x,z\\)-axis. Furthermore, any spatial derivative in another direction than the \\(z\\)-axis can be discarded and since we're looking at a wave in free space, the conductivity \\( \\sigma \\) is null.\n\n% TODO: Reference\nFinally, the large system above can be reduced to just two equations\n\\begin{align}\n\t-\\partial_z H_y &= \\varepsilon \\partial_t E_x \\\\\n\t\\partial_z E_x  &= -\\mu \\partial_t H_y\n\\end{align}\nwhich will be discretized in a staggered manner in both space and time by using a finite difference (e.g. central-difference approximation)\n% TODO: Reference the approximation\nto obtain the discrete equations\n\\begin{align}\n\t-\\frac{H_y^{n}(k+1/2) - H_y^n(k-1/2)}{\\Delta z} &= \\varepsilon \\frac{E_x^{n+1/2}(k)-E_x^{n-1/2}(k)}{\\Delta t} \\\\\n\t\\frac{E_x^{n+1/2}(k+1)-E_x^{n+1/2}(k)}{\\Delta z}  &= -\\mu \\frac{H_y^{n+1}(k+1/2)-H_y^{n}(k+1/2)}{\\Delta t}\n\\end{align}\nwhere the superscript gives the instant in time \\( t = \\Delta t \\cdot n \\) and the function parameter gives the position in the grid \\( z = \\Delta z \\cdot k \\). Notice that the calculation of the electric and magnetic field is interleaved in a similar way as you would think about the propagation of an electro-magnetic wave, where a time-varying electric field causes a time-varying magnetic field which again causes a time-varying electric field and so on.\n\nThe calculation here will therefore proceed as such: (1) determine the electric field at instant \\( n+1/2 \\), (2) with that determine the magnetic field at instant \\( n+1 \\), and so on. The spatial grid is also interleaved between electric and magnetic field but the underlying reasoning will be left to the 3D-formulation, where it can be more easily grasped visually.\n\nLet's rearrange to clarify this approach:\n\\begin{align}\n\tE_x^{n+1/2}(k) &= E_x^{n-1/2}(k) - \\frac{\\Delta t}{\\varepsilon \\Delta z}\\left( H_y^n(k+1/2) - H_y^n(k-1/2) \\right) \\\\\n\tH_y^{n+1}(k+1/2) &= H_y^n(k+1/2) - \\frac{\\Delta t}{\\mu \\Delta z}\\left( E_x^{n+1/2}(k+1) - E_x^{n+1/2}(k) \\right) \\text{ .}\n\\end{align}\n% TODO: Reference\nIt can be seen that the first equation only depends on field values of the past and that the second equation only depends on the result of the first equation and field values of the past.\n\nThe time step \\( \\Delta t \\) is chosen to fulfill the \\textit{CFL} (Courant-Friedrichs-Lewy) condition\n\\begin{equation}\n\tc \\frac{\\Delta t}{\\Delta z} \\leq 1\n\\end{equation}\nwhich in our case leads to a maximum time step of\n\\begin{equation}\n\t\\Delta t = \\frac{\\Delta z}{c}\n\\end{equation}\nwhere \\( c \\) is the speed of light. This essentially guarantees that a wave can not pass more than one interval of size \\( \\Delta z \\) in a single time step \\( \\Delta t \\).\n\n% TODO: Reference\nInsertion into the relevant part of equations [REF] yields:\n\\begin{align}\n\t\\frac{\\Delta t}{\\varepsilon \\Delta z} &= \\frac{1}{c \\cdot \\varepsilon} = \\sqrt{\\frac{\\mu_0}{\\varepsilon_0}} \\frac{1}{\\varepsilon_r} = \\frac{Z_0}{\\varepsilon_r} \\\\\n\t\\frac{\\Delta t}{\\mu \\Delta z} &= \\frac{1}{c \\cdot \\mu} = \\sqrt{\\frac{\\varepsilon_0}{\\mu_0}} \\frac{1}{\\mu_r} = \\frac{1}{Z_0 \\mu_r}\n\\end{align}\nwhere \\( Z_0 \\approx 376.73 \\Omega \\) refers to the impedance of free space.\n\n\\section{Simulations}\nNow we just have to set up a grid of values for permittivity and permeability and one or more sources and we can start doing some examples.\n\n% TODO: do a new section here, and one above\n\n\\end{document}          \n", "meta": {"hexsha": "000f2d99640e5db49b61172cf73fe2e7303ed83b", "size": 6417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/plane_wave/plane_wave.tex", "max_stars_repo_name": "DGX2000/electromagnetics-notes", "max_stars_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": "notes/plane_wave/plane_wave.tex", "max_issues_repo_name": "DGX2000/electromagnetics-notes", "max_issues_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": "notes/plane_wave/plane_wave.tex", "max_forks_repo_name": "DGX2000/electromagnetics-notes", "max_forks_repo_head_hexsha": "a05f79c9ac4df476532eb9f084181b3fb9e7b961", "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": 64.8181818182, "max_line_length": 461, "alphanum_fraction": 0.7199625993, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6206109947183924}}
{"text": "\\begin{appendices}\n\n{\\let\\cleardoublepage\\relax}\n\\appendix\n\\chapter{}\n\\section{Estimation}\n\n \\citeauthor*{ac} \\cite{ac} \n\\blindtext  \n\n\\begin{comment}\n\\begin{figure}[H]\n\\begin{center}\n  \\includegraphics[width=0.2\\linewidth]{pixelnb.png}\n  \\caption{The square neighborhood used for spatial denoising.}\n  \\label{fig:lbpschem}\n\\end{center}\n\\end{figure}\n\\end{comment} \n\n\\begin{equation}\n\t\\bar{\\mathbf{c}} = \\frac{1}{N}\\sum_{c \\in Nb(c_{ij}) }c \n\\end{equation}\n\n\\begin{equation}\n\t\\mathbf{K}_{ij} = \\frac{1}{N-1}\\sum_{c \\in Nb(c_{ij})}(c-\\bar{c}_{ij})(c-\\bar{c}_{ij})^T\n\\end{equation}\n\\noindent We denote the noiseless value of the same pixel as $\\mathbf{c}_{ij}^{d}$. We can estimate the posterior probability of the noiseless pixel given the observed noise pixel $p(\\mathbf{c}_{ij}^{d}|\\mathbf{c}_{ij})$ taking into account the Bayesian theorem. Assuming normal distribution for the a priori probability of the noiseless value $p(\\mathbf{c}_{ij}^{d})$ as $\\mathbf{c}_{ij}^{d}\\sim \\mathcal{N} (\\bar{\\mathbf{c}}, \\mathbf{K}_{ij})$ and likelihood $p(\\mathbf{c}_{ij}|\\mathbf{c}_{ij}^{d})$ with mean set as the noisy pixel value and covariance set as the additive noise covariance as $p(\\mathbf{c}_{ij}|\\mathbf{c}_{ij}^{d}) = \\mathcal{N} (\\mathbf{c}_{ij}, \\mathbf{K}_{n})$, Bayesian theorem gives:\n\\begin{align}\n\tp(\\mathbf{c}_{ij}^{d}|\\mathbf{c}_{ij}) &= \\frac{p(\\mathbf{c}_{ij}^{d})p(\\mathbf{c}_{ij}|\\mathbf{c}_{ij}^{d})}{p(\\mathbf{c}_{ij})} \\nonumber \\\\\n\t\t&= \\mathcal{N} (\\mathbf{W}_{ij}(\\mathbf{c}_{ij}-\\bar{\\mathbf{c}})+\\bar{\\mathbf{c}}, \\mathbf{K}_{ij} - \\mathbf{W}_{ij}\\mathbf{K}_{ij})\n\\end{align}\n\n\\blindtext  \n\n\n\\section{Skin Conditions Included in the Study}\n\\blindtext  \n\n\\begin{table}[h!]\n\\centering\n\\caption{The skin conditions included in our dataset.}\n\\label{tabl:diseases}\n\t\\begin{tabular}{l c c c c} \n \t\t\\toprule %\\hline\n \t\t Macropathology Diagnosis & Anatomical Location \\\\ [0.5ex] \n \t\t\\midrule %\\hline\n \t\tone & Exposed skin \\\\\n \t\tone & Exposed skin \\\\\n \t\t\\bottomrule %\\hline\n\t\\end{tabular}\n\\end{table} \n\n\\noindent \\blindtext  \n \n\n\n\\end{appendices}", "meta": {"hexsha": "e7549ee14c7149249eaee1df7250ee8bf9e5b917", "size": 2056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendix.tex", "max_stars_repo_name": "foxelas/GraduationThesisTemplate", "max_stars_repo_head_hexsha": "a18c496870b74672403cfcf3c7b3524151d7c728", "max_stars_repo_licenses": ["MIT"], "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": "foxelas/GraduationThesisTemplate", "max_issues_repo_head_hexsha": "a18c496870b74672403cfcf3c7b3524151d7c728", "max_issues_repo_licenses": ["MIT"], "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": "foxelas/GraduationThesisTemplate", "max_forks_repo_head_hexsha": "a18c496870b74672403cfcf3c7b3524151d7c728", "max_forks_repo_licenses": ["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.4482758621, "max_line_length": 709, "alphanum_fraction": 0.6746108949, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6206109903438709}}
{"text": "\\section{Particle Swarm Optimization}\n\\label{sec:PSOAlg}\nParticle Swarm Optimization (PSO) algorithms are population-based\nprobabilistic optimization algorithms first proposed by \nKennedy and Eberhart~\\cite{EberhartKennedy1995,KennedyEberhart1995}\nto solve problem $\\mathbf P_c$ defined in~\\eqref{sub:Proc} with \npossibly discontinuous cost function $f \\colon \\Re^n \\to \\Re$.\nIn Section~\\ref{sec:PSOBin}, we will present a PSO algorithm \nfor discrete independent variables\nto solve problem $\\mathbf P_d$ defined in~\\eqref{sub:Prod},\nand in Section~\\ref{sec:PSOConDis} we will present a PSO algorithm for \ncontinuous and discrete independent variables\nto solve problem $\\mathbf P_{cd}$ defined in~\\eqref{sub:Procd}.\nTo avoid ambiguous notation, we always denote the dimension of the \ncontinuous independent variable by $n_c \\in \\Na$ \nand the dimension of the \ndiscrete independent variable by\n$n_d \\in \\Na$.\\\\\n\nPSO algorithms exploit a set of potential solutions \nto the optimization problem.\nEach potential solution is called a {\\em particle}, and the set\nof potential solutions in each iteration step is called a {\\em population}.\nPSO algorithms are global optimization algorithms and\ndo not require nor approximate gradients of the cost function.\nThe first population is typically initialized using a random number generator to\nspread the particles uniformly in a user-defined hypercube.\nA particle update equation, which is modeled \non the social behavior of members\nof bird flocks or fish schools,\ndetermines the location of each particle in the next generation.\\\\\n\nA survey of PSO algorithms can be found in \nEberhart and Shi~\\cite{EberhartShi2001}.\nLaskari et. al. present a PSO algorithm for \nminimax problems~\\cite{LaskariEtAl2002:1} and for\ninteger programming~\\cite{LaskariEtAl2002:2}.\nIn~\\cite{ParsopoulosVrahatis2002:2}, Parsopoulos and Vrahatis discuss the\nimplementation of inequality and equality constraints\nto solve problem $\\mathbf P_{cg}$ defined in~\\eqref{sub:Procg}.\\\\\n\nWe first discuss the case where the independent variable is continuous,\ni.e., the case of problem $\\mathbf P_c$ defined in~\\eqref{sub:Proc}.\n\n% --------------------------------------------\n\\subsection{PSO for Continuous Variables}\n\nWe will first present the initial version of the PSO algorithm\nwhich is the easiest to understand.\n\nIn the initial version of the PSO \nalgorithm~\\cite{EberhartKennedy1995,KennedyEberhart1995},\nthe update equation for the particle location is as follows:\nLet $k \\in \\Na$ denote the generation number,\nlet $n_P \\in \\Na$ denote the number of particles in each generation,\nlet $x_i(k) \\in \\Re^{n_c}$, $i \\in \\{ 1, \\ldots, n_P\\}$, \ndenote the $i$-th particle of the $k$-th generation,\nlet $v_i(k) \\in \\Re^{n_c}$ denote its velocity,\nlet $c_1, c_2 \\in \\Re_+$ and let\n$\\rho_1(k), \\rho_2(k) \\sim U(0,1)$ be uniformly distributed random numbers \nbetween $0$ and $1$.\nThen, the update equation is, for all $i \\in \\{1, \\ldots, n_P\\}$ and\nall $k \\in \\Na$,\n\\begin{subequations}\n\\begin{eqnarray}\n  v_i(k+1) & = & v_i(k) + c_1 \\, \\rho_1(k) \\, \\bigl( p_{l,i}(k) - x_i(k) \\bigr)\n \\nonumber \\\\\n&& \n  + c_2 \\, \\rho_2(k) \\, \\bigr( p_{g,i}(k) - x_i(k) \\bigr), \\\\\n  x_i(k+1) & = & x_i(k) + v_i(k+1),\n\\end{eqnarray}\n  \\label{sub:psoOriUpdEqn}\n\\end{subequations}\nwhere $v_i(0) \\triangleq 0$ and \n\\begin{subequations}\n  \\begin{eqnarray}\n    p_{l,i}(k) & \\triangleq & \\argmin_{x \\in \\{ x_i(j) \\}_{j=0}^k} f(x), \\\\\n    p_{g,i}(k) & \\triangleq & \\argmin_{x \\in \\{ \\{ x_i(j) \\}_{j=0}^k \\}_{i=1}^{n_P} } f(x).\n\\label{eq:PSOGloBesIni}\n  \\end{eqnarray}\n\\end{subequations}\nThus, $p_{l,i}(k)$ is the location that for the $i$-th particle yields the lowest\ncost over all generations,\nand $p_{g,i}(k)$ is the location of the best particle over all generations.\nThe term $c_1 \\,  \\, \\rho_1(k) \\, ( p_{l,i}(k) - x_i(k) )$ is associated\nwith cognition since it takes into account the particle's own experience,\nand the term \n$c_2 \\, \\rho_2(k) \\, ( p_{g,i}(k) - x_i(k))$ is associated with\nsocial interaction between the particles.\nIn view of this similarity, $c_1$ is called \n{\\it cognitive acceleration constant} and \n$c_2$ is called {\\it social acceleration constant}.\\\\\n\n% ----------------------------\n\\subsubsection{Neighborhood Topology}\n\\begin{subequations}\nThe minimum in~\\eqref{eq:PSOGloBesIni} need not be taken over all\npoints in the population.\nThe set of points over which the minimum is taken is defined by\nthe {\\it neighborhood topology}.\nIn PSO, the neighborhood topologies are usually defined\nusing the particle index, and not the particle location.\nWe will use the {\\it lbest}, {\\it gbest}, and the {\\it von Neumann}\nneighborhood topology, which we will now define.\\\\\n\nIn the {\\it lbest} topology of size $l \\in \\Na$, with $l > 1$, \nthe neighborhood of a particle with index $i \\in \\{1, \\ldots, n_P \\}$ \nconsist of all particles whose index are in the set\n\\begin{equation}\n  \\mathcal N_i \\triangleq \\{ i-l, \\ldots i, \\ldots , i+l \\},  \n\\label{eq:defLBestNeiHoo}\n\\end{equation}\nwhere we assume that the indices wrap around, i.e., we replace\n$-1$ by $n_P-1$, replace $-2$ by $n_P-2$, etc.\\\\\n\nIn the {\\it gbest} topology, the neighborhood contains all\npoints of the population, i.e., \n\\begin{equation}\n\\mathcal N_i \\triangleq \\{ 1, \\ldots , n_P \\},  \n\\end{equation}\nfor all $i \\in \\{1, \\ldots, n_P \\}$.\\\\\n\nFor the {\\it von Neumann} topology, \nconsider a $2$-dimensional lattice, \nwith the lattice points enumerated as shown in Figure~\\ref{fig:PSOTopology}.\nWe will use the von Neumann topology of range $1$, which is defined,\nfor $i,j \\in \\mathbb Z$, as the set\nof points whose indices belong to the set\n\\begin{equation}\n\\mathcal N_{(i,j)}^v \\triangleq \\left\\{(k,l) \\ \\Bigl| \\ | k - i | + | l - j | \\le 1,\n \\ k,l \\in \\mathbb Z \\right\\}.\n\\label{eq:defVonNeuNei}\n\\end{equation}\nThe gray points in Figure~\\ref{fig:PSOTopology} are $\\mathcal N_{(1,2)}^v$.\nFor simplicity, we round in GenOpt the user-specified number of \nparticles $n_P' \\in \\mathbb N$\nto the next biggest integer $n_P$ such that \n$\\sqrt n_P \\in \\Na$ and $n_P \\ge n_P'$.\\footnote{In principle, \nthe lattice need not be a square, \nbut we do not see any computational disadvantage of selecting a square lattice.}\nThen, we can wrap the indices by replacing, for $k \\in \\mathbb Z$,\n$(0,k)$ by $(\\sqrt n_P, k)$, \n$(\\sqrt n_P + 1,k)$ by $(1, k)$, and similarly by replacing\n$(k,0)$ by $(k, \\sqrt n_P)$ and\n$(k, \\sqrt n_P + 1)$ by $(k, 1)$.\nThen, a particle with indices $(k,l)$,\nwith $1 \\le k \\le \\sqrt n_P$ and $1 \\le l \\le \\sqrt n_P$, \nhas in the PSO algorithm the index $i = (k-1) \\, \\sqrt n_P + l$, and \nhence $i \\in \\{1, \\ldots, n_P \\}$.\\\\\n\\label{sub:PSONeiHooDef}\n\\end{subequations}\n\n\\begin{figure}\n\\centering\n\\begin{pspicture}(-1, 1)(7,-5)\n%%\\psgrid\n% draw dots\n{\\psset{fillcolor=lightgray, fillstyle=solid}\n \\multido{\\iX=0+1}{3}{%\n   \\rput(4,-\\iX){%\n     \\rput(0,-\\iX){%\n       \\pscircle(0,0){0.5}%\n     }%\n   }%\n }%\n \\multido{\\iX=1+1}{3}{%\n   \\rput(\\iX,-2){%\n     \\rput(\\iX,0){%\n       \\pscircle(0,0){0.5}%\n     }%\n   }%\n }%\n}\n\\multido{\\iX=1+1}{2}{%\n  \\multido{\\iY=1+1}{3}{%\n    \\rput(\\iY,-\\iX){%\n      \\rput(\\iY,-\\iX){%\n        \\pscircle(0,0){0.5}%\n        \\psline(0,-0.5)(0,-1)%\n        \\psline(0,0.5)(0,1)%\n        \\psline(-0.5,0)(-1,0)%\n        \\psline(0.5,0)(1,0)%\n      }%\n    }\n  }%\n}%\n\\multido{\\iX=0+1}{3}{%\n  \\multido{\\iY=0+1}{4}{%\n    \\rput(\\iY,-\\iX){%\n      \\rput(\\iY,-\\iX){%\n        \\rput(0,0){\\iX,\\iY}%\n      }%\n    }\n  }%\n}%\n {%\n   \\psset{linestyle=dashed}%\n   \\multido{\\iX=0+1}{4}{%\n     \\rput(\\iX,0){%\n     \\rput(\\iX,0){%\n       \\pscircle(0,0){0.5}%\n       \\psline(0,-0.5)(0,-1)%\n       \\psline(0,0.5)(0,1)%\n       \\psline(-0.5,0)(-1,0)%\n       \\psline(0.5,0)(1,0)%\n     }%\n   }%\n }%\n \\multido{\\iX=0+1}{3}{%\n   \\rput(0,-\\iX){%\n     \\rput(0,-\\iX){%\n       \\pscircle(0,0){0.5}%\n       \\psline(0,-0.5)(0,-1)%\n       \\psline(0,0.5)(0,1)%\n       \\psline(-0.5,0)(-1,0)%\n       \\psline(0.5,0)(1,0)%\n     }%\n   }%\n }%\n}%\n\\end{pspicture}\n\\caption{Section of a $2$-dimensional lattice of particles with $\\sqrt n_P \\ge 3$.\nThe particles belonging to the von Neumann neighborhood \n$\\mathcal N_{(1,2)}^v$ with range $1$,\ndefined in~\\eqref{eq:defVonNeuNei},\nare colored gray.\nIndicated by dashes are the particles that are generated by wrapping the indices.}\n\\lab{fig:PSOTopology}\n\\end{figure}\n\n\nKennedy and Mendes~\\cite{KennedyMendes2002} show that greater connectivity of\nthe particles speeds up convergence, but it does not tend to improve\nthe population's ability to discover the global optimum.\nBest performance has been achieved with the von Neumann topology, whereas\nneither the {\\it gbest} nor the {\\it lbest} topology seemed especially good in\ncomparison with other topologies.\n\nCarlisle and Dozier~\\cite{CarlisleDozier2001} achieve on unimodal\nand multi-modal functions for the\n{\\it gbest} topology better results than for the {\\it lbest} topology.\n\n\n% ----------------------------\n\\subsubsection{Model PSO Algorithm}\n\nWe will now present the Model PSO Algorithm that is implemented in GenOpt.\n\n\\begin{subequations}\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{algorithm}\n[Model PSO Algorithm for Continuous Variables]\n~\\\\\n{\\em\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n \\textbf{Data}:\n     & Constraint set $\\mathbf X$, as defined in~\\eqref{eq:setXPc},\\\\\n     & but with finite lower and upper bound for each independent variable.\\\\ \n     & Initial iterate $x_0 \\in \\mathbf X$.\\\\\n     & Number of particles $n_P \\in \\Na$ and number of generations $n_G \\in \\Na$.\\\\\n  \\textbf{Step 0}: \n     & Initialize $k=0$, $x_0(0) = x_0$ and\n     the neighborhoods $\\{ \\mathcal N_i \\}_{i=1}^{n_P}$ .\\\\\n  \\textbf{Step 1}:\n     & Initialize $\\{ x_i(0) \\}_{i=2}^{n_P} \\subset \\mathbf X$ randomly distributed.\\\\\n  \\textbf{Step 2}:\n     & For $i \\in \\{1, \\ldots, n_P\\}$, determine\n     the local best particles\n\\end{tabularx}\n\\vspace{-1ex}\n\\begin{equation}\n\\hspace{2cm}  p_{l,i}(k) \\triangleq \\argmin_{x \\in \\{ x_i(m) \\}_{m=0}^k} f(x)\n\\end{equation}\n\\vspace{-1ex}\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n & and the global best particle\n\\end{tabularx}\n\\vspace{-1ex}\n\\begin{equation}\n\\hspace{2cm}  p_{g,i}(k) \\triangleq \\argmin_{x \\in \\{ x_j(m) \\ | \\ j \\in \\mathcal N_i \\}_{m=0}^k} f(x).\n\\end{equation}\n\\vspace{-1ex}\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n  \\textbf{Step 3}:\n     & Update the particle location $\\{ x_i(k+1) \\}_{i=1}^{n_P}\\subset \\mathbf X$.\\\\\n  \\textbf{Step 4}:\n     & If $k = n_G$, stop. Else, go to Step 2.\\\\\n  \\textbf{Step 5}:\n     & Replace $k$ by $k + 1$, and go to Step 1.\\\\\n    \\hline \\\\\n\\end{tabularx}\n}\n~\\\\ \\lab{al:PSOImp}\n\\end{algorithm}\n\\end{minipage}\nWe will now discuss the different implementations of the \nModel PSO Algorithm~\\ref{al:PSOImp} in GenOpt.\\\\\n\\lab{sub:PSOImp}\n\\end{subequations}\n\n% ---------------------------------\n\\subsubsection{Particle Update Equation}\n\n% ------------------------------\n\\paragraph[Inertia Weight]{Version with Inertia Weight}\nEberhart and Shi~\\cite{ShiEberhart1998,ShiEberhart1999} introduced\nan {\\it inertia weight} $w(k)$ which improves the performance of the\noriginal PSO algorithm.\nIn the version with inertia weight, the particle update equation is,\nfor all $i \\in \\{1, \\ldots, n_P\\}$, for $k \\in \\Na$ and\n$x_i(k) \\in \\Re^{n_c}$, with $v_i(0) = 0$,\n\\begin{subequations}\n\\begin{eqnarray}\n \\widehat v_i(k+1) & = &  w(k) \\, v_i(k) + \n c_1 \\, \\rho_1(k) \\, \\bigl( p_{l,i}(k) - x_i(k) \\bigr) \\nonumber \\\\\n &&   \n  + c_2 \\, \\rho_2(k) \\, \\bigr( p_{g,i}(k) - x_i(k) \\bigr), \n  \\label{eq:psoUpdEqn1IneWei} \\\\\n  v_i^j(k+1) & = &  \\mathrm{sign}( \\widehat v_i^j(k+1) ) \\, \n  \\min\\{ | \\widehat v_i^j(k+1) | , v_{max}^j \\}, \\nonumber \\\\\n  && \\qquad \\qquad j \\in \\{1, \\ldots, n_c \\}, \n\\label{eq:psoUpdEqn2IneWei} \\\\\n  x_i(k+1) & = & x_i(k) + v_i(k+1),\n\\end{eqnarray}\nwhere\n\\begin{equation}\n  v_{max}^j \\triangleq \\lambda \\, (u^j - l^j),\n  \\label{eq:PSOMaxVelCon}\n\\end{equation}\nwith $\\lambda \\in \\Re_+$,\nfor all $j \\in \\{1, \\ldots, n_c \\}$,\nand $l,u \\in \\Re^{n_c}$ are the lower and upper bound of the independent variable.\nA common value is $\\lambda = 1/2$.\nIn GenOpt, if $\\lambda \\le 0$,\nthen no velocity clamping is used, and hence, $v_i^j(k+1) = \\widehat v_i^j(k+1)$,\nfor all $k \\in \\Na$, all $i \\in \\{1, \\ldots, n_P \\}$ and all\n$j \\in \\{1, \\ldots, n_c \\}$.\n\nWe compute the inertia weight as\n\\begin{equation}\n  w(k) = w_0 - \\frac{k}{K} \\, ( w_0 - w_1 ),\n\\label{eq:PSOIneWeiLin}\n\\end{equation}\nwhere $w_0 \\in \\Re$ is the initial inertia weight, \n$w_1 \\in \\Re$ is the inertia weight for the last generation,\nwith $0 \\le w_1 \\le w_0$,\nand $K \\in \\Na$ is the maximum number of generations.\n$w_0 = 1.2$ and $w_1 = 0$ can be considered as \ngood choices~\\cite{ParsopoulosVrahatis2002:1}.\n\\label{sub:psoUpdEqnIneWei}\n\\end{subequations}\n\n% ------------------------------\n\\paragraph[Constriction Coefficient]{Version with Constriction Coefficient}\nClerc and Kennedy~\\cite{ClercKennedy2002} introduced\na version with a constriction coefficient that reduces \nthe velocity.\nIn their Type 1'' implementation, the particle update equation is,\nfor all $i \\in \\{1, \\ldots, n_P\\}$, for $k \\in \\Na$\nand $x_i(k) \\in \\Re^{n_c}$, with $v_i(0) = 0$,\n\\begin{subequations}\n\\begin{eqnarray}\n \\widehat v_i(k+1) & = & \\chi(\\kappa, \\varphi) \\, \\bigl( v_i(k) + \n c_1 \\, \\rho_1(k) \\, \\bigl( p_{l,i}(k) - x_i(k) \\bigr) \\nonumber \\\\\n &&   \n  + c_2 \\, \\rho_2(k) \\, \\bigr( p_{g,i}(k) - x_i(k) \\bigr) \\bigr),\n  \\label{eq:psoUpdEqn1ConCoe} \\\\\n  v_i^j(k+1) & = &  \\mathrm{sign}( \\widehat v_i^j(k+1) ) \\, \n  \\min\\{ | \\widehat v_i^j(k+1) | , v_{max}^j \\}, \\nonumber \\\\\n  && \\qquad \\qquad j \\in \\{1, \\ldots, n_c\\}, \n\\label{eq:psoUpdEqn2ConCoe} \\\\\n  x_i(k+1) & = & x_i(k) + v_i(k+1),\n\\end{eqnarray}\nwhere\n\\begin{equation}\n  v_{max}^j \\triangleq \\lambda \\, (u^j - l^j),\n  \\label{eq:PSOMaxVelConConCoe}\n\\end{equation}\nis as in~\\eqref{eq:PSOMaxVelCon}.\n\nIn \\eqref{eq:psoUpdEqn1ConCoe}, \n$\\chi(\\kappa, \\varphi)$ is called {\\it constriction coefficient}, defined as\n\\begin{equation}\n  \\chi(\\kappa, \\varphi) \\triangleq\n  \\begin{cases}\n     \\frac{ 2 \\, \\kappa }{ | 2 - \\varphi - \\sqrt{\\varphi^2 - 4 \\, \\varphi} |}, &\n      \\text{if } \\varphi > 4, \\\\\n     \\kappa , & \\text{otherwise},\n  \\end{cases}\n\\label{eq:PSOConCoeChi}\n\\end{equation}\nwhere \n$\\varphi \\triangleq {c_1 + c_2}$\nand $\\kappa \\in (0, 1]$ control how fast the population collapses\ninto a point. If $\\kappa = 1$, the space is thoroughly searched, which\nyields slower convergence.\n\nEquation~\\eqref{sub:psoUpdEqnConCoe} can be used with or without \nvelocity clamping~\\eqref{eq:psoUpdEqn2ConCoe}.\nIf velocity clamping~\\eqref{eq:psoUpdEqn2ConCoe} is used,\nClerc and Kennedy use\n$\\varphi = 4.1$, otherwise they use $\\varphi = 4$. In either case, they\nset $c_1 = c_2 = \\varphi / 2$ and a population size of $n_P = 20$.\\\\\n\nCarlisle and Dozier~\\cite{CarlisleDozier2001} recommend the settings\n$n_P = 30$, no velocity clamping, $\\kappa = 1$, $c_1 = 2.8$\nand $c_2 = 1.3$.\\\\\n\n\nKennedy and Eberhart~\\cite{KennedyEberhartShi2001} report that\nusing velocity clamping \\eqref{eq:psoUpdEqn2ConCoe} \nand a constriction coefficient\nshows faster convergence for some test problems compared to using\nan inertia weight,\nbut the algorithm tends to get stuck in local minima. \n\\label{sub:psoUpdEqnConCoe}\n\\end{subequations}\n\n% ---------------------------------\n\\subsection{PSO for Discrete Variables}\n\\label{sec:PSOBin}\nKennedy and Eberhart~\\cite{KennedyEberhart1997} introduced\na binary version of the PSO algorithm to solve problem $\\mathbf P_d$\ndefined in~\\eqref{sub:Prod}.\\\\\n\nThe binary PSO algorithm encodes the discrete independent variables in a string of\nbinary numbers and then operates with this binary string.\nFor some $i \\in \\{1, \\ldots, n_d\\}$,\nlet $x_i \\in \\Na$ be the component of a discrete independent variable,\nand let $\\psi_i \\in \\{0, 1 \\}^{m_i}$ be its \nbinary representation (with $m_i \\in \\Na_+$ bits),\nobtained using Gray encoding~\\cite{Gray1993}, and\nlet $\\pi_{l,i}(k)$ and $\\pi_{g,i}(k)$ be the binary\nrepresentation of $p_{l,i}(k)$ and $p_{g,i}(k)$, respectively,\nwhere $p_{l,i}(k)$ and $p_{g,i}(k)$ are defined in~\\eqref{sub:PSOImp}.\n\nThen, for\n$i \\in \\{1, \\ldots, n_d\\}$ and $j \\in \\{1, \\ldots, m_i\\}$\nwe initialize randomly\n$\\psi_i^j(0) \\in \\{0, 1 \\}$,\nand compute, for $k \\in \\Na$,\n\\begin{subequations}\n\\begin{eqnarray}\n \\widehat v_i^j(k+1) & = & v_i^j(k) + \n c_1 \\, \\rho_1(k) \\, \\bigl( \\pi_{l,i}^j(k) - \\psi_i^j(k) \\bigr) \\nonumber \\\\\n &&   \n  + c_2 \\, \\rho_2(k) \\, \\bigr( \\pi_{g,i}^j(k) - \\psi_i^j(k) \\bigr) \\bigr),\n  \\label{eq:psoUpdEqn1Bin} \\\\\n  v_i^j(k+1) & = &  \\mathrm{sign}( \\widehat v_i^j(k+1) ) \\, \n  \\min\\{ | \\widehat v_i^j(k+1) | , v_{max} \\}, \n  \\label{eq:psoUpdEqn2Bin}\n \\\\\n  \\psi_i^j(k+1) & = & \n  \\begin{cases}\n    0, & \\text{if } \\rho_{i,j}(k) \\ge s\\bigl( v_i^j(k+1)  \\bigr),\\\\\n    1, & \\text{otherwise,}\n  \\end{cases}\n\\end{eqnarray}\nwhere\n\\begin{equation}\n  s(v) \\triangleq \\frac{1}{1+e^{-v}}\n\\end{equation}\nis the sigmoid function shown in Fig.~\\ref{fig:PSOSigFun}\nand $\\rho_{i,j}(k) \\sim U(0,1)$,\nfor all $i \\in \\{1, \\ldots, n_d\\}$ and for all\n$j \\in \\{1, \\ldots, m_i\\}$.\n\\label{sub:psoUpdEqnBin}\n\\end{subequations}\n\n\\begin{figure}\n\\centering\n{\\psset{yunit=2.5, arrowscale=2}\n\\begin{pspicture}(-5, -0.1)(5,1.5)\n%\\showgrid\n\\multido{\\iX=-4+1}{9}{%\n  \\rput(\\iX,0){\\psline[linewidth=0.2pt]{-}(0,0)(0,1)}\n  \\rput(\\iX,0){\\psline{-}(0,-2pt)(0,2pt)}\n  \\uput[-90](\\iX,0){$\\iX$}\n}\n{\\psset{yunit=0.1}%\n  \\multido{\\iX=2+2}{4}{%\n    \\rput(0,\\iX){\\psline[linewidth=0.2pt]{-}(-4,0)(4,0)}\n    \\rput(0,\\iX){\\psline{-}(-2pt,0)(2pt,0)}\n    \\uput[180](0,\\iX){$0.\\iX$}\n  }\n}\n  \\rput(0,1){\\psline[linewidth=0.2pt]{-}(-4,0)(4,0)}\n  \\rput(0,1){\\psline{-}(-2pt,0)(2pt,0)}\n  \\uput[180](0,1){$1$}\n\\psplot[plotpoints=25]{-4}{4}{ 1 2.71828 x neg exp 1 add div }\n\\psline{->}(-4.5,0)(4.7,0)\n\\psline{->}(0,0)(0,1.3)\n\\uput[-90](4.5,-0.1){$v$}\n\\uput[0](0,1.3){$s(v) = {1} / {( 1 + e^{-v} )}$}\n\\end{pspicture}\n}\n\\caption{Sigmoid function.}\n\\label{fig:PSOSigFun}\n\\end{figure}\n\nIn~\\eqref{eq:psoUpdEqn2Bin}, $v_{max} \\in \\Re_+$ is often set to $4$ to prevent a\nsaturation of the sigmoid function,\nand $c_1,c_2 \\in \\Re_+$ are often such that $c_1+c_2=4$ (see~\\cite{KennedyEberhartShi2001}).\n\nNotice that $s(v) \\to 0.5$, as $v \\to 0$, \nand consequently the probability of flipping a bit goes to $0.5$.\nThus, in the binary PSO, a small $v_{max}$ causes a large exploration, whereas in the\ncontinuous PSO, a small $v_{max}$ causes a small exploration of the search space.\\\\\n\nAny of the above neighborhood topologies can be used,\nand Model Algorithm~\\ref{al:PSOImp} applies if we replace\nthe constraint set $\\mathbf X$ by the user-specified set\n$\\mathbf X_d \\subset \\mathbb Z^{n_d}$.\n\n% --------------------------------------------\n\\subsection{PSO for Continuous and Discrete Variables}\n\\lab{sec:PSOConDis}\nFor problem $\\mathbf P_{cd}$ defined in~\\eqref{sub:Procd}, \nwe treat the continuous \nindependent variables as in~\\eqref{sub:psoUpdEqnIneWei} \nor~\\eqref{sub:psoUpdEqnConCoe}, and the discrete independent variables as\nin~\\eqref{sub:psoUpdEqnBin}.\nAny of the above neighborhood topologies can be used,\nand Model Algorithm~\\ref{al:PSOImp} applies if we define the constraint\nset $\\mathbf X$ as in~\\eqref{sub:setXd}.\n\n% --------------------------------------------\n\\subsection{PSO on a Mesh}\n\\label{sec:PSOMes}\nWe now present a modification to the previously discussed PSO\nalgorithms.\nFor evaluating the cost function, we will modify the continuous\nindependent variables such that they belong to a fixed mesh in $\\Re^{n_c}$.\nSince the iterates of PSO algorithms typically cluster during the last\niterations, this reduces in many cases the number of simulation calls\nduring the optimization. The modification is done by replacing the cost\nfunction $f \\colon \\Re^{n_c} \\times \\mathbb Z^{n_d} \\to \\Re$ in \nModel Algorithm~\\ref{al:PSOImp} as follows:\nLet $x_0 \\triangleq (x_{c,0}, x_{d,0} ) \\in \\Re^{n_c} \\times \\mathbb Z^{n_c}$\ndenote the initial iterate,\nlet $\\mathbf X_c$ be the feasible set for the continuous independent variables\ndefined in~\\eqref{eq:feaSetXc},\nlet $r, s \\in \\Na$, with $r>1$, be user-specified parameters, let\n\\begin{equation}\n  \\Delta \\triangleq \\frac{1}{r^s}\n\\label{eq:PSOMeshDiv}\n\\end{equation}\nand let the mesh be defined as\n\\begin{equation}\n  \\mathbb M(x_{c,0}, \\Delta, s) \\triangleq \\left\\{ x_{c,0} + \\Delta \\,\n  \\sum_{i=1}^n m^i \\,\n  s^i \\, e_i \\ | \\ m \\in \\mathbb Z^{n_c} \\right\\},\n\\label{eq:PSODefMesh}\n\\end{equation}\nwhere $s \\in \\Re^{n_c}$ is equal to the value defined by the variable\n\\texttt{Step} in GenOpt's command file (see page~\\pageref{par:comFil}).\nThen, we replace $f(\\cdot, \\cdot)$ by \n$\\widehat f \\colon \\Re^{n_c} \\times \\mathbb Z^{n_d} \\times \\Re^{n_c} \\times \\Re  \\times \\Re^{n_c} \\to \\Re$, defined by\n\\begin{equation}\n  \\widehat f( x_c, x_d; x_{c,0}, \\Delta, s) \\triangleq \n  f( \\gamma( x_c ), x_d),\n\\end{equation}\nwhere $\\gamma \\colon \\Re^{n_c} \\to \\Re^{n_c}$ is the projection of the\ncontinuous independent variable to the closest feasible mesh point,\ni.e., $\\gamma(x_c) \\in \\mathbb M(x_{c,0}, \\Delta, s) \\cap \\mathbf X_c$.\nThus, for evaluating the cost function, \nthe continuous independent variables are replaced by the closest\nfeasible mesh point, and the discrete independent variables\nremain unchanged.\\\\\n\nGood numerical results have been obtained by selecting $s \\in \\Re^{n_c}$ and\n$r, s \\in \\Na$ such that \nabout $50$ to $100$ mesh points are located\nalong each coordinate direction.\n\n\n% --------------------------------------------\n\\subsection{Population Size and Number of Generations}\nParsopoulos and Vrahatis~\\cite{ParsopoulosVrahatis2002:1} use\nfor $x \\in \\Re^{n_c}$ a population size of about $5 \\, n$ up to $n = 15$.\nFor $n \\approx 10 \\ldots 20$, they use $n_P \\approx 10 \\, n$.\nThey set the number of generations to $n_G = 1000$ up to $n = 20$ and\nto $n_G = 2000$ for $n = 30$.\n\nVan den Bergh and Engelbrecht~\\cite{VanDenBerghEngelbrecht2001}\nrecommend using more than $20$ particles\nand $2000$ to $5000$ generations.\\\\\n\nKennedy and Eberhart~\\cite{KennedyEberhartShi2001} use, for\ntest cases with the {\\it lbest} neighborhood topology of size $l=2$\nand $n=2$ and $n=30$,\na population size of $n_P = 20 \\ldots 30$. They report that $10 \\ldots 50$\nparticles usually work well.\nAs a rule of thumb, they recommend for the {\\it lbest} neighborhood to\nselect the neighborhood size such that each neighborhood consists of $10 \\ldots 20\\%$\nof the population.\n \n% --------------------------------------------\n\\subsection{Keywords}\nFor the Particle Swarm algorithm, \nthe command file (see page~\\pageref{par:comFil})\ncan contain continuous and discrete independent variables.\\\\\n\nThe different specifications for the \\texttt{Algorithm} section \nof the GenOpt command file are as follows:\\\\\n\n\\noindent\nPSO algorithm with inertia weight:\n\\begin{lstlisting}\nAlgorithm{\n  Main                      = PSOIW;\n  NeighborhoodTopology      = gbest | lbest | vonNeumann;\n  NeighborhoodSize          = Integer;  // 0 < NeighborhoodSize\n  NumberOfParticle          = Integer;\n  NumberOfGeneration        = Integer;\n  Seed                      = Integer;\n  CognitiveAcceleration     = Double;   // 0 < CognitiveAcceleration\n  SocialAcceleration        = Double;   // 0 < SocialAcceleration\n  MaxVelocityGainContinuous = Double;\n  MaxVelocityDiscrete       = Double;   // 0 < MaxVelocityDiscrete\n  InitialInertiaWeight      = Double;   // 0 < InitialInertiaWeight\n  FinalInertiaWeight        = Double;   // 0 < FinalInertiaWeight\n}\n\\end{lstlisting}\n\n\\noindent\nPSO algorithm with constriction coefficient:\n\\begin{lstlisting}\nAlgorithm{\n  Main                      = PSOCC;\n  NeighborhoodTopology      = gbest | lbest | vonNeumann;\n  NeighborhoodSize          = Integer;  // 0 < NeighborhoodSize\n  NumberOfParticle          = Integer;\n  NumberOfGeneration        = Integer;\n  Seed                      = Integer;\n  CognitiveAcceleration     = Double;   // 0 < CognitiveAcceleration\n  SocialAcceleration        = Double;   // 0 < SocialAcceleration\n  MaxVelocityGainContinuous = Double;\n  MaxVelocityDiscrete       = Double;   // 0 < MaxVelocityDiscrete\n  ConstrictionGain          = Double;   // 0 < ConstrictionGain <= 1\n}\n\\end{lstlisting}\n\n\\noindent\nPSO algorithm with constriction coefficient and \ncontinuous independent variables\nrestricted to a mesh:\n\\label{algSec:PSOCCMesh}\n\\begin{lstlisting}\nAlgorithm{\n  Main                      = PSOCCMesh;\n  NeighborhoodTopology      = gbest | lbest | vonNeumann;\n  NeighborhoodSize          = Integer;  // 0 < NeighborhoodSize\n  NumberOfParticle          = Integer;\n  NumberOfGeneration        = Integer;\n  Seed                      = Integer;\n  CognitiveAcceleration     = Double;   // 0 < CognitiveAcceleration\n  SocialAcceleration        = Double;   // 0 < SocialAcceleration\n  MaxVelocityGainContinuous = Double;\n  MaxVelocityDiscrete       = Double;   // 0 < MaxVelocityDiscrete\n  ConstrictionGain          = Double;   // 0 < ConstrictionGain <= 1\n  MeshSizeDivider           = Integer;  // 1 < MeshSizeDivider\n  InitialMeshSizeExponent   = Integer;  // 0 <= InitialMeshSizeExponent\n}\n\\end{lstlisting}\n\n\\noindent\nThe entries that are common to all implementations are defined as follows:\n\\begin{codedescription}\n\\item [Main]\nThe name of the main algorithm.\nThe implementation \\texttt{PSOIW} uses the location update \nequation~\\eqref{sub:psoUpdEqnIneWei} \nfor the continuous independent variables,\nand the implementation \\texttt{PSOCC} \nuses~\\eqref{sub:psoUpdEqnConCoe}\nfor the continuous independent variables.\nAll implementations use~\\eqref{sub:psoUpdEqnBin} for the discrete independent variables.\n\\item [NeighborhoodTopology]\nThis entry defines what neighborhood topology is being used.\n\\item [NeighborhoodSize]\nFor the {\\it lbest} neighborhood topology, \nthis entry is equal to $l$ in \\eqref{eq:defLBestNeiHoo}.\nFor the {\\it gbest} and the {\\it von Neumann} neighborhood topology, \nthe value of \\texttt{NeighborhoodSize} is ignored.\n\\item [NumberOfParticle]\nThis is equal to the variable $n_P \\in \\Na$.\n\\item [NumberOfGeneration]\nThis is equal to the variable $n_G \\in \\Na$ in Algorithm~\\ref{al:PSOImp}.\n\\item [Seed]\nThis value is used to initialize the random number generator.\n\\item [CognitiveAcceleration]\nThis is equal to the variable $c_1 \\in \\Re_+$.\n\\item [SocialAcceleration]\nThis is equal to the variable $c_2 \\in \\Re_+$.\n\\item [MaxVelocityGainContinuous]\nThis is equal to the variable $\\lambda \\in \\Re_+$ in~\\eqref{eq:PSOMaxVelCon}\nand in~\\eqref{eq:PSOMaxVelConConCoe}.\nIf \\texttt{MaxVelocityGainContinuous} is set to zero or to a negative value,\nthen no velocity clamping is used, and hence, $v_i^j(k+1) = \\widehat v_i^j(k+1)$,\nfor all $k \\in \\Na$, all $i \\in \\{1, \\ldots, n_P \\}$ and all\n$j \\in \\{1, \\ldots, n_c \\}$.\n\\item [MaxVelocityDiscrete]\nThis is equal to the variable $v_{max} \\in \\Re_+$ in~\\eqref{eq:psoUpdEqn2Bin}.\n\\end{codedescription}\n\n\\vspace{2\\baselineskip}\n\\noindent\nFor the \\texttt{PSOIW} implementation, following additional entries must be\nspecified:\n\\begin{codedescription}\n\\item [InitialInertiaWeight]\nThis is equal to $w_0 \\in \\Re_+$ in~\\eqref{eq:PSOIneWeiLin}.\n\\item [FinalInertiaWeight]\nThis is equal to $w_1 \\in \\Re_+$ in~\\eqref{eq:PSOIneWeiLin}.\n\\end{codedescription}\n\n\\vspace{2\\baselineskip}\n\\noindent\nFor the \\texttt{PSOCC} implementation, following additional entries must be\nspecified:\n\\begin{codedescription}\n\\item [ConstrictionGain]\nThis is equal to $\\kappa \\in (0, 1]$ in~\\eqref{eq:PSOConCoeChi}.\n\\end{codedescription}\nNotice that for discrete independent variables, the entries of\n\\texttt{InitialInertiaWeight}, \\texttt{FinalInertiaWeight}, and \\texttt{ConstrictionGain}\nare ignored.\\\\\n\n\\vspace{2\\baselineskip}\n\\noindent\nFor the \\texttt{PSOCCMesh} implementation, following additional entries must be\nspecified:\n\\begin{codedescription}\n\\item [MeshSizeDivider]\nThis is equal to $r \\in \\Na$, with $r > 1$, used in~\\eqref{eq:PSOMeshDiv}.\n\\item [InitialMeshSizeExponent]\nThis is equal to $s \\in \\Na$ used in~\\eqref{eq:PSOMeshDiv}.\n\\end{codedescription}\n\n", "meta": {"hexsha": "c5b5a3f8c9a21310485114e515696fd20a168f6a", "size": 27972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/algParSwaOpt.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/algParSwaOpt.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/algParSwaOpt.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": 37.4959785523, "max_line_length": 118, "alphanum_fraction": 0.6697769198, "num_tokens": 9748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.620607669078932}}
{"text": "\\LoadClass[notes]{hph}\n\\setauthor{Hrant P.~Hratchian}\n\\settitle{Summer Fortran Workshop: Problem 1 -- The Modified Particle in a Box}\n\\setrunningtitle{Summer Fortran Workshop: Problem 1}\n\\setdate{\\today}\n\\setcounter{chapter}{1}\n%\n\\begin{document}\n\\makeheaderfooter{}\n\\maketitle\n%\n%\n% Section: Introduction and Problem Definition\n\\section{Introduction and Problem Definition}\nConsider a \\emph{modified} one-dimensional particle-in-a-box (\\emph{m}PIB) where the potential is $\\infty$ for $x\\le{}0$ and $x\\ge{}L$. In the range from $0$ to $L$, let the potential energy be given by\n%\n\\begin{equation}\\label{Eq:mPIBPotential}\n\\displaystyle\n  V\\left(x\\right) = b x\\,\\,\\,\\,\\,\\,\\,\\,\\,\\,0<x<L\n\\end{equation}\n%\nUsing atomic units, write a Fortran program that solves for the eigenfunctions and eigenvalues of the first five states of this system. Use the linear variational method to carry out this numerical problem. The standard one-dimensional PIB eigenfunctions should be used as your basis set.\n\nThe PIB problem is a standard model system case studied in quantum mechanics. A brief overview of the model and key results are described below in Section \\ref{Section:TheoreticalBackground}. This problem introduces a non-zero potential inside the box. This programming problem solves for this mPIB using the linear variational method, which is also described in Section \\ref{Section:TheoreticalBackground}.\n\nThe program should take a set of six input arguments from the command line: mass, box length $L$, slope parameter $b$, and the number of basis functions to be used in the calculation.\n\nThe program should output the eigenvalues and expansion coefficients for the ground and first excited state.\n\n%\n% Section: Theoretical Background\n\\section{Theoretical Background}\\label{Section:TheoreticalBackground}\nThis coding problem relies on two theoretical background topics: (1) the particle-in-a-box problem; and (2) the linear variational method.\n\n%\n% Subsection: Particle-in-a-Box\n\\subsection{Particle-in-a-Box}\nAs mentioned above, the one-dimensional particle-in-a-box (PIB) is a model system where the potential is $\\infty$ for $x \\le{}0$ and $x \\ge{} L$. Most derivations begin by dividing the coordinate space into three regions: Region I ($x\\le{}0$), Region II ($0<x<L$), and Region III ($x\\ge{}L$). Regions I and III the potential energy is $\\infty$ and it is trivial to show that the wave function vanishes.\n\nIn Region II, a set of discrete quantum states are found. A quantum number, $n$, is determined to have allowed values $1, 2, 3, \\cdots{}$.\n%\n\\begin{equation}\n\\displaystyle\n  \\braket{x}{n} = \\psi(x) = \\left(\\frac{2}{L}\\right)^{\\sfrac{1}{2}}\\sin{\\left(\\frac{n \\pi}{L}x\\right)}\n    \\,\\,\\,\\,\\,\\,\\,\\,\\,\\,0<x<L\\,\\,\\,\\,\\,\\,\\,\\,\\,\\,n=1,2,3,\\cdots{}\n\\end{equation}\n%\nand the quantized energy levels $\\left\\{E_n\\right\\}$ are\n%\n\\begin{equation}\\label{Eq:PIBenergies}\n\\displaystyle{}\n  E_n = \\frac{\\pi^2}{2 m L^2}n^2\\,\\,\\,\\,\\,\\,\\,\\,\\,\\,n=1,2,3,\\cdots{}\n\\end{equation}\n%\nNote that the energies in Eq.~(\\ref{Eq:PIBenergies}) are given in atomic units ($\\hbar=1$).\n\n%\n% Subsection: Linear Variational Method\n\\subsection{Linear Variational Method}\nThe linear variational method is used to solve the Schr\\\"{o}dinger equation numerically and is the central technique used in this coding problem set. It is an especially useful method when a basis set can be well-defined for the physical system of interest, particularly if the basis set can be systematically increased and refined. The basis set used must satisfy three general requirements. First the members of the basis set should satisfy the same boundary conditions expected for the exact solutions of the Schr\\\"{o}dinger equation being studies. Second, it must be possible to solve matrix elements of the form\n%\n\\begin{equation}\n\\displaystyle\n  H_{\\alpha\\beta} = \\braketop{\\alpha}{\\mathcal{H}}{\\beta}\n\\end{equation}\n%\nwhere \\ket{\\alpha} and \\ket{\\beta} are members of the chosen basis set and $\\mathcal{H}$ is the Hamiltonian. Third, the basis set should either be formally complete or be systematically expandable such that numerical experimentation can sufficiently establish approximate completeness.\n \nGiven these requirements of the basis set, the development of the linear variational method begins with the Schr\\\"{o}dinger equation\n%\n\\begin{equation}\\label{Eq:SchrodingerEquation}\n\\displaystyle\n  \\mathcal{H}\\ket{\\Psi} = E\\ket{\\Psi}\n\\end{equation}\n%\nwhere $\\mathcal{H}$ is the Hamiltonian, \\ket{\\Psi} is the (ground state) eigen-ket (i.e., the wave function), and $E$ is the energy eigenvalue corresponding to \\ket{\\Psi}. Using a (numerically) complete basis with obeying the same boundary conditions as model potential, which we denote as $\\left\\{\\chi_1, \\chi_2, \\cdots{}\\right\\}$, \n%\n\\begin{equation}\\label{Eq:basisExpansion}\n\\displaystyle\n  \\ket{\\Psi} \\approx{} \\sum_n{c_n\\ket{\\chi_n}}\n\\end{equation}\n%\nSubstituting Eq.~(\\ref{Eq:basisExpansion}) into Eq.~(\\ref{Eq:SchrodingerEquation}) yields\n%\n\\begin{equation}\\label{Eq:SchrodingerEquationExpansion}\n\\displaystyle\n  \\mathcal{H}\\ket{\\sum_n{c_n\\chi_n}} = E\\ket{\\sum_n{c_n\\chi_n}}\n\\end{equation}\n%\nMultiplying on the left by another member of the complete set and invoking the interchange theorem of summation and integration, Eq.~(\\ref{Eq:SchrodingerEquationExpansion}) becomes\n%\n\\begin{equation}\\label{Eq:SchrodingerEquationMatrix1}\n\\displaystyle\n  \\sum_n{c_n \\braketop{m}{\\mathcal{H}}{n}} = E\\sum_n{c_n\\braket{m}{n}}\n\\end{equation}\n%\nwhere index labels $m$ and $n$ have been used to denote \\ket{\\chi_m} and \\ket{\\chi_n}.\n\nIn the application of the linear variational method used here, the basis set will be the conventional PIB eigenfunctions. Noting that this is an orthonormal basis set, Eq.~(\\ref{Eq:SchrodingerEquationMatrix1}) can be written as\n%\n\\begin{equation}\\label{Eq:SchrodingerEquationMatrix1}\n\\displaystyle\n  \\sum_n{c_n \\braketop{m}{\\mathcal{H}}{n}} = E\\sum_n{c_n\\delta_{mn}}\n\\end{equation}\n%\nand, in matrix form as\n%\n\\begin{equation}\\label{Eq:SchrodingerEquationMatrix2}\n\\displaystyle\n\\begin{aligned}\n  \\sum_n{H_{mn}c_{n}} ={}& Ec_m  \\\\\n  \\mathbf{Hc} ={}& E\\mathbf{c}\n\\end{aligned}\n\\end{equation}\n%\nEquation (\\ref{Eq:SchrodingerEquationMatrix2}) is an eigensystem. Once the Hamiltonian matrix elements are solved, a standard eigenvalue decomposition algorithm can be used to find a set of eigenvectors (the expansion coefficients $\\mathbf{c}$) and eigenvalues (the expectation energy corresponding to each eigenvector). The eigenvector with the lowest corresponding eigenvalue is the linear variational ground state solution to Eq.~(\\ref{Eq:SchrodingerEquation}). The other eigenvectors (with eigenvalues greater than the lowest) are the linear variational method solutions for excited states. Generally, a well chosen basis set that can be systematically increased will converge in the number of basis functions for the ground state and low energy excited states before converging for higher energy excited states.\n\n\n%How does the ground state energy vary as a function of the number of basis functions? To explore this point, begin by using the two lowest energy states of the standard particle-in-a-box system as your set of basis functions. Then, use the first three states of the standard particle-in-a-box as your basis set. Follow this by numerical tests using four, five, six, seven, eight, nine, and ten states. Plot the ground state energy as a function of the number of basis functions used.\n%\n%Repeat the previous experiment with the potential function changed to $V\\left(x\\right) = 10 m x$.\n%\n%Plot the ground state wavefunction for the previous two problems using an appropriately converged basis set size. Comment on the effect of the added potential on the shape of the ground state wavefunction.\n%\n\\end{document}\n", "meta": {"hexsha": "9b06bc61184e54fae556312b23aae57fa9ee19f8", "size": 7754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exercises_Workshop2/ProblemSet01-ModifiedPIB/tex/problem01.tex", "max_stars_repo_name": "MQCPack/summerCodingWorkshop", "max_stars_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-29T16:24:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-29T16:24:28.000Z", "max_issues_repo_path": "Exercises_Workshop2/ProblemSet01-ModifiedPIB/tex/problem01.tex", "max_issues_repo_name": "MQCPack/summerCodingWorkshop", "max_issues_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_issues_repo_licenses": ["MIT"], "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_Workshop2/ProblemSet01-ModifiedPIB/tex/problem01.tex", "max_forks_repo_name": "MQCPack/summerCodingWorkshop", "max_forks_repo_head_hexsha": "77989f555497c14711c4aa1817540fdc3131eee4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-26T21:05:45.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-26T21:05:45.000Z", "avg_line_length": 61.5396825397, "max_line_length": 816, "alphanum_fraction": 0.7601238071, "num_tokens": 2099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.620558654178418}}
{"text": "\n\\section{Data Mapping Between Meshes}\\label{sec:data_mapping_between_meshes}\n\n% introduction, mapping required for operator splitting, different dimensionalities, source to target mesh\n% goal is to construct a mapping in the order of the target mesh\n% parallel partitioning -> treat source mesh as point cloud\n\n% target->source is interpolation, construct transposed mapping\nAfter the implementation of various solvers for specific parts of the multi-domain model has been described in the previous sections, we now focus on the data mapping between different meshes that occurs in the coupling schemes between the execution of the coupled solvers. \n\nData mapping between meshes is required in scenarios that involve both a finely resolved 3D mesh for the electrophysiology model and a coarse 3D mesh for the solid mechanics model. Moreover, data are mapped between the 3D muscle mesh and the embedded 1D fiber meshes in the fiber based electrophysiology model. In these two cases, the mapping has to be carried out in both directions between the involved meshes. The operation can be characterized as \\emph{volume mapping}.\n\nWe implement a generic mapping scheme between two meshes of any dimensionality and with any relative orientation with respect to each other. \nGiven is a finite element interpolant on a \\emph{source} mesh, defined by the dof values at the nodes. The goal is to set the dof values of the \\emph{target} mesh, such that the error between the finite element representations on the common domain of source and target mesh is as low as possible. By using the ansatz functions of the target mesh, the constructed mapping has the same order of accuracy as the target mesh interpolant. For a linear target mesh, the mapping operation is second order accurate, for a quadratic target mesh, the mapping operation is third order accurate.\n\nThe considered source and target meshes are possibly partitioned. In order to perform the data mapping directly between two such meshes without communication between the processes, the partitioning of the volumes would have to be identical. However, this is not practical for different meshes and would disallow different orientations of source and target meshes. The only way to allow such a mapping is to consider either the source or the target mesh as a point cloud and construct the mapping between individual points and a mesh.\n\nConsidering the case of mapping the activation parameter value $\\gamma$, which is stored on multiple 1D fibers, to the value $\\bar{\\gamma}$ on the 3D muscle mesh, it is natural to consider the source mesh as a point cloud. Then, instead of multiple fibers, we have a set of points, where $\\gamma$ is known. This set of source points is mapped to the enclosing 3D target mesh. On every process, the source points have to be located inside the local subdomain of the target mesh.\n\nThe reverse mapping in this example is also required: The geometry of the 3D muscle mesh has to be mapped to the fibers points, such that a deformation of the muscle also affects the embedded fibers. This reverse mapping from the target mesh to the source fiber meshes or points is trivial: The source values can be interpolated in the target mesh using the finite element discretization.\nWe construct the mapping from source to target mesh to be the transpose operation to this interpolation. In the following section, we introduce the method with a graphical example.\n\n\\subsection{Construction of the Parallel Data Mapping}\n\n\\Cref{fig:mapping_between_meshes_2} shows a scenario, where data mapping is performed from a source mesh to a target mesh. The source mesh is given by the orange points $s_0$ to $s_3$. The target mesh is visualized by the black and gray elements $e_{\\text{T},0}$ to $e_{\\text{T},3}$  and nodes $t_0$ to $t_3$.\n\nThe value at $s_0$ contributes to all nodes $t_0$ to $t_3$ of the target element $e_{\\text{T},0}$ as indicated by the red arrows. The relations between the contributions to $t_0,t_1,t_2$ and $t_3$ are determined by the values of the respective target element ansatz functions $\\phi_0$ to $\\phi_3$, evaluated at the location of $s_0$.\nSimilarly, the source points $s_1$ to $s_3$ contribute to the nodes of their enclosing target elements $e_{\\text{T},1}$ and $e_{\\text{T},2}$. \n\n% mapping scheme\n\\begin{figure}%\n  \\centering%\n  \\def\\svgwidth{0.4\\textwidth}\n  \\input{images/implementation/mapping_between_meshes_2.pdf_tex}%\n  \\caption{Data mapping scheme from source points (orange) to a target mesh (black).}%\n  \\label{fig:mapping_between_meshes_2}%\n\\end{figure}%\n\nAs a consequence, all shown source points $s_0$ to $s_3$ influence the value of the target node $t_0$, as indicated by the red arrows.\nThe value $\\hat{t}_0$ at point $t_0$ is computed using the values $\\hat{s}_i$ at the points $s_i$ for $i=1,\\dots,4$ as follows:\n%\n\\begin{align}\\label{eq:mapping_source_target}\n  \\hat{t}_0 = \\s{i=0}{4} \\alpha_i\\,\\hat{s}_i, \\quad \\text{with }\\alpha_i = \\dfrac{\\phi_{\\noexpand\\mkern-4mu t_0}(\\bfxi_{s_i})}{\\s{i=0}{4} \\phi_{\\noexpand\\mkern-4mu t_0}(\\bfxi_{s_i})}.\n\\end{align}\nHere, $\\phi_{\\noexpand\\mkern-4mu t_0}$ is the finite element ansatz function for the node $t_0$. It is evaluated at the locations $\\bfxi_{s_i}$ of the source points $s_i$ in the respective target elements. The factors $\\alpha_i$ specify the fractions, with which the different contributions to $\\hat{t}_0$ are scaled. Their construction ensures the property $\\sum_{i=1}^4 \\alpha_i = 1$.\nNote that the number of summands in the sum over the source points can be different from 4 for other target points.\n\n% reverse mapping scheme\n\\begin{figure}%\n  \\centering%\n  \\begin{subfigure}{0.4\\textwidth}\n    \\centering\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/implementation/mapping_between_meshes_3.pdf_tex}%\n    \\caption{Mapping from target to source points using the reverse scheme of \\cref{fig:mapping_between_meshes_2}.}%\n    \\label{fig:mapping_between_meshes_3}%\n  \\end{subfigure}\n  \\quad\n  \\begin{subfigure}{0.4\\textwidth}\n    \\centering\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/implementation/mapping_between_meshes_4.pdf_tex}%\n    \\caption{Inverse mapping scheme where the roles of source and target mesh are swapped.}%\n    \\label{fig:mapping_between_meshes_4}%\n  \\end{subfigure}\n  \\caption{Data mapping from target mesh to source mesh.}%\n  \\label{fig:mapping_between_meshes_34}%\n\\end{figure}%\n\nThe reverse mapping from target nodes to source points uses the same data dependencies between dofs in the source and in the target meshes. \\Cref{fig:mapping_between_meshes_3} shows the scheme for the reverse mapping. It is the same as in \\cref{fig:mapping_between_meshes_2}, except that the direction of the arrows has been flipped. As noted earlier, the mapping from the target to the source mesh is simply an interpolation in the target mesh. The value $\\hat{s}_0$ is computed from $\\hat{t}_0$ to $\\hat{t}_3$ using the finite element interpolation formula in element $e_{\\text{T},0}$:%\n\\begin{align*}\n  \\hat{s}_0 = \\s{i=0}{4}\\hat{t}_i\\,\\phi_{\\noexpand\\mkern-4mu t_i}(\\bfxi_{s_0}).\n\\end{align*}\nAgain, the contribution factors sum up to one, $\\sum_{i=0}^4 \\phi_{\\noexpand\\mkern-4mu t_i}(\\bfxi_{s_0}) = 1$.\n\nThis mapping scheme has the advantage that it requires no communication between the involved processes to determine the target dofs, to which a source dof contributes to. Considering the example in \\cref{fig:mapping_between_meshes_2} and assuming that the four target elements are located on four different subdomains, it can be seen that each source point $s_i$ only has to access the target element, where it is contained, to determine the respective element coordinates $\\bfxi_{s_i}$.\n\nFor the computation of the factors $\\alpha_i$ in \\cref{eq:mapping_source_target} and for the computation of the target dofs, communication is required. This communication step is the same exchange of ghost dof values, which is also needed for the assembly of finite element stiffness and mass matrices. In the implementation, it is available by the respective functionality of PETSc as described in \\cref{sec:oragnization_of_parallel_partitioned_data}.\nThe reverse mapping from target to source meshes, i.e., the interpolation scheme, works without any communication as all required data are local to the processes.\n\nInstead of reversing the source to target mapping as described, it is often also possible to change the roles of source and target mesh and construct a new mapping in this way. This is only possible, if the two meshes have the same dimensionality, as in the considered example visualizations with two 2D meshes. \\Cref{fig:mapping_between_meshes_4} shows the presented mapping scheme with the roles of source and target meshes reversed.\nBy comparing with \\cref{fig:mapping_between_meshes_3}, it can be seen that, in this case, the node $t_0$ contributes to the same nodes $s_0$ to $s_3$ in both approaches. However, the contribution factors are different. In general, the dependent nodes in both meshes are not necessarily the same in the two mapping directions. This means that, in general, the reversed or transposed mapping is not equal to the inverse mapping that is created by interchanging source and target meshes.\n\nFor mappings between different dimensionalities, only the approach of reversing the mapping in one direction is possible. For example, mapping from a 1D mesh to a 3D mesh allows no interpolation in the 1D mesh to get the 3D mesh data, as the 1D mesh occupies only a subset of the domain of the 3D mesh. This is a reason for implementing the presented mapping scheme, where the mapping direction can be reversed. Another advantage is that, once the mapping is constructed, both mapping directions are available and the expensive operation of locating the points of one mesh inside the elements of the other mesh has only be performed once.\n\n\\subsection{Special Treatment of Coarse Meshes}\n% special case with coarse meshes\n\n% reverse mapping scheme\n\\begin{figure}%\n  \\centering%\n  \\begin{subfigure}{0.4\\textwidth}\n    \\centering\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/implementation/mapping_between_meshes_5.pdf_tex}%\n    \\caption{Mapping scheme from source to target mesh.}%\n    \\label{fig:mapping_between_meshes_5}%\n  \\end{subfigure}\n  \\quad\n  \\begin{subfigure}{0.4\\textwidth}\n    \\centering\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/implementation/mapping_between_meshes_6.pdf_tex}%\n    \\caption{Reverse mapping scheme from target mesh to source points.}%\n    \\label{fig:mapping_between_meshes_6}%\n  \\end{subfigure}\n  \\caption{Data mapping scheme with additional data dependencies for a coarse source mesh.}%\n  \\label{fig:mapping_between_meshes_56}%\n\\end{figure}%\n\nWhile the mapping error in the described scheme converges to zero, when the mesh widths approach zero, an issue occurs, if one of the meshes is significantly coarser than the other. \\Cref{fig:mapping_between_meshes_5} depicts the case of a coarse source mesh in orange color that is mapped to a finer target mesh in black and gray colors. According to the presented scheme, the source points $s_0$ and $s_3$ contribute to target nodes as visualized by the red arrows. The analog contributions for $s_1$ and $s_2$ are not shown in \\cref{fig:mapping_between_meshes_5}. Some target mesh nodes in this example have large distances to the source points and, as a result, do not get contributions from any source point. For example, this is the case for the target points $t_1$ and $t_2$.\n\nTo define the value at $t_2$ depending on the source data, we add new contributions from all nodes of the source element in which $t_2$ is located. These contributions are visualized by the yellow arrows in \\cref{fig:mapping_between_meshes_5}.\nThe contributions use the ansatz functions of the source element, and the operation is equivalent to interpolating the value for $t_2$ in the source mesh:\n\\begin{align*}\n  \\hat{t}_2 = \\s{i=0}{4}\\hat{s}_i\\,\\phi_{\\noexpand\\mkern-4mu s_i}(\\bfxi_{t_2}).\n\\end{align*}\nThe location $\\bfxi_{t_2}$ of $t_2$ in element coordinates of the source element is required for this computation. Analogously, corresponding contributions are added for the other target nodes that do not yet get any contribution from the source data.\n\nThese additional contributions are also present in the reversed mapping scheme from the target to the source mesh. As can be seen in \\cref{fig:mapping_between_meshes_6}, the value at $t_2$ contributes to the source nodes $s_0$ to $s_3$. At any source node, the number of contributions increases accordingly. The visualization in \\cref{fig:mapping_between_meshes_6} shows five incoming arrows with contributions for $s_0$ and $s_3$. The actual number is higher, since not all target nodes with additional contributions are visualized. At the target nodes, the contribution factors get rescaled, such that they add up to 1 and their relations are preserved.\n\n\\subsection{Computation of Element Coordinates For Mapped Points}\n\nDuring the setup of the mapping between the source mesh and the target mesh, we need to find, for every source point $s_i$, the target element $e_{\\text{T},j}$ that contains $s_i$. Furthermore, we need to determine the local element coordinates $\\bfx_{s_i} = (\\xi_1,\\xi_2,\\xi_3)^\\top$ of the point in this element. To check, if the point is inside a particular element, we compute its coordinates in the element coordinate system. If the coordinates $\\bfxi$ are inside the range of $[0,1]^d$, the point is considered inside this element, and the coordinates are determined.\n\nThe source point is given by coordinates $\\bfx=(x_1,x_2,x_3)^\\top \\in \\R^3$ in the world coordinate frame. The point is related to the $d$-dimensional element coordinate frame $(\\xi_1,\\dots,\\xi_d)$ of its containing target element by the following map:\n\\begin{align}\\label{eq:mapping_parameter_world}\n  \\bfx(\\bfxi) = \\s{i=1}{n_\\text{dofs}} \\phi_i(\\bfxi)\\, \\bfx^i.\n\\end{align}\nHere, $\\phi_i$ for $i=1,\\dots,n_\\text{dofs}$, are the nodal ansatz functions of the target element. The element  has $n_\\text{dofs}$ dofs and is given by its node positions $\\bfx^i$.\n\nThe computation of the element coordinates $\\bfxi$ from the world coordinates $\\bfx$ consists of inverting the mapping in \\cref{eq:mapping_parameter_world}. In the following, several approaches are presented to perform this inversion for different mesh types.\n\nFor meshes of type \\code{StructuredRegularFixedOfDimension<D>}, the inversion can be performed analytically. The mesh is a Cartesian grid with a fixed mesh width $h$. For quadratic elements, $h$ denotes the side length of an element, not the distance between adjacent nodes.\nThe computation of the element coordinates $\\bfxi$ for the point $\\bfx$ uses the position $\\bfx^1$ of the first node and is given by:\n\\begin{align*}\n  \\bfxi = (\\bfx - \\bfx^1) / h.\n\\end{align*}\nThis formula is also used for 1D meshes of any type.\n\nFor non-Cartesian 2D meshes with linear ansatz functions, i.e., meshes of type \\code{Struc}\\code{tured}\\code{DeformableOfDimension<2>}, the inversion of the mapping from element to world coordinate frame in \\cref{eq:mapping_parameter_world} can also be done analytically. We consider this problem in a generic way, where both the point $\\bfx$ and the nodes $\\bfx^1$ to $\\bfx^4$ of the 2D element are embedded in 3D space, $\\bfx,\\bfx^1,\\dots,\\bfx^4 \\in \\R^3$. The computation determines the element coordinates $(\\xi_1,\\xi_2)$ of the projection of $\\bfx$ onto the plane of the triangle $(\\bfx^1,\\bfx^2,\\bfx^3)$. \n\nThis functionality is used for specifying electrodes on the skin surface. The electrode positions are specified as a 2D grid in 3D space above the muscle. The mapping automatically projects the points of this grid onto the surface of the 3D mesh. \\Cref{fig:electrodes} shows such a use case. A simulation of surface EMG is shown, the coloring corresponds to the potential $\\phi_b$ in millivolts in the body domain. A grid of electrode points, visualized by spheres, is mapped onto the surface of the muscle mesh and simulates electrode patches that capture high density surface EMG.\n\n% electrodes\n\\begin{figure}%\n  \\centering%\n  \\includegraphics[width=\\textwidth]{images/implementation/electrodes.png}%\n  \\caption{Simulation of surface EMG using the fiber based electrophysiology model with body fat layer. Only the top surface of the fat layer mesh is shown. The spheres correspond to the position of surface electrodes that are used to sample the simulation result in a spatial grid.}%\n  \\label{fig:electrodes}%\n\\end{figure}%\n\nAfter calculating the mentioned projection on the 2D plane, the computation has to invert the map in \\cref{eq:mapping_parameter_world}. The ansatz functions $\\phi_i$ are bilinear in the coordinates $\\xi_1$ and $\\xi_2$. This quadratic equation has two solutions for the unknown coordinates $\\bfxi$. The formulas for those solutions have been determined using the symbolic mathematics toolbox \\emph{SymPy} \\cite{meurer2017sympy} and the solution, where the point is inside the element or closer to its center is chosen.\n\nFor generic hexahedral 3D meshes, \\cref{eq:mapping_parameter_world} is a cubic equation in $\\bfxi$, and the analytic inversion is not feasible. However, for simplex elements, i.e., tetrahedra given by points $\\bfx^1$ to $\\bfx^4$, it is possible. The ansatz in this case is given by:\n\\begin{align*}\n  \\bfx &= (1-\\xi_1-\\xi_2-\\xi_3)\\,\\bfx^1 + \\xi_1\\,\\bfx^2 + \\xi_2\\,\\bfx^3 + \\xi_3\\,\\bfx^4.\n\\end{align*}\nThis can be reformulated as:\n\\begin{align}\\label{eq:simplex_ansatz}\n   \\bfx-\\bfx^1 &= (\\bfx^2 - \\bfx^1)\\,\\xi_1 + (\\bfx^3  - \\bfx^1)\\,\\xi_2 + (\\bfx^4 - \\bfx^1)\\,\\xi_3.\n\\end{align}\nThis linear system of three equations can be solved for the three unknowns $\\xi_1,\\xi_2$ and $\\xi_3$.\n\nTo invert the mapping for hexahedral elements, we proceed as follows.\nA hexahedral element can be subdivided into five simplex elements. \nFour outer simplex elements share their faces with parts of the hexahedral's surface. One interior simplex element only touches the hexahedron surface by its edges. \n\nIn each of the four outer simplex elements, we define a coordinate system $(\\xi_1,\\xi_2,\\xi_3)$ with the origin located at a corner of the hexahedron. \nIn these elements, the coordinates $\\bfxi$ for the point $\\bfx$ can be computed  using the ansatz in \\cref{eq:simplex_ansatz}. The computed coordinate values can be transformed to the hexahedral coordinate system by applying the appropriate mirror operations $\\xi \\mapsto (1-\\xi)$ on some coordinates. Using the average values of the hexahedral coordinates resulting from all four outer simplex elements gives a good approximation for the correct hexahedral element coordinates $\\bfxi$ of the point $\\bfx$.\n\nTo obtain the correct element coordinates, these approximate values are used as initial guess in a Newton scheme, which subsequently tries to find the root of $\\bfr = (\\bfxi - \\bfx(\\bfxi))$ and, thus, invert the mapping in \\cref{eq:mapping_parameter_world}. \n\nRuntime measurements have shown that the lower number of Newton iterations resulting from the heuristic with the four simplex elements to compute an initial guess outweighs the additional runtime for the heuristic and, in total, leads to a faster computation.\n\nThe Newton scheme uses the inverse Jacobian matrix of the mapping in \\cref{eq:mapping_parameter_world}. If the residual norm $\\Vert\\bfr\\Vert_2$ cannot not be brought under the threshold of \\num{1e-8} in 16 iterations, this indicates that the problem of inverting the Jacobian is badly conditioned and the Jacobian has a large numerical error. In this case, the optimization is restarted using the derivative-free Nelder-Mead algorithm.\n\nBefore applying the Newton and Nelder-Mead algorithms, our implementation performs two basic checks that can directly terminate the computation of the coordinates: First, the coordinates of the point $\\bfx$ are compared with the bounding box of all nodes of the element. If the point is outside the bounding box, the element coordinates do not have to be computed, and a different element, which contains the point $\\bfx$, is searched. Second, all node positions are checked for equality with the point $\\bfx$. If $\\bfx$ is the same as one of the node positions, the element coordinates are directly known. This case frequently occurs, if one of source and target mesh is a subset of the other.\n\n\\subsection{Conditioning of the Problem and Mapping Tolerances}\n\nAs mentioned in the last section, the Newton scheme that solves the inverse problem of mapping a point from elemental coordinates to world coordinates uses the inverse Jacobian matrix of the mapping. The inversion of this matrix has a high numerical error, if the condition number of the Jacobian matrix is large. A large condition number can be found for 3D hexahedral elements, where the two element coordinate directions for $\\xi_1$ and $\\xi_2$ are almost linearly dependent. This is the case for elements with an interior angle of nearly \\SI{180}{\\degree}. \\Cref{fig:bad_element} shows such an element, which occurs at the outer boundary of the muscle mesh.\n\n% bad_element\n\\begin{figure}%\n  \\centering%\n  \\includegraphics[width=0.3\\textwidth]{images/implementation/bad_element2.png}%\n  \\caption{Hexahedral element of the muscle mesh with an interior angle of nearly \\SI{180}{\\degree}. Such elements lead to poor conditioning of the Jacobian matrix inversion problem and, as a consequence, require numerous Newton iterations in the setup of the data mapping between meshes.}%\n  \\label{fig:bad_element}%\n\\end{figure}%\n\nIf the conditioning is too bad and the computed inverse Jacobian has a large numerical error, the Newton scheme fails to find a solution in the given maximum number of iterations and the Nelder-Mead algorithm is used instead. This algorithm usually succeeds. However, it requires significantly more compute time than the Newton scheme. The case where the Nelder-Mead algorithm is needed, however, only occurs for a small number of elements and only in highly-resolved meshes.\n\n\\Cref{fig:condition_number2} shows the condition number of the Jacobian matrix of the mapping from element to world coordinates per element. The condition number is numerically approximated using the \\emph{von Mises} power iteration algorithm to obtain the largest eigenvalue of the Jacobian and its inverse.\nIt can be seen in \\cref{fig:condition_number7x7} that the elements with the highest condition number are located along longitudinal lines on the outer surface of the muscle mesh. Two such lines exist on both sides of the muscle. The cross-sectional mesh at the top of the muscle shows that the elements along these lines have large interior angles at the respective positions. \n\n% condition number 7x7\n\\begin{figure}%\n  \\centering%\n  \\begin{subfigure}{0.9\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{images/implementation/condition_number.png}%\n    \\caption{Scenario with $7\\times 7$ fibers.}%\n    \\label{fig:condition_number7x7}%\n  \\end{subfigure}\\\\[4mm]\n  \\begin{subfigure}{0.9\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{images/implementation/condition_number2.png}%\n    \\caption{Scenario with $9\\times 9$ fibers}%\n    \\label{fig:condition_number9x9}%\n  \\end{subfigure}\n  \\caption{Fiber meshes and corresponding muscle mesh, obtained with a sampling stride of two. The left and right view show both sides of the muscle mesh. The 3D mesh is colored by the condition number of the Jacobian matrix.}%\n  \\label{fig:condition_number2}%\n\\end{figure}%\n\n\\Cref{fig:condition_number9x9} shows the same information for a different mesh with $9\\times 9$ fibers instead of the subset of $7\\times 7$ fibers in \\cref{fig:condition_number7x7}. In \\cref{fig:condition_number9x9}, the outer surface of the muscle mesh is smoother and the interior angle of the elements along the respective longitudinal lines is even closer to \\SI{180}{\\degree}. Thus, the resulting maximum condition number has a higher value of \\num{30.2} compared to \\num{4.48} in the example of \\cref{fig:condition_number7x7}.\n\nAnother effect can be seen in the visualization in \\cref{fig:condition_number7x7}. The muscle mesh was generated from the fiber data with sampling strides of two in the cross-sectional directions. As a consequence, the nodes of the 3D mesh are part of every second fiber. This results in some outer fibers being located outside the domain of the 3D mesh. Such a case can be seen for the upper-most fiber in \\cref{fig:condition_number7x7}. \n\nTo also involve such fibers in the computation, we enable data mapping between the 3D mesh and fibers that are outside but close to the 3D mesh. We add a tolerance parameter $\\xi_\\text{tolerance}$ to the implementation that specifies, how far outside the mesh fibers can be located to still be included in the mapping. On the element level, a point is considered to be part of an element, if its element coordinates $(\\xi_1,\\xi_2,\\xi_3)$ are no further than $\\xi_\\text{tolerance}$ off the element domain, i.e., for %\n\\begin{align*}\n  -\\xi_\\text{tolerance} \\leq \\xi_i \\leq 1 + \\xi_\\text{tolerance}\\quad \\forall i \\in \\{1,2,3\\}.\n\\end{align*}\nThis treats the outside fibers as if they were located inside the 3D mesh. For the fibers in the interior, the threshold leads to potentially multiple neighboring elements claiming ownership of a point. In this case, the element that contains the point without this tolerance value is chosen.\nBy default, the tolerance value is set to $\\xi_\\text{tolerance}=0.1$, but it can be adjusted to different values in the Python settings file if needed.\n\nIn summary, OpenDiHu can map data between any two overlapping meshes. The inversion of the mapping from elemental to world coordinates is an important task of this problem, which is non-trivial for 3D hexahedral elements and is solved numerically. The combination of fiber meshes with a 3D muscle mesh leads to specific effects such as degraded condition numbers or fibers outside the 3D mesh that have to be considered in the mapping.\n\n\\begin{reproduce_no_break}\n  The visualizations in \\cref{fig:condition_number2} were obtained using the \\code{electrophysiology/fibers/fibers_emg} example. The condition number of the Jacobian is computed by the \\code{StaticBidomainSolver} if the parameter \\code{`enableJacobianConditionNumber`} is set to \\code{True}.\n\\end{reproduce_no_break}\n", "meta": {"hexsha": "932095245ab8ed6d90c54933523040abe5d23b61", "size": 26357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/07_implementation_2.tex", "max_stars_repo_name": "maierbn/phd_thesis_source", "max_stars_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-05T19:00:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T19:00:04.000Z", "max_issues_repo_path": "document/07_implementation_2.tex", "max_issues_repo_name": "maierbn/phd_thesis_source", "max_issues_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "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": "document/07_implementation_2.tex", "max_forks_repo_name": "maierbn/phd_thesis_source", "max_forks_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "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": 113.6077586207, "max_line_length": 782, "alphanum_fraction": 0.7820692795, "num_tokens": 6596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6205586444563777}}
{"text": "%---------------------------Mean Aspect Frobenius-----------------------------\n\\section{Mean Aspect Frobenius}\n\nFor quadrilaterals, there is not a unique definition of the aspect Frobenius.\nInstead, we use the aspect Frobenius\ndefined for triangles (see section~\\S\\ref{s:tri-aspect-Frobenius}).\nConsider the four triangles formed by pairs of neighboring quadrilateral edges.\nGiven three counterclockwise, consecutively ordered quadrilateral vertices $i$, $j$, and $k$\ndenote the triangular aspect frobenius $F_{ijk}$.\nTo obtain a single value for the metric, we average the four unique triangular aspects\n\\[\n  q = \\frac{1}{4}\\left(F_{301} + F_{012} + F_{123} + F_{230}\\right).\n\\]\n\n\\quadmetrictable{mean 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 square\n{\\cite{pebay:04}}%                          Citation\n{v\\_quad\\_med\\_aspect\\_frobenius}%          Verdict function name\n\n", "meta": {"hexsha": "babd1c1186f292e614a3982da596b168934fd217", "size": 1125, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadMedAspectFrobenius.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/QuadMedAspectFrobenius.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/QuadMedAspectFrobenius.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": 46.875, "max_line_length": 92, "alphanum_fraction": 0.5795555556, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6205586386057963}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb,amsthm,fullpage,enumerate,hyperref}\n\\theoremstyle{definition}\n\\newtheorem{exmp}{Example}\n\\newtheorem{defi}{Definition}\n\\newtheorem{theo}{Theorem}\n\\newtheorem{coro}{Corollary}\n\\newtheorem{prop}{Proposition}\n\\begin{document}\nIn this talk I'm going work towards defining modular forms in the {\\it correct} way. This means using Katz' definitions. The only problem is that in order to use his definitions, you need a very solid grasp of algebraic geometry and differential geometry.\n\\section{Lattices and modular forms}\nSuppose you have two linearly independent elements in the complex plane, call them $\\omega_1$ and $\\omega_2$. Then you can form a lattice\n\\[L=\\mathbb{Z}\\omega_1+\\mathbb{Z}\\omega_2.\\]\nTopologically, the quotient\n\\[\\mathbb{C}/L=\\{\\tau+L:\\tau\\in\\mathbb{C}\\},\\]\nis a torus. We can see this by the homeomorphism\n\\[\\phi:\\mathbb{C}/L\\to I^2/{\\sim}\\text{, given by }x\\omega_1+y\\omega_2+L\\mapsto [\\mathrm{mod}(x,1),\\mathrm{mod}(y,1)]_{\\sim}.\\]\nRecall that for an integer weight $k$, the group $\\mathrm{SL}_2(\\mathbb{Z})$ acts on the right on functions $f:\\mathbb{H}\\to\\mathbb{C}$ by\n\\[(f|_k\\gamma)(\\tau)=(c\\tau+d)^{-k}f(\\gamma.\\tau),\\]\nwhere $(a,b;c,d)\\in\\gamma\\in\\mathrm{SL}_2(\\mathbb{Z})$ and $\\gamma.\\tau=(a\\tau+b)/(c\\tau+d)$.\n\nClassically, a modular form of integral weight $k$ and level $1$, is a holomorphic function on the upper-half plane satisfying:\n\\begin{enumerate}[(i)]\n  \\item $f|_k\\gamma=f$ for every $\\gamma\\in\\mathrm{SL}_2(\\mathbb{Z})$, and\n  \\item $f(\\tau)$ is bounded as $\\tau\\to i\\infty$.\n\\end{enumerate}\nThis can be expressed in terms of lattices.\n\\begin{defi}[Modular form, lattice definition]\n  Let $k$ be an integer. Then a modular form of weight $k$ and level $1$ is a function $F$ on lattices in $\\mathbb{C}$ satisfying:\n  \\begin{enumerate}[(i)]\n    \\item $F(\\lambda L)=\\lambda^{-k}F(L)$ for every $\\lambda\\in\\mathbb{C}\\setminus\\{0\\}$.\n    \\item Let $\\omega\\in\\mathbb{C}$ be fixed and define $L_\\tau=\\mathbb{Z}\\omega+\\mathbb{Z}\\tau$. Then\n      \\[\\mathbb{C}\\ni\\tau\\mapsto F(L_\\tau)\\in\\mathbb{C},\\]\n      is holomorphic.\n    \\item With $L_\\tau$ as above, then $F(L_\\tau)$ is bounded as $\\tau\\to i\\infty$.\n  \\end{enumerate}\n\\end{defi}\nThese definitions are equivalent in the sense that given a modular form $f$ on the upper-half plane, then there's a unique modular form\\footnote{Given by $\\mathbb{Z}\\omega_1+\\mathbb{Z}\\omega_2\\mapsto \\omega_2^{-k}f(\\omega_1/\\omega_2)$ for $\\mathrm{Im}(\\omega_1/\\omega_2)>0$.} $F$ on lattices satisfying $F(\\mathbb{Z}+\\mathbb{Z}\\tau)=f(\\tau)$, and given a modular form $F$ on lattices, then there's a unique modular form\\footnote{Given by $\\tau\\mapsto F(\\mathbb{Z}+\\mathbb{Z}\\tau)$.} $f$ on the upper-half plane satisfying $f(\\tau)=F(\\mathbb{Z}+\\mathbb{Z}\\tau)$.\n\nSince we vaguely know that lattices and elliptic curves are equivalent, this suggest that we can view modular forms (of level $1$) as functions on elliptic curves \\ldots\\ somehow.\n\nThis is Katz' starting point.\n\\section{How do we carry the weight?}\nThe way we carry the weight to the setting of elliptic curves is to associate a differential form to the curve.\n\nIn this section I want to establish the necessary notions that allows us to do this for the lattice $\\mathbb{C}/L$. So, what we'll do is that in more generality that complex tori $\\mathbb{C}^n/L$ are complex manifolds, and then make sense of the $1$-form $dz$ on $\\mathbb{C}/L$ even means.\n\\subsection{Complex manifolds -- the very basics}\nFor this section, I decided to use the excellent book {\\it From Holomorphic Functions to Complex Manifolds} by Grauert and Fritzsche.\n\nLet's begin by defining what a complex manifold is.\n\\begin{defi}[Complex coordinate system, complex coordinates]\n  An $n$-dimensional complex coordinate system $(U,\\phi)$ in $X$ consists of an open set $U\\subseteq X$ and a homeomorphism $\\phi:U\\to B$ where $B\\subseteq\\mathbb{C}^n$.\n\n  If $p\\in X$ is a point, then a complex coordinate system $(U,\\phi)$ in $X$ with $p\\in U$ is called a complex coordinate system at $p$. The entries $z_i=\\mathbf{z}=\\phi(p)$ are called the complex coordinates of $p$ with respect to $(U,\\phi)$.\n\n  If $f$ is a complex function in $U$, we view it as a function of the complex coordinates $(z_1,\\dots,z_n)$ via\n  \\[(z_1,\\dots,z_n)\\mapsto f\\circ\\phi^{-1}(z_1,\\dots,z_n).\\]\n\\end{defi}\n\\begin{defi}[Compatible coordinate systems]\n  Let $\\mathcal{U}=(U,\\phi)$ and $\\mathcal{V}=(V,\\psi)$ be two $n$-dimensional complex coordinate systems in a Hausdorff space $X$. Then we say that $\\mathcal{U}$ and $\\mathcal{V}$ are (holomorphically) compatible if $U\\cap V=\\emptyset$ or\n  \\[\\phi\\circ\\psi^{-1}:\\psi(U\\cap V)\\to\\phi(U\\cap V),\\]\n  is biholomorphic (bijective holomorphic with holomorphic inverse).\n\\end{defi}\nNow we get to a notion that I believe most of you have heard of -- an atlas.\n\\begin{defi}[Atlas, complex structure]\n  Let $X$ be a Hausdorff space. Then a covering of $X$ with pairwise compatible $n$-dimensional complex coordinate systems is called an $n$-dimensional complex atlas on $X$.\n\n  Two atlases $\\mathcal{A}_1$ and $\\mathcal{A}_2$ on $X$ are called equivalent if {\\it any} two coordinate systems $(U,\\phi)\\in\\mathcal{A}_1$ and $(V,\\psi)\\in\\mathcal{A}_2$ are compatible.\n\n  An equivalence class of $n$-dimensional complex atlases on $X$ is called an $n$-dimensional complex structure on $X$.\n\\end{defi}\nThis is all we need to define a complex manifold.\n\\begin{defi}[Complex manifold]\n  An $n$-dimensional complex manifold is a second-countable Hausdorff space $X$ together with an $n$-dimensional complex structure.\n\\end{defi}\nThe space $\\mathbb{C}^n$ itself is a complex manifold.\n\\begin{exmp}\n  Let $\\mathbb{C}^n$ have the Euclidean topology coming from $\\mathbb{R}^{2n}$. Then $\\mathbb{C}^n$ is Hausdorff and second countable (take balls with rational radii and centers).\n\n  Let $\\mathcal{A}=\\{(\\mathbb{C}^n,\\mathrm{id})\\}$. Since $\\mathrm{id}$ is biholomorphic, it's clear that $\\mathcal{A}$ is an $n$-dimensional complex atlas. Hence $[\\mathcal{A}]$ is a complex structure.\n\\end{exmp}\nSo is any non-empty open subset of a complex manifold.\n\\begin{exmp}\n  Hello!\n\\end{exmp}\n\nIn order to talk about, we need the notion of quotients of manifolds, and for this we need to define\n\\begin{enumerate}\n  \\item Holomorphic maps.\n  \\item Holomorphic functions on complex manifolds.\n  \\item Holomorphic mappings between complex manifolds.\n  \\item Analytic subsets.\n  \\item Local Jacobian.\n  \\item The rank of a holomorphic map.\n%  \\item Immersion and submersion.\n\\end{enumerate}\n\\begin{defi}[Holomorphic maps]\n  Let $B\\subseteq\\mathbb{C}^n$ be open. A map\n  \\[\\mathbf{f}=(f_1,\\dots,f_m):B\\to\\mathbb{C}^m,\\]\n  is called holomorphic if all components $f_i$ are holomorphic.\n\\end{defi}\n\\begin{defi}[Holomorphic functions on complex manifolds]\n  Let $X$ be an $n$-dimensional complex manifold. A complex function $f$ on an open subset $B\\subseteq X$ is called holomorphic if for each $p\\in B$ there is a coordinate system $(U,\\phi)$ at $p$ such that\n  \\[f\\circ\\phi^{-1}:\\phi(U\\cap B)\\to\\mathbb{C},\\]\n  is holomorphic. We denote the set of holomorphic functions on $B$ by $\\mathcal{O}(B)$.\n\\end{defi}\n\\begin{defi}[Holomorphic mappings between complex manifolds]\n  Let $X$ and $Y$ be complex manifolds and let $F:X\\to Y$ be continuous. Then $F$ is called holomorphic if for any $p\\in X$ there is a coordinate system $(U,\\phi)$ at $p$ and a coordinate system $(V,\\psi)$ at $F(p)$ with $F(U)\\subseteq V$ such that\n  \\[\\psi\\circ F\\circ\\phi^{-1}:\\phi(U)\\to \\psi(V),\\]\n  is a holomorphic map.\n\\end{defi}\n\\begin{defi}[Analytic subset]\n  Let $X$ be an $n$-dimensional complex manifold. Then a subset $A\\subseteq X$ is called analytic if for each point $p\\in X$ there is a connected open neighborhood $U$ of $p$ and finitely many holomorphic functions $f_1,\\dots,f_m$ on $U$ such that\n  \\[U\\cap A=\\{q\\in U:f_i(q)=0\\text{ for }i=1,\\dots,m\\}.\\]\n\\end{defi}\n\\begin{defi}[Local Jacobian]\n  Let $f_1,\\dots,f_m$ be holomorphic functions defined on an open subset $U\\subseteq X$. Let $p\\in U$ be a point and $(V,\\psi)$ a complex coordinate system in $X$ at $p$. Then the mapping $\\mathbf{f}:(f_1,\\dots,f_m):U\\to\\mathbb{C}^m$ is holomorphic and we define\n  \\[J_\\mathbf{f}(p;\\psi)=\\Big(\\frac{\\partial(f_i\\circ\\psi^{-1})}{\\partial z_j}(\\psi(p))\\Big)_{\\substack{1\\leq i\\leq m\\\\1\\leq j\\leq n}},\\]\n  is the local Jacobian matrix at $(V,\\psi)$ and $p$.\n\\end{defi}\nOne can show that\n\\[J_\\mathbf{f}(p;\\psi)=J_\\mathbf{f}(p;\\phi)\\cdot\\lambda,\\]\nfor some invertible matrix $\\lambda$. This shows that\n\\[\\mathrm{rk}\\,J_\\mathbf{f}(p;\\psi)=\\mathrm{rk}\\,J_\\mathbf{f}(p;\\phi),\\]\nfor any pair of coordinate systems $(U,\\phi)$ and $(V,\\psi)$ at $p$ in $X$. Hence we can define:\n\\begin{defi}[Rank of holomorphic map]\n  Let $X$ be an $n$-dimensional complex manifold and let $U\\subset X$ be an open subset. Let $\\mathbf{f}:U\\to\\mathbb{C}^m$ be a holomorphic map. Then we write\n  \\[\\mathrm{rk}_p(\\mathbf{f})=\\mathrm{rk}(J(p;\\psi)),\\]\n  where $(V,\\psi)$ is any coordinate system at $p$ in $X$.\n\\end{defi}\n%\\begin{defi}[Submersion]\n%  Let $X$ and $Y$ be complex manifolds with dimension $n$ and $m$, respectively, and let $f:X\\to Y$ be a holomorphic map. \n%\\end{defi}\n\\subsection{Quotients of manifolds}\nLet $X$ be an $n$-dimensional complex manifold and let $\\sim$ be an equivalence relation. Then it's interesting to ask when $X/{\\sim}$ carries the structure of a complex manifold such that $\\pi:X\\to X/{\\sim}$ is a holomorphic map.\n\nThis is what we'll answer in this section. Let us begin by defining ``saturated'' sets.\n\\begin{defi}[Saturated set]\n  Let $X$ be a complex manifold and let $\\sim$ be an equivalence relation on $X$. Let $\\pi:X\\to X/{\\sim}$ be the projection $\\pi(x)=[x]$. We call a set $A$ saturated if\n  \\[\\pi^{-1}(\\pi(A))=A.\\]\n\\end{defi}\n\\begin{theo}\n  Let $X$ be a complex manifold of dimension $n$, and let $\\sim$ be an equivalence relation.  Suppose the following conditions hold.\n  \\begin{enumerate}[(i)]\n    \\item With the quotient topology, $X/{\\sim}$ is Hausdorff.\n    \\item For any $x_0\\in X$ there exists a saturated open neighborhood $\\hat{U}$ of $[x_0]$ in $X$ and a holomorphic map $\\mathbf{f}:\\hat{U}\\to\\mathbb{C}^{n-d}$ such that\n      \\begin{enumerate}[(a)]\n        \\item such that $\\mathbf{f}^{-1}(\\mathbf{f}(x))=[x]$ for all $x\\in\\hat{U}$.\n        \\item $\\mathrm{rk}_x(\\mathbf{f})=n-d$ for $x\\in\\hat{U}$.\n      \\end{enumerate}\n  \\end{enumerate}\n  Then $X/{\\sim}$ carries a unique structure of an $n-d$ dimensional complex manifold such that $\\pi:X\\to X/{\\sim}$ is a holomorphic map (in fact a so-called ``submersion'').\n\\end{theo}\n\\begin{proof}\n  {\\tt Include only the part about the complex structure.}\n\\end{proof}\nThe above theorem has an important corollary.\n\\begin{coro}\n  Let $X$ be an $n$-dimensional complex manifold and let $G$ be a group that acts freely and properly discontinuously on $X$. Then $X/G$ has the structure of an $n$-dimensional complex manifold. (It's more or less unique, but let's not delve into this.)\n\\end{coro}\n\\begin{proof}\n  The fact that $G$ acts freely and properly discontinuously is what makes $X/G$ Hausdorff, so let's ignore this for now, and really try to focus on the complex structure.\n\\end{proof}\n\\begin{prop}\n  Let $L$ be a lattice in $\\mathbb{C}^n$. Then $L$ acts freely and properly discontinously on $\\mathbb{C}^n$ by translation.\n\\end{prop}\n\\begin{proof}\n  {\\tt Definitely include.}\n\\end{proof}\nNow we finally now can define complex tori.\n\\begin{defi}[Complex torus]\n  Let $L$ be a lattice in $\\mathbb{C}^n$. Then the $n$-dimensional complex torus associated to $L$ is the quotient manifold $\\mathbb{C}^n/L$.\n\\end{defi}\n\\subsection{Complex differential forms on complex manifolds}\nThere is a lot of interesting content here, and I won't delve into the deep stuff. In fact, I'll only consider forms on $\\mathbb{C}/L$. But still, we need to define:\n\\begin{enumerate}\n  \\item Derivations.\n  \\item Tangent vectors.\n  \\item Tangent space.\n  \\item Induced maps.\n\\end{enumerate}\nA word on notation: if $X$ is a complex manifold and $B\\subseteq X$ is open, we say that a function $f:B\\to\\mathbb{C}$ is smooth if for every complex coordinate system $(U,\\phi)$ with $U\\cap B\\neq\\emptyset$ it holds that $f\\circ\\phi^{-1}$ is smooth on $\\phi(U\\cap B)\\subseteq\\mathbb{C}^n$. The real vector space of real valued smooth functions on $B$ is denoted by $\\mathcal{E}(B)$.\n\\begin{defi}[Derivation]\n  Let $X$ be an $n$-dimensional manifold and let $a\\in X$ be a point. Then a derivation on $X$ at $a$ is an $\\mathbb{R}$-linear map $v:\\mathcal{E}(X)\\to\\mathbb{R}$ such that\n  \\[v[f\\cdot g]=v[f]\\cdot g(a)+f(a)\\cdot v[g],\\]\n  for $f,g\\in\\mathcal{E}(X)$.\n\n  The (real) vector space of derivations on $X$ at $a$ is denoted by $T^\\mathbb{R}_a(X)$.\n\\end{defi}\nThe notation hints at a connection with tangent vectors, and there is an isomorphisms to the space of tangent vectors, but I want to keep it simple.\n\nThe following proposition is useful.\n\\begin{prop}\n  If $f\\in\\mathcal{E}(X)$ and $f|_U=0$ for some open neighborhood of $U$ of $a\\in X$, then $v[f]=0$ for every derivation $v$ at $a$.\n\\end{prop}\n\\begin{proof}\n  Let $g\\in\\mathcal{E}(X)$ satisfy $g|_V=0$ for some neighborhood $V$ of $a$, whose closure is compact and contained in $U$; and $g|_{X\\setminus U}=0$. (This is just a cut-off/mollifier function, and they are no problem to construct.)\n\n  Then $g\\cdot f=f$ and also\n  \\[v[f]=v[g\\cdot f]=v[g]\\cdot f(a)+g(a)\\cdot v[f]=0,\\]\n  because $a\\in V\\subseteq U$.\n\\end{proof}\nThe point of the previous proposition is that we can always restrict derivations to locally defined functions.\n\\begin{coro}\n  Let $X$ be an $n$-dimensional complex manifold, and let $f,g$ be smooth functions on $X$ that agree on an open neighborhood of a point $a\\in X$. Then for every derivation $v$ at $a$ it holds that $v[f]=v[g]$.\n\\end{coro}\n\\begin{proof}\n  Apply the previous proposition to $f-g$.\n\\end{proof}\nWe now extend to complex valued functions.\n\\begin{defi}\n  Let $f=g+ih$ be a complex valued smooth function on the open set $B\\subseteq X$ and let $v$ be a derivation at $a\\in B$. Then we define\n  \\[v[f]=v[g]+iv[h].\\]\n\\end{defi}\nThis allows us to complexify $T^\\mathbb{R}_a(X)$ to get $T_a(X)$.\n\\begin{prop}\n  Let $J:T_a^\\mathbb{R}(X)\\to T_a^\\mathbb{R}(X)$ satisfy\n  \\[J(v)[f]=iv[f],\\]\n  for every holomorphic function $f:X\\to\\mathbb{C}$. Then $J$ is a complex structure.\n\\end{prop}\nWe define $T_a(X)=(T^\\mathbb{R}_a(X),J)$ and recall that $(a+ib)v=av+b\\cdot J(v)$ for $a+ib\\in\\mathbb{C}$.\n\n\\begin{defi}[Induced mapping]\n  Given a holomorphic map $F:X\\to Y$ where $X$ and $Y$ are complex manifolds and a point $x\\in X$, we can define a map $(F_\\ast)_x:T_x(X)\\to T_{F(y)}(Y)$, as follows.\n  \\[(F_\\ast v)[g]=v[g\\circ F],\\]\n  for derivations $v\\in T_x(X)$ and functions $g\\in\\mathcal{E}(Y)$.\n\n  This is called the tangential map, or the pushforward.\n\\end{defi}\nThis construction actually defines a covariant functor from the category of a complex manifolds with a distinguished point to the category of vector spaces. In the sense that given $F:X\\to Y$, and $a\\in X$ and $b=F(a)$, then we get a linear map $(F_\\ast)_a:T_a(X)\\to T_b(X)$ satisfying\n\\[(\\mathrm{id}_X)_\\ast=\\mathrm{id}_{T_x(X)},\\]\nand\n\\[(G\\circ F)_\\ast=G_\\ast\\circ F_\\ast.\\]\n\nNow we're finally ready to define what we mean by $dz$, or more generally $dz_i$ for $1\\leq i\\leq n$, on a complex $n$-dimensional manifold $X$. First, we set\n\\[T^\\ast_x(X)=\\mathrm{Hom}_\\mathbb{R}(T_x(X),\\mathbb{R}),\\]\nand define $F_x(X)=T^\\ast_x(X)\\oplus iT^\\ast_x(X)$.\n\n\\begin{defi}[Differential of function]\n  Let $X$ be an $n$-dimensional complex manifold and let $x\\in X$. Let $f$ be a real of complex valued function, smooth on a neighborhood of $x$. Then we define $(df)_x\\in F_x(X)$ by\n  \\[(df)_x(v)=v[f].\\]\n  In particular, if $(z_1,\\dots,z_n)$ are local coordinates at $x$, we define\n  \\[dz_i=(dz_i)_x,\\]\n  so that $dz_i(v)=v[z_i]$.\n\\end{defi}\nThat's really it, now we know theoretically what Katz' means by $dz$ on $\\mathbb{C}/L$.\n\\end{document}\n", "meta": {"hexsha": "a1187f27ab5c2c3c4b2a6c97530b4f750d7ae652", "size": 15953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk1/manuscript2.tex", "max_stars_repo_name": "zin0vka/katz_modular_forms", "max_stars_repo_head_hexsha": "75dc6e38a6d09a78c090ee356de293e947050839", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "talk1/manuscript2.tex", "max_issues_repo_name": "zin0vka/katz_modular_forms", "max_issues_repo_head_hexsha": "75dc6e38a6d09a78c090ee356de293e947050839", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "talk1/manuscript2.tex", "max_forks_repo_name": "zin0vka/katz_modular_forms", "max_forks_repo_head_hexsha": "75dc6e38a6d09a78c090ee356de293e947050839", "max_forks_repo_licenses": ["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.3266129032, "max_line_length": 561, "alphanum_fraction": 0.6987400489, "num_tokens": 5296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6204886312201554}}
{"text": "\\section{Introduction}\nHello, World! å ä ö\n\n\\begin{equation}\nJ^{\\alpha,\\beta} = -(1-x^2) \\frac{d^2}{dx^2} - [\\beta - \\alpha - (\\alpha + \\beta +2)x]\\frac{d}{dx}.\n\\end{equation}\n\n\\section{Lol}\n\n\\begin{eqnarray}\nu(\\theta,\\, t) &=& \\sum_{n \\in \\Z} \\left( \\int_{2n\\pi}^{2n\\pi+\\pi} W_t(\\theta-\\phi)f(\\phi-2n\\pi) \\dd \\phi + \\int_{2n\\pi - \\pi}^{2n\\pi}W_t(\\theta-\\phi)  f(2n\\pi - \\phi)\\dd \\phi \\right)\\nonumber\\\\\n&=& \\sum_{n \\in \\Z} \\left( \\int_{0}^{\\pi} W_t(\\theta-\\varphi-2n\\pi) f(\\varphi)\\dd \\varphi + \\int_{0}^{\\pi}W_t(\\theta+\\varphi-2 n \\pi)  f(\\varphi) \\dd \\varphi \\right)\\nonumber,\n\\end{eqnarray}\n\n\\subsection{Test}\n\n\\begin{defi}\nFor $t>0$ we define $h_t(x)$ by\n\\begin{displaymath}\nh_t(x)=\\frac{\\vv'_t(x)}{ W'_t(x)}, \\quad  0 < x \\leq \\pi,\n%h_t(z)=\\frac{d\\vv_t}{dz} \\left( \\frac{d W_t}{dz} \\right)^{-1}, \\quad  z\\in[0,\\pi]\n\\end{displaymath}\nand as $\\lim_{x \\rightarrow 0^+}h_t(x)$ at $x=0$.\n\\end{defi}\n\n\n\\begin{thm}\\label{thm:integralformula}\nLet $t>0$ and $\\theta \\in \\zeropi$. Then\n\\begin{equation}\\label{eq:estimationsintegral}\nG^{0}_t(\\cos\\theta,\\,1) =e^{t/4} \\int_{\\theta/2}^{\\pi-\\theta/2} \\frac{ -\\vv'_{t/4}(\\gamma)  }{\\sqrt{2\\cos \\theta - 2\\cos 2\\gamma}} \\dd \\gamma.\n\\end{equation}\n\\end{thm}\n\n\n\\begin{proof}[Proof of Theorem \\ref{thm:integralformula}]\nLet us first prove that $h_t(x) \\leq 1$ for $x\\in [0,\\,\\pi]$ and then prove that $h_t(x) \\leq \\frac{\\pi}{t}(\\pi -x) $ for $x\\in [0,\\,\\pi]$.\n\\end{proof}", "meta": {"hexsha": "de6d8bbc85833b6d2d4fbad8bac15f9b2466c4da", "size": 1408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matematics_article/content.tex", "max_stars_repo_name": "Penlect/latex-templates", "max_stars_repo_head_hexsha": "51affdf1973ab4ac3c7ff303641181f0ef6cd5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "matematics_article/content.tex", "max_issues_repo_name": "Penlect/latex-templates", "max_issues_repo_head_hexsha": "51affdf1973ab4ac3c7ff303641181f0ef6cd5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matematics_article/content.tex", "max_forks_repo_name": "Penlect/latex-templates", "max_forks_repo_head_hexsha": "51affdf1973ab4ac3c7ff303641181f0ef6cd5df", "max_forks_repo_licenses": ["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.0540540541, "max_line_length": 194, "alphanum_fraction": 0.6065340909, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6204564820107001}}
{"text": "\\documentclass{article}\n\n\\usepackage[margin=0.2cm]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{ulem}\n\\usepackage{hyperref}\n\\usepackage{minted}\n\\usepackage{multicol}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{subfigure}\n\n\n\\begin{document}\n\n\\tableofcontents\n\n\\newpage\n\\section{Hall's marriage theorem}\nLet $G=(V,E)=(X+Y,E)$ be a bipartite graph, $G$ has a complete matching from $X$ to $Y$ iff $\\forall S\\subseteq X\\ |S|\\leq |N(S)|$,\\\\\nwhere $N_G(S)=\\{y\\in Y\\mid \\exists x\\in S\\ (x,y)\\in E\\}$.\n\n\n\n\\subsubsection{sufficiency}\n($\\Rightarrow$)\\quad\nLet $M=\\{(x,f(x))\\in E\\mid x\\in X\\}\\subseteq E$ be a complete matching.\\\\\n$N_G(S)=\\{y\\in Y\\mid \\exists x\\in S\\ (x,y)\\in E\\}\\supseteq \\{f(x)\\mid x\\in S\\}$.\n\n\\subsubsection{necessity}\n($\\Leftarrow$)\\quad\nApply induction on $|X|$.\n\\begin{enumerate}\n\t\\item When $|X|=1$, the necessity is hold.\n\t\\item Suppose that the necessity is hold, for $|X|\\leq k$\n\t\\item For $|X|=k+1$, $\\forall S\\subseteq X\\ |S|\\leq |N_G(X)|$\n\t      \\begin{itemize}\n\t\t      \\item $\\forall \\varnothing\\subsetneq S\\subsetneq X\\ |N_G(S)|>|S|$\\\\\n\t\t            Select any edge $e=(x,y)$. Remove the vertices $x,y$ and every edges $(u,v)$ to get $G'$ s.t. $x\\in\\{u,v\\}\\lor y\\in\\{u,v\\}$.\\\\\n\t\t            In $G'$, $\\forall \\varnothing\\subsetneq S\\subseteq (X\\setminus \\{x\\})\\quad |N_{G'}(S)|\\geq |N_{G}(S)|-1\\geq |S|$.\\\\\n\t\t            So we can find a complete matching  $M':X'\\to Y'$ in $G'$.\\\\\n\t\t            Thus A complete matching $M:X\\to Y$ can generated by $M'\\cup \\{(x,y)\\}$\n\t\t      \\item $\\exists \\varnothing\\subsetneq S\\subsetneq X\\ |N_G(S)|=|S|$\\\\\n\t\t            Let $G_0=(V_0,E_0),G_1=(V_1,E_1)$ be two induced subgraph of $G$, where $V_0=S+N_G(S),V_1=(X\\setminus S)+ (Y\\setminus N_G(S))$.\n\t\t            \\begin{itemize}\n\t\t\t            \\item For $G_0$: $\\forall P\\subseteq S\\ N_{G_0}(P)=N_{G}(P)$ so $\\forall P\\subseteq S\\ |N_{G_0}(P)|=|N_{G}(P)|\\geq |P|$.\n\t\t\t            \\item For $G_1$: We claim that $\\forall Q\\subseteq (X\\setminus S)\\ |N_{G_1}(Q)|\\geq |Q|$.\\\\\n\t\t\t                  Otherwise, let $Q_0$ be a subset s.t. $|N_{G_1}(Q_0)|<|Q_0|$.\\\\\n\t\t\t                  Then $N_{G}(S\\cup Q_0)=N_{G}(S)\\cup N_{G}(Q_0)$, where $N_{G}(S)=N_{G_0}(S),\\ N_{G}(Q_0)\\subseteq (N_{G}(S)\\cup N_{G_1}(Q)),\\ N_{G_1(Q_0)}\\cap N_G(S)=\\varnothing$.\\\\\n\t\t\t                  which leads to $|N_{G}(S\\cup Q_0)|=|\\leq |N_G(S)|+|N_{G_0}(Q_0)| < |S|+|Q_0|$, however $|N_{G}(S\\cup Q_0)|\\geq |S\\cup Q_0|=|S|+|Q_0|$.\\\\\n\t\t\t                  Therefore in $G_1$, $\\forall Q\\subseteq (X\\setminus S)\\ |N_{G_1}(Q)|\\geq |Q|$.\\\\\n\t\t            \\end{itemize}\n\t\t            We can find a complete matching by merging the complete matching in $G_0$ and $G_1$.\n\t      \\end{itemize}\n\\end{enumerate}\n\n\\subsubsection{generalization}\n\nIn a bipartite graph $G=(X+Y,E)$\nLet $\\mathrm{def}_G(S)=|S|-|N_G(S)|$,\nthen the size of maximum matching in $G$ is $|X|-\\max_{\\varnothing\\subseteq S\\subseteq X}\\mathrm{def}_G(S)$\n\n\\newpage\n\\section{Havel-Hakimi algorithm}\n\n\\subsubsection{the theorem}\n\nGiven a list of non-negative integers $(d_1,d_2\\ldots d_n)$ where $d_1\\geq d_2\\geq d_3\\ldots d_n\\geq 0$.\\\\\nIs there a undirected simple\\footnote{no loops $(v,v)$, no dup-edges $k\\times (v,v)$} graph $G=(V,E)$ s.t. the degree sequence of $G$ is $(d_1,d_2\\ldots d_n)$?\n\n\\begin{minted}{python}\nfrom typing import List\ndef check(deg_seq: List[int]) -> bool:\n    if len(deg_seq)==0:\n        return True\n\n    head,seq = deg_seq[0],deg_seq[1:]\n    if len(seq)>=head:\n        for i in range(head):\n            seq[i]=seq[i]-1\n        seq = sorted(seq, reverse=True)\n        return seq[-1]>=0 and check(seq)\n    return False\n\\end{minted}\n\n\\subsubsection{proof}\n\n\\emph{TODO}\n\n\n\n\\newpage\n\\section{graph isomorphism invariant}\n\n\\subsection{degree sequence}\n\n$G\\cong H\\implies f(G)=H(G)$, where $f(G)=\\mathrm{multi-set}\\{\\deg_G(v)\\mid v\\in G\\}$.\\\\\nThis is a necessary but not sufficient condition, see the following example, where $H,G$ have the same degree sequence but are not isomorphic to each other.\n\n\\begin{minted}{C}\n//!/usr/bin/dot\n// in graphviz dot\ngraph G{\n\t1 -- 2\n\t2 -- 3\n\t3 -- 4\n\t4 -- 5\n\t2 -- x\n}\ngraph H{\n\t1 -- 2\n\t2 -- 3\n\t3 -- 4\n\t4 -- 5\n\t3 -- x\n}\n\\end{minted}\n\n\n\\newpage\n\\section{Lower bound of $\\max(\\omega(G),\\alpha(G))$}\n\n\\subsection{futher readings}\n\\href{https://en.wikipedia.org/wiki/Ramsey_theory}{wikipedia: Ramsey theory}\n\n\\subsection{statement}\n\n(Ramsey's Theorem) Every graph with $n$ vertices contains either a clique or an independent set with at least $\\frac{1}{2}\\log_2 n$ vertices.\\\\\n$\\omega(G)$: the clique number.\n$\\alpha(G)$: the independence number.\n\n\\subsection{proof}\n\n\\begin{enumerate}\n\t\\item $n=1$, hold\n\t\\item $n=2$, hold\n\t\\item Suppose that $n=1,2,3\\ldots k$, the statement is true\\\\\n\t      For $n=k+1$, select a arbitary vertex $u$.\n\t      Let $A=\\{v\\mid \\{u,v\\}\\in E,v\\neq u\\},\\, B=\\{v\\mid \\{u,v\\}\\not\\in E,v\\neq u\\}$\n\t      \\begin{itemize}\n\t\t      \\item $A$, there exists a clique $C$ of at least $\\frac{1}{2}\\log_2 |A|$ vertices.\n\t\t            $C+\\{u\\}$ is still a clique.\n\t\t      \\item $B$, there exists a independent set $I$ of at least $\\frac{1}{2}\\log_2 |B|$ vertices.\n\t\t            $I+\\{u\\}$ is still an independent set.\n\t      \\end{itemize}\n\t      Therefore, we can find either a clique or an independent set consisting of at least $1+\\frac{1}{2}\\max\\left(\\log_2 |A|+\\log_2 |B|\\right)$\\\\\n\t      $|A+B|=|A|+|B|=n-1=k\\implies \\max(|A|,|B|)\\geq \\frac{1}{2}k\\implies \\max\\left(\\log_2 |A|,\\log_2 |B|\\right)\\geq -1+\\log_2 k$\\\\\n\t      Thus $\\max(\\omega(G),\\alpha(G))\\geq 1+\\left(-1+\\log_2 k\\right)=\\log_2 k\\geq \\frac{1}{2}\\log_2 n$\n\\end{enumerate}\n\n\n\\newpage\n\\section{Sufficient conditions for existence of a hamilton circuit }\n\n\\begin{itemize}\n\t\\item Dirac's Theorem:\n\t      A simple graph $G=(V,E)$ s.t. $|V|\\geq 3$ and $\\forall v\\in V\\ \\deg(v)\\geq \\frac{|V|}{2}$ has a Hamilton circuit.\n\t\\item Ore's Theorem:\n\t      A simple graph $G=(V,E)$ s.t. $|V|\\geq 3$ and $\\forall \\{u,v\\}\\left( \\{u,v\\}\\not\\in E\\rightarrow \\deg(u)+\\deg(v)\\geq |V|\\right)$\n\\end{itemize}\n\n\\subsection{proof}\n\n\\newpage\n\\section{Kuratowski's Theorem: the equivalent condition of planar graph}\n\n\n\\subsection{statement}\n\n\\begin{itemize}\n\t\\item \\emph{elementary subdivision (expansion)}: Let $G=(V,E)$ be a undirected graph.\\\\\n\t      Delete an edge $\\{u,v\\}$ and add a vertex $w$, two edges $\\{u,w\\},\\{w,v\\}$.\\\\\n\t      (adding a new vertex in the middle of an edge)\n\t\\item \\emph{subdivision (expansion)}: subdivision of $G$: graphs that can be obtained by performing a series of elementary subdivision on $G$.\n\t\\item \\emph{smoothing}: the reverse process of subdivision (or expansion).\n\t\\item \\emph{homeomorphic}: Two graphs $G,H$ are call homeomorphic to each other\n\t      if a subdivision of $G$ is isomorphic to $H$\n\t      or a subdivision of $H$ is isomorphic to $G$.\n\t\\item \\emph{theorem} if $H,G$ are homeomorphic graphs then $H$ is an planar graphs iff $G$ is planar.\n\t\\item \\emph{Kuratowski's Theorem}: A graph $G$ is planar iff it does not have a subgraph that is homeomorphic to $K_{3,3}$ or $K_5$.\n\\end{itemize}\n\n\n\\newpage\n\\section{coloring planar graphs}\n\n\\emph{the graphs discussed in this section should be simple graphs (no self-loops nor multi-edges)}\n\n\\subsection{lemmans}\n\n\\begin{itemize}\n\t\\item A graph is planar iff its dual graph is planar.\n\t\\item \\emph{Euler's formula for (connected) planar graph}: $V-E+R=2$,\n\t      where $V,E,R$ be the number of vertices, the number of edges, the number of regions.\n\t\\item \\emph{degree} Define the degree of a vertex and a region,\n\t      $\\deg(v)=\\left|\\{e\\in E\\mid e=\\{u,v\\}\\}\\right|$\n\t      and\n\t      $\\deg(r)=\\left|\\{e\\in E\\mid \\text{$e$ is on the boundary of $r$}\\}\\right|$\n\t\\item \\emph{hand-shaking lemma}: For any undirected graph $G=(V,E)$, we have $2|E|=\\sum_{v\\in V}\\deg(v)$\\\\\n\t      Apply it on the dual graph of a planar graph to get the practical property: $2|E|=\\sum_{r\\in \\text{regions}}\\deg(r)$\n\t\\item \\emph{upper bound of edges in planar graph}: For a connected planar graph, if every region $r_i$ has $\\deg(r_i)\\geq d$,\\\\\n\t      then $2E=\\sum_{r\\in \\text{region}}\\deg(r)\\geq dR=d(2+E-V)$,\n\t      thus $E\\leq \\frac{d}{d-2}(V-2)$\\\\\n\t      helpful collaries\n\t      \\begin{itemize}\n\t\t      \\item $V\\geq 3$, planar, connected $\\Rightarrow$ $E\\leq 3V-6$\n\t\t      \\item $V\\geq 3$, planar, connected, no 3-cycle $\\Rightarrow$ $E\\leq 2V-4$\n\t\t      \\item \\emph{5 is an upper bound of $\\delta$}: Every planar graph has a vertex of degree at most $5$\n\t      \\end{itemize}\n\\end{itemize}\n\n\\subsection{The Six coloring theorem}\n\nInduction, find the vertex $u$ with the least degree (by previous lemma $\\deg(u)\\leq 5$), assign a color that differs from all its neighbors' colors to $u$.\n\n\\subsection{The Four coloring theorem}\n\n\n\\subsection{The Five coloring theorem}\n\n\\begin{enumerate}\n\t\\item $V\\leq 5$, hold.\n\t\\item Suppose that property is hold for $V=1,2,3\\ldots k$\n\t\\item For $V=k+1$, find the vertex with the least degree denoted as $u$, find a $5$-coloring of $G-u$\\\\\n\t      WLOG, let $\\deg(u)=5$, and the five neighbors are colorized with $A,B,C,D,E$.\\\\\n\t      Denote $v_1,v_2,v_2,v_4,v_5$ the neighbors of $v$ \\emph{in clockwise order}\\footnote{we would partition the plane with the edges $\\{u,v_1\\},\\{u,v_2\\},\\{u,v_3\\},\\{u,v_4\\},\\{u,v_5\\}$}\\\\\n\t      \\begin{itemize}\n\t\t      \\item If there is a path $P$ from $v_1$ to $v_3$ such that the vertices on the path have either color $A$ or color $C$.\\\\\n\t\t            Consider the circuit $u\\to v_1\\to P\\to v_3\\to u$, it split the plane into two region (namely, inner and outer part) where $v_2$ is inside and $v_4,v_5$ are outside.\\\\\n\t\t            Perform the re-coloring opertion $(A,B,C,D,E)\\to (A,D,C,B,E)$ inside the circle.\\\\\n\t\t            This is still a valid $5$-coloring of $G-u$ and we can now assign color $B$ to $u$ obtaining a $5$-coloring of $G$.\n\t\t      \\item $v_1,v_3$ are not connected only using the vertices of color $A$ or $C$.\\\\\n\t\t            Take the subgraph $H$ induced by all vertices of color $A$ and $C$, $v_1,v_3$ are in different connected component. Perform re-coloring opertion $(A,C)\\to (C,A)$ in the connected component of $H$ that contains $v_1$\\\\\n\t\t            This is still a valid $5$-coloring of $G-u$ and we can now assign color $A$ to $u$ obtaining a $5$-coloring of $G$.\n\t      \\end{itemize}\n\\end{enumerate}\n\n\\newpage\n\\subsection*{illustration}\n\\includegraphics{images/ch5-five-coloring-p1.png}\n\\includegraphics{images/ch5-five-coloring-p2.png}\n\n\\newpage\n\\section{Number of centroid/center s in a (unrooted) tree}\n\n\\newcommand{\\ECC}{\\mathrm{ECC}}\n\\newcommand{\\V}{\\mathrm{Vertex}}\n\\newcommand{\\N}{\\mathrm{Neighbor}}\n\\newcommand{\\dis}{\\mathrm{dis}}\n\\newcommand{\\subtree}{\\mathrm{subtree}}\n\\newcommand{\\height}{\\mathrm{height}}\n\n\\subsection{center of a tree}\n\n\nThe eccentricity of a vertex in an unrooted tree is the length of the longest simple path beginning at this vertex.\nA vertex is called a center if no vertex in the tree has smaller eccentricity than this vertex.\\\\\nLet $\\ECC{u}=\\max_{v\\in \\V{T}}\\dis{u}{v}$, the vertices with maximum ECC is called centers.\n\n\\subsection{counting centers}\nonly two cases\n\\begin{itemize}\n\t\\item a unique center.\n\t\\item two adjacent centers.\n\\end{itemize}\n\nSuppose that $c\\in \\V(T)$ is a center of $T$.\nMake $c$ the root of $T$ to obtain a rooted tree $T'$.\\\\\nLet $\\N(c)=\\{u_1,u_2\\ldots u_k\\}$\ns.t. $\\height (u_1)=H_1\\geq \\height (u_2)=H_2\\cdots \\height (u_k)=H_k$,\nthen $\\ECC_T(u)=H_1+1$\\\\\nDenote the leaf with maximum level in $\\subtree(u_i)$ using $L_i$.\n\n\\begin{enumerate}\n\t\\item $H_1=H_2\\geq H_3\\geq H_4\\cdots H_k$\\\\\n\t      $c$ is the unique center of $T$\n\t      \\begin{itemize}\n\t\t      \\item Centers in $\\subtree(u_1)$ or $\\subtree(u_2)$ do not exist.\\\\\n\t\t            Consider the path $c'\\to c\\to u_2\\to L_2$,\n\t\t            we have $\\ECC(c')\\geq 1+1+H_2=2+H_1>\\ECC(u)$.\n\t\t      \\item Centers in $\\subtree(u_3)\\ldots \\subtree(u_k)$  do not exist.\\\\\n\t\t            The path $c'\\to u_i\\to c\\to u_1\\to L_1$,\n\t\t            we have $\\ECC(c')\\geq 1+1+H_1> \\ECC(u)$.\n\t      \\end{itemize}\n\t\\item $H_1-1=H_2\\geq H_3\\geq H_4\\cdots H_k$\\\\\n\t      $c,u_1$ are the two adjacent centers of $T$.\n\t\t\t\tThe longest simple path from $u_1$ is $u_1\\to c\\to u_2\\to L_2$, $\\ECC(u_1)=2+H_2=H_1+1=\\ECC(c)$\n\t      \\begin{itemize}\n\t\t      \\item Centers in $\\subtree(u_1)-\\{u_1\\}$ do not exist.\\\\\n\t\t            path $c'\\to u_1\\to c\\to u_2\\to L_2$,\n\t\t\t\t\t\t\t\twe have $\\ECC(c')\\geq 2+1+H_2=H_1+2>\\ECC(c)$\n\t\t      \\item Centers in $\\subtree(u_2)\\ldots \\subtree(u_k)$  do not exist.\\\\\n\t\t            path $c'\\to u_k\\to c\\to u_1\\to L_1$,\n\t\t\t\t\t\t\t\twe have $\\ECC(c')\\geq 2+1+H_1>\\ECC(c)$\n\t      \\end{itemize}\n\t\\item $H_1-2=H_2\\geq H_3\\geq H_4\\cdots H_k$\\\\\n\t      This is impossible.\n\t      Otherwise $\\ECC(u_1)=\\max(H_1,H_2+1)=H_1<H_1+1 =\\ECC(c)$,\n\t      $c$ can not be a center of $T$.\n\t      Contradiction.\n\n\\end{enumerate}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "162a6df069e7cfb4082591f4d7bfbfcea7f39878", "size": 12788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course_note/ConcreteMathematics/ch5-graphs.tex", "max_stars_repo_name": "hehelego/WhyNotMarkdown", "max_stars_repo_head_hexsha": "21a8cdb5f11de893ec8be31dd1a2d4b0eb782134", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-02-21T08:39:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-23T08:19:12.000Z", "max_issues_repo_path": "course_note/ConcreteMathematics/ch5-graphs.tex", "max_issues_repo_name": "hehelego/WhyNotMarkdown", "max_issues_repo_head_hexsha": "21a8cdb5f11de893ec8be31dd1a2d4b0eb782134", "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": "course_note/ConcreteMathematics/ch5-graphs.tex", "max_forks_repo_name": "hehelego/WhyNotMarkdown", "max_forks_repo_head_hexsha": "21a8cdb5f11de893ec8be31dd1a2d4b0eb782134", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-08-03T12:18:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-10T00:18:18.000Z", "avg_line_length": 41.5194805195, "max_line_length": 231, "alphanum_fraction": 0.6292618079, "num_tokens": 4654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.859663754105328, "lm_q1q2_score": 0.6204564742258093}}
{"text": "\\documentclass{article}\n\n\\usepackage{amssymb}\n\\usepackage{algorithm}\n\\usepackage[noend]{algpseudocode}\n\n\\usepackage{biblatex}\n\\addbibresource{bibliography.bib}\n\n\\begin{document}\n\n\\section{Background}\n\nGiven data $(y_i, x_i, z_i), i = 1, \\dots, n$ with outcome $y_i \\in \\mathbb{R}$, covariates $x_i \\in \\mathbb{R}^p$ and effect modifiers $z_i \\in \\mathbb{R}^q$ one assumes the varying coefficient model\n%\n\\begin{equation}\ny_i = \\sum_{j=1}^p x_{ij} \\beta_j(z_i) + \\varepsilon_i = x_i^T \\beta(z_i) + \\varepsilon_i,\n\\end{equation}\n%\n\\cite{hastie1993varying}. The coefficients $\\beta(\\cdot) = (\\beta_1(\\cdot), \\dots, \\beta_p(\\cdot))^T$ determine a (rather simple) functional, relationship between outcome $y$ and (likely low dimensional) covariate $x$. The coefficients themselves are considered to be (potentially complex) functions of the (potentially high dimensional) effect modifier $z$.\\\\\nEach varying coefficient mapping $\\beta_j(\\cdot)$ is estimated using an ensemble of gradient\nboosted decision trees. This is done by iteratively minimizing a loss function\n%\n\\begin{equation}\n    L(y, \\beta) = \\sum_{i=1}^n l(y_i, x_i^T\\beta(z_i)).\n\\end{equation}\n%\nThe generic gradient boosting algorithm described in \\cite{friedman2001greedy} is adapted for the varying coefficient scenario. The resulting procedure is sketched in Algorithm~\\ref{alg:vcboost} below. A similar algorithm has already been described by \\cite{zhou2019tree}.\n%\n\\begin{algorithm}[h]\n\\caption{VCBoost}\n\\label{alg:vcboost}\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\beta_j^{(0)}(z) = 0$, $j = 1, \\dots, p$\n\t\t\\For{$m = 1, \\dots$, maxiter}\t\n\t\t\t\\For{$j = 1, \\dots, p$}\n\t\t\t\t\\State $\\tilde{y_i} = - \\frac{\\partial l(y_i, x_i^T\\beta^{(m-1)}(z_i))}{\\partial \\beta_j^{(m-1)}(z_i)}$ \\Comment{negative gradient wrt. $\\beta_j$}\n\t\t\t\t\\State $h = $ regression tree fit on $\\{\\tilde{y_i}, z_i\\}_{i=1, \\dots, n}$\n\t\t\t\t\\State $\\rho = $ argmin$_{\\rho} \\left[ \\sum_{i=1}^n l (y, x_i^T\\beta^{(m-1)}(z_i) + \\rho h(z_i) x_{ij}) \\right]$ \\Comment{line search}\n\t\t\t\t\\State $\\beta_j^{(m)}(\\cdot) = \\beta_j^{(m-1)}(\\cdot) + \\rho h(\\cdot)$\n\t\t\t\\EndFor\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{algorithm}\\\\\n%\nThe pseudoresponses $\\tilde{y_i}$ in Line 4 are obtained by noting that\n%\n\\begin{equation}\n\\tilde{y_i} = - \\frac{\\partial l(y_i, x_i^T\\beta^{(m-1)}(z_i))}{\\partial \\beta_j^{(m-1)}(z_i)} = - \\frac{\\partial l(y_i, x_i^T\\beta^{(m-1)}(z_i))}{\\partial x_i^T\\beta^{(m-1)}(z_i)}x_{ij}\n\\end{equation}\n%\nand the derivative remaining on the right hand side is the usual gradient based on the previous fitted responses $x_i^T\\beta^{(m-1)}(z_i)$. Hence, this is easily determined for common loss functions. Also this part of the pseudo response is the same, regardless of the coordinate ($j = 1, \\dots, p$) currently handled in the inner loop. A variation of the algorithm only computes $\\frac{\\partial l(y_i, x_i^T\\beta^{(m-1)}(z_i))}{\\partial x_i^T\\beta^{(m-1)}(z_i)}$ once during the outer loop and then updates all coefficient estimates before recomputing.\\\\\nAlso the line search determining the step size $\\rho$ can be done globally, e.g. determining one $\\rho$ based on all observations $i = 1, \\dots n$ as shown above. Alternatively, the line search can be done separately for each leaf in the regression tree $h$ (see Eq. (18) in \\cite{friedman2001greedy}).\\\\\nAs usual one can also introduce a learning rate $ < 1$ to shrink the step size for the update in row 7 of the algorithm.\\\\\nFinally there would also be many hyper-parameters controlling the tree building process in line 5.\n\n\\subsection{Details for specific loss functions}\n...\n\n\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "a74a00314f22b796d2d06a96d9c87193830ecf9d", "size": 3595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "background/background.tex", "max_stars_repo_name": "sepauly/vcboost", "max_stars_repo_head_hexsha": "7005bf158c1a4673a50ee8c3f04b90b3dcee28b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "background/background.tex", "max_issues_repo_name": "sepauly/vcboost", "max_issues_repo_head_hexsha": "7005bf158c1a4673a50ee8c3f04b90b3dcee28b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "background/background.tex", "max_forks_repo_name": "sepauly/vcboost", "max_forks_repo_head_hexsha": "7005bf158c1a4673a50ee8c3f04b90b3dcee28b2", "max_forks_repo_licenses": ["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.9838709677, "max_line_length": 555, "alphanum_fraction": 0.7073713491, "num_tokens": 1182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6204304797640524}}
{"text": "\\graphicspath{{Pics/}}\n\n\\newpage\n\\section{Conjugates}\n\n\n\\subsection{Isogonal Conjugate}\n\n\\begin{minipage}{.5\\linewidth}\n    \\theo{https://artofproblemsolving.com/community/c2771h1181729}\n    {Isogonal Line Lemma}{\n        Let $AP,AQ$ are isogonal lines with respect to $\\angle BAC$. Let $BP \\cap\n        CQ = F$ and $BQ \\cap CP = E$. Then $AE,AF$ are isogonal lines with respect\n        to $\\angle BAC$.\n    }\n\n    \\proof{\n        \\[\\begin{aligned}\n            A(B, F; P, X) &= (B, F; P, X) = C(B, Q; E, X) \\\\\n                          &= (B, Q; E, X) = (X, E; Q, B) \n        \\end{aligned}\\]\n        So if we define a projective transformation that swaps isogonal lines wrt $\n        \\angle BAC $, we see $ AE, AF $ are conjugates of each other.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.47\\linewidth}\n    \\figdf{}{Isogonal_Lemma}{}\n\\end{minipage}\n\n\n\n\n\n\\prob{}\n{India Postals 2015 Set 2}{E}{\n    Let $ABCD$ be a convex quadrilateral. In the triangle $ABC$ let $I$ and\n    $J$ be the incenter and the excenter opposite the vertex $A$,\n    respectively. In the triangle $ACD$ let $K$ and $L$ be the incenter and\n    the excenter opposite the vertex $A$, respectively. Show that the lines\n    $IL$ and $JK$, and the bisector of the angle $BCD$ are concurrent.\n}\n\n\\solu{\n    Using \\autoref{theorem:Isogonal Line Lemma}\n}\n\n\n\\lem{}{ \n    Let $ \\w_1, \\w_2 $ be two circles such that $ \\w_1 $ passes through $\n    A, B $ and is tangent to $ AC $ at $ A $. $ \\w_2 $ is defined similarly by\n    swapping $ B $ with $ C $. $ \\w_1\\cap\\w_2 = X $.\n\n    Let $ \\gamma_1, \\gamma_2 $ be two circles such that $ \\gamma_1 $ passes\n    through $ A, B $ and is tangent to $ BC $ at $ B $. $ \\gamma_2 $ is\n    defined similarly by swapping $ B $ with $ C $. $ \\gamma_1\\cap\\gamma_2 = Y$.\n\n    Then $ X, Y $ are isogonal conjugates wrt $ \\triangle ABC $.\n}\t\n\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\lem{Isogonality in quadrilateral}{\n        For a point $ X $, its isogonal conjugate wrt a quadrilateral $ ABCD $\n        exists iff \\[ \\measuredangle BXA + \\measuredangle DXC = 180^\\circ\\]\n    }\n    \\solu{\n        Draw the cirles, look for similarity.\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.49\\linewidth}\n\\figdf{1}{isogonal_in_quad}{Isogonality in quadrilateral}\n\\end{minipage}\n\n\n\n\n\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\lem{Ratio}{\n        Given a $ \\triangle ABC $ with isogonal conjugate $ P, $ $ Q. $ Let $ AP,\n        $ $ AQ $ cut the circumcircle of $ \\triangle ABC $ again at $ U, $ $ V, $\n        respectively and let $ D $ $ \\equiv $ $ AP $ $ \\cap $ $ BC. $ Then\n        \\[\\frac{AQ}{QV} = \\frac{PD}{DU}\\]\n    }\n    \\begin{prooof}\n        By using cross ratio:\n        \\[\\begin{aligned}\n            (A, F; Q, V) &= C(A, F; Q, V)\\\\\n                         &=C(D, A; P, V*) =(D, A; P, V*)\\\\\n                         &=(A, D; V*, P)\n        \\end{aligned}\\]\n    \\end{prooof}\n\\end{minipage}\\hfill%\n\\begin{minipage}{.45\\linewidth}\n    \\figdf{.9}{AoPS_c284651h2018537_cute_problem_on_radical_axis_1}{}\n\\end{minipage}\n\n\n\n\n\n\\newpage\\subsubsection{Symmedians}\n\n\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\den{Symmedians}{\n        In $ \\triangle ABC $, let $ T_a, T_b, T_c $ be the meet points of the\n        tangents at $ A, B, C $. Let $ \\triangle N_aN_bN_c $ be the cevian\n        triangle of $ AT_a, BT_b, CT_c $. Let $ S $ be the symmedian point of $\n        \\triangle ABC $. Let $ M_a, M_b, M_c $ be the midpoints of $ BC, CA, AB $.\n    }\n\n    \\lem{Most Important Symmedian Property}{\n        Let the circles tangent to $ AC, AB $ at $ A $ and passes through $ B, C $\n        respectively meet at $ T' $ for the second time. Let $ AT_a\\cap \\odot ABC\n        = A' $. Let the tangents to $ \\odot ABC $ at $ A, A' $ meet $ BC $ at $ T\n        $. Prove that, $ A, T', T_a, \\text{ and } T, T', O $ are collinear.\n    }\n\n\\end{minipage}\\hfill%\n\\begin{minipage}{.47\\linewidth}\n    \\figdf{}{Symmedian_Lemma_1}{$ T' $ is quite special!}\n\\end{minipage}\n\n\\vspace{2em}\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\prob{https://artofproblemsolving.com/community/c5h202907p1116181}\n    {USAMO 2008 P2}{E}{\n        Let $ ABC$ be an acute, scalene triangle, and let $ M$, $ N$, and $ P$\n        be the midpoints of $ {BC}$, $ {CA}$, and $ {AB}$, respectively. Let\n        the perpendicular bisectors of $ {AB}$ and $ {AC}$ intersect ray $ AM$\n        in points $ D$ and $ E$ respectively, and let lines $ BD$ and $ CE$\n        intersect in point $ F$, inside of triangle $ ABC$. Prove that points\n        $ A$, $ N$, $ F$, and $ P$ all lie on one circle.\n    }\n\n    \\begin{solution}[Phantom Point]\n        First assume $ F\\in BD, \\text{ and } F=T' $ (Where $ T' $ comes from\n        \\autoref{lemma:Most Important Symmedian Property}, and prove that $\n        F\\in CE $.)\n    \\end{solution}\n\\end{minipage}\\hfill%\n\\begin{minipage}{.47\\linewidth}\n    \\figdf{}{USAMO_2008_P2}{USAMO 2008 P2}\n\\end{minipage}\n\n\\vspace{1em}\n\n\\begin{solution}[Isogonal Conjugate]\n    Construct the isogonal conjugate of $ F $, which is the intersection of the circles touching $ BC $ and passing through $ A, B $ and $ A, C $.\n\\end{solution}\n\\solu{Using \\autoref{theorem:Isogonal Line Lemma} by taking the reflections of $ B , C $ over $ D, F $}\n\n\n\\prob{https://artofproblemsolving.com/community/c6h1095220p4902494}\n{IRAN TST 2015 Day 3, P3}{M}{\n    $AH$ is the altitude of triangle $ABC$ and $H^\\prime$ is the reflection of $H$\n    trough the midpoint of $BC$. If the tangent lines to the circumcircle of $ABC$\n    at $B$ and $C$, intersect each other at $X$ and the perpendicular line to\n    $XH^\\prime$ at $H^\\prime$, intersects $AB$ and $AC$ at $Y$ and $Z$\n    respectively, prove that $\\angle ZXC=\\angle YXB$.\n}\n\n\n\\begin{minipage}{.5\\linewidth}\n    \\prob{https://web.facebook.com/photo.php?fbid=539157073197109}\n    {Two Symmedian Points}{E}{\n        Let $E, F$ be the feet of $B, C$-altitudes. Let $K, K_A$ be the symmedian\n        points of $\\triangle ABC, \\triangle AEF$. Prove that $KK_A\\perp BC,\n        KK_A\\cap BC = P$ and $KK_A=KP$\n    }\n\\end{minipage}\\hfill%\n\\begin{minipage}{.45\\linewidth}\n    \\figdf{.8}{Two_Symmedian_Points}{$KK_A\\perp BC$}\n\\end{minipage}\n\n\n\n\n\n\n\n\n\n\\newpage\\subsection{Isotonic Conjugate}\n\n\\theo{}{Isotonic Lemma}{Let $ M $ be the midpoint of $ BC $, and $ PQ $ such that $ Q $ is the reflection of $ P $ on $ M $. Two points $ Q, R $ on $ AP, AQ $, $ BQ\\cap CR = X,\\ BR\\cap CQ = Y $. Then $ AX, AY $ are isotonic wrt $ BC $.\n    \\fig{1}{Isotonic_Lemma}{}\n}\\label{isotonic_lemma}\n\n\n\n\\prob{https://artofproblemsolving.com/community/c6h626330p3756450}{IGO 2014 S5}{M}{Two points $P$ and $Q$ lying on side $BC$ of triangle $ABC$ and their distance from the midpoint of $BC$ are equal.The perpendiculars from $P$ and $Q$ to $BC$ intersect $AC$ and $AB$ at $E$ and $F$,respectively.$M$ is point of intersection $PF$ and $EQ$.If $H_1$ and $H_2$ be the orthocenters of triangles $BFP$ and $CEQ$, respectively, prove that $ AM\\perp H_1H_2 $.}\n\n\\solu{We first show that the slope of $ H_1H_2 $ is fixed, and then show that $ AM $ is fixed where we use \\hrf{isotonic_lemma}{isotonic lemma}, and finally show that these two lines are perpendicular.}\n\n\n\n\\newpage\\subsection{Reflection}\n\n\\lem{Homothety and Reflection}{Let two oppositely oriented congruent triangles be $ \\triangle ABC, \\triangle DEF $. Prove that the midpoints of $ AD, BE, CF $ are collinear. \n    \\fig{.7}{homothety+reflection}{Oppositely oriented congruent triangles}\n}\n\n\\prob{}{Autumn Tournament, 2012}{E}{Let two oppositely oriented equilateral triangles be $ \\triangle ABC, \\triangle DEF $. What is the least possible value of $ \\max{\\left (AD, BE, CF\\right )} $?}\n", "meta": {"hexsha": "3a97d73d4d6f8959f38010be2afdeecc35dda91f", "size": 7592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geo/sec4_conjugates.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": "geo/sec4_conjugates.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": "geo/sec4_conjugates.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": 35.6431924883, "max_line_length": 451, "alphanum_fraction": 0.6224973656, "num_tokens": 2505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.620430477898262}}
{"text": "\\chapter{Literature Review}\n\\label{ch:review}\n\\vspace{2em}\n\nP. Erdős and  A. Rényi started the study of Random Graphs \\cite{erds:rand} in 1960, and in the same paper also asked the question about the existence of a Hamiltonian path in a random undirected graph. \nThis problem has been extensively studied over the years with a recent survey by Frieze \\cite{frieze:2019survey} giving a very good introduction to all the different directions that this study of Hamiltonian Cycles in Random graphs has taken.\n\nPósa\\cite{posa:ham} and Komlós$\\&$ E. Szemerédi\\cite{komlos:undir} made significant advances in the undirected version of the problem, showing that in $G_{n, m}$, $m \\in \\bigO(n\\log n)$ is sufficient for a graph to be Hamiltonian.\n\nBollobas \\cite{boll:ham} improved this result by showing that\n\\[ \\lim_{n \\rightarrow \\infty} Pr( G_{m^*} \\text{is hamiltonian}) = 1 \\]\nwhere $G_m$ is defined as the graph obtained by taking the first $m$ edges from the list $E = \\{ e_1, e_2, \\cdots e_{\\frac{n(n-1)}{2}} \\}$ obtained by permuting the edges of a complete graph on $n$ vertices, and $m^* = min\\{m : \\delta(G_m) \\ge 2\\}$\n\nAn analogous result for directed graphs was given by Frieze \\cite{frieze:dham} while also giving a $\\bigO(n^{1.5})$ algorithm(DHAM)  showing that \n\\[ \\lim_{n \\rightarrow \\infty} Pr( \\text{DHAM finds a hamilton cycle in } D_{m^*} ) = 1 \\]\nwhere $D_m$ is the directed analogue of $G_m$ defined above, and $m^* = min\\{m : \\delta^+(D_m) \\ge 1, \\delta^-(D_m) \\ge 1\\}$\n\nThe algorithm is divided into 3 phases, the first obtains a permutation digraph from the given graph (which is obtaining a permutation on the set of vertices such that they form $\\bigO(\\log n)$ cycles). The second merges some of the these cycles to get an asymptotically larger cycle. And the final phase merges all cycles to obtain the desired Hamiltonian cycle.\n\nA somewhat similar 3-phase method has been used to obtain existential results on more classes of graphs (cite a few papers here and elaborate). These results do not usually explicitly give an algorithm, or try to bound the runtime of the same. In our thesis, we attempt to use the above 3-phase algorithm, to experimentally see, if the DHAM algorithm also runs successfully with polynomial growth on these classes of graphs.", "meta": {"hexsha": "09babb99f8ae6e1ad2035c87bf111e2ec47baf0e", "size": 2277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapters/ch-review.tex", "max_stars_repo_name": "LaughingBudda/hachikuji", "max_stars_repo_head_hexsha": "0d65ecec12dd843dfb7e3828ac3b5c3824ce6901", "max_stars_repo_licenses": ["MIT"], "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/chapters/ch-review.tex", "max_issues_repo_name": "LaughingBudda/hachikuji", "max_issues_repo_head_hexsha": "0d65ecec12dd843dfb7e3828ac3b5c3824ce6901", "max_issues_repo_licenses": ["MIT"], "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/chapters/ch-review.tex", "max_forks_repo_name": "LaughingBudda/hachikuji", "max_forks_repo_head_hexsha": "0d65ecec12dd843dfb7e3828ac3b5c3824ce6901", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 113.85, "max_line_length": 424, "alphanum_fraction": 0.7496706192, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6204304677969008}}
{"text": "% \\documentclass[draft,11pt]{article}\n%\\documentclass[11pt]{article}\n\n\\subsection{Eigenvalue Bounds Beyond Test Vectors}\n\nIn the previous sections, we first saw a complete characterization of the\neigenvalues and eigenvectors of the unit weight complete graph on $n$\nvertices, $K_n$. Namely, $\\LL_{K_N} = n\\II - \\vecone \\vecone^\\trp$, and\nthis means that \\emph{every} vector $\\yy \\perp \\vecone$ is an\neigenvector of eigenvalue $n$.\n\nWe then looked at eigenvalues of $P_n$, the unit weight path on $n$\nvertices, and we showed using \\emph{test vector} bounds that\n\n\\begin{equation}\n  \\label{eq:testvectorbounds}\n\\lambda_2(\\LL_{P_n}) \\leq \\frac{12}{n^2} \\text{ and } 1 \\leq\n\\lambda_n(\\LL_{P_n}).\n\\end{equation}\n%\nIdeally we would like to prove an almost matching upper bound on\n$\\lambda_2$ and an almost matching lower bound on $\\lambda_n$, but it\nis not clear how to get that from the Courant-Fischer theorem.\n\nTo get there, we start we need to introduce some more tools.\n% The Courant-Fischer theorem is not as helpful when we want to prove lower bounds on $\\lambda_2$. To prove lower bounds, we need the form with a maximum on the outside, which gives\n% \\begin{align*}\n% \\lambda_2 \\geq \\max_{S : \\dim{S} = n - 1 } \\min_{ \\vv\\in S } \\frac{ \\vv^\\top \\LL \\vv}{ \\vv^\\top \\vv}\n% \\end{align*}\n% This is not too helpful, as it is difficult to prove lower bounds on\n% \\begin{align*}\n% \\min_{ \\vv\\in S } \\frac{ \\vv^\\top \\LL \\vv}{ \\vv^\\top \\vv}\n% \\end{align*}\n% over a space $S$ of large dimension. We need another technique.\n\n\\subsection{The Loewner Order, aka. the Positive Semi-Definite Order}\nWe'll now introduce an ordering on symmetric matrices called the\n\\emph{Loewner order}, which I also like to just call the positive\nsemi-definite order.\nAs we will see in a moment, it is a partial order on symmetric matrices, we denote\nit by ``$\\preceq$''.\nFor conveniece, we allow ourselves to both write  $\\AA \\preceq \\BB$\nand equivalently $\\BB \\succeq \\AA$.\n\nFor a symmetric matrix $\\AA \\in \\R^{n \\times n}$ we define that\n\\begin{align*}\n\\AA \\succeq \\matzero\n\\end{align*}\nif and only if $\\AA$ is positive semi-definite.\n\nMore generally, when we have two symmetric matrices $\\AA, \\BB \\in\n\\R^{n \\times n}$, we will write\n\n\\begin{equation}\n  \\label{eq:psdorder}\n  \\AA \\preceq \\BB\n  \\text{ if and only if for all } \\xx \\in \\R^n\n  \\text{ we have } \\xx^{\\trp} \\AA \\xx \\leq \\xx^{\\trp} \\BB\n  \\xx\n\\end{equation}\n\nThis is a partial order, because it satisfies the three requirements\nof\n\\begin{enumerate}\n\\item Reflexivity: $\\AA \\preceq \\AA$.\n\\item Anti-symmetry:\n  $\\AA \\preceq \\BB$ and $\\BB \\preceq \\AA$\n  implies $\\AA = \\BB$\n\\item Transitivity:    $\\AA \\preceq \\BB$ and $\\BB \\preceq \\CC$\n  implies $\\AA \\preceq \\CC$\n\\end{enumerate}\nCheck for yourself that these properties hold!\n\nThe PSD order has other very useful properties:\n$\\AA \\preceq \\BB$ implies $\\AA + \\CC \\preceq \\BB + \\CC$ for any\nsymmetric matrix $\\CC$. Convince yourself of this too!\n\nAnd, combining this observation with transitivity, we can see that\n$\\AA \\preceq \\BB$  and $\\CC\\preceq \\DD$\nimplies ${\\AA + \\CC \\preceq \\BB + \\DD}$.\n\nHere is another useful property: If $\\matzero \\preceq \\AA$ then for all $\\alpha \\geq 1$\n\\[\n \\frac{1}{\\alpha} \\AA \\preceq \\AA \\preceq \\alpha \\AA.\n\\]\n\nHere is another one:\n\\begin{claim}\n  \\label{clm:eigorderfrompsdorder}\nIf $\\AA \\preceq \\BB$, then for all $i$\n\\[\n\\lambda_i(\\AA) \\leq \\lambda_i(\\BB).\n\\]\n\\end{claim}\n\\begin{proof}\n  We can prove this Claim by applying the subspace version of the\n  Courant-Fischer theorem.\n\\[\n\\lambda_i(\\AA) =\n\\min_{\n      \\substack{\n        \\mathrm{subspace~} W \\subseteq \\R^n\n        \\\\\n        \\dim{W} = i\n      }\n    }\n    \\max_{\n      \\xx \\in W, \\xx \\neq \\veczero\n    }\n    \\frac{\\xx^\\trp \\AA\\xx}{\\xx^\\trp\\xx}\n\\leq\n \\min_{\n      \\substack{\n        \\mathrm{subspace~} W \\subseteq \\R^n\n        \\\\\n        \\dim{W} = i\n      }\n    }\n    \\max_{\n      \\xx \\in W, \\xx \\neq \\veczero\n    }\n    \\frac{\\xx^\\trp \\BB\\xx}{\\xx^\\trp\\xx}\n= \\lambda_i(\\BB).\n\\]\n\\end{proof}\nNote that the converse of Clam~\\ref{clm:eigorderfrompsdorder} is very\nmuch false, for example the matrices\n$ \\AA =\n\\begin{pmatrix}\n  2 & 0 \\\\\n  0 & 1\n\\end{pmatrix}$\nand $\\BB = \\begin{pmatrix}\n  1 & 0 \\\\\n  0 & 2\n\\end{pmatrix}$ have equal eigenvalues, but both $\\AA \\not\\preceq \\BB$ and\n$\\BB \\not\\preceq \\AA$.\n\n\\begin{remark}\n  It's useful to get used to and remember some of the properties of the Loewner\n  order, but all the things we have established so far are almost\n  immediate from the basic characterization in\n  Equation~\\eqref{eq:psdorder}.\n  So, ideally, don't memorize all these facts, instead, try to see that\n  they are simple consequences of the definition.\n\\end{remark}\n\n\\subsection{Upper Bounding a Laplacian's $\\lambda_n$ Using Degrees}\nIn an earlier lecture, we observed that for any graph $G=(V,E,\\ww)$,\n$\\LL = \\DD - \\AA \\succeq \\matzero$.\nWe can see this from\n$\\xx^\\top (\\DD-\\AA) \\xx = \\sum_{ (u,v) \\in E } \\ww(u,v)\n( \\xx(u) - \\xx(v) )^2 \\geq 0$.\nSimilarly $\\DD + \\AA \\succeq \\matzero$. because\n$\\xx^\\top (\\DD+\\AA) \\xx = \\sum_{ (u,v) \\in E } \\ww(u,v)\n( \\xx(u) + \\xx(v) )^2 \\geq 0$.\nBut this means that $-\\AA \\preceq \\DD$ and hence $\\LL = \\DD-\\AA\n\\preceq 2\\DD$.\n\nSo, for the path graph $P_n$, we have\n$\\LL_{P_n} \\preceq \\DD-\\AA \\preceq 2\\DD \\preceq 4 \\II$.\nSo by Claim~\\ref{clm:eigorderfrompsdorder}\n\\begin{equation}\n  \\label{eq:pathlambdamaxub}\n\\lambda_n(\\LL_{P_n}) \\leq 4.\n\\end{equation}\nWe can see that our test vector-based lower bound on $\\lambda_n(\\LL_{P_n})$ from\nEquation~\\eqref{eq:testvectorbounds} is tight up\nto a factor 4.\n\nSince this type of argument works for any unit weight graph, it proves the following claim.\n\\begin{claim}\n  \\label{clm:lambdamaxfromeig}\n  For any unit weight graph $G$,\n  $\\lambda_{n}(\\LL_G) \\leq 2 \\max_{v\n    \\in V} \\mathop{degree}(v)$.\n\\end{claim}\nThis is tight on a graph consisting of a single edge.\n\n\\subsection{The Loewner Order and Laplacians of Graphs.}\nIt's sometimes convenient to overload the for the PSD order to also\napply to graphs. We will write\n\\begin{align*}\nG \\preceq H\n\\end{align*}\nif $\\LL_{G} \\preceq\n\\LL_H$.\n\nFor example, given two unit weight graphs\n$G = (V,E)$ and $H = (V,F)$, if $H = (V,F)$ is a subgraph of $G$,\nthen\n\\begin{align*}\n\\LL_H \\preceq \\LL_G.\n\\end{align*}\n\nWe can see this from the Laplacian quadratic form:\n\\begin{align*}\n\\xx^\\top \\LL_G \\xx = \\sum_{ (u,v) \\in E } \\ww(u,v) ( \\xx(u) - \\xx(v) )^2.\n\\end{align*}\nDropping edges will only decrease the value of the quadratic form. The\nsame is for decreasing the weights of edges.\nThe graph order notation is especially useful when we allow for\nscaling a graph by a constant, say $c > 0$,\n\\begin{align*}\nc \\cdot H \\preceq G\n\\end{align*}\nWhat is $c \\cdot H$? It is the same graph as $H$, but the weight of\nevery edge is multiplied by $c$.\nNow we can make statements like $\\frac{1}{2} H \\preceq G \\preceq 2 H$,\nwhich turn out to be useful notion of the two graphs approximating\neach other.\n\n% \\subsection{Dan}\n% I begin by recalling an extremely useful piece of notation that is used in the Optimization community. For a symmetric matrix $\\AA$, we write\n% \\begin{align*}\n% \\AA \\succeq 0\n% \\end{align*}\n% if $\\AA$ is positive semidefinite. That is, if all of the eigenvalues of $\\AA$ are nonnegative, which is equivalent to\n% \\begin{align*}\n% \\vv^\\top \\AA \\vv\\geq 0,\n% \\end{align*}\n% for all $\\vv$. We similarly write\n% \\begin{align*}\n% \\AA \\succeq {\\bf B}\n% \\end{align*}\n% if\n% \\begin{align*}\n% \\AA - {\\bf B} \\succeq 0\n% \\end{align*}\n% which is equivalent to\n% \\begin{align*}\n% \\vv^\\top \\AA \\vv\\geq \\vv^\\top {\\bf B} \\vv\n% \\end{align*}\n% for all $\\vv$.\n\n% The relation $\\preceq$ is an example of a partial order. It applies to some pairs of symmetric matrices, while others are incomparable. But, for all pairs to which it does apply, it acts like an order. For example, we have\n% \\begin{align*}\n% \\AA \\succeq {\\bf B}, \\mathrm{~and~} {\\bf B} \\succeq {\\bf C} \\mathrm{~implies~} \\AA \\succeq {\\bf C},\n% \\end{align*}\n% and\n% \\begin{align*}\n% \\AA \\succeq {\\bf B} \\mathrm{~implies~} \\AA + {\\bf C} \\succeq {\\bf B} + {\\bf C},\n% \\end{align*}\n% for symmetric matrices ${\\cal A}$, ${\\cal B}$ and ${\\cal C}$.\n\n% I find it convenient to overload this notation by defining it for graphs as well. Thus, I'll write\n% \\begin{align*}\n% G \\succeq H\n% \\end{align*}\n% if $\\LL_{G} \\succeq \\LL_H$.\n\n% For example, if $G = (V,E)$ is a graph and $H = (V,F)$ is a subgraph of $G$, then\n% \\begin{align*}\n% \\LL_G \\succeq \\LL_H.\n% \\end{align*}\n\n% To see this, recall the Laplacian quadratic form:\n% \\begin{align*}\n% \\xx^\\top \\LL_G \\xx = \\sum_{ (u,v) \\in E } w_{u,v} ( \\xx(u) - \\xx(v) )^2.\n% \\end{align*}\n% It is clear that dropping edges can only decrease the value of the quadratic form. The same holds for decreasing the weights of edges.\n\n% This notation is most powerful when we consider some multiple of a graph. Thus, I could write\n% \\begin{align*}\n% G \\succeq c \\cdot H, \\mathrm{~for~some~} c > 0.\n% \\end{align*}\n% What is $c \\cdot H$? It is the same graph as $H$, but the weight of every edge is multiplied by $c$.\n\n% Using the Courant-Fischer Theorem, we can prove\n% \\begin{lemma}\n% If $G$ and $H$ are graphs such that\n% \\begin{align*}\n%  G \\succeq c \\cdot H,\n% \\end{align*}\n% then\n% \\begin{align*}\n% \\lambda_k (G) \\geq c \\cdot \\lambda_k(H), \\mathrm{~for~all~} k.\n% \\end{align*}\n% \\end{lemma}\n% \\begin{proof}\n% The Courant-Fischer Theorem tells us that\n% \\begin{align*}\n% \\lambda_k (G)\n% = & ~ \\min_{ S \\subseteq \\R^n, \\dim{S} = k } \\max_{ \\xx \\in S }\n%  \\frac{ \\xx^\\top \\LL_G \\xx }{ \\xx^\\top \\xx } \\\\\n% \\geq & ~ c \\dot \\min_{ S \\subseteq \\R^n, \\dim{S} = k } \\max_{ \\xx \\in S } \\frac{ \\xx^\\top L_H \\xx }{ \\xx^\\top \\xx } \\\\\n% = & ~ c \\cdot \\lambda_k (H).\n% \\end{align*}\n% \\end{proof}\n\n% \\begin{corollary}\n% Let $G$ be a graph and let $H$ be obtained by either adding an edge to $G$ or increasing the weight of an edge in $G$. Then, for all $i$,\n% \\begin{align*}\n% \\lambda_i (G) \\leq \\lambda_i (H).\n% \\end{align*}\n% \\end{corollary}\n\n\n% \\subsection{Approximations of Graphs}\n% An idea that we will use in later lectures is that one graph approximations another if their Laplacian quadratic forms are similar. For example, we will say that $H$ is a $c$-approximation of $G$ if\n% \\begin{align*}\n% c \\cdot H \\succeq G \\succeq H /c.\n% \\end{align*}\n% Surprising approximations exist.\n\n% For example, expander graphs are very sparse approximations of the complete graph. For example, the following is known\n% \\begin{theorem}\n% For every $\\epsilon > 0$, there exists a $d > 0$ such that for all sufficiently large $n$ there is a $d$-regular graph $G_n$ that is $(1+\\epsilon)$-approximation of $K_n$.\n% \\end{theorem}\n\n% These graphs have many fewer edges than the complete graphs!\n% In a latter lecture we will also prove that every graph can be well-approximated by a sparse graph.\n\n\n\\subsection{The Path Inequality}\nNow, we'll see a general tool\nfor comparing two graphs $G$ and $H$ to prove\nan inequalities like $c H\n\\preceq G$ for some constant $c$.\nOur tools won't necessarily work well for all cases, but we'll see\nsome examples where they do.\n\n\n% By now you should be wondering, ``how do we prove that $G \\succeq c \\cdot H$ for some graph $G$ and $H$?'' Not too many ways are known. We'll do it by proving some inequalities of this form for some of the simplest graphs, and then extending them to more general graphs.\nIn the rest of the lecture, we will often need to compare two graphs\ndefine on the same vertex set $V = \\setof{1,\\ldots,n} = [n]$.\n\nWe use $G_{i,j}$ to denote the unit weight graph on vertex set $[n]$\nconsisting of a single edge between vertices $i$ and $j$.\n\n\\begin{lemma}[The Path Inequality]\n  \\label{lem:pathineq}\n\\begin{align*}\n(n-1) \\cdot P_n \\succeq G_{1,n},\n\\end{align*}\n\\end{lemma}\n% The following very simple proof of this inequality was discovered by Sam Daitch.\n% \\begin{lemma}\n% \\begin{align*}\n% (n-1) \\cdot P_n \\succeq G_{1,n}.\n% \\end{align*}\n% \\end{lemma}\n\\begin{proof}\n\nWe want to show that for every $\\xx \\in \\in \\R^n$,\n\\begin{align*}\n(n-1) \\cdot \\sum_{i=1}^{n-1} ( \\xx(i+1) - \\xx(i) )^2 \\geq ( \\xx(n) - \\xx(1) )^2.\n\\end{align*}\nFor $i \\in [n-1]$, set\n\\begin{align*}\n\\DDelta (i) = \\xx(i+1) - \\xx(i).\n\\end{align*}\nThe inequality we want to prove then becomes\n\\begin{align*}\n(n-1) \\sum_{i=1}^{n-1} ( \\DDelta(i) )^2 \\geq \\left( \\sum_{i=1}^{n-1} \\DDelta (i)  \\right)^2.\n\\end{align*}\nBut, this is immediate from the Caucy-Schwarz inequality\n$\\aa^{\\trp}\\bb \\leq \\norm{\\aa}_2\\norm{\\bb}_2$:\n\\begin{align*}\n(n-1) \\sum_{i=1}^{n-1} ( \\DDelta (i) )^2\n= & ~ \\| \\vecone_{n-1} \\|^2 \\cdot \\| \\DDelta \\|^2 \\\\\n= & ~ ( \\| \\vecone_{n-1} \\| \\cdot \\| \\DDelta \\| )^2 \\\\\n\\geq & ~  ( \\vecone^\\top_{n-1} \\DDelta )^2  \\\\\n= & ~ (  \\sum_{i=1}^{n-1} \\DDelta(i) )^2\n\\end{align*}\n\\end{proof}\n% \\Zhao{We skip Lemma 4.6.2}\n\n\\subsection{Lower Bounding $\\lambda_2$ of a Path Graph}\n\nWe will now use Lemma~\\ref{lem:pathineq} to prove a lower bound on $\\lambda_2(\\LL_{P_n})$.\n% I'll now demonstrate the power of Lemma 4.6.1 by using it to prove a lower bound on $\\lambda_2 (P_n)$ that will be very close to the upper bound we obtained from the test vector.\n% To prove a lower bound on $\\lambda_2 (P_n)$, we\nOur strategy will be to prove that the path $P_n$ is at least some multiple of the\ncomplete graph $K_n$, measured by the Loewner order, i.e. $K_n \\preceq\nf(n) P_n$ for some function $f: \\N \\to \\R$.\nWe can combine this with our observation from the previous lecture\nthat $\\lambda_2 (\\LL_{K_n}) = n$ to show that\n\\begin{align}\n  \\label{eq:pathtocompleteeig}\nf(n) \\lambda_2(\\LL_{P_n}) \\geq \\lambda_2(\\LL_{K_n}) = n,\n\\end{align}\nand this will give our lower bound on $\\lambda_2(\\LL_{P_n}).$\n% will prove that some multiple of the path is at least the complete\n% graph. To this end, write\nWhen establishing the inequality between $P_n$ and $K_n$, we can treat\neach edge of the complete graph separately, by first noting that\n\\begin{align*}\n\\LL_{K_n} = \\sum_{i < j} \\LL_{G_{i,j}}\n\\end{align*}\nFor every edge $(i,j)$ in the complete graph, we apply the Path\nInequality, Lemma~\\ref{lem:pathineq}:\n\\begin{align*}\n  \\label{eq:1}\nG_{i,j}\n\\preceq & ~ (j-i) \\sum_{k=i}^{j-1} G_{k,k+1} \\\\\n\\preceq & ~ (j-i) P_n\n\\end{align*}\nThis inequality says that $G_{i,j}$ is at most $(j-i)$ times the part of the path connecting $i$ to $j$, and that this part of the path is less than the whole.\n\nSumming inequality (4.3) over all edges $(i,j) \\in K_n$ gives\n\\begin{align*}\nK_n = \\sum_{i < j} G_{i,j} \\preceq \\sum_{i < j}  (j-i)P_n.\n\\end{align*}\nTo finish the proof, we compute\n\\begin{align*}\n\\sum_{i < j}  (j-i) \\leq \\sum_{i < j}  n \\leq n^3\n\\end{align*}\n\nSo\n\\begin{align*}\nL_{K_n} \\preceq n^3 \\cdot L_{P_n}.\n\\end{align*}\n\nPlugging this into Equation~\\eqref{eq:pathtocompleteeig}\nwe obtain\n\\begin{align*}\n\\frac{1}{ n^2 } \\leq \\lambda_2 (P_n).\n\\end{align*}\nThis only differs from our test vector-based upper bound in\nEquation~\\eqref{eq:testvectorbounds} by a factor 12.\n\nWe could make this consirably tigher by being more careful about the sums.\n\n\\subsection{Laplacian Eigenvalues of the Complete Binary Tree}\n\nLet's do the same analysis with the complete binary tree with unit\nweight edges on $n =\n2^{d+1}-1$ vertices, which we\ndenote by $T_d$.\n\n$T_d$ is the balanced binary tree on this many vertices, i.e. it\nconsists of a root node, which has two children, each of those\nchildren have two children and so on until we reach a depth of $d$\nfrom the root, at which point the child vertices have no more\nchildren.\nA simple induction shows that indeed $n = 2^{d+1}-1$.\n\nWe can also describe the edge set by saying that each node $i$ has\nedges to its children $2i$ and $2i+1$ whenever the node labels do not\nexceed $n$.\nWe emphasize that we still think of the graph as undirected.\n\n\n\\paragraph{The largest eigenvalue.}\nWe'll start by above bounding $\\lambda_n(\\LL_{T_d})$ using a test\nvector.\n\nWe let $\\xx(i) = 0$ for all nodes that have a child node, and $\\xx(i)\n= -1$ for even-numbered leaf nodes and $\\xx(i) = +1$ for odd-numbered\nleaf nodes.\nNote that there are $(n+1)/2$ leaf nodes, and every leaf node has a\nsingle edge, connecting it to a parent with value $0$.\nThus\n\\begin{align}\n\\lambda_n(\\LL) = \\max_{ \\substack{ \\vv \\neq \\veczero} } \\frac{\n  \\vv^\\top \\LL \\vv}{ \\vv^\\top \\vv}\n  \\geq\n  \\frac{\\xx^\\top \\LL \\xx}\n  { \\xx^\\top \\xx}\n  =\n  \\frac{ (n+1)/2 }{ (n+1)/2 }\n  = 1\n  .\n\\end{align}\nMeanwhile, every vertex has degree at most 3, so by\nClaim~\\ref{clm:lambdamaxfromeig}, $\\lambda_n(\\LL) \\leq 6$.\nSo we can bound the largest eigenvalue above and below by constant.\n\n\\paragraph{$\\lambda_2$ and diameter in any graph.}\nThe following lemma gives a simple lower bound on $\\lambda_2$ for any\ngraph.\n\\begin{lemma}\n  \\label{lem:lambda2diam}\n  For any unit weight graph $G$ with diameter $D$,\n  \\[\n    \\lambda_2(\\LL_G) \\geq \\frac{1}{nD}.\n    \\]\n\\end{lemma}\n\\begin{proof}\n  We will again prove a lower bound comparing $G$ to the complete\n  graph. For each edge $(i,j) \\in K_n$, let $G^{i,j}$ denote a\n  shortest path in $G$ from $i$ to $j$. This path will have length at most $D$. So, we have\n\\begin{align*}\nK_n\n= & ~ \\sum_{i < j} G_{i,j} \\\\\n\\preceq & ~ \\sum_{i < j} D G^{i,j} \\\\\n\\preceq & ~ \\sum_{i < j} D G \\\\\n\\preceq & ~ n^2 D G.\n\\end{align*}\nSo, we obtain the bound\n\\begin{align*}\nn^2D \\lambda_{2} (G) \\geq n,\n\\end{align*}\nwhich implies our desired statement.\n\\end{proof}\n\n\\paragraph{$\\lambda_2$ in a tree.}\nSince a complete binary tree $T_d$ has diameter $2d \\leq 2\\log_2(n)$,\nby Lemma~\\ref{lem:lambda2diam}, $\\lambda_2(\\LL_{T_d}) \\geq\n\\frac{1}{2n\\log_2(n)}$.\n\nLet us give an upper bound on $\\lambda_2$ of the tree using a test\nvector.\nLet $\\xx \\in \\R^v$ have $\\xx(1) = 0$ and $\\xx(i) = -1$ for $i$ in the left\nsubtree and $\\xx(i) = +1$ in the right subtree.\nThen\n\\begin{align*}\n\\lambda_2(\\LL_{T_d}) = \\min_{ \\substack{ \\vv \\neq \\veczero \\\\ \\vv^\\top\n  \\vecone = 0} } \\frac{ \\vv^\\top \\LL \\vv}{ \\vv^\\top \\vv}\n  \\leq\n  \\frac{ \\xx^\\top \\LL \\xx}{ \\xx^\\top \\xx}\n  =\n  \\frac{2}{n-1}.\n\\end{align*}\nSo, we have shown\n$\\frac{1}{2n\\log_2(n)} \\leq \\lambda_2(\\LL_{T_d})\n\\leq \\frac{2}{n-1}$, and unlike the previous examples, the gap is more\nthan a constant.\n\nIn the exercises for Week 3, I will ask you to improve the lower bound to\n$1/(cn)$ for some constant $c$.\n\n\n\n% \\FloatBarrier\n% \\bibliographystyle{alpha}\n% \\bibliography{refs}\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"agao21_script\"\n%%% TeX-engine: luatex\n%%% End:\n", "meta": {"hexsha": "2ead4b3740cdc52f71b3f5eb918ed91ee5b9dda5", "size": 18278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "agao21_script/lecture5_mod.tex", "max_stars_repo_name": "lukevolpatti/agao21_script", "max_stars_repo_head_hexsha": "864f2937cdd16ab28b8019b0ae9cfbf31a080a84", "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": "agao21_script/lecture5_mod.tex", "max_issues_repo_name": "lukevolpatti/agao21_script", "max_issues_repo_head_hexsha": "864f2937cdd16ab28b8019b0ae9cfbf31a080a84", "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/lecture5_mod.tex", "max_forks_repo_name": "lukevolpatti/agao21_script", "max_forks_repo_head_hexsha": "864f2937cdd16ab28b8019b0ae9cfbf31a080a84", "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.0372439479, "max_line_length": 272, "alphanum_fraction": 0.6675785097, "num_tokens": 6411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.6204283707828411}}
{"text": "\\par\n\\section{Driver programs for the {\\tt A2 object}}\n\\label{section:A2:drivers}\n\\par\n%=======================================================================\n\\begin{enumerate}\n%-----------------------------------------------------------------------\n\\item\n\\begin{verbatim}\ntest_norms msglvl msgFile type nrow ncol inc1 inc2 seed\n\\end{verbatim}\nThis driver program tests the {\\tt A2} norm methods.\nUse the script file {\\tt do\\_norms} for testing.\nWhen the output file is loaded into matlab,\nthe last two lines contain matrices whose\nentries should all be around machine epsilon.\n\\par\n\\begin{itemize}\n\\item\nThe {\\tt msglvl} parameter determines the amount of output.\nUse {\\tt msglvl = 1} for just timing output.\n\\item\nThe {\\tt msgFile} parameter determines the message file --- if {\\tt\nmsgFile} is {\\tt stdout}, then the message file is {\\it stdout},\notherwise a file is opened with {\\it append} status to receive any\noutput data.\n\\item\nThe {\\tt type} parameter denotes the type of entries ---\n{\\tt SPOOLES\\_REAL} or {\\tt SPOOLES\\_COMPLEX} \n\\item\nThe {\\tt nrow} parameter is the number of rows.\n\\item\nThe {\\tt ncol} parameter is the number of rows.\n\\item\nThe {\\tt inc1} parameter is the row increment.\n\\item\nThe {\\tt inc2} parameter is the column increment.\n\\item\nThe {\\tt seed} parameter is a random number seed.\n\\end{itemize}\n%-----------------------------------------------------------------------\n\\item\n\\begin{verbatim}\ntest_QR msglvl msgFile type nrow ncol inc1 inc2 seed\n\\end{verbatim}\nThis driver program tests the {\\tt A2\\_QRreduce()} and\n{\\tt A2\\_QRreduce2()} methods which reduce $A$ to $QR$\nvia rank-1 and rank-2 updates.\nUse the script file {\\tt do\\_QR} for testing.\nWhen {\\tt msglvl > 1}, the matrix $A$ and matrices $R1$ and $R2$\n(computed from {\\tt A2\\_QRreduce()} and\n{\\tt A2\\_QRreduce2()}, respectively)\nare printed to the message file.\nWhen the output file is loaded into matlab,\nthe errors $A^TA - R_1^TR_1$ and $A^TA - R_2^TR_2$\n(if $A$ is real) \nor\nthe errors $A^HA - R_1^HR_1$ and $A^HA - R_2^HR_2$\n(if $A$ is complex) are computed.\n\\par\n\\begin{itemize}\n\\item\nThe {\\tt msglvl} parameter determines the amount of output.\nUse {\\tt msglvl = 1} for just timing output.\n\\item\nThe {\\tt msgFile} parameter determines the message file --- if {\\tt\nmsgFile} is {\\tt stdout}, then the message file is {\\it stdout},\notherwise a file is opened with {\\it append} status to receive any\noutput data.\n\\item\nThe {\\tt type} parameter denotes the type of entries ---\n{\\tt SPOOLES\\_REAL} or {\\tt SPOOLES\\_COMPLEX} \n\\item\nThe {\\tt nrow} parameter is the number of rows.\n\\item\nThe {\\tt ncol} parameter is the number of rows.\n\\item\nThe {\\tt inc1} parameter is the row increment.\n\\item\nThe {\\tt inc2} parameter is the column increment.\n\\item\nThe {\\tt seed} parameter is a random number seed.\n\\end{itemize}\n%-----------------------------------------------------------------------\n\\end{enumerate}\n", "meta": {"hexsha": "dc81ffb06121a372435608bfc093bba2997a1ae3", "size": 2891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ccx_prool/SPOOLES.2.2/A2/doc/drivers.tex", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/SPOOLES.2.2/A2/doc/drivers.tex", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/SPOOLES.2.2/A2/doc/drivers.tex", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 33.6162790698, "max_line_length": 72, "alphanum_fraction": 0.6568661363, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6203810567814885}}
{"text": "\\chapter{k-Nearest Neighbors}\n\\label{ch:knn}\n\nThe idea of k-nearest neighbors is simple - find k instances that are the most similar to each data instance. We make the prediction or estimate probabilities based on the classes of these k instances. For classification, the final label is the majority label of k nearest instances. For regression, the final value is the average value of k nearest instances.\n\n\\begin{marginfigure}\n    \\includegraphics[width=50mm]{knn.png}%\n    \\caption{kNN classifier looks at k nearest neighbors, say 5, of instance X. 4 neighbors belong to the red class and 1 to the blue class. X will thus be classified as red with 80\\% probability.}\n\\end{marginfigure}\n\nUnlike most other algorithms, kNN does not construct a model but just stores the data. This kind of learning is called \\textit{lazy learning}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{workflow.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nThe advantage of kNN algorithm is that it can successfully model the data, where classes are not linearly separably. It can also be re-trained quickly, because new data instances effect model only locally. However, the first training is can be slow for large data sets, as the model has to estimate k distances for data instance.\n\n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[scale=0.4]{knn-orange.png}\n    \\caption{$\\;$}\n\\end{figure*}\n", "meta": {"hexsha": "407d4afd83791c20eec6a18008c56e28f1345d42", "size": 1399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/026-knn/knn.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/026-knn/knn.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/026-knn/knn.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": 53.8076923077, "max_line_length": 360, "alphanum_fraction": 0.7612580415, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079208, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6202027196921155}}
{"text": "\\subsection{Metropolis-Hastings Accept/Reject}\nWritten in terms of these transformations, the augmented leapfrog operator\n$\\mathbf{L}_{\\theta}$ consists of $M$ sequential applications of the\nsingle-step leapfrog operator $\\mathbf{L}_{\\theta} \\xi = \\mathbf{L}_{\\theta}(x,\nv, d) = (x^{\\prime\\prime\\times M}, v^{\\prime\\prime\\times M}, d)$, followed by\nthe previously-defined momentum flip operator $\\mathbf{F}$ which flips the\ndirection variable $d$, i.e.\\ $\\mathbf{F}\\xi = (x, v, -d)$.\n%\nUsing these, we can express a complete molecular dynamics update step as\n$\\mathbf{FL}_{\\theta}\\xi = \\xip$, where now the Metropolis-Hastings acceptance\nprobability for this proposal is given by\n%\n\\begin{equation}\n    A(\\mathbf{F}\\mathbf{L} \\xi | \\xi) = \\min\\left(1,\n        \\frac{p(\\mathbf{F}\\mathbf{L}\\xi)}{p(\\xi)}\\left|\n        \\frac{\\partial\\left[\\mathbf{F}\\mathbf{L}\\xi\\right]}\n            {\\partial\\xi^{T}}\\right|\\right),\n\\end{equation}\n%\nWhere $\\left|\\frac{\\partial\\left[\\mathbf{F}\\mathbf{L}\\xi\\right]}\n{\\partial\\xi^{T}}\\right|$ denotes the determinant of the Jacobian describing\nthe transformation.\n\nIn contrast to generic HMC where\n$\\left|\\frac{\\partial\\left[\\mathbf{F}\\mathbf{L}\\xi\\right]}\n{\\partial\\xi^{T}}\\right| = 1$, we now have non-symplectic transformations\n(i.e.\\ non-volume preserving) and so we must explicitly account for the\ndeterminant of the Jacobian.\n%\nThese non-volume preserving transformations have the effect of deforming the\nenergy landscape, which, depending on the nature of the transformation, may\nallow for the exploration of regions of space which were previously\ninaccessible.\n%\n\\newcommand{\\energyA}{\\includegraphics[width=0.4\\textwidth]{energy_landscape/original_energy_landscape.pdf}}\n\\newcommand{\\energyB}{\\includegraphics[width=0.4\\textwidth]{energy_landscape/modified_energy_landscape.pdf}}\n%\n\\begin{figure}\n  \\centering \n  \\Huge\n  \\parbox{\\widthof{\\energyA}}{\\energyA} $\\overset{\\mathcal{J}}{\\longrightarrow}$\n  \\parbox{\\widthof{\\energyB}}{\\energyB} \n  \\normalsize\n  \\caption{Example of how the determinant of the Jacobian can deform the energy landscape.}\n\\end{figure}\n\nTo simplify our notation, introduce an additional operator $\\mathbf{R}$ that\nre-samples the momentum and direction, e.g.\\ given $\\xi = (x, v, d)$,\n$\\mathbf{R}\\,\\xi = (x, v^{\\prime}, d^{\\prime})$ where $v^{\\prime} \\sim\n\\mathcal{N}(0, I)$, $d^{\\prime} \\sim \\mathcal{U}\\left(\\{-1, 1\\}\\right)$.\n%\nA complete sampling step of our algorithm then consists of the following two\nsteps:\n%\n\\begin{enumerate}\n    \\item $\\xi^{\\prime} = \\mathbf{FL}_{\\theta} \\,\\xi$ with probability\n        $A(\\mathbf{FL}_{\\theta}\\,\\xi|\\xi)$ %(Eq.~\\ref{eq:metropolis_hastings}),\n        otherwise $\\xi^{\\prime} = \\xi$.\n    \\item $\\xi^{\\prime} = \\mathbf{R}\\,\\xi$.\n\\end{enumerate}\n%\nNote however, that for MH to be well-defined, this deterministic operator must\nbe \\emph{invertible} and \\emph{have a tractable Jacobian} (i.e.\\ we can compute\nits determinant).\n%\nIn order to make this operator invertible, we augment the state space $(x, v)$\ninto $(x, v, d)$, where $d \\in \\{-1, 1\\}$ is drawn with equal probability and\nrepresent the direction of the update.\n%\nAll of the previous expressions for the augmented leapfrog updates represent\nthe forward ($d = 1$) direction.\n%\nWe can derive the expressions for the backward direction ($d = -1$) by\nreversing the order of the updates (i.e.\\ $\\vpp \\rightarrow \\vp$, then $\\xpp\n\\rightarrow \\xp$, followed by $\\xp \\rightarrow x$ and finally $\\vp \\rightarrow\nv$).\n%\nFor completeness, we include in Sec.~\\ref{sec:lf_forward} and\nSec~\\ref{sec:lf_backward} all of the equations (both forward and backward\ndirections) relevant for updating the variables of interest in our augmented\nleapfrog sampler.\n\\section{Forward Direction \\texorpdfstring{$(d = 1)$}{(d = 1)}:}%\n\\label{sec:lf_forward}\n% \\vspace{-20pt}\n\\begin{align}\n  \\label{eq:forward_update}\n  \\vp &= v \\odot \\exp{\\left(\\frac{\\eps}{2}S_{v}(\\zeta_{1})\\right)}% \n        - \\frac{\\eps}{2}\\left[\\partial_{x}\\,U(x)\\odot \\exp{\\left(\\eps\n          Q_{v}(\\zeta_{1})\\right)}%\n        + T_{v}(\\zeta_{1})\\right] \\\\\n  \\xp &= x_{\\bar{m}^{t}} + m^{t}\\odot \\left[x \\odot \\exp{\\left(\\eps\n    S_{x}(\\zeta_{2})\\right)}%\n        + \\eps\\left(\\vp\\odot\\exp{\\left(\\eps Q_{x}(\\zeta_{2})\\right)} \n          + T_{x}(\\zeta_{2})\\right)\\right] \\\\\n  \\xpp &= x^{\\prime}_{m^{t}} + \\bar{m}^{t}\\odot \\left[\\xp \\odot \\exp{\\left(\\eps\n    S_{x}(\\zeta_{3})\\right)}%\n        + \\eps\\left(\\vp\\odot\\exp{\\left(\\eps Q_{x}(\\zeta_{3})\\right)} +\n      T_{x}(\\zeta_{3})\\right)\\right] \\\\\n  \\vpp &= \\vp \\odot \\exp{\\left(\\frac{\\eps}{2}S_{v}(\\zeta_{4})\\right)}%\n        - \\frac{\\eps}{2}\\left[\\partial_{x}\\,U(\\xpp)\\odot \\exp{\\left(\\eps\n          Q_{v}(\\zeta_{4})\\right)}%\n          + T_{v}(\\zeta_{4})\\right]\n\\end{align} \n%\nWith $\\zeta_{1} = (x, \\partial_{x}\\, U(x), t)$, $\\zeta_{2} = (x_{\\bar{m}^{t}},\nv, t)$, $\\zeta_{3} = (x^{\\prime}_{m^{t}}, v, t)$, $\\zeta_{4} = (\\xpp,\n\\partial_{x}\\, U(\\xpp), t)$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n\\section{Backward Direction \\texorpdfstring{$(d = -1)$}{(d = -1)}:}%\n\\label{sec:lf_backward}\n%\n\\begin{align}\n  \\label{eq:backward_update}\n  v^{\\prime} &= {\\left\\{v + \\frac{\\eps}{2}\\left[\\partial_{x}\\,U(x)\\odot\n        \\exp{\\left(\\eps Q_{v}(\\zeta_{1})\\right)}%\n    + T_{v}(\\zeta_{1})\\right]\\right\\}} \\odot\n    \\exp{\\left(-\\frac{\\eps}{2}S_{v}(\\zeta_{1})\\right)} \\\\\n  \\xp &= x_{m^{t}} + \\bar{m}^{t}\\odot%\n    {\\left[x - \\eps{\\left(\\exp{\\left(\\eps Q_{x}(\\zeta_{2})\\right)}\\odot \\vp%\n    + T_{x}(\\zeta_{2})\\right)}\\right]}\\odot \\exp{\\left(-\\eps\n    S_{x}(\\zeta_{2})\\right)} \\\\ \n  \\xpp &= x_{\\bar{m}^{t}} + m^{t}\\odot%\n    {\\left[\\xp - \\eps{\\left(\\exp{\\left(\\eps Q_{x}(\\zeta_{3})\\right)}\\odot \\vp%\n    + T_{x}(\\zeta_{3})\\right)}\\right]}\\odot \\exp{\\left(-\\eps\n    S_{x}(\\zeta_{3})\\right)} \\\\\n  v^{\\prime\\prime} &= {\\left\\{\\vp +\n      \\frac{\\eps}{2}\\left[\\partial_{x}\\,U(\\xpp)\\odot%\n        \\exp{\\left(\\eps Q_{v}(\\zeta_{1})\\right)}\n  + T_{v}(\\zeta_{1})\\right]\\right\\}}\\odot \n    \\exp{\\left(-\\frac{\\eps}{2}S_{v}(\\zeta_{4})\\right)}\n\\end{align}\n%\nWith $\\zeta_{1} = (x, \\partial_{x}\\, U(x), t)$, $\\zeta_{2} = (x_{m^{t}}, v,\nt)$, $\\zeta_{3} = (x^{\\prime}_{\\bar{m}^{t}}, v, t)$, $\\zeta_{4} = (\\xpp,\n\\partial_{x}\\, U(\\xpp), t)$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Determinant of the Jacobian}\nIn terms of the auxiliary functions $S_{i}, Q_{i}, T_{i}$, we can compute the\nJacobian:\n%\n\\begin{align}\n  \\log|\\mathcal{J}| \n  &= \\log\\bigg|\\frac{\\partial{\\left[\\mathbf{FL}_{\\theta}\\xi\\right]}}{\\partial\n  \\xi^{T}}\\bigg|\\\\\n  &= d \\sum_{t\\leq N_{\\mathrm{LF}}}\n    {\\left[\\frac{\\eps}{2} \\mathbbm{1}\\cdot S_{v}(\\zeta_{1}^{t}) + \\eps m^{t}\n        \\cdot S_{x}(\\zeta_{2}^{t}) \n      + \\eps \\bar{m}^{t} \\cdot S_{x}(\\zeta_{3}^{t}) + \\frac{\\eps}{2}\\mathbbm{1}\n\\cdot S_{v}(\\zeta_{4}^{t})\\right]}.  \\end{align}\n%\nwhere $N_{\\mathrm{LF}}$ is the number of leapfrog steps, and $\\zeta_{i}^{t}$\ndenotes the intermediary variable $\\zeta_{i}^{t}$ at time step $t$ and $d$ is\nthe direction of $\\xi$, i.e.\\ $d = 1 \\,\\, (-1)$ for the forward (backward)\nupdate.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "ac9dfb19bd191f9eb688f411a95a311a4a24df07", "size": 7304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/mh.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/mh.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/mh.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": 45.3664596273, "max_line_length": 108, "alphanum_fraction": 0.5943318729, "num_tokens": 2554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6202007188765344}}
{"text": "\\subsection*{Generating Adversarial Samples}\nRandomly sampling the noise field to find samples close to a certain image would be time-consuming and inefficient. Luckily generating adversarial input images can be done by using the Fast Method (eq \\ref{FastMethod}) proposed by \\citeauthor{goodfellow2015explaining}.\n\\begin{equation}\n    X^{adv} = X + \\epsilon * sign(\\nabla_{x}J(X, y_{true}))\n    \\label{FastMethod}\n\\end{equation}\nWith $X$ being the input image, $\\epsilon$ a hyperparameter determining much the original image can be perpetrated and $J(X, y_{true})$ the loss function which to, in the adversarial case, maximize.\n\n\\subsection*{Steering Adversarial Samples}\nTo steer the network towards a specific output we can adjust the equation \\ref{FastMethod} to minimize a loss function with a given target $y$.\n\\begin{equation}\n    X^{steer} = X - \\epsilon * sign(\\nabla_{x}J(X, y_{target}))\n\\end{equation}\nWhere $y_{target}$ can be determined to be anything.\n\n\\subsection*{Evaluation}\nTo determine if the model is indeed susceptible the BLEU scores will be calculated for different values of $\\epsilon$. Furthermore, to also investigate if the semantic meaning of the sentence is significantly affected, the cosine similarity of the original and adversarial output will be calculated using universal sentence embedding proposed by \\citeauthor{DBLP:journals/corr/abs-1803-11175}.\nTo see if the model can also be steered the BLEU score and cosine similarity are calculated with respect to the $y_{target}$.\n", "meta": {"hexsha": "acb20bea0093b214c8645cefe4bf57f88d705bb9", "size": 1512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/chapters/methodology.tex", "max_stars_repo_name": "dikvangenuchten/bep-adversarial-image-annotation", "max_stars_repo_head_hexsha": "f4d8a7349df7a6c7cc8aa4a4409c45a7082b24ee", "max_stars_repo_licenses": ["MIT"], "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/methodology.tex", "max_issues_repo_name": "dikvangenuchten/bep-adversarial-image-annotation", "max_issues_repo_head_hexsha": "f4d8a7349df7a6c7cc8aa4a4409c45a7082b24ee", "max_issues_repo_licenses": ["MIT"], "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/methodology.tex", "max_forks_repo_name": "dikvangenuchten/bep-adversarial-image-annotation", "max_forks_repo_head_hexsha": "f4d8a7349df7a6c7cc8aa4a4409c45a7082b24ee", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.5789473684, "max_line_length": 393, "alphanum_fraction": 0.7797619048, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.620200713403697}}
{"text": "\\section{Response Theory for (3+1)D Topological Insulator}\nThe response theory has action\n\\begin{align}\n    S[A,g] &=\n    \\theta\\cdot \\frac{1}{32\\pi^2}\n    \\int_{M^4} F_{\\mu\\nu}F_{\\lambda\\sigma} \\epsilon^{\\mu\\nu\\lambda\\sigma}\n    - \\frac{1}{48}\n    \\int \\frac{1}{\\left( 2\\pi \\right)^2} \\Tr R\\wedge R\n\\end{align}\nwhere $\\theta=\\pi$ for non-trivial and $\\theta=0$ for trivial.\nRecall that\n\\begin{align}\n    \\int F_{\\mu\\nu}F_{\\lambda\\sigma} \\epsilon^{\\mu\\nu\\lambda\\sigma}\n    =\n    \\vec{E}\\cdot\\vec{B}\n\\end{align}\n\nThe physical consequences are TME:\n\\begin{enumerate}\n    \\item Domain wall in $\\theta$, $\\frac{1}{2}$ integer Hall conductance at\n        surface.\n    \\item Witten effect\n        \\begin{align}\n            Q_e &= \\frac{1}{2}Q_m\n        \\end{align}\n    \\item Magnetic field induces charge polarization\n\\end{enumerate}\nthe current is\n\\begin{align}\n    j^{\\mu} &= \\frac{\\delta S}{\\delta A^\\mu}\n    = \\frac{1}{2\\pi} \\epsilon^{\\mu\\nu\\lambda\\sigma}\n    \\partial_\\nu \\theta \\partial_\\lambda A_\\sigma\n\\end{align}\nLet $\\theta$ be uniform and time-dependent\n\\begin{align}\n    j^i &=\n    -\\frac{1}{2\\pi}\n    \\epsilon^{tijk} \\partial_t \\theta \\partial_j A_k\\\\\n    &= -\\frac{1}{2\\pi}\\partial_t \\theta\\cdot B^i\n\\end{align}\nso then the current is\n\\begin{align}\n    \\vec{j} &=\n    \\frac{\\partial\\vec{p}}{\\partial t}\\\\\n    &=\n    -\\frac{1}{2\\pi} \\partial_t \\theta \\vec{B}\n\\end{align}\nand so the magnetic polarizability is\n\\begin{align}\n    \\vec{P} &=\n    -\\frac{\\theta}{2\\pi}\\vec{B} + \\mathrm{const}\n\\end{align}\nFor a topological insulator $\\theta=\\pi$.\nIt's a bulk polarization but poarlizaiton only has an effect on the surface.\nWhen I change $\\theta$ from 0 to $3\\pi$ for example,\nmy quantum hall effeect on the surface is $\\left(1 + \\frac{1}{2}\\right)e^2/h$.\n\nIn 1D I can always add an integer charge on the surface.\nIf I put $2\\pi$ here,\nthe efect is tackign on a quantum hall effect on the surace.\nThe bulk didn't play a special role,\nit's just something intrinsicaly 2D you can do.\n\n\\begin{question}\n    Why is QHE layer the same as surface charge?\n\\end{question}\nThe magnetic field induces the surface carge.\nCharge density is attached to magnetic field in the integer quantum hall effect.\n\n\\begin{question}\n    How do you physically increase $\\theta$?\n    Whatif you wanted to?\n\\end{question}\nThis was just a trick to get this eqution.\nEvery insulator in 3D has a $\\theat$.\nCould be anything.\nButi f it's time-reversal invariatn,\nit's pinned to $0$ or $\\pi$.\nWhat $\\theta$ is for a specific material,\nits' a aproperty of hte matieral.\n\n\\begin{question}\n    Insead of magnetic field, the charge goes ot the edge of the system?\n\\end{question}\nIf I insert a magnetic field localy,\nI locally get a charge.\nIf I insert a uniform magnetic field then I get a uniform charge.\n\n\\begin{question}\n    So the divergence of $\\vec{B}$ is zero,\n    does that mean there's no net charge within anywhere in the system?\n\\end{question}\nFrom the Witten effect,\ncharge is attached to the monopole.\nIf you have no monopoles,\nthen you won't have any.\n\nI told you all thsi stuff,\njust asserted the response theory of the TI  has a $\\theta$ term,\nbut I didn't derive it from any mdoel.\nI want to give you one type of model.\nThis goes back to the dimensional reduction from (4+1)D.\n\nTo describe (3+1)D TI,\nit's useful to start with a (4+1)D analogue of the Chern insulator.\n\nWhat is a (4+1)D Chern insualtor?\nIn 2+1D,\nwe wrote the berry connection.\nBut now you have to define a non-abelian Berry connection.\n\\begin{align}\n    a_i^{\\alpha\\beta} &=\n    -i \\bra{\\alpha,k} \\frac{\\partial}{\\partial k_i} \\ket{\\beta,k}\\\\\n    f_{ij}^{\\alpha\\beta} &=\n    \\partial_i a_j^{\\alpha\\beta}\n    - \\partial_j a_i^{\\alpha\\beta}\n    + i\\left[ a_i, a_j \\right]^{\\alpha\\beta}\n\\end{align}\nwhere $i,j$ are spatial indices and $\\alpha\\beta$ are band indices.\nThe second Chern number is\n\\begin{align}\n    C_2 &=\n    \\frac{1}{32\\pi^2} \\int d^4k\n    \\epsilon^{ijkl} \\Tr f_{ij}f_{kl}\n\\end{align}\nHere we get a (4+1)D Chern-Simons term\n\\begin{align}\n    S_{CS,4+1} &=\n    \\int\n    \\frac{C_2}{24\\pi^2} A_{\\mu}\\partial_\\nu A_\\lambda \\partial_\\rho A_\\sigma\n    \\epsilon^{\\mu\\nu\\lambda\\sigma}\n\\end{align}\nThere isa Maxwell term with two factors of $A$,\nbut here we have3 factors of $A$,\nso this is subleading,\nbut this term is topological,\nwherease Maxwell si not toolgocial.\n\nIn (2+1)D we had a model for the Chern Insulator,\nwhere it's basically a massive Dirac fermion you put on a lattice.\n\nHere we write a $(4+1)D$ massive Dirac fermion instead.\nSo the mdoel for the $(4+1)D$ Chern insulator is a massive Dirac fermion,\nwhich in momentum space you would write\n\\begin{align}\n    H &= \\sum_k \\psi_k^\\dagger d_a(k)\\Gamma^a \\psi_k\n\\end{align}\nwhere the $\\psi_k$ are 4-component fermions,\nand these $\\Gamma$ are $(4+1)D$ Dirac matrices which satisfy the Clifford\nalgebra\n\\begin{align}\n    \\left\\{ \\Gamma^\\mu, \\Gamma^\\nu \\right\\} = 2\\delta_{\\mu\\nu}\n\\end{align}\nwhere $\\mu,\\nu=0,\\ldots,4$.\nAnd our lattice vectors are\n\\begin{align}\n    d(k) &=\n    \\left( \n    m + c\\sum_{i}\\cos k_k,\n    \\sin k_x,\n    \\sin k_y,\n    \\sin k_z,\n    \\sin k_w,\n    \\right)\n\\end{align}\nand to be concrete,\nwe can write explicityly the Gamma matrices\n\\begin{align}\n    \\Gamma^a &=\n    \\sigma^a \\otimes \\tau^2\n\\end{align}\nfor $a=1,2,3$\nand\n\\begin{align}\n    \\Gamma^4 = I\\otimes \\tau^1\\\\\n    \\gamma^0 &= I\\otimes \\tau^3\n\\end{align}\nand the lattice vectors\n\\begin{align}\n    \\hat{d}(k) &=\n    \\frac{\\vec{d}(k)}{|d(k)|}\n\\end{align}\nThe second Chern number is\n\\begin{align}\n    C_2 &=\n    \\frac{3}{8\\pi^2}\n    \\int d^4k\n    \\epsilon^{abcde}\n    \\hat{d}_a\n    \\partial_x \\hat{d}_b\n    \\partial_y \\hat{d}_c\n    \\partial_z \\hat{d}_d\n    \\partial_w \\hat{d}_2\\\\\n    &=\n    \\begin{cases}\n        0 & m < -4c, m >4c\\\\\n        1 & -4c < m < -2c\n    \\end{cases}\n\\end{align}\nand just like before,\nthere are $(3+1)D$ gapless chiral fermions on the surface with\n$|C_2|$ flavours.\n\nThe surface Hamiltonian will be\n\\begin{align}\n    H_{\\mathrm{surface}} &=\n    \\sgn(C_2)\n    \\int \\frac{d^3k}{(2\\pi)^3}\n    \\sum_{i=1}^{|C_2|}\n    V_i \\psi_i^\\dagger \\vec{\\sigma}\\cdot\\vec{k} \\psi_i\n\\end{align}\nwhere these are 2-component fermions.\n\nThere is a chiral anomaly\n\\begin{align}\n    \\partial_\\mu j^\\mu \\propto FF\n\\end{align}\n\nNow that we have this $(4+1)D$ cherin insulator,\nwe can dimension-reduce and view one of these $A$ componetns as a parameter,\nand we effectively get an $F\\wedge F$ term in the dmiensinoally reduce dmouel\n\nThese chircal fermions onthe surface descend into Dirac cones on the surface of\nthe $(3+1)D$ topological insulator.\n\n\\begin{question}\n    Why are there $C_2$ flavours?\n\\end{question}\nIt is the analogue of $C_1$ flarous in $(2+1)D$.\n\nIt's always a 2-component fermion,\nbuti t's a question of how many you have.\nThe Chern numbero f bulk is just like the $(2+1)D$ case.\n\n\\begin{question}\n    Why 2 component fermions?\n\\end{question}\nI don't have a quick answer.\n\nThe point is you decompose your fermions\nwith a chirality operator,\nso you split the 4 componet into 2, 2 components,\nand because it's chiral,\nyou only have 2.\nThey are $C_2$ flarous of the 2-compoent fermion.\n\n\\begin{question}\n    How do you visualize a $(2+1)D$ chiral fermion.\n\\end{question}\nI don't have a godo visualization.\nThere's chirality operator,\nand you project them onto two eigenvectors.\n\nIf you have massless particles moving in a direciton,\nyou can attribute a handedness of the particles,\nwhich you cannot Loretnz boost out of.\n\nYeah, it's basically in this language,\n$1\\pm \\Gamma^0$,\nthat's how you define the Chirality operator.\nProjection onto some particular chirality.\n\n\\begin{question}\nIn 2 spatial dimensions,\nyou have only clockwise and anti-clockwise.\nWhat's the analog of this?\n\\end{question}\nI don't usually think of chiral fermions in 3 dimensions.\n\n\\begin{question}\n    In the 1D case,\n    you could think of the Chern number as the wrapping of the sphere?\n\\end{question}\nOh yes.\nThe $\\hat{d}$ vector is a map from the Brilluoin zone $\\hat{d}:T^4\\to S^4$.\nThis is computing the winding numbero f the map from $S^4\\to S^4$.\n\nIf you take $k\\to\\infty$, it is the case that it all points in the same\ndirection,\nI don't know if there's an easy way of saying it.\n\nHis point is if I take $k_x$ to $\\infty$ but not the other ones,\n\nI was plannig on presenting the dimensinoal reduction from $(4+1)D$\nto $(3+1)D$.\n\nThe point is the $(4+1)D$ model can be thought of as\ndecoupled $(3+1)D$ models parameterized by $k_w$.\nWe did a version of this in $(2+1)D$,\nwhere we thoguht of it as a $(1+1)D$ Hamiltonian parametrized by $k_y$.\n\nLet's write the Hamiltnoian first in real space on a lattice.\nOn real space on a lattice,\nthat Hamiltnoian will look like\n\\begin{align}\n    H_{(4+1)D} &=\n    \\sum_{\\sigma,a=1,\\ldots,4}\\left[ \n    \\psi_{\\vec{r}}^\\dagger\n    \\left(\n    \\frac{c\\Gamma^0 - i\\Gamma^i}{2}\n    \\right)\n    \\psi_{\\vec{r} + \\hat{a}}\n    e^{i A_{\\vec{r},\\vec{r} + \\hat{a}}}\n    + \\mathrm{h.c.}\n    + m\\psi_{\\vec{r}}^\\dagger \\Gamma^0 \\psi_r\n    \\right]\n\\end{align}\nand then I can write it in the ``Landau gauge''\ntranslationlaly invariatn in $w$ direction\n\\begin{align}\n    H_{(2+1)D}[A] &=\n    \\sum_{k_w} H_{(3+1)D}[k_w, A]\n\\end{align}\nand then\n\\begin{align}\n    H_{(3+1)D} [k_w, A] &=\n    \\sum_{\\vec{r}, a=1,\\ldots,3}\\left[ \n    \\psi_{\\vec{r}, k_w}^\\dagger\n    \\left( \n    \\frac{c\\Gamma^0 - i\\Gamma^a}{2}\n    \\right)\n    \\psi_{\\vec{r} + \\hat{a}, k_w}\n    e^{i A_{\\vec{r},\\vec{r} + \\hat{a}}}\n    + \n    \\mathrm{h.c.}\n    \\right]\\\\\\nonumber\n    &\\qquad+\n    \\sum_{\\vec{r}}\n    \\psi_{\\vec{r}, k_w}^\\dagger\\left[ \n    \\sin\\left( k_w + A_{\\vec{r}, w} \\right)\\Gamma^4\n    +\n    \\left( m + c\\cos\\left( k_w + A_{\\vec{r},w} \\right)\\right)\\Gamma^0 \n    \\right]\n\\end{align}\nSo if I set $\\theta=k_w + A_{\\vec{r},w}$,\nI just replace $k_w + A_{\\vec{r},w} = \\theta_{\\vec{r}}$\nand this gives us\n$H_{(3+1)D}[A,\\theta]$.\n\nAt the level of the effective action,\nwe can figure out the efective response theory\nby doing dimensinoal reduction in the response theory.\n\nAnd so\n\\begin{align}\n    S_{(4+1)D} &=\n    \\frac{C_2}{24\\pi^2} \\int d^4x \\, dt\\,\n    \\epsilon^{\\mu\\nu\\rho\\sigma\\tau}\n    A_{\\mu} \\partial_\\nu A_\\rho \\partial_\\sigma A_\\tau\n\\end{align}\nand under dimensional reduction $C_2=$,\nand I can just rewrie this action as\n\\begin{align}\n    S &=\n    \\frac{1}{24\\pi^2} 3\n    \\int d^3x \\, dt\\,\n    \\epsilon^{w \\mu\\nu\\rho\\sigma}\n    A_w \\partial_\\mu A_\\nu \\partial_\\rho A_\\sigma\\\\\n    &=\n    \\frac{\\theta}{32\\pi^2}\n    \\int \\epsilon^{\\mu\\nu\\rho\\sigma} F_{\\mu\\nu}F_{\\rho\\sigma}\n\\end{align}\n\nWhy did we set $C_2=1$?\nBecause I want to describe the non-trivial topological insulator.\nIf I set $C_2=2$, then I would just get two copies of the TI.\n\nYou can just do perturbation theory to see what the response theory looks like.\n\n\\begin{question}\n    Is $\\theta$ here defined on $2\\pI$ and does it save the time-reversal\n    symmetry?\n\\end{question}\nHere it does, just follows from the same argumetn I made before.\n\nThis $k_w + A_{r,w}=\\theta_r$,\nwhich you can see is periodic in $2\\pi$.\n\nIf you write the time-reversal operator,\nthis term does not commute with the time-reversal operator,\nso $\\theta$ has to be $0$ or $\\pI$.\n\n\\begin{question}\n    When is dimensional reduction not possible?\n    This is quite general argumetn.\n\\end{question}\nYou can always do dimensional reduction,\nbut it's not necesarily the case that you start with some theory,\nand you do dimesnional reductino and yo uget an interseting and nontrivial\ntheory.\n\nFor example, if I set $C_2=2$,\nI get two copies and I get the trivial insulator.\n\nIn $(2+1)D$ where we did dimesniaonl reductnio,\nthe $(1+1)D$ theory was not trivial because it realised a topological pump.\n\nWe start with a topological pahse characterised by integer $C_2$,\nand then $\\mathbb{Z}_2$ invariants.\n\nYou could dmiensional reduce one more time,\nand yo uget the $(2+1)D$ topological insulator,\nwhich is time-reversal invariant.\n\n\\begin{question}\n    Do we need the model gapped?\n\\end{question}\nIf you start witha gapped model,\nyou usually wind up with a gapped model.\nBut if you started with a gapless mdoel,\nyou might not end up with a gapless model.\n\n\nNow you can also do the $(2+1)D$ surface.\nIf we take $C_2=1$,\nwe would only have one flavour,\nand if I dmeinosaly reduce,\nand set $k_w=0$,\nthen I would just get a single Dirac cone.\nThis ia nice way to se the (2+1)D surface\nwould jsut beceom a (2+1)D Dirac cone.\nI won't write it out,\nbecause it's obvious from this.\n\n\nLet me write out one more thing to be a little more clear.\nWen you do dimensinoal reduction,\nyou can think of putting a system on a cylinder,\nin which case the azimuthal direction is $w$.\nThen your momentum would be quantized\n\\begin{align}\n    k_w &= \\frac{2\\pi}{L-w}n\n\\end{align}\nand the low-energy mode is the one where $n=0$.\nIf you start with Chiral fermions and do dimesnioanl reductio\nyou have one massless fermion, the zero-ommentum mode\nthat descends to the massless dirac cone,\nbut you would have higher dmieinosal massive Dirac fermions.\n\n\nIntersting commetn:\nIf you start with the $(2+1)D$ surface Dirac cone,\nI mentinoed before this theory has a Perry anomaly,\nhwich is a mix of U(1) and TR symmetry,\nbut you see the theory has problems,\nyou can decude the fact that the only way of preserving the symmetyra nd makig\nmaking the theory well-define is to inroduce a bulk (3+1) respone theory.\n\nSo start with a (2+1)D surface theory with a Dirac cone,\nthen try to make the path integral well-defined with\n$T$, $U(1)$.\nThen educe a $(3+1)D$ bulk with\n\\begin{align}\n    S_{eff} &=\n    \\int F\\wedge F + R\\wedge R\n\\end{align}\nThere's a paper by Witten in 2015,\nwhich is nice because he uses the APS index therem by Atiyah.\nI would go thorugh it,\nbut it would be an entire lecture.\n\n\\begin{question}\n    Does it go up to higher dimensions?\n\\end{question}\nIn Witen's paper,\nhe only does $(3+1)D$ topological theories,\nbut the index theorem hsould work.\n\nThe thing is,\nthis parity anomaly you don't have in every dimension,\nyou have it in every 8 dimensisno.\nThere's a periodicity of 8.\nEverything we did for free fermions has periodicity 8.\nDeep,\nbut we don't care beyond 3 dimensions.\n\n\\begin{question}\n    Are zero modes of (3+1)D a subset of zero modes in (4+1)D\n\\end{question}\nI don't know, it's not obvious.\n\n\\begin{question}\n    Experimental progress in realising these?\n\\end{question}\nThere are multiple generations of people who predicted various matirerals.\nThe first material is BismuthAntimony,\nbut since then many materials have been porpsoed.\nThere's no problem gettinga band structure exhitibing this topolgoical\ninsulator,\nbut the problem is getting the chemical potential in the gap.\nYou can't tune the chemical potential like in 2D,\nyou need to use doping,\nbut it's hard to get hese materials into actual insualtors.\nEarly on,\nit was difficult getting the chmiceal potential in the right place.\nBut in the band structre,\nyou could confirm things like an odd numberof Dirac conesno the surface.\nI don't know if people actually sucessfully made an insulating matieral that was\ntopogoloical and gets the chemcial potential in the right palce.\n\nWas anyone following?\n\nNow I want to switch gears a little bit.\nLet's summarize what we did.\n\nWe talked about a $(1+1)D$ Majorana system with\n$G_f = \\mathbb{Z}_2^f$,\nand there is a $\\mathbb{Z}_2$ invariant.\n\nThen we considered $(2+1)D$ systems with $G_f=\\mathbb{Z}_2^f$.\nThere is a $\\mathbb{Z}$ invariatn which si the chiral central charge,\nwhich is realised by the $p+ip$ superconductor.\n$G_f = U(1)^f$And there is a $\\mathbb{Z}$ invariant Chern insulator.\nAnd we studied \n$G_f = U(1)^f \\rtimes \\mathbb{Z}_4^{t,f}/\\mathbb{Z}_2$\nwhich results in a $\\mathbb{Z}_2$ invariatn in class AII.\n\nThen in $(3+1)D$,\nwe geta $\\mathbb{Z}_2$ invariant to class AII.\n\nAll the above are examples of invertible topological phases.\nThey all have free fermion realisations.\nThese are all examples,\nonce we look at what states are at the free fermion level,\nall states were stable to added interaciton.\nThey all had phsycal propblems.\nthe $\\mathbb{Z}$ invairnat is jus the QHE conducatnce.\nAnd we also solved for hte phsycial properties of these invariats.\nWe didn't formally argue it,\nbut it is plausible because iti s a physical quantitiy you could measure its\nproperties.\n\nThere are other tings tha could hapepen.\nthera resiutaltios in free fermions you get $\\mathbb{Z}$ invariatns,\nbut when you add interactinos,\nit drops to $\\mathbb{Z}_8$.\n\nAnd then you could have invertible models with no fre fermion ralisations.\nAnd then you have non-invertible models.\n\n\\section{Bosonic in (1+1)D}\nTheseare inrinsically strongly interacting,\nbecause if not they will condense into superfuliud state.\nI necessarily need a strongly interacting system.\nSo all the tools we had for free fermion models become useless.\nIn $(1+1)D$ for bosons,\nbosons can only realize a certina subclass of invertible phases.\n\nThere are some aspects.\n\\begin{enumerate}\n    \\item There's no topological order in 1D.\n        This means if you forget about any symmetries of your model,\n        any gapped bosonic state in 1D can be adiabatically conencted to trivila\n        state.\n        That's difernt to the fermionic case,\n        where if you ignore all pases,\n        it's still non-trivial bcause thereare stil MZMs.\n        For bosons,\n        if you ignore symmetries,\n        everything can be adiabatically connected to the trivial phase.\n        So no topological order in 1D.\n    \\item If you add symmetry,\n        then we couldh ave a class of topological phases called SPT phases.\n        SPT stands for symmetry protected topological.\n        These are a subset of invertible phases,\n        which has the property that if you break the symmetry,\n        it can be adiabatically connected to a trivail state,\n        but if you have the symmetyr,\n        it cannot be in a way that preserves the symmetry.\n        These are classified by a quantitiy called the group cohomology\n        $H^2(G, U(1))$.\n        The second cohomology group with group elements of $G$ wiht coefficients\n        in $U(1)$.\n\\end{enumerate}\nRigorous proof will require mathematical frameowrks not in this class.\nWe can establish this using matrix product states.\n\nTher eare no invertible phaess that are not SPTs.\nThere are no chiral phases.\nYou wouldn't be able to define chiral,\nthe boundary is zero dmiensional,\nso there are no chiral moedes.\n$(2+1)D$ is special,\neven bosons have an nivertible phase that is not an SPT.\n\nLet me start off by giving an example of an interesting 1D state.\nThe most important example is the AKLT state.\n\nThese guys considered a spin-1 chain,\nwith $G=SO(3)$ symmetry.\n\nThe Hamiltonian includes a Heisenberg term,\nbut in addition,\nthere's an extra term that is the square of he Heisenberg term\nand a constant offset\n\\begin{align}\n    H_{AKLT} &=\n    \\frac{1}{2} \\sum_{i} \\left( \n    \\vec{S}_i\\cdot \\vec{S}_{i+1}\n    + \\frac{1}{3} \\left( \\vec{S}_i\\cdot\\vec{S}_{i+1} \\right)^2\n    + \\frac{2}{3}\n    \\right)\\\\\n    &= \\sum_i P_{i,i+1}^{(2)}\n\\end{align}\nwhere $S_i^{\\alpha}$ is a $3\\times 3$ matrix\nand $P_{i,i+1}^{(2)}$ is a projector onto spin-2 subspace of neighbouring spin\n1s.\n\nThis is simply the explicit form of this projector.\nFor spin $1/2$ particles,\nthere is no square term.\nOnce we have this sum of projectors,\nG\nthe ground state is the state that is annihilated by all projects.\n\nI have a spin chain,\nand I am summing over every site on the spin chain.\nThe first term would be $P_{1,2}$,\nwhere I project 1 and 2 onto spin 2, etc.\n\nIs there a non-trivial state that si annihilated by all $P$s.\nYou might be worried thesubspace annihlated by this is zero-dimensiona,\nbut it's one-dimensional on a periodic chain.\n\nThe one way to construct the ground state is a cool trick.\nThink of every spin 1 as coming from 2 spin 1/2 systems,\nbut project onto the spin 1 subspace.\n\nThis is site $i$ for example,\nwould have two spin $\\frac{1}{2}$ systems,\nwhich I project onto spin-1 subspace.\nYou'll notice that in order for these two sites $i$ and $i=1$,\nthe only way this projector is going to give something non-trival\nis if every pair of spin-1/2 fuses into a state of spin-1.\n\nIf any two spin-$\\frac{1}{2}$ fuse to spin 0,\nthat subspace is going to be annihilated by this projector\n$P^{(2)}$.\n\nImagine if you had\n\\begin{align}\n    \\frac{1}{2}\\otimes \\frac{1}{2}\\otimes\n    \\frac{1}{2}\\otimes \\frac{1}{2}\n    =\n    (0 \\oplus 1) \\oplus (0 + 1)\n\\end{align}\nI can consider where these spin-1/2s from neighbouring parts fouse across.o\n\nconsider a state\nwhere each spin-1 you break down into spin-1/2s,\nand then project them onto spin1.\nAndthen you draw lines connecting adjacent spin-1/2s in different proejctors.\n\nIf you put this on a zero chain,\nyou won't hvae ege modé.o\n\nThe 0-energy ground state í the unique gapped grouned sate in AKLT.\n\nThis is a ``frustration free'' state.\nThere will be dangling spin-1/2 degrees of freedon.\nOn an open chin,\n\nJust likewe found we have anomalies for the boundaries,\nthis eges system is ano.\n\nSpin-1 degrese offreedom form faithful linear optaions of SO(3) symmetry,\nwherease spin-$\\frac{1}{2}$ is only a projection.\n\nThere will be dangling spin-$\\frac{1}{2}$ degrees of freedom.\nEdge degeneracy forms a projective representation of $SO(3)$.\nWahereas,\n\nThere's anomalies associated iwth global symemtries,\nand then there are graviational anomalies,\nand they are more severe.\nThe edges system is \n\nSome boudnary theories might be in conflict iwththe.\n", "meta": {"hexsha": "ac467bece8cc67213a7fc0a98a659878fde4cab8", "size": 21416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys733/lecture17.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/lecture17.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/lecture17.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": 31.5405007364, "max_line_length": 80, "alphanum_fraction": 0.7050336197, "num_tokens": 6774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6200673839705748}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{algorithm}\n\\usepackage{graphicx}\n\\usepackage[noend]{algpseudocode}\n\\usepackage{url}\n\n\\newlength\\tindent\n\\setlength{\\tindent}{\\parindent}\n\\setlength{\\parindent}{0pt}\n\\renewcommand{\\indent}{\\hspace*{\\tindent}}\n\n\\newtheorem{thm}{Theorem}\n\\newtheorem{cor}{Corollary}[thm]\n\\newtheorem{lemma}{Lemma}[thm]\n\n\\title{Knapsack Problem}\n\\author{Daniel Braithwaite}\n\n\\begin{document}\n\t\\pagenumbering{gobble}\n\t\\maketitle\n\t\\newpage\n  \t\\pagenumbering{arabic}\n  \t\n\t\\section{Dynamic Knapsack 0-1}  \n\t\t\\subsection{Algorithm}\n\t\t\n\t\t \tGiven a list of items $item_1,......item_n$, say we have a table T that in position T[i][j] stores the best solution's for packing items $item_1,....item_i$ into a bag with capacity j. We can use the following recurrence\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\tmax\n\t\t\t\t\\begin{cases}\n\t\t\t\t\tT[i-1][j]\\\\\n\t\t\t\t\tT[i-1][j-items[i].weight] + items[i].value\n\t\t\t\t\\end{cases}\n\t\t\t\\end{align}\t\t\t\t\n\t\t\n\t\t\t\\begin{algorithm}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\Procedure{dnamicKnapsack01}{$capacity, items$}\n\t\t\t\t\t\t\\State $T \\gets int[items.length][capacity+1]$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\For{$i = 0, i < items.length, i \\gets i+1$}\n\t\t\t\t\t\t\t\\For{$j = 0, j < capacity+1, j \\gets j+1$}\n\t\t\t\t\t\t\t\t\\State Fill out cell based on recurrence\n\t\t\t\t\t\t\t\\EndFor\n\t\t\t\t\t\t\\EndFor\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $solution \\gets [0....0]$ (n zeros)\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $i \\gets items.length-1$\n\t\t\t\t\t\t\\State $j \\gets capacity-1$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\While{$j > 0$} \\Comment{while we have available capacity} \n\t\t\t\t\t\t\t\\State Use recurrence to figure out what action we took to get this value\n\t\t\t\t\t\t\t\\If{We took item $i$ to get here}\n\t\t\t\t\t\t\t\t\\State $j \\gets items[i].weight$\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\\State $solution[i] \\gets 1$\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State $i \\gets i - 1$\n\t\t\t\t\t\t\\EndWhile\n\t\t\t\t\t\t\n\t\t\t\t\t\\EndProcedure\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{algorithm}\n\t\t\\subsection{Proof}\n\t\t\tWe want to work our way towards the recurrence we used in the dynamic programming algorithm. Say we have $n$ items we are trying to put into a bag of capacity $C$. Ether we put the $n^{th}$ item in the bag or we didn't. From this we get the following two sub problems.\n\t\t\t\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item \\textbf{We took the $n^{th}$ item:} Here we are solving the sub problem where we have items $item_1,.....,item_{n-1}$ and bag with capacity $C - item_n.weight$.\n\t\t\t\t\n\t\t\t\t\\item \\textbf{Didn't take $n^{th}$ item:} Here the sub problem is the items $item_1,.....,item_{n-1}$ and bag with capacity $C$.\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\tThis observation gives us our recurrence, now we need to show optimal sub structure for both of these cases\n\t\t\t\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Say we took the $n^{th}$ item. Let $S$ be set of items taken giving the optimal solution for this problem. Assume for a contradiction that $S - \\{item_n\\}$ isn't the optimal solution for the problem $item_1,.....,item_{n-1}$ with a bag of capacity $C - item_n.weight$. Let $S^\\prime$ be an optimal solution for this sub problem. But then we could take $S^\\prime$ and add $n$ back in. This would give us a better solution than $S$ for the whole problem. A contradiction!\n\t\t\t\t\n\t\t\t\t\\item Now say we didn't take the $n^{th}$ item. Let $S$ be the optimal selection of items. Assume for a contradiction that $S$ is not the optimal solution for the sub problem $item_1,.....,item_{n-1}$ with capacity $C$. But then we could take a better solution say $S^\\prime$, not choose the $n^{th}$ item and have a solution better than $S$. A contradiction!\n\t\t\t\\end{enumerate}\t\t\t\t\t\t\t\t\n\t\t\n\t\tNow we see the Knapsack 0-1 problem as optimal substructure. Now we must prove the algorithm is correct. First we look at filling out the table.\\newline\n\t\t\n\t\tFill out the table must be correct as we just proved the problem had optimal substructure using that recurrence. The last thing to show is that recovering the solution from the table is always correct.\\newline\n\t\t\n\t\tTo start this we see that this also uses the recurrence we defined to determine what action was taken. If an item was taken then we mark it as taken in the solution. With ether action we move back in the table to where that solution came from until we have $j$ at 0 which means that we have no more available capacity.\t\t\n\t\t\n\t\t\\subsection{Complexity}\t\t\n\t\t\t\\subsubsection{Filling Out Table}\n\t\t\t\tThe main part of the algorithm cost is here. The table is of size $weight * numItems$ and no matter the input data the whole table has to be filed out. The cost of using the recurrence is $O(1)$. Therefore the cost for filling out the table is\n\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\t\\theta(nC)\n\t\t\t\t\\end{align}\n\t\t\t\t\n\t\t\t\\subsubsection{Finding Solution}\n\t\t\t\tThe cost of this involves moving through the table and recovering the decisions at each point. Finding what decision was made is $O(1)$. At worst case you would be moving one square in the table at a time. Therefore finding the solution has cost\n\t\t\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\tO(n + C)\n\t\t\t\t\\end{align}\n\t\t\t\t\n\t\t\t\\subsubsection{Overall Cost}\n\t\t\t\tCombing the cost of the previous sections we see this algorithm has the following cost\n\t\t\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\t\\theta(nC)\n\t\t\t\t\\end{align}\n\t\t\n\t\t\\subsection{Testing}\n\t\t\tI plotted the lines for the best, average and worst case data this algorithm could encounter. I defined the worst case data to be as follows.\n\t\t\t\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item \\textbf{Best Case} is when reconstructing the solution we can just do it all in one step. So for this to happen we set all the item values and weights to be the same.\n\t\t\t\t\n\t\t\t\t\\item \\textbf{Worst Case} is when we take as many steps through the table as possible. To get this we set all the weights to be 1.\n\t\t\t\t\n\t\t\t\t\\item \\textbf{Average Case} is just randomly generated data\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\begin{figure}[h]\n\t\t\t\t\\vspace{3mm}\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\includegraphics[scale=0.4]{Dynamic.png}\n\t\t\t\t\\end{center}\n\t\t\t\\end{figure}\n\t\t\t\n\t\t\t\\break\n\t\t\t\n\t\t\tNo matter the input for this algorithm the dynamic programming table will have to be filled. The only thing that will cause a difference will be how long it will take to recover the solution. However this cost is minimal compared to the cost of computing the table. So for some input size $n$ if we have best, worst or average case data the number of steps will be almost identical for all of them. This is why you can only see one line, as they are all overlapping. All the lines fit perfect with the theoretical.\n\t\t\n\t\t\t\\break\t\t\t\n\t\t\n\t\\section{Brute Force Knapsack 0-N}\n\t\t\\subsection{Algorithm}\n\t\t\t\\begin{algorithm}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\Procedure{bruteforceKnapsack01}{$capacity, items$}\n\t\t\t\t\t\t\\State $w, b \\gets [0,.....,0]$ \\Comment{number of entries equals items.length}\n\n\t\t\t\t\t\t\\While{true}\n\t\t\t\t\t\t\t\\State $w[0] \\gets w[0] + 1$\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\For{index i in w} \\Comment{Handle when we are taking to much of an item}\n\t\t\t\t\t\t\t\t\\If{$w[i] > item_i.mutiplicity$}\n\t\t\t\t\t\t\t\t\t\\State $w[i] \\gets 0$\n\t\t\t\t\t\t\t\t\t\\State $w[i+1] \\gets w[i+1] + 1$\n\t\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\\EndFor\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\If{we have taken all of the last item} \\Comment{this is true if we have enumerated all possible solutions}\n\t\t\t\t\t\t\t\t\\State break\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State $weight \\gets$ weight of possible solution w\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\If{$weight \\leqslant capacity$}\n\t\t\t\t\t\t\t\t\\State Store solution in b if the value is better\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\\EndWhile\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\Return b\n\t\t\t\t\t\\EndProcedure\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{algorithm}\t\t\n\t\t\\subsection{Proof}\t\t\n\t\t\tThe brute force algorithm works by enumerating all the possible options and storing the one with the best value if its weight is less or equal to the capacity\n\t\t\\subsection{Complexity}\n\t\t\tThis algorithm has to enumerate all the possible combinations of items. No matter what the input data is (best, worst, average case) it will still have to enumerate all the solutions as it has no way of being able to tell if it has found the best one except for checking the all the remaining ones. We get the complexity to be \n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\theta(2^n)\n\t\t\t\\end{align}\n\t\t\t\n\t\t\\subsection{Testing}\n\t\t\tThere is no best, worst or average case, as discussed in \\textbf{2.3}. As such we only graphed the average case and the theoretical line. When graphing this we only ran it on very small data sets as it is a very inefficient algorithm.\n\t\t\t\n\t\t\t\\begin{figure}[h]\n\t\t\t\t\\vspace{3mm}\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\includegraphics[scale=0.4]{BruteForce.png}\n\t\t\t\t\\end{center}\n\t\t\t\\end{figure}\n\t\t\t\n\t\t\tAs you can see in the graph the average case line matches up perfectly with the theoretical line.\n\t\t\n\t\\section{Problem Conversion 0-N to 0-1}\n\t\tThe following 0-N algorithms will convert there 0-N knapsack problems to 0-1 problems. Here we will detail the algorithm for doing this with the cost. Rather than actually producing a new list of items and working with that we will create a mapping. Say our item list has size $n^\\prime$ and this list represents $n$ items. Then our mapping take numbers in the range 0 to n and map them to numbers between 0 and $n^\\prime$.\n\t\n\t\t\\break\t\n\t\t\t\t\n\t\t\\subsection{Algorithm}\n\t\t\t\\begin{algorithm}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\Procedure{createMapping}{$items$}\n\t\t\t\t\t\t\\State $mapping \\gets []$\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\\State $i \\gets 0, j \\gets 1, k \\gets 0$\n\t\t\t\t\t\t\\While{$k < items.length$}\n\t\t\t\t\t\t\t\\State itemMapping.map(i to k)\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\If{$j = items[k].multiplicity$}\n\t\t\t\t\t\t\t\t\\State $j \\gets 0$\n\t\t\t\t\t\t\t\t\\State $k \\gets k + 1$\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State $i \\gets i + 1$\n\t\t\t\t\t\t\t\\State $j \\gets j + 1$\n\t\t\t\t\t\t\\EndWhile\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\Return mapping\n\t\t\t\t\t\\EndProcedure\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{algorithm}\t\t\n\t\t\\subsection{Proof}\n\t\t\tFor each item passed in has a multiplicity (i.e. how many of that item we have) if we examine the algorithm we can clearly that it will create a mapping to an item item.multiplicity times. From this we see that the algorithm is correct.\n\t\t\t\n\t\t\\subsection{Cost}\n\t\t\tWe can clearly see that the loop is going to iterate exactly once for each of the $n$ items making the cost\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\theta(n)\n\t\t\t\\end{align}\t\t\t\t\n\t\t\n\t\t\\break\n\t\t\n\t\\section{Dynamic Knapsack 0-N}\n\t\t\\subsection{Algorithm}\n\t\t\tHere we can use our previous 0-1 knapsack algorithm to solve this one. We just need to create an algorithm to convert a 0-N knapsack problem to a 0-1 problem and then once solved convert the solution back. The key difference being that if we want to access item k then really what we are doing is accessing the item k is mapped to ($mapping[k]$).\n\t\t\n\t\t\t\\begin{algorithm}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\Procedure{dnamicKnapsack0N}{$capacity, items$}\n\t\t\t\t\t\t\\State $mapping \\gets createMapping(items)$\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $T \\gets int[mapping.length][capacity+1]$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\For{$i = 0, i < mapping.length, i \\gets i+1$}\n\t\t\t\t\t\t\t\\For{$j = 0, j < capacity+1, j \\gets j+1$}\n\t\t\t\t\t\t\t\t\\State Fill out cell based on recurrence\n\t\t\t\t\t\t\t\\EndFor\n\t\t\t\t\t\t\\EndFor\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $solution \\gets [0....0]$ \\Comment{items.length number of 0's}\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $i \\gets items.length-1$\n\t\t\t\t\t\t\\State $j \\gets capacity-1$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\While{$j > 0$} \\Comment{while we have available capacity} \n\t\t\t\t\t\t\t\\State Use recurrence to figure out what action we took to get this value\n\t\t\t\t\t\t\t\\If{We took item $i$ to get here}\n\t\t\t\t\t\t\t\t\\State $j \\gets items[mapping[i]].weight$\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\\State $solution[mapping[i]]$++\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State $i \\gets i - 1$\n\t\t\t\t\t\t\\EndWhile\n\t\t\t\t\t\\EndProcedure\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{algorithm}\n\t\t\\subsection{Proof}\n\t\t\tWe see this algorithm works by converting the 0-N knapsack problem into a 0-1 knapsack problem and uses the 0-1 dynamic algorithm to solve it. The solution is then converted back to 0-N format.\\newline\n\t\t\t\n\t\t\tWe know that the conversion to 0-1 format is correct, we also know that the dynamic algorithm for solving the 0-1 knapsack is correct. So all we need prove is that the conversion of the solution back to 0-N is correct.\\newline\n\t\t\t\n\t\t\tBy inspecting the algorithm we see that our solution has an entry for each of the original items. We are using the recurrence to determine if an item was taken as we traverse the table. If an item was taken then we need to figure out what one of the original items it maps to and increment our count of that original item in the solution. We know we are able to do this correctly because our mapping is correct. \n\t\t\\subsection{Complexity}\n\t\tThere are two parts for this algorithm we will explore the complexity for each of them and then we can come up with an overall complexity\n\t\t\t\n\t\t\\subsubsection{Solving The 0-1 Problem}\n\t\t\tWe already know the complexity of this and it is\n\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\theta(nC)\n\t\t\t\\end{align}\n\t\t\n\t\t\\subsubsection{Recovering Solution}\n\t\t\tThe complexity of recovering the solution is the same as it was in the 0-1 dynamic solution. We only changed how the items where accessed\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\O(n + C)\n\t\t\t\\end{align}\n\t\t\n\t\t\\subsubsection{Overall Complexity}\n\t\t\tThe dominating cost is still that  of solving the 0-1 Knapsack problem giving this algorithm\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\theta(nC)\n\t\t\t\\end{align}\n\t\t\t\n\t\t\t\\break\n\t\t\\subsection{Testing}\n\t\t\t\\textbf{Please Note:} For the testing of all the knapsack 0-N algorithms we used data where none of the items had a multiplicity over 1 (for simplicity). This \\textbf{wouldn't} effect the results as the conversion will still run and the rest of the algorithm will run for the same amount of time had there been less input items but the same total n items\\newline\t\t\n\t\t\n\t\t\tWe tested this data on the same type of best, average and worst case data as we did for the 0-1 dynamic knapsack and as expected got the same result. \n\t\t\t\n\t\t\t\\begin{figure}[h]\n\t\t\t\t\\vspace{3mm}\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\includegraphics[scale=0.4]{Dynamic0N.png}\n\t\t\t\t\\end{center}\n\t\t\t\\end{figure}\n\t\t\t\n\t\t\tWe can see that all the lines match up perfectly with the theoretical data\n\t\t\t\n\t\n\t\\break\t\t\t\n\n\t\\section{Graph Search Knapsack 0-N}\n\t\tTo start with we want to convert the 0-N problem to a 0-1 problem. This is so we can use a similar idea to the dynamic programming table\\footnote{\\url{http://courses.csail.mit.edu/6.006/fall11/rec/rec21_knapsack.pdf}}. Each node will be represented by the following triple $<i, j, value, previous>$ where $0 \\leqslant i \\leqslant numItems$ and $0 \\leqslant j \\leqslant capacity$ . The i and j mean the node contains the best solution for the items 0 to i-1 for a knapsack of capacity j.\\newline\\newline\n\t\t\n\t\tA node is connected to at most two others. Let $n$ be a node. The possibility's are ether we take item n.i or we don't. In the first case n is linked to a node where i = n.i + 1, and j = n.j + item[i] (as long as n.j + item[i] is $\\leqslant$ capacity. In the second case n is linked to the node where i = n.i + 1, and j = n.j. As we are building the graph we want to keep track of the current best value of each node, along with that we keep track of the previous node that was used to get this value.\n\t\t\n\t\tFor simplicity we will sometimes refer to a node as just <i,j>. Then we can refer to the value and previous node as <i,j>.value and <i,j>.previous\n\t\n\t\t\\subsection{Algorithm}\n\t\t\t\\begin{algorithm}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\Procedure{graphKnapsack0N}{$capacity, items$}\n\t\t\t\t\t\t\\State $items^\\prime \\gets convertTo01Problem(items)$\n\t\t\t\t\t\t\\State $fringe \\gets []$\n\t\t\t\t\t\t\\State add root node $<0, 0, 0, null>$\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\While{fringe is not empty}\n\t\t\t\t\t\t\t\\State $current \\gets node from fringe$\n\t\t\t\t\t\t\t\\State remove current from fringe\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\If{$current.i + 1 > items^\\prime$}\n\t\t\t\t\t\t\t\t\\State return to top of loop\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State get node $<current.i + 1,current.j>$ if it doesn't exist add it to fringe.\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\State update $<current.i + 1,current.j>$ if our current path to the node is better\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\If{there is enough available weight to take item j}\n\t\t\t\t\t\t\t\t\\State get node $<current.i + 1,current.j + items ^\\prime[i].weight>$ if it doesn't exist add it to fringe\n\t\t\t\t\t\t\t\t\\State update that node if there is a better path to it\n\t\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\\EndWhile\n\t\t\t\t\t\t\n\t\t\t\t\t\t\\State $solution \\gets [0,.....,0]$  \\Comment{same length as items}\n\t\t\t\t\t\\EndProcedure\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{algorithm}\n\t\t\n\t\t\\break\n\t\t\\subsection{Proof}\n\t\t\tWe will need to prove two things for this algorithm to be correct. First being that our method of generating the graph will explore all the possibility's. Second we need to show that we can recover the best path through the graph, thus giving us the optimal solution and finally show that the part of the algorithm that recovers the solution also correctly converts it back to a 0-N solution.\t\\newline\t\n\t\t\n\t\t\tWe think of nodes as representing a sub problem. For example the node $<2, 5>$ is saying we have considered the items 0 and 1, and that we have used up 5 of our total capacity. From here we have two choices ether we take item 2 (taking item 2 also depends on weather we have enough spare capacity) or we don't take item $i$. Meaning there is an edge between $<2, 5>$ and the nodes $<3, 5>$ and $<3, 5 + 1>$ (assuming the weight of item 2 is 1). If we make this more general and apply it to some node $<i, j>$ then clearly we are searching all the possible combinations. So if we store the node with the best value as we are building this binary tree then by the end we clearly will have a node that holds the best possible value\\newline\n\t\t\t\n\t\t\tNow we have a node that can tell us the best value possible when trying to put all these items into a back with a known capacity. But what we are really interested in is the combination of items. As we are building the graph when we link two nodes with an edge, say  $n$ to $n^\\prime$, we examine the current value of $n^\\prime$ and see if the value of $n$ (plus the value of item $n.i$ we are taking it) is greater than it. If it is then we store $n$ as the previous node in $n^\\prime$. We do this for all nodes so at the end we can just step back through the tree starting from the best node giving us the solution.\\newline\n\t\t\t\n\t\t\tFinally we look at the part of the code that recovers the solution. This starts at the node in the graph that has the best value stepping back though the nodes using the previous value. At any iteration in the loop we have a node $n$ and the one before it $n_p$. We compare $n.j$ and $n_p.j$ if they are equal then we didn't take an item so just set $n$ to $n_p$. If they are not equal then we update the solution by using our mapping $solution[mapping[n_p.i]]$++. We increment the item $n_p.i$ as moving from $n_p$ to $n$ meant we where acting on the item $n_p.i$. This clearly gives us a 0-N solution that is correct.\n\t\t\t\n\t\t\\subsection{Complexity}\n\t\t\tThis algorithm has two components that we will explore separately.\n\t\t\t\n\t\t\t\\subsubsection{Constructing The Graph}\n\t\t\t\tWe can think of constructing the graph as traversing all the nodes in the graph. Which at worst case there will be as many nodes as there are cells in the dynamic programming table. However the key thing to note is that this is at worst, there often will be less nodes than this. Giving us the following complexity where n is the number of items (that is not the number of items in the input array but the sum of there multiplicity's) and C is the total capacity of the bag \n\t\t\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\tO(nC)\n\t\t\t\t\\end{align}\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\\subsubsection{Finding The Solution}\n\t\t\t\tAt any node we know that it is connected to at most 2 nodes, there for what we generated is a binary tree. We also know the two following things. That there is going to be at most n + 1 layers (one for every possible value of i, $0 \\leqslant i \\leqslant n$). The second thing we know that as we are recovering the solution we are only stepping back through the tree. Therefore at worst we will have to step though the height of the tree giving us the complexity\n\t\t\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\tO(n+1)\n\t\t\t\t\\end{align}\n\t\t\t\n\t\t\t\\subsubsection{Overall Complexity}\n\t\t\t\tThe dominating cost of the algorithm is that of constructing the graph so we get the algorithm complexity to be   \n\t\t\t\t\n\t\t\t\t\\begin{align}\n\t\t\t\t\tO(nC)\n\t\t\t\t\\end{align}\t\n\t\t\t\t\n\t\t\\subsection{Testing}\n\t\t\tThe graph below displays the best, average and worst case for the graph search algorithm, we defined these as follows.\n\t\t\t\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item \\textbf{Best Case} is when we can construct the graph with only having one layer. If we set all the items to have a capacity that will consume all available space we can get this.\n\t\t\t\t\n\t\t\t\t\\item \\textbf{Worst Case} is when we set each of the items to have a different weight, so for example for a set of 3 items we have $item_1.weight = 1, item_2.weight = 2,item_3.weight = 3$. This will give us the most possible nodes without much overlap. If we chose to do the same worst case data as we did for the dynamic programming we would do better than average as there would be a lot of overlap between nodes.\n\t\t\t\t\n\t\t\t\t\\item \\textbf{Average Case} is just randomly generated data\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\begin{figure}[h]\n\t\t\t\t\\vspace{3mm}\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\includegraphics[scale=0.4]{Graph0N.png}\n\t\t\t\t\\end{center}\n\t\t\t\\end{figure}\n\t\t\t\t\t\n\t\t\tAs we see in the graph this is much more varied than the other algorithms. The best case is very different from the average and worst case which are quite close together. However they are all less than the theoretical line which I graphed as $n*C + n + 1$ as this is the maximum number of steps the algorithm can take.\t\t\n\t\t\t\n\t\t\t\n\t\\section{Graph Search vs Dynamic}\n\t\tIf we examine the order costs of the algorithm we would expect that the graph search would out perform the dynamic algorithm, or atleast perform the same as it. The graph search algorithm has a complexity of $O(nC)$ meaning it is bounded from above by $nC$. Compared to the complexity of the dynamic algorithm $\\theta(nC)$ meaning it is bounded from above and below by $nC$.\\newline\n\n\t\tIf we examine the algorithms more closely we can also see this as noted in the dynamic algorithm complexity section the algorithm will always have to fill out the entire table no matter the input data. We also noted previously that in the graph search it was only worst case where we would have to traverse $nC$ number of nodes. \\newline\t\t\n\t\t\n\t\tWe can conclude from this that the graph search algorithm will perform at most $nC$ steps where as the dynamic algorithm will always perform $nC$ steps.\\newline\n\t\t\n\t\tWe can also examine the cost of reconstructing the solution for each of the algorithms. Even here the graph search algorithm is faster, with a complexity of $O(n + 1)$ compared to the dynamic algorithm where recovering the solution is $O(n + C)$. \\newline\n\t\t\n\t\tWith this in mind we compare the best case of the dynamic algorithm and the worst case of the graph search.\n\t\t\n\t\t\\begin{figure}[h]\n\t\t\t\\vspace{3mm}\n\t\t\t\\begin{center}\n\t\t\t\t\\includegraphics[scale=0.4]{DynamicGraphComparason.png}\n\t\t\t\\end{center}\n\t\t\\end{figure}\n\t\t\n\t\tAs we can see in the graph the graph search algorithm clearly out performs the dynamic algorithm.\n\t\t\n  \t\t\t\n\\end{document}", "meta": {"hexsha": "8628cf72c146c571f73feed9e823f01c69c8c1e9", "size": 23027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Undergraduate/COMP361/Assignment 3/Report/report.tex", "max_stars_repo_name": "danielbraithwt/University", "max_stars_repo_head_hexsha": "50c6a904e1c53c03bce9928975607c35fd741e33", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Undergraduate/COMP361/Assignment 3/Report/report.tex", "max_issues_repo_name": "danielbraithwt/University", "max_issues_repo_head_hexsha": "50c6a904e1c53c03bce9928975607c35fd741e33", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-12-09T00:17:19.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-09T00:28:42.000Z", "max_forks_repo_path": "Undergraduate/COMP361/Assignment 3/Report/report.tex", "max_forks_repo_name": "danielbraithwt/University", "max_forks_repo_head_hexsha": "50c6a904e1c53c03bce9928975607c35fd741e33", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-23T23:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-23T23:02:31.000Z", "avg_line_length": 53.3032407407, "max_line_length": 739, "alphanum_fraction": 0.6973552786, "num_tokens": 6301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225279, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.6200673762614931}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\usepackage{igor_macros}\n\n%%No paragraph break on emty lines\n\\catcode10=10   \\catcode13=10\n\n%\\def\\ee{\\end{equation}}\n\n\\title {Deduction of Hamilton-Jakoby equation}\n\\author {Igor Bukanov}\n\\date { 08 February 1999 }\n\n\\begin{document}\n\n\\begin{abstract}\nI present strict deduction of Hamilton-Jakoby eqution and corresponding\napproach for solving equation of motion. I decided to write this due to\nuneasy feeling that Landau-Lifshic Mechanics left to me. In any case it \nwas  useful exercise.\n\\end{abstract}\n\n\\maketitle\n\n\\section{Definitions and deduction}\nConsider the standard expression for the action of a classical system\ngiven by\n\\eqgl{\n\\l{S-def}\nS = \\int_0^T L[\\vec{\\dot{q}}(t), \\vec{q}(t), t] dt, \\\\\n\\l{init-cond}\n\\vec{q}(0) = \\vec{q_0}, \\, \\vec{q}(T) = \\vec{q_1},  \\\\\n\\vec{q} \\equiv q_1 \\dots q_N, \\notag\n}\nwhere $N$ stands for the number of degree of freedom.\n\nThe corresponding Lagrange equations of motion are\n\\eqnl{L-eqn}{\n\\frac{\\partial L}{\\partial q^i}\n    = \\frac{d}{dt}\\frac{\\partial L}{\\partial \\dot{q}^i}\n}\n\nA solution of (\\ref{L-eqn}) that satisfy the initial conditions \n\\rf{init-cond} maybe formally written in the following form,\n\\eqgl{\n\\vec{q} = \\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1), \\, \\notag \\\\\n\\vec{q}(0, T, \\vec{q}_0, \\vec{q}_1) = \\vec{q}_0, \\, \\l{formal-solution} \\\\\n\\vec{q}(T, T, \\vec{q}_0, \\vec{q}_1) = \\vec{q}_1 . \\notag\n}\n\nThe form \\rf{formal-solution} provides minimal or at least extremal action,\nthat is a function of initial conditions \\rf{init-cond} and time interval $T$,\n\n\\eqnl{S-min-def}{\nS_{min} \\equiv S_{min}(T, \\vec{q_0}, \\vec{q_1})\n    = \\int_0^T L[\\vec{\\dot{q}}(t, T, \\vec{q}_0, \\vec{q}_1), \n                 \\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1), t] dt\n}\n\nWith \\rf{S-min-def} in hands I can start deduction of a equation for $S_{min}$\nitself. In the following I assume $S \\equiv S_{min}$.\n\n\\par\nI calculate time derivative for it as a derivative of parametric\nintegral ,\n\\eqnl{der-S-a}{\n\\frac{\\partial S}{\\partial T} \n    = \\left.L[\\vec{\\dot{q}}, \\vec{q}, t)\\right|_{t=T}\n    + \\int_0^T \\frac{\\partial}{\\partial T} L[\\vec{\\dot{q}}, \\vec{q}, t] dt .\n}\n\nTo father transform \\rf{der-S-a} I consider a general expression of the form\n\\eqn{\nF(a) =\n\\int_0^T dt \n    \\frac{\\partial}{\\partial a} L[\\vec{\\dot{q}}(t, a), \\vec{q}(t, a), t]\n}\nwith some arbitrary parameter $a$. I have\n\\eqn{\nF(a) = \n\\int_0^T dt \\left\\lbrace\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\\frac{\\partial\\vec{\\dot{q}}}{\\partial a}\n+ \\frac{\\partial L}{\\partial\\vec{q}}\\frac{\\partial\\vec{q}}{\\partial a}\n\\right\\rbrace .\n}\n\nBut \n\\eqn{\n\\frac{\\partial\\vec{\\dot{q}}}{\\partial a} \n    \\equiv \\frac{\\partial}{\\partial a}\\frac{\\partial}{\\partial t}\\vec{q}(t, a) \n    = \\frac{\\partial}{\\partial t}\\frac{\\partial}{\\partial a}\\vec{q}(t, a) \n}\nunder the assumtion that $\\vec{q}(t, a)$ is smoth enough to permit interchange\nof the differention order. This gives\n\\eqn{\n\\begin{split}\nF(a) &= \n\\int_0^T dt \\left\\lbrace\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\\frac{\\partial}{\\partial t}\n\\frac{\\partial\\vec{q}}{\\partial a}\n+ \\frac{\\partial L}{\\partial\\vec{q}}\\frac{\\partial\\vec{q}}{\\partial a}\n\\right\\rbrace . \\\\\n&= \n\\int_0^T dt \\left\\lbrace\n\\frac{\\partial}{\\partial t}\\left[\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n\\frac{\\partial\\vec{q}}{\\partial a}\\right]\n+ \\frac{\\partial L}{\\partial\\vec{q}}\\frac{\\partial\\vec{q}}{\\partial a}\n- \\frac{\\partial}{\\partial t}\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n    \\frac{\\partial\\vec{q}}{\\partial a}\n\\right\\rbrace . \\\\\n&= \n\\left.\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n\\frac{\\partial\\vec{q}}{\\partial a}\\right|_{t=0}^T\n+\n\\int_0^T dt \\frac{\\partial\\vec{q}}{\\partial a} \\left\\lbrace\n\\frac{\\partial L}{\\partial\\vec{q}}\n- \\frac{\\partial}{\\partial t}\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n\\right\\rbrace . \\\\\n\\end{split}\n}\n\nAssuming now that $\\vec{q}$ satisfies the Lagrange equations \\rf{L-eqn},\nthe second term in the last expression gives 0 and I have\n\\eqgl{\n\\l{param-derivative}\n\\int_0^T \\frac{\\partial}{\\partial a} L[\\vec{\\dot{q}}(t, a), \\vec{q}(t, a), t] dt\n= \n\\left.\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n\\frac{\\partial\\vec{q}}{\\partial a}\\right|_{t=0}^T ,\n\\\\\n\\vec{\\dot{q}}(t, a) \\equiv \n\\left.\\frac{\\partial\\vec{q}}{\\partial t}\\right|_a \\notag\n}\n\nWhen $a \\equiv T$ the last equation gives for \\rf{der-S-a}\n\\eqn{\n\\int_0^T dt \n    \\frac{\\partial}{\\partial T} L[\\vec{\\dot{q}}(t, T), \\vec{q}(t, T), t]\n= \n\\left.\n\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n\\frac{\\partial\\vec{q}}{\\partial T}\\right|_{t=0}^T ,\n}\nand finally I have for \\rf{der-S-a}\n\\eqnl{der-S-b}{\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial T} \n    = \\left. L[\\vec{\\dot{q}}, \\vec{q}, t]\\right|_{t=T}\n    + \\left.\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n      \\frac{\\partial\\vec{q}}{\\partial T}\\right|_{t=0}^T .\n}\n\nNow I take into account that\n\\eqnl{L-at-second-edge}{\n\\begin{split}\n\\left. L[\\vec{\\dot{q}}, \\vec{q}, t]\\right|_{t=T}\n&\\equiv \\left. L[\\vec{\\dot{q}}(t, T, \\vec{q}_0, \\vec{q}_1), \n \\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1), t]\n\\right|_{t=T}\n\\\\\n&= L[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \n    \\vec{q}(T, T, \\vec{q}_0, \\vec{q}_1), T]\n\\\\ \n&= L[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \\vec{q}_1, T]\n\\end{split}\n}\n\nfrom the boundary condition \\rf{formal-solution}, \n$\\vec{q}(T, T, \\vec{q}_0, \\vec{q}_1) = \\vec{q}_1$.\n\\par\n\nFrom the same condition it is also follows \n\\eqn{\n\\frac{\\partial}{\\partial T}\n\\vec{q}(t=T, T, \\vec{q}_0, \\vec{q}_1)\n=\n\\frac{\\partial \\vec{q}_1}{\\partial T}\n=\n\\left.\\frac{\\partial}{\\partial t}\n\\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=T}\n+\n\\left.\\frac{\\partial}{\\partial T}\n\\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=T} ,\n}\nbut $\\frac{\\partial \\vec{q}_1}{\\partial T} \\equiv 0$ because \nthe boundary conditions themself are not depend on $T$, so\n\n\\eqn{\n0 =\n\\left.\\frac{\\partial}{\\partial t}\n\\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=T}\n+\n\\left.\\frac{\\partial}{\\partial T}\n\\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=T} .\n}\nIn the same way \n\\eqn{\n0 \\equiv \\frac{\\partial \\vec{q}_0}{\\partial T} \n= \\frac{\\partial}{\\partial T}\n\\vec{q}(t=0, T, \\vec{q}_0, \\vec{q}_1)\n=\n\\left.\\frac{\\partial}{\\partial T}\n\\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=0} .\n}\nThis gives for \\rf{der-S-b} \n\\eqnl{der-S-c}{\n\\begin{split}\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial T} \n&= \nL[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \\vec{q}_1, T]\n- \\left.\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\n  \\frac{\\partial}{\\partial t}\n  \\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1)\\right|_{t=T}\n\\\\ &\\equiv\nL[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \\vec{q}_1, T]\n- \\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1)\n\\frac{\\partial }{\\partial\\vec{\\dot{q}}} \nL[\\vec{\\dot{q}}, \\vec{q}_1, T]\n  \n\\end{split}\n}\n\nNow I consider ${\\partial S}/{\\partial \\vec{q}_1}$.\n\\eqn{\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial \\vec{q}_1}\n = \\int_0^T \\frac{\\partial}{\\partial \\vec{q}_1}\n     L[\\vec{\\dot{q}}(t, T, \\vec{q}_0, \\vec{q}_1), \n                 \\vec{q}(t, T, \\vec{q}_0, \\vec{q}_1), t] dt\n \n}\n\nFrom \\rf{param-derivative} with $a \\equiv \\vec{q}_1$ I get\n\\eqn{\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial \\vec{q}_1}\n=\n\\left.\\frac{\\partial L}{\\partial\\dot{q^i}}\n\\frac{\\partial q^i}{\\partial \\vec{q}_1}\\right|_{t=0}^T \n\\equiv\n\\left.\\frac{\\partial L}{\\partial\\dot{q^i}}\n\\frac{\\partial}{\\partial \\vec{q}_1}q^i(t, T, \\vec{q}_0, \\vec{q}_1)\n\\right|_{t=0}^T .\n}\n\nUsing the boundary conditions in \\rf{formal-solution} one more time I have\n\\eqn{\n\\left.Y(t)\\frac{\\partial}{\\partial q^j_1}q^i(t, T, \\vec{q}_0, \\vec{q}_1)\n\\right|_{t=0}^T \n= \nY(T)\\frac{\\partial q^i_1}{\\partial q^j_1} \n    - Y(0)\\frac{\\partial q^i_0}{\\partial q^j_1}\n= \nY(T)\\delta^i_j - 0 = Y(T)\\delta^i_j .\n}\n\nThus \n\\eqnl{der-S-d}{\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial \\vec{q}_1}\n= \n\\left.\\frac{\\partial L}{\\partial\\vec{\\dot{q}}}\\right|_{t=T} ,\n}\n\nEquations \\rf{der-S-c} and \\rf{der-S-d} together form a closed system\n\\eqnl{S-der-system}{\n\\left\\lbrace\n\\begin{split}\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial T} \n&= \nL[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \\vec{q}_1, T]\n- \\dot{q^i}(T, T, \\vec{q}_0, \\vec{q}_1)\n    \\frac{\\partial }{\\partial\\dot{q^i}} \n    L[\\vec{\\dot{q}}, \\vec{q}_1, T]\n\n\\\\\n\\frac{\\partial S(T, \\vec{q}_0, \\vec{q}_1)}{\\partial \\vec{q}_1}\n&= \\frac{\\partial}{\\partial\\vec{\\dot{q}}}\n    L[\\vec{\\dot{q}}(T, T, \\vec{q}_0, \\vec{q}_1), \\vec{q}_0, \\vec{q}_1)]\n\\end{split}\n\\right.\n}\n\nor simply\n\\eqnl{S-der-system-b}{\n\\left\\lbrace\n\\begin{split}\n\\frac{\\partial S(T, \\vec{q}_1)}{\\partial T} \n&= \nL[\\vec{\\dot{q}}, \\vec{q}_1, T]\n- \\dot{q}^i \\partial_{\\dot{q}^i}L [\\vec{\\dot{q}}, \\vec{q}_1, T]\n\\\\\n\\frac{\\partial S(T, \\vec{q}_1)}{\\partial q^i_1}\n&= \n\\partial_{\\dot{q}^i}L[\\vec{\\dot{q}}, \\vec{q}_1, T]\n\\end{split}\n\\right. ,\n}\nwhere I skiped a dependence of $S$ on $\\vec{q}_0$, which reflects the fact\nthat a general solution of \\rf{S-der-system-b} will include some constants\n$C_\\alpha$, that assume dependence on $\\vec{q}_0$\n\nFrom a pure algebraic point of view I can use the second equation \nin \\rf{S-der-system-b} to expres $\\vec{\\dot{q}}$ as a function of\n$\\vec{q}_1$, $T$ and $\\frac{\\partial S}{\\partial \\vec{q}_1}$:\n\\eqn{\n\\vec{\\dot{q}} = \n    \\vec{\\dot{q}}(\\vec{q}_1, T, \\frac{\\partial S}{\\partial \\vec{q}_1})\n}\n\n[ Note: I skipped completely the issue about the existence of such solution.]\n\nThis gives from \\rf{S-der-system-b} the single partial differencal equation \nfor $S$ as a function of $\\vec{q}_1$ and $T$,\n\\eqnl{S-eqn}{\n\\begin{split}\n\\frac{\\partial S(T, \\vec{q}_1)}{\\partial T}\n= &   \nL[\\vec{\\dot{q}}(\\vec{q}_1, T, \n    \\frac{\\partial S(T, \\vec{q}_1)}{\\partial \\vec{q}_1}), \n    \\vec{q}_1, T]\n\\\\\n& - \\dot{q}^i(\\vec{q}_1, T, \n        \\frac{\\partial S(T, \\vec{q}_1)}{\\partial \\vec{q}_1})\n \\frac{\\partial S(T, \\vec{q}_1)}{\\partial q^i_1}\n\\end{split}\n}\n\nThe equation \\rf{S-eqn} is called Hamilton-Jakoby equation. \nIt is the first order partial non-linear differential equation. \nIn short I can write it as \n\\eqnl{JH-eqn}{\n\\frac{\\partial S(T, \\vec{q})}{\\partial T}\n=    \nL[\\vec{\\dot{q}}, \\vec{q}, T]\n - \\frac{\\partial S(T, \\vec{q})}{\\partial q^i} \\dot{q}^i\n}\n\nwhere $\\vec{\\dot{q}} = \\vec{\\dot{q}}(\\partial_{\\vec{q}}S, T, q)$ \ncan be considered as a symbol representing a function\n obtained from the solution of the algebraic system\n\\eqnl{JH-qdot}{\n\\frac{\\partial S(T, \\vec{q})}{\\partial q^i}\n= \n\\partial_{\\dot{q}^i}L[\\vec{\\dot{q}}, \\vec{q}, T]\n}\n\n\\par \n\nNow comes technically more difficult in my opinion part to \ndeduce the solution of the equation of motion \\rf{L-eqn} from \nthe solution of the JH-equation \\rf{JH-eqn}.\n\n\\par\n\nAs for a first-oder partial differncial equation for $S$ in $N+1$ space, \nthe general solution of \\rf{JH-eqn} can be written as function\nof $T$, $\\vec{q}$ and $N + 1$ constants $\\vec{\\alpha}$ and $\\alpha_0$:\n\\eqn{\n    S = \\tilde{S}(T, \\vec{q}, \\vec{\\alpha}) + \\alpha_0,\n}\nwhere $\\alpha_0$ is written explicitly as additive constant. \nIt is possible because $S$ is present in \\rf{JH-eqn} only via\nits patial derivatives $\\partial_T S$ and $\\partial_{\\vec{q}} S$.\n\n\\par\nIn the following the value of $\\alpha_0$ is not important and for \nthis reason I simply assume that\n\\eqnl{S-is-T-q-alpha}{\n    S = S(T, \\vec{q}, \\vec{\\alpha}).\n}\n\nI define \n\\eqnl{beta-definition}{\n    \\vec{\\beta}(T, \\vec{q}, \\vec{\\alpha}) = \\frac{\\partial S}{\\partial \\alpha}.\n}\n\nThis definition also can be seen as introduction of new coordinates \n$T$, $\\vec{\\beta}$, $\\vec{\\alpha}$ instead of the set \n$T$, $\\vec{q}$, $\\vec{\\alpha}$. I will assume in the following that \n\\rf{beta-definition} can be resolved with respect to $\\vec{q}$. \n[Warning: under what condition this can be true?] I.e. I can assume\nthat \n\\eqn{\n    \\vec{q} = \\vec{q}(T, \\vec{\\beta}, \\vec{\\alpha})\n        \\equiv \\vec{q}(T, \\frac{\\partial S}{\\partial \\alpha}, \\vec{\\alpha}).\n}\n\nWith this definitions/assumesiones in hands I differenciate \\rf{JH-eqn}\nwith respect to $\\alpha$,\n\\eqn{\n\\begin{split}\n\\frac{\\partial^2 S}{\\partial \\vec{\\alpha} \\partial T}\n & = \\frac{\\partial^2 S}{\\partial T \\partial \\vec{\\alpha}}\n\\\\ & \n\\equiv \\frac{\\partial \\vec{\\beta}}{\\partial T}\n= \\frac{\\partial}{\\partial \\vec{\\alpha}}\n    L[\\vec{\\dot{q}}(\\partial_{\\vec{q}}S(T, \\vec{q}, \\vec{\\alpha}), T, q), \n        \\vec{q}, T]\n-\n\\frac{\\partial}{\\partial \\vec{\\alpha}}\\left\\lbrace \n \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i} \\dot{q}^i\n\\right\\rbrace\n\\\\ & \n= \\frac{\\partial L}{\\partial \\dot{q}^i}\n\\frac{\\partial \\dot{q^i}}{\\partial \\vec{\\alpha}}\n-\\frac{\\partial^2 S}{\\partial \\vec{\\alpha} \\partial q^i}\\dot{q}^i\n-\\frac{\\partial S}{\\partial q^i} \n    \\frac{\\partial \\dot{q}^i}{\\partial \\vec{\\alpha}}\n\n= \n\\frac{\\partial S}{\\partial q^i} \n    \\frac{\\partial \\dot{q}^i}{\\partial \\vec{\\alpha}}\n-\\frac{\\partial^2 S}{\\partial \\vec{\\alpha} \\partial q^i}\\dot{q}^i\n-\\frac{\\partial S}{\\partial q^i} \n    \\frac{\\partial \\dot{q}^i}{\\partial \\vec{\\alpha}}\n\\end{split},\n}\nor \n\\eqnl{beta-over-T}{\n\\left.\\frac{\\partial \\vec{\\beta}}{\\partial T}\\right|_{\\alpha\\vec{q}}\n\\; = \\; -\\frac{\\partial^2 S}{\\partial \\vec{\\alpha} \\partial q^i}\\dot{q}^i\n\\; = \\; \n-\\left.\\frac{\\partial\\vec\\beta}{\\partial q^i}\n  \\right|_{\\alpha T}\\dot{q}^i \n}\n\nwhere I used \\rf{JH-qdot} to replace \n$\\partial_{\\dot{q}^i}L[\\vec{\\dot{q}}, \\vec{q}, T]$ by \n$\\partial_{q^i}S$.\n\n\\par\n\nI must note here that $\\dot{\\vec{q}}$ in \\rf{beta-over-T} is just a symbol\nthat denote a function defined as the solution of \n\\rf{JH-qdot}, i.e. it just represents some function of $T$, $\\beta$,\n$\\alpha$:\n\\eqn{\n\\vec{\\dot{q}}\n = \n\\vec{\\dot{q}}(\\partial_{\\vec{q}}S(\\vec{q}, T, \\vec{\\alpha}), T, q)\n=\n\\vec{\\dot{q}}(\\partial_{\\vec{q}}S(\\vec{q}(T, \\vec{\\beta}, \\vec{\\alpha}), \n  T, \\vec{\\alpha}), T, q(T, \\vec{\\beta}, \\vec{\\alpha}))\n}\n\n\\par\nNow I return to the interpretation of \\rf{beta-definition} as a non-explicit\ndefinition of function $\\vec{q}(\\vec{\\beta}, T, \\vec{\\alpha})$. I will show \nthat with fixed $\\vec{\\beta}$, $\\vec{\\alpha}$ this function $\\vec{q}$ as\nfunction of $T$ satisfies the equation of motion \\rf{L-eqn}. Indeed, I have\nfor \n\\eqn{\n\\left.\\frac{\\partial{q}}{\\partial{T}}\\right|_{\\beta\\alpha} \n\\; \\equiv \\;\n\\vec{q}_T\n}\nfrom $\\vec{\\beta} = \\vec{\\beta}(\\vec{q}, T, \\vec{\\alpha})$:\n\n\\eqnl{q-dot-q-T-deduction}{\n\\begin{split}\n0 & = \n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial T}\n(\\vec{q}, T, \\vec{\\alpha})\\right|_{\\alpha\\beta}\n\\; = \\;\n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial q^i}\\right|_{\\alpha T}\n\\left.\\frac{\\partial q^i}{\\partial T}\\right|_{\\alpha\\beta} \n+ \n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial T}\n\\right|_{\\alpha\\vec{q}}\n\\\\ & =\n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial q^i}\\right|_{\\alpha T}\nq^i_T\n+ \n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial T}\n\\right|_{\\alpha\\vec{q}}\n\\; = \\;\n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial q^i}\\right|_{\\alpha T}\nq^i_T\n-\\left.\\frac{\\partial\\vec\\beta}{\\partial q^i}\n  \\right|_{\\alpha T}q^i_T\\dot{q}^i \n\\\\ & =\n\\left.\\frac{\\partial\\vec{\\beta}}{\\partial q^i}\\right|_{\\alpha T}\n\\left(q^i_T - \\dot{q}^i\\right)\n\\end{split}\n}\n\n\\par\nAssuming that the matrix\n$\\frac{\\partial\\vec{\\beta}}{\\partial q^i} \n\\equiv \\frac{\\partial\\beta^j}{\\partial q^i}$ has non-zero determinant\n[ I need to refer to a proper mathematics for exact reasons ]\nI multiply \\rf{q-dot-q-T-deduction} by \n$\\left(\\frac{\\partial\\beta^j}{\\partial q^i}\\right)^{-1}$ which gives\n\\eqnl{q-dot-is-q-T}{\n\\dot{q}^i = q^i_T \n\\equiv \\left.\\frac{\\partial{q^i}}{\\partial{T}}\\right|_{\\alpha\\beta} .\n} \n\nThat is, an abstract symbol $\\dot{\\vec{q}}$ is equal to the partial derivative\n$\\vec{q}_T$. This in turns means from \\rf{JH-qdot} that $\\vec{q}_T$ satisfies\n\\eqnl{JH-qdot-alpha}{\n\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n= \n\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T].\n}\n\nI differenciate the last equation over T to get\n\\eqn{\n\\begin{split}\n\\frac{d}{d T}\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T]\n& \\equiv  \n\\left.\\frac{\\partial}{\\partial T}\\right|_{\\alpha \\vec{\\beta}}\n\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T]\n\\; = \\;\n \\left.\\frac{\\partial}{\\partial T}\\right|_{\\alpha\\vec{\\beta}} \n  \\left.\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n    \\right|_{\\alpha T}\n\\\\\n& = \\left.\\frac{\\partial}{\\partial T}\\right|_{\\alpha\\vec{q}} \n  \\left.\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n    \\right|_{\\alpha T}\n+ \t\n\\left.\\frac{\\partial}{\\partial q^j}\\right|_{\\alpha T} \n  \\left.\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n    \\right|_{\\alpha T}\n  \\left.\\frac{\\partial q^j}{\\partial T}\\right|_{\\alpha \\vec{\\beta}} \t\t\n\\\\\n& =  \\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha T}\n  \\left\\{L[\\vec{\\dot{q}}, \\vec{q}, T]\n - \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j} \\dot{q}^j\n    \\right\\} \n\\\\\n& \\phantom{ = }\n+\n\\left.\\frac{\\partial}{\\partial q^j}\\right|_{\\alpha T} \n  \\left.\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n    \\right|_{\\alpha T}\n  q^j_T\n\\end{split}\n}\n\ndue to \\rf{JH-eqn}, thus\n\n\\eqn{\n\\begin{split}\n\\frac{d}{d T}\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T]\n& =  \\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha T}\n  \\left\\{L[\\vec{q_T}, \\vec{q}, T]\n - \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j} q_T^j\n    \\right\\} \n\\\\\n& \\phantom{ = }\n\n+\n\\left.\\frac{\\partial}{\\partial q^j}\\right|_{\\alpha T} \n  \\left.\\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i}\n    \\right|_{\\alpha T}\n  q^j_T\n\\\\\n& =  \\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha T}\n  L[\\vec{q_T}, \\vec{q}, T]\n - \\frac{\\partial^2 S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^i \\partial q^j} \n    q_T^j\n -  \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j}   \n    \\frac{\\partial q_T^j} {\\partial q^i }\n\\\\\n& \\phantom{ = }\n+\n\\frac{\\partial^2 S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j \\partial q^i}\n  q^j_T\n\n\\\\\n& =  \\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha T}\n  L[\\vec{q_T}, \\vec{q}, T]\n -  \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j}   \n    \\frac{\\partial q_T^j} {\\partial q^i }\n\n\\\\\n& =  \n\\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha \\vec{q}_T}\n  L[\\vec{q_T}, \\vec{q}, T]\n\n+\n\\left.\\frac{\\partial}{\\partial q_T^j}\\right|_{\\alpha \\vec{q}}\n  L[\\vec{q_T}, \\vec{q}, T] \n\\left.\\frac{\\partial q_T^j}{\\partial q^i}\\right|_{\\alpha T}\n\\\\\n& \\phantom{ = }\n\n -  \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j}   \n    \\frac{\\partial q_T^j} {\\partial q^i }.\n\n\\end{split}\n}\n\nUsing \\rf{JH-qdot-alpha} one more time I finally have\n\\eqn{\n\\begin{split}\n\\frac{d}{d T}\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T]\n& =  \n\\left.\\frac{\\partial}{\\partial q^i}\\right|_{\\alpha \\vec{q}_T}\n  L[\\vec{q_T}, \\vec{q}, T]\n\n+  \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j}   \n    \\frac{\\partial q_T^j} {\\partial q^i }.\n\\\\\n& \\phantom{ = }\n -  \\frac{\\partial S(T, \\vec{q}, \\vec{\\alpha})}{\\partial q^j}   \n    \\frac{\\partial q_T^j} {\\partial q^i }.\n\n\\end{split}\n}\n\nor simply\n\\eqn{\n\\frac{d}{d T}\\partial_{q_T^i}L[\\vec{q}_T, \\vec{q}, T]\n\\; = \\; \n\\frac{\\partial}{\\partial q^i} L[\\vec{q_T}, \\vec{q}, T].\n}\n\nThus $\\vec{q}(T, \\vec{\\beta}, \\vec{\\alpha})$ defined in inexplicit way\nvia \\rf{beta-definition} is a solution of equations of motion \\rf{L-eqn}\nthat depends on $2N$ constants $\\alpha_i$, $\\beta_i$, $i=1..N$\n\n\\par\n\n\\section{Bottom line}\n\nIn short, I can describe the Hamilton-Jakoby method as following procedure.\n\n\\begin{enumerate}\n\\item\nGiven the Lagrangian $L=L(\\dot{\\vec{q}}, \\vec{q}, T)$ express $\\dot{\\vec{q}}$\nas a function of $\\partial_{\\dot{\\vec{q}}}L$, $q$ and~$T$:\n\\eqn{\n\\dot{\\vec{q}} = \\dot{\\vec{q}}\n    (\\frac{\\partial L}{\\partial \\dot{\\vec{q}}}, \\vec{q}, T)\n}\n\n\\item\nSubstitude $\\partial_{\\dot{\\vec{q}}}L$ by $\\partial_{\\vec{q}}S(T, \\vec{q})$\nin the expression for $\\dot{\\vec{q}}$ and find a general solution \nof the Hamilton-Jakoby equation \\rf{JH-eqn} for $S(T, \\vec{q})$:\n\n\\eqn{\n\\partial_T S(T, \\vec{q}) =    \nL[\\vec{\\dot{q}}(\\partial_{\\vec{q}}S, \\vec{q}, T), \\vec{q}, T]\n - \\partial_{q^i} S(T, \\vec{q}) \\dot{q}^i(\\partial_{\\vec{q}}S, \\vec{q}, T).\n}\n\n\\item\nPresent the general solution in the following form:\n\\eqn{\nS = S(T, \\vec{q}, \\vec{alpha}) + \\alpha_0,\n}\nwhere $\\vec{alpha})$ and $\\alpha_0$ are $N+1$ arbitrary constants.\n\n\\item\n\nFrom $beta^i \\equiv \\partial_{\\alpha_i} S(T, \\vec{q}, \\vec{\\alpha})$ express\n$\\vec{q}$ as a function of $\\vec{\\alpha}$, $\\vec{\\beta}$ and~$T$:\n\\eqn{\n\\vec{q} = \\vec{q}(\\vec{\\alpha}, \\vec{\\beta}, T).\n}\n\n\\item\n\nUse definitions $\\vec{q_0} = \\vec{q}(\\vec{\\alpha}, \\vec{\\beta}, T_0)$, \n$\\vec{v_0} = \\partial_T \\vec{q}(\\vec{\\alpha}, \\vec{\\beta}, T_0)$ to express\n$q$ via initial conditions:\n\\eqn{\n\\vec{q} = \\vec{q}(\\vec{q_0}, \\vec{v_0}, T).\n}\n\n\\end{enumerate}\n\nAnd that is it.\n\n\\end{document}\n\n", "meta": {"hexsha": "b6a0412b01880149203c1428e95824123dd022ab", "size": 20329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writes/hj_equation/main.tex", "max_stars_repo_name": "ibukanov/ahome", "max_stars_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/hj_equation/main.tex", "max_issues_repo_name": "ibukanov/ahome", "max_issues_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/hj_equation/main.tex", "max_forks_repo_name": "ibukanov/ahome", "max_forks_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": 29.8079178886, "max_line_length": 80, "alphanum_fraction": 0.6115893551, "num_tokens": 8180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6200057378987868}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{amsmath,amssymb,graphicx}\n\\usepackage{../setspace}\n\\addtolength{\\textwidth}{1.5in}\n\\addtolength{\\hoffset}{-1in}\n\\addtolength{\\textheight}{1.5in}\n\\addtolength{\\voffset}{-1in}\n\n\\title{STAT3401: Lab exercises concerning measures of distance}\n\\author{Paul Hewson}\n\\date{11th January 2007}\n\\usepackage{/usr/share/R/share/texmf/Sweave}\n\\begin{document}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{12pt}\n\\sffamily\n\\maketitle\n\n\n\\section{Mahalanobis distance and multivariate normality}\n\n\\begin{Schunk}\n\\begin{Sinput}\n> USA.mah.dist <- mahalanobis(USArrests, center = mean(USArrests), \n+     cov = var(USArrests))\n> hist(USA.mah.dist, freq = FALSE)\n> curve(dchisq(x, df = 4), add = TRUE, col = \"red\")\n\\end{Sinput}\n\\end{Schunk}\n\nor consider $qq$ plots:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> n <- 50\n> p <- 4\n> qqplot(USA.mah.dist, qchisq(ppoints(n), p))\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\begin{itemize}\n\\item Do you think that the USArrests data can be considered to be multivariate normal.   If so, repeat this with some other data, such as the simulated multivariate normal data you generated in week 1, or any other data we have met (e.g. iris data).\n\\item For any data you consider, compare your findings on multivariate normality with what you find when examining univariate normality of either the margins or the linear combinations\n\\end{itemize}\n\nMore advanced work: there are some who think that a beta distribution should be used.   There is a function \\texttt{qqbetaM} in a file in the portal.   Copy this into your workspace, \\texttt{source} the function and see whether you think it makes a difference.     \n\n\\begin{Schunk}\n\\begin{Sinput}\n> source(\"qqbetaM.R\")\n> qqbetaM(USA.mah.dist, 4)\n\\end{Sinput}\n\\end{Schunk}\n\nCompare the qqplots you obtain from this function with qqplots from the $\\chi^{2}$ based quantiles.   Do you have any data where your impression of normality may be altered by a change in the comparison?   From your reading material, when might it matter whether you use a beta distribution or a $\\chi^{2}$?\n\n\\section{Gower's distance}\n\nThis is quite an important exercise!   Make sure you are happy calculating Gower's distance.  Use the \\texttt{class07.csv} data in the portal, and calculate the distance between a few individuals by hand.   Then use \\texttt{daisy} in \\texttt{library(cluster)} to calcuate it in R (it's a slightly fiddly function to use). \n\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "376a6b473360a381e6669d9ffeb40324d8d085a8", "size": 2434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/STAT3401Week3DistanceLab.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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/STAT3401Week3DistanceLab.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "exercises/STAT3401Week3DistanceLab.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "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.328358209, "max_line_length": 322, "alphanum_fraction": 0.7477403451, "num_tokens": 715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125626441471, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.620005724435213}}
{"text": "\\section{The homotopy image of a map}\\label{chap:image}\n\\subsection{The universal property of the image of a map}\n\n\\begin{defn}\nLet $f:A\\to X$ and $g:B\\to X$ be maps. We define\n\\begin{equation*}\n\\mathrm{hom}_X(f,g)\\defeq\\sm{h:A\\to B}f\\htpy g\\circ h.\n\\end{equation*}\n\\end{defn}\n\n\\begin{rmk}\nIn other words, a term $(h,H):\\mathrm{hom}_X(f,g)$ consists of a map $h:A\\to B$ equipped with a homotopy $H:f\\htpy g\\circ h$ witnessing that the 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*}\ncommutes. Recall from \\cref{ex:triangle_fib} that the type $\\mathrm{hom}_X(f,g)$ is equivalent to the type\n\\begin{equation*}\n\\prd{x:X}\\fib{f}{x}\\to\\fib{g}{x}.\n\\end{equation*}\n\\end{rmk}\n\n\\begin{lem}\nFor any $f:A\\to X$ and any embedding\\index{embedding} $m:B\\to X$, the type $\\mathrm{hom}_X(f,m)$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\nSince propositions are closed under equivalences by \\cref{lem:prop_equiv}, it suffices to show that the type\n\\begin{equation*}\n\\prd{x:X}\\fib{f}{x}\\to\\fib{m}{x},\n\\end{equation*}\nis a proposition. Recall from \\cref{cor:prop_emb} that a map is an embedding if and only if its fibers are propositions.\nThus we see that the type $\\prd{x:X}\\fib{f}{x}\\to\\fib{m}{x}$ is a product of propositions, so it is a proposition by \\cref{thm:trunc_pi}.\n\\end{proof}\n\n\\begin{defn}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=small]\nA \\arrow[rr,\"i\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"m\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $I:f\\htpy m\\circ i$, and where $m$ is an embedding\\index{embedding}.\nWe say that $m$ has the \\define{universal property of the image of $f$}\\index{universal property!of the image|textit} if the map\n\\begin{equation*}\n(i,I)^\\ast : \\mathrm{hom}_X(m,m')\\to\\mathrm{hom}_X(f,m')\n\\end{equation*}\ndefined by $(i,I)^\\ast(h,H)\\defeq (h\\circ i,\\ct{I}{(i\\cdot H)})$,\nis an equivalence for every embedding $m':B'\\to X$. \n\\end{defn}\n\n\\begin{rmk}\nSince $\\mathrm{hom}_X(f,m)$ is a proposition for every $f:A\\to X$ and every embedding $m:B\\to X$, it follows by \\cref{ex:prop_equiv} that the universal property of the image of $f$ is equivalent to the property that the implication\n\\begin{equation*}\n\\mathrm{hom}_X(f,m')\\to\\mathrm{hom}_X(m,m')\n\\end{equation*}\nholds for every embedding $m':B'\\to X$. \n\\end{rmk}\n\nThe homotopy image can be used in many important constructions. In this lecture we discuss two applications: the propositional truncation, and set quotients.\n\n\\subsection{The propositional truncation}\nNote that embeddings into the unit type are just propositions. To see this, note that\n\\begin{align*}\n\\sm{A:\\UU}{f:A\\to\\unit}\\isemb(f)\n& \\eqvsym \\sm{A:\\UU}\\isemb(\\const_\\ttt) \\\\\n& \\eqvsym \\sm{A:\\UU}\\prd{x:\\unit}\\isprop(\\fib{\\const_\\ttt}{x}) \\\\\n& \\eqvsym \\sm{A:\\UU}\\isprop(\\fib{\\const_\\ttt}{\\ttt}) \\\\\n& \\eqvsym \\sm{A:\\UU}\\isprop(A).\n\\end{align*}\nTherefore, the universal property of the image of the map $A\\to\\unit$ is a proposition $P$ satisfying the universal property of the propositional truncation:\n\n\\begin{defn}\nLet $A$ be a type, and let $P$ be a proposition that comes equipped with a map $\\eta:A\\to P$. We say that $\\eta:A\\to P$ satisfies the \\define{universal property of propositional truncation}\\index{universal property!of propositional truncation|textit} if for every proposition $Q$, the precomposition map\n\\begin{equation*}\n\\blank\\circ\\eta:(P\\to Q)\\to (A\\to Q)\n\\end{equation*}\nis an equivalence.\n\\end{defn}\n\n\\begin{thm}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=small]\nA \\arrow[rr,\"i\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"m\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwith $I:f\\htpy m\\circ i$, and where $m$ is an embedding. The following are equivalent:\n\\begin{enumerate}\n\\item $m$ satisfies the universal property of the image of $f$.\n\\item for each $x:X$, the proposition $\\fib{m}{x}$ satisfies the universal property of the propositional truncation of $\\fib{f}{x}$.\n\\end{enumerate}\n\\end{thm}\n\n\nNote that, given a family of propositions $P$ over a type $A$, the type $\\sm{a:A}P(a)$ isn't necessarily a proposition. Instead, we think of $\\sm{a:A}P(a)$ of the \\emph{subtype} of $A$ containing the terms that satisfies $P$. Using the propositional truncation we can assert that there \\emph{exists} a term in $A$ that satisfies $P$ without requiring one to construct it. \n\n\\begin{defn}\nLet $P:A\\to \\prop$ be a family of propositions over a type $A$. Then we define\n\\begin{equation*}\n\\exists_{(a:A)}P(a)\\defeq \\brck{\\sm{a:A}P(a)}.\n\\end{equation*}\n\\end{defn}\n\nSimilarly, we can define the disjunction of two propositions $P$ and $Q$ to be the \\emph{proposition} $\\brck{P+Q}$, which clearly satisfies the universal property of disjunction\\footnote{Alternatively, we have shown in \\cref{ex:join_propositions} that the join $\\join{P}{Q}$ also is a proposition that satisfies the universal property of disjunction.}. In \\cref{table:logic} we give an overview of the logical connectives on propositions.\n\n\\begin{table}\n\\caption{\\label{table:logic}Logic in type theory}\n\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n\\emph{Logical connective} & \\emph{Interpretation in HoTT} \\\\\n\\midrule\n$\\top$ & $\\unit$ \\\\\n$\\bot$ & $\\emptyt$ \\\\\n$P\\land Q$ & $P\\times Q$ \\\\\n$P\\lor Q$ & $\\brck{P+Q}$ \\\\\n$P\\to Q$ & $P\\to Q$ \\\\\n$P\\leftrightarrow Q$ & $\\eqv{P}{Q}$ \\\\\n$\\neg P$ & $P\\to\\emptyt$ \\\\\n$\\forall x.P(x)$ & $\\prd{x:A}P(x)$ \\\\\n$\\exists x.P(x)$ & $\\brck{\\sm{x:A}P(x)}$ \\\\\n$\\exists! x.P(x)$ & $\\iscontr(\\sm{x:A}P(x))$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\subsection{Constructing the propositional truncation}\nAlthough technically it is not necessary to construct the propositional truncation before constructing the image of a map, we do so because the construction is simpler in this special case, and yet contains most of the essential ideas.\n\n\\begin{lem}\\label{lem:extend_join_prop}\nSuppose $f:A\\to P$, where $A$ is any type, and $P$ is a proposition.\nThen the map\n\\begin{equation*}\n(\\join{A}{B}\\to P)\\to (B\\to P)\n\\end{equation*}\ngiven by $h\\mapsto h\\circ \\inr$ is an equivalence, for any type $B$.\n\\end{lem}\n\n\\begin{proof}\nSince both types are propositions by \\cref{thm:trunc_pi} it suffices to construct a map\n\\begin{equation*}\n(B\\to P)\\to (\\join{A}{B}\\to P).\n\\end{equation*}\nLet $g:B\\to P$. Then the square\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times B \\arrow[r,\"\\proj 2\"] \\arrow[d,swap,\"\\proj 1\"] & B \\arrow[d,\"g\"] \\\\\nA \\arrow[r,swap,\"f\"] & P\n\\end{tikzcd}\n\\end{equation*}\ncommutes since $P$ is a proposition. Therefore we obtain a map $\\join{A}{B}\\to P$ by the universal property of the join.\n\\end{proof}\n\nThe idea of the construction of the propositional truncation is that if we are given a map $f:A\\to P$, where $P$ is a proposition, then it extends uniquely along $\\inr:A\\to \\join{A}{A}$ to a map $\\join{A}{A}\\to P$. This extension again extends uniquely along $\\inr:\\join{A}{A}\\to \\join{A}{(\\join{A}{A})}$ to a map $\\join{A}{(\\join{A}{A})}\\to P$ and so on, resulting in a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[dr] \\arrow[r,\"\\inr\"] & \\join{A}{A} \\arrow[d,densely dotted] \\arrow[r,\"\\inr\"] & \\join{A}{(\\join{A}{A})} \\arrow[dl,densely dotted] \\arrow[r,\"\\inr\"] & \\cdots \\arrow[dll,densely dotted,bend left=10] \\\\\n& P\n\\end{tikzcd}\n\\end{equation*}\n\n\\begin{defn}\nThe \\define{join powers} $A^{\\ast n}$ of a type $X$ are defined by\n\\begin{align*}\nA^{\\ast 0} & \\defeq \\emptyt \\\\\nA^{\\ast 1} & \\defeq A \\\\\nA^{\\ast (n+1)} & \\defeq \\join{A}{A^{\\ast n}}.\n\\end{align*}\nFurthermore, we define $A^{\\ast\\infty}$ to be the sequential colimit of the type sequence\n\\begin{equation*}\n\\begin{tikzcd}\nA^{\\ast 0} \\arrow[r] & A^{\\ast 1} \\arrow[r,\"\\inr\"] & A^{\\ast 2} \\arrow[r,\"\\inr\"] & \\cdots.\n\\end{tikzcd}\n\\end{equation*}\n\\end{defn}\n\nOur goal is now to show that $A^{\\ast\\infty}$ is a proposition and satisfies the universal property of the propositional truncation.\n\n\\begin{lem}\nConsider a type sequence\n\\begin{equation*}\n\\begin{tikzcd}\nA_0 \\arrow[r,\"f_0\"] & A_1 \\arrow[r,\"f_1\"] & A_2 \\arrow[r,\"f_2\"] & \\cdots\n\\end{tikzcd}\n\\end{equation*}\nwith sequential colimit $A_\\infty$, and let $P$ be a proposition. Then the map\n\\begin{equation*}\n\\seqin^\\ast: (A_\\infty\\to P)\\to \\Big(\\prd{n:\\N}A_n\\to P\\Big)\n\\end{equation*}\ngiven by $h\\mapsto \\lam{n}(h\\circ \\seqin_n)$ is an equivalence. \n\\end{lem}\n\n\\begin{proof}\nBy the universal property of sequential colimits established in \\cref{thm:sequential_up} we obtain that $\\coconemap$ is an equivalence. Note that we have a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}\n& P^{A_\\infty} \\arrow[dl,swap,\"\\coconemap\"] \\arrow[dr,\"\\seqin^\\ast\"] \\\\\n\\cocone(P) \\arrow[rr,swap,\"\\proj 1\"] & & \\Big(\\prd{n:\\N}A_n\\to P\\Big).\n\\end{tikzcd}\n\\end{equation*}\nNote that for any $g:\\prd{n:\\N}A_n\\to P$ the type \n\\begin{equation*}\n\\prd{n:\\N} g_n\\htpy g_{n+1}\\circ f_n\n\\end{equation*}\nis a product of contractible types, since $P$ is a proposition. Therefore it is contractible by \\cref{thm:funext_wkfunext}, and it follows by \\cref{ex:proj_fiber} that the projection is an equivalence. We conclude by the 3-for-2 property of equivalences (\\cref{ex:3_for_2}) that $\\seqin^\\ast$ is an equivalence.\n\\end{proof}\n\n\\begin{lem}\\label{lem:infjp_up}\nLet $A$ be a type, and let $P$ be a proposition. Then the function\n\\begin{equation*}\n\\blank\\circ \\seqin_0: (A^{\\ast\\infty}\\to P)\\to (A\\to P)\n\\end{equation*}\nis an equivalence. \n\\end{lem}\n\n\\begin{proof}\nWe have the commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}\n&[-3em] P^{A^{\\ast\\infty}} \\arrow[dl,swap,\"\\seqin^\\ast\"] \\arrow[dr,\"\\blank\\circ\\seqin_0\"] \\\\\n\\Big(\\prd{n:\\N}A^{\\ast n} \\to P\\Big) \\arrow[rr,swap,\"\\lam{h}h_0\"] & & P^A.\n\\end{tikzcd}\n\\end{equation*}\nTherefore it suffices to show that the bottom map is an equivalence. Since this is a map between propositions, it suffices to construct a map in the converse direction. Let $f:A\\to P$. We will construct a term of type\n\\begin{equation*}\n\\prd{n:\\N}A^{\\ast n} \\to P\n\\end{equation*}\nby induction on $n:\\N$. The base case is trivial. Given a map $g:A^{\\ast n}\\to P$, we obtain a map $g:A^{\\ast(n+1)}\\to P$ by \\cref{lem:extend_join_prop}.\n\\end{proof}\n\n\\begin{lem}\\label{lem:isprop_infjp}\nThe type $A^{\\ast\\infty}$ is a proposition for any type $A$.\n\\end{lem}\n\n\\begin{proof}\nBy \\cref{cor:contr_prop} it suffices to show that $A^{\\ast\\infty}\\to \\iscontr(A^{\\ast\\infty})$, and by \\cref{lem:infjp_up} it suffices to show that\n\\begin{equation*}\nA\\to \\iscontr(A^{\\ast\\infty}),\n\\end{equation*}\nbecause $\\iscontr(A^{\\ast\\infty})$ is a proposition by \\cref{ex:isprop_istrunc}. \n\nLet $x:A$. To see that $A^{\\ast\\infty}$ is contractible it suffices by \\cref{ex:seqcolim_contr} to show that $\\inr:A^{\\ast n}\\to A^{\\ast(n+1)}$ is homotopic to the constant function $\\const_{\\inl(x)}$. However, we get a homotopy $\\const_{\\inl(x)}\\htpy \\inr$ immediately from the path constructor $\\glue$.  \n\\end{proof}\n\n\\begin{thm}\nFor any type $A$ there is a type $\\brck{A}$ that comes equipped with a map $\\eta:A\\to \\brck{A}$, and satisfies the universal property of propositional truncation.\n\\end{thm}\n\n\\begin{proof}\nLet $A$ be a type. Then we define $\\brck{A}\\defeq A^{\\ast\\infty}$, and we define $\\eta\\defeq \\seqin_0:A\\to A^{\\ast\\infty}$. Then $\\brck{A}$ is a proposition by \\cref{lem:isprop_infjp}, and $\\eta:A\\to \\brck{A}$ satisfies the universal property of propositional truncation by \\cref{lem:infjp_up}.\n\\end{proof}\n\n\\subsection{The construction of the image of a map}\nThe image of a map $f:A\\to X$ can be defined using the propositional truncation:\n\\begin{defn}\nFor any map $f:A\\to X$ we define the \\define{image}\\index{image|textbf} of $f$ to be the type\n\\begin{equation*}\n\\im(f) \\defeq \\sm{x:X}\\brck{\\fib{f}{x}}\n\\end{equation*}\nand we define the \\define{image inclusion} to be the projection $\\proj 1 :\\im(f)\\to X$. \n\\end{defn}\nHowever, the construction of the fiberwise join in \\cref{ex:fib_join} suggests that we can also define the image of $f$ as the infinite join power $f^{\\ast\\infty}$, where we repeatedly take the fiberwise join of $f$ with itself. The reasons for defining the image in this way are twofold: we will be able to use this construction to show that the set-quotients of a small type are small, and second, we many interesting types appear in this construction.\n\n\\begin{lem}\nConsider a map $f:A\\to X$, an embedding $m:U\\to X$, and $h:\\mathrm{hom}_X(f,m)$. Then the map\n\\begin{equation*}\n\\mathrm{hom}_X(\\join{f}{g},m)\\to \\mathrm{hom}_X(g,m)\n\\end{equation*}\nis an equivalence for any $g:B\\to X$.\n\\end{lem}\n\n\\begin{proof}\nNote that both types are propositions, so any equivalence can be used to prove the claim. Thus, we simply calculate\n\\begin{align*}\n\\mathrm{hom}_X(\\join{f}{g},m) & \\eqvsym \\prd{x:X}\\fib{\\join{f}{g}}{x}\\to \\fib{m}{x} \\\\\n& \\eqvsym \\prd{x:X}\\join{\\fib{f}{x}}{\\fib{g}{x}}\\to\\fib{m}{x} \\\\\n& \\eqvsym \\prd{x:X}\\fib{g}{x}\\to\\fib{m}{x} \\\\\n& \\eqvsym \\mathrm{hom}_X(g,m).\n\\end{align*}\nThe first equivalence holds by \\cref{ex:triangle_fib}; the second equivalence holds by \\cref{ex:fib_join}, also using \\cref{ex:equiv_precomp,lem:postcomp_equiv} where we established that that pre- and postcomposing by an equivalence is an equivalence; the third equivalence holds by \\cref{lem:extend_join_prop,lem:postcomp_equiv}; the last equivalence again holds by \\cref{ex:triangle_fib}.\n\\end{proof}\n\nFor the construction of the image of $f:A\\to X$ we observe that if we are given an embedding $m:U\\to X$ and a map $(i,I):\\mathrm{hom}_X(f,m)$, then $(i,I)$ extends uniquely along $\\inr:A\\to \\join[X]{A}{A}$ to a map $\\mathrm{hom}_X(\\join{f}{f},m)$. This extension again extends uniquely along $\\inr:\\join[X]{A}{A}\\to \\join[X]{A}{(\\join[X]{A}{A})}$ to a map $\\mathrm{hom}_X(\\join{f}{(\\join{f}{f})},m)$ and so on, resulting in a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[dr] \\arrow[r,\"\\inr\"] & \\join[X]{A}{A} \\arrow[d,densely dotted] \\arrow[r,\"\\inr\"] & \\join[X]{A}{(\\join[X]{A}{A})} \\arrow[dl,densely dotted] \\arrow[r,\"\\inr\"] & \\cdots \\arrow[dll,densely dotted,bend left=10] \\\\\n& U\n\\end{tikzcd}\n\\end{equation*}\n\n\\begin{defn}\nSuppose $f:A\\to X$ is a map. Then we define the \\define{fiberwise join powers} \n\\begin{equation*}\nf^{\\ast n}:A_X^{\\ast n} X.\n\\end{equation*}\n\\end{defn}\n\n\\begin{constr}\nNote that the operation $(B,g)\\mapsto (\\join[X]{A}{B},\\join{f}{g})$ defines an endomorphism on the type\n\\begin{equation*}\n\\sm{B:\\UU}B\\to X.\n\\end{equation*}\nWe also have $(\\emptyt,\\ind{\\emptyt})$ and $(A,f)$ of this type. For $n\\geq 1$ we define\n\\begin{align*}\nA_X^{\\ast (n+1)} & \\defeq \\join[X]{A}{A_X^{\\ast n}} \\\\\nf^{\\ast (n+1)} & \\defeq \\join{f}{f^{\\ast n}}.\\qedhere\n\\end{align*}\n\\end{constr}\n\n\\begin{defn}\nWe define $A_X^{\\ast\\infty}$ to be the sequential colimit of the type sequence\n\\begin{equation*}\n\\begin{tikzcd}\nA_X^{\\ast 0} \\arrow[r] & A_X^{\\ast 1} \\arrow[r,\"\\inr\"] & A_X^{\\ast 2} \\arrow[r,\"\\inr\"] & \\cdots.\n\\end{tikzcd}\n\\end{equation*}\nSince we have a cocone\n\\begin{equation*}\n\\begin{tikzcd}\nA_X^{\\ast 0} \\arrow[r] \\arrow[dr,swap,\"f^{\\ast 0}\" near start] & A_X^{\\ast 1} \\arrow[r,\"\\inr\"] \\arrow[d,swap,\"f^{\\ast 1}\" near start] & A_X^{\\ast 2} \\arrow[r,\"\\inr\"] \\arrow[dl,swap,\"f^{\\ast 2}\" xshift=1ex] & \\cdots \\arrow[dll,bend left=10] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nwe also obtain a map $f^{\\ast\\infty}:A_X^{\\ast\\infty}\\to X$ by the universal property of $A_X^{\\ast\\infty}$. \n\\end{defn}\n\n\\begin{lem}\\label{lem:finfjp_up}\nLet $f:A\\to X$ be a map, and let $m:U\\to X$ be an embedding. Then the function\n\\begin{equation*}\n\\blank\\circ \\seqin_0: \\mathrm{hom}_X(f^{\\ast\\infty},m)\\to \\mathrm{hom}_X(f,m)\n\\end{equation*}\nis an equivalence. \n\\end{lem}\n\n\\begin{thm}\\label{lem:isprop_infjp}\nFor any map $f:A\\to X$, the map $f^{\\ast\\infty}:A_X^{\\ast\\infty}\\to X$ is an embedding that satisfies the universal property of the image inclusion of $f$.\n\\end{thm}\n\n\\subsection{Surjective maps}\n\nAnother application of the propositional truncation is the notion of surjective map.\n\n\\begin{defn}\nA map $f:A\\to B$ is said to be \\define{surjective} if there is a term of type\n\\begin{equation*}\n\\issurj(f)\\defeq \\prd{y:B}\\brck{\\fib{f}{b}}.\n\\end{equation*}\n\\end{defn}\n\n\\begin{eg}\nAny equivalence is a surjective map, and so is any map that has a section (those are sometimes called \\define{split epimorphisms}). Other examples include the base point inclusion $\\unit\\to\\sphere{n}$ for any $n\\geq 1$. \n\\end{eg}\n\n\\begin{thm}\\label{thm:surjective}\nConsider a commuting triangle\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\arrow[rr,\"q\"] \\arrow[dr,swap,\"f\"] & & B \\arrow[dl,\"m\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nin which $m$ is an embedding. Then $m$ satisfies the universal property of the image of $f$ if and only if $i:A\\to B$ is surjective.\n\\end{thm}\n\n\\begin{thm}\nLet $f:A\\to B$ be a map. The following are equivalent:\n\\begin{enumerate}\n\\item $f$ is an equivalence.\n\\item $f$ is both surjective and an embedding.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{exercises}\n\\item Show that\n\\begin{equation*}\n\\eqv{\\brck{A}}{\\prd{P:\\prop}(A\\to P)\\to P}\n\\end{equation*}\nfor any type $A:\\UU$. This is called the \\define{impredicative encoding} of the propositional truncation.\n\\item For any $B:A\\to\\UU$, construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\exists_{(a:A)}\\brck{B(a)}\\Big)}{\\brck{\\sm{a:A}B(a)}}\n\\end{equation*}\n%\\item \\label{also}(Mart\\'in Escard\\'o) For any two propositions $P$ and $Q$, define\n%\\begin{equation*}\n%P\\boxplus Q \\defeq ((P\\to Q)\\to Q)\\times ((Q\\to P)\\to P).\n%\\end{equation*}\n%\\begin{subexenum}\n%\\item Show that $P\\lor Q\\to P\\boxplus Q$ and $P\\boxplus Q\\to\\neg(\\neg P\\land \\neg Q)$.\n%\\end{subexenum}\n%\\item \\label{ex:brck_comp} Formulate the computation rule corresponding to the path constructor $\\mu$. That is, compute the type of $\\apd{\\rec{\\brck{\\blank}}(f,g)}{\\mu(x,y)}$, and find a canonical element in it.\n\\item Let\n\\begin{tikzcd}\nP_0 \\arrow[r] & P_1 \\arrow[r] & P_2 \\arrow[r] & \\cdots\n\\end{tikzcd}\nbe a sequence of propositions. Show that\n\\begin{equation*}\n\\eqv{\\colim_n(P_n)}{\\exists_{(n:\\N)} P_n}.\n\\end{equation*}\n\\item Show that the relation $x,y\\mapsto\\brck{x=y}$ is an equivalence relation, on any type.\n\\item Let $f:A\\to X$ be a map. Construct an equivalence\n\\begin{equation*}\n\\eqv{\\Big(\\sm{y:\\mathsf{join\\usc{}power}_X(n,A)}f(x)=f^{\\ast n}(y)\\Big)}{\\Big(\\sm{y:A}f(x)=f(y)\\Big)^{\\ast n}}\n\\end{equation*}\nfor any $x:A$.\n\\item Let $f:A\\to B$ be a map. Show that the following are equivalent:\n\\begin{enumerate}\n\\item The commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] \\arrow[r] & \\brck{A} \\arrow[d,\"\\brck{f}\"] \\\\\nB \\arrow[r] & \\brck{B}.\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square.\n\\item There is a term of type $A\\to\\isequiv(f)$.\n\\item The commuting square\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times A \\arrow[r,\"f\\times f\"] \\arrow[d,swap,\"\\proj 1\"] & B \\times B \\arrow[d,\"\\proj 1\"] \\\\\nA \\arrow[r,swap,\"f\"] & B\n\\end{tikzcd}\n\\end{equation*}\nis a pullback square. \n\\end{enumerate}\n\\item Consider a pullback square\n\\begin{equation*}\n\\begin{tikzcd}\nA' \\arrow[d,swap,\"{f'}\"] \\arrow[r,\"p\"] & A \\arrow[d,\"f\"] \\\\\nB' \\arrow[r,swap,\"q\"] & B,\n\\end{tikzcd}\n\\end{equation*}\nin which $q:B'\\to B$ is surjective. Show that if $f':A'\\to B'$ is an embedding, then so is $f:A\\to B$.\n\\item Show that a type $A$ is a proposition if and only if the map $\\inl:A\\to \\join{A}{A}$ is an equivalence.\n\\item Show that $\\inl:\\brck{A}\\to \\join{\\brck{A}}{A}$ is an equivalence for any type $A$.\n\\item Consider a family of diagrams of the form\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A_i \\arrow[r] \\arrow[d,swap,\"{f_i}\"] &\n        C \\arrow[r] \\arrow[d,\"g\"] & X \\arrow[d,\"h\"] \\\\\n      B_i \\arrow[r] & D \\arrow[r] & Y \n    \\end{tikzcd}\n  \\end{equation*}\n  indexed by $i:I$, in which the left squares are pullback squares,\n  and assume that the induced map\n  \\begin{equation*}\n    \\Big(\\sm{i:I}B_i\\Big)\\to D\n  \\end{equation*}\n  is surjective. Show that the following are equivalent:\n  \\begin{enumerate}\n  \\item For each $i:I$ the outer rectangle is a pullback square.\n  \\item The right square is a pullback square.\n  \\end{enumerate}\n  Hint: By \\cref{thm:descent-Sigma} it suffices to prove this equivalence for a single diagram of the form\n    \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[r] \\arrow[d,swap,\"{f}\"] &\n        C \\arrow[r] \\arrow[d,swap,\"g\"] & X \\arrow[d,\"h\"] \\\\\n      B \\arrow[r] & D \\arrow[r] & Y \n    \\end{tikzcd}\n    \\end{equation*}\n  where the map $B \\to D$ is assumed to be surjective.\n\\end{exercises}\n", "meta": {"hexsha": "fac6fa6ddd3e058e7dbc72d528382ba68734b1d4", "size": 20278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/image.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/image.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/image.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": 43.236673774, "max_line_length": 454, "alphanum_fraction": 0.6855705691, "num_tokens": 7254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.6200057195699266}}
{"text": "\\chapter{Linear Multistep Methods}\n\n\n\\begin{intro}\n  In the previous methods we obtained the value after the next time\n  step always by using \\emph{one} initial value at the beginning of\n  the current time interval, possibly with the\n  help of intermediate steps. These methods often are accused to have\n  a higher computation time than methods which use several previous\n  points, the argument being that function values at these points have\n  been computed already. Such methods using values of several time steps in\n  the past are called multistep methods. They are constructed such\n  that using more steps yields a method of higher order.\n\n  We will begin this chapter by introducing some of the\n  formulas. Afterwards, we will study their stability and convergence\n  properties.\n\\end{intro}\n\n\\begin{example}[Adams-Moulton formulas]\n  \\label{ex:lmm:2}  \n  \\index{Adams-Moulton methods} Basically, there are two construction\n  principles for the multistep methods: Quadrature and numerical\n  differentiation.  We postpone the latter to example~\\ref{ex:lmm:3}\n  and deal with the former for now.  As first example we choose the\n  class of Adams-Moulton methods for which the integral from point\n  $t_{k-1}$ to point $t_{k}$ is approximated by a quadrature of the\n  points $t_{k-\\lmms}$ to $t_k$, hence\n  \\begin{gather}\n    \\label{eq:lmm:16}\n    y_k = y_{k-1} + \\sum_{r=0}^\\lmms f_{k-r} \\int_{t_{k-1}}^{t_k}\n    L_r(t) \\dt,\n  \\end{gather}\n  where $f_j$ denotes the function value $f(t_j, y_j)$ and $L_r(t)$\n  the Lagrange interpolation polynomial to point $t_r$ with respect to\n  the points $t_{k-\\lmms},\\dots,t_k$.  This is shown in\n  Figure~\\ref{fig:lmm:adams-moulton}.\n  \\begin{figure}[tbp]\n    \\begin{center}\n      \\includegraphics[width=.9\\textwidth]{fig/adams-moulton.tikz}\n    \\end{center}\n    \\caption{The quadrature of Adams-Moulton formulas: the\n      integration interval is marked by the wavy line in the end. The support \n\t\t\tpoints of the quadrature are stated under the line.}\n    \\label{fig:lmm:adams-moulton}\n  \\end{figure}\n  Since the integral involves the point being computed itself, these\n  methods are implicit. The first of these are\n  \\input{definitions/adams-moulton}  \n\\end{example}\n\n\\begin{example}[Adams-Bashforth formulas]\n  \\label{ex:lmm:1}\n  \\index{Adams-Bashforth methods} With the same principle we obtain\n  explicit methods by omitting the point in time $t_k$ in the\n  definition of the interpolation polynomial. See\n  Figure~\\ref{fig:lmm:adams-bashforth}.\n  \\begin{figure}[tbp]\n    \\begin{center}\n      \\includegraphics[width=.9\\textwidth]{fig/adams-bashforth.tikz}\n    \\end{center}\n    \\caption{The quadrature of Adams-Bashforth formulas: the\n      integration interval is marked by the wavy line in the end. The support \n\t\t\tpoints of the quadrature are stated under the line.}\n    \\label{fig:lmm:adams-bashforth}\n  \\end{figure}\n  This yields quadrature formulas of the form\n  \\begin{gather}\n    \\label{eq:lmm:17}\n    y_k = y_{k-1} + \\sum_{r=1}^\\lmms f_{k-r} \\int_{t_{k-1}}^{t_k}\n    L_r(t) \\dt.\n  \\end{gather}\n  Again, we list the first few:\n  \\input{definitions/adams-bashforth}\n\\end{example}\n\n\\begin{example}\n  \\label{ex:lmm:3}\n  \\index{BDF methods} Backward differencing formulas (BDF) are as well\n  based on Lagrange interpolation at the points $t_{k-\\lmms}$ to\n  $t_k$. In contrast to Adams formulas they do not use quadrature for\n  the right hand side, but rather the derivative of the interpolation\n  polynomial in the point $t_k$.  Using Lagrange interpolation\n  polynomials $L_i(t)$, we let\n  \\begin{gather*}\n    y(t) = \\sum_{r=0}^\\lmms y_{n-r} L_{n-r}(t),\n  \\end{gather*}\n  where $y_n$ is still to determine. Now we assume that $y$ solves the ODE\n  in point $t_n$, hence\n  \\begin{gather*}\n    y'(t_n) = f(t_n, y_n) = \\sum_{r=0}^\\lmms y_{n-r} L'_{n-r}(t_n).\n  \\end{gather*}\n  This yields the following schemes:\n  \\input{definitions/bdf}\n  For an example on how to derive these schemes see the appendix.\n\\end{example}\n\n\\begin{remark}\n  We know from introduction to numerical analysis, that the numerical\n  differentiation and the extrapolation, the evaluation of\n  interpolation polynomials outside of the interval which is spanned\n  through the interpolation points, are not stable.  Therefore, we\n  expect stability problems for the Adams-Bashforth and BDF\n  methods. Moreover, we remember that Lagrange interpolation with\n  equidistant support points is unstable for a high-degree\n  polynomials. Therefore, we also expect that all methods above\n  perform well only with moderate order.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Definition and consistency of LMM}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\input{definitions/lmm}\n\n\\begin{remark}\n  \\index{step size!constant} The LMM was defined for constant step size\n  $h$.  In principle it is possible to implement the method with a\n  variable step size but we restrict ourselves to the constant case.\n  Notes to the step size control can be found later on in this chapter.\n\\end{remark}\n\n\\begin{remark}\n  One-step methods were always denoted by describing how to compute\n  $y_1$ from $y_0$. Here, the notation becomes more complicated, but\n  sometimes we consider only $y_s$ computed from $y_0,\\dots,y_{s-1}$\n  implying the same rules for $y_k$ computed from\n  $y_{k-\\lmms},\\dots,y_{k-1}$.\n\\end{remark}\n\\input{definitions/lmm-errors}\n\n\\begin{lemma}\n  Consider the differential equation\n  \\begin{gather*}\n    y' = f(t,y) \\qquad y(t_0) = y_0\n  \\end{gather*}\n  where f is given continuously differentiable and $y(t)$ is the exact solution.\n  For the local error we obtain\n\n  \\begin{gather}\n    y(t_k)-y_k = \\left( \\alpha_0 \\identity - h\\beta_0 \\frac{\\partial f}{\\partial y}(t_k,\\eta) \\right)^{-1} (L_h u)(t_k).\n  \\end{gather}\n\n  Here $\\eta$ is a value between $y(t_k)$ and $y_k$ if $f$ is a scalar\n\tfunction.\n  If $f$ is multidimensional, the matrix \n\t$\\frac{\\partial f}{\\partial y}(t_k,\\eta)$ is the Jacobi matrix, \n\twhich rows are evaluated at possible places between\n\t$y(t_k)$ and $y_k$.\n\\end{lemma}\n\n\\begin{proof}\n  Considering the local error we can assume exact initial values \n  and therefore we can transform ~\\ref{eq:lmm:4} to:\n  \\begin{gather*}\n    \\alpha_\\lmms y_k + \\sum\\limits_{r=1}^\\lmms \\alpha_{\\lmms-r} y(t_{k-r})\n    = h \\left( \\beta_\\lmms f_k + \\sum\\limits_{r=1}^\\lmms \\beta_{\\lmms-r} f_{k-r} \\right)\n  \\end{gather*}\n  We transform further:\n  \\begin{multline*}\n    \\sum\\limits_{r=0}^{\\lmms} \\left( \\alpha_r y(t_{k-r})\n      - h \\beta_r f(t_{k-r},y(t_{k-r})) \\right)\n    \\\\\n    - \\alpha_0 y(t_k) + h \\beta_0 f(t_k, y(t_k)) + \\alpha_0 y_k\n    - h \\beta_0 f(t_k,y_k) = 0.\n  \\end{multline*}\n\tWe now insert ~\\ref{eq:lmm:9} which results in\n  \\begin{gather*}\n    (L_h y)(t_k) = \\alpha_0 \\left( y(t_k) - y_k \\right) - h \\beta_0 \\left( f(t_k,y(t_k)) - f(t_k,y_k) \\right)\n    \\\\\n    \\left( y(t_k) - y_k \\right) \\left( \\alpha_0 \\identity - h \\beta_0 \\frac{f(t_k,y(t_k)) - f(t_k,y_k)}{y(t_k) - y_k} \\right)\n  \\end{gather*}\n  By application of the mean value theorem and \n  subsequent transformation we obtain the statement of the theorem.\n\\end{proof}\n\n      % \\cite[Lemma 2.2, p. 369]{HairerNorsettWanner93}\n\n\\input{definitions/lmm-consistency}\n\\input{theorems/lmm-bramble-hilbert}\n\n\\begin{proof}\n  We start with the Taylor expansion of a solution $u$ of the ODE and\n  the corresponding right hand side $f$ for $t_k$, where we insert,\n  unlike usual, $f=u'$:\n  \\begin{alignat*}2\n    u(t) &= \\sum_{i=0}^p \\frac{u^{(i)}(t_k)}{i!}(t-t_k)^i +\n    \\frac{u^{(p+1)}(\\xi)}{(p+1)!}(t-t_k)^{p+1} &=:& \\phi(t) + r_u(t)\n    \\\\\n    f\\bigl(t,u(t)\\bigr) &= \\sum_{i=1}^p \\frac{u^{(i)}(t_k)}{(i-1)!}(t-t_k)^{i-1} +\n    \\frac{u^{(p+1)}(\\xi)}{p!}(t-t_k)^{p} &=:& \\phi'(t) + r_f(t),\n  \\end{alignat*}\n  with the Taylor polynomial $\\phi(t)$ of degree $p$ and remainder\n  $r_u(t)$ and $r_f(t)$. Out of this we calculate:\n  \\begin{align*}\n    L_h u(t_k) =& \\sum_{r=0}^\\lmms \\alpha_{\\lmms-r} \\phi(t_{k-r}) - h\n    \\sum_{r=0}^\\lmms \\beta_{\\lmms-r} \\phi'(t_{k-r})\n    \\\\\n    &+ \\sum_{r=0}^\\lmms \\alpha_{\\lmms-r} r_u(t_{k-r}) - h\n    \\sum_{r=0}^\\lmms \\beta_{\\lmms-r} r_f(t_{k-r}).\n  \\end{align*}\n  Since $t_{k-r}-t_k = r h$, the first row equals a polynomial \n  $\\psi(h)$ in $h$ of degree $p$. For the second row we insert the\n\treminder estimate $r_u(t) = \\mathcal O((t-t_k)^{p+1}) = h\n  r_f(t)$ and get:\n  \\begin{gather}\n    \\label{eq:lmm:15}\n    L_h u(t_k) = L_h \\phi(t_k) + \\mathcal O(h^{p+1}) = \\psi(h) + \\mathcal O(h^{p+1}).\n  \\end{gather}\n  According to the definition of the truncation error, this term has to be of\n\torder $p+1$, such that the method is of order $p$. However it is $\\psi$\n  of degree $p$. This can only hold true if $L_h\\phi=\\psi\\equiv\n  0$. On the other hand $\\tau_h(t_k)$ automatically is of order\n  $p$. Since $u$ is the solution of an arbitrary right hand side, this\n\tcondition has to be satisfied for all kind of Taylor polynomials $\\phi$ \n\tof degree $p$.\n\\end{proof}\n\n\\begin{Theorem}{lmm-consistency}\n  \\index{step size!constant}\n  A LMM with constant step size is consistent of order\n  $p$ if and only if\n    \\begin{gather}\n      \\label{eq:lmm:12}\n      \\begin{split}\n      \\sum_{r=0}^\\lmms \\alpha_{r} &= 0, \\\\\n      \\sum_{r=0}^\\lmms \\bigl(\\alpha_{r}r^q - q \\beta_{r}\n      r^{q-1}\\bigr) &= 0,\n      \\qquad q = 1,\\dots,p        \n      \\end{split}\n    \\end{gather}\n\\end{Theorem}\n\n\n\\begin{proof}\n  According to lemma~\\ref{Lemma:lmm-bramble-hilbert} it is sufficient\n  to show that ~\\eqref{eq:lmm:12} is equivalent to $L_h \\phi_q=0$ for\n  polynomials of degree $q\\le p$. Due to linearity of the method it\n  however is sufficient to show this for a basis of the polynomial\n  space of degree $p$.  For that we choose the monomial basis of the\n  form\n  \\begin{gather*}\n  \\pi_q(t) =\n  \\left(\\frac{t-t_{k-\\lmms}}h\\right)^q,\\qquad q=0,\\dots,p.\n  \\end{gather*}\n  For those it holds: $\\pi_q(t_{k-r}) = (\\lmms-r)^q$. Now we see that\n  the first condition is $L_h\\pi_0 = 0$ (here is\n  $\\pi_0'\\equiv0$) and the second condition is $L_h\\pi_q = 0$.\n\\end{proof}\n\n\\begin{todo}\n  Beispiel einer konsistenten LMM, die nicht konvergiert.\n\\end{todo}\n\n\\begin{remark}\n  As shown in a homework problem, a consistent LMM is not necessary\n  convergent. To understand this behavior and develop criteria for\n  convergence we need to diverge into the theory of difference\n  equations.\n\\end{remark}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Properties of difference equations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  The stability of LMM can be understood by employing the fairly old\n  theory of difference equations. In order to keep the presentation\n  simple in this section, we use a different notation for numbering\n  indices in the equations. Nevertheless, the coefficients of the\n  characteristic polynomial are the same as for LMM.\n\\end{intro}\n\n\\input{definitions/difference-equation}\n\n\\begin{Lemma}{lmm:1}\n  The solutions of the equation~\\eqref{eq:lmm:3} with $y_n\\in \\R$ or\n  $y_n\\in \\C$ form a vector space of dimension $\\lmms$. \n\\end{Lemma}\n\n\\begin{proof}\n  Since the equation~\\eqref{eq:lmm:3} is linear and homogeneous, it is\n  obvious that if two sequences of solutions $\\{y^{(1)}\\}$ and\n  $\\{y^{(2)}\\}$ satisfy the equation, sums of multiples of them\n  satisfy it too.\n\n  As soon as the initial values $y_0$ to $y_{\\lmms-1}$ are chosen, all\n  other sequence members are uniquely defined.  Moreover it holds\n  \\begin{gather*}\n    y_0=y_1=\\dots=y_{\\lmms-1}=0\n    \\quad\\Longrightarrow\\quad\n    y_n = 0, \\;n \\ge 0.\n  \\end{gather*}\n  Therefore it is sufficient to consider the first $\\lmms$ values.  If\n  they are linear independent, then the overall sequences are and vice\n  versa. Thus, the initial values form a $\\lmms$\n  dimensional vector space.\n\\end{proof}\n\n\\input{theorems/difference-equation-solutions}\n\n\\begin{proof}\n  Inserting the solution $y_n = \\xi^n$ into the difference equation\n  results in\n  \\begin{gather*}\n    \\sum_{r=0}^\\lmms \\alpha_{r} \\xi^{n+r} = \\xi^{n}\n    \\sum_{r=0}^\\lmms \\alpha_{r} \\xi^{r}\n    = \\xi^{n} \\chi(\\xi) = 0.\n  \\end{gather*}\n\\end{proof}\n\n\\input{theorems/difference-equation-basis}\n\n\\begin{proof}\n  First we observe that the sum of the multiplicities of the roots\n  results in the degree of the polynomial:\n  \\begin{gather*}\n    \\lmms = \\sum_{i=1}^\\iota \\nu_i.\n  \\end{gather*}\n  Moreover we know because of Lemma~\\ref{Lemma:lmm:1}, that $\\lmms$ is\n  the dimension of the solution space. We show that the sequences\n  $\\{y^{(i,k)}_n\\}$ are linear independent. This is clear for\n  sequences of different index $i$. It is also clear for different roots,\n  because for $n\\to\\infty$ the exponential function nullifies the\n  influence of the polynomials.\n  \n  It remains to show that the sequences $\\{y^{(i,k)}_n\\}$ in fact are\n  solutions of the difference equations.  For $k=0$ we have proven\n  this already in lemma~\\ref{Lemma:difference-equation-solutions}.  We proof the fact here for\n  $k=2$ and for a double zero $\\xi_i$; the principle for higher order\n  roots should be clear then.  Equation~\\eqref{eq:lmm:3} applied to\n  the sequence $\\{n \\xi_i^n\\}$ results in\n  \\begin{align*}\n    \\sum_{r=0}^{\\lmms} \\alpha_r (n+r) \\xi_i^{n+r}\n    &= n \\xi_i^n \\sum_{r=0}^{\\lmms} \\alpha_r \\xi_i^{r}\n    + \\xi_i^{n+1} \\sum_{r=1}^{\\lmms} \\alpha_r r \\xi_i^{r-1}\n    \\\\\n    &= n \\xi_i^n \\rho(\\xi_i) + \\xi_i^{n+1} \\rho'(\\xi_i) = 0.\n  \\end{align*}\n  Here the term with $\\alpha_0$ vanishes, because it is multiplied\n  with $r=0$. $\\rho(\\xi_i) = \\rho'(\\xi_i) = 0$ because $\\xi_i$ is a\n  multiple root.\n\\end{proof}\n\n\\input{theorems/root-test}\n\n\\begin{proof}\n  According to theorem~\\ref{Theorem:difference-equation-basis} we can write all solutions\n  as linear combinations of the sequences $y^{(i,k)}$ in\n  equation~\\eqref{eq:lmm:6}. Therefore,\n  \\begin{enumerate}\n  \\item all solutions to $|\\xi_i|<1$ for $n\\to\\infty$ converge to zero\n  \\item all solutions to $|\\xi_i|>1$ for $n\\to\\infty$ divergence to infinity\n  \\item all solutions to $|\\xi_i|=1$ for $n\\to\\infty$ stay bounded \n\tif and only if $\\xi_i$ is simple.\n  \\end{enumerate}\n  This proves the statement of the theorem.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Stability and convergence}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{remark}\n  In contrast to one-step methods the convergence of multistep methods\n  follows not directly from the consistency of the method, if the\n  right hand side of the differential equation satisfies the Lipschitz\n  condition~\\eqref{eq:IVP:1}.  Analog to the A-stability we will\n  discuss this by means of a simple model problem and we will deduce\n  stability conditions.\n\\end{remark}\n\n\\begin{remark}\n  In the following we investigate the solution to a fixed point in time\n  $t$ with a shrinking step size $h$. Therefore we choose $n$\n  steps of step size $h = t/n$ and let $n$ go towards infinity.\n\\end{remark}\n\n\\input{definitions/lmm-stability}\n\\input{theorems/lmm-stability}\n\n\\begin{proof}\n  The application of the LMM to the equation~\\eqref{eq:lmm:1} results\n  in the difference equation\n  \\begin{gather*}\n    \\sum_{r=0}^{\\lmms} \\alpha_{\\lmms-r} y_{n-r} = 0.\n  \\end{gather*}\n  Now we have to proof that the solutions for fixed $t = h n$ stay\n  bounded if $h\\to 0$. But we also see that the upper equation does\n  not contain $h$. Therefore we have to examine, if the solutions\n  $y_n$ stay bounded for $n\\to \\infty$.  By resorting the summation we\n  obtain a difference equation of the form~\\eqref{eq:lmm:3}. Due to\n  corollary~\\ref{Corollary:root-test} it follows the statement of the theorem.\n\\end{proof}\n\n\\begin{Corollary}{adams-stability}\n  Adams-Bashforth and Adams-Moulton methods are stable.\n\\end{Corollary}\n\n\\begin{proof}\n  For all of these methods the first generating polynomial is $\\rho(x)\n  = x^\\lmms-x^{\\lmms-1}$. It has the simple root $\\xi_1 = 1$ and the\n  $\\lmms-1$-fold root 0.\n\\end{proof}\n\n\\begin{Theorem}{BDF-stability}\n  The BDF methods are stable for $\\lmms \\le 6$ and not\n  stable for $\\lmms \\ge 7$.\n\\end{Theorem}\n\n\\input{definitions/lmm-convergence}\n\\input{theorems/lmm-one-step}\n\n\\begin{proof}\n  From the general form of LMM we\n  obtain\n  \\begin{gather*}\n    \\frac1{\\alpha_s} \\sum_{r=0}^\\lmms \\alpha_{\\lmms-r} y_{k-r}\n    = \\frac{h}{\\alpha_s} \\sum_{r=0}^{\\lmms-1} \\beta_{\\lmms-r} f_{k-r}\n    + \\beta_s f_k.\n  \\end{gather*}\n  We rewrite this to\n  \\begin{gather*}\n    y_k = -\\sum_{r=1}^{\\lmms} \\alpha'_{\\lmms-r} y_{k-r} +\n    h\\psi_h(t_{k-1}, Y_{k-1}),\n  \\end{gather*}\n  where we implicitly enter this formula as value for $y_k$ in the\n  computation of $f_k$. It remains to realize that this is the first\n  set of $d$ equations in~\\eqref{eq:lmm-one-step:1}, and that the\n  remaining ones are just shifting $y_i$ to $y_{i+1}$.\n\\end{proof}\n\n\\input{theorems/lmm-one-consistency}\n\n\\begin{proof}\n  The first component of $Y_k - \\widehat Y_k$ is the local error of\n  step $k$, which is of order $h^{p+1}$ by the assumption. The other\n  components vanish by the definition of the method.\n\\end{proof}\n\n\\input{theorems/lmm-one-stability}\n\n\\begin{proof}\n  We notice that $\\widehat\\rho(x) = \\sum \\alpha'_{s-r} x^r$ is the\n  characteristic polynomial of the matrix $A$ and thus its eigenvalues\n  are the roots of $\\widehat\\rho(x)$, which has the same roots as the\n  generating polynomial $\\rho(x)$. By the root test, we know that\n  simple roots, which correspond to irreducible blocks of dimension\n  one have maximal modulus one. Furthermore, every Jordan block of\n  dimension greater than one corresponds to a multiple root, which by\n  assumption has modulus strictly less than one. It is easy to see\n  that such a block admits a modified canonical form\n  \\begin{gather*}\n    J_i =\n    \\begin{pmatrix}\n      \\lambda_i & 1- \\abs{\\lambda_i}\\\\\n        & \\lambda_i &\\ddots\\\\\n          &&\\ddots & 1- \\abs{\\lambda_i}\\\\\n            &&&\\lambda_i\n    \\end{pmatrix}.\n  \\end{gather*}\n  Thus, the canonical form $J = T^{-1}AT$ has norm $\\norm{J}_{\\infty}\n  \\le 1$. If we define the norm\n  \\begin{gather*}\n    \\norm{x} = \\norm{(T^{-1}\\otimes \\identity)x}_\\infty,\n  \\end{gather*}\n  we obtain the result by\n  \\begin{multline*}\n    \\norm{(A\\otimes \\identity)x}\n    = \\norm{(T^{-1}\\otimes \\identity)(A\\otimes \\identity)x}_\\infty\n    = \\norm{(J\\otimes \\identity)(T^{-1}\\otimes \\identity)x}_\\infty\n    \\\\\n    \\le \\norm{(T^{-1}\\otimes \\identity)x}_\\infty\n    = \\norm{x}.\n  \\end{multline*}\n\\end{proof}\n\n\\input{theorems/lmm-convergence}\n\n\\begin{proof}\n  We reduce the proof to convergence of a one-step method with\n  \\begin{gather}\n    \\label{eq:lmm:18}\n    Y_k = G(Y_{k-1}) =  (A\\otimes \\identity) Y_{k-1} + h \\verfahren_h(t_{k-1}, Y_{k-1}).\n  \\end{gather}\n  Let $Y_{k-1}$ and $Z_{k-1}$ be two initial values for the interval $I_k$.\n  By the previous lemma, we have in the norm defined there, for\n  sufficiently small $h$, and assuming a Lipschitz constant $L_h$ for\n  $\\verfahren_h$ :\n  \\begin{gather}\n    \\label{eq:lmm:19}\n    \\norm{G(Y_{k-1})-G(Z_{k-1})} \\le (1+h L_h) \\norm{Y_{k-1}-Z_{k-1}}.\n  \\end{gather}\n  Thus, the local error $\\eta_k = U_k - \\widehat Y_k$ at step $k$, which by\n  Lemma~\\ref{Lemma:lmm-one-consistency} is bounded by $M h^{p+1}$, accumulates\n  until step $n$ at most to $h^{p+1}(1_h L_h)^{n-k}$.\n\n  We have:\n  \\begin{align*}\n    \\norm{U_1 - Y_1} &\\le (1+h L_h)\\norm{U_0-y_0} + M h^{p+1} \\\\\n    \\norm{U_2 - Y_2} &\\le (1+h L_h)^2\\norm{U_0-y_0} +  M h^{p+1} \\bigl(1+ (1+h L_h)\\bigr)\\\\\n    \\norm{U_3 - Y_3} &\\le (1+h L_h)^3\\norm{U_0-y_0} +  M h^{p+1} \\Bigl(\\bigl(1+ (1+h L_h)+ (1+h L_h)^2\\bigr)\\Bigr)\\\\\n    \\norm{U_n-Y_n} &\\le e^{n h L_h}\\norm{U_0-Y_0} +\n    \\frac{M h^p}{L_h}\\bigl(e^{n h L_h} - 1\\bigr).\n  \\end{align*}\n\\end{proof}\n\n\\subsection{Starting procedures}\n\n\\begin{intro}\nIn contrast to one-step methods, where the numerical solution is obtained \nsolely from the differential equation and the initial value, multistep \nmethods require more than one start value. An LMM with $s$ steps requires $s$ \nknown start values $y_{k-s}, \\dots, y_{k-1}$. Mostly, they are not provided \nby the IVP itself. Thus, general LMM decompose into two parts: \n\\begin{itemize}\n\\item a \\emph{starting phase} where the start values are computed in a \nsuitable way and\n\\item a \\emph{run phase} where the LMM is executed. \n\\end{itemize}\nIt is crucial that the method of the starting phase provides a suitable order \ncorresponding to the LMM of the run phase, recall Definition \n\\ref{Definition:lmm-convergence}. Moreover, it should have analog properties to \nthe LMM, like explicit/implicit or applicability to stiff problems. \n% We now consider different starting procedures for an implicit LMM with \n% convergence order $p$. According to Definition \\ref{Definition:lmm-convergence} \n% the starting values are required to have the same convergence order. \nPossible choices for the starting phase include multistep methods with variable \norder and one-step methods.  \n\\end{intro}\n\n\\begin{example}[Self starter]\nA 2-step BDF method requires $y_0$ and $y_1$ to be known. $y_0$ is given by the \ninitial value while $y_1$ is unknown so far. To guarantee that the method has \norder 2, $y_1$ needs to be locally of order 2 at least\n\\begin{align}\\label{eq:lmm_1BDFstarter}\n|u(t_1)-y_1| \\leq c_0 h^2.\n\\end{align}\nThis is ensured, for example, by one step of the 1-step BDF method.\n\nHowever, starting an LMM with $s>2$ steps by a first-order method and then \nsuccessively increasing the order until $s$ is reached does not provide the \ndesired global order. That is due to the fact that the first step limits  \nthe overall convergence order to 2, compare \\eqref{eq:lmm_1BDFstarter}. \nNevertheless, self starters are often used in practice. \n\\end{example}\n% In this case local \n% error estimates are used to bound the errors of the starting values and all \n% approximations of the run phase by reducing the step sizes, \n% %. Moreover, also in \n% %the run phase the step sizes are controlled using local error estimates, \n% see the  \n% discussion on step size control in Section \\ref{section:step_size_control}. \n\n\n\\begin{example}[Runge-Kutta starter]\n\\label{Example:RKstarter}\nOne can use Runge-Kutta methods to start LMM. Since only a fixed\nnumber of starting steps are performed, the local order of the\nRunge-Kutta approximation is crucial.  For an implicit LMM with\nconvergence order $p$ and stepsize $h$ one could use an RK method with\nconsistency order $p-1$ with the same stepsize $h$.\n\nConsider a 3-step BDF method. Thus, beside $y_0$, we need start values \n$y_1, y_2$ with errors less than $c_0 h^3$. They can be computed by RK methods \nof consistency order $2$, for example by two steps of the 1-stage Gau\\ss \\ \ncollocation method with step size $h$ since it has consistency order $2s=2$, \nsee theorem \\ref{Theorem:gauss-consistency}.\n\\end{example}\n\n\n\n\n\\begin{example}[Continuous Runge-Kutta starter]\n  Another option is to use continuous Runge-Kutta methods and to\n  evaluate the continuous approximation to obtain the required\n  starting values.\n\n  In constrast to Example \\ref{Example:RKstarter} one could also use\n  the continuous polynomial approximation of Gau\\ss \\ collocation to\n  start a 3-step BDF method. One step with step size $2h$ of a 2-stage\n  Gau\\ss \\ collocation method would give a polynomial of degree $2$\n  which is then evaluated in $t_1=t_0+h$ and $t_2=t_1+h$ to obtain\n  $y_1, y_2$. According to Theorem\n  \\ref{Theorem:collocation-continuous} $y_1, y_2$ have the appropriate\n  order.\n\\end{example}\n\n\\begin{remark}\n  In practice not the order of a procedure is crucial but rather the\n  fact that the errors of all approximations (the start values and all\n  approximations of the run phase) are bounded by the user-given\n  tolerance, compare Section \\ref{section:step_size_control}. Thus,\n  the step sizes of all steps are controlled using local error\n  estimates. Hence, self starting procedures usually start with very\n  small step sizes and increase them successively. Due to their higher\n  orders RK starters usually are allowed to use moderate step sizes in\n  the beginning. Generally, LMM are applied with variable step sizes\n  and orders in practice (see e.g. Exercise 7.2).\n\\end{remark}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{LMM and stiff problems}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{Definition*}{lmm-stability-region}{A-stability of LMM}\n  \\index{stability region!of a LMM}\n  The linear model difference equation\n  \\begin{gather}\n    \\label{eq:lmm:7}\n    \\sum_{r=0}^{\\lmms} \\bigl(\\alpha_{\\lmms-r} - z \\beta_{\\lmms-r}) y_{n-r} = 0.\n  \\end{gather}\n  is obtained by applying an LMM to the model equation\n  $u' = \\lambda u$ and inserting $z=h\\lambda$.\n\n  The \\define{stability region} of an LMM is the set of points $z\\in \\C$,\n  for which all solution sequences $\\{y_n\\}$ of the equation~\\eqref{eq:lmm:7}\n  stay bounded for $n\\to\\infty$. An LMM is called \\define{A-stable}, if the \n  stability region contains the left half-plane of $\\C$.\n\\end{Definition*}\n\n\n\\begin{Definition}{lmm-stability-polynomial}\n  The stability polynomial of an LMM is obtained by inserting\n  $y_n = x^n$ into the linear model difference equation to obtain\n  \\begin{gather}\n    \\label{eq:lmm:8}\n    r_z(x) = \\sum_{r=0}^{\\lmms} \\bigl(\\alpha_{\\lmms-r} - z \\beta_{\\lmms-r})\n    x^{\\lmms-r}.\n  \\end{gather}\n\\end{Definition}\n\n\\begin{remark}\n  Instead of the simple amplification function $r(z)$ of the one-step\n  methods, we get here a function of two variables.  The point $z$ for\n  which we want to show stability and the artificial variable $x$ from\n  the analysis of the method.\n\\end{remark}\n\n\\begin{Lemma}{lmm-stability}\n  Let $\\{\\xi_1(z),\\dots,\\xi_\\lmms(z)\\}$ be the set of roots of the\n  stability polynomial $r_z(x)$ as functions of $z$.\n  A point $z\\in \\C$ is in the stability region of a LMM, if these\n  roots satisfy the root test in corollary~\\ref{Corollary:root-test}.\n\\end{Lemma}\n\n\\begin{proof}\n  The proof is analog to theorem~\\ref{Theorem:lmm-stability}.\n\\end{proof}\n\n\\begin{Theorem*}{dahlquist2}{2nd Dahlquist barrier}\n  \\defindex{Dahlquist barrier (second)} There is no A-stable LMM of\n  order $p>2$. Among the A-stable LMM of order 2, the trapezoidal rule\n  (Crank-Nicolson) has the smallest error constant.\n\\end{Theorem*}\n\n\\subsection{Relaxed A-stability}\n\n\\begin{intro}\n  Motivated by the fact that there are no higher order A-stable LMM\n  and by highly dissipative problems, people have introduced relaxed\n  concepts of A-stability.\n\\end{intro}\n\n\\input{definitions/aa-stability}\n\n\\begin{remark}\n  The introduction of the A(0)-stability is motivated by linear\n  systems of the form $u'=-Au$ with symmetric, positive definite\n  matrix $A$. In fact one requires there only stability on the real\n  axis because all eigenvalues are real. Thus, any positive angle\n  $\\alpha$ is sufficient.\n  \n  Similarly A($\\alpha$)-stable LMM are suitable for linear problems in\n  which high frequently vibration ($\\Im\\lambda$ large) decay fast\n  ($-\\Re\\lambda$ large).\n\n  In all cases one observes corresponding properties of the Jacobian\n  matrix $\\partial_u f$ for the application of nonlinear problems.\n\\end{remark}\n\n\\begin{example}\n  The stability regions of the stable BDF methods are in\n  Figure~\\ref{fig:bdf-stability}. The corresponding values for\n  A($\\alpha$)-stability and stiff stability are in Table  \n\\ref{tab:bdf-stability}.\n\\end{example}\n\\begin{figure}[tp]\n  \\centering\n  \\includegraphics[width=.45\\textwidth]{fig/stability-bdf.png}\n  \\hfill\n  \\includegraphics[width=.45\\textwidth]{fig/stability-bdf-zoom.png}\n  \\caption{Boundaries of stability regions of BDF1 to BDF6. Unstable\n    region right of the origin. Zoom on the right}\n  \\label{fig:bdf-stability}\n\\end{figure}\n\\begin{table}[tp]\n  \\centering\n  \\begin{tabular}{c|cccccc}\n    $k$ & 1 & 2 & 3 & 4 & 5 & 6 \\\\\\hline\n    $\\alpha$ & 90$^\\circ$ & 90$^\\circ$& 86.03$^\\circ$\n                    & 73.35$^\\circ$& 51.84$^\\circ$\n                            & 17.84$^\\circ$ \\\\\n    $D$ & 0 & 0 & 0.083& 0.667& 2.327& 6.075\n  \\end{tabular}\n  \\caption{Values for A($\\alpha$)- and stiff stability for BDF methods\n    of order $k$.}\n  \\label{tab:bdf-stability}\n\\end{table}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Predictor-corrector schemes}\n\n\\begin{Definition*}{predictor-corrector}{Predictor-corrector methods}\n  Assume a pair of time stepping schemes, one explicit, one implicit,\n  \\begin{align*}\n    \\hat y_{k} &= \\hat \\verfahren_p(y_{k-1}) \\\\\n    y_k &= \\verfahren_c(y_{k-1},y_{k}),\n  \\end{align*}\n  we can use $\\hat y_k$ as initial value for the Newton iteration for\n  $y_k$. In an extreme case, we let\n  \\begin{gather*}\n    y_k = \\verfahren_c(y_{k-1},\\hat y_{k}),\n  \\end{gather*}\n  without any further iteration.\n\\end{Definition*}\n\n\\begin{remark}\n  Predictor-corrector methods were developed strongly around\n  Adams-Moulton and Adams-Bashforth methods, since the implicit ones\n  have much smaller error constants. Given that these methods offer no\n  considerable advantages compared to Runge-Kutta methods, but\n  stability properties and implementation are weak points, We omit\n  their discussion.\n\n  A simple predictor for BDF methods can be obtained, since they are\n  based on an interpolating polynomial. Thus, we simply extrapolate\n  this polynomial to the next point in time.\n\\end{remark}\n\n\\begin{example}\n  While the predictor-corrector idea sounds reasonable, we have to be\n  careful with stiff problems, the original reason for using implicit\n  methods. Take again our favorite IVP\n  \\begin{gather*}\n    u' = \\lambda u,\n    \\qquad u(0) = 1.\n  \\end{gather*}\n  We apply the BDF(1) scheme, namely the implicit Euler method, with\n  step size 1. According to its stability\n  function~\\eqref{eq:impl:stabil:impleuler}, we obtain\n  \\begin{gather*}\n    y_1 = \\frac1{1-\\lambda}.\n  \\end{gather*}\n  Hence, the interpolating polynomial is\n  \\begin{gather*}\n    y(t) = (1-t) + \\frac1{1-\\lambda} t = 1 + \\frac{\\lambda}{1-\\lambda}t.\n  \\end{gather*}\n  For the mildly stiff problem $\\lambda = -3$, we obtain\n  \\begin{gather*}\n    y_1 = 0.25, \\qquad y_2 = 0.0625,\n    \\qquad \\hat y_2 = y(2) = -0.5.\n  \\end{gather*}\n  Thus, the extrapolated value is already a much worse initial value\n  for a Newton iteration than using the value from the previous time\n  step.\n  \n  While this example was particularly chosen to exhibit such failure,\n  it does show that extrapolation of stiff problems has its\n  pitfalls. Here, we end up with a time step restriction which is\n  comparable to the stability condition of the explicit method.\n\\end{example}\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End: \n", "meta": {"hexsha": "313f1dbee3c945dd164ddc64a86d489b6dde0e0f", "size": 31202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/lmm.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/lmm.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/lmm.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": 39.5964467005, "max_line_length": 125, "alphanum_fraction": 0.6715595154, "num_tokens": 9603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.6199848234915085}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage[utf8]{inputenc}\n\n\\title{MaS Assignment I\\\\\n\\large The Chirikov Map}\n\\author{Klaas Kliffen s2369494}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nThe Chirikov map is an area preserving chaotic map. It is displayed in a square with 2$\\pi$ as the length of the sides.\n\nThe Chirikov map is defined by the set of functions:\n\\begin{align} \np_{n+1} &= p_n + K \\text{ sin}[2\\pi x_n] / (2*\\pi)\\\\\nx_{n+1} &= x_n + p_{n+1}\n\\end{align}\nThese are taken modulo 1, to produce the following functions:\n\\begin{align} \np_{n+1} &= \\{p_n + K \\text{ sin}[2\\pi x_n] / (2*\\pi)\\} \\text{ mod} 1\\\\ \nx_{n+1} &= \\{x_n + p_{n+1}\\} \\text{ mod} 1\n\\end{align}\n\nTaking the modulo causes the Chirikov map to be displayed in a square with 1 as the length of the sides.\nThe functions take the parameter $K$ as a parameter. The initial conditions are defined by values of $p$ and $x$ each in $[0,1]$.\n\n\\subsection*{Initialisation}\nThe system is initialised by $\\{x_0,p_0\\} \\in [0,1] \\times [0,1]$\n\n\\subsection*{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}\nThe first part of the assignment assumes a fixed value of $K = 1$ and varies the initial conditions. The aim of this part will be to distinguish between different kinds of 'orbits'.\n\n\\subsection*{b) Behaviour for different values of $K$}\nThe second part will use the orbits from the first part and will use a varying value for $K$.\nThe aim of this part will be to explore the changing orbits for an increasing value of $K$\n\n\\section{Methods}\nThis section globally describes the adapted functions used in this assignment.\n\n\\subsection*{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}\nTo generate the values describing the orbit, a step function is created to accept 2 coordinates and calculates the next coordinates from the equations 3 and 4.\nThis function can be used to explore the different kind of orbits given the initial values.\\\\\nFor each initial value, the first thousand iterations are run. To determine the order in which points are visited, another number of iterations may be given. These will be noted in the result section.\\\\\n\n\\subsection*{b) Behaviour for different values of $K$}\nTo plot multiple orbits for a given $K$, the step function is called multiple times, each with different pseudo-random initial values. The calculated values are then stored in two arrays to be plotted.\\\\\nFor each value of K, 50 orbits are calculated with pseudo random initial conditions, each with 1000 iterations.\n\n\\section{Results}\n\\subsection{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}\nThere are three types of orbits that can be found. These will be addressed each in its own section.\n\\subsubsection{Points}\nBarely visible are two single points in figure \\ref{pointorbit} at $(0,0.5)$ and $(0.5,0.5)$. From figure \\ref{pointval} it is clear that $p$ stays constant, with $x$ switching between the two points. The value of $p$ is constant, because in formula (3) the sinus component is constant with $x$ varying between two values: 0 and 0.5, both yielding a zero value for the sinus. Since $p$ is constant at 0.5, from formula (4), it is clear that x with initial condition 0.5, can only be 0 and 0.5 in an alternating order. Therefor, only 20 iterations are shown in figure \\ref{pointval}.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/orbitpoint.png}\n\\caption{Orbit plot of two points}\n\\label{pointorbit}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/valuepoint.png}\n\\caption{The values for $p$ and $x$ in the first 20 iterations}\n\\label{pointval}\n\\end{figure}\n\n\\subsubsection{Curves}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/orbitcurve.png}\n\\caption{Orbit plot of four curves}\n\\label{curveorbit}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/valuecurve.png}\n\\caption{The values for $p$ and $x$ in the first 250 iterations }\n\\label{curveval}\n\\end{figure}\n\n\\newpage\n\nFigure \\ref{curveorbit} represent curves. These curves are closed and symmetrical.The values of $p$ are in two ranges: a higher range, yielding the top curve and a lower range, yielding the lower curve. The value of $x$ varies in one range. In figure \\ref{curveval} it can be seen that $x$ varies between two peaks. The curves are visited in a fixed order as figure \\ref{curveval} shows for the first 250 iterations. The top curve is visited first with a few iterations. After that, the bottom curve is visited with with a similar amount of iterations.\n\n\\subsubsection{Areas}\nIn figure \\ref{areaorbit} two dotted areas can be seen. One on the top layer and one on the bottom. These areas seem to be symmetrical around the centre point of the image. These areas seem to be filled with chaotic values. In figure \\ref{areaval} the values for $p$ seem to be on the lower half of the image, but after about 300 iterations, these values seem to spike to the upper half of the image. The values for $x$ seem to be chaotic and spread about all of the $[0,1]$ range.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/orbitarea.png}\n\\caption{Orbit plot of two areas}\n\\label{areaorbit}\n\\end{figure}\n\n\\newpage\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.9\\textwidth]{img/valuearea.png}\n\\caption{The values for $p$ and $x$ in the first 500 iterations}\n\\label{areaval}\n\\end{figure}\n\n\\subsection{b) Behaviour for different values of $K$}\n\nThe figures 7 to 22 are taken at different values for $K$ in an increasing order.\n\n\\subsubsection{Increasing value of $K$}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k0.png}\n\\caption{Orbits for $K = 0$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k01.png}\n\\caption{Orbits for $K = 0.1$}\n\\end{minipage}\n\\end{figure}\n\nFor value $K=0$ the orbits are plotted in figure 7. These are all horizontal lines. Since the sinus component form formula (3) is completely neglected, this value is constant. The value for $x$ however, could be anywhere in the range of [0,1]. This yields horizontal lines.\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k025.png}\n\\caption{Orbits for $K = 0.25$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k05.png}\n\\caption{Orbits for $K = 0.5$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k075.png}\n\\caption{Orbits for $K = 0.75$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k095.png}\n\\caption{Orbits for $K = 0.95$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/kc.png}\n\\caption{Orbits for $K_c = 0.97164$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k098.png}\n\\caption{Orbits for $K = 0.98$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k1.png}\n\\caption{Orbits for $K = 1.0$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k125.png}\n\\caption{Orbits for $K = 1.25$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k15.png}\n\\caption{Orbits for $K = 1.5$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k175.png}\n\\caption{Orbits for $K = 1.75$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k2.png}\n\\caption{Orbits for $K = 2.0$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k225.png}\n\\caption{Orbits for $K = 2.25$}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k25.png}\n\\caption{Orbits for $K = 2.5$}\n\\end{minipage}\\hfill\n\\begin{minipage}{0.5\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{img/k3.png}\n\\caption{Orbits for $K = 3.0$}\n\\end{minipage}\n\\end{figure}\n\nIn figures 8 to 12 ($K$ values in the range of [0.1,0.95]) it can be seen that the straight lines at $K = 0$ slowly curve into two curves at the horizontal centre of the image. In between are similar structures of curves visible.\n\nAbove  $K = 0.75$ areas of chaotic dots appear and take up most of the image after $K = 2$, destroying the curves in the centre of the image.\nAfter values of 3.0 for $K$ most of the area of the image is taken up by the chaotic region.\\\\\n\nAround $K = 1.25$ six smaller curves can be seen on the edges of the two large curves on the top and the bottom of the image. These become bigger and move outwards away from the centre of the large curve. When $K$ reaches a value of 2.0, these satellite curves are dissolved into the chaotic region of the image. This behaviour seems similar to the period doubling of the logistic map. For values of $K$ between 2.25 and 3.0, another instance of these smaller curves can be seen.\n\n\\subsubsection{KAM orbits}\nKAM orbits are orbits spanning the entire range of [0,1]. These only exist below a certain threshold value for $K$ called $K_c$. The value 0.971635 as described by Greene\\cite{kval} is used as the value for $K_c$. Figures 12 to 15 show plots of orbits for values of $K$ between 0.95 and 1.0. Although figures 14 and 15 show orbits spanning the entire range of $[0,1]$, when zooming in, it becomes clear these do not follow a closed curve and are more of a chain of curves.\n\n\\section{Conclusion and discussion}\n\n\\subsection{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}\nFrom the different initial conditions three types of 'orbits' can be determined: Points, curves and areas. Each of these types has a certain order in which points are visited. For point orbits, these are clearly defined. For curves both values will vary in between ranges. For areas, the $x$ value will vary over the complete interval of $[0,1]$ and $p$ will vary only over smaller ranges.\n\n\\subsection{b) Behaviour for different values of $K$}\nFor an increasing value of $K$ the amount of chaotic regions will increase. For values up to $K = 0.9$ the regions will be very small to non existent. After that the regions will grow. For values of $K$ in between $[1.0,1.75]$ and $[2.0,3.0]$ there will be a process similar to period doubling with smaller curves moving outward of the large centre curve. After $K = 3.0$ the image will only consist of the centre two curves and a chaotic region.\\\\\nExploring the limit of KAM orbits around the value of $K_c = 0.971635$ did not lead to observable results. Possibly to issues with the resolution of the plot and the amount of points per orbit plotted.\n\n\\subsection{Discussion}\nThe resolution on the images is limited. It is hard to prove from figures alone that a line could cross the entire horizontal scale of an image and not be distorted by a chaotic region. Depending on the resolution and the amount of points generated for each orbit, the image yield a better view of KAM orbits.\n\n\\begin{thebibliography}{1337}\n\\bibitem{kval}\nGreene, John M.\\\\\n\\emph{A method for determining a stochastic transition}\\\\\nJournal of Mathematical Physics, 20, 1183-1201 (1979)\\\\ DOI:http://dx.doi.org/10.1063/1.524170\n\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "6320ce607aaa67bd94657940d9f31a8015231d9c", "size": 11743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ass1/img2/main.tex", "max_stars_repo_name": "KlaasYK/mas", "max_stars_repo_head_hexsha": "aeaa395c510be2f6a0f12043104865c8f4a1f8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ass1/img2/main.tex", "max_issues_repo_name": "KlaasYK/mas", "max_issues_repo_head_hexsha": "aeaa395c510be2f6a0f12043104865c8f4a1f8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ass1/img2/main.tex", "max_forks_repo_name": "KlaasYK/mas", "max_forks_repo_head_hexsha": "aeaa395c510be2f6a0f12043104865c8f4a1f8df", "max_forks_repo_licenses": ["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.1653846154, "max_line_length": 582, "alphanum_fraction": 0.7510857532, "num_tokens": 3505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390162, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.6199848234915084}}
{"text": "\\chapter{Collisions}\\label{ch:collisions}\nMany musical instruments rely on collisions in some shape or form. Examples are the collision between a hammer and a piano string, a guitar pick and the string, and even the collision between the lips of a trumpet player. \n\nThis work uses collision models that rely on penalising methods. The colliding objects -- although possibly perfectly rigid -- are supposed to interpenetrate, and collision is interpreted as a \\textit{penalty}. The eventual force acting on the colliding objects is then dependent on the level of penetration. For deformable objects, such as the hammer felt tip of a piano, the penalty is dependent on the level of deformation. These collision models were first used in a musical context by e.g. \\cite{Chatziioannou2013, Bilbao2014}.\n\nThe discretisations proposed in \\cite{Chatziioannou2013, Bilbao2014} rely on implicit nonlinear schemes which require an iterative method, such as the Newton-Raphson method presented in Section \\ref{sec:newtonRaphson}, to obtain their solution. \nThe exact number of iterations required per time step, especially in interactive applications, is usually unknown. This could be detrimental to real-time applications, as the number of iterations, and consequently the extra number of computations, could be very large in a particular situation. Furthermore, and perhaps more importantly, existence and uniqueness of the solution might not be available. \n\nIn \\cite{Ducceschi2021} (co-authored by the PhD student [\\hyperref[ch:listOfPublications]{O3}]), Ducceschi et al. propose a method based on quadratisation of the collision potential energy, that circumvents the need of an iterative method to solve nonlinear collisions. Energy quadratisation for explicit schemes first appeared in the context of Port-Hamiltonian systems and was due to Lopes et al. in \\cite{Lopes2015}. The introduction of an additional state variable, which is what Ducceschi's work is based on, was introduced in \\cite{Yang2017, Jiang2019}. Papers \\citeP[D] and \\citeP[E] follow an earlier iteration of the non-iterative collision algorithm from \\cite{Ducceschi2019, Bilbao2019} which exhibited spurious oscillations that Ducceschi et al. resolve in \\cite{Ducceschi2021}. Paper \\citeP[H] uses the corrected collision model for the collision between the lips exciting the trombone. The corrected model will be used in this work and presented in this chapter. \n\nThis chapter first provides a definition for the collision potential as well as its quadratisation, used as the basis for the explicit method. Then, the method will be applied to a simple mass-barrier collision and finally, to a mass-spring -- string collision which can be used to model a finger-fretted string.\n\n\\subsubsection{Collision potential}\nCollisions can be modelled using a nonlinear \\textit{collision potential}, which can be defined as\n\\begin{equation}\\label{eq:potential}\n    \\phi(\\eta) = \\frac{K_\\ctxt}{\\alpha_\\ctxt+1}[\\eta]_+^{\\alpha_\\ctxt+1},\n\\end{equation}\nwith collision stiffness $K_\\ctxt \\geq 0$ (in N/m$^{\\alpha_\\ctxt}$) and dimensionless nonlinear collision coefficient $\\alpha_\\ctxt \\geq 1$. Here $\\eta = \\eta(t)$ describes the relative displacement between the two colliding bodies (in m). The $[\\cdot ]_+$ operator, defined as \n\\begin{equation}\\label{eq:etaPlus}\n    [\\cdot]_+ = \\frac{\\cdot + |\\cdot|}{2},\n\\end{equation}\ndescribes the `positive part of' and when applied to $\\eta$ in Eq. \\eqref{eq:potential} causes the potential $\\phi$ to only be non-zero when the two colliding bodies are in contact. \n% See Figure \\ref{fig:eta}.\n% %\n% \\begin{figure}[h]\n% \\centerline{\\includegraphics[width=0.6\\columnwidth]{figures/interactions/eta.eps}}\n% \\caption{\\label{fig:eta}{A plot of $[\\eta]_+$.}}\n% \\end{figure}\n\nThe derivative of Eq. \\eqref{eq:potential} with respect to $\\eta$ is defined as \n\\begin{equation}\\label{eq:derivPotential}\n    \\phi'(\\eta) = K_\\ctxt[\\eta]_+^{\\alpha_\\ctxt}\n\\end{equation}\nand can then be used in the PDE at hand. \n\nThe issue with this form of the collision potential, is that an iterative method, such as Newton-Raphson presented in Section \\ref{sec:newtonRaphson}, needs to be used in order to solve the system \\cite{Ducceschi2021}.\n\n\\subsubsection{Quadratic form}\nIn \\cite{Ducceschi2021}, the authors propose to rewrite the potential in Eq. \\eqref{eq:derivPotential} in a quadratic form. Using the chain rule and  $\\psi = \\psi(\\eta)$, Eq. \\eqref{eq:derivPotential} can be rewritten as\n\\begin{equation}\\label{eq:quadraticPotential}\n    \\phi'(\\eta) = \\psi\\psi' \\quad \\text{where} \\quad \\psi = \\sqrt{2\\phi} \\quad \\text{and} \\quad \\psi' = \\frac{\\dot{\\psi}}{\\dot{\\eta}}\\ ,\n\\end{equation}\nwhere a dot denotes a single derivative with respect to time. \n\nThis form of the potential can be discretised to a FD scheme that can be solved explicitly. This process will be shown below, using an example of the simple mass -- rigid barrier collision. \n\n\\section{The mass -- rigid barrier collision}\\label{sec:massRigidBarrier}\nAs a test case, a mass colliding with a rigid barrier is presented here, which is arguably the simplest case of a collision. Consider a mass at location $u = u(t)$ (in m) colliding with a barrier at location $b$ (in m).\n\nIf the barrier is placed above the mass, the force it exerts on the mass will be negative and its system would be described as\n\\begin{equation}\\label{eq:massBarrierPre}\n    M\\ddot u = -\\psi\\psi',\n\\end{equation}\nwith mass $M$ (in kg) and $\\psi = \\psi(\\eta)$ and $\\psi'$ are as defined in Eq. \\eqref{eq:quadraticPotential} with $\\eta = \\eta(t) = u(t) - b$. \n\nLooking towards the discretisation the mass-barrier collision, one could use the definitions in Eq. \\eqref{eq:quadraticPotential} to rewrite Eq. \\eqref{eq:massBarrierPre} to the following system of equations\n\\begin{subequations}\\label{eq:massBarrier}\n    \\begin{align}\n        M\\ddot u &= -\\psi g,\\label{eq:massBarrierPDE1}\\\\\n        \\dot\\psi &= g \\dot\\eta,\\label{eq:massBarrierPDE2}\\\\\n        \\eta(t) &= u(t) - b,\\label{eq:massBarrierPDE3}\n    \\end{align}\n\\end{subequations} \nwhere $g = \\psi'$.\n\n\\subsubsection{Relative location of objects}\nWhen working with multiple interacting objcts, it is important to consider whether an object is located `above' or `below' the other, \n%\n% Notice that \n% it is important to keep in mind the relative location of the colliding objects, i.e., whether one object is `above' or `below' an other. \ni.e., which (generally) has a more positive or negative displacement than the other. A mass with a displacement of $0.01$ m will thus be `above' a barrier with a displacement of $-0.05$ m. Along these lines, a positive force acting on an element will accelerate it upwards and a negative force will accelerate it downwards.\n\nThe relative location of the two colliding objects will affect two things in system \\eqref{eq:massBarrier}:\n\nFirstly, the location of the object determines the direction of the collision force, i.e., the sign of the right-hand side in system \\eqref{eq:massBarrier}. In this case, the barrier is placed above the mass, and will exert a downwards (negative) force on the mass during collision. If the barrier was placed below the mass, the opposite would have applied.\n\nSecondly, the definition of $\\eta$ in \\eqref{eq:massBarrierPDE3} is affected by the relative location of the objects. The collision potential in Eq. \\eqref{eq:potential} is only non-zero when $\\eta$ is positive. If the barrier is placed above the mass, $u(t)-b$ will be positive on collision. It is thus important to remember that $\\eta$ should be defined as the element above subtracted from the element below.\n\n\\subsection{Discrete time}\nBefore discretising system \\eqref{eq:massBarrier} in full, the discrete approximation to the collision potential will be elaborated on.\nFollowing \\cite{Ducceschi2021}, $\\psi$ is placed on an interleaved temporal grid (see Section \\ref{sec:firstOrderDiscrete}) using\n\\begin{equation}\\label{eq:psiHalfDef}\n    \\psi^{n-1/2} = \\mu_{t-}\\psi^n,\n\\end{equation} \nwhere the interleaved temporal grid is used here as it results in energy conservation in discrete time (see Section \\ref{sec:energyAnalysisMassBarrier}). Approximations to $\\psi$ and $g$ in Eq. \\eqref{eq:massBarrier} can then be made as \n\\begin{equation}\n    \\psi \\approxeq \\mtp \\psi^{n-1/2}\n\\end{equation}\nand \n\\begin{equation}\\label{eq:approxPsi}\n    g \\approxeq g^n = \\frac{\\delta_{t+}\\psi^{n-1/2}}{\\delta_{t\\cdot}\\eta^n} ,\n\\end{equation}\nrespectively. Notice that applying a first-order difference operator to a grid function on an interleaved grid is second-order accurate.\\footnote{$\\ \\dtp \\psi^{n-1/2}\\ \\overset{\\text{Eq. \\eqref{eq:approxPsi}}}{=}\\ \\dtp \\mtm \\psi^n\\ \\overset{\\text{Eq. \\eqref{eq:identity2}}}{=}\\  \\dtd \\psi^n$ which is second-order accurate (see Section \\ref{sec:FDoperators}).}\nThe result of the approximation in Eq. \\eqref{eq:approxPsi} allows $\\psi$ to be treated as an independent time series:\n\\begin{equation}\n    \\dtp \\psi^{n-1/2} = g^n \\dtd \\eta^n.\n\\end{equation}\nWith the above approximations in place, system \\eqref{eq:massBarrier} can be discretised and yields the following system of equations: \n\\begin{subequations}\\label{eq:massBarrierSystem}\n    \\begin{align}\n        M\\dtt \\un &= -\\left(\\mtp\\psi^{n-1/2}\\right)g^n,\\label{eq:massBarrierSystem1}\\\\\n        \\dtp \\psi^{n-1/2} &= g^n \\dtd \\eta^n,\\label{eq:massBarrierSystem2}\\\\ \n        \\eta^n &= \\un - b.\\label{eq:massBarrierSystem3}\n    \\end{align}\n\\end{subequations}\n\n\n\\subsubsection{An explicit definition for $g^n$}\nTo be able to calculate $\\psi^{n+1/2}$ and $u^{n+1}$ in system \\eqref{eq:massBarrierSystem} explicitly, a definition for $g^n$ only based on known values must be found. As $g^n \\approxeq \\psi'$ as per Eq. \\eqref{eq:approxPsi}, the derivative can be computed analytically according to \n\\begin{equation}\n    g^n = \\psi'\\bigg\\rvert_{\\eta=\\eta^n} \\quad \\overset{\\text{Eq. \\eqref{eq:quadraticPotential}}}{=}\\quad  \\frac{\\phi'}{\\sqrt{2\\phi}}\\bigg\\rvert_{\\eta=\\eta^n}.\n\\end{equation}\nRecalling \\eqref{eq:derivPotential} and \\eqref{eq:potential}, this can conveniently be rewritten to\n\\begin{equation}\\label{eq:gn}\n    g^n = \\frac{K_\\ctxt[\\eta^n]_+^{\\alpha_\\ctxt}}{\\sqrt{\\frac{2K_\\ctxt}{\\alpha_\\ctxt+1}[\\eta^n]_+^{\\alpha_\\ctxt+1}}}=K_\\ctxt\\sqrt{\\frac{\\alpha_\\ctxt+1}{2K_\\ctxt}}[\\eta^n]_+^{\\alpha_\\ctxt}[\\eta^n]_+^{\\frac{-(\\alpha_\\ctxt+1)}{2}}=\\sqrt{\\frac{K_\\ctxt(\\alpha_\\ctxt+1)}{2}}[\\eta^n]_+^{\\frac{\\alpha_\\ctxt-1}{2}}\\,.\n\\end{equation}\nFor implementation purposes, one can expand the $[\\cdot]_+$ operator as the following (equivalent) condition:\n\\begin{subnumcases}{ \\label{eq:gDefOld} g^n =}\n    \\sqrt{\\frac{K_\\text{c}(\\alpha_\\text{c}+1)}{2}}\\cdot(\\eta^n)^{\\frac{\\alpha_\\text{c}-1}{2}},\n    & if $\\eta^n \\geq 0$ \\label{eq:collCorr1Old}\\\\\n    0, & $\\text{if } \\eta^n < 0$\\label{eq:collCorr2Old}\n\\end{subnumcases}\nThis implementation is the one presented in \\cite{Ducceschi2019}, but exhibited spurious oscillations and `sticking' behaviour. This is due to the possibility of negative forces for positive penetrations due to the discontinuity in the definition for $g^n$ at $\\eta^n = 0$.\n\nIn \\cite{Ducceschi2021}, the definition for $g^n$ in \\eqref{eq:gDefOld} is extended, starting out by using an implicit equation for $g^n$ by directly discretising Eq. \\eqref{eq:approxPsi}\n\\begin{equation}\\label{eq:gImp}\n    g_\\text{imp}^n = 2\\frac{\\psi^{n+1/2} - \\psi^{n-1/2}}{\\eta^{n+1} - \\eta^{n-1}}\\ .\n\\end{equation}\nIf there is, however, no collision at $n+1/2$, $\\psi^{n+1/2} = 0$ and Eq. \\eqref{eq:gImp} reduces to\n\\begin{equation*}\n    g_\\text{imp}^n = -2\\frac{\\psi^{n-1/2}}{\\eta^{n+1} - \\eta^{n-1}}\\ .\n\\end{equation*}\nFurthermore, due to the fact that there is no collision, $\\eta^{n+1}$ can be calculated according to $\\eta^{n+1} = \\eta^\\star = u^\\star - b$, where $u^\\star$ is the value of $u^{n+1}$ calculated using the scheme in Eq. \\eqref{eq:massBarrierSystem1} without the collision force. Expanding Eq. \\eqref{eq:massBarrierSystem1} without the collision force yields  \n\\begin{equation*}\n    \\frac{M}{k^2}\\left(u^\\star - 2\\un + u^{n-1}\\right) = 0 \\quad \\Longrightarrow \\quad u^\\star = 2u^n - u^{n-1}.\n\\end{equation*}\nThus, if there is no collision, $g^n_\\text{imp}$ can now be explicitly calculated from known values and be used in the definition for $g^n$ in Eq. \\eqref{eq:gDefOld} according to \\cite{Ducceschi2021}\n\\begin{subnumcases}{ \\label{eq:gDef} g^n =}\n    \\kappa\\sqrt{\\frac{K_\\text{c}(\\alpha_\\text{c}+1)}{2}}\\cdot(\\eta^n)^{\\frac{\\alpha_\\text{c}-1}{2}},\n    & if $\\eta^n \\geq 0,$ \\label{eq:collCorr1}\\\\\n    -2 \\frac{\\psi^{n-1/2}}{\\eta^\\star-\\eta^{n-1}}, & if $\\eta^n < 0\\ \\text{ and } \\ \\eta^{\\star} \\neq \\eta^{n-1},$\\label{eq:collCorr2}\\\\\n    0, & $\\text{if } \\eta^n < 0\\ \\text{ and } \\ \\eta^{\\star} = \\eta^{n-1}.\\qquad$\\label{eq:collCorr3}\n\\end{subnumcases}\n%\nHere, $\\kappa = 1$ if $\\psi^{n-1/2} \\geq 0$, otherwise $\\kappa = -1$ and aims to resolve the `sticking' behaviour by forcing an outwardly-directed force at all times. As was done in paper \\citeP[H], condition \\eqref{eq:collCorr3} has been added to the definition of $g^n$ from \\cite{Ducceschi2021} to prevent a division by 0 in Eq. \\eqref{eq:collCorr2}. \n\nThis definition for $g^n$ does not exhibit the spurious oscillations that the old definition in Eq. \\eqref{eq:gDefOld} did, and can still be explicitly calculated from known values of the system. \n\n\\subsection{Solving the system}\\label{sec:solvingMassBarrier}\nTo implement the system in Eq. \\eqref{eq:massBarrierSystem}, its definitions need to be slightly rewritten. Using identity \\eqref{eq:identity3}, $\\mtp \\psi^{n-1/2}$ can be rewritten to\n\\begin{equation*}\n    \\mu_{t+}\\psi^{n-1/2} = \\frac{k}{2}\\delta_{t+}\\psi^{n-1/2} + \\psi^{n-1/2}.\n\\end{equation*}\nThen, substituting \\eqref{eq:massBarrierSystem2} into this, yields\n\\begin{equation}\\nonumber\n    \\mu_{t+}\\psi^{n-1/2} = \\frac{k}{2}g^n\\delta_{t\\cdot}\\eta^n + \\psi^{n-1/2},\n\\end{equation}\nand inserting this into \\eqref{eq:massBarrierSystem1}, yields\n\\begin{equation}\\label{eq:substitutionFDS}\n    M\\delta_{tt}u^n = -\\left(\\frac{k}{2}g^n\\delta_{t\\cdot}\\eta^n + \\psi^{n-1/2}\\right)g^n\\ .\n\\end{equation}\nAs the position of barrier $b$ is static, the following is true:\n\\begin{equation}\\label{eq:derEtaEqDerU}\n    \\frac{d\\eta}{dt} = \\frac{d}{dt}\\Big(u - b\\Big)\\quad \\Longrightarrow \\quad \\delta_{t\\cdot}\\eta^n = \\delta_{t\\cdot}u^n,\n\\end{equation}\ni.e., the time derivative of $\\eta$ equals the time derivative of $u$.\\footnote{Note that if the barrier was placed underneath the mass, making \\eqref{eq:massBarrierSystem3} $\\eta^n = b-u^n$, this would result in $\\delta_{t_\\cdot}\\eta^n = -\\delta_{t\\cdot}u^n$.} Eq. \\eqref{eq:substitutionFDS} can now be solved explicitly as $u^{n+1}$ is the only unknown in the system\n\\begin{equation}\n    \\bigg(\\frac{M}{k^2} + \\frac{(g^n)^2}{4}\\bigg)u^{n+1} = \\frac{M}{k^2}(2u^n-u^{n-1})+\\frac{(g^n)^2}{4}u^{n-1}-\\psi^{n-1/2}g^n\\ ,\n\\end{equation}\nand can be solved by a simple division. \n\nFinally, $u^{n+1}$ can be used to calculate $\\eta^{n+1}$ by evaluating \\eqref{eq:massBarrierSystem3} at $n+1$:\n\\begin{equation}\\label{eq:etaNPlus1}\n    \\eta^{n+1} = u^{n+1}-b,\n\\end{equation}\nwhich is used to calculate $\\psi^{n+1/2}$ by expanding and rewriting \\eqref{eq:massBarrierSystem2} to\n\\begin{equation}\\label{eq:psiNPlusHalf}\n    \\psi^{n+1/2} = \\psi^{n-1/2} + \\frac{\\eta^{n+1} - \\eta^{n-1}}{2}\\ .\n\\end{equation}\n\nFigure \\ref{fig:massBarrierCollision} shows the mass -- rigid barrier collision over time for two values of $K_\\text{c}$. The mass is initialised with an initial (upwards) velocity using $u^0 = -1$ m and $u^1 = -0.95$ m. The figure shows that the penetration of the mass with the barrier causes a downwards force on the mass. As expected, this force is higher for a larger value of $K_\\ctxt$ and causes the mass to accelerate downwards more quickly.\n\n\\def\\figSpacing{0.01\\textwidth}\n\\def\\figWidth{0.49\\textwidth}\n\\begin{figure}[h]\n    \\centering\n    \\subfloat[$K_\\ctxt = 10^7$. \\label{fig:massBarrierLow}]{\\includegraphics[width=\\figWidth]{figures/interactions/massBarrierLow.eps}}\\hspace{\\figSpacing}\n    \\subfloat[$K_\\ctxt = 10^9$.\\label{fig:massBarrierHigh}]{\\includegraphics[width=\\figWidth]{figures/interactions/massBarrierHigh.eps}}\n    \\caption{The mass -- rigid barrier collision over time with $\\alpha_\\text{c} = 1.3$ for different values of $K_\\text{c}$. \\label{fig:massBarrierCollision}}\n\\end{figure}\n\n\n\\subsection{Energy analysis}\\label{sec:energyAnalysisMassBarrier}\nTo prove that the collision term does not add any additional energy into the system (retaining passivity) and that it does not add additional constraints on the stability of the system, the energy analysis techniques presented in Section \\ref{sec:energyAnalysis} can be used. Notice that for brevity, the steps presented in Section \\ref{sec:energyAnalysis} will not explicitly be followed.\n\nMultiplying Eq. \\eqref{eq:massBarrierSystem1} by $(\\dtd \\un)$ yields \n\\begin{equation*}\n    \\dtp \\h_\\mtxt  = -\\left(\\mtp\\psi^{n-1/2}\\right)g^n (\\dtd \\un)\n\\end{equation*}\nwhere the energy of the mass is defined as (see Eq. \\eqref{eq:energyBalanceMassSpring})\n\\begin{equation}\n    \\h_\\mtxt = \\frac{M}{2}(\\dtm\\un)^2.\n\\end{equation}\nExpanding $g^n$ yields \n\\begin{align*}\n    \\dtp \\h_\\mtxt  &= -\\left(\\mtp\\psi^{n-1/2}\\right)\\frac{\\dtp \\psi^{n-1/2}}{\\dtd \\eta^n}(\\dtd \\un)\\\\\n    \\xLeftrightarrow{\\mystrut\\ \\text{Eq. \\eqref{eq:derEtaEqDerU}}} \\qquad & = -\\left(\\mtp\\psi^{n-1/2}\\right)\\dtp \\psi^{n-1/2},\n\\end{align*}\nwhich, using identity \\eqref{eq:prodIdentity3}, can be rewritten to \n\\begin{equation}\n    \\dtp(\\h_\\mtxt + \\h_\\ctxt) = 0,\n\\end{equation}\nwith collision energy\n\\begin{equation}\\label{eq:collisionEnergy}\n    \\h_\\ctxt = \\frac{(\\psi^{n-1/2})^2}{2}.\n\\end{equation}\nRecall that in order for a scheme to be passive, its energy must be non-negative, and the fact that $\\psi$ is squared proves passivity for system \\eqref{eq:massBarrierSystem}.\n\nFigure \\ref{fig:massBarrierEnergy} shows the energetic output of the mass -- rigid barrier collision corresponding to Figure \\ref{fig:massBarrierLow}. The left panel shows that the kinetic energy of the mass is transferred into the energy of the collision, after which it is converted into kinetic energy of the mass again.\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/interactions/massBarrierEnergy.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.8, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (t) at (-5.8, 0.5) {\\small $\\color{blue}\\mathfrak{h}_\\text{m}$};\n        \\node[] (v) at (-5.8, 0) {\\small $\\color{red}\\mathfrak{h}_\\ctxt$};\n\n      \\end{tikzpicture}\n      \\caption{The energy of the mass (blue), the collision (green) and the total energy (black) of the mass -- rigid barrier collision. The energy corresponds to the behaviour in Figure \\ref{fig:massBarrierLow}. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) shows that the deviation of the energy is within machine precision. \\label{fig:massBarrierEnergy}}\n\\end{figure}\n\n\\section{Mass-spring -- string collision}\\label{sec:massString}\nThe mass-spring -- string collision is slightly trickier than the mass -- rigid barrier collision, as there are two moving components rather than one. This system is chosen as an example as it has the interesting use-case of fretting a string to change the pitch, modelling the fretting finger as a mass.\n\nConsider a lossless stiff string of length $L$, its transverse displacement described by $u = u(x,t)$ (in m) and defined for $t\\geq 0$ and $x\\in \\D$ with domain $\\D = [0, L]$. The mass with displacement $w = w(t)$ (in m) and $t\\geq 0$ will model the fretting finger. The PDE for the stiff string and its parameter definitions can be found in Eq. \\eqref{eq:stiffStringPDENoLosses} and for the mass-spring system in Eq. \\eqref{eq:massSpringPDE}. Placing the string above the mass, the following system emerges:\n\\begin{subequations}\\label{eq:massStringPDE}\n\\begin{align}   \n    \\rho A \\ptt u & =T\\pxx u - EI\\pxxxx u + \\delta(x-x_\\text{m}) \\psi g \\label{eq:massStringPDE1}\\\\\n    M \\ddot w &=-Kw - \\psi g\\label{eq:massStringPDE2}\\\\\n    \\dot\\psi &= g \\dot\\eta,\\label{eq:massStringPDE3}\\\\\n    \\eta(t) &= w(t) - u(x_\\text{m}, t),\\label{eq:massStringPDE4}\n\\end{align}\n\\end{subequations}\nwhere spatial Dirac delta function $\\delta(x-x_\\text{m})$ localises the mass (finger) along the string at location $x_\\text{m} \\in \\D$ (see Eq. \\eqref{eq:spatialDirac}). Furthermore, $\\psi = \\psi(\\eta)$ and $g=\\psi'$ are as defined in Eq. \\eqref{eq:quadraticPotential}. \n\nDiscretising system \\eqref{eq:massStringPDE}, with the collision discretised according to the process explained in Section \\ref{sec:massRigidBarrier}, yields\n\\begin{subequations}\n    \\begin{align}   \n        \\rho A \\delta_{tt}u^n_l & =T\\delta_{xx}u^n_l - EI\\delta_{xxxx}u_l^n + J_l(x_\\text{m}) \\big(\\mu_{t+}\\psi^{n-1/2}\\big)g^n, \\label{eq:massString1}\\\\\n        M \\delta_{tt}w^n &=-Kw^n - \\big(\\mu_{t+}\\psi^{n-1/2}\\big)g^n,\\label{eq:massString2}\\\\\n        \\delta_{t+}\\psi^{n-1/2} &= g^n\\delta_{t\\cdot}\\eta^n,\\label{eq:massString3}\\\\\n        \\eta^n &= w^n - I_l(x_\\text{m})\\uln,\\label{eq:massString4}\n    \\end{align}\n\\end{subequations}\nwhere $l\\in d$ with discrete domain $d=\\{0, \\hdots, N\\}$ and number of grid points along the string $N+1$. Furthermore, spreading and interpolation operators $I_l(x_\\text{m}) = I_{l, o}(x_\\text{m})$ and $J_l(x_\\text{m}) = J_{l, o}(x_\\text{m})$ are as defined in Section \\ref{sec:interpolationSpreading}. The order $o$ is left unspecified. Following the same process as in Section \\ref{sec:solvingMassBarrier}, Eqs. \\eqref{eq:massString1} and \\eqref{eq:massString2} can be rewritten to \n\\begin{subequations}\\label{eq:massStringComb}\n    \\begin{align}\n        \\rho A \\delta_{tt}u^n_l & =T\\delta_{xx}u^n_l - EI\\delta_{xxxx}u_l^n + J_l(x_\\text{m}) \\left(\\frac{k}{2}g^n\\delta_{t\\cdot}\\eta^n + \\psi^{n-1/2}\\right)g^n,\\label{eq:massStringComb1}\\\\\n        M \\delta_{tt}w^n &=-Kw^n - \\left(\\frac{k}{2}g^n\\delta_{t\\cdot}\\eta^n + \\psi^{n-1/2}\\right)g^n,\\label{eq:massStringComb2}\n    \\end{align}\n\\end{subequations}\nwhich can be used as a starting point for solving the system.\n\n\\subsection{Solving the system}\nAs the colliding objects are both moving, Eq. \\eqref{eq:derEtaEqDerU} is not valid anymore and another strategy needs to be used.\nTo start, one must isolate the string at the collision location $x_\\text{m}$ by taking an inner product of Eq. \\eqref{eq:massStringComb1} with $J_l(x_\\text{m})$ over discrete domain $d$. Using identity \\eqref{eq:identityIJ} and dividing all terms by $\\rho A$ yields\n\\begin{align*}\n    \\delta_{tt}I_l(x_\\text{m})u^n_l =c^2I_l(x_\\text{m})\\delta_{xx}u^n_l &- \\kappa^2I_l(x_\\text{m})\\delta_{xxxx}u_l^n \\\\\n    &\\quad + \\frac{\\lVert J_l(x_\\text{m})\\rVert^2_d}{\\rho A} \\left(\\frac{k}{2}g^n\\delta_{t\\cdot}\\eta^n + \\psi^{n-1/2}\\right)g^n.\n\\end{align*}\nwith $c = \\sqrt{T/\\rho A}$ and $\\kappa = \\sqrt{EI/\\rho A}$. Expanding the temporal FD operators yields \n\\begin{equation}\\label{eq:stringMassunp1}\n    I_l(x_\\text{m})u_l^{n+1} = u^\\star+ \\underbrace{\\frac{\\lVert J_l(x_\\text{m})\\rVert^2_d k^2}{\\rho A}}_{\\mathfrak{J}_l} \\left(\\frac{(g^n)^2}{4}\\left(\\eta^{n+1}-\\eta^{n-1}\\right) + \\psi^{n-1/2}g^n\\right),\n\\end{equation}\nwhere \n\\begin{equation*}\n    u^\\star = I_l(x_\\text{m})(2u_l^n -u_l^{n-1}) + c^2k^2I_l(x_\\text{m})\\delta_{xx}\\uln- \\kappa^2k^2I_l(x_\\text{m})\\delta_{xxxx}\\uln\n\\end{equation*}\nis the result of the update equation of the string at $x_\\text{m}$ without the collision term. Then, Eq. \\eqref{eq:massString4} evaluated at $n+1$, which is $\\eta^{n+1} = w^{n+1} - I(x_\\text{m})u_l^{n+1}$, can be substituted into Eq. \\eqref{eq:stringMassunp1}, which results in\n\\begin{equation}\\label{eq:expandedMassString1}\n    \\begin{aligned}\n    \\left(1 + \\mathfrak{J}_l\\frac{(g^n)^2}{4}\\right)I_l(x_\\text{m})u_l^{n+1} - \\mathfrak{J}_l&\\frac{(g^n)^2}{4} w^{n+1}= u^\\star\\\\\n    & + \\mathfrak{J}_l \\left(-\\frac{(g^n)^2}{4}\\eta^{n-1} + \\psi^{n-1/2}g^n\\right).\n    \\end{aligned}\n\\end{equation}\nPerforming this same process on the FD scheme of the mass in Eq. \\eqref{eq:massStringComb2} yields\n\\begin{equation}\\label{eq:expandedMassString2}\n    \\begin{aligned}\n    -\\frac{(g^n)^2 k^2}{4M} I_l(x_\\text{m})u_l^{n+1} + &\\left(1 + \\frac{(g^n)^2 k^2}{4M}\\right)w^{n+1} = w^\\star\\\\\n    & - \\frac{k^2}{M} \\left(-\\frac{(g^n)^2}{4}\\eta^{n-1} + \\psi^{n-1/2}g^n\\right),\n    \\end{aligned}\n\\end{equation}\nwhere \n\\begin{equation*}\n    w^\\star = 2w^n - w^{n-1} - \\frac{Kk^2}{M}w^n\n\\end{equation*}\nis (again) the result of the update equation of the mass without the collision term.\nEquations \\eqref{eq:expandedMassString1} and \\eqref{eq:expandedMassString2} can be treated as a system of linear equations (see Section \\ref{sec:linearEquations}) with unknowns $I_l(x_\\text{m})u^{n+1}$ and $w^{n+1}$. Writing the aforementioned equations in matrix form yields\n\\begin{align}\n    \\begin{bmatrix}\n            I_l(x_\\text{m})u^{n+1}_l\\\\\n            w^{n+1}\n        \\end{bmatrix}\n        = \n        \\mathbf{A}^{-1}\\mathbf{v}\n    \\end{align}\n    where\n    \\begin{equation}\n    \\begin{gathered}\n    \\mathbf{A} = \n        \\begin{bmatrix}\n            \\left(1 + \\mathfrak{J}_l\\frac{(g^n)^2}{4}\\right) & -\\mathfrak{J}_l\\frac{(g^n)^2}{4}\\\\\n            -\\frac{(g^n)^2 k^2}{4M} &\\left(1 + \\frac{(g^n)^2 k^2}{4M}\\right)\n        \\end{bmatrix}\n        \\quad \\text{and}\\\\\n        \\mathbf{v} = \n        \\begin{bmatrix}\n            u^\\star + \\mathfrak{J}_l \\left(-\\frac{(g^n)^2}{4}\\eta^{n-1} + \\psi^{n-1/2}g^n\\right)\\\\\n            w^\\star- \\frac{k^2}{M} \\left(-\\frac{(g^n)^2}{4}\\eta^{n-1} + \\psi^{n-1/2}g^n\\right)\n        \\end{bmatrix}.\n        \\nonumber\n    \\end{gathered}\n\\end{equation}\nFrom this, $\\eta^{n+1}$ can be calculated, and can consequently be applied to the string and mass in system \\eqref{eq:massStringComb}.\n\nFigure \\ref{fig:massStringCollision} shows an implementation of the mass spring collision. The mass is initialised with an upwards initial velocity, where $w^0 = -0.2, w^1 = -0.1$, and collides with the string almost instantly after the start of the simulation. As the first panel shows, the collision model allows for interpenetration of the objects. Immediately after, the collision force accelerates the string upwards and the mass downwards.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/interactions/stringMassCollision.eps}\n    \\caption{The collision of the mass (blue) and the string (red). The collision model allows for interpenetration of the objects as shown in the left panel. \\label{fig:massStringCollision}}\n\\end{figure}\n\n\\subsection{Energy analysis}\nThis section follows Section \\ref{sec:energyAnalysis} without explicitly following the steps for brevity. \n\nOne can obtain the energy of the stiff string FD scheme in Eq. \\eqref{eq:massString1} by taking the inner product of scheme by $(\\dtd \\uln)$ over discrete domain $d$ to obtain \n\\begin{equation}\\label{eq:rOCEnergyString}\n    \\dtp \\h_\\text{s} = \\left\\langle (\\dtd \\uln), J_l(x_\\text{m})\\left(\\mtp \\psi^{n-1/2}\\right)g^n\\right\\rangle_d\n\\end{equation}\nwhere the energy of the string is (see Eq. \\eqref{eq:energyBalanceStiffString})\n\\begin{equation*}\n    \\begin{gathered}\n        \\h_\\text{s} = \\t_\\text{s} + \\v_\\text{s}, \\qwiq \\t_\\text{s} = \\frac{\\rho A}{2}\\lVert\\dtm \\uln\\rVert^2_d,\\quad \\text{and} \\\\\n        \\v_\\text{s} = \\frac{T}{2}\\langle\\dxp\\uln, e_{t-}\\dxp\\uln\\rangle_{\\underline{d}} + \\frac{EI}{2}\\langle\\dxx\\uln, e_{t-}\\dxx\\uln\\rangle_{\\overline{\\underline{d}}}\\ .\n    \\end{gathered}\n\\end{equation*}\nEnergy analysis for the mass in Eq. \\eqref{eq:massString2} can be done by multiplying the scheme by $(\\dtd w^n)$ to get \n\\begin{equation}\\label{eq:rOCEnergyMass}\n    \\dtp \\h_\\text{m} = -(\\dtd w^n)\\left(\\mtp \\psi^{n-1/2}\\right)g^n,\n\\end{equation}\nwhere (see Eq. \\eqref{eq:energyBalanceMassSpring})\n\\begin{equation*}\n    \\h_\\text{m} = \\t_\\text{m} + \\v_\\text{m}, \\qwiq \\t_\\text{m} = \\frac{M}{2}(\\dtm w^n)^2, \\qaq \\v_\\text{m} = \\frac{K}{2}w^n e_{t-}w^n.\n\\end{equation*}\nThe total energy in the system is the addition of Eqs. \\eqref{eq:rOCEnergyString} and \\eqref{eq:rOCEnergyMass}, which, using identity \\eqref{eq:identityIJ} for the former, can be written as:\n\\begin{align*}\n    \\dtp(\\h_\\text{s} + \\h_\\text{m}) &= \\Big(I_l(x_\\text{m})(\\dtd \\uln) - (\\dtd w^n)\\Big)\\left(\\mtp \\psi^{n-1/2}\\right)g^n,\\\\\n    &= \\underbrace{\\dtd\\left(I_l(x_\\text{m})\\uln - w^n\\right)}_{-\\dtd \\eta^n}\\left(\\mtp \\psi^{n-1/2}\\right)g^n.\n\\end{align*}\nThen, expanding $g^n$ according to Eq. \\eqref{eq:approxPsi} yields \n\\begin{align*}\n    \\dtp(\\h_\\text{s} + \\h_\\text{m}) &= - \\dtd\\eta^n\\left(\\mtp \\psi^{n-1/2}\\right)\\frac{\\delta_{t+}\\psi^{n-1/2}}{\\delta_{t\\cdot}\\eta^n}\\\\\n    &= -\\left(\\mtp \\psi^{n-1/2}\\right)\\delta_{t+}\\psi^{n-1/2}\n\\end{align*}\nwhich, using identity \\eqref{eq:prodIdentity3}, can be rewritten as\n\\begin{equation}\n    \\dtp(\\h_\\text{s} + \\h_\\text{m} + \\h_\\text{c}) = 0,\n\\end{equation}\nwith collision energy\n\\begin{equation*}\n    \\h_\\text{c} = \\frac{(\\psi^{n-1/2})^2}{2}.\n\\end{equation*}\nAgain, the fact that $\\psi$ is squared here, means that $\\h_\\text{c}$ is non-negative, and proves passivity of the system. \n\nFigure \\ref{fig:massStringCollisionEnergy} shows the energy of the mass-spring collision corresponding to the behaviour shown in Figure \\ref{fig:massStringCollision}. One can observe that energy of the mass is transferred to the string almost immediately after the start of the simulation. Furthermore, the figure shows that the mass and the string collide again at $n\\approx 110$. The interpenetration of the two colliding objects can be observed from the small peaks in the value for $\\h_\\ctxt$ at these times. \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/interactions/stringMassCollisionEnergy.eps}\n        };\n    \n        \\node[] (he) at (0.2,0.5) {\\small $\\mathfrak{h}_\\text{e}$};\n\n        \\node[] (h) at (-5.8, 1) {\\small $\\mathfrak{h}$};\n        \\node[] (t) at (-5.8, 0.5) {\\small $\\color{blue}\\mathfrak{h}_\\text{m}$};\n        \\node[] (v) at (-5.8, 0) {\\small $\\color{red}\\mathfrak{h}_\\stxt$};\n        \\node[] (c) at (-5.8, -0.5) {\\small $\\color[HTML]{00DB00}\\mathfrak{h}_\\ctxt$};\n\n      \\end{tikzpicture}\n      \\caption{The energy of the mass (blue), the string (red), the collision (green) and the total energy (black) of the mass-string collision. The energy corresponds to the system in Figure \\ref{fig:massStringCollision}. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) shows that the deviation of the energy is within machine precision. \\label{fig:massStringCollisionEnergy}}\n\\end{figure}\n\\section{Two-sided collision: A connection}\\label{sec:twoSidedCollision}\n\n% As an alternative to the method connections shown in Chapter \\ref{ch:connections} showed ways to connect various resonators using techniques presented in \\cite{theBible}. An alternative method to establish these connections can be devised using the methods presented in this chapter.\n% \n\nUsing the methods presented in this chapter, one could devise a two-sided collision and alter the collision potential in Eq. \\eqref{eq:potential} to \\cite{Bilbao2019}\n\\begin{equation}\\label{eq:twoSidedPotential}\n    \\phi(\\eta) = \\frac{K}{\\alpha_\\ctxt+1}|\\eta|^{\\alpha_\\ctxt+1},\n\\end{equation}\nand taking its derivative with respect to $\\eta$ yields\n\\begin{equation}\n    \\phi'(\\eta) = \\sgn(\\eta)K|\\eta|^{\\alpha_\\ctxt}.\n\\end{equation}\nOne can observe that, as opposed to the (one-sided) potential presented in Eq. \\eqref{eq:potential}, the collision force will be non-zero, for both a positive and negative $\\eta$. This two-sided collision can be used as a connection -- as an alternative to connections presented in Chapter \\ref{ch:connections} -- and has been used in papers \\citeP[D] and \\citeP[E] in combination with Eq. \\eqref{eq:potential} to model the mechanics of the tromba marina. See Chapter \\ref{ch:tromba} for more details.", "meta": {"hexsha": "bc87f1d93bc73c7f93c528bc81aa11160c1d879c", "size": 32134, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/interactions/collisions.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/interactions/collisions.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/interactions/collisions.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": 76.8755980861, "max_line_length": 977, "alphanum_fraction": 0.7048920147, "num_tokens": 10435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199511728004, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6199848225920694}}
{"text": "\\chapter{Derivations}\\label{app:derivations}\n\\def\\Psilp{\\Psi_{l+1}^n}\n\\def\\Psilm{\\Psi_{l-1}^n}\n\\def\\Psinp{\\Psi_l^{n+1}}\n\\def\\Psinm{\\Psi_l^{n-1}}\n\n\\section{Webster's update equation (Eq. \\eqref{eq:webstersUpdateEq})}\\label{app:webstersUpdateEq}\nThis section derives the update equation for Webster's equation in Eq. \\eqref{eq:webstersUpdateEq}:\n\\begin{align*}\n    &\\begin{aligned}\n    \\frac{\\Sbar}{k^2}(\\Psi_l^{n+1} - 2\\Psiln+\\Psi_l^{n-1}) &= c^2\\bigg((\\dxm \\Sp)(\\mxm \\dxp \\Psiln)\\\\\n    & + (\\mxm \\Sp)(\\dxm \\dxp \\Psiln)\\bigg),\\\\\n    \\Psinp - 2\\Psiln+\\Psinm &= \\frac{c^2k^2}{\\Sbar}\\bigg(\\frac{1}{h}(\\Sp - \\Sm)\\frac{1}{2h}\\overbrace{(\\Psilp -\\Psilm)}^{\\mxp\\dxm\\Psiln = \\delta_{x\\cdot}\\Psiln}\\nonumber\\\\\n    &+\\frac{1}{2}(\\Sp + \\Sm)\\frac{1}{h^2}(\\Psilp-2\\Psiln+\\Psilm)\\bigg),\n    \\end{aligned}\\\\[-0.5em]\n    &\\begin{aligned}\n        \\Psinp &= 2\\Psiln -\\Psinm +\\overbrace{\\frac{\\lambda^2}{2\\Sbar}}^{\\lambda = \\frac{ck}{h}}\\Big(\\Sp\\Psilp - \\Sp\\Psilm\\\\\n        &\\qquad\\qquad - \\Sm\\Psilp + \\Sm\\Psilm+ \\Sp\\Psilp + \\Sp\\Psilm \\\\\n        &\\qquad\\qquad + \\Sm\\Psilp + \\Sm\\Psilm - 2 (\\Sp + \\Sm)\\Psiln\\Big)\\nonumber,\\\\\n        \\Psinp &= 2\\Psiln-\\Psinm+ \\frac{\\lambda^2}{2\\Sbar}\\Big(2\\Sp\\Psilp + 2\\Sm\\Psilm - 4\\Sbar\\Psiln\\Big)\\nonumber,\\\\\n        \\Psinp &= 2\\Psiln-\\Psinm+ \\frac{\\lambda^2\\Sp}{\\Sbar}\\Psilp + \\frac{\\lambda^2\\Sm}{\\Sbar}\\Psilm - 2\\lambda^2\\Psiln\\nonumber,\\\\\n        \\Psinp &= 2(1-\\lambda^2)\\Psiln-\\Psinm+ \\frac{\\lambda^2\\Sp}{\\Sbar}\\Psilp + \\frac{\\lambda^2\\Sm}{\\Sbar}\\Psilm.\n    \\end{aligned}\n\\end{align*}\n\n\\section{Boundary terms Webster's equation (Eq. \\eqref{eq:centStrictDissip})}\\label{app:boundaryWebster}\nThis section derives process of obtaining the values for $\\el$ and $\\er$ such that the boundary terms in Webster's equation are strictly dissipative. \n\nStarting with the second term in the energy balance in Eq. \\eqref{eq:powerBalanceWebster}:\n\\begin{equation}\n    - c^2\\langle\\dtd\\Psiln, \\dxm\\big(\\Sp(\\dxp\\Psiln)\\big)\\rangle_d^{\\el,\\er}.\n\\end{equation}\nUsing identity \\eqref{eq:weightedIdentityMinus}\n\\begin{equation*}\n    \\begin{aligned}\n    \\langle f_l^n, \\dxm g_l^n \\rangle_d^{\\el,\\er}  = -&\\langle \\dxp f_l^n, g_l^n \\rangle_{\\underline{d}}+ f_N^ng_{N-1}^n - f_0^ng_0^n \\\\\n    &+ \\frac{\\epsilon_\\text{r}}{2}f_N^n(g_N^n-g_{N-1}^n)+ \\frac{\\epsilon_\\text{l}}{2}f_0^n(g_0^n - g_{-1}^n),\n    \\end{aligned}\n\\end{equation*}\nthis can be rewritten to (with $f=\\dtd\\Psi$ and $g = S_{l+1/2}(\\dxp\\Psi)$)\n\\begin{equation*}\n        -c^2\\langle \\dtd\\Psiln,\\dxm \\big(\\Sp(\\dxp\\Psiln)\\big) \\rangle_{d}^{\\epsilon_\\text{l},\\epsilon_\\text{r}} = c^2\\langle \\dtd\\dxp \\Psiln, \\big(\\Sp(\\dxp\\Psiln)\\big)\\rangle_{\\underline{d}} - \\b.\n\\end{equation*}\nwhere\n\\begin{equation}\n    \\b = \\b_\\text{r} - \\b_\\text{l}\n\\end{equation}\nwith\n\\begin{equation*}\n    \\mathfrak{b}_\\text{r} =  \\begin{aligned}[t]\n        &c^2 (\\dtd\\Psi_N^n)\\Big(S_{N-1/2}\\overbrace{(\\dxp\\Psi_{N-1}^n)}^{(\\dxm\\Psi_{N}^n)}\\Big)\\\\\n        &+ \\frac{\\epsilon_\\text{r}}{2}(\\dtd\\Psi_{N}^n)\\Big(S_{N+1/2}(\\dxp\\Psi_N^n)- S_{N-1/2}\\underbrace{(\\dxp \\Psi_{N-1}^n)}_{(\\dxm\\Psi_{N}^n)}\\Big)\n    \\end{aligned}\n\\end{equation*}\nand \n\\begin{equation*}\n    \\mathfrak{b}_\\text{l} = \\begin{aligned}[t]\n        &c^2(\\dtd\\Psi_0^n)\\Big(S_{1/2}(\\dxp\\Psi_0^n)\\Big)\\\\\n        & -\\frac{\\epsilon_\\text{l}}{2}(\\dtd\\Psi_0^n)\\Big(S_{1/2}(\\dxp\\Psi_0^n)-S_{-1/2}\\underbrace{(\\dxp\\Psi_{-1}^n)}_{(\\dxm\\Psi_0^n)}\\Big)\n    \\end{aligned}\n\\end{equation*}\nwhich can be rewritten to\n\\begin{align}\n    \\b_\\text{r} &= c^2(\\dtd\\Psi_N^n)\\left(\\frac{\\epsilon_\\text{r}}{2}S_{N+1/2}(\\dxp \\Psi_N^n) + \\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)S_{N-1/2}(\\dxm\\Psi_N^n)\\right),\\\\\n    \\b_\\text{l} &= c^2(\\dtd\\Psi_0^n)\\left(\\frac{\\epsilon_\\text{l}}{2}S_{-1/2}(\\dxm\\Psi_0^n)+\\left(1-\\frac{\\epsilon_\\text{l}}{2}\\right)S_{1/2}(\\dxp \\Psi_0^n))\\right).\n\\end{align}\n% \\\\\n% &= \\\\\n% &\\qquad - c^2(\\dtd\\Psi_0^n)\\left(\\frac{\\epsilon_\\text{l}}{2}S_{-1/2}(\\dxm\\Psi_0^n)+\\left(1-\\frac{\\epsilon_\\text{l}}{2}\\right)S_{1/2}(\\dxp \\Psi_0^n))\\right)\n\nThen, for the centred radiating boundary condition in Eq. \\eqref{eq:centRadBound} to be strictly dissipative, i.e., $\\dxd \\Psiln = 0 \\ \\Rightarrow \\ \\b_\\text{r} = 0$ the special choice for $\\epsilon_\\text{r} = S_{N-1/2} / \\mu_{xx}S_N$ needs to be made:\n\\begin{equation}\n    \\begin{aligned}\n        \\mathfrak{b}_\\text{r} &= c^2 (\\dtd\\Psi_N^n)\\!\\left(\\frac{S_{N-1/2}}{2\\mu_{xx}S_N}S_{N+1/2}(\\dxp\\Psi_N^n)+\\left(1\\!-\\!\\frac{S_{N-1/2}}{2\\mu_{xx}S_N}\\right)\\!S_{N-1/2}(\\dxm\\Psi_N^n)\\!\\right),\\\\\n        &= c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(\\frac{S_{N+1/2}}{2\\mu_{xx}S_N}(\\dxp\\Psi_N^n)+\\left(1-\\frac{S_{N-1/2}}{2\\mu_{xx}S_N}\\right)(\\dxm\\Psi_N^n)\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{S_{N-1/2}}{2\\mu_{xx}S_N}\\right)\\left(\\frac{\\frac{S_{N+1/2}(\\dxp\\Psi_N^n)}{2\\mu_{xx}S_N}}{\\left(1-\\frac{S_{N-1/2}}{2\\mu_{xx}S_N}\\right)}+\\dxm\\Psi_N^n\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)\\left(\\frac{\\frac{S_{N+1/2}(\\dxp\\Psi_N^n)}{2\\mu_{xx}S_N}}{\\left(\\frac{2\\mu_{xx}S_N - S_{N-1/2}}{2\\mu_{xx}S_N}\\right)}+\\dxm\\Psi_N^n\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)\\left(\\frac{S_{N+1/2}(\\dxp\\Psi_N^n)}{2\\mu_{xx}S_N - S_{N-1/2}}+\\dxm\\Psi_N^n\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)\\left(\\frac{S_{N+1/2}(\\dxp\\Psi_N^n)}{S_{N+1/2} + S_{N-1/2} - S_{N-1/2}}+\\dxm\\Psi_N^n\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)\\left(\\dxp\\Psi_N^n+\\dxm\\Psi_N^n\\right),\\\\\n        &=c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)\\left(\\frac{1}{h}\\left(\\Psi_{N+1}^n - \\Psi_N^n + \\Psi_N^n - \\Psi_{N-1}^n\\right)\\right),\\\\\n&= c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(1-\\frac{\\epsilon_\\text{r}}{2}\\right)2(\\delta_{x\\cdot}\\Psi_N^n),\\\\\n&= c^2 (\\dtd\\Psi_N^n)S_{N-1/2}\\left(2-\\epsilon_\\text{r}\\right)(\\delta_{x\\cdot}\\Psi_N^n).\n    \\end{aligned}\n\\end{equation}\nThe same can be done for $\\mathfrak{b}_\\text{l}$ with $\\epsilon_\\text{l} = S_{1/2}/\\mu_{xx}S_0$ to get\n\\begin{equation}\n    \\mathfrak{b}_\\text{l} = c^2(\\dtd\\Psi_0^n)S_{1/2}\\left(2-\\epsilon_\\text{l}\\right)(\\delta_{x\\cdot}\\Psi_0^n).\n\\end{equation}\n\n\\section{Derivatives for Newton-Raphson for the elasto-plastic friction model (Eq. \\eqref{eq:NRit})}\\label{app:elastoDeriv}\nRecalling the functions needed for to compute the Newton-Raphson iteration for the elasto-plastic bow model in Section \\ref{sec:elastoPlastic}, being Eq. \\eqref{eq:elastog1}\n\\begin{equation*}\n    g_1(v^n,z^n) = \\left(\\frac{2}{k} + 2\\sz\\right)v^n + \\lVert J_l(x_\\Btxt^n)\\rVert_d^2\\frac{f(v^n,z^n)}{\\rho A}+ b^n= 0,\n\\end{equation*}\nand Eq. \\eqref{eq:elastog2}:\n\\begin{equation*}\n    g_2(v^n, z^n) = r^n - a^n = 0,\n\\end{equation*}\nthe derivatives needed to solve the Newton-Raphson iteration in Eq. \\eqref{eq:NRit} \n\\begin{equation*}\n    \\begin{bmatrix}\n        v^n\\\\\n        z^n\n        \\end{bmatrix}_{i+1}\n        =\n        \\begin{bmatrix}\n        v^n\\\\\n        z^n\n        \\end{bmatrix}_i\n        -\n        \\begin{bmatrix}\n        \\frac{\\partial g_1}{\\partial v} & \\frac{\\partial g_1}{\\partial z}\\\\\n        \\frac{\\partial g_2}{\\partial v} & \\frac{\\partial g_2}{\\partial z}\\\\\n        \\end{bmatrix}^{-1}\n        \\begin{bmatrix}\n        g_1\\\\\n        g_2\n        \\end{bmatrix}\\,\n        .\n\\end{equation*}\ncan be shown to be\n\\begin{align*}\n    \\frac{\\partial g_1}{\\partial v} &= \\frac{2}{k} + 2\\sigma_0 + \\frac{s_1\\lVert J_l(x_\\Btxt^n)\\rVert_d^2}{\\rho A}\\frac{\\partial r}{\\partial v}+\\frac{s_2\\lVert J_l(x_\\Btxt^n)\\rVert_d^2}{\\rho A},\\\\\n    \\frac{\\partial g_1}{\\partial z} &= \\frac{s_0\\lVert J_l(x_\\Btxt^n)\\rVert_d^2}{\\rho A} + \\frac{s_1\\lVert J_l(x_\\Btxt^n)\\rVert_d^2}{\\rho A}\\frac{\\partial r}{\\partial z},\\\\\n    \\frac{\\partial g_2}{\\partial v} &= \\frac{\\partial r}{\\partial v}\n    \\\\\\frac{\\partial g_2}{\\partial z}&= \\frac{\\partial r}{\\partial z} -\\frac{2}{k}.\n\\end{align*}\nRecalling from Eq. \\eqref{eq:r} that\n\\begin{equation*}\n    r^n = r(v^n,z^n) = v^n\\bigg[1-\\alpha(v^n,z^n)\\frac{z^n}{z_\\text{ss}(v^n)}\\bigg]\n\\end{equation*}\nits derivatives can be computed as\n\\begin{align*}\n    \\frac{\\partial r}{\\partial v} &= 1-z^n\\Bigg(\\frac{(\\alpha^n+\\frac{\\partial \\alpha^n}{\\partial v}v^n)z_\\text{ss}^n - \\frac{\\partial z_\\text{ss}^n}{\\partial v}\\alpha^n v^n}{(z_\\text{ss}^n)^2}\\Bigg),\\\\\n    \\frac{\\partial r}{\\partial z} &= -\\frac{v^n}{z_\\text{ss}^n}\\bigg(\\frac{\\partial \\alpha^n}{\\partial z}z^n + \\alpha^n\\bigg),\n    \\end{align*}\nwith\n\\begin{align*}\n    \\frac{\\partial\\alpha^n}{\\partial v} &=\\sgn(z_\\text{ss}^n)\\frac{\\partial z_\\text{ss}^n}{\\partial v}\\frac{z_\\text{ba} - |z^n|}{(|z_\\text{ss}^n| - z_\\text{ba})^2}\\frac{\\pi}{2}\\cos\\big(\\sgn(z^n)\\Phi\\big),\\\\\n    \\frac{\\partial\\alpha^n}{\\partial z}&=\\frac{\\sgn(z^n)\\pi\\cos\\big(\\sgn(z^n)\\Phi\\big)}{2(|z_\\text{ss}^n|-z_\\text{ba})},\\\\\n    \\frac{\\partial z_\\text{ss}^n}{\\partial v} &= -\\frac{2|v^n|}{v_\\text{S}^2 s_0}(f_\\text{S}-f_\\text{C})e^{-(v^n/v_\\text{S})^2}.\n\\end{align*}\n", "meta": {"hexsha": "5127c50f83d4dcdce418e314f8dcd92f0dffe3e0", "size": 8845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/appendices/derivations.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/appendices/derivations.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/appendices/derivations.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": 61.4236111111, "max_line_length": 252, "alphanum_fraction": 0.6088185415, "num_tokens": 3994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6199848207915686}}
{"text": "\\section{Important Shapes in 2D \\& 3D}\r\n\\noindent\r\nIn 2D space $(\\R^2)$, the most common and simple shapes you will encounter are lines and circles.\r\n\\begin{itemize}\r\n\t\\item Lines have a form like $x=1$ or $y=2x+1$.\r\n\t\\item Circles have a form like $\\left(x-1\\right)^2 + \\left(y-2\\right)^2 = 9$.\r\n\\end{itemize}\r\n\r\n\\noindent\r\nIn 3D space $(R^3)$, these 2D shapes have higher dimensional versions: planes, cylinders, and spheres.\r\n\\begin{itemize}\r\n\t\\item{Planes have forms like $x = 1$, $y = 2x+1$, and $z = 2x+3y+5$.\\\\\r\n\t\t\\small{Note the similarity to the equation for lines. One can think of a plane as a line extruded in a direction.}}\r\n\t\\item{Cylinders have forms like $\\left(x-4\\right)^2 + \\left(y-5\\right)^2 = 36$.\\\\\r\n\t\t\\small{Note the similarity to the equation for circles. One can think of a cylinder as a circle extruded away from it's face.}}\r\n\t\\item{Spheres have forms like $\\left(x-7\\right)^2 + \\left(y-8\\right)^2 + \\left(z-9\\right)^2 = 100$.\\\\\r\n\t\t\\small{Note the similarity to the equations for circles. One can think of a sphere as a circle rotated and extruded about its center.}}\r\n\\end{itemize}", "meta": {"hexsha": "b744f4e20e471a1b074aa6cf151727cecb4fd975", "size": 1109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/geometry/importantShapes2D3D.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/geometry/importantShapes2D3D.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/geometry/importantShapes2D3D.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": 61.6111111111, "max_line_length": 138, "alphanum_fraction": 0.6907123535, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6199320996674023}}
{"text": "%auto-ignore\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\n\\begin{document}\n\\section{Standard Hodge propagator for Euclidean space}\\label{Sec:HeatRN}\n\\allowdisplaybreaks\n\nWe will use Propositions~\\ref{Prop:StdCodifInt} and~\\ref{Prop:HeatKerFormulas} to prove in two ways that $\\StdPrpg$ for $\\R^n$ extends smoothly to the blow-up. We will start with the following well known formulas.\n\\begin{Proposition}[Green form and heat kernel for $\\R^n$]\\label{Prop:GreenKernelRn}\nThe Green form for $\\R^n$, which can be equivalently characterized as the unique solution $\\GKer\\in \\DR^n(\\R^n\\times\\R^n\\backslash\\Diag)$ of\n\\begin{equation}\\label{Eq:GrRn}\n\\Laplace_y \\GKer(x,y) = \\delta(x-y)(\\Diff{x}^1-\\Diff{y}^1)\\dotsb(\\Diff{x}^n-\\Diff{y}^n),\n\\end{equation}\nwhere $\\delta(x-y)$ is the Dirac delta function, satisfies\n$$ \\GKer(x,y) = \\begin{cases}\n\\displaystyle\\frac{1}{(n-2) \\Vol(\\Sph{n-1})} \\frac{1}{\\Abs{x-y}^{n-2}}(\\Diff{x}^1 - \\Diff{y}^1) \\dotsb (\\Diff{x}^n - \\Diff{y}^n) & \\text{for }n\\ge 3, \\\\[1em]\n-\\dfrac{1}{2\\pi}\\ln \\Abs{x-y}(\\Diff{x}^1 - \\Diff{y}^1)(\\Diff{x}^2 - \\Diff{y}^2)& \\text{for }n=2.\n\\end{cases} $$\nThe heat kernel for $\\R^n$, i.e., the solution of $\\Laplace_y \\QKer_t(x,y) = -\\frac{\\partial}{\\partial t}\\QKer_t(x,y)$,  is given by\n\\begin{equation}\\label{Eq:EuclidHeatKer}\n\\QKer_t(x,y) = (4\\pi t)^{-\\frac{n}{2}}\\exp\\Bigl(-\\frac{\\Abs{x-y}^2}{4t}\\Bigr) (\\Diff{x}^1 - \\Diff{y}^1)\\ldots (\\Diff{x}^n-\\Diff{y}^n).\n\\end{equation}\n\\end{Proposition}\n\\begin{proof}\nSee \\cite{BGV}.\n\\end{proof}\n\n\\begin{Proposition}[Standard Hodge propagator for $\\R^n$]\\label{Prop:StdHodgePropRn}\nThe standard Hodge propagator for $\\R^n$ with $n\\ge 2$ satisfies\n$$\\StdPrpg(x,y) = \\frac{(-1)^{n+1}}{\\Vol(\\Sph{n-1})} \\sum_{i=1}^n (-1)^{i-1} \\frac{x^i-y^i}{\\Abs{x-y}^n}(\\Diff{x}^1 - \\Diff{y}^1)\\dotsb\\reallywidehat{(\\Diff{x}^i - \\Diff{y}^i)}\\dotsb(\\Diff{x}^n-\\Diff{y}^n) $$\nand extends smoothly to $\\Bl_\\Diag(\\R^n\\times \\R^n)$. \n\\end{Proposition}\n\\begin{proof}[Proof using the Green form]\nConsider the formulas from Proposition~\\ref{Prop:GreenKernelRn}. Recall the formula for the codifferential\n\\begin{equation}\\label{Eq:CodiffRn}\n\\CoDd f(x)\\Diff{x}^I = - \\sum_{i\\in I} \\varepsilon(i,I) \\frac{\\partial f(x)}{\\partial x^i} \\Diff{x}^{I\\backslash\\{i\\}}.\n\\end{equation}\nFor $n\\ge 3$, we compute\n\\begin{align*}\n&(\\Id\\otimes\\CoDd_y)\\GKer(x,y) \\\\\n&\\quad=\\frac{1}{(n-2)\\Vol(\\Sph{n-1})} \\sum_I (-1)^{n\\Abs{I}} (\\Id \\otimes \\CoDd_y)\\Bigl(\\frac{1}{\\Abs{x-y}^{n-2}}(\\Star\\Diff{x}^I)\\wedge\\Diff{y}^I\\Bigr) \\\\\n&\\quad=\\frac{1}{\\Vol(\\Sph{n-1})} \\sum_{I} (-1)^{n\\Abs{I} + \\Abs{I} + n+1} \\sum_{i\\in I}\\frac{x^i-y^i}{\\Abs{x-y}^n}\\varepsilon(i,I)(\\Star\\Diff{x}^{I})\\wedge\\Diff{y}^{I\\backslash\\{i\\}}\\\\\n&\\quad=\\frac{1}{\\Vol(\\Sph{n-1})} \\sum_{I} (-1)^{n\\Abs{I} + \\Abs{I} + n+1} \\sum_{i\\in I}\\frac{x^i-y^i}{\\Abs{x-y}^n}\\varepsilon(i,I)\\varepsilon(I,I^c) \\Diff{x}^{I^c}\\wedge\\Diff{y}^{I\\backslash\\{i\\}}\\\\\n&\\quad=\\begin{multlined}[t]\\frac{1}{\\Vol(\\Sph{n-1})} \\sum_{i=1}^n \\frac{x^i-y^i}{\\Abs{x-y}^n} \\sum_{\\substack{J\\subset \\{1,\\dotsc,\\hat{i},\\dotsc,n\\}}}(-1)^{n\\Abs{J} + \\Abs{J}}\\varepsilon(i,J)\\varepsilon(J\\cup\\{i\\},J^c\\backslash\\{i\\})\\\\ \\Diff{x}^{J^c\\backslash\\{i\\}} \\wedge \\Diff{y}^{J}\\end{multlined}\\\\\n&\\quad=\\frac{1}{\\Vol(\\Sph{n-1})} \\sum_{i=1}^n (-1)^{i-1} \\frac{x^i-y^i}{\\Abs{x-y}^n}(\\Diff{x}^1 - \\Diff{y}^1)\\dotsb\\reallywidehat{(\\Diff{x}^i - \\Diff{y}^i)}\\dotsb(\\Diff{x}^n-\\Diff{y}^n).\n\\end{align*}\nIn the last step, we used that\n$$ \\varepsilon(i,J)\\varepsilon(J\\cup\\{i\\},J^c\\backslash\\{i\\}) = (-1)^{i-1}\\varepsilon(J,J^c\\backslash\\{i\\}) $$\nand\n\\begin{align*}\n&\\Diff{x}^{J^c\\backslash\\{i\\}} \\wedge \\Diff{y}^{J}\\\\\n& = (-1)^{\\Abs{J}} \\varepsilon(J^c\\backslash\\{i\\},J)[(\\Diff{x}^1-\\Diff{y}^1)\\dotsb\\reallywidehat{(\\Diff{x}^i-\\Diff{y}^i)}\\dotsb (\\Diff{x}^n-\\Diff{y}^n)]_{J^{c}\\backslash\\{i\\}, J}\\\\\n& = (-1)^{n \\Abs{J} + \\Abs{J}}[(\\Diff{x}^1-\\Diff{y}^1)\\dotsb\\reallywidehat{(\\Diff{x}^i-\\Diff{y}^i)}\\dotsb (\\Diff{x}^n-\\Diff{y}^n)]_{J^{c}\\backslash\\{i\\}, J},\n\\end{align*}\nwhere $[\\cdot]_{I_1,I_2}$ denotes the part of the product which picks the first variable at positions $I_1$ and the second at positions $I_2$. The computation for $n=2$ gives the same result, and the formula for $\\StdPrpg$ is justified by Proposition~\\ref{Prop:StdCodifInt}.\n%\\begin{align*}\n%(\\Diff{x}^1 - \\Diff{y}^1) \\dotsb (\\Diff{x}^n - \\Diff{y}^n) &=\\sum_{k=0}^n(-1)^{n-k} \\sum_{\\substack{I\\subset \\{1,\\dotsc,n\\}\\\\\\Abs{I}=k}} \\varepsilon(I I^c \\mapsto[n])\\Diff{x}^{I} \\wedge \\Diff{y}^{I^c} \\\\\n%&=\\sum_{k=0}^n(-1)^{n-k}\\sum_{\\substack{I \\subset \\{1,\\dotsb,n\\}\\\\\\Abs{I}=k}} \\Diff{x}^I \\wedge (\\Star \\Diff{y}^I)\n%\\end{align*}\n\nWe will now study whether $\\StdPrpg$ extends smoothly to the blow-up. Consider the polar coordinates in one variable\n\\begin{align*}\n\\phi: [0,\\infty) \\times \\Sph{n} \\times \\R^n  &\\longrightarrow \\R^n \\times \\R^n \\\\\n(r,\\omega,u) &\\longmapsto (u+r\\omega, u).\n\\end{align*}\nThere is a unique smooth map $\\tilde{\\phi}$ which fits in the blow-up diagram\n$$\\begin{tikzcd}\n & \\Bl_\\Diag(\\R^n\\times \\R^n)\\arrow{d}{\\pi}\\\\{}\n [0,\\infty)\\times\\Sph{n}\\times\\R^n\\arrow{r}{\\phi}\\arrow{ru}{\\tilde{\\phi}}& \\R^n\\times \\R^n,\n\\end{tikzcd}$$\nand it is a diffeomorphism of manifolds with boundary. We denote by\n$$ \\phi_0 \\coloneqq \\Restr{\\phi}{(0,\\infty) \\times \\Sph{n}\\times\\R^n} : (0,\\infty)\\times\\Sph{n}\\times\\R^n\\longrightarrow \\R^n \\times \\R^n\\backslash\\Diag $$\nthe restriction of $\\phi$ to the interior. The commutative diagram\n$$\\begin{tikzcd}{}\n[0,\\infty)\\times\\Sph{n}\\times\\R^n\\arrow{r}{\\tilde{\\phi}}& \\Bl_\\Diag(\\R^n\\times\\R^n) \\\\\n(0,\\infty)\\times\\Sph{n}\\times\\R^n\\arrow{r}{\\phi_0}\\arrow[hook]{u} & \\R^n\\times\\R^n\\backslash\\Diag \\arrow[hook]{u}{\\tilde{\\iota}}\n\\end{tikzcd}$$\nshows that we can equivalently study whether the form \n$$ \\StdPrpgPol\\coloneqq \\phi_0^* \\StdPrpg $$\nadmits a smooth extension $\\widetilde{\\StdPrpgPol}$ to $[0,\\infty)\\times\\Sph{n-1}\\times\\R^n$. We have\n\\begin{align*}\n\\StdPrpgPol(r,\\omega,u) &= \\phi_0^*\\bigl(\\CoDd_y \\GKer)(r,\\omega,u) \\\\\n& = \\begin{multlined}[t] \n\\frac{(-1)^{n+1}}{r^{n-1}\\Vol(\\Sph{n-1})}\\sum_{i=1}^n (-1)^{i-1} \\omega^i (r\\Diff{\\omega}^1 + \\omega^1 \\Diff{r}) \\dotsb \\reallywidehat{(r\\Diff{\\omega}^i + \\omega^i \\Diff{r})} \\dotsb \\\\ (r\\Diff{\\omega}^n + \\omega^n \\Diff{r})\n\\end{multlined}\\\\\n & = \\begin{aligned}[t]\n \\frac{(-1)^{n+1}}{r^{n-1}\\Vol(\\Sph{n-1})} \\Bigl(r^{n-1}&\\sum_{1\\le i \\le n}(-1)^{i-1}\\omega^i\\Diff{\\omega}^1\\dotsb\\widehat{\\Diff{\\omega}^i}\\dotsb\\Diff{\\omega}^n    \\\\\n  - r^{n-2}&\\sum_{1\\le i < j \\le n}(-1)^{i+j} \\omega^i \\omega^j \\Diff{r}\\Diff{\\omega}^1 \\dotsb \\widehat{\\Diff{\\omega}^i} \\dotsb \\widehat{\\Diff{\\omega}^j} \\dotsb\\Diff{\\omega}^n \\\\\n  + r^{n-2}&\\sum_{1 \\le j < i \\le n}(-1)^{i+j} \\omega^j\\omega^i \\Diff{r} \\Diff{\\omega}^1 \\dotsb \\widehat{\\Diff{\\omega}^j} \\dotsb \\widehat{\\Diff{\\omega}^i} \\dotsb\\Diff{\\omega}^n\\Bigr)\n  \\end{aligned} \\\\\n & = (-1)^{n+1}\\frac{\\Vol_{\\Sph{n-1}}(\\omega)}{\\Vol(\\Sph{n-1})},\n\\end{align*} \nwhere the last two sums canceled. The result extends smoothly beyond $r=0$ because it does not depend on $r$ at all.\n\\end{proof}\n\\begin{proof}[Proof using the heat kernel]\nConsider the polar coordinates with respect to the diagonal\n$$ \\begin{aligned}\n   \\varphi: [0,\\infty)\\times \\Sph{n-1} \\times \\R^n &\\longrightarrow \\R^n \\times \\R^n \\backslash \\Diag \\\\ \n (r,\\omega,u) &\\longmapsto (x,y) = (u+r\\omega, u-r\\omega).\n   \\end{aligned} $$\nThere is a unique smooth map $\\tilde{\\varphi}$ which fits in the blow-up diagram\n$$\\begin{tikzcd}\n & \\Bl_\\Diag(\\R^n\\times \\R^n)\\arrow{d}{\\pi}\\\\{}\n [0,\\infty)\\times\\Sph{n}\\times\\R^n\\arrow{r}{\\varphi}\\arrow{ru}{\\tilde{\\varphi}}& \\R^n\\times \\R^n,\n\\end{tikzcd}$$\nand it is a diffeomorphism of manifolds with boundary. The heat kernel \\eqref{Eq:EuclidHeatKer} transforms under $\\varphi$ as\n\\begin{align*}\n\\QKerPol_t(r,\\omega,u) &\\coloneqq (\\varphi^* \\QKer_t)(r,\\omega,u) \\\\\n & = (4 \\pi t)^{-\\frac{n}{2}} \\exp(-\\frac{r^2}{t}) 2^n r^{n-1} \\Diff{r} \\Vol(\\omega) \\\\\n &= (\\pi t)^{-\\frac{n}{2}} \\exp(-\\frac{r^2}{t}) r^{n-1} \\Diff{r} \\Vol(\\omega).\n\\end{align*}\nIt follows from Proposition~\\ref{Prop:HeatKerFormulas} that for $(r,\\omega,u)\\in (0,\\infty) \\times \\Sph{n-1}\\times \\R^n$ we have\n\\begin{equation}\\label{Eq:StdPrpgPol}\n\\StdPrpgPol(r,\\omega,u) = (-1)^{n+1}\\frac{1}{2}\\lim_{t\\to 0} \\int_t^\\infty \\CoDdPol \\QKerPol_\\tau(r,\\omega,u) \\Diff{\\tau},\n\\end{equation}\nwhere $\\CoDdPol$ is the codifferential on $\\R^n\\times \\R^n$ computed with respect to the pullback of the product Riemannian metric. If $g: \\R^n \\otimes \\R^n\\rightarrow \\R$ is an inner product, then the pullback Riemannian metric satisfies\n\\begin{equation}\\label{Eq:PullbackMetric}\ng^{\\mathrm{pol}}\\coloneqq \\varphi^*(g\\oplus g)(r,\\omega,u) = 2\\begin{pmatrix}\ng(\\omega,\\omega) & 0 & 0 \\\\\n0 & r^2 g & 0 \\\\\n0 & 0 & g\n\\end{pmatrix};\n\\end{equation}\nit is degenerate at the boundary $r=0$. Next, it is easy to check that the conformal transformation $g\\mapsto\\lambda g$ on vectors induces the conformal transformation $g\\mapsto\\frac{1}{\\lambda^k}g$ on $k$-forms. Thus, if $\\Norm{\\cdot}^\\mathrm{pol}$ denotes the point-wise norm with respect to $g^{\\mathrm{pol}}$ for the standard Euclidean metric, then\n$$ \\Norm{\\Diff{r}}^{\\mathrm{pol}} = 2^{-\\frac{1}{2}},\\quad\\Norm{\\Vol(u)}^{\\mathrm{pol}} = 2^{-\\frac{n}{2}},\\quad\\Norm{\\Vol(\\omega)}^{\\mathrm{pol}} = 2^{-\\frac{n-1}{2}} r^{-(n-1)}, $$\nand hence\n$$ \\VolPol(r,\\omega,u) = 2^{n}r^{n-1}\\Diff{r}\\Vol(\\omega)\\Vol(u). $$\nIn order to get the Hodge star $\\StarPol$, we compute\n\\begin{align*}\n\\Diff{r}\\Vol(\\omega)\\wedge \\StarPol \\bigl(\\Diff{r}\\Vol(\\omega)\\bigr) & \\overset{!}{=} {\\Norm{\\Diff{r}\\Vol(\\omega)}^{\\mathrm{pol}}}^2 \\Vol^{\\mathrm{pol}}(r,\\omega,u) \\\\\n&=r^{-(n-1)} \\Diff{r}\\Vol(\\omega)\\Vol(u), \\\\\n\\Diff{r}\\Vol(u) \\wedge \\StarPol(\\Diff{r}\\Vol(u)) &\\overset{!}{=} {\\Norm{\\Diff{r} \\Vol(u)}^{\\mathrm{pol}}}^2\\Vol^{\\mathrm{pol}}(r,\\omega,u) \\\\ \n&=\\frac{1}{2} r^{n-1} \\Diff{r} \\Vol(\\omega) \\Vol(u).\n\\end{align*}\nUsing the product structure \\eqref{Eq:PullbackMetric}, it follows that\n\\begin{align*}\n\\StarPol\\bigl(\\Diff{r}\\Vol(\\omega)\\bigr)&=r^{-(n-1)} \\Vol(u)\\quad\\text{and}\\\\\n\\StarPol(\\Diff{r}\\Vol(u))&= \\frac{1}{2} r^{n-1} \\Vol(\\omega).\n\\end{align*}\nRecalling the definition of the codifferential $\\CoDd \\alpha = (-1)^{n(k-1)+1} \\Star\\Dd\\Star \\alpha$, we compute\n\\begin{align*}\n(\\StarPol \\Dd \\StarPol)\\bigl(\\QKerPol_t(r,\\omega,u)\\bigr) &=  \\StarPol \\Dd \\Bigl( (\\pi t)^{-\\frac{n}{2}} \\exp(-\\frac{r^2}{t}) \\Vol(u) \\Bigr)  \\\\ \n& = \\StarPol\\Bigl(\\frac{-2r}{t}(\\pi t)^{-\\frac{n}{2}}\\exp(-\\frac{r^2}{t}) \\Diff{r} \\Vol(u)\\Bigr)\\\\\n&= -\\frac{1}{t}(\\pi t)^{-\\frac{n}{2}} \\exp(-\\frac{r^2}{t}) r^n \\Vol(\\omega),\n\\end{align*}\nand because the product dimension is even, we obtain\n$$ \\CoDdPol \\QKerPol_t(r,\\omega,u) = \\frac{1}{t}(\\pi t)^{-\\frac{n}{2}} \\exp(-\\frac{r^2}{t}) r^n \\Vol(\\omega). $$\nIn order to integrate this according to \\eqref{Eq:StdPrpgPol}, we will make use of the $\\Gamma$-function $\\Gamma(z) = \\int_0^\\infty x^{z-1} e^{-x} \\Diff{x}$. Then, we have\n\\begin{align*}\n(-1)^{n+1}\\StdPrpgPol(r,\\omega,u)&=\\frac{1}{2}\\lim_{t\\to 0} \\int_t^\\infty \\CoDdPol \\QKerPol_\\tau(r,\\omega,u)\\Diff{\\tau}\\\\\n&=\\frac{1}{2}\\pi^{-\\frac{n}{2}}r^n \\Bigl(\\lim_{t\\to 0}\\int_{t}^\\infty \\tau^{-\\frac{n}{2} - 1} \\exp(-\\frac{r^2}{\\tau})\\Diff{\\tau}\\Bigr)\\Vol(\\omega)\\\\\n&=\\frac{1}{2}\\pi^{-\\frac{n}{2}}r^n \\Bigl(\\lim_{t\\to 0}\\int_{\\frac{r^2}{t}}^0 \\Bigl(\\frac{r^2}{z}\\Bigr)^{-\\frac{n}{2} - 1}\\exp(-z)\\bigl(-z^{-2}r^2\\Diff{z}\\bigr)\\Bigr)\\Vol(\\omega)\\\\\n&= \\frac{1}{2}\\pi^{-\\frac{n}{2}}\\Bigl(\\lim_{t\\to 0} \\int_0^{\\frac{r^2}{t}} z^{\\frac{n}{2}-1} \\exp(-z) \\Diff{z}\\Bigr)\\Vol(\\omega) \\\\\n&= \\frac{\\Gamma(\\frac{n}{2})}{2\\pi^{\\frac{n}{2}}}\\Vol(\\omega) \\\\\n& = \\frac{\\Vol(\\omega)}{\\Vol(\\Sph{n-1})},\n\\end{align*}\nwhich recovers the formula in the other proof of Proposition~\\ref{Prop:StdHodgePropRn}.\n\\end{proof}\n\n\\begin{Example}[The case $n=1$]\\label{Ex:SDFSDF}\nIt is easy to check directly that\n$$ \\Prpg(x,y) \\coloneqq \\theta(x-y), $$\nwhere $\\theta$ is the Heavyside step function, is the Schwartz form of a Hodge homotopy $\\Htp$. Indeed, for any smooth $f: \\R\\rightarrow\\R$ with compact support, we have \n$$ \\Htp(f \\Diff{x})(y) = \\int_x \\Prpg(x,y)f(x)\\Diff{x} = \\int_{y}^{\\infty} f(x)\\Diff{x}, $$\nand hence $\\Dd\\circ\\Htp = -\\Id$. It is also easy to check that the following is the Laplace Green form:\n$$ \\GKer(x,y) = - \\frac{1}{2}\\Abs{x-y}(\\Diff{x}-\\Diff{y}). $$\nIndeed, using $\\Sgn(x) = 2\\theta(x) - 1$, we get\n$$ \\frac{\\partial^2}{\\partial y^2} \\frac{1}{2}\\Abs{x-y} = \\frac{\\partial}{\\partial y}\\frac{1}{2}\\Sgn(y-x) = \\delta(y-x) = \\delta(x-y), $$\nwhich shows \\eqref{Eq:GrRn}. We carefully compute\n\\begin{align*}\n(\\Id\\otimes \\CoDd_y)\\GKer(x,y) & = \\CoDd_y \\Bigl(\\frac{1}{2}\\Abs{x-y}\\Diff{y}\\Bigr) \\\\\n& = -\\frac{1}{2} \\frac{\\partial}{\\partial y}\\Abs{x-y} \\\\\n& = -\\frac{1}{2}(2\\theta(y-x)-1) \\\\ \n& = - \\theta(y-x) + \\frac{1}{2} \\\\\n& = \\theta(x-y) - \\frac{1}{2}\n\\end{align*}\nand apply Proposition~\\ref{Prop:StdCodifInt} to get\n$$ \\StdPrpg(x,y) = \\theta(x-y) - \\frac{1}{2}. $$\nIn particular, we see that the sign agrees with the direct computation of the Hodge propagator above. Smoothness on the blow-up is for $n=1$ equivalent to smoothness on the closures of connected components of $\\R\\times\\R\\backslash\\Diag$; this is readily satisfied. \n\\end{Example}\n\n\\begin{Question}\n\tIs it possible to use the asymptotic heat kernel expansion and formula~\\eqref{Eq:PrpgUsingHeatKernel} or the asymptotic Green kernel expansion and formula \\eqref{Eq:FormForPUsingG} to infer from the case of $\\R^n$ with the standard Euclidean metric $g_0$ that $\\StdPrpg$ extends smoothly to the blow-up for flat manifolds, i.e., locally isometric to $(\\R^n,g_0)$?  \n\\end{Question}\n\n\n%NOTICE THAT ALREADY $\\GKer$ EXTENDS SMOOTHLY TO THE BLOW-UP. BUT ACCORDING TO EXAMPLE BLAH BLAH WE CAN NOT USE IT TO PROVE IT BECAUSE OF THE POLARZIED OPERATORS. MAYBE YES BECAUSE OF ITS SIMPLE FORM?\n\\end{document}\n", "meta": {"hexsha": "e6d3d78d27e15028d1592322f77c018d9ba0768c", "size": 13717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/GrKer_Rn.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_Rn.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_Rn.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": 72.1947368421, "max_line_length": 366, "alphanum_fraction": 0.6336662536, "num_tokens": 5759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.619924476568034}}
{"text": "\\chapter{constElm}\n\n\\section{Introduction}\n\nA linearized process may have parameters that do not change value throughout the state space of that process.\nThese parameters are essentially \\emph{constants}.\n\nConstants can be removed from a process as follows:\n\\begin{itemize}\n\\item Substitute references to a constant by the explicit value of that constant;\n\\item Remove the constant from the process parameter list.\n\\end{itemize}\n\nThe advantages of removing constants from a process are smaller state vectors (and therefore reduced memory usage) and faster performance in general.\nThese advantages may be small; however, the detection and removal of constants can be done fairly cheaply.\n\n\\section{Algorithm}\n\nThe algorithm consists of the following steps \\cite{groote2001computer}:\n\n\\begin{enumerate}\n\n\\item Mark all process parameters.\n(This means that, initially, we assume that all process parameters are constants.)\n\n\\item Let $P$ be the set of all marked process parameters.\nDefine a substitution $\\rho = [p \\rightarrow v_0(p) \\;|\\; p \\in P]$, where $v_0$ is a function that gives the initial value of a given process parameter.\n\n\\item Consider each summand $s$ of the LPE.\nConstruct an equation $c_s \\rightarrow p = v_s(p)$ for all $p \\in P$, where $c_s$ is the guard of $s$ and where $v_s$ is a function that gives the expression of which the value is assigned to the process parameter $p$ in the instantiation, and apply the substitution $\\rho$ to it.\n(This gives $(c_s \\rightarrow p = v_s(p))[\\rho] \\Leftrightarrow {c_s}[\\rho] \\rightarrow v_0(p) = v_s(p)[\\rho]$.)\n\nIf the obtained equation is a tautology (that is, if its negation is unsatisfiable) for all $s$, $p$ remains marked; otherwise, unmark $p$.\n\n\\item Repeat the previous two steps until $P$ remains constant.\nAll remaining marked process parameters can be safely removed the process.\n\n\\end{enumerate}\n\n\\section{Example}\n\nConsider the following LPE:\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A](x, y, z :: Int)\n  = A [[z = 2]] >-> example[A](z-1, 1, 2)\n  + A >-> example[A](y, x, x+y)\n  + A >-> example[A](1, x, z+1)\n  ;\n\n//Initialization:\nexample[A](1, 1, 2);\n\\end{lstlisting}\n\nFirst, $\\rho = [ x \\rightarrow 1, y \\rightarrow 1, z \\rightarrow 2 ]$.\n\nWe must check the following equations:\n\n\\begin{align*}\n(z = 2 \\rightarrow x = z-1)[\\rho] &\\Leftrightarrow (2 = 2 \\rightarrow 1 = 2-1) \\Leftrightarrow \\textit{true} \\\\\n(z = 2 \\rightarrow y = 1)[\\rho] &\\Leftrightarrow (2 = 2 \\rightarrow 1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(z = 2 \\rightarrow z = 2)[\\rho] &\\Leftrightarrow (2 = 2 \\rightarrow 2 = 2) \\Leftrightarrow \\textit{true} \\\\\n(x = y)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(y = x)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(z = x+y)[\\rho] &\\Leftrightarrow (2 = 1+1) \\Leftrightarrow \\textit{true} \\\\\n(x = 1)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(y = x)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(z = z+1)[\\rho] &\\Leftrightarrow (2 = 2+1) \\Leftrightarrow \\textit{false} \\\\\n\\end{align*}\n\nThe last equation is not a tautology, and so $z$ is unmarked.\n\nThe new value of $\\rho$ is $[ x \\rightarrow 1, y \\rightarrow 1 ]$.\n\n\\clearpage\nThe equations are now the following:\n\n\\begin{align*}\n(z = 2 \\rightarrow x = z-1)[\\rho] &\\Leftrightarrow (z = 2 \\rightarrow 1 = z-1) \\Leftrightarrow \\textit{true} \\\\\n(z = 2 \\rightarrow y = 1)[\\rho] &\\Leftrightarrow (z = 2 \\rightarrow 1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(x = y)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(y = x)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(x = 1)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n(y = x)[\\rho] &\\Leftrightarrow (1 = 1) \\Leftrightarrow \\textit{true} \\\\\n\\end{align*}\n\nAll of the equations above are tautologies, and so $x$ and $y$ remain marked.\nRemoving the marked parameters from the LPE gives\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A](z :: Int)\n  = A [[z==2]] >-> example[A](2)\n  + A >-> example[A](2)\n  + A >-> example[A](z+1)\n  ;\n\n//Initialization:\nexample[A](2);\n\\end{lstlisting}\n\nObviously, more simplification is possible.\n\n", "meta": {"hexsha": "8d3f9faedc99081be1ca71bff943724940a15d8e", "size": 4174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_tex/lpeopsDoc/constElm.tex", "max_stars_repo_name": "Sercammus/TxsLpeOps", "max_stars_repo_head_hexsha": "3354f2762cf195e571f4c05040ec500165969359", "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": "_tex/lpeopsDoc/constElm.tex", "max_issues_repo_name": "Sercammus/TxsLpeOps", "max_issues_repo_head_hexsha": "3354f2762cf195e571f4c05040ec500165969359", "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/lpeopsDoc/constElm.tex", "max_forks_repo_name": "Sercammus/TxsLpeOps", "max_forks_repo_head_hexsha": "3354f2762cf195e571f4c05040ec500165969359", "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.7523809524, "max_line_length": 280, "alphanum_fraction": 0.6954959272, "num_tokens": 1333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6199244723527996}}
{"text": "\\lab{Facial Recognition using Eigenfaces}{Facial Recognition using Eigenfaces}\n\\label{lab:FacialRecognition}\n\n\\objective{Use the singular value decomposition to build a facial recognition system.}\n\nSuppose we have a large database containing images of human faces.\nWe would like to identify people by matching their pictures to those in the database.\nThis task is called \\emph{facial recognition}.\n\nFacial recognition is important in law enforcement, as well as other situations. \nFor example, facial recognition can be combined with video surveillance to identify when a person is not authorized to be in a location.\n\nHumans can easily compare two face images and determine whether they belong to the same person, but automating this process is more challenging.\nOne technique for automated facial recognition uses \\emph{eigenfaces}.\n\n\\section*{Load the data}\nEigenfaces are an efficient way to store and query a database of face images.\nAs the name suggests, this method uses eigenvectors of matrices related to the collection of face images.\nEssentially, the method of eigenfaces projects face images to a lower-dimensional subspace in a way that preserves their distinguishing characteristics. \nIn the lower-dimensional subspace, comparing face images is much faster.\n\nRecall that a digital image may be stored as an $m \\times n$ array of pixel intensities. \nIn this lab, we will store the images as $mn$-vectors by concatenating the rows of the $m \\times n$ arrays.\n\n\n\\begin{problem}\n\\label{prob:getTrainingFaces}\nThe problems in this lab will help you write a class \\li{FacialRec} to perform facial recognition. \nFirst we need to get a database of face images.\n\\begin{enumerate}\n\\item Download 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 photographs of many people, organized into folders by person.\n\\end{enumerate}\nWith this directory we can begin to write our \\li{FacialRec} class. This class is outlined below.\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import linalg as la\nfrom os import walk\nfrom scipy.ndimage import imread\nfrom matplotlib import pyplot as plt\nimport matplotlib.cm as cm \nfrom random import sample\n\nclass FacialRec:\n    ##########Members##########\n    #   F, mu, Fbar, and U \n    ###########################\n    def __init__(self,path):\n        self.initFaces(path)\n        self.initMeanImage()\n        self.initDifferences()\n        self.initEigenfaces()\n\n    def initFaces(self, path):\n        self.F = getFaces(path)\n    def initMeanImage(self):\n        pass\n    def initDifferences(self):\n        pass\n    def initEigenfaces(self):\n        pass\n    def project(self, s):\n        pass\n    def findNearest(self, image):\n        pass\n\\end{lstlisting}\n\nThe function \\li{getFaces()} should construct a database of face images by selecting exactly one face image for each person in the directory.\nIt should return an array whose columns are the selected face images.\nOne implementation of this function is found at the end of this lab.\n\n\\begin{enumerate}[resume]\n\\item Initialize a \\li{FacialRec} instance with the command \\li{facialRec = FacialRec(\\\"./faces94\\\")}. You may have to replace the parameter \\li{\\\"./faces94\\\"} with the location of the directory \\li{faces94} on your machine. Check that \\li{facialRec.F} is a $360000 \\times 153$ array. The columns of this array are 153 face images of 153 different people.\n\\end{enumerate}\n\\end{problem}\n\n\n\\section*{Shift by the mean}\n\nThe facial recognition algorithm is more robust if we first \\emph{shift by the mean}. \nSuppose we have a collection of $k$ face images represented as vectors $\\f_1, \\f_2, \\ldots, \\f_k$ of length $mn$.\nDefine the \\emph{mean face} ${\\boldsymbol \\mu}$ to be the average of the $\\f_i$:\n\\[\n{\\boldsymbol \\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\\begin{problem}\n\\label{prob:meanFace}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement the method \\li{FacialRec.initMeanImage()} as follows.\n\\begin{lstlisting}\ndef initMeanImage(self):\n    self.mu = # Compute the mean face of the images in self.F\n\\end{lstlisting}\nThis can be done in one line using \\li{np.mean} and specifying the correct axis.\n\n\\item Plot the mean face. \nThe function \\li{show()} at the end of this lab will plot a flattened grayscale image.\nYour mean face should match Figure \\ref{facialRecognition:meanFace}.\n\\end{enumerate}\n\\end{problem}\n\n\n\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 - {\\boldsymbol \\mu}$.\nThe mean-shifted face vector $\\bar{\\f}_i$ is the deviation of the $i$-th face from the mean, and thus captures the unique features of the face.\nNow form the $mn \\times k$ matrix $\\bar{F}$ whose columns are given by the mean-shifted face vectors, i.e.\n\\[\n\\bar{F} = \\begin{bmatrix}\n\\bar{\\f}_1 & \\bar{\\f}_2 & \\cdots & \\bar{\\f}_k\n\\end{bmatrix}.\n\\]\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement the method \\li{FacialRec.initDifferences()} to compute $\\bar{F}$ as follows.\n\\begin{lstlisting}\ndef initDifferences(self):\n    self.Fbar = # Compute the mean-shifted face vectors Fbar\n\\end{lstlisting}\nThis can be done in one line using array broadcasting.\n\\item\nPlot the first mean-shifted face, i.e. the first column of the matrix \\li{Fbar}.\nIt should match the first face in Figure \\ref{facialRecognition:differenceFaces}.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Project to a subspace}\nNow suppose we have a new face vector $\\g$. \nThe closest face image to $\\g$ should be the vector $\\bar{\\f}_i$ that minimizes $\\|\\bar{\\g}-\\bar{\\f}_i\\|_2$, where $\\bar{\\g} = \\g - {\\boldsymbol \\mu}$.\nUnfortunately, computing $\\|\\bar{\\g}-\\bar{\\f}_i\\|_2$ for each $i$ is computationally intractable when the length $mn$ of the vectors is large.\nSince a low-resolution photo may easily have $100\\times 100 = 10,000$ pixels, in practice $mn$ is very large indeed.\n\nHere is the trick: instead of computing in the $mn$-dimensional space of all possible images, we will compute in a lower-dimensional subspace.\nWe could start by using the subspace spanned by the vectors $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$, which is at most $k$-dimensional. \nUnfortunately, in practice $k$ is still to large for this subspace to be computationally efficient.\n%We need to project our problem into some subspace of the span of $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$.\n\nTherefore, we want to project to a subspace of $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$ in a way that retains as much information about the $\\bar{\\f_i}$ as possible.\nMathematically, we want to find the $s$-dimensional subspace of $\\text{span}\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$ that is closest to the $\\bar{\\f_i}$ in the least-squares sense.\nIn a minute, we will prove that the SVD of $\\bar{F}$ (whose columns are $\\bar{\\f}_1, \\ldots \\bar{\\f}_k$) solves this problem.\nBut first, let us summarize how the solution works.\n\nLet $U \\Sigma V^T$ be an SVD of $\\bar{F}$ with $\\u_i$ the columns of $U$. \nThen the ``best'' $s$-dimensional subspace for approximating $\\text{span}\\{\\bar{\\f}_1, \\ldots \\bar{\\f}_k\\}$ is the span of $\\u_1, \\ldots, \\u_s$. \nThe matrix for this projection is $P_s = U_s U_s^T$ where $U_s = [ \\u_1\\; \\ldots \\; \\u_s]$.\n\nBecause the vectors $\\u_i$ are eigenvectors of $\\bar{F}\\bar{F}^T$, we call them \\emph{eigenfaces}. \nTherefore, the best $s$-dimensional subspace for solving the facial recognition problem is exactly the span of the first $s$ eigenfaces.\n\n\\subsection*{The proof: SVD as a least squares solution}\n\\begin{theorem}\nLet $\\f_1, \\ldots, \\f_k$ be vectors on $\\mathbb{R}^{mn}$, and let $\\bar{F} = [\\bar{f}_1 \\; \\ldots \\; \\bar{f}_k]$. Suppose $U\\Sigma V^T$ is an SVD for $\\bar{F}$. Then the $s$-dimensional subspace that solves the least squares problem for $\\f_1, \\ldots, \\f_k$ is the span of the first $s$ columns of $U$. If $U_s$ is the first $s$ columns of $U$, then the matrix $U_sU_s^T$ is projection onto this subspace.\n\\end{theorem}\n\\begin{proof}\nWe seek a rank-$s$ projection matrix $P_s$ so that $\\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2$ is minimized---i.e.,\n the sum of the squares of the ``errors'' is minimal when we project $\\bar{\\f}_i$ via $P_s$.\n But minimizing this quantity is the same as minimizing its square, which happens to equal the Frobenius norm of $P_s\\bar{F} - \\bar{F}$. \nWritten mathematically,\n \\begin{align*}\n\\inf_{\\text{rank}(P_s)=s} \\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2 &=  \\inf_{\\text{rank}(P_s)=s} \\left( \\sum_{i=1}^k \\|P_s\\bar{\\f}_i - \\bar{\\f}_i\\|_2^2 \\right) ^2\\\\\n & =  \\inf_{\\text{rank}(P_s)=s} \\| P_s\\bar{F}-\\bar{F}\\|_F.\n \\end{align*}\n \nNow let $U \\Sigma V^T$ be an SVD of $\\bar{F}$ with $\\u_i$ the columns of $U$, $\\v_i$ the columns of $V$, and $\\sigma_i$ the singular values of $\\bar{F}$.\nIf $P_s = \\sum_{i=1}^s \\u_i \\u_i^T$, then \n\\begin{align*}\nP_s\\bar{F} &=  \\left( \\sum_{i=1}^s \\u_i \\u_i^T \\right)\\left(  \\sum_{j=1}^k \\sigma_j \\u_i \\v_i^T \\right)\n= \\sum_{i=1}^s\\sum_{j=1}^k \\sigma_j \\u_i\\u_i^T\\u_j\\v_j^T\\\\\n&=  \\sum_{i=1}^s\\sum_{j=1}^k \\sigma_j \\u_i\\delta_{ij}\\v_j^T\n= \\sum_{i=1}^s \\sigma_i \\u_i\\v_i^T.\n\\end{align*}\n\nIn fact, the Schmidt-Eckart-Young-Mirsky Theorem from Lab \\ref{lab:SVD} tells us that $X = \\sum_{i=1}^s \\sigma_i \\u_i\\v_i^T$ is exactly the rank-$s$ matrix that minimizes $\\|X - \\bar{F}\\|_F$. \nSince $P_s \\bar{F}$ will always have rank $s$ or less, the projection $P_s =  \\sum_{i=1}^s \\u_i \\u_i^T$ is the one we seek.\nIf we let $U_s = [ \\u_1\\; \\ldots \\; \\u_s]$, then we may write $P_s = U_sU_s^T$. Notice that $P_s$ is projection onto the subspace spanned by the columns of $U_s$.\n\\end{proof}\n\n\\begin{problem}\n\\label{prob:svd}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement the method \\li{FacialRec.initEigenfaces()} as follows.\n\\begin{lstlisting}\ndef initEigenfaces(self):\n    self.U, s, Vt = # Compute the SVD of Fbar\n\\end{lstlisting}\nThis can be done in one line with the function \\li{linalg.svd()}.\nBecause we will only use the first few columns of $U$, specify the keyword parameter \\li{full_matrices=False} to compute only the compact SVD.\n\\item Plot the first eigenface (i.e. the first column of \\li{U}).\nIt should match the first eigenface shown in Figure \\ref{facialRecognition:eigenfaces}.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Change basis}\n\nIt does us no good to project all our vectors into an $s$-dimensional space if we still store them as vectors in $\\mathbb{R}^{nm}$. \nInstead, we must store our face vectors in terms of the columns of $U_s$.\nThis way, each vector is a lenth-$s$ array in NumPy, instead of a length-$mn$ array.\n\nThe change-of-basis matrix is $U_s^T$, so $U_s^T\\widehat{P}_s = U_s^TU_sU_s^T = U_s^T$. \nThus we can project into the subspace and change basis by multiplying by $U_s^T$.\nTo change back to the full $mn$-vector, multiply by $U_s$.\n\n\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\n\n\n\\begin{problem}\n\\label{prob:top_n}\n\\leavevmode\n\\begin{enumerate}\n\\item Implement the method  \\li{FacialRec.project(s)} as follows.\n\\begin{lstlisting}\ndef project(self,s):\n        # Return U_s^T\n\\end{lstlisting}\n\\item (Optional) Let \\li{face} be the first mean-shifted face from the database (the first column of \\li{facialRec.Fbar}). Do the following:\n\\begin{enumerate}\n\\item Project \\li{face} onto the subspace spanned by the first 75 eigenfaces.\n\\item Change basis back to the standard basis on $\\mathbb{R}^{mn}$.\n\\item Add back the mean face \\li{facialRec.mu}.\n\\item Plot the resulting image.\n\\end{enumerate}\nYour image should match Figure \\ref{fig:75_efaces}.\n\\end{enumerate}\n\\end{problem}\n\n\n\\begin{figure}\n\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltThirtySecond.png}\n\\caption{5 eigenfaces, about 1/32 of the total.}\n\\label{fig:5_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltSixteenth.png}\n\\caption{9 eigenfaces, or 1/16 of the total.}\n\\label{fig:9_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltEighth.png}\n\\caption{19 eigenfaces, about 1/8 of the total.}\n\\label{fig:19_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltFourth.png}\n\\caption{38 eigenfaces, about 1/4 of the total.}\n\\label{fig:38_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltHalf.png}\n\\caption{75 eigenfaces, about 1/2 of the total.}\n\\label{fig:75_efaces}\n\\end{subfigure}\n\\begin{subfigure}[b]{0.3\\textwidth}\n\\includegraphics[width=\\textwidth]{rebuiltAll.png}\n\\caption{All 153 of the eigenfaces.}\n\\label{fig:all_efaces}\n\\end{subfigure}\n\\caption{Image rebuilt with various numbers of eigenfaces. The image is somewhat recognizable when it is reconstructed with only 1/8 of the eigenfaces.}\n\\label{fig:rebuiltImage}\n\\end{figure}\n\n\\begin{comment}\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\\end{comment}\n\n\\section*{Recognizing faces}\nFinally, we are ready to identify which mean-shifted image $\\bar{\\f}_i$ is closest to $\\bar{\\g}$. \nWe begin by projecting all vectors to some $s$-dimensional subspace and writing them in terms of an orthonormal basis for that subspace. \nThis is accomplished with multiplication by $U_s^T$:\n\\[\n\\widehat{\\f}_i = U_s^T(\\f_i-{\\boldsymbol \\mu}) \\qquad \\widehat{\\g} = U_s^T(\\widehat{\\g}-{\\boldsymbol \\mu}).\n\\]\n\nNext, we compute which $\\widehat{\\f}_i$ is closest to $\\widehat{\\g}$. \nSince the columns of $U_s$ are an orthonormal basis, we get the same result doing the computation in this basis as we would in the standard Euclidean basis.\nDefine\n\\[\ni^* = \\text{argmin}_i \\|\\widehat{\\f}_i - \\widehat{\\g}\\|_2.\n\\]\nThen the $i^*$-th face image is the best match for $\\g$.\n\n\\begin{problem}\n\\label{prob:nearest}\n\\leavevmode\n\\begin{enumerate}\n\\item\nImplement the method \\li{FacialRec.findNearest()} as follows.\n\\begin{lstlisting}\ndef findNearest(self, image, s=38):\n    Ut = self.project(s)\n    ghat = # Shift `image' by the mean and project, producing g-hat as defined above\n    Fhat = # Project Fbar, producing a matrix whose columns are the f-hat defined above \n        \n    # Return the index that minimizes || fhat_i - ghat ||_2.\n\\end{lstlisting}\nThe functions \\li{la.norm()} and \\li{np.argmin()} will be useful for the last line.\n\n\\item Test your facial recognition system on faces selected randomly from the \\li{faces94} dataset.\nThe function \\li{sampleFaces(n_tests, path)} at the end of this lab will build an array of \\li{n_tests} random faces from the \\li{faces94} database.\n\nPlot the random face beside the face returned by your facial recognition code to see if your system is accurately recognizing faces.\nThe function \\li{show2()} at the end of this lab will plot two face vectors side-by-side.\n\n\\end{enumerate}\n\\end{problem}\n\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.\n\nAlthough there are other approaches to facial recognition that utilize more complex techniques, the method of eigenfaces remains\na wonderfully simple and effective solution, illustrating another application of the singular value decomposition.\n\n\\section*{Appendix: Helper Code}\nThis section contains some functions to help you code up the facial recognition class outlined in the problems of this lab.\n\n\\begin{lstlisting}\ndef getFaces(path=\"./faces94\"):\n    \"\"\"\n    Traverse the directory specified by `path' and return an array containing\n    one column vector per subdirectory.\n    \n    For the faces94 dataset, this gives an array with just one column for each\n    face in the database. Each column corresponds to a flattened grayscale image.\n    \"\"\"\n    \n    # Traverse the directory and get one image per subdirectory\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        \n    # put all the face vectors column-wise into a matrix\n    F = np.array(faces).T\n    return F\n\n\ndef show(im, w=200, h=180):\n    \"\"\"\n    Plot the flattened grayscale image `im' of width `w' and height `h'\n    \"\"\"\n    \n    plt.imshow(im.reshape((w,h)), cmap=cm.Greys_r)\n    plt.show()\n    \n\n\ndef sampleFaces(n_tests,path = \"./faces94\")\n    \"\"\"\n    Return an array containing a sample of n_tests images contained \n    in the path as flattened images in the columns of the output\n    \"\"\"\n    files = []\n    for (dirpath, dirnames, filenames) in walk(path):\n        for f in filenames:\n            if f[-3:]==\"jpg\": # only get jpg images\n            files.append(dirpath+\"/\"+f)\n            \n    #Get a sample of the images\n    test_files = sample(files, n_tests)\n    #Flatten and average the pixel values\n    images = np.array([imread(f).mean(axis=2).ravel() for f in test_files]).T\n    return images\n    \n\ndef show2(im1, im2, w=200, h=180):\n    \"\"\"\n    Convenience function for plotting two flattened grayscale images of\n    the specified width and height side by side\n    \"\"\"\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\n\n\\end{lstlisting}", "meta": {"hexsha": "f3c92725cbf78554d182b53cb03852a8d6fbb3fd", "size": 18902, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FacialRecognition/FacialRecognition.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/FacialRecognition/FacialRecognition.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/FacialRecognition/FacialRecognition.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.3708920188, "max_line_length": 405, "alphanum_fraction": 0.7209819067, "num_tokens": 5496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6199244693769322}}
{"text": "\\chapter{Homogenization and Justification}\n\nMechanical models of highly periodic structures within the asymptotic homogenization theory, which defines a multi-scale method for determining the effective moduli of periodic media, have been studied profoundly for example by \\textit{Bakhvalov, Panasenko} \\cite{bakhvalov1989homogenisation:}. The approach exploits a separation of scales within the composite material, deriving a leading order homogenized equations governing the effective macroscopic behavior.\n\nGiven the assumptions for the multiscale elastodynamic model of cortical bone, the objective in this section will be to rigorously give a justification of the existence of such multiscale PDE system motivated from \\cite{altenbach2018generalized}, \\cite{Parnell2008} then show the schematic procedure to obtain the so-called macroscopic mechanical behavior of bone which will be used for the numerical simulations and finally give a convergence result of the solution between the multiscale model and the homogenized one. \n\nFirst, let us define the adequate spaces for our problem. Given the domain $\\Omega \\subset \\mathbb{R}^d$, it will be denoted by $\\mathbf{L}^2(\\Omega)$ the $d$-dimensional vector functions, being each component on $L^2(\\Omega)$. Similarly, it is defined the space $\\mathbf{H}^1(\\Omega)$ of d-dimensional vector functions, where as before, each component belongs to $H^1(\\Omega)$ defined as usual in the literature \\cite{evans2010partial}. \nIn particular, denoting the vector trace operator by $\\gamma: \\mathbf{H}^1(\\Omega) \\rightarrow \\mathbf{L}^2(\\partial \\Omega)$, we can define the space:\n\\begin{equation*}\n    \\mathbf{H}^1(\\Omega, \\Gamma_D) = \\big \\{ v \\in \\mathbf{H}^1(\\Omega) \\, \\vert \\, \\gamma (v) \\vert_{\\Gamma_D} = \\mathbf{0} \\big \\}\n\\end{equation*}\n\nMoreover, by applying the \\textit{Rellich-Kondrachov} theorem, the embedding from $\\mathbf{H}^1(\\Omega, \\Gamma_D)$ into $\\mathbf{L}^2(\\Omega)$ is compact \\footnote{From a more abstract point of view, it is possible to define $\\kappa: \\mathbf{L}^2( \\Omega) \\longrightarrow \\mathbf{H}^{-1/2}(\\Gamma_D)$ being the trace operator, i.e., $\\kappa (u) = u \\vert_{\\Gamma_D}$. Then define an adequate space of square integrable vector functions with homogeneous Dirichlet condition on $\\Gamma_D$ by $\\mathbf{L}^2(\\Omega, \\Gamma_D) := \\kappa^{-1}\\big( \\{ \\mathbf{0}\\}\\big)$. Note that the operator $\\kappa$ defined is linear and continuous in the corresponding spaces, moreover, since $\\{\\mathbf{0}\\}$ is a close subset, then $\\mathbf{L}^2(\\Omega, \\Gamma_D)$ is a close subspace of $\\mathbf{L}^2(\\Omega)$.\nIn particular, $\\mathbf{L}^2(\\Omega, \\Gamma_D)$ is separable, so that there exist a Hilbertian base associated.}.\n\nGiven $\\epsilon > 0$, let us fix a porosity $p \\in (0,1)$ and consider $(C_{ijkl})_{ijkl}:=\\mathbf{C}(p) \\in \\text{ lin}\\big(\\textbf{Sym}^{d\\times d})$, the space of linear, continuous operators on the $d\\times d$ symmetric matrices space, being uniformly elliptic and bounded elasticity tensors. Also, denote by $\\rho^{\\epsilon}(\\mathbf{x}) = \\rho \\big( \\frac{\\mathbf{x}}{\\epsilon}\\big)$ an uniformly bounded density, $C_{ijkl}^{\\epsilon}(\\mathbf{x}) = C_{ijkl}(\\frac{\\mathbf{x}}{\\epsilon})$, $\\mathbf{F}(t, \\mathbf{x})$ a force independent of $\\epsilon$ and consider for fixed parameter $T > 0$ the following evolution PDE problem modelling the displacements:\n\\begin{equation}\n    \\label{MainPDE}\n    \\left \\{\n    \\begin{array}{cc}\n        \\rho^{\\epsilon} \\partial_{tt} u^{\\epsilon} - \\nabla\\cdot \\sigma^{\\epsilon}(u^{\\epsilon})= \\mathbf{0} & \\text{ in } (0,T) \\times \\Omega \\\\\n        \\sigma^{\\epsilon}_{ij}(u^{\\epsilon}) = C_{ijkl}^{\\epsilon} \\mathbf{e}_{kl}(u^{\\epsilon}) & \\text{ in } (0,T)\\times \\Omega \\\\\n        u^{\\epsilon} = \\mathbf{0} & \\text{ on } (0,T) \\times \\Gamma_D \\\\\n        \\sigma^{\\epsilon}_{ij} n_j = \\mathbf{F} & \\text{ on } (0,T) \\times \\Gamma_N \\\\\n        \\partial_t u^{\\epsilon} = u^{\\epsilon} = \\mathbf{0} & \\text{ on } \\{t=0\\} \\times \\Omega\n    \\end{array}\n    \\right.\n\\end{equation}\n\\begin{prop}\nAssuming $0 < \\rho_0 \\leq \\rho\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) < + \\infty$ and $\\mathbf{F} \\in L^{\\infty}(0,T;\\mathbf{L}^2(\\Omega,\\Gamma_N))$, there exist a unique solution $u^{\\epsilon}$ to (\\ref{MainPDE}) for each $\\epsilon > 0$, such that\n\\begin{equation*}\n    u^{\\epsilon} \\in \\mathcal{C}^0(0,T;\\mathbf{H}^1(\\Omega,\\Gamma_D)) \\cap \\mathcal{C}^1(0,T;\\mathbf{L}^2(\\Omega))\n\\end{equation*}\n\\end{prop}\n\n\\begin{rem}\nInspired from \\cite{raviart1983introduction}, a constructive proof is given based in the spectral decomposition of the elastic operator on $\\mathbf{H}^1(\\Omega, \\Gamma_D)$ and solutions of the reduced ODE's associated to each eigenvalue\\footnote{The formulation of the elastodynamic problem with Dirichlet boundary conditions had been studied in literature, in particular on the multiscale works from \\cite{panasenko2005multi-scale}, \\cite{bakhvalov1989homogenisation:}. On the other hand, the formal study of Neumann boundary conditions has been done mainly on \\cite{oleinik1992mathematical}.}. % of the elastic operator.\n\\end{rem}\n\nIn the following, it is denoted the dot product $(u,v)_{\\Omega} := \\int_{\\Omega} \\rho^{\\epsilon} u\\cdot v \\, d\\mathbf{x}$ for $u, v \\in \\mathbf{L}^2(\\Omega)$, which is equivalent to the usual one of $\\mathbf{L}^2(\\Omega)$ for each $\\epsilon$ by the assumptions of boundness on the density. On the other hand, $(\\cdot\\,, \\cdot)_{\\Gamma_N}$ denotes the usual dot product of $\\mathbf{L}^2(\\Gamma_N)$ vector functions.\n\nUnder such notation, problem (\\ref{MainPDE}) can be rewritten in variational form satisfied in distributions over $(0,T)$ by: \n\\begin{equation}\n    \\label{MainTimePDE}\n    \\begin{array}{cc}\n        \\text{Find } u^{\\epsilon} \\in \\mathcal{C}^0 (0,T;\\mathbf{H}^1(\\Omega,\\Gamma_D)) \\cap \\mathcal{C}^1(0,T;\\mathbf{L}^2(\\Omega)) & \\text{ s.t. }\\\\\n        \\partial_{tt} (u^{\\epsilon}(t),v)_{\\Omega} + \\mathcal{I}_{C}(u^{\\epsilon}(t),v) = (\\mathbf{F}(t),v)_{\\Gamma_N}&  \\forall v \\in \\mathbf{H}^1(\\Omega,\\Gamma_D) \\\\\n        \\partial_{t} u^{\\epsilon}(0) = u^{\\epsilon}(0) = \\mathbf{0} & \\\\\n    \\end{array}\n\\end{equation}\nbeing $\\mathcal{I}_{C}(u,v) := \\int_{\\Omega} C_{ijkl}^{\\epsilon}\\mathbf{e}_{kl}(u^{\\epsilon}(t)) \\partial_{x_j} v_i$.\nLet us prove the existence and uniqueness of solution for (\\ref{MainTimePDE}).\n\\begin{proof}\n\\begin{enumerate}\n    \\item To this end, it will be considered approximate solutions to (\\ref{MainTimePDE}). It is defined the subspace $V_m$ generated by the first $m \\in \\mathbb{N}$ eigenvectors $\\{w_1, \\dots, w_m \\}$ being $(w_i)_{i \\in \\mathbb{N}} \\subset \\mathcal{C}^{\\infty}(\\Omega)$ a Hilbertian base of $\\mathbf{H}^1(\\Omega, \\Gamma_D)$ were the regularity follows from bootstrap and by the Sobolev embedding.\n    Then, let us consider the problem in time, defined by:\n    \\begin{equation}\n        \\label{ApproxTimePDE}\n        \\begin{array}{cc}\n            \\text{Find } u^{\\epsilon}_m: t \\in (0,T) \\longrightarrow u_m(t) \\in V_m & \\text{ s.t. } \\\\\n            \\partial_{tt}(u_m^{\\epsilon}(t),v)_{\\Omega} + \\mathcal{I}_{C}(u^{\\epsilon}_m(t),v) = (\\mathbf{F}(t),v)_{\\Gamma_N} & \\forall v \\in \\mathbf{H}^1(\\Omega,\\Gamma_D) \\\\\n            \\partial_{t} u^{\\epsilon}_m(0) = u^{\\epsilon}_m(0) = \\mathbf{0} & \\\\\n        \\end{array}\n    \\end{equation}\n    \\begin{rem}\n    Note that the linear operator $b(t)(v) := (\\mathbf{F}(t),v)_{\\Gamma_N}$ is well-defined and moreover continuous on $\\mathbf{H}^1(\\Omega,\\Gamma_D)$ for each $t \\in (0,T)$.\n    This follows from the trace theorem applied on $\\mathbf{H}^1(\\Omega, \\Gamma_D)$ since $\\forall t \\geq 0$, we have the bounds:\n    \\begin{align*}\n        \\vert b(t)(v) \\vert & \\leq \\Vert \\mathbf{F}(t) \\mathbb{I}_{\\Gamma_N} \\Vert_{\\mathbf{L}^2(\\partial \\Omega)} \\Vert \\gamma (v) \\Vert_{\\mathbf{L}^2(\\Gamma_N)} \\\\\n        & \\leq \\Vert \\mathbf{F}\\Vert_{\\mathbf{L}^{\\infty}(0,T;\\mathbf{L}^2(\\Gamma_N))} \\Vert \\gamma(v) \\Vert_{\\mathbf{L}^2(\\partial \\Omega)} \\\\\n        & \\leq \\Vert \\mathbf{F} \\Vert_{\\mathbf{L}^{\\infty}(0,T;\\mathbf{L}^2(\\Gamma_N))} \\Vert v \\Vert_{\\mathbf{H}^1(\\Omega)}\\\\\n        & = \\Vert \\mathbf{F}\\Vert_{\\mathbf{L}^{\\infty}(0,T;\\mathbf{L}^2(\\Gamma_N))} \\Vert v \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_D)}\n    \\end{align*}\n    \\end{rem}\n    Defining $u^{\\epsilon}_m(t) = \\sum_{i=1}^m \\alpha_i^{\\epsilon}(t) w_i$ with $\\alpha_i^{\\epsilon} (t) = (u^{\\epsilon}_m(t),w_i)_{\\Omega}$ it follows that the functions $\\alpha_i^{\\epsilon}$ are solutions to the ODE system:\n    \\begin{equation}\n        \\label{AlphaODE}\n        \\begin{array}{cc}\n            \\partial_{tt} \\alpha_i^{\\epsilon}(t) + \\lambda_i \\alpha_i^{\\epsilon}(t) = (\\mathbf{F}(t),w_i)_{\\Gamma_N}& \\forall t \\in (0,T) \\\\\n            \\partial_t \\alpha_i^{\\epsilon}(0) = \\alpha_i^{\\epsilon}(0) = 0 & \n        \\end{array}\n    \\end{equation}\n    being $(\\lambda_i)_{i \\geq 1}$ a positive, increasing sequence of eigenvalues associated to the decomposition of the operator $\\mathcal{I}_C(\\cdot, \\cdot)$.\\\\\n    Let us note by applying the variation of parameters technique, that the solution to (\\ref{AlphaODE}) is given in the form:\n    \\begin{equation}\n        \\label{AlphaODEsol}\n        \\alpha_i^{\\epsilon} (t) = \\frac{1}{\\sqrt{\\lambda_i}} \\int\\limits_0^t sin(\\sqrt{\\lambda_i} (t-s)) (\\mathbf{F}(t),w_i)_{\\Gamma_N} \\, ds\n    \\end{equation}\n    so that, defining the matrix for $\\omega \\in \\mathbb{R}$ by:\n    \\begin{equation*}\n        Q(\\omega) =\n        \\begin{bmatrix}\n        cos(\\omega) & sin(\\omega) \\\\\n        -sin(\\omega) & cos(\\omega)\n        \\end{bmatrix}\n    \\end{equation*}\n    it is obtained the following relation for the solution and their derivative in the form:\n    \\begin{equation}\n        \\label{MatrixODEsol}\n        \\begin{bmatrix}\n        \\sqrt{\\lambda_i} \\alpha_i^{\\epsilon}(t) \\\\\n        \\partial_{t} \\alpha_i^{\\epsilon}(t) \n        \\end{bmatrix}\n        = \\int \\limits_0^t Q\\big(\\sqrt{\\lambda_i}(t-s)\\big)\n        \\begin{bmatrix}\n        0 \\\\\n        (\\mathbf{F}(t),w_i)_{\\Gamma_N}\n        \\end{bmatrix}\n    \\end{equation}\n    \n    \\item Next, the sequence $(u^{\\epsilon}_m)_{m \\in \\mathbb{N}}$ is of Cauchy type on the spaces $\\mathcal{C}^0(0,T;\\mathbf{H}^1(\\Omega, \\Gamma_D))$ and $\\mathcal{C}^1(0,T; \\mathbf{L}^2(\\Omega))$.\\\\\n    Let $m,p$ be two integers such that $p > m \\geq 1$ then from (\\ref{AlphaODEsol}) it follows that\n    \\begin{equation*}\n        \\mathcal{I}_C(u_p^{\\epsilon}(t)- u_m^{\\epsilon}(t),u_p^{\\epsilon}(t)- u_m^{\\epsilon}(t)) + \\vert \\partial_t (u_p^{\\epsilon}(t)- u_m^{\\epsilon}(t))_{\\Omega} \\vert^2 = \\sum_{i=m+1}^p \\big( \\lambda_i \\vert \\alpha_i^{\\epsilon}(t) \\vert^2 + \\vert \\partial_t \\alpha_i^{\\epsilon}(t) \\vert^2 \\big) \n    \\end{equation*}\n    and since $Q(\\omega)$ is an orthogonal matrix, from (\\ref{MatrixODEsol}) it follows that\n    \\begin{equation}\n        \\label{AlphaBound}\n        \\big( \\lambda_i \\vert \\alpha_i^{\\epsilon}(t) \\vert^2 + \\vert \\partial_t \\alpha_i^{\\epsilon}(t) \\vert^2 \\big)^{1/2} \\leq \\int \\limits_0^t \\vert (\\mathbf{F}(t),w_i)_{\\Gamma_N} \\vert \\, ds \n    \\end{equation}\n    so that, by using the Cauchy-Schwatz inequality, it can be obtained\n    \\begin{align*}\n        \\lambda_i \\vert \\alpha_i^{\\epsilon}(t) \\vert^2 + \\vert \\partial_t \\alpha_i^{\\epsilon}(t) \\vert^2 &\\leq 2 \\big( \\int_0^t \\vert (\\mathbf{F}(t),w_i)_{\\Gamma_N} \\vert \\, ds \\big)^2 \\\\\n        & \\leq  2 t \\int_0^t \\vert (\\mathbf{F}(t),w_i)_{\\Gamma_N} \\vert^2 \\, ds\n    \\end{align*}\n    from which it can be deduced the bound\n    \\begin{equation*}\n        \\mathcal{I}_C \\big(u_p^{\\epsilon}(t) - u_m^{\\epsilon}(t),u_p^{\\epsilon}(t) - u_m^{\\epsilon}(t) \\big) + \\vert \\partial_t (u_p^{\\epsilon}(t) - u_m^{\\epsilon}(t)) \\vert^2 \\leq 2 \\sum_{i=m+1}^p t \\int_0^t \\vert (\\mathbf{F}(s),w_i)_{\\Gamma_N} \\vert^2 \\, ds\n    \\end{equation*}\n    Now, since $\\mathbf{F} \\in L^{\\infty}(0,T;\\mathbf{L}^2( \\Gamma_N))$ it follows\n    \\begin{equation*}\n        \\underset{p,m \\longrightarrow + \\infty}{\\text{lim}} \\sum_{i=m+1}^p \\big \\{ T \\int_0^T \\vert (\\mathbf{F}(s),w_i)_{\\Gamma_N}\\vert^2 \\, ds \\big \\} = 0\n    \\end{equation*}\n    and by using the uniform ellipticity of the tensor $\\mathbf{C}$, it can be concluded that $(u_m^{\\epsilon}(t))_{m \\in \\mathbb{N}}$ is a Cauchy sequence on the spaces $\\mathcal{C}^0(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))$ and $\\mathcal{C}^1(0,T; \\mathbf{L}^2(\\Omega, \\Gamma_D))$.\n    \n    \n    \\item Since the above spaces are complete, there exist $u^{\\epsilon}(t)$ limit as $m \\longrightarrow +\\infty$ of $u^{\\epsilon}_m(t)$ belonging to the spaces $\\mathcal{C}^0(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))$ and $\\mathcal{C}^1(0,T; \\mathbf{L}^2(\\Omega))$.\\\\\n    Let us see that $u^{\\epsilon}$ effectively solves the problem (\\ref{MainPDE}). To do this, let $m \\geq 1$ and consider $\\psi \\in \\mathcal{D}(0,T)$, since $u_m(t)$ solves (\\ref{AlphaODE}) it follows:\n    \\begin{equation*}\n        \\int_0^T (u_m^{\\epsilon}(t),v)_{\\Omega} \\partial_{tt}\\psi(t) + \\int_0^T \\mathcal{I}_C (u_m^{\\epsilon}(t),v) \\psi(t)  = \\int_0^T (\\mathbf{F}(t),v)_{\\Gamma_N} \\psi(t) \n    \\end{equation*}\n    so that, in the limit as $m \\longrightarrow 0$, the solution $u^{\\epsilon}(t)$ solves the problem\n    \\begin{equation*}\n        \\int_0^T (u^{\\epsilon}(t),v)_{\\Omega} \\partial_{tt}\\psi(t) + \\int_0^T \\mathcal{I}_C (u^{\\epsilon}(t),v) \\psi(t) = \\int_0^T (\\mathbf{F}(t),v)_{\\Gamma_N}\\psi(t) \n    \\end{equation*}\n    with $\\partial_t u^{\\epsilon}(0) = u^{\\epsilon}(0) = 0$ and the desired results follows. Moreover, continuity with respect to boundary data is obtained, since from (\\ref{AlphaBound}) the solution $u^{\\epsilon}(t)$ in the limit satisfies the inequality \n    \\begin{equation*}\n        \\big( \\mathcal{I}_C(u^{\\epsilon}(t), u^{\\epsilon}(t))+ \\vert \\partial_t u^{\\epsilon}(t) \\vert^2 \\big)^{1/2} \\leq \\int_0^T \\Vert \\mathbf{F}(t) \\Vert_{\\mathbf{L}^2(\\Gamma_N)} \\, dt \\leq T\\, \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T;\\mathbf{L}^2(\\Gamma_N)}\n    \\end{equation*}\n    and by the uniform boundness of the tensor $C$, the following bound is obtained\n    \\begin{equation*}\n        \\Vert u^{\\epsilon} \\Vert_{L^{\\infty}(0,T;\\mathbf{H}^1(\\Omega, \\Gamma_D))}  + \\Vert \\partial_t u^{\\epsilon} \\Vert_{L^{\\infty}(0,T;\\mathbf{L}^2(\\Omega))} \\lesssim T \\, \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T; \\mathbf{L}^2(\\Gamma_N))}\n    \\end{equation*}\n    Note in particular that the above bound is independent of $\\epsilon > 0$ since there is no dependency on the right-hand side of the inequality, from which follows well-possedness for each multiscale elastic problem with parameters $\\epsilon > 0$.\n\\end{enumerate}\n\n\\end{proof}\n\n%%%%%\n%%%%% THE ABOVE ADDED 21/10/2018\n%%%%%\n\nNow, the idea is to obtain a result of time regularity for the solution of the multiscale elastodynamic model. The motivation comes from \\textit{Panasenko} works \\cite{panasenko2005multi-scale}, who obtained such type of results in a general viscoelastic case with full \\textit{Dirichlet} boundary conditions.\n\nIn this case, a bootstrap type method is used to obtain the time-regularity for the mixed boundary problem, with the bounds derived from spectral theory.\n\n\\begin{prop}\n\\label{BootstrapingProp}\nLet $u^{\\epsilon} \\in \\mathcal{C}^{0}(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))$ denote the unique solution of the mixed boundary multiscale problem and suppose also the regularity for the parameters and surface force given by $C_{ijkl} \\in L^{\\infty}(\\mathbf{Y})$ and $\\mathbf{F} \\in \\mathcal{C}^p(0,T; \\mathbf{L}^{2}(\\Gamma_N))$, then for each $p \\geq 1$ we have that:\n\\begin{equation*}\n    u^{\\epsilon}, \\partial_t u^{\\epsilon} \\in \\mathcal{C}^p(0,T; \\mathbf{L}^2(\\Omega)).\n\\end{equation*}\n\\end{prop}\n\\begin{rem}\nIn particular, from the proof it's also possible to obtain that\n\\begin{equation*}\n    u^{\\epsilon}, \\partial_t u^{\\epsilon} \\in \\mathcal{C}^p(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D)).\n\\end{equation*}\n\\end{rem}\n\n\\begin{proof}\nLet us develop the main idea of the proof:\\\\\n\\begin{enumerate}\n    \\item Using the spectral theory for the existence of multiscale problem, it is obtained a solution $u^{\\epsilon}$ having regularity:\n    \\begin{equation*}\n        u^{\\epsilon} \\in \\mathcal{C}^0(0,T;\\mathbf{H}^1(\\Omega, \\Gamma_D)) \\cap \\mathcal{C}^1(0,T;\\mathbf{L}^2(\\Omega))\n    \\end{equation*}\n    thus the results being valid for initial cases $p = 0, 1$.\n    \\item Let us take $\\vert h \\vert \\ll 1$ such that $t+h \\in (0,T)$ and define the difference with parameter $\\epsilon > 0$ fixed as:\n    \\begin{equation*}\n        u_h^{\\epsilon}(t, \\mathbf{x}, \\frac{\\mathbf{x}}{\\epsilon}) := u^{\\epsilon} (t+h, \\mathbf{x}, \\frac{\\mathbf{x}}{\\epsilon}) - u^{\\epsilon}(t, \\mathbf{x}, \\frac{\\mathbf{x}}{\\epsilon})\n    \\end{equation*}\n    Now, defining the difference of surface forces as\n    \\begin{equation*}\n        \\mathbf{F}_h(t):= \\mathbf{F}(t+h) - \\mathbf{F}(t)\n    \\end{equation*}\n    it follows that the problem satisfied for functions $u_h^{\\epsilon}$ is given by:\n    \\begin{equation*}\n        (P_{\\epsilon}) \\left \\{\n        \\begin{array}{cc}\n            \\rho^{\\epsilon} \\partial_{tt} u_h^{\\epsilon} - \\nabla \\cdot \\sigma^{\\epsilon}( u_h^{\\epsilon} ) = \\mathbf{0}  &  \\text{ in } (0,T)\\times \\Omega \\\\\n            \\sigma^{\\epsilon}_{ij} (u^{\\epsilon}_h) = C^{\\epsilon}_{ijkl} \\mathbf{e}_{kl}(u^{\\epsilon}_h) & \\text{ in } (0,T) \\times \\Omega \\\\\n            C^{\\epsilon}_{ijkl}\\mathbf{e}_{kl}( u_h^{\\epsilon})n_j = \\mathbf{F}_h & \\text{ on } (0,T)\\times \\Gamma_N \\\\\n            u^{\\epsilon}_h = \\mathbf{0} & \\text{ on }(0,T)\\times \\Gamma_D\n        \\end{array}\n        \\right .\n    \\end{equation*}\n    with initial condition at rest (i.e. $\\partial_t u_h^{\\epsilon} = u_h^{\\epsilon} = \\mathbf{0}$ on $\\{t=0\\} \\times \\Omega$).\n    \n    \\item Using the assumption of regularity for the surface force $\\mathbf{F}$, it can be obtained from spectral theory the bound:\n    \\begin{equation*}\n        \\Vert u_h^{\\epsilon} \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_D)} + \\Vert \\partial_t u_h^{\\epsilon}\\Vert_{\\mathbf{L}^2(\\Omega)} \\lesssim \\int \\limits_t^{t+h} \\Vert \\mathbf{F}(s) \\Vert_{\\mathbf{L}^2(\\Gamma_N)} \\, ds\n    \\end{equation*}\n    so, from the continuity it is obtained that as $h \\rightarrow 0$, the terms \n    \\begin{equation*}\n        \\Vert u_h^{\\epsilon} \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_D)}, \\Vert \\partial_t u_h^{\\epsilon} \\Vert_{\\mathbf{L}^2 (\\Omega)} \\rightarrow 0\n    \\end{equation*}\n    then $u^{\\epsilon} \\in \\mathcal{C}^2(0,T; \\mathbf{L}^2(\\Omega))$.\n    \n    \n    \\item Now, let us observe that we can take a time derivative to the full problem $(P_{\\epsilon})$, and obtain a similar multiscale problem. Applying again the spectral theory, it is possible to obtain a solution $v_h^{\\epsilon} = \\partial_t u_h^{\\epsilon}$, satisfying same bounds as before. In such a way, it follows that:\n    \\begin{equation*}\n        \\Vert \\partial_{tt} u_h^{\\epsilon} \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_D)} + \\Vert \\partial_t u_h^{\\epsilon} \\Vert_{\\mathbf{L}^2 (\\Omega)} \\lesssim \\int_t^{t+h} \\Vert \\partial_t \\mathbf{F}(t) \\Vert_{\\mathbf{L}^2(\\Gamma_N)}\n    \\end{equation*}\n    so that, as $h \\rightarrow 0$ we conclude the regularity\n    \\begin{equation*}\n        \\partial_t u_h^{\\epsilon} \\in \\mathcal{C}^0(0,T;\\mathbf{H}^1(\\Omega, \\Gamma_D)) \\cap \\mathcal{C}^1(0,T;\\mathbf{L}^2(\\Omega)) \n    \\end{equation*}\n    then\n    \\begin{equation*}\n        u_h^{\\epsilon} \\in \\mathcal{C}^3(0,T; \\mathbf{L}^2(\\Omega))\n    \\end{equation*}\n    and by a bootstrap type argument, the results follows for each $p \\geq 1$.\n\\end{enumerate}\n\n\\end{proof}\n\n\n%%%%%\n%%%%% THE ABOVE ADDED 21/10/2018\n%%%%%\n\n\\section{Homogenization Procedure}\n\n In this section, it is described the procedure to obtain effective (or macroscopic) equations derived from the multiscale model (\\ref{MainPDE}), by means of asymptotic approximation of the displacement $u^{\\epsilon}(\\mathbf{x},t)$ proposed by the two-scale homogenization theory inspired from \\cite{altenbach2018generalized}. This framework enables us to obtain an effective PDE model governing the overall macroscopic mechanical behavior that incorporates the highly oscillatory microstructure variation by using the cell problems. It provides moreover an algorithmic procedure suitable for numerical implementation\\footnote{It keeps the mechanical behavior explicitly stated in all the derivation of the homogenized model, thus keeping its physical interpretation in the context of solid mechanics.}.\n\nTo give jargon regarding homogenization literature, the variable $\\mathbf{x}$ is defined as slow or global coordinate, while $\\mathbf{y}$ denote the fast or local variable, related by $\\mathbf{y} = \\epsilon^{-1}\\mathbf{x}$ as used before. In particular, the $\\epsilon$ parameter represent the highly-oscillatory periodicity assumed on the material components described by the cell structure.\n\n\\subsection{Two-Scale Asymptotic Homogenization}\nIt is assumed that displacement solutions to problem (\\ref{MainPDE}) can be expressed as expansion at different $\\epsilon$ scales. Thus, the solution is found by an asymptotic expression at each time $t \\in \\mathbb{R}_+$ in the form:\n\\begin{equation}\n    \\label{AsymptoticExpansion}\n    u^{\\epsilon}(t, \\mathbf{x}) = \\sum_{a=0}^{\\infty} \\epsilon^a u^{(a)}(t, \\mathbf{x},\\mathbf{y}) \n\\end{equation}\nwhere the vector functions $u^{(a)}(\\mathbf{x}, \\cdot)$ are assumed Y-periodic, spanning the full domain $\\Omega$ for each $a>0$. Moreover, throughout the developments it is assumed regularity for each $t \\in (0,T)$ in the form:\n\\begin{equation*}\n    u^{(a)}(t, \\mathbf{x},\\mathbf{y}) \\in \\mathbf{H}^1\\big(\\Omega; \\, \\mathbf{H}^1(\\mathbf{Y})\\big) \\quad \\forall a \\in \\mathbb{N}\n\\end{equation*}\nwhere $\\mathbf{H}^1(\\mathbf{Y})$ denotes the space of d-dimensional vector function on $H^1(\\mathbf{Y})$.\nIn what follows, it will be imposed several restrictions for the proposed solution (\\ref{AsymptoticExpansion}) to effectively satisfy the problem (\\ref{MainPDE}). In particular, the regularity assumption will naturally arise from restriction imposed for each $u^{(a)}$. In all that follows, it is dropped the time dependency in the functions for easiness of exposition.\n\nSince there is an explicit relation between slow and fast variables, it is considered expressions of strain rate dependent on each one. Let us define for $\\Phi \\in \\mathcal{C}^{\\infty}(\\Omega \\times \\mathbf{Y})$ the strain on each variable by:\n\\begin{equation*}\n    \\mathbf{e}_{kl,\\alpha} (\\Phi(\\alpha)) = \\frac{1}{2}(\\partial_{\\alpha_l} \\Phi_k (\\alpha) + \\partial_{x_k} \\Phi_l (\\alpha)) \\quad \\forall \\alpha \\in \\{\\mathbf{x}, \\mathbf{y}\\}\n\\end{equation*}\nthus, after applying it over the strain tensor $\\mathbf{e}(\\cdot)$ it follows the relation at components $k,l$ given in the form:\n\\begin{equation}\n    \\label{Multiscale-Strain}\n    \\mathbf{e}_{kl} ( u^{(a)}(\\mathbf{x}, \\frac{\\mathbf{x}}{\\epsilon})) = \\mathbf{e}_{kl,x}( u^{(a)} (\\mathbf{x},\\mathbf{y})) + \\epsilon^{-1} \\mathbf{e}_{kl,y} (u^{(a)}(\\mathbf{x},\\mathbf{y})).\n\\end{equation}\n%%%%%%%%%%%%\nIn the following, it is used a separation of scales to obtain the so-called homogenized coefficients, approximating the overall macroscopic (effective) behavior by applying the asymptotic solution, i.e., seeking\n\\begin{equation*}\n    \\rho^{\\epsilon}(\\mathbf{x}) u(\\mathbf{x})^{\\epsilon} + P^{(\\epsilon)}(u^{\\epsilon}(\\mathbf{x})) = \\mathcal{O}(\\epsilon^{\\gamma}) \\quad \\gamma \\geq 0\n\\end{equation*}\nwhere the elasticity operator $P^{(\\epsilon)}$ is expected to satisfy under some corrections\n\\begin{equation}\n    \\label{P-Operator}\n    P^{(\\epsilon)}(u^{\\epsilon}(\\mathbf{x}) = - div \\, \\big[\\mathbf{C}^{hom}(\\mathbf{x}): \\mathbf{e}(u^{(0)}(\\mathbf{x}))\\big] + \\mathcal{O}(\\epsilon)\n\\end{equation}\nwhere $\\mathbf{C}^{hom}(\\mathbf{x})$ is some four-order tensor to be found and the right-hand side $\\mathcal{O}(\\epsilon^{\\gamma})$ denotes the error expected from such an approximation. \n\nTo handle derivatives from (\\ref{P-Operator}), let us define the operator \n\\begin{equation*}\n    L_{\\alpha \\beta} (\\cdot) = - \\partial_{\\alpha_j} \\big( C_{ijkl} (\\mathbf{y}) \\mathbf{e}_{kl, \\beta}(\\cdot) \\big), \\quad \\alpha, \\beta \\in \\{ \\mathbf{x},\\mathbf{y} \\}\n\\end{equation*}\nAnd recall that by the chain rule $\\forall \\, \\Phi(\\mathbf{x},\\mathbf{y})$ enough regular vector functions, it follows:\n\\begin{equation*}\n    \\partial_{x_j} (\\Phi (\\mathbf{x}, \\frac{\\mathbf{x}}{\\epsilon})) = \\big \\{ \\partial_{x_j} \\Phi (\\mathbf{x}, \\mathbf{y}) + \\frac{1}{\\epsilon} \\partial_{y_j} \\Phi(\\mathbf{x},\\mathbf{y}) \\big \\}_{\\mathbf{y}= \\epsilon^{-1}\\mathbf{x}}.\n\\end{equation*}\n\nNow, using (\\ref{AsymptoticExpansion}), the idea is to regroup in powers of $\\epsilon$ thus impose constrains over each term $\\epsilon^{(a)}$ to satisfy the main formulation (\\ref{MainPDE}). To this end, note that from (\\ref{P-Operator}) it follows:\n\\begin{equation*}\n    P^{(\\epsilon)}(u(\\mathbf{x},\\epsilon)) = A + B + C + \\mathcal{O}(\\epsilon)\n\\end{equation*}\nwhere \n\\begin{equation*}\n    \\begin{array}{cc}\n        A &= P^{(\\epsilon)}(u^{(0)}(\\mathbf{x},\\mathbf{y})) \\\\\n        B &= \\epsilon P^{(\\epsilon)}(u^{(1)}(\\mathbf{x},\\mathbf{y})) \\\\\n        C &= \\epsilon^2 P^{(\\epsilon)}(u^{(2)}(\\mathbf{x},\\mathbf{y})) \\\\\n    \\end{array}\n\\end{equation*}\nExpanding every term and using (\\ref{Multiscale-Strain}), it follows:\n\\begin{align*}\n    A &= - \\partial_{x_j} \\big( C_{ijkl}\\mathbf{e}(u^{(0)}) \\big) \\\\\n    &=- \\partial_{x_j} \\big( C_{ijkl} \\mathbf{e}_{kl,x} (u^{(0)}) + \\frac{1}{\\epsilon}C_{ijkl}\\mathbf{e}_{kl,y}(u^{(0)}) \\big)\\\\\n    &= - L_{xx}u^{(0)} - \\frac{1}{\\epsilon} L_{yx}u^{(0)} - \\frac{1}{\\epsilon} L_{xy}u^{(0)} - \\frac{1}{\\epsilon^2}L_{yy}u^{(0)}\n\\end{align*}\nSimilarly, for the other terms it can be obtained:\n\\begin{align*}\n    B &= -\\epsilon L_{xx} u^{(1)} - L_{yx}u^{(1)} - L_{xy} u^{(1)} - \\frac{1}{\\epsilon} L_{yy}u^{(1)} \\\\\n    C &= -\\epsilon^2 L_{xx} u^{(2)} - \\epsilon L_{yx}u^{(2)} - \\epsilon L_{xy} u^{(2)} - L_{yy}u^{(2)} \n\\end{align*}\nSo, the following necessary conditions for powers of $\\epsilon$ are derived:\n\\begin{equation}\n    \\label{Epsilon-Separation}\n    \\begin{array}{ccc}\n        \\epsilon^{-2} \\longrightarrow & L_{yy} u^{(0)} &= \\mathbf{0} \\\\\n        \\epsilon^{-1} \\longrightarrow & L_{xy}u^{(0)} + L_{yx} u^{(0)} + L_{yy} u^{(1)} &= \\mathbf{0} \\\\\n        \\epsilon^{0} \\longrightarrow & L_{xx} u^{(0)} + L_{xy} u^{(1)} + L_{yx} u^{(1)} + L_{yy} u^{(2)} + \\rho^{\\epsilon} u^{(0)} &= \\mathbf{0}\n    \\end{array}\n\\end{equation}\n\nLet us consider the asymptotic expansion (\\ref{AsymptoticExpansion}) as an approximation for the exact solution of the original problem (\\ref{MainPDE}) where their boundary conditions had been replaced to the behavior at $\\mathcal{O}(1)$.\n\\begin{equation*}\n    \\begin{array}{cc}   \n        u^{(0)}(\\mathbf{x},\\mathbf{y}) = \\mathbf{0} & \\forall (\\mathbf{x}, \\mathbf{y}) \\in \\Gamma_D\\times \\mathbf{Y}\\\\\n        \\big(\\mathbf{C}(\\mathbf{y}): \\mathbf{e} (u^{(0)}(\\mathbf{x}, \\mathbf{y}) \\big) \\cdot n = \\hat{\\mathbf{F}}(\\mathbf{x}) & \\forall (\\mathbf{x},\\mathbf{y}) \\in \\Gamma_N \\times \\mathbf{Y}\n    \\end{array}\n\\end{equation*}\nand the remaining terms for each $a \\in \\mathbb{N}$ in the expansion are assigned by\n\\begin{equation*}\n    \\begin{array}{cc}\n        u^{(a)}(\\mathbf{x},\\mathbf{y}) = \\mathbf{0} & \\forall (\\mathbf{x}, \\mathbf{y}) \\in \\Gamma_D \\times \\mathbf{Y} \\\\\n        \\big( \\mathbf{C}(\\mathbf{y}): \\mathbf{e} (u^{(a)}(\\mathbf{x},\\mathbf{y}) \\big) \\cdot n = \\mathbf{0} & \\forall  (\\mathbf{x}, \\mathbf{y}) \\in \\Gamma_N\\times \\mathbf{Y} \n    \\end{array}\n\\end{equation*}\n\nLet us recall a classical results for elliptic problems. It relates the existence for problems in (\\ref{Epsilon-Separation}) by some compatibility conditions.\n\\begin{lem}\n\\label{ExistenceLemma}\nLet $f(\\cdot)$ be a square integrable function over $\\mathbf{Y}$. Consider the problem:\n\\begin{equation*}\n    L_{yy} \\Phi(\\mathbf{y}) = f(\\mathbf{y}) \\text{ in } \\mathbf{Y}\n\\end{equation*}\nwhere $\\Phi$ is $\\mathbf{Y}$-periodic function. Then it holds:\n\\begin{enumerate}\n    \\item There exist a $\\mathbf{Y}$-periodic solution $\\Phi$ iff $\\langle f \\rangle = \\mathbf{0}$\n    \\item If a $Y$-periodic solution $\\Phi$ exists, then it's unique up to a constant vector $\\mathbf{c} \\in \\mathbb{R}^d$.\n\\end{enumerate}\n\\end{lem}\n\n\\begin{rem}\nIt is being used as notation\n\\begin{equation*}\n    \\langle f \\rangle := \\frac{1}{\\vert Y \\vert} \\int_{\\mathbf{Y}} f(\\mathbf{y}) \\, d\\mathbf{y}\n\\end{equation*}\nwhere $\\vert Y \\vert$ denotes the measure of the set $\\mathbf{Y}$.\n\\end{rem}\n\n\\subsection{Contribution at Second Order}\nFor the contribution at order $\\mathcal{O}(\\epsilon^{-2})$ recall that problem (\\ref{MainPDE}) with their boundary conditions states:\n\\begin{equation}\n    \\label{Order-2VectorPDE}\n    \\left \\{\n    \\begin{array}{cc}\n        L_{yy} u^{(0)}( \\mathbf{x},\\mathbf{y}) = \\mathbf{0} & \\text{ in } \\Omega \\times \\mathbf{Y}\\\\\n        u^{(0)} (\\mathbf{x},\\mathbf{y}) = \\mathbf{0} & \\text{ in } \\Gamma_D \\times \\mathbf{Y} \\\\\n        \\big( \\mathbf{C}(\\mathbf{y}) :\\mathbf{e}(u^{(0)}(\\mathbf{x},\\mathbf{y}) \\big) \\cdot n = \\mathbf{F}(t, \\mathbf{x}) & \\text{ in } \\Gamma_N \\times \\mathbf{Y} \\\\\n    \\end{array}\n    \\right .\n\\end{equation}\nBy the Lemma (\\ref{ExistenceLemma}) it can be deduced that $u(\\mathbf{x},\\mathbf{y})$ is solution of (\\ref{Order-2VectorPDE}) iff it is constant with respect to the $\\mathbf{y}$-variable. It implies then:\n\\begin{equation}\n    \\label{IndepencyofY}\n    u^{(0)}(t, \\mathbf{x},\\mathbf{y}) = v(t, \\mathbf{x})\n\\end{equation}\ni.e. being independent with respect to the microstructure (or fast variable) $\\mathbf{Y}$. In particular, the contribution of the boundary conditions is associated to such vector function $v(t, \\mathbf{x})$, at each time $t \\in (0,T)$ in the form:\n\\begin{equation*}\n    \\begin{array}{cc}\n        v(\\mathbf{x}) = \\mathbf{0} & \\text{ on } \\Gamma_D\\\\\n        \\big(\\mathbf{C}(\\mathbf{y}):\\mathbf{e}(v(\\mathbf{x})) \\big) \\cdot n = \\mathbf{F}(\\mathbf{x}) & \\text{ on } \\Gamma_N \\times \\mathbf{Y}\n    \\end{array}\n\\end{equation*}\n\n\\subsection{Contributions at First Order}\nFor the contribution at order $\\mathcal{O}(\\epsilon^{-1})$ recall by (\\ref{IndepencyofY}) it follows $u^{(0)}(\\mathbf{x},\\mathbf{y}) = v(\\mathbf{x})$ then it can deduced by definition:\n\\begin{equation*}\n    L_{xy} v(\\mathbf{x}) = \\mathbf{0}\n\\end{equation*}\nSo, the problem formulation in (\\ref{Epsilon-Separation}) is reduced to\n\\begin{equation}\n    \\label{Order-1VectorPDE}\n    \\begin{array}{cc}\n        L_{yy} u^{(1)}(\\mathbf{x},\\mathbf{y}) = - L_{yx} v(\\mathbf{x}) & \\text{ in } \\Omega \\times \\mathbf{Y}\n    \\end{array}\n\\end{equation}\nNow, using the Lemma (\\ref{ExistenceLemma}) on (\\ref{Order-1VectorPDE}) taking into account (\\ref{IndepencyofY}), the $Y$-periodicity of $\\mathbf{C}(\\mathbf{y})$ and the diverge theorem, it follows:\n\\begin{equation*}\n    \\big\\langle - L_{yx} u^{(0)}(\\mathbf{x}, \\cdot) \\big\\rangle = \\mathbf{0}\n\\end{equation*}\nthus, the existence of solution for problem \\ref{Order-1VectorPDE} is satisfied.\n\nNow, by separation of variables and the second condition of lemma (\\ref{ExistenceLemma}), a general solution to the system of equations (\\ref{Order-1VectorPDE}) can be given by:\n\\begin{equation}\n    \\label{Order-1Ansatz}\n    u^{(1)}(\\mathbf{x},\\mathbf{y}) = \\mathbf{N}^{rs}(\\mathbf{y}) \\mathbf{e}_{rs,x}(v(\\mathbf{x})) \n\\end{equation}\nwhere $N^{rs} \\in \\mathbf{H}^1 (\\mathbf{Y})$ the so-called cell solution.\n\nThen replacing (\\ref{IndepencyofY}), (\\ref{Order-1Ansatz}) into (\\ref{Order-1VectorPDE}) results on the so-called cell problems. Explicitly, note that replacing the terms described before, it follows:\n\\begin{align*}\n    &\\,L_{yy} \\big( \\mathbf{N}^{rs} (\\mathbf{y}) \\mathbf{e}_{rs,x} (v(\\mathbf{x})) \\big) + L_{yx}(v(\\mathbf{x}) ) = \\mathbf{0} \\\\\n    \\implies& -\\partial_{y_j} \\big( C_{ijkl}\\mathbf{e}_{kl,y}(\\mathbf{N}^{rs}(\\mathbf{y}) ) \\mathbf{e}_{rs,x}(v(\\mathbf{x})) = \\partial_{y_j} \\big( C_{ijrs}\\mathbf{e}_{rs,x}(v(\\mathbf{x})) \\big) \\\\\n    \\implies& - \\partial_{y_j} \\big( C_{ijkl} \\mathbf{e}_{kl,y} (\\mathbf{N}^{rs}(\\mathbf{y})) \\big) = \\partial_{y_j} (C_{ijrs})\n\\end{align*}\nand applying lemma (\\ref{ExistenceLemma}), it follows that $\\mathbf{N}^{rs}$ is $Y$-periodic where it has been added the boundary conditions taken from (\\ref{Order-1VectorPDE}), obtaining:\n\\begin{equation*}\n    \\left \\{\n    \\begin{array}{cc}\n         - \\partial_{y_j} \\big( C_{ijkl} \\mathbf{e}_{kl,y} (\\mathbf{N}^{rs}(t,\\mathbf{y})) \\big) = \\partial_{y_j} (C_{ijrs}) & \\text{ in } (0,T)\\times \\mathbf{Y} \\\\\n        \\big( \\mathbf{C}(\\mathbf{y}) : \\mathbf{e}(\\mathbf{N}^{rs}(t,\\mathbf{y})) \\big) \\cdot n = \\mathbf{0} & \\text{ on } (0,T)\\times \\partial \\mathbf{Y}\\\\\n        \\mathbf{N}^{rs} (0, \\mathbf{y}) = \\mathbf{0} &  \\text{ in } \\mathbf{Y}\n    \\end{array}\n    \\right.\n\\end{equation*}\n\nthe above deduced by construction using the ansatz (\\ref{Order-1Ansatz}) define a solution to the PDE system (\\ref{Order-1VectorPDE}).\n\n\\subsection{Contribution at the zero order}\nFor the contribution at order $\\mathcal{O}(\\epsilon^0)$ problem (\\ref{MainPDE}) after regrouping the terms it follows:\n\\begin{equation}\n    \\label{Order-0VectorPDE}\n    \\begin{array}{cc}\n        L_{yy} u^{(2)} = \\rho^{\\epsilon}(\\mathbf{x})\\partial_{tt} v(\\mathbf{x}) - \\tilde{P}(u^{(1)},u^{(2)}) (\\mathbf{x},\\mathbf{y}) & \\text{ in } \\Omega \\times \\mathbf{Y}\n    \\end{array}\n\\end{equation}\nwhere it has been denoted \n\\begin{equation*}\n    \\tilde{P}(u^{(0)}, u^{(1)}) (\\mathbf{x},\\mathbf{y}) :=  L_{xx} u^{(0)} + L_{xy} u^{(1)} + L_{yx} u^{(1)}\n\\end{equation*}\nthen by Lemma \\ref{ExistenceLemma}, it follows existence of a $Y$-periodic solution of (\\ref{Order-0VectorPDE}) iff \n\\begin{equation}\n    \\label{Order-0ExistenceCond}\n    \\big \\langle \\rho(\\mathbf{y}) \\partial_{tt} v(\\mathbf{x}) - L_{xx} u^{(1)} (\\mathbf{x},\\mathbf{y}) - L_{xy} u^{(1)}(\\mathbf{x},\\mathbf{y}) - L_{yx} u^{(1)}(\\mathbf{x},\\mathbf{y}) \\big \\rangle = \\mathbf{0}\n\\end{equation}\nFrom \\ref{Order-0ExistenceCond} the homogenized equation is obtained, which can be deduced explicitly in the form:\n\\begin{align*}\n    & \\quad \\langle \\rho(\\mathbf{y}) \\rangle \\partial_{tt} v(\\mathbf{x}) + \\langle L_{xx} u^{(0)}(\\mathbf{x},\\mathbf{y}) +L_{xy} u^{(1)}(\\mathbf{x},\\mathbf{y}) \\rangle = \\mathbf{0} \\\\\n    \\Leftrightarrow & \\quad \\langle \\rho(\\mathbf{y}) \\rangle \\partial_{tt} v(\\mathbf{x}) + \\langle L_{xx} u^{(0)}(\\mathbf{x}, \\mathbf{y}) + L_{xy}\\big( \\mathbf{N}^{rs}(\\mathbf{y})\\mathbf{e}_{rs,x}(v(\\mathbf{x})) \\big) = \\mathbf{0} \\\\\n    \\Leftrightarrow & \\quad \\langle \\rho\\rangle \\partial_{tt} v_i(\\mathbf{x}) - \\partial_{x_j}\\big \\langle \\big(C_{ijrs}^{hom}(\\mathbf{N}^{rs})\\big) \\mathbf{e}_{rs,x}(\\hat{v}(\\mathbf{x})) \\big \\rangle  = \\mathbf{0} \\quad \\forall i \\in \\{1,\\dots, d\\}\\\\\n    \\Leftrightarrow & \\quad \\rho^{0} \\partial_{tt} v_i(\\mathbf{x}) - C_{ijkl}^{hom} \\partial_{x_j} \\mathbf{e}_{rs,x} (v(\\mathbf{x})) = \\mathbf{0} \\quad \\forall i \\in \\{1,\\dots,d\\}\n\\end{align*}\nwhere it is denoted $\\rho^{0} = \\langle \\rho \\rangle$ and $C_{ijrs}^{hom}$ the so-called homogenized elastic coefficients defined by \n\\begin{equation*}\n    C_{ijrs}^{hom} = \\big \\langle C_{ijrs}(\\mathbf{y}) + C_{ijkl}\\mathbf{e}_{kl,y}\\big(\\mathbf{N}^{rs}(\\mathbf{y})\\big) \\big \\rangle \n\\end{equation*}\nWith the above definition and the homogenized equation obtained from (\\ref{Order-0VectorPDE}) it can be obtained the effective behavior of the system defined by:\n\\begin{equation}\n    \\label{HomogenizedPDE}\n    \\left \\{\n    \\begin{array}{cc}\n        \\rho^{0} \\partial_{tt} v - \\nabla \\cdot \\sigma^{0} (v) = \\mathbf{0} & \\text{ in } (0,T) \\times \\Omega \\\\\n        \\sigma^{0}_{ij}(v) = C^{hom}_{ijkl}\\mathbf{e}_{kl,x}(v) & \\text{ in } (0,T)\\times\\Omega \\\\\n        v = \\mathbf{0} & \\text{ on } (0,T)\\times\\Gamma_D \\\\\n        \\sigma^{0}(v) \\cdot n = \\mathbf{F} & \\text{ on }(0,T)\\times \\Gamma_N\n    \\end{array}\n    \\right .\n\\end{equation}\nIn particular, the PDE problem (\\ref{HomogenizedPDE}) is well-posed and the mechanical behavior maintains the linear elasticity property from the material.\n\nFinally, it will be useful in the next chapters to recall that the homogenized elastic operator defines a bilinear form on $\\mathbf{H}^1(\\Omega, \\Gamma_D)$ by:\n\\begin{equation*}\n    a(u,v) := \\int \\limits_{\\Omega} \\sigma^{hom}_{ij}(u(\\mathbf{x}) \\partial_{x_j} v_i \\, dx \\quad u,v \\in \\mathbf{H}^1(\\Omega, \\Gamma_D)\n\\end{equation*}\nmoreover, since the homogenized coefficients are bounded and uniformly elliptic it can be applied the classical theorem of spectral decomposition \\cite{raviart1983introduction}.\n\\begin{prop}\n\\label{EigenValuesProp}\nLet $V \\subset H$ Hilbert spaces, such that $V$ is dense and continuously embedded in $H$. Suppose the canonical injection from $V$ on $H$ is compact, and the bilineal form $a(\\cdot, \\cdot)$ is symmetric, V-elliptic. Then there exist an increasing sequence which tend to $+ \\infty$ of eigenvalues\n\\begin{equation*}\n    0 < \\lambda_1 < \\lambda_2  \\leq \\dots \\leq \\lambda_m \\leq \\cdots \n\\end{equation*}\nand a hilbertian orthonormal base of $H$ given by eigenvector $w_m$ such that:\n\\begin{equation*}\n    \\forall v \\in V, \\quad a(w_,, v) = \\lambda_m (w_m, v), \\quad \\forall m = 1, 2, \\dots\n\\end{equation*}\n\\end{prop}\n\n\n\n\\section{Justification of the homogenization}\nHaving obtained the homogenized model, in this section it is developed the justification procedure of convergence for the solution in the space $\\mathbf{H}^1(\\Omega, \\Gamma_D)$. It corresponds to an extension of the work done by \\cite{oleinik1992mathematical} in the static case. To handle easily the derivatives, it will be reformulated the problem (\\ref{MainPDE}) to a canonical form described below\\footnote{The choice of a canonical formulation for the mixed boundary elastodynamic model is based on straightforward usage of space derivatives and estimations to assure the justification of the asymptotic solution, in the sense that the two-scale approximate solution $u^{\\epsilon}(t, \\mathbf{x})$ converge to the real (experimental solution) $u(t, \\mathbf{x})$ in some space with enough regularity.}.\n\nOver the bounded smooth domain $\\Omega \\subset \\mathbb{R}^d$ it is considered the multiscale problem of second order in time:\n\\begin{equation}\n    \\label{MainMultiPDE}\n    \\left \\{\n    \\begin{array}{cc}\n        \\mathcal{L}_{\\epsilon}(u^{\\epsilon}) := \\rho\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{tt} u^{\\epsilon} - \\partial_{x_h} \\big( A^{hk}\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_k} u^{\\epsilon} \\big)  = \\mathbf{0} & \\text{ in } (0,T)\\times \\Omega  \\\\\n        \\sigma^{\\epsilon}(u^{\\epsilon})\\cdot n := A^{hk}\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_k} u^{\\epsilon} n_k  = \\mathbf{F}(t,\\mathbf{x}) & \\text{ on } (0,T) \\times \\Gamma_N \\\\\n        u^{\\epsilon} =  \\mathbf{0} & \\text{ on } (0,T) \\times \\Gamma_D \\\\\n        \\partial_t u^{\\epsilon} = u^{\\epsilon} = \\mathbf{0} & \\text{ on } \\{ t=0 \\} \\times \\Omega \n    \\end{array}\n    \\right.\n\\end{equation}\nbeing $n$ the unit outward normal to $\\partial \\Omega$, the disjoint decomposition $\\partial \\Omega = \\Gamma_D \\dot \\cup \\Gamma_N$ and assumed enough regularity for the boundaries (at least \\textit{Lipschitz}). It is also assumed that the coefficients matrices $A^{hk}(\\mathbf{y})$ are smooth functions, $1$-periodic that satisfy conditions of uniformly ellipticity and boundness in $\\mathbf{y}$.\\\\\nRecall also from (\\ref{HomogenizedPDE}) the homogenized mixed boundary problem, rewritten in canonical form is given by:\n\\begin{equation}\n    \\label{HomMultiPDE}\n    \\left \\{\n    \\begin{array}{ccc}\n        \\mathcal{L}_0 (u^0) := \\rho^0 \\partial_{tt} u^0 - \\partial_{x_h}\\big( A^{hk}_{hom} \\partial_{x_k} u^0 \\big) = \\mathbf{0} & \\text{ in } (0,T)\\times \\Omega \\\\\n        \\sigma^0(u^0) \\cdot n := A^{hk}_{hom} \\partial_{x_k}u^0 n_h = \\mathbf{F}(t, \\mathbf{x}) & \\text{ on } (0,T) \\times \\Gamma_N \\\\\n        u^0 = \\mathbf{0} & \\text{ on } (0,T) \\times \\Gamma_D \\\\\n        \\partial_t u^0 = u^0 = \\mathbf{0} & \\text{ on } \\{ t=0 \\} \\times \\Omega\n    \\end{array}\n    \\right .\n\\end{equation}\nwhere the matrices $A^{hk}_{hom}$ (denoting the homogenized material coefficients) are defined by the formulas:\n\\begin{equation}\n    \\label{HomCoeffs}\n    A^{pq}_{hom} = \\int \\limits_{\\mathbf{Y}} A^{pq}(\\mathbf{y}) + A^{pj} (\\mathbf{y}) \\partial_{y_j} \\mathbf{N}^q (\\mathbf{y}) \\, d\\mathbf{y}\n\\end{equation}\nbeing the matrices $\\mathbf{N}^q(\\mathbf{y})$ the so-called cell solutions of the following boundary value problem:\n\\begin{equation}\n    \\label{CellProblems}\n    \\left \\{\n    \\begin{array}{cc}\n        \\partial_{y_k} \\big( A^{kj}(\\mathbf{y}) \\partial_{y_j} \\mathbf{N}^q \\big) = -\\partial_{y_k} \\big( A^{kq}(\\mathbf{y}) \\big) & \\text{ in } \\mathbf{Y} \\\\\n        \\mathbf{N}^q(\\mathbf{y}) \\quad 1\\text{-periodic in } \\mathbf{y}, & \\int_{\\mathbf{Y}}  \\mathbf{N}^q (\\mathbf{y}) \\, d\\mathbf{y} = \\mathbf{0}\n    \\end{array}\n    \\right .\n\\end{equation}\nwhere $\\mathbf{Y} = (0,1)^d$ is the characteristic microstructure and $d \\in \\mathbb{N}^*$ denotes the dimension, usually $2$ or $3$.\\\\\n\n\\begin{rem}\n Let us note from (\\ref{CellProblems}) that by applying  coercivity and boundness conditions over the coefficients $A^{kj}(\\mathbf{y})$, it follows continuity and boundness conditions on (\\ref{HomCoeffs}). Thus the homogenized problem (\\ref{HomMultiPDE}) is of elastic type, and moreover it can be applied the same proof as in the case of prop. \\ref{BootstrapingProp} obtaining by bootstrapping method:\n \\begin{equation*}\n     u^0, \\, \\partial_{t} u^0 \\in \\mathcal{C}^p (0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))\n \\end{equation*}\n\\end{rem}\n\nIt is assumed an approximate solution to the problem (\\ref{MainMultiPDE}) in the form:\n\\begin{equation}\n    \\label{Asymptotic}\n    \\tilde{u}(t,\\mathbf{x}) = u^0 (t,\\mathbf{x}) + \\epsilon \\mathbf{N}^{s} \\big(\\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0(t,x)\n\\end{equation}\nwhere $u^0$ is the solution to problem (\\ref{HomMultiPDE}) and $\\mathbf{N}^{s} (\\mathbf{y})$ solutions to the so-called cell problems (\\ref{CellProblems}).\n\n%The function $\\varphi(\\mathbf{x})$ denotes the truncation function satisfying the conditions \n%\\begin{enumerate}\n%    \\item $\\varphi \\in \\mathcal{C}^{\\infty}(\\Omega)$ with $\\vert \\nabla \\varphi\\vert \\lesssim \\epsilon^{-1}$,\n%    \\item $\\varphi = 0$ in $\\Gamma_D$ and $\\varphi = 1$ outside an $\\epsilon$-neighborhood of $\\Gamma_D$.\n%\\end{enumerate}\n%Such type of functions exists, in particular, we can consider the function $\\varphi(\\mathbf{x}) := w(\\epsilon^{-1} \\rho(\\mathbf{x},\\partial \\Omega))$ being\n\n%\\begin{equation*}\n%    w(t) = \n%    \\left \\{\n%    \\begin{array}{cc}\n%        t & \\text{ if } 0 \\leq t \\leq 1 \\\\\n%        1 & \\text{ if } t > 1\n%    \\end{array}\n%    \\right .\n%\\end{equation*}\n\n%\\begin{rem}\n%The truncation function $\\varphi$ enters in the expression of $\\tilde{u}$ since the matrices $\\mathbf{N}^s \\big(\\frac{\\mathbf{x}}{\\epsilon}\\big)$ are in general not defined in a neighborhood of $\\Gamma_D$ (the other boundaries $\\Gamma_N$ are associated with \\textit{Neumann} type boundary conditions).\n%\\end{rem}\n\nNow, let us enunciate the main result, where the sketch of proof will be presented in the next section.\n\\begin{theo}\nAssuming that $\\mathbf{F} \\in L^{\\infty}(0,T;\\mathbf{L}^{2}(\\Gamma_N))$ and also $\\mathbf{N}^q \\in L^{\\infty}(0,T; \\mathbf{H}^1(\\Omega))$ for each $q \\in \\{1,\\dots, N\\}$. Then the solutions $u^{\\epsilon}$ and $u^0$ of problems (\\ref{MainMultiPDE}) and (\\ref{HomMultiPDE}) respectively, satisfy the following inequality\n\\begin{equation*}\n    \\label{MainInequality}\n    \\Vert u^{\\epsilon} - u^0 - \\epsilon \\mathbf{N}^s \\big(\\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0 \\Vert_{L^{\\infty}(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))} \\lesssim \\epsilon^{1/2} \\Vert u^0 \\Vert_{L^{\\infty}(0,T; \\mathbf{H}^{3}(\\Omega))}\n\\end{equation*}\n\\end{theo}\n\n\\section{Sketch of the Proof}\nThe result is constructed using the work done on \\cite{oleinik1992mathematical}, extending it from the elastostatic case to the elastodynamic model with mixed boundary conditions by controlling the behavior of each time-dependent that appears in the deduction. In this sense, the proof corresponds to an extension of the work done by \\textit{Oleinik}.\n\nThe idea will be to study at fixed time $t \\in (0,T)$ the elastodynamic operator $\\mathcal{L}_{\\epsilon}$.\nLet us apply the operator $\\mathcal{L}_{\\epsilon}$ to a vector valued function $u^{\\epsilon}-\\tilde{u}$, where $\\tilde{u}$ is defined by (\\ref{Asymptotic}), then:\n\\begin{align*}\n    \\mathcal{L}_{\\epsilon} (u^{\\epsilon}-\\tilde{u}) =&\\, \\rho^{\\epsilon} \\partial_{tt} (u^{\\epsilon}-\\tilde{u}) - \\partial_{x_h} \\big( A^{hk}\\partial_{x_k} u^{\\epsilon} \\big) + \\partial_{x_h} \\big( A^{hk}\\partial_{x_k} (u^0 + \\epsilon \\mathbf{N}^s \\partial_{x_s}u^0 )\\big) \\\\\n    \\overset{(*)}{=}& - (\\rho^{\\epsilon}-\\rho^0) \\partial_{tt} u^0 - \\epsilon \\rho^{\\epsilon} \\partial_{tt}\\big(\\mathbf{N}^s \\partial_{x_s}u^0 \\big)  \\\\\n    & - \\partial_{x_h} \\big[ \\big( A_{hom}^{hk} - A^{hk} - \\epsilon A^{hj}\\partial_{x_j} \\mathbf{N}^k \\big) \\partial_{x_k} u^0 \\big] + \\epsilon \\partial_{x_h} \\big( A^{hk} \\mathbf{N}^s \\partial_{x_k x_s} u^0 \\big) \n\\end{align*}\nwhere in $(*)$ it was rewritten, relabeled and separated term with $\\epsilon$ order.\nTaking into account the equation in (\\ref{CellProblems}) for the $\\mathbf{N}^s$ it follows:\n\\begin{align*}\n    \\mathcal{L}_{\\epsilon} (u^{\\epsilon} - \\tilde{u})  :=& - (\\rho^{\\epsilon}-\\rho^0) \\partial_{tt} u^0 - \\epsilon \\rho^{\\epsilon} \\partial_{tt}\\big(\\mathbf{N}^s \\partial_{x_s}u^0 \\big) + \\epsilon A^{hk}\\mathbf{N}^s \\partial_{x_h x_k x_s}u^0 \\\\\n    & - \\big[ A^{pq}_{hom} - A^{pq} - A^{pj} \\partial_{y_j} \\mathbf{N}^q - \\partial_{y_h}(A^{hp} \\mathbf{N}^q) \\big] \\partial_{x_p x_q} u^0 \n    \\end{align*}\n\nFrom the above expression, let us define the matrices $\\mathbf{N}^{hk}(\\mathbf{y})$ as weak solutions of the following boundary value problem\n\\begin{equation}\n    \\label{SecondCellProblem}\n    \\left \\{\n    \\begin{array}{cc}\n        \\partial_{y_k} \\big( A^{kj}\\partial_{y_j} \\mathbf{N}^{pq}\\big) = -\\partial_{y_k} \\big( A^{kp} \\mathbf{N}^q\\big) - A^{pj}\\partial_{y_j} \\mathbf{N}^q - A^{pq} + A^{pq}_{hom} & \\text{ in } \\mathbf{Y}\\\\\n        \\sigma(N^{pq})\\cdot n := A^{kl}\\partial_{x_k}\\mathbf{N}^{pq}n_l = - n_k A^{pk}\\mathbf{N}^q & \\text{ on } \\partial \\mathbf{Y} \\\\\n        \\mathbf{N}^{hk}(\\mathbf{y}) \\text{ $\\mathbf{Y}$-periodic}, \\quad  \\int_{\\mathbf{Y}} N^{pq} d \\mathbf{y} = \\mathbf{0} &\n    \\end{array}\n    \\right .\n\\end{equation}\n\nSo, using (\\ref{SecondCellProblem}) it can be obtained:\n\\begin{align*}\n    \\mathcal{L}_{\\epsilon} (u^{\\epsilon} -\\tilde{u})  = & - (\\rho^{\\epsilon}-\\rho^0) \\partial_{tt} u^0 - \\epsilon \\rho^{\\epsilon} \\partial_{tt}\\big(\\mathbf{N}^s \\partial_{x_s}u^0 \\big)  \\\\\n    & + \\epsilon A^{hk} \\mathbf{N}^s \\partial_{x_h x_k x_s} u^0 + \\epsilon A^{kj} \\partial_{y_j} \\mathbf{N}^{pq} \\partial_{x_p x_q x_k} u^0  \\\\\n    & - \\epsilon \\partial_{x_k} \\big[ A^{kj} \\partial_{y_j} \\mathbf{N}^{pq} \\partial_{x_p x_q} u^0\\big] \n\\end{align*}\n\nThus, it follows:\n\\begin{equation}\n    \\mathcal{L}_{\\epsilon} (u^{\\epsilon}-\\tilde{u}) = G_{tt}^0 + \\epsilon G_{tt}^1 + \\epsilon F_0 + \\epsilon \\partial_{x_k} F_k\n\\end{equation}\nwhere each term is defined by:\n\\begin{equation}\n    \\label{Variables}\n    \\begin{aligned}\n        G_{tt}^0 = & -(\\rho^{\\epsilon} - \\rho^0) \\partial_{tt}u^0 \\\\\n        G_{tt}^1 = & -\\rho^{\\epsilon} \\partial_{tt}(\\mathbf{N}^s \\partial_{x_s} u^0) \\\\\n        F_0 = & \\, A^{hk}N^s \\partial_{x_h x_k x_s} u^0  + A^{kj}\\partial_{y_j} \\mathbf{N}^{pq} \\partial_{x_p x_q x_k} u^0 \\\\\n        F_k = & - A^{kj} \\partial_{y_j} \\mathbf{N}^{pq} \\partial_{x_p x_q} u^0 \n    \\end{aligned}\n\\end{equation}\n\n\\begin{rem}\nLet us recall the two-scale asymptotic solution proof, by the hypothesis of continuity for the $\\mathcal{O}(1)$ term in the form:\n\\begin{equation*}\n    v \\in \\mathcal{C}^2(0,T; \\mathbf{H}^1(\\Omega, \\Gamma_D))\n\\end{equation*}\nIt follows that terms $G^0_{tt}, G_{tt}^1$ are bounded.\n\\end{rem}\n\nLet us now obtain a expression for the \\textit{Neumann} condition at $\\Gamma_N$. To this end, applying $\\sigma_{\\epsilon}$ to the difference $u^{\\epsilon} - \\tilde{u}$ it follows that:\n\\begin{align*}\n    \\sigma_{\\epsilon} (u^{\\epsilon} - \\tilde{u}) & =  \\sigma_{\\epsilon}(u^{\\epsilon}) - \\sigma_{\\epsilon} (\\tilde{u}) \\\\\n    & = F_h(t) n_h - A^{hk} \\partial_{x_k} \\big( u^0 + \\epsilon N^s \\partial_{x_s}u^0 \\big)n_h \\\\\n    & = \\big(A^{hk}_{hom} - A^{hk} \\big) \\partial_{x_k} u^0 n_h - A^{hl} \\partial_{y_l} N^s \\partial_{x_s} u^0 n_h - \\epsilon A^{hk} N^s \\partial_{x_k x_s} u^0 n_h\n\\end{align*}\n\nTaking into account the obtained expression, let us define:\n\\begin{equation*}\n    \\alpha^{is}(\\mathbf{y}) := A^{is}_{hom} - A^{is}(\\mathbf{y}) - A^{ij}(\\mathbf{y}) \\partial_{y_j} \\mathbf{N}^s(\\mathbf{y}), \\quad i,s \\in \\{1,\\dots, d\\}\n\\end{equation*}\nThat allows us to obtain the expression at the \\textit{Neumann} boundary in the form:\n\\begin{equation}\n    \\label{NeumannExp}\n    \\begin{aligned}\n    \\sigma_{\\epsilon} (u^{\\epsilon}-\\tilde{u}) &= \\alpha^{hs} \\partial_{x_s} u^0 n_h - \\epsilon A^{hk}N^s \\partial_{x_k x_s} u^0 n_h \\\\\n    & = I_0 + \\epsilon I_1\n    \\end{aligned}\n\\end{equation}\nwhere $I_0 = \\alpha^{hs} \\partial_{x_s} u^0 n_h$ and $I_1= -A^{hk}N^s \\partial_{x_k x_s} u^0 n_h$. \nThe function $\\alpha^{hs}$ has already been studied in the similar context by \\textit{Oleinik} \\cite{oleinik1992mathematical}, who shown a continuity property: For each $v \\in \\mathbf{H}^1(\\Omega)$ \n\\begin{equation}\n    \\label{OleinikLemma2.2}\n    \\left \\vert \\int_{\\partial \\Omega} \\alpha^{ik}(\\frac{\\mathbf{x}}{\\epsilon}) v_k n_i \\,ds \\right \\vert \\lesssim\\epsilon^{1/2} \\Vert \\nabla v \\Vert_{\\mathbf{L}^2(\\Omega)}\n\\end{equation}\nwhich applies to our case of functions $v \\in \\mathbf{H}^1(\\Omega, \\Gamma_D)$, whereas the $I_2$ term can be shown to satisfy similarly the bound:\n\\begin{equation}\n    \\label{I1-bound}\n    \\left \\vert \\int_{\\partial \\Omega} I_2 \\right \\vert \\lesssim \\epsilon^{1/2} \\Vert \\nabla u_0 \\Vert_{\\mathbf{L}^2(\\Omega)}\n\\end{equation}\nThe intuition behind  (\\ref{I1-bound}) relies in using that $\\partial \\Omega \\subset \\partial B_{\\epsilon}(\\Omega)$ where $B_{\\epsilon}(\\Omega) = \\{ \\mathbf{x} \\in \\Omega \\, \\vert \\, \\rho(\\mathbf{x}, \\Omega) \\leq \\epsilon \\}$ from which the $\\epsilon^{1/2}$ bound follows by applying \\textit{Lemma 2.2} from \\cite{oleinik1992mathematical} with the uniform bound on $\\mathbf{Y}$ of $A^{hk}$ and $N^s$.\n\n\nOn the other hand, at the boundary $\\Gamma_D$ for the difference $u^{\\epsilon} - \\tilde{u}$ it follows:\n\\begin{equation*}\n    u^{\\epsilon} - \\tilde{u} = - \\epsilon N^s \\partial_{x_s}u^0 \\equiv \\psi_{\\epsilon}\n\\end{equation*} \nSuch kind of function satisfies moreover\n\\begin{equation}\n    \\label{BoundDirichlet}\n    \\Vert \\psi_{\\epsilon} \\Vert_{\\mathbf{H}^{1/2}(\\Gamma_D)} \\lesssim \\epsilon^{1/2} \\Vert u^0 \\Vert_{\\mathbf{H}^2(\\Omega)}\n\\end{equation} \nTo prove (\\ref{BoundDirichlet}), it suffices to find a function $\\Psi_{\\epsilon} \\in H^1(\\Omega)$ such that $\\Psi_{\\epsilon} \\vert_{\\Gamma_D} = \\psi_{\\epsilon} \\in \\mathbf{H}^{1/2}(\\Gamma_D)$ with $\\Vert \\Psi_{\\epsilon} \\Vert_{\\mathbf{H}^1(\\Omega)} \\lesssim \\epsilon^{1/2} \\Vert u^0 \\Vert_{\\mathbf{H}^2(\\Omega)}$.\n\nLet us define such $\\Psi_{\\epsilon}(\\mathbf{x})$ using a cutoff function. To this end, let $\\varphi_{\\epsilon} \\in \\mathcal{C}^{\\infty}(\\Omega)$ be such that:\n\\begin{equation*}\n    \\left \\{\n    \\begin{aligned}\n    \\varphi_{\\epsilon}(\\mathbf{x}) = 1 & \\text{ if } \\rho(\\mathbf{x}, \\Gamma_D) \\leq \\epsilon \\\\\n    \\varphi_{\\epsilon}(\\mathbf{x}) = 0 & \\text{ if } \\rho(\\mathbf{x}, \\Gamma_D) \\geq 2\\epsilon \n    \\end{aligned}\n    \\right.\n\\end{equation*}\nwith $0 \\leq \\varphi_{\\epsilon}(\\mathbf{x}) \\leq 1$ and $\\vert \\nabla \\varphi_{\\epsilon} \\vert \\lesssim \\epsilon^{-1}$.\nThen, by construction it follows that $\\Psi_{\\epsilon} := \\epsilon \\varphi_{\\epsilon} N^s \\partial_{x_s}u^0 \\in \\mathbf{H}^1(\\Omega)$.\nThus, from $\\varphi_{\\epsilon}$ and the uniformly boundness in $\\epsilon$ of $N^s, \\partial_{y_j} N^s$ for each $s,j \\in \\{1,\\dots, d\\}$ it follows:\n\\begin{equation*}\n    \\Vert \\Psi_{\\epsilon} \\Vert_{H^1(\\Omega)} \\leq \\Vert u^0 \\Vert_{H^1(B_{\\epsilon}(\\Gamma_D))} + \\epsilon \\Vert u^0 \\Vert_{\\mathbf{H}^2(\\Omega)}\n\\end{equation*}\nbeing $B_{\\epsilon}(\\Gamma_D) = \\{\\mathbf{x}\\in \\Omega \\, :\\, \\rho(\\mathbf{x},\\Gamma_D) \\leq 2\\epsilon \\}$. From which it can be deduced the desired result after applying the  result (Lemma 1.5 at \\cite{oleinik1992mathematical}). %$\\Vert u^0 \\Vert_{\\mathbf{H}^1(\\Omega^{\\epsilon})} \\lesssim \\epsilon^{1/2} \\Vert u^0 \\Vert_{\\mathbf{H}^2(\\Omega)}$.\n\nFrom the developments done, a mixed boundary evolution problem for the variable $u^{\\epsilon} - \\tilde{u}$ is obtained given by:\n\\begin{equation}\n    \\label{MixedFormulationDiff}\n    \\left \\{\n    \\begin{aligned}\n        \\mathcal{L}_{\\epsilon}(u^{\\epsilon} - \\tilde{u}) = G_{tt}^0 + \\epsilon G_tt^1 + \\epsilon \\partial_{x_k} F_k + \\epsilon F_0   & \\text{ in } (0,T) \\times \\Omega \\\\\n        u^{\\epsilon}-\\tilde{u} = \\psi_{\\epsilon} & \\text{ on } (0,T)\\times \\Gamma_D\\\\\n        \\sigma_{\\epsilon}(u^{\\epsilon}-\\tilde{u}) = I_0 + \\epsilon I_1 & \\text{ on } (0,T)\\times\\Gamma_N\n    \\end{aligned}\n    \\right .\n\\end{equation}\nwhere each term $G_{tt}^0, G_{tt}^1, F_k^0$ are uniformly bounded in $\\epsilon$ and time, $I_0, I_1$ bounded in (\\ref{OleinikLemma2.2}), (\\ref{I1-bound}) respectively\nand $\\psi_{\\epsilon}$ bounded in (\\ref{BoundDirichlet}). Moreover, the operator $\\mathcal{L}_{\\epsilon}(\\cdot)$ is of linear elastic type.\nIt follows that (\\ref{MixedFormulationDiff}) defines a well-posed evolution problem, which can be solved as in the case of the previous multiscale problems by using the spectral decomposition method \\cite{raviart1983introduction}. Thus, the existence of solution is guaranteed and the continuity condition with respect to the initial data implies in particular the bound\n\\begin{equation*}\n    \\Vert u^{\\epsilon} - u^0 - \\epsilon N^s \\partial_{x_s}u^0 \\Vert_{L^{\\infty}(0,T; \\mathbf{H}^1(\\Omega))} \\lesssim \\epsilon^{1/2} \\Vert u^0 \\Vert_{L^{\\infty}(0,T; \\mathbf{H}^3(\\Omega)}\n\\end{equation*}\n\n\n\\begin{rem}\nLet us note from the above bound that for each $t \\in (0,T)$ it can be deduced:\n\\begin{equation}\n    \\label{TimeBound}\n    \\Vert u^{\\epsilon} - u^0 - \\epsilon \\varphi \\mathbf{N}^s\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0 \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_N)} \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T;\\mathbf{L}^{2}(\\Gamma_N))}\n\\end{equation}\n\\end{rem}\n\n\\section{Energy Estimations}\nThe convergence results shown before contains information of the elastic operator behavior as $\\epsilon$ varies, thus the convergence of its energy operator. The results is inspired from the energy result of \\textit{Oleinik} \\cite{oleinik1992mathematical}, extending it to a time-dependent model.\n\nLet us define the energy operators $E_{\\epsilon}$ and $E_{0}$ associated to the multiscale and homogenized problems defined in the form:\n\\begin{equation*}\n    E_{\\epsilon}(u^{\\epsilon}) := \\int_0^T \\int_{\\Omega} \\frac{1}{2}u_i^{\\epsilon}u_i^{\\epsilon} + \\int_0^T \\int_{\\Omega} \\big( \\partial_{x_j} u^{\\epsilon}, A^{jk} \\big( \\frac{\\mathbf{x}}{\\epsilon}\\big) \\partial_{x_k} u^{\\epsilon} \\big)\n\\end{equation*}\nand analogously:\n\\begin{equation*}\n    E_0(u^0) := \\int_0^T \\int_{\\Omega} \\frac{1}{2}u_i^{0}u_i^{0} + \\int_0^T \\int_{\\Omega} \\big( \\partial_{x_j} u^0, A^{jk}_{hom} \\partial_{x_k} u^0 \\big)\n\\end{equation*}\nThus, the following can be obtained\n\\begin{lem}\nAssuming the hypothesis of the above theorem, we have the convergence of the energy operators, i.e., \n\\begin{equation*}\n    \\vert E_{\\epsilon} (u^{\\epsilon}) - E_0 (u^0) \\vert \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F} \\Vert_{L^{\\infty}(0,T; \\mathbf{L}^{2}(\\Gamma_N))} \n\\end{equation*}\n\\end{lem}\n\\begin{proof}\nLet us fix $t \\in (0,T)$, it follows from the result (\\ref{TimeBound}) the bounds for $u^{\\epsilon}$ and $\\partial_{x_i} u^{\\epsilon}$ in the form:\n\\begin{equation*}\n    u^{\\epsilon} = u^0 + \\epsilon \\mathbf{N}^s\\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0 + r^{\\epsilon}(\\mathbf{x},t) \n\\end{equation*}\nwhere the remaining term is bounded for\n\\begin{equation*}\n    \\Vert r^{\\epsilon}(\\cdot, t) \\Vert_{\\mathbf{H}^1(\\Omega; \\Gamma_D)} \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T;\\mathbf{L}^{2}(\\Gamma_N))}\n\\end{equation*}\nand for each $i \\in \\{1,2,3\\}$:\n\\begin{equation*}\n    \\partial_{x_i} u^{\\epsilon} = \\partial_{x_i} u^0 + \\epsilon \\partial_{y_i} \\mathbf{N}^s \\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0 + q^{\\epsilon}_i(\\mathbf{x},t)\n\\end{equation*}\nwhere now, the remaining term satisfies \n\\begin{equation*}\n    \\Vert q^{\\epsilon}_i(\\cdot, t) \\Vert_{\\mathbf{H}^1(\\Omega, \\Gamma_D)} \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T; \\mathbf{L}^{2}(\\Gamma_N))}\n\\end{equation*}\nSo, using the definition of the energy operator it follows that:\n\\begin{align*}\n    E_{\\epsilon}(u^{\\epsilon}) &= \\int_0^T \\int_{\\Omega} \\frac{1}{2}(u^0 + \\epsilon \\mathbf{N}^s \\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0, u^0 + \\epsilon \\mathbf{N}^s \\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} (u^0) \\big) + R(r^{\\epsilon}) \\\\\n    & + \\int_0^T \\int_{\\Omega} \\big( \\partial_{x_j} u^0 + \\epsilon \\partial_{x_j} \\mathbf{N}^s \\big( \\frac{\\mathbf{x}}{\\epsilon} \\big) \\partial_{x_s} u^0, A^{jk} \\big(\\frac{\\mathbf{x}}{\\epsilon} \\big) \\big[\\partial_{x_k} u^0 + \\epsilon \\partial_{x_k} \\mathbf{N}^s \\big( \\frac{\\mathbf{x}}{\\epsilon}\\big) \\partial_{x_s} u^0 \\big] \\big) + Q(q^{\\epsilon})\n\\end{align*}\nwhere the remaining integral terms can be bounded by\n\\begin{equation*}\n    \\vert R(r^{\\epsilon}) \\vert \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T;\\mathbf{L}^{2}(\\Gamma_N))} \n\\end{equation*}\nand moreover\n\\begin{equation*}\n    \\vert Q(q^{\\epsilon} \\vert \\lesssim \\epsilon^{1/2} \\Vert \\mathbf{F}\\Vert_{L^{\\infty}(0,T;\\mathbf{L}^{2}(\\Gamma_N))}\n\\end{equation*}\nsince the functions $u^0, \\partial_{x_k}u^0, \\mathbf{N}^s, \\partial_{x_k} \\mathbf{N}^s$ are bounded.\n\nLet us consider a base for the $d\\times d$ matrices $(m_{ij})_{ij}$, using the notation $m_s = (m_{s1}, \\dots, m_{sd})$. Thus, consider for each $s, t \\in \\{1,2,3\\}$ the matrices \n\\begin{equation*}\n    H^{st}(\\mathbf{y}) = \\partial_{y_i}\\big(\\mathbf{N}^s + y_s m_s\\big) A^{ij}(\\mathbf{y}) \\partial_{y_j} \\big(\\mathbf{N}^t +  y_t m_t\\big) - A^{st}_{hom}\n\\end{equation*}\nIt follows then by the homogenized coefficient definition that $\\langle H^{st} \\rangle_{\\mathbf{Y}} = \\mathbf{0}$.\nUsing the definition of $H^{st}$ over the multiscale energy expression, it can be deduced that\n\\begin{equation*}\n    E_{\\epsilon}(u^{\\epsilon}) - E_{0}(u^{0}) = \\int_0^T \\int_{\\Omega} \\frac{1}{2}(u^0, u^0) + \\partial_{x_s}u^0 H^{st}(\\frac{\\mathbf{x}}{\\epsilon}) \\partial_{t}u^0  + \\tilde{R}(r^{\\epsilon}) + Q(q^{\\epsilon})\n\\end{equation*}\nbeing $\\vert \\tilde{R}(r^{\\epsilon})\\vert \\lesssim \\epsilon^{1/2}\\Vert \\mathbf{F} \\Vert_{L^{\\infty}(0,T;\\mathbf{L}^2(\\Gamma_N))}$, obtained using the same technique as in \\textit{Theorem 1.3} \\cite{oleinik1992mathematical}.\n\\end{proof}\n\n\\section{Continuity on the Porosity}\nThe definition of homogenized coefficients contains an explicit dependency on the porosity level since it defines the characteristic microstructure. In this section, it will be studied the continuity of the homogenized coefficients with respect to the porosity level addressing the well-posedness of the inverse problem formulation. Moreover, differentiability is also assessed\\footnote{A similar study has been done for the multiscale \\textit{Calderón} problem by with high-oscillation conductivity coefficients, oriented to the inverse problem identification of homogenized coefficients \\textit{A. Abudlle and A. di Blasio} \\cite{Abdulle:221051}} by means of the cell problem definition. \n\nMore explicitly, it is given estimations for such effective coefficients with a continuity property under reasonable hypothesis on the porosity\\footnote{Such reasonable hypothesis are oriented in a continuity condition on the definition of the multiscale coefficients $C_{ijkl}(\\mathbf{y},p)$, for example of \\textit{Lipschitz} type on $p$.}. To this end, let us recall that our formulation for the elasticity coefficients at a cell point $\\mathbf{y}\\in \\mathbf{Y}$ is given by:\n\\begin{equation*}\n    C_{ijkl}(\\mathbf{y}, p) = C_{ijkl}^{m} \\mathbb{I}_{\\mathbf{y} \\in \\mathbf{Y}_m(p)} + C_{ijkl}^{f} \\mathbb{I}_{\\mathbf{y} \\in \\mathbf{Y}_f(p)}\n\\end{equation*}\nbeing $\\mathbf{Y}_m(p)$ and $\\mathbf{Y}_f(p)$ the matrix and fluid-like parts of the cell, where the explicit dependency on the porosity fraction $p \\in (0,1)$ implies \\textit{a posteriori} also the dependence of $p$ on the homogenized coefficient.\n\n\\subsection{Definition and Estimates}\nIn this section is defined the space in which the highly oscillatory coefficients $C_{ijkl}(\\cdot)$ belongs dependent on the porosity parameter.\n\\begin{defn}\nLet us define the set of operators on the feasible porosity interval $(0,1)$, associated to a cell-domain $\\mathbf{Y}$ by:\n\\begin{equation}\n    \\label{T-definition}\n    \\mathbf{T}((0,1) \\times \\mathbf{Y}) := \\big \\{ \\mathbf{C}(\\cdot, \\cdot) \\in L^{\\infty}((0,1); \\, \\text{lin}(\\textbf{Sym}^d))\\, : \\mathbf{C}(p, \\mathbf{y})^* = \\mathbf{C}(p, \\mathbf{y}) \\, \\forall \\mathbf{y} \\in \\mathbf{Y}\\big \\}\n\\end{equation}\nwhere it is used the notation of $lin(\\mathbf{Sym}^d)$ as the space of linear, continuous operators from the $d\\times d$ symmetric matrices space with $\\mathbf{L}^2(\\mathbf{Y})$ entries into itself, being $d=2,3$ and $*$ denoting the adjoint. \n\\end{defn}\n\\begin{rem}\nNote that, the linear elastic second-order tensors $\\mathbf{C} = (C_{ijkl})_{ijkl}$ belong to $\\mathbf{T}((0,1)\\times \\mathbf{Y})$. In particular, the symmetry of the tensors expressed in \\textit{Voigt} engineering notation described as $C_{IJ}=C_{JI}$ is given by the self-adjoint property, by identifying the set $lin(\\mathbf{Sym}^d)$ with the space of arrays indexed in the form $\\mathbf{C}(p, \\cdot) = (C_{ijkl} (p, \\cdot) )_{ijkl}$.\nOver such considerations, the set (\\ref{T-definition}) becomes:\n\\begin{equation*}\n    \\mathbf{T}((0,1)\\times \\mathbf{Y}) = \\big \\{ C_{ijkl}(\\cdot, \\mathbf{y}) \\in L^{\\infty}((0,1); \\mathbb{R})  \\,:\\, C_{ijkl}(\\mathbf{y}) = C_{ijlk}(\\mathbf{y}) = C_{klij}(\\mathbf{y}) \\in L^2(\\mathbf{Y})\\big \\}\n\\end{equation*}\nwhere it is assumed implicitly the dependency on $p$ of each coefficient.\n\\end{rem}\nWith the above it can be defined the space of bounded and coercive tensors associated to parameters $(\\alpha,\\beta) \\in \\mathbb{R}^2_+$ given as a subset of $\\mathbf{T}((0,1)\\times \\mathbf{Y})$ with conditions specified below.\nLet $(C_{ijkl})_{ijkl} \\in \\mathbf{T}((0,1)\\times \\mathbf{Y})$, consider $\\alpha, \\beta$ two positive parameters and define the following properties:\n\\begin{enumerate}\n    \\item[(H1)] If $\\xi \\in \\mathbf{R}^{d\\times d} \\setminus \\{\\mathbf{0}_{d \\times d}\\}$ then $\\alpha \\xi_{ij} \\, \\xi_{ij} \\leq C_{ijkl}(p,\\mathbf{y})  \\xi_{kl}\\,\\xi_{ij}\\, \\text{a.e.} \\mathbf{y} \\in \\mathbf{Y}$ for each $p \\in (0,1)$.\n    \\item[(H2)] If $\\xi \\in \\mathbf{R}^{d\\times d} \\setminus \\{\\mathbf{0}_{d \\times d}\\}$ then $C_{ijkl}(p,\\mathbf{y}) \\xi_{kl} \\xi_{ij} \\leq \\beta  \\xi_{ij} \\xi_{ij} \\, \\text{ a.e. }\\mathbf{y} \\in \\mathbf{Y}$ for each $p \\in (0,1)$.\n\\end{enumerate}\nThe above enables to consider the suitable space of linear elastic tensors, related to the generalized \\textit{Hookes} law.\n\\begin{defn}\nA tensor $\\mathbf{C} = (C_{ijkl})_{ijkl} \\in \\mathcal{T}(\\alpha, \\beta, (0,1)\\times \\mathbf{Y})$\nif $\\mathbf{C}$ is a feasible tensor, i.e., belongs to $\\mathbf{T}((0,1)\\times \\mathbf{Y})$ and satisfies the properties $(H1)-(H2)$.\n\\end{defn}\n\\begin{rem}\nIn the two-scale elastodynamic model formulation, the linear elastic tensor is expressed on the macroscopic (or slow) variable by\n\\begin{equation*}\n    \\mathbf{C}^{\\epsilon}(p,\\mathbf{x}) =\\mathbf{C}(p,\\frac{\\mathbf{x}}{\\epsilon})\n\\end{equation*} being $\\mathbf{x}\\in \\Omega$, in such a way that $\\mathbf{C} \\in \\mathcal{T}(\\alpha, \\beta, (0,1)\\times \\mathbf{Y})$. Recall also that, the $\\epsilon$ parameter indicates the relation of micro-to-macro scale (\\ref{TimeDif-Scheme}).\n\\end{rem}\nFollowing the two-scale homogenization procedure studied in the sections before, the homogenized problem governing the macroscopic mechanical behavior is of elastic type with effective coefficients defined at porosity $p \\in (0,1)$ by:\n\\begin{equation}\n    \\label{eq:homogenized-coeff}\n    C^{hom}_{ijrs}(p) = \\frac{1}{\\vert \\mathbf{Y}\\vert} \\int\\limits_{\\mathbf{Y}} C_{ijrs}(p,\\mathbf{y}) \\, dy + \\frac{1}{\\vert \\mathbf{Y}\\vert} \\int\\limits_{\\mathbf{Y}} C_{ijkl}(p,\\mathbf{y}) \\mathbf{e}_{kl,y}( N^{rs}(p))\\,dy\n\\end{equation}\nfor each $ i,j,r,s \\in \\{1,2,3\\}$, where the vector functions $(N^{rs})_{rs}$ are defined as the unique $\\mathbf{Y}$-periodic solution to the cell problems, satisfying for each $i \\in \\{1,2,3\\}$, the equality:\n\\begin{equation}\n    \\label{eq:cell}\n    -\\partial_{y_j} \\big[ C_{ijkl}(p,\\mathbf{y}) \\mathbf{e}_{kl}(N^{rs}(p,\\mathbf{y}) \\big] = \\partial_{y_j} \\big[ C_{ijrs}(p,\\mathbf{y}) \\big] \n\\end{equation}\nwith the normalization condition $\\langle N^{rs} \\rangle_{\\mathbf{Y}} = \\mathbf{0}$. Such a condition is necessary to obtain a well-posed elliptic problem on the space $\\mathbf{H}^1(\\mathbf{Y})$.\nExplicitly, vector solutions $N^{rs}(\\cdot,p)$ to the cell problem are found on   \n\\begin{equation*}\n    \\mathbf{H}^1_{ 0} (\\mathbf{Y}) := \\big \\{ N(p) \\in  \\mathbf{H}^1(\\mathbf{Y}) \\, : \\, \\langle N(p) \\rangle_{\\mathbf{Y}}=\\mathbf{0} \\, \\big \\}\n\\end{equation*}\n\n\\subsubsection{Variational Formulations}\nSolutions to problem (\\ref{eq:cell}) are found via variational formulation of such problem for each $r,s \\in \\{1,2,3\\}$. In all that follows, it is assumed a condition of radial symmetry on the coefficients\\footnote{Such kind of condition, which is naturally presented in periodic and compound media is assumed throughout this study, moreover the numerical results developed are obtained over a formulation of bone satisfying that property since the model is defined as compounds material with the inclusion being of different kind where the surrounding is a known fixed material. It is important to observe that under such assumptions the term associated to $\\partial \\mathbf{Y}$ vanishes obtaining the expression observed on (\\ref{eq:cell_variational}).} $C_{ijkl}(\\mathbf{y})$ which applied to (\\ref{eq:cell}) gives us the desired equivalent problem:\n\\begin{equation}\n    \\label{eq:cell_variational}\n    \\left \\{\n    \\begin{array}{cc}\n        \\text{Find a function } N^{rs} \\in \\mathbf{H}^1_{0}(\\mathbf{Y}) \\text{ such that } & \\quad \\\\\n        \\int\\limits_{\\mathbf{Y}} C_{ijkl}(p,\\mathbf{y})\\mathbf{e}_{kl,y} (N^{rs}) \\, \\partial_{y_j}(v_i)\\,d\\mathbf{y} = -\\int\\limits_{\\mathbf{Y}} C_{ijrs}(p, \\mathbf{y}) \\partial_{y_j}(v_i)\\,d\\mathbf{y} &  \\forall v \\in \\mathbf{H}^1_{0}(\\mathbf{Y}).\n    \\end{array}\n    \\right.\n\\end{equation}\nNote the variational formulation (\\ref{eq:cell_variational}) can be rewritten by the symmetry of the operator $\\mathbf{C}(\\cdot,p)$ in the form:\n\\begin{equation}\n    \\label{eq:cell_symmetric}\n    \\left \\{\n    \\begin{array}{cc}\n        \\text{Find a function } N^{rs}(p) \\in \\mathbf{H}^1_{0}(\\mathbf{Y}) \\text{ such that } & \\quad\\\\\n        \\int\\limits_{\\mathbf{Y}} C_{ijkl}(p,\\mathbf{y})\\mathbf{e}_{kl,y} (N^{rs})\\, \\mathbf{e}_{kl,y}(v)\\,d\\mathbf{y} = -\\int\\limits_{\\mathbf{Y}} C_{ijrs}(p,\\mathbf{y}) \\mathbf{e}_{ij,y}(v)\\,d\\mathbf{y} &\\forall v \\in \\mathbf{H}^1_{0}(\\mathbf{Y}).\n    \\end{array}\n    \\right.\n\\end{equation}\nLet us now define the following useful notation for the contraction of the last two indexes:\n\\begin{defn}\nLet us consider $\\mathbf{a} = (a_{ij})_{ij}$ and $\\mathbf{b} = (b_{ij})_{ij}$ elements in $\\mathcal{M}_{d\\times d}(\\mathbb{R})$, and consider $\\mathbf{A}=(A_{ijkl})_{ijkl}$ a element of $\\mathbf{T}([0,1]\\times \\mathbf{Y})$ identified with their multidimensional array. It is defined the contraction of the (last) two indices by\n\\begin{equation*}\n    \\mathbf{a}:\\mathbf{b} := a_{ij}b_{ij}\n\\end{equation*}\nand naturally extending the definition to three elements in the form:\n\\begin{equation*}\n    \\mathbf{A}:\\mathbf{a}:\\mathbf{b} := A_{ijkl}a_{kl}b_{ij}\n\\end{equation*}\n\\end{defn}\n\\begin{rem}\nIn particular, since $\\mathbf{A} \\in \\mathbf{T}((0,1)\\times \\mathbf{Y})$ then it can be deduced the symmetry conditions $A_{ijkl}=A_{klij}=A_{ijlk}$, which allows to obtain a conmutative property between $\\mathbf{a},\\mathbf{b}$ two matrices:\n\\begin{equation}\n    \\mathbf{A}: \\mathbf{a}:\\mathbf{b}= \\mathbf{A}:\\mathbf{b}:\\mathbf{a}\n\\end{equation}\n\\end{rem}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%5\n\n\\subsubsection{Symmetries}\nAs before, let us denote the base of $\\mathbf{Sym}^d$ by the set $(m_{ij})_{ij}$ for each $i,j \\in \\{1,\\dots d\\}$, i.e., the set of $d \\times d$ matrices with $1$ at the entry $(i,j)$ and $0$ otherwise. Observe that the homogenized coefficient (\\ref{eq:homogenized-coeff}) (where it is assumed w.l.o.g $\\vert \\mathbf{Y} \\vert = 1$) can be rewritten with the previously defined notation in the form:\n\\begin{equation}\n    \\label{eq:effective_coef}\n    \\begin{array}{ccc}\n        C_{ijrs}^{hom}(p) &=& \\int\\limits_{\\mathbf{Y}} \\mathbf{C}(\\mathbf{y},p):m_{rs}:m_{ij} + \\int\\limits_{\\mathbf{Y}} \\mathbf{C}(\\mathbf{y},p):\\mathbf{e}(N^{rs}):m_{ij} \\, d\\mathbf{y} \\\\\n         &=&\\int\\limits_{\\mathbf{Y}} \\mathbf{C}(\\mathbf{y},p):\\big(m_{rs} + \\mathbf{e}(N^{rs})\\big):m_{ij} \\, d\\mathbf{y}\n    \\end{array}\n\\end{equation}\n\nMoreover, expression (\\ref{eq:cell_symmetric}) can be rewritten in the form:\n\\begin{equation}\n    \\label{eq:cell_v}\n    \\int\\limits_{\\mathbf{y}}\\mathbf{C}(\\mathbf{y},p):\\mathbf{e}(v): \\mathbf{e}(N^{rs}) \\, d\\mathbf{y} = - \\int\\limits_{\\mathbf{y}} \\mathbf{C}(\\mathbf{y},p):\\mathbf{e}(v):m_{rs}\\, d\\mathbf{y} \\quad \\forall v \\in \\mathbf{H}^1_{0}(\\mathbf{Y}) \\, d\\mathbf{y}\n\\end{equation}\n\nSo, by using the above equality (\\ref{eq:cell_v}) with $v = N^{ij}$ in the expression (\\ref{eq:effective_coef}), it is obtained the homogenized coefficient in the form:\n\\begin{equation}\n    \\label{eq:effective_coef_symmetric}\n    C_{ijkl}^{hom}(p) = \\int\\limits_{\\mathbf{Y}} \\mathbf{C}(\\mathbf{y},p):(m_{rs}+\\mathbf{e}(N^{rs})):(m_{ij}+\\mathbf{e}(N^{ij})) \\, d\\mathbf{y}\n\\end{equation}\nIt follows then from (\\ref{eq:effective_coef_symmetric}) the full symmetric properties of the elements $C^{hom}_{ijkl}$, since by (\\ref{eq:cell_symmetric}) follows the that $N^{rs}(p,\\mathbf{y}) = N^{sr}(p, \\mathbf{y})$ thus taking into account the symmetry of $\\mathbf{C}(p)$ it can be deduced:\n\\begin{equation*}\n    C^{hom}_{ijkl} = C^{hom}_{klij} = C^{hom}_{ijlk} \\quad \\forall i,j,k,l \\in \\{1,2,3\\}\n\\end{equation*}\nwhich implies in particular the usage of engineering \\textit{Voigt} notation for the homogenized equations, obtaining a standard elasticity tensor.\n\nIn all that follows, it will be denoted by $M(\\mathbf{Y})$ the space of $d \\times d$ matrices $L^2(\\mathbf{Y})$ entries with norm $\\Vert \\cdot \\Vert_{M(\\mathbf{Y})}$ defined for $A = (A_{kl})_{kl} \\in M(\\mathbf{Y})$ by\n\\begin{equation}\n    \\Vert A \\Vert_{M(\\mathbf{Y})} = \\big(\\sum_{k,l=1}^d \\Vert A_{kl} \\Vert^2_{L^2(\\mathbf{Y})} \\big)^{1/2}\n\\end{equation}\nLet us recall the coercivity condition over $\\mathbf{C}(p, \\cdot)$, applying a duality argument over the space $M(\\mathbf{Y})$ it follows that:\n\\begin{equation}\n    \\label{eq:Estimate-Nrs}\n    \\Vert \\mathbf{e}(N^{rs}(p))\\Vert_{M(\\mathbf{Y})} \\leq \\frac{\\beta}{\\alpha}\n\\end{equation}\nwhich will be useful in the estimation in the following subsections. Observe with the above definition, the elastic tensors belong to $lin(M(\\mathbf{Y}))$.\n%%%%%%%%%%%%%%\n\\subsection{About the Continuity}\n\nTo study the continuity condition on the effective coefficients $C^{hom}_{ijkl}(\\cdot)$, let $p, q \\in (0,1)$ be two porosity levels. It will be first shown a useful estimation of $N^{rs}(p)-N^{rs}(q)$ for each $r,s \\in \\{1,2,3\\}$. \nUsing (\\ref{eq:cell_symmetric}) rewritten in tensor notation, the following equality can be obtained that relates the cell solutions to their coefficients associated to the porosity level in the form:\n\\begin{equation}\n    \\label{eq:diff_Nrs}\n    \\begin{aligned}\n        \\int\\limits_{\\mathbf{Y}} \\mathbf{C}(\\mathbf{y},p):\\mathbf{e}\\big( N^{rs}(p)-N^{rs}(q) \\big) : \\mathbf{e}(v) & =  -\\int\\limits_{\\mathbf{Y}} \\mathbf{C}(p)-\\mathbf{C}(q) : m_{rs}:\\mathbf{e}(v) \\\\\n        & \\quad - \\int\\limits_{\\mathbf{Y}}\\mathbf{C}(p)-\\mathbf{C}(q):\\mathbf{e}(N^{rs}(q)):\\mathbf{e}(v).\n    \\end{aligned}\n\\end{equation}\nSo that, using (\\ref{eq:diff_Nrs}) it follows the representation $\\forall v \\in \\mathbf{H}^1_{0}(\\mathbf{Y})$\n\\begin{equation}\n    \\label{eq:diff_Nrs_full}\n    \\int\\limits_{\\mathbf{Y}} \\mathbf{C}(p):\\mathbf{e}\\big(N^{rs}(p)-N^{rs}(q)\\big):\\mathbf{e}(v) = -\\int\\limits_{\\mathbf{Y}} \\mathbf{C}(p)-\\mathbf{C}(q):m_{rs}+\\mathbf{e}(N^{rs}(q)):\\mathbf{e}(v).\n\\end{equation}\nApplying then a duality argument on (\\ref{eq:diff_Nrs_full}) since $M(\\mathbf{Y})^* = M(\\mathbf{Y})$ it is deduced the first estimate for the difference between the cell solutions, expressed by:\n\\begin{equation*}\n    \\Vert \\mathbf{C}(p):\\mathbf{e}\\big(N^{rs}(p)-N^{rs}(q)\\big) \\Vert_{M(\\mathbf{Y})} \\leq \\Vert \\mathbf{C}(p)-\\mathbf{C}(q):m_{rs}+\\mathbf{e}(N^{rs}(q))\\Vert_{M(\\mathbf{Y})}\n\\end{equation*}\nfrom which after taking H\\\"{o}lder inequality and recalling the coercivity of $\\mathbf{C}(p)$ it is possible to obtain:\n\\begin{equation}\n    \\label{eq:ineq_diff_N}\n    \\Vert \\mathbf{e}\\big(N^{rs}(p)-N^{rs}(q)\\big) \\Vert_{M(\\mathbf{Y})} \\leq \\alpha^{-1}\\Vert \\mathbf{C}(p)-\\mathbf{C}(q) \\Vert_{lin (M(\\mathbf{Y}))} \\Vert m_{rs}+\\mathbf{e}(N^{rs}(q)) \\Vert_{M(\\mathbf{Y})}.\n\\end{equation}\n\nLet us then estimate the difference between the homogenized coefficients associated to the porosities $p, q$. By applying the definition and rearranging terms it follows:\n\\begin{equation*}\n    \\begin{aligned}\n        C^{hom}_{ijrs}(p) - C^{hom}_{ijrs}(q) = & \\int_{\\mathbf{Y}} \\mathbf{C}(p):m_{rs} + \\mathbf{e}(N^{rs}(p)):m_{ij} - \\int_{\\mathbf{Y}} \\mathbf{C}(q):m_{rs} + \\mathbf{e}(N^{rs}(q)):m_{ij}\\\\\n        = & \\int_{\\mathbf{Y}} \\mathbf{C}(p) - \\mathbf{C}(q):m_{rs} + \\mathbf{e}(N^{rs}(p)):m_{ij} \\\\\n        & + \\int_{\\mathbf{Y}} \\mathbf{C}(q):\\mathbf{e}(N^{rs}(p)) - \\mathbf{e}(N^{rs}(q)):m_{ij} \n    \\end{aligned}\n\\end{equation*}\nand by applying the H\\\"{o}lder inequality and using (\\ref{eq:ineq_diff_N}) it follows:\n\\begin{equation}\n    \\label{eq:diff-HomCoeffs}\n    \\begin{aligned}\n        \\vert C^{hom}_{ijrs}(p) - C^{hom}_{ijrs}(q)\\vert \\leq & \\, \\Vert \\mathbf{C}(p)-\\mathbf{C}(q) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert m_{rs}+e(N^{rs}(p)) \\Vert_{M(\\mathbf{Y})} \\\\\n         & +  \\frac{\\beta}{\\alpha} \\Vert \\mathbf{C}(p)-\\mathbf{C}(q) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert m_{rs}+\\mathbf{e}(N^{rs}(q)) \\Vert_{M(\\mathbf{Y})} \n    \\end{aligned}\n\\end{equation}\n\nFinally, applying the estimation (\\ref{eq:Estimate-Nrs}) over (\\ref{eq:diff-HomCoeffs}) it follows the continuity property for the coefficients:\n\\begin{equation}\n    \\label{ContinuityPropHom}\n    \\vert C^{hom}_{ijrs}(p) - C^{hom}_{ijrs}(q)\\vert \\leq \\Vert \\mathbf{C}(p) - \\mathbf{C}(q) \\Vert_{lin(M(\\mathbf{Y}))} (1+\\frac{\\beta}{\\alpha})\\frac{\\beta}{\\alpha}\n\\end{equation}\n\n\\subsection{About the Derivative}\nOur interest now is to obtain some estimates for the derivatives with respect to the porosity $p$. By using the expression (\\ref{eq:effective_coef_symmetric}) for fixed $i,j,r,s \\in \\{1,2,3\\}$ and $\\overline{p} \\in (0,1)$ it can be deduced:\n\\begin{equation}\n    \\label{eq:DerivHomCoeff}\n    \\partial_{p}  C_{ijkl}^{hom} (\\overline{p}) = \\int\\limits_{\\mathbf{Y}} \\partial_{p}\\big( \\mathbf{C}(\\mathbf{y},\\overline{p}) \\big)\\, : \\,m_{rs}+\\mathbf{e}(N^{rs}(\\overline{p}))\\, :\\,m_{ij}+\\mathbf{e}(N^{ij}(\\overline{p})) \\, d\\mathbf{y} \n\\end{equation}\nwhich results by distributing each term, rules of differentiation and (\\ref{eq:cell_v}).\n\nIt follows then from (\\ref{eq:DerivHomCoeff}) after applying holder inequality that:\n\\begin{equation*}\n    \\vert \\partial_p C^{hom}_{ijrs}(\\overline{p}) \\vert \\leq \\Vert \\mathbf{C}(\\overline{p}) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert m_{rs} + \\mathbf{e}(N^{rs}(\\overline{p})) \\Vert_{M(\\mathbf{Y})} \\Vert m_{ij} + \\mathbf{e}(N^{ij}(\\overline{p})) \\Vert_{M(\\mathbf{Y})}\n\\end{equation*}\n\nwhich after applying the estimate (\\ref{eq:Estimate-Nrs}) the following inequality for the derivative can be deduced:\n\\begin{equation}\n    \\label{EstimateDerivHomCoeff}\n    \\vert \\partial_p C^{hom}_{ijrs}(p) \\vert \\leq (1+\\frac{\\beta}{\\alpha})^2 \\Vert \\partial_p \\mathbf{C}\\Vert_{L^{\\infty}((0,1); lin(M(\\mathbf{Y}))}\n\\end{equation}\n\nThe above estimates enable us to obtain a bound for the difference of the homogenized elastic tensors.\n\nNow, let $\\overline{p}, \\overline{q}$ be two porosity level on $(0,1)$.\nApplying the equality (\\ref{eq:DerivHomCoeff}), rearranging terms and using directly H\\\"{o}lder inequality, it follows:\n\\begin{align*}\n    \\vert \\partial_p C_{ijrs}(\\overline{p}) - & \\partial_p C_{ijrs}(\\overline{q}) \\vert \\leq  \\quad \\\\\n    &\\quad \\Vert \\partial_p \\mathbf{C}(\\overline{p}) - \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert m_{rs} + \\mathbf{e}(N^{rs}(\\overline{p})) \\Vert_{M(\\mathbf{Y})} \\Vert m_{ji} + \\mathbf{e}(N^{ij}(\\overline{p}))\\Vert_{M(\\mathbf{Y})} \\\\\n    & + \\Vert \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert \\mathbf{e}(N^{rs}(\\overline{p})) -\\mathbf{e}(N^{rs}(\\overline{q})) \\Vert_{M(\\mathbf{Y})} \\Vert m_{ij} + \\mathbf{e}(N^{ij}(\\overline{q}) \\Vert_{M(\\mathbf{Y})}  \\\\\n    & + \\Vert \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert m_{rs} + \\mathbf{e}(N^{rs}(\\overline{p})) \\Vert_{M(\\mathbf{Y})} \\Vert \\mathbf{e}(N^{ij}(\\overline{p})) - \\mathbf{e}(N^{ij}(\\overline{q})) \\Vert_{M(\\mathbf{Y})}\n\\end{align*}\nFrom which can be deduced taking into consideration the bounds for the cell solutions (\\ref{eq:Estimate-Nrs}), (\\ref{eq:ineq_diff_N}) that:\n\\begin{equation}\n    \\label{EstimateDiffDeriv}\n    \\begin{aligned}\n        \\vert \\partial_p C_{ijrs}(\\overline{p}) - \\partial_p C_{ijrs}(\\overline{q}) \\vert & \\,  \\leq (1+ \\frac{\\beta}{\\alpha})^2\\Vert \\partial_p \\mathbf{C}(\\overline{p}) - \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\\\\n        & + 2\\frac{\\beta}{\\alpha}(1+\\frac{\\beta}{\\alpha})^2 \\Vert \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\Vert \\mathbf{C}(\\overline{p}) - \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))}\n    \\end{aligned}\n\\end{equation}\n\nAs conclusion, it is obtained the following properties:\n\\begin{prop}\nUnder the assumptions of regularity for the multiscale elastic coefficients $\\mathbf{C} = (C_{ijkl})_{ijkl} \\in \\mathcal{T}(\\alpha, \\beta, (0,1)\\times \\mathbf{Y})$ of type:\n\\begin{enumerate}\n    \\item[HI] A Lipschitz continuity assumption for the elastic coefficients in the form:\n    \\begin{equation*}\n        \\Vert \\mathbf{C}(\\overline{p}) - \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\leq L \\vert \\overline{p} - \\overline{q} \\vert^{l} \n    \\end{equation*}\n    for some $L, l > 0$ positive constants, and each $\\overline{p},\\overline{q} \\in (0,1)$.\n\\end{enumerate}\nThen it follows for each $i,j,r,s \\in \\{1,2,3\\}$ and $\\overline{p},\\overline{q}$ porosity levels:\n\\begin{enumerate}\n    \\item[PI] A continuity property for the homogenized coefficients:\n    \\begin{equation*}\n        \\vert C_{ijrs}^{hom}(\\overline{p})-C^{hom}_{ijrs}(\\overline{q}) \\vert \\leq L \\vert \\overline{p} - \\overline{q} \\vert^{l} \\frac{\\beta}{\\alpha} (1+\\frac{\\beta}{\\alpha})\n    \\end{equation*}\n\\end{enumerate}\n\nMoreover, if it is satisfied:\n\\begin{enumerate}\n    \\item[HII] Uniformly boundness over the porosity range for the derivative, i.e., $\\Vert \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} < \\infty$ for each $\\overline{q} \\in (0,1)$.\n    \\item[HIII] Lipschitz continuity condition for the derivative, in the form:\n    \\begin{equation*}\n        \\Vert \\partial_p \\mathbf{C}(\\overline{p})- \\partial_p \\mathbf{C}(\\overline{q}) \\Vert_{lin(M(\\mathbf{Y}))} \\leq \\overline{L} \\vert \\overline{p}-\\overline{q}\\vert^{\\overline{l}}\n    \\end{equation*}\n    for $\\overline{L}, \\overline{l} > 0$ constants and each $\\overline{p},\\overline{q} \\in (0,1)$.\n\\end{enumerate}\nThen it follows that each $i,j,r,s \\in \\{1,2,3\\}$ and $\\overline{p},\\overline{q}$ porosity levels:\n\\begin{enumerate}\n    \\item[PII] A continuity property for the derivatives of hom. coeffients:\n    \\begin{equation*}\n        \\vert \\partial_p C_{ijrs}^{hom}(\\overline{p})-\\partial_p C_{ijrs}(\\overline{q}) \\vert \\leq C(\\alpha, \\beta) \\vert \\overline{p}-\\overline{q} \\vert^{\\overline{l}} + \\tilde{C}(\\alpha, \\beta) \\vert \\overline{p}-\\overline{q} \\vert^{l}\n    \\end{equation*}\n    being $C(\\alpha,\\beta), \\tilde{C}(\\alpha,\\beta) > 0$ constants.\n\\end{enumerate}\n\\end{prop}", "meta": {"hexsha": "e0b6a7da3487e2fda22bac29792f34c5ce16e99a", "size": 80446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homogenization.tex", "max_stars_repo_name": "Reidmen/Master-Thesis-2018", "max_stars_repo_head_hexsha": "4cefa410208dfced927616ba8e2b62c4b6557281", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "homogenization.tex", "max_issues_repo_name": "Reidmen/Master-Thesis-2018", "max_issues_repo_head_hexsha": "4cefa410208dfced927616ba8e2b62c4b6557281", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homogenization.tex", "max_forks_repo_name": "Reidmen/Master-Thesis-2018", "max_forks_repo_head_hexsha": "4cefa410208dfced927616ba8e2b62c4b6557281", "max_forks_repo_licenses": ["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.542340628, "max_line_length": 853, "alphanum_fraction": 0.6584914104, "num_tokens": 28683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6199244650799969}}
{"text": "\\documentclass[a4paper,twoside,12pt,hidelinks]{article}\n\n% Packages\n% ---------------------\n\n\\usepackage{amsmath} % Needed for command eqref\n\\usepackage{amsthm} % Used to show the proof box\n\\usepackage{fancyhdr} % Head and foot options\n\\usepackage{hyperref} % Uses automatic references \\autoref\n\\usepackage[T1]{fontenc}\n\\usepackage{libertine}\n\\usepackage[libertine]{newtxmath} % Font\n\n% Page settings\n% ---------------------\n\n\\usepackage[top=2cm, bottom=2.5cm,left=2.5cm,right=2.5cm]{geometry} %  Page margins\n\\setlength{\\parskip}{\\baselineskip} % Add space between paragraphs\n\\setlength{\\intextsep}{20pt plus 2.0pt minus 2.0pt} % Add vertical space before and after tables and figures (http://tex.stackexchange.com/a/26522/101976)\n\\parindent=0cm % Remove the paragraph indent of the first line\n\\addtolength{\\jot}{2\\jot} % Double the line between equations\n\\raggedbottom % Prevents spreading the page content vetically for non-full pages.\n\n% Set vertical space around equations.\n\\AtBeginDocument{%\n \\abovedisplayskip=15pt plus 5pt minus 5pt\n \\abovedisplayshortskip=12pt plus 3pt\n \\belowdisplayskip=15pt plus 5pt minus 5pt\n \\belowdisplayshortskip=12pt plus 3pt minus 4pt\n}\n\n\n\\begin{document}\n\n\\thispagestyle{empty}\n\n\\section*{Derivation of equation of motion for the angle $\\theta$}\n\nThe derivation is used in the article \\href{https://evgenii.com/blog/earth-orbit-simulation/}{https://evgenii.com/blog/earth-orbit-simulation}.\n\nWe have the Lagrangian\n\\begin{equation*}\n  L = \\frac{m}{2} (\\dot{r}^2 + r^2 \\dot{\\theta}^2) + \\frac{G M m}{r}.\n\\end{equation*}\nWe need to calculate\n\\begin{equation}\n  \\frac{d}{dt} \\Big( \\frac{\\partial L}{\\partial \\dot{\\theta}} \\Big) = \\frac{\\partial L}{\\partial \\theta}.\n  \\label{eq_main_deribative}\n\\end{equation}\nSince $L$ does not depend on $\\theta$,\n\\[\n  \\frac{\\partial L}{\\partial \\theta} = 0.\n\\]\nFurthermore,\n\\begin{align*}\n   \\frac{\\partial L}{\\partial \\dot{\\theta}} &= \\frac{\\partial }{\\partial \\dot{\\theta}} \\Big( \\frac{m}{2} r^2 \\dot{\\theta}^2 \\Big) \\\\\n    &= \\frac{m}{2} r^2 (2) \\dot{\\theta} = m r^2 \\dot{\\theta}.\n\\end{align*}\nNext, we take the time derivative:\n\\begin{align*}\n   \\frac{d}{dt} \\Big( \\frac{\\partial L}{\\partial \\dot{\\theta}} \\Big) &= \\frac{d}{dt} \\Big( m r^2 \\dot{\\theta} \\Big) \\\\\n    &= m \\frac{d}{dt} \\Big( r^2 \\dot{\\theta} \\Big) \\\\\n    &= m (2 r \\dot{r} \\dot{\\theta} + r^2 \\ddot{\\theta}). \\tag{Product rule}\n\\end{align*}\nSubstituting into \\autoref{eq_main_deribative} gives\n\\[\n  m ( 2 r \\dot{r} \\dot{\\theta} + r^2 \\ddot{\\theta} ) = 0.\n\\]\nSimplify:\n\\[\n  2 \\dot{r} \\dot{\\theta} + r \\ddot{\\theta} = 0.\n\\]\nFinally, we solve for $\\ddot{\\theta}$:\n\\[\n  \\ddot{\\theta} = - \\frac{2 \\dot{r} \\dot{\\theta}}{r}.\n\\]\n\n\n\\end{document}", "meta": {"hexsha": "c4e597e204c6d7c1f44c582ae64b23fe8401f956", "size": 2674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/2016/09/earth_orbit_simulation/earth_orbit_derivation_theta_dot.tex", "max_stars_repo_name": "evgenyneu/evgenii.com", "max_stars_repo_head_hexsha": "76566e4d59965117acdb9dacee0c4756c4dd0d2c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-05-02T13:23:36.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-15T18:28:32.000Z", "max_issues_repo_path": "files/2016/09/earth_orbit_simulation/earth_orbit_derivation_theta_dot.tex", "max_issues_repo_name": "evgenyneu/evgenii.com", "max_issues_repo_head_hexsha": "76566e4d59965117acdb9dacee0c4756c4dd0d2c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-24T07:05:50.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-24T07:20:58.000Z", "max_forks_repo_path": "files/2016/09/earth_orbit_simulation/earth_orbit_derivation_theta_dot.tex", "max_forks_repo_name": "evgenyneu/evgenii.com", "max_forks_repo_head_hexsha": "76566e4d59965117acdb9dacee0c4756c4dd0d2c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-02T13:29:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-22T07:20:26.000Z", "avg_line_length": 33.8481012658, "max_line_length": 154, "alphanum_fraction": 0.6753926702, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.6199244650799968}}
{"text": "\\BoSSSopen{tutorial10-PoissonSystem/Poisson}\n\\graphicspath{{tutorial10-PoissonSystem/Poisson.texbatch/}}\n\n\\BoSSScmd{\n/// \\section*{What's new?}\n/// \\label{sec:poissonSystem_new}\n/// \\begin{itemize}\n///     \\item {implementation of a saddle point problem into \\BoSSS{} \n///           (e.g. the Poisson equation as a system)}\n///     \\item {central-difference-form and strong form}\n///     \\item {comparison of both formulations}\n///     \\item advanced: {algebraic reduction of the poisson problem}\n/// \\end{itemize}\n/// %==========================================\n/// \\section*{Prerequisites}\n/// %==========================================\n/// \\begin{itemize}\n///    \\item {implementation of numerical fluxes, chapter \\ref{NumFlux}} \n///    \\item {spatial operator, chapter \\ref{SpatialOperator}} \n/// \\end{itemize}\n/// %==========================================\n/// \\section{Problem statement}\n/// %==========================================\n/// Within this exercise, we are going to investigate \n/// the discretization of a Poisson equation as a system.\n/// Obviously, it is possible to discretize the Poisson equation as a system of\n/// first-order-PDE's, introducing a vector field $\\vec{\\sigma}$:\n/// \\begin{alignat}{3}\n///  \\vec{\\sigma}  + \\nabla u & = 0, & & \\text{ in } \\domain\n///    \\label{eq:PoissonSys1} \\\\\n///  \\operatorname{div}(\\vec{\\sigma}) &  = g_{\\domain}, & & \\text{ in } \\domain\n///    \\label{eq:PoissonSys2} \\\\\n///   u                                               & = g_D, & & \\text{ on } \\Gamma_D \\\\\n///   - \\vec{\\sigma} \\cdot \\vec{n}_{\\partial \\domain} & = g_N, & & \\text{ on } \\Gamma_N\n/// \\end{alignat}\n/// resp. in matrix-notation:\n/// \\begin{align*}\n///   \\begin{bmatrix}\n///     \\one & \\nabla \\\\\n///     \\operatorname{div} & 0 \\\\\n///   \\end{bmatrix}\\cdot\n///   \\begin{bmatrix}\n///     \\vec{\\sigma}\\\\\n///     u\n///   \\end{bmatrix}=\n///   \\begin{bmatrix}\n///     0 \\\\\n///     g_{\\domain}\n///   \\end{bmatrix}\n/// \\end{align*}\n/// This exercise, together with the previous one,\n/// will form the foundation for an incompressible Stokes- resp. Navier-Stokes solver.    \n/// \\section{Solution within the BoSSS framework}\n }\n\\BoSSSexeSilent\n%\n\\BoSSScmd{\nrestart\n }\n\\BoSSSexeSilent\n%\n\\BoSSScmd{\nusing ilPSP.LinSolvers; \\newline \nusing BoSSS.Solution.Tecplot; \\newline \nusing ilPSP.Connectors.Matlab;\n }\n\\BoSSSexe\n%\n\\BoSSScmd{\n % \n }\n\\BoSSSexe\n\\BoSSScmd{\n/// % ===================================\n/// \\subsection{Tests on the divergence}\n/// % ===================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Common base-class for $\\text{div}$-implementations}\n/// We are going to implement two different formulations of the \n/// divergence-operator for which going to show equivalence. \n/// We implement a common base-class for both formulations:\nabstract public class BaseDivergence :  \\newline \n\\btab \\btab BoSSS.Foundation.IEdgeForm, // edge integrals \\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm     // volume integrals \\newline \n\\{ \\newline \n    /// We don't use parameters (e.g. variable viscosity, ...)\n    /// at this point: so the parameter list can be null, resp. empty:\n\\btab public IList<string> ParameterOrdering \\{  \\newline \n\\btab \\btab get \\{ return null; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n    /// But we have a vector argument variable, \n    /// $ [ \\sigma_1, \\sigma_2 ] = \\vec{\\sigma} $\n    /// (our trial function):\n\\btab public IList<String> ArgumentOrdering \\{  \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"sigma1\", \"sigma2\" \\}; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags VolTerms \\{ \\newline \n\\btab \\btab get \\{ \\newline \n\\btab \\btab \\btab return TermActivationFlags.AllOn; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags InnerEdgeTerms \\{ \\newline \n\\btab \\btab get \\{ \\newline \n\\btab \\btab \\btab return (TermActivationFlags.AllOn);  \\newline \n\\btab \\btab \\} \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{ \\newline \n\\btab    get \\{ \\newline \n\\btab \\btab    return TermActivationFlags.AllOn; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\} \\newline \n \\newline \n    /// The following functions cover the actual math.\n    /// For any discretization of the divergence-operator, we have to specify:\n    /// \\begin{itemize}\n    ///    \\item a volume integrand,\n    ///    \\item an edge integrand for inner edges, i.e. on $ \\Gamma_i$,\n    ///    \\item an edge integrand for boundary edges, \n    ///          i.e. on $\\partial \\Omega$.\n    /// \\end{itemize}\n    /// These functions are declared as \\code{abstract}, meaning that one has \n    /// to specify them in classes derived from \\code{BaseLaplace}.\n \\newline \n\\btab abstract public double VolumeForm(ref CommonParamsVol cpv,  \\newline \n\\btab \\btab    double[] U, double[,] GradU,  \\newline \n\\btab \\btab    double V, double[] GradV);         \\newline \n \\newline \n\\btab abstract public double InnerEdgeForm(ref CommonParams inp,  \\newline \n\\btab \\btab double[] U\\_IN, double[] U\\_OT, double[,] GradU\\_IN, double[,] GradU\\_OT,  \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT); \\newline \n \\newline \n\\btab abstract public double BoundaryEdgeForm(ref CommonParamsBnd inp,  \\newline \n\\btab \\btab double[] U\\_IN, double[,] GradU\\_IN, double V\\_IN, double[] GradV\\_OT); \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We are going to use both, Dirichlet- and Neumann-boundary conditions\n/// in this exercise; the function \\code{IsDirichletBndy} is used to\n/// specify the type of boundary condition at point \\code{X}:\nFunc<double[],bool> IsDirichletBndy = delegate(double[] X) \\{ \\newline \n\\btab double x = X[0]; \\newline \n\\btab double y = X[1]; \\newline \n\\btab if(Math.Abs(x - (-1.0)) < 1.0e-8) \\newline \n\\btab \\btab return true;     \\newline \n\\btab if(Math.Abs(y - (-1.0)) < 1.0e-8) \\newline \n\\btab \\btab return true;     \\newline \n\\btab return false; \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Formulation (i): Central-difference-form of $\\text{div}$}\n/// The implementation of the central-difference form is as follows:\n }\n\\BoSSSexe\n\\BoSSScmd{\nclass Divergence\\_cendiff : BaseDivergence \\{ \\newline \n \\newline \n \\newline \n    /// The volume form is equal to \n    /// $ -\\vec{\\sigma} \\cdot \\nabla v$:\n\\btab override public double VolumeForm(ref CommonParamsVol cpv,  \\newline \n\\btab \\btab double[] Sigma, double[,] GradSigma,  \\newline \n\\btab \\btab double V, double[] GradV) \\{ \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab for(int d = 0; d < cpv.D; d++) \\{ \\newline \n\\btab \\btab \\btab Acc -= Sigma[d]*GradV[d]; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n \\newline \n    /// At the cell boundaries, we use a central-difference-flux,\n    /// i.e. $\\mean{\\vec{\\sigma}} \\cdot \\vec{n}_{\\Gamma} \\jump{v}$:\n\\btab override public double InnerEdgeForm(ref CommonParams inp,  \\newline \n\\btab \\btab double[] Sigma\\_IN, double[] Sigma\\_OT, double[,] GradSigma\\_IN, double[,] GradSigma\\_OT,  \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{ \\newline \n\\btab \\btab \\btab Acc += 0.5*(Sigma\\_IN[d] + Sigma\\_OT[d])*inp.Normale[d]*(V\\_IN - V\\_OT); \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n \\newline \n\\btab override public double BoundaryEdgeForm(ref CommonParamsBnd inp,  \\newline \n\\btab \\btab double[] Sigma\\_IN, double[,] GradSigma\\_IN, double V\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n \\newline \n\\btab \\btab if(IsDirichletBndy(inp.X)) \\{ \\newline \n            /// Dirichlet-boundary: by taking the inner value of $\\vec{\\sigma}$, \n            /// this is a free boundary with respect to $\\vec{\\sigma}$.\n\\btab \\btab \\btab for(int d = 0; d < inp.D; d++) \\{ \\newline \n\\btab \\btab \\btab \\btab Acc += Sigma\\_IN[d]*inp.Normale[d]*V\\_IN; \\newline \n\\btab \\btab \\btab \\} \\newline \n\\btab \\btab \\} else \\{ \\newline \n            /// Neumann-boundary\n\\btab \\btab \\btab double gNeu = 0.0; \\newline \n\\btab \\btab \\btab Acc += gNeu*V\\_IN; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Formulation (ii): 'Strong' form of $\\text{div}$:}\n/// Here, we use the form \n/// \\[\n///    b(\\vec{\\sigma},v) = \n///    \\oint_{\\Gamma \\backslash \\Gamma_D} \n///           \\mean{v} \\jump{\\vec{\\sigma}} \\cdot \\vec{n}_\\Gamma \n///    \\dA \n///    -\n///    \\int_{\\domain} \\operatorname{div}(\\vec{\\sigma}) \\cdot v \\dV\n/// \\]\n/// This is actually the negative divergence, which will be more useful\n/// later on.\nclass Divergence\\_strong : BaseDivergence \\{ \\newline \n \\newline \n    /// We have to implement \\code{VolumeForm},\n    /// \\emph{InnerEdgeForm} and \\code{BoundaryEdgeForm}:\n\\btab override public double VolumeForm(ref CommonParamsVol cpv,  \\newline \n\\btab \\btab double[] Sigma, double[,] GradSigma,  \\newline \n\\btab \\btab double V, double[] GradV) \\{ \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab for(int d = 0; d < cpv.D; d++) \\{ \\newline \n\\btab \\btab \\btab Acc -= GradSigma[d,d]*V; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n \\newline \n\\btab override public double InnerEdgeForm(ref CommonParams inp,  \\newline \n\\btab \\btab double[] Sigma\\_IN, double[] Sigma\\_OT, double[,] GradSigma\\_IN, double[,] GradSigma\\_OT,  \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{ \\newline \n\\btab \\btab \\btab Acc += 0.5*(V\\_IN + V\\_OT)*(Sigma\\_IN[d] - Sigma\\_OT[d])*inp.Normale[d]; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n \\newline \n\\btab override public double BoundaryEdgeForm(ref CommonParamsBnd inp,  \\newline \n\\btab \\btab double[] Sigma\\_IN, double[,] GradSigma\\_IN, double V\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n \\newline \n\\btab \\btab if(IsDirichletBndy(inp.X)) \\{ \\newline \n\\btab \\btab \\btab Acc = 0;\\newline \n\\btab \\btab \\} else \\{ \\newline \n\\btab \\btab \\btab double gNeu = 0.0; \\newline \n\\btab \\btab \\btab for(int d = 0; d < inp.D; d++) \\{ \\newline \n\\btab \\btab \\btab \\btab Acc += Sigma\\_IN[d]*inp.Normale[d]*V\\_IN; \\newline \n\\btab \\btab \\btab \\} \\newline \n\\btab \\btab \\btab Acc -= gNeu*V\\_IN; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\} \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n    /// %==========================================\n    /// \\subsection{Equality test}\n    /// %==========================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n    /// We are going to test the equivalence of both formulations\n    /// on a 2D grid, using a DG basis of degree 1:\n var grd2D               = Grid2D.Cartesian2DGrid(GenericBlas.Linspace(-1,1,6),                                                    GenericBlas.Linspace(-1,1,7)); \\newline \n var gdata2D             = new GridData(grd2D); \\newline \n var b                   = new Basis(gdata2D, 1); \\newline \n SinglePhaseField sigma1 = new SinglePhaseField(b,\"sigma1\"); \\newline \n SinglePhaseField sigma2 = new SinglePhaseField(b,\"sigma2\"); \\newline \n CoordinateVector sigma  = new CoordinateVector(sigma1,sigma2); \\newline \n var TrialMapping        = sigma.Mapping; \\newline \n var TestMapping         = new UnsetteledCoordinateMapping(b);\n }\n\\BoSSSexe\n\\BoSSScmd{\n    /// We create the matrix of the central-difference formulation:\n var OpDiv\\_cendiff = (new Divergence\\_cendiff()).Operator(); \\newline \n var MtxDiv\\_cendiff = OpDiv\\_cendiff.ComputeMatrix(TrialMapping,  \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   null,  \\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   TestMapping);\n }\n\\BoSSSexe\n\\BoSSScmd{\n    /// We create the matrix of the strong formulation \n    /// and show that the matrices of both formulations are equal.\n    /// We use the \\code{InfNorm(...)}-method to identify whether a \n    /// matrix is (approximately) zero or not.\n var OpDiv\\_strong  = (new Divergence\\_strong()).Operator(); \\newline \n var MtxDiv\\_strong = OpDiv\\_strong.ComputeMatrix(TrialMapping, null, TestMapping); \\newline \n var TestP         = MtxDiv\\_cendiff + MtxDiv\\_strong; \\newline \n TestP.InfNorm();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %==================================\n/// \\subsection{The gradient-operator}\n/// \\label{subsec:poissonSystem_gradientOp}\n/// %==================================\n/// For the variational formulation of the gradient operator, a vector-valued\n/// test-function is required. Unfourtunately, this is not supported by \n/// \\BoSSS. Therefore we have to discretize the gradent component-wise,\n/// i.e. as $\\partial_{x}$ and $\\partial_y$. A single derivative \n/// can obviously be expressed as a divergence by the\n/// identity $ \\partial_{x_d} = \\text{div}( \\vec{e}_d u ) $.\nclass Gradient\\_d : \\newline \n\\btab \\btab BoSSS.Foundation.IEdgeForm, // edge integrals \\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm     // volume integrals \\newline \n\\{ \\newline \n\\btab public Gradient\\_d(int \\_d) \\{ \\newline \n\\btab \\btab this.d = \\_d; \\newline \n\\btab \\} \\newline \n \\newline \n    /// The component index of the gradient:\n\\btab int d; \\newline \n \\newline \n    /// As ususal, we do not use parameters:\n\\btab public IList<string> ParameterOrdering \\{  \\newline \n\\btab \\btab get \\{ return null; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n    /// We have one argument $u$:\n\\btab public IList<String> ArgumentOrdering \\{  \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"u\" \\}; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags VolTerms \\{ \\newline \n\\btab \\btab get \\{ return TermActivationFlags.AllOn; \\} \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags InnerEdgeTerms \\{ \\newline \n\\btab \\btab get \\{ return (TermActivationFlags.AllOn); \\} \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{ \\newline \n\\btab    get \\{ return TermActivationFlags.AllOn; \\} \\newline \n\\btab \\} \\newline \n \\newline \n    /// Now, we implement \n    /// \\begin{itemize}\n    ///    \\item the volume form $u \\vec{e}_d \\cdot \\nabla v$\n    ///    \\item the boundary form \n    ///       $\\mean{u \\ \\vec{e}_d} \\cdot \\vec{n}_\\Gamma \\jump{v}$\n    /// \\end{itemize}\n\\btab public double VolumeForm(ref CommonParamsVol cpv,  \\newline \n\\btab \\btab    double[] U, double[,] GradU,  \\newline \n\\btab \\btab    double V, double[] GradV) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab Acc -= U[0]*GradV[this.d]; \\newline \n\\btab \\btab return Acc; \\newline \n\\btab \\}         \\newline \n \\newline \n\\btab public double InnerEdgeForm(ref CommonParams inp,  \\newline \n\\btab \\btab double[] U\\_IN, double[] U\\_OT, double[,] GradU\\_IN, double[,] GradU\\_OT,  \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab Acc += 0.5*(U\\_IN[0] + U\\_OT[0])*inp.Normale[this.d]*(V\\_IN - V\\_OT); \\newline \n\\btab \\btab return Acc;   \\newline \n\\btab  \\} \\newline \n \\newline \n\\btab public double BoundaryEdgeForm(ref CommonParamsBnd inp,  \\newline \n\\btab \\btab double[] U\\_IN, double[,] GradU\\_IN, double V\\_IN, double[] GradV\\_OT) \\{ \\newline \n \\newline \n\\btab \\btab double Acc = 0; \\newline \n\\btab \\btab if(IsDirichletBndy(inp.X)) \\{ \\newline \n\\btab \\btab \\btab double u\\_Diri = 0.0; \\newline \n\\btab \\btab \\btab Acc += u\\_Diri*inp.Normale[this.d]*V\\_IN; \\newline \n\\btab \\btab \\} else \\{ \\newline \n\\btab \\btab \\btab Acc += U\\_IN[0]*inp.Normale[this.d]*V\\_IN; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\btab return Acc;               \\newline \n\\btab \\} \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, we are ready to assemble the full $\\nabla$ operator\n/// as $\\left[ \\begin{array}{c} \\partial_x \\\\ \\partial_y \\end{array} \\right]$.\nvar OpGrad = new SpatialOperator(1,2,QuadOrderFunc.Linear(),\"u\",\"c1\",\"c2\"); \\newline \nOpGrad.EquationComponents[\"c1\"].Add(new Gradient\\_d(0)); \\newline \nOpGrad.EquationComponents[\"c2\"].Add(new Gradient\\_d(1)); \\newline \nOpGrad.Commit();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// As an additional test, we create the gradient-matrix and verify that \n/// its transpose \n/// is equal to the negative \\code{MtxDiv}-matrix:\nvar MtxGrad = OpGrad.ComputeMatrix(TestMapping, null, TrialMapping); \\newline \nvar Test2   = MtxGrad.Transpose() - MtxDiv\\_strong; \\newline \nTest2.InfNorm();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %====================================\n/// \\subsection{The complete Poisson-system}\n/// %====================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n///\\paragraph{Assembly of the system}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We also need the identity-matrix in the top-left corner \n/// of the Poisson-system:\npublic class Identity :  \\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm  \\newline \n\\{ \\newline \n\\btab public IList<string> ParameterOrdering \\{  \\newline \n\\btab \\btab get \\{ return new string[0]; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public string component;  \\newline \n \\newline \n\\btab public IList<String> ArgumentOrdering \\{  \\newline \n\\btab \\btab get \\{ return new string[] \\{ component \\}; \\}  \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public TermActivationFlags VolTerms \\{ \\newline \n\\btab \\btab get \\{ \\newline \n\\btab \\btab \\btab return TermActivationFlags.AllOn; \\newline \n\\btab \\btab \\} \\newline \n\\btab \\} \\newline \n \\newline \n\\btab public double VolumeForm(ref CommonParamsVol cpv,  \\newline \n\\btab \\btab    double[] U, double[,] GradU,  \\newline \n\\btab \\btab    double V, double[] GradV) \\{ \\newline \n\\btab \\btab return U[0]*V;            \\newline \n\\btab \\} \\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We are going to implement the linear Poisson-operator\n/// \\[\n/// \\left[ \\begin{array}{ccc}\n///      1           &  0         & \\partial_x \\\\\n///      0           &  1         & \\partial_y \\\\\n///      -\\partial_x & -\\partial_y & 0 \n/// \\end{array} \\right]\n/// \\cdot \n/// \\left[ \\begin{array}{c} \\sigma_0 \\\\ \\sigma_1 \\\\ u \\end{array} \\right]\n/// = \n/// \\left[ \\begin{array}{c} c_0 \\\\ c_1 \\\\ c_2 \\end{array} \\right]\n/// \\]\n/// The variables $c_0$, $c_1$ and $c_2$, which correspond to the \n/// test functions are also called co-domain variables of the operator.\n/// We are using the negative divergence, since this will lead to a \n/// symmetric matrix, instead of a anti-symmetric one.\n/// By doing so, we can e.g. use a Cholesky-factorization to determine \n/// whether the system is definite or not.\nvar OpPoisson = new SpatialOperator(3, 3,  \\newline \n\\btab \\btab \\btab \\btab \\btab   QuadOrderFunc.Linear(), \\newline \n\\btab \\btab \\btab \\btab \\btab   \"sigma1\", \"sigma2\", \"u\", // the domain-variables \\newline \n\\btab \\btab \\btab \\btab \\btab   \"c1\", \"c2\", \"c3\"); //       the co-domain variables  \\newline \n/// Now we add all required components to \\code{OpPoisson}:\nOpPoisson.EquationComponents[\"c1\"].Add(new Gradient\\_d(0)); \\newline \nOpPoisson.EquationComponents[\"c1\"].Add(new Identity() \\{ component = \"sigma1\" \\}); \\newline \nOpPoisson.EquationComponents[\"c2\"].Add(new Gradient\\_d(1)); \\newline \nOpPoisson.EquationComponents[\"c2\"].Add(new Identity() \\{ component = \"sigma2\" \\}); \\newline \nOpPoisson.EquationComponents[\"c3\"].Add(new Divergence\\_strong()); \\newline \nOpPoisson.Commit();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We create mappings $[\\sigma_1, \\sigma_2, u ]$:\n/// three different combinations of DG orders will be investigated:\n/// \\begin{itemize}\n/// \\item equal order: the same polynomial degree for $u$ and $\\vec{\\sigma}$\n/// \\item mixed order: the degree of $u$ is lower than the degree \n///       of $\\vec{\\sigma}$.\n/// \\item `strange' order: the degree of $u$ is higher than the degree of \n///       $\\vec{\\sigma}$.\n/// \\end{itemize}\nvar b3         = new Basis(gdata2D, 3); \\newline \nvar b2         = new Basis(gdata2D, 2); \\newline \nvar b4         = new Basis(gdata2D, 4); \\newline \nvar EqualOrder = new UnsetteledCoordinateMapping(b3,b3,b3); \\newline \nvar MixedOrder = new UnsetteledCoordinateMapping(b4,b4,b3); \\newline \nvar StrngOrder = new UnsetteledCoordinateMapping(b2,b2,b3);\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar MtxPoisson\\_Equal = OpPoisson.ComputeMatrix(EqualOrder, null, EqualOrder); \\newline \nvar MtxPoisson\\_Mixed = OpPoisson.ComputeMatrix(MixedOrder, null, MixedOrder); \\newline \nvar MtxPoisson\\_Strng = OpPoisson.ComputeMatrix(StrngOrder, null, StrngOrder);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We show that the matrices are symmetric \n/// (use e.g. \\code{SymmetryDeviation(...)}), but indefinite\n/// (use e.g. \\code{IsDefinite(...)}).\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble symDev\\_Equal = MtxPoisson\\_Equal.SymmetryDeviation();\\newline \nsymDev\\_Equal;\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble symDev\\_Mixed = MtxPoisson\\_Mixed.SymmetryDeviation();\\newline \nsymDev\\_Mixed;\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble symDev\\_Strng = MtxPoisson\\_Strng.SymmetryDeviation();\\newline \nsymDev\\_Strng;\n }\n\\BoSSSexe\n\\BoSSScmd{\nMtxPoisson\\_Equal.IsDefinite();\n }\n\\BoSSSexe\n\\BoSSScmd{\nMtxPoisson\\_Mixed.IsDefinite();\n }\n\\BoSSSexe\n\\BoSSScmd{\nMtxPoisson\\_Strng.IsDefinite();\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// BoSSScmdSilent BoSSSexeSilent\nNUnit.Framework.Assert.LessOrEqual(symDev\\_Equal, 1.0e-8);\\newline \nNUnit.Framework.Assert.LessOrEqual(symDev\\_Mixed, 1.0e-8);\\newline \nNUnit.Framework.Assert.LessOrEqual(symDev\\_Strng, 1.0e-8);\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\n    /// %==========================================\n    /// \\section{Advanced topics}\n    /// %==========================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %====================================\n/// \\subsection{Algebraic reduction}\n/// %====================================\n/// Since the top-left corner of our matrix \n/// \\[ \n/// \\left[ \\begin{array}{cc}\n/// 1   & B \\\\\n/// B^T & 0 \n/// \\end{array} \\right]\n/// \\]\n/// is actually very easy to eliminate the variable $\\vec{\\sigma}$\n/// from our system algebraically. \n/// The matrix of the reduces system is obviously $B^T \\cdot B$.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\paragraph{Extraction of sub-matrices and elimination}\n/// From the mapping, we can actually obtain index-lists for each variable,\n/// which can then be used to extract sub-matrices from \n/// \\code{MtxPoisson\\_Equal}, \\code{MtxPoisson\\_Mixed}, resp. \n/// \\code{MtxPoisson\\_Strng}.\nint[] SigmaIdx\\_Equal = EqualOrder.GetSubvectorIndices(true, 0,1); \\newline \nint[] uIdx\\_Equal     = EqualOrder.GetSubvectorIndices(true, 2); \\newline \nint[] SigmaIdx\\_Mixed = MixedOrder.GetSubvectorIndices(true, 0,1); \\newline \nint[] uIdx\\_Mixed     = MixedOrder.GetSubvectorIndices(true, 2); \\newline \nint[] SigmaIdx\\_Strng = StrngOrder.GetSubvectorIndices(true, 0,1); \\newline \nint[] uIdx\\_Strng     = StrngOrder.GetSubvectorIndices(true, 2);\n }\n\\BoSSSexe\n\\BoSSScmd{\n// The extraction of the sub-matrix and the elimination, for the equal order: \\newline \nvar MtxPoissonRed\\_Equal =  \\newline \n\\btab   MtxPoisson\\_Equal.GetSubMatrix(uIdx\\_Equal, SigmaIdx\\_Equal)  // -Divergence \\newline \n\\btab * MtxPoisson\\_Equal.GetSubMatrix(SigmaIdx\\_Equal, uIdx\\_Equal); // Gradient\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Finally, we also\n/// create the reduced system for the mixed and the strange \n/// order, test for the definiteness of the reduced system.\n/// Equal and mixed order are positive definite, while the strange order\n/// is indefinite - a clear indication that something ist wrong:\n }\n\\BoSSSexe\n\\BoSSScmd{\nvar MtxPoissonRed\\_Mixed =  \\newline \n\\btab   MtxPoisson\\_Mixed.GetSubMatrix(uIdx\\_Mixed, SigmaIdx\\_Mixed)  // -Divergence \\newline \n\\btab * MtxPoisson\\_Mixed.GetSubMatrix(SigmaIdx\\_Mixed, uIdx\\_Mixed); // Gradient   \\newline \nvar MtxPoissonRed\\_Strng =  \\newline \n\\btab   MtxPoisson\\_Strng.GetSubMatrix(uIdx\\_Strng, SigmaIdx\\_Strng)  // -Divergence \\newline \n\\btab * MtxPoisson\\_Strng.GetSubMatrix(SigmaIdx\\_Strng, uIdx\\_Strng); // Gradient\n }\n\\BoSSSexe\n\\BoSSScmd{\nbool isdef\\_red\\_Equal = MtxPoissonRed\\_Equal.IsDefinite();\\newline \nisdef\\_red\\_Equal;\n }\n\\BoSSSexe\n\\BoSSScmd{\nbool isdef\\_red\\_Mixed = MtxPoissonRed\\_Mixed.IsDefinite();\\newline \nisdef\\_red\\_Mixed;\n }\n\\BoSSSexe\n\\BoSSScmd{\nbool isdef\\_red\\_Strng = MtxPoissonRed\\_Strng.IsDefinite();\\newline \nisdef\\_red\\_Strng;\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// BoSSScmdSilent BoSSSexeSilent\nNUnit.Framework.Assert.IsTrue(isdef\\_red\\_Equal);\\newline \nNUnit.Framework.Assert.IsTrue(isdef\\_red\\_Mixed);\\newline \nNUnit.Framework.Assert.IsFalse(isdef\\_red\\_Strng);\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\n/// We compute the condition number of all three matrices; we observe that\n/// the mixed as well as the equal-order discretization result give rather \n/// moderate condition numbers. For the strange orders, the condition number\n/// of the system is far to high:\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble condest\\_Mixed = MtxPoissonRed\\_Mixed.condest();\\newline \ncondest\\_Mixed;\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble condest\\_Equal = MtxPoissonRed\\_Equal.condest();\\newline \ncondest\\_Equal;\n }\n\\BoSSSexe\n\\BoSSScmd{\ndouble condest\\_Strng = MtxPoissonRed\\_Strng.condest();\\newline \ncondest\\_Strng;\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// BoSSScmdSilent BoSSSexeSilent\nNUnit.Framework.Assert.LessOrEqual(condest\\_Mixed, 1e5);\\newline \nNUnit.Framework.Assert.LessOrEqual(condest\\_Equal, 1e5);\\newline \nNUnit.Framework.Assert.Greater(condest\\_Strng, 1e10);\n }\n\\BoSSSexeSilent\n", "meta": {"hexsha": "1981800a759845f019e3ca5683a221add548090a", "size": 25409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/tutorial10-PoissonSystem/Poisson.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/tutorial10-PoissonSystem/Poisson.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/tutorial10-PoissonSystem/Poisson.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": 38.7332317073, "max_line_length": 171, "alphanum_fraction": 0.659884293, "num_tokens": 7966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6199244650799967}}
{"text": "\\section{Error Calculation}\n\\label{sec:Error_Calculation}\nThis section contains the error calculation of the measured values. The error calculation is done for the fitted vacuum permeability $\\mu_0$ (see sections \\ref{subsubsec:Short_Cylindrical_Coil} to \\ref{subsubsec:Long_Cylindrical_Coil_Field}).\n\n\\subsection{Uncertainties}\n\\label{subsec:Uncertainties}\nAll conducted measurements in this experiment have uncertainties. The uncertainty of the gaussmeter and the Hall sensor is really small (only 0.3 \\%) compared to the other uncertainties. This means that it could be neglected. In this exercise it is considered nevertheless. The systematic uncertainties are shown in table \\ref{tab:measurement_devices_and_sensors} and table \\ref{tab:Specifications_Cylindrical_Coils} (the uncertainty of the radius $R$ is only half of the uncertainty of the diameter $d$).\n\n\\subsection{Calculating the Uncertainty of $\\mu_0$}\n\\label{subsec:Calculating_the_Uncertainty}\nTo derive the total uncertainty of the vacuum permeability $\\mu_0$ the following equations are used. The statistical uncertainty is obtained from the fits (from QtiPlot).\n\\begin{equation}\ns_{\\mu_{0,\\ TOT}}=\\sqrt{s_{\\mu_{0,\\ SYST}}^2+s_{\\mu_{0,\\ STAT}}^2}\n\\label{eq:total_uncert}\n\\end{equation}\nwith:\n\\begin{equation}\ns_{\\mu_{0,\\ SYST}}=\\sqrt{\\left(\\frac{\\partial \\mu_0}{\\partial B_0}\\Biggr|_{\\mu_0}\\cdot s_{B_0}\\right)^2 + \\left(\\frac{\\partial \\mu_0}{\\partial I}\\Biggr|_{\\mu_0}\\cdot s_{I}\\right)^2 + \\left(\\frac{\\partial \\mu_0}{\\partial l}\\Biggr|_{\\mu_0}\\cdot s_{l}\\right)^2 + \\left(\\frac{\\partial \\mu_0}{\\partial R}\\Biggr|_{\\mu_0}\\cdot s_{R}\\right)^2}\n\\label{eq:error_propagation}\n\\end{equation}\n\nand with:\n\n\\[\n\\frac{\\partial \\mu_0}{\\partial B_0}\\Biggr|_{\\mu_0}=\\frac{l}{NI}\\cdot\\sqrt{1+(\\,^{2R}\\!/_{l})^2} \\qquad , \\qquad \\frac{\\partial \\mu_0}{\\partial I}\\Biggr|_{\\mu_0}=-\\frac{B_0l}{NI^2}\\cdot\\sqrt{1+(\\,^{2R}\\!/_{l})^2}\n\\]\n\n\\[\n\\frac{\\partial \\mu_0}{\\partial l}\\Biggr|_{\\mu_0}=\\frac{B_0}{NI}\\cdot\\frac{1}{\\sqrt{1+(\\,^{2R}\\!/_{l})^2}} \\qquad , \\qquad \\frac{\\partial \\mu_0}{\\partial R}\\Biggr|_{\\mu_0}=\\frac{4B_0R}{lNI}\\cdot\\frac{1}{\\sqrt{1+(\\,^{2R}\\!/_{l})^2}}\n\\]\n\nwhere:\n\\begin{conditions}\n\ts_{\\mu_{0,\\ TOT}} & total uncertainty of $\\mu_0$ \\\\\n\ts_{\\mu_{0,\\ SYST}} & systematical uncertainty of $\\mu_0$ \\\\\n\ts_{\\mu_{0,\\ STAT}} & statistical uncertainty of $\\mu_0$ (obtained from a fit) \\\\\n\tB_0 & magnetic field in the center \\\\\n\t\\mu_0 & vacuum permeability \\\\\n\tN & number of turns \\\\\n\tI & current \\\\\n\tl & length \\\\\n\tR & radius\n\\end{conditions}\n\n\\subsection{Calculated Uncertainties $\\mu_0$}\n\\label{subsec:Calculated_Uncertainties}\nThe systematic uncertainty was calculated using equation \\ref{eq:error_propagation} and the statistical uncertainty was obtained from the fits (see sections \\ref{subsubsec:Short_Cylindrical_Coil} to \\ref{subsubsec:Long_Cylindrical_Coil_Field}). The total uncertainty was calculated by using equation \\ref{eq:total_uncert}.\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t & \\textbf{Systematic} $(\\,^\\text{Vs}\\!/_\\text{Am})$ & \\textbf{Statistical} $(\\,^\\text{Vs}\\!/_\\text{Am})$ & \\textbf{Total} $(\\,^\\text{Vs}\\!/_\\text{Am})$ \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Short Center} (sec. \\ref{subsubsec:Short_Cylindrical_Coil}) & $1.92167\\cdot10^{-8}$ & $1.87622\\cdot10^{-10}$ & $1.92176\\cdot10^{-8}$ \\\\\n\t\t\\textbf{Short Field} (sec. \\ref{subsubsec:Short_Cylindrical_Coil_Field}) & $1.92288\\cdot10^{-8}$ & $6.34659\\cdot10^{-10}$ & $1.92393\\cdot10^{-8}$ \\\\\n\t\t\\textbf{Long Center} (sec. \\ref{subsubsec:Long_Cylindrical_Coil}) & $1.48213\\cdot10^{-8}$ & $1.57922\\cdot10^{-10}$ & $1.48221\\cdot10^{-8}$ \\\\\n\t\t\\textbf{Long Field} (sec. \\ref{subsubsec:Long_Cylindrical_Coil_Field}) & $1.47958\\cdot10^{-8}$ & $3.64561\\cdot10^{-10}$ & $1.48003\\cdot10^{-8}$ \\\\\n\t\\end{tabular}\n\t\\caption{Calculated Uncertainties}\n\t\\label{tab:Calculated_Uncertainties}\n\\end{table}\n\nTo calculate the systematic uncertainty of the short coil (center value) the measurement point where the current $I=0.42$\\ A was used (see table \\ref{tab:Short_Cylindrical_Coil_Measurements_Central_Value}).\n\nTo calculate the systematic uncertainty of the short coil (field pattern) the measurement point which is closest to the center was used. The position of this point is $z=-0.003$\\ m (see table \\ref{tab:Short_Cylindrical_Coil_Measurements_Field_Pattern}).\n\nTo calculate the systematic uncertainty of the long coil (center value) the measurement point where the current $I=0.521$\\ A was used (see table \\ref{tab:Long_Cylindrical_Coil_Measurements_Central_Value}).\n\nTo calculate the systematic uncertainty of the long coil (field pattern) the measurement point which is closest to the center was used. The position of this point is $z=0.004$\\ m (see table \\ref{tab:Long_Cylindrical_Coil_Measurements_Field_Pattern}).\n", "meta": {"hexsha": "49cd56c8edb20b5413fb74ebf089bd177576c2be", "size": 4790, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "glaL3_E_6_Magnetic_Fields/sections/error_calculation.tex", "max_stars_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_stars_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "glaL3_E_6_Magnetic_Fields/sections/error_calculation.tex", "max_issues_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_issues_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "glaL3_E_6_Magnetic_Fields/sections/error_calculation.tex", "max_forks_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_forks_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_forks_repo_licenses": ["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.4285714286, "max_line_length": 505, "alphanum_fraction": 0.7286012526, "num_tokens": 1586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426303, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6199244621041298}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Dimensionality Reduction}\n\\label{chap:dim_reduct}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Feature Selection}\n\\label{dim_reduct:feature_selection}\n% TODO\n% TODO Can look at correlation or mutual information between variables\n% TODO could also use a chi2 test for independence between input variables and the dependent variable, see which ones might be useful. See https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Forward and Backward Feature Selection}\n\\label{dim_reduct:feature_selection:forward_backward}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Principle Component Analysis (PCA)}\n\\label{dim_reduct:PCA}\n% https://youtu.be/dhK8nbtii6I\n\nPrinciple component analysis (PCA) \\cite{pca} is a popular linear method\nof reducing a dataset to a limited set of more descriptive dimensions.\nPCA works by preforming a change of basis from\nthe dataset's original vector space to a new orthonormal basis which\nminimizes the average squared distance between the data points and the basis vectors,\nor equivalently maximizes the variance of the data in the new vector space.\n\nTo begin, we construct a $n \\times m$ matrix $\\mathbf{X}$\nfrom the $n$ features and $m$ data points in the original vector space\nwith basis $\\left\\{\\vu{e}_{i}\\right\\}$.\nIf we project the $\\vb{x}_{j}$ data point on to\nsome new unit vector $\\vu{u}_{i}$,\n$\\vb{x}_{j} \\to \\vu{u}_{i}\\transpose \\vb{x}_{j} \\vu{u}_{i}$,\nthe variance of the data along $\\vu{u}_{i}$ will be\n\n\\begin{subequations}\\label{dim_reduct:PCA:variance}\n\\begin{align}\n\\variance{\\mathbf{X} \\vu{u}_{i}}\n&= \\frac{1}{m}\\sum_{j=1}^{m} \\left(\n\\vu{u}_{i}\\transpose \\vb{x}_{j}\n-\n\\vu{u}_{i}\\transpose \\expval{\\vb{x}}\n\\right)^{2}\n= \\frac{1}{m}\\sum_{j=1}^{m} \\left( \\vu{u}_{i}\\transpose \\left(\\vb{x}_{j} - \\expval{\\vb{x}}\\right)\\right)^{2}, \\label{dim_reduct:PCA:variance:a} \\\\\n&= \\frac{1}{m}\\sum_{j=1}^{m}\n\\vu{u}_{i}\\transpose\n\\left(\\vb{x}_{j} - \\expval{\\vb{x}}\\right)\n\\left(\\vb{x}_{j} - \\expval{\\vb{x}}\\right)\\transpose\n\\vu{u}_{i}\n= \\vu{u}_{i}\\transpose \\mathbf{M} \\vu{u}_{i}, \\label{dim_reduct:PCA:variance:M}\n\\end{align}\n\\end{subequations}\n\n\\noindent where $\\mathbf{M}$ is\nthe covariance matrix\\footnote{$M_{ij} = \\cov{\\mathbf{X} \\vu{e}_{i}}{\\mathbf{X} \\vu{e}_{j}}$,\nsee \\cref{stats:corr_covar:covar_matrix}.} of $\\mathbf{X}$\nand $\\expval{\\vb{x}} = \\sum_{i=1}^{n} \\expval{\\mathbf{X} \\vu{e}_{i}} \\vu{e}_{i}$.\nWe now wish to find a new orthonormal basis $\\left\\{\\vu{u}_{i}\\right\\}$\nwhich maximizes $\\variance{\\mathbf{X} \\vu{u}_{i}}$,\nsubject to the constraint that $\\abs{\\vu{u}_{i}} = \\vu{u}_{i}\\transpose \\vu{u}_{i} = 1$,\n\\ie the classic Lagrange multiplier problem of \\cref{opt:lagrange_mult}.\n\nTaking matrix derivatives\n\n\\begin{subequations}\\label{dim_reduct:PCA:lagrange}\n\\begin{align}\n0 &= \\dv{\\vu{u}_{i}} \\left( \\vu{u}_{i}\\transpose \\mathbf{M} \\vu{u}_{i}\n+ \\lambda \\left( 1 - \\vu{u}_{i}\\transpose \\vu{u}_{i} \\right) \\right)\n= 2 \\mathbf{M} \\vu{u}_{i} - 2 \\lambda \\vu{u}_{i}, \\label{dim_reduct:PCA:lagrange:setup} \\\\\n&\\implies \\mathbf{M}\\vu{u}_{i} = \\lambda \\vu{u}_{i}, \\label{dim_reduct:PCA:lagrange:eigen}\n\\end{align}\n\\end{subequations}\n\n\\noindent we discover that $\\left\\{\\vu{u}_{i}\\right\\}$\nis just the eigenbasis of $\\mathbf{M}$ with eigenvalues $\\lambda_{i}$.\nIf we left multiply \\cref{dim_reduct:PCA:lagrange:eigen} by $\\vu{u}_{i}\\transpose$\nwe see that the largest eigenvalue $\\lambda_{1}$ corresponds to the\nnew $\\vu{u}_{1}$ dimension with the largest variance, \\ie the first principle component (PC1),\n$\\vu{u}_{2}$ with the second largest variance, \\ie second principle component (PC2), and so on.\n\nIn practice, we should first center and normalize the data,\nby subtracting the mean and dividing by the standard deviation along each dimension,\nbefore preforming the eigendecomposition.\nIntuitively, PCA is stretching and rotating the vector space to find the best PCs,\nbut the origin will remain fixed, $\\vu{u}_{i}\\transpose\\,\\va{0}\\,\\vu{u}_{i} = \\va{0}$,\nand the input dimensions are being mixed together $1 \\mathbin{:} 1$ without regard for units.\nSome PCA software packages perform these preprocessing steps by default,\nbut it is not universal so check the appropriate documentation.\n\nIf there are few data points relative to the original dimensions, $m < n$,\nthe eigendecomposition will still work, but some of the $\\lambda_{i}$ may be $< 0$.\nThese eigenvalues should be disregarded, leaving $\\min\\left(m,n\\right)$ possible principle components.\n\n% TODO real estate example: show how PCA can merge fields like # rooms, # bathrooms, sq footage, zip code, distance to schools, etc down to two dimensions standing in for house size and location\n% TODO include representative figure?\n% TODO many ways of actually doing the computation, including sparse PCA\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Scree plots}\n\\label{dim_reduct:PCA:Scree}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Singular Value Decomposition (SVD)}\n\\label{dim_reduct:SVD}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Linear Discriminant Analysis (LDA)}\n\\label{dim_reduct:LDA}\n% TODO\n\n% TODO include Gaussian Discriminant Analysis (GDA) and Quadratic Discriminant Analysis (QDA)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Isomap}\n\\label{dim_reduct:isomap}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Factor Analysis and Confounding Variables}\n\\label{dim_reduct:factor_ana}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Mutual Information (MI)}\n\\label{dim_reduct:MI}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Normalized Mutual Information (NMI)}\n\\label{dim_reduct:MI:normalized}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Term Frequency-Inverse Document Frequency (TF-IDF)}\n\\label{dim_reduct:tfidf}\n\nTerm frequency-inverse document frequency (TF-IDF) is a statistic\nused in natural language processing (NLP) to quantify\nthe importance, or uniqueness, of a term $t$ in a document $d$\nwith respect to a wider set of documents $D$\\footnote{Note that $d$ is not necessarily an element of $D$, we can compare novel $d$ to a reference corpus $D$.}.\nAs the name suggests, TF-IDF is the product of two components,\none representing the frequency of the term under consideration within the document of interest,\nand the other the inverse of the frequency of the term in all documents of the broader corpus.\nThere are a handful of definitions available for each term, but we will only describe\none of the more standard forms in this section:\n\n\\begin{subequations}\\label{eq:unsupervised:tfidf}\n\\begin{align}\n\\text{tf}\\left(t,d\\right) &= \\frac{n_{t,d}}{\\sum_{t' \\in d} n_{t',d}}, \\label{eq:unsupervised:tfidf:tf} \\\\\n\\text{idf}\\left(t,D\\right) &= \\log\\left(\\frac{\\abs{D}}{1 + \\abs{\\left\\{d' \\in D \\, | \\, t \\in d'\\right\\}}}\\right), \\label{eq:unsupervised:tfidf:idf} \\\\\n\\text{tf-idf}\\left(t,d\\right) &= \\text{tf}\\left(t,d\\right) \\times \\text{idf}\\left(t,D\\right). \\label{eq:unsupervised:tfidf:tfidf}\n\\end{align}\n\\end{subequations}\n\n\\noindent Here $n_{t,d}$ is number of times $t$ appears in $d$,\n$\\abs{D}$ is the number of documents in $D$,\nand $\\abs{\\left\\{d \\in D \\, | \\, t \\in d\\right\\}}$ is the number of number of documents in $D$ which contain $t$.\nWe take the natural log in the $\\text{idf}\\left(t,D\\right)$ component to better accommodate large corpora of documents,\nand include the constant $1+$ term to avoid divide-by-zero issues.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Prevalence Ratio}\n\\label{dim_reduct:prevalence_ratio}\n\nThe prevalence ratio (PR) is a similar concept to TF-IDF,\nallowing us to identify important characteristics of a population of interest versus the wider population.\nFor example, we can use a PR to assess the association of hypertension with heart failure by comparing\nthe prevalence of hypertension in a cohort of heart failure patients\nto the prevalence of hypertension in the general population,\nor at least a representative sample\\footnote{Defining an acceptable representative sample is often the hardest part of the analysis and may require stratification, \\eg stratifying by age when investigating disease.} of it.\n\nThe prevalence of a characteristic $c$ in a population $P$ is $\\abs{\\{p' \\in P \\, | \\, c \\in p'\\}} \\, / \\, \\abs{p' \\in P}$,\nnote the similarity to $\\text{tf}\\left(t,d\\right)$ \\cref{eq:unsupervised:tfidf:tf}.\nThe prevalence ratio is then\n\n\\begin{equation}\\label{eq:unsupervised:PR}\n\\text{PR}\\left(t,d\\right) = \\frac{ \\abs{\\{p' \\in P \\, | \\, c \\in p'\\}} \\, / \\, \\abs{p' \\in P} }{ \\abs{\\{p' \\in P_{0} \\, | \\, c \\in p'\\}} \\, / \\, \\abs{p' \\in P_{0}} },\n\\end{equation}\n\n\\noindent where $P$ is the population of interest and $P_{0}$ is the wider population.\n\nNote that the PR is mathematically identical to the relative risk, or hazard ratio (HR) discussed in \\cref{chap:survival}.\nThere is a similar discussion in the literature \\cite{pmid27460748,10.3389/fvets.2017.00193}\non prevalence ratios versus odds ratios as is described in \\cref{survival:additional:odds}.\n\n% See also: https://sph.unc.edu/wp-content/uploads/sites/112/2015/07/nciph_ERIC8.pdf\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{\\texorpdfstring{$t$}{t}-Distributed Stochastic Neighbor Embedding (\\texorpdfstring{$t$}{t}-SNE)}\n\\label{dim_reduct:tSNE}\n% TODO\n% TODO \\tSNE\n", "meta": {"hexsha": "162645585849bc2e5138aeb3a7b53bf23618d1e1", "size": 10277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/dim_reduct.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/dim_reduct.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/dim_reduct.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": 49.4086538462, "max_line_length": 224, "alphanum_fraction": 0.623820181, "num_tokens": 2789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6199244602859291}}
{"text": "\\documentclass[11pt,twocolumn]{amsart} % twocolumn\n\\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.\n\\geometry{a4paper}                   % ... or a4paper or a5paper or ... \n\\usepackage{layout}\n%\\geometry{landscape}                % Activate rotated page geometry\n%\\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage{epstopdf}\n\\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n% shortcuts\n\\newcommand{\\ve}[1]{\\boldsymbol{#1}}\n\\newcommand{\\ma}[1]{\\boldsymbol{#1}}\n\\newenvironment{m}{\\begin{bmatrix}}{\\end{bmatrix}}\n\\def\\argmax{\\operatornamewithlimits{arg\\,max}}\n\n\\title{Some stuff for \\textbf{home}}\n\\author{Gaspard Buma}\n%\\date{}                                           % Activate to display a given date or no date\n\n\\begin{document}\n\n\\twocolumn[\n\\maketitle\n]\n\\section{Notations}\nData set\n\\[\n\t\\ve{s_t} = \\begin{m} s_{t1} & \\hdots & s_{t12} \\end{m}\n\\]\n\\begin{align*}\n\t\\ve{t_t} = & \\begin{m} \\ve{s_{t-24}} & \\hdots & \\ve{s_t} \\end{m} \\\\\n\t\\ve{t_t} = & \\begin{m} s_{(t-24)1} & \\hdots & s_{(t-24)12} \\hdots s_{t1} & \\hdots & s_{t12} \\end{m}\n\\end{align*}\n\n\\begin{align*}\n\t\\ve{u_t} = & \\begin{m} f_{t1} & \\hdots & f_{t12} \\hdots a_{t1} & \\hdots & a_{t12} & \\hdots & \\hat{s_{t1}} & \\hdots & \\hat{s_{t12}} \\end{m}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "688b6f3ba6ff8d257dace3ac3bc88c4837bbb94a", "size": 1473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/setup.tex", "max_stars_repo_name": "BackupTheBerlios/rubyk", "max_stars_repo_head_hexsha": "a885b079633073da259941c6dc05ad0c419d3f72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-14T20:36:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-14T20:36:21.000Z", "max_issues_repo_path": "doc/setup.tex", "max_issues_repo_name": "BackupTheBerlios/rubyk", "max_issues_repo_head_hexsha": "a885b079633073da259941c6dc05ad0c419d3f72", "max_issues_repo_licenses": ["MIT"], "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": "BackupTheBerlios/rubyk", "max_forks_repo_head_hexsha": "a885b079633073da259941c6dc05ad0c419d3f72", "max_forks_repo_licenses": ["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.0714285714, "max_line_length": 139, "alphanum_fraction": 0.6306856755, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6199141147499798}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\n  \\textit{Logic sometimes makes monsters.} For half a century we have\n  seen a mass of bizarre functions which appear to be forced to\n  resemble as little as possible honest functions which serve some\n  purpose. More of continuity, or less of continuity, more\n  derivatives, and so forth.\n  \\byline{Henri Poincar\\'e} % can someone find the actual reference for this?!\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  What is meant by uniform convergence on compact sets?\n\\end{problem}\n\n\\begin{problem}\n  What is a biholomorphism $f : U \\to V$?\n\\end{problem}\n\n\\begin{problem}\n  Define \\textbf{star-convex}.\n\\end{problem}\n\n\\section{Numericals}\n\n\\begin{problem}\\label{max-modulus-numerical}\n  Consider $f(z) = 4z - (2z - i)^2 - 2i - 4$.  Find $z$ in \n  \\[\n    \\{ x + iy \\in \\C : 0 \\leq x \\leq 1 \\mbox{ and } 0 \\leq y \\leq 1 \\}\n  \\]\n  maximizing $\\abs{f(z)}$.\n\\end{problem}\n\n\\section{Exploration}\n\n\\begin{problem}\n  Sometimes things are \\textit{much} better in the complex case than\n  the real case.  Find a sequence of smooth functions\n  $f_n : [-1,1] \\to \\R$ converging uniformly to $f(x) = \\abs{x}$ which\n  is not differentiable at zero.  Can the uniform limit of holomorphic\n  functions fail to be holomorphic?\n\\end{problem}\n\n\\begin{problem}\\label{hadamard-three-lines}Prove \\textbf{Hadamard's\n    three-lines theorem} which is about the strip\n  \\[\n    S_{a,b} := \\{ x+iy \\in \\C : a \\leq x \\leq b\\}\n  \\]\n  bounded by two horizontal lines, i.e., the line with real part $a$\n  and the line with real part $b$.  Suppose $f : S_{a,b} \\to \\C$ is a\n  bounded continuous function which is holomorphic on the interior of\n  $S_{a,b}$.  Define $M : [a,b] \\to \\R$ by\n  \\[\n    M(x) := \\sup_{y \\in \\R} \\abs{f(x+iy)},\n  \\]\n  that is, $M(x)$ is the supremum of $\\abs{f}$ on the (third!) line with real part $x$.\n  \n  Show that, if $t \\in [0,1]$, then \\[\n    M\\left( ta + (1-t)b \\right) \\leq M(a)^t M(b)^{1-t}.\n  \\]\n\\end{problem}\n\n\\begin{problem}\\label{schwarz-lemma}Suppose $f : B_1(0) \\to B_1(0)$ is holomorphic and $f(0) = 0$.  Show\n  that $\\abs{f(z)} \\leq \\abs{z}$ for all $z \\in B_1(0)$.  How large\n  could $\\abs{f'(0)}$ be?  This is the \\textbf{Schwarz lemma}.\n\\end{problem}\n\n\\begin{problem}\\label{schwarz-lemma-2}Suppose again that $f : B_1(0) \\to B_1(0)$ is holomorphic and $f(0) = 0$, and\n  suppose further that $\\abs{f(z)} = \\abs{z}$ for some nonzero\n  $z \\in \\C$.  Show that $f$ must be a rotation, i.e., there is some\n  $\\lambda \\in \\C$ with $\\abs{\\lambda} = 1$ and $f(z) = \\lambda z$.\n  (This is also the Schwarz lemma.)\n\\end{problem}\n\n\\begin{problem}\\label{schwarz-lemma-3}Suppose that\n  $f : B_1(0) \\to B_1(0)$ is holomorphic and $f(0) = 0$ and $\\abs{f'(0)} = 1$.  What\n  can you deduce about $f$?\n\\end{problem}\n\n\\begin{problem}\\label{schwarz-reflection-principle-2}Consider the\n  closed upper half-plane\n  \\[\n    H := \\{ x + iy \\in \\C : x \\in \\R \\mbox{ and } y \\geq 0 \\}.\n  \\]\n  Suppose $f : H \\to \\C$ is continuous, holomorphic on the interior of\n  $H$, and sends reals to reals, i.e., if $x \\in \\R$ then\n  $f(x) \\in \\R$.  Use a trick like \\ref{schwarz-reflection-principle}\n  to describe an entire function agreeing with $f$ on its domain.\n\\end{problem}\n\n\\begin{problem}Consider the closed disk\n  \\[\n    D := \\{ z \\in \\C : \\abs{z} \\leq 1 \\},\n  \\]\n  and suppose $f : D \\to D$ is continuous, holomorphic on the interior\n  of $D$, sends boundary to boundary, i.e., if $z \\in \\partial D$ then\n  $f(z) \\in \\partial D$, and misses an interior point, i.e., there is\n  some $w$ in the interior of $D$ which is not in the image of $f$.\n\n  Combine \\ref{cayley-transform} and\n  \\ref{schwarz-reflection-principle-2} to produce an entire function.\n  What can you deduce about $f$?\n\\end{problem}\n\n\\section{Prove or Disprove and Salvage if Possible}\n\n\\begin{problem}\\label{cauchy-for-starlike}Suppose $U \\subset \\C$ is a\n  star-convex open set, and $f : U \\to \\C$ is holomorphic, and\n  $\\gamma : [0,1] \\to U$ is a smooth closed curve.  Then\n  \\[\n    \\int_\\gamma f(z) \\, dz = 0.\n  \\]\n\\end{problem}\n\n\\begin{problem}\\label{moreras-theorem}If a function $f : B_r(0) \\to \\C$\n  satisfies % missing continuous!\n  \\[\n    \\int_\\gamma f(z) \\, dz = 0\n  \\]\n  for all piecewise smooth closed curves $\\gamma$ in the disk\n  $B_r(0)$, then $f$ is holomorphic.\n\\end{problem}\n\n\\begin{problem}\\label{uniform-convergence-holomorphic}If the sequence of\n  holomorphic functions $f_n : U \\to \\C$ converge pointwise to\n  $f : U \\to \\C$, then $f$ is holomorphic.\n\\end{problem}\n\n\\begin{problem}\\label{automorphisms-of-disk}Suppose $f, g : B_r(0) \\to B_r(0)$ are holomorphic and\n  $f \\circ g = g \\circ f$ are the identity on $B_r(0)$.  Then there is\n  $w \\in B_r(0)$ and $\\theta \\in [0,2\\pi)$ with\n  \\[\n    f(z) = e^{i\\theta} \\cdot \\frac{w - z}{1 - \\conj{w}z}.\n  \\]\n  This should remind you of \\ref{blaschke-factors}.  This result\n  highlights the rigidity of biholomorphic functions as compared to,\n  say, homeomorphisms.\n\\end{problem}\n\n\\end{document}\n", "meta": {"hexsha": "b25f24d2698bcb95e37695cc43eef990100fd1b1", "size": 5056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set06.tex", "max_stars_repo_name": "kisonecat/math5522h", "max_stars_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-13T03:38:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T03:38:29.000Z", "max_issues_repo_path": "problem-sets/set06.tex", "max_issues_repo_name": "kisonecat/math5522h", "max_issues_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "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/set06.tex", "max_forks_repo_name": "kisonecat/math5522h", "max_forks_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-11T18:43:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-11T18:43:51.000Z", "avg_line_length": 33.932885906, "max_line_length": 115, "alphanum_fraction": 0.6558544304, "num_tokens": 1794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.6199141097813194}}
{"text": "% This chapter has been modified on 6/4/05.\n%\\setcounter{chapter}{3}\n\n\\chapter{Conditional Probability}\\label{chp 4}  \n\n\\section{Discrete Conditional Probability}\\label{sec 4.1} \n\n\\subsection*{Conditional Probability}\n\\par\nIn this section we ask and answer the following question.  Suppose we assign a\ndistribution function to a sample space and then learn that an event $E$ has\noccurred.  How should we change the probabilities of the remaining events?  We\nshall call the new probability for an event $F$ the \\emx {conditional\nprobability\\index{probability!conditional}\\index{conditional probability} of $F$ given $E$} and\ndenote it by\n$P(F|E)$.\n\n\\begin{example}\\label{exam 4.1}\nAn experiment consists of rolling a die once.  Let $X$ be the outcome.  Let $F$ be the event\n$\\{X = 6\\}$, and  let $E$ be the event $\\{X > 4\\}$.  We assign the\ndistribution function\n$m(\\omega) = 1/6$ for $\\omega = 1, 2, \\ldots , 6$.  Thus, $P(F) =\n1/6$.  Now suppose that the die is rolled and we are told that the event $E$ has occurred.  \nThis leaves only two possible outcomes: 5 and~6.  In the absence of any other \ninformation, we would still regard these outcomes to be equally likely, so the \nprobability of $F$ becomes 1/2, making $P(F|E) = 1/2$.\n\\end{example}\n\n\\begin{example}\\label{exam 4.1.5}\nIn the Life Table (see Appendix~C), one finds that in a population of 100{,}000 females, 89.835\\%\ncan expect to live to age 60, while 57.062\\% can expect to live to age 80.  Given that a woman is\n60, what is the probability that she lives to age 80?\n\\par\nThis is an example of a conditional probability.  In this case, the original sample space\ncan be thought of as a set of 100{,}000 females.  The events $E$ and $F$ are the subsets of the\nsample space consisting of all women who live at least 60 years, and at least 80 years,\nrespectively.  We consider $E$ to be the new sample space, and note that $F$ is a subset of $E$. \nThus, the size of $E$ is 89{,}835, and the size of $F$ is 57{,}062.  So, the probability in\nquestion equals $57{,}062/89{,}835 = .6352$.  Thus, a woman who is 60 has a 63.52\\% chance of\nliving to age 80.\n\\end{example}\n\n\n\\begin{example}\\label{exam 4.2}\nConsider our voting example from Section~\\ref{sec 1.2}: three candidates A, B,\nand C are running for office.  We decided that A and B have an equal chance of\nwinning and C is only 1/2 as likely to win as A.  Let $A$ be the event ``A\nwins,\" $B$ that ``B wins,\" and $C$ that ``C wins.\"  Hence, we assigned\nprobabilities $P(A) = 2/5$, $P(B) = 2/5$, and $P(C) = 1/5$.  \n\\par\nSuppose that before the election is held, $A$ drops out of the race.  As in Example~\\ref{exam\n4.1}, it would be natural to assign new probabilities to the events $B$ and $C$ which are\nproportional to the original probabilities.  Thus, we would have $P(B|~A) = 2/3$, and\n$P(C|~A) = 1/3$.  It is important to note that any time we assign probabilities to real-life\nevents, the resulting distribution is only useful if we take into account all relevant\ninformation.  In this example, we may have knowledge that most voters who favor $A$ will vote\nfor $C$ if $A$ is no longer in the race.  This will clearly make the probability that\n$C$ wins greater than the value of 1/3 that was assigned above.\n\\end{example}\n\nIn these examples we assigned a distribution function and then were given new\ninformation that determined a new sample space, consisting of the outcomes that\nare still possible, and caused us to assign a new distribution function to this\nspace.\n\nWe want to make formal the procedure carried out in these examples.  Let\n$\\Omega = \\{\\omega_1,\\omega_2,\\dots,\\omega_r\\}$ be the original sample space\nwith distribution function $m(\\omega_j)$ assigned.  Suppose we learn that the\nevent $E$ has occurred.  We want to assign a new distribution function\n$m(\\omega_j|E)$ to $\\Omega$ to reflect this fact.  Clearly, if a sample point\n$\\omega_j$ is not in $E$, we want $m(\\omega_j|E) = 0$.  Moreover, in the\nabsence of information to the contrary, it is reasonable to assume that the\nprobabilities for $\\omega_k$ in $E$ should have the same relative magnitudes\nthat they had before we learned that $E$ had occurred.  For this we require\nthat\n$$\nm(\\omega_k|E) = cm(\\omega_k)\n$$\nfor all $\\omega_k$ in $E$, with $c$ some positive constant.  But we must also\nhave\n$$\n\\sum_E m(\\omega_k|E) = c\\sum_E m(\\omega_k) = 1\\ .\n$$\nThus,\n$$\nc = \\frac 1{\\sum_E m(\\omega_k)} = \\frac 1{P(E)}\\ .\n$$\n(Note that this requires us to assume that $P(E) > 0$.)  Thus, we will\ndefine\n$$\nm(\\omega_k|E) = \\frac {m(\\omega_k)}{P(E)}\n$$\nfor $\\omega_k$ in $E$.  We will call this new distribution the \\emx {conditional\ndistribution}\\index{conditional distribution} given $E$.  For a general event $F$, this gives\n$$\nP(F|E) = \\sum_{F \\cap E} m(\\omega_k|E) = \\sum_{F \\cap E}\\frac {m(\\omega_k)}{P(E)} = \n\\frac {P(F \\cap E)}{P(E)}\\ .\n$$\n\nWe call $P(F|E)$ the \\emx {conditional probability of $F$ occurring given that $E$ occurs,}\nand compute it using the formula\n$$\nP(F|E) = \\frac {P(F \\cap E)}{P(E)}\\ .\n$$\n\n\\begin{example}(Example~\\ref{exam 4.1} continued){\\label{exam 4.3}}\nLet us return to the example of rolling a die.  Recall that $F$ is the event $X = 6$, and\n$E$ is the event $X > 4$.  Note that $E \\cap F$ is the event $F$.  So, the above formula gives\n\\begin{eqnarray*}\nP(F|E) & = & \\frac {P(F \\cap E)}{P(E)} \\\\\n& = & \\frac {1/6}{1/3} \\\\\n& = & \\frac 12\\ ,\\\\\n\\end{eqnarray*}\nin agreement with the calculations performed earlier.\n\\end{example}\n\n\\begin{example}\\label{exam 4.4}\nWe have two urns, I and II.  Urn I contains 2 black balls and 3 white balls. \nUrn II contains 1 black ball and 1 white ball.  An urn is drawn at random and a ball\nis chosen at random from it.  We can represent the sample space of this experiment as the paths\nthrough a tree as shown in Figure~\\ref{fig 4.1}. The probabilities assigned to the paths are\nalso shown.  \n\\par\nLet $B$ be the event ``a black ball is drawn,\" and $I$ the event ``urn I is\nchosen.\"  Then the branch weight 2/5, which is shown on one branch in the figure, can now be\ninterpreted as the conditional probability $P(B|I)$.\n\n\\putfig{4.5truein}{PSfig4-1}{Tree diagram.}{fig 4.1}\n\n\\par\nSuppose we wish to calculate $P(I|B)$.  Using the formula, we obtain\n\\begin{eqnarray*}\nP(I|B) & = & \\frac {P(I \\cap B)}{P(B)} \\\\\n       & = & \\frac {P(I \\cap B)}{P(B \\cap I) + P(B \\cap II)} \\\\\n       & = & \\frac {1/5}{1/5 + 1/4} = \\frac 49\\ .\n\\end{eqnarray*}\n\\end{example}\n\n\\subsection*{Bayes Probabilities}\n\nOur original tree measure gave us the probabilities for drawing a ball of a\ngiven color, given the urn chosen.  We have just calculated the \\emx {inverse\nprobability} that a particular urn was chosen, given the color of the ball. \nSuch an inverse probability is called a \\emx {Bayes probability}\\index{Bayes\nprobability}\\index{probability!Bayes} and may be obtained by a formula that we shall develop\nlater.  Bayes probabilities can also be obtained by simply constructing the tree measure for the\ntwo-stage experiment carried out in reverse order.  We show this tree in Figure~\\ref{fig 4.2}.\n\n\\putfig{4.5truein}{PSfig4-2}{Reverse tree diagram.}{fig 4.2}\n\nThe paths through the reverse tree are in one-to-one correspondence with those in the forward\ntree, since they correspond to individual outcomes of the experiment, and so they are assigned\nthe same probabilities.  From the forward tree, we find that the probability of a black ball is\n$$\n\\frac 12 \\cdot \\frac 25 + \\frac 12 \\cdot \\frac 12 = \\frac 9{20}\\ .\n$$\n\nThe probabilities for the branches at the second level are found by simple\ndivision.  For example, if $x$ is the probability to be assigned to the top\nbranch at the second level, we must have\n$$\n\\frac 9{20} \\cdot x = \\frac 15\n$$\nor $x = 4/9$.  Thus, $P(I|B) = 4/9$, in agreement with our previous\ncalculations.  The reverse tree then displays all of the inverse, or Bayes,\nprobabilities.  \n\n\\begin{example}\\label{exam 4.5}\nWe consider now a problem called the \\emx {Monty Hall}\\index{Monty Hall problem} problem.   This\nhas long been a favorite problem but was revived by a letter from Craig Whitaker\\index{WHITAKER,\nC.} to Marilyn vos Savant\\index{vos SAVANT, M.} for consideration in her column in \\emx {Parade\nMagazine}.\\footnote{Marilyn vos Savant, Ask Marilyn, \\emx {Parade Magazine}, 9 \nSeptember;  2 December;  17  February 1990, reprinted in Marilyn vos Savant, \\emx {Ask\nMarilyn}, St. Martins, New York, 1992.}  Craig wrote:\n\\begin{quote}  Suppose you're on Monty Hall's \\emx {Let's Make a Deal!} You are given the choice of\nthree doors, behind one door is a car\\index{car}, the others, goats\\index{goat}.  You pick a door,\nsay 1, Monty opens another door, say 3, which has a goat.  Monty says to you ``Do you want to\npick door 2?\" Is it to your advantage to switch your choice of doors?\n\\end{quote}\n\\par\nMarilyn gave a solution concluding that you should switch, and if you do, your probability of\nwinning is 2/3.  Several irate readers, some of whom identified themselves as having a PhD in\nmathematics, said that this is absurd since after Monty has ruled out one door there are only two\npossible doors and they should still each have the same probability 1/2 so there is no advantage to\nswitching.  Marilyn stuck to her solution and encouraged her readers to simulate the game and draw\ntheir own conclusions from this.  We also encourage the reader to do this (see\nExercise~\\ref{exer 4.1.9.6}).\n\\par\nOther readers complained that Marilyn had not described the problem completely.  In particular, the\nway in which certain decisions were made during a play of the game were not specified.  This aspect\nof the problem will be discussed in Section~\\ref{sec 4.3}.  We will assume that the car was put\nbehind a door by rolling a three-sided die which made all three choices equally likely.  Monty\nknows where the car is, and always opens a door with a goat behind it.  Finally, we assume that if \nMonty has a choice of doors (i.e., the contestant has picked the door with the car behind it), he\nchooses each door with probability 1/2.  Marilyn\nclearly expected her readers to assume that the game was played in this manner.\n\\par\nAs is the case with most apparent paradoxes, this one can be resolved through careful analysis.\nWe begin by describing a simpler, related question.  We say that a contestant is using\nthe ``stay\" strategy if he picks a door, and, if offered a chance to switch to another door,\ndeclines to do so (i.e., he stays with his original choice).  Similarly, we say that the\ncontestant is using the ``switch\" strategy if he picks a door, and, if offered a chance to switch to\nanother door, takes the offer.  Now suppose that a contestant decides in advance to play the\n``stay\" strategy.  His only action in this case is to pick a door (and decline an invitation to\nswitch, if one is offered).  What is the probability that he wins a car?  The same\nquestion can be asked about the ``switch\" strategy.  \n\\par\nUsing the ``stay\" strategy, a contestant will win the car with probability 1/3, since 1/3 of the\ntime the door he picks will have the car behind it.  On the other hand, if a contestant plays\nthe ``switch\" strategy, then he will win whenever the door he originally picked does not have\nthe car behind it, which happens 2/3 of the time.  \n\\par\nThis very simple analysis, though correct, does not quite solve the problem that Craig posed.  Craig\nasked for the conditional probability that you win if you switch, given that you have chosen door 1\nand that Monty has chosen door 3.  To solve this problem, we set up the problem before\ngetting this information and then compute the conditional probability given this information. \nThis is a process that takes place in several stages; the car is put behind a door, the contestant\npicks a door, and finally  Monty opens a door.  Thus it is natural to analyze this using a tree\nmeasure.  Here we make an additional assumption that if Monty has a choice of doors (i.e., the\ncontestant has picked the door with the car behind it) then he picks each door with probability\n1/2.  The assumptions we have made determine the branch probabilities and these in turn determine\nthe tree measure. The resulting tree and tree measure are shown in Figure~\\ref{fig 4.4}.  It is tempting to\nreduce the tree's size by making certain assumptions such as: ``Without loss of generality, we\nwill assume that the contestant always picks door 1.\"  We have chosen not to make any such\nassumptions, in the interest of clarity.  \n\n\\putfig{4.5truein}{PSfig4-0}{The Monty Hall problem.}{fig 4.4}\n\\par\nNow the given information, namely that the contestant chose door 1 and Monty chose door 3, means\nonly two paths through the tree are possible (see Figure~\\ref{fig 4.4.5}).  \n\\putfig{4.5truein}{PSfig4-4-5}{Conditional probabilities for the Monty Hall problem.}{fig 4.4.5}\nFor one of these paths, the car is behind door 1 and for the other it is behind door 2.  \nThe path with the car behind door 2 is twice as likely as the one with the car behind door 1. \nThus the conditional probability is 2/3 that the car is behind door 2 and 1/3 that it is \nbehind door 1, so if you switch you have a 2/3 chance of winning the car, as Marilyn claimed.\n\\par\nAt this point, the reader may think that the two problems above are the same, since they have the\nsame answers.  Recall that we assumed in the original problem if the contestant\nchooses the door with the car, so that Monty has a choice of two doors, he chooses each of them with\nprobability 1/2.  Now suppose instead that in the case that he has a choice, he chooses the door\nwith the larger number with probability 3/4.  In the ``switch\" vs. ``stay\" problem, the\nprobability of winning with the ``switch\" strategy is still 2/3.  However, in\nthe original problem, if the contestant switches, he wins with probability 4/7.  The reader can\ncheck this by noting that the same two paths as before are the only two possible paths in the tree. \nThe path leading to a win, if the contestant switches, has probability 1/3, while the path which\nleads to a loss, if the contestant switches, has probability 1/4.\n\\end{example}\n\n\n\\subsection*{Independent Events}     \n\nIt often happens that the knowledge that a certain event $E$ has occurred has no effect on the\nprobability that some other event $F$ has occurred, that is, that $P(F|E) = P(F)$.  One would\nexpect that in this case, the equation\n$P(E|F) = P(E)$ would also be true.  In fact (see Exercise~\\ref{exer 4.1.1}), \neach equation implies the other.  If these equations are true, we might say\nthe $F$ is \\emx {independent} of $E$.  For example, you would not expect the\nknowledge of the outcome of the first toss of a coin to change the probability\nthat you would assign to the possible outcomes of the second toss, that is, you\nwould not expect that the second toss depends on the first.  This idea is\nformalized in the following definition of independent events.\n\n\\begin{definition}\\label{def 4.2}\nLet $E$ and $F$ be two events.  We say that they are \\emx {independent}\\index{events!independent}\\index{independence of\nevents} if either 1) both events have positive probability and\n$$\nP(E|F) = P(E)\\ {\\rm and}\\ P(F|E) = P(F)\\ ,\n$$\nor 2) at least one of the events has probability 0.\n\\end{definition}\n\nAs noted above, if both $P(E)$ and $P(F)$ are positive, then each of the above equations\nimply the other, so that to see whether two events are independent, only one of these\nequations must be checked (see Exercise~\\ref{exer 4.1.1}).\n\\par\nThe following theorem provides another way to check for independence.\n\n\\begin{theorem}\\label{thm 4.1}\nTwo events $E$ and $F$ are independent if and only if \n$$P(E\\cap F) = P(E)P(F)\\ .$$\n\\proof\nIf either event has probability 0, then the two events are independent and the above equation \nis true, so the theorem is true in this case.  Thus, we may assume that both events have positive \nprobability in what follows. Assume that $E$ and $F$ are independent.  Then $P(E|F) = P(E)$, and so\n\\begin{eqnarray*}\nP(E\\cap F) & = & P(E|F)P(F) \\\\\n       & = & P(E)P(F)\\ .\n\\end{eqnarray*}\n\nAssume next that $P(E\\cap F) = P(E)P(F)$.  Then\n$$\nP(E|F) = \\frac {P(E \\cap F)}{P(F)} = P(E)\\ .\n$$\nAlso,\n$$\nP(F|E) = \\frac {P(F \\cap E)}{P(E)} = P(F)\\ .\n$$\nTherefore, $E$ and $F$ are independent.\n\\end{theorem}\n\n\\begin{example}\\label{exam 4.6}\nSuppose that we have a coin which comes up heads with probability $p$, and tails with probability\n$q$.  Now suppose that this coin is tossed twice.  Using a frequency interpretation of probability, it is reasonable to assign to the\noutcome $(H,H)$ the probability $p^2$, to the outcome $(H, T)$ the probability $pq$, and so on.  \nLet $E$ be the event that heads turns up on the first toss and $F$ the event that tails turns up on\nthe second toss.  We will now check that with the above probability assignments, these two events are\nindependent, as expected.  We have $P(E) = p^2 + pq = p$, $P(F) = pq + q^2 = q$.  Finally $P(E\\cap\nF) = pq$, so $P(E\\cap F) = \\linebreak[4] P(E)P(F)$.  \n\\end{example}\n\n\\begin{example}\\label{exam 4.7}\nIt is often, but not always, intuitively clear when two events are\nindependent.  In Example~\\ref{exam 4.6}, let $A$ be the event ``the\nfirst toss is a head\" and $B$ the event ``the two outcomes are the same.\" Then\n$$\nP(B|A) = \\frac {P(B \\cap A)}{P(A)} = \\frac {P\\{\\mbox {HH}\\}}{P\\{\\mbox {HH,HT}\\}} =\n\\frac {1/4}{1/2} = \\frac 12 = P(B).\n$$\nTherefore, $A$ and $B$ are independent, but the result was not so obvious.\n\\end{example}\n\n\\begin{example}\\label{exam 4.8}\nFinally, let us give an example of two events that are not independent. \nIn Example~\\ref{exam 4.6}, let $I$ be the event ``heads on the first toss\" and $J$\nthe event ``two heads turn up.\"  Then $P(I) = 1/2$ and $P(J) = 1/4$.  The event\n$I \\cap J$ is the event ``heads on both tosses\" and has probability $1/4$. \nThus, $I$ and $J$ are not independent since $P(I)P(J) = 1/8 \\ne P(I \\cap J)$.\n\\end{example}\n\nWe can extend the concept of independence to any finite set of events\n$A_1$,~$A_2$, \\dots,~$A_n$.\n\n\\begin{definition}\\label{def 4.3}\nA set of events $\\{A_1,\\ A_2,\\ \\ldots,\\ A_n\\}$ is said to be \\emx {mutually\nindependent}\\index{independence of events!mutual}\\index{mutually independent events} if for any\nsubset\n$\\{A_i,\\ A_j,\\ldots,\\ A_m\\}$ of these events we have\n$$\nP(A_i \\cap A_j \\cap\\cdots\\cap A_m) = P(A_i)P(A_j)\\cdots P(A_m),\n$$\nor equivalently, if for any sequence $\\bar A_1$,~$\\bar A_2$,\n\\dots,~$\\bar A_n$ with $\\bar A_j = A_j$ or $\\tilde A_j$,\n$$\nP(\\bar A_1 \\cap \\bar A_2 \\cap\\cdots\\cap \\bar A_n) =\nP(\\bar A_1)P(\\bar A_2)\\cdots P(\\bar A_n).\n$$\n(For a proof of the equivalence in the case $n = 3$, \nsee Exercise~\\ref{exer 4.1.31}.)\n\\end{definition}\nUsing this terminology, it is a fact that any sequence  $(\\mbox S,\\mbox S,\\mbox F,\\mbox\nF, \\mbox S, \\dots,\\mbox S)$ of possible outcomes of a Bernoulli trials process forms a sequence of mutually\nindependent events.\n\\par\nIt is natural to ask: If all pairs of a set of events are independent, is the whole set\nmutually independent?  The answer is \\emx {not necessarily,} and an example is given in\nExercise~\\ref{exer 4.1.7}.\n\\par\nIt is important to note that the statement \n$$\nP(A_1 \\cap A_2 \\cap \\cdots \\cap A_n) = P(A_1)P(A_2) \\cdots P(A_n)\n$$\ndoes not imply that the events $A_1$,~$A_2$, \\dots,~$A_n$ are mutually independent (see\nExercise~\\ref{exer 4.1.8}).\n\n\\subsection*{Joint Distribution Functions and Independence of Random Variables}\n\nIt is frequently the case that when an experiment is performed, several different\nquantities concerning the outcomes are investigated.  \n\n\\begin{example}\\label{exam 4.91}\nSuppose we toss a coin three times.  The basic random variable ${\\bar X}$ corresponding\nto this experiment has eight possible outcomes, which are the ordered triples consisting\nof H's and T's.  We can also define the random variable $X_i$, for $i = 1, 2, 3$, to be\nthe outcome of the $i$th toss.  If the coin is fair, then we should assign the probability\n1/8 to each of the eight possible outcomes.  Thus, the distribution functions of $X_1$,\n$X_2$, and $X_3$ are identical; in each case they are defined by $m(H) = m(T) = 1/2$.\n\\end{example}\n\nIf we have several random variables $X_1, X_2, \\ldots, X_n$ which correspond to a given\nexperiment, then we can consider the joint random variable ${\\bar X} = (X_1, X_2,\n\\ldots, X_n)$ defined by taking an outcome $\\omega$ of the experiment, and writing, as an\n$n$-tuple, the corresponding $n$ outcomes for the random variables $X_1, X_2, \\ldots, X_n$. \nThus, if the  random variable $X_i$ has, as its set of possible outcomes the set $R_i$, then\nthe set of possible outcomes of the joint random variable ${\\bar X}$ is the Cartesian\nproduct of the $R_i$'s, i.e., the set of all $n$-tuples of possible outcomes of the $X_i$'s.\n\n\\begin{example}(Example~\\ref{exam 4.91} continued){\\label{exam 4.92}}\nIn the coin-tossing example above, let $X_i$ denote the outcome of the $i$th toss.  Then the\njoint random variable ${\\bar X} = (X_1, X_2, X_3)$ has eight possible outcomes.\n\\par\nSuppose that we now define $Y_i$, for $i = 1, 2, 3$, as the number of heads which occur in\nthe first $i$ tosses.  Then $Y_i$ has $\\{0, 1, \\ldots, i\\}$ as possible outcomes, so at\nfirst glance, the set of possible outcomes of the joint random variable ${\\bar Y} = (Y_1,\nY_2, Y_3)$ should be the set\n$$\\{(a_1, a_2, a_3)\\ :\\ 0 \\le a_1 \\le 1, 0 \\le a_2 \\le 2, 0 \\le a_3 \\le 3\\}\\ .$$\nHowever, the outcome $(1, 0, 1)$ cannot occur, since we must have $a_1 \\le a_2 \\le a_3$.  The\nsolution to this problem is to define the probability of the outcome $(1, 0, 1)$ to be 0.  In addition, we must\nhave $a_{i+1} - a_i \\le 1$ for $i = 1, 2$.\n\\par\nWe now illustrate the assignment of probabilities to the various outcomes for the joint\nrandom variables ${\\bar X}$ and ${\\bar Y}$.  In the first case, each of the\neight outcomes should be assigned the probability 1/8, since we are assuming that we have a\nfair coin.  In the second case, since $Y_i$ has $i+1$ possible outcomes, the set of possible\noutcomes has size 24.    Only eight of these 24 outcomes can actually occur, namely the ones\nsatisfying $a_1 \\le a_2 \\le a_3$.  Each of these outcomes corresponds to exactly one of the\noutcomes of the random variable ${\\bar X}$, so it is natural to assign probability 1/8\nto each of these.  We assign probability 0 to the other 16 outcomes.  In each case, the\nprobability function is called a joint distribution function.\n\\end{example}\n\nWe collect the above ideas in a definition.\n\n\\begin{definition}\\label{def 4.4}\nLet $X_1, X_2, \\ldots, X_n$ be random variables associated with an experiment.  Suppose\nthat the sample space (i.e., the set of possible outcomes) of $X_i$ is the set $R_i$.  Then\nthe joint random variable\\index{random variable!joint}\\index{joint random variable} ${\\bar\nX} = (X_1, X_2,\n\\ldots, X_n)$ is defined to be the random variable whose outcomes consist of ordered $n$-tuples\nof outcomes, with the\n$i$th coordinate lying in the set $R_i$.  The sample space $\\Omega$ of ${\\bar X}$ is the\nCartesian product of the $R_i$'s:  \n$$\\Omega = R_1 \\times R_2 \\times \\cdots \\times R_n\\ .$$\nThe joint distribution function\\index{distribution function!joint}\\index{joint distribution\nfunction} of\n${\\bar X}$ is the function which gives the probability of each of the outcomes of\n${\\bar X}$.\n\\end{definition}\n\n\\begin{example}(Example~\\ref{exam 4.91} continued){\\label{exam 4.93}}\nWe now consider the assignment of probabilities in the above example.  In the case of the\nrandom variable ${\\bar X}$, the probability of any outcome $(a_1, a_2, a_3)$ is just the\nproduct of the probabilities $P(X_i = a_i)$, for $i = 1, 2, 3$.  However, in the case of\n${\\bar Y}$, the probability assigned to the outcome $(1, 1, 0)$ is not the product of\nthe probabilities $P(Y_1 = 1)$, $P(Y_2 = 1)$, and $P(Y_3 = 0)$.  The difference between these\ntwo situations is that the value of $X_i$ does not affect the value of $X_j$, if $i \\ne j$,\nwhile the values of $Y_i$ and $Y_j$ affect one another.  For example, if $Y_1 = 1$, then\n$Y_2$ cannot equal 0.  This prompts the next definition.\n\\end{example}\n\n\\begin{definition}\\label{def 4.4.5}\nThe random variables $X_1$,~$X_2$, \\ldots,~$X_n$ are \\emx {mutually\nindependent}\\index{independence of random variables!mutual}\\index{mutually independent \nrandom\\\\ variables}\\index{random variables!mutual independence of} if\n\\begin{eqnarray*}\n&&P(X_1 = r_1, X_2 = r_2, \\ldots, X_n = r_n)   \\\\\n&& \\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; = P(X_1 = r_1) P(X_2 = r_2) \\cdots  P(X_n = r_n)\n\\end{eqnarray*} \nfor any choice of $r_1, r_2, \\ldots, r_n$.  Thus, if $X_1,~X_2, \\ldots,~X_n$ are mutually\nindependent, then the joint distribution function of the random variable \n$${\\bar X} = (X_1, X_2, \\ldots, X_n)$$\nis just the product of the individual distribution\nfunctions.  When two random\\linebreak[4] variables are mutually independent, we shall say more\nbriefly that they are \\emx { indepen-\\linebreak[4] dent.}\\index{independence of random\\\\\nvariables}\\index{random variables!independence of}\n\\end{definition}\n\n\\begin{example}\\label{exam 4.94} In a group of 60 people, the numbers who do or do not smoke\nand do or do not have cancer are reported as shown in Table~\\ref{table 4.1}.\n\\begin{table}\n\\centering\n\\begin{tabular}{l|cc|c}\n             &\\hspace{.15in}Not smoke\\hspace{.15in}&\\hspace{.15in}Smoke\\hspace{.15in}&\\hspace{.15in}Total\\hspace{.15in}  \\\\ \\hline\n Not cancer  & 40             & 10             & 50 \\\\\n Cancer      & \\hspace{.1in}7 &\\hspace{.075in}3& 10 \\\\ \\hline\n Totals      & 47          & 13     & 60 \\\\\n\\end{tabular}\n\\caption{Smoking and cancer.}\n\\label{table 4.1}\n\\end{table}\nLet $\\Omega$ be the sample space consisting of these 60 people.  A person is chosen at random\nfrom the group.  Let $C(\\omega) = 1$ if this person has cancer and~0 if not, and $S(\\omega) =\n1$ if this person smokes and~0 if not. Then the joint distribution of $\\{C,S\\}$ is given in \nTable~\\ref{table 4.2}.\n\\begin{table}\n\\centering\n\\begin{tabular}{lr|lcr}\n  &    &            &  S      \\\\\n  &    & \\hspace{.15in} 0&  & 1\\hspace{.15in}\\\\ \\hline\n  & 0  &  40/60     &  &10/60  \\\\ \nC &    &            &  &       \\\\\n  & 1  & \\hspace{.1in}7/60  &  &3/60   \\\\\n\\end{tabular}\n\\caption{Joint distribution.}\n\\label{table 4.2}\n\\end{table}\n\\noindent For example $P(C = 0, S = 0) = 40/60$, $P(C = 0, S = 1) = 10/60$, and so forth.  The\ndistributions of the individual random variables are called \\emx {marginal\ndistributions.}\\index{marginal distribution function}\\index{distribution function!marginal}  The\nmarginal distributions of\n$C$ and $S$ are:\n$$ p_C = \\pmatrix{ 0     & 1     \\cr 50/60 & 10/60 \\cr},\n$$\n\n$$ p_S = \\pmatrix{ 0     & 1     \\cr 47/60 & 13/60 \\cr}.\n$$\nThe random variables $S$ and $C$ are not independent, since\n\\begin{eqnarray*}\n P(C = 1,S = 1)   &=& \\frac 3{60} = .05\\ , \\\\\nP(C = 1)P(S = 1) &=& \\frac {10}{60} \\cdot \\frac\n{13}{60} = .036\\ .\n\\end{eqnarray*}\nNote that we would also see this from the fact that\n\\begin{eqnarray*} P(C = 1|S = 1) &=& \\frac 3{13} = .23\\ , \\\\\nP(C = 1) &=& \\frac 16 = .167\\ .\n\\end{eqnarray*}\n\n\\end{example}\n\n\\subsection*{Independent Trials Processes}\n\nThe study of random variables proceeds by considering special classes of random variables. \nOne such class that we shall study is the class of \\emx {independent trials.}\n\n\\begin{definition}\\label{def 5.5} A sequence of random variables $X_1$,~$X_2$, \\dots,~$X_n$\nthat are mutually independent and that have the same distribution is called a sequence of\nindependent trials or an \\emx {independent trials process.}\\index{independent trials process}\n\nIndependent trials processes arise naturally in the following way.  We have a single\nexperiment with sample space $R = \\{r_1,r_2,\\dots,r_s\\}$ and a distribution function\n$$m_X = \\pmatrix{ r_1 & r_2 & \\cdots & r_s \\cr p_1 & p_2 & \\cdots & p_s\\cr}\\ .\n$$\n\nWe repeat this experiment $n$ times.  To describe this total experiment, we choose as sample\nspace the space\n$$\n\\Omega = R \\times R \\times\\cdots\\times R,\n$$ consisting of all possible sequences $\\omega = (\\omega_1,\\omega_2,\\dots,\\omega_n)$ where\nthe value of each $\\omega_j$ is chosen from $R$.  We assign a distribution function to be\nthe \\emx {product distribution}\n$$ m(\\omega) = m(\\omega_1)\\cdot\\ \\ldots\\ \\cdot m(\\omega_n)\\ ,\n$$ \nwith $m(\\omega_j) = p_k$ when $\\omega_j = r_k$.  Then we let $X_j$ denote the $j$th coordinate\nof the outcome $(r_1, r_2, \\ldots, r_n)$.  The random variables\n$X_1$,~\\dots,~$X_n$ form an independent trials process.\n\\end{definition}\n\n\\begin{example}\\label{exam 5.6.1} An experiment consists of rolling a die three times.  Let\n$X_i$ represent the outcome of the $i$th roll, for $i = 1, 2, 3$.  The common distribution\nfunction is\n$$ m_i = \\pmatrix{ 1 & 2 & 3 & 4 & 5 & 6 \\cr 1/6 & 1/6 & 1/6 & 1/6 & 1/6 & 1/6 \\cr}.\n$$\n\nThe sample space is $R^3 = R \\times R \\times R$ with $R = \\{1,2,3,4,5,6\\}$.  If\n$\\omega = (1,3,6)$, then $X_1(\\omega) = 1$, $X_2(\\omega) = 3$, and\n$X_3(\\omega) = 6$ indicating that the first roll was a 1, the second was a 3, and the third\nwas a 6.  The probability assigned to any sample point is\n$$ m(\\omega) = \\frac16 \\cdot \\frac16 \\cdot \\frac16 = \\frac1{216}\\ .\n$$\n\\end{example}\n\n\\begin{example}\\label{exam 5.7} Consider next a Bernoulli trials process with probability $p$\nfor success on each experiment.  Let $X_j(\\omega) = 1$ if the $j$th outcome is success and\n$X_j(\\omega) = 0$ if it is a failure.  Then $X_1$,~$X_2$, \\dots,~$X_n$ is an independent\ntrials process.  Each $X_j$ has the same distribution function\n$$ m_j = \\pmatrix{ 0 & 1 \\cr q & p  \\cr},\n$$ where $q = 1 - p$.\n\nIf $S_n = X_1 + X_2 +\\cdots + X_n$, then\n$$ P(S_n = j) = {n \\choose j} p^{j} q^{n - j}\\ ,  \n$$ and $S_n$ has, as distribution, the binomial distribution $b(n,p,j)$.\n\\end{example}\n\n\\subsection*{Bayes' Formula}     \n\nIn our examples, we have considered conditional probabilities of the following\nform: Given the outcome of the second stage of a two-stage experiment, find the\nprobability for an outcome at the first stage.  We have remarked that these\nprobabilities are called \\emx {Bayes probabilities.}\n\nWe return now to the calculation of more general Bayes probabilities.  Suppose\nwe have a set of events $H_1,$~$H_2$, \\dots,~$H_m$ that are pairwise disjoint\nand such that the sample space $\\Omega$ satisfies the equation\n$$\n\\Omega = H_1 \\cup H_2 \\cup\\cdots\\cup H_m\\ .\n$$\nWe call these events \\emx {hypotheses.}\\index{hypotheses}  We also have an event $E$ that gives us\nsome information about which hypothesis is correct.  We call this event \\emx {evidence.}\n\nBefore we receive the evidence, then, we have a set of \\emx {prior\nprobabilities}\\index{prior probabilities} $P(H_1)$,                \\hfill\\break\n~$P(H_2)$, \\dots,~$P(H_m)$ for the hypotheses. \nIf we know the correct hypothesis, we know the probability for the evidence.  That\nis, we know $P(E|H_i)$ for all $i$.  We want to find the probabilities for the\nhypotheses given the evidence.  That is, we want to find the conditional\nprobabilities $P(H_i|E)$.  These probabilities are called the \\emx {posterior\nprobabilities.}\\index{posterior probabilities}\n\nTo find these probabilities, we write them in the form\n\n\\begin{equation}\nP(H_i|E) = \\frac{P(H_i \\cap E)}{P(E)}\\ . \\label{eq 4.1}\n\\end{equation}\nWe can calculate the numerator from our given information by\n\\begin{equation}\nP(H_i \\cap E) = P(H_i)P(E|H_i)\\ . \\label{eq 4.2}  \n\\end{equation}\nSince one and only one of the events $H_1$,~$H_2$, \\dots,~$H_m$ can occur, we\ncan write the probability of $E$ as\n\n$$\nP(E) = P(H_1 \\cap E)  + P(H_2 \\cap E)  + \\cdots + P(H_m \\cap E)\\ .\n$$\nUsing Equation~\\ref{eq 4.2}, the above expression can be seen to equal\n\n\\begin{equation}\n   P(H_1)P(E|H_1) + P(H_2)P(E|H_2) + \\cdots + P(H_m)P(E|H_m) \\ .\n\\label{eq 4.3}                                               \n\\end{equation}\nUsing (\\ref{eq 4.1}), (\\ref{eq 4.2}), and (\\ref{eq 4.3})\nyields \\emx {Bayes' formula}:\\index{Bayes' formula}\n$$\nP(H_i|E) = \\frac{P(H_i)P(E|H_i)}{\\sum_{k = 1}^m P(H_k)P(E|H_k)}\\ .\n$$\n\nAlthough this is a very famous formula, we will rarely use it.  If the number\nof hypotheses is small, a simple tree measure calculation is easily carried\nout, as we have done in our examples.  If the number of hypotheses is large, then we should\nuse a computer.\n\\par\nBayes probabilities are particularly appropriate for medical diagnosis.  A\ndoctor is anxious to know which of several diseases a patient might have.  She\ncollects evidence in the form of the outcomes of certain tests.  From\nstatistical studies the doctor can find the prior probabilities of the various\ndiseases before the tests, and the probabilities for specific test outcomes,\ngiven a particular disease.  What the doctor wants to know is the posterior\nprobability for the particular disease, given the outcomes of the tests.\n\n\\begin{example}\\label{exam 4.10}\nA doctor is trying to decide if a patient has one of three diseases\n$d_1$,~$d_2$, or~$d_3$.  Two tests are to be carried out, each of which results\nin a positive $(+)$ or a negative $(-)$ outcome.  There are four possible test\npatterns $+{}+$,~$+{}-$, $-{}+$, and~$-{}-$.  National records have indicated\nthat, for 10{,}000 people having one of these three diseases, the distribution of\ndiseases and test results are as in Table~\\ref{table 4.3}.\n\n%\\Mplace{\\Table \\paste{maintab}4 \\endTable}\n\\begin{table}\n\\centering\n\\begin{tabular}{c|c|cccc} \n             & Number having & \\multicolumn{4}{c}{\\underbar{The results}}  \\\\\n  Disease    & this disease\\hspace{.25in} &\\hspace{.2in}+\\hspace{.1in}+\\hspace{.2in}\n&\\hspace{.1in}+\\hspace{.1in}--\\hspace{.2in}&\\hspace{.2in}--\\hspace{.1in}+\\hspace{.2in}\n&\\hspace{.1in}--\\hspace{.1in}--\\hspace{.2in}\\\\ \\hline\n  $ d_{1} $  &\\hspace{.075in}3215&2110            &\\hspace{.15in}301&\\hspace{.1in}704  & \\hspace{.1in}100\\\\\n  $ d_{2} $  &\\hspace{.075in}2125&\\hspace{.1in}396&\\hspace{.15in}132&1187  & \\hspace{.1in}410\\\\\n  $ d_{3} $  &\\hspace{.075in}4660&\\hspace{.1in}510&\\hspace{.075in}3568&\\hspace{.15in}73  & \\hspace{.1in}509\\\\ \\hline\nTotal        &10000  &&&&\\\\ \\hline\n\\end{tabular}\n\\caption{Diseases data.}\n\\label{table 4.3}\n\\end{table}\n\nFrom this data, we can estimate the prior probabilities for each of the\ndiseases and, given a particular disease, the probability of a particular test\noutcome.  For example, the prior probability of disease $d_1$ may be estimated\nto be $3215/10{,}000 = .3215$.  The probability of the test result $+{}-$, given\ndisease $d_1$, may be estimated to be $301/3215 = .094$.\n\\par\nWe can now use Bayes' formula to compute various posterior probabilities.  The\ncomputer program {\\bf Bayes}\\index{Bayes (program)} computes these posterior probabilities.  The\nresults for this example are shown in Table~\\ref{table 4.35}.\n\n\n\\begin{table}\n\\centering\n\\begin{tabular}{lccc}\n                                    &  $d_1$ &  $d_2$ &  $d_3$  \\\\\n+\\hspace{.1in}+                     & .700   & .131   & .169    \\\\\n+\\hspace{.125in}--                    & .075   & .033   & .892    \\\\\n\\hspace{.025in}--\\hspace{.125in}+     &\n.358   & .604   & .038    \\\\\n\\hspace{.025in}--\\hspace{.15in}--  &\n.098   & .403   & .499    \\\\\n\\end{tabular}\n\\caption{Posterior probabilities.}\n\\label{table 4.35}\n\\end{table}\nWe note from the outcomes that, when the test result is $++$, the disease $d_1$\nhas a significantly higher probability than the other two.  When the outcome is $+-$,\nthis is true for disease $d_3$.  When the outcome is $-+$, this is true for disease $d_2$.\nNote that these statements might have been guessed by looking at the data. If the outcome is $--$, \nthe most probable cause is $d_3$, but the probability that a patient has $d_2$ is only slightly smaller.\nIf one looks at the data in this case, one can see that it might be hard to guess which of the two\ndiseases $d_2$ and $d_3$ is more likely.\n\\end{example}\n \nOur final example shows that one has to be careful when the prior probabilities\nare small.\n\n\\begin{example}\\label{exam 4.11}\nA doctor gives a patient a test for a particular cancer\\index{cancer}.  Before the results of\nthe test, the only evidence the doctor has to go on is that 1 woman in~1000 has\nthis cancer.  Experience has shown that, in 99 percent of the cases in which\ncancer is present, the test is positive; and in 95 percent of the cases in\nwhich it is not present, it is negative.  If the test turns out to be positive,\nwhat probability should the doctor assign to the event that cancer is present? \nAn alternative form of this question is to ask for the relative frequencies of false \npositives and cancers.\n\nWe are given that %${\\rm prior(cancer)} = .001$ and\n$\\mbox{prior(cancer)} = .001$ and\n$\\mbox{prior(not\\ cancer)} = .999$.  We know also that $P(+| \\mbox{cancer}) =\n.99$, $P(-|\\mbox{cancer}) = .01$, $P(+|\\mbox{not\\ cancer}) = .05$, and\n$P(-|\\mbox{not\\ cancer}) = .95$.  Using this data gives the result shown in\nFigure~\\ref{fig 4.5}.\n\n\\putfig{5truein}{PSfig4-5}{Forward and reverse tree diagrams.}{fig 4.5}\n\nWe see now that the probability of cancer given a positive test has only\nincreased from .001 to .019.  While this is nearly a twenty-fold increase, the\nprobability that the patient has the cancer is still small.  Stated in another way,\namong the positive results, 98.1 percent are false positives, and 1.9 percent are \ncancers.  When a group of second-year medical students was asked this question, over half of the\nstudents incorrectly guessed the probability to be greater than .5.  \n\\end{example}\n\n\\subsection*{Historical Remarks}\n\nConditional probability was used long before it was formally defined.  Pascal and Fermat\nconsidered the \\emx {problem of points}:\\index{problem of points} given that team A has won $m$\ngames and team B has won $n$ games, what is the probability that A will win the series?  (See\nExercises~\\ref{exer 5.1.11}--\\ref{exer 5.1.13}.)  This is clearly a conditional probability\nproblem.  \n\\par\nIn his book,  Huygens\\index{HUYGENS, C.} gave a number of problems, one of which was:\n\\begin{quote}\n\\indent Three gamblers, A, B and C, take 12 balls of which 4 are white and 8\nblack.  They play with the rules that the drawer is blindfolded, A is to draw\nfirst, then B and then C, the winner to be the one who first draws a white\nball.  What is the ratio of their chances?\\footnote{Quoted in F.~N. David,\n\\emx {Games, Gods and Gambling} (London: Griffin, 1962), p.~119.}\n\\end{quote}\n\\par\nFrom his answer it is clear that Huygens meant that each ball is replaced after\ndrawing.  However, John Hudde\\index{HUDDE, J.}, the mayor of Amsterdam, assumed that he meant to\nsample without replacement and corresponded with Huygens about the difference\nin their answers.  Hacking remarks that ``Neither party can understand what the\nother is doing.\"\\index{HACKING, I.}\\footnote{I.~Hacking, \\emx {The Emergence of Probability}\n(Cambridge: Cambridge University Press, 1975), p.~99.}\n\\par\nBy the time of de~Moivre's\\index{de MOIVRE, A.} book, \\emx {The Doctrine of Chances,} these\ndistinctions were well understood.  De~Moivre defined independence and\ndependence as follows:\n\\begin{quote}\n\\indent Two Events are independent, when they have no connexion one with the\nother, and that the happening of one neither forwards nor obstructs the\nhappening of the other.\n\\par\nTwo Events are dependent, when they are so connected together as that the\nProbability of either's happening is altered by the happening of the\nother.\\footnote{A.~de~Moivre, \\emx {The Doctrine of Chances,} 3rd~ed. (New York:\nChelsea, 1967), p.~6.}\n\\end{quote}\n\nDe~Moivre used sampling with and without replacement to illustrate that the\nprobability that two independent events both happen is the product of their\nprobabilities, and for dependent events that:\n\\begin{quote}\nThe Probability of the happening of two Events dependent, is the product of the\nProbability of the happening of one of them, by the Probability which the other\nwill have of happening, when the first is considered as having happened; and\nthe same Rule will extend to the happening of as many Events as may be\nassigned.\\footnote{ibid, p.~7.}\n\\end{quote}\n\\par\nThe formula that we call Bayes' formula, and the idea of computing the\nprobability of a hypothesis given evidence, originated in a famous essay of\nThomas Bayes\\index{BAYES, T.}.  Bayes was an ordained minister in Tunbridge Wells near London. \nHis mathematical interests led him to be elected to the Royal Society in~1742,\nbut none of his results were published within his lifetime.  The work upon\nwhich his fame rests, ``An Essay Toward Solving a Problem in the Doctrine of\nChances,\" was published in~1763, three years after his\ndeath.\\footnote{T.~Bayes, ``An Essay Toward Solving a Problem in the Doctrine\nof Chances,\" \\emx {Phil.\\ Trans.\\ Royal Soc.\\ London,} vol.~53 (1763),\npp.~370--418.}  Bayes reviewed some of the basic concepts of probability and\nthen considered a new kind of inverse probability problem requiring the use of\nconditional probability.\n\\par\nBernoulli\\index{BERNOULLI, J.}, in his study of processes that we now call Bernoulli trials, had\nproven his famous law of large numbers which we will study in Chapter~\\ref{chp\n8}.  This theorem assured the experimenter that if he knew the probability $p$\nfor success, he could predict that the proportion of successes would approach\nthis value as he increased the number of experiments.  Bernoulli himself\nrealized that in most interesting cases you do not know the value of $p$ and\nsaw his theorem as an important step in showing that you could determine $p$ by\nexperimentation.\n\\par\nTo study this problem further, Bayes started by assuming that the probability\n$p$ for success is itself determined by a random experiment.  He assumed in\nfact that this experiment was such that this value for $p$ is equally likely to\nbe any value between 0 and 1.\\choice{\\footnote{Bayes is using continuous\nprobabilities as discussed in Chapter 2 of the complete Grinstead-Snell book.}}{}  Without knowing this value we\ncarry out\n$n$ experiments and observe $m$ successes.  Bayes proposed the problem of finding\nthe conditional probability that the unknown probability $p$ lies between $a$\nand $b$.  He obtained the answer:\n$$\nP(a \\leq p < b | m {\\mbox{\\,\\,successes\\,\\, in}}\\,\\,n \\,\\,{\\mbox{trials}}) \n= \\frac {\\int_a^b x^m(1 - x)^{n - m}\\,dx}{\\int_0^1 x^m(1 - x)^{n - m}\\,dx}\\ .\n$$\n\\par\n\\choice{}{We shall see in the next section how this result is obtained.}  Bayes clearly\nwanted to show that the conditional distribution function, given the outcomes of\nmore and more experiments, becomes concentrated around the true value of $p$. \nThus, Bayes was trying to solve an \\emx {inverse problem.}  The computation of\nthe integrals was too difficult for exact solution except for small values\nof~$j$ and~$n$, and so Bayes tried approximate methods.  His methods were not\nvery satisfactory and it has been suggested that this discouraged him from\npublishing his results.\n\\par\nHowever, his paper was the first in a series of important studies carried out\nby Laplace, Gauss, and other great mathematicians to solve inverse problems. \nThey studied this problem in terms of errors in measurements in astronomy.  If\nan astronomer were to know the true value of a distance and the nature of the\nrandom errors caused by his measuring device he could predict the probabilistic\nnature of his measurements.  In fact, however, he is presented with the inverse\nproblem of knowing the nature of the random errors, and the values of the\nmeasurements, and wanting to make inferences about the unknown true value.\n\\par\nAs Maistrov remarks, the formula that we have called Bayes' formula does not\nappear in his essay.  Laplace gave it this name when he studied these inverse\nproblems.\\index{MAISTROV, L.}\\footnote{L.~E. Maistrov, \\emx {Probability Theory: A Historical\nSketch,} trans.~and ed.~Samual Kotz (New York: Academic Press, 1974), p.~100.}\nThe computation of inverse probabilities is fundamental to statistics and has\nled to an important branch of statistics called Bayesian analysis, assuring\nBayes eternal fame for his brief essay.\n\n\\exercises\n\\begin{LJSItem}\n\n\\i\\label{exer 4.1.1} Assume that $E$ and $F$ are two events with positive\nprobabilities.  Show that if $P(E|F) = P(E)$, then $P(F|E) = P(F)$.\n\n\\i\\label{exer 4.1.2} A coin is tossed three times.  What is the probability that exactly two\nheads occur, given that\n\\begin{enumerate}\n\\item the first outcome was a head?\n\n\\item the first outcome was a tail?\n\n\\item the first two outcomes were heads?\n\n\\item the first two outcomes were tails?\n\n\\item the first outcome was a head and the third outcome was a head?\n\\end{enumerate}\n\n\\i\\label{exer 4.1.3} A die is rolled twice.  What is the probability that the sum of the faces\nis greater than 7, given that\n\\begin{enumerate}\n\\item the first outcome was a 4?\n\n\\item the first outcome was greater than 3?\n\n\\item the first outcome was a 1?\n\n\\item the first outcome was less than 5?\n\\end{enumerate}\n\n\\i\\label{exer 4.1.4} A card is drawn at random from a deck of cards.  What is the probability\nthat\n\\begin{enumerate}\n\\item it is a heart, given that it is red?\n\n\\item it is higher than a 10, given that it is a heart? (Interpret J,~Q, K,~A\nas 11,~12, 13,~14.)\n\n\\item it is a jack, given that it is red?\n\\end{enumerate} \n\n\\i\\label{exer 4.1.5} A coin is tossed three times.  Consider the following events\\newline\n$A$: Heads on the first toss.\\newline\n$B$: Tails on the second.\\newline\n$C$: Heads on the third toss.\\newline\n$D$: All three outcomes the same (HHH or TTT).\\newline\n$E$: Exactly one head turns up.\n\\begin{enumerate}\n\\item Which of the following pairs of these events are independent?\\newline\n(1) $A$, $B$\\newline\n(2) $A$, $D$\\newline\n(3) $A$, $E$\\newline\n(4) $D$, $E$\n\n\\item Which of the following triples of these events are \nindependent?\\newline\n(1) $A$, $B$, $C$\\newline\n(2) $A$, $B$, $D$\\newline\n(3) $C$, $D$, $E$\n\\end{enumerate}\n\n\\i\\label{exer 4.1.6} From a deck of five cards numbered 2,~4, 6, 8, and~10, respectively, a\ncard is drawn at random and replaced.  This is done three times.  What is the\nprobability that the card numbered 2 was drawn exactly two times, given that\nthe sum of the numbers on the three draws is~12?\n\n\\i\\label{exer 4.1.7} A coin is tossed twice.  Consider the\nfollowing events.\\newline\n$A$: Heads on the first toss.\\newline\n$B$: Heads on the second toss.\\newline\n$C$: The two tosses come out the same.\n\\begin{enumerate}\n\\item Show that $A$,~$B$,~$C$ are pairwise independent but not\nindependent.\n\n\\item Show that $C$ is independent of $A$ and $B$ but not of $A \\cap B$.\n\\end{enumerate}\n\n\\i\\label{exer 4.1.8} Let $\\Omega = \\{a,b,c,d,e,f\\}$.  Assume that $m(a) = m(b) = 1/8$ and\n$m(c) = m(d) = m(e) = m(f) = 3/16$.  Let $A$,~$B$, and~$C$ be the events $A = \\{d,e,a\\}$, \n$B = \\{c,e,a\\}$, $C = \\{c,d,a\\}$.  Show that $P(A \\cap B \\cap C) = P(A)P(B)P(C)$ but no two of these\nevents are independent.\n \n\\i\\label{exer 4.1.9} What is the probability that a family of two children has\n\\begin{enumerate}\n\\item two boys given that it has at least one boy?\n\n\\item two boys given that the first child is a boy?\n\\end{enumerate}\n\n\\i\\label{exer 4.1.9.5}  In Example~\\ref{exam 4.1.5}, we used the Life Table (see Appendix~C)\nto compute a conditional probability.  The number 93{,}753 in the table, corresponding to\n40-year-old males, means that of all the males born in the United States in 1950, 93.753\\% were\nalive in 1990.  Is it reasonable to use this as an estimate for the probability of a male, born\nthis year, surviving to age 40? \n\n\\i\\label{exer 4.1.9.6} Simulate the Monty Hall problem.  Carefully state any assumptions\nthat you have made when writing the program.  Which version of the problem do you think that\nyou are simulating?\n\n\\i\\label{exer 4.1.10} In Example~\\ref{exam 4.11}, how large must the prior probability of\ncancer be to give a posterior probability of .5 for cancer given a positive\ntest?\n\n\\i\\label{exer 4.1.11} Two cards are drawn from a bridge deck.  What is the probability that\nthe second card drawn is red?\n\n\\i\\label{exer 4.1.12} If $P(\\tilde B) = 1/4$ and $P(A|B) = 1/2$, what is $P(A \\cap B)$?\n\n\\i\\label{exer 4.1.13}\n\\begin{enumerate} \n\\item What is the probability that your bridge partner has exactly two aces,\ngiven that she has at least one ace?\n\n\\item What is the probability that your bridge partner has exactly two aces,\ngiven that she has the ace of spades?\n\\end{enumerate}\n\n\\i\\label{exer 4.1.14} Prove that for any three events $A$,~$B$,~$C$, each having positive\nprobability, and with the property that $P(A \\cap B) > 0$,\n$$\nP(A \\cap B \\cap C) = P(A)P(B|A)P(C|A \\cap B)\\ .\n$$\n\n\\i\\label{exer 4.1.15} Prove that if $A$ and $B$ are independent so are\n\\begin{enumerate}\n\\item $A$ and $\\tilde B$.\n\n\\item $\\tilde A$ and $\\tilde B$.\n\\end{enumerate}\n\n\\i\\label{exer 4.1.16} A doctor assumes that a patient has one of three diseases $d_1$,~$d_2$,\nor~$d_3$.  Before any test, he assumes an equal probability for each disease. \nHe carries out a test that will be positive with probability .8 if the patient\nhas $d_1$, .6 if he has disease $d_2$, and .4 if he has disease $d_3$.  Given that\nthe outcome of the test was positive, what probabilities should the doctor now\nassign to the three possible diseases?\n\n\\i\\label{exer 4.1.17} In a poker hand, John has a very strong hand and bets 5 dollars.  The\nprobability that Mary has a better hand is .04.  If Mary had a better hand she\nwould raise with probability .9, but with a poorer hand she would only raise\nwith probability .1.  If Mary raises, what is the probability that she has a\nbetter hand than John does?\n\n\\i\\label{exer 4.1.18} The Polya urn model\\index{Polya urn model} for contagion is as follows: We\nstart with an urn which contains one white ball and one black ball.  At each\nsecond we choose a ball at random from the urn and replace this ball and add one\nmore of the color chosen.  Write a program to simulate this model, and see if\nyou can make any predictions about the proportion of white balls in the urn\nafter a large number of draws.  Is there a tendency to have a large fraction of\nballs of the same color in the long run?\n\n\\i\\label{exer 4.1.19} It is desired to find the probability that in a bridge deal each player\nreceives an ace.  A student argues as follows.  It does not matter where the\nfirst ace goes.  The second ace must go to one of the other three players and\nthis occurs with probability 3/4.  Then the next must go to one of two, an\nevent of probability 1/2, and finally the last ace must go to the player who\ndoes not have an ace.  This occurs with probability 1/4.  The probability that\nall these events occur is the product $(3/4)(1/2)(1/4) = 3/32$.  Is this\nargument correct?\n\n\\i\\label{exer 4.1.20} One coin in a collection of 65 has two heads.  The rest are fair.  If a\ncoin, chosen at random from the lot and then tossed, turns up heads 6 times in\na row, what is the probability that it is the two-headed coin?\n\n\\i\\label{exer 4.1.21} You are given two urns and fifty balls.  Half of the balls are white and\nhalf are black.  You are asked to distribute the balls in the urns with no\nrestriction placed on the number of either type in an urn.  How should you\ndistribute the balls in the urns to maximize the probability of obtaining a\nwhite ball if an urn is chosen at random and a ball drawn out at random? \nJustify your answer.\n\n\\i\\label{exer 4.1.22} A fair coin is thrown $n$ times.  Show that the conditional probability\nof a head on any specified trial, given a total of $k$ heads over the $n$\ntrials, is $k/n$ $(k > 0)$.\n\n\\i\\label{exer 4.1.23} (Johnsonbough\\index{JOHNSONBOUGH, R.}\\footnote{R. Johnsonbough, ``Problem\n\\#103,\" \\emx {Two Year College Math Journal,} vol.~8 (1977), p.~292.})  A coin with probability\n$p$ for heads is tossed $n$ times.  Let $E$ be the event ``a head is obtained on the\nfirst toss' and $F_k$ the event `exactly $k$ heads are obtained.\"  For which\npairs $(n,k)$ are $E$ and $F_k$ independent?\n\n\\i\\label{exer 4.1.24} Suppose that $A$ and $B$ are events such that $P(A|B) = P(B|A)$ and $P(A\n\\cup B) = 1$ and $P(A \\cap B) > 0$.  Prove that $P(A) > 1/2$.\n\n\\i\\label{exer 4.1.25} (Chung\\index{CHUNG, K. L.}\\footnote{K. L. Chung, \\emx {Elementary\nProbability Theory With Stochastic Processes, 3rd ed.} (New York:  Springer-Verlag, 1979), p.~152.})\nIn London, half of the days have some rain.  The weather forecaster is correct 2/3 of the time,\ni.e., the probability that it rains, given that she has predicted rain, and the probability that it\ndoes not rain, given that she has predicted that it won't rain, are both equal to 2/3.  When rain is\nforecast, Mr.\\ Pickwick\\index{Pickwick, Mr.} takes his umbrella.  When rain is not forecast, he\ntakes it with probability 1/3.  Find\n\\begin{enumerate}\n\\item the probability that Pickwick has no umbrella, given that it rains.\n\n\\item the probability that he brings his umbrella, given that it doesn't rain.\n\\end{enumerate}\n\n\\i\\label{exer 4.1.26} Probability theory was used in a famous court\ncase: \\emx {People v. Collins.}\\index{Collins, People v.}\\index{People v. Collins}\\footnote{M.~W.\nGray, ``Statistics and the Law,\" \\emx {Mathematics Magazine,} vol.~56 (1983), pp.~67--81.}  In\nthis case a purse was snatched from an elderly person in a Los Angeles suburb.  A couple seen\nrunning from the scene were described as a black man with a beard\\index{beard} and a\nmustache\\index{mustache} and a blond girl with hair in a ponytail\\index{ponytail}.  Witnesses said\nthey drove off in a partly yellow car.  Malcolm and Janet Collins were arrested.  He was black and\nthough clean shaven when arrested had evidence of recently having had a beard\nand a mustache.  She was blond and usually wore her hair in a ponytail.  They\ndrove a partly yellow Lincoln.  The prosecution called a professor of mathematics\nas a witness who suggested that a conservative set of probabilities for the\ncharacteristics noted by the witnesses would be as shown in Table~\\ref{table 4.4}.\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{lc}\n{\\rm man with mustache}    & 1/4          \\cr\n{\\rm girl with blond hair} & 1/3          \\cr\n{\\rm girl with ponytail}   & 1/10         \\cr\n{\\rm black man with beard} & 1/10          \\cr\n{\\rm interracial couple in a car} & 1/1000 \\cr\n{\\rm partly yellow car}    & 1/10    \\cr\n\\end{tabular}\n\\caption{Collins case probabilities.}\n\\label{table 4.4}\n\\end{table}\n\\par\nThe prosecution then argued that the probability that all of these\ncharacteristics are met by a randomly chosen couple is the product of the\nprobabilities or 1/12{,}000{,}000, which is very small.  He claimed this was proof\nbeyond a reasonable doubt that the defendants were guilty.  The jury agreed\nand handed down a verdict of guilty of second-degree robbery.\n\nIf you were the lawyer for the Collins couple how would you have countered the\nabove argument?  (The appeal of this case is discussed in \nExercise~\\ref{sec 5.1}.\\ref{exer 9.2.23}.)\n\n\\i\\label{exer 4.1.27} A student is applying to Harvard and Dartmouth.  He estimates that he\nhas a probability of .5 of being accepted at Dartmouth and .3 of being accepted at\nHarvard.  He further estimates the probability that he will be accepted by both\nis .2.  What is the probability that he is accepted by Dartmouth if he is\naccepted by Harvard?  Is the event ``accepted at Harvard\" independent of the\nevent ``accepted at Dartmouth\"?\n\n\\i\\label{exer 4.1.28} Luxco, a wholesale lightbulb manufacturer, has two factories.  Factory A\nsells bulbs in lots that consists of 1000 regular and 2000 \\emx {softglow}\nbulbs each.  Random sampling has shown that on the average there tend to be\nabout 2 bad regular bulbs and 11 bad softglow bulbs per lot.  At factory B the\nlot size is reversed---there are 2000 regular and 1000 softglow per lot---and\nthere tend to be 5 bad regular and 6 bad softglow bulbs per lot.\n\nThe manager of factory A asserts, ``We're obviously the better producer; our\nbad bulb rates are .2 percent and .55 percent compared to B's .25 percent and\n.6 percent.  We're better at both regular and softglow bulbs by half of a tenth\nof a percent each.\"\n\n``Au contraire,\" counters the manager of B, ``each of our 3000 bulb lots\ncontains only 11 bad bulbs, while A's 3000 bulb lots contain 13.  So our .37\npercent bad bulb rate beats their .43 percent.\"\n\\par\nWho is right?\n\n\\i\\label{exer 4.1.29} Using the Life Table for 1981 given in Appendix~C, find the\nprobability that a male of age~60 in 1981 lives to age~80.  Find the same\nprobability for a female.\n\n\\i\\label{exer 4.1.30}\n\\begin{enumerate}\n\\item There has been a blizzard and Helen is trying to drive from Woodstock\\index{Woodstock}\nto Tunbridge\\index{Tunbridge}, which are connected like the top graph in Figure~\\ref{fig\n4.51}.  Here $p$ and $q$ are the probabilities that the two roads are passable.  What\nis the probability that Helen can get from Woodstock to Tunbridge?\n\n\\item Now suppose that Woodstock and Tunbridge are connected like the middle graph \nin Figure~\\ref{fig 4.51}.\nWhat now is the probability that she can get from $W$ to $T$?  Note that if we\nthink of the roads as being components of a system, then in\n(a) and (b) we have computed the\n\\emx {reliability}\\index{reliability of a system} of a system whose components are (a)~\\emx {in\nseries} and (b)~\\emx {in parallel.}\n\n\\item Now suppose $W$ and $T$ are connected like the bottom graph in Figure~\\ref{fig 4.51}.\nFind the probability of Helen's getting from $W$ to $T$.  \\emx {Hint}: If the\nroad from $C$ to $D$ is impassable, it might as well not be there at all; if it\nis passable, then figure out how to use part (b) twice.\n\\end{enumerate}\n\n\\putfig{3.5truein}{PSfig4}{From Woodstock to Tunbridge.}{fig 4.51} %%3.5truein\n\n\n\\i\\label{exer 4.1.31} Let $A_1$,~$A_2$, and $A_3$ be events, and let $B_i$ represent\neither $A_i$ or its complement $\\tilde A_i$.  Then there are eight possible choices for the\ntriple $(B_1, B_2, B_3)$.  Prove that the events $A_1$,~$A_2$,~$A_3$ are independent if and\nonly if $$P(B_1 \\cap B_2 \\cap B_3) = P(B_1)P(B_2)P(B_3)\\ ,$$\nfor all eight of the possible choices for the triple $(B_1, B_2, B_3)$.\n\n\\i\\label{exer 5.1.4} Four women, A,~B, C, and~D, check their hats, and the hats are returned\nin a random manner.  Let $\\Omega$ be the set of all possible permutations of A,~B, C,~D.  Let\n$X_j = 1$ if the $j$th woman gets her own hat back and 0 otherwise.  What is the\ndistribution of $X_j$?  Are the $X_i$'s mutually independent?\n\n\\i\\label{exer 5.1.5} A box has numbers from 1 to 10.  A number is drawn at random.  Let\n$X_1$ be the number drawn.  This number is replaced, and the ten numbers mixed.  A second\nnumber $X_2$ is drawn.  Find the distributions of $X_1$ and $X_2$.  Are\n$X_1$ and $X_2$ independent?  Answer the same questions if the first number is not replaced\nbefore the second is drawn.\n\n\\i\\label{exer 5.1.6} A die is thrown twice.  Let $X_1$ and $X_2$ denote the outcomes. \nDefine $X = \\min(X_1, X_2)$.  Find the distribution of $X$.\n\n\\istar\\label{exer 5.1.7} \\begin{sloppypar} Given that $P(X = a) = r$, $P(\\max(X,Y) = a) = s$,\nand  \n$P(\\min(X,Y) = a) = t$, show that you can determine $u = P(Y = a)$ in terms of $r$,~$s$,\nand~$t$.\\end{sloppypar}\n\n\\i\\label{exer 5.1.8} A fair coin is tossed three times.  Let $X$ be the number of heads that\nturn up on the first two tosses and $Y$ the number of heads that turn up on the third toss. \nGive the distribution of\n\\begin{enumerate}\n\\item the random variables $X$ and $Y$.\n\n\\item the random variable $Z = X + Y$.\n\n\\item the random variable $W = X - Y$.\n\\end{enumerate}\n\n\\i\\label{exer 5.1.10} Assume that the random variables $X$ and $Y$ have the joint distribution\ngiven in Table~\\ref{table 4.5}.\n\\begin{table}\n\\centering\n\\begin{tabular}{lr|rrrrr} \n     &     &  $Y$  &       &        &        \\\\\n     &     &   -1  &  0    &  1     &  2     \\\\ \\hline\n$X$  & -1  &   0   & 1/36  &  1/6   & 1/12   \\\\\n     &  0  & 1/18  &  0    &  1/18  &  0     \\\\\n     &  1  &   0   & 1/36  &  1/6   & 1/12   \\\\\n     &  2  & 1/12  &  0    &  1/12  & 1/6    \\\\\n\\end{tabular}\n\\caption{Joint distribution.}\n\\label{table 4.5}\n\\end{table}\n\n\\begin{enumerate}\n\\item What is $P(X \\geq 1\\ \\mbox {and\\ } Y \\leq 0)$?\n\n\\item What is the conditional probability that $Y \\leq 0$ given that $X = 2$?\n\n\\item Are $X$ and $Y$ independent?\n\n\\item What is the distribution of $Z = XY$?\n\\end{enumerate}\n\n\\i\\label{exer 5.1.11} In the \\emx {problem of points}\\index{problem of points}, discussed in \nthe historical remarks in Section~\\ref{sec 3.2}, two players, A and B, play a series of points in a\ngame with player A winning each point with probability $p$ and player B winning each point with\nprobability\n$q = 1 - p$.  The first player to win $N$ points wins the game.  Assume that $N = 3$.  Let $X$\nbe a random variable that has the value~1 if player A wins the series and 0 otherwise.  Let\n$Y$ be a random variable with value the number of points played in a game.  Find the\ndistribution of $X$ and $Y$ when $p = 1/2$.  Are $X$ and $Y$ independent in this case?  Answer\nthe same questions for the case $p = 2/3$.\n\n\\i\\label{exer 5.1.12} The letters between Pascal\\index{PASCAL, B.} and Fermat\\index{FERMAT, P.}, which\nare often credited with having started probability theory, dealt mostly with the \\emx {problem of\npoints} described in Exercise~\\ref{exer 5.1.11}.  Pascal and Fermat considered the problem of\nfinding a fair division of stakes if the game must be called off when the first player has won\n$r$ games and the second player has won $s$ games, with $r < N$ and $s < N$.  Let $P(r,s)$ be the\nprobability that player A wins the game if he has already won $r$ points and player B has won\n$s$ points.  Then\n\\begin{enumerate}\n\\item $P(r,N) = 0$ if $r < N$,\n\\item $P(N,s) = 1$ if $s < N$,\n\\item $P(r,s) = pP(r + 1,s) + qP(r,s + 1)$ if $r < N$ and $s < N$;\n\\end{enumerate} and (1),~(2), and~(3) determine $P(r,s)$ for $r \\leq N$ and $s \\leq N$.  Pascal\nused these facts to find $P(r,s)$ by working backward: He first obtained $P(N - 1,j)$ for $j =\nN - 1$,~$N - 2$, \\dots,~0; then, from these values, he obtained\n$P(N - 2,j)$ for $j = N - 1$,~$N - 2$, \\dots,~0 and, continuing backward, obtained all the\nvalues $P(r,s)$.  Write a program to compute $P(r,s)$ for given $N$,~$a$, $b$, and~$p$.  \\emx {\nWarning}: Follow Pascal and you will be able to run $N = 100$; use recursion and you will\nnot be able to run $N = 20$.\n\n\\i\\label{exer 5.1.13} Fermat solved the \\emx {problem of points} (see Exercise~\\ref{exer\n5.1.11}) as follows: He realized that the problem was difficult because the possible ways the\nplay might go are not equally likely.  For example, when the first player needs two more games\nand the second needs three to win, two possible ways the series might go for the first player\nare WLW and LWLW.  These sequences are not equally likely.  To avoid this difficulty, Fermat\nextended the play, adding fictitious plays so that the series went the maximum number of games\nneeded (four in this case).  He obtained equally likely outcomes and used, in effect, the\nPascal triangle to calculate $P(r,s)$.  Show that this leads to a \\emx {formula} for $P(r,s)$\neven for the case $p \\ne 1/2$.\n\n\\i\\label{exer 5.1.14} The Yankees are playing the Dodgers in a world series.  The Yankees win\neach game with probability .6.  What is the probability that the Yankees win the series?  (The\nseries is won by the first team to win four games.)\n\n\\i\\label{exer 5.1.15} C.~L. Anderson\\index{ANDERSON, C. L.}\\footnote{C.~L. Anderson, ``Note on the\nAdvantage of First Serve,\" \\emx {Journal of Combinatorial Theory,} Series~A, vol.~23 (1977),\np.~363.} has used Fermat's argument for the \\emx {problem of points} to prove the following result\ndue to J.~G. Kingston\\index{KINGSTON, J. G.}.  You are playing the \\emx {game of points} (see\nExercise~\\ref{exer 5.1.11}) but, at each point, when you serve you win with probability $p$, and\nwhen your opponent serves you win with probability $\\bar{p}$.  You will serve first, but you\ncan choose one of the following two conventions for serving: for the first convention you\nalternate service (tennis)\\index{tennis}, and for the second the person serving continues to serve\nuntil he loses a point and then the other player serves (racquetball)\\index{racquetball}.  The\nfirst player to win $N$ points wins the game.  The problem is to show that the probability of\nwinning the game is the same under either convention.\n\\begin{enumerate}\n\n\\item Show that, under either convention, you will serve at most $N$ points and your opponent\nat most $N - 1$ points.\n\n\\item Extend the number of points to $2N - 1$ so that you serve $N$ points and your opponent\nserves $N - 1$.  For example, you serve any additional points necessary to make $N$ serves and\nthen your opponent serves any additional points necessary to make him serve $N - 1$ points. \nThe winner is now the person, in the extended game, who wins the most points.  Show that\nplaying these additional points has not changed the winner.\n\n\\item Show that (a) and (b) prove that you have the same probability of winning the game under\neither convention.\n\\end{enumerate}\n\n\\i\\label{exer 5.1.15.5}\nIn the previous problem, assume that $p = 1 - \\bar{p}$.\n\\begin{enumerate}\n\\item  Show that under either service convention, the first player will win more often than the second\nplayer if and only if $p > .5$.\n\\item\nIn volleyball,\\index{volleyball} a team can only win a point while it is serving.  Thus, any\nindividual ``play\" either ends with a point being awarded to the serving team or with the service\nchanging to the other team.  The first team to win $N$ points wins the game.  (We ignore here the \nadditional restriction that the winning team must be ahead by at least two points at the end of the\ngame.)  Assume that each team has the same probability of winning the play when it is serving, i.e., \nthat $p = 1 - \\bar{p}$.  Show that in this case, the team that serves first will win more than half the\ntime, as long as $p > 0$.  (If $p = 0$, then the game never ends.)  \\emx {Hint}: Define $p'$ to be\nthe probability that a team wins the next point, given that it is serving.  If we write $q = 1 -\np$, then one can show that \n$$p' = \\frac p{1-q^2}\\ .$$\nIf one now considers this game in a slightly different way, one can see that the second service\nconvention in the preceding problem can be used, with $p$ replaced by $p'$.\n\\end{enumerate} \n\n\\i\\label{exer 5.1.19} A poker hand consists of 5 cards dealt from a deck of 52 cards.  Let $X$\nand $Y$ be, respectively, the number of aces and kings in a poker hand.  Find the joint\ndistribution of $X$ and $Y$.\n\n\\i\\label{exer 5.1.24.5} Let $X_1$ and $X_2$ be independent random variables and let $Y_1 =\n\\phi_1(X_1)$ and $Y_2 = \\phi_2(X_2)$.\n\\begin{enumerate}\n\n\\item Show that\n$$ P(Y_1 = r, Y_2 = s) = \\sum_{\\phi_1(a) = r \\atop \\phi_2(b) = s} P(X_1 = a, X_2 = b)\\ .\n$$\n\n\\item Using (a), show that $P(Y_1 = r, Y_2 = s) = P(Y_1 = r)P(Y_2 = s)$ so that $Y_1$ and\n$Y_2$ are independent.\n\\end{enumerate}\n\n\\i\\label{exer 4.1.32} Let $\\Omega$ be the sample space of an experiment.  Let $E$ be an\nevent with $P(E) > 0$ and define $m_E(\\omega)$ by\n$m_E(\\omega) = m(\\omega|E)$.  Prove that $m_E(\\omega)$ is a distribution function on\n$E$, that is, that $m_E(\\omega) \\geq 0$ and that $\\sum_{\\omega\\in\\Omega}\nm_E(\\omega) = 1$.  The function $m_E$ is called the \\emx {conditional distribution given $E$.}\n\n\\i\\label{exer 4.1.33} You are given two urns each containing two biased coins.  The coins in\nurn~I come up heads with probability~$p_1$, and the coins in urn~II come up\nheads with probability $p_2 \\ne p_1$.  You are given a choice of (a)~choosing\nan urn at random and tossing the two coins in this urn or (b)~choosing one coin\nfrom each urn and tossing these two coins.  You win a prize if both coins turn\nup heads.  Show that you are better off selecting choice (a).\n\n\\i\\label{exer 4.1.34} Prove that, if $A_1$,~$A_2$, \\dots,~$A_n$ are independent events\ndefined on a sample space $\\Omega$ and if $0 < P(A_j) < 1$ for all $j$, then\n$\\Omega$ must have at least $2^n$ points.\n\n\\i\\label{exer 4.1.35} Prove that if\n$$\nP(A|C) \\geq P(B|C) \\mbox{\\,\\,and\\,\\,} P(A|\\tilde C) \\geq P(B|\\tilde C)\\ ,\n$$\nthen $P(A) \\geq P(B)$.\n\n\\i\\label{exer 4.1.36} A coin is in one of $n$ boxes.  The probability that it is in the $i$th\nbox is $p_i$.  If you search in the $i$th box and it is there, you find it with\nprobability $a_i$.  Show that the probability~$p$ that the coin is in the $j$th\nbox, given that you have looked in the $i$th box and not found it, is\n$$\np =  \\left \\{ \\matrix{\n                 p_j/(1-a_ip_i),&\\,\\,\\, \\mbox{if} \\,\\,\\, j \\ne i,\\cr\n                 (1 - a_i)p_i/(1 - a_ip_i),&\\,\\,\\,\\mbox{if} \\,\\, j = i.\\cr}\\right. \n$$\n\n\\i\\label{exer 4.1.37} George Wolford\\index{WOLFORD, G.} has suggested the following variation on\nthe Linda problem (see Exercise~\\ref{sec 1.2}.\\ref{exer 1.2.24}).  \nThe registrar is carrying John and Mary's registration cards and drops them in a\npuddle.  When he pickes them up he cannot read the names but on the first card\nhe picked up he can make out Mathematics 23 and Government 35, and on the second\ncard he can make out only Mathematics 23.  He asks you if you can help him\ndecide which card belongs to Mary.  You know that Mary likes government but does\nnot like mathematics.  You know nothing about John and assume that he is just a\ntypical Dartmouth student.  From this you estimate:\n\\vskip .1in\n$$\\begin{array}{ll}\nP(\\mbox {Mary\\ takes\\ Government\\ 35})  &= .5\\ , \\\\\nP(\\mbox {Mary\\ takes\\ Mathematics\\ 23}) &= .1\\ , \\\\\nP(\\mbox {John\\ takes\\ Government\\ 35})  &= .3\\ , \\\\\nP(\\mbox {John\\ takes\\ Mathematics\\ 23}) &= .2\\ .\n\\end{array}\n$$\n\\vskip .1in\nAssume that their choices for courses are independent events.  Show that the\ncard with Mathematics 23 and Government 35 showing is more likely to be Mary's\nthan John's.  The conjunction fallacy referred to in the Linda problem would be\nto assume that the event ``Mary takes Mathematics 23 and Government 35\" is\nmore likely than the event ``Mary takes Mathematics 23.\"  Why are we not\nmaking this fallacy here?\n\n\\i\\label{exer 4.1.38} (Suggested by Eisenberg and Ghosh\\index{EISENBERG,\nB.}\\index{GHOSH, B. K.}\\footnote{B. Eisenberg and B.~K. Ghosh, ``Independent Events in a Discrete\nUniform Probability Space,\" \\emx {The American Statistician,} vol.~41, no.~1 (1987),\npp.~52--56.})  A deck of playing cards can be described as a Cartesian product\n$$\n\\mbox{Deck} =  \\mbox{Suit} \\times \\mbox{Rank}\\ ,\n$$\nwhere $\\mbox{Suit} = \\{\\clubsuit,\\diamondsuit,\\heartsuit,\\spadesuit\\}$ and %\n$\\mbox{Rank} = \\{2,3,\\dots,10,{\\mbox J},{\\mbox Q},{\\mbox K},{\\mbox A}\\}$.  This\njust means that every card may be thought of as an ordered pair like\n$(\\diamondsuit,2)$.  By a \\emx {suit event}\\index{suit event} we mean any event $A$ contained in\nDeck which is described in terms of Suit alone.  For instance, if $A$ is ``the\nsuit is red,\" then\n$$\nA = \\{\\diamondsuit,\\heartsuit\\} \\times \\mbox{Rank}\\ ,\n$$\nso that $A$ consists of all cards of the form $(\\diamondsuit,r)$ or\n$(\\heartsuit,r)$ where $r$ is any rank.  Similarly, a \\emx {rank event}\\index{rank event} is any\nevent described in terms of rank alone.\n\\begin{enumerate}\n\\item Show that if $A$ is any suit event and $B$ any rank event, then $A$\nand $B$ are \\emx {independent.}  (We can express this briefly by saying that\nsuit and rank are independent.)\n\n\\item Throw away the ace of spades.  Show that now no nontrivial (i.e.,\nneither empty nor the whole space) suit event $A$ is independent of any\nnontrivial rank event $B$.  \\emx {Hint}: Here independence comes down to\n$$\nc/51 = (a/51) \\cdot (b/51)\\ ,\n$$\nwhere $a$,~$b$,~$c$ are the respective sizes of $A$,~$B$ and~$A \\cap B$.  It\nfollows that 51 must divide $ab$, hence that 3 must divide one of $a$ and $b$,\nand 17 the other.  But the possible sizes for suit and rank events preclude\nthis.\n\n\\item Show that the deck in (b) nevertheless does have\npairs $A$,~$B$ of nontrivial independent events.  \\emx {Hint}: Find 2 events\n$A$ and $B$ of sizes 3 and 17, respectively, which intersect in a single point.\n\n\\item Add a joker to a full deck.  Show that now there is no pair $A$,~$B$\nof nontrivial independent events.  \\emx {Hint}: See the hint in\n(b); 53 is prime.\n\\end{enumerate}\n\\par\n\\medskip\n\\noindent\nThe following problems are suggested by Stanley Gudder\\index{GUDDER, S.} in his article\n``Do Good Hands Attract?\"\\footnote{S. Gudder, ``Do Good Hands Attract?\" \\emx {\nMathematics Magazine,} vol.~54, no.~1 (1981), pp.~13--16.}  He says that\nevent $A$ \\emx {attracts}\\index{events!attraction of} event $B$ if $P(B|A) > P(B)$ and \\emx {\nrepels}\\index{events!repulsion of}\n$B$ if $P(B|A) < P(B)$.\n\n\\i\\label{exer 4.1.39} Let $R_i$ be the event that the $i$th player in a poker game has a\nroyal flush.  Show that a royal flush (A,K,Q,J,10 of one suit) attracts another royal flush, \nthat is $P(R_2|R_1) > P(R_2)$.  Show that a royal flush repels full houses.\n\n\\i\\label{exer 4.1.40} Prove that $A$ attracts $B$ if and only if $B$ attracts $A$.  Hence we\ncan say that $A$ and $B$ are \\emx {mutually attractive} if $A$ attracts $B$.\n\n\\i\\label{exer 4.1.41} Prove that $A$ neither attracts nor repels $B$ if and only if $A$ and\n$B$ are independent.\n\n\\i\\label{exer 4.1.42} Prove that $A$ and $B$ are mutually attractive if and only if $P(B|A) >\nP(B|\\tilde A)$.\n\n\\i\\label{exer 4.1.43} Prove that if $A$ attracts $B$, then $A$ repels $\\tilde B$.\n\n\\i\\label{exer 4.1.44} Prove that if $A$ attracts both $B$ and $C$, and $A$ repels $B \\cap C$,\nthen $A$ attracts $B \\cup C$.  Is there any example in which $A$ attracts both\n$B$ and $C$ and repels $B \\cup C$?\n\n\\i\\label{exer 4.1.45} Prove that if $B_1$,~$B_2$, \\dots,~$B_n$ are mutually disjoint and\ncollectively exhaustive, and if $A$ attracts some $B_i$, then $A$ must repel\nsome $B_j$.\n\n\\i\\label{exer 4.1.46} \n\\begin{enumerate}\n\\item\nSuppose that you are looking in your desk for a letter from some time ago.  Your desk has eight\ndrawers, and you assess the probability that it is in any particular drawer is 10\\% (so there is\na 20\\% chance that it is not in the desk at all).  Suppose now that you start searching \nsystematically through your desk, one drawer at a time.  In addition, suppose that you have not found\nthe letter in the first $i$ drawers, where $0 \\le i \\le 7$.  Let $p_i$ denote the probability that\nthe letter will be found in the next drawer, and let $q_i$ denote the probability that the letter \nwill be found in some subsequent drawer (both $p_i$ and $q_i$ are conditional probabilities, since\nthey are based upon the assumption that the letter is not in the first $i$ drawers).  Show that\nthe $p_i$'s increase and the $q_i$'s decrease.  (This problem is from Falk et al.\\footnote{R.\\\nFalk, A.\\ Lipson, and C.\\ Konold, ``The ups and downs of the hope function in a fruitless search,\"\nin \\emx{Subjective Probability,} G.\\ Wright and P.\\ Ayton, (eds.) (Chichester: Wiley, 1994), pgs.\n353-377.})\\index{FALK, R.}\\index{LIPSON, A.}\\index{KONOLD, C.}\n\\item\nThe following data appeared in an article in the Wall Street Journal.\\footnote{C. Crossen, ``Fright by the\nnumbers:  Alarming disease data are frequently flawed,\" \\emx{Wall Street Journal,} 11 April 1996, p.\nB1.}\\index{Wall Street Journal}\\index{CROSSEN, C.} For the ages 20, 30, 40, 50, and 60, the probability of a \nwoman in the U.S.\\ developing cancer in the next ten years is 0.5\\%, 1.2\\%, 3.2\\%, 6.4\\%, and 10.8\\%,\nrespectively.  At the same set of ages, the probability of a woman in the U.S.\\ eventually developing cancer is\n39.6\\%, 39.5\\%, 39.1\\%, 37.5\\%, and 34.2\\%, respectively.  Do you think that the problem in part (a) gives an\nexplanation for these data? \n\\end{enumerate}\n\n\\i\\label{exer 4.1.47} \nHere are two variations of the Monty Hall problem that are discussed by Granberg.\\footnote{D.\nGranberg, ``To switch or not to switch,\" in\n\\emx{The power of logical thinking,} M. vos~Savant, (New York: St.\\ Martin's\n1996).}\\index{GRANBERG, D.}\\index{Monty Hall problem}\n\\begin{enumerate}\n\\item\nSuppose that everything is the same except that Monty forgot to find out in advance which door has the car behind\nit.  In the spirit of ``the show must go on,\" he makes a guess at which of the two doors to open and\ngets lucky, opening a door behind which stands a goat.  Now should the contestant switch?\n\\item\nYou have observed the show for a long time and found that the car is put behind door A 45\\% of the time,\nbehind door B 40\\% of the time and behind door C 15\\% of the time. Assume that everything else\nabout the show is the same.  Again you pick door A. Monty opens a door with a goat and\noffers to let you switch. Should you?  Suppose you knew in advance that Monty was going to give you\na chance to switch.  Should you have initially chosen door A?\n\\end{enumerate}\n\n\\end{LJSItem}\n\n%At one point, the following \\choice command starting giving errors,\n%so I commented it out (I also commented out the ending }).\n%\\choice{}{\\section{Continuous Conditional Probability}\\label{sec 4.2}\n\\section{Continuous Conditional Probability}\\label{sec 4.2}\n\nIn situations where the sample space is continuous we will follow the same procedure as in the\nprevious section.  Thus, for example, if $X$ is a continuous random variable with density function\n$f(x)$, and if $E$ is an event with positive probability, we define a conditional\ndensity\\index{conditional density}\\index{density function!conditional} function by the formula\n$$ f(x|E) = \\left \\{ \\matrix{\n f(x)/P(E), &  \\mbox{if} \\,\\,x \\in E,       \\cr\n         0, & \\mbox{if}\\,\\,x \\not \\in E.  \\cr}\\right.        \n$$\nThen for any event $F$, we have\n$$ \nP(F|E) = \\int_F f(x|E)\\,dx\\ .\n$$\nThe expression $P(F|E)$ is called the conditional probability of $F$ given $E$.  As in the previous\nsection, it is easy to obtain an alternative expression for this probability:\n$$\nP(F|E) = \\int_F f(x|E)\\,dx = \\int_{E\\cap F} \\frac {f(x)}{P(E)}\\,dx = \\frac {P(E\\cap F)}{P(E)}\\ .\n$$\n\\par\nWe can think of the conditional density function as being 0 except on $E$, and\nnormalized to have integral 1 over $E$.  Note that if the original density is a\nuniform density corresponding to an experiment in which all events of equal\nsize are \\emx {equally likely,} then the same will be true for the conditional\ndensity.\n\n\\begin{example}\\label{exam 4.12}\nIn the spinner\\index{spinner} experiment (cf.\\ Example~\\ref{exam 2.1.1}),\nsuppose we know that the spinner has stopped with head in the upper half of the\ncircle, $0 \\leq x \\leq 1/2$.  What is the probability that $1/6 \\leq x\n\\leq 1/3$?\n\nHere $E = [0,1/2]$, $F = [1/6,1/3]$, and $F \\cap E = F$.  Hence\n\\begin{eqnarray*}\nP(F|E) &=& \\frac {P(F \\cap E)}{P(E)} \\\\\n       &=& \\frac {1/6}{1/2} \\\\\n       &=& \\frac 13\\ ,\n\\end{eqnarray*}\nwhich is reasonable, since $F$ is 1/3 the size of $E$.  The conditional density\nfunction here is given by\n\n$$\nf(x|E) =  \\left \\{ \\matrix{\n               2, & \\mbox{if}\\,\\,\\, 0   \\leq x < 1/2, \\cr\n               0, & \\mbox{if}\\,\\,\\, 1/2 \\leq x < 1.\\cr}\\right.\n$$\nThus the conditional density function is nonzero only on $[0,1/2]$, and is\nuniform there.\n\\end{example}\n\n\\begin{example}\\label{exam 4.13}\nIn the dart\\index{darts} game (cf.\\ Example~\\ref{exam 2.2.2}),\nsuppose we know that the dart lands in the upper half of the target.  What is\nthe probability that its distance from the center is less than 1/2?\n\nHere $E = \\{\\,(x,y) : y \\geq 0\\,\\}$, and $F = \\{\\,(x,y) : x^2 + y^2 <\n(1/2)^2\\,\\}$.  Hence,\n\\begin{eqnarray*}\nP(F|E) & = & \\frac {P(F \\cap E)}{P(E)} = \\frac {(1/\\pi)[(1/2)(\\pi/4)]}\n{(1/\\pi)(\\pi/2)} \\\\\n       & = & 1/4\\ .\n\\end{eqnarray*}\nHere again, the size of $F \\cap E$ is 1/4 the size of $E$.  The conditional\ndensity function is\n$$\nf((x,y)|E) =  \\left \\{ \\matrix{\n        f(x,y)/P(E) = 2/\\pi, &\\mbox{if}\\,\\,\\,(x,y) \\in E, \\cr\n        0,                   &\\mbox{if}\\,\\,\\,(x,y) \\not \\in E.\\cr}\\right.\n$$\n\\end{example}\n\n\\begin{example}\\label{exam 4.14}\nWe return to the exponential density\\index{exponential density}\\index{density\nfunction!exponential} (cf.\\ Example~\\ref{exam 2.2.7.5}).  We suppose that we are observing a lump\nof plutonium-239.  Our experiment consists of waiting for an emission, then starting a clock, and\nrecording the length of time $X$ that passes until the next emission.   Experience has shown that\n$X$ has an exponential density with some parameter $\\lambda$, which depends upon the size of the\nlump.  Suppose that when we perform this experiment, we notice that the clock reads $r$ seconds,\nand is still running.  What is the probability that there is no emission in a further $s$ seconds?\n\nLet $G(t)$ be the probability that the next particle is emitted after time $t$.  Then\n\\begin{eqnarray*}\nG(t) & = & \\int_t^\\infty \\lambda e^{-\\lambda x}\\,dx \\\\\n     & = & \\left.-e^{-\\lambda x}\\right|_t^\\infty = e^{-\\lambda t}\\ .\n\\end{eqnarray*}\n\nLet $E$ be the event ``the next particle is emitted after time $r$\" and $F$ the event ``the\nnext particle is emitted after time $r + s$.\"  Then\n\\begin{eqnarray*}\nP(F|E) & = & \\frac {P(F \\cap E)}{P(E)} \\\\\n       & = & \\frac {G(r + s)}{G(r)} \\\\\n       & = & \\frac {e^{-\\lambda(r + s)}}{e^{-\\lambda r}} \\\\\n       & = & e^{-\\lambda s}\\ .\n\\end{eqnarray*}\n\n\nThis tells us the rather surprising fact that the probability that we have to\nwait $s$ seconds more for an emission, given that there has been no emission in $r$ seconds,\nis \\emx {independent} of the time $r$.  This property (called the \\emx {\nmemoryless}\\index{memoryless property} property) was introduced in Example~\\ref{exam 2.2.7.5}. \nWhen trying to model various phenomena, this property is helpful in deciding whether the\nexponential density is appropriate.  \n\\par\nThe fact that the exponential density is memoryless means that it is reasonable to assume\nif one comes upon a lump of a radioactive isotope at some random time, then the amount of time\nuntil the next emission has an exponential density with the same parameter as the time between\nemissions.  A well-known example, known as the ``bus paradox,\"\\index{bus paradox} replaces the\nemissions by buses.  The apparent paradox arises from the following two facts:  1) If you know that,\non the average, the buses come by every 30 minutes, then if you come to the bus stop at a random\ntime, you should only have to wait, on the average, for 15 minutes for a bus, and 2) Since the buses\narrival times are being modelled by the exponential density, then no matter when you arrive,\nyou will have to wait, on the average, for 30 minutes for a bus.\n\\par\nThe reader can now see that in Exercises~\\ref{sec 2.2}.\\ref{exer 2.2.8.5}, \n\\ref{sec 2.2}.\\ref{exer 2.2.8.6}, and \\ref{sec 2.2}.\\ref{exer\n2.2.11}, we were asking for simulations of conditional probabilities, under various assumptions\non the distribution of the interarrival times.  If one makes a reasonable assumption about this\ndistribution, such as the one in Exercise~\\ref{sec 2.2}.\\ref{exer 2.2.8.6}, then the average \nwaiting time is more nearly one-half the average interarrival time.\n\\end{example}\n\n\\subsection*{Independent Events}\n\nIf $E$ and $F$ are two events with positive probability in a continuous sample space, then, as in\nthe case of discrete sample spaces, we define $E$ and $F$ to be \\emx {\nindependent}\\index{events!independent}\\index{independence of events} if \n$P(E|F) = P(E)$ and $P(F|E) = P(F)$.  As before, each of the above equations imply the\nother, so that to see whether two events are independent, only one of these equations must be\nchecked.  It is also the case that, if $E$ and $F$ are independent, then $P(E \\cap F) = P(E)P(F)$.\n\n\\begin{example}(Example~\\ref{exam 4.12} continued){\\label{exam 4.15}}\nIn the dart\\index{darts} game (see Example~\\ref{exam 4.12}), let $E$ be the event that the\ndart lands in the \\emx {upper} half of the target ($y \\geq 0$) and $F$ the\nevent that the dart lands in the \\emx {right} half of the target ($x \\geq\n0$).  Then $P(E \\cap F)$ is the probability that the dart lies in the first\nquadrant of the target, and\n\\begin{eqnarray*}\nP(E \\cap F) & = & \\frac 1\\pi \\int_{E \\cap F} 1\\,dxdy \\\\\n            & = & \\mbox{Area}\\,(E\\cap F)         \\\\\n            & = & \\mbox{Area}\\,(E)\\,\\mbox{Area}\\,(F)  \\\\\n            & = & \\left(\\frac 1\\pi \\int_E 1\\,dxdy\\right) \\left(\\frac 1\\pi \\int_F\n1\\,dxdy\\right) \\\\\n            & = & P(E)P(F)\n\\end{eqnarray*}\nso that $E$ and $F$ are independent.  What makes this work is that the events\n$E$ and $F$ are described by restricting different coordinates.  This idea is made \nmore precise\\linebreak[4] below.\n\\end{example}\n\n\\subsection*{Joint Density and Cumulative Distribution Functions}\n\nIn a manner analogous with discrete random variables, we can define joint density\nfunctions and cumulative distribution functions for multi-dimensional continuous random\nvariables.  \n\n\\begin{definition}\\label{def 4.5}\nLet $X_1,~X_2, \\ldots,~X_n$ be continuous random variables associated with an experiment, and\nlet ${\\bar X} = (X_1,~X_2, \\ldots,~X_n)$.  Then the joint cumulative\ndistribution\\index{cumulative distribution function!joint}\\index{joint cumulative \ndistribution\\\\ function} function of\n${\\bar X}$ is defined by\n$$F(x_1, x_2, \\ldots, x_n) = P(X_1 \\le x_1, X_2 \\le x_2, \\ldots, X_n \\le x_n)\\ .$$\nThe joint density function\\index{joint density function}\\index{density function!joint} of\n${\\bar X}$ satisfies the following equation:\n$$F(x_1, x_2, \\ldots, x_n) = \\int_{-\\infty}^{x_1} \\int_{-\\infty}^{x_2} \\cdots\n\\int_{-\\infty}^{x_n} f(t_1, t_2, \\ldots t_n)\\,dt_ndt_{n-1}\\ldots dt_1\\ .$$\n\\end{definition}\n\nIt is straightforward to show that, in the above notation,\n\\begin{equation}\nf(x_1, x_2, \\ldots, x_n) = {{\\partial^n F(x_1, x_2, \\ldots, x_n)}\\over\n{\\partial x_1 \\partial x_2 \\cdots \\partial x_n}}\\ .\\label{eq 4.4}\n\\end{equation}\n\n\\subsection*{Independent Random Variables}\n\nAs with discrete random variables, we can define mutual independence of continuous\nrandom variables.\n\n\\begin{definition}\\label{def 4.6} Let $X_1$,~$X_2$, \\ldots,~$X_n$ be continuous random\nvariables with cumulative distribution functions $F_1(x),~F_2(x), \\ldots,~F_n(x)$.  Then\nthese random variables are \\emx {mutually independent}\\index{independence of random\nvariables!mutual} if\n$$F(x_1, x_2, \\ldots, x_n) = F_1(x_1)F_2(x_2) \\cdots  F_n(x_n)$$   \nfor any choice of $x_1, x_2,\n\\ldots, x_n$.  Thus, if $X_1,~X_2, \\ldots,~X_n$ are mutually independent, then the joint\ncumulative distribution function of the random variable ${\\bar X} = (X_1, X_2, \\ldots,\nX_n)$ is just the product of the individual cumulative distribution functions.  When two random\nvariables are mutually independent, we shall say more briefly that they are \\emx {\nindependent.}\\index{independence of random\\\\ variables}\n\\end{definition}\n\nUsing Equation~\\ref{eq 4.4}, the following theorem can easily be shown to hold for mutually\nindependent continuous random variables.\n\n\\begin{theorem}\\label{thm 4.2}\nLet $X_1$,~$X_2$, \\ldots,~$X_n$ be continuous random variables with density\nfunctions $f_1(x),~f_2(x), \\ldots,~f_n(x)$.  Then these random variables are \\emx { mutually\nindependent} if and only if\n$$f(x_1, x_2, \\ldots, x_n) = f_1(x_1)f_2(x_2) \\cdots  f_n(x_n)$$    for any choice of $x_1,\nx_2, \\ldots, x_n$.  \n\\end{theorem}\n\nLet's look at some examples.\n\n\\begin{example}\nIn this example, we define three random variables, $X_1,\\ X_2$, and $X_3$.  We will show that\n$X_1$ and $X_2$ are independent, and that $X_1$ and $X_3$ are not independent.  Choose a point\n$\\omega = (\\omega_1,\\omega_2)$ at random from the unit square.  Set $X_1 =\n\\omega_1^2$, $X_2 = \\omega_2^2$, and $X_3 =\n\\omega_1 + \\omega_2$.  Find the joint distributions $F_{12}(r_1,r_2)$ and $F_{23}(r_2,r_3)$.\n\nWe have already seen (see Example~\\ref{exam 2.2.7.1}) that\n\\begin{eqnarray*}\n F_1(r_1) & = & P(-\\infty < X_1 \\leq r_1) \\\\\n         & = & \\sqrt{r_1}, \\qquad \\mbox{if} \\,\\,0 \\leq r_1 \\leq 1\\ ,\n\\end{eqnarray*}\nand similarly,\n$$ F_2(r_2) = \\sqrt{r_2}\\ ,$$\nif $0 \\leq r_2 \\leq 1$.\nNow we have (see Figure~\\ref{fig 5.15})\n\\putfig{3truein}{PSfig5-15}{$X_1$ and $X_2$ are independent.}{fig 5.15}\n\\begin{eqnarray*}\n F_{12}(r_1,r_2) & = & P(X_1 \\leq r_1 \\,\\, \\mbox{and}\\,\\, X_2 \\leq r_2) \\\\\n                & = & P(\\omega_1 \\leq \\sqrt{r_1} \\,\\,\\mbox{and}\\,\\, \\omega_2 \\leq\n\\sqrt{r_2}) \\\\\n                & = & \\mbox{Area}\\,(E_1)\\\\\n                & = & \\sqrt{r_1} \\sqrt{r_2} \\\\\n                & = &F_1(r_1)F_2(r_2)\\ .\n\\end{eqnarray*}\nIn this case $F_{12}(r_1,r_2) = F_1(r_1)F_2(r_2)$ so that $X_1$ and $X_2$ are\nindependent.  On the other hand, if $r_1 = 1/4$ and $r_3 = 1$, then (see Figure~\\ref{fig\n5.16})\n\\putfig{3truein}{PSfig5-16}{$X_1$ and $X_3$ are not independent.}{fig 5.16}\n\\begin{eqnarray*}\nF_{13}(1/4,1) & = & P(X_1 \\leq 1/4,\\ X_3 \\leq 1) \\\\\n              & = & P(\\omega_1 \\leq 1/2,\\ \\omega_1 + \\omega_2 \\leq 1) \\\\\n              & = & \\mbox{Area}\\,(E_2) \\\\\n              & = & \\frac 12 - \\frac 18 = \\frac 38\\ .\n\\end{eqnarray*}\nNow recalling that\n$$F_3(r_3) = \\left \\{ \\matrix{\n                  0, & \\mbox{if} \\,\\,r_3 < 0, \\cr\n         (1/2)r_3^2, & \\mbox{if} \\,\\,0 \\leq r_3 \\leq 1, \\cr\n   1-(1/2)(2-r_3)^2, & \\mbox{if} \\,\\,1 \\leq r_3 \\leq 2, \\cr\n                  1, & \\mbox{if} \\,\\,2 < r_3,\\cr}\\right.\n$$ (see Example~\\ref{exam 2.2.7.2}), we have $F_1(1/4)F_3(1) = (1/2)(1/2) = 1/4$.  Hence, $X_1$\nand $X_3$ are not independent random variables.  A similar calculation shows that $X_2$ and\n$X_3$ are not independent either.\n\\end{example}\n\nAlthough we shall not prove it here, the following theorem is a useful one.  The\nstatement also holds for mutually independent discrete random variables.  A proof may be\nfound in R\\'enyi.\\index{R\\'ENYI, A.}\\footnote{A. R\\'enyi, \\emx {Probability Theory} (Budapest:\nAkad\\'emiai Kiad\\'o, 1970), p.~183.}\n\n\\begin{theorem}\\label{thm 4.3}\nLet $X_1, X_2, \\ldots, X_n$ be mutually independent continuous random variables and let\n$\\phi_1(x), \\phi_2(x), \\ldots, \\phi_n(x)$ be continuous functions.  Then $\\phi_1(X_1),$\n\\newline\n$\\phi_2(X_2), \\ldots, \\phi_n(X_n)$ are mutually independent.\n\\end{theorem}\n\n\\subsection*{Independent Trials}\n\nUsing the notion of independence, we can now formulate for continuous sample spaces the notion\nof independent trials (see Definition~\\ref{def 5.5}).\n\n\\begin{definition}\\label{def 5.12} A sequence $X_1$,~$X_2$, \\dots,~$X_n$ of random variables\n$X_i$ that are mutually independent and have the same density is called an \\emx {independent\ntrials\\linebreak[4] process.}\\index{independent trials process}\n\\end{definition}\n\\par\nAs in the case of discrete random variables, these independent trials processes arise\nnaturally in situations where an experiment described by a single random variable is repeated\n$n$ times.\n\n\\subsection*{Beta Density}\n\nWe consider next an example which involves a sample space with both discrete\nand continuous coordinates.  For this example we shall need a new density\nfunction called the \\emx {beta density.}\\index{density function!beta}\\index{beta density}  This\ndensity has two parameters\n$\\alpha$,~$\\beta$ and is defined by\n$$\nB(\\alpha,\\beta,x) =  \\left \\{ \\matrix{ \n(1/B(\\alpha,\\beta))x^{\\alpha - 1}(1 - x)^{\\beta - 1}, & {\\mbox{if}}\\,\\, 0 \\leq x \\leq 1, \\cr\n                                                   0, & {\\mbox{otherwise}}.\\cr}\\right. \n$$\nHere $\\alpha$ and $\\beta$ are any positive numbers, and the beta function\n$B(\\alpha,\\beta)$ is given by the area under the graph of $x^{\\alpha - 1}(1 -\nx)^{\\beta - 1}$ between 0 and 1:\n$$\nB(\\alpha,\\beta) = \\int_0^1 x^{\\alpha - 1}(1 - x)^{\\beta - 1}\\,dx\\ .\n$$\nNote that when $\\alpha = \\beta = 1$ the beta density if the uniform density. \nWhen $\\alpha$ and $\\beta$ are greater than 1 the density is bell-shaped, but\nwhen they are less than 1 it is U-shaped as suggested by the examples in\nFigure~\\ref{fig 4.6}.\n\n\\putfig{4truein}{PSfig4-6}{Beta density for $\\alpha = \\beta = .5,1,2.$}{fig 4.6}\n\nWe shall need the values of the beta function only for integer values of\n$\\alpha$ and $\\beta$, and in this case\n$$\nB(\\alpha,\\beta) = \\frac{(\\alpha - 1)!\\,(\\beta - 1)!}{(\\alpha + \\beta - 1)!}\\ .\n$$\n\n\\begin{example}\\label{exam 4.16}\nIn medical problems it is often assumed that a drug is effective with a\nprobability~$x$ each time it is used and the various trials are\nindependent, so that one is, in effect, tossing a biased coin with probability\n$x$ for heads.  \nBefore further experimentation, you do not know the value $x$ but past experience might give\nsome information about its possible values. It is natural to represent this information\nby sketching a density function\nto determine a distribution for $x$.  Thus, we are considering $x$ to be a continuous random\nvariable, which takes on values between 0 and 1.  If you have no knowledge at all, you would\nsketch the uniform density.  If past experience suggests that\n$x$ is very likely to be near 2/3 you would sketch a density with maximum at 2/3 and a\nspread reflecting your uncertainly in the estimate of 2/3. You would then want to find a\ndensity function that reasonably fits your sketch.  The beta densities provide a class of\ndensities that can be fit to most sketches you might make. For example, for\n$\\alpha > 1$ and $\\beta > 1$ it is bell-shaped with the parameters $\\alpha$ and $\\beta$\ndetermining its peak and its spread. \n\\par\nAssume that the experimenter has chosen a beta density to describe the state of\nhis knowledge about $x$ before the experiment.  Then he gives the drug to $n$\nsubjects and records the number $i$ of successes.   The number $i$ is a discrete random\nvariable, so we may conveniently describe the set of possible outcomes of this experiment\nby referring to the ordered pair $(x, i)$.\n\\par\nWe let $m(i|x)$ denote the probability that we observe $i$ successes given the value of $x$.  By our\nassumptions, $m(i|x)$ is the binomial distribution with probability~$x$ for success:\n$$\nm(i|x) = b(n,x,i) = {n \\choose i} x^i(1 - x)^j\\ ,\n$$\nwhere $j = n - i$.  \n\\par\nIf $x$ is chosen at random from $[0,1]$ with a beta\ndensity $B(\\alpha,\\beta,x)$, then the density function for the outcome of the\npair $(x,i)$ is\n\\begin{eqnarray*}\nf(x,i) & = & m(i|x)B(\\alpha,\\beta,x) \\\\\n       & = & {n \\choose i} x^i(1 - x)^j \\frac 1{B(\\alpha,\\beta)} x^{\\alpha - 1}(1 -\nx)^{\\beta - 1} \\\\\n       & = & {n \\choose i}  \\frac 1{B(\\alpha,\\beta)} x^{\\alpha + i - 1}(1 - x)^{\\beta +\nj - 1}\\ .\n\\end{eqnarray*}\nNow let $m(i)$ be the probability that we observe $i$ successes \\emx {not}\nknowing the value of $x$.  Then\n\\begin{eqnarray*}\nm(i) & = & \\int_0^1 m(i|x) B(\\alpha,\\beta,x)\\,dx \\\\\n     & = & {n \\choose i} \\frac 1{B(\\alpha,\\beta)} \\int_0^1 x^{\\alpha + i - 1}(1 -\nx)^{\\beta + j - 1}\\,dx \\\\\n     & = & {n \\choose i} \\frac {B(\\alpha + i,\\beta + j)}{B(\\alpha,\\beta)}\\ .\n\\end{eqnarray*}\nHence, the probability density $f(x|i)$ for $x$, given that $i$ successes were\nobserved, is\n$$\nf(x|i)  =  \\frac {f(x,i)}{m(i)} \n$$\n\\begin{equation}\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ =  \n\\frac {x^{\\alpha + i - 1}(1 - x)^{\\beta + j - 1}}{B(\\alpha + i,\\beta\n+ j)}\\ ,\\label{eq 4.5}\n\\end{equation}\nthat is, $f(x|i)$ is another beta density.  This says that if we observe $i$\nsuccesses and $j$ failures in $n$ subjects, then the new density for the\nprobability that the drug is effective is again a beta density but with\nparameters $\\alpha + i$, $\\beta + j$.\n\\par\nNow we assume that before the experiment we choose a beta density with\nparameters $\\alpha$ and $\\beta$, and that in the experiment\nwe obtain $i$ successes in $n$ trials.  We have just seen that in this case, the new density for $x$\nis a beta density with parameters $\\alpha + i$ and $\\beta + j$.  \n\\par\nNow we wish to calculate the probability that the drug is effective on the next subject.  For any\nparticular real number $t$ between 0 and 1, the probability that $x$ has the value $t$ is given by\nthe expression in Equation~\\ref{eq 4.5}.  Given that $x$ has the value $t$, the probability that the drug\nis effective on the next subject is just $t$.  Thus, to obtain the probability that the drug is effective\non the next subject, we integrate the product of the expression in Equation~\\ref{eq 4.5} and $t$ over all\npossible values of $t$.  We obtain:\n\\begin{eqnarray*}\n\\lefteqn{\\frac 1{B(\\alpha + i,\\beta + j)} \n\\int_0^1 t\\cdot t^{\\alpha + i - 1}(1 - t)^{\\beta + j - 1}\\,dt}\n\\\\\n  & = & \\frac {B(\\alpha + i + 1,\\beta + j)}{B(\\alpha + i,\\beta + j)} \\\\\n  & = & \\frac {(\\alpha + i)!\\,(\\beta + j - 1)!}{(\\alpha + \\beta + i + j)!} \\cdot \n\\frac {(\\alpha + \\beta + i + j - 1)!}{(\\alpha + i - 1)!\\,(\\beta + j - 1)!} \\\\\n  & = & \\frac {\\alpha + i}{\\alpha + \\beta + n}\\ .\n\\end{eqnarray*}\nIf $n$ is large, then our estimate for the probability of success after the experiment is\napproximately the proportion of successes observed in the experiment, which is\ncertainly a reasonable conclusion.\n\\end{example}\n\nThe next example is another in which the true probabilities are unknown and must be\nestimated based upon experimental data.\n\n\\begin{example}(Two-armed bandit problem)\\label{exam 4.17}\\index{two-armed bandit}\nYou are in a casino and confronted by two slot machines.  Each machine pays off\neither 1 dollar or nothing.  The probability that the first machine pays off a\ndollar is $x$ and that the second machine pays off a dollar is $y$.  We assume\nthat $x$ and $y$ are random numbers chosen independently from the interval\n$[0,1]$ and unknown to you.  You are permitted to make a series of ten plays,\neach time choosing one machine or the other.  How should you choose to maximize\nthe number of times that you win?\n\nOne strategy that sounds reasonable is to calculate, at every stage, the\nprobability that each machine will pay off and choose the machine with the\nhigher probability.  Let win($i$), for~$i = 1$ or~2, be the number of times\nthat you have won on the $i$th machine.  Similarly, let lose($i$) be the number\nof times you have lost on the $i$th machine.  Then, from Example~\\ref{exam\n4.16}, the probability $p(i)$ that you win if you choose the $i$th machine is \n$$\np(i) = \\frac {{\\mbox{win}}(i) + 1} {{\\mbox{win}}(i) + {\\mbox{lose}}(i) + 2}\\ .\n$$\nThus, if $p(1) > p(2)$ you would play machine 1 and otherwise you would play\nmachine 2.  We have written a program {\\bf TwoArm}\\index{TwoArm (program)} to simulate this\nexperiment.  In the program, the user specifies the initial values for $x$ and\n$y$ (but these are unknown to the experimenter).  The program calculates at\neach stage the two conditional densities for $x$ and $y$, given the outcomes of\nthe previous trials, and then computes $p(i)$, for~$i = 1$,~2.  It then chooses\nthe machine with the highest value for the probability of winning for the next\nplay.  The program prints the machine chosen on each play and the outcome of\nthis play.  It also plots the new densities for~$x$ (solid line) and $y$\n(dotted line), showing only the current densities.  We have run the program for\nten plays for the case $x = .6$ and $y = .7$.  The result is shown in\nFigure~\\ref{fig 4.7}.\n\n\\putfig{4.5truein}{PSfig4-7}{Play the best machine.}{fig 4.7}\n\nThe run of the program shows the weakness of this strategy.  Our initial\nprobability for winning on the better of the two machines is .7.  We start with\nthe poorer machine and our outcomes are such that we always have a probability\ngreater than .6 of winning and so we just keep playing this machine even though\nthe other machine is better.  If we had lost on the first play we would have\nswitched machines.  Our final density for $y$ is the same as our initial\ndensity, namely, the uniform density.  Our final density for $x$ is different\nand reflects a much more accurate knowledge about $x$.  The computer did pretty\nwell with this strategy, winning seven out of the ten trials, but ten trials\nare not enough to judge whether this is a good strategy in the long run.\n\n\\putfig{4.5truein}{PSfig4-8}{Play the winner.}{fig 4.8}\n\nAnother popular strategy  is the \\emx {play-the-winner strategy.}  As the name\nsuggests, for this strategy we choose the same machine when we win and switch\nmachines when we lose.  The program {\\bf TwoArm} will simulate this\nstrategy as well.  In Figure~\\ref{fig 4.8}, we show the results of running this program\nwith the play-the-winner strategy and the same true probabilities of .6 and .7\nfor the two machines.  After ten plays our densities for the unknown\nprobabilities of winning suggest to us that the second machine is indeed the\nbetter of the two.  We again won seven out of the ten trials.\n\nNeither of the strategies that we simulated is the best one in terms of\nmaximizing our average winnings.  This best strategy is very complicated but is\nreasonably approximated by the play-the-winner strategy.  Variations on this\nexample have played an important role in the problem of clinical tests of drugs\nwhere experimenters face a similar situation.\n\\end{example}\n\n\\exercises\n\\begin{LJSItem}\n\n\\i\\label{exer 4.2.1} Pick a point $x$ at random (with uniform density) in the interval\n$[0,1]$.  Find the probability that $x > 1/2$, given that\n\\begin{enumerate}\n\\item $x > 1/4$.\n\n\\item $x < 3/4$.\n\n\\item $|x - 1/2| < 1/4$.\n\n\\item $x^2 - x + 2/9 < 0$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.2} A radioactive material emits $\\alpha$-particles at a rate described by\nthe density function\n$$\nf(t) = .1e^{-.1t}\\ .\n$$\nFind the probability\nthat a particle is emitted in the first 10~seconds, given that\n\\begin{enumerate}\n\\item no particle is emitted in the first second.\n\n\\item no particle is emitted in the first 5 seconds.\n\n\\item a particle is emitted in the first 3 seconds.\n\n\\item a particle is emitted in the first 20 seconds.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.3} The Acme Super light bulb\\index{light bulb} is known to have a useful life\ndescribed by  the density function\n$$\nf(t) = .01e^{-.01t}\\ ,\n$$\nwhere time $t$ is measured in hours.  \n\\begin{enumerate}\n\\item Find the \\emx {failure rate} of this bulb \n(see Exercise~\\ref{sec 2.2}.\\ref{exer 2.2.6}).\n\n\\item Find the \\emx {reliability} of this bulb after 20 hours.\n\n\\item Given that it lasts 20 hours, find the probability that the bulb lasts another 20\nhours.\n\n\\item Find the probability that the bulb burns out in the forty-first hour, given\nthat it lasts 40 hours.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.4} Suppose you toss a dart at a circular target of radius 10 inches.  Given\nthat the dart lands in the upper half of the target, find the probability that\n\\begin{enumerate}\n\\item it lands in the right half of the target.\n\n\\item its distance from the center is less than 5 inches.\n\n\\item its distance from the center is greater than 5 inches.\n\n\\item it lands within 5 inches of the point $(0,5)$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.5} Suppose you choose two numbers $x$ and $y$, independently at random from\nthe interval $[0,1]$.  Given that their sum lies in the interval $[0,1]$,\nfind the probability that\n\\begin{enumerate}\n\\item $|x - y| < 1$.\n\n\\item $xy < 1/2$.\n\n\\item $\\max\\{x,y\\} < 1/2$.\n\n\\item $x^2 + y^2 < 1/4$.\n\n\\item $x > y$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.6} Find the conditional density functions for the following experiments.\n\\begin{enumerate}\n\\item A number $x$ is chosen at random in the interval $[0,1]$, given that\n$x > 1/4$.\n\n\\item A number $t$ is chosen at random in the interval $[0,\\infty)$ with\nexponential density $e^{-t}$, given that $1 < t < 10$.\n\n\\item A dart is thrown at a circular target of radius 10 inches, given that\nit falls in the upper half of the target.\n\n\\item Two numbers $x$ and $y$ are chosen at random in the interval\n$[0,1]$, given that $x > y$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.7} Let $x$ and $y$ be chosen at random from the interval $[0,1]$.  Show\nthat the events $x > 1/3$ and $y > 2/3$ are independent events.\n\n\\i\\label{exer 4.2.8} Let $x$ and $y$ be chosen at random from the interval $[0,1]$.  Which\npairs of the following events are independent?\n\\begin{enumerate}\n\\item $x > 1/3$.\n\n\\item $y > 2/3$.\n\n\\item $x > y$.\n\n\\item $x + y < 1$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.8.5}  Suppose that $X$ and $Y$ are continuous random variables with\ndensity functions $f_X(x)$ and $f_Y(y)$, respectively.  Let $f(x, y)$ denote the joint\ndensity function of $(X, Y)$.  Show that\n$$\n\\int_{-\\infty}^\\infty f(x, y)\\, dy = f_X(x)\\ ,\n$$ and\n$$\n\\int_{-\\infty}^\\infty f(x, y)\\, dx = f_Y(y)\\ .\n$$\n\n\n\\istar\\label{exer 4.2.9} In Exercise~\\ref{sec 2.2}.\\ref{exer 2.2.13} you\nproved the following: If you take a stick of unit length and break it into three pieces,\nchoosing the breaks at random (i.e., choosing two real numbers independently \nand uniformly from [0, 1]), then the probability that the three pieces form\na triangle is 1/4.  Consider now a similar experiment: First break the stick at\nrandom, then break the longer piece at random.  Show that the two experiments\nare actually quite different, as follows:\n\\begin{enumerate}\n\\item Write a program which simulates both cases for a run of 1000 trials,\nprints out the proportion of successes for each run, and repeats this process\nten times.  (Call a trial a success if the three pieces do form a triangle.) \nHave your program pick $(x,y)$ at random in the unit square, and in each case\nuse $x$ and $y$ to find the two breaks.  For each experiment, have it plot\n$(x,y)$ if $(x,y)$ gives a success.\n\n\\item Show that in the second experiment the theoretical probability of\nsuccess is actually $2\\log 2 - 1$.\n\\end{enumerate}\n\n\\i\\label{exer 4.2.10} A coin has an unknown bias $p$ that is assumed to be uniformly\ndistributed between 0 and 1.  The coin is tossed $n$ times and heads turns up\n$j$ times and tails turns up $k$ times.  We have seen that the probability that\nheads turns up next time is\n$$\n\\frac {j + 1}{n + 2}\\ .\n$$\nShow that this is the same as the probability that the next ball is black for\nthe Polya urn model\\index{Polya urn model} of Exercise~\\ref{sec 4.1}.\\ref{exer 4.1.18}. \nUse this result to explain why, in the Polya urn model, the proportion of black\nballs does not tend to 0~or~1 as one might expect but rather to a uniform\ndistribution on the interval $[0,1]$.\n\n\\i\\label{exer 4.2.11} Previous experience with a drug suggests that the probability~$p$ that\nthe drug is effective is a random quantity having a beta density with\nparameters $\\alpha = 2$ and $\\beta = 3$.  The drug is used on ten subjects and\nfound to be successful in four out of the ten patients.  What density should we\nnow assign to the probability~$p$?  What is the probability that the drug will\nbe successful the next time it is used?\n\n\\i\\label{exer 4.2.12} Write a program to allow you to compare the strategies play-the-winner\nand play-the-best-machine for the two-armed bandit problem of Example~\\ref{exam\n4.17}.  Have your program determine the initial payoff probabilities for\neach machine by choosing a pair of random numbers between 0 and 1.  Have your\nprogram carry out 20 plays and keep track of the number of wins for each of the\ntwo strategies.  Finally, have your program make 1000 repetitions of the 20\nplays and compute the average winning per 20 plays.  Which strategy seems to be\nthe best?  Repeat these simulations with 20 replaced by 100.  Does your answer to the\nabove question change?\n\n\\i\\label{exer 4.2.13} Consider the two-armed bandit problem of Example~\\ref{exam 4.17}. \nBruce Barnes\\index{BARNES, B.} proposed the following strategy, which is a variation on the\nplay-the-best-machine strategy.  The machine with the greatest probability of\nwinning is played \\emx {unless} the following two conditions hold: (a)~the\ndifference in the probabilities for winning is less than .08, and (b)~the ratio\nof the number of times played on the more often played machine to the number of\ntimes played on the less often played machine is greater than 1.4.  If the\nabove two conditions hold, then the machine with the smaller probability of\nwinning is played.  Write a program to simulate this strategy.  Have your\nprogram choose the initial payoff probabilities at random from the unit\ninterval $[0,1]$, make 20 plays, and keep track of the number of wins. \nRepeat this experiment 1000 times and obtain the average number of wins per 20\nplays.  Implement a second strategy---for example, play-the-best-machine or one\nof your own choice, and see how this second strategy compares with Bruce's on\naverage wins.\n\n%\\end{LJSItem}}\n\\end{LJSItem}\n\n\\section{Paradoxes}\\label{sec 4.3}\n\nMuch of this section is based on an article by Snell and Vanderbei.\\index{SNELL, J.\nL.}\\index{VANDERBEI, R.}\\footnote{J. L. Snell and R. Vanderbei, ``Three Bewitching\nParadoxes,\" in \\emx {Topics in Contemporary Probability and Its Applications}, CRC Press, Boca\nRaton, 1995.}\n\\par\nOne must be very careful in dealing with problems involving conditional probability.  \nThe reader will recall that in the Monty Hall problem (Example~\\ref{exam 4.5}), if the contestant\nchooses the door with the car behind it, then Monty has a choice of doors to open.  We made an\nassumption that in this case, he will choose each door with probability 1/2.  We then noted \nthat if this assumption is changed, the answer to the original question changes.   In this\nsection, we will study other examples of the same phenomenon.\n\n\\begin{example}\\label{exam 4.3.1}\nConsider a family with two children.  Given that one of the children is a boy,\nwhat is the probability that both children are boys?\n\\par\nOne way to approach this problem is to say that the other child is equally likely to\nbe a boy or a girl, so the probability that both children are boys is 1/2.  The ``text-book\"\nsolution would be to draw the tree diagram and then form the\nconditional tree by deleting paths to leave only those paths that are consistent\nwith the given information.  The result is shown in Figure~\\ref{fig 4.3}. We see that the \nprobability of two boys given a boy in the family is not 1/2 but rather 1/3.\n\\putfig{3.5truein}{PSfig4-3}{Tree for Example \\protect\\ref{exam 4.3.1}\\protect.}{fig 4.3}\n\\end{example}\n\nThis problem and others like it are discussed in Bar-Hillel and\nFalk.\\index{BAR-HILLEL, M.}\\index{FALK, R.}\\footnote{M. Bar-Hillel and R. Falk, ``Some teasers\nconcerning conditional probabilities,\" \\emx {Cognition}, vol. 11 (1982), pgs. 109-122.} These\nauthors stress that the answer to conditional probabilities of this  kind can change depending\nupon how the information given was actually obtained.   For example, they show that 1/2 is the\ncorrect answer for the following scenario.\n\n\\begin{example}\\label{exam 4.3.2}\nMr.\\ Smith is the father of two.  We meet him walking along the street with a young boy whom \nhe proudly introduces as his son.  What is the probability that Mr.\\ Smith's other child is also\na boy?\n\\par\nAs usual we have to make some additional assumptions.  For example, we will\nassume that if Mr.\\ Smith has a boy and a girl, he is equally likely to choose\neither one to accompany him on his walk. In Figure~\\ref{fig 4.3.5} we show the tree analysis of this \nproblem and we see that 1/2 is, indeed, the correct answer.\n\\putfig{5truein}{PSfig4-3-5}{Tree for Example \\protect\\ref{exam 4.3.2}\\protect.}{fig 4.3.5}\n\\end{example}\n\n\\begin{example}\\label{exam 4.3.3}\nIt is not so easy to think of reasonable scenarios that would lead to the classical 1/3 answer.\nAn attempt was made by Stephen Geller\\index{GELLER, S.} in proposing this problem to Marilyn vos\nSavant.\\index{vos SAVANT, M.}\\footnote{M. vos Savant, ``Ask Marilyn,\" \\emx {Parade\nMagazine}, 9  September;  2 December;  17  February 1990, reprinted in Marilyn\nvos Savant, \\emx {Ask Marilyn}, St. Martins, New York, 1992.}\nGeller's problem is as follows:  A shopkeeper says she has two new baby beagles to show you, but she\ndoesn't know whether they're both male, both female, or one of each sex.  You tell her that \nyou want only a male, and she telephones the fellow who's giving them a bath.  ``Is at least \none a male?\" she asks. ``Yes,\" she informs you with a smile.  What is the probability that \nthe \\emx {other} one is male?\n\\par\nThe reader is asked to decide whether the model which gives an answer of 1/3 is a reasonable one \nto use in this case.\n\\end{example}\n\nIn the preceding examples, the apparent paradoxes could easily be resolved by clearly stating\nthe model that is being used and the assumptions that are being made.  We now turn to some\nexamples in which the paradoxes are not so easily resolved.\n\n\\begin{example}\\label{exam 4.3.4}\nTwo envelopes each contain a certain amount of money.  One envelope is given to Ali\\index{Ali} \nand the other to Baba\\index{Baba} and they are told that one envelope contains twice as much money\nas the other.  However, neither knows who has the larger prize.  Before anyone has \nopened their envelope, Ali is asked if she would like to trade her envelope with Baba.\nShe reasons as follows:  Assume that the amount in my envelope is $x$.  If I switch,\nI will end up with $x/2$ with probability 1/2, and $2x$ with probability 1/2.  If I were\ngiven the opportunity to play this game many times, and if I were to switch each time, \nI would, on average, get\n$$\n\\frac 12 \\frac x2 + \\frac 12 2x = \\frac 54 x\\ .\n$$\nThis is greater than my average winnings if I didn't switch.  \n\\par\nOf course, Baba is presented with the same opportunity and reasons in the same way \nto conclude that he too would like to switch.  So they switch and each thinks that \nhis/her net worth just went up by 25\\%.\n\\par\nSince neither has yet opened any envelope, this process can be\nrepeated and so again they switch.  Now they are back with their original\nenvelopes and yet they think that their fortune has increased 25\\% twice.\nBy this reasoning, they could convince themselves that by repeatedly switching the\nenvelopes, they could become arbitrarily wealthy.  Clearly, something is wrong with \nthe above reasoning, but where is the mistake?\n\\par\nOne of the tricks of making paradoxes is to make them slightly more difficult\nthan is necessary to further befuddle us.  As John Finn\\index{FINN, J.} has suggested, in this\nparadox  we could just have well started with a simpler problem.  Suppose Ali and Baba know that \nI am going to give then either an envelope with \\$5 or one with \\$10 \nand I am going to toss a coin to decide which to give to Ali, and then give the other to \nBaba.  Then Ali can argue that Baba has $2x$ with probability $1/2$ and $x/2$ with probability \n$1/2$.  This leads Ali to the same conclusion as before.   But now it is clear that this is \nnonsense, since if Ali has the envelope containing \\$5, Baba cannot possibly have half of this, \nnamely \\$2.50, since that was not even one of the choices.  Similarly, if Ali has \\$10, \nBaba cannot have twice as much, namely \\$20. In fact, in this simpler problem the possibly \noutcomes are given by the tree diagram in Figure~\\ref{fig 4.9}.\n\\putfig{3truein}{PSfig4-9}{John Finn's version of Example \\protect\\ref{exam 4.3.4}\\protect.}{fig 4.9}%%4.5truein \nFrom the diagram, it is clear that neither is made better off by switching.\n\\end{example}\n\nIn the above example, Ali's reasoning is incorrect because he infers that if the amount\nin his envelope is $x$, then the probability that his envelope contains the smaller amount\nis 1/2, and the probability that her envelope contains the larger amount is also 1/2.  In \nfact, these conditional probabilities depend upon the distribution of the amounts that\nare placed in the envelopes.\n\\par\nFor definiteness, let $X$ denote the positive integer-valued random variable which represents\nthe smaller of the two amounts in the envelopes.  Suppose, in addition, that we are given \nthe distribution of $X$, i.e., for each positive integer $x$, we are given the value of \n$$p_x = P(X = x)\\ .$$\n(In Finn's example, $p_5 = 1$, and $p_{n} = 0$ for all other values of $n$.)\nThen it is easy to calculate the conditional probability that an envelope contains the \nsmaller amount, given that it contains $x$ dollars.  The two possible sample points are\n$(x, x/2)$ and $(x, 2x)$.  If $x$ is odd, then the first sample point has probability 0,\nsince $x/2$ is not an integer, so the desired conditional probability is 1 that $x$ is \nthe smaller amount.  If $x$ is even, then the two sample points have probabilities $p_{x/2}$ \nand $p_x$, respectively, so the conditional probability that $x$ is the smaller amount is\n$$\\frac{p_x}{p_{x/2} + p_x}\\ ,$$\nwhich is not necessarily equal to 1/2.\n\\par\nSteven Brams\\index{BRAMS, S.} and D. Marc Kilgour\\index{KILGOUR, D. M.}\\footnote{S. J. Brams\nand D. M. Kilgour, ``The Box Problem:  To Switch or Not to Switch,\" \\emx {Mathematics Magazine},\nvol. 68, no. 1 (1995),  p. 29.} study the problem, for different distributions, of whether or\nnot one should  switch envelopes, if one's objective is to maximize the long-term average\nwinnings.  Let\n$x$ be the amount in your envelope.  They show that for any distribution of $X$, there\nis at least one value of $x$ such that you should switch.  They give an example of a \ndistribution for which there is exactly one value of $x$ such that you should switch (see\nExercise~\\ref{exer 4.3.5}).  Perhaps the most interesting case is a distribution in which\nyou should always switch.  We now give this example.\n\n\\begin{example}\\label{exam 4.3.5}\nSuppose that we have two envelopes\\index{envelopes} in front of us, and that one envelope contains\ntwice the amount of money as the other (both amounts are positive integers).  We are given\none of the envelopes, and asked if we would like to switch.\n\\par\nAs above, we let $X$ denote the smaller of the two amounts in the envelopes, and let \n$$p_x = P(X = x)\\ .$$\nWe are now in a position where we can calculate the long-term average winnings, if we switch.  \n(This long-term average is an example of a probabilistic concept known as expectation, and\nwill be discussed in Chapter~\\ref{chp 6}.)  Given that one of the two sample points has \noccurred, the probability that it is the point $(x, x/2)$ is\n$$\\frac{p_{x/2}}{p_{x/2} + p_x}\\ ,$$\nand the probability that it is the point $(x, 2x)$ is\n$$\\frac{p_x}{p_{x/2} + p_x}\\ .$$\nThus, if we switch, our long-term average winnings are\n$$\\frac{p_{x/2}}{p_{x/2} + p_x}\\frac x2 + \\frac{p_x}{p_{x/2} + p_x} 2x\\ .$$\nIf this is greater than $x$, then it pays in the long run for us to switch.\nSome routine algebra shows that the above expression is greater than $x$ if and only\nif\n\\begin{equation}\n\\frac{p_{x/2}}{p_{x/2} + p_x} < \\frac 23\\ .\n\\label{eq 4.3.1}\n\\end{equation}\n\\par\nIt is interesting to consider whether there is a distribution on the positive integers\nsuch that the inequality~\\ref{eq 4.3.1} is true for all even values of $x$.  Brams and \nKilgour\\footnote{ibid.} give the following example.\n\\par\nWe define $p_x$ as follows:\n$$\np_x = \\left \\{ \\matrix{\n               \\frac 13 \\Bigl(\\frac 23\\Bigr)^{k-1}, & \\mbox{if}\\,\\, x = 2^k, \\cr\n               0, & \\mbox{otherwise.}\\cr\n}\\right.\n$$\nIt is easy to calculate (see Exercise~\\ref{exer 4.3.4}) that for all relevant values of $x$, \nwe have\n$$\n\\frac{p_{x/2}}{p_{x/2} + p_x} = \\frac 35\\ ,\n$$\nwhich means that the inequality~\\ref{eq 4.3.1} is always true.\n\\end{example}\n\nSo far, we have been able to resolve paradoxes by clearly stating the assumptions being made\nand by precisely stating the models being used.  We end this section by describing a paradox\nwhich we cannot resolve.\n\n\\begin{example}\\label{exam 4.3.6}\nSuppose that we have two envelopes\\index{envelopes} in front of us, and we are told that the\nenvelopes contain\n$X$ and $Y$ dollars, respectively, where $X$ and $Y$ are different positive integers.  We randomly\nchoose one of the envelopes, and we open it, revealing $X$, say.  Is it possible to determine, with\nprobability greater than 1/2, whether $X$ is the smaller of the two dollar amounts?\n\\par\nEven if we have no knowledge of the joint distribution of $X$ and $Y$, the surprising answer \nis yes!  Here's how to do it.  Toss a fair coin until the first time that heads turns up.  Let $Z$\ndenote the number of tosses required plus 1/2.  If $Z > X$, then we say that $X$ is the smaller of the \ntwo amounts, and if $Z < X$, then we say that $X$ is the larger of the two amounts.  \n\\par\nFirst, if $Z$ lies between $X$ and $Y$, then we are sure to be correct.  Since $X$ and $Y$ are \nunequal, $Z$ lies between them with positive probability.  Second, if $Z$ is not between $X$ and $Y$,\nthen $Z$ is either greater than both $X$ and $Y$, or is less than both $X$ and $Y$.  In either \ncase, $X$ is the smaller of the two amounts with probability 1/2, by symmetry considerations (remember,\nwe chose the envelope at random).  Thus, the probability that we are correct is greater than 1/2.\n\\end{example}\n\n\\exercises\n\\begin{LJSItem}\n\n\\i\\label{exer 4.3.1}\nOne of the first conditional probability paradoxes was\nprovided by Bertrand.\\index{BERTRAND, J.}\\footnote{J. Bertrand, \\emx {Calcul des Probabilit\\'{e}s},\nGauthier-Uillars, 1888.}  It is called the \\emx {Box Paradox}\\index{Box paradox}.  A cabinet has\nthree drawers. In the first drawer there  are two gold balls, in the second drawer  there are two\nsilver balls, and in the third drawer there  is one silver and one gold ball. A drawer is picked\nat random and a ball chosen at random from the  two balls in the drawer.  Given that a  gold ball\nwas drawn, what is the probability that the drawer with the two gold balls was chosen?\n\n\\i\\label{exer 4.3.2}\nThe following problem is called the \\emx {two aces problem}\\index{Two aces problem}. This problem,\ndating back to 1936, has been attributed to the English mathematician J. H. C.\nWhitehead\\index{WHITEHEAD, J. H. C.} (see Gridgeman\\index{GRIDGEMAN, N. T.}\\footnote{N. T. \nGridgeman, Letter, \\emx {American Statistician}, 21 (1967), pgs. 38-39.}). This problem was also\nsubmitted to Marilyn vos Savant\\index{vos SAVANT, M.} by the master of mathematical puzzles Martin\nGardner\\index{GARDNER, M.}, who remarks that it is one of his favorites.\n\\par\nA bridge\\index{bridge} hand has been dealt, i.\\ e. thirteen cards are dealt to each player.  Given that\nyour partner has at least one ace, what is the probability that he has at least two aces?  Given that\nyour partner has the ace of hearts, what is the probability that he has at least two aces?  Answer these\nquestions for a version of bridge in which there are eight cards, namely four aces and four kings, and\neach player is dealt two cards.  (The reader may wish to solve the problem with a 52-card deck.)\n\n\\i\\label{exer 4.3.3}\nIn the preceding exercise, it is natural to ask ``How do we get the information that the given hand \nhas an ace?\" Gridgeman considers two different ways that we might get this information.  (Again, assume\nthe deck consists of eight cards.)\n\\begin{enumerate}\n\\item\nAssume that the person holding the hand is asked to ``Name an ace in your hand\" and answers ``The ace\nof hearts.\"  What is the probability that he has a second ace?\n\\item\nSuppose the person holding the hand is asked the more direct question ``Do you have the ace of\nhearts?\" and the answer is yes.  What is the probability that he has a second ace? \n\\end{enumerate}\n\n\\i\\label{exer 4.3.4}  Using the notation introduced in Example~\\ref{exam 4.3.5}, show that in the\nexample of Brams\\index{BRAMS, S.} and Kilgour\\index{KILGOUR, D. M.}, if $x$ is a positive power of\n2, then\n$$\n\\frac{p_{x/2}}{p_{x/2} + p_x} = \\frac 35\\ .\n$$\n\n\\i\\label{exer 4.3.5} Using the notation introduced in Example~\\ref{exam 4.3.5}, let\n$$\np_x = \\left \\{ \\matrix{\n               \\frac 23 \\Bigl(\\frac 13\\Bigr)^k, & \\mbox{if}\\,\\, x = 2^k, \\cr\n               0, & \\mbox{otherwise.}\\cr\n}\\right.\n$$\nShow that there is exactly one value of $x$ such that if your envelope contains $x$,\nthen you should switch.\n\n\n\\istar\\label{exer 4.3.6} (For bridge\\index{bridge} players only.  From\nSutherland.\\index{SUTHERLAND, E.}\\footnote{E. Sutherland, ``Restricted Choice\\index{restricted\nchoice, principle of} --- Fact or Fiction?\", \\emx {Canadian Master Point}, November 1, 1993.})  \nSuppose that we are the declarer in a hand of bridge, and we have the king, 9, 8, 7, and 2  of a\ncertain suit, while the dummy has the ace, 10, 5, and 4 of the same suit.  Suppose that  we want\nto play this suit in such a way as to maximize the probability of having no losers  in the suit. \nWe begin by leading the 2 to the ace, and we note that the queen drops on our  left.  We then lead\nthe 10 from the dummy, and our right-hand opponent plays the six (after playing the three on the\nfirst round).  Should we finesse or play for the drop?\n\n\n\\end{LJSItem}\n\n\n", "meta": {"hexsha": "774144a8ef3f70d358f3a12b085a01fd2222f5d1", "size": 123784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ch4.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/ch4.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/ch4.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": 51.8141481792, "max_line_length": 133, "alphanum_fraction": 0.7118367479, "num_tokens": 38554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.6199141041637647}}
{"text": "\\section{DFS and BFS}\n\n%%%%%%%%%%%%%%%\n\\begin{frame}{Classifying edges}\n  \\begin{definition}[Classifying edges]\n    Given a DFS/BFS traversal $\\Rightarrow$ DFS/BFS tree:\n    \\begin{itemize}\n      \\item Tree edge: $\\to$ child\n      \\item Back edge: $\\to$ ancestor\n      \\item Forward edge: $\\to$ \\emph{nonchild} descendant\n      \\item Cross edge: $\\to$ neither ancestor nor descendant\n    \\end{itemize}\n  \\end{definition}\n\n  \\begin{alertblock}{Remarks:}\n    \\begin{itemize}\n      \\item applicable to both DFS and BFS\n      \\item w.r.t. DFS/BFS trees\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Classifying edges}\n  \\begin{exampleblock}{Classifying edges \\pno{3.4.1}}\n    \\begin{figure}\n      \\begin{subfigure}{0.50\\linewidth}\n\t\\centering\n\t\\includegraphics[width=0.50\\textwidth]{figures/dfs-digraph.png}\n\t\\caption{DFS on directed graph.}\n      \\end{subfigure}%\n      \\begin{subfigure}{0.50\\linewidth}\n\t\\centering\n\t\\includegraphics[width=0.50\\textwidth]{figures/dfs-undirected.png}\n\t\\caption{DFS on undirected graph.}\n      \\end{subfigure}\n\n      \\begin{subfigure}{0.50\\linewidth}\n\t\\centering\n\t\\includegraphics[width=0.50\\textwidth]{figures/bfs-digraph.png}\n\t\\caption{BFS on directed graph.}\n      \\end{subfigure}%\n      \\begin{subfigure}{0.50\\linewidth}\n\t\\centering\n\t\\includegraphics[width=0.60\\textwidth]{figures/bfs-undirected.png}\n\t\\caption{BFS on undirected graph.}\n      \\end{subfigure}\n    \\end{figure}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Classifying edges}\n  \\begin{exampleblock}{DFS tree and BFS tree coincide \\pno{3.4.30}}\n    $G = (V,E), v \\in V$. DFS tree $T$ = BFS tree $T'$.\n\n    \\begin{itemize}\n      \\item $G$ is an undirected graph $\\Rightarrow$ $G = T$.\n      \\item $G$ is a digraph $\\Rightarrow^{?}$ $G = T$.\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item $T$: tree + back; $T'$: tree + cross\n      \\item $T$: tree + back + forward + cross; $T'$: tree + back + cross \n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Distance constraints for BFS}\n  \\begin{exampleblock}{Distance constraints for BFS \\pno{3.4.4}}\n    \\begin{columns}[t]\n      \\column{0.40\\textwidth}\n        BFS on digraph:\n\t\\begin{description}\n\t  \\item[TE:] $d[v] = d[u] + 1$\n\t  \\item[BE:] $0 \\le d[v] \\le d[u]$\n\t  \\item[CE:] $d[v] \\le d[u] + 1$\n\t\\end{description}\n      \\column{0.60\\textwidth}\n        BFS on undirected graph:\n\t\\begin{description}\n\t  \\item[TE:] $d[v] = d[u] + 1$\n\t  \\item[CE:] $d[v] = d[u] \\lor d[v] = d[u] + 1$ \n\t\\end{description}\n    \\end{columns}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution to ``\\emph{CE} in BFS on \\emph{undirected} graph''.}\n    \\begin{itemize}\n      \\item $d[v] = d[u], d[v] = d[u] + 1$\n      \\item $d[v] < d[u], d[v] > d[u] + 1$\n    \\end{itemize}\n  \\end{block}\n\n  \\begin{alertblock}{Remark.}\n    \\begin{itemize}\n      \\item BFS tree defines a \\emph{shortest-path} from its root to every other node.\n      \\item Layers in BFS on \\emph{undirected} graph; c.f. bipartite testing \\pno{3.4.26}\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Lifetime of vertices in DFS}\n  \\begin{exampleblock}{Lifetime of vertices in DFS \\pno{3.4.5}} \n    $\\forall u,v$:\n    \\begin{itemize}\n      \\item $u$ is an ancestor of $v$: $[\\text{d}[v], \\text{f}[v]] \\subset [\\text{d}[u], \\text{f}[u]]; [_{u}\\; [_{v}\\; ]_{v}\\; ]_{u}$\n      \\item $u,v$ has no ancestor/descendant relation: $[\\text{d}[v], \\text{f}[v]] || [\\text{d}[u], \\text{f}[u]]$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    Assume $u, v \\in $ DFS tree.\n\n    \\begin{itemize}\n      \\item $c$: least common ancestor of $u,v$ \\pno{3.4.17}\n      \\item $c \\to u' \\leadsto u; c \\to v' \\leadsto v$\n      \\item $u', v'$ disjoint; $u \\subset u' \\land v \\subset v'$\n    \\end{itemize}\n  \\end{block}\n\n  \\begin{alertblock}{Remark.}\n    $\\forall u,v: [_{u} \\; ]_{u}, [_{v} \\; ]_{v}$ \\emph{disjoint} $\\lor$ \\emph{contained} $\\Leftarrow$ a ``stack'' view.\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Preprocessing for ancestor/descendant relation}\n  \\begin{exampleblock}{Preprocessing for ancestor/descendant relation \\pno{3.4.14}}\n    \\begin{itemize}\n      \\item binary tree $\\Rightarrow$ tree $T$\n      \\item $r \\in T$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    $v: \\text{d}[v], \\text{f}[v]$\n  \\end{block}\n\n  \\begin{alertblock}{Remark.}\n    $\\forall v$: how many descendants?\n\n    $(\\text{f}[v] - \\text{d}[v] - 1) / 2$\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n\\begin{frame}{Edge types and lifetime of vertices in DFS}\n  \\begin{exampleblock}{Edge types and lifetime of vertices in DFS \\pno{3.4.3}}\n    $\\forall u \\to v$:\n    \\begin{itemize}\n      \\item tree/forward edge: $[_{u}\\; [_{v}\\; ]_{v}\\; ]_{u}$\n      \\item back edge: $[_{v}\\; [_{u}\\; ]_{u}\\; ]_{v}$\n      \\item cross edge: $[_{v}\\; ]_{v}\\; [_{u}\\; ]_{u}$\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{alertblock}{Remark.}\n    \\begin{itemize}\n      \\item $\\text{f}[v] < \\text{d}[u]$: cross edge\n      \\item $\\text{f}[u] < \\text{f}[v]$: back edge\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "9783d7e08cc5ff4b5bb29c3ad829190bbf3bbe4b", "size": 5170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/dfs-bfs.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-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/dfs-bfs.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-2016/algorithm-tutorial-graph-decomposition-2016-05-19/sections/dfs-bfs.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": 31.5243902439, "max_line_length": 133, "alphanum_fraction": 0.5955512573, "num_tokens": 1844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.619914102759376}}
{"text": "\\section*{Appendix}\r\n\r\nThis section provides a detailed description of the {\\tt TESS3} algorithm.  The first step of the algorithm builds a nearest-neighbor graph based on the geographic coordinates of the sampling sites. The number of neighbors in the graph was set to represent $5\\%$ of total connections. Then, the program runs a least-squares minimization algorithm.  In this approach, the estimates of $Q$ and $G$ are obtained after solving the following constrained least-squares problem~\\citep{cai2011graph}\r\n\r\n$$\r\n(\\hat Q, \\hat G) = \\arg \\min {\\rm LS}(Q, G) \\, ,\r\n$$\r\n\r\n\\noindent where\r\n\r\n\\begin{equation}\\label{eq:LS}\r\n{\\rm LS}(Q, G) =  \\|  \\tilde{X} - QG \\|^2_{\\rm F}   +   \\alpha   \\sum_{s_i \\sim s_j}   w_{ij} \\|  Q_{i.}  - Q_{j.} \\|^2   \\, , \r\n\\end{equation}\r\n\r\n\\noindent and $Q$ and $G$ are non-negative matrices such that, for all $i$ and $\\ell$, we have  \r\n\r\n$$\r\n\\sum_{k=1}^K Q_{ik} = 1  \\qquad \\sum_{j=0}^{p} G_{i\\ell}(j) = 1 \\, .\r\n$$\r\n\r\n\\noindent In this equation, $\\| M \\|_{\\rm F}$ denotes the Frobenius norm of a matrix $M$,  $\\| V \\|$ is the Euclidean norm of a vector $V$, $\\alpha$ is a non-negative {\\it regularization parameter}. The summation on the right-hand side of the second term runs over all pairs of sites, $s_i \\sim s_j$ , sharing an edge in the nearest-neighbor graph. The quantity $w_{ij}$ is a weight that decreases with geographic distance between sampling sites as follows\r\n\r\n\\begin{equation} \r\nw_{ij} =\\exp( -  d(s_i, s_j)^2 / \\bar{d^2}  ) \\, ,  \r\n\\end{equation}\r\n\r\n\\noindent where $d$ is the Euclidean distance, and $\\bar{d}$ is the average distance computed over the neighboring sites in the sample. More specifically, the weight of an edge in the nearest-neighbor graph is related to the Laplace-Beltrami operator on a manifold~\\citep{belkin2003laplacian}. In the algorithm, the regularization parameter $\\alpha$ is equal to $c \\times nL(p+1) / \\sum w_{ij}$. The default value of $c$ is $0.1\\%$.\r\n\r\n\r\nLeast squares minimization is performed using the Alternating Non-negativity-constrained Least Squares (ANLS) algorithm with the active set (AS) method following the approach used in the computer program {\\tt sNMF}~\\citep{frichot2014fast,kim2011fast}. The ANLS-AS algorithm starts with the initialization of the $Q$ matrix, and then computes a non-negative matrix $G$ that minimizes the quantity \r\n\r\n$${\\rm LS}_1(G) = \\|X - QG \\|_F^2 \\, .\r\n$$\r\n\r\n\r\n\\noindent The obtained solution is normalized so that its entries satisfy the probabilistic constraints for genotypic frequencies. Given $G$, the $Q$-matrix is computed after minimizing the following quantity \r\n \r\n$${\\rm LS}_2(Q) = \r\n\\left|\\left|\r\n\\left(\r\n    \\begin{array}{c}\r\n      {\\rm Vec}(\\tilde{X}^T) \\\\\r\n      0\r\n    \\end{array}\r\n  \\right)\r\n   -  \r\n   \\left(\r\n   \\begin{array}{c}\r\n      {\\rm Id} \\otimes G^T \\\\\r\n      \\sqrt{\\alpha} ~ \\Gamma \\otimes {\\rm Id}\r\n    \\end{array}\r\n  \\right) {\\rm Vec}(Q^T)  \r\n   \\right|\\right|_F^2\r\n   \\, ,\r\n$$\r\n\r\n\\noindent where ${\\rm Vec}(\\tilde{X})$ denotes the vectorization of the matrix $\\tilde{X}$ formed by stacking the columns of $\\tilde{X}$ into a single column vector, $\\Gamma$ is the Cholesky decomposition of the graph Laplacian associated with the weights of the graph~\\citep{chung1997spectral}, Id is the identity matrix, and $\\otimes$ is a symbol for the Kronecker product. Iterations are stopped when the relative difference between two successive values of ${\\rm LS}(Q,G)$  is lower than a tolerance threshold of $\\epsilon$. The default value for $\\epsilon$ equals $10^{-7}$.", "meta": {"hexsha": "cf7c0840f74da86b780a3dbb75cff3e48dbb8cb2", "size": 3520, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1Article/Article/appendix.tex", "max_stars_repo_name": "cayek/Thesis", "max_stars_repo_head_hexsha": "14d7c3fd03aac0ee940e883e37114420aa614b41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1Article/Article/appendix.tex", "max_issues_repo_name": "cayek/Thesis", "max_issues_repo_head_hexsha": "14d7c3fd03aac0ee940e883e37114420aa614b41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1Article/Article/appendix.tex", "max_forks_repo_name": "cayek/Thesis", "max_forks_repo_head_hexsha": "14d7c3fd03aac0ee940e883e37114420aa614b41", "max_forks_repo_licenses": ["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.7543859649, "max_line_length": 579, "alphanum_fraction": 0.6869318182, "num_tokens": 1044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.6926419831347361, "lm_q1q2_score": 0.619768740572855}}
{"text": "\\newpage\\section{Calculus}\n\n\t\n\t\n\t\\lem{}{ \\begin{align*}\n\t\t\t(f(x)+g(x))' = f'(x)+g'(x) \\\\ \\\\\n\t\t\t(f(x)g(x)) = f'(x)g(x) + f(x)g'(x) \\\\ \\\\\n\t\t\t(\\frac{f(x)}{g(x)})' = \\frac{f'(x)g(x) - f(x)g'(x)}{g(x)^2} \\\\ \\\\\n\t\t\t(f(g(x)))' = f'(g(x)) + g'(x)\n\t\\end{align*} }\n\n\n\t\\lem{The Derivative of an Odd function is always an Even function, and vice versa.}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n", "meta": {"hexsha": "7545d8c31048eb13d867f0c84146cad902512b5d", "size": 357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg/sec4_calculus.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": "alg/sec4_calculus.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": "alg/sec4_calculus.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": 16.2272727273, "max_line_length": 84, "alphanum_fraction": 0.4453781513, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6197374902349829}}
{"text": "\\section{Hoare Triple Validity}\n\n\\subsection{Showing the validity of a Hoare triple using Midnight-Formula}\n\nProving the validity of the following hoare triple: $\\{x^2 + 4x + 3 = 0\\} x := x - 1 \\{ x = -4 \\lor x = -2 \\}$\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/hoareTripleMidnight.png}\n\\caption{Verification Condition - Midnight Formula}\n\\end{figure}", "meta": {"hexsha": "1c9eefe8bd8b019ccc5129457f81de836fdf1c50", "size": 385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_AdvPrPa/Excercises/Verification/01_HoareTripleValidity.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/Verification/01_HoareTripleValidity.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/Verification/01_HoareTripleValidity.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": 35.0, "max_line_length": 110, "alphanum_fraction": 0.7272727273, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6196076824504395}}
{"text": "\\section{Introduction}\n\\par\nIf the ultimate goal is to solve linear systems of the form\n$AX = B$, one must compute an $A = LDU$, $A = U^TDU$ or\n$A = U^HDU$ factorization, depending on whether the matrix $A$\nis nonsymmetric, symmetric or Hermitian.\n$D$ is a diagonal or block diagonal matrix,\n$L$ is unit lower triangular,\nand $U$ is unit upper triangular.\n$A$ is sparse, but the sparsity structure of $L$ and $U$ will\nlikely be much larger than that of $A$,\ni.e., they will suffer fill-in.\nIt is crucial to find a permutation matrix such that the factors of\n$PAP^T$ have as moderate fill-in as can be reasonably expected.\n\\par\nTo illustrate, consider a 27-point finite difference operator defined\non an $n \\times n \\times n$ grid.\nThe number of rows and columns in $A$ is $n^3$, as is the number of\nnonzero entries in $A$.\nUsing the natural ordering, the numbers of entries in $L$ and $U$ \nare $O(n^5)$, and it takes $O(n^7)$ operations to compute the\nfactorization.\nThe banded and profile orderings \\cite{geo81-book} \nhave the same complexity.\n\\par\nUsing the nested dissection ordering,\n\\cite{geo73-nested},\nthe factor storage is reduced to $O(n^4)$ and factor operations to\n$O(n^6)$.\nIn practice, the minimum degree ordering has this same low-fill\nnature, although topological counterexamples exist\n\\cite{ber90-mindeg}.\nA unit cube is the worst case comparison between banded and profile\norderings and the minimum degree and nested dissection orderings.\nBut, there is still a lot to be gained by using a good permutation\nwhen solving most sparse linear systems, and the relative gain\nbecomes larger as the problem size increases.\n\\par\nThis short paper is a gentle introduction to the ordering methods\n--- the background as well as the specific function calls.\nBut finding a good ordering is not enough.\nThe ``choreography'' of the factorization and solves, i.e., what\ndata structures and computations exist, and in a parallel\nenvironment, which thread or processor does what and when,\nis as crucial.\nThe structure of the factor matrices, as well as the structure of the\ncomputations is controlled by a ``front tree''.\nThis object is constructed directly by the {\\bf SPOOLES} ordering\nsoftware, or can be created from the graph of the matrix and an\noutside permutation.\nVarious transformations on the front tree can make a large\ndifference in performance.\nSome knowledge of the linear system, (e.g., does it come from a 2-D\nor 3-D problem? is it small or large?), coupled with some knowledge\nof how to tailor a front tree, can be important to getting the best\nperformance from the library.\n\\par\nSection~\\ref{section:ordering} introduces some background on sparse\nmatrix orderings and describes the {\\bf SPOOLES} ordering software.\nSection~\\ref{section:front-trees} presents the front tree object\nthat controls the factorization, and its various transformations\nto improve performance.\n\n", "meta": {"hexsha": "9960941258ec2e2a76b09c10e475a5e5d93b0dbd", "size": 2887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ccx_prool/SPOOLES.2.2/documentation/FrontTrees/intro.tex", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/SPOOLES.2.2/documentation/FrontTrees/intro.tex", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/SPOOLES.2.2/documentation/FrontTrees/intro.tex", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 45.109375, "max_line_length": 69, "alphanum_fraction": 0.775545549, "num_tokens": 710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6195957962434055}}
{"text": "%!TEX root = dsp_2nd_program_hw.tex\n\n\\section{Code}\n\n\n\\subsection{DTMF\\_1.cpp --- Main function for problem 1}\\label{dtmf1}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n# include <fstream>\n# include <string>\n# include <stdio.h>\n# include <stdlib.h>\n# include <cmath>\n# include <ctime>\n# include <sstream>\n# include <iostream>\n# include <cstdlib>\n# include <unistd.h>  \n# include <dirent.h>  \n# include <sys/stat.h>  \n# define PI 3.1415926\nint const MAX_STR_LEN = 200;  \n\n# include \"complex.h\"\n# include \"dif_fft.h\"\n# include \"find_dtmf_symbol.h\"\n\nusing namespace std;\n\n// FFT Algorithm\nint main()\n{\n\tchar dir_name[100] = \"./txtData1/\"; \n\n    struct dirent * filename;    // return value for readdir()  \n    DIR * dir;                   // return value for opendir()  \n    dir = opendir( dir_name );  \n    /* read all the files in the dir ~ */  \n    while( ( filename = readdir(dir) ) != NULL )  \n    {  \n        // get rid of \".\" and \"..\"  \n        if( strcmp( filename->d_name , \".\" ) == 0 ||   \n            strcmp( filename->d_name , \"..\") == 0 )  \n            continue;  \n        cout << filename ->d_name <<endl;  \n    \n    \tchar hhh[MAX_STR_LEN];\n    \tstrcpy(hhh, dir_name);\n    \tstrcat(hhh, (filename->d_name));\n\t\tifstream in( hhh );\n\t\tstring filename;\n\t\tstring line;\n\t\t\n\t\tif(in) // 有该文件  \n\t\t{\n\t\t\tdouble audio[60000];\n\t\t\tint count = 0;\n\t\t\twhile (getline (in, line)) // line中不包括每行的换行符\n\t\t\t{\n\t\t\t\t// audio[count] = atof(const_cast<const char *>(line.c_str()));\n\n\t\t\t\tdouble d;\n\t\t\t\tstringstream ss(line);\n\t\t\t\tss >> d;\n\t\t\t\taudio[count] = d;\n\n\t\t\t\tcount = count + 1;\n\t\t\t\t// cout << audio[count-1] << endl;\n\t\t\t}\n\n\t\t\t// is 2^k or not, if not add zero\n\t\t\tint add_zero_count = 0;\n\t\t\tfor (int i = 1; i < 100; ++i)\n\t\t\t{\n\t\t\t\tif ( pow(2,i) < count ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if ( pow(2,i) == count ) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tadd_zero_count = pow(2,i) - count;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// add value to input_seq[]\n\t\t\tint total_length = count + add_zero_count;\n\t\t\tcomplex* input_seq = new complex[total_length];\n\t\t\tfor (int i = 0; i < count; i++)\n\t\t\t{\n\t\t\t\tinput_seq[i].re = audio[i];\n\t\t\t\tinput_seq[i].im = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < add_zero_count; i++)\n\t\t\t{\n\t\t\t\tinput_seq[count + i].re = 0;\n\t\t\t\tinput_seq[count + i].im = 0;\n\t\t\t}\n\n\t\t\t// FFT\n\t\t\tcomplex* output_seq = DIF_FFT_reordered(input_seq, total_length);\n\n\t\t\t// Amp, Find max 1,2 and their positions\n\t\t\tint amp;\n\t\t\tint max1 = 0;\n\t\t\tint max2 = 0;\n\t\t\tint max1_pos = 0;\n\t\t\tint max2_pos = 0;\n\t\t\tfor (int i = 0; i < total_length/2; ++i)\n\t\t\t{\n\t\t\t\tamp = pow(output_seq[i].re,2) + pow(output_seq[i].im,2);\n\t\t\t\tif (amp > max2)\n\t\t\t\t{\n\t\t\t\t\tif (amp > max1) {\n\t\t\t\t\t\t// max2 = max1\n\t\t\t\t\t\tmax2 = max1;\n\t\t\t\t\t\tmax2_pos = max1_pos;\n\t\t\t\t\t\t// max1 = new\n\t\t\t\t\t\tmax1 = amp;\n\t\t\t\t\t\tmax1_pos = i;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmax2 = amp;\n\t\t\t\t\t\tmax2_pos = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// x-axis\n\t\t\t\t// 0:f_s/(N-1):f_s\n\t\t\tint fs = 8000;\n\t\t\tint N = total_length;\n\t\t\tdouble step = double(fs)/(N-1);\n\t\t\tdouble* x_axis = new double[N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t{\n\t\t\t\tx_axis[i] = i * step;\n\t\t\t}\n\n\t\t\t// Get max1, max2 freq\n\t\t\tcout << \"Max1 pos:\" << x_axis[max1_pos] << endl;\n\t\t\tcout << \"Max2 pos:\" << x_axis[max2_pos] << endl;\n\n\t\t\t// decipher\n\t\t\tchar output_symbol = find_dtmf_symbol(x_axis[max1_pos], x_axis[max2_pos]);\n\t\t\tcout << \"The symbol for this sound: \" << output_symbol << endl;\n\n\t\t\tcout << endl;\n\n\t\t} else { // fail reading file\n\t\t\tcout << \"no such file\" << endl;\n\t\t}\n    }  \n\treturn 0;\n}\n\\end{lstlisting}\n\n\\subsection{DTMF\\_2.cpp --- Main function for problem 2}\\label{dtmf2}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n# include <fstream>\n# include <string>\n# include <stdio.h>\n# include <stdlib.h>\n# include <cmath>\n# include <ctime>\n# include <sstream>\n# include <iostream>\n# include <cstdlib>\n# include <unistd.h>  \n# include <dirent.h>  \n# include <sys/stat.h>  \n# define PI 3.1415926\nint const MAX_STR_LEN = 200;  \n\n# include \"complex.h\"\n# include \"goertzel.h\"\n# include \"find_dtmf_symbol.h\"\n\nusing namespace std;\n\n// Goertzel Algorithm\nint main()\n{\n\tcout << \"Running Prob2, using Goertzel Algorithm ... \" << endl << endl;\n\n\tchar dir_name[100] = \"./txtData1/\"; \n\n    struct dirent * filename;    // return value for readdir()  \n    DIR * dir;                   // return value for opendir()  \n    dir = opendir( dir_name );  \n    /* read all the files in the dir ~ */  \n    while( ( filename = readdir(dir) ) != NULL )  \n    {  \n        // get rid of \".\" and \"..\"  \n        if( strcmp( filename->d_name , \".\" ) == 0 ||   \n            strcmp( filename->d_name , \"..\") == 0 )  \n            continue;  \n        cout << filename ->d_name <<endl;  \n    \n    \tchar hhh[MAX_STR_LEN];\n    \tstrcpy(hhh, dir_name);\n    \tstrcat(hhh, (filename->d_name));\n\t\tifstream in( hhh );\n\t\tstring filename;\n\t\tstring line;\n\t\t\n\t\tif(in) // 有该文件  \n\t\t{\n\t\t\tdouble audio[60000];\n\t\t\tint count = 0;\n\t\t\twhile (getline (in, line)) // line中不包括每行的换行符\n\t\t\t{\n\t\t\t\t// audio[count] = atof(const_cast<const char *>(line.c_str()));\n\n\t\t\t\tdouble d;\n\t\t\t\tstringstream ss(line);\n\t\t\t\tss >> d;\n\t\t\t\taudio[count] = d;\n\n\t\t\t\tcount = count + 1;\n\t\t\t\t// cout << audio[count-1] << endl;\n\t\t\t}\n\n\t\t\t// is 2^k or not, if not add zero\n\t\t\tint add_zero_count = 0;\n\t\t\tfor (int i = 1; i < 100; ++i)\n\t\t\t{\n\t\t\t\tif ( pow(2,i) < count ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if ( pow(2,i) == count ) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tadd_zero_count = pow(2,i) - count;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// add value to input_seq[]\n\t\t\tint total_length = count + add_zero_count;\n\t\t\tcomplex* input_seq = new complex[total_length];\n\t\t\tfor (int i = 0; i < count; i++)\n\t\t\t{\n\t\t\t\tinput_seq[i].re = audio[i];\n\t\t\t\tinput_seq[i].im = 0;\n\t\t\t}\n\t\t\tfor (int i = 0; i < add_zero_count; i++)\n\t\t\t{\n\t\t\t\tinput_seq[count + i].re = 0;\n\t\t\t\tinput_seq[count + i].im = 0;\n\t\t\t}\n\n\t\t\t// Goertzel, return amp^2\n\t\t\tdouble* targeted_amp = Goertzel(input_seq, total_length);\n\n\t\t\t// Amp, Find max 1,2 and their positions\n\t\t\tint amp;\n\t\t\tint max1 = 0;\n\t\t\tint max2 = 0;\n\t\t\tint max1_pos = 0;\n\t\t\tint max2_pos = 0;\n\t\t\tfor (int i = 0; i < 8; ++i)\n\t\t\t{\n\t\t\t\tamp = targeted_amp[i];\n\t\t\t\tif (amp > max2)\n\t\t\t\t{\n\t\t\t\t\tif (amp > max1) {\n\t\t\t\t\t\t// max2 = max1\n\t\t\t\t\t\tmax2 = max1;\n\t\t\t\t\t\tmax2_pos = max1_pos;\n\t\t\t\t\t\t// max1 = new\n\t\t\t\t\t\tmax1 = amp;\n\t\t\t\t\t\tmax1_pos = i;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmax2 = amp;\n\t\t\t\t\t\tmax2_pos = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Get max1, max2 freq\n\t\t\tdouble x_axis[] = \t\t\t\t \t\t{697,\n\t\t\t\t\t\t\t\t\t\t\t  \t\t 770,\n\t\t\t\t\t\t\t\t\t\t\t  \t\t 852,\n\t\t\t\t\t\t\t\t\t\t\t  \t\t 941,\n\t\t\t\t\t\t\t\t1209,1336,1477,1633};\n\n\t\t\tcout << \"Max1 pos:\" << x_axis[max1_pos] << endl;\n\t\t\tcout << \"Max2 pos:\" << x_axis[max2_pos] << endl;\n\n\t\t\t// decipher\n\t\t\tchar output_symbol = find_dtmf_symbol(x_axis[max1_pos], x_axis[max2_pos]);\n\t\t\tcout << \"The symbol for this sound: \" << output_symbol << endl;\n\n\t\t\tcout << endl;\n\n\t\t} else { // fail reading file\n\t\t\tcout << \"no such file\" << endl;\n\t\t}\n\n    }  \n\treturn 0;\n}\n\\end{lstlisting}\n\n\\subsection{DTMF\\_3.cpp --- Main function for problem 3}\\label{dtmf3}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n# include <fstream>\n# include <string>\n# include <stdio.h>\n# include <stdlib.h>\n# include <cmath>\n# include <ctime>\n# include <sstream>\n# include <iostream>\n# include <cstdlib>\n# include <unistd.h>  \n# include <dirent.h>  \n# include <sys/stat.h>  \n# define PI 3.1415926\nint const MAX_STR_LEN = 200;  \n\n# include \"complex.h\"\n# include \"goertzel.h\"\n# include \"find_dtmf_symbol.h\"\n\nusing namespace std;\n\n// Goertzel Algorithm to identify 3\nint main()\n{\n\n\t\tcout << \"Identifying Prob3, a long audio, using Goertzel Algorithm ...\" << endl << endl;\n\n\t\tifstream in(\"./txtData2/data.txt\");\n\t\tstring filename;\n\t\tstring line;\n\t\t\n\t\tif(in) // 有该文件  \n\t\t{\n\t\t\tdouble audio[60000];\n\t\t\tint count = 0;\n\t\t\twhile (getline (in, line)) // line中不包括每行的换行符\n\t\t\t{\n\t\t\t\t// audio[count] = atof(const_cast<const char *>(line.c_str()));\n\n\t\t\t\tdouble d;\n\t\t\t\tstringstream ss(line);\n\t\t\t\tss >> d;\n\t\t\t\taudio[count] = d;\n\n\t\t\t\tcount = count + 1;\n\t\t\t\t// cout << audio[count-1] << endl;\n\t\t\t}\n\n\t\t\t// Stops (in seconds)\n\t\t\tdouble stops[] = \t{0.4459, 0.6633,\n\t\t\t\t\t\t\t     0.8642, 1.072,\n\t\t\t\t\t\t\t     1.27,   1.473,\n\t\t\t\t\t\t\t     1.7,    1.89,\n\t\t\t\t\t\t\t     2.09,   2.29,\n\t\t\t\t\t\t\t     2.5,    2.722,\n\t\t\t\t\t\t\t     2.915,  3.1,\n\t\t\t\t\t\t\t     3.34,   3.549,\n\t\t\t\t\t\t\t     3.782,  4,\n\t\t\t\t\t\t\t     4.182,  4.398, \n\t\t\t\t\t\t\t     4.581,  4.794,\n\t\t\t\t\t\t\t     5.013,  5.222, \n\t\t\t\t\t\t\t     5.431,  5.641, \n\t\t\t\t\t\t\t     5.869,  6.059, \n\t\t\t\t\t\t\t     6.258,  6.447};\n\n\t\t    int len_data2 = count;\n\t\t\tdouble seconds_len_data2 = len_data2/8000.0;\n\n\t\t\tfor (int d = 0; d < 15; ++d)\n\t\t\t{\n\n\t\t\t\tint start_index = stops[d*2]/seconds_len_data2*len_data2;\n\t\t\t\tint end_index = stops[d*2+1]/seconds_len_data2*len_data2;\n\n\t\t\t\t// Get this audio\n\t\t\t\tcount = end_index - start_index + 1;\n\t\t\t\tdouble* this_audio = new double[count];\n\t\t\t\tfor (int i = 0; i < count; ++i)\n\t\t\t\t{\n\t\t\t\t\tthis_audio[i] = audio[i+start_index];\n\t\t\t\t}\n\n\t\t\t\t// is 2^k or not, if not add zero\n\t\t\t\tint add_zero_count = 0;\n\t\t\t\tfor (int i = 1; i < 100; ++i)\n\t\t\t\t{\n\t\t\t\t\tif ( pow(2,i) < count ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if ( pow(2,i) == count ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tadd_zero_count = pow(2,i) - count;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// add value to input_seq[]\n\t\t\t\tint total_length = count + add_zero_count;\n\t\t\t\tcomplex* input_seq = new complex[total_length];\n\t\t\t\tfor (int i = 0; i < count; i++)\n\t\t\t\t{\n\t\t\t\t\tinput_seq[i].re = this_audio[i];\n\t\t\t\t\tinput_seq[i].im = 0;\n\t\t\t\t}\n\t\t\t\tfor (int i = 0; i < add_zero_count; i++)\n\t\t\t\t{\n\t\t\t\t\tinput_seq[count + i].re = 0;\n\t\t\t\t\tinput_seq[count + i].im = 0;\n\t\t\t\t}\n\n\t\t\t\t// Goertzel, return amp^2\n\t\t\t\tdouble* targeted_amp = Goertzel(input_seq, total_length);\n\n\t\t\t\t// amp indicator\n\t\t\t\t// for (int ii = 0; ii < 8; ++ii)\n\t\t\t\t// {\n\t\t\t\t// \tcout << targeted_amp[ii] << endl;\n\t\t\t\t// }\n\n\t\t\t\t// Amp, Find max 1,2 and their positions\n\t\t\t\tint amp;\n\t\t\t\tint max1 = 0;\n\t\t\t\tint max2 = 0;\n\t\t\t\tint max1_pos = 0;\n\t\t\t\tint max2_pos = 0;\n\t\t\t\tfor (int i = 0; i < 8; ++i)\n\t\t\t\t{\n\t\t\t\t\tamp = targeted_amp[i];\n\t\t\t\t\tif (amp > max2)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (amp > max1) {\n\t\t\t\t\t\t\t// max2 = max1\n\t\t\t\t\t\t\tmax2 = max1;\n\t\t\t\t\t\t\tmax2_pos = max1_pos;\n\t\t\t\t\t\t\t// max1 = new\n\t\t\t\t\t\t\tmax1 = amp;\n\t\t\t\t\t\t\tmax1_pos = i;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmax2 = amp;\n\t\t\t\t\t\t\tmax2_pos = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Get max1, max2 freq\n\t\t\t\tdouble x_axis[] = \t\t\t\t \t\t{697,\n\t\t\t\t\t\t\t\t\t\t\t\t  \t\t 770,\n\t\t\t\t\t\t\t\t\t\t\t\t  \t\t 852,\n\t\t\t\t\t\t\t\t\t\t\t\t  \t\t 941,\n\t\t\t\t\t\t\t\t\t1209,1336,1477,1633};\n\n\t\t\t\tcout << \"Max1 pos:\" << x_axis[max1_pos] << endl;\n\t\t\t\tcout << \"Max2 pos:\" << x_axis[max2_pos] << endl;\n\n\t\t\t\t// decipher\n\t\t\t\tchar output_symbol = find_dtmf_symbol(x_axis[max1_pos], x_axis[max2_pos]);\n\t\t\t\tcout << \"The symbol for this sound: \" << output_symbol << endl;\n\n\t\t\t\tcout << endl;\n\n\t\t\t}\n\n\t\t} else { // fail reading file\n\t\t\tcout << \"no such file\" << endl;\n\t\t}\n\t\n\n\treturn 0;\n}\n\\end{lstlisting}\n\n\n\\subsection{complex.h}\\label{code:complex}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n/********************************************************************/\n// Complex Struct & Some Basic func\n\n\nusing namespace std;\n\ntypedef struct Complex\n{\n\tdouble re;\n\tdouble im;\n\tComplex() {\n\t\tre = 0;\n\t\tim = 0;\n\t};\n\tComplex(double a,double b) {\n\t\tre = a;\n\t\tim = b;\n\t};\n} complex;\n\n\ncomplex* append_seq(complex seq_1[], complex seq_2[], int N);\ncomplex* reorder_seq(complex input_seq[], int N);\ncomplex* Calc_WN(int N);\nint reverse_bit(int value, int N);\n\n// Multiplier\ncomplex ComplexMul(complex c1, complex c2)\n{\n\tcomplex r;\n\t\n\tr.re = c1.re*c2.re - c1.im*c2.im;\n\tr.im = c1.re*c2.im + c1.im*c2.re;\n\n\treturn r;\n}\n\n// Adder\ncomplex ComplexAdd(complex c1, complex c2)\n{\n\tcomplex r;\n\t\n\tr.re = c1.re + c2.re;\n\tr.im = c1.im + c2.im;\n\t\n\treturn r;\n}\n\n// -c\ncomplex ReverseComplex(complex c)\n{\n\tc.re = -c.re;\n\tc.im = -c.im;\n\t\n\treturn c;\n}\n\n// scalar mul\ncomplex ComplexScalarMul(complex cc, double con)\n{\n\tcomplex r;\n\t\n\tr.re = cc.re * con;\n\tr.im = cc.im * con;\n\n\treturn r;\n}\n\n// Other func\n\n\n/********************************************************************/\n// Append [seq_1] & [seq_2] to [seq_1,seq_2]\ncomplex* append_seq(complex seq_1[], complex seq_2[], int N) {\n\tcomplex* total_seq = new complex[N*2];\n\tfor (int i = 0; i < N; i++) {\n\t\ttotal_seq[i] = seq_1[i];\n\t}\n\tfor (int i = N; i < 2*N; i++) {\n\t\ttotal_seq[i] = seq_2[i-N];\n\t}\n\treturn total_seq;\n}\n\n\n/********************************************************************/\n// Reorder the input_seq to an order\ncomplex* reorder_seq(complex input_seq[], int N) {\n\n\tcout << \"Reorder the sequence ...\" << endl;\n\n\tcomplex* reordered_seq = new complex[N];\n\tfor (int i = 0; i < N; ++i)\n\t{\n\t\tint k = reverse_bit(i, log2(N));\n\t\treordered_seq[k] = input_seq[i];\n\t}\n\n\treturn reordered_seq;\n}\n\n\n/********************************************************************/\n// Reverse Bit\n\t// input: \n\t\t// a decimal num, \n\t\t// N-based reverse method\n\t// output: a decimal num\nint reverse_bit(int value, int N) {\n\n\tint ret = 0;\n\tint i = 0;\n\n\twhile (i < N) {\n\t\tret <<= 1;\n\t\tret |= (value>>i) & 1;\n\t\ti++;\n\t}\n\n\treturn ret;\n}\n\n\n/********************************************************************/\n// Calc WN[], with N = input_N\ncomplex* Calc_WN(int N) {\n\n\tcout << \"Calculating WN[] of N = \" << N << \" ...\" << endl;\n\tcomplex* WN = new complex[N];\n\n\tcomplex WN_unit; WN_unit.re = cos(2*PI/N); WN_unit.im = -sin(2*PI/N);\n\tWN[0].re=1; WN[0].im=0;\n\n\tfor (int i = 1; i < N; ++i)\n\t{\n\t\tWN[i] = ComplexMul(WN[i-1], WN_unit);\n\t}\n\n\treturn WN;\n}\n\\end{lstlisting}\n\n\\subsection{dif\\_fft.h --- FFT implementation}\\label{code:fft}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\ncomplex* DIF_FFT_reordered(complex input_seq[], int N);\ncomplex* DIF_FFT(complex input_seq[], int N, complex WN[], int recur_time_count);\n\n/********************************************************************/\n// DIF-FFT\n\t// input_seq[]: \n\t// N: size of input_seq\n\t\t// Must be a 2^k integer\ncomplex* DIF_FFT_reordered(complex input_seq[], int N) {\n\t\n\t// Initialize\n\tcomplex* reordered_seq = new complex[N];\n\t\n\t// Calc WN\n\tcomplex* WN = new complex[N];\n\tWN = Calc_WN(N);\n\n\t// Calc DIF-FFT\n\treordered_seq = DIF_FFT(input_seq, N, WN, 0);\n\t// Reorder\n\treordered_seq = reorder_seq(reordered_seq, N);\n\n\treturn reordered_seq;\n}\ncomplex* DIF_FFT(complex input_seq[], int N, complex WN[], int recur_time_count) {\n\n\t// cout << \"\\tDIF_FFT executed!\\n\"; // for validation\n\t// output seq\n\tcomplex* return_seq = new complex[N];\n\n\tif ( N != 2 ) {\n\n\t\tcomplex* first_half_seq = new complex[N/2];\n\t\tcomplex* second_half_seq = new complex[N/2];\n\n\t\tint k = pow(2,recur_time_count);\n\n\t\t// Calc\n\t\tfor (int i = 0; i < N/2; ++i) {\n\t\t\tfirst_half_seq[i] = ComplexAdd(input_seq[i], input_seq[i+N/2]) ;\n\t\t}\n\t\tfor (int i = 0; i < N/2; ++i) {\n\t\t\tsecond_half_seq[i] = ComplexMul( ComplexAdd(input_seq[i], ReverseComplex(input_seq[i+N/2])), WN[i*k] ) ;\n\t\t}\n\n\t\t// DFT\n\t\tcomplex* DFTed_first_half_seq = new complex[N/2];\n\t\tDFTed_first_half_seq = DIF_FFT(first_half_seq, N/2, WN, recur_time_count+1);\n\t\tcomplex* DFTed_second_half_seq = new complex[N/2];\n\t\tDFTed_second_half_seq = DIF_FFT(second_half_seq, N/2, WN, recur_time_count+1);\n\n\t\t// Append [DFTed_first_half_seq] & [DFTed_second_half_seq]\n\t\treturn_seq = append_seq(DFTed_first_half_seq, DFTed_second_half_seq, N/2);\n\t\treturn return_seq;\n\n\t} else if ( N == 2 ) { // Smallest Butterfly Unit\n\n\t\t// cout << \"\\tDIF_FFT N==2 triggered!\\n\"; // for validation\n\t\treturn_seq[0] = ComplexAdd(input_seq[0], input_seq[1]);\n\t\treturn_seq[1] = ComplexMul( ComplexAdd(input_seq[0], ReverseComplex(input_seq[1])), WN[0] );\n\t\treturn return_seq;\n\t\n\t}\n\n\t// return [return_seq] # unordered\n\treturn return_seq;\n}\n/********************************************************************/\n\\end{lstlisting}\n\n\n\\subsection{goertzel.h --- Goertzel implementation}\\label{code:goertzel}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n// input x[n], N\n// output: amp of the targeted 8 freq (freqs)\n\ndouble* Goertzel(complex input_seq[], int N) {\n\n\tcout << \"Calculating Goertzel ...\" << endl;\n\t// targeted freqs\n\tdouble freqs[] = \t\t\t\t \t\t{697,\n\t\t\t\t\t\t\t\t\t  \t\t 770,\n\t\t\t\t\t\t\t\t\t  \t\t 852,\n\t\t\t\t\t\t\t\t\t  \t\t 941,\n\t\t\t\t\t\t1209,1336,1477,1633};\n\n\t// Calc WN\n\tcomplex* WN = new complex[N];\n\tWN = Calc_WN(N);\n\n\tint sampling_rate = 8000;\n\n\t// Calc DFT of targeted 8 freqs\n\tcomplex targeted_X[8];\n\tcomplex* v = new complex[N];\n\n\tfor (int i = 0; i < 8; ++i)\n\t{\t\n\t\tint k = ( N * freqs[i] ) / sampling_rate;\n\t\tdouble w_k = 2 * PI * k / N;\n\n\t\t// init\n\t\tv[0] = input_seq[0];\n\t\tv[1] = ComplexAdd(input_seq[1], ComplexScalarMul(v[0], 2*cos(w_k)));\n\n\t\tfor (int j = 2; j < N; ++j)\n\t\t{\n\t\t\tv[j] = ComplexAdd(ComplexAdd(input_seq[j], ComplexScalarMul(v[j-1], 2*cos(w_k))), ReverseComplex(v[j-2]));\n\t\t}\n\n\t\ttargeted_X[i] = ComplexAdd(v[N-1], ReverseComplex(ComplexMul(WN[k], v[N-2])));\n\t}\n\n\t// Calc amp\n\tdouble* amp_targeted_X = new double[8];\n\tfor (int i = 0; i < 8; ++i)\n\t{\n\t\tamp_targeted_X[i] = pow(targeted_X[i].re,2) + pow(targeted_X[i].im,2);\n\t\t// cout << amp_targeted_X[i] << endl; // indicator\n\t}\n\n\treturn amp_targeted_X; \n}\n\\end{lstlisting}\n\n\n\\subsection{find\\_dtmf\\_symbol.h --- judge signals}\\label{code:finddtmf}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\n// Decipher\nchar find_dtmf_symbol(double a, double b)\n{\n\tchar symbol[]\t =  {'1','2','3','A',\n\t\t\t\t\t\t '4','5','6','B',\n\t\t\t\t\t\t '7','8','9','C',\n\t\t\t\t\t\t '*','0','#','D'};\n\tdouble freqs1[] = \t\t\t\t \t\t{697,\n\t\t\t\t\t\t\t\t\t  \t\t 770,\n\t\t\t\t\t\t\t\t\t  \t\t 852,\n\t\t\t\t\t\t\t\t\t  \t\t 941};\n\tdouble freqs2[] = {1209,1336,1477,1633};\n\n\t// switch if a > b, making sure a < b\n\tif (a > b) {\n\t\tint c = a;\n\t\ta = b;\n\t\tb = c;\n\t}\n\n\t// get a pos: x\n\tint x = 100;\n\tfor (int i = 0; i < 4; ++i)\n\t{\n\t\tif ( abs(freqs1[i] - a) <= 10 )\n\t\t{\n\t\t\tx = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// get b pos: y\n\tint y = 100;\n\tfor (int i = 0; i < 4; ++i)\n\t{\n\t\tif ( abs(freqs2[i] - b) <= 10 )\n\t\t{\n\t\t\ty = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (x == 100 || y == 100)\n\t{\n\t\tchar error_char = 'x';\n\t\treturn error_char;\n\t}\n\t// get return symbol\n\tchar return_symbol = symbol[ x*4 + y ];\n\n\treturn return_symbol;\n}\n\\end{lstlisting}\n\n\n\n\\subsection{read\\_wav.m --- Convert .wav files to .txt}\\label{code:readwav}\n\\begin{lstlisting}\n// Work by Lin, Tzu-Heng\n// W42, 2014011054\n// Dept. of Electronic Engineering, Tsinghua University\n// DSP Course Work\n\nclose all;clc;clear;\n\n%% Data1\ndirpath = './Data1/';\nwritepath = './txtData1/';\ndat = dir( dirpath );\nfor j = 1 : length( dat )\n    if( ~isequal( dat( j ).name, '.' ) &...\n        ~isequal( dat( j ).name, '..') )\n        datpath = [dirpath dat( j ).name];\n        [y, Fs] = audioread(datpath);\n        f = fopen([writepath dat( j ).name(1:8) '.txt'],'w');\n        fprintf(f, '%f\\n', y);\n        fclose(f);\n    end\nend\n\n%% Data2\ndatpath = './Data2/data.wav';\n[y, Fs] = audioread(datpath);\nf = fopen('./txtData2/data.txt','w');\nfprintf(f, '%f\\n', y);\nfclose(f);\n\\end{lstlisting}\n\n", "meta": {"hexsha": "2bd8bc4dae5eb266402061467124a1906edfa468", "size": 19097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/code.tex", "max_stars_repo_name": "lzhbrian/DTMF", "max_stars_repo_head_hexsha": "e2c7a4e9ee9246edd35ebb7cdddf99f102809ece", "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": "tex/code.tex", "max_issues_repo_name": "lzhbrian/DTMF", "max_issues_repo_head_hexsha": "e2c7a4e9ee9246edd35ebb7cdddf99f102809ece", "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/code.tex", "max_forks_repo_name": "lzhbrian/DTMF", "max_forks_repo_head_hexsha": "e2c7a4e9ee9246edd35ebb7cdddf99f102809ece", "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": 21.8751431844, "max_line_length": 109, "alphanum_fraction": 0.5568937529, "num_tokens": 6289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6195957906294893}}
{"text": "% Created 2021-11-23 Tue 09:03\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation,aspectratio=1610]{beamer}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble, euscript}\n\\DeclareMathOperator{\\atantwo}{atan2}\n\\newcommand*{\\ctrb}{\\EuScript{C}}\n\\newcommand*{\\obsv}{\\EuScript{O}}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{Discrete-time State feedback}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Discrete-time State feedback},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.4.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Discret-time state space model}\n\\label{sec:org94bda5c}\n\\begin{frame}[label={sec:org2a875e6}]{The discrete-time state-space model}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd0007cb}]{The discrete-time state-space model}\n\\begin{center}\n  \\begin{tikzpicture}[node distance=42mm, block/.style={inner sep=6pt, rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]\n    \\node[coordinate] (input) {};\n    \\node[block, right of=input, align=center] (plant)  {$x(k+1) = \\Phi x(k) + \\Gamma u(k)$\\\\$y(k) = C x(k)$};\n    \\node[coordinate, right of=plant] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\n\\section{PMSM - sysid}\n\\label{sec:org8f4c529}\n\n\\begin{frame}[label={sec:org4fc96f8}]{Obtain state-space model from discrete-time pulse-transfer function}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgb5bf028}]{The permanent magnet synchronous motor}\n\\begin{center}\n\\includegraphics[width=0.9\\linewidth]{../../figures/permanent-motor.jpg}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgb21b305}]{The PMSM}\n\\begin{center}\n\\includegraphics[width=0.8\\linewidth]{../../figures/pmsm_control_block_diag.png}\n\\end{center}\n{\\footnotesize Liu and Li  ``Speed control for PMSM servo system'', IEEE Transactions on Industrial Electronics, 2012.}\n\\end{frame}\n\\begin{frame}[label={sec:org4b44d9c}]{Identified model}\nTwo poles, two zeros, one delay\n\\begin{center}\n  \\begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=10mm}, sumnode/.style={circle, draw, inner sep=2pt}]\n\n    \\node[coordinate] (input) {};\n    \\node[block, right of=input] (delay1)  {$\\frac{1}{z}$};\n    \\node[block, right of=delay1, node distance=30mm] (plant)  {$\\frac{b_0z^2 + b_1z + b_2}{z^2 + a_1 z + a_2}$};\n    \\node[coordinate, right of=plant] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (delay1);\n    \\draw[->] (delay1) -- node[above, pos=0.3] {} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n\n    \\begin{scope}[yshift=-1cm, xshift = 3cm]\n    \\node {$\\Updownarrow$};\n    \\end{scope}\n    \\begin{scope}[yshift=-3cm, xshift = 3cm]\n    \\node {$\\Updownarrow$};\n    \\end{scope}\n\n    \\node[coordinate, below of=input, node distance=2cm] (input2) {};\n    \\node[block, right of=input2, node distance=30mm] (plant)  {$\\frac{b_0z^2 + b_1z + b_2}{z^2 + a_1 z + a_2}$};\n    \\node[block, right of=plant] (delay2)  {$\\frac{1}{z}$};\n    \\node[coordinate, right of=delay2] (output) {};\n\n    \\draw[->] (input2) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, pos=0.3] {} (delay2);\n    \\draw[->] (delay2) -- node[above, near end] {$y(k)$} (output);\n\n    \\node[coordinate, below of=input2, node distance=2cm] (input3) {};\n    \\node[block, right of=input3, node distance=30mm] (plant)  {$\\frac{b_0z^2 + b_1z + b_2}{z(z^2 + a_1 z + a_2})$};\n    \\node[coordinate, right of=plant, node distance=30mm] (output) {};\n\n    \\draw[->] (input3) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n\n\n\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org50003c7}]{Identified model}\n\\[ H(z) = \\frac{6.91z^2 + 16.48z -17.87}{z(z^2 - 1.766z + 0.7665)} = \\frac{6.91(z+3.19)(z-0.81)}{z(z-0.998)(z-0.768)}\\]\n\\end{frame}\n\n\\begin{frame}[label={sec:orge0a0d61}]{From pulse-transfer function to state space model}\n\\begin{center}\n  \\begin{tikzpicture}[node distance=32mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]\n\n    \\node[coordinate] (input) {};\n    \\node[block, right of=input] (plant)  {$H(z) = \\frac{b_0z^2 + b_1z + b_2}{z(z^2 + a_1 z + a_2)}$};\n    \\node[coordinate, right of=plant] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n\n    \\begin{scope}[yshift=-2cm, xshift = 3cm]\n    \\node {$\\Updownarrow$};\n    \\end{scope}\n\n    \\begin{scope}[yshift=-4cm, node distance=50mm, xshift=-2cm]\n    \\node[coordinate] (input) {};\n    \\node[block, right of=input, align=center] (plant)  {$x(k+1) = \\Phi x(k) + \\Gamma u(k)$\\\\$y(k) = C x(k)$};\n    \\node[coordinate, right of=plant] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above, near end] {$y(k)$} (output);\n    \\end{scope}\n\n\n\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org82965d6}]{Canonical forms}\nGiven pulse-transfer function \n\\[ H(z) = \\frac{b_1 z^2 + b_2 z + b_3}{z^3 + a_1z^2 + a_2z + a_3}.\\] \nFind a representation in state space form\n\\begin{align*}\n x(k+1) &= \\Phi x(k) + \\Gamma u(k) \\\\\n y(k) &= C x(k)\n \\end{align*}\n\n\\pause\n\n\\begin{itemize}\n\\item Controlable canonical form\n\\item Observable canonical form\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}[label={sec:org11e0a2a}]{Controllable canonical form}\nGiven pulse-transfer function \n\\[ H(z) = \\frac{b_1 z^2 + b_2 z + b_3}{z^3 + a_1z^2 + a_2z + a_3}.\\] \n\n\\begin{align*}\n x(k+1) &= \\begin{bmatrix} -a_1 & -a_2 & -a_3\\\\1 & 0 & 0\\\\0 & 1 & 0\\end{bmatrix} x(k) + \\begin{bmatrix}1\\\\0\\\\0\\end{bmatrix} u(k) \\\\\n y(k) &= \\begin{bmatrix} b_1 & b_2 & b_3 \\end{bmatrix} x(k)\n \\end{align*}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:orgc102ae9}]{Observable canonical form}\nGiven pulse-transfer function \n\\[ H(z) = \\frac{b_1 z^2 + b_2 z + b_3}{z^3 + a_1z^2 + a_2z + a_3}.\\] \n\n\\begin{align*}\n x(k+1) &= \\begin{bmatrix} -a_1 & 1 & 0\\\\-a_2 & 0 & 1\\\\-a_3 & 0 & 0\\end{bmatrix} x(k) + \\begin{bmatrix}b_1\\\\b_2\\\\b_3\\end{bmatrix} u(k) \\\\\n y(k) &= \\begin{bmatrix} 1 & 0 & 0 \\end{bmatrix} x(k)\n \\end{align*}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org29c6710}]{Canonical forms}\n\\alert{Activity} Find the controllable canonical form for the pulse-transfer function of the motor (needed for question 2 on the exercises).\n\n\\[ H(z) = \\frac{6.91z^2 + 16.48z -17.87}{z(z^2 - 1.766z + 0.7665)} = \\frac{6.91(z+3.19)(z-0.81)}{z(z-0.998)(z-0.768)}\\]\n\n\\pause\n\n\\begin{center}\n  \\includegraphics[width=.6\\linewidth]{../../figures/discrete-controllable.png}\n\\end{center}\n\\end{frame}\n\n\\section{Apollo moon lander}\n\\label{sec:org5cca4ce}\n\\begin{frame}[label={sec:org9930f8c}]{Discretizing a continuous-time state-space model}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd570eaa}]{Example - The Apollo lunar module}\n\\begin{center}\n\\includegraphics[width=\\linewidth]{../../figures/fig-apollo}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd51ff9a}]{Example - The Apollo lunar module}\nState variables: \\(x = \\begin{bmatrix} x_1 & x_2 & x_3 \\end{bmatrix}^T = \\begin{bmatrix} \\dot{\\theta} & \\theta & \\dot{z} \\end{bmatrix}^T\\). With dynamics\n\\[ \\begin{cases} \\dot{x}_1 =  \\ddot{\\theta} = \\frac{1}{J} u\\\\ \\dot{x}_2 = \\dot{\\theta} = x_1\\\\ \\dot{x}_3 = \\ddot{z} = g\\theta = gx_2 \\end{cases} \\]\n\n\\[ \\dot{x} = \\begin{bmatrix} \\dot{x}_1\\\\\\dot{x}_2\\\\\\dot{x}_3\\end{bmatrix} = \\underbrace{\\begin{bmatrix} \\textcolor{red!60!black}{0} & \\textcolor{red!60!black}{0} &\\textcolor{red!60!black}{0} \\\\\\textcolor{red!60!black}{1} & \\textcolor{red!60!black}{0}& \\textcolor{red!60!black}{0}\\\\ \\textcolor{red!60!black}{0}& \\textcolor{red!60!black}{g} &\\textcolor{red!60!black}{0} \\end{bmatrix}}_{A} \\begin{bmatrix} x_1\\\\x_2\\\\x_3\\end{bmatrix} + \\underbrace{\\begin{bmatrix} \\textcolor{red!60!black}{\\frac{1}{J}} \\\\ \\textcolor{red!60!black}{0} \\\\\\textcolor{red!60!black}{0}  \\end{bmatrix}}_{B} u \\]\n\\end{frame}\n\n\\section{Discretization}\n\\label{sec:org1f5260c}\n\n\\begin{frame}[label={sec:org818e46f}]{Discretization}\nThe general solution to a linear, continuous-time state-space system\n\\begin{align*}\nx(t_k+\\tau)& = \\mathrm{e}^{A(\\tau)} x(t_k) + \\int_{0}^\\tau \\mathrm{e}^{As} B u\\big((t_k+\\tau)-s) ds\n\\end{align*}\n\n\\pause\n\n\\begin{center}\n  \\begin{tikzpicture}\n    \\draw[->] (-3,0) -- (6,0) node[below] {$t$};\n    \\draw (-2, 0.2) -- ( -2, 0) node[below] {$t_k=kh$};\n    \\draw (1, 0.2) -- ( 1, 0) node[below] {$t_{k+1}=kh+h$};\n    \\draw (4, 0.2) -- ( 4, 0) node[below] {$kh+2h$};\n    \\draw[thick, orange!90!black] (-3,0.3) -- (-2, 0.3) -- (-2,1) -- (1, 1) -- (1,0.8) -- (4, 0.8) --(4, 0.5) --(5.5, 0.5) node[pos=0.1, coordinate, pin=30:{$u(t)$}] {} ; \n    \\draw[->] (-2, -0.7) -- (0, -0.7) node[below] {$\\tau$};\n  \\end{tikzpicture}\n\\end{center}\n\n\\pause\n\n \\begin{align*}\n  x(kh+h) &= \\mathrm{e}^{Ah} x(kh) + \\int_{0}^{h} \\mathrm{e}^{As} B u(kh+h-s) ds\\\\\n   &= \\underbrace{\\mathrm{e}^{Ah}}_{\\Phi(h)} x(kh) + \\underbrace{\\left(\\int_{0}^h \\mathrm{e}^{As} B ds \\right)}_{\\Gamma(h)} u(kh)\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}[label={sec:org8a9a709}]{Discretization - The matrix exponential}\n\\begin{center}\n  \\includegraphics[width=.7\\linewidth]{../../figures/dubious.png}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgf9cef9f}]{Discretization - The matrix exponential}\nSquare matrix \\(A\\). Scalar variable \\(t\\).\n\\[ \\mathrm{e}^{At} = I + At + \\frac{t^2}{2!}A^2 + \\frac{t^3}{3!} A^3 + \\cdots\\]\nLaplace transform\n\\[ \\laplace{\\mathrm{e}^{At}} = (sI - A)^{-1}\\]\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org03ba997}]{Discretization - example}\n\\small\n\n \\begin{align*}\n  x(kh+h) &= \\mathrm{e}^{Ah} x(kh) + \\int_{0}^{h} \\mathrm{e}^{As} B u(kh+h-s) ds\\\\\n   &= \\underbrace{\\mathrm{e}^{Ah}}_{\\Phi(h)} x(kh) + \\underbrace{\\left(\\int_{0}^h \\mathrm{e}^{As} B ds \\right)}_{\\Gamma(h)} u(kh)\n\\end{align*}\n\\[ A = \\begin{bmatrix} 0 & 0 & 0\\\\1 & 0 & 0\\\\0 & g & 0\\end{bmatrix}, \\quad A^2 = \\begin{bmatrix} 0 & 0 & 0\\\\1 & 0 & 0\\\\0 & g & 0\\end{bmatrix}\\begin{bmatrix} 0 & 0 & 0\\\\1 & 0 & 0\\\\0 & g & 0\\end{bmatrix}= \\begin{bmatrix} 0 & 0 & 0\\\\0 & 0 & 0\\\\g & 0  & 0\\end{bmatrix}, \\quad A^3 = 0\\]\nSo,\n\\begin{align*}\n \\Phi(h) &= \\mathrm{e}^{Ah} = I + Ah + A^2 h^2/2  + \\cdots \\\\\n\\end{align*}\n\n\\pause\n\n\\begin{align*}\n \\Phi(h) &= \\begin{bmatrix} 1 & 0 & 0\\\\0 & 1 & 0\\\\0 & 0 & 1\\end{bmatrix} + \\begin{bmatrix} 0 & 0 & 0\\\\1 & 0 & 0\\\\0 & g & 0\\end{bmatrix}h + \\begin{bmatrix} 0 & 0 & 0\\\\0 & 0 & 0\\\\g & 0 & 0\\end{bmatrix}\\frac{h^ 2}{2}= \\begin{bmatrix} 1 & 0 & 0\\\\h & 1 & 0\\\\\\frac{h^2g}{2} & hg & 1\\end{bmatrix}\n \\end{align*}\n\\end{frame}\n\n\\begin{frame}[label={sec:org568062b}]{Discretization - example}\n \\begin{align*}\n  x(kh+h) &= \\mathrm{e}^{Ah} x(kh) + \\int_{0}^{h} \\mathrm{e}^{As} B u(kh+h-s) ds\\\\\n   &= \\underbrace{\\mathrm{e}^{Ah}}_{\\Phi(h)} x(kh) + \\underbrace{\\left(\\int_{0}^h \\mathrm{e}^{As} B ds \\right)}_{\\Gamma(h)} u(kh)\n\\end{align*}\n\\[\\mathrm{e}^{As}B &=  \\begin{bmatrix} 1 & 0 & 0\\\\s & 1 & 0\\\\\\frac{s^2g}{2} & sg & 1\\end{bmatrix} \\begin{bmatrix} \\frac{1}{J}\\\\0\\\\0 \\end{bmatrix} = \\frac{1}{J} \\begin{bmatrix} 1\\\\s\\\\\\frac{gs^2}{2} \\end{bmatrix}\n  \\]\n\\begin{align*}\n\\Gamma (h) &= \\int_0^h \\mathrm{e}^{As}B ds = \\frac{1}{J} \\int_0^h \\begin{bmatrix} 1\\\\s\\\\\\frac{gs^2}{2} \\end{bmatrix}ds = \\frac{1}{J}\\begin{bmatrix} h\\\\ \\frac{h^2}{2} \\\\ \\frac{g h^3}{6} \\end{bmatrix} \n\\end{align*}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgb414f0f}]{Discretization - example}\n \\begin{align*}\n  x(kh+h) &= \\mathrm{e}^{Ah} x(kh) + \\int_{0}^{h} \\mathrm{e}^{As} B u(kh+h-s) ds\\\\\n   &= \\underbrace{\\mathrm{e}^{Ah}}_{\\Phi(h)} x(kh) + \\underbrace{\\left(\\int_{0}^h \\mathrm{e}^{As} B ds \\right)}_{\\Gamma(h)} u(kh)\\\\\n   &= \\begin{bmatrix} 1 & 0 & 0\\\\h & 1 & 0\\\\\\frac{h^2g}{2} & hg & 1\\end{bmatrix} x(kh) + \\frac{1}{J} \\begin{bmatrix} h\\\\ \\frac{h^2}{2} \\\\ \\frac{g h^3}{6} \\end{bmatrix} u(kh)\n\\end{align*}\n\\end{frame}\n\n\\section{Stability}\n\\label{sec:org3e7227a}\n\\begin{frame}[label={sec:org68f96c3}]{Stability}\n\\end{frame}\n\\begin{frame}[label={sec:org6d21b1f}]{Eigenvalues and eigenvectors}\n\\alert{Definition} The eigenvalues \\(\\lambda_i  \\in \\mathbb{R}\\) and eigenvectors \\(v_i \\in \\mathbb{R}^n\\) of a matrix \\(\\Phi \\in \\mathbb{R}^{n\\times{}n}\\) are the \\(n\\) pairs \\((\\lambda_i, v_i \\neq 0 ), \\; i=1,2,\\ldots,n\\) that satisfy\n\\[ \\Phi v_i = \\lambda_i v_i \\]\n\\end{frame}\n\n\\begin{frame}[label={sec:orgd9a48bb}]{Stability}\nThe system\n\\begin{equation*}\nx(k+1)=\\Phi x(k), \\ \\ x(0)=x_0\n\\end{equation*}\nis \\alert{stable} if  \\(\\underset{t\\to\\infty}{\\lim}x(kh)=0, \\quad \\forall\\;  x_0\\in\\Bbb{R}^n\\).\n\nA necessary and sufficient requirement for stability is that \\alert{all the eigenvalues of \\(\\Phi\\) are inside the unit circle.}\n\nThe \\alert{eigenvalues} of \\(\\Phi\\) are the  \\alert{poles} of the system.\n\\end{frame}\n\n\\section{State feedback}\n\\label{sec:org75d4b43}\n\\begin{frame}[label={sec:orgc029191}]{State feedback control}\n\\end{frame}\n\\begin{frame}[label={sec:orgb5b6f23}]{State feedback control}\nGiven\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\Phi x(k) + \\Gamma u(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:ssmodel}\n\\end{equation}\nand measurements (or an estimate) of the state vector \\(x(k)\\). \n\n\\alert{Linear state feedback} is the control law\n\\begin{equation*}\n\\begin{split}\n u(k) &= f\\big((x(k), u_c(k)\\big) = -\\textcolor{morange}{l_1}x_1(k) - \\textcolor{morange}{l_2}x_2(k) - \\cdots - \\textcolor{morange}{l_n} x_n(k) + \\textcolor{mbluegreen}{l_0}u_c(k)\\\\\n      &= -\\textcolor{morange}{L}x(k) + \\textcolor{mbluegreen}{l_0}u_c(k), \n\\end{split}\n\\end{equation*}\nwhere \\[ \\textcolor{morange}{L} = \\bbm \\textcolor{morange}{l_1} & \\textcolor{morange}{l_2} & \\cdots & \\textcolor{morange}{l_n} \\ebm. \\]\nSubstituting this in the state-space model \\eqref{eq:ssmodel} gives\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation}\n\\end{frame}\n\n\\begin{frame}[label={sec:org1f6fa3e}]{Pole placement by state feedback}\nGiven (or choosing) a desired placement of the closed-loop poles \\(p_1, p_2, \\ldots, p_n\\), being roots of the desired characteristic polynomial\n\\begin{equation}\na_c(z) = (z-p_1)(z-p_2)\\cdots(z-p_n) = z^n + \\alpha_1 z^{n-1} + \\cdots \\alpha_n.\n\\label{eq:desiredpoles}\n\\end{equation}\n\n\\pause\n\nLinear state feedback gives the system\n \\begin{equation}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation}\nwith characteristic polynomial\n\\begin{equation}\n\\det\\left(zI - (\\Phi - \\Gamma \\textcolor{morange}{L})\\right) = z^n + \\beta_1(\\textcolor{morange}{l_1},\\ldots,\\textcolor{morange}{l_n}) z^{n-1} + \\cdots \\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}).\n\\label{eq:poles}\n\\end{equation}\n\n\\pause\n\nSet the coefficients of the desired characteristic polynomial \\eqref{eq:desiredpoles} equal to the coefficients of \\eqref{eq:poles} to obtain the system of equations\n\\begin{equation*}\n\\begin{split}\n\\beta_1(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_1\\\\\n\\beta_2(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgbacb088}]{Pole placement by state feedback}\nThe system of equations\n\\begin{equation*}\n\\begin{split}\n\\beta_1(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_1\\\\\n\\beta_2(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_2\\\\\n&\\vdots\\\\\n\\beta_n(\\textcolor{morange}{l_1}, \\ldots, \\textcolor{morange}{l_n}) &= \\alpha_n\n\\end{split}\n\\label{eq:coeffs}\n\\end{equation*}\n\nis always linear in the parameters of the controller, hence\n\\begin{equation*}\nM \\textcolor{morange}{L}\\transp = \\alpha,\n\\end{equation*}\nwhere \\(\\alpha\\transp = \\bbm \\alpha_1 & \\alpha_2 & \\cdots & \\alpha_n \\ebm.\\)\n\\end{frame}\n\n\\begin{frame}[label={sec:org86c6a79},fragile]{Pole placement by state feedback}\n Given a desired placement of the closed-loop poles \\(p_1, p_2, \\ldots, p_n\\), being roots of the desired characteristic polynomial\n\\begin{equation*}\na_c(z) = (z-p_1)(z-p_2)\\cdots(z-p_n) = z^n + \\alpha_1 z^{n-1} + \\cdots \\alpha_n.\n\\label{eq:desiredpoles}\n\\end{equation*}\nand closed-loop system\n \\begin{equation*}\n \\begin{split}\n  x(k+1) &= \\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right) x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n  y(k) &= C x(k)\n \\end{split}\n \\label{eq:closedloop}\n\\end{equation*}\n\nThe Matlab (\\emph{control systems toolbox}) has methods for computing the gain vector \\(L\\)\n\n\\begin{enumerate}\n\\item \\alert{Ackerman's method} \n\\begin{verbatim}\nL = acker(Phi, Gamma, pd)\n\\end{verbatim}\n\\item \\alert{Numerically more stable method} \n\\begin{verbatim}\nL = place(Phi, Gamma, pd)\n\\end{verbatim}\n\\end{enumerate}\n\\end{frame}\n\n\\begin{frame}[label={sec:org41f1c99}]{The reference input gain \\(l_0\\)}\nThe closed-loop state space system\n\\begin{equation*}\n\\begin{split}\n x(k+1) &= \\underbrace{\\left(\\Phi -\\Gamma \\textcolor{morange}{L} \\right)}_{\\Phi_c} x(k) + \\textcolor{mbluegreen}{l_0}\\Gamma u_c(k)\\\\\n y(k) &= C x(k)\n\\end{split}\n\\end{equation*}\nwith constant reference signal \\(u_c(k) = u_{c,f}\\) has the steady-state solution (\\(x(k+1)=x(k)\\))\n\\pause\n\\[ x_f =  \\textcolor{mbluegreen}{l_0} (I - \\Phi_c)^{-1}\\Gamma u_{c,f}\\]\n\\[ y_f = Cx_f = \\textcolor{mbluegreen}{l_0} C(I - \\Phi_c)^{-1}\\Gamma u_{c,f}.\\]\nWe want \\(y_f =  u_{c,f}\\),\n\\[ \\Rightarrow \\qquad \\textcolor{mbluegreen}{l_0} = \\frac{1}{C(I-\\Phi_c)^{-1}\\Gamma}\\]\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "a4db113f1c7ebdd44674cb9dec104c5d0f1a88c6", "size": 17986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "discrete-state-space/slides/discrete-state-feedback.tex", "max_stars_repo_name": "kjartan-at-tec/mr2025", "max_stars_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "discrete-state-space/slides/discrete-state-feedback.tex", "max_issues_repo_name": "kjartan-at-tec/mr2025", "max_issues_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "discrete-state-space/slides/discrete-state-feedback.tex", "max_forks_repo_name": "kjartan-at-tec/mr2025", "max_forks_repo_head_hexsha": "88c28aa76e84890c25d252167e5bbcd25318463e", "max_forks_repo_licenses": ["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.4429824561, "max_line_length": 583, "alphanum_fraction": 0.6428889136, "num_tokens": 7253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.6195533518382438}}
{"text": "\\documentclass{beamer}\n\\usepackage{beamerthemesplit}\n\\usepackage{coqdoc}\n\n\\title{Coq: it has an unfortunate name}\n\\author{Dan Colish}\n\\date{\\today}\n\n\\begin{document}\n\\frame{\\titlepage}\n\n\\section{Intro}\n\\subsection{What is Coq?}\n\\frame\n{\n  \\frametitle{Why Prove anything at all?}\n\n  \\begin{itemize}\n    \\item Formally state mathematical theories\n    \\item Define predicate functions that can be evaluated systematically\n    \\item Verifies that a program does what we expect it to.\n  \\end{itemize}\n}\n\n\\frame {\n  \\frametitle{Computer Checking Proofs}\n  \\begin{itemize}\n    \\item Hand-written proofs are subject to mistakes\n    \\item Considered to be informal since there is no formal method of\n      checking\n    \\item Coq allows us to systematically verify proofs using the\n      Calculus of Inductive Constructions\n    \\item All decisions about Coq proofs are resolved using very\n      strong type checking\n   \\end{itemize}\n}\n\n\\frame {\n  \\frametitle{So What's it look like?}\n    Here's something simple.\n\n  \\begin{coqdoccode}\n\\scriptsize{   \\coqdockw{Theorem} \\coqlemma{acm.sillyprop}{silly\\_prop} :forall (\\coqdocvar{A} \\coqdocvar{B} \\coqdocvar{C}: \\coqdockw{Prop}), \\coqdoceol\n\\coqdocindent{1.00em}\n(\\coqdocvar{A} \\ensuremath{\\rightarrow} (\\coqdocvar{B} \\ensuremath{\\rightarrow} \\coqdocvar{C})) \\ensuremath{\\rightarrow} (\\coqdocvar{A} \\ensuremath{\\rightarrow} \\coqdocvar{B}) \\ensuremath{\\rightarrow} (\\coqdocvar{A} \\ensuremath{\\rightarrow} \\coqdocvar{C}).\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Proof}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{intros} \\coqdocvar{A} \\coqdocvar{B} \\coqdocvar{C} \\coqdocvar{H1} \\coqdocvar{HA} \\coqdocvar{H2}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{apply} \\coqdocvar{H1}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{apply} \\coqdocvar{H2}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{apply} \\coqdocvar{HA}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{assumption}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Qed}.\\coqdoceol\n}\\end{coqdoccode}\n\nAnd a little more complex...\n\n\\begin{coqdoccode}\n\\scriptsize{\n\\coqdocnoindent\n\\coqdockw{Theorem} \\coqdocvar{ex1} : \\ensuremath{\\forall} (\\coqdocvar{A} \\coqdocvar{B} \\coqdocvar{C} \\coqdocvar{D}:Prop),\\coqdoceol\n\\coqdocindent{1.00em}\n(\\coqdocvar{A} \\ensuremath{\\lor} \\coqdocvar{B}) \\ensuremath{\\rightarrow} (\\coqdocvar{B} \\ensuremath{\\land} \\coqdocvar{C}) \\ensuremath{\\rightarrow} (\\coqdocvar{B} \\ensuremath{\\rightarrow} \\coqdocvar{C}) \\ensuremath{\\lor} \\coqdocvar{D}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Proof}.\\coqdoceol\n\\coqdocnoindent\n\\coqdoctac{intros}.\\coqdoceol\n\\coqdocnoindent\n\\coqdoctac{destruct} \\coqdocvar{H0}.\\coqdoceol\n\\coqdocnoindent\n\\coqdocvar{left}.\\coqdoceol\n\\coqdocnoindent\n\\coqdoctac{intros}.\\coqdoceol\n\\coqdocnoindent\n\\coqdoctac{apply} \\coqdocvar{H1}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Qed}.\\coqdoceol\n}\\end{coqdoccode}  \n}\n\n\\frame {\n  \\frametitle{That's cool, now what?}\n  Now we can start reasoning about programs. Lets say we have the following functions on lists.\n  \nFirst we need to tell Coq how to construct a list \\begin{coqdoccode}\n\\scriptsize{\n\\coqdocnoindent\n\\coqdockw{Inductive} \\coqinductive{simplelists.natlist}{natlist} : \\coqdockw{Type} :=\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqconstructor{simplelists.nil}{nil} : \\coqinductiveref{simplelists.natlist}{natlist}\\coqdoceol\n\\coqdocindent{1.00em}\n\\ensuremath{|} \\coqconstructor{simplelists.cons}{cons} : \\coqinductiveref{Coq.Init.Datatypes.nat}{nat} \\ensuremath{\\rightarrow} \\coqinductiveref{simplelists.natlist}{natlist} \\ensuremath{\\rightarrow} \\coqinductiveref{simplelists.natlist}{natlist}.\\coqdoceol\n\\coqdocemptyline\n}\\end{coqdoccode}\nUsing this constructor we can then define lists \\begin{coqdoccode} \\scriptsize{\n\\coqdocemptyline\n\\coqdocnoindent\n\\coqdockw{Definition} \\coqdefinition{simplelists.l123}{l\\_123} := \\coqconstructorref{simplelists.cons}{cons} 1 (\\coqconstructorref{simplelists.cons}{cons} 2 (\\coqconstructorref{simplelists.cons}{cons} 3 \\coqconstructorref{simplelists.nil}{nil})).\\coqdoceol\n\\coqdocemptyline\n}\\end{coqdoccode}\nIs is trivial to add notation for easier use of the list constructor \\begin{coqdoccode}\n\\scriptsize {\n\\coqdocnoindent\n\\coqdockw{Notation} \"x :: l\" := (\\coqconstructorref{simplelists.cons}{cons} \\coqdocvar{x} \\coqdocvar{l}) (\\coqdoctac{at} \\coqdocvar{level} 60, \\coqdocvar{right} \\coqdocvar{associativity}).\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Notation} \"[ ]\" := \\coqconstructorref{simplelists.nil}{nil}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Notation} \"[ x , .. , y ]\" := (\\coqconstructorref{simplelists.cons}{cons} \\coqdocvar{x} .. (\\coqconstructorref{simplelists.cons}{cons} \\coqdocvar{y} \\coqconstructorref{simplelists.nil}{nil}) ..).\\coqdoceol\n\\coqdocemptyline\n}\\end{coqdoccode}\n}\n\n\\frame {\n  \\frametitle{More Lists}\n  \n  Now we can define a few functions over lists \\begin{coqdoccode}\n\\scriptsize{\n    \\coqdocemptyline\n    \\coqdocnoindent\n    \\coqdockw{Fixpoint} \\coqdefinition{simplelists.repeat}{repeat} (\\coqdocvar{n} \\coqdocvar{count} : \\coqinductiveref{Coq.Init.Datatypes.nat}{nat}) \\{\\coqdockw{struct} \\coqdocvar{count}\\} : \\coqinductiveref{simplelists.natlist}{natlist} := \\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{match} \\coqdocvar{count} \\coqdockw{with}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqconstructorref{Coq.Init.Datatypes.O}{O} \\ensuremath{\\Rightarrow} \\coqconstructorref{simplelists.nil}{nil}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqconstructorref{Coq.Init.Datatypes.S}{S} \\coqdocvar{count'} \\ensuremath{\\Rightarrow} \\coqdocvar{n} :: (\\coqdefinitionref{simplelists.repeat}{repeat} \\coqdocvar{n} \\coqdocvar{count'})\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{end}.\\coqdoceol\n    \\coqdocemptyline}\n  \\end{coqdoccode}\n  The \\coqdocvar{length} function calculates the length of a\n  list. \\begin{coqdoccode}\n\\scriptsize {\n    \\coqdocemptyline\n    \\coqdocnoindent\n    \\coqdockw{Fixpoint} \\coqdefinition{simplelists.length}{length} (\\coqdocvar{l}:natlist) \\{\\coqdockw{struct} \\coqdocvar{l}\\} : \\coqinductiveref{Coq.Init.Datatypes.nat}{nat} := \\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{match} \\coqdocvar{l} \\coqdockw{with}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqconstructorref{simplelists.nil}{nil} \\ensuremath{\\Rightarrow} \\coqconstructorref{Coq.Init.Datatypes.O}{O}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqdocvar{h} :: \\coqdocvar{t} \\ensuremath{\\Rightarrow} \\coqconstructorref{Coq.Init.Datatypes.S}{S} (\\coqdefinitionref{simplelists.length}{length} \\coqdocvar{t})\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{end}.\\coqdoceol\n    \\coqdocemptyline}\n  \\end{coqdoccode}\n  The \\coqdocvar{app} function concatenates two\n  lists. \\begin{coqdoccode}\n\\scriptsize{\n    \\coqdocemptyline\n    \\coqdocnoindent\n    \\coqdockw{Fixpoint} \\coqdefinition{simplelists.app}{app} (\\coqdocvar{l1} \\coqdocvar{l2} : \\coqinductiveref{simplelists.natlist}{natlist}) \\{\\coqdockw{struct} \\coqdocvar{l1}\\} : \\coqinductiveref{simplelists.natlist}{natlist} := \\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{match} \\coqdocvar{l1} \\coqdockw{with}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqconstructorref{simplelists.nil}{nil}    \\ensuremath{\\Rightarrow} \\coqdocvar{l2}\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\ensuremath{|} \\coqdocvar{h} :: \\coqdocvar{t} \\ensuremath{\\Rightarrow} \\coqdocvar{h} :: (\\coqdefinitionref{simplelists.app}{app} \\coqdocvar{t} \\coqdocvar{l2})\\coqdoceol\n    \\coqdocindent{1.00em}\n    \\coqdockw{end}.\\coqdoceol\n    \\coqdocemptyline\n    \\coqdocemptyline\n    \\coqdocnoindent\n    \\coqdockw{Notation} \"x ++ y\" := (\\coqdefinitionref{simplelists.app}{app} \\coqdocvar{x} \\coqdocvar{y}) \\coqdoceol\n    \\coqdocindent{10.50em}\n    (\\coqdocvar{right} \\coqdocvar{associativity}, \\coqdoctac{at} \\coqdocvar{level} 60).\\coqdoceol\n    \\coqdocemptyline}\n  \\end{coqdoccode}\n}\n\\frame{\n  \\frametitle{List Theorems}\n  One trivial theorem we can show is the indentity of a list\n  using \n \n\\begin{coqdoccode}\n\\scriptsize{\n    \\coqdocnoindent\n    \\coqdockw{Theorem} \\coqlemma{simplelists.nilapp}{nil\\_app} : \\ensuremath{\\forall} \\coqdocvar{l}:natlist,\\coqdoceol\n    \\coqdocindent{1.00em}\n    [] ++ \\coqdocvar{l} = \\coqdocvar{l}.\\coqdoceol\n    \\coqdocnoindent\n    \\coqdockw{Proof}.\\coqdoceol\n    \\coqdocindent{1.50em}\n    \\coqdoctac{reflexivity}. \\coqdockw{Qed}.\\coqdoceol}\n\\end{coqdoccode}\nA more complex theorem involving induction\n\n \\begin{coqdoccode}\n\\scriptsize{\n\\coqdocnoindent\n\\coqdockw{Theorem} \\coqdocvar{assoc\\_app} : \\ensuremath{\\forall} \\coqdocvar{l1} \\coqdocvar{l2} \\coqdocvar{l3} : \\coqdocvar{natlist}, \\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdocvar{l1} ++ (\\coqdocvar{l2} ++ \\coqdocvar{l3}) = (\\coqdocvar{l1} ++ \\coqdocvar{l2}) ++ \\coqdocvar{l3}.\\coqdoceol\n\\coqdocnoindent\n\\coqdockw{Proof}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdoctac{intros} \\coqdocvar{l1} \\coqdocvar{l2} \\coqdocvar{l3}. \\coqdoctac{induction} \\coqdocvar{l1} \\coqdockw{as} [\\ensuremath{|} \\coqdocvar{n} \\coqdocvar{l1'}].\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdocvar{Case} \"l1 = nil\".\\coqdoceol\n\\coqdocindent{2.00em}\n\\coqdoctac{reflexivity}.\\coqdoceol\n\\coqdocindent{1.00em}\n\\coqdocvar{Case} \"l1 = cons n l1'\".\\coqdoceol\n\\coqdocindent{2.00em}\n\\coqdoctac{simpl}. \\coqdoctac{rewrite} \\ensuremath{\\rightarrow} \\coqdocvar{IHl1'}. \\coqdoctac{reflexivity}. \\coqdockw{Qed}.\\coqdoceol\n}\n\\end{coqdoccode}\n}\n\n\\frame {\n  \\frametitle{Resources}\n  \\begin{itemize}\n    \\item Coq: http://coq.inria.fr/\n    \\item Software Foundations http://www.cis.upenn.edu/~bcpierce/sf/\n      (from which i heavily borrowed for these slides)\n\\end{itemize}\n}\n\n\n\n\\end{document}\n   ", "meta": {"hexsha": "1a78f32874c5d866347a704b61a92f5b2fc0e820", "size": 9531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acm-coq/acm-coq.tex", "max_stars_repo_name": "dcolish/Presentations", "max_stars_repo_head_hexsha": "50697a3f26405a916eab481b8749cfef2fa23d4b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-02-28T09:24:58.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-22T03:38:18.000Z", "max_issues_repo_path": "acm-coq/acm-coq.tex", "max_issues_repo_name": "dcolish/Presentations", "max_issues_repo_head_hexsha": "50697a3f26405a916eab481b8749cfef2fa23d4b", "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": "acm-coq/acm-coq.tex", "max_forks_repo_name": "dcolish/Presentations", "max_forks_repo_head_hexsha": "50697a3f26405a916eab481b8749cfef2fa23d4b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-17T01:28:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-17T01:28:58.000Z", "avg_line_length": 41.8026315789, "max_line_length": 266, "alphanum_fraction": 0.7423145525, "num_tokens": 3759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834649, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6195533473661281}}
{"text": "\\chapter{}\n\n\\begin{ex}\n    Let \\(\\left\\{\\mathbb{P}_{\\theta}\\right\\}_{\\theta \\in \\Theta}, \\Theta \\subseteq \\mathbb{R}\\), be an identifiable parametric family of distributions with common support, where card \\((\\Theta) \\geq 2\\). Consider the family of estimators \\(\\Delta=\\left\\{\\delta(\\mathbf{X}): \\mathbb{E}_{\\theta} \\delta^{2}<\\infty, \\theta \\in\\right.\\) \\(\\Theta\\}\\) and the loss function \\(L(\\theta, a)=(\\theta-a)^{2}\\). Prove that there does not exist an estimator \\(\\delta(\\mathbf{X})\\) for which \\(R(\\theta, \\delta)=0, \\theta \\in \\Theta\\).\n\\end{ex}\n\n\\begin{proof}\n    \\[\\begin{aligned}\n            R(\\theta, \\delta)&=EL(\\theta, \\delta)\\\\\n            &=E(\\theta^2-2\\theta\\delta(X)+\\delta^2(X))\\\\\n            &=\\theta^2-2\\theta E(\\delta(X))+E(\\delta(X))^2\\\\\n            &=\\theta^2-2\\theta E(\\delta(X))+Var(\\delta(X))+(E(\\delta(X)))^2\\\\\n            &=(\\theta-E(\\delta(X)))^2+Var(\\delta(X))\\\\\n            &\\geqslant Var(\\delta(X))>0. \n        \\end{aligned}\n    \\]\n    So, $\\forall \\theta \\in \\Theta$, $R(\\theta, \\delta)>0$. \n\\end{proof}\n\n\\begin{ex}\n    If \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma_{0}^{2}\\right), \\mu \\in \\mathbb{R}\\), where \\(\\sigma_{0}^{2}\\) is known, let \\(\\delta(\\mathbf{X})=\\sum_{i=1}^{n} c_{i} X_{i}\\) be any linear estimator of \\(\\mu\\). Show that, if \\(\\delta\\) is biased, then the quadratic risk \\(\\mathbb{E}_{\\mu}(\\delta-\\mu)^{2}\\) is unbounded. \n\\end{ex}\n\n\\begin{proof}\n    For $\\delta(X)$, \n    \\[\n        E(\\delta(X))=\\sum_{i=1}^nc_i E(X_i)=\\mu\\sum_{i=1}^nc_i. \n    \\]\n    Hence, if $\\sum c_i\\neq 1$, $\\delta(X)$ is biased. Then, \n    \\[\n        \\begin{aligned}\n            E(\\delta-\\mu)^2&=E\\left(\\sum c_iX_i\\right)^2-2\\mu^2\\sum c_i+\\mu^2\\\\\n            &=Var\\left(\\sum c_iX_i\\right)+\\left(\\mu\\sum c_i\\right)^2-2\\mu^2\\sum c_i+\\mu^2\\\\\n            &=\\sigma_0^2\\sum c_i+\\mu^2\\left(\\sum c_i-1\\right)^2. \n        \\end{aligned}\n    \\] \n    If $\\sum c_i\\neq 1$, then $\\left(\\sum c_i-1\\right)^2>0$. And $E(\\delta-\\mu)^2\\to\\infty$, when $\\left(\\sum c_i-1\\right)^2\\to \\infty$. \n\\end{proof}\n\n\\begin{ex}\n    Let \\(\\mathcal{P}=\\left\\{\\mathbb{P}_{\\theta}\\right\\}_{\\theta \\in \\Theta}\\) be a parametric family and let \\(g\\) be a measurable function. Suppose \\(g(\\theta)\\) is \\(U\\)-estimable, i.e., there exists an estimator \\(\\delta_{0}(\\mathbf{X})\\) such that \\(\\mathbb{E}_{\\theta} \\delta_{0}(\\mathbf{X})=g(\\theta), \\theta \\in \\Theta\\). Show that the class of unbiased estimators of \\(g(\\theta)\\) is given by\n    \\(\\left\\{\\delta(\\mathbf{X}): \\delta(\\mathbf{X})=\\delta_{0}(\\mathbf{X})-U_{\\delta}(\\mathbf{X})\\right.\\) for some unbiased estimator \\(U_{\\delta}(\\mathbf{X})\\) of zero \\(\\}\\).\n\\end{ex}\n\n\\begin{proof}\n    What we need to prove is $E(\\delta(X))=g(\\theta)$. Then, \n    \\[\n        \\begin{aligned}\n            E(\\delta(X))&=E(\\delta_0(X))-E(U_\\delta(X))\\\\\n            &=g(\\theta). \n        \\end{aligned}\n    \\]\n    ???\n\\end{proof}\n\n\\begin{ex}\n    Let \\(G(d \\mathbf{x})\\) be a \\(\\sigma\\)-finite measure, and let \\(\\mathcal{P}=\\{f(\\mathbf{x} \\mid \\theta) G(d \\mathbf{x})\\}_{\\theta \\in \\Theta}\\) be a family of distributions with associated measurements \\(\\mathbf{X}\\). Recall that the likelihood function is given by\n    \\[\n    \\mathcal{L}(\\theta \\mid \\mathbf{X}):=f(\\mathbf{X} \\mid \\theta)\n    \\]\n    In particular, for any given \\(\\theta, \\mathcal{L}(\\theta \\mid \\mathbf{X})\\) is a random variable. Note that the definition of likelihood function simply entails a change of perspective with respect to the generalized joint density: instead of fixing \\(\\theta\\), we now fix the sample \\(\\mathbf{X}\\). So, starting from a sample \\(\\mathbf{X}\\), further recall that the maximum likelihood estimator is defined by\n    \\[\n        \\widehat{\\theta}_{\\mathrm{ML}}=\\operatorname{argmax}_{\\theta \\in \\Theta} \\mathcal{L}(\\theta \\mid \\mathbf{X}) .\n    \\]\n    Find the maximum likelihood estimator of the following parameters under each parametric family. \n    \\begin{enumerate}[(a)]\n        \\item \\(\\widehat{\\lambda}_{\\mathrm{ML}}\\) when \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\operatorname{Poi}(\\lambda), \\lambda>0\\). \n        \\item \\(\\widehat{\\lambda}_{\\mathrm{ML}}\\) when \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\exp (\\lambda), \\lambda>0\\). \n        \\item \\(\\left(\\widehat{\\mu}_{\\mathrm{ML}}, \\widehat{\\sigma^{2}}_\\mathrm{ML}\\right)\\) when \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right), \\mu, \\sigma^{2} \\in \\mathbb{R} \\times(0, \\infty)\\) (hint: first solve for \\(\\widehat{\\mu}_{\\mathrm{ML}}\\).\n        \\item \\(\\widehat{\\theta}_{\\mathrm{ML}}\\) when \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} U[0, \\theta], \\theta>0\\). \n        \\item \\(\\widehat{\\mu^{2}}{ }_{\\mathrm{ML}}\\) when \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}(\\mu, 1), \\mu \\in \\mathbb{R}\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item The likelihood function is \n        \\[\n            f(\\lambda|X)=\\frac{\\exp(-n\\lambda)\\lambda^{\\sum x_i}}{\\prod x_i!}, \n        \\]\n        Then, \n        \\[\n            \\mathcal{L}(\\lambda)=\\log(\\lambda)\\sum x_i-n\\lambda-\\sum \\log(x_i!). \n        \\]\n        \\[\n            \\mathcal{L}'(\\lambda)=\\frac{\\sum x_i}{\\lambda}-n=0, \n        \\]\n        Therefore, \n        \\[\n            \\hat{\\lambda}_{ML}=\\bar{X}. \n        \\]\n        \\item The likelihood function is \n        \\[\n            f(\\lambda|X)=\\lambda^n\\exp\\left(-\\lambda\\sum x_i\\right), \n        \\]\n        Then, \n        \\[\n            \\mathcal{L}(\\lambda)=n\\log(\\lambda)-\\lambda\\sum x_i, \n        \\]\n        \\[\n            \\mathcal{L}'(\\lambda)=\\frac{n}{\\lambda}-\\sum x_i=0, \n        \\]\n        Therefore, \n        \\[\n            \\hat{\\lambda}_{ML}=\\frac{1}{\\bar{X}}. \n        \\]\n        \\item The likelihood function is \n        \\[\n            f(\\mu, \\sigma^2|X)=(2\\pi\\sigma^2)^{-n/2}\\exp\\left(-\\frac{1}{2\\sigma^2}\\sum(x_i-\\mu)^2\\right)\n        \\]\n        Then, \n        \\[\n            \\mathcal{L}(\\mu, \\sigma^2) = -\\frac{n\\log(2\\pi)}{2}-\\frac{n}{2}\\log(\\sigma^2)-\\frac{\\sum x_i^2}{2\\sigma^2}+\\frac{\\mu\\sum x_i}{\\sigma^2}-\\frac{n\\mu^2}{2\\sigma^2}. \n        \\]\n        \\[\n            \\mathcal{L}'(\\mu)=\\frac{\\sum x_i}{\\sigma^2}-\\frac{n\\mu}{\\sigma^2}=0, \\qquad \\hat{\\mu}_{ML}=\\bar{X}. \n        \\]\n        \\[\n            \\mathcal{L}'(\\sigma^2)=-\\frac{n}{2}\\frac{1}{\\sigma^2}+\\frac{1}{(\\sigma^2)^2}\\left(\\frac{\\sum x_i^2}{2}-\\mu\\sum x_i+\\frac{n\\mu^2}{2}\\right)=0, \n        \\]\n        \\[\n            \\widehat{\\sigma^2}_{ML}=\\frac{\\sum x_i^2-2\\mu\\sum x_i+n\\mu^2}{n}=\\frac{\\sum x_i^2}{n}-\\bar{X}^2. \n        \\]\n        \\item The likelihood function is \n        \\[\n            f(\\theta|X)=\\frac{1}{\\theta^n}\\mathbf{1}_{0\\leqslant x_{(1)}, x_{(n)}\\leqslant\\theta}, \n        \\]\n        Then, \n        \\[\n            \\mathcal{L}(\\theta)=-n\\log(\\theta), \n        \\]\n        \\[\n            \\mathcal{L}'(\\lambda)=\\frac{-n}{\\theta}<0, \n        \\]\n        Therefore, \n        \\[\n            \\hat{\\theta}_{ML}=X_{(n)}. \n        \\]\n        \\item Maximum likelihood estimator has unvari\n        \\[\n            \\mathcal{L}(\\mu) = -\\frac{n\\log(2\\pi)}{2}-\\frac{\\sum x_i^2}{2}+\\mu\\sum x_i-\\frac{n\\mu^2}{2}. \n        \\]\n        Let $t=\\mu^2$, $\\mu=\\pm\\sqrt{t}$. When $\\mu>0$, \n        \\[\n            \\mathcal{L}'(t)=\\frac{1}{2}t^{-1/2}\\sum x_i-\\frac{n}{2}=0, \\qquad \\widehat{\\mu^2}_{ML}=\\bar{X}^2. \n        \\]\n        When $\\mu<0$, \n        \\[\n            \\mathcal{L}'(t)=-\\frac{1}{2}t^{-1/2}\\sum x_i-\\frac{n}{2}=0, \\qquad \\widehat{\\mu^2}_{ML}=\\bar{X}^2. \n        \\]\n        Always positive? \n        \\item Because the invariability of ML, \\[\n            \\widehat{\\sigma}_{ML}=\\sqrt{\\widehat{\\sigma^2}_{ML}}=\\sqrt{Var(X)}. \n        \\] \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma_{0}^{2}\\right), \\mu \\in \\mathbb{R}\\). \n    \\begin{enumerate}[(a)]\n        \\item If \\(\\sigma_{0}^{2}\\) is known, find the UMVU estimators of \\(\\mu^{2}, \\mu^{3}\\) and \\(\\mu^{4}\\) (suggestion: consider \\(\\bar{X}=Y+\\mu, Y \\sim \\mathcal{N}\\left(0, \\sigma^{2} / n\\right)\\), and expand \\(\\left.\\mathbb{E}(Y+\\mu)^{k}, k \\in \\mathbb{N}\\right)\\). \n        \\item Solve the preceding problem when \\(\\sigma\\) is unknown. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\begin{itemize}\n            \\item $\\mu^2$: \n            \\[\n                \\begin{aligned}\n                    E(\\bar{X})^2&=E(Y)^2+2\\mu E(Y)+\\mu^2\\\\\n                    &=Var(Y)+(E(Y))^2+\\mu^2\\\\\n                    &=\\frac{\\sigma_0^2}{n}+\\mu^2, \n                \\end{aligned}\n            \\]\n            So, $E(\\bar{X}^2-\\sigma_0^2/n)=\\mu^2$. And $T(X)=\\bar{X}^2-\\sigma_0^2/n$ is UMVU for $\\mu^2$. \n            \\item $\\mu^3$: \n            \\[\n                \\begin{aligned}\n                    E(\\bar{X}^3)&=E(Y^3)+3\\mu E(Y^2)+3\\mu^2E(Y)+\\mu^3\\\\\n                    &=3\\mu\\frac{\\sigma^2_0}{n}+\\mu^3, \n                \\end{aligned}\n            \\]\n            So, $E(\\bar{X}^3-3\\bar{X}\\sigma_0^2/n)=\\mu^3$. $T(X)=\\bar{X}^3-3\\bar{X}\\sigma_0^2/n$ is UMVU for $\\mu^3$. \n            \\item $\\mu^4$: \n            \\[\n                \\begin{aligned}\n                    E(\\bar{X}^4)&=E(Y^4)+4\\mu E(Y^3)+6\\mu^2E(Y^2)+4\\mu^3E(Y)+\\mu^4\\\\\n                    &=3\\left(\\frac{\\sigma_0^2}{n}\\right)^4+6\\mu^2\\left(\\frac{\\sigma_0^2}{n}\\right)+\\mu^4, \n                \\end{aligned}\n            \\]\n            So, $E(\\bar{X}^4-6(\\bar{X}^2-\\sigma_0^2/n)\\sigma_0^2/n-3(\\sigma_0^2/n)^4)=\\mu^4$. $T(X)=\\bar{X}^4-6(\\bar{X}^2-\\sigma_0^2/n)\\sigma_0^2/n-3(\\sigma_0^2/n)^4$ is UMVU for $\\mu^4$. \n        \\end{itemize}\n        \\item Because $S^2$ is UMVU for $\\sigma_0^2$, replacing $\\sigma_0^2$ with $S^2$ can get the results. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    If \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\), where one of the parameters is known, and the estimator is a polynomial in \\(\\mu\\) or \\(\\sigma\\). Then, clearly, the UMVU estimator is a polynomial in \\(\\bar{X}\\) or \\(S_{*}^{2}:=\\sum_{i=1}^{n}\\left(X_{i}-\\mu\\right)^{2}\\). The variance of any such polynomial can be estimated if one knows the moments \\(\\mathbb{E}\\left(\\bar{X}^{k}\\right)\\) and \\(\\mathbb{E}\\left(S_{*}^{k}\\right), k \\in \\mathbb{N}\\). To determine \\(\\mathbb{E}\\left(\\bar{X}^{k}\\right)\\), write \\(\\bar{X}=Y+\\mu\\), where \\(Y \\sim \\mathcal{N}\\left(0, \\sigma^{2} / n\\right) .\\)\n    \\begin{enumerate}[(a)]\n        \\item Show that\n        \\[\n        \\mathbb{E}\\left(\\bar{X}^{k}\\right)=\\sum_{r=0}^{k}\\left(\\begin{array}{l}\n        k \\\\\n        r\n        \\end{array}\\right) \\mu^{k-r} E\\left(Y^{r}\\right)\n        \\]\n        with\n        \\[\n        \\mathbb{E}\\left(Y^{r}\\right)=\\left\\{\\begin{array}{cc}\n        (r-1)(r-3) \\ldots(3)(1)\\left(\\sigma^{2} / n\\right)^{r / 2}, & r \\geq 2 \\text { is even } \\\\\n        0, & r \\text { is odd. }\n        \\end{array}\\right.\n        \\]\n        \\item As an example, consider the UMVU estimator \\(S_{*}^{2} / n\\) of \\(\\sigma^{2}\\). Show that \\(\\mathbb{E}\\left(S_{*}^{4}\\right)=\\) \\(n(n+2) \\sigma^{4}\\) and \\(\\operatorname{Var}\\left(S_{*}^{2} / n\\right)=2 \\sigma^{4} / n\\), and that the UMVU estimator of this variance is \\(2 S_{*}^{4} / n^{2}(n+2)\\).\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\), where both parameters are unknown. \n    \\begin{enumerate}[(a)]\n        \\item Show that the UMVU estimator of \\(\\mu^{2}\\) is given by\n        \\[\n        \\delta(\\mathbf{X})=\\bar{X}^{2}-\\frac{S^{2}}{n}; \n        \\]\n        \\item Determine \\(Var\\delta(\\mathbf{X})\\); \n        \\item Find the UMVU estimator of \\(Var \\delta(\\mathbf{X})\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n    If \\(X \\sim \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right.\\)) (i.e., \\(n=1\\)), show that no unbiased estimator \\(\\delta\\) of \\(\\sigma^{2}\\) exists when \\(\\mu\\) in unknown (suggestion: for fixed \\(\\sigma=\\sigma_{0}, X\\) is a complete and sufficient statistic for \\(\\mu\\). Now consider \\(\\mathbb{E} \\delta(X)=\\sigma_{0}^{2}\\), and conclude that \\(\\delta(X)\\) is a constant a.s.)\n\\end{ex}\n\n\\begin{ex}\n    Let \\(X \\sim \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right)\\) (i.e., \\(n=1\\)), where both parameters are unknown. Fix \\(u \\in \\mathbb{R}\\). Show that the UMVU estimator of\n    \\[\n    p:=\\mathbb{P}(X \\leq u)\n    \\]\n    is \\(1_{\\{X \\leq u\\}}\\). \n\\end{ex}\n\n\\begin{ex}\n    Consider two independent samples \\(X_{1}, \\ldots, X_{m} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu_{1}, \\sigma_{1}^{2}\\right), Y_{1}, \\ldots, Y_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu_{2}, \\sigma_{2}^{2}\\right)\\). \n    \\begin{enumerate}[(a)]\n        \\item Assume \\(\\sigma_{1}^{2}=\\sigma_{2}^{2}=: \\sigma^{2}\\) (unknown). Determine the UMVU estimators of \\(\\sigma^{2}\\) and \\(\\left(\\mu_{2}-\\mu_{1}\\right) / \\sigma\\). \n        \\item Now assume \\(\\mu_{1}=\\mu_{2}\\) (unknown), and \\(\\sigma_{1}^{2} / \\sigma_{2}^{2}=\\gamma\\), where \\(\\gamma\\) is known. Prove that: \n        \\begin{enumerate}[(i)]\n            \\item \\(T^{\\prime}(\\mathbf{X}, \\mathbf{Y})=\\left(\\sum X_{i}^{2}+\\gamma \\sum Y_{j}^{2}, \\sum X_{i}+\\gamma \\sum Y_{j}\\right)\\) is a complete and sufficient statistic. \n            \\item The estimator\n            \\[\n                \\delta_{\\gamma}(\\mathbf{X}, \\mathbf{Y})=\\alpha \\bar{X}+(1-\\alpha) \\bar{Y}, \\quad \\alpha=\\frac{\\sigma_{2}^{2} / n}{\\sigma_{1}^{2} / m+\\sigma_{2}^{2} / n}\n            \\]\n            is UMVU for \\(\\mu\\). \n        \\end{enumerate}\n        \\item Now assume \\(\\mu_{1}=\\mu_{2}\\) (unknown), and \\(\\sigma_{1}^{2} / \\sigma_{2}^{2}=\\gamma\\) is also unknown. We want to prove that the UMVU estimator of \\(\\mu\\) does not exist. \n        \\begin{enumerate}[(i)]\n            \\item Fix two parameter values \\(\\gamma_{1}\\) and \\(\\gamma_{2}\\). Define the estimators\n            \\[\n            \\delta_{\\gamma_{i}}(\\mathbf{X}, \\mathbf{Y})=\\alpha_{i} \\bar{X}+\\left(1-\\alpha_{i}\\right) \\bar{Y}, \\quad \\alpha_{i}=\\frac{1 / n}{\\gamma_{i} / m+1 / n}, \\quad i=1,2,\n            \\]\n            where \\(\\alpha_{1}\\) and \\(\\alpha_{2}\\) are regarded as fixed constants. Let \\(\\xi_{1}(\\mathbf{X}, \\mathbf{Y}), \\xi_{2}(\\mathbf{X}, \\mathbf{Y})\\) be unbiased estimators of \\(\\mu\\) which are not a.s.-equal to \\(\\delta_{\\gamma_{1}}\\) and \\(\\delta_{\\gamma_{2}}\\), respectively. Conclude that\n            \\[\n            \\begin{array}{ll}\n            \\operatorname{Var}_{\\mu_{1}, \\gamma_{1}}\\left(\\delta_{\\gamma_{1}}\\right)<\\operatorname{Var}_{\\mu_{1}, \\gamma_{1}}\\left(\\xi_{1}\\right), & \\exists \\mu_{1} \\in \\mathbb{R} \\\\\n            \\operatorname{Var}_{\\mu_{2}, \\gamma_{2}}\\left(\\delta_{\\gamma_{2}}\\right)<\\operatorname{Var}_{\\mu_{2}, \\gamma_{2}}\\left(\\xi_{2}\\right), & \\exists \\mu_{2} \\in \\mathbb{R}. \n            \\end{array}\n            \\]\n            \\item Prove that \\(\\delta_{\\gamma_{1}}\\) and \\(\\delta_{\\gamma_{2}}\\) are not a.s.-equal estimators for every pair \\(\\mu, \\gamma\\). Conclude that the UMVU estimator of \\(\\mu\\) does not exist. \n        \\end{enumerate}\n        \\item Still assuming that \\(\\mu_{1}=\\mu_{2}\\) (unknown), and that \\(\\sigma_{1}^{2} / \\sigma_{2}^{2}=\\gamma\\) is also unknown, prove that the estimator \\(\\widehat{\\mu}:=\\widehat{\\alpha} \\bar{X}+(1-\\widehat{\\alpha}) \\bar{Y}\\), where \\(\\widehat{\\alpha}\\) is a function only of \\(S_{X}^{2}\\) and \\(S_{Y}^{2}\\), is unbiased for \\(\\mu\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n    Let \\(\\left(X_{1}, Y_{1}\\right), \\ldots,\\left(X_{n}, Y_{n}\\right) \\stackrel{\\text { i.i.d. }}{\\sim} N_{2}(\\mu, \\Sigma)\\), i.e., \n    \\[\n    \\begin{gathered}\n    f(\\mathbf{x}, \\mathbf{y} \\mid \\theta)=f(\\mathbf{x}, \\mathbf{y} \\mid \\mu, \\Sigma)=\\left(\\frac{1}{2 \\pi \\sigma_{1} \\sigma_{2} \\sqrt{1-\\rho^{2}}}\\right)^{n} \\\\\n    \\exp \\left(-\\frac{1}{2\\left(1-\\rho^{2}\\right)}\\left(\\frac{1}{\\sigma_{1}^{2}} \\sum_{i=1}^{n}\\left(X_{i}-\\mu_{1}\\right)^{2}+\\frac{1}{\\sigma_{2}^{2}} \\sum_{i=1}^{n}\\left(Y_{i}-\\mu_{2}\\right)^{2}-\\frac{2 \\rho}{\\sigma_{1} \\sigma_{2}} \\sum_{i=1}^{n}\\left(X_{i}-\\mu_{1}\\right)\\left(Y_{i}-\\mu_{2}\\right)\\right)\\right), \\\\\n    \\left(\\mu, \\sigma^{2}, \\rho\\right) \\in \\mathbb{R} \\times(0, \\infty) \\times(-1,1) .\n    \\end{gathered}\n    \\]\n    \\begin{enumerate}\n        \\item Conclude that \\(T(\\mathbf{X}, \\mathbf{Y})=\\left(\\bar{X}, \\bar{Y}, S_{X}^{2}, S_{Y}^{2}, S_{X Y}\\right)\\) is a complete and sufficient statistic. \n        \\item Conclude that \\(S_{X Y}\\) is UMVU for \\(\\operatorname{Cov}\\left(X_{1}, Y_{1}\\right)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n    Let \\(X_{1}, \\ldots, X_{n}\\) be an i.i.d. sample from the (nonparametric) family \\(\\mathcal{P}\\) which encompasses all a.c. distributions in \\(\\mathbb{R}\\). Show that the order statistics are complete. (hint: establish the following facts. \n    \\begin{enumerate}[(i)]\n        \\item Let \\(\\mathcal{P}_{0} \\subseteq \\mathcal{P}_{1}\\) be two families of distributions such that, for a Borel set \\(B\\),\n        \\[\n        \\mathbb{P}_{\\theta}(B)=0, \\quad \\theta \\in \\mathcal{P}_{0} \\Rightarrow \\mathbb{P}_{\\theta}(B)=0, \\quad \\theta \\in \\mathcal{P}_{1} .\n        \\]\n        If a statistic \\(T\\) is complete for \\(\\mathcal{P}_{0}\\), then it is also complete for \\(\\mathcal{P}_{1}\\); \n        \\item note that \\(\\mathcal{P}\\) in the statement of the problem includes the a.c. canonical exponential family\n        \\[\n        q(\\mathbf{x} \\mid \\eta)=h(\\mathbf{x}) \\exp \\left\\{\\eta_{1} \\sum_{i=1}^{n} x_{i}+\\eta_{2} \\sum_{i=1}^{n} x_{i}^{2}+\\ldots+\\eta_{n} \\sum_{i=1}^{n} x_{i}^{n}-A(\\boldsymbol{\\eta})\\right\\}\n        \\]\n        where \\(h(\\mathbf{x})>0\\) has fast enough decay at \\(\\|\\mathbf{x}\\| \\rightarrow \\infty\\). Now show that\n        \\[\n        \\left(\\sum_{i=1}^{n} x_{i}, \\sum_{i=1}^{n} x_{i}^{2}, \\ldots, \\sum_{i=1}^{n} x_{i}^{n}\\right)\n        \\]\n        is equivalent to the vector of order statistics). \n    \\end{enumerate}\n\\end{ex}\n\n\n\\begin{ex}\n    We say that an estimator \\(\\delta(\\mathbf{X})=\\delta\\left(X_{1}, \\ldots, X_{n}\\right)\\) is symmetric in its \\(n\\) arguments if\n    \\[\n    \\delta\\left(X_{1}, \\ldots, X_{n}\\right)=\\delta\\left(X_{\\pi_{1}}, \\ldots, X_{\\pi_{n}}\\right)\n    \\]\n    for any permutation \\(\\pi=\\left(\\pi_{1}, \\ldots, \\pi_{n}\\right)\\) of its indices \\(1, \\ldots, n(\\) e.g., \\(\\delta(\\mathbf{X})=\\bar{X})\\). \n\n    Let \\(\\mathcal{P}=\\{F\\}\\) be a (nonparametric) family of distributions for which the order statistics \\(X_{(1)} \\leq \\ldots \\leq X_{(n)}\\) are complete and sufficient. Let \\(g(F)\\) be a \\(U\\)-estimable quantity and assume that the symmetric estimator \\(\\delta(\\mathbf{X})\\) is such that \\(\\mathbb{E}_{F} \\delta(\\mathbf{X})=g(F)\\). Prove that \\(\\delta(\\mathbf{X})\\) is UMVU for \\(g(F)\\). \n\\end{ex}\n\n\n\\begin{ex}\n    Let \\(\\mathcal{P}=\\{F\\}\\) be a (nonparametric) family of distributions in \\(\\mathbb{R}\\) which includes all a.c. distributions, and consider \\(g(F)=\\mathbb{P}(X \\leq a)=F(a)\\), \\(a\\) being a known constant. Let \\(X_{1}, \\ldots, X_{n}\\) be an i.i.d. sample, where \\(X_{1} \\sim F\\), and define the estimator\n    \\[\n    \\widehat{F}_{n}(a):=\\frac{\\#\\left\\{i: X_{i} \\leq a\\right\\}}{n}\n    \\]\n    (as a function of \\(a \\in \\mathbb{R}, \\widehat{F}_{n}(a)\\) is called the empirical distribution function). \n    \\begin{enumerate}[(a)]\n        \\item Show that \\(\\widehat{F}_{n}(a)\\) is unbiased for \\(\\mathbb{P}(X \\leq a)\\). \n        \\item Show that \\(\\widehat{F}_{n}(a)\\) is a symmetric estimator. \n        \\item Conclude that \\(\\widehat{F}_{n}(a)\\) is UMVU for \\(\\mathbb{P}(X \\leq a)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\n\\begin{ex}\n    Consider the (nonparametric) family\n    \\(\\mathcal{P}=\\left\\{\\right.\\) i.i.d. sample \\(X_{1}, \\ldots, X_{n}\\) from a d.f. \\(F\\) with a.c. density \\(f\\) and finite fourth moment \\(\\} .\\)\n    Let\n    \\[\n    g(F)=\\mathbb{E} X_{1}, \\quad h(F)=\\operatorname{Var} X_{1}\n    \\]\n    be two estimators. \n    \\begin{enumerate}\n        \\item Prove that \\(\\mathbb{E}\\left(X_{1} \\mid X_{(1)}, \\ldots, X_{(n)}\\right)\\) is UMVU for \\(g(F)\\). \n        \\item Prove that \\(\\bar{X}\\) is UMVU for \\(g(F)\\). \n        \\item Conclude that \\(\\mathbb{E}\\left(X_{1} \\mid X_{(1)}, \\ldots, X_{(n)}\\right)=\\bar{X} \\mathcal{P}\\)-a.s. \n        \\item Prove that \\(S^{2}\\) is UMVU for \\(h(F)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\n\\begin{ex}\n    Let \\(\\mathcal{P}\\) be the nonparametric family \\((0.1)\\), and let \\(g(F)\\) be an estimator. \n    \\begin{enumerate}\n        \\item For \\(r \\leq n\\), let \\(\\delta\\left(X_{i_{1}}, \\ldots, X_{i_{r}}\\right) \\in \\Delta\\) be an unbiased estimator for \\(g(F)\\). Show that there exists a symmetric, unbiased estimator for \\(g(F)\\). Conclude that we can assume without loss of generality that \\(\\delta\\left(X_{i_{1}}, \\ldots, X_{i_{r}}\\right)\\) is symmetric. \n        \\item The random variable\n        \\[\n        U(\\mathbf{X})=\\left(\\begin{array}{l}\n        n \\\\\n        r\n        \\end{array}\\right)^{-1} \\sum_{1 \\leq i_{1}<\\ldots<i_{r} \\leq n} \\delta\\left(X_{i_{1}}, \\ldots, X_{i_{r}}\\right)\n        \\]\n        is called an \\(r\\)-degree \\(U\\)-statistic for \\(g(F)\\). Prove that \\(U(\\mathbf{X})\\) is UMVU for \\(g(F)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\n\\begin{ex}\n    Let \\(\\mathcal{P}\\) be the nonparametric family \\((0.1)\\), and let \\(g(F)=\\mu^{2}\\) be the estimator, where \\(\\mathbb{E} X_{1}=\\mu\\). \n    \\begin{enumerate}\n        \\item Prove that \\(\\mathbb{E}\\left(X_{1} X_{2} \\mid X_{(1)}, \\ldots, X_{(n)}\\right)\\) is UMVU for \\(\\mu^{2}\\). \n        \\item Compute the conditional probability\n        \\[\n        \\mathbb{P}\\left(X_{1} X_{2}=x_{(i)} x_{(j)} \\mid X_{(1)}=x_{(1)}, \\ldots, X_{(n)}=x_{(n)}\\right), \\quad i \\neq j\n        \\]\n        and conclude that\n        \\[\n        \\widehat{\\mu^{2}} \\mathrm{UMVU}=\\frac{1}{n(n-1)} \\sum_{i \\neq j} X_{i} X_{j}. \n        \\]\n        \\item Conclude that the \\(\\widehat{\\mu^{2}}\\) UMVU is a \\(U\\)-statistic and find its degree. \n    \\end{enumerate}\n\\end{ex}\n\n", "meta": {"hexsha": "579d323781b48092284605ded01480b2749372a4", "size": 21784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/set4.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/set4.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/set4.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": 55.8564102564, "max_line_length": 645, "alphanum_fraction": 0.5368160118, "num_tokens": 8237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385543, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6195533439977998}}
{"text": "\\subsection{Category adjunctions}\\label{subsec:category_adjunctions}\n\n\\begin{remark}\\label{rem:adjoint_functors}\\cite{StanfordPlato:category_theory}\n  When the functor \\( G: \\cat{D} \\to \\cat{C} \\) is left adjoint to \\( F: \\cat{C} \\to \\cat{D} \\) and \\( F \\) is not invertible, then \\( G \\) finds a \\enquote{generalized inverse} under \\( F \\) for every object in \\( \\cat{C} \\) that try to \\enquote{act the same} with respect to morphisms.\n\n  \\Fullref{def:category_adjunction} contains two equivalent definition of an adjunction, and \\fullref{rem:universal_mapping_property} describes how they can be characterized via universal mapping properties.\n\\end{remark}\n\n\\begin{definition}\\label{def:category_adjunction}\\mcite[sec. 2.2]{Leinster2016Basic}\n  An \\term{adjunction} between the \\hyperref[def:category]{categories} \\( \\cat{C} \\) and \\( \\cat{D} \\) can be defined in several equivalent ways. Let \\( F: \\cat{C} \\to \\cat{D} \\) and \\( G: \\cat{D} \\to \\cat{C} \\) be arbitrary functors.\n\n  In all the cases below, if there exists an adjunction between \\( F \\) and \\( G \\), we say that \\( F \\) is \\term{left adjoint} to \\( G \\) and, correspondingly, that \\( G \\) is \\term{right adjoint} to \\( F \\). A conventional notation for adjoint functors is \\( F \\dashv G \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:category_adjunction/hom} A \\term{hom-adjunction} is a triple \\( (F, G, \\varphi) \\), where \\( \\varphi \\) is \\hyperref[thm:natural_isomorphism]{natural isomorphism}\n    \\begin{equation}\\label{eq:def:category_adjunction/hom}\n      \\varphi: \\cat{D}(F(\\anon*), \\anon*) \\Rightarrow \\cat{C}(\\anon*, G(\\anon*)).\n    \\end{equation}\n\n    The functors\n    \\begin{align*}\n      &\\cat{D}(F(\\anon*), \\anon*): \\cat{C}^{\\opcat} \\times \\cat{D} \\to \\cat{Set}, \\\\\n      &\\cat{C}(\\anon*, G(\\anon*)): \\cat{C}^{\\opcat} \\times \\cat{D} \\to \\cat{Set}\n    \\end{align*}\n    are straightforward modifications of the \\hyperref[eq:def:hom_functor/binary]{binary hom-functor} on \\( \\cat{C} \\).\n\n    Naturality of \\( \\varphi \\) in this case means that, for every two morphisms \\( f: B \\to A \\) in \\( \\cat{C} \\) and \\( g: X \\to Y \\) in \\( \\cat{D} \\), the following diagram commutes:\n    \\begin{equation}\\label{eq:def:category_adjunction/varphi_nat}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__category_adjunction.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    \\thmitem{def:category_adjunction/unit_counit} A \\term{unit-counit adjunction} is a quadruple \\( (F, G, \\eta, \\varepsilon) \\), where\n    \\begin{equation}\\label{eq:def:category_adjunction/unit_counit/signature}\n      \\begin{aligned}\n               \\eta &: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F, \\\\\n        \\varepsilon &: F \\bincirc G \\Rightarrow \\id_{\\cat{D}}\n      \\end{aligned}\n    \\end{equation}\n    are natural transformations satisfying the condition that, for any pair of objects \\( A \\) in \\( \\cat{C} \\) and \\( Y \\) in \\( \\cat{D} \\), the following triangle diagrams commute:\n\n    \\begin{minipage}{0.43\\textwidth}\n      \\begin{equation}\\label{eq:def:category_adjunction/d_triangle}\n        \\begin{aligned}\n          \\includegraphics[page=2]{output/def__category_adjunction.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{minipage}\n    \\hfill\n    \\begin{minipage}{0.44\\textwidth}\n      \\raggedright\n      \\begin{equation}\\label{eq:def:category_adjunction/c_triangle}\n        \\begin{aligned}\n          \\includegraphics[page=3]{output/def__category_adjunction.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{minipage}\n    \\smallskip\n\n    Note that an adjunction is not an \\hyperref[def:category_equivalence]{equivalence}, they simply have a common setup. Similarly to \\hyperref[def:category_equivalence]{equivalence}, we call the \\hyperref[def:natural_transformation]{natural transformation} \\( \\eta \\) the \\term{unit} of the adjunction and \\( \\varepsilon \\) the \\term{counit}.\n  \\end{thmenum}\n\\end{definition}\n\\begin{defproof}\n  \\ImplicationSubProof{def:category_adjunction/hom}{def:category_adjunction/unit_counit} Let \\( (F, G, \\varphi) \\) be a hom-adjunction.\n\n  For every morphism \\( f: B \\to A \\) in \\( \\cat{C} \\), from the naturality of \\( \\varphi \\) we have\n  \\begin{equation}\\label{eq:def:category_adjunction/varphi_eta}\n    \\begin{aligned}\n      \\includegraphics[page=4]{output/def__category_adjunction.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Since \\( \\varphi_{A,F(B)} \\) is a morphism in \\( \\cat{Set} \\), it is a function, and we can apply it in order to define the family\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\eta: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F, \\\\\n      &\\eta_A \\coloneqq \\varphi_{A,F(A)}(\\id_{F(A)}).\n    \\end{aligned}\n  \\end{equation*}\n\n  We must show that \\( \\eta \\) is a natural transformation. On the diagram \\eqref{eq:def:category_adjunction/varphi_eta}, we can start in the top left corner with \\( F(\\id_A) \\) and top right corner with \\( F(\\id_B) \\) and reach the middle.\n\n  We obtain that,\n  \\begin{equation*}\n    \\cat{C}(f, [G \\bincirc F](\\id_A))\\parens[\\Big]{ \\underbrace{\\varphi_{A, F(A)}(\\id_A)}_{\\eta_A} }\n    =\n    \\eta_A \\bincirc f\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\cat{C}(\\id_B, [G \\bincirc F](f))\\parens[\\Big]{ \\underbrace{\\varphi_{B, F(B)}(\\id_B)}_{\\eta_B} }\n    =\n    [G \\bincirc F](f) \\bincirc \\eta_B\n  \\end{equation*}\n  are equal. That is, the following diagram commutes:\n  \\begin{equation}\\label{eq:def:category_adjunction/eta_nat}\n    \\begin{aligned}\n      \\includegraphics[page=5]{output/def__category_adjunction.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  In order to define the natural transformation \\( \\varepsilon: F \\bincirc G \\Rightarrow \\id_{\\cat{D}} \\), we use the inverse transformation \\( \\varphi^{-1} \\). For every morphism \\( g: X \\to Y \\) in \\( \\cat{D} \\), we have\n  \\begin{equation}\\label{eq:def:category_adjunction/varphi_varepsilon}\n    \\begin{aligned}\n      \\includegraphics[page=6]{output/def__category_adjunction.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Thus, we define the family\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\varepsilon: F \\bincirc G \\Rightarrow \\id_{\\cat{D}}, \\\\\n      &\\varepsilon_X \\coloneqq \\varphi_{G(X),X}^{-1}(\\id_{G(X)}).\n    \\end{aligned}\n  \\end{equation*}\n\n  We can prove that \\( \\varepsilon \\) is a natural transformation analogously to how we proved it for \\( \\eta \\), and we will skip the details.\n\n  We will now show that the triangle diagram \\eqref{eq:def:category_adjunction/d_triangle} commutes. Consider the morphism \\( (\\eta_A, F(\\id_A)) \\) in \\( \\cat{C}^{\\opcat} \\times \\cat{D} \\). Applying the functors \\( \\cat{D}(F(\\anon*), \\anon*) \\) and \\( \\cat{D}(\\anon*, G(\\anon*)) \\) to this morphism and using the naturality of \\( \\varphi \\), we obtain\n  \\begin{equation}\\label{eq:def:category_adjunction/d_triangle_proof}\n    \\begin{aligned}\n      \\includegraphics[page=7]{output/def__category_adjunction.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Note that \\( \\varepsilon_{F(A)} \\) is a member of \\( \\cat{D}([F \\bincirc G \\bincirc F](A), F(A)) \\).\n\n  Composing the functions in \\eqref{eq:def:category_adjunction/d_triangle_proof} in one direction, we obtain\n  \\begin{balign*}\n    &\\phantom{{}={}}\n    \\varphi_{A,F(A)}^{-1} \\parens[\\Bigg]{ \\cat{C}\\parens[\\Big]{ \\eta_A, [G \\bincirc F](\\id_A) } \\parens[\\Big]{ \\varphi_{[G \\bincirc F](A),F(A)} (\\varepsilon_{F(A)}) } }\n    = \\\\ &=\n    \\varphi_{A,F(A)}^{-1} \\parens[\\Bigg]{ \\parens[\\Big]{ \\varphi_{[G \\bincirc F](A),F(A)} (\\varepsilon_{F(A)}) } \\bincirc \\eta_A }\n    = \\\\ &=\n    \\varphi_{A,F(A)}^{-1} \\parens[\\Big]{ \\id_{[G \\bincirc F](A)} \\bincirc \\eta_A }\n    = \\\\ &=\n    \\id_{F(A)}.\n  \\end{balign*}\n\n  Composing the functions in \\eqref{eq:def:category_adjunction/d_triangle_proof} in the other direction, we obtain\n  \\begin{equation*}\n    \\cat{D}\\parens[\\Big]{ F(\\eta_A), F(\\id_A) } (\\varepsilon_{F(A)})\n    =\n    \\varepsilon_{F(A)} \\bincirc F(\\eta_A).\n  \\end{equation*}\n\n  Therefore,\n  \\begin{equation*}\n    \\id_{F(A)} = \\varepsilon_{F(A)} \\bincirc F(\\eta_A).\n  \\end{equation*}\n  and thus \\eqref{eq:def:category_adjunction/d_triangle} commutes.\n\n  We can similarly prove that \\eqref{eq:def:category_adjunction/c_triangle} commutes.\n\n  Therefore, \\( (F, G, \\eta, \\varepsilon) \\) is a unit-counit adjunction.\n\n  \\ImplicationSubProof{def:category_adjunction/unit_counit}{def:category_adjunction/hom} Let \\( (F, G, \\eta, \\varepsilon) \\) be a unit-counit adjunction.\n\n  For every pair of objects \\( A \\in \\cat{C} \\) and \\( X \\in \\cat{D} \\), define the functions\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\varphi_{A,X}: \\cat{D}(F(A), X) \\to \\cat{C}(A, G(X)) \\\\\n      &\\varphi_{A,X}(g) \\coloneqq G(g) \\bincirc \\eta_A.\n    \\end{aligned}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\psi_{A,X}^{-1}: \\cat{C}(A, G(X)) \\to \\cat{D}(F(A), X) \\\\\n      &\\psi_{A,X}^{-1}(f) \\coloneqq \\varepsilon_X \\bincirc F(f),\n    \\end{aligned}\n  \\end{equation*}\n\n  From the naturality of \\( \\varepsilon \\) and from \\eqref{eq:def:category_adjunction/d_triangle} it follows that the following diagram commutes:\n  \\begin{equation}\\label{eq:def:category_adjunction/varphi_inverse_def}\n    \\begin{aligned}\n      \\includegraphics[page=8]{output/def__category_adjunction.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore,\n  \\begin{equation*}\n    g = \\varepsilon_X \\bincirc \\underbrace{[F \\bincirc G](f) \\bincirc F(\\eta_A)}_{F(\\varphi_{A,X}(g))} = [\\phi_{A,X} \\bincirc \\varphi_{A,X}](g)\n  \\end{equation*}\n  and thus \\( \\psi_{A,X} \\) is a left inverse of \\( \\varphi_{A,X} \\).\n\n  We can analogously show that \\( \\psi_{A,X} \\) is a right inverse, and hence that \\( \\varphi_{A,X} \\) is invertible.\n\n  Since we have already shown that \\( \\varphi \\) is a bijective function, it remains to verify the naturality of \\( \\varphi \\) in order to show that it is a natural isomorphism. Let \\( f: B \\to A \\) be a morphism in \\( \\cat{C} \\) and \\( g: X \\to Y \\) be a morphism in \\( \\cat{D} \\). Fix some morphism \\( s: F(A) \\to X \\).\n\n  Composing the functions of \\eqref{eq:def:category_adjunction/varphi_nat} in one direction, we obtain\n  \\begin{equation}\\label{eq:def:category_adjunction/varphi_nat_chase_right}\n    \\varphi_{B, Y}\\parens[\\Big]{ \\cat{D}(F(f), g)(s) }\n    =\n    \\varphi_{B, Y}\\parens[\\Big]{ g \\bincirc s \\bincirc F(f) }\n    =\n    G(g) \\bincirc G(s) \\bincirc [G \\bincirc F](f) \\bincirc \\eta_B.\n  \\end{equation}\n\n  In the other direction, we have\n  \\begin{equation}\\label{eq:def:category_adjunction/varphi_nat_chase_down}\n    \\cat{C}(f, G(g))\\parens[\\Big]{ \\varphi_{A, X}(s) }\n    =\n    \\cat{C}(f, G(g))\\parens[\\Big]{ G(s) \\bincirc \\eta_A }\n    =\n    G(g) \\bincirc G(s) \\bincirc \\eta_A \\bincirc f.\n  \\end{equation}\n\n  From the naturality of \\( \\eta \\), we have that \\eqref{eq:def:category_adjunction/eta_nat} commutes and hence\n  \\begin{equation*}\n    \\eta_A \\bincirc f\n    =\n    [G \\bincirc F](s) \\bincirc \\eta_B.\n  \\end{equation*}\n\n  Therefore, \\eqref{eq:def:category_adjunction/varphi_nat_chase_right} and \\eqref{eq:def:category_adjunction/varphi_nat_chase_down} are equal and, thus, \\eqref{eq:def:category_adjunction/varphi_nat} also commutes.\n\n  This proves the naturality of \\( \\varphi \\).\n\\end{defproof}\n\n\\begin{proposition}\\label{thm:category_adjunction_duality}\n  The functor \\( F: \\cat{C} \\to \\cat{D} \\) is \\hyperref[def:category_adjunction]{left adjoint} to \\( G: \\cat{D} \\to \\cat{C} \\) if and only if the \\hyperref[def:dual_functor]{dual functor} \\( F^{\\opcat} \\) is right adjoint to \\( G^{\\opcat} \\).\n\n  This is part of the duality principles listed in \\fullref{thm:categorical_principle_of_duality}.\n\\end{proposition}\n\\begin{proof}\n  \\begin{equation*}\n    \\cat{C^{\\opcat}}(G^{\\opcat}(X), A) = \\cat{C}(A, G(X)) \\cong \\cat{D}(F(A), X) = \\cat{D^{\\opcat}}(X, F^{\\opcat}(A)).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:concrete_category}\\mcite[26]{MacLane1994}\n  A \\term{concrete category} is a pair \\( (\\cat{C}, U) \\), where \\( \\cat{C} \\) is a category and \\( U: \\cat{C} \\to \\cat{Set} \\) is a \\hyperref[def:functor_invertibility/faithful]{faithful functor} that gives us a set for any object of \\( \\cat{C} \\). More generally, a \\( \\cat{D} \\)-concrete category is a pair \\( (\\cat{C}, U) \\), where \\( U: \\cat{C} \\to \\cat{D} \\).\n\n  In the context of a concrete category, we call \\( U \\) a \\term{forgetful functor} and any \\hyperref[def:category_adjunction]{left adjoint} to \\( U \\) functor a \\term{free functor}. According to Jean-Pierre Marquis in \\cite{StanfordPlato:category_theory}, the motivation for this terminology is that free functors build objects that are free from additional restrictions.\n\n  We list several examples in \\fullref{ex:def:category_adjunction}. The forgetful functor is usually clear from the context, and we identify a concrete category \\( (\\cat{C}, U) \\) with its underlying set \\( \\cat{C} \\). The corresponding free functor, however, often requires a nontrivial but straightforward construction.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:category_adjunction}\n  We list some examples of \\hyperref[def:category_adjunction]{category adjunctions}. Note that only some of them are commonly referred to as \\enquote{free}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:def:category_adjunction/set_top} Perhaps the simplest meaningful example of an adjunction is the \\hyperref[def:standard_topologies/discrete]{discrete topology} functor \\( D: \\cat{Set} \\to \\cat{Top} \\), which is left adjoint to the forgetful functor \\( U: \\cat{Top} \\to \\cat{Set} \\), which maps a small \\hyperref[def:topological_space]{topological space} \\( (\\mscrX, \\mscrT) \\) into its underlying set \\( \\mscrX \\).\n\n    Given a set \\( A \\) and a topological space \\( (\\mscrX, \\mscrT) \\), every function \\( s: A \\to \\mscrX \\) is \\hyperref[def:global_continuity]{continuous} when \\( A \\) is endowed with the discrete topology. Conversely, every continuous function is obviously a \\hyperref[def:function]{function}. It follows that there is an equality\n    \\begin{equation*}\n      \\cat{Top}\\parens[\\Big]{ \\underbrace{(A, \\pow(A))}_{D(A)}, (\\mscrX, \\mscrT) } = \\cat{Set}\\parens[\\Big]{ A, \\mscrX }.\n    \\end{equation*}\n\n    Therefore, \\( (D, U, \\id) \\) is a hom-adjunction. Furthermore, \\( (D, U, \\id, \\id) \\) is a unit-counit adjunction.\n\n    \\thmitem{ex:def:category_adjunction/top_set} The \\hyperref[def:standard_topologies/discrete]{indiscrete topology} functor \\( I: \\cat{Set} \\to \\cat{Top} \\) is right-adjoint to the same forgetful functor \\( U: \\cat{Top} \\to \\cat{Set} \\), again with identities for all natural transformations of the adjunction.\n\n    Therefore, we have\n    \\begin{equation*}\n      D \\dashv U \\dashv I.\n    \\end{equation*}\n\n    \\thmitem{ex:def:category_adjunction/set_cat} We discussed in \\fullref{ex:discrete_category_adjunction} the \\hyperref[def:discrete_category]{discrete category} functor \\( D: \\cat{Set} \\to \\cat{Cat} \\). We showed in \\fullref{ex:set_discr_cat_isomorphism} that, when restricted to the subcategory \\( \\cat{DiscrCat} \\) rather than \\( \\cat{Cat} \\), \\( D \\) it is an inverse to the forgetful functor \\( U \\). In the general case, however, this is an adjunction rather than an isomorphism. More precisely, \\( D \\) is left adjoint to \\( U \\).\n\n    Note that for any functor \\( F: \\cat{C} \\to \\cat{D} \\), we have \\( U(F) \\coloneqq F\\restr_{\\obj(C)} \\). Thus, \\( U \\) is not only a functor in \\( [\\cat{Cat}, \\cat{Set}] \\); it also induces a natural isomorphism between the functors \\( \\cat{Cat}(D(\\anon*), \\cat{\\anon*}) \\) and \\( \\cat{Set}(\\anon*, U(\\anon*)) \\).\n\n    Indeed, fix a small category \\( \\cat{C} \\) and a set \\( A \\). From our discussion in \\fullref{ex:set_discr_cat_isomorphism} it is obvious that the restriction\n    \\begin{equation*}\n      U: \\cat{Cat}(D(A), \\cat{C}) \\to \\cat{Set}(A, U(\\cat{C}))\n    \\end{equation*}\n    is a bijective function.\n\n    In order to verify the naturality of the transformation induced by \\( U \\), we must show that for any function \\( f: B \\to A \\) and functor \\( F: \\cat{C} \\to \\cat{D} \\), the following diagram commutes\n    \\begin{equation}\\label{eq:ex:def:category_adjunction/set_cat/u_nat}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/ex__def__category_adjunction.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    The commutativity of \\eqref{eq:ex:def:category_adjunction/set_cat/u_nat} follows from the following: for every functor \\( S: D(A) \\to \\cat{C} \\) we have\n    \\begin{equation*}\n      U(F \\bincirc S \\bincirc D(f))\n      =\n      U(F) \\bincirc U(S) \\bincirc U(D(f))\n      =\n      U(F) \\bincirc U(S) \\bincirc f.\n    \\end{equation*}\n\n    Therefore, \\( (D, U, U) \\) is a \\hyperref[def:category_adjunction/hom]{hom-adjunction}.\n\n    We can also explicitly define a unit-counit adjunction. The unit \\( \\eta: \\id_{\\cat{Set}} \\Rightarrow U \\bincirc D \\) is simply the identity.\n\n    The counit is slightly more interesting. Given a small category \\( \\cat{C} \\), applying \\( D \\bincirc U \\) gives us the subcategory consisting only of the objects and identity morphisms of \\( \\cat{C} \\). Then the counit \\( \\varepsilon: D \\bincirc U \\Rightarrow \\id_{\\cat{Cat}} \\) is simply the inclusion functor \\( \\Iota \\) from this subcategory to \\( \\cat{C} \\).\n\n    The triangle\n    \\begin{equation}\\label{eq:ex:def:category_adjunction/set_cat/triangles}\n      \\begin{aligned}\n        \\includegraphics[page=2]{output/ex__def__category_adjunction.pdf}\n        \\quad\\quad\n        \\includegraphics[page=3]{output/ex__def__category_adjunction.pdf}\n      \\end{aligned}\n    \\end{equation}\n    corresponding to \\eqref{eq:def:category_adjunction/d_triangle} and \\eqref{eq:def:category_adjunction/c_triangle}, obviously commute.\n\n    The quadruple \\( (D, U, \\eta, \\varepsilon) \\) is a \\hyperref[def:category_adjunction/unit_counit]{unit-counit adjunction}.\n\n    \\thmitem{ex:def:category_adjunction/quiv_cat} The left adjoint of the forgetful functor \\( U: \\cat{Cat} \\to \\cat{Quiv} \\) is the free category functor defined in \\fullref{def:quiver_free_category}. We denote this functor by \\( F: \\cat{Quiv} \\to \\cat{Cat} \\).\n\n    We can define the family of functions\n    \\begin{equation}\\label{eq:ex:def:category_adjunction/quiv_cat/varphi_family}\n      \\begin{aligned}\n        &\\varphi: \\cat{Cat}(F(\\anon*), \\cat{\\anon*}) \\Rightarrow \\cat{Quiv}(\\anon*, U(\\cat{\\anon*})), \\\\\n        &\\varphi_{Q, \\cat{C}}(S) \\coloneqq \\parens[\\Big]{ v \\mapsto S(v), a \\mapsto S(\\iota(a)) }.\n      \\end{aligned}\n    \\end{equation}\n\n    For every functor \\( S: F(Q) \\to \\cat{C} \\), \\( \\varphi_{Q, \\cat{C}} \\) defines a quiver homomorphism that restricts \\( S \\) to \\hyperref[def:quiver_path]{quiver paths} of containing only one arc. Formally, \\( \\iota \\) is the canonical embedding\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\iota: Q \\to [U \\bincirc F](Q) \\\\\n        &\\iota_V(v) \\coloneqq v,\n        &\\iota_A(a) \\coloneqq (h(a), a).\n      \\end{aligned}\n    \\end{equation*}\n\n    We will later see that \\( \\iota \\) is the unit of a unit-counit adjunction.\n\n    Now, from \\eqref{eq:def:quiver_free_category/functor_from_homomorphism}, it is clear that the free category functor \\( F \\), when restricted to the set of quiver homomorphisms \\( \\cat{Quiv}(Q, U(\\cat{C})) \\), is the two-sided inverse of \\( \\varphi_{Q, \\cat{C}} \\).\n\n    We will show that \\( \\varphi \\) is a natural transformation. Fix a functor \\( G: \\cat{C} \\to \\cat{D} \\) and a homomorphism \\( (g_V, g_A): Q \\to R \\). We must show that the following diagram commutes:\n    \\begin{equation}\\label{eq:ex:def:category_adjunction/quiv_cat/varphi_nat}\n      \\begin{aligned}\n        \\includegraphics[page=4]{output/ex__def__category_adjunction.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    That is, for every functor \\( S: F(A) \\to \\cat{C} \\), we must show\n    \\begin{equation*}\n      \\varphi_{R, \\cat{D}}(G \\bincirc S \\bincirc F(g_V, g_A))\n      =\n      U(G) \\bincirc \\varphi_{R, \\cat{D}}(S) \\bincirc (g_V, g_A).\n    \\end{equation*}\n\n    This is also clear from \\eqref{eq:def:quiver_free_category/functor_from_homomorphism}.\n\n    Therefore, \\( (F, U, \\varphi) \\) is a \\hyperref[def:category_adjunction/hom]{hom-adjunction}.\n\n    Furthermore, the canonical embedding \\( \\iota \\) defined above, when parameterized by \\( Q \\), is a unit of adjunction.\n\n    The counit  \\( \\varepsilon: F \\bincirc U \\Rightarrow \\id_{\\cat{Cat}} \\) is more involved. As discussed in \\fullref{def:quiver_free_category}, for every finite path \\( p \\) in the quiver \\( U(\\cat{C}) \\) with arcs \\( a_1, \\ldots, a_n \\), the functor \\( F \\bincirc U \\) simply \\enquote{evaluates} \\( p \\) as\n    \\begin{equation*}\n      a_n \\bincirc a_{n-1} \\bincirc \\cdots \\bincirc a_1.\n    \\end{equation*}\n\n    Since the embedding only produces paths with a single arc, the adjunction triangles commute:\n    \\begin{equation}\\label{eq:ex:def:category_adjunction/quiv_cat/triangles}\n      \\begin{aligned}\n        \\includegraphics[page=5]{output/ex__def__category_adjunction.pdf}\n        \\quad\\quad\n        \\includegraphics[page=6]{output/ex__def__category_adjunction.pdf}\n      \\end{aligned}\n    \\end{equation}\n\n    \\thmitem{ex:def:category_adjunction/multgph_quiv} In \\fullref{def:quiver/forgetful}, we have defined the \\hyperref[def:concrete_category]{forgetful functor} \\( U: \\hyperref[def:category_of_small_quivers]{\\cat{Quiv}} \\to \\hyperref[def:undirected_multigraph]{\\cat{MultGph}} \\). Given a \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\) and a choice function \\( c \\) for the family of two-element sets in \\( \\mscrU \\), we have an orientation functor \\( O_c: \\cat{MultGph} \\to \\cat{Quiv} \\) defined in \\fullref{def:multigraph_orientation}.\n\n    It may seem that, for a fixed choice function, \\( O_c \\) is \\hyperref[def:category_adjunction]{left adjoint} to \\( U \\). This is not true, however, as shown in \\cref{fig:ex:def:category_adjunction/multgph_quiv}.\n\n    \\begin{figure}\n      \\hfill\n      \\includegraphics[page=7]{output/ex__def__category_adjunction.pdf}\n      \\hfill\n      \\includegraphics[page=8]{output/ex__def__category_adjunction.pdf}\n      \\hfill\\hfill\n      \\caption{Two undirected homomorphisms from \\( G \\) to \\( U(Q) \\), denoted using dashed lines, only one of which is a quiver homomorphism from \\( O_c(G) \\) to \\( Q \\)}\n      \\label{fig:ex:def:category_adjunction/multgph_quiv}\n    \\end{figure}\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:adjoint_equivalence}\n  We call the quadruple \\( (F, G, \\eta, \\varepsilon) \\) with signature \\eqref{eq:def:category_equivalence/signature} an \\term{adjoint equivalence} if it is both an \\hyperref[def:category_adjunction]{adjunction} and \\hyperref[def:category_equivalence]{equivalence}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:adjoint_equivalence}\n  Let \\( (F, G, \\eta, \\varepsilon) \\) be a \\hyperref[def:category_equivalence]{category equivalence} between \\( \\cat{C} \\) and \\( \\cat{D} \\).\n\n  There exists a natural isomorphism \\( \\zeta: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F \\) such that \\( (F, G, \\zeta, \\varepsilon) \\) is an \\hyperref[def:adjoint_equivalence]{adjoint equivalence}.\n\\end{proposition}\n\\begin{proof}\n  From \\fullref{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor} it follows that \\( F \\) is fully faithful and essentially surjective.\n\n  We will now use the same trick as in the end of the proof of \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence} to define \\( \\zeta \\).\n\n  Since \\( F \\) is fully faithful, there is a bijective function\n  \\begin{equation*}\n    \\varphi: \\cat{D}\\parens[\\Big]{ F(A), [F \\bincirc G \\bincirc F](A) } \\to \\cat{C}\\parens[\\Big]{ A, [F \\bincirc G](A) }.\n  \\end{equation*}\n\n  Hence, we can define\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\zeta: \\id_{\\cat{C}} \\to G \\bincirc F, \\\\\n      &\\zeta_A \\coloneqq \\varphi(\\varepsilon_{F(A)}^{-1})\n    \\end{aligned}\n  \\end{equation*}\n  so that \\( F(\\zeta_A) = \\varepsilon_{F(A)}^{-1} \\). By \\fullref{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms}, \\( \\zeta_A \\) is also an isomorphism.\n\n  As in \\fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, we use \\fullref{thm:commutative_diagrams_preserved_and_reflected} and the naturality of \\( \\varepsilon \\) to prove that \\eqref{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_source_nat} implies \\eqref{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_image_nat} (with \\( \\eta \\) replaced by \\( \\zeta \\)).\n\n  Therefore, \\( \\zeta \\) is a natural isomorphism and the quadruple \\( (F, G, \\zeta, \\varepsilon) \\) is an equivalence of categories.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:functor_adjoint_uniqueness}\n  If a functor has two \\hyperref[def:category_adjunction]{left adjoints} (resp. right adjoints), then there exists a unique natural isomorphism between them.\n\n  We say that left adjoints (resp. right adjoints) are unique up to a natural isomorphism.\n\\end{proposition}\n\\begin{proof}\n  We will first prove the statement for left adjoints. Suppose that \\( (F', G, \\eta', \\varepsilon') \\) and \\( (F', G, \\eta^\\dprime, \\varepsilon^\\dprime) \\) are two unit-counit adjunctions.\n\n  \\SubProof{Proof of existence of isomorphism}\\mcite{MathSE:left_adjoint_uniqueness} We can utilize the naturality of the units \\( \\eta' \\) and \\( \\eta^\\dprime \\) and counits \\( \\varepsilon' \\) and \\( \\varepsilon^\\dprime \\) to show that the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:functor_adjoint_uniqueness/existence}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__functor_adjoint_uniqueness.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  By the commuting triangle \\eqref{eq:def:category_adjunction/d_triangle}, all paths from \\( F'(A) \\) to \\( F'(A) \\) above are identities.\n\n  The bottom-most path in \\eqref{eq:thm:functor_adjoint_uniqueness/existence} justifies defining the natural transformation\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\alpha: F' \\Rightarrow F^\\dprime \\\\\n      &\\alpha_A \\coloneqq \\varepsilon'_{F^\\dprime(A)} \\bincirc F'(\\eta_A^\\dprime).\n    \\end{aligned}\n  \\end{equation*}\n\n  Then \\( \\alpha_A \\) is an isomorphism for every object \\( A \\) in \\( \\cat{C} \\) with inverse \\( \\varepsilon_{F'(A)}^\\dprime \\bincirc F^\\dprime(\\eta_A') \\). Therefore, it is a natural isomorphism from \\( F' \\) to \\( F^\\dprime \\).\n\n  \\SubProof{Proof of uniqueness of isomorphism} Suppose that \\( \\beta: F' \\Rightarrow F^\\dprime \\) is another natural isomorphism. Then, by the commuting triangle \\eqref{eq:def:category_adjunction/d_triangle}, the following diagram also commutes:\n  \\begin{equation}\\label{eq:thm:functor_adjoint_uniqueness/uniqueness}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__functor_adjoint_uniqueness.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore,\n  \\begin{equation*}\n    \\beta_A\n    =\n    \\varepsilon^\\dprime_{F^\\dprime(A)} \\bincirc F^\\dprime(\\eta^\\dprime_A) \\bincirc \\alpha_A\n    \\reloset {\\eqref{eq:def:category_adjunction/d_triangle}} =\n    \\alpha_A.\n  \\end{equation*}\n\n  This finishes the proof for left adjoints. The other direction is \\hyperref[thm:categorical_principle_of_duality]{dual}. If \\( G' \\) and \\( G^\\dprime \\) are two right adjoints to \\( F \\), then by \\fullref{thm:category_adjunction_duality}, \\( G'^{\\opcat} \\) and \\( {G^\\dprime}^{\\opcat} \\) are left adjoints and are thus isomorphic. Then by \\fullref{thm:morphism_invertibility_duality}, \\( G' \\) and \\( G^\\dprime \\) are also isomorphic.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:universal_objects_as_adjunctions}\n  Fix a category \\( \\cat{C} \\). We can characterize the universal objects in \\( \\cat{C} \\) from \\fullref{def:universal_objects} via adjunctions with the \\hyperref[def:universal_categories]{terminal category} \\( \\cat{1} \\).\n\n  Let \\( \\Delta^{\\cat{1}}: \\cat{C} \\to \\cat{1} \\) be the \\hyperref[def:diagonal_functor]{constant functor} into \\( \\cat{1} \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:universal_objects_as_adjunctions/initial} The object \\( I \\) of \\( \\cat{C} \\) is \\hyperref[def:universal_objects]{initial} if and only if it is (the unique value of) a left adjoint to \\( \\Delta^{\\cat{1}} \\) functor.\n\n    In particular, the uniqueness proved in \\fullref{thm:def:universal_objects/properties/initial} follows from \\fullref{thm:functor_adjoint_uniqueness}.\n\n    \\thmitem{thm:universal_objects_as_adjunctions/terminal} \\hyperref[thm:categorical_principle_of_duality]{Dually}, the \\hyperref[def:universal_objects]{terminal objects} are exactly the right adjoint to \\( \\Delta_I^{\\cat{1}} \\) functors.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  We will only prove \\fullref{thm:universal_objects_as_adjunctions/initial} since the other direction is \\hyperref[thm:categorical_principle_of_duality]{dual}.\n\n  \\SufficiencySubProof Let \\( I \\) be an initial object in \\( \\cat{C} \\). We can then regard it as a functor \\( F: \\cat{1} \\to \\cat{C} \\).\n\n  We define the natural transformations\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\eta: \\id_{\\cat{1}} \\Rightarrow \\Delta_I^{\\cat{1}} \\bincirc F \\\\\n      &\\eta_{\\cat{0}} \\coloneqq \\id_{\\cat{0}}\n    \\end{aligned}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\varepsilon: F \\bincirc \\Delta_I^{\\cat{1}} \\Rightarrow \\id_{\\cat{C}} \\\\\n      &\\varepsilon_A \\T{is the unique morphism} I \\to A\n    \\end{aligned}\n  \\end{equation*}\n\n  Since \\( I \\) has a unique morphism into any other object of \\( \\cat{C} \\), for every morphism \\( f: A \\to B \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:universal_objects_as_adjunctions/sufficiency_nat}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/thm__universal_objects_as_adjunctions.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  It follows that both \\( \\eta \\) and \\( \\varepsilon \\) are natural transformations. Furthermore, they trivially satisfy the triangle diagrams triangle \\eqref{eq:def:category_adjunction/d_triangle} and \\eqref{eq:def:category_adjunction/c_triangle}.\n\n  Hence, \\( (F, \\Delta_I^{\\cat{1}}, \\eta, \\varepsilon) \\) is a \\hyperref[def:category_adjunction/unit_counit]{unit-counit adjunction}.\n\n  \\NecessitySubProof Conversely, suppose that \\( (F, \\Delta_I^{\\cat{1}}, \\eta, \\varepsilon) \\) is a unit-counit adjunction.\n\n  Let \\( I \\coloneqq F(\\cat{0}) \\). Then \\( \\varepsilon_A \\) is a morphism from \\( I \\) to \\( A \\). By \\eqref{eq:def:category_adjunction/d_triangle}, \\( \\varepsilon_I = \\id_I \\) since the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:universal_objects_as_adjunctions/d_triangle}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/thm__universal_objects_as_adjunctions.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Suppose that \\( \\zeta \\) is another morphism from \\( I \\) to \\( A \\). The naturality of \\( \\varepsilon \\) implies that, for the morphism \\( \\id_A: A \\to A \\), the following diagram commutes:\n  \\begin{equation}\\label{eq:thm:universal_objects_as_adjunctions/necessity_nat}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/thm__universal_objects_as_adjunctions.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  The upper left triangle in \\eqref{eq:thm:universal_objects_as_adjunctions/necessity_nat} is \\eqref{eq:thm:universal_objects_as_adjunctions/d_triangle}.\n\n  We conclude that \\( \\zeta = \\varepsilon_A \\) and, generalizing on \\( A \\), that every morphism from \\( I \\) is unique.\n\\end{proof}\n\n\\begin{remark}\\label{rem:left_and_right_adjoint_not_equivalence}\n  We discussed in \\fullref{ex:def:universal_objects/grp} that \\enquote{the} trivial group \\( \\set{ e } \\) is a \\hyperref[def:universal_objects/zero]{zero object} of \\( \\cat{Grp} \\). By \\fullref{thm:universal_objects_as_adjunctions}, this object induces a functor that is both left adjoint and right adjoint of \\( \\Delta_I^{\\cat{1}} \\). Nevertheless, the categories \\( \\cat{Grp} \\) and \\( \\cat{1} \\) are not \\hyperref[def:category_equivalence]{equivalent}.\n\\end{remark}\n\n\\begin{remark}\\label{rem:universal_mapping_property}\n  We will now regard adjoint functors as a way to \\enquote{construct} new objects.\n\n  Let \\( (F, G, \\iota, \\pi) \\) be a \\hyperref[def:category_adjunction/unit_counit]{unit-counit adjunction} between the categories \\( \\cat{C} \\) and \\( \\cat{D} \\). In the current context, especially in connection with \\hyperref[def:category_of_cones/limit]{limits} and \\hyperref[def:category_of_cones/colimit]{colimits}, we will call the components of the counit \\( \\pi: F \\bincirc G \\Rightarrow \\id_{\\cat{D}} \\) --- \\term{projections}, and the components of the unit \\( \\iota: \\id_{\\cat{C}} \\Rightarrow G \\bincirc F \\) --- \\term{coprojections}.\n\n  Take objects \\( A \\) in \\( \\cat{C} \\) and \\( X \\) in \\( \\cat{D} \\) and a morphism \\( f: A \\to G(X) \\). We want to obtain a morphism \\( \\widetilde{f}: F(A) \\to X \\), for which the following diagram commutes:\n  \\begin{equation}\\label{eq:rem:universal_mapping_property/c_triangle}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/rem__universal_mapping_property.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  From the naturality of \\( \\iota \\) and from the triangle diagram \\eqref{eq:def:category_adjunction/c_triangle} it follows that the following diagram commutes:\n  \\begin{equation}\\label{eq:rem:universal_mapping_property/f_tilde_existence}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/rem__universal_mapping_property.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  It is clear from \\eqref{eq:rem:universal_mapping_property/f_tilde_existence} that\n  \\begin{equation*}\n    G(\\widetilde{f}) = G(\\pi_X) \\bincirc [G \\bincirc F](f) = G(\\pi_X \\bincirc F(f)).\n  \\end{equation*}\n\n  Furthermore, this value is unique. From the naturality of \\( \\pi \\) and the triangle diagram \\eqref{eq:def:category_adjunction/d_triangle} it follows that the following diagram commutes:\n  \\begin{equation}\\label{eq:rem:universal_mapping_property/f_tilde_uniquness}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/rem__universal_mapping_property.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Therefore,\n  \\begin{equation*}\n    \\widetilde{f} = \\pi_X \\bincirc F(f)\n  \\end{equation*}\n\n  Taking into account that the functor \\( F \\) itself is unique up to a unique isomorphism, as per \\fullref{thm:functor_adjoint_uniqueness}, we have proved the following statement:\n  \\begin{displayquote}\n    For every object \\( A \\) in \\( \\cat{C} \\), there exist unique up to a unique isomorphism object \\( F(A) \\) in \\( \\cat{D} \\) and canonical coprojection map \\( \\iota_A: A \\to [G \\bincirc F](A) \\) satisfying the following property, called a \\term{universal mapping property}:\n    \\begin{displayquote}\n      For every object \\( X \\) in \\( \\cat{D} \\) and every map \\( f: A \\to G(X) \\) in \\( \\cat{C} \\), there exists a unique map \\( \\widetilde{f}: F(A) \\to X \\) in \\( \\cat{D} \\) such that the diagram \\eqref{eq:rem:universal_mapping_property/c_triangle} commutes.\n    \\end{displayquote}\n  \\end{displayquote}\n\n  Intuitively, this universal mapping property states that any map (morphism) with domain \\( A \\) in \\( \\cat{C} \\) can be transformed into a map with domain \\( F(A) \\) in \\( \\cat{D} \\).\n\n  The statement becomes more meaningful when we regard \\( G: \\cat{D} \\to \\cat{C} \\) as a \\hyperref[def:concrete_category]{forgetful functor}. In this case, every object of \\( \\cat{D} \\) is regarded as an object of \\( \\cat{C} \\), and we write \\( X \\) rather than \\( G(X) \\). The universal mapping property then becomes:\n  \\begin{displayquote}\n    For every object \\( A \\) in \\( \\cat{C} \\), there exist unique up to a unique isomorphism object \\( F(A) \\) in \\( \\cat{D} \\) and canonical coprojection map \\( \\iota_A: A \\to F(A) \\) satisfying the following universal mapping property:\n    \\begin{displayquote}\n      For every object \\( X \\) in \\( \\cat{D} \\) and every map \\( f: A \\to X \\) in \\( \\cat{C} \\), there exists a unique map \\( \\widetilde{f}: F(A) \\to X \\) in \\( \\cat{D} \\) such that the following diagram commutes:\n      \\begin{equation}\\label{eq:rem:universal_mapping_property/c_triangle_forgetful}\n        \\begin{aligned}\n          \\includegraphics[page=4]{output/rem__universal_mapping_property.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{displayquote}\n  \\end{displayquote}\n\n  In \\fullref{def:concrete_category} we mentioned that we will call the left adjoint of a forgetful functor a free functor. Universal mapping properties allow characterizing certain \\enquote{free constructions}, such as the free groups defined in \\fullref{def:free_group}, without explicitly building a free functor and proving that it is left adjoint. Indeed, for every suitable object and map, we explicitly build the natural isomorphism \\( \\varphi \\) of a hom-adjunction, and the commutative triangle \\eqref{eq:rem:universal_mapping_property/c_triangle} ensures that this \\( \\varphi \\) is a natural transformation.\n\n  Universal mapping properties of this form are used for \\hyperref[def:category_of_cones/colimit]{colimits} --- see \\fullref{rem:limit_universal_mapping_property}.\n\n  Of course, there is a \\hyperref[thm:categorical_principle_of_duality]{dual} universal mapping property:\n  \\begin{displayquote}\n    For every object \\( X \\) in \\( \\cat{D} \\) there exist unique up to a unique isomorphism object \\( G(X) \\) in \\( \\cat{C} \\) and canonical projection map \\( \\pi_X: [F \\bincirc G](X) \\to X \\) satisfying the following property, called a \\term{universal mapping property}:\n    \\begin{displayquote}\n      For every object \\( A \\) in \\( \\cat{C} \\) and every map \\( g: F(A) \\to X \\) in \\( \\cat{D} \\), there exists a unique map \\( \\widetilde{g}: A \\to G(X) \\) in \\( \\cat{C} \\) such that the following diagram commutes:\n      \\begin{equation}\\label{eq:rem:universal_mapping_property/d_triangle}\n        \\begin{aligned}\n          \\includegraphics[page=5]{output/rem__universal_mapping_property.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{displayquote}\n  \\end{displayquote}\n\n  In this case, we can regard \\( F \\) as a forgetful functor and \\( G \\) as a free functor to obtain the following:\n  \\begin{displayquote}\n    For every object \\( X \\) in \\( \\cat{D} \\) there exist unique up to a unique isomorphism object \\( G(X) \\) in \\( \\cat{C} \\) and canonical projection map \\( \\pi_X: G(X) \\to X \\) satisfying the following property, called a \\term{universal mapping property}:\n    \\begin{displayquote}\n      For every object \\( A \\) in \\( \\cat{C} \\) and every map \\( g: A \\to X \\) in \\( \\cat{D} \\), there exists a unique map \\( \\widetilde{g}: A \\to G(X) \\) in \\( \\cat{C} \\) such that the following diagram commutes:\n      \\begin{equation}\\label{eq:rem:universal_mapping_property/d_triangle_forgetful}\n        \\begin{aligned}\n          \\includegraphics[page=6]{output/rem__universal_mapping_property.pdf}\n        \\end{aligned}\n      \\end{equation}\n    \\end{displayquote}\n  \\end{displayquote}\n\n  Universal mapping properties of this form are used for \\hyperref[def:category_of_cones/limit]{limits} --- see \\fullref{rem:limit_universal_mapping_property}.\n\\end{remark}\n", "meta": {"hexsha": "ae97dfda213b7d71e419557ea030f965a8666790", "size": 38711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/category_adjunctions.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/category_adjunctions.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/category_adjunctions.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": 62.7406807131, "max_line_length": 617, "alphanum_fraction": 0.6884089794, "num_tokens": 12390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6195533338928149}}
{"text": "\\subsection{Computing inverses}\n\\label{ssec:computing-inverses}\n\nIn Example~\\ref{exa:verifying-inverse}, we verified that a matrix $A$\nhad an inverse. But we did not actually compute the inverse: the\ninverse $B$ was already given, and we merely checked that $AB=I$ and\n$BA=I$. We now explore a method for finding the inverse when it is not\nalready known what it is.\n\n\\begin{example}{Finding the inverse of a matrix}{finding-inverse}\n  Find the inverse of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rr}\n      1 & -2 \\\\\n      2 & -3\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To find $A^{-1}$, we need to find a matrix $\\begin{mymatrix}{rr}\n    x & z \\\\\n    y & w\n  \\end{mymatrix}$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      1 & -2 \\\\\n      2 & -3\n    \\end{mymatrix} \\begin{mymatrix}{rr}\n      x & z \\\\\n      y & w\n    \\end{mymatrix} =\\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  We can multiply these two matrices, and see that in order for this\n  equation to be true, we must solve the systems of equations\n  \\begin{equation*}\n    \\begin{array}{c}\n      x  - 2y = 1, \\\\\n      2x - 3y = 0,\n    \\end{array}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{array}{c}\n      z  - 2w = 0, \\\\\n      2z - 3w = 1.\n    \\end{array}\n  \\end{equation*}\n  Writing the augmented matrix for these two systems gives\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & -2 & 1 \\\\\n      2 & -3 & 0\n    \\end{mymatrix}\n    % \\label{inverse-1a}\n  \\end{equation*}\n  for the first system and\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & -2 & 0 \\\\\n      2 & -3 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n  for the second one. Note that both systems have $A$ as their coefficient\n  matrix. Since both systems have the same coefficient matrix, they both\n  require exactly the same row operations, and we can use the method of\n  Example~\\ref{exa:multiple-systems} to solve both systems at the same\n  time.  To do so, we create a single augmented matrix containing both of the\n  right-hand sides:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|rr}\n      1 & -2 & 1 & 0 \\\\\n      2 & -3 & 0 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then we perform row operations until the coefficient matrix is in\n  {\\rref}:\n  \\begin{equation}\\label{eqn:finding-inverse}\n    \\begin{mymatrix}{rr|rr}\n      1 & -2 & 1 & 0 \\\\\n      2 & -3 & 0 & 1\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-2R_1}{\\roweq}\n    \\begin{mymatrix}{rr|rr}\n      1 & -2 &  1 & 0 \\\\\n      0 &  1 & -2 & 1\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1+2R_2}{\\roweq}\n    \\begin{mymatrix}{rr|rr}\n      1 & 0 & -3 & 2 \\\\\n      0 & 1 & -2 & 1\n    \\end{mymatrix}.\n  \\end{equation}\n  This corresponds to the following {\\rref}s for the two original\n  systems of equations:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & 0 & -3 \\\\\n      0 & 1 & -2\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{rr|rr}\n      1 & 0 & 2 \\\\\n      0 & 1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  The solution of the first system is $x=-3$ and $y=-2$. The solution\n  for the second system is $z=2$ and $w=1$. If we take the values\n  found for $x$, $y$, $z$, and $w$ and put them into our inverse\n  matrix, we see that the inverse is\n  \\begin{equation*}\n    A^{-1} =\n    \\begin{mymatrix}{rr}\n      x & z \\\\\n      y & w\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rr}\n      -3 & 2 \\\\\n      -2 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that this is exactly the right-hand side in the last\n  augmented matrix of {\\eqref{eqn:finding-inverse}}. In other words,\n  all we really had to do to find the inverses were the row operations\n  in {\\eqref{eqn:finding-inverse}}. The inverse can be read off\n  directly from the result.\n\\end{solution}\n\nThe example suggests a general method for finding the inverse of a\nmatrix, which we summarize in the following algorithm.\n\n\\begin{algorithm}{Finding the inverse of a matrix}{matrix-inversion-algorithm}\n  Suppose $A$ is an $n\\times n$-matrix. To find $A^{-1}$ if it exists%\n  \\index{matrix!finding the inverse}, form the augmented\n  $n\\times 2n$-matrix\n  \\begin{equation*}\n    \\mat{A\\mid I}.\n  \\end{equation*}\n  If possible, do row operations until you obtain an\n  $n\\times 2n$-matrix of the form\n  \\begin{equation*}\n    \\mat{I\\mid B}.\n  \\end{equation*}\n  If this can be done, then $A$ is invertible and $A^{-1}=B$. If it is\n  not possible (i.e., if the {\\rref} of $A$ has less than\n  $n$ pivot entries), then $A$ is not invertible.\n\\end{algorithm}\n\nThis algorithm shows how to find the inverse if it exists. It also\ntells us if $A$ does not have an inverse.\n\n\\begin{example}{Finding the inverse of a matrix}{finding-inverse2}\n  Let $A=\\begin{mymatrix}{rrr}\n    1 & 2 & 2 \\\\\n    1 & 0 & 2 \\\\\n    3 & 1 & -1\n  \\end{mymatrix}$. Find $A^{-1}$ if it exists.\n\\end{example}\n\n\\begin{solution}\n  We set up the augmented matrix and reduce it to {\\rref}.\n  \\begin{eqnarray*}\n    \\mat{A\\mid I} &=&\n    \\begin{mymatrix}{rrr|rrr}\n      1 & 2 &  2 & 1 & 0 & 0 \\\\\n      1 & 0 &  2 & 0 & 1 & 0 \\\\\n      3 & 1 & -1 & 0 & 0 & 1\n    \\end{mymatrix}\\\\[1ex]\n    &\\stackrel{R_2\\rowop R_2-R_1}{\\stackrel{R_3\\rowop R_3-3R_1}{\\roweq}}&\n    \\begin{mymatrix}{rrr|rrr}\n      1 &  2 &  2 &  1 & 0 & 0 \\\\\n      0 & -2 &  0 & -1 & 1 & 0 \\\\\n      0 & -5 & -7 & -3 & 0 & 1\n    \\end{mymatrix}\\\\[1ex]\n    &\\stackrel{R_1\\rowop 7R_1}{\\stackrel{R_3\\rowop -2R_3}{\\roweq}}&\n    \\begin{mymatrix}{rrr|rrr}\n      7 & 14 & 14 &  7 & 0 &  0 \\\\\n      0 & -2 &  0 & -1 & 1 &  0 \\\\\n      0 & 10 & 14 &  6 & 0 & -2\n    \\end{mymatrix}\\\\[1ex]\n    &\\stackrel{R_1\\rowop R_1+7R_2}{\\stackrel{R_3\\rowop R_3+5R_2}{\\roweq}}&\n    \\begin{mymatrix}{rrr|rrr}\n      7 &  0 & 14 &  0 & 7 &  0 \\\\\n      0 & -2 &  0 & -1 & 1 &  0 \\\\\n      0 &  0 & 14 &  1 & 5 & -2\n    \\end{mymatrix}\\\\[1ex]\n    &\\stackrel{R_1\\rowop R_1-R_3}{\\roweq}&\n    \\begin{mymatrix}{rrr|rrr}\n      7 &  0 &  0 & -1 & 2 &  2 \\\\\n      0 & -2 &  0 & -1 & 1 &  0 \\\\\n      0 &  0 & 14 &  1 & 5 & -2\n    \\end{mymatrix}\\\\[-1ex]\n    &\\stackrel{R_1\\rowop \\frac{1}{7}R_1}{\\stackrel{R_2\\rowop -\\frac{1}{2}R_2}{\\stackrel{R_3\\rowop \\frac{1}{14}R_3}{\\roweq}}}&\n    \\def\\arraystretch{1.5}\n    \\begin{mymatrix}{rrr|rrr}\n      1 & 0 & 0 & -\\frac{1}{7} & \\frac{2}{7} & \\frac{2}{7} \\\\\n      0 & 1 & 0 & \\frac{1}{2} & -\\frac{1}{2} & 0           \\\\\n      0 & 0 & 1 & \\frac{1}{14} & \\frac{5}{14} & -\\frac{1}{7}\n    \\end{mymatrix}.\n  \\end{eqnarray*}\n  Notice that the last augmented matrix is of the form\n  $\\mat{I\\mid B}$, where the left-hand side is the $3 \\times 3$\n  identity matrix.  Therefore, the inverse is the $3 \\times 3$-matrix\n  on the right-hand side, given by\n  \\begin{equation*}\n    A^{-1} ~=~\n    \\def\\arraystretch{1.5}\n    \\begin{mymatrix}{rrr}\n      -\\frac{1}{7} & \\frac{2}{7} & \\frac{2}{7} \\\\\n      \\frac{1}{2} & -\\frac{1}{2} & 0 \\\\\n      \\frac{1}{14} & \\frac{5}{14} & -\\frac{1}{7}\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWhen looking for the inverse of a matrix, it can happen that the\nleft-hand side cannot be row reduced to the identity matrix. The\nfollowing is an example of this situation.\n\n\\begin{example}{A non-invertible matrix}{matrix-no-inverse}\n  Let $A=\\begin{mymatrix}{rrr}\n    1 & -2 & 2 \\\\\n    1 &  0 & 2 \\\\\n    2 & -2 & 4\n  \\end{mymatrix}$. Find $A^{-1}$ if it exists.%\n  \\index{matrix!inverse!does not exist}%\n  \\index{inverse!of a matrix!does not exist}\n\\end{example}\n\n\\begin{solution}\n  We write the augmented matrix\n  \\begin{equation*}\n    \\mat{A\\mid I}\n    ~=~\n    \\begin{mymatrix}{rrr|rrr}\n      1 & -2 & 2 & 1 & 0 & 0 \\\\\n      1 &  0 & 2 & 0 & 1 & 0 \\\\\n      2 & -2 & 4 & 0 & 0 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n  and proceed to do row operations attempting to obtain\n  $\\mat{I\\mid A^{-1}}$. After a few row operations, we have\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|rrr}\n      \\circled{1} & -2 & 2 & 1 & 0 & 0 \\\\\n      0 & \\circled{2} & 0 & -1 & 1 & 0 \\\\\n      0 & 0 & 0 & -1 & -1 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n  At this point, we see that the coefficient matrix has rank $2$,\n  i.e., there are only two pivot entries. This means there is no way\n  to obtain $I$ on the left-hand side of this augmented matrix.\n  Hence, there is no way to complete the algorithm, and the inverse of\n  $A$ does not exist.\n\\end{solution}\n\nIf the algorithm provides an inverse, it is always possible to\ndouble-check that your answer is correct.  To do so, use the method\ndemonstrated in Example~\\ref{exa:verifying-inverse}. Check that the\nproducts $AA^{-1}$ and $A^{-1}A$ both equal the identity\nmatrix. Through this method, you can always ensure that you have\ncalculated $A^{-1}$ properly.\n\n", "meta": {"hexsha": "d90e77a0bcba733689915108cb65a2c88c38d19f", "size": 8627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Inverses-Computing.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-Inverses-Computing.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-Inverses-Computing.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.1902985075, "max_line_length": 125, "alphanum_fraction": 0.5920945868, "num_tokens": 3339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.6195198789354163}}
{"text": "\\section{Solving For The Market Steady State}\n\n\\label{appx: Flux Sketch} \n\\subsection{Steady State Flow Equations}\n\\begin{itemize}\n    \\item Fix some strategies $s_m,s_w$ and let:\n\n\\begin{equation*}\n    \\rho_m(\\mu,b)=\\mathbb{E}_{\\theta_w}\\Big[s_m(\\theta,\\mu,b)\\Big]= \\iint\\limits_{[0,1]^2} s_m(\\theta,\\mu,b)\\,dG(\\theta|\\omega)\\,dW(\\omega;s), \n\\end{equation*}\n\n    \\item Let $R^m_b=\\mathbb{P}(\\mu \\in(\\mu',\\mu''],b;s)$\n    \\begin{itemize}\n        \\item I.e. agents with pizzaz $\\mu\\in(\\mu',\\mu'']$ and budget $b$\n        \\item Eg. $R^m_b=M(\\mu'',b;s)-M(\\mu'',b-1;s)-M(\\mu',b;s)+M(\\mu',b-1;s)$\n        \\item and $R^m_1=M(\\mu'',1)-M(\\mu',1)$\n\n    \\end{itemize}\n    \n    \\item Fix any $\\mu',\\mu''\\in [0,1]$. For all $\\mu\\in(\\mu',\\mu'']$ the steady state male market must satisfy the following flow equations: \n    \\end{itemize} \n    \\begin{align}\n        \\underbrace{\\frac{\\lambda_m}{N_w}\\Big(F_m(\\mu'')-F_m(\\mu')\\Big)}_{\\text{Enters platform}}&\\;=\\;\\underbrace{(1-\\delta)\\sum^B_{b=1} R^m_b}_{\\text{Exogenous death}}+\\underbrace{\\delta R^m_1 \\int^{\\mu''}_{\\mu'}\\rho_m(\\mu,1)\\,dM(\\mu;s)}_{\\text{Expended budget}} \\label{flow1} \\\\[15pt]\n        \\underbrace{\\delta R^m_{b+1} \\int^{\\mu''}_{\\mu'}\\rho_m(\\mu,b+1)\\,dM(\\mu;s)}_{\\text{Enters b}}&\\;=\\;\\underbrace{(1-\\delta) R^m_{b}+\\delta R^m_{b} \\int^{\\mu''}_{\\mu'}\\rho_m(\\mu,b)\\,dM(\\mu;s) }_{\\text{Leaves b}} \\label{flow2} \\\\[15pt]\n        \\underbrace{\\frac{\\lambda_m }{N_m}\\Big(F_m(\\mu'')-F_m(\\mu')\\Big)}_{\\text{Enters platform}}&\\;=\\;\\underbrace{(1-\\delta)R^m_{B} + \\delta R^m_{B} \\int^{\\mu''}_{\\mu'}\\rho_m(\\mu,B)\\,dM(\\mu;s)}_{\\text{Leaves @ B}} \\label{flow3} \\\\[15pt]\\nonumber\n    \\end{align}\n    \n\\subsection{Solving for the Endogenous Type Distribution}\n\\begin{itemize}\n    \\item With an abuse of notation, let the probability of someone in $R^m_b$ swiping right be:\n    \\begin{equation*}\n        \\bar\\rho_m(b)=\\int^{\\mu''}_{\\mu'}\\rho_m(u,b)\\,dM(u;s) \n    \\end{equation*}\n    \\item Solve for $R^m_B$ from \\eqref{flow3}\n    \\begin{equation*}\n        R^m_B= \\frac{\\lambda_m \\Big(F_m(\\mu'')-F_m(\\mu')\\Big)}{N_m\\Big((1-\\delta)+\\delta \\bar\\rho_m(B)\\Big)}\n    \\end{equation*}\n    \\item Rearrange for $R^m_b$ using \\eqref{flow2}\n    \\begin{equation*}\n        R^m_b=\\underbrace{\\frac{\\delta \\bar\\rho_m(b+1)}{\\Big((1-\\delta)+\\delta \\bar\\rho_m(b)\\Big)}}_{k_{b}}R^m_{b+1}\n    \\end{equation*}\n    \\item By the above recurrence relation:\n    \\begin{align*}\n        R^m_{B-1}&= k_{B-1}R^m_{B}\\\\\n        R^m_{B-2}&= k_{B-2}R^m_{B-1}\\\\\n        &=k_{B-2}(k_{B-1}R^m_{B})\\\\\n         &\\;\\vdots \\\\ \n         R^m_{b}&=R^m_{B}\\prod^{B-b}_{i=1} k_{B-i}\n    \\end{align*}\n    \\item Let $\\mu''=1$ and $\\mu'=0$. Then $R^m_b = \\mathbb{P}_m(b_m=b; s)$\n    \\item Given that $b$ is discrete and the above defines a PMF, we also have:\n\\end{itemize}\n\n\n\n$$\n\\mathbb{P}_m(b_m=b;s)=R^m_{B}\\prod^{B-b}_{i=1} k_{B-i}\n$$\n\n\n\n$$\n\\implies M_b(b;s)=R^m_{B}\\sum^b_{j=1}\\prod^{B-j}_{i=1} k_{B-i}\n$$\n\n- Let $\\mu''=\\mu$ and $\\mu'=0$. Then:\n\n$$\nR^m_b=M(\\theta,b;s)-M(\\theta,b-1;s)=\\mathbb{P}_m(\\theta_m<\\theta \\,\\cap \\, b_m=b;s)\n$$\n\n- By substituting the extended form for the above two cases and rearranging:\n\n$$\nM_{\\theta}(\\theta|b_m=b;\\mu,\\omega)=\\frac{\\mathbb{P}_m(\\theta_m<\\theta \\,\\cap \\, b_m=b;\\mu,\\omega)}{\\mathbb{P}(b_m=b;\\mu,\\omega)}=F_m(\\theta)\n$$\n\n- To solve for $M(\\theta,b;\\mu,\\omega)$\n\n$$\n\\begin{aligned}M(\\theta,b;\\mu,\\omega)&=\\sum^b_{j=1} M_{\\theta}(\\theta|b_m=j;\\mu,\\omega)\\mathbb{P}_m(b_m=j;\\mu,\\omega)\\\\&=F_m(\\theta)R^m_{B}\\sum^b_{j=1}\\prod^{B-j}_{i=1} k_{B-i}\\\\&=F_m(\\theta)M_b(b;\\mu,\\omega)\\end{aligned}\n$$\n\n- Letting $b=B$, we get the marginal distribution for $\\theta_m$:\n\n$$\nM(\\theta,B;\\mu,\\omega)=F_m(\\theta)M_b(B;\\mu,\\omega)=F_m(\\theta)=M_\\theta(\\theta;\\mu,\\omega)\n$$\n\n- Hence, we have:\n\n$$\n\\begin{aligned} \\mathbb{P}_m(b_m=b;\\mu,\\omega)&=\\frac{\\lambda_m  }{N_m\\Big(1-\\delta (1-\\rho^m_B) \\Big)}\\prod^{B-b}_{i=1}\\frac{\\delta\\rho^m_{B-i+1}}{\\Big(1-\\delta (1-\\rho^m_{B-i}) \\Big)}\\\\M_b(b;\\mu,\\omega)&=\\sum^b_{i=1}\\mathbb{P}_m(b_m=i;\\mu,\\omega)\\\\M_{\\theta}(\\theta;\\mu,\\omega)&=F_m(\\theta)\\\\M(\\theta,b;\\mu,\\omega)&=M_{\\theta}(\\theta;\\mu,\\omega)M_b(b;\\mu,\\omega)\\end{aligned}\n$$\n\n Tying up The Steady State\n\n- Consider the above arguments for the analogous case for women\n    - Since we know the marginal attractiveness distribution for women in the steady state is equal to $F_w(\\theta)$ then the expected probability of a right-swipe for men $\\rho^m_b$ is expressed as below, with an analogous expression for women\n\n$$\n\\rho^m_b=\\int_{\\Theta_w} \\mu(\\theta',b)\\,dW_\\theta(\\theta';\\mu,\\omega)=\\int_{\\Theta_w} \\mu(\\theta',b)\\,dF_w(\\theta')\n$$\n\n- Substitute into the first set of flow equations to solve for\n- Furthermore, let:\n\n$$\n\\begin{aligned} z^m_b &=\\prod^{B-b}_{i=1}\\frac{\\delta\\rho^m_{B-i+1}}{\\Big(1-\\delta (1-\\rho^m_{B-i}) \\Big)}, \\quad \\forall b=1,...,B_m-1\\\\z^w_b&=\\prod^{B-b}_{i=1}\\frac{\\delta\\rho^w_{B-i+1}}{\\Big(1-\\delta (1-\\rho^w_{B-i}) \\Big)} , \\quad \\forall b=1,...,B_w-1\\\\\\\\ z^m_B&=\\Big(1-\\delta (1-\\rho^m_B) \\Big) \\\\\\\\ z^w_B&=\\Big(1-\\delta (1-\\rho^w_B) \\Big) \\end{aligned}\n$$\n\n- Then the steady state is given by:\n\n$$\n\\begin{aligned}N_m(\\mu,\\omega)&=\\lambda_m\\left(\\frac{z^m_B-\\delta z^m_1\\rho^m_1}{(1-\\delta)z^m_B}\\right)\\\\\\\\N_w(\\mu,\\omega)&=\\lambda_w\\left(\\frac{z^w_B-\\delta z^w_1\\rho^w_1}{(1-\\delta)z^w_B}\\right)\\\\\\\\M(\\theta,b;\\mu,\\omega)&=F_m(\\theta) \\left(\\frac{(1-\\delta)}{z^m_B-\\delta z^m_1\\rho^m_1}\\right)\\sum^b_{i=1} z^m_i\\\\\\\\W(\\theta,b;\\mu,\\omega)&=F_w(\\theta)\\left(\\frac{(1-\\delta)}{z^w_B-\\delta z^w_1\\rho^w_1}\\right)\\sum^b_{i=1} z^w_i \\end{aligned}\n$$", "meta": {"hexsha": "d5772eb1487d8cd012bf914e3e1973ed5344f951", "size": 5494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dissertation/appendices/ap-a.tex", "max_stars_repo_name": "patohdzs/project-tinder", "max_stars_repo_head_hexsha": "4a8c138a63e31fa36981a421863a1af5162519c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dissertation/appendices/ap-a.tex", "max_issues_repo_name": "patohdzs/project-tinder", "max_issues_repo_head_hexsha": "4a8c138a63e31fa36981a421863a1af5162519c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dissertation/appendices/ap-a.tex", "max_forks_repo_name": "patohdzs/project-tinder", "max_forks_repo_head_hexsha": "4a8c138a63e31fa36981a421863a1af5162519c5", "max_forks_repo_licenses": ["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.3620689655, "max_line_length": 442, "alphanum_fraction": 0.602293411, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503681, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6195198619119812}}
{"text": "\n\\section{Fuzzy Prolog}\n\nProlog is based on First Order Logic, where the truth values are only\n{\\em true} and {\\em false}. In Fuzzy Logic, there is a whole range of\ntruth values: any real from 0 (absolute falsity) to 1 (absolute\ntruth). Fuzzy Prolog is a logic programming language based on\nthis logic.\n\nA (logic) concept can be seen as a set which includes the elements of \n``universe'' to which the concept is applicable. A predicate then can\nbe associates with a {\\em characteristic function} which determines if\nthe arguments given to the predicates are in the set defining the\npredicate (satisfy the relation represented by the predicate) or not.\n%\nGiven a relevant universal set $U$, a (classic) set $A$, associated to\na predicate, can be defined by a characteristic function \n$A : U\\rightarrow \\{0,1\\}$. If an element $x$ in $U$ belongs to $A$\nthen $A(x) = 1$, otherwise $A(x) = 0$.\n\nFuzzy sets, on the other hand, try to model imprecise concepts. An\nelement in the universal set belongs to a fuzzy sets in a certain\ngrade. For example, the youth of a person given his age. A person\nwhich is 25 years old is certainly young, and if he is 50 then he is\nnot young, but if he is 36 years old he is young in some\ngrade. Therefore, a fuzzy set $A$ is defined by a characteristic\nfunction $A : X \\rightarrow [0,1]$. Figure \\ref{fig:fuzzysetyoung}\nshows the characteristic function for the fuzzy set for \\texttt{young}.\nThe value $A(x)$ is the membership value of $x$ in the fuzzy set $A$,\nif we consider $A$ as a predicate, this value is called the truth value.\n\n\\begin{figure}[htbp]\n  \\begin{center}\n\\setlength{\\unitlength}{2547sp}%\n%\n\\begingroup\\makeatletter\\ifx\\SetFigFont\\undefined%\n\\gdef\\SetFigFont#1#2#3#4#5{%\n  \\reset@font\\fontsize{#1}{#2pt}%\n  \\fontfamily{#3}\\fontseries{#4}\\fontshape{#5}%\n  \\selectfont}%\n\\fi\\endgroup%\n\\begin{picture}(5175,2685)(1051,-3136)\n\\thinlines\n{\\color[rgb]{0,0,0}\\put(1801,-2761){\\vector( 0, 1){2250}}\n\\put(1801,-2761){\\vector( 1, 0){4125}}\n}%\n{\\color[rgb]{0,0,0}\\put(2401,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(3601,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(3001,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(4801,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(5401,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(1801,-961){\\line(-1, 0){150}}\n}%\n\\thicklines\n{\\color[rgb]{0,0,0}\\put(1801,-2761){\\line( 1, 0){600}}\n\\put(2401,-2761){\\line( 1, 2){900}}\n\\put(3301,-961){\\line( 1, 0){600}}\n\\put(3901,-961){\\line( 1,-2){900}}\n\\put(4801,-2761){\\line( 1, 0){675}}\n}%\n\\thinlines\n{\\color[rgb]{0,0,0}\\put(4201,-2761){\\line( 0,-1){150}}\n}%\n{\\color[rgb]{0,0,0}\\put(1801,-1861){\\line(-1, 0){150}}\n}%\n\\put(2326,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}10}%\n}}}\n\\put(2926,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}20}%\n}}}\n\\put(4726,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}50}%\n}}}\n\\put(5326,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}60}%\n}}}\n\\put(3526,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}30}%\n}}}\n\\put(4126,-3136){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}40}%\n}}}\n\\put(1501,-2836){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{16.8}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}0}%\n}}}\n\\put(1501,-1036){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{16.8}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}1}%\n}}}\n\\put(1276,-1936){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{16.8}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}0.5}%\n}}}\n\\put(6226,-2986){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}Age}%\n}}}\n\\put(1051,-586){\\makebox(0,0)[lb]{\\smash{\\SetFigFont{8}{14.4}{\\rmdefault}{\\mddefault}{\\updefault}{\\color[rgb]{0,0,0}Youth}%\n}}}\n\\end{picture}\n    \\caption{The fuzzy set \\texttt{young}}\n    \\label{fig:fuzzysetyoung}\n  \\end{center}\n\\end{figure}\n\nThe package \\texttt{fuzzy} allows Ciao to interpret fuzzy\npredicates. Fuzzy predicates which correspond to fuzzy sets on a\nuniversal set of numbers and with characteristic functions which are\npolygonal can be defined by the operator \n\\texttt{:\\# fuzzy\\_predicate}. For example, the above fuzzy set\n\\texttt{young} is defined as: \n\\begin{quote}\n\\begin{verbatim}\n:- use_package([...,fuzzy,...]).\n\nyoung :# fuzzy_predicate [(0,0),(10,0),(25,1),(35,1),(50,0),(60,0)].\n\\end{verbatim}\n\\end{quote}\n%\nwhere each element in the list is a vertex in the polygonal function.\nThis sentence defines a fuzzy predicate \\texttt{young/2}, where the\nfirst argument is the age and the second argument represents the truth\nvalue. Truth values are assigned to the variable in the last argument\nas constraints (Section~\\ref{sec:constr-logic-progr}) over real\nnumbers. For example,\n\n\\begin{verbatim}\n?- young(30,M).\n\nM = 1 ? \n\nyes\n?- young(38,M).\n\n(M.=.0.8 ? \n\nyes\n?- young(45,M).\n\nM.=.0.333333333333333313 ? \n\nyes\n?- young(50,M).\n\nM = 0 ? \n\\end{verbatim}\n\nMore complex fuzzy predicates can be defined by fuzzy clauses. We use\n\\texttt{:{\\tiny$^\\sim$}} instead of \\texttt{:-} as the neck of\nfuzzy clauses to distinguish them from Prolog clauses. For example,\n\\begin{quote}\n{\\tt\n\\begin{tabbing} \nyoung\\_co\\=uple(X,Y,Mu) :{\\tiny$^\\sim$} \\\\\n\\>        age(X,X1), \\\\\n\\>        age(Y,Y1),  \\\\\n\\>        young(X1,MuX), \\\\\n\\>        young(Y1,MuY). \\\\\n\\\\\nage(john,46). \\\\\nage(rose,36).\n\\end{tabbing}\n}\n\\end{quote}\n%\ndefines a fuzzy predicate \\texttt{young\\_couple/3} that uses in its\ndefinition a fuzzy predicate \\texttt{young/2} and a Prolog predicate\n\\texttt{age/2}. The truth value of Prolog calls in the body of the\nfuzzy clause is 1 is it succeeds and 0 otherwise. The truth value of\n\\texttt{young\\_couple} is obtained by aggregating the truth values of\nthe calls in the body. By default the aggregation function is\n\\texttt{min}, i.e., the minimum from all body goals. In this example,\n\n\\begin{verbatim}\n?- young_couple(john,rose,M).\n\nM.=.0.26 ? \n\\end{verbatim}\n%\nbecause $0.26$ is the minimum of $\\{1,1,0.93,0.26\\}$ which are the\ntruth values of the calls \\texttt{age(john,X1)},\n\\texttt{age(rose,Y1)}, \\texttt{young(46,MuX)} and\n\\texttt{young(36,MuY)} respectively.\n\nAggregation functions are indicated after the operator\n\\texttt{:{\\tiny$^\\sim$}}. For example, if we want the truth value of\n\\texttt{young\\_couple/3} to be the product of the truth values in its\ndefinition then we write: \n\\begin{quote}\n{\\tt\n\\begin{tabbing} \nyoung\\_co\\=uple(X,Y,Mu) :{\\tiny$^\\sim$} prod \\\\\n\\>        age(X,X1), \\\\\n\\>        age(Y,Y1),  \\\\\n\\>        young(X1,MuX), \\\\\n\\>        young(Y1,MuY).\n\\end{tabbing}\n}\n\\end{quote}\n%\nso that now:\n\n\\begin{verbatim}\n?- young_couple(john,rose,M).\n\nM.=.0.23 ? \n\\end{verbatim}\n%\nsince $0.23$ is the product of $\\{1,1,0.93,0.26\\}$. \n\nOther {\\em aggregations functions} are:\n\\begin{itemize}\n\\item \\texttt{max}: the maximum truth value in the body of the\n  clause. It is a ``disjunctive'' aggregation operation.\n\\item \\texttt{luka}: the Lukasiewicz T-norm. It is a ``conjunctive''\n  operator like \\texttt{min} and \\texttt{prod}. The Lukasiewicz T-norm\n  of two values $x$ and $y$ is defined as $\\max(0,x + y -1)$.\n\\item \\texttt{dluka}: the Lukasiewicz T-conorm. It is defined as\n  $\\min(1,x + y)$. \n\\item \\texttt{dprod} the product T-conorm. It is defined as $x + y -\n  (x * y)$.\n\\end{itemize}\n%\n(T-conorms are disjunctive operators dual to the conjunctive operator\nof the corresponding T-norm.)\n\nThe min-max fuzzy logic can be modeled using the operators \\texttt{max} and\n\\texttt{min}. In the same way, using the operators \\texttt{luka} and\n\\texttt{dluka} the lukasiewicz fuzzy logic can be modeled. Let us see\nan example. \n\nSuppose we want to measure which is the possibility that a couple\nof values, obtained throwing two loaded dice, sum 5. Let us suppose we\nonly know that one die is loaded to obtain a small value and the other\nis loaded to obtain a large value. The program to declare this is the\nfollowing: \n\\begin{quote}\n{\\tt\n\\begin{tabbing} \nsmall :\\# fuzzy\\_predicate([(1,1),(2,1),(3,0.7),(4,0.3),(5,0),(6,0)]). \\\\\nlarge :\\# fuzzy\\_predicate([(1,0),(2,0),(3,0.3),(4,0.7),(5,1),(6,1)]). \\\\\n\\ \\\\\ndie1(X,M)\\= 123456789012345678901234567890\\= two\\_dice\\=\\kill\ndie1(X,M)\\> :{\\tiny$^\\sim$}       \\> two\\_dice\\=(X,Y,M) :{\\tiny$^\\sim$} min \\\\\n\\>       small(X,M).            \\> \\> die1(X,M1), \\\\\n\\>                              \\> \\> die2(Y,M2). \\\\\ndie2(X,M) :{\\tiny$^\\sim$} \\\\\n\\>        large(X,M).\n\\end{tabbing}\n}\n\\end{quote}\n%\nwhere \\texttt{two\\_dice(X,Y,M)} gives the possibility that the first die\nobtains the value \\texttt{X} and the second the value \\texttt{Y}.\nTherefore in this clause we need a conjunctive operator as\n\\texttt{min}. Now we can define:\n\\begin{quote}\n{\\tt\n\\begin{tabbing} \nsum(5,M)\\= :{\\tiny$^\\sim$} max \\\\\n\\>        two\\_dice(4,1,M1), \\\\\n\\>        two\\_dice(1,4,M2), \\\\\n\\>        two\\_dice(3,2,M3), \\\\\n\\>        two\\_dice(2,3,M4).\n\\end{tabbing}\n}\n\\end{quote}\n%\nfor which we need a disjunctive operator as \\texttt{max} which\naggregates the different ways of obtaining 5 for the sum. We will\nget for example: \n\n\\begin{verbatim}\n?- sum(5,M).\n\nM.=.0.7 ?\n\\end{verbatim}\n\nThe package also gives the possibility of defining fuzzy predicates\nwhich are the fuzzy negation of other fuzzy predicates. For example,\nthe fuzzy predicate \\texttt{small} could be defined as:\n\\begin{quote}\n\\begin{verbatim}\nsmall :# fnot large/2\n\\end{verbatim}\n\\end{quote}\n%\nso that the truth value \\verb+M+ of \\verb+small(X,M)+ is defined as\n\\verb+1-N+ where \\verb+N+ is the truth value of \\verb+large(X,N)+.  \n\nIt is possible to ``fuzzify'' Prolog predicates. For\nexample to fuzzify \\verb+age/2+ it is only necessary to write:\n\\begin{quote}\n\\begin{verbatim}\nage_f :# fuzzy age/2\n\\end{verbatim}\n\\end{quote}\n%\nand the program is expanded with a new fuzzy predicate\n\\texttt{age\\_f/3} (the last argument is the truth value) with truth\nvalue equal to 0 if \\texttt{age/2} fails and 1 otherwise. \n\nProlog calls\nin bodies of fuzzy clauses are automatically fuzzified, except those\nthat are enclosed in \\verb+{}+ brackets. This is useful if we want\ntruly prolog calls to define a fuzzy predicate, for example to set a\nthreshold for a fuzzy clause like in the following program:\n\\begin{quote}\n{\\tt\n\\begin{tabbing} \nvery\\_goo\\=d\\_credit\\_customer(X,Mu):{\\tiny$^\\sim$} min \\\\\n\\>        good\\_credit\\_customer(X,M), \\\\\n\\>        \\{Mu .>=. 0.8\\}.  \\\\\nvery\\_good\\_credit\\_customer(X,Mu):{\\tiny$^\\sim$} min \\\\\n\\>        good\\_credit\\_customer(X,M), \\\\\n\\>        fail, \\\\\n\\>        \\{Mu .<. 0.8\\}.\n\\end{tabbing}\n}\n\\end{quote}\n%\nwhich defines a very good credit customer as a good credit customer\nwith truth value greater than $0.8$. A  good credit customer is\ndefined, for example, as follows:\n\\begin{quote}\n{\\tt\n\\begin{tabbing} \ngood\\_credit\\_customer(john,0.8):{\\tiny$^\\sim$} . \\\\\ngood\\_credit\\_customer(mary,0.5):{\\tiny$^\\sim$} . \\\\\ngood\\_credit\\_customer(alan,0.9):{\\tiny$^\\sim$} . \n\\end{tabbing}\n}\n\\end{quote}\n\nNote how fuzzy facts do require the operator \\texttt{:{\\tiny$^\\sim$}}\n(with a space separating it from the final dot). Otherwise, they will\nbe deemed as normal Prolog clauses. Mixing fuzzy clauses and Prolog\nclauses may cause unexpected behaviours. The compiler will signal\nthe problem with a warning message indicating discontiguous clauses for\nthe predicate.\n\nIn this case we obtain the following answers: \n\n\\begin{verbatim}\n?- very_good_credit_customer(X,Mu).\n\nX = john,\nMu.=.0.8 ? ;\n\nX = alan,\nMu.=.0.9 ? ;\n\nMu = 0,\nX = mary ? ;\n\nno\n?- \n\\end{verbatim}\n", "meta": {"hexsha": "6f6f4caca7473fadbd00f8f5e2505cd62c8e6ac1", "size": 11704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "www/CiaoDE/ciao/doc/tutorial/SRC/fuzzy.tex", "max_stars_repo_name": "leuschel/ecce", "max_stars_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-10-16T08:23:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-10T18:17:26.000Z", "max_issues_repo_path": "www/CiaoDE/ciao/doc/tutorial/SRC/fuzzy.tex", "max_issues_repo_name": "leuschel/ecce", "max_issues_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "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": "www/CiaoDE/ciao/doc/tutorial/SRC/fuzzy.tex", "max_forks_repo_name": "leuschel/ecce", "max_forks_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-10-18T11:11:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-13T14:18:49.000Z", "avg_line_length": 33.25, "max_line_length": 123, "alphanum_fraction": 0.6766062884, "num_tokens": 4089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.619216767160694}}
{"text": "\\section{Scanning with Regular Languages \\& Parsers with CFG}\n\\subsection*{Scanner}\nSplits input in sub-strings and groups in lexical units. Feeds tokenized version of input to parser. \\textbf{hand-built scanners:} Beyond regular languages; Easier to debug; More efficient.\n\\subsection*{Automata}\n\\textbf{NFA} ($Q,\\Sigma,\\delta,q_0,F$) $Q \\times (\\Sigma \\cup \\{\\epsilon \\}) \\rightarrow 2^Q$ transition func. \\textbf{DFA} NFA deterministic if $\\delta (q,\\epsilon )\\ =\\ \\phi\\ \\forall\\ q\\ \\in\\ Q \\wedge\\ |\\delta(q,a)|\\ =\\ 1\\ \\forall\\ (q,a)\\ \\in\\ Q\\ \\times\\ \\Sigma$. For DFAs, $\\delta$ form $Q \\times\\ \\Sigma\\ \\rightarrow\\ Q$. Can detect word w, in $\\mathcal{O}(|w|)$ from regex constructed in P-time.\n\\subsection*{Myhill-Nerode theorem}\n\\textbf{Equivalence classes:}We say x, y are equivalent with respect to L, written x \\textasciitilde$_L$ y if xz $\\in$ L $\\iff$ yz $\\forall\\ z \\in \\Sigma^*$\np> \\textbf{theorem:} Language L is regular iff $~_L$ has finite number of equivalence classes. Number of equivalence classes of $~_L$ is number of states of smallest DFA.\n\\subsection*{recognizing v scanning}\n\\textbf{Recognizing:} Given string, simulate DFA and get boolean answer: (not) lexeme recognized. \\textbf{Scanning:} Given string, scanner returns sequence tokens. Token is longest match (maximal much).\n\\subsection*{Longest matches}\nFind longest prefix of remaining string which is lexical unit. \\textbf{2 or more matches:} 1. First will be chosen; 2. Disallow, DFAs cant accept same input. Doing: 1. DFAs ordered; 2. Language checking when generating scanner. For all pairs of EREs with $L_1,L_2$, we should check: $L_1 \\cap L_2 = \\phi$.\n\\subsection*{Grammar}\nG = (V, T, P, S) P: $\\alpha\\rightarrow\\beta$ with $\\alpha \\in (V \\cup T)^*V(V\\cup T)^*$ and $\\beta \\in (V \\cup T)^*$. \\textbf{Derivation} Let $\\gamma \\in (V \\cup T)^*V(V \\cup T)^*$ and $\\delta \\in (V \\cup T)^*$. We say $\\delta$ can be derived from $\\gamma$ iff there are $\\gamma_1,\\gamma_2 \\in (V \\cup T)*$ and a rule $\\alpha \\rightarrow \\beta \\in P$ st $\\gamma = \\gamma_1 \\cdot \\alpha \\cdot \\gamma_2$ and $\\delta = \\gamma_1 \\cdot \\beta \\cdot \\gamma_2$.\n\\subsection*{Grammar classes}\nFor all rules $\\alpha \\rightarrow \\beta$: \\textit{class 0}: All grammars no restriction; \\textit{class 1}: Context-sensitive grammars: either $\\alpha = S$ and $\\beta = \\epsilon$ or $|\\alpha| \\leqslant |\\beta|$ and S does not appear in $\\beta$; \\textit{class 2}: Context-free grammars: $\\alpha \\in V$; \\textit{class 3}: $\\alpha \\in V$ and left-regular = $\\beta \\in T^* \\cup (V \\cdot T^*)$. right-regular = $\\beta \\in T^* \\cup (T^* \\cdot V)$. \\textbf{Chomsky’s hierarchy:} Languages: $Reg \\subset CFL \\subset CSL \\subset RE$.\n\\subsection*{Universality of CNF}\n\\textbf{CFG to CNF:} Eliminate: 1. Start symbol from RHS; 2. Rules with non-solitary terminals. 3. RHS with more than 2 nonterminals. 4. $\\epsilon$ productions; 5. Unit rules. \\textbf{splits:} For grammars in CNF, A can generate w if we can find a rule A -> BC and we can split w in two non-empty words w = u $\\cdot$ v st: B -> u and C -> v. It does detect w in polynomial time $\\mathcal{O}(|w|^3)$\n\\subsection*{Attributes (semantics)}\nWe associate to every nonterminal variable V of the grammar a finite set A(V) of attributes partitioned into synthesized attributes $A_s(V)$ and inherited attributes $A_i(V)$. I Each attribute $\\alpha \\in A(V)$ has a (potentially infinite) set of possible values. The actual value will be selected based on the appearance of V in the derivation tree. \\textbf{Attribute mapping functions:} For each rule $\\alpha \\rightarrow \\beta_1 ... \\beta_k$ we have a semantic rule functions $f_{\\alpha,j}$ mapping values of certain attributes of $\\beta_1 ... \\beta_k$ to values of $\\alpha \\in A(\\beta_j)$. \\textbf{welldefinedness:} Semantic rule should not be recursive. They are formulated in a way st all attributes are always defined at all nodes in all possible derivation trees. \\textbf{synthesized/inherited:} synthesized if its value depends on the vaules of its children in some derivation tree, if not the inherited.\n\\subsection*{(Non)deterministic pushdown automata}\nA is a tuple $(Q, \\Sigma, \\Gamma, \\delta, q_0, Z_0, F)$ $\\delta : Q \\times (\\Sigma \\cup \\{\\epsilon\\}) \\times \\Gamma \\rightarrow 2^{Q\\times\\Gamma^*}$ transition func. \\textbf{Deterministic:} 1. $\\forall q \\in Q$, all $a \\in \\Sigma \\cup {\\epsilon}$, and all $\\gamma \\in \\Gamma$: $\\delta(q,a,\\gamma)$ has at most 1 element. 2. $\\forall q \\in Q$, and all $\\gamma \\in \\Gamma$: if $\\delta(q,\\epsilon,\\gamma) \\neq \\phi$ then $\\delta(q,a,\\gamma) = \\phi$ for all $a \\in \\Sigma$, but does not accept CFL $L_{pal}$\n\\subsection*{Simplifying grammar}\n\\textbf{Factoring:} $A \\rightarrow wB$ and $A \\rightarrow wC$, split A into $A_1 \\rightarrow wA_2$ and $A_2 \\rightarrow B$, $A_2 \\rightarrow C$. \\textbf{Indirect left recursion:} $\\forall$ pairs of rules $A \\rightarrow Bw$ and $B \\rightarrow \\beta_1$ we replace the first rule by $A \\rightarrow \\beta_1 w$. Repeated. \\textbf{Direct left recursion:} If we have rules $(V \\rightarrow V \\alpha_i)_{i\\in I}$ and $(V \\rightarrow \\beta_j)_{j\\in J}$, we can replace them by $(V' \\rightarrow \\alpha_i )_{i\\in I}$, $(V \\rightarrow \\beta_j V')_{j\\in J}$, and $V' \\rightarrow \\epsilon$. \\textbf{unproductive:} A unproductive if there is no word w that can be derived from A. \\textbf{unreachable:} $X \\in T \\cup V$ is unreachable if no sentential form contains X.\n", "meta": {"hexsha": "9c9948379544b48c6e686b0fb5c3129e4224bce8", "size": 5392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/scanning_parsing.tex", "max_stars_repo_name": "BasilRommens/compilers-cheatsheet", "max_stars_repo_head_hexsha": "a8336115c175db4cbe0c5bb6f960dd1e5bcf87bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-02-10T21:27:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-11T19:35:39.000Z", "max_issues_repo_path": "src/scanning_parsing.tex", "max_issues_repo_name": "BasilRommens/compilers-cheatsheet", "max_issues_repo_head_hexsha": "a8336115c175db4cbe0c5bb6f960dd1e5bcf87bb", "max_issues_repo_licenses": ["MIT"], "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/scanning_parsing.tex", "max_forks_repo_name": "BasilRommens/compilers-cheatsheet", "max_forks_repo_head_hexsha": "a8336115c175db4cbe0c5bb6f960dd1e5bcf87bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 215.68, "max_line_length": 912, "alphanum_fraction": 0.7086424332, "num_tokens": 1674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6192167646188272}}
{"text": "\\chapter{O-C Diagrams}\n\\label{Chapter_oc}\n\\section{O-C Basics}\nObserved minus Calculated diagrams is a diagnostic tool and involves the evaluation and interpretation \nof the disagreement between the measure of an observable event and its\npredicted value \\citep{Sterken2005basic}.\nThe idea that random processes may be important in determining O-C behaviour is not new, dating back at least to\n\\cite{Eddington1929}. Before dealing with the consequences for the statistics of\nO-C diagrams, it is worthwhile to review possible physical causes of random\ncycle-to-cycle period variations \\citep{Koen2005stat}.\n\nIn astronomy, O-C usually implies a temporal aspect, and is used when\ndiscussing cyclic phenomena where the times of occurrence of a given event is irregular. \nThe O-C diagram is then constructed by plotting the quantity O-C as a function of time, the correct interpretation \nof these deviations leads to a better model (and a new O-C diagram).\n\nIn variable-star studies, O-C is sometimes expressed as deviations of phase\nin the cycle of variability, whereas the time axis is the cycle number (commonly\nindicated by $E$). In such studies, the O-C diagram mostly refers to rather\nsimple C formalisms, viz. linear or quadratic ephemeris formulae, sometimes\ncombined with a trigonometric periodic term \\citep{Sterken2005basic}.\n\n%Period of a recurrent phenomenon is the time interval after which the event \n%goes exactly through a same cycle again. In reality, we deal with cycles, rhythms, waves, and \n%pseudo-periods or characteristic times, in short, with processes that repeat themselves\n%in a more or less regular way.\n\nWe are dealing with processes that repeat themselves in a more or less regular way.\nAny attempt to construct a reliable O-C diagram will fail if a wrong\nvalue of period $P$ is used. But it is not always easy to derive a period from the observational data: \n$P$ is not directly observable, it follows from the\ndetermination of at least two moments of time of the same reference phase (epochs). \nThe observation of two such epochs $T_{1}$ and $T_{2}$ immediately provide us an upper limit for $P$. \nWhen more than two such times are available, the period can be derived by a least-squares solution of a set of\nequations\n\\begin{equation} \\label{eq:period}\nT_{i} - T_{j} = nP\n\\end{equation}\nwhere $n$ is an integer, commonly called the cycle number $E$(epoch).\n\nPhase is a position on the cycle of variation, a convenient periodic measure of\nelapsed time: $\\varphi (t)$ is the fraction of $P$ that elapsed since the occurrence of the\nreference time $T_{0}$ and is given by\n\n\\begin{equation} \\label{eq:phase}\n\\varphi = \\frac{T-T_{0}}{P} ~\\bmod~ 1\n\\end{equation}\n\nThe most common approach to the O-C procedure is the one in which one reference \nphase is selected, and where the timings of this reference phase are studied\nand interpreted.\nSeveral methods exist to determine the reference phase in a variability curve. \nThis methods are discussed in Chapter \\ref{Chapter_minima_det}.\n\n\\section{Constant and Variable Period}\nIf $P$ is constant and if its value is known, equation (\\ref{eq:period}) leads to\n\n%\\begin{equation} \\label{eq:Tmin}\n%T_{max} = T_{0} + P E\n%\\end{equation}\n%or,\n\\begin{equation} \\label{eq:Tmin2}\nT_{min} = T_{0} + P E\n\\end{equation}\nwhere $T_{min}$ is the time of minimum light, $T_{0}$\nis the zero epoch and $E$ is the number of cycles elapsed since the zero epoch. $T_{0}$ and\n$P$ are obtained through a least-squares solution. The longer the time interval (in\ncycles) over which the data have been collected, the higher will be the accuracy\nof the solution for $P$: the uncertainty in $P$ is inversionally proportional to the\nnumber of cycles, and proportional to the r.m.s. scatter of the data.\n\nIt is certainly not a trivial task to conclude from experimental data that a\nsignificant period change has occurred. In principle, changes of period could\nbe described by any mathematical formula expressing $P$ as a function of time.\nThus, the time of epoch $T_{m}$ is\n\n\\begin{equation} \\label{eq:P_var}\nT_{m} = T_{0} + \\int P(t)dt   ~~~~~\\mathrm{or}~~~~~   T_{m} = T_{0} + \\int P(E)dE\n\\end{equation}\n\nIn most cases, relation (\\ref{eq:P_var}) is restricted to linear variations, cyclic variations, or\na combination of both of them.\n\nMany causes can lead to period variations.\n%the reference phase is seen systematically earlier (negative O-C) or later (positive O-C), \n%depending whether eclipsing variable is nearer or further from the observer. \n%Such meandering of the reference phase will result in a cyclic O-C diagram. \n%Apsidal motion in an elliptical orbit can re-orient the orbit with\n%respect to the observer and cause an effect similar to the previous case. \nTransfer of matter (between stars in a multiple system) or mass ejection (from a system)\ncan provoke period changes. Periodic variations of O-C can indicate presents of other body in binary system.\n\nIf period changes linear with time, we will write $P$ as $P = a+bt$, where $t$ is the time, and $a,~b$ are constants.\nLet $P_{0}$ be the period at $t=0$ and $\\bar{P}$ is the average period over the whole time of observations, then\n\n\\begin{equation} \\label{eq:P_lin_P}\nP = a + b \\bar{P}E\n\\end{equation} \nand\n\\begin{equation} \\label{eq:P_lin_Pmid}\n\\bar{P} = a + \\frac{1}{2}bt\n\\end{equation}  \nso\n\\begin{equation} \\label{eq:P_lin_Tm}\nT_{m} = T_{0} + aE + \\frac{1}{2}b \\bar{P}E^{2}\n\\end{equation} \nwith\n\\begin{equation} \\label{eq:P_lin_add}\nP_{0} = a,  ~~~~  \\frac{dP}{dE} = b\\bar{P},   ~~~~   \\frac{dP}{dt} = b\n\\end{equation} \nexpected time\n\\begin{equation} \\label{eq:P_lin_Tm_res}\nT_{m} = T_{0} + P_{0}E + \\frac{1}{2} \\frac{dP}{dt} \\bar{P}E^{2}\n\\end{equation} \n\n\\begin{equation} \\label{eq:P_lin_OC_res}\nO-C = \\frac{1}{2} \\frac{dP}{dt} \\bar{P}E^{2}\n\\end{equation} \n\n%Equation (\\ref{eq:P_lin_Tm}) is the most-frequently applied equation in O-C discussions. \n%Unfortunately, it is often misunderstood. Worse even, the factor $1/2$ is occasionally\n%forgotten. The numerical value of $\\frac{dP}{dt}$ is obtained through a quadratic fit, which\n%also yields $P_{0}$.\n\nWhen we now look at the O-C diagram for BW Vul in Fig.\\ref{fig_oc}, we see that its\nshape suggests a possible parabolic form, which seems to stand for a linear period\nchange. The least-squares parabolic fit to equation (\\ref{eq:P_lin_Tm}) yields $P_{0} = 0.2010274$\nand $\\frac{dP}{dt}= 1.8 \\cdot 10^{−10}$ days per cycle, or $~9.1 \\cdot 10^{−10}$ day per day.\n\n\\begin{figure}[!ht]\n\\vspace{0cm}\n\\centerline{\\includegraphics[width=0.65\\textwidth]{oc_example.png}}\n\\caption{O-C diagram of some $T_{min}$ of BW Vul with best fit parabola. \\citep{Sterken2005basic}}\n\\label{fig_oc}\n\\end{figure}\n\n\\begin{figure}[!ht]\n\\vspace{0cm}\n\\centerline{\\includegraphics[width=0.65\\textwidth]{oc_example_2.png}}\n\\caption{Differential O-C diagram after prewhitening with the fitted parabola. \\citep{Sterken2005basic}}\n\\label{fig_oc2}\n\\end{figure}\n\nWhen looking at Fig.\\ref{fig_oc}, one notices that there are stretches of the O-C parabolic\nfit where the data at one time are systematically above the fitted curve, and at\nother times remain below the curve. Figure \\ref{fig_oc2} shows the differences that were\nobtained by removing the parabolic trend, and shows wave shape with\nvariable amplitude \\citep{Sterken2005basic}. Such a trend, in particular when it repeats itself, \ncan indicate presence of other body in binary system. \nIn such case, O-C can be fitted with additional term corresponding to 3rd body orbit parameters:  \n\n\\begin{equation} \\label{eq:P_lin_OC_sin}\nT_{m} = T_{0} + P_{0}E + \\frac{1}{2} \\frac{dP}{dt} \\bar{P}E^{2} +\n\\dfrac{a_{12}\\sin i}{c}   \\left[  \\dfrac{1-e^2}{1+e \\cos\\nu}   \\sin(\\nu + \\omega)  + e \\sin \\omega  \\right]\n\\end{equation} \n \n\n%\\begin{equation} \\label{eq:P_lin_OC_sin}\n%T_{m} = T_{0} + P_{0}E + \\frac{1}{2} \\frac{dP}{dt} \\bar{P}E^{2} + A\\sin(2\\frac{\\pi}{\\Pi}E+\\phi)\n%\\end{equation} \n%\n%\\begin{equation}\\label{eq:4_mmm}\n%T_{min} = JD_{0}+P \\times E + Q \\times E^2 + \\dfrac{a_{12}\\sin i}{c}   \\left[  \\dfrac{1-e^2}{1+e \\cos\\nu}   \\sin(\\nu + \\omega)  + e \\sin \\omega  \\right] \n%\\end{equation}\nwhere $a_{12} \\sin i$ is the projected semi-major axis, $e$ is the eccentricity,\n$\\omega$ is the longitude of the periastron, $\\nu$ is the true anomaly of the EB orbit around the common centre of the mass of\nthe whole system and $c$ is the velocity of light \\citep{irwin1959}.\n", "meta": {"hexsha": "2beee34545f5ac7c36c6fbbecbc6d23c621be954", "size": 8357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Chapter_OC.tex", "max_stars_repo_name": "vkudak/PhD", "max_stars_repo_head_hexsha": "898b0dfc86b04471c92050253c59c0c874e92c24", "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/Chapter_OC.tex", "max_issues_repo_name": "vkudak/PhD", "max_issues_repo_head_hexsha": "898b0dfc86b04471c92050253c59c0c874e92c24", "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": "Chapters/Chapter_OC.tex", "max_forks_repo_name": "vkudak/PhD", "max_forks_repo_head_hexsha": "898b0dfc86b04471c92050253c59c0c874e92c24", "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.744047619, "max_line_length": 154, "alphanum_fraction": 0.7393801603, "num_tokens": 2472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672181749421, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6192167638479333}}
{"text": "% Preamble.\n\\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{siunitx}\n%\\usepackage{subfiles}  % Include for subfiles.\n%\\usepackage{tikz}  % Include for handmade figures.\n%\\usepackage{graphicx}  % Include for external figures.\n\n%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{3}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-09-11}\n\n\\title{\\vspace{-2\\baselineskip}PHYS 151 - Written Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\n\\section*{1.}\n\\textit{The figure shows a sailing ship approaching a hostile harbor. At time\n$t = 0$, a cannon placed atop a lighthouse, at height $h$ above the deck of\nthe hostile ship, fires a projectile at the oncoming ship, which is moving at\na speed of $v_1$ toward the shore. The cannonball is fired at a speed of $v_2$\nat an angle $\\theta$ above the horizontal.}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{For this cannonball to impact exactly the front of the ship,\n\tat what distance $D$ from the dock should the ship be when the equipment\n\tis thrown? Ignore air resistance.} \\\\[\\baselineskip]\n\tThe ship's horizontal and vertical positions as functions of time can be\n\tmodeled by\n\t\\begin{gather*}\n\t\tx_s(t) = -v_1t + D, \\\\\n\t\ty_s(t) = 0.\n\t\\end{gather*}\n\tIn turn, the projectile's horizontal and vertical positions can be modeled\n\tby\n\t\\begin{gather*}\n\t\tx_p(t) = v_2\\cos(\\theta)t, \\\\\n\t\ty_p(t) = -\\frac{g}{2}t^2 + v_2\\sin(\\theta)t + h.\n\t\\end{gather*}\n\tThe projectile must hit the ship at a time $t_f$ when both\n\t$x_s(t_f) = x_p(t_f)$ and $y_s(t_f) = y_p(t_f)$. Because $y_s(t_f)$ and\n\t$y_p(t_f)$ are both known, $t_f$ can be solved for with\n\t\\begin{gather*}\n\t\ty_s(t_f) = y_p(t_f), \\\\\n\t\t0 = -\\frac{g}{2}{t_f}^2 + v_2\\sin(\\theta)t_f + h, \\\\\n\t\tt_f = \\frac{v_2\\sin(\\theta) + \\sqrt{(v_2\\sin(\\theta))^2 + 2gh}}{g}.\n\t\\end{gather*}\n\tUsing $t_f$, $D$ can be solved for with\n\t\\begin{gather*}\n\t\tx_s(t_f) = x_p(t_f), \\\\\n\t\t-v_1t_f + D = v_2\\cos(\\theta)t_f, \\\\\n\t\tD = v_2\\cos(\\theta)t_f + v_1t_f, \\\\\n\t\tD = (v_2\\cos(\\theta) + v_1) t_f.\n\t\\end{gather*}\n\tIn summary, the expanded formula to find the distance $D$ is\n\t\\begin{gather*}\n\t\t\\boxed{D = (v_2\\cos(\\theta) + v_1) t_f}\n\t\\end{gather*}\n\twhere\n\t\\begin{equation*}\n\t\t\\boxed{\n\t\t\tt_f = \\frac{v_2\\sin(\\theta)\n\t\t\t+ \\sqrt{(v_2\\sin(\\theta))^2 + 2gh}}{g}\n\t\t}.\n\t\\end{equation*}\n\t\\item \\textit{What is the total time of flight of the cannonball? \\\\\n\tUse $v_1 = 40.0\\si{\\frac{cm}{s}},\\ v_2 = 16.0\\si{\\frac{m}{s}},\\ \n\t\\theta = \\ang{55.0}$, and $h = 9.25\\si{m}$.}\n\t\\begin{align*}\n\t\tt_f\n\t\t&= \\frac{v_2\\sin(\\theta) + \\sqrt{(v_2\\sin(\\theta))^2 + 2gh}}{g} \\\\\n\t\t&= \\frac\n\t\t\t{\n\t\t\t\t(16.0\\si{\\frac{m}{s}}) \\sin(\\ang{55.0})\n\t\t\t\t+ \\sqrt{\n\t\t\t\t\t((16.0\\si{\\frac{m}{s}}) \\sin(\\ang{55.0}))^2\n\t\t\t\t\t+ 2 (9.81\\si{\\frac{m}{s^2}}) (9.25\\si{m})\n\t\t\t\t}\n\t\t\t}\n\t\t\t{9.81\\si{\\frac{m}{s^2}}}\n\t\t\t\\\\\n\t\t&= \\boxed{3.25\\si{s}}.\n\t\\end{align*}\n\t\\item \\textit{Using the numbers given in (b.), what are the $x$ and $y$\n\tcomponents of the velocity of the cannonball just before impacting the\n\tdeck of the ship?} \\\\[\\baselineskip]\n\tLet $v_x(t)$ and $v_y(t)$ represent the horizontal and vertical components\n\tof the projectile's velocity as functions of time, respectively.\n\t\\begin{align*}\n\t\tv_x(t_f)\n\t\t&= v_2\\cos(\\theta) \\\\\n\t\t&= (16.0\\si{\\frac{m}{s}}) \\cos(\\ang{55.0}) \\\\\n\t\t&= \\boxed{9.18\\si{\\frac{m}{s}}}.\n\t\\end{align*}\n\t\\begin{align*}\n\t\tv_y(t_f)\n\t\t&= -gt_f + v_2\\sin(\\theta) \\\\\n\t\t&= -(9.81\\si{\\frac{m}{s^2}}) (3.25\\si{s})\n\t\t\t+ (16.0\\si{\\frac{m}{s}}) \\sin(\\ang{55.0}) \\\\\n\t\t&= \\boxed{-18.8\\si{\\frac{m}{s}}}.\n\t\\end{align*}\n\\end{enumerate}\n\n\n\\end{document}\n", "meta": {"hexsha": "ec674c546edb3d7020acde834cedc30c13ccc98a", "size": 3753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20203-phys-151-50380/hw03/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-20203-phys-151-50380/hw03/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-20203-phys-151-50380/hw03/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": 31.275, "max_line_length": 78, "alphanum_fraction": 0.6392219558, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.6192167618477742}}
{"text": "\\begin{itemize}\n\\item For an L-shape gene it is verified that:\n\\begin{itemize}\n\\item The ratio $r=\\frac{\\min\\{\\mathit{cMI}(t)\\}}{\\mathit{cMI}(0)}$ is small, \n\\item $t^{\\ast} = \\mathrm{argmin}\\{ \\mathit{cMI}(t) \\}$ is the \\textbf{optimal threshold} for \ndichotomizing the methylation data of this gene.\n\\end{itemize}\n\\end{itemize}\n\n%To estimate the MI terms we use a kernel-based estimator by applying a %Gaussian kernel to each data point:\n%\\[\n%I(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%\\]\n%where $h$ is a tuning parameter for the kernel width empirically set to \n% $h=0.3$.\n  \n\n\\subsection{Based on Spline regression}\n\\begin{itemize}\n\\item As an alternative to the previous method we suggest that spline regression \\cite{racine} can be used for scatter plot clustering.\n\\item In spline regression a curve $y=s(x)$ is represented as $\\mathbf{y}_i=\\mathbf{B}_i\\mathbf{c}$ where \n\\begin{itemize}\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 and \n\\item $\\mathbf{c}$ is the vector of spline coefficients.\n\\end{itemize}\n\n\\item This suggests the following method (and algorithm) for detecting L--shaped genes based on \\textbf{Clustering Spline Coefficients}:\n\\begin {enumerate}\n\\item Select genes with significant correlation.\n\\item For each selected gene fit a cubic splines regression model.\n\\item Obtain a distance matrix between all genes using the $1-\\rho$ distance computed on spline coefficients.\n\\item Perform a hierarchical clustering and \n\\item Select genes in the \\textit{L-shaped cluster(s)}.\n\\end{enumerate}\n\\end{itemize}\n", "meta": {"hexsha": "45201f7eeeec02dcccbe8842d225a95ba5633beb", "size": 1800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2016-07-IBS-Victoria-Poster/sections/methods2.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/2016-07-IBS-Victoria-Poster/sections/methods2.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/2016-07-IBS-Victoria-Poster/sections/methods2.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": 48.6486486486, "max_line_length": 136, "alphanum_fraction": 0.7022222222, "num_tokens": 582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6190965391388298}}
{"text": "\\subsection{Field extensions}\\label{subsec:field_extensions}\n\n\\begin{definition}\\label{def:splitting_field}\n  A \\term{splitting field} for a nonconstant polynomial \\( f(X) \\in \\Bbbk[X] \\) of degree \\( n \\) is the smallest \\hyperref[def:field_extension]{field extension} \\( \\BbbK \\) of \\( \\Bbbk \\) in which \\( f(X) \\) has \\( n \\) \\hyperref[def:polynomial_root]{roots}. That is,\n  \\begin{equation*}\n    \\BbbK \\cong \\Bbbk(a_1, \\ldots, a_n),\n  \\end{equation*}\n  where \\( a_1, \\ldots, a_n \\) are roots of \\( f(X) \\).\n\n  By \\fullref{thm:splitting_field_existence}, splitting fields exist and are unique up to an isomorphism.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:splitting_field_existence}\n  There exists a unique up to an (possibly nonunique) isomorphism \\hyperref[def:splitting_field]{splitting field} for every nonconstant polynomial in one indeterminate over a field.\n\\end{proposition}\n\\begin{proof}\n  \\SubProof{Proof of existence}\\mcite[thm 9.10 \\\\ thm. 9.12]{Knapp2016BasicAlgebra} We use induction on the degree of the polynomial \\( f(X) = \\sum_{k=0}^n a_k x^k \\) over \\( \\Bbbk \\). In the base case \\( n = 1 \\), \\( f(X) \\) is already linear, and hence \\( \\Bbbk \\) is itself a splitting field for \\( f(X) \\).\n\n  Suppose that there exist splitting fields for polynomials over \\( \\Bbbk \\) of degree \\( n - 1 \\). By \\fullref{thm:maximal_ideal_theorem}, the \\hyperref[def:semiring_ideal]{principal ideal} \\( \\braket{ f(X) } \\) is contained in some maximal ideal \\( M \\). By \\fullref{thm:quotient_by_maximal_ideal}, the quotient of \\( R[X] \\) by \\( M \\) is a field.\n\n  Define \\( u_n \\coloneqq \\braket{ X } + M \\). We have \\( f(u_n) = \\braket{ f(X) } + M \\), hence \\( u_n \\) is a root of \\( f \\) in \\( M \\). Then\n  \\begin{equation*}\n    f(X) = (X - u_n) q(X)\n  \\end{equation*}\n  for some polynomials \\( q(X) \\) and \\( r(X) \\), both of degree less than \\( n \\) (or \\( r(X) = 0 \\)).\n\n  We can now apply the inductive hypothesis to obtain a splitting field of \\( q(X) \\). Let \\( u_1, \\ldots, u_{n-1} \\) be the roots of \\( q(X) \\) in this field. We can then adjoin \\( u_1, \\ldots, u_n \\) to the field \\( \\Bbbk \\) to obtain a splitting field \\( \\Bbbk(u_1, \\ldots, u_n) \\) of \\( f(X) \\). Denote this field by \\( \\BbbK \\).\n\n  \\SubProof{Proof of uniqueness} Suppose that, given our previous construction, \\( \\BbbL \\) is also a splitting field for \\( f(X) \\).\n\n  Again, we use induction on the degree \\( n \\) of \\( f(X) \\). The case \\( n = 1 \\) is again obvious.\n\n  Suppose that any two splitting fields for polynomials over \\( \\Bbbk \\) of degree \\( n - 1 \\) are isomorphic. Let \\( b_n \\) be a root of \\( f(X) \\) in \\( \\BbbL \\) and let\n  \\begin{equation*}\n    f(X) = (X - b_n) r(X).\n  \\end{equation*}\n\n  Let \\( b_1, \\ldots, b_{n-1} \\) be the roots of \\( r(X) \\). Let \\( \\varphi \\) be an isomorphism between the subfield \\( \\Bbbk(a_1, \\ldots, a_{n-1}) \\) of \\( \\BbbK \\) and the corresponding subfield \\( \\Bbbk(b_1, \\ldots, b_{n-1}) \\) of \\( \\BbbL \\). It follows that\n  \\begin{equation*}\n    \\underbrace{\\prod_{k=1}^{n-1} (X - b_k)}_{r(X)} = \\underbrace{\\prod_{k=1}^{n-1} (X - \\varphi(a_k))}_{q^\\varphi(X)}.\n  \\end{equation*}\n\n  Therefore, we can extend \\( \\varphi \\) to an isomorphism \\( \\widehat{\\varphi}: \\BbbK \\to \\BbbL \\) by putting \\( \\widehat{\\varphi}(a_n) \\coloneqq b_n \\).\n\\end{proof}\n\n\\begin{theorem}[Classification of finite fields]\\label{thm:finite_fields}\n  \\hfill\n  \\begin{thmenum}\n    \\thmitem{thm:finite_fields/characteristic} The \\hyperref[def:ring_characteristic]{characteristic} of a \\hyperref[def:field]{field} with \\( q \\) elements is a \\hyperref[def:prime_number]{prime number} \\( p \\), and \\( q \\) is a power of \\( p \\).\n\n    The fields of prime cardinality are sometimes called \\term{prime fields}.\n\n    \\thmitem{thm:finite_fields/prime_field} For a prime number \\( p \\), the ring \\hyperref[thm:ring_of_integers_modulo]{\\( \\BbbZ_p \\)} of integers modulo \\( p \\) is a field.\n\n    \\thmitem{thm:finite_fields/splitting} All \\hyperref[def:field]{fields} with \\( q \\) elements are \\hyperref[def:field/homomorphism]{isomorphic} as \\hyperref[def:splitting_field]{splitting fields} for the polynomial\n    \\begin{equation*}\n      X^q - X \\in \\BbbZ_p[X].\n    \\end{equation*}\n\n    Utilizing the general conventions of identifying isomorphic objects in algebra, we denote by \\( \\BbbF_q \\) \\enquote{the} finite field with \\( q \\) elements. Finite fields are also called \\term{Galois fields}.\n\n    Every member of \\( \\BbbF_q \\) is a root of \\( X^q - X \\).\n  \\end{thmenum}\n\\end{theorem}\n\\begin{proof}\n  \\SubProofOf{thm:finite_fields/characteristic} Let \\( \\BbbK \\) be a field with \\( q \\) elements and let \\( p \\) be the \\hyperref[def:ring_characteristic]{characteristic} of \\( \\BbbK \\). Then \\( \\BbbZ_p \\) is a subring of \\( \\BbbK \\). By \\fullref{thm:multiplicative_group_of_integers_modulo}, \\( \\BbbZ_p \\) is a field.\n\n  By \\fullref{thm:quotient_by_maximal_ideal}, \\( \\braket{ p } \\) is a maximal ideal in \\( \\BbbZ \\), and, by \\fullref{thm:def:semiring_ideal/maximal_is_prime}, \\( p \\) is a prime number.\n\n  By \\fullref{thm:lagranges_theorem_for_groups}, \\( p \\) divides \\( q \\). But \\( \\BbbK / \\BbbZ_p \\) is again a field by \\fullref{thm:quotient_ideal_lattice_theorem}, and again has prime characteristic. Continuing by induction, we eventually obtain a sequence \\( p_1, \\ldots, p_n \\) of prime numbers such that\n  \\begin{equation*}\n    q = p_1 \\cdots p_n.\n  \\end{equation*}\n\n  By \\fullref{thm:lagranges_theorem_for_groups}, \\( q \\) cannot contain subgroups of prime cardinalities \\( p_1 \\) and \\( p_2 \\) unless \\( p_1 = p_2 \\). Hence, again by induction, we conclude that\n  \\begin{equation*}\n    p_1 = \\cdots = p_n.\n  \\end{equation*}\n\n  Therefore, \\( q = p^n \\).\n\n  \\SubProofOf{thm:finite_fields/prime_field} Follows from \\fullref{thm:multiplicative_group_of_integers_modulo}.\n\n  \\SubProofOf{thm:finite_fields/splitting} Let \\( \\BbbK \\) be a field with \\( q \\) elements with characteristic \\( p \\). We will show that every element of \\( \\BbbK \\) is a root of \\( X^q - X \\in \\BbbZ_p[X] \\).\n\n  The multiplicative group of \\( \\BbbK \\) has order \\( q - 1 \\). The order of a non-zero element \\( a \\in \\BbbK \\) divides \\( q - 1 \\) by \\fullref{thm:def:group_order/divides}, hence \\( a^{q - 1} = 1 \\pmod q \\). We also have \\( 0^q = 0 \\). Therefore, for every element of \\( \\BbbF_q \\), we have \\( a^q = a \\).\n\n  Then\n  \\begin{equation*}\n    X^q - X = \\prod_{u \\in \\BbbK} (X - u).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:functions_over_prime_fields}\n  For every \\hyperref[thm:finite_fields]{finite field} \\( \\BbbF_q \\) and every \\hyperref[def:polynomial_algebra]{polynomial ring} \\( \\BbbF_q[X_1, \\ldots, X_n] \\) in finitely many indeterminates, there exists an \\( \\BbbF_q \\)-\\hyperref[def:algebra_over_ring]{algebra} isomorphism\n  \\begin{equation*}\n    \\frac {\\BbbF_q[X_1, \\ldots, X_n]} {\\braket{ X_i^q - X_i \\given i = 1, \\ldots, n }} \\cong \\fun(\\BbbF_q^n, \\BbbF_q),\n  \\end{equation*}\n  where \\( \\fun(\\BbbF_q^n, \\BbbF_q) \\) is the \\hyperref[thm:functions_over_algebra]{\\( \\BbbF_q \\)-algebra of all functions} from \\( \\BbbF\n  _q^n \\) to \\( \\BbbF_q \\).\n\n  Furthermore, every coset of polynomials has a unique representative given by \\fullref{thm:finite_field_lagrange_interpolation}.\n\\end{proposition}\n\\begin{proof}\n  Consider the \\hyperref[thm:polynomial_semiring_universal_qroperty]{functional evaluation homomorphism}\n  \\begin{equation*}\n    \\Phi: \\BbbF_q[X_1, \\ldots, X_m] \\to \\fun(\\BbbF_q^m, \\BbbF_q).\n  \\end{equation*}\n\n  By \\fullref{thm:finite_field_lagrange_interpolation}, \\( \\Phi \\) is surjective. Then, by \\fullref{thm:quotient_algebra_universal_property},\n  \\begin{equation*}\n    \\BbbF_q[X_1, \\ldots, X_n] / \\ker \\Phi \\cong \\fun(\\BbbF_q^m, \\BbbF_q).\n  \\end{equation*}\n\n  We will now prove that \\( \\ker \\Phi \\) equals\n  \\begin{equation*}\n    I \\coloneqq \\braket{ X_i^q - X_i \\given i = 1, \\ldots, n }.\n  \\end{equation*}\n\n  First, let \\( e: \\mscrX \\to \\BbbF_q \\) be the variable assignment that assigns \\( u_1, \\ldots, u_n \\) to the corresponding indeterminates. By \\fullref{thm:finite_fields/splitting}, every member of \\( \\BbbF_q \\) is a root of \\( X_i^q - X_i \\). Then, for any indeterminate \\( X_i \\),\n  \\begin{equation*}\n    \\Phi_e(X_i^q - X_i) = u_i^q - u_i = 0 \\pmod q.\n  \\end{equation*}\n\n  Hence, the polynomial function \\( \\Phi(X_i^q - X_i) \\) is the zero constant function. It follows that any linear combination of the polynomials \\( X_i^q - X_i \\) for \\( i = 1, \\ldots, n \\) is also the zero function. Therefore, \\( I \\subseteq \\ker \\Phi \\).\n\n  We will prove the converse inclusion via induction on \\( n \\).\n\n  In the case of a single indeterminate \\( X \\), for every polynomial \\( f(X) \\in \\ker \\Phi \\), we know that the entirety of \\( \\BbbF_q \\) are roots of \\( f(X) \\). By \\fullref{thm:def:integral_domain/root_limit}, \\( f(X) \\) has at most \\( q \\) roots. Hence, \\( X - u \\) divides \\( f(X) \\) for every \\( u \\in \\BbbF_q \\). We have\n  \\begin{equation*}\n    \\underbrace{\\prod_{u \\in \\BbbF_q} (X - u)}_{\\mathclap{ X^q - X \\T*{by \\fullref{thm:finite_fields/splitting}}}} \\mid f(X),\n  \\end{equation*}\n  and hence \\( f(X) \\in \\braket{ X^q - X } \\).\n\n  We have, up until now, shown that the entire proposition holds for the case of one indeterminate. Suppose that the proposition holds for \\( n - 1 \\) indeterminates and let \\( f \\in \\BbbF_q[X_1, \\ldots, X_n] \\) be a nonconstant polynomial such that \\( \\Phi(f) \\) is the zero function. Due to \\fullref{thm:def:polynomial_algebra/iterated}, we can regard \\( f \\) as a univariate polynomial in \\( X_n \\)over \\( \\BbbF_q[X_1, \\ldots, X_{n-1}] \\). Thus,\n  \\begin{equation*}\n    f(X_1, \\ldots, X_n) = \\sum_{k =0}^\\infty \\underbrace{\\parens*{ \\sum_\\gamma a_{(k,\\gamma)} X_1^{\\gamma_1} X_2^{\\gamma_1} \\cdots X_{n-1}^{\\gamma_{n-1}} }}_{s_k(X_1, \\ldots, X_{n-1})} {X_n}^k,\n  \\end{equation*}\n  where \\( \\gamma \\) is a multi-index over the first \\( n - 1 \\) indeterminates.\n\n  As a polynomial in \\( X_n \\), \\( f \\) has \\( m \\coloneqq (n-1)p \\) roots \\( s_1, \\ldots, s_m \\), which are themselves polynomials from \\( \\BbbF_q[X_1, \\ldots, X_{n-1}] \\). For some \\( c \\), we have\n  \\begin{equation*}\n    f(X_1, \\ldots, X_n) = c(X_1, \\ldots, X_{n-1}) \\prod_{j=1}^m (X_n - s_j(X_1, \\ldots, X_{n-1}))\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    0 = \\Phi(f) = \\Phi(c) \\cdot \\prod_{j=1}^m \\parens[\\Big]{ \\Phi(X_n) - \\Phi(s_j) }.\n  \\end{equation*}\n\n  Since \\( \\BbbF_q[X_1, \\ldots, X_{n-1}] \\) is \\hyperref[def:entire_semiring]{entire}, we conclude that either \\( \\Phi(c) \\) is the zero function or \\( \\Phi(X_n) = \\Phi(s_j) \\) for at least one index \\( 1 \\leq j \\leq m \\). The latter is impossible, because \\( \\Phi(X_n) \\) is linearly independent from polynomials in the first \\( n - 1 \\) variables.\n\n  The inductive hypothesis holds for the polynomial \\( c \\), and \\( \\Phi(c) \\) being the zero function implies\n  \\begin{equation*}\n    c \\in \\braket{ X_i^q - X_i \\given i = 1, \\ldots, n - 1 } \\subsetneq I.\n  \\end{equation*}\n\n  Therefore, \\( f \\in I \\) since \\( f \\) divides \\( c \\). We have chosen \\( f \\) to be an arbitrary member of \\( \\ker \\Phi \\), which implies \\( \\ker \\Phi \\subseteq I \\).\n\n  We have already shown that \\( I \\subseteq \\ker \\Phi \\). We thus conclude that \\( I = \\ker \\Phi \\) and\n  \\begin{equation*}\n    \\BbbF_q[X_1, \\ldots, X_m] / I \\cong \\fun(\\BbbF_q^m, \\BbbF_q).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:transcendetal_element}\n  We say that the element \\( a \\in \\BbbK \\) of the field extension \\( \\BbbK \\) of \\( \\Bbbk \\) is \\term{transcendental} over \\( \\BbbK \\) if it is \\hyperref[def:algebraic_dependence]{algebraically independent}.\n\n  If \\( a \\) is not transcendental, we say that it is \\term{algebraic}. If every element of \\( \\BbbK \\) is algebraic over \\( \\Bbbk \\), we say that \\( \\BbbK \\) is an \\term{algebraic extension} of \\( \\Bbbk \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:field_is_algebraic_over_itself}\n  Every field is an \\hyperref[def:transcendental_element]{algebraic extension} of itself.\n\\end{proposition}\n\\begin{proof}\n  Every element \\( a \\in \\BbbK \\) is a root of the polynomial \\( X - a \\).\n\\end{proof}\n\n\\begin{theorem}[Euler's constant is transcendental]\\label{thm:eulers_constant_is_transcendental}\n  \\hyperref[def:exponential_function]{Euler's constant} \\( e \\) is \\hyperref[def:transcendetal_element]{transcendental} over \\( \\BbbQ \\).\n\\end{theorem}\n\n\\begin{theorem}[Pi is transcendental]\\label{thm:pi_is_transcendental}\\mcite[454]{Knapp2016BasicAlgebra}\n  The number \\hyperref[def:pi]{\\( \\pi \\)} is \\hyperref[def:transcendetal_element]{transcendental} over \\( \\BbbQ \\).\n\\end{theorem}\n\n\\begin{example}\\label{ex:polynomials_over_pi}\n  \\Fullref{thm:pi_is_transcendental} implies that the polynomials \\( \\BbbQ[X] \\) can be embedded into \\( \\BbbR \\) via \\( \\Phi_\\pi: \\BbbQ[X] \\to \\BbbR \\). We can identify a polynomial\n  \\begin{equation*}\n    p(X) = \\sum_{i=0}^n a_k X^k\n  \\end{equation*}\n  with rational coefficients with the number\n  \\begin{equation*}\n    p(\\pi) = \\sum_{i=0}^n a_k \\pi^k.\n  \\end{equation*}\n\\end{example}\n\n\\begin{definition}\\label{def:finite_field_extension}\n  If \\( \\BbbK \\) is \\hyperref[thm:vector_space_dimension]{finite-dimensional vector space} over \\( \\Bbbk \\), we say that \\( \\BbbK \\) is a \\term{finite extensions} of \\( \\Bbbk \\).\n\\end{definition}\n\n\\begin{lemma}\\label{thm:finite_field_extensions_are_algebraic}\n  Every \\hyperref[def:finite_field_extension]{finite field extension} is \\hyperref[def:transcendetal_element]{algebraic}.\n\\end{lemma}\n\\begin{proof}\n  Let \\( \\BbbK \\) be a field extension of \\( \\Bbbk \\). Consider the evaluation map \\( \\Phi_a: \\Bbbk[X] \\to \\Bbbk[u] \\) for some \\( u \\in \\BbbK \\).\n\n  Since the polynomials \\( X^k \\) for \\( k = 0, 1, 2, \\ldots \\) form a basis for \\( \\Bbbk[X] \\). If \\( \\Phi_a \\) is injective, then \\( \\Phi_a(X_k) \\) are linearly independent over \\( \\BbbK \\). But \\( \\BbbK \\) has finite dimension over \\( \\Bbbk \\).\n\n  The obtained contradiction shows that \\( \\Phi_a \\) is not injective.\n\\end{proof}\n\n\\begin{definition}\\label{def:algebraically_closed_field}\\mcite[prop. 9.20]{Knapp2016BasicAlgebra}\n  We say that the field \\( \\BbbK \\) is algebraically closed if any of the equivalent conditions are satisfied:\n  \\begin{thmenum}\n    \\thmitem{def:algebraically_closed_field/trivial_algebraic_extensions} \\( \\BbbK \\) has no nontrivial algebraic \\hyperref[def:transcendental_element]{extensions}.\n    \\thmitem{def:algebraically_closed_field/linear_irreducible_polynomials} Every irreducible polynomial in \\( \\BbbK[X] \\) is linear.\n    \\thmitem{def:algebraically_closed_field/at_least_one_root} Every nonconstant polynomial in \\( \\BbbK[X] \\) has at least one root in \\( \\BbbK \\).\n    \\thmitem{def:algebraically_closed_field/factorization} Every polynomial in \\( \\BbbK[X] \\) \\hyperref[def:irreducible_factorization]{factors} into a product of linear polynomials.\n    \\thmitem{def:algebraically_closed_field/exactly_n_roots} Every polynomial in \\( \\BbbK[X] \\) of degree \\( n \\) has exactly \\( n \\) roots in \\( \\BbbK \\), counting the root multiplicities.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:algebraically_closed_field/trivial_algebraic_extensions}{def:algebraically_closed_field/linear_irreducible_polynomials} Let \\( p(X) \\) be an irreducible polynomial in \\( \\BbbK[X] \\).\n\n  Since \\( \\BbbK[X] \\) is a unique factorization domain, it satisfies \\fullref{def:unique_factorization_domain/primes_and_ideals}, and hence \\( p(X) \\) is a prime element. Thus, \\( \\braket {p(X)} \\) is a \\hyperref[def:semiring_ideal/prime]{prime ideal} in \\( \\BbbK[X] \\).\n\n  Since \\( \\BbbK[X] \\) is a principal ideal domain, by \\fullref{thm:def:principal_ideal_domain/prime_ideal_is_maximal}, \\( \\braket{ p(X) } \\) is also a maximal ideal. By \\fullref{def:semiring_ideal/maximal/quotient}, the quotient \\( Q \\coloneqq \\BbbK[X] / \\braket{ p(X) } \\) is a field. The vectors \\( 1, X, X^2, \\cdots, X^n \\) for a basis of \\( Q \\) over \\( \\BbbK \\), where \\( n \\) is the degree of \\( p(X) \\).\n\n  By \\fullref{thm:finite_field_extensions_are_algebraic}, \\( Q \\) is an algebraic extension of \\( \\BbbK \\). Since \\( \\BbbK \\) has no nontrivial algebraic extensions, it follows that \\( \\BbbK = Q \\). Thus, \\( Q \\) has dimension \\( 1 \\), and we have already discussed that \\( \\dim Q = \\deg p \\). Therefore, \\( p \\) is a linear polynomial.\n\n  \\ImplicationSubProof{def:algebraically_closed_field/linear_irreducible_polynomials}{def:algebraically_closed_field/at_least_one_root} Suppose that every irreducible polynomial is linear.\n\n  By \\fullref{thm:def:unique_factorization_domain/polynomial_ring}, \\( \\BbbK[X] \\) is a unique factorization domain, and thus there exist irreducible polynomials \\( q_1(X), \\ldots, q_n(X) \\) and a unit \\( a \\) such that\n  \\begin{equation*}\n    p(X) = a q_1(X) \\cdots q_n(X).\n  \\end{equation*}\n\n  By assumption, the irreducible polynomials are linear, and hence have roots. Therefore, \\( p(X) \\) has at least one root.\n\n  \\ImplicationSubProof{def:algebraically_closed_field/at_least_one_root}{def:algebraically_closed_field/factorization} Suppose that \\( u_1 \\) is a root of \\( p(X) \\). Then \\( p(X) \\) is divisible by \\( (X - u_1) \\). Using induction on the degree of \\( p(X) \\), we can factor \\( p(X) \\) into\n  \\begin{equation*}\n    p(X) = a (X - u_1) (X - u_2) \\cdots (X - u_n),\n  \\end{equation*}\n  where \\( a \\) is a unit of \\( \\BbbK \\). This is the desired factorization.\n\n  \\ImplicationSubProof{def:algebraically_closed_field/factorization}{def:algebraically_closed_field/exactly_n_roots} Follows from the equivalence in \\fullref{def:polynomial_root} by induction on the polynomial degree. By \\fullref{thm:def:integral_domain/root_limit}, the number of roots is bounded by \\( n \\).\n\n  \\ImplicationSubProof{def:algebraically_closed_field/exactly_n_roots}{def:algebraically_closed_field/trivial_algebraic_extensions} Suppose that every nonconstant polynomial of degree \\( n \\) has exactly \\( n \\) roots in \\( \\Bbbk \\) and let \\( \\BbbK \\) be an algebraic extension of \\( \\Bbbk \\).\n\n  By \\fullref{thm:def:integral_domain/root_limit}, every polynomial in \\( \\BbbK[X] \\) has at most \\( n \\) roots. By assumption, every root of every polynomial is contained in \\( \\Bbbk \\). Since \\( \\BbbK \\) is algebraic over \\( \\Bbbk \\), it follows that every element of \\( \\BbbK \\) is a root of some polynomial. Therefore, \\( \\BbbK = \\Bbbk \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:no_finite_extensions_of_closed_fields}\n  An \\hyperref[def:algebraically_closed_field]{algebraically closed field} has no nontrivial finite extension fields.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:finite_field_extensions_are_algebraic} applied to \\fullref{def:algebraically_closed_field/trivial_algebraic_extensions}.\n\\end{proof}\n\n\\begin{theorem}[{Weak \\term[en=zero locus theorem]{nullstellensatz}}]\\label{thm:weak_nullstellensatz}\n  Let \\( \\mscrK \\) be an \\hyperref[def:algebraically_closed_field]{algebraically closed field} and let \\( \\BbbK[X_1, \\ldots, X_n] \\) be its \\hyperref[def:polynomial_algebra]{polynomial ring} in \\( n \\) indeterminates.\n\n  The ideal \\( M \\) of \\( \\BbbK[X_1, \\ldots, X_n] \\) is \\hyperref[def:semiring_ideal/maximal]{maximal} if and only if there exist elements \\( u_1, \\ldots, u_n \\) of \\( \\BbbK \\) such that\n  \\begin{equation*}\n    M = \\braket{ X_1 - u_1, \\ldots, X_n - u_n }.\n  \\end{equation*}\n\\end{theorem}\n", "meta": {"hexsha": "2b8a999c1ee9b3f94e1a20aafd2a02cc8ca6590c", "size": 19256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/field_extensions.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/field_extensions.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/field_extensions.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": 71.8507462687, "max_line_length": 448, "alphanum_fraction": 0.6816057333, "num_tokens": 6603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.6190965250053325}}
{"text": "\\section{On-policy Prediction with Approximation}\n\nIn this section we consider the applications of function approximation techniques in reinforcement learning, to learn mappings from states to values. Typically we will consider parametric functional forms, in which case we can achieve a reduction in dimensionality of the problem (number of parameters smaller than state space). In this way, the function generalises between states, as the update of one state impacts the value of another.\\\\\n\nFunction approximation techniques are applicable to partially observable problems, in which the full state space is not available to the agent. A function approximation scheme which ignores certain aspects of the space behaves just as if those aspects are unobservable.\n\n\\subsection{Value-function Approximation}\nMany techniques from supervised learning are applicable to learning value functions from experience, but not all are equipped to deal with the non-stationarity that often occurs in RL. In RL it is also important to be able to learn online.\\\\\n\n\\subsection{The Prediction Objective ($\\VE{}$)}\nDefine a state distribution $\\mu(s) \\geq 0$, $\\sum_s \\mu(s) = 1$ that represents how much we care about each state $s$. Given an estimator $\\hat{v}(s, \\vec{w})$ of $v_\\pi(s)$, parameterised by $\\vec{w}$, we define our objective function as the \\emph{Mean Squared Value Error}\n\\begin{equation}\n    \\VE{} \\doteq \\sum_{s \\in \\S{}} \\mu(s) \\left[ v_\\pi(s) - \\hat{v}(s, \\vec{w})\\right]^2.\n\\end{equation}\\\\\n\nOften we choose $\\mu(s)$ to be the fraction of time spent in $s$. Under on-policy training this is referred to as the \\emph{on-policy distribution}. In continuing tasks, this is the stationary distribution under $\\pi$.\\\\\n\nAt this stage it is not clear that we have chosen the correct (or even a good) objective function, since the ultimate goal is a good policy for the task. For now, will continue with $\\VE{}$ nonetheless.\n\n\\subsubsection*{The on-policy distribution in episodic tasks}\nIn an episodic task the on-policy distribution depends on how the initial states of the episode are chosen. Let $h(s)$ be the probability that an episode begins in state $s$ and $\\eta(s)$ be the expected time spent in $s$ per episode. Note that you can either start in $s$ or transition there from $\\bar{s}$, so\n\\[\n    \\eta(s) = h(s) + \\sum_{\\bar{s}} \\eta(\\bar{s}) \\sum_a \\pi(a \\vert{} \\bar{s}) p(s \\vert{} \\bar{s}, a) \\quad \\forall s \\in \\S{}.\n\\]\nOne can solve this system for $\\eta$, then take the on-policy distribution as \n\\[\n    \\mu(s) = \\frac{\\eta(s)}{\\sum_{s'}\\eta(s')} \\quad \\forall s \\in \\S{}.\n\\]\nThis is the natural choice without discounting. With discounting we consider it a form of termination and include a factor of $\\gamma$ in the second term of the recurrence relation above.\n\n\\subsection{Stochastic-gradient and Semi-gradient Methods}\n\\subsubsection*{(Stochastic) Gradient Descent}\nWe assume that states appear in examples with the same distribution $\\mu(s)$, in which case a good strategy is to minimise our loss function on observed examples. \\emph{Stochastic gradient-descent} moves the weights in the direction of decreasing $\\VE{}$:\n\\begin{align}\n    \\vec{w}_{t+1} &=  \\vec{w}_t - \\frac12 \\alpha \\grad_{\\vec{w}} \\left[v_\\pi(S_t) - \\hat{v}(S_t, \\vec{w})\\right]^2 \\\\\n                  &= \\vec{w}_t + \\alpha \\left[ v_\\pi(S_t) - \\hat{v}(S_t, \\vec{w})\\right] \\grad_{\\vec{w}} \\hat{v}(S_t, \\vec{w}).\n\\end{align}\nOf course, we might not know the true value function exactly, we will likely only have access to some approximation of it $U_t$, possibly corrupted by noise or got from bootstrapping with our latest estimate. In these cases we cannot perform the above computation, but we can still make the general SGD update\n\\begin{equation}\n    \\vec{w}_{t+1} = \\vec{w}_t + \\alpha \\left[ U_t - \\hat{v}(S_t, \\vec{w})\\right] \\grad_{\\vec{w}} \\hat{v}(S_t, \\vec{w})\n\\end{equation}\nIf $U_t$ is an unbiased estimate of the state value for each $t$, then the sequence $\\vec{w}_t$ is guaranteed to converge to a local optimum under the usual stochastic approximation conditions for decreasing $\\alpha$.\\\\\n\nThe Monte Carlo target $U_t = G_t$ is an unbiased estimator, so locally optimal convergence is guaranteed in this case. Algorithm is given below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/gradient_monte_carlo.png}\\\\\n\n\\subsubsection*{Semi-Gradient Descent}\nWe don't get the same convergence guarantees if we use bootstrapping estimates of the value function in our update target, for instance if we had used the TD(0) update $U_t = R_{t+1} + \\gamma \\hat{v}(S_{t+1}, \\vec{w})$. This is because the target now depends on the parameters $\\vec{w}$, so the gradient is not exactly the gradient of our loss function -- it only takes into account the change on our estimate with respect to $\\vec{w}$. For this reason we call updates such as this \\emph{semi-gradient methods}.\\\\\n\nSemi-gradient methods are often preferable to pure gradient methods since they can offer much faster learning, in spite of not giving the same convergence guarantees. A prototypical choice is the TD(0) update, an algorithm for which is given in the box below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/semi_gradient_td0.png}\\\\\n\n\\subsubsection*{State Aggregation}\n\\emph{State aggregation} is a simple form of generalising in which we group together states and fix them to have the same estimated value. \n\n\\subsection{Linear Methods}\nAs always, linear methods of function approximation are an important special case\n\\begin{equation}\n    \\hat{v}(s, \\vec{w}) = \\vec{w}^\\top \\vec{x}(s)\n\\end{equation}\nwhere $\\vec{x}(s)$ are feature vectors, vectors of functions (features) $x_i: \\S{} \\to \\mathbb{R}$. The SGD update for the linear model is\n\\begin{equation}\n    \\vec{w}_{t+1} = \\vec{w}_t + \\alpha \\left[ U_t - \\hat{v}(S_t, \\vec{w})\\right] \\vec{x}(s).\n\\end{equation}\nNaturally, the linear case is the most studied and the majority of convergence results for learning systems are for this case (or simpler). In particular, there is the benefit that there is a unique global optimum for our loss function (in the non-degenerate case).\n\n\\subsubsection*{Convergence of Linear TD(0)}\nThe semi-gradient TD(0) algorithm is known to converge under linear function approximation. The point converged to is not the global optimum, but a point near the local optimum. We consider this case in more detail. First write $\\vec{x}_t = \\vec{x}(S_t)$ then rearrange the update\n\\begin{align}\n    \\vec{w}_{t+1} &= \\vec{w}_t + \\alpha \\left(R_{t+1} + \\gamma \\vec{w}_t^\\top \\vec{x}_{t+1} - \\vec{w}_{t}^\\top \\vec{x}_t\\right)\\vec{x}_t \\\\\n                  &= \\vec{w}_t + \\alpha \\left(R_{t+1}\\vec{x}_t - \\vec{x}_t(\\vec{x}_t -  \\gamma\\vec{x}_{t+1})^\\top\\vec{w}_t\\right).\n\\end{align}\nNow note that we can write\n\\[\n    \\E{}[\\vec{w}_{t+1} \\vert{} \\vec{w}_t] = \\vec{w}_t + \\alpha (\\vec{b} - \\mathrm{A}\\vec{w}_t)\n\\]\nwhere $\\vec{b} = \\E{}[R_{t+1}\\vec{x}_t]$ and $\\mathrm{A} = \\E{}\\left[\\vec{x}_t(\\vec{x}_t - \\gamma\\vec{x}_{t+1})^\\top\\right]$. It's clear now that in a steady state we must have (can be shown that $\\mathrm{A}$ positive definite and so invertible)\n\\[\n    \\vec{w}_{\\text{TD}} = \\mathrm{A}^{-1}\\vec{b}.\n\\]\nWe call this point the \\emph{TD fixed point}, linear semi-gradient TD(0) converges to this point. (In the notes there is a box with some details.)\\\\\n\nAt the TD fixed point (in the continuing case) it has been proven that $\\VE$ is within a bounded expansion of the lowest possible error\n\\begin{equation}\n    \\VE(\\vec{w}_{\\text{TD}}) \\leq \\frac{1}{1 - \\gamma} \\min_{\\vec{w}} \\VE(\\vec{w}).\n\\end{equation}\nIt is often the case that $\\gamma$ is close to 1, so this region can be quite large. The TD method has substantial loss in asymptotic performance. Regardless of this, it still has much lower variance than MC methods and can thus be faster. The desired update method will depend on the task at hand.\\\\\n\n\\subsubsection*{Other Linear Updates}\nLinear semi-gradient DP $U_t = \\sum_a \\pi(a \\vert{} S_t) \\sum_{s', r} p(s', r \\vert{} S_t, a) [r + \\gamma \\hat{v}(s', \\vec{w}_t)]$ with updates according to the on-policy distribution also converged to the TD fixed point. There are convergence results for other step methods we have considered too. Critical to all of these is that updates are taken according to the on-policy distribution. For other update distributions, bootstrapping methods can diverge to infinity. $n$-step semi-gradient TD is given in the box below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/semi_gradient_tdn.png}\\\\\n\n\n\\subsection{Feature Construction for Linear Methods}\nDiscussed in this section\n\\begin{itemize}\n    \\item Polynomial Basis\n    \\item Fourier Basis\n    \\item One could use other orthogonal function bases but they are yet to see application in RL.\n    \\item Radial Basis Functions. (Offer little advantage over coarse coding with circles, but greatly increases computational complexity)\n\\end{itemize}\n\n\\setcounter{subsubsection}{2}\n\\subsubsection{Coarse Coding}\nOne way of promoting generalisation between states is to cover the state-space in overlapping regions, with each region representing a feature. If the state is being considered, then all regions that contain this state will be activated. The amount of overlap of the receptive fields (the states which can activate a feature) dictates the breadth of generalisation.\n\n\n\\subsubsection{Tile Coding}\nA \\emph{tiling} of a continuous state space is form of coarse-coding that creates a partition of the state space (all of the state space is covered but elements of the tiling do not overlap). We call a sub-region of a tiling a \\emph{tile}. One might introduce multiple overlapping tilings to incorporate generalisation.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/tile_coding.png}\\\\\n\nAn advantage of tilings is that, because each tiling forms a partition, the total number of features active at any one time is just the total number of tilings used. So $\\alpha = \\frac{1}{kn}$, where $n$ is the number of tilings, results in $k$-trial learning. That is, on average the learning asymptotes after $k$ presentations of each state (assuming all updates use the same, constant target).\\\\\n\nTile coding is computationally efficient and may be the most practical feature representation for modern sequential digital computers.\\\\\n\nA useful trick for reducing memory requirements is \\emph{hashing}. One can essentially hash the state space, then tile the hashed values. This means that each tile in the hashed space will represent (multiple) pseudo-randomly distributed tiles in the original space. Since only a small proportion of the state space needs to have high resolution value estimates, this can be a good way to reduce memory with little loss in performance.\n\n\\subsection{Selecting Step-Size Parameters Manually}\nIn the tabular case, taking $\\alpha = \\frac1\\tau$ will mean that the estimate for a state will approach the mean of its targets, with the most recent targets having the greatest effect, in about $\\tau$ experiences.\\\\\n\nWith function approximation, there is not a clear notion of the number of visits to a state because of continuous degrees of generalisation. However, a sensible consideration for learning from $\\tau$ presentations is \n\\begin{equation}\n    \\alpha = \\frac{1}{\\tau \\E{}[\\vec{x}^\\top\\vec{x}]}.\n\\end{equation}\n\n\\subsection{Nonlinear Function Approximation: Artificial Neural Networks}\nThese of course see a lot of application in RL, especially with deep learning. There are some good review articles on the web.\n\n\\subsection{Least-Squares TD}\nWe saw earlier that TD(0) with linear function approximation converges to the TD fixed point \n\\[\n    \\vec{w}_{\\text{TD}} = \\mathrm{A}^{-1}\\vec{b},\n\\]\nwhere $\\vec{b} = \\E{}[R_{t+1}\\vec{x}_t]$ and $\\mathrm{A} = \\E{}\\left[\\vec{x}_t(\\vec{x}_t - \\gamma\\vec{x}_{t+1})^\\top\\right]$. Previously we computed the solution iteratively, but this is a waste of data! We could compute the MLE of $\\mathrm{A}$ and $\\vec{b}$ and then use those. This is the \\emph{Least-Squares TD Algorithm}, it uses the estimators\n\\begin{equation}\n    \\hat{\\mathrm{A}}_t = \\sum_{k=0}^{t-1} x_k ( x_k - \\gamma x_{k+1})^\\top + \\epsilon \\mathrm{I} \\quad \\mathrm{and} \\quad \\hat{\\vec{b}}_t = \\sum_{k=0}^{t-1} R_{t+1} x_k \n\\end{equation}\nwhere we introduce $\\epsilon > 0$ to ensure that the sequence of $\\hat{\\mathrm{A}}_t$ are each invertible. (These are estimates of $t\\mathrm{A}$ and $t\\vec{b}$ but the $t$ cancel out.)\\\\\n\nThis is the most data efficient form of TD(0), but it is also more computationally intensive. Implementing incrementally and with tricks to do the matrix inverse (because of the particular form of $\\mathrm{A}$ as sum of outer products), one can do this in $O(d^2)$ computations, where $d$ is the number of parameters/features (note that this is independent of $t$). (For comparison, the semi-gradient TD(0) method needs $O(d)$ computations.) The formula for $\\mathrm{A}$ is \n\\begin{align}\n    \\hat{\\mathrm{A}}_t &= \\left(\\hat{\\mathrm{A}}_{t-1} + x_t ( x_t - \\gamma x_{t+1})^\\top\\right)^{-1} \\\\ \n                      &= \\hat{\\mathrm{A}}_{t-1}^{-1} - \\frac{\\hat{\\mathrm{A}}_{t-1}^{-1} x_t( x_t - \\gamma x_{t+1})^\\top \\hat{\\mathrm{A}}_{t-1}^{-1}}{1 + x_t ( x_t - \\gamma x_{t+1})^\\top \\hat{\\mathrm{A}}_{t-1}^{-1} x_t}\n\\end{align}\nTo store $\\hat{A}_{t-1}$ LSTD also needs $O(d^2)$ memory. LSTD has no step-size parameter, which means that it never forgets -- this can be a blessing or a curse depending on the application. The choice between LSTD and semi-gradient TD will depend on the application, for instance the computation available and the importance of learning quickly. Pseudocode for LSTD is given below.\\\\\n\n\\includegraphics[width=\\textwidth]{\\NotesImages/lstd.png}\\\\\n\n\n\\subsection{Memory-based Function Approximation}\nAs an alternative to the parametric approaches discussed above, we might instead store all the training examples and execute an algorithm on the whole dataset when required, such as LOESS or nearest neighbour averaging. This approach is sometimes called \\emph{lazy learning}. The methods that go with this are non-parametric function approximation schemes. One can often evaluate the function approximation locally in the neighbourhood of the current state, which helps with the curse of dimensionality.\n\n\\subsection{Kernel-based Function Approximation}\nUsing kernels to define similarities between states for generalisation, e.g. kernel regression for state values.\n\n\\subsection{Looking Deeper at On-policy Learning: Interest and Emphasis}\nSometimes we are not equally interested in each state, so limited resources can be better spent than to treat every state equally. For instance, in discounted episodic problems we might be more interested in starting states because later rewards are discounted. \\\\\n\nIntroduce the scalar random variable $I_t \\geq 0 $ called $interest$, the degree of interest we have in accurately valuing the state at time $t$. If we don't care at all about the state then $I_t = 0$, if we fully care then it might be 1 (but it is formally allowed to take any non-negative value). The interest can be set in any causal way. The distribution in our loss function $\\VE$ is then defined as the distribution of states encountered when following the target policy, weighted by the interest.\\\\\n\nWe also introduce the scalar random variable $M_t \\geq 0$, called the \\emph{emphasis}. The emphasis multiplies the learning update at each time-step. For general $n$-step learning\n\\begin{equation}\n    \\vec{w}_{t+n} = \\vec{w}_{t + n - 1} + \\alpha M_t [G_{t:t+n} - \\hat{v}(S_t, \\vec{w}_{t+n-1})] \\grad_{\\vec{w}} \\hat{v}(S_t, \\vec{w}_{t+n-1}) \\quad 0 \\leq t < T,\n\\end{equation}\nwith the emphasis defined recursively as\n\\begin{equation}\n    M_t = I_t + \\gamma^n M_{t-n}\n\\end{equation}\nwith $M_t = 0$ $\\forall t < 0$.\n\n\n\n", "meta": {"hexsha": "3bc7aab9e6326d68b172d83addfb631eae757056", "size": 15784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/chapter9/chapter9_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/chapter9/chapter9_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/chapter9/chapter9_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": 89.1751412429, "max_line_length": 524, "alphanum_fraction": 0.736758743, "num_tokens": 4238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6190965186186042}}
{"text": "%!TEX root = inversion.tex\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Copyright (c) 2003-2018 by The University of Queensland\r\n% http://www.uq.edu.au\r\n%\r\n% Primary Business: Queensland, Australia\r\n% Licensed under the Apache License, version 2.0\r\n% http://www.apache.org/licenses/LICENSE-2.0\r\n%\r\n% Development until 2012 by Earth Systems Science Computational Center (ESSCC)\r\n% Development 2012-2013 by School of Earth Sciences\r\n% Development from 2014 by Centre for Geoscience Computing (GeoComp)\r\n%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\section{DC resistivity inversion: 3D}\\label{sec:forward DCRES}\r\nThis section will discuss DC resistivity\\index{DC forward} forward modelling, as well as an \\escript\r\nclass which allows for solutions of these forward problems. The DC resistivity \r\nforward problem is modelled via the application of Ohm's Law to the flow of current\r\nthrough the ground. When sources are treated as a point sources and Ohm's Law \r\nis written in terms of the potential field, the equation becomes:\r\n\\begin{equation} \\label{ref:dcres:eq1}\r\n\\nabla \\cdot (\\sigma \\nabla \\phi) = -I \\delta(x-x_s) \\delta(y-y_s) \\delta(z-z_s)\r\n\\end{equation}\r\nWhere $(x,y,z)$ and $(x_s, y_s, z_s)$ are the coordinates of the observation and source\r\npoints respectively. The total potential, $\\phi$, is split into primary and secondary \r\npotentials $\\phi = \\phi_p + \\phi_s$, where the primary potential is analytically calculated \r\nas a flat half-space background model with conductivity of $\\sigma_p$. \r\nThe secondary potential is due to conductivity deviations \r\nfrom the background model and has its conductivity denoted as $\\sigma_s$. \r\nThis approach effectively removes the singularities of the Dirac delta \r\nsource and provides more accurate results \\cite{rucker2006three}.\r\nAn analytical solution is available for the primary potential of a uniform half-space due to a single pole source and is given by:\r\n\\begin{equation} \\label{ref:dcres:eq2}\r\n\\phi_p = \\frac{I}{2 \\pi \\sigma_1 R}\r\n\\end{equation}\r\nWhere $I$ is the current and $R$ is the distance from the observation points to the source.\r\nIn \\escript the observation points are the nodes of the domain and $R$ is given by\r\n\\begin{equation} \\label{ref:dcres:eq3}\r\nR = \\sqrt{(x-x_s)^2+(y-y_s)^2 + z^2}\r\n\\end{equation}\r\nThe secondary potential, $\\phi_s$, is given by\r\n\\begin{equation}\\label{ref:dcres:eq4}\r\n-\\mathbf{\\nabla}\\cdot\\left(\\sigma\\,\\nabla \\phi_s \\right)  = \r\n \\mathbf{\\nabla}\\cdot\\left( \\left(\\sigma_p-\\sigma\\right)\\,\\nabla \\phi_p  \\right)\r\n\\end{equation} \r\nwhere $\\sigma_p$ is the conductivity of the background half-space.\r\nThe weak form of above PDE is given by multiplication of a suitable test function, $w$, and integrating over the domain $\\Omega$:\r\n\\begin{multline}\\label{ref:dcres:eq5}\r\n-\\int_{\\partial\\Omega} \\sigma\\,\\nabla \\phi_s  \\cdot \\hat{n} w\\,ds +\r\n \\int_{\\Omega} \\sigma\\,\\nabla \\phi_s  \\cdot \\nabla w\\,d\\Omega =\\\\\r\n-\\int_{\\partial\\Omega} \\left(\\sigma_p-\\sigma\\right)\\,\\nabla \\phi_p  \r\n\\cdot \\hat{n} w\\,ds + \\int_{\\Omega} \\left(\\sigma_p-\\sigma\\right)\\,\\nabla \\phi_p  \\cdot \\nabla w\\,d\\Omega \r\n\\end{multline}\r\nThe integrals over the domain boundary provide the boundary conditions which are\r\nimplemented as Dirichlet conditions (i.e. zero potential) at all interfaces except the\r\ntop, where Neumann conditions apply (i.e. no current flux through the air-earth interface).\r\nFrom the integrals over the domain, the \\escript coefficients can be deduced: the \r\nleft-hand-side conforms to \\escript coefficient $A$, whereas the right-hand-side agrees\r\nwith the coefficient $X$ (see User Guide).\r\n\r\nA number a of different configurations for electrode set-up are available \\cite[pg 5]{LOKE2014}.\r\nAn \\escript class is provided for each of the following survey types:\r\n\\begin{itemize}\r\n\\item Wenner alpha\r\n\\item Pole-Pole\r\n\\item Dipole-Dipole\r\n\\item Pole-Dipole\r\n\\item Schlumberger\r\n\\end{itemize}\r\n\r\nThese configurations are comprised of at least one pair of current and potential\r\nelectrodes separated by a distance $a$. In those configurations which use $n$,\r\nelectrodes in the currently active set may be separated by $na$. In the classes\r\nthat follow, the specified value of $n$ is an upper limit. That is $n$ will\r\nstart at 1 and iterate up to the value specified.\r\n\r\n\\subsection{Usage}\r\nThe DC resistivity forward modelling classes are specified as follows:\r\n\r\n\\begin{classdesc}{WennerSurvey}{self, domain, primaryConductivity, secondaryConductivity,\r\ncurrent, a, midPoint, directionVector, numElectrodes}\r\n\\end{classdesc}\r\n\r\n\\begin{classdesc}{polepoleSurvey}{domain, primaryConductivity, secondaryConductivity, \r\ncurrent, a, midPoint, directionVector, numElectrodes}\r\n\\end{classdesc}\r\n\r\n\\begin{classdesc}{DipoleDipoleSurvey}{self, domain, primaryConductivity, secondaryConductivity,\r\ncurrent, a, n, midPoint, directionVector, numElectrodes}\r\n\\end{classdesc}\r\n\r\n\\begin{classdesc}{PoleDipoleSurvey}{self, domain, primaryConductivity, secondaryConductivity,\r\ncurrent, a, n, midPoint, directionVector, numElectrodes}\r\n\\end{classdesc}\r\n\r\n\\begin{classdesc}{SchlumbergerSurvey}{self, domain, primaryConductivity, secondaryConductivity,\r\ncurrent, a, n, midPoint, directionVector, numElectrodes}\r\n\\end{classdesc}\r\n\r\n\\noindent Where:\r\n\\begin{itemize}\r\n\\item \\texttt{domain} is the domain which represent the half-space of interest. \r\nit is important that a node exists at the points where the electrodes will be placed.\r\n\\item \\texttt{primaryConductivity} is a data object which defines the primary conductivity\r\nit should be defined on the ContinuousFunction function space.\r\n\\item \\texttt{secondaryConductivity} is a data object which defines the secondary conductivity\r\nit should be defined on the ContinuousFunction function space.\r\n\\item \\texttt{current} is the value of the injection current to be used in amps this is a currently a\r\nconstant.\r\n\\item \\texttt{a} is the electrode separation distance.\r\n\\item \\texttt{n} is the electrode separation distance multiplier.\r\n\\item \\texttt{midpoint} is the centre of the survey. Electrodes will spread from this point\r\nin the direction defined by the direction vector and in the opposite direction, placing\r\nhalf of the electrodes on either side.\r\n\\item \\texttt{directionVector} defines as the direction in which electrodes are spread.\r\n\\item \\texttt{numElectrodes} is the number of electrodes to be used in the survey.\r\n\\end{itemize} \r\n\r\nWhen calculating the potentials the survey is moved along the set of electrodes.\r\nThe process of moving the electrodes along is repeated for each consecutive value of $n$.\r\nAs $n$ increases less potentials are calculated, this is because a greater spacing is\r\nrequired and hence some electrodes are skipped. The process of building up these\r\npseudo-sections is covered in greater depth by Loke (2014)\\cite[pg 19]{LOKE2014}.\r\nThese classes all share common member functions described below. For the surveys\r\nwhere $n$ is not specified only one list will be returned. \r\n\r\n\\begin{methoddesc}[]{getPotential}{}\r\nReturns 3 lists, each made up of a number of lists containing primary, secondary and total\r\npotential differences. Each of the lists contains $n$ sublists.\r\n\\end{methoddesc}\r\n\r\n\\begin{methoddesc}[]{getElectrodes}{}\r\nReturns a list containing the positions of the electrodes\r\n\\end{methoddesc}\r\n\r\n\\begin{methoddesc}[]{getApparentResistivityPrimary}{}\r\nReturns a series of lists containing primary apparent resistivities one for each \r\nvalue of $n$.\r\n\\end{methoddesc}\r\n\r\n\\begin{methoddesc}[]{getApparentResistivitySecondary}{}\r\nReturns a series of lists containing secondary apparent resistivities one for each \r\nvalue of $n$.\r\n\\end{methoddesc}\r\n\r\n\\begin{methoddesc}[]{getApparentResistivityTotal}{}\r\nReturns a series of lists containing total apparent resistivities, one for each \r\nvalue of $n$. This is generally the result of interest.\r\n\\end{methoddesc}\r\n\r\nThe apparent resistivities are calculated by applying a geometric factor to the\r\nmeasured potentials.\r\n\r\n", "meta": {"hexsha": "695e143aa81bd5052d930e14ec74dd5e36b62db3", "size": 8009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/inversion/ForwardDCRES.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/inversion/ForwardDCRES.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/inversion/ForwardDCRES.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": 51.6709677419, "max_line_length": 131, "alphanum_fraction": 0.7509052316, "num_tokens": 2023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6190965082344478}}
{"text": "%------------------------------------------------------------------------------\n\\section{Covariance matrix propagation}\n\\label{sec:propagation-covariance}\n%------------------------------------------------------------------------------\n\n\\subsection{State space representation}\n\\label{sec:state-space-notation}\n%------------------------------------------------------------------------------\n\nThe orbit determination problem is typically approached by using a state space representation. For a very detailed description of the associated concepts, referencing the textbook\nof \\citet{tapley2004} is highly recommended, which also served as the basis for the following derivation. \n\nThe \\gls{sym:stateDim}-dimensional state vector $\\xt$ of a satellite can be defined as\n\\begin{equation}\n \\xt = \\left(\\rt^T, \\vt^T, \\gls{sym:cvec}^T \\right)^T,\n\\end{equation}\nwith \\gls{sym:cvec} being a multi-dimensional vector of constant parameters to be solved for in the orbit determination process, which might, for example,\ninclude the drag and \\acrshort{acr:srp} coefficients. Due to the non-linear nature of orbital motion, the conversion of the second-order differential equations of motion into a vector of first-order differential equations is written as\n\\begin{equation}\n \\frac{d}{dt} \\xt = \\gls{sym:functionvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right). \\label{eq:non-linear-system}\n\\end{equation}\nAs the state, in general, cannot be observed directly, an additional equation, the \\textit{measurement model} \\citep{maybeck1979}, is required to map the state vector to the observations:\n\\begin{equation}\n \\yt = \\gls{sym:functiongvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right) + \\boldsymbol{\\gls{sym:obsError}}, \\label{eq:non-linear-obs}\n\\end{equation}\nhere, \\gls{sym:obsError} is the error in the observation. With {\\yt} being \\gls{sym:obsDim}-dimensional, and, in general, $\\gls{sym:obsDim}<\\gls{sym:stateDim}$, for the orbit determination the number of \nobservations \\gls{sym:numObs} guarantees that $\\gls{sym:numObs}\\times\\gls{sym:obsDim} >> \\gls{sym:stateDim}$.\n\nA linearization is obtained by introducing a reference trajectory, denoted by an index \\gls{idx:ref}, and work with the deviations\n\\begin{align}\n \\Delta\\xt &= \\xt - \\xref, \\label{eq:deviation-ref} \\\\\n \\Delta\\yt &= \\yt - \\yref, \\label{eq:deviation-ref-y}\n\\end{align}\nwhich are assumed to be small - a concept familiar to Encke's method for perturbed orbits. Expanding \\eq{eq:non-linear-system} and \\eq{eq:non-linear-obs} about the reference state gives\n\\begin{align}\n \\xdot &= \\gls{sym:functionvec}\\left(\\gls{sym:state}_{\\gls{idx:ref}},\\gls{sym:t}\\right) + \\left(\\frac{\\partial \\gls{sym:functionvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right)}{\\partial\n\\xt}\\right)_{\\gls{idx:ref}} \\cdot \\left(\\xt - \\xref\\right) + \\mathcal{O}\\left(\\Delta\\xt^2\\right), \\\\\n\\yt &= \\gls{sym:functiongvec}\\left(\\gls{sym:state}_{\\gls{idx:ref}},\\gls{sym:t}\\right) + \\left(\\frac{\\partial \\gls{sym:functiongvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right)}{\\partial\n\\xt}\\right)_{\\gls{idx:ref}} \\cdot \\left(\\xt - \\xref\\right) + \\mathcal{O}\\left(\\Delta\\xt^2\\right) + \\boldsymbol{\\gls{sym:obsError}},\n\\end{align}\nor, combined with \\eq{eq:deviation-ref} and \\eq{eq:deviation-ref-y} and neglecting higher-order terms:\n\\begin{align}\n \\Delta \\xdot &= \\left(\\frac{\\partial \\xdot}{\\partial \\xt}\\right)_{\\gls{idx:ref}} \\Delta \\xt, \\\\\n \\Delta \\yt &= \\left(\\frac{\\partial \\gls{sym:functiongvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right)}{\\partial \\xt}\\right)_{\\gls{idx:ref}} \\Delta \\xt + \\gls{sym:obsError}.\n\\end{align}\nDefining the system matrix $\\gls{sym:systemMat}\\left(\\gls{sym:t}\\right)$ as\n\\begin{equation}\n \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\equiv \\left(\\frac{\\partial \\xdot}{\\partial \\xt}\\right)_{\\gls{idx:ref}}\n\\end{equation}\nand the output matrix as\n\\begin{equation}\n \\gls{sym:outputMat}\\left(\\gls{sym:t}\\right) \\equiv \\left(\\frac{\\partial \\gls{sym:functiongvec}\\left(\\gls{sym:state},\\gls{sym:t}\\right)}{\\partial \\xt}\\right)_{\\gls{idx:ref}}\n\\end{equation}\nthe homogeneous part of the state space representation is obtained for the linearized system:\n\\begin{align}\n \\Delta \\xdot &= \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\Delta \\xt, \\label{eq:diff-homo} \\\\\n \\Delta \\yt   &= \\gls{sym:outputMat}\\left(\\gls{sym:t}\\right) \\Delta \\xt + \\gls{sym:obsError}. \\label{eq:meas-model-linearized}\n\\end{align}\nThe general solution for \\eq{eq:diff-homo} is:\n\\begin{align}\n \\Delta \\xt &= \\frac{\\partial \\Delta \\xt}{\\partial \\Delta\\gls{sym:state}_0} \\Delta \\gls{sym:state}_0 \\\\\n            &= \\frac{\\partial \\left(\\xt - \\xref\\right)}{\\partial \\left(\\gls{sym:state}_0 - \\gls{sym:state}_{\\gls{idx:ref},0}\\right)} \\Delta \\gls{sym:state}_0 \n\\label{eq:ref-constant}\\\\\n            &= \\frac{\\partial \\xt}{\\partial \\gls{sym:state}_0} \\Delta \\gls{sym:state}_0 \\label{eq:set-homo}\n\\end{align}\ngiven the initial condition $\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)=\\gls{sym:state}_0$ and noting that the reference state is constant in the partial derivative in\n\\eq{eq:ref-constant}. Now the state error transition matrix \\gls{sym:set} can be introduced, which translates the state error $\\Delta \\xt$ from $\\gls{sym:t}_0$ to $\\gls{sym:t}$:\n\\begin{equation}\n \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\equiv \\frac{\\partial \\xt}{\\partial \\gls{sym:state}_0}\n\\end{equation}\nDifferentiating \\eq{eq:set-homo} provides\n\\begin{equation}\n \\Delta \\xdot = \\dot{\\gls{sym:set}}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right) \\Delta \\gls{sym:state}_0,\n\\end{equation}\nwhich, together with \\eq{eq:set-homo}, can be substituted into \\eq{eq:diff-homo}:\n\\begin{equation}\n \\dot{\\gls{sym:set}}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right) \\Delta \\gls{sym:state}_0 = \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right)\n\\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\Delta \\gls{sym:state}_0,\n\\end{equation}\nfinally providing a differential equation for the state error transition matrix, which will later be integrated numerically for the propagation of the covariance matrix:\n\\begin{equation}\n \\dot{\\gls{sym:set}}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right) = \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\label{eq:set-ode}\n\\end{equation}\n\nThe main advantage of solving for the state error transition matrix using \\eq{eq:set-ode} over the direct solution of \\eq{eq:diff-homo} \nis that the state error transition matrix allows for a simple formulation of the covariance matrix propagation and the determination of \nthe best estimate of the state vector \\citep{tapley2004}.\n\nThe influence of system or process noise, which is characterized by the unmodeled accelerations, is provided by another term leading to the general formulation of the state\nspace representation:\n\\begin{equation}\n \\Delta \\xdot = \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\Delta \\xt + \\gls{sym:inputMat} \\left(\\gls{sym:t}\\right) \\gls{sym:inputVec}\\left(\\gls{sym:t}\\right),\n\\label{eq:state-space}\n\\end{equation}\nhere, $\\gls{sym:inputVec}\\left(\\gls{sym:t}\\right)$ is the process noise, while $\\gls{sym:inputMat}\\left(\\gls{sym:t}\\right)$ is the input matrix, which converts the unmodeled\naccelerations into the quantities of the state vector.\n\nA particular solution to \\eq{eq:state-space} can be found via the \\textit{variation of constants} method, starting with:\n\\begin{equation}\n \\Delta \\xt = \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\gls{sym:vop}\\left(\\gls{sym:t}\\right). \\label{eq:vop}\n\\end{equation}\nDifferentiating:\n\\begin{equation}\n \\Delta \\xdot = \\dot{\\gls{sym:set}}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right) \\gls{sym:vop}\\left(\\gls{sym:t}\\right) + \\set{\\gls{sym:t}}{\\gls{sym:t}_0}\n\\dot{\\gls{sym:vop}}\\left(\\gls{sym:t}\\right),\n\\end{equation}\nand substituting into \\eq{eq:state-space} provides\n\\begin{equation}\n \\dot{\\gls{sym:set}}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right) \\gls{sym:vop}\\left(\\gls{sym:t}\\right) + \\set{\\gls{sym:t}}{\\gls{sym:t}_0}\n\\dot{\\gls{sym:vop}}\\left(\\gls{sym:t}\\right) = \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\Delta \\xt + \\gls{sym:inputMat} \\left(\\gls{sym:t}\\right)\n\\gls{sym:inputVec}\\left(\\gls{sym:t}\\right).\n\\end{equation}\nThis equation can be re-written by substituting the already known relationships for the time derivative of the state error transition matrix, \\eq{eq:set-ode},\nand \\eq{eq:vop}: \n\\begin{equation}\n \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\gls{sym:vop}\\left(\\gls{sym:t}\\right) + \\set{\\gls{sym:t}}{\\gls{sym:t}_0}\n\\dot{\\gls{sym:vop}}\\left(\\gls{sym:t}\\right) = \\gls{sym:systemMat}\\left(\\gls{sym:t}\\right) \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\gls{sym:vop}\\left(\\gls{sym:t}\\right)  +\n\\gls{sym:inputMat} \\left(\\gls{sym:t}\\right) \\gls{sym:inputVec}\\left(\\gls{sym:t}\\right),\n\\end{equation}\nwhich results in\n\\begin{equation}\n \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\dot{\\gls{sym:vop}}\\left(\\gls{sym:t}\\right) = \\gls{sym:inputMat} \\left(\\gls{sym:t}\\right) \\gls{sym:inputVec}\\left(\\gls{sym:t}\\right).\n\\end{equation}\nThe solution is now obtained by integration:\n\\begin{equation}\n \\gls{sym:vop}\\left(\\gls{sym:t}\\right) = \\gls{sym:vop}_0 + \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\gls{sym:set}^{-1}\\left(\\gls{sym:xi},\\gls{sym:t}_0\\right)\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right)\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right) d\\gls{sym:xi}. \\label{eq:result-ct}\n\\end{equation}\n\nSubstituting the result for $\\gls{sym:vop}\\left(\\gls{sym:t}\\right)$ from \\eq{eq:result-ct} into \\eq{eq:vop} results in:\n\\begin{equation}\n \\Delta \\xt = \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\gls{sym:vop}_0 + \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\set{\\gls{sym:t}}{\\gls{sym:t}_0}\n\\gls{sym:set}^{-1}\\left(\\gls{sym:xi},\\gls{sym:t}_0\\right)\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right)\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right) d\\gls{sym:xi},\n\\end{equation}\nwhich can be simplified using the following properties of the state error transition matrix:\n\\begin{equation}\n \\set{\\gls{sym:t}}{\\gls{sym:t}_0}\\gls{sym:set}^{-1}\\left(\\gls{sym:xi},\\gls{sym:t}_0\\right) = \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\set{\\gls{sym:t}_0}{\\gls{sym:xi}}\n = \\set{\\gls{sym:t}}{\\gls{sym:xi}},\n\\end{equation}\nas well as the initial condition $\\gls{sym:vop}_0 = \\gls{sym:state}_0$ to finally provide the general solution for the inhomogeneous \\eq{eq:state-space}:\n\\begin{equation}\n \\Delta \\xt = \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\Delta \\gls{sym:state}_0 + \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\set{\\gls{sym:t}}{\\gls{sym:xi}}\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right)\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right) d\\gls{sym:xi}. \\label{eq:state-space-general-solution}\n\\end{equation}\n\nThe result in \\eq{eq:state-space-general-solution} is also referred to as the \\textit{matrix superposition integral} \\citep{gelb1974}, where the second term describes how an input \n(here: process noise \\gls{sym:inputVec}) at a time \\gls{sym:xi} translates into a state vector change at time \\gls{sym:t}.\n\n%------------------------------------------------------------------------------\n\\subsection{General formulation using the state transition matrix}\n\\label{sec:propagation-covariance-theory}\n%------------------------------------------------------------------------------\n\nUsing the state space representation, as introduced in \\sect{sec:state-space-notation}, with its general solution given by \\eq{eq:state-space-general-solution},\n the covariance matrix at a time \\gls{sym:t} follows as:\n\\begin{alignat}{3}\n \\gls{sym:P}\\left(\\gls{sym:t}\\right) = \\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}\\right)\\cdot\\Delta\\gls{sym:state}\\left(\\gls{sym:t}\n\\right)^T\\right]&=\n\\gls{sym:expVal}\\Bigl[&&\\left(\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\n\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)+\n\\int_{\\gls{sym:t}_0}^{\\gls{sym:t}}\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:xi}\\right)\\cdot\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right)\\cdot\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right) d\\gls{sym:xi}\\right)\\times \\notag \\\\\n& &&\\left(\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\n\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)+ \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}}\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right)\\cdot\n\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)\\cdot\\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right) d\\gls{sym:eta}\\right)^T\\Bigr] \\notag \\\\\n&= &&\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)\\cdot\n\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)^T\\right]\\cdot \\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)^T + \\label{eq:full-cov-prop} \\\\\n& &&\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\\int_{\\gls{sym:t}_0}^{\\gls{sym:t}}\\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)\n\\cdot\\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right)^T\\right]\\cdot\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)\\cdot\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right) d\\gls{sym:eta}+ \\notag \\\\\n& &&\n\\left(\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\\int_{\\gls{sym:t}_0}^{\\gls{sym:t}}\\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)\n\\cdot\\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right)^T\\right]\\cdot\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)\\cdot\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right) d\\gls{sym:eta}\\right)^T + \\notag \\\\\n& &&\n\\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:xi}\\right) \\cdot\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right) \\cdot\n\\gls{sym:expVal}\\left[\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right)\\cdot \\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right)^T\\right]\n\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)^T \\cdot\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right)^T d\\gls{sym:xi} d\\gls{sym:eta}. \\notag\n\\end{alignat}\nAnalysing the individual terms in the above sum, the first one is the time update of the covariance matrix from $\\gls{sym:t}_0$ to \\gls{sym:t}, with\n\\begin{equation}\n  \\gls{sym:P}\\left(\\gls{sym:t}_0\\right) = \\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)\\cdot\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)^T\\right ].\n\\end{equation}\n\nThe second and third term in \\eq{eq:full-cov-prop} are similar in that the one is obtained from the other by transposing. That contribution results \nfrom the cross-correlation of the state vector at $\\gls{sym:t}_0$ and the process noise and shall be defined as \\gls{sym:Qxu}:\n\\begin{equation}\n \\gls{sym:Qxu}\\left(\\gls{sym:t}\\right) =\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:t}_0\\right)\\cdot\\int_{\\gls{sym:t}_0}^{\\gls{sym:t}}\\gls{sym:expVal}\\left[\\Delta\\gls{sym:state}\\left(\\gls{sym:t}_0\\right)\n\\cdot\\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right)^T\\right]\\cdot\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)\\cdot\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right) d\\gls{sym:eta}\n\\end{equation}\n\nThe last term in \\eq{eq:full-cov-prop} shall be denoted as $\\gls{sym:Quu}\\left(\\gls{sym:t}\\right)$, being the second moment of process noise matrix:\n\\begin{equation}\n \\gls{sym:Quu}\\left(\\gls{sym:t}\\right) = \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\int_{\\gls{sym:t}_0}^{\\gls{sym:t}} \\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:xi}\\right) \\cdot\n\\gls{sym:inputMat}\\left(\\gls{sym:xi}\\right) \\cdot\n\\gls{sym:expVal}\\left[\\gls{sym:inputVec}\\left(\\gls{sym:xi}\\right)\\cdot \\gls{sym:inputVec}\\left(\\gls{sym:eta}\\right)^T\\right]\n\\gls{sym:inputMat}\\left(\\gls{sym:eta}\\right)^T \\cdot\n\\gls{sym:set}\\left(\\gls{sym:t},\\gls{sym:eta}\\right)^T d\\gls{sym:xi} d\\gls{sym:eta}.\n\\end{equation}\n\nIt is now possible to write \\eq{eq:full-cov-prop} in a more condensed way:\n\\begin{equation}\n \\gls{sym:P}\\left(\\gls{sym:t}\\right) = \\set{\\gls{sym:t}}{\\gls{sym:t}_0} \\gls{sym:P}_0 \\set{\\gls{sym:t}}{\\gls{sym:t}_0}^T + \\gls{sym:Qxu}\\left(\\gls{sym:t}\\right) +\n\\gls{sym:Qxu}\\left(\\gls{sym:t}\\right)^T + \\gls{sym:Quu}\\left(\\gls{sym:t}\\right).\n\\end{equation}\n\n%------------------------------------------------------------------------------\n\\subsection{SET matrix integration}\n\\label{sec:propagation-covariance-set-integration}\n%------------------------------------------------------------------------------\nThe state vector \\gls{sym:state} is defined as\n\\begin{equation}\n \\gls{sym:state} = \\left(\\gls{sym:radvec}, \\gls{sym:velvec}\\right)^T \n                 = \\left(\\rx, \\ry, \\rz, \\gls{sym:v}_{\\gls{idx:x}}, \\gls{sym:v}_{\\gls{idx:y}}, \n\\gls{sym:v}_{\\gls{idx:z}}\\right)^T\n\\end{equation}\n\nThe partial derivative matrix \\gls{sym:matrixF}, without any solve-for parameters, is defined as\n\\begin{equation}\n \\gls{sym:matrixF}\\left(\\gls{sym:tg}\\right) = \\frac{\\partial \\dot{\\gls{sym:state}}}{\\partial \\gls{sym:state}} = \n \\begin{pmatrix}\n    % first row\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\rx} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\ry} &     \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\rz} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}} \\\\\n    % second row\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\rz} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}} \\\\\n    % third row\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\rz} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} &\n    \\frac{\\partial \\gls{sym:v}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}} \\\\\n    % fourth row   \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\rz} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}} \\\\\n    % fifth row\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\rz} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}} \\\\\n    % sixth row\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\rz} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:x}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:y}}} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\gls{sym:v}_{\\gls{idx:z}}}    \n  \\end{pmatrix} \\label{eq:partial-derivative-matrix}\n\\end{equation}\n\n%------------------------------------------------------------------------------\n\\subsubsection{Partial derivatives for the geopotential}\n\\label{sec:propagation-covariance-set-integration-geopotential}\n%------------------------------------------------------------------------------\n\nThe partial derivatives of the acceleration contribution due to the non-spherical Earth in the body fixed frame, are\ndetermined according to \\cite{long1989}. \nAs they are only a function of the radius vector, the partial derivate matrix contribution of the geopotential results in (see \n\\eq{eq:partial-derivative-matrix}):\n\\begin{equation}\n \\gls{sym:matrixF}_{\\gls{idx:geop}}\\left(\\gls{sym:tg}\\right) =  \n \\begin{pmatrix}\n    % first row\n    0 & 0 & 0 & 1 & 0 & 0 \\\\\n    % second row\n    0 & 0 & 0 & 0 & 1 & 0 \\\\\n    % third row\n    0 & 0 & 0 & 0 & 0 & 1 \\\\\n    % fourth row   \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:x}}}{\\partial \\rz} &\n    0 & 0 & 0 \\\\\n    % fifth row\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:y}}}{\\partial \\rz} &\n    0 & 0 & 0 \\\\\n    % sixth row\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\rx} &\n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\ry} & \n    \\frac{\\partial \\gls{sym:a}_{\\gls{idx:z}}}{\\partial \\rz} &\n    0 & 0 & 0    \n  \\end{pmatrix} \\label{eq:partial-derivative-matrix-geopotential}\n\\end{equation}\nThe individual derivatives are based on a differentiation of the acceleration vector components derived for the geopotential \nin \\eq{eq:geopotential-acceleration-1} through \\eq{eq:geopotential-acceleration-2} and are computed as follows:\n\\begin{equation}\n  \\begin{aligned}\n \\frac{\\partial \\gls{sym:avec}_{\\gls{idx:geop},\\gls{idx:bodyfixed}}}{\\partial \\rbf} &= \n  \\frac{\\partial}{\\partial\\rbf} \\left(\\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:r}}\\right) \n  \\frac{\\partial\\gls{sym:radvec}}{\\partial\\rbf} +\n  \\frac{\\partial}{\\partial\\rbf} \\left(\\frac{\\partial\\gls{sym:potential}}{\\partial\\phigc}\\right) \n  \\frac{\\partial\\phigc}{\\partial\\rbf} +\n  \\frac{\\partial}{\\partial\\rbf} \\left(\\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:long}}\\right) \n  \\frac{\\partial\\gls{sym:long}}{\\partial\\rbf}  \\\\\n  &+ \\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:r}} \\frac{\\partial^2\\gls{sym:r}}{\\partial\\rbf} +\n      \\frac{\\partial\\gls{sym:potential}}{\\partial\\phigc} \\frac{\\partial^2\\gls{sym:lat}}{\\partial\\rbf} +\n      \\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:long}} \\frac{\\partial^2\\gls{sym:long}}{\\partial\\rbf} \n\\label{eq:geop-acc-derivative}\n\\end{aligned}\n\\end{equation}\n\nThe partial derivatives of the first three terms in \\eq{eq:geop-acc-derivative}, $\\partial\\gls{sym:potential}/\\partial\\gls{sym:r}$, \n$\\partial\\gls{sym:potential}/\\partial\\phigc$, $\\partial\\gls{sym:potential}/\\partial\\gls{sym:long}$, with respect to the\nbody-fixed radius vector, $\\gls{sym:r}_{\\gls{idx:bodyfixed}}$, are obtained by differentiating\n\\eq{eq:geopotential-acceleration-1} through \\eq{eq:geopotential-acceleration-2} \nusing the following notation \\citep{long1989}:\n\\begin{equation}\n \\frac{\\partial}{\\partial\\rbf}\n \\begin{bmatrix}\n  \\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:r}} \\\\[0.5em]\n  \\frac{\\partial\\gls{sym:potential}}{\\partial\\phigc} \\\\[0.5em]\n  \\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:long}}\n \\end{bmatrix} \n = \n \\begin{pmatrix}\n  %first row\n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}^2} & \n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\phigc} & \n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\gls{sym:long}} \\\\\n  % second row\n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\phigc\\partial\\gls{sym:r}} & \n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:lat}^2_{\\gls{idx:gc}}} & \n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\phigc\\partial\\gls{sym:long}} \\\\\n  % third row\n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}\\partial\\gls{sym:r}} &\n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}\\partial\\gls{sym:r}} &\n  \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}\\partial\\phigc}\n \\end{pmatrix}\n \\begin{bmatrix}\n  \\frac{\\partial\\gls{sym:radvec}}{\\partial\\gls{sym:r}_{\\gls{idx:bodyfixed}}} \\\\[0.5em]\n  \\frac{\\partial\\phigc}{\\partial\\rbf} \\\\[0.5em]\n  \\frac{\\partial\\gls{sym:long}}{\\partial\\rbf}\n \\end{bmatrix} \\label{eq:second-derivative-potential} \n\\end{equation}\nFor example, the first element in \\eq{eq:second-derivative-potential} would be read as:\n\\begin{equation}\n \\frac{\\partial}{\\partial\\rbf} \\left(\\frac{\\partial\\gls{sym:potential}}{\\partial\\gls{sym:r}}\\right) =\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}^2} \\frac{\\partial\\gls{sym:r}}{\\partial\\rbf} +\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\phigc} \n\\frac{\\partial\\phigc}{\\partial\\rbf} +\n\\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\gls{sym:long}} \\frac{\\partial\\gls{sym:long}}{\\partial\\rbf}\n\\end{equation}\nThe matrix in \\eq{eq:second-derivative-potential} is symmetric, so that only six different second derivatives have to be computed, based on the first \nderivatives in \\eq{eq:deriv-geopotential}, as well as the derivatives of the associated Legendre functions (\\eq{eq:deriv-legendre-phi} and \n\\eq{eq:deriv-legendre-phi-2}) with respect to the  independent variable (being the sine of the geocentric latitude):\n\\begin{align}\n%\n% d^2U/dr^2\n%\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}^2} = &\\frac{\\gls{sym:grav}}{\\gls{sym:r}^3} \n             \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \n\\left(\\gls{sym:geo_n}+2\\right)\\left(\\gls{sym:geo_n}+1\\right) \\times \\notag \\\\\n      &\\qquad \\qquad \\times \\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \\left(\\cnm{}{} \\cos \n\\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) + \\snm{}{} \\sin \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \n\\legphi{}{} \\displaybreak[0] \\\\[1em]\n%\n% d^2U/drdphi\n%\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\phigc} = &\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\phigc\\partial\\gls{sym:r}} = -\\frac{\\gls{sym:grav}}{\\gls{sym:r}^2} \n             \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \n\\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \\left(\\gls{sym:geo_n}+1\\right) \n\\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \\left(\\cnm{}{} \\cos \n\\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) + \\snm{}{} \\sin \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \\times \\notag \n\\\\\n & \\qquad \\qquad \\times \\left(\\legphi{}{+1} - \\gls{sym:geo_m} \\tan \\phigc \\legphi{}{} \\right) \\displaybreak[0] \\\\[1em]\n%\n% d^2U/drdlambda\n%\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:r}\\partial\\gls{sym:long}} = & \n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}\\partial\\gls{sym:r}} = -\\frac{\\gls{sym:grav}}{\\gls{sym:r}^2} \n             \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \n\\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \\left(\\gls{sym:geo_n}+1\\right) \n\\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \\gls{sym:geo_m} \\left(\\snm{}{} \\cos \n\\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) - \\cnm{}{} \\sin \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \\times \\notag \n\\\\\n & \\qquad \\qquad \\times \\legphi{}{} \\displaybreak[0] \\\\[1em]\n%\n% d^2U/dphi^2\n%\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\phigc^2} = &\\frac{\\gls{sym:grav}}{\\gls{sym:r}} \n \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \n \\left(\\cnm{}{} \\cos \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) + \\snm{}{} \\sin \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \n\\left(\\tan\\phigc\\legphi{}{+1} \\right. + \\notag \\\\  & \\qquad \\qquad + \\left. \\left(\\gls{sym:geo_m}^2\\sec^2\\phigc - \\gls{sym:geo_m}\\tan^2\\phigc - \n\\gls{sym:geo_n}\\left(\\gls{sym:geo_n}+1\\right)\\right)\\legphi{}{}\\right) \\displaybreak[0]  \\label{eq:d2Udphi2}\\\\[1em]\n%\n% d^2U/dphidlambda\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\phigc\\partial\\gls{sym:long}} = & \n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}\\partial\\phigc} = \\frac{\\gls{sym:grav}}{\\gls{sym:r}} \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \n\\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \\gls{sym:geo_m} \\left(\\snm{}{} \\cos \n\\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) - \\cnm{}{} \\sin \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \\times \\notag \\\\\n & \\qquad \\qquad \\times \\left(\\legphi{}{+1} - \\gls{sym:geo_m} \\tan \\phigc \\legphi{}{} \\right) \\displaybreak[0] \\\\[1em]\n%\n% d^2U/dlambda^2\n%\n \\frac{\\partial^2\\gls{sym:potential}}{\\partial\\gls{sym:long}^2} = &\n -\\frac{\\gls{sym:grav}}{\\gls{sym:r}^2} \\sum\\limits_{\\gls{sym:geo_n}=2}^{\\infty} \\left(\\frac{\\re}{\\gls{sym:r}}\\right)^{\\gls{sym:geo_n}} \n\\sum\\limits_{\\gls{sym:geo_m}=0}^{\\gls{sym:geo_n}} \\gls{sym:geo_m}^2 \\left(\\cnm{}{} \\cos \\left(\\gls{sym:geo_m}\\gls{sym:long}\\right) + \\snm{}{} \\sin \n\\left(\\gls{sym:geo_m}\\gls{sym:long}\\right)\\right) \\legphi{}{}  \n\\end{align}\nNote that there is no discontinuity for $\\phigc=90^\\circ$ in \\eq{eq:d2Udphi2}, as for $\\gls{sym:geo_m}=0$ the tangent is reduced by a cosine function provided \nby the \\legphi{}{+1} function and for $\\gls{sym:geo_m}=1$ one obtains for the combination of secant and tangent:\n\\begin{equation}\n \\sec^2\\phigc - \\tan^2\\phigc = 1\n\\end{equation}\nFinally, for all $\\gls{sym:geo_m}>1$, there is always a $\\cos^2\\phigc$ term, which reduces the secant (to unity) and the squared tangent (to $\\sin^2\\phigc$).\n\nThe second part of \\eq{eq:geop-acc-derivative} contains second derivatives of \\gls{sym:r}, \\phigc and \\gls{sym:long} with respect to the radius in the \nbody-fixed frame. These derivatives are obtained by differentiating \\eqsto{eq:deriv-spherical-1}{eq:deriv-spherical-3} \\citep{long1989}:\n\\begin{align}\n \\frac{\\partial^2\\gls{sym:r}}{\\partial\\rbf^2}    =& \\frac{1}{\\gls{sym:r}}\\left(\\gls{sym:identity}-\\frac{\\rbf\\rbf^T}{\\gls{sym:r}^2}\\right) \\\\[1em]\n \\frac{\\partial^2\\phigc}{\\partial\\rbf^2}         =& \n-\\frac{1}{\\left(\\rx^2+\\ry^2\\right)^{3/2}}\\left(\\left(\\frac{\\partial\\rz}{\\partial\\rbf}\\right)^T-\\frac{\\rz\\rbf}{\\gls{sym:r}^2}\n\\right)\\left(\\rx\\left(\\frac{\\partial\\rx}{\\partial\\rbf}\\right)+\\ry\\left(\\frac{\\partial\\ry}{\\partial\\rbf}\\right)\\right) - \\notag \\\\[1em]\n & \n-\\frac{1}{\\gls{sym:r}^2\\sqrt{\\rx^2+\\ry^2}}\\left(\\rbf\\left(\\frac{\\partial\\rz}{\\partial\\rbf}\\right)+\\rz\\gls{sym:identity}-\\frac{2\\rz}{\\gls{sym:r}^2}\n\\rbf\\rbf^T\\right) \\\\[1em]\n \\frac{\\partial^2\\gls{sym:long}}{\\partial\\rbf^2} =& \\frac{1}{\\left(\\rx^2+\\ry^2\\right)^2}\n \\begin{bmatrix}\n -\\ry \\\\\n \\rx  \\\\\n  0\n \\end{bmatrix}\n \\left(\\rx\\left(\\frac{\\partial\\rx}{\\partial\\rbf}\\right)+\\ry\\left(\\frac{\\partial\\ry}{\\partial\\rbf}\\right)\\right) +\n \\frac{1}{\\rx^2+\\ry^2}\n \\begin{bmatrix}\n  0 & -1 & 0 \\\\\n  1 & 0  & 0 \\\\\n  0 & 0  & 0 \n \\end{bmatrix}\n\\end{align}\nWhile the above equations appear to be quite complex, they can be significantly simplified, considering the fact that the partial derivatives of the radius \ncomponents are unit vectors:\n\\begin{align}\n \\frac{\\partial\\rx}{\\partial\\rbf} = \\left[1,0,0\\right] \\notag \\\\\n \\frac{\\partial\\ry}{\\partial\\rbf} = \\left[0,1,0\\right] \\notag \\\\\n \\frac{\\partial\\rz}{\\partial\\rbf} = \\left[0,0,1\\right] \\notag \n\\end{align}\n\nNow all quantities are available to compute the inertial acceleration $\\gls{sym:avec}_{\\gls{idx:bodyfixed}}$ in the body-fixed (\\acrshort{acr:itrf}) frame. \nIn order to obtain the derivative of the acceleration in the \\acrshort{acr:gcrf} with respect to the radius vector in the \\acrshort{acr:gcrf},  \nthe relationship from \\eq{eq:ns-trafo} is used:\n\\begin{equation}\n \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:ns}}}{\\partial\\gls{sym:radvec}} = \n\\kot{itrf}{gcrf}\\frac{\\partial\\gls{sym:avec}_{\\gls{idx:bodyfixed}}}{\\partial\\rbf}\\frac{\\partial\\rbf}{\\partial\\gls{sym:radvec}}= \n\\kot{itrf}{gcrf}\\frac{\\partial\\gls{sym:avec}_{\\gls{idx:bodyfixed}}}{\\partial\\rbf}\\left(\\kot{itrf}{gcrf}\\right)^T\n\\end{equation}\n\n%------------------------------------------------------------------------------\n\\subsubsection{Partial derivatives for atmospheric drag contributions}\n\\label{sec:propagation-covariance-set-integration-drag}\n%------------------------------------------------------------------------------\n\nThe computation of partial derivatives due to atmospheric drag is based on \\eq{eq:drag-acceleration}, the latter being a function of the relative velocity, \nwhich deviates from the inertial velocity due to the rotating atmosphere and horizontal wind. A similar procedure to the one shown in the following was \npresented in \\cite{long1989}. Provided that the relative velocity is already available in the \\gls{acr:gcrf}, the derivatives of the acceleration vector with \nrespect to the inertial velocity vector can be determined as follows:\n\\begin{equation}\n \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\gls{sym:velvec}} = \n   \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\relvel}\\frac{\\partial\\relvel}{\\partial\\gls{sym:velvec}} =\n   \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\relvel} = \n-\\frac{\\density}{2}\\frac{\\cd\\crossSection}{\\gls{sym:mass}}\\left(\\gls{sym:identity}\\left|\\relvel\\right|+\\frac{\\relvel\\relvel^T}{\\left|\\relvel\\right|}\\right).\n\\end{equation}\nThe partial derivative of the relative velocity with respect to the inertial velocity is one, which is due to the definition of the relative \nvelocity in the \\gls{acr:gcrf}:\n\\begin{equation}\n \\relvel = \\gls{sym:velvec} + f\\left(\\gls{sym:radvec},t\\right)\n \\label{eq:relvel-fr}\n\\end{equation}\nThe additional terms, designated with $f\\left(\\gls{sym:radvec},t\\right)$ are due to the already mentioned rotating atmosphere as well as horizontal wind and \nare only functions of the radius vector and time.\n\nNeglecting horizontal wind contributions, the relative velocity can be given as a function of the rotating atmosphere alone, being assumed to co-rotate with \nthe Earth, resulting in:\n\\begin{equation}\n \\relvel = \\gls{sym:velvec} - \\gls{sym:rot}_{,\\gls{acr:gcrf}}\\times\\gls{sym:radvec}\n \\label{eq:relvel-rot}\n\\end{equation}\n\nThe angular rotation vector of the Earth, \\gls{sym:rot}, is defined in the \\gls{acr:tirs} as \n$\\gls{sym:rot}_{,\\gls{acr:tirs}}=\\left[0,0,\\omega_{\\gls{idx:earth}}\\right]^T$. As the relative velocity is evaluated in the \\gls{acr:gcrf}, one has to take care \nof the appropriate frame transformation. \n\nThe associated partial derivatives of the acceleration vector with respect to the radius vector thus result as:\n\\begin{equation}\n \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\gls{sym:radvec}} = \n   \\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\relvel}\\frac{\\partial\\relvel}{\\partial\\gls{sym:radvec}} =\n  -\\frac{\\partial\\gls{sym:avec}_{\\gls{idx:drag}}}{\\partial\\relvel}\\left(\\kot{tirs}{gcrf} \\gls{sym:rot}_{,\\gls{acr:tirs}}\\right)\n\\end{equation}\nMaking use of the fact, that $\\gls{sym:rot}_{,\\gls{acr:tirs}}$ has only a non-zero component in \\gls{sym:zg}-direction, the first rotation in the \ntransformation from \\gls{acr:tirs} to \\gls{acr:gcrf} (reduction of the \\acrfull{acr:era}, see \\eq{eq:ERA}) is not required (identity).", "meta": {"hexsha": "8cf64f6df03551b435325325526a90da79532460", "size": 34431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/01-NEPTUNE/02-Propagation/covariance.tex", "max_stars_repo_name": "mmoeckel/neptune", "max_stars_repo_head_hexsha": "6c170d0df7b12fbfa1e92b15337ca8e8df3b48b0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-03-30T08:42:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T10:48:20.000Z", "max_issues_repo_path": "documentation/01-NEPTUNE/02-Propagation/covariance.tex", "max_issues_repo_name": "mmoeckel/neptune", "max_issues_repo_head_hexsha": "6c170d0df7b12fbfa1e92b15337ca8e8df3b48b0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-06-11T03:36:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T12:34:22.000Z", "max_forks_repo_path": "documentation/01-NEPTUNE/02-Propagation/covariance.tex", "max_forks_repo_name": "mmoeckel/neptune", "max_forks_repo_head_hexsha": "6c170d0df7b12fbfa1e92b15337ca8e8df3b48b0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-10T05:30:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:13:35.000Z", "avg_line_length": 66.8563106796, "max_line_length": 235, "alphanum_fraction": 0.666143882, "num_tokens": 13007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6190883022408511}}
{"text": "\\section{Scattering theory}\n\nSince in a real metal there would be many scatters that can be behave as obstacles for electron that have free wave functions. Therefore we need to calculate them to analyse the real behaviour of the electrons.\n\n\\noindent\nThen the wave function of the electron in a real matel $\\Psi(\\vb{r},t)$ should satisfy the following time-dependet Schrodinger equation\n\\begin{equation} \\label{2.1}\n  i \\hbar \\pdv{\\Psi(\\vb{r},t)}{t} = [H_e(t) + U(\\vb{r})] \\Psi(\\vb{r},t)\n\\end{equation}\nwhere $U(\\vb{r})$ is the total scattering potential. We have represented the all scatters using this potential. Since the solutions \\eqref{1.52} are create a complete orthonormal basis we can represent this wave function using those as follows\n\\begin{equation} \\label{2.2}\n  \\Psi(\\vb{r},t) = \\sum_j a_j(t) \\ket{\\psi_j(t)}\n\\end{equation}\nwhere the difference inidces j corresponding to the different sets of all quantum numbers $p_x$ and $n$\n\\begin{equation} \\label{2.3}\n  j \\rightarrow (m,n) \\quad \\text{where} \\quad\n  m,n =0,1,2,...\n\\end{equation}\nwith $m$ is defined for quantized momentum in $x$ direction\n\\begin{equation} \\label{2.4}\n  p_x = m \\frac{2\\pi \\hbar}{L_x}\n\\end{equation}\n\n\\noindent\nNow we can use the conventional pertubation theory to calculate scattering process of electron at a state $\\ket{\\psi_j}$ to a state $\\ket{\\psi_j'}$. For that assume an electron be in the $j$ state at the time $t=0$ and corresponding $a_j'(0) = \\delta_{j,j'}$.\n\n\\noindent\nFirst subtitute a general electron state $\\Psi(\\vb{r},t)$ at time $t$ as the incoming electron to the Schrodinger equation given in Eq. \\eqref{2.1}\n\\begin{equation} \\label{2.5}\n  i \\hbar \\pdv{t} \\sum_j a_j(t) \\ket{\\psi_j(t)}= [H_e(t) + U(\\vb{r})] \\sum_j a_j(t) \\ket{\\psi_j(t)}\n\\end{equation}\n\\begin{equation} \\label{2.6}\n  i \\hbar\\sum_j   \\dot{a_j}(t) \\ket{\\psi_j(t)} + a_j(t)\\pdv{t}\\ket{\\psi_j(t)}= [H_e(t) + U(\\vb{r})] \\sum_j a_j(t) \\ket{\\psi_j(t)}\n\\end{equation}\nsince all the ${\\ket{\\psi(t)}}$ staistfy the Schrodinger equation \\eqref{1.18}\n\\begin{equation} \\label{2.7}\n  i \\hbar\\sum_j   \\dot{a_j}(t) \\ket{\\psi_j(t)} = \\sum_j U(\\vb{r}) a_j(t) \\ket{\\psi_j(t)}.\n\\end{equation}\nThen take inner product with state with the state $\\ket{\\psi_{j'}(t)}$\n\\begin{equation} \\label{2.8}\n  i \\hbar\\sum_j   \\dot{a_j}(t) \\braket{\\psi_{j'}(t)}{\\psi_j(t)} = \\sum_j\n  a_j(t) \\bra{\\psi_{j'}(t)} U(\\vb{r}) \\ket{\\psi_j(t)}\n\\end{equation}\nBut using the \\textit{Born approximation} we can assume that this incoming wave have the initial state of the electron at $t=0$ and therefore this equation will modified to\n\\begin{equation} \\label{2.9}\n  i \\hbar\\sum_j   \\dot{a_j}(t) \\braket{\\psi_{j'}(t)}{\\psi_j(t)} =\n  \\bra{\\psi_{j'}(t)} U(\\vb{r}) \\ket{\\psi_j(t)}\n\\end{equation}\ndue to orthonormality this becomes\n\\begin{equation} \\label{2.10}\n  i \\hbar \\dot{a_{j'}}(t) =\n  \\bra{\\psi_{j'}(t)} U(\\vb{r}) \\ket{\\psi_j(t)}\n\\end{equation}\nand finally this leads to first order pertubation theory for Sscattering as follows\n\\begin{equation} \\label{2.11}\n   \\dot{a_{j'}}(t) =\n  -\\frac{i}{\\hbar}\\bra{\\psi_{j'}(t)} U(\\vb{r}) \\ket{\\psi_j(t)}\n\\end{equation}\nwhere\n\\begin{equation} \\label{2.12}\n   a_{j'}(t) =\n  -\\frac{i}{\\hbar}\n  \\int_0^t dt' \\int_S d\\vb{r} \\;\n  \\psi_{j'}^{*} (\\vb{r},t') U(\\vb{r}) {\\psi_j(\\vb{r},t')}\n\\end{equation}\nwhere the integration should be performed over the 2DEG area $S=L_xL_y$. Then we can calculate this using the eqution we derived in \\eqref{1.52} as follows\n\\begin{equation} \\label{2.13}\n  \\begin{aligned}\n    a_{j'}(t) & =\n   -\\frac{i}{\\hbar}\n   \\int_0^t dt' \\int_S d\\vb{r} \\;\n   \\bigg[\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n'}^*\\big(y - {y'}_0 -\\zeta(t)\\big) \\\\\n   & \\times\n     \\exp(\n    \\frac{i}{\\hbar}\\bigg[E_{n'}t' - m'\\frac{2\\pi \\hbar x}{L_x} -\n   \\frac{eE(y-{y'}_0)}{\\omega}\\cos(\\omega t')-\n   m_e\\dot{\\zeta}(t)\\big[y - {y'}_0 -\\zeta(t')\\big]\n    - \\int_0^{t'}dt'L(\\zeta,\\dot{\\zeta},t\")\\bigg]) \\\\\n    & \\times\n    U(\\vb{r}) \\\\\n    & \\times\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 -\\zeta(t')\\big) \\\\\n    & \\times\n      \\exp(\n     \\frac{i}{\\hbar}\\bigg[ - E_{n}t' + m\\frac{2\\pi \\hbar x}{L_x} -\n    \\frac{eE(y-y_0)}{\\omega}\\cos(\\omega t') -\n    m_e\\dot{\\zeta}(t')\\big[y - y_0 -\\zeta(t')\\big]\n     - \\int_0^{t'}d\\tilde{t}L(\\zeta,\\dot{\\zeta},\\tilde{t})\\bigg])\n    \\bigg]\n  \\end{aligned}\n\\end{equation}\nthen this will be simplified to\n\\begin{equation} \\label{2.14}\n  \\begin{aligned}\n    a_{j'}(t) & =\n   -\\frac{i}{\\hbar}\n   \\int_0^t dt' \\int_S d\\vb{r} \\;\n   \\bigg[\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n'}^*\\big(y - {y'}_0 -\\zeta(t')\\big)\n   U(\\vb{r})\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 -\\zeta(t')\\big)  \\\\\n   & \\times\n     \\exp(\n    \\frac{i}{\\hbar}\\bigg[ E_{n'}t' - m'\\frac{2\\pi \\hbar x}{L_x} -\n   \\frac{eE(y-{y'}_0)}{\\omega}\\cos(\\omega t') -\n   m_e\\dot{\\zeta}(t')\\big[y - {y'}_0 -\\zeta(t')\\big]\n    - \\int_0^{t'}d\\tilde{t}L(\\zeta,\\dot{\\zeta},\\tilde{t})\\bigg]) \\\\\n    & \\times\n      \\exp(\n     \\frac{i}{\\hbar}\\bigg[ - E_{n}t' + m\\frac{2\\pi \\hbar x}{L_x} +\n    \\frac{eE(y-y_0)}{\\omega}\\cos(\\omega t') +\n    m_e\\dot{\\zeta}(t')\\big[y - y_0 -\\zeta(t')\\big]\n     + \\int_0^{t'}d\\tilde{t}L(\\zeta,\\dot{\\zeta},\\tilde{t})\\bigg])\n    \\bigg]\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{2.15}\n  \\begin{aligned}\n    a_{j'}(t) & =\n   -\\frac{i}{\\hbar}\n   \\int_0^t dt' \\int_S d\\vb{r} \\;\n   \\bigg[\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n'}^*\\big(y - {y'}_0 -\\zeta(t')\\big)\n   U(\\vb{r})\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 -\\zeta(t')\\big)\n   \\exp(\\frac{2\\pi i(m-m') \\hbar x}{L_x})\n   \\\\\n   & \\times\n     \\exp(\n    \\frac{i}{\\hbar}\\bigg[ E_{n'}t' +\n   \\frac{eE{y'}_0}{\\omega}\\cos(\\omega t') +\n   m_e\\dot{\\zeta}(t'){y'}_0\n    \\bigg])\n      \\exp(\n     \\frac{i}{\\hbar}\\bigg[ - E_{n}t' -\n    \\frac{eEy_0}{\\omega}\\cos(\\omega t') -\n    m_e\\dot{\\zeta}(t)y_0\n    \\bigg])\n    \\bigg].\n  \\end{aligned}\n\\end{equation}\nThe time dependence of the $chi_n(y)$ can neglect since it is integrate over all the values of the $y$ and we can write this as\n\\begin{equation} \\label{2.16}\n  \\begin{aligned}\n    a_{j'}(t) & =\n   -\\frac{i}{\\hbar}\n   \\int_S d\\vb{r} \\;\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n'}^*\\big(y - {y'}_0 -\\zeta(t')\\big)\n   U(\\vb{r})\n   \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 -\\zeta(t')\\big)\n   \\exp(\\frac{2\\pi i(m-m') \\hbar x}{L_x})\n   \\\\ & \\times\n   \\int_0^t dt' \\;\n   \\bigg[\n     \\exp(\n    \\frac{i}{\\hbar}\\bigg[ (E_{n'} -E_{n}) t' +\n   \\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\omega(\\omega_0^2-\\omega^2)}\\cos(\\omega t')\n    \\bigg])\n    \\bigg].\n  \\end{aligned}\n\\end{equation}\nUsing Jacobi-Anger expansion\n\\begin{equation} \\label{2.17}\n  e^{iz\\cos(\\theta)} = \\sum_{l=-\\infty}^{\\infty} i^l J_j(z)e^{in\\theta}\n\\end{equation}\nabove eqution can be modified as\n\\begin{equation} \\label{2.18}\n  \\begin{aligned}\n    a_{j'}(t)  =\n   -\\frac{i}{\\hbar}\n   U_{j'j}\n   \\int_0^t dt' \\;\n   \\bigg[\n   \\sum_{l=-\\infty}^{\\infty} i^l J_l\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n     \\exp(\n    \\frac{i}{\\hbar} (E_{n'} -E_{n} + l\\hbar\\omega) t')\n    \\bigg]\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{2.19}\n  U{j'j} \\equiv \\mel{\\Phi_{j'}(\\vb{r})}{U(\\vb{r})}{\\Phi_j(\\vb{r})}\n\\end{equation}\nwith bare electron eigen states (without dressing field)\n\\begin{equation} \\label{2.20}\n  \\Phi_{j}(\\vb{r}) = \\frac{1}{\\sqrt{L_x}}\\exp(\\frac{2\\pi im \\hbar x}{L_x}) \\chi_{n}(y).\n\\end{equation}\nConsidering time evalution from negative values we can write the same expression as follows\n\\begin{equation} \\label{2.21}\n  \\begin{aligned}\n    a_{j'}(t)  =\n   -\\frac{i}{\\hbar}\n   U_{j'j}\n   \\int_{-t/2}^{t/2} dt' \\;\n   \\bigg[\n   \\sum_{l=-\\infty}^{\\infty} i^l J_l\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n     \\exp(\n    \\frac{i}{\\hbar} (E_{n'} -E_{n} + l\\hbar\\omega) t')\n    \\bigg].\n  \\end{aligned}\n\\end{equation}\nTo calculate scattering probability we can use this scattering amplitude's squre value\n\\begin{equation} \\label{2.22}\n  \\begin{aligned}\n    |a_{j'}(t)|^2  =\n   \\frac{|U_{j'j}|^2}{\\hbar^2} &\n   \\int_{-t/2}^{t/2} dt' \\;\n   \\bigg[\n   \\sum_{l=-\\infty}^{\\infty} {-i}^l J_l\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n     \\exp(\n    \\frac{-i}{\\hbar} (E_{n'} -E_{n} + l\\hbar\\omega) t')\n    \\bigg] \\\\\n    & \\times\n    \\int_{-t/2}^{t/2} dt^{''} \\;\n    \\bigg[\n    \\sum_{k=-\\infty}^{\\infty} i^k J_k\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\exp(\n     \\frac{i}{\\hbar} (E_{n'} -E_{n} + k\\hbar\\omega) t^{''})\n     \\bigg]\n  \\end{aligned}\n\\end{equation}\nConsidering long time $t\\rightarrow \\infty$ we can make the integral into a delta function as follows\n\\begin{equation} \\label{2.23}\n  \\begin{aligned}\n    |a_{j'}(t)|^2  =\n   4\\pi^2|U_{j'j}|^2 &\n   \\bigg[\n   \\sum_{l=-\\infty}^{\\infty} {-i}^l J_l\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n     \\delta(-E_{n'} +E_{n} - l\\hbar\\omega)\n     \\bigg] \\\\\n    & \\times\n    \\bigg[\n    \\sum_{k=-\\infty}^{\\infty} i^k J_k\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\delta(E_{n'} - E_{n} + k\\hbar\\omega)\n     \\bigg]\n  \\end{aligned}\n\\end{equation}\nand this implies $l=k$ and this leads to\n\\begin{equation} \\label{2.24}\n  \\begin{aligned}\n    |a_{j'}(t)|^2  =\n   4\\pi^2|U_{j'j}|^2\n   \\bigg[\n   \\sum_{l=-\\infty}^{\\infty} J_l^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n     \\delta^2(E_{n'} - E_{n} + l\\hbar\\omega).\n  \\end{aligned}\n\\end{equation}\nThen using the famous the square $\\delta$ function transormation method\n\\begin{equation} \\label{2.25}\n  \\begin{aligned}\n     \\delta^2(\\epsilon ) = \\delta(\\epsilon )\\delta^2(0)\n     \\lim_{t\\rightarrow\\infty} \\int_{-t/2}^{t/2} e^{i0\\times t' /\\hbar} dt' =\n     \\frac{\\delta(\\epsilon) t}{2\\pi \\hbar}\n  \\end{aligned}\n\\end{equation}\nwe can calculatre the probability of electron scattering between states $j$ and $j'$ per unit time as\n\\begin{equation} \\label{2.26}\n    \\mathcal{W}_{j'j} \\equiv \\dv{|a_{j'}(t)|^2}{t} =\n    |U_{j'j}|^2\n     \\sum_{l=-\\infty}^{\\infty} J_l^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\times\n    \\frac{2\\pi}{\\hbar} \\delta(E_{n'} - E_{n} + l\\hbar\\omega)\n\\end{equation}\n\n\\noindent\nTo avoid thee energy echange betwen a high-frequency field and electrons, the field should be purely dressing. We can achieve that by using the field with off-resonant and high frequency. Therefore, the only effect of the dressing field on 2DEG is the renormalization of the probability of elastic electron scattering within the same Landau level $(E_{n'}=E_n)$, which described by the term with $l=0$ the Eq. \\eqref{2.26} leads to\n\\begin{equation} \\label{2.27}\n    \\mathcal{W}_{j'j} = J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\mathcal{W}_{j'j}^{(0)}\n\\end{equation}\nwhere\n\\begin{equation} \\label{2.28}\n    \\mathcal{W}_{j'j}^{(0)} = \\frac{2\\pi}{\\hbar} |U_{j'j}|^2\n    \\delta(E_{n'} - E_{n})\n\\end{equation}\nis the probability of scattering of a \\textit{bare electron}. It is important to notice that the Bessel function factor depend on both the dressing field and stationaty magnetic field. This factor is responcible for all the effcts discussed in thisarticle.\n\n\\noindent\nOne can define the lifetime of the dressed electron at the Landau level $\\tau$ is renormalized by the Bessel function as below\n\\begin{equation} \\label{2.29}\n    \\frac{1}{\\tau} \\equiv \\sum_{j'} \\mathcal{W}_{j'j} =\n    \\sum_{j'}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\mathcal{W}_{j'j}^{(0)}\n\\end{equation}\nwhere we have consider all posibilities that electron can jump to the state $j'$. Then rewrite the delat function as follows\n\\begin{equation} \\label{2.30}\n    \\delta(\\epsilon) =\n    \\frac{1}{\\pi} \\lim_{\\Gamma \\rightarrow 0 } \\frac{\\Gamma}{\\Gamma^2 + \\epsilon^2}\n\\end{equation}\nwhere in this study we can assume that the paramater $\\Gamma \\equiv \\hbar/\\tau$ as scattering induced broading of the Landau level. But for the elestic scatteing within the same Landau level, we can write the $\\delta$ function as\n\\begin{equation} \\label{2.31}\n    \\delta(E_{n'} - E_{n}) \\approx\n    \\frac{1}{\\pi \\Gamma}.\n\\end{equation}\nTherefore Eq. \\eqref{2.29} will change to\n\\begin{equation} \\label{2.32}\n    \\frac{1}{\\tau} =\n    \\sum_{j'}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\times\n    \\frac{2\\pi}{\\hbar} |U_{j'j}|^2 \\times \\frac{1}{\\pi \\Gamma}\n\\end{equation}\n\\begin{equation} \\label{2.33}\n    \\frac{1}{\\tau} =\n    \\sum_{j'}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\times\n    \\frac{2}{\\hbar} |U_{j'j}|^2 \\times \\frac{\\tau}{\\hbar}\n\\end{equation}\nand finally this can be modified to\n\\begin{equation} \\label{2.34}\n    \\frac{1}{\\tau} =\n    \\bigg[\n    \\frac{2}{\\hbar^2}\n    \\sum_{j'}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    |U_{j'j}|^2\n    \\bigg]^{1/2}\n\\end{equation}\nwhere the summation is performed over electron states $j'$ within the same Landau level.\n\n\\noindent\nNow lets specify more on the scattering potential where we can model them as randomly distributed delta fucntions as follows\n\\begin{equation} \\label{2.35}\n    U(\\vb{r}) \\equiv \\sum_{i=1}^{N_s} U_0 \\delta(\\vb{r} - \\vb{r}_i)\n\\end{equation}\nwhere $N_s$ is the total number of scatters in the considering matel. Now we can calculate $|U_{j'j}|^2$ as follows\n\\begin{equation} \\label{2.36}\n  \\begin{aligned}\n    |U_{j'j}|^2 = &\n    \\sum_{i =1}^{N_s}\n    \\frac{1}{L_x^2}\n    \\int \\int  dx_1 dy_1\n      \\exp(\\frac{-{p'}_x x_1}{\\hbar})\n      \\chi_n^* (y_1 - {y'}_0)\n      U_0 \\delta(x_1-x_i)\\delta(y_1-y_i)\n      \\exp(\\frac{{p}_x x_1}{\\hbar})\n      \\chi_n (y_1 - {y}_0) \\\\\n    & \\times\n    \\int \\int  dx_2 dy_2\n      \\exp(\\frac{{p'}_x x_2}{\\hbar})\n      \\chi_n (y_2 - {y'}_0)\n      U_0 \\delta(x_2 - x_i)\\delta(y_2 - y_i)\n      \\exp(\\frac{-{p}_x x_2}{\\hbar})\n      \\chi_n^* (y_2 - {y}_0)\n  \\end{aligned}\n\\end{equation}\nand considering only non-zero values for $x_1$ and $x_2$ integrals we can re-write this as\n\\begin{equation} \\label{2.37}\n  \\begin{aligned}\n    |U_{j'j}|^2 = &\n    \\sum_{i =1}^{N_s}\n    \\frac{U_0^2}{L_x^2}\n    \\int dy_1\n      \\exp(\\frac{-{p'}_x x_i}{\\hbar})\n      \\chi_n^* (y_1 - {y'}_0)\n      \\delta(y_1-y_i)\n      \\exp(\\frac{{p}_x x_i}{\\hbar})\n      \\chi_n (y_1 - {y}_0) \\\\\n    & \\times\n    \\int dy_2\n      \\exp(\\frac{{p'}_x x_i}{\\hbar})\n      \\chi_n (y_2 - {y'}_0)\n      \\delta(y_2 - y_i)\n      \\exp(\\frac{-{p}_x x_i}{\\hbar})\n      \\chi_n^* (y_2 - {y}_0)\n  \\end{aligned}\n\\end{equation}\nand this will be simplified to\n\\begin{equation} \\label{2.38}\n  \\begin{aligned}\n    |U_{j'j}|^2 = &\n    \\sum_{i =1}^{N_s}\n    \\frac{U_0^2}{L_x^2}\n    \\int dy_1\n      \\chi_n^* (y_1 - {y'}_0)\n      \\delta(y_1-y_i)\n      \\chi_n (y_1 - {y}_0) \\\\\n    & \\times\n    \\int dy_2\n      \\chi_n (y_2 - {y'}_0)\n      \\delta(y_2 - y_i)\n      \\chi_n^* (y_2 - {y}_0).\n  \\end{aligned}\n\\end{equation}\nAgain considering only non-zero values for $y_1$ and $y_2$ integrals we can re-write this as\n\\begin{equation} \\label{2.39}\n  \\begin{aligned}\n    |U_{j'j}|^2 = &\n    \\sum_{i =1}^{N_s}\n    \\frac{U_0^2}{L_x^2}\n      \\chi_n^* (y_i - {y'}_0)\n      \\chi_n (y_i - {y}_0)\n      \\chi_n (y_i - {y'}_0)\n      \\chi_n^* (y_i - {y}_0).\n  \\end{aligned}\n\\end{equation}\n\\begin{equation} \\label{2.40}\n  \\begin{aligned}\n    |U_{j'j}|^2 =\n    \\frac{U_0^2}{L_x^2}\n    \\sum_{i =1}^{N_s}\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0).\n  \\end{aligned}\n\\end{equation}\nNow subtituting this derivation into the Eq. \\eqref{2.34} we will get\n\\begin{equation} \\label{2.41}\n    \\frac{1}{\\tau} =\n    \\bigg[\n    \\frac{2U_0^2}{\\hbar^2 L_x^2}\n    \\sum_{{y'}_0}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n    \\sum_{i =1}^{N_s}\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0)\n    \\bigg]^{1/2}\n\\end{equation}\nwhere $j'$ reduced to ${p'}_x$ (since $n'=n$)and we can represent it by ${y'}_0$. Then this will modified to\n\\begin{equation} \\label{2.42}\n    \\frac{1}{\\tau} =\n    \\bigg[\n    \\frac{2U_0^2}{\\hbar^2 L_x^2}\n    \\sum_{{y'}_0}\n    \\sum_{i =1}^{N_s}\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0)\n    \\bigg]^{1/2}.\n\\end{equation}\nNow considering large size of sample and a macroscopically large $N_s$ scatters we can promate the summation to integrations as follows\n\\begin{equation} \\label{2.43}\n    \\frac{1}{\\tau} =\n    \\bigg[\n    \\frac{2U_0^2}{\\hbar^2 L_x^2}\n    \\frac{eB L_x}{2\\pi\\hbar}\\int d{y'}_0\n    \\frac{N_s} {L_x}\\int dy_i\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0)\n    \\bigg]^{1/2}.\n\\end{equation}\nAssuming $L_x = L_y$ we can define the area of the 2D material as\n\\begin{equation} \\label{2.44}\n    S \\equiv L_xL_x = L_xL_y\n\\end{equation}\nand then we can re-write the above as\n\\begin{equation} \\label{2.45}\n    \\frac{1}{\\tau} =\n    \\bigg[\n    \\frac{eBN_sU_0^2}{\\pi\\hbar^3 S}\n    \\int d{y'}_0\n    \\int dy_i\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0)\n    \\bigg]^{1/2}.\n\\end{equation}\nDefine the \\textit{density of scatters} per unit area of 2DEG\n\\begin{equation} \\label{2.46}\n    n_s \\equiv \\frac{N_s}{S}\n\\end{equation}\nand the \\textit{magnetic length} as\n\\begin{equation} \\label{2.47}\n    l_0 \\equiv \\sqrt{\\frac{\\hbar}{eB}}.\n\\end{equation}\nNow our Eq. \\eqref{2.45} leads to\n\\begin{equation} \\label{2.48}\n    \\frac{1}{\\tau} =\n    \\sqrt{\n    \\frac{n_sU_0^2}{\\pi l_0^2 \\hbar^2}}\n    \\bigg[\n    \\int d{y'}_0\n    \\int dy_i\n    J_0^2\\bigg[\\frac{eE({y'}_0 - y_0)\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\chi_n^2 (y_i - {y'}_0)\n      \\chi_n^2 (y_i - {y}_0)\n    \\bigg]^{1/2}\n\\end{equation}\nand now define new dummy variables as follows (since $y_0$ is a paramter)\n\\begin{equation} \\label{2.49}\n    ({y'}_0 - y_0) \\rightarrow  y  \\quad \\text{and} \\quad\n    ({y}_i- {y'}_0) \\rightarrow y'\n\\end{equation}\nand finally we will get the eqution for the dressed electron lifetime at the $n$th Landau level as\n\\begin{equation} \\label{2.50}\n    \\frac{1}{\\tau} =\n    \\sqrt{\n    \\frac{n_sU_0^2}{\\pi l_0^2 \\hbar^2}}\n    \\bigg[\n    \\int \\int  dy dy'\\;\n    J_0^2\\bigg[\\frac{eEy\\omega_0^2}{\\hbar\\omega(\\omega_0^2-\\omega^2)}\\bigg]\n      \\chi_n^2 (y')\n      \\chi_n^2 (y+y')\n    \\bigg]^{1/2}\n\\end{equation}\n\\hfill$\\blacksquare$\n", "meta": {"hexsha": "47f5bd22fe42b0df092bfd25beea5eb1f38a1bb8", "size": 18444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_02.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/sec_02.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/sec_02.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.888, "max_line_length": 431, "alphanum_fraction": 0.6011711126, "num_tokens": 7908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768108626046, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6190882998456759}}
{"text": "\\chapter{Power and Sample Size \\label{chapter:powersamplesize}}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Statistical Power}\n\n\\textbf{Power} is the probability that a hypothesis test will reject the null hypothesis if the alternative hypothesis is, in fact, true. The graph below shows two distributions: the sampling distribution under the null (mean $\\mu_0$) and the sampling distribution under the alternative hypothesis (mean $\\mu_1$). Note that these sampling distributions are for the \\emph{test statistic}; it could be the sample mean, sample proportion, sample correlation coefficient, sample difference in means, etc.\n\n\\begin{center}\n%\\includegraphics[width=0.65\\textwidth]{img/statistical-power-chart.png}\n\\end{center}\n\n\\begin{mdframed}\n\\textbf{Question 2.8:} There are three ways to increase the power of a hypothesis test. (Hint: Have a look at the parameters in the formula for the $T$-test statistic, above.) Try to list them here:\n\\begin{enumerate}\n\\item ~\n\\item ~\n\\item ~\n\\end{enumerate}\n\\vspace{5mm}\n\\end{mdframed}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Sample Size Calculations}\n\nFor many statistical hypothesis tests, we can reverse the calculation and ask: how many samples do we need at a certain effect size to reject the null at a given significance level? Even in cases where you can't invert the test statistic itself, you can often use \\textbf{bootstrapping}, \\textbf{permutations}, etc. to simulate the appearance of the data under the null. \n\nThis graph shows the number of samples required to detect the effect size shown in the Appalachian town example in the slides ($\\overline{x} = 125.45$, $\\mu_0 = 139.75$) at varying significance levels: $\\alpha = 0.1$ (orange line), $\\alpha = 0.05$ (blue dotted line), and $\\alpha = 0.01$ (turquoise dashed line). \n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/hyp-z-test-power-curve-1.png}\n\\end{center}\n\nNow let's vary the effect size. The graph below shows three lines, representing the sample sizes needed to reject the null at $\\alpha = 0.1$ (solid), $0.05$ (dotted), and $0.01$ (dashed) significance levels, using a two-sided test.\n\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{img/hyp-z-test-power-curve-2.png}\n\\end{center}\n", "meta": {"hexsha": "fa6f6c673a206dc3473026859def0f72f2971a74", "size": 2323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-power-sample-size.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-power-sample-size.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-power-sample-size.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.075, "max_line_length": 500, "alphanum_fraction": 0.7094274645, "num_tokens": 570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.6190167546193813}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Conclusions\\label{ch:Conclusions}}\nIn this dissertation I have developed the first Monte Carlo implementation of Arnoldi's method for neutron transport.  This implementation uses explicitly restarted Arnoldi's method to estimate multiple eigenvalues of the transport-fission operator of the Boltzmann transport equation \\eqref{eq:BoltzmannEquation}.  \n\nUsing Arnoldi's method for estimating eigenvalues is a new technique in the Monte Carlo particle transport field; traditionally, the power method has been used.  Arnoldi's method has been used in the numerical analysis community for many years to estimate multiple eigenvalues and eigenvectors of a linear operator, but this is the first time it has been used with a Monte Carlo application of the linear operator.\n\nI have demonstrated the ability to use Arnoldi's method to estimate up to three eigenvalues of the transport-fission operator for a variety of homogeneous and heterogeneous one-dimensional problems.  The eigenvalue estimates have been compared to and agree with published results and independent deterministic calculations within statistical uncertainty.  The eigenvectors have also been estimated and compared with deterministic calculations; again the results from Arnoldi's method are in harmony with the deterministic calculations.  In some situations, Arnoldi's estimated eigenvectors are improvements over the power method estimated eigenvectors.\n\nArnoldi's method can be used to calculate more than three eigenmodes.  Calculating additional higher-order eigenmodes will require additional iterations in a restart, and it may be necessary to track more particles in an iteration or use a finer spatial discretization. \n\nArnoldi's method requires the fission source to be discretized.  The simplest way to discretize the fission source is to use a constant in space or first-order accurate spatial approximation of the fission source which can, unfortunately, cause an error in the eigenvalue estimate if too few spatial bins are used to discretize the source.  I have implemented a second order accurate approximation to the fission source and have used it to reduce the error in the eigenvalue calculation by an order of magnitude for the same number of particles tracked.  The eigenvector estimates from the second order accurate approximation are a great improvement over the first order accurate approximation.  Rather than a jagged, step-wise approximation to the eigenvector, the second-order accurate approximation is a smooth and nearly continuous function across bins.  In addition, the figure of merit for the second-order accurate approximation is 2--3 times larger than the first order accurate approximation.\n\nI have investigated relaxing the precision to which the transport-fission operator is applied at every Arnoldi iteration.  Studies have shown that relaxing Arnoldi's method has no effect on the convergence to the correct eigenvalues.  Relaxing Arnoldi's method in a Monte Carlo particle transport application simply involves tracking fewer particles in an iteration than was initially specified; tracking fewer particles is less computationally expensive and reduces the overall time for the simulation.  \n\nRelaxing Arnoldi's method for Monte Carlo criticality applications can save on computation time.  Relaxing too much, however,  can cause the eigenvalue estimates to be incorrect.  In addition, relaxing Arnoldi's method only a little can cause the figure of merit to be smaller than for a non-relaxed Arnoldi's method.  Relaxing Arnoldi's method turns out to be not a sufficient improvement to make it worthwhile to use in practice.  \n\nTwo important topics currently being investigated in the Monte Carlo particle transport community are the underestimation of the variance of the mean eigenvalue estimate and the convergence of the fission source.  The power method \\emph{under}estimates the variance because it ignores the correlation between power method iterations.  My implementation of Arnoldi's method also ignores the inter-iteration correlation, but the reported variance appears to be more conservative.  In one of the problems discussed in this dissertation, I have shown that Arnoldi's method \\emph{over}estimates the uncertainty in the eigenvalue estimate by approximately 10\\%.\n\nThe power method can take a long time to converge the fission source---especially for problems with a large dominance ratio.  In Monte Carlo criticality calculations, both the eigenvalue estimate and the fission source must be converged before tallying begins.  If convergence is slow, more iterations must be discarded and computation wasted.  I have shown that Arnoldi's method is superior to the power method in converging both the eigenvalue estimate and the fission source.  Arnoldi's method appears to converge both the eigenvalue estimate and the fission source immediately, while the power method can require several hundreds of iterations.  \n\n\\section{Future Work \\label{sec:FutureWork}}\nWork on Monte Carlo Arnoldi's method for criticality calculations is far from complete.  This dissertation represents the first work performed in this field.  Some of the many topics that still need to be explored are described next.\n\n\\subsection{Implicit Restarts} \\label{sec:IRAM}\nOne of the most intriguing ways that restarted Arnoldi's method could be improved is by implementing \\emph{implicit} restarts.  Implicit restarts were developed by \\citet{Sorensen:1992Impli-0} as a way to restart Arnoldi's method with an improved starting vector, and at the same time reduce the computational expense of the algorithm and increase the stability of maintaining orthogonality between Arnoldi vectors.  \n\nImplicitly restarted Arnoldi's method (IRAM), as it is called, performs iterations of the shifted \\QR algorithm on the upper Hessenberg matrix, $H_m$, in the Arnoldi factorization in exchange of Arnoldi iterations.  It can be shown that performing these shifted \\QR iterations allows Arnoldi's method to jump into the middle of the next restart, skipping several iterations.  IRAM is mathematically equivalent to picking a vector for the beginning of a new restart as a linear combination of the eigenvectors associated with the desired region of the spectrum of \\A{} as we did in explicitly restarted Arnoldi's method.  The full derivation and proof of implicitly restarted Arnoldi's method is given in Appendix \\ref{ch:IRAM}.\n\nIn Arnoldi's method, applying the linear operator \\A{} is the most computationally expensive part, using greater than 80\\% of the computer cycles in a given iteration.  Since the number of iterations in an Arnoldi restart is small, performing \\QR iterations on $H_m$ will be inexpensive.  Trading computationally expensive applications of \\A{} for inexpensive \\QR iterations on $H_m$ should significantly reduce the computational expense of Arnoldi's method.\n\n\\subsection{Calculating Eigenvalue Estimates at Every Iteration}\nIn \\Fref{ch:ArnoldiMethod} it was suggested that an Arnoldi restart could be treated similarly to the power method; that is, at the end of an Arnoldi restart an estimate for the eigenvalues are calculated and stored.  In the power method, an eigenvalue estimate is calculated at every iteration; since multiple iterations make up one Arnoldi restart, the power method has many more eigenvalue estimates than does Arnoldi's method for the same number of iterations and number of particles tracked.\n\nThe variance of the mean of the eigenvalue estimates goes as one over the square-root of the number of eigenvalue estimates.  Thus, the power method has an advantage over Arnoldi's method in that it has more eigenvalue estimates---the variance for the mean eigenvalue from the power method will almost certainly be smaller.  \n\nThere is no reason why an eigenvalue estimate could not be calculated at every Arnoldi iteration instead of just at the end of a restart.  Of course, after the first iteration we could only estimate the fundamental eigenvalue; we would have to wait for additional iterations to estimate higher order eigenvalues.  It would be slightly more computationally expensive, but the decrease in the variance may be worth the extra expense.  In all of the calculations in which Arnoldi's method was directly compared to the power method, the figures of merit from the power method calculations were larger than the figures of merit for Arnoldi's method even though both methods took approximately the same amount of computational time.  The figure of merit is larger for the power method because the variance is smaller.  Calculating an eigenvalue estimate at every iteration would increase the number of estimates in Arnoldi's method, but is more computationally expensive.\n\nA preliminary test has been performed to see how estimating the eigenvalue at each iteration might work.  I have repeated the 20 mfp simulation in \\Fref{ch:ArnoldiMethod} from Arnoldi's method, but instead of estimating three eigenvalues only the fundamental eigenvalue is estimated and only two iterations are done per restart.  In each iteration 1E5 particles are tracked.  The number of restarts are 125 inactive and 500 active.  The total number of particles tracked and the total number of iterations is the same for this simulation and the power method and Arnoldi's method from \\Fref{ch:ArnoldiMethod}.\n\nThe results of this simulation are given in \\Fref{tab:N1Arnoldi}.  The results for the new simulation are given first and denoted with a star.  The eigenvalue estimate is within statistical uncertainty of the reference value of $\\lambda_0 = 4.82780$.  We can see that the standard deviation of this simulation is identical to the power method simulation from \\Fref{ch:ArnoldiMethod}, but that the figure of merit is larger.\n\\begin{table}[h] \\centering\n    \\begin{tabular}{rccc}\n        \\toprule\n        & $\\lambda_0$ & $\\sigma$ & FOM \\\\\n        \\midrule\n        Arnoldi* & 4.82806 & 6.3\\e{-4} & 6.6\\e{3} \\\\\n        Power    & 4.82734 & 6.3\\e{-4} & 5.4\\e{3} \\\\\n        Arnoldi  &  4.8290 & 1.5\\e{-3} & 1.1\\e{3} \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\caption{Eigenvalue estimate and figure of merit for Arnoldi's method (Arnoldi*) with just 2 iterations per restart and only saving the fundamental eigenmode.  Also included are results from \\Fref{tab:BasicResults} for comparison.  (Reference $\\lambda_0 = 4.82780$.)}\n    \\label{tab:N1Arnoldi}\n\\end{table}\n\n\\Fref{fig:N1ArnoldiValues} shows the eigenvalue estimate convergence as well as the Shannon Entropy.  In this particular simulation, Arnoldi's method does not converge the eigenvalue estimate or the Shannon entropy immediately as we have seen previously, but it still only requires a few restarts to converge.  \\Fref{fig:N1ArnoldiVectors} shows the estimated fundamental eigenvector along with the reference solution.  Again we see that Arnoldi's method can accurately estimate the fundamental eigenvector.  \n\\begin{figure} \\centering\n    \\subfloat[Eigenvalue estimate and Shannon Entropy]{\\label{fig:N1ArnoldiValues}\\input{Conclusions/Data/N1ArnoldiValues}}\n\n    \\subfloat[Eigenvector]{\\label{fig:N1ArnoldiVectors}\\input{Conclusions/Data/N1ArnoldiVectors}}\n    \\caption{Preliminary calculation of eigenvalue estimates, eigenvector, and Shanon entropy from an Arnoldi's method with just 2 iterations per restart and only saving the fundamental eigenmode.  The black line is the reference solution.}\n\\end{figure}\n\nThese preliminary results show two important things.  First, if we are interested in just one eigenmode we should use a smaller Krylov subspace (fewer iterations per restart) and have more active restarts; this reduces the variance and increases the figure of merit. Second, we see that computing an eigenvalue estimate more frequently can reduce the variance for the mean eigenvalue.\n\n\\subsection{Condensing Arnoldi's Method}\nOne suggestion that has been made\\footnote{very determinedly, in fact} for Arnoldi's method is to eliminate restarts and just do a few highly accurate iterations.  We have seen that Arnoldi's method does not need many inactive restarts to converge the fission source.  The only remaining reason to use many restarts is to obtain an estimation of the statistical uncertainty of the eigenvalue estimate.  However we also know that the estimate of the uncertainty is wrong.\n\nIt has been proposed that rather than performing many Arnoldi restarts, it may be beneficial to track many more particles during just one or two Arnoldi restarts with sufficient Krylov subspace size.  The application of \\A{} would be performed much more accurately and the eigenvalue estimates would be much better.\n\nWith only one or two Arnoldi restarts the statistical uncertainty could not be calculated as described in this dissertation; the variance of just two estimates isn't helpful.  In principle the statistical uncertainty could be calculated by propagating the statistical error through the iterations of Arnoldi's method.  This would be a profound change in how statistical uncertainties are calculated in Monte Carlo eigenvalue computations, no one has done this before.  \n\nA preliminary simulation has been done using this idea.  We return to the 20 mfp slab geometry introduced in \\Fref{ch:ArnoldiMethod}.  We will use the same total number of particles, but will put all of them into one inactive restart and one active restart; each restart has 10 iterations with 6.25\\e{6} particles tracked in each iteration.  \n\nThe eigenvalues from this simulation are given in \\Fref{tab:CondensedArnoldi} and the estimated eigenvectors in \\Fref{fig:CondensedArnoldiVectors}; the ``Condensed'' Arnoldi is Arnoldi's method with just two restarts, but many particles tracked in each iteration.  We see that the eigenvalue estimates are not exactly the same as the reference solution but that the eigenvector is an excellent estimate as with the regular Arnoldi's method.  However we do not have a way yet of estimating the statistical uncertainty of these values so we do not know if the eigenvalue estimates are within statistical uncertainty of the reference solution.\n\\begin{table}[h] \\centering\n    \\begin{tabular}{rccc}\n        \\toprule\n         & $\\lambda_0$ & $\\lambda_1$ & $\\lambda_2$ \\\\\n         \\midrule\n        Condensed Arnoldi & 4.8309 & 4.3824 & 3.8131 \\\\\n        Reference & 4.8278 & 4.3831 & 3.8174 \\\\\n        \\bottomrule\n\\end{tabular}\n    \\caption{Eigenvalue estimates for 20 mfp thick slab geometry from a condensed Arnoldi's method and Reference eigenvalues from \\cite{Garis:1991One-s-0}, and \\cite{Dahl:1979Eigen-0}.}\n    \\label{tab:CondensedArnoldi}\n\\end{table}\n\n\\begin{figure} \\centering\n    \\input{Conclusions/Data/CondensedArnoldiVectors}\n    \\caption{Preliminary calculation of eigenvectors from condensed Arnoldi.}\n    \\label{fig:CondensedArnoldiVectors}\n\\end{figure}\n\n\\subsection{Multi-dimensional and Real-world Problems}\nAll of the simulations demonstrated in this dissertation have been one-dimensional.  Restricting a prolem to one-dimension is sufficient for a proof-of-concept but it certainly does not represent a real-world problem.  As of yet, there have been no attempts at using Arnoldi's method in a three-dimensional, production code such as MCNP; any estimates of how Arnoldi's method may operate in three-dimensions is just speculation.\n\nMost likely the biggest issue when moving to three-dimensions is the length of the Arnoldi vectors.  It is expected that the number of discretization bins necessary for three dimensions would be at least $N^3$ where $N$ is the number of bins for a one-dimensional problem.  Increasing the size of the Arnoldi vectors by this magnitude would increase the computational expense of orthogonalizing the Arnoldi vectors as well as the expense of sampling and scoring in and from a three-dimensional source.  \n\nThe size of the Krylov subspace (number of iterations in a restart) necessary for a three-dimensional problem would seem to be greater than for a one-dimensional problem.  In this dissertation, the more difficult problems (i.e. problems with larger dominance ratios) required additional iterations for an accurate eigenvalue estimate.  A three-dimensional problem would almost certainly require more iterations than a one-dimensional problem and would therefore require more time.  \n\nArnoldi's method, while having been used extensively in the numerical analysis community has yet to be incorporated in Monte Carlo particle transport algorithms.  This dissertation represents the first work in this area.  Arnoldi's method has many promising qualities; further investigation will determine the ability of Arnoldi's method to be used in production Monte Carlo codes.\n", "meta": {"hexsha": "3c5aec4c13f624ce4b86502072b6f9510b85eaed", "size": 16716, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/Conclusions/Conclusions.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": "Dissertation/Conclusions/Conclusions.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": "Dissertation/Conclusions/Conclusions.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": 163.8823529412, "max_line_length": 1001, "alphanum_fraction": 0.8038406317, "num_tokens": 3603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6190167487061621}}
{"text": "\\section{Summary and Background}\n\\label{sec:summary}\n\n  A brief summary of \\citetitle{qe2paper} follows. Supporting information and \n  commentary on the methods presented is included as applicable.\n\n  \\subsection{Multigroup Neutron Diffusion and \\glsentrylong{nem}}\n\n    % write the equation\n    In its conventional form, the multigroup neutron diffusion equation for a\n    problem domain $\\vr \\in \\Omega$ can be written \n    \\begin{equation}\n      \\label{eq:multigroup_diffusion}\n      \\grad \\cdot \\current_g(\\vr) + \\Sigma_{r,g}(\\vr) \\phi_g(\\vr)= \n        \\frac{\\chi_g(\\vr)}{\\lambda} \n        \\sum_{g'=1}^{G} \\nu\\Sigma_{f,g'}(\\vr) \\phi_{g'}(\\vr) + \n        \\sum_{\\substack{g'=1 \\\\ g' \\ne g}}^{G} \n        \\Sigma_{s,g' \\rightarrow g}(\\vr) \\phi_{g'}(\\vr)\n    \\end{equation}\n    where \n    \\begin{conditions} % custom environment designed for this purpose\n      \\vr & spatial position vector, \\\\\n      \\current_g(\\vr) & net neutron current for energy group $g$ \n        \\units{$\\frac{1}{\\text{cm}^2 \\; \\text{s}}$}, \\\\\n      \\phi_g(\\vr) & fundamental eigenvector, \n        scalar neutron flux for energy group $g$\n        \\units{$\\frac{1}{\\text{cm}^2 \\; \\text{s}}$}, \\\\\n      \\Sigma_{r,g}(\\vr) & macroscopic removal cross section for energy group $g$ \n        \\units{$\\frac{1}{\\text{cm}}$}, \\\\\n      \\chi_g(\\vr) & fission spectrum for energy group $g$,\\\\\n      \\lambda & fundamental eigenvalue, effective neutron multiplication factor, \\\\\n      \\nu \\Sigma_{f,g}(\\vr) & number of fission neutrons times macroscopic fission\n        cross section in energy group $g$ \\units{$\\frac{1}{\\text{cm}}$}, \\\\\n      \\Sigma_{s,g' \\rightarrow g} (\\vr) & macroscopic scatter cross section from\n        energy group $g'$ to energy group $g$ \\units{$\\frac{1}{\\text{cm}}$}, \\\\\n      G & total number of energy groups.\n    \\end{conditions}\n\n    The three-dimensional domain, $\\Omega$, can then be discretized into a\n    structured grid of nodes. Next, the \\gls{nem} is introduced. Fundamentally,\n    the \\gls{nem} projects the transverse integrated flux onto a set of basis\n    functions. The transverse integrated multigroup neutron equation is given as\n    \\begin{equation}\n      \\label{eq:transverse_multigroup_diffusion}\n      \\frac{d \\current_{g,u} (u)}{d u} + \\overline{\\Sigma_{r,g}}\n        \\phi_{g,u}(u) = Q_{g,u}(u) - L_{g,u}(u)\n    \\end{equation}\n    where $u = x,\\ y,\\ z$ is a coordinate direction \\cite{qe2paper}. The terms \n    $Q_{g,u}(u)$ and $L_{g,u}(u)$ represent the transverse integrated neutron\n    source and transverse leakage respectively. Note that in\n    \\eref{eq:transverse_multigroup_diffusion}, the node indices\n    (i.e.~$i,j,k$) have been omitted and $\\overline{\\Sigma_{r,g}}$ represents\n    the average value of $\\Sigma_{r,g}(\\vr)$ in the node. The transverse\n    integrated current $\\current_{g,u}$ is then approximated\n    \\begin{equation}\n      \\label{eq:current_approximation}\n      \\current_{g,u}(u) = - \\overline{D_g} \\, \\frac{d \\phi_{g,u}(u)}{du}\n    \\end{equation}\n    where $\\overline{D_g}$ is the average value of the diffusion coefficient in\n    the node.\n\n    \\gls{nem} basis functions are typically polynomials and\n    \\citeauthor{qe2paper} select the Legendre polynomials. In their work, the\n    scalar flux is projected onto quartic polynomials and the transverse\n    integrated neutron source and transverse leakage terms are projected onto\n    quadratic polynomials. The selection of quartic and quadratic polynomials\n    respectively is consistent as the second derivative of the scalar flux is\n    related to the source and leakage terms \\cite{gehinThesis}. This projection\n    can be written\n    \\begin{align}\n      \\label{eq:flux_expansion}\n      \\phi_{g,u}(u) &= \\sum_{n=0}^{N_{\\phi} = 4} a_{g,u,n} \\, f_{u,n}(u), \\\\\n      \\label{eq:source_expansion}\n      Q_{g,u}(u)    &= \\sum_{n=0}^{N_Q = 2}      q_{g,u,n} \\, f_{u,n}(u), \\\\\n      \\label{eq:leakage_expansion}\n      L_{g,u}(u)    &= \\sum_{n=0}^{N_L = 2}      l_{g,u,n} \\, f_{u,n}(u),\n    \\end{align}\n    where $a_{g,u,n}$, $q_{g,u,n}$, and $l_{g,u,n}$ are the expansion\n    coefficients of $\\phi_{g,u}(u)$, $Q_{g,u}(u)$, and $L_{g,u}(u)$ respectively\n    and $f_{u,n}(u)$ is the $n^{th}$ Legendre polynomial \\cite{qe2paper}. To\n    solve for the coefficients of the expansions in \\eref{eq:flux_expansion},\n    \\eref{eq:source_expansion}, and \\eref{eq:leakage_expansion}, five equations\n    are required. The selected equations are:\n    \\begin{enumerate}\n      \\item flux continuity condition,\n      \\item current continuity condition,\n      \\item nodal neutron balance ($f_0$ weighted residual),\n      \\item $f_1$ weighted residual, and\n      \\item $f_2$ weighted residual.\n    \\end{enumerate}\n    Special attention is paid to boundary conditions and these conditions \n    replace the flux and current continuity equations on the problem boundary.\n\n  \\subsection{Local Elimination}\n    \\label{sec:local_elimination}\n\n    Recall the quantity of interest for this calculation is the fundamental\n    eigenmode composed of eigenvalue, $\\lambda$, and eigenvector,\n    $\\phi_g(\\vr)$. The coefficients in \\eref{eq:flux_expansion},\n    \\eref{eq:source_expansion}, and \\eref{eq:leakage_expansion} are not\n    desired directly, but must be solved in order to obtain the quantity of\n    interest. It has been previously demonstrated that all coefficients need\n    not be solved simultaneously which allows for the reduction of the\n    dimensionality of the problem. The odd and even coefficients can be solved\n    separately as a result of the five solution equations selected\n    \\cite{gehinThesis}.\n    \n    \\citeauthor{qe2paper} then show that the number of coefficients can be\n    further reduced as the odd coefficients can be expressed in terms of\n    each other with similar results for the even coefficients. That is,\n    instead of solving for $a_{g,u,1}$ and $a_{g,u,3}$, a new coefficient is\n    introduced: $a_{g,u,1-3}$. Similarly, $a_{g,u,2-4}$ becomes a solution\n    variable. This is an important and novel step of the reviewed work as the\n    solution of \\gls{nem} coefficients represents the bulk of the\n    computational time and the number of coefficients required for solving the\n    \\gls{nem} equations has been reduced \\cite{qe2paper}.\n\n    Finally, the \\gls{nem} equations are solved to obtain currents, scalar\n    fluxes, $a_{g,u,1-3}$, and $a_{g,u,2-4}$. The resulting solution vector,\n    $\\vPhi_g$, can be written \n    \\begin{equation}\n      \\label{eq:solution_vector}\n      \\vPhi_g =\n      \\begin{pmatrix}\n        \\current_{g,x,+} \\\\\n        \\current_{g,y,+} \\\\\n        \\vspace{8pt}\n        \\current_{g,z,+} \\\\\n        \\overline{\\phi_g} \\\\\n        a_{g,x,1-3} \\\\\n        a_{g,y,1-3} \\\\\n        a_{g,z,1-3} \\\\\n        a_{g,x,2-4} \\\\\n        a_{g,y,2-4} \\\\\n        a_{g,z,2-4}\n      \\end{pmatrix}\n    \\end{equation}\n    and the total number of solving variables is $10 \\times N \\times G$ where\n    $N$ is the total number of nodes and $G$ is the total number of energy\n    groups. Note that the \\gls{nem} coefficients and neutron current must be\n    solved in each spatial direction. Typically, solving for the \\gls{nem}\n    coefficients themselves is not preferred as the values themselves are not\n    quantities of interest.  The preferred \\gls{cmfd} implementation computes\n    a modified diffusion coefficient, $\\dtilde$, and will be discussed in\n    \\sref{sec:cmfd_formulation}.\n\n  \\subsection{\\glsentrylong{jfnk} Theory and Inexact Newton Condition}\n    \\label{sec:jfnk_theory}\n\n    The \\gls{jfnk} method begins with Newton's method. Newton's method provides\n    a framework to find the root of a residual function as $\\residual(\\vx^*) =\n    \\vzero$ where $\\vx^*$ is a root of the residual function. It is first\n    necessary to construct a residual function based on the \\gls{nem} equations.\n    \\citeauthor{qe2paper} propose a residual function that contains the residual\n    of  the \\gls{nem} solution, $\\vPhi_g$, and the absolute change in the\n    fundamental eigenvalue, $\\lambda$, during the Newton iteration. This differs\n    from the residual function proposed by \\citeauthor{gill_azmy} but the new\n    form may be preferable as it directly contains information about the\n    fundamental eigenvalue, $\\lambda$.\n    \n    The $m^{th}$ Newton step can be described \n    \\begin{equation}\n      \\label{eq:newton_step}\n      \\jacobian (\\vx^m) \\cdot \\step^m = - \\residual(\\vx^m)\n    \\end{equation}\n    where $\\jacobian(\\vx^m)$ is the Jacobian of $\\residual(\\vx^m)$ and \n    $\\step^m$ is the Newton step. Then, the Newton step proceeds as\n    \\begin{equation}\n      \\vx^{m+1} = \\vx^{m} + \\step^{m}.\n    \\end{equation}\n\n    For the choice of residual function made by \\citeauthor{qe2paper}, an \n    analytic Jacobian is not simple to compute. Therefore, a finite difference\n    approximation is used to estimate the Jacobian. In fact, the Jacobian itself\n    is not needed as the Newton step in \\eref{eq:newton_step} will be solved\n    with a Krylov method. All that is needed is the finite difference\n    Jacobian-vector product which is equivalent to a directional derivative. The\n    directional derivative can be written\n    \\begin{equation}\n      \\label{eq:dirder}\n      \\jacobian(\\vx^m) \\cdot \\vv \\approx \\frac{\\residual(\\vx^m + \\epsilon \\vv) - \n        \\residual(\\vx^m)}{\\epsilon}\n    \\end{equation}\n    where $\\vv$ is the direction and $\\epsilon$ is the finite difference step\n    size. Typically, $\\epsilon$ is on the order of the square-root of machine\n    precision, $\\sqrt{\\epsilon_{mach}} \\approx 10^{-8}$\n    \\cite{qe2paper,gill_azmy,textbookkelley}. Since the Jacobian has been\n    replaced by a directional derivative, the method is termed Jacobian-Free.\n\n    As previously mentioned, the Newton step in \\eref{eq:newton_step} is solved\n    using a Krylov method as\n    \\begin{equation}\n      \\label{eq:inexact_newton_condition}\n      \\| \\residual(\\vx^m) + \\jacobian(\\vx^m) \\cdot \\step^m \\| \\le \n        \\eta_m \\| \\residual(\\vx^m) \\|\n    \\end{equation}\n    where the tolerance $\\eta_m$ is referred to as the forcing term.\n    \\citeauthor{qe2paper} investigated solving\n    \\eref{eq:inexact_newton_condition} using \\gls{gmres} and \\gls{bicgstab}\n    Krylov methods and determined that \\gls{bicgstab} performed preferably.\n    \\eref{eq:inexact_newton_condition} is termed the inexact Newton condition.\n    It is known that the choice of forcing term, $\\eta_m$, can significantly\n    effect the convergence rate of the \\gls{jfnk} method \\cite{textbookkelley}.\n    Essentially, it is undesirable to ``over-solve''\n    \\eref{eq:inexact_newton_condition}, especially during the initial Newton\n    iterations.\n\n    The Eisenstat-Walker forcing term is a standard choice for $\\eta_m$ and has\n    been shown to work well \\cite{qe2paper,gill_azmy}. In both the work by\n    \\citeauthor{qe2paper} and the work by \\citeauthor{gill_azmy}, the authors\n    perform a study to determine a preferable choice of forcing term. The\n    authors all determine that the Eisenstat-Walker forcing term is ideal.\n    However, $\\eta_m = 10^{-1}$ provides equally well and sometimes better\n    results \\cite{qe2paper,gill_azmy,jfnk_wielandt,ma784notes}. These results \n    indicate that both the Eisenstat-Walker forcing term and $\\eta_m = 10^{-1}$\n    perform similarly and such a study is unnecessary in the future.\n\n  \\subsection{Choice of Physics-Based Preconditioner}\n\n    The inexact Newton condition (discussed in\n    \\sref{sec:jfnk_theory}) is solved iteratively with a Krylov solver.\n    The wise choice of preconditioner can significantly reduce the number of\n    Krylov iterations required to solve a linear system. It can be shown that\n    if one preconditions a matrix with its inverse, the Krylov method will\n    converge in one iteration \\cite{textbookkelley}. While computing the\n    matrix inverse would defeat the purpose of the Krylov method, this result\n    indicates that the preconditioning operator is selected to approximate the\n    matrix inverse.\n\n    \\citeauthor{qe2paper} investigate only left-preconditioning. The \n    left-preconditioned form of the inexact Newton condition can be written\n    \\begin{equation}\n      \\label{eq:left_precondition}\n      \\| \\mm_L^{-1} \\residual(\\vx^m) + \\mm_L^{-1} \\left( \\jacobian(\\vx^m)\n        \\cdot \\step^m \\right) \\| \\le \\eta_m \\| \\mm_L^{-1} \\residual(\\vx^m) \\|\n    \\end{equation}\n    where $\\mm_L$ is the left-preconditioning operator. Note that in\n    \\eref{eq:left_precondition}, the residual that is reduced during a Krylov\n    iteration is not directly related to the residual $\\residual(\\vx^m)$.\n    Typically, this is not a problem. Right-preconditioning can also be\n    considered but is not investigated in the proposed implementation.\n    \\citeauthor{gill_azmy} investigate both left- and right-preconditioning.\n\n    An extensive review of the choice of preconditioner in \\gls{jfnk}\n    solutions to the multigroup neutron diffusion equation has been presented\n    elsewhere \\cite{gill_azmy}. It is expected that the results of the\n    preconditioner study for the multigroup neutron diffusion equation should\n    be applicable to the \\gls{nem} equations. Preconditioners investigated\n    include the diffusion operator, incomplete Cholesky factorization, the\n    diffusion-fission operator, and preconditioning with a few \\glspl{pi}. The\n    results of the preconditioner study indicates that preconditioning with\n    approximately five \\glspl{pi} provided the fastest convergence of the\n    \\gls{jfnk} iterations. The incomplete Cholesky preconditioner provided\n    similar convergence rate but requires additional and expensive matrix\n    calculations. A \\gls{pi} preconditioner was also investigated in work by\n    \\citeauthor{jfnk_wielandt} and similar performance was reported\n    \\cite{jfnk_wielandt}.\n\n    The use of a \\gls{pi} preconditioner was not investigated by\n    \\citeauthor{qe2paper}. Instead, the authors designed a new preconditioner\n    based on the data available during the \\gls{nem} iterations. Special\n    attention is also paid to ensure the preconditioner can be solved using\n    the \\gls{tdma} and \\gls{adi} methods. These methods are among the fastest\n    numerical matrix solution techniques available. The authors incorporate\n    information in the preconditioner from the \\gls{nem} equations,\n    group-to-group scattering, and transverse leakage contributions. The\n    construction of the preconditioner appears to be computationally\n    expensive. Unfortunately, \\citeauthor{qe2paper} do not compare their\n    preconditioner to any other preconditioner or even a case without a\n    preconditioner. Therefore, it is impossible to determine the relative\n    computational efficiency of this preconditioning method.\n\n  \\subsection{Convergence Rate Consideration}\n\n    The $q$-quadratic convergence rate of the \\gls{jfnk} method is what makes it\n    desirable to implement. Therefore, it is important to compare the\n    convergence behavior of the \\gls{jfnk} method to the traditional \\gls{pi}\n    method.\n\n    \\subsubsection{Convergence of \\glsentrylong{pi} Method}\n      \\label{sec:dominance_ratio}\n\n      The convergence behavior of the \\gls{pi} method is known and studied well \n      \\cite{nakamura,gehinThesis,my_ms_thesis}. The convergence rate of the\n      \\gls{pi} method is determined by the first and second largest eigenvalues\n      of the equations of interest (either the multigroup neutron diffusion\n      equation or \\gls{nem} equations). It can be shown that each iteration of\n      the \\gls{pi} method reduces the error by a multiple termed the dominance\n      ratio, $d$, defined as\n      \\begin{equation}\n        \\label{eq:dominance_ratio}\n        d = \\frac{\\lambda_1}{\\lambda_0}\n      \\end{equation}\n      where $\\lambda_0 = \\lambda$ is the fundamental eigenvalue and $\\lambda_1$\n      is the next largest eigenvalue \\cite{my_ms_thesis}. The \\gls{pi} method\n      converges linearly and the dominance ratio is the leading coefficient in \n      the convergence behavior. For the multigroup neutron diffusion and\n      \\gls{nem} equations, $d$ is guaranteed to be less than one and smaller\n      values of $d$ result in faster convergence \\cite{nakamura}. For typical\n      reactor simulations, $d > 0.9$ and often $d > 0.95$ implying convergence\n      is slow, often requiring hundreds of iterations.\n\n      The typical approach to address the challenge of large dominance ratios is\n      the \\gls{ws}~\\cite{gehinThesis}. Briefly, the \\gls{ws} subtracts a portion\n      of the fission source from both sides of the equation. It can be shown\n      that the dominance ratio is decreased \\textit{significantly} such that $d\n      \\approx 0.5$ may be expected. It is common for the \\gls{ws} to speedup \n      the solution \\gls{pi} method by a factor of three or more. This will be\n      discussed more in \\sref{sec:wielandt_shift}.\n\n    \\subsubsection{Convergence of Newton Method}\n\n      When the iterate in the \\gls{jfnk} method, $\\vx^m$, is far from the\n      solution, $\\vx^*$, the method converges $q$-superlinearly. As the\n      iteration approaches the solution, it achieves $q$-quadratic convergence\n      \\cite{textbookkelley}.\n\n      It has been demonstrated that the dominance ratio of the multigroup\n      neutron diffusion equation has little effect on the convergence rate when\n      the equations are solved using the \\gls{jfnk} method \\cite{gill_azmy}.\n      This is expected as the convergence rate of the \\gls{jfnk} method is not\n      related to the eigenvalues of the operator but is related to the\n      properties of the Jacobian including its Lipschitz continuity\n      \\cite{textbookkelley}. These results indicate that the \\gls{ws} would have\n      little to no effect on the \\gls{jfnk} method. However,\n      \\citeauthor{qe2paper} indicate in their concluding remarks that they\n      expect the \\gls{ws} to ``improve the efficiency further'' and this is\n      inaccurate~\\cite{qe2paper}.\n", "meta": {"hexsha": "ef24b1764f86ac04cf3172e3f2c75365d06159d2", "size": 17926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_summary.tex", "max_stars_repo_name": "wcdawn/WilliamDawn-QE2", "max_stars_repo_head_hexsha": "da790b3bca756652ae97e8f9b0d3d83e13a163ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-30T15:17:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-30T15:17:59.000Z", "max_issues_repo_path": "sec_summary.tex", "max_issues_repo_name": "wcdawn/WilliamDawn-QE2", "max_issues_repo_head_hexsha": "da790b3bca756652ae97e8f9b0d3d83e13a163ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sec_summary.tex", "max_forks_repo_name": "wcdawn/WilliamDawn-QE2", "max_forks_repo_head_hexsha": "da790b3bca756652ae97e8f9b0d3d83e13a163ec", "max_forks_repo_licenses": ["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.4863221884, "max_line_length": 83, "alphanum_fraction": 0.7046747741, "num_tokens": 4846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6190020731688249}}
{"text": "\\chapter{A quick theoretical background}\n\\label{chap:theoreticalbackground}\n\nIn this chapter we introduce briefly some essential terminology for supervised learning. Clearly, a complete mathematical treatment of the field is beyond the scope of this manual, thus we go only briefly over most of the introduced ideas. We refer to any reference textbook for an in-depth treatment.\\cite{alpaydin2004introduction,Friedman2009,Mohri2012}\n\n\\section{The supervised learning problem}\n\nThe starting point in supervised learning is a set $S$, called a \\textit{dataset}, composed of $N$ pairs of the form:\n\n\\begin{equation}\nS = \\left\\{ x_i, y_i \\right\\}_{i=1}^N\n\\label{eq:dataset}\n\\end{equation}\n\n\\noindent where $x \\in \\mathcal{X}$ and $y \\in \\mathcal{Y}$. $\\mathcal{X}$ and $\\mathcal{Y}$ are called the \\textit{input} and \\textit{output} spaces, respectively.  We call a particular choice of $\\mathcal{Y}$ a \\textit{task}, partly for historical reasons with respect to previous versions of the toolbox. We list the input and output types currently supported by Lynx in Table \\ref{tab:basicinputs} and Table \\ref{tab:basictasks}, respectively. Although we have currently focused on real-valued input patterns, nothing prevents the toolbox from being extended to more complex situations, such as graphs, sequences, and so on.\n\nWe suppose that points in the two spaces are linked by an unknown probabilistic relationship, of which we only know the $N$ samples in $S$. Each sample is also called an \\textit{example}, while each element $x \\in \\mathcal{X}$ is sometimes referred to as a \\textit{pattern}.\n\nInformally, the goal of supervised learning is finding a suitable function $f: \\mathcal{X} \\rightarrow \\mathcal{Y}$ such that, given any new sampling $(x, y)$ of the unknown process, minimizes the expected error between $f(x)$ and $y$. Formally, a \\textit{learning algorithm} $\\mathcal{A}$ can be defined as a mapping between the space $\\mathcal{S}$ of all possible datasets and a given \\textit{hypothesis} of the unknown relation:\n\n\\begin{equation}\n\\mathcal{A}(S) : \\mathcal{S} \\rightarrow \\mathcal{H}\n\\label{eq:learningalgorithm}\n\\end{equation}\n\n\\noindent where $\\mathcal{H}$ is called the \\textit{hypothesis space}, or \\textit{model space}. The notion of error is instead formalized by defining a \\textit{loss} function of the form:\n\n\\begin{equation}\nL(S, f) :  \\mathcal{S} \\times \\mathcal{H} \\rightarrow \\R\n\\label{eq:lossfunction}\n\\end{equation}\n\n\\noindent An example of Eq. (\\ref{eq:lossfunction}) is the \\textit{Mean-Squared Error} (MSE) given by:\n\n\\[\nL(S, f) = \\sum_{(x,y) \\in S}(f(x) - y)^2\n\\]\n\n\\noindent In this framework, different learning algorithms differentiate themselves on the choice of the model space, or in the way in which a single hypothesis is extracted from $\\mathcal{H}$ given a dataset. It is also possible to compute the performance of an algorithm in term of more complex measures, such as confusion matrices, ROC curves, correlation coefficients, and so on. In this case, we will talk more generally about \\textit{performance measures}.\n%\n\\ra{1.2}\n\\begin{center}\n\\begin{table}[t]\n{\\centering\\hfill{}\n\t\\begin{tabular}{p{0.25\\columnwidth}p{0.6\\columnwidth}}\n\t\t\\toprule\n\t\tName & Description \\\\ \n\t\t\\midrule\n\t\tReal-valued vector & $\\vect{x} \\in \\R^d$, each element is a \\textit{feature} of the pattern  \\\\\n\t\tKernel vector &  $\\vect{x} \\in \\R^n$, corresponds to a vector of similarities with respect to $n$ other patterns \\\\\n\t\tTime-series & $\\vect{x} \\in \\R^n$, each element is the sample of a univariate time-series \\\\\n\t\t\\bottomrule\n\t\\end{tabular}}\n\t\\hfill{}\n\t\\caption{Summary of inputs defined in the toolbox.}\n\t\\label{tab:basicinputs}\n\\end{table}\n\\end{center}\n\n\\ra{1.2}\n\\begin{center}\n\\begin{table}[t]\n\t{\\centering\\hfill{}\n\t\t\\begin{tabular}{p{0.35\\columnwidth}p{0.5\\columnwidth}}\n\t\t\t\\toprule\n\t\t\tName & Description \\\\ \n\t\t\t\\midrule\n\t\t\tRegression & $y \\in \\R$  \\\\\n\t\t\tBinary classification & $y \\in \\left\\{-1,+1\\right\\}$  \\\\\n\t\t\tMulticlass classification & $y \\in \\left\\{1,\\dots,M\\right\\}$, where $M$ is the number of classes  \\\\\n\t\t\tMultilabel classification & $\\vect{y} \\in \\left\\{-1,+1\\right\\}^L$, where $L$ is the number of binary labels associated to every pattern \\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}}\n\t\t\\hfill{}\n\t\t\\caption{Summary of outputs (tasks) defined in the toolbox.}\n\t\t\\label{tab:basictasks}\n\t\\end{table}\n\\end{center}\n\t%\n\\vspace{-5em}\nAn extension of this basic framework that we have implemented inside Lynx is the \\textit{semi-supervised} learning (SSL) framework.\\cite{chapelle2006semi} In SSL, we suppose having available an additional unlabeled dataset of $M$ input patterns $U = \\left\\{ x_i \\right\\}_{i=1}^M$. An SSL algorithm uses this additional information trying to improve its own accuracy. Formally, if we denote by $\\mathcal{U}$ the space of all possible unlabeled datasets, an SSL algorithm $\\mathcal{A}_{\\mbox{\\scriptsize SSL}}$ is a mapping of the form:\n\n\\begin{equation}\n\\mathcal{A}_{\\mbox{\\scriptsize SSL}}(S,U): \\mathcal{S} \\times \\mathcal{U} \\rightarrow \\mathcal{H}\n\\label{eq:ssl}\n\\end{equation}\n\n\\noindent where the difference with Eq. \\eqref{eq:learningalgorithm} is the presence of the additional input $U$.\n\n\\section{Some additional terminology}\n\nWe call an \\textit{experiment} the test of a particular learning algorithm on a dataset. For a realistic workflow, refer to Fig. \\ref{fig:workflow}. The dataset, before being used, is processed by one (or more) \\textit{preprocessors}. A typical example of preprocessor is the \\textit{Principal Component Analysis} (PCA). The dataset is not used all for training, but it is partitioned in a \\textit{training set} and a \\textit{testing set}. The way in which data is subdivided is called a \\textit{partitioning strategy}. A partitioning strategy can also define multiple splits for a single dataset (e.g., k-fold cross-validation procedures): in this case, each split is called a \\textit{fold}. Finally, in Fig. \\ref{fig:workflow} the learning algorithm is encapsulated inside a generic ``\\textit{wrapper}'' object, that we define to be any method performing some additional optimization over the training procedure or the resulting model. This rather general definition includes techniques for optimizing the parameters of the algorithm, selecting a suitable subset of features, or training an ensemble of classifiers \\cite{alpaydin2004introduction}.\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[scale=0.6]{./images/Disegno3}\n\\caption{Workflow of a single experiment}\n\\label{fig:workflow}\n\\end{figure}", "meta": {"hexsha": "a98a2a2273a232bd896cbd47ae20556b11781ce8", "size": 6497, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/Manual Source Code/chapters/chapter1.tex", "max_stars_repo_name": "ispamm/Lynx-Toolbox", "max_stars_repo_head_hexsha": "c018ee3dbad4bfc75315732a883ccfd44e15f18a", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-02-02T09:09:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T08:38:25.000Z", "max_issues_repo_path": "manual/Manual Source Code/chapters/chapter1.tex", "max_issues_repo_name": "ispamm/Lynx-Toolbox", "max_issues_repo_head_hexsha": "c018ee3dbad4bfc75315732a883ccfd44e15f18a", "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": "manual/Manual Source Code/chapters/chapter1.tex", "max_forks_repo_name": "ispamm/Lynx-Toolbox", "max_forks_repo_head_hexsha": "c018ee3dbad4bfc75315732a883ccfd44e15f18a", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-02-02T09:09:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T07:23:32.000Z", "avg_line_length": 65.6262626263, "max_line_length": 1149, "alphanum_fraction": 0.7488071418, "num_tokens": 1806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6190020651555856}}
{"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\nThe following definition of decidability is made for general types, even though we will mostly be interested in the decidabilyt of proposition. The reason will become aparent in a moment, when we show that types with decidable equality are sets. This useful theorem would become trivial if we restricted the notion of decidability to propositions.\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    \\isdecidable(A)\\defeq A+\\neg A.\n  \\end{equation*}\n  Decidable propositions are called \\define{classical}. We will write\n  \\begin{equation*}\n    \\classicalprop_\\UU \\defeq \\sm{P:\\prop_\\UU}\\isdecidable(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}\\label{eg:classical-prop}\n  The types $\\unit$ and $\\emptyt$ are decidable. Indeed, we have\n  \\begin{align*}\n    \\decunit & \\defeq \\inl(\\ttt) & & :\\isdecidable(\\unit) \\\\\n    \\decemptyt & \\defeq \\inr(\\idfunc) & & : \\isdecidable(\\emptyt).\\qedhere\n  \\end{align*}\n  Any type $A$ equipped with a point $a:A$ is decidable.\n\\end{eg}\n\nSince $P$ and $\\neg P$ are mutually exclusive cases, it follows that $\\isdecidable(P)$ is a proposition. Therefore we see that the type of decidable propositions in a universe $\\UU$ form a subtype of the type of all propositions in $\\UU$.\n\n\\begin{lem}\\label{lem:isprop-isdecidable}\n  For any proposition $P$, the type $\\isdecidable(P)$ is a proposition.\n\\end{lem}\n\n\\begin{proof}\n  By \\cref{lem:isprop_eq} it suffices to show that\n  \\begin{equation*}\n    \\prd{t,t':\\isdecidable(P)}t=t.\n  \\end{equation*}\n  We proceed by case analysis on $t$ and $t'$. We have four cases to consider:\n  \\begin{align*}\n    \\inl(p) & =\\inl(p') & \\inr(f) & =\\inl(p') \\\\\n    \\inl(p) & =\\inr(f') & \\inr(f) & =\\inr(f').\n  \\end{align*}\n  We construct these four identifications as follows:\n  \\begin{enumerate}\n  \\item First, we want to show that $\\inl(p)=\\inl(p')$ for any $p,p':P$. We obtain this identification from the fact that $p=p'$, which we have because $P$ is assumed to be a proposition.\n  \\item Next, we want to show that $\\inl(p)=\\inr(f')$ for any $p:P$ and $f':\\neg P$. Since we have contradictory assumptions, we obtain $f'(p):\\emptyt$. We now obtain the desired identification by applying the function $\\emptyt \\to (\\inl(p)=\\inr(f')$.\n  \\item The construction of an identification $\\inr(f)=\\inl(p')$ for $f:\\neg P$ and $p':P$ is similar. We have $f(p'):\\emptyt$, which gives the desired identification via the function $\\emptyt\\to (\\inr(f)=\\inl(p'))$.\n  \\item Finally, we want to show that $\\inr(f)=\\inr(f')$ for $f,f':\\neg P$. The type $\\neg P$ is a proposition, so we have an identification $f=f'$ from which we obtain $\\inr(f)=\\inr(f')$.\\qedhere\n  \\end{enumerate}\n\\end{proof}\n\nWe have seen in \\cref{thm:propositional-extensionality} that the univalence axiom implies propositional extensionality. Recall that propositional extensionality is the property that the map\n\\begin{equation*}\n  (P=Q)\\to (P\\leftrightarrow Q)\n\\end{equation*}\nis an equivalence. We will use this fact here to conclude that $\\classicalprop_\\UU$ is equivalent to $\\bool$.\n\n\\begin{prp}\n  The type of classical propositions in any universe $\\UU$ is equivalent to $\\bool$.%\n  \\index{classical-Prop_U@{$\\classicalprop_\\UU$}!classical-Prop_U bool@{$\\classicalprop_\\UU\\eqvsym\\bool$}}\n\\end{prp}\n\n\\begin{proof}\n  Since the empty type and the unit type are decidable propositions, we have a map $\\varphi:\\bool\\to\\classicalprop_\\UU$ defined by\n  \\begin{align*}\n    \\varphi(\\btrue) & \\defeq (\\unit,\\decunit) \\\\\n    \\varphi(\\bfalse) & \\defeq (\\emptyt,\\decemptyt).\n  \\end{align*}\n  Next, we define a map $\\psi:\\classicalprop_\\UU\\to\\bool$. Let $P$ be a proposition that comes equipped with a term $t:P+\\neg P$. To define a boolean, we proceed by case analysis on $t$. The map $\\psi$ is thus defined by\n  \\begin{align*}\n    \\psi(P,\\inl(p)) & \\defeq \\btrue \\\\\n    \\psi(P,\\inr(f)) & \\defeq \\bfalse.\n  \\end{align*}\n  To see that $\\psi$ is an inverse of $\\varphi$, note that\n  \\begin{align*}\n    \\varphi(\\psi(P,\\inl(p))) & \\jdeq (\\unit,\\decunit) & \\psi(\\varphi(\\btrue)) & \\jdeq \\btrue \\\\\n    \\varphi(\\psi(P,\\inr(f))) & \\jdeq (\\emptyt,\\decemptyt) & \\psi(\\varphi(\\bfalse)) & \\jdeq \\bfalse.\n  \\end{align*}\n  It is therefore immediate that $\\psi$ is a retract of $\\varphi$. However, in order to show that $\\psi$ is a section of $\\varphi$ we still need to show that\n  \\begin{align*}\n    (\\unit,\\decunit) & = (P,\\inl(p)) \\\\\n    (\\emptyt,\\decemptyt) & = (P,\\inr(f)).\n  \\end{align*}\n  Since $\\isdecidable(P)$ is shown to be a proposition in \\cref{lem:isprop-isdecidable}, it suffices to show that\n  \\begin{align*}\n    \\unit & = P & & \\text{if we have }p:P \\\\\n    \\emptyt & = P & & \\text{if we have }f:\\neg P.\n  \\end{align*}\n  In both cases we proceed by propositional extensionality. Therefore we obtain the desired identifications by observing that\n  \\begin{align*}\n    \\unit & \\leftrightarrow P & & \\text{if we have }p:P \\\\\n    \\emptyt & \\leftrightarrow P & & \\text{if we have }f:\\neg P.\\qedhere\n  \\end{align*}\n\\end{proof}\n\nWe will now study the concept of decidable equality.\n\n\\begin{defn}\n  We say that a type $A$ has \\define{decidable equality} if the identity type $x=y$ is decidable for every $x,y:A$. Types with decidable equality are also called \\define{discrete}.\n\\end{defn}\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\n\\begin{cor}\n  Equality on the natural numbers is decidable.\n\\end{cor}\n\n\\begin{proof}\n  Recall from the proof of \\cref{thm:eq_nat} that the canonical map\n  \\begin{equation*}\n    (m=n)\\simeq \\EqN(m,n)\n  \\end{equation*}\n  is an equivalence. Thus we obtain that $(m=n)$ is decidable from the fact that $\\EqN(m,n)$ is decidable.\n\\end{proof}\n\n\\begin{comment}\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}\\isdecidable(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 $\\Fin(n)$ has decidable equality. \n\\end{cor}\n\\end{comment}\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.\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  Recall from \\cref{ex:dne-dec} that $(A+\\neg A)\\to (\\neg\\neg A\\to A)$ for any type $A$, so we obtain that\n  \\begin{equation*}\n    \\prd{x,y:A}\\neg\\neg(x=y)\\to (x=y).\n  \\end{equation*}\n  Now observe that $\\neg\\neg(x=y)$ is a proposition for each $x,y:A$, and that the relation $x,y\\mapsto\\neg\\neg(x=y)$ is reflexive. Therefore we are in position to apply \\cref{lem:prop_to_id} and we conclude that $A$ is a set.\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\\classicalprop.\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    \\isminimal_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 $\\isminimal_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)}\\isminimal_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)}\\isminimal_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 strong induction principle of \\texorpdfstring{$\\N$}{N}}\n\n\\begin{thm}\n  For any type family $P$ over $\\N$ there an operation\n  \\begin{equation*}\n    \\strongindN : P(\\zeroN)\\to\\Big(\\prd{n:\\N}\\Big(\\prd{m:\\N}(m\\leq n)\\to P(m)\\Big)\\to P(n+1)\\Big)\\to \\Big(\\prd{n:\\N}P(n)\\Big).\n  \\end{equation*}\n  Moreover, the operation $\\strongindN$ comes equipped with identifications\n  \\begin{align*}\n    \\strongindN(p_0,p_S,\\zeroN) & = p_0 \\\\\n    \\strongindN(p_0,p_S,n+1) & = p_S(n,(\\lam{m}\\lam{p}\\strongindN(p_0,p_S,m))),\n  \\end{align*}\n  for any $p_0:P(\\zeroN)$ and $p_S:\\prd{n:\\N}\\Big(\\prd{m:\\N}(m\\leq n)\\to P(m)\\Big)\\to P(n+1)$.\n\\end{thm}\n\n\\begin{proof}\n  Consider\n  \\begin{align*}\n    p_0 & : P(\\zeroN) \\\\\n    p_S & : \\prd{n:\\N}\\Big(\\prd{m:\\N}(m\\leq n)\\to P(m)\\Big)\\to P(n+1)\n  \\end{align*}\n  \n  First, we claim that there is a function\n  \\begin{equation*}\n    \\tilde{p}_0 : \\prd{m:\\N}(m\\leq\\zeroN)\\to P(m)\n  \\end{equation*}\n  that comes equipped with an identification\n  \\begin{equation*}\n    \\tilde{p}_0(\\zeroN,p)=p_0\n  \\end{equation*}\n  for any $p:\\zeroN\\leq\\zeroN$. The fact that we have such a dependent function $\\tilde{p}_0$ follows immediately by induction on $m$ and $p:m\\leq \\zeroN$.\n\n  Next, we claim that there is a function\n  \\begin{equation*}\n    \\tilde{p}_S : \\prd{n:\\N}\\Big(\\prd{m:\\N}(m\\leq n) \\to P(m)\\Big)\\to \\Big(\\prd{m:\\N}(m\\leq n+1)\\to P(m)\\Big)\n  \\end{equation*}\n  equipped with a homotopy\n  \\begin{equation*}\n    \\prd{m:\\N}\\prd{q:m\\leq n}{p:m\\leq n+1} \\tilde{p}_S(n,H,m,p) = H(m,q)\n  \\end{equation*}\n  and an identification\n  \\begin{equation*}\n    \\tilde{p}_S(n,H,n+1,p)=p_S(n,H)\n  \\end{equation*}\n  for every $p:n+1\\leq n+1$.\n\n  Using $\\tilde{p}_0$ and $\\tilde{p}_S$, we obtain by induction on $n$ a function\n  \\begin{equation*}\n    \\tilde{s}:\\prd{n:\\N}\\prd{m:\\N} (m\\leq n)\\to P(m)\n  \\end{equation*}\n  satisfying the computation rules\n  \\begin{align*}\n    \\tilde{s}(\\zeroN) & \\jdeq \\tilde{p}_0 \\\\\n    \\tilde{s}(n+1) & \\jdeq \\tilde{p}_S(n,\\tilde{s}(n)).\n  \\end{align*}\n  Now we define\n  \\begin{equation*}\n    \\strongindN(p_0,p_S,n) \\defeq \\tilde{s}(n,n,\\reflleqN(n)),\n  \\end{equation*}\n  where $\\reflleqN(n):n\\leq n$ is the proof of reflexivity of $\\leq$.\n\n  It remains to show that $\\strongindN$ satisfies the identifications claimed in the statement of the theorem. The identification that computes $\\strongindN$ at $\\zeroN$ is easy to obtain:\n  \\begin{align*}\n    \\strongindN(p_0,p_S,\\zeroN) & \\jdeq \\tilde{s}(\\zeroN,\\zeroN,\\reflleqN(\\zeroN)) \\\\\n                                & \\jdeq \\tilde{p}_{0}(\\zeroN,\\reflleqN) \\\\\n                                & = p_0.\n  \\end{align*}\n  To construct the identification that computes $\\strongindN$ at a successor, we start with a similar computation:\n  \\begin{align*}\n    \\strongindN(p_0,p_S,n+1) & \\jdeq \\tilde{s}(n+1,n+1,\\reflleqN(n+1)) \\\\\n                                   & \\jdeq \\tilde{p}_S(n,\\tilde{s}(n),n+1,\\reflleqN(n+1)) \\\\\n    & = p_S(n,\\tilde{s}(n))\n  \\end{align*}\n  Thus we see that, in order to show that\n  \\begin{equation*}\n    p_S(n,\\tilde{s}(n))=p_S(n,(\\lam{m}\\lam{p}\\tilde{s}(m,m,\\reflleqN(m)))),\n  \\end{equation*}\n  we need to prove that\n  \\begin{equation*}\n    \\tilde{s}(n)=\\lam{m}\\lam{p}\\tilde{s}(m,m,\\reflleqN(m)).\n  \\end{equation*}\n  Here we apply function extensionality, so it suffices to show that\n  \\begin{equation*}\n    \\tilde{s}(n,m,p)=\\tilde{s}(m,m,\\reflleqN(m))\n  \\end{equation*}\n  for every $m:\\N$ and $p:m\\leq n$. We proceed by induction on $n:\\N$. The base case is trivial. For the inductive step, we note that\n  \\begin{align*}\n    \\tilde{s}(n+1,m,p)=\\tilde{p}_S(n,\\tilde{s}(n),m,p)=\\begin{cases}\\tilde{s}(n,m,p) & \\text{if }m\\leq n \\\\\n    p_S(n,\\tilde{s}(n)) & \\text{if }m=n+1.\\end{cases}\n  \\end{align*}\n  Therefore it follows by the inductive hypothesis that\n  \\begin{equation*}\n    \\tilde{s}(n+1,m,p)=\\tilde{s}(m,m,\\reflleqN(m))\n  \\end{equation*}\n  if $m\\leq n$ holds. In the remaining case, where $m=n+1$, note that we have\n  \\begin{align*}\n    \\tilde{s}(\\succN,\\succN,\\reflleqN(\\succN)) & = \\tilde{p}(n,\\tilde{s}(n),n+1,\\reflleqN(n+1)) \\\\\n    & = p_S(n,\\tilde{s}(n)).\n  \\end{align*}\n  Therefore we see that we also have an identification\n  \\begin{equation*}\n    \\tilde{s}(n+1,m,p)=\\tilde{s}(m,m,\\reflleqN(m))\n  \\end{equation*}\n  when $m=n+1$. This completes the proof of the strong induction principle for $\\N$.\n\\end{proof}\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    \\isbounded_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    \\ismaximal_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    \\maximum_P:\\Big(\\sm{n:\\N}P(n)\\Big)\\to\\Big(\\sm{n:\\N}{p:P(n)}\\ismaximal_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 Euclidean algorithm}\n\nIt was immediate from our definition of the greatest common divisor of $a$ and $b$ that it indeed divides both $a$ and $b$, and that it is the greatest such number. However, as a program that is supposed to \\emph{compute} the greatest common divisor of $a$ and $b$ it performs rather poorly: it checks for every $n$ from $1$ until either $a$ or $b$ whether it is a divisor of both $a$ and $b$, and only then it gives as output the largest common divisor that it has found. In this section we give a new definition of an operation\n\\begin{equation*}\n  \\gcdeuclid:\\N \\to (\\N \\to \\N)\n\\end{equation*}\nfollowing Euclid's algorithm, with the opposite qualities: it will compute rather quicky a value for $\\gcdeuclid(a,b)$, but it will be left as something to show that this value is indeed the greatest common divisor of $a$ and $b$.\n\n\\begin{defn}\n  We define a binary operation\n  \\begin{equation*}\n    \\gcdeuclid:\\N \\to (\\N\\to\\N).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{proof}\n  We will define the operation $\\gcdeuclid$ with the \\emph{strong} induction principle for $\\N$, which was given as \\cref{ex:strong-induction}. Thus it suffices to construct a function $\\N\\to\\N$, which will provide the values for $\\gcdeuclid(\\zeroN)$, and a function\n  \\begin{equation*}\n    h_a:\\Big(\\prd{x:\\N}(x\\leq a) \\to \\N\\to\\N\\Big)\\to (\\N\\to\\N),\n  \\end{equation*}\n  for every $a:\\N$, which will provide the values for $\\gcdeuclid(a+1)$.\n\n  In the base case, we simply define\n  \\begin{equation*}\n    \\gcdeuclid(\\zeroN)\\defeq\\idfunc.\n  \\end{equation*}\n  For the inductive step, consider a family of maps $F_x:\\N\\to\\N$ indexed by $x\\leq a$. We think of $F_x(b)$ as the value for $\\gcdeuclid(x,b)$, so our assumption of having such a family of maps $F_x$ is really the assumption that $\\gcdeuclid(x,b)$ is defined for every $x\\leq a$. Our goal is to construct a map\n  \\begin{equation*}\n    \\gcdeuclid(a+1):\\N\\to\\N\n  \\end{equation*}\n  We proceed by strong induction on $b:\\N$. In the base case, we define\n  \\begin{equation*}\n    \\gcdeuclid(a+1,\\zeroN)\\defeq a+1.\n  \\end{equation*}\n  For the inductive step, assume that we have a number $G_y:\\N$ for every $y\\leq b$. Observe that $(b\\leq a)+(a<b)$ holds for any $b:B$, see \\cref{ex:order_N}. Thus we can proceed by case analysis to define\n  \\begin{equation*}\n    h_a(F,b+1)\\defeq\n    \\begin{cases}\n      F_{(a+1)-(b+1)}(b+1) & \\text{if }b\\leq a\\\\\n      G_{(b+1)-(a+1)} & \\text{if }a<b.\n    \\end{cases}\n  \\end{equation*}\n  This completes the inductive step, and hence we obtain a binary operation\n  $\\gcdeuclid$ that satisfies\n  \\begin{align*}\n    \\gcdeuclid(\\zeroN,b) & \\jdeq b \\\\\n    \\gcdeuclid(a+1,\\zeroN) & \\jdeq a+1 \\\\\n    \\gcdeuclid(a+1,b+1) & \\jdeq \\gcdeuclid((a+1)-(b+1),b+1) & & \\text{if }b\\leq a.\\\\\n    \\gcdeuclid(succN(a),b+1) & \\jdeq \\gcdeuclid(a+1,(b+1)-(a+1)) & & \\text{if }a<b.\\qedhere            \n  \\end{align*}\n\\end{proof}\n\n\\begin{prp}\n  For each $a,b:\\N$, the number $\\gcdeuclid(a,b)$ is the greatest common divisor of $a$ and $b$.\n\\end{prp}\n\n\n\\subsection{The trial division primality test}\n\n\\begin{thm}\n  For any $n:\\N$, the proposition $\\isprime(n)$ is decidable.\n\\end{thm}\n\nIt is important to note that, even when we prove that a type such as $\\isprime(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\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}\\isprime(p)\\times (n\\leq p).\n  \\end{equation*}\n  Note that the number $n!+1$ is relatively prime to any number $m\\leq n$. Therefore the primes in its prime factorization must all be larger than $n$. Thus, the function that assigns to $n$ the least prime factor of $n!+1$ shows that for any $n:\\N$ there is a prime number $p$ that is larger than $n$.\n\\end{proof}\n\n\\begin{cor}\n  There is a function\n  \\begin{equation*}\n    \\primetype : \\N \\to \\sm{p:\\N}\\isprime(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\n\\begin{exercises}\n  \\exercise Show that for any $f:\\Fin(m)\\to\\Fin(n)$ and any $i:\\Fin(n)$, the type $\\fib{f}{i}$ is decidable.\n  \\exercise Consider a decidable type $P(i)$ indexed by $i:\\Fin(n)$.\n  \\begin{subexenum}\n  \\item Show that the type\n    \\begin{equation*}\n      \\prd{i:\\Fin(n)}P(i)\n    \\end{equation*}\n    is decidable.\n  \\item Show that the type\n    \\begin{equation*}\n      \\sm{i:\\Fin(n)}P(i)\n    \\end{equation*}\n    is decidable.\n  \\end{subexenum}\n  \\exercise\n  \\begin{subexenum}\n  \\item Show that $\\N$ and $\\bool$ have decidable equality. Hint: to show that $\\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  \\exercise Define the prime-counting function $\\pi:\\N\\to\\N$.\n  \\exercise (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  \\exercise For any $k:\\Z$, define a function $i\\mapsto i+k \\mod n$ of type $\\Fin(n)\\to\\Fin(n)$. Show that this function is an equivalence.\n  \\exercise For any $k:\\Z$, define a function $i\\mapsto i\\cdot k \\mod n$ of type $\\Fin(n)\\to\\Fin(n)$. Show that this function is an equivalence if and only if $\\gcd(n,k)=1$.\n  \\exercise Show that\n  \\begin{equation*}\n    \\sum_{i=0}^n \\binom{n-i}{i}=F_{n+1}\n  \\end{equation*}\n  \\exercise Show that if $2^n-1$ is prime, then $n$ is prime.\n  \\exercise Prove Fermat's little theorem.\n  \\exercise Extend the definition of the greatest common divisor to all integers.\n  \\exercise Show that\n  \\begin{equation*}\n    (\\Fin(m)\\simeq\\Fin(n))\\leftrightarrow(m=n).\n  \\end{equation*}\n  \\exercise Show that $\\N$ satisfies \\define{ordinal induction}, i.e., construct for any type family $P$ over $\\N$ a function of type\n  \\begin{equation*}\n    \\ordindN : \\Big(\\prd{k:\\N} \\Big(\\prd{m:\\N} (m< k) \\to P(m)\\Big)\\to P(k)\\Big) \\to \\prd{n:\\N}P(n).\n  \\end{equation*}\n  Moreover, prove that\n  \\begin{equation*}\n    \\ordindN(h,n)=h(n,\\lam{m}\\lam{p}\\ordindN(h,m))\n  \\end{equation*}\n  for any $n:\\N$ and any $h:\\prd{k:\\N}\\Big(\\prd{m:\\N}(m<k)\\to P(m)\\Big)\\to P(k)$.\n  \\exercise\n  \\begin{subexenum}\n  \\item Show that if $A$ and $B$ have decidable equality, then so do the types $A+B$ and $A\\times B$.\n  \\item Show that $\\Z$ and $\\Fin(n)$ have decidable equality, for every $n:\\N$.\n  \\end{subexenum}\n  \\exercise Let $P:\\N\\to\\classicalprop$ be a decidable subset of $\\N$.\n  \\begin{subexenum}\n  \\item Show that $\\sm{m:\\N}{p:P(m)}\\isminimal_P(m,p)$ is a proposition.\n  \\item Show that the map\n    \\begin{equation*}\n      \\Big(\\sm{n:\\N}P(n)\\Big)\\to\\Big(\\sm{m:\\N}{p:P(m)}\\isminimal_P(m,p)\\Big)\n    \\end{equation*}\n    is a propositional truncation.\n  \\end{subexenum}\n  \\exercise Suppose that $A:I\\to \\UU$ is a type family over a set $I$ with decidable equality. Show that\n  \\begin{equation*}\n    \\Big(\\prd{i:I}\\iscontr(A_i)\\Big)\\leftrightarrow \\iscontr\\Big(\\prd{i:I}A_i\\Big).\n  \\end{equation*}\n\\end{exercises}\n", "meta": {"hexsha": "b33caaea9c50dad398e4dde6ec1559162b9b017c", "size": 27950, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/number-theory.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/number-theory.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/number-theory.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.4732965009, "max_line_length": 529, "alphanum_fraction": 0.6782468694, "num_tokens": 9247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6190020626692798}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 8}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\n\\section{Irreducible Markov chains and regular Markov chains}\n\\begin{definition}\nA Markov chain is called an \\textbf{irreducible chain} if it is possible to go from every state to every state (not necessarily in one move).\n\\end{definition}\n\n\\begin{remark}\nNote that absorbing chains are NOT irreducible chains.\n\\end{remark}\n\n\\begin{definition}\nA Markov chain is called a \\textbf{regular chain} if some power of the transition matrix has only positive elements. \n\\end{definition}\n\n\\begin{remark}\nNote that regular chains are irreducible chains. But the converse is NOT true as the following example shows.\n\\end{remark}\n\n\\begin{example}\nLet the transition matrix of a Markov chain be defined by\n\\begin{equation*}\n    P = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}.\n\\end{equation*}\nIf we start from state 1, then next step we jump to state 2. If we start from state 2, then we jump to state 1. In other words, we are flipping between two states after each step. So the chain is irreducible. But \n\\begin{equation*}\n    P^{2n} = \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}, \\quad \n    P^{2n+1} = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}.\n\\end{equation*}\nSo the chain is not regular.\n\\end{example}\n\n\\begin{remark}\nAny transition matrix that has no zeros determines a regular Markov chain. However, it is possible for a regular Markov chain to have a transition matrix that has zeros.\n\\end{remark}\n\nWe shall discuss two important theorems relating to regular chains. But before, we will use the following two lemmas.\n\n\\begin{lemma}\n\\label{lemma:8.1}\nSuppose $X$ is a random variable with finite number of outcomes, with the greatest being $x_{max}$ and the least being $x_{min}$. Then we have \n\\begin{equation*}\n    \\Exp(X) \\leq x_{max}, \\quad \\Exp(X) \\geq x_{min}.\n\\end{equation*}\n\\end{lemma}\n\n\\begin{proof}\nAssume $X$ has $n$ outcomes, and let $f(x_i) = \\Prob(X = x_i)$, then we have\n\\begin{gather*}\n    \\Exp(X) = \\sum_{i=1}^n x_i f(x_i) \\geq \\sum_{i=1}^n x_{min} f(x_i) = x_{min}, \\\\\n    \\Exp(X) = \\sum_{i=1}^n x_i f(x_i) \\leq \\sum_{i=1}^n x_{max} f(x_i) = x_{max}.\n\\end{gather*}\n\\end{proof}\n\n\\begin{lemma}\n\\label{lemma:8.2}\nSuppose a transition matrix $P$ only has positive entries and the smallest entry is $d>0$. Consider a vector $y$. Denote its maximum value as $M_0$ and its minimum value as $m_0$. Now consider the product $Py$. Denote its maximum value as $M_1$ and its minimum value as $m_1$. Then we have\n\\begin{equation*}\n    M_1 - m_1 \\leq (1-2d) (M_0 - m_0).\n\\end{equation*}\n\\end{lemma}\n\n\\begin{proof}\nNote that $P$ is a transition matrix. So each row of $P$ sums up to $1$. From lemma \\ref{lemma:8.1}, we note that each entry in the vector $Py$ is a weighted average of the entries in $y$, therefore, we have\n\\begin{equation}\n    \\label{eq:8.1}\n    \\tag{8-1}\n    M_1 \\leq M_0, \\quad m_1 \\geq m_0.\n\\end{equation}\nThe largest weighted average that could be obtained in the present case would occur if all but one of the entries of $y$ have value $M_0$ and one entry has value $m_0$, and this one small entry is weightedby the smallest possible weight, namely $d$. In this case, the weighted average would equal $m_0 d + M_0(1-d)$.\n%\\begin{equation*}\n%    m_0 d + M_0(1-d).\n%\\end{equation*}\nSimilarly, the smallest possible weighted average equals $M_0 d + m_0(1-d)$.\n%\\begin{equation*}\n%    M_0 d + m_0(1-d).\n%\\end{equation*}\nTherefore, we have \n%Since \\eqref{eq:8.1} is true for any $y$, we can take some particular form of $y$ to find the best and worst outcome of $Py$. First let $y = \\begin{bmatrix} M_0 & \\cdots & m_0 & \\cdots & M_0 \\end{bmatrix}$ such that $y$ only one entry being $m_0$ and such entry captures the minimum entry $d$ of $P$. Then we can show that \n\\begin{equation}\n    \\label{eq:8.2}\n    \\tag{8-2}\n    M_1 \\leq m_0 d + M_0(1-d),\n\\end{equation}\n%Similarly, by letting $y = \\begin{bmatrix} m_0 & \\cdots & M_0 & \\cdots & m_0 \\end{bmatrix}$ such that $y$ only one entry being $M_0$ and such entry captures the minimum entry $d$ of $P$, we can obtain \n\\begin{equation}\n    \\label{eq:8.3}\n    \\tag{8-3}\n    m_1 \\geq M_0 d + m_0(1-d). \n\\end{equation}\n\\eqref{eq:8.2}-\\eqref{eq:8.3} yields \n\\begin{equation*}\n    M_1 - m_1 \\leq (1-2d) (M_0 - m_0).\n\\end{equation*}\n\\end{proof}\n\nNow we give two important theorems.\n\n\\begin{theorem}[Fundamental limit theorem for regular chains]\n\\label{thm:8.1}\nLet $P$ be the transition matrix for a regular chain. Then, as $n \\to \\infty$, the powers $P^n$ approach a limiting matrix $W$ with all rows the \\textbf{same} vector $w$. The vector $w$ is a strictly positive probability vector (\\ie., the components are all \\textbf{positive} and they sum to one).\n\\end{theorem}\n\n\\begin{proof}\nWe consider an arbitrary vector $y$, and denote the maximum entry of $P^n y$ as $M_n$ and the minimum entry of $P^n y$ as $m_n$. From lemma 1, we must have \n\\begin{equation*}\n    M_n \\leq M_{n-1}, \\quad m_n \\geq m_{n+1}.\n\\end{equation*}\nWriting all these inequality from 1 to $n$ gives\n\\begin{equation*}\n    M_0 \\geq M_1 \\geq \\cdots \\geq M_n \\geq m_n \\geq \\cdots \\geq m_1 \\geq m_0.\n\\end{equation*}\nTherefore $\\{M_n\\}$ is a decreasing sequence bounded below and $\\{m_n\\}$ is an increasing sequence bounded above. From sequence theory we know that $\\{ M_n \\}$ and $\\{m_n\\}$ must converge. Let\n\\begin{equation*}\n    M = \\lim_{n\\to\\infty} M_n, \\quad m = \\lim_{n\\to\\infty} m_n.\n\\end{equation*}\nFrom Lemma \\ref{lemma:8.2} we have \n\\begin{equation}\n    \\label{eq:8.4}\n    \\tag{8-4}\n    M_n - m_n \\leq (1-2d)^n (M_0 - m_0).\n\\end{equation}\nOn the other hand, since $d$ is the minimum entry of $P$, we must have $0 < d \\leq \\frac{1}{2}$, which gives $0 \\leq 1-2d < 1$. Thus from \\eqref{eq:8.4} we have \n\\begin{equation}\n    \\label{eq:8.5}\n    \\tag{8-5}\n    \\lim_{n\\to\\infty} (M_n - m_n) = 0 \\quad \\Rightarrow \\quad \n    M=m \\quad \\forall \\ y.\n\\end{equation}\nWe choose a particular form of $y$ such that $y = e_j$ with $j$th entry being 1 and others being 0. Then $P^n y$ gives the $j$th column of $P^n$. Using \\eqref{eq:8.5}, we have\n\\begin{equation*}\n    \\lim_{n\\to\\infty} P^n y = \\alpha \\1 \\quad \\text{for some $\\alpha > 0$},\n\\end{equation*}\nwhich shows the $j$th column has the same entries.\n\nThus, by letting $y = e_j$, $1\\leq j \\leq n$, we conclude that each column of $P^n$ has the same entries. This finishes the proof.\n\\end{proof}\n\nThe $ij$th entry of $P^n$, $p^{(n)}_{ij}$, is the probability that the process will be in state $s_j$ after $n$ steps if it starts in state $s_i$. If we denote the common row of $W$ by $w$, then Theorem \\ref{thm:8.1} states that the probability of being in $s_j$ in the long run is approximately $w_j$, the $j$th entry of $w$, and is independent of the starting state. \n\n\\begin{theorem}\n\\label{thm:8.2}\nLet $P$ be a regular transition matrix, let\n\\begin{equation*}\n    W = \\lim_{n\\to\\infty} P^n,\n\\end{equation*}\nand let $w$ be the common row of $W$. Then\n\\begin{enumerate}[(a)]\n    \\item \n    $wP = w$, which means $w$ is a left eigenvector of $P$ with eigenvalue 1, and any row vector $v$ such that $vP = v$ is a constant multiple of $w$.\n    \n    \\item \n    $P\\1 = \\1$, which means $\\1$ is an eigenvector of $P$ with eigenvalue 1, and any column vector $x$ such that $Px = x$ is a multiple of $\\1$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nTo prove part (a), we note that from Theorem \\ref{thm:8.1}, \n\\begin{equation*}\n    \\lim_{n\\to\\infty} P^n = W.\n\\end{equation*}\nThus\n\\begin{equation*}\n    \\lim_{n\\to\\infty} P^{n+1} = P^n P = W P.\n\\end{equation*}\nBut $\\lim_{n\\to\\infty} P^{n+1} = W$, and so $W = WP$ and $w = wP$.\n\nLet $v$ be any vector with $vP = v$. Then $v = vP^n$, and passing to the limit, $v = vW$. Let $r$ be the sum of the components of $v$, \\ie, $r = \\sum_{i=1}^n v_i$. Then it is easily checked that $vW = rw$. So, $v = rw$.\n\nTo prove part (b), assume that $x = Px$. Then $x = P^n x$, and again passing to the limit, $x = Wx$. Since all rows of $W$ are the same, the components of $Wx$ are all equal, so $x$ is a multiple of $\\1$.\n\\end{proof}\n\nNote that an immediate consequence of Theorem \\ref{thm:8.2} is the fact that there is only one \\textbf{probability vector} $v$ such that $vP = v$, which is $v = w$. The probability vector $v$ is the vector such that $\\sum_{i=1}^n = 1$.\n\n\\begin{remark}\nComputing $W$ is equivalent to computing the left eigenvector of $P$ with eigenvalue 1. It is equivalent to compute the right eigenvector of $P^T$ with eigenvalue 1.\n\\end{remark}\n\n\\begin{example}\nLet $P$ be a transition matrix such that \n\\begin{equation*}\n    P = \\begin{bmatrix}  \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{4} & \\frac{3}{4} \\end{bmatrix}.\n\\end{equation*}\nCompute $W = \\lim_{n\\to\\infty} P^n$. \n\nThis is equivalent to compute $P^T x = x$. Note that $x$ is a probability vector, so $\\1^T x = 1$.\n\\begin{equation*}\n    P^T x = x \\quad \\Rightarrow \\quad \\begin{cases} \\frac{1}{2} x_1 + \\frac{1}{4}x_2 = x_1 \\\\ x_1+x_2 = 1 \\end{cases} \\quad \\Rightarrow \\quad\n    \\begin{cases} x_1 = \\frac{1}{3} \\\\ x_2 = \\frac{2}{3} \\end{cases}\n\\end{equation*}\nTherefore $w = [\\frac{1}{3} \\ \\frac{2}{3}]$, and $W = \\begin{bmatrix} w \\\\ w \\end{bmatrix} = \\begin{bmatrix} \\frac{1}{3} & \\frac{2}{3} \\\\ \\frac{1}{3} & \\frac{2}{3} \\end{bmatrix}$.\n\\end{example}\n\n\\section{Fixed vectors}\n\\begin{definition}\nA row vector $w$ with the property $wP = w$ is called a \\textbf{fixed row vector} for $P$. Similarly, a column vector $x$ such that $Px = x$ is called a \\textbf{fixed column vector} for $P$.\n\\end{definition}\n\nThus, the common row of $W$ is the unique vector $w$ which is both a fixed row vector for $P$ and a probability vector. Theorem \\ref{thm:8.2} shows that any fixed row vector for $P$ is a multiple of $w$ and any fixed column vector for $P$ is a constant vector. One can also state the above definition in terms of eigenvalues and eigenvectors. A fixed row vector is a left eigenvector of the matrix $P$ corresponding to the eigenvalue 1. A similar statement can be made about fixed column vectors.\n\nThe following theorem generalizes Theorem \\ref{thm:8.1} to the case where the starting state is itself\ndetermined by a probability vector.\n\n\\begin{theorem}\n\\label{thm:8.3}\nLet $P$ be the transition matrix for a regular chain and $v$ an arbitrary probability vector. Then\n\\begin{equation*}\n    \\lim_{n\\to\\infty} vP^n = w,\n\\end{equation*}\nwhere $w$ is the unique fixed probability vector for $P$.\n\\end{theorem}\n\n\\begin{proof}\nBy Theorem \\ref{thm:8.1},\n\\begin{equation*}\n    \\lim_{n\\to\\infty} P^n = W.\n\\end{equation*}\nHence \n\\begin{equation*}\n    \\lim_{n\\to\\infty} vP^n = vW.\n\\end{equation*}\nBut the entries in $v$ sum to 1, and each row of $W$ equals $w$. From these statements, it is easy to check that\n\\begin{equation*}\n    vW = w.\n\\end{equation*}\n\\end{proof}\n\n\\begin{remark}\nIf we start a Markov chain with initial probabilities given by $v$, then the probability vector $v P^n$ gives the probabilities of being in the various states after $n$ steps. Theorem \\ref{thm:8.3} then establishes the fact that, even in this more general class of processes, the probability of being in $s_j$ approaches $w_j$.\n\\end{remark}\n\n\\begin{remark}\nTheorem \\ref{thm:8.3} tells that \\textbf{regular chains} always equilibriate to $w$.\n\\end{remark}\n\n\\begin{newnotion}{Question}\nDoes the result holds for irreducible chains?\n\\end{newnotion}\n\\textbf{NOT} true for irreducible chains. The following is a counterexample.\n\\begin{example}\nLet \n\\begin{equation*}\n    P = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}.\n\\end{equation*}\nIf we calculate the left eigenvector, we can obtain \n\\begin{equation*}\n    w = \\begin{bmatrix} \\frac{1}{2} & \\frac{1}{2} \\end{bmatrix}.\n\\end{equation*}\nBut if we start from $(1,0)$ or $(0,1)$, we will never goes to this equilibrium.\n\\end{example}\n\n\\begin{definition}\nThe \\textbf{period} $d(i)$ of a state $i$ is defined by $d(i) = \\gcd\\{n : P_{ii}(n) > 0\\}$, the greatest common divisor of the epochs at which return is possible. We call $i$ \\textbf{periodic} if $d(i) > 1$ and \\textbf{aperiodic} if $d(i) = 1$.\n\\end{definition}\n\n\\begin{newnotion}{Important}\nAperiodic + irreducible means all results so for regular chains hold.\n\\end{newnotion}\n\n\\begin{remark}\nAperiodic + irreducible $\\Leftrightarrow$ regular for finite outcome Markov chains.\n\\end{remark}\n\n\\end{document}", "meta": {"hexsha": "4f4dd8965133f91761dd67aa560d6a1f8bbd6954", "size": 12412, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_8.tex", "max_stars_repo_name": "yuhan-zhao/freshman21-v1", "max_stars_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_drafts/MATH 2901/notes_8.tex", "max_issues_repo_name": "yuhan-zhao/freshman21-v1", "max_issues_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_drafts/MATH 2901/notes_8.tex", "max_forks_repo_name": "yuhan-zhao/freshman21-v1", "max_forks_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_forks_repo_licenses": ["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.299270073, "max_line_length": 496, "alphanum_fraction": 0.6834514985, "num_tokens": 4276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.724870288063979, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.6189759818661772}}
{"text": "%!TEX root = ../CombinatoricsNotes.tex\n\n \\section{Representing Sets and Sperner Systems.}\n \\lect{1}{11}\n% \\marginnote{Lecture 2: Monday, January 11, 2016. }\n\\marginnote{We begin our systematic investigation into extremal combinatorics.}\nLet's start with some definitions. \n\\begin{itemize}[]\n\\item[Power set:] \nLet $X$ be a finite set with cardinality $|X| = n$. The \\defn{power set} is $\\P(X)$, the collection of subsets of $X$. $|\\P(X)|= 2^n$.\n\\item[$r$-element subsets:] \nThe set $X^{(r)}$ is the collection of all $r$-element subsets of $X$. The cardinality $|X^{(r)}| = {n\\choose r}$.\n\\item[Set system:]\nA \\defn{set system} $\\F \\subset \\P(X)$ on $X$ is a collection of subsets of $X$. For example, $\\F = \\{\\emptyset, \\{1\\}, \\{1,2\\}, \\{2,3\\},\\{3\\}\\}$ is a set system on $\\{1,2,3\\}$.\n\\item[$r$-graph:]\nIf $\\F\\subset X^{(r)}$, then we call $\\F$ an $r$-graph or \\defn{hypergraph}. 2-graphs are just ordinary graphs: $\\F\\subset X^{(2)}$ can be thought of as a graph with vertex set $X$, edge set $\\F$.\n\\end{itemize}\nWe'll also frequently use the notation $[n] = \\{1,2,\\dotsc,n\\}$.\n\n\\newthought{Now, given a set system} $\\{A_1,A_2,\\dotsc,A_m\\}$, we want to ``reduce'' the sets such that distinct sets remain distinct.\nThat is, we want to find $S\\subset X$ as small as possible such that $\\{A_1\\cap S, A_2\\cap S, \\dotsc, A_m\\cap S\\}$ are all distinct. \\marginnote{Note that $S$ acts by deleting elements from our base set $X$.}\nLet's start with two sets, $\\{A_1,A_2\\}$. We want $S$ as small as possible such that $A_1\\cap S\\neq A_2\\cap S$. In this case, we can simply choose $S$ to be a singleton of an element which is in one set but not the other\\sidenote{which always exists because $A_1\\neq A_2$.}.\nIf we use our example earlier, $\\{\\emptyset, \\{1\\}, \\{1,2\\}, \\{2,3\\},\\{3\\}\\}$ on $[3]$, we cannot remove any; $|\\P([2])| = 4$ and we have five elements.\nIf our set system is $\\{\\emptyset, \\{1,2\\}, \\{2,3\\},\\{3\\}\\}$ on $[3]$, then we may remove $1$; that is, $S = \\{2,3\\}$.\nThis motivates a question: How small can $S$ be as a function of $m$?\n\\begin{theorem}\nLet $\\F = \\{A_1,A_2,\\dotsc,A_m\\}$ be a set system. Then there exists $S$, $|S|\\leq m-1$ such that $A_1\\cap S$, $A_2\\cap S$, \\ldots, $A_m\\cap S$ are all distinct.\n\\end{theorem}\n\\begin{remark}\nThe bound is tight: the set system $\\{\\emptyset, \\{1\\}, \\{2\\}, \\dotsc, \\{m-1\\}\\}$ has the property that if we remove any element, we collapse two sets to the empty set.\n\\end{remark}\n\\begin{proof}\t\nChoose $S$ as small as possible such that $A_1\\cap S$, $A_2\\cap S$, \\ldots, $A_m\\cap S$ are all distinct, and assume that $|S| \\geq m$.\nLet $A_i' = A_i\\cap S$. By the minimality of $S$ for every $x\\in S$ there exists $i,j\\in[m]$ such that $A_i'\\setminus \\{x\\} = A_j'\\setminus \\{x\\}$, with $i\\neq j$.\n\nNow, construct a graph  on the vertex set $[m]$ as follows. For each $x\\in S$, choose one pair $i$ and $j$ ($i\\neq j$) such that $A_i'\\setminus \\{x\\} = A_j'\\setminus \\{x\\}$, and join $i$ and $j$ by an edge\\sidenote[][-2cm]{$A_i'\\setminus \\{x\\} = A_j'\\setminus \\{x\\}$ is equivalent to $A_i \\symd A_j  =\\{x\\}$, where the symmetric difference $X\\symd Y = (X\\cup Y)\\setminus (X\\cap Y)$.\nBecause of this, we will make a new edge each time: if $x,y\\in S$ yielded the same edge, then $\\{x\\}=A_i \\symd A_j = \\{y\\} $.}. \nThis graph has $m$ verticies and $|S|\\geq m$ edges, so it contains a cycle\\sidenote{Easy to see by picture; draw $m-1$ edges on $m$ vertices, and then if you don't have a cycle yet, you have a line, and no matter how you place the last edge, you get a cycle.}. Without loss of generality, assume there is a cycle on verticies $1,2,\\dotsc,k$ in order. Then there exists distinct $x_1,x_2,\\dotsc,x_k\\in S$ such that $A_1\\symd A_2 = \\{x_1\\}$, $A_2\\symd A_3 = \\{x_2\\}$, \\ldots, $A_{k-1}\\symd A_k = \\{x_{k-1}\\}$, and $A_k \\symd A_1 = \\{x_k\\}$. \n\nWe can take the symmetric difference of all of them:\n\\[\n\\emptyset = (A_1\\symd A_2) \\symd (A_2 \\symd A_3) \\symd \\dotsm \\symd (A_k \\symd A_1) = \\{x_1,x_2,\\dotsc, x_k\\}\n\\]\n\\marginnote{Note the symmetric difference is commutative and associative.}\nOn the left, we have two of each set, so we can regroup and commute to obtain the empty set, using $A\\symd A = \\emptyset$. On the right, we have the symmetric difference of distinct singletons, which is just the union. This is a contradiction, so our minimal $S$ must have $|S|\\leq m-1$.\n\\end{proof}\nBefore we continue finding ways to represent sets, we'll need some graph theoretic tools. First, some definitions.\n% \\begin{definition}\n\\begin{itemize}[]\n\t\\item[Bipartite:]  \nA graph $G$ is \\defn{bipartite}[graph!bipartite] with bipartition $(V_1,V_2)$ if every edge of $G$ contains one vertex of $V_1$ and one vertex of $V_2$. \n\n\\item[Matching: ]A collection of edges $M$ of $G$ is a \\defn{matching}[graph!matching] of $V_1$ into $V_2$ if for every $v\\in V_1$, $M$ contains exactly one edge containing $v$, and for $v\\in V_2$, at most one edge. This is illustrated in \\cref{fig:bipartite_matching}.\n\n\\begin{marginfigure}\n\\begin{center}\n\\begin{tikzpicture}[color=black]\n\n\\node (rect) at (0,0)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt,label=left:$V_2$]{};\n\n\\node (rect2) at (0,1.5)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt,label=left:$V_1$]{};\n\n\\pgfmathsetseed{2}\n% \\def\\z{rand}\n\\foreach \\x in {1,...,6}\n{\n\\filldraw (rand*1.4,rand*.4) circle (0.4pt) node(a\\x){};\n\\filldraw (rand*1.4,1.5+rand*.4) circle (0.4pt) node(b\\x){};\n}\n\n%some extra nodes in the bottom one\n\\foreach \\x in {1,...,6}\n{\n\\filldraw (rand*1.4,rand*.4) circle (0.4pt);\n}\n\n\\foreach \\x in {1,...,6}\n{\n% \\ifthenelse{\\x > 1}{\\draw[dashed] (a\\x) -- (u)}{};\n% \\foreach \\y in {1,...,\\x}\n% {\n\\draw (a\\x) -- (b\\x);\n% }\n}\n\n\\end{tikzpicture}\n\\end{center}\n\\caption{Think of elements of $V_1$ as job applicants, and $V_2$ as positions. Then a matching of $V_1$ into $V_2$ is an arrangement so that every job applicant has a position, but some positions could be unfilled.  \\label{fig:bipartite_matching}}\n\\end{marginfigure}\n\n\n\\item[Neighborhood:] For $S\\subset V_1$, define the \\defn{neighborhood}[graph!neighborhood] $N(S)$ as the set of verticies adjacent to at least one vertex in $S$.\n\\end{itemize}\nThe following result\\sidenote{\\cite{Hallmarriage}} connects these ideas.\n\\begin{theorem}[Hall's marriage theorem]\nLet $G$ be a bipartite graph with bipartition $(V_1,V_2)$. Then $G$ contains a matching of $V_1$ into $V_2$ if and only if \n\\begin{equation}\t \\label{eq:Hall_condition}\n|N(S)| \\geq |S| \\text{ for every } S\\subset V_1. \\tag{Hall's condition}\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\t\nThe condition is necessary because you need to have enough verticies available in $N(S)$ for elements of $S$ to match into. We will prove sufficiency by induction on $|V_1|$. The base case is immediate. For the induction step, we will split into two cases.\n\\begin{enumerate}[{Case }1:]\n\t\\item For every $S\\subset V_1$ with $S\\neq \\emptyset$ and $S\\neq V_1$, we have that $|N(S)| > |S|$. \n% \\end{enumerate}\nIn this case, choose  $v\\in V_1$; then $v$ has a $w\\in V_2$ adjacent to it, because $|N(\\{v\\})|> |\\{v\\}|=1$. Apply the induction hypothesis to $G \\setminus \\{v,w\\}$.\n\nWe then just need to check Hall's condition on $G' =G \\setminus \\{v,w\\}$. For every $S\\subset V_1 \\setminus\\{v\\}$, we have \n\\[\t\n |N'(S)| \\geq |N(S)| -1 \\geq |S|,\n\\]\n where $N'$ is the neighborhood with respect to $G'$. The first inequality holds because we removed at most one neighbor by removing $w$. The second inequality holds from our assumption in this case. Then the induction hypothesis yields a matching on $V_1\\setminus \\{v\\}$ into $V_2\\setminus \\{w\\}$, which we can extend to a matching on $V_1$ into $V_2$ by matching $v$ to $w$.\n% \\begin{enumerate}[{Case }1:]\\setcounter{enumi}{1}\n\\item There exists $S\\subset V_1$ with $S\\neq \\emptyset$ and $S\\neq V_1$, such that $|N(S)| = |S|$. \n% \\end{enumerate}\nBy induction hypothesis,  there exists a matching $M_1$ of $S$ into $N(S)$.\n\n It remains to find a matching from $V_1\\setminus S$ into $V_2 \\setminus N(S)$. By induction hypothesis, it is enough to show that for every $T\\subset V_1\\setminus S$, we have\n\\[\n |N(T)\\cap (V_2 \\setminus N(S))| \\geq |T|.\n\\]\n \\marginnote{Here's the trick.}Since $S\\cup T\\subset V_1$, by assumption, we have Hall's condition\n\\[\n |N(S\\cup T)|\\geq |S\\cup T| = |S| + |T|.\n\\]\n\n We know $N(S\\cup T) = N(S) \\cup N(T) = N(S) \\cup (N(T)\\setminus N(S))$. So $|N(S\\cup T)| = |N(S)| + |N(T)\\setminus N(S)| $. So Hall's condition becomes\n\\[\n |N(T)\\setminus N(S)| \\geq |T|\n\\]\n as desired.\\qedhere\n \\end{enumerate}\n\\end{proof}\n\n\nLet's employ Hall's theorem to represent sets. Let \n\\[\n \\F = \\{A_1,A_2,\\dotsc,A_m\\}\n \\] be a set system.\n% \\begin{definition}\nA \\defn{system of distinct representatives} for $\\F$ is a collection $\\{x_1,\\dotsc,x_m\\}$ of elements such that $x_1,\\dotsc, x_m$ are pairwise distinct, and $x_i \\in A_i$ for $i\\in[m]$.\n% \\end{definition}\nGiven $\\F$, one can consider the bipartite graph $G$ with bipartition $(V_1,V_2)$ such that $V_1 = \\F$ and $V_2= \\bigcup_{i\\in[m]} A_i$. We join $A_i$ to $x$ iff $x\\in A_i$.\nThen a system of distinct representatives for $\\F$ is exactly a matching on $G$ from $V_1$ into $V_2$. Hall's theorem then immediately implies the following result.\n\\begin{corollary}\nA set system $\\F = \\{A_1,\\dotsc,A_m\\}$ has a system of distinct representatives if and only if for every $\\F'\\subset \\F$, \n\\[\n|\\F'| \\leq \\left|\\bigcup_{A\\in \\F'}A\\right|.\n\\]\n\\end{corollary}\n\\newthought{Given a set $X$}, there is a natural bipartite graph and matching which will prove useful.\n\\begin{corollary} \\label{cor:Xr_matching_exists}\nLet $X$ be a set with $|X|=n$. Let $G$ be a bipartite graph with bipartition $(X^{(r)}, X^{(r-1)})$ such that $A\\in X^{(r)}$ is adjacent to $B \\in X^{(r-1)}$ if $B\\subset A$. Then if  $r> n/2$, the graph $G$ has a matching of $X^{(r)}$ into $X^{(r-1)}$.\n\\begin{marginfigure}\n\\begin{center}\n \\begin{tikzcd}[column sep=tiny]\nX^{(3)}  & &\\{1,2,3\\}  \\\\\nX^{(2)} &\\{1,2\\} \\arrow[dash,green]{d}  \\arrow[dash]{rd}& \\{1,3\\} \\arrow[dash]{ld}\\arrow[dash]{d} \\arrow[dash,green]{rd} & \\arrow[dash,green]{ld} \\arrow[dash]{d}\\{2,3\\} \\\\\nX^{(1)} & \\{1\\}  & \\{2\\} &\\{3\\} \\\\\nX^{(0)} & & \\emptyset\n\\end{tikzcd}\n\\end{center}\n\\caption{Example of the graph relation on $G= (X^{(2)}, X^{(3)})$, with a matching highlighted in green.}\n\\end{marginfigure}\n\\end{corollary}\n\\begin{remark}\nThis corollory implicitly shows ${n \\choose r} \\leq {n \\choose r-1}$ if $r> n/2$.\n\\end{remark}\n\\begin{proof}\t\nIt suffices to check \\ref{eq:Hall_condition}. For every $\\A\\subset X^{(r)}$, we want $|N(\\A)| \\geq |\\A|$. Label\n\\[\n\\B:= N(\\A) = \\{B\\in X^{(r-1)}: B\\subset A, \\text{ for some }A\\in \\A\\}.\n\\]\nEvery element of $X^{(r)}$ is incident to $r$ edges of $G$\\sidenote{Each edge corresponds to taking an element away from the set.}. So we have $|\\A|r$ edges leaving $\\A$, ending in $\\B$.\nEvery element of $X^{(r-1)}$ is incident to $n-r+1$ edges of $G$, which can be seen by the fact that there are $n-(r-1)$ possible elements to add to a set $B\\in X^{(r-1)}$ to obtain a superset in $X^{(r)}$. So we have at most $|\\B|(n-r+1)$ edges leaving $\\B$, ending in $\\A$\\sidenote{Since not every edge leaving $\\B$ needs to reach something in $\\A$ (it could reach something in $X^{(r)} \\setminus \\A$), it is only ``at most.''}.\nSo $|\\A|r \\leq |\\B|(n-r+1)$. But by assumption $r \\geq (n-r+1)$, so $|\\B| \\geq |\\A|$ as desired.\n\\end{proof}\n\n\\lect{1}{13}\n% \\marginnote{Lecture 3: Wednesday, January 13, 2016.}\n\nRecall that $\\F\\subset \\P(X)$ is a \\emph{Sperner system} if for all $A,B\\in \\F$, if $A\\leq B$, then $A=B$.\nWe wish to find $\\max |\\F|$ such that $\\F$ is a Sperner system, as a function $|X| = n$. Note that $X^{(r)}$ is always Sperner, and $|X^{(r)}| = {|X| \\choose r}$, which is maximized when $r = \\floor{n/2}$.\n\\begin{theorem}[\\cite{sperner1928}] \\label{thm:sperner}\nIf $\\F\\subset \\P(X)$ is Sperner, then $|\\F| \\leq {n \\choose \\floor{n/2}}$, where $n=|X|$.\n\\end{theorem}\n\\begin{proof}\t\n\\marginnote{A Sperner system is a system of sets such that no two are comparable. A dual notion is a system of sets such that all are comparable. }\nAn ordered collection $(A_1,A_2,\\dotsc, A_k)$ of sets  in $\\P(X)$  is a \\defn{chain} if $A_1\\subsetneqq A_2 \\subsetneqq A_3 \\subsetneqq\\dotsm \\subsetneqq A_k$. \n\\begin{marginfigure}\n\\begin{center}\n \\begin{tikzcd}[column sep=tiny]\nX^{(3)}  & &\\{1,2,3\\} \\arrow[dash]{d}\\arrow[dash]{rd}\\arrow[dash,green]{ld} \\\\\nX^{(2)} &\\{1,2\\} \\arrow[dash,green]{d}  \\arrow[dash]{rd}& \\{1,3\\} \\arrow[dash]{ld}\\arrow[dash]{d} \\arrow[dash,blue]{rd} & \\arrow[dash,red]{ld} \\arrow[dash]{d}\\{2,3\\} \\\\\n\\mathbf{X^{(1)}} & \\mathbf{\\{1\\}} \\arrow[dash,green]{rd} & \\mathbf{\\{2\\}} \\arrow[dash]{d}&\\mathbf{\\{3\\}}\\arrow[dash]{ld} \\\\\nX^{(0)} & & \\emptyset\n\\end{tikzcd}\n\\end{center}\n\\caption{Consider $X^{(1)}$, a natural maximal Sperner system. Note that each element of $X^{(1)}$ can form a distinct chain, such as $\\emptyset \\subsetneqq \\{1\\} \\subsetneqq \\{1,2\\} \\subsetneqq \\{1,2,3\\}$.}\\label{fig:Sperner_chains}\n\\end{marginfigure}\nIt is enough to show that $\\P(X)$ can be partitioned into ${n \\choose \\floor{n/2}}$ chains. Indeed, every Sperner system can contain $\\leq 1$ element from each chain in the partition; see \\cref{fig:Sperner_chains} for an example.\nBetter yet, we partition $\\P(X)$ into chains such that every chain contains an element of $X^{(\\floor{n/2})}$. \n\nLet's begin by partitioning all subsets of $X$ of size $\\geq \\floor{n/2}$.\nWe will first do this inductively starting from $X^{(\\floor{n/2})}$, and extending the partition to $X^{(\\floor{n/2})}\\cup X^{(\\floor{n/2}+1)}\\cup\\dotsm \\cup X^{(k)}$ to $X^{(k+1)}$ using the matching obtained in \\cref{cor:Xr_matching_exists} from $X^{(k)}$ to $X^{(k+1)}$ by adding each element of $X^{(k+1)}$ to the chain of the set it's matched to. Note that are chains are not maximal; some (all but one) truncate before they reach the top, $X^{(n)}$.\nThen we can extend the partition to sets of size $< \\floor{n/2}$ by symmetry.\n\\end{proof}\n\\begin{remark}\nThis proof is instructive and provides the useful technique of partitioning into chains. But we can prove stronger results with slicker proofs.\n\\end{remark}\nSuppose $k< n/2$ and we want to find the maximum size Sperner system such that every set in the system has size $\\leq k$.\nAs one may guess, the maximum size will be $|X^{(k)}| = {n\\choose k}$. To show this, we'll use the following result.\n\\begin{theorem}[Lubell, Meshalkin, Yamamoto, Boll\\'obas, and possibly others, A.K.A. the LYM inequality] \\marginnote{\\cite{LUBELL_LYM,Meshalkin_LYM,yamamoto1954_LYM,Bollab_LYM}}\n\\label{thm:LYM_inequality}\nLet $\\F\\subset \\P(X)$, $|X|=n$ be a Sperner system.\nLet $\\F_k = \\F\\cap X^{(k)}$ be the set of $k$ element sets in $\\F$, and let $f_k = |\\F_k|$. Then\n\\begin{equation}\t\\tag{LYM} \n\\label{eq:LYM}\n\\sum_{k=0}^n \\frac{f_k}{{n\\choose k}} \\leq 1.\n\\end{equation}\n\\end{theorem}\n\\begin{remark}\nWe have\n\\[\n1 \\geq \\sum_{k=0}^n \\frac{f_k}{{n\\choose k}} \\geq \\sum_{k=0}^n \\frac{f_k}{{n\\choose \\floor{n/2}}},\n\\]\nthus\n\\[\n{n\\choose \\floor{n/2}} \\geq \\sum_{k=0}^n f_k = |\\F|\n\\]\nwhich is Sperner's theorem.\n\\end{remark}\n\\begin{proof} Let's assume $X=[n]$ for convenience.\nConsider all maximum chains in $\\P(X)$ and count how many chains an element of $\\F$ belongs to. Each of the maximal chains is of the form $\\emptyset = A_0$, $A_1$, \\ldots, $A_n = X = [n]$, and $|A_i| = i$. So each maximal chain corresponds to an ordering $a_1,a_2,\\dotsc,a_n$ of $[n]$, where $\\{a_i\\} = A_i \\setminus A_{i-1}$, is the element you add to $A_i$ to get the next set in the chain.\n\nThus, there are $n!$ maximal chains (the number of re-orderings of $[n]$). Consider\n$F \\in X^{(k)}$.\nHow many  maximal chains is $F$ in? If $k=0,n$, $F$ is in every chain, so $n!$. If $k=1$, then $F$ is in $(n-1)!$ chains. If $k=2$, then $2!(n-2)!$. In general, $F$ is in $k!(n-k)!$ maximal chains\\sidenote{We choose $k$ to get to the set, then $(n-k)$ to finish the chain.} Each maximal chain contains $\\leq 1$ element of $\\F$. The total number of elements of $\\F$ in all maximum chains is\n\\[\n \\sum_{k=0}^n f_k k!(n-k)!\\leq n!\n\\]\nDividing by $n!$, we obtain the LYM inequality.\n\\end{proof}\n\\begin{remark}\nLet's consider an alternate proof. Let $C$ be a uniformly randomly chosen maximal chain, and consider the expectation value of the number of elements of $C\\cap \\F$. Of course, there is at most 1 element, since $\\F$ is a Sperner system. On the other hand,\n\\begin{align*}\t\n\\E ( | C\\cap \\F|) &=\\sum_{k=0}^n \\E( | C \\cap \\F_k|) = \\sum_{k=0}^n f_k \\cdot (\\text{probability that a set of size $k$ is in $C$})\\\\\n &=  \\sum_{k=0}^n f_k \\cdot \\frac{1}{(\\text{number of sets of size $k$)}} = \\sum_{k=0}^n \\frac{f_k}{{n \\choose k}} \\leq 1.\n\\end{align*}\n\\end{remark}\n\n\nWhen does equality hold in LYM? Certainly when $\\F= X^{(r)}$ for any $r$. We'd like to show this condition is necessary as well, but to do so, we'll first prove a more refined inequality in which equality is easier to check. Then we'll use this to show sufficiency for equality in the LYM inequality.\n\n\\begin{theorem}[Local LYM inequality] \\label{thm:local_LYM}\nLet $\\A\\subset X^{(r)}$, and $|X|=n$. Define\n$\\partial \\A \\subset X^{(r-1)}$\nthe \\defn{shadow} of $A$ by\n\\[\n\\partial \\A := \\{B\\in X^{(r-1)}: B\\supseteq A \\text{ for some }A\\in \\A \\}.\n\\]\nThen\n\\begin{equation}\t\\label{eq:local_LYM} \\tag{Local LYM}\n\\frac{|\\partial \\A|}{{n\\choose r-1}} \\geq \\frac{|\\A|}{{n \\choose r}}\n\\end{equation}\nor equivalently,\n\\[\n r| \\A| \\leq |\\partial \\A| (n-r+1).\n\\]\nMoreover, equality holds if and only if $\\A= \\emptyset$ or $\\A=  X^{(r)}$.\n\\end{theorem}\n\\begin{proof}\t\n\\[\n r|\\A| = | \\{ (B,A): B\\in \\partial A, \\, A\\in \\A, \\, B\\subset A\\}| \\leq |\\partial A| (n-r+1)\n \\] as seen in \\cref{cor:Xr_matching_exists}.\nIf equality holds, then $\\A$ contains all supersets in $X^{(r)}$ of all sets in $\\partial A$. \n\n\n\\begin{marginfigure}\n\\begin{center}\n\\begin{tikzcd}[column sep=tiny]\n\\A & \\{x_1,\\dotsc,x_r\\} \\arrow[dash]{d} \\arrow[dash]{rd} & \\arrow[dash]{ld} \\\\\n\\partial \\A & \\{x_2,\\dotsc,x_n\\} & \\{x_1,x_2,\\dotsc,x_n\\}\n\\end{tikzcd}\n\\end{center}\n\\caption{If $\\A$ contains all supersets in the $X^{(r)}$ layer of sets in the shadow $\\partial \\A$, then as long as $\\A\\neq \\emptyset$, it must contain every set; here, for example, $\\A$ has to include the endpoint of the edge leaving the bottom left vertex. }\n\\end{marginfigure}\n\nConsider the graph as in \\cref{cor:Xr_matching_exists}:  there are no edges from $A\\cup \\partial A$ to the remaining verticies, so since $G$ is connected\\sidenote{as is easy to check},  we have equality in \\eqref{eq:local_LYM}.\n\\end{proof}\n\n\\begin{theorem}\nThe equality in the LYM inequality \\eqref{eq:LYM} holds iff $\\F = X^{(r)}$ for some $r$.\n\\end{theorem}\n\\begin{proof}\t\nInductively define $G_n = \\F_n$, and for $k < n$, $G_k  = \\partial G_{k+1} \\cup \\F_k$. \\marginnote{$G_k$ is the set of all $k$-element sets which are subsets of sets in $\\F$.}\n\nLet $\\phi_k = \\frac{f_k}{{n \\choose k}}$ be the proportion of sets of $\\F$ in $X^{(k)}$. Similarly, set $\\gamma_k = \\frac{|G_k|}{{n\\choose k}}$. By the local LYM,\n\\[\n\\frac{|\\partial G_{k+1}|}{{n\\choose k}} \\geq \\frac{|G_{k+1}|}{{n\\choose k+1}} = \\gamma_{k+1}\n\\]\nSo,\n\\[\n\\gamma_k = \\frac{|\\partial G_{k+1} \\cup \\F_k|}{{n\\choose k}} = \\frac{|\\partial G_{k+1}|}{{n\\choose k}} + \\frac{|\\F_k|}{{n\\choose k}} \\geq  \\gamma_{k+1} + \\phi_k\n\\]\nwhere we are using that $\\F$ is Sperner, so that $\\partial G_{k+1}$ is disjoint from $\\F_k$. Thus, we have $\\gamma_k \\geq \\gamma_{k+1} + \\phi_k$, with equality iff $\\gamma_{k+1} = 1$ or $\\gamma_{k+1} = 0$. \\marginnote{Since that is when we have equality in \\cref{eq:local_LYM}.}\n\nNote $\\gamma_n = \\phi_n$. Then\n\\begin{gather*}\t\n\\gamma_{n-1} \\geq \\gamma_n + \\phi_{n-1} = \\phi_n + \\phi_{n-1}\\\\\n\\gamma_{n-2} \\geq \\gamma_{n-1} + \\phi_{n-2} = \\phi_n + \\phi_{n-1} + \\phi_{n-2}\\\\\n\\text{etc.}\\\\\n\\gamma_k \\geq \\phi_n + \\phi_{n-1} + \\dotsm + \\phi_k.\n\\end{gather*}\nHence, $1 \\geq \\gamma_0 \\geq \\phi_n + \\phi_{n-1} + \\dotsb + \\phi_0$. This is the LYM inequality. But equality holds if $\\gamma_k = \\gamma_{k+1} +\\phi_k$ for each $k$, i.e. $\\gamma_{k+1} = 1$ or $\\gamma_{k+1} = 0$ for each $k$. Assuming we have equality, we use that $\\gamma_k$ is non-increasing with $k$, so there must exist $k_0$ such that $\\gamma_{k_0} = 1$, and $\\gamma_{k_0+1} = 0$ (writing $\\gamma_{n+1} = 0$). Thus, there are no sets in $\\F$ of size at least $k+1$. In other words, $G_{k+1} = \\emptyset$, and $G_k = \\F_k = X^{(k)}$. But then we must have $\\F  = X^{(k)}$ as desired, since $\\F$ may not have any super sets or subsets of $X^{(k)}$, i.e., any other set in $\\P(X)$.\n\\end{proof}\n\\begin{remark}\nThe matchings with $X^{(r)}$ and $X^{(r-1)}$ are the essential objects here in proving the local LYM, and hence LYM and its equality.\n\\end{remark}\n\\begin{exercise}\nProve Sperner's theorem using the original way: partitioning into ${n\\choose \\floor{n/2}}$ chains by induction on $n$ instead of Hall's theorem.\n\\marginnote{This is \\cref{thm:sym_part}.}\n\\end{exercise}\n\n", "meta": {"hexsha": "e4cef54c73cc661aa7d7bc56ebbf7e5edabbbd5c", "size": 20871, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch1_sperner.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/ch1_sperner.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/ch1_sperner.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": 64.2184615385, "max_line_length": 684, "alphanum_fraction": 0.6567006852, "num_tokens": 7741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.6189759791713173}}
{"text": "\\documentclass[11pt,fleqn]{article}\n% \\usepackage{cs70,latexsym,epsf}\n\\usepackage{latexsym,epsf,fleqn}\n\\usepackage{amsmath,amsthm,amsfonts,amssymb}\n\\usepackage{mathtools}\n\\usepackage{array}\n\\usepackage{booktabs}\n\n\\usepackage{geometry}\n\\geometry{\n  a4paper,\n  total={170mm,257mm},\n  left=20mm,\n  top=20mm,\n}\n\n\\newcommand\\Set[2]{\\{\\,#1\\mid#2\\,\\}}\n\\newcommand\\underoverset[3]{\\underset{#1}{\\overset{#2}{#3}}}\n\\newcommand{\\mbf}[1]{\\mbox{{\\bfseries #1}}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\n\\begin{document}\n\n\\section*{CS 70 homework 1 solutions}\n\nYour full name: Joey Yandle\n\\newline\nYour login name: dragon\n\\newline\nHomework 1\n\\newline\nYour section number: 0\n\\newline\nYour list of partners: Galina Vinnik\n\\newline\n\n\\begin{enumerate}\n\\item\nFor each of the following, define proposition\nsymbols for each simple proposition in the argument (for example, $P$ =\n``I will ace this homework''). Then write out the logical form of\nthe argument. If the argument form corresponds to a known inference\nrule, say which it is. If not, show that the proof is correct using\ntruth tables.\n\\begin{enumerate}\n\\item  I will ace this homework and I will have fun doing it.\nTherefore, I will ace this homework.\n\\begin{align}\n  P &= \\text{``I will ace this homework''}\\\\\n  Q &= \\text{``I will have fun doing it''}\\\\\n  P &\\land Q \\implies P\n\\end{align}\n\n$P \\land Q$ implies both $P$ and $Q$, and $P \\implies P$.\n\\begin{align}\n\\therefore P \\land Q \\implies P\\qed\n\\end{align}\n\n\\item It is hotter than 100 degrees today or the pollution is\ndangerous. It is less than 100 degrees today. Therefore, the pollution\nis dangerous.\n\\begin{align}\n  P &= \\text{``It is hotter than 100 degrees today''}\\\\\n  Q &= \\text{``The pollution is dangerous''}\\\\\n  \\neg P &= \\text{``It is less than 100 degrees today''}\\\\\n  Q &= \\text{``The pollution is dangerous''}\\\\\n  (P &\\lor Q) \\land \\neg P \\implies Q\n\\end{align}\n\nWe know that not only is $(P \\lor Q)$ true, but also $P$ is not true, so $Q$ must be true.\n\\begin{align}\n\\therefore (P \\lor Q) \\land \\neg P \\implies Q \\qed\n\\end{align}\n\n(This is ignoring the possibility of the temperature being exactly 100 degrees, in which case it is possible for the pollution to not be dangerous)\n\n\\newpage\n\\item Tina will join a startup next year. Therefore,\nTina will join a startup next year or she will be unemployed.\n\\begin{align}\n  P &= \\text{``Tina will join a startup next year''}\\\\\n  Q &= \\text{``Tina will be unemployed''}\\\\\n  P &\\implies (P \\lor Q)\n\\end{align}\n\n$P \\implies P$, and $(P \\lor Q)$ is true if $P$ or $Q$ is true.\n\\begin{align}\n\\therefore P \\implies (P \\lor Q) \\qed\n\\end{align}\n\n\\item If I work all night on this homework, I will answer all the\nexercises. If I answer all the exercises, I will understand the\nmaterial. Therefore, if I work all night on this homework, I will\nunderstand the material.\n\n\\begin{align}\n  P &= \\text{``I work all night on this homework''}\\\\\n  Q &= \\text{``I will answer all the exercises''}\\\\\n  R &= \\text{``I will understand the material''}\\\\\n  (P &\\implies Q) \\land (Q \\implies R) \\iff P \\implies R\n\\end{align}\n\n$P \\implies Q$, and $Q \\implies R$.  So if $P$ is true, $Q$ is true, and if $Q$ is true then $R$ is true.\n\\begin{align}\n\\therefore P \\implies R\\qed\n\\end{align}\n\\end{enumerate}\n\n\\item\nRecall that $\\N=\\{0,1,\\ldots\\}$ denotes the set of natural numbers,\nand $\\Z=\\{\\ldots,-1,0,1,\\ldots\\}$ denotes the set of integers.\n\\begin{enumerate}\n\\item Define $P(n)$ by\n\\[ P(n) = \\forall m \\in \\N , \\; m<n \\implies\n\\neg (\\exists k \\in \\N , \\; n=mk \\; \\wedge \\; k<n) \\]\nConcisely, for which numbers $n\\in\\N$ is $P(n)$ true?\n\n$m | n \\implies \\exists k \\in \\N \\ni n=mk$, which implies $\\lnot P(n)$.  Therefore $P(n)$ is true when $m<n \\implies m \\nmid n$.  Such numbers are called prime numbers.\n\\begin{align}\n\\therefore P(n)\\;\\text{is true}\\;\\forall n \\in \\mathbb{P}\\qed\n\\end{align}\n\n\\item Rewrite the following in a way that\nremoves all negations (``$\\neg$, $\\ne$'') but remains equivalent.\n\\[ \\forall i . \\; \\neg \\forall j . \\;\n\\neg \\exists k . \\; \n(\\neg \\exists \\ell . \\; f(i,j) \\ne g(k,\\ell)). \\]\n\n$\\forall i,j\\;\\exists k,l \\ni f(i,j) = g(k,\\ell)$\n\n\\item Prove or disprove:\n$\\forall m \\in \\Z . \\; \\exists n \\in \\Z . \\; m \\ge n$.\n\nLet $n = m$.  By reflexion, $m \\ge m$.\n\\begin{align}\n\\therefore \\exists n \\ni m \\ge n\n\\end{align}\n\n\\item Prove or disprove:\n$\\exists m \\in \\Z . \\; \\forall n \\in \\Z . \\; m \\ge n$.\n\nAssume such an $m$ exists.  Let $n = m+1$.  This implies\n\\begin{align}\n  m &\\ge m+1\\\\\n  0 &\\ge 1\n\\end{align}\n\nThis is false, so using proof by contradiction the proposition fails.\n\n\\end{enumerate}\n\n\\newpage\n\\item\nAlice and Bob are playing a game of chess,\nwith Alice to move first.\nIf $x_1,\\dots,x_n$ represents a sequence of possible moves\n(i.e., first Alice will make move $x_1$, then Bob will make move $x_2$,\nand so on),\nwe let $W(x_1,\\dots,x_n)$ denote the proposition that,\nafter this sequence of moves is completed,\nBob is checkmated.\n\\begin{enumerate}\n\\item State using quantifier notation the proposition that Alice\ncan force a checkmate on her second move, no matter how Bob plays.\n\\begin{align}\n\\forall x_2\\;\\exists x_1, x_3 \\ni W(x_1, x_2, x_3) = \\top\n\\end{align}\n\n\\item Alice has many possibilities to choose from on her first move,\nand wants to find one that lets her force a checkmate on her second move.\nState using quantifier notation the proposition that $x_1$\nis \\emph{not} such a move.\n\\begin{align}\n\\forall x_2, x_3\\; W(x_1, x_2, x_3) = \\bot\n\\end{align}\n\n\\end{enumerate}\n\n\\item\nJoan is either a knight or a knave.\nKnights always tell the truth, and only the truth;\nknaves always tell falsehoods, and only falsehoods.\nSomeone asks Joan, ``Are you a knight?''  She replies,\n``If I am a knight then I'll eat my hat.''\n\\begin{enumerate}\n\\item Must Joan eat her hat?\n\\begin{align}\n  P &= \\text{``Joan is a knight''}\\\\\n  Q &= \\text{``Joan will eat hat''}\\\\\n  P &\\implies Q\n\\end{align}\n\nIf Joan is a knight, then she speaks truth, and so by the proposition will eat her hat.  If she is not a knight, then she speaks false, so we must negate her proposition:\n\\begin{align}\n  \\lnot (P &\\implies Q) \\iff (P \\land \\lnot Q)\n\\end{align}\n\nSo if Joan is a knave, then her statement must be false, but if it is false, then she must be a knight.  So Joan cannot be a knave, and thus must eat her hat.\n\n\\item Let's set this up as problem in propositional logic.\nIntroduce the following propositions:\n\\begin{eqnarray}\nP &=& \\text{``Joan is a knight''}\\\\\nQ &=& \\text{``Joan will eat her hat''}.\n\\end{eqnarray}\nTranslate what we're given into propositional logic,\ni.e., re-write the premises in terms of these propositions.\n\\begin{align}\n  P &\\implies (P \\implies Q) \\iff (P \\land Q)\\\\\n  \\lnot P &\\implies \\lnot (P \\implies Q) \\iff (P \\land \\lnot Q)\n\\end{align}\n\n\\item Using proof by enumeration,\nprove that your answer from part (1) follows from the premises\nyou wrote in part (2).\n(No inference rules allowed.)\n\n\\begin{tabular}{cccc}\n  \\toprule\n  $P$ & $Q$ & $P \\land Q$ & $P \\land \\lnot Q$ \\\\\n  \\midrule\n  T & T &      T    &      F          \\\\\n  T & F &      F    &      T          \\\\\n  F & T &      F    &      F          \\\\\n  F & F &      F    &      F          \\\\\n  \\bottomrule\n\\end{tabular}\n\nSo $P \\implies (P \\implies Q)$ is supported by enumeration, while $\\lnot P \\implies \\lnot (P \\implies Q)$ leads to contradiction.  Thus Joan will eat the hat.\n\\end{enumerate}\n\n\\newpage\n\\item\nFor each claim below,\nprove or disprove the claim.\n\\begin{enumerate}\n\\item Every positive integer can be expressed as the sum of two perfect squares. \n(A perfect square is the square of an integer. 0 may be used in the sum.)\n\\begin{align}\n  a \\in \\mathbb{Z} &\\implies \\exists j,k \\in \\Z \\ni a = j^2 + k^2\\\\\n  (a = j^2 + k^2) &\\implies |j|,|k| \\le \\sqrt{a}\n\\end{align}\n\nThis cannot be true for all positive integers, since it is not true for $3$; the only integers $\\le \\sqrt{3}$ are $0$ and $1$, and the max sum of their squares is $2$.\n\\begin{align}\n  \\therefore (j^2 + k^2 < 3)\\;\\forall j,k \\le \\sqrt{3}\n\\end{align}\n\n\\item For all rational numbers $a$ and $b$, $a^b$ is also rational.\n\\begin{align}\n  b \\in \\mathbb{R} &\\implies \\exists j,k \\in \\Z \\ni b = \\frac{j}{k}\\\\\n  k \\nmid j &\\implies a^b = a^{\\frac{j}{k}} = a^j a^{\\frac{1}{k}}\\\\\n  |k| > 1 &\\implies \\exists a \\ni a^{\\frac{1}{k}} \\notin \\mathbb{R}\\;(\\text{e.g.}\\;a \\in \\mathbb{P})\\\\\n  \\therefore \\exists a, b &\\in \\mathbb{R} \\ni a^b \\notin \\mathbb{R}\n\\end{align}\n\n\\end{enumerate}\n\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "982ea4607eb5ad0bf7d63771de511b340db12c42", "size": 8491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs70/homework.tex", "max_stars_repo_name": "xoloki/math", "max_stars_repo_head_hexsha": "503dd8df6543a448e8df04d48de8c9d401e09534", "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": "cs70/homework.tex", "max_issues_repo_name": "xoloki/math", "max_issues_repo_head_hexsha": "503dd8df6543a448e8df04d48de8c9d401e09534", "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": "cs70/homework.tex", "max_forks_repo_name": "xoloki/math", "max_forks_repo_head_hexsha": "503dd8df6543a448e8df04d48de8c9d401e09534", "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.1628787879, "max_line_length": 170, "alphanum_fraction": 0.6661170651, "num_tokens": 2861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.6189759771053045}}
{"text": "\\documentclass{article}\n\\usepackage[hmargin=1in,vmargin=1.5in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{graphicx}\n\\usepackage{subcaption}\n\\usepackage{bm}\n\\newcommand{\\x}{\\bm x}\n\\title{Homework 4}\n\\setcounter{MaxMatrixCols}{20}\n\\author{Xinyi Gu, Songchen Tan}\n\\date{\\today}\n\\begin{document}\n\\maketitle\n\\section{}\nSee the solution in Figure 1.\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth]{1.1.png}\n\\end{figure}\n\\begin{figure}[!ht]\n    \\includegraphics[width=\\textwidth]{1.2.png}\n    \\caption{Solution to Problem 1}\n\\end{figure}\n\n\\section{}\n\\subsection{}\n$$\ns_1+ s_2 + s_3 + ... + s_n = 3*i, \\quad i \\in \\mathbb{Z} \n$$ \ni.e, the sum of the set S is divisible by 3.\n\n\\subsection{}\n\nLet $f(a, b, c, s)$ be the state with the information that $a, b, c$ represent the remaining sum of integers in each group, while using the first $s$ elements in the set $S$. If this is possible, $f=1$, else $f=0$\n\nThe state transition equation would be:\n\n$$\nf(a,b,c,s) = f(a-S[s],b,c,s-1) \\text{ or } f(a,b-S[s],c,s-1) \\text{ or } f(a,b,c-S[s],s-1)\n$$\n\nand the base cases would be $f(0,0,0,0)=1$ and $f(a,b,c,0)=0$ if not all $a,b,c$ equals 0.\n\nWe can obtain the actual partition method when calculating the state transition: mark the dependence of $f(a,b,c,s)$ with $(s,A)$ if it uses $f(a-S[s],b,c,s-1)$, and similarly for set B and C. We collect all marks toward the final solution and we can get the partition method.\n\n\n\\subsection{}\n\nLet $a_i, b_i, c_i, i= 1, ..., n $ denote to position of each number, if $s_i$ is in the subset A, then $a_i = 1, b_i = 0, c_i = 0$, if in B, $a_i = 0, b_i = 1, c_i = 0$, if C, then $a_i = 0, b_i = 0, c_i = 1$\n\nThe integer programming formulation for this problem can be set as:\n\n\\begin{align*}\n    &\\max m\\quad \\\\\n    \\text{s.t.} \\quad& \\sum_ia_i\\ge m, \\sum_ib_i\\ge m, \\sum_ic_i\\ge m  \\\\\n    \\quad & \\sum_ia_i s_i = \\sum_i b_i s_i = \\sum_i c_i s_i = \\frac{1}{3}\\sum_is_i\\\\\n    & a_i+ b_i+ c_i = 1, \\quad i = 1, ... n \\\\\n    & a_i, b_i, c_i \\in \\{0, 1\\}\n\\end{align*}\n\n\n\n\n\\section{}\nWe denote the set defined by the first set, second set and third constraint to be $C_1,C_2,C_3$, and set $0\\le x_{ij}\\le 1$ to be $C_4$. Denoting the feasible set after four kinds of relaxations to be $X_1=C_1\\cap C_2\\cap C_4\\cap\\mathbb Z$, $X_2=C_3\\cap C_4\\cap\\mathbb Z$, $X_3=C_2\\cap C_3\\cap C_4\\cap\\mathbb Z$, and $X_4=C_2\\cap C_4\\cap\\mathbb Z$. Let $\\x=\\{x_{ij}\\}$ $z=\\sum_{ij}c_{ij}x_{ij}$, we have\n\n\\begin{itemize}\n    \\item $Z_{LP}=\\min z$ s.t. $\\x\\in P_{LP}=C_1\\cap C_2\\cap C_3\\cap C_4$;\n    \\item $Z_{D1}=\\min z$ s.t. $\\x\\in P_1=C_3\\cap \\operatorname{CH}(X_1)$;\n    \\item $Z_{D2}=\\min z$ s.t. $\\x\\in P_2=C_1\\cap C_2\\cap \\operatorname{CH}(X_2)$;\n    \\item $Z_{D3}=\\min z$ s.t. $\\x\\in P_3=C_1\\cap \\operatorname{CH}(X_3)$;\n    \\item $Z_{D4}=\\min z$ s.t. $\\x\\in P_4=C_1\\cap C_3\\cap \\operatorname{CH}(X_4)$;\n    \\item $Z_{IP}=\\min z$ s.t. $\\x\\in P_{IP}=C_1\\cap C_2\\cap C_3\\cap C_4\\cap\\mathbb Z$;\n\\end{itemize}\n\nWe first give a lemma on the property of convex hulls: if $A$ is a convex set and $B$ is an arbitrary set, then $\\operatorname{CH}(A\\cap B)$ is a subset of $A\\cap\\operatorname{CH}(B)$. This is because for any point in the former set, there exists a convex combination of points in $A\\cap B$ that yields this point; and therefore this point is a member of both $\\operatorname{CH}(B)$ and $\\operatorname{CH}(A)$. Since $A=\\operatorname{CH}(A)$, the point is a member of $A\\cap\\operatorname{CH}(B)$.\n\n\nUsing this lemma, we get $C_1\\cap C_2\\cap \\operatorname{CH}(X_2)\\subseteq C_1\\cap C_2\\cap C_3\\cap \\operatorname{CH}(C_4\\cap\\mathbb Z)=C_1\\cap C_2\\cap C_3\\cap C_4$, therefore $P_2\\subseteq P_{LP}$, so $Z_{LP}\\le Z_{D2}$. Similarly, we can trivially get $Z_{D2}\\le Z_{D3}\\le Z_{IP}$.\n\nWhen the third constraint is relaxed, the problem can be reformulated as a network flow problem, and the integrality of such problems implies that solving each subproblem $Z_{D1}(p)$ in $\\operatorname{CH}(X_1)$ is equivalent to solving in $C_1\\cap C_2\\cap C_4$, therefore we have $Z_{D1}=Z_{LP}$. Similarly $Z_{D4}=Z_{LP}$. Assembling all the relationship we got so far gives us the desired order.\n\n\\section{}\n\\subsection{}\n\\begin{align*}\n    \\log \\mathbb{P}[\\Tilde{z_j} = 0] & = \\log(\\prod_{i \\in I^{+}_{j}} \\mathbb{P}[\\Tilde{y_i} = 0]\\prod_{i \\in I^{-}_{j}} \\mathbb{P}[\\Tilde{y_i} = 1]) &\\\\\n    & =  \\log(\\prod_{i \\in I^{+}_{j}} (1-y^{*}_i)\\prod_{i \\in I^{-}_{j}} y^{*}_i) &\\\\\n    & = \\sum_{i \\in I^{+}_{j}} \\log(1-y^{*}_i) + \\sum_{i \\in I^{-}_{j}} \\log y^{*}_i &\\\\\n    & \\leq - \\sum_{i \\in I^{+}_{j}}y^{*}_i - \\sum_{i \\in I^{-}_{j}}(1-y^{*}_i) &(logarithm \\quad inequality \\quad by \\quad hint)\\\\\n\\end{align*}\n\n\\subsection{}\n\n\\begin{align*}\n    \\mathbb{E}[\\Tilde{z_j}] & = 0 \\times \\mathbb{P}[\\Tilde{z_j} = 0] + 1 \\times \\mathbb{P}[\\Tilde{z_j} = 1] &\\\\\n    & = \\mathbb{P}[\\Tilde{z_j} = 1] &\\\\\n    & = 1 - \\mathbb{P}[\\Tilde{z_j} = 0] &\\\\\n    & =  1 - e^{\\log \\mathbb{P}[\\Tilde{z_j} = 0]} &\\\\\n    & \\geq  1 - ({ 1 + (1-\\frac{1}{e})\\log  \\mathbb{P}[\\Tilde{z_j} = 0]}) &(logarithm \\quad inequality \\quad by \\quad hint)\\\\\n    & = \\frac{e-1}{e}(-\\log \\mathbb{P}[\\Tilde{z_j} = 0])&\\\\\n    & \\geq \\frac{e-1}{e}( \\sum_{i \\in I^{+}_{j}}y^{*}_i + \\sum_{i \\in I^{-}_{j}}(1-y^{*}_i))& (4.1)\\\\\n    & \\geq \\frac{e-1}{e} z^{*}_{j}\n\\end{align*}\n\n\\subsection{}\n\n\\begin{align*}\n    Z_{LP} & \\geq Z_{IP} & (LP \\quad relaxation \\quad is \\quad an \\quad upper-bound \\quad of \\quad IP)\\\\\n    & \\geq \\mathbb{E}[Z_H]=\\sum_j w_j \\mathbb E[\\tilde z_{j}] & (\\mathbb{E}[Z_H] \\leq \\max Z_H = Z_{IP})\\\\\n    & \\geq \\sum_j\\frac{e-1}{e} w_jz^{*}_{j} =  \\frac{e-1}{e} Z_{LP} & (4.2)\\\\\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "9593ba4c03736adae5d22f2f613ef34dea348f7d", "size": 5614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/main.tex", "max_stars_repo_name": "tansongchen/learn-optimization", "max_stars_repo_head_hexsha": "b44e902c857287ff05da449b9a639dfe534af8ed", "max_stars_repo_licenses": ["MIT"], "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/main.tex", "max_issues_repo_name": "tansongchen/learn-optimization", "max_issues_repo_head_hexsha": "b44e902c857287ff05da449b9a639dfe534af8ed", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "tansongchen/learn-optimization", "max_forks_repo_head_hexsha": "b44e902c857287ff05da449b9a639dfe534af8ed", "max_forks_repo_licenses": ["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.2456140351, "max_line_length": 496, "alphanum_fraction": 0.6229070182, "num_tokens": 2328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.6189759717155846}}
{"text": "\\section{Boundary Behavior of Hierarchical B-Splines}\n\\label{sec:32notAKnot}\n\n\\minitoc{87mm}{8}\n\n\\noindent\nAs we have seen in the last section (see \\cref{cor:hierSplittingBSpline}),\nthe hierarchical splitting equation \\eqref{eq:hierSplittingUV}\nonly holds when restricting the function spaces to\n$\\rspldomain{l}{p} =\n\\clint{\\tfrac{p-1}{2} \\ms{l},\\; 1 - \\tfrac{p-1}{2} \\ms{l}}$,\nwhich is a proper subset of the domain $\\clint{0, 1}$ if $p > 1$.\nAs we will see, the implications of this fact on the approximation quality\nof the hierarchical B-spline basis are severe.\nIn this section, we study the underlying reasons of the restriction, and\nwe introduce a new hierarchical B-spline basis\nthat does not suffer from this issue.\n\n\n\n\\subsection{Approximation Quality of Uniform Hierarchical B-Splines}\n\\label{sec:321approximation}\n\n\\paragraph{Interpolation of polynomials}\n\nSplines are a piecewise generalization of polynomials.\nApproximation spaces spanned by splines of degree $p$ should\nat least contain all polynomials of degree $\\le p$.\nUnfortunately, this statement is not true for uniform B-splines\n$\\bspl{l,i}{p}$ as we have defined them in the last section.\nA counterexample is given in \\cref{fig:nakInterpolation},\nin which a cubic polynomial $\\objfun$ is interpolated with\nhierarchical cubic B-splines.\nWe can clearly see deviations of the interpolant from the polynomial\nnear the boundary,\nwhere the pointwise relative error exceeds \\SI{10}{\\percent}.\nThe oscillations are even visible in the interior of the\nspline interpolation domain $\\rspldomain{l}{p}$.\nObviously, this phenomenon impairs the approximation quality\nfor other non-polynomial functions as well.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Objective function $\\objfun$ \\emph{\\textcolor{C0}{(blue)},}\n    interpolant $\\fgintp{l}$ \\emph{\\textcolor{C1}{(red, dashed)},}\n    grid points \\emph{(dots),} and\n    spline interpolation domain $\\rspldomain{l}{p}$\n    \\emph{(thick line).}%\n  }[72mm]{%\n    \\includegraphics{nakInterpolation_1}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    Pointwise relative error\n    $\\abs{(\\objfun - \\fgintp{l})/\\objfun}$ on a logarithmic scale.%\n  }[72mm]{%\n    \\includegraphics{nakInterpolation_2}%\n  }%\n  \\caption[%\n    Issues when interpolating with uniform hierarchical B-splines%\n  ]{%\n    Hierarchical cubic B-splines $\\bspl{l',i'}{p}$\n    ($l' \\le l$, $i' \\in \\hiset{l'}$, $p = 3$)\n    fail to replicate a cubic polynomial $\\objfun$\n    (here: $\\objfun(x) \\ceq -10.2 x^3 + 14.7 x^2 - 5x + 0.7$)\n    \\vphantom{$\\bspl{l',i'}{p}$}%\n    when interpolating on the grid of level $l = 3$.%\n    \\vphantom{$\\bspl{l',i'}{p}$}%\n  }%\n  \\label{fig:nakInterpolation}%\n\\end{figure}\n\nThis issue can be explained as follows:\nAccording to \\thmref{cor:hierSplittingBSpline},\nwe have $\\restrictedsplspace{l}{p}\n= \\bigoplus_{l'=0}^l \\restrictspace{\\hsbspl{l'}{p}}{\\rspldomain{l}{p}}$\nwith $p = 3$.\nSince cubic polynomials are also cubic splines,\nit follows $\\objfun \\in \\restrictedsplspace{l}{p}$ and hence\n$\\objfun \\in \\bigoplus_{l'=0}^l \\restrictspace{\\hsbspl{l'}{p}}{\\rspldomain{l}{p}}$.\nThis means that there is a linear combination of hierarchical B-splines\n$\\bspl{l',i'}{p}$ ($l' \\le l$, $i' \\in \\hiset{l'}$)\nthat replicates $\\objfun$ on the whole domain $\\rspldomain{l}{p}$\n(not be confused with $\\fgintp{l}$ in \\cref{fig:nakInterpolation},\nwhich does not replicate $\\objfun$ exactly on $\\rspldomain{l}{p}$).\nHowever, in general, this interpolant is not equal $\\objfun$ outside\n$\\rspldomain{l}{p}$ (i.e., in $\\clint{0, 1} \\setminus \\rspldomain{l}{p}$),\nas \\thmref{prop:splineSpace} only holds for $\\rspldomain{l}{p}$.\nIn particular, the interpolant evaluated at $x \\in \\{0, 1\\}$ is not\nequal to $\\objfun(x)$.\nIf we now force the additional interpolation conditions in\n$\\gp{l,0} = 0$ and $\\gp{l,2^l} = 1$,\nthe resulting interpolant $\\fgintp{l}$ cannot be the same as the previous\ninterpolant,\nwhich is why $\\objfun$ and $\\fgintp{l}$ differ inside $\\rspldomain{l}{p}$.\n\n\\paragraph{Schoenberg--Whitney conditions}\n\nFormally, the unique existence of an interpolating spline is\ndescribed by the \\term{Schoenberg--Whitney conditions:}\n\n\\begin{proposition}[Schoenberg--Whitney conditions]\n  \\label{prop:schoenbergWhitneyConditions}\n  Let $\\knotseq = (\\knot{0}, \\dotsc, \\knot{m+p})$ be a knot sequence\n  and $t_0, \\dotsc, t_{m-1}$ a sequence of interpolation points with\n  $t_0 < \\dotsb < t_{m-1}$ and\n  $\\knot{p} \\le t_0 < t_{m-1} \\le \\knot{m}$.\n  Then, there exists a unique interpolating spline\n  $\\spl = \\sum_{k=0}^{m-1} \\interpcoeff{k} \\nonunifbspl{k,\\knotseq}{p}$\n  for arbitrary data if and only if\n  \\begin{equation}\n    \\knot{k} < t_k < \\knot{k+p+1},\\quad\n    k = 0, \\dotsc, m - 1.\n  \\end{equation}\n\\end{proposition}\n\n\\vspace*{0pt plus 0.3fill}\n\n\\begin{proof}\n  See \\cite{Hoellig13Approximation}.\n\\end{proof}\n\n\\vspace*{0pt plus 1.0fill}\n\nThe Schoenberg--Whitney conditions require that the interpolation points\nare contained in $\\rspldomain{l}{p}$,\nwhich is not the case for $p = 3$ (see \\cref{fig:nakInterpolation}),\nas $\\rspldomain{l}{p}$ does not contain the points $x = 0$ and $x = 1$.\nFor general degree $p$, the first $\\tfrac{p-1}{2}$ and the\nlast $\\tfrac{p-1}{2}$ grid points of level $l$ are\nmissing from $\\rspldomain{l}{p}$,\nthus violating the Schoenberg--Whitney conditions.\nOne possible remedy would be to move these interpolation points inside\n$\\rspldomain{l}{p}$ without changing the corresponding basis functions\n(i.e., the knots stay the same) \\cite{Hoellig13Approximation}.\nFor instance in the cubic case, we could move\n$x = 0$ to $x = 1.5 \\ms{l}$ and\n$x = 1$ to $x = 1 - 1.5 \\ms{l}$.\nHowever, with this approach, we would not be able to interpolate\nboundary values.\nIn addition, the condition of the interpolation problem will most likely\nworsen if we place interpolation points near the ends of the supports\nof the corresponding basis functions.\n\n\\pagebreak\n\n\\paragraph{Mismatch of dimensions}\n\nTo find a solution for this issue,\nlet $\\wholesplspace{l}{p}$ denote the space of all splines of degree $p$\non the grid of level $l$, i.e., the space $\\nonunifsplspace{\\knotseq}{p}$ with\n\\begin{equation}\n  \\label{eq:fullGridKnots}\n  \\knot{k} \\ceq (k - p) \\ms{l},\\quad\n  k = 0, \\dotsc, m + p,\\quad\n  m \\ceq 2^l + p.\n\\end{equation}\nWe have $\\spldomain{\\knotseq}{p} = \\clint{0, 1}$\nfor this choice of $\\knotseq$.\nHence, the grid points $\\gp{l,i}$ ($i = 0, \\dotsc, 2^l$) satisfy\nthe Schoenberg--Whitney conditions for the uniform B-spline basis.\nClearly, the sum $\\bigoplus_{l'=0}^l \\hsbspl{l'}{p}$\nis a subspace of $\\wholesplspace{l}{p}$,\nbut it cannot be equal to $\\wholesplspace{l}{p}$ due to\n\\begin{equation}\n  \\dim \\bigoplus_{l'=0}^l \\hsbspl{l'}{p}\n  = 2^l + 1\n  < 2^l + p\n  = m\n  = \\dim \\wholesplspace{l}{p},\\quad\n  p > 1,\n\\end{equation}\nby \\thmref{prop:splineSpace}.\nThere are too few nodal (and hierarchical) basis functions to\nspan the whole spline space $\\wholesplspace{l}{p}$.\n\n\\paragraph{Restriction to spline subspaces}\n\nThe key idea is now to impose additional $p - 1$ boundary conditions\non the basis functions to restrict $\\wholesplspace{l}{p}$ to a reasonable subspace\nwith the correct dimension $(2^l + p) - (p - 1) = 2^l + 1$.\n``Reasonable'' means that besides this dimension constraint,\ntwo requirements should be met:\nFirst, the Schoenberg-Whitney conditions should be satisfied for\nthe new subspace and the grid of level $l$.\nSecond, the new subspace should contain all polynomials of degree $\\le p$,\neliminating the issue discussed in \\cref{fig:nakInterpolation}.\n\n\n\n\\subsection{Hierarchical Not-A-Knot B-Splines}\n\\label{sec:322NAKBSplines}\n\n\\paragraph{Not-a-knot conditions}\n\nA suitable subspace can be obtained by incorporating the\nso-called \\term{not-a-knot boundary conditions} into $\\wholesplspace{l}{p}$.\nFor the cubic case $p = 3$\n(for which we need two conditions),\nthe not-a-knot conditions demand that\nfor all splines $\\spl$ in the subspace,\n$\\deriv[3]{x}{s}$ is continuous at the first and at the last\ninterior knot $\\gp{l,1} = \\ms{l}$ and $\\gp{l,2^l-1} = 1 - \\ms{l}$\n\\cite{Hoellig13Approximation}.\nThis means that\n$\\gp{l,1}$ and $\\gp{l,2^l-1}$ are effectively removed from the\nknot sequence, as this is equivalent to requiring that\n$\\spl$ is a cubic polynomial on $\\clint{0, \\gp{l,2}}$ and\n$\\clint{\\gp{l,2^l-2}, 1}$ (hence ``not-a-knot'').\nFor general degree $p$ (for which we need $(p - 1)$ conditions),\nwe require that the $p$-th derivative $\\deriv[p]{x}{s}$\nis continuous at the first $\\tfrac{p-1}{2}$ and the last $\\tfrac{p-1}{2}$\ninner grid points\n\\begin{equation}\n  \\label{eq:removedNAKKnots}\n  \\gp{l,i},\\quad\n  i \\in \\{1, \\dotsc, \\tfrac{p-1}{2}\\} \\cup\n  \\{2^l - \\tfrac{p-1}{2}, \\dotsc, 2^l - 1\\}.\n\\end{equation}\nThis is equivalent to removing these knots\nfrom the knot sequence $\\knotseq$,\nor, alternatively, to requiring that $\\spl$ is a polynomial\nof degree $\\le p$ on $\\clint{0, \\gp{l,(p+1)/2}}$ and on\n$\\clint{\\gp{l,2^l-(p+1)/2}, 1}$.\n\n\\usenotation{zzzznak}\nThe knot sequence $\\nodalknotseq[\\nak]{l}{p}$\nwith not-a-knot boundary conditions is defined as follows:\n\\begin{subequations}\n  \\begin{gather}\n    \\nodalknotseq[\\nak]{l}{p}\n    \\ceq (\\nodalknot[\\nak]{l,0}{p}, \\dotsc,\n    \\nodalknot[\\nak]{l,m+p}{p}),\\quad\n    m \\ceq 2^l + 1,\\\\\n    \\nodalknot[\\nak]{l,k}{p}\n    \\ceq\n    \\begin{cases}\n      \\gp{l,k-p},&\n      k = 0, \\dotsc, p,\\\\\n      \\gp{l,k-(p+1)/2},&\n      k = p + 1, \\dotsc, 2^l,\\\\\n      \\gp{l,k-1},&\n      k = 2^l + 1, \\dotsc, 2^l + p + 1.\n    \\end{cases}\n  \\end{gather}\n\\end{subequations}\nThis knot sequence $\\nodalknotseq[\\nak]{l}{p}$\ncan be obtained by removing the knots\ngiven in \\eqref{eq:removedNAKKnots} from the\nknot sequence \\eqref{eq:fullGridKnots} for the full grid of level $l$.\nWe show $\\nodalknotseq[\\nak]{l}{p}$ and the corresponding B-spline functions\nin \\cref{fig:splineSpaceNotAKnot}.\nThe resulting spline space\n\\begin{equation}\n  \\naksplspace{l}{p}\n  \\ceq \\nonunifsplspace{\\nodalknotseq[\\nak]{l}{p}}{p}\n\\end{equation}\nis a subspace\nof $\\wholesplspace{l}{p}$ with the desired dimensionality:\n\\begin{equation}\n  \\dim \\bigoplus_{l'=0}^l \\hsbspl{l'}{p}\n  = 2^l + 1\n  = \\dim \\naksplspace{l}{p}.\n\\end{equation}\nThe space $\\naksplspace{l}{p}$ satisfies our two requirements:\n\\vspace{0.1em}%\nFirst, the spline interpolation domain\n$\\spldomain{\\nodalknotseq[\\nak]{l}{p}}{p}\n= \\clint{\\nodalknot[\\nak]{l,p}{p}, \\nodalknot[\\nak]{l,m}{p}}$\nof $\\naksplspace{l}{p}$ equals the whole unit interval $\\clint{0, 1}$.\n\\vspace{-0.3em}%\nThis means that the Schoenberg--Whitney conditions are satisfied\n\\vspace{0.1em}%\nfor $\\naksplspace{l}{p}$, since all interpolation points\n(grid points) are contained in\n$\\spldomain{\\nodalknotseq[\\nak]{l}{p}}{p} = \\clint{0, 1}$.\n\\vspace{-0.3em}%\nSecond, $\\naksplspace{l}{p}$ still contains all polynomials of\ndegree $\\le p$, as we have only removed knots compared to\n$\\wholesplspace{l}{p}$.\n\n\\begin{figure}\n  \\includegraphics{splineSpace_3}%\n  \\caption[%\n    Nodal not-a-knot B-splines and knot sequence%\n  ]{%\n    Not-a-knot knot sequence $\\nodalknotseq[\\nak]{l}{p}$\n    \\emph{(ticks on horizontal axis)}\n    and nodal cubic not-a-knot B-splines ($p = 3$)\n    of level $l = 3$.\n    In the domain $\\clint{0, 1}$ \\emph{(delimited by dashed lines),}\n    the first $\\tfrac{p-1}{2}$ and the last $\\tfrac{p-1}{2}$ interior grid points\n    of the set of grid points $\\fgset{l}$\n    \\emph{\\textcolor{mittelblau}{(blue dots)}}\n    have been removed from the set of knots.\n    The spline interpolation domain\n    $\\spldomain{\\nodalknotseq[\\nak]{l}{p}}{p}$\n    \\emph{(thick line)}\n    equals the whole domain $\\clint{0, 1}$.%\n  }%\n  \\label{fig:splineSpaceNotAKnot}%\n\\end{figure}\n\n\\vspace*{\\fill}\n\nHowever, $\\bigoplus_{l'=0}^l \\hsbspl{l'}{p}$ is not a subspace of\n$\\naksplspace{l}{p}$ anymore,\nsince the hierarchical basis functions $\\bspl{l',i'}{p}$ are not\nnot-a-knot splines (due to the additional knots that we removed from\n$\\naksplspace{l}{p}$).\nFor this reason,\nwe have to incorporate the not-a-knot boundary conditions into the\nhierarchical basis.\n\n\\vspace*{\\fill}\n\nBefore defining the new hierarchical basis functions,\nwe make two additional observations.\nFirst, $\\nodalknotseq[\\nak]{l}{p}$ coincides with the\nuniform knot sequence $\\nodalknotseq{l}{p}$ of \\thmref{cor:nodalBSplineSpace}\nfor the piecewise linear case of $p = 1$.\nThis is intuitively clear:\nFor this case,\nwe do not need to remove any knots as the hierarchical splitting already\nholds for the full domain by \\cref{cor:hierSplittingHatMV}.\nSecond, the removal of the knots in \\eqref{eq:removedNAKKnots}\nis only possible if $p + 1 \\le 2^l$,\nwhich is equivalent to $l \\ge \\ceil{\\log_2(p+1)}$.\nFor coarser levels,\nthere are not enough interior knots that could be removed.\nWithout any special treatment,\nwe would not be able to obtain enough basis functions to span the spline space.\n\n\\pagebreak\n\n\\paragraph{Definition of hierarchical not-a-knot B-splines}\n\nFor the definition of \\term{hierarchical not-a-knot B-splines}\n$\\bspl[\\nak]{l,i}{p}$ based on \\thmref{def:nonUniformBSpline},\nwe use global Lagrange polynomials for the coarser levels:\n\\begin{subequations}\n  \\label{eq:hierarchicalNotAKnotBSpline}\n  \\begin{gather}\n    \\bspl[\\nak]{l,i}{p}\n    \\ceq\n    \\begin{cases}\n      \\lagrangepoly{l,i},&\n      l < \\ceil{\\log_2(p+1)},\\\\\n      \\nonunifbspl{i,\\nodalknotseq[\\nak]{l}{p}}{p},&\n      l \\ge \\ceil{\\log_2(p+1)},\n    \\end{cases}\\quad\n    l \\in \\natz,\\quad\n    i \\in \\hiset{l},\\\\\n    \\lagrangepoly{l,i}\\colon \\clint{0, 1} \\to \\real,\\quad\n    \\lagrangepoly{l,i}(x)\n    \\ceq \\!\\!\\prod_{\\substack{i'=0,\\dotsc,2^l\\\\i'\\not=i}}\n    \\frac{x - \\gp{l,i'}}{\\gp{l,i} - \\gp{l,i'}}.\n  \\end{gather}\n\\end{subequations}\nThe hierarchical not-a-knot B-spline basis is shown for the\ncubic case $p = 3$ in \\cref{fig:notAKnotBSpline}.\nThe function $\\lagrangepoly{l,i}$ is the $i$-th\n\\term{Lagrange polynomial} of level $l$, that is,\nthe unique polynomial of degree $\\le 2^l$ that interpolates the data\n$\\{(\\gp{l,i'}, \\kronecker{i}{i'}) \\mid i' = 0, \\dotsc, 2^l\\}$.\nSince its degree $\\deg \\lagrangepoly{l,i}$ is bounded by $2^l$,\nwe have $\\deg \\lagrangepoly{l,i} < p + 1$,\nas the Lagrange polynomials are employed only when\n$l < \\ceil{\\log_2(p+1)}$.\nDue to $2^l$ even (when $l \\ge 1$) and $p$ odd,\nwe can conclude from $\\deg \\lagrangepoly{l,i} \\le 2^l \\le p$ that actually\n$\\deg \\lagrangepoly{l,i} \\le 2^l < p$\n(for $p > 1$; for $p = 1$, the case $l = 0$ is the exception).\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Nodal not-a-knot B-splines\n    $\\bspl[\\nak]{l,i}{p}$ ($i \\in \\hiset{l}$)\n    and grid points $\\gp{l,i}$ \\emph{(dots).}%\n  }[67.5mm]{%\n    \\includegraphics{hierarchicalBasis_8}%\n  }%\n  \\hfill%\n  \\begin{tikzpicture}\n    \\draw[decorate,decoration={brace,aspect=0.145}] (0,-8.5) -- (0,0);\n    \\node[anchor=east,inner sep=0mm] at (-0.15,-7.265) {$= \\bigoplus$};\n  \\end{tikzpicture}%\n  \\hfill%\n  \\subcaptionbox{%\n    Hierarchical not-a-knot B-splines\n    $\\bspl[\\nak]{l',i'}{p}$ ($l' \\le l$, $i' \\in \\hiset{l'}$)\n    and grid points $\\gp{l',i'}$ \\emph{(dots).}%\n  }[71mm]{%\n    \\includegraphics{hierarchicalBasis_9}%\n  }%\n  \\caption[%\n    Nodal and hierarchical not-a-knot B-splines%\n  ]{%\n    Univariate nodal and hierarchical cubic not-a-knot B-splines ($p = 3$)\n    up to level $l = 3$.\n    The nodal space $\\nsbspl[\\nak]{l}{p}$,\n    which coincides with the not-a-knot spline space $\\naksplspace{l}{p}$,\n    decomposes into the direct sum\n    of the hierarchical subspaces $\\hsbspl[\\nak]{l'}{p}$ ($l' \\le l$).\n    The knots of each level $l'$ are given by removing the\n    first $\\tfrac{p-1}{2}$ and last $\\tfrac{p-1}{2}$\n    inner points \\emph{(crosses)}\n    from the set of grid points $\\gp{l',i'}$\n    ($i' = 0, \\dotsc, 2^{l'}$).%\n  }%\n  \\label{fig:notAKnotBSpline}%\n\\end{figure}\n\n\\vspace*{\\fill}\n\nThe motivation for using Lagrange polynomials for coarse levels\nis that they form a basis of the polynomial space\nand that they can be implemented and calculated quickly.\nHowever, the specific choice of basis functions for the levels\n$l < \\ceil{\\log_2(p + 1)}$ is arbitrary,\nas long as these functions are linearly independent\n(of each other and of the ``true'' not-a-knot B-splines\n$\\bspl[\\nak]{l,i}{p}$, $l \\ge \\ceil{\\log_2(p+1)}$)\nand contained in the space $\\naksplspace{l}{p}$.\n\n\\pagebreak\n\n\\paragraph{Implementation}\n\nNote that in each level $l \\ge \\ceil{\\log_2(p+1)}$,\nonly the first $\\tfrac{p+1}{2}$\n(indices $i = 1, 3, \\dotsc, p$)\nand the last $\\tfrac{p+1}{2}$\n(indices $i = 2^l - p, 2^l - p + 2, \\dotsc, 2^l - 1$)\nhierarchical basis functions $\\bspl[\\nak]{l,i}{p}$\ndiffer from $\\bspl{l,i}{p}$,\ni.e., we have\n\\begin{equation}\n  \\bspl[\\nak]{l,i}{p} = \\bspl{l,i}{p},\\quad\n  i = p + 2,\\; p + 4,\\; \\dotsc,\\; 2^l - p - 2.\n\\end{equation}\n\n\\vspace*{\\fill}\n\n\\noindent\nThis means that we can reuse uniform B-spline code\nfor the inner functions.\nDue to $\\bspl[\\nak]{l,i}{p}(x) = \\bspl[\\nak]{l,2^l-i}{p}(1-x)$\n(because of the symmetry of $\\nodalknotseq[\\nak]{l}{p}$),\nwe only have to reimplement $\\tfrac{p+1}{2}$ not-a-knot B-splines per level $l$.\nAs $\\bspl[\\nak]{l,i}{p}$ and $\\bspl[\\nak]{l+1,i}{p}$\nuse the same knots up to an affine transformation for $l$ large enough\n($l \\ge 3$ suffices for $p = 3$),\nonly a number of special cases for coarse levels $l$ must be implemented.\nIn other words, the not-a-knot approach is ``minimally invasive''\nwith respect to an implementation that already uses uniform B-splines.\n\n\\pagebreak\n\n\\paragraph{Hierarchical splitting}\n\nThe main benefit of the hierarchical not-a-knot B-spline basis\nis the validity of the hierarchical splitting.\nAs usual, we define $\\nsbspl[\\nak]{l}{p}$ and $\\hsbspl[\\nak]{l}{p}$\nas the nodal and the hierarchical not-a-knot subspace of level $l$,\nrespectively.\n\n\\begin{proposition}[%\n  univariate hierarchical splitting for not-a-knot B-splines%\n]\n  \\label{prop:hierSplittingNAKBSplineUV}\n  The hierarchical splitting \\eqref{eq:hierSplittingUV}\n  holds for the hierarchical not-a-knot B-spline basis:\n  \\begin{equation}\n    \\naksplspace{l}{p}\n    = \\nsbspl[\\nak]{l}{p}\n    = \\bigoplus_{l'=0}^l \\hsbspl[\\nak]{l'}{p},\n  \\end{equation}\n  where for $l < \\ceil{\\log_2(p+1)}$, $\\naksplspace{l}{p}$\n  is defined as the space $\\polyspace{2^l}$ of polynomials of degree\n  $\\le 2^l$ on $\\clint{0, 1}$.\n  (For $l \\ge \\ceil{\\log_2(p+1)}$,\n  $\\naksplspace{l}{p}$ is the not-a-knot spline space.)\n\\end{proposition}\n\n\\begin{proof}\n  For $l < \\ceil{\\log_2(p+1)}$, all\n  three spaces coincide with $\\polyspace{2^l}$ and nothing is to prove.\n  \n  For $l \\ge \\ceil{\\log_2(p+1)}$,\n  we check the two conditions of \\thmref{lemma:hierSplittingUV}.\n  First, the hierarchical subspace $\\hsbspl[\\nak]{l'}{p}$ ($l' \\le l$)\n  is a subspace of $\\naksplspace{l}{p} = \\nsbspl[\\nak]{l}{p}$.\n  This is a conclusion of \\thmref{prop:splineSpace}, as\n  every function $\\bspl[\\nak]{l',i'}{p}$ ($i' \\in \\hiset{l'}$)\n  is continuous on $\\clint{0, 1}$, a polynomial on every knot interval of\n  $\\nodalknotseq[\\nak]{l}{p}$, and at the knots themselves\n  at least $(p - 1)$ times continuously differentiable.\n  \n  Second, the hierarchical functions $\\bspl[\\nak]{l',i'}{p}$\n  ($l' \\le l$, $i' \\in \\hiset{l'}$) are linearly independent.\n  This can be shown similarly to the proof of\n  \\thmref{prop:hierBSplineLinearlyIndependent}.\n  The linear independence of the Lagrange polynomials\n  can be checked by inserting grid points into a zero linear combination.\n  The linear combination collapses and only one term remains,\n  the coefficient corresponding to the grid point.\n  Hence, all coefficients must vanish.\n\\end{proof}\n\n\\vspace*{1em}\n\n\\begin{corollary}[%\n  multivariate hierarchical splitting for not-a-knot B-splines%\n]\n  \\label{cor:hierSplittingNAKBSplineMV}\n  It holds\n  \\begin{equation}\n    \\naksplspace{\\*l}{\\*p}\n    = \\nsbspl[\\nak]{\\*l}{\\*p}\n    = \\bigoplus_{\\*l'=\\*0}^\\*l \\hsbspl[\\nak]{\\*l'}{\\*p},\n  \\end{equation}\n  where $\\naksplspace{\\*l}{\\*p}$ is the\n  tensor product space of $\\naksplspace{l_t}{p_t}$\n  ($t = 1, \\dotsc, d$) as defined in \\cref{prop:hierSplittingNAKBSplineUV}.\n\\end{corollary}\n\n\\begin{proof}\n  Follows directly from \\thmref{prop:splittingUVToMV}.\n\\end{proof}\n\n\\paragraph{Sparse grids with not-a-knot B-splines}\n\nRegular sparse grid spaces using the new hierarchical not-a-knot basis\nare defined analogously to the uniform case, i.e.,\n\\begin{equation}\n  \\label{eq:sparseGridRegularNAK}\n  \\regsgspace[\\*p,\\nak]{n}{d}\n  \\ceq \\bigoplus_{\\normone{\\*l} \\le n} \\hsbspl[\\nak]{\\*l}{\\*p}.\n\\end{equation}\nIf the level $n$ is large enough, then $\\regsgspace[\\*p,\\nak]{n}{d}$\ncontains the space $\\polyspace{\\*p}$ of all $d$-variate polynomials of\ncoordinate degree $\\le \\*p$ on $\\clint{\\*0, \\*1}$\n(i.e., functions $\\objfun\\colon \\clint{0, 1} \\to \\real$ of the form\n$\\objfun(\\*x) \\ceq \\sum_{\\*q=\\*0}^\\*p \\interpcoeff{\\*q} \\prod_{t=1}^d x_t^{q_t}$\nwith $\\interpcoeff{\\*q} \\in \\real$).\nThis means that in contrast to the uniform B-spline basis,\nhierarchical not-a-knot B-splines on sparse grids are able to\nreplicate global polynomials on $\\clint{\\*0, \\*1}$:\n\n\\begin{shortcorollary}[%\n  sparse grid with not-a-knot B-splines contains polynomials%\n]\n  \\label{cor:sparseGridRegularNAKPolynomials}\n  If $n \\ge \\normone{\\ceil{\\veclog_\\*2(\\*p + \\*1)}}$,\n  then $\\polyspace{\\*p} \\subset \\regsgspace[\\*p,\\nak]{n}{d}$.\n\\end{shortcorollary}\n\n\\begin{proof}\n  Let $\\*l \\ceq \\ceil{\\veclog_\\*2(\\*p + \\*1)}$ and $n \\ge \\normone{\\*l}$.\n  By \\cref{cor:hierSplittingNAKBSplineMV}, we have\n  $\\bigoplus_{\\*l'=\\*0}^{\\*l} \\hsbspl[\\nak]{\\*l'}{\\*p} = \\naksplspace{\\*l}{\\*p}$.\n  In addition, all $\\*l' \\in \\natz^d$ with $\\*l' \\le \\*l$ satisfy\n  $\\normone{\\*l'} \\le n$ and thus,\n  $\\bigoplus_{\\*l'=\\*0}^{\\*l} \\hsbspl[\\nak]{\\*l'}{\\*p} \\subset\n  \\regsgspace[\\*p,\\nak]{n}{d}$ by \\eqref{eq:sparseGridRegularNAK}.\n  We conclude\n  $\\polyspace{\\*p} \\subset \\naksplspace{\\*l}{\\*p} \\subset\n  \\regsgspace[\\*p,\\nak]{n}{d}$, which is the asserted claim.\n\\end{proof}\n\n\n\n\\subsection{Modified and Non-Uniform Hierarchical Not-A-Knot B-Splines}\n\\label{sec:323modifiedNAKBSplines}\n\n\\paragraph{Modified hierarchical not-a-knot B-splines}\n\nAs for uniform and Clenshaw--Curtis B-splines\n(\\cref{sec:31standardBSplines}),\nit is possible to define a modified version of the\nhierarchical not-a-knot B-spline basis to obtain\n``reasonable'' boundary values without boundary points.\nHowever, we cannot use \\thmref{lemma:marsden} similarly to\n\\eqref{eq:modifiedBSplineConstruction}:\nDue to the removal of knots, there is only a single\nnot-a-knot B-spline $\\bspl[\\nak]{l,0}{p}$ left of\n$\\bspl[\\nak]{l,1}{p}$.\nB-splines $\\bspl[\\nak]{l,i}{p}$ with index $i < 0$\nwould vanish on $\\clint{0, 1}$.\n\nWhile we are therefore not able to construct modified functions\nwhose second derivative vanishes in a neighborhood of $x = 0$,\nwe can use $\\bspl[\\nak]{l,0}{p}$ to let the\nsecond derivative vanish in $x = 0$ itself:\n\\begin{equation}\n  \\label{eq:modifiedNotAKnotBSpline}\n  \\bspl[\\nak,\\modified]{l,i}{p}(x)\n  \\ceq\n  \\begin{cases}\n    1,&\n    l = 1,\\quad i = 1,\\\\\n    \\bspl[\\nak]{l,1}{p}(x)\n    - \\dfrac{\\deriv[2]{x}{\\bspl[\\nak]{l,1}{p}}(0)}%\n    {\\deriv[2]{x}{\\bspl[\\nak]{l,0}{p}}(0)}\n    \\bspl[\\nak]{l,0}{p}(x),&\n    l \\ge 2,\\quad i = 1,\\\\\n    \\bspl[\\nak]{l,i}{p}(x),&\n    l \\ge 2,\\quad i \\in \\hiset{l} \\setminus \\{1, 2^l - 1\\},\\\\\n    \\bspl[\\nak,\\modified]{l,1}{p}(1 - x),&\n    l \\ge 2,\\quad i = 2^l - 1.\n  \\end{cases}\n  \\hspace*{-2mm}\n\\end{equation}\nThe resulting modified hierarchical not-a-knot B-spline basis\n$\\bspl[\\nak,\\modified]{l,i}{p}$ is shown with dashed lines\nin \\cref{fig:modifiedNotAKnotBSpline}.\nAs before, we have to implement $\\bspl[\\nak,\\modified]{l,1}{p}$\nonly for a single level $l$, as modified functions of higher levels\nare the same up to an affine parameter transformation.\nNote again that for $p \\ge 5$, we would have to modify additional\ninterior B-splines as the interior of their support then extends to the\nboundary of $\\clint{0, 1}$.\nWe refrain from doing so to keep the definition\n\\eqref{eq:modifiedNotAKnotBSpline} simple.\n\n\\paragraph{Non-uniform hierarchical not-a-knot B-splines}\n\nThe not-a-knot construction is completely independent of the\ndistribution of the grid points at hand.\nConsequently, we can define hierarchical not-a-knot B-splines\nfor non-uniform distributions.\nFor instance, to define not-a-knot B-splines for\nChebyshev points (see \\cref{sec:314nonUniform}),\nwe first specify the knot sequence as\n\\begin{subequations}\n  \\begin{gather}\n    \\nodalknotseq[\\cc,\\nak]{l}{p}\n    \\ceq (\\nodalknot[\\cc,\\nak]{l,0}{p}, \\dotsc,\n    \\nodalknot[\\cc,\\nak]{l,m+p}{p}),\\quad\n    m \\ceq 2^l + 1,\\\\\n    \\nodalknot[\\cc,\\nak]{l,k}{p}\n    \\ceq\n    \\begin{cases}\n      \\ccgp{l,k-p},&\n      k = 0, \\dotsc, p,\\\\\n      \\ccgp{l,k-(p+1)/2},&\n      k = p + 1, \\dotsc, 2^l,\\\\\n      \\ccgp{l,k-1},&\n      k = 2^l + 1, \\dotsc, 2^l + p + 1,\n    \\end{cases}\n  \\end{gather}\n\\end{subequations}\nand then define hierarchical not-a-knot Clenshaw--Curtis B-splines as\n\\begin{subequations}\n  \\begin{gather}\n    \\bspl[\\cc,\\nak]{l,i}{p}\n    \\ceq\n    \\begin{cases}\n      \\lagrangepoly[\\cc]{l,i},&\n      l < \\ceil{\\log_2(p+1)},\\\\\n      \\nonunifbspl{i,\\nodalknotseq[\\cc,\\nak]{l}{p}}{p},&\n      l \\ge \\ceil{\\log_2(p+1)},\n    \\end{cases}\\quad\n    l \\in \\natz,\\quad\n    i \\in \\hiset{l},\\\\\n    \\lagrangepoly[\\cc]{l,i}\\colon \\clint{0, 1} \\to \\real,\\quad\n    \\lagrangepoly[\\cc]{l,i}(x)\n    \\ceq \\!\\!\\prod_{\\substack{i'=0,\\dotsc,2^l\\\\i'\\not=i}}\n    \\frac{x - \\ccgp{l,i'}}%\n    {\\ccgp{l,i} - \\ccgp{l,i'}}.\n  \\end{gather}\n\\end{subequations}\n\nThis definition can even be combined with the modification\nof hierarchical not-a-knot B-splines as discussed above.\nWe can use exactly the same approach as in\n\\eqref{eq:modifiedNotAKnotBSpline}, if we replace the\nnot-a-knot basis functions with their non-uniform not-a-knot counterparts\n(not-a-knot Clenshaw--Curtis B-splines in the above example).\nThe hierarchical not-a-knot Clenshaw--Curtis B-spline basis of\ncubic degree and the corresponding modified functions are shown in\n\\cref{fig:clenshawCurtisNotAKnotBSpline}.\n\n\\begin{figure}\n  \\subcaptionbox{%\n    $\\bspl[\\nak]{l',i'}{p}$,\n    $\\bspl[\\nak,\\modified]{l',i'}{p}$\n    \\emph{(dashed),} and $\\gp{l',i'}$ \\emph{(dots).}%\n    \\label{fig:modifiedNotAKnotBSpline}%\n  }[73mm]{%\n    \\includegraphics{hierarchicalBasis_10}%\n  }%\n  \\hfill\n  \\subcaptionbox{%\n    $\\bspl[\\cc,\\nak]{l',i'}{p}$,\n    $\\bspl[\\cc,\\nak,\\modified]{l',i'}{p}$\n    \\emph{(dashed),} and $\\ccgp{l',i'}$ \\emph{(dots).}%\n    \\label{fig:clenshawCurtisNotAKnotBSpline}%\n  }[76mm]{%\n    \\includegraphics{hierarchicalBasis_11}%\n  }%\n  \\caption[%\n    Comparison of hierarchical not-a-knot B-splines%\n  ]{%\n    Comparison of uniform \\emph{(left)} and\n    Clenshaw--Curtis \\emph{(right)} hierarchical cubic not-a-knot\n    B-splines $\\bspl[\\nak]{l',i'}{p}$ and\n    $\\bspl[\\cc,\\nak]{l',i'}{p}$\n    ($l ' \\le l$, $i' \\in \\hiset{l'}$, $p = 3$) up to level $l = 3$\n    together with the respective modified versions\n    $\\bspl[\\nak,\\modified]{l',i'}{p}$ and\n    $\\bspl[\\cc,\\nak,\\modified]{l',i'}{p}$\n    \\emph{(dashed).}\n    The knots of each level $l'$ are given by removing the\n    first $\\tfrac{p-1}{2}$ and last $\\tfrac{p-1}{2}$\n    inner points \\emph{(crosses)}\n    from the set of grid points $\\gp{l',i'}$ or\n    $\\ccgp{l',i'}$\n    ($i' = 0, \\dotsc, 2^{l'}$), respectively.%\n  }%\n  \\label{fig:uniformAndClenshawCurtisNotAKnotBSpline}%\n\\end{figure}\n\n\n\n\\subsection{Other Approaches to Incorporate Boundary Conditions}\n\\label{sec:324naturalBoundary}\n\nNot-a-knot boundary conditions are not the only approach\nto obtain a subspace of $\\wholesplspace{l}{p}$ with the right dimension $2^l - 1$.\n\\term{Natural boundary conditions} are another possibility,\nwhich we want to discuss briefly.\nIn the cubic case, for which they are usually formulated\n\\cite{Hoellig13Approximation},\nthese boundary conditions require that the\nsecond derivatives $\\deriv[2]{x}{\\basis{l,i}}$ of the\nbasis functions vanish at the boundary $x \\in \\{0, 1\\}$.\nTo obtain the necessary number of $p - 1$ constraints also\nfor higher degrees $p$,\nwe require that all derivatives\n$\\deriv[q]{x}{\\basis{l,i}}$ of order\n$q = 2, \\dotsc, \\tfrac{p+1}{2}$ vanish at $x \\in \\{0, 1\\}$.\n\nConsequently, we can define hierarchical natural B-splines as\n\\begin{subequations}\n  \\begin{gather}\n    \\bspl[\\ntrl]{l,i}{p}(x)\n    \\ceq\n    \\begin{cases}\n      \\lagrangepoly{0,i}(x),&\n      l = 0,\\\\\n      \\bspl{l,i}{p} +\n      \\sum_{j \\in J_i^{p,\\ntrl}} c_{l,i,j} \\bspl{l,j}{p},&\n      l \\ge 1,\n    \\end{cases}\\quad\n    l \\in \\natz,\\quad\n    i \\in \\hiset{l},\\\\\n    J_i^{p,\\ntrl}\n    \\ceq \\{i-\\tfrac{p-1}{2}, \\dotsc, i-1\\} \\cup\n    \\{i+1, \\dotsc, i+\\tfrac{p-1}{2}\\},\n  \\end{gather}\n\\end{subequations}\nwhere the coefficients $c_{l,i,j} \\in \\real$ are chosen such that\nthe natural boundary conditions are satisfied:\n\\begin{equation}\n  \\deriv[q]{x}{\\bspl[\\ntrl]{l,i}{p}}(x)\n  = 0,\\quad\n  l \\ge 1,\\quad\n  i \\in \\hiset{l},\\quad\n  q = 2, \\dotsc, \\tfrac{p+1}{2},\\quad\n  x \\in \\{0, 1\\}.\n\\end{equation}\nThe first half of the coefficients $c_{l,i,j} \\in \\real$\n($j < i$) vanishes if the interior of the support of $\\bspl{l,i}{p}$\ndoes not contain $x = 0$\n(i.e., $i \\ge \\tfrac{p+1}{2}$).\nThe second half of the coefficients~($j > i$) vanishes analogously\nif $1 \\notin \\interiorsupp \\bspl{l,i}{p} \\iff i \\le 2^l - \\tfrac{p+1}{2}$.\nThis means that\nonly the first $\\floor{\\tfrac{p+1}{4}}$ and the last $\\floor{\\tfrac{p+1}{4}}$\nhierarchical functions have to be altered in each level.\n\n\\Cref{fig:naturalBSpline} shows the hierarchical natural spline basis.\nThe main disadvantage of natural boundary conditions is that\nwe are not able to replicate arbitrary polynomials exactly on $\\clint{0, 1}$\nwith this approach.\nOnly polynomials that satisfy natural boundary conditions themselves\n(linear polynomials for example)\ncan be replicated exactly.\nFor this reason, we do not further consider this basis in the\nrest of the thesis.\n\n\\begin{SCfigure}\n  \\includegraphics{hierarchicalBasis_12}%\n  \\caption[%\n    Hierarchical natural B-splines%\n  ]{%\n    Hierarchical cubic natural B-splines\n    \\vspace{-0.1em}%\n    $\\bspl[\\ntrl]{l',i'}{p}$\n    ($l' \\le l$, $i' \\in \\hiset{l'}$, $p = 3$) and\n    \\vspace{0.05em}%\n    grid points $\\gp{l',i'}$ \\emph{(dots)} up to level $l = 3$.%\n  }%\n  \\label{fig:naturalBSpline}%\n\\end{SCfigure}\n", "meta": {"hexsha": "abc7bce2fff17ae04a18c8a6fa96488556f904fc", "size": 29996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/32notAKnot.tex", "max_stars_repo_name": "valentjn/thesis-arxiv", "max_stars_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-12T09:28:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:07:17.000Z", "max_issues_repo_path": "tex/document/32notAKnot.tex", "max_issues_repo_name": "valentjn/thesis-arxiv", "max_issues_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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/32notAKnot.tex", "max_forks_repo_name": "valentjn/thesis-arxiv", "max_forks_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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.1237623762, "max_line_length": 83, "alphanum_fraction": 0.6735564742, "num_tokens": 10477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.72487026428967, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.6189759683021414}}
{"text": "\\documentclass[jou]{apa6}\n\n\\usepackage[american]{babel}\n\n\\usepackage{csquotes}\n\\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}\n\\DeclareLanguageMapping{american}{american-apa}\n\\addbibresource{bibliography.bib}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Discrete Structures\n%% The start of RBS stuff\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Working internal and external links in PDF\n\\usepackage{hyperref}\n% Extra math symbols in LaTeX\n\\usepackage{amsmath}\n\\usepackage{gensymb}\n\\usepackage{amssymb}\n% Enumerations with (a), (b), etc.\n\\usepackage{enumerate}\n\\usepackage[framemethod=TikZ]{mdframed}\n\\usepackage{xcolor}\n\n\\let\\OLDitemize\\itemize\n\\renewcommand\\itemize{\\OLDitemize\\addtolength{\\itemsep}{-6pt}}\n\n\\usepackage{etoolbox}\n\\makeatletter\n\\preto{\\@verbatim}{\\topsep=3pt \\partopsep=3pt }\n\\makeatother\n\n% These sizes redefine APA for A4 paper size\n\\oddsidemargin 0.0in\n\\evensidemargin 0.0in\n\\textwidth 6.27in\n\\headheight 1.0in\n\\topmargin -24pt\n\\headheight 12pt\n\\headsep 12pt\n\\textheight 9.19in\n\n\n\n\\title{Sample Quiz 8}\n\\author{Discrete Structures, Spring 2020}\n\\affiliation{RBS}\n\n\\leftheader{Discrete Sample Quiz 8}\n\n\\abstract{%\n}\n\n%\\keywords{}\n\n\\setlength\\parindent{0pt}\n\n\\begin{document}\n\n%\\thispagestyle{empty}\n\n\\twocolumn\n\\section{Final Exam, 2020-04-23}\n\n\\vspace{4pt}\n{\\bf Question 1.}\\\\\nBy $U$ we denote the set of all positive integers \nbetween $1$ and $120$. This is the {\\em universe} in which \nwe define several subsets:\n$$\\left\\{ \\begin{array}{l}\nA = \\{ x \\in U\\;\\mid\\;2\\mid{}x\\},\\\\\nB = \\{ x \\in U\\;\\mid\\;3\\mid{}x\\},\\\\\nC = \\{ x \\in U\\;\\mid\\;5\\mid{}x\\},\\\\\nX = \\{ x \\in U\\;\\mid\\;2\\mid{}x\\;\\vee\\;3\\mid{}x\\},\\\\\nY = \\{ x \\in U\\;\\mid\\;(3\\mid{}x\\;\\wedge\\;5\\mid{}x)\\;\\vee\\neg(2\\mid{}x)\\}.\n\\end{array} \\right.$$\n\n{\\bf (A)} Express $X$ using the sets $A,B,C$ (using set union $V \\cup W$, \nset intersection $V \\cap W$, set complement $\\overline{V}$ operations).\\\\\n{\\bf (B)} Express $Y$ using the sets $A,B,C$ in a similar way.\\\\\n{\\bf (C)} Find $|X|$ - the size of the set $X$.\\\\\n{\\bf (D)} Find $|Y|$ - the size of the set $Y$.\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 2.}\\\\\nLet $A$ and $B$ be sets with sizes $|A| = 8$ and $|B| = 5$\nand $|A \\cap B| = 3$. \n\nCalculate the largest and the smallest possible values \nfor each of the following set sizes: \n\n{\\bf (A)} $|A \\cup B|$.\\\\\n{\\bf (B)} $|A \\times (B \\times B)|$.\\\\\n{\\bf (C)} $\\left| \\mathcal{P}(\\mathcal{P}(A \\cap B)) \\right|$ - the \npowerset of a powerset of $A \\cap B$.\\\\\n{\\bf (D)} $|A \\oplus B|$ - the symmetric difference of the sets $A$ and $B$.\n\n\n\\vspace{10pt}\n{\\bf Question 3.}\\\\ \nConsider the following recurrent sequence: \n\n$$\\left\\{ \\begin{array}{l}\na_0 = 3\\\\\na_1 = 4\\\\\na_{n+2} = 5a_{n+1} - 6a_n,\\;\\text{if}\\;n \\geq 0 \\\\\n\\end{array} \\right.$$\n\nAssume that $b_n$ is another sequence satisfying the \nrecurrence rule\n$$b_{n+2} = 5b_{n+1} - 6b_n,\\;\\text{if}\\;n \\geq 0$$\n(The first two members $b_0,b_1$ are not known.)\n\n{\\bf (A)} Write the first $6$ members of this sequence ($a_0,\\ldots,a_5$).\\\\\n{\\bf (B)} Write the characteristic equation for this sequence.\\\\\n{\\bf (C)} Write the general expression for an arbirary sequence $b_n$\nsatisfying the recurrent expression as a sum of two geometric progressions \n(you can leave unknown coefficients in your answer; just explain which ones they are).\\\\\n{\\bf (D)} Write the formula to compute $a_n$ (that would satisfy \nthe initial conditions $a_0 = 3$ and $a_1 = 4$).\n\n\n\\vspace{10pt}\n{\\bf Question 4.}\\\\ \nConsider this code snippet in Python:\n\n\\begin{verbatim}\nn = 1000\nsum = 0\nfor i in range(1, n*n+1):\n    for j in range(1,i+1):\n        sum += i % j\n\\end{verbatim}\n\nAnd a similar one in R:\n\n\\begin{verbatim}\nn <- 1000\nsum <- 0\nfor (i in 1:(n*n)) {\n    for (j in 1:i) {\n        sum <- sum + i %% j\n    }\n}\n\\end{verbatim}\n\n{\\bf (A)} Explain in human language what this algorithm does.\\\\\n{\\bf (B)} Denote by $f(n)$ the \nnumber of times the variable `sum` is incremented. \nWrite the Big-O-Notation for $f(n)$. Find \na function $g(n)$ such that \n$f(n)$ is in $O(g(n))$. (If there are multiple functions, \npick the one with the slowest growth.)\\\\\n{\\bf (C)} Express the function $f(n)$ precisely - \nhow many times `sum` is incremented in terms of variable $n$. \n\n\n\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 5.}\n\nLet $A$ be the set of all positive divisors of the number $120$ \n(including $1$ and $120$ itself).  \n\n{\\bf (A)} What is the multiplication of all \nnumbers in the set $A$?\\\\\n{\\bf (B)} Express this number as the product of prime powers.\n\n \n \n\n\n\\vspace{10pt}\n{\\bf Question 6.} \n\nDefine the following binary relationship on the set of \ninteger numbers $\\mathbb{Z}$:   \nWe say that $aRb$ (numbers $a,b \\in \\mathbb{Z}$ are in the relation $R$) iff\n$$\\left\\{ \\begin{array}{l}\na - b \\equiv 0\\,(\\text{mod}\\;11)\\\\\na - b \\equiv 0\\,(\\text{mod}\\;12)\\\\\na - b \\equiv 0\\,(\\text{mod}\\;13)\n\\end{array} \\right.$$\n\n\\begin{tabular}{|l|l|l|} \\hline\n{\\bf Item} & {\\bf Statement} & {\\bf True or False?} \\\\ \\hline\n{\\bf (A)} & $R$ is reflexive &  \\\\ \\hline\n{\\bf (B)} & $R$ is symmetric &  \\\\ \\hline\n{\\bf (C)} & $R$ is antisymmetric &  \\\\ \\hline\n{\\bf (D)} & $R$ is transitive &  \\\\ \\hline\n{\\bf (E)} & $aRb$ iff $a=b$ &  \\\\ \\hline\n\\end{tabular}\n\nFor all items where you answered `FALSE`, specify a counterexample\n(values for some numbers that would make the condition true, but the \nconclusion false). \nIf the statement was true, write \"none\".\n\n\n{\\bf (A)} counterexample: $\\ldots$\\\\\n{\\bf (B)} counterexample: $\\ldots$\\\\\n{\\bf (C)} counterexample: $\\ldots$\\\\\n{\\bf (D)} counterexample: $\\ldots$\\\\\n{\\bf (E)} counterexample: $\\ldots$\n\n\n\\vspace{10pt}\n{\\bf Question 7.}\\\\\nFour people $A,B,C,D$ each has his own hat. \nAfter the meeting they leave their \nbuilding in a hurry, everyone grabs some hat at random \nso that all $4!$ permutations of the hats have equal probabilities. \n\nLet the random variable $X$ denote the number of hats that\nwere picked up correctly. (For example, if\nthe hat assignment is this: $(A \\rightarrow A, \nB \\rightarrow B, C \\rightarrow D, D \\rightarrow C)$, then \n$X = 2$, because two people got their own hats.)\n\n{\\bf (A)}  Find $E(X)$ - the expected value of $X$.\\\\\n{\\bf (B)}  Find $V(X)$ - the variance of $X$. \n\n\n\n\\vspace{10pt}\n{\\bf Question 8.}\\\\\nThere was a crooked man who had a crooked 1 euro coin. \nOn lucky days it would flip the *heads* with probability $p=\\frac{2}{3}$, \nand the *tails* with probability $p=\\frac{1}{3}$, but on unlucky days\nit was the opposite ($p(\\mathtt{heads})=\\frac{1}{3}$, but\n$p(\\mathtt{tails})=\\frac{2}{3}$). \nThere were equal probabilities of $\\frac{1}{2}$ for lucky and unlucky days.\n\n\nOne morning he flipped the coin $5$ times and altogether got three {\\em heads}\nand two {\\em tails}.\n\nLet us introduce the following events:\n\n\\begin{itemize}\n\\item $E$ (evidence): Five coin tosses result in three {\\em heads} and two {\\em tails}.\n\\item $H$ (hypothesis): The current day is lucky.\n\\end{itemize}\n\n{\\bf (A)} Find $P(E|H)$ - the conditional probability of $E$ given that the \nday is lucky.\\\\\n{\\bf (B)} Find $P(E|H)\\cdot P(H)$ - the probability that the day \nis lucky and $E$ happens.\\\\\n{\\bf (C)} Find $P(E|\\overline{H})$ - the conditional probability of $E$\ngiven that the day is not lucky.\\\\\n{\\bf (D)} Find $P(E|\\overline{H})\\cdot P(\\overline{H})$ - the probability \nthat the day is unlucky and $E$ happens.\\\\\n{\\bf (E)} Find $P(E)$ - as the sum of two probabilities ($E$ happened\non a lucky day and also $E$ happened on unlucky day).\\\\\n{\\bf (F)} Find the conditional probability $P(H|E)$ - \nthe likelyhood that the croocked man has a lucky day, given \nthat the event $E$ has happened.\n\n\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 9.}\n\n\\begin{figure}[!htb]\n\\center{\\includegraphics[width=2in]{final/final-syntax-tree.png}}\n\\caption{\\label{fig:final-syntax-tree} A tree for an expression.}\n\\end{figure}\n\nThe syntax tree describes an algebraic expression (please note\nthe difference between the unary minus that\nflips the value of the variable $y$ and \nthe binary minus that subtracts the \ntwo subexpressions: $-y$ and $6 \\times 3$). \n\n{\\bf (A)} Write the preorder DFS traversal of\nthis tree.\\\\\n{\\bf (B)} Write the inorder DFS traversal of \nthis tree.\\\\\n{\\bf (C)} Write the postorder DFS traversal of \nthis tree.\n\n{\\em Note.} In all $3$ answers denote the unary \nminus with the tilde sign $\\sim$, \nbut the regular/binary minus with $-$. \n\n\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 10.}\\\\\n\\begin{figure}[!htb]\n\\center{\\includegraphics[width=2in]{final/prim-weighted-graph.png}}\n\\caption{\\label{fig:prim-weighted-graph} A graph with 9 vertices.}\n\\end{figure}\n\nRun the Prim's algorithm on the weighted graph in Figure~\\ref{fig:prim-weighted-graph}, \nstart growing the tree from the vertex $I$. \n\n\\begin{tabular}{|l|l|} \\hline\n{\\bf Step} & {\\bf Newly Added Edge} \\\\ \\hline\n{\\bf Step 1} & \\\\ \\hline\n{\\bf Step 2} & \\\\ \\hline\n{\\bf Step 3} & \\\\ \\hline\n{\\bf Step 4} & \\\\ \\hline\n{\\bf Step 5} & \\\\ \\hline\n{\\bf Step 6} & \\\\ \\hline\n{\\bf Step 7} & \\\\ \\hline\n{\\bf Step 8} & \\\\ \\hline\n\\end{tabular}\n\n\nWhat is the total weight of the obtained Minimum Spanning Tree?\n\n\n\n\n\n\\mbox{}\n\\newpage\n\\subsection{Answers}\n\nEvery problem is worth $15$ points. The total for this final is 150 points.\n\n\n\\vspace{4pt}\n{\\bf Question 1.}\\\\\n\n{\\bf (A)} $X = A \\cup B$ (Boolean OR means set union)\\\\\n{\\bf (B)} $Y = (B \\cap C) \\cup \\overline{A}$ (Boolean and means set intersection; negation means set complement)\\\\\n{\\bf (C)} $|X| = |A| + |B| - |A \\cap B| = 60+40-20 = 80$ (principle of inclusion-exclusion).\\\\\n{\\bf (D)} $|Y|$ is all odd numbers and also four even numbers divisible by $15$\n($30, 60, 90, 120$). The total is $60 + 4 = 64$. \n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Each correct answer is $3$ points (total $12$). \n\\item Explaining both {\\bf (C}) and {\\bf (D)} is another $3$ points (total $3$).\n\\item Using wrong set notation ($\\wedge$ instead of $\\cap$ etc.) divides the number of points in half.\n\\item $68$ instead of $64$ is $2$ points (instead of $3$). \n\\end{itemize}\n}\n\n\n\\vspace{10pt}\n{\\bf Question 2.}\\\\\nIn all the answers the largest and the smallest value are equal, because\nwe know exactly how the two sets intersect; how many elements belong to just\none of the sets $A$, $B$, and how many elements belong to the both sets. \n\n{\\bf (A)} $|A \\cup B| = |A| + |B| - |A \\cap B| = 8+5-3 = 10$ (the principle of inclusion-exclusion).\\\\\n{\\bf (B)} $|A \\times (B \\times B)| = 8 \\cdot 5 \\cdot 5 = 200$\\\\\n(Cartesian product has size that is the product of all participant sets: \none can combine three elements from the sets $A$, $B$ and $B$ in this many ways).\\\\\n{\\bf (C)} $2^{2^3} = 2^8 = 256$ (the number of elements in the powerset \nof any set $X$ can be obtained by raising $2$ to the power $|X|$).\\\\\n{\\bf (D)} $|A \\oplus B| = (8-3) + (5-3) = 7$ (we remove the common elements from both $A$ and $B$). \n\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Each correct answer is $3$ points (total $12$).\n\\item Expressions or verbal explanations of the answers is $3$ points (total $3$).\n\\end{itemize}\n}\n\n\n\n\\vspace{10pt}\n{\\bf Question 3.}\\\\\n{\\bf (A)} $a_0 = 3$,\\\\\n$a_1 = 4$,\\\\\n$a_2 = 5\\cdot 4 - 6 \\cdot 3 = 2$,\\\\\n$a_3 = 5\\cdot 2 - 6 \\cdot 4 = -14$,\\\\  \n$a_4 = 5\\cdot(-14) - 6 \\cdot 2 = -82$,\\\\\n$a_5 = 5\\cdot(-82) - 6 \\cdot (-14) = -326$,\\\\\n$a_6 = 5\\cdot(-326) - 6 \\cdot (-82) = -1138$.\n\n{\\bf (B)} The characteristic equation is obtained, if we try to find $a_n$ \nin the form of a geometric progression $r^n$:   \n$r^{n+2} = 5r^{n+1} - 6r^n,$ or  \n$r^2 -5r + 6 = 0$.   \nIt has two roots: $r_1 = 2$, $r_2 = 3$. \n\n{\\bf (C)} The general form of the expression for any iterative\nsequence $b_n$ satisfying the relationship $b_{n+2} = 5b_{n+1} - 6b_n$ is as follows:\n$$b_n = A \\cdot 2^n + B \\cdot 3^n,$$\nwhere $A,B$ are two constants that depend on the two initial values of the sequence $b_n$. \n\n{\\bf (D)} We need to solve a system of two equations, to ensure that the formula\n$a_n = A \\cdot 2^n + B \\cdot 3^n$ has correct values for $n=0$ and $n=1$. \nWe get the following system: \n$$\\left\\{ \\begin{array}{l} \nA + B = 3,\\\\\n2A + 3B = 4.\\\\\n\\end{array} \\right.$$\nSubstitute $B = 3-A$ into the second equation. We get that \n$2A + 9 - 3A = 4$ and $A = 5$. We also get that $B = -2$. \nTherefore the exact formula to calculate the sequence $a_n$ is this:\n$$a_n  = 5 \\cdot 2^n - 2 \\cdot 3^n,\\;\\text{where}\\;n \\geq 0.$$\nThis actually works, if we plug in the values calculated in {\\bf (A)} for $n = 0,\\ldots,6$.\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Answer in {\\bf (A)} is $4$ points.\n\\item Answer in {\\bf (B)} is $4$ points.\n\\item Answer in {\\bf (C)} is $3$ points.\n\\item Answer in {\\bf (D)} is $4$ points.\n\\end{itemize}\n}\n\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 4.}\\\\\n{\\bf (A)} The algorithm takes all numbers $i$ from $1$ to $n^2$ and\ndivides them by all the smaller numbers $j < i$, and adds up all the obtained remainders.\n\n{\\bf (C)} The outer loop is repeated $n^2$ times. The inner loop is repeated\n$1 + 2 + 3 + \\ldots + n^2$ times. This is an arithmetic progression.\nThe sum of an arithmetic progression is the arithmetic mean of the first and the last \nmember multiplied by the number of members: \n$$f(n) = \\frac{1 + n^2}{2} \\cdot n^2 = \\frac{n^4 + n^2}{2}.$$\n\n{\\bf (B)} $f(n)$ is in $O(n^4)$. Therefore we can take $g(n) = n^4$. We can\npick another $g(n)$ that is multiplied by some nonzero constant\n(such as $\\frac{n^4}{2}$ or $17n^4$ or anything else - that also counts\nas a valid answer).  \nCertainly, $f(n)$ is also in $O(n^k)$ for any $k > 4$, but the function $g(n) = n^4$ \nis the slowest growing. \n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Answer for {\\bf (A)} is $5$ points.\n\\item Answer for {\\bf (B)} (any 4th degree polynomial of $n$) is $5$ points. \nAn attempt to estimate some arithmetic progression with a different upper limit\n(say, $1 + 2 + \\ldots + n$) gets $2$ points.\n\\item Answer for {\\bf (C)} is $5$ points. If the answer is \nprovided just for $n=1000$ (not for any variable), then it is $4$ points.\n\\end{itemize}\n}\n\n\n\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 5.}\\\\\n{\\bf (A)} If expressed as a product of two positive integers $120 = ab$, \none of the divisors $a$ or $b$ would be smaller than $\\sqrt{120} \\approx 11$, and the other\none would be bigger. We can easily list all the ways to express $120$ \nas a product of two integers: \n$$1 \\cdot 120 = 2 \\cdot 60 = 3 \\cdot 40 = 4 \\cdot 30 = $$\n$$= 5 \\cdot 24 = 6 \\cdot 20 = 8 \\cdot 15 = 10 \\cdot 12,$$\nand there are no other factorizations, since all the divisors less than $11$ are\nalready listed.  \nMultiplying them all together would give \n$$(120)^8 = 42998169600000000$$\n\n{\\bf (B)} As a product of prime factors:\n$$(120)^8 = (2^3 \\cdot 3 \\cdot 5)^8 = 2^{24} \\cdot 3^8 \\cdot 5^8.$$\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Correct item {\\bf (A)} is $7$ points (also floating point answers were fine - \nnot all had easy access to the big integer arithmetic). \n\\item Correct item {\\bf (B)} is $8$ points.\n\\end{itemize}\n}\n\n\n\\vspace{10pt}\n{\\bf Question 6.}\\\\\n\n\\begin{tabular}{|l|l|l|} \\hline\n{\\bf Item} & {\\bf Statement} & {\\bf True or False?} \\\\ \\hline\n{\\bf (A)} & $R$ is reflexive & TRUE \\\\ \\hline\n{\\bf (B)} & $R$ is symmetric & TRUE \\\\ \\hline\n{\\bf (C)} & $R$ is antisymmetric & FALSE \\\\ \\hline\n{\\bf (D)} & $R$ is transitive & TRUE \\\\ \\hline\n{\\bf (E)} & $aRb$ iff $a=b$ & FALSE \\\\ \\hline\n\\end{tabular}\n\n\n{\\bf (A)} Counterexample: None\\\\\n{\\bf (B)} Counterexample: None\\\\\n{\\bf (C)} Consider counterexample $a=0$, $b = 11 \\cdot 12 \\cdot 13 = 1716$.  \nWhile it is true that $aRb$ and $bRa$, nevertheless $a \\neq b$.\\\\\n{\\bf (D)} Counterexample: None\\\\\n{\\bf (E)} Counterexample is same as in {\\bf (C)}: $a=0$, $b = 1716$.\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize} \n\\item One correct answer is $2$ points (total $10$).\n\\item Counterexamples for {\\bf (C)} and {\\bf (E)} is $5$ points (they are, in fact, the same). \n\\end{itemize}\n}\n\n\n\n\\vspace{10pt}\n{\\bf Question 7.} Answer: {\\tt 17}\\\\\n\n\\begin{itemize}\n\\item For $1$ of $24$ permutations $X = 4$ (all hats stay in place),\n\\item For $0$ permutations $X = 3$ (it is not possible for exactly three hats to stay in place, because\nthen the 4th hat also returns to its owner),\n\\item For $6$ of $24$ permutations $X = 2$ (there are ${4 \\choose 2} = 6$ ways how to pick $2$ hats\nthat stay in place; and the remaining two hats can switch places only in one way),\n\\item For $8$ of $24$ permutations $X = 1$ (there are ${4 \\choose 1} = 4$ ways how to pick $1$ hat\nthat stays in place; and the remaining three hats can rotate in two ways). \n\\item For the remaining $24 - (1 + 6 + 8) = 9$ permutations $X = 0$ (no hats stay in place).\n\\end{itemize}\n\n{\\scriptsize\n\\begin{table}[h!]\n\\begin{center}\n\\caption{Random Variable $X$ for the Hat Problem}\n\\begin{tabular}{|l|r|r|r|} \\hline\n\\label{table:t1}\n{\\bf Permutation} & $X$ & $X-E(X)$ & $(X-E(X))^2$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{ABCD}}$ & $4$ & $3$ & $9$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{AB}}\\mathtt{DC}$ & $2$ & $1$ & $1$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{A}}\\mathtt{CB}\\textcolor{red}{\\mathtt{D}}$ & $2$ & $1$ & $1$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{A}}\\mathtt{CDB}$ & $1$ & $0$ & $0$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{A}}\\mathtt{DBC}$ & $1$ & $0$ & $0$ \\\\ \\hline\n$\\textcolor{red}{\\mathtt{A}}\\mathtt{D}\\textcolor{red}{\\mathtt{C}}\\mathtt{D}$ & $2$ & $1$ & $1$ \\\\ \\hline\n\n{\\tt BACD} & $2$ & $1$ & $1$ \\\\ \\hline\n{\\tt BADC} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt BCAD} & $1$ & $0$ & $0$ \\\\ \\hline\n{\\tt BCDA} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt BDAC} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt BDCA} & $1$ & $0$ & $0$ \\\\ \\hline\n\n{\\tt CABD} & $1$ & $0$ & $0$ \\\\ \\hline\n{\\tt CADB} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt CBAD} & $2$ & $1$ & $1$ \\\\ \\hline\n{\\tt CBDA} & $1$ & $0$ & $0$ \\\\ \\hline\n{\\tt CDAB} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt CDBA} & $0$ & $-1$ & $1$ \\\\ \\hline\n\n{\\tt DABC} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt DACB} & $1$ & $0$ & $0$ \\\\ \\hline\n{\\tt DBAC} & $1$ & $0$ & $0$ \\\\ \\hline\n{\\tt DBCA} & $2$ & $1$ & $1$ \\\\ \\hline\n{\\tt DCAB} & $0$ & $-1$ & $1$ \\\\ \\hline\n{\\tt DCBA} & $0$ & $-1$ & $1$ \\\\ \\hline\\hline\n{\\bf Mean} & $1$ & $0$ & $1$ \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n}\n\n\n\n\n\n{\\bf (A)} $E(X) = \\frac{1}{24} \\cdot 4 + \\frac{6}{24} \\cdot 2 + \\frac{8}{24} \\cdot 1 = 1$. \nThis means that the expected number of hats that stay in place is exactly $1$.\\\\\n{\\bf (B)} For all $24$ permutations, subtract the value $E(X) = 1$ from \nevery hat experiment outcome. Define $x_1,\\ldots,x_{24}$ - all $24$ values of the \nrandom variable $X$ (exactly one value is $4$, exactly six values are $2$, \nexactly $8$ values are $1$, exactly $9$ values are $0$): \n$$V(X) = \\frac{\\sum_{i=1}^{24} (x_i - 1)^2}{24} = \\frac{24}{24} = 1.$$\n\nTherefore, $V(X) = 1$ (variance also equals $1$, but the unit of measurement \nis not hats but ``hats squared'').\n\n{\\em Note.} $E(X)=1$ is the arithmetic mean over the column $X$, but $V(X)=1$ \nis the arithmetic mean over the column $(X-E(X))^2$ (see Table~\\ref{table:t1}).\n\n{\\scriptsize\n{\\em Grading (theoretically max=20, but most results are not that high).} \n\\begin{itemize} \n\\item Correctly found $E(X)$ is $5$ point.\n\\item Correctly found $V(X)$ is $5$ point.\n\\item Justified computation for $E(X)$ is $5$ points.\n\\item Justified computation for $V(X)$ is $5$ points.\n\\end{itemize}\n}\n\n\n\n\n\\vspace{10pt}\n{\\bf Question 8.} \\\\\n\n{\\bf (A)} $P(E|H)$ is the outcome of the Binomial distribution: \nThere are $n=5$ coin-toss experiments; the probability of success for any single experiment \nis $p = \\frac{2}{3}$ (since we know that the day is lucky and hypothesis $H$ holds). \nTherefore, \n$$P(E|H) = {5 \\choose 3} p^3 (1-p)^2 = 10 \\left( \\frac{2}{3} \\right)^3 \\left( \\frac{1}{3} \\right)^2 = \n\\frac{80}{243}$$\n\n{\\bf (B)} $P(E|H)\\cdot P(H) = \\frac{80}{243}\\cdot\\frac{1}{2}= \\frac{40}{243}$, \nsince $P(H) = \\frac{1}{2}$ (the {\\em a priori} probability of a lucky day is exactly $1/2$). \n\n{\\bf (C)} $P(E|\\overline{H})$ is the outcome of the Binomial distribution: \nAgain, there are $n=5$ coin-toss experiments, but now the probability of a single\nexperiment is just $p = \\frac{1}{3}$. Therefore, \n$$P(E|\\overline{H}) = {5 \\choose 3} p^3 (1-p)^2 = 10 \\left( \\frac{1}{3} \\right)^3 \\left( \\frac{2}{3} \\right)^2 = \n\\frac{40}{243}$$\n\n{\\bf (D)} $P(E|\\overline{H}) \\cdot P(\\overline{H}) = \\frac{40}{243}\\cdot\\frac{1}{2} = \\frac{20}{243}$. \n\n{\\bf (E)} We can compute $P(E)$ as the sum of two mutually incompatible events: \nevent $E$ can happen either on a lucky day or on an unlucky day: \n$$P(E) = P(E|H)\\cdot P(H) + P(E|\\overline{H}) \\cdot P(\\overline{H}) = \n\\frac{40}{243} + \\frac{20}{243} = \\frac{60}{243}.$$\n\n{\\bf (F)} Use Bayes formula: \n\\begin{align}\nP(H|E) = & \\frac{P(E|H) \\cdot P(H)}{P(E|H) \\cdot P(H) + P(E|\\overline{H}) \\cdot P(\\overline{H})} = \\nonumber \\\\\n = & \\frac{P(E|H) \\cdot P(H)}{P(E)} =  \\frac{ \\frac{40}{243}}{ \\frac{60}{243}} = \\frac{2}{3}. \\nonumber\n\\end{align}\n\nBayes formula is intuitive: It shows the proportion of the \nsubcase $P(E|H) \\cdot P(H)$ (i.e. event $E$ hapens on a lucky day) out of the\nwhole probability $P(E) = P(E|H)\\cdot P(H) + P(E|\\overline{H}) \\cdot P(\\overline{H})$\n(i.e. event $E$ happens either on a lucky or unlucky day). \n\n{\\scriptsize\n{\\em Grading (theoretically max=20, but most results are not that high).} \n\\begin{itemize} \n\\item Any item from {\\bf (A)} to {\\bf (E)} is $3$ points. \n\\item Bayes formula or a similar expression finding the reverse conditional probability \nin {\\bf (F)} in $5$ points.\n\\end{itemize}\n}\n\n\n\n\\vspace{10pt}\n{\\bf Question 9.}\\\\\n{\\bf (A)} $\\mathtt{+:-\\sim{}y\\times6\\;3\\;z\\;2}$,\\\\\n{\\bf (B)} $\\mathtt{y\\sim{}-\\,6\\,\\times3:z\\,+\\,2}$,\\\\\n{\\bf (C)} $\\mathtt{y\\sim{}6\\;3\\,\\times-\\,z\\,:2\\,+}$.\n\n{\\bf Note.} In inorder traversal {\\bf (B)} we first visit \nthe first subtree (e.g., $\\mathtt{y}$), and only then the \nparent node (e.g., unary minus $\\sim$). \nSee (Rosen2019, p.811).\n\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Each correctly written expression is \n\\item Item {\\bf (B)} with switched order of the unary minus and its child node $y$ is\n$3$ points instead of $5$.\n\\item Minor typos in single characters get $4$ or $5$ points.\n\\item Any major differences from the correct result do not get points.\n\\end{itemize}\n}\n\n\n%\\vspace{10pt}\n\\newpage\n{\\bf Question 10.}\\\\\n\nWe start from vertex $I$. At every step we \ngrow the tree by a single edge (so that it stays connected\nand the newly added edge has the smallest possible weight). \n\n\n\\begin{tabular}{|l|l|} \\hline\n{\\bf Step} & {\\bf Newly Added Edge} \\\\ \\hline\n{\\bf Step 1} & $IG$, $w=1$ \\\\ \\hline\n{\\bf Step 2} & $IE$, $w=2$ \\\\ \\hline\n{\\bf Step 3} & $ED$, $w=1$ \\\\ \\hline\n{\\bf Step 4} & $DC$, $w=2$ \\\\ \\hline\n{\\bf Step 5} & $CH$, $w=2$ \\\\ \\hline\n{\\bf Step 6} & $GA$, $w=3$ \\\\ \\hline\n{\\bf Step 7} & $AB$, $w=2$ \\\\ \\hline\n{\\bf Step 8} & $IF$, $w=5$ \\\\ \\hline\n\\end{tabular}\n\n\nThe total weight of all added edges (same as the total weight of the MST) is $18$. \n\n\n\\begin{figure}[!htb]\n\\center{\\includegraphics[width=1.5in]{final/prim-weighted-mst.png}}\n\\caption{\\label{fig:prim-weighted-mst} MST edges shown in blue.}\n\\end{figure}\n\n{\\scriptsize\n{\\em Grading.} \n\\begin{itemize}\n\\item Incorrectly adding up weights could subtract $1$ or $2$ points from the total.\n\\item Adding $9$ edge weights (or any other number instead of $8$ weights) and getting incorrect sum is $11$ points (instead of $15$). \n\\item Not showing the edges in answers (or displaying them in an order that differs from Prim's algorithm), \nbut still getting something close to MST is about $8$ points.\n\\end{itemize}\n}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "390bb159ece22228695cda8d93b24840fd91bca2", "size": 23304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/site/discrete-spring2020/questionbase/final.tex", "max_stars_repo_name": "kapsitis/math", "max_stars_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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/site/discrete-spring2020/questionbase/final.tex", "max_issues_repo_name": "kapsitis/math", "max_issues_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-07-20T03:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T21:50:18.000Z", "max_forks_repo_path": "src/site/discrete-spring2020/questionbase/final.tex", "max_forks_repo_name": "kapsitis/math", "max_forks_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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.1878453039, "max_line_length": 135, "alphanum_fraction": 0.6318657741, "num_tokens": 8429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.6189759676732945}}
{"text": "% !TEX root = ../zeth-protocol-specification.tex\n\n\\section{Data structures and representation}\\label{preliminaries:structured-data}\n\n\\newcommand{\\STR}{\\mathsf{STR}}\n\n\\subsection{Structured data}\\label{preliminaries:data-types:formulation}\n\nWhen describing the operations to be performed and the data to be manipulated as part of the protocol, we commonly employ tuples of related data where each element of the tuple has some associated semantic meaning and which must often satisfy some conditions. In this section, we develop a framework to reason about such \\emph{structured} data, where a single datum may consist of one or more logical parts (called \\emph{fields}). The framework is built on top of simple mathematical concepts such as sets, and mappings between them, ensuring that we can always reason about structured data in a rigorous way. We also define notation to aid the specification of structured data, and to refer to specific components of a datum. This will be used extensively in the specification of the protocol.\n\nAs a simple motivating example, consider a protocol that processes data relating to individual people. This fictional system may send and receive data such as \\emph{name}, \\emph{age} and \\emph{address} for a single person, grouping this data into a logical unit. Further, each piece of data must satisfy specific conditions (\\emph{name} must be a series of characters from some alphabet, \\emph{age} must be a positive integer, etc.) We shall make use of this example several times during the formulation below.\n\nIn what follows, let $\\STR = \\smallset{a, b, \\ldots, y, z}^{*}$ (the Kleene star of the \\emph{Roman alphabet}). In our formulation, field names $f_i$ will be elements in this set.\n\n\\begin{remark}\n  Note that a similar formulation could be made using an arbitrary set, such as the same alphabet augmented with specific symbols, or the alphabet of a different language. Our choice of $\\STR{}$ here is for simplicity.\n\\end{remark}\n\nWe begin by defining a data type as a set of values called ``fields'', each with a ``name'' from $\\STR$. Abstract sets are used to constrain the values of each field.\n\n\\begin{definition}[Structured Data Type]\\label{preliminaries:def:datatype}\n  Let $f_0, \\ldots, f_{n-1}$ be $n$ distinct elements of $\\STR$ and let $V_0, \\ldots, V_{n-1}$ be sets, for some $n \\in \\NN$. We define \\emph{the structured data type $\\datatypestyle{T}$ with fields $\\smallset{(f_i, V_i)}_{i \\in [n]}$} to be a set of values:\n  \\[\n    \\datatypestyle{T} = V_0 \\times \\cdots \\times V_{n-1}\n  \\]\n  with associated post-fix ``dot'' operators $.f_i : \\datatypestyle{T} \\to V_i$ for $i = 0, \\ldots, n-1$, acting on values $\\mathbf{x} \\in \\datatypestyle{T}$ to extract the individual elements:\n  \\[\n    \\mathbf{x}.f_i = v_i \\text{, where } \\mathbf{x} = (v_0, \\ldots, v_{n-1}) \\in \\datatypestyle{T}\n  \\]\n\n  Here, we say that the $i$-th field has \\emph{field name} $f_i$, with \\emph{value set} $V_i$. Each ``dot'' operator $.f_i$ \\emph{extracts} the $i$-th component, or the \\emph{value with field name $f_i$}.\n\\end{definition}\n\n\\begin{example}\\label{preliminaries:eg:datatype-person}\n  Consider our example protocol that processes information about people. A potentially useful structured data type $\\datatypestyle{Person}$ may be defined with fields:\n  \\[\n    \\smallset{ (\\varstyle{name}, \\STR), (\\varstyle{age}, \\NN), (\\varstyle{height}, \\RR^+) }\n  \\]\n  Values $\\mathbf{p}$ in $\\datatypestyle{Person}$ are simply tuples in $\\STR{} \\times \\NN \\times \\RR^+$, with semantic meaning (name, age, height) assigned to each component of $\\mathbf{p}$.\n\n  Examples of valid elements in $\\datatypestyle{Person}$ include $\\mathbf{a} = (\\varstyle{alice}, 28, 1.65)$ and $\\mathbf{b} = (\\varstyle{bob}, 31, 1.74)$, where the following equalities hold:\n  \\begin{align*}\n    \\mathbf{a}.\\varstyle{name} &= \\varstyle{alice}, \\\\\n    \\mathbf{b}.\\varstyle{age} &= 31, \\\\\n    \\mathbf{b}.\\varstyle{height} &= 1.74;\n  \\end{align*}\n\\end{example}\n\nFor clarity, structured data types may be specified using tables of names, descriptions and value sets, rather than sets of the form $\\smallset{(f_i, V_i)}_{i \\in [n]}$. Similarly, it is frequently convenient to include the \\emph{field names} alongside values when specifying structured data values.\n\n\\begin{example}\\label{preliminaries:eg:datatype-person-table}\n  $\\datatypestyle{Person}$ from \\cref{preliminaries:eg:datatype-person} might be described in table-form as follows:\n  \\begin{table}[H]\n    \\centering\n    \\begin{tabular}{cp{15em}c}\n      Field                & Description        & Data type \\\\ \\toprule\n      $\\varstyle{name}$   & Name of the person & $\\STR{}$ \\\\ \\midrule\n      $\\varstyle{age}$    & Age in years       & $\\NN$ \\\\ \\midrule\n      $\\varstyle{height}$ & Height in meters   & $\\RR^+$ \\\\ \\midrule\n    \\end{tabular}\n  \\end{table}\n\\end{example}\n\n\\begin{example}\\label{preliminaries:eg:datatype-person-value-with-field-names}\n  The values $\\mathbf{a}$ and $\\mathbf{b}$ in \\cref{preliminaries:eg:datatype-person} might be written as follows:\n  \\begin{align*}\n    \\mathbf{a} &=\n    \\{\\varstyle{name}:\\: \\varstyle{alice}, \\; \\varstyle{age}:\\: 28, \\; \\varstyle{height}:\\: 1.65\\} \\\\\n    \\mathbf{b} &=\n    \\{\\varstyle{name}:\\: \\varstyle{bob}, \\; \\varstyle{age}:\\: 31, \\; \\varstyle{height}:\\: 1.74\\}\n  \\end{align*}\n\\end{example}\n\n\\begin{remark}[``dot'' operators in assignment]\\label{preliminaries:rem:dot-assignment}\n  The ``dot'' operators may be used in algorithm descriptions to indicate \\emph{assignment to a specific component}. For example $\\mathbf{a}.\\varstyle{age} \\gets 29$ means that the value of the $\\varstyle{age}$ field of $\\mathbf{a}$ is replaced by the value $29$.\n\n  Formally, for a structured data type $\\datatypestyle{T}$ with fields $\\smallset{(f_i, V_i)}_{i \\in [n]}$ where $\\mathbf{x} = (v_0, \\ldots, v_{n-1}) \\in \\datatypestyle{T}$ and $v_i^\\prime \\in V_i$:\n  \\[\n    \\mathbf{x}.f_i \\gets v_i^\\prime\n  \\]\n  is equivalent to:\n  \\[\n    \\mathbf{x} \\gets (v_0, \\ldots, v_{i-1}, v_i^\\prime, v_{i+1}, \\ldots, v_{n-1})\n  \\]\n\\end{remark}\n\nWe define one further operator and related assignment notation, convenient in cases where $V_i = X^m$ for sets $X$ and $m \\in \\NN$.\n\\begin{definition}[Square bracket operator]\\label{def:squareb-operator}\n  For $m \\in \\NN$ and set $X$, define the operator $[\\ ] : X^m \\times [m] \\to X$ as:\n  \\[\n    \\mathbf{x}[i] = x_i \\text{ where } \\mathbf{x} = (x_0, \\ldots, x_m)\n  \\]\n  For the set $X^*$, the operator takes the form $[\\ ] : X^* \\times \\NN \\to X$, defined as:\n  \\[\n    \\mathbf{x}[i] =\n    \\begin{cases}\n        x_i & \\text{ if } \\len{\\mathbf{x}} > i \\text{ where } \\mathbf{x} = (x_0, \\ldots) \\\\\n        \\bot & \\text{otherwise}\n    \\end{cases}\n  \\]\n\\end{definition}\n\n\\begin{remark}[Square bracket operators in assignment]\n  Similarly to \\cref{preliminaries:rem:dot-assignment}, we develop assignment notation for the square bracket operator $[\\ ]$.\n  Let $\\mathbf{x} = (x_0, \\ldots, x_{m-1})$ be a member of $X^m$, and $x_i^\\prime$ be some element in $X$. The statement:\n  \\[\n    \\mathbf{x}[i] \\gets x_i^\\prime\n  \\]\n  is equivalent to:\n  \\[\n    \\mathbf{x} \\gets (x_0, \\ldots, x_{i-1}, x_i^\\prime, x_{x+1}, \\ldots, x_{m-1})\n  \\]\n  Informally, this can be interpreted as replacing the $i$-th component of $\\mathbf{x}$ with $x_i^\\prime$.\n\\end{remark}\n\n\\begin{remark}[Deep structures and chained ``dot'' operators]\nConsider the case of structured data $\\datatypestyle{T}$ with fields $\\{(f_i, V_i)\\}_{i \\in [n]}$ for $n \\in \\NN$. Let $\\datatypestyle{T^\\prime}$ be another structured data type with fields $\\{(f^\\prime_i, V^\\prime_i)\\}_{i \\in [n^\\prime]}$ for $n^\\prime \\in \\NN$, and assume that $V_j = \\datatypestyle{T^\\prime}$ for some $j \\in [n]$. Informally, the values of the $j$-th field of elements of $\\datatypestyle{T}$ are themselves structured data of type $\\datatypestyle{T^\\prime}$.\n\nIn this case, ``dot'' operators may be \\emph{chained}, so that $\\mathbf{x}.f_j.f^\\prime_k$ refers to the $k$-th field $v^\\prime_k$ of the $j$-th field $v_j$ of $\\mathbf{x} \\in \\datatypestyle{T}$.\n\\end{remark}\n\n\\begin{example}\\label{preliminaries:eg:datatype-person-deep}\n  Define a structured data type $\\datatypestyle{Address}$ with fields $(\\varstyle{country}, \\STR{}), (\\varstyle{zipcode}, \\STR{})$. We redefine the structured data type $\\datatypestyle{Person}$ from \\cref{preliminaries:eg:datatype-person}, with an extra field $\\varstyle{address}$ of type $\\datatypestyle{Address}$. That is, $\\datatypestyle{Person}$ is the structured data type with fields:\n  \\begin{table}[H]\n    \\centering\n    \\begin{tabular}{cp{15em}c}\n      Field                 & Description           & Data type \\\\ \\toprule\n      $\\varstyle{name}$    & Name of the person    & $\\STR{}$ \\\\ \\midrule\n      $\\varstyle{age}$     & Age in years          & $\\NN$ \\\\ \\midrule\n      $\\varstyle{height}$  & Height in meters      & $\\RR^+$ \\\\ \\midrule\n      $\\varstyle{address}$ & Address of the person & $\\datatypestyle{Address}$ \\\\ \\midrule\n    \\end{tabular}\n  \\end{table}\n  An example element $\\mathbf{a}$ in $\\datatypestyle{Person}$ is:\n  \\begin{align*}\n    \\mathbf{a} =\n    \\{ &\\\\\n       & \\varstyle{name}:\\: \\varstyle{alice}, \\\\\n       & \\varstyle{age}:\\: 28, \\\\\n       & \\varstyle{height}:\\: 1.65, \\\\\n       & \\varstyle{address}:\\: (\\varstyle{country}:\\: \\varstyle{UK}, \\varstyle{zipcode}:\\: \\varstyle{SW1A})\\\\\n    \\}\n  \\end{align*}\n  In this case, the following equalities using the dot and square bracket operators all hold:\n  \\begin{align*}\n    & \\mathbf{a}.\\varstyle{name} = \\varstyle{alice} \\\\\n    & \\mathbf{a}.\\varstyle{height} = 1.65 \\\\\n    & \\mathbf{a}.\\varstyle{address}.\\varstyle{country} = \\varstyle{UK} \\\\\n    & \\mathbf{a}.\\varstyle{address}.\\varstyle{zipcode} = \\varstyle{SW1A} \\\\\n    & \\mathbf{a}.\\varstyle{address}.\\varstyle{country}[1] = \\varstyle{K}\n  \\end{align*}\n\\end{example}\n\n\\subsection{Representations}\\label{preliminaries:data-types:representation}\n\nThe binary alphabet $\\bin$, denoted $\\BB$, is used to represent the presence or absence of an electrical signal in a computer. In fact, every piece of information in a computer is represented as a string of bits.\nWe assume the existence of an efficient binary representation for some set of primitive datatypes (such as the natural numbers $\\NN$, or alphanumeric characters). Structured data types built up from primitive types (as described above) can then recursively be assigned similarly efficient representations.\nThis is used to define the following functions to \\emph{encode} data to its bit-string representation, and to \\emph{decode} such bit-strings back to elements of the original type.\n\n\\begin{definition}\n  For a set $X$ of values which are to be represented as bit strings, we define functions:\n  \\begin{align*}\n    \\encode{}{X} &: X \\to \\BB^* \\\\\n    \\decode{}{X} &: \\BB^* \\to X \\cup \\bot\n  \\end{align*}\n  satisfying\n  \\[\n    \\decode{\\encode{x}{X}}{X} = x\\ \\forall x \\in X\n  \\]\n  to be the functions which encode (resp.~decode) elements of $X$ into (resp.~from) the bit-string representations chosen above.\n  We note that $\\decode{}{X}$ may return $\\bot$ in the case that the input bit-string is malformed.\n\\end{definition}\n\nWithout ambiguity, we overload the functions $\\encode{}{}$ and $\\decode{}{}$ to mean $\\encode{}{X}$ and $\\decode{}{X}$ where the set $X$ is clear from context.\n\nIn the following sections, we assume that elements of $\\NN$ are encoded as big-endian binary numbers in the natural way. We denote by $\\NN_{b}$ the set of natural numbers that can be uniquely encoded in this way using $b$ bits (possibly with padding). In other words,\n\\[\n  \\NN_{b} = \\smallset{x \\in \\NN\\ \\suchthat\\ \\encode{x}{\\NN} \\in \\BB^{b}}\n\\]\n", "meta": {"hexsha": "2ef683a9783ef692eb45ff64b5311a37b1d66175", "size": 11629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chap01-sec01.tex", "max_stars_repo_name": "clearmatics/zeth-specifications", "max_stars_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-29T18:22:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-29T18:22:00.000Z", "max_issues_repo_path": "chapters/chap01-sec01.tex", "max_issues_repo_name": "clearmatics/zeth-specifications", "max_issues_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-10-27T10:41:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-16T10:57:05.000Z", "max_forks_repo_path": "chapters/chap01-sec01.tex", "max_forks_repo_name": "clearmatics/zeth-specifications", "max_forks_repo_head_hexsha": "ba29c67587395f5c7b26b52ee7ab9cba12f1cc6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-26T04:51:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-26T04:51:29.000Z", "avg_line_length": 64.6055555556, "max_line_length": 794, "alphanum_fraction": 0.6834637544, "num_tokens": 3487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.72487026428967, "lm_q1q2_score": 0.6189759602175617}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\n\\title{Common activation functions used in neural net}\n\\author{}\n\\date{}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amsmath,amssymb}\n\\usepackage[left=2.5cm,right=2.5cm,top=1cm,bottom=1.25cm]{geometry}\n\\usepackage{hyperref}\n\\usepackage{multicol}\n\\usepackage[export]{adjustbox}\n\\usepackage{sidecap}\n\\hypersetup{colorlinks=true,urlcolor=blue}\n\\renewcommand{\\thesubsection}{\\arabic{subsection}.}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Activation function}\nThe activation function of a node in an artificial neural network converts an input signal to an output signal. This is loosely based on the biological neuron where the activation function decides whether or not to pass the signal accumulated in a cell body to the next cell.\n\n\n\\section*{Why we need activation functions}\n\n\\begin{itemize}\n    \\item Activation functions determine the firing potential of a neuron and can act as a decision function(i.e., whether the neuron should fire or not).\n    \\item  A feedforward neural network with linear activation and any number of hidden layers is equivalent to just a linear neural neural network with no hidden layer. For example lets consider the neural network in figure with two hidden layers and no activation:\\\\\n    \\includegraphics[scale=0.75, center]{neural_net_three_layers.png}\n    \\begin{align*}\n        y &= h_2 W_3 + b_3 \\\\\n          &= (h_1 W_2 + b_2) W_3 + b_3 \\\\\n          &= h_1 W_2 W_3 + b_2 W_3 + b_3 \\\\\n          &= (x W_1 + b_1) W_2 W_3 + b_2 W_3 + b_3 \\\\\n          &= x W_1 W_2 W_3 + b_1 W_2 W_3 + b_2 W_3 + b_3 \\\\\n          &= x W' + b'\n    \\end{align*}\n    So we could replace this neural net with a single layer neural net.This can be extended to $n$ layers. This indicates adding layers doesn't increase the approximation power of a linear neural net at all. We need non-linear activation functions to approximate non-linear functions and most real world problems are highly complex and non-linear. In fact when the activation function is non-linear, then a two-layer neural network with sufficiently large number of hidden units can be proven to be a universal function approximator.\n    \\item Activation functions are also needed for squashing the unbounded linearly weighted sum from neurons.\n\\end{itemize}\n\n\\section*{Some desirable properties of activation functions}\n\\begin{itemize}\n    \\item \\textit{Nonlinear:} To approximate complex non-linear functions the activation function also needs to be non-linear.\n    \\item \\textit{Continuously differentiable:} This is desirable for gradient based optimization methods.\n    \\item \\textit{Monotonic:} When the activation function is monotonic, the error surface associated with a single-layer model is guaranteed to be convex.\n    \\item \\textit{Approximates Identity function($f(x)=x$) near origin:} When activation functions have this property, the neural network will learn efficiently when its weights are initialized with small random values. This is because gradient near origin will be close to $1$. When the activation function does not approximate identity near the origin, special care must be used when initializing the weights. Activation functions where $f(0)=0$, $f'(0)=1$ and $f'(x)$ is continuous at $0$ have this property.  \n    \\item \\textit{Range:} When the range of activation function is finite, gradient-based training methods tend to be more stable because only limited range of values affect gradient significantly. When the range is infinite, training is generally more efficient(faster) because most of the values contribute significantly to gradients. In the latter case, smaller learning rates are typically necessary.  \n    \n\\end{itemize}\n\n\\section*{Common activation functions}\n\n\\subsection{Sigmoid}\n\\begin{itemize}\n    \\item Equation: $f(x) = \\sigma(x) = \\frac{1}{1+e^{-x}}$\n    \\item Derivative: $f'(x) = \\sigma(x) (1 - \\sigma(x))$\n    \\item Graph:\\\\ \\includegraphics[ center]{sigmoid.png}\n    \\item Pros\n    \\begin{enumerate}\n        \\item Its non-linear, continuously differentiable, monotonic.\n        \\item Output is in the range of $[0, 1]$ so it can be used as a binary classifier or estimate probability.\n        \\item The bounded output means the activations won't blow up.\n    \\end{enumerate}\n    \\item Cons\n    \\begin{enumerate}\n        \\item Towards either end of the sigmoid function the change in activation is very small as input is changed and gradient is very close to zero. This gives rise to the \\textbf{vanishing gradients problem}. This means that neurons in those regions will get very little gradient update and become saturated. The learning will become very slow.\n        \\item Sigmoid outputs are not zero centered and it does not approximate identity function near origin.\n        \\item Exponential function is computationally expensive.\n    \\end{enumerate}\n\\end{itemize}\n\n\\subsection{Tanh}\n\\begin{itemize}\n    \\item Equation: $f(x) = \\tanh(x) = \\frac{e^x-e^{-x}}{e^x+e^{-x}}$\n    \\item Derivative: $f'(x) = 1 - f(x)^2$\n    \\item Graph:\\\\ \\includegraphics[ center]{tanh.png}\n    \\item Pros\n    \\begin{enumerate}\n        \\item Its non-linear, continuously differentiable, monotonic.\n        \\item Output is bounded in the range of $[-1, +1]$ so the activation won't blow up.\n        \\item It approximates identity function near origin. Optimization is easier than sigmoid because gradient is steeper.\n    \\end{enumerate}\n    \\item Cons\n    \\begin{enumerate}\n        \\item Suffers vanishing gradients problem just like sigmoid. \n        \\item Also computationally expensive.\n    \\end{enumerate}\n\\end{itemize}\n\n\\subsection{ReLU(Rectified Linear Unit)}\n\\begin{itemize}\n    \\item Equation: \n    \\begin{equation*}\n        f(x)=\\begin{cases}\n        x, & \\text{$x>=0$}.\\\\\n        0, & \\text{$x<0$}.\n        \\end{cases}\n    \\end{equation*}\n    \\item Derivative:\n    \\begin{equation*}\n        f'(x)=\\begin{cases}\n        1, & \\text{$x>=0$}.\\\\\n        0, & \\text{$x<0$}.\n        \\end{cases}\n    \\end{equation*}\n    \\item Graph:\\\\ \\includegraphics[ center]{relu.png}\n    \\item Pros\n    \\begin{enumerate}\n        \\item Its non-linear, monotonic.\n        \\item The gradient does not saturate like sigmoid or tanh so it rectifies the vanishing gradient problem. \n        \\item The second derivative of the rectifying operation is $0$ almost everywhere, and the derivative of the rectifying operation is $1$ everywhere that the unit is active. This means that the gradient direction is far more useful for learning than it would be with activation functions that introduce second-order effects(sigmoid and tanh).\n        \\item It is computationally inexpensive.\n    \\end{enumerate}\n    \\item Cons\n    \\begin{enumerate}\n        \\item When the activation is zero for a neuron it doesn't get any further update via gradient descent. So such neuron will stop responding to variations in error or input signal.This is called \\textbf{dying relu problem}. When initializing the parameters of the network, it can be a good practice to set all elements of bias to a small, positive value, such as $0.1$. This makes it very likely that the rectified linear units will be initially active for most inputs in the training set and allow the derivatives to pass through.\n        \\item It cannot be used in the output layer of a network. We usually use sigmoid(binary) or softmax(multiclass) for classification task and linear function for regression task.\n        \\item The range of relu is $[0, \\infty)$. This means it can blow up the activation.\n        \\item ReLU is not differentiable at $x=0$. However it sill works for gradient based learning in practice because neural training training algorithms do not usually arrive at a local minimum of the cost function, but instead merely reduce its value significantly and gradient based optimization on a digital computer is subject to numerical error anyway.  \n    \\end{enumerate}\n\\end{itemize}\n\n\\subsection{Leaky ReLU and Parametric ReLU}\n\\begin{itemize}\n    \\item Equation: \n    \\begin{equation*}\n        f(x)=\\begin{cases}\n        x, & \\text{$x>=0$}.\\\\\n        \\alpha x, & \\text{$x<0$}.\n        \\end{cases}\n    \\end{equation*}\n    $\\alpha=0.01$ for Leaky ReLU\n    \\item Derivative:\n    \\begin{equation*}\n        f'(x)=\\begin{cases}\n        1, & \\text{$x>=0$}.\\\\\n        \\alpha, & \\text{$x<0$}.\n        \\end{cases}\n    \\end{equation*}\n    \\item Graph:\\\\ \\includegraphics[center]{leaky_relu.png}\n    \\item Pros\n    \\begin{enumerate}\n        \\item It has non-zero slope everywhere and so doesn't have the dying relu problem.\n    \\end{enumerate}\n    \\item Cons\n    \\begin{enumerate}\n        \\item The result is not always consistent and in practice doesn't always perform better than plain relu.\n    \\end{enumerate}\n\\end{itemize}\n\n\\subsection{ELU(Exponential Linear Unit)}\n\\begin{itemize}\n    \\item Equation: \n    \\begin{equation*}\n        f(x)=\\begin{cases}\n        x, & \\text{$x>0$}.\\\\\n        \\alpha (e^x-1), & \\text{$x<=0$}.\n        \\end{cases}\n    \\end{equation*}\n    \\item Derivative:\n    \\begin{equation*}\n        f'(x)=\\begin{cases}\n        1, & \\text{$x>=0$}.\\\\\n        \\alpha e^x, & \\text{$x<0$}.\n        \\end{cases}\n    \\end{equation*}\n    \\item Graph:\\\\ \\includegraphics[center]{elu.png}\n    \\item Pros\n    \\begin{enumerate}\n        \\item It doesn't have dying relu problems.\n        \\item It becomes smooth slowly for negative inputs unlike relu which sharply becomes smooth.\n    \\end{enumerate}\n    \\item Cons\n    \\begin{enumerate}\n        \\item Output becomes saturated for large negative values and gradient becomes zero for neurons in that region.\n    \\end{enumerate}\n\\end{itemize}\n\n\n\\end{document}\n", "meta": {"hexsha": "56e00d10c427d19da706b2140eb6e2b095e51113", "size": 9637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/notes/Common activation functions used in neural net/main.tex", "max_stars_repo_name": "xashru/deep-learning-distilled", "max_stars_repo_head_hexsha": "3b787710ee49dd53f5db7a62d91046356d6c5a9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-10-27T16:40:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-01T13:48:13.000Z", "max_issues_repo_path": "source/notes/Common activation functions used in neural net/main.tex", "max_issues_repo_name": "xashru/deep-learning-distilled", "max_issues_repo_head_hexsha": "3b787710ee49dd53f5db7a62d91046356d6c5a9e", "max_issues_repo_licenses": ["MIT"], "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/notes/Common activation functions used in neural net/main.tex", "max_forks_repo_name": "xashru/deep-learning-distilled", "max_forks_repo_head_hexsha": "3b787710ee49dd53f5db7a62d91046356d6c5a9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-03-10T14:42:40.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-17T06:46:54.000Z", "avg_line_length": 51.5347593583, "max_line_length": 537, "alphanum_fraction": 0.7056137802, "num_tokens": 2455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914975839675, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.618949764516823}}
{"text": "%---------------------------Taper---------------------------\n\\section{Taper\\label{s:hex-taper}}\n\nTaper measures the maximum ratio of a cross-derivative to its shortest associated principal axis.\nGiven a pair of principal axes $f$ and $g$, the taper is\n\\[\n  T_{fg} = \\frac{\\normvec{ X_{fg}}}{\\min\\left\\{\\normvec{ X_f},\\normvec{X_g}\\right\\}}\n\\]\nThe metric is then the maximum taper of any cross-derivative\n\\[\n  q = \\max\\left\\{ T_{12}, T_{13}, T_{23} \\right\\}\n\\]\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2}$ or $\\normvec{X_3} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{taper}%\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{tf:89}}%                  Citation\n{v\\_hex\\_taper}%                              Verdict function name\n", "meta": {"hexsha": "acecc7bf849bd6d1c520ca42d374b66a36a8f206", "size": 997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexTaper.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/HexTaper.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/HexTaper.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.5416666667, "max_line_length": 101, "alphanum_fraction": 0.4894684052, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6188063925654048}}
{"text": "\\chapter{Auxin-PIN dynamic system contribution to pattern formation}\\label{cap:4}\nAs stated in the introduction, previous results on root-hair initiation \\cite{intra2, intra1_R, phdthesis:victor} discussed the importance of auxin gradient in determining pattern formation. The main assumption consists in assuming a certain, fixed in time, auxin distribution. Similarly, the results we proposed in Section \\ref{cap3:results} imply a-priori a hormone auxin concentration.\n\nAuxin hormone actually is governed by a differential problem and various studies regarding auxin evolution in space and time are available in the literature \\cite{plant:Alim, plant:Farcot, plant:Mironova}. Concentration-based and flux-based models are used to describe auxin trasport and PIN distribution on cell membrane.\n\nThe possibility to couple spatially-extended cellular models for ROPs pattern formation with concentration or flux-based models for auxin dynamics has not been examined yet, as far as we know.\n\nIn this chapter we develop a semi-implicit method to solve a particular model chosen for auxin dynamics, taken from \\cite{plant:Farcot}, and show on a two cells system how active ROPs spot formation can be affected by this dynamics. The overall results confirm the importance for ROPs dynamics when modelling communication between cells.\n\n\n\\section{Physical model}\nTaking into account a pluricellular system of N cells, the root-hair cells are projected onto a 2D rectangular domain as done in Section \\ref{sec:PluriMod}. We define for each cell $\\Omega_i$ the set of neighboring cells $\\mathcal{N}_i$. Auxin-PIN dynamics is meaningful only when considering a pluricellular system, since auxin model under study in \\cite{plant:Farcot} considers the transport and diffusion of auxin driven by a difference in auxin and PIN from one cell to the others. In order to describe the dynamics of auxin transport, the following variables are defined:\n\\begin{itemize}\n  \\item $a_i [mol \\ m^{-3}]$, the auxin concentration in cell $\\Omega_i$;\n  \\item $\\Tilde{P}_{ij} [mol \\ m^{-2}]$, the concentration of transporter proteins PIN facilitating transport from cell $\\Omega_i$ to cell $\\Omega_j$.\n\\end{itemize}\nAnother important variable in the flux-based model is $\\Phi_{ij}$. It represents the flux of auxin from cell $\\Omega_i$ to cell $\\Omega_j$, supposed to induce the insertion of PIN proteins $\\Tilde{P}_{ij}$.\n\\begin{figure}\n  \\centering\n  \\includegraphics[scale=0.5]{cap4/fig_farcot.png}\n  \\caption{Two neighboring cells with concentrations of auxin, carriers proteins and flux from $i$ to $j$; figure taken from \\cite{plant:Farcot}.}\n  \\label{fig:farcot}\n\\end{figure}\nThe flux is modelled through the combination of two contributions: the free diffusion towards neighboring cells $j \\in \\mathcal{N}_i$, and the active transport by the transporter (PIN) proteins. Variation of auxin $a_i$ in cell $\\Omega_i$ is therefore influenced by fluxes from neighboring cells together with a local production term and a decay term.\n\nOn the other hand, PIN variation is due to insertion and removal of PIN $\\Tilde{P}_{ij}$ and to insertion induced by flux $\\Phi_{ij}$ inside cell $\\Omega_i$.\n\nTo sum up, the dynamics of auxin and carriers proteins PIN in each cell $\\Omega_i$ with $i \\in \\{ 1, ..., N \\}$ can be written as the following system of coupled ordinary differential equations:\n\\begin{equation}\\begin{aligned}\n\\begin{cases}\n  {\\displaystyle d a_i\\over\\displaystyle d t} & = {\\displaystyle 1 \\over \\displaystyle V_i} \\sum_{j=1}^{N} A_{ij} \\Phi_{ij} +k - \\delta a_i \\\\[8pt]\n  {\\displaystyle d \\Tilde{P}_{ij}\\over\\displaystyle d t} & = h\\left(\\Phi_{ij}\\right) + \\rho_0 - \\mu \\Tilde{P}_{ij},\n\\end{cases}\n\\end{aligned} \\end{equation}\nwhere coefficient $ k [mol m^{-3} s^{-1}]$ is the constant rate auxin is produced, $ \\delta [s^{-1}]$ is the decay rate, $\\rho_0 [mol m^{-2} s^{-1}]$ is the insertion rate of PIN and $\\mu [s^{-1}]$ the corresponding removal rate; $V_i$ is the volume characterizing cell $\\Omega_i$ and $A_{ij}[m^{-2}]$ is the exchange surface area between cell $\\Omega_i$ and $\\Omega_j$. If cell $\\Omega_i$ and $\\Omega_j$ are not neighbours, $A_{ij = 0}$ and $A_{ij} = A_{ji}$ holds for all cells. On the contrary, it is not necessarily true that $\\Tilde{P}_{ij}$  and $\\Tilde{P}_{ji}$ are equal \\cite{plant:Farcot, plant:Alim}.\n\nFlux from cell $\\Omega_i$ to cell $\\Omega_j$ is modeled as follows:\n\\begin{equation}\n  \\Phi_{ij} = \\left( T \\Tilde{P}_{ij} + \\Tilde{D}_a \\right) a_i - \\left( T \\Tilde{P}_{ji} + \\Tilde{D}_a \\right) a_j,\n\\end{equation}\nbeing $\\Tilde{D}_a [ms^{-1}]$ the auxin diffusion coefficient and $T [m^{-3} mol^{-1} s^{-1}]$ the auxin transport efficiency coefficient.\n\nThe intensity of PIN insertion due to the feedback of the auxin flux is described by a continuous, increasing function $h: \\mathds{R} \\rightarrow \\mathds{R}_+$. Since the active trasport is directional, when more auxin comes in than goes out, no additional PIN is inserted. This modelling consideration in terms of function $h$ implies that:\n\\begin{equation}\n  h\\left(\\Phi_{ij}\\right) = 0 \\text{ whenever } \\Phi_{ij} \\leq 0 \\text{ and } h\\left(\\Phi_{ij}\\right) > 0 \\text{ for } \\Phi_{ij} > 0.\n\\end{equation}\n\nThe original system of equations can be rescaled and simplified. In particular, under the assumptions of cells having same volume $V =V_i$ and exchange surface areas $A = A_{ij}$, rescaling properly the diffusion coefficient $D_a$ and variables $P_{ij}$, a new system is obtained. Thus, the final system of equations we work on is:\n\\begin{equation}\\label{eq:Sys_auxPIN}\\begin{aligned}\n\\begin{cases}\n  {\\displaystyle d a_i\\over\\displaystyle d t} & = \\sum_{j \\in \\mathcal{N}_i} \\displaystyle \\Phi_{ji} +k - \\delta a_i \\\\[8pt]\n  {\\displaystyle d P_{ij}\\over\\displaystyle d t} & = h\\left(\\Phi_{ij}\\right) - \\mu P_{ij},\n\\end{cases}\n\\end{aligned} \\end{equation}\nwhere flux from cell $\\Omega_i$ to cell $\\Omega_j$ is redefined as follows:\n\\begin{equation}\n  \\Phi_{ij} = \\left( P_{ij} + D_a \\right) a_i - \\left( P_{ji} + D_a \\right) a_j,\n\\end{equation}\nbeing $P_{ij}$ and $D_a$ dimentionally different from the original quantities $\\Tilde{P}_{ij}$ and $\\Tilde{D}_a$.\n\nDifferent sets of parameters, taken from \\cite{plant:Farcot}, necessary for a complete simulation of the system \\eqref{eq:Sys_auxPIN} are collected in Table \\ref{tab:setprm_aux} .\n\\begin{table}\n    \\caption*{\\textbf{Sets of parameters}}\n    \\centering\n    \\begin{tabular}{| p{5em} |c| c c c c|}\n    \\hline\n    \\rowcolor{bluepoli!40} % comment this line to remove the color\n    \\textbf{Variable} & \\textbf{Measure Unit} & \\textbf{Value} & & & \\T\\B \\\\\n    \\hline \\hline\n     &  & F4 & F5 & F6 & F7 \\T\\B \\\\\n    $k$ & $mol \\cdot m^{-3} s^{-1} $ & 0.1 & 10 & 0.5 & 0.5 \\\\\n    $\\delta$ & $s^{-1} $ & 1.0 & 1 & 0.5 & 0.5\\\\\n    $D_a$ & $m \\cdot s^{-1} $ & 1.0 & 0.1 & 0.3 & 7.0\\\\\n    $\\mu$ & $s^{-1}$ & 1.0 & 0.1 & 1.0 & 1.5\\\\\n    $\\rho$ &  &  &  & \\{2; 2.3; 2.7 \\} & 2.8\\\\\n    \\hline\n    \\end{tabular}\n    \\\\[10pt]\n    \\caption{Table with the four sets of parameters used in auxin-PIN model, taken from \\cite{plant:Farcot}.}\n    \\label{tab:setprm_aux}\n\\end{table}\n\nAnother important feature for characterizing auxin transport model is the definition of a function to describe the feedback of the auxin flux into PIN insertion $h$. Typical choices of $h$ found in literature are:\n\\begin{equation}\\begin{aligned}\n    h\\left(\\Phi \\right) & = \\rho \\frac{\\Phi^n}{\\theta^n + \\Phi^n}, &\\text{ with } \\theta \\text{ saturating coefficient} \\\\\n    h\\left(\\Phi \\right) & = \\rho \\Phi^n, &\\text{ without saturating coefficient, }\n\\end{aligned} \\end{equation}\n$\\rho$ being a scaling coefficient.\n\nThe function $h(x) = \\frac{x^5}{5^5 + x^5} \\ \\mathbb{1}\\{x>0 \\}$ has been chosen for parameters sets F4 and F5 in Table \\ref{tab:setprm_aux} while  $h(x) = \\rho x \\ \\mathbb{1}\\{x>0 \\}$ has been adopted for sets F6 and F7.\n% \\towrite{ Questione aperta: cosa rappresenta l'auxina che calcola Farcot rispetto ai prm usati dentro ROPs system $k_{20}$ e $\\alpha$ ? \\color{black}Io per ora ho ipotizzato che la concentrazione di auxina che trova Farcot sia l'overall auxin level $k_{20}$ e siccome nel paper auxin è costante in ogni cellula metto $\\nu = 0 $ così tolgo la dipendenza spaziale ($\\alpha = exp(-\\nu *x ecc) = 1$).}\n\nIn this chapter, we propose a new coupling between auxin-PIN transport problem and ROPs RD system. In particular, we recover the overall auxin level $k_{20}$ of each cell $\\Omega_i$ from the dynamic system \\eqref{eq:Sys_auxPIN} and then evaluate ROPs active and inactive concentrations solving the RD system in a pluricellular system. More precisely, we solve in sequence the auxin-PIN problem, we find auxin mean concentration $a_i \\ \\forall i \\in \\{1, ..., N\\}$, we assemble ROPs system replacing $k_{20}$ parameters with different $a_i$ computed one for each cell. In general, as in \\cite{plant:Farcot}, we assume a homogeneous auxin locally in the cell (therefore $\\nu$ is set equal to 0 in \\eqref{eq:alpha_exp}). We are not considering exponential space distribution, but an auxin gradient only generated by difference in the mean concentration of auxin, from one cell to the neighbours.\n\n\\section{Numerical discretization}\nIn this section we employ a semi-implicit method to solve the auxin-PIN transport model. For simplicity, we focus the analysis on a two-cells system and therefore rewrite \\eqref{eq:Sys_auxPIN} for $N = 2$:\n\\begin{equation}\\begin{aligned}\n\\begin{cases}\n  {\\displaystyle d a_{1}(t)\\over\\displaystyle d t} & = \\Phi_{21}(t) + k - \\delta a_1(t) \\\\[6pt]\n  {\\displaystyle d a_{2}(t)\\over\\displaystyle d t} & = \\Phi_{12}(t) + k - \\delta a_2(t) \\\\[6pt]\n  {\\displaystyle d P_{12}(t)\\over\\displaystyle d t} & = h\\left(\\Phi_{12}(t)\\right) - \\mu P_{12}(t) \\\\[6pt]\n  {\\displaystyle d P_{21}(t)\\over\\displaystyle d t} & = h\\left(\\Phi_{21}(t)\\right) - \\mu P_{21}(t).\n\\end{cases}\n\\end{aligned} \\end{equation}\n\nWe divide the time interval $\\left[0, T_{max}\\right]$ into $N_{max}$ sub-intervals such that $t^n = n \\Delta t$ with $\\Delta t = T_{max} / N_{max}  $. We define $a_i^n$ and $P_{ij}^n$ as approximations of the solutions evaluated at time $t^n$:\n\\begin{equation}\n  a_i\\left( t^n \\right) \\simeq a_i^n, \\ \\ \\ P_{ij}\\left( t^n \\right) \\simeq P_{ij}^n.\n\\end{equation}\nFor the time derivative, we apply the implicit Euler method as follows:\n\\begin{equation}\\label{eq:SIEuler}\\begin{aligned}\n\\begin{cases}\n  {\\displaystyle a_1^{n+1} - a_1^n\\over\\displaystyle \\Delta t} & = \\Phi_{21}^{n+1} + k - \\delta a_1^{n+1} \\\\[6pt]\n  {\\displaystyle a_2^{n+1} - a_2^n \\over\\displaystyle \\Delta t} & = \\Phi_{12}^{n+1} + k - \\delta a_2^{n+1} \\\\[6pt]\n  {\\displaystyle P_{12}^{n+1} - P_{12}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{12}^{n+1}\\right) - \\mu P_{12}^{n+1} \\\\[6pt]\n  {\\displaystyle P_{21}^{n+1} - P_{21}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{21}^{n+1}\\right) - \\mu P_{21}^{n+1}.\n\\end{cases}\n\\end{aligned} \\end{equation}\nWe explicit the flux in the auxin equations:\n\\begin{equation} \\label{eq:2cell_auxPIN}\\begin{aligned}\n  \\begin{cases}\n    {\\displaystyle a_1^{n+1} - a_1^n\\over\\displaystyle \\Delta t}  & = \\left( P_{21}^{n+1} + D_a \\right) a_2^{n+1} - \\left( P_{12}^{n+1} + D_a \\right) a_1^{n+1} + k - \\delta a_1^{n+1} \\\\[6pt]\n    {\\displaystyle a_2^{n+1} - a_2^n \\over\\displaystyle \\Delta t} & = \\left( P_{12}^{n+1} + D_a \\right) a_1^{n+1} - \\left( P_{21}^{n+1} + D_a \\right) a_2^{n+1} + k - \\delta a_2^{n+1} \\\\[6pt]\n    {\\displaystyle P_{12}^{n+1} - P_{12}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{12}^{n+1}\\right) - \\mu P_{12}^{n+1} \\\\[6pt]\n    {\\displaystyle P_{21}^{n+1} - P_{21}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{21}^{n+1}\\right) - \\mu P_{21}^{n+1}.\n  \\end{cases}\n\\end{aligned}\\end{equation}\n\nThe system is highly non-linear because of the definition of the fluxes of auxin $\\Phi_{12}$ and $\\Phi_{21}$ and due to the non-linear function $h$. Therefore, we decide to use a semi-implicit method in order to linearize the system. Since we are more interested in auxin concentration rather than the PIN concentration, we keep implicit $a_1$ and $a_2$, while discretize explicitly $P_{12}$ and $P_{21}$ in the first two equations. Regarding PIN equations, function $h$ depends on the sign of the argument and contributes coming from auxin and PIN concentrations cannot linearized as before. Therefore we decide to treat explicitly the flux input inside $h$ function.\n\nThe semi-implicit counterpart of \\eqref{eq:2cell_auxPIN} is thus given by:\n\\begin{equation}\\begin{aligned}\n\\begin{cases}\n  {\\displaystyle a_1^{n+1} - a_1^n\\over\\displaystyle \\Delta t} & = \\left( P_{21}^{n} + D_a \\right) a_2^{n+1} - \\left( P_{12}^{n} + D_a \\right) a_1^{n+1} + k - \\delta a_1^{n+1} \\\\[6pt]\n  {\\displaystyle a_2^{n+1} - a_2^n \\over\\displaystyle \\Delta t} & = \\left( P_{12}^{n} + D_a \\right) a_1^{n+1} - \\left( P_{21}^{n} + D_a \\right) a_2^{n+1} + k - \\delta a_2^{n+1} \\\\[6pt]\n  {\\displaystyle P_{12}^{n+1} - P_{12}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{12}^{n}\\right) - \\mu P_{12}^{n+1} \\\\[6pt]\n  {\\displaystyle P_{21}^{n+1} - P_{21}^{n} \\over\\displaystyle \\Delta t} & = h\\left(\\Phi_{21}^{n}\\right) - \\mu P_{21}^{n+1}.\n\\end{cases}\n\\end{aligned} \\end{equation}\n\nThis linearized system can be rewritten in algebraic form as follows:\n\\begin{equation}\n  A \\mathbf{X} = \\mathbf{b},\n\\end{equation}\nwhere\n\\begin{equation}\\begin{aligned}\n  \\mathbf{X} = \\begin{bmatrix} a_1^{n+1} \\\\  a_2^{n+1} \\\\ P_{12}^{n+1} \\\\P_{21}^{n+1} \\end{bmatrix}  , \\ \\ \\ \\mathbf{b} = \\begin{bmatrix}  \\frac{1}{\\Delta t}a_1^{n} + k \\\\ \\frac{1}{\\Delta t} a_2^{n+1} + k \\\\ \\frac{1}{\\Delta t} P_{12}^{n} + h\\left(\\Phi_{12}^n \\right) \\\\P_{21}^{n+1} + h\\left(\\Phi_{21}^n \\right)\\end{bmatrix}&, \\\\[6pt]\n A = \\begin{bmatrix} \\frac{1}{\\Delta t} + P_{12}^n + D_a + \\delta & -P_{21}^n - D_a & 0 & 0 \\\\\n  -P_{12}^n - D_a  & \\frac{1}{\\Delta t} + P_{21}^n + D_a + \\delta & 0 & 0 \\\\\n  0 & 0 & \\frac{1}{\\Delta t} + \\mu & 0 \\\\\n  0 & 0 & 0 & \\frac{1}{\\Delta t} + \\mu  \\end{bmatrix}&.\n\\end{aligned}\\end{equation}\n\nThe semi-implicit method partially decouples the dynamics between auxin and PIN concentrations. In particular, at each time-step we solve a linear system to find the vector of auxin concentrations $\\mathbf{a} = \\left[a_1^{n+1}, a_2^{n+1} \\right]$, whereas each PIN concentration $P_{12}^{n+1}$, $P_{21}^{n+1}$ is computed with a simple division.\nWe define the auxin system matrix $A_a$ and right hand side vector $\\mathbf{b}_a$ as\n\\begin{equation}\n  A_a = \\begin{bmatrix} \\frac{1}{\\Delta t} + P_{12}^n + D_a + \\delta & -P_{21}^n - D_a \\\\ -P_{12}^n - D_a  & \\frac{1}{\\Delta t} + P_{21}^n + D_a + \\delta   \\end{bmatrix}, \\ \\ \\  \\mathbf{b}_a =  \\begin{bmatrix}  \\frac{1}{\\Delta t}a_1^{n} + k \\\\ \\frac{1}{\\Delta t} a_2^{n+1} + k \\end{bmatrix};\n\\end{equation}\nthen the linear system for auxin concentrations is formulated as follows:\n\\begin{equation} \\label{eq:aux_linsys}\n  A_a \\mathbf{a} = \\mathbf{b}_a.\n\\end{equation}\n\nThen, for updating PIN $P_{ij}$ concentration for a generic $i,j$ we only compute it as follows:\n\\begin{equation}\\label{eq:pindiv}\n  P_{ij}^{n+1} = \\left(\\frac{1}{\\Delta t} + \\mu \\right)^{-1} \\left[ \\frac{1}{\\Delta t} P_{ij}^{n} + h\\left(\\Phi_{ij}^n \\right) \\right].\n\\end{equation}\n\nTo sum up, given an initial state of the system, $\\mathbf{a}^0 = \\left[a_1^0, a_2^0 \\right]$, $P_{12}^0$ and $P_{21}^0$, usually selected randomly from 0 and 1, for $n = 0, ... N_{max}-1$ we find $\\mathbf{a}^{n+1} = \\left[a_1^{n+1}, a_2^{n+1}\\right]$ solving the linear system \\eqref{eq:aux_linsys} and the we update $P_{12}^{n+1}$ and $P_{21}^{n+1}$ values with formula \\eqref{eq:pindiv}.\n\nAfter solving the auxin-PIN model applying the semi-implicit method, we replace values of local overall auxin level $k_{20}$ in each cell with the auxin concentration $a_i^{n+1}$ and solve the ROPs system. The complete procedure to solve the auxin-PIN model together with RD involving ROPs proteins is presented synthetically in Algorithm \\ref{alg:RRmod_auxPIN}.\n\\begin{algorithm}[H]\n    \\caption{Pluricellular system solver procedure: RR coupled with auxin-PIN dynamics}\n    \\label{alg:RRmod_auxPIN}\n    Given $N \\geq 1$ cells, $k_i$\n    \\begin{algorithmic}[1]\n    \\STATE Initialization: $\\forall i = 1, ..., N$\n    \\STATE{\\verb|[ai]| randomly init}\n    \\STATE{\\verb|[PINi]| randomly init}\n    \\STATE \\verb|[U0i, V0i]| $\\gets [k_i u_0, k_i v_0]$\n    \\STATE \\verb|[Uiprec, Viprec]| $\\gets$  \\verb|[U0i, V0i]|\n    \\WHILE{$t < T_{max}$}\n    \\STATE{\\verb|update ai| and \\verb|PINi| matrices and vectors}\n    \\STATE{\\verb|solve auxin-PIN| problem \\eqref{eq:aux_linsys} - \\eqref{eq:pindiv}}\n    \\STATE{\\verb|update| $k_{20}$}\n    \\STATE{\\verb|assemble| matrix for $\\forall i = 1,..., N$}\n    \\FOR{$iter < Niter$}\n    \\STATE{$\\forall i =1, ..., N$}\n    \\STATE{compute BC contribute from $j \\in \\mathcal{N}_i$}\n    \\STATE{\\verb|interpolate| on $i$}\n    \\STATE{update \\verb|rhs|}\n    \\STATE{\\verb|solve| $\\Omega_i$ problem \\eqref{eq:pluriModel}}\n    \\STATE{update residual, check tolerance, update \\verb|iter|}\n    \\STATE \\verb|[Uiprec, Viprec]| $\\gets$  \\verb|[Ui, Vi]|\n    \\ENDFOR\n    \\STATE \\verb|[U0i, V0i]| $\\gets$  \\verb|[Ui, Vi]|\n    \\ENDWHILE\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\section{Numerical Results}\nIn this section we present some of the results obtained by resorting to Algorithm \\ref{alg:RRmod_auxPIN} in order to couple auxin-PIN transport model and ROPs multi-cellular system. In the majority of works about auxin dynamics, auxin distribution has been modelled within a strand of cells. Thus, the multi-cellular systems to solve is composed by two cells attached along the short side, as the scheme in Figure \\ref{fig:farcot} illustrates. In particular, $\\Omega_1$ corresponds to the left cell and $\\Omega_2$ to the right one.\n\nIn the first subsection we present an intermediate result, applying the RR solver on a strand of two cells without considering auxin-PIN dynamics. Then, we test Algorithm \\ref{alg:RRmod_auxPIN} under different sets of parameters and we validate the multi-cellular model changing channel characterization.\n% There the localized auxin supply yields the successive polarization of PIN distribution\n% along a strand of cells. We model the auxin and PIN dynamics within cells with a minimal canalization model\n\n% \\subsection{auxina-PIN on 2 cells system}\n% PROBLEMI SOLO AUXINA E PIN per 2 cellule\n%\n% \\towrite{NON LI METTEREI. COSA NE DITE?\n% Non so se vogliamo metterli, di per sè i problemi di auxina e pin vengono risolto allo stesso modo dopo (non sono influenzati dal ROP system). Qua si nota che per delta t diversi vengono soluzioni diverse, ma non ci poniamo prblemi e usiamo come per gli altri un delta t fisso 0.5?}\n\n% Questi hanno $\\Delta t = 1$ (per ora tolti)\n% 2022-02-22_16-44-08 F4 2022-02-24_10-24-19 con img csv\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF4_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-24-19/auxina.png}\n%     }\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF4_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-24-19/pin.png}\n%     }\n%     \\caption[auxin-PIN - with F4 prm]{auxin-PIN dynamics on 2 cells system with F4 parameters set.}\n%     \\label{fig:F4_dt1}\n% \\end{figure}\n% % 2022-02-22_16-50-49 F5 2022-02-24_10-14-28 con img csv\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF5_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-14-28/auxina.png}\n%     }\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF5_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-14-28/pin.png}\n%     }\n%     \\caption[auxin-PIN - with F5 prm]{auxin-PIN dynamics on 2 cells system with F5 parameters set.}\n%     \\label{fig:F5_dt1}\n% \\end{figure}\n% % 2022-02-22_17-07-25 F6 rho 2 2022-02-24_10-14-51 con img csv\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF62_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-14-51/auxina.png}\n%     }\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF62_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-14-51/pin.png}\n%     }\n%     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2$ parameters set.}\n%     \\label{fig:F62_dt1}\n% \\end{figure}\n% % 2022-02-22_18-18-58 F6 rho 2.7 2022-02-24_10-15-10 con img csv\n% % 2022-02-22_19-09-25 F7 rho 2.8 2022-02-24_10-15-24 con img csv\n%\n% % 2022-02-24_10-15-02 F6 rho 2.3 e delta t 1\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF623_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-15-02/auxina.png}\n%     }\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF623_dt1}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_10-15-02/pin.png}\n%     }\n%     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm, $\\Delta t = 1$]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2.3$ parameters set and $\\Delta t = 1$.}\n%     \\label{fig:F623_dt1}\n% \\end{figure}\n\n\n% Questi hanno $\\Delta t = 0.5$ come pb ROPs però se aumento dt cambiano ... sono poi identici dopo. per me non necessari.\n% % 2022-02-24_11-33-54 F6 F6 rho 2\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF62}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-33-54/auxina.png}\n%     }\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF62}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-33-54/pin.png}\n%     }\n%     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm, $\\Delta t = 0.5$]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2$ parameters set and $\\Delta t = 0.5$.}\n%     \\label{fig:F62}\n% \\end{figure}\n%\n% % 2022-02-24_11-34-18 F6 rho 2.3\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-18/auxina.png}}\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-18/pin.png}}\n%     % \\quad\n%     % \\subfloat[confront with $\\Delta t= 1$.\\label{fig:1vs05}]{\n%     %     \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-18/confronto_dt0.5.png}}\n%     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm, $\\Delta t = 0.5$]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2.3$ parameters set and $\\Delta t = 0.5$.}\n%     \\label{fig:F623}\n% \\end{figure}\n% % 2022-02-24_11-34-32 F6 rho 2.7\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF627}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-32/auxina.png}}\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF627}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-32/pin.png}}\n%     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm, $\\Delta t = 0.5$]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2.7$ parameters set and $\\Delta t = 0.5$.}\n%     \\label{fig:F627}\n% \\end{figure}\n% % 2022-02-24_11-34-54 F7 rho 2.8\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\\label{fig:auxF7}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-54/auxina.png}}\n%     \\quad\n%     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\\label{fig:pinF7}]{\n%         \\includegraphics[scale=0.15]{cap4/2022-02-24_11-34-54/pin.png}}\n%     \\caption[auxin-PIN - with F7 $\\rho = 2.8$ prm, $\\Delta t = 0.5$]{auxin-PIN dynamics on 2 cells system with F7 $\\rho = 2.8$ parameters set and $\\Delta t = 0.5$.}\n%     \\label{fig:F7}\n% \\end{figure}\n\n\\subsection{ROPs system in a strand of two cells}\n% \\towrite{ROPs system di 2 cellule però con mesh diversa, senza aux pin dynamics ma solito auxin esponenziale.\n% SERVE? toglierei, posso tenere come unico confronto quello con lo stesso canale che si usa dopo ovvero figura \\ref{fig:UH5} e basta. Qua ci sono canali e gradiente di auxina dato da alpha esponenziale solito con $\\nu = 1.5$, quindi non mi verrebbe da fare commenti tanto più diversi di quelli nel cap 3; cioè non mi sembra dia informazioni in più}\n% 2022-03-08_10-14-21 canale\n% $a_y = 10 , \\epsilon_y = 1$\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[$t = 100s  $\\label{1UH1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-14-21/img.0050.png}}\n%     \\quad\n%     \\subfloat[$t = 200s$ .\\label{2UH1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-14-21/img.0100.png}}\n%     \\quad\n%     \\subfloat[$t = 400s$ .\\label{3UH1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-14-21/img.0200.png}}\n%     \\quad\n%     \\subfloat[$t = 1000s$ .\\label{4UH1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-14-21/img.0499.png}}\n%     \\quad\n%     \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-08_10-14-21/legenda.png}}\n%     \\caption[2cell RRmod Active ROPs - with $a_y = 10 , \\epsilon_y = 1$]{Active ROPs $u$ evolution with RRmod algo solver on 2 cells system with $a_y = 10 , \\epsilon_y = 1$.}\n%     \\label{fig:UH1}\n% \\end{figure}\n% \\towrite{giusto molto simile ai casi di beta nullo con 1 cellula da sola ... quasi stagnanti perchè è zero il flusso, troppo piccoli i canali forse}\n% % 2022-03-08_10-18-08 canale\n% $a_y = 10 , \\epsilon_y = 3$\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[$t = 100s  $\\label{1UH3}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-18-08/img.0050.png}}\n%     \\quad\n%     \\subfloat[$t = 200s$ .\\label{2UH3}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-18-08/img.0100.png}}\n%     \\quad\n%     \\subfloat[$t = 400s$ .\\label{3UH3}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-18-08/img.0200.png}}\n%     \\quad\n%     \\subfloat[$t = 1000s$ .\\label{4UH3}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_10-18-08/img.0499.png}}\n%     \\quad\n%     \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-08_10-18-08/legenda.png}}\n%     \\caption[2cell RRmod Active ROPs - with $a_y = 10 , \\epsilon_y = 3$]{Active ROPs $u$ evolution with RRmod algo solver on 2 cells system with $a_y = 10 , \\epsilon_y = 3$.}\n%     \\label{fig:UH3}\n% \\end{figure}\n% \\towrite{fino a qua toglierei}\n% 2022-03-08_10-16-01 canale\nWe test the array of two cells under exponential auxin distribution as in equation \\eqref{eq:alpha_exp} and choosing as initial state:\n\\begin{equation}\n  \\left[ U_1^0, V_1^0 \\right] = 1.5 \\left[u^0,v^0 \\right], \\ \\ \\ \\left[ U_2^0, V_2^0 \\right] = \\left[u^0,v^0 \\right].\n\\end{equation}\nThe two cells have channel functions defined as follows:\n\\begin{equation}\\label{eq:betaY}\\begin{aligned}\n    \\beta_{uRR} & = \\mathbb{1} \\Big\\{ \\frac{L_y}{2} - a_y - \\epsilon_y \\leq y \\leq \\frac{L_y}{2} - a_y \\Big\\}\n    + \\mathbb{1} \\Big\\{\\frac{L_y}{2} + a_y \\leq y \\leq \\frac{L_y}{2} + a_y + \\epsilon_y \\Big\\} \\\\\n    \\beta_{vRR} & = \\mathbb{1} \\Big\\{ \\frac{L_y}{2} - a_y - \\epsilon_y \\leq y \\leq \\frac{L_y}{2} - a_y \\Big\\}\n    + \\mathbb{1} \\Big\\{\\frac{L_y}{2} + a_y \\leq y \\leq \\frac{L_y}{2} + a_y + \\epsilon_y \\Big\\}.\n\\end{aligned}\\end{equation}\nIn the majority of tests, we set $a_y = 5$ and $\\epsilon_y = 5$.\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 100s  $\\label{1UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0050.png}}\n    \\quad\n    \\subfloat[$t = 200s$ .\\label{2UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0100.png}}\n    \\quad\n    \\subfloat[$t = 300s$ \\label{3UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 400s$ \\label{4UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0200.png}}\n    \\quad\n    \\subfloat[$t = 600s$ .\\label{5UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0300.png}}\n    \\quad\n    \\subfloat[$t = 1000s$ \\label{6UH5}]{\\includegraphics[scale=0.14]{cap4/2022-03-08_10-16-01/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.35]{cap4/2022-03-08_10-16-01/legenda.png}}\n    \\caption[2cell RR Active ROPs - with $a_y = 5 , \\epsilon_y = 5$]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system with $a_y = 5 , \\epsilon_y = 5$.}\n    \\label{fig:UH5}\n\\end{figure}\nFigure \\ref{fig:UH5} shows results obtained still taking auxin distribution defined a priori and not considering the dynamic system with PIN carriers. This simulation shows a behaviour similar to the results in Section \\ref{cap3:results}. A front is formed at the border where auxin maximum is located and it breaks into spots, subsequent travelling towards minimum of auxin. It confirms that auxin gradient guarantees pattern formation.\n\n\\subsection{Coupled ROPs model with auxin-PIN dynamics}\nWe present some relevant results of the multi-cellular system for ROP pattern formation under chemical dynamics between auxin and PIN. In particular, we aim at observing the generation and evolution of active spots of ROPs in the system, under different types of auxin dynamics.\n\nSets of parameters F4 and F5 in Table \\ref{tab:setprm_aux}, depending on the number of cells in the strand, leads to alternating sources and sinks of auxin. Sinks are cells with high auxin and incoming flux, whereas sources are groups of cells with low auxin and outgoing flux.\n\nAuxin-PIN system under the F4 set of parameters converges after few seconds to a homogeneus auxin distribution, with $a_1 = a_2 = 1$. Therefore the system is characterized by no gradient of auxin (see Figure \\ref{fig:Uaux_F4}). We observe a considerable spot formation in Figure \\ref{fig:U_F4}. Firstly a homoclinic stripe is formed at the right of the common interface, then it breaks into multiple spots. After some seconds, another stripe is formed in the left cell and simultaneously the spots formed in the right part start travelling towards the exterior. A plausible responsible for this self-generated pattern is the gradient of ROPs generated by the initial difference in initial states and the open channels, as it happens in Figure \\ref{fig:4c_gradD_diffI}.\n\n\nAuxin-PIN system under the set F5 of parameters shows a different behaviour. As can be seen in Figure \\ref{fig:Uaux_F5}, auxin concentration in the first and second cell converges to the same low value $a_1 = a_2 = 0.1$ and, as for the F4 set of parameters, there is no auxin gradient characterizing the system after few time steps.\n\nDifferently from Figure \\ref{fig:U_F4}, the numerical output in Figure \\ref{fig:U_F5} is characterized by active ROPs concentration converging to a null homogeneous state. The possible reason is that the overall auxin level is too low to sustain spot formation. The gradient of ROPs generated by open channels may not be enough and it still need a sufficient high, even if constant, concentration of auxin to form hotspots, coherently with Figure \\ref{fig:U_F4}.\n% 2022-03-28_10-37-40 con F4\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F4}]{\\includegraphics[scale=0.25]{cap4/2022-03-28_10-37-40/auxF.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F4}]{\\includegraphics[scale=0.25]{cap4/2022-03-28_10-37-40/pin.png}}\n    \\caption[auxin-PIN - with the F4 set]{auxin-PIN dynamics on 2 cells system with the F4 parameters set.}\n    \\label{fig:Uaux_F4}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 50s $\\label{1U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0050.png}}\n    \\quad\n    \\subfloat[$t = 250s$\\label{3U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 300s$\\label{2U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0300.png}}\n    \\quad\n    \\subfloat[$t = 400s$\\label{4U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0400.png}}\n    \\quad\n    \\subfloat[$t = 450s$\\label{7U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0450.png}}\n    \\quad\n    \\subfloat[$t = 500$\\label{8U_F4}]{\\includegraphics[scale=0.15]{cap4/2022-03-28_10-37-40/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-01_10-13-10/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F5 prm]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F4 parameters set.}\n    \\label{fig:U_F4}\n\\end{figure}\n\n% 2022-03-01_10-13-10 F5\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F5}]{\\includegraphics[scale=0.25]{cap4/2022-03-01_10-13-10/auxF.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F5}]{\\includegraphics[scale=0.25]{cap4/2022-03-01_10-13-10/pinF.png}}\n    \\caption[auxin-PIN - with the F5 prm]{auxin-PIN dynamics on 2 cells system with the F5 parameters set.}\n    \\label{fig:Uaux_F5}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 4s $\\label{1U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0002.png}}\n    \\quad\n    \\subfloat[$t = 10s$\\label{3U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0005.png}}\n    \\quad\n    \\subfloat[$t = 20s$\\label{2U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0010.png}}\n    \\quad\n    \\subfloat[$t = 30s$\\label{4U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0015.png}}\n    \\quad\n    \\subfloat[$t = 40s$\\label{7U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0020.png}}\n    \\quad\n    \\subfloat[$t = 1000s$\\label{8U_F5}]{\\includegraphics[scale=0.15]{cap4/2022-03-01_10-13-10/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-01_10-13-10/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F5 set]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F5 parameters set.}\n    \\label{fig:U_F5}\n\\end{figure}\n\nWe then set the system to solve auxin-PIN dynamics under the set F6 of parameters, which is characterized by a not smooth function $h$. As reported in \\cite{plant:Farcot}, under these conditions the system shows oscillating values of auxin concentration in each cell.\n\n% 2022-02-28_17-21-17 F6 rho 2 - lost vtk files -> 2022-03-21_10-46-16\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F62}]{\\includegraphics[scale=0.25]{cap4/2022-02-28_17-21-17/auxF.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F62}]{\\includegraphics[scale=0.25]{cap4/2022-02-28_17-21-17/pinF.png}}\n    \\caption[auxinPIN - with the F6 $\\rho = 2$ set]{auxin-PIN dynamics on 2 cells system with the F6 $\\rho = 2$ parameters set.}\n    \\label{fig:Uaux_F62}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 0s  $\\label{1U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0000.png}}\n    \\quad\n    \\subfloat[$t = 250s$ .\\label{4U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 260s$ .\\label{5U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0130.png}}\n    \\quad\n    \\subfloat[$t = 300s$ .\\label{6U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 350s$ .\\label{7U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0175.png}}\n    \\quad\n    \\subfloat[$t = 500s$ .\\label{8U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 750s$ .\\label{9U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0375.png}}\n    \\quad\n    \\subfloat[$t = 1000s$ .\\label{10U_F62}]{\\includegraphics[scale=0.15]{cap4/2022-03-21_10-46-16/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-21_10-46-16/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2$ set]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2$ parameters set.}\n    \\label{fig:U_F62}\n\\end{figure}\n\nIn Figure \\ref{fig:Uaux_F62}, we can show results for $\\rho = 2$: auxin values in the first and second cell oscillate around a common mean value, alternating with different values up to a steady state with $a_1 = a_2 = 1$. The continuous changing in auxin levels between the two cells at the beginning and the subsequent convergence to a sufficient high value lead to an interesting pattern formation.\n\nAs Figure \\ref{fig:U_F62} shows, two stripes arise close to the interface, one inside each cell, which then break into multiple spots, then slowly travel away from the common interface. Since the pattern formation takes place near the boundary dividing the two cells, the possible responsibles of patches are either the gradient of auxin induced by the jump in concentrations or the gradient of ROPs generated by openend channels. Moreover, the jump in auxin levels at each time step generates a too soft gradient in auxin distribution in the two cells system, because the oscillations are rapid and have small amplitude.\n% 2022-03-01_09-31-44 F6 rho 2 con Tmax = 3000\n% 2022-03-08_16-03-34 F6 rho 2.3\n% We give more results sostaining that ROPs spots can be self-generated by its gradient under a sufficient high value of auxin.\n\nUsing parameter $\\rho = 2.3$, the oscillations of auxin concentration beocome periodic, as illustrated in Figure \\ref{fig:Uaux_F623}, and the overall auxin levels in each cell range around $1$ taking values approximately in the interval $\\left[0.8; 1.2\\right]$.\n\nThis high fequence oscillations in auxin dynamics are not replicated by the ROPs system, which is instead characterized by a slower evolution and inertia in changing conformation.\nWe can clearly recognize from the simulation frames in Figure \\ref{fig:U_F623} that active ROPs flow from the left cell to the right one through the open channels and then two symmetric spots are formed one in each cell moving towards the exterior.\n\n\\begin{figure}[p]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F623}]{\\includegraphics[scale=0.3]{cap4/2022-03-08_16-03-34/auxF.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F623}]{\\includegraphics[scale=0.3]{cap4/2022-03-08_16-03-34/pinF.png}}\n    \\caption[auxin-PIN - with the F6 $\\rho = 2.3$ set]{auxin-PIN dynamics on 2 cells system with the F6 $\\rho = 2.3$ parameters set.}\n    \\label{fig:Uaux_F623}\n\\end{figure}\n\\begin{figure}[hp]\n    \\centering\n    \\subfloat[$t = 236s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0118.png}}\n    \\quad\n    \\subfloat[$t = 250s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 270s$ \\label{fig:1U_F623}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0135.png}}\n    \\quad\n    \\subfloat[$t = 300s$ \\label{fig:2U_F623}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 350s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0175.png}}\n    \\quad\n    % \\subfloat[$t = 400s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0200.png}}\n    % \\quad\n    \\subfloat[$t = 500s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 700s$]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0350.png}}\n    \\quad\n    \\subfloat[$t = 1000s$ ]{\\includegraphics[scale=0.15]{cap4/2022-03-08_16-03-34/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-08_16-03-34/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2.3$ set]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2.3$ parameters set.}\n    \\label{fig:U_F623}\n\\end{figure}\n\n% 2022-03-02_08-46-01 F6 rho 2.7\n\\begin{figure}[p]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F627}]{\\includegraphics[scale=0.3]{cap4/2022-03-02_08-46-01/auxF.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F627}]{\\includegraphics[scale=0.3]{cap4/2022-03-02_08-46-01/pinF.png}}\n    \\caption[auxin-PIN - with the F6 $\\rho = 2.7$ set]{auxin-PIN dynamics on 2 cells system with the F6 $\\rho = 2.7$ parameters set.}\n    \\label{fig:Uaux_F627}\n\\end{figure}\n\\begin{figure}[hp]\n    \\centering\n    \\subfloat[$t = 0s  $\\label{1U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0000.png}}\n    \\quad\n    \\subfloat[$t = 100s$\\label{2U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0050.png}}\n    \\quad\n    \\subfloat[$t = 130s$\\label{3U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0075.png}}\n    \\quad\n    \\subfloat[$t = 200s$\\label{4U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0100.png}}\n    \\quad\n    \\subfloat[$t = 250s$\\label{7U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 300s$\\label{8U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 500s$\\label{9U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 1000s$\\label{10U_F627}]{\\includegraphics[scale=0.15]{cap4/2022-03-02_08-46-01/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-02_08-46-01/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2.7$ set]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2.7$ parameters set.}\n    \\label{fig:U_F627}\n\\end{figure}\n\n% 2022-04-06_18-46-10 questa simulazione conferma che in realtà le oscillazioni sono così velocit che è come se fosse a rop costante 1 da un certo t in poi (inizio no, vedi 2022-04-06_15-39-08\n\nA similar behaviour can be observed  in Figure \\ref{fig:U_F627} for a system under the F6 set of parameter with $\\rho = 2.7$. Oscillations in Figure \\ref{fig:Uaux_F627} have a higher frequence and amplitude then the ones obtained with $\\rho = 2 $ or $\\rho = 2.3 $ (compare Figure \\ref{fig:Uaux_F627} with Figures \\ref{fig:Uaux_F62} and \\ref{fig:Uaux_F623}). The local auxin concentrations change in a slightly bigger range, approximately taking values in $\\left[0.6; 1.4\\right]$ around $1$. Since we do not observe sensible difference in pattern location we assume that the main responsible for it is again the ROPs gradient between channels.\n\nWe present other simulations, in order to validate the idea that in the new multi-cellular system the responsible for ROPs pattern formation can be also the channels of communication and not only the imposed auxin gradient.\n\nWe test if ROPs system is sensitive to high frequence auxin concentrations as those in Figure \\ref{fig:Uaux_F623}, in order to verify if auxin gradient generated is detected by ROPs patterning. We modify algorithm in \\ref{alg:RRmod_auxPIN}. The ROPs system is solved updating $k_{20}$ parameter with auxin concentrations found with auxin-PIN system only up to $t = 500s$. After this time, we set a constant value for the overall auxin level such that it is equal to the mean value auxin concentrations oscillate around. To sum up, $k_{20}$ is chosen as follows:\n\\begin{equation*}\\begin{aligned}\n  k_{20} = a_i \\ \\forall i = 1,2 \\ \\ \\ &\\text{if } \\ t < 500 s \\\\[6pt]\n  k_{20} = \\bar{a}_1 = \\bar{a}_2 = 1 \\ \\ \\ &\\text{if } \\ t > 500 s.\n\\end{aligned}\\end{equation*}\nIn Figure \\ref{fig:U_F623_auxinconst} the results of this test are shown. We do not observe a sensible difference with respect to the frames in Figure \\ref{fig:U_F623}. As a consequence, we can assume that auxin concentrations in the two cells oscillate too rapidly to be considered as a gradient responsible for hotspots generation.\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 236s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0118.png}}\n    \\quad\n    \\subfloat[$t = 250s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 270s$ ]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0135.png}}\n    \\quad\n    \\subfloat[$t = 300s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 350s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0175.png}}\n    % \\quad\n    % \\subfloat[$t = 400s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0200.png}}\n    \\quad\n    \\subfloat[$t = 500s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 700s$]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0350.png}}\n    \\quad\n    \\subfloat[$t = 1000s$ ]{\\includegraphics[scale=0.15]{cap4/2022-04-06_18-46-10/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-04-06_18-46-10/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2.3$ set up to $t = 500s$]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2.3$ parameters set up to $t = 500s$, then auxin constan.}\n    \\label{fig:U_F623_auxinconst}\n\\end{figure}\n\n% 2022-03-02_08-47-02 F7 rho 2.8\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_F7}]{\\includegraphics[scale=0.25]{cap4/2022-03-02_08-47-02/auxF2.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_F7}]{\\includegraphics[scale=0.25]{cap4/2022-03-02_08-47-02/pinF2.png}}\n    \\caption[auxin-PIN - with the F7 $\\rho = 2.8$ set]{auxin-PIN dynamics on 2 cells system with the F7 $\\rho = 2.8$ parameters set.}\n    \\label{fig:Uaux_F7}\n\\end{figure}\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 0s  $\\label{1U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/img.0000.png}}\n    \\quad\n    \\subfloat[$t = 230s$\\label{2U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0115.png}}\n    \\quad\n    \\subfloat[$t = 250s$\\label{3U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 260s$\\label{4U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0130.png}}\n    \\quad\n    \\subfloat[$t = 280s$\\label{5U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0140.png}}\n    \\quad\n    \\subfloat[$t = 300s$\\label{6U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 500s$\\label{7U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 1000s$\\label{10U_F7}]{\\includegraphics[scale=0.13]{cap4/2022-03-02_08-47-02/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.4]{cap4/2022-03-02_08-47-02/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F7 $\\rho = 2.8$ set]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F7 $\\rho = 2.8$ parameters set.}\n    \\label{fig:U_F7}\n\\end{figure}\nFor the F6 set of parameters, ROPs system behaves as if auxin dynamics and therefore auxin gradient is absent. Too frequent changes in auxin are not registered by ROPs slow evolution because the time-scale characterizing pattern formation of ROPs belongs to a different order than auxin frequence.\nThe results using the F6 parameters set prove that ROPs spots can be self-generated by ROPs' flux through cells under sufficient high values of auxin.\n\nThe auxin-PIN transport dynamics under set the F7 of parameters shows almost no oscillations in the values of auxin concentrations from the beginning (see Figure \\ref{Uaux_F7}).\n\nResults in Figure \\ref{fig:U_F7} represent another example substaining that patches can be generated as a consequence of the structural coupling, modelled through common membrane between cells with open channels, consistently with \\cite{phdthesis:victor, intra1_R}. As in Figures \\ref{fig:U_F4} and \\ref{fig:U_F5}, the system is characterized by no auxin gradient because auxin concentrations in the two cells soon converge to the same values. The spots therefore are self-generated by the considered multi-cellular model.\n\n% Sto facendo questo tentativo con $\\Delta t = 0.01$ per vedere cosa succede,\n% come cambia ...  % 2022-03-12_21-27-46 % \\begin{figure}[H] \\centering\n% \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$.\n% \\label{Uaux_F623_dt001}]{\\includegraphics[scale=0.3]{cap4/2022-03-12_21-27-46/aux.png}}\n% \\quad \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$.\n% \\label{Upin_F623_dt001}]{\\includegraphics[scale=0.3]{cap4/2022-03-12_21-27-46/pin.png}}\n% \\caption[auxin-PIN - with F6 $\\rho = 2.3$ prm]{auxin-PIN dynamics on 2 cells\n% system with F6 $\\rho = 2.3$ parameters set.} \\label{fig:Uaux_F623_dt001}\n% \\end{figure}\n\n% 2022-03-08_21-59-54_tesi\n\\textbf{Auxin with exponential distribution}\n\nAuxin distribution is now taken space-dependent similarly as done in Section \\ref{cap3:results}. The overall auxin level $k_{20}$ is set equal to the auxin concentration computed with auxin-PIN system and then inside ROPs system auxin distribution is still taken exponential as follows:\n\\begin{equation*}\n  \\alpha(x) = k_{20} exp\\left(-\\nu \\frac{x}{L_x}\\right), \\ \\text{with} \\ \\nu = 1.5.\n\\end{equation*}\nWe present in Figure \\ref{fig:U_F623_exp} results obtained under the set F6 of parameters and $\\rho = 2.3$.\n\nNumerical illustrations in Figure \\ref{fig:U_F623_exp} visualize a double location of active ROPs because of the double source of gradient in auxin distribution. Indeed, on the left side of cell 1 we recognize the influence of the exponential distribution: a homoclinic stripe is formed, then it breaks into two spots that after a longer time unify in an unique one moving towards the right. Focusing instead on the interface, spots are formed and we observe a different evolution of patches with respect to the ones in Figure \\ref{fig:U_F623} is observed. There, the jump in $k_{20}$ occurs and the difference in auxin concentration between cells is increased by the exponential distribution. Moreover, channels are open and ROPs flux cooperates in the pattern formation.\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[$t = 30s$ \\label{1U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0015.png}}\n    \\quad\n    \\subfloat[$t = 60s$ \\label{2U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0030.png}}\n    \\quad\n    \\subfloat[$t = 120s$ \\label{3U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0060.png}}\n    \\quad\n    \\subfloat[$t = 180s$ \\label{4U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0090.png}}\n    \\quad\n    \\subfloat[$t = 200s $ \\label{5U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0100.png}}\n    \\quad\n    \\subfloat[$t = 250s$ \\label{6U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0125.png}}\n    \\quad\n    \\subfloat[$t = 270s$ \\label{7U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0135.png}}\n    \\quad\n    \\subfloat[$t = 300s$ \\label{8U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0150.png}}\n    \\quad\n    \\subfloat[$t = 500s$ \\label{9U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0250.png}}\n    \\quad\n    \\subfloat[$t = 1000s$ \\label{10U_F623_exp}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54_tesi/frame.0499.png}}\n    \\quad\n    \\subfloat[]{\\includegraphics[scale=0.5]{cap4/2022-03-08_21-59-54_tesi/legenda.png}}\n    \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2.3$ set and exponential distribution]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2.3$ parameters set and exponential auxin distribution.}\n    \\label{fig:U_F623_exp}\n\\end{figure}\n\n% 2022-03-08_21-59-54\n% \\towrite{Try with $\\Delta t = 1$ to see if in the coupled problem we see \"sensitive\" difference (per la dinamica auxin-PIN per alcuni prm vedevi differenze nelle oscillazioni \\ref{fig:U_F623}). here used homogeneous auxin ($\\nu = 0$), set of prm F6 with $\\rho = 2.3$. PER ORA LO TOLGO, però era venuto diverso ....}\n\n% frame to confront with \\ref{fig:U_F623} ... diversissimo ...\n% \\begin{figure}[H]\n%     \\centering\n%     \\subfloat[$t = 236s  $\\label{1U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0118.png}}\n%     \\quad\n%     \\subfloat[$t = 250s$ .\\label{2U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0125.png}}\n%     \\quad\n%     \\subfloat[$t = 270s$ .\\label{3U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0135.png}}\n%     \\quad\n%     \\subfloat[$t = 300s$ .\\label{4U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0150.png}}\n%     \\quad\n%     \\subfloat[$t = 350s$ .\\label{5U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0175.png}}\n%     \\quad\n%     \\subfloat[$t = 400s$ .\\label{6U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0200.png}}\n%     \\quad\n%     \\subfloat[$t = 500s$ .\\label{7U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0250.png}}\n%     \\quad\n%     \\subfloat[$t = 1000s$ .\\label{8U_F623_dt1}]{\\includegraphics[scale=0.15]{cap4/2022-03-08_21-59-54/frame.0499.png}}\n%     \\caption[2cell RR Active ROPs coupled auxin-PIN - with F6 $\\rho = 2.3$ prm and and $\\Delta  t = 1$]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with F6 $\\rho = 2.3$ parameters set and $\\Delta  t = 1$.}\n%     \\label{fig:U_F623_dt1}\n% \\end{figure}\n\n% 2022-03-18_16-40-47\n\\textbf{Change channel characterization}\n\nWe here present an interesting result sustaining the modelling assumptions made on channels functions. We set the system under the set F6 of parameters and $\\rho = 2$, using a bigger transport efficiency coefficient $\\alpha_{u,vRR} = 5$. In Figure \\ref{fig:U_alpha5} different frames of the numerical simulation obtained are shown.\n \\begin{figure}[H]\n     \\centering\n     \\subfloat[$t = 10s  $\\label{1U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0010.png}}\n     \\quad\n     \\subfloat[$t = 50s$ \\label{2U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0050.png}}\n     \\quad\n     \\subfloat[$t = 100s$ \\label{3U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0100.png}}\n     \\quad\n     \\subfloat[$t = 150s$ \\label{4U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0150.png}}\n     \\quad\n     \\subfloat[$t = 175s$ \\label{5U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0175.png}}\n     \\quad\n     \\subfloat[$t = 200s$ \\label{6U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0200.png}}\n     \\quad\n     \\subfloat[$t = 250s$ \\label{7U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0250.png}}\n     \\quad\n     \\subfloat[$t = 500s$ \\label{8U_alpha5}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_16-40-47/frame.0499.png}}\n     \\quad\n     \\subfloat[\\label{legU_alpha5}]{\\includegraphics[scale=0.4]{cap4/2022-03-18_16-40-47/legenda.png}}\n     \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2$ set and and $\\alpha_{u,vRR} = 5$]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2$ parameters set and $\\alpha_{u,vRR} = 5$.}\n     \\label{fig:U_alpha5}\n \\end{figure}\n % \\begin{figure}[H]\n %     \\centering\n %     \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_a5}]{\\includegraphics[scale=0.3]{cap4/2022-03-18_16-40-47/aux.png}}\n %     \\quad\n %     \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_a5}]{\\includegraphics[scale=0.3]{cap4/2022-03-18_16-40-47/pin.png}}\n %     \\caption[auxin-PIN - with F6 $\\rho = 2$ prm and $\\alpha_{u,vRR} = 5$]{auxin-PIN dynamics on 2 cells system with F6 $\\rho = 2$ parameters set and $\\alpha_{u,vRR} = 5$.}\n %     \\label{fig:Uaux_alpha5}\n % \\end{figure}\nThe increase in the transport efficiency yields a unique thicker stripe, in contrast to the two stripes in Figure \\ref{fig:U_F62} obtained for $\\alpha_{u,vRR} = 1$, and more symmetric spots with respect to the common interface.\n\n% 2022-03-18_14-49-41\nThe result we finally show is obtained with no open communication channels, i.e., setting functions $\\beta_{uRR} = \\beta_{vRR} = 0$.\n\\begin{figure}[H]\n    \\centering\n    \\subfloat[auxin on $\\Omega_1$ and $\\Omega_2$. \\label{Uaux_b0}]{\\includegraphics[scale=0.3]{cap4/2022-03-18_14-49-41/aux.png}}\n    \\quad\n    \\subfloat[PIN on $\\Omega_1$ and $\\Omega_2$. \\label{Upin_b0}]{\\includegraphics[scale=0.3]{cap4/2022-03-18_14-49-41/pin.png}}\n    \\caption[auxin-PIN - with the F6 $\\rho = 2$ set and $\\beta_{uRR} = \\beta_{vRR} = 0$]{auxin-PIN dynamics on 2 cells system with the F7 $\\rho = 2$ parameters set and $\\beta_{uRR} = \\beta_{vRR} = 0$.}\n    \\label{fig:Uaux_beta0}\n\\end{figure}\n \\begin{figure}[H]\n     \\centering\n     \\subfloat[$t = 0s  $\\label{1U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0000.png}}\n     \\quad\n     \\subfloat[$t = 10s$ \\label{2U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0010.png}}\n     \\quad\n     \\subfloat[$t = 20s$ \\label{3U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0020.png}}\n     \\quad\n     \\subfloat[$t = 50s$ \\label{4U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0050.png}}\n     \\quad\n     \\subfloat[$t =100s$ \\label{5U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0100.png}}\n     \\quad\n     \\subfloat[$t = 500s$ \\label{6U_beta0}]{\\includegraphics[scale=0.15]{cap4/2022-03-18_14-49-41/frame.0499.png}}\n     \\quad\n     \\subfloat[\\label{legU_beta0}]{\\includegraphics[scale=0.4]{cap4/2022-03-18_14-49-41/legenda.png}}\n     \\caption[2cell RR Active ROPs coupled auxin-PIN - with the F6 $\\rho = 2$ set and and $\\beta_{uRR} = \\beta_{vRR} = 0$]{Active ROPs $u$ evolution with RR algorithm solver on 2 cells system coupled with auxin-PIN dynamics, with the F6 $\\rho = 2$ parameters set and no communicating channels ($\\beta_{uRR} = \\beta_{vRR} = 0)$.}\n     \\label{fig:U_F62_beta0}\n \\end{figure}\n\nThough under initially oscillating values of auxin concentration and then constant high auxin level as shown in Figure \\ref{fig:Uaux_beta0}, no pattern in active ROPs is formed. Jumps of auxin levels generates a gradient in the distribution in the two cell system, but locally inside each cell auxin is still constant and no-flux boundary conditions between the cells correspond to solve the two cells separately, as if they do not belong to the same multi-cellular system.\n\nThe comparison between the pattern in Figure \\ref{fig:U_F62_beta0} and the ones obtained with open channels in Figure \\ref{fig:U_F62} is one of the most interesting result of the multi-cellular system coupled with auxin-PIN dynamics. Indeed, it confirms that responsible for spot generation can be not only auxin distribution but also the strucutral communication between cells. Setting no-flux boundary condition between cells, the system evolves to a null homogeneus active ROPs distribution. Therefore, this test validate that the main responsible for pattern formation in simulation presented in Figure \\ref{fig:U_F62} is the modelled open channels between cells.\n\nOscillations of auxin concentrations in a row of cells are not a bad approximation of the organization of root tissues \\cite{plant:Farcot} and the plot in Figure \\ref{fig:Uaux_beta0} present a physically reasonable behaviour of auxin distribution in a multi-cellular system. A null homogeneous active ROPs concentration as in Figure \\ref{fig:U_F62_beta0} is not what is expected from a physical intra-cellular model of ROPs dynamics under sufficiently high values of auxin. As a consequence, in order to have a complete, reliable spatially-extended model for root-hair initiation, it is necessary to consider structural communication between cells. The first attempt of communication modelling developed in this thesis is an interesting and valuable approach because of similarities between pattern observed in previously presented results and those in other works \\cite{phdthesis:victor}.\n\nWe present in Table \\ref{table:aux_summaryRes} a scheme of the results in order to give to the reader an overview of the motivations and main conclusions of each test presented in Chapter \\ref{cap:4}.\n% in coda una simulazione che da t 500 in poi tiene auxina fisso a 1\n% fatta una che tiene auxina fisso a 1 fino a 5oo e poi considera la dinamica; per sbaglio in 2022-04-06_15-39-08\n\n \\begin{table}[H]\n   \\caption*{\\textbf{Table summarizing presented results}}\n     \\begin{tabular}{|p{3cm} |p{4cm} p{4cm} p{3cm}|}\n     \\hline\n %    \\rowcolor{bluepoli!40}\n     \\textbf{Experiment} & \\textbf{Motivations} & \\textbf{Main conclusions} & \\textbf{Figures} \\T\\B \\\\\n     \\hline \\hline\n     \\textbf{E1} & Simulate auxin-PIN transport with different set of parameters & Confirm reliability of the semi-implicit method & \\ref{fig:Uaux_F4} - \\ref{fig:Uaux_F5} - \\ref{fig:Uaux_F62} - \\ref{fig:Uaux_F623} - \\ref{fig:Uaux_F627} - \\ref{fig:Uaux_F7} \\T\\B\\\\\n     \\hline\n     \\textbf{E2} & Simulate ROPs system with 2 cells array & Confirm gradient and channels influence & \\ref{fig:UH5} \\T\\B\\\\\n     \\hline\n     \\textbf{E3} - ROPs \\& auxin-PIN & Simulated different parameters sets F4, F5 and F7 & Responsible for spot fomation is the structural multi-cellular modeling & \\ref{fig:U_F4} - \\ref{fig:U_F5} - \\ref{fig:U_F7}\\T\\B\\\\\n     \\hline\n     \\textbf{E4} - ROPs \\& auxin-PIN & Simulated parameters set F6 under different $\\rho$ & Too rapid oscillations do not generate an auxin gradient relevant for spot fomation & \\ref{fig:U_F62} - \\ref{fig:U_F623} - \\ref{fig:U_F627} - \\ref{fig:U_F623_auxinconst} \\T\\B\\\\\n     \\hline\n     \\textbf{E5} - ROPs \\& auxin-PIN & Simulated parameters set F6 da capire se mettere & Too rapid oscillations do not generate an auxin gradient relevant for spot fomation & \\ref{fig:U_F62} - .... \\T\\B\\\\\n     \\hline\n     \\textbf{E6} - ROPs \\& auxin-PIN & Consider exponential distribution of auxin inside the cells & Double gradient influence in spot formation & \\ref{fig:U_F623_exp} \\T\\B\\\\\n     \\hline\n     \\textbf{E7} - ROPs \\& auxin-PIN & Simulate with bigger coefficient $\\alpha_{RR}$  & Channel influence on spot appearence & \\ref{fig:U_alpha5} \\T\\B\\\\\n     \\hline\n     \\textbf{E8} - ROPs \\& auxin-PIN & Simulate oscillating auxin with closed channels for ROP & No spot formation confirm importance of communication model & \\ref{fig:U_F62_beta0} \\T\\B\\\\\n     \\hline\n     \\end{tabular}\n     \\\\[10pt]\n     \\caption[Table summarizing auxin-PIN and RR results on two cells system]{}\n     \\label{table:aux_summaryRes}\n \\end{table}\n", "meta": {"hexsha": "3355baece949e9505b3332d76492258236c1bf6c", "size": 63007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Chapter4.tex", "max_stars_repo_name": "danieleavitabile/root-simulator", "max_stars_repo_head_hexsha": "b530efef392f3cabbc251ee5f0d7d50dea2271d3", "max_stars_repo_licenses": ["MIT"], "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/Chapter4.tex", "max_issues_repo_name": "danieleavitabile/root-simulator", "max_issues_repo_head_hexsha": "b530efef392f3cabbc251ee5f0d7d50dea2271d3", "max_issues_repo_licenses": ["MIT"], "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/Chapter4.tex", "max_forks_repo_name": "danieleavitabile/root-simulator", "max_forks_repo_head_hexsha": "b530efef392f3cabbc251ee5f0d7d50dea2271d3", "max_forks_repo_licenses": ["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.6508515815, "max_line_length": 892, "alphanum_fraction": 0.7022394337, "num_tokens": 22288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6188063877272463}}
{"text": "\\section{The code for NMO}\n\nNow I'll show how to implement the above algorithm in Python using the NumPy and SciPy libraries \\citep{van_der_Walt_2011}.\nWe'll split the algorithm into three functions.\nThis is very important when programming any moderately complex code because it allows us to test each part of our code independently.\nIt also reduces the amount of code we have to search through to find that bug that is messing up our results.\nModular code is easier to understand and to reuse.\n\nThe first function I'll define performs the NMO correction on a given CMP gather.\nWe'll assume that the CMP gather is a 2D array of amplitudes and that the\nvelocities are a 1D array with $v_\\mathrm{NMO}$ for each time sample.\n\n\\begin{lstlisting}[language=python]\n    import numpy as np\n\n    def nmo_correction(cmp, dt, offsets, velocities):\n        nmo = np.zeros_like(cmp)\n        nsamples = cmp.shape[0]\n        times = np.arange(0, nsamples*dt, dt)\n        for i, t0 in enumerate(times):\n            for j, x in enumerate(offsets):\n                t = reflection_time(t0, x, velocities[i])\n                amplitude = sample_trace(cmp[:, j], t, dt)\n                if amplitude is not None:\n                    nmo[i, j] = amplitude\n        return nmo\n\\end{lstlisting}\n\nThis function is essentially the algorithm above translated to Python with some\nof the details pushed into the \\texttt{reflection\\_time} and\n\\texttt{sample\\_trace} functions, which we will define below.\n\nFirst, the function that calculates the reflection travel-time:\n\n\\begin{lstlisting}[language=python]\n    def reflection_time(t0, x, vnmo):\n        t = np.sqrt(t0**2 + x**2/vnmo**2)\n        return t\n\\end{lstlisting}\n\nFor the \\texttt{sample\\_trace} function, we'll use cubic splines from the\n\\texttt{scipy.interpolate} package.\nFor more information on interpolation with scipy, see the tutorial by\n\\citet{Hall_2016}.\n\n\\begin{lstlisting}[language=python]\n    from scipy.interpolate import CubicSpline\n\n    def sample_trace(trace, time, dt):\n        before = int(np.floor(time/dt))\n        N = trace.size\n        samples = np.arange(before - 1, before + 3)\n        if any(samples < 0) or any(samples >= N):\n            amplitude = None\n        else:\n            times = dt*samples\n            amps = trace[samples]\n            interpolator = CubicSpline(times, amps)\n            amplitude = interpolator(time)\n        return amplitude\n\\end{lstlisting}\n\nThe Jupyter notebook contains the full code for these functions, including\ndocumentation through Python documentation strings or ``docstrings'' and code\nthat tests that the functions work as expected.\nAlso included is an application of our \\texttt{nmo\\_correction} function to a\nsynthetic CMP (Figure 2).\n", "meta": {"hexsha": "be430c27005bd328fd1ce46441bf20e418c0e825", "size": 2727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "the-code-of-nmo.tex", "max_stars_repo_name": "katrinleinweber/nmo-tutorial", "max_stars_repo_head_hexsha": "8b3348010ba06ea0542628b930e0be6b149fb59e", "max_stars_repo_licenses": ["CC-BY-4.0", "BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-12-22T15:05:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T10:05:36.000Z", "max_issues_repo_path": "the-code-of-nmo.tex", "max_issues_repo_name": "katrinleinweber/nmo-tutorial", "max_issues_repo_head_hexsha": "8b3348010ba06ea0542628b930e0be6b149fb59e", "max_issues_repo_licenses": ["CC-BY-4.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": "the-code-of-nmo.tex", "max_forks_repo_name": "katrinleinweber/nmo-tutorial", "max_forks_repo_head_hexsha": "8b3348010ba06ea0542628b930e0be6b149fb59e", "max_forks_repo_licenses": ["CC-BY-4.0", "BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-08-04T07:24:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-11T16:56:23.000Z", "avg_line_length": 40.1029411765, "max_line_length": 133, "alphanum_fraction": 0.699669967, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6187874831113256}}
{"text": "\\documentclass[letterpaper, 8pt]{extarticle}\n\n\\usepackage{steven}\n\\usepackage[margin=1.5cm]{geometry}\n\\usepackage{physics}\n\\usepackage{oubraces}\n\\usepackage{parskip}\n\\usepackage{fancyhdr}\n\\usepackage{multicol}\n\\usepackage{titlesec}\n\\usepackage{mathtools}\n\\usepackage[nodisplayskipstretch]{setspace}\n\n\\setstretch{0.1}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\setlength{\\headheight}{20pt}\n\\setlength{\\headsep}{8pt}\n\\lhead{STA261 Cheatsheet}\n\\rhead{Steven Tran}\n\n\\titlespacing{\\section}{0pt}{\\parskip}{\\parskip}\n\n\\titleformat{\\section}\n\t{\\normalfont\\upshape\\bfseries}{\\thesection}{1em}{}\n\n\\pagenumbering{gobble}\n\\setlength\\parindent{0pt}\n\\hfuzz=\\maxdimen\n\n\\begin{document}\n\\begin{multicols*}{3}\n\t\\section{STA257 Basics}\n\tSet stuff\n\t\\begin{gather*}\n\t\tA,B\\text{ disjoint}\\Leftrightarrow A\\cap B=\\emp \\\\\n\t\tA\\cup B=B\\cup A \\\\\n\t\t(A\\cup B)\\cup C=A\\cup (B\\cup C) \\\\\n\t\t(A\\cup B)\\cap C=(A\\cap C)\\cup (B\\cap C)\n\t\\end{gather*}\n\tProbability Measure:\n\t\\begin{gather}\n\t\tP(\\Omega)=1 \\\\\n\t\tA\\subset\\Omega\\IMP P(A)\\geq 0\\\\\n\t\tA_i\\text{ mutually disjoint}\\scriptstyle\\IMP P\\mqty(\\bigcup_{i=1}^nA_i)=\\sum_{i=1}^nP(A_i)\n\t\\end{gather}\n\t\\text{PMF} $p(x_i)$\\quad\\text{PDF} $f(x_i)$\\quad CDF $F(x_i)$\n\t\\begin{gather*}\n\t\t\\shortintertext{Conditional Probability}\n\t\tP(A|B)=P(A\\cap B)/P(B)\n\t\t\\shortintertext{Law of Total Probability ($\\bigcup_{i=1}^nB_i=\\Omega,B_i$ disjoint, $P(B_i)>0$)}\n\t\tP(A)=\\sum_{i=1}^nP(A|B_i)P(B_i)\n\t\t\\shortintertext{Bayes': $A,B_i$ disjoint, $\\sum_{i=1}^nB_i=\\Omega,P(B_i)>0$, then}\n\t\tP(B_j|A)=\\frac{P(A|B_j)P(B_j)}{\\sum_{i=1}^nP(A|B_i)P(B_i)}\n\t\t\\shortintertext{Multinomial Coefficient: group $n$ objects into $k$ classes, each of size $n_i$}\n\t\t\\binom{n}{n_1,\\cdots,n_k}=\\frac{n!}{n_1!n_2!\\cdots n_k!} \n\t\t\\shortintertext{Binomial Theorem}\n\t\t(a+b)^n=\\sum_{k=0}^n\\binom{n}{k}a^kb^{n-k}\n\t\\end{gather*}\n\t\\section{Distributions}\n\tBernouilli: success ($p$) or failure ($1-p$) with $p\\IN[0,1]$. $X\\sim Ber(p)$ then\n\t\\[p(x)=\\begin{cases}p^x(1-p)^{1-x}, &x=0, 1\\\\0&\\text{otherwise}\\end{cases}\\]\n\tExpectation $p$ Variance $(1-p)p$ MGF $q+pe^t$\n\t\n\tBinomial: $n$ $Ber(p)$ trials with $k$ successes. $X\\sim Bin(n, p)$ then\n\t\\[p(k)=\\binom{n}{k}p^k(1-p)^{n-k}\\]\n\tE $np$\\quad V $npq$\\quad MGF $(1-p+pe^t)^n$\n\t\n\tGeometric: $k$ $Ber(p)$ trials until 1 success. $X\\sim Geo(p)$ then \n\t\\[p(k)=p(1-p)^{k-1}\\]\n\tE $\\frac{1}{p}$\\quad V $\\frac{1-p}{p^2}$\\quad MGF $\\frac{pe^t}{1-(1-p)e^t}$\n\t\\begin{gather*}\n\t\t\\sum_{n=1}^\\infty az^{n-1}=\\sum_{n=0}^\\infty az^n \\\\\n\t\t\\sum_{n=1}^ka_nr^{n-1}=a_n\\mqty(\\frac{1-r^k}{1-r})\n\t\\end{gather*}\n\tNeg. Binomial: $Ber(p)$ trials conducted until $r$ successes. $X\\sim NB(r,p)$ then\n\t\\[p(k)=\\binom{k-1}{r-1}p^r(1-p)^{k-r}\\]\n\tE $\\frac{r}{p}$\\quad V $\\frac{rp}{(1-p)^2}$\\quad MGF $\\mqty(\\frac{1-p}{1-pe^t})^2$\n\t\n\tHypergeometric: $X\\sim HG(n,m,r)$ where $n$ is the total number of items, $m$ is the number of items sampled, and $r$ is the number of items with a property, then\n\t\\[p(k)=\\frac{\\binom{r}{k}\\binom{n-r}{m-k}}{\\binom{n}{m}} \\tag{$k\\IN 0,\\cdots, \\min(r,m)$}\\]\n\tE $\\frac{mr}{n}$\n\t\n\tPoisson: \\# events. $X\\sim Poi(\\text{rate}=\\lambda)$ then\n\t\\[p(k)=\\frac{\\lambda^ke^{-\\lambda}}{k!}\\]\n\tE $\\lambda$\\quad V $\\lambda$\\quad MGF $e^{\\lambda(e^t-1)}$\n\t\n\tProperties of Poisson:\n\t\\begin{itemize}\n\t\t\\item For $|S_i|=N_i$ independent $Poi(\\lambda)$, $N_i\\sim Poi(\\lambda|S_i|)$\n\t\t\\item For $n$ large, $Bin(n,p)\\sim Poi(np)$ can be approximated\n\t\\end{itemize}\n\t\n\tExponential ($Gamma(1,\\lambda)$): $X$ waiting time $\\sim Exp(\\lambda)$, then \n\t\\[f(x)=\\lambda e^{-\\lambda x}\\quad F(x)=1-e^{-\\lambda x}\\]\n\tE $\\frac{1}{\\lambda}$\\quad V $\\frac{1}{\\lambda^2}$\\quad M $\\frac{\\lambda}{\\lambda-t}$\n\t\n\tGamma (sum $a$ iid $Exp(\\lambda)$): $X\\sim \\Gamma(a,\\lambda)$ then\n\t\\[f(x)=\\frac{\\lambda^a}{\\Gamma(a)}x^{a-1}e^{-x\\lambda}\\]\n\tE $\\frac{a}{\\lambda}$\\quad V $\\frac{a}{\\lambda^2}$\\quad M $\\mqty(\\frac{\\lambda}{\\lambda-t})^a$\n\t\n\tBeta: used to model proportions between $0$ and $1$ with $a,b>0$ shape parameters. $X\\sim Beta(a,b)$ then\n\t\\[f(x)=\\frac{\\Gamma(a+b)}{\\Gamma(a)\\Gamma(b)}x^{a-1}(1-x)^{b-1}\\]\n\tE $\\frac{a}{a+b}$\\quad V $\\frac{ab}{(a+b)^2(a+b+1)}$\n\t\n\tNormal: $X\\sim N(\\mu, \\sigma^2)$ then \n\t\\begin{gather*}\n\t\tf(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}} \\\\\n\t\t\\text{MGF } e^{\\mu t+\\frac{\\sigma^2t^2}{2}}\\quad f(\\mu-x)=f(\\mu+x) \\\\\n\t\t\\frac{X-\\mu}{\\sigma}\\sim N(0,1)\n\t\\end{gather*}\n\tStd. Normal $Z\\sim N(0,1)$ $\\phi(z)$ given in table\n\t\n\t$X_i\\sim N(\\mu_i,\\sigma^2_i$ for $i\\IN\\{1,\\cdots,n\\}$. $Y=\\sum_{i=1}^na_iX_i+b$, then\n\t\\[Y\\sim N\\mqty(\\displaystyle \\sum_{i=1}^na_i\\mu_i+b,\\sum_{i=1}^na_i^2\\sigma_i^2)\\]\n\t\n\tChi-Square distribution: $U=Z^2$ where $Z\\sim N(0,1)$, then $U\\sim\\chi^2_{df=1}$. If $X\\sim \\chi^2_{(m)}$ and $Y\\sim \\chi^2_{(n)}$ then $X+Y\\sim \\chi^2_{(m+n)}$. If $X\\sim\\chi^2_{(m)}$ then $E(X)=m$.\n\t\n\t$t$ distribution: $Z\\sim N(0,1)\\perp U\\sim\\chi^2_{(m)}$ then $\\frac{Z}{\\sqrt{\\frac{U}{m}}}\\sim t_{(m)}$, the $t$ distribution with $m$ degrees of freedom\n\t\n\t$F$ distribution: $X\\sim\\chi^2_{(m)}\\perp Y\\sim\\chi^2_{(n)}$ then $\\frac{\\frac{X}{m}}{\\frac{Y}{n}}\\sim F(m,n)$.\n\t\n\t\\section{Inequalities, Expectation, Variance, MGFs}\n\t\n\tMarkov's Inequality: $P(X\\geq 0)=1, E(X)$ exists then \n\t\\[P(X\\geq t)\\leq \\frac{E(X)}{t}\\]\n\tChebyshev's Inequality: $P(|X-\\mu|>t)\\leq\\frac{\\sigma^2}{t^2}$ (proof: set $Y=(x-\\mu)^2$ and apply Markov))\n\t\\begin{gather*}\n\t\t\\text{r-th moment}=E(X^r) \\\\\n\t\t\\text{r-th central moment}=E\\mqty[(X-E(X))^r]\\\\\n\t\tM(t)=E(e^{tX})\\\\\n\t\tX\\perp Y\\IMP M_{X+Y}=M_XM_Y\\\\\n\t\tM_{XY}(s,t)=E(e^{sX+tY})\\\\\n\t\tM^{(r)}(0)=E(X^r)\\\\\n\t\tE(X)=\\sum_ix_ip(x_i)\\quad E(X)=\\int_\\R xf(x)\\dd x \\tag{provided these converge} \\\\\n\t\tY=g(X)\\IMP E(Y)=\\sum_ig(x_i)p(x_i) \\\\ E(Y)=\\int_\\R g(x)f(x)\\dd x \\\\\n\t\tE(aX+b)=aE(X)+E(b)\\quad E(XY)=E(X)E(Y) \\tag{if $X\\perp Y$} \\\\\n\t\tVar(X)=E\\mqty[(X-E(X))^2]\\\\\n\t\t=E(X^2)-(E(X))^2=\\int_\\R(x-\\mu)f(x)\\dd x \\\\\n\t\tsd=\\sqrt{Var(X)} \\\\\n\t\tY=aX+b\\IMP Var(Y)=a^2Var(X)\n\t\\end{gather*}\n\t\\section{Conditional \\& Multivariate Stuff}\n\tLaw of Total Expectation\n\t\\begin{gather*}\n\t\tE(Y)=E(E(Y|X)) \n\t\t\\shortintertext{Law of Total Variance}\n\t\tVar(Y)=Var(E(Y|X))+E(Var(Y|X))\\\\\n\t\tp_{xy}(x,y)=p_{X|Y}(x|y)p_y(y)\\\\\n\t\tp_x(x)=\\int_yp_{xy}(x,y)\\dd y\\\\\n\t\tE(Y)=\\idotsint \\underbrace{g(x_1,\\cdots,x_n)}_\\text{may do nothing}f(x_1,\\cdots,x_n)\\dd \\{x_i\\}\\\\\n\t\tE(Y|X=x)=\\sum_yp_{Y|X}(y|x) \\\\\n\t\tE(h(Y)|X=x)=\\int_yh(Y)f_{Y|X}(y|x)\\dd y\\\\\n\t\t\\shortintertext{$X_i\\perp X_j$ then $Var(\\sum x_i)=\\sum Var(X_i)$ and $Cov(X_i,X_j)=0$)}\\\\\n\t\tCov(X,Y)=E\\mqty[(X-\\mu_X)(Y-\\mu_Y)]\\\\\n\t\t=E(XY)-E(X)E(Y)\\\\\n\t\tCov(a+X,Y)=Cov(X,Y)\\\\\n\t\tCov(aX,bY)=abCov(X,Y)\\\\\n\t\tCov(X,Y+Z)=Cov(X,Y)+Cov(X,Z)\\\\\n\t\tVar(X+Y)=Var(X)+Var(Y)+2Cov(X,Y)\\\\\n\t\t\\begin{align*}\n\t\t\tCov(aW+bX,cY+dZ)&=acCov(W,Y)\\\\\n\t\t\t&+bcCov(X,Y)\\\\\n\t\t\t&+adCov(W,Z)\\\\\n\t\t\t&+bdCov(X,Z)\n\t\t\\end{align*}\\\\\n\t\tVar(a+\\sum b_ix_i)=\\sum_{i,j}b_ib_jCov(x_i,x_j)\n\t\\end{gather*}\n\t\\newpage\n\tPosterior density:\n\t\\[f_{P|X}(p|x)=\\frac{f_{X,P}(x,p)}{f_X(x)}=\\frac{f_{X|P}(x|p)f_P(p)}{f_X(x)}\\]\n\t\\section{Limit Theorems}\n\tLaw of Large Numbers: $X_1,X_2,\\cdots,X_i,\\cdots$ independent and $E(X_i)=\\mu$, $Var(X_i)=\\sigma^2$, $\\bar X_n=\\frac{1}{n}\\sum_{i=1}^nX_i$. \n\t\n\tThen $\\forall\\epsilon>0, P(|\\bar X_n-\\mu|>\\epsilon)\\overset{n\\to\\infty}{\\longrightarrow} 0$ by Chebyshev's inequality.\n\t\n\tConvergence in Distribution: $X_1,\\cdots$ are random variables with $F_1,\\cdots$, and $X$ has cdf $F$. $X_n\\overset{D}{\\longrightarrow}X$ if $F_n(X)\\overset{D}{\\rightarrow}F(X)$ wherever $F$ is continuous.\n\t\\begin{itemize}\n\t\t\\item the next outcome (as we get more and more $X_i$s) converge closer and closer to some cdf\n\t\t\\item to show converge in distribution, we usually use MGFs. Call $\\{F_n\\}$ a sequence of cdfs with MGFs $\\{M_n\\}$. \n\t\t\\[\\overbrace{M_N(t)\\to M(t)}^{\\forall t\\IN I\\sth 0\\IN t}\\IMP F_n(x)\\to F(x)\\]\n\t\tsince the MGF uniquely determines the distribution of a RV.\n\t\\end{itemize}\n\t\n\tCentral Limit Theorem: $X_1,\\cdots$ iid with mean $\\mu$, variance $\\sigma^2$, cdf $F$, MGF $M$ defined in a neighbourhood of $0$. Let $S_n=\\sum_{i=1}^n X_i$. Then $\\bar X_n\\overset{D}{\\to}N(\\mu,\\frac{\\sigma^2}{n})$ or $\\frac{\\bar X_n-\\mu}{\\frac{\\sigma}{\\sqrt n}}\\overset{D}{\\to}N(0,1)$ or $P\\mqty(\\frac{S_n}{\\sigma\\sqrt x}\\leq x)\\rightarrow\\phi(x)$.\n\t\n\tProof: $M_{S_n}(t)=\\mqty(M_x(t))^n,M_{Z_n}(t)=\\mqty(M_x\\mqty(\\frac{t}{\\sigma\\sqrt x}))^n,M_X(s)=M_X(0)+SM'(0)+\\frac{S^2}{2}M''(0)+\\epsilon_S$ with $\\frac{\\epsilon_S}{S^2}\\to 0$. This equals $1+\\frac{1}{2}\\sigma^2+\\mqty(\\frac{t}{\\sigma\\sqrt x}))^2+\\epsilon_n$, so $M_{Z_n}(t)=\\mqty(1+\\frac{t^2}{2n}+\\epsilon_n)^n\\to e^{\\frac{t^2}{2}}$ hence $Z_n\\sim N(0,1)$.\n\t\n\t\\section{Definitions}\n\t\\begin{itemize}\n\t\t\\item Population: a collection of all the subjects that have something in common.\n\t\t\\item[$\\to$] Parameter: a characteristic/summary of the population, represented by $\\theta$. Can be mean ($\\mu$), std. dev ($\\sigma$), etc.\n\t\t\\item Sample: a subset of the population. We use the sample to make an inference about the unknown parameters of our population.\n\t\t\\item[$\\to$] Statistic: any summary of the sample; since statistics/estimators are a function of sample observations, we use $T$ to represent them. Examples: sample total ($\\sum X_i$), sample mean ($\\bar X$), etc.\n\t\\end{itemize}\n\t\\begin{center}\t\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\hline\n\t\tparameter & estimator & estimate \\\\\\hline\n\t\t$\\mu$ & $\\bar X=\\frac{\\sum X}{n}$ & $\\bar x=\\frac{\\sum x}{n}$ \\\\\n\t\t$\\sigma$ & $S$ & $s$\\\\\\hline\n\t\\end{tabular}\n\t\\end{center}\n\t\n\t\\section{Method of Moments}\n\t$X_1,\\cdots,X_n$ iid RVs. Define the k-th population moment to be $\\mu_k=E(X^k)$ and the k-th sample moment to be $\\hat\\mu_k=\\frac{1}{n}\\sum_{i=1}^nX_i^k$. We use $\\hat\\mu_k$ as an estimator of $\\mu_k$ using 3 steps:\n\t\\begin{enumerate}\n\t\t\\item express lower order population moments in terms of the parameters\n\t\t\\item invert the expressions to express the parameters in terms of the population moments\n\t\t\\item replace the population moments using the sample moments\n\t\\end{enumerate}\n\t\\section{Likelihood}\n\t$X_1,\\cdots,X_n$ RVs with joint density/mass function $f(x_1,\\cdots,x_n|\\theta)$. Given a sample $(x_1,\\cdots,x_n)$, the likelihood function of $\\theta$ is defined as\n\t\\[L(\\theta):=L(\\theta|x_1,\\cdots,x_n)=f(x_1,\\cdots,x_n|\\theta)\\]\n\twhere the likelihood is intuitively the probabilility of the parameter being some value given the sample data. If $X_1,\\cdots,X_n$ are iid, then we can express the joint as the product of the marginal densities, i.e.\n\t\\[L(\\theta)=\\prod_{i=1}^nf_\\theta(x_i)\\]\n\tSuppose we have $\\theta$ with likelihood function $L(\\theta)$. The best point estimate can be found by picking a $\\hat\\theta$ that maximizes $L(\\theta)$, i.e. $\\hat\\theta$ satisfies $L(\\hat\\theta)\\geq L(\\theta)\\quad \\forall\\theta\\IN\\Omega$.\n\t\n\tUsually, we compute the MLE by optimizing the log-likelihood $\\ell(\\theta)$ ($\\ln x$ is one-to-one and increasing). Solve $\\pdv{\\ell(\\theta)}{\\theta}=0$ for $\\theta$ and check that $\\left.\\pdv[2]{\\ell(\\theta)}{\\theta}\\right|_{\\theta=\\hat\\theta}<0$.\n\t\n\tInvariance property: suppose $\\hat\\theta$ is the MLE of $\\theta$ and let $\\psi(\\theta)$ be any 1-1 function of $\\theta$ defined on $\\Omega$, then $\\psi(\\hat\\theta)$ is the MLE of $\\psi(\\theta)$.\n\t\n\tFisher Information\n\t\\begin{align*}\n\t\tI(\\theta)&=E\\mqty[\\displaystyle\\pdv{\\theta}\\ln f(X|\\theta)]^2\n\t\t\\shortintertext{also, if $f$ is sufficiently smooth (in order to bring operation in integration when finding expectation),}\n\t\t&=-E\\mqty[\\displaystyle\\pdv[2]{\\theta}\\ln f(X|\\theta)]\n\t\\end{align*}\n\t\n\tThe large sample distribution of a MLE is approximately normal with mean $\\theta_0$ and variance $\\frac{1}{nI(\\theta_0)}$. Moreover, the asymptotic variance is given by\n    \\[\\underbrace{Var(\\hat\\theta)\\geq\\frac{1}{nI(\\theta_0)}}_\\text{Cram\\'er-Rao Bound}=-\\frac{1}{E\\ell''(\\theta_0)}\\]\n    \n    Proof: consider the correlation coefficient $\\rho$ between two variables $Y,Z$, which is bounded between $-1$ and $1$.\n    Then\n    \\begin{align*}\n        \\rho^2(T,S()\\theta))&\\leq 1 \\\\\n        \\frac{(\\text{cov}(T,S(\\theta)))^2}{\\text{var}(T)\\text{var}(S(\\theta))}&\\leq 1 \\\\\n        \\IMP \\text{var(T)}&\\geq\\frac{(\\text{cov}(T,S(\\theta)))^2}{\\text{var}(S(\\theta))}\n    \\end{align*}\n\t\n\t\\section{Mean Squared Error \\& Bias}\n\tLet $\\theta$ be a parameter, $\\psi(\\theta)$ be a real-valued function, and $T$ be an estimator of $\\psi(\\theta)$. The Mean Squared Error is defined as\n\t\\begin{align*}\n\t\tMSE_\\theta(T)&=E_\\theta[(T-\\psi(\\theta))^2\\\\\n\t\t&=Var_\\theta(T)+(E_\\theta(T)-\\psi(\\theta))^2 \\tag{*}\\\\\n\t\t&=Var_\\theta(T)+(Bias(T))^2\n\t\\end{align*}\n\tProof (*): Add $-E(T)+E(T)$ to inner term in definition of MSE, expand using squares.\n\t\\[\\text{Bias}:=E_\\theta(T)-\\psi(\\theta)\\]\n\tWhen the bias of an estimator is 0, it is unbiased.\n\t\n\t\\section{Quiz 1 Problems}\n\t\\begin{enumerate}[label=\\alph*), wide, labelwidth=0pt, labelindent=0pt]\n\t\t\\item (Rice E8Q4) Suppose $X$ is a discrete random variable with $P(X=0,1,2,3)=\\frac{2}{3}\\theta,\\frac{1}{3}\\theta,\\frac{2}{3}(1-\\theta),\\frac{1}{3}(1-\\theta)$ respectively where $\\theta\\IN[0,1]$ and 10 observations were taken: $(3,0,2,1,3,2,1,0,2,1)$. \n\t\t\n\t\tMethod of moments estimate of $\\theta$: $E(X)=\\sum_{k=0}^3kP(X=k)=\\frac{\\theta}{3}+\\frac{4}{3}(1-\\theta)+(1-\\theta)=\\frac{7}{3}-2\\theta$. We rearrange for $\\theta$ and write the sample mean $\\bar X$ in place of $E(X)$: $\\hat\\theta=\\frac{7}{6}-\\frac{1}{2}\\bar X$ which yields $\\hat\\theta=0.417$.\n\t\t\n\t\tStandard error: we need to calculate the variance of $X$ ($Var(X)=E(X^2)-(E(X))^2$). The process yields $E(X^2)=\\frac{17-16\\theta}{3}$ so $Var(X)=-4\\theta^2+4\\theta+\\frac{2}{9}$. $Var(\\bar X)=Var(\\frac{1}{n}\\sum_{i=1}^nX_i)=\\frac{1}{n^2}Var(X_i)=\\frac{1}{n}Var(X_1)$. \n\t\t\n\t\t$Var(\\hat\\theta)=\\frac{1}{4}Var(\\bar X)=-\\frac{1}{10}\\theta^2+\\frac{1}{10}\\theta+\\frac{1}{180}$. We replace $\\theta$ with $\\hat\\theta=0.417$, yielding that $s_{\\hat\\theta}^2=0.0299$ and the standard deviation is simply the square of this.\n\t\t\n\t\t\\item (Rice E8Q19) Suppose $X_1,\\cdots,X_n$ are iid $N(\\mu, \\sigma^2)$. MLE of each of $\\sigma,\\mu$, with the other one known: \n\t\t\n\t\t$L(\\theta)=\\frac{1}{\\sigma^n(2\\pi)^\\frac{n}{2}}e^{-\\frac{1}{2}}\\left(\\sum_{i=1}^n\\left(\\frac{x_i-\\mu}{\\sigma}\\right)^2\\right)$. Log likelihood: $\\ell(\\theta)=-n\\ln(\\sigma)-\\frac{n}{2}\\ln(2\\pi)-\\frac{1}{2\\sigma^2}\\sum_{i=1}^n(x_i-\\mu)^2$ and then maximize this function for each parameter. We get that $\\hat\\sigma=\\sqrt{\\frac{1}{n}\\sum_{i=1}^n(x_i-\\mu)^2}$ and $\\hat\\mu=\\frac{\\sum_{i=1}^nx_i}{n}$.\n\t\t\n\t\t\\item (Rice E8Q7) Suppose $X\\sim Geo(p)$ and we have an iid sample of size $n$. Method of moments estimate of $p$: we are looking to express $p$ in terms of the moments; we have that $E(X)=p$ so $p=\\frac{1}{E(X)}$. Hence, $\\hat p=\\frac{1}{\\bar X}$.\n\t\t\n\t\tMLE of $p$: $L(p)=p^n(1-p)^{\\sum_{i=1}^n(x_i-1)}$, $\\ell(p)=n\\ln(p)+\\sum_{i=1}^n(x_i-1)\\ln(1-p)$ which we can use to maximize $p$: $p=\\frac{n}{\\sum_{i=1}^nx_i}=\\frac{1}{\\bar X}$, obtaining that $\\bar p=\\frac{1}{\\bar X}$.\n\t\t\n\t\tVariance of our MLE: $Var(\\hat p)=\\frac{-1}{E(\\ell''(p)}$ asymptotically and we have that $E(\\ell''(p))=E\\left(-\\frac{n}{p^2}-\\left[\\sum_{i=1}^nX_i-n\\right]\\frac{1}{(1-p)^2}\\right)=-\\frac{n}{p^2}-\\left(\\sum_{i=1}^nE(X_i)-n\\right)\\frac{1}{(1-p)^2}=-\\frac{n}{p^2(1-p)}$. Hence $Var(\\hat p)\\approx\\frac{p^2(1-p)}{n}$.\n\t\t\n\t\tIf $p$ has a uniform prior distribution on $[0,1]$, the posterior distribution of $p$ is $f_{P|X}(p|x)=\\frac{f_{X|P}(x|p)f_p(p)}{f_X(x)}$. $f_{X|P}(x|p)$ is simply the likelihood function, and $f_X(x)$ can be computed: $f_X(x)=\\int_\\R f_{X|P}(x|p)f_P(p)\\dd p=\\int_0^1f_{X|P}(x|p)\\dd p=\\int_0^1p^n(1-p)^{\\sum_{i=1}^n(x_i-1)}\\dd p$. Relating this to a Beta distribution, we find a value for $f_X(x)$ so we plug it into $F_{P|X}(p|x)$.\n\t\t\n\t\tThe expected value of our posterior distribution is given by $E(P|X)=\\frac{n}{n+\\sum_{i=1}^nx_i-n}$ (again, using the mean of a Beta distribution).\n\t\\end{enumerate}\n\t\n\t\\newpage\n\t\\section{Types of Convergence}\n\t\\begin{itemize}\n\t\t\\item Convergence in distribution: $Z_n\\overset{d}{\\to}Z$ if $\\displaystyle\\lim_{n\\to\\infty}F_n(x)=F(x)$ everywhere $F$ is continuous\n\t\t\\item Convergence in probability: $Z_n\\overset{P}{\\to}Z$ if $\\displaystyle\\lim_{n\\to\\infty}P(|Z_n-Z)|>\\epsilon)=0$\n\t\t\\item Almost-surely convergence: $Z_n\\overset{a.s.}{\\to}Z$ if $P(\\displaystyle\\lim_{n\\to\\infty}Z_n=Z)=1$\n\t\\end{itemize}\n\t\\section{Unbiased Estimator for $\\sigma^2$}\n\tWe have that the population variance is\n\t\\[\\sigma^2=\\frac{1}{N}\\sum_{i=1}^N(X_i-\\mu)^2\\]\n\tand we have may want to estimate it using $\\frac{1}{n-1}\\sum_{i=1}^n(X_i-\\bar X)^2$ or $\\frac{1}{n}\\sum_{i=1}^n(X_i-\\bar X)^2$. The first is unbiased, and the other one (given by both the method of moments \\& MLE estimation) is biased. Proof:\n\t\\begin{align*}\n\t\t\\sum_i(X_i-\\mu)^2&=\\sum_i(X_i-\\bar X+\\bar X-\\mu)^2\\\\\n\t\t&=\\sum_i\\left[(X_i-\\bar X)^2+(\\bar X-\\mu)^2\\right.\\\\\n\t\t&+\\left.2(X_i-\\bar X)(\\bar X-\\mu)\\right]\\\\\n\t\t&=n\\hat\\sigma^2+n(\\bar X-\\mu)^2+0(\\bar X-\\mu)\\\\\n\t\t&=\\sum_i(X_i-\\bar X)^2+n(\\bar X-\\mu)^2\\\\\n\t\t\\sum_i(X_i-\\bar X)^2&=\\sum_i(X_i-\\mu)^2-n(\\bar X-\\mu)^2\n\t\t\\shortintertext{Take expectation on both sides:}\n\t\tE[\\cdots]&=\\sum_iVar(X_i)-nVar(\\bar X)\\\\\n\t\t&=\\sum_i\\sigma^2-n\\frac{\\sigma^2}{n}=n\\sigma^2-\\sigma^2\\\\\n\t\t&=(n-1)\\sigma^2\n\t\\end{align*}\n\tAnother method for the normal distribution: it can be shown that $\\bar X$ and $S^2$ are independent, and $\\frac{(n-1)S^2}{\\sigma^2}\\sim\\chi^2_{(n-1)}$. Starting with the equation before we took the expectation, we can divide it by $\\sigma^2$ to obtain\n\t\\[\\sum_i\\left(\\frac{X_i-\\mu}{\\sigma}\\right)^2=\\frac{(n-1)S^2}{\\sigma^2}+\\left(\\frac{\\bar X-\\mu}{\\sigma/\\sqrt n}\\right)^2\\]\n\twhere $\\sum_i\\left(\\frac{X_i-\\mu}{\\sigma}\\right)^2\\sim\\chi^2_{(n)}$ and $\\left(\\frac{\\bar X-\\mu}{\\sigma/\\sqrt n}\\right)^2\\sim\\chi^2_{(1)}$. So we can use MGFs and the independence of $\\bar X$ and $S^2$ to find that $\\frac{(n-1)S^2}{\\sigma^2}\\sim\\chi^2_{(n-1)}$. Since the expectation of a Chi Square variable is just its degrees of freedom we have that $E(S^2)=\\sigma^2$ so $S^2$ is an unbiased estimator of $\\sigma^2$ under the normal distribution.\n\t\n\t\\section{Sufficient Statistic}\n\tRoughly, a sufficient statistic for a parameter is a summary of a sample which yields the same information about the parameter as the entire sample (data reduction). Formally, a statistic $T(X_1,\\cdots,X_n)$ is sufficient for $\\theta$ if the conditional distribution of $X_1,\\cdots,X_n$ given $T=t$ doesn't depend on $\\theta$.\n\t\n\t\\textbf{Factorization Theorem}: $T(X_1,\\cdots,X_n)$ is sufficient for $\\theta$ if the joint probability function factors in the form\n\t\\begin{align*}\n\t\t&f(x_1,\\cdots,x_n|\\theta) \\\\\n\t\t=\\ &g(T(x_1,\\cdots,x_n),\\theta)h(x_1,\\cdots,x_n)\n\t\\end{align*}\n\twhere $h$ is a function of sample observations and $g$ involves $\\theta$ and the sufficient statistic $T$.\n\t\n\tIt is also useful to identify distributions in the exponential family of distributions. We can express the density or frequency functions in the form\n\t\n\t\\[f(x|\\theta)=\\begin{cases}\n\te^{c(\\theta)T(x)+d(\\theta)+S(x)}, & x\\IN A\\\\\n\t0, & x\\not\\in A\n\t\\end{cases}\\]\n\tSuch distributions include the  normal, exponential, log-normal, gamma, chi-squared, beta, Dirichlet, Bernoulli, categorical, Poisson, geometric, inverse Gaussian, von Mises and von Mises-Fisher distributions. Some distributions are exponential families only if some of their parameters are held fixed. {\\tiny The family of Pareto distributions with a fixed minimum bound $x_m$ form an exponential family. The families of binomial and multinomial distributions with fixed number of trials n but unknown probability parameter(s) are exponential families. The family of negative binomial distributions with fixed number of failures (a.k.a. stopping-time parameter) r is an exponential family. However, when any of the above-mentioned fixed parameters are allowed to vary, the resulting family is not an exponential family.} As mentioned above, as a general rule, the support of an exponential family must remain the same across all parameter settings in the family.\n\t\n\t\\section{Consistent Estimators}\n\tIn this course, consider only estimators being consistent in probability. \n\t\n\tImmediate results: the LLN tells use that $\\bar X=\\frac{1}{n}\\sum X_i\\overset{P}{\\to}E(X_i)$ for any distribution, so $\\bar X$ is a consistent estimator of $\\mu$ for $X_i\\overset{iid}{\\sim}N(\\mu,\\sigma^2)$, $\\bar X$ is a consistent estimator of $\\lambda$ for $X_i\\overset{iid}{\\sim}Poi(\\lambda)$, etc.\n\t\n\t\\textbf{Slutsky's lemma}: $X_n, Y_n$ are sequences.\n\t\\begin{gather*}\n\t\tX_n\\overset{P}{\\to}X, Y_n\\overset{P}{\\to}Y\\IMP X_n+Y_n\\overset{P}{\\to}X+Y \\\\\n\t\tX_n\\overset{P}{\\to}X, Y_n\\overset{P}{\\to}Y\\IMP X_nY_n\\overset{P}{\\to}XY\n\t\\end{gather*}\n\t\\textbf{Continuous mapping theorem}: $X_n\\overset{P}{\\to}X$ and $g$ continuous. Then $g(X_n)\\overset{P}{\\to}g(X)$\n\t\n\t\\textbf{MSE consistent}: an estimator $T_n$ is MSE consistent if $MSE(T_n)\\overset{n\\to\\infty}{\\longrightarrow}0$\n\t\n\tWe have that the MLE is consistent. Let $\\theta_0$ represent the true value of the parameter which produced the data (unknown, constant) let $X_i\\overset{iid}{\\sim} f(x|\\theta_0)$, and let $\\hat\\theta$ be the MLE. Proof that $\\hat\\theta\\overset{P}{\\to}\\theta_0$: start with the log likelihood $\\ell(\\theta)=\\sum_{i=1}^n\\log f(X_i|\\theta)$. Divide both sides by the sample size $n$ and apply LLN.\n\t\n\tSince $\\frac{1}{n}\\ell(\\theta)$ gets closer to $E(\\log f(X_i|\\theta))$, the $\\theta$ that maximizes $\\frac{1}{n}\\ell(\\theta)$ should be closed to the $\\theta$ that maximizes $E(\\log f(X_i|\\theta))$. We can show that $E(\\log f(X_i|\\theta))$ is maximized at $\\theta_0$.\n\t\n\t\\section{Score and Fisher Information}\n\tThe score function is the derivative of the log likelihood, \n\t\\[S(\\theta)=\\pdv{\\theta}\\ell(\\theta)=\\ell'(\\theta)\\]\n\tand the solution to the score equation \n\t\\[S(\\theta)=0\\]\n\tis the MLE. We say that $\\left.S(\\theta)\\right|_{\\theta=\\hat\\theta}=0$.\n\t\n\tThe score as a random variable for iid $X_i$ has that\n\t\\begin{align*}\n\t\tS(\\theta|X_i)&=\\pdv{\\theta}\\sum_i\\log f(X_i|\\theta)\\\\\n\t\t&=\\sum_i\\pdv{\\theta}\\log f(X_i|\\theta)=\\sum_iS(\\theta|X_i)\n\t\\end{align*}\n\tThey key takeaway is that $S(\\theta)$ is random; for a different set of observations, the likelihood function varies. \n\t\n\tThe Fisher Information is defined by\n\t\\begin{align*}\n\t\tI(\\theta_0)&=Var\\left(S(\\theta|X)|_{\\theta=\\theta_0}\\right)\\\\\n\t\t&=E\\left(\\pdv{\\theta}\\left.\\log f(X|\\theta)\\right|_{\\theta=\\theta_0}\\right)^2\\\\\n\t\t&=-E\\left(\\pdv[2]{\\theta}\\log f(X|\\theta)|_{\\theta=\\theta_0}\\right)\n\t\\end{align*}\n\tand is the amount of information that each observable random variable $X$ contains about $\\theta$.\n\t\\section{Quiz 2 Problems}\n\t\\begin{enumerate}[label=\\alph*), wide, labelwidth=0pt, labelindent=0pt]\n\t\t\\item (W4 Notes) Suppose $X_1,X_2,X_3\\overset{iid}{\\sim}Poi(\\lambda)$. Verify that $T=\\sum_{i=1}^3X_i$ is a sufficient statistic for $\\lambda$.\n\t\t\\begin{align*}\n\t\t\t&P(X_1=x_1,\\cdots,X_3=x_3|\\sum x_i=t)\\\\\n\t\t\t&=\\frac{P(X_1=x_1,\\cdots,X_3=x_3,\\sum x_i=t)}{P(\\sum x_i=t)}\\\\\n\t\t\t&=\\frac{P(X_1=x_1,\\cdots,X_3=t-(x_1+x_2))}{P(\\sum x_i=t)}\\\\\n\t\t\t&=\\frac{\\frac{\\cancel{e^{-\\lambda}}\\lambda^{x_1}}{x_1!}\\frac{\\cancel{e^{-\\lambda}}\\lambda^{x_2}}{x_2!}\\frac{\\cancel{e^{-\\lambda}}\\lambda^{t-(x_1+x_2)}}{(t-(x_1+x_2))!}}{\\frac{\\cancel{e^{-3\\lambda}}(3\\lambda)^t}{t!}}\\\\\n\t\t\t&=\\frac{\\cancel{\\lambda^t}}{x_1!x_2!}\\frac{t!}{(3\\cancel{\\lambda})^t}=\\frac{t!}{x_1!x_2!3^t}\n\t\t\\end{align*}\n\t\twhich doesn't depend on $\\lambda$.\n\t\t\n\t\t\\item (W4 Notes) Factorization theorem for $Poi(\\lambda)$:\n\t\t\\begin{align*}\n\t\t\tL(\\lambda)&=e^{n\\lambda}\\lambda^{\\sum x_i}\\frac{1}{\\prod x_i!}\\\\\n\t\t\t&=g\\left(\\sum_{i=1}^nx_i,\\lambda\\right)h(x_1,\\cdots,x_n)\n\t\t\\end{align*}\n\t\tso $T=\\sum x_i$ is a sufficient statistic for $\\lambda$.\n\t\t\n\t\t\\item (W4 Notes) Score \\& Fisher Information using Poisson Distribution\n\t\t\n\t\tLet $X_1,\\cdots,X_n\\overset{iid}{\\sim}Poi(\\lambda)$ with $\\lambda_0$ parameter. \n\t\t\\begin{align*}\n\t\t\tL(\\lambda)&=\\prod f(X_i|\\theta)\\\\\n\t\t\t&=\\prod\\frac{e^{-\\lambda}\\lambda^{\\sum X_i}}{\\prod X_i!}\\\\\n\t\t\t\\ell(\\lambda)&=-n\\lambda +(\\sum X_i)\\ln\\lambda-\\sum\\ln(X_i)!\\\\\n\t\t\t\\pdv{\\lambda}\\ell(\\lambda)&=-n+\\frac{\\sum X_i}{\\lambda}\\\\\n\t\t\tI(\\lambda_0)&=Var(S(\\lambda|X)|_{\\lambda=\\lambda_0})\\\\\n\t\t\t&=Var\\left(-1+\\frac{X}{\\lambda_0}\\right)\\\\\n\t\t\t&=\\frac{1}{\\lambda^2_0}Var(X)=\\frac{1}{\\lambda_0}\n\t\t\\end{align*}\n    \\end{enumerate}\n    \\newpage\n    \\section{Efficiency}\n    For two estimators $T_1,T_2$ of a statistic $\\theta$, the efficiency of $T_1$ relative to $T_2$ is\n    \\[\\text{eff}(T_1,T_2)=\\frac{\\text{var}(T_2)}{\\text{var}(T_1)}\\]\n    A more efficient estimator has a smaller variance, and the most efficient unbiased estimator achieves the Cram\\`er-Rao Lower Bound.\n\n    \\section{Distribution of MLE}\n    Under some conditions, as $n\\to\\infty$, \n    \\[\\frac{\\hat\\theta-\\theta_0}{\\sqrt{\\frac{1}{n}I(\\theta_0)}}\\overset{D}{\\to}N(0,1)\\]\n    As a consequence, for large $n$, $E(\\hat\\theta)=\\theta_0$ and $V(\\hat\\theta)=\\frac{1}{nI(\\theta_0)}$.\n\n    Proof: we have that $\\ell'(\\hat\\theta)=0, E(\\ell'(\\theta_0))=0), \\ell'(\\theta_0)\\overset{D}{\\to}N(0,nI(\\theta_0))$ so $\\frac{1}{n}\\ell'(I(\\theta_0))\\overset{D}{\\to}N(0,\\frac{1}{n}I(\\theta_0))$. \n    \n    Additionally, by LLN, $\\frac{1}{n}\\ell''(\\theta_0)\\overset{P}{\\to}-I(\\theta_0)$. \n\n    We then use the Taylor series expansion of $\\ell'(\\hat\\theta)$ around $\\theta_0$ to find that\n    \\[\\hat\\theta-\\theta_0\\approx-\\frac{\\ell'(\\theta_0)}{\\ell''(\\theta_0)}=\\frac{\\frac{1}{n}\\ell'(\\theta_0)}{-\\frac{1}{n}\\ell''(\\theta_0)}\\]\n    And with this we obtain the result. Additionally, the MLE is: asymptotically unbiased, a function of sufficient statistics, consistent, and asymptotically efficient.\n\n    \\section{Confidence Intervals}\n    Some sampling distributions:\n    \\begin{itemize}\n        \\item $X_1,\\cdots,X_n\\overset{iid}{\\sim}N(\\mu,\\sigma^2)$:\n        \\begin{gather*}\n            \\frac{\\bar X-\\mu}{\\sigma/\\sqrt n}\\sim N(0,1) \\\\\n            \\frac{\\bar X-\\mu}{S/\\sqrt n}\\sim t_{(n-1)} \\\\\n            \\frac{(n-1)S^2}{\\sigma^2}\\sim\\chi^2_{(n-1)}\n        \\end{gather*}\n        \\item Distribution of MLE (above)\n    \\end{itemize}\n    $\\gamma$-Confidence interval: intuitively, some interval which will have at least $\\gamma$ chance of containing the true parameter. $C(X_1,\\cdots,X_n)=(l(X_1,\\cdots,X_n),u(X_1,\\cdots,X_n))$ is a $\\gamma$ confidence interval for $\\psi$ if $P(l()\\leq\\psi(\\theta)\\leq u)\\geq\\gamma$ for every $\\theta\\IN\\Omega$.\n\n    Pivotal Quantity: a random variable defined in terms of the sample; involves the unknown parameters in its expression, but the distribution of this quantity doesn't depend on the parameters.\n\n    For each of the sampling distributions above, we can use the $z, t$, or $\\chi^2$ distributions to calculate the necessary quantiles which correspond to $\\gamma$. We use the standard normal for $\\mu$ when $\\sigma^2$ is known, the $t$ distribution for $\\mu$ when $\\sigma^2$ is unknown, and the $\\chi^2$ distribution for $\\sigma^2$. \n    \n    For two-sided confidence intervals, notice that the $Z,t$ distributions are symmetric about their means so the shortest interval is also symmetric about the mean. For the $chi^2$ distribution, we use $\\frac{1\\pm\\gamma}{2}$ even though it may not yield the shortest interval (its shape is determined by the degrees of freedom).\n\n    For MLE-based confidence intervals, the confidence interval is given by\n    \\[\\hat\\theta\\pm z_{(\\frac{1+\\gamma}{2})}\\sqrt{\\frac{1}{nI(\\theta_0)}}\\]\n    where $\\hat\\theta$ is the MLE and we use either a plug-in estimate of the Fisher Information (replace $\\theta_0$ by $\\hat\\theta$) or the observed Fisher Information (replace $\\theta_0$ with summary of observed data).\n\n    For one-sided confidence intervals, we consider one side of each distribution.\n\n    Interpretation:\n    \\begin{itemize}\n        \\item For $z,t$ intervals, the sample mean is the midpoint of the lower and upper bound. The width of the interval is given by $u-l$, and the margin of error is half of the width.\n        \\item The width of the interval increases as the confidence level increases or the standard deviation ($\\sigma,s$) increases\n        \\item The width of the interval decreases as the sample size increases\n        \\item CIs are not fixed numbers but rather random variables; ``there is a 95\\% chance that $\\mu$ is between 4.442 and 5.318 is incorrect.'' Rather, we should say, ``if we keep taking samples and construct 0.95-CIs, 95\\% of the confidence intervals will capture the true value of the parameter.''\n\t\\end{itemize}\n\t\n\t\\section{Hypothesis Tests}\n\tNull Hypothesis, $H_0$: the hypothesis we want to test with respect to the parameter. Usually will be a simple hypothesis (parameter takes a single value from the parameter space).\n\n\tAlternative Hypothesis, $H_A$ or $H_1$: other values the parameter of interest can take on. Usually will be a composite hypothesis.\n\n\tWe use test statistics which, under the null hypothesis, will have a known distribution. Some of the pivotal quantities used to construct confidence intervals are useful for the critical region or $p$-value approach.\n\n\tCritical region, $R_\\alpha(T)$ ($\\alpha\\IN[0,1]$): a region of the distribution of the test statistic under the null hypothesis such that we reject $H_0$ if $T(X)\\IN R_\\alpha(T)$.\n\t\\[P[T(X)\\IN R_\\alpha(T)|H_0\\text{ true}]=\\alpha\\]\n\n\t$p$-value: the smallest level of significance at which $H_0$ would be rejected based on the observed data, or the probability of observing the result as or more extreme than what was actually observed if $H_0$ is true. We reject $H_0$ if the $p$-value is less than a cutoff (conventionally, $0.01,0.05,0.1$).\n\n\tSome example $p$-values for two-sided tests:\n\n\t\\begin{gather*}\n\t\t2\\left(1-\\Phi\\left(\\left|\\frac{\\bar x-\\mu_0}{\\sigma/\\sqrt n}\\right|\\right)\\right) \\tag{z test} \\\\\n\t\t2\\left(1-G\\left(\\left|\\frac{\\bar x-\\mu_0}{s/\\sqrt n}\\right|\\right)\\right) \\tag{t test}\n\t\\end{gather*}\n\n\t\\begin{center}\n\t\t\\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t& fail to reject $H_0$ & reject $H_0$ \\\\\\hline\n\t\t\t$H_0$ true & correct & type 1 ($\\alpha$) \\\\\\hline\n\t\t\t$H_0$ false & type 2 ($\\beta$) & correct \\\\\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\tNotice that $\\alpha,\\beta$ are inversely related. \n\n\tPower of a test: $1-\\beta$. We calculate this using the density under $H_1$; start with finding $R_a$ given $H_0$, and then calculate the probability of having data within the rejection region given $H_1$.\n\n\t\\section{Tests of Two Populations}\n\tBy constructing other test statistics, we can reduce a hypothesis test involving two population parameters to one of the previous tests.\n\n\tConsider two independent normal samples\n\t\\begin{gather*}\n\t\tX_1,\\cdots,X_n\\sim N(\\mu_x,\\sigma^2_x) \\\\\n\t\tY_1,\\cdots,Y_m\\sim N(\\mu_y,\\sigma^2_y)\n\t\\end{gather*}\n\tSay we want to test $H_0:\\sigma^2_x=\\sigma^2_y$ vs $H_1:\\sigma^2_x\\neq\\sigma^2_y$, then using an $F$ distribution, we can write\n\t\\[\\frac{S^2_x/\\sigma^2_x}{S^2_y/\\sigma^2_y}\\sim F_{n-1,m-1}\\]\n\tUnder $H_0$, $\\frac{S^2_x}{S^2_y}\\sim F_{n-1,m-1}$ and the rejection region is $(-\\infty, F_{\\alpha/2,(n-1,m-1))})\\cup (F_{1-\\alpha/2,(n-1,m-1)}, \\infty)$\n\n\tSay we want to test $H_0:\\mu_x=\\mu_y$ ($\\mu_x-\\mu_y$) vs $H_1:\\mu_x\\neq \\mu_y$ with $\\sigma_x,\\sigma_y$ known. We can use $\\bar X,\\bar Y$ to estimate each parameter respectively, giving\n\t\\begin{gather*}\n\t\t\\bar X-\\bar Y\\sim N\\left(\\mu_x-\\mu_y,\\sigma^2_x/n+\\sigma^2_y/m\\right) \\\\\n\t\t\\frac{(\\bar X-\\bar Y)-(\\mu_x-\\mu_y)}{\\sqrt{\\sigma^2_x/n+\\sigma^2_y/m}}\\sim N(0,1)\n\t\t\\intertext{and under $H_0$}\n\t\t\\frac{(\\bar X-\\bar Y)}{\\sqrt{\\sigma^2_x/n+\\sigma^2_y/m}}\\sim N(0,1)\n\t\\end{gather*}\n\tAlso if we know $\\sigma_x=\\sigma_y=\\sigma$, we can factor out the population variance term in the denominator above.\n\n\tSay we want to test  $H_0:\\mu_x=\\mu_y$ ($\\mu_x-\\mu_y$) vs $H_1:\\mu_x\\neq \\mu_y$ with $\\sigma_x,\\sigma_y$ unknown but equal. Then\n\t\\begin{align*}\n\t\t\\frac{(n-1)S^2_x}{\\sigma^2}+\\frac{(m-1)S^2_y}{\\sigma^2}&\\sim\\chi^2_{(n+m-2)}\\\\\n\t\t\\frac{1}{\\sigma^2}((n-1)S^2_x+(m-1)S^2_y)&\\sim\\chi^2_{(n+m-2)}\n\t\t\\intertext{and using the def'n of a $t$-distribution}\n\t\t\\frac{\\frac{\\bar X-\\bar Y}{\\sigma\\sqrt{1/n+1/m}}}{\\sqrt{\\frac{\\frac{1}{\\sigma^2}[(n-1)S^2_x+(m-1)S^2_y]}{n+m-2}}}&\\sim t_{n+m-2}\\\\\n\t\t\\frac{\\bar X-\\bar Y}{\\sqrt{\\frac{(n-1)S^2_x+(m-1)S^2_y}{n+m-2}}\\sqrt{\\frac{1}{n}+\\frac{1}{m}}}&\\sim t_{n+m-2}\\\\\n\t\t\\frac{\\bar X-\\bar Y}{S_p\\sqrt{\\frac{1}{n}+\\frac{1}{m}}}&\\sim t_{n+m-2}\n\t\\end{align*}\n\twe call $S^2_p=\\sqrt{\\frac{(n-1)S^2_x+(m-1)S^2_y}{n+m-2}}$ the pooled sample variance.\n\n\tIn this case, we use the test statistic $\\frac{\\bar X-\\bar Y}{\\sqrt{\\frac{S^2_x}{n}+\\frac{S^2_y}{m}}}$ which is approximated using a $t$ distribution with a complicated form of the degrees of freedom (not in this course).\n\n\tFor paired (dependent) data $X,Y$, we can define $D=X-Y$ and test $\\mu_d=0$ using \n\t\\[\\frac{\\bar D}{S_d/\\sqrt n}\\sim t_{n-1}\\]\n\\end{multicols*}\n\\end{document}\n", "meta": {"hexsha": "633b4ee61f7dc9b5d5bffe47d594dbf76db08fd0", "size": 32407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet.tex", "max_stars_repo_name": "st-tran/STA261-Notes", "max_stars_repo_head_hexsha": "7f7249cceee6c2fd437413971083a85022200172", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet.tex", "max_issues_repo_name": "st-tran/STA261-Notes", "max_issues_repo_head_hexsha": "7f7249cceee6c2fd437413971083a85022200172", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet.tex", "max_forks_repo_name": "st-tran/STA261-Notes", "max_forks_repo_head_hexsha": "7f7249cceee6c2fd437413971083a85022200172", "max_forks_repo_licenses": ["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.9262135922, "max_line_length": 964, "alphanum_fraction": 0.6572654056, "num_tokens": 12312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.6187874831113255}}
{"text": "As stated in the introduction, metasurfaces are 2D materials with some sub-wavelength structure. Their properties are determined by the geometry of this structure which is usually a simple shape, like a rectangle or oval, on a periodic grid. The shape is called metaatom and in the case of plasmonic metasurfaces it is made of metal.\nWith the $S$-matrix calculus and SASA we can fully describe stacks of homogeneous isotropic materials but we still have no understanding of what happens when we add a metasurface to a stack. To build some intuition for how a specific metasurface will affect the transmission spectrum of a stack, we will need a little more theory on optics in materials. As stated before, all optical properties of a material a captured by the $\\vb D$ and $\\vb H$ fields and in our context\n\\begin{equation} \\label{eq:bg:D}\n    \\vb D = \n    \\epsilon_0 \\, \\vb E + \\vb P =\n    \\epsilon_0\\, \\underbrace{\\qty(1 + \\chi)}_{\n         := \\epsilon\n    }\\, \\vb E\n\\end{equation}\nso the $\\vb D$ field is determined by the $\\vb E$ field and dielectric function $\\epsilon$. In the following sections we will discuss which materials have which kind of dielectric functions and how we can use these to gain some understanding of the optical mechanisms in a metasurface.\n\n\\paragraph{Dielectric Function}~\\\\\nIn the simplest model we can describe electrons in a material as an ensemble of harmonic oscillators\n\n\\begin{equation} \\label{eq:bg:lorentz}\n    m \\ddot{\\vb x} + m \\gamma \\dot{\\vb x} + m \\omega_0^2 \\vb x = -e \\vb E,\n\\end{equation}\n\nwith the displacement $\\vb x$, electron mass $m$, electron charge $e$, dampening factor $\\gamma$ and resonance frequency $\\omega_0$.\nIn this model the macroscopic polarization $\\vb P$ is directly caused by this displacement $\\vb x$ through\n\\begin{equation} \\label{eq:bg:P}\n    \\vb P = - \\rho e \\vb x,\n\\end{equation}\n\nwhere $\\rho$ is the density of electrons.\nIf we assume a harmonic time dependency $\\vb E(t) = \\vb E_0 e^{i \\omega t}$ equation \\eqref{eq:bg:lorentz} is solved by \n\\begin{equation}\n    \\vb x(t) = \\frac{e}{m(\\omega^2 + i \\gamma \\omega - \\omega_0^2)} \\vb E(t)\n\\end{equation}\n\nand using equation \\eqref{eq:bg:D} and \\eqref{eq:bg:P} this results in the $\\vb D$ field\n\\begin{equation}\n    \\vb D = \n    \\epsilon_0 \\underbrace{ \n    \\qty(1 - \\frac{f}{\\omega^2 + i \\gamma \\omega - \\omega_0^2})\n    }_{\n        =\\epsilon\n    }\n    \\vb E,\n\\end{equation}\n\nwhere $f = \\rho e^2 / \\epsilon_0 m$ is the oscillator strength.\nIn a real material there are always multiple resonance frequencies $\\omega_m$ but in good approximation these do not influence each other and the total dielectric function can be obtained simply by summing over all $m$ \\cite{FOMO}\n\\begin{equation}\n    \\epsilon(\\omega) := \n    \\epsilon'(\\omega) + i \\epsilon''(\\omega) = \n    1 + \\sum_m \\frac{f_m}{\\omega_m^2 - \\omega_0^2 - i \\gamma \\omega}\n\\end{equation}\n\n\\begin{figure}[H]\n    \\floatbox[{\n    \\capbeside\n    \\thisfloatsetup{capbesideposition={right,top}}}]{figure}[\\FBwidth]\n    {\\caption{\n        Example plots for the real and imaginary part of the refractive index \n        $n = \\eta + i\\kappa$\n        as calculated by the multiple resonance Lorentz model.\n        \\cite{FOMO}\n    }\n    \\label{fig:bg:lorentz}}\n    {\\includegraphics[width=0.5\\textwidth]{bg_lorentz}}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.8\\linewidth]{bg_dielectric}\n        \\caption{}\n        \\label{fig:bg:dielectric}\n    \\end{subfigure}%\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        \\includegraphics[width=.8\\linewidth]{bg_metal}\n        \\caption{}\n        \\label{fig:bg:metal}\n    \\end{subfigure}\n    \\caption{Imaginary and real part of the dielectric function \n    $\\epsilon = \\epsilon' + i \\epsilon''$\n    for dielectrics (a) and metals (b) in the visible spectrum.\n    \\cite{FOMO}}\n    \\label{fig:bg:dm}\n    \\end{figure}\n\nIn section \\ref{sec:s_mats} we have already discussed how the dielectric function is related to the complex refractive index by\n\\begin{equation}\n    \\epsilon = n^2 = (\\eta + i \\kappa)^2\n\\end{equation}\n\nand this relationship is used to generate figure \\ref{fig:bg:lorentz}. We observe high $\\kappa$, so high absorption, at the resonance frequencies in the from of Lorentz peaks. Between resonance frequencies generally \n$\\partial \\eta / \\partial \\omega > 0$.\nThis is called normal dispersion and explains, for example, why red light is diffracted stronger than blue light.\nFigure \\ref{fig:bg:lorentz} is just a general example. To understand metasurfaces we need to discuss how the resonance frequencies are distributed in real materials.\n\\\\\n\n\\indent\nDielectrics in the visible spectrum are well described by two resonance frequencies. One in the IR and one in the UV range. That means in the visible spectrum we have a vanishing imaginary part $\\epsilon''$ of the dielectric function and normal dispersion as seen in figure \\ref{fig:bg:dielectric}. \nMetals on the other hand are characterized by their high availability in free charges, thereby eliminating the restoring force ($\\omega_0 = 0$) and reducing the dielectric function to \n\\begin{equation}\n    \\epsilon(\\omega) = 1 - \\frac{\\omega_\\s p^2}{\\omega^2 + i \\gamma \\omega}\\, ,\n\\end{equation}\n\nwith the plasma frequency \n$\\omega_\\s p^2 = f = \\rho e^2 / \\epsilon_0 m$.\nThis results in a large negative $\\epsilon'$ and a positive $\\epsilon''$ as seen in figure \\ref{fig:bg:metal}. The negative $\\epsilon'$ is responsible for the reflection of visible light at metallic surfaces.\n\n\\paragraph{Surface Plasmon Polaritons}~\\\\\nFinally, we can discuss the mechanism behind the optical properties of plasmonic metasurfaces. These work by allowing the excitation of a special electromagnetic wave at a metal dielectric interface called Surface Plasmon Polariton (SPP). This wave is confined to and travels along the interface until its energy is lost via absorption or scattering. That means it enables some photons to be absorbed by coupling into the interface. At which wavelengths this conversion occurs depends on the metasurface geometry and can thus be tailored for a specific optical target.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.6\\linewidth]{bg_md_interface}\n    \\caption{Metal dielectric interface with light in a TM mode.}\n    \\label{fig:bg:md_inderface}\n\\end{figure}\n\nSuppose the described wave exists as a TM mode, as can be seen in figure \\ref{fig:bg:md_inderface}, and has the form \n\n\\begin{equation}\n\\begin{aligned}\n    E_x &= E_0 e^{i k_x x - k_z z} \\\\\n    E_z &= E_0 \\frac{k_x}{k_z} e^{i k_x x - k_z z}\\\\\n    H_y &= H_0 e^{i k_x x - k_z z}\n\\end{aligned}\n\\end{equation}\n\nThat is, propagating along the $x$ axis and evanescently decaying along the $z$ axis. This wave does indeed satisfy Maxwell's equation and the continuity conditions discussed in section \\ref{sec:s_mats} if and only if \\cite{Maier2007}\n\n\\begin{equation} \\label{eq:bg:con1}\n    \\frac{\\epsilon_1}{k_{z1}} = - \\frac{\\epsilon_2}{k_{z2}} \n\\end{equation}\n\nand\n\n\\begin{equation} \\label{eq:bg:con2}\n    k_x^2 + k_{zn}^2 = \\epsilon_n \\frac{\\omega^2}{c^2}\n    \\qq{for}\n    n = 1,2.\n\\end{equation}\n\nEquation \\eqref{eq:bg:con1} explains why SPP's are only possible at metal dielectric interfaces because $\\epsilon'_1$ and $\\epsilon'_2$ need to have different signs and this is fulfilled precisely for metals and dielectrics as can be seen in figure \\ref{fig:bg:dm}. If we solve equation \\eqref{eq:bg:con1} and \\eqref{eq:bg:con2}, we can obtain the dispersion relation for SPP's\n\n\\begin{equation}\n    k_x = \\frac{\\omega}{c}\n    \\qty(\\frac{\\epsilon_1 \\epsilon_2}{\\epsilon_1 + \\epsilon_2})^{1/2}.\n\\end{equation}\n\nThis dispersion relation is shown in figure \\ref{fig:bg:dispersion}. For small wave vectors SPP's behave like light but then they start to have increasingly lower energy $E = \\hbar \\omega$ compared to a free photon at the same momentum $\\vb p = \\hbar \\vb k$. However, for a conversion Photon $\\rightarrow$ SPP both energy and momentum have to be conserved.\nThus excitation of SPP's is not possible at a simple smooth metallic surface, but rather the wave vector of an incident photon has to be matched to that of an SPP of the same energy by the surface geometry.\n\\\\\n\n\\indent\nTo summarize, photons can couple into a plasmonic metasurface by exiting a special electromagnetic wave called Surface Plasmon Polariton confined to the interface. The exact wavelength at which this conversion is possible depends on the metaatom geometry and can thus be easily tuned to create different optical behaviors.\n\n\\begin{figure}[H]\n    \\floatbox[{\n    \\capbeside\n    \\thisfloatsetup{capbesideposition={right,top}}}]{figure}[\\FBwidth]\n    {\\caption{\n        Dispersion relation for light and Surface Plasmon Polaritons in air (grey) and silica (black). Frequency and wave vector are normalized to the plasma frequency $\\omega_\\s p$ \\cite{Maier2007}.\n    }\n    \\label{fig:bg:dispersion}}\n    {\\includegraphics[width=0.55\\textwidth]{bg_dispersion}}\n\\end{figure}", "meta": {"hexsha": "1846bd72f11ab3324c81cddf3a7dbe9121f17082", "size": 9023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/background/plasmonic.tex", "max_stars_repo_name": "TimLucaTuran/bachlor-arbeit", "max_stars_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "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/background/plasmonic.tex", "max_issues_repo_name": "TimLucaTuran/bachlor-arbeit", "max_issues_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-17T15:04:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-17T15:04:05.000Z", "max_forks_repo_path": "tex/background/plasmonic.tex", "max_forks_repo_name": "TimLucaTuran/bachlor-arbeit", "max_forks_repo_head_hexsha": "f6c1eb502d7e99a4fdf2f3b0110677578f8eff95", "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": 55.0182926829, "max_line_length": 568, "alphanum_fraction": 0.7243710518, "num_tokens": 2498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.618786426141838}}
{"text": "\\subsection{Bit-Blasting}\n\n\\begin{frame}\n  \\frametitle{Bit-Blasting}\n\nOur goal is to devise an automatic decision procedure (\\smtsolver)\nto check the satisfiability of a given \\bitvector formula\n\\vfill\n\\pause\nState-of-the-art techniques are based on reduction to SAT. It is\ncalled {\\bf bit-blasting}\n\\vfill\n\\pause\n\\begin{itemize}\n  \\item the formula is seen as a circuit, in which\n        variables and constants are inputs, while\n        other terms are intermediate nodes. The outermost\n        Boolean connective or predicate represents the output\n\\vfill\n\\pause\n\n  \\item each variable is assigned to a vector of Boolean variables\n        ($n$ variables for a variable of sort \\SBv{n})\n\\vfill\n\\pause\n\n  \\item each intermediate node is assigned to a vector of\n\tBoolean \\formulae\n        ($n$ \\formulae for a term of sort \\SBv{n})\n\\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bit-Blasting}\n  \n  $$\n  (\\w{a}{2} \\band \\w{b}{4}[1:0]) = (\\w{c}{2} + \\w{d}{2})  \n  $$\n  \\vfill\n  \\begin{overlayarea}{\\textwidth}{5cm}\n  \\begin{center}\n    \\only<1|handout:0>{\\scalebox{.35}{\\input{bb_example_0.pdf_t}}}\n    \\only<2|handout:0>{\\scalebox{.35}{\\input{bb_example_1.pdf_t}}}\n    \\only<3|handout:0>{\\scalebox{.35}{\\input{bb_example_2.pdf_t}}}\n    \\only<4|handout:0>{\\scalebox{.35}{\\input{bb_example_3.pdf_t}}}\n    \\only<5|handout:0>{\\scalebox{.35}{\\input{bb_example_4.pdf_t}}}\n    \\only<6|handout:0>{\\scalebox{.35}{\\input{bb_example_5.pdf_t}}}\n    \\only<7|handout:0>{\\scalebox{.35}{\\input{bb_example_6.pdf_t}}}\n    \\only<8|handout:0>{\\scalebox{.35}{\\input{bb_example_7.pdf_t}}}\n    \\only<9->{\\scalebox{.35}{\\input{bb_example_8.pdf_t}}}\n  \\end{center}\n  \\end{overlayarea}\n  \\vfill\n  \\onslide<10->{\n    $((b^1 \\wedge a^1) \\leftrightarrow (c^1 \\oplus d^1 \\oplus (c^0 \\wedge d^0))) \\wedge ((b^0 \\wedge a^0) \\leftrightarrow (c^0 \\oplus d^0))$\n  }\n  \n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{Bit-Blasing Algorithm (1)}\n\n  \\tiny\n\n  \\begin{tabbing}\n    \\= asdf \\= asdfasdfasdfasdfasdf \\= asdfasdfasdf \\= asdf \\kill\n    \\> BB := $\\{ \\}$, C := $\\{ \\}$ \\\\\n    \\> \\\\\n    \\> {\\bf Procedure} Bit-Blast-Term( $t$ : \\SBv{n} term ) \\\\\n    \\> \\\\\n    \\> {\\bf if} ( $t \\in $ C ) {\\bf return}; \\> \\> // If already in cache, skip \\\\\n    \\> {\\bf else} C := C $\\cup\\ t$     \\> \\> // Put in cache \\\\\n    \\> \\\\ \\pause\n    \\> {\\bf if} ( $t$ is a \\SBv{n} variable ) \\\\\n    \\> \\> // Let $x$ be the name of the variable \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ x \\mapsto [\\bit{x}{{n-1}}, \\ldots, \\bit{x}{0}] \\}$ \\\\\n    \\> \\> // where $\\bit{x}{i}$ are fresh Boolean variables \\\\\n    \\> \\\\ \\pause\n    \\> {\\bf else if} ( $t$ is a \\SBv{n} constant ) \\\\\n    \\> \\> // Let $c$ be the constant \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ c \\mapsto [\\bit{c}{{n-1}}, \\ldots, \\bit{c}{0}] \\} $ \\\\\n    \\> \\> // where $\\bit{c}{i}$ is $\\bot$ if the i-th bit of $c$ is $0$, $\\top$ otherwise \\\\\n    \\> \\\\ \\pause\n    \\> {\\bf else if} ( $t$ is ($t_1 \\band t_2$), and $t_1, t_2$ are \\SBv{n} terms ) \\\\\n    \\> \\> Bit-Blast-Term( $t_1$ ) \\\\\n    \\> \\> Bit-Blast-Term( $t_2$ ) \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ t \\mapsto [\\mbox{BB}(t_1, n-1) \\wedge \\mbox{BB}(t_2, n-1), \\ldots, \\mbox{BB}(t_1, 0) \\wedge \\mbox{BB}(t_2, 0)] \\} $ \\\\\n    \\ldots\n  \\end{tabbing}\n\n  where $\\mbox{BB}(t, i)$ means: \n  \\begin{enumerate}\n    \\item retrieve the correspondence $t \\mapsto [\\bit{t}{n-1}, \\ldots, \\bit{t}{0}]$, and\n    \\item return $\\bit{t}{i}$ \n  \\end{enumerate}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{Bit-Blasing Algorithm (2)}\n\n  \\scriptsize\n\n  \\begin{tabbing}\n    \\= asdf \\= asdf \\= asdf \\= asdf \\kill\n    \\> {\\bf Procedure} Bit-Blast( $\\varphi$ : \\SBv{n} formula ) \\\\\n    \\> \\\\\n    \\> {\\bf if} ( $\\varphi$ is $(t_1 = t_2)$, and $t_1, t_2$ are \\SBv{n} terms ) \\\\\n    \\> \\> Bit-Blast-Term( $t_1$ ) \\\\\n    \\> \\> Bit-Blast-Term( $t_2$ ) \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ \\varphi \\mapsto ((\\mbox{BB}(t_1, n-1) \\leftrightarrow \\mbox{BB}(t_2, n-1)) \\wedge \n\t                                      \\ldots \\wedge\n\t\t\t\t              (\\mbox{BB}(t_1, 0) \\leftrightarrow \\mbox{BB}(t_2, 0))) \\} $ \\\\\n    \\> \\\\ \\pause\n    \\> {\\bf else if} ( $\\varphi$ is $(t_1 <_u t_2)$, and $t_1, t_2$ are \\SBv{n} terms ) \\\\\n    \\> \\> Bit-Blast-Term( $t_1$ ) \\\\\n    \\> \\> Bit-Blast-Term( $t_2$ ) \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ \\ldots \\}$ \\\\\n    \\> \\\\ \\pause\n    \\> {\\bf else if} ( $\\varphi$ is $\\varphi_1 \\wedge \\varphi_2$ are \\SBv{n} formula ) \\\\\n    \\> \\> Bit-Blast( $\\varphi_1$ ) \\\\\n    \\> \\> Bit-Blast( $\\varphi_2$ ) \\\\\n    \\> \\> BB := BB $\\cup\\ \\{ \\varphi \\mapsto (\\mbox{BB}(\\varphi_1) \\wedge \\mbox{BB}(\\varphi_2)) \\}$ \\\\\n    \\ldots\n  \\end{tabbing}\n\n  where $BB(\\varphi)$ means: \n  \\begin{enumerate}\n    \\item retrieve the correspondence $\\varphi \\mapsto \\psi$, and\n    \\item return $\\psi$ \n  \\end{enumerate}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{SMT via Bit-Blasing}\n\n  \\begin{center}\n  \\scalebox{.5}{\\input{bitblasting.pdf_t}}\n  \\end{center}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Bit-Blasing pros and cons}\n\n  \\scriptsize\n\n  Pros\n  \\begin{itemize}\n    \\item Very easy to write, if compared to write a native \\bitvector solver \\pause\n    \\vfill\n    \\item Boolean model from SAT can be mapped back to a model for each \\bitvector variable.\n\t  If $\\w{x}{n}$ was bit-blasted as $x^{n-1}, \\ldots, x^0$\n\t  \\begin{itemize}\n\t    \\item retrieve SAT assignment for each $x^i$ (e.g., $x^0 = \\top$, $x^1 = \\bot$)\n\t    \\item construct actual value for $\\w{x}{n}$ by mapping $\\top$ to $1$ and $\\bot$ to $0$ (e.g., $\\w{x}{2} = 01$)\n\t  \\end{itemize}\n  \\end{itemize}\n  \\vfill\n  \\pause\n  Cons\n  \\begin{itemize}\n    \\item Does not scale very well. Consider the formula $\\neg(\\w{x}{n} = \\w{0}{32}) \\wedge (\\w{x}{n} \\band \\w{y}{n}) = (\\w{x}{n} + \\w{y}{n})$.\n          It is unsat for {\\bf every} $n$. \\pause But to prove it for $n=32$ requires $64$ Boolean variables, to prove it with $n=1024$\n\t  requires $2048$ Boolean variables\n    \\vfill\n    \\pause\n    \\item It destroys the structure of the formula. In the encoding $\\w{x}{32}$ is not seen as a ``single object'' but each\n          $x^i$ is unrelated and independent\n  \\end{itemize}\n\n\\end{frame}\n", "meta": {"hexsha": "6a80baf8513d0e6da21526c47f70bee8e1409bcf", "size": 6042, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture2/bitblasting.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": "lecture2/bitblasting.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": "lecture2/bitblasting.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": 34.5257142857, "max_line_length": 147, "alphanum_fraction": 0.5701754386, "num_tokens": 2327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6187691428717245}}
{"text": "\\chapter{Statistical Mechanics Problems}\n\\begin{enumerate}\n\t\\item A system of $\\mathrm{N}$ particles has only two allowed state $\\mathrm{A}$ and $\\mathrm{B}$. The probability for $\\mathrm{A}$ is $\\mathrm{P}$ and for $\\mathrm{B}$ is 1-P? What is the probability for the system to be in macrostate defined by the distribution of $(r, N-r) ?$\n\t\\begin{answer}\n\t\t \\begin{align*}\n\t\t \t\\text{The probability of finding }&\\mathrm{r}\\text{ particle in state } \\mathrm{A}=\\mathrm{P}^{r}\\\\\n\t\t \t\\text{ The probability of finding }&N-r\\text{ particle in state } B=(1-P)^{N-r}\\\\\n\t\t \\text{\tThe Total no. of-ways in which}&\\text{ r particle can be choosen from }N \\text{- particle is }{ }^{N} C_{r}=N ! / r !(N-r) !\\\\\n\t\t \\text{ The probability in which r particle }&\\text{are in state $A$ and $N-r$ particle in state $B$ is }=\\frac{N !}{r !(N-r) !} P^{r}(1-P)^{N-r}\n\t\t \\end{align*}\n\t\\end{answer}\n\t\\item A one dimensiional random walker takes step to left or right with equal probability. The probability that the random walker starting from orign is back to orign after $N$ even number of step,is \n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{N !}{\\left(\\frac{N}{2}\\right) !\\left(\\frac{N}{2}\\right) !}\\left(\\frac{1}{2}\\right)^{N}$\n\t\t\\task[\\textbf{b.}]$\\frac{N!}{(\\frac{N}{2})!(\\frac{N}{2})!}$\n\t\t\\task[\\textbf{c.}]$2N!(\\frac{1}{2})^{2N}$\n\t\t\\task[\\textbf{d.}] $N!(\\frac{1}{2})^{N}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Probability} \\quad P&=\\frac{N!}{r~(N-r)}P(1-P)^{N-r}\\\\\n\t\t&=\\frac{N !}{\\left(\\frac{N}{2}\\right) !\\left(\\frac{N}{2}\\right) !}\\left(\\frac{1}{2}\\right)^{\\frac{N}{2}}\\left(1-\\frac{1}{2}\\right)^{N-\\frac{N}{2}}=\\frac{N!}{(\\frac{N}{2})!(\\frac{N}{2})!}\\left( \\frac{1}{2}\\right) ^N\n\t\t\\end{align*}\n\t\tOption \\textbf{(a)} is correct\n\t\\end{answer}\n\t\\item Calculate the no. of microstates for a configuration of a system of $N$ distinguishable particles in which there are $n_1$ particles in a particle state $1 \\& n_2$ particle in state $2,n_3$ particle .....$n_1$ particle in the $i$ th state.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Total No. of particle }&=N\\\\\n\t\t\\text{No: of microstate for state}-1&={{N_C}_{n1}}\\\\\n\t\\text{\tNo. of microstate for state }-2&=\\mathrm{N}-\\mathrm{n}_{1}{ }_{\\mathrm{C}_{\\mathrm{n}} 2}\\\\\n\\text{\tNo. of microstate for state }i^{\\text {th }}&=N-n_{1}-n_{2} \\ldots . n_{i}-1_{c_{n_{i}}}\n\\intertext{So\\quad total number of microstate is}\n\\mathrm{N}_{\\mathrm{C}_{\\mathrm{n}_{1}}} \\times \\mathrm{N}-\\mathrm{n}_{1} \\mathrm{C}_{\\mathrm{n}_{2}} &\\times \\mathrm{N}-\\mathrm{n}_{1}-\\mathrm{n}_{2} \\mathrm{C}_{\\mathrm{n}_{3}} \\times \\ldots \\ldots \\ldots \\mathrm{N}-\\mathrm{n}_{1}-\\mathrm{n}_{2}-\\mathrm{n}_{3}-\\mathrm{ni}-1_{\\mathrm{n}_{\\mathrm{i}}}\\\\\n=\\frac{N !}{n_{1} !\\left(N-n_{1}\\right) !} &\\times \\frac{(N-n) !}{n_{2} !\\left(N-n_{1}-n_{2}\\right) !} \\times \\ldots \\ldots \\cdot \\frac{\\left(N-n_{1}-n_{2} \\ldots n_{i}\\right) !}{n_{i} !\\left(N-n_{1}-n_{2} \\ldots n_{i}\\right) !}\\\\\n=\\frac{N !}{n_{i} !\\left(N-n_{1}-n_{2} \\ldots . n_{i}\\right) !}&\n-\\text{ For distinguishable particle}\\\\\n=\\frac{1}{n_{i} !\\left(N-n_{1}-n_{2} \\ldots n_{i} !\\right) !}& \\rightarrow\n\\text{For indistinguishable particle}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Four distinguishable coins are tossed a large no. of time write down the different microstate which may be observed \\& the macrostate into which they would fall. Give the probability of the most probable macrostate.\\\\\n\t\\begin{center}\n\t\\begin{tabular}{|p{2.5cm}|p{2.7cm}|p{2.5cm}|p{2.7cm}|p{2.5cm}|}\n\t\t\\hline Macrostate & Microstate coins having head up & Microstate coins having tail up & No.of microstate & Probability \\\\\n\t\t\\hline $\\mathrm{n}_{1}=4, \\mathrm{n}_{2}=0$ & $\\mathrm{a} \\mathrm{b} \\mathrm{c} \\mathrm{d}$ & $-$ & 1 & $\\frac{1}{16}$ \\\\\n\t\t\\hline & $\\mathrm{abc}$ & $\\mathrm{d}$ & & \\\\\n\t\t$\\mathrm{n}_{1}=3, \\mathrm{n}_{2}=1$ & $\\mathrm{bcd}$ & $\\mathrm{a}$ & 4 & $\\frac{4}{16}$ \\\\\n\t\t& $\\mathrm{cda}$ & $\\mathrm{b}$ & & \\\\\n\t\t& $\\mathrm{dab}$ & $\\mathrm{c}$ & & \\\\\n\t\t\\hline\n\t\t &$\\mathrm{ab}$&$\\mathrm{cd}$ & &\\\\\n\t\t &$\\mathrm{ac}$&$\\mathrm{bd}$ & &\\\\\n\t\t $n_1=2,n_2=3$&$\\mathrm{ad}$&$\\mathrm{bc}$ &6&$\\frac{6}{16}$\\\\\n\t\t &$\\mathrm{bc}$&$\\mathrm{ad}$ & &\\\\\n\t\t &$\\mathrm{bd}$&$\\mathrm{ac}$ & &\\\\\n\t\t &$\\mathrm{cd}$&$\\mathrm{ab}$ & &\\\\\n\t\t \\hline\n\t\t  &$\\mathrm{a}$&$\\mathrm{bcd}$ & &\\\\\n\t\t$n_1=1,n_2=3$&$\\mathrm{b}$&$\\mathrm{acd}$ &4 &$\\frac{4}{16}$\\\\\n\t\t  &$\\mathrm{c}$&$\\mathrm{abd}$ & &\\\\\n\t\t &$\\mathrm{d}$&$\\mathrm{abc}$ & &\\\\\n\t\t  \\hline\n\t\t  \t$n_1=0,n_2=1$&$-$&$\\mathrm{abcd}$ &1 &$\\frac{1}{16}$\\\\\n\t\t  \t \\hline\n\t\\end{tabular}\n\\end{center}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Total no. of microstate }&=6\\\\\n\t\\text{The probability of most probable state }&=6/16\n\t\\end{align*}\n\\end{answer}\n\t\\item An isolated system consist of two non-interacting spin $-1/2$ particles a \\& b fixed in space \\& kept in magnetic field B. Find out the total number of microstates allowed in the system.\n\n\t\\begin{answer}\n\t\t$\\left. \\right. $\\\\\n\t\t\\begin{table}[H]\n\t\\begin{tabular}{|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|}\n\t\t\\hline\n\t\tSystemstate or macrostate  &Particlestate or Microstate & Magnetic moment &Energy  &No.of microstate  \\\\ \\hline\n\t\t1& U \\quad U&$2\\mu_0$ & $-2\\mu_0 B$& 1   \\\\ \\hline\n\t \\multirow{ 2}{*}{1} & U \\quad D & 0 & 0 & \\multirow{ 2}{*}{2}\\\\ \n\t\t & U \\quad D & 0 & 0 &  \\\\ \\hline\n\t\t 3&D\\quad D&$-2\\mu_0$& $+-2\\mu_0B$&1\\\\\n\t\t \\hline\n\t\\end{tabular}\n\\end{table}\n\\begin{align*}\n\\intertext{Total no. of microstate $=4$ for $\\operatorname{Spin}-\\frac{1}{2}$ two particle system no. of accessible microstate corresponding to energy.}\nE=0\\text{ is }2&\n\\intertext{The no. of microstate for $\\mathrm{N}$ no. of Spin S particle}\n(2 S+1)^{N}&\n\\intertext{The probability of getting a macrostate in which there are r particle out of N Spin $1 / 2$ particle in spin up state}\n\\mathrm{N}_{\\mathrm{C}_{\\mathrm{r}}} \\times \\frac{1}{2^{\\mathrm{N}}}\n\\end{align*}\n\t\\end{answer}\n\\item We have equal amount of two identical ideal gases at the same temperature $T$ but at different pressure $P_1$ and $P_2$ in two containers of volume $V_1$ and $V_2$ respectively. The containers are connected. Find the change in entropy (The temperature after mixing also ramains same)\n\\begin{answer}\n\t\\begin{align*}\n\tS&=Nk_B \\ \\ell n\\left( \\frac{V}{N}\\right)+\\frac{3}{2}Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right] \\\\\n\t\\sum\\limits_{i=1}^{2}Si&=N_1k_B\\ \\ell n\\frac{V_i}{N}+\\frac{3}{2}N_1k_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right] \\\\\n\t&=Nk_B\\ \\ell n\\frac{V_1}{N}+\\frac{3}{2}Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right]+\\\\\n\t\t&=Nk_B\\ \\ell n\\frac{V_2}{N}+\\frac{3}{2}Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right]+\\\\\n\t\t&\\left\\{\\begin{array}{l}P_{1} V_{1}=N k_{B} T \\Rightarrow \\frac{V_1}{N}=\\frac{k_B T}{P_1}\\\\ P_{2} V_{2}=N k_{B} T \\Rightarrow \\frac{V_2}{N}=\\frac{k_B T}{P_2} \\end{array}\\right.\\\\\n\t\t\\sum\\limits_{i=1}^{2}Si&=Nk_B\\ \\ell n\\frac{k_B T}{P_1}+\\frac{3}{2}Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right] +\\\\\n\t\t&=Nk_B\\ \\ell n\\frac{k_B T}{P_2}+\\frac{3}{2}Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right]\n\t\t\\intertext{\\textbf{Total entropy:}}\n\t\tS_T&=2Nk_B\\ \\ell n\\frac{V_1+V_2}{2N}+\\frac{3}{2}\\times 2Nk_B \\left[\\frac{5}{3}+\\ell n \\left(\\frac{2\\pi mk_BT}{h^2} \\right) \\right]\n\t\t\\intertext{Change in entropy}\n\t\t\\Delta S&=S_T-\\sum\\limits_{i=1}^{2}Si=2Nk_B\\ \\ell n\\frac{V_1+V_2}{2N}-Nk_B \\ \\ell n\\frac{k_B T}{P_1}-NK \\ \\ell n\\frac{k_B T}{P_2}\n\t\t\\intertext{Let after mixing pressure $=P$ and after mixing total No of particle $=N+N=2 N$}\n\t\t\\end{align*}\n\t\t\\begin{align*}\n\t\t&\\mathrm{P}\\left(\\mathrm{V}_{1}+\\mathrm{V}_{2}\\right)=2 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}\\hspace{6cm}\\mathrm{P}\\left(\\mathrm{V}_{1}+\\mathrm{V}_{2}\\right)=2 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}\\\\\n\t\t&\\frac{\\left(\\mathrm{V}_{1}+\\mathrm{V}_{2}\\right)}{2 \\mathrm{~N}}=\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}}\\hspace{6.5cm}\\frac{1}{\\mathrm{P}}=\\frac{\\mathrm{V}_{1}+\\mathrm{V}_{2}}{2 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}}=\\frac{\\mathrm{V}_{1}}{2 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}}+\\frac{\\mathrm{V}_{2}}{2 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}}\\\\\n\t\t&\\Delta \\mathrm{S}=2 \\mathrm{Nk}_{\\mathrm{B}} \\ \\ell n \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}}-\\mathrm{Nk}_{\\mathrm{B}} \\ell \\mathrm{n} \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}_{1}}-\\mathrm{Nk}_{\\mathrm{B}}  \\ \\ell n \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}_{2}}\\hspace{2cm}\\frac{1}{\\mathrm{P}}=\\frac{1}{2}\\left(\\frac{1}{\\mathrm{P}_{1}}+\\frac{1}{\\mathrm{P}_{2}}\\right)\\\\\n\t\t&=N k_{\\mathrm{B}}  \\ \\ell n \\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}}\\right)^{2}-\\mathrm{Nk}_{\\mathrm{B}}  \\ \\ell n \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}_{1}}-\\mathrm{Nk}_{\\mathrm{B}}  \\ \\ell n \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{P}_{2}}\\hspace{2cm}P=\\frac{2 P_{1} P_{2}}{P_{1}+P_{2}}\\\\\n\t\t&=N k_{B}  \\ \\ell n \\frac{\\left(\\frac{k_{B} T}{P}\\right)^{2}}{\\left(\\frac{k_{B} T}{P_{1}}\\right)\\left(\\frac{k_{B} T}{P_{2}}\\right)}\\\\\n\t\t&=N k_{B}  \\ \\ell n \\left[\\frac{\\left(k_{B} T\\right)^{2}\\left(P_{1}+P_{2}\\right)^{2}}{\\left(2 P_{1} P_{2}\\right)^{2}} \\times \\frac{P_{1} P_{2}}{\\left(k_{B} T\\right)^{2}}\\right]\\\\\n\t\t\\Delta \\mathrm{S}&=\\mathrm{Nk}_{\\mathrm{B}} \\ell \\mathrm{n} \\frac{\\left(\\mathrm{P}_{1}+\\mathrm{P}_{2}\\right)^{2}}{4 \\mathrm{P}_{1} \\mathrm{P}_{2}}\\\\\n\t\t\\Delta \\mathrm{S}&=\\mathrm{Nk}_{\\mathrm{B}}  \\ \\ell n \\frac{\\left(\\mathrm{P}_{1}+\\mathrm{P}_{2}\\right)^{2}}{4 \\mathrm{P}_{1} \\mathrm{P}_{2}}\\quad\\text{ Here we get }\\Delta S>0\\\\\n\t\t\\intertext{(We are considering identical particle. So it is a reversible case only when the particle density is same otherwise for identical gas also we will get $\\Delta S>0$)}\n\t\\end{align*}\n\\end{answer}\n\t\\item Calculate the number of microstate for a free particle in 3-dimension that have momentum $p$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathrm{d} \\tau&=\\mathrm{dx} d y d z d p_{x} d p_{y} d p_{z}\\\\\n\t\\textbf{\tAllowed Phase Space Volume}=&\\int \\mathrm{d} \\tau=\\int \\mathrm{dxdydz} \\int \\mathrm{dp}_{\\mathrm{x}} \\mathrm{dp}_{\\mathrm{y}} \\mathrm{dp}_{\\mathrm{z}}\\\\\n\t&=V \\int p^{2} d p \\int_{0}^{\\pi} \\sin \\theta d q \\int_{0}^{2 \\pi} d \\phi=V \\frac{4}{3} \\pi p^{3}\\\\\n\\text{\tNo. of microstate }&=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} \\times \\frac{4}{3} \\pi \\mathrm{p}^{3}\n\\intertext{Note : for 2. dimension.}\n\\int \\mathrm{dx}&=\\int \\mathrm{dx} \\int \\mathrm{dy} \\int \\mathrm{dp}_{\\mathrm{x}} \\int \\mathrm{dp}_{\\mathrm{x}}\\\\\n&=\\int \\mathrm{d}^{2} \\mathrm{q} \\cdot \\mathrm{d}^{2} \\mathrm{p} \\quad=\\mathrm{A} \\cdot \\pi \\mathrm{p}^{2} \\quad\\{\\text{ where }\\mathrm{A}= \\text{area} \\}\n\\intertext{Since wave polarize in 2 dimension}\n\\int \\mathrm{dr}&=2 \\mathrm{~A} \\pi \\mathrm{p}^{2}\n\\intertext{If momentum lies between $p$ and $p+d p$}\n\\therefore\\text{ No. of microstate }&=\\frac{2 \\mathrm{~A}}{\\mathrm{~h}^{2}} 2 \\pi \\mathrm{pdp}=\\frac{4 \\mathrm{~A} \\pi}{\\mathrm{h}^{2}} \\mathrm{pdp}\n\\intertext{If momentum lies between $\\mathrm{p}$ and $\\mathrm{p}+\\mathrm{dp}$ then no. of microstate $=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} 4 \\pi \\mathrm{p}^{2} \\mathrm{dp}$}\n\\text{Density of state }&=\\frac{\\text { no. of state }}{\\text { Volume }}\\text{ or} \\frac{\\text { no. of state }}{\\text { energy int erval }}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Calculate the number of microstates accessible to the photon having frequency between $\\nu$ and $\\nu+d\\nu$ confined to a 3 dimentional cavity of volume $V$\n\t \\begin{answer}\n\t \t\\begin{align*}\n\t \t\\intertext{No. of microstate in frequency range 0 to $\\nu$}\n\t \t\\Omega&=\\frac{V}{h^{3}} \\frac{4}{3} \\pi(2 m E)^{3 / 2} \\hspace{3cm}\n\t \tE=\\frac{P^{2}}{2 m} \\Rightarrow P=\\sqrt{2 m} E\\\\\n\t \t&=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} \\frac{4}{3} \\pi\\left(\\mathrm{P}^{2}\\right)^{3 / 2}\\hspace{3cm} \\mathrm{P}=\\frac{\\mathrm{E}}{\\mathrm{C}}=\\frac{\\mathrm{h\\nu}}{\\mathrm{C}}\\\\\n\t \t\\Omega&=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} \\frac{4}{3} \\pi \\mathrm{P}^{3}=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} \\frac{4}{3} \\pi\\left(\\frac{\\mathrm{h\\nu}}{\\mathrm{c}}\\right)^{3}=\\frac{4}{3} \\frac{\\pi \\mathrm{V\\nu}^{3}}{\\mathrm{c}^{3}}\n\t \t\\intertext{No. of microstates in the frequency range $\\nu$ and $v+d \\nu$ is}\n\t \t\\mathrm{d} \\Omega&=\\frac{4}{3}\\  \\frac{\\pi \\mathrm{V}}{\\mathrm{c}^{3}} 3 \\mathrm{\\nu}^{2} \\mathrm{~d} \\mathrm{v}=\\frac{4 \\pi \\mathrm{V}}{\\mathrm{c}^{3}} \\mathrm{\\nu}^{2} \\mathrm{~d} \\mathrm{\\nu}\n\t \t\\intertext{Density of state}\n\t \tg(E)&=\\text{ no. of states per unit energy range}\\\\\n\t \\text{\twe have }\\quad\n\t \t\\Omega&=\\frac{V}{h^{3}} \\ \\frac{4}{3} \\ \\pi(2 m E)^{3 / 2}\\\\\n\t \t\\mathrm{d} \\Omega&=\\frac{\\mathrm{V}}{\\mathrm{h}^{3}} \\ \\frac{4}{3}\\  \\cdot \\frac{3}{2} \\pi(2 \\mathrm{mE})^{1 / 2} 2 \\mathrm{~m} \\mathrm{dE}\\\\\n\t \t&=\\frac{V}{h^{3}} \\cdot 2 \\pi(2 m)^{3 / 2} E^{1 / 2} d E\\\\\n\t \t&\\left[\\mathrm{E}=\\frac{\\mathrm{P}^{2}}{2 \\mathrm{~m}} \\Rightarrow 2 \\mathrm{~m}\\frac{P^2}{E}-\\frac{E^2}{c^2 E}=\\frac{E}{c^2}\\right]\\\\\n\t \t&=\\frac{V}{h^{3}} 2 \\pi \\left(\\frac{E}{c^2} \\right) ^{\\frac{3}{2}}E^{\\frac{1}{2}}dE\\\\\n\t \t&=\\frac{V}{h^3}\\ \\frac{2\\pi}{c^3}E^2dE\\\\\n\t \tg(E)&=\\frac{d\\Omega}{dE}=\\frac{2\\pi VE^2}{h^3 c^3}\n\t \t\\end{align*}\n\t \\end{answer}\n \\section{Canonical Ensemble}\n\t\\item Show that the partition fuction of two independent (non-interacting)\n\tsystem $i$ and $j$ is given by \n\t$$Z_{ij}=Z_i\\times Z_j$$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{We know that}\n\t\tP_{i}&=\\frac{e^{-\\beta E_{i}}}{Z_{i}}, P_{j}=\\frac{e^{-\\beta E_{j}}}{Z_{j}}\\\\\n\t\tE&=E_{i}+E_{j}, P_{i j}=\\frac{e^{-\\beta\\left(E_{i}+E_{j}\\right)}}{Z_{i j}}\\\\\n\t\tP_{i j}&=\\frac{e^{-\\beta E}}{Z_{i i}}=\\frac{e^{-\\beta\\left(E_{i}+E_{j}\\right)}}{Z_{i i}}=\\frac{e^{-\\beta E_{i}} \\times e^{-\\beta E_{j}}}{\\dot{Z}_{i i}}\\\\\n\t\t\\mathbf{P}_{\\mathrm{ij}}&=\\mathrm{P}_{\\mathrm{i}} \\times \\mathrm{P}_{\\mathrm{j}}\\\\\n\t\t\\frac{e^{-\\beta E_{i}} \\times e^{-\\beta E_{j}}}{Z_{i j}}&=\\frac{e^{-\\beta E_{i}}}{Z_{i}} \\times \\frac{e^{-\\beta E_{j}}}{Z_{i}}\\\\\n\t\t\\text{So  }\\quad Z_{\\mathrm{ij}}&=Z_{\\mathrm{i}} \\times Z_{\\mathrm{j}}\\\\\n\t\\text{\tIn general }Z_{i j k} \\cdots \\cdots&=Z_{i} \\times Z_{j} \\times Z_{k} \\times \\cdots \\\\\n\t\\text{Total partition function }Z&=Z_{\\text {Rotational motion }} \\times Z_{\\text {Translational motion }} \\times Z_{\\text {Vibrational motion }} \\times \\ldots \\ldots \\ldots \\ldots \\ldots\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A system consist of three independent particles localised in space. Each particle have two states of energy $O$ and $E$. When the system is in thermal equilibrium with a heat bath at temperature $T$. Calculate its partition function? \n \t\\begin{answer}\n \t\tMethod :-1\n \t\t\\begin{align*}\n \t\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\sum_{\\mathrm{r}} \\mathrm{g}_{\\mathrm{r}} \\mathrm{e}^{-\\beta \\mathrm{E}_{\\mathrm{r}}}\\\\\n \t\tQ_1 (V,T)=\\sum e^{\\beta E_r}=1+e^{\\beta E}\\colorbox{red}{Not completed}\n \t\t\\end{align*}\n \t\\end{answer}\n\t\\item The partition function for two Bose particle each of which can occupy any of the enetgy level $0$ and $E$ \n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$1+e^{-2 E / K T}+2 e^{-E / K T}$\n\t\t\\task[\\textbf{b.}] $1+e^{-2 E / K T}+e^{-E / K T}$\n\t\t\\task[\\textbf{c.}]$2 \\mathrm{e}^{-2 \\mathrm{E} / \\mathrm{KT}}+\\mathrm{e}^{-\\mathrm{E} / \\mathrm{KT}}$\n\t\t\\task[\\textbf{d.}] $e^{-2 E / K T}+e^{-E / K T}$\n\t\\end{tasks}\n\t\\begin{answer}$\\left. \\right. $\\\\\n\t\t\\renewcommand*{\\arraystretch}{2}\n\t\t\\begin{tabular}{llllll} \n\t\t\t& $\\mathbf{0}$ & $\\mathbf{E}$ & Total energy & \\multicolumn{2}{c}{ degeneracy } \\\\\n\t\t\t1 & aa & 0 & 0 & 1 & $\\left(g_{1}\\right)$ \\\\\n\t\t\t2 & a & a & E & 1 & $\\left(g_{2}\\right)$ \\\\\n\t\t\t3 & 0 & a & 2 E & 1 & $\\left(g_{3}\\right)$\n\t\t\\end{tabular}\n\t\\begin{align*}\n\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\sum_{\\mathrm{r}} \\mathrm{g}_{\\mathrm{r}} \\mathrm{e}^{-\\beta \\mathrm{E}_{\\mathrm{r}}}=\\mathrm{g}_{1} \\mathrm{e}^{-\\beta \\mathrm{E}_{1}}+\\mathrm{g}_{2} \\mathrm{e}^{-\\beta \\mathrm{E}_{2}}+\\mathrm{g}_{3} \\mathrm{e}^{-\\beta \\mathrm{E}_{3}}\\\\\n\t&=1+\\mathrm{e}^{-\\beta E}+\\mathrm{e}^{-2 \\beta E}\n\t\\end{align*}\n\tCorrect answer is option \\textbf{(b)}\n\t\\end{answer}\n\t\\item The partition function of single gas molecule is $Z\\alpha$. The partition fuction of $N$ such non-interacting gas molecule is given by\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{(Z \\alpha)^{N}}{N !}$\n\t\t\\task[\\textbf{b.}]$(Z \\alpha)^{N}$\n\t\t\\task[\\textbf{c.}] $\\mathrm{NZ} \\alpha$\n\t\t\\task[\\textbf{d.}] $(Z \\alpha)^{N} / N$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{For indistinguishable particle }&\\frac{(Z \\alpha)^{N}}{N !}\\\\\n\t\t\\text{for distinguishable particle }&(Z \\alpha)^{N}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A system has energy level $E_0,2E_0,3E_0....$ where the excited state are triply degenerate. Four non-interacting Bosons are placed in this system. If the total energy of these Bosons is $5E_0$. The number of microstate is \n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]2\n\t\t\\task[\\textbf{b.}]3\n\t\t\\task[\\textbf{c.}]4\n\t\t\\task[\\textbf{d.}]5\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Total energy }&=5 \\mathrm{E}_{0}\n\t\t\\intertext{For this 3 bosons must be in $E_0$ state and $1$ in $2E_0$ state.}\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=4cm]{SM-problem-01}\n\t\t\\end{figure}\n\t\tCorrect answer is option \\textbf{(b)}\n\t\\end{answer}\n\t\\item An ensemble of quantum harmonic oscillator is kept at a finite temperature $T$ \n\t$$\\mathrm{T}=\\frac{1}{\\mathrm{k}_{\\mathrm{B}} \\beta} \\quad\n k_B\t\\text{-Boltzmann constant}$$\n The partition function of a single oscillator with energy $\\left( n+1/2\\right) \\hbar\\omega$ is given by\n  \\begin{tasks}(2)\n \t\\task[\\textbf{a.}] $Z=\\frac{e^{-\\beta \\hbar \\omega / 2}}{1-e^{-\\beta \\hbar \\omega}}$\n \t\\task[\\textbf{b.}]$Z=\\frac{e^{-\\beta \\hbar \\omega / 2}}{1+e^{-\\beta \\hbar \\omega}}$\n \t\\task[\\textbf{c.}]$Z=\\frac{1}{1-e^{-\\beta \\hbar \\omega}}$\n \t\\task[\\textbf{d.}] $Z=\\frac{1}{1+e^{-\\beta \\hbar \\omega}}$\n \\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{(i) }Q_{N}\\left(V_{1} T\\right)&=\\sum_{r} e^{-\\beta E}=\\sum_{n} e^{-\\beta(n+1 / 2) \\hbar w}\\\\\n\t\t&=e^{-\\beta \\hbar \\omega / 2}+e^{-3 / 2 \\beta \\hbar \\omega}+e^{-5 / 2^{\\beta \\hbar \\omega}}+\\ldots \\ldots\\\\\n\t\t&=\\mathrm{e}^{-\\beta \\hbar \\omega / 2}\\left(1+\\mathrm{e}^{-\\beta \\hbar \\omega}+\\mathrm{e}^{-\\beta \\hbar \\omega}+\\ldots \\ldots\\right.\\\\\n\t\t&=\\mathrm{e}^{-\\beta \\hbar \\omega / 2}\\left(\\frac{1}{1-\\mathrm{e}^{-\\beta \\hbar \\omega}}\\right)\\text{ use G.P, formula}\\hspace{0.5cm}\\left\\{\\begin{array}{lll}R=1+r+\\pi^{2} \\ldots \\ldots \\ldots \\ldots \\ldots \\infty & \\text { G.P. } \\\\ \\sum_{0}^{\\infty} R=\\frac{1}{1-r} & r<1 &  \\end{array}\\right\\}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item The average number of energy quanta of the oscillator is given by \n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\langle\\mathrm{n}\\rangle=\\frac{1}{\\mathrm{e}^{\\beta \\hbar \\omega}-1}$\n\t\t\\task[\\textbf{b.}]$\\langle\\mathrm{n}\\rangle=\\frac{\\mathrm{e}^{-\\beta \\hbar \\omega}}{\\mathrm{e}^{\\beta \\hbar \\omega}-1}$\n\t\t\\task[\\textbf{c.}]$\\langle\\mathrm{n}\\rangle=\\frac{1}{\\mathrm{e}^{\\beta \\hbar \\omega}+1}$\n\t\t\\task[\\textbf{d.}] $\\langle n\\rangle=\\frac{e^{-\\beta \\hbar \\omega}}{e^{\\beta \\hbar \\omega}+1}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{(i) The average energy of a quantum oscillator is given by}\n\t\t\\mathrm{U}&=\\mathrm{N}\\left[1 / 2 \\hbar \\omega+\\frac{\\hbar \\omega}{\\mathrm{e}^{\\beta \\hbar \\omega-1}}\\right]\n\t\t\\intertext{If we neglect the zero point energy the average energy bocome}\n\t\\mathrm{U}&=\\frac{\\mathrm{N} \\hbar \\omega}{\\mathrm{e}^{\\beta \\hbar \\omega}-1}\\\\\n\t\\text{Avarege number of energy quanta}&=\\frac{U}{N\\hbar \\omega}\\\\\\colorbox{red}{Not completed}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item In a particular salt among $n$ atoms each atom has a spin $1/2$ and is associated with a magnetic dipolemoment $\\mu_B$. The distance between the magnetic atoms is large enough to make the interaction between them negligible. In otherwords our system is an idealised spin system. The salt is placed in an external magnetic field $B$. Find the partition function of the individual atom and that for the salt \n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathrm{Q}_{1}(\\mathrm{~V}, \\mathrm{~T})&=\\sum_{\\mathrm{r}} \\mathrm{e}^{-\\beta \\mathrm{E}_{\\mathrm{r}}}\\qquad E=\\mu_B\\ B =\\text{for} S=-\\frac{1}{2}\\qquad \\left\\lbrace\\text{ where }\\mu_B=\\text{ Bohr magneton }\\right\\rbrace \\\\\n\t\t&=e^{-\\beta\\mu_B\\ B}+e^{\\beta\\mu_B\\ B}\n\t\t\\intertext{Since the salt consist of $N$ number of particles}\n\t\tQ_N(V,T)&=[Q_1(V,T)]^N=[e^{-\\beta\\mu_B\\ B}+e^{\\beta\\mu_B\\ B}]^N \\rightarrow \\text{distinguishable}\\\\\n\t\t\\colorbox{red}{Not completed}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Consider a system of two identical particles which may occupy any of the three levels. The lowest energy state $\\varepsilon_0=0$ is double degenerates. The system is in thermal equilibrium at temperature T. Determine the partition function and everage energy of the system if particles obey\n\t(i) M-B statistics\\\\\n\t(ii) B-E statistics\\\\\n\t(iii) F-D statistics.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{(i) For $M-B$ }&\\text{statistics, $g_{i}=16$}\\\\\n\t\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\Sigma g_{r} e^{-\\beta E_{r}}=4+4 e^{-\\beta \\epsilon}+5 e^{-2 \\beta \\epsilon}+2 e^{-3 \\beta \\epsilon}+e^{-4 \\beta \\epsilon}\\\\\n\t\t\\langle\\mathrm{E}\\rangle&=-\\frac{\\partial}{\\partial \\beta} \\ln \\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})=\\frac{\\in\\left[4 e^{-\\beta \\epsilon}+10 e^{-2 \\beta \\epsilon}+6 e^{-3 \\beta \\epsilon}+4 e^{-4 \\beta \\epsilon}\\right]}{Q_{N}(V, T)}\\\\\n\t\t\\langle E\\rangle&=\\frac{\\in\\left[2 e^{-\\beta \\epsilon}+6 e^{-2 \\beta \\epsilon}+3 e^{-3 \\beta \\epsilon}+4 e^{-4 \\beta \\epsilon}\\right]}{Q_{N}(V, T)}\n\t\t\\intertext{(iii) For F-D statistics:}\n\t\tQ_{N}(V, T)&=1+2 e^{-\\beta \\epsilon}+2 e^{-\\beta \\epsilon}+e^{-3 \\beta \\epsilon}\\\\\n\t\t\\langle E\\rangle&=\\frac{\\in\\left(2 e^{-\\beta \\epsilon}+4 e^{-2 \\beta \\epsilon}+3 e^{-3 \\beta \\epsilon}\\right)}{Q_{N}(V, T)}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Thermodynamics of Ensemble}\n\\begin{enumerate}\n\t\\item Consider a system of an extreme relativistic gas consisting of $3 \\mathrm{~N}$ particles moving in 1 dimension, Show that the partition function in this case is given by $\\frac{1}{3 \\mathrm{~N} !}\\left[2 \\mathrm{~L}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{hc}}\\right)\\right]^{3 \\mathrm{~N}} . \\mathbf{L}$ being the length of the space available. Study the thermodynamics and check that weather $\\mathrm{PV}=\\frac{1}{3} \\mathrm{U} \\cdot \\frac{\\mathrm{U}}{\\mathrm{N}}=3 \\mathrm{k}_{\\mathrm{B}} \\mathrm{T}, \\gamma=\\frac{4}{3}$ or not.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\left[\\mathrm{Q}_{1}(\\mathrm{~V}, \\mathrm{~T})\\right]^{\\mathrm{N}}=\\frac{1}{\\mathrm{~N} !}\\left[\\frac{1}{\\mathrm{~h}^{3}} \\int \\mathrm{e}^{-\\beta \\mathrm{H}} \\mathrm{d} \\omega\\right]^{\\mathrm{N}}\\\\\n\t\t&=\\frac{1}{N ! h^{3 N}} \\int e^{-\\beta P c} d^{3 N} p d^{3 N} q\\\\\n\t\t\\text{For extreme relativistic case }\\mathrm{H}&=\\mathrm{pc}\\text{ and } \\mathrm{d} \\omega=\\mathrm{d}^{3 \\mathrm{~N}} \\mathrm{p} \\mathrm{d}^{3 \\mathrm{~N}} \\mathrm{q}\\\\\n\t\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\frac{\\mathrm{V}^{\\mathrm{N}}}{\\mathrm{N} ! \\mathrm{h}^{3 \\mathrm{~N}}}\\left[\\int \\mathrm{e}^{\\frac{-\\mathrm{pc}}{\\mathrm{kT}}} \\mathrm{d}^{3 \\mathrm{~N}} \\mathrm{p}\\right]^{\\mathrm{N}}\\left(\\int d^{3 \\mathrm{~N}} \\mathrm{q}=\\int \\mathrm{d}^{3} \\mathrm{q}_{1} \\mathrm{~d}^{3} \\mathrm{q}_{\\mathrm{2}} .....\\mathrm{d}^{3} \\mathrm{q}_{N}\\right)\\\\\n\t\t&=\\frac{\\mathrm{V}^{\\mathrm{N}}}{\\mathrm{N} ! \\mathrm{h}^{3 \\mathrm{~N}}}\\left[\\int\\limits_{0}^{\\infty} \\mathrm{e}^{\\frac{-\\mathrm{pc}}{\\mathrm{kT}}}{ 4\\pi p }^2\\ pd \\right]^N\\\\\n\t\t&=\\frac{(4 \\pi V)^{N}}{N ! h^{3 N}}\\left[\\int\\limits_{0}^{\\infty} \\mathrm{e}^{\\frac{-\\mathrm{pc}}{\\mathrm{kT}}}{  p }^2\\ pd \\right]^N\\\\\n\t\t\\text{Let }\\frac{\\mathrm{pc}}{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}&=\\mathrm{x} \\Rightarrow \\frac{c}{k_B T} dp=dx\\\\\n\t\t&\\frac{(4 \\pi \\mathrm{V})^{\\mathrm{N}}}{\\mathrm{N} ! \\mathrm{h}^{3 \\mathrm{~N}}}\\left[\\int_{0}^{\\infty} \\mathrm{e}^{-\\mathrm{x}}\\left(\\frac{k_B Tx}{c}\\right)\\ \\frac{k_B T}{c}dx    \\right]=\\frac{(4\\pi V)}{N!h^{3N}}\\left[ \\left(\\frac{k_B T}{c} \\right) \\int e^{-x}x^2\\ dx\\right] ^N\\\\\n\t\t&\\frac{(4 \\pi \\mathrm{V})^{\\mathrm{N}}}{\\mathrm{N} ! \\mathrm{h}^{3 \\mathrm{~N}}}\\left[ \\left( \\frac{k_B T}{c}\\right)^3 2!\\right] ^N\\\\\n\t\t\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\frac{1}{\\mathrm{~N} !}\\left[8 \\pi \\mathrm{V}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{hc}}\\right)^{3}\\right]^{\\mathrm{N}}\\\\\n\t\t\\ell n \\ \\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\mathrm{N} \\ell n 8 \\pi \\mathrm{V}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{hc}}\\right)^{3}-\\log N !=N \\ell n 8 \\pi V\\left(\\frac{k_{B} T}{h c}\\right)^{3}-N \\ell n N+N\\\\\n\t\t&=\\mathrm{N} \\ell \\mathrm{n} \\frac{8 \\pi \\mathrm{V}}{\\mathrm{N}}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{hc}}\\right)^{3}+\\mathrm{N}\\\\\n\t\tA&=-k_{B} T \\ell n Q_{N}(V, T)=-N k_{B} T \\ell n \\frac{8 \\pi V}{N}\\left(\\frac{k_{B} T}{h c}\\right)^{3}-N k_{B} T\\\\\n\t\tP&=-\\left(\\frac{\\partial A}{\\partial V}\\right)=N k_{B} T \\frac{\\frac{8 \\pi}{N}\\left(\\frac{k_{B} T}{h c}\\right)^{3}}{\\frac{8 \\pi V}{N}\\left(\\frac{k_{B} T}{h c}\\right)^{3}}=\\frac{N k_{B} T}{V}\\\\\n\t\t\\Rightarrow \\quad U&=-T^{2} \\frac{\\partial}{\\partial T}\\left(\\frac{A}{T}\\right)\\\\\n\t\\text{\tNow, }U&=T^{2} \\frac{\\partial}{\\partial T}\\left[N k_{B} \\ln \\frac{8 \\pi V}{N}\\left(\\frac{k_{B} T}{h c}\\right)^{3}+N k_{B}\\right]\\\\\n\t&=\\mathrm{T}^{2} \\mathrm{Nk} \\times \\frac{\\frac{8 \\pi \\mathrm{V}}{\\mathrm{N}}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}}}{\\mathrm{hc}}\\right)^{3}, 3 \\mathrm{~T}^{2}}{\\frac{8 \\pi \\mathrm{V}}{\\mathrm{N}}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{hc}}\\right)^{3}}=\\frac{3 \\mathrm{k}_{\\mathrm{B}} \\mathrm{NT}^{4}}{\\mathrm{~T}^{3}}=3 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}\\\\\n\t\\mathrm{U}&=3 \\mathrm{Nk}_{\\mathrm{B}} \\mathrm{T}\\\\\n\\text{\tNow, }\\quad \\mathrm{P}&=\\left(\\frac{\\partial \\mathrm{A}}{\\partial \\mathrm{V}}\\right)_{\\mathrm{T}, \\mathrm{M}}=\\mathrm{PV}=\\frac{Nk_B T}{V}\\times V=N k_B T\\\\\n\\text{and }\\frac{1}{3} U&=\\frac{3 U k_{B} T}{3}=N k_{B} T\\\\\n\\text{So we get }\\mathrm{PV}&=\\frac{1}{3} \\mathrm{U} \\quad \\text{or}\\quad P=\\frac{1}{3}\\ \\frac{U}{V}\\\\\n\\text{Now }\\mathrm{dQ}&=\\mathrm{dU}+\\mathrm{PdV}\\\\\n\\text{For adiabic process }&\\mathrm{dQ}=0\\\\\n\\mathrm{dU}+\\mathrm{PdV}&=0 \\Rightarrow \\mathrm{d}(3PV)+PdV=0\\\\\n3 \\mathrm{PdV}&+3 \\mathrm{VdP}+\\mathrm{PdV}=0 \\quad \\text{or} \\quad 4PdV=3VdP\\\\\n\\frac{\\mathrm{dP}}{\\mathrm{P}}&=-\\frac{4}{3} \\frac{\\mathrm{dV}}{\\mathrm{V}}\\\\\n\\text{Integrating }\\ell nP&=-\\frac{4}{3} \\ell n V+c-\\ell n V^{4 / 3}+c\\\\\n\\ell n\\mathrm{P}+\\ell n \\mathrm{V}^{4 / 3}&=\\text{ constant,}\\quad \\mathrm{PV}^{4 / 3}= \\text{ constant}\\\\\n\\text{For this we know }\\gamma&=\\frac{4}{3}\n\t\t\\end{align*}\n\t\t\\begin{align*}\n\t\t\\text{(2) }\\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\left[\\mathrm{Q}_{1}(\\mathrm{~V}, \\mathrm{~T})\\right]^{3 \\mathrm{~N}}=\\frac{1}{3 \\mathrm{~N} !}\\left[\\frac{1}{\\mathrm{~h}} \\int_{\\infty}^{\\infty} \\mathrm{e}^{-\\beta \\mathrm{Pc}} \\mathrm{dp} \\mathrm{dq}\\right]^{3 \\mathrm{~N}}\\\\\n\t\t&=\\frac{1}{3 N ! h^{3 N}} L^{3 N}\\left|\\int^{\\infty} e^{-\\frac{P_{c}}{k T}} d p\\right|^{3 N} \\quad\\{L \\rightarrow\\text{ Length }\\}\\\\\n\t\t\\text{Let }\\frac{\\mathrm{pc}}{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}&=\\mathrm{x} \\Rightarrow \\mathrm{dp}=\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{c}} \\mathrm{dx}\\\\\n\t\t \\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T}) &=\\frac{1}{3 \\mathrm{~N} ! \\mathrm{h}^{3 \\mathrm{~N}}} \\mathrm{~L}^{3 \\mathrm{~N}}\\left[2 \\int_{0}^{\\infty} \\mathrm{e}^{-\\mathrm{x}} \\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{c}} \\mathrm{dx}\\right]^{3 \\mathrm{~N}} \\\\\n\t\t  &=\\frac{1}{3 \\mathrm{~N} ! \\mathrm{h}^{3 \\mathrm{~N}}} \\mathrm{~L}^{3 \\mathrm{~N}}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{c}}\\right)^{3 \\mathrm{~N}}\\left[2 \\int_{0}^{\\infty} \\mathrm{e}^{-\\mathrm{x}} \\mathrm{dx}\\right]^{3 \\mathrm{~N}} \\\\\n\t\t  &=\\frac{1}{3 \\mathrm{~N} ! \\mathrm{h}^{3 \\mathrm{~N}}} \\mathrm{~L}^{3 \\mathrm{~N}}\\left(\\frac{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}{\\mathrm{c}}\\right)^{3 \\mathrm{~N}}\\left[\\left[-2 \\mathrm{e}^{-\\mathrm{x}}\\right]_{0}^{\\infty}\\right]^{3 \\mathrm{~N}}\\\\\n\t\t  &=\\frac{1}{3 N ! h^{3 N}} \\mathrm{~L}^{3 N}\\left(\\frac{\\mathrm{k}_{B} T}{c}\\right)^{3 N}2^{3 N}\\\\\n\t\t  \\mathrm{Q}_{\\mathrm{N}}(\\mathrm{V}, \\mathrm{T})&=\\frac{1}{3N!}\\left[ 2L \\left( \\frac{k_B T}{hc}\\right) \\right] ^{3N}\n\t\t\\end{align*}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Grand canonical emsemble}\n\\begin{enumerate}\n\t\\item Consider a system may be either unoccupied or occoupied by one particle with energy $0$ and $E$. Find out \\\\\n\t1) partition function of the system \\\\\n\t2) Thermal average energy of the system. Thermal average occupancy of the system\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\t\\begin{array}{llll}\\mathbf{0} & \\mathbf{E} & \\mathbf{N_{r}} &E_s\\\\ 0 & 0 & 0 &0\\\\ 1 & 0 & 1 &0\\\\ 0 & 1 & 1&E\\end{array}\\\\\n\t\t\t\\mathrm{Z}(\\mu, \\mathrm{V}, \\mathrm{T})&=\\sum_{\\mathrm{rs}}e^{-\\alpha N_1-\\beta E_s}\\\\\n\t\t\t&=e^{-\\alpha\\times0-\\beta\\times0}+e^{-\\alpha\\times1-\\beta\\times0}+e^{-\\alpha\\times1-\\beta\\times1}\\\\\n\t\t\t1+\\mathrm{e}^{-\\alpha}+\\mathrm{e}^{-\\alpha-\\beta \\epsilon}=&=1+e^{+\\frac{\\mu}{k_{B} T}}+e^{\\left(\\frac{\\mu}{k_{B} T}-\\frac{E}{k_{B} T}\\right)}\\\\\n\t\t\tU&=\\left\\langle E_{S}\\right\\rangle=\\frac{\\sum_{r s} \\in_{S} e^{-\\alpha N_{r}-\\beta E_{S}}}{\\sum_{r s} e^{-\\alpha N_{r}-\\beta E_{S}}}=\\sum_{r s} E_{S} P_{r s}\\\\\n\t\t\t\\bar{N}&=\\left\\langle N_{r}\\right\\rangle=\\frac{\\sum_{r s} N_{r} e^{-\\alpha N_{r}-\\beta E S}}{\\sum_{r s} e^{-\\alpha N_{r}-\\beta E_{S}}}=\\sum_{r s} N_{r} P_{r S}\\\\\n\t\t\t\\overline{\\mathrm{N}}&=-\\frac{\\partial}{\\partial N} \\ln \\mathrm{Z}(\\mu, \\mathrm{V}, \\mathrm{T})_{\\beta, \\mathrm{V}}=\\mathrm{e}^{-\\alpha}-\\mathrm{e}^{-\\alpha-\\beta \\epsilon} / 1+\\mathrm{e}^{-\\alpha}+\\mathrm{e}^{-\\alpha-\\beta \\epsilon}\\\\\n\t\t\t\\mathrm{E}&=-\\frac{\\partial}{\\partial \\beta} \\ln \\mathrm{Z}(\\mu, \\mathrm{V}, \\mathrm{T})_{\\alpha, \\mathrm{N}}=\\frac{\\epsilon \\mathrm{e}^{(\\mu-\\epsilon) \\beta}}{1+\\mathrm{e}^{\\mu \\beta}+\\mathrm{e}^{(\\mu-\\epsilon) \\beta}}\n\t\t\\end{align*}\n\t\\end{answer}\n \\item Repeat the above problem if each state may be occupied by one particle of the same time \n \\begin{answer}\n \t\\begin{align*}\n \t\\begin{array}{llll} & \\mathbf{E} & \\mathbf{N}_{\\mathrm{r}} & \\mathbf{E}_{\\mathrm{s}} \\\\ 0 & 0 & 0 & 0 \\\\ 1 & 0 & 1 & 0 \\\\ 0 & 1 & 1 & \\mathrm{E} \\\\ 0 & 1 & 2 & \\mathrm{E}\\end{array}\\\\\n \t\\mathrm{Z}_{\\mathrm{N}}(\\mu, \\mathrm{V}, \\mathrm{T})&=1+\\mathrm{e}^{-\\alpha}+\\mathrm{e}^{-\\alpha-\\beta \\epsilon}+\\mathrm{e}^{-2 \\alpha-\\beta \\epsilon}\n \t\\end{align*}\n \\end{answer}\n\t\\item In a system in thermal equilibrium at absolute temperature T, two states with energy difference $4.83 \\times 10^{-21} \\mathrm{~J}$ occour with relative probability $\\mathrm{e}^{2}$. Deduce the temperature $\\left(\\mathrm{k}_{\\mathrm{B}}=1.38 \\times 10^{-23} \\mathrm{~J} / \\mathrm{K}\\right)$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\Delta \\mathrm{E}&=4.83 \\times 10^{-23}\\\\\n\t\t\\frac{\\mathrm{P}_{1}}{\\mathrm{P}_{2}}&=\\mathrm{e}^{2}\\\\\n\t\t\\mathrm{P}_{\\mathrm{i}}&=\\mathrm{Ce}^{-\\beta \\mathrm{E}_{\\mathrm{i}}}\\\\\n\t\t\\mathrm{P}_{1}&=\\mathrm{Ce}^{-\\beta \\mathrm{E}_{1}}\\qquad \\mathrm{P}_{2}=\\mathrm{Ce}^{-\\beta \\mathrm{E}_{2}}\\\\\n\t\t\\frac{\\mathrm{P}_{1}}{\\mathrm{P}_{2}}&=\\frac{\\mathrm{Ce}^{-\\beta \\mathrm{E}_{1}}}{\\mathrm{Ce}^{-\\beta \\mathrm{E}_{2}}}=\\mathrm{e}^{-\\beta\\left(\\mathrm{E}_{1}-\\mathrm{E}_{2}\\right)}=e^{-\\beta (E_2-E_1)}\\\\\n\t\te^{2}&=e^{\\left(E_{2}-E_{1}\\right)}\\\\\n\t\t2&=\\beta\\left(\\mathrm{E}_{2}-\\mathrm{E}_{1}\\right)\\\\\n\t\t2&=\\frac{1}{\\mathrm{k}_{\\mathrm{B}} \\mathrm{T}}\\left(\\mathrm{E}_{2}-\\mathrm{E}_{1}\\right)\\\\\n\t\t2 \\mathrm{k}_{\\mathrm{B}} \\mathrm{T}&=\\mathrm{E}_{2}-\\mathrm{E}_{1}\\Rightarrow T=\\frac{E_2-E_1}{2k_B}\\\\\n\t\t&=\\frac{4.83 \\times 10^{-23J}}{2 \\times 1.38 \\times 10^{-23}J/K}=1.75 K\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item A diatomic gas in thermal equilibrium have temperature $500K$. Its rotational constant $2.0 cm^{-1}$. Calculate the relative populations in the rotational states.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Population}\\quad E&=\\frac{h^2}{8\\pi^2 I}J(J+I)\\qquad B=\\frac{h}{8\\pi^2IC}\\\\\n\t\t\\color{red}{???}\\\\\n\t\t\\mathrm{N}_{\\mathrm{J}}&=\\frac{\\mathrm{N}(2 \\mathrm{~J}+1) \\mathrm{e}^{-\\beta \\mathrm{E}_{\\mathrm{J}}}}{\\sum_{\\mathrm{J}} \\mathrm{e}^{-\\beta \\mathrm{E}_{\\mathrm{J}}}}\\\\\n\t\\text{\tBut }\n\t\t\\mathrm{BhC}&=3.96 \\times 10^{-16} \\mathrm{erg}\\\\\n\t\t\\frac{\\mathrm{N}_{10}}{\\mathrm{~N}_{0}}&=91.28 \\text{Ans.}\\\\\n\t\t\\frac{\\mathrm{N}_{20}}{\\mathrm{~N}_{0}}&=3.371\\text{ Ans}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "2cbabc2e8520afdb504cea4a8b635faf14a3c855", "size": 32226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Statistical Mechanics/chapter/Problems.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": "Statistical Mechanics/chapter/Problems.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": "Statistical Mechanics/chapter/Problems.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": 78.9852941176, "max_line_length": 553, "alphanum_fraction": 0.6075218767, "num_tokens": 13553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6187691409163698}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\title{Assignment 7}\n\n\n\\section{Question 1}\n\\begin{statebox}{Timescale Invariance}{question-1}\n    \\begin{align*}\n        d_1 &= \\frac{\\log(S/E)+(r+\\sigma^2/2)(T-t)}{\\sigma\\sqrt{T-t}} \\\\\n        d_1 &= \\frac{\\log(S/E)+(r-\\sigma^2/2)(T-t)}{\\sigma\\sqrt{T-t}}\n    \\end{align*}\n    Prove the following identity:\n    \\[\n    \td_2 = d_1 - \\sigma\\sqrt{T-t}\n    \\]\n\\end{statebox}\n\n\\Python{}{code/7-a.py}\n\n\n\n\\section{Question 2}\n\\begin{statebox}{Put-Call Parity}{question-2}\n    With $t=0$, $S_0=5$, $E=4$, $T=1$, $\\sigma=0.3$ and $r=0.05$, find the option values and verify the put-call parity.\n\\end{statebox}\n\n\\Python{}{code/7-b.py}\n\n\n\n\\section{Question 3}\n\\begin{statebox}{Study Note}{question-3}\n    \\begin{enumerate}\n    \t\\item Write a study note of Black-Scholes' 73 paper.\n    \t\\item Find a sequence of works following this paper and sort out hot topics nowadays.\n    \\end{enumerate}\n\\end{statebox}\n\nTo be continued.\n", "meta": {"hexsha": "528cda3300522dcf25ed6e198d2cb8921327c9e3", "size": 962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA216/sections/7.tex", "max_stars_repo_name": "AllenYZB/homework", "max_stars_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-15T04:24:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-15T04:24:40.000Z", "max_issues_repo_path": "MA216/sections/7.tex", "max_issues_repo_name": "AllenYZB/homework", "max_issues_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MA216/sections/7.tex", "max_forks_repo_name": "AllenYZB/homework", "max_forks_repo_head_hexsha": "65bd3372df197bec5e152a37cdc1f6f5432b7f3e", "max_forks_repo_licenses": ["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.05, "max_line_length": 120, "alphanum_fraction": 0.6299376299, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6187691330949511}}
{"text": "\\subsection{Norms}\\label{subsec:norms}\n\n\\begin{remark}\\label{rem:normed_fields}\n  Norms generalize distances of points in a plane, while absolute values generalize the absolute value over either \\( \\BbbR \\) or \\( \\BbbC \\). The axioms themselves differ minimally. Absolute values in a field are multiplicative norms over the field, however we cannot define absolute values in terms of norms since absolute values are needed for defining norms. Still, we will refer to fields with absolute values as \\term{normed fields}.\n\\end{remark}\n\n\\begin{definition}\\label{def:absolute_value}\\mcite{nLab:absolute_value}\n  Let \\( R \\) be a \\hyperref[def:semiring]{semiring}. We say that the function \\( \\abs{\\cdot}: V \\to \\BbbR_{>0} \\) is an \\term{absolute value} or a \\term{semiring norm} if\n  \\begin{thmenum}\n    \\thmitem[def:absolute_value/RN1]{RN1}(identity) \\( x = 0_R \\) if and only if \\( \\abs{x} = 0 \\)\n    \\thmitem[def:absolute_value/RN2]{RN2}(multiplicativity) For any \\( x, y \\in V \\),\n    \\begin{equation*}\n      \\abs{xy} = \\abs{x} \\cdot \\abs{y}\n    \\end{equation*}\n\n    \\thmitem[def:absolute_value/RN3]{RN3}(subadditivity) For any \\( x, y \\in V \\),\n    \\begin{equation*}\n      \\abs{x + y} \\leq \\abs{x} + \\abs{y}\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:norm}\n  Let \\( M \\) be an \\( R \\)-module with absolute value \\( \\abs{\\cdot} \\). We say that the function \\( \\norm{\\cdot}: M \\to \\BbbR_{\\geq 0} \\) is a \\term{norm} if\n  \\begin{thmenum}\n    \\thmitem[def:norm/N1]{N1}(identity) \\( x = 0_M \\) if and only if \\( \\norm x = 0_{\\BbbR} \\)\n\n    \\thmitem[def:norm/N2]{N2}(absolute homogeneity)\n    \\begin{equation*}\n      \\norm{t x} = \\abs{t} \\norm{x} \\text{ for all } t \\in R \\text{ and } x \\in M\n    \\end{equation*}\n\n    \\thmitem[def:norm/N3]{N3}(subadditivity)\n    \\begin{equation*}\n      \\norm{x + y} \\leq \\norm{x} + \\norm{y} \\text{ for all } x, y \\in M\n    \\end{equation*}\n  \\end{thmenum}\n\n  If we remove \\fullref{def:norm/N1}, then \\( \\norm{\\cdot} \\) is called a \\term{seminorm}.\n\n  If instead \\( V \\) is an \\hyperref[def:algebra_over_ring]{associative} and \\( \\norm{\\cdot} \\) satisfies the additional axiom\n  \\begin{thmenum}\n    \\thmitem{def:norm/multiplicativity}(multiplicativity)\n    \\begin{equation*}\n      \\norm{xy} = \\norm{x} \\cdot \\norm{y} \\text{ for all } x, y \\in M,\n    \\end{equation*}\n  \\end{thmenum}\n  we say that it is a \\term{multiplicative norm}.\n\\end{definition}\n\n\\begin{definition}\\label{def:norm_induced_metric}\n  A norm \\( \\norm \\cdot \\) on a real or complex vector space \\( V \\) induces the \\hyperref[def:vector_space]{metric}\n  \\begin{balign*}\n     & \\rho: V \\times V \\to \\BbbR_{\\geq 0}  \\\\\n     & \\rho(x, y) \\coloneqq \\norm{x - y}.\n  \\end{balign*}\n\\end{definition}\n\\begin{proof}\n  The function is positive definite since \\( \\norm \\cdot \\) is positive definite; we will show that the function is a metric.\n\n  \\SubProofOf{def:metric_space/M1} Follows from \\fullref{def:norm/N1}.\n\n  \\SubProofOf{def:metric_space/M2} By \\fullref{def:norm/N2},\n  \\begin{equation*}\n    \\rho(x, y) = \\norm{ x - y } = \\norm{ (-1) (y - x) } = \\abs{-1} \\norm{y - x} = \\rho(y, x).\n  \\end{equation*}\n\n  \\SubProofOf{def:metric_space/M3}\n  \\begin{equation*}\n    \\rho(x, y) + \\rho(y, z) = \\norm{x - y} + \\norm{y - z} \\geq \\norm{x - z} = \\rho(x, z).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:duality_mapping}\\mcite[exmpl. 2.26]{Phelps1993}\n  We define the \\term{duality mapping}\n  \\begin{balign*}\n     & D: E \\multto X^*,                                                                                              \\\\\n     & D(x) \\coloneqq \\{ x^* \\in X^* \\colon \\norm x = \\norm {x^*} \\text{ and } \\inprod{x^*} x = \\norm {x^*} \\norm x \\}.\n  \\end{balign*}\n\n  We will usually use this mapping for unit vectors, so we may as well consider its restriction to the unit spheres, where\n  \\begin{balign*}\n     & D': S_X \\multto S_{X^*},                                       \\\\\n     & D'(x) \\coloneqq \\{ x^* \\in S_{X^*} \\colon \\inprod{x^*} x = 1 \\}.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{definition}\\label{def:smooth_norm}\\mcite[def. 2.36]{Phelps1993}\n  The norm \\( \\norm \\cdot \\) on \\( X \\) is called \\term{smooth} if any of  if for each \\( x \\in S_X \\) the duality mapping is single-valued.\n\\end{definition}\n\n\\begin{definition}\\label{def:rotund_norm}\\mcite[def. 2.36]{Phelps1993}\n  The norm \\( \\norm \\cdot \\) on \\( X \\) is called \\term{rotund} or \\term{strictly convex} if any of the following equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:rotund_norm/no_sphere_segments} There are no line segments in the unit sphere \\( S_X \\).\n    \\thmitem{def:rotund_norm/least_norm} Every convex subset of \\( X \\) has at most one point of least norm.\n    \\thmitem{def:rotund_norm/linearly_dependent}\n    \\begin{balign}\\label{def:rotund_norm/linearly_dependent/equation}\n      \\norm{x + y} = \\norm x + \\norm y \\implies x \\text{ and } y \\text{ are linearly dependent}.\n    \\end{balign}\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:rotund_norm/no_sphere_segments}{def:rotund_norm/least_norm} Let the norm in \\( E \\) be rotund and let \\( C \\subseteq E \\) be a (potentially empty) convex set. We will prove that \\( C \\) contains at most one point of least norm.\n\n  If \\( C \\) is empty or otherwise contains no element of least norm, trivially contains at most one point of least norm.\n\n  Now let \\( C \\) contain at least one element \\( x \\in C \\) of least norm. Assume that \\( y \\in C \\) is another element of least norm. Necessarily \\( \\norm x = \\norm y \\).\n\n  Fix \\( t \\in (0, 1) \\) and define \\( z \\coloneqq tx + (1-t)y \\). Since \\( C \\) is convex, it contains \\( z \\). Since \\( x \\) and \\( y \\) are elements of least norm, we have \\( \\norm z \\geq \\norm x \\). By the triangle inequality,\n  \\begin{balign*}\n    \\norm{z}\n    =\n    \\norm{tx + (1-t)y}\n    \\leq\n    t \\norm x + (1-t) \\norm y\n    =\n    \\norm{x},\n  \\end{balign*}\n  thus \\( \\norm z = \\norm x \\).\n\n  This implies that the entire segment \\( [x, y] \\) are elements of least norm in \\( C \\). Hence, the segment \\( [x, y] \\) is contained in the sphere \\( \\norm x S_E \\), which contradicts the rotundity of the norm \\( \\norm{\\cdot} \\).\n\n  Hence, \\( C \\) contains at most one element of least norm.\n\n  \\ImplicationSubProof{def:rotund_norm/least_norm}{def:rotund_norm/no_sphere_segments} Let every convex set \\( C \\subseteq E \\) have at most one element of least norm.\n\n  Assume that the norm \\( \\norm{\\cdot} \\) is not rotund. Then the unit sphere \\( S_E \\) contains a line segment \\( [x, y], x \\neq y \\). The set \\( [x, y] \\) is compact and, by the Weierstrass extreme value theorem, the norm attains its minimum on the segment in a point \\( z \\in [x, y] \\). Since the segment is also convex and we assumed that convex sets have at most one element of least norm, it follows that this element \\( z \\) is unique.\n\n  Then for any point \\( s \\in [x, y], s \\neq z \\), we have \\( \\norm s > \\norm z = 1 \\), thus \\( s \\) cannot be an element of the unit sphere. The obtained contradiction shows that the norm \\( \\norm{\\cdot} \\) is rotund.\n\n  \\ImplicationSubProof{def:rotund_norm/no_sphere_segments}{def:rotund_norm/linearly_dependent} Let \\( E \\) be rotund let \\( x, y \\in E \\) be distinct vectors such that\n  \\begin{balign}\\label{def:rotund_norm/linearly_dependent/assumption}\n    \\norm{x + y} = \\norm x + \\norm y.\n  \\end{balign}\n\n  If either of them is the zero vector, then they are trivially linearly dependent.\n\n  Assume that both \\( x \\) and \\( y \\) are nonzero and define\n  \\begin{balign*}\n    \\xi \\coloneqq \\frac x {\\norm x}\n     &  &\n    \\eta \\coloneqq \\frac y {\\norm y}\n     &  &\n    t \\coloneqq \\frac {\\norm x} {\\norm{x + y}}\n  \\end{balign*}\n\n  \\Fullref{def:rotund_norm/linearly_dependent/assumption} implies that\n  \\begin{equation*}\n    1 - t = 1 - \\frac {\\norm x} {\\norm{x + y}} = \\frac {\\norm{x + y} - \\norm x} {\\norm{x + y}} = \\frac {\\norm y} {\\norm{x+y}}.\n  \\end{equation*}\n\n  Since both \\( \\xi \\) and \\( \\eta \\) are in \\( S_E \\), by rotundity, their convex combination\n  \\begin{equation*}\n    \\nu \\coloneqq t \\xi + (1-t)\\eta\n  \\end{equation*}\n  should not be contained in \\( S_E \\) unless \\( \\xi = \\eta \\).\n\n  Calculating the norm, we obtain\n  \\begin{balign*}\n    \\norm{\\nu}\n     & =\n    \\norm{t \\xi + (1-t)\\eta}\n    =    \\\\ &=\n    \\norm{\\frac {\\norm x \\xi} {\\norm{x + y}} + \\frac {\\norm y \\eta} {\\norm{x + y}}}\n    =    \\\\ &=\n    \\norm{\\frac {x + y} {\\norm{x + y}}}\n    = 1,\n  \\end{balign*}\n  hence \\( \\nu \\in S_E \\). Thus, \\( \\xi = \\eta \\) and \\( x = \\frac {\\norm x} {\\norm y} y \\), so \\( x \\) and \\( y \\) are linearly dependent.\n\n  \\ImplicationSubProof{def:rotund_norm/linearly_dependent}{def:rotund_norm/no_sphere_segments} Let \\fullref{def:rotund_norm/linearly_dependent/equation} hold and fix \\( x, y \\in S_E, t \\in (0, 1) \\). Define \\( z \\coloneqq tx + (1-t)y \\).\n  First, assume that the vectors \\( tx \\) and \\( (1-t)y \\) satisfy the left part of \\fullref{def:rotund_norm/linearly_dependent/equation}, i.e.\n  \\begin{equation*}\n    \\norm z = \\norm{tx + (1-t)y} = t \\norm x + (1-t) \\norm y = 1.\n  \\end{equation*}\n\n  This does not refute rotundity since \\( x \\) and \\( y \\) are not necessarily distinct. It follows from \\fullref{def:rotund_norm/linearly_dependent/equation} that \\( tx \\) and \\( (1-t)y \\) are linearly dependent, hence \\( x \\) and \\( y \\) are also linearly dependent. Since \\( x \\) and \\( y \\) both have unit norm, either \\( y = x \\) or \\( y = -x \\).\n\n  If we assume that \\( y = -x \\), then\n  \\begin{balign*}\n    \\norm z\n    =\n    \\norm{tx + (1-t)y}\n    =\n    (2t - 1) \\norm x\n    =\n    2t - 1,\n  \\end{balign*}\n  which is only possible if \\( t = 1 \\) since \\( \\norm z = 1 \\). But \\( t \\) is strictly less than 1.\n\n  Hence, \\( y \\neq -x \\) and the only remaining possibility is that \\( y = x \\).\n\n  Now assume that the vectors \\( tx \\) and \\( (1-t)y \\) do not satisfy the left part of \\fullref{def:rotund_norm/linearly_dependent/equation}. This implies \\( \\norm z < 1 \\). Thus, \\( x \\) and \\( y \\) are necessarily distinct, but \\( z \\) is not contained in the unit sphere and the segment \\( [x, y] \\) is not contained in \\( S_E \\).\n\n  We have shown that \\( x, y \\in S_E \\) implies that either \\( y = x \\) or that the segment \\( [x, y] \\) is not contained in \\( S_E \\), thus the norm in \\( E \\) is rotund.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:smooth_rotund_norm_duality}\\mcite[exer. 2.37(a)]{Phelps1993}\n  If the norm in a Banach space \\( X \\) is such that its dual norm in \\( X^* \\) is rotund (resp. smooth), then it is itself smooth (resp. rotund).\n\\end{theorem}\n\\begin{proof}\n  \\begin{enumerate}\n    \\item First, let the dual norm \\( \\norm{\\cdot}^* \\) be rotund and assume that \\( \\norm{\\cdot} \\) is not smooth.\n\n          Fix \\( x \\in S_X \\). Since \\( D(x) \\) is nonempty (by \\fullref{thm:hahn_banach_implies_duality_mapping_nonempty}) and since \\( \\norm{\\cdot} \\) is not smooth, then there exist two different functionals \\( x^*, y^* \\in D(x) \\), such that\n          \\begin{balign*}\n            \\inprod {x^*} x\n            =\n            \\inprod {y^*} x\n            =\n            1.\n          \\end{balign*}\n\n          We will show that the segment \\( [x^*, y^*] \\) is contained in \\( S_{X^*} \\), i.e. that the dual norm is not rotund.\n\n          Fix any \\( t \\in (0, 1) \\) and define \\( z^* \\coloneqq t x^* + (1-t) y^* \\). We only need to show that \\( \\norm{z^*} = 1 \\).\n\n          By the triangle inequality, we have\n          \\begin{balign*}\n            \\norm{z^*}\n            =\n            \\norm{t x^* + (1-t) y^*}\n            \\leq\n            t \\norm{x^*} + (1-t) \\norm{y^*}\n            =\n            t + (1-t)\n            =\n            1.\n          \\end{balign*}\n\n          For the reverse inequality, note that\n          \\begin{balign*}\n            \\norm{z^*}\n            \\geq\n            \\inprod {z^*} x\n            =\n            t \\inprod {x^*} x + (1-t) \\inprod {y^*} x\n            =\n            t + (1-t)\n            =\n            1,\n          \\end{balign*}\n          thus \\( \\norm{z^*} = 1 \\). Hence, \\( [x^*, y^*] \\) is contained in \\( S_{X^*} \\) and the dual space is not smooth. The obtained contradiction proves that the norm in \\( X \\) is rotund.\n\n    \\item Now let the dual norm \\( \\norm{\\cdot}^* \\) be smooth and assume that \\( \\norm{\\cdot} \\) is not rotund. Then there exist points \\( x, y \\in S_X \\) such that the while segment \\( [x, y] \\) is contained in \\( S_X \\).\n\n          Fix \\( t \\in (0, 1) \\) and define \\( z \\coloneqq tx + (1-t)y \\in S_X \\). Denote by \\( J: X \\to X^{**} \\) the canonical embedding into the double-dual. By \\fullref{thm:hahn_banach_implies_duality_mapping_nonempty}, there exists a functional \\( z^* \\in X^* \\), such that\n          \\begin{balign*}\n            \\inprod {J(z)} {z^*}\n            =\n            \\inprod{z^*} z\n            =\n            1.\n          \\end{balign*}\n\n          Because the dual norm \\( \\norm{\\cdot}^* \\) is smooth, we cannot have \\( \\inprod{J(x)} {z^*} =  \\inprod{z^*} x = 1 \\) or \\( \\inprod{J(y)} {z^*} = \\inprod{z^*} y = 1 \\) and since \\( \\norm{z^*} = 1 \\), necessarily\n          \\begin{equation*}\n            \\inprod{z^*} x < 1 \\text{ and } \\inprod{z^*} y < 1.\n          \\end{equation*}\n\n          If follows that\n          \\begin{balign*}\n            1\n            =\n            \\inprod{z^*} z\n            =\n            t \\inprod{z^*} x + (1-t) \\inprod{z^*} y\n            <\n            t + (1-t)\n            =\n            1,\n          \\end{balign*}\n          which is a contradiction. Hence, \\( \\norm{\\cdot} \\) is rotund.\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:hilbert_space_smooth_rotund}\\mcite[exer. 2.37(c)]{Phelps1993}\n  Norms in Hilbert spaces are both smooth and rotund.\n\\end{proposition}\n\\begin{proof}\n  Let \\( X \\) be a Hilbert space, i.e. the norm is generated by an inner product and, due to Riesz's theorem, we identify the space \\( X \\) with its continuous dual \\( X^* \\).\n\n  To prove that \\( X \\) is rotund, choose \\( x, y \\in S_X, x \\neq y \\). We will show that the segment \\( [x, y] \\) is not contained in \\( S_X \\).\n\n  If \\( x \\) and \\( y \\) are linearly dependent, necessarily \\( y = -x \\) and all non-trivial convex combinations of \\( x \\) and \\( y \\) are contained in the open unit ball, hence \\( [x, y] \\not\\subseteq S_X \\).\n\n  Not let \\( x \\) and \\( y \\) be linearly independent. By the Cauchy-Bunyakovsky-Schwarz inequality, we have\n  \\begin{balign}\\label{eq:hilbert_cauchy_inequality}\n    \\inprod x y \\leq \\abs{\\inprod x y} < \\norm x \\norm y = 1.\n  \\end{balign}\n\n  Fix \\( t \\in (0, 1) \\) and let \\( z \\coloneqq tx + (1-t)y \\). We will show that \\( z \\not\\in S_X \\). Indeed,\n  \\begin{balign*}\n    \\norm{z}^2\n    =\n    \\inprod z z\n     & =\n    t^2 \\norm x^2 + t(1-t) \\inprod x y + (1-t) t \\inprod y x + (1-t)^2 \\norm y^2\n    =    \\\\ &=\n    t^2 + (1-t)^2 + 2 t(1-t) \\inprod x y\n    <    \\\\ &\\reloset {(\\ref{eq:hilbert_cauchy_inequality})} <\n    t^2 + (1-t)^2 + 2 t(1-t)\n    =    \\\\ &=\n    t^2 + 1 - 2t + t^2 + 2t - t^2\n    =\n    1.\n  \\end{balign*}\n\n  Thus, \\( \\norm{z}^2 < 1 \\) and \\( \\norm z < 1 \\) and \\( z \\not\\in S_X \\).\n\n  In both cases, no interior point of the segment \\( [x, y] \\) is contained in \\( S_X \\), hence the norm in \\( X \\) is rotund.\n\n  Since we identify \\( X \\) with its dual, the norm in \\( X^* \\) is also rotund and by \\fullref{thm:smooth_rotund_norm_duality}, the norm in \\( X \\) is also smooth.\n\\end{proof}\n\n\\begin{example}\\label{thm:c0_l1_not_smooth_rotund}\\mcite[exer. 2.37(c)]{Phelps1993}\n  The norms in \\( c_0 \\) and \\( l^1 \\) are neither smooth nor rotund.\n\\end{example}\n\\begin{proof}\n  Consider the space \\( c_0 \\) of all real sequences that converge to zero equipped with the uniform norm\n  \\begin{equation*}\n    \\norm{x}_{c_0} \\coloneqq \\sup_i \\abs{x_i}.\n  \\end{equation*}\n\n  Note that the dual space of \\( c_0 \\) is (isometrically isomorphic to) the space \\( l^1 \\) of absolutely summable sequences with norm\n  \\begin{equation*}\n    \\norm{x}_{l^1} \\coloneqq \\sum_i \\abs{x_i}.\n  \\end{equation*}\n\n  Let \\( \\{ e_n \\}_{n=1}^\\infty \\) be the canonical basis of \\( c_0 \\), i.e. the coordinates \\( e^{(i)}_n \\) of \\( e_n \\) are given by the Dirac delta function, \\( e^{(i)}_n \\coloneqq \\delta_{i,n} \\).\n\n  For every natural \\( n \\geq 1 \\), define \\( x_n \\) to be the same as \\( e_n \\) except that the first coordinate of \\( x_n \\) is always \\( 1 \\).\n\n  The corresponding norms of \\( e_n \\) are all equal to 1 and the norms of \\( x_n \\) are\n  \\begin{balign*}\n    \\norm{x_n}_{c_0} = 1\n     &  &\n    \\norm{x_n}_{l^1} = 2.\n  \\end{balign*}\n\n  For every \\( n \\) we have\n  \\begin{equation*}\n    \\inprod {e_1} {x_n} = \\inprod {e_n} {x_n} = 1,\n  \\end{equation*}\n  hence \\( J_{c_0}(x_n) \\) has at least two elements \\( e_1 \\) and \\( e_n \\) and the norm in \\( c_0 \\) is not smooth.\n\n  Given that \\( \\{ x_1, x_2, \\ldots \\} \\subseteq S_{c_0} \\), consider the convex combinations of \\( x_2 \\) and \\( x_3 \\):\n  \\begin{balign*}\n    tx_2 + (1-t)x_3\n    =\n    (1, t, (1-t), 0, 0, \\ldots).\n  \\end{balign*}\n\n  Evidently \\( tx_2 + (1-t)x_3 \\in S_{c_0} \\) for every \\( t \\in (0, 1) \\), hence the norm in \\( c_0 \\) is not rotund.\n\n  The contrapositions to the statements in \\fullref{thm:smooth_rotund_norm_duality} say that if \\( X \\) is not rotund (resp. smooth), then the dual space \\( X^* \\) is not smooth (resp. rotund). Thus, \\( l^1 \\) is neither smooth or rotund as the dual of \\( c_0 \\).\n\\end{proof}\n", "meta": {"hexsha": "57020f47f7566729bb5d4e464d1452cb57f11116", "size": 17285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/norms.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/norms.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/norms.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.147632312, "max_line_length": 442, "alphanum_fraction": 0.5913798091, "num_tokens": 5981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.618769129087516}}
{"text": "\\subsection{Descriptions of Error}\\label{sec:set-error}\nIf we assume $\\observed$ is absolutely continuous with respect to $\\dmeas$, we can describe $\\observed$ with a density $\\observedP$. Then, for any partition $\\set{D_\\idisc}_{\\idisc=1}^{\\ndiscs}$ of $\\dspace$,\n\\[\n\\observed (D_\\idisc) = \\int_{D_\\idisc} \\observed \\, \\dmeas, \\quad \\text{ for } \\idisc = 1, \\hdots, \\ndiscs.\n\\]\n\nWe often use Monte Carlo approximations to compute the approximations $p_{\\dspace, \\idisc}=\\observed(D_\\idisc)$ in the first for-loop in Algorithm~\\ref{alg:inv_density}.\nThese samples are generated on $\\dspace$ and do not require numerical solutions to the model.\nWe therefore assume that for any discretization of $\\dspace$, these approximations can be made sufficiently accurate and neglect the error in this computation.\n\nWe denote the exact solution to the SIP associated with this partitioning of $\\dspace$ by $\\PP_{\\pspace, \\ndiscs}$.\nIn situations where $\\qoi(\\param^{(\\iparam)})$ is estimated (e.g. by application of a functional on a finite-element solution to a PDE), the approximate solutions to the SIP given in the final for-loop of Algorithm~\\ref{alg:inv_density} are denoted by $\\PP_{\\pspace, \\ndiscs, \\nsamps, h}$.\nHere, the $h$ is in reference to a mesh or other numerical parameter that determines the accuracy of the numerical solution $u_h(\\param^{(\\iparam)})\\approx u(\\param^{(\\iparam)})$, and subsequently the accuracy in the computations of $\\qoi_\\iparam = \\qoi(\\param^{(\\iparam)})$ in Algorithm~\\ref{alg:inv_density}.\nThen, by repeated application of the triangle inequality,\n\\begin{equation}\n\\label{eq:set-triangleineq}\nd(\\PP_{\\pspace, \\ndiscs, \\nsamps, h}, \\paramP) \\leq\n\\underset{ \\text{(E1)} }{\\underbrace{d(\\PP_{\\pspace, \\ndiscs, \\nsamps, h},\\PP_{\\pspace, \\ndiscs, \\nsamps})}} +\n\\underset{ \\text{(E2)} }{\\underbrace{d(\\PP_{\\pspace, \\ndiscs, \\nsamps}, \\PP_{\\pspace, \\ndiscs}) }}+\n\\underset{ \\text{(E3)} }{\\underbrace{d(\\PP_{\\pspace, \\ndiscs}, \\paramP) }}.\n\\end{equation}\n\nThe term (E1) describes the effect of the error in the numerically evaluated $\\qoi_\\iparam$ on the solution to the SIP.\nThe term (E2) describes the effect of finite sampling error in $\\pspace$ on the solution to the SIP and (E3) describes the effect of discretization error of $\\observed$ on the solution to the SIP.\n\nWe assume that $h$ is tunable so that for any $A\\in \\pborel$,\n\\[\n\\lim\\limits_{h \\downarrow 0} \\PP_{\\pspace, \\ndiscs, \\nsamps, \\imesh} (A) = \\PP_{\\pspace, \\ndiscs, \\nsamps} (A).\n\\]\nIt is possible to prove the convergence of $\\PP_{\\pspace, \\ndiscs, \\nsamps, \\imesh} (A) \\to \\paramP (A)$ for some $A\\in \\pborel$ and on estimating the error in $\\PP_{\\pspace, \\ndiscs, \\nsamps, h}(A)$.\nFor example, in \\cite{BGE+15}, adjoint-based a posteriori estimates in the computed QoI are combined with a statistical analysis to both estimate and bound the error in $\\PP_{\\pspace, \\ndiscs, \\nsamps, \\imesh} (A)$.\nIn \\cite{JNME19}, adjoints are used to compute both error and derivative estimates of $\\qoi(\\param^{(\\iparam)})$ to improve the accuracy in $\\PP_{\\pspace, \\ndiscs, \\nsamps, \\imesh} (A)$.\nSince the error due to $\\imesh$ can be estimated as described in previous studies, and $\\ndiscs$ can be made arbitrarily large, we neglect (E1) and (E3) here.\nThus, we limit our focus to (E2), where certain geometric properties of the QoI map (namely, skewness), are known to significantly impact this term.\n\n\\FloatBarrier\n", "meta": {"hexsha": "cd47502b42bb669e978213f2c1d9803012cd62a9", "size": 3405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "set-based/set_error.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/set_error.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/set_error.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": 92.027027027, "max_line_length": 310, "alphanum_fraction": 0.7251101322, "num_tokens": 1058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587668, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6187581664887516}}
{"text": "\\documentclass{beamer}\n\\usepackage[utf8]{inputenc}\n\n\\input{../../shared.tex}\n\n\\title{Newton's and Quasi-Newton Methods}\n\\date{\\today}\n\n\n\\begin{document}\n\\maketitle\n\\frame{\\tableofcontents[]}\n\n\\section{Introduction}\n\n\\begin{frame}\n  \\frametitle{$1$-dimensional case: Newton-Raphson method}\n  \\textcolor{blue}{Objective:} Find zero of differentiable $f: \\R \\to \\R$.\n  \\vspace{0.3cm}\n  \\begin{minipage}{0.48\\textwidth}\n    \\textcolor{blue}{Strategy:} Solve\n    \\begin{equation}\n      f(x_k) + f'(x_k) (x - x_k) = 0.\n    \\end{equation}\n    \\textcolor{blue}{Method:} Gives\n    \\begin{equation}\n      x_{k+1} = x_k - \\frac{f(x_k)}{f'(x_k)}\n    \\end{equation}\n  \\end{minipage}\n  \\hfill\n  \\begin{minipage}{0.48\\textwidth}\n    \\begin{figure}[ht]\n      \\centering\n      \\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{newton-raphson}\n      % \\caption{\\label{fig:label} }\n    \\end{figure}\n  \\end{minipage}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{The Babylonian method}\n  \\begin{itemize}\n    \\item \\textcolor{blue}{compute square root} of $R \\in \\R_+$\n    \\item find zero of $f(x) = x^2 - R$\n    \\item use Newton-Raphson:\n          \\begin{equation}\n            x_{k+1} = x_k - \\frac{f(x_k)}{f'(x_k)} = x_k - \\frac{x_k^2 - R}{2 x_k} = \\frac12 \\left( x_k + \\frac{R}{x_k} \\right)\n          \\end{equation}\n    \\item Starting from $x_0 > 0$ we have\n          \\begin{equation}\n            x_{k+1} = \\frac12 \\left( x_k + \\frac{R}{x_k} \\right) \\ge \\frac{x_k}{2}.\n          \\end{equation}\n    \\item Starting from $x_0 = R \\ge 1$, it takes $\\mathcal{O}(\\log R)$ steps to get to $x_k - \\sqrt{R} < \\frac12$.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{The Babylonian method - Takeoff}\n  \\onslide<1>{%\n    Note that\n    \\begin{equation}\n      x_{k+1} - \\sqrt{R} = \\frac12 \\left( x_k + \\frac{R}{x_k} \\right) - \\sqrt{R} = \\frac{x_k}{2} + \\frac{R}{2 x_k} - \\sqrt{R} = \\frac{1}{2 x_k} {\\left( x_k - \\sqrt{R} \\right)}^2\n    \\end{equation}\n    For simplicity $R \\ge 1/4$, then $x_k \\ge \\sqrt{R} \\ge 1/2$. Hence\n    \\begin{equation}\n      x_{k+1} - \\sqrt{R} = \\frac{1}{2 x_k} {\\left( x_k - \\sqrt{R} \\right)}^2 \\le {\\left( x_k - \\sqrt{R} \\right)}^2\n    \\end{equation}\n  }\n\n  \\onslide<2->{%\n    If $x_0 - \\sqrt{R} < \\frac12$ (ensured after $\\mathcal{O}(\\log R)$ steps).\n    \\begin{equation}\n      x_{k} - \\sqrt{R} \\le {\\left( x_0 - \\sqrt{R} \\right)}^{2^k} \\le {\\left(\\frac12\\right)}^{2^k}\n    \\end{equation}\n    To achieve $x_k - \\sqrt{R} < \\epsilon$ we only need $k = \\log \\log (\\epsilon^{-1})$ steps!\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{The Babylonian method - Example}\n  $R=1000$, in double arithmetic\n  \\begin{itemize}\n    \\item $7$ steps to get to $x_7 - \\sqrt{1000} < 1/2$\n          \\item $3$ steps to get to $\\sqrt{1000}$ up to \\textit{machine precision}\n          \\item First phase: $\\approx$ \\textcolor{blue}{one more correct digit} per iteration\n          \\item Second phase: $\\approx$ \\textcolor{blue}{double the number of correct digits} per iteration\n  \\end{itemize}\n\n  \\begin{center}\n    In practice: $\\log \\log x \\le 5$.\n  \\end{center}\n\n\\end{frame}\n\n\n\\section{Newton's method}%\n\n\\begin{frame}\n  \\frametitle{Newton's method for optimization}\n  \\begin{itemize}\n    \\item \\textcolor{blue}{Goal:} Find global minimum $x^*$ of convex, differentiable function $f$.\n    \\item \\textcolor{blue}{Strategy:} Search for zero of derivative.\n    \\item \\textbf{$1$-dimensional case:} Apply Newton-Raphson method to $f'$:\n          \\begin{equation}\n            x_{k+1} = x_k - \\frac{f'(x_k)}{f''(x_k)} = x_k - {f''(x_k)}^{-1} f(x_k)\n          \\end{equation}\n          (requires \\textcolor{blue}{twice} differentiable and $f'' > 0$)\n\n    \\item \\textbf{$d$-dimensional case:} Newtons methods for minimizing convex $f: \\R^d \\to \\R$:\n          \\begin{equation}\n            x_{k+1} = x_k - \\nabla^2 f(x_k) \\nabla f(x_k).\n          \\end{equation}\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Newton's method as adaptive gradient descent}\n  General update scheme:\n  \\begin{equation}\n    x_{k+1} = x_k - H(x_k) \\nabla f(x_k)\n  \\end{equation}\n  for some matrix $H(x) \\in \\R^{d \\times d}$.\n  \\begin{itemize}\n    \\item \\textcolor{blue}{Newton's method}: $H = {\\nabla^2 f(x_k)}^{-1}$.\n    \\item \\textcolor{blue}{Gradient descent}: $H = \\alpha \\Id$\n  \\end{itemize}\n  \\vspace{1cm}\n \\begin{block}{}\n  Newton's methods \\textbf{adapts} to the local geometry of $f$ at $x_k$ \\\\\n \\end{block}\n  $\\rightarrow$ \\textit{no need for choosing a stepsize}.\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Convergence in one step on quadratic functions}\n  A \\textcolor{blue}{quadratic} function\n  \\begin{equation}\n    f(x) = \\frac12 x^T M x + q^T x + c\n  \\end{equation}\n  is called \\textit{nondegenerate} if $M \\in \\R^{d \\times d}$ is invertible.\n  \\begin{itemize}\n    \\item $x^* := M^{-1}q$ is the unique solution of $\\nabla f(x) = 0$\n    \\item $x^*$ is the unique global minimum if $f$ is convex\n  \\end{itemize}\n  \\begin{lemma}%\n    On nondegenerate quadratic functions with arbitrary starting point $x_0$, Newtons method yields $x_1=x^*$\n  \\end{lemma}\n  \\begin{proof}\n    We have $\\nabla f(x) = Mx -q$ and $\\nabla^2 f(x) = M$. Therefore\n    \\begin{equation}\n      x_1 = x_0 - \\nabla^2 f(x_0) \\nabla f(x_0) = x_0 - M^{-1}(M x_0 - q) = M^{-1}q = x^*. \\qed\\qedhere\n    \\end{equation}\n  \\end{proof}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Affine Invariance}\n  Newton’s method is \\textcolor{blue}{affine invariant}\n  (invariant under any invertible affine transformation):\n  Denote the Newton step for $h$ by\n  \\begin{equation}\n    N_h(x) := x - {\\nabla^2 h }^{-1} \\nabla h(x).\n  \\end{equation}\n  \\begin{lemma}%\n    Let $f: \\R^d \\to \\R$ be twice differentiable, $A \\in \\R^{d \\times d}$ an invertible matrix and $b \\in \\R^d$.\n    \\begin{equation}\n      g(x) = Ax + b.\n    \\end{equation}\n    Then\n    \\begin{equation}\n      N_{f \\circ g} = g^{-1} \\circ N_f \\circ g\n    \\end{equation}\n  \\end{lemma}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{}\n  \\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{newton_aff_invariance}\n    % \\caption{\\label{fig:label} }\n  \\end{figure}\n  Gradient descent suffers if coordinates are at different scales; Newton's method doesn't.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Minimizing the second-order Taylor approximation}\n  Alternative interpretation of Newton's method:\n  Minimize (local) \\textcolor{blue}{quadratic model} of $f$.\n  \\begin{lemma}%\n    Let $f$ be conve, twice differentiable and $\\nabla^2 f(x) \\succ 0$. Then $x_{k+1}$ resulting from \\textbf{Newton's step} satisfies\n    \\begin{equation}\n      x_{k+1} = \\argmin_{x \\in \\R^d} f(x_k) + \\langle \\nabla f(x_k), x-x_k \\rangle + \\frac12 \\langle x-x_k, \\nabla^2 f(x_k) (x-x_k)  \\rangle\n    \\end{equation}\n  \\end{lemma}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Local Convergence}\n  We will prove:\\\\\n  Under suitable conditions on $f$ and \\textcolor{blue}{close to the minimum} Newton's method approximates solution up to an error $\\epsilon$ in \\textcolor{blue}{$\\log \\log (1/\\epsilon)$} iterations.\n  \\begin{itemize}\n    \\item much faster than anything so far..\n    \\item only locally\n  \\end{itemize}\n  We call this a \\textcolor{blue}{local convergence} result.\\\\\n\n  \\textcolor{blue}{Global convergence} statements are more difficult to obtain (some only recently).\n\\end{frame}\n\n\n\\section{Convergence analysis}%\n\n\\begin{frame}\n  \\frametitle{Theorem + Technical conditions }\n  \\begin{theorem}\n    Let $f$ be convex with unique global minimum $x^*$, and $X$ a ball around $x^*$ s.t.\n    \\begin{enumerate}\n      \\item \\textcolor{blue}{Bounded inverse Hessians:} There exists $\\mu > 0$\n            \\begin{equation}\n              \\Vert {\\nabla^2 f(x)}^{-1} \\Vert \\le \\frac{1}{\\mu}, \\quad \\forall x \\in X\n            \\end{equation}\n      \\item \\textcolor{blue}{Lipschitz continuous Hessians:} There exists $B>0$\n            \\begin{equation}\n              \\Vert \\nabla^2 f(x) - \\nabla^2 f(y) \\Vert \\le B \\Vert x-y \\Vert, \\quad \\forall x,y \\in X\n            \\end{equation}\n    \\end{enumerate}\n    Then, for $x_{k+1} = N_f(x_k)$ we have\n    \\begin{equation}\n      \\Vert x_{k+1} -x^* \\Vert \\le \\frac{B}{2 \\mu} \\Vert x_k - x^* \\Vert^2\n    \\end{equation}\n  \\end{theorem}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Super-exponential speed}\n  \\begin{corollary}%\n    In the setting of previous theorem, if\n    \\begin{equation}\n      \\Vert x_k - x^* \\Vert \\le \\frac{\\mu}{B},\n    \\end{equation}\n    then\n    \\begin{equation}\n      \\Vert x_k -x^*  \\Vert \\le \\frac{\\mu}{B} {\\left( \\frac{1}{2} \\right)}^{2^k-1}\n    \\end{equation}\n  \\end{corollary}\n  Close to the global minimum, we will reach distance to the minumum less than $\\epsilon$ in at most $\\log \\log (1/\\epsilon)$ steps.\n\n  As for the last phase of Babylonian method.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Super-exponential speed - intuition}\n\n  \\begin{itemize}\n    \\item Almost constant Hessians close to optimality...\n    \\item so $f$ behaves almost like a quadratic\n    \\item on which Newton's converge in one step\n  \\end{itemize}\n\n  \\begin{lemma}%\n    If\n    \\begin{equation}\n      \\Vert x_0 - x^* \\Vert \\le \\frac{\\mu}{B}\n    \\end{equation}\n    the Hessians in Newton's method satisfy the \\textcolor{blue}{relative error bound}\n    \\begin{equation}\n      \\frac{\\Vert  \\nabla^2 f(x_k) - \\nabla^2 f(x^*) \\Vert}{\\Vert \\nabla^2 f(x^*) \\Vert} \\le {\\left( \\frac12 \\right)}^{2^k-1}.\n    \\end{equation}\n  \\end{lemma}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Proof of convergence theorem}\n  We abbreviate $H = \\nabla^2 f(x_k)$, $x=x_k$, $x^+ = x_{k+1}$\n  \\begin{equation}\n    \\begin{aligned}\n      x^+ - x^* &= x - x^* - H^{-1} \\nabla f(x) \\\\\n      &= x - x^* + H^{-1}( \\nabla f(x^*) - \\nabla f(x)) \\\\\n      &= x - x^* + H^{-1} \\int_{0}^{1} H(x + t(x^* - x))(x^* - x) \\diff t,\n    \\end{aligned}\n  \\end{equation}\n  \\onslide<2->{%\n    where we used the fundamental theorem of calculus\n    \\begin{equation}\n      \\int_{a}^{b} h' (t) \\diff t\n    \\end{equation}\n    with\n    \\begin{align}\n      h(t)  &= \\nabla f(x + t(x^* -x )) \\\\\n      h'(t) &= \\nabla^2f (x + t(x^* -x ))(x^*-x).\n    \\end{align}\n  }\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Proof of convergence theorem II}\n  So far\n  \\begin{equation}\n      x^+ - x^* = x - x^* + H^{-1} \\int_{0}^{1} H(x + t(x^* - x))(x^* - x) \\diff t\n  \\end{equation}\n  With\n  \\begin{equation}\n    x- x^* = {H(x)}^{-1} \\int_{0}^{1} - H(x)(x^*-x)\n  \\end{equation}\n  we get\n  \\begin{equation}\n    x^+ - x^* =  H^{-1} \\int_{0}^{1} (H(x + t(x^* - x))- H(x))(x^* - x) \\diff t.\n  \\end{equation}\n  Using norms\n  \\begin{equation}\n    \\Vert x^+ - x^*  \\Vert \\le  \\Vert H^{-1} \\Vert \\left\\Vert  \\int_{0}^{1} H(x + t(x^* - x))- H(x)(x^* - x) \\diff t \\right\\Vert\n  \\end{equation}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Proof of convergence theorem III}\n\n  \\begin{align}\n    \\Vert x^+ - x^*  \\Vert &=  \\Vert H^{-1} \\Vert \\left\\Vert  \\int_{0}^{1} (H(x + t(x^* - x))- H(x))(x^* - x) \\diff t \\right\\Vert \\\\\n    &\\le \\Vert H^{-1} \\Vert  \\Vert x^* - x \\Vert \\int_{0}^{1} \\left\\Vert  (H(x + t(x^* - x))- H(x)) \\right\\Vert \\diff t\n  \\end{align}\n  Use \\textbf{bounded inverse Hessians} and \\textbf{Lipschitz continuity} of the Hessian to conclude\n  \\begin{align}\n    \\Vert x^+ - x^*  \\Vert  &\\le \\frac{1}{\\mu} \\Vert x^* - x \\Vert \\int_{0}^{1} B \\Vert t(x^*-x) \\Vert \\diff t  \\\\\n    &= \\frac{B}{\\mu} \\Vert x^*-x \\Vert^2 \\int_{0}^{1}t \\diff t = \\frac{B}{2\\mu} \\Vert x-x^* \\Vert^2. \\qed\n  \\end{align}\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Strong convexity $\\Rightarrow$ Bounded inverse Hessians}\n\n  \\begin{itemize}\n    \\item How to ensure bounded inverse Hessians?\n  \\end{itemize}\n\n  \\begin{lemma}%\n    Let $f: \\R^d \\to \\R$ be $C^2$ and \\textbf{strongly convex} with parameter $\\mu$, i.e.\\\n    \\begin{equation}\n      f(y) \\ge f(x) \\langle \\nabla f(x), y-x \\rangle + \\frac{\\mu}{2} \\Vert y-x \\Vert^2, \\quad \\forall x,y.\n    \\end{equation}\n  Then, $\\nabla^2 f(x)$ is invertible and $\\Vert \\nabla^2 f(x) \\Vert^{-1} \\le 1/\\mu$ for all $x$.\n  \\end{lemma}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Downside of Newton's method}\n  \\textcolor{blue}{Computational bottleneck} in every step:\n  \\begin{itemize}\n    \\item compute Hessian\n    \\item invert Hessian or solve $\\nabla^2 f(x_k) \\Delta x = - \\nabla f(x_k)$\n  \\end{itemize}\n  \\vspace{1cm}\n  Matrix has size $d\\times d$, taking $\\mathcal{O}(d^3)$ to invert.\\\\\n  In many applications the dimension $d$ is large (too large to even store Hessian).\n\n  \\vspace{1cm}\n  When training a ML model $d$ is the \\textit{number or parameters} of our ML model (number of features for linear model).\n\\end{frame}\n\n\n\\section{Quasi-Newton methods}%\n\n\\begin{frame}\n  \\frametitle{The secant method}\n  Another iterative method for finding zeros in $1$-d.\n  Recall Newton-Raphson:\n  \\begin{equation}\n    x_{k+1} = x_k - \\frac{f(x_k)}{f'(x_k)}\n  \\end{equation}\n  Use \\textcolor{blue}{finite difference approximation} of $f'(x_k)$:\n  \\begin{equation}\n    f'(x_k) \\approx \\frac{f(x_k) - f(x_{k-1})}{x_k - x_{k-1}}.\n  \\end{equation}\n  We obtain the \\textcolor{blue}{\\textbf{secant method}}:\n  \\begin{equation}\n    x_{k+1} = x_k - f(x_k) \\frac{x_k - x_{k-1}}{f(x_k) - f(x_{k-1})}.\n  \\end{equation}\n\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{The secant method II}\n  \\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth,keepaspectratio]{secant_method}\n  \\end{figure}\n  Constructs the line through $(x_{k-1}, f(x_{k-1}))$ and $(x_k, f(x_k))$.\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{The secant method III}\n  \\begin{itemize}\n    \\item is a \\emph{derivative-free} version of the Newton-Raphson method.\n    \\item \\textcolor{blue}{For optimization}: Apply secant method to $f'$ to optimize $f$:\n          \\begin{equation}\n            x_{k+1} = x_k - f'(x_k) \\frac{x_k - x_{k-1}}{f'(x_k) - f'(x_{k-1})}.\n          \\end{equation}\n    \\item yields a \\textcolor{blue}{second-derivative free} version of Newton's method.\n  \\end{itemize}\n\n  \\vspace{1cm}\n\n  \\onslide<2->{%\n    \\begin{center}\n      \\textit{What abouthigher dimensions? Can't divide vectors..}\n    \\end{center}\n  }\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{The secant condition}\n  In $1$-d:\n  \\begin{align}\n    H_k &:= \\frac{f'(x_k) - f'(x_{k-1})}{x_k - x_{k-1}} \\approx f''(x_k) \\\\\n    &\\Leftrightarrow f'(x_k) - f'(x_{k-1}) = H_k (x_k - x_{k-1}),\n  \\end{align}\n  the \\textcolor{blue}{secant condition}.\n  \\begin{itemize}\n    \\item Newton's method: $x_{k+1} = x_k - {f''(x_k)}^{-1} f'(x_k)$\n    \\item Secant method: $x_{k+1} = x_k - {H_k}^{-1} f'(x_k)$\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Quasi-Newton methods}\n\n  \\begin{equation}\n    \\nabla f(x_k) - \\nabla f(x_{k-1}) = H_k (x_k - x_{k-1}) \\approx \\nabla^2 f(x_k) (x_k - x_{k-1})\n  \\end{equation}\n  We therefore hope that $H_k \\approx \\nabla^2 f(x_k)$.\n\n  \\begin{equation}\n    \\text{Secant:} \\quad x_{k+1} = x_k = H_k^{-1} \\nabla f(x_k)\n  \\end{equation}\n\n  \\begin{itemize}\n    \\item $d=1$: unique number $H_k$ satisfying the secant condition\n    \\item $d>0$: secant condition $\\nabla f(x_k) - \\nabla f(x_{k-1}) = H_k (x_k - x_{k-1})$ has \\textbf{infinitely} many \\textit{symmetric} solutions\n  \\end{itemize}\n\n  \\begin{block}{}\n    \\textit{Any scheme of choosing in each step of the secant method a symmetric $H_k$ that satisfies the secant condition defines a \\textcolor{blue}{Quasi-Newton method}.}\n  \\end{block}\n\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Quasi-Newton methods II}\n\n  \\begin{itemize}\n    \\item Newton’s method is a Quasi-Newton method if and only if f is a nondegenerate \\textbf{quadratic} function.\n    \\item Hence, Quasi-Newton methods \\textit{do not generalize} Newton’s method but form a\n          family of \\textit{related} algorithms.\n    \\item First Quasi-Newton method by William Davidon in 1956\n    \\item But the paper got rejected for lacking a convergence analysis,\n    \\item was finally officially published in 1991\n    \\item \\textcolor{blue}{methods of choice} in a number of relevant machine learning applications\n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Developing a Quasi-Newton method}\n  \\begin{itemize}\n    \\item We want to avoid matrix inversion\n          $\\Rightarrow$ directly deal with the inverse $H_k^{-1}$\n    \\item \\textcolor{blue}{Given:} iterates $x_{k-1}, x_k$ and matrix $H_{k-1}^{-1}$\n    \\item \\textcolor{blue}{Seeking:} next matrix $H_k^{-1}$ needed in next Quasi-Newton step\n          \\begin{equation}\n            x_{k+1} = x_k = H_k^{-1} \\nabla f(x_k)\n          \\end{equation}\n    \\item How to choose $H_k^{-1}$?\n    \\item Newton’s method: $\\nabla^2 f(x_k)$ fluctuates only very little in the region of very fast convergence.\n    \\item Makes sense to have $H_k \\approx H_{k-1}$ or $H_k^{-1} \\approx H_{k-1}^{-1}$\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Greenstadt's family of Quasi-Newton methods}\n  Greenstadt [Gre70]: Update\n  \\begin{equation}\n    H_k^{-1} = H_{k-1}^{-1} + E_k,\n  \\end{equation}\n  with $E_k$ an error matrix.\n  \\begin{itemize}\n    \\item Try to \\textcolor{blue}{minimize error} subject to $H_k$ satisfying the \\textbf{secant condition}!\n  \\end{itemize}\n\n  Simple error measure: Frobenius norm\n  \\begin{equation}\n    \\Vert E \\Vert_F^2 := \\sum_{i=1}^{d} \\sum_{j=1}^{d} E_{ij}^2\n  \\end{equation}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{BFGS method}\n  \\begin{itemize}\n    \\item special version of Greenstadt\n    \\item is named after Broyden, Fletcher, Goldfarb and Shanno\n          who all came up with it independently around 1970. Greenstadt’s name is\n          mostly forgotten.\n    \\item Newton’s method needs to compute and invert\n          Hessians $\\rightarrow$ cost of $\\mathcal{O}(d^3)$ per iteration\n    \\item Any method in Greenstadt’s family avoids computation of Hessian.\n          \\textbf{Only gradients are needed}.\n    \\item In the BFGS method, the cost per iteration drops to $\\mathcal{O}(d^2)$.\n    \\item even this can be prohibitive $\\rightarrow$ limited memory BFGS\n    \\item uses observation that we do not need $H_{k}^{-1}$, only $H_{k}^{-1} \\nabla f(x_k)$\n  \\end{itemize}\n\n\\end{frame}\n\\end{document}\n", "meta": {"hexsha": "d015832fb3f69c0cf18bb1cf1ca0f0b41d5f201b", "size": 17977, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Newtons-method/Newtons_method.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": "slides/Newtons-method/Newtons_method.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": "slides/Newtons-method/Newtons_method.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": 33.8549905838, "max_line_length": 199, "alphanum_fraction": 0.6230183012, "num_tokens": 6529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6187184327062375}}
{"text": "\\section{The Generic MST Algorithm}\t\\label{section:mst-generic-alg}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The Generic MST Algorithm}\n  \\begin{description}\n\t\\setlength{\\itemsep}{5pt}\n\t\\item<1->[Overview:] Grow the MST one edge at a time\n\t\\item<2->[State:] Manage a set of edges $X$\n\t\\item<3->[\\textcolor{red}{\\bf Invariant:}] $X$ is a subset of some MST\n\t\\item<4->[Init:] $X = \\emptyset$\n\t\\item<5->[Iteration:] Find \\only<5>{an edge}\\only<6->{a \\textcolor{red}{\\bf safe} edge} $e$ {\\it s.t.} \n\t  \\\\ $X \\cup \\set{e}$ is also a subset of some MST\n\t\\item<7->[Termination:] $(n-1)$ iterations\n  \\end{description}\n\n  \\vspace{0.20cm}\n  \\uncover<8->{\n\t\\begin{center}\n\t  \\textcolor{brown}{\\large How to find a safe $e$ for $X$ in each iteration?}\n\t\\end{center}\n  }\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The Cut Property}\n\tGiven that $X$ is part of some MST $T$:\n\t\\vspace{0.10cm}\n    \\begin{itemize}\n\t  \\setlength{\\itemsep}{3pt}\n      \\item<2-> A cut $(S, V \\setminus S)$ \\textcolor{red}{\\bf respecting} $X$ ($X$ does not cross $(S, V \\setminus S)$)\n\t  \\item<6-> $e$: a lightest edge across $(S, V \\setminus S)$\n\t\\end{itemize}\n\t\\vspace{0.10cm}\n\tThen, $X + \\set{e}$ is also a part of some MST $T'$.\n\n  \\importikznocaption{0.50\\textwidth}{0.50\\textwidth}{tikz-in-beamer/cut-property-example-overlay.tex}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{The Cut Property}\n  \\begin{enumerate}\n\t\\item<1-> $X \\subseteq T, \\textcolor{blue}{e \\in T} \\Rightarrow X + \\set{e} \\subseteq T$\n\t\\item<2-> $X \\subseteq T, \\textcolor{red}{e \\notin T} \\Rightarrow X + \\set{e} \\subseteq T'$.\n  \\end{enumerate}\n\n  \\vspace{-0.30cm}\n\n  \\importikznocaption{0.35\\textwidth}{0.35\\textwidth}{tikz-in-beamer/cut-property-proof-clrs-overlay.tex}\n\n  \\begin{itemize}\n\t\\item<5-> $T + \\set{e} \\Longrightarrow$ cycle $C$ ($uv + P_{u \\leadsto v}$)\n\t\\item<6-> $\\exists e' \\in P_{u \\leadsto v} \\colon e'$ across the cut; $w(e') \\geq w(e)$\n    \\item<7-> $T' = T + \\set{e} - \\set{e'}$ is an ST\n    \\item<8-> $w(T') \\le w(T) \\Rightarrow T' \\textrm{ is an MST}$\n\t\\item<9-> $e' \\notin X {\\scriptsize (\\textcolor{red}{\\bf respect})} \\Rightarrow X + \\set{e} \\subseteq T'$\n  \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "6adc45cf24807d02d37c4daeb74a3bf5d669ed69", "size": 2173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "algorithm-lecture-mst/sections/mst-generic-alg.tex", "max_stars_repo_name": "hengxin/algorithm-lectures", "max_stars_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-20T06:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-12T19:07:16.000Z", "max_issues_repo_path": "algorithm-lecture-mst/sections/mst-generic-alg.tex", "max_issues_repo_name": "hengxin/algorithm-lectures", "max_issues_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_issues_repo_licenses": ["MIT"], "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-lecture-mst/sections/mst-generic-alg.tex", "max_forks_repo_name": "hengxin/algorithm-lectures", "max_forks_repo_head_hexsha": "cf00b0d2d88da6e20d37c36d1f49ca6c1a0669ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-12T10:36:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-12T10:36:11.000Z", "avg_line_length": 38.1228070175, "max_line_length": 120, "alphanum_fraction": 0.6111366774, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624840223698, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6187184229050032}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 2.5 Combining rules -- a solution}\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   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   # rules for covariant derivatives of v\n\n   deriv1 := \\nabla_{a}{v^{b}} -> \\partial_{a}{v^{b}}\n                                + \\Gamma^{b}_{d a} v^{d}.\n\n   deriv2 := \\nabla_{a}{\\nabla_{b}{v^{c}}} -> \\partial_{a}{\\nabla_{b}{v^{c}}}\n                                            + \\Gamma^{c}_{d a} \\nabla_{b}{v^{d}}\n                                            - \\Gamma^{d}_{b a} \\nabla_{d}{v^{c}}.\n\n   # second covariant derivative of v\n\n   expr := v^{c}_{b a} -> \\nabla_{a}{\\nabla_{b}{v^{c}}}.  # cdb (ex-0205.101,expr)\n   save := @(expr).\n\n   # apply the rules, then simplify\n\n   substitute     (expr,deriv2)       # cdb (ex-0205.102,expr)\n   substitute     (expr,deriv1)       # cdb (ex-0205.103,expr)\n   distribute     (expr)              # cdb (ex-0205.104,expr)\n   product_rule   (expr)              # cdb (ex-0205.105,expr)\n   canonicalise   (expr)              # cdb (ex-0205.107,expr)\n   substitute     (expr,save)         # cdb (ex-0205.108,expr)\n\\end{cadabra}\n\nThe trick here is to introduce in line 17 a dummy left hand side, \\verb|v^{c}{}_{b a}|,\nthat is invisible with respect to the substitution rules of lines 8 and 11. Thus lines 22\nand 23 will only target the right hand side of \\verb|expr|.\n\nNotice how a copy of the initial expression is made in 18. This is used later in line 27 to\nreplace the dummy object \\verb|v^{c}{}_{b a}| with \\verb|\\nabla_{a}{\\nabla_{b}{v^{c}}}|\nbut this time acting on the left hand side of the rule. The result is a rule for second\ncovariant deriavtives.\n\n\\clearpage\n\n\\begin{align*}\n   & \\Cdb{ex-0205.101} \\\\\n   & \\Cdb{ex-0205.102} \\\\\n   & \\Cdb{ex-0205.103} \\\\\n   & \\Cdb{ex-0205.104} \\\\\n   & \\Cdb{ex-0205.105} \\\\\n   & \\Cdb{ex-0205.107} \\\\\n   & \\Cdb{ex-0205.108}\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "e9866659bbf33ea4a343e2ada41504b12d8e241a", "size": 2161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0205.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-0205.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-0205.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": 34.3015873016, "max_line_length": 94, "alphanum_fraction": 0.5539102267, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6187184188974634}}
{"text": "\\section{Translation}\n\\label{sec:translation}\n\n\\iflong\nHaving shown the input and output languages for RZ,\nwe now explain how the translation from one to the other works.\nA theory is translated to a\nspecification, where the theory elements are translated as follows.\n\\fi % \\iflong\n\n\n\\subsection{Translation of sets and terms}\n\\label{sec:transl-sets-terms}\n\nA set declaration $\\iParameter{s}{\\iSet}$ is translated to\n%\n\\begin{source}\ntype s\npredicate (\\iPer{s}) : s \\iTo s \\iTo bool\nassertion symmetric_s :  \\iForall x:s, y:s, x \\iPer{s} y \\iTo y \\iPer{s} x\nassertion transitive_s : \\iForall x:s, y:s, z:s, x \\iPer{s} y \\iAnd y \\iPer{s} z \\iTo x \\iPer{s} z\npredicate \\iT{s} : s \\iTo bool\nassertion support_def_s :  \\iForall x:s,  x : \\iT{s} \\iIff x \\iPer{s} x\n\\end{source}\n%\nThis says that the programmer should define a type~$s$ and a per\n$\\per_s$ on~$\\values{s}$. Here~$\\per_s$ is \\emph{not} an OCaml value\nof type $s \\to s \\to \\mathtt{bool}$, but an abstract relation on the\nset $\\values{s} \\times \\values{s}$.  The relation may be uncomputable.\n\n\\iflong\nThe translation of the declaration of a dependent set\n$\\iParameter{\\f{t}}{\\f{s} \\to \\iSet}$ follows the interpretation of dependent\nsets as uniform families (Section~\\ref{sec:uniform-families}):\n%\n\\begin{source}\ntype t\npredicate \\iPer{t} : s \\iTo t \\iTo t \\iTo bool\nassertion strict_t :  \\iForall x:s, y:t, z:t, y \\iPer{t x} z \\iTo x : \\iT{s}\nassertion extensional_t :\n  \\iForall x:s, y:s, z:t, w:t, x \\iPer{s} y \\iTo z \\iPer{t x} w \\iTo z \\iPer{t y} w\nassertion symmetric_t : \\iForall x:s, y:t, z:t, y \\iPer{t x} z \\iTo z \\iPer{t x} y\nassertion transitive_t :\n  \\iForall x:s, y:t, z:t, w:t, y \\iPer{t x} z \\iAnd z \\iPer{t x} w \\iTo y \\iPer{t x} w\npredicate \\iT{t} : s \\iTo t \\iTo bool\nassertion support_def_t :  \\iForall x:s, y:t, y : \\iT{t x} \\iIff y \\iPer{t x} y\n\\end{source}\n%\nThe underlying output type~$\\f{t}$ is still non-dependent, but the per is\nparameterized by~$\\f{s}$.\n\\else % \\iflong\nThe translation of the declaration of a dependent set\n$\\iParameter{\\f{t}}{\\f{s} \\to \\iSet}$ uses uniform families\n(Section~\\ref{sec:uniform-families}). The underlying type~$\\f{t}$ is\nnon-dependent, but the per $\\per_{\\f{t}}$ receives an additional\nparameter $\\f{x} : \\values{\\f{s}}$.\n\\fi % \\iflong\n\nA value declaration $\\iParameter{x}{s}$ is translated to\n%\n\\begin{source}\nval x : s\nassertion x_support : x : \\iT{s}\n\\end{source}\n%\nwhich requires the definition of a value~$\\f{x}$ of type~$\\f{s}$ which is in\nthe support of~$\\f{s}$.\n\\iflong\nWhen $\\f{s}$ is not a basic set, RZ computes the\ninterpretation of the underlying type and support.\n\\fi\n\nA value definition $\\iDefinition{\\f{x}}{e}$ where~$e$ is an expression\ndenoting an element of~$\\f{s}$ is translated to\n%\n\\newcommand{\\iE}{$e$}\n\\begin{source}\nval x : s\nassertion x_def : x \\iPer{s} \\iE\n\\end{source}\n%\nThe assertion does \\emph{not} force~$\\f{x}$ to be defined as~$e$, only\nto be equivalent to it with respect to~$\\per_{\\f{s}}$. This is\nuseful, as often the clearest or easiest ways to define a value are not the most\nefficient ways to compute it.\n\nConstructions of sets in the input language are translated to\ncorresponding constructions of modest sets.\n%\n\\iflong\nIn Section~\\ref{sec:modest-sets-pers} we saw how products,\nexponentials and their dependent versions are formed. We briefly\nreview the remaining constructions of modest sets. We only consider\nthose constructions of terms that are not entirely straightforward.\n%\n\\else\n%\nWe comment on those that are least familiar.\n%\n\\fi\n\n\\iflong\n\\paragraph{Disjoint union.}\n%\nA disjoint union of modest sets $\\isum{\\il_1}{A}{\\il_2}{B}$ is the\nmodest set whose underlying type is the sum of underlying types,\n%\n\\begin{equation*}\n  \\typeOf{\\isum{\\il_1}{A}{\\il_2}{B}} =\n  \\osumtyx{\\il_1}{\\typeOf{A}}{\\il_2}{\\typeOf{B}},\n\\end{equation*}\n%\nand the per is the disjoint union of pers $\\per_{A}$ and $\\per_{B}$, so\nthat we have\n%\n\\begin{align*}\n  \\oper{\\isum{\\il_1}{A}{\\il_2}{B}}{\\oinj{\\il_1}{u}}{\\oinj{\\il_1}{v}}\n  &\\iff \\oper{s_1}{u}{v},\n  \\\\\n  \\oper{\\isum{\\il_1}{A}{\\il_2}{B}}{\\oinj{\\il_2}{u}}{\\oinj{\\il_2}{v}}\n  &\\iff \\oper{s_2}{u}{v}.\n\\end{align*}\n\\fi % \\iflong\n\n\\paragraph{Subsets.}\n%\n\\iflong\n%\nThe construction of subsets may look surprising at first, but\nit makes sense computationally.\n\\fi\nGiven a predicate~$\\phi$ on a per~$A$, the sub-per $\\set{x : A\n  \\such \\phi}$ has underlying type $\\typeOf{A} \\times \\typeOf{\\phi}$\nwhere $(u_1,v_1) \\per_{\\set{x : A \\such \\phi}} (u_2,v_2)$ when $u_1\n\\per_A u_2$, $v_1 \\rz \\phi(u_1)$ and $v_2 \\rz \\phi(u_2)$. The point is\nthat a realizer for an element of $\\set{x : A\n  \\such \\phi}$ carries information about \\emph{why} the element\nbelongs to the subset, just like a predicate $\\phi$ carries\ninformation of type $\\typeOf{\\phi}$ about why a particular instance of~$\\phi$ holds.\n\nA type coercion $\\icoerce{e}{t}$ can convert an element of the subset $s =\n\\set{x : t \\such \\phi(x)}$ to an element of~$t$. At the level of\nrealizers this is achieved by the first projection, which keeps a\nrealizer for the element but forgets the one for~$\\phi(e)$. The\nopposite type coercion $\\icoerce{e'}{s}$ takes an $e' \\in t$ and converts it\nto an element of the subset. This is only well-formed when $\\phi(e')$\nis valid. Then, if $u \\rz_t e'$ and $v \\rz \\phi(e')$, a realizer for\n$\\icoerce{e'}{s}$ is $(u, v)$. However, since RZ cannot in general know\na~$v$ which validates~$\\phi(e')$, it emits the pair $(u,\n(\\ooblig{v}{\\typeOf{\\phi}}{\\oapp{\\oapp{\\phi}{u}}{v}}{v}))$.\n\n\\paragraph{Quotients.}\n%\n\\iflong\n%\nThe category of modest sets has coequalizers, hence a quotient modest\nset $A/\\rho$ may be constructed for an any equivalence relation~$\\rho$\non~$A$. However, because equality does not carry any computational\ncontent, equality of equivalence classes $\\ieclass{x}{\\rho} =\n\\ieclass{y}{\\rho}$ implies only $\\inot{\\inot{\\rho(x,y)}}$, not the\nusual~$\\rho(x,y)$. As this may cause confusion\nand mistakes, it is better to permit only quotients by \\emph{stable}\nequivalence relations, which behave as expected.\n\n%\n\\else\n%\nEven though we may form quotients of pers by arbitrary equivalence\nrelations, only quotients by $\\lnot\\lnot$-stable relations behave as\nexpected.\\footnote{The trouble is that from equality of equivalence\n  classes $[x]_{\\rho} = [y]_{\\rho}$ we may conclude only\n  $\\lnot\\lnot\\rho(x,y)$ rather than the expected $\\rho(x,y)$.}\n%\n\\fi\nA stable equivalence relation on a per~$A$ is the same thing as a\npartial equivalence relation~$\\rho$ on~$\\typeOf{A}$ which satisfies\n$x \\per_A y \\implies \\rho(x,y)$. Then the quotient $A/\\rho$ is the per\nwith $\\typeOf{A/\\rho} = \\typeOf{A}$ and $x \\per_{A/\\rho} y \\iff\n\\rho(x,y)$.\n\nLuckily, it seems that many equivalence relations occurring in\ncomputable mathematics are stable, or can be made stable.\n%\n\\iflong For example, Cauchy sequences (of rational numbers)\n$(a_n)_{n\\in\\NN}$ and $(b_n)_{n\\in\\NN}$ represent the same real number\nwhen\n%\n\\begin{equation}\n  \\label{eq:cauchy}%\n  \\xall{i}{\\NN}{\n    \\xsome{j}{\\NN}{\n      \\forall m,n \\geq j.\\,|a_m - b_n| \\leq 2^{-i}\n    }\n  } \\;.\n\\end{equation}\n%\nThis defines an equivalence relation on the set of Cauchy sequences\nwhich does not seem to be stable; intuitively a realizer for this\nequivalence would be a computation telling us at what point\nin the sequence the terms will be within~$2^{-i}$ of each other.\n%\nHowever, if we restrict attention just to the \\emph{rapid} Cauchy\nsequences, i.e., those satisfying $\\xall{i}{\\NN}{|a_{i+1} - a_i| \\leq\n  2^{-i}}$, then the equivalence relation becomes\n%\n\\begin{equation*}\n  \\xall{i}{\\NN}{|a_i - b_i| \\leq 2^{-i+3}},\n\\end{equation*}\n%\nwhich is a negative formula; the above realizer is rendered\nunnecessary.\n%\n\\else % iflong\n%\nFor example, the coincidence relation on Cauchy sequences is expressed\nby a $\\forall\\exists\\forall$~formula, but if we consider \\emph{rapid}\nCauchy sequences (those sequences $a$ satisfying\n$\\xall{i}{\\NN}{|a_{i+1} - a_i| \\leq 2^{-i}}$), it becomes a (negative)\n$\\forall$~formula.\n%\n\\fi % iflong\nIt is interesting that most practical implementations of\nreal numbers follow this line of reasoning and represent real numbers in a\nway that avoids annotating every sequence with its rate of convergence.\n\nTranslation of an equivalence class $\\ieclass{e}{\\rho}$ is quite\nsimple, since a realizer for~$e$ also realizes its equivalence class\n$\\ieclass{e}{\\rho}$. The elimination term\n$\\ileteclass{x}{\\rho}{\\xi}{e}$, means ``let $x$ be any element of\n$\\rho$-equivalence class $\\xi$ in~$e$''. It is only well-formed when\n$e$ does not depend on the choice of~$x$, but this is something RZ\ncannot check. Therefore, if $u$ realizes $\\xi$, RZ uses $u$ as a\nrealizer for~$x$ and emits an obligation saying that the choice of a\nrealizer for~$x$ does not affect~$e$.\n\n\\paragraph{The underlying set of realizers.}\n%\nAnother construction on a per~$A$ is the underlying\nper of realizers $\\irz{A}$, defined by\n%\n\\iflong\n\\begin{align*}\n  \\typeOf{\\irz{A}} &= \\typeOf{A} \\\\\n  u \\per_{\\irz{A}} v &\\iff u \\in \\support{A} \\land u = v,\n\\end{align*}\n%\n\\else  % \\iflong\n$\\typeOf{\\irz{A}} = \\typeOf{A}$ and \n$u \\per_{\\irz{A}} v u \\in \\support{A} \\land \\iff u = v$, \n\\fi % \\iflong\n%\nwhere by $u = v$ we mean observational equality of values~$u$ and~$v$.\n%\nAn element $r \\in \\irz{A}$ realizes a unique element $\\irz{r} \\in A$.\nThe elimination term $\\iletrz{x}{e_1}{e_2}$, which means ``let $x$ be\nany realizer for~$e_1$ in $e_2$'', is only well-formed if $e_2$ does\nnot depend on the choice of~$x$. This is an uncheckable condition,\nhence RZ emits a suitable obligation in the output, and uses for $x$\nthe same realizer as for~$e_1$.\n\nThe construction $\\irz{A}$ validates the Presentation Axiom (see\nSection~\\ref{sec:axiom-choice}). In the input language it gives us\naccess to realizers, which is useful because many constructions in\ncomputable mathematics, such as those in Type Two\nEffectivity~\\cite{Wei00}, are explicitly expressed in terms of\nrealizers.\n\n\\iflong\n\\paragraph{Definite description.}\n%\nRussell's definite description operator $\\ithe{x}{s}{\\phi(x)}$ denotes\nthe unique element of $\\isubset{x}{s}{\\phi(x)}$. In case such an~$x$\ndoes not exist, or if there are several, the term is not well formed.\nThe RZ translation essentially just asks the programmer to provide\nsuitable realizers for $x$ and for $\\phi(x)$, and to check uniqueness,\n%\n\\begin{equation*}\n  \\ooblig{x{:}s,b}{\\typeOf{\\phi}}{\n    (\\ototal{x}{s} \\land \\oapp{\\oapp{\\phi}{x}}{b} \\land\n    \\oforall{x'}{s}{\n      \\oforall{c}{\\typeOf{\\phi}}{\n        (\\oimply{\\oapp{\\oapp{\\phi}{x'}}{c}}{\\oper{s}{x}{x'}})\n      }\n    })\n    }{(x,b)}.\n\\end{equation*}\n%\nThis is the best RZ can do, since in general it can check neither\nthat~$x$ exists, nor that it is unique.\n\\fi\n\n\\subsection{Translation of propositions}\n\\label{sec:transl-prop}\n\nThe driving force behind the translation of logic is a theorem\n\\cite[4.4.10]{Troelstra:van-Dalen:88:1} that says that under the\nrealizability interpretation every formula~$\\phi$ is equivalent to one\nthat says, informally speaking, ``there exists~$u \\in \\typeOf{\\phi}$,\nsuch that $u$ realizes $\\phi$''. Furthermore, the formula ``$u$\nrealizes $\\phi$'' is computationally trivial. The translation of a\npredicate $\\phi$ then consists of its underlying type $\\typeOf{\\phi}$\nand the relation $u \\rz \\phi$, expressed as a negative formula.\n\nThus an axiom $\\iAxiom{\\f{A}}{\\phi}$ in the input is translated to\n%\n\\newcommand{\\iTypeOfPhi}{$|\\phi|$}\n\\newcommand{\\iPhi}{$\\phi$}\n\\begin{source}\nval u : \\iTypeOfPhi\nassertion A : u \\iRz \\iPhi\n\\end{source}\n%\nwhich requires the programmer to validate~$\\phi$ by providing a\nrealizer for it. When $\\phi$ is a compound statement RZ computes the\nmeaning \\iflong of $u \\rz \\phi$ \\fi as described in\nFigure~\\ref{fig:rz-logic}.\n\nIn RZ we avoid the explicit realizer notation $u \\rz \\phi$ in order to\nmake the output easier to read.\n%\n\\iflong\n%\nA basic predicate declaration $\\iParameter{p}{\\iarrow{s}{\\iProp}}$ is\ntranslated to\n%\n\\begin{source}\ntype ty_p\npredicate p : s \\iTo ty_p \\iTo bool\nassertion strict_p :  \\iForall x:s, a:ty_p, p x a \\iTo x : \\iT{s}\nassertion extensional_p :\n   \\iForall x:s, y:s, a:ty_p, x \\iPer{s} y \\iTo p x a \\iTo p y a\n\\end{source}\n%\nWe see that the predicate~$p$ has gained an additional argument of\ntype $\\f{ty\\_p}$ (which the programmer is supposed to define in an\nimplementation), and we write $\\oapp{\\oapp{p}{x}}{a}$ instead of $a\n\\rz \\oapp{p}{x}$. The two assertions require that $p$ be strict and\nextensional with respect to $\\per_s$.\n%\n\\else % iflong\n%\nA basic predicate declaration $\\iParameter{p}{\\iarrow{s}{\\iProp}}$ is\ntranslated to a type declaration $\\otyspec{\\f{ty\\_p}}$ and a predicate\ndeclaration $\\opropspec{p}{s \\to \\f{ty\\_p} \\to \\oProp}$ together with\nassertions that~$p$ is strict and extensional.\n%\n\\fi % iflong\n\n\\iflong\nFrequently we know that a predicate is stable, which can be taken into\naccount when computing its realizability interpretation. For this\npurpose the input language has the subkind $\\iStable$ of $\\iProp$.\nWhen RZ encounters a predicate which is declared to be stable, such as\n$p : \\iarrow{s}{\\iStable}$, it does not generate a declaration of\n$\\f{ty\\_p}$ and it does not give $p$ an extra argument.\n\nAnother special kind in the RZ input language is the kind $\\iEquiv{s}$ of\nstable equivalence relations on a set~$s$. When an equivalence\nrelation is declared with $\\iParameter{p}{\\iEquiv{s}}$, RZ will output\nassertions stating that $p$ is strict, extensional, \nreflexive, symmetric and transitive.\n\\fi % \\iflong\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"cie\"\n%%% End: \n", "meta": {"hexsha": "6deb81abaa6fb00e408016274f55738e7eb1f81c", "size": 13505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "private/cie/translation.tex", "max_stars_repo_name": "andrejbauer/rz", "max_stars_repo_head_hexsha": "d92cacaf78fb50d61fc6712c74b8fdaf5d2c6d28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-08-28T10:12:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-07T21:04:22.000Z", "max_issues_repo_path": "private/cie/translation.tex", "max_issues_repo_name": "andrejbauer/rz", "max_issues_repo_head_hexsha": "d92cacaf78fb50d61fc6712c74b8fdaf5d2c6d28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "private/cie/translation.tex", "max_forks_repo_name": "andrejbauer/rz", "max_forks_repo_head_hexsha": "d92cacaf78fb50d61fc6712c74b8fdaf5d2c6d28", "max_forks_repo_licenses": ["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.5989159892, "max_line_length": 98, "alphanum_fraction": 0.7006293965, "num_tokens": 4413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.6859494614282923, "lm_q1q2_score": 0.6186720095499708}}
{"text": "\\chapter{$\\tau$ Model of Star Formation}\n\\label{chap:tau_model}\nOur galaxy models are constructed from the simple stellar population\n(SSP) library of \\citet{Bruzual03} with an initial mass function from\n\\citet{Chabrier03}. These SSPs rely on the STELIB stellar library\n\\citep{LeBorgne03}. The goal of any regularized galaxy model is to\nassign individual SSP weights based on a modeled star formation\nhistory (SFH). Our SSP basis set is normalized to \\val{1}{M_{\\odot}}\nand thus the SSP weights will be the total mass of stars in a give\npopulation. We let the mass of a model galaxy at lookback time, $t$,\nbe\n\\begin{equation}\n\\label{TM:eq:M(t)}\nM(t) = \\int_{t_{\\rm form}}^t \\psi(t') dt',\n\\end{equation}\nwhere $\\psi(t)$ is the amount of mass in stars produced at loockback time\n$t$. Equation \\ref{TM:eq:M(t)} is generally true for any star formation\nhistory. For a $\\tau$ model we use\n\\begin{equation}\n\\label{TM:eq:taumodel}\n\\psi(t) = \\psi_0 e^{-t/\\tau_{SF}}.\n\\end{equation}\n\nTaking the above, our galaxy flux, $G(\\lambda)$, is constructed by\nweighting the spectra of individual SSPs, $f_i(\\lambda)$, by the mass\nformed during their formation age:\n\\begin{equation}\nG(\\lambda) = \\sum_i^N f_i(\\lambda) M_i,\n\\end{equation}\nwhere\n\\begin{equation}\nM_i = \\int_{t_2}^{t_1} \\psi(t') dt'.\n\\end{equation}\n\nIn practice our SSP ages are discreet and we need to choose a range of time\n($t_2 - t_1$) over which SSP contributes to star formation. We set these\nlimits of integration such that an equal amount of mass is formed in each half\nof a logarithmically-spaced SSP age bin. In other words, given an SSP of age\n$t_i$, the limits of integration are\n\\begin{equation}\nt_{2,i} = \\frac{\\log (t_{i+1}) - \\log (t_i)}{2} = t_{1,i+1}.\n\\end{equation}\nWe set the end points $t_{1,0} = 0$ and $t_{2,N} = t_{\\rm form}$.\n\nIn the situation where $t_{\\rm form}$ is less than the oldest SSP in\nour library the SSP mass bins will be unevenly spaced in age. To fix\nthis problem we assign each SSP an age that is weighted by the amount\nof mass formed during the time assigned to its bin. In other words,\nthe weighted age of an SSP with age $t_i$ is the midpoint of mass bin\n$M_i$. This weighted age, $t_{i,w}$, is defined such that\n\\begin{equation}\n\\int_{t_1}^{t_{i,w}} \\psi(t') dt' = \\int_{t_{i,w}}^{t_2} \\psi(t') dt'.\n\\end{equation}\nIf we assume the $\\tau$ model described in Eq. \\ref{TM:eq:taumodel} the weighted age is\n\\begin{equation}\nt_{i,w} = \\tau_{SF} \\log\\left( 0.5 \\left( e^{t_1/\\tau_{SF}} + e^{t_2/\\tau_{SF}} \\right)\\right).\n\\end{equation}\n\nFinally, we adopt the extinction law of \\citet{Charlot00} with a value\nof $A_V=1.63$, which defines a reddening term that is constant across all SSPs, \n\\begin{equation}\nR(\\lambda) = e^{-\\frac{A_V}{1.086} \\left(\\lambda/\\val{5500}{\\AA}\\right)^{-0.7}},\n\\end{equation}\n so our final galaxy is given by\n\\begin{equation}\nG(\\lambda) = R(\\lambda)\\sum_i^N f_i(\\lambda) M_i.\n\\end{equation}\n\nAs a proxy for star formation history we define the mean light-weighted age as\n\\begin{equation}\n\\label{TM:eq:MLWA}\n\\tau_L = \\frac{\\sum_k\\left[S(\\lambda_K) R(\\lambda_k) \\sum_i f_i(\\lambda_k) M_i t_i\\right]}{\\sum_{k}\\left[S(\\lambda_k) R(\\lambda_k) \\sum_i f_i(\\lambda_k) M_i\\right]}\n%% \\tau_L = \\frac{\\sum_k S(\\lambda_k)\\left(\\frac{\\sum_{i,j} \\psi(t_i,Z_j) f(\\lambda, t_i,Z_j) t_i}{\\sum_{i,j} \\psi(t_i,Z_j) f(\\lambda, t_i, Z_j)} \\right)}{\\sum_k S(\\lambda_k)},\n\\end{equation}\nwhere $S(\\lambda_j)$ defines the bandpass over which the age is computed. We\nset $S(\\lambda_j)$ to be flat over \\val{5450}{\\AA} $\\leq\\lambda\\leq$\n\\val{5550}{\\AA} and zero everywhere else.\n\n\\bibliographystyle{thesis}\n\\bibliography{ms_n891_paper}", "meta": {"hexsha": "d3dd44d5f4dfc6682e8dfe7154adedf789f51104", "size": 3617, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix/tau_model.tex", "max_stars_repo_name": "eigenbrot/eigenbrot-thesis", "max_stars_repo_head_hexsha": "113dfb95996777e2b36785d7ee80a824a671ab09", "max_stars_repo_licenses": ["MIT"], "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/tau_model.tex", "max_issues_repo_name": "eigenbrot/eigenbrot-thesis", "max_issues_repo_head_hexsha": "113dfb95996777e2b36785d7ee80a824a671ab09", "max_issues_repo_licenses": ["MIT"], "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/tau_model.tex", "max_forks_repo_name": "eigenbrot/eigenbrot-thesis", "max_forks_repo_head_hexsha": "113dfb95996777e2b36785d7ee80a824a671ab09", "max_forks_repo_licenses": ["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.2125, "max_line_length": 176, "alphanum_fraction": 0.7138512579, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384593, "lm_q2_score": 0.6859494421679929, "lm_q1q2_score": 0.6186719903703355}}
{"text": "\\section{Nets and Optimal Search}\n\n\\subsection{British Museum procedure}\n\nFind all possible paths and select the best one from them.\n\n\\subsection{Branch and Bound}\n\n\\begin{itemize}\n  \\item Form a one-element queue consisting of a zero-length path \n    that contains only the root node\n  \\item Until the first path in the queue terminates at the \n    goal node or the queue is empth:\n    \\begin{itemize}\n      \\item Remove the first path from the queue; create new paths \n        by extending the first path to all the neighbors\n        of the terminal node\n      \\item Reject all new paths with loops\n      \\item add the remaining new paths, if any, to the queue\n      \\item Sort the entire queue by path length with \n        least-cost paths in front\n    \\end{itemize}\n  \\item If the goal node is gound, annouce success; otherwise, \n    annouce failure\n\\end{itemize}\n\n\\subsection{Branch and Bound with lower-bound estimate}\n\n\\begin{itemize}\n  \\item Form a one-element queue consisting of a zero-length path \n    that contains only the root node\n  \\item Until the first path in the queue terminates at the \n    goal node or the queue is empth:\n    \\begin{itemize}\n      \\item Remove the first path from the queue; create new paths \n        by extending the first path to all the neighbors\n        of the terminal node\n      \\item Reject all new paths with loops\n      \\item Add the remaining new paths, if any, to the queue\n      \\item Sort the entire queue by \\textbf{the sum of the path\n        length and a lower-bound estimate of the cost\n        remaining, with least-cost paths in front}\n    \\end{itemize}\n  \\item If the goal node is gound, annouce success; otherwise, \n    annouce failure\n\\end{itemize}\n\n\\subsection{Branch and Bound with dynamic programming}\n\n\\begin{itemize}\n  \\item Form a one-element queue consisting of a zero-length path \n    that contains only the root node\n  \\item Until the first path in the queue terminates at the \n    goal node or the queue is empth:\n    \\begin{itemize}\n      \\item Remove the first path from the queue; create new paths \n        by extending the first path to all the neighbors\n        of the terminal node\n      \\item Reject all new paths with loops\n      \\item Add the remaining new paths, if any, to the queue\n      \\item \\textbf{if two or more paths reach a common node,\n        delete all those paths except the one that reaches the\n        common node with the minimum cost}\n      \\item Sort the entire queue by \\textbf{the sum of the path\n        length with least-cost paths in front}\n    \\end{itemize}\n  \\item If the goal node is gound, annouce success; otherwise, \n    annouce failure\n\\end{itemize}\n\n\\subsection{A* procedure - Branch and bound with Underestimates\nand Dynamic Programming}\n\n\\begin{itemize}\n  \\item Form a one-element queue consisting of a zero-length path \n    that contains only the root node\n  \\item Until the first path in the queue terminates at the \n    goal node or the queue is empth:\n    \\begin{itemize}\n      \\item Remove the first path from the queue; create new paths \n        by extending the first path to all the neighbors\n        of the terminal node\n      \\item Reject all new paths with loops\n      \\item Add the remaining new paths, if any, to the queue\n      \\item \\textbf{if two or more paths reach a common node,\n        delete all those paths except the one that reaches the\n        common node with the minimum cost}\n      \\item Sort the entire queue by \\textbf{the sum of the path\n        length and a lower-bound estimate of the cost\n        remaining, with least-cost paths in front}\n    \\end{itemize}\n  \\item If the goal node is gound, annouce success; otherwise, \n    annouce failure\n\\end{itemize}\n\n\\subsection{Which optimal search method is good for me?}\n\\begin{itemize}\n  \\item The British Museum procedure is good only when the \n    search tree is small\n  \\item Branch-and-bound search is good when the tree is big \n    and bad paths turn distinctly bad quickly\n  \\item Branch-and-bound search with a guess is good when \n    there is a good lower-bound estimate of the distance\n    remaining to the goal\n  \\item Dynamic programming is good when many paths convers\n    on the same place\n  \\item The A* procedure is good when both branch-and-bound \n    search with a guess and dynamic programming are good\n\\end{itemize}\n\n", "meta": {"hexsha": "2f5efcdf84c557585e779cc53e4ba8b270997634", "size": 4328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "optimal_search.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": "optimal_search.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": "optimal_search.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": 38.990990991, "max_line_length": 67, "alphanum_fraction": 0.7123382625, "num_tokens": 1034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6186170167944048}}
{"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\\DeclareMathOperator{\\lcm}{lcm}\n\n\\begin{document}\t\n\\section*{Diophantine equations}\n\\begin{enumerate}\n\t\\item \n\tDiophantine equations are polynomial equations, usually in two or more unknowns, such that only integer solutions are sought.\n\t\\item \n\tA Diophantine equation equates two or more monomials, each of degree $1$ in one of the variables, to a constant.\n\t\\item \n\tAn exponential Diophantine equation is one in which exponents on terms can be unknowns. \n\\end{enumerate}\n\\section*{Problems}\n\\begin{enumerate}\n\t\\item \n\tGiven integers $a,b,c$, find the conditions on $a,b,c$ such that there is an integer solution $x,y$ to\n\t$ax+by=c$.\n\t\\item % andreescu 3.2.intro\n\tProve that for every positive integer $m$ there is a positive integer $n$ such that $m+n+1$ is a perfect square and $mn+1$ is a perfect cube.\n\t\n\t\\item % andreescu 3.2.intro\n\tShow that if $a,b$ are non-negative integers such that $\\tfrac{a^2+b^2}{1+ab}$ is also an integer, then $\\tfrac{a^2+b^2}{1+ab}$ is a perfect square.\n\t\n\t\\item % aops\n\tSolve in integers\n\t$$x^3 +x^2 + x + 1 = y^2$$\n\t\n\t\\item % andreescu 3.5.9\n\tProve that the equation $y^2=x^5-4$ has no integer solutions.\n\t\n\t\\item % stevens 4.2.3\n\tProve that there are no integer solutions to\n\t$$x^3 + y^4 = 19^{19}$$\n\t\n\t\\item % andreescu 3.6.intro\n\tFind the positive integer solutions to the equation\n\t$3^x+4^y=5^z$\t\n\t\n\t\\item % andreescu 3.2.15\n\tProve that if there exists a triple of positive integers $(x,y,z)$ such that \n\t$$x^2 + y^2+1 = xyz$$\n\tthen $z=3$ and find all such triplets.\n\t\n\t\\item % andreescu 3.6.4.b\n\tGiven an odd prime $p$, find all pairs of nonnegative integers $x,y$ that solve the equation\n\t$$p^x - y^p =1$$\n\t\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "90e0ecf68bf9f6038fe040760d5a8304be53bd69", "size": 1934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14_diophantine_equations.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": "14_diophantine_equations.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": "14_diophantine_equations.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": 31.1935483871, "max_line_length": 149, "alphanum_fraction": 0.7119958635, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6186170132218151}}
{"text": "\\chapter{Background}\n\nIn this chapter the theoretical background of electrical conductivity measurement will be explained. A market research was conducted to compare commercially available solutions of sensor systems and components that could be used to develop one.\n\n\\section{Theoretical Background}\n\nThe following section is summarized and translated from \\textcite{trankler2015sensortechnik} and \\textcite{gevatter2000automatisierungstechnik}.\\\\\n\nThe conductivity $ \\kappa $  is the ability of a certain volume of a substance to conduct electricity. It is measured in the unit \\unitfrac{S}{m} and is a specific parameter normalized to the length and cross section of the volume. Conductivity in a liquid depends on ions as charge carrier and can therefore be used to measure its concentration.\n\nTo better understand conductivity, an equivalent circuit diagram, shown in figure \\ref{fig:ecd}, of an electrode system shown in figure \\ref{fig:elec}, can be used. This method is called conductometry and in this form a two-electrode-cell is used. In this measurement configuration, two electrodes are submerged in the liquid to be measured and a voltage is applied. The resistance $ R $ of the substance is determined by measuring the potential drop $U_R$ given a constant voltage $ U $, current $ I $ and internal resistance $ R_i$. \\\\\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\begin{circuitikz}[european voltages]\n\t\t\t\\draw\n  \t\t\t(0,0) to [short, *-] (2,0)\n  \t\t\tto [R, l=$R$] (2,2)\n  \t\t\t(0,0) to [open, v^<=$U$] (0,4)\n  \t\t\tto [short, *- ,i=$I$] (2,4)\n  \t\t\tto [R, l_=$R_i$] (2,2)\n  \t\t\t(2.25,0) to [open, v<=$U_R$] (2.25,2);\n\t\t\\end{circuitikz}\n\t\t\\caption[The equivalent circuit diagram]{The equivalent circuit diagram - A voltage drop $U_R$ over the resistance of the fluid relative to the internal resistance $R_i$ is driven by the applied voltage $U$.}\n\t\t\\label{fig:ecd}\n\t\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\t\\begin{center}\n    \t\\tikzset{external/export next=false}\n\t\t\\begin{tikzpicture}\n  \t\t    % Draw electrode\n \t   \t\t\\fill [black!25] (0.5,2) node[left, black] {$A$} rectangle (1.5,-1);\n\t    \t\t% draw voltmeter\n \t   \t\t\\draw[join = round, thick] (1,2) -- (1,2.5) -- (2.4,2.5);\n \t   \t\t\\draw[join = round, thick] (3.1,2.5) -- (4.5,2.5) -- (4.5,2);\n \t   \t\t\\draw (2.75,2.5) node [circle, draw] {V};\n  \t  \t\t%Draw electrode\n  \t  \t\t\\fill [black!25] (4,2) node[left, black] {$A$}  rectangle (5,-1);\n  \t  \t\t\n\t\t\\draw [darrow] (1.5,-0.5) -- (4,-0.5) node[above, pos=0.5] {$d$};\n    \t\t%Draw water\n    \t\t\\fill [blue!75, opacity=0.3] (-0.5,1) rectangle (6,-2);\n\t\t\\end{tikzpicture}\n\t\t\\caption[Two electrodes submerged in the solution]{Two electrodes submerged in the solution - the electrode of area $A$ are placed within the distance $d$. A voltmeter is used to measure the voltage drop $U_R$.}\n\t\t\\label{fig:elec}\n\t\\end{center}\n\\end{figure}\n\nThe resistance $ R $ is\n\\begin{equation}\n\tR = \\dfrac{U_R}{I}\n\\label{eq:R}\n\\end{equation}\n\nThe inverse of the resistance $ R $ is the conductance $ G $\n\\begin{equation}\n\tG = \\dfrac{I}{U_R}\n\\label{eq:G}\n\\end{equation}\n\nThe cell constant $ C $ describes the geometry of the sensor\n\\begin{equation}\n\tC = \\dfrac{d}{A}\n\\label{eq:C}\n\\end{equation}\nwhere $ d $ is the distance between the electrodes and $ A $ the surface area thereof. \n\nConsidering the cell constant $ C $ finally yields the conductivity $\\kappa$\n\\begin{equation}\n\t\\kappa = G \\cdot C\n\\label{eq:kappa} \n\\end{equation}\n\nIn electrolytes, the electrical conduction is a result of mass transfer, where ions are carrying the charges. If the measurement is conducted with direct current, this mass transfer leads to changes in the measured solution and the electrode surface, negatively impacting the measurement. Furthermore, polarization effects create additional resistance, leading to lower than actual results. To avoid this, alternating current is used. The fast, periodical swap of polarity eliminates the net mass flow and its effects. Polarization is a result of the current flowing through the electrode, thereby its effects can be minimized by minimizing this current. One method to do so is replacing the two-electrode-cell with a four-electrode-cell.\nThis separates the current flow from the potential measurement by using one electrode pair to apply the current, and a separate pair to measure the potential drop. \\\\\n\nThe electrolyte's temperature affects the mobility of the ions and thereby also has a big influence on the conductivity. It has to be taken into account when comparing two measurements. If the temperature $ T $ is known, the conductivity at that temperature $ \\kappa_{T} $ can be normalized to a reference temperature $ T_{ref} $ using equation \\eqref{eq:kref}, resulting in the reference conductivity $ \\kappa_{ref} $.\n\n\\begin{equation}\n\t\\kappa_{ref} = \\kappa_{T} \\frac{1}{1 + C_{T} \\cdot (T - T_{ref})}\n\\label{eq:kref}\n\\end{equation}\n\nThe temperature coefficient $ C_{T} $ assumes a linear correlation and is only valid in a narrow temperature range. For bigger ranges the denominator can be replaced with a polynomial using higher order coefficients, resulting in equation \\eqref{eq:kref+}.\n\n\\begin{equation}\n\t\\kappa_{ref} = \\kappa_{T} \\frac{1}{\\sum\\limits_{i=0}^n C_{Ti} \\cdot (T - T_{ref})^{i}}\n\\label{eq:kref+}\n\\end{equation}\n\n\\section{Market Research}\n\nConductivity meters can be readily bought and range from prices of over \\euro{1000} for lab equipment \\parencite{expcm} to \\euro{100} for simple field water quality monitors \\parencite{cheapcm}. Even cheaper water quality testers from no-name manufacturers can be found for as little as \\euro{10} from online vendors.\n\n\\begin{figure}[H]\n\t\\begin{center}\n    \t\\tikzset{external/export next=false}\n\t\t\\includegraphics[scale=0.6]{images/ccm.jpg}\n\t\t\\caption{Fisher Scientific™ Traceable™ Salinity Meter Pen \\parencite{cheapcm}}\n\t\t\\label{fig:ccm}\n\t\\end{center}\n\\end{figure}\n\nFigure \\ref{fig:ccm} shows a field conductivity meter from a quality manufacturer as an example for the typical traits most available solutions share:\n\\begin{itemize}\n\t\\item a single electrode pair\n\t\\item a display to report measurements\n\t\\item designed to perform singular reads with high quality\n\\end{itemize}\n\nWhile field conductivity meters have the electrodes integrated to form one compact device, the more expensive lab equipment often has the electrodes attached to the device with a cable, allowing for a more flexible use.\\\\\n\nA different option was found in the MinieC I2C eC interface from Sparky's Widgets \\parencite{uec}. The MinieC interface is an Open Hardware project providing a conductivity sensor, licensed under Creative Commons \\parencite{cc}. This license allows to study the original design files and build modified versions. Ready-made boards can be purchased for about \\euro{25}. The design approach of this solution is also more modular than that the other products. The MinieC offers an interface to connect external electrodes and can be controlled and read by a microcontroller.\\\\\n\nTable \\ref{tab:feat} shows a comparison of the strengths and weaknesses of the different systems with respect to the use case in this project. Both the lab and field conductivity meters offer complete solutions with high accuracy. They do however lack the modularity of the MinieC as well as the machine interface, both of which are more important for the intended purpose than the accuracy. The complete solutions which are offered simply are solutions for a different case than ours, while the MinieC is positioned as a flexible building block to be used in whatever way needed. While it means that more work has to be done in designing a system around it, this is exactly the trait that allows us to build a device fit for our tasks.\n\n\\begin{table}[H]\n    \\centering\n\n    \\caption[]{Feature comparison table of different conductivity sensor solutions. Strengths and weaknesses are indicated by + and - signs.}\n    \\label{tab:feat}\n    \\begin{tabular}{l  c  c  c}\n        \t\\toprule\n         Feature & Lab Conductivity Meter & Field Conductivity Meter & MinieC \\\\\n        \t\\midrule\n\t\tModularity & - & - - & ++ \\\\\n\t\tCompleteness & ++ & ++ & - \\\\\n\t\tInterface & - & - & ++ \\\\\n\t\tAccuracy & ++ & + & - \\\\\n\t\tPrice & - - & - & + \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}", "meta": {"hexsha": "b264c0d85ccc8acf59f50cc5461f4cb17940838e", "size": 8226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/content/theory.tex", "max_stars_repo_name": "turbinenreiter/OpenSalinity", "max_stars_repo_head_hexsha": "26d29afb9237c9817d0b2dbf6ac69ad9d475e67a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-01T22:06:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-01T22:06:59.000Z", "max_issues_repo_path": "doc/thesis/content/theory.tex", "max_issues_repo_name": "turbinenreiter/OpenSalinity", "max_issues_repo_head_hexsha": "26d29afb9237c9817d0b2dbf6ac69ad9d475e67a", "max_issues_repo_licenses": ["MIT"], "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/content/theory.tex", "max_forks_repo_name": "turbinenreiter/OpenSalinity", "max_forks_repo_head_hexsha": "26d29afb9237c9817d0b2dbf6ac69ad9d475e67a", "max_forks_repo_licenses": ["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.9333333333, "max_line_length": 738, "alphanum_fraction": 0.7346219305, "num_tokens": 2215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6186170029606872}}
{"text": "\\chapter{SCIARA-fv3 - Model Formalization}\\label{sect:SCIARA_MODEL}\n\n\\section{Model Overview}\nSciara-fv3 is the latest release of the Sciara family of\nComplex Cellular Automata Models for simulating basaltic\nlava flows. As its predecessor, Sciara-fv2, it is\nbased on a Bingham-like rheology. However, unlike fv2, it explicitly\ncomputes the flow momentum and the time corresponding\nto the computational step (CA clock). In formal terms, it is\ndefined as:\n\\[\nSCIARA-fv3=<R,X,Q,P,\\tau,L,\\gamma>\n\\]\n\nwhere:\n\n\\begin{enumerate}\n  \\item R is the cellular space, the set of square cells that define the\n  bi-dimensional finite region where the phenomenon evolves.\n  \\item X is the pattern of cells belonging to the Moore\nneighborhood that influence the cell state change (see fig.\n\\ref{fig:mooreNeighModel})\n  \\item \\(Q= Q_z \\times Q_h  \\times Q_T  \\times  Q_{\\overrightarrow{p}}  \\times\n  Q_f^9 \\times  Q_{\\overrightarrow{vf}}^9  \\) is the finite set of states,\n  considered as Cartesian product of substates. Their meanings are: cell altitude a.s.l.,\ncell lava thickness, cell lava temperature, momentum\n(both x and y components), lava thickness outflows\n(from the central cell toward the adjacent cells) and\nflows velocities (both x and y components), respec-\ntively;\n  \\item \\(P = w,t_0, P_T,P_d,P_{hc},\\delta,\\rho,\\epsilon,\\sigma,c_v\\) is the finite set\nof parameters (invariant in time and space), whose\nmeaning is illustrated in Tab. \\ref{tab:parameters}; note that \\(P_T , P_d\\) ,\nand \\(P_{hc}\\) are set of parameters;\n\\item \\(\\tau : Q^9 \\longmapsto Q\\) is the cell deterministic transition\nfunction; it is splitted in \\textit{``elementary processes''}  which, are described\nin section \\ref{sect:ElementaryProcesses};\n\\item \\(L \\subseteq R \\) specifies the emitted lava thickness from the source\ncells (i.e. craters);\n\\item \\(\\gamma : Q_h \\times \\mathbb{N} \\longmapsto Q_h\\) specifies the emitted\nlava thickness from the source cells at each step \\(k \\in \\mathbb{N}\\)\n  \n\\end{enumerate}\n\n\\begin{figure}\n\\begin{center}\n  \\includegraphics[scale=0.65]{./images/mooreNeighSciaraModel}\n  \\caption{Example of Moore neighborhood and decomposition of momentum\nalong the cellular space directions. Cells are indexes from 0 (the central cell,\nin grey) to 8. Cells integer coordinates are omitted for a better readability.}\n  \\label{fig:mooreNeighModel}\n\\end{center}\n\\end{figure}\n\n\n\\begin{table}[!t]\n% increase table row spacing, adjust to taste\n\\renewcommand{\\arraystretch}{1.3}\n% if using array.sty, it might be a good idea to tweak the value of\n% \\extrarowheight as needed to properly center the text within the cells\n\\caption{List of parameters of SCIARA-fv3 with values considered for the simulation of the 2006 Etnean lava flow.}\n\\label{tab:parameters}\n\\centering\n%% Some packages, such as MDW tools, offer better commands for making tables\n%% than the plain LaTeX2e tabular which is used here.\n\\begin{tabular}{l l l l}\n\\hline\nParameter & Meaning & Unit & Best value\\\\\n\\hline\n$w$ & Cell side & [m] & 10\\\\\n$t_0$ & Initial CA clock & [s] & 1\\\\\n$t_{\\max}$ & Upper value for the CA clock & [s] & 120\\\\\n$P_T$\\\\\n\t$\\;\\;\\: T_{sol}$ & Temperature of solidification & [K] & 1143\\\\\n\t$\\;\\;\\: T_{vent}$ & Temperature of extrusion & [K] & 1360\\\\\n$P_d$\\\\\n\t$\\;\\;\\: dP_{T_{sol}}$ & Dissipation factor at solidification & - & 0.5\\\\\n\t$\\;\\;\\: dP_{{T_vent}}$ & Dissipation at extrusion & - & 0.315\\\\\n$P_{hc}$\\\\\n\t$\\;\\;\\: hc_{T_{sol}}$ & Critical height at solidification & [m] & 23.066\\\\\n\t$\\;\\;\\: hc_{{T_{vent}}}$ & Critical height at extrusion & [m] & 1.014\\\\\n$r$ & Relaxation rate & - & 0.5\\\\\n$\\delta$ & Cooling parameter & - & 1.5070\\\\\n$\\rho$ & Lava density & [Kg m$^{-3}$] & 2600\\\\\n$\\epsilon$ & Lava emissivity & - & 0.9\\\\\n%$\\sigma$ & Stephan-Boltzmann constant & [J m$^{-2}$ s$^{-1}$ K$^{-4}$] & $5.68 \\cdot 10^{-8}$\\\\\n$c_v$ & Specific heat & [J kg$^{-1}$ K$^{-1}$] & 1150\\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\section{Elementary process}\\label{sect:ElementaryProcesses}\n\\subsection{Elementary process \\(\\tau_1\\): lava flows computation}\nThe elementary process $\\tau_1$ computes lava outflows and their velocities. It is formally defined as:\n$$\n\\tau_1: Q_z^9 \\times Q_h^9 \\times Q_{\\overrightarrow{p}} \\to Q_f^9 \\times Q_{\\overrightarrow{v_f}}^9\n$$\n\nLava flows are computed by a two-step process: the first computes the CA clock,\n$t$, i.e. the physical time corresponding to a CA computational step, while the\nsecond the effective lava outflows, $h_{(0,i)}$, their velocities\n$v_{f_{(0,i)}}$ and displacements $s_{(0,i)}$ $(i=0,1,...,8)$. The elementary\nprocess $\\tau_1$ is thus executed two times, the first one in ``time evaluation\nmode'', the second in ``flow computing mode''. Both modes compute the so called\n``minimizing outflows'', $\\phi_{(0,i)}$, i.e. those which minimize the unbalance\nconditions within the neighborhood, besides their final velocities and\ndisplacements. In ``time evaluation mode'', $t$ is preliminary set to a large\nvalue, $t_{\\max}$, and the computed displacement, $s_{(0,i)}$, is compared with\nthe maximum allowed value, $d_{(0,i)}$, which is set to the distance between the\ncentral cell and the neighbor that receives the flow. In case of\nover-displacement, the time $t$ must be opportunely reduced in order to avoid\nthe overflow condition. In case no over-displacement are obtained, $t$ remains\nunchanged. Eventually, in ``flow computing mode'', effective lava outflows,\n$h_{(0,i)}$, are computed by adopting the CA clock obtained in ``time evaluation\nmode'', by guarantying no overflow condition.\n\n\\subsubsection{Computation of the minimizing outflows $\\phi_{(0,i)}$}\\label{sec:min-ouflows}\nAs in \\cite{xxx, xxx}, the initial velocity of the lava inside the cell,\n$\\overrightarrow{v_{0}}_{_{(0)}}$, is obtained from the momentum components. In\nturn, it is decomposed in two components laying over the two directions of the\nCA cellular space which are the nearest with respect to\n$\\overrightarrow{v_{0}}_{_{(0)}}$ itself. These latter directions, which will be\nindicated by $e^\\circlearrowleft$ and $e^\\circlearrowright$, can be found by\nmoving in counterclockwise and clockwise directions starting from the direction\nof $\\overrightarrow{v_{0}}_{_{(0)}}$, respectively, as shown in Fig.\n\\ref{fig:mooreNeighModel}. Thus, if $i$ denotes the $i$-th direction of the cellular\nspace, $v_{0_{(0)}}^\\circlearrowleft$ and $v_{0_{(0)}}^\\circlearrowright$ the\nmodules of the components of $\\overrightarrow{v_{0}}_{_{(0)}}$ along the\ndirections $e^\\circlearrowleft$ and $e^\\circlearrowright$, respectively, then\nthe modules of the components of $\\overrightarrow{v_{0}}_{_{(0)}}$ along the\ndirections of the cellular space can be expressed as:\n$$ v_{0_{(0,i)}}=\n\t\\begin{cases}\n\t\tv_{0_{(0)}}^\\circlearrowleft, & \\mbox{if }i = e^\\circlearrowleft \\\\\n\t\tv_{0_{(0)}}^\\circlearrowright, & \\mbox{if }i = e\t^\\circlearrowright \\\\\n\t\t0, & \\mbox{otherwise}\n\t\\end{cases}\n$$\nMoreover, let ${h_k}_{(0,i)} = {v_0}_{(0,i)}^2/2g$ denote the kinetic head associated to the $i$-th component of velocity.\n\nViscosity effects are modeled in terms of velocity dissipation mechanism, by means of the function $dP$. It depends on temperature and vary according to a power law of the type $\\log dP = a+bT$, where $T \\in Q_T$ is the lava temperature and $a$ and $b$ are coefficients determined by solving the system (cf. Tab. \\ref{tab:parameters}):\n$$\n\\begin{cases}\n\t\\log dP_{T_{sol}} = a+bT_{sol}\\\\\n\t\\log dP_{T_{vent}} = a+bT_{vent}\\\\\n\\end{cases}\n$$\nSimilarly, the relation between critical height and lava temperature can be described by a power law of the kind $\\log hc = c+dT$ whose coefficients are obtained by solving the system (cf. Tab. \\ref{tab:parameters}):\n$$\n\\begin{cases}\n\t\\log hc_{T_{sol}} = c+dT_{sol}\\\\\n\t\\log hc_{T_{vent}} = c+dT_{vent}\\\\\n\\end{cases}\n$$\n\nBefore applying the minimization algorithm of the differences for computing the\nminimizing outflows, a preliminary control was performed to eliminating cells\nthat cannot receive lava due to their energy conditions. As in\n\\cite{Spataro2010}, a topographic correction is considered for flow symmetry\nreason. In addition, in Sciara-fv3 the concepts of effective height,\n$h_{e_{(0,i)}}$, and apparent height, $h_{a_{(0,i)}}$, was introduced. The first\nis the part of $h_{(0)}$ that can really flow out of the cell toward its $i$-th\nneighborhood, while the second one is the part which is constrained inside the\ncell due to energy conditions. There are three cases (see Fig. \\ref{fig:cases}):\n\\begin{enumerate}\n\\item if $z_{(0)} + h_{k_{(0,i)}} + h_{(0)} \\leq z_{(i)} + h_{(i)}$, then \\\\\n$\\begin{cases}\n\th_{e_{(0,i)}} = 0\\\\\n\th_{a_{(0,i)}} = h_{(0)}\\\\\n\\end{cases}$\n\\item if $z_{(0)} + h_{k_{(0,i)}} < z_{(i)} + h_{(i)} < z_{(0)} + hk_{(0,i)} + h_{(0)}$, then \\\\\n$\\begin{cases}\n\th_{e_{(0,i)}} = (z_{(0)} + h_{k_{(0,i)}} + h_{(0)}) - (z_{(i)} + h_{(i)})\\\\\n\th_{a_{(0,i)}} = h_{(0)} - h_{e_{(0,i)}}\\\\\n\\end{cases}$\n\\item if $z_{(i)} + h_{(i)} \\leq z_{(0)} + h_{k_{(0,i)}}$, then \\\\\n$\\begin{cases}\n\th_{e_{(0,i)}} = h_{(0)}\\\\\n\th_{a_{(0,i)}} = 0\\\\\n\\end{cases}$\n\\end{enumerate}\nThus, if denoting with $\\theta_{(0,i)} = \\arctan ((z_{(0)} + h_{a_{(0,i)}} + h_{e_{(0,i)}}/2) - (z_{(i)} + h_{(i)}))$ the slope angle between the central cell and its $i$-th neighbor (see Fig. \\ref{fig:cases}), according to the concept of critical height, the cells for which\n$$\nh_{e_{(0,i)}} \\leq hc \\cos \\theta_i\n$$\nare eliminated and cannot receive flow.\n\nThe minimization algorithm of the differences is therefore applied to the following quantities, in order to compute the minimizing outflows:\n\n\\begin{tabular}{l}\n$u_{(0)} = z_{(0)}$\\\\\n$m = h_{(0)}$\\\\\n$u_{(i)} = z_{(i)} + h_{(i)}$\n\\end{tabular}\n\nThe application of the algorithm determines the computation of the minimizing flows, $\\phi_{(0,i)}$, from the central cell to the $i$-th neighbor, where $\\phi_{(0,0)}$ represents the residual flow which does not leave the cell. Eventually, final velocities and displacements are computed. As a first step, final velocities are computed for each outflow $\\phi_{(0,i)}$ $(i=1,2, \\ldots, 8)$, by taking into account dissipation:\n$$\nv_{f_{(0,i)}} = (v_{0_{(0,i)}} + a t)(1-dP)\n$$\nHere, $a = g \\sin \\theta$ is the acceleration of gravity, and does not take into account dissipation, which is modeled by the function $dP$. Instead, the final velocity of $\\phi_{(0,0)}$ is computed as:\n$$\nv_{f_{(0,0)}} = v_{0_{(0)}}(1-dP)\n$$\nIn order to compute the displacement, a mean acceleration is computed, which also takes into account dissipation effects: $\\overline{a} = (v_{f_{(0,i)}} - v_{0_{(0,i)}})/t$. Therefore, the displacements $s_{(0,i)}$ $(i = 1,2, \\ldots, 9)$ are computed as:\n$$\ns_{(0,i)} = v_{0_{(0,i)}} t + \\frac{1}{2} \\overline{a} t^2\n$$\nwhile, a null displacement is assigned to $\\phi_{(0,0)}$:\n$$\ns_{(0,0)} = 0\n$$\nsince, even if in the real case a movement can occur, inside the discrete context of the cellular space, it is always located at the center of the cell. This is a model simplification which is much more correct as the smaller the size of the cell is.\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.8]{./images/fig2PDP}\n\\caption{Cases in which the generic neighbor (\\textit{cell} $i$) is\neliminated or not eliminated by the minimization algorithm of the difference. If the neighbor is eliminated (\\textit{Case} 1), the overall amount of debris inside the central cell is considered as apparent ($h=h_a$), and can not generate an outflow. If the neighbor is not eliminated (\\textit{Case} 2 and 3), a part (\\textit{Case} 2) or the entire amount of debris (\\textit{Case} 3) on the central cell is considered effective ($h \\geq h_e$) and can generate outflows. Note that the slope angle $\\theta$, considered in the critical height computation, is also shown.}\n\\label{fig:cases}\n\\end{figure}\n\n\\subsubsection{Time evaluation}\\label{sect:modeltimeEvaluation}\nOnce the minimizing outflows are computed, the CA clock can be determined. As stated above, when $\\tau_1$ is executed in ``time evaluation mode'', $t$ is preliminary set to a large value, $t_{\\max}$. As a consequence, the computed displacements, $s_{(0,i)}$, can overcome the maximum allowed distance, $w$, i.e. the distance between the central cell and the neighbor that receive the flow. In case of over-displacement, i.e. $s_{(0,i)} > w$, the time $t$ must be opportunely reduced in order to avoid the overflow. The new value of $t$ is determined as follows:\n\n%As a consequence, the computed displacements, $s_{(0,i)}$, can overcome the maximum allowed distance, $d_{(0,i)}$, which is set equal to the distance between the central cell and the neighbor that receive the flow:\n%$$\n%d_{(0,i)}=\n%\t\\begin{cases}\n%\t\tw, & \\mbox{if }i \\in \\{1,2,3,4\\} \\\\\n%\t\tw \\sqrt{2}, & \\mbox{otherwise }\\\\\n%\t\\end{cases}\n%$$\n%In case of over-displacement, i.e. $s_{(0,i)} > d_{(0,i)}$, the time $t$ must be opportunely reduced in order to avoid the overflow. The new value of $t$ is determined as follows:\n\n\\begin{itemize}\n%\\item for each minimizing flow, $\\phi_{(0,i)}$, a new time, $t_{(0,i)}$, is computed by imposing $s_{(0,i)} = d_{(0,i)}$ and by solving the equation with respect to $t$:\n%$$\n%t_{(0,i)} = t = \\frac{ - v_{0_{(0,i)}} + \\sqrt{v_{0_{(0,i)}}^2 + 2 \\overline{a} d_{(0,i)}} }{\\overline{a}}\n%$$\n%so that overflow is avoided between the central cell and its $i$-th neighbor;\n\n\\item for each minimizing flow, $\\phi_{(0,i)}$, a new time, $t_{(0,i)}$, is computed by imposing $s_{(0,i)} = w$ and by solving the equation with respect to $t$:\n$$\nt_{(0,i)} = t = \\frac{ - v_{0_{(0,i)}} + \\sqrt{v_{0_{(0,i)}}^2 + 2 \\overline{a} w} }{\\overline{a}}\n$$\nso that overflow is avoided between the central cell and its $i$-th neighbor;\n\n\n\\item a new time, $t_j$, is computed in order to avoid overflow conditions along all the neighborhood as:\n$$\nt_c = \\min_{i=1,2, \\ldots ,8} t_{(0,i)}\n$$\nso that overflow is avoided in all the neighborhood;\n\n\\item a new minimal time, $t_{opt}$, is computed as:\n$$\nt_{opt} = \\min_{c \\in R} t_{c}\n$$\nin order to avoid overflow conditions over all the cellular space $R$;\n\n\\item $t_{opt}$ is multiplied by a relaxation rate factor, $0 < r \\leq 1$, for smoothing the phenomenon, and the new CA clock, $\\overline{t}$, is obtained:\n$$\n\\overline{t} = t_{opt} r\n$$\n\\end{itemize}\n\n\\subsubsection{Outflows computation}\nIn ``flow computing mode'', minimizing outflows, $\\phi_{(0,i)}$, are re-computed by considering the new CA clock $\\overline{t}$. Subsequently, lava outflows, $h_{(0,i)}$, are computed proportionally to the displacement, by simply multiplying the minimizing outflow by the ratio between the actual displacement and the maximum allowed:\n$$\n%h_{(0,i)} = \\phi_{(0,i)} \\frac{ s_{(0,i)} }{ d_{(0,i)} }\nh_{(0,i)} = \\phi_{(0,i)} \\frac{ s_{(0,i)} }{ w }\n$$\nFinal velocity and displacement are computed as in Section \\ref{sec:min-ouflows}.\n\n\n\n\\subsection{Elementary process $\\tau_2$: updating of mass and\nmomentum}\\label{sect:sciaraModelTau2} The elementary process updates lava\nthickness and momentum.\nIt is formally defined as:\n$$\n\\tau_2: Q_f^9 \\times Q_{\\overrightarrow{v_f}}^9 \\to Q_h \\times Q_{\\overrightarrow{p}}\n$$\nOnce the outflows $h_{(0,i)}$ are known for each cell $c \\in R$, the new lava thickness inside the cell can be obtained by considering the mass balance between inflows and outflows:\n$$\nh_{(0)} = \\sum_{i=0}^9 (h_{(i,0)} - h_{(0,i)})\n$$\n\nMoreover, also the new value for the momentum can be updated by accumulating the contributions given by the inflows:\n$$\n\\overrightarrow{p}_{(0)} = \\sum_{i=0}^9 h_{(i,0)} \\overrightarrow{v_f}_{_{(i,0)}}\n$$\n%while its components along the $x$ and $y$ directions can be simply obtained as:\n%$$\n%p_{x_{(0)}} = \\sum_{i=0}^9 h_{(i,0)} v_{(i,0)} \\cos \\alpha_{(i,0)}\n%$$\n%$$\n%p_{y_{(0)}} = \\sum_{i=0}^9 h_{(i,0)} v_{(i,0)} \\sin \\alpha_{(i,0)}\n%$$\t\n%being $\\alpha_{(i,0)}$ the angle which defines the direction of the velocity of the $i$-th inflow, $h_{(i,0)}$.\n\n\\subsection{Elementary process $\\tau_3$: temperature variation and lava\nsolidification}\\label{sect:temperatureDrop}\n\n$$\n\\tau_3: Q_f^9 \\times Q_T^9 \\to Q_T \\times Q_h\n$$\n\nAs in the elementary process $\\tau_1$, a two step process determines the new\ncell lava temperature. In the first one, the temperature is obtained as weighted\naverage of residual lava inside the cell and lava inflows from neighboring ones:\n$$\n\\overline{T} = \\frac{ \\sum_{i=0}^8 h_{(i,0)} T_i } { \\sum_{i=0}^8 h_{(i,0)} }\n$$ A further step updates the calculated temperature by considering thermal\nenergy loss due to lava surface radiation \\cite{Park1984}:\n$$ T = \\frac{\\overline{T}}  { \\sqrt[3]{1 + \\frac{3\\overline{T}^3 \\epsilon \\sigma\n\\overline{t} \\delta}{\\rho c_v w^2 h}} } $$ where $\\epsilon$, $\\sigma$,\n$\\overline{t}$, $\\delta$, $\\rho$, $c_v$, $w$ and $h$ are the lava emissivity,\nthe Stephan-Boltzmann constant, the CA clock, the cooling parameter, the lava\ndensity, the specific heat, the cell side and the debris thickness, respectively\n(see Tab. \\ref{tab:parameters}). When the lava temperature drops below the\nthreshold $T_{sol}$, lava solidifies. Consequently, the cell altitude increases\nby an amount equal to lava thickness and new lava thickness is set to zero.\n\nLava flows are computed by a two-step process: the first computes the CA clock, $t$, i.e. the physical time corresponding to a CA computational step, while the second the effective lava outflows, $h_{(0,i)}$, their velocities $v_{f_{(0,i)}}$ and displacements $s_{(0,i)}$ $(i=0,1,...,8)$. The elementary process $\\tau_1$ is thus executed two times, the first one in ``time evaluation mode'', the second in ``flow computing mode''. Both modes compute the so called ``minimizing outflows'', $\\phi_{(0,i)}$, i.e. those which minimize the unbalance conditions within the neighborhood, besides their final velocities and displacements. In ``time evaluation mode'', $t$ is preliminary set to a large value, $t_{\\max}$, and the computed displacement, $s_{(0,i)}$, is compared with the maximum allowed value, $d_{(0,i)}$, which is set to the distance between the central cell and the neighbor that receives the flow. In case of over-displacement, the time $t$ must be opportunely reduced in order to avoid the overflow condition. In case no over-displacement are obtained, $t$ remains unchanged. Eventually, in ``flow computing mode'', effective lava outflows, $h_{(0,i)}$, are computed by adopting the CA clock obtained in ``time evaluation mode'', by guarantying no overflow condition.\n\n", "meta": {"hexsha": "8d06b17c612ee007e9cdc1069411af201670d675", "size": 18335, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SciaraModel.tex", "max_stars_repo_name": "knotman90/MSc-Thesis", "max_stars_repo_head_hexsha": "021634dbf93b3189c9d94a1691459cf1aea0563c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SciaraModel.tex", "max_issues_repo_name": "knotman90/MSc-Thesis", "max_issues_repo_head_hexsha": "021634dbf93b3189c9d94a1691459cf1aea0563c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SciaraModel.tex", "max_forks_repo_name": "knotman90/MSc-Thesis", "max_forks_repo_head_hexsha": "021634dbf93b3189c9d94a1691459cf1aea0563c", "max_forks_repo_licenses": ["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.0703363914, "max_line_length": 1279, "alphanum_fraction": 0.7006272157, "num_tokens": 5667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7090191276365463, "lm_q1q2_score": 0.6185109792964332}}
{"text": "\\documentclass{mrl}\n\n\\title{Dual linkable ring signatures}\n\\authors{Sarang Noether\\footnote{\\texttt{sarang.noether@protonmail.com}} and Brandon Goodell\\footnote{\\texttt{surae.noether@protonmail.com}}}\n\\affiliations{Monero Research Lab}\n\\date{\\today}\n\n\\type{RESEARCH BULLETIN}\n\\ident{MRL-0008}\n\n\\begin{document}\n\n\\begin{abstract}\nThis bulletin describes a modification to Monero's linkable ring signature scheme that permits dual-key outputs as ring members. Key images are tied to both output one-time public keys in a dual, preventing both keys in that transaction from being spent separately. This method has applications to non-interactive refund transactions. We discuss the security implications of the scheme.\n\\end{abstract}\n\n\\section{Introduction}\nThe original CryptoNote protocol describes the use of a type of one-time linkable spontaneous anonymous group (LSAG) signature. A signer chooses a so-called ring of public output keys, one of which is her own, and fashions a signature on the message of her choice. The scheme is such that any verifier can be assured that one of the keys in the ring is the true signer (that is, the signer knows the corresponding private key), and that this key was not used to sign any other message with any other ring. For space efficiency, early Monero transactions used a ring-independent one-time version of the LSAG signature scheme in \\cite{liu} to direct funds using the ring as a sender anonymity set.\n\nTo handle confidential transactions, Monero uses a variation of this scheme called multilayered linkable spontaneous anonymous group (MLSAG) signatures. These signatures allow the signer to include vectors of keys that include Pedersen commitments to amounts, as described in \\cite{shen}.\n\nIn both LSAG and MLSAG signatures, ring members (with the exception of amount commitments) are output public keys, which are generated in Monero transactions. A given transaction typically has multiple outputs, where the sender directs a portion of funds from a previous output to some address, and sends the change back to herself so the transaction balances. In each case, the recipient can recover the output's private key and use it in a later ring signature.\n\nIn this research bulletin, we describe a modification to the construction of transaction outputs and to the construction of ring signatures. We first describe a change whereby a sender generates a dual-key output and a specified trigger block height that ``switches\" the validity between the two. Further, we describe a modification to LSAG and MLSAG signatures, a dual linkable spontaneous anonymous group (DLSAG) signature scheme, that allows a sender to include one of these dual-key outputs in a linkable ring signature. When a dual, which is comprised of two separate output public keys, is the true spender, any verifier can link two ring signatures if they were computed by either of the keys in the dual. Additionally, it is possible to include both dual-key outputs and non-dual (that is, single) outputs as ring members in a DLSAG signature, ensuring that signers have the largest possible set of potential ring members available to them.\n\nThis signature scheme has applications to refund transactions in Monero, which themselves are important for certain second-layer solutions. To generate such a refund transaction, a sender generates a dual-key output and specifies a trigger block height. The consensus protocol could dictate that prior to the trigger height, only one of the keys in the dual is valid as a spender; after the trigger height, only the other key in the dual is valid. This allows the sender to reclaim the funds if they are not spent by the recipient in time.\n\nA related version of this scheme was originally described in personal communication with Pedro Moreno-Sanchez, and was in collaboration with pseudonymous coauthor \\texttt{donut}. This related scheme considered the use of commitments to block trigger heights in order to hide the actual switching height.\n\n\\section{Description}\nLet $\\mathbb{G}$ be an additive group of prime order $\\ell$. Let $H_s: \\{0,1\\}^* \\to \\mathbb{Z}_\\ell$ and $H_p: \\{0,1\\}^* \\to \\mathbb{G}$ be cryptographic hash functions. Let $G \\in \\mathbb{G}$ be a publicly-known group generator.\n\nWhen sending funds in a Monero transaction, the sender uses the recipient's public user address $(A,B) := (aG,bG) \\in \\mathbb{G} \\times \\mathbb{G}$, along with a random nonce $r$, to generate a one-time output public key defined as $P := H_s(rA,t)G + B$, where $t$ is the output's index within the transaction. The recipient uses her private user key $(a,b)$ and the point $R := rG$ to recover the output private key $p := H_s(aR,t) + b$, which is used to spend the funds as part of a later ring signature.\n\nTo facilitate refund transactions, we assume that a sender has generated a modified output consisting of two one-time public keys. One such key is directed to the recipient's address, while the other is typically directed back to the sender. These one-time keys are called a \\textit{dual}, and are designated as such in the transaction structure for later identification. The dual also has an associated trigger block height value, with the intent that prior to the trigger, only the first one-time key is valid and can be used to spend the associated funds, and after the trigger, only the second is valid. This has the effect of permitting the recipient to claim funds up to a certain time, after which the sender can reclaim them.\n\nDespite the simplicity of generating separate outputs representing the spend authority of the same funds based on a given block height, it does not suffice to use a traditional LSAG or MLSAG ring signature that includes one of the public keys in a dual without modifying the key image computation. Because key images are computed for each output spent in a ring signature, it would be possible for both the pre-trigger and post-trigger keys to be used in separate signatures undetected. To combat this, we modify the LSAG scheme such that one-time output public keys come in pairs that share the same key image. We later discuss the MLSAG equivalent to the construction.\n\n\\subsection{Signature generation}\nWe show the steps of generating the DLSAG signature in Table \\ref{table:dlsag_gen}, allowing for any of the ring members (including the real spender) to be either part of a dual or not. In the following notation, we assume the spender wishes to spend funds associated to a one-time key $P_\\pi = p_\\pi G$ with a ring size $n$, where $1 \\leq \\pi \\leq n$ is a secret index. We also assume that any key $P_i$ that is part of a dual has a partner key $Q_i$. The roles of $P_i$ and $Q_i$ in a dual are arbitrary.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lcl}\nDual-key & & Single-key \\\\\n\\hline\n$m_\\pi \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$J \\equiv m_\\pi p_\\pi Q_\\pi$ & & $J \\equiv p_\\pi H_p(P_\\pi)$ \\\\\n$F_\\pi \\equiv m_\\pi Q_\\pi$ & & $F_\\pi \\equiv H_p(P_\\pi)$ \\\\\n& choose random $u$ \\\\\n& $c_{\\pi+1} \\equiv H_s(\\textsf{txdata},uG,uF_\\pi)$ \\\\\n\\hline\n& for each $i \\neq \\pi$ \\\\\n& choose random $s_i$ \\\\\n$m_i \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_i \\equiv m_iQ_i$ & & $F_i \\equiv H_p(P_i)$ \\\\\n& $c_{i+1} \\equiv H_s(\\textsf{txdata},s_iG + c_iP_i,s_iF_i+ c_iJ)$ \\\\\n\\hline\n& $s_\\pi \\equiv u - c_\\pi p_\\pi$ \\\\\n& output $(c_1,\\{s_i\\}_{i=1}^n,J)$\n\\end{tabular}\n\\caption{DLSAG signature generation}\n\\label{table:dlsag_gen}\n\\end{center}\n\\end{table}\n\nNote that a DLSAG signature fully reduces to the LSAG case when all keys in the ring, including the true spender, are not part of a dual; that is, when the signature follows only the right-hand side of the above diagram.\n\nThe sender is free to sign with either type of key. However, she must consider a restriction on the allowed ring members. If a potential ring member is part of a dual, she must examine the original transaction and determine whether that key is valid at the current block height. If it is not, then she must choose the partner key within the dual. She may wish to further avoid keys whose trigger is very close to the current block height in case her transaction is not included in a new block quickly enough. These restrictions ensure that adversarial verifiers of the signature cannot easily eliminate invalid ring members when trying to determine the true spender.\n\nAlso observe that partner keys $P$ and $Q$ in a dual share the same key image when generated in the same transaction, since $mpQ = mqP = mpqG$ by construction. The inclusion of the hash $m$, which encodes both the originating transaction as well as the index of the output within that transaction, prevents one of the two recipients of a dual from burning the funds of the other by generating another dual with the same key image that the evil recipient spends first.\n\n\\subsection{Signature verification}\nVerification of a DLSAG proceeds similarly to that of an LSAG signature, and may be done by any observer. When presented with a list of output public keys that are used in the ring signature, the verifier first ensures that for any keys that are part of a dual, the chosen key is valid at the transaction's block height. If not, the verifier rejects the signature. The verifier also examines the key image $J$; if it appears as part of any previous valid LSAG or DLSAG signature, the signature is rejected. The verifier next completes the steps in Table \\ref{table:dlsag_ver}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lcl}\nDual-key & & Single-key \\\\\n\\hline\n& for each $1 \\leq i < n$ \\\\\n$m_i \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_i \\equiv m_i Q_i$ & & $F_i \\equiv H_p(P_i)$ \\\\\n& $c_{i+1} \\equiv H_s(\\textsf{txdata},s_iG + c_iP_i,s_iF_i + c_iJ)$ \\\\\n\\hline\n$m_n \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_n \\equiv m_n Q_n$ & & $F_n \\equiv H_p(P_n)$ \\\\\n& $c_1^* \\equiv H_s(\\textsf{txdata},s_nG + c_nP_n,s_nF_n + c_nJ)$ \\\\\n& accept only if $c_1^* = c_1$\n\\end{tabular}\n\\caption{DLSAG signature verification}\n\\label{table:dlsag_ver}\n\\end{center}\n\\end{table}\n\n\\section{Application to refund transactions}\nA useful application of the DLSAG scheme is to refund transactions. Some constructions of payment channels, which permit off-chain transactions between two parties that are later settled, require the use of non-interactive refund transactions as well. Suppose that Alice wishes to send funds to Bob, but wants to ensure that they are returned to her after an agreed-upon amount of time if Bob does not spend them. To do so, Alice constructs a transaction where the funds destined for Bob are part of a dual: one key $P$ is directed to Bob, and the partner key $Q$ is directed to her. The two keys in the dual share a range proof. A block height $h$ is included in the transaction data, where $h$ is greater than the current block height of the network.\n\nIf Bob wishes to claim the funds, he must spend them prior to block height $h$ in a transaction that uses the key $P$ in a DLSAG signature. Verifiers see that the transaction includes $P$ among its ring members, and that this output is still valid. The key image is of the form $J = mpQ$, which has not been used before. The verifiers accept the transaction as valid.\n\nHowever, if Bob does not claim the funds prior to block height $h$, Alice may claim them by spending her key $Q$ using a DLSAG signature. Verifiers now see that the transaction includes $Q$, and that this key is now valid. The key image is $J = mqP$, which has not been used since Bob did not spend $P$. The verifiers accept this transaction as valid.\n\nNotice that if Bob spent $P$ prior to height $h$ but Alice becomes evil and wishes to spend $Q$ after height $h$ (which would constitute a double spend), the process will properly fail. Verifiers will find Alice's key image $J = mqP = mpQ$ to be the same as Bob's, and will reject her transaction. This construction of a shared key image is essential, as otherwise verifiers would not reject Alice's evil transaction. On the other hand, if the chain on which Bob signed the transaction is later overtaken by a chain with greater cumulative difficulty that does not include Bob's transaction, Alice can always claim the funds later; we consider this possibility outside the scope of this work.\n\n\\section{Multi-input extension}\nThe DLSAG construction presented above applies only to the now defunct CryptoNote ring signature implementation. However, modern transactions require a more robust multi-key signature that can accommodate the amount commitments used in the Monero confidential transaction model. We therefore must ensure that there is an appropriate generalization of the DLSAG construction.\n\nIn a general MSLAG signature, each of the $k$ inputs has an associated ring containing $n$ public output keys (in addition to a separate amount commitment that we do not consider here). The sender chooses a secret index $1 \\leq \\pi \\leq n$ such that she controls the public keys $P_{\\pi,j} \\equiv p_{\\pi,j}G$ for $1 \\leq j \\leq k$. Signature generation proceeds according to the steps in Table \\ref{table:general_gen}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lcl}\nDual-key & & Single-key \\\\\n\\hline\n& for each $1 \\leq j \\leq k$ \\\\\n$m_{\\pi,j} \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$J_j \\equiv m_{\\pi,j}p_{\\pi,j}Q_{\\pi,j}$ & & $J \\equiv p_{\\pi,j}H_p(P_{\\pi,j})$ \\\\\n$F_{\\pi,j} \\equiv m_{\\pi,j}Q_{\\pi,j}$ & & $F_{\\pi,j} \\equiv H_p(P_{\\pi,j})$ \\\\\n& choose random $u_j$ \\\\\n\\hline\n& $c_{\\pi+1} \\equiv H_s(\\textsf{txdata},\\{u_jG,u_jF_{\\pi,j}\\}_{j=1}^k)$ \\\\\n\\hline\n& for each $i \\neq \\pi, 1 \\leq j \\leq k$ \\\\\n& choose random $s_{i,j}$ \\\\\n$m_{i,j} \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_{i,j} \\equiv m_{i,j}Q_{i,j}$ & & $F_{i,j} \\equiv H_p(P_{i,j})$ \\\\\n& $c_{i+1} \\equiv H_s(\\textsf{txdata},\\{s_{i,j}G + c_{i}P_{i,j},s_{i,j}F_{i,j}+ c_{i}J_j\\}_{j=1}^k)$ \\\\\n\\hline\n& for each $1 \\leq j \\leq k$ \\\\\n& $s_{\\pi,j} \\equiv u_j - c_\\pi p_{\\pi,j}$ \\\\\n\\hline\n& output $(c_1,\\{s_{i,j}\\}_{i,j=1}^{n,k},\\{J_j\\}_{j=1}^k)$\n\\end{tabular}\n\\caption{Generalized DLSAG signature generation}\n\\label{table:general_gen}\n\\end{center}\n\\end{table}\n\nAs before, this reduces completely to an MLSAG signature if no ring members are part of a dual. Further, it reduces entirely to the single-input DLSAG construction shown above in the case $k=1$. Given a signature and description of the corresponding set of public one-time output keys, signature verification follows the steps in Table \\ref{table:general_ver}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{lcl}\nDual-key & & Single-key \\\\\n\\hline\n& for each $1 \\leq i < n, 1 \\leq j \\leq k$ \\\\\n$m_{i,j} \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_{i,j} \\equiv m_{i,j}Q_{i,j}$ & & $F_{i,j} \\equiv H_p(P_{i,j})$ \\\\\n& $c_{i+i} \\equiv H_s(\\textsf{txdata},\\{s_{i,j}G + c_{i}P_{i,j},s_{i,j}F_{i,j} + c_{i}J_j\\}_{j=1}^k)$ \\\\\n\\hline\n& for each $1 \\leq j \\leq k$ \\\\\n$m_{n,j} \\equiv H_s(\\textsf{txid},\\textsf{index})$ \\\\\n$F_{n,j} \\equiv m_{n,j}Q_{n,j}$ & & $F_{n,j} \\equiv H_p(P_{n,j})$ \\\\\n& $c_1^* \\equiv H_s(\\textsf{txdata},\\{s_{n,j}G + c_{n}P_{n,j},s_{n,j}F_{n,j}+ c_{n}J_j\\}_{j=1}^k)$ \\\\\n& accept only if $c_1^* = c_1$\n\\end{tabular}\n\\caption{Generalized DLSAG signature verification}\n\\label{table:general_ver}\n\\end{center}\n\\end{table}\n\n\\section{Security}\nThe similarity between DLSAG signatures and the LSAG (from \\cite{liu}) and MLSAG (from \\cite{shen}) schemes leads to similar proofs of security. As in the cited cases, we want to show that our signatures are unforgeable, linkable, and signer-ambiguous. As the proofs are nearly identical to those presented for the original signature schemes, we highlight only the notable differences.\n\n\\subsection{Unforgeability}\nThe LSAG/MLSAG proofs of unforgeability use the number of calls to random oracles to establish bounds on a defined adversary's advantage in breaking the discrete logarithm problem in recovering a signer's private key. These oracles represent the behavior of the hash-to-scalar function $H_s$, hash-to-point function $H_p$, and valid signing. We observe that for a dual key image of the form $J = mpqG$, the value $m$ is uniformly distributed under the random oracle model. For a uniformly distributed value $xG$, the distributions of $(pG,qG,J)$ and $(pG,qG,xG)$ are computationally indistinguishable under the decisional Diffie-Hellman assumption.\n\nThe proof of unforgeability in \\cite{shen} therefore holds with only minor modification, where we consider calls to the hash-to-point random oracle for dual keys replaced by calls to a decisional Diffie-Hellman oracle.\n\n\\subsection{Linkability}\nIf an adversary is able to create two signatures signed by key vectors sharing a common true signing key, there are two cases. If the common signing key is not part of a dual, the proof continues identically to \\cite{shen}. If the common signing key is part of a dual, then we observe that $$\\log_G(s_iG + c_iP_i) = \\log_{m_iQ_i}(s_iF_i + c_iJ)$$ where $i$ is the index of the common signing key in one of the signatures; this leads to the same conclusion as in \\cite{shen}.\n\n\\subsection{Signer ambiguity}\nWe observe that the ambiguity proof in \\cite{shen} does not rely on the particular structure of the base point used in terms passed into the hash-to-scalar function $H_s$ to generate commitments. The proof is trivially modified to account for the $F_i$ terms presented here. \n\n\\subsection{Heuristic attacks}\nThe DLSAG scheme provides a guarantee that, absent external information, any public key referenced in a signature is equiprobable as the true signer. However, an adversary may use such external information to undermine this guarantee via heuristics.\n\\begin{itemize}\n\\item \\textit{Spend time}. If Alice initiates a refund transaction to Bob and Bob does not spend the funds before the trigger height, Alice may attempt to spend the funds shortly after this occurs. If an adversary sees a ring containing a dual whose trigger was recently reached (or perhaps is about to be reached), the adversary may conclude that the dual is the true spender. Moreover, one of the keys in a dual is valid for only a small amount of time, while its partner is available in perpetuity. Such heuristics should be considered in relation to the suspected spend patterns discussed elsewhere, as in \\cite{monerolink,monerolink2}.\n\\item \\textit{Availability of dual outputs}. Dual outputs are trivially distinguishable from single outputs. If the number of available dual outputs in the blockchain is small relative to single outputs, they will be chosen less frequently as ring members. An adversary may conclude that any ring containing dual outputs is more likely to have such an output as the true spender.\n\\end{itemize}\n\n\\subsection{Key reuse}\nThe current Monero transaction implementation mitigates against both double-spending and one-time key reuse. If a user's wallet sees multiple outputs paying to the same one-time key, it chooses the one with the largest amount; otherwise, it risks losing a larger amount since all such outputs have the same key image. Note that the proposed construction separates these roles; the modified key image computation considered here will not inherently prohibit spending to the same one-time key. Alternate protocol-level rules involving one-time key reuse, or the inclusion of a second key image and more complex signature, would be required to retain this.\n\n\\section{Concluding remarks}\nThe signature scheme presented here offers an interesting and novel approach to non-interactive refund transactions for use in Monero. However, implementation choices like block height commitments and requirements for outputs would have an effect on transaction complexity, size, and adversarial heuristics. It is not known whether a space-efficient key generation method could be used to describe dual-key outputs in a more efficient way. The cost in verification complexity is likely to be unavailable without novel signature schemes.\n\n\\bibliographystyle{plain}\n\\bibliography{main}\n\n\\end{document}", "meta": {"hexsha": "a3cee23c8d808463310c6c429409f33d886cc5a6", "size": 19966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/bulletins/MRL-0008-dlsag/main.tex", "max_stars_repo_name": "b-g-goodell/lab-mirror", "max_stars_repo_head_hexsha": "5b994284677f556e30d189377a4c7a40705afc73", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-08-30T19:17:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-12T06:26:36.000Z", "max_issues_repo_path": "publications/bulletins/MRL-0008-dlsag/main.tex", "max_issues_repo_name": "b-g-goodell/lab-mirror", "max_issues_repo_head_hexsha": "5b994284677f556e30d189377a4c7a40705afc73", "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": "publications/bulletins/MRL-0008-dlsag/main.tex", "max_forks_repo_name": "b-g-goodell/lab-mirror", "max_forks_repo_head_hexsha": "5b994284677f556e30d189377a4c7a40705afc73", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-08-30T19:49:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-23T18:01:35.000Z", "avg_line_length": 103.9895833333, "max_line_length": 948, "alphanum_fraction": 0.7645497345, "num_tokens": 5115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6185109645206484}}
{"text": "%!TEX root = main.tex\n\n\n\\section{Maximizing earnings under uncertainty}\n\\label{sec:sensitivity}\nThe primary source of variability in the input of the {\\originalproblem} problem\nis the set of empirical transition matrices {\\empiricaltransitionmatrix}.  In a typical application,\nwe expect that predictive models would be employed to generate estimates of these matrices based upon observations\nfrom historical data (as we do in our own experiments).  Empirically observed transition matrices may \nsuffer from estimation errors due to the presence of external confounding factors (e.g., \nweather, special \nevents inside the city) while gathering the data. As a result, the dynamic programming solution \nto {\\originalproblem}  may also be sensitive to the transition probabilities. In this section, \nwe address the question of how the results of the solutions we described in the previous section change \nunder the assumption that there is some uncertainty (and thus noise) in the underlying empirical transition \nmatrices we use as part of our input.\n\nConcretely, we now assume that the empirical transition matrix~(\\empiricaltransitionmatrix)  is generated from an \nunderlying traffic matrix, or count matrix, recording trips between locations $i$ and $j$.\n\n\\spara{Count matrix (\\countmatrix)}:\nEvery edge $e(i\\rightarrow j) \\in E$ is associated with an\ninteger-valued weight $c(i,j)$ that denotes the number of requests\nat zone $i$ that had node $j$ as their destination.\nThen, we compute frequencies $f(i,j) = \\frac{c(i,j)}{\\sum_k c(i,k)}$, for all outbound trips from $i$.\n\nWith this, we now describe how to quantify uncertainty in the rows of {\\empiricaltransitionmatrix} \n(and the underlying {\\countmatrix}, by construction). This will enable us to  \nmodify the {\\originalproblem} into the {\\robustproblem} problem following ideas developed\nby \\citet{nilim2004robustness}.\n\n\n%\\subsection{Likelihood model}\n%\\label{sec:likelihood_model}\n\n\\spara{Modeling uncertainty:}\nWe now assume that there is an underlying \\emph{true} transition matrix\n{\\truetransitionmatrix}, and the question we explore is \nour confidence that the\n{\\countmatrix} we observe is actually \ngenerated by the true transition matrix {\\truetransitionmatrix}.  As before, both \n{\\truetransitionmatrix} and {\\countmatrix} are clearly time-dependent in practice,\nbut for ease of exposition, we ignore the time-dependency aspect of the problem here.\n\nWe consider each row of the true transition matrix and the count matrix\nseparately; let {\\rowp} and {\\rowc} denote\nany particular row of {\\truetransitionmatrix} and {\\countmatrix} respectively.  \nFollowing the ideas of Kullback {\\etal}~\\cite{kullback62tests}, we have a discriminatory random variable $2\\hat{I}$, which follows a $\\chi^2$ distribution with $(n-1)$ degrees of freedom. Heuristically, $2\\hat{I}$ can be considered as a measure of the ``divergence'' of {\\rowc} from {\\rowp}.\nThus, \nfor $\\rowc$ to be in the  \\emph{$(1-\\alpha)$ (or $100(1-\\alpha)\\%$) \nconfidence interval of $\\rowp$}, we need:\n\\begin{align*}\\label{eq:ul}\n\\text{F}_{\\chi^2_{n-1}}\\left[2\\hat{I}\\right] &=  \\text{F}_{\\chi^2_{n-1}}\\left[2\\sum_{i=1}^n\\rowc(i)\\log\\rowc(i)-2n\\log n -2\\sum_{i=1}^n\\rowc(i)\\log\\rowp(i)\\right] \\nonumber\\\\\n&= 1 - \\alpha,\n\\end{align*}\nwhere \n $\\rowp(i)$ (resp. $\\rowc(i)$) is the $i$-th element of vector $\\rowp$ (resp.\\ $\\rowc$).\n In the above equation, $\\alpha$ quantifies the uncertainty that\n one can tolerate and is an upper bound on what one believes actually exists in the set of observations $\\rowp$. \nThus, we call $\\alpha$ the \\emph{input uncertainty level}.\n \nBy setting $\\beta_\\text{max} = \\sum_{i=1}^n\\rowc(i)\\log \\rowc(i)$,\nwe get\n\\begin{equation}\\label{eq:constraint}\n\\sum_{i=1}^n\\rowc(i)\\log\\rowp(i) = \\frac{2(\\beta_\\text{max}-n\\log n)-\\text{F}^{-1}_{\\chi^2_{n-1}}(1 - \\alpha)}{2},\n\\end{equation}\nwhere $\\text{F}^{-1}_{\\chi^2_{n-1}}$ is the inverse of the $\\chi^2$ cdf. \nIn other words, for all vectors $\\rowp$ for which Equation~\\eqref{eq:constraint}\nis satisfied, $\\rowc$ is within the $(1-\\alpha)$-confidence interval of $\\rowp$.\n\nThus given $\\countmatrix$ and $\\alpha$, we define \nthe \\emph{$\\alpha$-feasible\nmatrices} $\\mathcal{P}_{\\alpha}$ to be \nthe \nset of true transition matrices  such that\nfor every matrix {\\truetransitionmatrix} in $\\mathcal{P}_{\\alpha}$\nand every row $\\rowp$ of {\\truetransitionmatrix}, Equation~\\eqref{eq:constraint}\nis satisfied.\n\n% \\iffalse\n% \\spara{The likelihood model:}\n% Here, we will assume there is an underlying \\emph{true} transition matrix\n% {\\truetransitionmatrix}, and the count matrix {\\countmatrix}, which is used to \n% obtain the empirical transition matrix {\\empiricaltransitionmatrix} is the solution\n% to the maximum likelihood problem\n\n% \\begin{equation}\n% \\max_\\truetransitionmatrix L(\\truetransitionmatrix) := \\sum_{i,j}c(i,j) \\log{p(i,j)} : \\truetransitionmatrix \\geq 0, \\truetransitionmatrix\\vec{1} = \\vec{1} \n% \\end{equation}\n% The optimal log-likelihood is $\\betamax= \\sum_{i,j}c(i,j)\\log{f(i,j)}$.\n% A classical description of uncertainty in a maximum-likelihood setting is via the likelihood region (\\citet{lehmann2006theory}, \\citet{poor2013introduction})\n\n% \\begin{equation*}\n% \\likelihoodregion(\\beta) := \\bigg\\{\\truetransitionmatrix \\in \\mathbb{R}^{n \\times n}: \\truetransitionmatrix \\geq 0, \\truetransitionmatrix \\vec{1}=\\vec{1}, \\sum_{i,j}f(i,j)\\log{p(i,j)} \\geq \\beta\\bigg\\} \\label{eq:likelihood_region}\n% \\end{equation*}\n% where $\\beta < \\betamax$ is a user provided number, which represents the uncertainty level. In practice, one can choose uncertainty level and $\\beta$ using the guidelines detailed by \\citet{nilim2004robustness}.\n\n% We only need to work with uncertainty on each row {\\truetransitionmatrix}, that is projection of the set $\\likelihoodregion(\\beta)$. Due to the separable nature of the log-likelihood function, the projection of the above set onto the $\\truetransitionmatrix_i$ variables of the matrix {\\truetransitionmatrix} can be given as,\n\n% \\begin{equation*}\n% \\likelihoodregion_i(\\beta_i) := \\bigg\\{p \\in \\Delta^n : \\sum_{j}f(i,j)\\log{p(i,j)} \\geq \\beta_i \\bigg\\},\n% \\end{equation*}\n% where,\n% \\begin{equation*}\n% \\beta_i = \\beta - \\sum_{k \\neq i}\\sum_{j}c(k,j)\\log{f(k,j)},\n% \\end{equation*}\n% and  $\\Delta^n = \\{\\vec{p} \\in \\mathbb{R}^n_+ : \\transpose{p} \\vec{1} = 1 \\}$\n\n% \\fi\n\n%\\subsection{\\textsc{The robust control problem}}\n\\spara{The {\\robustproblem} problem:} \n%%Clearly, there are a large number of matrices in the set $\\mathcal{P}_\\alpha$.\nOur approach is to compute the \\emph{worst-case}{ {\\totalexpectedearnings} for a driver, by\n  finding the {\\truetransitionmatrix} among all matrices in $\\mathcal{P}_\\alpha$ \n such that the {\\totalexpectedearnings} of the driver\n are minimized.  \nThis quantifies the worst-case difference between the earnings computed\nas a solution to the {\\originalproblem} and the worst-case earnings of the\ndriver, given bounded uncertainty $\\alpha$.\n%%\n%%\nWe formalized this as the following problem definition:\n\n\\begin{problem}[{\\robustproblem}]\\label{problem:robust}\nGiven sets of time evolving {\\countmatrix}, {\\traveltimematrix} and {\\rewardsmatrix}, the driver's budget $B$ and input uncertainty level $\\alpha$,\nfind $\\widehat{\\policy}$\nsuch that:\n\\[  \\widehat{\\policy} = \\argmax_{\\policy\\in \\policyspace}\n\\min_{\\truetransitionmatrix\\in\\mathcal{P}_\\alpha}\\mathcal{E}(\\policy,\\truetransitionmatrix,\\traveltimematrix,\\rewardsmatrix,B).\n\\]\n\\end{problem}\nNote that the above problem requires searching among all possible true transition \nmatrices in $\\mathcal{P}_\\alpha$, which is a non-enumerable set. \nIn fact, we can show (details omitted due to space constraints) that \nProblem~\\ref{problem:robust} can be solved by enhancing the \\emph{total expected future earnings} associated with {\\getpassenger} action in the  dynamic-programming routines we described in Section~\\ref{sec:driver_strategies}\nwith an optimization problem. We use an off-the-shelf minimizer to solve this optimization problem. \nAlternatively, a bisection algorithm can approximate this problem within an accuracy $\\delta$ in $O(\\log(V_{\\max}/\\delta))$ time, where $V_{\\max}$ is the maximum value of the value function~\\cite{nilim2004robustness}.\n\n% \\iffalse\n% which assumes that every ${\\empiricaltransitionmatrix}^t$ has an uncertainty level of $\\beta$, and a likelihood region $\\likelihoodregion^t$ associated with them. While the {\\originalproblem} problem maximizes the {\\totalexpectedearnings}, the {\\nominalproblem} maximises the `worst-case' {\\totalexpectedearnings}. In order to do that, we devise a situation where the driver seeks to maximize the {\\totalexpectedearnings} \n% while the ``nature\" selects the worst-case time varying transition matrices from the likelihood region {\\likelihoodregion} in order to minimize the {\\totalexpectedearnings}.\n\n% We define \\textit{policy of nature} as a specific ordered selection of time varying true transition matrices \n% %\\begin{equation}\n% $\\mathbb{P} = \\big( \\truetransitionmatrix^t \\big)_{t \\leq N}$.\n% %\\end{equation}\n% Similarly, the corresponding ordered set of likelihood regions is,\n% %\\begin{equation}\n% $\\mathcal{T} = \\big(\\mathcal{P}^t \\big)_{t \\leq N}$. \n% %\\end{equation}\n% Using these notations, we define the {\\robustproblem} problem as follows,\n% \\begin{equation}\n% \\label{eq:robust_control_problem}\n% \\phi(\\policyspace, \\mathcal{T}, \\traveltimematrix, \\rewardsmatrix) = \\max_{\\policy \\in \\policyspace} \\min_{\\mathbb{P} \\in \\mathcal{T}} \\mathcal{E}^{N,B}(\\policy, \\mathbb{P}, \\traveltimematrix, \\rewardsmatrix) \\\\\n% \\end{equation}\n% It should be noted that the ordered set $\\mathbb{P}$ is not enumerable, thereby making it impossible to solve Eq.(\\ref{eq:robust_control_problem}) by conventional dynamic programming.\n% \\fi\n\n\n% \\iffalse\n% \\subsection{\\textsc{Robust Markov Decision Process}}\n\n% As described in previous section, the uncertainty in empirically observed transition matrix affects the cumulative earning only in the case of {\\getpassenger} action, we express Eq.(\\ref{eq:cumulative_earning_get_passenger}) in form of an optimization problem, which we refer to as the `inner problem'.\n% \\begin{equation}\n% \\cumulativeearning{i}{t,b} = \\sigma_{\\likelihoodregion_{i}^{t}} \\bigg(\\rewardsmatrix_{i}^{t} + \\inducedearningvector{i}{t,b}{\\getpassengeraction}\\bigg)\n% \\end{equation}\n% where, the $\\sigma_{\\likelihoodregion}(\\vec{v})$ is a minimization problem of the form,\n% \\begin{equation}\n% \\sigma_{\\likelihoodregion}(\\vec{v}) = \\inf\\big\\{ \\transpose{p}\\vec{v}: \\vec{p} \\in \\likelihoodregion \\big\\}\n% \\end{equation}\n% We now update the recursive equations for calculating {\\totalexpectedearnings} for each of the strategies using the above transformation. For brevity, we only show the updated equation for {\\relocationflexible} below.\n% \\begin{eqnarray}\n% \\label{eq:robust_relocationflexible_strategy}\n% \\cumulativeearning{i}{t,b} &=& \\max_{a \\in \\actionsset}\n%     \\begin{cases}\n%     \\sigma_{\\likelihoodregion_{i}^{t}} \\bigg(\\rewardsmatrix_{i}^{t} + \\inducedearningvector{i}{t,b}{a}\\bigg), &\\textrm{  if } a = \\getpassengeraction\\\\ \\\\\n%     r^t(i,\\homezone) + \\cumulativeearning{\\homezone}{t',b}, &\\textrm{  if } a = \\gohomeaction \\\\ \\\\\n%     \\max_{j} \\bigg\\{r^t(i,j) + \\cumulativeearning{j}{t',b'}\\bigg\\}, &\\textrm{  if } a = \\relocateaction\n%     \\end{cases}\n% \\end{eqnarray}\n\n% \\subsection{\\textsc{The bisection algorithm}}\n\n% The inner problem defined in the previous section is solved in every step of the dynamic program to find an optimal policy for any of the strategies. In this section, we describe an approximation algorithm to solve the inner problem in Eq.(\\ref{eq:inner_problem}) within a bounded error of $\\delta > 0$.\n% \\begin{equation}\n% \\sigma_{\\mathcal{P}}(\\vec{v}) = \\min_{\\vec{p} \\in \\mathcal{P}} \\transpose{p}\\vec{v}\n% \\label{eq:inner_problem}\n% \\end{equation}\n% Assuming that $\\vec{v} \\in \\mathbb{R}^n_+$, the bisection algorithm gives an output of the form,\n% \\begin{eqnarray}\n% \\hat{\\sigma}_{\\mathcal{P}} (\\vec{v}) &=& \\sigma_{\\mathcal{P}} (\\vec{v}) - \\delta_{\\mathcal{P}}(\\vec{v})\n% \\end{eqnarray} \n% where $0 \\leq \\delta_{\\mathcal{P}}(\\vec{v}) \\leq \\delta$.\n\n% The inner problem can be expressed as an optimization problem as follows.\n% \\begin{equation}\n% \\sigma^* = \\min_{\\vec{p}} \\transpose{\\vec{p}}\\vec{v}: \\vec{p} \\in \\Delta^n, \\sum_{j} \\vec{f}(j)\\log{\\vec{p}(j)} \\geq \\beta\n% \\end{equation}\n% The Lagrangian $\\mathbf{L}: \\mathbb{R}^n \\times \\mathbb{R}^n \\times \\mathbb{R} \\times \\mathbb{R} \\rightarrow \\mathbb{R}$ associated with it is,\n% \\begin{equation}\n% \\mathbf{L}(\\vec{v}, \\zeta, \\mu, \\lambda) = \\transpose{\\vec{p}}\\vec{v} - \\transpose{\\zeta}\\vec{p} + \\mu(1 - \\transpose{\\vec{p}}\\mathbf{1}) + \\lambda(\\beta - \\transpose{f}\\log{\\vec{p}})\n% \\end{equation}\n% where $\\zeta, \\mu$ and $\\lambda$ are Lagrange multipliers. We also define $\\vmin = \\min_j{\\vec{v}(j)}$ and $\\vmax = \\max_j{\\vec{v}(j)}$. We can define the dual problem as,\n% \\begin{equation}\n% \\sigma^* = \\max_{\\lambda, \\mu} h(\\lambda, \\mu)\n% \\end{equation}\n% where,\n% \\begin{eqnarray}\n% h(\\lambda, \\mu) = \n%     \\begin{cases}\n%     \\lambda(1 + \\beta) + \\mu - \\lambda \\sum_j \\vec{f}(j) \\log\\bigg({\\frac{\\lambda \\vec{f}(j)}{\\vec{v}(j) - \\mu}}\\bigg), &\\textrm{  if } \\lambda > 0, \\mu < \\vmin, \\\\\n%     -\\infty, &\\textrm{  otherwise } \\\\\n%     \\end{cases} \\nonumber\n% \\end{eqnarray}\n% which further reduces to a 1-dimensional optimization problem,\n% \\begin{equation}\n% \\sigma^* = \\max_{\\mu < \\vmin} \\sigma(\\mu)\n% \\end{equation}\n% where,\n% \\begin{eqnarray*}\n% \\sigma(\\mu) &=& h(\\lambda(\\mu), \\mu), \\\\\n% \\lambda(\\mu) &=& \\bigg(\\sum_{j} \\frac{\\vec{f}(j)}{\\vec{v}(j) - \\mu}\\bigg)^{-1}\n% \\end{eqnarray*}\n% \\begin{lemma}\n% The global maximiser of $\\sigma(\\mu)$ is contained within the interval $[\\mu_{-}, \\mu_{+})$ where, $\\mu_{-} = \\frac{\\vmin - e^{(\\beta - \\betamax)}\\vmax}{1 - e^{(\\beta - \\betamax)}}$ and $\\mu_{+} = \\vmin$.\n% \\todo[Harshal]{Include the proof in supplementary material and provide a link here.}\n% \\end{lemma}\n% \\begin{lemma}\n% After $\\mathcal{N} \\approx \\log_2(V/ \\delta)$ steps, the bisection algorithm provides an optimal solution to the inner problem within a bounded error of $\\delta > 0$, when\n% $V = \\max(\\sigma^* - \\sigma(\\mu_+), \\sigma^* - \\sigma(\\mu_-))$.\n% \\end{lemma}\n% \\todo[Harshal]{Include the proof in supplementary material and provide a link here.}\n% \\begin{algorithm}\n% \\LinesNumbered\n% \\KwIn{$\\mu_{+}, \\mu_{-}, \\mathcal{N}$}\n% \\KwOut{Solution to problem (\\ref{eq:inner_problem})}\n\n% \\For{$k = 1 \\cdots \\mathcal{N}$}{\n%     $\\mu_k = (\\mu_+ + \\mu_-)/2$ ;\\\\\n%     \\uIf{$\\sigma^{'}(\\mu_k) > 0$}{\n%         $\\mu_- = \\mu_k$ \\;\n%     }\n%     \\uElseIf{$\\sigma^{'}(\\mu_k) < 0$}{\n%         $\\mu_+ = \\mu_k$ \\;\n%     }\n%     \\Else{\n%         \\Return $\\sigma(\\mu_k)$\n%     }\n% $k = k + 1$ ;\\\\\n% }\n% \\Return $\\argmax_i \\{\\sigma(\\mu_i)\\}$;\n% \\caption{Bisection algorithm}\n% \\label{alg:bisection_algorithm}\n% \\end{algorithm}\n\n% \\todo[Harshal]{Add note on the complexity of solving the inner problem.}\n\n% \\subsection{\\textsc{\\texorpdfstring{$\\epsilon$}{epsilon}-suboptimal algorithm}}\n\n% An {\\epsilonsuboptimal}, {\\epsilonsuboptimalpolicy} is a policy such that the worst-case {\\totalexpectedearnings} under it, i.e., \n% \\begin{equation}\n% \\phi(\\hat{\\policy}, \\mathcal{T}, \\traveltimematrix, \\rewardsmatrix) = \\min_{\\mathbb{P} \\in \\mathcal{T}} \\mathcal{E}^{N,B}(\\hat{\\policy}, \\mathbb{P}, \\traveltimematrix, \\rewardsmatrix)\n% \\end{equation}\n% satisfy the condition,\n% \\begin{equation*}\n% \\phi(\\hat{\\policy}, \\mathcal{T}, \\traveltimematrix, \\rewardsmatrix) \\leq \\phi(\\policyspace, \\empiricaltransitionmatrix, \\traveltimematrix, \\rewardsmatrix) \\leq \\phi(\\hat{\\policy}, \\mathcal{T}, \\traveltimematrix, \\rewardsmatrix) + \\epsilon\n% \\end{equation*}\n% Here, $\\epsilon > 0$ is user input. Using the uncertainty model from section (\\ref{sec:likelihood_model}), we solve the bisection algorithm with an accuracy $\\delta = \\epsilon / N$. \n% \\note[Harshal]{Only in the case where every optimal action in a policy is {\\getpassenger}, the entire $\\epsilon$ error buffer is used. In practice, the error buffer used will be $(n \\times \\delta)$ where $n$ is the number of times the optimal action choice happens to be {\\getpassenger}}\n% This gives us the robust finite horizon dynamic programming algorithm. The algorithm for the most {\\relocationflexible} is shown below. However, it can be adapted for any of the other strategies described earlier.\n% \\begin{algorithm}\n% \\LinesNumbered\n% \\KwIn{$\\empiricaltransitionmatrix, \\traveltimematrix, \\rewardsmatrix, \\epsilon, \\beta$}\n% \\KwOut{Solution to problem (\\ref{eq:robust_relocationflexible_strategy})}\n\n% Initialize $t = N$ and $b = B$; \\\\\n% \\While{$t > 0$}{\n%     \\While{$b > 0$}{\n%         \\For{$i \\in \\cityzones$}{\n%         Use Algorithm (\\ref{alg:bisection_algorithm}), to calculate a value $\\hat{\\sigma}_{i}$,\n%         $\\hat{\\sigma}_{\\likelihoodregion_i} \\leq \\sigma_{\\likelihoodregion_i}(\\rewardsmatrix_{i}^{t} + \\inducedearningvector{i}{t,b}{\\getpassengeraction}) \\leq \\hat{\\sigma}_{\\likelihoodregion_i} + \\delta$ \\;\n%         Solve Eq.(\\ref{eq:robust_relocationflexible_strategy})\n%         \\begin{eqnarray*}\n%         \\cumulativeearning{i}{t,b} = \\max_{a \\in \\actionsset}\n%             \\begin{cases}\n%             \\hat{\\sigma}_{i}, &\\textrm{  if } a = \\getpassengeraction\\\\\n%             r^t(i,\\homezone) + \\cumulativeearning{\\homezone}{t',b}, &\\textrm{  if } a = \\gohomeaction \\\\\n%             \\max_{j} \\bigg\\{r^t(i,j) + \\cumulativeearning{j}{t',b'}\\bigg\\}, &\\textrm{  if } a = \\relocateaction\n%         \\end{cases}\n%         \\end{eqnarray*}\n%         }\n%     $b = b - 1$ \\;\n%     }\n% $t = t - 1$ \\;\n% }\n% \\Return $\\cumulativeearning{\\homezone}{N,B}$ and $\\epsilonsuboptimalpolicy$;\n% \\caption{Robust Finite Horizon Dynamic Program}\n% \\label{alg:robust_dynamic_program}\n% \\end{algorithm}\n% \\fi\n", "meta": {"hexsha": "2c7ca72eb9829e619588554ef5dc7b64421f6f7e", "size": 17767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/WSDM-2018/uncertainty.tex", "max_stars_repo_name": "chdhr-harshal/uber-driver-strategy", "max_stars_repo_head_hexsha": "f21f968e7aa04d8105bf42e046ab120f813aa12f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-14T22:30:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-05T17:54:25.000Z", "max_issues_repo_path": "paper/WSDM-2018/uncertainty.tex", "max_issues_repo_name": "chdhr-harshal/uber-driver-strategy", "max_issues_repo_head_hexsha": "f21f968e7aa04d8105bf42e046ab120f813aa12f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-02-17T10:36:43.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-17T10:46:33.000Z", "max_forks_repo_path": "paper/WSDM-2018/uncertainty.tex", "max_forks_repo_name": "chdhr-harshal/uber_driver_strategy", "max_forks_repo_head_hexsha": "f21f968e7aa04d8105bf42e046ab120f813aa12f", "max_forks_repo_licenses": ["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.8311258278, "max_line_length": 424, "alphanum_fraction": 0.7032138234, "num_tokens": 5543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6185035630456717}}
{"text": "\\chapter{Application of cohomology}\nIn this final chapter on topology, I'll state (mostly without proof)\nsome nice properties of cohomology groups, and in particular\nintroduce the so-called cup product.\nFor an actual treatise on the cup product,\nsee \\cite{ref:hatcher} or \\cite{ref:maxim752}.\n\n\\section{Poincar\\'e duality}\nFirst cool result:\nyou may have noticed symmetry in the (co)homology groups of\n``nice'' spaces like the torus or $S^n$.\nIn fact this is predicted by:\n\\begin{theorem}\n\t[Poincar\\'e duality]\n\tIf $M$ is a smooth oriented compact $n$-manifold,\n\tthen we have a natural isomorphism\n\t\\[ H^k(M; \\ZZ) \\cong H_{n-k}(M) \\]\n\tfor every $k$.\n\tIn particular, $H^k(M) = 0$ for $k > n$.\n\\end{theorem}\nSo for smooth oriented compact manifolds,\ncohomology and homology groups are not so different.\n\nFrom this follows the symmetry that we mentioned\nwhen we first defined the Betti numbers:\n\\begin{corollary}\n\t[Symmetry of Betti numbers]\n\tLet $M$ be a smooth oriented compact $n$-manifold,\n\tand let $b_k$ denote its Betti number.\n\tThen \\[ b_k = b_{n-k}. \\]\n\\end{corollary}\n\\begin{proof}\n\t\\Cref{prob:betti}.\n\\end{proof}\n\n\n\\section{de Rham cohomology}\nWe now reveal the connection between\ndifferential forms and singular cohomology.\n\nLet $M$ be a smooth manifold.\nWe are interested in the homology and cohomology groups of $M$.\nWe specialize to the case $G = \\RR$, the additive group of real numbers.\n\\begin{ques}\n\tCheck that $\\Ext(H, \\RR) = 0$ for any finitely generated abelian group $H$.\n\\end{ques}\nThus, with real coefficients the universal coefficient theorem says that\n\\[ H^k(M; \\RR) \\cong \\Hom(H_k(M), \\RR) = \\left( H_k(M) \\right)^\\vee \\]\nwhere we view $H_k(X)$ as a real vector space.\nSo, we'd like to get a handle on either $H_k(M$) or $H^k(M; \\RR)$.\n\nConsider the cochain complex\n\\[\n\t0 \\to \\Omega^0(M)\n\t\\taking d \\Omega^1(M)\n\t\\taking d \\Omega^2(M)\n\t\\taking d \\Omega^3(M)\n\t\\taking d \\dots\n\\]\nand let $\\HdR^k(M)$ denote its cohomology groups.\nThus the de Rham cohomology is the closed forms modulo the exact forms.\n\\[\n\t\\text{Cochain} : \\text{Cocycle} : \\text{Coboundary}\n\t= \\text{$k$-form} : \\text{Closed form} : \\text{Exact form}. \n\\]\n\nThe whole punch line is:\n\\begin{theorem}\n\t[de Rham's theorem]\n\tFor any smooth manifold $M$, we have a natural isomorphism\n\t\\[ H^k(M; \\RR) \\cong \\HdR^k(M). \\]\n\\end{theorem}\nSo the theorem is that the real cohomology groups of manifolds $M$\nare actually just given by the behavior of differential forms.\nThus, \n\\begin{moral}\n\tOne can metaphorically think of elements of cohomology groups\n\tas $G$-valued differential forms on the space.\n\\end{moral}\n\nWhy does this happen?\nIn fact, we observed already behavior of differential\nforms which reflects holes in the space.\nFor example, let $M = S^1$ be a circle\nand consider the \\textbf{angle form} $\\alpha$\n(see \\Cref{ex:angle_form}).\nThe from $\\alpha$ is closed, but not exact,\nbecause it is possible to run a full circle around $S^1$.\nSo the failure of $\\alpha$ to be exact is signaling\nthat $H_1(S^1) \\cong \\ZZ$.\n\n\\section{Graded rings}\n\\prototype{Polynomial rings are commutative graded rings,\nwhile $\\Lambda^\\bullet(V)$ is anticommutative.}\nIn the de Rham cohomology, the differential forms can interact in another way:\ngiven a $k$-form $\\alpha$ and an $\\ell$-form $\\beta$, we can consider\na $(k+\\ell)$-form\n\\[ \\alpha \\wedge \\beta. \\]\nSo we can equip the set of forms with a ``product'', satisfying\n$\\beta \\wedge \\alpha = (-1)^{k\\ell} \\alpha \\wedge \\beta$\nThis is a special case of a more general structure:\n\n\\begin{definition}\n\tA \\vocab{graded pseudo-ring} $R$ is an abelian group\n\t\\[ R = \\bigoplus_{d \\ge 0} R^d \\]\n\twhere $R^0$, $R^1$, \\dots, are abelian groups,\n\twith an additional associative binary operation $\\times : R \\to R$.\n\tWe require that if $r \\in R^d$ and $s \\in R^e$, we have $rs \\in R^{d+e}$.\n\tElements of an $R^d$ are called \\vocab{homogeneous elements};\n\tif $r \\in R^d$ and $r \\neq 0$, we write $|r| = d$.\n\\end{definition}\nNote that we do \\emph{not} assume commutativity.\nIn fact, these ``rings'' may not even have an identity $1$.\nWe use other words if there are additional properties:\n\\begin{definition}\n\tA \\vocab{graded ring} is a graded pseudo-ring with $1$.\n\tIf it is commutative we say it is a \\vocab{commutative graded ring}.\n\\end{definition}\n\\begin{definition}\n\tA graded (pseudo-)ring $R$ is \\vocab{anticommutative} if\n\tfor any homogeneous $r$ and $s$ we have\n\t\\[ rs = (-1)^{|r| |s|} sr. \\]\n\\end{definition}\n\nTo summarize:\n\\begin{center}\n\t\\small\n\t\\begin{tabular}[h]{|c|cc|}\n\t\t\\hline\n\t\t\\textbf{Flavors of graded rings} &\n\t\tNeed not have $1$ & Must have a $1$ \\\\ \\hline\n\t\tNo Assumption & graded pseudo-ring & graded ring \\\\\n\t\tAnticommutative & anticommutative pseudo-ring & anticommutative ring \\\\\n\t\tCommutative &  & commutative graded ring \\\\ \\hline\n\t\\end{tabular}\n\\end{center}\n\n\\begin{example}[Examples of graded rings]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The ring $R = \\ZZ[x]$ is a \\textbf{commutative graded ring},\n\t\twith the $d$th component being the multiples of $x^d$.\n\t\t\\ii The ring $R = \\ZZ[x,y,z]$ is a \\textbf{commutative graded ring},\n\t\twith the $d$th component being the abelian group\n\t\tof homogeneous degree $d$ polynomials (and $0$).\n\t\t\\ii Let $V$ be a vector space, and consider\n\t\tthe abelian group\n\t\t\\[ \\Lambda^\\bullet(V) = \\bigoplus_{d \\ge 0} \\Lambda^d(V). \\]\n\t\tFor example, $e_1 + (e_2 \\wedge e_3) \\in \\Lambda^\\bullet(V)$, say.\n\t\tWe endow $\\Lambda^\\bullet(V)$ with the product $\\wedge$,\n\t\twhich makes it into an \\textbf{anticommutative ring}.\n\t\t\\ii Consider the set of differential forms of a manifold $M$,\n\t\tsay \\[ \\Omega^\\bullet(M) = \\bigoplus_{d \\ge 0} \\Omega^d(M) \\]\n\t\tendowed with the product $\\wedge$.\n\t\tThis is an \\textbf{anticommutative ring}.\n\t\\end{enumerate}\n\tAll four examples have a multiplicative identity.\n\\end{example}\n\nLet's return to the situation of $\\Omega^\\bullet(M)$.\nConsider again the de Rham cohomology groups $\\HdR^k(M)$,\nwhose elements are closed forms modulo exact forms.\nWe claim that:\n\\begin{lemma}\n\t[Wedge product respects de Rham cohomology]\n\tThe wedge product induces a map\n\t\\[ \\wedge : \\HdR^k(M) \\times \\HdR^\\ell(M) \\to \\HdR^{k+\\ell}(M). \\]\n\\end{lemma}\n\\begin{proof}\n\tFirst, we recall that the operator $d$ satisfies\n\t\\[\n\t\td(\\alpha \\wedge \\beta)\n\t\t= (d\\alpha) \\wedge \\beta + \\alpha \\wedge (d\\beta).\n\t\\]\n\tNow suppose $\\alpha$ and $\\beta$ are closed forms.\n\tThen from the above, $\\alpha \\wedge \\beta$ is clearly closed.\n\tAlso if $\\alpha$ is closed and $\\beta = d\\omega$ is exact,\n\tthen $\\alpha \\wedge \\beta$ is exact, from the identity\n\t\\[ d(\\alpha \\wedge \\omega)\n\t\t= d\\alpha \\wedge\\omega + \\alpha \\wedge d\\omega = \\alpha \\wedge \\beta. \\]\n\tSimilarly if $\\alpha$ is exact and $\\beta$ is closed\n\tthen $\\alpha \\wedge \\beta$ is exact.\n\tThus it makes sense to take the product modulo exact forms,\n\tgiving the theorem above.\n\\end{proof}\n\nTherefore, we can obtain a \\emph{anticommutative ring}\n\\[ \\HdR^\\bullet(M) = \\bigoplus_{k \\ge 0} \\HdR^k(M) \\]\nwith $\\wedge$ as a product, and $1 \\in \\Lambda^0(\\RR) = \\RR$ as the identity\n\n\\section{Cup products}\nInspired by this, we want to see if we can construct a similar product\non $\\bigoplus_{k \\ge 0} H^k(X; R)$ for any topological space $X$ and ring $R$\n(where $R$ is commutative with $1$ as always).\nThe way to do this is via the \\emph{cup product}.\n\nThen this gives us a way to multiply two cochains, as follows.\n\\begin{definition}\n\tSuppose $\\phi \\in C^k(X;R)$ and $\\psi \\in C^\\ell(X;R)$.\n\tThen we can define their \\vocab{cup product}\n\t$\\phi\\smile\\psi \\in C^{k+\\ell}(X;R)$ to be\n\t\\[\n\t\t(\\phi\\smile\\psi)([v_0, \\dots, v_{k+\\ell}])\n\t\t= \n\t\t\\phi\\left( [v_0, \\dots, v_k] \\right)\n\t\t\\cdot\n\t\t\\psi\\left( [v_k, \\dots, v_{k+\\ell}] \\right)\n\t\\]\n\twhere the multiplication is in $R$.\n\\end{definition}\n\n\\begin{ques}\n\tAssuming $R$ has a $1$, which $0$-cochain is the identity for $\\smile$?\n\\end{ques}\n\nFirst, we prove an analogous result as before:\n\\begin{lemma}[$\\delta$ with cup products]\n\tWe have\n\t$\\delta(\\phi\\smile\\psi) = \\delta\\phi\\smile\\psi\n\t+ (-1)^k\\phi\\smile\\delta\\psi$.\n\\end{lemma}\n\\begin{proof}\n\tDirect $\\sum$ computations.\n\\end{proof}\nThus, by the same routine we used for de Rham cohomology, we get\nan induced map\n\\[ \\smile : H^k(X;R) \\times H^\\ell(X;R) \\to H^{k+\\ell}(X;R).  \\]\nWe then define the \\vocab{singular cohomology ring}\nwhose elements are finite sums in \n\\[ H^\\bullet(X;R) = \\bigoplus_{k \\ge 0} H^k(X;R) \\]\nand with multiplication given by $\\smile$.\nThus it is a graded ring (with $1_R \\in R$ the identity)\nand is in fact anticommutative:\n\\begin{proposition}[Cohomology is anticommutative]\n\t$H^\\bullet(X; R)$ is an anticommutative ring,\n\tmeaning $\\phi \\smile \\psi = (-1)^{k\\ell} \\psi \\smile \\phi$.\n\\end{proposition}\nFor a proof, see \\cite[Theorem 3.11, pages 210-212]{ref:hatcher}.\nMoreover, we have the de Rham isomorphism\n\\begin{theorem}\n\t[de Rham extends to ring isomorphism]\n\tFor any smooth manifold $M$, the isomorphism\n\tof de Rham cohomology groups to singular cohomology\n\tgroups in facts gives an isomorphism\n\t\\[ H^\\bullet(M; \\RR) \\cong \\HdR^\\bullet(M) \\]\n\tof anticommutative rings.\n\\end{theorem}\n\nTherefore, if ``differential forms'' are the way to visualize\nthe elements of a cohomology group, the wedge product is the\ncorrect way to visualize the cup product.\n\nWe now present (mostly without proof)\nthe cohomology rings of some common spaces.\n\n\\begin{example}\n\t[Cohomology of torus]\n\tThe cohomology ring $H^\\bullet(S^1 \\times S^1; \\ZZ)$\n\tof the torus is generated by elements $|\\alpha| = |\\beta| = 1$\n\twhich satisfy the relations\n\t$\\alpha \\smile \\alpha = \\beta \\smile \\beta = 0$,\n\tand $\\alpha \\smile \\beta = -\\beta \\smile \\alpha$.\n\t(It also includes an identity $1$.)\n\tThus as a $\\ZZ$-module it is\n\t\\[ H^\\bullet(S^1 \\times S^1; \\ZZ)\n\t\t\\cong \\ZZ \\oplus \\left[ \\alpha \\ZZ \\oplus \\beta \\ZZ \\right]\n\t\t\\oplus (\\alpha \\smile \\beta) \\ZZ. \\]\n\tThis gives the expected dimensions $1+2+1=4$.\n\tIt is anti-commutative.\n\\end{example}\n\n\\begin{example}[Cohomology ring of $S^n$]\n\tConsider $S^n$ for $n \\ge 1$.\n\tThe nontrivial cohomology groups are given by\n\t$H^0(S^n; \\ZZ) \\cong H^n(S^n; \\ZZ) \\cong \\ZZ$.\n\tSo as an abelian group\n\t\\[ H^\\bullet(S^n; \\ZZ) \\cong \\ZZ \\oplus \\alpha \\ZZ \\]\n\twhere $\\alpha$ is the generator of $H^n(S^n, \\ZZ)$.\n\t\n\tNow, observe that $|\\alpha\\smile\\alpha| = 2n$, but\n\tsince $H^{2n}(S^n; \\ZZ) = 0$ we must have $\\alpha\\smile\\alpha=0$.\n\tSo even more succinctly,\n\t\\[ H^\\bullet(S^n; \\ZZ) \\cong \\ZZ[\\alpha]/(\\alpha^2). \\]\n\tConfusingly enough, this graded ring is both\n\tcommutative \\emph{and} anti-commutative.\n\tThe reason is that $\\alpha \\smile \\alpha = 0 = -(\\alpha \\smile \\alpha)$.\n\\end{example}\n\n\\begin{example}[Cohmology ring of real and complex projective space]\n\tIt turns out that\n\t\\begin{align*}\n\t\tH^\\bullet(\\RP^n; \\Zc2) &\\cong \\Zc2[\\alpha]/(\\alpha^{n+1}) \\\\\n\t\tH^\\bullet(\\CP^n; \\ZZ) &\\cong \\ZZ[\\beta]/(\\beta^{n+1})\n\t\\end{align*}\n\twhere $|\\alpha| = 1$ is a generator of $H^1(\\RP^n; \\Zc2)$\n\tand $|\\beta| = 2$ is a generator of $H^2(\\CP^n; \\ZZ)$.\n\n\tConfusingly enough, both graded rings are commutative \\emph{and} anti-commutative.\n\tIn the first case it is because we work in $\\Zc 2$, for which $1 = -1$,\n\tso anticommutative is actually equivalent to commutative.\n\tIn the second case, all nonzero homogeneous elements have degree $2$.\n\\end{example}\n\n\n\\section{Relative cohomology pseudo-rings}\nFor $A \\subseteq X$, one can also define a relative cup product\n\\[ H^k(X,A;R) \\times H^\\ell(X,A;R) \\to H^{k+\\ell}(X,A;R). \\]\nAfter all, if either cochain vanishes on chains in $A$,\nthen so does their cup product.\nThis lets us define \\vocab{relative cohomology pseudo-ring}\nand \\vocab{reduced cohomology pseudo-ring} (by $A = \\{\\ast\\}$), say\n\\begin{align*}\nH^\\bullet(X,A;R) &= \\bigoplus_{k \\ge 0} H^k(X,A; R) \\\\\n\\wt H^\\bullet(X;R) &= \\bigoplus_{k \\ge 0} \\wt H^k(X;R).\n\\end{align*}\nThese are both \\textbf{anticommutative pseudo-rings}.\nIndeed, often we have $\\wt H^0(X;R) = 0$ and thus there is no identity at all.\n\nOnce again we have functoriality:\n\\begin{theorem}\n\t[Cohomology (pseudo-)rings are functorial]\n\tFix a ring $R$ (commutative with $1$).\n\tThen we have functors\n\t\\begin{align*}\n\t\tH^\\bullet(-; R) &: \\catname{hTop}\\op \\to \\catname{GradedRings} \\\\\n\t\tH^\\bullet(-,-; R) &: \\catname{hPairTop}\\op \\to \\catname{GradedPseudoRings}.\n\t\\end{align*}\n\\end{theorem}\n\nUnfortunately, unlike with (co)homology groups,\nit is a nontrivial task to determine the cup product\nfor even nice spaces like CW complexes.\nSo we will not do much in the way of computation.\nHowever, there is a little progress we can make.\n\n\\section{Wedge sums}\nOur goal is to now compute $\\wt H^\\bullet(X \\vee Y)$.\nTo do this, we need to define the product of two graded pseudo-rings:\n\\begin{definition}\n\tLet $R$ and $S$ be two graded pseudo-rings.\n\tThe \\vocab{product pseudo-ring} $R \\times S$ is the graded pseudo-ring\n\tdefined by taking the underlying abelian group as \n\t\\[ R \\oplus S = \\bigoplus_{d \\ge 0} (R^d \\oplus S^d). \\]\n\tMultiplication comes from $R$ and $S$, followed by\n\tdeclaring $r \\cdot s = 0$ for $r \\in R$, $s \\in S$.\n\\end{definition}\nNote that this is just graded version of the product ring\ndefined in \\Cref{ex:product_ring}.\n\\begin{exercise}\n\tShow that if $R$ and $S$ are graded rings (meaning they have $1_R$ and $1_S$),\n\tthen so is $R \\times S$.\n\\end{exercise}\n\nNow, the theorem is that:\n\\begin{theorem}\n\t[Cohomology pseudo-rings of wedge sums]\n\tWe have\n\t\\[\n\t\t\\wt H^\\bullet(X \\wedge Y; R)\n\t\t\\cong \\wt H^\\bullet(X;R)\n\t\t\\times \\wt H^\\bullet(Y;R)\n\t\\]\n\tas graded pseudo-rings.\n\\end{theorem}\n\nThis allows us to resolve the first question posed at the beginning.\nLet $X = \\CP^2$ and $Y = S^2 \\vee S^4$.\nWe have that\n\\[ H^\\bullet(\\CP^2; \\ZZ) \\cong \\ZZ[\\alpha] / (\\alpha^3). \\]\nHence this is a graded ring generated by there elements:\n\\begin{itemize}\n\t\\ii $1$, in dimension $0$.\n\t\\ii $\\alpha$, in dimension $2$.\n\t\\ii $\\alpha^2$, in dimension $4$.\n\\end{itemize}\nNext, consider the reduced cohomology pseudo-ring\n\\[ \\wt H^\\bullet(S^2 \\vee S^4; \\ZZ) \\cong\n\t\\wt H^\\bullet(S^2; \\ZZ)\n\t\\oplus \\wt H^\\bullet(S^4 ; \\ZZ).\n\\]\nThus the absolute cohomology ring $H^\\bullet(S^2 \\vee S^4 \\; \\ZZ)$\nis a graded ring also generated by three elements.\n\\begin{itemize}\n\t\\ii $1$, in dimension $0$ (once we add back in the $0$th dimension).\n\t\\ii $a_2$, in dimension $2$ (from $H^\\bullet(S^2 ; \\ZZ)$).\n\t\\ii $a_4$, in dimension $4$ (from $H^\\bullet(S^4 ; \\ZZ)$).\n\\end{itemize}\nEach graded component is isomorphic, like we expected.\nHowever, in the former, the product of two degree $2$ generators is\n\\[ \\alpha \\cdot \\alpha = \\alpha^2. \\]\nIn the latter, the product of two degree $2$ generators is\n\\[ a_2 \\cdot a_2 = a_2^2 = 0 \\]\nsince $a_2 \\smile a_2 = 0 \\in H^\\bullet(S^2; \\ZZ)$.\n\nThus $S^2 \\vee S^4$ and $\\CP^2$ are not homotopy equivalent.\n\n\\section{K\\\"unneth formula}\nWe now wish to tell apart the spaces $S^2 \\times S^4$ and $\\CP^3$.\nIn order to do this, we will need a formula\nfor $H^n(X \\times Y; R)$ in terms of $H^n(X;R)$ and $H^n(Y;R)$.\nThus formulas are called \\vocab{K\\\"unneth formulas}.\nIn this section we will only use a very special case,\nwhich involves the tensor product of two graded rings.\n\n\\begin{definition}\n\tLet $A$ and $B$ be two graded rings which are also $R$-modules\n\t(where $R$ is a commutative ring with $1$).\n\tWe define the \\vocab{tensor product} $A \\otimes_R B$ as follows.\n\tAs an abelian group, it is \n\t\\[ A \\otimes_R B = \\bigoplus_{d \\ge 0}\n\t\t\\left( \\bigoplus_{k=0}^{d} A^k \\otimes_R B^{d-k}  \\right). \\]\n\tThe multiplication is given on basis elements by\n\t\\[ \\left( a_1 \\otimes b_1 \\right)\\left( a_2 \\otimes b_2 \\right)\n\t\t= (a_1a_2) \\otimes (b_1b_2).\n\t\\]\n\tOf course the multiplicative identity is $1_A \\otimes 1_B$.\n\\end{definition}\n\nNow let $X$ and $Y$ be topological spaces, and take the product:\nwe have a diagram\n\\begin{diagram}\n\t&& X \\times Y && \\\\\n\tX &\\ldTo(2,1)^{\\pi_X} && \\rdTo(2,1)^{\\pi_Y} & Y \\\\\n\\end{diagram}\nwhere $\\pi_X$ and $\\pi_Y$ are projections.\nAs $H^k(-; R)$ is functorial, this gives induced maps\n\\begin{align*}\n\t\\pi_X^\\ast &: H^k(X \\times Y; R) \\to H^k(X; R) \\\\\n\t\\pi_Y^\\ast &: H^k(X \\times Y; R) \\to H^k(Y; R)\n\\end{align*}\nfor every $k$.\n\nBy using this, we can define a so-called cross product.\n\\begin{definition}\n\tLet $R$ be a ring, and $X$ and $Y$ spaces.\n\tLet $\\pi_X$ and $\\pi_Y$ be the projections of $X \\times Y$\n\tonto $X$ and $Y$.\n\tThen the \\vocab{cross product} is the map\n\t\\[\n\t\tH^\\bullet(X; R) \\otimes_R H^\\bullet(Y;R)\n\t\t\\taking{\\times} H^\\bullet(X \\times Y; R)\n\t\\]\n\tacting on cocycles as follows:\n\t$\\phi \\times \\psi = \\pi_X^\\ast(\\phi) \\smile \\pi_Y^\\ast(\\psi)$.\n\\end{definition}\n\nThis is just the most natural way to take a $k$-cycle\non $X$ and an $\\ell$-cycle on $Y$, and create a $(k+\\ell)$-cycle\non the product space $X \\times Y$.\n\n\n\\begin{theorem}\n\t[K\\\"unneth formula]\n\tLet $X$ and $Y$ be CW complexes such that $H^k(Y;R)$\n\tis a finitely generated free $R$-module for every $k$.\n\tThen the cross product is an isomorphism of anticommutative rings\n\t\\[\n\t\tH^\\bullet(X;R) \\otimes_R H^\\bullet(Y;R)\n\t\t\\to H^\\bullet(X \\times Y; R). \n\t\\]\n\\end{theorem}\n\nIn any case, this finally lets us resolve the question\nset out at the beginning.\nWe saw that $H_n(\\CP^3) \\cong H_n(S^2 \\times S^4)$ for every $n$,\nand thus it follows that $H^n(\\CP^3; \\ZZ) \\cong H^n(S^2 \\times S^4; \\ZZ)$ too.\n\nBut now let us look at the cohomology rings. First, we have\n\\[ H^\\bullet(\\CP^3; \\ZZ) \\cong \\ZZ[\\alpha] / (\\alpha^3)\n\t\\cong \\ZZ \\oplus \\alpha\\ZZ \\oplus \\alpha^2\\ZZ \\oplus \\alpha^3\\ZZ\n\\] \nwhere $|\\alpha| = 2$; hence this is a graded ring generated by\n\\begin{itemize}\n\t\\ii $1$, in degree $0$.\n\t\\ii $\\alpha$, in degree $2$.\n\t\\ii $\\alpha^2$, in degree $4$.\n\t\\ii $\\alpha^3$, in degree $6$.\n\\end{itemize}\n\nNow let's analyze\n\\[ H^\\bullet(S^2 \\times S^4; \\ZZ) \\cong \n\t\\ZZ[\\beta] / (\\beta^2)\n\t\\otimes\n\t\\ZZ[\\gamma] / (\\gamma^2).\n\\]\nIt is thus generated thus by the following elements:\n\\begin{itemize}\n\t\\ii $1 \\otimes 1$, in degree $0$.\n\t\\ii $\\beta \\otimes 1$, in degree $2$.\n\t\\ii $1 \\otimes \\gamma$, in degree $4$.\n\t\\ii $\\beta \\otimes \\gamma$, in degree $6$.\n\\end{itemize}\nAgain in each dimension we have the same abelian group.\nBut notice that if we square $\\beta \\otimes 1$ we get\n\\[ (\\beta \\otimes 1)(\\beta \\otimes 1) = \\beta^2 \\otimes 1 = 0. \\]\nYet the degree $2$ generator of $H^\\bullet(\\CP^3; \\ZZ)$\ndoes not have this property.\nHence these two graded rings are not isomorphic.\n\nSo it follows that $\\CP^3$ and $S^2 \\times S^4$ are not homotopy equivalent.\n\n\t\n% Borsuk Ulam\n\n\\section\\problemhead\n\n\\begin{dproblem}\n\t[Symmetry of Betti numbers by Poincar\\'e duality]\n\t\\label{prob:betti}\n\tLet $M$ be a smooth oriented compact $n$-manifold,\n\tand let $b_k$ denote its Betti number.\n\tProve that $b_k = b_{n-k}$.\n\t\\begin{hint}\n\t\tWrite $H^k(M; \\ZZ)$ in terms of $H_k(M)$\n\t\tusing the UCT, and analyze the ranks.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\tShow that $\\RP^n$ is not orientable for even $n$.\n\t\\begin{hint}\n\t\tUse the previous result on Betti numbers.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\tShow that $\\RP^3$ is not homotopy equivalent to $\\RP^2 \\vee S^3$.\n\t\\begin{hint}\n\t\tUse the $\\Zc2$ cohomologies, and find the cup product.\n\t\\end{hint}\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tShow that $S^m \\vee S^n$ is not a deformation retract\n\tof $S^m \\times S^n$ for any $m,n \\ge 1$.\n\t\\begin{hint}\n\t\tAssume that $r : S^m \\times S^n \\to S^m \\vee S^n$ is such a map.\n\t\tShow that the induced map\n\t\t$H^\\bullet(S^m \\vee S^n; \\ZZ) \\to H^\\bullet(S^m \\times S^n; \\ZZ)$\n\t\tbetween their cohomology rings is monic\n\t\t(since there exists an inverse map $i$).\n\t\\end{hint}\n\t\\begin{sol}\n\t\tSee \\cite[Example 3.3.14, pages 68-69]{ref:maxim752}.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "26f2f719cd6e8ba61f61e9d795a4e0296086ff1b", "size": 19459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/homology/cup-product.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/cup-product.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/cup-product.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.5091240876, "max_line_length": 83, "alphanum_fraction": 0.6794799322, "num_tokens": 6773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.6185035536365756}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{mathptmx}\n\\usepackage[small,compact]{titlesec} \n\\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.\n\\usepackage{url}\n\\usepackage{hyperref}\n\\usepackage{breakurl}\n\\geometry{letterpaper}                   % ... or a4paper or a5paper or ... \n%\\geometry{landscape}                % Activate for for rotated page geometry\n\\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent\n\\usepackage{graphicx}\n\\usepackage{amssymb, amsmath}\n\\usepackage{epstopdf}\n\n\\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}\n\n\\title{Implicit Springs}\n\\author{Miles Macklin}\n%\\date{}                                           % Activate to display a given date or no date\n\n\\begin{document}\n\\maketitle\n\n\\section{Implicit Integration}\nThe backward Euler integration method described in [1][2] requires the Jacobian of spring forces with respect to a particle's position and velocity. This document shows how to derive these Jacobians for use in a semi-implicit integrator.\n\n\\subsection{Vector Calculus Basics}\n\n\\renewcommand{\\v}[1]{\\ensuremath{\\mathbf{#1}}} % for vectors\n\\newcommand{\\uv}[1]{\\ensuremath{\\mathbf{\\hat{#1}}}} % for unit vectors\n\\newcommand\\ddx[1]{\\frac{\\partial#1}{\\partial \\v{x} }} \n\\newcommand\\dd[2]{\\frac{\\partial#1}{\\partial #2}} \n\nIn order to calculate the force Jacobians we will need to know how to calculate the derivatives of some basic quantities with respect to a vector.\n\nIn general the derivative of a scalar valued function with respect to a vector is defined as:\n\n\\[\\ddx{f} = \\begin{bmatrix} \\dd{f}{x_i} & \\dd{f}{x_j} & \\dd{f}{x_k} \\end{bmatrix}\\]\n\nAnd for a vector valued function with respect to a vector:\n\n\\[\\ddx{\\v{f}} = \\begin{bmatrix} \\dd{f_i}{x_i} & \\dd{f_i}{x_j} & \\dd{f_i}{x_k} \\\\ \\dd{f_j}{x_i} & \\dd{f_j}{x_j} & \\dd{f_j}{x_k} \\\\ \\dd{f_k}{x_i} & \\dd{f_k}{x_j} & \\dd{f_k}{x_k} \\end{bmatrix}\\]\n\nFrom these definitions we can work out the derivative of some basic geometric quantities. First, the derivative of a dot product of two vectors with respect to one vector:\n\n\\[\\ddx{\\v{x}^T \\cdot \\v{y}} = \\v{y}^T \\]\n\nWe will explicitly keep track of whether vectors are row vectors or column vectors as it will be important when taking derivatives of spring forces.\n\nThe derivative of a vector magnitude with respect to the vector, gives the normalized vector transposed: \n\n\\[\\ddx{|\\v{x}|} = \\left(\\frac{\\v{x}}{|\\v{x}|}\\right)^T = \\uv{x}^T \\]\n\n\nThe derivative of a normalized vector $\\v{\\hat{x}} = \\frac{\\v{x}}{|\\v{x}|} $ can be obtained using the quotient rule:\n\n\\[\\ddx{\\uv{x}} = \\frac{\\v{I}|\\v{x}| - \\v{x}\\cdot\\uv{x}^T}{|\\v{x}|^2}\\]\n\nWhere $\\v{I}$ is the $n$ x $n$ identity matrix where n is dimension of $x$, and the product of a column vector and a row vector $\\uv{x}\\cdot\\uv{x}^T$ is the outer product which is an $n$ x $n$ matrix that can be constructed using standard matrix multiplication definition.\n\nDividing through by $|\\v{x}|$ we have:\n\n\\[\\ddx{\\uv{x}} = \\frac{\\v{I} - \\uv{x}\\cdot\\uv{x}^T}{\\v{|x|}}\\]\n\n\\subsection{Jacobian of Stretch Force}\n\nRecall the equation for the stretch force on a particle $i$ due to an undamped Hookean spring:\n\n\\[\\v{F_s} = -k_s(|\\v{x}_{ij}| - r)\\uv{x}_{ij}\\]\n\nWhere $\\v{x}_{ij} = \\v{x}_i - \\v{x}_j$ is the vector between the two connected particles positions and $r$ is the rest length.\n\nThe Jacobian of the stretch force with respect to particle $i$'s position is obtained by using the product rule for the two $\\v{x}_i$ dependent terms in $\\v{F_s}$:\n\n\\[\\dd{\\v{F_s}}{\\v{x}_i} = -ks\\left[(|\\v{x}_{ij}| - r)\\dd{\\uv{x}_{ij}}{\\v{x}_i} + \\uv{x}_{ij}\\dd{(|\\v{x}_{ij}| - r)}{\\v{x}_i}\\right]\\]\n\nUsing the previously derived formulas for the derivative of a vector magnitude and normalized vector we have:\n\n\\[\\dd{\\v{F_s}}{\\v{x}_i} = -ks\\left[(|\\v{x}_{ij}| - r)\\left(\\frac{\\v{I} - \\uv{x}_{ij}\\cdot \\uv{x}_{ij}^T}{|\\v{x}_{ij}|}\\right) + \\uv{x}_{ij}\\cdot \\uv{x}_{ij}^T\\right]\\]\n\nDividing the first two terms through by $|\\v{x}_{ij}|$:\n\n\\[\\dd{\\v{F_s}}{\\v{x}_i} = -ks\\left[(1 - \\frac{r}{|\\v{x}_{ij}|})\\left(\\v{I} - \\uv{x}_{ij}\\cdot \\uv{x}_{ij}^T\\right) + \\uv{x}_{ij}\\cdot \\uv{x}_{ij}^T\\right]\\]\n\nDue to the symmetry in the definition of $\\v{x}_{ij}$ we have:\n\n\\[\\dd{\\v{F_s}}{\\v{x}_j}  = -\\dd{\\v{F_s}}{\\v{x}_i}\\]\n\n\n\\subsection{Jacobian of Damping Force}\n\nThe equation for the damping force on a particle $i$ due to a spring:\n\n\\[\\v{F_d} = -k_d\\cdot\\uv{x}(\\v{v}_{ij}\\cdot \\uv{x}_{ij})\\]\n\nWhere $\\v{v}_{ij} = \\v{v}_i-\\v{v}_j$ is the relative velocities of the two particles. This is the preferred formulation because it damps only velocities along the spring axis.\n\nTaking the derivative with respect to $\\v{v}_i$:\n\n\\[\\dd{\\v{F_d}}{\\v{v}_i} = -k_d\\cdot\\uv{x}\\cdot\\uv{x}^T\\]\n\nAs with stretching, the force on the opposite particle is simply negated:\n\n\\[\\dd{\\v{F_d}}{\\v{v}_j} = -\\dd{\\v{F_d}}{\\v{v}_i} \\]\n\n\\section {References}\n\n\\begin{itemize}\n\\item{[Baraff Witkin] - Physically Based Modelling, SIGGRAPH course - \\url{http://www.pixar.com/companyinfo/research/pbm2001/}}\n\\item{[Baraff Witkin] - Large Steps in Cloth Simulation - \\url{http://run.usc.edu/cs599-s10/cloth/baraff-witkin98.pdf}}\n\\item{[N. Joubert] - An Introduction to Simulation (\\url{http://njoubert.com/teaching/cs184_sp09/section/simulation.pdf})}\n\\item{[D Prichard] - Implementing Baraff and Witkin's Cloth Simulation - \\url{http://davidpritchard.org/freecloth/docs/report.pdf}}\n\\item{[Choi] - Stable but Responsive Cloth - \\url{http://graphics.snu.ac.kr/~kjchoi/publication/cloth.pdf}}\n\\item{Numerical Recipes, 3rd edition 2007 - ch17.5}\n\\end{itemize}\n\\end{document}  \n\n\n\n\n\n\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": "66c55f3e56795db4a43d0b938f8efab7a2b48751", "size": 5662, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/springs/implicitsprings.tex", "max_stars_repo_name": "NTForked/sandbox", "max_stars_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 105, "max_stars_repo_stars_event_min_datetime": "2015-01-02T13:44:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T14:08:45.000Z", "max_issues_repo_path": "projects/springs/implicitsprings.tex", "max_issues_repo_name": "NTForked/sandbox", "max_issues_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-05-08T10:28:10.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-09T02:05:10.000Z", "max_forks_repo_path": "projects/springs/implicitsprings.tex", "max_forks_repo_name": "NTForked/sandbox", "max_forks_repo_head_hexsha": "f73d2902bfce3972b889c71f076c724063c180dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2015-02-12T03:38:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T14:09:13.000Z", "avg_line_length": 38.7808219178, "max_line_length": 272, "alphanum_fraction": 0.6716707877, "num_tokens": 1841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6184649389310886}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage[\\graphtype]{mfpic}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\opengraphsfile{pl02-16}\n\\begmath 2.16 Complex Error Function $w(z)$\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nCompute the Fadeeva function $w(z)$, defined by Equation~7.1.3 in \\cite{ams55}:%\n\\begin{equation}\\label{w_def}\nw(z)=e^{-z^2}\\left[ 1+\\frac{2i}{\\sqrt{\\pi }}\\int_0^ze^{t^2}dt\\right] .\n\\end{equation}\nThe Fadeeva function is related to the error function by%\n\\begin{equation*}\nw(z)=e^{-z^2}\\erfc (-iz),\n\\end{equation*}\nto Dawson's integral%\n\\begin{equation*}\nF(z)=e^{-z^2}\\int_0^ze^{t^2}dt,\\text{ by}\\quad \\frac{2i}{\\sqrt{\\pi }}%\nF(z)=w(z)-e^{-z^2},\n\\end{equation*}\nto the Fresnel integrals%\n\\begin{equation*}\n\\hspace{-10pt}C(z)=\\int_0^z\\cos \\left( \\frac \\pi 2t^2\\right) dt,\\ \\text{and}\\ \\\nS(z)=\\int_0^z\\sin \\left( \\frac \\pi 2t^2\\right) dt,\n\\end{equation*}\nby\n\\begin{equation*}\nC(z)+iS(z)=\\frac{1+i}2\\left[ 1- e^{i \\pi z^2 / 2}w\\left( \\frac{\\sqrt{\\pi\n}}2(1+i)z\\right) \\right] ,\n\\end{equation*}\nand to the Voigt functions $V(x,y)$ and $L(x,y)$ (used in spectroscopy and\nastronomy --- see \\cite{Penner:1959:QMS}) by $V(x,y)=\\Re w(z)$ and\n$L(x,y)=\\Im w(z)$, where $z=x+iy.$\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[COMPLEX]  \\ {\\bf Z, W}\n\n\\item[INTEGER]  \\ {\\bf IFLAG}\n\\end{description}\n\n$$\n\\fbox{{\\bf CALL CWOFZ (Z, W, IFLAG)}}\n$$\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[Z]  \\ [in] Argument at which the function is to be evaluated.\n\n\\item[W]  \\ [out] Value of $w(z)$, where $z$ is given by the argument Z.\n\n\\item[IFLAG]  \\ [out] A flag indicating success or failure of the\ncomputation:\n\n\\begin{itemize}\n\\item[0]  means $w(z)$ was successfully calculated,\n\n\\item[$+1$]  means $w(z)$ was not successfully calculated because it would\nhave no significant digits.\n\n\\item[$-1$]  means $w(z)$ was not successfully calculated because it would\noverflow.\n\\end{itemize}\n\nSee Section E, Error Procedures and Restrictions, for a discussion of values\nof Z that result in nonzero values of IFLAG. If IFLAG is nonzero, the real\nand imaginary parts of W are set to the largest representable number.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange the subprogram name to ZWOFZ. On computers that support a double\nprecision complex data type, frequently spelled COMPLEX*16, and on which\ndouble precision complex is represented by an array of two double precision\nnumbers, with the first being the real part, and the second being the\nimaginary part, change the type declarations of Z and W so that Z and W are\ndeclared to be of type double precision complex. On machines that do not\nsupport double precision complex, change the declarations of Z and W to\n\n{\\bf DOUBLE PRECISION \\ Z(2), W(2)}\n\nIn the latter case, put the real part of $z$ into Z(1), and the imaginary\npart of $z$ into Z(2), and find the real and imaginary parts of $w(z)$ in\nW(1) and W(2), respectively.\n\n\\subsection{Examples and Remarks}\n\nSee DRCWOFZ and ODCWOFZ for an example of the usage of this subprogram.\n\n\\subsection{Functional Description}\n\nFrom Eq.~\\eqref{w_def} it is clear that $w(z)$ is analytic in the entire\nplane.  In the upper half-plane, $0 \\leq |w(z)| < 1$, which may have been\nthe original reason to consider $w(z)$ to be a generalization of erfc.\n\n$w(z)$ satisfies the differential equation $w^{\\prime}(z) + 2zw(z) = 2i/%\n\\sqrt{\\pi }$.  Since $w(z)$ is analytic it satisfies the Cauchy-Riemann\nconditions.  If we let $w(z) = u(z) + iv(z)$, and $z = x + iy$, where $u$,\n$v$, $x$ and $y$ are real, the Cauchy-Riemann conditions, together with\nthe differential equation, give us $u_x = 2yv - 2xu \\text{ and } u_y = 2xv\n+ 2yu - 2\\pi ^{1/2} $.  In some applications, particularly related to\nspectroscopy, one needs $V(x,y)$, $L(x,y)$, $V_x(x,y)$ and $V_y(x,y)$.  We\nhave already, above, identified $V(x,y)$ as $u(z)$ and $L(x,y)$ as $v(z)$.\nThus, one can compute these four functions by computing $w(z)$ alone.\n\nThese subprograms are based on a subprogram by G. P. M. Poppe and C. M. J.\nWijers described in \\cite{Poppe:1990:MEC} and \\cite{Poppe:1990:AEC}. The subprogram by Poppe and\nWijers was modified to work in either single or double precision, and some\ntests of argument range were changed to be invoked only when necessary.\nMachine characteristics are discovered, and errors are processed, using\nMATH77 conventions. The subprogram name was changed to conform to\nMATH77 naming conventions.\n\nThe algorithm uses three different methods. Inside the ellipse $%\n(x/6.3)^2+(y/4.4)^2\\leq .292^2$ the algorithm uses the series approximation\ngiven by Equation~7.1.6 in \\cite{ams55}. In the elliptic annulus $%\n.292^2<(x/6.3)^2+(y/4.4)^2\\leq 1.0$ the algorithm uses a Taylor series, with\nderivatives calculated by the Laplace continued fraction. Outside the latter\nellipse, a Laplace continued fraction is used.\n% \\input prepic.tex\n% \\input pictex.tex\n% \\input postpic.tex\n% \\beginpicture \\ninepoint\n% \\setcoordinatesystem units <   .786in,   .864in>\n% \\setplotarea x from    .000 to   3.500, y from  -2.500 to   3.000\n% \\axis left label {$\\Im z$\\hspace{-6pt}} ticks in numbered from -2.5 to\n% 3.0 by .5 /\n% \\axis right ticks in quantity 12 /\n% \\axis top ticks in quantity 8 /\n% \\axis bottom label {} ticks in withvalues 0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 / at 0 .5 1 1.5 2 2.5 3 3.5 / /\n% \\put {$0.2$} at   1.080  2.460\n% \\put {$0.3$} at    .750  1.500\n% \\put {$0.5$} at    .420   .700\n% \\put {$1$} at    .280  -.040\n% \\put {$2$} at    .250  -.550\n% \\put {$5$} at    .250 -1.010\n% \\put {$10$} at    .250 -1.300\n% \\put {$30$} at    .250 -1.670\n% \\put {$100$} at    .250 -2.000\n% \\put {$300$} at    .250 -2.260\n% \\put {$45$} at   1.100   .640\n% \\put {$90$} at   1.260  -.400\n% \\put {$135$} at   1.280  -.920\n% \\put {$180$} at   1.350 -1.200\n% \\put {$-90$} at   1.480 -1.600\n% \\put {$0$} at   1.640 -1.900\n% \\put {$90$} at   1.830 -2.120\n% \\put {$180$} at   2.050 -2.300\n% \\put {$-90$} at   2.290 -2.400\n% \\put {$0$} at   2.590 -2.400\n% \\put {$90$} at   2.840 -2.400\n% \\setsolid\n% \\setquadratic \\plot\n%   .1225 -2.2415   .1050 -2.2406   .0700 -2.2392   .0350 -2.2384\n%   .0000 -2.2382\n% /\n% \\setquadratic \\plot\n%   .1225 -1.9820   .0700 -1.9796   .0000 -1.9785\n% /\n% \\setquadratic \\plot\n%   .1575 -1.6553   .0875 -1.6506   .0000 -1.6486\n% /\n% \\setquadratic \\plot\n%   .1575 -1.2904   .0875 -1.2848   .0000 -1.2823\n% /\n% \\setquadratic \\plot\n%   .1750 -1.0094   .0875 -1.0015   .0000  -.9989\n% /\n% \\setquadratic \\plot\n%   .1750  -.5257   .1050  -.5190   .0000  -.5151\n% /\n% \\setquadratic \\plot\n%   .3150  -.5498   .3850  -.5671   .4375  -.5826   .4900  -.6005\n%   .5425  -.6203   .5775  -.6350   .6265  -.6575   .6650  -.6764\n%   .7000  -.6950   .7350  -.7150   .7761  -.7400   .8183  -.7675\n%   .8575  -.7949   .8925  -.8209   .9275  -.8485   .9622  -.8775\n%    .9934  -.9050   1.0150  -.9247   1.0500  -.9585   1.0787  -.9875\n%   1.1047 -1.0150   1.1375 -1.0509   1.1725 -1.0913   1.2004 -1.1250\n%   1.2250 -1.1555\n% /\n% \\setquadratic \\plot\n%   1.3271 -1.2900   1.3475 -1.3178   1.3825 -1.3652   1.4081 -1.4000\n%   1.4350 -1.4355   1.4700 -1.4812   1.4930 -1.5100\n% /\n% \\setquadratic \\plot\n%   1.6100 -1.6430   1.6416 -1.6750   1.6702 -1.7025   1.6999 -1.7300\n%   1.7325 -1.7588   1.7675 -1.7886   1.8200 -1.8317   1.8550 -1.8599\n%   1.8982 -1.8950   1.9318 -1.9225   1.9775 -1.9608   2.0125 -1.9916\n%   2.0562 -2.0325   2.0842 -2.0600   2.1350 -2.1131   2.1616 -2.1425\n%   2.2050 -2.1924   2.2324 -2.2250   2.2575 -2.2550   2.2784 -2.2800\n%   2.3018 -2.3075\n% /\n% \\setquadratic \\plot\n%   2.4150 -2.4307   2.4500 -2.4649   2.4877 -2.5000\n% /\n% \\setquadratic \\plot\n%   2.5200 -2.4074   2.4850 -2.3730   2.4500 -2.3351   2.4274 -2.3075\n%   2.3865 -2.2525   2.3625 -2.2169   2.3317 -2.1700   2.3100 -2.1361\n%   2.2750 -2.0833   2.2400 -2.0343   2.2050 -1.9897   2.1695 -1.9500\n%   2.1175 -1.8986   2.0825 -1.8683   2.0473 -1.8400   2.0110 -1.8125\n%   1.9600 -1.7754   1.9075 -1.7378   1.8601 -1.7025   1.8200 -1.6702\n%   1.7675 -1.6233   1.7369 -1.5925   1.7120 -1.5650   1.6800 -1.5253\n%   1.6489 -1.4825   1.6275 -1.4492   1.5989 -1.4000   1.5750 -1.3536\n%   1.5575 -1.3173   1.5334 -1.2625   1.5108 -1.2075   1.4998 -1.1800\n%   1.4875 -1.1486\n% /\n% \\setquadratic \\plot\n%   1.4675 -1.0975   1.4458 -1.0425   1.4175  -.9737\n% /\n% \\setquadratic \\plot\n%   1.3469  -.8225   1.3174  -.7675   1.2852  -.7125   1.2600  -.6727\n%   1.2250  -.6215   1.1904  -.5750   1.1686  -.5475   1.1375  -.5104\n%   1.1025  -.4715   1.0850  -.4530   1.0500  -.4181   1.0150  -.3854\n%   .9802  -.3550   .9625  -.3400   .9275  -.3122   .8925  -.2860\n%   .8575  -.2614   .8326  -.2450   .8050  -.2273   .7700  -.2062\n%   .7175  -.1770   .6891  -.1625   .6650  -.1505   .6314  -.1350\n%   .5950  -.1190   .5663  -.1075   .5425  -.0981   .5075  -.0855\n%   .4725  -.07376   .4025  -.05318   .3500  -.03987\n% /\n% \\setquadratic \\plot\n%   .2100  -.01412   .1050  -.00344   .0000   .00006\n% /\n% \\setquadratic \\plot\n%   .2800   .7484   .1400   .7640   .0000   .7691\n% /\n% \\setquadratic \\plot\n%   .5600   .6844   .6257   .6625   .6825   .6415   .7350   .6201\n%   .7875   .5967   .8225   .5799   .8759   .5525   .9256   .5250\n%    .9717   .4975   1.0149   .4700   1.0555   .4425   1.0937   .4150\n%   1.1298   .3875   1.1639   .3600   1.1964   .3325   1.2272   .3050\n%   1.2600   .2742   1.2845   .2500   1.3125   .2210   1.3475   .1827\n%   1.3825   .1415   1.4058   .1125   1.4350   .0740   1.4660   .0300\n%   1.4875  -.0025   1.5182  -.0525   1.5488  -.1075   1.5630  -.1350\n%   1.5890  -.1900   1.6009  -.2175   1.6227  -.2725   1.6417  -.3275\n%   1.6581  -.3825   1.6720  -.4375   1.6834  -.4925   1.6924  -.5475\n%   1.6991  -.6025   1.7063  -.7125   1.7071  -.7675   1.7063  -.8225\n%   1.7043  -.8775   1.6998  -.9600   1.6968 -1.0150   1.6938 -1.0975\n%   1.6935 -1.1250   1.6947 -1.1800   1.6975 -1.2190   1.7027 -1.2625\n%   1.7135 -1.3175   1.7210 -1.3450   1.7413 -1.4000   1.7544 -1.4275\n%   1.7850 -1.4775   1.8102 -1.5100   1.8375 -1.5391   1.8900 -1.5830\n%   1.9425 -1.6175   1.9978 -1.6475   2.0825 -1.6886   2.1350 -1.7156\n%   2.2022 -1.7575   2.2400 -1.7871   2.2923 -1.8400   2.3322 -1.8950\n%   2.3753 -1.9775   2.3974 -2.0325   2.4178 -2.0875   2.4325 -2.1261\n%   2.4502 -2.1700   2.4850 -2.2376   2.5353 -2.3075\n% /\n% \\setquadratic \\plot\n%   2.6101 -2.3075   2.5809 -2.2800   2.5419 -2.2250   2.5290 -2.1975\n%   2.5119 -2.1425   2.5026 -2.0875   2.5000 -2.0600   2.4966 -2.0050\n%   2.4911 -1.9225   2.4850 -1.8779   2.4692 -1.8125   2.4458 -1.7575\n%   2.4077 -1.7025   2.3625 -1.6614   2.3100 -1.6310   2.2575 -1.6118\n%   2.1700 -1.5932   2.1000 -1.5816   2.0125 -1.5617   1.9522 -1.5375\n%   1.8900 -1.4958   1.8725 -1.4793   1.8375 -1.4334   1.8201 -1.4000\n%   1.8035 -1.3450   1.7995 -1.3175   1.7981 -1.2900   1.8020 -1.2350\n%   1.8072 -1.2075   1.8200 -1.1616   1.8340 -1.1250   1.8465 -1.0975\n%   1.8725 -1.0480   1.8900 -1.0187   1.9075  -.9913   1.9250  -.9650\n%   1.9477  -.9325   1.9670  -.9050   1.9950  -.8643   2.0125  -.8387\n%   2.0416  -.7950   2.0586  -.7675   2.0825  -.7256   2.1000  -.6927\n%   2.1172  -.6575   2.1294  -.6300   2.1508  -.5750   2.1602  -.5475\n%   2.1762  -.4925   2.1875  -.4433   2.1940  -.4100   2.2020  -.3550\n%   2.2073  -.3000   2.2100  -.2450   2.2103  -.2175   2.2092  -.1625\n%   2.2057  -.1075   2.2031  -.0800   2.1963  -.0250   2.1875   .0278\n%   2.1818   .0575   2.1700   .1096   2.1623   .1400   2.1525   .1752\n%   2.1380   .2225   2.1289   .2500   2.1089   .3050   2.0866   .3600\n%   2.0650   .4088   2.0475   .4456   2.0211   .4975   1.9907   .5525\n%   1.9578   .6075   1.9036   .6900   1.8375   .7796   1.7850   .8440\n%   1.7264   .9100   1.6800   .9586   1.6275  1.0099   1.5867  1.0475\n%   1.5230  1.1025   1.4700  1.1452   1.4172  1.1850   1.3650  1.2222\n%   1.2966  1.2675   1.2425  1.3010   1.1725  1.3413   1.1043  1.3775\n%   1.0325  1.4127    .9625  1.4441    .8750  1.4796\n% /\n% \\setquadratic \\plot\n%   .6125  1.5633   .5425  1.5803   .4550  1.5983   .3500  1.6157\n%   .2450  1.6284   .1225  1.6376   .0000  1.6407\n% /\n% \\setquadratic \\plot\n%   .0000  2.6529   .1400  2.6499   .2800  2.6408   .4200  2.6258\n%   .5425  2.6075   .6499  2.5875   .7729  2.5600   .8575  2.5382\n%   .9450  2.5130\n% /\n% \\setquadratic \\plot\n%   1.2075  2.4206   1.2950  2.3840   1.3914  2.3400   1.4875  2.2922\n%   1.5750  2.2450   1.6483  2.2025   1.7325  2.1504   1.8025  2.1042\n%   1.8900  2.0424   1.9600  1.9896   2.0371  1.9275   2.1013  1.8725\n%   2.1875  1.7935   2.2575  1.7244   2.3275  1.6504   2.4212  1.5425\n%   2.5076  1.4325   2.5725  1.3416   2.6388  1.2400   2.6775  1.1757\n%   2.7300  1.0813   2.7615  1.0200   2.8000   .9390   2.8175   .8995\n%   2.8475   .8275   2.8686   .7725   2.8875   .7197   2.9050   .6671\n%   2.9225   .6100   2.9386   .5525   2.9526   .4975   2.9651   .4425\n%   2.9813   .3600   2.9903   .3050   2.9979   .2500   3.0042   .1950\n%   3.0090   .1400   3.0109   .1125   3.0136   .0575   3.0148   .0025\n%   3.0149  -.0250   3.0139  -.0800   3.0115  -.1350   3.0097  -.1625\n%   3.0049  -.2175   2.9985  -.2725   2.9905  -.3275   2.9808  -.3825\n%   2.9693  -.4375   2.9575  -.4865   2.9487  -.5200   2.9400  -.5501\n%   2.9225  -.6057   2.9043  -.6575   2.8827  -.7125   2.8525  -.7809\n%   2.8175  -.8507   2.7871  -.9050   2.7530  -.9600   2.7300  -.9945\n%   2.6950 -1.0425   2.6775 -1.0651   2.6502 -1.0975   2.6253 -1.1250\n%   2.6075 -1.1436   2.5900 -1.1592   2.5395 -1.1800   2.5368 -1.1800\n%   2.5025 -1.1697   2.4738 -1.1525   2.4500 -1.1405   2.4221 -1.1250\n%   2.3800 -1.1065   2.3450 -1.0932   2.2925 -1.0783   2.2050 -1.0660\n%   2.1175 -1.0704   2.0650 -1.0818   2.0125 -1.1016   1.9775 -1.1206\n%   1.9425 -1.1459   1.9250 -1.1618   1.8900 -1.2044   1.8556 -1.2900\n%   1.8529 -1.3175   1.8550 -1.3500   1.8696 -1.4000   1.8856 -1.4275\n%   1.9075 -1.4528   1.9489 -1.4825   2.0125 -1.5039   2.1000 -1.5042\n%   2.1875 -1.4811   2.2400 -1.4581   2.2750 -1.4393   2.2969 -1.4275\n%   2.3275 -1.4078   2.3625 -1.3843   2.3975 -1.3593   2.4184 -1.3450\n%   2.4500 -1.3204   2.4675 -1.3064   2.5025 -1.2817   2.5550 -1.2687\n%   2.5900 -1.2935   2.6103 -1.3175   2.6425 -1.3656   2.6597 -1.4000\n%   2.6775 -1.4446   2.6995 -1.5375   2.7039 -1.5925   2.7021 -1.6475\n%   2.6950 -1.6971   2.6882 -1.7300   2.6717 -1.7850   2.6600 -1.8159\n%   2.6425 -1.8578   2.6264 -1.8950   2.6142 -1.9225   2.6022 -1.9500\n%   2.5807 -2.0050   2.5651 -2.0600   2.5582 -2.1150   2.5630 -2.1700\n%   2.5840 -2.2250   2.6035 -2.2525   2.6337 -2.2800   2.6775 -2.3041\n%   2.7125 -2.3149\n% /\n% \\setquadratic \\plot\n%   2.7125 -2.3640   2.6950 -2.3568   2.6600 -2.3402\n% /\n% \\setquadratic \\plot\n%   2.6600 -2.4085   2.6775 -2.4194   2.7125 -2.4397\n% /\n% \\setquadratic \\plot\n%   2.9750 -2.3417   3.0176 -2.3625   3.0625 -2.4036   3.0871 -2.4450\n%   3.1036 -2.5000\n% /\n% \\setquadratic \\plot\n%   2.1525 -2.4999   2.1175 -2.4686   2.0650 -2.4221   2.0475 -2.4065\n%   2.0282 -2.3900\n% /\n% \\setquadratic \\plot\n%   1.9250 -2.3011   1.8725 -2.2575   1.8323 -2.2250\n% /\n% \\setquadratic \\plot\n%   1.7325 -2.1461   1.6975 -2.1191   1.6625 -2.0923   1.6275 -2.0657\n%   1.5832 -2.0325   1.5467 -2.0050   1.5050 -1.9735   1.4700 -1.9473\n%   1.4175 -1.9075   1.3825 -1.8813   1.3300 -1.8422   1.2950 -1.8160\n%   1.2600 -1.7899   1.2250 -1.7641   1.1900 -1.7386   1.1550 -1.7133\n%   1.1025 -1.6766   1.0675 -1.6524   1.0325 -1.6288    .9975 -1.6059\n%   .9450 -1.5728   .9100 -1.5516   .8575 -1.5212   .8225 -1.5019\n%   .7852 -1.4825   .7350 -1.4573   .6825 -1.4328   .6300 -1.4102\n%   .5775 -1.3895   .5250 -1.3709   .4550 -1.3486   .4200 -1.3387\n%   .3500 -1.3214\n% /\n% \\setquadratic \\plot\n%   .3150 -1.0326   .3566 -1.0425   .4200 -1.0592   .4725 -1.0756\n%   .5339 -1.0975   .5775 -1.1144   .6300 -1.1370   .6650 -1.1535\n%   .7176 -1.1800   .7682 -1.2075   .8151 -1.2350   .8575 -1.2613\n%   .8925 -1.2841   .9275 -1.3080   .9625 -1.3330   .9975 -1.3589\n%   1.0500 -1.4000   1.0841 -1.4275   1.1200 -1.4572   1.1550 -1.4868\n%   1.1900 -1.5170   1.2250 -1.5478   1.2600 -1.5789   1.3055 -1.6200\n%   1.3475 -1.6574\n% /\n% \\setquadratic \\plot\n%   1.3977 -1.7025   1.4289 -1.7300   1.4604 -1.7575   1.4923 -1.7850\n%   1.5245 -1.8125   1.5572 -1.8400   1.5750 -1.8544\n% /\n% \\setquadratic \\plot\n%   1.7150 -1.9682   1.7500 -1.9963   1.7945 -2.0325\n% /\n% \\setquadratic \\plot\n%   1.9250 -2.1418   1.9572 -2.1700   1.9878 -2.1975\n% /\n% \\setquadratic \\plot\n%   1.8834 -2.5000   1.8470 -2.4725   1.8025 -2.4391   1.7675 -2.4135\n%   1.7150 -2.3753   1.6800 -2.3504   1.6450 -2.3259   1.6100 -2.3017\n%   1.5575 -2.2657   1.5225 -2.2421   1.4875 -2.2190   1.4350 -2.1843\n%   1.3825 -2.1505   1.3475 -2.1282   1.2950 -2.0953   1.2600 -2.0737\n%   1.2075 -2.0419   1.1725 -2.0211   1.1200 -1.9905   1.0850 -1.9708\n%   1.0325 -1.9418    .9959 -1.9225    .9450 -1.8961    .9100 -1.8783\n%   .8575 -1.8531   .8225 -1.8373   .7655 -1.8125   .7175 -1.7925\n%   .6650 -1.7723   .6229 -1.7575   .5600 -1.7364   .5075 -1.7207\n%   .4378 -1.7025   .4025 -1.6938   .3500 -1.6828\n% /\n% \\setquadratic \\plot\n%   .3850 -2.0145   .4550 -2.0291   .5250 -2.0455   .5775 -2.0600\n%   .6300 -2.0748   .6825 -2.0915   .7506 -2.1150   .8050 -2.1346\n%   .8575 -2.1550   .8933 -2.1700   .9578 -2.1975   .9975 -2.2148\n%   1.0500 -2.2390   1.0850 -2.2560   1.1375 -2.2819   1.1900 -2.3086\n%   1.2425 -2.3361   1.2950 -2.3644   1.3475 -2.3934   1.3897 -2.4175\n%   1.4372 -2.4450   1.4837 -2.4725   1.5293 -2.5000\n% /\n% \\setquadratic \\plot\n%   1.1130 -2.5000   1.0675 -2.4797   1.0150 -2.4574    .9625 -2.4362\n%   .9100 -2.4163   .8575 -2.3967   .8050 -2.3782   .7525 -2.3614\n%   .6651 -2.3350   .5950 -2.3156   .5250 -2.2986   .4550 -2.2839\n%   .3850 -2.2708\n% /\n% \\setquadratic \\plot\n%   1.9189 -1.3725   1.9334 -1.4000   1.9600 -1.4231   1.9950 -1.4345\n%   2.0437 -1.4275   2.0977 -1.3725   2.1035 -1.3450   2.1000 -1.3161\n%   2.0650 -1.2678   2.0300 -1.2529   1.9672 -1.2625   1.9195 -1.3175\n%   1.9189 -1.3725\n% /\n% \\setquadratic \\plot\n%   2.6238 -2.1975   2.6414 -2.2250   2.6775 -2.2483   2.7125 -2.2539\n%   2.7475 -2.2466   2.7825 -2.2261   2.8065 -2.1975   2.8175 -2.1662\n%   2.8197 -2.1425   2.8135 -2.1150   2.7957 -2.0875   2.7475 -2.0606\n%   2.7125 -2.0591   2.6775 -2.0692   2.6301 -2.1150   2.6196 -2.1425\n%   2.6238 -2.1975\n% /\n% \\setdashes\n% \\setquadratic \\plot\n%    .1570 -2.5000    .1606 -2.4450    .1662 -2.3625\n% /\n% \\setquadratic \\plot\n%    .1808 -2.1700    .1831 -2.1425    .1878 -2.0875\n% /\n% \\setquadratic \\plot\n%    .2065 -1.8950    .2124 -1.8400    .2220 -1.7575\n% /\n% \\setquadratic \\plot\n%    .2474 -1.5650    .2598 -1.4825    .2732 -1.4000\n% /\n% \\setquadratic \\plot\n%   .3090 -1.2075   .3265 -1.1250   .3500 -1.0229   .3675  -.9527\n%   .3875  -.8775   .4030  -.8225   .4276  -.7400   .4449  -.6850\n%   .4724  -.6025   .4900  -.5525   .5075  -.5045   .5250  -.4582\n%   .5439  -.4100   .5600  -.3701   .5777  -.3275   .5950  -.2871\n%   .6135  -.2450   .6300  -.2085   .6514  -.1625   .6650  -.1337\n%   .6912  -.08000   .7049  -.05250   .7330   .00250   .7474   .03000\n%   .7620   .0575   .7769   .0850   .8050   .1362   .8225   .1672\n%   .8384   .1950   .8543   .2225   .8750   .2577   .8925   .2870\n%   .9202   .3325   .9450   .3726   .9719   .4150   .9975   .4550\n%   1.0253   .4975   1.0435   .5250   1.0619   .5525\n% /\n% \\setquadratic \\plot\n%   1.1900   .7367   1.2159   .7725   1.2562   .8275   1.2775   .8563\n%   1.3178   .9100   1.3475   .9492   1.3825   .9948   1.4235  1.0475\n%   1.4668  1.1025   1.5050  1.1505   1.5400  1.1941   1.5773  1.2400\n%   1.6275  1.3013   1.6679  1.3500   1.7138  1.4050   1.7500  1.4480\n%   1.8025  1.5099   1.8375  1.5508   1.8900  1.6118   1.9425  1.6723\n%   1.9950  1.7323   2.0458  1.7900   2.0945  1.8450   2.1434  1.9000\n%   2.1926  1.9550   2.2421  2.0100   2.2925  2.0658   2.3450  2.1237\n%   2.4150  2.2005   2.4672  2.2575   2.5200  2.3149   2.5725  2.3718\n%   2.6425  2.4474   2.6950  2.5039   2.7475  2.5602   2.8175  2.6351\n%   2.8761  2.6975   2.9400  2.7656   3.0100  2.8398   3.0835  2.9175\n%   3.1618  3.0000\n% /\n% \\setquadratic \\plot\n%   3.5000  -.00009   3.0625  -.00113   2.6075  -.00962   2.4675  -.01671\n%   2.3275  -.02768   2.2225  -.03918   2.1284  -.05250   2.0650  -.06316\n%   1.9807  -.0800   1.9250  -.0927   1.8550  -.1109   1.8025  -.1262\n%   1.7500  -.1430   1.7150  -.1551   1.6800  -.1680   1.6450  -.1816\n%   1.6100  -.1960   1.5750  -.2113   1.5400  -.2274   1.5050  -.2446\n%   1.4700  -.2625   1.4516  -.2725   1.4029  -.3000   1.4000  -.3016\n%   1.3650  -.3227\n% /\n% \\setquadratic \\plot\n%   1.1550  -.4757   1.1357  -.4925   1.1025  -.5223   1.0758  -.5475\n%   1.0477  -.5750   1.0150  -.6087    .9800  -.6467    .9468  -.6850\n%   .9241  -.7125   .8925  -.7523   .8575  -.7993   .8225  -.8494\n%   .7875  -.9029   .7691  -.9325   .7350  -.9905   .7000 -1.0546\n%   .6650 -1.1240   .6388 -1.1800   .6030 -1.2625   .5704 -1.3450\n%   .5407 -1.4275   .5050 -1.5375   .4725 -1.6498   .4317 -1.8125\n%   .3964 -1.9775   .3911 -2.0050   .3850 -2.0371\n% /\n% \\setquadratic \\plot\n%   .3758 -2.0875   .3675 -2.1352   .3617 -2.1700\n% /\n% \\setquadratic \\plot\n%   .3323 -2.3625   .3212 -2.4450   .3141 -2.5000\n% /\n% \\setquadratic \\plot\n%   .4712 -2.5000   .5166 -2.2800   .5775 -2.0388   .6210 -1.8950\n%   .6795 -1.7300   .7175 -1.6370   .7700 -1.5231   .8203 -1.4275\n%   .8692 -1.3450   .9052 -1.2900   .9450 -1.2341   .9873 -1.1800\n%   1.0346 -1.1250   1.0850 -1.0724   1.1200 -1.0392   1.1375 -1.0235\n%   1.1550 -1.0085\n% /\n% \\setquadratic \\plot\n%   1.2491 -1.2900   1.2075 -1.3271   1.1550 -1.3798   1.0896 -1.4550\n%   1.0325 -1.5304    .9625 -1.6373    .8925 -1.7628    .8060 -1.9500\n%   .7333 -2.1425   .6808 -2.3075   .6283 -2.5000\n% /\n% \\setquadratic \\plot\n%   1.2566 -2.5000   1.3475 -2.3310   1.4525 -2.1615   1.5050 -2.0851\n%   1.5750 -1.9902\n% /\n% \\setquadratic \\plot\n%   1.7150 -1.8177   1.7500 -1.7765   1.8025 -1.7145   1.8351 -1.6750\n%   1.8725 -1.6276   1.8981 -1.5925   1.9337 -1.5375   1.9488 -1.5100\n%   1.9729 -1.4550   1.9815 -1.4275   1.9903 -1.3725\n% /\n% \\setquadratic \\plot\n%   1.9950 -1.3666   2.0087 -1.3725   2.0262 -1.4000   2.0475 -1.4630\n%   2.0516 -1.5100   2.0475 -1.5480   2.0369 -1.5925   2.0148 -1.6475\n%   1.9950 -1.6852   1.9487 -1.7575   1.9075 -1.8131   1.8375 -1.9009\n%   1.7528 -2.0050   1.6461 -2.1425   1.5400 -2.2933   1.4782 -2.3900\n%   1.4135 -2.5000\n% /\n% \\setquadratic \\plot\n%   1.5704 -2.5000   1.6612 -2.3625   1.7621 -2.2250\n% /\n% \\setquadratic \\plot\n%   1.9200 -2.0325   1.9600 -1.9862   2.0125 -1.9253   2.0383 -1.8950\n%   2.0825 -1.8410   2.1046 -1.8125   2.1436 -1.7575   2.1609 -1.7300\n%   2.1875 -1.6794   2.2160 -1.5925   2.2195 -1.5375   2.2087 -1.4825\n%   2.1961 -1.4550   2.1767 -1.4275   2.1525 -1.4048   2.1175 -1.3825\n%   2.0825 -1.3680   2.0475 -1.3597   1.9950 -1.3581\n% /\n% \\setquadratic \\plot\n%   1.9950 -1.3496   2.0047 -1.3450   2.0274 -1.3175   2.0475 -1.2923\n%   2.0650 -1.2686   2.0825 -1.2421   2.1000 -1.2101   2.1199 -1.1525\n%   2.1253 -1.0975   2.1176 -1.0425   2.1088 -1.0150   2.0825  -.9640\n%   2.0475  -.9197   1.9996  -.8775   1.9569  -.8500   1.9075  -.8262\n%   1.8550  -.8081   1.8025  -.7963   1.7500  -.7895   1.6625  -.7885\n%   1.5925  -.7963   1.5225  -.8110   1.4700  -.8267   1.4525  -.8328\n%   1.4175  -.8463\n% /\n% \\setquadratic \\plot\n%   1.4875 -1.1440   1.5400 -1.1263   1.5925 -1.1134   1.6975 -1.1042\n%   1.8156 -1.1250   1.8550 -1.1413   1.8900 -1.1624   1.9116 -1.1800\n%   1.9385 -1.2075   1.9583 -1.2350   1.9725 -1.2625   1.9775 -1.2734\n%   1.9884 -1.3175\n% /\n% \\setquadratic \\plot\n%   1.9648 -2.1975   2.0151 -2.1425   2.0681 -2.0875   2.1175 -2.0388\n%   2.1535 -2.0050   2.1875 -1.9744   2.2400 -1.9296   2.2750 -1.9018\n%   2.3100 -1.8757   2.3450 -1.8516   2.3975 -1.8197   2.4500 -1.7936\n%   2.5025 -1.7744   2.6075 -1.7607   2.7125 -1.7884   2.7650 -1.8278\n%   2.8000 -1.8784   2.8145 -1.9225   2.8171 -1.9500   2.8101 -2.0050\n%   2.7866 -2.0600   2.7693 -2.0875   2.7481 -2.1150   2.7253 -2.1425\n%   2.6950 -2.1732\n% /\n% \\setquadratic \\plot\n%   2.6950 -2.1913   2.7092 -2.1975   2.7235 -2.2250   2.7311 -2.2525\n%   2.7329 -2.3075\n% /\n% \\setquadratic \\plot\n%   2.7125 -2.3800   2.6940 -2.4175   2.6600 -2.4710\n% /\n% \\setquadratic \\plot\n%   2.6517 -2.3075   2.6772 -2.2525   2.6896 -2.1975\n% /\n% \\setquadratic \\plot\n%   2.6950 -2.1822   2.7475 -2.1854   2.7825 -2.2003   2.8141 -2.2250\n%   2.8336 -2.2525   2.8350 -2.2559   2.8500 -2.3075\n% /\n% \\setquadratic \\plot\n%   2.9976 -2.5000   3.0416 -2.4725   3.0800 -2.4525   3.1150 -2.4391\n%   3.1675 -2.4278   3.2375 -2.4330   3.2900 -2.4570   3.3091 -2.4725\n%   3.3322 -2.5000\n% /\n% \\setquadratic \\plot\n%   2.6875 -2.1425   2.6775 -2.1093   2.6425 -2.0605   2.6075 -2.0351\n%   2.5725 -2.0205   2.4850 -2.0133   2.3975 -2.0349   2.3427 -2.0600\n%   2.2925 -2.0896   2.2400 -2.1266   2.1875 -2.1694   2.1868 -2.1700\n%   2.1559 -2.1975\n% /\n% \\setquadratic \\plot\n%   1.9735 -2.3900   1.9285 -2.4450   1.8856 -2.5000\n% /\n% \\setquadratic \\plot\n%   1.9250 -2.2431   1.8550 -2.3281   1.7866 -2.4175   1.7665 -2.4450\n%   1.7277 -2.5000\n% /\n% \\setquadratic \\plot\n%   2.5023 -2.5000   2.5025 -2.4998   2.5200 -2.4802\n% /\n% \\setquadratic \\plot\n%    .7855 -2.5000    .8828 -2.2250   1.0087 -1.9500   1.1047 -1.7850\n%   1.2250 -1.6199   1.3300 -1.5067   1.4525 -1.4054   1.5225 -1.3611\n%   1.6100 -1.3192   1.6625 -1.3012   1.7325 -1.2860   1.8200 -1.2825\n%   1.8900 -1.2952   1.9250 -1.3079   1.9600 -1.3264   1.9775 -1.3393\n%   1.9950 -1.3534\n% /\n% \\setquadratic \\plot\n%   1.9950 -1.3592   1.9425 -1.3581   1.8900 -1.3673   1.8550 -1.3768\n%   1.7908 -1.4000   1.7327 -1.4275   1.6839 -1.4550   1.6450 -1.4799\n%   1.6023 -1.5100\n% /\n% \\setquadratic \\plot\n%   1.3955 -1.7025   1.3300 -1.7811   1.2659 -1.8675   1.1937 -1.9775\n%   1.1200 -2.1056   1.0338 -2.2800    .9625 -2.4483    .9531 -2.4725\n%    .9426 -2.5000\n% /\n% \\setquadratic \\plot\n%   1.0996 -2.5000   1.1900 -2.3103   1.2950 -2.1234   1.3650 -2.0150\n%   1.4350 -1.9173   1.4875 -1.8501   1.5422 -1.7850   1.5916 -1.7300\n%   1.6441 -1.6750   1.6800 -1.6393   1.7288 -1.5925   1.7585 -1.5650\n%   1.7889 -1.5375   1.8200 -1.5099   1.8550 -1.4793   1.8822 -1.4550\n%   1.9075 -1.4334   1.9250 -1.4183   1.9600 -1.3878   1.9719 -1.3725\n%   1.9950 -1.3650\n% /\n% \\setquadratic \\plot\n%   2.2254 -2.3075   2.3100 -2.2365   2.3975 -2.1791   2.4500 -2.1540\n%   2.5200 -2.1334   2.5900 -2.1303   2.6425 -2.1441   2.6775 -2.1609\n%   2.6950 -2.1791\n% /\n% \\setquadratic \\plot\n%   2.6950 -2.1847   2.6425 -2.1822   2.5900 -2.1963   2.5375 -2.2192\n%   2.4850 -2.2490   2.4500 -2.2725   2.4034 -2.3075\n% /\n% \\setquadratic \\plot\n%   2.4150 -2.4399   2.4653 -2.3900   2.5200 -2.3377\n% /\n% \\setquadratic \\plot\n%   2.5522 -2.3075   2.5725 -2.2891   2.6075 -2.2568   2.6250 -2.2412\n%   2.6600 -2.2097   2.6687 -2.1975   2.6950 -2.1902\n% /\n% \\setquadratic \\plot\n%   2.1419 -2.3900   2.0915 -2.4450   2.0442 -2.5000\n% /\n% \\endpicture\\vspace{-5pt}\n%\\centerline{$\\Re z$}\\vspace{5pt}\n%\\centerline{\\bf Modulus and phase of $w(z).$}\n%\n\\subparagraph{Accuracy Tests}\n\nThe accuracy of the approximations was analyzed by Poppe and Wijers. They\nconcluded that relative accuracy is maintained within~14 significant digits,\nexcept inside a circle of radius~0.126 around a zero of the function (all\nzeros of $w(z)$ are in the lower half-plane), where absolute accuracy is\nretained but relative accuracy is not. They also compared the accuracy of $%\nw(z)$ to $\\erfc z$ for several purely imaginary values of $z$. Their testing\nprocedure is reported in \\cite{Poppe:1990:MEC}.\n\nWe tested CWOFZ in four regions along the imaginary axis, where $w(z)$ is\nreal, on an IBM PC/AT, by comparing to DERFCE. Each region was divided into\n500 subregions, and a point was randomly selected in each subregion. The\nmaximum errors are shown below, where ULP means ``error in units of last\nposition of the reference result,\" and $\\rho \\approx 1.192\\times 10^{- 7}$ is the\nround-off level for IEEE single precision arithmetic.\\vspace{-5pt}\n\\begin{center}\n\\begin{tabular}{lrrr}\n\\multicolumn{1}{c}{\\bf Range} & {\\bf ULP} &\n\\multicolumn{1}{c}{\\bf Absolute} & \\multicolumn{1}{c}{\\bf Relative}\\\\\n$[$0..0.75$]$ & 2.42 & 1.21 $\\rho $\\rule{.1in}{0pt} & 2.29 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$0.75..1.2848$]$ & 19.05 & 4.76 $\\rho $\\rule{.1in}{0pt} & 12.95 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$1.2848..4.4$]$ & 6.05 & 1.23 $\\rho $\\rule{.1in}{0pt} & 3.49 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$4.4..100$]$ & 2.19 & 0.12 $\\rho $\\rule{.1in}{0pt} & 1.43 $\\rho $\\rule{.05in}{0pt}\n\\end{tabular}\n\\end{center}\\vspace{-5pt}\nIn the range [0.75..1.2848] errors grow as $x$ increases. Errors are four\ntimes larger near~1.2848 than near~0.75.\n\nWe tested ZWOFZ in five regions along the imaginary axis, where $w(z)$ is\nreal, on an IBM PC/AT, by comparing to an extended precision calculation of $%\n\\exp (x^2) \\erfc x.$ Each region was divided into~200 subregions, and a\npoint was randomly selected in each subregion. The maximum errors are shown\nbelow, where $\\rho \\approx 2.22\\times 10^{-16}$ is the round-off level for IEEE\ndouble precision arithmetic.\\vspace{-5pt}\n\\begin{center}\n\\begin{tabular}{lrrr}\n\\multicolumn{1}{c}{\\bf Range} & {\\bf ULP} &\n\\multicolumn{1}{c}{\\bf Absolute} & \\multicolumn{1}{c}{\\bf Relative}\\\\\n$[$0..0.75$]$ & 1.47 & 0.73 $\\rho $\\rule{.1in}{0pt} & 1.35 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$0.75..1.2848$]$ & 14.29 & 3.57 $\\rho $\\rule{.1in}{0pt} & 9.84 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$1.2848..3.4469$]$ & 6.23 & 0.78 $\\rho $\\rule{.1in}{0pt} & 4.44 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$3.4469..4.4$]$ & 14.20 & 1.78 $\\rho $\\rule{.1in}{0pt} & 13.42 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$4.4..100$]$ & 3.02 & 0.19 $\\rho $\\rule{.1in}{0pt} & 1.52 $\\rho $\\rule{.05in}{0pt}\n\\end{tabular}\n\\end{center}\\vspace{-5pt}\nIn the range [0.75..1.2848] errors grow as $x$ increases. Errors are four\ntimes larger near~1.2848 than near~0.75.\n\nWe tested ZWOFZ in four regions along the real axis on an IBM PC/AT, by\ncomparing the imaginary part of the result to an extended precision\ncalculation of Dawson's integral, $F(x)$. Each region was divided into~200\nsubregions, and a point was randomly selected in each subregion. The maximum\nerrors are as follows.\\vspace{-5pt}\n\\begin{center}\n\\begin{tabular}{lrrr}\n\\multicolumn{1}{c}{\\bf Range} & {\\bf ULP} &\n\\multicolumn{1}{c}{\\bf Absolute} & \\multicolumn{1}{c}{\\bf Relative}\\\\\n$[$0..1.83960$]$ & 2.21 & 0.93 $\\rho $\\rule{.1in}{0pt} & 1.73 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$1.8396..2.95$]$ & 17.28 & 3.90 $\\rho $\\rule{.1in}{0pt} & 11.20 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$2.95..6.3$]$ & 8.99 & 1.12 $\\rho $\\rule{.1in}{0pt} & 6.24 $\\rho $\\rule{.05in}{0pt}\\\\\n$[$6.3..100$]$ & 1.59 & 0.06 $\\rho $\\rule{.1in}{0pt} & 0.90 $\\rho $\\rule{.05in}{0pt}\n\\end{tabular}\n\\end{center}\\vspace{-5pt}\nWe tested ZWOFZ along the real axis on an IBM PC/AT, by comparing the real\npart of the result to an extended precision calculation of $\\exp (-x^2)$, in\nthe range [0..10]. The maximum error was 2.04~ULP; the maximum absolute\nerror was 0.26\\ $\\rho $; the maximum relative error was 0.45\\ $\\rho $. The\nlargest errors occurred near the change of method at $x = 1.8396.$\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\n$w(z)$ is computable throughout the upper half plane without restriction. To\ncompute $w(z)$ in the lower half plane we use $w(-z) = 2 \\exp (-z^2)-w(z)$.\nSince $\\exp (-z^2) = \\exp (\\Re z^2) [\\cos (\\Im z^2) + i \\sin(\\Im z^2)]$, we\nmust have $x^2 - y^2 < \\ln \\ \\Omega $, where $\\Omega $ is the largest\nrepresentable floating point number. Argument reduction in computing sin and\ncos causes loss of precision, and so we restrict $2|xy| < \\rho ^{-1/2}$,\nwhere $\\rho $ is the smallest positive number such that the floating point\nrepresentation of $1.0 + \\rho $ is different from~1.0. If $y < 0$ and $x^2 -\ny^2 \\geq \\ln \\ \\Omega $ the error processor (see Chapter~19.2) is invoked\nwith LEVEL = 2, and IFLAG is set to $-$1. If $y < 0$ and $2|xy| \\geq \\rho\n^{-1/2}$ the error message processor is invoked with LEVEL = 2, and IFLAG is\nset to +1. The usual action of the error message processor when invoked with\nLEVEL = 2 is to halt execution of the program. This action may be altered by\ncalling ERMSET (see Chapter~19.2).\n\n\\subsection{Supporting Information}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nCWOFZ & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, CWOFZ, ERFIN, ERMOR, ERMSG, SERV1\\rule[-5pt]{0pt}{8pt}}\\\\ZWOFZ & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERV1, ERFIN, ERMOR, ERMSG, ZWOFZ\\rule[-5pt]{0pt}{8pt}}\\\\\\end{tabular}\n\nPresent version converted from ACM TOMS Algorithm~680, \\cite{Poppe:1990:AEC}, by W.\nV. Snyder, 1991.\n\n\n\\begcodenp\n\n\\medskip\\\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRCWOFZ}\\vspace{5pt}\n\\lstinputlisting{\\codeloc{cwofz}}\n\n\\vspace{10pt}\\centerline{\\bf \\large ODCWOFZ}\\vspace{5pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{cwofz}}\n\\closegraphsfile\n\\end{document}\n", "meta": {"hexsha": "23827a05170708f36d247ff87aee313bd865aff3", "size": 32948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch02-16.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/ch02-16.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/ch02-16.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": 44.9495225102, "max_line_length": 122, "alphanum_fraction": 0.6012201044, "num_tokens": 16955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568417, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6184649243953112}}
{"text": "\\chapter{mathematical tool solutions}\n\\begin{abox}\n\tPractice set 1 solutions\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item Consider a particle in a one dimensional potential that satisfies $V(x)=V(-x)$. Let $\\left|\\psi_{0}\\right\\rangle$ and $\\left|\\psi_{1}\\right\\rangle$ denote the ground and the first excited states, respectively, and let $|\\psi\\rangle=\\alpha_{0}\\left|\\psi_{0}\\right\\rangle+\\alpha_{1}\\left|\\psi_{1}\\right\\rangle$ be a normalized state with $\\alpha_{0}$ and $\\alpha_{1}$ being real constants. The expectation value $\\langle x\\rangle$ of the position operator $x$ in the state $|\\psi\\rangle$ is given by\n\t\t\\exyear{NET DEC 2011}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\alpha_{0}^{2}\\left\\langle\\psi_{0}|x| \\psi_{0}\\right\\rangle+\\alpha_{1}^{2}\\left\\langle\\psi_{1}|x| \\psi_{1}\\right\\rangle$\n\t\t\\task[\\textbf{B.}]$\\alpha_{0} \\alpha_{1}\\left[\\left\\langle\\psi_{0}|x| \\psi_{1}\\right\\rangle+\\left\\langle\\psi_{1}|x| \\psi_{0}\\right\\rangle\\right]$\n\t\t\\task[\\textbf{C.}]$\\alpha_{0}^{2}+\\alpha_{1}^{2}$\n\t\t\\task[\\textbf{D.}]$2 \\alpha_{0} \\alpha_{1}$\n\t\\end{tasks}\n\\begin{answer}\n Since $V(x)=V(-x)$ so potential is symmetric.\n\t$$\n\t\\begin{aligned}\n\t&\\left\\langle\\psi_{0}|x| \\psi_{0}\\right\\rangle=0,\\left\\langle\\psi_{1}|x| \\psi_{1}\\right\\rangle=0 \\\\\n\t&\\langle\\psi|x| \\psi\\rangle=\\left(\\alpha _ { 0 } \\left\\langle\\psi_{0}\\left|+\\alpha_{1}\\left\\langle\\psi_{1}\\right|\\right) \\times\\left(\\alpha_{0}\\left|\\psi_{0}\\right\\rangle+\\alpha_{1}\\left|\\psi_{1}\\right\\rangle\\right)=\\alpha_{0} \\alpha_{1}\\left[\\left\\langle\\psi_{0}|x| \\psi_{1}\\right\\rangle+\\left\\langle\\psi_{1}|x| \\psi_{0}\\right\\rangle\\right]\\right.\\right.\n\t\\end{aligned}\n\t$$\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The wave function of a particle at time $t=0$ is given by $|\\psi(0)\\rangle=\\frac{1}{\\sqrt{2}}\\left(\\left|u_{1}\\right\\rangle+\\left|u_{2}\\right\\rangle\\right)$, where\n\t$\\left|u_{1}\\right\\rangle$ and $\\left|u_{2}\\right\\rangle$ are the normalized eigenstates with eigenvalues $E_{1}$ and $E_{2}$ respectively, $\\left(E_{2}>E_{1}\\right)$. The shortest time after which $|\\psi(t)\\rangle$ will become orthogonal to $|\\psi(0)\\rangle$ is\n\t\\exyear{NET DEC 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{-\\hbar \\pi}{2\\left(E_{2}-E_{1}\\right)}$\n\t\\task[\\textbf{B.}]$\\frac{\\hbar \\pi}{E_{2}-E_{1}}$\n\t\\task[\\textbf{C.}]$\\frac{\\sqrt{2} \\hbar \\pi}{E_{2}-E_{1}}$\n\t\\task[\\textbf{D.}]$\\frac{2 \\hbar \\pi}{E_{2}-E_{1}}$\n\\end{tasks}\n\\begin{answer}\n\t$|\\psi(0)\\rangle=\\frac{1}{\\sqrt{2}}\\left(\\left|u_{1}\\right\\rangle+\\left|u_{2}\\right\\rangle\\right) \\Rightarrow|\\psi(t)\\rangle=\\frac{1}{\\sqrt{2}}\\left(\\left|u_{1}\\right\\rangle e^{\\frac{-i E_{1} t}{\\hbar}}+\\left|u_{2}\\right\\rangle e^{\\frac{-i E_{2} t}{\\hbar}}\\right)$\\\\\n\t$|\\psi(t)\\rangle$ is orthogonal to $|\\psi(0)\\rangle \\Rightarrow\\langle\\psi(0) \\mid \\psi(t)\\rangle=0 \\Rightarrow \\frac{1}{2} e^{\\frac{-i E_{1} t}{\\hbar}}+\\frac{1}{2} e^{\\frac{-i E_{2} t}{\\hbar}}=0$\n\t\\begin{align*}\n\t&\\Rightarrow e^{\\frac{-i E_{1} t}{\\hbar}}+e^{\\frac{-i E_{2} t}{\\hbar}}=0 \\Rightarrow e^{\\frac{-i E_{1} t}{\\hbar}}=-e^{\\frac{-i E_{2} t}{\\hbar}} \\Rightarrow e^{i \\frac{\\left(E_{2}-E_{1}\\right)}{\\hbar}}=-1 \\\\\n\t&\\Rightarrow \\cos \\frac{\\left(E_{2}-E_{1}\\right) t}{\\hbar}=\\cos \\pi \\Rightarrow t=\\frac{\\pi \\hbar}{E_{2}-E_{1}}\n\t\\end{align*}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The commutator }\\left[x^{2}, p^{2}\\right] \\text { is }$\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $2 i \\hbar x p$\n\t\\task[\\textbf{B.}]$2 i \\hbar(x p+p x)$\n\t\\task[\\textbf{C.}]$2 i \\hbar p x$\n\t\\task[\\textbf{D.}]$2 i \\hbar(x p-p x)$\n\\end{tasks}\n\\begin{answer}\n$\\left[x^{2}, p^{2}\\right]=x\\left[x, p^{2}\\right]+\\left[x, p^{2}\\right] x=x p[x, p]+x[x, p] p+p[x, p] x+[x, p] p x$\\\\\n$$\\left[x^{2}, p^{2}\\right]=x p(i \\hbar)+x(i \\hbar) p+p(i \\hbar) x+(i \\hbar) p x=2 i \\hbar(x p+p x)$$\nThe correct option is \\textbf{(b)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Which of the following is a self-adjoint operator in the spherical polar coordinate system $(r, \\theta, \\phi)$ ?\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{i \\hbar}{\\sin ^{2} \\theta} \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{B.}]$-i \\hbar \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{C.}] $-\\frac{i \\hbar}{\\sin \\theta} \\frac{\\partial}{\\partial \\theta}$\n\t\\task[\\textbf{D.}] $-i \\hbar \\sin \\theta \\frac{\\partial}{\\partial \\theta}$\n\\end{tasks}\n\\begin{answer}\n\t$\\frac{-i \\hbar}{\\sin \\theta} \\frac{\\partial}{\\partial \\theta} \\text { is Hermitian. }$\\\\\n\tThe correct option is \\textbf{c}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Given the usual canonical commutation relations, the commutator $[A, B]$ of $A=i\\left(x p_{y}-y p_{x}\\right)$ and $B=\\left(y p_{z}+z p_{y}\\right)$ is\n\t\\exyear{NET DEC 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\hbar\\left(x p_{z}-p_{x} z\\right)$\n\t\\task[\\textbf{B.}]$-\\hbar\\left(x p_{z}-p_{x} z\\right)$\n\t\\task[\\textbf{C.}]$\\hbar\\left(x p_{z}+p_{x} z\\right)$\n\t\\task[\\textbf{D.}]$-\\hbar\\left(x p_{z}+p_{x} z\\right)$\n\\end{tasks}\n\\begin{answer}\n\n\t\\begin{align*}\n\t\t&[A, B]=\\left\\lfloor\\left(i x p_{y}-i y p_{x}\\right),\\left(y p_{z}+z p_{y}\\right)\\right]\\\\\n\t\t&{[A, B]=i\\left[x p_{y}, y p_{z}\\right]-i\\left[y p_{x}, y p_{z}\\right]+i\\left\\lfloor x p_{y}, z p_{y}\\right\\rfloor-i\\left\\lfloor y p_{x}, z p_{y}\\right\\rfloor} \\\\\n\t\t&\\left.\\left.[A, B]=i\\left[x p_{y}, y p_{z}\\right]-0+0-i \\mid y p_{x}, z p_{y}\\right\\rfloor=i\\left[x p_{y}, y p_{z}\\right\\rfloor-i \\mid y p_{x}, z p_{y}\\right\\rfloor \\\\\n\t\t&\\left.[A, B]=i x\\left[p_{y}, y p_{z}\\right\\rfloor+i\\left[x, y p_{z}\\right] p_{y}-i y \\mid p_{x}, z p_{y}\\right\\rfloor-i\\left|y, z p_{y}\\right| p_{x} \\\\\n\t\t&\\left.[A, B]=i x\\left[p_{y}, y p_{z}\\right\\rfloor+0-0-i\\left\\lfloor y, z p_{y}\\right\\rfloor p_{x}=i x \\mid p_{y}, y p_{z}\\right\\rfloor-i\\left\\lfloor y, z p_{y}\\right\\rfloor p_{x} \\\\\n\t\t&{[A, B]=i x \\times(-i \\hbar) p_{z}-i z i \\hbar \\times p_{x}=\\hbar\\left[x p_{z}+z p_{x}\\right]} \\\\\n\t\t&{[A, B]=\\hbar\\left(x p_{z}+p_{x} z\\right)}\n\t\\end{align*}\n\tThe correct option is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If the operators $A$ and $B$ satisfy the commutation relation $[A, B]=I$, where $I$ is the identity operator, then\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[e^{A}, B\\right]=e^{A}$\n\t\\task[\\textbf{B.}]$\\left[e^{A}, B\\right]=\\left[e^{B}, A\\right]$\n\t\\task[\\textbf{C.}]$\\left[e^{A}, B\\right]=\\left[e^{-B}, A\\right]$\n\t\\task[\\textbf{D.}]$\\left[e^{A}, B\\right]=I$\n\\end{tasks}\n\n\\begin{answer}\n\t\\begin{align*}\n\t&[A, B]=I \\text { and } e^{A}=\\left[1+\\frac{A}{1}+\\frac{A^{2}}{\\lfloor 2}+\\ldots \\ldots . .\\right]\\\\\n\t&{\\left[e^{A}, B\\right]=\\left[1+\\frac{A}{1}+\\frac{A^{2}}{L 2}+\\ldots \\ldots . B\\right]=[1, B]+[A, B]+\\frac{\\left[A^{2}, B\\right]}{\\lfloor 2}+\\frac{\\left[A^{3}, B\\right]}{\\lfloor 3} \\ldots .} \\\\\n\t&{\\left[e^{A}, B\\right]=0+I+\\frac{A[A, B]+[A, B] A}{2 !}+\\frac{A\\left[A^{2}, B\\right]+\\left[A^{2}, B\\right] A}{3 !}+\\ldots .} \\\\\n\t&{\\left[e^{A}, B\\right]=1+A+\\frac{A^{2}}{2 !}+\\ldots .=e^{A} \\text { where }[A, B]=I,\\left[A^{2}, B\\right]=2 A \\text { and }\\left[A^{3}, B\\right]=3 A^{2} .}\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Suppose Hamiltonian of a conservative system in classical mechanics is $H=\\omega x p$, where $\\omega$ is a constant and $x$ and $p$ are the position and momentum respectively. The corresponding Hamiltonian in quantum mechanics, in the coordinate representation, is\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar \\omega\\left(x \\frac{\\partial}{\\partial x}-\\frac{1}{2}\\right)$\n\t\\task[\\textbf{B.}]$-i \\hbar \\omega\\left(x \\frac{\\partial}{\\partial x}+\\frac{1}{2}\\right)$\n\t\\task[\\textbf{C.}] $-i \\hbar \\omega x \\frac{\\partial}{\\partial x}$\n\t\\task[\\textbf{D.}]$-\\frac{i \\hbar \\omega}{2} \\times \\frac{\\partial}{\\partial x}$\n\\end{tasks}\n\\begin{answer}\n\t$\\text { Classically } H=\\omega x p \\text {, quantum mechanically } H \\text { must be Hermitian, }$\\\\\n\tSo, $H=\\frac{\\omega}{2}(x p+p x)$ and $H \\psi=\\frac{\\omega}{2}(x p \\psi+p x \\psi)$\n\t\\begin{align*}\n\t&\\Rightarrow H \\psi=\\frac{\\omega}{2}\\left(x(-i \\hbar) \\frac{\\partial \\psi}{\\partial x}+\\frac{-i \\hbar \\partial(x \\psi)}{\\partial x}\\right)=\\frac{\\omega}{2}(-i \\hbar)\\left(x \\frac{\\partial \\psi}{\\partial x}+x \\frac{\\partial \\psi}{\\partial x}+\\psi\\right) \\\\\n\t&\\Rightarrow H \\psi=\\frac{-i \\hbar \\omega}{2}\\left(2 x \\frac{\\partial \\psi}{\\partial x}+\\psi\\right)=-i \\hbar \\omega\\left(x \\frac{\\partial}{\\partial x}+\\frac{1}{2}\\right) \\psi\n\t\\end{align*}\nThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $x$ and $p$ denote, respectively, the coordinate and momentum operators satisfying the canonical commutation relation $[x, p]=i$ in natural units $(\\hbar=1)$. Then the commutator $\\left[x, p e^{-p}\\right]$ is\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i(1-p) e^{-p}$\n\t\\task[\\textbf{B.}]$i\\left(1-p^{2}\\right) e^{-p}$\n\t\\task[\\textbf{C.}]$i\\left(1-e^{-p}\\right)$\n\t\\task[\\textbf{D.}]ipe $^{-p}$\n\\end{tasks}\n\\begin{answer}\n\t$\\because[x, p]=i$\\\\\n\t\\begin{align*}\n\t\t\\left[x, p e^{-p}\\right] &=[x, p] e^{-p}+p\\left[x, e^{-p}\\right]=i e^{-p}+p\\left[x, 1-p+\\frac{p^{2}}{\\lfloor 2}-\\frac{p^{3}}{\\lfloor 3} \\ldots . .\\right] \\\\\n\t\t&=i e^{-p}+p\\left[[x, 1]-[x, p]+\\left[x, \\frac{p^{2}}{L 2}\\right] \\ldots\\right]=i e^{-p}+p\\left[0-i+\\frac{2 i p}{\\lfloor 2}-\\frac{3 i p^{2}}{\\lfloor 3} \\ldots \\ldots\\right] \\\\\n\t\t\\Rightarrow\\left[x, p e^{-p}\\right] &=i e^{-p}-i\\left[p-p^{2}+\\frac{p^{3}}{\\lfloor 2} \\ldots . .\\right]=i e^{-p}-i p e^{-p}=i(1-p) e^{-p}\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The wavefunction of a particle in one-dimension is denoted by $\\psi(x)$ in the coordinate representation and by $\\phi(p)=\\int \\psi(x) e^{\\frac{-i p x}{\\hbar}} d x$ in the momentum representation. If the action of an operator $\\hat{T}$ on $\\psi(x)$ is given by $\\hat{T} \\psi(x)=\\psi(x+a)$, where $a$ is a constant then $\\hat{T} \\phi(p)$ is given by\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{i}{\\hbar} \\operatorname{ap} \\phi(p)$\n\t\\task[\\textbf{B.}]$e^{\\frac{-i a p}{\\hbar}} \\phi(p)$\n\t\\task[\\textbf{C.}]$e^{\\frac{+i a p}{\\hbar}} \\phi(p)$\n\t\\task[\\textbf{D.}]$\\left(1+\\frac{i}{\\hbar} a p\\right) \\phi(p)$\n\\end{tasks}\n\\begin{answer}\n\t$\\phi(p)=\\int \\psi(x) e^{\\frac{-i p x}{\\hbar}} d x$\\\\\n\t\\begin{align*}\n\t\t&T \\psi(x)=\\psi(x+a) \\\\\n\t\t&T \\phi(p)=\\int T \\psi(x) e^{\\frac{-i p x}{\\hbar}} d x=\\int \\psi(x+a) e^{\\frac{-i p x}{\\hbar}} d x=e^{\\frac{i p a}{\\hbar}} \\int \\psi(x+a) e^{\\frac{-i p(x+a)}{\\hbar}} d x \\\\\n\t\t&\\Rightarrow T \\phi(p)=e^{\\frac{i p a}{\\hbar}} \\phi(p)\n\t\\end{align*}\n\tThe correct option is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Two different sets of orthogonal basis vectors $\\left\\{\\left(\\begin{array}{l}1 \\\\ 0\\end{array}\\right),\\left(\\begin{array}{l}0 \\\\ 1\\end{array}\\right)\\right\\}$ and $\\left\\{\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{l}1 \\\\ 1\\end{array}\\right), \\frac{1}{\\sqrt{2}}\\left(\\begin{array}{c}1 \\\\ -1\\end{array}\\right)\\right\\}$ are given for a two dimensional real vector space. The matrix representation of a linear operator $\\hat{A}$ in these basis are related by a unitary transformation. The unitary matrix may be chosen to be\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left(\\begin{array}{cc}0 & -1 \\\\ 1 & 0\\end{array}\\right)$\n\t\\task[\\textbf{B.}]$\\left(\\begin{array}{ll}0 & 1 \\\\ 1 & 0\\end{array}\\right)$\n\t\\task[\\textbf{C.}]$\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{cc}1 & 1 \\\\ 1 & -1\\end{array}\\right)$\n\t\\task[\\textbf{D.}] $\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{ll}1 & 0 \\\\ 1 & 1\\end{array}\\right)$\n\\end{tasks}\n\\begin{answer}\n$u_{1}=\\left(\\begin{array}{ll}\n\t1 & 0 \\\\\n\t0 & 1\n\\end{array}\\right), u_{2}=\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{cc}\n\t1 & 1 \\\\\n\t1 & -1\n\\end{array}\\right) \\Rightarrow u=u_{1} \\otimes u_{2}=\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{cc}\n\t1 & 1 \\\\\n\t1 & -1\n\\end{array}\\right)$\\\\\nThe correct option is \\textbf{(c)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\\item A Hermitian operator $\\hat{O}$ has two normalized eigenstates $|1\\rangle$ and $|2\\rangle$ with eigenvalues 1 and 2 , respectively. The two states $|u\\rangle=\\cos \\theta|1\\rangle+\\sin \\theta|2\\rangle$ and $|v\\rangle=\\cos \\phi|1\\rangle+\\sin \\phi|2\\rangle$ are such that $\\langle v|\\hat{O}| v\\rangle=7 / 4$ and $\\langle u \\mid v\\rangle=0$. Which of the following are possible values of $\\theta$ and $\\phi$ ?\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\theta=-\\frac{\\pi}{6}$ and $\\phi=\\frac{\\pi}{3}$\n\t\\task[\\textbf{B.}]$\\theta=\\frac{\\pi}{6}$ and $\\phi=\\frac{\\pi}{3}$\n\t\\task[\\textbf{C.}]$\\theta=-\\frac{\\pi}{4}$ and $\\phi=\\frac{\\pi}{4}$\n\t\\task[\\textbf{D.}]$\\theta=\\frac{\\pi}{3}$ and $\\phi=-\\frac{\\pi}{6}$\n\\end{tasks}\n\\begin{answer}\n\t$|u\\rangle=\\cos \\theta|1\\rangle+\\sin \\theta|2\\rangle, \\quad|v\\rangle=\\cos \\phi|1\\rangle+\\sin \\phi|2\\rangle$\\\\\\\\\n\tit is given\n\t$\\hat{O}|1\\rangle=|1\\rangle, \\quad \\hat{O}|2\\rangle=2|2\\rangle \\Rightarrow\\langle v|\\hat{O}| v\\rangle=\\frac{7}{4}$\\\\\n\t\\begin{align*}\n\t\t&\\cos ^{2} \\phi+2 \\sin ^{2} \\phi=\\frac{7}{4} \\Rightarrow \\cos ^{2} \\phi+\\sin ^{2} \\phi=1 \\Rightarrow \\sin ^{2} \\phi=\\frac{7}{4}-1 \\\\\n\t\t&\\sin \\phi=\\frac{\\sqrt{3}}{2} \\Rightarrow \\phi=\\frac{\\pi}{3} \\\\\n\t\t&\\langle u \\mid v\\rangle=0 \\Rightarrow \\cos \\theta \\cos \\phi+\\sin \\theta \\sin \\phi=0 \\Rightarrow \\cos (\\theta-\\phi)=0 \\\\\n\t\t&\\Rightarrow \\theta-\\phi=\\frac{\\pi}{2} \\text { or } \\phi-\\theta=\\frac{\\pi}{2} \\Rightarrow \\theta=\\frac{\\pi}{2}+\\frac{\\pi}{3} \\text { or } \\theta=\\frac{\\pi}{3}-\\frac{\\pi}{2} \\Rightarrow \\theta=\\frac{5 \\pi}{6} \\text { or } \\theta=-\\frac{\\pi}{6}\n\t\\end{align*}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\hat{L}_{x}, \\hat{L}_{y}, \\hat{L}_{z}$ are the components of the angular momentum operator in three dimensions the commutator $\\left[\\hat{L}_{x}, \\hat{L}_{x} \\hat{L}_{y} \\hat{L}_{z}\\right]$ may be simplified to\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar L_{x}\\left(\\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$i \\hbar \\hat{L}_{z} \\hat{L}_{y} \\hat{L}_{x}$\n\t\\task[\\textbf{C.}]$i \\hbar L_{x}\\left(2 \\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t&:\\left[L_{x}, L_{x} L_{y} L_{z}\\right]=L_{x}\\left[L_{x}, L_{y} L_{z}\\right]+\\left[L_{x}, L_{x}\\right] L_{y} L_{z} \\\\\n\t\t=& L_{x}\\left[L_{x}, L_{y}\\right] L_{z}+L_{x} L_{y}\\left[L_{x}, L_{z}\\right]+0=L_{x}\\left[i \\hbar L_{z}\\right] L_{z}+L_{x} L_{y}\\left(-i \\hbar L_{y}\\right) \\\\\n\t\t=& i \\hbar L_{x} L_{z}^{2}-i \\hbar L_{x} L_{y}^{2}=i \\hbar L_{x}\\left(L_{z}^{2}-L_{y}^{2}\\right)\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator, $a=x+\\frac{d}{d x}$ acting on smooth function of $x$. Then commutator $[\\alpha, \\cos x]$ is\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\sin x$\n\t\\task[\\textbf{B.}]$\\cos x$\n\t\\task[\\textbf{C.}]$-\\cos x$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{answer}\n\t\n\t\\begin{align*}\n\t&a=x+\\frac{d}{d x}\\\\\n\t\t&{[a, \\cos x]=\\left[x+\\frac{d}{d x}, \\cos x\\right]=[x, \\cos x]+\\left[\\frac{d}{d x}, \\cos x\\right]=0+\\left[\\frac{d}{d x}, \\cos x\\right]} \\\\\n\t\t&{\\left[\\frac{d}{d x}, \\cos x\\right] \\psi(x)=\\frac{d}{d x} \\cos x \\psi(x)-\\cos x \\frac{d \\psi}{d x}} \\\\\n\t\t&=\\cos x \\frac{d \\psi}{d x}+(-\\sin x) \\psi-\\frac{\\cos x d \\psi}{d x}=-\\sin x \\psi \\\\\n\t\t&{[a, \\cos x] \\psi(x)=-\\sin x \\psi} \\\\\n\t\t&{[a, \\cos x]=-\\sin x}\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator $\\vec{\\pi}=\\vec{p}-q \\vec{A}$, where $\\vec{p}$ is the momentum operator, $\\vec{A}=\\left(A_{x}, A_{y}, A_{z}\\right)$ is the vector potential and $q$ denotes the electric charge. If $\\vec{B}=\\left(B_{x}, B_{y}, B_{z}\\right)$ denotes the magnetic field, the $z$-component of the vector operator $\\vec{\\pi} \\times \\vec{\\pi}$ is\n\t\\exyear{NET DEC 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i q \\hbar B_{z}+q\\left(A_{x} p_{y}-A_{y} p_{x}\\right)$\n\t\\task[\\textbf{B.}]$-i q \\hbar B_{z}-q\\left(A_{x} p_{y}-A_{y} p_{x}\\right)$\n\t\\task[\\textbf{C.}]$-i q \\hbar B_{2}$\n\t\\task[\\textbf{D.}] $i q \\hbar B_{z}$\n\\end{tasks}\n\\begin{answer}\n\t$\\vec{\\pi}=\\vec{p}-q \\vec{A}$\\\\\n\t\\begin{align*}\n\t&(\\vec{\\pi} \\times \\vec{\\pi}) \\psi=(\\vec{p}-q \\vec{A}) \\times(\\vec{p}-q \\vec{A}) \\psi=\\vec{p} \\times \\vec{p} \\psi-q \\vec{p} \\times \\vec{A} \\psi-q \\vec{A} \\times \\vec{p} \\psi+q^{2} \\vec{A} \\times \\vec{A} \\psi \\\\\n\t&\\vec{p} \\times \\vec{p} \\psi=0 \\\\\n\t&-q \\vec{p} \\times \\vec{A} \\psi=-q(-i \\hbar \\vec{\\nabla} \\times \\vec{A}) \\psi=q i \\hbar \\vec{B} \\psi \\\\\n\t&q \\vec{A} \\times \\vec{p} \\psi=q(\\vec{A}(-i \\hbar \\vec{\\nabla})) \\psi=0 \\\\\n\t&q^{2} \\vec{A} \\times \\vec{A} \\psi=0 \\\\\n\t&\\vec{\\pi} \\times \\vec{\\pi}=q i \\hbar \\vec{B}\n\t\\end{align*}\n\tSo, $z$ component is given by $q i \\hbar B_{z}$\\\\\n\tThe correct option is \\textbf{(d)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The two vectors }\\left(\\begin{array}{l}\n\t\ta \\\\\n\t\t0\n\t\\end{array}\\right) \\text { and }\\left(\\begin{array}{l}\n\t\tb \\\\\n\t\tc\n\t\\end{array}\\right) \\text { are orthonormal if }$\n\t\\exyear{NET JUNE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $a=\\pm 1, b=\\pm 1 / \\sqrt{2}, c=\\pm 1 / \\sqrt{2}$\n\t\\task[\\textbf{B.}] $a=\\pm 1, b=\\pm 1, c=0$\n\t\\task[\\textbf{C.}]$a=\\pm 1, b=0, c=\\pm 1$\n\t\\task[\\textbf{D.}] $a=\\pm 1, b=\\pm 1 / 2, c=1 / 2$\n\\end{tasks}\n\\begin{answer}\n\t$\\left|\\phi_{1}\\right\\rangle=\\left(\\begin{array}{l}\n\t\ta \\\\\n\t\t0\n\t\\end{array}\\right),\\left|\\phi_{2}\\right\\rangle=\\left(\\begin{array}{l}\n\t\tb \\\\\n\t\tc\n\t\\end{array}\\right)$\\\\\n\t$\\begin{array}{ll}\n\t\t\\left\\langle\\phi_{1} \\mid \\phi_{1}\\right\\rangle=1 & \\Rightarrow a=\\pm 1 \\\\\n\t\t\\left\\langle\\phi_{2} \\mid \\phi_{2}\\right\\rangle=1 & \\Rightarrow|b|^{2}+|c|^{2}=1 \\\\\n\t\t\\left\\langle\\phi_{1} \\mid \\phi_{2}\\right\\rangle=0 & \\Rightarrow\\left(\\begin{array}{ll}\n\t\t\ta & 0\n\t\t\\end{array}\\right)\\left(\\begin{array}{l}\n\t\t\tb \\\\\n\t\t\tc\n\t\t\\end{array}\\right)=0 \\\\\n\t\t& a . b+0 \\cdot c=0 \\Rightarrow a \\cdot b=0 \\\\\n\t\t|c|^{2}=1, \\quad & \\quad c=\\pm 1 \\quad \\text { so } b=0 \\\\\n\t\ta=\\pm 1, \\quad & b=0, \\quad c=\\pm 1\n\t\\end{array}$\\\\\n\tThe correct option  is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $x$ denote the position operator and $p$ the canonically conjugate momentum operator of a particle. The commutator\n\t$$\n\t\\left[\\frac{1}{2 m} p^{2}+\\beta x^{2}, \\frac{1}{m} p^{2}+\\gamma x^{2}\\right]\n\t$$\n\twhere $\\beta$ and $\\gamma$ are constants, is zero if\n\t\\exyear{NET DEC 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\gamma=\\beta$\n\t\\task[\\textbf{B.}]$\\gamma=2 \\beta$\n\t\\task[\\textbf{C.}]$\\gamma=\\sqrt{2} \\beta$\n\t\\task[\\textbf{D.}]$2 \\gamma=\\beta$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t&{\\left[\\frac{1}{2 m} p^{2}+\\beta x^{2}, \\frac{1}{m} p^{2}+\\gamma x^{2}\\right]=0 \\Rightarrow \\frac{1}{2 m} \\gamma\\left[p^{2}, x^{2}\\right]+\\frac{\\beta}{m}\\left[x^{2}, p^{2}\\right]=0} \\\\\n\t\t&-\\frac{\\gamma}{2 m}\\left[x^{2}, p^{2}\\right]+\\frac{\\beta}{m}\\left[x^{2}, p^{2}\\right]=0 \\Rightarrow \\frac{1}{m}\\left[x^{2}, p^{2}\\right]\\left[\\frac{-\\gamma}{2}+\\beta\\right]=0 \\Rightarrow \\gamma=2 \\beta\n\t\\end{align*}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Consider the operator $A_{x}=L_{y} p_{z}-L_{z} p_{y}$, where $L_{i}$ and $p_{i}$ denote, respectively, the components of the angular momentum and momentum operators. The commutator $\\left[A_{x}, x\\right]$ where $x$ is the $x$ - component of the position operator, is\n\t\\exyear{NET DEC 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar\\left(z p_{z}+y p_{y}\\right)$\n\t\\task[\\textbf{B.}]$-i \\hbar\\left(z p_{z}-y p_{y}\\right)$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(z p_{z}+y p_{y}\\right)$\n\t\\task[\\textbf{D.}]$i \\hbar\\left(z p_{z}-y p_{y}\\right)$\n\\end{tasks}\n\\begin{answer}\n\t $A_{x}=L_{y} p_{z}-L_{z} p_{y}, L_{y}=z p_{x}-x p_{z}, L_{z}=x p_{y}-y p_{x}$\n\t\\begin{align*}\n\t&{\\left[A_{x}, x\\right]=\\left[L_{y} p_{z}, x\\right]-\\left[L_{z} p_{y}, x\\right]=\\left[L_{y}, x\\right] p_{z}-\\left[L_{z}, x\\right] p_{y}} \\\\\n\t&=\\left[z p_{x}, x\\right] p_{z}+\\left[y p_{x}, x\\right] p_{y}=z\\left[p_{x}, x\\right] p_{z}+y\\left[p_{x}, x\\right] p_{y} \\\\\n\t&=\\left(-i \\hbar z p_{z}\\right)+\\left(-i \\hbar y p_{y}\\right)=-i \\hbar\\left(z p_{z}+y p_{y}\\right)\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 2 solutions\n\t\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item The quantum mechanical operator for the momentum of a particle moving in one dimension is given by\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar \\frac{d}{d x}$\n\t\\task[\\textbf{B.}]$-i \\hbar \\frac{d}{d x}$\n\t\\task[\\textbf{C.}]$i \\hbar \\frac{\\partial}{\\partial t}$\n\t\\task[\\textbf{D.}]$-\\frac{\\hbar^{2}}{2 m} \\frac{d^{2}}{d x^{2}}$\n\\end{tasks}\n\\begin{answer}\n\tThe correct option \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{x}, L_{y}$ and $L_{z}$ are respectively the $x, y$ and $z$ components of angular momentum operator $L$. The commutator $\\left[L_{x} L_{y}, L_{z}\\right]$ is equal to\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar\\left(L_{x}^{2}+L_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$2 i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}] 0\n\\end{tasks}\n\\begin{answer}\n$\\left\\lfloor L_{x} L_{y}, L_{z}\\right]=L_{x}\\left[L_{y} L_{z}\\right]+\\left[L_{x}, L_{z}\\right] L_{y}=i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\\\\\nThe correct option is \\textbf{(c)}\t\n\\end{answer}\n\\textbf{common data questions 3 and 4 }\\\\\nIn a one-dimensional harmonic oscillator, $\\varphi_{0}, \\varphi_{1}$ and $\\varphi_{2}$ are respectively the ground, first and the second excited states. These three states are normalized and are orthogonal to one another $\\psi_{1}$ and $\\psi_{2}$ are two states defined by\n$$\n\\psi_{1}=\\varphi_{0}-2 \\varphi_{1}+3 \\varphi_{2}, \\psi_{2}=\\varphi_{0}-\\varphi_{1}+\\alpha \\varphi_{2}, \\psi_{2}=\\varphi_{0}-\\varphi_{1}+\\alpha \\varphi_{2}\n$$\nwhere $\\alpha$ is a constant\\\\\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { The value of } \\alpha \\text { which } \\psi_{2} \\text { is orthogonal to } \\psi_{1} \\text { is }$\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}]2\n\t\\task[\\textbf{B.}]1\n\t\\task[\\textbf{C.}]-1\n\t\\task[\\textbf{D.}]-2\n\\end{tasks}\n\\begin{answer}\n\t$\\text { For orthogonal condition scalar product }\\left(\\psi_{2}, \\psi_{1}\\right)=0, \\text { so } 1+2+3 \\alpha=0 \\Rightarrow \\alpha=-1$\\\\\n\tThe correct option is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item For the value of $\\alpha$ determined in $\\mathrm{Q} 3$, the expectation value of energy of the oscillator in the state $\\psi_{2}$ is\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}] $\\hbar \\omega$\n\t\\task[\\textbf{B.}]$3 \\hbar \\omega / 2$ \n\t\\task[\\textbf{C.}]$3 \\hbar \\omega$\n\t\\task[\\textbf{D.}]$9 \\hbar \\omega / 2$\n\\end{tasks}\n\\begin{answer}\n\t$\\psi_{2}=\\phi_{0}-\\phi_{1}+\\alpha \\phi_{2} \\text { put } \\alpha=-1,\\langle H\\rangle=\\frac{\\left\\langle\\psi_{2}|H| \\psi_{2}\\right\\rangle}{\\left\\langle\\psi_{2} \\mid \\psi_{2}\\right\\rangle}=\\frac{\\frac{\\hbar \\omega}{2}+\\frac{3 \\hbar \\omega}{2}+\\frac{5 \\hbar \\omega}{2}}{3}=\\frac{3}{2} \\hbar \\omega$\\\\\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Which one of the following commutation relations is NOT CORRECT? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[L^{2}, L_{z}\\right]=0$\n\t\\task[\\textbf{B.}]$\\left\\lfloor L_{x}, L_{y}\\right\\rfloor=i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$\\left[L_{z}, L_{+}\\right]=\\hbar L_{+}$\n\t\\task[\\textbf{D.}] $\\left[L_{z}, L_{-}\\right]=\\hbar L_{-}$\n\\end{tasks}\n\\begin{answer}\n\tThe correct option is \\textbf{(d)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\vec{L}$ and $\\vec{p}$ be the angular and linear momentum operators, respectively, for a a particle. The commutator $\\left\\lfloor L_{x}, p_{y}\\right\\rfloor$ gives\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-i \\hbar p_{z}$\n\t\\task[\\textbf{B.}]0\n\t\\task[\\textbf{C.}]$i \\hbar p_{x}$\n\t\\task[\\textbf{D.}]$i \\hbar p_{z}$\n\\end{tasks}\n\\begin{answer}\n\\begin{align*}\n\t&:\\left[L_{x}, p_{y}\\right]=\\left[y p_{z}-z p_{y}, p_{y}\\right]=\\left[y p_{z}, p_{y}\\right]-\\left[z p_{y}, p_{y}\\right]=\\left[y, p_{y}\\right] p_{z} \\\\\n\t&\\cdot\\left[p_{y}, p_{y}\\right]=0 \\text { and }\\left[z, p_{y}\\right]=0 \\Rightarrow\\left[L_{x}, p_{y}\\right]=i \\hbar p_{z} \\quad \\because\\left[y, p_{y}\\right]=i \\hbar\n\\end{align*}\nThe correct option is \\textbf{(d)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { Which of the following operators is Hermitian? }$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{d}{d x}$\n\t\\task[\\textbf{B.}]$\\frac{d^{2}}{d x^{2}}$\n\t\\task[\\textbf{C.}]$i \\frac{d^{2}}{d x^{2}}$\n\t\\task[\\textbf{D.}]$\\frac{d^{3}}{d x^{3}}$\n\\end{tasks}\n\\begin{answer}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $x$ and $p$ are the $x$ components of the position and the momentum operators of a particle respectively, the commutator $\\left[x^{2}, p^{2}\\right]$ is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar(x p-p x)$\n\t\\task[\\textbf{B.}]$2 i \\hbar(x p-p x)$\n\t\\task[\\textbf{C.}]$i \\hbar(x p+p x)$\n\t\\task[\\textbf{D.}]$2 i \\hbar(x p+p x)$\n\\end{tasks}\\begin{answer}\n$\\left[x^{2}, p^{2}\\right]=p\\left[x^{2}, p\\right]+\\left[x^{2} p\\right] p=2 i \\hbar p x+2 i \\hbar x p \\Rightarrow 2 i \\hbar(x p+p x)$\\\\\nThe correct option is \\textbf{(d)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { For the parity operator } P, \\text { which of the following statements is NOT true? }$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $P^{\\dagger}=P$\n\t\\task[\\textbf{B.}] $P^{2}=-P$\n\t\\task[\\textbf{C.}] $P^{2}=I$\n\t\\task[\\textbf{D.}]$P^{\\dagger}=P^{-1}$\n\\end{tasks}\n\\begin{answer}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { Which one of the following operators is Hermitian? }$\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\frac{\\left(p_{x} x^{2}-x^{2} p_{x}\\right)}{2}$\n\t\\task[\\textbf{B.}]$i \\frac{\\left(p_{x} x^{2}+x^{2} p_{x}\\right)}{2}$\n\t\\task[\\textbf{C.}]$e^{i p_{x} a}$\n\t\\task[\\textbf{D.}]$e^{-i p_{x} a}$\n\\end{tasks}\n\\begin{answer}\n\t$A=i \\frac{\\left(p_{x} x^{2}-x^{2} p_{x}\\right)}{2}, A^{\\dagger}=-i \\frac{\\left(\\left(p_{x} x^{2}\\right)^{\\dagger}-\\left(x^{2} p_{x}\\right)^{\\dagger}\\right)}{2}=i \\frac{\\left(p_{x} x^{2}-x^{2} p_{x}\\right)}{2}$\\\\\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "9f4126e4299c4abc95df268f554188d6ae99d034", "size": 26777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/mathematical tool solutions.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/mathematical tool solutions.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/mathematical tool solutions.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": 51.6930501931, "max_line_length": 520, "alphanum_fraction": 0.6161257796, "num_tokens": 11422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6184649231888746}}
{"text": "%!TEX root = ../COSCFair.tex\n\n\\section{Theoretical Analysis}\n\\label{sec:theory}\n\nIn this section, we discuss the fairness metrics and perform a theoretical analysis to improve the fairness in the predictions of a given classifier. We provide formal definitions of the fairness metrics with more details than our discussion in Section \\ref{sec:related}. \n\n\\subsection{Fairness Measures}\n\nThe concept of fairness is vague and can be interpreted in different ways. For that reason, there are multiple fairness measures that are similar in the intent. However, these measures (metrics) differ in the way of treating the protected groups and conflict with each other in some cases. We list here five of the well-known fairness metrics. \n\n\n\\stitle{Demographic Parity (DP):} this metric states that, the instances in both protected (unprivileged) and unprotected (privileged) groups should have equal probability of being predicted as positive outcome. This metric can be applied on the original class labels in a dataset as well as on the classifier predictions. For a dataset to be fair, the following condition must be satisfied:\n\\[P\\left[Y({\\bf x})=1\\ |\\ S({\\bf x})=G' \\right]  = P\\left[Y({\\bf x})=1\\ |\\ S({\\bf x}) = G \\right].\\] That means, \n% \\begin{equation} \\label{eq:DPDiff}\n% \\small\n% DP_{diff} = P\\left[Y({\\bf x})=1\\ |\\ S({\\bf x})=G' \\right] - P\\left[ {Y({\\bf x})}=1\\ |\\ S({\\bf x}) = G \\right] \\approx 0.\n% \\end{equation}\n\\begin{align} \\label{eq:DPDiff}\n\\begin{split}\nDP_{diff} = &\\ P\\left[Y({\\bf x})=1\\ |\\ S({\\bf x})=G' \\right]\n    \\\\& - P\\left[ {Y({\\bf x})}=1\\ |\\ S({\\bf x}) = G \\right] \\approx 0.\n\\end{split}\n\\end{align}\nThe same definition can be applied to ensure the classifier's fairness by substituting the original labels by the predicted ones.% in the Equations.  \n\n\\stitle{Disparate Impact Ratio (DIR):} is defined as the ratio between the probability of protected and unprotected groups getting positive or desired outcomes. Based on a legal rule \\cite{US_guideline}, a dataset or a classifier is considered fair if its $DIR$ is at least 0.8, which is also known as the \\emph{80\\%-rule}. $DIR$ can be formulated as:\n\\begin{equation}\\label{eq:di}\nDIR(D) = \\frac{ P\\left[({\\bf x}) = 1 | S({\\bf x}) = G\\right]} {P\\left[Y({\\bf x}) = 1 | S({\\bf x})=G'\\right]}.\n\\end{equation}\nIn this research we target increasing the value of $DIR$ to be close to or greater than $0.8$. Similar to demographic parity, this metric can also be used to measure the fairness of the classifier's predictions.\n\n\n\\stitle{Equalized Odds (EO):} this metric states that instances from protected and unprotected groups should have equal True Positive Rate (TPR) and False Positive Rate (FPR). \nif we denote, \\\\\n\\begin{center}\n$P_1 = P\\left[ \\widehat{Y}({\\bf x})=1\\ |\\ S({\\bf x})=G', Y ({\\bf x})=1 \\right],$\\\\ \n$P_2 = P\\left[ \\widehat{Y}({\\bf x})=1\\ |\\ S({\\bf x})=G, Y({\\bf x})=1 \\right],$\\\\  \n$P_3 = P\\left[ \\widehat{Y}({\\bf x})=1\\ |\\ S({\\bf x})=G', Y({\\bf x})=0 \\right]$, \\\\\n$P_4 = P\\left[ \\widehat{Y}({\\bf x})=1\\ |\\ S({\\bf x})=G, Y({\\bf x})=0 \\right]$.\\\\\n\\end{center}\nthen the EO is defined as:\n\\begin{equation}\\label{eq:eo}\nP_1 = P_2\\ \\text{and}\\ P_3 = P_4 \\\\\n\\end{equation}\nIn our experiments, we use the Average Equalized Odds difference (AEO Diff.), which is defined as:\n\\[\nAEO_{diff} = \\frac{(P_1 - P_2)+(P_3 - P_4)}{2}. \n\\]\nAccording to AEO Diff., a classifier is fair if the $AEO_{diff}$ value should be close to $0$.\n\n\n\n\\stitle{Predictive Parity:} to deem a classifier as fair in terms of predictive parity, both protected and unprotected groups should have the same positive predictive value. It is formalized as:\\\\\n\\begin{small}\n\\[\nP\\left[Y({\\bf x}) = 1\\ |\\ \\widehat{Y}({\\bf x})=1, S({\\bf x})=G\\right] = P\\left[Y({\\bf x}) = 1\\ |\\ \\widehat{Y}({\\bf x})=1, S({\\bf x})=G'\\right].\n\\]\n\\end{small}\n\n\\stitle{Consistency:} this individual fairness metric measures how similar the labels are for the similar instances in a dataset based on the k-neighbors of the instance. Thus, instances should have the same labels if they are similar in terms of features. This metric is formulated as:\n\n% $ y_{NN} = 1 - \\frac{1}{n}\\sum_{i=1}^n |\\hat{y}_i - \\frac{1}{{k_{neighbors}}}  \\sum_{j\\in\\mathcal{N}_{{n_{neighbors}}}(x_i)} \\hat{y}_j|$.\n\n%this is directly from AIF360 Consistency computation\n\\[\nConsistency = 1 - \\frac{1}{|D|}\\sum_{i=1}^{|D|} \\left| \\widehat{y}({\\bf x}_i) -\n           \\frac{1}{\\left|kNN({\\bf x}_i)\\right|} \\sum_{{\\bf x}_j\\in kNN({\\bf x}_i)} \\widehat{y}({\\bf x}_j) \\right|,\n\\]\nwhere $\\left|kNN({\\bf x})\\right|$ represents the set of closed $k$ neighbors for the kNN computation.\n\nEven though the intention of these definitions of fairness through the different metrics is clear, there is no agreement on what should be considered fair/unfair. For example, for an algorithm to be deemed fair, the equalized odds difference should be close to $0$. However, there is no agreement on the cutoff value to consider the algorithm as fair or not. The only exception is the Disparate Impact Ratio (DIR) which is based on the $80\\%$ legal rule. Moreover, it is mathematically impossible to satisfy a set of measures at the same time \\cite{chouldechova2017fair,kleinberg2017inherent,pleiss2017calibration}. For these reasons, we focus on how to improve the $DIR$ of a dataset (or the output of a ML algorithm) and how the improvement in the $DIR$ values will affect the other metrics such as accuracy and F1-Score. \n\nLet $|D|$ be the number of instances in the dataset $D$, $N_p$ %= \\# +ve\nbe the total number positive examples in the dataset, $N_{G_p}/N_{G'_p}$ %  = \\# +ve | S = G\nbe the number positive examples from the unprivileged/privileged groups, respectively. Let $\\xi$ be the percentage value of $DIR$ for the original dataset ($DIR(D) = \\xi/100$). Our goal is to increase the value of $DIR$ by $\\delta/100$, with $0 < \\delta < 125 - \\xi $, to make $DIR(C)$ close to or greater than $80\\%$, where $C$ is a given classifier. To do so, we should increase/decrease the number of instances that are predicted positive from the unprivileged/privileged groups. If $p(Y({\\bf x}) = 1\\ |\\ S({\\bf x}) = G) = \\frac{N_{G_p}}{N_G}$, and $p(Y({\\bf x}) = 1\\ |\\ S({\\bf x}) = G') = \\frac{N_{G'_p}}{N_{G'}}$. \n% \\fixme{--Hakim: I finished revising the analysis up to this point}\nSince, $DIR(D) = \\xi\\%$ then: \n\\begin{equation} \\label{eq:NGP}\n\\frac{N_{G_p}/{N_G}}{N_{G'_p}/{N_{G'}}} = \\frac{\\xi}{100}\\ \\text{and}\\ N_{G_p} = \\frac{\\xi N_G N_{G'_p}}{100N_{G'}}.\n\\end{equation}\nTo increase the value of $DIR(C)$ to $(\\xi+\\delta)\\%$, we need:\n\\begin{equation}\\label{eq:general}\n\\frac{\\left(N_{G_p}+\\epsilon\\right)/{N_G}}{\\left(N_{G'_p}-\\gamma\\right)/{N_{G'}}} = \\frac{\\xi+\\delta}{100},\n% \\frac{N_G+\\epsilon}{W-\\omega-\\gamma} = \\frac{\\xi+\\delta}{100}.    \n\\end{equation}\nwhere $\\epsilon$ is the number of instances (records) from the unprivileged group that should be predicted positive while their original label is negative. \nConceptually, $\\epsilon$ can take any integer value between $0$ and $N_G - N_{G_p}$.\nConversely, $0 < \\gamma < N_{G'_p}$ is the number of instances from the privileged group that should be predicted negative while their original label is positive. \nSolving for $\\epsilon$ and $\\gamma$, we get:\n\\begin{equation} \\label{eq:compute_eps_gam}\n    \\frac{\\left(N_{G_p}+\\epsilon\\right){N_{G'}}}{\\left(N_{G'_p}-\\gamma\\right){N_{G}}} = \\frac{\\xi+\\delta}{100}.\n\\end{equation}\n\nSubstituting $N_{G_P}$ from Eq. (\\ref{eq:NGP}) in Eq. (\\ref{eq:compute_eps_gam}), we get:\n\\[\n\\left(\\xi + \\delta\\right)\\left(N_{G'_p}-\\gamma\\right)N_{G} = 100 N_{G'} \\left(\\frac{\\xi N_G N_{G'_p}}{100N_{G'}} + \\epsilon\\right) \n\\]\nHence:\n\\[\n100 \\epsilon N_{G'} +\\gamma \\left(\\xi + \\delta\\right) N_{G} = \\delta N_{G'_p} N_G\n\\]\nWe can distinguish between three special cases:\n\\begin{enumerate}[label=\\textbf{C\\arabic*:}]\n    \\item $\\epsilon = \\gamma$, in this case we need to increase the number of instances from the protected group that are predicted positive by $\\epsilon = \\frac{\\delta N_{G'_p} N_G}{100N_{G'}+\\left(\\xi+\\delta\\right)N_G}$ and decrease the number of instances from the unprotected group that are predicted positive by the same amount.\n    \\item $\\gamma = 0$, in this case we need to increase the number of instances from the protected group that are predicted positive by $\\epsilon = \\frac{\\delta N_{G'_p} N_G}{100N_{G'}}$ while keeping the same number of positives from the unprotected group.\n    \\item $\\epsilon = 0$, in this case we need to decrease the number of instances from the unprotected group that are predicted positive by $\\gamma = \\frac{\\delta N_{G'_p} N_G}{\\left(\\xi+\\delta\\right)N_G}$ while keeping the same number of positives from the protected group.\n\\end{enumerate}\n\nSince the number of instances (records) from the unprivileged group is significantly smaller than the number of instances from the privileged group, it can be easily shown that increasing the positives of the unprivileged group while keeping the number of positives from the privileged group unchanged will incur the minimum number of changes (case {\\bf C2}: $\\gamma = 0$). This cannot be achieved in real life scenarios but we can increase the probability of classifying an instance as positive given that it is from the unprivileged group. \nTo do so, we consider generating more examples from the  unprivileged group with positive label.To do so, we use oversampling technique to generate synthetic data from the class of the minority. Since the synthetic data generator, such as SMOTE~\\cite{smote}, interpolates the original instances in the training set to generate new instances, the quality of the generated instances depends on the similarity between the interpolated instances. To increase the similarity between the instances, we cluster the data before generating the new instances. \nIn the evaluation section, we report the number of instances that have been predicted differently due to our solution. \n\nIt should be noted that improving the $DIR$ metric will certainly affect the other metrics. For example, according to Eq. (\\ref{eq:general}), increasing $DIR$ by $\\delta$ will have the following effects: i) the number of True Positives (TP) will be decreased by $\\gamma$. We assume that we have trained a perfect classifier, which can predict all the labels in the test set correctly. Based on the required changes in the classifier's predictions, if the original true positives is $TP$ then the new true positives $TP'= TP - \\gamma$; ii) similarly, the True Negatives will be decreased by $\\epsilon$ (i.e. $TN'= TN -\\epsilon$); iii) The False Positives (FP) will be increased by $\\epsilon$ ($FP'= FP + \\epsilon$) and the False Negatives (FN) will be increased by $\\gamma$ ($FN'= FN + \\gamma$). Thus, the perfect classifier's accuracy will be decreased by $\\left(\\frac{\\gamma+\\epsilon}{|D|}\\right)$. If $F'_1$ is the new $F1\\text{-}Score$, then $F'_1 = \\frac{2*(TP-\\gamma)}{2*TP+FN+FP+\\epsilon-\\gamma}$. For the case of perfect classifier, $F_1 = 1$ and $F'_1 = \\frac{2(TP-\\gamma)}{2TP -\\gamma+\\epsilon}$. The decrease in the $F1\\text{-}Score$ will be $1 - \\frac{2(TP-\\gamma)}{2TP -\\gamma+\\epsilon}$.\n\n\\begin{example}\n\\noindent The German dataset \\cite{UCIdfs} has 1000 instances. We split the dataset for training and testing using the 70/30 rule with stratification. In the test set $T$, we have $N_{G'} = 181$ instances from the privileged group and $N_G = 31$ from the unprivileged group. The number of positive instances from privileged/unprivileged is $(N_{G'_p} = 134)$/$(N_{G_p} = 17)$, respectively. In this case, improving $DIR(C)$ from $74\\%$ to be greater than $80\\%$ while considering $\\epsilon = 0$ in Eq. (\\ref{eq:general}) and assuming that we have a perfect classifier, we will need to predict approximately $10$ instances from the privileged group to be negative instead of their original positive label. In this case, the accuracy of the perfect classifier will decrease by $10/300 = 3.3\\%$ and $F1\\text{-}Score$ will be reduced by $\\frac{10}{2*210-10}= 2.4\\%$. However, when $\\gamma = 0$, $\\epsilon$ will be 2 and the decrease in accuracy and $F1\\text{-}Score$ will be $0.6\\%$ and $0.5\\%$, respectively.\n\\end{example}\n\n% Based on our analysis and the statistics from the data, we can conclude that the classifier fail to predict more positive instances from the unprivileged group because the number of positive instances in the training set is small compared to the number of positive instances from the privileged group. To solve the problem, we consider generating more examples from the  unprivileged group with positive label.To do so, we use oversampling technique to generate synthetic data from the class of the minority. Since the synthetic data generator, such as SMOTE~\\cite{smote}, interpolates the original instances in the training set to generate new instances, the quality of the generated instances depends on the similarity between the interpolated instances. To increase the similarity between the instances, we cluster the data before generating the new instances. \n", "meta": {"hexsha": "6d0c2eb77e6a4fdfa6f92b05e6121186f1620055", "size": 12989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FairnessPaper/Sections/Theory.tex", "max_stars_repo_name": "bendiste/Algorithmic-Fairness", "max_stars_repo_head_hexsha": "7e3b54e38eddb7572777be6f9772e3b2a8e398ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "FairnessPaper/Sections/Theory.tex", "max_issues_repo_name": "bendiste/Algorithmic-Fairness", "max_issues_repo_head_hexsha": "7e3b54e38eddb7572777be6f9772e3b2a8e398ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "FairnessPaper/Sections/Theory.tex", "max_forks_repo_name": "bendiste/Algorithmic-Fairness", "max_forks_repo_head_hexsha": "7e3b54e38eddb7572777be6f9772e3b2a8e398ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 107.347107438, "max_line_length": 1200, "alphanum_fraction": 0.7172992532, "num_tokens": 3759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6184649225121277}}
{"text": "\\chapter{Number theory}\n\\label{chap:Number theory}\n\nIn this chapter, you will learn about the\nnumber theoretic functions in libzahl.\n\n\\vspace{1cm}\n\\minitoc\n\n\n\\newpage\n\\section{Odd or even}\n\\label{sec:Odd or even}\n\nThere are four functions available for testing\nthe oddness and evenness of an integer:\n\n\\begin{alltt}\n   int zodd(z_t a);\n   int zeven(z_t a);\n   int zodd_nonzero(z_t a);\n   int zeven_nonzero(z_t a);\n\\end{alltt}\n\n\\noindent\n{\\tt zodd} returns 1 if {\\tt a} contains an\nodd value, or 0 if {\\tt a} contains an even\nnumber. Conversely, {\\tt zeven} returns 1 if\n{\\tt a} contains an even value, or 0 if {\\tt a}\ncontains an odd number. {\\tt zodd\\_nonzero} and\n{\\tt zeven\\_nonzero} behave exactly like {\\tt zodd}\nand {\\tt zeven}, respectively, but assumes that\n{\\tt a} contains a non-zero value, if not\nundefined behaviour is invoked, possibly in the\nform of a segmentation fault; they are thus\nsligtly faster than {\\tt zodd} and {\\tt zeven}.\n\nIt is discouraged to test the returned value\nagainst 1, we should always test against 0,\ntreating all non-zero value as equivalent to 1.\nFor clarity, we use also avoid testing that\nthe returned value is zero, for example, rather\nthan {\\tt !zeven(a)} we write {\\tt zodd(a)}.\n\n\n\\newpage\n\\section{Signum}\n\\label{sec:Signum}\n\nThere are two functions available for testing\nthe sign of an integer, one of the can be used\nto retrieve the sign:\n\n\\begin{alltt}\n   int zsignum(z_t a);\n   int zzero(z_t a);\n\\end{alltt}\n\n\\noindent\n{\\tt zsignum} returns $-1$ if $a < 0$,\n$0$ if $a = 0$, and $+1$ if $a > 0$, that is,\n\n\\vspace{1em}\n\\( \\displaystyle{\n    \\mbox{sgn}~a = \\left \\lbrace \\begin{array}{rl}\n        -1 & \\textrm{if}~ a < 0 \\\\\n         0 & \\textrm{if}~ a = 0 \\\\\n        +1 & \\textrm{if}~ a > 0\n    \\end{array} \\right .\n}\\)\n\\vspace{1em}\n\n\\noindent\nIt is discouraged to compare the returned value\nagainst $-1$ and $+1$; always compare against 0,\nfor example:\n\n\\begin{alltt}\n   if (zsignum(a) >  0)  \"positive\";\n   if (zsignum(a) >= 0)  \"non-negative\";\n   if (zsignum(a) == 0)  \"zero\";\n   if (!zsignum(a))      \"zero\";\n   if (zsignum(a) <= 0)  \"non-positive\";\n   if (zsignum(a) <  0)  \"negative\";\n   if (zsignum(a))       \"non-zero\";\n\\end{alltt}\n\n\\noindent\nHowever, when we are doing arithmetic with the\nsignum, we may relay on the result never being\nany other value than $-1$, $0$, and $+0$.\nFor example:\n\n\\begin{alltt}\n   zset(sgn, zsignum(a));\n   zadd(b, sgn);\n\\end{alltt}\n\n{\\tt zzero} returns 0 if $a = 0$ or 1 if\n$a \\neq 0$. Like with {\\tt zsignum}, avoid\ntesting the returned value against 1, rather\ntest that the returned value is not 0. When\nhowever we are doing arithmetic with the\nresult, we may relay on the result never\nbeing any other value than 0 or 1.\n\n\n\\newpage\n\\section{Greatest common divisor}\n\\label{sec:Greatest common divisor}\n\nThere is no single agreed upon definition\nfor the greatest common divisor of two\ninteger, that cover non-positive integers.\nIn libzahl we define it as\n\n\\vspace{1em}\n\\( \\displaystyle{\n    \\gcd(a, b) = \\left \\lbrace \\begin{array}{rl}\n        -k & \\textrm{if}~ a < 0, b < 0 \\\\\n        b  & \\textrm{if}~ a = 0 \\\\\n        a  & \\textrm{if}~ b = 0 \\\\\n        k  & \\textrm{otherwise}\n    \\end{array} \\right .\n}\\),\n\\vspace{1em}\n\n\\noindent\nwhere $k$ is the largest integer that divides\nboth $\\lvert a \\rvert$ and $\\lvert b \\rvert$. This\ndefinion ensures\n\n\\vspace{1em}\n\\( \\displaystyle{\n    \\frac{a}{\\gcd(a, b)} \\left \\lbrace \\begin{array}{rl}\n        > 0 & \\textrm{if}~ a < 0, b < 0 \\\\\n        < 0 & \\textrm{if}~ a < 0, b > 0 \\\\\n        = 1 & \\textrm{if}~ b = 0, a \\neq 0 \\\\\n        = 0 & \\textrm{if}~ a = 0, b \\neq 0 \\\\\n        \\in \\textbf{N} & \\textrm{otherwise if}~ a \\neq 0, b \\neq 0\n    \\end{array} \\right .\n}\\),\n\\vspace{1em}\n\n\\noindent\nand analogously for $\\frac{b}{\\gcd(a,\\,b)}$. Note however,\nthe convension $\\gcd(0, 0) = 0$ is adhered. Therefore,\nbefore dividing with $\\gcd(a, b)$ you may want to check\nwhether $\\gcd(a, b) = 0$. $\\gcd(a, b)$ is calculated\nwith {\\tt zgcd(a, b)}.\n\n{\\tt zgcd} calculates the greatest common divisor using\nthe Binary GCD algorithm.\n\n\\vspace{1em}\n\\hspace{-2.8ex}\n\\begin{minipage}{\\linewidth}\n\\begin{algorithmic}\n    \\RETURN $a + b$ {\\bf if} $ab = 0$\n    \\RETURN $-\\gcd(\\lvert a \\rvert, \\lvert b \\rvert)$ {\\bf if} $a < 0$ \\AND $b < 0$\n    \\STATE $s \\gets \\max s : 2^s \\vert a, b$\n    \\STATE $u, v \\gets \\lvert a \\rvert \\div 2^s, \\lvert b \\rvert \\div 2^s$\n    \\WHILE{$u \\neq v$}\n        \\STATE $v \\leftrightarrow u$ {\\bf if} $v < u$\n        \\STATE $v \\gets v - u$\n        \\STATE $v \\gets v \\div 2^x$, where $x = \\max x : 2^x \\vert v$\n    \\ENDWHILE\n    \\RETURN $u \\cdot 2^s$\n\\end{algorithmic}\n\\end{minipage}\n\\vspace{1em}\n\n\\noindent\n$\\max x : 2^x \\vert z$ is returned by {\\tt zlsb(z)}\n\\psecref{sec:Boundary}.\n\n\n\\newpage\n\\section{Primality test}\n\\label{sec:Primality test}\n\nThe primality of an integer can be tested with\n\n\\begin{alltt}\n   enum zprimality zptest(z_t w, z_t a, int t);\n\\end{alltt}\n\n\\noindent\n{\\tt zptest} uses Miller–Rabin primality test,\nwith {\\tt t} runs of its witness loop, to\ndetermine whether {\\tt a} is prime. {\\tt zptest}\nreturns either\n\n\\begin{itemize}\n\\item {\\tt PRIME} = 2:\n{\\tt a} is prime. This is only returned for\nknown prime numbers: 2 and 3.\n\n\\item {\\tt PROBABLY\\_PRIME} = 1:\n{\\tt a} is probably a prime. The certainty\nwill be $1 - 4^{-t}$.\n\n\\item {\\tt NONPRIME} = 0:\n{\\tt a} is either composite, non-positive, or 1.\nIt is certain that {\\tt a} is not prime.\n\\end{itemize}\n\nIf and only if {\\tt NONPRIME} is returned, a\nvalue will be assigned to {\\tt w} — unless\n{\\tt w} is {\\tt NULL}. This will be the witness\nof {\\tt a}'s completeness. If $a \\le 1$, it\nis not really composite, and the value of\n{\\tt a} is copied into {\\tt w}.\n\n$\\gcd(w, a)$ can be used to extract a factor\nof $a$. This factor is however not necessarily,\nand unlikely so, prime, but can be composite,\nor even 1. In the latter case this becomes\nutterly useless. Therefore using this method\nfor prime factorisation is a bad idea.\n\nBelow is pseudocode for the Miller–Rabin primality\ntest with witness return.\n\n\\vspace{1em}\n\\hspace{-2.8ex}\n\\begin{minipage}{\\linewidth}\n\\begin{algorithmic}\n    \\RETURN NONPRIME ($w \\gets a$) {\\bf if} {$a \\le 1$}\n    \\RETURN PRIME {\\bf if} {$a \\le 3$}\n    \\RETURN NONPRIME ($w \\gets 2$) {\\bf if} {$2 \\vert a$}\n    \\STATE $r \\gets \\max r : 2^r \\vert (a - 1)$\n    \\STATE $d \\gets (a - 1) \\div 2^r$\n    \\STATE {\\bf repeat} $t$ {\\bf times}\n    \n    \\hspace{2ex}\n    \\begin{minipage}{\\linewidth}\n        \\STATE $k \\xleftarrow{\\$} \\textbf{Z}_{a - 2} \\setminus \\textbf{Z}_{2}$ \\textcolor{c}{\\{Uniformly random assignment.\\}}\n        \\STATE $x \\gets k^d \\mod a$\n        \\STATE {\\bf continue} {\\bf if} $x = 1$ \\OR $x = a - 1$\n        \\STATE {\\bf repeat} $r$ {\\bf times or until} $x = 1$ \\OR $x = a - 1$\n\n        \\hspace{2ex}\n        \\begin{minipage}{\\linewidth}\n            \\vspace{-1ex}\n            \\STATE $x \\gets x^2 \\mod a$\n        \\end{minipage}\n        \\vspace{-1.5em}\n        \\STATE {\\bf end repeat}\n        \\STATE {\\bf if} $x = 1$ {\\bf return} NONPRIME ($w \\gets k$)\n    \\end{minipage}\n    \\vspace{-0.8ex}\n    \\STATE {\\bf end repeat}\n    \\RETURN PROBABLY PRIME\n\\end{algorithmic}\n\\end{minipage}\n\\vspace{1em}\n\n\\noindent\n$\\max x : 2^x \\vert z$ is returned by {\\tt zlsb(z)}\n\\psecref{sec:Boundary}.\n", "meta": {"hexsha": "889d111fdf4b776283666848d72c29b1cf70d854", "size": 7232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/number-theory.tex", "max_stars_repo_name": "maandree/libzahl", "max_stars_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2016-03-06T10:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T10:40:14.000Z", "max_issues_repo_path": "doc/number-theory.tex", "max_issues_repo_name": "maandree/libzahl", "max_issues_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-05-09T12:34:47.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-22T13:11:49.000Z", "max_forks_repo_path": "doc/number-theory.tex", "max_forks_repo_name": "maandree/libzahl", "max_forks_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-14T12:23:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T12:10:26.000Z", "avg_line_length": 27.6030534351, "max_line_length": 126, "alphanum_fraction": 0.6321902655, "num_tokens": 2566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.6184334800806601}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{ABW Octonion}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn ABW octonion has the form\n\\begin{equation}\n    a_{0} + a_{1} A + a_{2} B + a_{3} AB + a_{4} W + a_{5} AW + a_{6} BW + a_{7} ABW\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the AB quaternions.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Zero-Divisors}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "07877150afc13d7a2408f38d87fc12e5d160af12", "size": 2323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/N.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/N.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/N.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": 48.3958333333, "max_line_length": 84, "alphanum_fraction": 0.1919931124, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.6825737473266735, "lm_q1q2_score": 0.6184048684715344}}
{"text": "% !TeX root = ../thuthesis-example.tex\n\n\\chapter{MATHEMATICAL SYMBOLS AND FORMULA}\n\n\\section{Symbols}\n\nAs required by the national formatting standards, the template uses \\pkg{unicode-math} for formatting mathematical symbols, which differs to the default used by LATEX. \n\n\\begin{enumerate}\n  \\item Capital Greek letters are italic by default e.g. \\cs{Delta}：$\\Delta$。\n  \\item Increment symbol: $\\increment$（U+2206）\n  \\item Vectors, matrices, tensors should be ITALIC, and BOLD using the \\cs{symbf} command; for example: $\\symbf{A}$, $\\symbf{\\alpha}$.\n  \\item For constants and special functions, use the \\cs{symup} command. For example:\n    $\\symup{\\pi} = 3.14\\dots$; $\\symup{e} = 2.718\\dots$，\n  \\item Example of integrals and differentials: $\\int f(x) \\dif x$。\n\\end{enumerate}\n\nFor more usage of symbols, you could use the following references\n\\href{http://mirrors.ctan.org/macros/latex/contrib/unicode-math/unicode-math.pdf}{\\pkg{unicode-math}}\n\\href{http://mirrors.ctan.org/macros/latex/contrib/unicode-math/unimath-symbols.pdf}{\\pkg{unimath-symbols}}.\n\nFor units and metrics, it is recommended to use the following package:\n\\href{http://mirrors.ctan.org/macros/latex/contrib/siunitx/siunitx.pdf}{\\pkg{siunitx}}\nIt can conveniently handle the space between Greek letters/numbers and the unit. For example:\n\\SI{6.4e6}{m}，\n\\SI{9}{\\micro\\meter}，\n\\si{kg.m.s^{-1}}，\n\\SIrange{10}{20}{\\degreeCelsius}。\n\n\n\n\\section{Mathematical formula}\n\nYou can use the following environments \\env{equation} 和 \\env{equation*} for mathematical formulae.\n\nPlease pay attention that round brackets should be included before and after referencing an equation: e.g. Equation \\eqref{eq:example}.\n\n\\begin{equation}\n  \\frac{1}{2 \\symup{\\pi} \\symup{i}} \\int_\\gamma f = \\sum_{k=1}^m n(\\gamma; a_k) \\mathscr{R}(f; a_k)\n  \\label{eq:example}\n\\end{equation}\n\nWhen there are multiple equations, please try to align them at the \"equal\" sign if possible. We recommend using the \\env{align} environment.\nFor example:\n\\begin{align}\n  a & = b + c + d + e \\\\\n    & = f + g\n\\end{align}\n\n\n\\section{Mathematical axioms and proofs}\n\nYou can use \\pkg{amsthm} or \\pkg{ntheorem} packages to set up your axiom. After loading one of those package, the template will automatically setup the environments: \\env{theorem} and \\env{proof}\n\nAn example:\n\\begin{theorem}[Lindeberg--Lévy Central Limit Theorem]\n  Set random variables $X_1, X_2, \\dots, X_n$ i.i.d., with expectation mean of $\\mu$ and variance $\\sigma^2 \\ne 0$. By formula, $\\bar{X}_n = \\frac{1}{n} \\sum_{i+1}^n X_i$, we have\n  \\begin{equation}\n    \\lim_{n \\to \\infty} P \\left(\\frac{\\sqrt{n} \\left( \\bar{X}_n - \\mu \\right)}{\\sigma} \\le z \\right) = \\Phi(z),\n  \\end{equation}\n  where $\\Phi(z)$ is the function of a normal distribution.\n\\end{theorem}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\nThe template also provides the following environments: \\env{assumption}、\\env{definition}、\\env{proposition}、\n\\env{lemma}、\\env{theorem}、\\env{axiom}、\\env{corollary}、\\env{exercise}、\n\\env{example}、\\env{remar}、\\env{problem}、\\env{conjecture} ", "meta": {"hexsha": "6e8054aec74da72e12f204b73323c9cb3015f1fd", "size": 3027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "data/chap-example-3.tex", "max_stars_repo_name": "davide97l/master-thesis", "max_stars_repo_head_hexsha": "1627af369f754618031aea9ceb99ca044952af16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-02T05:46:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-02T05:46:48.000Z", "max_issues_repo_path": "data/chap-example-3.tex", "max_issues_repo_name": "davide97l/master-thesis", "max_issues_repo_head_hexsha": "1627af369f754618031aea9ceb99ca044952af16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "data/chap-example-3.tex", "max_forks_repo_name": "davide97l/master-thesis", "max_forks_repo_head_hexsha": "1627af369f754618031aea9ceb99ca044952af16", "max_forks_repo_licenses": ["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.8695652174, "max_line_length": 195, "alphanum_fraction": 0.7208457218, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6184034971016525}}
{"text": "\\subsubsection{Single Fungal Species}\nIt is simple to analyze and predict a single species of fungus, because in this ideal environment, the growth and reproduction process of a single fungus can be accurately represented by the \\textbf{Logistic Model}. Substitute data of $F_A\\sim F_E$ into the previous differential equation \\textit{Eq.~(\\ref{12eq})} and get \\textit{Eq.~(\\ref{14eq})} as follows.\n\\begin{equation}\n  \\label{14eq}\n  \\begin{cases}\n    \\frac{1}{N_A(t)}\\frac{dN_A(t)}{dt} = r_A(1-\\frac{N_A(t)}{{N_A}_{max}}) \\\\ \\\\\n    \\frac{1}{N_B(t)}\\frac{dN_B(t)}{dt} = r_B(1-\\frac{N_B(t)}{{N_B}_{max}}) \\\\ \\\\\n    \\frac{1}{N_C(t)}\\frac{dN_C(t)}{dt} = r_C(1-\\frac{N_C(t)}{{N_C}_{max}}) \\\\ \\\\\n    \\frac{1}{N_D(t)}\\frac{dN_D(t)}{dt} = r_D(1-\\frac{N_D(t)}{{N_D}_{max}}) \\\\ \\\\\n    \\frac{1}{N_E(t)}\\frac{dN_E(t)}{dt} = r_E(1-\\frac{N_E(t)}{{N_E}_{max}}) \\\\\n  \\end{cases}\n\\end{equation}\nThe function curves of $N_A(t)$, $N_B(t)$, $N_C(t)$, $N_D(t)$, and $N_E(t)$ are as follows.\n\\par\n\\begin{figure}[H]\n  \\centering\n  \\label{functioncurves}\n  \\includegraphics[width=\\textwidth]{figures/Single.png}\n  \\caption{Function curves of each single fungus.}\n\\end{figure}\n\\par\nThe fungal data in the above figure are all based on the research and analysis of the environmental climate in \\textit{Table~\\ref{fivetypicalfungalspecies}}. The temperature, moisture and so on indicated in the table are the most suitable environmental conditions for the five fungi. Looking up the climatic data, it is found that the optimal growth environment of the five fungi corresponds exactly to the five typical climatic characteristics, including arid, semi-arid, temperate, arboreal and tropical rain forests. Therefore, it is obvious that when five species of fungi $F_A\\sim F_E$, grow and reproduce under the optimal conditions, they can exert their greatest advantages in decomposing lignin or cellulose. On the contrary, these fungi will be at disadvantages due to excessive environmental blocking.\n\\begin{table}[H]\n  \\centering\n  \\caption{Corresponding optimal environment for the five fungi.}\n  \\label{correspondingoptimalenvironment}\n  \\begin{tabular*}{\\hsize}{@{\\extracolsep{\\fill}}cccc}\n    \\toprule\n    & Fungi & Corresponding Environment & \\\\\n    \\midrule\n    & $F_A$ & Arid & \\\\\n    & $F_B$ & Semi-arid & \\\\\n    & $F_C$ & Temperate & \\\\\n    & $F_D$ & Arboreal & \\\\\n    & $F_E$ & Tropical rain forests & \\\\\n    \\bottomrule\n  \\end{tabular*}\n\\end{table}\nThe above table illustrates the corresponding optimal environment when the five fungi live alone, but it is quite different from the real situation in the nature. The following will further analyze the combinations between fungal species.", "meta": {"hexsha": "9bbd3e13d18c28cda6da8227807318fa64f07986", "size": 2668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/5/1.tex", "max_stars_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_stars_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-07T14:38:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T10:37:34.000Z", "max_issues_repo_path": "4/5/1.tex", "max_issues_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_issues_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_issues_repo_licenses": ["MIT"], "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/5/1.tex", "max_forks_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_forks_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_forks_repo_licenses": ["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.4102564103, "max_line_length": 812, "alphanum_fraction": 0.7117691154, "num_tokens": 795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6184034958261719}}
{"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^{3/2}}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\n$\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n^{3/2}}$ is a $p$-series with $p=\\frac32$. Since $p>1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n^{3/2}}$ converges by the $p$-series test. \r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty  \\frac{1}{n^{3/2}}$ converges absolutely.\r\n\r\n\\subsection*{Other solution}\r\n\r\nYou can also use the Integral Test, but when the $p$-test works, why work more?\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": "30bad88bcd35edb1fee4e473d22b526a9715002a", "size": 1483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/n1.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/n1.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/n1.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": 29.0784313725, "max_line_length": 197, "alphanum_fraction": 0.6311530681, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6184034910376217}}
{"text": "\\mychapter{14}{Lesson 14} %181114\n\n\\subsubsection{Decisional Diffie-Hellman (cont'd)}\n\n%AP190913: Is p supposed to be prime?\n\\begin{claim}\n    \\ddh{} is not hard for groups $\\integer_p^\\times$\n\\end{claim}\n\n\\begin{proof}\n    Let $\\quadres_p$ be the group of quadratic residues modulo $p$, where the group operation is multiplication:\n    \\[\n        \\quadres(p) = \\{y : \\exists x \\in \\integer_p \\implies y \\equiv_p x^2\\} = \\{g^z : \\forall z\\}\n    \\]\n    where $g$ generates $\\integer_p^\\times$.Then, we can test if a give number $y$ is in $\\quadres_p$ by checking if $y^{(p-1)/2} \\equiv_p 1$, because:\n    \\[\n        \\exists z : y = g^{2z} \\implies y^{(p-1)/2} = g^{\\frac{2z(p-1)}{2}} = g^{z(p-1)} \\equiv_p 1\n    \\]\n    Otherwise: % AP190208: Not sure at all that this is correct\n    \\[\n        \\nexists z : y = g^{2z} \\implies y^{(p-1)/2} \\equiv_p g^{z(p-1)} \\cdot g^{(p-1)/2} \\not\\equiv_p 1\n    \\]\n\n    Furthermore: $g^{xy} \\in \\quadres_p \\implies x \\equiv_2 0 \\vee y \\equiv_2 0$. With this in mind, given a random choice of $x$ and $y$, the probability that $g^{xy}$ falls in $\\quadres(p)$ is $\\frac{3}{4}$, and the probability of it being outside the group is $\\frac{1}{4}$. This is an advantage available to a polynomial adversary.\n\\end{proof}\n\nNevertheless, some other groups are believed to harden quadratic residue membership; examples of such groups are $\\quadres_p$ itself for $p = 2q + 1$, where $q$ is prime, or the elliptic curve groups.\n\n\\subsubsection{Extended \\ddh}\n\nThis is a construction that takes the \\ddh{} assumption to an extreme using groups. The \\ddh{} assumption is reported here:\n\\[\n    (G, g, q) \\pickUAR \\groupgen(1^\\lambda), \\forall i\\: X_i, Y_i, Z_i \\sim \\unifdist(G) \\implies (g^X, g^Y, g^{XY}) \\compindist (g^X, g^Y, g^Z)\n\\]\nwhere $X$, $Y$ and $Z$ are distribution ensembles.\n\nThe construction extends this concept of hardness in detecting $xy$ by replicating it $n$-times:\n\\begin{theorem}\n    Let $X$, $Y_{1\\upto n}$ and $Z_{1 \\upto n}$ be distribution ensembles over a group $(G, g, q)$ Then:\n    \\[\n        (g^X, g^{Y_1}, g^{XY_1}, \\dots, g^{Y_n}, g^{XY_n}) \\compindist (g^X, g^{Y_1}, g^{Z_1}, \\dots, g^{Y_n}, g^{Z_n})\n    \\]\n\\end{theorem}\n\n\\begin{proof}\n    \\todo{The game is modified a bit to ease the analysis of the reduction, must take care...\n    \n    Also, this kind of proof is ``tight''; the hybridization would have introduced a negligible difference instead}\n\n    The proof can be structured by progressive hybridization over the sequences, and breaking the \\ddh{} assumption at any step $i$. Here instead, we will simulate the \\textsc{ext} sequence directly in the distinguishing game, and assume there is $\\distinguisher^{\\textsc{ext}}$ capable of telling them apart; figure \\ref{cryptoredux:extddh} shows the steps to take.\n\n    \\begin{cryptoredux}\n        {extddh}\n        {Breaking \\ddh{} by distinguishing the \\ddh{} sequence}\n        {ddh}\n        {ext}\n        \n        \\cseqdelay\n        \\receive{\\shortstack[l]{\n            %AP190913: Actually, the adversary knows this!\n            $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ \\\\\n            $x, y \\pickUAR \\integer_q$ \\\\\n            $b \\pickUAR \\binary$ \\\\\n            $\\beta_b \\pickUAR \\{0, \\integer_q\\setminus\\{0\\}\\}$ \\\\\n            $z_b = xy + \\beta_b$\n        }}{$(g^x, g^y, g^{z_b})$}{}\n\n        \\cseqbeginloop\n        \\cseqdelay\n        \\cseqadversary{\\shortstack[r]{\n            $u_i, v_i \\pickUAR \\integer_p$ \\\\\n            $g^{y_i} = (g^y)^{u_j}g^{v_j}$ \\\\\n            $g^{z_i} = (g^z)^{u_j}(g^x)^{v_j}$\n        }}\n        \\cseqdelay\n        \\cseqendloop\n        \\cseqdelay\n        \n        \\invoke{}{$(g^x, g^{y_1}, g^{z_1}, \\dots)$}{}\n\n        \\return{}{$b'$}{}\n\n        \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n    \\end{cryptoredux}\n\n\\end{proof}\n\nNotice that $(g^y)^{u_j}g^{v_j}= g^{yu_j + v_j}$, and $(g^z)^{u_j}(g^x)^{v_j} = g^{zu_j + xv_j}$, which depending on what $z$ is, becomes either $g^{x(yu_j + v_j)}$, matching perfectly the $y_i$ case, or remains as a random linear combination, matching the $z_i$ case.\n\n\\subsubsection{Naor-Reingold \\prf}\n\nThis is an alternative to the extended \\ddh{} seen above, designed by Moni Naor and Omer Reingold. It constructs a \\prf{} as follows:\n\\[\n    F^{\\textsc{nr}} \\in \\integer_q^{(n+1)} \\times \\binary^n \\to (G, g, q) : f^{\\textsc{nr}}_k(x_{1\\upto n}) \\mapsto g^{k_0\\prod_{i = 1}^{n}k_i^{x_i}}\n\\]\n\n\\todo{Transcribing notes directly:\n\\{\nThis is \\ggm{} with $G^{g, q, a}(g^b) = G_0(g^b) \\mathrel{||} G_1(g^b) = (g^b, g^{ab})$\n\nE.g.: $011 \\mapsto g^{a_0a_1^0a_2^1a_3^1}$\n\n\\}\n\nNotes about claw-free permutations follow; also, hash functions make an appearance\n\n}\n\n\n\\begin{figure}\n    \\centering\n    \\begin{tikzpicture}[\n        level 1/.style={sibling distance=16em},\n        level 2/.style={sibling distance=8em},\n        level 3/.style={sibling distance=4em}]\n\n        \\node{$g^{a_0}$}\n            child{ node {}\n                child { node {}\n                    child { node (a) {$g^{a_0}$} node [below of = a] {$\\vdots$}}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                }\n                child { node {}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                }\n            }\n            child { node {}\n                child { node {}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                }\n                child { node {}\n                    child { node (a) {} node [below of = a] {$\\vdots$}}\n                    child { node (a) {$g^{a_0a_1a_2a_3}$} node [below of = a] {$\\vdots$}}\n                }\n            };\n    \\end{tikzpicture}\n    \\caption{Depicting Naor-Reingold method as a tree-like structure}\n    \\label{fig:nrtree}\n\\end{figure}\n\n\\section{Public key encryption schemes}\n\nNow we discuss a substantially different way of encrypting messages, which involves two separate keys per party instead of a single, shared key; hence the names \\emph{Public key scheme}, or \\pke{}, or \\emph{Asymmetric key scheme}.\n\n\n\\subsubsection{\\textsc{Cpa}-security, revisited}\n\nIn a \\pke{} setting, the adversary knows the public key by design, which in turn is all that he needs to preform encryptions; therefore, the queries in a hypothetical \\cpa{} game are moot, because \\adversary{} can make the encryptions on its own; figure \\ref{cryptogame:pkecpa} shows the changed game for a \\pke{}.\n\n\n\\begin{cryptogame}\n    {pkecpa}\n    {Chosen plaintext attacks, revisited for \\pke{} schemes}\n    {cpa2}\n\n    \\receive{$(\\pk, \\sk) \\pickUAR \\keygen(1^\\lambda)$}{$\\pk$}{}\n\n    \\cseqbeginloop\n    \\cseqadversary{$c = \\Enc(\\pk, m)$}\n    \\cseqendloop\n\n    \\send{}{$m_0, m_1$}{}\n\n    \\receive{\\shortstack[l]{\n        $b \\pickUAR \\binary$ \\\\\n        $c_b = \\Enc(\\pk, m_b)$\n    }}{$m_b$}{}\n\n    \\cseqbeginloop\n    \\cseqadversary{$c = \\Enc(\\pk, m)$}\n    \\cseqendloop\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n\n\\end{cryptogame}\n\n\\todo{Another verbatim transcription:\n\nAbstract construction (inefficient) for trapdoor permutation\n\n$(Gen, f, f')$, where $gen= \\keygen : \\singleton \\to \\Xi_\\pk, f(\\pk, \\cdot) \\in \\Xi_\\pk \\to \\Xi_\\pk, f' = f^{-1}(\\sk, \\cdot) \\in \\Xi_\\pk \\to \\Xi_\\pk$\n\nCorrectness: $f^{-1}(\\sk, f(\\pk, m)) = m$\n\n$TDP \\implies PKE$, Easy but not trivial\n\n$\\cryptog{tdp}$... same as \\cpa2?\n\nWhy $f, f'$ is not cpa-secure? Because they are deterministic\n\nUse $f$'s hardcore predicate\n\n}\n", "meta": {"hexsha": "448340c103d4a386057febbfa3dea7b41241ae78", "size": 7503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_14.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_14.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_14.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": 38.0862944162, "max_line_length": 366, "alphanum_fraction": 0.5890976943, "num_tokens": 2496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6183080646741754}}
{"text": "\\def \\bookname {Analysis II}\n\n\\documentclass[13pt,a4paper]{report}\n\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\n\\theoremstyle{definition}\n\n\\newtheorem{lemma}{Lemma}[section]\n\\newtheorem{exercise}{Exercise}[section]\n\\newtheorem{solution}{Solution}[section]\n\n\\begin{document}\n\\chapter{Metric spaces}\n\\section{Definitions and examples}\n\n\\begin{lemma}\\label{convergence_lemma_1}\nLet $(x_n)^\\infty_{n=m}$ be a sequence of real numbers, and let $x$ be another real number. Then\n$(x_n)^\\infty_{n=m}$ converges to $x$ if and only if $\\lim_{n \\rightarrow \\infty}\nd(x_n, x) = 0$.\n\\end{lemma}\n\n\\begin{exercise}\nProve Lemma \\ref{convergence_lemma_1}.\n\\end{exercise}\n\n\\begin{solution}\nBy definition of limit, for any $\\varepsilon > 0$ there exists an $N \\ge m$ such that\n$d(x_n, x) = |x_n - x| < \\varepsilon$ for all $n \\ge N$. This is exactly the definition\nof convergence in previous book.\n\\end{solution}\n\n\\begin{exercise}\nShow that the real line with the metric $d(x, y) := |x - y|$ is indeed a metric space.\n(Hint: you may wish to review your proof of Proposition 4.3.3.)\n\\end{exercise}\n\n\\begin{solution} We verify the four properties listed in Definition 1.1.2\n\\begin{itemize}\n    \\item[1.] $d(x, x) = |x - x| = 0$.\n    \\item[2.] For all $x \\ne y$, $d(x, y) = |x - y| > 0$.\n    \\item[3.] For all $x$ and $y$, $d(x, y) = |x - y| = |y - x| = d(y, x)$.\n    \\item[4.] For all $x, y$ and $z$, $d(x, y) = |x - y| = |x - z + z - y| \\le\n    |x - z| + |z - y| = d(x, z) + d(z, y)$.\n\\end{itemize}\n\\end{solution}\n\n\\begin{exercise}\nLet $X$ be a set, and let $d: X \\times X \\rightarrow [0, \\infty)$ be a function.\n\\begin{itemize}\n    \\item[(a)] Give an example of a pair $(X, d)$ which obeys axioms (bcd) of Definition 1.1.2,\n    but not (a). (Hint: modify the discrete metric.)\n    \\item[(b)] Give an example of a pair $(X, d)$ which obeys axioms (acd) of Definition 1.1.2,\n    but not (b).\n    \\item[(c)] Give an example of a pair $(X, d)$ which obeys axioms (abd) of Definition 1.1.2,\n    but not (c).\n    \\item[(d)] Give an example of a pair $(X, d)$ which obeys axioms (abc) of Definition 1.1.2,\n    but not (d). (Hint: try examples where $X$ is a finite set.)\n\\end{itemize}\n\\end{exercise}\n\n\\begin{solution} In general, setting $X$ to be a finite set and defining $d$ by specifying values\nfor all pairs of elements can produce a lot of metric spaces for each of the problem. For this\nexercise to be more challenging, we try to avoid abusing this approach.\n\\begin{itemize}\n    \\item[(a)] Let $d$ be the metric such that for all $x, y \\in X$, $d(x, y) = 1$. This is similar\n    to the discrete metric except that $d(x, x) = 1$ so it does not obey (a).\n    \\item[(b)] Similar to (a), we can as well set $d(x, y) = 0$ for all $x, y \\in X$.\n    \\item[(c)]\n    \\item[(d)] Let $X = \\{ 1, 2, 3 \\}$ and define $d(x, x) = 0$ for $x \\in X$, $d(1, 2) = d(2, 1)\n    = 1$, $d(2, 3) = d(3, 2) = 1$ and finally $d(1, 3) = d(3, 1) = 3$.\n\\end{itemize}\n\\end{solution}\n\n\\begin{exercise}\nShow that the pair $(Y, d|_{Y \\times Y})$ defined in Example 1.1.5 is indeed a metric space.\n\\end{exercise}\n\n\\begin{solution}\nEach of the four properties remains after $d$ is restricted to $Y \\subset X$ and is vacuous to\nverify.\n\\end{solution}\n\n\\begin{exercise}\\label{exercise_1_1_5}\nLet $N \\ge 1$, and let $a_1, a_2, \\ldots, a_n$ and $b_1, b_2, \\ldots, b_n$ be real numbers. Verify\nthe identity\n    \\begin{equation*}\n    \\Bigg(\\sum_{i = 1}^n a_i b_i\\Bigg)^2 + \\frac{1}{2} \\sum_{i = 1}^n \\sum_{j = 1}^n\n    (a_i b_j - a_j b_i)^2 = \\Bigg(\\sum_{i = 1}^n a_i^2 \\Bigg) \\Bigg(\\sum_{j = 1}^n b_j^2 \\Bigg)\n    \\end{equation*}\nand conclude the \\it{Cauchy-Schwarz inequality}\n    \\begin{equation*}\n    \\Bigg|\\sum_{i = 1}^n a_i b_i \\Bigg| \\le \\Bigg(\\sum_{i = 1}^n a_i^2\\Bigg)^{\\frac{1}{2}}\n    \\Bigg(\\sum_{j = 1}^n b_j^2\\Bigg)^{\\frac{1}{2}}\n    \\tag{(1.3)}\n    \\end{equation*}\nThen use the Cauchy-Schwarz inequality to prove the \\it{triangle inequality}\n    \\begin{equation*}\n    \\Bigg(\\sum_{i = 1}^n (a_i + b_i)^2\\Bigg)^{\\frac{1}{2}} \\le\n    \\Bigg(\\sum_{i = 1}^n a_i^2\\Bigg)^{\\frac{1}{2}} +\n    \\Bigg(\\sum_{j = 1}^n b_j^2\\Bigg)^{\\frac{1}{2}}\n    \\end{equation*}\n\\end{exercise}\n\n\\begin{solution}\n\\end{solution}\n\n\\begin{exercise}\nShow that $({\\bf R}^n, d_{l^2})$ in Example 1.1.6 is indeed a metric space. (Hint: use Exercise\n\\ref{exercise_1_1_5}.)\n\\end{exercise}\n\n\\begin{exercise}\nShow that the pair $({\\bf R}^n, d_{l^1})$ in Example 1.1.7 is indeed a metric space.\n\\end{exercise}\n\n\\begin{exercise}\nProve the two inequalities in (1.1). (For the first inequality, square both sides. For the second\ninequality, use Exercise \\ref{exercise_1_1_5}.)\n\\end{exercise}\n\n\\begin{exercise}\nShow that the pair $({\\bf R}^n, d_{l^\\infty})$ in Example 1.1.9 is indeed a metric space.\n\\end{exercise}\n\n\\begin{exercise}\nProve the two inequalities in (1.2).\n\\end{exercise}\n\n\\begin{exercise}\nShow that the discrete metric ${\\bf R}^n, d_{\\text{disc}}$ in Example 1.1.11 is indeed a metric\nspace.\n\\end{exercise}\n\n\\begin{exercise}\nProve Proposition 1.1.18.\n\\end{exercise}\n\n\\begin{exercise}\nProve Proposition 1.1.19.\n\\end{exercise}\n\n\\begin{exercise}\nProve Proposition 1.1.20. (Hint: modify the proof of Proposition 6.1.7.)\n\\end{exercise}\n\n\\begin{exercise}\nLet\n    \\begin{equation*}\n    X := \\Bigg\\{ (a_n)_{n = 0}^\\infty : \\sum_{n = 0}^\\infty |a_n| < \\infty \\Bigg\\}\n    \\end{equation*}\nbe the space of absolutely convergent sequences. Define the $l^1$ and $l^\\infty$ metrics on this\nspace by\n    \\begin{equation*}\n\n    \\end{equation*}\n\\end{exercise}\n\n\\begin{exercise}\n\\end{exercise}\n\n\\end{document}\n", "meta": {"hexsha": "b6b923c9cf085063a9b6a47ee20adbdc3b76ca60", "size": 5546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Analysis II/solution.tex", "max_stars_repo_name": "Poligun/Solutions", "max_stars_repo_head_hexsha": "da86be33a5d769722576bb2fab141226f9e1fabb", "max_stars_repo_licenses": ["MIT"], "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 II/solution.tex", "max_issues_repo_name": "Poligun/Solutions", "max_issues_repo_head_hexsha": "da86be33a5d769722576bb2fab141226f9e1fabb", "max_issues_repo_licenses": ["MIT"], "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 II/solution.tex", "max_forks_repo_name": "Poligun/Solutions", "max_forks_repo_head_hexsha": "da86be33a5d769722576bb2fab141226f9e1fabb", "max_forks_repo_licenses": ["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.6121212121, "max_line_length": 99, "alphanum_fraction": 0.6462315182, "num_tokens": 2081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.618308041859753}}
{"text": "\\chapter{Derivation Steps in Detail}\nIn this appendix chapter we provide some further derivation steps used to derive some of our equations. \n\n\\section{Taylor Series Approximation}\n\\label{chap:taylorseriesapproxappendix}\n\nIn order to prove equation $\\ref{eq:taylorseriesapproximationofp}$ from section $\\ref{sec:taylorapproximation}$ we have to show the following: For any $N\\mathbb{\\in N}$ and\n\\begin{equation}\n \\sum_{n=0}^{N}\\frac{(ikwh)^{n}}{n!}\\mathcal{F}\\left\\{ h{}^{n}\\right\\} (\\alpha,\\beta) \\approx P(\\alpha,\\beta) \n\\end{equation}\nwe have to prove:\n \n\\begin{enumerate}\n\\item Show that there exist such an $N\\mathbb{\\in N}$s.t the approximation\nholds true.\n\\item Find a value for B s.t. this approximation is below a certain error\nbound, for example machine precision $\\epsilon$. \n\\end{enumerate}\n\n\\subsection{Proof Sketch of 1.}\nBy using the \\textbf{ratio test} which is on Taylor's theorem$\\footnote{Please have a look at \\texttt{http://en.wikipedia.org/wiki/Taylors\\textunderscore theorem} in order to see a proper definiton of the ratio test.}$ it is possible to show that the series\n\n\\begin{equation}\n  \\sum_{n=0}^{N}\\frac{(ikwh)^{n}}{n!}\\mathcal{F}\\left\\{ h{}^{n}\\right\\} (\\alpha,\\beta)\n\\end{equation}\nconverges absolutely.\n\n\\myparagraph{Proof of that the section converges absolutely}\nLet us Consider \n\n\\begin{equation}\n  \\sum_{k=0}^{\\infty}\\frac{y^{n}}{n!}\n\\end{equation}\n\nfor which we define\n\n\\begin{equation}\n  a_{k}=\\frac{y^{k}}{k!} \n\\end{equation}\n\nBy applying the definition of the ratio test for this series it follows: \n\n\\begin{equation}\n \\forall y:limsup_{k\\rightarrow\\infty}|\\frac{a_{k+1}}{a_{k}}|=limsup_{k\\rightarrow\\infty}\\frac{y}{k+1}=0 \n\\end{equation}\n\nThus this series converges absolutely, no matter what value we will pick for $y$. Q.E.D.\n\n\\subsection{Part 2: Find such an N}\nLet $f(x)=e^{x}$. We can formulate its Taylor series, stated above. Let $P_{n}(x)$ denote the n-th Taylor polynomial, \n\n\\begin{equation}\n P_{n}(x)=\\sum_{k=0}^{n}\\frac{f^{(k)}(a)}{k!}(x-a)^{k}\n\\end{equation}\n\nwhere $a$ is our developing point (here a is equal zero). We can define the error of the n-th Taylor polynomial to be equal to\n\n\\begin{equation}\n  E_{n}(x)=f(x)-P_{n}(x)\n\\end{equation}\n\nThe error of the n-th Taylor polynomial is difference between the value of the function and the Taylor polynomial. This directly implies that \n\n\\begin{equation}\n  |E_{n}(x)|=|f(x)-P_{n}(x)| \n\\end{equation}\n\nBy using the Lagrangian Error Bound it follows: \n\n\\begin{equation}\n |E_{n}(x)|\\leq\\frac{M}{(n+1)!}|x-a|^{n+1} \n\\end{equation}\n\nwith $a=0$, where \\textbf{M} is some value satisfying \n\n\\begin{equation}\n  |f^{(n+1)}(x)|\\leq M\n\\end{equation}\n\non the interval $I=[a,x]$. Since we are interested in an upper bound of the error and since \\textbf{a} is known, we can reformulate the interval as $I=[0,x_{max}]$, where \n\n\\begin{equation}\n x_{max} = \\|i\\| k_{max} w_{max} h_{max}\n\\end{equation}\n\nWe are interested in computing an error bound for $e^{ikwh(x,y)}$. E.g. let us assuming the following parameters (used within Stam's Paper): \n\n\\begin{itemize}\n  \\item Height of bump: 0.15$\\mu m$\n  \\item Width of a bump: 0.5$\\mu m$\n  \\item Length of a bump: 1$\\mu m$\n  \\item $k=\\frac{2\\pi}{\\lambda}$ is the wavenumber, $\\lambda\\in[\\lambda_{min,}\\lambda_{max}]$ and\n  thus $k_{max}=\\frac{2\\pi}{\\lambda_{min}}$. Since $(u,v,w) = -\\omega_i - \\omega_r$ and both are unit direction vectors, \n  each component can have a value in range {[}-2, 2{]}.\n  \\item for simplification, assume$[\\lambda_{min,}\\lambda_{max}]=[400nm,700nm].$\n\\end{itemize}\n\nWe get:  \n\n\\begin{align}\nx_{max}\n &= \\|i\\| \\cdot k_{max} \\cdot w_{max} \\cdot h_{max} \\nonumber \\\\\n &= k_{max} \\cdot w_{max} \\cdot h_{max} \\nonumber \\\\\n &=2\\cdot(\\frac{2\\pi}{4 \\cdot 10^{-7}m}) \\cdot 1.5 \\cdot 10^{-7} \\nonumber \\\\\n &=1.5\\pi\n\\end{align}\n\nand it follows for our interval $I=[0,1.5\\pi]$. Next we are going to find the value for $M$. Since the exponential function is monotonically growing (on the interval $I$) and the derivative of the exponential function is again an exponential function, we can find such an $M$: \n\n\\begin{align*}\n M\n &=e^{x_{max}} \\nonumber \\\\\n &=exp(1.5\\pi)\n\\end{align*}\n\nand $|f^{(n+1)}(x)|\\leq M$ holds. With \n\n\\begin{align}\n|E_{n}(x_{max})|\n &\\leq\\frac{M}{(n+1)!}|x_{max}-a|^{n+1} \\nonumber \\\\\n &= \\frac{exp(1.5\\pi)*(1.5\\pi)^{n+1}}{(n+1)!}\n\\end{align}\n\nwe now can find a value of $n$ for a given bound, i.e. we can find an value of $N\\mathbb{\\in N}$ s.t. $\\frac{exp(1.5\\pi)*(1.5\\pi)^{N+1}}{(N+1)!}\\leq\\epsilon$. With Octave/Matlab we can see: \n\n\\begin{itemize}\n\\item if N=20 then $\\epsilon\\approx2.9950*10^{-4}$\n\\item if N=25 then $\\epsilon\\approx8.8150*10^{-8}$\n\\item if N=30 then $\\epsilon\\approx1.0050*10^{-11}$\n\\end{itemize}\n\nWith this approach we have that $\\sum_{n=0}^{25}\\frac{(ikwh)^{n}}{n!}\\mathcal{F}\\left\\{ h{}^{n}\\right\\} (\\alpha,\\beta)$ is an approximation of $P(u,v)$ with error $\\epsilon\\approx8.8150*10^{-8}$. This means we can precompute 25 Fourier Transformations in order to approximate P(u,v) having an error $\\epsilon\\approx8.8150*10^{-8}$. \n\n\\section{PQ approach}\n\\subsection{One dimensional case}\n\\label{sec:pqonedimappendix}\nSince our series is bounded, we can simplify the right-hand-side of equation $\\ref{eq:pqgeometricseries}$. Note that $e^{-ix}$ is a complex number. Every complex number can be written in its polar form, i.e. \n\n\\begin{equation}\ne^{-ix} = cos(x) + i sin(x) \n\\label{eq:polarform}\n\\end{equation}\n\nUsing the following trigonometric identities\n\\begin{gather}\ncos(-x) = cos(x) \\nonumber \\\\\nsin(-x) = -sin(x)\n\\end{gather}\n\ncombined with $\\ref{eq:polarform}$ we can simplify the series $\\ref{eq:pqgeometricseries}$ even further to:\n\n\\begin{align}\n\\frac{1-e^{iwT(N+1)}}{1-e^{-iwT}}\n& =\\frac{1-cos(wT(N+1)) + i sin(wT(N+1)) }{1-cos(wT) + i sin(wT)}\n\\label{eq:pq1minusexp}\n\\end{align}\n\nEquation $\\ref{eq:pq1minusexp}$ is still a complex number, denoted as $(p+iq)$. Generally, every complex number can be written as a fraction of two complex numbers. This implies that the complex number $(p+iq)$ can be written as $(p+iq) = \\frac{(a+ib)}{(c+id)}$ for any $(a+ib), (c+id) \\neq 0$. Let us use the following substitutions: \n\n\\begin{align}\na& := 1 - cos(wT(N+1))&\nb& =sin(wT(N+1)) \\nonumber \\\\\nc& =1-cos(wT)&\nd& =sin(wT)\n\\label{eq:pqabcdsubstitudes}\n\\end{align}\n\nHence, using $\\ref{eq:pqabcdsubstitudes}$, it follows \n\n\\begin{equation}\n  \\frac{1-e^{iwT(N+1)}}{1-e^{-iwT}} = \\frac{(a+ib)}{(c+id)}\n\\end{equation}\n\nBy rearranging the terms, it follows $(a+ib) = (c+id)(p+iq)$ and by multiplying its right hand-side out we get the following system of equations:\n\n\\begin{align}\n(cp-dq)& =a \\nonumber \\\\\n(dp + cq)& =b\n\\label{eq:cdadcn}\n\\end{align}\n\nAfter multiplying the first equation of $\\ref{eq:cdadcn}$ by $c$ and the second by $d$ and then adding them together, we get using the law of distributivity new identities for $p$ and $q$:\n\n\\begin{align}\np& =\\frac{(ac+bd)}{c^2 + d^2} \\nonumber \\\\\nq& =\\frac{(bc+ad)}{c^2 + d^2}\n\\label{eq:pq1}\n\\end{align}\n\nUsing some trigonometric identities and putting our substitution from $\\ref{eq:pqabcdsubstitudes}$ for $a$, $b$, $c$, $d$ back into the current representation $\\ref{eq:pq1}$ of $p$ and $q$ we will get:\n\n\\begin{align}\np& =\\frac{1}{2}+\\frac{1}{2}\\left(\\frac{cos(wTN)-cos(wT(N+1))}{1-cos(wT)}\\right) \\nonumber \\\\\nq& =\\frac{sin(wT(N+1))-sin(wTN)-sin(wT)}{2(1-cos(wT))}\n\\end{align}\n\nSince we have seen, that $\\sum_{n=0}^N e^{-uwnT}$ is a complex number and can be written as $(p+iq)$, we now know an explicit expression for $p$ and $q$. Therefore, the one dimensional inverse Fourier transform of $S$ is equal:\n\n\\begin{align}\n\\mathcal{F}^{-1}\\{S\\}(w)\n& =\\mathcal{F}^{-1}\\{f\\}(w) \\sum_{n=0}^{N} e^{-iwnT} \\nonumber \\\\\n& = (p+iq) \\mathcal{F}^{-1}\\{f\\}(w)  \n\\label{eq:mainfinding1dappendix}\n\\end{align}\n\n\\subsection{Two dimensional case}\n\\label{sec:pqtwodimappendix}\n\n\\begin{align}\n\\mathcal{F}^{-1}\\{S\\}(w_1, w_2)\n& = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} \\sum_{n_2=0}^{N_1} \\sum_{n_2=0}^{N_2} h(x_1 + n_1 T_1, x_2 + n_2 T_2) e^{iw(x_1 + x_2)}dx_1 dx_2 \\nonumber \\\\\n& = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} \\sum_{n_2=0}^{N_1} \\sum_{n_2=0}^{N_2} h(y_1, y_2) e^{iw((y_1 - n_1 T_1) + (y_2 + n_2 T_2))}dx_1 dx_2 \\nonumber \\\\\n& =\\sum_{n_2=0}^{N_1} \\sum_{n_2=0}^{N_2} \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} h(y_1, y_2) e^{iw(y_1 + y_2)} e^{-iw(n_1 T_1 + n_2 T_2)}dy_1 dy_2 \\nonumber \\\\\n& =\\sum_{n_2=0}^{N_1} \\sum_{n_2=0}^{N_2} e^{-iw(n_1 T_1 + n_2 T_2)} \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} Box(y_1, y_2) e^{iw(y_1 + y_2)} dy_1 dy_2 \\nonumber \\\\\n& =\\left(\\sum_{n_2=0}^{N_1} \\sum_{n_2=0}^{N_2} e^{-iw(n_1 T_1 + n_2 T_2)}\\right) \\mathcal{F}^{-1}\\{h\\}(w_1,w_2) \\nonumber \\\\\n& =\\left(\\sum_{n_2=0}^{N_1} e^{-iw n_1 T_1}\\right) \\left(\\sum_{n_2=0}^{N_2} e^{-iw n_2 T_2}\\right) \\mathcal{F}^{-1}\\{h\\}(w_1,w_2) \\nonumber \\\\\n& =(p_1 + i q_1)(p_2 + i q_2) \\mathcal{F}^{-1}\\{h\\}(w_1,w_2) \\nonumber \\\\\n& =((p_1 p_2 - q_1 q_2) + i(p_1 p_2 + q_1 q_2)) \\mathcal{F}^{-1}\\{h\\}(w_1,w_2) \\nonumber \\\\\n& =(p + iq) \\mathcal{F}_{DTFT}\\{h\\}(w_1,w_2)\n\\label{eq:pqmainfindingappendix}\n\\end{align}\n\nWhere we have defined \n\n\\begin{align}\np := (p_1 p_2 - q_1 q_2) \\nonumber \\\\ \nq := (p_1 p_2 + q_1 q_2)\n\\label{eq:pqsubst2dappendix}\n\\end{align}", "meta": {"hexsha": "ab58a64897885ea743c1a9c5da95b7ac0b62907e", "size": 9187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/Source/Chapters/appendix_derivation.tex", "max_stars_repo_name": "simplay/Bachelor-Thesis", "max_stars_repo_head_hexsha": "ef450c5420b768b2a1fd84c9ad768f34db12fc88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "document/Source/Chapters/appendix_derivation.tex", "max_issues_repo_name": "simplay/Bachelor-Thesis", "max_issues_repo_head_hexsha": "ef450c5420b768b2a1fd84c9ad768f34db12fc88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-05-13T14:35:57.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-13T14:35:57.000Z", "max_forks_repo_path": "document/Source/Chapters/appendix_derivation.tex", "max_forks_repo_name": "simplay/Bachelor-Thesis", "max_forks_repo_head_hexsha": "ef450c5420b768b2a1fd84c9ad768f34db12fc88", "max_forks_repo_licenses": ["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.1179039301, "max_line_length": 335, "alphanum_fraction": 0.6631109176, "num_tokens": 3544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6182965592464474}}
{"text": "\\section{Algorithms}\\label{section:word}\n\n\\begin{definition}[Approximation algorithm]\n    Find approximate solutions to~\\nameref{optproblem}\n\\end{definition}\n\n\n\\begin{definition}[Asymptotic Polynomial-time Approximation Scheme, APTAS]\n\\label{APTAS}\n    A family of algorithms, and a constant $c$ such that all solutions has an\n    approximation of $(1 + \\epsilon)\\times{OPT} + c$ for minimization problems.\n\\end{definition}\n\n\n\\begin{definition}[Bin-packing]\n    A series of algorithms to learn how to distribute $n$ numbers into $k$ bins.\n    First-fit, best-fit, worst-fit (stack into where there is most free space),\n    best-fit, etc.\n\\end{definition}\n\n\\begin{definition}[Complimentary slackness]\n    Given an optimal solution to a linear program,\n    $Z_{LP}$ and it's dual $Y_{LP}$, with $x_{1}, x_{2}, \\dots x_{n}$ and\n    $y_{1}, y_{2}, \\dots y_{n}$ respecively, with\n    $w_{1}, w_{2}, \\dots w_{n}$ and $z_{1}, z_{2}, \\dots z_{n}$  as slack\n    variables for each solution, respectively,\n    then $\\forall x, x_{i}z_{i} = 0$ and $\\forall y, y_{i} w_{i} = 0$\n\n    This necessary condition for optimality conveys a fairly simple economic\n    principle.  In standard form (when maximizing), if there is slack in a\n    constrained primal resource (i.e., there are ``leftovers''),\n    then additional quantities of that resource must have no value. \n\\end{definition}\n\n\\begin{definition}[Difference heuristic and approximation]\n    While an heurisitc makes a choice, without a guarantee of optimality,\n    an approximation can make a choice and know that this choice will render\n    a solution within a factor of OPT.\\\n\\end{definition}\n\n\\begin{definition}[EDD]\\label{EDD}\n    Earliest Due Date\n\\end{definition}\n\n\\begin{definition}[F-approximation]\n    Also referred to as a linear approximation, using a function f,\n    which is affine.\n\\end{definition}\n\n\\begin{definition}[FPTAS, fully polynomial approximation scheme]\\label{FPTAS}\n    As in~\\nameref{PTAS}, just $\\frac{1}{\\epsilon}$.\n    The algoritm is required to be polynomial both in running time and problem\n    size.\n\n    Note that strongly NP-complete problems do not have any FPTAS.\\\n\\end{definition}\n\n\\begin{definition}[Integrality gap]\\label{integralitygap}\n    The biggest difference between an IP and LP\n\\end{definition}\n\n\\begin{definition}[Locality of Reference]\n     also known as the principle of locality, is a phenomenon describing the\n     same value, or related storage locations, being frequently accessed. There\n     are two basic types of reference locality – temporal and spatial locality.\n     Temporal locality refers to the reuse of specific data, and/or resources,\n     within a relatively small time duration. Spatial locality refers to the\n     use of data elements within relatively close storage locations. Sequential\n     locality, a special case of spatial locality, occurs when data elements\n     are arranged and accessed linearly, such as, traversing the elements in a\n     one-dimensional array\n\n\\end{definition}\n\n\\begin{definition}[Makespan]\n    The total length of a schedule; from 0 to $C_{\\max}$\n\\end{definition}\n\n\\begin{definition}[$\\tilde{O}$]\\label{otilde}\n    Given function $f(x)$, $\\tilde{O}(f(x)) = O(f(x)\\cdot{\\log^{k}{f(x)}})$\n\\end{definition}\n\n\\begin{definition}[Optimization problem]\\label{optproblem}\n    To find the best solution of $n$ feasible solutions.\n\\end{definition}\n\n\\begin{definition}[Perfect matching]\n    A collection $E^{\\prime} \\subseteq E$ of edges in a graph \n    $G = (V,E)$, such that $\\forall v \\in V$, are connected \n    from $E^{\\prime}$ only once.\n\\end{definition}\n\n\n\\begin{definition}[Pre-empty schedule]\\label{pre-emptive}\n    You can interrupt task and re-continue them.\n\\end{definition}\n\n\n\\begin{definition}[PTAS, Polynomial-time approximation scheme]\\label{PTAS}\n    Given an optimization problem (e.g.\\ an NP-problem) and a parameter \n    $\\epsilon$, produce a solution within (($1 + \\epsilon) \\times OPT$)\n    $\\epsilon > 0$\n\n    E.g.\\ for the traveling salesman, a tour would be of length max \n    $(1 + \\epsilon) \\times L$, with $L$ being the length of the tour\n\n    Note that for minimization, there is $1 + \\epsilon$, and for maximization,\n    there is $1 - \\epsilon$\n    \n    If you have a scheme with $(1 \\pm \\epsilon) \\times OPT + \\kappa$, then \n    it is not under PTAS.\\ PTAS only handles the former part, $(1 \\pm \\epsilon)$\n\n    For MAX SNP, there does not exist polynomial approximation schemes\n\\end{definition}\n\n\\begin{definition}[Parallel Random Access Machine]\n    an abstract computer for designing parallel algorithms\n\n\\end{definition}\n\n\\begin{definition}[$\\rho$-approximation]\n    Polynomial algorithm that is guaranteed to have objective function\n    to OPT within $\\rho$ of\n    optimum (not the ($1 + \\epsilon$) of~\\nameref{PTAS}).\n\\end{definition}\n\n\\begin{definition}[Scheduling]\n    See~\\nameref{srpt},\n    \\begin{itemize}\n        \\item \\textbf{$P_{i}$} = time to do a job $i$\n        \\item \\textbf{$R_{i}$} = earliest time a job $i$ can start\n        \\item \\textbf{$C_{i}$} = time of completion for job $i$\n        \\item \\textbf{$D_{i}$} = due date for job $i$\n        \\item \\textbf{$L_{i}$} = $C_{i} - D_{i}$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Strong duality]\n    The optimal value of the dual is equal to that of the primal linear program.\n\n    $ \\sum{y^{*}_{i}} = \\sum{w_{i}x_{i}}$\n\\end{definition}\n\n\\begin{definition}[Weak duality property]\n    No dual program has a solution greater than the optimal of the primal\n    linear program\n\\end{definition}\n\n\\begin{definition}[$\\alpha$ approximation]\n    Produce a solution who's value is within a factor of $\\alpha$ \n    of the optimal.\n\\end{definition}\n", "meta": {"hexsha": "da231e04281c6fa2732465b56b0b677451e5f07d", "size": 5681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/algorithm.tex", "max_stars_repo_name": "andsild/NotusVitae", "max_stars_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": "src/def/algorithm.tex", "max_issues_repo_name": "andsild/NotusVitae", "max_issues_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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/def/algorithm.tex", "max_forks_repo_name": "andsild/NotusVitae", "max_forks_repo_head_hexsha": "8afc580cce2ece4f129c006af3879bb738bb2269", "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": 37.1307189542, "max_line_length": 80, "alphanum_fraction": 0.7041013906, "num_tokens": 1528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6182965530386327}}
{"text": "\\chapter{The pred{\\und}sets Library}\n\nThe \\ml{pred\\_sets} library contains a theory of predicates regarded as sets.\nA predicate {\\small\\verb!s:'a->bool!} is considered as a collection or `set' of\nelements of type \\ml{'a}, and the standard operations on sets such as union,\nintersection, and set difference are appropriately defined for this\nrepresentation.  The library was originally written in 1989 by Ton Kalker.  It\nwas completely rewritten by the present author for \\HOL\\ version 2.01 in early\n1992.  The aim of this revision was to make the \\ml{pred\\_sets} library closely\nparallel to the much more developed \\HOL\\ \\ml{sets} library, with the same\nnames for constants and theorems and the same form of definitions for\noperations on sets.  The present document is itself also adapted from the\nmanual for the \\ml{sets} library~\\cite{melham}.\n\nThere is only one theory in the \\ml{pred\\_sets} library, namely the theory\n`\\ml{pred\\_set}'. This document explains the logical basis of this theory and\nthe theorem-proving support provided by library.  The latter includes\nconversions for expanding set specifications and for evaluating various\noperations on finite sets described by enumeration of their elements.  The\nlibrary also provides parser and pretty-printer support for terms that denote\nsets.\n\n\\section{Membership and the axioms of set theory}\n\nA value \\ml{x} is defined to be an element of a set exactly when the\ncharacteristic predicate of the set is true of \\ml{x}. Since sets in the\n\\ml{pred\\_sets} library are just represented by their characteristic\npredicates, this membership relation is straightforward to define as follows:\n\n\\begin{hol}\n\\index{definition!of IN@of {\\ptt IN}}\n\\index{SPECIFICATION@{\\ptt SPECIFICATION}}\n\\begin{verbatim}\n   SPECIFICATION   |- !P x. x IN P = P x\n\\end{verbatim}\\end{hol}\n\n\\noindent The infix function constant \\ml{IN} defined here constitutes the\nbasic language for the entire theory of sets in the \\ml{pred\\_sets} library;\nall operators and predicates on sets are ultimately defined in terms of this\none function.\n\nThe definition of \\ml{IN} shown above loosely corresponds to what is usually\ncalled the {\\it axiom of specification\\/}\\index{axiom of specification} for\nsets (hence the name \\ml{SPECIFICATION}). This axiom states that sets can be\nconstructed from predicates that describe or `specify' their elements. A value\nis an element of the constructed set exactly when the predicate is true of that\nvalue.  Since sets and predicates are identical in the \\ml{pred\\_sets} library,\nwe can simply say that \\ml{x} is in the `set' \\ml{P} exactly when\n{\\small\\verb!P x!} holds.\n\nThe definition of \\ml{IN} is one of two fundamental theorems in the\n\\ml{pred\\_sets} library, from which all others are derived.  The second of\nthese fundamental theorems states what is usually called the {\\it axiom of\nextension\\/}\\index{axiom of extension} for sets.  This is not, of course,\nliterally an {\\it axiom\\/} of the \\ml{pred\\_sets} theory, but rather a theorem\nderived by proof:\n\n\\begin{hol}\n\\index{EXTENSION@{\\ptt EXTENSION}}\n\\begin{verbatim}\n   EXTENSION   |- !s t. (s = t) <=> (!x. x IN s = x IN t)\n\\end{verbatim}\\end{hol}\n\n\\noindent \\ml{EXTENSION} states that two sets are equal exactly when they have\nthe same elements.  This follows directly from the definition of the constant\n\\ml{IN} and the extensionality functions in higher order logic.\n\nOnce the theorems \\ml{EXTENSION} and \\ml{SPECIFICATION} have been proved, they\nprovide a complete basis for all further reasoning about sets and membership.\nThe library theory \\ml{pred\\_sets} is developed entirely on the basis of these\ntwo `axioms' of set theory.\n\n\\section{Generalized set specifications}\n\nIn addition to the basic constant \\ml{IN}, which allows one to regard a\npredicate as the set of all values that satisfy it, the \\ml{pred\\_sets} library\nalso provides a general way of constructing sets by describing or specifying\ntheir elements.  Roughly speaking, there are two components to a generalized\nset specification: an expression \\ml{E[x]} and a predicate \\ml{P[x]}. For any\nsuch expression and predicate, there is a corresponding set\n{\\small\\verb!{E[x] | P[x]}!}, the set of all values {\\small\\verb!E[x]!} for\nwhich {\\small\\verb!P[x]!} holds.\n\nThe \\ml{pred\\_sets} library supports generalized set specifications by means of\nthe constant:\n\n\\begin{hol}\n\\index{GSPEC@{\\ptt GSPEC}}\n\\begin{verbatim}\n   GSPEC : ('b -> ('a # bool)) -> 'a -> bool\n\\end{verbatim}\n\\end{hol}\n\n\\noindent The function \\ml{GSPEC} takes a function \\ml{f :\\ 'b -> ('a \\# bool)}\nand constructs the set (i.e. predicate of type {\\small\\verb!'a->bool!}) of all\nvalues \\ml{FST(f x)} for which \\ml{SND(f x)} holds, for some value \\ml{x} of\ntype \\ml{'b}. The formal definition of the constant \\ml{GSPEC} is given by the\nfollowing constant specification:\n\n\\begin{hol}\n\\index{definition!of GSPEC@of {\\ptt GSPEC}}\n\\index{GSPECIFICATION@{\\ptt GSPECIFICATION}}\n\\begin{verbatim}\n   GSPECIFICATION   |- !f v. v IN (GSPEC f) = (?x. v,T = f x)\n\\end{verbatim}\n\\end{hol}\n\n\\noindent This theorem is analogous to the axiom of specification\\index{axiom\nof specification!for generalized set specifications} for \\ml{IN}.\nThis states that a value \\ml{v} is an element of the set specified by\n\\ml{f} exactly when \\ml{v} is one of the values of \\ml{FST(f x)} for which\n\\ml{SND(f x)} is true.\n\nTo see how this supports the notion of generalized set specification described\nabove, let \\ml{f} in this definition be the function\n{\\small\\verb!\\x.E[x],P[x]!}.  With a little simplification, we would then have:\n\n\\begin{hol}\n\\begin{verbatim}\n   |- !v. v IN (GSPEC \\x.E[x],P[x]) = ?x. (v = E[x]) /\\ P[x]\n\\end{verbatim}\n\\end{hol}\n\n\\noindent That is, a value \\ml{v} is in the set constructed by \\ml{GSPEC}\nexactly when for some \\ml{x} for which \\ml{P[x]}, the value \\ml{v} is equal to\n\\ml{E[x]}.  The constructed set therefore contains all values \\ml{E[x]} for\nwhich \\ml{P[x]} holds.\n\n\\subsection{Parser and pretty-printer support}\\label{abst}\n\nTo facilitate the use of sets constructed by generalized set specification, the\n\\ml{pred\\_sets}\\linebreak[3] library provides parser and pretty-printer support\nfor set abstractions expressed by the notation\n{\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!}.  The built-in \\ML\\ function\n\\ml{define\\_set\\_abstraction\\_syntax}%\n\\index{define\\_set\\_abstraction\\_syntax@{\\ptt\ndefine\\_set\\_abstraction\\_syntax}} (see the manual~\\cite{description} for\ndetails) is used to introduce this \\mbox{notation} when the library is loaded.\nThe call made to this function extends the \\HOL\\ parser so that a quotation of\nthe form {\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!} {\\samepage parses to:\n\n\\begin{hol}\n\\begin{alltt}\n   GSPEC (\\bk(\\m{x\\sb{1}},\\(\\dots\\),\\m{x\\sb{n}}).(\\(E\\),\\(P\\)))\n\\end{alltt}\n\\end{hol}\n\n\\noindent where $x_1$, \\dots, $x_n$ are} the variables that occur free in both\nthe expression $E$ and the proposition $P$ (i.e.\\ the set $\\{x_1,\\dots,x_n\\}$\nis the intersection of the set of free variables of $E$ and the set of free\nvariables of $P$).  If there are {\\it no\\/} variables free in both $E$ and $P$,\nthen a parser error is generated.  When the\n\\ml{print\\_set}\\index{print\\_set@{\\ptt print\\_set} (flag)} flag is \\ml{true},\nthe quotation pretty-printer inverts this transformation.\n\nA simple example of this set abstraction notation is shown in the following\n\\HOL\\ session, in which it is assumed that the \\ml{pred\\_sets} library has\nalready been loaded. (See section~\\ref{using} for a description of how\n\\ml{pred\\_sets} is loaded.)\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#let gtr = new_definition (`gtr`, \"gtr N = {n | n > N}\");;\ngtr = |- !N. gtr N = {n | n > N}\n\n#set_flag (`print_set`,false);;\ntrue : bool\n\n#\"{n | n > N}\";;\n\"GSPEC(\\n. (n,n > N))\" : term\n\\end{verbatim}\\end{session}\n\n\n\\noindent The term {\\small\\verb!{n | n > N}!} in the definition of \\ml{gtr}\ndenotes the set of all natural numbers greater than \\ml{N}.  It is important to\nnote that the variable \\ml{N} is a free variable in this term, since it occurs\non only one side of the bar `{\\small\\verb!|!}'.  The set abstraction\n{\\small\\verb!{n | n > N}!} therefore parses to the generalized set\nspecification\n\n\\begin{hol}\n\\begin{verbatim}\n   GSPEC(\\n. (n,n > N))\n\\end{verbatim}\\end{hol}\n\n\\noindent This is what gives this set abstraction the (presumably intended)\ninterpretation `the set of all \\ml{n} greater than \\ml{N}'.  By contrast, the\nterm\n\n\\begin{hol}\n\\begin{verbatim}\n   GSPEC(\\(n,N). (n,n > N))\n\\end{verbatim}\\end{hol}\n\n\\noindent denotes the set of all numbers \\ml{n} greater than some number\n\\ml{N}---i.e., the set $\\{\\ml{1},\\ml{2},\\ml{3},\\dots\\}$.  This is {\\it not\\/}\nthe default interpretation of the parser, which constructs a generalized set\nspecification that binds the variable \\ml{n} only. Note that only\ndefault\\pagebreak[3] interpretations are pretty-printed using the {\\samepage\nset abstraction notation:\n\n\\begin{session}\n\\begin{verbatim}\n#set_flag(`print_set`,true);;\nfalse : bool\n\n#\"GSPEC (\\n. (n,n>N))\";;\n\"{n | n > N}\" : term\n\n#\"GSPEC (\\(n,N). (n,n>N))\";;\n\"GSPEC(\\(n,N). (n,n > N))\" : term\n\\end{verbatim}\\end{session}\n\n\\noindent That is, a term of the form:\n\n\\begin{hol}\n\\begin{alltt}\n   GSPEC (\\bk(\\m{x\\sb{1}},\\(\\dots\\),\\m{x\\sb{n}}).(\\(E\\),\\(P\\)))\n\\end{alltt}\\end{hol}\n\n\\noindent prints as {\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!} only if the\nvariables $x_1$, \\dots, $x_n$ occur free in both $E$ and $P$.}\n\n\nIn general, the expression $E$ in a set abstraction\n{\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!} need not be just a variable.\nConsider, for example, the following \\HOL\\ session:\n\n\\begin{session}\n\\begin{verbatim}\n#let S = \"{(n,m) | n < m}\";;\nS = \"{(n,m) | n < m}\" : term\n\n#set_flag(`print_set`,false);;\ntrue : bool\n\n#\"{(n,m) | n < m}\";;\n\"GSPEC(\\(n,m). ((n,m),n < m))\" : term\n\\end{verbatim}\\end{session}\n\n\\noindent Here, a set abstraction is used to construct the set of all pairs of\nnumbers \\ml{(n,m)} for which \\ml{n} is less than \\ml{m}.  Note that both\nvariables \\ml{n} and \\ml{m} are bound in the underlying generalized set\nspecification.\n\n\\subsection{Theorem-proving support}\n\n\\index{SET\\_SPEC\\_CONV@{\\ptt SET\\_SPEC\\_CONV}|(}\n\\index{conversions!SET\\_SPEC\\_CONV@{\\ptt SET\\_SPEC\\_CONV}|(}\nThe \\ml{pred\\_sets} library provides proof support for the set abstraction\nnotation in the form of a conversion called \\ml{SET\\_SPEC\\_CONV}.  This\nconversion implements the axiom of specification for set abstractions.%\n\\index{axiom of specification!for set abstractions}\nWhen $v$ is a variable, evaluating:\n\n\\begin{hol}\\def\\m#1{\\mbox{\\small$#1$}}\n\\begin{alltt}\n   SET_SPEC_CONV \"\\m{t} IN \\lb\\m{v} \\vb \\m{P}\\rb\";;\n\\end{alltt}\\end{hol}\n\n\\noindent returns the theorem:\n\n\\begin{hol}\\def\\m#1{\\mbox{\\small$#1$}}\n\\begin{alltt}\n   {\\vb}- \\m{t} IN \\lb\\m{v} \\vb \\m{P}\\rb = \\m{P[t/v]}\n\\end{alltt}\\end{hol}\n\n\\noindent This states that $t$ is an element of the set of all $v$ such that\n$P$ exactly when $P[t/v]$ holds. Note that, in general, the term $t$ need not\nbe a variable. The following session illustrates this use of\n\\ml{SET\\_SPEC\\_CONV} for membership {\\samepage in a particular set abstraction:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#SET_SPEC_CONV ``12 IN {n | n > N}``;\n|- 12 IN {n | n > N} = 12 > N\n\\end{verbatim}\\end{session}}\n\n\\pagebreak[3]\n\nThe conversion \\ml{SET\\_SPEC\\_CONV} behaves differently when applied to terms\nof the form {\\small\\verb!\"!$t$\\verb! IN {!$E$\\verb! | !$P$\\verb!}\"!} where\n{\\small $E$} is not a variable.  Applying the conversion to a term of this kind\nyields the theorem:\n\n\\begin{hol}\\def\\m#1{\\mbox{\\small$#1$}}\n\\begin{alltt}\n   {\\vb}- \\m{t} IN \\lb\\m{E} \\vb \\m{P}\\rb = ?\\m{x\\sb{1}\\dots x\\sb{n}}. (\\m{t} = \\m{E}) /\\bk \\m{P}\n\\end{alltt}\\end{hol}\n\n\\noindent where $x_1$, \\dots, $x_n$ are the variables that occur free in both\n$E$ and $P$. The expression $E$ cannot in general be eliminated in this case,\nas it can by the substitution $P[t/v]$ when $E$ is just a variable $v$.\n\n\\pagebreak[3]\n\nThe following session illustrates the form of the theorem proved by\n\\ml{SET\\_SPEC\\_CONV} for the second type of input term discussed above:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#let th1 = SET_SPEC_CONV \"p IN {(n,m) | n < m}\";;\nth1 = |- p IN {(n,m) | n < m} = (?n m. (p = n,m) /\\ n < m)\n\n#let th2 = SET_SPEC_CONV \"(a,b) IN {(n,m) | n < m}\";;\nth2 = |- (a,b) IN {(n,m) | n < m} = (?n m. (a,b = n,m) /\\ n < m)\n\n#let th3 = SET_SPEC_CONV \"a IN {n + m | n < m}\";;\nth3 = |- a IN {n + m | n < m} = (?n m. (a = n + m) /\\ n < m)\n\\end{verbatim}\\end{session}\n\n\\noindent The right-hand sides of \\ml{th1} and \\ml{th2} could, in principle, be\nfurther simplified.  The value of the expression `\\ml{(n,m)}' is an injective\nfunction of the values of \\ml{n} and \\ml{m}, and so by eliminating the\nexistential quantifiers these two theorems could be simplified to:\n\n\\begin{hol}\n\\begin{verbatim}\n   th1    |- p IN {(n,m) | n < m} = (FST p < SND p)\n\n   th2    |- (a,b) IN {(n,m) | n < m} = (a < b)\n\\end{verbatim}\\end{hol}\n\n\\noindent But in general the value of {\\small $E$} in a set abstraction\n{\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!} will not be an injective function of\nits free variables, as for example is the case in theorem \\ml{th3}.  The\nconversion \\ml{SET\\_SPEC\\_CONV} therefore attempts no further simplification of\nits result than is described above for the general\ncase.\\index{SET\\_SPEC\\_CONV@{\\ptt SET\\_SPEC\\_CONV}|)}%\n\\index{conversions!SET\\_SPEC\\_CONV@{\\ptt SET\\_SPEC\\_CONV}|)}\n\n\\section{The empty and universal sets}\n\nThe following two constants are defined in the \\ml{pred\\_sets} library:\n{\\small\\verb!EMPTY:'a->bool!}, which denotes the empty set; and\n{\\small\\verb!UNIV:'a->bool!}, which denotes the universe, or set of all values\nof type \\ml{'a}.{\\samepage  These constants are defined formally as follows:\n\n\\begin{hol}\n\\index{definition!of EMPTY@of {\\ptt EMPTY}}\n\\index{EMPTY\\_DEF@{\\ptt EMPTY\\_DEF}}\n\\index{definition!of UNIV@of {\\ptt UNIV}}\n\\index{UNIV\\_DEF@{\\ptt UNIV\\_DEF}}\n\\begin{verbatim}\n  EMPTY_DEF  |- EMPTY = \\x. F\n  UNIV_DEF   |- UNIV  = \\x. T\n\\end{verbatim}\\end{hol}\n\n\\noindent The\\index{naming conventions!for definitions|(} theorems\n\\ml{EMPTY\\_DEF} and \\ml{UNIV\\_DEF} shown above are named according\nto the general convention that all definitions in the \\ml{pred\\_sets} library\nare given names ending\nin `{\\small\\verb!_DEF!}'.\\index{naming conventions!for definitions|)}}\n\n\\pagebreak[3]\n\nNote that because of the restriction on free variables discussed above, the set\nabstractions {\\small\\verb!\"{x | T}\"!} and {\\small\\verb!\"{x | F}\"!} cannot be\nused in these definitions; the more primitive form of set construction given by\nthe above lambda-abstractions must be used instead.  But users of the library\nwill never need to appeal to these definitions, since the following theorems\nabout \\ml{EMPTY} and \\ml{UNIV} are also made available in the theory\n\\ml{pred\\_sets}:\n\n\\begin{hol}\n\\index{NOT\\_IN\\_EMPTY@{\\ptt NOT\\_IN\\_EMPTY}}\n\\index{IN\\_UNIV@{\\ptt IN\\_UNIV}}\n\\begin{verbatim}\n   NOT_IN_EMPTY  |- !x. ~x IN EMPTY\n   IN_UNIV       |- !x. x IN UNIV\n\\end{verbatim}\\end{hol}\n\n\\noindent That is, nothing is an element of \\ml{EMPTY} and everything is an\nelement of \\ml{UNIV}. These properties follow directly from the definitions and\nthe theorem \\ml{SPECIFICATION}.  Other pre-proved theorems about the empty and\nuniversal sets are also available in the library; see chapter~\\ref{theorems}\nfor a complete list.\n\n\\section{Set inclusion}\n\nThe infix functions \\ml{SUBSET} and \\ml{PSUBSET} denote the binary relations of\nset inclusion and proper set inclusion, respectively.  These are defined\nformally in the obvious way:\n\n\\begin{hol}\n\\index{definition!of SUBSET@of {\\ptt SUBSET}}\n\\index{SUBSET\\_DEF@{\\ptt SUBSET\\_DEF}}\n\\index{definition!of PSUBSET@of {\\ptt PSUBSET}}\n\\index{PSUBSET\\_DEF@{\\ptt PSUBSET\\_DEF}}\n\\begin{verbatim}\n  SUBSET_DEF   |- !s t. s SUBSET t = (!x. x IN s ==> x IN t)\n  PSUBSET_DEF  |- !s t. s PSUBSET t = s SUBSET t /\\ ~(s = t)\n\\end{verbatim}\\end{hol}\n\n\\noindent That is, \\ml{s} is a subset of \\ml{t} if every element of \\ml{s} is\nalso an element of \\ml{t}; and \\ml{s} is a proper subset of \\ml{t} if it is a\nsubset of \\ml{t} but not equal to \\ml{t}.\n\nVarious pre-proved theorems about the subset and proper subset relations are\nsupplied by the \\ml{pred\\_sets} library.  For example, the fact that\n\\ml{SUBSET} is a partial order is stated by the three built-in theorems shown\nbelow.\n\n\\begin{hol}\n\\index{SUBSET\\_TRANS@{\\ptt SUBSET\\_TRANS}}\n\\index{SUBSET\\_REFL@{\\ptt SUBSET\\_REFL}}\n\\index{SUBSET\\_ANTISYM@{\\ptt SUBSET\\_ANTISYM}}\n\\begin{verbatim}\n  SUBSET_REFL     |- !s. s SUBSET s\n  SUBSET_TRANS    |- !s t u. s SUBSET t /\\ t SUBSET u ==> s SUBSET u\n  SUBSET_ANTISYM  |- !s t. s SUBSET t /\\ t SUBSET s ==> (s = t)\n\\end{verbatim}\\end{hol}\n\n\\noindent Also provided are built-in theorems about the relationship between\nset inclusion and other constants or operations on sets.  For example, there\nare the following facts about set inclusion and the empty and universal sets:\n\n\\begin{hol}\n\\index{EMPTY\\_SUBSET@{\\ptt EMPTY\\_SUBSET}}\n\\index{SUBSET\\_UNIV@{\\ptt SUBSET\\_UNIV}}\n\\index{NOT\\_PSUBSET\\_EMPTY@{\\ptt NOT\\_PSUBSET\\_EMPTY}}\n\\index{NOT\\_UNIV\\_PSUBSET@{\\ptt NOT\\_UNIV\\_PSUBSET}}\n\\begin{verbatim}\n  EMPTY_SUBSET       |- !s. {} SUBSET s\n  SUBSET_UNIV        |- !s. s SUBSET UNIV\n  NOT_PSUBSET_EMPTY  |- !s. ~s PSUBSET {}\n  NOT_UNIV_PSUBSET   |- !s. ~UNIV PSUBSET s\n\\end{verbatim}\\end{hol}\n\n\\noindent As\\index{naming conventions!for theorems generally|(} these examples\nillustrate, the names of theorems in the \\ml{pred\\_sets} library are generally\nconstructed from the names of the constants they contain.  Furthermore, the\nordering of elements in the name of a theorem attempts to reflect the content\nof the theorem itself.\\index{naming conventions!for theorems generally|)}\n\n\\section{Union, intersection, and set difference}\n\nThe binary operations of union, intersection and set difference are all defined\nusing the set abstraction notation introduced above in section~\\ref{abst}.  The\nformal definitions are:\n\n\\begin{hol}\n\\index{definition!of UNION@of {\\ptt UNION}}\n\\index{UNION\\_DEF@{\\ptt UNION\\_DEF}}\n\\index{definition!of INTER@of {\\ptt INTER}}\n\\index{INTER\\_DEF@{\\ptt INTER\\_DEF}}\n\\index{definition!of DIFF@of {\\ptt DIFF}}\n\\index{DIFF\\_DEF@{\\ptt DIFF\\_DEF}}\n\\begin{verbatim}\n  UNION_DEF    |- !s t. s UNION t = {x | x IN s \\/ x IN t}\n  INTER_DEF    |- !s t. s INTER t = {x | x IN s /\\ x IN t}\n  DIFF_DEF     |- !s t. s DIFF t = {x | x IN s /\\ ~x IN t}\n\\end{verbatim}\\end{hol}\n\n\\noindent These definitions illustrate the practical utility of the scheme for\nvariable binding in set abstractions discussed above in section~\\ref{abst}.  An\nabstraction {\\small\\verb!\"{!$E$\\verb! | !$P$\\verb!}\"!} binds only the variables\nthat occur in both {\\small $E$} and {\\small $P$}, and the variables \\ml{s} and\n\\ml{t} in the set abstractions shown above may therefore be made parameters to\nthe sets\\pagebreak[3] constructed by them.\n\nUsing \\ml{SET\\_EQ\\_CONV}, it is trivial to derive the following membership\nconditions for \\ml{UNION}, \\ml{INTER} and \\ml{DIFF} from the definitions given\nabove. As\\index{naming conventions!for membership conditions|(} a general rule,\ntheorems stating membership conditions of the kind illustrated by these\nexamples are given names of the form {\\small\\verb!IN_!$\\langle\\hbox{\\it\nconstant\\/}\\rangle$} ending in the name of the operation used to construct the\nset in question.\\index{naming conventions!for membership conditions|)}\n\n\\begin{hol}\n\\index{IN\\_UNION@{\\ptt IN\\_UNION}}\n\\index{IN\\_INTER@{\\ptt IN\\_INTER}}\n\\index{IN\\_DIFF@{\\ptt IN\\_DIFF}}\n\\begin{verbatim}\n   IN_UNION  |- !s t x. x IN (s UNION t) = x IN s \\/ x IN t\n   IN_INTER  |- !s t x. x IN (s INTER t) = x IN s /\\ x IN t\n   IN_DIFF   |- !s t x. x IN (s DIFF t) = x IN s /\\ ~x IN t\n\\end{verbatim}\\end{hol}\n\n\\noindent These theorems, which are saved in the library under the names\nindicated above, may in practice be used as the defining properties of union,\nintersection and set difference; users should almost never have to appeal\ndirectly to the definitions of these operations.  Other built-in theorems about\n\\ml{UNION}, \\ml{INTER} and \\ml{DIFF} may be found in chapter~\\ref{theorems}.\n\n\\section{Disjoint sets}\n\nTwo sets are {\\it disjoint\\/} if they have no elements in common. This concept\nis formalized in the \\ml{pred\\_sets} library by the constant \\ml{DISJOINT}, the\ndefinition of which is:\n\n\\begin{hol}\n\\index{definition!of DISJOINT@of {\\ptt DISJOINT}}\n\\index{DISJOINT\\_DEF@{\\ptt DISJOINT\\_DEF}}\n\\begin{verbatim}\n   DISJOINT_DEF  |- !s t. DISJOINT s t = (s INTER t = {})\n\\end{verbatim}\\end{hol}\n\n\\noindent At present, there are relatively few pre-proved theorems about the\n\\ml{DISJOINT} relation in the library. But see chapter~\\ref{theorems} for the\nfew theorems about \\ml{DISJOINT} that are in fact available in the\n\\ml{pred\\_sets} library.\n\n\\section{Insertion and deletion of an element}\n\nTo aid in the construction of particular sets of values (especially finite\nsets) the library contains definitions of two constants \\ml{INSERT} and\n\\ml{DELETE}.  These denote the operations of augmenting a set with a given\nvalue and removing a value from a set, respectively.  The formal definitions of\nthese operations are:\n\n\\begin{hol}\n\\index{definition!of INSERT@of {\\ptt INSERT}}\n\\index{INSERT\\_DEF@{\\ptt INSERT\\_DEF}}\n\\index{definition!of DELETE@of {\\ptt DELETE}}\n\\index{DELETE\\_DEF@{\\ptt DELETE\\_DEF}}\n\\begin{verbatim}\n   INSERT_DEF  |- !x s. x INSERT s = {y | (y = x) \\/ y IN s}\n   DELETE_DEF  |- !s x. s DELETE x = s DIFF (INSERT x EMPTY)\n\\end{verbatim}\\end{hol}\n\n\\noindent The elements of the set denoted by {\\small\\verb!x INSERT s!} are all\nthe elements of the set \\ml{s} together with the value \\ml{x}, which may or may\nnot be an element of \\ml{s} itself.  The set denoted by\n{\\small\\verb!s DELETE x!} contains all the elements of \\ml{s}\nexcept the value \\ml{x}.\n\n{\\samepage The membership conditions for sets constructed using \\ml{INSERT} and\n\\ml{DELETE} are given by the following pre-proved theorems:\n\n\\begin{hol}\n\\index{IN\\_INSERT@{\\ptt IN\\_INSERT}}\n\\index{IN\\_DELETE@{\\ptt IN\\_DELETE}}\n\\begin{verbatim}\n   IN_INSERT  |- !x y s. x IN (y INSERT s) = (x = y) \\/ x IN s\n   IN_DELETE  |- !s x y. x IN (s DELETE y) = x IN s /\\ ~(x = y)\n\\end{verbatim}\\end{hol}\n\n\\noindent In addition, the library} contains a substantial collection of\ntheorems about the relationship between the operations \\ml{INSERT} and\n\\ml{DELETE} and other relations and operations on sets.  Chapter~\\ref{theorems}\ngives a complete list of these theorems.\n\n\\subsection{Parser and pretty-printer support}\\label{finite}\n\nThe \\ml{pred\\_sets} library provides special parser and pretty-printer support\nfor finite sets that are constructed by enumeration of their elements. This\nnotation is introduced by a call made when the library is loaded to the\nbuilt-in \\ML\\ function \\ml{define\\_finite\\_set\\_syntax}%\n\\index{define\\_finite\\_set\\_syntax@{\\ptt define\\_finite\\_set\\_syntax}}\n(see~\\cite{description} for details of this function).  This has the effect of\nextending the \\HOL\\ parser so that a quotation of the form\n{\\small\\verb!\"{!\\tt$t_1$,$t_2$,\\dots,$t_n$\\verb!}\"!} parses to the following\nset built up from \\ml{EMPTY} by repeatedly using the function \\ml{INSERT}:\n\n\\begin{hol}\n\\begin{alltt}\n   INSERT \\m{t\\sb{1}} (INSERT \\m{t\\sb{2}} \\dots (INSERT \\m{t\\sb{n}} EMPTY)\\dots)\n\\end{alltt}\\end{hol}\n\n\\noindent Note that the quotation {\\small\\verb!\"{}\"!} just parses to the\nconstant \\ml{EMPTY}. When the\n\\ml{print\\_set}\\index{print\\_set@{\\ptt print\\_set} (flag)}\nflag is \\ml{true}, the \\HOL\\ pretty-printer for terms inverts this\ntransformation.\n\nUsers should note that care must be taken with regard to the precedence of\ncomma in a context {\\small\\verb!\"{!\\dots\\verb!}\"!}, as the following session\nillustrates:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#set_flag(`print_set`,false);;\ntrue : bool\n\n#\"{1,2,3,4}\";;\n\"1 INSERT (2 INSERT (3 INSERT (4 INSERT EMPTY)))\" : term\n\n#\"{(1,2),(3,4)}\";;\n\"(1,2) INSERT ((3,4) INSERT EMPTY)\" : term\n\n#\"{((1,2),(3,4))}\";;\n\"((1,2),3,4) INSERT EMPTY\" : term\n\\end{verbatim}\\end{session}\n\n\\noindent Different grouping by means of enclosing parentheses has given sets\nwith four elements (each a number), two elements (each of which is a pair), and\none element (a pair of pairs) respectively.\n\n\\subsection{Conversions for enumerated finite sets}\n\nThe \\ml{pred\\_sets} library provides a collection of optimized conversions for\ncomputing the results of operations and predicates on finite sets specified by\nenumeration of their elements.  All these conversions, the current\nimplementations of which are somewhat experimental, are designed to work only\nfor finite sets of the form {\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!}\"!}.\nThe sections that follow describe most of these conversions; the remainder are\ndiscussed in later sections of this manual.\n\n\\subsubsection{Membership}\\label{inconv}\n\nThe\\index{IN\\_CONV@{\\ptt IN\\_CONV}|(}%\n\\index{conversions!IN\\_CONV@{\\ptt IN\\_CONV}|(} most basic\nconversion for finite sets is a decision procedure for membership called\n\\ml{IN\\_CONV}.  In general, a way of deciding equality of elements is needed in\norder to determine whether a given value is an element of a particular finite\nset.  The function\n\n\\begin{hol}\n\\begin{verbatim}\n   IN_CONV : conv -> conv\n\\end{verbatim}\\end{hol}\n\n\\noindent must therefore be supplied with a conversion that implements a\ndecision procedure for equality of set elements.  It is assumed that this\nconversion will map equations {\\small\\tt\"$e_1$ = $e_2$\"} between elements of a\nbase type \\ml{ty} to the theorem {\\small\\tt |- ($e_1$ = $e_2$) = T} or to the\ntheorem {\\small\\tt |- ($e_1$ = $e_2$) = F}, as appropriate.\n\nIf \\ml{conv} is an equality conversion of the kind described above, then the\nfunction returned by \\ml{IN\\_CONV conv} is a conversion that decides membership\nin finite sets of values of the base type \\ml{ty}.  In particular, a call:\n\n\\begin{hol}\n\\begin{alltt}\n   IN\\_CONV conv \"\\m{t} IN \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb\"\n\\end{alltt}\\end{hol}\n\n\\noindent returns the theorem\n\n\\begin{hol}\n\\begin{alltt}\n   |- \\m{t} IN \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb = T\n\\end{alltt}\\end{hol}\n\n\\noindent if the term $t$ is alpha-equivalent to some term $t_i$ or if the\nsupplied conversion \\ml{conv} proves {\\tt |- ($t$ = $t_i$) = T} for some $i$\nwhere $1 \\leq i \\leq n$.  If, on the other hand \\ml{conv} proves the theorem\n{\\tt |- ($t$ = $t_i$) = F} for all $i$ where $1 \\leq i \\leq n$, then the result\nis the theorem\n\n\\begin{hol}\n\\begin{alltt}\n   |- \\m{t} IN \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb = F\n\\end{alltt}\\end{hol}\n\n\\noindent In all other cases, the call to \\ml{IN\\_CONV} shown above will fail.\n\nThe following session shows how \\ml{IN\\_CONV} can be used in practice.\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#IN_CONV num_EQ_CONV \"1 IN {2,1,3}\";;\n|- 1 IN {2,1,3} = T\n\n#IN_CONV num_EQ_CONV \"4 IN {2,1,3}\";;\n|- 4 IN {2,1,3} = F\n\\end{verbatim}\\end{session}\n\n\\noindent The built-in conversion \\ml{num\\_EQ\\_CONV} is used here to decide\nequality of the natural numbers involved in the membership\nassertions\\pagebreak[3] being proved.\n\nAn example in which \\ml{IN\\_CONV} fails is the following:\n\n\\begin{session}\n\\begin{verbatim}\n#IN_CONV num_EQ_CONV \"x IN {1,2,3}\";;\nevaluation failed     IN_CONV\n\n#num_EQ_CONV \"x = 1\";;\nevaluation failed     num_EQ_CONV\n\\end{verbatim}\\end{session}\n\n\\noindent Failure occurs in this case because the term \\ml{x} is a variable,\nand \\ml{num\\_EQ\\_CONV} therefore cannot determine if it is equal to any of the\nset elements \\ml{1}, \\ml{2} or \\ml{3}.  Note, however, that the supplied\nconversion is not required to prove anything if the value being tested for\nmembership happens to be syntactically identical to an element of the given\nset:\n\n\\begin{session}\n\\begin{verbatim}\n#IN_CONV NO_CONV \"x IN {1,x,3}\";;\n|- x IN {1,x,3} = T\n\\end{verbatim}\\end{session}\n\n\\noindent In this case, the supplied conversion, namely \\ml{NO\\_CONV}, always\nfails; but the call to \\ml{IN\\_CONV} nonetheless succeeds and returns the\nappropriate result.\\index{IN\\_CONV@{\\ptt IN\\_CONV}|)}%\n\\index{conversions!IN\\_CONV@{\\ptt IN\\_CONV}|)}\n\n\\subsubsection{Union}\n\nThe\\index{UNION\\_CONV@{\\ptt UNION\\_CONV}|(}%\n\\index{conversions!UNION\\_CONV@{\\ptt UNION\\_CONV}|(}\n\\ml{pred\\_sets} library contains a conversion\n\n\\begin{hol}\n\\begin{verbatim}\n   UNION_CONV : conv -> conv\n\\end{verbatim}\\end{hol}\n\n\\noindent that can be used to compute the union of two finite sets.  The first\nargument to \\ml{UNION\\_CONV} (i.e.\\ the conversion argument) is expected to be\nan equality conversion of the same kind required as an argument by\n\\ml{IN\\_CONV} (see section~\\ref{inconv}).  As will be seen below, this\nconversion is used by \\ml{UNION\\_CONV} to simplify the set that it computes as\nthe result of taking the union of two finite sets.\n\nGiven an equality conversion \\ml{conv}, the function \\ml{UNION\\_CONV} returns a\nconversion that computes the union of a finite set\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!}\"!} and another set {\\small$s$}. The\nsecond set {\\small$s$} in fact need not be finite.  Ignoring, for the moment,\nthe possible simplification done using the supplied conversion \\ml{conv}, a\ncall:\n\n\\begin{hol}\\begin{alltt}\n   UNION\\_CONV conv \"\\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb UNION \\m{s}\"\n\\end{alltt}\\end{hol}\n\n\\noindent just returns the theorem\n\n\\begin{hol}\\begin{alltt}\n   |- \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb UNION \\m{s} = \\m{t\\sb{1}} INSERT (\\m{\\dots} (\\m{t\\sb{n}} INSERT \\m{s})\\m{\\dots})\n\\end{alltt}\\end{hol}\n\n\\noindent That is, \\ml{UNION\\_CONV} computes the required union as a repeated\ninsertion of values into the set {\\small$s$}.\\pagebreak[3] When {\\small$s$} is\na finite set of the form {\\small\\verb!\"{!\\tt$u_1$,\\dots,$u_m$\\verb!}\"!}, the\n{\\samepage resulting theorem will have the form shown below.\n\n\\begin{hol}\n\\begin{alltt}\n   |- \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb UNION \\lb\\m{u\\sb{1}},\\dots,\\m{u\\sb{m}}\\rb = \\lb\\m{t\\sb{1}},\\m{\\dots},\\m{t\\sb{n}},\\m{u\\sb{1}},\\m{\\dots},\\m{u\\sb{m}}\\rb\n\\end{alltt}\\end{hol}\n\n\\noindent When computing} theorems of this form (i.e.\\ when the second set of\nthe union is a finite set {\\small\\verb!\"{!\\tt$u_1$,\\dots,$u_m$\\verb!}\"!}) the\nfunction \\ml{UNION\\_CONV} attempts to remove redundant elements in the\nresulting set using the supplied equality conversion \\ml{conv}.  In particular,\nif \\ml{conv} is able to prove that some element {\\small$t_i$} of\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!}\"!} is equal to any element\n{\\small$u_j$} of {\\small\\verb!\"{!\\tt$u_1$,\\dots,$u_m$\\verb!}\"!}, that is if the\nconversion \\ml{conv} maps the term {\\small\\verb!\"!$t_i$\\verb! = !$u_j$\\verb!\"!}\nto the theorem {\\small\\verb!|- (!$t_i$\\verb! = !$u_j$\\verb!) = T!}, then the\nresulting theorem will be\n\n\\begin{hol}\n\\begin{alltt}\n   |- \\lb\\m{t\\sb{1}},\\dots\\m{t\\sb{i}},\\dots,\\m{t\\sb{n}}\\rb UNION \\lb\\m{u\\sb{1}},\\dots,\\m{u\\sb{j}},\\dots,\\m{u\\sb{m}}\\rb = \\lb\\m{t\\sb{1}},\\m{\\dots},\\m{t\\sb{n}},\\m{u\\sb{1}},\\dots,\\m{u\\sb{j}},\\dots,\\m{u\\sb{m}}\\rb\n\\end{alltt}\\end{hol}\n\n\\noindent That is, the redundant term \\m{t_i} will be removed from the initial\nsequence of elements in the resulting finite set.  The function\n\\ml{UNION\\_CONV} also checks for and eliminates alpha-equivalent elements.\n\nSome examples of \\ml{UNION\\_CONV} in use are shown in the following \\HOL\\\nsession:\n\n\\begin{session}\n\\begin{verbatim}\n#UNION_CONV NO_CONV \"{1,2,3} UNION {4,5,6}\";;\n|- {1,2,3} UNION {4,5,6} = {1,2,3,4,5,6}\n\n#UNION_CONV NO_CONV \"{1,2,3} UNION {3,2,SUC 0}\";;\n|- {1,2,3} UNION {3,2,SUC 0} = {1,3,2,SUC 0}\n\\end{verbatim}\\end{session}\n\n\\noindent The supplied equality conversion in these examples is \\ml{NO\\_CONV},\nand only the elements of the first set {\\small\\verb!{1,2,3}!} that are\nredundant by virtue of being alpha-equivalent to elements of the second set\nare eliminated from the resulting set.  An example in which the equality\nconversion is actually used is:\n\n\\begin{session}\n\\begin{verbatim}\n#UNION_CONV num_EQ_CONV \"{1,2,3} UNION {3,2,SUC 0}\";;\n|- {1,2,3} UNION {3,2,SUC 0} = {3,2,SUC 0}\n\\end{verbatim}\\end{session}\n\n\\noindent In this case, \\ml{num\\_EQ\\_CONV} is used to prove that\n{\\small\\verb!1!} is equal to {\\small\\verb!SUC 0!}, so that the resulting union\nis the set {\\small\\verb!\"{3,2,SUC 0}\"!}, rather than\n{\\small\\verb!\"{1,3,2,SUC 0}!\"}.\\index{UNION\\_CONV@{\\ptt UNION\\_CONV}|)}%\n\\index{conversions!UNION\\_CONV@{\\ptt UNION\\_CONV}|)}\n\n\\subsubsection{Insertion}\n\nThe\\index{INSERT\\_CONV@{\\ptt INSERT\\_CONV}|(}%\n\\index{conversions!INSERT\\_CONV@{\\ptt INSERT\\_CONV}|(}\nconversion \\ml{INSERT\\_CONV} performs the following reduction\non finite sets:\n\n\\begin{hol}\n\\begin{alltt}\n   {\\normalsize\\rm reduce}\\quad\"\\m{t} INSERT \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{i}},\\dots,\\m{t\\sb{n}}\\rb\"\\quad\\m{\\normalsize\\rm to}\\quad\"\\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{i}},\\dots,\\m{t\\sb{n}}\\rb\"\n\\end{alltt}\\end{hol}\n\n\\noindent if a supplied equality conversion can prove\n{\\small\\verb!|- (!$t$\\verb! = !$t_i$\\verb!) = T!}.  Since the\nenumerated set notation\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!}\"!} is just a parser-supported\nabbreviation (see section~\\ref{finite}), this is equivalent to reducing the set\n{\\small\\verb!\"{!\\tt$t$,$t_1$,\\dots,$t_i$,\\dots,$t_n$\\verb!}\"!} to\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_i$,\\dots,$t_n$\\verb!}\"!} when the terms\n{\\small$t$} and {\\small$t_i$} are provably equal.\\pagebreak[3]\n\nMore specifically, if for some {\\small$t_i$} in\n{\\small\\verb!{!$t_1$\\verb!,!\\dots\\verb!,!$t_n$\\verb!}!},\nthe terms {\\small$t$} and  {\\small$t_i$} are alpha-equivalent, of if\nthe conversion \\ml{conv} maps {\\small\\verb!\"!$t$\\verb! = !$t_i$\\verb!\"!} to\nthe theorem {\\small\\verb!|- (!$t$\\verb! = !$t_i$\\verb!) = T!}, then the call:\n\n\\begin{hol}\n\\begin{alltt}\n   INSERT\\_CONV conv \"\\m{t} INSERT \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb\";;\n\\end{alltt}\\end{hol}\n\n\\noindent will return the theorem:\n\n\\begin{hol}\n\\begin{alltt}\n   |- \\m{t} INSERT \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb = \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb\n\\end{alltt}\\end{hol}\n\nHere is an example of \\ml{INSERT\\_CONV} in use:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#INSERT_CONV num_EQ_CONV \"(SUC 2) INSERT {0,1,2,3}\";;\n|- {SUC 2,0,1,2,3} = {0,1,2,3}\n\\end{verbatim}\\end{session}\n\nWhen applied repeatedly, \\ml{INSERT\\_CONV} can be used to reduce finite sets by\neliminating as many redundant occurrences of elements as possible.  An easy to\nprogram, but slow-running, way of doing this is to use \\ml{DEPTH\\_CONV}:\n\n\\begin{session}\n\\begin{verbatim}\n#DEPTH_CONV (INSERT_CONV num_EQ_CONV) \"{1,3,x,SUC 1,SUC(SUC 1),2,1,3,x}\";;\n|- {1,3,x,SUC 1,SUC(SUC 1),2,1,3,x} = {2,1,3,x}\n\\end{verbatim}\\end{session}\n\n\\noindent For a faster alternative to this method, see the reference entry for\n\\ml{INSERT\\_CONV} in\nchapter~\\ref{entries}.\\index{INSERT\\_CONV@{\\ptt INSERT\\_CONV}|)}%\n\\index{conversions!INSERT\\_CONV@{\\ptt INSERT\\_CONV}|)}\n\n\\subsubsection{Deletion}\n\nThe\\index{DELETE\\_CONV@{\\ptt DELETE\\_CONV}|(}%\n\\index{conversions!DELETE\\_CONV@{\\ptt DELETE\\_CONV}|(}\nconversion \\ml{DELETE\\_CONV} reduces terms of the form\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!} DELETE !$t$\\verb!\"!}\nby deleting all elements provably equal to {\\small$t$} from the set\n{\\small\\verb!{!\\tt$t_1$,\\dots,$t_n$\\verb!}!}.\nLike \\ml{IN\\_CONV} and \\ml{INSERT\\_CONV}, the function \\ml{DELETE\\_CONV} takes\na conversion for deciding equality of set elements as an argument.\nIf \\ml{conv}\nis such a conversion, the call:\n\n\\begin{hol}\\begin{alltt}\n   DELETE\\_CONV conv \"\\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb DELETE \\m{t}\";;\n\\end{alltt}\\end{hol}\n\n\\noindent will return the theorem:\n\n\\begin{hol}\\begin{alltt}\n   |- \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb DELETE \\m{t} = \\lb\\m{t\\sb{i}},\\dots,\\m{t\\sb{j}}\\rb\n\\end{alltt}\\end{hol}\n\n\\noindent where the resulting set\n {\\small\\verb!{!\\tt$t_i$,\\dots,$t_j$\\verb!}!} is the set of all\nvalues {\\small$t_k$} in the original set\n {\\small\\verb!{!\\tt$t_1$,\\dots,$t_n$\\verb!}!} for which \\ml{conv} proves\n{\\tt |- ($t_k$ = $t$) = F}, and where for all {\\small$t_k$} in\n{\\small\\verb!{!\\tt$t_1$,\\dots,$t_n$\\verb!}!} but not in\n {\\small\\verb!{!\\tt$t_i$,\\dots,$t_j$\\verb!}!}, either  {\\small$t_k$}\nis alpha-equivalent to  {\\small$t$} or \\ml{conv} proves\n{\\tt |- ($t_k$ = $t$) = T}.  Note that the conversion \\ml{conv} must\nprove either equality or inequality for every element of the original set that\nis not simply alpha-equivalent to the deleted value.\n\nThe following session shows \\ml{DELETE\\_CONV} in use:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#DELETE_CONV num_EQ_CONV \"{0,1,2,3} DELETE (SUC 1)\";;\n|- {0,1,2,3} DELETE (SUC 1) = {0,1,3}\n\\end{verbatim}\\end{session}%\n\\index{DELETE\\_CONV@{\\ptt DELETE\\_CONV}|)}%\n\\index{conversions!DELETE\\_CONV@{\\ptt DELETE\\_CONV}|)}\n\n\n\\section{Singleton sets}\n\nA {\\it singleton\\/} set is a set that contains precisely one element.  In the\n\\ml{pred\\_sets} library, the property of being a singleton set is expressed by\nthe definition:\n\n\\begin{hol}\n\\index{definition!of SING@of {\\ptt SING}}\n\\index{SING\\_DEF@{\\ptt SING\\_DEF}}\n\\begin{verbatim}\n   SING_DEF   |- !s. SING s = (?x. s = {x})\n\\end{verbatim}\\end{hol}\n\n\\noindent The library contains several built-in theorems about singleton sets.\nThese are sometimes expressed in terms of the predicate \\ml{SING}, as for\nexample in the theorem\n\n\\begin{hol}\n\\index{SING@{\\ptt SING}}\n\\begin{verbatim}\n   SING   |- !x. SING{x}\n\\end{verbatim}\\end{hol}\n\n\\noindent But properties of singleton sets are more usually formulated as\ntheorems about sets of the form `{\\small\\verb\"{x}\"}'. For example, the built-in\ntheorems about singleton sets include:\n\n\\begin{hol}\n\\index{SING@{\\ptt SING}}\n\\begin{verbatim}\n   NOT_SING_EMPTY  |- !x. ~({x} = {})\n   IN_SING         |- !x y. x IN {y} = (x = y)\n   EQUAL_SING      |- !x y. ({x} = {y}) = (x = y)\n\\end{verbatim}\\end{hol}\n\n\\noindent A\\index{naming conventions!for theorems about singletons|(} general\nconvention is that theorems about singleton sets are given names that contain\nthe element `\\ml{SING}', regardless of whether or not they actually contain the\npredicate \\ml{SING}.\\index{naming conventions!for theorems about singletons|)}\n\n\\section{The {\\tt CHOICE} and {\\tt REST} functions}\n\nThe \\ml{pred\\_sets} library contains the definition of a functions \\ml{CHOICE}\nwhich can be used to select an arbitrary element from a non-empty set. The\nfunction \\ml{CHOICE} is defined formally by the following constant\nspecification:\n\n\\begin{hol}\n\\index{definition!of CHOICE@of {\\ptt CHOICE}}\n\\index{CHOICE\\_DEF@{\\ptt CHOICE\\_DEF}}\n\\begin{verbatim}\n   CHOICE_DEF   |- !s. ~(s = {}) ==> (CHOICE s) IN s\n\\end{verbatim}\\end{hol}\n\n\\noindent This theorem alone is the defining property for the constant\n\\ml{CHOICE}, which is therefore an only partially specified function from sets\nto values.  Note, in particular, that there is no information given by this\ndefinition about the result of applying \\ml{CHOICE} to an empty set.\n\nThe library also contains a function \\ml{REST}, which is defined in terms of\nthe \\ml{CHOICE} function as follows\n\n\\begin{hol}\n\\index{definition!of REST@of {\\ptt REST}}\n\\index{REST\\_DEF@{\\ptt REST\\_DEF}}\n\\begin{verbatim}\n   REST_DEF   |- !s. REST s = s DELETE (CHOICE s)\n\\end{verbatim}\\end{hol}\n\n\\noindent For any non-empty set \\ml{s}, the set \\ml{REST s} comprises all those\nelements of \\ml{s} except the value selected from \\ml{s} by \\ml{CHOICE}.\n\nThe library contains various built-in theorems about the functions \\ml{CHOICE}\nand \\ml{REST}; for a full list of these theorems, see chapter~\\ref{theorems}.\n\n\\section{Image of a function on a set}\n\nThe {\\it image\\/} of a function {\\small\\verb!f:'a->'b!} on a set\n{\\small\\verb!s:'a->bool!} is the set of values {\\small\\verb!f(x)!} for all\n\\ml{x} in \\ml{s}.  In the \\ml{pred\\_sets} library, the image of a function on a\nset is defined in terms of the obvious set abstraction:\n\n\\begin{hol}\n\\index{definition!of IMAGE@of {\\ptt IMAGE}}\n\\index{IMAGE\\_DEF@{\\ptt IMAGE\\_DEF}}\n\\begin{verbatim}\n   IMAGE_DEF   |- !f s. IMAGE f s = {f x | x IN s}\n\\end{verbatim}\\end{hol}\n\n\\noindent Using \\ml{SET\\_SPEC\\_CONV}, is trivial to prove from this\ndefinition the following membership condition for sets constructed using\n\\ml{IMAGE}:\n\n\\begin{hol}\n\\index{IN\\_IMAGE@{\\ptt IN\\_IMAGE}}\n\\begin{verbatim}\n   IN_IMAGE   |- !y s f. y IN (IMAGE f s) = (?x. (y = f x) /\\ x IN s)\n\\end{verbatim}\\end{hol}\n\n\\noindent The \\ml{pred\\_sets} library contains various theorems about\n\\ml{IMAGE} in addition to this membership theorem.  These include, for example,\ntheorems about the image of a function on sets constructed by the operations of\nunion and intersection.  For a full list of theorems about \\ml{IMAGE}, see\nchapter~\\ref{theorems}.\n\n\\subsection{Theorem-proving support}\n\nThe\\index{IMAGE\\_CONV@{\\ptt IMAGE\\_CONV}|(}%\n\\index{conversions!IMAGE\\_CONV@{\\ptt IMAGE\\_CONV}|(}\n\\ml{pred\\_sets} library contains\na conversion for computing the image of a function {\\small\\verb!f!} on a finite\nset {\\small\\verb!{!\\tt$t_1$,\\dots,$t_n$\\verb!}!}.  The function\n\n\\begin{hol}\n\\begin{verbatim}\n   IMAGE_CONV : conv -> conv -> conv\n\\end{verbatim}\\end{hol}\n\n\\noindent is parameterized by two conversions.  The first conversion is\nexpected to compute the result of applying the function {\\small\\verb!f!} to\neach element {\\small$t_1$}, \\dots, {\\small $t_n$}.  The second parameter is an\nequality conversion which is used to simplify the resulting image set by\nremoving redundant occurrences of its elements.\n\nThe following session shows a simple example of the use of \\ml{IMAGE\\_CONV} on\nterms of the form\n{\\small\\tt\\verb!\"IMAGE (\\x.x+2) {!$t_1$,\\dots,$t_n$\\verb!}\"!}.\nWe first define a conversion that evaluates the\nresult of applying the function {\\small\\verb!(\\x.x+2)!} to a term {\\small$t$}.\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n- val AP_CONV = BETA_CONV THENC (TRY_CONV ADD_CONV);;\nAP_CONV = - : conv\n\n- AP_CONV ``(\\n.n+2) 7``;\n|- (\\n. n + 2)7 = 9\n\\end{verbatim}\\end{session}\n\n\\noindent This conversion, together with the function \\ml{IMAGE\\_CONV}, gives a\nconversion for computing the image of {\\small\\verb!(\\x.x+2)!} on a finite set\nof numerical values.\n\n\\begin{session}\n\\begin{verbatim}\n- IMAGE_CONV AP_CONV NO_CONV ``IMAGE (\\x.x+2) {1;2;3;4}``;\nval it = |- IMAGE(\\x. x + 2){1;2;3;4} = {3;4;5;6} : thm\n\n- IMAGE_CONV AP_CONV NO_CONV ``IMAGE (\\x.x+2) {n;1;n}``;\nval it = |- IMAGE(\\x. x + 2){n;1;n} = {3;n + 2} : thm\n\\end{verbatim}\\end{session}\n\n\\noindent In this case, the second parameter supplied to \\ml{IMAGE\\_CONV} is\nthe conversion \\ml{NO\\_CONV}. This means that no reduction of the resulting\nimage set is done, beyond the elimination of elements that are provably\nredundant by virtue of being alpha-equivalent to some other element (as in the\nsecond example above).\n\nThe following session illustrates the use of the second parameter to\n\\ml{IMAGE\\_CONV}.\n\n\\begin{session}\n\\begin{verbatim}\n#IMAGE_CONV BETA_CONV NO_CONV \"IMAGE (\\x. SUC x) {1,SUC 0,2,0}\";;\n|- IMAGE(\\x. SUC x){1,SUC 0,2,0} = {SUC 1,SUC(SUC 0),SUC 2,SUC 0}\n\n#IMAGE_CONV BETA_CONV num_EQ_CONV \"IMAGE (\\x. SUC x) {1,SUC 0,2,0}\";;\n|- IMAGE(\\x. SUC x){1,SUC 0,2,0} = {SUC(SUC 0),SUC 2,SUC 0}\n\\end{verbatim}\\end{session}\n\n\\noindent In the first evaluation, just applying \\ml{BETA\\_CONV} to the\napplication of {\\small\\verb!(\\x. SUC x)!} to each element has resulted in an\nimage set containing both {\\small\\verb!SUC 1!} and {\\small\\verb!SUC(SUC 0)!}.\nIn the second example, \\ml{num\\_EQ\\_CONV} is used to prove these values equal,\nand therefore to simplify the resulting set by eliminating one of them from it.\nFor more detail about \\ml{IMAGE\\_CONV}, see the reference entry for this\nconversion in chapter~\\ref{entries}.\\index{IMAGE\\_CONV@{\\ptt IMAGE\\_CONV}|)}%\n\\index{conversions!IMAGE\\_CONV@{\\ptt IMAGE\\_CONV}|)}\n\n\\section{Mappings between sets}\n\nThe \\ml{pred\\_sets} library contains a few basic definitions and theorems\nhaving to do with mappings between sets.  A function \\ml{f:'a->'b} is an {\\it\ninjective\\/} (one-to-one) mapping from a set {\\small\\verb!s:'a->bool!} to a set\n{\\small\\verb!t:'b->bool!} if it takes distinct elements of the set \\ml{s} to\ndistinct element of the set \\ml{t}:\n\n\\begin{hol}\n\\index{definition!of INJ@of {\\ptt INJ}}\n\\index{INJ\\_DEF@{\\ptt INJ\\_DEF}}\n\\begin{verbatim}\n   INJ_DEF =\n   |- !f s t.\n       INJ f s t =\n       (!x. x IN s ==> (f x) IN t) /\\\n       (!x y. x IN s /\\ y IN s ==> (f x = f y) ==> (x = y))\n\\end{verbatim}\\end{hol}\n\n\\noindent Likewise, a function \\ml{f:'a->'b} is a {\\it surjective\\/} (onto)\nmapping from \\ml{s} to \\ml{t} if for every element \\ml{x} of \\ml{t} there is\nsome element \\ml{y} of \\ml{s} for which {\\small\\verb!f y = x!}:\n\n\\begin{hol}\n\\index{definition!of SURJ@of {\\ptt SURJ}}\n\\index{SURJ\\_DEF@{\\ptt SURJ\\_DEF}}\n\\begin{verbatim}\n   SURJ_DEF =\n   |- !f s t.\n       SURJ f s t =\n       (!x. x IN s ==> (f x) IN t) /\\\n       (!x. x IN t ==> (?y. y IN s /\\ (f y = x)))\n\\end{verbatim}\\end{hol}\n\n\\noindent Finally, a function \\ml{f:'a->'b} is a {\\it bijection\\/} from \\ml{s}\nto \\ml{t} if it is both injective and surjective:\n\n\\begin{hol}\n\\index{definition!of BIJ@of {\\ptt BIJ}}\n\\index{BIJ\\_DEF@{\\ptt BIJ\\_DEF}}\n\\begin{verbatim}\n   BIJ_DEF = |- !f s t. BIJ f s t = INJ f s t /\\ SURJ f s t\n\\end{verbatim}\\end{hol}\n\nThere are a few pre-proved theorems about the predicates \\ml{INJ}, \\ml{SURJ},\nand \\ml{BIJ} available in the library; see chapter~\\ref{theorems} for a full\nlist of these theorems.\n\nThe library also contains constant specifications for two functions \\ml{LINV}\nand \\ml{RINV}, which yield left and right inverses to injective and surjective\nmappings respectively.  These functions are defined by:\n\n\\begin{hol}\n\\index{definition!of LINV@of {\\ptt LINV}}\n\\index{LINV\\_DEF@{\\ptt LINV\\_DEF}}\n\\index{definition!of RINV@of {\\ptt RINV}}\n\\index{RINV\\_DEF@{\\ptt RINV\\_DEF}}\n\\begin{verbatim}\n   LINV_DEF = |- !f s t. INJ f s t ==> (!x. x IN s ==> (LINV f s(f x) = x))\n   RINV_DEF = |- !f s t. SURJ f s t ==> (!x. x IN t ==> (f(RINV f s x) = x))\n\\end{verbatim}\\end{hol}\n\n\\noindent There are, at present, no additional built-in theorems about these\ntwo functions. Furthermore, the definitions of \\ml{LINV} and \\ml{RINV} shown\nabove should be regarded as only provisional; they may be changed in future\nversions.\n\n\\section{Finite and infinite sets}\n\nThe \\ml{pred\\_sets} library includes the definition of a predicate called\n\\ml{FINITE}, which is true of finite sets and false of infinite ones.  The\ndefinition of this constant is shown below.\n\n\\begin{hol}\n\\index{definition!of FINITE@of {\\ptt FINITE}}\n\\index{FINITE\\_DEF@{\\ptt FINITE\\_DEF}}\n\\begin{verbatim}\n   FINITE_DEF\n     |- !s.\n         FINITE s =\n         (!P. P{} /\\ (!s'. P s' ==> (!e. P(e INSERT s'))) ==> P s)\n\\end{verbatim}\\end{hol}\n\n\\noindent That is, a set \\ml{s} is finite precisely when it is in the smallest\nclass of sets that contains the empty set and is closed under the \\ml{INSERT}\noperation.  This inductive definition makes \\ml{FINITE} true of just those sets\nthat can be constructed from the empty set by a finite sequence of applications\nof the \\ml{INSERT} operation.\n\nThe \\ml{pred\\_sets} library contains various built-in theorems that follow from\nthe definition of \\ml{FINITE} given above.  Among these are the two fundamental\ntheorems shown below:\n\n\\begin{hol}\n\\index{FINITE\\_EMPTY@{\\ptt FINITE\\_EMPTY}}\n\\index{FINITE\\_INSERT@{\\ptt FINITE\\_INSERT}}\n\\begin{verbatim}\n   FINITE_EMPTY   |- FINITE{}\n   FINITE_INSERT  |- !x s. FINITE(x INSERT s) = FINITE s\n\\end{verbatim}\\end{hol}\n\n\\noindent These state that the empty set is indeed finite and insertion\nconstructs finite sets only from other finite sets. See chapter~\\ref{theorems}\nfor other built-in theorems about finite sets.\n\nThe above definition of \\ml{FINITE} formalizes the notion of a finite set in\nlogic, and it therefore also determines the form of definition for the\ncomplementary notion of an infinite set. In the \\ml{pred\\_sets} library, the\npredicate \\ml{INFINITE} is defined as follows:\n\n\\begin{hol}\n\\index{definition!of INFINITE@of {\\ptt INFINITE}}\n\\index{INFINITE\\_DEF@{\\ptt INFINITE\\_DEF}}\n\\begin{verbatim}\n   INFINITE_DEF   |- !s. INFINITE s = ~FINITE s\n\\end{verbatim}\\end{hol}\n\n\\noindent There are a few consequences of this definition stored in the\n\\ml{pred\\_sets} library.  The following theorem, for example, states that the\nimage of an injective function on an infinite set is infinite:\n\n\\begin{hol}\n\\index{IMAGE\\_11\\_INFINITE@{\\ptt IMAGE\\_11\\_INFINITE}}\n\\begin{verbatim}\n   IMAGE_11_INFINITE\n      |- !f. (!x y. (f x = f y) ==> (x = y)) ==>\n             (!s. INFINITE s ==> INFINITE(IMAGE f s))\n\\end{verbatim}\\end{hol}\n\n\\noindent Other built-in theorems about \\ml{INFINITE} can be found in\nchapter~\\ref{theorems}.\n\n\\subsection{Theorem-proving support}\n\nThere are two \\ML\\ functions in the \\ml{pred\\_sets} library for reasoning about\npropositions that involve the finiteness predicate \\ml{FINITE}.\nThe\\index{FINITE\\_CONV@{\\ptt FINITE\\_CONV}|(}\n\\index{conversions!FINITE\\_CONV@{\\ptt FINITE\\_CONV}|(} first of these is a\nconversion \\ml{FINITE\\_CONV} which automatically proves that sets of the form\n{\\small\\verb!\"{!\\tt$t_1$,\\dots,$t_n$\\verb!}\"!} are finite.  Evaluating\n\n\\begin{hol}\n\\begin{alltt}\n   FINITE\\_CONV \"FINITE \\lb\\m{t\\sb{1}},\\dots,\\m{t\\sb{n}}\\rb\";;\n\\end{alltt}\\end{hol}\n\n\\noindent yields the theorem\n{\\small\\verb!|- FINITE {!\\tt$t_1$,\\dots,$t_n$\\verb!} = T!}.%\n\\index{FINITE\\_CONV@{\\ptt FINITE\\_CONV}|)}%\n\\index{conversions!FINITE\\_CONV@{\\ptt FINITE\\_CONV}|)}\n\nThe\\index{SET\\_INDUCT\\_TAC@{\\ptt SET\\_INDUCT\\_TAC}|(}\n\\index{tactics!SET\\_INDUCT\\_TAC@{\\ptt SET\\_INDUCT\\_TAC}|(}\nsecond \\ML\\ function for\nreasoning about the predicate \\ml{FINITE} is an induction tactic called\n\\ml{SET\\_INDUCT\\_TAC}.  When applied to a goal of the form\n{\\small\\verb!\"!!$s$\\verb!. FINITE !$s$\\verb! ==> !$P$\\verb!\"!}, this tactic\nreduces it to proving that the property of sets expressed by\n{\\small\\verb!\\!$s$\\verb!.!$P$} holds of the empty set and is preserved by the\ninsertion of an element into an arbitrary finite set.  Since every finite set\ncan be built up from the empty set by repeated insertion of values, these\nsubgoals imply that this property holds of all finite sets.\n\nThe following session illustrates the use of the tactic \\ml{SET\\_INDUCT\\_TAC}\nfor proving that the intersection of an arbitrary set \\ml{t} with a finite set\n\\ml{s} is finite.  We first set up an appropriate goal:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{verbatim}\n#g \"!s:'a->bool. FINITE s ==> !t. FINITE(s INTER t)\";;\n\"!s. FINITE s ==> (!t. FINITE(s INTER t))\"\n\n() : void\n\\end{verbatim}\\end{session}\n\n\\noindent Expanding with \\ml{SET\\_INDUCT\\_TAC} yields:\n\n\\begin{session}\n\\begin{verbatim}\n#expand SET_INDUCT_TAC;;\nOK..\n2 subgoals\n\"!t. FINITE((e INSERT s) INTER t)\"\n    [ \"FINITE s\" ]\n    [ \"!t. FINITE(s INTER t)\" ]\n    [ \"~e IN s\" ]\n\n\"!t. FINITE({} INTER t)\"\n\n() : void\n\\end{verbatim}\\end{session}\n\n\\noindent The resulting subgoals are easy to prove, given the two basic\ntheorems \\ml{FINITE\\_EMPTY} and \\ml{FINITE\\_INSERT} shown in the previous\nsection. Note that it may be assumed in the step case that the value \\ml{e}\nbeing inserted into the set \\ml{s} is not already an element of\n\\ml{s}.\\index{SET\\_INDUCT\\_TAC@{\\ptt SET\\_INDUCT\\_TAC}|)}%\n\\index{tactics!SET\\_INDUCT\\_TAC@{\\ptt SET\\_INDUCT\\_TAC}|)}\n\n\\section{Cardinality of finite sets}\n\nThe {\\it cardinality\\/} of a finite set is the number of elements it contains.\nIn the \\ml{pred\\_sets} library, this is formalized by a constant \\ml{CARD}\ndefined by means of the following constant specification:\n\n\\begin{hol}\n\\index{definition!of CARD@of {\\ptt CARD}}\n\\index{CARD\\_DEF@{\\ptt CARD\\_DEF}}\n\\begin{verbatim}\n  CARD_DEF\n    |- (CARD{} = 0) /\\\n       (!s.\n         FINITE s ==>\n         (!x. CARD(x INSERT s) = (x IN s => CARD s | SUC(CARD s))))\n\\end{verbatim}\\end{hol}\n\n\\noindent This theorem is the sole defining property of \\ml{CARD}.  Because the\nequation in the second clause holds only under the assumption that \\ml{s} is\nfinite, this form of definition allows nothing significant to be deduced about\nthe cardinality `\\ml{CARD s}' of an {\\it infinite\\/} set \\ml{s}.\n\nThe built-in theorems about cardinality are all restricted to finite sets only,\neither implicitly as in the theorem:\n\n\\begin{hol}\n\\index{CARD\\_SING@{\\ptt CARD\\_SING}}\n\\begin{verbatim}\n   CARD_SING  |- !x. CARD{x} = 1\n\\end{verbatim}\\end{hol}\n\n\\noindent or explicitly, as in:\n\n\\begin{hol}\n\\index{FINITE\\_ISO\\_NUM@{\\ptt FINITE\\_ISO\\_NUM}}\n\\begin{verbatim}\n   FINITE_ISO_NUM\n     |- !s:'a->bool.\n         FINITE s ==>\n         (?f:num->'a.\n           (!n m.\n             n < (CARD s) /\\ m < (CARD s) ==> (f n = f m) ==> (n = m)) /\\\n           (s = {f n | n < (CARD s)}))\n\\end{verbatim}\\end{hol}\n\n\\noindent This second theorem states that the elements of a finite set can\nalways be put into a one-to-one correspondence with the natural numbers less\nthan the set's cardinality---i.e. the elements of a finite set \\ml{s} can be\nnumbered \\ml{0}, \\ml{1}, \\dots, {\\small\\verb!(CARD s)-1!}.  Other theorems\ninvolving the cardinality function \\ml{CARD} can be found in\nchapter~\\ref{theorems}.\n\n\\section{Using the library}\\label{using}\n\nThe \\ml{pred\\_sets} library is loaded into a user's \\HOL\\ session using the\nfunction \\ml{load\\_library} (see the \\HOL\\ manual for a general description of\nlibrary loading).  The first action in the load sequence is to update the\ninternal \\HOL\\ search paths.  A pathname to the library is added to the search\npath so that theorems may be autoloaded from the library theory\n\\ml{pred\\_sets}; and the \\HOL\\ help search path is updated with a pathname to\nonline help files for the \\ML\\ functions in the library.\n\nAfter the search paths are updated, the actions taken by the load sequence for\n\\ml{pred\\_sets} depend on the current state of the \\HOL\\ session. If the system\nis in draft mode, the library theory \\ml{pred\\_sets} is added as a new parent\nto the current theory.  If the system is not in draft mode, but the current\ntheory is an ancestor of the \\ml{pred\\_sets} theory in the library (e.g.\\ the\nuser is in a fresh \\HOL\\ session) then \\ml{pred\\_sets} is made the current\ntheory.  In both cases, the \\ML\\ functions provided by the library are loaded\ninto \\HOL\\, and all the theorems in the library (including definitions) are set\nup to be autoloaded on demand.  The parser and pretty-printer for the notation\ndescribed above in sections~\\ref{abst} and~\\ref{finite} are then activated, and\nthe \\ML\\ functions provided by the library for reasoning about sets are loaded.\nThe \\ml{pred\\_sets} library is then fully loaded into the user's \\HOL\\ session.\n\n\\subsection{Example session}\n\nThe following session shows how the \\ml{pred\\_sets} library may be loaded using\n\\ml{load\\_library}. Suppose, beginning in a fresh \\HOL\\ session, the user\nwishes to create a theory \\ml{foo} whose parents include the theory\n\\ml{pred\\_sets} in the library. This may be done as follows:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{alltt}\n#new_theory `foo`;;\n() : void\n\n#load_library `pred_sets`;;\n  \\(\\vdots\\)\nLibrary pred_sets loaded.\n() : void\n\\end{alltt}\\end{session}\n\n\\noindent Loading the library while drafting the theory \\ml{foo} makes the\nlibrary theory \\ml{pred\\_sets} into a parent of \\ml{foo}.  The same effect\ncould have been achieved (in a fresh session) by first loading the library and\nthen creating \\ml{foo}:\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{alltt}\n#load_library `pred_sets`;;\n  \\(\\vdots\\)\nLibrary pred_sets loaded.\n() : void\n\n#new_theory `foo`;;\n() : void\n\\end{alltt}\\end{session}\n\n\\noindent The theory \\ml{pred\\_sets} is first made the current theory of the\nnew session.  It then automatically becomes a parent of \\ml{foo} when this\ntheory is created by \\ml{new\\_theory}.\n\nNow, suppose that \\ml{foo} has been created as shown above, and the user does\nsome work in this theory, quits \\HOL, and in a later session wishes to load the\ntheory \\ml{foo}.  This must be done by {\\it first\\/} loading the\n\\ml{pred\\_sets} library and {\\it then\\/} loading the theory \\ml{foo}.\n\n\\setcounter{sessioncount}{1}\n\\begin{session}\n\\begin{alltt}\n#load_library `pred_sets`;;\n  \\(\\vdots\\)\nLibrary pred_sets loaded.\n() : void\n\n#load_theory `foo`;;\nTheory foo loaded\n() : void\n\\end{alltt}\\end{session}\n\n\\noindent This sequence of actions ensures that the system can find the parent\ntheory \\ml{pred\\_sets} when it comes to load \\ml{foo}, since loading the\nlibrary updates the search path.\n\n\\subsection{The {\\tt load\\_pred\\_sets} function}%\n\\index{load\\_pred\\_sets@{\\ptt load\\_pred\\_sets}|(}\n\nThe \\ml{pred\\_sets} library may in many cases simply be loaded into the system\nas illustrated by the examples given above.  There are, however, certain\nsituations in which the library cannot be fully loaded at the time when the\n\\ml{load\\_library} is used.  This occurs when the system is not in draft mode\nand the current theory is not an ancestor of the theory \\ml{pred\\_sets}.  In\nthis case, loading the library can (and will) update the search paths.  But the\ntheory \\ml{pred\\_sets} can neither be made into a parent of the current theory\nnor be made the current theory.  This means that autoloading from the library\ncan not at this stage be activated; and the \\ML\\ code in the library can not be\nloaded into \\HOL, since it requires access to some of the theorems in the\nlibrary.\n\nIn the situation described above---when the system is not in draft mode and the\ncurrent theory is not an ancestor of the theory \\ml{pred\\_sets}---the library\nload sequence defines an \\ML\\ function called \\ml{load\\_pred\\_sets} in the\ncurrent \\HOL\\ session.  If at a future point in the session the \\ml{pred\\_sets}\ntheory (now accessible via the search path) becomes an ancestor of the current\ntheory, this function can then be used to complete loading of the library.\nEvaluating {\\small\\verb!load_pred_sets()!} in such a context loads the \\ML\\\nfunctions of the \\ml{pred\\_sets} library into \\HOL\\ and activates autoloading\nfrom its theory files.  It also activates the parser and pretty-printer support\nfor set abstractions and finite sets.  The function \\ml{load\\_pred\\_sets} fails\nif the theory \\ml{pred\\_sets} is not an ancestor of the current \\HOL\\ theory.\n\nNote that the function \\ml{load\\_pred\\_sets} becomes available upon loading the\n\\ml{pred\\_sets} library only if the library theory \\ml{pred\\_sets} at the point\nof loading the library can neither be made into a new parent (i.e.\\ the system\nis not in draft mode) nor be made the current\ntheory.\\index{load\\_pred\\_sets@{\\ptt load\\_pred\\_sets}|)}\n", "meta": {"hexsha": "24ce155b97e63677a57fd57be92389d27de75ea6", "size": 58238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pred_set/Manual/description.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": "src/pred_set/Manual/description.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": "src/pred_set/Manual/description.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": 40.108815427, "max_line_length": 208, "alphanum_fraction": 0.7089185755, "num_tokens": 18459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6182965530386326}}
{"text": "\\chapter{Algorithms}\r\n\\section {Generators and relations}\r\n{\\bf Notation:} $X$ are the generators, $R$ are the relations.  Each $R \\in R$ is\r\nof the form $u_1 u_2 \\ldots u_k =1$ where each $u_1= x, x^{-1}, x \\in X$.  Write\r\n$G= \\langle X|R \\rangle $ for the generated group.  \r\nIf $H$ is a group and $\\varphi: X \\rightarrow H$,\r\n$\\varphi$ can be extended to an homomorphism between $H$ and $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $F$ is \\emph{free} on $X$ if $i: X \\rightarrow F$ and\r\n$\\forall g: X \\rightarrow G$, $\\exists ! f:F \\rightarrow G$ such that\r\n$i(f(x))=g(x)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} Free groups exist.  Any group is a homomorphic image of a free group.\r\n\\section {Coset enumeration}\r\nLet $G= \\langle g_1 , g_2 , \\ldots , g_m \\rangle $.  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= \\langle (k_i g_j ) {\\overline {(k_i g_j )^{-1}}} \\rangle $\r\nfor $i= 1, 2, 3, \\ldots , s$ and\r\n$j= 1, 2, 3, \\ldots , m$.\r\n\\\\\r\n\\\\\r\n{\\bf Coxeter:}\r\nMaintain 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|$, find cosets of $H<G$ and calculate $|G:H|$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\n${\\cal B}= \\langle \\beta_1 , ... , \\beta_n \\rangle $ 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 \\emph{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 Theorem:}\r\nLet $G$ be a group with $G/Z(G)$ finite, then $G^{(1)}$ is finite.\r\n\\begin{quote}\r\n\\emph{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\\end{quote}\r\n{\\bf Todd Coxeter example:} $G= \\langle x,y| x^3=y^3=(xy)^2=1 \\rangle $.  $H= \\langle x \\rangle $.\r\n\\begin{center}\r\n\\begin{tabular} {|l||r|r|r|r||r|r|r||r|r|r|r|r|}\r\n\\hline\r\nLine & Coset & $x$ & $x$ & $x$ & $y$ & $y$ & $y$ & $x$ & $y$ & $x$ & $y$\\\\\r\n\\hline\r\n1 & $1$ & $1$ & $1$ & $1$ & $2$ & $3$ & $1$ & $1$ & $2$ & $3$ & $1$\\\\\r\n\\hline\r\n2 & $2$ & $3$ & $5$ & $2$ & $3$ & $1$ & $2$ & $3$ & $1$ & $1$ & $2$\\\\\r\n\\hline\r\n3 & $3$ & $5$ & $2$ & $3$ & $1$ & $2$ & $3$ & $5$ & $6$ & $7$ & $3$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nLine 1 coincidence: $1y=2$, $4y=1$, $4=1y^{-1}=3$.\r\nLine 3 coincidence: $7=3y^{-1}=2$, $6=2x^{-1}=5$.\\\\\r\n\\\\\r\nThis yields:\r\n\\begin{center}\r\n\\begin{tabular} {|r||r|r|r|r|}\r\n\\hline\r\nElement & $1$ & $2$ & $3$ & $5$ \\\\\r\n$x$ & $1$ & $3$ & $5$ & $2$\\\\\r\n\\hline\r\n$y$ & $2$ & $3$ & $1$ & $5$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nLine 1 coincidence: $1y=2$, $4y=1$, $4=1y^{-1}=3$.\r\nLine 3 coincidence: $7=3y^{-1}=2$, $6=2x^{-1}=5$.\\\\\r\n", "meta": {"hexsha": "aa3719c0d19a0a7e269c6c19a44565dfd81546ab", "size": 3032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtAlgorithms.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/gtAlgorithms.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/gtAlgorithms.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": 37.4320987654, "max_line_length": 99, "alphanum_fraction": 0.5432058047, "num_tokens": 1289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.6182965517455121}}
{"text": " \\documentclass [12pt]{article} \n\n\\usepackage {amsmath}\n\\usepackage {amsthm}\n\\usepackage {amssymb}\n\\usepackage {graphicx} \n\\usepackage {float}\n\\usepackage {multirow}\n\\usepackage {xcolor}\n\\usepackage {algorithmic}\n\\usepackage [ruled,vlined,commentsnumbered,titlenotnumbered]{algorithm2e} \\usepackage {array} \n\\usepackage {booktabs} \n\\usepackage {url} \n\\usepackage {parskip} \n\\usepackage [margin=1in]{geometry} \n\\usepackage [T1]{fontenc} \n\\usepackage {cmbright} \n\\usepackage [many]{tcolorbox} \n\\usepackage [colorlinks = true,\n            linkcolor = blue,\n            urlcolor  = blue,\n            citecolor = blue,\n            anchorcolor = blue]{hyperref} \n\\usepackage {enumitem} \n\\usepackage {xparse} \n\\usepackage {verbatim}\n\\usepackage{listings}\n\\usepackage{xcolor}\n\\lstset { %\n    language=C++,\n    backgroundcolor=\\color{black!5}, % set backgroundcolor\n    basicstyle=\\footnotesize,% basic font setting\n}\n\n\\DeclareTColorBox {Solution}{}{breakable, title={Solution}} \\DeclareTColorBox {Solution*}{}{breakable, title={Solution (provided)}} \\DeclareTColorBox {Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt} \\DeclareDocumentCommand {\\Expecting }{+m}{\\textbf {[We are expecting:} #1\\textbf {]}} \\DeclareDocumentCommand {\\Points }{m}{\\textbf {(#1 pt.)}} \n\n\\begin {document} \n\n{\\LARGE \\textbf {COMP 285 (NC A\\&T, Spr `22)}\\hfill \\textbf {Lecture 2} } \n\\vspace {1em} \n\\begin {Instruction} \n\nAdapted From Virginia Williams’ lecture notes. Additional credits: J. Su, W. Yang, Gregory Valiant, Mary Wootters, Aviad Rubinstein, Sami Alsheikh.\n\\end {Instruction} \n\n\\begin{centering}\n\\section*{Insertion Sort, Proofs, and Formal Big-Oh}\n\\end{centering}\n\n\n\\section{Introduction}\n\nIn general, when analyzing an algorithm, we want to know two things.\n\n\\begin{enumerate}\n    \\item Does it work?\n    \\item How fast is it?\n\\end{enumerate}\n\nToday, we’ll begin to see how we might formally answer these questions, through the lens\nof sorting. We’ll start with InsertionSort to make sure we focus not on the algorithm itself, but on the newly introduced concepts.\n\n\\section{InsertionSort}\n\nThere are many ways to implement \\texttt{InsertionSort}. You can see several C++ implementations here: \\href{https://www.onlinegdb.com/edit/7iNReAeY-n}{https://www.onlinegdb.com/edit/7iNReAeY-n}. For the purposes of lecture, we'll stick to pseudo-code for now. Here's a possible implementation of \\texttt{InsertionSort}.\n\n\\begin{verbatim}\ndef InsertionSort(A):\n    for i in range(1,len(A)):\n        current = A[i]\n        j = i-1\n        while j >= 0 and A[j] > current:\n            A[j+1] = A[j]\n            j -= 1\n    A[j+1] = current\n\\end{verbatim}\n\nLet's ask our two questions: does this algorithm work, and does it have good performance?\n\n\\subsection{Correctness of InsertionSort}\n\nOnce you figure out what \\texttt{InsertionSort} is doing (see the \\href{https://docs.google.com/presentation/d/1dyxQVgRnZX1C1UMkoxdPFQbItSSKCWpScSNs0tl_pkI/edit?usp=sharing}{slides} for the intuition on this), you may think that it’s ``obviously'' correct. However, if you didn’t know what it was doing and just got the above code, maybe this wouldn’t be so obvious. Additionally, for algorithms that we’ll study in the future, it won’t always be obvious that it works, and so we’ll have to prove it. To warm us up for those proofs, let’s carefully go through a proof of correctness of \\texttt{InsertionSort}.\n\nWe’ll do the proof by maintaining a \\textit{loop invariant}, in this case that after iteration $i$, then $A[:i+1]$ is sorted. This is obviously true when $i=0$ (because the one-element list $A[: 1]$ is definitely sorted) and then we’ll show that for any $i > 0$, if it’s true for $i - 1$, then it’s true for $i$. At the end of the day, we’ll conclude that $A[:n]$ (aka, the whole thing) is sorted and we’ll be done.\n\nFormally, we will proceed by induction.\n\n\\begin{itemize}\n    \\item \\textbf{Inductive hypothesis.} After iteration $i$ of the outer loop, $A[:i+1]$ is sorted.\n    \\item \\textbf{Base case.} When $i = 0$, $A[:1]$ contains only one element, and this is sorted\n    \\item \\textbf{Inductive step.} Suppose that the inductive hypothesis holds for $i - 1$, so $A[:i]$ is sorted after the $i-1$’st iteration. We want to show that $A[:i+1]$ is sorted after the $i$’th iteration.\n    \n    Suppose that $j^*$ is the largest integer in $\\{0, \\dots , i - 1\\}$ so that $A[j^*] < A[i]$. Then the effect of the inner loop is to turn \n    $$\n        [A[0], A[1], \\dots , A[j^*], \\cdots , A[i - 1], A[i]]\n    $$\n    into\n    $$\n        [A[0], A[1], \\dots , A[j^*], A[i], A[j^* + 1], . . . , A[i - 1]].\n    $$\n\n    We claim that this latter list is sorted. This is because $A[i] > A[j^*]$, and by the inductive hypothesis, we have $A[j^*] \\geq A[j]$ for all $j \\leq j^*$, and so $A[i]$ is larger than everything that is positioned before it. Similarly, by the choice of $j^*$ we have $A[i] \\leq A[j^* + 1] \\leq A[j]$ for all $j \\geq j^* + 1$, so $A[i]$ is smaller than everything that comes after it. Thus, $A[i]$ is in the right place. All of the other elements were already in the right place, so this proves the claim.\n\n    Thus, after the $i$’th iteration completes, $A[:i+1]$ is sorted, and this establishes the inductive hypothesis for $i$.\n    \\item \\textbf{Conclusion.} By induction, we conclude that the inductive hypothesis holds for all $i \\leq n - 1$. In particular, this implies that after the end of the $n - 1$’st iteration (after the algorithm ends) $A[:n]$ is sorted. Since $A[:n]$ is the whole list, this means the whose list is sorted when the algorithm terminates, which is what we were trying to show.\n\\end{itemize}\n\nThe above proof was maybe a bit pedantic: we used a lot of words to prove something that may have been pretty obvious. However, it’s important to understand the structure of this argument, because we’ll use it a lot, sometimes for more complicated algorithms.\n\n\n\\subsection{Running time of InsertionSort}\n\nThe running time of \\texttt{InsertionSort} is about $n^2$ operations. To be a bit more precise, at iteration $i$, the algorithm may have to look through and move $i$ elements, so that’s about $\\Sigma_{i=1}^n i = \\frac{n(n+1)}{2}$ operations.\nWe’re not going to stress the precise operation count, because we’ll argue that the end of the lecture that we don’t care too much about it. The main question that we have, is, can we do asymptotically better than $n^2$\n2? That is, can we come up with an algorithm that sorts an arbitrary list of $n$ integers in time that scales less than $n^2$? For example, like $n^{1.5}$, or $n \\log(n)$, or even $n$?\n\nYou should recall from COMP 280 that a much better algorithm exists, which is called \\texttt{MergeSort} and which has running time $O(n \\log(n))$.\n\n\\section{Guiding Principles of Algorithm Design and Analysis}\n\nAfter going through the algorithm and analysis, it is natural to wonder if we’ve been too sloppy. In particular, note that the algorithm never ``looks at'' the input. For instance, what if we received the sequence of numbers $[1, 2, 3, 5, 4, 6, 7, 8]$? Clearly, there is a ``sorting algorithm'' for this sequence that only takes a few operations, but \\texttt{MergeSort} runs through all $\\log n + 1$ levels of recursion anyway. Would it be better to try to design our algorithms with this in mind? Additionally, in our analysis, we’ve given a very loose upper bound on the time required and dropped a number of constant factors and lower order terms. Is this a problem? In what follows, we’ll argue that these are actually features, not bugs, in the design and analysis of the algorithm.\n\n\n\\subsection{Worst-Case Analysis}\n\nOne guiding principle we’ll use throughout the class is that of Worst-Case Analysis. In particular, this means that we want any statement we make about our algorithms to hold for every possible input. Stated differently, we can think about playing a game against an adversary, who wants to maximize our running time (make it as bad as possible). We get to specify an algorithm and state a running time $T(n)$; the adversary then chooses an input. We win the game if even in the worst case, whatever input the adversary chooses (of size $n$), our algorithm runs in at most $T(n)$ time.\n\nNote that because our algorithm made no assumptions about the input, then our running time bound will hold for every possible input. This is a very strong, robust guarantee \\footnote{In the case where you have significant domain knowledge about which inputs are likely, you may choose to design an algorithm that works well in expectation on these inputs (this is frequently referred to as Average-Case Analysis). This type of analysis of ten much more tricky, and requires strong assumptions on the input}. \n\n\\subsection{Asymptotic Analysis}\n\nThroughout our arguments about running time, we combined constants  and gave very loose upper bounds (like being okay with a naive implementation of our pseudocode, or with this very wasteful upper bound 11m on the work done at a subproblem). Why did we choose to do this? First, it makes the math much easier. But does it come at the cost of getting the “right\" answer? Would we get a more predictive result if we threw all these exact expressions back into the analysis? From the perspective of an algorithm designer, the answer is to both of these questions is a resounding ``No''. As an algorithm designer, we want to come up with results that are broadly applicable, whose truth does not depend on features of a specific programming language or machine architecture. The constants that we’ve dropped will depend greatly on the language and machine on which you’re working. For the same reason we use pseudocode instead of writing our algorithms in C++, trying to quantify the exact running time of an algorithm would be inappropriately specific. This is not to say that constant factors never matter in applications (e.g. I would be rather upset if my web browser ran 7 times slower than it does now) but worrying about these factors is not the goal of this class. In this class, our goal will be to argue about which strategies for solving problems are wise and why.\n\nIn particular, we will focus on \\textit{Asymptotic Analysis}. This type of analysis focuses on the running time of your algorithm as your input size gets very large (i.e. $n \\to +\\infty$). This framework is motivated by the fact that if we need to solve a small problem, it doesn’t cost that much to solve it by brute-force. If we want to solve a large problem, we may need to be much more creative in order for the problem to run efficiently. From this perspective, it should be very clear that $11n(\\log n + 1)$ is much better than $n^2/2$. (If you are unconvinced,\ntry plugging in some values for $n$.)\n\nIntuitively, we’ll say that an algorithm is ``fast'' when the running time grows ``slowly'' with the input size. In this class, we want to think of growing “slowly\" as growing as close to linear as possible. Based on this this intuitive notion, we can come up with a formal system for analyzing how quickly the running time of an algorithm grows with its input size.\n\n\\subsection{Asymptotic Notation}\nTo talk about the running time of algorithms, we will use the following notation. $T(n)$ denotes\nthe runtime of an algorithm on input of size $n$.\n\n\\subsubsection{``Big-Oh'' Notation:}\n\nIntuitively, Big-Oh notation gives an upper bound on a function. We say $T(n)$ is $O(f(n))$ when as $n$ gets big, $f (n)$ grows at least as quickly as $T(n)$. Formally, we say\n$$\n T(n) = O(f(n)) \\iff \\exists c, n_0 > 0 \\text{ s.t } \\forall n \\geq n_0, 0 \\leq T(n) \\leq c \\cdot f(n)\n$$\n\n\\subsubsection{``Big-Omega'' Notation:}\n\nIntuitively, Big-Omega notation gives a lower bound on a function. We say $T(n)$ is $\\Omega(f(n))$ when as $n$ gets big, $f (n)$ grows at least as slowly as $T(n)$. Formally, we say\n$$\n T(n) = O(f(n)) \\iff \\exists c, n_0 > 0 \\text{ s.t } \\forall n \\geq n_0, 0 \\leq c \\cdot f(n) \\leq T(n)\n$$\n\n\\subsubsection{``Big-Theta'' Notation:}\n\nIntuitively, Big-Theta notation gives both a lower and upper bound on a function. We say $T(n)$ is $\\Theta(f(n))$ if and only if $T(n) = O(f(n))$ and $T(n) = \\Omega(f(n))$.\n$$\n T(n) = O(f(n)) \\iff \\exists c_1, c_2, n_0 > 0 \\text{ s.t } \\forall n \\geq n_0, 0 \\leq c_1 f(n) \\leq T(n) \\leq c_2 f(n)\n$$\n\nWe will cover each of these definition in more detail next lecture.\n\\end{document}", "meta": {"hexsha": "f745e89532e34f72a3ae05f0e29133c3ddc66cba", "size": 12413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/lectures/lecture2.tex", "max_stars_repo_name": "facebookEIR/algorithms-course", "max_stars_repo_head_hexsha": "f0893b43aaf3b321eb134c82512bd7b9271fdea6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-16T02:47:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T02:47:46.000Z", "max_issues_repo_path": "assets/lectures/lecture2.tex", "max_issues_repo_name": "facebookEIR/algorithms-course", "max_issues_repo_head_hexsha": "f0893b43aaf3b321eb134c82512bd7b9271fdea6", "max_issues_repo_licenses": ["MIT"], "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/lectures/lecture2.tex", "max_forks_repo_name": "facebookEIR/algorithms-course", "max_forks_repo_head_hexsha": "f0893b43aaf3b321eb134c82512bd7b9271fdea6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-01-20T21:52:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-21T03:00:16.000Z", "avg_line_length": 75.2303030303, "max_line_length": 1372, "alphanum_fraction": 0.7255296866, "num_tokens": 3452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.9390248135892422, "lm_q1q2_score": 0.6182703707288292}}
{"text": "\\documentclass[13pt,onlymath]{beamer}\n\\usefonttheme{serif}\n\\usepackage{graphicx,amsmath,amssymb,tikz,psfrag,epstopdf,fancyvrb}\n\\usepackage[lighttt]{lmodern}\n%\\usepackage{graphicx,psfrag}\n\n\\input defs.tex\n\n%% formatting\n\n\\mode<presentation>\n{\n\\usetheme{default}\n}\n\\setbeamertemplate{navigation symbols}{}\n\\usecolortheme[rgb={0.13,0.28,0.59}]{structure}\n\\setbeamertemplate{itemize subitem}{--}\n\\setbeamertemplate{frametitle} {\n    \\begin{center}\n      {\\large\\bf \\insertframetitle}\n    \\end{center}\n}\n\n\\newcommand\\footlineon{\n  \\setbeamertemplate{footline} {\n    \\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,leftskip=.8cm,rightskip=.6cm]{structure}\n      \\footnotesize \\insertsection\n      \\hfill\n      {\\insertframenumber}\n    \\end{beamercolorbox}\n    \\vskip 0.45cm\n  }\n}\n\\footlineon\n\n\\AtBeginSection[] \n{ \n    \\begin{frame}<beamer> \n        \\frametitle{Outline} \n        \\tableofcontents[currentsection,currentsubsection] \n    \\end{frame} \n} \n\n%% begin presentation\n\n\\title{\\large \\bfseries Shortest Path Algorithms}\n\n\\author{Jaehyun Park\\\\[3ex]\nCS 97SI\\\\\nStanford University}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\frame{\n\\thispagestyle{empty}\n\\titlepage\n}\n\n\\section{Cross Product}\n\\begin{frame}{Cross Product}\n\\BIT\n\\item Arguably the most important operation in 2D geometry\n\\item We'll use it all the time\n\\vfill\n\\item Applications:\n\\BIT\n\\item Determining the (signed) area of a triangle\n\\item Testing if three points are collinear\n\\item Determining the orientation of three points\n\\item Testing if two line segments intersect\n\\EIT \\EIT\n\\end{frame}\n\n\\begin{frame}{Cross Product}\nDefine $\\mathrm{ccw}(A, B, C) = (B-A) \\times (C-A) = (b_x-a_x)(c_y-a_y)-(b_y-a_y)(c_x-a_x)$\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/ccw}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Segment-Segment Intersection Test}\n\\BIT\n\\item Given two segments $AB$ and $CD$\n\\item Want to determine if they intersect properly: two segments meet at a single point that are strictly inside both segments\n\\EIT\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{figures/seg_intersection}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Segment-Segment Intersection Test}\n\\BIT\n\\item Assume that the segments intersect\n\\BIT\n\\item From $A$'s point of view, looking straight to $B$, $C$ and $D$ must lie on different sides\n\\item Holds true for the other segment as well\n\\EIT\n\\item The intersection exists and is proper if:\n\\BIT\n\\item $\\mathrm{ccw}(A, B, C) \\times \\mathrm{ccw}(A, B, D) < 0$\n\\item \\emph{and} $\\mathrm{ccw}(C, D, A) \\times \\mathrm{ccw}(C, D, B) < 0$\n\\EIT\\EIT\n\\end{frame}\n\n\\begin{frame}{Non-proper Intersections}\n\\BIT\n\\item We need more special cases to consider!\n\\item \\eg, If $\\mathrm{ccw}(A, B, C)$, $\\mathrm{ccw}(A, B, D)$, $\\mathrm{ccw}(C, D, A)$, $\\mathrm{ccw}(C, D, B)$ are all zeros, then two segments are collinear\n\\item Very careful implementation is required\n\\EIT\n\\end{frame}\n\n\\section{Convex Hull Problem}\n\n\\begin{frame}{Convex Hull Problem}\n\\BIT\n\\item Given $n$ points on the plane, find the smallest convex polygon that contains all the given points\n\\BIT\n\\item For simplicity, assume that no three points are collinear\n\\EIT\\EIT\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/convhull}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Simple Algorithm}\n\\BIT\n\\item $AB$ is an edge of the convex hull iff $\\mathrm{ccw}(A, B, C)$ have the same sign for all other points $C$\n\\BIT\n\\item This gives us a simple algorithm\n\\EIT\n\\vfill\n\\item For each $A$ and $B$:\n\\BIT\n\\item If $\\mathrm{ccw}(A, B, C) > 0$ for all $C \\ne A, B$:\n\\BIT\n\\item Record the edge $A \\rightarrow B$\n\\EIT\\EIT\n\\item Walk along the recorded edges to recover the convex hull\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Faster Algorithm: Graham Scan}\n\\BIT\n\\item We know that the leftmost given point has to be in the convex hull\n\\BIT\n\\item We assume that there is a unique leftmost point\n\\EIT\n\\item Make the leftmost point the origin\n\\BIT\n\\item So that all other points have positive $x$ coordinates\n\\EIT\n\\item Sort the points in increasing order of $y/x$\n\\BIT\n\\item Increasing order of angle, whatever you like to call it\n\\EIT\n\\item Incrementally construct the convex hull using a stack\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Incremental Construction}\n\\BIT\n\\item We maintain a \\emph{convex chain} of the given points\n\\item For each $i$, do the following:\n\\BIT\n\\item Append point $i$ to the current chain\n\\item If the new point causes a concave corner, remove the bad vertex from the chain that causes it\n\\item Repeat until the new chain becomes convex\n\\EIT\\EIT\n\\end{frame}\n\n\\begin{frame}{Example}\nPoints are numbered in increasing order of $y/x$\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham1}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nAdd the first two points in the chain\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham2}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nAdding point 3 causes a concave corner 1-2-3: remove 2\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham3}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nThat's better...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham4}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nAdding point 4 to the chain causes a problem: remove 3\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham5}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham6}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham7}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham8}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nBad corner!\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham9}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nBad corner again!\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham10}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham11}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham12}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nContinue adding points...\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham13}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\nDone!\n\\begin{center}\n\\includegraphics[height=0.5\\textheight]{figures/graham14}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Pseudocode}\n\\BIT\n\\item Set the leftmost point as $(0, 0)$, and sort the rest of the points in increasing order of $y/x$\n\\item Initialize stack $S$\n\\item For $i=1, \\ldots, n$:\n\\BIT\n\\item Let $A$ be the second topmost element of $S$, $B$ be the topmost element of $S$, and $C$ be the $i$th point\n\\item If $\\mathrm{ccw}(A, B, C) < 0$, pop $S$ and go back\n\\item Push $C$ to $S$\n\\EIT\n\\item Points in $S$ form the convex hull\n\\EIT\n\\end{frame}\n\n\\section{Sweep Line Algorithm}\n\n\\begin{frame}{Sweep Line Algorithm}\n\\BIT\n\\item A problem solving strategy for geometry problems\n\\item The main idea is to maintain a line (with some auxiliary data structure) that sweeps through the entire plane and solve the problem locally\n\\item We can't simulate a continuous process, (e.g. sweeping a line) so we define events that causes certain changes in our data structure\n\\BIT\n\\item And process the events in the order of occurrence\n\\EIT\n\\item We'll cover one sweep line algorithm\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Sweep Line Algorithm}\n\\BIT\n\\item Problem: Given $n$ axis-aligned rectangles, find the area of the union of them\n\\item We will sweep the plane from left to right\n\\item Events: left and right edges of the rectangles\n\\item The main idea is to maintain the set of ``active'' rectangles in order\n\\BIT\n\\item It suffices to store the $y$-coordinates of the rectangles\n\\EIT \\EIT\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep1}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep2}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep3}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep4}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep5}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep6}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep7}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep8}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep9}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep10}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example}\n\\begin{center}\n\\includegraphics[height=0.6\\textheight]{figures/sweep11}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Pseudo-pseudocode}\n\\BIT\n\\item If the sweep line hits the left edge of a rectangle\n\\BIT\n\\item Insert it to the data structure\n\\EIT\n\\item Right edge?\n\\BIT\n\\item Remove it\n\\EIT\n\\item Move to the next event, and add the area(s) of the green rectangle(s)\n\\BIT\n\\item Finding the length of the union of the blue segments is the hardest step\n\\item There is an easy $O(n)$ method for this step\n\\EIT\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Notes on Sweep Line Algorithms}\n\\BIT\n\\item Sweep line algorithm is a generic concept\n\\BIT\n\\item Come up with the right set of events and data structures for each problem\n\\EIT\n\\item Exercise problems\n\\BIT\n\\item Finding the perimeter of the union of rectangles\n\\item Finding all $k$ intersections of $n$ line segments in $O((n+k) \\log n)$ time\n\\EIT\\EIT\n\\end{frame}\n\n\\section{Intersecting Half-planes}\n\n\\begin{frame}{Intersecting Half-planes}\n\\BIT\n\\item Representing a half-plane: $ax+by+c \\le 0$\n\\item The intersection of half-planes is a convex area\n\\BIT\n\\item If the intersection is bounded, it gives a convex polygon\n\\EIT\n\\item Given $n$ half-planes, how do we compute the intersection of them?\n\\BIT\n\\item \\ie, Find vertices of the convex area\n\\EIT\n\\item There is an easy $O(n^3)$ algorithm and a hard $O(n \\log n)$ one\n\\BIT\n\\item We will cover the easy one\n\\EIT\\EIT\n\\end{frame}\n\n\\begin{frame}{Intersecting Half-planes}\n\\BIT\n\\item For each half-plane $a_ix + b_iy + c_i \\le 0$, define a straight line $e_i: a_ix + b_iy + c_i = 0$\n\\item For each pair of $e_i$ and $e_j$:\n\\BIT\n\\item Compute their intersection $p=(p_x, p_y)$\n\\item Check if $a_k p_x + b_k p_y + c_k \\le 0$ for all half-planes\n\\BIT\n\\item If so, store $p$ in some array $P$\n\\item Otherwise, discard $p$\n\\EIT\\EIT\n\\item Find the convex hull of the points in $P$\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Intersecting Half-planes}\n\\BIT\n\\item The intersection of half-planes can be unbounded\n\\BIT\n\\item But usually, we are given limits on the min/max values of the coordinates\n\\item Add four half-planes $x \\ge -M$, $x \\le M$, $y \\ge -M$, $y \\le M$ (for large $M$) to ensure that the intersection is bounded\n\\EIT\n\\item Time complexity: $O(n^3)$\n\\BIT\n\\item Pretty slow, but easy to code\n\\EIT\\EIT\n\\end{frame}\n\n\\section{Notes on Binary/Ternary Search}\n\n\\begin{frame}{Notes on Binary Search}\n\\BIT\n\\item Usually, binary search is used to find an item ofi rulnterest in a sorted array\n\\vfill\n\\item There is a nice application of binary search, often used in geometry problems\n\\BIT\n\\item Example: finding the largest circle that fits into a given polygon\n\\BIT\n\\item Don't try to find a closed form solution or anything like that!\n\\item Instead, binary search on the answer\n\\EIT\\EIT\n\\EIT\n\\end{frame}\n\n\\begin{frame}{Ternary Search}\n\\BIT\n\\item Another useful method in many geometry problems\n\\item Finds the minimum point of a ``convex'' function $f$\n\\BIT\n\\item Not exactly convex, but let's use this word anyway\n\\EIT\n\\item Initialize the search interval $[s, e]$\n\\item Until $e-s$ becomes ``small enough'':\n\\BIT\n\\item $m_1 := s+(e-s)/3$, $m_2 := e - (e-s)/3$\n\\item If $f(m_1) \\le f(m_2)$, set $e := m_2$\n\\item Otherwise, set $s := m_1$\n\\EIT\\EIT\n\\end{frame}\n\n\\end{document}\n", "meta": {"hexsha": "5cecd5da4c25faf85e19fc2bff340aa47fe315e6", "size": 12481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "collection/cp/stanfordacm-master/97si_slides/comp_geometry.tex", "max_stars_repo_name": "daemonslayer/Notebook", "max_stars_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-24T13:12:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-24T13:12:01.000Z", "max_issues_repo_path": "collection/cp/stanfordacm-master/97si_slides/comp_geometry.tex", "max_issues_repo_name": "daemonslayer/Notebook", "max_issues_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "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": "collection/cp/stanfordacm-master/97si_slides/comp_geometry.tex", "max_forks_repo_name": "daemonslayer/Notebook", "max_forks_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "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.5758196721, "max_line_length": 159, "alphanum_fraction": 0.7380818845, "num_tokens": 3938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6182622187808828}}
{"text": "In the original release of the \\mf Drain (DRN) Package a drain is designed to simulate the effects of agricultural drains, springs, and other features that remove water from the aquifer at a rate proportional to the difference between the head in the aquifer and some fixed head or elevation, called the drain elevation, so long as the head in the aquifer is above that elevation. If, however, the aquifer head falls below the drain elevation, then the drain has no effect on the aquifer. The constant of proportionality is called the drain conductance.  This chapter describes a new feature of the \\mf DRN Package that allows the drain conductance to gradually increase from zero to the user-specified value as a function of the simulated groundwater head.\n\n\\subsection{Theory}\n\nThe standard drain equation in \\mf is\n\n\\begin{align}\n\t\\label{eqn:bcdrnqout}\n    \t\\mli{Qout}_{nb} = \\begin{dcases} \n    \t\t0 &h_{n} \\le \\mli{HDRN}_{nb} \\\\\n    \t\t\\mli{CDRN}_{nb} \\left( h_{n} - \\mli{HDRN}_{nb} \\right) &h_{n} > \\mli{HDRN}_{nb}\n\t\\end{dcases} ,\n\\end{align}\n\n\\noindent where $\\mli{Qout}_{nb}$ is the flow from the aquifer to drain $nb$ (\\ulct), $\\mli{CDRN}_{nb}$ is the drain conductance (\\ulst), $\\mli{HDRN}_{nb}$ is the drain elevation (\\ul), and $h_{n}$ is the head in the cell containing the drain (\\ul). Equation~\\ref{eqn:bcdrnqout} rewritten in terms of flow from the drain into aquifer (\\ulct), $\\mli{QDRN}$, is\n\n\\begin{align}\n\t\\label{eqn:bcdrnqdrn}\n    \t\\mli{QDRN}_{nb} = \\begin{dcases} \n    \t\t\\mli{CDRN}_{nb} \\left( \\mli{HDRN}_{nb} - h_{n} \\right) &h_{n} > \\mli{HDRN}_{nb} \\\\\n    \t\t0 &h_{n} \\le \\mli{HDRN}_{nb}\n\t\\end{dcases} .\n\\end{align}\n\nThe standard DRN Package has been modified to include the option to scale the drain conductance using either linear or cubic scaling. The modified form of the drain equation (eq.~\\ref{eqn:bcdrnqdrn}) with linear scaling is\n\n\\begin{equation}\n\t\\label{eqn:bcdrnqoutalt0}\n\t\\mli{QDRN}_{nb} = F_{\\mli{DRN}_{nb}} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) ,\n\\end{equation}\n\n\\noindent where $\\mli{ZDRN}_{nb}$ is the elevation at which drainage discharge begins (\\ul), and $F_{\\mli{DRN}_{nb}}$ is the linear scaling function (unitless), which accounts for how the conductance of the drain changes with changes in head. Conceptually, the drain conductance changes because the area through which flow occurs depends on the head. The area through which flow occurs increases as the head at the drain increases. The linear scaling function is defined as\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\label{eqn:bcdrnFC}\n\t\tF_{\\mli{DRN}_{nb}} = \\begin{dcases} \n\t\t\t0 &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t\\Delta h_{n,nb}^{r}  &0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t1 &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent where $\\mli{DDRN}_{nb}$ is the drainage depth (\\ul) and the relative drain head difference (\\ul) is defined as\n\n\\begin{equation}\n\t\\label{eqn:reldrainheaddiff}\n\t\\Delta h_{n,nb}^{r} \\equiv \\frac{h_n - \\mli{ZDRN}_{nb}}{\\left| \\mli{DDRN}_{nb} \\right|} .\n\\end{equation}\n\n\\noindent The elevation at which drainage begins, $\\mli{ZDRN}_{nb}$ depends on whether the drainage depth, $\\mli{DDRN}_{nb}$, is positive or negative and is calculated as\n\n\\begin{align}\n\t\\label{eqn:bcdrnZDRN}\n\t\\mli{ZDRN}_{nb} = \\begin{dcases}\n\t\t\\mli{HDRN}_{nb} - \\left| \\mli{DDRN}_{nb} \\right| &\\mli{DDRN}_{nb} < 0, \\\\\n\t\t\\mli{HDRN}_{nb} &\\mli{DDRN}_{nb} \\ge 0\n    \t\\end{dcases} .\n\\end{align}\n\n\\noindent If $\\mli{DDRN}_{nb}$ is positive, $\\mli{ZDRN}_{nb}$ is the drain elevation just as it is in the standard formulation. If $\\mli{DDRN}_{nb}$ is negative, $\\mli{ZDRN}_{nb}$ is the drain elevation plus the (negative) drainage depth. If $\\mli{DDRN}_{nb}$ is zero, the standard formulation is used. The linear scaling function ($F_{\\mli{DRN}_{nb}}$) is shown in figure~\\ref{fig:drndischscalef}.\n\n\\begin{figure}[!ht]\n\t\\begin{center}\n\t\\includegraphics{./Figures/DischargeScaleFactor.pdf}\n\t\\caption[Graphs showing combined linear and cubic scaling functions for drain discharge and the derivatives of the linear and cubic scaling fraction functions]{Graphs showing combined linear and cubic scaling functions for drain discharge and the derivatives of the linear and cubic scaling fraction functions. \\textit{A}, linear and cubic fraction functions and \\textit{B}, derivatives of the linear and cubic scaling functions with respect to the relative drain head difference $\\left( \\frac{h - \\mli{ZDRN}}{\\left| \\mli{DDRN} \\right|} \\right)$. The derivative of the linear and cubic scaling functions with respect to $h$ is the product of the derivative with respect to $\\frac{h - \\mli{ZDRN}}{\\left| \\mli{DDRN} \\right|}$ and $\\frac{1}{\\mli{DDRN}}$}\n\t\\label{fig:drndischscalef}\n\t\\end{center}\n\\end{figure}\n\nThe linear scaling function varies with head according to equations~\\ref{eqn:bcdrnFC} and~\\ref{eqn:reldrainheaddiff}. Differentiation of equation~\\ref{eqn:bcdrnFC} with respect to $h_n$, with application of the chain rule to account for the variation of $ \\Delta h_{n,nb}^{r}$ with respect to $h_n$ in equation~\\ref{eqn:reldrainheaddiff}, gives\n\n\\begin{equation}\n\t\\label{eqn:bcdrndFC}\n\t\\begin{aligned}\n\t\t\\frac{\\partial F_{\\mli{DRN}_{nb}}}{\\partial h_n} = \\begin{dcases} \n\t\t\t0 &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t\\frac{1}{\\left| \\mli{DDRN}_{nb} \\right|}  &0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t1 &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent which is discontinuous in the neighborhood of $h_n = \\mli{ZDRN}_{nb}$ and $h_n = \\mli{ZDRN}_{nb} - \\left| \\mli{DDRN}_{nb} \\right| $. The derivative of the linear scaled drain discharge (eq.~\\ref{eqn:bcdrnqoutalt0}) with respect to $h_n$ is\n\n\\begin{equation}\n\t\\label{eqn:bcdrnNRlindqoutalt0}\n\t\\frac{\\partial \\mli{QDRN}_{nb}}{\\partial h_n} = -F_{\\mli{DRN}_{nb}} \\mli{CDRN}_{nb}  + \\frac{\\partial F_{\\mli{DRN}_{nb}}}{\\partial h_n} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) .\n\\end{equation}\n\n\\noindent Substitution of equations ~\\ref{eqn:bcdrnFC} and~\\ref{eqn:bcdrndFC} into equation~\\ref{eqn:bcdrnNRlindqoutalt0} results in\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\label{eqn:bcdrnNRlindQdh}\n\t\t\\frac{\\partial \\mli{QDRN}_{nb}}{\\partial h_n} = \\begin{dcases} \n\t\t\t0 &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t- 2\\, \\mli{CDRN}_{nb} \\, \\Delta h_{n,nb}^{r}  &0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t-\\mli{CDRN}_{nb} &\\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent which remains discontinuous in the vicinity of $\\mli{ZDRN}_{nb}$.\n\nWhen the Newton-Raphson formulation is used, discontinuous derivatives can cause non-convergence in the neighborhood of the discontinuity \\citep{doi:10.1029/2006WR005195}. To ensure continuous drain discharge derivatives when the Newton-Raphson formulation is used, cubic smoothing of the linear relative drain head difference is used and equation~\\ref{eqn:bcdrnqoutalt0} is modified to\n\n\\begin{equation}\n\t\\label{eqn:bcdrnNRqoutalt0}\n\t\\mli{QDRN}_{nb}^* = F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) ,\n\\end{equation}\n\n\\noindent where where $F_{\\mli{DRN}_{nb}}^*$ is the cubic scaling function. The cubic scaling function is defined as\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\label{eqn:bcdrnFCC}\n\t\tF_{\\mli{DRN}_{nb}}^* = \\begin{dcases} \n\t\t\t0 & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t- \\left( \\Delta h_{n,nb}^{r} \\right)^3  + 2 \\left( \\Delta h_{n,nb}^{r} \\right)^2  & 0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t1 & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent which is continuous in the vicinity of $h_n = \\mli{ZDRN}_{nb}$ and $h_n = \\mli{ZDRN}_{nb} - \\left| \\mli{DDRN}_{nb} \\right| $ (fig.~\\ref{fig:drndischscalef}\\textit{A}). The derivative of equation~\\ref{eqn:bcdrnFCC} with respect to $h_n$ is\n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\label{eqn:bcdrndFCC}\n\t\t\\frac{\\partial F_{\\mli{DRN}_{nb}}^*}{\\partial h_n} = \\begin{dcases} \n\t\t\t0 & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t-\\frac{3}{\\left| \\mli{DDRN}_{nb} \\right|} \\left( \\Delta h_{n,nb}^{r} \\right)^2  + \\\\\n\t\t\t\\phantom{-}\\frac{4}{\\left| \\mli{DDRN}_{nb} \\right|} \\, \\Delta h_{n,nb}^{r} & 0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t0 & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent which is discontinuous in the vicinity of $h_n = \\mli{ZDRN}_{nb} - \\left| \\mli{DDRN}_{nb} \\right| $ (fig.~\\ref{fig:drndischscalef}\\textit{B}). The derivative of the cubic scaled drain discharge (eq.~\\ref{eqn:bcdrnNRqoutalt0}) with respect to $h$ is\n\n\\begin{equation}\n\t\\label{eqn:bcdrnNRdqoutalt0}\n\t\\frac{\\partial \\mli{QDRN}_{nb}^*}{\\partial h} = -F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb}  + \\frac{\\partial F_{\\mli{DRN}_{nb}}^*}{\\partial h} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) .\n\\end{equation}\n\n\\noindent Substitution of equations~\\ref{eqn:bcdrnFCC} and~\\ref{eqn:bcdrndFCC} into equation~\\ref{eqn:bcdrnNRdqoutalt0} results in \n\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\label{eqn:bcdrndQdh}\n\t\t\\frac{\\partial \\mli{QDRN}_{nb}^*}{\\partial h_n} = \\begin{dcases} \n\t\t\t0 & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\le 0 \\\\\n\t\t\t-\\mli{CDRN}_{nb} \\Biggl[ - \\left( \\Delta h_{n,nb}^{r} \\right)^3  + 2 \\left( \\Delta h_{n,nb}^{r} \\right)^2 \\Biggr] + \\\\\n\t\t\t\\phantom{-} \\mli{CDRN}_{nb} \\Biggl[- \\frac{3}{\\mli{DDRN}_{nb}} \\left( \\Delta h_{n,nb}^{r} \\right)^2  + \\Biggr. \\\\\n\t\t\t\\Biggl. \\phantom{-\\mli{CDRN}_{nb} \\Biggl[- } \\frac{4}{\\mli{DDRN}_{nb}} \\left( \\Delta h_{n,nb}^{r} \\right) \\Biggr] \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) & 0 < \\Delta h_{n,nb}^{r} < 1 \\\\\n\t\t\t-\\mli{CDRN}_{nb} & \\phantom{0 <} \\Delta h_{n,nb}^{r} \\ge 1\n\t\t\\end{dcases} ,\n\t\\end{aligned}\n\\end{equation}\n\n\\noindent which is continuous in the vicinity of $h_n = \\mli{ZDRN}_{nb}$ and $h_n = \\mli{ZDRN}_{nb} - \\left| \\mli{DDRN}_{nb} \\right| $.\n\n\\subsection{Example Drain Discharge Scaling Calculations}\n\nAn example of the differences between the standard, linearly-scaled, and cubicly-scaled drainage discharge are shown in figure~\\ref{fig:drndischdiff}. In this example the elevation that drainage discharge starts ($\\mli{ZDRN}$) is set at $\\frac{\\mli{DDRN}}{2}$ below land surface elevation and drainage discharge is equal for all approaches at $\\mli{ZDRN} + \\mli{DDRN}$ (fig.~\\ref{fig:drndischdiff}\\textit{A}). In this conceptual problem, the groundwater head linearly increases from a value less than $\\mli{ZDRN}$ to greater than $\\mli{ZDRN + DDN}$ during the simulation, which is presented as the head difference ($h - \\mli{ZDRN}$) divided by the drainage depth in figure~\\ref{fig:drndischdiff}\\textit{B}. The drainage discharge that results from the linear increase in groundwater head using the original-, linear-, and cubic-scaling increases with time as is shown in figure~\\ref{fig:drndischdiff}\\textit{C} and shows the continuous nature of the linear- and cubic scaled drainage discharge and that all three approaches result in the same drain discharge rate when the relative drain head difference is greater than or equal to one. Figure~\\ref{fig:drndischdiff}\\textit{D} shows that the cumulative drain discharge for the original drain formulation is 170 to 200 $L^3$ greater than the cubic- and linear-scaled drainage discharge, respectively.\n\n\\begin{figure}[!ht]\n\t\\begin{center}\n\t\\includegraphics{./Figures/DRNDischargeDifferences.pdf}\n\t\\caption[Graphs showing a conceptual model cell using scaled drain discharge and the relation between the groundwater level and drain discharge]{Graphs showing a conceptual model cell using scaled drain discharge and the relation between the groundwater level and drain discharge. \\textit{A}, Conceptual model cell containing a drain cell where drainage discharge starts $\\frac{\\mli{DDRN}}{2}$ below land surface and is equal $\\frac{\\mli{DDRN}}{2}$ above land surface for all drain scaling approaches, \\textit{B}, conceptual linear groundwater level increases, which are presented as a relative drain head difference, with fractional simulation time, \\textit{C}, calculated original, linear, and cubic scaled drainage discharge rates resulting from conceptual groundwater level increases, and \\textit{D}, calculated original, linear, and cubic scaled drainage cumulative discharge resulting from conceptual groundwater level increases}\n\t\\label{fig:drndischdiff}\n\t\\end{center}\n\\end{figure}\n\n\\subsection{Incorporation of the modified Drain (DRN) Package into the CVFD Groundwater Flow Equation}\n\nTo prepare the CVFD equation for solution using the standard formulation, it is convenient to rearrange the discretized groundwater flow equation for a cell so that all terms containing heads at the end of the current time step are grouped on the left-hand side of the equation, and all terms that are independent of head at the end of the current time step are on the right-hand side of equation 6--1 in \\cite{modflow6gwf}. Refer to \\cite{modflow6gwf} for additional information on how the groundwater flow equation is formulated in \\mf. \n\n\\subsubsection{Standard Formulation}\n\nAccording to the sign convention in \\mf, $\\mli{QDRN}_{nb}$ in the groundwater flow equation is defined as a head-dependent flow out of cell $n$, and corresponding terms must be added to the left and right sides of equation~6--1 in \\cite{modflow6gwf} for each cell containing a drain. This is accomplished in the modified Drain Package by adding the head-dependent term and the known term in equation~\\ref{eqn:bcdrnqoutalt0} to the left- and right-side of equation~6--1 in \\cite{modflow6gwf}. The contribution of the modified drain equations to the left-hand side and right-hand sides of the groundwater flow equation are\n\n\\begin{equation}\n\t\\label{eqn:qdrnstd}\n\t\\begin{aligned}\n\t\tA_{n,n} &\\leftarrow A_{n,n} - F_{\\mli{DRN}_{nb}} \\mli{CDRN}_{nb}   \\\\\n\t\tb_n &\\leftarrow b_n - F_{\\mli{DRN}_{nb}} \\mli{CDRN}_{nb} ZDRN_{nb} ,\n\t\\end{aligned}\n\\end{equation} \n\n\\noindent where $A_{n,n}$ is the diagonal of the coefficient matrix for cell $n$ and $b_n$ is the right-hand side of the groundwater flow equation for cell $n$. In the case where drainage discharge is not scaled, $F_{\\mli{DRN}_{nb}}$ is zero when $h_n$ is less than or equal to $HDRN_{nb}$ and one when $h_n$ is greater than $HDRN_{nb}$, which results in identical behavior as the original drain package formulation.\n\n\n\\subsubsection{Newton-Raphson Formulation}\n\nThe modified Newton-Raphson form of equation~\\ref{eqn:bcdrnNRqoutalt0} solved in terms of $h$ instead of $\\Delta h$  and incorporated into the Newton-Raphson form of the groundwater flow equation \\citep[eq. 2--26]{modflow6gwf} is\n\n\\begin{equation}\n\t\\label{eqn:nrQout}\n\t\\frac{\\partial \\mli{QDRN}_{nb}^*}{\\partial h_n}  h^k_n  = - \\mli{QDRN}_{nb}^* + \n\t\\frac{\\partial \\mli{QDRN}_{nb}^*}{\\partial h_n}  h^{k-1}_n,\n\\end{equation} \n\n\\noindent where $h^k_n$ is the head at the end of the current non-linear (picard) iteration and $h^{k-1}_n$ is the head at the start of the current non-linear iteration. Substitution of equations~\\ref{eqn:bcdrnNRqoutalt0} and~\\ref{eqn:bcdrnNRdqoutalt0} into equation~\\ref{eqn:nrQout} results in\n\n\\begin{equation}\n\t\\label{eqn:nrQout01}\n\t\\begin{aligned}\n\t\tA_{n,n} \\leftarrow & A_{n,n} - F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb}  + \\frac{\\partial F_{\\mli{DRN}_{nb}}^*}{\\partial h} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) \\\\\n\t\tb_n \\leftarrow & b_n - F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n}^{k-1} \\right) \\\\\n\t\t& \\phantom{b_n} + \\Biggl[ -F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb} + \\frac{\\partial F_{\\mli{DRN}_{nb}}^*}{\\partial h} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n} \\right) \\Biggr] h^{k-1}_n .\n\t\\end{aligned} \n\\end{equation}\n\n\\noindent Simplifying the right-hand side contribution in equation~\\ref{eqn:nrQout01} results in\n\n\\begin{equation}\n\t\\label{eqn:nrQout02}\n\tb_n \\leftarrow b_n - F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb} \\mli{ZDRN}_{nb} + \\Biggl[ \\frac{\\partial F_{\\mli{DRN}_{nb}}^*}{\\partial h} \\mli{CDRN}_{nb} \\left( \\mli{ZDRN}_{nb} - h_{n}  \\right) \\Biggr] h^{k-1}_n .\n\\end{equation}\n\n\\noindent The $F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb}$ term in equation~\\ref{eqn:nrQout01} and the $F_{\\mli{DRN}_{nb}}^* \\mli{CDRN}_{nb} \\mli{ZDRN}_{nb}$ term in equation~\\ref{eqn:nrQout02} are subtracted from the diagonal of the coefficient matrix and the right-hand side of the groundwater-flow equation, respectively, during the standard formulation step for the drain package. The Newton-Raphson formulation for the modified drain package is completed by augmenting the coefficient matrix with the derivative term in equation~\\ref{eqn:nrQout01} and adding the second term in equation~\\ref{eqn:nrQout02} (the product of a derivative term and the head at the start of the current iteration) to the right-hand side of the groundwater-flow equation. \n\n\\subsection{Use of Drain Discharge Scaling}\n\nA few examples of how the modified drain package can be used to simulate drainage discharge consistent with other \\mf packages are given below.\n\n\\paragraph{The original drain package formulation with a specified drainage depth value}\n\nSpecifying $\\mli{DDRN}$ to be 0 results in a drain that behaves the same as the original DRN Package (eq.~\\ref{eqn:bcdrnqout}). Using a combination of $\\mli{DDRN}$ values set to zero and non-zero values will result in drains with 0 values behaving like the original drain package and others using the scaled drainage discharge approach.\n\n\\paragraph{Groundwater seepage from the Unsaturated Zone Flow Package}\n\nThe drain package can be used as an alternative to the groundwater seepage option in the Unsaturated Zone Flow (UZF) Package. Specifying a positive $\\mli{DDRN}$ value and $\\mli{HDRN}_{nb}$ to be $\\frac{\\mli{DDRN}}{2}$ below the single values specified with the standard DRN Package approach (for example, setting $\\mli{DDRN}$ to be at land surface) results in a formulation that is equivalent to the groundwater seepage option available in the UZF Package in \\mf \\citep{modflow6gwf}. To be consistent with the UZF package, the drain conductance should be calculated as\n\n\\begin{equation}\n\t\\label{eqn:uzfcond}\n\t\\mli{CDRN}_{nb} = \\frac{K_{v_{nb}} A_n}{\\mli{DDRN}_{nb}} ,\n\\end{equation}\n\n\\noindent where $K_{v_{nb}}$ is vertical hydraulic conductivity (\\ult) and $A_n$ is the horizontal area of cell $n$ (\\uls).\n", "meta": {"hexsha": "e3a32a0c35bc4277f3a1f6c032a1913cea88da6d", "size": 18186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SuppTechInfo/drain-discharge-scaling.tex", "max_stars_repo_name": "kzeiler/modflow6", "max_stars_repo_head_hexsha": "a185d95b91985e965f8a04ae353305dff19b9637", "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/SuppTechInfo/drain-discharge-scaling.tex", "max_issues_repo_name": "kzeiler/modflow6", "max_issues_repo_head_hexsha": "a185d95b91985e965f8a04ae353305dff19b9637", "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/SuppTechInfo/drain-discharge-scaling.tex", "max_forks_repo_name": "kzeiler/modflow6", "max_forks_repo_head_hexsha": "a185d95b91985e965f8a04ae353305dff19b9637", "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": 74.5327868852, "max_line_length": 1349, "alphanum_fraction": 0.7167051578, "num_tokens": 6207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867681382279, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6182622039067238}}
{"text": "\\providecommand{\\main}{..}\n\\documentclass[\\main/main.tex]{subfiles}\n\\begin{document}\n\n\\chapter{The classifier}\n\n\\section{Training the classifier}\n\n\\subsection{Convert documents to vector representation}\nGiven a set of training class-labeled elements \\(T\\), we convert the documents, treated as \\textit{bag of elements}, to enumeration-sorted frequency vectors: the most common words in the language are dropped before elaborating the documents.\n\nGiven a document composed of \\(n=\\#d\\) elements \\(d = \\crl{e_1, e_2, \\ldots, e_n}\\), first we define \\(d_\\neq \\subseteq d\\) as the set of distinct elements in \\(d\\). Then, we map to every distinct element its normalized cardinality in the set \\(d\\):\n\\[\n\tz(e_i) = \\frac{\\arity{e_j \\in d: e_j=e_i}}{n}\n\\]\nThen, we proceed to map to a common enumeration the elements, using as full-set of elements the entire training set elements, so that \\(\\forall e_i, e_j \\in T, \\exists! i, j \\in \\N: i=j \\Leftrightarrow e_i=e_j \\).\n\n\\subsection{Choosing representative points}\nGiven an arbitrary percentage of points \\(p \\in \\sqr{0,1}\\) and an arbitrary distance in percentage \\(\\alpha \\in \\sqr{0,1}\\), for each class of points \\(C_j \\in T\\) we choose using \\(k\\)-Means:\n\\[\n\tk=\\ceil{\\#C_j\\cdot p^2}\n\\]\nThis way the centroids surely distribute among the different points, following their density. If the points are, in truth, a unique cluster, the centroids will distribute themselves in an uniform fashion.\n\nThen, we select the most distant points in every cluster in a number equal to \\(\\floor{\\arity{p \\in C_j: p \\in Q_i}\\cdot p}\\). We move each point \\(p\\) of an amount proportional to the distance from the point to its centroid \\(c_i\\):\\(\\alpha \\cdot L^2\\rnd{p, c_i}\\) towards its centroid.\n\n\\subsubsection{Using a metric to choose k}\nFor the high dimensionality and number of the vectors, iterating multiple times \\textit{KMeans} searching for an optimal \\(k\\) following any given metric has an high time cost. For this reason, an attempt using \\textbf{PCA} to reduce the dimensionality and predict the number of clusters in high dimensionality space using a density metric was made.\n\n\\paragraph*{The density was defined as follows:}\n\\[\n\t\\bar{\\rho}_{jk} = \\frac{1}{k} \\sum_{i=1}^k \\rho_{{jk}_i} = \\frac{1}{k} \\sum_{i=1}^k \\rnd{\\frac{\\arity{\\bmv \\in C_{r_j}:\\bmv \\in Q_i}}{\\#C_{r_j}}}^k \\cdot \\frac{1}{r_{Q_i}^2} \\qquad r_{Q_i}^2 = \\begin{cases}\n\t\t\\frac{1}{n} \\sum_{h=1}^{n} {(\\bmc_i - \\bmp_h)}^2 & \\text{if \\(n \\neq 0\\)} \\\\\n\t\t1                                                & \\text{else}\n\t\\end{cases}\n\\]\nWhere \\(r_{Q_i}\\) is the approximated radius of the cluster \\(Qk_i\\), using the farthest \\(n\\) frontier points \\(p_f\\).\n\n\\paragraph*{Does the prediction hold?}\nWhile the metric on two dimensions reduction seemed to work, when iterated on increasingly larger number of dimensions, with the exception of strongly clustered data, it did not much better than a random selection.\n\nAs follows, with 2D PCA density metrics the heuristic seems to be successful to identify the number of clusters \\(k\\) necessary to describe the given classes.\n\\begin{figure}\n\t\\begin{subfigure}{0.24\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{multi-cluster}\n\t\t\\caption{Data with multi-clusters, 2D PCA, \\(k=6\\)}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}{0.24\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{multi-cluster-pca-score}\n\t\t\\caption{Density for data multi-clusters, 2D PCA, density/k}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}{0.24\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{one-cluster}\n\t\t\\caption{Data with single-cluster, 2D PCA, \\(k=1\\)}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}{0.24\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{one-cluster-pca}\n\t\t\\caption{Density for data single-cluster, 2D PCA, density/k}\n\t\\end{subfigure}\n\\end{figure}\n\nThe prediction on any given PCA reduction however is not valid for different dimension numbers, on multi-clusters classes.\n\nAny number of clusters \\(k\\) high enough (\\(k>5\\)) is no more precise than a density metric. With increasing number of clusters, as shown below, it becomes increasingly unreliable.\n\n\\begin{figure}\n\t\\begin{subfigure}{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{one-cluster-pca-k}\n\t\t\\caption{Best value of \\(k\\) for increasing dimensions in PCA reduction, one-clusters data.}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}{0.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{multi-cluster-pca-k}\n\t\t\\caption{Best value of \\(k\\) for increasing dimensions in PCA reduction, multi-clusters data.}\n\t\\end{subfigure}\n\\end{figure}\n\n\\subsection{Completing the classifier}\nThe classifier model is now finished, comprised of every class-labeled representative point.\n\n\n\\section{Classifying a document}\nTo classify a given a document \\(d\\) we proceed as follows:\n\\begin{enumerate}\n\t\\item Convert the document \\(d\\) to a zipf representative vector, using the common enumeration: \\(\\bmv = z(d)\\).\n\t\\item The document is then classified with the same label as the closest representative point in the classifier model.\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "21ff3cf23164fc02b18ce23f6eb75005665eb78c", "size": 5034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/documentation/Documentazione progetto/chapters/classifier.tex", "max_stars_repo_name": "LucaCappelletti94/zipf_classifier", "max_stars_repo_head_hexsha": "6de213e7d0c28c12f3887f10266d922f54d76444", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documentation/documentation/Documentazione progetto/chapters/classifier.tex", "max_issues_repo_name": "LucaCappelletti94/zipf_classifier", "max_issues_repo_head_hexsha": "6de213e7d0c28c12f3887f10266d922f54d76444", "max_issues_repo_licenses": ["MIT"], "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/documentation/Documentazione progetto/chapters/classifier.tex", "max_forks_repo_name": "LucaCappelletti94/zipf_classifier", "max_forks_repo_head_hexsha": "6de213e7d0c28c12f3887f10266d922f54d76444", "max_forks_repo_licenses": ["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.1290322581, "max_line_length": 349, "alphanum_fraction": 0.7296384585, "num_tokens": 1416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6181683731458051}}
{"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\n\\section*{Question 3}\n\nGive an example of a directed graph $G = (V, E)$, a source vertex $s \\in V$, and a set of tree edges $E_\\pi \\subseteq E$ such that for each vertex $v \\in V$, the unique simple path in the graph $(V, E_\\pi)$ from $s$ to $v$ is a shortest path in $G$, yet the set of edges $E_\\pi$ cannot be produced by running BFS on $G$, no matter how the vertices are ordered in each adjacency list.\n\n\\subsection*{Solution}\n\nFigure \\ref{fig31} provides an example of a graph $G = (V, E)$ in which $E_\\pi$ can be chosen as either $\\{(a,b), (a,c), (b,d), (c,d)\\}$ or $\\{(a,b), (a,c), (b,e), (c,d)\\}$.\nTaking node $a$ as the source vertex, $E_\\pi$ will immediately ensure a unique shortest path from $a$ to all other nodes.\n\n\\begin{figure}[H]\\centering\n\\tikzstyle{vertex}=[circle,draw,minimum size=0.7cm]\n  \\begin{tikzpicture}\n    \\node[vertex] (1) {a};\n    \\node[vertex] (2) [above right = 0.5cm and 1.5cm of 1] {b};\n    \\node[vertex] (3) [below right = 0.5cm and 1.5cm of 1] {c};\n    \\node[vertex] (4) [right = 1.5cm of 2] {d};\n    \\node[vertex] (5) [right = 1.5cm of 3] {e};\n    \\path[draw,thick,->]\n\t(2) edge (5)\n\t(3) edge (4)\n\t;\n    \\path[draw,ultra thick,->]\n    (1) edge (2)\n    (1) edge (3)\n    (2) edge (4)\n    (3) edge (5)\n    ;\n  \\end{tikzpicture}\n\\caption{Directed graph $G$}\\label{fig31}\n\\end{figure}\n\nApplying the breadth-first algorithm to graph $G$ starting from vertex $a$, will result into the Figure \\ref{fig:sfig3-1} after one step (visiting vertex $a$).\nAt step 2, one of nodes $b$ or $c$ must be visited.\nDue to symmetry of the graph which ensures no loss of generality, suppose node $b$ will be visited.\nSince both nodes $b$ and $c$ are connected to nodes $d$ and $e$, any such visit will put nodes $d$ and $e$ in queue, adding edges $(b,d)$ and $(b,e)$ to the set of tree edges.\nIn next step of algorithm, vertex $c$ will be visited.\nHowever, since all vertices connected to $c$ are already placed in queue, the visit will not affect the set of tree edges.\nHence, full implementation of the BFS algorithm will result in Figure \\ref{fig:sfig3-2}.\n\n\\begin{figure}[H]\\centering\n\\tikzstyle{vertex}=[circle,draw,minimum size=0.7cm]\n\\tikzstyle{not visited}=[]\n\\tikzstyle{visited}=[fill=gray!50]\n\\tikzstyle{in queue}=[fill=gray!20]\n\\tikzstyle{label}=[]\n\\tikzstyle{ultra thick}=[line width=0.6mm]\n  \\begin{subfigure}{0.49\\textwidth}\\centering\n    \\begin{tikzpicture}\n    \\node[vertex,visited] (1) {a};\n    \\node[vertex,in queue] (2) [above right = 0.5cm and 1.5cm of 1] {b};\n    \\node[vertex,in queue] (3) [below right = 0.5cm and 1.5cm of 1] {c};\n    \\node[vertex] (4) [right = 1.5cm of 2] {d};\n    \\node[vertex] (5) [right = 1.5cm of 3] {e};\n    \\path[draw,thick,->]\n\t(2) edge (5)\n\t(3) edge (4)\n\t;\n    \\path[draw,ultra thick,->]\n    (1) edge (2)\n    (1) edge (3)\n    (2) edge (4)\n    (3) edge (5)\n    ;\n    \\end{tikzpicture}\n    \\caption{}\n    \\label{fig:sfig3-1}\n  \\end{subfigure}\n  \\begin{subfigure}{0.49\\textwidth}\\centering\n    \\begin{tikzpicture}\n    \\node[vertex,visited] (1) {a};\n    \\node[vertex,visited] (2) [above right = 0.5cm and 1.5cm of 1] {b};\n    \\node[vertex,visited] (3) [below right = 0.5cm and 1.5cm of 1] {c};\n    \\node[vertex,visited] (4) [right = 1.5cm of 2] {d};\n    \\node[vertex,visited] (5) [right = 1.5cm of 3] {e};\n    \\path[draw,thick,->]\n\t(3) edge (4)\n\t(3) edge (5)\n\t;\n    \\path[draw,ultra thick,->]\n    (1) edge (2)\n    (1) edge (3)\n    (2) edge (4)\n    (2) edge (5)\n    ;\n    \\end{tikzpicture}\n    \\caption{}\n    \\label{fig:sfig3-2}\n  \\end{subfigure}\n\\caption{Implementation of BFS on $G$ starting from $a$ at two different steps of the algorithm}\\label{fig32}\n\\end{figure}\n\nTherefore, regardless of the order of adjacency lists, no implementation of the breadth-first search algorithm will generate $E_\\pi$ as set of tree edges.\n", "meta": {"hexsha": "0111a1d2e1d6007494663d4310049e849e7dd128", "size": 4140, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q03.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/hw05q03.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/hw05q03.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": 40.9900990099, "max_line_length": 383, "alphanum_fraction": 0.6251207729, "num_tokens": 1436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850154599563, "lm_q2_score": 0.8757869835428966, "lm_q1q2_score": 0.6181173297194518}}
{"text": "\\section{1-D DP}\n\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{exampleblock}{Weighted interval/class scheduling \\pno{2.2.20}}\n    \\begin{itemize}\n      \\item $\\mathcal{C} = \\set{c_{1}, c_{2}, \\cdots, c_{n}}$\n      \\item $c_{i}$: $\\langle g_{i}, s_{i}, f_{i} \\rangle$\n      \\item choosing non-conflicting classes to maximize your grades\n    \\end{itemize}\n\n    \\fignocaption{width = 0.40\\textwidth}{fig/weighted-interval.png}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $G[i]$: the maximal grades obtained from $\\set{c_{1}, c_{2}, \\cdots, c_{i}}$\n      \\item goal: $G[n]$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item question: choose $c_{i}$ or not in $G[i]$? % {\\footnotesize \\textcolor{red}{(binary chioce)}}\n      \\item recurrence: \n\t\\[\n\t  G[i] = \\max \\set{G[i-1], G[j] + g_{i}}\n\t\\]\n\t\n\t$c_{j}$: the last class which does not conflict with $c_{i}$\n      \\item initialization:\n\t\\[\n\t  G[0] = 0\n\t\\]\n    \\end{itemize}\n    \\uncover<2->{\n      \\begin{center}\n\t\\textcolor{red}{sort $\\mathcal{C}$ by finishing time.}\n      \\end{center}\n    }\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{alertblock}{Why is ordering necessary?}\n    \\fignocaption{width = 0.50\\textwidth}{fig/weighted-interval-unordered.pdf}\n\n    \\[\n      G[7] = \\max \\set{G[6], G[\\set{1,3,5}] + g_{7}}\n    \\]\n\n    \\begin{center}\n      subproblems changed: all $O(2^{n})$ subsets\n    \\end{center}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{alertblock}{Sorting by starting time?}\n    \\fignocaption{width = 0.50\\textwidth}{fig/weighted-interval-starting-time-ordered.pdf}\n\n    \\[\n      G[6] = \\max \\set{G[5], G[\\set{2,3}] + g_{6}}\n    \\]\n\n    \\begin{center}\n      subproblems changed: all $O(2^{n})$ subsets\n    \\end{center}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{exampleblock}{Maximal sum subarray \\pno{2.2.3, 2.2.13, \\textcolor{red}{Google Interview Problem}}}\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\t\\begin{itemize}\n\t  \\item special case: $\\text{mss} = 0$ if all negative\n\t\\end{itemize}\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\\[ \n\t  \\text{MSS}[i] = \\max \\set{\\text{MSS}[i-1] + a_{i}, 0} \\text{ \\textcolor{red}{(prove it!)}}\n\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  \\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}{1-D DP}\n  \\begin{exampleblock}{Reconstructing string \\pno{2.2.14}}\n    \\begin{itemize}\n      \\item string $S[1 \\cdots n]$\n      \\item dict for \\emph{lookup}:\n\t\\begin{displaymath}\n\t  \\text{dict}(w) = \\left\\{ \\begin{array}{ll}\n\t    \\text{true} & \\textrm{if } w \\textrm{ is a valid word}\\\\\n\t    \\text{false} & \\textrm{o.w.}\n\t  \\end{array} \\right.\n\t\\end{displaymath}\n      \\item Is $S[1 \\cdots n]$ valid (reconstructed as a sequence of valid words)?\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $V[i]$: is $S[1 \\cdots i]$ valid?\n      \\item goal: $V[n]$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{1-D DP}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item question: where does the last word start? % {\\footnotesize \\textcolor{red}{(multi-way choices)}}\n      \\item recurrence: \n\t\\[ \n\t  V[i] = \\bigvee_{j = 1 \\ldots i} (V[j-1] \\land \\text{dict}(S[j \\cdots i]))\n\t\\]\n      \\item initialization: $V[0] = \\text{true}$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}<beamer:0>[fragile]{1-D DP}\n    \\begin{displaymath}\n      V[i] = \\left\\{ \\begin{array}{ll}\n\t0 & i = 0 \\\\\n\t\\bigvee_{j = 1 \\ldots i} (V[j-1] \\land \\text{dict}(S[j \\cdots i])) & 1 \\le i \\le n\n      \\end{array} \\right.\n    \\end{displaymath}\n\n  \\begin{block}{Code.}\n    \\begin{verbatim}\n    V[0] = true\n    For i = 1 to n\n      For j = 1 to i\n        V[i] = V[j-1] and Dict(S[j...i])\n    return V[n]\n    \\end{verbatim}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}<beamer:0>{1-D DP}\n  \\begin{exampleblock}{A trip through hotels \\pno{2.2.21}}\n    \\begin{itemize}\n      \\item hotel sequence (distance): $a_{0} = 0, a_{1}, \\cdots, a_{n}$\n      \\item stop at only hotels\n      \\item cost: $(200 - x)^{2}$ \n      \\item to minimize overall cost\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item $C[i]$: minimum cost when the destination is $a_{i}$\n      \\item goal: $C[n]$\n      \\item question: what is the last but one hotel $a_{j}$ to stop in the optimal solution?\n      \\item recurrence: $C[i] = \\min_{0 \\le j < i} \\set{C[j] + (200 - (a_{i} - a_{j}))^{2}}$\n      \\item initialization: $C[0] = 0$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n", "meta": {"hexsha": "72044a25f8025a39457c968e481622ab19b34cea", "size": 6318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-dp-2016-06-16/sections/1d-dp.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-2016/algorithm-tutorial-dp-2016-06-16/sections/1d-dp.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-2016/algorithm-tutorial-dp-2016-06-16/sections/1d-dp.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": 28.08, "max_line_length": 108, "alphanum_fraction": 0.5599873378, "num_tokens": 2392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.618008920323057}}
{"text": "\\section{Verification of Distribution over Monoid Concatenation}~\\label{sec:monoid:distribution}\nIn this section we prove distribution over monoid concatenation. \n%\nConcretely, if a function @f :: i -> m@\nfrom some input @i@ to a monoid @m@, \ndistributes on the input\n@f (i1 stringMappend i2) == (f i1) mappend (f i2)@, \nthen @f@ distributes over monoid concatenation: \n@f i == mconcat (map f (chunk n i))@. \n%\nFor the above property to hold, the input @i@\nshould satisfy certain properties, \nfor example, the input should define the methods\n@stringMappend@ and @chunk@. \n%\nFirst~\\S~\\ref{subsec:rstring} we defined Refined Strings \nas an example of proper inputs, and then~\\S~\\ref{subsec:distribution}\nwe prove distribution over Monoid Concatenation on Refined Strings.  \n\n\n\\subsection{Refined Strings}\\label{subsec:rstring}\nWe represent the input as a Refined String \ndefined at a library @RString.hs@\nwith implementation irrelevant for the proofs.  \n%\n\\NV{introduce RString here is good, but implementation and constact time indexing seems irrelevant here}\n\\begin{code}\ndata RString\n\\end{code}\n%\n@RString.hs@\ndefines the monoid operators @stringMempty@ and @(stringMappend)@\nthat satisfy the monoid laws. \n%\nMoreover, it defines string manipulation operators\nthat come refined via various theorems. \n%\nFor example, the library exposes the\noperators @takeStr@ and @dropStr@\n\\begin{code}\ntakeStr :: i:Nat -> xs:{RString | i <= stringLen xs } \n  -> {v:RString | stringLen v == i }\ndropStr :: i:Nat -> xs:{RString | i <= stringLen xs } \n  -> {v:RString | stringLen v == stringLen xs - i}\n\\end{code}\n%\nand asserts that appending a list split via @take@ and @drop@\nexactly reconstructs the list.\n\\begin{code}\nconcatTakeDrop \n  :: i:Nat -> xs:{RString | i <= stringLen xs} \n  -> {xs == takeStr i xs stringMappend dropStr i xs }\n\\end{code}\n%\nThe operators defined in @RString@ are already reflected in the logic. \n%\nThus we use them to further define operators\nthat we reflect and use in the theorems. \n%\nFor example, @takeStr@ and @dropStr@ are used to define \n@chunkStr@ \n\\begin{code}\nchunkStr i xs \n  | i <= 1 ||stringLen xs <= i \n  = C xs N \n  | otherwise\n  = C (takeStr i xs) (chunkString i (dropStr i xs))\n\\end{code}\n%\nWe reflect @chunkStr@ into logic and use it to define and prove \ndistribution over monoid concatenation. \n\n\n\\subsection{Distribution over Monoid Concatenation on Refined Strings}\\label{subsec:distribution}\n%\nWe use the refinement type specification for @monoidDirstibution@\nto specify and prove  that for each monoid @m@, \nif the function @f:RString -> m@ distributes over @RString@\nthen it distributes over monoids. \n%\nNote that the assumption of the theorem, \nis expressed in the specifications as a functional argument \nthat makes the proper assumptions for @f@. \n%\nTo prove distribution over monoids for a specific @f@, \nwe need to invoke @monoidDirstibution@ \non @f@ and a proper proof argument that @f@ distributes over @RString@.\n%\n\\begin{theorem}[Monoid Distribution]\\label{theorem:monoid:distribution}\nIf @m@ is a monoid, then each function @f:RString -> m@\nthat distributes over @RString@, distributes over monoid concatenation.\n%\n\\begin{code}\nmonoidDirstibution\n  :: f:(RString -> m)\n  -> (x1:_ -> x2:_ -> {f (x1 stringMappend x2) == (f x1) <> (f x2)} )\n  -> is:RString\n  -> n:Int \n  -> {f is == mconcat (map f (chunkStr n is))}\n\\end{code}\n\\end{theorem}\n\n\\begin{proof}\nThe proof proceeds by induction on the length of the input.\n%\n\\begin{code}\nmonoidDirstibution f thm is n  \n  | stringLen is <= n || n <= 1\n  =   mconcat (map f (chunkStr n is))\n  ==. mconcat (map f (C is N))\n  ==. mconcat (f is `C` map f N)\n  ==. f is <> mconcat N\n  ==. f is <> mempty \n  ==. f is ? idRight (f is)\n  *** QED \nmonoidDirstibutionf f thm is n  \n  =   mconcat (map f (chunkStr n is))\n  ==. mconcat (map f (C takeIs (chunkStr n dropIs))) \n  ==. mconcat (f takeIs `C` map f (chunkStr n dropIs))\n  ==. f takeIs <> f dropIs\n       ? monoidDirstibution f thm dropIs n  \n  ==. f (takeIs <+> dropIs)\n       ? thm takeIs dropIs\n  ==. f is \n       ? concatTakeDrop n is \n  *** QED  \n  where\n    dropIs = dropStr n is \n    takeIs = takeStr n is \n\\end{code}\n%\nIn the base case we use rewriting and right identity on the monoid @f is@. \n%\nIn the inductive case, \nwe use the inductive hypothesis on the input @dropIs = dropStr n is@, \nthat is provably smaller than @is@ as @n > 1@. \n%\nThen, by our assumption argument @thm takeIs dropIs@\nwe get basic distribution of @f@, that is \n@f takeIs <> f dropIs == f (takeIs stringMappend dropIs)@. \n%\nFinally, we merge @takeIs stringMappend dropIs@ to @is@\nusing the property @concatTakeDrop@ take is exported by the @RString@\nlibrary.\n\\qed\\end{proof}", "meta": {"hexsha": "de62e219e178a7fa05d0eaa7ae668272141a4f15", "size": 4692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/monoid-distribution.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/monoid-distribution.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/monoid-distribution.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": 32.3586206897, "max_line_length": 104, "alphanum_fraction": 0.7035379369, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6180089155895131}}
{"text": "\\chapter{Theory}\\label{cha:theory}\nThis chapter presents the literature used in order to answer the research questions.\nIt starts off with defining line voxelization and the three algorithms used.\nThen the optimal scanline is presented together with other voxelization techniques.\nFinally, some error metrics are presented, one of which is used as part of the final results.\n\n\\section{Line Voxelization}\n\\textit{Line voxelization} is a way of generating voxels based on a 3D line.\nThis is needed for the optimal scanline method to work, as this is how the scanlines are generated. \nIn this thesis, line voxelization defines all voxels in a grid being touched by a line. \nThis is similar to how lines are drawn to a screen in 2D.\nAn example of line voxelization can be seen in \\figref{fig:line-voxelization}.\nTo determine which voxels are touching the line, three algorithms are introduced in the upcoming sections. \n\n\\input{fig/line-voxelization.fig}\n\n\\newpage\n\n\\subsection{Real Line Voxelization}\n\\call{voxeltraversal} proposed a method of ray marching voxels in a uniform grid. \nThis can also be used to voxelize lines and will further be called \\textit{Real Line Voxelization} (RLV).\nThe basis of the algorithm is the line equation\n$$p = p_0 + vt,$$\nwhere $p$ is a position on the line, $p_0$ is the start position of the line, $v$ is the direction of the line (normalized) and $t$ is how much the direction is scaled.\n\nWhen the algorithm starts, it initializes $t$ as\n$$t_x = \\frac{p_{1,x} - p_{0,x}}{v_x},$$\nwhere $p_{1,x}$ is the x-position of the next voxel in the x-axis, as seen in \\figref{fig:next-voxel}.\nThis is calculated similarly for each component of $t$.\nEach iteration of the algorithm evaluates $t_{min}$ as $min(t_x,t_y,t_z)$.\nLet's assume $t_{min} = t_x$.\nThis means the next voxel is in the x-direction.\nAgain, from \\figref{fig:next-voxel}, $p_{1,x}$ is closer to $p_0$ compared to $p_{1,y}$ and therefore has a smaller $t$ value.\nThis means the next voxel would be placed to the right of $p_0$.\nThe $t$ for the next iteration is calculated by subtracting all of its components by $t_{min}$.\n\nFinally assign \n$$t_x = \\frac{|p_{i,x} - p_{i-1,x}|}{v_x} = \\frac{1}{v_x},$$\nwhere $p_{i,x}$ is the x-position of the $i$'th voxel in the x-direction.\nHere the grid is assumed to have a voxel size of 1, meaning $|p_{i,x} - p_{i-1,x}| = 1$.\nAfter this the iteration is restarted.\nThe iteration is then terminated when the sum of all $t_{min}$ exceeds the length of the line.\n\n\\input{fig/next-voxel.fig}\n\n\\newpage\n\n\\subsection{Integer Line Voxelization}\n\\textit{Integer Line Voxelization} (ILV) follows the same structure as RLV except it avoids the floating-point arithmetics and divisions.\nThe changes needed to avoid floating-points are adapted from \\call{scanline-voxelization}.\n\nHaving RLV as a basis, ILV requires three changes.\nFirstly, the initial $t$ is calculated from the center of the start voxel, which means \n$$p_{1,x} - p_{0,x} = \\frac{1}{2},$$\nand therefore\n\\begin{equation*}\n\\left\\{\n\\begin{aligned}\n    t_x &= \\frac{1}{2 \\Delta X} \\\\\n    t_y &= \\frac{1}{2 \\Delta Y} \\\\\n    t_z &= \\frac{1}{2 \\Delta Z}\n\\end{aligned}\n\\right.\n,\n\\end{equation*}\nwhere $\\Delta X$ denotes the length of the line in the x-axis.\n$\\Delta Y$ and $\\Delta Z$ are defined similarly.\n\nSecondly, since only the relative sizes of $t$'s components are needed, the equation can therefore be multiplied with \n$$2 \\Delta X\\Delta Y\\Delta Z,$$\nto avoid fractions.\nAs such, the integer version of $t_x$ is denoted $T_x$ and can be described as\n\\begin{equation}\\label{eq:Tx}\n  T_x = \\Delta Y\\Delta Z.\n\\end{equation}\n$T_y$ and $T_z$ are described similarly.\n\nLastly, the iteration of the algorithm follows RLV, replacing $t$ with $T$, but the assignment to $t_x$ in the end is instead \n$$T_x = 2 \\Delta Y\\Delta Z,$$\nif $T_{min} = T_x$.\nThis follows \\equref{eq:Tx}, but multiplied with 2.\nThe reason is that before $T$ was calculated to traverse half a voxel, multiplying it by 2 then traverses a whole voxel.\n\n\\subsection{3D Bresenham Algorithm}\nThe 3D version of the \\textit{Bresenham} algorithm presented by \\call{3d-bresenham} follows the original by \\call{bresenham} rather nicely.\nThe 3D algorithm starts off with a few assumptions about the line,\n$\\Delta X \\ge \\Delta Y \\ge 0$ and $\\Delta X \\ge \\Delta Z \\ge 0$, these are defined the same as in the previous section.\n\nIn the original Bresenham an error in the y-axis is initialized to\n$$e_y = 2 \\Delta Y - \\Delta X.$$\nThen for each iteration, if the current $x$ is greater than $X_1$, terminate the iteration.\nOtherwise set the current voxel and increment $x$ by one.\nFollowing that, check if the error of the line is greater than 0.\nIf it is, increase $y$ by one and decrease the error, otherwise increase the error.\nThen restart the loop.\nThe change in the error is defined as\n\n\\begin{equation*}\n\\left\\{\n\\begin{aligned}\n  e'_y &= e_y + 2 (\\Delta Y - \\Delta X) &, e_y \\ge 0\\\\\n  e'_y &= e_y + 2 \\Delta Y &, e_y < 0 \\\\\n\\end{aligned}\n\\right.\n.\n\\end{equation*}\n\nTo extend the algorithm to 3D, \\citeauthor{3d-bresenham} added another error, $e_z$, which kept track of when $z$ should increase.\nThis works the same way as $e_y$ and is evaluated after $e_y$.\nA pseudo code of the algorithm can be found in \\appref{app:3dbresen}.\n\n\\section{Model Voxelization}\nAs mentioned in the introduction, voxelization is a way of turning a 3D model or scene into voxel data.\nThis can be done in a wide range of ways and is still being researched today.\nFour such techniques, two of which are based on the optimal scanline, are presented in the following sections.\n\n\\subsection{Floating-Point Optimal Scanline}\\label{sss:vox_optscan}\nOne of the more recent works in voxelization include work done by \\call{scanline-voxelization}.\nThis algorithm, called optimal scanline, uses line voxelization as its core concept.\nAll its calculations are done for each triangle of the model.\nThe algorithm first sorts the vertices of a triangle based on its most dominant axis.\nThis axis is defined as the x-, y- or z-axis which most aligns with the triangle's normal.\nIt can be determined by choosing the axis with the greatest absolute value of the normal's components.\nThat is, choose the axis which matches $max(|n_x|, |n_y|, |n_z|)$, where $n$ is the normal of the triangle.\nThe dominant axis will further be assumed to be the z-axis.\n\nWith the vertices of the triangle sorted, it performs line voxelizations between each of the vertices using RLV.\nThis results in all the edges of the triangle being voxelized.\n\nIn order to fill the interior of the triangle, it splits the edges into slices in the z-axis.\nWhere each edge has the same integer z-value.\nThen, for each slice, perform 2D line voxelization between the edges of the triangle.\nThis is shown in \\figref{fig:real-optimal-scanline}.\nThe figure also shows that not every edge voxel needs to contain a scanline endpoint.\nThat is where the optimal keyword of the algorithm comes in.\nThe authors propose a theorem stating that, there exists a distance, $l$, where there cannot exist a voxel between two parallel lines.\nThis distance can be seen in \\figref{fig:scanline-distance}.\nIntuitively, the distance can be seen to be the length of the voxel's diagonal projected onto the scanline direction, $d_{sl}$.\nFurthermore, the length, $l$, can be calculated as $|d_{sl,x}| + |d_{sl,y}|$.\nTo prove this the scanline can be classified into four cases, all the combination of the signs of $d_{sl}$. The result is the four following equations:\n\\begin{equation*}\n\\left\\{\n\\begin{aligned}\n  l &= ((0,1) - (1,0)) \\cdot d_{sl}\\hspace{1cm},d_{sl,x} < 0 < d_{sl,y}\\\\\n  l &= ((1,0) - (0,1)) \\cdot d_{sl}\\hspace{1cm},d_{sl,y} < 0 < d_{sl,x}\\\\\n  l &= ((0,0) - (1,1)) \\cdot d_{sl}\\hspace{1cm},d_{sl,x}, d_{sl,y} < 0\\\\\n  l &= ((1,1) - (0,0)) \\cdot d_{sl}\\hspace{1cm},0 < d_{sl,x}, d_{sl,y}\\\\\n\\end{aligned}\n\\right.\n\\end{equation*}\nThe values $(0,0)$, $(1,1)$, $(1,0)$ and $(0,1)$ are the corners of the voxel.\nThey are used to calculate the diagonal that aligns with $d_{sl}$.\nCalculating the dot product of each of the equations results in $l = |d_{sl,x}| + |d_{sl,y}|$.\n\n\\input{fig/real-optimal-scanline.fig}\n\\input{fig/scanline-distance.fig}\n\n\\newpage\n\n\\subsection{Integer Optimal Scanline}\\label{ss:integer-optimal-scanline}\nThe way integer voxelization of the optimal scanline is handled is a bit different from the floating-point one. \nSince the scanline direction and the scanline length are both floating-points, these cannot be used.\nInstead, it makes use of an iterative approach, where it steps through the edge voxels of the triangle until the voxel is too far away from the previous scanline. \nHow exactly it was derived can be found in~\\cite{scanline-voxelization}, but the final theory is presented below (assuming z is the most dominant axis).\n\nTo start off, two boundary variables are defined, called $C_{lower}$ and $C_{upper}$.\nThese are defined as\n\\begin{equation*}\n  \\left\\{\n    \\begin{aligned}\n      C_{lower} &= \\Delta Y X^a - \\Delta X Y^a - |\\Delta X| - |\\Delta Y|\\\\\n      C_{upper} &= \\Delta Y X^a - \\Delta X Y^a + |\\Delta X| + |\\Delta Y|\n    \\end{aligned}\n  \\right.,\n\\end{equation*}\nwhere ($X^a$, $Y^a$) and ($X^b$, $Y^b$) are the endpoints of the previous scanline and $\\Delta X = X^b - X^a$, $\\Delta Y = Y^b - Y^a$.\nEach iteration, the algorithm steps the edge voxelization by one voxel and calculate a variable called $C_k$ to be\n$$ C_k = \\Delta Y X_k - \\Delta X Y_k, $$\nwhere ($X_k$, $Y_k$) is the k'th voxel on the edge, with k=0 being the previous scanline endpoint.\nIf this variable is outside the boundaries, $C_{lower}$ and $C_{upper}$, the voxel is too far away from the previous scanline and $(X_{k-1},Y_{k-1})$ is chosen as the next scanline endpoint. \nThis iteration is performed separately for both the edges.\nAs a triangle has three edges and not two, the voxels on the edge from $v_1$ to $v_2$ are merged with the voxels on the edge from $v_2$ to $v_3$.\nThose two edges are therefore counted as a single edge.\n\n\\subsection{Rasterization}\nAnother technique used for surface voxelization utilizes the GPU rasterizer in order to optimize the voxel generation.\nOne such technique was presented by \\call{octree-voxelization}.\nThe basic idea is that, for every triangle in the model, find the triangle's most dominant axis and render it from that direction. \nIn practice, this means swapping the dominant axis with the z-axis in a vertex shader.\nThe triangle is then sent to the rasterizer which outputs fragments of the triangle.\nThe voxel coordinate is then simply the position of the fragment and its depth value.\nThen the axes are swapped back from before in order to place it correctly in the scene.\nFinally it writes the coordinate to a 3D texture which stores the voxel data.\nNote that all rasterization is done in a framebuffer with the same width and height as the voxel grid resolution.\nThere are however problems with the algorithm creating holes in the voxelization in some instances.\nIt can be resolved by using a technique called conservative rasterization.\nThis involves marking all fragments which are touched by the triangle. \n\n\n% \\subsection{Triangle-Box Intersection}\n% Triangle-box intersection is another method of voxelization that was proposed by \\call{SAT-voxelization}.\n% The main idea of the method is, as its name implies, performing intersection tests between the voxels and the triangles.\n% In order to minimize the amount of tests, a few optimizations are done.\n% The first of which is classifying the type of triangle it is, be it a 1D line, a 2D triangle or a 3D triangle.\n% These are further classified to their respective dominant axis.\n% All the triangles of the model are then sorted so that they are grouped in their classes. \n% This makes it so that most of the GPU threads are performing the same tasks without branch divergence.\n% Another optimization is that a triangle has at most three voxel thickness in the most dominant axis.\n% This could reduce the amount of tests needed significantly.\n\n\\newpage\n\n\\subsection{Depth Buffer}\nOne way of performing solid voxelization is to make use of the depth buffer \\cite{depth-buffer}.\nThis is done by rendering the entire model from six different directions, positive x, y and z, and negative x, y and z.\nIn these rendering steps, only the depth buffer is needed.\nThen the voxelization is defined as all voxels which are within all the depth buffers. \n\nOne way to do this, is to iterate through the entire grid and marking all voxels which are within the buffers as occupied.\nThis is however rather slow for higher resolutions, as the complexity grows cubically.\nAnother way would be to choose one axis, let's say the z-axis, and iterate through its buffer x- and y-coordinates.\nThen for each coordinate, there is a minimum and maximum z-position which is determined by the two depth buffers in the z-axis.\nThis means the algorithm only needs to iterate through these two values instead of all the z-values.\nAs most models do not fill the entire voxel grid, this reduces the runtime of the algorithm in the average case.\n\nOne obvious problem of the algorithm is that it needs to render the object six times to voxelize it.\nFor convex shapes, this can be reduced to two, as the shape can be fully described by rendering it from the front and back. \n\n\\section{Error Analysis}\\label{s:error}\nCalculating the approximation errors can be done using several methods.\nThe choice of method depends on the use case.\nThis thesis presents two different methods to analyze the error.\nThese are relative error, the one used in~\\cite{scanline-voxelization}, and the Jaccard distance.\n\n\\subsection{Relative Error}\nThe \\textit{relative error} can be described as\n\\begin{equation*}\n  e_{re} = \\frac{|x - y|}{|x|} = \\Big|\\frac{x - y}{x}\\Big|,\n\\end{equation*}\nwhere $x$ is the actual value and $y$ is the approximation.\nThis was the method used by \\call{scanline-voxelization}, where they set $x$ to the total voxel count of the floating-point version and $y$ to the total voxel count of the integer version.\nA problem with this is that if a voxel is moved to another location, the error would be considered 0.\nThis can be seen in \\figref{fig:relative-error}, where the relative error of the voxel count is 0.\nTherefore, a different error metric is required in order to describe this error.\n\n\\input{fig/relative-error.fig}\n\n\\newpage\n\n\\subsection{Jaccard Distance}\\label{ss:mae}\nThe \\textit{Jaccard distance} is an error metric which aims to measure differences in sets.\nIt is derived from  the Jaccard similarity presented in \\cite{jaccard}, where it instead measures how similar two sets are.\nThe Jaccard similarity is defined as the size of the intersection divided by the size of the union of the two sets.\nThis results in a value between zero and one, which can be interpreted as a percentage of how similar two sets are.\nThe Jaccard distance is defined as one subtracted by the Jaccard similarity.\nIt can also be defined as the symmetric difference divided by the union of the two sets.\nBoth of which are equivalent.\n", "meta": {"hexsha": "c6448f21969bbd1656fe983d9b650d66bdca5b02", "size": 15073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Latex/theory.tex", "max_stars_repo_name": "Thraix/MasterThesis", "max_stars_repo_head_hexsha": "4e4cb94b2a4ee261b2b9974aa4b20f6643eb6595", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-16T10:54:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-16T10:54:38.000Z", "max_issues_repo_path": "Thesis/Latex/theory.tex", "max_issues_repo_name": "Thraix/MasterThesis", "max_issues_repo_head_hexsha": "4e4cb94b2a4ee261b2b9974aa4b20f6643eb6595", "max_issues_repo_licenses": ["MIT"], "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/Latex/theory.tex", "max_forks_repo_name": "Thraix/MasterThesis", "max_forks_repo_head_hexsha": "4e4cb94b2a4ee261b2b9974aa4b20f6643eb6595", "max_forks_repo_licenses": ["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.4224806202, "max_line_length": 191, "alphanum_fraction": 0.7526703377, "num_tokens": 3976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6180089155895131}}
{"text": "% Copyright 2017-2018 Markus J. Pflaum, licensed under CC BY-NC-ND 4.0\n% main author: \n%   Markus J. Pflaum\n%\n\\section{Summability}\n\\label{sec:summability}\n\\begin{definition}\nAssume to be given a locally convex topological vector space $\\tvsV$ over the field $\\fldK$ of real or complex numbers.\nLet $(v_i)_{i \\in I}$ be a family of elements of $\\tvsV$. Let $\\mathscr{F} (I)$ be the\nset of finite subsets of $I$ and note that it is filtered by set-theoretic inclusion. \nThe family  $(v_i)_{i \\in I}$ then gives rise to the net \n$\\Big( \\sum_{i \\in J} v_i \\Big)_{J \\in \\mathscr{F}(I)}$. One calls the family  $(v_i)_{i \\in I}$\n\\emph{summable} to an element $v \\in \\tvsV$ if the net \n$\\Big( \\sum_{i \\in J} v_i \\Big)_{J \\in \\mathscr{F}(I)}$ converges to $v$. In other words this means that \nfor every convex zero neighborhood $U \\subset \\tvsV$ and $\\varepsilon >0$ there exists an element\n$J_{U,\\varepsilon} \\in \\mathscr{F} (I)$ such that for all finite sets $J$ with $ J_{U,\\varepsilon} \\subset J \\subset I$\n\\[\n   p_U \\left( v - \\sum_{i \\in J} v_i \\right) < \\varepsilon \\ .\n\\]\nAs before, $p_U$ denotes here the gauge of $U$. \nIf $\\tvsV$ is Hausdorff, the limit $v$ of a summable family  $(v_i)_{i \\in I}$ is\nuniquely determined, and one  writes in this situation\n\\[\n   v = \\sum_{i \\in I} v_i \\ .  \n\\]\nWe denote the space of summable families in $\\tvsV$ over the given index set $I$ by \n$\\ell^1 (I ,\\tvsV)$. For $E=\\C$ we just write $\\ell^1 (I )$ instead of $\\ell^1 (I ,\\C)$. If in addition the index set \ncoincides with $\\N$, we briefly denote $\\ell^1 (\\N )$ by $\\ell^1$.\n\\end{definition}\n\n\\begin{proposition}[Cauchy criterion for summability]\n  Let $\\tvsV$ be a complete locally convex topological vector space. \n  A family $(v_i)_{i \\in I}$ of elements of $\\tvsV$ then is summable \n  to some $v\\in \\tvsV$ if and only if it satisfies the following Cauchy condition:\n  \\begin{axiomlist}[\\hspace{1pt}]\n  \\item[\\textup{\\sffamily (C)}] \n    For every convex zero neighborhood $U \\subset \\tvsV$ and $\\varepsilon >0$ there exists an element\n    $J_{U,\\varepsilon} \\in \\mathscr{F} (I)$ such that for all $K \\in \\mathscr{F} (I)$ with  $ K \\cap J_{U,\\varepsilon} = \\emptyset$\n    the relation \n    \\[\n      p_U \\left( \\sum_{i \\in K} v_i \\right) < \\varepsilon \n    \\]\n    holds true. \n  \\end{axiomlist}\n \n\\end{proposition}\n\\begin{proof}\n  By completeness of $\\tvsV$ it suffices to verify that the net $\\Big( \\sum_{i \\in J} v_i \\Big)_{J \\in \\mathscr{F}(I)}$ is a Cauchy net\n  if and only if condition \\textup{\\sffamily (C)} is satisfied. Recall that one calls\n  $\\Big( \\sum_{i \\in J} v_i \\Big)_{J \\in \\mathscr{F}(I)}$ a Cauchy net if for every convex zero neighborhood $U \\subset \\tvsV$ \n  all $\\varepsilon >0$ there exists an element $J_{U,\\varepsilon} \\in \\mathscr{F} (I)$ such that for all $J,J' \\in \\mathscr{F} (I)$ \n  containing  $ J_{U,\\varepsilon}$ as a subset the relation \n  \\[\n     p_U \\left( \\sum_{i \\in J} v_i - \\sum_{i\\in J'} v_i \\right) < \\varepsilon \n  \\]\n  holds true. \n  But that is clearly equivalent to condition \\textup{\\sffamily (C)}. \n\\end{proof}\n\n\\para Several other notions of summability have been introduced in the analysis and functional analysis literature.  \nThese are mainly either used to establish summability criteria or are used in the study of \ntopological tensor products and nuclearity of locally convex topological vector spaces, see \\cite{GroPTTEN,PieNLCS}. \nIn the following we define these further notions of summability and study their properties.\nThe symbol $\\tvsV$  hereby always stands for a locally convex \\tvs, $I$ always denotes a nonempty\nindex set, and $\\mathscr{F} (I)$ the set of its finite subsets.\n\n\\begin{definition}\n  A family   $(v_i)_{i \\in I}$ in $\\tvsV$ is called \\emph{weakly summable} to $v \\in \\tvsV$ if for \n  every continuous linear form $\\alpha : \\tvsV \\to \\fldK$ the net \n  $\\Big( \\sum_{i \\in J} \\alpha( v_i ) \\Big)_{J \\in \\mathscr{F}(I)}$ converges in $\\fldK$ to $\\alpha ( v )$.\n  In other words this means that for every $\\alpha \\in \\tvsV'$ and $\\varepsilon >0$ there exists a finite set \n  $J_{\\alpha,\\varepsilon} \\subset I$ such that for all finite sets $J$ with $J_{\\alpha,\\varepsilon} \\subset  J \\subset I $ \n  \\[\n    \\left| \\alpha (v) -  \\sum_{j\\in J} \\alpha( v_i )   \\right|< \\varepsilon \\ . \n  \\]\n  The set of all weakly summable families in $\\tvsV$ with index set $I$ is denoted $\\ell^1 [I, \\tvsV]$.\n\\end{definition}\n\n\\begin{definition}\n  A family  $(v_i)_{i \\in I}$ in $\\tvsV$ is called \\emph{absolutely summable} if for every circled convex \n  zero neighborhood $U \\subset \\tvsV$ there exists some $C\\geq 0$ such that\n  \\[\n    \\sum_{i \\in J} p_U \\left( v_i\\right) \\leq C \\quad \\text{for all } J \\in \\mathscr{F} (I) \\ .\n  \\]\n  We denote the set of all absolutely summable families  in $\\tvsV$ by  $\\ell^1 \\{ I, \\tvsV \\}$.\n\\end{definition}\n\n\\begin{proposition}\n  A family $(v_i)_{i \\in I} \\subset \\tvsV$ is absolutely summable if and only if for every element $U$ \n  of a basis of circled convex zero neighborhoods there exists a $C\\geq 0$ such that\n  \\[\n    \\sum_{i \\in J} p_U \\left( v_i\\right) \\leq C \\quad \\text{for all } J \\in \\mathscr{F} (I) \\ .\n  \\]\n\\end{proposition}\n\n\\begin{proof}\n  \n\\end{proof}\n\n\\begin{definition}\n A family $(v_i)_{i \\in I}$ in $\\tvsV$ is called \\emph{totally summable} if there exists a bounded \n absolutely convex subset $B\\subset \\tvsV$  and a $C\\geq 0$ such that\n \\[\n   \\sum_{i \\in J} p_B \\left( v_i\\right) \\leq C  \\quad \\text{for all } J \\in \\mathscr{F} (I) \\ .\n \\]\n We write $\\ell^1 \\langle I, \\tvsV \\rangle$ for the set of all totally summable families in $\\tvsV$.\n\\end{definition}\n\n\\subsec{Summable families of complex numbers}\n\n\\begin{lemma}[cf.~{\\cite[Lem.~1.1.2]{PieNLCS}}]\n  Let $(z_i)_{i\\in I}$ be a family of  complex numbers for which there exists a positive real number $C > 0$ \n  such that \n  \\[\n     \\left|\\sum_{i\\in J} z_i \\right| \\leq C \\quad \\text{for all } J \\in \\mathscr{F} (I) \\ .\n  \\]\n  Then one has the estimate\n   \\[\n     \\sum_{i\\in J}\\left| z_i \\right| \\leq 4 C \\quad \\text{for all } J \\in \\mathscr{F} (I) \\ .\n  \\]\n\\end{lemma}\n\n\\begin{proof}\n  We assume first that all $z_i$ are real. Then let $I^+$ the set of all indices $i\\in I$ such that $z_i \\geq 0$,\n  and $I^-$ the set of all  $i\\in I$ such that $z_i < 0$. Then, for all finite $J\\subset I$\n  \\[\n     \\sum_{i\\in J} \\left| z_i \\right| =  \\sum_{i\\in J\\cap I^+}  \\left| z_i  \\right| +  \\sum_{i\\in J\\cap I^-}  \\left| z_i  \\right|\n    =  \\left| \\sum_{i\\in J\\cap I^+}  z_i  \\right| +  \\left| \\sum_{i\\in J\\cap I^-}  z_i  \\right| \\leq 2  C \\ .\n  \\] \n  In the general case decompose $z_i$ into real and imaginary parts $x_i = \\Re z_i$ and   $y_i = \\Im z_i$.\n  By the triangle inequality one obtains for all finite $J\\subset I$\n  \\[\n    \\sum_{i\\in J} \\left| z_i \\right| \\leq \\sum_{i\\in J} \\left| x_i \\right| + \\sum_{i\\in J} \\left| y_i \\right| \\leq 4 C \\ .\n  \\]\n\\end{proof}\n\n\\begin{proposition}\n\\label{thm:summability-criteria-family-complex-numbers}\n  For a  family $(z_i)_{i\\in I}$ of complex numbers the following are equivalent.\n  \\begin{romanlist}\n  \\item The family $(z_i)_{i\\in I}$ is summable. \n  \\item The family $(\\left| z_i \\right| )_{i\\in I}$ is summable.\n  \\item The family $(z_i)_{i\\in I}$ is absolutely summable.\n\n  \\item There exists some $C > 0$ such that \n        $\\sum_{i\\in J}\\left| z_i \\right| \\leq C$ for all $J\\in \\mathscr{F} (I)$.\n  \\end{romanlist}\n  In case that  one hence all of the conditions are fulfilled, the estimate \n  \\[\n     \\left|  \\sum_{i\\in I} z_i \\right|  \\leq \\sum_{i\\in I}\\left| z_i \\right| \n  \\]\n  holds true.\n\\end{proposition}\n\n\\begin{proof}\n  Assume that  $(z_i)_{i\\in I}$ is absolutely summable. Since $\\C$ is normed with norm given by the absolut value \n  this just means that there exists some $C > 0$ such that \n  $\\sum_{i\\in J}\\left| z_i \\right| \\leq C$ for all $J\\in \\mathscr{F} (I)$. Hence the supremum \n  $c = \\sup \\left\\{ \\sum_{i\\in J}\\left| z_i \\right| \\mid J \\in \\mathscr{F} (I)\\right\\}$ exists and is $\\leq C$. \n  For given $\\varepsilon >0$ choose $J_\\varepsilon \\in \\mathscr{F} (I)$ such that \n  \\[\n        c- \\varepsilon \\leq \\sum_{i\\in J_\\varepsilon}\\left| z_i \\right| \\leq c \\ .\n  \\]\n  Then one has for all $K\\in \\mathscr{F} (I)$ with $K\\cap J_\\varepsilon = \\emptyset$ \n  \\[\n     \\left| \\sum_{i\\in K} z_i \\right| \\leq  \\sum_{i\\in K} \\left| z_i \\right| \\leq \\varepsilon \\ .\n  \\]\n  Hence $\\left( \\sum_{i\\in J} z_i \\right)_{J \\in \\mathscr{F} (I)}$ is a Cauchy net, so has to\n  converges  by completeness of $\\C$. This proves summability of   $(z_i)_{i\\in I}$.\n  \n  Vice versa, assume now that   $(z_i)_{i\\in I}$ is summable. Then\n  $\\left( \\sum_{i\\in J} z_i \\right)_{J \\in \\mathscr{F} (I)}$ is a Cauchy net. Hence there exists an element \n  $J_1 \\in  \\mathscr{F} (I)$ such that for all $K\\in  \\mathscr{F} (I)$ with $K \\cap J_1 = \\emptyset$  \n  the inequality \n  \\[\n      \\left| \\sum_{i\\in K} z_i \\right| < 1 \n  \\]\n  holds true. Let $C = \\sum_{i\\in J_1} \\left| z_i\\right|$. Then one has for all $J\\in  \\mathscr{F} (I)$\n  \\[\n       \\left| \\sum_{i\\in J} z_i \\right| \\leq  \\left| \\sum_{i\\in J\\setminus J_1} z_i \\right| +  \n       \\left| \\sum_{i\\in J\\cap J_1} z_i \\right| \\leq 1 + C \\ .\n  \\]\n  By the preceding lemma the set of partial sums $ \\sum_{i\\in J} \\left| z_i \\right|$, where $J$ runs through the \n  finite subsets of $I$, is then bounded by $4 + 4C$, hence  $(z_i)_{i\\in I}$ is absolutely summable.\n\\end{proof}\n\n\\subsec{Summability in Banach spaces}\n\n\\begin{proposition}\\label{thm:summability-criteria-family--normed-vector-space}\n  Let $\\banachV$ be a normed vector space. \n  For a  family $(v_i)_{i\\in I}$ of elements in $\\tvsV$ the following are equivalent:\n  \\begin{romanlist}\n  \\item\\label{ite:absolute-summable-family-normed-vector-space} The family $(v_i)_{i\\in I}$ is absolutely summable. \n  \\item\\label{ite:norm-summable-family-normed-vector-space} The family $(\\left\\| v_i \\right\\| )_{i\\in I}$ is summable.\n  \\item\\label{ite:cauchy-summable-family-normed-vector-space} There exists some $C > 0$ such that \n        $\\sum_{i\\in J}\\left\\| v_i \\right\\| \\leq C$ for all $J\\in \\mathscr{F} (I)$.\n  \\end{romanlist}\n  If $\\banachV$ is even a Banach space, these conditions are all equivalent to \n  \\begin{romanlist}\n  \\setcounter{enumi}{3}\n  \\item The family $(v_i)_{i\\in I}$ is summable.\n  \\end{romanlist}\n\\end{proposition}\n\\begin{proof}\n  \\ref{ite:norm-summable-family-normed-vector-space} and \\ref{ite:cauchy-summable-family-normed-vector-space}\n  are equivalent by \\Cref{thm:summability-criteria-family-complex-numbers}\n  Assume now that \\ref{ite:absolute-summable-family-normed-vector-space} holds true. \n\\end{proof}\n\n\n\\textbf{to do:} Carl Neumann series\n\n\n\\subsec{Properties of and relations between the various summability types} \n\n\\begin{theorem}\n  Let $I$ be a non-empty index set. Then the spaces $\\ell^1 (I, \\tvsV )$ of summable families, \n  $\\ell^1 [I, \\tvsV ]$ of weakly summable families, $\\ell^1 \\{I, \\tvsV \\}$ of absolutely summable families and\n  $\\ell^1 \\langle I, \\tvsV \\rangle$ of totally summable families in $E$ are all subvector spaces of \n  the product vector space $E^I = \\Pi_{i\\in I} E$.   Furthermore one has the following chain of inclusions:\n  \\[\n     \\ell^1 \\langle I, \\tvsV \\rangle\\subset\\ell^1 \\{I, \\tvsV \\}   \\quad\\text{and} \\quad \\ell^1 (I, \\tvsV) \\subset \\ell^1 [I, \\tvsV ] \\ .\n  \\] \n  If $E$ is complete, then one even has \n   \\[\n        \\ell^1 \\{I, \\tvsV \\}   \\subset \\ell^1 (I, \\tvsV)     \n   \\]\n\\end{theorem}\n\n\\begin{proof}\n    Now let $(v_i)$ be a summable family and $\\alpha : \\tvsV \\to \\fldK$ a continuous linear form. \n\n Let $U$ be an absolutely convex zero neighborhood. Then $U$ absorbes $B$, so there exists $r>0$ such that\n $B \\subset rU$. Hence\n\\end{proof}\n\n\n", "meta": {"hexsha": "5245c0620a02165aecbc8527fcddf50c0f149953", "size": 11633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/summability.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/summability.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/summability.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": 48.8781512605, "max_line_length": 136, "alphanum_fraction": 0.6538296226, "num_tokens": 4255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.8418256512199032, "lm_q1q2_score": 0.6180006488059938}}
{"text": "\\section{Correctness of Parallel String Matching}\\label{sec:stringmatching}\n\nIn \\S~\\ref{sec:parallelization} we showed that any monoid morphism\nwhose domain is chunkable can be parallelized. We now apply that\nresult to parallelize string matching. We start by observing that\nstrings are a chunkable monoid. %\\NV add monoid methods\nWe then turn string matching for a\ngiven target into a monoid morphism from a string to a suitable\nmonoid, @SM target@, defined in\n\\S~\\ref{subsec:stringmatcher}. \nFinally, in \\S~\\ref{subsec:parallel-string-matching}, we parallelize string matching\nby a simple use of the\nparallel morphism function of \\S~\\ref{subsec:both-levels}. \n\n\\ignore{\n  In this section we apply the Correctness of Parallelization Theorem~\\ref{theorem:two-level}\nto a string matching function @toSM@\nthat is a morphism between strings and the indices where a target string appears,\nto get correctness of parallelization of @toSM@.\n\nWe define @toSM :: RString -> SM target@\nfrom a Refined String data type @RString@\nto a dependently typed string maching data type @SM target@\nwhere @target@ represents the substring to be matched.\n%\nTo apply Theorem~\\ref{theorem:two-level} on @toSM@ we need to discharge three proof obligations.\n%\n\\begin{itemize}\n\\item @RString@ is a chunkable monoid (\\S~\\ref{subsec:refinedstrings}),\n\\item @SM target@ is a monoid (\\S~\\ref{subsec:stringmatcher}), and\n\\item @toSM@ is a morphism between @RString@ and @SM target@ (\\S~\\ref{subsec:smmorphism}).\n\\end{itemize}\n%\nWith these proof obligations discharged we conclude (\\S~\\ref{subsec:parallel-string-matching})\ncorrectness of parallel string matching.\n}\n\n\\subsection{Refined Strings are Chunkable Monoids}\\label{subsec:refinedstrings}\n\\input{text/stringmatcher/rstring-is-monoid}\n\n\\subsection{String Matching Monoid}\\label{subsec:stringmatcher}\n\\input{text/stringmatcher/string-matcher-is-monoid}\n\n\\subsection{String Matching Monoid Morphism}\\label{subsec:smmorphism}\n\\input{text/stringmatcher/string-matching-morphism}\n\n\\subsection{Parallel String Matching}\\label{subsec:parallel-string-matching}\n\\input{text/stringmatcher/all-together}\n", "meta": {"hexsha": "ac7ceeb0d6260c7c71f727b8120a9b050949c9a9", "size": 2118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/stringmatching.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/stringmatching.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/stringmatching.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": 43.2244897959, "max_line_length": 96, "alphanum_fraction": 0.7894239849, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.618000644963245}}
{"text": "%\\NeedsTeXFormat{LaTeX2e}[1995/06/01]\n\\input{preamble}\n\n\\newcommand{\\version}{Draft: 18 June 2017}\n\n\\lhead{\\scriptsize Barnes \\& Soule}\n\\chead{\\scriptsize}\n\\rhead{\\scriptsize \\thepage}\n\n\\lfoot{\\scriptsize Nagadan}\n\\cfoot{\\scriptsize}\n\\rfoot{\\scriptsize \\version}\n\n\\usepackage{color}\n\\definecolor{red}{RGB}{255,0,0}\n\n\\newcommand{\\phit}{\\phi_t}\n\\newcommand{\\phis}{\\phi_s}\n\n\n\n%******************************************************************************\n\\begin{document}\n%******************************************************************************\n\n%==============================================================================\n% Title block information\n%==============================================================================\n\\title{Nagadan: Identification Influential Data using a Quadratic Discharge Potential Model}\n\\author{\nDr. Randal J. Barnes\\\\\nDepartment of Civil, Environmental, and Geo- Engineering\\\\\nUniversity of Minnesota\n\\and\nRichard Soule\\\\\nSource Water Protection\\\\\nMinnesota Department of Health\\\\\n}\n\\date{\\version}\n\\maketitle\n\\thispagestyle{plain}\n\n\n%==============================================================================\n\\section{Introduction}\n%==============================================================================\n\n\n%==============================================================================\n\\section{Geohydrologic Descriptors}\n%==============================================================================\nThe underlying model for the regional flow is given by a quadratic function.\n%\n\\begin{equation}\\label{2.1}\n    \\Phi(x,y) = A x^2 + B y^2 + C xy + Dx + Ey + F\n\\end{equation}\n%\nThe six model parameters, $\\left\\{ A, B, C, D, E, F \\right\\}$, are organized into a single column vector and modeled as stochastic variables.\n%\n\\begin{equation}\\label{2.2}\n    \\mat{P} = \\begin{bmatrix} A \\\\ B \\\\ C \\\\ D \\\\ E \\\\ F \\end{bmatrix}\n\\end{equation}\n%\n\n\\newpage\n%------------------------------------------------\n\\subsection{Regional recharge}\n%------------------------------------------------\nThe regional recharge is given by\n%\n\\begin{equation}\\label{2.3}\n    N = -2 \\left( A + B \\right)\n\\end{equation}\n%\n\\begin{equation}\\label{2.4}\n    \\ev{N} = -2 \\left( \\ev{A} + \\ev{B} \\right)\n\\end{equation}\n%\n\\begin{equation}\\label{2.5}\n    \\var{N} = 4 \\left( \\var{A} + \\var{B} + 2\\cov{A,B} \\right)\n\\end{equation}\n\n\n%------------------------------------------------\n\\subsection{Regional Discharge Components}\n%------------------------------------------------\nThe regional discharge components, $Q_x$ and $Q_y$, are given by\n%\n\\begin{align}\n    Q_x &= -D    \\label{2.6}\\\\\n    Q_y &= -E    \\label{2.7}\n\\end{align}\n%\n\\begin{align}\n    \\ev{Q_x} &= -\\ev{D} \\label{2.8}\\\\\n    \\ev{Q_y} &= -\\ev{E} \\label{2.9}\n\\end{align}\n%\n\\begin{align}\n    \\var{Q_x} &= \\var{D} \\label{2.10}\\\\\n    \\var{Q_y} &= \\var{E} \\label{2.11}\\\\\n    \\cov{Q_x,Q_y} &= \\cov{D,E} \\label{2.12}\n\\end{align}\n\n%------------------------------------------------\n\\subsection{First-order second-moment analysis}\n%------------------------------------------------\nLet the function $g(x,y)$ be twice differentiable over the domain of interest.\n%\n\\begin{equation} \\label{8.1}\n    \\ev{g(X,Y)} \\approx g(\\mu_X,\\mu_Y) + \\frac{1}{2} \\left[\n        \\ppderiv{g}{x} \\, \\sigma_X^2 +\n        \\ppderiv{g}{y} \\, \\sigma_Y^2 +\n        2 \\pqderiv{g}{x}{y} \\, \\sigma_{XY} \\right]\n\\end{equation}\n%\n\\begin{equation} \\label{8.2}\n    \\var{g(X,Y)} \\approx\n        \\left[ \\pderiv{g}{x} \\right]^2 \\sigma_X^2 +\n        \\left[ \\pderiv{g}{y} \\right]^2 \\sigma_Y^2 +\n        2 \\left[ \\pderiv{g}{x} \\cdot \\pderiv{g}{y} \\right] \\sigma_{XY}\n\\end{equation}\n%\nwhere all of the partial derivatives are evaluated at $(\\mu_X,\\mu_Y)$.\n\n\n\\newpage\n%------------------------------------------------\n\\subsection{Regional Discharge Magnitude}\n%------------------------------------------------\nThe regional discharge magnitude, $T$, is given by\n%\n\\begin{align}\n    S &= Q_x^2 + Q_y^2 \\label{2.13}\\\\\n    T &= \\sqrt{S} \\label{2.14}\n\\end{align}\n%\n\\begin{align}\n    \\pderiv{T}{Q_x} &= \\frac{Q_x}{T} \\label{2.15}\\\\\n    \\pderiv{T}{Q_y} &= \\frac{Q_y}{T} \\label{2.16}\\\\\n    \\ppderiv{T}{Q_x} &= \\frac{Q_y^2}{T^3} \\label{2.17}\\\\\n    \\ppderiv{T}{Q_y} &= \\frac{Q_x^2}{T^3} \\label{2.18}\\\\\n    \\pqderiv{T}{Q_x}{Q_y} &= - \\frac{Q_x Q_y}{T^3} \\label{2.19}\n\\end{align}\n\n\\begin{equation}\\label{2.20}\n    \\ev{T} \\approx T + \\frac{1}{2} \\left[\n        \\ppderiv{T}{Q_x} \\, \\var{Q_x} +\n        \\ppderiv{T}{Q_y} \\, \\var{Q_y} +\n        2 \\pqderiv{T}{Q_x}{Q_y} \\, \\cov{Q_x,Q_y} \\right]\n\\end{equation}\n%\n\\begin{equation}\\label{2.21}\n    \\var{T} \\approx\n        \\left[ \\pderiv{T}{Q_x} \\right]^2 \\var{Q_x} +\n        \\left[ \\pderiv{T}{Q_y} \\right]^2 \\var{Q_y} +\n        2 \\left[ \\pderiv{T}{Q_x} \\cdot \\pderiv{T}{Q_y} \\right] \\cov{Q_x,Q_y}\n\\end{equation}\n\n%------------------------------------------------\n\\subsection{Regional Discharge Direction}\n%------------------------------------------------\nThe regional discharge magnitude, $U$, is given by\n%\n\\begin{align}\n    S &= Q_x^2 + Q_y^2 \\label{2.22}\\\\\n    U &= \\text{atan2}\\left(Q_y, Q_x\\right) \\label{2.23}\n\\end{align}\n%\n\\begin{align}\n    \\pderiv{U}{Q_x} &= -\\frac{Q_y}{S} \\label{2.24}\\\\\n    \\pderiv{U}{Q_y} &=  \\frac{Q_x}{S} \\label{2.25}\\\\\n    \\ppderiv{U}{Q_x} &=  2 \\frac{Q_x Q_y}{S^2} \\label{2.26}\\\\\n    \\ppderiv{U}{Q_y} &= -2 \\frac{Q_x Q_y}{S^2} \\label{2.27}\\\\\n    \\pqderiv{U}{Q_x}{Q_y} &= \\frac{Q_y^2 - Q_x^2}{S^2} \\label{2.28}\n\\end{align}\n\n\\begin{equation}\\label{2.29}\n    \\ev{U} \\approx U + \\frac{1}{2} \\left[\n        \\ppderiv{U}{Q_x} \\, \\var{Q_x} +\n        \\ppderiv{U}{Q_y} \\, \\var{Q_y} +\n        2 \\pqderiv{U}{Q_x}{Q_y} \\, \\cov{Q_x,Q_y} \\right]\n\\end{equation}\n%\n\\begin{equation}\\label{2.30}\n    \\var{U} \\approx\n        \\left[ \\pderiv{U}{Q_x} \\right]^2 \\var{Q_x} +\n        \\left[ \\pderiv{U}{Q_y} \\right]^2 \\var{Q_y} +\n        2 \\left[ \\pderiv{U}{Q_x} \\cdot \\pderiv{U}{Q_y} \\right] \\cov{Q_x,Q_y}\n\\end{equation}\n\n\n%******************************************************************************\n\\end{document}\n%******************************************************************************\n", "meta": {"hexsha": "39a11cbc18fc7a8fa8461d425f32685aafeb7123", "size": 6055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/Nagadan.tex", "max_stars_repo_name": "RandalJBarnes/NagadanPy", "max_stars_repo_head_hexsha": "4fc3cf7e7650adb39d0e68ee9cddc243b85ef904", "max_stars_repo_licenses": ["MIT"], "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/Nagadan.tex", "max_issues_repo_name": "RandalJBarnes/NagadanPy", "max_issues_repo_head_hexsha": "4fc3cf7e7650adb39d0e68ee9cddc243b85ef904", "max_issues_repo_licenses": ["MIT"], "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/Nagadan.tex", "max_forks_repo_name": "RandalJBarnes/NagadanPy", "max_forks_repo_head_hexsha": "4fc3cf7e7650adb39d0e68ee9cddc243b85ef904", "max_forks_repo_licenses": ["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.8928571429, "max_line_length": 141, "alphanum_fraction": 0.4777869529, "num_tokens": 1961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6180006409958139}}
{"text": "\\documentclass{article}\n\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\\usepackage{amstext}\n\\usepackage{graphicx}\n\n\\title{\\textbf{Six DOF Aircraft Simulator}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nThe goal of this project is to implement a six degrees of freedom (DOF), nonlinear simulation for fixed-wing aircraft. \nThe first iteration of this project is using a linear aircraft model. The second iteration will be using a nonlinear model. \n   \n\\section{Aircraft Model}\nThe linear longitudinal and lateral models for a conventional fixed-wing aircraft could be written as follows \\cite{Nelson}.\n\n\\begin{equation} \\label{Eq:Linear_Long_sys}\n    \\begin{bmatrix}\n    \\dot{u} \\\\\n    \\dot{w} \\\\\n    \\dot{q} \\\\\n    \\dot{\\theta} \\\\ \t\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    X_u & X_w & 0 & -g \\cos{\\theta_0}\\\\\n    Z_u & Z_w & u_0 & -g \\sin{\\theta_0}\\\\\n    M_u & M_w & M_q & 0\\\\\n    0 & 0 & 1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    u \\\\\n    w \\\\\n    q \\\\\n    \\theta \\\\ \t\n    \\end{bmatrix}\n    +\n    \\begin{bmatrix}\n    X_{\\delta_e} & X_{\\delta_t} \\\\\n    Z_{\\delta_e} & 0 \\\\\n    M_{\\delta_e} & M_{\\delta_t} \\\\\n    0 & 0\\\\ \t\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    {\\delta_e} \\\\\n    {\\delta_t}  \t\n    \\end{bmatrix}\n\\end{equation}\n\n\\begin{equation} \\label{Eq:Linearized_sys}\n    \\begin{bmatrix}\n    \\dot{v} \\\\\n    \\dot{p} \\\\\n    \\dot{r} \\\\\n    \\dot{\\phi} \\\\\n    \\dot{\\psi} \\\\\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    Y_v & Y_p & -(u_0 - Y_r) & g \\cos{\\theta_0} & 0\\\\\n    \\mathcal{L}_v & \\mathcal{L}_p & \\mathcal{L}_r & 0 & 0\\\\\n    N_v & N_p & N_r & 0 & 0\\\\\n    0 & 1 & 0 & 0 & 0\\\\\n    0 & 0 & \\sec{\\theta_0} & 0 & 0\\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    v\\\\\n    p\\\\\n    r\\\\\n    \\phi\\\\\n    \\psi\\\\ \t\n    \\end{bmatrix}\n    +\n    \\begin{bmatrix}\n    0 & Y_{\\delta_r} \\\\\n    \\mathcal{L}_{\\delta_a} & \\mathcal{L}_{\\delta_r} \\\\\n    N_{\\delta_a} & N_{\\delta_r} \\\\\n    0 & 0\\\\\n    0 & 0\\\\ \t\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    {\\delta_a} \\\\\n    {\\delta_r}  \t\n    \\end{bmatrix}\n\\end{equation}\n\nIn this project we will consider the linear model of the aircraft \"DELTA\" given in \\cite[PP. 561--563]{Mclean}\nwhose parameters are given as follows (at $U_0 = 75~ m/s$ and $\\theta_0 = 2.7 ^\\circ$)\n\\begin{equation}\\label{Eq:DELTA_Params}\n    \\begin{split}\n        m &= 300000 kg\\\\\n        X_u &= -0.02\\\\\n        X_w &= 0.1\\\\\n        Z_u &= -0.23\\\\\n        Z_w &= -0.634\\\\\n        M_u &= -2.55*10^{-5}\\\\\n        M_w &= -0.005\\\\\n        M_q &= -0.61\\\\\n        Y_v &= -0.078\\\\\n        Y_p &= 0\\\\\n        Y_r &= 0\\\\\n        \\mathcal{L}_v &= -0.086\\\\\n        \\mathcal{L}_p &= -1.0758\\\\\n        \\mathcal{L}_r &= 0.6334\\\\\n        N_v &= 0.0037\\\\\n        N_p &= -0.1121\\\\\n        N_r &= -0.2569\\\\\n        X_{\\delta_e} &= 0.14\\\\\n        Z_{\\delta_e} &= -2.9\\\\\n        M_{\\delta_e} &= -0.64\\\\\n        X_{\\delta_t} &= 1.56\\\\\n        M_{\\delta_t} &= 0.0054\\\\\n        Y_{\\delta_r} &= 0.0065\\\\\n        \\mathcal{L}_{\\delta_a} &= 0.46\\\\\n        \\mathcal{L}_{\\delta_r} &= 0.1\\\\\n        N_{\\delta_a} &= 0.05\\\\\n        N_{\\delta_r} &= -0.21\\\\\n    \\end{split}\n\\end{equation}\nwhere $\\delta_t$ is considered to be from the trim thrust. \nAs such, $\\delta_t$ is allowed the between $1$ and $-0.56$ \\cite{Hassan2016_JAST}.\n\n\\section{Algorithm Structure}\n\n\n\\section{Results}\nIn this simulation example, the aircraft is subject to both elevator and aileron sinusoidal inputs\n with an amplitude of $5$ degrees and a frequency of $\\pi$ rad/s. Figures \\ref{Fig:Translational_Velocities}, \n \\ref{Fig:Rotational_Velocities} and \\ref{Fig:Attitude} show the resulting translational velocities, \n rotational velocities and attitude angles, respectively.\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{sim_results_uvw.png}\n    \\caption{Translational velocities.}\n    \\label{Fig:Translational_Velocities}\n\\end{figure}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{sim_results_pqr.png}\n    \\caption{Rotational velocities.}\n    \\label{Fig:Rotational_Velocities}\n\\end{figure}\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{sim_results_phi_theta_psi.png}\n    \\caption{Attitude angles.}\n    \\label{Fig:Attitude}\n\\end{figure}\n\n\n\\bibliographystyle{unsrt}\n\\bibliography{ref}\n\\end{document}", "meta": {"hexsha": "6376ee344044065730badc895ba6dad18152a51d", "size": 4314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/6DOF_Aircraft_Simulator.tex", "max_stars_repo_name": "ammhassan/6DOF_Aircraft_Simulator", "max_stars_repo_head_hexsha": "8e2165ed023d07e4491d4a6176e41e3e7d0e21cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-19T22:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-19T22:15:04.000Z", "max_issues_repo_path": "doc/6DOF_Aircraft_Simulator.tex", "max_issues_repo_name": "ammhassan/6DOF_Aircraft_Simulator", "max_issues_repo_head_hexsha": "8e2165ed023d07e4491d4a6176e41e3e7d0e21cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-11T16:02:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-11T16:02:18.000Z", "max_forks_repo_path": "doc/6DOF_Aircraft_Simulator.tex", "max_forks_repo_name": "ammhassan/6DOF_Aircraft_Simulator", "max_forks_repo_head_hexsha": "8e2165ed023d07e4491d4a6176e41e3e7d0e21cb", "max_forks_repo_licenses": ["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.9625, "max_line_length": 124, "alphanum_fraction": 0.590403338, "num_tokens": 1556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746407, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6177785934120582}}
{"text": "%\\section*{Appendices}\n\\addcontentsline{toc}{section}{Appendices}\n\\renewcommand{\\thesubsection}{\\Alph{subsection}}\n\\label{sec:annexe}\nRecall that $r_{x_i}$ is the distance between a BS at the origin and one given device $x_i$, $\\theta$ is the SINR threshold for capture effect. $H_{x_i}$ and $\\exp(G_{x_i})$ are respectively random variable accounting for Rayleigh fading and lognormal shadowing.\n\\begin{align}\np_{s} \\left( r_{x_i} \\right)\n%&= \\mathbb{P}\\left\\lbrace \\frac{P_r}{I^{'}} \\geq \\theta \\right\\rbrace \\nonumber\\\\\n& =\\mathbb{P}\\left\\lbrace \\frac{H_{x_i} \\exp(G_{x_i}) r_{x_i}^{-\\gamma}}{\\sum_{x_j \\in \\Phi_{m}} H_{, x_j} \\exp(G_{x_j}) r_{x_j}^{-\\gamma}}  \\geq \\theta \\right\\rbrace \\nonumber\\\\\n%& =\\mathbb{P} \\left\\lbrace \\frac{H_{x_i}  r_{x_i}^{-\\gamma}}{\\sum_{x_j \\in \\Phi_{m}} H_{x_j} \\exp(G_{x_j}-G_{x_i}) r_{x_j}^{-\\gamma}} \\geq \\theta \\right\\rbrace \\nonumber\n\\end{align}\nLet $I=\\sum_{x_j \\in \\Phi_{m}} H_{x_j} \\exp(G_{x_j}) r_{x_j}^{-\\gamma}$, which is the cumulative interference suffered for device $x_i$. Thus, we have:\n%Let $Z_{3}= \\exp(G_{x_j}-G_{x_i})$, $H = Z_1 Z_3$. $I$ be \n\\begin{align}\n\\label{eq:def_ps}\np_{s}\\left( r \\right)  &= Pr \\left\\lbrace H_{x_i} \\geq I \\theta\\exp(-G_{x_i})r ^{\\gamma}  \\right\\rbrace  \\nonumber\\\\\n&=\\mathbb{E}_{G_{x_i}}\\left\\lbrace  \\mathbb{E}_{I} \\left[ \\exp(-\\theta \\exp(-g_{x_i}) r^{\\gamma}  I ) \\vert G_{x_i} = g_{x_i}\\right]\\right\\rbrace   \\nonumber\\\\\n&= \\mathbb{E}_{G_{x_i}} \\left[ \\mathcal{L}_{I}\\left\\lbrace \\theta \\exp(-G_{x_i}) r^{\\gamma}\\right\\rbrace \\right] \n\\end{align}\nIt is observed that the $p_s\\left( r \\right)$ is actually the expectation (w.r.t $G_{x_i}$) of a conditional Laplace Transform of cumulative interference $I$ at point $\\theta \\exp(-G_{x_i})  r_{x_i}^{\\gamma}$.\n\\begin{align}\n\\label{eq:interferece-laplace-transform}\n\\mathcal{L}_{I}\\left( s \\right)  &= \\mathbb{E}\\left[ \\exp(-sI)\\right] \\nonumber\\\\\n&= \\mathbb{E}\\left[ \\exp(-s\\sum_{x_j \\in \\Phi_m} H_{x_j} \\exp(G_{x_j})  r_{x_j}^{-\\gamma})\\right] \\nonumber \\\\\n&= \\mathbb{E}_{\\Phi_m} \\left\\lbrace \\prod_{x_j\\in \\Phi_m} \\mathbb{E}\\left[\\exp(-sH_{x_j} \\exp(G_{x_j})  r_{x_j}^{-\\gamma})\\right] \\right\\rbrace \n\\end{align}\n\nFormula (\\ref{eq:interferece-laplace-transform}) is actually the Probability Generating Functional (PGFL) of a Poisson point process.\nApplying Campell's theorem, \n%\\qsong{Here I give the wikipedia link for this theorem, in the final version, I will give a reference of one book: https://en.wikipedia.org/wiki/Campbell's_theorem_(probability)}\n\\begin{align}\n\\label{eq:laplace_trans_I}\n\\mathcal{L}_{I}\\left( s \\right) &=\\exp\\left\\lbrace -\\lambda_m \\pi \\mathbb{E}\\left[ H^{\\frac{2}{\\gamma}}\\right]\\mathbb{E}\\left[ \\exp(\\frac{2}{\\gamma}G_{x_j})\\right] \\Gamma(1-\\frac{2}{\\gamma})s^{\\frac{2}{\\gamma}}  \\right\\rbrace \n\\end{align}\nThis result has been derived in~\\cite[eq.3.20]{haenggi2009interference}.\n\n\\begin{align}\n\\label{eq:lognormal_moment}\n\\mathbb{E}\\left[ \\exp(\\frac{2}{\\gamma}G_{x_j})\\right] &= \\exp \\left\\lbrace \\left( \\frac{\\sqrt{2}\\beta\\sigma}{\\gamma}\\right) ^2\\right\\rbrace \n\\end{align}\n\\begin{align}\n\\label{eq:expo_moment}\n\\mathbb{E}\\left[ H^{\\frac{2}{\\gamma}} \\right] &= \\Gamma(1+\\frac{2}{\\gamma}) \n\\end{align}\n\nSubstituting $(\\ref{eq:expo_moment})(\\ref{eq:lognormal_moment})$ into $(\\ref{eq:laplace_trans_I})$, we have:\n\\begin{align}\n\\mathcal{L}_{I}\\left( s \\right) &= \\exp\\left\\lbrace -p\\lambda_m \\pi \\Gamma(1+\\frac{2}{\\gamma}) \\Gamma(1-\\frac{2}{\\gamma}) \\exp \\left( \\frac{\\sqrt{2}\\beta\\sigma}{\\gamma}\\right) ^2 s^{\\frac{2}{\\gamma}}  \\right\\rbrace\n\\end{align}\nLet $s=\\theta \\exp(-G) r^{\\gamma}$, thus\n\\begin{align}\n\t\\mathcal{L}_{I}\\left\\lbrace \\theta \\exp(-G) r^{\\gamma}\\right\\rbrace = \\exp\\left\\lbrace -A r^2\\exp(-\\frac{2}{\\gamma}G)\\right\\rbrace ,\n\\end{align}\nwhere $A=p\\lambda_m\\pi \\Gamma(1+\\frac{2}{\\gamma}) \\Gamma(1-\\frac{2}{\\gamma}) \\exp \\left( \\frac{\\sqrt{2}\\beta\\sigma}{\\gamma}\\right) ^2 \\theta^{\\frac{2}{\\gamma}}$.\n\n\nWe continue to process formula $(\\ref{eq:def_ps})$. It remains to calculate the expectation with respect to $G$:\n\\begin{align}\n\t\\label{eq:def_ps_2}\n\tp_{s}(r) &= \\mathbb{E}_{G}\\left[ \\exp(-A r^2 \\exp(-\\frac{2}{\\gamma}G)) \\right] \\nonumber\\\\\n\t&=\\int_{-\\infty}^{+\\infty} \\exp(-A r^2 e^{-\\frac{2}{\\gamma}x})\\frac{1}{\\sqrt{2\\pi}\\sigma} \\exp(-\\frac{x^2}{2\\sigma^2}) dx \\nonumber\\\\\n\t&=\\int_{-\\infty}^{+\\infty} \\exp(-A r^2 e^{x})\\frac{1}{\\sqrt{2\\pi}\\frac{2}{\\gamma}\\sigma} \\exp(-\\frac{x^2}{2(\\frac{2}{\\gamma})^2\\sigma^2}) dx \n\\end{align}\nFormula $(\\ref{eq:def_ps_2})$ is actually the value of Laplace Transform for one log-normal random variable $X \\sim LN(0, \\frac{2}{\\gamma}\\sigma)$ at point $Ar^2$.\n\\begin{align}\n\tp_{s}(r) &= \\mathbb{E}\\left[ \\exp(-Ar^2X)\\right] \\nonumber\\\\\n\t&= \\mathcal{L}_{X} \\left[ Ar^2\\right]  \n\\end{align}\nNow we will not consider to get the closed-form expression for $p_{s}(r)$, because in the following the form will simplify the analysis. \n%现在我们先不考虑：获取P_s的解析解，因为在下一步计算会更方便\n%A closed form expression of the Laplace transform of the lognormal distribution does not\n%exist. According to reference~\\cite{asmussen2016laplace}, the Laplace transform of a log-normal random variable can be accurately approximated as follows:\n%\\begin{align}\n%\\label{eq:laplace-transform-lognormal-form-1}\n%\\mathcal{L} \\left\\lbrace X \\right\\rbrace \\left( s \\right)\n%&= \\frac{\\exp(-\\frac{W(s \\sigma_{X}^2 e^{\\mu_{X}} )^2 + 2W(s \\sigma_{X}^2 e^{\\mu_{X}})}{2\\sigma_{X}^2})}{\\sqrt{1 + W(s \\sigma_{X}^2 e^{\\mu_{X}})}},\n%\\end{align}\n%where $W\\left( \\cdot \\right)$ is the Lambert W function~\\cite{corless1996lambertw}, which is defined as the solution in principal branch of the\n%equation $W\\left(x\\right) e^{W \\left( x\\right) }= x$.\n\nWe want to know the outage probability $P_{f1}$ over an infinite plane. Our strategy is to start with outage probability $P_{f1}(R)$ over a finite circle region with radius $R$, then extend to an infinite area. We still assume one device is located at the origin of the circle region with radius $R$. The spatial density of base station is $\\pi R^2 \\lambda_b$. The number of base station $N$ is thus:\n\\begin{align}\n\t\\mathbb{P}\\left[ N=n\\right] = e^{-\\pi R^2 \\lambda_b}\\frac{\\left( \\pi R^2 \\lambda_b\\right) ^n}{n!} \n\\end{align}\nSince the base station is uniformly distributed in the circle region, the probability density function of distance between a given base station and the device $r$ at the origin is as follows:\n\\begin{align}\n\tf\\left(r\\right) = \\frac{2r}{R^2}, r \\in \\left[ 0, R\\right]  \n\\end{align} \n\nThus, the outage probability $P_f\\left( R\\right) $ conditioned on base station $N$ is as follows:\n\\begin{align}\n\tP_{f1}\\left( R \\vert N= n\\right ) &=  \\prod_{i=1}^{n}\\int_{0}^{R}(1-p_{s}(r_i))f(r_i) dr_i \\nonumber\\\\\n\t&= \\left[ 1-\\int_{0}^{R} p_s\\left(r\\right)f\\left( r\\right)dr \\right]^n \n\\end{align} \n\nNext step, we decondition for  $P_{f1}\\left( R \\vert N= n\\right )$, we have the expression $P_{f1}\\left( R \\right )$, which is actually the probability generating function (PGF) of Poisson distribution with intensity $\\pi R^2 \\lambda_b$:\n\\begin{align}\n\t\tP_{f1}\\left( R\\right ) &= \\mathbb{E}\\left[ P_f\\left( R \\vert N= n\\right )  \\right] \\nonumber\\\\\n\t\t&= \\exp(-\\pi R^2 \\lambda_b \\int_{0}^{R} p_{s}\\left( r \\right)f\\left( r\\right)dr  ) \\\\\n\t\t&= \\exp(-\\pi R^2 \\lambda_b \\int_{0}^{R} \\mathbb{E}\\left[ e^{-Ar^2X} \\right]  \\frac{2r}{R^2}dr) \\\\ \n\t\t&= \\exp(-\\pi R^2 \\lambda_b \\mathbb{E}\\left[\\int_{0}^{R} e^{-Ar^2X} \\frac{2r}{R^2}dr \\right] ) \\\\ \n\t\t&= \\exp(-\\pi R^2 \\lambda_b \\mathbb{E}\\left[\\int_{0}^{R} e^{-Ar^2X} \\frac{2r}{R^2}dr \\right] ) \\\\ \n\t\t&= \\exp(-\\pi\\lambda_b \\mathbb{E}\\left[\\int_{0}^{R^2} e^{-ArX} dr \\right] ) \\\\\n\t\t&= \\exp( \\pi\\lambda_b \\mathbb{E}\\left[ \\frac{e^{-ArX} }{AX} \\vert_{0}^{R^2}\\right] ) \\\\\n\t\t&= \\exp( \\pi\\lambda_b \\mathbb{E}\\left[ \\frac{e^{-AR^2X} }{AX} - \\frac{1}{AX}\\right] )\n\\end{align}\nBy extending $R$ to $+\\infty$, we get the outage probability over infinite plane:\n\\begin{align}\n\t\\label{eq:analytical_result_approach_1}\n\tP_f &=  \\exp( \\pi\\lambda_b A \\mathbb{E}\\left[ {X^{-1}}\\right] ) \\\\\n\t&= \\exp(-\\frac{1}{\\frac{p\\lambda_m}{\\lambda_b}\\Gamma(1+\\frac{2}{\\gamma}) \\Gamma(1-\\frac{2}{\\gamma})\\theta^{\\frac{2}{\\gamma}}} )\n\\end{align}\nWe surprisingly observe that with BS reception diversity, the limit case, the outage probability has the same formula with the case where just Rayleigh fading is considered. But in practical system, we still observe that shadowing has improved the outage probability, since the wireless network cannot be infinite and the population is always limited. \n\n\nAs a comparison reference, now we consider probability $P_{f2}$ over an infinite plane using traditional method: the device attach the nearest BS.\nThe distance to the nearest base station, we denote this distance as $r$. Its PDF is:\n\\begin{align}\nf\\left( r\\right)  = 2 \\pi \\lambda_b  r \\exp(-\\lambda_b \\pi r^2), r \\in \\left[ 0, +\\infty\\right] \n\\end{align}\n\\begin{align}\nP_{f2}\\left( R \\right) &= \\mathbb{E}\\left[ 1-p_{s}\\left(r\\right) \\right]  \\nonumber\\\\\n&= 1-\\int_{0}^{R}   p_{s}\\left(r\\right)  f\\left( r\\right) dr \\nonumber\\\\\n&= 1-\\int_{0}^{R} \\mathbb{E}\\left[ \\exp(-A r^2 X)\\right]  2 \\pi \\lambda_b  r \\exp(-\\lambda_b \\pi r^2) dr \\nonumber\\\\\n&= 1-  \\pi \\lambda_b \\mathbb{E}\\left[ \\int_{0}^{R} \\exp\\left\\lbrace -\\left( AX+\\lambda_b \\pi\\right)  r^2 \\right\\rbrace    dr^2 \\right] \\nonumber\\\\\n&= 1 + \\frac{\\pi \\lambda_b \\exp\\left\\lbrace -\\left( AX+\\lambda_b \\pi\\right)  r^2 \\right\\rbrace }{AX+\\lambda_b \\pi}\\vert_{0}^{R} \n\\end{align}\nSimilarly, by extending $R$ to $+\\infty$, we have $P_{f2}$: \n\\begin{align}\nP_{f2} &= 1 - \\mathbb{E}\\left[ \\frac{1}{\\frac{AX}{\\pi\\lambda_b}+1} \\right] \\nonumber\n\\end{align}\nFor the simplicity  of writing in the following, let $B= A \\left( \\pi \\lambda \\right) ^{-1}$. And we will focus on the term $\\mathbb{E}\\left[ \\frac{1}{BX+1} \\right]$. Thus, \n\\begin{align}\n\\label{eq:mean_bx+1_step1}\n&\\mathbb{E}\\left[ \\frac{1}{BX+1} \\right] =  \\int_{0}^{+\\infty} \\frac{1}{\\left( Bx+1\\right) \\sqrt{2\\pi}\\sigma_X x} \\exp(-\\frac{(\\ln(x))^2}{2\\sigma_X^2})dx\\nonumber\\\\\n&= \\int_{-\\infty}^{+\\infty} \\frac{1}{ Be^t+1} \\cdot \\frac{1}{\\sqrt{2\\pi} \\sigma_X} \\exp\\left\\lbrace -\\frac{t^2}{2 \\sigma_X^2}\\right\\rbrace dt \\nonumber\\\\\n&= \\int_{-\\infty}^{+\\infty} \\frac{1}{1+e^{-(t-\\ln(B))}} \\cdot \\frac{1}{\\sqrt{2\\pi} \\sigma_X} \\exp\\left\\lbrace -\\frac{t^2}{2 \\sigma_X^2}\\right\\rbrace dt \\nonumber\\\\\n&= \\int_{-\\infty}^{+\\infty} \\frac{1}{1+\\exp{-\\left( \\frac{t-\\frac{\\ln(B)}{\\sigma_X}}{\\frac{1}{\\sigma_X}}\\right) }} \\cdot \\frac{1}{\\sqrt{2\\pi}} \\exp\\left\\lbrace -\\frac{t^2}{2}\\right\\rbrace dt \\nonumber\\\\\n& = \\int_{-\\infty}^{+\\infty} \\frac{\\phi\\left( t \\right) }{1+\\exp{-\\left( \\frac{t-\\frac{\\ln(B)}{\\sigma_X}}{\\frac{1}{\\sigma_X}}\\right) }} dt,\n\\end{align}\nwhere $\\phi\\left( t \\right)$ is the PDF of standard normal distribution. According to~\\cite{crooks2009logistic}, the logistic function can be approximately by an error function:\n\\begin{align}\n\\label{eq:logistical_erf_fun_appro}\n\\frac{1}{1 + \\exp(-\\frac{x}{\\alpha})} &\\approx \\frac{1}{2} + \\frac{1}{2}\\erf(\\frac{\\sqrt{\\pi}}{4\\alpha}x)，\n\\end{align}\nwhere $\\alpha$ is the parameter of logistic function. Applying $(\\ref{eq:logistical_erf_fun_appro})$ for the denominator of integrand in $(\\ref{eq:mean_bx+1_step1})$ , we have:\n\\begin{align}\n\\frac{1}{1+\\exp{-\\left( \\frac{t-\\frac{\\ln(B)}{\\sigma_X}}{\\frac{1}{\\sigma_X}}\\right) }} &\\approx \\frac{1}{2} + \\frac{1}{2}\\erf(\\frac{\\sqrt{\\pi}\\sigma}{4}\\left( t-\\frac{\\ln(B)}{\\sigma_X}\\right) ) \\nonumber\\\\\n&= \\Phi\\left( \\sqrt{\\frac{\\pi}{8}}\\sigma\\left( t-\\frac{\\ln(B)}{\\sigma_X}\\right) \\right) \n\\end{align}\nTherefore:\n\\begin{align}\n&\\mathbb{E}\\left[ \\frac{1}{BX+1} \\right] = \\int_{-\\infty}^{+\\infty} \\Phi\\left( \\sqrt{\\frac{\\pi}{8}}\\sigma_X\\left( t-\\frac{\\ln(B)}{\\sigma_X}\\right) \\right) \\phi\\left( t \\right) dt \\nonumber\\\\ \n&= Pr \\left\\lbrace X_1 \\leq \\sqrt{\\frac{\\pi}{8}}\\sigma_X\\left( X_2-\\frac{\\ln(B)}{\\sigma}\\right) \\right\\rbrace \\nonumber\\\\\n&= Pr \\left\\lbrace X_1 - \\sqrt{\\frac{\\pi}{8}}\\sigma_X X_2 \\leq -\\frac{\\ln(B)}{2} \\sqrt{\\frac{\\pi}{2}} \\right\\rbrace \n\\end{align}\nwhere $X_1, X_2$ are independent standard normal random variable. Obviously, $X_1 - \\sqrt{\\frac{\\pi}{8}}\\sigma_X X_2 \\sim \\mathcal{N}\\left( 0,  1+ \\frac{\\pi}{8}\\sigma_X^2\\right) $. Hence,\n\\begin{align}\n\\label{eq:mean_bx+1_step2}\n\\mathbb{E}\\left[ \\frac{1}{BX+1} \\right] &= Pr \\left\\lbrace \\frac{X_1 - \\sqrt{\\frac{\\pi}{8}}\\sigma_X X_2}{\\sqrt{1+ \\frac{\\pi}{8}\\sigma_X^2}} \\leq -\\frac{\\ln(B)}{\\sqrt{\\frac{8}{\\pi}+ \\sigma_X^2}}\\right\\rbrace  \\nonumber\\\\\n&= \\Phi\\left( -\\left( \\frac{8}{\\pi}+ \\sigma_X^2\\right) ^{-\\frac{1}{2}}\\ln(B) \\right) \\nonumber\\\\\n&= \\frac{1}{2} + \\frac{1}{2} \\erf \\left\\lbrace -\\left( \\frac{16}{\\pi}+ 2\\sigma_X^2\\right) ^{-\\frac{1}{2}}\\ln(B)\\right\\rbrace \n\\end{align}\nStill, applying $(\\ref{eq:logistical_erf_fun_appro})$ for $(\\ref{eq:mean_bx+1_step2})$, we have:\n% 实际上此图可以删除\n%\\begin{figure}\n%\t\\centering\n%\t\\includegraphics[width=0.7\\linewidth]{Figures/erf_approx}\n%\t\\caption{The approximation of the logistic function by error function. The absolute difference between the two functions is always less than 0.02.}\n%\t\\label{fig:erf_approx}\n%\\end{figure}\n\\begin{align}\n\\label{eq:analytical_result_approach_2}\nP_{f2} &= 1 - \\frac{1}{1 + \\exp\\left\\lbrace \\left( 1 +\\frac{\\pi \\sigma_X^2}{8} \\right)^{-\\frac{1}{2}} \\ln(B) \\right\\rbrace} \\nonumber\\\\\n&= 1-\\frac{1}{1 + B^{\\left( 1 +\\frac{\\pi \\sigma_X^2}{8} \\right)^{-\\frac{1}{2}}}},\n\\end{align}\nwhere $B= \\frac{p\\lambda_m}{\\lambda_b}\\Gamma(1+\\frac{2}{\\gamma}) \\Gamma(1-\\frac{2}{\\gamma}) \\exp \\left( \\frac{\\sqrt{2}\\beta\\sigma}{\\gamma}\\right) ^2 \\theta^{\\frac{2}{\\gamma}}$.", "meta": {"hexsha": "62576c7102098e765e5f329839e9a6d429bddcd7", "size": 13430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter5/bs_rx_divers_annexe.tex", "max_stars_repo_name": "hansomesong/PhD-Thesis", "max_stars_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_stars_repo_licenses": ["MIT"], "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/bs_rx_divers_annexe.tex", "max_issues_repo_name": "hansomesong/PhD-Thesis", "max_issues_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_issues_repo_licenses": ["MIT"], "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/bs_rx_divers_annexe.tex", "max_forks_repo_name": "hansomesong/PhD-Thesis", "max_forks_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_forks_repo_licenses": ["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.8757062147, "max_line_length": 400, "alphanum_fraction": 0.6591213701, "num_tokens": 5281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6177785872518538}}
{"text": "\\section{Results}\n\\subsection{Simplices}\nThe first set of topological statistics we look at are the simplices. These statistics describe the local connectivity of a random graph. The higher the dimension of a simplex and the more simplices observed in each dimension, the more complex the structure becomes. The higher the dimension of the simplex, the more ordered this structure becomes.\n\nBeginning with the Bio-M MC, we observe large numbers of simplices across the dimensions that went as high as dimension 6. In dimensions 2 and 3, we see simplices of almost as many as 80 and 70 million respectively.\n\nThe first model of comparison is the \\ER model. This model is able to match the simplicial counts of the Bio-M MC in the $0^{th}$ and $1^{st}$ dimensions, however, with a lack of order applied to the model, the complexity and ordered structure diminishes, the higher the simplicial dimension we attain.\n\nThe second model, the General Biological model, as produced here \\cite{Reimann_2017}, again matches the Bio-M MC in the $0^{th}$ and $1^{st}$ dimension. The number of $2^{nd}$ dimensional simplices observed here is somewhat larger than what has been produced by the \\ER model. There are approximately 35 million 2-dimensional simplices and just below 10 million 3-dimensional simplices. These two dimensions in particular are a focus point for which to be able to compare the four models proposed here.\n\nThe Configuration model, like all subsequent models, produced precisely the same number of $0^{th}$ and $1^{st}$ dimensional simplices as that of the \\ER model and the General Biological model, since these describe a single vertex and a directed edge joining two vertices as part of an ordered set respectively. The first difference occurs with the 2-dimensional simplices. Of the four proposed models, the Configuration model produced, consistently, the fewest 2-dimensional simplices. We observed approximately 33.5 million each time, 3 million fewer than the General Biological model. There is almost the same difference in the number of simplices between the Configuration model and the General Biological model for simplices in the $3^{rd}$ dimension compared to the $2^{nd}$ dimension.\n\nApplying the geometric constraint in the Geometric Configuration model saw an improvement in matching the complexity of the Bio-M MC for 2-dimensional and higher simplices when compared to the Configuration model and the General Biological model. This refinement in the model, allowed for the biggest jump in accuracy between models, showing as many as 5 million more 2-dimensional simplices than the Configuration model, and almost 3 million more in the $3^{rd}$ dimension.\n\nThe next model, the Block Configuration model saw the application of a biological constraint. This constraint is the layer to layer interactions of the neurons. By applying this layer to layer constraint, we were able to further improve the model's likeness to the Bio-M MC. This model observed as many as 41 million 2-dimensional simplices and 8.5 million 3-dimensional simplices. This is an improvement in both dimensions from the Geometric Configuration model.\n\nThe Block Geometric Configuration model produced a similar number of 2- and 3-dimensional simplices as the Block Configuration model. So, there was no significant improvement to the numbers in these dimensions. However, this model did produce some more complex simplicial structures. We observed simplices in dimensions as high as the $6^{th}$, matching that of the Bio-M MC, just not as numerous.\n\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[height=8cm,width=12cm]{graph/simplices_zoomed.png}\n\\caption{Simplicial Comparisons}\n\\end{center}\n\\end{figure}\n\n\n\n\\subsection{Betti Numbers and Euler Characteristic}\nWe want to compare the global connectivity of each model. We do this with Betti Numbers. In particular, we want to compare this connectivity in the highest dimension for which each model observes a non-zero Betti Number. This occurs in dimension 3. We have below, a set of results for 100 realisations of each model to give ourselves a statistical range to work with.\n\nIn figures 40-42, we have individual box-plots for each model, followed by a box-plot with all the models side by side. The reason behind this can be observed with the scales used in each individual box-plot. We begin with the \\ER model observing anywhere between 0 and 10 $3^{rd}$ dimensional Betti Numbers, all the way up to the Geometric model observing approximately $30,000$. Given that Betti Numbers is a count for the organisation of the structure of the graph, we can see that with a geometric constraint applied to the network, this enables the MC to maintain a lot more ordered structure than without this constraint. This appears more apparent between the Configuration model and the Geometric Configuration model than the respective Block models. This would suggest that the bigger the volume, the more important a geometric constraint is when simulating the connectivity of neurons.\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering \\ER Model]{{\\includegraphics[width=7cm]{graph/betti3_er.png} }}%\n    \\qquad\n    \\subfloat[\\centering Configuration Model]{{\\includegraphics[width=7cm]{graph/betti3_conf.png} }}%\n    \\caption{Box-plots of Betti Numbers observed in the $3^{rd}$ dimension for the models}%\n    \\label{fig:example}%\n\\end{figure}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Geometric Configuration Model]{{\\includegraphics[width=7cm]{graph/betti3_geo.png} }}%\n    \\qquad\n    \\subfloat[\\centering Block Configuration Model]{{\\includegraphics[width=7cm]{graph/betti3_block_conf.png} }}%\n    \\caption{Box-plots of Betti Numbers observed in the $3^{rd}$ dimension for the models}%\n    \\label{fig:example}%\n\\end{figure}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Block Geometric Configuration Model]{{\\includegraphics[width=7cm]{graph/betti3_block_geo.png} }}%\n    \\qquad\n    \\subfloat[\\centering All Models]{{\\includegraphics[width=7cm]{graph/all_betti.png} }}%\n    \\caption{Box-plots of Betti Numbers observed in the $3^{rd}$ dimension for the models}%\n    \\label{fig:example}%\n\\end{figure}\n\n\nWe also compare the $3^{rd}$ Betti Number with the Euler Characteristic for our 4 models. We can see that they cluster together within each model with a larger variation in the Betti Number. The block models observed similar values with respect to one another, especially in comparison to the other two models. The size of the graph can clearly give large differences in their clustered values as we see from the Configuration and Geometric Configuration models.\n\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[width=12cm]{graph/bVe.png}\n\\caption{Betti number in dimension 3 against Euler characteristic}\n\\end{center}\n\\end{figure}\n\n\\subsection{Total Variation distance: Distance Distribution}\nOne of the statistics we mention in Section 2, Mathematical Preliminaries, is the Total Variation (TV) distance. We use this statistic to give us a measure of how well one model may fit to that of the Bio-M MC in various statistical measures. However, here, we use it to check the fit of distance distributions and in the next subsection, how well the Block-wise Edge densities fit for each model.\n\nSo, we ran 100 realisations of each model with the intent to see how well the distributions of each model fit the distribution of the Bio-M MC. Below, after 100 realisations of each model, we have a table of the mean of each distribution.\n\nWe can see that the models observed a wide range of TV distances in relation to one another, with the \\ER model being the weakest and the GB model being the strongest. As mentioned in their respective sections, the BC model and the BGC model observe remarkably similar TV distances when comparing to the Bio-M MC. The spread of values for each respective model, was rather small, suggesting some consistency in the way the models reconnect the neurons in the MC.\n\\begin{center}\n \\begin{tabular}{| c | c |}\n \\hline\n \\textbf{Model} & \\textbf{Mean Total Variation distance}  \\\\ [0.5ex]\n \\hline\n \\ER &  0.7092   \\\\\n \\hline\n Configuration & 0.6595    \\\\\n \\hline\n Geometric Configuration & 0.3169   \\\\\n \\hline\n Block Configuration & 0.3939   \\\\\n \\hline\n Block Geometric Configuration & 0.3937 \\\\\n \\hline\n General Biological & 1.5341e-08  \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering \\ER Model ]{{\\includegraphics[width=7cm]{results_imgs/erModel.png} }}%\n    \\qquad\n    \\subfloat[\\centering Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/cModel.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Geometric Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/gcModel.png} }}%\n    \\qquad\n    \\subfloat[\\centering Block Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/bcModel.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Block Geometric Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/bgcModel.png} }}%\n    \\qquad\n    \\subfloat[\\centering General Biological Model]{{\\includegraphics[width=7cm]{results_imgs/gbModel.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\nA note on the General Biological model from what we see in Figure 46(b) is that over the 100 realisations we obtained a TV distance greater than zero for one realisation. Given that this occurred only once and that the difference is insignificant, we do not concern ourselves with this.\n\n\\subsection{Total Variation distance: Block-wise Edge Densities}\nHere, we compare the Block-wise Edge densities between each model and the Bio-M MC. As we mentioned previously, there were 100 realisations of each model and each were compared to the Bio-M MC. To begin comparison, we compare each block and then sum over all blocks to ascertain the TV distance of each model to the Bio-M MC and where relevant, we then give a breakdown of TV distances, block by block.\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering \\ER Model]{{\\includegraphics[width=7cm]{results_imgs/er_block_var.png} }}%\n    \\qquad\n    \\subfloat[\\centering Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/conf1_overall.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\nFigure 47 shows us the \\ER model and the Configuration model. Both models show a similar range of values, however, the range of values given by the Configuration model is closer to that of the Bio-M MC. This 0.12 improvement between models is somewhat significant, highlighting the importance to maintain the in-degrees and out-degrees of the respective neurons in an already observed MC.\n\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Geometric Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/gc1_overall.png} }}%\n    \\qquad\n    \\subfloat[\\centering Block Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/bc_block_var.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\n\nFigure 48(a) highlights further the importance of a geometric constraint applied to the MC. The improvement of Block-wise Edge densities almost doubles from the Configuration model. Furthermore, we have no outliers in our range of values, showing that the model can statistically be more consistent with the Bio-M MC. The Block Configuration model exhibits no differences to the Bio-M MC as is the case for the BGC model and the GB model. This is since they rearrange connections within the layer by layer blocks or subsets of these (morphological blocks).\n\\begin{figure}[H]%\n    \\centering\n    \\captionsetup{justification=centering}\n    \\subfloat[\\centering Block Geometric Configuration Model]{{\\includegraphics[width=7cm]{results_imgs/bgc_block_var.png} }}%\n    \\qquad\n    \\subfloat[\\centering General Biological Model]{{\\includegraphics[width=7cm]{results_imgs/GB_block_var.png} }}%\n    \\caption{Box-plots of observed total distance variation from each model to the Bio-M MC}%\n    \\label{fig:example}%\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[width=12cm]{results_imgs/er_bed.png}\n\\caption{Block-wise Edge Density Total Variation Distance Block by Block: \\ER Model}\n\\end{center}\n\\end{figure}\nThe \\ER model gives a range of TV distances for each block. The biggest occurring in L6 to L6. The smallest sets of values occur in the blocks that relate to Layer 1, whether it be the pre-synaptic set of neurons or the post-synaptic set of neurons.\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[width=12cm]{results_imgs/conf_bed.png}\n\\caption{Block-wise Edge Density Total Variation Distance Block by Block: Configuration Model}\n\\end{center}\n\\end{figure}\nNow, likewise with the \\ER model, the Configuration Model observes the largest set of TV distances from L6-L6 and similarly much smaller values for L1, whether it be from pre-synaptic neurons or to post-synaptic neurons, the TV distance values here are just a lot smaller.\n\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[width=12cm]{results_imgs/gc_bed.png}\n\\caption{Block-wise Edge Density Total Variation Distance Block by Block: Geometric Configuration Model}\n\\end{center}\n\\end{figure}\nAs mentioned for the \\ER model and the Configuration model, the smallest differences occur in relation to neurons in Layer 1 for the GC model. However, we note here that in fact, there is a large improvement to the difference in respect of the L6-L6 connections, where we only see a mean TV distance of approximately 0.025, a large improvement on the previous two models, highlighting the strength of the geometric constraint.\n\n\n\\subsection{Timings}\n\\begin{figure}[H]\n\\begin{center}\n\\captionsetup{justification=centering}\n\\includegraphics[width=12cm]{graph/timings.png}\n\\caption{Computation times for the random graphs}\n\\end{center}\n\\end{figure}\n\n\\begin{center}\n \\begin{tabular}{| c | c | c | c |}\n \\hline\n \\textbf{Model} & \\textbf{Min(s)} & \\textbf{Mean(s)} & \\textbf{Max(s)} \\\\ [0.5ex]\n \\hline\n \\ER & 5 & 5    & 5    \\\\\n \\hline\n Configuration &  49.78 & 50.63  & 51.75   \\\\\n \\hline\n Geometric Configuration & 854.87\n & 870.93 &  901.63   \\\\\n \\hline\n Block Configuration & 34.77 & 34.01 & 35.55   \\\\\n \\hline\n Block Geometric Configuration & 94.77\n  & 97.55 & 99.89 \\\\\n \\hline\n General Biological & 420  & 426     & 432   \\\\\n \\hline\n\\end{tabular}\n\\end{center}\nFinally, we have our timings for the models. All of these were computed on the same machine, of which the details are listed below. However, there were slight differences in the methods between my models and that of the General Biological model and Bio-M MC. The General Biological model and Bio-M MC were computed first by converting the file formats from H5 to CSV and then converted to an NPY array, whereas my models just simply needed to take the saved NPY array.\n\nA note on the geometrically constrained models is that they had a similar computation time up until approximately 80$\\%$ completion and then slowed down significantly in order to connect the remaining vertices. Therefore the remaining 20$\\%$ of connections took the majority of time to compute.\n\\newpage\n\\begin{lstlisting}[language=bash]\nArchitecture:                    x86_64\nCPU op-mode(s):                  32-bit, 64-bit\nByte Order:                      Little Endian\nAddress sizes:                   43 bits physical, 48 bits virtual\nCPU(s):                          12\nOn-line CPU(s) list:             0-11\nThread(s) per core:              2\nCore(s) per socket:              6\nSocket(s):                       1\nNUMA node(s):                    1\nVendor ID:                       AuthenticAMD\nCPU family:                      23\nModel:                           113\nModel name:                      AMD Ryzen 5 3600 6-Core Processor\nStepping:                        0\nFrequency boost:                 enabled\nCPU MHz:                         2199.811\nCPU max MHz:                     3600,0000\nCPU min MHz:                     2200,0000\nBogoMIPS:                        7199.87\nVirtualization:                  AMD-V\nL1d cache:                       192 KiB\nL1i cache:                       192 KiB\nL2 cache:                        3 MiB\nL3 cache:                        32 MiB\nNUMA node0 CPU(s):               0-11\n\\end{lstlisting}\n\n\n\n\n\n", "meta": {"hexsha": "28afe1ec40238239eb7c4c7481be068a824634de", "size": 17320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2020UUMScKieranBarber/tex_files/results.tex", "max_stars_repo_name": "lamastex/topologicalDataAnalysisOnABrainNetwork", "max_stars_repo_head_hexsha": "05ca6b5f1751147164354b188d098f0b37f461dc", "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": "2020UUMScKieranBarber/tex_files/results.tex", "max_issues_repo_name": "lamastex/topologicalDataAnalysisOnABrainNetwork", "max_issues_repo_head_hexsha": "05ca6b5f1751147164354b188d098f0b37f461dc", "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": "2020UUMScKieranBarber/tex_files/results.tex", "max_forks_repo_name": "lamastex/topologicalDataAnalysisOnABrainNetwork", "max_forks_repo_head_hexsha": "05ca6b5f1751147164354b188d098f0b37f461dc", "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": 66.106870229, "max_line_length": 895, "alphanum_fraction": 0.7495381062, "num_tokens": 4204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6177785866084613}}
{"text": "\\section{Group theory}\\label{sec:group_theory}\n\nModern algebra takes its roots in abstracting \\hyperref[def:set_of_integers]{integers} and \\hyperref[def:set_of_real_numbers]{real numbers} and their addition and multiplication. Both of these operations are \\hyperref[def:magma/commutative]{commutative} and, if we want to generalize their properties, it is sensible to study commutative operations.\n\nAnother type of objects that usually fits in the same algebraic framework are \\hyperref[def:function]{functions} and their \\hyperref[def:multi_valued_function/composition]{composition}. Functions from a set to itself can be composed to form another function of the same type, similarly to how two integers can be added to obtain another integer. The main difference is in the non-commutativity of function composition.\n\nThis suggests that we use the same algebraic structures to study both generalizations of numbers and generalizations of functions over a set. The first case is commutative, the second is not. This is why commutative and non-commutative structures, even though they are similarly defined, can have very different properties and applications.\n\nWe shall not attempt to give a precise definition for an \\term{algebraic structure}. There are very general frameworks for doing so, however their complexity is unjustified for us. We will instead build standard algebraic structures from \\enquote{base building blocks}, although we will utilize very general definitions like categorical kernels and images defined in \\fullref{def:zero_morphisms}.\n\nThe simplest algebraic structures that will be of interest to us are \\hyperref[def:group]{groups} and their less well-behaved generalizations, \\hyperref[def:magma/associative]{semigroups} and \\hyperref[def:unital_magma/monoid]{monoids}.\n\nExcept as a building block for more complicated algebraic structures, groups arise whenever some mathematical structure exhibits symmetries, and this concept is formalized via \\hyperref[def:automorphism_group]{automorphism groups} and \\hyperref[def:left_group_action]{group actions}. If, instead of symmetries we have non-invertible but nonetheless well-behaved transformations, we can instead study \\hyperref[def:endomorphism_monoid]{endomorphism monoids} and \\hyperref[def:left_monoid_action]{monoid actions}.\n", "meta": {"hexsha": "780d464370cc553c2e078b09dec8eee35b6273ca", "size": 2309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/group_theory.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/group_theory.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/group_theory.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": 164.9285714286, "max_line_length": 511, "alphanum_fraction": 0.8263317453, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6177785804482568}}
{"text": "\\documentclass[letterpaper, twoside, 12pt]{book}\n\\usepackage{packet}\n\n\n\\begin{document}\n\n\\setcounter{chapter}{3}\n\n\\chapter{Packet 4.2: Sections 16.5-16.9}\n\n\\setcounter{chapter}{16}\n\\setcounter{section}{4}\n\n\\section{Curl and Divergence} %16.5\n\n\\begin{definition}\n  The \\textbf{curl} of a vector field $\\vect F=\\<P,Q,R\\>$\n  is given by the expression\n  \\[\n    \\text{curl }\\vect{F}\n      =\n    \\nabla \\times \\vect{F}\n      =\n    \\left\\<\n      \\frac{\\partial}{\\partial x},\n      \\frac{\\partial}{\\partial y},\n      \\frac{\\partial}{\\partial z}\n    \\right\\>\n      \\times\n    \\<P,Q,R\\>\n      =\n    \\<R_y-Q_z,P_z-R_x,Q_x-P_y\\>\n  \\]\n\\end{definition}\n\n          \\begin{problem}\n            Prove that if $\\vect{F}$ is conservative, then\n            $\\text{curl }\\vect{F}=\\vect{0}$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{remark}\n  For a vector field $\\vect{F}$ and direction $\\vect{u}$,\n  $(\\text{curl }\\vect{F})\\cdot\\vect{u}$ may be thought of as\n  the tendency of $\\vect{F}$ to ``spin'' counter-clockwise\n  around $\\vect{u}$.\n\\end{remark}\n\n          \\begin{problem}\n            Compute the curl of $\\<x+y,z^2-3,yz\\>$ around the point\n            $(2,0,-1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{theorem}\n  Green's Theorem may be rewritten in terms of curl as follows:\n  \\[\n    \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n      =\n    \\iint_R (\\text{curl }\\vect{F}) \\cdot \\veck \\dvar{A}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove the previous theorem.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{definition}\n  The \\textbf{divergence} of a vector field $\\vect F=\\<P,Q,R\\>$\n  is given by the expression\n  \\[\n    \\text{div }\\vect{F}\n      =\n    \\nabla \\cdot \\vect{F}\n      =\n    \\left\\<\n      \\frac{\\partial}{\\partial x},\n      \\frac{\\partial}{\\partial y},\n      \\frac{\\partial}{\\partial z}\n    \\right\\>\n      \\cdot\n    \\<P,Q,R\\>\n      =\n    P_x+Q_y+R_z\n  \\]\n\\end{definition}\n\n          \\begin{problem}\n            Prove that the divergence of a curl vector field\n            is always $0$. Put another way, show that\n            $\\text{div }(\\text{curl }\\vect{F})=0$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{remark}\n  Divergence measures the tendency of a vector field to diverge away\n  from a point.\n\\end{remark}\n\n          \\begin{problem}\n            Compute the divergence of $\\<x+y,z^2-3,yz\\>$ away from the point\n            $(2,0,-1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{definition}\n  The \\textbf{flux} of a velocity vector field $\\vect{F}$ across a closed\n  curve $C$ is given by\n  \\[\n    \\int_C \\vect{F}\\cdot\\vect{n}\\dvar{s}\n  \\]\n  where $\\vect n$ yields outward unit normal vectors to $C$.\n\\end{definition}\n\n\\begin{remark}\n  Flux measures the tendency of a vector field to flow outward from\n  a closed and bounded region (or inward if the flux is negative).\n\\end{remark}\n\n\\begin{theorem}\n  Green's Theorem may be rewritten in terms of divergence as follows:\n  \\[\n    \\int_C \\vect{F}\\cdot\\vect{n}\\dvar{s}\n      =\n    \\iint_R \\text{div }\\vect{F} \\dvar{A}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Compute the flux of the velocity vector field\n            $\\<x+y,x^2+y^2\\>$ across the boundary of the unit square.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\section{Parametric Surfaces} %16.6\n\n\\begin{remark}\n  Just like a curve may be parameterized by $\\vect{r}(t)$\n  for an interval $a\\leq t\\leq b$, a surface may be parameterized by\n  $\\vect{r}(u,v)$ for a region $R$ in the $uv$ plane.\n\\end{remark}\n\n\\begin{theorem}\n  Following are some common surface parameterizations.\n  \\begin{itemize}\n    \\item The surface $z=f(x,y)$ may be parametrized by\n      \\[\n        \\vect{r}(x,y) = \\<x,y,f(x,y)\\>\n      \\]\n    \\item A surface determined by a cylindrical coordinate equation may\n    be parametrized by substituting into\n      \\[\n        \\vect{r} = \\<r\\cos\\theta, r\\sin\\theta, z\\>\n      \\]\n    \\item A surface determined by a spherical coordinate equation may\n    be parametrized by substituting into\n      \\[\n        \\vect{r} =\n        \\<\\rho\\sin\\phi\\cos\\theta,\n        \\rho\\sin\\phi\\sin\\theta,\n        \\rho\\cos\\phi \\>\n      \\]\n  \\end{itemize}\n\\end{theorem}\n\n          \\begin{problem}\n            Find a parameterization from the $xy$ plane to the\n            plane $2x-y+z=7$ in $xyz$ space.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Find the parameterization from the rectangle $0\\leq z\\leq 3$\n            and $0\\leq\\theta\\leq2\\pi$ to the conical surface $z=\\sqrt{x^2+y^2}$\n            below the plane $z=3$ in $xyz$ space. (Hint: find the cylindrical\n            coordinate equation for the surface.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Find the parameterization from the rectangle $0\\leq\\phi\\leq\\pi$\n            and $0\\leq\\theta\\leq2\\pi$ to the spherical surface\n            $x^2+y^2+z^2=9$ in $xyz$ space. (Hint: find the spherical\n            coordinate equation for the surface.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{Surface Integrals} %16.7\n\n\\begin{definition}\n  The \\textbf{surface integral} of a function $f(x,y,z)$ over a surface\n  $S$ in $xyz$ space is given by\n  \\[\n    \\iint_S f(\\vect{r})\\dvar{\\sigma}\n      =\n    \\iint_R f(\\vect{r}(u,v))|\\vect{r}_u\\times\\vect{r}_v|\\dvar{A}\n  \\]\n  where $\\vect{r}(u,v)$ is a parameterization from the region $R$ in\n  the $uv$ plane to the surface $S$.\n\\end{definition}\n\n\\begin{theorem}\n  The surface area of $S$ is given by\n  \\[\n    \\iint_S \\dvar{\\sigma} = \\iint_S 1\\dvar{\\sigma}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Use the parameterization\n            \\[\n              \\vect{r}(\\phi,\\theta)\n                =\n              \\<\n                \\sin\\phi\\cos\\theta,\n                \\sin\\phi\\sin\\theta,\n                \\cos\\phi\n              \\>\n            \\]\n            from $0\\leq\\phi\\leq\\pi,0\\leq\\theta\\leq2\\pi$ to the unit\n            sphere to show that the surface area of the unit sphere\n            is $4\\pi$. (Note that this matches the formula $SA=4\\pi r^2$ used\n            in high school geometry.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n          \\begin{problem}\n            Show that the area of the parallelogram with vertices $(0,0,0)$,\n            $(2,1,2)$, $(0,2,-1)$, and $(2,3,1)$ is $3\\sqrt{5}$ using a surface\n            integral.\n            (Hint: use $\\vect{r}(u,v)=\\<2u,u+2v,2u-v\\>$.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\begin{definition}\n  An \\textbf{orientation} of a surface is a continuous unit\n  vector field normal to the surface.\n\\end{definition}\n\n\\begin{remark}\n  Orienting a surface is akin to choosing one side or another of the surface.\n\\end{remark}\n\n\\begin{remark}\n  Examples of non-orientable surfaces are the Mobi\\\"us strip and Klein bottle.\n\\end{remark}\n\n\\begin{definition}\n  The \\textbf{surface integral} of a vector field $\\vect{F}$ over an\n  oriented surface $S$ in $xyz$ space is given by\n  \\[\n    \\iint_S \\vect{F}\\cdot\\dvar{\\vect\\sigma}\n      =\n    \\iint_S \\vect{F}\\cdot\\vect{n}\\dvar\\sigma\n      =\n    \\iint_R \\vect{F}\\cdot(\\vect{r}_u\\times\\vect{r}_v)\\dvar{A}\n  \\]\n  where $\\vect n$ is the orientation of the surface and giving\n  its orientation, and\n  $\\vect{r}(u,v)$ is an appropriate parameterization from the region $R$ in\n  the $uv$ plane to the surface $S$.\n\\end{definition}\n\n\\begin{definition}\n  The \\textbf{flux} across a closed oriented surface (such as\n  the boundary of a solid) is given by\n  \\[\n    \\iint_S \\vect{F}\\cdot\\dvar{\\vect\\sigma}\n  \\]\n\\end{definition}\n\n          \\begin{problem}\n            Use the parameterization\n            \\[\n              \\vect{r}(\\phi,\\theta)\n                =\n              \\<\n                3\\sin\\phi\\cos\\theta,\n                3\\sin\\phi\\sin\\theta,\n                3\\cos\\phi\n              \\>\n            \\]\n            from $0\\leq\\phi\\leq\\pi,0\\leq\\theta\\leq2\\pi$ to the sphere\n            $x^2+y^2+z^2=9$ to prove that the flux across it for the\n            vector field $\\<x,y,z\\>$ is\n            \\[\n              \\int_0^{2\\pi}\\int_0^\\pi 27\\sin\\phi \\dvar{\\phi}\\dvar{\\theta}\n            \\]\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{Stokes' Theorem}%16.8\n\n\\begin{theorem}\n  Let $S$ be a surface with orientation $\\vect{n}$\n  and with boundary $C$ oriented counter-clockwise with respect to $\\vect{n}$.\n  Then\n  \\[\n    \\iint_S \\text{curl }\\vect{F}\\cdot\\dvar{\\vect\\sigma}\n      =\n    \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Let $S$ be the upper hemisphere $z=\\sqrt{1-x^2-y^2}$. Use\n            Stokes' Theorem to prove that\n            \\[\n              \\iint_S \\<2y,2z,2x\\>\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\int_0^{2\\pi} \\cos^3(t) \\dvar{t}\n            \\]\n            (Hint: what's the curl of $\\<z^2,x^2,y^2\\>$?).\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\section{Divergence Theorem}%16.8\n\n\\begin{theorem}\n  Let $S$ be the boundary of a solid $D$ oriented outwards.\n  Then\n  \\[\n    \\iint_S \\vect{F}\\cdot\\dvar{\\vect\\sigma}\n      =\n    \\iiint_D \\text{div }\\vect{F}\\dvar{V}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Let $S$ be the boundary of the unit cube in $xyz$ space.\n            Use the Divergence Theorem to prove that\n            \\[\n              \\iint_S \\<x+y,y^2+z^2,z^3+x^3\\>\\cdot\\dvar{\\vect\\sigma}\n                =\n              \\int_0^1\\int_0^1\\int_0^1 1+2y+3z^2 \\dvar{z}\\dvar{y}\\dvar{x}\n            \\]\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\\section{A small remark and puzzle}\n\n\\begin{remark}\n  Using derivatives, gradients, curl, and divergence, we may observe that\n  several kinds of integrals may be evaluated by observing how the\n  integrand behaves on the boundary of the domain of integration, and\n  vice versa.\n  \\[\n    \\int_{[a,b]} f'(x)\\dvar{x} = [f(x)]_a^b\n  \\]\n  \\[\n    \\int_C \\nabla f\\cdot \\dvar{\\vect r} = [f(P)]_A^B\n  \\]\n  \\[\n    \\iint_R \\text{div }\\vect{F} \\dvar{A}\n      =\n    \\int_C \\vect{F}\\cdot\\vect{n}\\dvar{s}\n  \\]\n  \\[\n    \\iint_R Q_x-P_y \\dvar{A}\n      =\n    \\int_C \\<P,Q\\>\\cdot\\dvar{\\vect r}\n  \\]\n  \\[\n    \\iint_S \\text{curl }\\vect{F}\\cdot\\dvar{\\vect\\sigma}\n      =\n    \\int_C \\vect{F}\\cdot\\dvar{\\vect{r}}\n  \\]\n  \\[\n    \\iiint_D \\text{div }\\vect{F}\\dvar{V}\n      =\n    \\iint_S \\vect{F}\\cdot\\dvar{\\vect\\sigma}\n  \\]\n\\end{remark}\n\n\\begin{problem}\n  (OPTIONAL)\n  This has nothing to do with the above remark, but here's a puzzle for\n  reading this far.\n\n  Wayne Brady is hosting a gameshow, and you've\n  been called down from the audience to attempt to win fabulous prizes.\n  Wayne gives you the choice of three doors: $A$, $B$, and $C$. He asks\n  you to choose a door, explaining that only one of the three doors holds\n  a prize behind it.\n\n  After you choose, Wayne opens one of the doors that you didn't choose to\n  reveal nothing behind it. He then offers you the opportunity to switch\n  your door with the other unopened door, after which you will immediately\n  be given whatever is behind it. Should you stick with your initial\n  guess, or should you switch, or does it even matter? Why?\n\\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{contributors}\n\n          \\end{contributors}\n\n\n\\end{document}", "meta": {"hexsha": "ffb76eecf6ad4eb75e818a7e80cb5f88f8df5834", "size": 12500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packet4_2.tex", "max_stars_repo_name": "StevenClontz/teaching-2015-spring", "max_stars_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packet4_2.tex", "max_issues_repo_name": "StevenClontz/teaching-2015-spring", "max_issues_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packet4_2.tex", "max_forks_repo_name": "StevenClontz/teaching-2015-spring", "max_forks_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_forks_repo_licenses": ["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.8015873016, "max_line_length": 79, "alphanum_fraction": 0.566, "num_tokens": 3766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185944046238981, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.6177495661417058}}
{"text": "\n\\subsection{Transition maps}\n\nWhere two charts overlap we can express the points where the charts overlap as two different coordinates.\n\nWe can express the mapping from these coordinates as a function. This is a transition map.\n\n\\subsubsection{Overlapping charts}\n\nIf two charts cover some of the same points on a manifold then we can define a function for those points where we move from one vector to another.\n\nWe can represent moving between charts as:\n\n\\(ab^{-1}\\)\n\n", "meta": {"hexsha": "57a67651df6bb2501b430de1c8c74c29ef91cef8", "size": 471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsTopological/01-02-transition.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/manifoldsTopological/01-02-transition.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/manifoldsTopological/01-02-transition.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.4375, "max_line_length": 146, "alphanum_fraction": 0.7855626327, "num_tokens": 95, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6177495557801425}}
{"text": "\\subsection{Damped Forced Vibrations ($b \\neq 0$)}\r\n\\noindent\r\nOur equation is \r\n\\begin{equation*}\r\n\tmy' + by' + ky = F_0\\cos{(\\gamma t)}\r\n\\end{equation*}\r\nDepending on if $\\Delta = b^2 - 4mk$ is positive, zero, or negative, we'll get different results and thus different guesses for $y_p$ and thus different solutions. There is, however, one long, complicated and not very useful for $y$.\r\n\\begin{equation*}\r\n\ty = C_1e^{\\frac{-b+\\sqrt{b^2-4mk}}{2m}t} + C_2e^{\\frac{-b-\\sqrt{b^2-4mk}}{2m}t} +\r\n\t \\frac{F_0\\left(b\\gamma\\sin{(\\gamma t)} + \\left(k-\\gamma^2m\\right)\\cos{(\\gamma t)}\\right)}{b^2\\gamma^2 + (k-\\gamma^2m)^2}\r\n\\end{equation*}\r\nThe one useful thing this formula does tell us is that assuming $m$, $b$, $k$, $F_0$, and $\\gamma$ are all positive and non-zero, the exponential terms quickly decrease to 0, so in the limit the function looks like the particular solution part.\r\n\r\n\\begin{center}\r\n\t\\includegraphics[width=0.75\\textwidth]{./higherOrder/forcedVibrs/damped_forced.png}\r\n\\end{center}\r\n\r\n\\ifodd\\includeHigherOrderExamples\\input{./higherOrder/forcedVibrs/dampedForcedVibrs_example.tex}\\fi", "meta": {"hexsha": "f4131a41b7e33055306cfd4f953d810811425b30", "size": 1100, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/forcedVibrs/dampedForcedVibrs.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/forcedVibrs/dampedForcedVibrs.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/forcedVibrs/dampedForcedVibrs.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": 61.1111111111, "max_line_length": 245, "alphanum_fraction": 0.7081818182, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6177495505993607}}
{"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\n\\section{Linear Magnetic Inversion}\\label{sec:forward magnetic}\nFor the magnetic inversion we use the anomaly of the magnetic flux\ndensity~\\index{magnetic flux density} of the Earth.\nThe controlling material parameter is the susceptibility~\\index{susceptibility}\n$k$ of the rock.\nWith magnetization $M$ and inducing magnetic field anomaly $H$, the magnetic\nflux density anomaly $B$ is given as\n\\begin{equation}\\label{ref:MAG:EQU:1}\nB_i = \\mu_0 \\cdot ( H_i  + M_i )\n\\end{equation}\nwhere $\\mu_0 = 4 \\pi \\cdot 10^{-7} \\frac{Vs}{Am}$.\nIn this forward model we make the simplifying assumption that the magnetization\nis proportional to the known geomagnetic flux density $B^b$:\n\\begin{equation}\\label{ref:MAG:EQU:4}\n\\mu_0  \\cdot M_i = k \\cdot B^b_i \\;. \n\\end{equation}\nValues for the magnetic flux density can be obtained by the International\nGeomagnetic Reference Field (IGRF)~\\cite{IGRF}\n(or the Australian Geomagnetic Reference Field (AGRF)~\\cite{AGRF}).\nIn most cases it is reasonable to assume that that the background field is\nconstant across the domain.\n\nThe magnetic field anomaly $H$ can be represented by the gradient of a\nmagnetic scalar potential\\index{scalar potential!magnetic} $\\psi$.\nWe use the form \n\\begin{equation}\\label{ref:MAG:EQU:6}\n\\mu_0  \\cdot H_i = - \\psi_{,i}\n\\end{equation}\nWith this notation one gets from Equations~(\\ref{ref:MAG:EQU:1}) and~(\\ref{ref:MAG:EQU:4}):\n\\begin{equation}\\label{ref:MAG:EQU:7}\nB_i = - \\psi_{,i}  + k \\cdot B^b_i\n\\end{equation}\nAs the $B$ magnetic flux density anomaly is divergence free ($B_{i,i}=0$) we obtain the PDE\n\\begin{equation}\\label{ref:MAG:EQU:8}\n- \\psi_{,ii} = - (k B^r_i)_{,i} \n\\end{equation} \nwith $B^r_i=B^b_i$ which needs to be solved for a given susceptibility $k$.\nThe magnetic scalar potential is set to zero at the top of the domain\n$\\Gamma_{0}$.\nOn all other faces the normal component of the magnetic flux density anomaly\n$B_i$ is set to zero, i.e. $n_i \\psi_{,i} = k \\cdot n_i  B^b_i$ with outer\nnormal field $n_i$.\n\nFrom the magnetic scalar potential we can calculate the magnetic flux density\nanomaly via Equation~(\\ref{ref:MAG:EQU:8}) to calculate the defect to the given\ndata.\nIf $B^{(s)}_i$ is a measurement of the magnetic flux density anomaly for\nsurvey $s$ and $\\omega^{(s)}_i$ is a weighting factor the data defect\n$J^{mag}(k)$ in the notation of Chapter~\\ref{chapter:ref:inversion cost function} is given as\n\\begin{equation}\\label{ref:MAG:EQU:9}\nJ^{mag}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\Omega} ( \\omega^{(s)}_i \\cdot (B_{i}- B^{(s)}_i) ) ^2 dx\n\\end{equation} \nSummation over $i$ is performed.\nThe cost function kernel\\index{cost function!kernel} is given as\n\\begin{equation}\\label{ref:MAG:EQU:10}\nK^{mag}(\\psi_{,i},k) = \\frac{1}{2}\\sum_{s} ( \\omega^{(s)}_i \\cdot (k \\cdot B^b_i - \\psi_{,i} - B^{(s)}_i) ) ^2\n\\end{equation} \nNotice that if magnetic flux density is measured in air one can ignore the\n$k\\cdot B^b_i$ as the susceptibility is zero.\n\nIn practice the magnetic flux density $b^{(s)}$ is measured along a certain\ndirection $d^{(s)}_i$ with a standard error deviation $\\sigma^{(s)}$ at\ncertain locations in the domain.\nIn this case one sets $B^{(s)}_i=b^{(s)} \\cdot d^{(s)}_i$ and the weighting\nfactors $\\omega^{(s)}$ as\n\\begin{equation}\\label{ref:MAG:EQU:11}\n\\omega^{(s)}_i \n= \\left\\{\n\\begin{array}{lcl}\nf \\cdot  \\frac{d^{(s)}_i}{\\sigma^{(s)}} & & \\mbox{data are available} \\\\\n& \\mbox{ where } & \\\\\n0 & & \\mbox{ otherwise } \\\\\n\\end{array}\n\\right.\n\\end{equation} \nwhere it is assumed that $d^{(s)}_i \\cdot d^{(s)}_i =1$. With the objective to control the \ngradient of the cost function the scaling factor $f$ is chosen in the way that \n\\begin{equation}\\label{ref:MAG:EQU:12}\n\\sum_{s} \\int_{\\Omega} ( \\omega^{(s)}_i B^{(s)}_i ) \n \\cdot ( \\omega^{(s)}_j \\frac{1}{L_j} ) \\cdot L^2 \\cdot\n( B^b_n \\frac{1}{L_n} )\n \\cdot k' \\;\n dx =\\alpha\n\\end{equation} \nwhere $\\alpha$ defines a scaling factor which is typically set to one and $L$ is defined by equation~(\\ref{ref:EQU:REG:6b}).\n$k'$ is considering the \nderivative of the density with respect to the level set function. \n\n\n\\subsection{Usage}\n\n\\begin{classdesc}{MagneticModel}{domain, w, B, background_field,\n        \\optional{, coordinates=\\None}\n        \\optional{, fixPotentialAtBottom=False},\n        \\optional{, tol=1e-8},\n}\nopens a magnetic forward model over the \\Domain \\member{domain} with \nweighting factors \\member{w} ($=\\omega^{(s)}$) and measured magnetic flux\ndensity anomalies \\member{B} ($=B^{(s)}$).\nThe weighting factors and the  measured magnetic flux density anomalies must be vectors.\n\\member{background_field} defines the background magnetic flux density $B^b$\nas a vector with north, east and vertical components. \n\\member{tol} sets the tolerance for the solution of the PDE~(\\ref{ref:MAG:EQU:8}).\nIf \\member{fixPotentialAtBottom} is set to  \\True, the magnetic potential \nat the bottom is set to zero in addition to the potential on the top. \n\\member{coordinates} set the reference coordinate system to be used. By the default the \nCartesian coordinate system is used.\n\\end{classdesc}\n\n\\begin{methoddesc}[MagneticModel]{rescaleWeights}{\n        \\optional{scale=1.}\n \\optional{k_scale=1.}}\nrescale the weighting factors such condition~(\\ref{ref:MAG:EQU:12}) holds where \n\\member{scale} sets the scale $\\alpha$\nand \\member{k_scale} sets $k'$. This method should be called before any inversion is started\nin order to make sure that all components of the cost function are appropriately scaled.\n\\end{methoddesc}\n\n\n\\subsection{Gradient Calculation}\nThis section briefly explains how the gradient\n$\\frac{\\partial J^{mag}}{\\partial k}$ of the cost function $J^{mag}$ with\nrespect to the susceptibility $k$ is calculated.  We follow the concept as outlined in section~\\ref{chapter:ref:inversion cost function:gradient}.\n\nThe magnetic potential $\\psi$ from PDE~(\\ref{ref:MAG:EQU:8}) is solved in weak form:\n\\begin{equation}\\label{ref:MAG:EQU:201}\n\\int_{\\Omega} q_{,i} \\psi_{,i} \\; dx  = \\int_{\\Omega}  k \\cdot q_{,i}  B^r_i \\; dx \n\\end{equation} \nfor all $q$ with $q=0$ on $\\Gamma_{0}$.\nIn the following we set $\\Psi[k]=\\psi$ for a given susceptibility $k$ as\nsolution of the variational problem~(\\ref{ref:MAG:EQU:201}).\nIf $\\Gamma_{k}$ denotes the region of the domain where the susceptibility is\nknown and for a given direction $p$ with $p=0$ on $\\Gamma_{k}$ one has\n\\begin{equation}\\label{ref:MAG:EQU:201aa}\n\\int_{\\Omega}   \\frac{\\partial J^{mag}}{\\partial k} \\cdot p \\; dx  = \\int_{\\Omega}  \n\\sum_{s} (\\omega^{(s)}_j \n( B^{(s)}_j-B_{j}))  \\cdot ( \\omega^{(s)}_i ( \\Psi[p]_{,i} - p  \\cdot B^b_i  ) ) \\; dx  \n\\end{equation} \nWith\n\\begin{equation}\\label{ref:MAG:EQU:202c}\nY_i[\\psi]=   \\sum_{s} (\\omega^{(s)}_j \n(B^{(s)}_j - B_{j}) )  \\cdot \\omega^{(s)}_i  \n\\end{equation} \nthis is written as \n\\begin{equation}\\label{ref:MAG:EQU:202cc}\n\\int_{\\Omega}   \\frac{\\partial J^{mag}}{\\partial k} \\cdot p \\;  dx  = \\int_{\\Omega}  \nY_i[\\psi] \\Psi[p]_{,i} - p \\cdot Y_i[\\psi]B^b_i   \\; dx  \n\\end{equation} \nWe then set adjoint function $Y^*[\\psi]$ as the solution of the equation \n\\begin{equation}\\label{ref:MAG:EQU:202d}\n\\int_{\\Omega} r_{,i} Y^*[\\psi]_{,i} \\; dx  =  \\int_{\\Omega} r_{,i} Y_i[\\psi]  \\; dx  \\mbox{ for all } r \\mbox{ with } r=0 \\mbox{ on } \\Gamma_{0}\n\\end{equation} \nwith $Y^*[\\psi]=0$ on $\\Gamma_{0}$. With $r=\\Psi[p]$ we get\n\\begin{equation}\\label{ref:MAG:EQU:202dd}\n\\int_{\\Omega} \\Psi[p]_{,i} Y^*[\\psi]_{,i} \\; dx  =  \\int_{\\Omega} \\Psi[p]_{,i} Y_i[\\psi]  \\; dx\n\\end{equation} \nand from Equation~(\\ref{ref:MAG:EQU:201}) with $q=Y^*[\\psi]$ we get\n\\begin{equation}\\label{ref:MAG:EQU:20e}\n\\int_{\\Omega} Y^*[\\psi]_{,i}  \\Psi[p]_{,i} \\; dx  = \\int_{\\Omega}  p \\cdot Y^*[\\psi]_{,i}  B^r_i \\; dx  \n\\end{equation}\nwhich leads to \n\\begin{equation}\\label{ref:MAG:EQU:20ee}\n\\int_{\\Omega} \\Psi[p]_{,i} ,Y_i[\\psi]  \\; dx  = \\int_{\\Omega}  p \\cdot Y^*[\\psi]_{,i}  B^r_i \\; dx  \n\\end{equation}\nand finally\n\\begin{equation}\\label{ref:MAG:EQU:201a}\n\\int_{\\Omega}   \\frac{\\partial J^{mag}}{\\partial k} \\cdot p \\;  dx  = \\int_{\\Omega}  \np \\cdot (Y^*[\\psi]_{,i}  B^r_i - Y_i[\\psi] B^b_i) \\; dx  \n\\end{equation} \nor \n\\begin{equation}\\label{ref:MAG:EQU:201b}\n\\frac{\\partial J^{mag}}{\\partial k} = Y^*[\\psi]_{,i}  B^r_i - Y_i[\\psi] B^b_i\n\\end{equation}\n\n\\subsection{Geodetic Coordinates}\nFor geodetic coordinates $(\\phi, \\lambda, h)$, see Chapter~\\ref{Chp:ref:coordinates}, the solution process needs to be slightly modified.\nObservations are recorded along the geodetic coordinates axes $\\alpha$ rather than the Cartesian axes $i$. In fact we\nhave in equation~\\ref{ref:MAG:EQU:9}:\n\\begin{equation}\\label{ref:MAG:EQU:300}\n\\omega^{(s)}_i \\cdot (B_{i}- B^{(s)}_i) = \\omega^{(s)}_{\\alpha} \\cdot (B_{{\\alpha}}- B^{(s)}_{\\alpha}) \n\\end{equation} \nwhere now $B^{(s)}_{\\alpha}$ are the observational data with weighting factors $\\omega^{(s)}_{\\alpha}$.  Using the \nfact that $B_{{\\alpha}} = k \\cdot B^b_{{\\alpha}} -d_{\\alpha \\alpha} \\psi_{,\\alpha}$ \nequation~\\ref{ref:MAG:EQU:10} translates to \n\\begin{equation}\\label{ref:MAG:EQU:301}\nJ^{mag}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n( \\omega^{(s)}_{\\alpha} \\cdot (d_{\\alpha \\alpha}  \\psi_{,\\alpha} - k \\cdot B^b_{{\\alpha}}  + B^{(s)}_{\\alpha} ) ) ^2 \\; v \\; d\\widehat{x}\n\\end{equation} \nwhere $\\widehat{\\Omega}$ and $d\\widehat{x}$ refer to integration over the geodetic coordinates axes. This can be rearranged to \n\\begin{equation}\\label{ref:MAG:EQU:301bb}\nJ^{mag}(k) = \\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n(  \\omega^{(s)}_{\\alpha} v^{\\frac{1}{2}} d_{\\alpha \\alpha} \\cdot ( \n \\psi_{,\\alpha} -  k \\cdot v_{\\alpha \\alpha} B^b_{{\\alpha}} + v_{\\alpha \\alpha} B^{(s)}_{\\alpha} ) ) ^2 \\; d\\widehat{x}\n=\\frac{1}{2}\\sum_{s} \\int_{\\widehat{\\Omega}} \n(  {\\widehat{\\omega}}^{(s)}_{\\alpha}\\cdot ( \\psi_{,\\alpha} -  k \\cdot \\widehat{B}^b_{{\\alpha}}+  \\widehat{B}^{(s)}_{\\alpha} ) ) ^2 \\; d\\widehat{x}\n\\end{equation} \nwith \n\\begin{equation}\\label{ref:MAG:EQU:301b}\n \\widehat{\\omega}^{(s)}_{\\alpha} = \\omega^{(s)}_{\\alpha} v^{\\frac{1}{2}} d_{\\alpha \\alpha} \\mbox{ , }\n\\widehat{B}^{(s)}_{\\alpha}=\n\\frac{1}{d_{\\alpha \\alpha}} B^{(s)}_{\\alpha}  \\mbox{ and } \\widehat{B}^b_{{\\alpha}} = \\frac{1}{d_{\\alpha \\alpha}}  B^b_{{\\alpha}} \n\\end{equation} \nwhich means one can apply the Cartesian formulation to the geodetic coordinates using modified data. \n\n\nThe magnetic potential is calculated from \n\\begin{equation}\\label{ref:MAG:EQU:302}\n\\int_{\\widehat{\\Omega}} v \\; d_{\\alpha \\alpha}^2 q_{,\\alpha} \\psi_{,\\alpha} \\;  d\\widehat{x}  \n=  \\int_{\\widehat{\\Omega}} v \\; d_{\\alpha \\alpha} k \\cdot q_{,\\alpha}  B^r_{\\alpha} \\; d\\widehat{x}   \n=  \\int_{\\widehat{\\Omega}}  k \\cdot q_{,\\alpha}  \\widehat{B}^r_{\\alpha} \\; d\\widehat{x}   \n\\end{equation} \nwith \n\\begin{equation}\\label{ref:MAG:EQU:302b}\n\\widehat{B}^r_{\\alpha}  =v \\; d_{\\alpha \\alpha} \\widehat{B}^r_{\\alpha}\n\\end{equation} \nsee equation~\\ref{ref:MAG:EQU:201}, and the adjoint function $Y^*[\\psi]$ for $Y_{\\alpha}[\\psi]$ is given from\n\\begin{equation}\\label{ref:MAG:EQU:303}\n\\int_{\\widehat{\\Omega}} v \\; d_{\\alpha \\alpha}^2 q_{,\\alpha} Y^*[\\psi]_{,\\alpha } \\;d\\widehat{x}  =\n\\int_{\\widehat{\\Omega}} r_{,{\\alpha}} ,Y_{\\alpha}[\\psi]  \\;d\\widehat{x}\n\\end{equation} \nand finally \n\\begin{equation}\\label{ref:MAG:EQU:310}\n\\frac{\\partial J^{mag}}{\\partial k} = Y^*[\\psi]_{,{\\alpha}}  B^r_{\\alpha} - Y_i[\\psi] B^b_{\\alpha}\n\\end{equation} \n\n", "meta": {"hexsha": "3072c72301df13cfce6ce465c7555a41ae1c5453", "size": 11837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/inversion/ForwardMagnetic.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/inversion/ForwardMagnetic.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/inversion/ForwardMagnetic.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": 48.9132231405, "max_line_length": 146, "alphanum_fraction": 0.6676522768, "num_tokens": 4203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961506, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6177495480022211}}
{"text": "\\chapter{Power Analysis by Simulation for Chapter \\ref{ga-lottery}}\\label{oa-power}\n\nThe purpose of a power analysis by simulation is to estimate $\\mathrm{Pr}(\\mathrm{Reject \\, H_0} | \\mathrm{H_0 \\, is \\, false})$ at a fixed significance level ($\\alpha =0.05$) and sample size ($N=21,732$) for different treatment effects $\\Delta_{1, \\ldots, j}$. In this case $N$ is the size of the observed sample of participants, excluding women and orphans. The simulation proceeds as follows:\n\n\\begin{enumerate}\n\t\\item Take a random sample of size $N$ without replacement from from the observed distribution of treatment assignments, weighted by the observed propensity score, to create a vector of simulated treatment assignments.\n\t\\item Simulate response values with $\\Delta_{j}$ as the difference-in-means between the simulated treated and control units. Generate random values from the binomial distribution with the probability of success on each trial equal to the mean of the response in the observed sample.\n\t\\item Run linear model on the simulated data and extract the $p$ value.\n\\end{enumerate}\n\nRepeat the simulation $\\mathcal{I}$ times and calculate power of the test by dividing the count of the number of $p$ values that are less than $\\alpha$ over $\\mathcal{I}$. Normally, 80\\% power is required to justify a study.  Fig. \\ref{power-plot-bin} provides the results of power analysis simulations for the officeholding response. ", "meta": {"hexsha": "f7adc5330f7f18bd0795825e34e3852ea22dfd97", "size": 1429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "a2-power.tex", "max_stars_repo_name": "jvpoulos/thesis", "max_stars_repo_head_hexsha": "15a691e8cb940ea427641155c7d69df3be152569", "max_stars_repo_licenses": ["MIT"], "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-power.tex", "max_issues_repo_name": "jvpoulos/thesis", "max_issues_repo_head_hexsha": "15a691e8cb940ea427641155c7d69df3be152569", "max_issues_repo_licenses": ["MIT"], "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-power.tex", "max_forks_repo_name": "jvpoulos/thesis", "max_forks_repo_head_hexsha": "15a691e8cb940ea427641155c7d69df3be152569", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 129.9090909091, "max_line_length": 395, "alphanum_fraction": 0.7732680196, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.6859494678483918, "lm_q1q2_score": 0.6177179312315744}}
{"text": "\\documentclass[11pt, oneside]{article} \n\\usepackage{amsmath}\n\\begin{document}\n\n\\section{Bogoliubov Tranformation for the Kondo Lattice}\n\nWe start from the Hamiltonian for the Kondo lattice\n\n$$ H = - \\sum_{i,\\sigma} t_{ij}c_{i\\sigma}^\\dagger c_{j\\sigma} + \nJ \\sum_r \\mathbf{S}_r\\cdot \\mathbf{s}_r +\n\\sum_{\\langle r, s \\rangle} I_{rs} \\mathbf{S}_r \\cdot \\mathbf{S}_s $$\n\nwhere $\\mathbf{S}_{i},\\mathbf{s}_{i}$ are the spin operators for the\nlocalized $f$-electrons and the itinerant $d$-electrons.\nNext, we use that\n\n$$ \\mathbf{S}_{r}=\\mathbf{S}_{r}^{f}+\\mathbf{S}_{r}^{b} $$\n\nrepresenting the fermionic and bosonic components of the spin. For the\nfermionic component, we use\n\n$$ \\mathbf{S}_{r}^{f} =\\frac{1}{2}\\sum_{\\alpha ,\\beta }f_{r,\\alpha }^{\\dagger\n}\\mathbf{\\sigma }_{\\alpha \\beta }f_{r,\\beta } $$\n\n$$ \\mathbf{s}_{r} =\\frac{1}{2}\\sum_{\\alpha ,\\beta }c_{r,\\alpha }^{\\dagger }\n\\mathbf{\\sigma }_{\\alpha \\beta }c_{r,\\beta } $$\n\nWe will assume that the bosonic part of the spins orders\nantiferromagnetically, and hence use the Holstein-Primakoff transformation\non the $A$ sublattice\n\n$$ S_{r}^{z} = S-a_{r}^{\\dagger }a_{r} $$\n$$ S_{r}^{+} = \\sqrt{2S}\\sqrt{1-\\frac{a_{r}^{\\dagger }a_{r}}{2S}}a_{r} $$\n$$ S_{r}^{-} = \\sqrt{2S}a_{r}^{\\dagger }\\sqrt{1-\\frac{a_{r}^{\\dagger }a_{r}}{2S}} $$\n\nand on the $B$ sublattice\n\n$$ S_{r}^{z} = -S+a_{r}^{\\dagger }a_{r} $$\n$$ S_{r}^{-} = \\sqrt{2S}a_{r}^{\\dagger }\\sqrt{1-\\frac{a_{r}^{\\dagger }a_{r}}{2S}} $$\n$$ S_{r}^{+} = \\sqrt{2S}\\sqrt{1-\\frac{a_{r}^{\\dagger }a_{r}}{2S}}a_{r} $$\n\n\n\nWe obtain\n\n$$ H_{MF}=\\sum_{k}\n\\left(\\begin{array}{cccc}\nc_{k,\\sigma }^{\\dagger } & f_{k,\\sigma }^{\\dagger } & c_{k+Q,\\sigma\n}^{\\dagger } & f_{k+Q,\\sigma }^{\\dagger }\n\\end{array} \\right) \n\\left( \\begin{array}{cccc}\n\\varepsilon _{k} & -V & U_{c} & 0 \\\\\n-V & \\chi _{k} & 0 & U_{f} \\\\\nU_{c} & 0 & \\varepsilon _{k+Q} & -V \\\\\n0 & U_{f} & -V & \\chi _{k+Q}\n\\end{array}\\right)\n\\left(\\begin{array}{c}\nc_{k,\\sigma } \\\\\nf_{k,\\sigma } \\\\\nc_{k+Q,\\sigma } \\\\\nf_{k+Q,\\sigma }\n\\end{array}\\right) $$\n\n$$ \\hat{H_k} = \n\\left( \\begin{array}{cccc}\n\\varepsilon _{k} & -V & U_{c} & 0 \\\\\n-V & \\chi _{k} & 0 & U_{f} \\\\\nU_{c} & 0 & \\varepsilon _{k+Q} & -V \\\\\n0 & U_{f} & -V & \\chi _{k+Q}\n\\end{array}\\right) $$\n\nWhere\n\n\\begin{eqnarray*}\n\\varepsilon_k &=& -2 \\cdot t (\\cos(k_x) + \\cos(k_y)) - \\mu \\\\\n\\chi_k &=& -2 \\cdot \\chi_0 (\\cos(k_x) + \\cos(k_y)) - \\varepsilon_f \\\\\nV &=& \\frac{J N}{4} \\sum_{q,\\alpha} \\langle f_{q\\alpha}^\\dagger c_{q\\alpha} \\rangle \\\\\nU_c &=& \\frac{J S}{2} sgn(\\sigma) \\\\\nU_f &=& \\frac{I S}{2} sgn(\\sigma)\n\\end{eqnarray*}\n\nThen the Green's function matrix is defined as\n$$ \\hat{G_R}(k,\\omega+i\\delta) = [(\\omega+i\\delta)\\hat{I} - \\hat{H_k}]^{-1} $$\nFrom which we calculate the QPI spectrum\n$$ g(q,\\omega)=\\int \\frac{d^2k}{(2 \\pi)^2}Im[ [\\hat{G_R}(k,\\omega)]_{11}[\\hat{G_R}(k+q,\\omega)]_{11}] $$\n\n\\end{document}  ", "meta": {"hexsha": "40145946adeb295191c1857d0cdee294cb8607cd", "size": 2821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "qpi.tex", "max_stars_repo_name": "slek120/susy_qpi", "max_stars_repo_head_hexsha": "245a00f252bd846b7ff71d7737fe5995c1fc45fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "qpi.tex", "max_issues_repo_name": "slek120/susy_qpi", "max_issues_repo_head_hexsha": "245a00f252bd846b7ff71d7737fe5995c1fc45fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "qpi.tex", "max_forks_repo_name": "slek120/susy_qpi", "max_forks_repo_head_hexsha": "245a00f252bd846b7ff71d7737fe5995c1fc45fc", "max_forks_repo_licenses": ["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.4252873563, "max_line_length": 104, "alphanum_fraction": 0.5898617512, "num_tokens": 1239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.6859494485880928, "lm_q1q2_score": 0.6177179102247219}}
{"text": "\\section{Analysis}\n\\label{analysis}\n\nIn this section, we assess the protocol's resistance to various attacks. We claim that in most cases, the protocol behaves no worse than a pure PoW network. \n\n\\subsection{Double-spend attack}\n\\label{double_spend_attack}\n\nThe \\textit{double-spend attack} is the well-known, but somewhat poorly named, ``51\\% attack'' \\cite{selfish_mining}. In the simplest version of this attack, a malicious agent sends some transaction to the network to reap an off-chain benefit (say she sells a large amount of her on-chain assets on an exchange), and then releases a side-chain in which that transaction never occurred. If this side-chain becomes the main-chain, she has \nexploited the network.\n\nLarge parts of the protocol were designed with the specific goal of frustrating this attack. The interleaving of PoW and PoS blocks serves to make this attack much harder to launch.\n\nWe model this attack by letting the average difficulty of PoW blocks on the chain be $d_w$, and the average difficulty of PoS blocks $d_s$. We let the attacker have $k$ times the hashpower and $l$ times the stake of the honest block producers on the network. Once the difficulty has adjusted on the attacker's side-chain, she will be producing PoW blocks of average difficulty $kd_w$, and PoS blocks of average difficulty $ld_s$. She should expect to win if her chain grows heavier \nthan the honest-chain in the long-run. Mathematically, this means she needs $$kd_w + ld_s > d_w + d_s$$\n\nWe can easily observe that if $k < 1$ and $l < 1$, the attacker is not expected to win, and if \\textit {both} $k>1$ and $l>1$, the attacker is always expected to win. Therefore, 51\\% of at least one\ndomain is necessary to expect to win, and 51\\% of both is sufficient to expect to win. \n\nThe intermediate case is when the attacker has a majority of one domain, but not the other. We let the attacker have $k>1$ and $l<1$ (the other case is symmetric). We can rewrite the winning condition as \n$$k > 1 + (1-l)\\frac{d_s}{d_w}$$\n\nNote that the difficulty values $d_w$ and $d_s$ are just indications of how hard it was to produce a block, and therefore can be controlled to some extent by the designers of a protocol. This gives us\nthe nice property that by manipulating these difficulty values, we can make the attack harder to launch in one direction than the other. On the OAN, for instance, we believe that it will be easier for attackers to acquire a majority of the hash power ($k > 1$) than a majority of the stake. Accordingly, we set the typical\n$d_s$ to be several orders of magnitude larger than $d_w$ (roughly $10^{14}$ times larger). The result is that an attacker with, say, 9/10ths the stake of the honest network still needs to have over $10^{10}$ times as much hash power as the honest work. The converse effect is that an attacker with a majority of the stake needs very little hash power to dominate the network, but we believe acquiring a majority of the stake to be infeasibly difficult.\n\n\\subsection{Nothing-at-Stake}\n\nThe  \\textit{Nothing-at-Stake} problem arises in pure PoS blockchains when stakers try to produce blocks on every branch they see \\cite{brown2018formal}. Since there is no cost to PoS block production, this is a profit-maximising strategy for PoS block forgers. This can lead to a fragile network with many branches and side-chains. \n\nOur protocol is not susceptible to this problem since the miners will resolve the branch; of several valid PoS blocks at the same level, whichever one has a PoW block built on top of it first will likely be included into the canonical chain.\n\n\\subsection{Stake Grinding}\n\nA PoS block producer is said to be \\textit{stake grinding} if, in the production of a block, they can somehow increase the chances that they produce the next block too \\cite{buterin_randomness}. In our protocol, the randomness that determines block production is entirely determined by the seed of the previous PoS block, and the private key of the block producer \\S\\ref{pos_block_generation}.\n\nAt every block an attacker will try to brute force compute an account that generates a lower delta for the next $k$ blocks, then attempt to transfer ownership of coins over to that account. The attack would proceed as follows: assume the attacker knows that they can produce block $n$. In the time that the attacker has before he has to announce his block ($\\Delta$), the attacker can select an account (via time-bounded brute-force search) which minimizes the $\\Delta$ for the next PoS block. The attacker then includes a transaction into block $n$ which transfers the attacker's stake to the selected account. When it's time to produce the next block, assuming the attacker has the smallest $\\Delta$ and is the block producer at this round as well, the attacker repeats this behavior as long as they can sustain this \\emph{streak} of discovering favorable accounts which yield small $\\Delta$s. \n\nNotice that this attack is made feasible by the instantaneous transfer of stake from one account to another. Therefore, if we enforce a lockout period (of $x$ blocks) before a staker is allowed to transfer stake to another account, the attacker must now win at-least $x+1$ blocks consecutively under the same account in order to successfully launch this attack. Therefore, the probability of success of the stake grinding attack can be reduced to the probability for an honest staker of winning $x+1$ blocks consecutively.\n\nLet $s_i$ denote the absolute stake controlled by the $i$th staker and let $p_i$ denote the probability that the next block is proposed by the $i$th staker. It is easy to see that for PoS blocks, the probability of winning the next block for an honest staker is denoted by: \n\n$$p_i=s_{i}/\\sum_i{s_i}$$\n\nAssuming that $\\sum_i{s_i}$ is constant for the next $x$ blocks, it follows that the $i$th staker's probability of winning $x+1$ blocks consecutively is denoted by\n\n\\begin{equation}\n    \\label{eq:attacker_success}\n    P(\\texttt{wining x consecutive blocks})=p_i^{x}\n\\end{equation}\n\nThis equation implies that the probability that an honest staker can produce $x$ consecutive blocks diminishes by a factor of $p_i$ for each incremental increase in $x$. \n\n\\subsection{Denial of Service}\n\nSince our protocol strictly interleaves PoW and PoS blocks, the network stalls if miners or stakers do not produce a block for some reason. This is a concern, but it is not significantly worse than a pure PoW network. \n\n\\subsection{Selfish Mining}\n\nThe problem of \\textit{selfish mining} in pure PoW networks is that miners who adopt this strategy hold onto blocks, mining from an advantageous position \\cite{selfish_mining}. This is done until such a point that the network catches up to them, at which point, they publish their chain. This strategy wastes the efforts (work) of honest miners, thus netting the attacker a block production rate disproportionate to their actual mining power. Our protocol does not suffer from this problem specifically, since mining and staking blocks must be interleaved.\n\nThere is, however, a similar problem that our protocol is vulnerable to. A staker can collude with a miner by sending the miner a PoS block before the waiting time has elapsed. This miner now gets a head start on mining a PoW block on top of it. This costs the staker nothing (since she can still release her block to the wider network when it becomes eligible). It does give the miner the chance to win more of the blocks than their share of the hash power. Further analysis is required to define the bounds around the advantage a miner can achieve by participating in such a scheme.  \n\n", "meta": {"hexsha": "c9e8f84e04a25244df21acdef16d4b63220fc984", "size": 7636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/4analysis.tex", "max_stars_repo_name": "aionnetwork/unity-interleave", "max_stars_repo_head_hexsha": "319117f5423e9b99a88ce28dc5280632c1c9a35b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-22T16:04:27.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-22T16:04:27.000Z", "max_issues_repo_path": "sections/4analysis.tex", "max_issues_repo_name": "aionnetwork/unity-interleave", "max_issues_repo_head_hexsha": "319117f5423e9b99a88ce28dc5280632c1c9a35b", "max_issues_repo_licenses": ["MIT"], "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/4analysis.tex", "max_forks_repo_name": "aionnetwork/unity-interleave", "max_forks_repo_head_hexsha": "319117f5423e9b99a88ce28dc5280632c1c9a35b", "max_forks_repo_licenses": ["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.3125, "max_line_length": 896, "alphanum_fraction": 0.7827396543, "num_tokens": 1764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.6859494550081926, "lm_q1q2_score": 0.6177179086814535}}
{"text": "\\subsection{Dynamics Constraints}\n\\label{text:approach/constraint/dynamics}\nThe dynamics constraints subside all constraints in problem \\ref{problem:general} that are not directly related to safety, i.e. \n\n\\begin{align}\n\\label{eq:constraint_f}\n&\\x_{t+1} = \\f(\\x_t, \\u_t) \\qquad& \\forall t \\in [0, T - 1] \\\\\n\\label{eq:constraint_x}\n&\\x_t \\in \\xset & \\forall t \\in [0, T]\\\\\n\\label{eq:constraint_u}\n&\\u_t \\in \\uset & \\forall t \\in [0, T]\\\\\n\\label{eq:constraint_x0}\n&\\x_0 \\in \\xset_0\n\\end{align}\n\nUsing the shooting trajectory optimization paradigm, the decision variables are the robot's control inputs $\\u_t \\in \\uset$. The states $\\x_t$ are obtained by unrolling the controls starting at some initial state $\\x_0 \\in \\xset_0$ and iteratively using the robot's dynamics $\\f(\\cdot)$. \\ac{IPOPT} on the other side solves a general \\ac{NLP} of the form \\cite{Wachter2006} \\\\\n\n\\begin{problem}{General IPOPT problem formulation}\n\\begin{align}\n\\min_{x \\in \\mathbb{R}^n} \\quad & \\f(x) \\\\\n\\textrm{s.t. } \\quad & g^L \\leq g(x) \\leq g^U \\\\\n& x^L \\leq x \\leq x^U \n\\end{align}\n\\label{problem:general_ipopt}\n\\end{problem}\n\nAs indicated in Section \\ref{text:approach/formulation}, the bounds of the controls $\\u_t$ have a shape, as the decision variable $\\x$ in problem \\ref{problem:general_ipopt}. Therefore \\ref{eq:constraint_u} is implicitly posed, without further ado, just by using the robot's control input bounds as bounds of the decision variable. Also, the constraints \\ref{eq:constraint_f} and  \\ref{eq:constraint_x0} are satisfied by the problem design, using the shooting method, leaving merely the constraint \\ref{eq:constraint_x} to be explicitly defined. The state $\\x$ of the robot incorporates both its position and its velocity. While the prediction models, objectives, and constraints only depend on relative measures regarding the agent's positions, the positional subset of $\\xset$ can be safely assumed to be unbounded ($\\xset_{pos} = \\mathbb{R}^2$). Due to the speed boundaries imposed on the robot ($||v||_1 \\leq v_{max}$, comp. Section \\ref{text:approach/formulation}), in order for the solution to be feasible, a maximal speed constraint must be established:\n\n\\begin{equation}\n\\x_t \\in \\xset \\Rightarrow -v_{max} \\leq g_{v_{max}}(\\x_t) = \\dot{\\x}_t \\leq v_{max} \\quad \\forall t \\in [0, T]\n\\label{eq:constraint_v_max}\n\\end{equation}\n\nComputing the Jacobian for constraint \\ref{eq:constraint_v_max} is straightforward using the chain rule and exploiting the linear robot dynamics (as above when deriving the goal objective's gradient in equation \\ref{eq:goal_gradient_dynamics}):  \n\n\\begin{align}\n\\nabla g_{v_{max}} &= \\pd{g_{v_{max}}}{\\u_{0:T-1}} = \\pd{g_{v_{max}}}{\\x_{0:T}} \\cdot \\pd{\\x_{0:T}}{\\u_{0:T-1}} \\\\\n\\Rightarrow \\pd{g_{v_{max}}}{\\x_{0:T}} &= \\begin{bmatrix} \\pd{g_{v_{max}}^1}{\\x_{0:T}} & \\hdots & \\pd{g_{v_{max}}^T}{\\x_{0:T}}\\end{bmatrix}^T  \\\\\n&= \\begin{bmatrix} \n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & \\hdots & 0 \\\\ \n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & \\hdots & 0 \\\\  \n0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & \\hdots & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & \\hdots & 0 \\\\ \n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \\hdots & 1 \\end{bmatrix} \\\\\n\\Rightarrow \\pd{\\x_{0:T}}{\\u_{0:T-1}} &= \\begin{bmatrix} \\mathbf{0}_{n \\times m} \\\\ B_n \\end{bmatrix}\n\\end{align}\n\n", "meta": {"hexsha": "7067264f92b5421b9933061bd60ef0b3574c8ab8", "size": 3340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/constraint_dynamics.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/constraint_dynamics.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/constraint_dynamics.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": 68.1632653061, "max_line_length": 1060, "alphanum_fraction": 0.6829341317, "num_tokens": 1162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6177057614521002}}
{"text": "\\chapter{Accurate Newton's Method for B\\'{e}zier Curve Intersection}\n\\label{chap:compensated-newton}\n\n\\section{Introduction}\n\nWhen using Newton's method to find the root of a function via\n\\begin{equation}\nG\\left(\\bm{x}\\right) = \\bm{x} - J^{-1} F\\left(\\bm{x}\\right)\n\\end{equation}\nthere are three computations performed that can introduce instability:\nevaluation of the residual function \\(F\\left(\\bm{x}\\right)\\), evaluation\nof the Jacobian \\(J\\) and solution of the linear system \\(J \\bm{y} =\nF\\left(\\bm{x}\\right)\\). In \\cite{Tisseur2001}, the author showed that by\njust using a more precise evaluation of the residual function, the\naccuracy of Newton's method can be improved.\n\nThis chapter considers Newton's method applied to two problems:\nroot-finding for polynomials expressed in Bernstein form and\nintersection of two B\\'{e}zier curves in \\(\\reals^2\\). In both problems,\nthe compensated de Casteljau method (see Chapter~\\ref{chap:k-compensated}) is\nused for evaluation of the residual. When evaluating a polynomial\n\\(p(s)\\) this is straightforward, but when evaluating the difference\n\\(b_1(s) - b_2(t)\\) between two curves special care must be taken.\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/newton_jghplus13.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Comparing relative error to condition number when using Newton's\n    method to find a root of \\(p(s) = (s - 1)^n - 2^{-31}\\), where polynomial\n    evaluation occurs via Horner's method.}\n  \\label{fig:jgh+13}\n\\end{figure}\n\nIn \\cite{Graillat2008}, the problem of finding simple roots \\(\\alpha\\) of\npolynomials \\(p(s)\\) expressed in the monomial basis is considered.\nA standard Newton's method (\\texttt{HNewtonBasic}) that evaluates \\(p(s)\\)\nand \\(p'(s)\\) using Horner's method is compared to a modified Newton's method\n(\\texttt{HNewtonAccurate}) that evaluates \\(p(s)\\) with a compensated\nHorner's method. This proceeds as in \\cite{Tisseur2001}: the evaluation of\nthe residual is done with greater accuracy but the rest of the process\nis the same. When computing a root \\(\\alpha\\), the standard Newton's method\nhas a relative error that grows linearly with the condition number of the\nroot (which will be defined in Section~\\ref{sec:conditioning}). The\nmodified Newton's method is fully accurate to machine precision (i.e.\nthe relative error is \\(\\bigO{\\mach}\\)) until \\(\\cond{\\alpha}\\) reaches\n\\(1/\\mach\\), as seen in Figure~\\ref{fig:jgh+13}.\n\nAfter the point where \\texttt{HNewtonAccurate} loses accuracy, we'd\nexpect a linear increase in relative error based on a compensated\nrule of thumb:\n\\begin{equation}\\label{eq:comp-rule-thumb}\n\\frac{\\left|\\widehat{\\alpha} - \\alpha\\right|}{\\left|\\alpha\\right|} \\leq\n  c_1 \\mach + c_2 \\cond{\\alpha} \\mach^2\n\\end{equation}\nwhere \\(c_1 \\mach\\) corresponds to rounding into the given\nprecision and \\(c_2 \\cond{\\alpha} \\mach^2\\) reflects the\ntypical error but from computations done with working precision\n\\(\\overline{\\mach} = \\mach^2\\). The point\nwhere the condition number exceeds \\(1/\\mach\\) should correspond to\nthe point where the second term is larger that the\nfirst term. However, this is not possible unless the\nJacobian (i.e. \\(p'(s)\\)) is also evaluated with a compensated\nmethod. A second modified Newton's method (\\texttt{HNewtonFull}) is\nintroduced in \\cite[Section~8]{Jiang2013} and the author shows that\nthis second modified Newton's method does indeed follow a compensated\nrule of thumb under appropriate conditions. We see in\nFigure~\\ref{fig:jgh+13} that \\texttt{HNewtonFull} enables\n\\(\\bigO{\\mach}\\) relative errors until the condition number reaches\n\\(1/\\mach\\) and then a linear increase in error as the condition number\ngrows from \\(1/\\mach\\) to \\(1/\\mach^2\\).\n\nWe'll proceed similarly for polynomials in\nBernstein form. Since this is a one dimensional Newton's method, improving\nthe evaluation of the Jacobian is straightforward. The results agree with\nwhat has been observed when using Horner's method for evaluation.\n\nComputing the intersection(s) of two parametric plane curves is a\ncommon task in computational geometry and has many uses, e.g. in\nfinite element methods that use overlapping curved meshes. Many\nmethods have been described in the literature to solve this problem.\nAlgebraic methods such as implicitization and eigenvalue-based\nmethods (e.g. \\cite{Manocha:CSD-92-698}) suffer\nfrom accuracy issues for moderately high degrees and can often be\nvery complex to implement. Some (\\cite{Bates2008}) even rely on symbolic\nalgebraic manipulations, which can be quite costly since it requires\narbitrary precision.\nGeometric methods (e.g. \\cite{Sederberg1986, Sederberg1990, Kim1998})\ntypically use a form of domain splitting to focus on subproblems and\neliminate parts of the domain where an intersection is guaranteed not\nto occur. After a domain has been sufficiently reduced, Newton's method\nis used for the last few bits of accuracy.\n\nWe'll focus on transversal curve intersections that are ill-conditioned.\nTransversal intersections are an extension of the concept of a\nsimple root. A non-transversal intersection occurs when the curves\nor tangent at the point of intersection or when one of the curves\nhas a zero tangent vector at that point, either due to an improper\nparameterization (e.g. \\(x(s) = s^2, y(s) = s^2 + 1\\)) or a cusp.\nIn many cases, transversal intersections that are ``almost tangent'' have\nvery high condition numbers.\n\nThe chapter is organized as follows. In Section~\\ref{sec:conditioning}\nwe define and discuss the conditioning of both a simple root and\na transversal intersection. In Section~\\ref{sec:compensated-simple-roots}\nwe describe two compensated Newton's methods for finding simple roots\nand perform a numerical experiment verifying the expected behavior.\nIn Section~\\ref{sec:compensated-curve-intersect} we describe a\ncompensated Newton's method for B\\'{e}zier curve intersection and\nperform sever numerical experiements to verify the expected behavior\non both transversal intersections and tangent intersections (i.e.\nintersections with infinite condition number).\nSection~\\ref{sec:false-starts} acts as a\ncoda: it describes some failed attempts at constructing numerical\nexamples. This section provides an in-depth discussion of a particular\nfamily of polynomials that has much better than expected conditioning\nwhen written in the Bernstein basis.\n\n\\section{Problem conditioning}\\label{sec:conditioning}\n\nConsider a smooth function \\(F: \\reals^n \\longrightarrow \\reals^n\\)\nwith Jacobian \\(F_{\\bm{x}} = J\\). We want to consider a special class of\nfunctions of the form \\(F\\left(\\bm{x}\\right) = \\sum_j c_j\n\\phi_j\\left(\\bm{x}\\right)\\) where the basis\nfunctions \\(\\phi_j\\) are also smooth functions on \\(\\reals^n\\)\nand each \\(c_j \\in \\reals\\). We want to consider the effects on a root\n\\(\\bm{\\alpha} \\in \\reals^n\\) of a perturbation in one of the\ncoefficients \\(c_j\\). We examine the perturbed functions\n\\begin{equation}\nG(x, \\delta) = F\\left(\\bm{x}\\right) + \\delta \\phi_j\\left(\\bm{x}\\right).\n\\end{equation}\nSince \\(G\\left(\\bm{\\alpha}, 0\\right) = \\bm{0}\\), if \\(J^{-1}\\) exists at\n\\(\\bm{x} = \\bm{\\alpha}\\) then\nthe implicit function theorem tells us that we can define\n\\(\\bm{x}\\) via\n\\begin{equation}\nG\\left(\\bm{x}\\left(\\delta\\right), \\delta\\right) = \\bm{0}.\n\\end{equation}\nTaking the derivative with respect to \\(\\delta\\) we find that\n\\(\\bm{0} = G_{\\bm{x}} \\bm{x}_{\\delta} + G_{\\delta}\\). Plugging in\n\\(\\delta = 0\\) we find that \\(0 = J\\left(\\bm{\\alpha}\\right) \\bm{x}_{\\delta} +\n\\phi_j\\left(\\bm{\\alpha}\\right)\\), hence we\nconclude that\n\\begin{equation}\n\\bm{x}\\left(\\delta\\right) = \\bm{\\alpha} - J\\left(\\bm{\\alpha}\\right)^{-1}\n  \\phi_j\\left(\\bm{\\alpha}\\right) \\delta + \\bigO{\\delta^2}.\n\\end{equation}\nThis gives a relative condition number (for the root) of\n\\begin{equation}\n\\frac{\\left \\lVert J\\left(\\bm{\\alpha}\\right)^{-1}\n  \\phi_j\\left(\\bm{\\alpha}\\right) \\right \\rVert}{\n  \\left \\lVert \\bm{\\alpha} \\right \\rVert}.\n\\end{equation}\n\nBy considering perturbations in \\emph{all} of the coefficients:\n\\(\\left|\\delta_j\\right| \\leq \\eps \\left|c_j\\right|\\), a similar analysis\ngives a root function\n\\begin{equation}\n\\bm{x}\\left(\\delta_0, \\ldots, \\delta_n\\right) = \\bm{\\alpha} -\n  J\\left(\\bm{\\alpha}\\right)^{-1} \\sum_{j = 0}^n \\delta_j\n  \\phi_j\\left(\\bm{\\alpha}\\right) + \\bigO{\\eps^2}.\n\\end{equation}\nWith this, we can define a root condition number\n\\begin{equation}\\label{eq:abstract-cond-num}\n\\kappa_{\\bm{\\alpha}} =\n  \\lim_{\\eps \\to 0} \\left(\\sup \\frac{\\left \\lVert\\delta \\bm{\\alpha}\n  \\right \\rVert / \\eps}{\\left \\lVert\\bm{\\alpha}\\right \\rVert}\\right) =\n  \\lim_{\\eps \\to 0} \\left(\\sup \\frac{\\left \\lVert\n  J\\left(\\bm{\\alpha}\\right)^{-1} \\sum_j \\delta_j\n  \\phi_j\\left(\\bm{\\alpha}\\right) \\right \\rVert / \\eps}{\n  \\left \\lVert\\bm{\\alpha}\\right \\rVert}\\right).\n\\end{equation}\n\nWhen \\(n = 1\\), \\(J^{-1}\\) is simply \\(1 / F'\\) and we find\n\\begin{equation}\n\\kappa_{\\alpha} =\n  \\frac{1}{\\left|\\alpha F'(\\alpha)\\right|} \\sum_{j = 0}^n \\left|\n  c_j \\phi_j(\\alpha)\\right|.\n\\end{equation}\nThis value is given by the triangle inequality applied to\n\\(\\delta \\alpha\\)  and equality can be attained since the sign\nof each \\(\\delta_j = \\pm c_j \\eps\\) can be modified at will to make\n\\(\\phi_j(\\alpha) \\delta_j = \\left|\\phi_j(\\alpha) c_j\\right| \\eps\\).\n\nWhen \\(n > 1\\), the triangle inequality tells us that\n\\begin{equation}\n\\kappa_{\\bm{\\alpha}} =\n  \\lim_{\\eps \\to 0} \\left(\\sup \\frac{\\left \\lVert\\delta \\bm{\\alpha} /\n  \\eps\\right \\rVert}{\\left \\lVert\\bm{\\alpha}\\right \\rVert}\\right) \\leq\n  \\frac{1}{\\left \\lVert\\bm{\\alpha}\\right \\rVert} \\sum_{j = 0}^n\n  \\left|c_j\\right| \\left \\lVert J\\left(\\bm{\\alpha}\\right)^{-1}\n  \\phi_j(\\bm{\\alpha})\\right \\rVert.\n\\end{equation}\nHowever, this bound is only attainable if all\n\\(\\phi_j(\\bm{\\alpha})\\) are parallel. However, we'll seldom need to\ncompute the exact condition number and are instead typically\ninterested in the order of magnitude. In this case a lower\nbound\n\\begin{equation}\n\\frac{1}{\\left \\lVert\\bm{\\alpha}\\right \\rVert}\n\\max_j \\left|c_j\\right| \\left \\lVert J\\left(\\bm{\\alpha}\\right)^{-1}\n\\phi_j(\\bm{\\alpha})\\right \\rVert\n\\end{equation}\nfor \\(\\kappa_{\\bm{\\alpha}}\\)\nwill suffice as an approximate condition number.\n\nFor an example, consider\n\\begin{equation}\n\\phi_0 = \\left[ \\begin{array}{c} x_0 \\\\ 2 \\\\ 0 \\end{array}\\right],\n\\phi_1 = \\left[ \\begin{array}{c} 0 \\\\ x_1 \\\\ 3 \\end{array}\\right],\n\\phi_2 = \\left[ \\begin{array}{c} 2 \\\\ 0 \\\\ x_2 \\end{array}\\right],\nF = \\phi_0 + 2 \\phi_1 + 3 \\phi_2,\n\\bm{\\alpha} = \\left[ \\begin{array}{c} -6 \\\\ -1 \\\\ -2 \\end{array}\\right].\n\\end{equation}\nFor a given \\(\\eps\\), the maximum root perturbation occurs when\n\\(\\delta_0 = \\eps, \\delta_1 = 2 \\eps, \\delta_2 = -3 \\eps\\) and\ngives\n\\(\\left \\lVert J\\left(\\bm{\\alpha}\\right)^{-1} \\sum_j\n\\delta_j \\phi_j\\left(\\bm{\\alpha}\\right) \\right \\rVert\n= 4 \\sqrt{10} \\eps \\approx 12.65 \\eps\\).\nThe pessimistic triangle inequality bound gives\n\\(\\sum_j \\left|c_j\\right| \\left \\lVert J\\left(\\bm{\\alpha}\\right)^{-1}\n\\phi_j(\\bm{\\alpha})\\right \\rVert \\approx 14.64 \\eps\\) and the\nmaximum individual perturbation is \\(2 \\sqrt{10} \\eps \\approx 6.325 \\eps\\)\n(this occurs when \\(\\delta_0 = \\delta_1 = 0, \\delta_2 = \\pm 3 \\eps\\)).\n\nIn this general framework, we can define a condition number both\nfor a simple root of a polynomial in Bernstein form and for the\nintersection of two planar B\\'{e}zier curves. For the first,\n\\(\\phi_j(s) = \\binom{n}{j} (1 - s)^{n - j} s^j\\) the Bernstein basis\nfunctions, a polynomial \\(p(s) = \\sum_j b_j \\phi_j(s)\\) with\na simple root \\(\\alpha \\in \\left(0, 1\\right]\\) has root condition number\n\\begin{equation}\n\\kappa_{\\alpha} =\n  \\frac{1}{\\alpha \\left|p'(\\alpha)\\right|} \\sum_{j = 0}^n \\left|\n  b_j \\phi_j(\\alpha)\\right| = \\frac{\\widetilde{p}(\\alpha)}{\n  \\alpha \\left|p'(\\alpha)\\right|}.\n\\end{equation}\nFor the intersection of a degree \\(m\\) curve \\(b_1(s)\\) and\na degree \\(n\\) curve \\(b_2(t)\\), we have basis functions\n\\begin{multline}\n\\phi_{0, -1, 1} = \\left[ \\begin{array}{c} B_{0, m}(s) \\\\ 0 \\end{array}\\right],\n\\phi_{0, -1, 2} = \\left[ \\begin{array}{c} 0 \\\\ B_{0, m}(s) \\end{array}\\right],\n\\cdots, \\\\\n\\phi_{m, -1, 1} = \\left[ \\begin{array}{c} B_{m, m}(s) \\\\ 0 \\end{array}\\right],\n\\phi_{m, -1, 2} = \\left[ \\begin{array}{c} 0 \\\\\n  B_{m, m}(s) \\end{array}\\right], \\\\\n\\phi_{-1, 0, 1} = \\left[ \\begin{array}{c} -B_{0, n}(t) \\\\\n  0 \\end{array}\\right],\n\\phi_{-1, 0, 2} = \\left[ \\begin{array}{c} 0 \\\\\n  -B_{0, n}(t) \\end{array}\\right], \\cdots, \\\\\n\\phi_{-1, n, 1} = \\left[ \\begin{array}{c} -B_{n, n}(t) \\\\\n  0 \\end{array}\\right], \\phi_{-1, n, 2} = \\left[ \\begin{array}{c} 0 \\\\\n  -B_{n, n}(t) \\end{array}\\right].\n\\end{multline}\nSince \\(F(s, t) = b_1(s) - b_2(t)\\) we have Jacobian \\(J(s, t) =\n\\left[ \\begin{array}{c c} b_1'(s) & -b_2'(t) \\end{array}\\right]\\). We'll\nconsider a transversal intersection \\(F(\\alpha, \\beta) = \\bm{0}\\) with\n\\(\\det J(\\alpha, \\beta) \\neq 0\\). Since each of the\n\\(\\phi_j\\) is just a scalar multiple of the standard basis\nvectors, writing \\(J^{-1} = \\left[ \\begin{array}{c c}\n\\bm{v}_1 & \\bm{v}_2 \\end{array}\\right]\\), we have\n\\begin{multline}\nJ\\left(\\alpha, \\beta\\right)^{-1} \\sum_{\\bm{j}} \\delta_{\\bm{j}}\n  \\phi_{\\bm{j}}\\left(\\alpha, \\beta\\right) = \\left[\\sum_{i = 0}^m\n  \\delta_{i, -1, 1} B_{i, m}\\left(\\alpha\\right) + \\sum_{j = 0}^n\n  \\delta_{-1, j, 1} B_{j, n}\\left(\\beta\\right)\\right] \\bm{v}_1 \\\\\n+ \\left[\\sum_{i = 0}^m\n  \\delta_{i, -1, 2} B_{i, m}\\left(\\alpha\\right) + \\sum_{j = 0}^n\n  \\delta_{-1, j, 2} B_{j, n}\\left(\\beta\\right)\\right] \\bm{v}_2 =\n  \\nu_1 \\bm{v}_1 + \\nu_2 \\bm{v}_2.\n\\end{multline}\nwhere\n\\begin{equation}\\label{eq:nu-bounds}\n\\left|\\nu_k\\right| / \\eps \\leq \\sum_{i = 0}^m\n  \\left|c_{i, -1, k}\\right| B_{i, m}\\left(\\alpha\\right) + \\sum_{j = 0}^n\n  \\left|c_{-1, j, k}\\right| B_{j, n}\\left(\\beta\\right) = \\mu_k\n\\end{equation}\nand the bound can be attained for both \\(k = 1, 2\\) by making the\nsigns of the \\(\\delta_{\\bm{j}}\\) agree. If we name the components of each\ncurve via\n\\(b_1(s) = \\left[ \\begin{array}{c c} x_1(s) & y_1(s) \\end{array}\\right]^T\\)\nand \\(b_2(t) = \\left[ \\begin{array}{c c} x_2(t) & y_2(t) \\end{array}\\right]^T\\)\nthen we see that \\(\\mu_1 = \\widetilde{x}_1(\\alpha) + \\widetilde{x}_2(\\beta)\\)\nand \\(\\mu_2 = \\widetilde{y}_1(\\alpha) + \\widetilde{y}_2(\\beta)\\).\nThus we have condition number\n\\begin{align}\n\\kappa_{\\alpha, \\beta} &= \\frac{1}{\\sqrt{\\alpha^2 + \\beta^2}}\n  \\max_{\\left|\\nu_k\\right| \\leq \\mu_k} \\left \\lVert \\nu_1 \\bm{v}_1 +\n  \\nu_2 \\bm{v}_2 \\right \\rVert_2 \\\\\n  &=\n  \\sqrt{\\frac{\\max_{\\left|\\nu_k\\right| \\leq \\mu_k}\n  \\nu_1^2 \\left(\\bm{v}_1 \\cdot \\bm{v}_1\\right) +\n  2 \\nu_1 \\nu_2 \\left(\\bm{v}_1 \\cdot \\bm{v}_2\\right) +\n  \\nu_2^2 \\left(\\bm{v}_2 \\cdot \\bm{v}_2\\right)}{\\alpha^2 + \\beta^2}}\n  \\label{eq:intersect-cond-num}.\n\\end{align}\nSince \\(J^{-1}\\) is invertible, we know \\(\\bm{v}_1\\) and \\(\\bm{v}_2\\) are\nnot parallel which can be used to show that the only internal critical\npoint of the function to be maximimized in~\\eqref{eq:intersect-cond-num}\nis \\(\\nu_1 = \\nu_2 = 0\\), which is the global minimum. Along the boundary of\nthe rectangle\n\\(\\left[-\\mu_1, \\mu_1\\right] \\times \\left[-\\mu_2, \\mu_2\\right]\\),\nwe fix one of \\(\\nu_1\\) or \\(\\nu_2\\) and the resulting univariate function is\nan up-opening parabola, hence any critical point must be a local\nminimum. Thus we know the maximum occurs at two of the four corners of the\nrectangle:\n\\begin{equation}\\label{eq:intersect-cond-num-too}\n\\kappa_{\\alpha, \\beta} = \\sqrt{\\frac{\\mu_1^2\n  \\left(\\bm{v}_1 \\cdot \\bm{v}_1\\right) +\n  2 \\mu_1 \\mu_2 \\left|\\bm{v}_1 \\cdot \\bm{v}_2\\right| +\n  \\mu_2^2 \\left(\\bm{v}_2 \\cdot \\bm{v}_2\\right)}{\\alpha^2 + \\beta^2}}.\n\\end{equation}\n\nAs far as the author can tell,\na condition number for the intersection of two planar B\\'{e}zier curves\nhas not been described in the Computer Aided Geometric Design (CAGD)\nliterature. In \\cite[Chapter~25, Equation 25.11]{Higham2002}\na more generic condition number is defined for the root of a nonlinear\nalgebraic system that is similar to the definition above.\n\nFor an example, consider the line\n\\(b_1(s) = \\left[ \\begin{array}{c c} 2s & 2s \\end{array}\\right]^T\\)\nand improperly parameterized line\n\\(b_2(t) = \\left[ \\begin{array}{c c} 4t^2 & 2 - 4t^2\n\\end{array}\\right]^T\\) which intersect at \\(\\alpha = \\beta = 1/2\\).\nAt the intersection we have \\(J^{-1} = \\frac{1}{8}\n\\left[ \\begin{array}{c c} 2 & 2 \\\\ -1 & 1 \\end{array}\\right]\\),\nso that \\(\\bm{v}_1 \\cdot \\bm{v}_1 = \\bm{v}_2 \\cdot \\bm{v}_2 =\n5/64\\) and \\(\\bm{v}_1 \\cdot \\bm{v}_2 = 3/64\\). Since the\n\\(x\\)-component of \\(F(s, t)\\) can be written as\n\\(2s - 4t^2 = 2 B_{1, 1}(s) - 4 B_{2, 2}(t)\\) and the\n\\(y\\)-component as \\(2s + 4t^2 - 2 = 2 B_{1, 1}(s) - 2 B_{0, 2}(t)\n- 2 B_{1, 2}(t) + 2 B_{2, 2}(t)\\) we have\n\\begin{alignat}{2}\n\\mu_1 &= 2 B_{1, 1}(\\alpha) &&+ 4 B_{2, 2}(\\beta) = 2 \\\\\n\\mu_2 &= 2 B_{1, 1}(\\alpha) + 2 B_{0, 2}(\\beta) +\n  2 B_{1, 2}(\\beta) &&+ 2 B_{2, 2}(\\beta) = 3.\n\\end{alignat}\nFollowing~\\eqref{eq:intersect-cond-num-too}, this gives\n\\(\\kappa_{\\alpha, \\beta} = \\sqrt{202}/8 \\approx 1.78\\).\n\n\\section{Simple polynomial roots}\\label{sec:compensated-simple-roots}\n\nSimilar to \\cite{Graillat2008} we define an algorithm to perform\nstandard Newton's method \\\\ (\\texttt{DNewtonBasic}) for polynomials in\nBernstein form as well as a modified Newton's \\\\\n(\\texttt{DNewtonAccurate}) that\nuses compensated de Casteljau (Algorithm~\\ref{alg:comp-de-casteljau}) to\nevaluate the residual. Via\nthe \\texttt{NewtonGeneric} helper (Algorithm~\\ref{alg:generic-newton}), we\nneed only define the callable that computes \\(p(s) / p'(s)\\). (Such callables\nwill have a single input \\(s\\) but will also be parameterized by the\ncoefficients of \\(p\\). This is often referred to as a closure in programming\nlanguages.)\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Newton's method for polynomial in Bernstein form.}}\n  \\label{alg:d-newton-basic}\n\n  \\begin{algorithmic}\n    \\Function{\\(s_{\\ast} = \\mathtt{DNewtonBasic}\\)}\n             {$b, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\For{\\(j = 0, \\ldots, n - 1\\)}\n        \\State \\(\\Delta b_j = b_{j + 1} - b_j\\)\n      \\EndFor\n      \\\\\n      \\Function{\\(\\mathtt{update} = \\mathtt{update\\_fn}\\)}{$s$}\n        \\State \\(\\widehat{b} = \\mathtt{DeCasteljau}(b, s)\\)\n        \\State \\(\\widehat{b'} = n \\otimes \\mathtt{DeCasteljau}(\\Delta b, s)\\)\n        \\State \\(\\mathtt{update} = \\widehat{b} \\oslash \\widehat{b'}\\)\n      \\EndFunction\n      \\\\\n      \\State \\(s_{\\ast} = \\mathtt{NewtonGeneric}\\left(\n        \\mathtt{update\\_fn}, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Modified Newton's method for polynomial in Bernstein form.}}\n  \\label{alg:d-newton-accurate}\n\n  \\begin{algorithmic}\n    \\Function{\\(s_{\\ast} = \\mathtt{DNewtonAccurate}\\)}\n             {$b, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}$}\n      \\State \\(n = \\texttt{length}(b) - 1\\)\n      \\For{\\(j = 0, \\ldots, n - 1\\)}\n        \\State \\(\\Delta b_j = b_{j + 1} - b_j\\)\n      \\EndFor\n      \\\\\n      \\Function{\\(\\mathtt{update} = \\mathtt{update\\_fn}\\)}{$s$}\n        \\State \\(\\widehat{b} = \\mathtt{CompDeCasteljau}(b, s)\\)\n        \\State \\(\\widehat{b'} = n \\otimes \\mathtt{DeCasteljau}(\\Delta b, s)\\)\n        \\State \\(\\mathtt{update} = \\widehat{b} \\oslash \\widehat{b'}\\)\n      \\EndFunction\n      \\\\\n      \\State \\(s_{\\ast} = \\mathtt{NewtonGeneric}\\left(\n        \\mathtt{update\\_fn}, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\nAs seen in \\cite[Section~8]{Jiang2013}, by using greater accuracy\nwhen computing the Jacobian \\(p'(s)\\), we can mitigate\nthe drastic increase in error as the condition number rises.\nBy using \\texttt{CompDeCasteljauDer}\n(Algorithm~\\ref{alg:comp-de-casteljau-derivative}) to compute\n\\(p'(s)\\) we define a ``fully accurate'' modified Newton's method\n(\\texttt{DNewtonFull}).\n\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Fully Accurate modified Newton's method for\n      polynomial in Bernstein form.}}\n  \\label{alg:d-newton-full}\n\n  \\begin{algorithmic}\n    \\Function{\\(s_{\\ast} = \\mathtt{DNewtonFull}\\)}\n             {$b, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}$}\n      \\Function{\\(\\mathtt{update} = \\mathtt{update\\_fn}\\)}{$s$}\n        \\State \\(\\widehat{b} = \\mathtt{CompDeCasteljau}(b, s)\\)\n        \\State \\(\\widehat{b'} = \\mathtt{CompDeCasteljauDer}(b, s)\\)\n        \\State \\(\\mathtt{update} = \\widehat{b} \\oslash \\widehat{b'}\\)\n      \\EndFunction\n      \\\\\n      \\State \\(s_{\\ast} = \\mathtt{NewtonGeneric}\\left(\n        \\mathtt{update\\_fn}, s_0, \\mathtt{tol}, \\mathtt{max\\_iter}\\right)\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/root_plots.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Roots of \\(p(s) = (1 - 5s)^n + 2^{30} (1 - 3s)^n\\) for\n    \\(n = 5, 15\\) and \\(25\\).}\n  \\label{fig:root-plots}\n\\end{figure}\n\nIn order to verify the accuracy of the three proposed methods, we\nconsider the family of polynomials\n\\begin{equation}\np(s) = (1 - 5s)^n + 2^{d} (1 - 3s)^n = \\sum_{j = 0}^n \\left[(-4)^j +\n  2^{d} (-2)^j\\right] B_{j, n}(s).\n\\end{equation}\nThe coefficients can be represented exactly when \\(\\left|(2j) -\n(j + d)\\right| \\leq 52\\), so we specialize to \\(d = 30\\) to get a\nsuitable upper bound for \\(n\\). We restrict to \\(n\\) odd so that\n\\((1 - 5s)^n = 2^{d} (3s - 1)^n\\) has \\(n\\) distinct roots, only one of\nwhich is real. The distribution of the roots can be seen in\nFigure~\\ref{fig:root-plots} for \\(n = 5, 15\\) and \\(25\\).\n\nTo discuss the lone real root, we define \\(\\omega \\in \\reals\\) such that\n\\((1 + \\omega)^n = 2^{30}\\) and \\(\\omega \\to 0^+\\). Solving\n\\((1 - 5s) = (1 + \\omega)(3s - 1)\\) gives the root\n\\begin{equation}\n\\alpha = \\frac{2 + \\omega}{8 + 3 \\omega} \\in \\left[\\frac{1}{4},\n  \\frac{1}{3}\\right].\n\\end{equation}\nwith condition number\n\\begin{equation}\n\\kappa_{\\alpha} = \\frac{\\widetilde{p}(\\alpha)}{\\alpha \\left|p'(\\alpha)\\right|}\n  \\sim \\frac{7^n}{2^{20} \\sqrt[7]{2} \\; n}.\n\\end{equation}\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/newton_de_casteljau.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Comparing relative error to condition number when using Newton's\n    method to find a root of \\(p(s) = (1 - 5s)^n + 2^{30} (1 - 3s)^n\\) for\n    \\(n\\) odd.}\n  \\label{fig:newton-de-casteljau-1d}\n\\end{figure}\n\nWe use Newton's method with an absolute error tolerance of \\(10^{-15}\\)\nand a maximum of 100 iterations. Since we know\n\\(\\alpha \\in \\left[1/4, 1/3\\right]\\) we use \\(s_0 = 1/2\\) as a starting\npoint. Figure~\\ref{fig:newton-de-casteljau-1d} plots the relative error\n\\(\\left|\\alpha - \\widehat{\\alpha}\\right| / \\alpha\\) against the condition\nnumber \\(\\kappa_{\\alpha}\\). Both the root \\(\\alpha\\) and the relative error\nare computed using a 500-bit extended precision arithmetic. As can be\nseen in the Figure, the standard Newton's method (\\texttt{DNewtonBasic})\nhas relative error that is linear in \\(\\kappa_{\\alpha}\\). Both\nthe first modified Newton's (\\texttt{DNewtonAccurate}) and the\nthe ``fully accurate'' modified Newton's (\\texttt{DNewtonFull}) have\n\\(\\bigO{\\mach}\\) errors until \\(\\kappa_{\\alpha}\\) reaches\n\\(1 / \\mach\\). At this point, the accuracy in \\texttt{DNewtonAccurate}\ntotally collapses to \\(\\bigO{1}\\) while \\texttt{DNewtonFull} follows\na compensated rule of thumb~\\eqref{eq:comp-rule-thumb}. As expected, the\nrelative error for \\texttt{DNewtonFull} linearly increases from\n\\(\\bigO{\\mach}\\) to \\(\\bigO{1}\\) as \\(\\kappa_{\\alpha}\\) increases from\n\\(1 / \\mach\\) to \\(1 / \\mach^2\\), at which point the condition number\noverwhelms.\n\n\\section{B\\'{e}zier curve intersection}\\label{sec:compensated-curve-intersect}\n\nWhen intersecting curves, our residual \\(F(s, t) = b_1(s) - b_2(t)\\) involved\nthe evaluation of four polynomials in Bernstein form: \\(x_1(s), y_1(s),\nx_2(t), y_2(t)\\). In order to compute a more accurate residual, the\nstraightforward approach would just use \\texttt{CompDeCasteljau}\n(Algorithm~\\ref{alg:comp-de-casteljau}) to compute each\npolynomial:\n\\begin{equation}\n\\widehat{F} = \\left[ \\begin{array}{c}\n  \\mathtt{CompDeCasteljau}(x_1, s) \\ominus \\mathtt{CompDeCasteljau}(x_2, t) \\\\\n  \\mathtt{CompDeCasteljau}(y_1, s) \\ominus \\mathtt{CompDeCasteljau}(y_2, t)\n  \\end{array}\\right].\n\\end{equation}\nHowever, when the common value (e.g. \\(x_1(\\alpha) = x_2(\\beta)\\)) at an\nintersection is significantly larger than zero, this may not be helpful.\nWhen computing \\(\\widehat{b} + \\widehat{\\partial b}\\), the values may\nbe so far apart in magnitude that the compensated value is the same\nas the non-compensated value. For example, consider the equation\n\\begin{equation}\n1088 = s^2 + 60 s + 1076 = 1076 (1 - s)^2 + 1106 \\cdot 2(1 - s)s + 1137s^2.\n\\end{equation}\nThis has one root in the unit interval \\(\\alpha = 4 \\sqrt{57} - 30 \\approx\n0.1993\\). For a nearby value like \\(s = \\frac{51}{256} + \\frac{1}{2^{22}}\n\\approx 0.1992\\) we compute \\(\\widehat{\\partial b} = 512 \\mach\\), but this\nvalue is too small relative to \\(1088\\) so\n\\(\\widehat{b} \\oplus \\widehat{\\partial b} = \\widehat{b}\\).\n\nAt intersections, we expect \\(x_1(\\alpha) - x_2(\\beta)\\) to be small\nbut don't necessarily expect the common value to be small (similarly for\nthe \\(y\\)-component). Hence we use \\texttt{DeCasteljauEFT}\n(Algorithm~\\ref{alg:eft-de-casteljau}, the EFT associated with\n\\texttt{CompDeCasteljau}) to separate the ``large part'' (computed value)\nfrom the ``small part'' (compensation term).\nWhen subtracting \\(x_2(t) = \\widehat{x_2} +\n\\partial x_2\\) from \\(x_1(s) = \\widehat{x_1} +\n\\partial x_1\\) at an intersection, the values \\(\\widehat{x_j}\\) may\nbe large but their difference should be small and only that difference\nis suited to interact with the compensation terms:\n\\(\\left[D, \\sigma\\right] =\n\\mathtt{TwoSum}(\\widehat{x_1}, -\\widehat{x_2})\\). Then the\ncomputation becomes\n\\begin{equation}\n\\left[\\widehat{x_1} + \\partial x_1\\right] -\n\\left[\\widehat{x_2} + \\partial x_2\\right] =\nD + \\left(\\partial x_1 - \\partial x_2 + \\sigma\\right).\n\\end{equation}\nUnfortunately the compensation term \\(\\tau = \\partial x_1 -\n\\partial x_2 + \\sigma\\) can't be computed without rounding,\nbut \\(\\widehat{\\tau} = \\left[\\widehat{\\partial x_1} \\ominus\n\\widehat{\\partial x_2}\\right] \\oplus \\sigma\\) can be used instead.\n\nWith this, we specify a compensated algorithm (\\texttt{CompCurveResidual})\nfor evaluating the residual \\(F(s, t)\\):\n\\begin{breakablealgorithm}\n  \\caption{\\textit{Compensated method for residual of\n      B\\'{e}zier curve intersection.}}\n  \\label{alg:compensated-residual}\n\n  \\begin{algorithmic}\n    \\Function{\\(\\widehat{F} = \\mathtt{CompCurveResidual}\\)}\n             {$x_1, y_1, s, x_2, y_2, t$}\n      \\State \\(\\left[\\widehat{x_1}, \\widehat{\\partial x_1}\\right] =\n        \\mathtt{DeCasteljauEFT}(x_1, s)\\)\n      \\State \\(\\left[\\widehat{x_2}, \\widehat{\\partial x_2}\\right] =\n        \\mathtt{DeCasteljauEFT}(x_2, t)\\)\n      \\State \\(\\left[D, \\sigma\\right] = \\mathtt{TwoSum}(\n        \\widehat{x_1}, -\\widehat{x_2})\\)\n      \\State \\(\\widehat{\\tau} = \\left[\\widehat{\\partial x_1} \\ominus\n        \\widehat{\\partial x_2}\\right] \\oplus \\sigma\\)\n      \\State \\(\\widehat{F}_0 = D \\oplus \\widehat{\\tau}\\)\n      \\\\\n      \\State \\(\\left[\\widehat{y_1}, \\widehat{\\partial y_1}\\right] =\n        \\mathtt{DeCasteljauEFT}(y_1, s)\\)\n      \\State \\(\\left[\\widehat{y_2}, \\widehat{\\partial y_2}\\right] =\n        \\mathtt{DeCasteljauEFT}(y_2, t)\\)\n      \\State \\(\\left[D, \\sigma\\right] = \\mathtt{TwoSum}(\n        \\widehat{y_1}, -\\widehat{y_2})\\)\n      \\State \\(\\widehat{\\tau} = \\left[\\widehat{\\partial y_1} \\ominus\n        \\widehat{\\partial y_2}\\right] \\oplus \\sigma\\)\n      \\State \\(\\widehat{F}_1 = D \\oplus \\widehat{\\tau}\\)\n    \\EndFunction\n  \\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/tangent_intersection.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Intersection of two B\\'{e}zier curves that are tangent and have\n    the same curvature at the point of tangency.}\n  \\label{fig:tangent-intersection}\n\\end{figure}\n\nIn order to compare Newton's method with the compensated residual to\nstandard Newton's, we consider a few examples. The first is on an\nintersection (Figure~\\ref{fig:tangent-intersection}) with infinite\ncondition number:\n\\begin{equation}\nF(s, t) = \\left[ \\begin{array}{c} 2(4s^2 - 1) \\\\ (2s - 1)^2 + 1\n\\end{array}\\right] - \\left[ \\begin{array}{c} 4(4t^2 - 1) \\\\ 4(2t - 1)^2 + 1\n\\end{array}\\right].\n\\end{equation}\nThese curves are tangent and have the same curvature when \\(\\alpha = \\beta =\n1/2\\); this is equivalent to a polynomial with a triple root.\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/newton_linear_converge.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Relative error plots for the computed intersection\n    \\(\\alpha = \\beta = 1/2\\)\n    when using standard Newton's method and a modified Newton's method that\n    uses a compensated residual.}\n  \\label{fig:newton-linear-converge}\n\\end{figure}\n\nWhen using Newton's method to find non-transveral intersections (i.e. roots\nwhere the Jacobian is singular), it is well-known that convergence will\nbe linear rather than quadratic. However, it is less well known that\nconvergence will typically stop prematurely due to loss of accuracy when\ncomputing the residual. For our example, we start with \\(s_0 = 1 - 2^{-40}\\)\nand \\(t = 3/4 + 2^{-20}\\); these slight perturbations are to avoid a\n``direct'' path to the intersection. We stop converging once the length\nof the update vector is below \\(10^{-15}\\) or after 50 iterations,\nwhichever comes first. In Figure~\\ref{fig:newton-linear-converge}\nwe see that the standard Newton's method stops converging when the relative\nerror is around \\(\\sqrt[3]{\\mach}\\), both for the \\(s\\) and \\(t\\) component\nof the intersection. This is because the cubic-like behavior of the\nintersection makes \\(\\left(\\sqrt[3]{\\mach}\\right)^3\\) resemble zero and\nfalsely produces a zero residual (which results in a zero Newton update).\nThe modified Newton's continues for much longer, until the relative error\nreaches \\(\\sqrt[3]{\\mach^2}\\).\n\nIt is from this example that we base our next numerical experiment. By\nintroducing a small perturbation \\(r\\) to the \\(x\\)-component of\none of the curves, we can make the tangent intersection split into three\ndistinct intersections. Similarly, a large perturbation \\(1/r\\) added to\nboth \\(y\\)-components will leave the solution intact but will make the\ncondition number increase. This gives a family (parameterized by \\(r\\)):\n\\begin{equation}\nF(s, t) = \\left[ \\begin{array}{c} 2(4s^2 - 1) - r \\\\ (2s - 1)^2 + 1 + 1/r\n\\end{array}\\right] - \\left[ \\begin{array}{c} 4(4t^2 - 1) \\\\\n4(2t - 1)^2 + 1 + 1/r \\end{array}\\right].\n\\end{equation}\nWe'll focus on \\(r = 2^{-n}\\) for \\(2 \\leq n \\leq 50\\), since for these\nvalues the coefficients of \\(F\\) can be represented exactly in\n\\(\\floats\\). These curves intersect at\n\\begin{align}\n(\\alpha_1, \\beta_1) &= \\left(\\frac{1 + \\sqrt{r}}{2},\n  \\frac{2 + \\sqrt{r}}{4}\\right), \\\\\n(\\alpha_2, \\beta_2) &= \\left(\\frac{1 - \\sqrt{r}}{2},\n  \\frac{2 - \\sqrt{r}}{4}\\right), \\\\\n(\\alpha_3, \\beta_3) &= \\left(\\frac{-3 + \\sqrt{16 + r}}{2},\n  \\frac{6 - \\sqrt{16 + r}}{4}\\right).\n\\end{align}\nWhen starting Newton's method from the \\(s_0 = t_0 = 1\\) (the ``top-right''\nof the unit square), we'll converge to the first intersection\n\\((\\alpha_1, \\beta_1)\\). For our chosen values of \\(r\\) (which will\ndetermine which coefficients are positive, e.g. in \\(\\widetilde{y}_2\\)),\none can show that\n\\begin{equation}\n\\kappa_{\\alpha_1, \\beta_1} = \\frac{\\sqrt{10}}{2r^2} -\n  \\frac{3 \\sqrt{10}}{40 r \\sqrt{r}} + \\bigO{\\frac{1}{r}}.\n\\end{equation}\n\n\\begin{figure}\n  \\includegraphics{../images/compensated-newton/almost_tangent.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Relative error plots for the computed intersection\n    \\(\\alpha = \\beta = 1/2\\)\n    when using standard Newton's method and a modified Newton's method that\n    uses a compensated residual.}\n  \\label{fig:almost-tangent}\n\\end{figure}\n\nWe compare the standard Newton's to the modified Newton's with a compensated\nresidual as \\(r \\to 0^+\\). We use \\(s_0 = t_0 = 1\\) as mentioned above\nand the same stopping criterion from the first example: stop once the length\nof the update vector is below \\(10^{-15}\\) or after 50 iterations, whichever\ncomes first. As seen in Figure~\\ref{fig:almost-tangent}, the standard\nNewton's method has relative error that increases linearly with\nthe condition number, i.e. \\(\\bigO{\\mach} \\kappa_{\\alpha_1, \\beta_1}\\),\nuntil it reaches \\(\\bigO{1}\\). The\nmodified Newton's method satisfies a compensated rule of\nthumb~\\eqref{eq:comp-rule-thumb}: the relative error is \\(\\bigO{\\mach}\\)\n(i.e. fully accurate up to rounding) until \\(\\kappa_{\\alpha_1, \\beta_1}\\)\nreaches \\(1 / \\mach\\) at which point the relative error resembles\n\\(\\bigO{\\mach^2} \\kappa_{\\alpha_1, \\beta_1}\\). What's more, when\n\\(r = 2^{-2m}\\) has a rational square root, the intersection\ncan be represented exactly in \\(\\floats\\) and the compensated method\ncomputes this intersection without any error.\n\n\\section{False starts}\\label{sec:false-starts}\n\nIt was quite challenging to generate families of polynomials with known\nill-conditioned simple roots and families of B\\'{e}zier curve pairs with known\nill-conditioned transversal intersections. The issue was not in finding a\nfamily with moderately high condition number, but in finding one where the\ncondition number would grow past \\(1 / \\mach\\) and even as far as\n\\(1 / \\mach^2\\). In many failed attempts, as the condition increased\nin a given family, it became impossible to represent the\ncoefficients exactly in \\(\\floats\\). Once the coefficients are rounded,\nthe roots or intertesections themselves will likely move erratically.\nThis erratic behavior is the goal when generating ill-conditioned problems,\nbut makes the values themselves less useful.\n\nTo give a sense of the nontrivial effort involved in finding a\nfamily, consider the following families of polynomials that\n\\emph{failed}:\n\\begin{itemize}\n  \\itemsep 0em\n  \\item \\(p(s) = (1 - s)^n - 2^{-d}\\) at the simple root\n    \\(s_{\\ast} = 1 - 2^{-d/n}\\). In the monomial basis, the\n    condition number of \\(s_{\\ast}\\) grows exponentially and was used\n    as the example in \\cite{Graillat2008} and \\cite[Section~8]{Jiang2013}.\n    However in the Bernstein basis, the root condition\n    number is always less than \\(1\\).\n  \\item \\(p(s) = (as - 1)^n - 2^{-d} (1 - s)^n\\) at the simple root\n    \\(s_{\\ast} = \\frac{1 + 2^{-d/n}}{a + 2^{-d/n}}\\). This is problematic\n    because when \\(a - 1\\) is not a power of \\(2\\), the coefficients\n    in \\((as - 1)^n = \\left[-(1 - s) + (a - 1)s\\right]^n\\) cannot be\n    represented exactly in \\(\\floats\\) for high enough degree. The rounded\n    coefficients result in sporadic behavior for the resulting polynomials.\n    When \\(a - 1 = 2^d\\), Newton's method converges with much better than\n    expected accuracy due to a unique quirk of the de Casteljau algorithm.\n    This case is interesting enough to consider in greater detail\n    in \\cite{Hermes2018}.\n  \\item \\(p(s) = (2s - 1)^n - 2^{-52}\\) at the simple root\n    \\(s_{\\ast} = \\frac{1 + 2^{-52/n}}{2}\\). The coefficients \\(b_j =\n    (-1)^{n - j} - 2^{-52}\\) can always be represented in \\(\\floats\\),\n    but as \\(n \\to \\infty\\) we have \\(s_{\\ast} \\to 1\\).\n    A root exactly equal to \\(1\\) is perfectly conditioned, so\n    unsurprisingly \\(\\kappa \\to 0\\) after reaching a maximum\n    value of \\(\\approx 3 \\cdot 10^{13}\\) when \\(n = 28\\).\n  \\item \\(p(s) = (3s - 1)^n - 2^{-d}\\) at the simple root \\(s_{\\ast} = \\frac{\n    1 + 2^{-d/n}}{3}\\). The coefficients \\(b_j = (-1)^{n - j} 2^j - 2^{-d}\\)\n    can be represented exactly in \\(\\floats\\) for \\(\\left|j + d\\right|\n    \\leq 52\\) (or \\(53\\), depending on \\(n\\)). This limitation stops the\n    condition number from growing large enough. For example, when \\(d = 10\\),\n    the largest term that can be represented exactly is \\(\\kappa_{43}\n    \\approx 1.03 \\cdot 10^{10}\\),\n    when \\(d = 20\\), the largest term that\n    can be represented exactly is \\(\\kappa_{33} \\approx 2.53 \\cdot 10^{10}\\)\n    and when \\(d = 30\\), the largest term that\n    can be represented exactly is \\(\\kappa_{23} \\approx 9.24 \\cdot 10^{10}\\).\n\\end{itemize}\n\nIn addition, several false starts were made when generating a family of\nB\\'{e}zier curve pairs with ill-conditioned intersection. In the\ncase of polynomials we increased the condition number via the degree,\nbut in the case of curve pairs it was increased by reducing a continuous\nparameter towards zero at which point the pair becomes tangent. The\nmost problematic case came from\n\\begin{equation}\nF(s, t; r) = \\left[ \\begin{array}{c} 2(4s^2 - 1) + r \\\\ (2s - 1)^2\n\\end{array}\\right] - \\left[ \\begin{array}{c} 4(4t^2 - 1) \\\\ 4(2t - 1)^2\n\\end{array}\\right].\n\\end{equation}\nIn this case, the polynomials \\((2s - 1)^2\\) and \\(4(2t - 1)^2\\) come\nfrom a very special class of polynomials described in \\cite{Hermes2018}\nwhere the de Casteljau algorithm is very accurate (much better than\nthe a priori upper bound). As a result, the \\(y\\)-contributions to the\nrelative error were essentially zero. This can be thought of as setting\n\\(\\mu_2 = 0\\) when computing the condition number. However, for this family\nof curves the \\(x\\)-components contribute \\(\\bigO{1}\\) to the condition\nnumber while the \\(y\\)-components \\emph{should} contribute \\(\\bigO{1/r}\\)\nbut instead contribution nothing. Hence the solution can always be computed\nby Newton's method with \\(\\bigO{\\mach}\\) relative error.\n", "meta": {"hexsha": "0161052fa01e251db894174c95521dd89d6ab56b", "size": 37445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/compensated-newton.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/compensated-newton.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/compensated-newton.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": 48.7565104167, "max_line_length": 79, "alphanum_fraction": 0.6834023234, "num_tokens": 12562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6177050985898049}}
{"text": "\\section{}\n\n\\subsection{}\n\n\\subsection{}\n\n\\subsection{}\n\n\t\\begin{problem}\n\t\tFrom Page 320 number 6. If we take the 95\\% upper, $n=60$, $s^2=12.5$, and $\\overline{x}=18.6$ the formula we are going to be using is $\\overline{x}+Z_\\alpha\\cdot \\frac{s}{\\sqrt{n} }$.\n\n\t\t\\begin{equation}\n\t\t\t18.6+1.645 \\frac{\\sqrt{12.5}}{\\sqrt{60}}\\approx19.55\n\t\t\\end{equation}\n\n\t\tBecause our result was 19.55, our interval is $(-\\infty, 19.55)$.\n\t\\end{problem}\n\n\tIf we were to take $\\overline{x_1}-\\overline{x_2}$, we would need to do \n\n\t\\begin{equation}\n\t\t\\overline{x_1}-\\overline{x_2}+Z_\\alpha\\cdot \\sqrt{\\frac{s_1^2}{n_1}+\\frac{s_2^2}{n_2}}.\n\t\\end{equation}\n\n\tSo if we were to have the $\\hat{p_1}-\\hat{p_2}$ lower,\n\n\t\\begin{equation}\n\t\t\\hat{p_1}-\\hat{p_2}-Z_\\alpha\\sqrt{\\frac{\\hat{p_1}\\hat{q_2}}{n_1}+\\frac{\\hat{p_2}\\hat{q_2}}{n_2}}.\n\t\\end{equation}\n\n\t\\begin{problem}\n\t\tLet's take a look at a problem, where 55\\% of 2000 American adults surveyed said they have watched digitally streamed TV programming on some type of device. $\\hat{W}$ sample size would be required for the width of a 99\\% CI to be at most 0.5 irrespective of the value of $\\hat{p}$. We know that the value of $\\hat{p}$ is 55\\%. and we need to find the $[a,b]$ interval.\n\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t\\left(\\hat{p}+2.576\\sqrt{\\frac{\\hat{p}\\hat{q}}{n}}\\right)-\\left(\\hat{p}-2.576\\sqrt{\\frac{\\hat{p}\\hat{q}}{n}}\\right)\\\\\n\t\t\t&=2\\cdot 2.576\\sqrt{\\frac{\\hat{p}\\hat{q}}{n}}\\\\\n\t\t\t&= \\text{size of the CI}\\\\\n\t\t\t0.5 &> 2\\cdot 2.576\\sqrt{\\frac{\\hat{p}\\hat{q}}{n}}\n\t\t\\end{aligned}\n\t\t$$\n\n\t\tConsider the worst scenario:\n\n\t\t$$\n\t\t\\begin{aligned}\n\t\t\t2\\cdot 2.576\\sqrt{\\frac{\\frac{1}{2}\\frac{1}{2}}{n}}&<0.05\\\\\n\t\t\t\\sqrt{\\frac{\\frac{1}{4}}{\\sqrt{n}}}&<\\frac{0.5}{2\\cdot2.576}\\\\\n\t\t\t\\frac{\\frac{1}{2}}{\\sqrt{n}}&<\\frac{.05}{2*2.576}\\\\\n\t\t\t\\frac{2.576}{0.5}&<\\sqrt{n}\\\\\n\t\t\tn&>\\left(\\frac{2.576}{.05}\\right)^2\\\\\n\t\t\tn&=2655\n\t\t\\end{aligned}\n\t\t$$\n\t\t\\end{problem}\n\n", "meta": {"hexsha": "51ee711830535cf3740a85c226ce388d36e1cfc0", "size": 1883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math321/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": "math321/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": "math321/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": 33.0350877193, "max_line_length": 370, "alphanum_fraction": 0.6192246415, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6177050979621751}}
{"text": "\\section{Appendix}\n\n\\subsection{Exercises}\n\n\\subsubsection{Exercise A.1}\nWe can choose $n_3 = max(n_1, n_2)$ such that $f_1(n) + f_2(n) \\leq (C_1 + C_2)g$ whenever\n$n > n_3$.\n\n\\subsubsection{Exercise A.2}\nSimilar to the first exercise, but now we have $C_1 C_2 h$ instead.\n\n\\subsubsection{Exercise A.3}\nLogarithms of different bases differ by a constant.\n\n\\subsubsection{Exercise A.4}\nThe argument treats $k$ as a constant, when in reality $k = O(n)$. The answer should be\n$O(n^3)$, which can be checked by looking at the closed form of the sum.\n\n\\subsubsection{Exercise A.5}\n$2^{O(n)}$ and $O(2^{n})$ are not the same, since $\\limsup_{n \\to  \\infty} \\frac{2^{C_1n}}{C_{2}2^n}$\nonly converges to a nonzero constant when $C_1 = 1$.\n\n\\subsubsection{Exercise A.6}\n$n^{k} \\neq \\Theta(2^n)$, $e^{-n} \\neq \\Theta(n^{-c})$, and $n! \\neq \\Theta(n^n)$, as all limits go to 0.\n\n\\subsubsection{Exercise A.7}\nTake $f = n$ and $g = 2n$. \n\n\\subsubsection{Exercise A.8}\n1. We can pull out the exponents as constants, so $f = \\Theta(g)$.\n\n2. $3 < 2^2$ so $f = o(g)$.\n\n3. $n = \\omega(\\log^2 n)$ so $f = \\omega(g)$.\n\n4. $2^{\\log n} \\to \\infty$ so $f = \\omega(g)$.\n\n\\subsubsection{Exercise A.9}\nOne example is $n^{\\log n}$.\n", "meta": {"hexsha": "377b3351eacc4c4011ff33eac25c2e245e53dfbd", "size": 1205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Nature_of_Computation_Moore_Mertens/appendix.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/appendix.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/appendix.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": 30.125, "max_line_length": 105, "alphanum_fraction": 0.6514522822, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6177050882760884}}
{"text": "\\documentclass[]{BasiliskReportMemo}\n\\usepackage{AVS}\n\\usepackage{algorithmic}\n\\usepackage[boxed]{algorithm}\n\n\n\\newcommand{\\submiterInstitute}{Autonomous Vehicle Simulation (AVS) Laboratory}\n\n\\newcommand{\\ModuleName}{ThrusterForces}\n\\newcommand{\\subject}{Algorithms to Map Desired Torque Vector onto a set of Thrusters }\n\\newcommand{\\status}{Ready}\n\\newcommand{\\preparer}{H. Schaub}\n\\newcommand{\\summary}{Include a short summary of what this system engineering report is about.  Should be 300 words or less.     }\n\n\n\\begin{document}\n\n\n\\makeCover\n\n\n%\n%\tenter the revision documentation here\n%\tto add more lines, copy the table entry and the \\hline, and paste after the current entry.\n%\n\\pagestyle{empty}\n{\\renewcommand{\\arraystretch}{1.1}\n\\noindent\n\\begin{longtable}{|p{0.5in}|p{4.5in}|p{1.14in}|}\n\\hline\n{\\bfseries Rev}: & {\\bfseries Change Description} & {\\bfseries By} \\\\\n\\hline\nv0.1 & Updated the thruster force evaluation to account for center of mass offsets & H. Schaub \\\\\nv0.2 & Updated the figure and the $[C]$ matrix notation & H. Schaub \\\\\nv0.3 & The thruster mapping logic has changed, and this documentation now reflects what the new algorithm does. & H. Schaub \\\\\n\\hline\n\n\\end{longtable}\n}\n\n\\newpage\n\\setcounter{page}{1}\n\\pagestyle{fancy}\n\n\\tableofcontents\n~\\\\ \\hrule ~\\\\\n\n\\begin{figure}[htb]\n\t\\centerline{\n\t\\includegraphics[]{Figures/thrusterNotation}\n\t}\n\t\\caption{Illustration of the Spacecraft Thruster Notation}\n\t\\label{fig:thruster}\n\\end{figure}\n\n\\section{Introduction}\n\\subsection{Torque Control Axes}\nThis technical note describes a general algorithm that maps a desired ADCS external control torque $\\bm L_{r}$ onto force commands for a cluster of thrusters.  Let $\\hat{\\bm c}_{j}$ be the axis about which the thrusters are to produce the desired torque.  The matrix of $N_{c}$ thruster axes rows is then given by\n\\begin{equation}\n\t[C]  = \\begin{bmatrix}\n\t\t\\hat{\\bm c}_{1} \\\\ \\vdots \\\\ \\hat{\\bm c}_{N_{c}}\n\t\\end{bmatrix}\n\\end{equation}\nThe module can accept up to 3 orthogonal control axis $\\hat{\\bm c}_{j}$.  Let $\\bar{\\bm L}_{r}$ be the three-dimensional reduced set of $\\bm L_{r}$ onto the set of control axes, given by:\n\\begin{equation}\n\t\\bar{\\bm L}_{r} = [C]^{T} [C] \\bm L_{r}\n\\end{equation}\nThe goal of the thruster mapping strategy is to find a set of $\\bm F$ thruster forces that yield $\\bar{\\bm L}_{r}$.  \n\n\\subsection{Thruster to Torque Mapping Matrix}\nThe $i^{\\text{th}}$ thruster location relative to the spacecraft point $B$ is given by $\\bm r_{i}$ as illustrated in Figure~\\ref{fig:thruster}.  The unit direction vector of the thruster force is $\\hat{\\bm g}_{t_{i}}$, while the thruster force is given by\n\\begin{equation}\n\t\\label{eq:th:1}\n\t\\bm F_{i} = F_{i} \\hat{\\bm g}_{t_{i}}\n\\end{equation}\nThe toque vector produced by each thruster about the body fixed point $C$ is thus\n\\begin{equation}\n\t\\bm \\tau_{i} = (\\bm r_{i} - \\bm r_{\\text{COM}}) \\times F_{i}  \\hat{\\bm g}_{t_{i}}\n\\end{equation}\nThe total torque onto the spacecraft, due to a cluster of $N$ thrusters, is\n\\begin{equation}\n\t\\tau_{j} = \\sum_{i=1}^{N} \\bm \\tau_{i} \n\t= \\sum_{i=1}^{N}  ((\\bm r_{i} - \\bm r_{\\text{COM}}) \\times \\hat{\\bm g}_{t_{i}}) F_{i} = \\sum_{i=1}^{N}  \\bm d_{i} F_{i}\n\\end{equation}\nwhere \n\\begin{equation}\n\t\\label{eq:th1:1}\n\t\\bm d_{i} =    ( \\bm r_{i} - \\bm r_{\\text{COM}})  \\times \\hat{\\bm g}_{t_{i}}\n\\end{equation}\nIn matrix form, the net spacecraft torque is written compactly as\n\\begin{equation}\n\t\\label{eq:DF}\n\t \\bm\\tau = \\begin{bmatrix}\n\t\t \\bm d_{1} \\cdots  \\bm d_{N}\n\t\\end{bmatrix} \\begin{bmatrix}\n\t\tF_{1} \\\\\n\t\t\\vdots \\\\\n\t\tF_{N}\n\t\\end{bmatrix} = [D] \\bm F\n\\end{equation}\nwhere $[D]$ is a $3\\times N$ matrix that maps the thruster forces $F_{i}$ to the spacecraft torque $\\bm \\tau$. \n\n\n\\section{ACS Thruster Force Algorithm for a Thruster Configuration with Full Torque Controllability}\nHere a thruster configuration is assumed that can produce pure torque-couples without exerting a net torque onto the spacecraft.  The thrusters force values $F_{i}$ must be strictly non-negative (i.e. either 0 or positive).   Note that in this configuration having all thrusters on will produce zero net force and torque onto the spacecraft.  Thus the $F_{i} = F_{j}$ solution is in the nullspace of the mapping in Eq.~\\eqref{eq:DF}.  \n\nThe goal of the thruster force algorithm is to determine a set of thruster forces $\\bm F$ such that the net force onto the spacecraft is\n\\begin{equation}\n\t\\label{eq:th:2}\n\t\\bm\\tau = \\bar{\\bm L}_{r}  = [D]\\bm F\n\\end{equation}\nwithout bleeding torque onto the un-controlled axes.  The first step is to perform a standard minimum norm inverse solution using\n\\begin{equation}\n\t\\label{eq:th:min}\n\t\\bm F = [D]^{T}([D][D]^{T})^{-1} \\bar{\\bm L}_{r}\n\\end{equation}\nThe $3\\times 3$ matrix $[D][D]^{T}$ is full rank and thus invertible with the assumption that this RCS configuration has a full 3D torque controllability.  This set of of thruster forces will contain $F_{i}$ values that are both positive and negative.  Next, to achieve strictly non-negative values, the minimum $F_{i}$ value is determined and subtracted from all $N$ force values.  \n\\begin{equation}\n\t\\bm F \\leftarrow \\bm F -  \\text{min}(\\bm F)\n\\end{equation}\nThe resulting set of $F_{i}$ forces will produce the desired control torque $\\bar{\\bm L}_{r}$ and achieve a net zero force onto the spacecraft.  The latter results is due to the assumption off an ACS thruster configuration that can produce pure moment couples.  \n\n\n\n\\section{2-Stage Minimum Norm ACS Thruster Mapping Algorithm}\nTo increase the robustness of the sign-constrained minimum norm thruster force solution, as 2nd stage is included if the number of available ACS thrusters is not equal to the number of installed thrusters.  This simulates scenarios where some thrusters are now offline.    The minimum norm solution from the earlier solution is first evaluated, and then shifted by subtracting the minimum $F_{i}$ value.  \n\nEach thruster can only produce a positive force.  With off-pulsing, the nominal thrust force plus the negative correction must still yield a non-negative thrust force.  The module parameter {\\tt thrForceSign} is either +1 or -1 to account for the desired force sign.  The value of this parameter is represented through $s_{F}$.  With the ACS thruster configuration this value would always be +1.  \n\nWe assume that $\\bm F$ elements only contain forces that are either zero or values with the desired sign.   Assume there are $M$  force values in $\\bm F$ with a sign that matches $s_{F}$.  The locations of these values is provided in the $N$-dimensional array $\\bm t_{\\text{used}}$ which contains either 0 or 1 values.  For example, consider $N=8$ and only thrusters 2 and 6 produce  zero forces. In this case we find\n\\begin{equation}\n\t\\bm t_{\\text{used}} = \\begin{bmatrix}\n\t\t1 & 0 & 1 & 1 & 1 & 0 & 1 & 1\n\t\\end{bmatrix}\n\\end{equation}\nThis reduces the thruster force search to a subset of $M$ thrusters.  Let $\\bar{\\bm F}_{j}$ be a $M\\times 1$ matrix of to be determined thruster forces.  The corresponding $3\\times M$ mapping matrix $[\\bar D]$ that projects $\\bar{\\bm F}$ onto a net body torque about point $B$ is defined as:\n\\begin{equation}\n\t[\\bar D] = \\begin{bmatrix} \\bar{\\bm d}_{1} & \\cdots & \\bar{\\bm d}_{M} \\end{bmatrix}\n\\end{equation}\nwith\n\\begin{equation}\n\t\\bar{\\bm d}_{i} = (\\bm r_{i} - \\bm r_{\\text{COM}}) \\times \\hat{\\bm g}_{i}\n\\end{equation}\nThe net torque due to $\\bar{\\bm F}$ is \n\\begin{equation}\n\t\\bar{\\bm \\tau} = [\\bar D] \\bar{\\bm F}\n\\end{equation}\n\nA modified set of thruster force solutions $\\bar{\\bm F}$ to generate the desired torque $\\bar{\\bm L}_{r}$ is found through a second minimum norm operation:\n\\begin{equation}\n\t\\label{eq:th:min2}\n\t\\bar{\\bm F} = [\\bar D]^{T}([\\bar D][\\bar D]^{T})^{-1} \\bar{\\bm L}_{r}\n\\end{equation}\n\n\n\n\nThe next step is to sum the individual $\\bar{\\bm F}$ thruster solutions to the yield the net set of thruster forces required to produce $\\bar{\\bm L}_{r}$.  This is done using the  $\\bm t_{\\text{used}}$ matrix to determine which thrusters have non-zero contributions.   The final step is to evaluate the minimum $F_{i}$ force again and subtract this from all thruster force values.\n\n\n\n\n\\section{DV Thruster Firing Strategy}\nWith a DV thruster configuration the thruster force axes are parallel.  As such, this configuration cannot produce a torque along the DV thrust axis.  A slightly modified version of the above algorithm is used in this case.  With the DV configuration the attitude along the axes orthogonal to the thrust vector are controlled via off-pulsing.  As such, the thruster firing mapping must produce negative $F_{i}$ values and the {\\tt thrForceSign} sign must be set to -1.  \n\nThe modified algorithm still evaluates the first minimum norm inverse, but does not subtract out the $\\text{min}(\\bm F)$ value.  Rather, the 2nd stage is used to determine which DV thrusters produce the torque with a negative torque value to generate the corresponding $[\\bar D]$ matrix.  After performing the 2nd minimum norm inverse with $[\\bar D]$ the subtraction of  $\\text{min}(\\bm F)$ is not performed.  \n\n\n\n\n\n\n\\section{Performance Illustration}\n\\subsection{ACS Thruster Configuration}\nTo illustrate the performance of this algorithm, the following simulation setup is used.  Let the ACS system have a total of $N = 8$ thrusters with the following body-fixed locations:\n\\begin{gather*}\n\t\\label{eq:th:loc}\n\t\\bm r_{1} = \\begin{bmatrix} +1.125, 0.0, +0.75  \\end{bmatrix}^{T} \\text{ m}\n\t\\quad\\quad\n\t\\bm r_{2} = \\begin{bmatrix} -1.125, 0.0, +0.75  \\end{bmatrix}^{T} \\text{ m}\n\t\\\\\n\t\\bm r_{3} = \\begin{bmatrix} -1.125, 0.0, +0.75  \\end{bmatrix}^{T}\t \\text{ m}\n\t\\quad\\quad\n\t\\bm r_{4} = \\begin{bmatrix} +1.125, 0.0, +0.75  \\end{bmatrix}^{T} \\text{ m}\n\t\\\\\n\t\\bm r_{5} = \\begin{bmatrix} +1.125, 0.0, -0.75  \\end{bmatrix}^{T}\t \\text{ m}\n\t\\quad\\quad\n\t\\bm r_{6} = \\begin{bmatrix} -1.125, 0.0, -0.75  \\end{bmatrix}^{T} \\text{ m}\n\t\\\\\n\t\\bm r_{7} = \\begin{bmatrix} -1.125, 0.0, -0.75  \\end{bmatrix}^{T}\t \\text{ m}\n\t\\quad\\quad\n\t\\bm r_{8} = \\begin{bmatrix} +1.125, 0.0, -0.75  \\end{bmatrix}^{T} \\text{ m}\n\\end{gather*}\nwith the force unit direction vectors:\n\\begin{gather*}\n\t\\label{eq:th:gt}\n\t\\bm g_{t_{1}} = \\begin{bmatrix} +0.707107, +0.707107, 0  \\end{bmatrix}^{T}\n\t\\quad\\quad\n\t\\bm g_{t_{2}} = \\begin{bmatrix} -0.707107, +0.707107, 0  \\end{bmatrix}^{T}\n\t\\\\\n\t\\bm g_{t_{3}} = \\begin{bmatrix} -0.707107, -0.707107, 0  \\end{bmatrix}^{T}\n\t\\quad\\quad\n\t\\bm g_{t_{4}} = \\begin{bmatrix} +0.707107, -0.707107, 0  \\end{bmatrix}^{T}\n\t\\\\\n\t\\bm g_{t_{5}} = \\begin{bmatrix} +0.707107, +0.707107, 0 \\end{bmatrix}^{T}\n\t\\quad\\quad\n\t\\bm g_{t_{6}} = \\begin{bmatrix} -0.707107, +0.707107, 0  \\end{bmatrix}^{T}\n\t\\\\\n\t\\bm g_{t_{7}} = \\begin{bmatrix} -0.707107, -0.707107, 0  \\end{bmatrix}^{T}\n\t\\quad\\quad\n\t\\bm g_{t_{8}} = \\begin{bmatrix} +0.707107, -0.707107, 0  \\end{bmatrix}^{T}\n\\end{gather*}\n\\begin{figure}[htb]\n\t\\centerline{\n\t\\includegraphics[]{Figures/8ThrConfig}\n\t}\n\t\\caption{Illustration of an 8-thruster ACS configuration}\n\t\\label{fig:8ThrConfig}\n\\end{figure}\n\\begin{figure}[p]\n\t\\centering\n\t\\subfigure[Percent Torque Error]\n\t{\\label{fig:minTorquePer}\n\t\\includegraphics[width=0.45\\textwidth]{Figures/minTorquePer}} \n\t\\\\\n\t\\subfigure[Thruster Control Implementation Effort]\n\t{\\label{fig:minTorqueSumF} \n\t\\includegraphics[width=0.45\\textwidth]{Figures/minTorqueSumF}}  \n\t\\subfigure[Net Thruster Disturbance Force]\n\t{\\label{fig:minTorqueNetF} \n\t\\includegraphics[width=0.45\\textwidth]{Figures/minTorqueNetF}}  \n\t\\caption{ACS Thruster Mapping Performance Mapping Illustration Comparing the 1-stage and 2-stage minimum norm solution to the thruster mapping of a nonlinear optimization solution.}\n\t\\label{fig:minTorque}\n\\end{figure}\n\n\nThe resulting configuration is illustrated in Figure~\\ref{fig:8ThrConfig}.  In this setup the center of mass position vector is set to $\\bm r_{\\text{COM}} = (0,0,0)^{T} \\text{ m}$.  The following plots show the thruster firing performance by considering a rang of scenarios.  The first case assumes all thrusters are available, and the $\\bm r_{\\text{COM}}$ vector is known perfectly.  The second and third case also have all thrusters available, but the $\\bm r_{\\text{COM}}$ vector knowledge is off by 10cm or 5cm in the $z$ direction.  The 4th case has the perfect $\\bm r_{\\text{COM}}$ vector, but the first thruster location is off by 1cm in the $y$ direction.  The 5th case again assumes a 10cm COM offset, but also that only 4/8 thrusters are available.  In essence, all the lower or upper thruster have become un-available.  The 6th and 7th case assumes perfect COM knowledge, but either the last one or last two thrusters are un-available.  \n\n\nThe resulting performance is illustrated in Figure~\\ref{fig:minTorque}.  Here 20 random $\\bm L_{r}$ torques are generated, and the mean results are shown.  The $[C]$ matrix is set to the identity matrix to control all three axes.   The 1-stage minimum norm algorithm is compared to an optimal thruster firing solution which minimizes the net thruster forces used, the net disturbance torque onto the craft, all subject to producing the desired control torque.    Regarding generating the desired control torque, only when 1 or 2 thrusters were lost did the algorithm have issues generating the required torque.  In all other cases the desired torque was always produced as shown in Figure~\\ref{fig:minTorquePer}.  In comparison, the 2-stage minimum norm algorithm performs very well in these latter cases where 1-2 thrusters are lost, yielding only very small torque errors on average.  \n\nThe control effort required to achieve this torque is shown in Figure~\\ref{fig:minTorqueSumF}.  Here the $F_{i}$ thruster force values are simply summed to have a sense of how much on-time or fuel is required for a given scenario.  If all ACS thrusters are operating and the COM is perfectly modeled is the control effort equivalent to the optimal solution.  In all other case the effort is about 10-20\\% larger.  in contrast, the 2-stage minimum norm algorithm control efforts in the cases with lost thrusters is very similar to those of the optimal answers.  This illustrates the robustness achieved by adding this 2nd stage if some thrusters are lost.  \n\nFinally, to see how well this algorithm is able to avoid net disturbance forces onto the spacecraft, the results in Figure~\\ref{fig:minTorqueNetF} are shown.  Overall the 1-stage algorithm did well, producing 0 net force in the ideal case and the case where the 1st thruster location is different, and matches the optimal answer for the lost thruster deck and lost single thruster case.  In the other cases there is some net disturbance force.  The 2-stage algorithm only differs here when thrusters are lost.  Here the net disturbance torque is higher than the 1-stage solution.  However, this is an expected result as the 1-stage solution produces huge torque errors, while the 2-stage solution produces a very different thruster solution which yields very small torque errors. \n\nOverall the 2-stage thruster firing performs very well in comparison to the the optimal thruster firing solutions.  The optimal solutions are computationally very expensive and not suitable to realtime flight-software implementations.  \n\n\n\n\n\n\n\n\n\\subsection{DV Thruster Configuration}\nNext consider a DV thruster configuration where the off-thruster-axis control torques are produces through off-pulsing.  Let the DV system have a total of $N = 6$ thrusters with the following body-fixed locations:\n\\begin{align*}\n\t\\label{eq:th:loc}\n\t\\bm r_{1} &= \\begin{bmatrix} 0, 0.413, -0.1671  \\end{bmatrix}^{T} \\text{ m}\n\t& \n\t\\bm r_{2} &= \\begin{bmatrix} 0.357668, 0.2065, -0.1671  \\end{bmatrix}^{T} \\text{ m}\n\t\\\\\n\t\\bm r_{3} &= \\begin{bmatrix} 0.357668, -0.2065, -0.1671 \\end{bmatrix}^{T}\t \\text{ m}\n\t&\n\t\\bm r_{4} &= \\begin{bmatrix} 0, -0.413, -0.1671  \\end{bmatrix}^{T} \\text{ m}\n\t\\\\\n\t\\bm r_{5} &= \\begin{bmatrix} -0.357668, -0.2065, -0.1671  \\end{bmatrix}^{T}\t \\text{ m}\n\t&\n\t\\bm r_{6} &= \\begin{bmatrix} -0.357668, 0.2065, -0.1671 \\end{bmatrix}^{T} \\text{ m}\n\\end{align*}\nwith the force unit direction vectors given by $\\hat{\\bm g}_{t_{i}} = (0,0,1)^{T}$ as illustrated in Figure~\\ref{fig:6ThrConfig}.\n\\begin{figure}[t]\n\t\\centerline{\n\t\\includegraphics[width=0.4\\textwidth]{Figures/dvThrConfig}\n\t}\n\t\\caption{Illustration of an 6-thruster DV configuration}\n\t\\label{fig:6ThrConfig}\n\\end{figure}\n\n\n\\begin{figure}[t]\n\t\\centering\n\t\\subfigure[Percent Torque Error]\n\t{\\label{fig:minTorquePerDV}\n\t\\includegraphics[width=0.4\\textwidth]{Figures/dvTorquePer}} \n\t\\subfigure[Thruster Control Implementation Effort]\n\t{\\label{fig:minTorqueSumFDV} \n\t\\includegraphics[width=0.45\\textwidth]{Figures/dvSumF}}  \n\t\\caption{DV Thruster Mapping Performance Mapping Illustration Comparing the 1-stage and 2-stage minimum norm solution to the thruster mapping of a nonlinear optimization solution.}\n\t\\label{fig:minTorqueDV}\n\\end{figure}\n\nFigure~\\ref{fig:minTorqueDV} illustrates the DV off-pulsing performance for 3 scenarios.  The 1st one has all thrusters available and no COM error.  The 2nd case adds 2cm COM offsets to the $x$ and $y$ axes, while the 3rd case has no COM error but lost an opposing set of thrusters.  Again 20 random $\\bm L_{r}$ vectors are generated and the mean performance evaluated.  As only torques about the $x$ and $y$ axis can be controlled with this DV thruster configuration, the control axis matrix is set to \n$$\n\t[C] = \\begin{bmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & 1 & 0\n\t\\end{bmatrix}\n$$\n\nThe torque implementation errors are compared in Figure~\\ref{fig:minTorquePerDV}.  The 2-stage process outlined above is able to produce the required torques in all cases, illustrating good robustness to COM offsets and loosing 2/6 thrusters.  Figure~\\ref{fig:minTorqueSumFDV} illustrates the net off-pulsing effort required to achieve these random control torque vectors.  The 2-stage algorithms requires slightly more off-pulsing than the optimal solution.  However, the difference isn't very large, especially in comparison to the drastically faster computational evaluation time.  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Module Parameters}\n\\subsection{$\\epsilon$ Parameter}\nThe minimum norm inverse requires a non-zero determinant value of $[D][D]^{T}$.  For this setup, this matrix is a scalar value\n\\begin{equation}\n\tD_{2} = \\text{det}([D][D]^{T})\n\\end{equation}\nIf this $D_{2}$ value is near zero, then the full 3D $\\bar{\\bm L}_{r}$ vector cannot be achieved.  A common example of such a scenario is with the DV thruster configuration where all $\\hat{\\bm g}_{t_{i}}$ axes are collinear.  Torques about these thrust axes cannot be produced.  In this case, the minimum norm solution is adjusted to only match the torques along the control matrix $[C]$ sub-space.  Torques being applied outside of $\\hat{\\bm c}_{j}$ is not possible as $D_{2}$ is essentially zero, indicating the other control axis cannot be controlled with this thruster configuration.  \n\nThe minimum norm torque solution is now modified to use\n\\begin{equation}\n\t\\bar{\\bm F} = ([C][\\bar D])^{T}( [C][\\bar D][\\bar D]^{T}[C]^{T})^{-1} [C] {\\bm L}_{r}\n\\end{equation}\nAs the thruster configuration cannot produce a general 3D torque, here the $[C]$ matrix must have either 1 or 2 control axes that are achievable with the given thruster configuration.  \n\nTo set this epsilon parameter, not the definition of the $[D]$ matrix components $\\bm d_{i} = (\\bm r_{i} \\times \\hat{\\bm g}_{t_{i}})$. Note that $\\bm r_{i} \\times \\hat{\\bm g}_{t_{i}}$ is a scaled axis along which the $i^{\\text{th}}$ thruster can produce a torque.  The value $\\bm d_{i}$ will be near zero if the dot product of this axis with the current control axis $\\hat{\\bm c}_{j}$ is small.  \n\nTo determine an appropriate $\\epsilon$ value, let $\\alpha$ be the minimum desired angle to avoid the control axis $\\hat{\\bm c}_{j}$ and the scaled thruster torque axis $\\bm r_{i} \\times \\hat{\\bm g}_{t_{i}}$ being orthogonal.  If $\\bar r$ is a mean distance of the thrusters to the spacecraft center of mass, then the $d_{i}$ values must satisfy\n\\begin{equation}\n\t\\frac{d_{i}}{\\bar r} > \\cos(90\\dg - \\alpha) = \\sin\\alpha\n\\end{equation}\nThus, to estimate a good value of $\\epsilon$, the following formula can be used\n\\begin{equation}\n\t\\epsilon \\approx d_{i}^{2} = \\sin^{2}\\!\\alpha \\ \\bar{r}^{2}\n\\end{equation}\nFor example, if $\\bar{r} = 1.3$ meters, and we want $\\alpha$ to be at least 1$\\dg$, then we would set $\\epsilon = 0.000515$.\n\n\\subsection{$[C]$ matrix}\nThe module requires control control axis matrix $[C]$ to be defined.  Up to 3 orthogonal control axes can be selected.  Let $N_{c}$ be the number of control axes.  The $N_{c}\\times 3$ $[C]$ matrix is then defined as\n\\begin{equation}\n\t[C] = \\begin{bmatrix}\n\t\t\\hat{\\bm c}_{1}\n\t\t\\\\\n\t\t\\vdots\n\t\\end{bmatrix}\n\\end{equation}\n\nNot that in python the matrix is given in a 1D form by defining {\\tt controlAxes\\_B}.  Thus, the $\\hat{\\bm c}_{j}$ axes are concatenated to produce the input matrix $[C]$. \n\n\\subsection{{\\tt thrForceSign} Parameter}\nBefore this module can be run, the parameter {\\tt thrForceSign} must be set to either +1 (on-pulsing with the ACS configuration) or -1 (off-pulsing with the DV configuration).\n\n\n\\bibliographystyle{unsrt}\n\\bibliography{references}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "82cbf8a6956c0cbf0d9c7f1b2b0d4de03535483d", "size": 21149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/fswAlgorithms/effectorInterfaces/thrForceMapping/_Documentation/Basilisk-ThrusterForces-20160627.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/thrForceMapping/_Documentation/Basilisk-ThrusterForces-20160627.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/thrForceMapping/_Documentation/Basilisk-ThrusterForces-20160627.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": 57.0053908356, "max_line_length": 947, "alphanum_fraction": 0.7243841316, "num_tokens": 6480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6177050864643969}}
{"text": "% !TEX root = ../main.tex\n\\newpage\n\\section{\\theory Hebbian Learning and Synaptic Plasticity} \\label{sec:HebbianLearningAndSynapticPlasticity}\n\\vspace{1mm}\n\\begin{quote}\n\\textsl{When an axon of cell A is near enough to excite a cell B and repeatedly or persistently takes part in firing it, some growth process or metabolic change takes places in one or both cells such that A's efficiency, as one of the cells firing B, is increased.}\\cite{Hebb1949}\n\\end{quote}\n\nThis quote from psychologist Donald Hebb has influenced the neuroscientific community since 1949. In its essence, Hebb postulated that neurons that \\textsl{fire together, wire together}. It has since become known as \\textsl{Hebbian learning}, and is simply modelled as a positive correlation between the action potentials of spiking neurons. It has been proven in vivo in many studies \\cite{ChrolCannon2014}, just like its counterpart, \\textsl{anti-Hebbian learning}, where a negative correlation can be found. In many applications, both processes are present. \n\n\n\\subsection{Spike-timing dependant plasticity}\nOne specific temporal interpretation of these ideas is \\textsl{spike-timing-dependent plasticity} (\\STDP), where the relative timing of action potentials from the pre- and postsynaptic neuron determine causality \\cite{Kempter1999, Gerstner2002}. If the postsynaptic neuron B fires right after the presynaptic neuron A, then we can expect the synaptic strength from post- to presynaptic neuron to increase, and vice versa. Whether A pushes B or B listens to A  is trivial.\n\nLet us say that neuron $\\theta_i$ spikes at time $t_i$ and that neuron $\\theta_j$ spikes at $t_j$. Taking the time difference $\\Delta t_{ij}$ as $t_j - t_i$, we can say that when $\\Delta t_{ij} > 0$ the spikes are correlated (there exists a temporally causal relation), and we can model an increase in synaptic strength of the connection from $\\theta_i$ to $\\theta_j$, which we will gather in the \\textsl{coupling matrix} $K_{ij}$. In the light of anti-Hebbian learning we can decrease $K_{ij}$ when $\\Delta t_{ij} < 0$, as there is no causal relation. We will find an expression for $\\Delta K_{ij}$ in function of $\\Delta t_{ij}$ so that at each time-step we can update $K_{ij} \\leftarrow K_{ij} + \\Delta K_{ij}$.\\\\\n\nWe can think of the coupling matrix as the continuous interpretation of $\\kappa A_{ij}$, where synaptic strength and network topology go hand in hand. This also means that we need to redefine some concepts:\n\\begin{align}\n\\kinbi = \\sum_{j=1}^{N} \\rvert K_{i j} \\rvert \\hspace{15mm} \n\\koutbj = \\sum_{i=1}^{N} \\rvert K_{i j} \\rvert \\hspace{15mm} \n\\kmean &= \\frac{1}{N} \\sum_{i,j=1}^{N} \\rvert K_{i j} \\rvert \\hspace{15mm}  \\label{eq:redefineFromK}  %\\hat{\\kmean} = \\frac{1}{N} \\sum_{i,j=1}^{N} K_{i j}\n\\end{align}\nThe absolute value ensures that we capture the magnitude of the coupling strength. %The reason we want to distinguish between $\\kmean$ and $\\hat{\\kmean}$ is that for some parts of the investigation it is beneficial to study how inhibitive and excitatory coupling strengths influence each other.\\\\\n\nAlso the network of Theta neurons needs a redefinition:\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_adaptive} \\\\\nI_{i}(t) &=\\frac{1}{\\kmean} \\sum_{j=1}^{N} K_{i j} \\cdot \\mathcal{P}_{n}(\\theta_{j}) \\label{eq:thetaneuronnetworkcurrent_adaptive}\n\\end{align}\n\n\nThe functions $W(t)$ that relate $\\Delta t_{ij}$ to $\\Delta K_{ij}$ are called \\textsl{learning windows},  as they define a range in which $K_{ij}$ is able to adapt or \\textsl{learn}, and also when learning is optimal. When signals between neurons show a very large time difference (negative or positive) we do not expect them to be correlated. %Because the learning windows are generally not symmetrical we can also expect the coupling matrix to be asymmetrical. \nThe magnitude of these functions is small, as it is assumed that learning dynamics happen at a slower timescale than the neuronal dynamics.\n\nAnother characteristic is the integral over the learning window. A window with a negative integral directs synaptic strengths mostly towards inhibitory behaviour, and vice versa with a positive integral. An integral of zero would mean that both inhibitory and excitatory synapses are stimulated equally. It has been proven that $\\int W(\\tau) \\mathop{d\\tau}$ is the magnitude of the correlation between signals \\cite{Gerstner2002}. \\\\\n\n%The magnitude of change is modulated by an asymmetric biphasic learning window around pulses originating from the postsynaptic neuron. Asymmetric because the peak is not situated at 0 and the integral over the window is generally positive, biphasic because this allows both to strengthen and weaken coupling strengths \\cite{Gerstner2002}. \n\nThis approach simplifies modelling the neuronal back-propagation, where another pulse is generated as an echo of the action potential which travels through the neuron dendrites (so, backwards). This behaviour is believed to adjust the presynaptic weights, though it is a controversial subject \\cite{Gerstner2002}. \\\\\n\nIn recent years, criticism on \\STDP has been growing, as experimental data has shown that \\STDP is usually accompanied by homeostatic plasticity of the neurons excitability and the synaptic strength. Basing our learning behaviour on the correlation between neuronal activity can be quite unstable: changes to the synaptic strength cause changes in the postsynaptic firing rate, which generates further changes to the synaptic strength in a positive feedback loop. Processes like \\textsl{intrinsic plasticity} (\\IP), where one neuron's excitability changes over time as to self-regulate sensitivity to incoming action potentials, or \\textsl{synaptic scaling}, where synapse characteristics are adjusted in unison to counteract positive feedback loops, have proven to stabilise the synchronisation \\cite{ChrolCannon2014, Kirkwood2019}. When \\STDP and \\IP are combined, it seems like the two process balance each other out and stable network topologies can be found \\cite{Song2017}.\n\n\n\\subsection{Formulations of \\STDP as a model}\n\\subsubsection{The Kempter method}\n%Analysis of a distinct \\STDP model was done in \\cite{Kempter1999}. \n\\cite{Kempter1999} proposed a distinct \\STDP model. Following the notation, we will denote the sequence of action potentials, the \\textsl{spike train}, coming from each neuron $\\theta_i$ as $S_i^{\\rm out}(t) = \\sum_{n} \\delta (t-t_{i}^{n})$, where $t_{i}^{n}$ is the time that $\\theta_i$ has fired. Similarly, we will denote the spike train coming into each neuron $\\theta_i$ as $S_i^{\\rm in}(t) = \\sum_{f} \\delta (t-t_{i}^{f})$ with $t_{i}^{f}$ being the time that a neighbouring neuron has spiked. Now we can say that the synaptic strengths are adjusted as:\n\\begin{align}\n\\Delta K_{ij} &= \\int_{t}^{t+\\mathcal{T}} w^{\\rm{out}} S_i^{\\rm out}(\\tau) + w^{\\rm{in}} S_{j}^{\\rm {in}}(\\tau) \\mathrm{d}\\tau\n+ \\iint_{t}^{t+\\mathcal{T}} W( \\tau^\\prime - \\tau) S_{i}^{\\rm out}(\\tau) S_{j}^{\\rm in}( \\tau^\\prime) \\mathrm{d} \\tau \\mathrm{d} \\tau^\\prime\n\\label{eq:KempterSTDPFormulation1} \\\\\n&= \\sum_{t_i^{n}\\in \\mathcal{T}} w^{\\mathrm{out}} + \\sum_{t_{j}^{f} \\in \\mathcal{T}} w^{\\mathrm{in}} + \\sum_{t_{j}^{f}, \\: t_i^{n} \\in \\mathcal{T}} \\hspace{-2mm} W (t_{j}^{f}-t_i^{n} ) \\label{eq:KempterSTDPFormulation2}\n\\end{align}\nwith $\\mathcal{T}$ the time domain over which learning takes place. $w^{\\mathrm{in}} > 0$ and $w^{\\mathrm{out}} < 0$ are small weights on the in- and outgoing action potentials. In \\eqref{eq:KempterSTDPFormulation1} we can recognise the correlation between signals as a convolution over the learning window. We will refer to \\eqref{eq:KempterSTDPFormulation2} as the Kempter method. \\\\\n\nThe following learning window is proposed:\n\\begin{align}\nW(t)_K = A\n\\begin{cases}\n\\left[\\left(1-\\frac{t}{\\tilde{\\tau}_{p}}\\right) - \\left(1-\\frac{t}{\\tilde{\\tau}_{n}}\\right)\\right] \\cdot \\exp \\left( \\frac{t}{\\tau_{\\rm syn}} \\right) & \\text{for } t \\leq 0 \\\\\n \\exp \\left(-\\frac{t}{\\tau_{p}}\\right) - \\exp \\left(-\\frac{t}{\\tau_{n}} \\right) & \\text{for } t > 0\n\\end{cases} \\label{eq:learningwindowKempter1999}\n\\end{align}\nHere $t$ is the delay between presynaptic spike arrival and postsynaptic firing, $A$ is a small learning parameter and all $\\tau$'s are time constants. The values are given as $A = 10^{-5}$, $\\tau_{\\rm syn} = 5$ ms, $\\tau_{p} = 1$ ms and $\\tau_{n} = 20$ ms. $\\tilde{\\tau}_{p} \\equiv \\tau_{\\rm syn} \\tau_{p} / (\\tau_{\\rm syn} + \\tau_{p})$ and $\\tilde{\\tau}_{n} \\equiv \\tau_{\\rm syn} \\tau_{n} / (\\tau_{\\rm syn} + \\tau_{n})$. $\\int W(\\tau)_K \\mathop{d \\tau} = 4.75 \\times 10^{-8}$ so that the correlation is positive. \\\\\n\n$w^{\\mathrm{in}}$ and $w^{\\mathrm{out}}$ are necessary for $K_{ij}$ to reach an equilibrium, which is proven from the average learning dynamics. Using an inhomogeneous Poisson process with time-dependent intensities to generate spike trains, the learning equation \\eqref{eq:KempterSTDPFormulation2} is found to converge to a stable equilibrium, also when different types of noise are added to selections of neurons \\cite{Kempter1999}. The authors do understand the concept of topology, as the variation of the coupling strength between nodes is examined, but they did not investigate the relation between coupling strength and spiking behaviour. The question will now be whether convergence of the synaptic strength still occurs when we will apply \\STDP to our network of Theta neurons, as changes to the coupling strength will also influence the spiking dynamics between neurons, which in turn will affect the learning again. The distribution of spikes in each spike train might not be coming from a recognisable distribution.\\\\\n\nTo counteract the excitatory nature of the learning window, the authors propose $w^{\\mathrm{in}} = A$ and $w^{\\mathrm{out}} = -1.0475 \\cdot A$ so that the amplitude of these weights is on the same order as the magnitude of the learning window \\cite{Kempter1999}. This is a regulatory process, as neurons are punished for sending out  many spikes over time by decreasing their influence over neighbours more than the increase in influence of their neighbours over them. This threshold can be overcome by teaching the neurons to spike at the right time (with respect to its neighbours' spikes) as then the learning window yields an increase in synaptic strength.%This process is inherently asymmetric. \\\\\n\n\n\\subsubsection{The Song method}\nAnother formulation of \\STDP as a mathematical model can be found in \\cite{Song2000}. It is postulated without being concerned about the biological aspect too much, simplifying some of the ideas of \\cite{Kempter1999}. The synaptic strengths are simply updated with:\n\\begin{align}\n\\Delta K_{ij} &= K^{\\rm max} \\cdot \\sum_{t_{j}^{f}, \\: t_i^{n} \\in \\mathcal{T}} \\hspace{-2mm} W (t_{j}^{f}-t_i^{n} ) \\label{eq:SongSTDPFormulation}\n\\end{align}\nwhere $K^{\\rm max}$ is the maximum allowed synaptic strength, so that we can think of \\eqref{eq:SongSTDPFormulation} as taking a percentage of the maximum coupling. The authors also constrain $0 \\leq K_{ij} \\leq K^{\\rm max}$, as there is no regulatory process like in \\eqref{eq:KempterSTDPFormulation2}. In their further work on \\STDP and \\IP the authors booked remarkable progress, and their work on the Izhikevich model is very interesting for our application \\cite{Song2017}. We will refer to \\eqref{eq:SongSTDPFormulation} as the Song method. \n\nThe learning window is then again defined as a discontinuous function:\n\\begin{align}\nW(t)_S =\n\\begin{cases}\nA_{n} \\cdot \\exp \\left(\\frac{t}{\\tau_n}\\right)  & \\text{for } s \\leq 0 \\\\\nA_{p} \\cdot \\exp \\left(\\frac{-t}{\\tau_p}\\right) & \\text{for } s > 0 \n\\end{cases} \\label{eq:learningwindowSong2000}\n\\end{align}\nwhere $A_p = 0.005$, $A_n = -0.00525$ and $\\tau_p = \\tau_n = 20$ ms. $\\int W(\\tau)_S \\mathop{d \\tau} = -5.0 \\times 10^{-6}$ so we expect the weights to be suppressed towards a negative value. Interestingly, the line between reward and punishment is very thin, as the largest increase and largest decrease in synaptic strength lie right next to each other on the spectrum. \\\\\n\nAs $K_{ij}$ is only allowed to be positive, the negative correlation of the learning window pushes most of the synaptic strengths towards zero. The range of coupling strengths is also very restricted and only allowed to change over a small interval: $K^{\\rm max}$ = 0.03 \\cite{Song2000, Song2017, ChrolCannon2012}. The learning dynamics, encoded into the topology of the network, show how the node degrees are pushed towards 0, with only a small group of neurons managing to learn the optimal spike timing. The spiking rate of all nodes in the network converges to a normal distribution. However, no mention is made of convergence of the node degrees, as the learning procedure is halted artificially.\\\\\n\nRecently, triphasic learning windows have been used to account for when it takes too long for the postsynaptic neuron to fire, and thus to decorrelate the relation between neurons that spike too soon and too late. These learning windows are curves that were fitted to experimental data of the cortex and the hippocampus \\cite{ChrolCannon2014}. \nExtending the work of \\cite{Song2000} we can find a brief investigation of network topology and clustering using triphasic windows, \\cite{ChrolCannon2012}. The method is as in \\eqref{eq:learningwindowSong2000}, with the following learning window:\n\\begin{align}\nW(t)_C = A_{p} \\cdot \\exp \\left(\\frac{-\\left(t - 15 \\right)^{2}}{ \\tau_{p}}\\right) - A_{n} \\cdot \\exp \\left(\\frac{-\\left(t - 20\\right)^{2}}{ \\tau_{n}}\\right)  \\label{eq:learningwindowChrolCannon2012}\n\\end{align}\nwhere $A_{p}=0.23$, $A_{n}=0.15$, $\\tau_{p}=200$ and $\\tau_n = 2000$. $\\int W(s)_C \\mathop{d s} = -6.0 \\times 10^{-3}$. \\\\\n\nWhen comparing the qualities of the different learning windows presented here, one can quickly notice the difference in magnitude between the learning windows. That does not necessarily include the magnitude of the correlation, but the magnitude of the window itself. In \\eqref{eq:learningwindowKempter1999}, the learning rate is a few orders of magnitude smaller than in \\eqref{eq:learningwindowChrolCannon2012} and this resulted in extremely slow convergence when testing. For \\eqref{eq:learningwindowSong2000} this issue was solved in \\cite{ChrolCannon2012} by using $A _p = 0.1$ and $A_n = -0.12$. In the same spirit, we will therefore use $A = 8.0 \\times 10^{-2}$ in \\eqref{eq:learningwindowKempter1999}. These alterations yield $\\int W(\\tau)_S \\mathop{d \\tau} = -4.0 \\times 10^{-4}$ and $\\int W(\\tau)_K \\mathop{d \\tau} = 3.8 \\times 10^{-4}$.\\\\\n\n%The learning windows generally have $W(t^{\\ast}) = 0$ for $t^{\\ast} \\geq 0$. This means that no learning will take place when the delay between neuron spikes is exactly $t^{\\ast} \\geq 0$. The triphasic windows show two of those points. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = \\textwidth]{../Figures/Learning/LearningWindows.pdf}\n\\caption{Three different biphasic learning windows. Left: with $W_K$ the the learning spectrum is quite narrow. Middle: we can see how in $W(t)_s$ a slightly larger emphasis is put on the anti-Hebbian learning. Right: a triphasic window can punish the synaptic strength when signals arrive either too early or too late. For simplicity, we will use the same colour to identify the results from using the different windows.}\n\\label{fig:LearningWindows}\n\\end{figure}\n\nIt is important to notice that learning only occurs when neurons spike, so that equilibrium states will halt the learning process. However, these states were rarely encountered during the testing process, and it seems like there continues to exist enough randomness in the states of $\\theta_i$ to persist spiking.\nWhen implementing \\STDP, a time-step smaller than 0.01 is necessary, otherwise important details in the learning dynamics that are captured by the shape of the learning window will be lost. \n\nAnother important observation is that when computing the time delay between spikes of the same neuron, $t_{i}^{f}-t_i^{n}$ will always be zero by definition. It is much simpler to perform this operation than to filter it out. In the case that $W(0)$ is zero, $K_{ii}$ will not change. Though for $W_S$ and $W_C$ we have $W(0) < 0$ so that $K_{ii}$ will always be decrease in magnitude. Conclusions can therefore not be drawn from self-coupling.\n\n%We can model intrinsic plasticity by adjusting the neuron's excitability as the inverse of the firing rate: he more spikes that a neuron will receive, the less affected it is \\cite{Song2017}.  An observed phenomenon is that the excitability evolves together with the coupling strength, but that at the extremes this relation reverses \\cite{Debanne2017, Debanne2018}.  These types of plasticities should be relatively easy to implement but have no impact on the network topology.\n\n\n\\subsection{Synaptic Scaling}\nThere is no upper or lower bound on the synapse strength, and generally connection strengths are nonzero. Positive reinforcement loops might disturb the learning process, which would not be beneficial for the model. One technique we can apply to keep the strengths within a definitive range is to scale homeostatically - a method where any increases in synaptic strength will balance out any decreases by scaling:\n\\begin{align}\nK_{ij}^s = K_{ij} \\frac{\\frac{1}{N} \\sum_{i,j} K_{ij}}{\\sum_{i} K_{ij}}\n\\end{align}\nIn this way, the out-degrees will remain constant. Using this approach, something has to remain constant, whether that is $\\kmean$, or $\\kmean^2$ or any other property of the adjacency matrix. However, this property is not one we are after: we want a method that is able to change the network topology entirely.\n\n\n\\subsection{Intrinsic Plasticity} \\label{sec:IP}\nInstead of scaling the weights to preserve a certain quantity in the network, we can allow the neurons to adjust their sensitivity to incoming signals. So when some synaptic strengths are increased, we can reduce the excitability, and vice-versa. This should counteract positive feedback. \n\nIf we look at the formulation of the network of Theta neurons \\eqref{eq:thetaneuronnetworkcurrent_adaptive}, we can see that $\\eta_i$ is the threshold on $I_i(t)$ for which the result of the \\PRC will be positive or negative. The neuron action potentials $\\mathcal{P}_n(\\theta_j)$ are scaled by the coupling matrix and the mean node degree. We expect that when neurons learn to adapt $K_{ij}$ and $\\eta_i$, the two will try to cancel each other out.\n\nIn \\cite{Song2017} an \\IP method is introduced in detail. We can simply update $\\eta_{i} \\leftarrow \\eta_{i} + \\eta_{\\max } \\cdot \\phi_{i}$, where: \n\\begin{minipage}{.45\\textwidth}\n   \\centering\n   \\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width = \\textwidth]{../Figures/Learning/IPlearningFunction.pdf}\n\t%\\caption{The learning behaviour for intrinsic plasticity as proposed in \\cite{Song2017}.}\n\t\\label{fig:IPlearningFunction}\n\t\\end{figure}\n\\end{minipage}\n\\begin{minipage}{.55\\textwidth}\n\\begin{align}\n\t\\phi_{i} (t) =\n\t\\begin{cases}\n\t-\\alpha \\cdot \\exp \\left(\\frac{T_{\\min }-t}{T_{\\rm min }}\\right) \\hspace{10mm} t<T_{ \\rm min } \\\\ \n\t\\alpha \\cdot \\exp \\left(\\frac{t-T_{\\rm max }}{T_{\\max }}\\right) \\hspace{12mm} t >T_{\\rm max } \\\\ \n\t0 \\hspace{24.5mm} T_{ \\rm min } \\leq t \\leq T_{\\rm max }\n\t\\end{cases}\n\\end{align}\n\\vspace{10mm}\n\\end{minipage}\nThe argument $t$ represents the time that has passed between successive spike of the same neuron, the \\textsl{inter-spike interval} (\\ISI). This is always a positive number. \\\\\n\nThe results of introducing \\IP seem to stabilise the resulting topologies in the Song method. Many more nodes seem to survive with a node degree that is not at the extremes, and there seems to exist an interesting relation between in- and out-degree vectors \\cite{Song2017}.\n\n\n\n%\\begin{figure}[H]\n%\\centering\n%\\includegraphics[width = 0.5\\textwidth]{../Figures/Learning/IPlearningFunction.pdf}\n%\\caption{The learning behaviour for intrinsic plasticity as proposed in \\cite{Song2017}.}\n%\\label{fig:IPlearningFunction}\n%\\end{figure}\n\n%\\textcolor{red}{QUESTION}: \\textsl{is it necessary to include more background theory on Hebbian Learning?}\n", "meta": {"hexsha": "b4970b6ee5e74254e5300dda70581136343035f7", "size": 20249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Mainmatter/Hebbian Learning and Plasticity.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/Hebbian Learning and Plasticity.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/Hebbian Learning and Plasticity.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": 123.4695121951, "max_line_length": 1029, "alphanum_fraction": 0.7553953282, "num_tokens": 5563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6177047480871413}}
{"text": "\\SecDef{prelim}{Preliminaries}\n\nIn this chapter I use a specific notation to simplify expressions. A vector $v \\in \\field{n}$ is considered a row vector. Any matrix $L \\in \\F_2^{n\\times m}$ defines a linear mapping $\\varphi \\colon \\F_2^n \\rightarrow \\F_2^m, \\ x \\mapsto xL$.\n\n\\subsection{Higher-Order Derivatives, Affine Equivalence and Algebraic Immunity of Boolean Functions}\n\nBoolean functions have several applications in cryptography, e.g., for designing stream ciphers. In order to resist algebraic attacks, the notion of algebraic immunity was introduced in 2004 as follows.\n\n\\begin{definition}[Algebraic immunity~\\cite{EC:MeiPasCar04}]\nLet $f\\colon \\F_2^n \\rightarrow \\F_2$. An $n$-bit Boolean function $g \\neq 0$ is called an \\emph{annihilator} of $f$, if $f g = 0$. The set of annihilators of $f$ together with $g=0$ form a vector space, denoted by $\\AN(f)$. We denote by $\\AN_d(f)$ the subspace of annihilators of $f$ with algebraic degree at most $d$ together with the zero-function. The \\emph{algebraic immunity} of $f$, denoted $\\AI(f)$, is defined as the minimum $k$ for which $\\AN_k(f) \\cup \\AN_k(f+1) \\neq \\{0\\}$.\n\\end{definition}\n\nAn important concept for Boolean function is the notion of affine equivalence. \n\n\\begin{definition}[Domain Affine Equivalence]\nTwo Boolean functions $f,g\\colon \\F_2^n \\rightarrow \\F_2$ are called \\emph{domain affine equivalent} if there exists a linear bijection $\\varphi \\colon \\F_2^n \\rightarrow \\F_2^n$ and a vector $c \\in \\F_2^n$ such that $g = f \\circ (\\varphi + c)$. If $c = 0$, $f$ and $g$ are called \\emph{linear equivalent}.\n\\end{definition}\nI remark that, in the literature, \\emph{domain affine equivalence} of Boolean functions is called simply \\emph{affine equivalence}. I specify the term to avoid ambiguity, as, for example, $g$ and $g\\oplus1$ are not domain affine equivalent in general.\nIt is well known that the weight, the algebraic degree and the dimensions of the annihilator spaces (and thus the algebraic immunity) are invariant under domain affine equivalence. \n\n\\subsection{Orthogonal Matrices and Preservation of Nonlinear Invariants}\n\nIn~\\cite{NonlinInv}, Todo, Leander and Sasaki introduced the \\emph{nonlinear invariant attack} and successfully distinguished the block ciphers Midori, Scream and iScream from a random permutation for a significant fraction of weak keys. For an $n$-bit permutation $G \\colon \\F_2^n \\rightarrow \\F_2^n$, the main idea consists in finding a non-constant $n$-bit Boolean function $f$ and a constant $\\varepsilon \\in \\F_2$ such that \n$$\n\\forall x \\in \\F_2^n\\colon f(x) = f(G(x)) + \\varepsilon.\n$$\n\nSuch a function $f$ is called an \\emph{invariant} for $G$.\nIn order to find an invariant for the cipher, Todo \\etal. observed that if $L \\in \\F_2^{n \\times n}$ is an orthogonal matrix, i.e., if $\\inprod{xL, yL} = \\inprod{x, y}$ for all $x,y \\in \\F_2^n$, then for all Boolean functions $f \\in \\BF{t}{2}$ it is\n\\eql{target_equation}{\n\\forall X \\in \\F_2^{t \\times n} \\colon\n\\bigoplus_{i=1}^n f\\big( (X^\\top)_i \\big) =\n\\bigoplus_{j=1}^n f\\big( ((XL)^\\top)_j \\big).\n}\nIn other words, \\emph{any} Boolean function $f\\colon \\F_2^t \\rightarrow \\F_2$ of algebraic degree at most 2 gives rise to an invariant over the linear layers of Midori, Scream and iScream of the form\n$(x_1,\\dots,x_n) \\mapsto f(x_1)+\\dots f(x_n)$, where $n$ denotes the number of S-boxes, $t$ denotes the bit length of the S-box and $x_i \\in \\F_2^t$.\n \nWe illustrate this from a slightly different point of view on the example of the linear layer used in Midori (see~\\cite{AC:BBISHA15}), which is defined by the following matrix:\n\\eql{midori}{\nL = \\matb{\n0 & 1 & 1 & 1 \\\\\n1 & 0 & 1 & 1 \\\\\n1 & 1 & 0 & 1 \\\\\n1 & 1 & 1 & 0\n}.\n}\nIt is easy to see that $L$ is orthogonal. Thus, according to \\EqRef{target_equation}, for \\emph{any} $f \\in \\BF{t}{2}$ and all $x_1,x_2,x_3,x_4 \\in \\F_2^t$, the following equation holds:\n\\eq{\n    &f(x_1) + f(x_2) + f(x_3) + f(x_4) = \\\\ &f(x_2+x_3+x_4)+f(x_1+x_3+x_4)+f(x_1+x_2+x_4)+f(x_1+x_2+x_3).\n}\n\nConsider an alternative way of proving this. The arguments of $f$ form an affine subspace of dimension 3, namely\n$$\nx_1 + \\Span(x_1+x_2, x_1+x_3, x_1+x_4).\n$$\nTherefore, the equation is equivalent to\n$$\n    \\delta_{x_1+x_2}\\delta_{x_1+x_3}\\delta_{x_1+x_4}f(x_1) = 0,\n$$\nwhich is clearly true for any $f \\in \\BF{t}{2}$ and any $x_1,x_2,x_3,x_4$ since all third-order derivatives of a quadratic function are equal to zero. This observation gives new insights on how to generalize the linear layer in order to preserve \\emph{higher-degree invariants}.\n\n\\begin{proposition}\n\\PropLabel{expanding-linear-high-degree}\nLet $d \\ge 2$ be an integer. Then there exists a matrix $L \\in \\F_2^{n \\times m}$ with $n = d+2, m=2^{d+1}-d-2$ and full rank $n$ such that for any $t \\ge 1$ and any $f \\in \\BF{t}{d}$, the following property holds: \n\\eql{invariant_preserving_linear}{\n\\forall X \\in \\F_2^{t \\times n} \\colon\n\\bigoplus_{i=1}^n f\\big( (X^\\top)_i\\big) =\n\\bigoplus_{j=1}^m f\\big( ((XL)^\\top)_j \\big).\n}\nAn example of such $L$ is given by a matrix with columns taken as all vectors from $\\field{n}$ with an odd Hamming weight greater or equal to 3.\n\\end{proposition}\n\\begin{proof}\nFor any $t \\ge 1$ and any $x_0,\\ldots,x_{d+1}\\in \\F_2^t$ consider the $(d+1)$-dimensional affine subspace\n\\[V = x_0 + \\Span(x_0+x_1,x_0+x_2,\\ldots,x_0+x_{d+1})\\;.\\]\nFor any Boolean function $f$ of degree $d$, any $(d+1)$-th derivative vanishes. Therefore, $\\bigoplus_{v \\in V} f(v) = 0$. This can be equivalently written as\n\\eql{higher-order-expanding}{\n    & f(x_0) + f(x_1) + \\ldots + f(x_{d+1}) = \\\\\n    & = \\bigoplus_{\\substack{I \\subseteq \\{1, \\ldots, d+1\\} \\\\ |I| \\ge 2 ~\\text{even}}}f(x_0 + \\bigoplus_{i \\in I}x_i) +\n        \\bigoplus_{\\substack{I \\subseteq \\{1, \\ldots, d+1\\} \\\\ |I| \\ge 3 ~\\text{odd}}}f(\\bigoplus_{i \\in I}x_i) \\\\\n    & = \\bigoplus_{\\substack{I \\subseteq \\{0, \\ldots, d+1\\} \\\\ |I| \\ge 3 ~\\text{odd}}}f(\\bigoplus_{i \\in I}x_i)\n    .\n}\nThe right-hand side contains $2^{d+1}-d-2$ applications of $f$. Let $Y$ be the set of the linear functions defining the arguments of $f$ in the right-hand side of \\EqRef{higher-order-expanding}, i.e.,\n$$\nY =\n\\pset{ \\bigoplus_{i \\in I}x_i ~\\biggm|~ I \\subseteq \\{0, \\ldots, d+1\\}, \\ |I| \\ge 3 ~\\text{odd} },\n$$\nand let $L$ be the matrix of the linear function that maps $(x_0, x_1, \\ldots, x_{d+1})$ to $(y_1, y_2, \\ldots, y_{2^{d+1}-d-2})$, where $y_i \\in Y$ and all $y_i$ are pairwise different. Then, \\EqRef{higher-order-expanding} is equivalent to \\EqRef{target_equation} with the described $L$.\n\nSince $m \\ge n \\ge 4$, any unit vector from $\\F_2^n$ can be expressed a linear combination of 3 columns of $L$, e.g., $$\n(1,0,0,0,\\ldots,0)=(1,1,1,0,\\ldots,0)+(1,0,1,1,\\ldots, 0)+(1,1,0,1,\\ldots,0).\n$$\nWe conclude that $L$ has full rank $n$.\n\\end{proof}\n\n\n\\begin{example}\nFor $d=2$ we obtain the orthogonal matrix given in \\EqRef{midori}. For $d=3$ we obtain an expanding linear mapping $\\varphi: \\field{5} \\to \\field{11}$ defined by the following $5 \\times 11$ matrix $L$:\n$$\nL = \\matb{\n0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\\\\n1 & 0 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\\\\n1 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n1 & 1 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\\\n}.\n$$\n\\end{example}\n\n\n", "meta": {"hexsha": "12477b712ba102c131044dfc2ee9e52d25d848b2", "size": 7255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9niLinear/2prelim.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/9niLinear/2prelim.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/9niLinear/2prelim.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": 65.3603603604, "max_line_length": 486, "alphanum_fraction": 0.6781529979, "num_tokens": 2636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.617678926987909}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\nI don't think derivatives are evil, per se --- I think they are dangerous.\n\\byline{Warren Buffett}\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  What is a half-space?  Define convex hull.\n\\end{problem}\n\n\\begin{problem}\n  Define the Wirtinger partial derivatives $\\displaystyle\\frac{\\partial}{\\partial z}$ and $\\displaystyle\\frac{\\partial}{\\partial \\conj{z}}$.\n\\end{problem}\n\n\\begin{problem}\n  What are the Cauchy-Riemann equations?\n\\end{problem}\n\n\\section{Numericals}\n\n\\begin{problem}\\label{cauchy-riemann-polar}What are the Cauchy-Riemann equations\\ldots in polar coordinates?\n\\end{problem}\n\n\\begin{problem}\n  For a natural number $n$ define $f : \\mathbb{C} \\to \\mathbb{C}$ by\n  \\[\n    f(r \\cos \\theta + i \\, r\\sin \\theta) = r^n \\cos \\left( n \\theta \\right) + i \\, r^n \\sin \\left( n \\theta \\right).\n  \\]\n  Use \\ref{cauchy-riemann-polar} to verify that $f$ satisfies the\n  Cauchy-Riemann equations.\n\\end{problem}\n\n\\begin{problem}\n  On a certain domain, define $f(z) = \\log \\abs{z} + i \\cdot \\Arg z$\n  and verify that $f$ satisfies the Cauchy-Riemann equations.\n\\end{problem}\n\n\\begin{problem}\n  Compute $\\displaystyle\\frac{\\partial}{\\partial z} \\left( z \\conj{z} \\right)$.\n\\end{problem}\n\n\\begin{problem}\\label{harmonic-conjugate}Let $u(x,y) = e^y \\sin x$.  Find $v(x,y)$ so that $u$ and $v$\n  satisfy the Cauchy-Riemann equations.  Such a function $v$ is a\n  \\textbf{harmonic conjugate} of $u$.\n\\end{problem}\n\n\\section{Exploration}\n\n\\begin{problem}\\label{cayley-transform}Relate the upper half-plane\n  $H = \\{ z \\in \\mathbb{C} : \\Imag z > 0 \\}$ and the open disk\n  $D = \\{ z \\in \\mathbb{C} : \\abs{z} < 1 \\}$ by finding $a,b,c,d \\in \\C$ so that the M\\\"obius transformation\n  \\[f(z) = \\frac{az + b}{cz + d}\\] yields a bijection $f : H \\to D$.\n\\end{problem}\n\n\\begin{problem}\\label{harmonic-necessary}Given $u : \\mathbb{R}^2 \\to \\mathbb{R}$, is it always possible to\n  find a function $v : \\mathbb{R}^2 \\to \\mathbb{R}$ so that $u$ and\n  $v$ satisfy the Cauchy-Riemann equations?\n\\end{problem}\n\n\\begin{problem}\\label{gauss-lucas}For $p \\in \\C[x]$, show that the convex hull of the zeroes of $p$\n  contains the zeroes of $p'$.  This is the \\textbf{Gauss-Lucas\n    theorem}.\n\\end{problem}\n\n\\begin{problem}\n  Suppose the smooth function $f : \\C \\to \\C$ satisfies the\n  Cauchy-Riemann equations.  Does $f'$ also satisfy the Cauchy-Riemann\n  equations?\n\\end{problem}\n\n\\begin{problem}\n  Suppose $f : \\R^2 \\to \\R^2$ satisfies the Cauchy-Riemann equations,\n  and consider curves $\\gamma_1, \\gamma_2 : (-1,1) \\to \\R^2$ passing\n  through the origin so that $\\gamma_1(0) = \\gamma_2(0) = (0,0)$.\n  Relate the angle between the curves $\\gamma_1$ and $\\gamma_2$ to the\n  angle between the curves $f \\circ \\gamma_1$ and $f \\circ \\gamma_2$.\n  (This is related to \\ref{tj-versus-jt}.)\n\\end{problem}\n\n\\begin{problem}\n  Suppose $f : \\C \\to \\C$ is smooth and holomorphic.  Show that the\n  real part of $f$ is harmonic (cf.~\\ref{harmonic-function}).\n\\end{problem}\n\n\\begin{problem}\n  Let's redo \\ref{abels-theorem} in the context of complex analysis.\n  Consider a sequence $(a_n)$ of complex numbers so that\n  $\\sum_{n=0}^\\infty a_n$ converges to $L$.  Then\n  $\\lim_{z \\to 1^{-}} \\sum_{n=0}^\\infty a_n z^n = L$ provided\n  $z \\to 1$ in a \\textbf{Stolz sector}, i.e., suppose there is some\n  $K$ so that $|1-z| \\leq K(1-|z|)$.\n\\end{problem}\n\n\\section{Prove or Disprove and Salvage if Possible}\n\nAs always with PODASIPs, many of statements below are incorrect.  For\nfull credit, you must not only salvage these false statements, but\nalso explain why the statement is false (e.g., perhaps by exhibiting a\ncounterexample).\n\n\\begin{problem}\n  Suppose $f : \\R^2 \\to \\R^2$ and $g : \\R^2 \\to \\R^2$ are smooth (but\n  not necessarily holomorphic when regarded as functions from $\\C$ to\n  $\\C$).  Then by the chain rule,\n  \\[\n    \\frac{\\partial}{\\partial z} \\left( f \\circ g \\right) =\n    \\frac{\\partial f}{\\partial z} \\frac{\\partial g}{\\partial z} + \\frac{\\partial f}{\\partial \\conj{z}} \\frac{\\partial g}{\\partial \\conj{z}}.\n  \\]\n  and similarly\n  \\[\n    \\frac{\\partial}{\\partial \\conj{z}} \\left( f \\circ g \\right) =\n    \\frac{\\partial f}{\\partial \\conj{z}} \\frac{\\partial g}{\\partial \\conj{z}} + \\frac{\\partial f}{\\partial z} \\frac{\\partial g}{\\partial z}.\n  \\]\n\\end{problem}\n\n\\begin{problem}\\label{schwarz-reflection-principle}If $f : \\C \\to \\C$ is holomorphic, then $z \\mapsto \\overline{f(\\conj z)}$ is holomorphic.\n\\end{problem}\n\n\\begin{problem}\\label{cauchy-riemann-alone-not-sufficient}Suppose $u, v : \\mathbb{R}^2 \\to \\mathbb{R}$ satisfy\n  \\[\n    \\frac{\\partial u}{\\partial x}(0,0)=\\frac{\\partial v}{\\partial y}(0,0)\n    \\mbox{ and }\n    \\frac{\\partial u}{\\partial y}(0,0)=-\\frac{\\partial v}{\\partial x}(0,0).\n  \\]\n  Then $f : \\C \\to \\C$ given by $f(x+iy) = u(x,y) + i \\, v(x,y)$ is holomorphic at $0$.\n\\end{problem}\n\n\\begin{problem}\\label{open-mapping-theorem-preview}There is a nonconstant holomorphic function with constant absolute value.\n\\end{problem}\n\n\\begin{problem}\\label{schwarzian-derivative}For $f : \\mathbb{C} \\to \\mathbb{C}$, the \\textbf{Schwarzian derivative} of $f$ is\n  \\[ (Sf)(z)=\\left({\\frac{f''(z)}{f'(z)}}\\right)'-{\\frac12}\\left(\\frac{f''(z)}{f'(z)}\\right)^2={\\frac {f'''(z)}{f'(z)}}-{\\frac32}\\left(\\frac{f''(z)}{f'(z)}\\right)^2. \\]\n  If $f$ is a M\\\"obius transformation, then $(Sf)(z) = 0$.\n\\end{problem}\n\n\\end{document}\n", "meta": {"hexsha": "468b463cf43bcc207b397908e598c507493f84ae", "size": 5456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set02.tex", "max_stars_repo_name": "kisonecat/math5522h", "max_stars_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-13T03:38:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T03:38:29.000Z", "max_issues_repo_path": "problem-sets/set02.tex", "max_issues_repo_name": "kisonecat/math5522h", "max_issues_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "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/set02.tex", "max_forks_repo_name": "kisonecat/math5522h", "max_forks_repo_head_hexsha": "c9fc5eb915c6d29d91a864dfe066878b75305c42", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-11T18:43:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-11T18:43:51.000Z", "avg_line_length": 37.3698630137, "max_line_length": 168, "alphanum_fraction": 0.6666055718, "num_tokens": 1937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.8791467754256018, "lm_q1q2_score": 0.6176270236476658}}
{"text": "\\newpage{}\n\\newpage{}\n\n\\hypertarget{a002---simply-an-average}{%\n\\section{A002 - Simply an average}\\label{a002---simply-an-average}}\n\n\\hypertarget{description}{%\n\\subsection{Description}}\n\nAnother algorithm could just calculate an average. Take all tasks and\ntheir durations, divide them by their count. Is this better?\n\nFrom visually reviewing the data we know that most tasks have a duration\nof a few hours max. Some take very long.\n\nAn average is not just an average as we know. There are several ways to\ncalculate one:\n\n\\begin{itemize}\n\\tightlist\n\\item\n  there is the ``simple average'' that includes all data (A002.1)\n\\item\n  there is the possibility of a boxplot like calculation, include only\n  the middle n\\% of the values (A002.2)\n\\end{itemize}\n\n\\hypertarget{using-the-algorithm-from-powershell}{%\n\\subsection{Using the algorithm from powershell}}\n\n\\hypertarget{a002.1}{%\n\\subsubsection{A002.1}}\n\nHave a look at Quality-Assurance\\_A002\\_1\\_swe2020.ps1 if you need more.\nBut actually it is just calculating the average. It is not even\nnecessary to do this in a programming language alltogether.\n\n\\begin{verbatim}\n$averageTaskDuration = ($historicData.DurationInSeconds | Measure-Object -Average).Average\n\n$anyEstimation = $averageTaskDuration\n\\end{verbatim}\n\n\\hypertarget{a002.2}{%\n\\subsubsection{A002.2}}\n\nFor that average let us only use the middle 90\\% of duration values.\nThat will cut extreme points and should reduce the error.\n\nQuality-Assurance\\_A002\\_2\\_swe2020.ps1:\n\n\\begin{verbatim}\n$historicData = $historicData | Sort-Object DurationInSeconds\n$count = ($historicData | Measure-Object).Count\n$fivePercent = [int]($count * 0.05)\n$historicData = $historicData[$fivePercent..($count-$fivePercent)]\n\\end{verbatim}\n\n", "meta": {"hexsha": "43dc46d47dd8d4a306894988bdeb1fd72b3a35c7", "size": 1730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/10000-_Algorithms/A002/index.tex", "max_stars_repo_name": "stho32/Automatically-Estimating-Task-Durations", "max_stars_repo_head_hexsha": "4f63d75dd56f56c05d9a046b98f21cff04971a08", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-12T17:24:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T06:43:27.000Z", "max_issues_repo_path": "Documentation/10000-_Algorithms/A002/index.tex", "max_issues_repo_name": "stho32/Automatically-Estimating-Task-Durations", "max_issues_repo_head_hexsha": "4f63d75dd56f56c05d9a046b98f21cff04971a08", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2021-08-13T00:24:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-26T10:01:19.000Z", "max_forks_repo_path": "Documentation/10000-_Algorithms/A002/index_fr.tex", "max_forks_repo_name": "stho32/Automatically-Estimating-Task-Durations", "max_forks_repo_head_hexsha": "4f63d75dd56f56c05d9a046b98f21cff04971a08", "max_forks_repo_licenses": ["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.3220338983, "max_line_length": 90, "alphanum_fraction": 0.7676300578, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177517, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.6175938943696384}}
{"text": "%!TEX root = ../main.tex\n%-------------------------------------------------------------------------------\n\\section{Improvements}\\label{Computation}\n%-------------------------------------------------------------------------------\nThe implementation of EKW models poses several computational challenges. Among them are numerical integration, global optimization, function approximation, and efficient parallelization. We now describe some of our efforts to align \\verb+respy+ and \\verb+estimagic+ with the state-of-the-art in computational methods. We have concluded our preparatory work and actively seek input from domain experts for further improvements and joint publication.\n%-------------------------------------------------------------------------------\n\\subsection{Numerical integration}\n%-------------------------------------------------------------------------------\nThe solution of EKW models requires the evaluation of millions of integrals to determine the future value of each action in each state. In \\citet{Eisenhauer.2020c}, we draw on the extensive literature on numerical integration \\citep{Davis.2007, Gerstner.1998} to improve the precision and reliability of their solution. The current practice in economics is to implement a random Monte Carlo integration which introduces considerable numerical error and computational instabilities \\citep{Judd.2011}.\\\\\n\n\\noindent We consider the optimality equation in a generic time period $t$ to clarify the structure of the integral. Let $v^{\\pi}_{t}(s_t, a_t)$ denote the action-specific value function of choosing action $a_t$ in state $s_t$ while continuing with the optimal policy going forward.\n%\n\\begin{align*}\nv^{\\pi}_{t}(s_t, a_t) & = u_t(s_t, a_t) + \\delta\\,\\E_{s_t} \\left[\\left.v^{\\pi^*}_{t + 1}(s_{t + 1})\\,\\right\\vert\\,\\mathcal{I}_t\\,\\right] \\\\\n& =  u_t(s_t, a_t) + \\delta\\, \\int_S v^{\\pi^*}_{t + 1}(s_{t + 1})\\, \\diff p_t(a_t, s_t)\\\\\n& =  u_t(s_t, a_t) + \\delta\\, \\int_S \\max_{a_{t + 1} \\in A}\\bigg\\{v^{\\pi^*}_{t + 1}(s_{t + 1}, a_{t + 1})\\bigg\\}\\diff p_t(a_t, s_t).\n\\end{align*}\n\n\\noindent Let's consider an atemporal version of the typical integral from \\citet{Keane.1997} as an example. As outlined earlier, individuals can choose among five alternatives. Each of the alternative-specific utilities is, in part, determined by a stochastic continuous state variable $\\epsilon$. The transition of all other state variables $x$ is deterministic. This results in a five-dimensional integral of the following form:\n%\n\\begin{align*}\n   \\int_{\\epsilon}\\, \\max_{a\\in A} \\bigg\\{v^{\\pi^*}(x, \\epsilon, a)\\bigg\\} \\phi_{\\mu, \\Sigma}(\\epsilon) \\diff\\epsilon \\quad\\forall\\, x \\in X,\n\\end{align*}\n\n\\noindent where $\\epsilon$ follows a multivariate normal distribution with mean $\\mu$, covariance matrix $ \\Sigma$, and probability density function $\\phi_{\\mu, \\Sigma}$.\n%-------------------------------------------------------------------------------\n\\subsection{Global optimization}\n%-------------------------------------------------------------------------------\nThe calibration of EKW models is challenging due to a large number of parameters and multiplicity of local minima. In \\citet{Eisenhauer.2020b}, we draw on the literature on global optimization to assess and improve the reliability of the calibrations \\citep{Locatelli.2013, Nocedal.2006}.\\\\\n\n\\noindent We conduct a benchmarking exercise using \\citet{Keane.1994, Keane.1997} as a well-known and empirically-grounded test case. Depending on the calibration procedure, particular challenges arise. For example, while likelihood-based calibration requires smoothing of the choice probabilities, simulation-based calibration involves the optimization of a noisy function. We provide guidelines for selecting the appropriate algorithm in each setting and showcase diagnostics to assess the reliability of the calibration results.\n", "meta": {"hexsha": "05a720acc7b92a05c051f0a6582edb61175a3425", "size": 3850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/s-improvements.tex", "max_stars_repo_name": "jkoenig97/ekw-pres", "max_stars_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_stars_repo_licenses": ["MIT"], "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/s-improvements.tex", "max_issues_repo_name": "jkoenig97/ekw-pres", "max_issues_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_issues_repo_licenses": ["MIT"], "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/s-improvements.tex", "max_forks_repo_name": "jkoenig97/ekw-pres", "max_forks_repo_head_hexsha": "634d9a2de17419d3f04440cdb5640b3a50af7ccd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 120.3125, "max_line_length": 531, "alphanum_fraction": 0.6696103896, "num_tokens": 902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6175938849050447}}
{"text": "\\documentclass[letterpaper, 10pt]{article}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,scrextend}\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\usepackage{silence}\n\\WarningFilter{latex}{You have requested package}\n\\input{ltx/pkg/preamble}\n\n\n\n\n\n\\begin{document}\n\n\\lhead{MAT224 Linear Algebra II}\n\\chead{Linear Transformations, Image \\& Kernel}\n\\rhead{Week 04}\n\n\\title{Linear Algebra II \\\\ \\Large{MAT224}}\n\\author{Lennart Döppenschmitt}\n% \\maketitle\n% \\tableofcontents\n\n\\section*{Linear Transformations Part II}%\n\\label{sec:title}\n\n\\textbf{Textbook:} Section 2.2\n\n\\lb\n\\textbf{Announcements} \n\\begin{itemize}\n\\item \nThe last hour before the lecture next week will be a review session!\nPlease collect your questions and email me if you would like to discuss anything\nparticular. (include MAT224 in subject, thanks)\n\n\\item\nAll vector spaces from now on, unless stated otherwise,\nwill be assumed to be finite dimensional.\n\\end{itemize}\n\n\n\n\n\n\n\n\n\\lb\nRemember that a basis encodes a vector $\\vec v ∈ V$ as an $n$-tuple.\nWe can use the same idea to encode linear transformations\n\n\n\n\\lb\n\\textbf{Example 2.2.2}\n\\lb\nLet $V = W = \\R^2$ with the standard basis $ \\cb{\\vec e_1, \\vec e_2}$.\nDefine $ \\map{V}[T]{W}$ by\n\\[ T(\\vec e_1) = \\vec e_1 + \\vec e_2 \\]\n\\[ T(\\vec e_2) = \\vec 2 e_1 - 2 \\vec e_2 \\]\n\\vspace{50pt}\n\n\n\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Algorithm}\n\\lb\nGiven a linear transformation $ \\map{V}[T]{W}$ given as a `formula',\nthis is how to compute its matrix in two chosen bases\n\\[ α = \\cb{\\vec{α}_1, \\ldots \\vec{α}_m} \\]\nof $V$ and\n\\[ β = \\cb{\\vec{β}_1, \\ldots \\vec{β}_n} \\]\nof $W$\n\\lb\n\\begin{enumerate}\n    \\item For each basis element $\\vec{α}_i$ in $V$, compute $T(\\vec{α}_i)$.\n    \\item Find the coorindate vector $γ^β(T(\\vec{α}_i)) = [ T(\\vec{α}_i) ]_β$.\n    \\item Assemble these coordinate vectors as columns in a matrix\n\\end{enumerate}\n\n\n\n\\lb\n\\textbf{Discussion}\n\\lb\nApply the above algorithm to find the matrix representing the derivative\n$ \\frac{d}{dx}$ from $\\pol{2}{\\R}$ to itself.\nChoose the basis on $\\pol{2}{\\R}$ consisting of monomials $α = \\cb{1, x, x^2}$.\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Definition 2.2.6}\n\\lb\nLet $T$ be a linear transformation between finite dimensional vector spaces $V$ and $W$\nwith bases $α$ and $β$ respectively.\nThe \\emph{matrix of the linear transformation} $T$ with respect to bases $α$ and $β$ is the\nmatrix $[T]_α^β$ satisfying\n\\[ [T]_α^β \\cdot [\\vec v]_α = [T(\\vec v) ]_β \\]\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Discussion}\n\\begin{enumerate}\n    \\item\n        What does he `size' of the matrix $[T]_α^β$ depend on?\n    \\item\n        What is the matrix of the identity transformation $ \\map{V}[\\tx{id}_V]{V}$?\n\\end{enumerate}\n\n\n\\lb\n\\textbf{Exmaple}\n\\lb\nWe compute the matrix of the linear transformation $ \\map{\\pol{3}{\\R}}[\\tx{ev}_2]{\\R}$\n\n\n\n\\newpage\n\\lb\n\\textbf{Discussion}\n\\lb\nOn the contrary, given a matrix $A ∈ \\mat{n, m}{\\R}$, does this give us a\nlinear transformation? What are the domain and codomain?\n\n\n\\vspace{300pt}\n\\lb\n\\textbf{Summary}\n\\begin{enumerate}\n    \\item\n        The upshot of this section is that linear transformations are completely interchangable\n        with matrices!\n        The identification depends on the choice of bases for the domain and codomain.\n    \\item\n        The operations\n        \\begin{itemize}\n            \\item matrix of a linear transformation $[T]_α^β$\n            \\item linear transformation of a matrix $T_A$\n        \\end{itemize}\n        are inverse to each other.\n\\end{enumerate}\n\n\n\n\n\\newpage\n\\lb\nWe now rephrase the \\emph{algorithm} from before in more mathematical terms.\n(Remember, abstraction is a powerful tool!)\n\\lb\n\\textbf{Proposition} \n\\lb\nIn the context of the above definition, the matrix of $T$ can be computed as\n\\[ [T]_α^β = γ^β \\circ T \\circ (γ^α)^{-1}\\]\n\\begin{proof}\n\\end{proof}\n\n\\vspace{200pt}\n\\lb\n\\textbf{Discussion}\n\\lb\nWithout doing a lot of work, can you argue what the matrix\nrepresenting the composition $F \\circ T$ is assuming you know $[F]$ and $[T]$?\n\n\n\n\n\n\n\n\n\\newpage\n\n\\section*{Imge and Kernel}%\n\\label{sec:Imge and Kernel}\n\n\n\\textbf{Textbook:} Section 2.3\n\n\n\\lb\n\\textbf{Definition (2.3.1 \\& 2.3.10)}\n\\lb\nFor a linear transformation $ \\map{V}[T]{W}$, we define\n\\begin{enumerate}\n    \\item\n        the \\emph{preimage} $T^{-1}(S)$ of $S \\subseteq W$ under $T$ as all $\\vec v ∈ V$ that map into $S$.\n    \\item\n        the \\emph{kernel} $\\ker(T)$ of $T$  as all $\\vec v ∈ V$ that map to $\\vec 0$ under $T$,\n    \\item \n        the \\emph{image} $\\tx{im}(T)$ of $T$ as all $\\vec w ∈ W$ such that $\\vec w = T(\\vec v)$ for some $\\vec v ∈ V$,\n\\end{enumerate}\n\n\n\n\n\\lb\n\\textbf{Example}\n\\begin{itemize}\n    \\item\n    The kernel of $\\map{\\pol{n}{\\R}}[\\frac{d}{dx}]{\\pol{n}{\\R}}$ are all constant polynomials,\n    while the image consists of polynomials of degree $n-1$.\n\n    \\item\n    The kernel of the evaluation map $\\map{\\pol{n}{\\R}}[\\tx{ev}_2]{\\pol{n}{\\R}}$ are all\n    polynomials that have a root at $x = 2$. What is the image?\n\n    \\item\n    What is the image of the linear transformation defined in example 2.2.2 $\\map{\\R^2}[T]{\\R^2}$?\n    \\[ T(\\vec e_1) = \\vec e_1 + \\vec e_2 \\]\n    \\[ T(\\vec e_2) = \\vec 2 e_1 - 2 \\vec e_2 \\]\n\\end{itemize}\n\n\n\\newpage\n\\lb\n\\textbf{Proposition 2.3.2 \\& 2.3.11}\n\\lb\nFor every linear transformation $\\map{V}[T]{W}$\n\\begin{enumerate}\n    \\item $\\ker(T)$ is a subspace in $V$\n    \\item $\\tx{im}(T)$ is a subspace in $W$.\n\\end{enumerate}\n\\begin{proof}\n\\end{proof}\n\n\n\n\\vspace{300pt}\n\\lb\n\\textbf{Proposition 2.3.7}\n\\lb\nThe subspace $\\ker(T)$ is the solution space to the homogeneous system of $[T]_α^β$.\n\\begin{proof}\n\\end{proof}\n\n\\vspace{200pt}\n\\lb\n\\textbf{Example}\n\\lb\nExample of computation to find $\\ker(T)$\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Observation}\n\\lb\nThe subspace $\\tx{im}(T)$ is the space of all $ \\vec b ∈ \\R^n$ such that the system\n$[T]_α^β \\vec x = \\vec b$ has a solution.\n\n\n\\vspace{200pt}\n\\lb\n\\textbf{Proposition 2.3.12}\n\\lb\nIf $ \\cb{\\vec v_1, \\ldots, \\vec v_k}$ spans $V$, then $ \\cb{T(\\vec v_1), \\ldots, T(\\vec v_k)}$\nspans $\\tx{im}(T)$.\n\\begin{proof}\n\\end{proof}\n\n\n\n\n\\vspace{200pt}\n\\lb\n\\textbf{Definition}\n\\lb\nFor a matrix $A = [ a_1, a_2, \\ldots, a_m] ∈ \\mat{n, m}{\\R}$ we denote\nthe span of the columns of $A$ by\n\\[ \\tx{col}(A) = \\spn{a_1, \\ldots, a_m} \\]\n\n\n\\lb\n\\textbf{Proposition}\n\\lb\nFor every linear transformation $\\map{V}[T]{W}$\n\\[ \\tx{im}(T) = \\tx{col}([T]_α^β) \\]\n\\begin{proof}\n\\end{proof}\n\n\n\n\\newpage\n\\lb\n\\textbf{Example} \n\\lb\nExample computation to find $\\tx{im}(T)$\n\n\\vspace{300pt}\n\\lb\nNotice that the columns might not be independent,\nin which case the columns are a spanning set of the image, but not a basis.\n\n\\lb\n\\textbf{Theorem}\n\\lb\nGiven a linear transformation $\\map{V}[T]{W}$ with matrix $[T]_α^β$ for some bases $α$ and $β$.\nLet $R = \\tx{RREF}([T]_α^β)$ be the reduced row echolon form of $[T]_α^β$.\n\\lb\nThen if the leading 1s in are $R$ lie in columns\n$j_1, j_2,\\ldots, j_r$, the columns $j_1, j_2,\\ldots, j_r$ of $[T]_α^β$ are a basis for \n$ \\tx{col}([T]_α^β)$\n\\begin{proof}\n\\end{proof}\n\n\n\\vspace{100pt}\n\\lb\n\\textbf{Discussion} \n\\lb\nSuppose a linear transformation $\\map{V}[T]{W}$ is given in a some bases $α$ and $β$ by\n\\[ [T]_α^β = \\begin{pmatrix} 1 & 2 & 0 & 1 \\\\ 1 & 2 & 1 & 0 \\end{pmatrix} \\]\nFind a basis for $\\tx{im}(T)$ and $\\ker(T)$.\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Theorem 2.3.17 (Rank-Nullity)}\n\\lb\nFor any linear transformation $\\map{V}[T]{W}$\n\\[ \\dim(V) = \\dim(\\ker(T)) + \\dim( \\tx{im}(T)) \\]\n\n\n\\lb\n\\textbf{Remark} \n\\begin{itemize}\n    \\item \n        $\\dim( \\tx{im}(T))$ is the same as the rank of $[T]_α^β$ and by abuse of\n        notation also referred to as $\\tx{rank}(T)$.\n    \\item\n        Some books refer to $\\dim(\\ker(T))$ as the \\emph{nullity} of $T$.\n\\end{itemize}\n\n\\begin{proof}\n\\end{proof}\n\n\n\\vspace{300pt}\n\\lb\n\\textbf{Theorem}\n\\lb\nA linear transformation $T$ is injective if and only if $\\ker(T) = \\cb{\\vec 0}$\n\\begin{proof}\n\\end{proof}\n\n\n\n\\newpage\n\\lb\n\\textbf{True or False} \nLet $\\map{V}[T]{W}$ be a linear transformation\n\\begin{enumerate}\n    \\item[$\\square$]\n        If $T$ is an isomorphism, then $\\dim(V) = \\dim(W)$.\n    \\item[$\\square$]\n        If $\\dim(V) > \\dim(W)$, $T$ has to be injective.\n    \\item[$\\square$]\n\\end{enumerate}\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": "9c477d93b165c85993fabfe65710548d77fe9cc6", "size": 8167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week04.tex", "max_stars_repo_name": "Researchnix/mat224", "max_stars_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-03T21:56:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-30T03:26:18.000Z", "max_issues_repo_path": "week04.tex", "max_issues_repo_name": "Researchnix/mat224", "max_issues_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week04.tex", "max_forks_repo_name": "Researchnix/mat224", "max_forks_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_forks_repo_licenses": ["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.2153465347, "max_line_length": 118, "alphanum_fraction": 0.6461368924, "num_tokens": 2937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.6175938819022647}}
{"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 16: Double Integrals}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Definition of Double Integrals}\n\nFor single-variable functions, we use integral to calculate the area under the \nfunction curve. For a multivariable function with two independent variables \n$z = f(x, y)$, we define double integrals to calculate the volume under the \nfunction graph over a region $R$ in the $x$$y$-plane. The notation is \n$\\iint_R f(x, y)dA$.\n\n\\bigskip\n\nDefinition of double integrals:\n\nIf we cut the region $R$ into small pieces of area $\\Delta A_i$, then the volume \ncan be calculated as \n\\begin{equation*}\n  V \\approx \\sum_i f(x_i, y_i) \\Delta A_i\n\\end{equation*}\nIf we take the limit of $\\Delta A_i$ to 0, then it becomes the double integral\n\\begin{equation*}\n  \\iint_R f(x, y) dA = \\lim_{\\Delta A_i \\to 0} \\sum_i f(x_i, y_i) \\Delta A_i\n\\end{equation*}\n\n\\section{Calculation of Double Integrals}\n\nTo compute a double integral $\\iint_R f(x, y) dA$, we can take slices of the \nfunction graph along one dimension and use integral to get the area of slices. \nIn this way, the area of all slices becomes a function of another dimension, \nthen we can use the integral again to sum up those slices to get the volume.\n\nMore concretely, let $S(x)$ denote the area of slices by plane parallel to \n$y$$z$-plane. Then\n\\begin{equation*}\n  \\iint_R f(x, y) dA = \\int_{x_min}^{x_max} S(x) dx\n\\end{equation*}\nFor a given $x_0$, the area of the slice\n\\begin{equation*}\n  S(x_0) = \\int_{y_min(x_0)}^{y_max(x_0)} f(x, y) dy\n\\end{equation*}\nTherefore, the double integral\n\\begin{equation*}\n  \\begin{split}\n    \\iint_R f(x, y) dA &= \\int_{x_min}^{x_max} S(x) dx \\\\\n                       &= \\int_{x_min}^{x_max} \\int_{y_min(x_0)}^{y_max(x_0)} f(x, y) dy dx\n  \\end{split}\n\\end{equation*}\nThis calculation method is called \\textbf{iterated integral}, because we iterate \ntwice through both dimensions to get the integral.\n\nNotice that the bounds of the outer integral are numbers, and the bounds of the \ninner integral are numbers or functions depending on the variable of the outer \nintegral. The bounds of both outer and inner integrals are determined by the \nregion of the double integral.\n\n\\section{Examples of Double Integral}\n\n\\begin{example}\n  Find the value of the double integral of the function $z = 1 - x^2 - y^2$ over \n  the region $R$ as $0 \\leq x \\leq 1$, $0 \\leq y \\leq 1$.\n\n  Solution:\n\n  By using iterated integrals,\n  \\begin{equation*}\n    \\iint_R f(x, y) dA = \\int_0^1 \\int_0^1 1 - x^2 - y^2 dy dx\n  \\end{equation*}\n  For the inner integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^1 1 - x^2 - y^2 dy &= (y - x^2y - \\frac{y^3}{3})|_0^1 \\\\\n                                &= 1 - x^2 - \\frac{1}{3} \\\\\n                                &= \\frac{2}{3} - x^2 \\\\\n    \\end{split}\n  \\end{equation*}\n  For the outer integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^1 \\frac{2}{3} - x^2 dx &= (\\frac{2x}{3} - \\frac{x^3}{3})|_0^1 \\\\\n                                    &= \\frac{2}{3} - \\frac{1}{3} \\\\\n                                    &= \\frac{1}{3} \\\\\n    \\end{split}\n  \\end{equation*}\n  Therefore, the value of the double integral is $\\frac{1}{3}$.\n\\end{example}\n\n\\begin{example}\n  Find the value of the double integral of the function $z = 1 - x^2 - y^2$ over \n  the region $R$ as \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  By the equation of the region $R$, we can get that for any given $x_0$, the \n  range of $y$ in the region $R$ is $[0, \\sqrt{1 - x^2}]$.\n\n  By using iterated integrals,\n  \\begin{equation*}\n    \\iint_R f(x, y) dA = \\int_0^1 \\int_0^{\\sqrt{1 - x^2}} 1 - x^2 - y^2 dy dx\n  \\end{equation*}\n  For the inner integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^{\\sqrt{1 - x^2}} 1 - x^2 - y^2 dy &= (y - x^2y - \\frac{y^3}{3})|_0^{\\sqrt{1 - x^2}} \\\\\n                                               &= \\sqrt{1 - x^2} - x^2\\sqrt{1 - x^2} - \\frac{(1 - x^2)^{\\frac{3}{2}}}{3}\\\\\n                                               &= \\frac{2}{3}(1 - x^2)^{\\frac{3}{2}} \\\\\n    \\end{split}\n  \\end{equation*}\n  For the outer integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^1 \\frac{2}{3}(1 - x^2)^{\\frac{3}{2}} dx &= \\int_0^{\\frac{\\pi}{2}} \\frac{2}{3}(1 - \\sin^2\\theta)^{\\frac{3}{2}} d(\\sin\\theta) \\\\\n                                                     &= \\frac{2}{3} \\int_0^{\\frac{\\pi}{2}} \\cos^4\\theta d\\theta \\\\\n                                                     &= \\frac{2}{3} \\int_0^{\\frac{\\pi}{2}} (\\frac{1 + \\cos 2\\theta}{2})^2 d\\theta \\\\\n                                                     &= \\frac{1}{6} \\int_0^{\\frac{\\pi}{2}} (1 + 2\\cos2\\theta + \\cos^2 2\\theta) d\\theta \\\\\n                                                     &= \\frac{1}{6} \\int_0^{\\frac{\\pi}{2}} (1 + 2\\cos2\\theta + \\frac{1 + \\cos 4\\theta}{2}) d\\theta \\\\\n                                                     &= \\frac{1}{12} \\int_0^{\\frac{\\pi}{2}} (3 + 4\\cos2\\theta + \\cos 4\\theta) d\\theta \\\\\n                                                     &= \\frac{1}{12} (3\\theta + 2\\sin2\\theta + \\frac{1}{4}\\cos 4\\theta)|_0^{\\frac{\\pi}{2}} \\\\\n                                                     &= \\frac{1}{12} \\cdot \\frac{3\\pi}{2} \\\\\n                                                     &= \\frac{\\pi}{8} \\\\\n    \\end{split}\n  \\end{equation*}\n  Therefore, the value of the double integral is $\\frac{\\pi}{8}$.\n\\end{example}\n\n\\section{Exchange the Order of Iterated Integrals}\n\nIn theory, no matter in which order we calculate the iterated integral, the \nvalues always exist and are the same. However, in practice an order requires \nmuch more complex computation than the other; sometimes we might not even be \nable to compute the double integral with a specific order, but able to do it \nwith the other order. Therefore, we need to be mindful about the order of \niterated integral we use.\n\nIn some cases, we can exchange the order of an iterated integral, with some \nadaption to the bounds of integrals.\n\n\\begin{example}\n  \\begin{equation*}\n    \\int_0^1 \\int_0^2 dx dy = \\int_0^2 \\int_0^1 dy dx\n  \\end{equation*}\n  For rectangle regions, the bounds of the inner integral don't depend on the \n  variable of the outer integral, so we can exchange the inner integral and \n  outer integral freely.\n\n  From the perspective of the definition of iterated integrals, for rectangle \n  regions, slices of either direction don't change the set of small pieces of \n  area $dA_i$ to sum up.\n\\end{example}\n\n\\begin{example}\n  Find the value of $\\int_0^1 \\int_x^{\\sqrt{x}} \\frac{e^y}{y} dy dx$.\n\n  It is too difficult to calculate $\\int_x^{\\sqrt{x}} \\frac{e^y}{y} dy$, so we \n  need to consider exchanging the order of integrals.\n\n  By looking at the region, we derive that\n  \\begin{equation*}\n    \\int_0^1 \\int_x^{\\sqrt{x}} \\frac{e^y}{y} dy dx = \\int_0^1 \\int_{y^2}^y \\frac{e^y}{y} dx dy\n  \\end{equation*}\n  and the one on the right-hand side is doable.\n\n  For the inner integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_{y^2}^y \\frac{e^y}{y} dx &= \\frac{xe^y}{y}|_{y^2}^y \\\\\n                                    &= e^y - ye^y \\\\\n    \\end{split}\n  \\end{equation*}\n  For the outer integral,\n  \\begin{equation*}\n    \\begin{split}\n      \\int_0^1 e^y - ye^y dy &= (2e^y - ye^y)|_0^1 \\\\\n                             &= 2e - e - 2 \\\\\n                             &= e - 2 \\\\\n    \\end{split}\n  \\end{equation*}\n  Therefore, the value of $\\int_0^1 \\int_x^{\\sqrt{x}} \\frac{e^y}{y} dy dx$ is \n  $e - 2$.\n\\end{example}\n\n\\end{document}", "meta": {"hexsha": "24ab9e2ec685dff91074ea9fe7eaa3c320e0239d", "size": 7912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture16.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": "lecture16.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": "lecture16.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": 38.0384615385, "max_line_length": 149, "alphanum_fraction": 0.58619818, "num_tokens": 2604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6175938775121578}}
{"text": "\\chapter{Bonus: Let's solve Pell's equation!}\nThis is an optional aside, and can be safely ignored.\n(On the other hand, it's pretty short.)\n\n\\section{Units}\n\\prototype{$\\pm 1$, roots of unity, $3-2\\sqrt2$ and its powers.}\nRecall according to \\Cref{prob:OK_unit_norm} that $\\alpha \\in \\OO_K$ is invertible\nif and only if \\[ \\NK(\\alpha) = \\pm 1. \\]\nWe let $\\OO_K^\\times$ denote the set of units of $\\OO_K$.\n\n\\begin{ques}\n\tShow that $\\OO_K^\\times$ is a group under multiplication.\n\tHence we name it the \\vocab{unit group} of $\\OO_K$.\n\\end{ques}\n\nWhat are some examples of units?\n\\begin{example}\n\t[Examples of units in a number field]\n\t\\listhack\n\t\\begin{enumerate}\n\t\t\\ii $\\pm 1$ are certainly units, present in any number field.\n\n\t\t\\ii If $\\OO_K$ contains a root of unity $\\omega$ (i.e.\\ $\\omega^n=1$),\n\t\tthen $\\omega$ is a unit.\n\t\t(In fact, $\\pm 1$ are special cases of this.)\n\n\t\t\\ii Of course, not all units of $\\OO_K$ are roots of unity.\n\t\tFor example, if $\\OO_K = \\ZZ[\\sqrt3]$ (from $K = \\QQ(\\sqrt3)$) then\n\t\tthe number $2+\\sqrt3$ is a unit, as its norm is\n\t\t\\[ \\NK(2+\\sqrt3) = 2^2 - 3 \\cdot 1^2 = 1. \\]\n\t\tAlternatively, just note that the inverse $2-\\sqrt3 \\in \\OO_K$ as well:\n\t\t\\[ \\left( 2-\\sqrt3 \\right)\\left( 2+\\sqrt3 \\right) = 1. \\]\n\t\tEither way, $2-\\sqrt3$ is a unit.\n\n\t\t\\ii Given any unit $u \\in \\OO_K^\\times$, all its powers are also units.\n\t\tSo for example, $(3-2\\sqrt2)^n$ is always a unit of $\\ZZ[\\sqrt2]$, for any $n$.\n\t\tIf $u$ is not a root of unity, then this generates infinitely many new units in $\\OO_K^\\times$.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{ques}\n\tVerify the claims above that\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Roots of unity are units, and\n\t\t\\ii Powers of units are units.\n\t\\end{enumerate}\n\tOne can either proceed from the definition\n\tor use the characterization $\\NK(\\alpha) = \\pm 1$.\n\tIf one definition seems more natural to you, use the other.\n\\end{ques}\n\n\\section{Dirichlet's unit theorem}\n\\prototype{The units of $\\ZZ[\\sqrt3]$ are $\\pm(2+\\sqrt3)^n$.}\n\n\\begin{definition}\n\tLet $\\mu(\\OO_K)$ denote the set of roots of unity\n\tcontained in a number field $K$ (equivalently, in $\\OO_K$).\n\\end{definition}\n\\begin{example}[Examples of $\\mu(\\OO_K)$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $K = \\QQ(i)$, then $\\OO_K = \\ZZ[i]$. So\n\t\t\\[ \\mu(\\OO_K) = \\{\\pm1, \\pm i\\} \\quad\\text{where } K = \\QQ(i). \\]\n\t\t\\ii If $K = \\QQ(\\sqrt3)$, then $\\OO_K = \\ZZ[\\sqrt 3]$. So\n\t\t\\[ \\mu(\\OO_K) = \\{\\pm 1\\} \\quad\\text{where } K = \\QQ(\\sqrt 3). \\]\n\t\t\\ii If $K = \\QQ(\\sqrt{-3})$, then $\\OO_K = \\ZZ[\\half(1+\\sqrt{-3})]$.\n\t\tSo\n\t\t\\[ \\mu(\\OO_K)\n\t\t\t= \\left\\{ \\pm 1, \\frac{\\pm 1 \\pm \\sqrt{-3}}{2} \\right\\}\n\t\t\t\\quad\\text{where } K = \\QQ(\\sqrt{-3})\n\t\t\\]\n\t\twhere the $\\pm$'s in the second term need not depend on each other;\n\t\tin other words $\\mu(\\OO_K) = \\left\\{ z \\mid z^6=1 \\right\\}$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{exercise}\n\tShow that we always have that $\\mu(\\OO_K)$\n\tcomprises the roots to $x^n-1$ for some integer $n$.\n\t(First, show it is a finite group under multiplication.)\n\\end{exercise}\n\nWe now quote, without proof, the so-called Dirichlet's unit theorem,\nwhich gives us a much more complete picture of what the units in $\\OO_K$ are.\nLegend says that Dirichlet found the proof of this theorem\nduring an Easter concert in the Sistine Chapel.\n\\begin{theorem}\n\t[Dirichlet's unit theorem]\n\tLet $K$ be a number field with signature $(r_1, r_2)$ and set\n\t\\[ s = r_1 + r_2 - 1. \\]\n\tThen there exist units $u_1$, \\dots, $u_s$ such that every unit\n\t$\\alpha \\in \\OO_K^\\times$ can be written \\emph{uniquely} in the form\n\t\\[ \\alpha = \\omega \\cdot u_1^{n_1} \\dots u_s^{n_s} \\]\n\tfor $\\omega \\in \\mu(\\OO_K)$ is a root of unity,\n\tand $n_1, \\dots, n_s \\in \\ZZ$.\n\\end{theorem}\nMore succinctly:\n\\begin{moral}\nWe have $\\OO_K^\\times \\cong \\ZZ^{r_1+r_2-1} \\times \\mu(\\OO_K)$.\n\\end{moral}\nA choice of $u_1$, \\dots, $u_s$ is called a choice of \\vocab{fundamental units}.\n\nHere are some example applications.\n\\begin{example}\n\t[Some unit groups]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Let $K = \\QQ(i)$ with signature $(0,1)$.\n\t\tThen we obtain $s = 0$, so Dirichlet's Unit theorem says that there are no\n\t\tunits other than the roots of unity.\n\t\tThus\n\t\t\\[ \\OO_K^\\times = \\{\\pm 1, \\pm i\\} \\quad\\text{where } K = \\QQ(i). \\]\n\t\tThis is not surprising,\n\t\tsince $a+bi \\in \\ZZ[i]$ is a unit if and only if $a^2+b^2 = 1$.\n\n\t\t\\ii Let $K = \\QQ(\\sqrt 3)$, which has signature $(2,0)$.\n\t\tThen $s=1$, so we expect exactly one fundamental unit.\n\t\tA fundamental unit is $2+\\sqrt3$ (or $2-\\sqrt3$, its inverse) with norm $1$, and so we find\n\t\t\\[ \\OO_K^\\times = \\left\\{ \\pm (2+\\sqrt3)^n \\mid n \\in \\ZZ \\right\\}.  \\]\n\n\t\t\\ii Let $K = \\QQ(\\sqrt[3]{2})$ with signature $(1,1)$.\n\t\tThen $s=1$, so we expect exactly one fundamental unit.\n\t\tThe choice $1 + \\sqrt[3]{2} + \\sqrt[3]{4}$. So\n\t\t\\[ \\OO_K^\\times\n\t\t\t= \\left\\{ \\pm \\left( 1+\\sqrt[3]{2}+\\sqrt[3]{4} \\right)^n \\mid n \\in \\ZZ \\right\\}. \\]\n\t\\end{enumerate}\n\\end{example}\n\nI haven't actually shown you that these are fundamental units,\nand indeed computing fundamental units is in general hard.\n\n\\section{Finding fundamental units}\nHere is a table with some fundamental units.\n\\[\n\t\\begin{array}{rl}\n\t\td & \\text{Unit} \\\\ \\hline\n\t\td=2 & 1+\\sqrt 2 \\\\\n\t\td=3 & 2+\\sqrt3 \\\\\n\t\td=5 & \\half(1+\\sqrt5) \\\\\n\t\td=6 & 5+2\\sqrt6 \\\\\n\t\td=7 & 8+3\\sqrt7 \\\\\n\t\td=10 & 3+\\sqrt{10} \\\\\n\t\td=11 & 10+3\\sqrt11\n\t\\end{array}\n\\]\n\nIn general, determining fundamental units is computationally hard.\n\nHowever, once I tell you what the fundamental unit is, it's not too bad\n(at least in the case $s=1$) to verify it.\nFor example,\nsuppose we want to show that $10 + 3\\sqrt{11}$ is a fundamental unit of $K = \\QQ(\\sqrt 11)$,\nwhich has ring of integers $\\ZZ[\\sqrt{11}]$.\nIf not, then for some $n > 1$, we would have to have\n\\[ 10 + 3 \\sqrt{11} = \\pm \\left( x+y\\sqrt{11} \\right)^n. \\]\nFor this to happen, at the very least we would need $\\left\\lvert y \\right\\rvert < 3$.\nWe would also have $x^2-11y^2 = \\pm 1$.\nSo one can just verify (using $y= 1,2$) that this fails.\n\nThe point is that: Since $(10,3)$ is the \\emph{smallest}\n(in the sense of $\\left\\lvert y \\right\\rvert$)\ninteger solution to $x^2-11y^2 = \\pm 1$, it must be the fundamental unit.\nThis holds more generally, although in the case that $d \\equiv 1 \\pmod 4$\na modification must be made as $x$, $y$ might be half-integers (like $\\half(1+\\sqrt5)$).\n\\begin{theorem}\n\t[Fundamental units of pell equations]\n\tAssume $d$ is a squarefree integer.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If $d \\equiv 2,3 \\pmod 4$,\n\t\tand $(x,y)$ is a minimal integer solution to $x^2-dy^2 = \\pm 1$,\n\t\tthen $x + y \\sqrt d$ is a fundamental unit.\n\t\t\\ii If $d \\equiv 1 \\pmod 4$,\n\t\tand $(x,y)$ is a minimal \\emph{half-integer} solution to $x^2-dy^2 = \\pm 1$,\n\t\tthen $x + y \\sqrt d$ is a fundamental unit.\n\t\t(Equivalently, the minimal integer solution to $a^2 - db^2 = \\pm 4$\n\t\tgives $\\half (a + b \\sqrt d)$.)\n\t\\end{enumerate}\n\t(Any reasonable definition of ``minimal'' will work, such as sorting by $\\left\\lvert y \\right\\rvert$.)\n\\end{theorem}\n\n\\section{Pell's equation}\nThis class of results completely eradicates Pell's Equation.\nAfter all, solving\n\\[ a^2 - d \\cdot b^2 = \\pm 1 \\]\namounts to finding elements of $\\ZZ[\\sqrt d]$ with norm $\\pm 1$.\nIt's a bit weirder in the $d \\equiv 1 \\pmod 4$ case, since in that case $K = \\QQ(\\sqrt d)$\ngives $\\OO_K = \\ZZ[\\half(1+\\sqrt d)]$, and so the fundamental unit may not actually be a solution.\n(For example, when $d = 5$, we get the solution $(\\half, \\half)$.)\nNonetheless, all \\emph{integer} solutions are eventually generated.\n\nTo make this all concrete, here's a simple example.\n\\begin{example}[$x^2-5y^2 = \\pm 1$]\n\tSet $K = \\QQ(\\sqrt 5)$, so $\\OO_K = \\ZZ[\\half(1+\\sqrt 5)]$.\n\tBy Dirichlet's unit theorem, $\\OO_K^\\times$ is generated by a single element $u$.\n\tThe choice\n\t\\[ u = \\frac 12 + \\frac 12 \\sqrt 5 \\]\n\tserves as a fundamental unit,\n\tas there are no smaller integer solutions to $a^2-5b^2=\\pm 4$.\n\n\tThe first several powers of $u$ are\n\t\\[\n\t\\begin{array}{rrr}\n\t\t\\renewcommand{\\arraystretch}{1.4}\n\t\tn & \\multicolumn{1}{c}{u^n} & \\text{Norm} \\\\ \\hline\n\t\t-2 & \\half(3-\\sqrt5) & 1 \\\\\n\t\t-1 & \\half (1-\\sqrt5) & -1 \\\\\n\t\t0 & 1 & 1 \\\\\n\t\t1 & \\half(1+\\sqrt5) & -1 \\\\\n\t\t2 & \\half(3+\\sqrt5) & 1 \\\\\n\t\t3 & 2 + \\sqrt 5 & -1 \\\\\n\t\t4 & \\half(7+3\\sqrt5) & 1 \\\\\n\t\t5 & \\half(11+5\\sqrt5) & -1 \\\\\n\t\t6 & 9 + 4\\sqrt 5 & 1\n\t\\end{array}\n\t\\]\n\tOne can see that the first integer solution is $(2,1)$, which gives $-1$.\n\tThe first solution with $+1$ is $(9,4)$.\n\tContinuing the pattern, we find that every third power of $u$ gives an integer solution\n\t(see also \\Cref{prob:unit_cubed}),\n\twith the odd ones giving a solution to $x^2-5y^2=-1$ and\n\tthe even ones a solution to $x^2-5y^2=+1$.\n\tAll solutions are generated this way, up to $\\pm$ signs\n\t(by considering $\\pm u^{\\pm n}$).\n\\end{example}\n\n\\section\\problemhead\n\\begin{problem}[Fictitious account of the battle of Hastings]\n\tDetermine the number of soldiers in the following battle:\n\t\\begin{quote}\n\t\tThe men of Harold stood well together,\n\t\tas their wont was, and formed thirteen squares,\n\t\twith a like number of men in every square thereof, and woe\n\t\tto the hardy Norman who ventured to enter their redoubts;\n\t\tfor a single blow of Saxon war-hatched would break his lance\n\t\tand cut through his coat of mail . . .\n\t\twhen Harold threw himself into the fray the Saxons\n\t\twere one might square of men, shouting the battle-cries,\n\t\t``Ut!'', ``Olicrosse!'', ``Godemite!''\n\t\\end{quote}\n\t% The answer can be found by hand.\n\t% You may assume that the army has size at least $1$ and\n\t% at most one billion.\n\\end{problem}\n\\begin{problem}\n\t\\label{prob:unit_cubed}\n\tLet $d > 0$ be a squarefree integer,\n\tand let $u$ denote the fundamental unit of $\\QQ(\\sqrt d)$.\n\tShow that either $u \\in \\ZZ[\\sqrt d]$,\n\tor $u^n \\in \\ZZ[\\sqrt d] \\iff 3 \\mid n$.\n\\end{problem}\n\\begin{problem}\n\tShow that there are no integer solutions to\n\t\\[ x^2 - 34y^2 = -1 \\]\n\tdespite the fact that $-1$ is a quadratic residue mod $34$.\n\\end{problem}\n", "meta": {"hexsha": "c3596540fae1b35457edc0c92012cb4a7e002ac8", "size": 9885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/pell.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/pell.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/pell.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.7647058824, "max_line_length": 103, "alphanum_fraction": 0.6511886697, "num_tokens": 3525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.617530777911283}}
{"text": "\\lab{Profiling Python Code}{Profiling}\n\\objective{Learn how to efficiently optimize Python code.}\n\\label{lab:ProfilingCode}\n\nThe best code goes through multiple drafts.\nIn a first draft, you should focus on writing code that does what it is supposed to and is easy to read.\nAfter writing a first draft, you may find that your code does not run as quickly as you need it to.\nThen it is time to \\emph{optimize} the most time consuming parts of your code so that they run as quickly as possible.\n\nIn this lab we will optimize the function \\texttt{qr1()} that computes the QR decomposition of a matrix via the modified Gram-Schmidt algorithm (see Lab \\ref{lab:QRdecomp}).\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import linalg as la\n\ndef qr1(A):\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = la.norm(Q[:, i])\n        Q[:, i] = Q[:, i]/la.norm(Q[:, i])\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-Q[:, j].dot(Q[:, i])*Q[:,i]\n    return Q, R\n\\end{lstlisting}\n\n\\section*{What to Optimize}\nPython provides a \\emph{profiler} that can identify where code spends most of its runtime.\nThe output of the profiler will tell you where to begin your optimization efforts.\n\nIn IPython\\footnote{If you are not using IPython, you will need to use the \\li{cProfile} module documented here: \\url{https://docs.python.org/2/library/profile.html}.}, \nyou can profile a function from the command line with \\texttt{\\%prun}.\nHere we profile \\texttt{qr1()} on a random $300 \\times 300$ array.\n\\begin{lstlisting}\n>>> A = np.random.rand(300, 300)\n>>> \\%prun qr1(A)\n\\end{lstlisting}\n\nOn this computer, we get the following output.\n\n{\\scriptsize\n\\begin{verbatim}\n         97206 function calls in 1.343 seconds\n\n   Ordered by: internal time\n\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.998    0.998    1.342    1.342 profiling_hw.py:4(qr1)\n    89700    0.319    0.000    0.319    0.000 {method 'dot' of 'numpy.ndarray' objects}\n      600    0.006    0.000    0.012    0.000 function_base.py:526(asarray_chkfinite)\n      600    0.006    0.000    0.009    0.000 linalg.py:1840(norm)\n     1200    0.005    0.000    0.005    0.000 {method 'any' of 'numpy.ndarray' objects}\n      600    0.002    0.000    0.002    0.000 {method 'reduce' of 'numpy.ufunc' objects}\n     1200    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}\n     1200    0.001    0.000    0.002    0.000 numeric.py:167(asarray)\n        1    0.001    0.001    0.001    0.001 {method 'copy' of 'numpy.ndarray' objects}\n      600    0.001    0.000    0.022    0.000 misc.py:7(norm)\n      301    0.001    0.000    0.001    0.000 {range}\n        1    0.001    0.001    0.001    0.001 {numpy.core.multiarray.zeros}\n      600    0.001    0.000    0.001    0.000 {method 'ravel' of 'numpy.ndarray' objects}\n      600    0.000    0.000    0.000    0.000 {method 'conj' of 'numpy.ndarray' objects}\n        1    0.000    0.000    1.343    1.343 <string>:1(<module>)\n        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n\\end{verbatim}\n}\n\n\nThe first line of the output tells us that executing \\texttt{qr1(A)} results in almost 100,000 function calls.  \nThen we see a table listing these functions along with data telling us how much time each takes.\nHere, \\texttt{ncalls} is the number of calls to the function, \\texttt{tottime} is the total time spent in the function, and \\texttt{cumtime} is the amount of time spent in the function including calls to other functions.\n\nFor example, the first line of the table is the function \\texttt{qr1(A)} itself. \nThis function was called once, it took 1.342s to run, and 0.344s of that was spent in calls to other functions.\nOf that 0.344s, there were 0.319s spent on 89,700 calls to \\texttt{np.dot()}.\n\nWith this output, we see that most time is spent in multiplying matrices.\nSince we cannot write a faster method to do this multiplication, we may want to try to reduce the number of matrix multiplications we perform.\n\n\n\n\\section*{How to Optimize}\nOnce you have identified those parts of your code that take the most time, how do you make them run faster?\nThis section lists a few ideas.\nAlways, you should use the profiling and timing functions to help you decide when an optimization is actually useful.\n\n\\subsection*{Avoid Recomputing Values}\nIn our function \\texttt{qr1()}, we can avoid recomputing \\texttt{R[i,i]} in the outer loop and \\texttt{R[i,j]} in the inner loop.\nThe rewritten function is as follows:\n\\begin{lstlisting}\ndef qr2(A):\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = la.norm(Q[:, i])\n        Q[:, i] = Q[:, i]/R[i, i]\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-R[i, j]*Q[:,i]\n    return Q, R\n\\end{lstlisting}\n\nProfiling \\texttt{qr2()} on a $300 \\times 300$ matrix produces the following output.\n\n{\\scriptsize\n\\begin{verbatim}\n         48756 function calls in 1.047 seconds\n\n   Ordered by: internal time\n\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.863    0.863    1.047    1.047 profiling_hw.py:16(qr2)\n    44850    0.171    0.000    0.171    0.000 {method 'dot' of 'numpy.ndarray' objects}\n      300    0.003    0.000    0.006    0.000 function_base.py:526(asarray_chkfinite)\n      300    0.003    0.000    0.005    0.000 linalg.py:1840(norm)\n      600    0.002    0.000    0.002    0.000 {method 'any' of 'numpy.ndarray' objects}\n      300    0.001    0.000    0.001    0.000 {method 'reduce' of 'numpy.ufunc' objects}\n      301    0.001    0.000    0.001    0.000 {range}\n      600    0.001    0.000    0.001    0.000 {numpy.core.multiarray.array}\n      600    0.001    0.000    0.001    0.000 numeric.py:167(asarray)\n      300    0.000    0.000    0.012    0.000 misc.py:7(norm)\n        1    0.000    0.000    0.000    0.000 {method 'copy' of 'numpy.ndarray' objects}\n      300    0.000    0.000    0.000    0.000 {method 'ravel' of 'numpy.ndarray' objects}\n        1    0.000    0.000    1.047    1.047 <string>:1(<module>)\n      300    0.000    0.000    0.000    0.000 {method 'conj' of 'numpy.ndarray' objects}\n        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}\n        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n\\end{verbatim}\n}\n\nOur optimization reduced almost every kind of function call by half, and reduced the total run time by 0.295s.\n\nSome less obvious ways to eliminate excess computations include moving computations out of loops, not copying large data structures, and simplifying mathematical expressions.\n\n\n\\subsection*{Avoid Nested Loops}\nThe best way to do this is to use NumPy array operations instead of iterating through arrays.\nIf you must use nested loops, focus your optimization efforts on the innermost loop, which gets called the most times.\n\n\\subsection*{Use Existing Functions Instead of Writing Your Own}\nIf there is an intuitive operation you would like to perform on an array, chances are that NumPy or another library already has a function that does it.\nPython and NumPy functions have already been optimized, and are usually many times faster than the equivalent you might write.\nWe saw an example of this in Lab \\ref{lab:NumPyArrays} where we compared NumPy array multiplication with our own matrix multiplication implemented in Python.\n\n\\subsection*{Use Generators When Possible}\nWhen you are iterating through a list, you can often replace the list with a \\emph{generator}.\nInstead of storing the entire list in memory, a generator computes each item as it is needed. \nFor example, the code\n\\begin{lstlisting}\n>>> for i in range(100):\n>>>     print i\n\\end{lstlisting}\nstores the numbers 0 to 99 in memory, looks up each one in turn, and prints it. \nOn the other hand, the code\n\\begin{lstlisting}\n>>> for i in xrange(100):\n>>>     print i\n\\end{lstlisting}\nuses a generator instead of a list. \nThis code computes the first number in the specified range (which is 0), and prints it.\nThen it computes the next number (which is 1) and prints that.\n\nIt is also possible to write your own generators. \nSee \\url{https://docs.python.org/2/tutorial/classes.html#generators} and \\url{https://wiki.python.org/moin/Generators} for more information.\n\nIn our example, replacing each \\texttt{range} with \\texttt{xrange} does not speed up \\texttt{qr2()} by a noticeable amount.\n\n\\subsection*{Avoid Excessive Function Calls}\nFunction calls take time.\nMoreover, looking up methods associated with objects takes time.\nRemoving ``dots'' can significantly speed up execution time.\n\nFor example, we could rewrite our function to reduce the number of times we need to look up the function \\texttt{la.norm()}.\n\n\\begin{lstlisting}\ndef qr2(A):\n    norm = la.norm\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = norm(Q[:, i])\n        Q[:, i] = Q[:, i]/R[i, i]\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-R[i, j]*Q[:,i]\n    return Q, R\n\\end{lstlisting}\nOnce again, an analysis with \\texttt{\\%prun} reveals that this optimization does not help significantly in this case.\n\n\n\\subsection*{Write Pythonic Code}\nSeveral special features of Python allow you to write fast code easily.\nFirst, list comprehensions are much faster than for loops.\nFor example, replace\n\\begin{lstlisting}\n>>> mylist = []\n>>> for i in xrange(100):\n>>>     mylist.append(math.sqrt(i))\n\\end{lstlisting}\nwith \n\\begin{lstlisting}\n>>> mylist = [math.sqrt(i) for i in xrange(100)]\n\\end{lstlisting}\nWhen it can be used, the function \\texttt{map()} is even faster.\n\\begin{lstlisting}\n>>> mylist = map(math.sqrt, xrange(100))\n\\end{lstlisting}\nThe analog of a list comprehension also exists for generators, dictionaries, and sets.\n\nSecond, swap values with a single assignment.\n\\begin{lstlisting}\n>>> a, b = 1, 2\n>>> a, b = b, a\n>>> print a, b\n2 1\n\\end{lstlisting}\n\nThird, many non-Boolean objects in Python have truth values.\nFor example, numbers are \\texttt{False} when equal to zero and \\texttt{True} otherwise.\nSimilarly, lists and strings are \\texttt{False} when they are empty and \\texttt{True} otherwise.\nSo when \\texttt{a} is a number, instead of\n\\begin{lstlisting}\n>>> if a != 0:\n\\end{lstlisting}\nuse\n\\begin{lstlisting}\n>>> if a:\n\\end{lstlisting}\n\\subsection*{Use Cython}\nWe will discuss Cython at the end of this lab.\n\n\\subsection*{Use a More Efficient Algorithm}\nThe optimizations discussed thus far will speed up your code at most by a constant.\nThey will not change the complexity of your code.\nIn order to reduce the complexity (say from $O(n^2)$ to $O(n \\log(n))$), you typically need to change your algorithm.\n\n\n\n\n\n\n\n\n\n\\section*{When to Stop}\nYou don't need to apply every possible optimization to your code.\nWhen your code runs acceptably fast, stop optimizing.\n\n\n\n\\section*{Cython}\nCython code is basically Python with extra type declarations.\nThis code is then compiled into C, which---depending on the details---can run much faster than the Python equivalent.\nIn this lab we will introduce Cython as a language and discuss how it can be used to speed up Python code.\n\n\\subsection*{Compiling Cython}\nWith a few exceptions, every Python program is also a Cython program.\nFor example, suppose you save the following script as \\texttt{cymodule.pyx}.\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy import linalg as la\n\ndef qr(A):\n    norm = la.norm\n    ncols = A.shape[1]\n    Q = A.copy()\n    R = np.zeros((ncols, ncols))\n    for i in range(ncols):\n        R[i, i] = norm(Q[:, i])\n        Q[:, i] = Q[:, i]/R[i, i]\n        for j in range(i+1, ncols):\n            R[i, j] = Q[:, j].dot(Q[:, i])\n            Q[:,j] = Q[:,j]-R[i, j]*Q[:,i]\n    return Q, R\n\\end{lstlisting}\nTo compile this code as Cython, we need to write another script, call it \\texttt{setup.py}.\n\\lstinputlisting[style=fromfile, language=Python]{setup.py}\nTo run the setup script, type the following in the command line.\n\\footnote{Note that \\texttt{python} in this line will need to refer to your version of Python that comes with Cython. \nOften, you will need to replace \\texttt{python} with a path pointing to a specific distribution of Python.}\n\\begin{lstlisting}\n>>> python setup.py build_ext --inplace\n\\end{lstlisting}\nNow start up IPython in the same directory where you ran the setup script.\nYou can import \\texttt{cymodule} just as if it were a Python module.\n\\begin{lstlisting}\n>>> import cymodule\n>>> cymodule.qr(A)\n\\end{lstlisting}\n\n\\subsection*{Speeding up Cython with Type Declarations}\nSo far, our Cythonized \\texttt{qr()} function does not run any faster than the Python version.\n\\footnote{Sometimes you will see speedup immediately after Cythonizing a Python function.}\nThe simplest way to take advantage of the C-compilation is to declare data types, as you would in a C program.\nAll Cython data types and their NumPy equivalents are listed in Table \\ref{table:cython_types}.\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|p{2.8cm}|p{2.5cm}|p{6cm}|}\n\\hline\nCython Type & NumPy Type& Description \\\\\n\\hline\nfloat & float32 & 32 bit floating point number \\\\\ndouble & float64 & 64 bit floating point number \\\\\nfloat complex & complex64 & 64 bit floating point complex number \\\\\ndouble complex & complex128 & 128 bit floating point complex number \\\\\nchar & int8 & 8 bit signed integer \\\\\nunsigned char & uint8 & 8 bit unsigned integer \\\\\nshort & int16 & 16 bit signed integer \\\\\nunsigned short & uint16 & 16 bit unsigned integer \\\\\nint & int32 & 32 bit signed integer \\\\\nunsigned int & uint32 & 32 bit unsigned integer \\\\\nlong & int32 or int64 & 32 or 64 bit signed integer (depends on platform) \\\\\nunsigned long & uint32 or uint64 & 32 or 64 bit unsigned integer (depends on platform ) \\\\\nlong long & int64 & 64 bit signed integer \\\\\nunsigned long long & uint64 & 64 bit unsigned integer \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Numeric types available in Cython.}\n\\label{table:cython_types}\n\\end{table}\n\nIn our example, when we declare the index \\texttt{j} to be an \\texttt{int}, the inner for loop is pushed into C (instead of Python), speeding up our code immensely.\nWe do this by modifying \\texttt{cymodule.pyx} as follows.\n\\begin{lstlisting}\n...\ndef qr():\n    cdef int j\n    ncols = A.shape[1]\n    Q = A.copy()\n    ...\n\\end{lstlisting}\n\nWe could also declare \\texttt{i} to be an int, but the effect of doing so is negligible.\n\nAfter modifying \\texttt{cymodule.pyx}, we must recompile it by running the script \\texttt{setup.py}, and then re-import it into Python.\nWhen we profile this function, we see that it is indeed a good deal faster than its Python cousin, and all the speed up is in the function itself (where the for loops are).\n{\\scriptsize\n\\begin{verbatim}\n   ...\n   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n        1    0.949    0.949    0.961    0.961 {cymodule.qr}\n   ...\n       \\end{verbatim}\n       }\nSimilarly, you can speed up function calls in Cython by declaring the types of some or all of the arguments.\n\\begin{lstlisting}\ndef myfunction(double arg1, int arg2, arg3):\n    ...\n\\end{lstlisting}\n\n\n\\subsection*{A Caution}\nNumPy's array methods are usually faster than a Cython equivalent you could code yourself.\nIf you are unsure which method is fastest, time them.\n\nMoreover, a good algorithm written with a slow language (like Python) is faster than a bad algorithm written in a fast language (like C).\nHence, focus on writing fast algorithms with good Python code, and only use Cython when and where it is necessary.\n\n\n\n\n\n\\begin{problem}\nPractice profiling and optimizing functions you have already written.\nSome suggested functions are listed below.\n\\begin{itemize}\n\\item LU decomposition (Lab \\ref{lab:ChangeBasis}). \n\\item Householder triangularization or Hessenburg decomposition (Lab \\ref{lab:QRdecomp}).\n\\item Givens triangularization (Lab \\ref{lab:givens})\n\\item Image Segmentation (Lab \\ref{lab:ImgSeg_eigenvalues})\n\\item Eigenvalue Solvers (Lab \\ref{lab:EigSolve})\n\\end{itemize}\nYour solution should include a before and after profiling of the function.  \nIt should also include a list of changes, the reasoning behind the changes, and the effect of the changes on runtime.  \n\nIt is possible that you will not be able to speed up the function significantly. \nRemember it is more important for code to be readable than to execute quickly.\n\\end{problem}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n      \n\\section*{More on Cython (Optional)}\nThis section has a more complete introduction to Cython. \nFor another reference, see \\url{http://docs.cython.org/src/tutorial/cython_tutorial.html}.\n\n\\subsection*{Compilation}\n\nCython code is usually written in a \\texttt{.pyx} file, which is then compiled to C.\nNext the C is compiled to a Python extension written in machine code.\nFigure \\ref{cython:compilation} shows how Cython code is compiled and called.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=.7\\textwidth]{compilation.pdf}\n\\caption{A diagram showing how Cython code is compiled and called.\nThe path from calling a Cython function in a Python file to its evaluation is shown in red.}\n\\label{cython:compilation}\n\\end{figure}\n\nThese two compilations (first to C and then to a Python extension) are accomplished by the script \\texttt{setup.py} discussed earlier in this lab.\n\\lstinputlisting[style=fromfile, language=Python]{setup.py}\nThe call to \\texttt{cythonize()} compiles \\texttt{cymodule.pyx} to C, and the call to \\texttt{setup()} converts the C code to a Python extension.\n\n\\begin{info}\nYou can learn more about the Python/C balance in your Cython file with the following line.\n\\begin{lstlisting}\n>>> cython -a cymodule.pyx\n\\end{lstlisting}\nThis will generate a \\li{html} file that you can open with your web browser.\nIt will show the lines that use Python in bright yellow and lines that use C in white.\n\\end{info}\n\nCython code can be compiled and imported to IPython with the Cython magic function.\nLoad this function with the following command.\n\\footnote{In older versions of IPython and Cython, you may need to use the command \\li{\\%load_ext cythonmagic}.}\n\\begin{lstlisting}\n>>> %load_ext Cython\n\\end{lstlisting}\nNow you can define any Cython function in the command line by prefacing it with \\li{\\%\\%cython}.\n\\begin{lstlisting}\n>>> %%cython\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> def qr():\n>>>     cdef int j\n>>> ...\n\\end{lstlisting}\n\n\\subsection*{Type Declarations}\nType declarations make Cython faster than Python because a computer can process numbers faster when it knows ahead of time what type they are.\nDeclaring a variable type in Cython makes the variable a native machine type instead of a Python object.\n\nYou can initialize a variable when it is declared or afterwards.\nIt is possible to initialize several variables at once, as demonstrated below.\n\n\\begin{lstlisting}\n# Declare integer variables i, j, and k.\n# Set k equal to 2.\ncdef int i, j, k=2\n\ncdef:\n    # Declare and initialize m equal to 4 and n equal to 5.\n    int m=4, n=5\n    # Declare and initialize e equal to 2.71.\n    double e = 2.71\n    # Declare a double precision complex number a.\n    double complex a\n\\end{lstlisting}\n\n\\begin{warn}\nUnlike Python integers, which can be arbitrarily large, Cython integers can overflow.\n\\end{warn} \n\n\\subsection*{Arrays in Cython}\nYou can also declare types for arrays.\nDoing so produces a \\emph{typed memoryview}, or Cython array.\nAs with ordinary variables, typed memoryviews can be initialized when they are declared or later.\n\\begin{lstlisting}\n# Define a NumPy array\nA = np.linspace(0,1,6)\n\n# Create typed memoryviews on A and B\ncdef double[:] cA = A\ncdef int[:,:] cB\n\n# Initialize cB\ncB = np.array([[1,2],[3,4],[5,6]], dtype=np.dtype(\"i\"))\n\\end{lstlisting}\n\nAccessing single entries from a memoryview is faster than accessing entries of a NumPy array.\nAlso, passing slices of a memoryview to a Cython function is fast.\nHowever, memoryviews do not support mathematical operations.\nThese must be performed on NumPy objects, or by looping through the arrays.\n\n\\begin{info}\nMemoryviews can be passed as arguments to most NumPy functions.\nNumpy includes functions for all common arithmetic operations.\nFor example, you can add typed memoryviews with \\li{c = np.add(a, b)}.\nThis may or may not be faster than looping through the array.\n\\end{info}\n\n\\subsection*{Compiler Directives}\nWhen you access elements of an array, Cython checks that the indices are within bounds.\nCython also allows negative indexing the same way Python does.\nThese features slow down code execution.\nAfter a program has been carefully debugged, they may be removed via \\emph{compiler directives}.\n\nCompiler directives in Cython can be included as comments or function decorators.\nDirectives included in comments will apply to the whole file, while function decorators will only apply to the function immediately following.\nThe comments to turn off bounds checking and negative indices are\n\\begin{lstlisting}\n# cython: boundscheck=False\n# cython: wraparound=False\n\\end{lstlisting}\nTo use the function decorators, first import the \\li{cython} module by including the line \\li{cimport cython} in your import statements.\nThe decorators are\n\\begin{lstlisting}\ncimport cython\n@cython.boundscheck(False)\n@cython.wraparound(False)\n\\end{lstlisting}\n\nCython has many other compiler directives, including \\li{cdivision}.\nWhen \\li{cdivision} is set to \\li{True}, the \\li{\\%} operator returns a number with the sign of the first argument (like in C).\nAlso, division by 0 will no longer raise a \\li{ZeroDivisionError}, which will increase the speed of your program.\n\n\\subsection*{More on Functions in Cython}\nSpeed up function calls in Cython by declaring the types of some or all of the arguments.\n\\begin{lstlisting}\ndef myfunction(double[:] X, int n, double h, items):\n    ...\n\\end{lstlisting}\nIf we pass in a NumPy array for the argument \\li{X}, Cython will convert it to a typed memoryview before it enters the function.\nHowever, if we pass in a NumPy array for \\li{items}, it will remain a NumPy array in the function.\nBoth typed and untyped arguments can be made into keyword arguments.\n\nCython also allows you to make C functions that are only callable within the C extension you are currently building.\nThey are not ported into the Python namespace.\nThese functions are declared using the same syntax as in Python, except the keyword \\li{def} is replaced with \\li{cdef}.\nThe keyword \\li{cpdef} combines \\li{def} and \\li{cdef} by creasting two versions of the function: one for Python and one for C.\n\nYou can also specify the return type for functions declared using \\li{cdef} and \\li{cpdef}, as in the code below.\n\\begin{lstlisting}\ncpdef int myfunction(double[:] X, int n, double h, items):\n    ...\n\\end{lstlisting}\n\n\\subsection*{Some Examples}\nThe following Python function computes the dot product of two 1-D arrays.\n\\begin{lstlisting}\ndef pydot(A, B):\n    tot = 0.\n    for i in xrange(A.shape[0]):\n        tot += A[i] * B[i]\n    return tot\n\\end{lstlisting}\nA C equivalent can be compiled from the following Cython code.\n\\begin{lstlisting}\ncimport cython\n\n@cython.boundscheck(False)\n@cython.wraparound(False)\ndef cydot(double[:] A, double[:] B):\n    cdef double tot=0.\n    cdef int i\n    for i in xrange(A.shape[0]):\n        tot += A[i] * B[i]\n    return tot\n\\end{lstlisting}\n\nFigure \\ref{cython:dot} compares the speed of \\li{pydot()}, \\li{cydot()}, and the \\li{dot()} method of a NumPy array.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{dot.pdf}\n\\caption{The running times of \\li{pydot()}, \\li{cydot()}, and the \\li{dot()} method of a NumPy array on vectors of length ``Array Size.''\nThe Cython version runs almost as fast as the version built into NumPy.}\n\\label{cython:dot}\n\\end{figure}\n\nFor a second example, we will write functions which compute $AA^T$ from $A$.\nThat is, given \\li{A}, these functions compute \\li{B} where\n\\li{B[i,j] = dot(A[i],A[j])}.\n\nHere is the Python solution.\n\\begin{lstlisting}\ndef pyrowdot(A):\n    B = np.empty((A.shape[0], A.shape[0]))\n    for i in xrange(A.shape[0]):\n        for j in xrange(i):\n            B[i,j] = pydot(A[i], A[j])\n        B[i,i] = pydot(A[i], A[i])\n    for i in xrange(A.shape[0]):\n        for j in xrange(i+1, A.shape[0]):\n            B[i,j] = B[j,i]\n    return B\n\\end{lstlisting}\n\nHere is the Cython solution. \nWe changed the function \\li{cydot()} to a C function since it will only be called by \\li{cyrowdot()}.\nAlso, the Cython solution uses a typed memoryview of its input.\n\n\\begin{lstlisting}\nimport numpy as np\ncimport cython\n# cython: boundscheck=False\n# cython: wraparound=False\n\ncdef double cydot(double[:] A, double[:] B):\n    cdef double tot=0.\n    cdef int i, n=A.shape[0]\n    for i in xrange(n):\n        tot += A[i] * B[i]\n    return tot\n\ndef cyrowdot(double[:,:] A):\n    cdef double[:,:] B = np.empty((A.shape[0], A.shape[0]))\n    cdef int i, j, n=A.shape[0]\n    for i in xrange(n):\n        for j in xrange(i):\n           B[i,j] = cydot(A[i], A[j])\n        B[i,i] = cydot(A[i], A[i])\n    for i in xrange(n):\n        for j in xrange(i+1, n):\n            B[i,j] = B[j,i]\n    return np.array(B)\n\\end{lstlisting}\n\nThis can also be done in NumPy by running \\li{A.dot(A.T)}.\nThe timings of \\li{pyrowdot()}, \\li{cyrowdot()}, and the NumPy command \\li{A.dot(A.T)} are shown in Figure \\ref{cython:rowdot}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{rowdot.pdf}\n\\caption{The timings of \\li{pyrowdot()}, \\li{cyrowdot()}, and the NumPy command \\li{A.dot(A.T)}.\nThe arrays used for testing were $n\\times 3$ where $n$ is shown along the horizontal axis.}\n\\label{cython:rowdot}\n\\end{figure}\n\nIn both of these examples, NumPy's implementation was faster than the version we wrote in Cython.\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Write the following function in Python.\n\\begin{lstlisting}\ndef pysum(X):\n    ''' Return the sum of the elements of X.\n    \n    INPUTS:\n    X - a 1-D NumPy array\n    ''''\n\\end{lstlisting}\n\n\\item Rewrite the same function in Cython using a typed for-loop, a typed memoryview of \\li{X}, and appropriate compiler directives.\n\n\\item Compare the speed of the functions you just wrote, the builtin \\li{sum()} function, and NumPy's \\li{sum()} function.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nThe code below defines a Python function which takes a matrix to the $n$th power.\n\\begin{lstlisting}\ndef pymatpow(X, power):\n    ''' Return X^{power}.\n    \n    INPUTS:\n    X\t\t- A square 2-D NumPy array\n    power\t- An integer\n    '''\n    prod = X.copy()\n    temparr = np.empty_like(X[0])\n    size = X.shape[0]\n    for n in xrange(1, power):\n        for i in xrange(size):\n            for j in xrange(size):\n                tot = 0.\n                for k in xrange(size):\n                    tot += prod[i,k] * X[k,j]\n                temparr[j] = tot\n            prod[i] = temparr\n    return prod\n\\end{lstlisting}\n\n\\begin{enumerate}\n\\item Port \\li{pymatpow()} to Cython using typed for-loops, typed arrays, and appropriate compiler directives.\n\\item Compare the speed of \\li{pymatpow()}, the function you just wrote, and the \\li{np.dot()} function.\n\\end{enumerate}\nNumPy takes products of matrices by calling BLAS and LAPACK, which are heavily optimized linear algebra libraries written in C, assembly, and Fortran.\n\\end{problem}\n\n\n\\begin{problem}\nIn Lab \\ref{lab:ChangeBasis} you wrote a function to compute the LU decomposition of a matrix.\n\\begin{enumerate}\n\\item Rewrite this function so it performs every operation element-by-element instead of using NumPy array operations.\n\\item Port the function from part (a) to Cython.\nUse typed for-loops, typed memoryviews, and appropriate compiler directives.\nYou may assume that you are only dealing with real arrays of double precision floating point numbers.\n\\item Compare the speed of your new solutions to the speed of the NumPy version you wrote earlier.\n\\end{enumerate}\n\\end{problem}\n\n\nThe correct choice of algorithm is more important than a fast implementation.\nFor example, suppose you wish to solve the following tridiagonal system.\n\\[\\begin{bmatrix}\nb_0 & c_0 & 0 & 0 & 0 & \\cdots & \\cdots & 0 \\\\\na_0 & b_1 & c_1 & 0 & 0 & \\cdots & \\cdots & 0 \\\\\n0 & a_1 & b_2 & c_2 & 0 & \\cdots & \\cdots & 0 \\\\\n0 & 0 & a_2 & b_3 & c_3 & \\cdots & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\ddots & \\vdots \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\ddots & c_{n-1} \\\\\n0 & 0 & 0 & 0 & 0 & \\cdots & a_{n-1} & b_n\n\\end{bmatrix}\n\\begin{bmatrix}\nd_0\\\\\nd_1\\\\\nd_2\\\\\nd_3\\\\\n\\vdots\\\\\n\\vdots\\\\\nd_n\n\\end{bmatrix}\n=\n\\begin{bmatrix}\nx_0\\\\\nx_1\\\\\nx_2\\\\\nx_3\\\\\n\\vdots\\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\\]\nOne way to do this is with the general solve method in SciPy's \\li{linalg} module.\nAlternatively, you could use an algorithm optimized for tridiagonal matrices.\nThe code below implements one such algorithm in Python.\n\nThe final result is stored in \\li{x}, and \\li{c} is used to store temporary values.\n\\begin{lstlisting}\ndef pytridiag(a, b, c, x):\n    '''Solve the tridiagonal system Ad = x where A has diagonals a, b, and c.\n    \n    INPUTS:\n    a, b, c, x - All 1-D NumPy arrays.\n    \n    NOTE:\n    The final result is stored in `x` and `c` is used to store temporary values.\n    '''\n    n = x.size\n    temp = 0.\n    c[0] /= b[0]\n    x[0] /= b[0]\n    for i in xrange(n-2):\n        temp = 1. / (b[i+1] - a[i] * c[i])\n        c[i+1] *= temp\n        x[i+1] = (x[i+1] - a[i] * x[i]) * temp\n    x[n-1] = (x[n-1] - a[n-2] * x[n-2]) / (b[n-1] - a[n-2] * c[n-2])\n    for i in xrange(n-2, -1, -1):\n        x[i] = x[i] - c[i] * x[i+1]\n\\end{lstlisting}\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Port the above code to Cython using typed for-loops, typed memoryviews and appropriate compiler directives.\n\\item Compare the speed of your new function with \\li{pytridiag()} and \\li{scipy.linalg.solve()}.\nTo compare the first two functions, start with $1000000 \\times 1000000$ sized systems.\nWhen testing the SciPy algorithm, start with $1000 \\times 1000$ systems.\n\\item What do you learn about good implementation versus proper choice of algorithm?\n\\end{enumerate}\nNote that an efficient tridiagonal matrix solver is implemented by \\li{scipy.sparse.linalg.spsolve()}.\n\\end{problem}\n\n\n", "meta": {"hexsha": "239820e0d803c61cf2a5b6b0b50a625c0e727b4d", "size": 30415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Profiling/oldProfiling.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/Profiling/oldProfiling.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/Profiling/oldProfiling.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": 39.0938303342, "max_line_length": 220, "alphanum_fraction": 0.7011014302, "num_tokens": 8637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321964553656, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.6175307762680843}}
{"text": "\\section{Scope and Motivation}\n\\label{sec:toyMC}\n\nIn this section, we discuss the crucialness of waveform analysis for incident light measurements in PMT-based experiments.\n\n\\subsection{Light curve}\nA particle interacts with matter and deposits energy when passing through the detector. Part of such energy converts into visible Cherenkov or scintillation photons. The \\textit{light curve} is the time evolution of light intensity at a PMT,\n\\begin{equation}\n  \\label{eq:light-curve}\n  \\mu\\phi(t-t_0)\n\\end{equation}\nwhere $\\mu$ is the intensity factor, $t_0$ is the time shift factor and $\\phi(\\cdot)$ is the normalized shape function. We parameterize the scintillation light curve as several exponentials with different decay rates~\\cite{rebber_particle_2021} and instantaneous Cherenkov light curve by a Dirac delta function.  It is convienent to model the PMT transit time spread~(TTS) in $\\phi(t)$ as a Gaussian smear, giving an \\textit{ex-Gaussian} or \\textit{exponentially modified Gaussian}~\\cite{li_separation_2016},\n\\begin{align}\n    \\phi(t) = \\frac{1}{2\\tau_\\ell} \\exp\\left(\\frac{\\sigma_\\ell^2}{2\\tau_\\ell^2}-\\frac{t}{\\tau_\\ell}\\right) \\left[1 - \\erf\\left( \\frac{\\sigma_\\ell}{\\sqrt{2}\\tau_\\ell} - \\frac{t}{\\sqrt{2}\\sigma_\\ell} \\right)\\right],\n    \\label{eq:time-pro}\n\\end{align}\nwhere subscript $\\ell$ stands for ``light curve'' and $\\sigma_\\ell$ encodes the timing uncertainty mainly from TTS. $\\phi(t)$ of Cherenkov light is a pure Gaussian by taking $\\tau_\\ell \\rightarrow 0$. Figure~\\ref{fig:time-pro} illustrates 3 examples of $\\phi(t)$. \n\n\\begin{figure}[!htb]\n  \\centering\n  \\resizebox{0.5\\textwidth}{!}{\\input{figures/profile.pgf}}\n  \\caption{\\label{fig:time-pro} Effective light curves in 3 settings.  A scintillator paired with ultra-fast photo-sensors gives the green curve with $\\tau_\\ell \\gg \\sigma_\\ell$.  A fast Cherenkov detector by the red curve has $\\tau_\\ell \\ll \\sigma_\\ell$.  The blue curve combining $\\tau_\\ell=\\SI{20}{ns}$ and $\\sigma_\\ell=\\SI{5}{ns}$ represents a typical scintillation detector.  We can regard $\\phi(t)\\mathrm{d}t$ as a probability density function~(PDF at the vertical axis) of PE times.}\n\\end{figure}\n\n\n\\subsection{Single PE response}\n\\label{subsec:spe}\n\nA PE induced by a photon at the PMT photocathode is then accelerated, collected, and amplified into $\\num[retain-unity-mantissa=false]{\\sim 1e7}$ electrons, forming a voltage pulse $V_\\mathrm{PE}(t)$ in the PMT output.\n\\begin{figure}[H]\n  \\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\resizebox{\\textwidth}{!}{\\input{figures/spe.pgf}}\n    \\caption{\\label{fig:spe} Single PE response $V_\\mathrm{PE}(t)$ in eq.~\\eqref{eq:dayaspe}.}\n  \\end{subfigure}\n  \\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\resizebox{\\textwidth}{!}{\\input{figures/wave.pgf}}\n    \\caption{\\label{fig:pile} PE pile-up and white noise in an PMT waveform.}\n  \\end{subfigure}\n  \\caption{A single PE from a PMT induces a voltage pulse in \\subref{fig:spe}. Multiple PEs piling up at a PMT form an input waveform $w(t)$ in \\subref{fig:pile}, when PEs are barely visually separable from each other. Output charge $\\hat{\\bm{t}}, \\hat{\\bm{q}}$ also in \\subref{fig:pile}, which we will discuss in~\\ref{sec:algorithm}. }\n\\end{figure}\n\nS.~Jetter~et al.~\\cite{jetter_pmt_2012} parameterizes $V_\\mathrm{PE}(t)$ as,\n\\begin{equation}\n  V_\\mathrm{PE}(t) = V_{0}\\exp\\left[-\\frac{1}{2}\\left(\\frac{\\log(t/\\tau_\\mathrm{PE})}{\\sigma_\\mathrm{PE}}\\right)^{2}\\right],\n  \\label{eq:dayaspe}\n\\end{equation}\nwhere shape parameters $\\tau_\\mathrm{PE}=\\SI{8}{ns}$, $\\sigma_\\mathrm{PE}=\\SI{0.5}{ns}$ and $V_{0}=\\SI{14.08}{mV}$, see figure~\\ref{fig:spe}.  A sample of PEs from the light curve $\\phi(t)$ in eq.~\\eqref{eq:time-pro} can be formulated as several delta functions, also known as sparse spike train~\\cite{levy_reconstruction_1981}, \n\\begin{equation}\n  \\label{eq:lc-sample}\n  \\tilde{\\phi}(t) = \\sum_{i=1}^{N_{\\mathrm{PE}}} q_i \\delta(t-t_i),\n\\end{equation}\nwhere $N_\\mathrm{PE}$ is the number of PEs, following Poisson distribution with parameter $\\mu$.  $t_i$ is the hit time of the $i$-th PE, $q_i$ is the relative charge of the $i$-th PE from charge distribution $\\mathcal{N}(1,\\sigma_\\mathrm{q}^2)$.  $\\sigma_\\mathrm{q}$ is set to $0.4$ in our simulation.\n\nA noise-free waveform $\\tilde{w}(t)$ is convolution of $\\tilde{\\phi}(t)$ and $V_\\mathrm{PE}(t)$, and the PMT voltage output waveform $w(t)$ is a time series modeled by the sum of $\\tilde{w}(t)$ and a Gaussian white noise $\\epsilon(t)$,\n\\begin{equation}\n  \\label{eq:1}\n  \\begin{aligned}\n    \\tilde{w}(t) &= \\tilde{\\phi}(t) \\otimes V_\\mathrm{PE}(t) \\\\\n    w(t) &= \\tilde{w}(t) + \\epsilon(t) = \\sum_{i=1}^{N_\\mathrm{PE}} q_i V_\\mathrm{PE}(t-t_i) + \\epsilon(t).\n  \\end{aligned}\n\\end{equation}\nSee figure~\\ref{fig:pile} for an example.\n\n\n\\subsection{Measurement of incident light}\n\\label{sec:time}\nWe see in figure~\\ref{fig:pile} that pile-ups and noises hinder the time $t_i$ and charge $q_i$ of the PEs. Fortunately event reconstruction only takes the time shift $t_0$ and the intensity $\\mu$ in eq.~\\eqref{eq:light-curve} as inputs, where $t_0$ carries the time of flight information and $\\mu$ is the expected $N_\\mathrm{PE}$ in a real detector.  All the uncertainties of $\\hat{t}_i$, $\\hat{q}_i$ and $\\hat{N}_\\mathrm{PE}$ are reflected in $\\hat{t}_0$ and $\\hat{\\mu}$. In this article, we denote $\\hat{x}$ as an estimator for the corresponding variable $x$ if not otherwise specified.  Classical TDC extracts the waveform's threshold crossing time $\\hat{t}_\\mathrm{1st}$ to approximate hit time of the first PE, while QDC extracts total charge $Q$ from waveform integration to estimate $\\mu$ by $\\hat{\\mu}_Q$.\n\n\\subsubsection{Time $t_0$}\n\\label{sec:time-shift-t_0}\n\n$\\hat{t}_\\mathrm{1st}$ is a biased estimator of $t_0$.  It is affected by the light intensity $\\mu$, as will be shown in figure~\\ref{fig:biasmethods} and discussed in section~\\ref{subsec:timeresolution}. We define the resolution $\\sigma_\\mathrm{1st}$ for a batch of waveforms as the standard deviation of $\\Delta t_0 = \\hat{t}_\\mathrm{1st} - t_0$. From a hypothetical perfect measurement of $t_i$, we define an ideal maximum likelihood estimator~(MLE) $\\hat{t}_\\mathrm{ALL}$ to capture time information of all the PEs,\n\\begin{equation}\n  \\label{eq:2}\n  \\hat{t}_\\mathrm{ALL} = \\arg\\underset{t_0}{\\max} \\prod_{i=1}^{N_\\mathrm{PE}} \\phi(t_i-t_0).\n\\end{equation}\nThe corresponding $\\sigma_\\mathrm{ALL}$ is the lower bound of time resolution. \n\nTo characterize $\\hat{t}_\\mathrm{1st}$ and $\\hat{t}_\\mathrm{ALL}$, we scan $\\mu$ from \\numrange{0}{30} for each light curve in figure~\\ref{fig:time-pro}. We generate a sample of $\\num[retain-unity-mantissa=false]{1e4}$ waveforms having at least 1 PE for every triplet of $(\\tau_\\ell, \\sigma_\\ell, \\mu)$.  Figure~\\ref{fig:reso-diff} shows that $\\sigma_{\\mathrm{1st}}$ equals $\\sigma_{\\mathrm{ALL}}$ when $\\tau_\\ell \\gg \\sigma_\\ell$, because $\\hat{t}_\\mathrm{ALL}$ reduces to $\\hat{t}_\\mathrm{1st}$(=$\\min_i t_i$) for an exponential light curve. For $\\mu \\to 0$, $\\sigma_{\\mathrm{1st}}$ and $\\sigma_{\\mathrm{ALL}}$ are also equal because at most 1 PE is available.  TDC is effective in those cases.\n\n\\begin{figure}[H]\n  \\centering\n  \\resizebox{0.8\\textwidth}{!}{\\input{figures/vs-deltadiv.pgf}}\n  \\caption{\\label{fig:reso-diff} Time resolution comparisons between $\\hat{t}_{\\mathrm{ALL}}$~(solid lines, when using information of all PEs) and $\\hat{t}_\\mathrm{1st}$~(dashed lines, using the true first PE instead of the threshold crossing time to eliminate the influence from TDC, while their resolutions are in comparison).  The difference is manifested especially when $\\sigma_\\ell$ and $\\mu$ are large. The three cases of $(\\tau_\\ell, \\sigma_\\ell)/\\si{ns}$ represent the scintillation with ultra-fast PMTs~$(20, 0)$, Cherenkov~$(0, 5)$ and scintilation coupled with PMT TTS~$(20, 5)$. The performance of waveform analysis lies between $\\sigma_{\\mathrm{1st}}$ and $\\sigma_{\\mathrm{ALL}}$. }\n\\end{figure}\n\nNevertheless, for $\\sigma_\\ell > 0$ and $\\mu >0$, the $\\sigma_{\\mathrm{1st}}$ significantly deteriorates from $\\sigma_{\\mathrm{ALL}}$.  For Cherenkov and scintillation experiments with non-negligible PMT TTS and occupancy, we shall explore more sophisticated waveform analysis algorithms to go beyond $\\hat{t}_{\\mathrm{1st}}$ and recover the accuracy of $\\hat{t}_\\mathrm{ALL}$ in eq.~\\eqref{eq:2} from waveform in eq.~\\eqref{eq:1}.\n\n\\subsubsection{Intensity $\\mu$}\n\\label{sec:intensity-mu}\n\nThe charge estimator $\\hat{\\mu}_Q$\n\\begin{equation}\n  \\begin{aligned}\n  \\label{eq:mu-q}\n  \\hat{\\mu}_Q = \\frac{\\int w(t) \\mathrm{d} t}{\\int V_\\mathrm{PE}(t) \\mathrm{d} t} &= \\frac{\\sum_{i=1}^{N_\\mathrm{PE}} \\int \\left[ q_i V_\\mathrm{PE}(t-t_i) + \\epsilon(t) \\right] \\mathrm{d} t}{\\int V_\\mathrm{PE}(t) \\mathrm{d} t} \\\\\n  & = \\sum_{i=1}^{N_\\mathrm{PE}} q_i + \\frac{\\int \\epsilon(t) \\mathrm{d} t}{\\int V_\\mathrm{PE}(t) \\mathrm{d} t}\n  \\end{aligned}\n\\end{equation}\nis not only affected by Poisson fluctuation of $N_\\mathrm{PE}$, but also by charge resolution of a PE $\\sigma_\\mathrm{q}$.  Sometimes we mitigate the impact of $\\sigma_\\mathrm{q}$ by rounding $\\hat{\\mu}_Q$ to integers.  It works well for $N_\\mathrm{PE} \\le 1$, which is equivalently a hit-based 0-1 $\\mu$ estimator $\\hat{\\mu}_\\mathrm{hit}$.  But for $N_\\mathrm{PE} \\ge 2$, it is hard to interpret $\\hat{\\mu}_Q$ rounding by physics principles and $\\hat{\\mu}_\\mathrm{hit}$ does not gain any additional information from the extra PEs.\n\nThe goal of waveform analysis is to eliminate the impact of $\\sigma_\\mathrm{q}$ as much as possible.  The resolution of any $\\mu$ estimator is therefore lower bounded by the pure Poisson fluctuation of $N_\\mathrm{PE}$.\n\n\\subsubsection{Shape $\\phi(\\cdot)$}\n\\label{sec:shape-phicdot}\n\nThe shape of a light curve is determined by light emission time profile, PMT timing and light propagation including refraction, reflection, dispersion and scattering.  $\\phi(\\cdot)$ thus depends on event locations.  In this article, we model $\\phi(\\cdot)$ by eq.~\\eqref{eq:time-pro} for simplicity and leave the $\\phi(\\cdot)$ variations to event reconstruction in the future publications.", "meta": {"hexsha": "cb440ac8fb8583b3b4060b2e324347dd2b6f69ee", "size": 10090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Note/toyMC.tex", "max_stars_repo_name": "mhy12345/waveform-analysis", "max_stars_repo_head_hexsha": "b71cd456f024eda3ecc04f5f6a69910ce229e86e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Note/toyMC.tex", "max_issues_repo_name": "mhy12345/waveform-analysis", "max_issues_repo_head_hexsha": "b71cd456f024eda3ecc04f5f6a69910ce229e86e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Note/toyMC.tex", "max_forks_repo_name": "mhy12345/waveform-analysis", "max_forks_repo_head_hexsha": "b71cd456f024eda3ecc04f5f6a69910ce229e86e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-06T05:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-06T05:47:02.000Z", "avg_line_length": 92.5688073394, "max_line_length": 814, "alphanum_fraction": 0.717839445, "num_tokens": 3184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199795472731, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6174584051041432}}
{"text": "\\title{\\bf Gravitational Lensing}\n\n\\section{Basics}\n\nUnder general relativity, in the presence of mass light is bent by the\ncurvature of spacetime. On astronomical scales this can cause the\nphenomenon of {\\it gravitational lensing}. \n\n\\subsection{Point mass lensing}\n\nUnderstanding lensing begins with the point mass case. It can be shown\nthat a photon traveling by a point mass, with an impact parameter $r$,\nis in the small deflection limit deflected by an angle:\n\\begin{equation}\n\\theta_D = \\frac{4GM}{rc^2} \n\\end{equation}\nThis differs by a factor of two from the equivalent Newtonian\ncalculation. An important feature of lensing is that it is achromatic;\ni.e., independent of wavelength.\n\nFigure \\ref{fig:symmetric} describes the symmetric point lens case and\ndefines the distances involved. In an analog to the optical thin lens\napproximation, we define the {\\it source plane} and the {\\it lens\n  plane}. In the perfectly aligned case the observer sees the source\nas a ring surrounding the lens; perfect alignment means an offset\nsubstantially than the source size.  A characteristic quantity of a\nlens is radius of this ring, which is the {\\it Einstein angle}:\n\\begin{equation}\n\\theta_E =  \\sqrt{\\frac{4GM}{c^2}} \\sqrt{\\frac{D_{LS}}{D_L D_S}}\n\\end{equation}\nwhich can be related to the {\\it Einstein radius} in the lens plane\n$r_E = D_L \\theta_E$.\n\nFigure \\ref{fig:offset} describes the offset point lens case. If the\nsource is a point source, this will result in two magnified (and one\nhighly demagnified) images for the observer. The condition on the\nsource angle:\n\\begin{equation}\n\\beta < \\theta_E\n\\end{equation}\ndefines the {\\it strong lensing} regime. In this regime, the two\nimages appear near the Einstein ring location. If the source is\nextended instead of point-like, it can appear highly distorted in the\nstrong lensing case.\n\nThe opposite case is known as the {\\it weak lensing} regime. \n\nIn either case, the distortion of lensing has an effect on the\napparent brightness of the object. The total magnification can be\ndefined as the increase in the solid angle of the image. This solid\nangle increase occurs even if our instrumentation still cannot detect\nthe extended nature of the image. Because surface brightness (more\ntechnically specific intensity) is conserved in general relativity\nthis magnification leads to an increase in total flux density.\n\nFor multiply imaged sources, the images formed follow different paths\nof different distances. This fact leads to a relative delay between\nphotons that travel different paths. In addition, a different general\nrelativistic delay is associated with each path, known as the {\\it\nShapiro delay}. Fluctuations in the source will appear to the observer\nat different times. A measured delay yields a measurement of physical\ndistance that can in principle be used to determine the distances of\nthe source and lens.\n\n\\subsection{Lensing from extended mass sheets}\n\nOn cosmological scales, weak lensing outside the Einstein radius of\nindividual groups and clusters occurs, but is not well described by\nsingle point mass lensing. We will instead here describe the lensing\nas due to a sheet of mass in the lens plane of varying surface\ndensity. \n\nLet us consider a point in the source plane that (undeflected) would\nbe at angle $\\vec{\\beta}$. Let $\\vec{x}$ represent the physical\nposition in the lens plane that the undeflected ray would have passed\nthrough.  The deflection angle is the sum of the contributions of all\nthe mass in the lens plans:\n\\begin{equation}\n\\vec{\\theta_D}\\left(\\vec{x}\\right) = \\frac{4G}{c^2\nD_L}  \\int \\dd^2 \\vec{x}' \\Sigma\\left(\\vec{x}\\right) \\frac{\\vec{x}\n- \\vec{x}'}{\\left|\\vec{x} - \\vec{x}'\\right|^2}\n\\end{equation}\nWe can relate the source plane position $\\vec{\\beta}$ to the observed\nangle $\\theta$ with the {\\it lens equation}:\n\\begin{equation}\n\\vec{\\beta} = \\vec{\\theta}\n- \\frac{D_{LS}}{D_S} \\vec{\\theta_D}\\left(D_L \\vec{\\theta}\\right)\n  = \\vec{\\theta} - \\vec{\\alpha}\n\\end{equation}\nWe can use the above relations to show:\n\\begin{equation}\n\\vec{\\alpha}\n= \\frac{1}{\\pi} \\int \\dd^2\\vec{\\theta}' \\kappa\\left(\\vec{\\theta}'\\right)\n\\frac{\\vec{\\theta} - \\vec{\\theta}'}\n{\\left|\\vec{\\theta} - \\vec{\\theta}'\\right|^2}.\n\\end{equation}\nwhere we define:\n\\begin{equation}\n\\kappa = \\frac{\\Sigma}{\\Sigma_{\\rm cr}},\n\\end{equation}\nand:\n\\begin{equation}\n\\Sigma_{\\rm cr} = \\frac{c^2 D_S}{4\\pi G D_{LS} D_L}\n\\end{equation}\nThe condition $\\kappa>1$ leads to multiply imaged sources.\n\nThe form of $\\vec{\\alpha}$ suggests that it can be written as the\ngradient of a potential,\n\\begin{equation}\n\\vec{\\beta} = \\vec{\\theta} - \\vec{\\nabla}\\psi,\n\\end{equation}\nwhere\n\\begin{equation}\n\\psi\n= \\frac{1}{\\pi} \\int \\dd^2\\vec{\\theta}' \\kappa\\left(\\vec{\\theta}'\\right)\n\\ln \\left|\\vec{\\theta} - \\vec{\\theta}'\\right|.\n\\end{equation}\nWe can also show:\n\\begin{equation}\n\\label{eq:poissonlike}\n\\nabla^2\\psi = 2 \\kappa\n\\end{equation}\nWe can define the Fermat time delay potential as\n\\begin{equation}\n\\tau\\left(\\vec{\\theta}; \\vec{\\beta}\\right) =\n\\frac{1}{2} \\left(\\vec{\\theta} - \\vec{\\beta}\\right)^2\n- \\psi\\left(\\vec{\\theta}\\right),\n\\end{equation}\nand the lens equation can be rewritten as.\n\\begin{equation}\n\\vec{\\nabla}\\tau = 0.\n\\end{equation}\nThis result is an expression of the general relativistic version of\nFermat's principle.\n\n\\subsection{Weak lensing}\n\nThe lens equation can be locally linearized  around $\\vec{\\beta_0}$:\n\\begin{equation}\n\\vec{\\beta} = \\vec{\\beta}_0\n+ \\frac{\\partial \\vec{\\beta}}{\\partial \\vec{\\theta}} \\cdot \\left(\\vec{\\theta}\n- \\vec{\\theta_D} \\right), \n\\end{equation}\nThe vector $\\vec{\\theta}$ and the Jacobian can be written in index form:\n\\begin{eqnarray}\n\\vec{\\theta} &=& \\theta_i {\\hat e}_i = \\theta_1 {\\hat e}_1\n+ \\theta_2 {\\hat e}_2 \\cr\n{\\bf A}\\left(\\vec{\\theta}\\right) &=& \n\\frac{\\partial \\vec{\\beta}}{\\partial \\vec{\\theta}} = \\left(\\delta_{ij}\n- \\frac{\\partial^2 \\psi}{\\partial\\theta_i \\partial\\theta_j}\\right)\n{\\hat e}_i {\\hat e}_j.\n\\end{eqnarray}\n\nThe Jacobian is symmetric, so has only three independent parameters,\nand we can define three parameters to characterize it, $\\kappa$,\n$\\gamma_1$, and $\\gamma_2$:\n\\begin{equation}\n{\\bf A} = \\left(\\begin{array}{cc}\n1-\\kappa - \\gamma_1 & -\\gamma_2 \\cr\n- \\gamma_2 & 1-\\kappa + \\gamma_1\n\\end{array}\\right).\n\\end{equation}\nWe do this because, as we are about to show, $\\kappa$ (called the {\\it\nconvergence}) is basically the isotropic component of the distortion,\nand $\\gamma = \\gamma_1 + i\\gamma_2 = |\\gamma| \\exp(2i\\phi)$ is a shear\nterm expressing the nonisotropic component, including the rotation of\nthe image $\\phi$.\n\nIf you have a circularly symmetric source on sky, this linear\ntransformation will convert it into an ellipse. You can determine the\nparameters of the ellipse from the eigenspace of the of the distortion\nmatrix. The two eigenvalues are\n\\begin{equation}\n\\lambda_{\\pm} = (1-\\kappa) \\pm |\\gamma|\n\\end{equation}\nThe eigenvector associated with $\\lambda_+$ is rotated from ${\\hat\ne}_1$ towards ${\\hat e}_2$ by the angle $\\phi$, which is defined by:\n\\begin{equation}\n\\cos 2\\phi = \\frac{\\gamma_1}{|\\gamma|}\n\\end{equation}\nBased on the eigenvalues, the magnification is:\n\\begin{equation}\nM = \\left(\\lambda_+ \\lambda_-\\right)^{-1} = \\left[(1-\\kappa)^2 -\n|\\gamma|^2\\right]^{-1} \n\\end{equation}\n\nIn order for $\\kappa$ to express an isotropic distortion, then we must\ndefine:\n\\begin{eqnarray}\n\\kappa &=& \\frac{1}{2}\\left(\n\\frac{\\partial^2\\psi}{\\partial\\theta_1^2} +\n\\frac{\\partial^2\\psi}{\\partial\\theta_2^2}\\right) \\cr\n\\gamma_1 &=& \\frac{1}{2} \\left(\n\\frac{\\partial^2\\psi}{\\partial\\theta_1^2} -\n\\frac{\\partial^2\\psi}{\\partial\\theta_2^2}\\right),\n\\end{eqnarray}\nand we can further see:\n\\begin{eqnarray}\n\\gamma_2 &=& \\frac{\\partial^2\\psi}{\\partial\\theta_1 \\partial\\theta_2}.\n\\end{eqnarray}\nTherefore, we can relate the lensing potential curvature to the shear\nand convergence of distortions.\n\nWe also see why we defined the convergence with $\\kappa$, because it\nis related to $\\psi$ in the same way as the $\\kappa$ in the previous\nsubsection (Equation \\ref{eq:poissonlike}). \n\nIn reality, the lensing is integrated through a series of mass sheets\nthat comprise the three-dimensional density field. In addition, the\nconvergence due to the mean density is already accounted for in the\ncosmological comoving transerve distance, luminosity distance, and\nangular diameter distances. The cosmological comoving transverse\ndistance is that which is relevant to lensing. A rigorous derivation\nis beyond our scope here, but the consequence is that the convergence\nin some direction for sources at $D=D_S$ can be written as:\n\\begin{equation}\n\\kappa(\\vec{\\theta}, D_S)\n= \\frac{3 \\Omega_m}{2} \\int_0^{D_S} \\frac{\\dd{D_L}}{a(D_L)}\n\\frac{D_{LS} D_L}{D_S} \\delta(\\vec{\\theta}, D_L)\n\\end{equation}\nwhere is it understood that $D_L$, $D_{LS}$, and $z_L$ are the\nappropriate quantities for a giving lens distance $D_L$. Two important\naspects of this formula are the dependence on $\\Omega_m$ and the\nweighting factor $D_{LS} D_L$, which tells us which distances do the\nmost lensing. For a flat universe, $D_{LS}D_L = (D_S - D_L)D_L$, which\nhas a maximum at $D_L = D_S/2$, so most of the lensing effect is at\nfrom about half the distance of the source. The convergence is also\ndependent on the distance of both the lenses and sources, which\ntherefore need to be known to interpret lensing data accurately.\n\nWeak lensing can be observed through its effects on the size and\nbrightness of sources (the magnification) or due to the induced change\nin ellipticity. Magnification causes a {\\it magnification bias} in\nflux-limited samples with steep flux counts, because the magnification\nwill bring a large number of sources from below the (unlensed) flux\nlimit.  Magnification can also be detected by correlating the number\nof background sources against foreground lens galaxies.\n\nThe changes in ellipticity can only be observed statistically, because\ngalaxies at best have random ellipticities (in fact, it is worse as\ntheir ellipticities tend to be aligned, an effect known as {\\it\nintrinsic alignment}). If you observe an individual galaxy, its\ntypical ellipticity is $\\sim 0.3$ whereas the lensing induced\nellipticity is $<10^{-3}$. One can average over many galaxies along\nsome line of site to detect a net ellipticity that can be associated\nwith lensing, which is the ratio of eigenvalues:\n\\begin{equation}\n\\frac{\\lambda_+}{\\lambda_-} = \\frac{1-\\kappa +  |\\gamma|}{1-\\kappa -\n|\\gamma|}\n\\end{equation}\nSince one cannot nearly as easily determine the magnification and\ntherefore $\\kappa$, the ratio in effect one is measuring the {\\it\nreduced shear}:\n\\begin{equation}\ng = \\frac{\\gamma}{1-\\kappa},\n\\end{equation}\nfor which\n\\begin{equation}\n\\frac{\\lambda_+}{\\lambda_-} = \\frac{1 +  |g|}{1- |g|}.\n\\end{equation}\n\nThere are two general ways the shear is used. The first is the {\\it\ncosmic shear}, which looks at shear-shear correlations. This method\nyields a fairly direct constraint on the statistics of the total mass\ndensity fluctuations. The second is {\\it galaxy-galaxy lensing}\ncorrelations, which cross-correlates known foreground sources with\nbackground shear patterns. In general galaxy-galaxy lensing is usually\neasier, because the cross-correlation increases the signal-to-noise\nand because it tends to average over systematics. \n\nThe shear-shear correlation is a bit subtle, because there is a\ncomponent of the shear transverse to the separation vector, and\ncross-wise from it. The treatment of this is beyond our scope\nhere. The key points are that the shear is interrelated with the\nsurface mass density. In particular:\n\\begin{eqnarray}\n\\gamma &=& \\frac{1}{2}\\left(\\partial\\psi_{,11}\n- \\partial\\psi_{,22}\\right) + i \\partial\\psi_{,12} \\cr\n&=& \\frac{1}{\\pi} \\int \\dd^2\\vec{\\theta}' \\kappa\\left(\\vec{\\theta}'\\right)\n\\left[\\frac{1}{2}\\left(\\partial_1\\partial_1 - \\partial_2 \\partial_2\\right)\n+ i \\partial_1 \\partial_2\\right]\n\\ln \\left|\\vec{\\theta} - \\vec{\\theta}'\\right] \\cr\n&=& \\frac{1}{\\pi} \\int \\dd^2\\vec{\\theta}' \\kappa\\left(\\vec{\\theta}'\\right)\n\\left( \\frac{\\theta_2^2 - \\theta_1^2 -\n2i \\theta_1\\theta_2}{\\theta^4} \\right)\n\\end{eqnarray}\nSo the shear is related through an integral with the surface mass\ndensity. This integral may be inverted from shear data to yield the\nmass density; it is a bit tricky because the kernel is $1/\\theta^2$ so\nedge and finite volume effects are important (though remember it is in\ntwo-dimensions so this scaling is not as bad as for three dimensions).\nIt can be further shown that the correlation function and power\nspectrum of the shear field can be directly related to the convergence\nfield, meaning that the statistics of the shear field can be used\ndirectly (without explicitly building a map of $\\kappa$).\n\nGalaxy-galaxy lensing typically is used by measuring the mean\ntangential shear $\\gamma_t$ around identified foreground sources\n(usually galaxies or clusters of galaxies). \n\n\\subsection{Microlensing}\n\nA phenomenon called {\\it microlensing} occurs when the lensing mass\nand background source have a relative angular motion. The background\nsource increases as it moves through the Einstein radius of the\nlens. This increase has a distinctive, achromatic signature, that can\nbe seen for individual stars in our Galaxy through monitoring.\n\nA related phenomenon also known as microlensing occurs when viewing a\nbackground source through a galactic system. The stars create a\nlensing potential surface with distinct cusps that cause fluctuations\nin the flux of the background source.\n\nThese phenomena can only occur if the background source is physically\nsmaller than the Einstein radius. Otherwise even if the center of the\nsource is aligned with the lens, most of the light is well outside the\nEinstein radius in the lens plane and is not deflected. This fact\nmakes it possible to constrain the relative sizes of the background\nsource in different wavelengths (e.g. radio vs. optical) through\nobservations of its lensing.\n\n\\section{Important numbers}\n\n\\section{Key References}\n\n\\begin{itemize}\n  \\item\n    {\\it Strong Lensing by Galaxies, \\href{https://ui.adsabs.harvard.edu/abs/2010ARA%26A..48...87T/abstract}\n    {\\citet{treu10a}}}\n  \\item\n    {\\it Weak lensing for precision cosmology, \\href{https://ui.adsabs.harvard.edu/abs/2018ARA%26A..56..393M/abstract}\n    {\\citet{mandelbaum18a}}}\n\\end{itemize}\n\n\\section{Order-of-magnitude Exercises}\n\n\\begin{enumerate} \n\\item Calculate a typical Einstein angles for:\n\\begin{enumerate}\n\\item A stellar mass lens between the Sun and the Galactic Center.\n\\item A galaxy lens at $z\\sim 0.1$, lensing objects at $z\\sim 1$.\n\\item A galaxy cluster lens at $z\\sim 0.1$, lensing objects at $z\\sim\n    1$.\n\\end{enumerate}\n\\item For a Milky Way-mass galaxy lens at cosmological distances (100s\n    of Mpc) and a background source about twice that distance,\n    estimate the typical time delay for a multiply-lensed system\n    Assume a point mass lens and that the source is at\n    $\\beta\\sim \\theta_E/2$, and ignore the General Relativistic\n    Shapiro delay contribution. \n\\item Assuming a constant density of stars in the Galactic disk,\n    estimate the probability of lensing of any given star near the\n    Galactic center.\n\\item Typical shear values\n\\end{enumerate}   \n\n\\section{Analytic Exercises}\n\n\\begin{enumerate}\n\\item GR calculation of lensing offset\n\\item For a symmetric, point mass lens, derive the angular radius of the image\n    that is formed, called the Einstein angle.\n\\begin{answer}\nUsing the notation in Figure \\ref{fig:symmetric}, geometrically it\nmust be that:\n\\begin{equation}\n\\theta_D = \\theta_S + \\theta_E\n\\end{equation}\nUnder the small angle approximation, therefore:\n\\begin{equation}\n\\theta_D = r_E \\left(\\frac{1}{D_L} + \\frac{1}{D_{LS}}\\right) =\nr_E \\frac{D_S}{D_{LS} D_L} \n\\end{equation}\nTherefore:\n\\begin{equation}\nr_E = \\frac{D_{LS} D_L}{D_S} \\theta_D.\n\\end{equation}\nAgain using the small angle approximation, the impact parameter is\n$r_E$, so we can write:\n\\begin{equation}\nr_E = \\frac{D_{LS} D_L}{D_S} \\frac{4GM}{r_Ec^2}\n\\end{equation}\nand solve for:\n\\begin{equation}\nr_E = \\sqrt{\\frac{4GM}{c^2} \\frac{D_{LS} D_L}{D_S}}\n\\end{equation}\nThe Einstein angle can then be calculated (again using small angles):\n\\begin{equation}\n\\theta_E = \\sqrt{\\frac{4GM}{c^2} \\frac{D_{LS}}{D_S D_L}}\n\\end{equation}\n\\end{answer}\n\n\\item Calculate the location of the two magnified images that form when the\nsource is offset from the point lens.\n\\begin{answer}\nUsing the notation in Figure \\ref{fig:offset}, we have:\n\\begin{equation}\nr_I = r_S + r_D,\n\\end{equation}\nand therefore:\n\\begin{eqnarray}\n\\theta_\\pm D_S &=& \\beta D_S + D_{LS} \\theta_D \\cr\n\\theta_\\pm &=& \\beta + \\frac{D_{LS}}{D_S} \\frac{4GM}{r_\\pm c^2} \\cr\n&=& \\beta + \\frac{D_{LS}}{D_S D_L} \\frac{4GM}{\\theta_\\pm c^2} \\cr\n&=& \\beta + \\frac{\\theta_E^2}{\\theta_\\pm}\n\\end{eqnarray}\nThen we can rearrange this to:\n\\begin{equation}\n\\theta_\\pm^2 - \\beta \\theta_\\pm - \\theta_E^2 = 0 \n\\end{equation}\nwith the solutions:\n\\begin{equation}\n\\theta_\\pm = \\frac{\\beta \\pm \\sqrt{\\beta^2 + 4\\theta_E^2}}{2}\n\\end{equation}\nFor the strong-lensing limit $\\beta \\ll \\theta_E$, this leads to:\n\\begin{equation}\n\\theta_\\pm = \\pm \\theta_E + \\frac{\\beta}{2}\n\\end{equation}\nFor the weak-lensing limit $\\beta \\gg \\theta_E$:\n\\begin{equation}\n\\theta_\\pm\n= \\beta \\left(\\frac{1}{2} \\pm \\frac{1}{2} \\sqrt{1+\n\\frac{4\\theta_E^2}{\\beta^2}}\\right) \n\\end{equation}\nand we find:\n\\begin{eqnarray}\n\\theta_+ &\\approx& \\beta + \\frac{\\theta_E^2}{\\beta} \\cr\n\\theta_- &\\approx& - \\frac{\\theta_E^2}{\\beta}\n\\end{eqnarray}\n\\end{answer}\n\\item In the weak lensing limit for a point mass lens,  what is the\nmagnification?\n\\begin{answer}\nConsider a source at $\\beta$, with a size in the radial and tangential\ndirections of $\\dd\\beta$ and $\\dd\\phi$ (for the polar coordinate\n$\\phi$). Its unlensed area is:\n\\begin{equation}\nA_S = \\beta \\dd\\beta \\dd\\phi\n\\end{equation}\nThe area of each lensed image is:\n\\begin{equation}\nA_\\pm = \\left| \\theta_\\pm\\right| \\dd\\theta_\\pm \\dd\\phi\n= \\left| \\theta_\\pm\\right| \\left|\\frac{\\dd\\theta_\\pm}{\\dd\\beta}\\right| \\dd\\beta\\dd\\phi\n= \\left|\\frac{\\theta_\\pm}{\\beta}\\right| \\left|\\frac{\\dd\\theta_\\pm}{\\dd\\beta}\\right| A_S\n\\end{equation}\nThen:\n\\begin{equation}\nM = \\frac{A_+ + A_-}{A_S} = \\frac{1+\n2\\theta_E^2/\\beta^2}{\\sqrt{1+4\\theta_E^2/\\beta^2} }\n\\end{equation}\n\\end{answer}\n\\item Critical surface density case\n\\item Derive shear and magnification properties\n\\end{enumerate}\n\n\\section{Numerics and Data Exercises}\n\n\\begin{enumerate}\n\\item Modeling of lens system\n\\item Specific strong lenses\n\\item Measurements of shear\n\\end{enumerate}\n\n\\bibliographystyle{apj}\n\\bibliography{exex}  \n\n\\begin{figure}\n\\includegraphics[width=0.9\\textwidth]{figures/symmetric_lens.jpg}\n\\caption{\\label{fig:symmetric} Geometry for symmetric point mass lens.}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=0.9\\textwidth]{figures/offset_lens.jpg}\n\\caption{\\label{fig:offset} Geometry for offset point mass lens.}\n\\end{figure}\n", "meta": {"hexsha": "d1e5134052eb0a16a5f7b0d868608262e4c8e251", "size": 18853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/lensing-text.tex", "max_stars_repo_name": "blanton144/exex", "max_stars_repo_head_hexsha": "b4d9d52b4fe8af761783f49b2c197a109d94cfdf", "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": "tex/lensing-text.tex", "max_issues_repo_name": "blanton144/exex", "max_issues_repo_head_hexsha": "b4d9d52b4fe8af761783f49b2c197a109d94cfdf", "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/lensing-text.tex", "max_forks_repo_name": "blanton144/exex", "max_forks_repo_head_hexsha": "b4d9d52b4fe8af761783f49b2c197a109d94cfdf", "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.6071428571, "max_line_length": 118, "alphanum_fraction": 0.7432238901, "num_tokens": 5542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.617458403964743}}
{"text": "\n\\documentclass{article}\n\n% Recommended, but optional, packages for figures and better typesetting:\n\\usepackage{microtype}\n\\usepackage{graphicx}\n\\usepackage{subfigure}\n\\usepackage{booktabs} % for professional tables\n\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{coro}{Corollary}\n\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}\n\n\n\\newcommand{\\diffusion}{N}\n\\newcommand{\\rotparm}{R}\n\n\\newcommand{\\latV}{z}\n\\newcommand{\\obsV}{x}\n\n\\newcommand{\\LEG}{\\mathrm{LEG}}\n\\newcommand{\\reals}{\\mathbb{R}}\n\\newcommand{\\LEGGP}{\\mathrm{LEG}}\n\\newcommand{\\PEG}{\\mathrm{PEG}}\n\\newcommand{\\PEGGP}{\\mathrm{PEG}}\n\\newcommand{\\KPEG}{\\mathrm{KPEG}}\n\\newcommand{\\KLEG}{\\mathrm{KLEG}}\n\\newcommand{\\SM}{\\mathrm{SM}}\n\\newcommand{\\Cov}{\\mathrm{Cov}}\n\\newcommand{\\TODO}{TODO}\n\n% hyperref makes hyperlinks in the resulting PDF.\n% If your build breaks (sometimes temporarily if a hyperlink spans a page)\n% please comment out the following usepackage line and replace\n% \\usepackage{icml2019} with \\usepackage[nohyperref]{icml2019} above.\n\\usepackage{hyperref}\n\n% Attempt to make hyperref and algorithmic work together better:\n\\newcommand{\\theHalgorithm}{\\arabic{algorithm}}\n\n% Use the following line for the initial blind version submitted for review:\n% \\usepackage{icml2019}\n\n% If accepted, instead use the following line for the camera-ready submission:\n\\usepackage[accepted]{icml2019}\n\n% The \\icmltitle you define below is probably too long as a header.\n% Therefore, a short form for the running title is supplied here:\n\\icmltitlerunning{Linear-time inference for Gaussian processes on one Dimension}\n\n%comment this line out later, when we're ready to submit - useful to have page numbers visible in draft mode\n\\pagestyle{headings}\n\n\\begin{document}\n\n\\twocolumn[\n\\icmltitle{General linear-time inference for Gaussian Processes on one dimension}\n\n% It is OKAY to include author information, even for blind\n% submissions: the style file will automatically remove it for you\n% unless you've provided the [accepted] option to the icml2019\n% package.\n\n% List of affiliations: The first argument should be a (short)\n% identifier you will use later to specify author affiliations\n% Academic affiliations should list Department, University, City, Region, Country\n% Industry affiliations should list Company, City, Region, Country\n\n% You can specify symbols, otherwise they are numbered in order.\n% Ideally, you should not use this facility. Affiliations will be numbered\n% in order of appearance and this is the preferred way.\n\n\\begin{icmlauthorlist}\n\\icmlauthor{Jackson Loper}{to}\n\\icmlauthor{David Blei}{to}\n\\icmlauthor{John P. Cunningham}{to}\n\\icmlauthor{Liam Paninski}{to}\n\\end{icmlauthorlist}\n\n\\icmlaffiliation{to}{Columbia University, New York, New York, USA}\n\n\\icmlcorrespondingauthor{Jackson Loper}{jl5116@columbia.edu}\n\n% You may provide any keywords that you\n% find helpful for describing your paper; these are used to populate\n% the \"keywords\" metadata in the PDF but will not be shown in the document\n\\icmlkeywords{Gaussian Processes}\n\n\\vskip 0.3in\n]\n\n% this must go after the closing bracket ] following \\twocolumn[ ...\n\n% This command actually creates the footnote in the first column\n% listing the affiliations and the copyright notice.\n% The command takes one argument, which is text to display at the start of the footnote.\n% The \\icmlEqualContribution command is standard text for equal contribution.\n% Remove it (just {}) if you do not need this facility.\n\n\\printAffiliationsAndNotice{}  % leave blank if no need to mention equal contribution\n% \\printAffiliationsAndNotice{\\icmlEqualContribution} % otherwise use the standard text.\n\n\\begin{abstract}\nGaussian Processes (GPs) provide a powerful probabilistic framework for interpolation, forecasting, and smoothing, but have been hampered by computational scaling issues.  Here we prove that for data sampled on one dimension (e.g., a time series sampled at arbitrarily-spaced intervals), approximate GP inference at any desired level of accuracy requires computational effort that scales \\emph{linearly} with the number of observations; this new theorem enables inference on much larger datasets than was previously feasible. To achieve this improved scaling we propose a new family of stationary covariance kernels: the Latent Exponentially Generated (LEG) family, which admits a convenient stable state-space representation that allows linear-time inference.  We prove that any continuous integrable stationary kernel can be approximated arbitrarily well by some member of the LEG family.  The proof draws connections to Spectral Mixture Kernels, providing new insight about the flexibility of this popular family of kernels.  We propose parallelized algorithms for performing inference and learning in the LEG model, test the algorithm on real and synthetic data, and demonstrate scaling to datasets with billions of samples.\n\\end{abstract}\n\n\\section{Introduction}\n\nGaussian Process (GP) methods are a powerful and expressive class of nonparametric techniques for interpolation, forecasting, and smoothing.  \nHowever, this expressiveness comes at a cost: if implemented naively, inference in a GP given $m$ observed data points will require $O(m^3)$ operations. \nA large body of work has devised various means to circumvent this cubic run-time; briefly, this literature can be broken down into several threads.  A first approach is to attempt to perform exact inference without imposing any restrictions on the covariance kernel, using careful numerical methods typically including preconditioned conjugate gradients \\cite{Cutajar2016}. \\citet{Wang2019}\nrepresents the state of the art: inference and learning can be performed on $\\sim 10^6$ datapoints on an 8-GPU machine and a few days of processing time.\nA second approach searches for good approximations to the posterior that do not rely on special properties of the covariance kernel.  Some well-known examples of this approach include   \\cite{quinonero2005unifying,snelson2007local,hensman2013gaussian,low2015parallel,de2017gpflow}.  \nIn a third approach, several techniques exploit special kernel structure.  Examples include matrices with Kronecker product structure \\cite{gilboa2013scaling}, Toeplitz structure \\cite{zhang2005time, cunningham2008}, matrices that can be well-approximated with hierarchical factorizations \\cite{Ambikasaran2015},\nor matrices which are sufficiently smooth to allow for interpolation-based approximations \\cite{kiss-gp}.\n\nWhen the GP has one-dimensional input -- e.g., \na scalar or vector time-series sampled at arbitrary time points -- the most popular method for scaling learning and inference is to approximate the GP with some form of Gaussian hidden Markov model (that is, a state-space model) \\cite{reinsel2003elements,mergner2009applications,cheung2010estimation,brockwell2013time}.  This model class has considerable virtue: it is a particular case of a GP, it includes popular models like the auto-regressive moving average process (ARMA, when on an evenly spaced grid), and perhaps most importantly it admits linear-time $O(m)$ inference via message passing.\n\nIs approximating a GP with a state-space model a generally viable strategy?\nIn several special cases it has been shown that state-space models provide excellent approximations of specific covariance kernels \n\\cite{karvonen2016approximate,benavoli2016state}.  Discrete-time processes on a finite interval can also be approximated this way \\cite{lindgren2011explicit}.  Practically, \\cite{gilboa2013scaling} shows it is straightforward to learn many GP models using a state-space model. \n\nIn this work we establish the full generality of this strategy: we offer a new theorem proving that \\emph{any} GP on one dimension with a Lebesgue-integrable continuous kernel can be arbitrarily well approximated by a specifically-chosen state-space model.  By doing so, we effectively reduce the run-time burden of  GPs on one dimension from cubic to linear.\n\nWe first develop a new class of Gaussian hidden Markov models on one dimension: the Latent Exponentially Generated (LEG) process.  This model family is a generalization of the Celerite family of Gaussian Processes \\cite{foreman2017celerite}.  Unlike some popular state-space models such as the ARMA, LEG \nprocesses do not require that the observations are equally spaced.  These models define a distribution on vector-valued functions on the entire real line, $X: \\mathbb{R} \\rightarrow \\mathbb{R}^n$.  By construction, LEG processes are stable and stationary, with a kernel that can be evaluated easily, and\ninference requires linear time.  In addition, we here show that inference for these models can be parallelized efficiently via a technique known as Cyclic Reduction \\cite{sweet1974generalized}, leading to significant runtime improvements.  Furthermore these models are general: our main mathematical result is to prove that for any stationary Gaussian Process $X$ on one dimension with integrable continuous covariance, for any $\\varepsilon$, the covariance of $X$ can be matched within $\\varepsilon$ by a \nLEG covariance kernel. \n\nLEG kernels generalize the Celerite kernel \\cite{foreman2017celerite} by allowing more model flexibility and permitting vector-valued observations.  Every Celerite kernel can be understood as a special case of a LEG kernel.   \n\nThe remainder of this paper defines the LEG family, derives its essential properties and generality, and finally empirically backs up these claims across real and synthetic data.  In particular, we show that the LEG family enables inference on datasets with billions of samples with runtimes that scale in minutes, not days.  \n\n\n%                  _   _     \n%                 | | | |    \n%  _ __ ___   __ _| |_| |__  \n% | '_ ` _ \\ / _` | __| '_ \\ \n% | | | | | | (_| | |_| | | |\n% |_| |_| |_|\\__,_|\\__|_| |_|\n                           \n\\section{Preamble: Gaussian process generalities}\n\nA Gaussian Process on one dimension is a random function $X: \\reals \\rightarrow \\reals^n$ such that for any finite collections of times $t_1,t_2\\cdots t_m$ the joint distribution of $(X(t_1),\\cdots X(t_m)) \\in \\mathbb{R}^{m\\times n}$ is jointly Gaussian.  The covariance kernel of $X$ is a matrix-valued function defined by \n\\[\n\\Sigma(s,t) = \\Cov(X(s),X(t)) \\in \\reals^{n\\times n}.\n\\]\nA process is said to be stationary if $\\Sigma(s,t)=C(s-t)$ for some matrix-valued function $C$ and $\\mathbb{E}[X(t)]$ is the same for all values of $t$.  In this case we write $\\tau$ for the time-lag $t-s$, i.e $C=C(\\tau)$.  \n\nWe will focus on two critical computational tasks here: inference and learning.  \n``Inference\" refers to using a GP model to compute the conditional densities of  $X$ given a finite collection of observations $D=(X(t_1),\\cdots X(t_m))$.  ``Learning\" refers to estimating the covariance of $X$ from the data $D$.  Both of these tasks can be computationally intensive: naive evaluation of the likelihood of $D$ requires computing the determinant of an $m\\times m$ matrix and solving an $m$-dimensional linear system.\nIn general these tasks require $O(m^3)$ operations.  Here we circumvent this scaling law by restricting ourselves to a parametric family of kernels which admit linear-time (i.e., $O(m)$) algorithms.  We further show that this restriction is without loss of generality, since this family of kernels is capable of approximating any integrable continuous stationary kernel on the real line.\n\n\n\\section{The LEG kernel}\n\nWe introduce a parametric family of random processes on one dimension: the Latent Exponentially Generated (LEG) process. This process will achieve both goals of this work: linear-time inference and arbitrary approximation quality to any GP. For clarity of exposition, what follows assumes stationarity and zero mean; generalizations are discussed in Section \\ref{sec:extensions}.  We first define the latent GP, after which we define the observation model; taken together these objects will form the LEG family.\n\nIn designing a family of latent GP models, \nour first goal is to enable fast computation:\nthe models should be stationary, with an easily-computed kernel.  In addition, it is convenient to focus on Markovian models, since the Markov property will enable efficient inference.\n\nA general and classic family of Markovian models are given by linear Langevin equations \\cite{coffey2004langevin}, i.e. processes defined by \n\\[\nz(t) = z(0) + \\int_0^t (-G z(s) ds + \\sigma dw(s)),\n\\]\nwhere $w$ is an $\\ell$-dimensional Brownian motion, and $G,\\sigma$ are square matrices.  To ensure this process doesn't grow without bound, we need the real part of the eigenvalues of $G$ to be positive.  Guaranteeing this nontrivial constraint is challenging \\cite{buesing2012learning,Gillis2019}.  To remedy this problem we developed a closely-related family of models which are always stable and stationary:\n\n\\begin{definition} Let $\\latV(0) \\sim \\mathcal{N}(0,I)$, let $w$ denote a Brownian motion, let $\\diffusion,\\rotparm$ be any $\\ell\\times \\ell$ matrices, and let $G=\\diffusion \\diffusion^\\top + \\rotparm-\\rotparm^\\top$.  Let $\\latV$ satisfy\n\\[\n\\latV(t) = \\latV(0) + \\int_0^t\\left(-\\frac{1}{2}G \\latV(s)ds + N dw(s)\\right).\n\\]\nThen we will say $z$ is a Purely Exponentially Generated process, $z \\sim \\PEGGP(\\diffusion,\\rotparm)$.\n\\end{definition}\n\nThis family has another advantage: the covariance kernel is easy to compute.  The covariance kernel for linear Langevin models usually involves an integral \\cite{vatiwutipong2019alternative}, but for PEG models we can compute this \nintegral in closed form:\n\\begin{lemma} $z \\sim \\PEGGP(\\diffusion,\\rotparm)$ is stationary, with covariance kernel given by\n\\[\nC_{\\PEG}(\\tau;\\diffusion,\\rotparm)  \\triangleq\n\\exp\\left(-\\frac{\\tau}{2}\\left(\\diffusion \\diffusion^\\top + \\rotparm-\\rotparm^\\top\\right)\\right).\n\\]\n\\end{lemma}\n{\\bf Proof:} See supplementary material.  \n\n\\begin{figure*}[ht]\n\\vskip 0.2in\n\\begin{center}\n\\centerline{\\includegraphics[width=2\\columnwidth]{pics/exampleprocs}}\n\\caption{\\textbf{PEG process samples}.  The plots above show representative samples from the model $\\PEG(\\diffusion,\\rotparm)$ as we vary $\\diffusion$ and $\\rotparm$.  Here we consider rank-2 PEG models (only one element of the 2d vector is plotted), so $\\diffusion,\\rotparm$ are both $2\\times 2$ matrices.   We vary $\\diffusion$ by taking it to be various multiples of the identity.  We vary $\\rotparm$ by taking various multiples of $J$, the antisymmetric $2\\times 2$ matrix with zeros on the diagonal and $\\pm 1$ on the off-diagonal.  In this simple rank-2 case, increasing $N$ leads to a less predictable process and  increasing $\\rotparm$ leads to faster oscillations.\n\\label{fig:exampleprocs}}\n\\end{center}\n\\vskip -0.2in\n\\end{figure*}\n \n\nThe matrices $\\diffusion,\\rotparm$ can be interpreted intuitively.  The positive definite diffusion $\\diffusion \\diffusion^\\top$ controls the predictability of the process: when an eigenvalue of $\\diffusion \\diffusion^\\top$ becomes larger, the process $Z$ becomes less predictable along the direction of the corresponding eigenvector.  The antisymmetric  $\\rotparm-\\rotparm^\\top$ term affects the process by applying an infinitesimal deterministic rotation at each point in time.  The eigenvalues of $\\rotparm - \\rotparm^\\top$ are purely imaginary, and when they are large they lead to rapid oscillations in the process, while the eigenvectors control how these oscillations are mixed across the dimensions of $Z$.  As an illustration, Figure \\ref{fig:exampleprocs} shows the first dimension of samples from an $\\ell=2$ dimensional PEG process with various values of $\\diffusion,\\rotparm$.\n\nWe now turn to the observed process: \n\n\\begin{definition}\nLet $\\latV \\sim \\PEGGP(\\diffusion,\\rotparm)$.  Fix any $n \\times \\ell$ matrix $B$ and any $\\ell \\times \\ell$ matrix $\\Lambda$.   For each $t$ independently, define the conditional observation model: \n\\[\n\\obsV(t)|\\latV(t) \\sim \\mathcal{N}(B \\latV(t),\\Lambda \\Lambda ^\\top).\n\\]\nWe define a \\textbf{Latent Exponentially Generated (LEG)} process to be the Gaussian Process $x: \\reals \\rightarrow \\reals^n$ generated by a PEG prior and the above observation model.  We write $x \\sim \\LEGGP(\\diffusion,\\rotparm,B,\\Lambda)$.  X has a LEG kernel:\n\\begin{gather*}\nC_\\LEG(\\tau;\\diffusion,\\rotparm,B,\\Lambda) \\\\ \\triangleq\nB \\left(C_\\PEG(\\tau;\\diffusion,\\rotparm)\\right) B^\\top + \\delta_{\\tau=0} \\Lambda \\Lambda^\\top.\n\\end{gather*}\nHere $\\delta$ is the indicator function, and again $\\tau>0$.  We will refer to the latent dimension $\\ell$ as the \\textbf{rank} of the LEG kernel.\n\\end{definition}\n\n\\subsection{Computation with LEG processes}\n\n\\label{subsec:leggpcomputation}\n\nThe LEG model is a Gaussian hidden Markov model.  As usual in such models, it follows that problems of evaluation, interpolation, smoothing, and sampling reduce to operations with block-tridiagonal matrices \\cite{de1988likelihood}.  This block-tridiagonal structure is what enables linear-time inference. \n\nWhile the obvious choice for processing these block-tridiagonal matrices might be a Kalman filter, it is not ideally suited for modern hardware: the na\\\"ive Kalman filter requires a single sequential sweep through the data.  If the latent process has a quick mixing time this requirement can be relaxed \\cite{gonzalez2009residual}, but we seek an algorithm that parallelizes efficiently regardless of the parameters of the model.  \n\nWe here propose to use Cyclic Reduction (CR) techniques instead.  These offer a convenient parallelizable approach to computation with block-tridiagonal matrices \\cite{sweet1974generalized}.  To our knowledge, the CR approach has not previously been applied in the Gaussian Process literature. \nLike the Kalman filter, CR can be understood as a linear-time Cholesky decomposition algorithm for block-tridiagonal matrices \\cite{eubank2002equivalence}.  Linear-time Cholesky decompositions lead directly to linear-time algorithms for solving linear systems and computing the determinant, which, in turn, allows us to compute all quantities required for inference in LEG processes. The difference between the Kalman filter and CR is ``pivoting''; CR computes the Cholesky decomposition of a carefully permuted version of a block-tridagonal matrix.  This pivoting allows the CR algorithm to proceed in $\\log_2 m$ parallelizable stages, each stage concerning a matrix half the size of the matrix from the previous stage\\footnote{Those familiar with the multigrid technique \\cite{terzopoulos1986image,hackbusch2013multi} -- which has been used for Gaussian inference in other contexts \\cite{papandreou2010gaussian,mukadam2016gaussian,zanella2017analysis} -- will note similarities between multigrid and CR.}.   Unlike the Kalman Filter, CR can be completed with $k$ processors on the order of $m/k$ time (as long as $k<m$).   Implementing parallel versions of CR in modern software libraries (TensorFlow2 in this case) was straightforward, making it easy to take advantage of modern hardware.  \n\nExact linear-time algorithms for likelihood (and gradient) evaluation, smoothing, forecasting, and interpolation are given in the supplement.  TensorFlow2-based Python code, tutorial  notebooks, and API documentation can be found at \\url{https://github.com/jacksonloper/leg-gps}. \n\n\\subsection{Generality of the LEG family}\n\\label{sec:smk}\nThe LEG family is useful only in so much as it is able to accurately approximate other GP kernels.  Here, we prove that in fact the LEG family is general: \\emph{any} stationary Lebesgue-integrable stationary continuous kernel can be approximated to arbitrary accuracy with a LEG family of a certain rank $\\ell$.  \n\nIntuitively the argument is as follows: first, the PEG family provides a general and well-behaved (stable, stationary, correlated) collection of $\\ell$ state-space components.  Second, the LEG observation model creates \n\\emph{mixture} \nof those underlying PEG components.  Third, we show that the LEG family has nonzero intersection with spectral mixture kernels (a popular class of kernels defined more carefully below), thus drawing a novel and useful connection between spectral mixtures and state space models. Fourth, we extend known facts about the generality of spectral mixtures to the multidimensional case.  As a result, finally, we conclude that the LEG family is general (all without sacrificing its linear runtime).\n\nTo begin, we study the spectral representation of the LEG kernel.  If a kernel is stationary and continuous, Bochner's theorem guarantees it has a spectrum \\cite{bhatia2015positive}: a unique matrix-valued measure $F$ such that\n\\[\nC(\\tau) = \\int e^{-i\\tau \\omega } dF(\\omega).\n\\] \nSpectral Mixture (SM) methods offer a direct way to approximate any stationary kernel through its spectrum.    For the purposes of this article we will define SM kernels as follows:  \n\n\\begin{definition}\n    Let $p$ denote a probability density on $\\mathbb{R}$, let $b_1, b_2 \\cdots b_{\\ell} \\in \\mathbb{C}^{n}$, let $\\mu \\in \\mathbb{R}^{\\ell}$, and let $\\gamma>0$.  The \\textbf{Spectral Mixture} kernel, $C_\\SM(t;p,b,\\mu,\\gamma)$, is given by \n    \\begin{gather*}\n     \\sum_{k=1}^{\\ell}\\int e^{-i\\xi x}   b_k b_k^* \\gamma p(\\gamma(\\xi - \\mu_k)) d \\xi.\n    \\end{gather*}\n    We will say that $C$ is \\textbf{based on $p$}, since its spectrum is a sum of scaled and shifted versions of $p$.\n\\end{definition}\n\nSpectral Mixtures were first introduced in machine learning in \\cite{wilson2013gaussian}, where it was noted that any kernel which is the covariance of a weakly stationary mean square continuous random process $X:\\ \\mathbb{R} \\rightarrow\\mathbb{R}$ (or indeed $X:\\ \\mathbb{R}^n \\rightarrow\\mathbb{R}$) can be well-approximated using SM kernels.    \nHowever, that result does not hold for our case, i.e.\\ kernels for processes of the form $X:\\ \\mathbb{R} \\rightarrow\\mathbb{R}^n$.  In this situation the spectrum of the kernel becomes a complex-matrix-valued measure (instead of an ordinary probability measure).\n\nThese mixture kernels have an interesting connection to LEG kernels: all Cauchy-based spectral mixture kernels are actually also LEG kernels.  These kernels thus fall at the intriguing intersection of Gaussian Hidden Markov models (which are linear run-time) and Spectral Mixture models (which have not previously been considered linear run-time).  Every Cauchy-based SM kernel can be understood as a LEG kernel.  There is also another generalization of Cauchy-based SM kernels, known as the Celerite kernels \\cite{foreman2017celerite}; these are built by linear combinations of kernels called Celerite terms.  Below we summarize the relationship between these three families of kernels:\n\n\\begin{lemma}[SM kernels, Celerite kernels, LEG kernels] \\label{lem:smareleg}\n\\hspace{.01in}\n\n\\begin{enumerate}\n    \\item Every Cauchy-based real-valued SM kernel $C_\\SM:\\ \\mathbb{R} \\rightarrow\\mathbb{R}$ can be understood as a Celerite kernel.  \n    \\item Every positive-definite Celerite term can be understood as a LEG kernel.\n    \\item Every Cauchy-based real-valued SM kernel $C_\\SM:\\ \\mathbb{R} \\rightarrow\\mathbb{R}^{n \\times n}$ can be understood as a LEG kernel.\n\\end{enumerate}\n\\end{lemma}\n\n{\\bf Proof:} See supplementary material.  \n\nThus, to prove that the family of LEG kernels is general, it suffices to show that SM kernels are general.  \n The key idea is to generalize a classic result from kernel density estimation.  We achieve this generalization in the following theorem:  \n\n\\begin{theorem}[Total variation convergence for weighted kernel density estimation] \\label{lem:kdereg}\nLet $K,p$ denote bounded densities on $\\mathbb{R}^d$.  Let $g:\\ \\mathbb{R^d} \\rightarrow [-M,M]$.  Let $\\gamma_\\ell = \\ell^{1/2d}$.  Let $\\mu_1,\\mu_2 \\cdots \\sim p$, independently.  For each $\\ell \\in 1,2,\\cdots$, define  \n\\[\nh_{\\ell}(\\xi) = \\frac{1}{\\ell} \\sum_{k=1}^{\\ell}g(\\mu_k) \\gamma^d_\\ell K(\\gamma_\\ell(\\xi - \\mu_k)).\n\\]\nThen\n\\[\n\\mathbb{P}\\left(\\lim_{\\ell \\rightarrow \\infty} \\int |h_{\\ell}(\\xi) - p(\\xi)g(\\xi)| d\\xi  = 0\\right) = 1.\n\\]\n\\end{theorem}\n\n{\\bf Proof:} See supplementary material.  \n% All proofs are deferred to the supplement.  \n\nWith this theorem in place, we next show that spectral mixture kernels can approximate any integrable continuous kernel for a stationary Gaussian process on one dimension: \n\n\\begin{coro}[Flexibility of Spectral Mixture kernels]\nFix $p$, a bounded probability density on $\\mathbb{R}^n$, $\\varepsilon>0$, and any Lebesgue-integrable continuous positive definite\\footnote{The requirements of continuity and integrability are slightly too strong.   For example, the sinc kernel is not Lebesgue integrable, but it is easy to approximate with a spectral mixture kernel.  In the future we hope to refine these conditions.}  stationary kernel $\\Sigma:\\ \\mathbb{R} \\rightarrow \\mathbb{C}^{n\\times n}$.   There exists a real valued kernel $C=C_\\SM(p,b,\\mu,\\gamma)$ such that $\\Vert C(\\tau)z -\\Sigma(\\tau)z \\Vert < \\varepsilon \\Vert z \\Vert$ for every $\\tau\\in\\mathbb{R},z\\in\\mathbb{C}^n$.  \n\\end{coro}\n\n{\\bf Proof:} See supplementary material.  \n\nThis corollary can be used to establish our main mathematical result, i.e., that LEG models enjoy the same flexibility guarantee.  \n\n\\begin{theorem}[Flexibility of LEG and Celerite kernels] \\label{thm:legflex}\nFor every $\\varepsilon>0$ and every Lebesgue-integrable continuous positive definite stationary kernel $\\Sigma: \\mathbb{R} \\rightarrow \\mathbb{R}^{n\\times n}$ there exists a Celerite kernel  $C$ such that $\\Vert C(\\tau)z -\\Sigma(\\tau)z \\Vert < \\varepsilon \\Vert z \\Vert$ for every $\\tau>0,z\\in\\mathbb{C}^n$.   Moreover, there exists a LEG kernel with the same guarantee.\n\\end{theorem}\n\n{\\bf Proof:} See supplementary material.  \n\nIn conclusion, we have proven that any stationary Gaussian Process on one dimension can be well approximated using LEG processes, and further that the computational effort for LEG processes scales linearly with the number of observations.  Thus, putting these two pieces together, approximate inference for any stationary Gaussian Processes on one dimension, at any desired level of accuracy, requires computational effort that scales linearly with the number of observations.\n\n\n%           _                 _                 \n%   _____  _| |_ ___ _ __  ___(_) ___  _ __  ___ \n%  / _ \\ \\/ / __/ _ \\ '_ \\/ __| |/ _ \\| '_ \\/ __|\n% |  __/>  <| ||  __/ | | \\__ \\ | (_) | | | \\__ \\\n%  \\___/_/\\_\\\\__\\___|_| |_|___/_|\\___/|_| |_|___/\n                                               \n\n\\section{Extensions}\n\n\\label{sec:extensions}\n\nBefore moving on to illustrate these results with experiments on simulated and real data, we pause to note several useful extensions.\n\n\\subsection{Non-stationary processes}  \nWe have focused on stationary processes here for simplicity.  A number of potential extensions to non-stationary processes are possible while retaining linear-time scaling.  As one example, \nstarting with LEG processes as a base, nonstationary models can be developed using the techniques from \\cite{benavoli2016state}.  \n\n\\subsection{Non-Gaussian observations}  \nMany approaches have been developed to adapt GP inference methods to non-Gaussian observations, including Laplace approximations, expectation propagation, variational inference, and a variety of specialized Monte Carlo methods \\cite{hartikainen2011sparse,riihimaki2014laplace,nguyen2014automated,nishihara2014parallel}.  Many of these can be easily adapted to the LEG model, using the fact that the sum of a block-tridiagonal matrix (from the precision matrix of the  LEG prior evaluated at the sampled data points) plus a diagonal matrix (contributed by the likelihood term of each observed data point) is again block-tridiagonal, leading to linear-time updates \\cite{smith2003estimating,Paninski2010,fahrmeir2013multivariate,polson2013bayesian,Khan,Nickisch}.\n\n\n\\subsection{Non-linear domains}\nJust as Gaussian Markov models in discrete time can be easily extended to Gaussian graphical models on general graphs, we can extend the Gaussian Markov PEG and LEG processes to stochastic processes on more general domains.  In the simplest case the domain of the process could be a tree, with the PEG kernel defined in terms of distance along the tree, rather than distance on the line.  Inference in the resulting tree-structured Gaussian graphical model can proceed via message passing in $O(m)$ time.\n\n\\subsection{Multi-dimensional domains}\nWe can also use LEG kernels to model processes of the form $x:\\ \\mathbb{R}^d\\rightarrow\\mathbb{R}^n$.  Let $B,\\Lambda$ be matrices, let $N,R$ be collections of matrices, and let $C_\\KLEG(\\tau;N,R,B,\\Lambda) \\triangleq \\delta_\\tau \\Lambda \\Lambda^\\top+ \\sum_{r=1}^{\\zeta} \\prod_{k=1}^d B C_\\PEG(\\tau_k;N_{rk},R_{rk})B^\\top$.   \n\\begin{theorem}\nLet $\\Sigma:\\ \\mathbb{R}^d \\rightarrow \\mathbb{R}^{n \\times n} $ any positive-definite integrable continuous stationary kernel, and fix $\\varepsilon>0$.  There exists a KLEG kernel such that $\\Vert C(\\tau)z-C_\\KLEG(\\tau)z\\Vert < \\varepsilon z$. \n\\end{theorem}\n{\\bf Proof:} See supplementary material.  \n\nEfficient computation is possible for observations from a KLEG process along a (potentially irreguarly-spaced) grid.  The covariance matrix of these observations has structure which can be leveraged for efficient computation.  For example, in the supplement we give an algorithm for multiplying by this matrix, and show that the computational cost of this algorithm scales linearly with the number of points in the grid.  Combined with GPyTorch (cf.\\ \\cite{gardner2018gpytorch}), this algorithm should yield efficient inference algorithms for KLEG processes.\n\n\n\n%                            _                      _       \n%                           (_)                    | |      \n%   _____  ___ __   ___ _ __ _ _ __ ___   ___ _ __ | |_ ___ \n%  / _ \\ \\/ / '_ \\ / _ \\ '__| | '_ ` _ \\ / _ \\ '_ \\| __/ __|\n% |  __/>  <| |_) |  __/ |  | | | | | | |  __/ | | | |_\\__ \\\n%  \\___/_/\\_\\ .__/ \\___|_|  |_|_| |_| |_|\\___|_| |_|\\__|___/\n%           | |                                             \n%           |_|                                             \n\n\n\\section{Experiments}\n\nHere we are interested in testing the theoretical results described above.  In practice, how fast is inference with the LEG process?  How well can the LEG model approximate popular kernels?  How well does the LEG model extrapolate and interpolate?  How well can it smooth?\n\n\\subsection{Computational complexity}\n\n\\begin{figure}[t!]\n\\vskip 0.2in\n\\begin{center}\n\\centerline{\\includegraphics[width=\\columnwidth]{pics/scaling}}\n\\caption{\\textbf{Walltime for evaluating LEG likelihoods}.  How long does it take to compute the likelihood of observations from a LEG model on an m5.24xlarge machine on the Amazon AWS service?   We compare times for differently-ranked models and different numbers of observations.   For example, the likelihood for one billion observations under a rank-3 LEG model can be computed in roughly three and a half minutes.  \n\\label{fig:sofast}}\n\\end{center}\n\\vskip -0.2in\n\\end{figure}\n\n\n\\begin{figure*}[t!]\n%\\vskip 0.2in\n\\begin{center}\n\\centerline{\\includegraphics[width=2\\columnwidth]{pics/kernelfriends}}\n\\caption{\\textbf{LEG kernel approximation of some popular specific kernels}.  \nBy taking the rank $\\ell$ sufficiently high we can achieve arbitrarily good approximations to any kernel.  In the three examples shown here, $\\ell=4$ already provides adequate approximation quality.  Note that in some cases some lines aren't visible because they are superimposed on each other; for example, when approximating Matern kernels we find nearly identical models for for $\\ell \\in {2,3,4}$.}\n\\label{fig:reppower}\n\\end{center}\n%\\vskip -0.2in\n\\end{figure*}\n\nThroughout what follows, we will perform inference on LEG processes using the Cyclic Reduction algorithm outlined in \\ref{subsec:leggpcomputation}. We wanted to check if there are practical difficulties that could negate the theoretically linear computational cost of this method.  We measured how long it took to compute the likelihood of single contiguous chains of observations from LEG processes of various ranks.  In each case we used an m5-24xlarge machine on Amazon Web Services (AWS).\n\n\n\nOverall, the empirical scaling appeared consistent with the theoretical predictions.  The likelihood of one million observations from a rank-3 model could be computed in $0.25$ seconds, and one billion observations could be computed in 195 seconds.  We saw similar trends across models of other ranks; the results are summarized in Figure \\ref{fig:sofast}.  Note that for smaller datasets we actually observed a sublinear scaling (i.e. a slope of less than one on the log-log plot) that turns approximately linear for larger values of $m$.\n\n\n\\subsection{Matching one-dimensional kernels}\n\n\n\nTheorem \\ref{thm:legflex} shows that LEG kernels can represent any stationary Gaussian process arbitrarily well \\emph{if} the latent dimension $\\ell$ is sufficiently high.  How high does this dimension actually need to be in order to get a good fit?  We investigate this question by examining several popular one-dimensional kernels.  In each case we draw fifty thousand observations, each taken $.1$ units apart from the next.  We fit LEG models of various ranks by optimizing the log likelihood using the Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm (as implemented in SciPy).  Gradients were computed by TensorFlow2 using backpropogation through the Cyclic Reduction algorithm.   We found this approach to be simple, scalable, and robust across datasets.  The likelihood could also be optimized using Expectation Maximization, but we found it was not as fast \\cite{dempster1977maximum}.  The model could also by fit by moment-matching instead of likelihood; this is a common practice for ARMA models \\cite{brockwell2013time} and we hope to explore this possibility in the future. \n\nHow well do LEG kernels approximate the Rational Quadratic (RQ) kernel,\n\\[\nC_{\\mathrm{RQ}}(\\tau) = 2/ (1 + \\tau^2)?\n\\]\nOn the one hand, the Rational Quadratic kernel is profoundly different from every LEG kernel.  The spectrum of the RQ kernel decays exponentially, whereas the spectrum of of a LEG process is asymptotically an inverse polynomial (recall from section \\ref{sec:smk} that PEG processes contain Cauchy spectral mixture models as a special case).  On the other hand, Theorem \\ref{thm:legflex} guarantees a Rational Quadratic kernel can be matched uniformly well by a LEG kernel.  Figure \\ref{fig:reppower} shows a rank-4 LEG kernel $C(\\tau)$ appears to do an excellent job of matching the RQ kernel for $t<2$ and an adequate job of matching for $t>2$.  \n\n\\begin{figure*}[t!]\n\\vskip 0.2in\n\\begin{center}\n\\centerline{\\includegraphics[width=2\\columnwidth]{pics/mlc02}}\n\\caption{\\textbf{LEG processes interpolate and extrapolate well across long timescales}.  It appears that a rank-5 LEG model is sufficient to capture the linear and periodic trends in the Mauna Loa CO$_2$ dataset.  Above we compare the true observations with interpolations made by the LEG model.  The gray areas encompass one and two predictive standard deviations, i.e. the LEG model's uncertainty in forecasting and extrapolating what out-of-sample observations would look like.}\n\\label{fig:realdata}\n\\end{center}\n\\vskip -0.2in\n\\end{figure*}\n\n\nThis apparent contradiction -- RQ is profoundly different (on the tails of the spectrum) from every LEG kernel, yet every RQ kernel can be matched arbitrarily well by a LEG kernel -- is resolved by considering the different timescales involved in any Gaussian Process.  LEG kernels can uniformly approximate any stationary covariance, which means that we can use them to get uniformly accurate forecasts and interpolations at any fixed timescale.  If a LEG kernel is trained on observations at a particular timescale, the kernel will attempt to match smoothness \\emph{at that timescale}.  For example, these LEG kernels were trained on observations at a timescale of $.1$, so they will attempt to match the covariance at that scale and larger.\n\n\nThe case of the (RBF) kernel, given by $C_\\mathrm{RBF}(\\tau)=\\exp(-\\tau^2/2)$, is even more extreme.  This kernel's spectrum decays log-quadratically -- even faster than the spectrum of the RQ kernel.  For any RBF process, any RQ process, and any PEG process, one can always find a small enough scale so that the RBF process will look smoother than the RQ process and the RQ process is smoother than the PEG processes.  Modeling this smoothness is difficult for lower-rank LEG models.  For example, the best rank-2 LEG model includes a large oscillation that is not found in the ground-truth RBF kernel.  It is not until rank 4 that the LEG process is able to match the kernel well.\n\nFinally, the Matern kernel with $\\nu=1.5$ turns out to be an easy case.  This kernel is given by \n\\[\nC_{\\mathrm{Matern}}(\\tau) = (1+\\sqrt{3}\\tau)\\exp(-\\sqrt{3}\\tau).\n\\]\nLike PEG kernels, the spectrum of the Matern kernel decays slower than exponentially.  In fact, this Matern kernel lies inside the rank-2 LEG family.  Let\n\\[\nN=3^{1/4}\\left(\\begin{array}{cc}\n1 & -1\\\\\n-1 & 1\n\\end{array}\\right)\\qquad R=\\sqrt{3}\\left(\\begin{array}{cc}\n0 & 1\\\\\n-1 & 0\n\\end{array}\\right).\n\\]\nThen the Matern kernel is given by $\\LEG(N,R,\\mathbf{1}/\\sqrt{2},0)$.\n\n\n\n\\begin{figure*}\n\\vskip 0.2in\n\\begin{center}\n\\centerline{\\includegraphics[width=2\\columnwidth]{pics/kenny}}\n\\caption{\\textbf{LEG processes can smooth irreguarly spaced neural data}.  Ten thousand irregularly spaced observations suggest that the firing rates of hippocampal neurons are modulated by the rat's position in a maze.  However, the modulation strength visible in the raw data is weak.  By smoothing this data with a LEG process we can see the trend more clearly. How much should we smooth?  By training a rank-5 LEG process we can determine a smoothness level automatically. The gray areas indicate the LEG model's posterior uncertainty about the estimated tuning curve.}\n\\label{fig:kenny}\n\\end{center}\n\\vskip -0.2in\n\\end{figure*}\n\n\\subsection{Mauna Loa CO$_2$}\n\n\nTo find out whether LEG models can offer a practical tool for extrapolation and interpolation, we turn to the Mauna Loa CO$_2$ dataset.  For the last sixty years, the monthly average atmosphere CO$_2$ concentrations at the the Mauna Loa Observatory in Hawaii have been recorded \\cite{keeling2005atmospheric}.  This dataset is interesting because it features two different kinds of structures: an overall upward trend and a yearly cycle.  To test the ability of the LEG model to learn these kinds of structures from data, we trained a rank-5 LEG kernel on all the data before 1980 and all the data after 2000.  We then asked the LEG model to interpolate what happened in the middle and forecast what the concentration might look like in the next twenty years.  \n\nThe results are shown in Figure \\ref{fig:realdata}.  It is encouraging that the LEG predictions interpolate adequately from 1980 to 1920.  Even though the LEG process is given no exogenous information about  ``years'' or ``seasons,'' it correctly infers the number of number of bumps between 1980 and 1920.  This example shows that the LEG model is sufficiently flexible to learn unanticipated structures in the data.  \n\n\\subsection{Hippocampal place-cells}\n\nSmoothing is another common application of GPs.  Here we see whether LEG models can be used to smooth irregularly spaced observations from neural spiking data \\cite{grosmark2016diversity}.  \n\nIn this data a rat's position in a one-dimensional maze is reported on a regular schedule, around 40 times per second.  At each time-step, each neuron may be silent or may fire (``spike'') some number of times.  For each neuron, we would like to estimate the ``tuning curve'' -- a function which takes in positions and returns the expected number of spikes as a function of the rat's position.  With no smoothness assumptions on this function, the problem is impossible; the rat is never observed at exactly the same place twice.  However, it is unclear how much smoothness should be assumed.  Gaussian Processes offer a natural way to automatically learn an appropriate level of smoothness from the data itself.  Note that the observed positions do not fall into a regularly spaced grid, so classical approaches such as the ARMA model cannot be applied.  \n\nHere we model this tuning curve using a PEG process, $z\\sim \\PEGGP(N,R)$.  In this view, each data-point from the experiment constitutes a noisy observation of $z$.  When the rat is at position $t$  we model the distribution on the number of spikes observed in a small timebin as a Gaussian, with mean $B z(t)$ and variance $\\Lambda \\Lambda^\\top$.  (It would be interesting to apply a non-Gaussian observation model here, as in, e.g., \\cite{smith2003estimating,rad2010efficient,savin2016,gao2016linear}, and references therein; \nas noted in section \\ref{sec:extensions}, linear-time approximate inference is feasible in this setting and is an important direction for future work.)\n\nFor each neuron we train the parameters of a separate LEG model.  We can then look at the posterior distribution on the underlying tuning curve $z$.  The posterior mean of this process for various neurons is shown in Figure \\ref{fig:kenny}.  We also represent one standard-deviation of the posterior variance of $z$ with gray shading.   Fitting the LEG model and looking at the posterior under the learned model appears to yield an effective Empirical Bayes approach for this kind of data. \n\n\\section{Conclusion}\n\nWe here make two advances in speeding up inference for Gaussian Processes on one dimension.  First, we show that the LEG model, a particularly tractable continuous-time Gaussian hidden Markov process, can be used to approximate any GP with a stationary integrable continuous kernel, critically enabling linear runtime scaling in the number of observations.  Second, we make this theoretical result practical by developing Cyclic Reduction-based algorithms to parallelize this computation, and sharing TensorFlow2-based implementations of these algorithms.  We believe these advances will open up a wide variety of new applications for GP modeling in highly data-intensive areas involving data sampled at high rates and/or over long intervals, including geophysics, astronomy, high-frequency trading, molecular biology, neuroscience, and more.\n\n\\section*{Acknowledgements}\n\nThanks to Jake Soloff for resolving a thorny point about matrix-valued measures.    \n\n\\bibliography{refs}\n\\bibliographystyle{icml2019}\n\n\n\n\\end{document}", "meta": {"hexsha": "c7423e0a2659ab166cb90c152ef109e4d76f7768", "size": 42601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/led.tex", "max_stars_repo_name": "jacksonloper/leg-gps", "max_stars_repo_head_hexsha": "c160f13440d67e1041b5b13cdab9dab253569ee7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-03-18T11:19:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T02:06:40.000Z", "max_issues_repo_path": "math/led.tex", "max_issues_repo_name": "jacksonloper/leg-gps", "max_issues_repo_head_hexsha": "c160f13440d67e1041b5b13cdab9dab253569ee7", "max_issues_repo_licenses": ["MIT"], "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/led.tex", "max_forks_repo_name": "jacksonloper/leg-gps", "max_forks_repo_head_hexsha": "c160f13440d67e1041b5b13cdab9dab253569ee7", "max_forks_repo_licenses": ["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.1234309623, "max_line_length": 1293, "alphanum_fraction": 0.7681509824, "num_tokens": 10447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6174583823390017}}
{"text": "\\section{Introduction}\nAll topics discussed in this paper rely on category theory and its notations. We refer the interested reader to ...\\\\\n\\indent Let $\\mathcal{I}$ be some category and $\\mathrm{URng}$ the category of unital rings. We aim to discuss the bifunctor \n$$\\mathfrak{sl} : \\mathcal{I} \\times \\mathrm{URng} \\longrightarrow \\mathrm{Lie}.$$\nHere, $\\mathrm{Lie}$ is the category of Lie algebras, situated in the following chains of categories:\n$$\\bao{lllllll}\n\\mathrm{Lie} &\\subset \\mathrm{Alg} &\\subset \\mathrm{Mod} &\\subset \\mathrm{Abel} &\\subset \\mathrm{Grp} &\\subset \\mathrm{Mon} &\\subset \\mathrm{SGrp}\\\\\n&&&&&& \\subset \\mathrm{PSpc}\\\\\n&& \\subset \\mathrm{SGrp}&&&&\\\\\n\\ea$$\n\n\\newpage\n\\newcommand{\\sltwor}{\\mathfrak{sl}_2(R)}\n\\section{Example}\nNow, let us discuss the special case $|I| = 2$ for $I \\in \\mathcal{I}$. We define $\\mathfrak{sl}(I,R) =: \\sltwor$ in a categorical sense.\n\\subsection{Representation}\nWe choose the $R$ module $M$ with\n$$M = \\bigoplus_{i=1}^3 R.e_i \\simeq_{\\mathrm{Mod}_R} R.X \\oplus R.Y \\oplus R.H,\\ e_1 \\stackrel{\\sim}{\\longmapsto} X, e_2 \\stackrel{\\sim}{\\longmapsto} Y,e_3 \\stackrel{\\sim}{\\longmapsto} H.$$\nLet $m = \\sum_{i \\in \\{X,Y,H\\}} m_i e_i \\in \\sltwor$ then the following matrix represents the adjunct of $m$:\n$$\\bao{rcl}\nad(m) &=& \\left(\\bao{ccc}\n2 m_H & & -2 m_X\\\\\n& -2 m_H & 2 m_Y\\\\\n-m_Y&m_X&\\\\\n\\ea\\right),\\\\\n &&\\\\\n &=& \\left[ n \\longmapsto [m,n] = \\begin{cases}(2 m_H n_X - 2 m_X n_H) X\\\\ - (2 m_H n_Y - 2 m_Y n_H) Y\\\\ + ( m_X n_Y - m_Y n_X) H\\end{cases}\\right]\\\\.\n \\ea$$\nThus, the map $\\rho : \\sltwor \\longrightarrow \\mathrm{End}_R(M)$, ", "meta": {"hexsha": "d06721f3d6bac93fd5ba7a1c348a344fcf447721", "size": 1587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "special_lie/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": "special_lie/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": "special_lie/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": 54.724137931, "max_line_length": 190, "alphanum_fraction": 0.6603654694, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699185, "lm_q2_score": 0.6959583376458153, "lm_q1q2_score": 0.6174574279682182}}
{"text": "\\documentclass[a4paper,12pt]{report}\n\n\\usepackage{amsmath,amsfonts,mathtools}\n\\usepackage{amssymb}\n\\usepackage{amsbsy}\n\\usepackage{hyperref}\n\n\\newcommand*{\\Comb}[2]{{}^{#1}C_{#2}}%\n\n\\begin{document}\n\\title{ECE286 Abridged}\n\\author{Aman Bhargava}\n\\date{Janaury 2020}\n\\maketitle\n\n\\tableofcontents\n\n\\chapter{Introduction}\n\\section{Counting}\nThere are three main types of counting:\n\\begin{enumerate}\n\\item \\textbf{With} replacement \\textbf{with} ordering.\n\\item \\textbf{No} replacement \\textbf{with} ordering.\n\\item \\textbf{No} replacement \\textbf{No} ordering.\n\\end{enumerate}\n\\paragraph{With replacement with ordering: } The classic example here is counting the \\textit{number of possible passwords}.\nWe have $n$ options for each character (let's say $n = 26$) and we have sequences of $k$ length (let's say the passwords are $k = 8$ long).\nThen our number of possible passwords is: $$n^k$$\n\n\\paragraph{No replacement with ordering: } You have $n$ total distinct objects and you want to see how many $k$-long groups you can make \nwith them. You can't use an object twice in the sequences. Your number of options goes down by $1$ at every additional object added \nto a given sequences, so you end up with the following number of \\textbf{permutations}:\n$$(n)(n-1)(n-2)...(n-k+1) = \\frac{n!}{(n-k)!} = nPr$$\n\n\\paragraph{No replacement no ordering: } Same as above but the order doesn't matter (think of the number of \\textbf{groups} instead \nof number of \\textbf{sequences}). We already know that you can make $nPr$ \\textbf{sequences}, and that a given \\textbf{group} can be \nsequentialized in $k!$ ways. Therefore, we simply divide our answer for $nPr$ by $k!$ as follows:\n$$\\frac{n!}{k!(n-k)!}$$\n\n\\section{Random Experiments}\nEssentially experiments where you don't know the outcome in advanced and it is useful to think of them as \nhaving a \\textit{random} component. There are three hand-wavy types:\n\\begin{enumerate}\n\\item Designed: E.g. a coin toss.\n\\item Observational: Uncontrolled, e.g. observe and measure the time to get to school.\n\\item Retrospective: Looking at past data.\n\\end{enumerate}\n\nThey all have \\textbf{procedure} and \\textbf{measurements}. \n\n\\subsection{Sample Space}\nThis is the set of all possible outcomes of the experiment, denoted by $S$. There are three types:\n\\begin{enumerate}\n\\item Finite (e.g. 3 coin tosses in a row)\n\\item Countably infinite (e.g. how many coin tosses until I get heads?)\n\\item Uncountably infinite (e.g. how tall is this person?)\n\\end{enumerate}\n\n\\subsection{Events}\nAn event is a \\textbf{set of outcomes} that we are interested in. For a coin flip experiment, we might have\n$$A = \\{HTT, THT, HHT\\}$$\n\nAll events are \\textbf{subsets} of the universal set $S$ (sample space). The \\textbf{Event Class $E$} is the \nset of all events. We assign probabilities $p$ and relative frequences $f$ to events in $E$.\n\n$$\\lim_{n \\to \\infty} f_A(n) = \\lim_{n\\to\\infty} \\frac{n_A}{n} = p_A$$\n\n\\chapter{Probability}\n\\section{Axioms of Probability Theory}\nHere's another list of three to remember:\n\\begin{enumerate}\n\\item For any event $A$, $P(A) \\geq 0$.\n\\item $P(S) = 1$. Events will always come from the sample space $S$.\n\\item For any two disjoint sets $A\\cap B = 0$ then $P(A\\cup B) = P(A) + P(B)$.\n\\end{enumerate}\n\nOne particularly nice property that arises from this is the following: for any events $A$ and $B$,\n$$P(A \\cup B) = P(A) + P(B) - P(A \\cap B)$$\nYou can get to this conclusion via the Venn diagram drawing approach.\n\n\\section{Conditional Probability}\nThe basic question we're answering here is: \\textit{How does event $A$ affect the probability of $B$?} \n\\paragraph{Central Idea: } because event $A$ happened, the sample space shrinks to $A$ for the next event.\n\n\\paragraph{Notation: } The ``probability of B given A'' is denoted by $P(B|A)$.\n$$P(B|A) \\equiv \\frac{P(A \\cap B)}{P(A)}$$\nIntuitively, this says that you divide the `area' of the overlap region by the area of $A$ to get $P(B|A)$. \n\n\\subsection{Independence}\n\n$A$ and $B$ are independent if \\textbf{knowing that B happened} doesn't tell you anything about $A$ happening. \n$$P(A|B) = P(A);\\,\\,\\, P(B|A) = P(B)$$\nIt is easily demonstrable that it is a \\textbf{symmetric property}. If $B$ is independent of $A$, then $A$ is \nindependent of $B$.\n\nThere are two types of independence:\n\\begin{enumerate}\n\\item Contrived: Because of how we chose $A$ and $B$ - we kind of got lucky that it just happens to be.\n\\item The nature of the experiment: The two things are really fundamentally independent.\n\\end{enumerate}\n\n\\section{Total Probability}\n\\paragraph{We define a partition through the following: } The set $\\{B_1, ..., B_n\\}$ is a partition of $S$ \niff:\n\\begin{enumerate}\n\\item $B_i \\cap B_j\\,\\, \\forall i, j < k, i \\neq j$\n\\item $\\sum B_i = S$\n\\item For any event $A$: $$A = \\sum(A \\cap B_i)$$\n\\end{enumerate}\n\n\\paragraph{TOTAL PROBABILITY LAW: } $$P(A) = \\sum_{i=1}^k P(A|B_i)P(B_i)$$\n\n\\section{Bayes Theorem}\n\n$$P(B | A) = \\frac{P(A|B) P(B) }{P(A)}$$\n\nA key idea is that the \\textbf{partition} (in this case $B$) is usually the \\textbf{INPUT}. \nWe know $P(B)$ is known, $P(B|A)$ is measured in the experiment, then we find the $P(A|B)$. \nThink about the example where $A$ is having cancer and $B$ is the test for cancer being positive.\n\n\n\\subsection{Multiple Tests}\n\nThe classical question to test one's understanding of Bayes Theorem is one where a patient is tested for cancer. There is some probability $P(C)$ that the patient has cancer, there is a probability $P(\\oplus)$ that the test will come back positive, and $P(\\oplus | C)$. One is generally required to find $P(C | \\oplus)$. With one test, it is a relatively straight forward plug-and play problem.\n\nWith two tests, things get a bit trickier. There are two keys to solving the problem:\n\n\\begin{itemize}\n\\item We assume that each test administered is \\textbf{independent} of the other administered tests. This can be difficult to deeply understand due to the fact that it goes against our intuition of `independent'. If we know that the first test resulted in a positive result, that changes the probability we would predict for the second to be positive. However, it is impossible to this problem without that assumption.\n\\item The algebra for manipulating a conditional probability with multiple results is as follows:\n\n$$P([\\oplus \\& \\oplus] | C) = P(\\oplus | C)P(\\oplus | C)$$\n\\end{itemize}\n\n\n\n\n\\chapter{Random Variables and Probability Distributions}\n\\section{Random Variables}\nA random variable \\textbf{maps} the results of an experiment to the real numbers. They \\textbf{can be many $\\to$ one}\nbut \\textbf{cannot}  be \\textbf{one $\\to$ many}. \n\nThe range of all values that $X(s)$ (which is the random variable $X$) can take:\n$$S_x = \\{x | X(s) = x, s \\in S\\}$$\n\nGenerally speaking, big $X$ is read as `any random $x$ value' or `the set of possible $x$ values' while \nlittle $x$ is usually a given $x$ value.\n\nThe difference between a discrete and continuous random variable is relatively straight forward. We have \nmapping functions $f$ that assign probabilities to ouctomes $x_i$ that obey the following properties:\n\n\\begin{enumerate}\n\\item $f(x_i) > 0$\n\\item $\\sum f(x_i) = 1$\n\\item $P(x = x_i or x = x_j) = f(x_i) + f(x_j)$. This makes sense because one $\\to$ many mappings are \nnot allowed so the sets are definitely disjoint.\n\\item $\\{s|X(s) = x_i\\} \\cap \\{s|X(s) = x_j\\} = 0$\n\\end{enumerate}\n\n\\section{Probability Functions}\n\\subsection{Probability Mass Functions (PMF's)}\nThese are for discrete variables. We know that event $A = \\{s | X(s) = x_i, s \\in S\\}$ and that \n$P(x = x_i) = P(A)$. The probability mass function is $f(x_i) = P(A)$ and has the following \nproperties:\n\\begin{itemize}\n\\item $0 \\leq f(x_i) \\leq 1$\n\\item $\\sum f(x_i) = 1$\n\\item If $A = \\{x_1, x_2\\}$ then $P(A) = f(x_1) + f(x_2)$. \n\\end{itemize}\n\n\\subsection{Cumulative Distribution Functions (CDFs)}\n$$F(x) = P(X < x)$$\n\\textit{Read: F(x) is the probability that some random $X$ is less than the given $x$.}\n\\paragraph{Properties:}\n\\begin{enumerate}\n\\item $0 \\leq F(x) \\leq 1$\n\\item $\\lim_{x \\to \\infty} F(x) = 1$\n\\item $\\lim_{x \\to -\\infty} F(x) = 0$\n\\item $F(x)$ is \\textbf{non-decreasing}.\n\\end{enumerate}\n\n$$P(x < X < x + dx) = F(x + dx) - F(x)$$\n\n\\subsection{Probability Density Functions (PDFs)}\n$$f(x) \\equiv \\lim_{dx \\to 0} \\frac{F(x + dx)- F(x)}{dx} = F'(x)$$\n\\paragraph{Properties:}\n\\begin{enumerate}\n\\item $f(x) > 0$\n\\item $\\int_{-\\infty}^{\\infty} f(x) dx = 1$\n\\item $P(a < X \\leq b) = \\int_a^b f(x) dx$\n\\end{enumerate}\n\n\\section{Mixed Random Variables}\n$$P(x < X < x + \\Delta x) \\approx f(x) \\Delta x$$\n\n\\section{Joint PDFs and PMFs}\nWe are now switching to mapping outcomes to \\textbf{vectors}. Each outcome $s$ has mapping $[X(s), Y(s)]$. \n\n\\paragraph{Range: } $S_{xy} - \\{(x, y) | x = X(s), y = Y(s), s \\in S\\}$\n\n\\subsection{Joint PMFs}\n$$f(x_i, y_j) = P(x = x_i, y = y_j)$$\n\\paragraph{Properties: } \n\\begin{enumerate}\n\\item $0 \\leq f(x_i, y_i) \\leq 1$\n\\item $\\sum\\sum f(x_i, y_j) = 1$\n\\item If $A\\subset S_{xy}$, $P(A) = \\sum\\sum_{(x_i, y_i) \\in A} f(x_i, y_i)$\n\\end{enumerate}\n\nThe general purpose here it to see the connection between two or more variables. \n\n\\subsection{Marginal PMFs}\n$$g(x_i) = P(X = x_i) = \\sum_{y_j \\in S_y} f(x_i, y_i)$$\n$$h(y_j) = P(Y = y_j) = \\sum_{x_i \\in S_x} f(x_i, y_i)$$\n\n\\paragraph{Interpretation: } % TODO: Populate this when you have the brain power\n\n\\subsection{Conditional PMFs}\nConditional probability of $y$ given $x = x_i$:\n$$f(y_j | x_i) = P(Y = y_j | x = x_i) = \\frac{f(x_i, y_j)}{g(x_i)}$$\n\nRoughly the same rules apply to joint CDFs and PDFs, etc. Just replace the sums with integrals from negative \nto positive infinity.\n\n\\chapter{Mathematical Expectation}\n\nMeans and variances. The main resource I use here is the textbook, so the notation may differ from the in-class notation. It is necessary to go back over the in-class material to correct the notation at a later date.\n\n\\section{Expected Value}\n\n$$\\mu = E[X] = \\sum_x xf(x)$$\n$$\\mu = E[X] = \\int_{-\\infty}^{\\infty} xf(x) dx$$\n\n\\section{Variance}\n\n$$\\sigma^2 = E[(X-\\mu)^2] = \\sum_x (x-\\mu)^2f(x)$$\n$$\\sigma^2 = E[(X-\\mu)^2] = \\int_{-\\infty}^{\\infty} (x-\\mu)^2f(x)dx$$\n\nWhere $\\sigma^2$ is the \\textbf{variance} and $\\sigma$ is the \\textbf{standard deviation}. $\\mu$ is still the average or expected value. By making some simplifications, we also get:\n\n$$\\sigma^2 = E(X^2)-\\mu^2$$\n\n\\subsection{Covariance}\n\nFor joint probability density/distribution function $f(x, y)$, the covariance of $X$ and $Y$ is:\n\n$$\\sigma_{XY} = E[(X-\\mu_X)(Y-\\mu_Y)] = \\sum_X\\sum_Y(x-\\mu_X)(y-\\mu_Y)f(x, y)$$\n\n$$\\sigma_{XY} = \\iint (x-\\mu_X)(y-\\mu_Y)f(x,y)\\,dx\\,dy$$\n\nThis measures the \\textbf{association} between the two. In other words, the amount of linear correlation. You can simplify it like before to be:\n\n$$\\sigma_{XY} = E(XY) - \\mu_X\\mu_Y$$\n\n\\subsection{Correlation Coefficient}\n\n$$\\rho_{XY} = \\frac{\\sigma_{XY}}{\\sigma_X\\sigma_Y}$$\n\n\\paragraph{Properties:}\n\\begin{itemize}\n\\item $-1<\\rho_{XY}<1$\n\\item Exact linear independency $\\to \\rho_{XY} = 1$ if $b>0$ in $Y = mX + b$ and $\\rho_{XY} = -1$ otherwise.\n\\end{itemize}\n\n\\section{Means and Variance of Linear Combinations of Random Variables}\n\n\\paragraph{Expected value $E()$ is LINEAR: } \n\\begin{itemize}\n\\item $E(aX + b) = aE(X) + b$\n\\item $E[g(X) \\pm h(X)] = E(g(X)) \\pm E(h(X))$. This also works for functions of two variables.\n\\item $E(XY) = E(X)E(Y)$\n\\item If $X$ and $Y$ are independent, $\\sigma_{XY} = 0$\n\\end{itemize}\n\n\\paragraph{Theorem: } $f(x, y)$ is a joint probability distribution and $a, b, c \\in R$: \n$$\\sigma^2_{aX+bY+c} = a^2\\sigma^2_X b^2\\sigma_Y^2 + 2ab\\sigma_{XY}$$\nBecause $\\sigma^2_{aX+bY+c} = E\\{ [(aX + bY + c)]^2 - \\mu_{aX+bY+c} \\}$. You then use linearity of all the operators to get to the final answer.\n\n\\subsection{What if the Function is Non-Linear?}\n\n$$E(Z) = E(X/Y) \\neq E(X)/E(Y)$$\n\nFor navigating non-linear functions of a random variable, we can take the taylor series expansion and \\textbf{truncate} at the first linear term.\n\n\n\\chapter{Some Discrete Probability Distributions}\n\n\\section{Binomial and Multinomial Distribution}\n\nLet say that you have a random binary experiment that you run $n$ times. Each trial can either be \\textbf{successful} or \\textbf{unsuccessful}. Binomial distributions tell you the probability of having $k$ out of the $n$ be \\textbf{successful} given a probability $p$ of each individual trail being successful.\n\n\\subsection{Bernoulli Process}\n\n\\begin{itemize}\n\\item Consists of \\textbf{repeated trials}.\n\\item Each trial has one of a \\textbf{binary outcome}.\n\\item Probability of success $p$ remains the same from one trial to the next.\n\\item Repeated trials are independent.\n\\end{itemize}\n\n\n\\paragraph{Binomial Distribution: } Probability of distribution of a discrete random variable in a Bernoulli trials. If we let $x$ be our random variable (representing the number of \\textbf{successful} trials), the distribution of our probability mass function (PMF) is given by $b(x; n, p)$: \n\n\\begin{itemize}\n\\item Denoted by $b(x; n, p)$: depends on \\textbf{number of trials and probability of success}.\n\\item \\textbf{Mean} and \\textbf{variance} of $b(x;n,p)$ are: $\\mu = np$, $\\sigma^2=npq$ respectively.\n\\end{itemize}\n\n$$b(x; n, p) = \\binom nx p^x(1-p)^{n-x}$$\n\n\\section{Multinomial Experiments and Distribution}\n\nWhat if our experiment has more than two potential outcomes? This is how multinomial distributions arise. As arguments, it takes the following (for a set of \nexperiments with $k$ possible outcomes and $n$ trials):\n\n\\begin{itemize}\n\\item $n$: The number of trials run.\n\\item $\\vec{x}$: The hypothesized number of times each of the $k$ outcomes will occur. $\\sum x_i = n$, obviously.\n\\item $\\vec{p}$: The probability of each of the $k$ possible outcomes. \n\\end{itemize}\n\nThe requirements of the trials themselves are very similar to those of a Bernoulli Process (independent outcomes, etc)\n\n\n$$f(\\vec{x}; \\vec{p}, n) = \\binom {n}{x_1,...,x_k} p_1^{x_1} p_2^{x_2}...p_k^{x_k}$$\n\nwhere $\\binom {n}{x_1,...,x_k} = \\frac{n!}{x_1!...x_k!}$\n\nUnder the stipulation that $\\sum \\vec{x}_i = n$ and $\\sum \\vec{p}_i = 1$.\n\n\\section{Hypergeometric Distribution}\n\nBasically the same as binomial distribution but without \\textbf{statistical independence} between trials. Sampling at each trial is done \\textbf{without replacement}.\n\nIt's exactly like the example of a deck of cards. We let the red cards be \\textit{successes} and the black cards be \\textit{failures}. We want to know the probability of getting a certain number of \\textit{successes} given $n$ tries, \\textbf{without replacing any of the cards}. \n\n\n\\paragraph{Utility: } Binomial distributions are useful when you are looking to gauge the overall quality of a batch with \\textit{good} and \\textit{bad} labels. Hypergeometric distributions are there for when the test for good/bad is \\textbf{destructive}. When that is the case, you can't replace the item to the sample bag, so independence is not maintained. \n\n\\paragraph{Formula} $$h(x; N, n, k) = \\frac{\\binom{k}{x} \\binom{N-k}{n-x}}{\\binom{N}{n}}$$\n\nWhere \n\n\\begin{enumerate}\n\\item $n$ is the number of trials.\n\\item $N$ is the total number of items being selected from at each trial.\n\\item $k$ is the number of \\textbf{successful} items available to be picked.\n\\item $x$ is the \\textit{requested} number of successes ($h$ gives the probability of selecting $x$ successes by the end of the experiment). Under the stipulation\n$$\\max\\{0, n-(N-k)\\} \\leq x \\leq min\\{n, k\\}$$\n\\end{enumerate}\n\n\\subsection{Mean and Variance of Hypergeometric Distributions}\n\n$$\\mu = \\frac{nk}{N}$$\n$$\\sigma^2 = \\frac{N-n}{N-1} n \\frac{k}{N} (1-\\frac{k}{N})$$\n\n\\paragraph{When to approximate hypergeometric to binomial: } If $n << N$ (the number of trials vs. the number of total items), then we can approximate a hypergeometric\ndistribution as a binomial one. Specifically, if $n/N \\leq 0.05$.\n\n\\section{Negative Binomial Distribution}\n\nWhat if we begin a similar trial to before (counting the number of \\textbf{successful} outcomes from random experiments), but instead of counting successes, we count the \\textbf{number of trials it takes} to get a certain number of successful outcomes?\n\nWe are now interested in the probability of the $k$th success occurring on the $x$th trial. This is a \\textbf{negative binomial} experiment.\n\n\\paragraph{Negative Binomial Random Variable: } The number of trials ($X$) required to get $k$ successes is the \\textbf{negative binomial random variable}. Denoted by: \n\n$$b^*(x; k, p) = \\binom{x-1}{k-1}p^kq^{x-k}$$\n\n$b^*$ takes in the following and outputs the probability of it occurring:\n\\begin{itemize}\n\\item $x$: The number of trials taken to produce the result.\n\\item $k$: The number of successes we are looking for.\n\\item $p$: Probability of success at any given trial.\n\\item Output $b^*$: Chance that it will take $x$ trials to get $k$ successes given probability $p$ of success on a given trial.\n\\end{itemize}\n\n\\section{Geometric Distribution}\n\nWe have a standard binary trial procedure. A \\textbf{geometric distribution} gives the chance that it will take $x$ trials for the \\textbf{first success} to occur:\n\n$$g(x;p) = pq^{x-1}$$\n\nWhere $q = 1-p$, the probability of failure at a given trial.\n\n\\paragraph{Mean and variance of Geometric Distribution: } \n$$\\mu = \\frac{1}{p}$$\n$$\\sigma^2 = \\frac{1-p}{p^2}$$\n\n\\section{Poisson Distribution and Poisson Process}\n\n\\paragraph{Poisson Experiments: } An experiment that gives the \\textbf{number of outcomes in a time period or region} $X$.\n\n\\textit{Example: } $X$ is the number of telephone calls received per hour by an office.\n\n\\textbf{Properties: } \n\n\\begin{itemize}\n\\item The number of outcomes in a given interval is \\textbf{independent} of the number of outcomes in a \\textit{disjoint} interval.\n\\item Probability of an outcome occurring in a small interval is proportional to the length of that interval.\n\\item The probability of more than one outcome occurring in a very small interval is negligible.\n\\end{itemize}\n\n\\textbf{Formulae} \n\n$$\\mu = \\lambda t$$\n\nWhere $\\mu$ is the average number of occurrences in spatial/temporal region $t$. $\\lambda$ is the proportionality between the two.\n\n$$p(x;\\lambda t) = \\frac{e^{-\\lambda t} (\\lambda t)^x}{x!},\\,\\,\\, x=0,1,2,...$$\n\nThe Poisson probability sums give the chance that the number of occurrences is \\textbf{less than or equal} to a value $r$ over region $t$:\n\n$$P(r; \\lambda t) = \\sum_{x=0}^{r} p(x; \\lambda t)$$\n\nOften found from tables.\n\n\\textbf{Means and Variances: } \n\n$$\\mu = \\sigma^2 = \\lambda t$$\n\n\\textbf{Nature of Poisson Distributions: }\n\n\\begin{enumerate}\n\\item More symmetric as average value grows large.\n\\item $b(x; n, p) \\to p(x; \\mu)$ as $n \\to \\infty$, $np \\to \\mu$ ($p$ must go to zero for this to be true as well).\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\chapter{Continuous Probability Functions}\n\n\\section{Continuous Uniform Distribution}\n\nThis is just a flat distribution -- anything in the given range is equally likely. Density function:\n\n$$f(x; A, B) = \\frac{1}{B-A} \\,\\,\\text{ if} \\,\\,A \\leq x \\leq B, \\,\\,\\, 0\\,\\,\\, \\text{else}$$\n\nNote that the value of $f(x)$ must integrate to 1 over its bounds.\n\n$$\\mu = \\frac{A+B}{2}; \\,\\,\\,\\,\\,\\, \\sigma^2 = \\frac{(B-A)^2}{12}$$\n\n\\section{Normal Distribution}\n\nAlso known as \\textbf{Gaussian distribution}. One of the most important distributions in statistics, has extensive use in science and industry. \n\n\\textbf{Normal random variable: } A random variable $X$ that is distributed according to a normal distribution. The probability density function is given as: \n\n$$n(x; \\mu, \\sigma) = \\frac{1}{\\sqrt{2\\pi}\\sigma} e^{-\\frac{1}{2\\sigma^2} (x-\\mu)^2}$$\n\nImportantly, as soon as $\\mu, \\sigma$ are specified, the entire distribution (density function) is parameterized.\n\n\\paragraph{Properties of a Normal Distribution: } \n\\begin{itemize}\n\\item \\textbf{Mode} occurs at $x = \\mu$ (point where the density function is maximized).\n\\item Curve is symmetric about $\\mu$.\n\\item Inflection points occur at $x = \\mu \\pm \\sigma$. Concave downward between the two inflection points, upward outside of them.\n\\item Asymptotically approaches 0 as you get further from $\\mu$.\n\\item Total area under the curve is $1$.\n\\end{itemize}\n\n\\section{Areas under the Normal Curve}\n\nThere isn't actually a convenient form for the integral of the normal distribution function. We use tables to calculate it (or software). \n\n\\paragraph{For effiency: } We can convert a normal random variable so that it has $mu = 0;\\,\\,\\, \\sigma = \\sigma^2 = 1$. We call this adjusted variable $Z$ where \n\n$$Z = \\frac{X - \\mu}{\\sigma}$$\n\nWe can now use tables for $Z$ and use algebra to solve for the corresponding values of $X$. If we want the probability of $x_1 < X < x_2$, then we use the table to determine $z_1 < Z < z_2$ with $z_1 = (x_1-\\mu)/\\sigma$, etc. \n\n$$P(x_1 < X < x_2) = \\frac{1}{\\sqrt{2\\pi}\\sigma} \\int_{x_1}^{x_2} e^{\\frac{-1}{2\\sigma^2} (x-\\mu)^2} dx = \\frac{1}{\\sqrt{2\\pi}} \\int_{z_1}^{z_2} e^{-\\frac{1}{2} z^2} dz$$\n$$= \\int_{z_1}^{z_2} n(z; 0, 1) dz = P(z_1 < Z < z_2)$$\n\n\\paragraph{STANDARD NORMAL DISTRIBUTION: } When $\\mu = 0; \\,\\,\\, \\sigma^2 = 1$ for a normal distribution.\n\nTables for making calculation more convenient often just tell you $P(Z < z)$.\n\n\n\\section{Applications of the Normal Distribution}\n\nThis section is relatively straight forward if one has a good grasp of how to use the normal distribution function.\n\n\\section{Normal Approximation to the Binomial}\n\nAs one might imagine, the line between discrete and continuous probability distributions can get blurred as we increase the number of elements in a binomial distribution to approach infinity.\n\n\\paragraph{Theorem: } If $X$ is a binomial random variable with $\\mu = np$ and variance $\\sigma^2 = npq$, then the \\textit{limiting form} of the distribution \n\n$$Z = \\frac{X - np}{\\sqrt{npq}}$$\n\nas $n \\to \\infty$ is the standard normal distribution $n(z; 0, 1)$.\n\n\\paragraph{Requirements for limit: } \n\\begin{itemize}\n\\item $\\mu = np$\n\\item $\\sigma^2 = npq$\n\\item $n \\to \\infty$\n\\item $p, q$ aren't too close to 0 or 1. \n\\end{itemize}\n\nPretty good approximation even if $n$ is small as long as $p \\approx q \\approx \\frac{1}{2}$.\n\n\\paragraph{Continuity correction: } If we want to know the probability of $X < x$ for a binomial distribution, we should take the integral from $(-\\infty, x+0.5]$ of the normal distribution. \nThe $+0.5$ is called a `continuity correction'.\n\n\n\\section{Gamma and Exponential Distributions}\n\nThe normal distribution is not universally perfectly applicable. The exponential distribution is just a special case of the gamma distribution, though, so they're in the same section of the textbook.\n\nImportant for \\textit{queuing theory} and \\textit{reliability probability}. Time between arrivals, time to failure of electrical parts, etc. are well modelled by exponential distributions.\n\n\\subsection{Gamma Function}\n\n$$\\Gamma(\\alpha) = \\int_0^{\\infty} x^{\\alpha-1}e^{-x}dx,\\,\\,\\,\\, \\text{for} \\,\\,\\, \\alpha > 0$$\n\n\\paragraph{Properties of the Gamma Function: } \n\\begin{itemize}\n\\item $\\Gamma(n) = (n-1)(n-2)(n-3)...(1)\\Gamma(1)$ for any positive integer $n$.\n\\item $\\Gamma(n) = (n-1)!$ for a positive integer $n$.\n\\item $\\Gamma(1) = 1$.\n\\item $\\Gamma(\\frac{1}{2}) = \\sqrt{\\pi}$\n\\end{itemize}\n\n\\paragraph{THE GAMMA DISTRIBUTION FUNCTION: } \n$$f(x; \\alpha, \\beta) = \\frac{1}{\\beta^\\alpha \\Gamma(\\alpha)} x^{\\alpha-1}e^{-x/\\beta}$$ \n\nwhen $x > 0$. Elsewhere, $f(x; \\alpha, \\beta) = 0$. Also, $\\alpha, \\beta > 0$.\n\n\\subsection{Exponential Distribution}\n\nIf we set $\\alpha = 0$ in the gamma function, we get the exponential function.\n\n$$f(x; \\beta) = \\frac{1}{\\beta} e^{-x/\\beta}$$\n\nfor $x > 0$ and $f(x; \\beta) = 0$ elsewhere.\n\n\\subsection{Means and Variances}\n\n$$\\mu = \\alpha\\beta; \\,\\,\\,\\,\\, \\sigma^2 = \\alpha\\beta^2$$\n\n\n\\subsection{Relationship to Poisson Process}\n\nPoisson distribution if is for \\textbf{counting discrete events} in a given \\textbf{time period} or region. One can think of the period between events as a random variable in its own right (ex. time between arrivals at an airport). \n\nConnection between Poisson distribution and exponential distribution comes when we look at the \\textbf{probability of no events in a timeframe}:\n\n$$p(0; \\lambda t) = \\frac{e^{-\\lambda t} (\\lambda t)^0}{0!} = e^{-\\lambda t}$$\n\nIf we let $X$ be the time before the first Poisson event, then the probability $P(X > x) = e^{-\\lambda x}$. The CDF is therefore: $$P(0 \\leq X \\leq x) = 1-e^{-\\lambda x}$$\n\nMaking the PDF $$f(x) = \\lambda e^{-\\lambda x}$$\n\nWhich is \\textbf{exactly the same} as an exponential distribution with $\\lambda = 1/\\beta$. \n\nApplications of gamma/exponential distributions are therefore often to do with predicting the time-of-arrival for Poisson events.\n\n\\subsection{Memoryless Property}\n\nTake the example of a component with an exponentially distributed lifetime prediction function. If we know that it has lasted to $t_0$ already, when we can say that \n\n$$P(X \\geq t) = P(X \\geq t_0 + t | X \\geq t_0)$$\n\nBasically, if the piece has lasted for $t_0$ hours already, it has the same probability of lasting an additional $t$ hours as it did at the beginning. The piece has no `memory' of any damage it \nmight have taken before.\n\nHowever, if there is wear involves, then you should use a \\textbf{gamma} or \\textbf{Weibull distribution}. \n\nExponential distributions are good at describing \\textbf{time between events} or time for $1$ poisson event to occur. Gamma is good for describing the time for \\textbf{multiple poisson events} to occur.\n\n\n\\section{Chi-Squared Distribution}\n\nIf we let $\\alpha = v / 2$ and $\\beta = 2$ in the \\textbf{gamma distribution} ($v$ is a positive integer representing \\textbf{degrees of freedom}), we get the \\textbf{chi-squared distribution}. \n\n$$f(x; v) = \\frac{1}{2^{v/2}\\Gamma(v/2)} x^{v/2 - 1} e^{-x/2}$$\n\nfor $x > 0$, $v$ is the integer number of degrees of freedom. Important distributino for statistical hypothesis testing and estimation.\n\n\\paragraph{Mean and variance: } \n\n$$\\mu = v;\\,\\,\\,\\,\\, \\sigma^2 = 2v$$\n\n\\section{Weibull Distribution}\n\n\\textbf{Weibull distribution} is a common and effective way to model the lifetime of parts and assemblies. It is parameterized by two positive numbers $\\alpha, \\beta$:\n\n$$f(x; \\alpha, \\beta) = \\alpha \\beta x^{\\beta - 1} e^{-\\alpha x ^ \\beta}$$\n\nfor $x > 0$. $f$ is 0 elsewhere. Alpha and beta must be greater than 0.\n\n\\paragraph{Mean and variance: } \n\n$$\\mu = \\alpha^{-1/\\beta} \\Gamma(1+\\frac{1}{\\beta});\\,\\,\\,\\, \\sigma^2 = \\alpha^{-2/\\beta}\\{ \\Gamma(1 + \\frac{2}{\\beta}) - [\\Gamma(1 + \\frac{1}{\\beta})]^2 \\}$$\n\n\\paragraph{Cumulative Distribution Function } for Weibull distribution:\n\n$$F(x) = 1 - e^{-\\alpha x ^\\beta}, \\,\\,\\, x \\geq 0$$\n\n\\subsection{Failure Rate for Weibull Distribution}\n\nIt is useful to predict the \\textbf{probability that a part will function properly for AT LEAST time $t$}. We call that the reliability function $R(t)$.\n\n$$R(t) = P(T > t) = \\int_t^{\\infty} f(t) dt = 1 - F(t)$$\n\nTherefore the probability that a component will fail in the interval $T \\in [t, t+\\Delta t]$ is:\n\n$$\\frac{F(t + \\Delta t) - F(t)}{R(t)}$$\n\nAs we take the limit for $\\Delta t \\to 0$, we get the \\textbf{failure rate} $Z(t)$:\n\n$$Z(t) = \\lim_{\\Delta t \\to 0} \\frac{F(t + \\Delta t) - F(t)}{\\Delta t} \\frac{1}{R(t)} = \\frac{f(t)}{1 - F(t)}$$\n$$Z(t) = \\alpha \\beta t^{\\beta - 1}$$\n\n\\paragraph{Interpretation of Failure Rate} \n\nQuantifies the rate of change of the conditional probability that the component lasts an additional $\\Delta t$ given that it has lasted for $t$ time. Some important properties are as follows: \n\n\\begin{itemize}\n\\item $\\beta = 1$: Forms an exponential distribution with no \\textit{memory}. The component does not get more or less likely to break thanks to having lasted for time $t$.\n\\item $\\beta > 1$: Causes $Z(t)$ to increase with $t$, so the component wears down over time.\n\\item $\\beta < 1$: Causes $Z(t)$ to decrease with $t$, so the component strengthens over time.\n\\end{itemize}\n\n\n\\chapter{Functions of Random Variables}\n\n\\section{Transformations on Variables}\n\nIf you have a function $u$ and a discreete random variable $X$, you might want to know what the properties of $Y = u(X)$ are based on $u$ and $X$. It has to be \\textbf{one-to-one}, though.\n\n\\paragraph{Theorem 1: } If $X$ is a \\textbf{discrete} random variable with probability distribution $f(x)$ and $Y = u(X)$ is a one-to-one transformation such that $y = u(x)$, $x = w(y)$, then the \nprobability distribution function of $y$ $g(y)$ is: \n\n$$g(y) = f[w(y)]$$\n\n\n\\paragraph{Theorem 2: } $X_1, X_2$ are \\textbf{discrete} random variables with joint probability distribution $f(x_1, x_2)$. $Y_1 = u_1(X_1, X_2)$ and $Y_2 = u_2(X_1, X_2)$ are both one-to-one transformations between ordered pairs $(x_1, x_2), (y_1, y_2)$. We let $y_1 = u_1(x_1, x_2);\\,\\,\\, y_2 = u_2(x_1, x_2)$. Then the joint probability of $y_1, y_2$ is: \n\n$$g(y_1, y_2) = f[w_1(y_1, y_2), w_2(y_1, y_2)]$$\n\n\\paragraph{Theorem 3: } $X$ is a \\textbf{continuous} random variable with PDF $f(x)$. $Y = u(X)$ is a 1-1 relationship. $y = u(x);\\,\\,\\, x = w(y)$. Then \n\n$$g(y) = f[w(y)] | J|$$\n\nwhere $J = w'(y)$, or the \\textbf{Jacobian} of the transformation.\n\n\\paragraph{Theorem 4: } $X_1, X_2$ \\textbf{cts} random vars with $f(x_1, x_2)$. $Y_1 = u_1(X_1, X_2);\\,\\,\\, Y_2 = u_2(X_1, X_2)$ are both 1-1. Then the joint PDF for the $y$'s is: \n\n$$g(y_1, y_2) = f[w_1(y_1, y_2), w_2(y_1, y_2)]|J|$$ \n\nWhere $$J = \\det{|\\frac{\\partial x_1}{\\partial y_1} , \\frac{\\partial x_1}{\\partial y_2} ; \\frac{\\partial x_2}{\\partial y_1} , \\frac{\\partial x_2}{\\partial y_2} |}$$\n\n\\paragraph{Theorem 5: } $X$ is \\textbf{cts} RV with $f(x)$. $Y = u(X)$, and is \\textbf{NOT 1-1}. If interval on $X$ can be divided into $k$ mutually disjoint sets that each have proper inverse functions \n$x_n = w_n(y)$, then the PDF of $y$ is: \n\n$$g(y) = \\sum_{i = 1}^{k} f[w_i(y)]|J_i|$$\n\nWhere $J_i = w_i'(y)$.\n\n\\section{Moments and Moment-Generating Functions}\n\n\\paragraph{Definition of Moment: } The $r$th moment about the origin for RV $X$ is: \n\n$$\\mu'_r = E(X^r) = \\sum_x x^r f(x) = \\int_{-\\infty}^{\\infty} x^r f(x) dx$$\n\nConnections to known statistical properties include:\n\n$$\\mu = \\mu_1';\\,\\,\\,\\, \\sigma^2 = \\mu_2' - \\mu^2$$\n\n\\subsection{Moment Generating Function}\n\nThese form an alternatie function to determine the moments of a RV:\n\n\\paragraph{Definition: } A \\textbf{moment generating function} of $X$ is given by $M_X(t)e^{tX}$. Therefore\n\n$$M_X(t) = E(e^{tx}) = \\sum_x e^{tx}f(x) = \\int_{-\\infty}^{\\infty} e^{tx}f(x) dx$$\n\nThese exist only when the integral/sum converges. To get the actual moments from a moment-generating function, we do the following: \n\n$$\\mu_r' = \\frac{d^r M_X(t)}{dt^r}|_{t=0}$$\n\nThe textbook has several good examples of solving things like binomial functions with this technique.\n\n\\paragraph{Uniqueness Theorem: } If $M_X(t) = M_Y(t)$ for RV's $X, Y$ for all $t$, then $X, Y$ have the exact same probability distribution.\n\n\\paragraph{Addition Theorem: } $$M_{X+a}(t) = e^{at}M_X(t)$$\n\n\\paragraph{Multiplication Theorem: } $$M_{aX}(t) = M_X(at)$$\n\n\\paragraph{Sum Theorem: } If $\\{X_1, X_2, ..., X_n\\}$ are independent random variables and $Y = \\sum X_n$, then $$M_Y(t) = M_{X_1}(t)M_{X_2}(t)...M_{X_n}(t)$$\n\n\\subsection{Linear Combinations of Random Variables}\n\nWe let $Y = a_1X_1 + a_2X_2$ where both $X$ are nomrally distributed with each having a $\\mu, \\sigma$. We first find that \n\n$$M_Y(t) = M_{X_1}(a_1t)M_{X_2}(a_2t)$$\n$$M_Y(t) = \\exp[(a_1\\mu_1 + a_2\\mu_2) t + (a_1^2\\sigma_1^2 + a_2^2 \\sigma_2^2)t^2/2]$$\n\nHence the mean is $\\mu = a_1\\mu_1 + a_2 \\mu_2$, variance is $\\sigma = a_1^2 \\sigma_1^2 + a_2^2 \\sigma_2^2$. \n\n\n\\paragraph{Theorem: } Expanding for $n$ summed normal distributions (independent), we get: \n\n$$\\mu_Y = \\sum a_i\\mu_i$$\n$$\\sigma_Y^2 = \\sum a_i^2 \\sigma_i^2$$\n\n\\paragraph{Chi Square Addition Theorem: } If $X_n$ each are mutually independent RV's with chi square distributions with $v_n$ degrees of freedom respectively, then \n\n$$Y = \\sum X_n$$\n\nIs yet another chi-squared distribution with $v = \\sum v_n$ degrees of freedom. \n\n\\paragraph{Corrolary: Normal Sum to Chi-Square: } Each $X_n$ are independent RV's with identical normal distributions (same $mu$, $\\sigma$). Then \n\n$$Y = \\sum_{i = 1}^{n} (\\frac{X_i - \\mu}{\\sigma})^2$$\n\nhas a chi-squared distribution with $v = n$.\n\n\\paragraph{Corrolary: Expanded Normal Sum to Chi-Squared: } Now each of the $X_n$ RV's can have different means and standard deviations. Now \n\n$$Y = \\sum_{i = 1}^{n} (\\frac{X_i - \\mu_i}{\\sigma_i})^2$$\n\nhas a chi-squared distribution with $v = n$. \n\n\n\n\n\n\n\\chapter{Introductory Statistics and Data Analysis Topics}\n\n\\section{Overview: Statistical Inference and Probability}\n\n\\paragraph{Vocabulary} \n\n\\begin{itemize}\n\\item \\textbf{Inferential statistics}: A toolbox for making scientific judgements in the face of variablility and uncertainty.\n\\item \\textbf{Sources of variation} \n\\item \\textbf{Samples}: Collections of \\textit{observations}. \n\\item Two main types of studies: observational and controlled.\n\\item \\textbf{Descriptive statistics}: Used when you want a summary of a dataset. Measures of central tendency, variation, etc.\n\\end{itemize}\n\n\\paragraph{P-Values} \n\nLet's say that a process yields 10 defective components out of 100 sampled ones. If we say that the \\textbf{maximum acceptable error rate} is 5\\%, we can calculate that the probability that 10 or more out of 100 were defective would be $0.002$ if the true error rate was 5\\%. That is our P-value for an error rate of 5\\%. From this, we learn that the probability that we are actually OK in terms of true error rate is incredibly small.\n\n\nP-values can also be used when one wants to know whether or not there is a statistical difference between observations on two population. It can measure \\textbf{the probability that these results would be obtained if there were no true difference}. \n\n\\paragraph{Probability vs. Statistical Inference} \n\nInferential statistics uses probability theory to draw conclusions about a dataset. \n\nProbability theory lets you draw conclusions about hypothetical data that you know some features about in a deductive fashion.\n\nYou are taught probability theory first to substantiate the algorithms in statistical theory.\n\n\n\n\\section{Sampling Procedures and Data Collection}\n\n\\paragraph{Simple Random Sampling}\n\nCharacterized by each sample within a set having \\textbf{equal likelihood} of being sampled. Usually is the gold standard for mitigating bias, but it is sometimes advantageous to use other sampling methods. \\textit{Stratified random sampling} is used when the population isn't homogenous and consists of \\textit{strata} -- non-overlapping groups. With stratified random sampling, you would perform random sampling on each stratum. \n\n\\paragraph{Experimental Design} \n\n\\begin{itemize}\n\\item \\textbf{Treatments}: Different groups in an experiment can be subjected to treaments or treatment combinations.\n\\item \\textbf{Experimental unit}: The different groups in an experiment.\n\\item \\textbf{Completely Randomized Design}: Participants are assigned to experimental groups entirely at random. Done to make sure that extraneous characteristics of each group do not overpower the treatment in question.\n\\end{itemize}\n\n\\section{Measures of Location: Mean and Median}\n\\paragraph{Definition: } Sample Mean $\\bar{x}$ is given by \n\n$$\\bar{x} = \\sum_{i=1}^n x_i/n$$\n\n\\paragraph{Definition: } Sample Median is given by the following assuming that $x_1, ..., x_n$ are arranged in INCREASING ORDER.\n\n$$\\tilde{x} = x_{(n+1)/2};\\,\\,\\,\\,\\,\\,\\text{if $n$ is odd}$$\n$$\\tilde{x} = \\frac{1}{2} (x_{n/2} + x_{n/2+1})\\,\\,\\,\\,\\,\\text{if $n$ is even}$$\n\n\\section{Measures of Variability}\n\n\\paragraph{Sample Variance: } Represented by $s^2$ is given by:\n$$s^2 = \\sum_{i = 1}^n \\frac{(x_i - \\bar{x})^2}{n-1}$$\n\n\\paragraph{Sample Standard Deviation: } Denoted by $s$, given by: \n\n$$s = \\sqrt{s^2}$$\n\nThe $n-1$ is often called the \\textbf{degrees of freedom associated with the variance} estimate.\n\n\\section{Statistical Modeling, Scientific Inspection, and Graphical Diagnostics}\n\n\\textit{The section on continuous vs. discrete data was foregone as it is a relatively simple distinction.} \n\n\\textbf{Postulated model: } Often at the end of analysis, the parameters of a \\textit{postulated model} are revealed. We can also do graphical analysis: \n\n\\begin{itemize}\n\\item \\textbf{Scatter plot: } If you don't know what a scatter plot is, you have some problems.\n\\item \\textbf{Stem-and-Leaf plot: } Left column is everything except for the ones place. The right column is the ones place for each sample.\n\\end{itemize}\n\n\n\\chapter{Fundamental Sampling Distributions and Data Descriptions}\n\n\\section{Random Sampling}\n\n\\paragraph{Populations and Samples} \n\n\\textbf{Population: } The `totality' of all the observations we are interested in. \\textit{Size} is determined by the number of observations in the population. \n\n\\textbf{Sample: } A subset of the population.\n\nWe make inferences from the samples to the populations. To ensure the validity of these inferences, we need to make sure that the sample selection protocol was \\textbf{unbiased}. \n\n\\paragraph{Random Sampling: } When observations are made independently and at random. \n\nWe let each $X_i$ represent the $i$th sampling from the population. $X_1, ..., X_n$ constitute a \\textit{random sample} from the population with values $x_1,...,x_n$. If $f(x)$ is the probability distribution function and all the measurements that comprise the random sample are independent, we can make a \\textbf{joint probability distribution} function to determine the probability of a collecting a given random sample: \n\n$$f(x_1, ..., x_n) = f(x_1)f(x_2)...f(x_n)$$\n\n\\section{Important Statistics}\n\n\\paragraph{Definition: } A \\textbf{statistic} is any function of the random variables that make up a random sample.\n\n\n\n\\section{Sampling Distributions}\n\n\\paragraph{Definition: } The \\textbf{sampling distribution} is the probability distribution of a \\textit{statistic}. \n\n\n\\section{Sampling Distribution of Means and the Central Limit Theorem}\n\n\\paragraph{Sampling Distribution of $\\bar{X}$} \n\nWe assume $n$ samples were taken from a \\textit{normal population} with mean $\\mu$ and variance $\\sigma^2$. From our established theorems, we get: \n\n$$\\bar{X} = \\frac{1}{n} \\sum X_i$$\n$$\\mu_{\\bar{X}} = \\frac{1}{n} (\\mu + \\mu + \\mu + ...) = \\mu$$\n$$\\sigma^2_{\\bar{X}} = \\frac{1}{n^2} (\\sigma^2 + \\sigma^2 + ...) = \\sigma^2/n$$\n\n\\paragraph{Central Limit Theorem: } If $\\bar{X}$ is the mean from $n$ samples from a normal population with distribution $mu$, $\\sigma^2$, then the limiting form of the distribution \n\n$$Z = \\frac{\\bar{X} - \\mu}{\\sigma/\\sqrt{n}}$$ \n\nas $n \\to \\infty$ is the standard normal $n(z; 0, 1)$. This is generally good for $n \\geq 30$ if the distribution isn't too skewed. Perfect regardless of $n$ if the sampled distribution is perfectly normally distributed. \n\n\\subsection{Inferences on the Population Mean}\n\nThe central limit theorem is very useful for inferring information about the true distribution of a stochastic process from $n$ samplings. It's pretty clear how this would be applied -- if you take a sample of size $n$ and you determine some average $\\bar{x}$, you can take the integral of the \\textbf{sampling distribution} for $\\bar{X}$ with the lower or upper bound as $\\bar{x}$ to determine the probability that the true mean is $\\mu$. \n\n\\subsection{Sampling Distribution between Two Means}\n\nWe want to compare two populations $X_1, X_2$ that have, respectively, $\\bar{X}_1, \\bar{X}_2, \\sigma_1, \\sigma_2, \\mu_1, \\mu_2$. We take a sample of size $n_1, n_2$ from each population, we want to find statistics about $\\bar{X}_1 - \\bar{X}_2$: \n\n$$\\mu_{\\bar{X}_1 - \\bar{X}_2} = \\mu_{\\bar{X}_1} - \\mu_{\\bar{X}_2} = \\mu_1 - \\mu_2$$\n$$\\sigma^2_{\\bar{X}_1 - \\bar{X}_2} = \\sigma^2_{\\bar{X}_1} + \\sigma^2_{\\bar{X}_2} = \\frac{\\sigma^2_1}{n_1} + \\frac{\\sigma^2_2}{n_2}$$\n\nThe following equation, therefore, approximates the standard normal $Z$: \n\n$$Z = \\frac{(\\bar{X}_1 - \\bar{X}_2) - (\\mu_1 - \\mu_2)}{\\sqrt{(\\sigma_1^2/n_1) + (\\sigma_2^2/n_2)}}$$\n\nAs again, this approximation generally works best when $n \\geq 30$. \n\n\\section{Sampling Distribution of $S^2$}\n\n\\textit{Notation: $S^2$ is the variance of a sample from a distribution. $\\sigma^2$ is the true variance of the random variable.}\n\n\\paragraph{Theorem: } If we take a sample of size $n$ from a population that is known to have variance and mean $\\sigma, \\mu$ and we get a measured variance of $S^2$ from our sample, then\n\n$$\\chi^2 = \\frac{(n-1)S^2}{\\sigma^2} = \\sum_{i = 1}^{n} \\frac{(X_i - \\bar{X})^2}{\\sigma^2}$$\n\nis a chi-squared distribution with $v = n-1$ degrees of freedom.\n\nYou can calculate the value of $\\chi^2$ for a given sample by $\\chi^2 = \\frac{(n-1)s^2}{\\sigma^2}$. The chance that a $\\chi^2$ value greater than or equal to the one returned by that function can be found via some tables that integrate the chi-squared probability density function. \n\nThe common method of interpreting this is as follows: Since 95\\% of the chi-square function falls between $\\chi^2_{0.025}$ and $\\chi^2_{0.975}$. Your steps to solving a problem of this type are as follows:\n\n\\begin{enumerate}\n\\item Calculate the variance of the sample $s^2$.\n\\item Assuming that the initial distribution was normal, use the given value of $\\sigma^2$ to calculate $\\chi^2$ using one of the above formulae: \n\\item Depending on the number of degrees of freedom $v = n-1$, determine if the calculated $\\chi^2$ falls in that 95\\% region. If it does, the current value of $\\sigma^2$ is fine!\n\\end{enumerate}\n\n\n\\section{$t$-Distribution}\n\nThe \\textit{central limit theorem} assumes that you know the true $\\sigma$ of the process you are dealing with. This isn't always the case, so $t$-distributions allow you to get roughly the same functionality as the central limit theorem by approximating the true $\\sigma$ with the $s$ value of the sample.\n\n$$T = \\frac{\\bar{X} - \\mu}{S/\\sqrt{n}}$$\n\nA small sample size makes $S \\neq \\sigma$ very likely, so the $t$-distribution deviates substantially from the standard normal. \n\n\\paragraph{$t$-distribution Theorem: } $Z$ is the standard normal. $V$ is a chi-squared random variable with $v$ degrees of freedom. $Z, V$ are independent. Then the random variable $T$ is given by \n\n$$T = \\frac{z}{\\sqrt{V/v}}$$\n\nhas the probability density function\n\n$$h(t) = \\frac{\\Gamma[(v+1)/2]}{\\Gamma(v/2)\\sqrt{\\pi v}} (1 + \\frac{t^2}{v})^{-(v+1)/2}, \\,\\,\\, -\\infty < t < \\infty$$\n\nThe utility of this is the following: \n\n\\paragraph{Utility of $t$-distribution: } If $X_1, X_2, ..., X_n$ are random variables with a mystery shared $\\mu, \\sigma$, and we lett \n\n$$\\bar{X} = \\frac{1}{n} \\sum_{i = 1}^n X_i  $$\n\n$$S^2 = \\frac{1}{n-1} \\sum_{i = 1}^n (X_i - \\bar{X})^2$$\n\nThen we get \n\n$$T = \\frac{\\bar{X} - \\mu}{S/\\sqrt{n}}$$\n\nThat has a $t$-distribution with $v = n-1$ degrees of freedom.\n\n\\paragraph{Using the $t$-distribution: } \n\\begin{itemize}\n\\item Basically looks the same as a normal distribution, is a bit wider because of greater variance in values. \n\\item $t_\\alpha$ represents the value of $t$ above which there is an area of $\\alpha$. \n\\item $t$-distributions are symmetrical about zero. Therefore, $t_{1-\\alpha} = -t_\\alpha$. \n\\item 95\\% of the $t$-distribution lies between $-t_0.025$ and $t_0.025$. \n\\end{itemize}\n\n\n\\section{$F$-distribution}\n\n$t$-distributions is really useful for comparing the \\textit{means} of two populations when you also don't know the variance of either. $F$-distributions are really useful for comparing the \\textit{variances} of two populations when you have limited information. \n\n\\paragraph{$F$-distribution Theorem: } $U$ and $V$ are chi-squared distributions with $v_1, v_2$ degrees of freedom respectively. The probability distribution of random variable $F$\n\n$$F = \\frac{U/v_1}{V/v_2}$$\n\nis\n\n$$h(f) = \\frac{\\Gamma[(v_1+v_2)/2](v_1/v_2)^{v_1/2}}{\\Gamma(v_1/2)\\Gamma(v_2/2)} \\frac{f^{(v_1/2)-1}}{(1+v_1f/v_2^{(v_1 + v_2)/2})}$$\n\nfor values of $f \\geq 0$. \n\nAs per usual, $f_\\alpha$ represents the value of $f$ where the area above that value is equal to $\\alpha$. A convenient switching theorem is: \n\n$$f_{1-\\alpha}(v_1, v_2) = \\frac{1}{f_\\alpha(v_2, v_1)}$$\n\n\\subsection{$F$-distribution with Two Sample Variances}\n\nSamples of size $n_1, n_2$ are selected from populations with $\\sigma_1^2, \\sigma_2^2$ respectively. From our established theorems on chi-squared relationships with randomly selected values from normal distributions, \n\n$$\\chi_1^2 = \\frac{(n_1 - 1)S_1^2}{\\sigma_1^2}; \\,\\,\\,\\, \\chi_2^2 = \\frac{(n_2 - 1)S_2^2}{\\sigma_2^2}$$\n\nare chi-squared distributions with $v_1 = n_1 - 1, v_2 = n_2 - 1$ degrees of freedom respectively. We let $X_1^2 = U$ and $X_2^2 = V$. From there we get this very applicable result: \n\n\\paragraph{Comparing sample variances of independent random variables: } \n\n$$F = \\frac{S_1^2/\\sigma_1^2}{S_2^2 / \\sigma_2^2} = \\frac{\\sigma_2^2 S_1^2}{\\sigma_1^2 S_2^2}$$\n\nhas an $F$-distributtion with $v_1 = n_1 - 1$ and $v_2 = n_2 - 1$ degrees of freedom. \n\n\n\n\\section{Quantile and Probability Plots}\n\n\\subsection{Quantile Plots}\n\n\\paragraph{Definition: } the quantile of a sample $q(f)$ is the value for which the fraction $f$ of the provided data is less than. $f$ goes from 0-1. $q(0.1)$ returns a number $q$. $P(F < q) = f$, you could think about it as. \n\n\\subsection{Normal Quantile-Quantile Plot}\n\n\\textit{The rest of this note has been excluded as the syllabus has been revised to only include 8.1-6.}\n\n\n\\chapter{One and Two-Sample Estimation Problems}\n\nThis chapter deals with statistical inference and estimating population parameters. Estimation procedures discussed will only involve one and two samples. \n\n\\section{Statistical Inference}\n\nThe classical approach to statistical inference is the \\textbf{classical method} where we directly infer the parameters of a population based on the data we gather. The \\textbf{Bayesian method} leverages prior knowledge about the population with gathered information to form conclusions about the data. \n\n\\paragraph{Estimation vs. hypothesis testing: } two main classes of statistical inferences. Estimation is a regression problem: you are trying to approximate some ground truth value from the world. Hypothesis testing is a boolean classification problem where you are trying to determine the validity of a conjecture. \n\n\\section{Classical Method of Estimation}\n\n\\paragraph{Point estimate: } A single actual value of a theoretical statistic. For the statistic $\\bar{X}$ (the average), $\\bar{x}$ is the point estimate. $\\bar{x}$ is based off of some $n$ readings and approximates some actual true fact about the distribution.\n\n\\paragraph{Unbiased estimator: } If an estimator has a mean equal to the parameter being approximated, then it is \\textbf{unbiased}. $$\\mu_{\\hat{\\Theta}} = E(\\hat{\\Theta} = \\theta$$\n\nWhere $\\hat{\\Theta}$ is the estimator and $\\theta$ is the true value.\n\n\\paragraph{Estimator efficiency: } If two estimators approximate the same true population parameter $\\theta$ and are \\textbf{unbiased}, then the one with the lower variance is the \\textbf{more efficient estimator.} \n\n\\paragraph{Interval Estimation: } This is exactly what it sounds like. It is an estimation of the interval between which one is likely to find the true value of a population parameter.\n\n$$\\hat{\\theta_L} < \\theta < \\hat{\\theta_U}$$\n\nThe length of an interval estimation indicates the accuracy of the central point measurement. \n\n\\paragraph{Interpreting Interval Estimates: } The actual values $\\hat{\\theta}_L, \\hat{\\theta}_U$ correspond to random variables $\\hat{\\Theta}_{L,U}$ such that \n\n$$P(\\hat{\\Theta}_L < \\theta < \\hat{\\Theta}_U) = 1-\\alpha$$\n\nWhere $100(1-\\alpha)$\\% is the \\textbf{confidence interval} and $1-\\alpha$ is the \\textbf{confidence coefficient/degree of confidence}. The lower and upper bounds are the \\textbf{confidence limits}. \n\n\\section{Single Sample: Estimating the Mean}\n\\begin{itemize}\n\\item Sampling distribution of $\\bar{X}$ has center $\\mu$ and is generally the best estimator of $\\mu$. \n\\item $\\bar{x}$ is the \\textbf{point estimate}. \n\\item $\\sigma_{\\bar{X}}^2 = \\sigma^2/n$\n\\item We can construct the \\textbf{confidence interval} for our estimate of $\\mu$ based on the sampling distribution of $\\bar{X}$\n\\end{itemize}\n\n\\paragraph{Confidence Interval on $\\mu$ if $\\sigma^2$ is known: } $\\bar{x}$ is the mean of a random sample size $n$ from a population with known variance $\\sigma^2$. A confidence interval of $100(1-\\alpha)$\\% for approximating $\\mu$ isgiven by: \n\n$$\\bar{x} - z_{\\alpha/2}\\frac{\\sigma}{\\sqrt{n}} < \\mu < \\bar{x} + z_{\\alpha/2} \\frac{\\sigma}{\\sqrt{n}}$$\n\nWhere $z_{\\alpha/2}$ is a $z$-value that leaves area $\\alpha/2$ to the right.\n\nGood results are guaranteed by this theory assuming $n \\geq 30$ and the distribution is not very skewed.\n\nA nice resultant theorem is as follows: \n\n\\paragraph{Theorem on Error of $\\mu$ approximation: } If $\\bar{x}$ is used as an estimate of $\\mu$, our confidence is $100(1-\\alpha)$\\% that the error of our estimate will not exceed $z_{\\alpha/2}\\frac{\\sigma}{\\sqrt{n}}$. \n\n\\paragraph{Inverse Theorem on $\\mu$ approximation: } If we want to confine error to $e$ with $100(1-\\alpha)$\\% confidence for our estimate $\\bar{x}$ of $\\mu$, our number of samples must be: \n\n$$n = (\\frac{z_{\\alpha/2} \\sigma}{e})^2$$\n\n\n\\subsection{One-Sided Confidence Bounds}\n\nBy the central limit theorem: \n\n$$P(\\frac{\\bar{X} - \\mu}{\\sigma/\\sqrt{n}} < z_\\alpha) = 1 - \\alpha$$\n\nWhich can be manipulated to...\n\n$$P(\\mu < \\bar{X} + z_\\alpha \\sigma / \\sqrt{n}) = 1-\\alpha$$\n\n\\subsection{Case of Unknown $\\sigma$}\n\nRecall the T-distribution: \n\n$$T = \\frac{\\bar{X} - \\mu}{S/\\sqrt{n}}$$\n\nThe random variable $T$ has a $t$-distribution with $n-1$ degrees of freedom. $S$ represents the sample standard deviation. Now we can use the $T$ distribution to construct our confidence intervals, replacing the normal distributions from before with $T$ distributions: \n\n$$P(-t_{\\alpha/2} < T < t_{\\alpha/2}) = 1-\\alpha$$\n\n\n$$P(-t_{\\alpha/2} < \\frac{\\bar{X} - \\mu}{S/\\sqrt{n}} < t_{\\alpha/2}) = 1-\\alpha$$\n\n$$P(\\bar{X} - t_{\\alpha/2}\\frac{S}{\\sqrt{n}} < \\mu < \\bar{X} + t_{\\alpha/2}\\frac{S}{\\sqrt{n}}) = 1-\\alpha$$\n\n\n\\paragraph{Theorem on confidence interval on $\\mu$ with $\\sigma^2$ unknown: } $\\bar{x}, s$ are the sample mean and standard deviation. The $100(1-\\alpha)$\\% confidence interval for $\\mu$ is: \n\n$$\\bar{x} - t_{\\alpha/2} \\frac{s}{n} < \\mu < \\bar{x} + t_{\\alpha/2}\\frac{s}{\\sqrt{n}}$$\n\nwhere $t_{\\alpha/2}$ is the value on the $t$ distribution of $v = n-1$ degrees of freedom that has an area of $\\alpha/2$ to the right.\n\n\\paragraph{Large-Sample Confidence Intervals: } \n\nIf $n \\geq 30$, it is recommended that $s$ can replace $\\sigma$, so \n\n$$\\mu \\approx \\bar{x} \\pm z_{\\alpha/2}\\frac{s}{\\sqrt{n}}$$\n\nThis is known as the \\textit{large-sample confidence interval}. \n\n\n\n\\section{Standard Error on a Point Estimate}\n\nWe now equate the \\textbf{standard deviation} of an estimator with the \\textbf{standard error} of the estimator (notated as $\\text{s.e.}(\\hat{\\theta})$. We write: \n\n$$\\bar{x} \\pm z_{\\alpha/2}\\frac{\\sigma}{\\sqrt{n}} = \\bar{x} \\pm z_{\\alpha/2} \\text{s.e.}(\\bar{x})$$\n\n\n\n\n\\section{Prediction Intervals}\n\nThe intervals we have gone through so far are about our confidence that our \\textbf{mean value} that we calculated based off of some observations is the correct one. This is appreciably different from when we have to figure out our confidence that an individual component is defective or not as the latter depends heavily on the standard deviation of the population.\n\n\\paragraph{Prediction interval of Future Observation ($\\sigma$ is known): } A $100(1-\\alpha)$\\% \\textbf{prediction interval} of a future observation $x_0$ for a population that has an \\textit{unknown mean $\\mu$} and \\textit{known variance $\\sigma^2$} is: \n\n$$\\bar{x} - z_{\\alpha/2}\\sigma \\sqrt{1 + 1/n} < x_0 < \\bar{x} + z_{\\alpha/2}\\sigma\\sqrt{1+1/n}$$\n\n\\textit{Where $z_{\\alpha/2}$ is the $z$-value leaving area $\\alpha/2$ to the right.} \n\n\\paragraph{Prediction interval of Future Observation, $\\sigma^2$ is unknown: } \n\n$$\\bar{x} - t_{\\alpha/2} s \\sqrt{1 + 1/n} < x_0 < \\bar{x} + t_{\\alpha/2} s \\sqrt{1+1/n}$$\n\n\\textit{Where $t_{\\alpha/2}$ is the $t$-value with $v = n-1$ degrees of freedom that leaves $\\alpha/2$ to the right.}\n\n\n\\paragraph{One-sided predictions: } Upper bound is $\\bar{x} + t_\\alpha s \\sqrt{1+1/n}$ and the lower bounded one-sided prediction would be $\\bar{x} - t_\\alpha s \\sqrt{1+1/n}$. \n\n\n\\subsection{Prediction Limits for Outlier Detection}\n\n\\paragraph{Outlier detection rule: } An observation is an outlier if it falls outside the prediction interval computed without including the questionable observation in the sample.\n\n\\section{Cramer-Rao Lower Bounds}\n\nThe goal here is to establish that, for any unbiased estimator ($E(\\hat{\\theta}) = \\theta$), the variance of the estimator is always greater than some lower bound called the \\textbf{Cramer-Rao lower bound} \n\n\\paragraph{CRLB Theorem: } If the joint pdf satisfies the regularity condition \n\n$$E(\\frac{\\partial}{\\partial \\theta} \\ln f(x, \\theta)) = 0$$\n\nThen for \\textbf{any} unbiased estimator we have the \\textbf{lower bound} \n\n$$\\text{var} \\hat{\\theta} \\geq \\frac{-1}{E[\\frac{\\partial^2}{\\partial \\theta^2} ln f(x; \\theta)]}$$\n\n\n\\chapter{One and Two-Sample Tests of Hypotheses}\n\n\\section{Statistical Hypotheses: General Concepts}\n\n\\paragraph{Statistical Hypothesis: } an assertion or conjecture concerning one or more populations.\n\n\\paragraph{Role of Probability in Hypothesis Testing} \n\\begin{itemize}\n\\item The rejection of a hypothesis implies evidence that refutes it. \n\\item Rejection implies that, if the if the hypothesis was true, there was a small probability of making the observation in question.\n\\item \\textbf{That being said,} failure to reject the hypothesis does not rule out any possibilities.\n\\item Therefore, if you want to \\textbf{strongly support} some conclusion, you should do so via the rejection of a hypothesis.\n\\end{itemize}\n\n\\paragraph{Null and Alternative Hypothesis} \n\n\\textbf{Null hypothesis: } any hypothesis $H_0$ we wish to test. Rejection results in the \\textbf{acceptance of the alternative hypothesis} $H_1$, which is usually the actual question we want answered. Your two possibilities for the result of your experiment include:\n\n\\begin{enumerate}\n\\item \\textbf{Reject $H_0$ } in favour of $H_1$ because of sufficient evidence. \n\\item \\textbf{Fail to reject $H_0$ } because of insufficient evidence in data.\n\\end{enumerate}\n\n \n\\section{Testing a Statistical Hypothesis}\n\n\\paragraph{Test Statistic: } The number we measure in order to make our final decision about the hypothesis. \n\n\\paragraph{Critical region: } Values of our test statistic that would result in the rejection of the null hypothesis. \n\n\\paragraph{Critical value: } Boundary number between criticla region and non-critical region.\n\n\\subsection{Probability of a Type I Error}\n\n\\paragraph{Type I error: } when you incorrectly reject the null hypothesis.\n\n\\paragraph{Type II error: } when you fail to reject the null hypothesis even though the null hypothesis is actually false.\n\n\\begin{tabular}{|| r | l | l ||}\n\\hline\n& \\textbf{$H_0$ is true} & \\textbf{$H_0$ is false} \\\\\n\\hline\n\n\\textbf{Do not Reject $H_0$} & Correct & Type II Error \\\\\n\n\\textbf{Reject $H_0$} & Type I Error & Correct \\\\\n\n\\hline\n\\end{tabular}\n\n\n\\paragraph{Level of Significance: } The probability of a type I error $\\alpha$\n\nIn th example of testing whether a new vaccine is better than the old one that only works for a quarter of the people after two years: \n\n$$\\alpha = P(\\text{type I error}) = P(X > 8 \\,\\text{when}\\, p = \\frac{1}{4}) = \n\\sum_{x=9}^{20} b(x;20, \\frac{1}{4}) = 1 - 0.9591 = 0.0409$$\n\nWe say that \\textit{we are testing the null hypothesis at the $\\alpha = 0.0409$ level of significance} (a.k.a. \\textit{size of test}). Since this value is very small, it is unlikely that a type I error will be committed. \n\n\\paragraph{Probability of a Type II Error: } denoted by $\\beta$, is \\textbf{impossible to compute unless there is a specific laternative hypothesis}. In the case of the vaccine testing experiment, our alternative hypothesis would have to take on the form $p = p_0$ (let say $p = \\frac{1}{2}$ for the example...) \n\n$$\\beta = P(\\text{type II error}) = P(X \\leq 8 \\, \\text{when} p = \\frac{1}{2})$$\n$$\\beta = \\sum_{x=0}^8 b(x; 20, \\frac{1}{2}) = 0.2517$$\n\nThis is a pretty large value because it is likely that, even if the vaccine works twice as well as the old one, we will risk accepting the null hypothesis. Ideally we obviously want low $\\alpha, \\beta$\n\nWe can adjust $\\alpha, \\beta$ by changing our critical value. We can also decrease both simutlaneously by increasing our sample size.\n\n\\paragraph{Power: } The power of a test is the \\textit{probability of rejecting $H_0$} in the case that a specific alternative hypothesis is true, $= 1-\\beta$. \n\n\\textit{Example: } We have a population and our null hypothesis is that the mean is NOT 68. That makes $H_1: \\, \\mu \\neq 68$. Ourvalue for $\\beta$ when our alternative hypothesis is set to $\\mu = 68.5$ is $\\beta = 0.8661$, making the \\textbf{power} $1-0.8661 = 0.1339$. We then say that \\textbf{our test will properly reject $H_0$ only 13.39\\% of the time if the true mean is 68.5}. \n\n\\subsection{One- and Two-Tailed Tests}\n\nIf the hypotheses are of the form\n\n$$H_0:\\,\\, \\theta = \\theta_0; \\,\\,\\, H_1: \\,\\, \\theta > \\theta_0$$\n\nthen it is a \\textbf{one-tailed} test. The critical region is in one tail of the distribution, whether it is the right tail or left tail.\n\n\nIf the hypotheses are of the form \n\n$$H_0:\\,\\, \\theta = \\theta_0 \\,\\,\\, H_1: \\,\\, \\theta \\neq \\theta_0$$\n\nthen it is a \\textbf{two-tailed} test for similar reasons as described above.\n\n\n\\paragraph{Choosing a Null and Alternative Hypothesis} \n\n\\begin{itemize}\n\\item $H_0$ often has an \\textit{equals sign}. \n\\item Make sure that you select the right number of tails -- if it is important to detect when something is both super or inferior, use two-tailed.\n\\end{itemize}\n\n\n\\section{$P$-Values for Decision making in Testing Hypotheses}\n\nIt is customary to use $\\alpha$ values of $0.05$ or $0.01$ to select the critical region. If we go with $\\alpha = 0.05$ and we have a two-tailed test involving the standard normal, then our critical region would be $$z > 1.96 \\text{ or } z < -1.96$$\n\nBecause $z_{0.025} = 1.96$ and we need to split the $\\alpha = 0.05$ across both tails. \n\nThe dogmatic obsession with $P$-values of $\\alpha = 0.05$ doens't always make sense -- if you need to adjust your $P$-value to $0.06$, you aren't really increasing your probability of committing a type I error that much. It's good practice to show calculate the P-value that would be required to reject the null hypothesis no matter what your initial conclusion is with a conventional P-value of 0.01 or 0.05.\n\n\\paragraph{$P$-Value Definition: } $P$ is the lowest possible value of significance $\\alpha$ at which the observed value of the test statistic is considered significant.\n\nThe $P$-value approach is considered more modern than the fixed-$\\alpha$ approach. Here are the procedural steps to follow for classical and $P$-value approach.\n\n\\paragraph{Classical Fixed-$\\alpha$} \n\n\\begin{itemize}\n\\item State null and alternative hypotheses.\n\\item Choose a fixed level of signficance $\\alpha$.\n\\item Choose an appropriate test statistic to establish critical region on $\\alpha$\n\\item Reject $H_0$ if the test statistic is in the critical region. Otherwise, do not reject.\n\\item Draw conclusions.\n\\end{itemize}\n\n\\paragraph{$P$-value approach} \n\n\\begin{itemize}\n\\item State null and alternative hypothesis.\n\\item Select test statistic.\n\\item Compute the $P$-value based on computed value of test statistic.\n\\item Use your judgement of the $P$-value to draw conclusion.\n\\end{itemize}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Not-In-Textbook}\n\\begin{itemize}\n\\item \\textbf{Q-Function}: Let Z be standard normal. We define the Q-function as $Q(z) = P(Z>z) = \\int_z^{\\infty} \\frac{1}{\\sqrt{2\\pi}} e^{t^2/2}dt$. \n\\end{itemize}\n\n\\chapter{Logistics}\n\n\\section{Midterm I}\n\\begin{itemize}\n\\item Date: Thursday, March 5. \n\\item Covers chapters 2-5.\n\\end{itemize}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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": "765791ffd9eaaaf65d3df79f397c2988d586a4e3", "size": 60244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/ECE286.tex", "max_stars_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_stars_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-10-25T06:03:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T02:14:13.000Z", "max_issues_repo_path": "tex/ECE286.tex", "max_issues_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_issues_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_issues_repo_licenses": ["MIT"], "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/ECE286.tex", "max_forks_repo_name": "AdamCarnaffan/EngSci_Abridged", "max_forks_repo_head_hexsha": "de733823c493d35689cfcd846f87a47e0b05331c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-05T14:21:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T19:01:31.000Z", "avg_line_length": 43.4347512617, "max_line_length": 440, "alphanum_fraction": 0.7062114069, "num_tokens": 18278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6173508304458734}}
{"text": "% Copyright 2021 Google LLC\n%\n% Use of this source code is governed by an MIT-style\n% license that can be found in the LICENSE file or at\n% https://opensource.org/licenses/MIT.\n\n%!BIB program = biber\n%!TeX program = lualatex\n%!TeX spellcheck = en-US\n\n\\documentclass[hctr2.tex]{subfiles}\n\\begin{document}\n\\section{Optimization of POLYVAL}\\label{polyvalimpl}\nThe polynomial hash function is where the bulk of optimizations must be done. A naive partially-optimized implementation of $H$ is slower than XCTR mode. We use several optimization techniques to increase the efficiency of $H$. We show several methods to increase the parallelism of $H$ and to reduce the number of slow instructions required to compute it. With these optimizations in place, the polynomial hash function becomes significantly faster than XCTR mode.\n\n\\subsection{Precomputed powers}\nSince $\\hgen$ is constant during hashing, powers of $\\hgen$ can be precomputed to avoid excess multiplications. \n\\begin{algorithm}[H]\n\\caption{Fixed width polynomial evaluation}\\label{polykalg}\n\\begin{algorithmic}[1]\n\t\\Require $M$ is exactly $k$ blocks long.\n\t\\Require $\\hgen^1$, $\\cdots$, $\\hgen^{k-1}$ have been precomputed.\n\t\\Procedure{PolyK}{$M$}\n\t\t\\State $poly \\gets 0^{128}$\n\t\t\\State $i \\gets 0$\n\t\t\\For{$i \\le k$}\n\t\t\\State $poly \\gets poly \\oplus \\hgen^{k-1-i}M[ni:n]$\n\t\t\\EndFor\n\t\t\\State \\textbf{return} $poly$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nThe subroutine \\texttt{PolyK} allows $k$ blocks to be efficiently hashed at once. By adapting Horner's method, we can use \\texttt{PolyK} as a subroutine to efficiently compute $poly(M)$.\n\n\\begin{algorithm}[H]\n\\caption{Polynomial evaluation}\\label{polyalg}\n\\begin{algorithmic}[1]\n\t\\Require $|M|$ is a multiple of block size.\n\t\\Require $\\hgen^1$, $\\cdots$, $\\hgen^{k}$ have been precomputed.\n\t\\Procedure{Poly}{$M$}\n\t\t\\State $poly \\gets 0^{128}$\n\t\t\\State $i \\gets 0$\n\t\t\\While{$|M| \\ge kn(i+1)$}\n\t\t\t\\State $poly \\gets poly*\\hgen^k \\oplus \\Call{PolyK}{M[ikn : kn]}$\n\t\t\t\\State $i \\gets i + 1$\n\t\t\\EndWhile\n\t\t\\State $m \\gets |M| - kni$\\Comment{$0 \\le m < k$}\n\t\t\\State $j \\gets 0$\n\t\t\\State $\\poly \\gets \\poly*\\hgen^m$\n\t\t\\While{$jn < m$}\n\t\t\\State $poly \\gets \\hgen^{m-j-1}M[ikn + jn : n]$\n\t\t\\EndWhile\n\t\t\\State \\textbf{return} $poly$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nNotice that each invocation of $\\texttt{PolyK}$ requires $k$ multiplications. Let $s$ be the number of invocations of \\texttt{PolyK} and $m = |M| \\bmod nk$. An invocation of \\texttt{Poly} requires $s(k+1) + m$ finite field multiplications. Since $s(k+1) + m$ is constant for any choice of $k$, we can use any choice of $k$ and retain the same number of multiplications required to compute \\texttt{Poly}. Furthermore, $\\texttt{PolyK}$ is parallelizable, so larger values of $k$ are preferred. Our implementation uses $k = 4$ for both x86-64 and ARM64.\n\n\\subsection{Hardware accelerated multiplication}\nFinite field multiplication for HCTR2 consists of two subroutines, polynomial multiplication and polynomial reduction. We use a well-known variant of Karatsuba multiplication for polynomial multiplication and a well-known variant of Barrett reduction for polynomial reduction \\cite{CLMUL}. We describe these algorithms for completeness.\n\nLet the input operands to polynomial multiplication be 128-bit polynomials $A, B$. We split $A, B$ into two 64-bit parts, $A = [A_1 : A_0]$, $B = [B_1 : B_0]$. Note that these values are assumed to be in registers, so the little-endian specification no longer applies. In other words, the lowest bit of $A_0$ is the constant term of $A$ and the highest bit of $A_1$ is the $x^{127}$ term. Let $clmul(X, Y)$ be the 128-bit carry-less product of two 64-bit operands. The following pseudocode describes Karatsuba multiplication for 128-bit polynomials $A, B$.\n\\begin{algorithm}[H]\n\\caption{Karatsuba multiplication for 128-bit polynomials}\\label{karatsuba}\n\\begin{algorithmic}[1]\n\t\\Require $A, B$ are 128-bit polynomials.\n\t\\Procedure{KaratsubaStep1}{A, B}\n\t\t\\State $C \\gets clmul(A_1, B_1)$\\Comment{$C = [C_1 : C_0]$}\n\t\t\\State $D \\gets clmul(A_0, B_0)$\\Comment{$D = [D_1 : D_0]$}\n\t\t\\State $E \\gets clmul(A_0 \\oplus B_0, A_1 \\oplus B_1)$\\Comment{$E = [E_1 : E_0]$}\n\t\t\\State \\textbf{return} $C, D, E$\n\t\\EndProcedure\n\t\\State\n\t\\Procedure{KaratsubaStep2}{C, D, E}\n\t\t\\State \\textbf{return} $[C_1 : C_0 \\oplus C_1 \\oplus D_1 \\oplus E_1 : D_1 \\oplus C_0 \\oplus D_0 \\oplus E_0 : D_0]$\n\t\\EndProcedure\n\t\\State\n\t\\Procedure{Karatsuba}{$A, B$}\n\t\t\\State $C, D, E \\gets \\Call{KaratsubaStep1}{A, B}$\n\t\t\\State \\textbf{return} $\\Call{KaratsubaStep2}{C, D, E}$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nWe now describe the polynomial reduction algorithm. This is the slight modification of the process described in \\cite{CLMUL}. This modification allows us to use carry-less multiplication instructions instead of bitshifts. Let $p(x) = [X_3 : X_2 : X_1 : X_0]$ be the $256$-bit operand. To compute the 128-bit reduction, we only need to reduce the upper 128-bit polynomial then XOR the reduction with the lower 128-bits. Let $c(x) = [X_3 : X_2]$ be the polynomial representing the upper 128-bits of the operand. Let $g(x)$ be the modulus and $g^*(x)$ be the lower 128-bits of the modulus. Since we assume the modulus to be $x^{128} + x^7 + x^2 + x + 1$, we have $g^*(x) = [\\text{0x0} : \\text{0x87}]$. Finally, let $q^+(x)$ be $x^{256}/g(x)$, in this case $q^+(x) = g(x)$. First we compute the 256-bit product of $q^+$ and $c(x)$ then discard the lower 128 bits. Let the operator $p(x) \\div x^{n}$ represent polynomial long division without remainder by $x^n$ or equivalently, bitshifting right by $n$.\n\\begin{gather*}\n       y(x) = q^+(x)c(x) = [Y_3 : Y_2 : Y_1 : Y_0]\\\\\n       y^*(x) = y(x) \\div x^{128} \\bmod x^{128} = [Y_3 : Y_2]\n\\end{gather*}\nHowever, notice in this case that\n\\begin{gather*}\n       y^*(x) = c(x)(x^{128} + g^*(x)) \\div x^{128} \\mod x^{128}\\\\\n       = [c(x)x^{128} + c(x)g^*(x)] \\div x^{128} \\mod x^{128}\\\\\n       = c(x) + (g^*(x)c(x) \\div x^{128}) \\mod x^{128}\n\\end{gather*}\nSince $deg(g^*(x)) < 64$ we have $deg(g^(x)c(x)) < 192$. Furthermore, since we wish to compute $g^*(x)c(x) \\div x^{128}$, we only need to compute the polynomial terms $a_{191}x^{192} + \\cdots + a_{127}x^{128}$. Therefore we have\n\\begin{align*}\n       (c(x) \\div x^{64})g^*(x) \\div x^{64} = g^*(x)c(x) \\div x^{128}\n\\end{align*}\nSubstituting this into our original equation gives:\n\\begin{gather*}\n       y^*(x) = c(x) + ((c(x) \\div x^{64})g^*(x)) \\div x^{64} \\mod x^{128}\\\\\n       = (c(x) \\div x^{64})(x^{64}) + (c(x) \\bmod x^{64}) + ((c(x) \\div x^{64})g^*(x)) \\div x^{64} \\mod x^{128}\n\\end{gather*}\nLet $t(x) = c(x) \\div x^{64}g^*(x)$. This gives\n\\begin{align*}\n       y^*(x) = (c(x) \\div x^{64})x^{64} + (c(x) \\text{ mod } x^{64}) + t(x) \\div x^{64} \\mod x^{128}\n\\end{align*}\nFurthermore, $t(x)$ is efficiently computable using carry-less multiplication.\n\\begin{align*}\n       t(x) = (c(x) \\div x^{64})g^*(x) = [T_1 : T_0] = clmul(X_3, \\texttt{0x87})\n\\end{align*}\nTo compute the final reduction of $c(x)$, we then multiply $y^*(x)$ by $g^*(x)$ and return the lowest 128 bits of the product.\n\\begin{align*}\n       r(x) = g^*(x)y^*(x) = t(x)x^{64} + g^*(x)\\left[(c(x) \\text{ mod } x^{64}) + (t(x) \\div x^{64})\\right]\n\\end{align*}\nFor simplicity let $z(x) = g^*(x)\\left[(c(x) \\text{ mod } x^{64}) + (t(x) \\div x^{64})\\right]$. Notice that this is also efficiently computable with carry-less multiplication.\n\\begin{align*}\n       z(x) = [Z_1 : Z_0] = clmul(X_2 \\oplus T_1,\\texttt{0x87})\n\\end{align*}\nSo our final computation of $r(x)$ is\n\\begin{align*}\n       r(x) = [T_0 \\oplus Z_1 : Z_0] \\oplus [X_1 : X_0]\n\\end{align*}\nThe following describes the same process in pseudocode.\n\\begin{algorithm}[H]\n\t\\caption{Barrett reduction modulo $x^{128} + x^7 + x^2 + x + 1$}\\label{barrett}\n\\begin{algorithmic}[1]\n\t\\Require $X$ is a 256-bit polynomial.\n\t\\Procedure{Barrett}{$X$} \\Comment{$X = [X_3 : X_2 : X_1 : X_0]$}\n\t\t\\State $T \\gets clmul(X_3, \\texttt{0x87})$\\Comment{$T = [T_1 : T_0]$}\n\t\t\\State $Z \\gets clmul(X_2 \\oplus T_1, \\texttt{0x87})$ \\Comment{$Z = [Z_1 : Z_0]$}\n\t\t\\State \\textbf{return} $[T_0 \\oplus Z_1 \\oplus X_1 : Z_0 \\oplus X_0]$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nCombining Karatsuba multiplication and Barrett reduction allows us to compute finite field multiplications.\n\\begin{algorithm}[H]\n\t\\caption{Naive GF128 Multiplication}\\label{GF128Naive}\n\\begin{algorithmic}[1]\n\t\\Require $A, B$ are 128-bit polynomials.\n\t\\Procedure{GF128}{$A, B$}\n\t\t\\State $P \\gets \\Call{Karatsuba}{A, B}$\n\t\t\\State $R \\gets \\Call{Barrett}{P}$\n\t\t\\State \\textbf{return} $R$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nThis approach greatly increases the speed of $H$, but it still has several problems. A single finite field multiplication requires 5 carry-less multiplications when implemented in this way, so an invocation to $\\texttt{PolyK}$ requires $5k$ carry-less multiplications. Furthermore, polynomial reduction requires an abundance of registers to implement. This makes a naive implementation of $\\texttt{PolyK}$ slow and difficult to parallelize on architectures where vectorized registers are scarce, such as x86-64. We fix this problem in the next subsection.\n\n\\subsection{Amortized reductions and parallelism}\nThe observation that $\\texttt{PolyK}$ is done only with pre-computed 128-bit polynomials leads to a large speedup in the implementation of $H$. The basic idea is to only perform a single polynomial reduction per invocation of $\\texttt{PolyK}$. Instead of performing polynomial multiplication in $GF_{128}$, we will simply perform multiplication in $GF_{2}[x]$. Since all multiplicands are pre-computed 128-bit polynomials, the output will always be a 256-bit polynomial. If we XOR all 256-bit polynomials together, we can then perform a single polynomial reduction at the end to compute the final output in $GF_{128}$.\n\nIn practice, we change this idea slightly. Instead of producing a 256-bit polynomial by completing the full Karatsuba multiplication, we instead only perform the first step of Karatsuba multiplication by computing $C_i$, $D_i$, and $E_i$. We then compute the following\n\\begin{algorithm}[H]\n\t\\caption{Parallelized GF128 multiplication}\\label{parallelgf128}\n\\begin{algorithmic}[1]\n\t\\Require All $A_i, B_i$ are 128-bit polynomials.\n\t\\Procedure{KaratsubaStep1Parallel}{$\\{A_0, \\cdots, A_{k-1}\\}, \\{B_0, \\cdots, B_{k-1}\\}$}\n\t\t\\State $C \\gets 0^{128}$\n\t\t\\State $D \\gets 0^{128}$\n\t\t\\State $E \\gets 0^{128}$\n\t\t\\For{$i \\gets 0, i < k$}\n\t\t\t\\State $C', D', E' \\gets \\Call{KaratsubaStep1}{A_i, B_i}$\\Comment{Compute in parallel.}\n\t\t\t\\State $C \\gets C \\oplus C'$\n\t\t\t\\State $D \\gets D \\oplus D'$\n\t\t\t\\State $E \\gets E \\oplus E'$\n\t\t\\EndFor\n\t\t\\State \\textbf{return} $C, D, E$\n\t\\EndProcedure\n\t\\State\n\t\\Procedure{GF128Parallel}{$\\{A_0, \\cdots, A_{k-1}\\}, \\{B_0, \\cdots, B_{k-1}\\}$}\n\t\t\\State $C, D, E \\gets \\Call{KaratsubaStep1Parallel}{\\{A_0, \\cdots, A_{k-1}\\}, \\{B_0, \\cdots, B_{k-1}\\}$}\n\t\t\\State $P \\gets \\Call{KaratsubaStep2}{C, D, E}$\n\t\t\\State $R \\gets \\Call{Barrett}{P}$\n\t\t\\State \\textbf{return} $R$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nUsing this method as a subroutine to compute $\\texttt{PolyK}$ allows the complex parts of polynomial multiplication to only be computed once per invocation of $\\texttt{PolyK}$.\n\nThis implementation only requires $3k + 2$ carry-less multiplications per invocation of $\\texttt{PolyK}$. Furthermore, it allows for greater parallelism since the first step of Karatsuba multiplication can be done using only 4 registers on x86-64.\n\n\\subsection{Further parallelism}\nA minor problem with the implementation of $\\texttt{PolyK}$ is that when computing $\\texttt{Poly}(M)$ the outer multiplications by $\\hgen^{k}$ cannot be parallelized. This can be fixed by precomputing the first $ck$ powers of $\\hgen$ for some integer $c$. This allows for a variant on the definition of $\\texttt{PolyK}$ which we will call $\\texttt{PolyInternal}$.\n\nUsing this idea, we can remove the non-parallelism of $\\hgen^k$ and further amortize polynomial reductions. The following pseudocode describes a fully parallelized implementation of $\\texttt{Poly}$.\n\\begin{algorithm}[H]\n\\caption{Subroutine for parallelized polynomial evaluation}\\label{polyalgsub}\n\\begin{algorithmic}[1]\n\t\\Require $|Q| < nkc$\n\t\\Require $\\hgen^1$, $\\cdots$, $\\hgen^{kc}$ have been precomputed.\n\t\\Procedure{PolyInternal}{$Q$}\n\t\t\\State $poly \\gets 0^{128}$\n\t\t\\State $nblocks \\gets \\lfloor |Q|/n \\rfloor$\n\t\t\\State $nstrides \\gets \\lfloor nblocks/c \\rfloor$\n\t\t\\State $C \\gets 0^{128}$\n\t\t\\State $D \\gets 0^{128}$\n\t\t\\State $E \\gets 0^{128}$\n\t\t\\For{$i = 0, i < nstrides$}\n\t\t\t\\State $e \\gets nblocks - 1 - ci$\n\t\t\t\\State $Alist \\gets \\{Q[nci + 0 : n], \\cdots, Q[nci + n(k - 1) : n]\\}$\n\t\t\t\\State $Blist \\gets \\{\\hgen^{e}, \\cdots, \\hgen^{e - k + 1}\\}$\n\t\t\t\\State $C', D', E' \\gets \\Call{KaratsubaStep1Parallel}{Alist, Blist}$\n\t\t\t\\State $C \\gets C \\oplus C'$\n\t\t\t\\State $D \\gets D \\oplus D'$\n\t\t\t\\State $E \\gets E \\oplus E'$\n\t\t\\EndFor\n\t\t\\For{$i = 0, i < nblocks \\bmod c$}\n\t\t\t\\State $e \\gets nblocks - 1 - i$\n\t\t\t\\State $C', D', E' \\gets \\Call{KaratsubaStep1}{Q[nc*nstrides + ni : n], \\hgen^{e}}$\n\t\t\t\\State $C \\gets C \\oplus C'$\n\t\t\t\\State $D \\gets D \\oplus D'$\n\t\t\t\\State $E \\gets E \\oplus E'$\n\t\t\\EndFor\n\t\t\\State $P \\gets \\Call{KaratsubaStep2}{C, D, E}$\n\t\t\\State $R \\gets \\Call{Barrett}{P}$\n\t\t\\State \\textbf{return} $R$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\caption{Parallelized polynomial evaluation}\\label{polyalg}\n\\begin{algorithmic}[1]\n\t\\Require $\\hgen^1$, $\\cdots$, $\\hgen^{kc}$ have been precomputed.\n\t\\Procedure{Poly}{$M$}\n\t\t\\State $poly \\gets 0^{128}$\n\t\t\\For{$i = 0, i < \\lceil |M| / c \\rceil$}\n\t\t\t\\State $poly \\gets poly*\\hgen^{kc} \\oplus \\Call{PolyInternal}{M[icn : cn]}$\n\t\t\\EndFor\n\t\t\\State \\textbf{return} $poly$\n\t\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\nThe number of polynomial reductions is reduced further for larger choices of $c$ since $\\texttt{PolyInternal}$ only requires a single invocation of polynomial reduction.\n\n\\end{document}\n", "meta": {"hexsha": "4bff7914e7c2028b9d7bcd7585e69783ac4534f3", "size": 14008, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/polyvalimpl.tex", "max_stars_repo_name": "google/hctr2", "max_stars_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-11-05T14:23:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:24:43.000Z", "max_issues_repo_path": "paper/polyvalimpl.tex", "max_issues_repo_name": "google/hctr2", "max_issues_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2021-11-01T21:35:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T23:41:06.000Z", "max_forks_repo_path": "paper/polyvalimpl.tex", "max_forks_repo_name": "google/hctr2", "max_forks_repo_head_hexsha": "1913bddafea9797108446d4284a1e3f8e43a1b5a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-04T17:58:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T13:29:03.000Z", "avg_line_length": 58.8571428571, "max_line_length": 999, "alphanum_fraction": 0.6864648772, "num_tokens": 4794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6173508207819188}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\chapter{The \"overturner\" circulation model} \\label{chap:overturnercirculation}\nA velocity field is proposed here that will be used further to build problems on which the method will be applied. That circulation model was initially proposed by \\textit{E. Deleersnijder} \\cite{deleersnijder2006overturner} as an idealized, two-dimensional representation of the meridian circulation in the Atlantic ocean. It has been studied extensively by \\textit{C. Timmermans} in her master's thesis \\cite{timmermans2006masterthesis}. The justifications of the model can be found in the latter. In this chapter, we only present the circulation model without justification. \n%\\textcolor{red}{Soit on fait le modèle overturner plus loin et alors il faut des justifications. Soit on ne le fait pas et c'est ok.}\n\n\\section{An idealized velocity field}\nLet us consider a rectangular domain in the $(y,z)$-coordinate system. \n%The coordinate $y$ is associated to the latitude with $\\hat{\\b{e}}_y$ pointing towards the North, and $z$ is associated to the depth with $\\hat{\\b{e}}_z$ pointing upwards. \nThe domain $\\Omega$ is delimited by\n\\begin{equation} \n\t0 \\le y \\le L,\\quad 0 \\le z \\le H,\n\\end{equation}\nwhere $L$ and $H$ are positive constants. \n%The ocean surface is thus located at $z = H$ while $z = 0$ stands for the deep-ocean. The South and North boundaries are respectively given by $y = 0$ and $y = L$. We aim at defining a stationary velocity field $\\b u(y,z) = (v(y,z),\\, w(y,z))$ that would roughly reproduce the main qualitative features of the meridian circulation in the Atlantic ocean. Under the Boussinesq approximation, the continuity equation reads\nThe stationary velocity field is denoted $\\b u(y,z) = (v(y,z),\\, w(y,z))$. Under the Boussinesq approximation, the continuity equation reads\n\\begin{equation} \\label{eq:continuity_boussinesq}\n\t\\nabla \\cdot \\b u = 0,\n\\end{equation}\nFor our particular problem, this amounts to\n\\begin{equation}\n\t\\frac{\\partial v}{\\partial y} + \\frac{\\partial w}{\\partial z} = 0.\n\\end{equation}\nNo-through boundary conditions are imposed at the boundaries of the domain, which implies that $\\b u(y,z) \\cdot \\hat{\\b{n}} = 0$ everywhere on $\\partial \\Omega$ (where $\\hat{\\b{n}}$ is the outwards unit normal at the boundary), or equivalently :\n\\begin{equation} \\label{eq:overturnerBC}\n\tv(0,z) = 0, \\quad v(L,z) = 0, \\quad w(y,0) = 0 \\quad \\mbox{and} \\quad w(y,H) = 0.\n\\end{equation}\n%\\textcolor{red}{Blahblah à mettre en relation avec ce qu'on doit dire plus tôt sur les modèles 2D de l'océan Atlantique,... Éventuellement s'inspirer de Timmermans mais attention quand même...}\n\nIn order to build a velocity field that satisfies the continuity equation~\\eqref{eq:continuity_boussinesq}, a \\textit{streamfunction} approach is used. The whole approach is explained in appendix~\\ref{app:streamfunction} along with some important properties of the streamfunction in two dimensions that will be useful in the next. Let $\\psi$ denote the streamfunction. The velocity field satisfies the relation\n\\begin{equation}\n\t\\b u = - \\rot \\psi.\n\\end{equation}\nIn particular, $\\psi$ must be such that the boundary conditions~\\eqref{eq:overturnerBC} are satisfied. Those conditions state that $\\b u$ must be tangent to the boundary everywhere on $\\partial \\Omega$, which precisely amounts to require that $\\psi$ is constant on $\\partial \\Omega$ (see property~\\ref{prop:streamfunction-tangent}). Without loss of generality, we can choose this constant to be zero. Hence, we require that \n\\begin{equation}\n\t\\psi(0,z) = 0, \\ \\psi(L,z) = 0, \\ \\psi(y,0) = 0 \\ \\mbox{and} \\ \\psi(y,H) = 0,\\ \\mbox{for all $(y,z) \\in \\Omega$}.\n\\end{equation}\n\n%\\textcolor{red}{Faire des liens avec chapitre précédent} \nIn order to build an acceptable idealization of the meridian circulation in the Atlantic ocean, \\textit{Deleersnijder} proposes in his working paper \\cite{deleersnijder2006overturner} to suppose that the meridian streamfunction has a unique extremum $\\Psi$, which is a maximum, and that it reaches that maximum at the point of coordinates $(y_0,z_0)$, located near the surface and near the North boundary of the domain. It is important to recall that the second partial derivatives of $\\psi$ must exist and be continuous for the above relations to hold.\n\nLet $\\xi_0 \\in \\mathbb{R}_0^+$, and let $\\phi(\\xi,\\xi_0)$ be defined as\n\\begin{equation} \\label{eq:phi}\n\t\\phi(\\xi,\\xi_0) = \\frac{\\xi(2\\xi_0-\\xi)}{\\xi_0^2},\n\\end{equation}\nThe derivative $\\phi'(\\xi,\\xi_0)$ of $\\phi$ with respect to $\\xi$ is\n\\begin{equation}\n\t\\phi'(\\xi,\\xi_0) = \\frac{2(\\xi_0-\\xi)}{\\xi_0^2}.\n\\end{equation}\nAn expression of the meridian streamfunction that satisfies the above constraints is then\n\\begin{equation} \\label{eq:psi_overturner}\n\t\\psi(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\t\\phi(y,y_0)\\phi(z,z_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(y,y_0)\\phi(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, & z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, &z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi(z,z_0) & \\mbox{if} & y_0 < y \\le L, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(z,z_0) & \\mbox{if} & y = y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(H-z,H-z_0) & \\mbox{if} & y = y_0, & z_0 < z \\le H,\\\\\n\t\t\t\\phi(y,y_0) & \\mbox{if} & 0 \\le y < y_0, & z = z_0,\\\\\n\t\t\t\\phi(L-y,L-y_0) & \\mbox{if} & y_0 < y \\le L, & z=z_0,\\\\\n\t\t\t1 & \\mbox{if} & y = y_0, & z=z_0.\\\\\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nFigure~\\ref{fig:psi_overturner} shows the isolines of the adimensional streamfunction $\\psi/\\Psi$ for a given choice of the parameters. The point is that this circulation describes revolutions around the point $(y_0,z_0)$. With the choice $\\b u = - \\nabla \\times \\psi$, those revolutions are clockwise.\n\\begin{figure}[!htp]\n\t\\centering\n\t\\includegraphics[width=.5\\textwidth]{fig/overturner/psi.eps}\n\t\\caption{Some isolines of the adimensional meridian streamfunction $\\psi(y,z)/\\Psi$, which are also streamlines of the flow.}\n\t\\label{fig:psi_overturner}\n\\end{figure}\n\nThe meridian and vertical components of the velocity are then expressed as\n\\begin{equation} \\label{eq:v_overturner}\n\tv(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\t- \\phi(y,y_0)\\phi'(z,z_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(y,y_0)\\phi'(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, & z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi'(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi(L-y,L-y_0)\\phi'(z,z_0) & \\mbox{if} & y_0 < y \\le L, & 0 \\le z < z_0,\\\\\n\t\t\t- \\phi'(z,z_0) & \\mbox{if} & y = y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(H-z,H-z_0) & \\mbox{if} & y = y_0, & z_0 < z \\le H,\\\\\n\t\t\t0 & \\mbox{if} &0 \\le y \\le L, & z = z_0.\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nand\n\\begin{equation} \\label{eq:w_overturner}\n\tw(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\t\\phi'(y,y_0)\\phi(z,z_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(y,y_0)\\phi(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi'(L-y,L-y_0)\\phi(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi'(L-y,L-y_0)\\phi(z,z_0) & \\mbox{if} & y_0 < y \\le L, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(y,y_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z = z_0,\\\\\n\t\t\t- \\phi'(L-y,L-y_0) & \\mbox{if} & y_0 < y \\le L, & z = z_0,\\\\\n\t\t\t0 & \\mbox{if} & y = y_0. &\n\t\t\\end{array}\n\t\\right.\n\\end{equation}", "meta": {"hexsha": "b255288a12c3397d7702d6a7569c0a64b7da6a7f", "size": 7294, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/overturnercirculation/overturnercirculation.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/overturnercirculation/overturnercirculation.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/overturnercirculation/overturnercirculation.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": 72.94, "max_line_length": 578, "alphanum_fraction": 0.679188374, "num_tokens": 2658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6173508197176516}}
{"text": "%%\r\n\\chapter{Constants and Some Basic Units}\r\n\r\n\\section{Mathematical constants}\r\n\\begin{align*}\r\n\\pi = & \\ 3.14159\\ldots\\\\\r\ne =  &\\  2.1728\\ldots\\\\\r\n\\ln10 =  & \\  2.30259\\ldots\\\\\r\n\\log10 =  &\\  1\r\n\\end{align*}\r\n\r\n\\section{International System (SI) basic units}\r\n\\begin{table}[h]\r\n\t\\centering\r\n\t\\begin{tabular}{llll}\r\n\t\t\\toprule[1.5pt]\r\n\t\tQuantity  &\tUnit & Symbol & Dimension symbol\\\\\r\n\t\t\\midrule[1pt]\r\n\t\tlength & meter & m & L\\\\\r\n\t\tmass & kilogram & kg & M\\\\\r\n\t\ttime & second & s & T\\\\\r\n\t\telectric current & ampere & A& I\\\\\r\n\t\ttemperature & kelvin & K& $\\theta$\\\\\r\n\t\tamount of substance & mole &   mol & N\\\\\r\n\t\tluminous intensity & candela & cd & J\\\\\r\n\t\t\\bottomrule[1.5pt]\r\n\t\\end{tabular}\r\n\\end{table}", "meta": {"hexsha": "4a52bcd8b62e8bd0aaff7851299f44a2b681588f", "size": 703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04-Book/backmatter/app1.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/backmatter/app1.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/backmatter/app1.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": 25.1071428571, "max_line_length": 49, "alphanum_fraction": 0.600284495, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293632411501, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.617350812906001}}
{"text": "\\section{Minimal Automaton}\n\n\\textbf{Assumption}: the automaton is clean except for the $q_{err}$ state.\n\nState $p$ is indistinguishable from $q$ iff $\\forall x, \\delta(p,x)$ and $\\delta(q, x)$ are both final or non-final. Indistiguishability is an equivalence relation, 2 indistinguishable states can be merged with no change in the language recognized.\n\n\\subsection{Compute distinguishability set}\n$p$ is distinguishable from $q$ iff\n\\begin{itemize}\n    \\item $p$ is final and $q$ is not, or vice-versa; or\n    \\item $\\exists a: \\delta(p, a)$ is distinguishable from $\\delta(q, a)$\n\\end{itemize}\n\n\\textbf{Example}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{automata/example-automaton-minimization.png}\n\\end{figure}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{minipage}{0.35\\linewidth}\n        \\begin{tabular}{r|c|cc}\n            \\cline{2-2}\n            $q_1$ & & & \\\\\n            \\cline{2-3}\n            $q_2$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\\\\n            \\cline{2-4}\n            $q_3$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\multicolumn{1}{c|}{} \\\\\n            \\cline{2-4}\n            \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$q_0$} & $q_1$ & $q_2$\n        \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}{0.6\\linewidth}\n        \\begin{tabular}{r|c|cc}\n            \\cline{2-2}\n            $q_1$ & (1,1)(0,2) & & \\\\\n            \\cline{2-3}\n            $q_2$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\\\\n            \\cline{2-4}\n            $q_3$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\multicolumn{1}{c|}{(3,3)(2,2)} \\\\\n            \\cline{2-4}\n            \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$q_0$} & $q_1$ & $q_2$\n        \\end{tabular}\n    \\end{minipage}\n    \\begin{minipage}{0.6\\linewidth}\n        \\begin{tabular}{r|c|cc}\n            \\cline{2-2}\n            $q_1$ & \\xmark & & \\\\\n            \\cline{2-3}\n            $q_2$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\\\\n            \\cline{2-4}\n            $q_3$ & \\xmark & \\multicolumn{1}{c|}{\\xmark} & \\multicolumn{1}{c|}{(3,3)(2,2)} \\\\\n            \\cline{2-4}\n            \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{$q_0$} & $q_1$ & $q_2$\n        \\end{tabular}\n    \\end{minipage}\n\\end{table}\n\nStates $q_2$ and $q_3$ are indistinguishable, so they can be merged.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{automata/example-automaton-minimization-2.png}\n\\end{figure}\n", "meta": {"hexsha": "4045a07a36c7b869f359c6bece1a36c36e3ec1c5", "size": 2398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/minimal-automaton.tex", "max_stars_repo_name": "Kakasinho/FLC-cheatsheet", "max_stars_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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/minimal-automaton.tex", "max_issues_repo_name": "Kakasinho/FLC-cheatsheet", "max_issues_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "max_issues_repo_licenses": ["MIT"], "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/minimal-automaton.tex", "max_forks_repo_name": "Kakasinho/FLC-cheatsheet", "max_forks_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "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": 36.3333333333, "max_line_length": 248, "alphanum_fraction": 0.5508757298, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.617299710961359}}
{"text": "\\newcommand{\\bmop}{\\mathcal{G}}\n\n\\chapter{Hybrid finite/boundary element method}\n\\chaptermark{Hybrid FEM/BEM}\n\\label{sec:hybr-finit-elem}\n\nThe boundary element method (BEM) is a spatial discretisation method similar to the FEM except that the problem on a domain is converted to an equivalent formulation in terms of integrals over the boundary of the domain before the discretisation is applied.\nThe main downside of such a formulation is that it results in a dense matrix after the discretisation is applied.\n\nThe hybrid finite/boundary element method (FEM/BEM) is a spatial discretisation method which applies FEM and BEM to different parts of the same problem.\nIn particular this method can be applied in the context of magnetostatic calculations to enforce the boundary condition at infinity in \\cref{eq:cont-phi-bound} without meshing an infinite region of space or arbitrarily truncating it.\nThis is done by applying the BEM to a part of the problem on the infinite external domain in order to convert it into a problem on the boundary of the magnetic domain.\nThe use of FEM for the remaining parts of the problem means that most of the obtained linear systems remain sparse.\n\nIn \\thisref{sec:hybr-finit-elem} we first give an overview of the FEM/BEM approach and then show how splitting the magnetostatic problem into two parts and applying some results from potential theory can lead to a formulation which involves only finite domains.\nWe then demonstrate how this formulation can be discretised, and discuss the evaluation of the required integrals.\nMethods of coupling the FEM/BEM magnetostatic calculations to the FEM-discretised LLG problem (as described in \\cref{sec:galerk-meth-llg}) are discussed in \\cref{sec:solution-strategies}, along with strategies for the solution of the resulting linear/non-linear systems.\n\n\n\\section{The continuous FEM/BEM formulation}\n\\label{sec:bem-derivation}\n\n\n % I'm worried about whether all this is ok with weak form: we use strong form for derivation of boundary formulation then ``just assume'' that it will all be ok when we weak form it...\n% But since, in the final equations, there are no derivatives of the solution we should be ok right?\n% It must be ok somehow because people use Galerkin BEM! Just need to read the book to see why\n\nWe want to use the boundary element method in the calculation of the magnetostatic scalar potential, $\\phim$, (defined in \\cref{eq:Hms,eq:cont-phi-bound}) to avoid performing calculations that involve the infinite external domain.\nHowever, applying the boundary element method alone would require the solution of dense matrix equations for the entire problem.\nWe can circumvent this issue by applying a hybrid method using both FEM and BEM.\nWe use the linearity of the Poisson operator to split the potential into two parts $\\phim = \\phione + \\phitwo$ in such a way that $\\phione$ can be calculated in the magnetic domain, $\\magd$, using only the finite element method.\nThis results in conditions on $\\phitwo$ that must be satisfied to give the correct total potential, including the problematic condition at infinity.\n\nIt turns out that $\\phim$ can be split in such a way that the $\\phitwo$ is equivalent to the potential resulting from a specific arrangement of fictional magnetic charges, which is known to solve the required differential equation including the boundary condition at infinity.\nThe details of this ``charge distribution'', which gives rise to a double-layer potential, depend on the boundary values of $\\phione$.\nThe use of such a charge distribution is equivalent to applying the BEM to $\\phitwo$.\n\nSo given $\\phione$ and using the known solution for this charge distribution we can calculate $\\phitwo$ anywhere.\nHowever the calculation of $\\phitwo$ at a point using this method involves an expensive dense matrix operation, so we only use it to calculate Dirichlet boundary conditions for $\\phitwo$ on the boundary of the magnetic domain, $\\boundd$.\nThese boundary conditions allow us to apply the finite element method to find $\\phitwo$ inside the magnetic domain $\\magd$ using standard sparse matrix techniques.\n\nThe magnetostatic field $ \\hms = \\grad \\phim$ constructed by the procedure outlined above is \\emph{the} magnetostatic field by the uniqueness (up to a constant) of solution for Poisson's equation with Dirichlet or Neumann boundary conditions.\\footnote{To see the uniqueness take the difference of two solutions of Poisson's equation: $\\phi = \\psi_1 - \\psi_2$.\nThen using identity \\cref{eq:20}, the linearity of Poisson's equation and the divergence theorem we obtain $\\intb{\\phi \\grad \\phi \\cdot \\nv} = \\intd{(\\grad \\phi)^2 }$.\nApplying Dirichlet, Neumann or mixed boundary conditions shows that the boundary integral is zero and hence $\\grad \\phi = 0$.}\n\nIn \\cref{sec:problem-description} we describe in more detail the splitting of the potential that allows this process.\nThen in \\cref{sec:double-layer-potent} we describe the properties of the fictional charge distribution.\nFinally in \\cref{sec:appl-magn-calc} we combine these parts to give a formulation of the magnetostatic problem involving only finite sized domains.\n\n\\subsection{The potential splitting}\n\\label{sec:problem-description}\n\\newcommand{\\examplepot}{f}\n\n\\begin{figure}\n  \\center\n  \\includegraphics[width=0.75\\textwidth]{./images/BEM-geometry}\n  % \\begin{tikzpicture}\n\n  %   %   Main nodes and some labels\n  %   \\node[label=below:$\\xv'$] (a) at (-2,-2) {};\n  %   \\node (b) at (-2,2) {};\n  %   \\node[label=right:\\Large{$\\boundd$}] (c) at (5,0) {};\n\n  %   %   Draw main shape of magnetic domain\n  %   \\draw [line width=0.5mm,draw=solidblue,fill=paleblue] (a.north) to [bend right=71] (c) to (b.south);\n  %   \\draw [line width=0.5mm,draw=solidblue] (a) to (b);\n  %   \\draw (a.north) circle(1mm) [fill=black] {};\n\n  %   %   More labels\n  %   \\node (center) at (1,0) {\\Large{Magnetic domain $\\magd$}};\n  %   \\node(external) at (8,3) {\\Large{External domain $\\extd$}};\n  % \\end{tikzpicture}\n\n  \\caption{A 2D representation of the geometry showing the labels used in \\thisref{sec:hybr-finit-elem}.\n    The point $\\xv'$ is a singular point of the boundary $\\boundd$, the angle $\\alpha(\\xv')$ is as shown.}\n  \\label{fig:BEM-geometry}\n\\end{figure}\n\nFirst we need to introduce some notation: we write $\\examplepot^\\inte(\\xv) = \\lim_{\\xv \\rightarrow \\boundd} \\examplepot(\\xv)$ from inside the magnetic domain, $\\examplepot^\\exte(\\xv) = \\lim_{\\xv \\rightarrow \\boundd} \\examplepot(\\xv)$ from outside the magnetic domain.\nThat is, $\\examplepot^\\inte$ denotes the value of $\\examplepot$ ``close'' to the boundary $\\boundd$ and ``just inside'' the magnetic domain and $\\examplepot^\\exte$ for the value of $\\examplepot$ ``just outside'' the magnetic domain (see \\cref{fig:BEM-geometry}).\n\nFrom \\cref{sec:magnetostatic-field} we have certain \\emph{physical} conditions on the magnetostatic potential $\\phim$.\nBoth inside and outside the magnetic domain, $\\magd$, we have\n\\begin{equation}\n  \\lap \\phim(\\xv) = \\div \\mv(\\xv),\n  \\label{eq:2}\n\\end{equation}\nwhere we define $\\mv = \\zerov$ outside of magnetic materials.\nWe also have the boundary conditions\n\\begin{equation}\n  \\pd{\\phim^\\inte(\\xv)}{\\nv} - \\pd{\\phim^\\exte(\\xv)}{\\nv} = \\mv \\cdot \\nv \\qquad \\xv \\in \\boundd,\n  \\label{eqn:dphibound}\n\\end{equation}\nand\n\\begin{equation}\n  \\phim^\\inte(\\xv) - \\phim^\\exte(\\xv)  = 0 \\qquad \\xv \\in \\boundd,\n  \\label{eqn:phibound}\n\\end{equation}\non the boundary of the magnetic material, $\\boundd$.\nFinally we have the condition that\n\\begin{equation}\n  \\phim(\\xv) \\rightarrow 0 \\qquad \\text{ as } \\abs{\\xv} \\rightarrow \\infty.\n  \\label{eq:48}\n\\end{equation}\n\nThe key observation for this part of the derivation is that \\cref{eq:2,eq:48,eqn:dphibound,eqn:phibound} are linear, \\ie if $\\phim = \\phione + \\phitwo$ then $\\lap \\phim = \\lap \\phione + \\lap \\phitwo$ and similarly for the boundary conditions.\nBased on this observation we define a new potential $\\phione$ which satisfies\n\\begin{equation}\n  \\phim(\\xv) = \\phione(\\xv) + \\phitwo(\\xv),\n  \\label{eq:21}\n\\end{equation}\neverywhere in $\\real^d$ and\n\\begin{equation}\n  \\lap \\phione(\\xv) = \\div \\mv(\\xv) \\qquad \\xv \\in \\magd,\n  \\label{eq:1}\n\\end{equation}\n\\begin{equation}\n  \\pd{\\phione^\\inte(\\xv)}{\\nv} = \\mv \\cdot \\nv \\qquad \\xv \\in \\boundd,\n  \\label{eqn:dphionebound}\n\\end{equation}\n\\begin{equation}\n  \\phione(\\xv) = 0 \\qquad \\xv \\in \\extd,\n  \\label{eqn:phioneoutside}\n\\end{equation}\nwhere $\\extd = \\real^d \\backslash \\magd$ is the infinite region of free space outside the magnetic domain.\nNote that \\cref{eq:1,eqn:dphionebound} give a self contained Poisson Neumann problem for $\\phione \\in \\magd \\cup \\boundd$, and that \\cref {eqn:phioneoutside} implies\n\\begin{equation}\n  \\pd{\\phione^\\exte(\\xv)}{\\nv} = 0 \\qquad \\xv \\in \\boundd.\n  \\label{eq:32}\n\\end{equation}\n\n\n\\Cref{eq:2,eq:48,eqn:dphibound,eqn:phibound} for $\\phim$ combined with \\cref{eq:21,eq:1,eqn:dphionebound,eqn:phioneoutside} for $\\phione$ give a number of conditions that $\\phitwo$ must satisfy.\nFrom \\cref{eq:2,eq:21,eq:1} and the fact that the problem is linear we have a differential equation for $\\phitwo$:\n\\begin{equation}\n  \\label{eq:8}\n  \\lap \\phitwo(\\xv) = 0,\n\\end{equation}\neverywhere in $\\real^d$.\nSubstituting \\cref{eq:21} into \\cref{eqn:dphibound} and using \\cref{eqn:dphionebound,eq:32} gives\n\\begin{equation}\n    \\pd{\\phitwo^\\inte(\\xv)}{\\nv} - \\pd{\\phitwo^\\exte(\\xv)}{\\nv} =\n    \\pd{\\phione^\\exte(\\xv)}{\\nv} - \\pd{\\phione^\\inte(\\xv)}{\\nv}\n    + \\mv \\cdot \\nv \\qquad \\xv \\in \\boundd,\n\\end{equation}\nthus the first boundary condition on $\\phitwo$ is\n\\begin{equation}\n  \\pd{\\phitwo^\\inte(\\xv)}{\\nv} = \\pd{\\phitwo^\\exte(\\xv)}{\\nv}  \\qquad \\xv \\in \\boundd.\n  \\label{eq:5}\n\\end{equation}\nFinally from \\cref{eqn:phibound,eq:21,eqn:phioneoutside} we have a second boundary condition on $\\phitwo$:\n\\begin{equation}\n  \\begin{aligned}\n    (\\phione^\\inte + \\phitwo^\\inte) - (\\phione^\\exte + \\phitwo^\\exte) &= 0, \\\\\n    \\phitwo^\\inte - \\phitwo^\\exte &= - \\phione^\\inte &\\qquad \\xv \\in \\boundd.\n    \\label{eq:4}\n  \\end{aligned}\n\\end{equation}\nAs mentioned previously, the solution of the Laplace equation \\cref{eq:8} subject to the boundary conditions \\cref{eq:5,eq:4} is satisfied by a certain arrangement of virtual magnetic charges.\nThis arrangement of charges is discussed in the next section.\n\n\\subsection{Double Layer Potentials}\n\\label{sec:double-layer-potent}\n\nA double layer potential can be thought of as the potential due to a layer of dipoles (\\ie two charges separated by an infinitesimal distance) of magnitude $\\mu(\\xv)$ in direction $\\nv$ over the surface $\\boundd$ \\cite{Sternberg1946}.\\footnote{Note that our potentials are a factor of $\\frac{-1}{4 \\pi}$ different from those in reference \\cite{Sternberg1946} and that our $\\phim^\\inte$ and $\\phim^\\exte$ definitions correspond to their $\\phim^-$ and $\\phim^+$.}\nIn \\thisref{sec:double-layer-potent} we give some (mathematical) properties of a double layer potential.\n%, in \\cref{} we will demonstrate that we can use a double layer potential to calculate $\\phitwo^\\inte$ in terms of $\\phione^\\inte$.\n\nThe double layer potential at a point $\\xv \\in \\real^d$ (including $\\xv \\in \\boundd$) is defined as\n\\begin{equation}\n  \\label{eq:3}\n  \\phim(\\xv) = \\int_{\\boundd} \\mu(\\yv) \\pd{\\Green}{\\nv(\\yv)} \\d \\yv,\n\\end{equation}\nwhere $G$ is the Green's function for the Laplacian operator and $\\nv(\\yv)$ is the outward unit normal at $\\yv \\in \\boundd$.\nFor $d=2$\n\\begin{equation}\n  \\Green = \\dfrac{-1}{2\\pi}\\ln(\\abs{\\xv - \\yv}),\n  \\label{eqn:greenslaplacian2d}\n\\end{equation}\nand for $d=3$\n\\begin{equation}\n  \\Green = \\dfrac{-1}{4 \\pi} \\dfrac{1}{\\abs{\\xv - \\yv}}.\n  \\label{eqn:greenslaplacian3d}\n\\end{equation}\n\n\nWe have the following results from potential theory:\n\\begin{enumerate}\n\\item The double layer potential satisfies Laplace's equation $\\lap \\phi = 0$ (in other words the double layer potential is harmonic) \\cite{Sternberg1946}.\n\n\\item The double layer potential undergoes a jump of $\\mu(\\xv)$ moving in the direction $\\nv$ across a smooth surface $\\boundd$ \\cite[136-140]{Sternberg1946}, \\ie\n  \\begin{equation}\n    \\label{eq:15}\n    \\phim^\\inte(\\xv) - \\phim^\\exte(\\xv) = \\mu(\\xv).\n  \\end{equation}\n\n\\item Defining the fractional angle at a point as\n  \\begin{equation}\n    \\gamma(\\xv) = \\frac{\\alpha(\\xv)}{\\alpha_{\\text{max}}},\n  \\end{equation}\n  where, in two dimensions, $\\alpha(\\xv)$ is the angle subtended by the domain at $\\xv$ and $\\alpha_{\\text{max}} = 2\\pi$.\n  Similarly in three dimensions $\\alpha(\\xv)$ is the solid angle and $\\alpha_{\\text{max}} = 4\\pi$.\n\n  Then for $\\xv \\in \\boundd$ the following relationship holds \\cite[137-139, 155]{Sternberg1946}\n  \\begin{equation}\n    \\phim^\\inte(\\xv) = (1 - \\gamma(\\xv)) \\mu(\\xv) + \\phim(\\xv).\n    \\label{eq:22}\n  \\end{equation}\n  Note that the angle $\\alpha$ at any smooth point on the surface (\\ie not at an infinitely sharp corner) is $\\pi$ in 2D (or $2\\pi$ in 3D).\n  So in these cases $\\gamma(\\xv) = \\frac{\\alpha(\\xv)}{\\alpha_{\\text{max}}} = \\frac{1}{2}$.\n\n\\item If $\\mu$ is continuous and has continuous first and second derivatives along the boundary (\\ie $\\mu(\\xv) \\in C^2(\\boundd)$) then the limits $\\pd{\\phim^\\inte(\\xv)}{\\nv}$ and $\\pd{\\phim^\\exte(\\xv)}{\\nv}$ exist and are equal \\cite[145-153]{Sternberg1946}.\n\n\\end{enumerate}\n\nNote that some derivations of the results above rely on the surface being a ``Lyapunov surface'' which imposes a number of smoothness conditions on the surface, in particular excluding surfaces with corners.\nThe proofs given in \\cite{Sternberg1946} allow a finite number of sharp corners, \\ie a polygonal domain.\n\n\\subsection{Application to Magnetostatic Calculations}\n\\label{sec:appl-magn-calc}\n\nFrom \\cref{sec:double-layer-potent} we can see that conditions \\cref{eq:8,eq:5,eq:4} on $\\phitwo$ are satisfied by a double layer potential with magnitude\\footnote{It is also possible to directly derive the double layer potential formula from \\cref{eq:8,eq:5,eq:4}, as described in \\cite[Appendix 2]{Knittel2011}.}\n\\begin{equation}\n  \\label{eq:24}\n  \\mu(\\xv) = - \\phione^\\inte(\\xv).\n\\end{equation}\n\nBy the uniqueness of solution for Poisson's equation this gives us, up to an additive constant, the only solution for $\\phitwo(\\xv)$ in the external domain.\nThis is good enough for a potential since it is only used in $\\hms(\\xv) = - \\grad \\phim(\\xv)$ and addition of a constant has no effect.\n\nSubstituting \\cref{eq:24} into \\cref{eq:3,eq:22} we have:\n\\begin{equation}\n  \\label{eq:6}\n  \\phitwo^\\inte(\\xv) =\n  - \\int_{\\boundd} \\phione^\\inte(\\yv) \\pd{\\Green}{\\nv(\\yv)} \\d \\yv\n  + \\big(\\gamma(\\xv) - 1 \\big) \\phione^\\inte(\\xv).\n\\end{equation}\nAfter substituting our definition for the three dimensional Green's function \\cref{eqn:greenslaplacian3d} into \\cref{eq:6} we obtain the same equation as given by Koehler et. al. \\cite{Koehler1997}.\n\nAlso note that $\\phim = \\phione + \\phitwo$ everywhere, so\n\\begin{equation}\n  \\begin{aligned}\n    \\label{eq:18}\n    \\phim^\\inte(\\xv)\n    &= - \\int_{\\boundd} \\phione^\\inte(\\yv) \\pd{\\Green}{\\nv(\\yv)} \\d \\yv\n    + \\gamma(\\xv) \\phione^\\inte(\\xv).\n  \\end{aligned}\n\\end{equation}\nEither \\cref{eq:6} or \\cref{eq:18} can be used to give boundary conditions for $\\phitwo \\in \\magd$ or $\\phim \\in \\magd$ respectively.\nWe will proceed using \\cref{eq:18} since it eliminates $\\phitwo$ from later calculations and is slightly simpler.\nWe also omit the distinction between interior and exterior since all exterior values have now been eliminated.\n\nThe final continuous problem is\n\\begin{equation}\n  \\begin{aligned}\n    \\lap \\phim(\\xv) &= \\div \\mv(\\xv),  \\\\\n    \\lap \\phione(\\xv) &= \\div \\mv(\\xv),\n  \\end{aligned}\n  \\label{eq:phi-bem-continuous}\n\\end{equation}\nin the magnetic domain $\\magd$, with boundary conditions\n\\begin{equation}\n  \\begin{aligned}\n    \\phim(\\xv) &= \\bmop \\big[ \\phione(\\xv) \\big]      & \\xv \\in \\boundd, \\\\\n    \\pd{\\phione(\\xv)}{\\nv} &= \\mv \\cdot \\nv  & \\xv \\in \\boundd,\n    \\label{eq:phi-bem-continuous-bc}\n  \\end{aligned}\n\\end{equation}\nwhere the operator $\\bmop$ is defined as\n\\begin{equation}\n  \\bmop \\bigs{\\phione(\\xv)} = - \\int_{\\boundd} \\phione(\\yv) \\pd{\\Green}{\\nv(\\yv)} \\d \\yv\n  + \\gamma(\\xv) \\phione(\\xv).\n\\end{equation}\nNote that $\\phione$ has purely Neumann boundary conditions, hence it is only defined up to a constant.\nHowever, as mentioned before, the addition of a constant is not important so we can fix $\\phione$ to zero at some point to resolve this issue.\n\nSo if $\\mv$ is some fixed function, we can apply the FEM to calculate $\\phione$, then use $\\bmop$ (assuming we have some discrete version of it) to calculate Dirichlet boundary conditions on $\\phim$ and, finally, use the FEM again to calculate $\\phim$.\nHowever, in the context of an implicit time integration scheme applied to the LLG equation the value of $\\mv$ is not fixed, and entire problem should be solved simultaneously to find a consistent set of $\\mv$, $\\phione$ and $\\phim$.\nEfficient methods for the solution of such a simultaneous system, or methods which avoid it, are the topic of \\cref{sec:solution-strategies}.\nFor now we continue by showing how the problem can be discretised.\n\n\\section{Discretisation}\n\\label{sec:discretisation}\n\n% Just in case we do need to distinguish between phim and phione basis functions:\n\\newsubcommand{\\tbfone}{\\tbf}{}\n\\newsubcommand{\\tbfm}{\\tbf}{}\n\nThe bulk equations~\\cref{eq:phi-bem-continuous} and the Neumann boundary condition on $\\phione$ in \\cref{eq:phi-bem-continuous-bc} are identical to those discussed in \\cref{sec:llg-initial-equations} and will be solved using the finite element method.\nAs such the weak residual form, discretisation and Jacobians are identical and all that remains to be discretised is the operator $\\bmop$.\nWe let\n\\begin{equation}\n  \\phim = \\sum_\\ibasis \\phim_{\\ibasis} \\tbfm_{\\ibasis}(\\xv),\n  \\qquad\n  \\phione = \\sum_\\ibasisb \\phione_{\\ibasisb} \\tbfone_{\\ibasisb}(\\xv),\n  \\label{eq:25}\n\\end{equation}\nwhere $\\tbf_i$ are the same polynomial basis functions as used in the finite element method of \\cref{sec:galerk-meth-llg}.\n\nSubstituting \\cref{eq:25} into \\cref{eq:18} we have\n\\begin{equation}\n  \\sum_\\ibasis \\phim_{\\ibasis} \\tbfm_{\\ibasis}(\\xv) =\n  - \\int_{\\boundd} \\sum_\\ibasisb \\phione_{\\ibasisb} \\tbfone_{\\ibasisb}(\\yv)\n  \\pd{\\Green}{\\nv(\\yv)} \\d \\yv\n   + \\gamma(\\xv) \\sum_\\ibasisb \\phione_{\\ibasisb} \\tbfone_{\\ibasisb}(\\xv).\n\\end{equation}\n\nSince the integrands are continuous functions on $\\boundd$, we can exchange the order of the sum and the integration, leaving\n\\begin{equation}\n  \\sum_\\ibasis \\phim_{\\ibasis} \\tbfm_{\\ibasis}(\\xv) =\n  - \\sum_\\ibasisb  \\phione_{\\ibasisb}  \\bigs{\\int_{\\boundd} \\tbfone_{\\ibasisb}(\\yv)\n    \\pd{\\Green}{\\nv(\\yv)} \\d \\yv }\n  + \\gamma(\\xv) \\sum_\\ibasisb \\phione_{\\ibasisb} \\tbfone_{\\ibasisb}(\\xv).\n  \\label{eq:27}\n\\end{equation}\n\nAt this point we could apply the Galerkin method (as described in \\cref{sec:intr-finite-ele-diff}): by multiplying \\cref{eq:27} by a test function and integrating.\nThis would result in a system of linear equations $\\Mm \\phimdis = \\bm' \\phionedis$ (where $\\bm'$ is the Galerkin discrete form of $\\bmop$) which could be solved for $\\phimdis$.\nHowever this would require calculating a double integral for each entry in $\\bm'$.\nInstead we apply a standard collocation method.\nCollocation methods enforce pointwise relationships in contrast to the Galerkin method which enforces relationships in a weighted integral form.\nThe collocation method is the conventional choice of discretisation approach for the BEM operator in micromagnetics.\n\nTo get the value of $\\phim$ at node $\\ibasisc$ using the collocation method we choose $\\xv = \\xv_\\ibasisc$ in \\cref{eq:27}.\nThen using the property $\\tbf_\\ibasis(\\xv_\\ibasisc) = \\delta_{\\ibasis \\ibasisc}$ and replacing $\\ibasisc$ by $\\ibasis$ we have\n\\begin{equation}\n  \\phim_{\\ibasis} =\n  - \\sum_\\ibasisb \\phione_{\\ibasisb}  \\bigs{\\int_{\\boundd_\\ibasisb} \\tbfone_{\\ibasisb}(\\yv)\n  \\pd{\\Green[\\ibasis]}{\\nv(\\yv)} \\d \\yv}\n   + \\gamma(\\xv_\\ibasis) \\phione_{\\ibasis},\n  \\label{eq:colocation}\n\\end{equation}\nwhere ${\\boundd_\\ibasisb}$ is the region of $\\boundd$ where $\\tbfone_{\\ibasisb} \\neq 0$, \\ie the elements which contain node $\\ibasisb$.\nNotice that the expression inside the square brackets is independent of all potentials: it depends only on the geometry and so can be pre-calculated and stored.\n\n\nThe equation \\cref{eq:colocation} gives the value of $\\phim$ at a boundary node in terms of a sum of geometric factors multiplied by the values of $\\phione$ at each boundary node.\nIn other words, this is a multiplication by a dense matrix $\\bm$ giving $\\phim$ at all the boundary nodes in terms of $\\phione$ at all boundary nodes:\n\\begin{equation}\n  \\label{eq:10}\n  \\phimdis = \\bm \\phionedis,\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{eq:17}\n  \\bm_{\\ibasis\\ibasisb} = - \\int_{\\boundd_\\ibasisb} \\tbfone_{\\ibasisb}(\\yv) \\pd{\\Green[\\ibasis]}{\\nv(\\yv)} \\d \\yv\n   + \\gamma(\\xv_\\ibasis)\\delta_{\\ibasis\\ibasisb}.\n\\end{equation}\n\nWe now convert the normal derivative of the Green's function into a more tangible form.\nIn 3D\n\\begin{equation}\n  \\label{eq:11}\n  \\pd{\\Green}{\\nv} = \\frac{-1}{4 \\pi} \\pd{}{\\nv} \\Gthreed = \\frac{-1}{4 \\pi} \\nv \\cdot \\grad \\Big( \\Gthreed \\Big).\n\\end{equation}\nConverting to spherical coordinates with the origin at $\\xv$ ($r = \\abs{\\yv - \\xv}$, $\\ruv = \\frac{\\yv - \\xv}{r}$) we have\\footnote{In spherical polar coordinates $\\nabla = \\ruv \\pd{}{r} +  \\phiv \\frac{1}{r} \\pd{}{\\phi} + \\thetav \\frac{1}{r \\sin \\theta} \\pd{}{\\theta}$.\nObviously $\\frac{1}{r}$ has no angular dependence so only the derivative with respect to $r$ is non-zero.}\n\\begin{equation}\n  \\label{eq:12}\n  \\pd{G(r)}{\\nv} = \\frac{-1}{4 \\pi} \\nv \\cdot \\ruv \\pd{}{r} \\Big( \\frac{1}{r} \\Big)\n  = \\frac{+1}{4 \\pi}  \\frac{\\nv \\cdot \\ruv}{r^2},\n\\end{equation}\n\\begin{equation}\n  \\label{eq:13}\n  \\pd{\\Green}{\\nv} = \\frac{\\nv \\cdot (\\yv - \\xv)}{4 \\pi \\abs{\\yv - \\xv} ^3} .\n\\end{equation}\nSimilarly, in 2D we find\n\\begin{equation}\n  \\label{eq:14}\n  \\pd{\\Green}{\\nv} = \\frac{-1}{2 \\pi} \\pd{}{\\nv} (\\Gtwod) = \\frac{\\nv \\cdot (\\yv - \\xv)}{2 \\pi \\abs{\\yv - \\xv}^2}.\n\\end{equation}\n\n\\newcommand{\\bminta}{I}\n\\newcommand{\\bmint}{\\bminta_{ij}}\n\nSo the boundary element matrix in $d=2,3$ dimensions has the entries\n\\begin{equation}\n  \\label{eq:19}\n  \\bm_{\\ibasis\\ibasisb} =\\frac{-1}{2^{(d-1)} \\pi} \\bmint\n    + \\gamma(\\xv_\\ibasis)\\delta_{\\ibasisb\\ibasis},\n\\end{equation}\nwhere\n\\begin{equation}\n  \\bmint = \\int_{\\boundd_\\ibasisb} \\tbfone_{\\ibasisb}(\\yv) \\frac{\\nv(\\yv) \\cdot (\\yv - \\xv_\\ibasis)}{\\abs{\\yv - \\xv_\\ibasis} ^d} \\d \\yv.\n\\label{eq:bmint}\n\\end{equation}\n\n\n\\section{Evaluation of the discrete boundary operator}\n\\label{sec:calc-integr-i_bm}\n\nIn \\thisref{sec:calc-integr-i_bm} we discuss methods of calculating the entries of the discrete boundary element matrix, $\\bm_{\\ibasis\\ibasisb}$.\nFirstly we discuss the apparent singularity in the integral \\cref{eq:bmint}, then we give two methods for evaluating these integrals: an analytical method and a numerical method.\n\n\\subsection{Apparent singularity of the main integral}\n\\label{sec:bem-singularity}\n\nOne factor that should be considered before attempting to evaluate the integral $\\bmint$ from \\cref{eq:bmint} is the apparent singularity when integrating over an element containing the source point $\\xv_\\ibasis$.\nHowever it is easy to show that there is no singularity when the element is flat.\nIn this case, if $\\xv_\\ibasisb$ is within the element being integrated over, then we have a factor of\n\\begin{equation}\n  \\label{eq:7}\n  \\nv(\\yv) \\cdot (\\yv - \\xv_i) \\equiv 0,\n\\end{equation}\nin the integrand.\nFor all points $\\yv$ in the element this term is zero by the definition of $\\nv$, so the integral is zero and the singularity is avoided.\n\nFor the case when $\\xv_i$ is outside the element this is not necessarily true.\nIn particular: elements near sharp corners of a domain may be very close to a node that is not in the plane of the element (\\ie such that $\\nv(\\yv) \\cdot (\\yv - \\xv_i) \\neq 0$), resulting in a \\emph{near}-singular integral.\nThis means that care must be taken in order to evaluate the integrals accurately.\n% what kind of near singular integral? -- Andrew. Well, it depends on the\n% type of the singularity, as described in the previous section.\n\n\n\\subsection{Analytical solutions}\n\n\\newcommand{\\svu}{\\unitv{s}}\n\\newcommand{\\rvu}{\\unitv{r}}\n\nFor linear test/solution basis functions and triangular elements an exact analytical solution for the integral \\cref{eq:bmint} was given by Lindholm \\cite[App. B]{Lindholm1984}.\\footnote{Note: Lindholm's definition of the 3D Green's function is a factor of $-1$ different to \\cref{eqn:greenslaplacian2d,eqn:greenslaplacian3d}.}\nCombining equations (2) and (3) from \\cite{Lindholm1984} with \\cref{eq:13} and using our notation for nodal positions, we see that Lindholm's $L$ operator is\n\\begin{equation}\n  \\begin{aligned}\n    L[U] &= \\frac{-1}{4 \\pi}\\int_\\boundd U(\\yv) \\frac{\\nv(\\yv) \\cdot (\\yv -\n      \\xv)}{\\abs{\\xv - \\yv}^2}\n    \\d\\yv, \\\\\n    &= -\\bmop[U] + \\gamma(\\xv) U(\\xv).\n  \\end{aligned}\n\\end{equation}\nThus $L[\\tbfone_{\\ibasisb}]$ integrated over the patch of elements $\\boundd_\\ibasisb$ with $\\xv = \\xv_\\ibasis$ corresponds exactly to $\\frac{1}{4\\pi}\\bmint$, as required in the calculation of $G_{i,j}$.\\footnote{The minus sign from the different definitions of the Green's function has cancelled with the minus sign from the fact that we are interested in calculating $-1$ times the operator.}\n\n% To clearly see the equivalence between the discretised operators we need to go through both discretisations simultaneously.\n% Ignoring sharp corners we have that\n% \\begin{equation}\n%   \\begin{aligned}\n%     \\phim(\\xv) = G[\\phione](\\xv) &= -L[\\phione](\\xv), \\\\\n%     %\n%     \\sum_{n} \\phim_n \\tbf_n(\\xv)\n%     &= - \\sum_{\\tri=1}^{N_\\tri} \\sum_{i=1}^{3} L_{\\tri,i}(\\xv) \\phione_{\\tri,i},\n%     \\quad\\quad&\\text{expand}\\\\\n%     %\n%     \\sum_{n} \\phim_n \\tbf_n(\\xv)\n%     &= - \\sum_{\\tri=1}^{N_\\tri} \\sum_n L_{\\tri,n}(\\xv) \\phione_n,\n%     &\\text{equivalent to sum over all nodes--local support}\\\\\n%     %\n%     \\phim_k &= - \\sum_{\\tri=1}^{N_\\tri} \\sum_n L_{\\tri,n}(\\xv_k) \\phione_n,\n%     &\\text{use $\\tbf_n(\\xv_k) = \\delta_{nk}$}\\\\\n%     %\n%     \\phim_k &= \\sum_n \\bigs{\\sum_{\\tri=1}^{N_\\tri} -L_{\\tri,n}(\\xv_k)} \\phione_n,\n%     &\\text{reorder}\\\\\n%     %\n%     \\phim_k &= \\sum_n \\bigs{\\sum_{\\tri \\in \\text{around}(n)} -L_{\\tri,n}(\\xv_k)} \\phione_n,\n%     &\\text{reduce elements to sum over--local support again}\\\\\n%     %\n%     &= \\sum_n G_{k,n} \\phione_n.\n%     &\\text{equation~\\cref{eq:10}}\n%   \\end{aligned}\n% \\end{equation}\n% Therefore\n% \\begin{equation}\n%   IG_{i,j} = \\sum_{\\tri \\in \\text{around}(j)} L_{\\tri,k}(\\xv_i),\n% \\end{equation}\n% where $k$ is the index of node $j$ within triangle $\\tri$.\n\nWe now give the analytical solution from Lindholm in the notation used here.\nLet $A_\\tri$ be the area of the triangle, $\\zv_{i,\\tri}$ denote the position of the $(i \\mod 3)$-th node of triangle $\\tri$, and $\\nv_\\tri$ be the outer unit normal to the plane of the triangle (``outer'' with respect to the domain $\\magd$).\nWe write the vector from triangle node $k$ to $\\xv$ as\n\\begin{equation}\n  \\rv_{k,\\tri}(\\xv) = \\zv_{k,\\tri} - \\xv,\n\\end{equation}\nthe vector along an edge of the triangle and\n\\begin{equation}\n  \\sv_{k,\\tri} = \\zv_{k+1,\\tri} - \\zv_{k,\\tri},\n\\end{equation}\nand $\\svu$ for the equivalent unit vector.\nThen using the third (un-numbered) equation in appendix B of \\cite{Lindholm1984}, converting to our notation and substituting in values from the rest of the paper where practical we have\n\\begin{equation}\n  \\begin{aligned}\n    \\label{eq:analytic-bem-integral}\n    \\frac{1}{4\\pi}\\bmint = \\sum_{\\tri \\in \\boundd_j} \\frac{\\abs{\\sv_{k+1,\\tri} }}{8 \\pi A_\\tri}\n    \\Bigg[&\n      \\Big( (\\nv_\\tri \\times \\svu_{k+1,\\tri}) \\cdot \\rv_{k+1,\\tri}(\\xv_i)\\Big) \\Omega_\\tri(\\xv_i) \\\\\n      &- \\nv_\\tri \\cdot \\rv_{1,\\tri}(\\xv_i) \\sum_{l=1}^{3}\n      (\\svu_{k+1,\\tri} \\cdot \\svu_{l,\\tri}) P_{l,\\tri}(\\xv_i)\n    \\Bigg],\n  \\end{aligned}\n\\end{equation}\nwhere, as before, $\\boundd_j$ is the set of triangles that are in contact with the node $j$.\nThe quantity $P_{l,\\tri}(\\xv)$ is given by\n\\begin{equation}\n  P_{l,\\tri}(\\xv) = \\ln\\bigb{\\frac{\\abs{\\rv_{l,\\tri}(\\xv)} + \\abs{\\rv_{l+1,\\tri}(\\xv)} + \\abs{\\sv_{l,\\tri}}}\n    {\\abs{\\rv_{l,\\tri}(\\xv)} + \\abs{\\rv_{l+1,\\tri}(\\xv)} - \\abs{\\sv_{l,\\tri}}}}.\n\\end{equation}\nFinally we need $\\Omega_\\tri$, the solid angle subtended by the triangle at $\\xv_i$:\n\\begin{equation}\n  \\label{eq:bem-triangle-solid-angle}\n  \\Omega_\\tri(\\xv) = \\text{sign}(\\nv_\\tri \\cdot \\rv_1) 2 \\arccos\\bigs{\\frac\n    {\\abs{\\rv_1}\\abs{\\rv_2}\\abs{\\rv_3} + \\abs{\\rv_1} \\rv_2\\cdot\\rv_3 + \\abs{\\rv_2}\\rv_1\\cdot \\rv_2}\n    {\\sqrt{2(\\abs{\\rv_2}\\abs{\\rv_3} + \\rv_2\\cdot\\rv_3)\n        (\\abs{\\rv_3}\\abs{\\rv_1} + \\rv_3\\cdot\\rv_1)\n        (\\abs{\\rv_1}\\abs{\\rv_2} + \\rv_1\\cdot\\rv_2)}}},\n\\end{equation}\nwhere we have dropped the $\\xv$ argument and $\\tri$ index from $\\rv_{i,\\tri}(\\xv)$ for brevity.\nThe use of $\\rv_1(\\xv)$ in \\cref{eq:analytic-bem-integral,eq:bem-triangle-solid-angle} is not a typo: the results are independent of which node in the triangle is used.\n\n\nA useful open source implementation of this calculation in C is included in \\magpar \\cite{magpar-website} and redistributed in \\nmag \\cite{nmag-website}.\n\n\n\\subsection{Adaptive numerical quadrature}\n\n\\newcommand{\\tolq}{\\epsilon_q}\n\nThe analytical formula given in the previous section is highly accurate but is only applicable to 2D triangular boundary elements, \\ie 3D tetrahedral bulk elements.\nHowever, it is very useful when testing code to be able to run 2D simulations since the run time can be orders of magnitude smaller.\nIt is also sometimes useful to be able to use structured quadrilateral meshes for simple geometries and for testing purposes.\nFor such meshes an adaptive numerical quadrature able to accurately integrate $\\bmint$ is appropriate.\nIt is likely that similar analytical results could be derived for each of these cases, but it is simpler and more general to use a numerical approach instead.\n% Has this been done? Ref? -- Andrew No idea, but from looking through my\n% BEM textbooks it looks like analytical solutions are only well known for\n% constant elements (mentioned in Wrobel2002, chapter on numerical\n% integration).\n\nAs discussed in \\cref{sec:bem-singularity} the integral $\\bmint$ is non-singular, so no special techniques are needed for its integration (other than what is needed to attain good accuracy).\nAs such an adaptive quadrature method can effectively calculate the integrals.\nWe use a simple adaptive quadrature algorithm as follows:\n\n\\begin{algorithm}[H]\n  Calculate the integral $\\bmint$ with a quadrature of order $n_1$ to obtain $I_1$\\;\n  Calculate the integral $\\bmint$ with a quadrature of order $n_2$ to obtain $I_2$\\;\n  \\While{$\\abs{\\frac{I_1 - I_2}{I_2}} \\geq \\tolq$}{\n    \\nllabel{algo:next-quad} Set $I_1 = I_2$, $n_2 = 2n_2$\\;\n    Calculate the integral $\\bmint$ with a quadrature of order $n_2$ to obtain $I_2$\\;\n  }\n\\end{algorithm}\n\nThe choice to double the quadrature order after each non-convergence in line~\\ref{algo:next-quad} means that little time is wasted attempting to evaluate near-singular integrals with low order quadratures.\n\nIt is possible to optimise this process by using a quadrature scheme which reuses the knots (\\ie evaluation points) from the lower order calculations in the more accurate calculations, such as the Clenshaw-Curtis quadrature \\cite{Trefethen2008}.\nHowever, for simplicity, we have not implemented the reuse of knot values.\n\nThe implementation of this algorithm in \\oomph uses standard Gaussian quadrature (as mentioned in \\cref{sec:numer-eval-integrals}) with $\\tolq = 10^{-8}$, starting orders of $n_1=2$, $n_2=4$, and a maximum order of $256$.\nThese parameters gave good accuracy\\footnote{Errors of below $\\tolq$ when compared with the analytical formula for triangular elements.} and sufficiently fast computation time such that the time spent computing these integrals is not a major component of the overall computation time.\nAs such we did not experiment with varying these values.\n\n\n\\section{Conclusions}\n\nIn this chapter we have derived a hybrid FEM/BEM approach to calculating the magnetostatic field generated by a magnetic body.\nThis approach is beneficial in that it enforces the boundary condition on the potential at infinity without requiring calculations on an infinite domain.\nHowever, it involves a dense matrix of size proportional to the number of boundary nodes, and the process of evaluating the required integrals is more complex that those given by a FEM discretisation.\n\nWe have also described general methods for the evaluation of the resulting integrals using numerical quadrature and a less general method for a common case using an analytical formula.\nThere is a large scope for improving the efficiency of the adaptive numerical quadrature described here.\nHowever, such optimisations were not investigated because the evaluation of the boundary matrix is not a performance critical component of the coupled LLG-magnetostatics problem since it only needs to be evaluated once for a given mesh.\n\nWhile we have followed the convention in computational micromagnetics of using a collocation approach to discretise the BEM operator, a Galerkin approach may be more appropriate.\nIn particular, we note that the authors of \\hlib use a Galerkin approach \\cite{Borm2003}.\n\n%%% Local Variables:\n%%% mode: Latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "3a77a6bb76e1c96a588424ee747ce895f91cc990", "size": 33379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "boundary-elements.tex", "max_stars_repo_name": "davidshepherd7/thesis", "max_stars_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-13T10:36:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-28T21:11:27.000Z", "max_issues_repo_path": "boundary-elements.tex", "max_issues_repo_name": "davidshepherd7/thesis", "max_issues_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "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": "boundary-elements.tex", "max_forks_repo_name": "davidshepherd7/thesis", "max_forks_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "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.1826241135, "max_line_length": 461, "alphanum_fraction": 0.7184457294, "num_tokens": 10475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6172997095628932}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{nopageno} \n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[normalem]{ulem}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\nJon Allen\n\nFebruary 12, 2014\n\n\\section*{14}\nGenerate the 6-tuples of 0s and 1s by using the base 2 arithmetic generating scheme and identify them with subsets of the set $\\{x_5,x_3,x_2,x_1,x_0\\}$.\n\n000000$\\to\\emptyset$ 000001$\\to\\{x_0\\}$\n000010$\\to\\{x_1\\}$ 000011$\\to\\{x_1,x_0\\}$\n000100$\\to\\{x_2\\}$ 000101$\\to\\{x_2,x_0\\}$\n000110$\\to\\{x_2,x_1\\}$ 000111$\\to\\{x_2,x_1,x_0\\}$\n001000$\\to\\{x_3\\}$ 001001$\\to\\{x_3,x_0\\}$\n001010$\\to\\{x_3,x_1\\}$ 001011$\\to\\{x_3,x_1,x_0\\}$\n001100$\\to\\{x_3,x_2\\}$ 001101$\\to\\{x_3,x_2,x_0\\}$\n001110$\\to\\{x_3,x_2,x_1\\}$ 001111$\\to\\{x_3,x_2,x_1,x_0\\}$\n010000$\\to\\{x_4\\}$ 010001$\\to\\{x_4,x_0\\}$\n010010$\\to\\{x_4,x_1\\}$ 010011$\\to\\{x_4,x_1,x_0\\}$\n010100$\\to\\{x_4,x_2\\}$ 010101$\\to\\{x_4,x_2,x_0\\}$\n010110$\\to\\{x_4,x_2,x_1\\}$ 010111$\\to\\{x_4,x_2,x_1,x_0\\}$\n011000$\\to\\{x_4,x_3\\}$ 011001$\\to\\{x_4,x_3,x_0\\}$\n011010$\\to\\{x_4,x_3,x_1\\}$ 011011$\\to\\{x_4,x_3,x_1,x_0\\}$\n011100$\\to\\{x_4,x_3,x_2\\}$ 011101$\\to\\{x_4,x_3,x_2,x_0\\}$\n011110$\\to\\{x_4,x_3,x_2,x_1\\}$ 011111$\\to\\{x_4,x_3,x_2,x_1,x_0\\}$\n100000$\\to\\{x_5\\}$ 100001$\\to\\{x_5,x_0\\}$\n100010$\\to\\{x_5,x_1\\}$ 100011$\\to\\{x_5,x_1,x_0\\}$\n100100$\\to\\{x_5,x_2\\}$ 100101$\\to\\{x_5,x_2,x_0\\}$\n100110$\\to\\{x_5,x_2,x_1\\}$ 100111$\\to\\{x_5,x_2,x_1,x_0\\}$\n101000$\\to\\{x_5,x_3\\}$ 101001$\\to\\{x_5,x_3,x_0\\}$\n101010$\\to\\{x_5,x_3,x_1\\}$ 101011$\\to\\{x_5,x_3,x_1,x_0\\}$\n101100$\\to\\{x_5,x_3,x_2\\}$ 101101$\\to\\{x_5,x_3,x_2,x_0\\}$\n101110$\\to\\{x_5,x_3,x_2,x_1\\}$ 101111$\\to\\{x_5,x_3,x_2,x_1,x_0\\}$\n110000$\\to\\{x_5,x_4\\}$ 110001$\\to\\{x_5,x_4,x_0\\}$\n110010$\\to\\{x_5,x_4,x_1\\}$ 110011$\\to\\{x_5,x_4,x_1,x_0\\}$\n110100$\\to\\{x_5,x_4,x_2\\}$ 110101$\\to\\{x_5,x_4,x_2,x_0\\}$\n110110$\\to\\{x_5,x_4,x_2x_1\\}$ 110111$\\to\\{x_5,x_4,x_2x_1,x_0\\}$\n111000$\\to\\{x_5,x_4,x_3\\}$ 111001$\\to\\{x_5,x_4,x_3,x_0\\}$\n111010$\\to\\{x_5,x_4,x_3,x_1\\}$ 111011$\\to\\{x_5,x_4,x_3,x_1,x_0\\}$\n111100$\\to\\{x_5,x_4,x_3,x_2\\}$ 111101$\\to\\{x_5,x_4,x_3,x_2,x_0\\}$\n111110$\\to\\{x_5,x_4,x_3,x_2,x_1\\}$ 111111$\\to\\{x_5,x_4,x_3,x_2,x_1,x_0\\}$\n\\section*{16}\nFor each of the subsets (a), (b), (c), and (d) in the preceding exercise, determine the subset that immediately \\emph{precedes} it in the base 2 arithmetic generating scheme.\n\\subsection*{(a)}\n$\\{x_4,x_1,x_0\\}=00010011\\gets00010010$, or $\\{x_4,x_1\\}$.\n\\subsection*{(b)}\n$\\{x_7,x_5,x_3\\}=10101000\\gets10100111$, or $\\{x_7,x_5,x_2,x_1,x_0\\}$\n\\subsection*{(c)}\n$\\{x_7,x_5,x_4,x_3,x_2,x_1,x_0\\}=10111111\\gets10111110$, or $\\{x_7,x_5,x_4,x_3,x_2,x_1\\}$\n\\subsection*{(d)}\n$\\{x_0\\}=00000001\\gets00000000$, or $\\emptyset$\n\\section*{17}\nWhich subset of $\\{x_7,x_6,\\dots,x_1,x_0\\}$ is 150th on the list of subsets of $S$ when the base 2 arithmetic generating scheme is used? 200th? 250th? (As in Section 4.3, the places on the list are numbered beginning with 0.)\n\\begin{align*}\n  2^0&=1&\n  2^1&=2&\n  2^2&=4&\n  2^3&=8&\n  2^4&=16&\n  2^5&=32&\n  2^6&=64&\n  2^7&=128\n\\end{align*}\n\\begin{align*}\n  150&=128+16+4+2\\to\\{x_7,x_4,x_2,x_1\\}&\n  200&=128+64+8\\to\\{x_7,x_6,x_3\\}\\\\\n  250&=128+64+32+16+8+2\\to\\{x_7,x_6,x_5,x_4,x_3,x_1\\}\n\\end{align*}\n\\section*{22}\nDetermine the reflected Gray code of order 6.\n\n000000 000001 000011 000010 000110 000111 000101 000100\n001100 001101 001111 001110 001010 001011 001001 001000\n011000 011001 011011 011010 011110 011111 011101 011100\n010100 010101 010111 010110 010010 010011 010001 010000\n110000 110001 110011 110010 110110 110111 110101 110100\n111100 111101 111111 111110 111010 111011 111001 111000\n101000 101001 101011 101010 101110 101111 101101 101100\n100100 100101 100111 100110 100010 100011 100001 100000\n\n\\section*{24}\nDetermine the predecessors of each of the 9-tuples in Exercise 23 in the reflected Gray code of order 9.\n\\subsection*{(a)}\n$010100110\\gets010100010$\n\\subsection*{(b)}\n$110001100\\gets110000100$\n\\subsection*{(c)}\n$111111111\\gets111111110$\n\\section*{27}\nGenerate the 2-subsets of $\\{1,2,3,4,5,6\\}$ in lexicographic order by using the algorithm described in Section 4.4.\n\\[\\begin{array}{ccc}\n  12&23&35\\\\\n  13&24&36\\\\\n  14&25&45\\\\\n  15&26&46\\\\\n  16&34&56\\\\\n\\end{array}\\]\n\\section*{29}\nDetermine the 7-subset of $\\{1,2,\\dots,15\\}$ that immediately follows 1,2,4,6,8,14,15 in the lexicographic order. Then determine the 7-subset that immediately precedes 1,2,4,6,8,14,15.\n\nSince 14 and 15 are as high as we can go we increment the 8 and start counting from there.\n\\[1,2,4,6,8,14,15\\text{ is followed by }1,2,4,6,9,10,11\\]\n\nSince we can't decrement the 15 to 14 because we already have a 14 we decrement the 14 to 13 and leave the 15 since it is the max and we want it to roll over on the next count up.\n\\[1,2,4,6,8,14,15\\text{is preceded by}1,2,4,6,8,13,15\\]\n\n\\section*{31}\nGenerate the 3-permutations of $\\{1,2,3,4,5\\}$\n\\begin{align*}\n  \\begin{array}{cccccccccc}\n    123&124&125&134&135&145&234&235&245&345\\\\\n    132&142&152&143&153&154&243&253&254&354\\\\\n    312&412&512&413&513&514&423&523&524&534\\\\\n    321&421&521&431&531&541&432&532&542&543\\\\\n    231&241&251&341&351&451&342&352&452&453\\\\\n    213&214&215&314&315&415&324&325&425&435\\\\\n  \\end{array}\n\\end{align*}\n\\section*{33}\nIn which position does the subset 2489 occur in the lexicographic order of the 4-subsets of $\\{1,2,3,4,5,6,7,8,9\\}$?\n\nUsing theorem 4.4.2 we have:\n\\[\\binom{9}{4}-\\binom{7}{4}-\\binom{5}{3}-\\binom{1}{2}-\\binom{0}{1}=\\frac{9!}{4!(9-4)!}-\\frac{7!}{4!(7-4)!}-\\frac{5!}{4!(5-3)!}-0-0=81\\]\n\n\\section*{34}\nConsider the r-subsets of $\\{1,2,\\dots,n\\}$ in lexicographic order.\n\\subsection*{(a)}\nWhat are the first $(n-r+1)$ $r$-subsets?\n\\begin{align*}\n  \\{1,2,\\dots, (r-1),&r\\}\\\\\n  \\{1,2,\\dots, (r-1),&(r+1)\\}\\\\\n  &\\vdots\\\\\n  \\{1,2,\\dots, (r-1),&n\\}\n\\end{align*}\nThe first $(n-r+1)$ subsets all contain $1,2,\\dots,(r-1)$ and then one last element that is all the numbers $r,\\dots,n$\n\\subsection*{(b)}\nWhat are the last $(r+1)$ $r$-subsets?\n\\begin{align*}\n  \\{(n-r+1)(n-r+2)\\dots(n-1)(n)\\}\\\\\n  \\{(n-r)(n-r+2)\\dots(n-1)(n)\\}\\\\\n  \\{(n-r)(n-r+1)(n-r+3)\\dots(n-1)(n)\\}\\\\\n  \\{(n-r)(n-r+1)\\dots(n-1)\\}\n\\end{align*}\nBasically the last subset is the last $r$ elements. Each of the preceeding $r$ subsets decreases by one the element that corresponds with how far from the last subset we are.\n\\section*{35}\nThe \\emph{complement} $\\bar{A}$ of an $r$-subset $A$ of $\\{1,2,\\dots,n\\}$ is the $(n-r)$-subset of $\\{1,2,\\dots,n\\}$, consisting of all those elements that do not belong to $A$. Let $M=\\binom{n}{r}$, the number of $r$-subsets and, at the same time, the number of $(n-r)$-subsets of $\\{1,2,\\dots,n\\}$. Prove that, if\n\\[A_1,A_2,A_3,\\dots,A_M\\]\nare the $r$-subsets in lexicographic order, then\n\\[\\overline{A_M},\\dots,\\overline{A_3},\\;\\overline{A_2},\\;\\overline{A_1}\\]\nare the $(n-r)$-subsets in lexicographic order.\n\\subsection*{lemma}\nReversing theorem 4.4.1 from the text we get the following lemma.\n\nLet $a_1a_2\\dots a_r$ be an $r$-subset of $\\{1,2,\\dots,n\\}$. The last $r$-subset in the lexicographic ordering is $(n-r+1)(n-r+2)\\dots n$. Assume that $a_1a_2\\dots a_r\\neq 12\\dots r$. Let $k$ be the largest integer such that $a_k>1$ and $a_k-1$ is different from each of $a_1,\\dots,a_{k-1}$ then the $r$-subset that is the immediate predecessor of $a_1a_2\\dots a_r$ in the lexicographic ordering is $a_1\\dots a_{k-1}(a_k-1)(n-r+k+1)\\dots n$\n\\subsection*{Proof}\nFirst let's take care of the trivial cases.\n\nLet $n<r$. Then $A_1=A_M=\\emptyset$ and $\\overline{A_1}=\\overline{A_M}=\\{1,2,\\dots,n\\}$. Since there is only one subset we are done.\n\nLet $n=r$. Then $A_1=A_M=\\{1,2,\\dots,n\\}$ and $\\overline{A_1}=\\overline{A_M}=\\emptyset$. Since there is only one subset we are done.\n\nLet $n>r$\n\nLet's look at $A_1$. It is $\\{1,2,\\dots,r\\}$. We also know that $A_M$ is $\\{(n-r+1),(n-r+2),\\dots,n\\}$ so $\\overline{A_M}$ is $\\{1,2,\\dots,(n-r)\\}$ which is by definition the first $(n-r)$-subset in lexicographical order.\n\nNow we find that $A_{M-1}$ is $\\{n-r,n-r+2,\\dots,n\\}$. The complement of this is $\\{1,2,\\dots,n-r-1,n-r+1\\}$. And the successor to $\\overline{A_M}$ is $\\{1,2,\\dots,n-r-1,n-r+1\\}$ So we see that the hypothesis holds for $A_M$ and $A_{M-1}$\n\nNow lets take some random subset $A_i=a_1a_2\\dots a_{n-r}$. Determine $k$ as in the lemma above. Then\n\\[a_1a_2\\dots a_r=a_1\\dots a_{k-1}a_k(n-r+k+1)\\dots n\\]\nwhere \\[a_k-1>a_{k-1}\\]\nThus the immediate predecessor of $a_1a_2\\dots a_r$ is $A_{i-1}=a_1\\dots a_{k-1}(a_k-1)(n-r+k+1)\\dots n$\n\nLet us take $\\overline{A_{i}}$. We know that $a_k(a_k+1)\\dots (a_k+r-k-1)(a_k+r-k)\\not\\in\\overline{A_i}$ and $a_1\\dots a_{k-1}\\not\\in\\overline{A_i}$ but that $a_k-1\\in\\overline{A_i}$. Further we know that $(a_k+r-k+1)\\dots n\\in\\overline{A_i}$. Notice that if we ``shift'' this $r-k$ places we have $a_k+1\\dots n-r+k$ and $|a_k+1\\dots n-r+k|=|(a_k+r-k+1)\\dots n|$. We don't really care anything about the part of $\\overline{A_i}$ before $a_k$ so we'll just call it $b_1\\dots b_p$. So the successor to $\\overline{A_i}$ is $b_1\\dots b_pa_k(a_k+1)(a_k+2)\\dots (n-r+k)$.\nAnd if we examine $\\overline{A_{i-1}}$ we will have the same $b_1\\dots b_p$ that $\\overline{A_i}$ has since we didn't change anything before $a_k$. And we have $(a_k-1)(n-r+k+1)\\dots n\\not\\in\\overline{A_{i-1}}$. Anything leftover must be in $\\overline{A_{i-1}}$ so we have $\\overline{A_{i-1}}=b_1\\dots b_pa_k(a_k+1)\\dots(n-r+k)$. Which is precisely the successor of $\\overline{A_i}$ and so we have proven our result by induction.\n\n\\end{document}\n", "meta": {"hexsha": "2875f1a86b8c354ddfca13dfbc4acbe6a27201d3", "size": 9430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-02-12.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-02-12.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-02-12.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": 50.6989247312, "max_line_length": 565, "alphanum_fraction": 0.669883351, "num_tokens": 4338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955813, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6171992356529703}}
{"text": "% !TeX encoding = UTF-8\n\\section{Safety of multigram}\nLet's introduce some reducible multigrams: A \\textit{tetragram} is a sequence ($v_1$, $v_2$, $v_3$, $v_4$) of vertices of $G$ such that it can build a facial cycle in this listed order. Analogously, we can define a \\textit{hexagram} ($v_1$, $v_2$, $v_3$, $v_4$, $v_5$, $v_6$). And a \\textit{pentagram} ($v_1$, $v_2$, $v_3$, $v_4$, $v_5$) is also defined likewise but with the limitation: $v_1$, $v_2$, $v_3$, $v_4$ have degree exactly three.\n\n\\subsection{Safe multigrams}\nAs was pointed out in the second section of this thesis, the detected multigrams should possess some attributes, which is called \\textit{safety}. Assume that $k$ = 4, 5, 6 and ($v_1, v_2, ..., v_k$) be a tetra-, penta- or hexagram in a triangle-free planar graph $G$. On the occasion that $k$ = 4 or $k$ = 6, the tetragram or hexagram is $safe$ if every path in $G$ of length at most three with ends $v_1$ and $v_3$ is a subgraph of cycle $v_1v_2...v_k$, which means the path(s) from $v_1$ to $v_3$ of length at most three has to be part of multigrams. The safety of pentagram is bit complicated: let $x_i$ be the neighbor of $v_i$ different from $v_{i-1}$ and $v_{i+1}$, where $v_0 = v_5$. Thus $x_i \\notin$ \\{$v_1, v_2, v_3, v_4, v_5$\\} for the reason that if that is the case, the vertices $v_i$, $x_i$ form a triangle with $v_{i-1}$ or $v_{i+1}$, which is a contradiction to the triangle-free graph. A pentagram ($v_1, v_2, v_3, v_4, v_5$) is \\textit{safe} \\cite{dvorak2013threecoloring}, if\n\\begin{itemize}\n    \\item the vertices $x_1, x_2, x_3, x_4$ are pairwise distinct and pairwise non-adjacent, and\n    \\item there is no path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three from $x_2$ to $v_5$, and\n    \\item every path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three from $x_3$ to $x_4$ has length exactly two, and its completion via the path $x_3v_3v_4x_4$ results in a facial cycle of length five in $G$.\n\\end{itemize}\n\n\\begin{definition}\nGiven a graph $G$ = ($V$, $E$), \\textit{identifying a pair of vertices} means that the two selected vertices $u, v \\in V(G)$ will be \"glued\" as a vertex $s$ and the neighbor of $s$ is the union of $u, v$'s neighbors. After that we'll then obtain a new graph $G^{'}$ = ($V^{'}$, $E^{'}$), where $V^{'} = V \\backslash \\{u, v\\} \\cup \\{s\\}$ and $E^{'}$ will be obtained by deleting parallel edges from $E$ after gluing the vertices.  It results $|V(G^{'})| = |V(G)| - 1$.\n\\end{definition}\n\n\\subsection{Identifying vertices and reconstruction of graph}\n\nIf there exists a safe tetra- or hexagram, $G^{'}$ can be obtained by identifying vertices $v_1$ with $v_3$. $v_1$ in \\textbf{Figure 6, 7} is at the same time $v_3$ as well. For \\textit{tetragram} $(v_1, v_2, v_3, v_4)$:\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/identifyingv1v3.png} \n\\label{figure} %用于文内引用的标签\n\\caption{Identifying $v_1$ and $v_3$ in a safe tetragram}\n\\end{figure}\n\n\\textit{Reconstruction step: }In graph $G^{'}$, we can assign colors as follows: let $c_1$ be the color of $v_2$, $c_2$ be the color of $v_1$ and $c_3$ be the color of $v_4$. Clearly that we can also color $v_3$ with $c_2$, since $v_1$ and $v_3$ are not adjacent and the tetragram is safe.\\\\\n\nFor \\textit{hexagram} $(v_1, v_2, v_3, v_4, v_5, v_6)$: \n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/identifyingv1v32.png} \n\\label{figure} %用于文内引用的标签\n\\caption{Identifying $v_1$ and $v_3$ in a safe hexagram}\n\\end{figure}\n\n\\textit{Reconstruction step: }In graph $G^{'}$, we can assign colors following these principles: let $c_1$ be the color of $v_2$, $c_2$ be the color of $v_1$. We can determine colors of $v_4$ and $v_6$ arbitrarily. Assume that the color of $v_4$ and $v_6$ is $c_3$ and the color of $v_5$ is $c_1$. Apparently, the color $c_2$ can be designated for $v_3$ as well, since $v_1$ and $v_3$ are not adjacent and the hexagram is safe.\\\\\n\nThe case of pentagram ($v_1$, $v_2$, $v_3$, $v_4$, $v_5$) is significantly different. $G^{'}$ will be attained from $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ by identifying $v_5$ with $x_2$ and $x_3$ with $x_4$.\n\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=1.1\\textwidth]{figure/pentagramidentift.png} \n\\label{figure} %用于文内引用的标签\n\\caption{Identifying $v_5, x_2$ and $x_3, x_4$ in a safe pentagram}\n\\end{figure}\n\n\\textit{Reconstruction step: }In graph $G^{'}$, let $c_1$ be the color of $x_1$, $c_2$ the color of $x_2$ and $v_5$, and $c_3$ the color of $x_3$ and $x_4$. Consider the following cases:\n\\begin{itemize}\n    \\item $c_1 = c_2$, we will color the remaining vertices in this order ($v_4, v_3, v_2, v_1$). Since there are at most two remaining colors when $v_i$ is colored, we can simply choose the third color for it. \n    \\item $c_2 = c_3$, similarly, we will color the vertices in the reversed order as in the first case.\n    \\item $c_1 \\ne c_2$ and $c_2 \\ne c_3$, we can color $v_2$ with $c_1$, $v_1$ with $c_3$, $v_3$ with $c_2$ and $v_4$ with $c_1$.\n\\end{itemize}\n\n\\subsection{Counterexamples: unsafe multigrams}\nSubsequently, let's take care of the importance of multigrams. What happens, when we identify certain pair of vertices if the given multigrams are not safe? If a tetragram or hexagram is not safe, then there exists a path of length at most three that is not part of tetragram or hexagram.\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/unsafetetragram.png} \n\\caption{An unsafe tetragram} %最终文档中希望显示的图片标题\n\\label{figure} %用于文内引用的标签\n\\end{figure}\n\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/unsafehexagram.png} \n\\caption{An unsafe hexagram} %最终文档中希望显示的图片标题\n\\label{figure} %用于文内引用的标签\n\\end{figure}\nObserve from above figures that after identifying vertices $v_1$ with $v_3$, a triangle consisting of $s, t, v_1$ will be created.\\newline \\\\\nIf a pentagram is not safe, then it has either a path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ at most three from $x_2$ to $v_5$ or a path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ from $x_3$ to $x_4$ of length 3.\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/Inkedunsafepentagram1_LI.jpg} \n\\label{figure} %用于文内引用的标签\n\\caption{Unsafe pentagram, case 1}\n\\end{figure}\n\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.7\\textwidth]{figure/unsafepentagram2.png} \n\\label{figure} %用于文内引用的标签\n\\caption{Unsafe pentagram, case 2}\n\\end{figure}\nNotice that in the former case, $v_5$($x_2$), $s$ and $t$ build a triangle and in the latter case, $x_3$($x_4$), $s$ and $t$ build a triangle in the same way.\n\n%----------------------------------------------------------------------\n\\section{Proof of Grötzsch's theorem}\nFirstly, we introduce a method that is often used in graph theory. \n\\textit{Discharging method} is an important proof technique in structural graph theory. The general process of discharging is this: we discharge the graph based on certain \"discharging rules,\" during which some elements gain charges, and some elements lose charges, while the sum of the charges stays constant. \\cite{wu2020introduction}\n\n\\begin{observation} Given $F$ is a set of all faces embedded in the graph $G$ = ($V$, $E$), then:\n\\begin{align*}\n    \\sum_{f \\in F}deg(f) = 2|E| \\ and \\ \\sum_{v \\in V}deg(v) = 2|E|\n\\end{align*}\n%$\\sum_{f \\in F}deg(f) = 2|E|$ and $\\sum_{v \\in V}deg(v) = 2|E|$.\n\\end{observation}\n\n\\begin{theorem}[Euler's formula]\nFor any planar graph with $v$ vertices, $e$ edges, and $f$ faces, we have $v - e + f = 2$. This equation is called \\textit{Euler's formula} for planar graphs. \\cite{Discrete_Mathematics}\n\\end{theorem}\n\n\\begin{proof}\nBy induction on the number of edges $e$.\\\\\n\\textit{Base case: } Show that the statement holds for the smallest natural number $e$ = 0.\\\\\n$e$ = 0, $v$ = 1, $f$ = 1 \\ $\\xrightarrow{}$ 1 - 0 + 1 = 2. \\\\\n\\\\\n\\textit{Inductive step: }Show that for any e $\\geq$ 0, if $e = n$ holds, then $e = n + 1$ holds as well. \\\\\n\\textit{Case 1: }$G$ is a tree. It follows $v = e + 1 = n + 2$, $f = 1$. $\\longrightarrow$ $v - e + f = (n + 2) - (n+1) + 1 = 2$.\\\\\n\\textit{Case 2: }There exists a simple cycle. Assume that there is a spanning tree $T$. $(u, v)$ is an edge which does not belong to $T$. The path between $u$ and $v$ builds a simple cycle with the edge $uv$. Removal of the edge $uv$ constructs a connect graph $G^{'}$ with $v^{'}$ $ = v$, $e^{'}$ $=e - 1$ and $f^{'}$ $= f - 1$. \\\\\nIt leads from induction hypothesis that 2 = $v^{'}$ - $e^{'}$ + $f^{'}$ = $v + (e - 1) + (f - 1) = v - e + f$.\\\n\\end{proof}\n\n\\begin{lemma}\nLet $G$ be a connected triangle-free plane graph and let $f_0$ be the\nunbounded face of $G$. Assume that the boundary of $f_0$ is a cycle $C$ of length\nat most six, and that every vertex of $G$ not on $C$ has degree at least three. If\n$G \\ne C$, then $G$ has either a tetragram, or a pentagram ($v_1, v_2, v_3, v_4, v_5$) such\nthat $v_1, v_2, v_3, v_4$ $\\notin V(C)$. \\cite{dvorak2013threecoloring}\n\\end{lemma}\n\n\\begin{proof}\nAssign the charge of a vertex $v$ to be 3deg($v$) - 12, the charge of the face $f_0$ to be $3|V(C)|$ + 11 and the charge of a face $f \\ne f_0$ of length $\\ell$ to be $3 \\ell - 12$. \n    \\begin{claim}\n    The sum of the charges of all vertices and faces is -1.\n    \\end{claim}\n    \\begin{proof}\n        \\begin{align*}\n            & Sum \\ of \\ charges \\ = \\sum_{v \\in V}(3deg(v) - 12) + \\sum_{f \\in F \\backslash {f_0}} (3\\ell - 12) + 3|V(C)| + 11 \\\\\n            &= \\underbrace{3 \\cdot 2|E| - 12 |V| + 3\\cdot2|E| - 12|F|}_{\\text{apply Euler's formula here: v + f - e = -2}} - (3\\ell_{f_0} - 12) + 3|V(C)| + 11 \\\\\n            &=-2 \\cdot 12 + 3|V(C)|- 3\\ell_{f_0} + 12 + 11\\\\\n            &= -1\n        \\end{align*}\n    \\end{proof}\n    Afterwards, we redistribute the charges conforming to the following rules:\n    \\begin{itemize}\n        \\item[(1)] Every vertex $v \\notin C$ and deg($v$) = 3 will receive one unit of charge from each incident face.\n        \\item[(2)] Every vertex $v \\in C$ and deg($v$) = 3 will receive three units from $f_0$.\n        \\item[(3)] Every vertex $v \\in C$ and deg($v$) = 2 will receive five units from $f_0$ and one unit from the other incident face. \n    \\end{itemize}\n    \n    \\begin{claim}\n    The final charge of $f_0$ is non-negative.\n    \\end{claim}\n    \n\\begin{proof}\nLet $\\ell$ be the size of cycle $C$. As we defined above, the initial charge of face $f_0$ is $3 \\ell + 11$. According to \\textbf{Lemma 4.2}($G \\ne C$), we know that there is at least one vertex on $C$ whose degree is at least three, which leads that there are at most $(\\ell - 1)$ vertices of $C$ with degree two and one vertex on $C$ has degree at least three. Thus, $f_0$ can send at most obeying rules (2) and (3) $\\big(5(\\ell - 1) + 3\\big)$ units of charge.\\\\\n$\\longrightarrow$ The final charge of $f_0$ = $3\\ell + 11 - 5(\\ell - 1) - 3 = 13 - 2\\ell \\geq 1$, since the length of the outer face is at most six.\n\\end{proof}\nNotice that among above three rules, all vertices do not send any units of charge. Hence, the charge of all vertices is also non-negative. In consonance with the definition of discharging method, the total sum before and after charging should keep unchanged, which contributes to the existence of a face $f \\ne f_0$ whose final charge is strictly negative. From rule (1) informed that $f$ will send at most one unit to each incident vertex. The final charge is $3\\ell - 12 - \\ell = 2\\ell - 12$, which is, as discussed, smaller than 0. It follows that the length of $f$ is at most five. Moreover, if $f$ has length exactly five, its initial charge is $3\\ell - 12 = 3$, then $f$ has to have at least four incident vertices. And all these vertices cannot be on $C$ and have degree two. Otherwise, $f$ will send nothing to the ends of the common subpath of $f$ and $f_0$. As a deduction, the vertices of $f$ structure a tetragram or a pentagram.\n\\end{proof}\n\n\\begin{lemma}\nEvery triangle-free plane graph $G$ of minimum degree at least three has a safe tetragram, a safe pentagram or a safe hexagram. \\cite{dvorak2013threecoloring}\n\\end{lemma}\n\\begin{proof}\nLet $G$ as stated. \n\n\\begin{claim}\nSuppose that $(v_1, v_2, v_3, v_4)$ is a tetragram in $G$ which bounds a face, then one of tetragrams $(v_1, v_2, v_3, v_4)$, $(v_2, v_3, v_4, v_1)$ is safe.\n\\end{claim}\n\n\\begin{proof}\nProve by contradiction: assume that both of tetragrams are unsafe, which implies that there is no pair of diagonally opposite vertices.\n\\begin{itemize}\n    \\item[(1)] \\textit{\\textbf{$v_1$ and $v_3$ is not the pair diagonally opposite vertices.}} So there is a path from $v_1$ to $v_3$ that is not part of graph $G$ of length at three. See the case in \\textbf{Figure 13}.\n    \\item[(2)] \\textit{\\textbf{$v_2$ and $v_4$ is not the pair diagonally opposite vertices.}} Then there must exist a path from $v_2$ to $v_4$ of length at most three. \n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.4\\textwidth]{figure/4face.png} \n    \\label{figure} %用于文内引用的标签\n    \\caption{4-face ($v_1, v_2, v_3, v_4$)}\n    \\end{figure}\n    Since the tetragram ($v_1, v_2, v_3, v_4$) is a 4-face, the path has to be outside of the face, which results that there is a cross among two paths which is a contradiction to the planarity.\n\\end{itemize}\n\\end{proof}\nTherefore, we may assume that $G$ has no 4-face. It follows that every 4-cycle is separating. If $G$ features a separating cycle of length at the most five, then select the separating cycle $C_1$ in order that the bounded disk is smallest possible and let $G_1$ be the subgraph of $G$ consisting of all vertices and edges drawn in the closed disk bounded by $C_1$. If $G$ has no separating cycle of length at most five, then let $G_1 := G$ and let $C_1$ be a facial cycle of $G$ of length at the most five. In addition, we reform the $G$ that $C_1$ is the outer face.\n\n\\begin{lemma}\nThe minimum degree of $G$ is at least three, then there exists a facial cycle $C_1$ of $G$ of length at most five.\n\\end{lemma}\n\n\\begin{proof}\nBy contradiction, assume there is no face of length at\nmost 5, which means every face has length at least 6. In this case, we have every vertex degree at least 3, so we have $e \\geq \\frac{3}{2} \\cdot v$ $\\Longleftrightarrow$ $v \\leq \\frac{2}{3} \\cdot e$ in view of the fact that each vertex contributes at least 3 edges, but we have counted each edge twice, so have to divide by 2. Similarly, since every face is of length at least 6, so $e \\geq \\frac{6}{2} \\cdot f$ $\\Longleftrightarrow$ $f \\leq \\frac{1}{3} \\cdot e$. Supposing that we plug these into Euler's formula, we get:\n\\begin{equation*}\n    2 = v + f - e \\leq \\frac{2}{3}e + \\frac{1}{3}e - e = 0\n\\end{equation*}\nThis is a contradiction.\n\\end{proof}\n\nObserve that no separating cycle of length at most five can be contained in $G_1$ for the reason that otherwise we can choose that smaller cycle to be $C_1$. Hence, there is no 4-cycle in $G_1$ except possibly $C_1$, because \n\\begin{itemize}\n    \\item it cannot be a 4-face, as proved in \\textbf{Claim 4},\n    \\item there is no 4-separating cycle as mentioned.\n\\end{itemize}\nA step further, we can define a subgraph $G_2$ of $G_1$ and the facial cycle $C_2$ of $G_2$ in this way: If there is a separating cycle of length six in $G_2$, then assign $C_2$ to be the cycle in which fewest vertices and edges are contained. $G_2$ is then the subgraph of all vertices and edges in which the cycle $C_2$ bounds. As analog to the case of $G_1$, there is no separating cycle of length at most six in $G_2$. Meanwhile, we've assumed that no 4-face is permitted, it leads that every cycle of length at most six in $G_2$ bounds a face. What's more, $C_2$ is a induced cycle from $G_2$. If it would not be the case, namely there would be a chord inside $C_2$, we could then choose a smaller cycle, which is a contradiction to the minimality. \n\nWe can apply \\textbf{Lemma 4.2.} on graph $G_2$ and the facial cycle $C_2$ and conclude that $G_2$ has a pentagram ($v_1, v_2, v_3, v_4, v_5$) with $v_1, v_2, v_3, v_4 \\notin V(C_2)$.\n\\begin{itemize}\n    \\item[(1)] \\textit{\\textbf{At least one of pentagrams ($v_1, v_2, v_3, v_4, v_5$) and ($v_4, v_3, v_2, v_1, v_5$) is safe.}} Then the lemma holds.\n    \\item[(2)] \\textit{\\textbf{None of them is safe.}} $\\forall i \\in \\{1, 2, 3, 4\\}$, let $x_i$ be the neighbor of $v_i$ other than $v_{i-1}$ and $v_{i+1}$, where $v_0 = v_5$. Notice that $x_1, x_2, x_3, x_4$ belong to $G_2$ because otherwise it might create crosses between the incident edges with neighbors and $C_2$, and they are pairwise distinct and non-adjacent, since \n    \\begin{itemize}\n        \\item $G_2$ is triangle-free,\n        \\item no separating cycle at most 5,\n        \\item no 4-cycle except $C_2$.\n    \\end{itemize}\n    It results $|\\{x_1, x_2, x_3, x_4\\} \\cap V(C_2)| \\leq 3$.\n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.2\\textwidth]{figure/intersect3vertices.png} \n    \\caption{The number of intersection $\\leq$ 3} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    If the number of intersection among these above two sets would be 4, then two of them have to be adjacent, which is a contradiction.\n\n\\begin{lemma}\nIf $v_5 \\in V(C_2)$, then $\\{x_1, x_2, x_3, x_4\\} \\cap V(C_2) = \\emptyset$.\n\\end{lemma}\n\\begin{proof}\nWe assume that at least one of $x_3$ and $x_4$ is not on $C_2$.\n\\begin{itemize}\n    \\item[Case 1:] \\textit{\\textit{$x_4$ is not on $C_2$.}} Suppose that $x_3$ lies on $C_2$. \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.6\\textwidth]{figure/x4notonc2.png} \n    \\caption{$x_4$ not on $C_2$, $x_3$ on $C_2$} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    It leads to a contradiction to the minimality of cycle $C_2$, for the reason that there is a smaller 4-separating cycle $x_3v_3v_4v_5$ or 5-separating cycle $x_3v_3v_4v_5s$ or 6-separating cycle $x_3v_3v_4v_5st$ containing $x_4$. Observe that if $x_2$ lies on $C_2$, it's analog to the former case when $x_3$ is on $C_2$. May assume now that $x_1$ lies on $C_2$:\n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.5\\textwidth]{figure/x1notonc2.png} \n    \\caption{$x_4$ not on $C_2$, $x_1$ on $C_2$} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    It results also a contradiction to the minimality of $C_2$, because it's required to have at least one extra vertex on $C_2$ between $x_1$ and $v_5$, since no triangle in planar graph is permitted. In consequence, we find a smaller separating cycle which just visits $v_1$ with path $x_1sv_5$ instead of visiting $s$ with path $x_1v_1v_5$.\n    \\item[Case 2:] \\textit{\\textit{$x_3$ is not on $C_2$.}} We may assume that $x_4$ is on $C_2$, otherwise it belongs to case 1. \n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.6\\textwidth]{figure/x3notonc2.png} \n    \\caption{$x_3$ not on $C_2$, $x_1$ on $C_2$} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    All cases under this circumstance are totally similar to the case 1.\n\\end{itemize}\n\\end{proof}\n\n\\end{itemize}\nSince the pentagram ($v_1, v_2, v_3, v_4, v_5$) is not safe, we know that, according to the definition of safety, there exists a pair of vertices $x$ and $y$ so that $\\{x, y\\} = \\{x_3, x_4\\}$ or $\\{x, y\\} = \\{x_2, v_5\\}$ and a path $P$ in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three ended with $x$ and $y$, which either \n\\begin{itemize}\n    \\item is from $x_2$ to $v_5$, or\n    \\item has length exactly three from $x_3$ to $x_4$ or its completion via the path $x_3v_3v_4x_4$ doesn't result in a facial cycle of length five in $G$.\n\\end{itemize}\nIf $\\{x, y\\} = \\{x_3, x_4\\}$, let $Q$ be the path $x_3v_3v_4x_4$; otherwise $x_2v_2v_1v_5$. Then we have following cases:\n\\begin{itemize}\n    \\item[Case 1:] \\textit{\\textbf{$P \\cup Q$ bounds a facial cycle in $G$.}} Thus, we know that $\\{x, y\\} = \\{x_3, x_4\\}$ and the length of path $P$ is exactly three. Suppose $P \\cup Q$ is listed in this order $x_3v_3v_4x_4ab$.\n    \\begin{claim}\n    $(x_4, v_4, v_3, x_3, a, b)$ is a safe hexagram. \n    \\end{claim}\n    \\begin{proof}\n    By contradiction: there would be a path from $x_4$ to $v_3$ of length at most three that is not part of this hexagram. Assume that this path would be $x_4u_1v_3$ or $x_4u_1u_2v_3$, where $u_1, u_2 \\ne v_4$.\n    \\begin{itemize}\n        \\item \\textit{\\textbf{The path is $x_4u_1v_3$.}} Note that $v_3$ has degree exactly three according to the definition of pentagram and its neighbors are $v_2$, $v_4, x_3$. In addition, $v_2$ has also degree exactly three and has neighbors $v_1, x_2, v_3$. So $u_1$ can't be $v_2$. What's more, $x_3, x_4$ are non-adjacent. It follows that this case is not possible.\n        \\item \\textit{\\textbf{The path is $x_4u_1u_2v_3$.}} \n        \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n            \\centering %图片居中\n            \\includegraphics[width=0.6\\textwidth]{figure/pcupqboundsaface.png} \n            \\caption{Path is $x_4u_1u_2v_3$.} %最终文档中希望显示的图片标题\n            \\label{figure} %用于文内引用的标签\n        \\end{figure}\n        Then $u_2 = x_3$. As discussed in \\textbf{Lemma 4.5.}, at most one of $x_3, x_4$ can lie on $C_2$. Therefore, $x_4u_1u_2(x_3)v_3v_4$ would form a separating cycle of length five, which is a contradiction.\n    \\end{itemize}\n    \\end{proof}\n    \n    \\item[Case 2:]\\textit{\\textbf{$P \\cup Q$ is a separating cycle in $G$.}} It results that $P \\cup Q$ is not a subgraph of $G_2$, for every cycle of length at most six in $G_2$ bounds a face.  \n    \n    \\begin{claim}\n    At most one of $\\{x, y\\}$ can lie on $C_2$.\n    \\end{claim}\n\\begin{proof}\n    Let's recall the following two cases:\n    \\begin{itemize}\n        \\item[(1)] \\textit{\\textbf{$\\{x, y\\} = \\{x_2, v_5\\}$}}: As pointed out in the \\textbf{Lemma 4.5.}, if $v_5 \\in V(C_2)$, $x_2$ can not belong to $C_2$.\n        \\item[(2)] \\textit{\\textbf{$\\{x, y\\} = \\{x_3, x_4\\}$}}: As mentioned in the \\textbf{Lemma 4.5.} that at least one of $x_3$ and $x_4$ is not on $C_2$.\n    \\end{itemize}\n\\end{proof}\nThus, we may assume that $x_4 \\in C_2$ and $x_3 \\notin C_2$. The other case is similar. Meanwhile, a subpath $R$ of $P \\cup Q$ of length exactly four joins $w_1, w_4 \\in V(C_2)$. \n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.7\\textwidth]{figure/lemma2.2.png} \n    \\caption{$P \\cup Q$ is a separating cycle} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\nObserve that the vertex $w \\in (P \\cup Q) \\backslash V(G_2)$ is adjacent to $w_1$ and $w_4$. Let's take care of the position of $w$: assume firstly that $w \\notin V(G_1)$, which implies that $w_1, w_4 \\in V(C_1)$ because $w_1, w_4 \\in V(C_2)$. Otherwise, edges $ww_1$ and $ww_4$ will build crosses with $C_1$. From the \\textbf{Figure 19.} informed that $w_1$ and $w_4$ cannot be adjacent on the grounds that if this would not be the case, $w_1w_4w$ will form a triangle, which is a contradiction. Thereby, there is a common neighbor of $w_1$ and $w_4$ in $C_2$ which can replace $w$. So we suppose that $w \\in V(G_1)$.\n\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.65\\textwidth]{figure/contradictionlemma2.2.1.png} \n    \\caption{$C_2$: $w_1, w_4$ has a common neighbor $q$ } %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n\\end{figure}\n\nProvided that there is common neighbor $q$ of $w_1, w_4$ in $C_2$, call it $q$ as in \\textbf{Figure 20}. Then $w_1qw_4w$ would form a 4-cycle which is a contradiction because as mentioned before there is no 4-cycle in $G_1$ except possibly $C_1$. Hence, we conclude that there are two vertices $w_2, w_3$ between $w_1$ and $w_4$ as in \\textbf{Figure 21}. \n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.6\\textwidth]{figure/contradictionlemma2.2.2.png} \n    \\caption{Between $w_1, w_4$ there are two vertices $w_2w_3$ on $C_2$ } %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n\\end{figure}\nLet $w_1w_2w_3w_4w_5w_6$ be the vertices of $C_2$. What's more, the cycle bounded by $w_1w_2w_3w_4w$ has to be a 5-face. Otherwise, it would be a separating cycle, which is a contradiction to the minimality of $C_1$. Notice that inside $P \\cup Q$ the only vertex $w$ is not inside $C_2$. However, inside $C_2$, there are two more vertices $w_5, w_6$ which are not inside $P \\cup Q$. So we should have chosen $P \\cup Q$ instead of $C_2$ because of the minimality of $C_2$. which is a contradiction.\n\\end{itemize}\n\\end{proof}\n%----------------------------------------------------------------------\n\\begin{theorem}[Grötzsch's theorem]\nEvery triangle-free planar graph is 3-colorable. \\cite{grotzsch1959dreifarbensatz}\n\\end{theorem}\n\\begin{proof}\nLet $G$ as stated to be a triangle-free graph and we'll prove this theorem by induction.\\\\\n\\textbf{Case 1: } If the minimum degree is smaller than three, which means it can be one or two.\n\\begin{itemize}\n    \\item if the minimum degree is one: search for vertices $\\forall v \\in V = \\{v | deg(v) = 1\\}$ and remove them from $G$ to get a new graph $G^{'}$. If the minimum degree of $G$ is two, then consider the case 1.2. Otherwise, we can apply the algorithm on $G^{'}$ and color $G^{'}$. Lastly, we can assign randomly a color different from the color of neighbor $\\forall u \\in \\{u$ | $u$ is the neighbor of $v$, $\\forall v \\in V \\}$ to $v$. \n    \n    \\item if the minimum degree is two: assume the vertex is $v \\in V(G)$ and its neighbors $u, w \\in V(G)$. Analogous to the former case, we remove the vertex $v$ from $G$ to obtain the new graph $G^{'}$. Suppose the coloring of $u, w$ is $c_1$ and $c_2$. If $c_1 = c_2$, then we can color $v$ randomly with a color different from $c_1(c_2)$. But if $c_1 \\ne c_2$, we can accordingly assign $c_3$ to $v$. \n\\end{itemize}\n\\textbf{Case 2:}  If every vertex $v$ has degree at least 3, we can apply \\textbf{Lemma 4.3.} on it. Thus, the theorem follows the induction on $G \\backslash v$ by identifying pairs diagonally opposite vertices. And the way of coloring is already shown in the third section \\textbf{Safety of multigram}: reconstruction step. \n\n\\end{proof}\n%----------------------------------------------------------------------\n\\section{Implementation}\n\\subsection{Naive polynomial-time implementation}\n\\begin{proof}[Description]\nThe brute force method is that we start with a vertex $v \\in V$ and just go through all its adjacent vertices which should be pairwise distinct. In this step, we will use multiple inner for-loops to achieve that. Notice that the case pentagram is kind of special. We need to check additionally whether $v_1, v_2, v_3, v_4$ have degree exactly three. Once we detect a multigram, then we should check the condition whether the found multigram is safe or not. \\footnote{ The entire code can be found here: \\href{https://github.com/qiaw99/3-color-linear-time}{https://github.com/qiaw99/3-color-linear-time}}\n\\begin{itemize}\n    \\item Found multigram is tetragram/hexagram. We can use the same way as above by using two for-loops to go through all neighbors and neighbors of neighbors so that we can check that there is no path of length at most three from $v_1$ to $v_3$ which is not part of the tetragram/hexagram. This can be done in $\\mathcal{O}(m^2)$ time, where $m = |E|$.\n    \n    \\item Found multigram is pentagram. As mentioned in the former case, we can also use two for-loops to check whether there is no path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three from $x_2$ to $v_5$, and every path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three from $x_3$ to $x_4$ has length exactly two. This can be done in $\\mathcal{O}(m^2)$ time as well.\n\\end{itemize}\n\\end{proof}\n\n\\newcommand\\mycommfont[1]{\\footnotesize\\ttfamily\\textcolor{blue}{#1}}\n\\SetCommentSty{mycommfont}\n\n\\SetKwInput{KwInput}{Input}                % Set the Input\n\\SetKwInput{KwOutput}{Output}              % set the Output\n\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n  \\KwInput{A triangle-free planar graph}\n  %\\KwOutput{A 3-coloring of $G$}\n  adj := Adjacency list \\\\\n  \\For{$v \\in V$}    \n    { \n        \\For{$s \\in adj[v]$}{\n            \\For{$t \\in adj[s]$}{\n                \\For{$u \\in adj[t]$}{\n\\tcp*{Detect tetragrams}\n                    \\If{$u \\in adj[v]$}{\n                        \\If{the detected tetragram is safe}{\n                            Get the right pair of diagonally opposite vertices and identify them.\n                        }\n                        \n                    } \\Else{\n                        \\For{$x \\in adj[u]$}{\n                            \\tcp*{Detect pentagrams}\n                            \\If{$x \\in adj[u]$}{\n                                \\If{the detected pentagram is safe}{\n                            Get the right pair of diagonally opposite vertices and identify them.\n                        }\n                            } \\Else{\n                                \\For{$y \\in adj[x]$}{\n                                \\tcp*{Detect hexagrams}\n                                \\If{$y \\in adj[x]$}{\n                                    \\If{the detected hexagram is safe}{\n                            Get the right pair of diagonally opposite vertices and identify them.\n                        }\n                                }\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n\\caption{The naive algorithm to detect multigrams and reduce the size of graph}\n\\end{algorithm}\nNote that according to the previous description, this brute force algorithm for detecting multigrams and identifying vertices will take $\\mathcal{O}(m^8)$\n time.\\\\\n \n We will give a small example how the program executes the given input graph step by step. The followings \\textbf{Figures 22 - 25} are the input graph and its result. The input graph contains two reducible multigrams: a tetragram and a pentagram.\n\n\\begin{figure}[htbp]\n\\centering\n\\begin{minipage}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[width=1\\textwidth]{figure/input.png}\n\\caption{\\footnotesize The input graph}\n\\end{minipage}\n\\begin{minipage}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[width=1\\textwidth]{figure/propercoloring.png}\n\\caption{\\footnotesize The proper coloring}\n\\end{minipage}\n\\end{figure}\n\n\\begin{figure}[htbp]\n\\centering\n\\begin{minipage}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[width=1\\textwidth]{figure/program identify.png}\n\\caption{\\footnotesize  Detect multigrams and identify vertices \\footnote{Implemented in Java (JDK 1.8)}}\n\\end{minipage}\n\\begin{minipage}[t]{0.48\\textwidth}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figure/coloring.png}\n\\caption{\\footnotesize  The corresponding coloring}\n\\end{minipage}\n\\end{figure}\n\n\\subsection{Improvement to the Brute-Force algorithm}\nWe can actually use some tricks to detect safe tetragrams and hexagrams more efficiently. Recall that tetragrams or hexagrams are called safe, if every path in $G$ of length at most three with ends $v_1$ and $v_3$ is a subgraph of cycle $v_1v_2...v_k$ (where $k = 4$ or $6$).\n\\begin{itemize}\n    \\item Tetragram. We can use two loops to go through all edges $e_1, e_2 \\in E$, where $e_1 \\ne e_2$. As the first step, we have to check whether $e_1, e_2$ forms a cycle. Next, we should check the condition of safety by using BFS. Observe that the running time of this improved algorithm for detecting tetragrams is $\\mathcal{O}(m^3)$, since BFS takes just $\\mathcal{O}(m)$ time.\n    \\SetCommentSty{mycommfont}\n    \n    \\SetKwInput{KwInput}{Input}                % Set the Input\n    \\SetKwInput{KwOutput}{Output}              % set the Output\n    \n    \\begin{algorithm}[H]\n    \\DontPrintSemicolon\n      \\KwInput{A triangle-free planar graph}\n      %\\KwOutput{A 3-coloring of $G$}\n      adj := Adjacency list \\\\\n      \\For{every $(x, y) \\in E$}    \n        { \n            \\For{every $(s, t) \\in E$ with $(s, t) \\ne (x, y)$}{\n                \\If{($x \\in adj[s]$ and $y \\in adj[t]$) or ($x \\in adj[t]$ and $y \\in adj[s]$) }{\n                    Do BFS to get all paths of length at most three from $a$ to $b$, where $a, b \\in \\{x, y, s, t\\}$ and $a, b$ are distinct \\\\\n                    \\If{$\\exists a, b: $ all path from $a$ to $b$ of length at most three are part of tetragram}{\n                        ($a, c, b, d$) is a safe tetragram, where $c, d \\in \\{x, y, s, t\\} \\backslash \\{a, b\\}$\n                    }\n                }\n            }\n        }\n    \\caption{Improvements to detect tetragrams}\n    \\end{algorithm}\n    \n    \\item Hexagram. The efficient way to detect hexagrams is analog to the previous case. We will use three loops to go through all edges $e_1, e_2, e_3 \\in E$, where $e_1 \\ne e_2 \\ne e_3$. Firstly, we check if $e_1, e_2, e_3$ builds a cycle. Then we have to take care of the safety of the hexagram by using BFS as well. Totally, the running time is $\\mathcal{O}(m^4)$. \n    \n    \\item Pentagram. We use two loops to go through all edges $e_1, e_2 \\in E$, where $e_1 \\ne e_2$ and another loop to go through all remaining vertices. Then, we apply BFS to check wether there is a path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three from $x_2$ to $v_5$ and every path in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ of length at most three has length exactly two. Therefore, the running time is $\\mathcal{O}(m^4)$.\n\n\\end{itemize}\nSo the running time can be improved to $\\mathcal{O}(m^4)$ in the worst case. \n\\subsection{Reconstruction step}\nThe algorithm will keep detecting all reducible multigrams until there is no multigram within the graph $G^{'}$ obtaining by identifying vertices in $G$. At this moment, the graph is easy to be colored. While identifying vertices, we will maintain two lists: one is to store the graph each time and the other is to store the pairs of identified vertices, with which we can reconstruct the graph coloring according to the subsection \\textbf{3.2.}\n\n%----------------------------------------------------------------------\n\\section{Improvements from the original paper}\n\nAs explained in the second section that in our algorithm, we will find some reducible multigrams to cut down the size of graph $G$. We've seen the algorithms in the fifth section and know that safety is not strong enough to get a linear-time algorithm. The difficulty now is how to efficiently check whether the found multigrams are safe, for which we will introduce another concept called \\textit{security} that allows us testing safety in constant time. Before that, let's give a few more definitions first.\n\n\\subsection{Definitions}\n\\begin{definition}\nA \\textit{monogram} in the graph $G$ is the one-vertex sequence consisting of a vertex $v \\in V(G)$ and has degree at most two. \\cite{dvorak2013threecoloring} \n\\end{definition}\nLet $G$ be a triangle-free planar graph, $k \\in \\{1, 4, 5, 6\\}$ and $\\gamma = (v_1, ..., v_k)$ a mono-, tetra-, penta- or hexagram in $G$. Let $C$ be the subgraph of $G$.\n\n\\begin{definition}\nA vertex $v \\in V(G)$ is \\textit{big}, if it has degree at least 60 and \\textit{small} otherwise. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\n\\begin{definition}\nA vertex $v \\in V(G)$ is called \\textit{$C$-admissible}, if $v$ is small and $v \\notin C$; otherwise called \\textit{$C$-forbidden}. \\cite{dvorak2013threecoloring} \n\\end{definition}\n\n\\begin{definition}\nA pentagram $(v_1, v_2, v_3, v_4, v_5)$ is a \\textit{decagram} if $v_5$ has degree exactly three as well. A tetragram $(v_1, v_2, v_3, v_4)$ is \\textit{octagram} if all vertices have degree three. \\cite{dvorak2013threecoloring}\n\\end{definition}\nFurthermore, we extend the concept multigram as follows: a \\textit{multigram} is a monogram, tetragram, pentagram, hexagram, octagram or decagram.\n\n\\begin{definition}\nLet $\\gamma$ be a multigram $(v_1, v_2, ..., v_k)$. The vertex $v_1$ is called \\textit{pivot} of multigram. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\\subsection{Security of multigrams}\nNext, we'll explain what's the meaning of $C$-secure and define a smaller graph $G^{'}$ which is called \\textit{$\\gamma$-reduction of $G$}.\n\n\\begin{itemize}\n    \\item[(1)] \\textit{\\textbf{$\\gamma$ is a monogram}}. We define it to be always safe. $\\gamma$ is $C$-secure, if $v_1 \\notin V(C)$ and $G^{'} := G \\backslash v_1$.\n    \\item[(2)] \\textit{\\textbf{$\\gamma$ is a tetragram}}. \n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.4\\textwidth]{figure/Csecuretetagram.png} \n    \\caption{$C$-secure tetragram} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    $\\gamma$ is $C$-secure if \n        \\begin{itemize}\n            \\item $\\gamma$ is safe,\n            \\item $v_1$ is $C$-admissible and has degree exactly three,\n            \\item letting $x$ be the neighbor of $v_1$ other than $v_2$ and $v_4$, the vertex $x$ is $C$-admissible,\n            \\item either\n                \\begin{itemize}\n                    \\item $v_3$ is $C$-admissible, or\n                    \\item every neighbor $w$ of $x$ is $C$-admissible or belongs to a 4-face incident with the edge $v_1x$ (either $v_1v_2wx$ or $v_1v_4wx$).\n                \\end{itemize}\n        \\end{itemize}\n        $G^{'}$ be the graph obtained by identifying vertices $v_1$ and $v_3$ and delete one edge from each f the two pairs of parallel edges. \n    \\item[(3)] \\textit{\\textbf{$\\gamma$ is an octagram}}. We define it to be always safe as well. $\\gamma$ is $C$-secure, if $v_1, v_2, v_3, v_4$ are $C$-admissible. $G^{'} := G \\backslash \\{v_1, v_2, v_3, v_4\\}$.\n    \\item[(4)] \\textit{\\textbf{$\\gamma$ is a decagram}}. $\\forall i \\in \\{1, 2, 3, 4\\}$, $x_i$ is the neighbor of $v_i$ other than $v_{i-1}$ and $v_{i+1}$, where $v_0 = v_5$. The decagram $\\gamma$ is \\textit{safe}, if \n    \\begin{itemize}\n        \\item $x_1, x_3$ are distinct and non-adjacent,\n        \\item there is no path of length two between them.\n    \\end{itemize}\n    The decagram $\\gamma$ is $C-$secure, if \n    \\begin{itemize}\n        \\item $\\gamma$ is safe,\n        \\item $v_1, v_2, v_3, v_4, v_5, x_1, x_3$ are $C$-admissible.\n    \\end{itemize}\n    $G^{'}$ is obtained from $G \\backslash \\{v_1, v_2, v_3, v_4, v_5\\}$ by adding the edge $x_1x_3$.\n    \n    \\item[(5)] \\textit{\\textbf{$\\gamma$ is a pentagram}}. $\\forall i \\in \\{1, 2, 3, 4\\}$, $x_i$ is the neighbor of $v_i$ other than $v_{i-1}$ and $v_{i+1}$, where $v_0 = v_5$.\n    $\\gamma$ is $C$-secure, if \n        \\begin{itemize}\n            \\item $v_1, v_2, v_3, v_4, v_5, x_1, x_2, x_3, x_4$ are $C$-admissible,\n            \\item either $v_5$ or $x_2$ has no $C$-forbidden neighbor,\n            \\item either $x_3$ or $x_4$ has no $C$-forbidden neighbor.\n        \\end{itemize}\n    $G^{'}$ is obtained from $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ by identifying $v_5$ and $x_2$; $x_3$ and $x_4$. If $x_3$ and $x_4$ should have a common neighbor, then delete one of the parallel edges.  \n    \n    \\item[(6)] \\textit{\\textbf{$\\gamma$ is a hexagram}}. $\\gamma$ is $C$-secure, if\n    \\begin{itemize}\n        \\item $v_1, v_3, v_6$ are $C$-admissible,\n        \\item $v_1$ has degree exactly three,\n        \\item the neighbor of $v_1$ other than $v_2$ or $v_6$ is $C$-admissible.\n    \\end{itemize}\n    $G^{'}$ be the graph obtained by identifying vertices $v_1$ and $v_3$ and delete one edge from each f the two pairs of parallel edges. \n\\end{itemize}\n\n\\begin{definition}\nA graph $G$ is \\textit{null} if $V(G)$ = $\\emptyset$. \\cite{wu2020introduction}\n\\end{definition}\n\n\\begin{definition}\nA multigram is \\textit{secure}, if it is $K_0$-secure, where $K_0$ is the null graph. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\n\\subsection{Constant-time operations}\nNote that the following lemmas will not be proved in this paper, see proofs from the original paper.\n\\begin{lemma}\nLet $G$ be a triangle-free plane graph, let $\\gamma$ be a safe multigram in $G$, and let $G^{'}$ be the $\\gamma$-reduction of $G$. Then $G^{'}$ is triangle-free, and every 3-coloring of $G^{'}$ can be converted to a 3-coloring of $G$ in constant time. Moreover, if $\\gamma$ is secure, then $G^{'}$ can be regarded as having been obtained from $G$ by deleting at most 126 edges, adding at most 116 edges, and deleting at least one isolated vertex.\\cite{dvorak2013threecoloring}\n\\end{lemma}\n\n\\begin{definition}\n\\textit{Two small vertices $u, v \\in V(G)$ are close} if either there is a path of length at most four between $u$ and $v$ consisting of small vertices, or a facial cycle of length at most six contains both $u$ and $v$. \\textit{A vertex $u$ is close to an edge $e$} if both $u$ and $e$ belong to the facial walk of the same face and the distance between $u$ and and one end of $e$ in this facial walk is at most two. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\n\\begin{claim}\nFor every vertex $v$ there are at most $1 + 4 \\cdot 59 + 59^{2} + 59^{3} + 59^{4}$ vertices that are close to $v$, and for every edge $e$, there are at most 10 vertices that are close to $e$. \\cite{dvorak2013threecoloring}\n\\end{claim}\n\\begin{proof}\n    \n    \\begin{figure}[htbp]\n    \\centering\n    \\begin{minipage}[t]{0.48\\textwidth}\n    \\centering\n    \\includegraphics[width=1\\textwidth]{figure/592.png}\n    \\caption{Case 1}\n    \\end{minipage}\n    \\begin{minipage}[t]{0.28\\textwidth}\n    \\centering\n    \\includegraphics[width=1\\textwidth]{figure/591.png}\n    \\caption{Case 2}\n    \\end{minipage}\n    \\end{figure}\n    Observe that in the \\textbf{Figure 27}, vertex 1 can have at most 59 neighbors, vertex 2 can have at most $59^{2}$ neighbors, vertex 3 can have at most $59^{3}$ neighbors and vertex 4 can have at most $59^{4}$ neighbors. In the \\textbf{Figure 28}, vertex 1 and 2 can totally have at most 59 neighbors, while vertex 3 and 4 each can have 59 neighbors. But vertex 5 can have only one vertex. So all things considered there are at most $1 + 4 \\cdot 59 + 59^{2} + 59^{3} + 59^{4}$ vertices that are close to $v$.\n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.28\\textwidth]{figure/593.png} \n    \\caption{Vertices close to edge $e$} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    Note that both $v$ and $e$ have to belong to the same walk of the same face. In addition, there are at most two faces that incident with edge $e$, which follows that there are at most 10 vertices that are close to edge $e$.\n\\end{proof}\n\n\\begin{lemma}\nGiven a triangle-free plane graph $G$ and a vertex $v \\in V(G)$, it can be decided in constant time whether $G$ has a secure multigram with pivot $v$. \\cite{dvorak2013threecoloring}\n\\end{lemma}\n\n\\begin{lemma}\nLet $G$ and $G^{'}$ be triangle-free plane graphs, such that for some pair of non-adjacent vertices $u, v \\in V(G)$ the graph $G^{'}$is obtained from $G$ by adding the edge $uv$. Let $\\gamma$ be a secure multigram in exactly one of the graphs $G$, $G^{'}$. Then the pivot of $\\gamma$ is close to $u$ or $v$ in $G$, or to the edge $uv$ in $G^{'}$. \\cite{dvorak2013threecoloring}\n\\end{lemma}\n\n\\begin{theorem}\nEvery non-null triangle-free planar graph has a secure multigram.\n\\end{theorem}\n\\begin{proof}\nSee the proof from the original paper. \\cite{dvorak2013threecoloring}\n\\end{proof}\n\n\\subsection{The algorithm}\nNow, let's focus on the linear-time algorithm with running time $\\mathcal{O}(|V(G)|)$:\nwe may assume that the input graph is triangle-free, because we can use the algorithm which was designed by Hopcroft and Tarjan \\cite{10.1145/321850.321852} to test planarity in $\\mathcal{O}(n)$ time by \\textit{path addition method}. So it holds our algorithm's running time in linear-time. \n%%% Coloring the comment as blue\n\\newcommand\\mycommfont[1]{\\footnotesize\\ttfamily\\textcolor{blue}{#1}}\n\\SetCommentSty{mycommfont}\n\n\\SetKwInput{KwInput}{Input}                % Set the Input\n\\SetKwInput{KwOutput}{Output}              % set the Output\n\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n  \\KwInput{A triangle-free planar graph}\n  \\KwOutput{A 3-coloring of $G$}\n  $L := \\{v \\in V(G) | deg(v) \\leq 3\\}$  \\tcp*{L is a list}\n  temp := $G$   \\tcp*{Store the original graph $G$}\n  \\For{$v \\in L$}    \n    { \n         Remove $v$ from $L$ \\\\\n    \t\\If{$G$ has a multigram with pivot $v$}\n        {\n            \\Statex $\\gamma$ := such safe multigram \\\\\n            $G^{'}$ := $\\gamma$-reduction of $G$ \\\\\n            \\For{every edge $uv$ deleted or added during construction of $G^{'}$}{\n                Add to $L$ all vertices that are close to $u$ or $v$ or to the edge $uv$ in $G$ or $G^{'}$\n            }\n            $G$ := $G^{'}$ \\tcp*{To reduce the size of $G$}\n        }\n        \\Else{\n            continue to next iteration\n        }\n    }\n   \\While{G $\\ne$ temp} \n   {\n        Color the graph $G$ \\tcp*{Reconstruction step}\\\\\n   \t\tConvert the 3-coloring of $G$ to the graph $G^{'}$ before the $\\gamma$-reduction \\\\\n   \t\t$G$ := $G^{'}$\n   }\n\\caption{3-coloring in triangle-free planar graph}\n\\end{algorithm}\n\\begin{proof}[Description] We initialize $L$ as the list of vertices with degree at most three. During the execution of the algorithm, $L$ includes all pivots of all secure multigrams. The algorithm works as follows: remove randomly a vertex $v$ from $L$ and check whether there is a multigram whose pivot is $v$, which can be done in constant time according to \\textbf{Lemma 6.2.} If there is no such multigram, then we go to the next iteration. Otherwise, let $\\gamma$ be such multigram and $G^{'}$ be the $\\gamma$-reduction of $G$, which can be done in constant time according to \\textbf{Lemma 6.1.} \\textbf{Lemma 6.3.} can guarantee that $L$ includes all pivots of all secure multigrams. After we get the coloring of $G^{'}$, it can be converted to the coloring of $G$. And we'll do this until we get the coloring of the original input graph $G$. Notice that the number of vertices added to $L$ is proportional to the number of vertices removed from $G$. Hence, the running time is $\\mathcal{O}(|V(G)|)$, as desired.\n\\end{proof}\n\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n  \\KwInput{A triangle-free plane graph $G$, a facial cycle $C$ in $G$ of length at most\nfive, and a proper 3-coloring $\\phi$ of $C$.}\n  \\KwOutput{A proper 3-coloring of $G$ whose restriction to $V(C)$ is equal to $\\phi$.}\n\\caption{3-coloring in triangle-free planar graph with coloring constraint}\n\\end{algorithm}\n\\begin{proof}[Description] \nThe description is exactly the same, except that we replace\n“secure” by “$C$-secure” and appeal to \\textbf{Lemma 7.1} rather than \\textbf{Theorem 6.4.} And its running time is still $\\mathcal{O}(|V(G)|)$.\\cite{dvorak2013threecoloring}\n\\end{proof}\n\n%----------------------------------------------------------------------\n\\section{Proof of correctness}\n\\begin{definition}\n\\textit{$f$ is opposite to $xy$}, if $xy$ is an edge in a planar graph, and $f$ is a face of $G$ incident with $y$ but not with the edge $xy$. Note that this definition is not symmetric: $f$ is opposite to $xy$, but $f$ is \\textit{not} opposite to $yx$. \\cite{dvorak2013threecoloring}\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=0.3\\textwidth]{figure/opposite.png} \n\\caption{$xy$-opposite and $yx$-opposite faces} %最终文档中希望显示的图片标题\n\\label{figure} %用于文内引用的标签\n\\end{figure}\n\\end{definition}\n\n\\begin{lemma}\nLet $G$ be a connected triangle-free planar graph and let $f_0$ be its\nouter face. Assume that $f_0$ is bounded by a cycle $C$ of length at most six,\n$V(G) \\ne V (C)$, and if $C$ has length six, then $|V(G) - V(C)| \\geq 2$. Then $G$\ncontains a $C$-secure multigram. \\cite{dvorak2013threecoloring}\n\\end{lemma}\n\n\\begin{proof}\nBy contradiction, presuming that $G$ is a counterexample with $E(G)$ minimum, namely $G$ doesn't contain any $C$-secure multigram.\n\n\\begin{corollary}\nIf $K \\ne C$ is a cycle in $G$ of length at most six, then $K$ bounds a face,\nor $K$ has length six and the open disk bounded by $K$ contains at most\none vertex. \\cite{dvorak2013threecoloring}\n\\end{corollary}\nWe conclude that $C$ is induced and every tetragram is safe the reason is that from \\textbf{Corollary 7.1.1.}, we know that a cycle in $G$ of length four will bound a face. Hence, according to \\textbf{Claim 4}, those tetragram is always safe.\\\\ \n\nNext, we assign the following charges to the vertices and faces of $G$. Primitively, a vertex $v \\in V(G)$ will obtain a charge of \n\\begin{equation*}\n\\left\\{\n    \\begin{array}{ll}\n    9 \\ deg(v) -36, & v \\notin V(C)  \\\\\n    8 \\ deg(v) - 19, & otherwise\n    \\end{array}\n\\right.\n\\end{equation*}\nand a face will take a charge of \n\\begin{equation*}\n\\left\\{\n    \\begin{array}{ll}\n    0, &  f = f_0\\\\\n    9\\ell -36, & f \\neq f_0 \\ and \\ f \\ has \\ length \\ \\ell\n    \\end{array}\n\\right.\n\\end{equation*}\n\n\\begin{claim}\nThe sum of charges is negative.\n\\end{claim}\n\\begin{proof}\n\\begin{align*}\n    & sum \\ of \\ charges \\ = \\sum_{v \\notin V(C)}9\\big(deg(v) - 4\\big) + \\sum_{v \\in V(C)} \\big(8 \\ deg(v) - 19\\big) + \\sum_{f \\neq f_0}9\\big(size(f) - 4\\big) \\\\\n    &= \\underbrace{\\sum_{v \\in V(G)}9\\big(deg(v) - 4\\big) - \\sum_{v \\in V(C)}9\\big(deg(v) - 4\\big)}_{\\sum_{v \\notin V(C)}9\\big(deg(v) - 4\\big)} + \\sum_{v \\in V(C)} \\big(8 \\ deg(v) - 19\\big) + \\sum_{f \\neq f_0}9\\big(size(f) - 4\\big) \\\\\n    &= \\sum_{v \\in V(G)}9\\big(deg(v) - 4\\big) + \\sum_{f \\neq f_0}9\\big(size(f) - 4\\big) - \\sum_{v \\in V(C)}(deg(v) - 17)\\\\\n    &= \\sum_{v \\in V(G)}9\\big(deg(v) - 4\\big) + \\sum_{f \\neq f_0}9\\big(size(f) - 4\\big) - \\sum_{v \\in V(C)}deg(v) + 17\\left| V \\right|\\\\\n    &= \\sum_{v \\in V(G)}9\\big(deg(v) - 4\\big) + \\sum_{f}9\\big(size(f) - 4\\big) - 9(size(f) - 4) - \\sum_{v \\in V(C)}deg(v) + 17\\left| V(C) \\right|\\\\\n    &= \\sum_{v \\in V(G)}9\\big(deg(v) - 4\\big) + \\sum_{f}9\\big(size(f) - 4\\big) - 9 \\left| V(C) \\right| + 36 - \\sum_{v \\in V(C)}deg(v) + 17\\left| V(C) \\right|\\\\\n    &= \\underbrace{18 \\left| E \\right| - 36\\left| V(G) \\right| + 18 \\left| E \\right| - 36 \\left| F \\right|}_{\\text{apply Euler's formula here: v + f - e = -2}} - \\sum_{v \\in V(C)}deg(v) + 8 \\left| V(C) \\right| + 36 \\\\\n    &= -36 \\cdot 2 - \\sum_{v \\in V(C)}deg(v) + 8 \\left| V(C) \\right| + 36\\\\\n    &= 8 \\left| V(C) \\right| - 36 - \\sum_{v \\in V(C)}deg(v)\\\\\n    &\\leq 8 \\left| V(C) \\right|- 2 \\left| V(C) \\right| - 1 - 36 \\\\\n    &\\leq -1 \\ (since \\ the \\ length \\ of \\ C \\ is \\ at \\ most \\ 6)\n\\end{align*}\n\nThe reason of first inequality is that all vertices of cycle $C$ have at least degree two and there is at least one vertex of $C$ whose degree is at least three, which follows $\\sum_{v \\in V(C)}deg(v) \\leq 2\\left| V(C) \\right| + 1$. \\\\\n\\end{proof}\n\n\\begin{definition}\nGiven the graph $G$, two edges $e_1 = v_1v_2$, $e_2 = v_3v_4$, where $v_1, v_2, v_3, v_4 \\in V(G)$ and $e_1, e_2 \\in E(G), \\ e_1 \\ne e_2$, are \\textit{consecutive}, if $v_2 = v_3$.\n\\end{definition}\n\n\\begin{definition}\nAssume $f$ $\\neq$ $f_0$ is a face contained in $G$ incident with a vertex $v \\in V(C)$. Provided that there exist two consecutive edges within the boundary of $f$ such both are incident with $v$ and neither belongs to $C$, then we are saying that $f$ is a $v-interior \\\nface$. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n\\centering %图片居中\n\\includegraphics[width=1\\textwidth]{f-interior.png} \n\\caption{$v$-interior face $f$} %最终文档中希望显示的图片标题\n\\label{figure} %用于文内引用的标签\n\\end{figure}\n\n\\begin{corollary}\nIf at least $k$ vertices of $C$ have degree at least three, then the sum of the\ncharges is at most -$k$. \\cite{dvorak2013threecoloring}\n\\end{corollary}\n\nWe now redistribute the charges consistent with the subsequent rules.\nThe rules are:\\cite{dvorak2013threecoloring}\n\\begin{itemize}\n    \\item[\\textbf{(A)}] Every face other than $f_0$ sends three units of charge to every incident vertex $v$ such that either $v$ $\\in$ $V(C)$ and $v$ has degree two in $G$, or $v$ $\\notin$ $V(C)$ and $v$ has degree exactly three.\n    \\item[\\textbf{(B)}] Every big vertex not on $C$ sends three units to each incident face, and\nfour units to each 4-face that shares an edge with $C$.\n\\item[\\textbf{(C)}] Every vertex $v \\in V(C)$ sends three units to every $v$-interior face.\n\\item[\\textbf{(D)}] If $x \\in V(G)$ is $C$-forbidden, and $y$ is a $C$-admissible neighbor of $x$ of\ndegree three, then $x$ sends three units to the unique face opposite to $xy$,\nand one unit to the face opposite to $yz$ for every $C$-admissible neighbor\n$z$ of $y$ of degree three.\n\\item[\\textbf{(E)}] Every $C$-forbidden vertex sends five units to every $C$-admissible neighbor\nof degree at least four.\n\\item[\\textbf{(F)}] For every $C$-admissible vertex $y$ of degree at least four that has a $C$-forbidden neighbor we select a $C$-forbidden neighbor $x$ of $y$ and let $y$\nsend one unit to each face opposite to $xy$, and one unit to the face\nopposite to $yz$ for every $C$-admissible neighbor $z$ of $y$ of degree three.\n\\end{itemize}\nSince $G$ is a counterexample of the lemma, $G$ doesn't contain any $C$-secure multigram, which follows that every vertex $v \\in V(G)$ has degree at least two and the vertices with degree two are on $C$. \n\\begin{claim}\nEvery vertex $v \\in V(G)$ with degree $d$ has non-negative charge.\n\\end{claim}\n\n\\begin{proof}\nWe will observe the following cases:\n\\begin{itemize}\n    \\item[Case 1.1:] \\textit{\\textbf{$v$ is $C$-admissible and $d = 3$.}} At the beginning, $v$ has the charge $9 \\cdot 3 - 36 = -9$. Pursuant to the rule (A), $v$ will get totally 9 units from three incident faces other than $f_0$, which results that the final charge of $v$ is zero (non-negative).\n    \\item[Case 1.2.1:] \\textit{\\textbf{$v$ is $C$-admissible, $d \\geq 4$ and has no $C$-forbidden neighbor.}} The original charge of $v$ is $9d - 36 \\geq 0$. What's more, $v$ doesn't send out any charges. So the final charge is still non-negative.\n    \\item[Case 1.2.2:] \\textit{\\textbf{$v$ is $C$-admissible, $d \\geq 4$ and has a $C$-forbidden neighbor.}} Let $x$ be the $C$-forbidden neighbor of $v$. Informed from the rule (E) that $v$ will receive five units from $x$. Meanwhile, $v$ sends out at most (2$d$ - 3) units according to the rule (F).\n    \n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n        \\centering %图片居中\n        \\includegraphics[width=0.3\\textwidth]{figure/lemma_5.1.2_2d-3.png} \n        \\caption{Case 1.2.2} %最终文档中希望显示的图片标题\n        \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    Notice that $v$ has remaining ($d - 1$) neighbors except $x$. In the worst case, all ($d - 1$) neighbors have degree exactly three. Thus, $v$ will send out at most ($d - 1$) units to each face $f$ that $f$ is opposite to $vz$, $\\forall z \\in Z$, where $Z$ is the set of all neighbors of $v$ except x. Furthermore, observe from \\textbf{Figure 32} that, ($d - 1$) edges(neighbors) can at most form ($d - 2$) $xv$-opposite faces. As a result, $v$ sends out at most ($d - 2 + d - 1$) = $2d - 3$ units.\\\\\n    $\\longrightarrow$ The final charge of $v = 9d - 36 + 5 - (2d - 3) = 7d - 28 \\geq 0$ is also non-negative.\n    \\item[Case 2.1:] \\textit{\\textbf{$v$ is big and $v \\notin C.$}} As stated in the rule (B), $v$ sends $3d$ units to all incident faces and at most 4$\\cdot$6 = 24 units to all 4-faces that share an edge of $C$, since $C$ has length at most six. Additionally, $v$ sends at most 5$d$ units using the rule (D),\n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n        \\centering %图片居中\n        \\includegraphics[width=0.4 \\textwidth]{figure/lemma_5.1.2_5d.png} \n        \\caption{Case 2.1 using the rule (D)} %最终文档中希望显示的图片标题\n        \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    The reason is that each neighbor $y$ of $v$ can have degree three and be $C$-admissible which can form at most two unique faces opposite to $vy$. In addition, every vertex $y$ can have at most three neighbors. Each neighbor $z$ can also be $C$-admissible of degree three. Hence, there are at most three faces opposite to $yz$ for each $y$. In conclusion, $v$ sends out at most five units for each neighbor, which deduces $v$ can send at most 5$d$ units using rule (D). Or using rule (E), provided that all neighbors of $v$ can be $C$-admissible and have degree at least 4. As a consequence, the final charge of $v$ = $9d -36 - 3d - 24 - 5d = d - 60 \\geq 0$, since $v$ is big.\n    \\item[Case 2.2:] \\textit{\\textbf{$v \\in C.$}} The charge of $v$ at the beginning is $8d - 19$. Note that if $d = 2$, by the rule (A), $v$ will receive three units. So we assume that is not the case. Otherwise, according to rule (A), $v$ sends out 3($d-3$) units by the rule (C), because $v$ has two neighbors that are on $C$, which leads that the remaining ($d-2$) neighbors can form ($d - 3$) $v$-interior faces. Besides, $v$ sends 5($d - 2$) units using rule (D) or (E). The argument is similar to the former case 2.2: there are at most ($d-2$) $C$-admissible neighbors of $v$. In consequence, the final charge of $v$ = $8d - 19 - 3(d - 3) - 5(d - 2) = 0$.\n\\end{itemize}\n\\end{proof}\n\n\\begin{claim}\nEvery face of length $\\ell \\geq 6$ has non-negative final charge.\n\\end{claim}\n\\begin{proof}\nNotice from rule (A) that each face $f \\ne f_0$ can just send at most 3$\\ell$ units. So the final charge = $9\\ell - 36 - 3\\ell = 6\\ell - 36 \\geq 0$. \n\\end{proof}\nFrom the \\textbf{Claim 9} we prove that there is a face $f \\ne f_0$ in G of length at most five that has strictly negative final charge.\n\n\\begin{corollary}\nNo vertex incident with $f$ has degree two. \\cite{dvorak2013threecoloring}\n\\end{corollary}\n\n\\begin{proof}\nProve using contradiction: there is a vertex $v$ incident with $f$ with degree exactly two. Thereby, $v$ and the two incident edges are on $C$, which implies that there are at least two vertices of $f$ are on $C$ that will not receive any charges from $f$. Because of the fact that the face $f$ has strictly negative final charge, we deduce that the length of $f$ is four:\n\\begin{align*}\n    The \\ final \\ charge &= 9\\ell -36 - \\big(1 \\cdot 3 + (\\ell - 2 - 1) \\cdot 3\\big) < 0\\\\\n    &\\Longrightarrow \\ell < 5\\\\\n    &\\Longleftrightarrow \\ell \\leq 4 \n\\end{align*}\nLet $u_1u_2u_3u_4$ be the bounded face, where $u_1u_2u_3$ are consecutive vertices of $C$ and $u_2$ has degree exactly two. Meanwhile, $u_4 \\notin C$, since $C$ is induced. Then $u_4$ is small and hence $C$-admissible. The reason is that if $u_4$ would be big, by using rule (B), $u_4$ would send seven units to $f$. Furthermore, $f$ has initial charge $9\\cdot4 - 36 = 0$ and $f$ sends three units to $u_2$ by rule (A). As a result, the final charge of $f$ would be $0 - 3 + 7 = 4$, which is a contradiction. Let $C^{'}$ be the cycle obtained from $C$ by replacing the vertex $u_2$ by $u_4$. Since we replace $u_2$ by $u_4$, it follows $|V(C^{'})| = |V(C)| \\leq 6$. So the length constraint holds.\n\\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n    \\centering %图片居中\n    \\includegraphics[width=0.4 \\textwidth]{figure/corollary3.png} \n    \\caption{Cycle $C$ and $C^{'}$} %最终文档中希望显示的图片标题\n    \\label{figure} %用于文内引用的标签\n\\end{figure}\nAs above mentioned, $u_4$ has degree at least three, $C^{'}$ can't form a face, which follows from \\textbf{Corollary 7.1.1} that $C^{'}$ has length six and contains exactly one vertex $v_4$. Next, we order the remaining three vertices on $C$ as in \\textbf{Figure 34} with $v_1v_2v_3$ so that the original cycle $C$ is $u_1u_2u_3v_1v_2v_3$ and $v_4$ is adjacent to $u_4, v_1, v_3$. Observe that:\n\\begin{itemize}\n    \\item[(1)] ($u_4, u_1, u_2, u_3$) is safe, since there is not path at most three other than $u_4u_1u_2$ and $u_4u_3u_2$ that ends with $u_2$ and $u_4$. \n    \\item[(2)] As proved above, $u_4$ is $C$-admissible and has degree exactly three.\n    \\item[(3)] Notice from the figure that the neighbor $v_4$ of $u_4$ is not on $C$ and has degree exactly three as well. It follows that $v_4$ is also $C$-admissible.\n    \\item[(4)] $v_4$ belongs to the 4-face($u_4, u_1, v_3, v_2$) incident with $u_4v_4$. \n\\end{itemize}\nResultantly, ($u_4, u_1, u_2, u_3$) is a $C$-secure tetragram, which is a contradiction to the supposition that there is no $C$-secure multigram in $G$.\n\\end{proof}\n\n\\begin{definition}\nLet $uv$ be the edge to which $f$ is opposite. $v$ is a \\textit{sink}, if $v$ has degree three and both $u$ and $v$ are $C$-admissible. $v$ is a \\textit{source}, if either $v \\notin V(C)$ and $v$ is big, or $v \\in V(C)$ and $f$ is $v$-interior. \\cite{dvorak2013threecoloring}\n\\end{definition}\n\n\\begin{observation}\n$v$ is \\textbf{not} a source, then either $v$ is small and $v \\notin V(C)$; or $v \\in V(C)$ and $f$ is not $v$-interior.\n\\end{observation}\n\n\\begin{observation}\nThe equivalences of definition of sink and source are stated as follows: \\cite{dvorak2013threecoloring}\n\\begin{itemize}\n    \\item $v$ is a sink $\\Longleftrightarrow$ $v$ has degree three and receives three units of charge from $f$ by rule (A) and $f$ does not receive three units by rule (D) from $u$.\n    \\item $v$ is a source $\\Longleftrightarrow$ $v$ sends three units of charge to $f$ by rule (B) or (C).\n\\end{itemize}\n\\end{observation}\nSuppose $s$ is the number of sources and $t$ is the number of sinks. Then we have the initial charge of $f$ $9 + 3s - 3t$, if the length of $f$ is five; $3s - 3t$, if the length of $f$ is four. \n\n\\begin{itemize}\n    \\item[Case 1.1: ] \\textit{\\textbf{$f$ has length five and $v_5$ is $C$-admissible of degree three.}} Let $v_1v_2v_3v_4v_5$ be the cycle that bounds $f$. For $f$ has strictly negative final charge in the end, there are at least four sinks. Hence, we may assume that $v_1, v_2, v_3, v_4$ are sinks. In other word, they are $C$-admissible and have degree exactly three. In addition, ($v_1, v_2, v_3, v_4, v_5$) is a pentagram according to the definition. Let $x_i$ be the neighbor of $v_i$ except $v_{i-1}$ and $v_{i+1}$, $\\forall i \\in \\{1, 2, 3, 4\\}$, where $v_0 = v_5$. It infers that $x_1, x_2, x_3, x_4$ are distinct and pairwise non-adjacent. The reason is as follows:\\\\\n    \\textit{\\textbf{(Case 1)}} If $x_i$ and $x_{i+1}$ would be adjacent, it will create a $C$-secure tetragram with vertices $v_i$ and $v_{i+1}$, which is a contradiction.\\\\\n    \\textit{\\textbf{(Case 2)}} If $x_i$ and $x_{i+2}$ would be adjacent, from \\textbf{Corollary 7.1.1.} that $x_ix_{i+2}v_{i+2}v_{i+1}v_{i}$ bounds a face. However, it contains a vertex $x_{i+1}$, which is a contradiction as well.\\\\\n    Notice from (Case 2) that there is no path from $x_1$ to $x_3$ with length two, then ($v_1, v_2, v_3, v_4, v_5$) is a $C$-secure decagram.\n    \n    \n    \n    \\item[Case 1.2: ] \\textit{\\textbf{$f$ has length five and $v_5$ is not $C$-admissible of degree three.}} If there is a path from $x_1$ to $x_3$ of length three, then consider the cycle $K$ = $x_1v_1v_2v_3x_3y$. \n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n        \\centering %图片居中\n        \\includegraphics[width=0.6 \\textwidth]{figure/contradictionpentagram.png} \n        \\caption{Case 1.2} %最终文档中希望显示的图片标题\n        \\label{figure} %用于文内引用的标签\n    \\end{figure}\n    Since the cycle $K$ has length six and from \\textbf{Corollary 7.1.1.} that $K$ contains at most one vertex, it results that $v_4$ and $v_5$ are not inside $K$. Hence, either $y = x_2$ or $x_2$ is the vertex containing in the cycle $K$. Therefore, $x_2$ is adjacent to $x_1$ and $x_3$. In the former case, it's obvious true. In the latter case, we can prove it by contradiction: if $x_2$ is not adjacent to one of $x_1$ and $x_3$, it will form a triangle, which is against to the definition of planar graph. So in any case, $x_2$ is adjacent to $x_1$ and $x_3$, which is a contradiction to what we've proved in the case 1.1 that $x_1, x_2, x_3$ should be pairwise non-adjacent. \n\\end{itemize}\nConsequently, from both cases above that $v_5$ is either not $C$-admissible or has degree at least four, which implies that $v_5$ is not a sink and then the final charge of $f$ is at least $9 - 3 \\cdot 4 = -3$. What's more. $v_5$ is not a source neither. If $v_5$ would be a source, then the final charge of $f$ would be zero, which is a contradiction to the negative final charge of $f$. Thus, it deduces from \\textbf{Observation 5.} that $v_5$ is $C$-admissible and hence has degree at least four. We may claim that the pentagram $(v_1, v_2, v_3, v_4, v_5)$ is safe: \n\\begin{itemize}\n    \\item there is a path of length at most three in $G \\backslash \\{v_1, v_2, v_3, v_4\\}$ that ends with $x_2$ and $v5$, which can be completed via a path $v_5v_1v_2$ to be a new cycle $K$.\n    \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n        \\centering %图片居中\n        \\includegraphics[width=0.6 \\textwidth]{figure/case1.3.png} \n        \\caption{Safe pentagram} %最终文档中希望显示的图片标题\n        \\label{figure} %用于文内引用的标签\n    \\end{figure}\nFrom \\textbf{Corollary 7.1.1.} that $K$ contains at most one vertex. On the grounds of this, $x_1$ is adjacent to $x_2$(the argument is the same as in the case 1.2), which is a contradiction.\n\n\\item considering the path of length at most three from $x_3$ to $x_4$ that can be completed to a cycle $K^{'}$ ($x_3v_3v_4x_4ab$) by the path $x_4v_4v_3x_3$ supposing that the length of cycle is six. Observe that $v_3, v_4$ are sinks, so $v_3$ has degree exactly three and $x_3, x_4$ are $C$-admissible. Thus, the hexagram ($v_4, v_3, x_3, b, a, x_4$) is $C$-secure, which is a contradiction. It follows that the path from $x_3$ to $x_4$ can only be two.\n\\end{itemize}\nAccording to the above proof, we have shown that the pentagram $(v_1, v_2, v_3, v_4, v_5)$ is safe. By symmetry the pentagram $(v_4, v_3, v_2, v_1, v_5)$ is safe as well. Meanwhile, $x_1, x_2, x_3, x_4$ are $C$-admissible, for $v_1, v_2, v_3, v_4$ are sinks. Provided that the neighbor $x_i$ of $v_i$ for $i \\in \\{1, 2, 3, 4\\}$ has a $C$-forbidden neighbor $u$, then $f$ will receive one unit either from rule (D) if $u$ has degree exactly three or (F) if $u$ has degree at least four. Notice that $v_5$ has degree at least four and if $v_5$ has a $C$-forbidden neighbor, then $f$ will receive one unit by rule (F). Note that initially, $f$ has charge 3. Hence, at most two vertices among $x_1, x_2, x_3, x_4, v_5$ have a $C$-forbidden neighbor. In consequence, either $(v_1, v_2, v_3, v_4, v_5)$ or $(v_4, v_3, v_2, v_1, v_5)$ is a $C$-secure pentagram, which is a contradiction.\\\\ \\\\\nWe've proved that $f$ has then length exactly four:\n   \n\\begin{itemize}\n    \\item[Case 2: ] \\textit{\\textbf{$f$ has length four.}} Let $v_1, v_2, v_3, v_4$ be the incident vertices of $f$. Recall that every tetragram is safe and $f$ has initial charge $3s - 3t$. We may assume that $v_1$ is a sink and $v_3$ is not a source. Consequently, $v_3 \\in V(C)$ and $f$ is not $v$-interior, for $v_3$ is not a source and $(v_1, v_2, v_3, v_4)$ is not a $C$-secure tetragram (implies $v_3$ is not $C$-admissible). What's more, only one of edges $v_2v_3$, $v_3v_4$ is shared with $C$. And we may assume the latter edge is the case, which implies $v_2 \\notin V(C)$. d that if $v_2$ is a sink, then the charge of $f$ is at least -6, otherwise -3. Let $v$ be the neighbor of $v_1$ different than $v_2$ and $v_4$: \n    \\begin{itemize}\n        \\item \\textit{\\textbf{$v$ has no $C$-forbidden neighbor.}} $(v_1, v_2, v_3, v_4)$ is then a $C$-secure tetragram, which is a contradiction.\n        \n        \\item \\textit{\\textbf{$v$ has a $C$-forbidden neighbor $u$.}} \n            \\begin{itemize}\n                \\item $u \\notin V(C)$. Therefore, $u$ is big and $f$ receives four units from $u$, since $f$ is a 4-face and shares an edge $v_3v_4$ with $C$ by rule (B). At this moment, the charge of $f$ = $-3 + 4 = 1$. Hence, $v_2$ has to be a sink so that the charge of $f$ = $1 - 3 = -2$. Let $v^{'}$ the neighbor of $v_2$ other than $v_1$ and $v_3$. As the same argument, $v^{'}$ has a $C$-forbidden neighbor $u^{'}$ as well. Notice that each $u$ and $u^{'}$ will send one unit to $f$ either by rule (D) or (F) depending on their degree such that the final charge of $f = -2 + 2 = 0$ is non-negative, which is a contradiction. \n                \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n                    \\centering %图片居中\n                    \\includegraphics[width=0.5 \\textwidth]{figure/notcsecuretetragram.png} \n                    \\caption{not $C$-secure tetragram} %最终文档中希望显示的图片标题\n                    \\label{figure} %用于文内引用的标签\n                \\end{figure}\n            \\end{itemize}\n        Thus, we've shown that every $C$-forbidden neighbor $u$ of $v$ is on $C$.\n        \n        \\begin{observation}\n        Each 4-face $f$ that shares an edge with $C$ has final charge at most -2$t$, where $t \\in \\{1, 2\\}$ is the number of sinks of $f$.\n        \\end{observation}\n        \n        At least one of $C$-forbidden neighbor $u$ of $v$ is adjacent to neither $v_2$ nor $v_4$ inasmuch as $(v_1, v_2, v_3, v_4)$ is not a $C$-secure tetragram. Let $C, C_1, C_2$ be three cycles composed of $C$ and the path $v_4v_1vu$. \n        \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n            \\centering %图片居中\n            \\includegraphics[width=0.8 \\textwidth]{figure/cc1c2.png} \n            \\caption{$C, C_1, C_2$} %最终文档中希望显示的图片标题\n            \\label{figure} %用于文内引用的标签\n        \\end{figure}\n        Observe from the \\textbf{Figure 38} that $v_2$ is contained in $C_2$. So from \\textbf{Corollary 7.1.1.} that the length of $C_2$ is at most six. Assume that the length of $C_2$ is exactly six, it results that $v_2$ has degree three and is adjacent to $u$, which is a contradiction.\\\\ \\\\\n        For this reason, the length of $C_2$ is at least seven. We conclude that the length of $C_1$ is at most 5, because the length of $C$ is at most six: $\\ell_{C_1} + 7 - 2 \\cdot 3 \\leq 6 \\Longleftrightarrow \\ell_{C_1} \\leq 5$. By means of the constraint of $u$, the length of $C_1$ is exactly five as in \\textbf{Figure 38}. Thereby, there is exactly a vertex $z$ that is adjacent to $u$, $v_4$ and has degree two. If $z$ would have degree at least three, then it would form a triangle or against the planarity. Let $\\gamma$ be the tetragram and $f(\\gamma)$ be the face that is bounded by $C_1$. \n        \\begin{definition}\n        A tetragram $\\gamma$ ($v_1, v_2, v_3, v_4$) is \\textit{bad}, if $f(\\gamma)$ is defined. \n        \\end{definition}\n        \n        \\begin{observation}\n        Bad tetragrams are faces of $G$ that have always negative final charge. \\cite{dvorak2013threecoloring}\n        \\end{observation}\n        Assume that the number of bad tetragrams in $G$ is $b$. The initial charge of face $f(\\gamma) = 9 \\cdot 5 - 36 = 9$. Since \n        \\begin{itemize}\n            \\item $v_1$ is a sink: $v_1 \\notin V(C)$ and has degree three.\n            \\item $z \\in V(C)$ and has degree two.\n            \\item $v \\notin V(C)$ and has degree three. \n        \\end{itemize}\n        $f(\\gamma)$ sends each three units to $u, v, v_1$ using rule (A). In addition, $f(\\gamma)$ receives one unit either from $v_3$ using rule, if $v_2$ has degree exactly three; or from $v_2$ using rule (F), if $v_2$ has degree at least four so that the final charge of $f(\\gamma)$ is -1. What's more, if there is another tetragram $\\gamma^{'}$ that is different than $\\gamma$ such that $f(\\gamma) = f(\\gamma^{'})$. As a result, the final charge of $f(\\gamma)$ is at most $-b$.\n        \n        \\begin{figure}[H] %H为当前位置，!htb为忽略美学标准，htbp为浮动图形\n            \\centering %图片居中\n            \\includegraphics[width=0.7 \\textwidth]{figure/temp.png} \n            \\caption{$C$-secure octagram ($v, v^{'}, v_2, v_1$)} %最终文档中希望显示的图片标题\n            \\label{figure} %用于文内引用的标签\n        \\end{figure}\n        Notice that $v_3, v_4, u$ have degree at least three. From \\textbf{Corollary 7.1.2.} informed that the total charge of $G$ is then at most -3, which follows $b \\geq 3$. There must be another bad tetragram for $b > 1$. Hence, the final charge of $G$ is at most -4. It leads $b \\geq 4$. Let $u^{'}$ be the unique neighbor of $u$ in $C \\backslash z$. Notice that $v_3v_4$ and $uu^{'}$ are the only edges of $C$ \n       incident to a bad tetragram. We conclude that $G$ has a vertex $v^{'}$ of degree three with neighbors $v, v_2, u^{'}$ and hence $v^{'}$ is a sink and $C$-admissible. And it implies that according to the definition of sink, $v_2$ is then $C$-admissible. Notice that $u^{'}v^{'}v_2v_3t$ bounds also a face which is similar to the 5-face $zv_4v_1vu$. It follows that $(v, v^{'}, v_2, v_1)$ is a $C$-secure octagram, because $v, v^{'}, v_2, v_1$ are all $C$-admissible as proved.\\\\\n        All in all, in any case, there will be a $C$-secure multigrams in $G$, as claimed.\n\n    \\end{itemize}\n\\end{itemize}\n\\end{proof}\n\n", "meta": {"hexsha": "769d0b69bf8279a50ec96d692f2f98babd0745b0", "size": 72637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/3_main.tex", "max_stars_repo_name": "qiaw99/3-color-linear-time", "max_stars_repo_head_hexsha": "3405fd84caf9cedbcb985c3800c0c3b42e086b8f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-02T14:03:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T09:36:38.000Z", "max_issues_repo_path": "thesis/3_main.tex", "max_issues_repo_name": "qiaw99/3-coloring-polynomial-time", "max_issues_repo_head_hexsha": "3405fd84caf9cedbcb985c3800c0c3b42e086b8f", "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": "thesis/3_main.tex", "max_forks_repo_name": "qiaw99/3-coloring-polynomial-time", "max_forks_repo_head_hexsha": "3405fd84caf9cedbcb985c3800c0c3b42e086b8f", "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": 77.3556975506, "max_line_length": 1020, "alphanum_fraction": 0.6677450886, "num_tokens": 25804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6171992227560595}}
{"text": "\\chapter{From LMS to Deep Learning}\n\\section{LMS of zero-mean time-series}\nThe time-series signal is non-stationary data, which can be analysed by the LMS algorithm. The algorithm is used to predict one-step value based on the previous four values $y[n-4]$, $y[n-3]$, $y[n-2]$ and $y[n-1]$. As shown in Fig.\\ref{fig:4_1_a}(a), the time-series is non-linear and zero mean. The performance of the basic LMS algorithm is illustrated in Fig.\\ref{fig:4_1_a}(b). The predicted time-series is zero-mean as well. However, the predicted series do not capture perfectly of the original at the beginning part. After 400 time index, the predicted series converge with small difference with true series. In order to evaluate the performance appropriately, the metrics of mean squared error (MSE) and prediction gain ($R_p$) are measured. The MSE should be close to zero while the gain should be as large as possible. As to the LMS algorithm, the MSE is 16.032$dB$ with $R_p=5.196$, which performs inexpressively to some extent.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/41a1.eps}\n     \\end{subfigure}\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/41a2.eps}\n     \\end{subfigure}\n     \\caption{LMS: zero mean time-series one-step prediction}\n     \\label{fig:4_1_a}\n\\end{figure}\n\\section{Activation function of predicted series}\n\\begin{figure}[htb]\n     \\centering\n     \\includegraphics[width=0.4\\textwidth]{fig/4/42.eps}\n     \\caption{Dynamical perceptron: zero mean time-series one-step prediction}\n     \\label{fig:4_2}\n\\end{figure}\n\\noindent\nDue to the non-linearity of most of real-life data, the activation function \\texttt{tanh} is applied to the each step of AR(4) process, which can be expressed as \n\\begin{align}\n\\hat y[n]&=tanh(\\mathbf{w^Ty})\\label{eq:act}\\\\\n\\text{where}\\quad \\mathbf{y}&=[y[n-4], y[n-3], y[n-2], y[n-1]]\\notag\n\\end{align}\nFig.\\ref{fig:4_2} depicts the output using activation function against the original time-series. It is obvious that using \\texttt{tanh} is inappropriate to predict the time-series data. The reason is that the range of \\texttt{tanh} lies in $(-1,1)$ whereas the zero-mean time-series is bounded in $(-40,40)$. Therefore, in order to appropriately predict the series, the activation function need to be scaled.\n\\section{Scaled activation function}\nAs analysis previous, scaling the activation function expresses in Eq.\\ref{eq:act} by factor $a$. Fig.\\ref{fig:4_3_a} illustrates the performance of varying $a$ with zero-mean data. For a small value of $a=20$, the predicted $\\hat y[n]$ is still lower than the range of the desired data. Thus, the MSE is extreme large than the standard LMS algorithm. However, the maximum range of prediction is restricted by activation function, leading to small variance of error. Thus, the prediction gain $R_p$ is larger than the LMS. With incremental of $a$ up to 80, the MSE is getting to decrease, corresponding to increasing predict gain. However, if the value of $a$ is over 80, the prediction is overshooting to the true data, resulting in decreasing $R_p$ and increasing MSE. In conclusion, the optimal range of $a$ for predictinng zero mean data is $70\\sim80$.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a1.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a2.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a3.eps}\n     \\end{subfigure}\n     \\\\\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a4.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a5.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43a6.eps}\n     \\end{subfigure}\n       \\caption{Scaled \\texttt{tanh}: Prediction of zero mean data}\n        \\label{fig:4_3_a}\n\\end{figure}\\\\\nIn addition, it is harder to predict the none-zero mean data as shown in Fig.\\ref{fig:4_3_b}, which presents in the larger MSE and smaller $R_p$. However, the optimal range of $a$ for non-zero mean prediction is $40\\sim 50$.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b1.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b2.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b3.eps}\n     \\end{subfigure}\n     \\\\\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b4.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b5.eps}\n     \\end{subfigure}\n    \\hspace{-0.2cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/43b6.eps}\n     \\end{subfigure}\n       \\caption{Scaled \\texttt{tanh}: Prediction of none-zero mean data}\n        \\label{fig:4_3_b}\n\\end{figure}\n\\section{None-linearity prediction with bias}\nPrevious work is based on the zero mean time-series to make one-step ahead prediction. By adding a bias $b$ for the activation function, expressed as $tanh(\\mathbf{w}^T\\mathbf{x}+b)$, the model can account for the mean automatically. Due to the small learning rate, the performances with bias are similar to the one without bias if only one epoch experiment is implemented. Thus, 100 number of epochs are used in order to continuously update weight. Fig.\\ref{fig.bia} plots the MSE curves with or without bias for 100 epochs learning. Same performances are obtained at the beginning of training. Both of curves are rapidly plummet at first epochs and then slightly decrease up to convergence. Overall, the model with bias outperform the one without bias which converges after 60 epochs. Fig.\\ref{fig.biasplot} shows the prediction of last epoch with bias against with the original non-zero mean series. Compared with the plots in Fig.\\ref{fig:4_3_b} with amplitude $a=50$, the MSE reduces approximately in a half and prediction gain increases as well.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/44a2.eps}\n         \\caption{Prediction MSE of 100 epochs}\n         \\label{fig.bia}\n     \\end{subfigure}\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/44a1.eps}\n          \\caption{The last epoch prediction}\n         \\label{fig.biasplot}\n     \\end{subfigure}\n     \\caption{\\texttt{tanh} with bias: None-zero mean time-series one-step prediction}\n     \\label{fig:4_4}\n\\end{figure}\n\\section{Prediction with initialized weight}\nAs to the LMS algorithm, the model cannot capture the original time-series at the beginning, which causes a long time to converge. Fig.\\ref{fig:4_5}(a) illustrates the standard LMS prediction for non-zero mean which performs dissatisfactory with quite large error and insignificant prediction gain. The reason is that the initial weights are assumed to zero, which introduces difficulties to predict the non-zero mean data. Fig.\\ref{fig:4_5} depicts the performance of training initial weights. After training the first 20 data samples for 100 epochs, the initial weights are obtained which can speed up the learning process. With the pre-trained initial weights, the model perform better than training model after 100 epoch, with smaller MSE = 5.162 and slightly larger $R_p=16.342$. \n\\begin{figure}[htb]\n     \\centering\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/45a1.eps}\n     \\end{subfigure}\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/45a2.eps}\n     \\end{subfigure}\n     \\caption{Standard LMS and Dynamical perceptron: zero mean time-series prediction}\n     \\label{fig:4_5}\n\\end{figure}\n\\section{Back-propagation of Deep Network}\nFor deep network, the neurons at each layers are fully connected with all inputs at last layer and outputs at next layer. And the weights can be expressed as:\n\\begin{align}\n\\mathbf{w}^{l}\\Rightarrow w_{ij}^{(l)}\\left\\{\n             \\begin{array}{lr}\n             1\\leqslant l \\leqslant L\\text{ layers;}\\\\\n             1\\leqslant i \\leqslant d^{(l-1)}\\text{ inputs;} \\\\\n             1\\leqslant j \\leqslant d^{(l)}\\text{ outputs;} \\\\\n             \\end{array}\n\\right.\\\\\nd\\text{ is neuron number at each layer}\\notag\n\\end{align}\nThus, the weighted output on each neuron position is calculated by summing all weighted inputs with activation function.\n\\begin{align}\nz_{j}^l &=\\sigma(w^l_{ij}a^{l-1}_{ij}+w^l_{i0})\\\\\n\\mathbf z^l &=\\sigma(\\mathbf w^l \\mathbf a^{l-1}+w^l_{i0})\n\\end{align}\nTherefore, set the weights randomly and the forward propagation process of the first iteration is finished. However, back-propagation of weights and bias need loss function, generally mean squared error, to calculated the gradient as shown below.\n\\begin{align}\nE=\\mathbb {E}\\{\\|x[n]-\\hat x[n]\\|^2 \\}\n\\end{align}\nTherefore, the error for the output $\\delta^l_j$ can be expressed as\n\\begin{align}\n\\delta^l_j&=\\frac{\\partial E}{\\partial z^l_j}\\notag\\\\\n&=\\sum_i\\frac{\\partial z_i^{l+1}}{\\partial z^l_j}\\delta_i^{l+1}\\notag\\\\\n&=\\sum_i w_{ij}^{l+1}\\delta^{l+1}_i\\sigma'(z^l_j)\n\\end{align}\nIn addition, the output error is corresponding to the previous weights. Thus, the gradient of weight is\n\\begin{align}\n\\frac{\\partial E}{\\partial w^l_{ij}}=a_{i}^{l-1}\\delta_j^l\n\\end{align}\nTherefore, the weight can be updated by\n\\begin{align}\nw_{ij}=w_{ij}-\\eta\\frac{\\partial E}{\\partial w^l_{ij}}=w_{ij}-\\eta a_{i}^{l-1}\\delta_j^l\n\\end{align}\n\\section{Deep Network}\nThere are 10 sinusoidal waves with different frequency and amplitude as the linear inputs. The output $y[n]$ after applying activation function to $\\mathbf x[n]$ is highly non-linear as shown in Fig.\\ref{fig:4_7_1}. With the default parameters, three model, specifically in single neuron with linear and \\texttt{tanh} function, deep network with \\texttt{relu}, are used to train and test to evaluate their performance. \n\\begin{figure}[htb]\n     \\centering\n     \\includegraphics[width=0.7\\textwidth]{fig/4/47a1.png}\n     \\caption{Harmonics sine waves and non-linear data with noise}\n     \\label{fig:4_7_1}\n\\end{figure}\\\\\nFig.\\ref{fig:4_7_2} shows the regression curves of these three models. The models use single neutron have similar performance, whose predictions are still linear. As to the deep network, this model can predict non-linear curve and the trend of the data is generally predicted. However, the performance is still insignificant which may be caused by the power of noise.\n\\begin{figure}[htb]\n     \\centering\n     \\includegraphics[width=0.7\\textwidth]{fig/4/47a2.eps}\n     \\caption{Performance of three models}\n     \\label{fig:4_7_2}\n\\end{figure}\\\\\nFig.\\ref{fig:4_7_3} shows the train error and test error for each model. The single neuron model learning curve rapidly decrease and then keep flat. While the test error of deep network starts at lower point and then converges to a slightly lower value. However, the single neuron models converge much more rapidly than the deep network, since their architectures are simple which are easily to be trained.\n\\begin{figure}[htb]\n     \\centering\n     \\includegraphics[width=0.8\\textwidth]{fig/4/47a3.eps}\n     \\caption{Learning curves of three models}\n     \\label{fig:4_7_3}\n\\end{figure}\n\\newpage\n\\section{Noise power and drawbacks of Deep Network}\nExperiments are repeated by changing different power of noise which are $\\sigma^2=$ 0, 0.01, 0.2. Fig.\\ref{fig:4_8_b} shows the predictions and learning curves with $\\sigma^2=0$. The model of deep network outperform during training and testing. The series is accurately captured in training and acceptable error in testing. However, the single neutron models can not predict non-linear series as well. \n\\begin{figure}[htb]\n     \\centering\n     \\begin{subfigure}[b]{0.8\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48b1.eps}\n     \\end{subfigure}\n     \\begin{subfigure}[b]{0.8\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48b2.eps}\n     \\end{subfigure}\n     \\caption{Performance of three models, $\\sigma^2=0$}\n     \\label{fig:4_8_b}\n\\end{figure}\\\\\nWhen adding a small power of noise $\\sigma^2=0.01$, the performance of deep network model is getting worse. Parts of trends are inaccurately captured, resulting in a slightly increased error. Nevertheless, the deep network model still has expressive performance compared with single neuron models.\n\\begin{figure}[htb]\n     \\centering\n     \\begin{subfigure}[b]{0.6\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48a1.eps}\n     \\end{subfigure}\n     \\begin{subfigure}[b]{0.7\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48a2.eps}\n     \\end{subfigure}\n     \\caption{Performance of three models, $\\sigma^2=0.01$}\n     \\label{fig:4_8_a}\n\\end{figure}\\\\\nIf the noise power is $\\sigma^2=0.2$, the deep network model suffers the problem of over-fitting, which makes the model to predict the noise  sufficiently in training. Thus, the testing error keeps increasing trend.\n\\begin{figure}[H]\n     \\centering\n     \\begin{subfigure}[b]{0.6\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48c1.eps}\n     \\end{subfigure}\n     \\begin{subfigure}[b]{0.7\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/4/48c2.eps}\n     \\end{subfigure}\n     \\caption{Performance of three models, $\\sigma^2=0.2$}\n     \\label{fig:4_8_c}\n\\end{figure}\n\\noindent\nIn summary, by varying the power of noise, the single neuron models perform much robust and stable with less computational cost as well, even if their performances need to be improved. As to the deep network model, it is easily affected by the noise power leading to a unstable performance. Moreover, due to fully-connected with all previous layer inputs and next layer outputs, the computational cost of deep network training is quite large.\n", "meta": {"hexsha": "9da82c1eb6af548821c81348d9285c392e9f00fa", "size": 15078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part4/Part4.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/Part4/Part4.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/Part4/Part4.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": 60.5542168675, "max_line_length": 1051, "alphanum_fraction": 0.7116328426, "num_tokens": 4329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6171992170954165}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\\section{AMC}\\label{sec:amc}\n\t\t\\begin{problem}[$2014$ Norwegian Mathematical Olympiad, problem $1$]\n\t\t\tLet $x,y$ be non-negative real numbers. Show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx^{2}+y^{2}+1\n\t\t\t\t\t\t& \\leq \\sqrt{(x^{3}+y+1)(y^{3}+x+1)}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[$2013$ Norwegian Mathematical Olympiad, problem $1$]\n\t\t\tFind all real numbers $a$ such that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t3x^{2}+y^{2}\n\t\t\t\t\t\t& \\geq -ax(x+y)\n\t\t\t\t\\end{align*}\n\t\t\tholds for all real numbers $x,y$.\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2012$, problem $4$]\n\t\t\tLet $x,y$ be positive real numbers. Show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(1+\\dfrac{x}{y}\\right)^{3}+\\left(1+\\dfrac{y}{x}\\right)^{3}\n\t\t\t\t\t\t& \\geq 16\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2010$, problem $2$]\n\t\t\tLet $x$ be a real number such that $0<x<1$. Show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{x^{2}}{1-x}+\\dfrac{(1-x)^{2}}{x}\n\t\t\t\t\t\t& \\geq1\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2009$, problem $4$]\n\t\t\tShow that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{2010}{2009}\\right)^{2009}\n\t\t\t\t\t\t& > 2\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2008$, problem $3$]\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\t\\item Let $x,y$ be positive real numbers such that $x+y=2$. Show that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\\dfrac{1}{x}+\\dfrac{1}{y}\n\t\t\t\t\t\t\t& \\leq\\dfrac{1}{x^{2}}+\\dfrac{1}{y^{2}}\n\t\t\t\t\t\\end{align*}\n\t\t\t\t\\item Let $x,y,z$ be real numbers such that $x+y+z=2$. Show that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\\dfrac{1}{x}+\\dfrac{1}{y}+\\dfrac{1}{z}+\\dfrac{4}{9}\n\t\t\t\t\t\t\t& \\leq \\dfrac{1}{x^{2}}+\\dfrac{1}{y^{2}}+\\dfrac{1}{z^{2}}\n\t\t\t\t\t\\end{align*}\n\t\t\t\\end{enumerate}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2006$, problem $2$]\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\t\\item Let $a,b$ be real non-negative numbers. Show that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\ta+b\n\t\t\t\t\t\t\t& \\geq \\dfrac{a^{2}+b^{2}}{2}+\\sqrt{ab}\n\t\t\t\t\t\\end{align*}\n\t\t\t\t\\item Let $a,b$ be real numbers in the interval $[0,3]$. Show that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\\dfrac{a^{2}+b^{2}}{2}+\\sqrt{ab}\n\t\t\t\t\t\t\t& \\geq \\dfrac{(a+b)^{2}}{2}\n\t\t\t\t\t\\end{align*}\n\t\t\t\\end{enumerate}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2005$, problem $4$]\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\\item Let $a,b,c$ be real positive numbers. Show that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t(a+b)(a+c)\n\t\t\t\t\t\t\t& \\geq2\\sqrt{abc(ab+bc+ca)}\n\t\t\t\t\t\\end{align*}\n\t\t\t\t\\item Let $a,b,c$ be real numbers such that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\tab+bc+ca\n\t\t\t\t\t\t\t& > a+b+c>0\n\t\t\t\t\t\\end{align*}\n\t\t\t\\end{enumerate}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2003$, problem $2$]\n\t\t\tLet $a_{1},\\ldots,a_{n}$ be $n$ positive integers. Show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sum_{i=1}^{n}a_{i}^{3}\n\t\t\t\t\t\t& \\geq\\left(\\sum_{i=1}^{n}a_{i}\\right)^{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2002$, problem $2$]\n\t\t\tLet $n\\geq2$ be a positive integer and $x_{1},\\ldots,x_{n},y_{1},\\ldots,y_{n}$ be positive real numbers such that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx_{1}+\\ldots+x_{n}\n\t\t\t\t\t\t& \\geq x_{1}y_{1}+\\ldots+x_{n}y_{n}\n\t\t\t\t\\end{align*}\n\t\t\tShow that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\tx_{1}+\\ldots+x_{n}\n\t\t\t\t\t\t& \\leq \\dfrac{x_{1}}{y_{1}}+\\ldots+\\dfrac{x_{n}}{y_{n}}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $2000$, problem $2$]\n\t\t\tLet $a,b,c,d$ be non-negative real numbers such that $a+b+c+d=4$. Show that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sqrt{a+b+c}+\\sqrt{b+c+d}+\\sqrt{c+d+a}+\\sqrt{d+a+b}\n\t\t\t\t\t\t& \\geq 6\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $1999$, problem $1$]\n\t\t\tIf $a,b,c,d,e$ are real numbers, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\ta^{2}+b^{2}+c^{2}+d^{2}+e^{2}\n\t\t\t\t\t\t& \\geq a(b+c+d+e)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $1995$, problem $4$]\n\t\t\tLet $x_{i},y_{i}$ be positive real numbers for $1\\leq i\\leq n$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\sum_{i=1}^{n}(x_{i}+y_{i})^{2}\\right)\\left(\\dfrac{1}{\\sum_{i=1}^{n}x_{i}y_{i}}\\right)\n\t\t\t\t\t\t& \\geq 4n^{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $1994$, problem $3$]\n\t\t\tLet $x_{1},\\ldots,x_{1994}$ be positive real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{x_{1}}{x_{2}}\\right)^{\\frac{x_{1}}{x_{2}}}\\cdots\\left(\\dfrac{x_{1993}}{x_{1994}}\\right)^{\\frac{x_{1994}}{x_{1993}}}\n\t\t\t\t\t\t& \\geq \\left(\\dfrac{x_{1}}{x_{2}}\\right)^{\\frac{x_{2}}{x_{1}}}\\cdots\\left(\\dfrac{x_{1993}}{x_{1994}}\\right)^{\\frac{x_{1994}}{x_{1993}}}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $1993$, problem $1$]\n\t\t\t\\begin{enumerate}[1.]\n\t\t\t\t\\item Let $a,b,c$ be sides of a triangle. Prove that\n\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\\dfrac{a}{b+c}+\\dfrac{b}{c+a}+\\dfrac{c}{a+b}\n\t\t\t\t\t\t\t& < 2\n\t\t\t\t\t\\end{align*}\n\t\t\t\\end{enumerate}\n\t\t\\end{problem}\n\t\n\t\t\\begin{problem}[Norwegian Mathematical Olympiad $1993$, problem $2$]\n\t\t\tLet $a,b,c,d$ are real numbers such that $b<c<d$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a+b+c+d)^{2}\n\t\t\t\t\t\t& > 8(ac+bd)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "7db1c67db0a3df0fe1e277d38057137d828fa783", "size": 5214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "amc.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": "amc.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": "amc.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": 32.3850931677, "max_line_length": 141, "alphanum_fraction": 0.5824702723, "num_tokens": 2164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6169462088147001}}
{"text": "\\documentclass{article}\n\n\\usepackage{graphicx}\n\\usepackage{array}\n\\usepackage[group-separator={,}]{siunitx}\n\\usepackage{tikz}\n\\usepackage{hyperref}\n\n%\\usepackage{bm}\n%\\usepackage{graphicx}\n\n\\title{Symmetric Three-body Problem Notes}\n\\author{Scott Hendrickson}\n\n\\begin{document}\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Equations of Motion}\n\n\\label{sec:intro}\n\nFrom Ekeland page 59 (paperback edition):\n\n\\begin{quote}\nImagine two stars of equal mass, rotating around their common center of gravity. Newton's law asserts that this is possible, and that the orbit of the two stars will be a circle, along which they travel with equal speed, being exactly opposite to each other at all times. [...] A third body, with very small mass--a comet, for instance--moves along [the axis].\n\\end{quote}\n\n%%%%%%%%\n\\begin{figure}[h]\n\\begin{center}\n\t%%%%%\n\t%\n\t% http://cremeronline.com/LaTeX/minimaltikz.pdf\n\t%\n\t\\begin{tikzpicture}[scale=0.9]]\n\t% arrows\n\t\\draw [thick, -] (0, -3) -- (0,4) ;\n\t\\draw [thick, <->] (0.1, 0) -- (3.1,0) ;\n\t%\\draw [thick, <->] (-0.1, 0) -- (-3.1,0) ;\n\t\\draw [thick, <->] (3.5, 0.4) -- (3.5,1.0) ;\n\t\\draw [thick, <->] (-3.5, 0.4) -- (-0.2,3.0) ;\n\t% circles\n\t\\draw [orange, ultra thick] (0,0) ellipse (3.5 and 1.3);\n\t\\draw [fill=purple, ultra thick] (0, 3.0) circle [radius=0.1];\n\t\\draw [fill=green, ultra thick] (3.5,0) circle [radius=0.29];\n\t\\draw [fill=green, ultra thick] (-3.5,0) circle [radius=0.29];\n\t% labels\n\t\\node[align=center, below] at (1.75,0.4){$r$};\n\t\\node[align=center, below] at (3.7,0.9){$y$};\n\t\\node[align=center, below] at (0.2,2){$z$};\n\t\\node[align=center, below] at (3.5,-0.5){$m$};\n\t\\node[align=center, below] at (-3.5,-0.5){$m$};\n\t\\node[align=center, below] at (0.4,3.05){$\\mu m$};\n\t\\node[align=center, below] at (-2.7,2.5){$\\sqrt{r^2 + (z-y)^2}$};\n\t\\end{tikzpicture}\n\\end{center}\n\\caption{Two stars of the same mass $m$ travel in a circular orbit along with a small comet on the centerline with an initial velocity along the z-axis. The system has cylindrical symmetry so that the plain containing the stars moves as a single unit and the comet does not leave the axis. }\n\\label{fig:tradeoff}\n\\end{figure}\n%%%%%%%%\n\nGravitational potentials from the interactions of the 3 masses. The first term is the interaction of the\nstars while the second term is the sum of the interactions of the comet with each of the stars.\n\n\\begin{eqnarray}\nU_{m m} & = & \\frac{-Gmm}{2r} \\\\\nU_{\\mu m} & = & \\frac{-2G\\mu mm}{\\sqrt{r^2 + (z-y)^2}} \\\\\n\\label{eq:potentials}\n\\end{eqnarray}\n\nKinetic energy terms represent radial, circular and motion along the axis.\n\n\\begin{eqnarray}\nT & = & \\frac{1}{2} \\mu m \\dot{z}^2 + m \\dot{y}^2 + m \\dot{r}^2 + m(r\\dot{\\theta})^2\n\\label{eq:potentials}\n\\end{eqnarray}\n\nLagrangian.\n\n\\begin{eqnarray}\n\\mathcal{L} & = & T - V \\\\\n& = & \\frac{1}{2} \\mu m \\dot{z}^2 + m \\dot{y}^2 + m \\dot{r}^2 + m(r\\dot{\\theta})^2 + \\frac{-Gmm}{2r} +  \\frac{-2G\\mu mm}{\\sqrt{r^2 + (z-y)^2}}\n\\label{eq:potentials}\n\\end{eqnarray}\n\nPartial derivatives with respect to velocities and postitions.\n\n\\begin{eqnarray}\n\\frac{\\partial{\\mathcal{L}}}{\\partial{ \\dot{z}}} & = & \\mu m \\dot{z} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{ \\dot{r}}} & = & 2m\\dot{r} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{ \\dot{y}}} & = & 2m\\dot{y} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{ \\dot{\\theta}}} & = & 2mr^2\\dot{\\theta} \n\\end{eqnarray}\n\n\\begin{eqnarray}\n\\frac{\\partial{\\mathcal{L}}}{\\partial{z}} & = & \\frac{2G \\mu m^2 (z-y)}{(r^2 + (z-y)^2)^{3/2}} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{r}} & = & 2mr\\theta^2 - \\frac{G m^2}{r^2} - \\frac{2 G \\mu m^2 r}{(r^2 + (z-y)^2)^{3/2}} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{y}} & = & - \\frac{2G \\mu m^2 (z-y)}{(r^2 + (z-y)^2)^{3/2}} \\\\\n\\frac{\\partial{\\mathcal{L}}}{\\partial{\\theta}} & = & 0 \n\\end{eqnarray}\n\n\\section{Equations of motion}\n\n\\begin{eqnarray}\n\\ddot{z} & = & \\frac{2G m (z-y)}{(r^2 + (z-y)^2)^{3/2}} \\\\\n\\ddot{y} & = & \\frac{G \\mu m (z-y)}{(r^2 + (z-y)^2)^{3/2}} \\\\\n\\ddot{r} & = & r\\dot{\\theta}^2 - Gm (\\frac{1}{2r^2} + \\frac{\\mu r}{(r^2 + (z-y)^2)^{3/2}}) \\\\\n\\ddot{\\theta} & = & \\frac{-2 \\dot{r} \\dot{\\theta}}{r} \n\\label{eq:mot}\n\\end{eqnarray}\n\nRewrite as a system of $1^{st}$ differential equations and integrated with a ``Leap frog'' integrator. This\npreserves phase space topology.\n\n\\begin{figure}[h]\n    \\begin{center}\n        \\includegraphics[height=7.75in]{./img/example.png}\n    \\end{center}\n\\label{fig:example}\n\\end{figure}\n\n\\section{Escape Velocity}\n\nEnergy at $z=0$ is the energy at $z=\\infty$,\n\n\\begin{eqnarray}\n\\frac{1}{2}\\mu m v_0^2 - \\frac{2G \\mu m^2}{r} & = & \\frac{1}{2}\\mu m (0)^2 - \\frac{2G \\mu m^2}{(\\infty)} \\\\\nv_0 & = & \\sqrt{\\frac{4Gm}{r}} \\\\\nv_0 & = & \\sqrt{\\frac{4(4.302e^-3 \\text{pc sun}^{-1} (\\frac{km}{s})^2) (1 \\text{ sun})}{0.5 \\text{ pc}}} \\\\\n& \\approx & 0.185515 \\frac{km}{s}\n\\label{eq:esc}\n\\end{eqnarray}\n\n\\section{Small z}\n\nFor small z, $\\tan{z/r} \\approx z/r$ and r is constant,\n\n\\begin{eqnarray}\n\\mu m \\ddot{z} & = &  - \\frac{2G \\mu m^2}{r^2} \\frac{z}{r} \\\\\nT & = & 2\\pi \\sqrt{\\frac{2G \\mu m^2}{r^3}} \\\\\n& \\approx & 23.94885 \\text{  time units}\n\\label{eq:small}\n\\end{eqnarray}\n\n%\n%\\begin{table}\n%\\caption{Fit parameters for Twitter, earthquake.}\n%\\label{tab:pars}\n%\\begin{tabular}{ | l | l |}\n%    \\hline\n%    Parameter & Value  \\\\ \\hline\n%    $t_0$ & fixxx sec\\\\ \n%              & 2012-03-20 18:08:22 UTC\\\\\n%    $r_0$ & fixxx act/min\\\\ \n%    $\\alpha$ & 0.001152 sec$^{-1}$\\\\ \n%    $\\beta$ & 0.000220 sec$^{-1}$\\\\ \\hline\n%    $t_{time_to_peak}$ & 26 min 30 sec \\\\ \n%    $S_{vol}$ & 5,568,800 tweets \\\\\n%    $t_{1/2}$ & 92 min 01 sec \\\\\n%    $t_{avg}$ & 87 min 49 sec \\\\ \\hline\n%\\end{tabular}\n%\\end{table}\n%\n%\\section{Sigmoid Model}\n%\\label{sec:sigmodel}\n%\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Sources and Licensing} \n\nFor code and example output, please visit and fork or clone \\url{https://github.com/DrSkippy/Gravitational-Three-Body-Symmetric}.\n\\noindent If you find errorsor have comments, please email scott@drskippy.net.\n\\noindent This work is licensed under a Creative Commons CC0 1.0 Universal (CC0 1.0) \n\\noindent \\url{http://creativecommons.org/publicdomain/zero/1.0/}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{thebibliography}{2013}\n\n\\bibitem[Ekeland1990]{Ekeland:1990} Ivar Ekeland. Mathematics and the Unexpected.  \\url{http://www.amazon.com/Mathematics-Unexpected-Ivar-Ekeland/dp/0226199908} 1990.\n\n\\bibitem[Drexel]{Drexel} The Leapfrog Integrator, \\url{http://einstein.drexel.edu/courses/Comp_Phys/Integrators/leapfrog/}.\n\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "0071306de27b34281f331b8ecea89100c8f618f1", "size": 6569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "DrSkippy/Gravitational-Three-Body-Symmetric", "max_stars_repo_head_hexsha": "b718b4d22633c17aa61981f6e1aa47fd0f55de44", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-30T05:36:45.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-30T05:36:45.000Z", "max_issues_repo_path": "notes.tex", "max_issues_repo_name": "DrSkippy/Gravitational-Three-Body-Symmetric", "max_issues_repo_head_hexsha": "b718b4d22633c17aa61981f6e1aa47fd0f55de44", "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": "notes.tex", "max_forks_repo_name": "DrSkippy/Gravitational-Three-Body-Symmetric", "max_forks_repo_head_hexsha": "b718b4d22633c17aa61981f6e1aa47fd0f55de44", "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.3926701571, "max_line_length": 360, "alphanum_fraction": 0.6110519105, "num_tokens": 2514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6169462061054718}}
{"text": "\\section{Linear combinations, span, and linear independence}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine if a vector is within a given span.\n  \\item Determine if a set is spanning.\n  \\item Determine if a set is linearly independent.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we will again explore concepts introduced earlier in terms of $\\R^n$ and extend them to apply to abstract vector spaces.\n\nWe can now revisit many of the concepts first introduced in\nChapter~\\ref{cha:vectors-rn} in the context of general vector spaces.\nWe will look at linear combinations, span, and linear independence in\nthis section, and at subspaces, bases, and dimension in the next\nsection.\n\n\\begin{definition}{Linear combination}{linear-combination-vector-space}\n  Let $V$ be a vector space over a field $K$. Let\n  $\\vect{u}_1,\\ldots,\\vect{u}_n\\in V$. A vector\n  $\\vect{v}\\in V$ is called a \\textbf{linear combination}%\n  \\index{linear combination!in a vector space}%\n  \\index{linear combination!of vectors} of\n  $\\vect{u}_1,\\ldots,\\vect{u}_n$ if there exist scalars\n  $a_1,\\ldots,a_n\\in K$ such that\n  \\begin{equation*}\n    \\vect{v} = a_1 \\vect{u}_1 + \\ldots + a_n \\vect{u}_n.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Linear combination of matrices}{linear-combination-matrix}\n  Write the matrix $A=\\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 2 \\end{mymatrix}$\n  as a linear combination%\n  \\index{linear combination!of matrices} of\n  \\begin{equation*}\n    \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mymatrix},\\quad\n    \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -1 \\end{mymatrix},\\quad\n    \\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 0 \\end{mymatrix},\\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{rr} 0 & -1 \\\\ 1 & 0 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We must find coefficients $a,b,c,d$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 2 \\end{mymatrix}\n    ~=~ a \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mymatrix}\n    + b \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -1 \\end{mymatrix}\n    + c \\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 0 \\end{mymatrix}\n    + d \\begin{mymatrix}{rr} 0 & -1 \\\\ 1 & 0 \\end{mymatrix},\n  \\end{equation*}\n  or equivalently,\n  \\begin{equation*}\n    \\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 2 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{cc} a+b & c-d \\\\ c+d & a-b \\end{mymatrix}.\n  \\end{equation*}\n  This yields a system of four equations in four variables:\n  \\begin{equation*}\n    \\begin{array}{r@{~~}c@{~}r}\n      a+b &=& 1, \\\\\n      c+d &=& -1, \\\\\n      c-d &=& 3, \\\\\n      a-b &=& 2.\n    \\end{array}\n  \\end{equation*}\n  We can easily solve the system of equations to find the unique\n  solution $a=\\frac{3}{2}$, $b=-\\frac{1}{2}$, $c=1$, $d=-2$.\n  Therefore\n  \\begin{equation*}\n    \\begin{mymatrix}{rr} 1 & 3 \\\\ -1 & 2 \\end{mymatrix}\n    ~=~ \\frac{3}{2} \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mymatrix}\n    - \\frac{1}{2} \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & -1 \\end{mymatrix}\n    + 1 \\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 0 \\end{mymatrix}\n    - 2 \\begin{mymatrix}{rr} 0 & -1 \\\\ 1 & 0 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Linear combination of polynomials}{linear-combination-polynomials}\n  Write the polynomial $p(x) = 7x^2 + 4x - 3$ as a linear combination%\n  \\index{linear combination!of polynomials} of\n  \\begin{equation*}\n    q_1(x) = x^2,\\quad\n    q_2(x) = (x+1)^2,\\quad\\mbox{and}\\quad\n    q_3(x) = (x+2)^2.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Note that $q_2(x) = (x+1)^2 = x^2 + 2x + 1$ and\n  $q_3(x) = (x+2)^2 = x^2 + 4x + 4$. We must find coefficients $a,b,c$\n  such that $p(x) = aq_1(x) + bq_2(x) + cq_3(x)$, or equivalently,\n  \\begin{equation*}\n    7x^2 + 4x - 3 ~=~ ax^2 ~+~ b(x^2 + 2x + 1) ~+~ c(x^2 + 4x + 4).\n  \\end{equation*}\n  Collecting equal powers of $x$, we can rewrite this as\n  \\begin{equation*}\n    7x^2 + 4x - 3 ~=~ (a+b+c)x^2 ~+~ (2b+4c)x ~+~ (b+4c).\n  \\end{equation*}\n  Since two polynomials are equal if and only if each corresponding\n  coefficient is equal, this yields a system of three equations in\n  three variables\n  \\begin{equation*}\n    \\begin{array}{r@{~~}c@{~}r}\n      a+b+c &=& 7, \\\\\n      2b+4c &=& 4, \\\\\n      b+4c &=& -3.\n    \\end{array}\n  \\end{equation*}\n  We can easily solve this system of equations and find that the\n  unique solution is $a=\\frac{5}{2}$, $b=7$,\n  $c=-\\frac{5}{2}$. Therefore\n  \\begin{equation*}\n    p(x) ~=~ \\frac{5}{2}\\,q_1(x) ~+~ 7\\,q_2(x) ~-~ \\frac{5}{2}\\,q_3(x).\n  \\end{equation*}\n\\end{solution}\n\nAs in Chapter~\\ref{cha:vectors-rn}, the span of a set of vectors is\ndefined as the set of all of its linear combinations. We generalize\nthe concept of span to consider spans of arbitrary (possibly finite,\npossibly infinite) sets of vectors.\n\n\\begin{definition}{Span of a set of vectors}{vector-space-span}\n  Let $V$ be a vector space over some field $K$, and let $S$ be a set\n  of vectors (i.e., a subset of $V$). The \\textbf{span}%\n  \\index{span}%\n  \\index{vector!span}%\n  \\index{vector space!span} of $S$ is the set of all linear\n  combinations of elements of $S$. In symbols, we have\n  \\begin{equation*}\n    \\sspan S\n    ~=~ \\set{a_1\\vect{u}_1+\\ldots+a_k\\vect{u}_k \\mid\n      \\mbox{\n        $\\vect{u}_1,\\ldots,\\vect{u}_k\\in S$\n        and\n        $a_1,\\ldots,a_k\\in K$\n      }}.\n  \\end{equation*}\n\\end{definition}\n\nIt is important not to misunderstand this definition.  Even when the\nset $S$ is infinite, each {\\em individual} element\n$\\vect{v}\\in\\sspan S$ is a linear combination of only {\\em finitely\n  many} elements $\\vect{u}_1,\\ldots,\\vect{u}_k$ of $S$.\nThe definition does not talk about infinite linear combinations\n\\begin{equation*}\n  a_1\\vect{u}_1 + a_2\\vect{u}_2 + a_3\\vect{u}_3 + \\ldots\n\\end{equation*}\nIndeed, such infinite sums do not typically exist.  However, different\nelements $\\vect{v},\\vect{w}\\in\\sspan S$ can be linear combinations of\na different (finite) number of vectors of $S$. For example, it is\npossible that $\\vect{v}$ is a linear combination of 10 elements of\n$S$, and $\\vect{w}$ is a linear combination of 100 elements of $S$.\n\n\\begin{example}{Spans of sequences}{spans-sequences}\n  Consider the vector space $\\Seq_K$ of infinite sequences. For every\n  $k\\in\\N$, let $e^k$ be the sequence whose $k\\th$ element is $1$ and\n  that is $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.\n  Let $S=\\set{e^k \\mid k\\in\\N}$. Which of the following sequences are in\n  $\\sspan S$?\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $f = (1,1,1,0,0,0,0,0,\\ldots)$ (followed by infinitely many zeros),\n    \\item $g = (1,2,0,5,0,0,0,0,\\ldots)$ (followed by infinitely many zeros),\n    \\item $h = (1,1,1,1,1,1,1,1,\\ldots)$ (followed by infinitely many ones),\n    \\item $k = (1,0,1,0,1,0,1,0,\\ldots)$ (forever alternating between $1$ and $0$).\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item We have $f\\in\\sspan S$, because $f = e^0 + e^1 + e^2$.\n    \\item We have $g\\in\\sspan S$, because $g = 1e^0 + 2e^1 + 5e^3$.\n    \\item The sequence $h$ is not in $\\sspan S$, because each element\n      of $\\sspan S$ is, by definition, a linear combinations of {\\em\n        finitely many} elements of $S$. No linear combinations of\n      finitely many $e^k$ can end in infinitely many ones. Note that\n      we are not permitted to write an infinite sum such as\n      $e^0+e^1+e^2+\\ldots$. Such infinite sums are not defined in\n      vector spaces.\n    \\item The sequence $k$ is not in $\\sspan S$, for the same reason.\n      We would need to add infinitely many sequences of the form $e^k$\n      to get a sequence that contains infinitely many non-zero\n      elements. However, this is not permitted by the definition of\n      span.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n  \\vspace{-4ex}\n\\end{solution}\n\n\\begin{example}{Span of polynomials}{span-of-polynomials}\n  Let $p(x)=7x^2+4x-3$. Is $p(x)\\in\\sspan\\set{x^2,~ (x+1)^2,~ (x+2)^2}$?\n\\end{example}\n\n\\begin{solution}\n  The answer is yes, because we found in\n  Example~\\ref{exa:linear-combination-polynomials} that\n  $p(x) = \\frac{5}{2}\\,x^2 ~+~ 7\\,(x+1)^2 ~-~ \\frac{5}{2}\\,(x+2)^2$.\n\\end{solution}\n\nWe say that a set of vectors $S$ is a \\textbf{spanning set}%\n\\index{spanning set}%\n\\index{vector space!spanning set} for $V$ if $V = \\sspan S$.\n\n\\begin{example}{Spanning set}{spanning-set}\n  Let $S = \\set{x^2,~ (x+1)^2,~ (x+2)^2}$. Show that $S$ is a\n  spanning set for $\\Poly_2$, the vector space of all polynomials of\n  degree at most $2$.\n\\end{example}\n\n\\begin{solution}\n  This is analogous to Example~\\ref{exa:linear-combination-polynomials}.\n  Consider an arbitrary element $p(x) = p_2x^2 + p^1x + p_0$ of\n  $\\Poly_2$. We must show that $p(x)\\in\\sspan S$, i.e., that there\n  exists $a,b,c\\in K$ such that\n  \\begin{equation*}\n    p(x) = ax^2 + b(x+1)^2 + c(x+2)^2.\n  \\end{equation*}\n  We can equivalently rewrite this equation as\n  \\begin{equation*}\n    p_2x^2 + p^1x + p_0 ~=~ (a+b+c)x^2 ~+~ (2b+4c)x ~+~ (b+4c),\n  \\end{equation*}\n  which yields the system of equations\n  \\begin{equation*}\n    \\begin{array}{r@{~~}c@{~}r}\n      a+b+c &=& p_2 \\\\\n      2b+4c &=& p_1 \\\\\n      b+4c &=& p_0\n    \\end{array}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{ccc|c}\n      1 & 1 & 1 & p_2 \\\\\n      0 & 2 & 4 & p_1 \\\\\n      0 & 1 & 4 & p_0 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{ccc|c}\n      1 & 0 & 0 & p_2-\\frac{3}{4}p_1+\\frac{1}{2}p_0 \\\\\n      0 & 1 & 0 & p_1-p_0 \\\\\n      0 & 0 & 1 & \\frac{1}{2}p_0-\\frac{1}{4}p_1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since the system has rank 3, it has a solution. Therefore,\n  $p(x)\\in\\sspan S$. Since $p(x)$ was an arbitrary element of\n  $\\Poly_2$, it follows that $S$ is a spanning set for $\\Poly_2$.\n\\end{solution}\n\nTo define the concept of linear independence in a general vector\nspace, it will be convenient to base our definition on the\n``alternative'' characterization of\nTheorem~\\ref{thm:characterization-linear-independence}. Here too, we\ngeneralize the definition to an arbitrary (finite or infinite) set of\nvectors.\n\n\\begin{definition}{Linear independence}{linear-independence-vector-space}\n  Let $V$ be a vector space over some field $K$. A finite set of\n  vectors $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is called\n  \\textbf{linearly independent}%\n  \\index{linear independence!in a vector space}%\n  \\index{vector!linearly independent!in a vector space}%\n  \\index{vector space!linear independence}\n  if the equation\n  \\begin{equation*}\n    a_1\\,\\vect{u}_1 + \\ldots + a_k\\,\\vect{u}_k = \\vect{0}\n  \\end{equation*}\n  has only the trivial solution $a_1,\\ldots,a_k=0$. An infinite set\n  $S$ of vectors is called linearly independent if every finite subset\n  of $S$ is linearly independent. A set of vectors is called\n  \\textbf{linearly dependent}%\n  \\index{linear dependence}%\n  \\index{vector!linearly dependent}if it is not linearly independent.\n\\end{definition}\n\n\\begin{example}{Linearly independent polynomials}{linear-independence-polynomial}\n  Determine whether the polynomials $x^2$, $x^2 + 2x - 1$, and\n  $2x^2 - x + 3$ are linearly independent.\n\\end{example}\n\n\\begin{solution}\n  According to the definition of linear independence, we must solve\n  the equation\n  \\begin{equation*}\n    ax^2 + b(x^2 + 2x - 1) + c(2x^2 - x + 3) ~=~ 0.\n  \\end{equation*}\n  If there is a non-trivial solution, the polynomials are linearly\n  dependent. If there is only the trivial solution, they are linearly\n  independent. We first rearrange the left-hand side to collect equal\n  powers of $x$:\n  \\begin{equation*}\n    (a + b + 2c)x^2 + (2b - c)x + (3c - b) ~=~ 0.\n  \\end{equation*}\n  This turns into a system of 3 equations in 3 variables:\n  \\begin{equation*}\n    \\begin{array}{rcl}\n      a + b + 2c &=& 0 \\\\\n      2b - c &=& 0 \\\\\n      3c - b &=& 0\n    \\end{array}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 &  1 &  2 & 0 \\\\\n      0 &  2 & -1 & 0 \\\\\n      0 & -1 &  3 & 0\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 &  0 &  0 & 0 \\\\\n      0 &  1 &  0 & 0 \\\\\n      0 &  0 &  1 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since the system has rank 3, there are no free variables. The only\n  solution is $a=b=c=0$, and the polynomials are linearly\n  independent.\n\\end{solution}\n\n\\begin{example}{Linearly independent sequences}{linear-independence-sequences}\n  Let $K$ be a field, and consider again the sequences from\n  Example~\\ref{exa:spans-sequences},\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. Let $S=\\set{e^0, e^1, e^2,\\ldots}$. This is an infinite\n  subset of $\\Seq_K$. Show that $S$ is linearly independent.\n\\end{example}\n\n\\begin{solution}\n  Since $S$ is an infinite set, we have to show that every finite\n  subset of $S$ is linearly independent. So consider a finite subset\n  \\begin{equation*}\n    \\set{e^{k_1}, e^{k_2}, \\ldots, e^{k_n}} \\subseteq S\n  \\end{equation*}\n  and assume that\n  \\begin{equation}\\label{eqn:linear-independence-sequences}\n    a_1e^{k_1} + a_2e^{k_2} + \\ldots + a_ne^{k_n} = 0.\n  \\end{equation}\n  We have to show that $a_1,\\ldots,a_n=0$. Consider some index\n  $i\\in\\set{1,\\ldots,n}$. Then the $k_i\\th$ element of\n  $a_1e^{k_1} + \\ldots + a_ne^{k_n}$ is equal to $a_i$ by the\n  left-hand side of {\\eqref{eqn:linear-independence-sequences}}, but\n  it is also equal to $0$ by the right-hand side of\n  {\\eqref{eqn:linear-independence-sequences}}. It follows that $a_i=0$\n  for all $i\\in\\set{1,\\ldots,n}$, and therefore\n  $\\set{e^{k_1}, e^{k_2}, \\ldots, e^{k_n}}$ is linearly\n  independent. Since $\\set{e^{k_1}, e^{k_2}, \\ldots, e^{k_n}}$ was an\n  arbitrary finite subset of $S$, it follows, by definition, that $S$\n  is linearly independent.\n\\end{solution}\n\n\\begin{example}{Linearly dependent matrices}{linearly-dependent-matrices}\n  Determine whether the following elements of $\\Mat_{m,n}$ are\n  linearly independent:\n  \\begin{equation*}\n    M_1 = \\begin{mymatrix}{rr} -1 & 0 \\\\ 1 & -1 \\end{mymatrix},\\quad\n    M_2 = \\begin{mymatrix}{rr}  1 & 1 \\\\ 1 &  2 \\end{mymatrix},\\quad\n    M_3 = \\begin{mymatrix}{rr}  1 & 3 \\\\ 5 &  4 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To determine whether $\\set{M_1,M_2,M_3}$ is linearly independent, we\n  look for solutions to\n  \\begin{equation*}\n    aM_1 + bM_2 + cM_3 = 0.\n  \\end{equation*}\n  Notice that this equation has non-trivial solutions, for example\n  $a=2$, $b=3$ and $c=-1$. Therefore the matrices are linearly\n  dependent.\n\\end{solution}\n\n\\begin{example}{Linearly independent functions}{linearly-independent-functions}\n  In the vector space $\\Func_{\\R,\\R}$ of real-valued functions on the\n  real numbers, show that the functions $f(x)=\\sin x$ and $g(x)=\\cos\n  x$ are linearly independent.\n\\end{example}\n\n\\begin{solution}\n  Assume $A\\sin x+B\\cos x=0$. Note that this is an equality of\n  functions, which means that it is true for all $x$. In particular,\n  substituting $x=0$ into the equation, and using the fact that\n  $\\sin 0=0$ and $\\cos 0=1$, we have\n  \\begin{equation*}\n    0 = A\\sin 0 + B\\cos 0 = A\\cdot 0 + B\\cdot 1 = B,\n  \\end{equation*}\n  and therefore $B=0$. On the other hand, substituting\n  $x=\\frac{\\pi}{2}$ into the equation, and using the fact that\n  $\\sin\\frac{\\pi}{2} = 1$ and $\\cos\\frac{\\pi}{2}=0$, we have\n  \\begin{equation*}\n    0 = A\\sin\\frac{\\pi}{2} + B\\cos\\frac{\\pi}{2} = A\\cdot 1 + B\\cdot 0\n    = A,\n  \\end{equation*}\n  and therefore $A=0$. Therefore, the equation $A\\sin x+B\\cos x=0$\n  only has the trivial solution $A=B=0$, and it follows that $\\sin x$\n  and $\\cos x$ are linearly independent.\n\\end{solution}\n\nThe properties of linear independence that were discussed in\nChapter~\\ref{cha:vectors-rn} remain true in the general setting of\nvector spaces. For example, the first two parts of\nProposition~\\ref{prop:properties-linear-independence} apply without change.\n(The third part specifically mentions $\\R^n$, but can be generalized\nto any vector space of dimension $n$). We also have the usual\ncharacterization of linear dependence in terms of redundant vectors:\n\n\\begin{proposition}{Linear dependence and redundant vectors}{linear-dependence-redundant}\n  Let $V$ be a vector space, and let $\\vect{u}_1,\\vect{u}_2,\\ldots$ be\n  a (finite or infinite) sequence of vectors in $V$. If\n  $\\vect{u}_1,\\vect{u}_2,\\ldots$ are linearly dependent, then at least\n  one of the vectors can be written as a linear combination of earlier\n  vectors in the sequence:\n  \\begin{equation*}\n    \\vect{u}_j = a_1\\,\\vect{u}_1 + a_2\\,\\vect{u}_2 + \\ldots + a_{j-1}\\,\\vect{u}_{j-1},\n  \\end{equation*}\n  for some $j$.\n\\end{proposition}\n\n\\begin{proof}\n  Suppose that the vectors are linearly dependent. Then the equation\n  $b_1\\vect{u}_1+\\ldots+b_k\\vect{u}_k=\\vect{0}$ has a non-trivial solution\n  for some $k$. In other words, there exist scalars $b_1,\\ldots,b_k$,\n  not all equal to zero, such that\n  $b_1\\vect{u}_1+\\ldots+b_k\\vect{u}_k=\\vect{0}$. Let $j$ be the largest index\n  such that $b_j\\neq 0$. Then\n  $b_1\\vect{u}_1+\\ldots+b_j\\vect{u}_j=\\vect{0}$. Dividing by $b_j$ and\n  solving for $\\vect{u}_j$, we have\n  $\\vect{u}_j = -\\frac{b_1}{b_j}\\vect{u}_1 - \\ldots -\n  \\frac{b_{j-1}}{b_j}\\vect{u}_{j-1}$, so $\\vect{u}_j$ can be written\n  as a linear combination of earlier vectors as claimed.\n\\end{proof}\n\n\\begin{example}{Polynomials of increasing degree}{polynomials-increasing-degree}\n  Consider a sequence of non-zero polynomials $p_1(x), \\ldots, p_k(x)$\n  of increasing degree, i.e., such that the degree of each $p_i(x)$ is\n  strictly larger than that of $p_{i-1}(x)$. Show that\n  $p_1(x),\\ldots,p_k(x)$ are linearly independent in the vector space\n  $\\Poly$.\n\\end{example}\n\n\\begin{solution}\n  A polynomial of degree $n$ cannot be a linear combination of\n  polynomials of degree less than $n$. Therefore, none of the\n  polynomials $p_1(x), \\ldots, p_k(x)$ can be written as a linear\n  combination of earlier polynomials. By\n  Proposition~\\ref{prop:linear-dependence-redundant}, $p_1(x), \\ldots,\n  p_k(x)$ are linearly independent.\n\\end{solution}\n\nTheorems~\\ref{thm:unique-linear-combination} and\n{\\ref{thm:linearly-independent-subset}} also remain true in the\nsetting of general vector spaces. The original proofs can be used\nwithout change. Thus, if $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly\nindependent, then every vector\n$\\vect{v}\\in\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ can be uniquely\nwritten as a linear combination of\n$\\vect{u}_1,\\ldots,\\vect{u}_k$. Also, given any finite set of vectors,\nwe can find a subset of the vectors that is linearly independent and\nhas the same span.\n\nWe finish this section with a useful observation about linear\nindependence. Namely, given a linearly independent set of vectors and\none more vector that is not in their span, then we can add the vector\nto the set and it will remain linearly independent.\n\n\\begin{proposition}{Adding to a linearly independent set}{adding-linearly-independent}\n  Suppose $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is linearly\n  independent and\n  $\\vect{v}\\notin \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$. Then\n  the set\n  \\begin{equation*}\n    \\set{\\vect{u}_1,\\ldots,\\vect{u}_k,\\vect{v}}\n  \\end{equation*}\n  is also linearly independent.\n\\end{proposition}\n\n\\begin{proof}\n  Assume, on the contrary, that the set were linearly dependent. Then\n  by Proposition~\\ref{prop:linear-dependence-redundant}, one of the\n  vectors can be written as a linear combination of earlier vectors.\n  This vector cannot be one of the $\\vect{u}_i$, because\n  $\\vect{u}_1,\\ldots,\\vect{u}_k$ are linearly independent.  It\n  also cannot be $\\vect{v}$, because\n  $\\vect{v}\\notin\n  \\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$. Therefore, our\n  assumption cannot be true, and the set is linearly independent.\n\\end{proof}\n", "meta": {"hexsha": "487c52224a75a030d2335201644a561b38a93d02", "size": 19878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces-Spanning.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-Spanning.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-Spanning.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.756, "max_line_length": 137, "alphanum_fraction": 0.6592715565, "num_tokens": 7132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672043084051, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6169461860014873}}
{"text": "\\section{Introduction}\r\n\\begin{theorem}\r\n    Let $F,f:[a,b]\\to\\mathbb R$ are continuous and $F$ differentiable with $F^\\prime=f$, we have\r\n    $$\\int_a^bf(t)\\,\\mathrm dt=F(b)-F(a)$$\r\n\\end{theorem}\r\nThere is a reason why this theorem takes so long to prove.\r\nFirst of all obvious we need to actually define what we meant by all those terms in there and link them together.\r\nMore subtlely, this is a theorem about the real numbers.\r\nSuppose $F^\\prime=f=G^\\prime$, then $F$ and $G$ can be differed by a constant.\r\nSo if we set\r\n$$F(x)=\\begin{cases}\r\n    1\\text{, if $x^2>2$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nand $G\\equiv 0$.\r\nSo $F$ is differentiable at every rational number and those derivatives are $0$, and so is $G$, but $F$ is not constant.\r\nHence the theorem is simply not true for rational numbers, so we must use properties of real numbers.\\\\\r\nThese are what real analysis (in a beginner's level) is going to be about.", "meta": {"hexsha": "e4650a55f3103ad8dc0f5f2a7854fb0b5d3a152d", "size": 934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/intro.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": "0/intro.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": "0/intro.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": 51.8888888889, "max_line_length": 121, "alphanum_fraction": 0.6959314775, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6169106211222607}}
{"text": "\\documentclass[inequalities.tex]{subfile}\n\n\\begin{document}\n\t\\chapter{Practice Problems}\\label{ch:practice}\n\n\tWe will pose various types of problems here. The problems will not be sorted in any particular order. There will be no categorization and similar problems will not be put together. We did not provide practice problems per section or chapter because in real contest, you will have no way of knowing what technique or theorem to use. This is why we demonstrated some problems while discussing a particular concept but did not add any extra problems. Here, you are free to use any method necessary to solve the problems.\n\t\t\\begin{problem}\n\t\t\tLet $a,b,c$ be positive real numbers. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t(a^{3}+2)(b^{3}+2)(c^{3}+2)\n\t\t\t\t\t\t& \\geq (a+b+c)^{3}\n\t\t\t\t\\end{align*}\n\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tRearrange the inequality as\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t(a^{3}+1^{3}+1^{3})^{\\frac{1}{3}}(1^{3}+b^{3}+1^{3})^{\\frac{1}{3}}(1^{3}+1^{3}+c^{3})^{\\frac{1}{3}}\n\t\t\t\t\t\t\t\t& \\geq \\left(a^{3}1^{3}1^{3}\\right)^{\\frac{1}{3}}+\\left(1^{3}b^{3}1^{3}\\right)^{\\frac{1}{3}}+\\left(1^{3}1^{3}c^{3}\\right)^{\\frac{1}{3}}\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\twhich is obviously true by \\nameref{thm:holdergen}.\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\n\t\t\\begin{problem}\n\t\t\tLet $a,b$ be positive real numbers such that $a+b=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{1}{a^{2}}+\\dfrac{1}{b^{2}}\n\t\t\t\t\t\t& \\geq 8\n\t\t\t\t\\end{align*}\n\n\t\t\t\t\\begin{solution}\n\t\t\t\t\tUsing \\nameref{thm:holdergen} on $(a+b),(a+b),\\left(\\frac{1}{a^{2}}+\\frac{1}{b^{2}}\\right)$,\n\t\t\t\t\t\t\\begin{align*}\n\t\t\t\t\t\t\t(a+b)^{\\frac{1}{3}}(a+b)^{\\frac{1}{3}}\\left(\\dfrac{1}{a^{2}}+\\dfrac{1}{b^{2}}\\right)^{\\frac{1}{3}}\n\t\t\t\t\t\t\t\t& \\geq \\left(a\\cdot a\\cdot\\dfrac{1}{a^{2}}\\right)^{\\frac{1}{3}}+\\left(b\\cdot b\\cdot\\dfrac{1}{b^{2}}\\right)^{\\frac{1}{3}}\n\t\t\t\t\t\t\\end{align*}\n\t\t\t\t\\end{solution}\n\t\t\\end{problem}\n\n\t\t\\begin{problem}\n\t\t\tLet $a,b,c$ be positive real numbers such that $a+b+c=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t4a^{3}+9b^{3}+36c^{3}\n\t\t\t\t\t\t& \\geq 1\n\t\t\t\t\\end{align*}\n\t\t\tNotice that $4,9,36$ are square numbers while $a+b+c$ is also $1$. This along with the terms like $4a^{3}$ tells us to somehow cancel the factors $4,9,36$ so that we can use the fact that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(a^{3}\\right)^{\\frac{1}{3}}+\\left(b^{3}\\right)^{\\frac{1}{3}}+\\left(c^{3}\\right)^{\\frac{1}{3}}\n\t\t\t\t\t\t& = 1\n\t\t\t\t\\end{align*}\n\t\t\tFortunately, we also have $\\frac{1}{2}+\\frac{1}{3}+\\frac{1}{6}=1$ so using \\nameref{thm:holdergen},\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left(\\dfrac{1}{2}+\\dfrac{1}{3}+\\dfrac{1}{6}\\right)^{\\frac{1}{3}}\\left(\\dfrac{1}{2}+\\dfrac{1}{3}+\\dfrac{1}{6}\\right)^{\\frac{1}{3}}\\left(4a^{3}+9b^{3}+36c^{3}\\right)^{\\frac{1}{3}}\n\t\t\t\t\t\t& \\geq\\\\ \\left(\\dfrac{1}{2}\\cdot\\dfrac{1}{2}\\cdot4a^{3}\\right)^{\\frac{1}{3}}+\\left(\\dfrac{1}{3}\\cdot\\dfrac{1}{3}\\cdot9b^{3}\\right)^{\\frac{1}{3}}+\\left(\\dfrac{1}{6}\\cdot\\dfrac{1}{6}\\cdot36c^{3}\\right)^{\\frac{1}{3}}\n\t\t\t\t\\end{align*}\n\t\t\tThis proves the claim.\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "15d639b7d224628219419112a737b6819a398a38", "size": 2948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercise.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": "exercise.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": "exercise.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": 50.8275862069, "max_line_length": 518, "alphanum_fraction": 0.5983717775, "num_tokens": 1178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.616841905554538}}
{"text": "\\appendix\n\n\\section{Baseline methods}\n\\subsection{Geweke test}\nThe Geweke test \\citep{geweke_getting_2004} compares (estimates of) the expectations of hand-picked features (\\emph{test functions}) under both the forward and backward joints. \nSpecifically, let $g: \\mathcal{Y}\\times \\Theta\\to \\mathbb{R}$ denote a test function, and let  $S_f=\\{(y_i, \\theta_i)\\}_{i=1}^n$ be samples from the forward joint and $S_b=\\{(\\tilde{y}_i, \\tilde{\\theta}_i)\\}_{i=1}^n$ be ones from the backward joint.\nThen, the z-score \n% $\\sqrt{n}(\\hat{\\bar{g}} - \\hat{\\tilde{g}})/\\sqrt{\\hat{\\sigma^{2}}+\\hat{\\tilde{\\sigma}}^{2}}$\n\\begin{equation}\n    \\frac{\\bar{g}(S_f) - \\bar{g}(S_b)}{\\sqrt{ \\frac{\\hat{\\sigma}^{2}}{N} + \\frac{\\hat{\\tilde{\\sigma}}^{2}}{N}}} \n    % \\xrightarrow[]{d} \\mathcal{N}(0, 1)\n    \\label{eq:geweke}\n\\end{equation}\nasymptotically follows the standard Gaussian if $\\tilde{\\pi}(\\theta\\given y)=\\pi(\\theta\\given y)$, where $\\bar{g}(S) = \\frac{1}{n}\\sum_{(y,\\theta) \\in S}g(y, \\theta)$ and $\\hat{\\sigma}, \\hat{\\tilde{\\sigma}}$ are estimated variances. \nThe width of the window estimator $\\hat{\\tilde{\\sigma}}$ can be set to account for the serial dependence in the backward joint samples.\n\n% \\subsection{\\cite{talts_validating_2018}}\n% % \\cite{talts_validating_2018} take a similar approach under the assumption that the posterior is absolutely continuous.\n% The authors draw samples using the BC algorithm, then compute univariate rank statistics of a draw from the prior among the thinned, approximately independent posterior samples; if there is no error, the rank statistics should be discretely uniformly distributed. \n% The authors suggest examining histograms of the rank statistics to better understand errors rather than conducting a formal test.\n\n\\subsection{Rank statistic approach of \\cite{gandy_unit_2020}}\nThe rank test from \\cite{gandy_unit_2020} requires reversibility of the MCMC sampler. It draws a sample $\\theta_{l}$ from the prior, with the associated index $l$ drawn uniformly from $\\{1,\\ldots,\\tilde{L}\\}$. The sampler is then run forward and backward to generate samples $\\theta_{1}, \\ldots, \\theta_{l-1}$ and $\\theta_{l+1}, \\ldots, \\theta_{\\tilde{L}} $. Under the null, the rank statistic of $\\theta_{l}$ among the other samples should be uniformly distributed; after many repeated simulations, this is verified using a $\\chi^{2}$ test.\n\n\\section{Experiment details}\n\\subsection{Experiment 1}\n\\subsubsection{Effect of sampler mixing speed}\n\\label{appendix:ex1a}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/results_1a.png}\n    \\caption{Experiment 1 type-I/II error rates against $\\sigma_{\\epsilon}$, over 1000 trials with a sample size of 250. As $\\sigma_{\\epsilon}$ increases, autocorrelation in the Gibbs sampler decreases and mixing speed increases. We use the thinning size $t=5$ for the SC simulator, and take $L=500$ burn-in steps for both the SC and BC simulators. For the Rank test, each rank statistic is calculated using a chain of length $\\tilde{L}=5$.}\n    \\label{fig:ex1a}\n\\end{figure}\n\n\\subsubsection{Effect of varying BC simulator burn-in}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/results_1b.png}\n    \\caption{Experiment 1 type-I/II error rates over 1000 trials for different burn-in sizes $L$. The top panels use the likelihood- and prior-augmented test functions and the bottom panels use the baseline as discussed in the text. We set $\\sigma_{\\epsilon}^{2}=0.1$. Type-II error rates fall as $L$ increases.}\n    \\label{fig:ex2b}\n\\end{figure}\n\n\\subsection{Experiment 2: Reversible Jump Sampler Implementation}\n\\label{appendix:ex2}\nThe prior is defined by\n\\begin{equation}\n  \\pi(\\theta|\\lambda, \\tau, a, b ) = p(\\ell|\\lambda) p(\\mathbf{\\gamma}|\\ell) p(\\sigma^{2} | a, b) \\prod_{j} p(\\beta_{j} | \\tau, \\gamma),\n\\end{equation}\nwhere\n\\begin{equation}\n  p(\\ell|\\lambda) = \\frac{\\exp{(-\\lambda)} \\lambda^{\\ell}}{C\\ell!}, \\quad \\ell \\in \\{1,\\ldots, p\\}\n\\end{equation}\n\\begin{equation}\n  p(\\mathbf{\\gamma}|\\ell) \\propto {d\\choose \\ell}^{-1}\n\\end{equation}\n\\begin{equation}\n  p(\\beta_{j} | \\tau, \\gamma ) = \\begin{cases} (2\\tau)^{-1}\\exp(-\\frac{|\\beta_{j}|}{\\tau}) & j \\in \\mathbf{\\gamma} \\\\ \\delta(\\beta_{j}) & \\text{otherwise} \\end{cases}\n\\end{equation}\n\\begin{equation}\n    p(\\sigma^{2} | a, b) = \\frac{b^{a}}{\\Gamma(a)} (\\sigma^{2})^{-a-1} \\exp{\\left(-\\frac{b}{\\sigma^{2}}\\right)}.\n\\end{equation}\n$C$ is a normalization constant, $\\delta$ is the Dirac delta function, and $\\mathbf{\\gamma}$ is a vector of the nonzero indices of $\\beta$.\nThe likelihood is given by\n\\begin{equation}\n  p(y | \\sigma, \\beta, X ) = (2\\pi)^{-\\frac{n}{2}} \\sigma^{-n} \\exp{\\left(-\\frac{\\Vert y-X\\beta\\Vert^{2}_{2}}{2\\sigma^{2}}\\right)}.\n\\end{equation}\nThe joint probability is then\n\\begin{equation}\n    \\begin{aligned}\n         p(y, \\theta | X, \\lambda, \\tau, a, b ) \\propto &\\sigma^{-n} \\exp{\\left(-\\frac{\\Vert  y-X\\beta\\Vert^{2}_{2}}{2\\sigma^{2}}\\right)} \\times \\\\ \n         & \\frac{\\exp{(-\\lambda)} \\lambda^{\\ell}}{\\ell!} {d\\choose \\ell}^{-1} \\prod_{j\\in \\mathbf{\\gamma}} (2\\tau)^{-1}\\exp\\left(-\\frac{|\\beta_{j}|}{\\tau}\\right) \\prod_{j' \\notin \\mathbf{\\gamma}} \\delta(\\beta_{j'}) \\frac{b^{a}}{\\Gamma(a)} (\\sigma^{2})^{-a-1} \\exp{\\left(-\\frac{b}{\\sigma^{2}}\\right)}.\n    \\end{aligned}\n    \\label{eq:ex2_joint}\n\\end{equation}\n\nEach iteration of the reversible-jump MCMC posterior sampler takes two steps in random order. A Gibbs step updates $\\sigma^{2}$. By conjugacy,\n\\begin{equation}\n    \\sigma^{2} | y, X, \\beta \\sim \\mathcal{IG}\\left(a + \\frac{n}{2}, b + \\frac{\\sum_{i=1}^{n}(y_{i}-x_{i}\\beta)^{2} }{2}\\right),\n\\end{equation}\nwhere $x_{i}$ denotes row $i$ of $X$.\n\nThe other step is a reversible jump. We start by proposing $\\ell' \\in \\{\\ell-1, \\ell, \\ell+1\\}$ uniformly at random, disallowing $\\ell<1$ and $\\ell>p$. Thus, when $\\ell \\in \\{1,p\\}$, there are only two valid proposals, not three. Then, depending on the $\\ell'$ proposed, we complete the proposal $\\tilde{\\theta}$ via one of the following\n\\begin{itemize}\n    \\item Update: $\\ell' = \\ell$\n    \\begin{enumerate}\n        \\item Choose $j \\in \\{1, \\ldots, \\ell\\}$ uniformly at random\n        \\item Propose $\\mathbf{\\gamma}' = \\mathbf{\\gamma}, \\beta'_{j} = \\beta_{j} + \\mathcal{N}(0, \\epsilon_{\\text{update}}), \\beta'_{i \\neq j} = \\beta_{i}$\n        \\item $P(\\tilde{\\theta} \\rightarrow \\theta) = P(\\theta \\rightarrow \\tilde{\\theta})=\\mathcal{N}(\\beta_{j}'; \\beta_{j},\\epsilon_{\\text{update}})=\\mathcal{N}(\\beta_{j}; \\beta_{j}',\\epsilon_{\\text{update}})$\n    \\end{enumerate}\n\\end{itemize}\n\n\\begin{itemize}\n    \\item Birth: $\\ell' = \\ell+1$\n    \\begin{enumerate}\n        \\item Choose $j \\in \\{\\ell+1, \\ldots, p\\}$ uniformly at random\n        \\item Propose $\\mathbf{\\gamma}' = \\mathbf{\\gamma} \\cup j$\n        \\item Propose $\\beta'_{j} = \\mathcal{N}(0, \\epsilon_{\\text{birth}}), \\beta'_{i \\neq j} = \\beta_{i}$\n        \\item $p(\\tilde{\\theta} \\rightarrow \\theta) = \\begin{cases}\\frac{1}{2}\\frac{1}{\\ell'} & \\ell'=p \\\\ \\frac{1}{3} \\frac{1}{\\ell'} & 1<\\ell<p \\end{cases} $\n        \\item $p(\\theta \\rightarrow \\tilde{\\theta}) = \\begin{cases}\\frac{1}{2}\\frac{1}{p-\\ell} \\mathcal{N}(\\beta_{j}'; 0,\\epsilon_{\\text{birth}}) & \\ell=1 \\\\ \\frac{1}{3} \\frac{1}{p-\\ell} \\mathcal{N}(\\beta_{j}'; 0,\\epsilon_{\\text{birth}}) & 1<\\ell<p \\end{cases} $\n    \\end{enumerate}\n\\end{itemize}\n\n\\begin{itemize}\n    \\item Death: $\\ell' = \\ell-1$\n    \\begin{enumerate}\n        \\item Choose $j \\in \\{1, \\ldots, \\ell\\}$ uniformly at random\n        \\item Propose $\\mathbf{\\gamma}' = \\mathbf{\\gamma} \\setminus j$ \n        \\item Propose $\\beta'_{j} = 0, \\beta'_{i \\neq j} = \\beta_{i}$\n        \\item $p(\\tilde{\\theta} \\rightarrow \\theta) = \\begin{cases}\\frac{1}{2}\\frac{1}{p-\\ell'} \\mathcal{N}(\\beta_{j}; 0,\\epsilon_{\\text{birth}}) & k'=1 \\\\ \\frac{1}{3} \\frac{1}{p-\\ell'} \\mathcal{N}(\\beta_{j}; 0,\\epsilon_{\\text{birth}}) & 1<\\ell'<p \\end{cases} $\n        \\item $p(\\theta \\rightarrow \\tilde{\\theta}) = \\begin{cases}\\frac{1}{2}\\frac{1}{\\ell} & \\ell=p \\\\ \\frac{1}{3} \\frac{1}{\\ell} & 1<\\ell<p \\end{cases} $\n    \\end{enumerate}\n\\end{itemize}\nfor random walk sizes $\\epsilon_{\\text{update}}, \\epsilon_{\\text{birth}}$.\n\nWe accept the birth-death proposal $\\tilde{\\theta}$ with probability \n\\begin{equation}\n    A(\\tilde{\\theta}|\\theta) = \\min{\\left(\\frac{p(y, \\tilde{\\theta} |  X,  \\lambda, \\tau, a, b  )}{p(y, \\theta |  X, \\lambda, \\tau, a, b  )} \\frac{p(\\tilde{\\theta} \\rightarrow \\theta)}{p(\\theta \\rightarrow \\tilde{\\theta})}, 1\\right)}.\n\\end{equation}\n\n", "meta": {"hexsha": "c264fbcdb07aaa7d037a87f50364adaceb18dba3", "size": 8459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NeurIPS_appendix.tex", "max_stars_repo_name": "awjiang/mcmc-joint-tests", "max_stars_repo_head_hexsha": "ce94b9070f8976ad2dc0731e46a5125db48c66b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NeurIPS_appendix.tex", "max_issues_repo_name": "awjiang/mcmc-joint-tests", "max_issues_repo_head_hexsha": "ce94b9070f8976ad2dc0731e46a5125db48c66b1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NeurIPS_appendix.tex", "max_forks_repo_name": "awjiang/mcmc-joint-tests", "max_forks_repo_head_hexsha": "ce94b9070f8976ad2dc0731e46a5125db48c66b1", "max_forks_repo_licenses": ["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.9090909091, "max_line_length": 541, "alphanum_fraction": 0.6571698782, "num_tokens": 2909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6168418962209209}}
{"text": "\\subsection{Nonsmooth derivatives}\\label{subsec:nonsmooth_derivatives}\n\n\\begin{remark}\\label{rem:nonsmooth_analysis}\n  Nonsmooth analysis studies generalized differentiability for functions which are not necessarily differentible. The generalized derivatives (see \\fullref{subsec:nonsmooth_derivatives}) are not linear, which motivates the study of subdifferentials (see \\fullref{subsec:subdifferentials}).\n\n  Both optimization in Euclidean spaces and infinite-dimensional optimization studies (not necessarily linear) real-valued functionals. Hence, we are only concerned with studying real-valued topological vector spaces.\n\\end{remark}\n\n\\begin{remark}\\label{rem:nonsmooth_differentiability}\n  Unlike in \\fullref{def:differentiability}, we do not introduce terminology for differentiability because actual differentiability refers to linear approximations of \\( f: U \\to Y \\) with some consistency properties. We will say that \\enquote{\\( f \\) has a Clarke derivative at \\( x_0 \\) in the direction \\( h \\)} rather than \\enquote{\\( f \\) is Clarke differentiable at \\( x_0 \\) in the direction \\( h \\)}.\n\\end{remark}\n\n\\begin{definition}\\label{def:nonsmooth_derivatives}\n  Let \\( X \\) be a real Hausdorff \\hyperref[def:topological_vector_space]{topological vector spaces} and let \\( U \\subseteq X \\) be an open set.\n\n  We fix a point \\( x_0 \\in U \\) and a direction \\( h \\in X \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:nonsmooth_derivatives/directional}\\Fullref{def:differentiability} already introduced directional derivatives. Here we introduce a special notation for them:\n    \\begin{equation*}\n      D_h^+ f(x_0) = f_+'(x_0)(h) \\coloneqq \\lim_{t \\downarrow 0} \\frac {f(x_0 + th) - f(x_0)} t.\n    \\end{equation*}\n\n    \\thmitem{def:nonsmooth_derivatives/dini}\\cite[definition 11.18]{Clarke2013} The upper (resp. lower) \\term{Dini derivative} is defined as\n    \\begin{balign*}\n      \\overline{D}_h f(x_0) = \\overline{f'}(x_0)(h) & \\coloneqq \\limsup_{t \\downarrow 0} \\frac {f(x_0 + th) - f(x_0)} t\n      \\\\\n      \\underline{D}_h f(x_0) = \\underline{f'}(x_0)(h) & \\coloneqq \\liminf_{t \\downarrow 0} \\frac {f(x_0 + th) - f(x_0)} t\n    \\end{balign*}\n\n    Dini derivatives are useful when the difference quotients are bounded, but do not have a limit.\n\n    \\thmitem{def:nonsmooth_derivatives/clarke}\\cite[section 10.1]{Clarke2013} The \\term{generalized Clarke derivative} is defined as\n    \\begin{equation*}\n      D_h^\\circ f(x_0)\n      =\n      f^\\circ(x_0)(h)\n      \\coloneqq\n      \\limsup_{\\substack{y \\to x_0 \\\\ t \\downarrow 0}} \\frac {f(y + th) - f(y)} t.\n    \\end{equation*}\n\n    Refer to \\fullref{subsec:clarke_gradients} for their usefulness.\n  \\end{thmenum}\n\\end{definition}\n", "meta": {"hexsha": "4f3b1a7fb3e53cdda66d96557f1b9e0c61acbe53", "size": 2675, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/nonsmooth_derivatives.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/nonsmooth_derivatives.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/nonsmooth_derivatives.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.4444444444, "max_line_length": 408, "alphanum_fraction": 0.7211214953, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245911726382, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6168055024188077}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrrmsc}\n\\section*{\\hspace*{-1.6cm} tfrrmsc}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nReassigned Morlet Scalogram time-frequency distribution.\n\\end{minipage}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,rtfr,hat] = tfrrmsc(x)\n[tfr,rtfr,hat] = tfrrmsc(x,t)\n[tfr,rtfr,hat] = tfrrmsc(x,t,N)\n[tfr,rtfr,hat] = tfrrmsc(x,t,N,f0t)\n[tfr,rtfr,hat] = tfrrmsc(x,t,N,f0t,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\t{\\ty tfrrmsc} computes the Morlet scalogram and its reassigned\n        version. The reassigned Morlet scalogram has the following\n        expression, where $h(t)$ is a gaussian window :\n\\begin{eqnarray*}\n\\hspace*{-.2cm}SC_x^{(r)}(t',a';h)=\\iint_{-\\infty}^{+\\infty} {a'}^2\\ \nSC_x(t,a;h)\\ \\delta(t'-\\hat{t}(x;t,a))\\ \\delta(a'-\\hat{a}(x;t,a))\\\n\\dfrac{dt\\ da}{a^2},  \n\\end{eqnarray*}\nwhere \n\\begin{eqnarray*}\n\\hat{t}(x;t,a)=t-\\Re\\left\\{a\\ \\dfrac{T_x(t,a;\\ens{T}_h)\\ T_x^*(t,a;h)}\n{|T_x(t,a;h)|^2}\\right\\} \\\\\n\\hat{\\nu}(x;t,a)=\\dfrac{\\nu_0}{\\hat{a}(x;t,a)}=\\dfrac{\\nu_0}{a} +\n\\Im\\left\\{\\dfrac{T_x(t,a;\\ens{D}_h)\\ T_x^*(t,a;h)}{2\\pi a\\\n|T_x(t,a;h)|^2}\\right\\}\n\\end{eqnarray*}\nwith $\\ens{T}_h(t)=t\\ h(t)$ and $\\ens{D}_h(t)=\\frac{dh}{dt}(t)$. $SC_x(t,a;h)$ denotes\nthe scalogram and $T_x(t,a;h)$ the wavelet transform :\n\\[SC_x(t,a;h)=\\left|T_x(t,a;h)\\right|^2=\\frac{1}{|a|}\\ \\left|\\int_{-\\infty}^{+\\infty}\nx(s)\\ h^*\\left(\\dfrac{s-t}{a}\\right)\\ ds\\right|^2.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)})\\\\\n        {\\ty t}     & the time instant(s)           & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins      & {\\ty Nx}\\\\\n        {\\ty f0t}   & time-bandwidth product of the mother wavelet \n                                              & {\\ty 2.5}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                              & {\\ty 0}\\\\\n\\hline \\end{tabular*} \\end{minipage}\n\n\\newpage\n\n\\hspace*{1.5cm} \\begin{minipage}[t]{13.5cm}\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\ \\hline\n        {\\ty tfr, rtfr}  & time-frequency representation and its reassigned\n            version\\\\\n        {\\ty hat}   & complex matrix of the reassignment vectors\\\\\n \n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrrmsc} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(64,0.1,0.4); \n         tfrrmsc(sig,1:64,64,2.1,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and\nTime-Scale Representations by the Reassignment Method'' IEEE Transactions\non Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.\n\\end{minipage}\n\n", "meta": {"hexsha": "093fdeface8c523785ddcc3c7cfd3e16bca9b3b9", "size": 3413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrrmsc.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrrmsc.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrrmsc.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 31.3119266055, "max_line_length": 86, "alphanum_fraction": 0.608555523, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324587033253, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.616805499354941}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsfonts, graphicx, fullpage, leftidx}\n\\begin{document}\n\\section{Pole/end-effector sub system}\nConsider a massless pole with a sphere attached to one end, with sphere mass being $m_s$. The other end of the pole (point $A$) is attached to the end-effector with mass $m_e$ at point $A$. The state of the system is the velocity of the end-effector point A $(\\dot{x}_A, \\dot{y}_A, \\dot{z}_A)$, the delta position between the sphere and the end-effector in the horizontal plane $x_{AB} = x_B - x_A, y_{AB} = y_B-y_A$, together with its time derivative $\\dot{x}_{AB}, \\dot{y}_{AB}$.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{pole.pdf}\n\\end{figure}\n\nThe position of the mass is\n\\begin{align}\n\t\\begin{bmatrix}\n\t\tx_A + x_{AB}\\\\\n\t\ty_A + y_{AB}\\\\\n\t\tz_A + \\sqrt{l^2 - x_{AB}^2 - y_{AB}^2}\n\t\\end{bmatrix}\n\\end{align}\nThe velocity of the mass is\n\\begin{align}\n\t\\begin{bmatrix}\n\t\t\\dot{x}_A + \\dot{x}_{AB}\\\\\n\t\t\\dot{y}_A + \\dot{y}_{AB}\\\\\n\t\t\\dot{z}_A - \\frac{x_{AB}\\dot{x}_{AB} + y_{AB}\\dot{y}_{AB}}{\\sqrt{l^2-x_{AB}^2 - y_{AB}^2}}\n\t\\end{bmatrix}\n\\end{align}\nThe total kinetic energy of the system is\n\\begin{multline}\n\tT = 0.5 m_e (\\dot{x}_A^2 + \\dot{y}_A^2 +\\dot{z}_A^2) + 0.5 m_s(\\dot{x}_A^2 + \\dot{y}_A^2 + \\dot{z}_A^2 + \\dot{x}_{AB}^2 + \\dot{y}_{AB}^2 + \\frac{(x_{AB}^2\\dot{x}_{AB}^2 + y_{AB}^2\\dot{y}_{AB}^2 + 2x_{AB}y_{AB}\\dot{x}_{AB}\\dot{y}_{AB})}{l^2-x_{AB}^2-y_{AB}^2}\\\\\n\t+ 2\\dot{x}_A\\dot{x}_{AB} + 2\\dot{y}_A\\dot{y}_{AB} - \\frac{2\\dot{z}_A(x_{AB}\\dot{x}_{AB}+y_{AB}\\dot{y}_{AB})}{\\sqrt{l^2-x_{AB}^2-y_{AB}^2}})\n\\end{multline}\nThe total potential energy is\n\\begin{align}\n\tV = m_egz_A + m_sg(z_A + \\sqrt{l^2-x_{AB}^2-y_{AB}^2})\n\\end{align}\nUsing Lagrangian $L = T-V$ and $\\frac{d}{dt}\\frac{\\partial L}{\\partial \\dot{q}}-\\frac{\\partial L}{\\partial q} = Bu$, we have\n\\begin{align}\n\t(m_e + m_s)\\ddot{x}_A + m_s\\ddot{x}_{AB} = f_x\\\\\n\t(m_e + m_s)\\ddot{y}_A + m_s\\ddot{y}_{AB} = f_y\n\\end{align}\n\\begin{multline}\n\t(m_e + m_s)(\\ddot{z}_A+g) - m_s\\left(\\dot{x}_{AB}^2\\frac{l^2 - y_{AB}^2}{z_{AB}^3} + \\frac{x_{AB}}{z_{AB}}\\ddot{x}_{AB} + \\dot{y}_{AB}^2\\frac{l^2-x_{AB}^2}{z_{AB}^3} + \\frac{y_{AB}}{z_{AB}}\\ddot{y}_{AB} - 2 \\frac{x_{AB}y_{AB}\\dot{x}_{AB}\\dot{y}_{AB}}{z_{AB}^3}\\right) = f_z\n\\end{multline}\n\\begin{multline}\n\tm_s(\\ddot{x}_A + \\ddot{x}_{AB}) - m_sx_{AB}(g+\\ddot{z}_A)/z_{AB} + m_s(x_{AB}^2\\ddot{x}_{AB}+x_{AB}\\dot{x}_{AB}^2+x_{AB}y_{AB}\\ddot{y}_{AB}+x_{AB}\\dot{y}_{AB}^2)/z_{AB}^2\\\\\n\t+ m_s(x_{AB}^3\\dot{x}_{AB}^2 + 2x_{AB}^2y_{AB}\\dot{x}_{AB}\\dot{y}_{AB} + x_{AB}y_{AB}^2\\dot{y}_{AB}^2)/z_{AB}^4=0\n\\end{multline}\n\\begin{multline}\n\tm_s(\\ddot{y}_A + \\ddot{y}_{AB}) - m_sy_{AB}(g+\\ddot{z}_A)/z_{AB} + m_s(y_{AB}^2\\ddot{y}_{AB}+y_{AB}\\dot{y}_{AB}^2+y_{AB}x_{AB}\\ddot{x}_{AB}+y_{AB}\\dot{x}_{AB}^2)/z_{AB}^2\\\\\n\t+ m_s(y_{AB}^3\\dot{y}_{AB}^2 + 2y_{AB}^2x_{AB}\\dot{y}_{AB}\\dot{x}_{AB} + y_{AB}x_{AB}^2\\dot{x}_{AB}^2)/z_{AB}^4=0\n\\end{multline}\n\nIn the matrix form, we have\n\\begin{align}\n\tM\t\\begin{bmatrix}\\ddot{x}_A\\\\\\ddot{y}_A\\\\\\ddot{z}_A\\\\\\ddot{x}_{AB}\\\\\\ddot{y}_{AB}\\end{bmatrix} + C = \\begin{bmatrix}f_x\\\\f_y\\\\f_z\\\\0\\\\0\\end{bmatrix}\\label{eq:pole_ee_manipulator_eq}\n\\end{align}\nwhere\n\\begin{align}\n\tM = \n\t\\begin{bmatrix}\n\t\tm_e + m_s & 0 & 0 & m_s & 0\\\\\n\t\t0 & m_e + m_s & 0 & 0 & m_s\\\\\n\t\t0 & 0 & m_e + m_s & -m_s\\frac{x_{AB}}{z_{AB}} & -m_s\\frac{y_{AB}}{z_{AB}}\\\\\n\t\tm_s& 0 & -m_s\\frac{x_{AB}}{z_{AB}} & m_s + m_s\\frac{x_{AB}^2}{z_{AB}^2} & m_s\\frac{x_{AB}y_{AB}}{z_{AB}^2}\\\\\n\t\t0 & m_s & -m_s\\frac{y_{AB}}{z_{AB}} &m_s\\frac{x_{AB}y_{AB}}{z_{AB}^2} & m_s + m_s\\frac{y_{AB}^2}{z_{AB}^2}\n\t\\end{bmatrix}\\\\\n\tC = \\begin{bmatrix}\n\t\t0\\\\\n\t\t0\\\\\n\t\t(m_e + m_s)g - m_s\\left(\\dot{x}_{AB}^2\\frac{l^2-y_{AB}^2}{z_{AB}^3} + \\dot{y}_{AB}^2\\frac{l^2-x_{AB}^2}{z_{AB}^3} - 2\\frac{x_{AB}y_{AB}\\dot{x}_{AB}\\dot{y}_{AB}}{z_{AB}^3}\\right)\\\\\n\t\t-m_sg\\frac{x_{AB}}{z_{AB}}+m_sx_{AB}\\left(\\frac{\\dot{x}_{AB}^2 + \\dot{y}_{AB}^2}{z_{AB}^2}+\\frac{(x_{AB}\\dot{x}_{AB} + y_{AB}\\dot{y}_{AB})^2}{z_{AB}^4}\\right)\\\\\n\t\t-m_sg\\frac{y_{AB}}{z_{AB}}+m_sy_{AB}\\left(\\frac{\\dot{x}_{AB}^2 + \\dot{y}_{AB}^2}{z_{AB}^2}+\\frac{(x_{AB}\\dot{x}_{AB} + y_{AB}\\dot{y}_{AB})^2}{z_{AB}^4}\\right)\n\t\\end{bmatrix}\n\\end{align}\n\n\\section{Whole system}\nAssuming that we construct a controller, that given the current state of the pole/end-effector system, this controller computes the force $f_x, f_y, f_z$ applied from the robot to the end-effector, now we want to compute the robot joint torque $\\tau$ to apply that force.\n\nWe first apply the force $f_x, f_y, f_z$ computed from the controller as input to the pole/end-effector system, from the dynamics equation \\eqref{eq:pole_ee_manipulator_eq} we can compute the acceleration of the end effector $\\ddot{x}_A, \\ddot{y}_A, \\ddot{z}_A$, together with the acceleration of the pole $\\ddot{x}_B, \\ddot{y}_B, \\ddot{z}_B$ (where we use both $\\ddot{x}_A, \\ddot{y}_A, \\ddot{z}_A$ and $\\ddot{x}_{AB}, \\ddot{y}_{AB}, \\ddot{z}_{AB}$). We know that for the pole to achieve this acceleration, the end-effector has to apply a force\n\\begin{align}\n\tf_B = m_s\\begin{bmatrix}\\ddot{x}_B \\\\ \\ddot{y}_B \\\\ \\ddot{z}_B + g\\end{bmatrix}\n\\end{align}\nonto the pole, applied at where the pole makes contact with the end effector. Based on Newton's third law, there is an equal and opposite force $-f_B$ applied on the end-effector at the contact point $P$ between the end-effector and the pole. Hence our goal is to compute the joint torque of the robot arm, such that the end-effector can achieve the desired acceleration $\\ddot{x}_A, \\ddot{y}_A, \\ddot{z}_A$ under the external force $-f_B$.\n\nWe can write the manipulator equation for the IIWA arm (together with the end-effector welded to the wrist joint)\n\\begin{align}\n\tM_{iiwa}\\ddot{q}_{iiwa} + C = g(q_{iiwa}) + \\tau - \\left(\\leftidx{^W}{J}^P\\right)^Tf_B\\label{eq:iiwa_eom}\n\\end{align}\nwhere $\\leftidx{^W}{J}^P$ is the Jacobian of the contact point $P$ written in the world frame.\nAnd we also have the constraints on the end-effector acceleration\n\\begin{align}\n\t\\leftidx{^W}{J}^E\\ddot{q}_{iiwa} + \\leftidx{^W}{\\dot{J}}^E\\dot{q}_{iiwa} = \\leftidx{^W}{a}^E_{des}\\label{eq:iiwa_ee_acceleration}\n\\end{align}\nwhere $\\leftidx{^W}{J}^E$ is the Jacobian of the end-effector written in the world frame. $\\leftidx{^W}{a}^E_{des}$ is the desired acceleration of the IIWA end-effector frame $E$ in the world frame $W$. This acceleration includes both the linear acceleraton $\\ddot{x}_A, \\ddot{y}_A, \\ddot{z}_A$, together with the desired angular acceleration. The desired acceleration can be set in two ways\n\\begin{itemize}\n\t\\item If our goal is to keep the end-effector to be horizontal, then we can compute the desired angular acceleration using a PD law depending on the orientation error.\n\t\\item We can also set the desired end-effector angular acceleration to be zero. Note that this won't handle any orientation drift. Namely if currently the end-effector angular velocity is non-zero, then the orientation will continue to drift.\n\\end{itemize}\n\nCombining the equations \\eqref{eq:iiwa_eom} and \\eqref{eq:iiwa_ee_acceleration} we have unknown variable $\\tau\\in\\mathbb{R}^7$. The problem is under-constrained, we can also impose the cost as $\\min \\tau^T\\tau$ to get a unique (and optimal) $\\tau$. If we ignore the joint torque limit, then this ends up being an equality-constrained QP which can be solved very efficiently in the closed form.\n\n\\end{document}\n", "meta": {"hexsha": "1234bc741d1d9beb0b60edca6828e72cfb8177ef", "size": 7326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/pole_balance.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/pole_balance.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/pole_balance.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": 70.4423076923, "max_line_length": 544, "alphanum_fraction": 0.6661206661, "num_tokens": 2975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.6859494614282923, "lm_q1q2_score": 0.6167518226427687}}
{"text": "% To be compiled by XeLaTeX, preferably under TeX Live.\n% LaTeX source for ``Yanqi Lake Lectures on Algebra'' Part III.\n% Copyright 2019  李文威 (Wen-Wei Li).\n% Permission is granted to copy, distribute and/or modify this\n% document under the terms of the Creative Commons\n% Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)\n% https://creativecommons.org/licenses/by-nc/4.0/\n\n% To be included\n\\chapter{Dimension of finitely generated algebras}\n\nThe main reference is \\cite[\\S 13]{Mat80}.\n\n\\section{Dimensions in fibers}\nConsider a homomorphism $\\varphi: A \\to B$, which induces $\\varphi^\\sharp: \\Spec(B) \\to \\Spec(A)$ on prime spectra. Given $\\mathfrak{p} \\in \\Spec(A)$, we are interested in the fiber $(\\varphi^\\sharp)^{-1}(\\mathfrak{p})$; the prime ideals $\\mathfrak{q}$ therein are described by $\\varphi^{-1}(\\mathfrak{q}) = \\mathfrak{p}$, or equivalently:\n\\[ \\varphi^{-1}(\\mathfrak{q}) \\cap (A \\smallsetminus \\mathfrak{p}) = \\emptyset, \\quad \\mathfrak{q} \\supset \\varphi(\\mathfrak{p}). \\]\nAdopt the convention that a zero ring has $\\Spec = \\emptyset$. The first condition says that $\\mathfrak{q}$ comes from $\\Spec(B_{\\mathfrak{p}})$, where $B_{\\mathfrak{p}}$ is the localization with respect to $\\varphi(A \\smallsetminus \\mathfrak{p})$ (possibly zero). The second condition then says that $\\mathfrak{q}B_{\\mathfrak{p}}$ lies over the image of $\\mathfrak{p}A_{\\mathfrak{p}}$. Set\n\\[ \\kappa(\\mathfrak{p}) := A_{\\mathfrak{p}}/\\mathfrak{p}A_{\\mathfrak{p}}. \\]\nThe fiber $(\\varphi^\\sharp)^{-1}(\\mathfrak{p})$ is then identified with the spectrum of\n\\[ B \\dotimes{A} \\kappa(\\mathfrak{p}) = \\left( B \\dotimes{A} A_{\\mathfrak{p}} \\right) \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p}) = B_{\\mathfrak{p}} \\dotimes{A_{\\mathfrak{p}}} (A_{\\mathfrak{p}}/\\mathfrak{p}A_{\\mathfrak{p}} ), \\]\nwhich is empty if and only if $B \\dotimes{A} \\kappa(\\mathfrak{p})$ is zero. This also equips $(\\varphi^\\sharp)^{-1}(\\mathfrak{p})$ with an extra structure: it is the spectrum of an explicit quotient ring of $B_{\\mathfrak{p}}$.\n\nObserve that for all $\\mathfrak{q} \\in (\\varphi^\\sharp)^{-1}(\\mathfrak{p})$, the localization of $B_{\\mathfrak{p}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p})$ at the image of $\\mathfrak{q}$ is canonically isomorphic to $B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p})$.\n\n\\begin{proposition}\\label{prop:fiber-ineq}\n\tAssume $A, B$ to be Noetherian. Let $\\mathfrak{q} \\in \\Spec(B)$ and $\\mathfrak{p} := \\varphi^\\sharp(\\mathfrak{q})$. We have\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\dim(B_{\\mathfrak{q}}) \\leq \\dim(A_{\\mathfrak{p}}) + \\dim B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p})$ (note that the existence of $\\mathfrak{q}$ ensures that $B_{\\mathfrak{p}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p}) \\neq \\{0\\}$, hence $B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p}) \\neq \\{0\\}$);\n\t\t\\item equality holds if going-down holds for $\\varphi$;\n\t\t\\item if going-down holds and $\\varphi^\\sharp$ is surjective, then $\\dim(B) \\geq \\dim(A)$, and for all ideal $\\mathfrak{a} \\subsetneq A$ we have $\\varphi(\\mathfrak{a}) B \\neq B$ and $\\mathrm{ht}(\\mathfrak{a}) = \\mathrm{ht}(\\varphi(\\mathfrak{a})B)$.\n\t\\end{enumerate}\n\\end{proposition}\n\nIt is crucial to notice that $\\dim B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p}) = \\text{ht}(\\mathfrak{q}B_{\\mathfrak{q}}/\\varphi(\\mathfrak{p}) B_{\\mathfrak{q}}) = \\text{ht}(\\mathfrak{q}/\\varphi(\\mathfrak{p})B)$.\n\nThis bounds the source dimension of a morphism by the target dimension plus the fiber dimension, localized both at $\\mathfrak{p}$ and $\\mathfrak{q} \\in (\\varphi^\\sharp)^{-1}(\\mathfrak{p})$. In order to have an equality, a certain submersion-like condition on $\\varphi^\\sharp$ is evidently required; this explains the going-down condition. Cf. \\cite[(6.H)]{Mat80}.\n\n\\begin{proof}\n\tWe have an induced local homomorphism $A_{\\mathfrak{p}} \\to B_{\\mathfrak{q}}$ since $\\mathfrak{q} \\mapsto \\mathfrak{p}$. Since (i) and (ii) depend only on this induced homomorphism, we may assume from the outset that $A$, $B$ are local with maximal ideals $\\mathfrak{p}, \\mathfrak{q}$, and $\\varphi$ is a local homomorphism. Let $d := \\dim A$ and take a parameter ideal $I = (t_1, \\ldots, t_d)$ of $A$, so that $\\mathfrak{p}^k \\subset I \\subset \\mathfrak{p}$ for some $k$. It follows that $\\sqrt{\\varphi(\\mathfrak{p}) B} = \\sqrt{\\varphi(I)B}$, therefore $\\dim(B \\dotimes{A} \\kappa(\\mathfrak{p})) = \\dim(B/\\varphi(\\mathfrak{p})B) = \\dim (B/\\varphi(I)B)$; denote this number as $e$. Take a $s_1, \\ldots, s_e \\in \\mathfrak{q}$ whose images generate a parameter ideal for $B/\\varphi(I)B$, and put $J := (\\varphi(t_1), \\ldots, \\varphi(t_d), s_1, \\ldots, s_e)$. Then $B/J$ is Artinian, therefore $\\dim B \\leq d+e$ establishes (i).\n\t\n\tAs for (ii), we conserve the same hypotheses and take a prime chain $\\mathfrak{q} = \\mathfrak{q}_0 \\supsetneq \\cdots \\supsetneq \\mathfrak{q}_e$ with $\\mathfrak{q}_e \\supset \\varphi(\\mathfrak{p})B$ in $B$, as well as a prime chain $\\mathfrak{p} = \\mathfrak{p}_0 \\supsetneq \\cdots \\supsetneq \\mathfrak{p}_d$ in $A$. Note that $\\varphi^{-1}(\\mathfrak{q}_e) = \\mathfrak{p}$ since $e = \\dim B/\\varphi(\\mathfrak{p})B$. By applying going-down repeatedly to the chain $\\mathfrak{p}_i$, we obtain a prime chain in $B$\n\t\\[ \\mathfrak{q}_e \\supsetneq \\cdots \\supsetneq \\mathfrak{q}_{e+d}, \\quad \\varphi^{-1}(\\mathfrak{q}_{e+i}) = \\mathfrak{p}_i. \\]\n\tConcatenation with $\\mathfrak{q}_0 \\supsetneq \\cdots$ gives $\\dim(B) = d + e$. This shows (ii).\n\t\n\tThe first assertion of (iii) results from (ii). To show the remaining one, let us show $\\varphi(\\mathfrak{a})B \\neq B$: if $\\varphi^\\sharp(\\mathfrak{q}) = \\mathfrak{p} \\supset \\mathfrak{a}$, then $\\mathfrak{q} \\supset \\varphi(\\mathfrak{a}) B$. Next, take a minimal over-prime $\\mathfrak{q} \\supset \\varphi(\\mathfrak{a})B$ with $\\text{ht}(\\mathfrak{q}) = \\text{ht}(\\varphi(\\mathfrak{a})B)$. With $\\mathfrak{p} := \\varphi^{-1}(\\mathfrak{q}) \\supset \\mathfrak{a}$, we must have $\\dim B_{\\mathfrak{q}} \\otimes \\kappa(\\mathfrak{p}) = \\text{ht}(\\mathfrak{q}/\\varphi(\\mathfrak{p})B) = 0$ by the minimality of $\\mathfrak{q}$. An application of (ii) yields\n\t\\begin{gather*}\n\t\t\\text{ht}(\\varphi(\\mathfrak{a})B) = \\text{ht}(\\mathfrak{q}) = \\text{ht}(\\mathfrak{p}) \\geq \\text{ht}(\\mathfrak{a}).\n\t\\end{gather*}\n\tTo obtain $\\leq$, choose $\\mathfrak{p} \\supset \\mathfrak{a}$ with $\\text{ht}(\\mathfrak{p}) = \\text{ht}(\\mathfrak{a})$ and take $\\mathfrak{q} \\in \\Spec(B)$ with $\\mathfrak{p} = \\varphi^{-1}(\\mathfrak{q})$; this implies $\\mathfrak{q} \\supset \\varphi(\\mathfrak{p})B \\supset \\varphi(\\mathfrak{a})B$. Upon shrinking $\\mathfrak{q}$, we may even assume $\\mathfrak{q}$ is minimal over $\\varphi(\\mathfrak{p})B$, i.e. $\\text{ht}(\\mathfrak{q}/ \\varphi(\\mathfrak{p})B) = 0$. Using (ii), this entails $\\text{ht}(\\mathfrak{a}) = \\text{ht}(\\mathfrak{p}) = \\text{ht}(\\mathfrak{q}) \\geq \\text{ht}(\\varphi(\\mathfrak{a})B)$.\n\\end{proof}\n\n\\vspace{1em}\n\\begin{center}\n\t\\begin{tikzpicture}\n\t\t\\draw (-2,1) -- (2,1);\n\t\t\\draw[line width=6pt, white] (0, 2) -- (0, -1.5);\n\t\t\\draw[line width=2pt, black] (0,2) -- (0, 0.7);\n\t\t\\draw[line width=1.5pt, dashed] (0, 0.65) -- (0, 0);\n\t\t\\draw[line width=2pt, black] (0,0) -- (0, -1.2);\n\t\t\\draw[line width=5pt, white] (-3,0) -- (3,0);\n\t\t\\draw (-3,0) -- (3,0);\n\t\t\\draw (-3,0) -- (-2,1);\n\t\t\\draw (3,0) -- (2,1);\n\t\t\\fill[opacity=0.2, shade, color=black!50!white] (-2,1) -- (2,1) -- (3,0) -- (-3,0) -- (-2,1);\n\t\t\\node[anchor=west, text width=4cm, align=left] at (4.5, 0.7) {\\small The minimal primes in a ring $B$ may have different heights when the scheme $\\Spec(B)$ is not equi-dimensional.};\n\t\\end{tikzpicture}\n\\end{center}\n\\vspace{1em}\n\nGoing-down holds for flat $\\varphi$ by Theorem \\ref{prop:going-down-flat}, therefore the dimension equality\n\\[ \\dim(B_{\\mathfrak{q}}) = \\dim(A_{\\mathfrak{p}}) + \\dim B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa(\\mathfrak{p}) \\]\nholds for flat ring homomorphisms.\n\n\\begin{remark}\n\tIn general, if $B$ is a finitely generated algebra over Noetherian $A$ such that $\\Spec(B) \\to \\Spec(A)$ is a closed map, the fiber dimension $\\mathfrak{p} \\mapsto \\dim B/\\mathfrak{p}B$ is an \\emph{upper semi-continuous function} on the target space $\\Spec(A)$. More concretely, the fiber dimension is non-decreasing under specialization of $\\mathfrak{p}$. Cf. \\cite[\\S 14.3]{Eis95} or \\cite[(13.E)]{Mat80}. Try to understand this phenomenon intuitively.\n\\end{remark}\n\n\\begin{proposition}\\label{prop:dim-integral}\n\tSuppose $B$ is integral over a subring $A$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item We have $\\dim A = \\dim B$.\n\t\t\\item If we assume moreover that $A, B$ are both Noetherian, then $\\mathrm{ht}(\\mathfrak{q}) \\leq \\mathrm{ht}(\\mathfrak{q} \\cap A)$ for every $\\mathfrak{q} \\in \\Spec(B)$.\n\t\t\\item Furthermore, if going-down also holds for $A \\hookrightarrow B$, we have $\\mathrm{ht}(J) = \\mathrm{ht}(J \\cap A)$ for every ideal $J \\subsetneq B$.\n\t\\end{enumerate}\n\\end{proposition}\n\\begin{proof}\n\tGoing-up holds and $\\Spec(B) \\twoheadrightarrow \\Spec(A)$ in the situation of (i) by Theorem \\ref{prop:Cohen-Seidenberg}, hence $\\dim B \\geq \\dim A$ by lifting prime chains. To prove $\\leq$, observe that $\\mathfrak{q} \\subsetneq \\mathfrak{q}'$ implies $\\mathfrak{q} \\cap A \\subsetneq \\mathfrak{q}' \\cap A$ since there are no inclusion relations in the fibers of $\\Spec(B) \\to \\Spec(A)$.\n\n\tAs for (ii), note that $\\text{ht}(\\mathfrak{q}) \\leq \\text{ht}(\\mathfrak{p}) + \\text{ht}(\\mathfrak{q}/\\mathfrak{p}B)$ where $\\mathfrak{p} := \\mathfrak{q} \\cap A$; as the are no inclusion relations in fibers, the last term must be $0$.\n\t\n\tNow assume going-down and consider (iii). Take $\\mathfrak{q} \\in \\Spec(B)$ with $\\text{ht}(\\mathfrak{q}) = \\text{ht}(J)$. Put $\\mathfrak{p} := \\mathfrak{q} \\cap A \\supset J　\\cap A$. Again, since there are no inclusions in the fiber over $\\mathfrak{p}$ of $\\Spec(B) \\twoheadrightarrow \\Spec(A)$, we have $\\dim(B_{\\mathfrak{q}}/ \\mathfrak{p}B_{\\mathfrak{q}}) = 0$. Proposition \\ref{prop:fiber-ineq} (ii) implies $\\text{ht}(\\mathfrak{q})=\\text{ht}(\\mathfrak{p})$, therefore $\\text{ht}(J) \\geq \\text{ht}(J \\cap A)$.\n\t\n\tOn the other hand, for any $\\mathfrak{p} \\supset J \\cap A$ with $\\text{ht}(\\mathfrak{p}) = \\text{ht}(J \\cap A)$, since $A/J \\cap A \\hookrightarrow B/J$ is integral, there exists $\\mathfrak{q} \\supset J$ with $\\mathfrak{q} \\cap A = \\mathfrak{p}$. Together with Proposition \\ref{prop:fiber-ineq} (i) and $\\mathrm{ht}(\\mathfrak{q}/\\mathfrak{p}B) = 0$, this implies $\\text{ht}(J) \\leq \\text{ht}(\\mathfrak{q}) \\leq \\text{ht}(\\mathfrak{p}) = \\text{ht}(J \\cap A)$ by (ii).\n\\end{proof}\n\n\\section{Calculation for polynomial algebras}\nLet us apply the results from the previous section to elucidate the Krull dimension of polynomial algebras.\n\n\\begin{theorem}\\label{prop:dim-polynomial-alg}\n\tLet $A$ be a Noetherian ring, we have $\\dim A[X_1, \\ldots, X_n] = \\dim A + n$ for any $n \\geq 0$. In particular, $\\dim A[X_1, \\ldots, X_n] = n$ if $A$ is Artinian (eg.\\ a field).\n\\end{theorem}\n\\begin{proof}\n\tEvidently we may assume $n=1$. We shall apply Proposition \\ref{prop:fiber-ineq} to $A \\hookrightarrow B = A[X]$. Take any $\\mathfrak{p} \\in \\Spec(A)$ and let $\\mathfrak{q}$ be a maximal element in $\\{\\mathfrak{q}' \\in \\Spec(B): \\mathfrak{q} \\cap A = \\mathfrak{p} \\}$. Put $\\kappa := \\kappa(\\mathfrak{p})$. It suffices to show that $B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa$ has dimension one, since $B$ is free hence flat over $A$, and Proposition \\ref{prop:fiber-ineq} will imply\n\t\\[ \\dim B_{\\mathfrak{q}} = \\dim A_{\\mathfrak{p}} + 1 \\]\n\tand taking supremum over $\\mathfrak{p} \\in \\Spec(A)$ gives the result.\n\t\n\tIndeed, put $B_{\\mathfrak{p}} := B[(A \\smallsetminus \\mathfrak{p})^{-1}] = A_{\\mathfrak{p}}[X]$ and $\\mathfrak{q}' := \\mathfrak{q}[(A \\smallsetminus \\mathfrak{p})^{-1}] \\in \\Spec(B_{\\mathfrak{p}})$. As $\\mathfrak{q}' \\supset \\mathfrak{p}A_{\\mathfrak{p}}$, we have $\\overline{\\mathfrak{q}'} := \\mathfrak{q}' \\supset \\mathfrak{p}A_{\\mathfrak{p}} \\in \\Spec(\\kappa[X])$, and $\\overline{\\mathfrak{q}'}$ is maximal in the fiber over $\\{0\\}$ of $\\Spec(\\kappa[X]) \\to \\Spec(\\kappa)$, i.e.\\ in $\\MaxSpec(\\kappa[X])$. Localization in stages yields\n\t\\[ B_{\\mathfrak{q}} \\dotimes{A_{\\mathfrak{p}}} \\kappa \\simeq \\frac{B_{\\mathfrak{q}}}{\\mathfrak{p} B_{\\mathfrak{q}}} \\simeq \\left( \\frac{B_{\\mathfrak{p}}}{ \\mathfrak{p} A_{\\mathfrak{p}} B_{\\mathfrak{p}}} \\right)_{\\mathfrak{q}' } \\simeq \\kappa[X]_{\\overline{\\mathfrak{q}'}}. \\]\n\tAs $\\kappa[X]$ is a principal ideal domain which is not a field, every maximal ideal thereof has height one. Hence $\\dim \\kappa[X]_{\\overline{\\mathfrak{q'}}} = \\mathrm{ht}(\\mathfrak{q}') = 1$.\n\\end{proof}\n\n\\begin{corollary}\\label{prop:poly-alg-ht}\n\tLet $\\Bbbk$ be a field, then for every $0 \\leq i \\leq n$ we have $\\mathrm{ht}(X_1, \\ldots, X_i) = i$ in $\\Bbbk[X_1, \\ldots, X_n]$.\n\\end{corollary}\n\\begin{proof}\n\tThe prime chain $\\{0\\} \\subset (X_1) \\subsetneq \\cdots \\subsetneq (X_1, \\ldots, X_n)$ has length $n = \\dim \\Bbbk[X_1, \\ldots, X_n]$. Thus for each $0 \\leq i \\leq n$, the chain $\\{0\\} \\subset (X_1) \\subsetneq \\cdots \\subsetneq (X_1, \\ldots, X_i)$ has maximal length among all prime chains starting with $(X_1, \\ldots, X_i)$.\n\\end{proof}\n\nCombined with Theorem \\ref{prop:dim-polynomial-alg}, we see that for $\\Bbbk$ a field, $R := \\Bbbk[X_1, \\ldots, X_n]$ and $\\mathfrak{p} := (X_1, \\ldots, X_i)$, the equality\n\\[ \\text{ht}(\\mathfrak{p}) + \\dim R/\\mathfrak{p} = \\dim R. \\]\nholds. This will be generalized to finitely generated domains over $\\Bbbk$.\n\nWe record another simple consequence for later use.\n\\begin{corollary}\\label{prop:fg-dimension-bound}\n\tLet $\\Bbbk$ be a field. Any $\\Bbbk$-algebra $A$ with $n$ generators has finite dimension $\\leq n$.\n\\end{corollary}\n\\begin{proof}\n\tWriting $A = \\Bbbk[X_1, \\ldots, X_n]/I$ for some ideal $I$, we have $\\dim A \\leq \\Bbbk[X_1, \\ldots, X_n]$ since every prime chain in $A$ lifts to $\\Bbbk[X_1, \\ldots, X_n]$. Now apply Theorem \\ref{prop:dim-polynomial-alg}.\n\\end{proof}\n\n\\section{Noether normalization and its consequences}\nFix a field $\\Bbbk$. A few preparatory results are in order.\n\n\\begin{lemma}\\label{prop:normalization-Nagata}\n\tSuppose $\\Bbbk$ is a field and $t \\in \\Bbbk[X_1, \\ldots X_e] \\smallsetminus \\Bbbk$. There exist $t_1, \\ldots, t_{e-1} \\in \\Bbbk[X_1, \\ldots, X_e]$ such that $\\Bbbk[X_1, \\ldots, X_e]$ is finitely generated as a module over the $\\Bbbk$-subalgebra $S := \\Bbbk[t_1, \\ldots, t_{e-1}, t]$.\n\\end{lemma}\n\\begin{proof}\n\tWe seek $t_i$ of the form $X_i - X_e^{k^i}$ where $k$ is a large integer. Then $t$ can be uniquely expressed as a polynomial of $t_1, \\ldots, t_{e-1}, X_e$. We claim that upon modifying $t$ by $\\Bbbk^\\times$, which is clearly harmless, one can choose $k$ such that $t$ is monic as an element of $\\Bbbk[t_1, \\ldots, t_{e-1}][X_e]$, say of some degree $\\delta$. If this is the case,\n\t\\[ t = X_e^\\delta + \\sum_{0 \\leq j < \\delta} \\left(\\text{polynomial in } t_1, \\ldots, t_{e-1}\\right) X_e^j \\]\n\tsays that $X_e$ is integral over $S$, and then $\\Bbbk[X_1, \\ldots, X_e]$ is generated as an $S$-module by $1, X_e, \\ldots, X_e^{\\delta-1}$.\n\t\n\tTo choose $k$, one stares at the expansion\n\t\\[ X_1^{a_1} \\cdots X_e^{a_e} = \\left(t_1 + X_e^{k^1}\\right)^{a_1} \\cdots \\left(t_{e-1} + X_e^{k^{e-1}}\\right)^{a_{e-1}} \\cdot X_e^{a_e} = X_e^{a_e + a_1 k^1 + \\cdots + a_{e-1} k^{e-1}} + \\text{mixed terms}. \\]\n\tIf $k > \\max\\{a_1, \\ldots, a_e \\}$, the exponent of $X_e$ is simply the base $k$ expression with digits $a_e, a_1, \\ldots, a_{e-1}$. Now write $t$ as a linear combination of monomials $X_1^{a_1} \\cdots X_e^{a_e}$ and expand them in terms of $t_1, \\ldots, t_{e-1}, X_e$. From the observation above, different $(a_1, \\ldots, a_e)$ contributes a different exponent of $X_e$ whenever $k \\gg 0$. Adjusting $t$ by $\\Bbbk^\\times$, we get the asserted property.\n\\end{proof}\n\n\\begin{lemma}\\label{prop:normalization-aux}\n\tLet $\\mathfrak{a}$ be a nonzero ideal of a domain $R$, then $\\dim(R/\\mathfrak{a}) + 1 \\leq \\dim R$.\n\\end{lemma}\n\\begin{proof}\n\tAny prime chain $\\mathfrak{p}_0 \\supsetneq \\cdots \\supsetneq \\mathfrak{p}_n$ in $R$ with $\\mathfrak{p}_n \\supset \\mathfrak{a}$ can be extended to a prime chain length $n+1$, namely by adjoining $\\mathfrak{p}_{n+1} := \\{0\\}$.\n\\end{proof}\n\n\\begin{theorem}[E.\\ Noether, M.\\ Nagata]\\label{prop:Noether-normalization}\\index{Noether normalization}\n\tLet $B$ be a finitely generated $\\Bbbk$-algebra of dimension $n$. Consider a chain of proper ideals $I_1 \\subsetneq \\cdots \\subsetneq I_m$, with $\\dim(B/I_j) = d_j$ and $d_1 > \\cdots > d_m \\geq 0$. Then there exist a $\\Bbbk$-subalgebra $A \\subset B$ together with an isomorphism $A \\simeq \\Bbbk[X_1, \\ldots, X_n]$, satisfying\n\t\\begin{compactitem}\n\t\t\\item $B$ is a finitely generated $A$-module, in particular $B$ is integral over $A$;\n\t\t\\item $I_j \\cap A \\simeq (X_{d_j+1}, \\ldots, X_n)$ under the isomorphism above, for each $1 \\leq j \\leq m$.\n\t\\end{compactitem}\n\\end{theorem}\n\nNote that the assumption $I_j \\subsetneq I_{j+1}$ is merely for convenience. Allowing $I_j = I_{j+1}$ and $d_j = d_{j+1}$ for some $j$ is surely possible..\n\n\\begin{proof}\n\tWrite $B = \\Bbbk[Y_1, \\ldots, Y_r]/J$, where $r \\geq n$ (Corollary \\ref{prop:fg-dimension-bound}), and denote the preimage of $I_j$ in $\\Bbbk[Y_1, \\ldots, Y_r]$ by $\\tilde{I}_j$. The first step is to reduce to the case $J=\\{0\\}$. To see this, we adjoin $\\tilde{I}_0 = \\{0\\}$ (with $d_0 = n$) into the ideal chain; it may happen that $\\tilde{I}_0 = \\tilde{I}_1$, but that's harmless. Suppose we can find $\\tilde{A} \\subset \\Bbbk[Y_1, \\ldots, Y_r]$, $\\tilde{A} \\simeq \\Bbbk[X_1, \\ldots, X_r]$ with the required properties relative to $\\tilde{I}_\\bullet$. Taking quotient by $J$, we obtain the corresponding properties for $I_\\bullet$. Indeed, the passage from $\\tilde{A}$ to $A := \\tilde{A}/(\\tilde{A} \\cap J)$ truncates the variables $X_{n + 1}, \\ldots, X_r$, whereas\n\t\\[ I_j \\cap A = \\frac{\\tilde{I}_j \\cap (\\tilde{A} + J)}{J} = \\frac{(\\tilde{I}_j \\cap \\tilde{A}) + J}{J}  \\simeq \\frac{\\tilde{I}_j \\cap \\tilde{A}}{J \\cap \\tilde{A}}; \\]\n\ttry to convince yourself of the middle equality.\n\n\tSecondly, having reduced to the case $B = \\Bbbk[Y_1, \\ldots, Y_r]$ (thus $r = n$), it suffices to pick $x_1, \\ldots, x_n \\in B$ such that\n\t\\begin{enumerate}[(a)]\n\t\t\\item $B$ is finitely generated as a module over $A := \\Bbbk[x_1, \\ldots, x_n]$, and\n\t\t\\item $I_j \\cap A \\supset (x_{d_j+1}, \\ldots, x_n)$ for all $j$.\n\t\\end{enumerate}\n\tIndeed, (a) implies $\\mathrm{Frac}(A)$ and $\\mathrm{Frac}(B)$ have the same transcendence degree $n$ over $\\Bbbk$, therefore $x_1, \\ldots, x_n$ must be algebraically independent over $\\Bbbk$. On the other hand, $\\dim(B/I_j) = \\dim(A/I_j \\cap A)$ by (a) and Proposition \\ref{prop:dim-integral}; but if $I_j \\cap A \\supsetneq (x_{d_j+1}, \\ldots, x_n)$ then $A/I_j \\cap A$ is a proper quotient of the domain $\\Bbbk[x_1, \\ldots, x_{d_j}]$, therefore would have dimension $< d_j$ by Lemma \\ref{prop:normalization-aux}.\n\t\n\tWe shall construct $x_1, \\ldots, x_n$ step by step. Suppose $0 \\leq e \\leq n$ and that we have produced elements $x'_1, \\ldots, x'_e$ and $x_{e+1}, \\ldots, x_n$ in $B$ satisfying\n\t\\begin{enumerate}[(i)]\n\t\t\\item $B$ is finitely generated as a module over $\\Bbbk[x'_1, \\ldots, x'_e, x_{e+1}, \\ldots, x_n] =: S_e$;\n\t\t\\item $I_j \\cap S_e \\supset (x_{e+1}, \\ldots, x_n)$ when $d_j \\leq e$;\n\t\t\\item $I_j \\cap S_e \\supset (x_{d_j + 1}, \\ldots, x_n)$ when $d_j \\geq e$ (with $j = 1, \\ldots, m$).\n\t\\end{enumerate}\n\n\tFor the initial case $e=n$, simply take $x'_i := Y_i$. Our aim is $e=0$. Let us explain the induction step from $e \\geq 1$ to $e-1$. The prior argument based on transcendence degrees implies the algebraic independence among\n\t\\[ x'_1, \\ldots, x'_e, x_{e+1}, \\ldots, x_n. \\]\n\tIf $e \\leq d_j$ for all $j$, we are done. Otherwise set $j := \\min\\{j': e > d_{j'} \\}$, we contend that\n\t\\[ I_j \\cap \\Bbbk[x'_1, \\ldots, x'_e] \\neq \\{0\\}. \\]\n\tIf not, we would have $I_j \\cap S_e = (x_{e+1}, \\ldots, x_n)$ since $I_j \\cap S_e \\supset (x_{e+1}, \\ldots, x_n)$ by (ii). We have $\\dim(S_e/I_j \\cap S_e) = \\dim(B/I_j) = d_j$ by integrality, whilst $\\dim(S_e/(x_{e+1}, \\ldots, x_n)) = e$. Contradiction.\n\t\n\tNow take $x_e \\in I_j \\cap \\Bbbk[x'_1, \\ldots, x'_e] \\smallsetminus \\{0\\}$. Note that $x_e \\notin \\Bbbk$ as $I_j \\neq B$. By Lemma \\ref{prop:normalization-Nagata}, we may choose $x''_1, \\ldots, x''_{e-1} \\in \\Bbbk[x'_1, \\ldots, x'_e]$ such that $\\Bbbk[x'_1, \\ldots, x'_e]$ is finitely generated over $\\Bbbk[x''_1, \\ldots, x''_{e-1}, x_e]$ as a module. It remains to verify that the new sequence\n\t\\[ x''_1, \\ldots, x''_{e-1}, x_e, \\ldots, x_n \\]\n\tsatisfies (i)---(iii) above with $e-1$ replacing $e$.\n\t\n\tFirst, $S_e$ is a finitely generated module over its subalgebra $\\Bbbk[x''_1, \\ldots, x_n]$ by construction, hence so is $B$ and (i) follows. Next, let $1 \\leq j' \\leq m$. If $d_{j'} > e-1$, the procedure above does not affect $x_{d_j + 1}, \\ldots, x_n$, so they belong to $I_{j'} \\cap \\Bbbk[x''_1, \\ldots, x_n]$. If $d_{j'} < e$, setting $j := \\min\\{j'' : e > d_{j''} \\}$ we have $j' \\geq j$ and\n\t\\[ I_{j'} \\cap \\Bbbk[x''_1, \\ldots, x_n] \\supset I_j \\cap \\Bbbk[x''_1, \\ldots, x_n] \\supset (x_{e+1}, \\ldots, x_n) + (x_e). \\]\n\tAll in all, we obtain (ii) and (iii).\n\\end{proof}\n\n\\begin{corollary}[Dimension formula]\\label{prop:fg-dim-formula}\\index{dimension formula}\n\tLet $B$ be a finitely generated algebra over a field $\\Bbbk$. Suppose $B$ is a domain, then for all $\\mathfrak{q} \\in \\Spec(B)$ we have\n\t\\[ \\dim(B/\\mathfrak{q}) + \\mathrm{ht}(\\mathfrak{q}) = \\dim B. \\]\n\\end{corollary}\n\\begin{proof}\n\tChoose a subalgebra $A$ of $B$ as in Theorem \\ref{prop:Noether-normalization} and put $\\mathfrak{p} = \\mathfrak{q} \\cap A$. Since $B$ is a domain and $A$ is normal, the Cohen--Seidenberg Theorem \\ref{prop:Cohen-Seidenberg} asserts the going-down property for $A \\hookrightarrow B$. Proposition \\ref{prop:dim-integral} implies that $\\dim A = \\dim B$, $\\dim A/\\mathfrak{p} = \\dim B/\\mathfrak{q}$ and $\\text{ht}(\\mathfrak{p}) = \\text{ht}(\\mathfrak{q})$, so we are again reduced to the case $B = \\Bbbk[X_1, \\ldots, X_n]$ and $\\mathfrak{q} = (X_{d+1}, \\ldots, X_n)$. This is known by Corollary \\ref{prop:poly-alg-ht}.\n\\end{proof}\n\nThe dimension formula allows us to compute $\\dim B$ by choosing any prime $\\mathfrak{q}$, a prime chain of longest length below $\\mathfrak{q}$ (i.e. in $B_{\\mathfrak{q}}$) and another one above $\\mathfrak{q}$ (i.e. in $B/\\mathfrak{q}$); their concatenation will then be a prime chain in $B$ with maximal length $\\dim B$. By applying the dimension formula to $\\mathfrak{q}, \\mathfrak{q}' \\subset B$ and to $\\mathfrak{q}'/\\mathfrak{q} \\subset B/\\mathfrak{q}$, it follows that $\\text{ht}(\\mathfrak{q}') = \\text{ht}(\\mathfrak{q}) + \\text{ht}(\\mathfrak{q}'/\\mathfrak{q})$ for all $\\mathfrak{q}' \\supsetneq \\mathfrak{q}$ in $B$.\n\nFor a general Noetherian domain $B$, we call a prime chain \\emph{maximal} if it is not properly contained in any prime chain. A priori, a maximal prime chain does not necessarily have length equal to $\\dim B$. If\n\\[ \\forall \\mathfrak{q}' \\supset \\mathfrak{q}: \\text{primes}, \\quad \\text{ht}(\\mathfrak{q}') = \\text{ht}(\\mathfrak{q}) + \\text{ht}(\\mathfrak{q}'/\\mathfrak{q}), \\]\nwe say $B$ is a \\emph{catenary} domain\\index{catenary}. This means that $\\text{ht}(\\mathfrak{q}'/\\mathfrak{q}) = \\dim B_{\\mathfrak{q}'}/\\mathfrak{q}B_{\\mathfrak{q}'}$ is the common length of all maximal prime chains between $\\mathfrak{q}'$ and $\\mathfrak{q}$. In particular, maximal prime chains in $B_{\\mathfrak{q}'}$ are automatically longest. As shown above, finitely generated domains over a field are catenary. For a finer analysis of catenary and universally catenary rings, we refer to \\cite[\\S 14]{Mat80}.\n\n\\begin{corollary}\n\tSuppose $B$ is a domain finitely generated over a field $\\Bbbk$. Set $L := \\mathrm{Frac}(B)$. Then $\\dim B = \\mathrm{tr.deg}_\\Bbbk(L)$ and it is the common length of maximal prime chains.\n\\end{corollary}\n\\begin{proof}\n\tChoose a subalgebra $A$ of $B$ as in Theorem \\ref{prop:Noether-normalization}. Since the field $\\text{Frac}(B)$ is a finite extension of $\\text{Frac}(A)$ and $\\dim A = \\dim B$ by Proposition \\ref{prop:dim-integral}, the first assertion reduces immediately to the case $B = \\Bbbk[X_1, \\ldots, X_n]$, which is obvious. As to the second assertion, consider a maximal prime chain $\\mathfrak{q}_0 \\supsetneq \\cdots \\supsetneq \\mathfrak{q}_n = \\{0\\}$ in $B$. Maximality implies $\\text{ht}(\\mathfrak{q}_i/\\mathfrak{q}_{i+1}) = 1$ for all $i$ and $\\dim B/\\mathfrak{q}_0 = 0$. Applying Corollary \\ref{prop:fg-dim-formula} repeatedly, we see\n\t\\begin{multline*}\n\t\t\\dim B = \\dim B/\\mathfrak{q}_n = \\dim B/\\mathfrak{q}_{n-1} + \\text{ht}(\\mathfrak{q}_{n-1}/\\mathfrak{q}_n) = \\\\\n\t\t\\dim B/\\mathfrak{q}_{n-2} + \\text{ht}(\\mathfrak{q}_{n-1}/\\mathfrak{q}_{n-2}) + \\text{ht}(\\mathfrak{q}_{n-1}/\\mathfrak{q}_n) = \\cdots = \\dim B/\\mathfrak{q}_0 + \\sum_{i=0}^{n-1} \\text{ht}(\\mathfrak{q}_i/\\mathfrak{q}_{i+1})\n\t\\end{multline*}\n\twhich equals $n$.\n\\end{proof}\n\n\\begin{remark}\n\tRecall that finitely generated domains over an algebraically closed field $\\Bbbk$ are objects ``opposite'' to the irreducible affine $\\Bbbk$-varieties. It is instructive to make a comparison with the analytic theory when $\\Bbbk=\\CC$. Let $\\mathcal{X}$ be a compact connected complex manifold of (complex) dimension $n$. Denote by $\\mathcal{M}(\\mathcal{X})$ the field of meromorphic functions on $\\mathcal{X}$. Siegel proved that $\\text{tr.deg}_{\\CC}(\\mathcal{M}(\\mathcal{X})) \\leq n$. When $\\mathcal{X}$ is a projective algebraic $\\CC$-variety, equality holds and we have $\\mathcal{M}(\\mathcal{X}) = \\text{Frac}(A)$ if $\\Spec(A)$ is any open dense affine subscheme in $\\mathcal{X}$. In general, the abundance of meromorphic functions on $\\mathcal{X}$ is a subtle issue, cf. the case of Riemann surfaces ($n=1$). Compact connected complex manifolds with $\\text{tr.deg}_{\\CC}(\\mathcal{M}(\\mathcal{X})) = \\dim_{\\CC} \\mathcal{X}$ are called \\emph{Moishezon manifolds}.\\index{Moishezon manifolds}\n\t\n\tNon-algebraic Moishezon manifolds do exist, and Moishezon proved that a Moishezon manifold is projective, hence algebraic, if and only if it is Kähler. Following M.\\ Artin and D.\\ Knutson, one can enlarge the category of $\\CC$-schemes into that of \\emph{algebraic spaces} over $\\CC$, and there is an analytification functor $\\mathcal{X} \\mapsto \\mathcal{X}_{\\text{an}}$ that sends algebraic spaces of finite type over $\\CC$ to complex analytic varieties. M. Artin \\cite[\\S 7]{Ar70} showed that the analytification establishes an equivalence between the category of smooth proper algebraic spaces of finite type over $\\CC$ and that of Moishezon manifolds. Therefore, such manifolds still retain an algebraic flavor: they are quotients of certain $\\CC$-schemes by étale equivalence relations.\n\\end{remark}\n", "meta": {"hexsha": "594e2385d66fa9b18eb89edc08fcd2c144e5f31a", "size": 26676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "YAlg3-6.tex", "max_stars_repo_name": "wenweili/Yanqi-Algebra-3", "max_stars_repo_head_hexsha": "4223e9973c97342ecb09b444b9fc3c30ffd53aa3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-07-09T06:22:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T14:44:14.000Z", "max_issues_repo_path": "YAlg3-6.tex", "max_issues_repo_name": "wenweili/Yanqi-Algebra-3", "max_issues_repo_head_hexsha": "4223e9973c97342ecb09b444b9fc3c30ffd53aa3", "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": "YAlg3-6.tex", "max_forks_repo_name": "wenweili/Yanqi-Algebra-3", "max_forks_repo_head_hexsha": "4223e9973c97342ecb09b444b9fc3c30ffd53aa3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-07-10T23:47:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-21T03:32:08.000Z", "avg_line_length": 116.4890829694, "max_line_length": 992, "alphanum_fraction": 0.6703778677, "num_tokens": 10247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6167095632700498}}
{"text": "\\chapter{Learning coupled dictionaries}\n\\label{chap_dictionarylearning} \nThis chapter describes an alternative approach to learn the relation between large and small scales of turbulence based on \\textit{dictionary learning} methods. The approach finds coupled dictionaries to represent the low and high resolution turbulent fields and to reconstruct the missing small-scale information. This method has been applied successfully in image processing, and remains a very active research subject. It potentially outperforms regression models, which are sometimes too simplistic to represent the underlying phenomenon in turbulence. Indeed learned dictionaries could encode part of the physics of the flow. \n\nThis chapter is organized as follows. First, different data representations are discussed, from predefined bases such as Fourier or wavelets to learned bases such as principal component analysis (PCA). Second, dictionary learning, a generalization of PCA, is discussed for the first time as a representation for turbulent fields. This section reviews also two algorithms to learn the dictionaries. Third, different approaches to learn coupled dictionaries of low and high resolution fields are presented. Last, the approach is tested on the DNS database of an isotropic turbulence presented in section \\ref{sec:data_isotropic}. \n\n\\section{From bases to dictionaries}\nThis section briefly reviews conventional representations of turbulent signals. Given a vector $ \\x_t $, the main idea of all representation methods is to find a ``\\textit{dictionary}'' $ \\dict $, a set of basis functions or the so-called ``\\textit{atoms}'' from which $ \\x_t $ can be represented via a linear combination. This representation by coefficients $ \\adictco_t $ is called a ``\\textit{code}''. The representation can be exact:\n\\begin{equation}\n\\x_t = \\dict \\adictco_t\n\\end{equation}\nor approximate:\n\\begin{equation}\n \\x_t = \\dict \\adictco_t +\\n_t\n\\end{equation}\nwhere $ \\n_t $ is an estimation noise term. Seeking the representation of the signal is an optimization problem to estimate the dictionary $ \\dict $ and the code $ \\adictco_t $. The dictionary can be mathematically predefined or learned from the data. The estimation of the coefficients $ \\adictco_t $ can be very simple with very fast algorithms for predefined or orthogonal bases, or more complex with redundant dictionaries. \n\n\\subsection{Predefined dictionaries}\nVarious types of dictionaries are studied to represent the data. They can be predefined \\textit{a priori} such as the well-known Fourier transform, the group of \\textit{wavelets} or \\textit{curvelets} \\citep{mallat1989theory,mallat1999wavelet}. These predefined transforms are easy to compute thanks to fast algorithms. Fourier transform aims at describing the signal via its frequency content by decomposing signals as an infinite series of sines and cosines. This transformation is localized in frequency but not in space/time. The constraint is overcome using wavelet transforms, replacing the sines and cosines by wavelet functions localized both in space/time and frequency. This property permits wavelets to better represent the signal with discontinuities or sharp spikes. In such cases, the representations are much more compact with wavelet functions than sines and cosines. This makes wavelets standard in signal compression, for example JPEG 2000 for images, while Fourier transform is mainly used for spectral analysis.\n\nRepresentations using predefined bases suffer from some limitations. Fourier transform is limited to spectral analysis due to its localization in frequency. Wavelet transforms overcome this constraint by its carefully designed functions, which permit the localization both in space/time and frequency domain. The aim is to optimize the ``\\textit{sparsity}'' of the representation, which is to minimize the number of basis functions to accurately represent the data. However, despite the large family of wavelets, all kinds of signals cannot be represented with high level of sparsity. Analogously for turbulence data, different flows or a single flow at various positions with respect to a wall can have significantly different physics, leading to signals with completely different properties.\n\n\\subsection{Adaptive dictionaries}\nTo further optimizing the representation, it is more appealing to learn dictionaries adaptively from the data \\citep{bengio2013representation}. The first and most common method is the \\textit{principal component analysis} (PCA). This approach learns a basis that maximizes the variance of the projected values. This is interesting for turbulence studies, since large scales of higher variances are of interest. This representation imposes orthogonal bases, which implies that the number of atoms is limited by the dimension of the input vectors. PCA is potentially subject to certain limitations due to this constraint. This chapter discusses the generalized version of PCA, which permits to learn a ``\\textit{redundant}'' dictionary. The method is called \\textit{dictionary learning}, which is widely used and remains an active research topic in image processing. It will be discussed further in this section before applying to the problem of turbulent field reconstruction. \n\nAdaptive dictionaries are useful in many applications \\citep{tovsic2011dictionary}. The first one is \\textit{dimension reduction} \\citep{burges2010dimension}, which is useful to build models or visualize large amount of data. For modeling, high dimensional input variables potentially causes the problem of high variance as discussed in chapter \\ref{chap_linearregression}, or intractable computation complexity. For visualization, it is a real constraint since the maximum number of dimensions one can observe and analyze is probably no more than three. The core idea is to project data onto a set of atoms in a dictionary. This projection is lossy, meaning that a certain amount of less informative variance is discarded. Another important application is to solve inverse problems such as super-resolution or denoising. These problems are very ill-posed and can not be solved directly by least-squares methods. A good representation of the data can play the role as a regularization term, making the problem easier to solve. The choice of a dictionary defines the space in which we search for solutions.\n\n\\section{Proper Orthogonal Decomposition (POD) as a representation of turbulent fields}\nPCA \\citep{jolliffe2002principal}, known also as \\textit{Karhunen–Loève} transform, is commonly used in many fields of signal and image processing. It was first introduced in turbulence studies by \\citet{lumley1967} under the name ``\\textit{proper orthogonal decomposition}'' (POD). It is then used as a standard approach for dimensionality reduction, which is largely beneficial in large scales reconstruction, flow control and coherent structure studies. PCA decomposes a sequence of snapshots into a dictionary $ \\dict $ to represent spatial structures, and a coefficient matrix $ \\dictco $, to capture temporal dynamics. The works on coherent structures and flow information extraction focus on the dictionary $ \\dict $ \\citep{bonnet1994stochastic, gordeyev2000coherent}. Each atom $ \\adict_i $, as ranked by its variance (an equivalent measure of the kinetic energy), represents the most energetic structures of the flow. Flow control and modeling works focus more on the use of projection coefficients $ \\dictco $. After learning the fixed dictionary $ \\dict $, independent of time, from given training fields, the temporal dynamics of the flow is presented in the projection coefficients $ \\dictco $ only. The efforts to model and control the flow are reduced tremendously by considering only several coefficients of high-variance atoms. This property is beneficial for reduced-order modeling works in flow control and reconstruction of large-scale velocity fields \\citep{ravindran2000reduced, ly2001modeling, taylor2004towards}.\n\nTo derive POD or PCA, let first denote a data matrix $ \\X $ of size $ \\dimsh \\times \\dimtl $ containing a sequence of $ \\dimsh- $dimensional input vectors $ \\x_t, t=1,2,...,\\dimtl $,\n\\begin{equation}\n\\X \\mydef \\begin{bmatrix} \\x_1, \\x_2, ..., \\x_\\dimtl \\end{bmatrix},\n\\end{equation} \nassumed centered \\textit{a priori}:\n\\begin{equation}\n\\sum\\limits_{t=1}^{\\dimtl}\\x_t = \\mybold{0}\n\\end{equation}\nFrom $ \\X $, a dictionary $ \\dict $ of size $ \\dimsh \\times \\dimsh $ is estimated, which contains $ \\dimsh $ atoms $ \\adict_i \\in \\R ^\\dimsh, i=1,2,...,\\dimsh  $. The objective is to project $ \\x_t $ onto a reduced-order subspace of dimension $ \\dimtrunc \\leq \\dimsh $ while maximizing the amount of variance. This idea, when applying to turbulent fields where variance represents the kinetic energy, is interpreted as determining the most energetic structures among a sequence of snapshots. \n\nThe first step is to find the most dominant basis function $ \\adict_1  \\in \\R^\\dimsh$, assuming $ \\normtwo{\\adict_1} = 1 $. Each input vector is projected onto this direction as $ \\adict_1^\\mytrans \\x_t $. The variance of this projection is:\n\\begin{equation}\ns_1 = \\frac{1}{\\dimtl} \\sum\\limits_{t=1}^{\\dimtl}\\left( \\adict_1^\\mytrans \\x_t\\right)^2 =  \\adict_1^\\mytrans \\Sigma \\adict_1\n\\end{equation}\nwhere $ \\Sigma  $ is the covariance matrix:\n\\begin{equation}\n\\Sigma = \\frac{1}{\\dimtl} X X^\\mytrans\n\\end{equation}\nThe aim now is to find  $ \\adict_1 $ such that $ s_1 $ is maximum, with the constraint that $ \\normtwo{\\adict_1} = 1$:\n\\begin{equation}\n\\adict_1 = \\argmax_{\\adict_1}{ \\left\\lbrace \\adict_1^\\mytrans \\Sigma \\adict_1 \\right\\rbrace } \\:\\:\\:\\:\\:\\: s.t \\:\\:\\:\\:\\:\\: \\normtwo{\\adict_1} = 1\n\\end{equation}\nThis optimization problem can be rewritten in an unconstrained manner by introducing a Lagrange multiplier $ \\lambda_1 $:\n\\begin{equation}\n\\adict_1 = \\argmax_{\\adict_1}{ \\left\\lbrace \\adict_1^\\mytrans \\Sigma \\adict_1 + \\lambda_1 \\left(1-\\adict_1^\\mytrans \\adict_1\\right) \\right\\rbrace } \n\\end{equation}\nSetting the derivative with respect to $ \\adict_1 $ to zero, one obtains:\n\\begin{equation}\n\\Sigma \\adict_1 = \\lambda_1 \\adict_1\n\\end{equation}\nwhich implies that $ \\adict_1 $ is an eigenvector of $ \\Sigma $, and $ \\lambda_1 $ is the equivalent eigenvalue. Also, multiplying both side with $ \\adict_1^\\mytrans $, using $ \\adict_1^\\mytrans\\adict_1=1 $, one has:\n\\begin{equation}\n\\adict_1^\\mytrans \\Sigma \\adict_1 = \\lambda_1\n\\end{equation}\nThe above expression implies that $ \\lambda_1 $ is the variance of the projection onto $ \\adict_1 $. This variance is maximized by selecting the maximum eigenvalue of the covariance matrix $ \\Sigma $. This process is repeated to find the second basis of the dictionary $ \\adict_2 $ such that it is orthogonal to the first one, i.e. $ \\adict_1^{\\mytrans}\\adict_2=0 $. This is identical to find the second eigenvector corresponding to the second largest eigenvalue $ \\lambda_2 $. The procedure of seeking all $ \\dimsh $ bases is identical to eigenvalue decomposition and SVD of the covariance matrix $ \\Sigma $. Sorting $ \\dimsh $ eigenvalues in a descending order as $ \\lambda_1 \\geq \\lambda_2 \\geq ... \\geq \\lambda_\\dimsh \\geq 0 $, one obtains the dictionary, or codebook, learned from the training samples $ \\X $ by putting the equivalent eigenvectors together as $ \\dict \\mydef \\left[ \\adict_1, \\adict_2, ..., \\adict_\\dimsh \\right] $. The projection matrix $ \\dictco $ is found such that:\n\\begin{equation}\n\\X = \\dict \\dictco\n\\end{equation}\n\n\n\\section{Dictionary learning as a new representation}\nDue to the orthogonality and variance maximization properties, PCA gains its success in many problems such as dimensionality reduction, low-order modeling and lossy compression. However, in solving different inverse problems, PCA is subject to several limitations. The number of atoms is at most the dimension of input vectors, leading to the ``limited expressiveness'' property \\citep{tovsic2011dictionary}. The representation learned by PCA can be efficient for training data, but a good generalization is not guaranteed. It is desirable to ignore the constraint on the number of basis functions and learn a redundant dictionary. Due to the redundancy, the sparsity constraint can be imposed and play the role of the regularization to solve ill-posed inverse problems.\n\n\\subsection{Redundant dictionary and sparse representation}\nDictionary learning (DL) ignores the constraint on the number of basis functions, or atoms, permitting to find a \\textit{redundant} (or \\textit{overcomplete}) dictionary $ \\dict \\in \\R^{\\dimsh \\times \\dimdict} $ to represent the data. $ K $ is the number of atoms, and redundancy means that $ \\dimdict $ is potentially larger than $ \\dimsh $. These vectors are therefore not necessarily orthogonal. The companion of redundancy is sparsity, where the linear transformation matrix $ \\dictco $ contains only a few nonzero coefficients. The representation then relies on the duality between redundancy and sparsity, which will be discussed further in this section. With more atoms, the representation using dictionary learning is expected to be more adaptive to the signal and to better represent new data. This is the reason why the approach often gives the state-of-the-art results in most inverse problems in image processing \\citep{elad2010on,yang2010image}.\n\nThe problem of representing data $ \\X $ using the redundant dictionary $ \\dict $ and sparse coefficients $ \\dictco $ includes two alternating optimization problems. The first one is to estimate the projection coefficients $ \\dictco $. PCA, with the orthogonality among atoms, simply estimates $ \\dictco $ by dot products. Dictionaries, which are not necessarily orthogonal, can have more atoms than the dimension ($ \\dimdict > \\dimsh $). There are potentially many matrices $ \\dictco $ such that $ \\X = \\dict \\dictco $. The sparsity constraint, meaning that $ \\dictco $ has a minimal number of nonzero coefficients, is imposed to make the solution unique. The representation of $ \\X $ becomes approximate, i.e. $ \\X \\approx \\dict \\dictco $. Finding $ \\dictco $ becomes an optimization problem of the form:\n\\begin{equation}\n\\dictco = \\argmin_{\\dictco}{\\normp{\\dictco}} \\quad s.t. \\quad \\X = \\dict \\dictco\n\\end{equation}\nor re-arranged in the form of a regularized cost function as in chapter \\ref{chap_linearregression}:\n\\begin{equation}\n\\dictco = \\argmin_{\\dictco}{\\normtwo{\\X - \\dict \\dictco} + \\lambda \\normp{\\dictco}}\n\\end{equation}\nThe common \\textit{$ \\ell^p $ norm} $ \\normp{.} $ is with $ 0 \\leq p \\leq 1 $. Solving the problem with the $ \\ell^0 $ norm, i.e. counting the number of nonzero coefficients, leads to orthogonal matching pursuit (OMP) \\citep{tropp2007signal}, while solving with the $ \\ell^1 $ norm, summing the absolute values of the coefficients, leads to LASSO as discussed in chapter \\ref{chap_linearregression}. Least Angle Regression (LARS) \\citep{efron2004least} is sometimes used as another efficient algorithm to solve $ \\ell^1 $ penalty problems and gives results very similar to LASSO. These regularizations help selecting a limited number of atoms that best approximate the input $ \\X $. The second problem is the choice of the dictionary, which is solved by efficient algorithms discussed in the next section.\n\n\\subsection{Dictionary learning methods}\nMany algorithms have been proposed to learn the dictionary from data, starting with gradient descend method \\citep{olshausen1996emergence}, then K-SVD \\citep{aharon2006ksvd}, feature-sign approach \\citep{lee2006efficient} and online dictionary learning \\citep{mairal2010online}. This section reviews some of those that are used later in this chapter. \n\n\\subsubsection{Alternate optimization}\nDictionary learning is an alternate optimization problem to search the redundant dictionary $ \\dict $ and the sparse matrix $ \\dictco $. The approach has started by using a gradient descent approach \\citep{olshausen1996emergence}. It has recently gained popularity thanks to the progress in solving regularized optimization problems with $ \\ell^p $ penalty \\citep{tibshirani1996regression, donoho2003optimally, efron2004least, donoho2012sparse}. One of the first efficient dictionary learning approach is the \\textit{method of optimal directions} (MOP) \\citep{engan1999method} where $ \\dict $ and $ \\dictco $ are estimated by solving:\n\\begin{equation}\n(\\dict, \\dictco) = \\argmin_{\\dict, \\dictco} \\normtwo{\\X - \\dict \\dictco} \\subjectto \\normzero{\\adictco_t} < \\dimtrunc \\quad \\forall t\n\\end{equation}\n$ \\dimtrunc $ is the sparsity constraint- the maximum number of nonzero coefficients. This optimization problem is  combinatorial and highly non-convex. The search for a local minimum is done by alternating two steps. With a fixed dictionary $ \\dict $, the \\textit{sparse coding} step finds the representation of the input vectors by solving:\n\\begin{equation}\n\\dictco = \\argmin_{\\dictco} \\left\\lbrace \\normtwo{\\X - \\dict\\dictco} + \\lambda \\normp{\\dictco}\\right\\rbrace\n\\end{equation}\nThis step uses OMP for $ \\ell^0 $ penalty and LASSO or LARS for $ \\ell^1 $ penalty. The \\textit{dictionary update} step re-estimates $ \\dict $ with fixed $ \\dictco $ via the Moore-Penrose pseudo-inverse:\n\\begin{equation}\n\\dict = \\X \\dictco^\\mypseudo = \\X \\dictco^\\mytrans (\\dictco \\dictco^\\mytrans)^{-1}\n\\end{equation}\nThis scheme converges rapidly after some iterations, but requires complex matrix inversion, which is not efficient in most cases \\citep{aharon2006ksvd}. \n\\subsubsection{K-SVD}\nThe \\textit{K-SVD} algorithm was proposed later by \\citet{aharon2006ksvd} and rapidly gained its popularity. The \\textit{dictionary update} is done by a block-relaxation approach. Instead of inversing the matrix, the algorithm updates each atom in an efficient way by generalizing the \\textit{k-means} clustering method \\citep{bishop2006pattern}. The $ k- $th atom is estimated by minimizing a quadratic error:\n\\begin{equation}\n\t\\left\\lbrace \\adict_k, \\adictco_k \\right\\rbrace = \\argmin_{\\adict_k, \\adictco_k} \\normtwo{E_k \\: - \\: \\adict_k \\adictco_k^\\mytrans}\n\\end{equation} \nwhere $  E_k $ is defined as the residual matrix:\n\\begin{equation}\nE_k \\mydef \\X_k \\: - \\: \\sum_{j\\neq k} \\left(\\adict_j \\adictco_j^\\mytrans \\: - \\: \\adict_k \\adictco_k^\\mytrans\\right)\n\\end{equation}\nwhere $ \\X_k $ gathers examples $ \\x_t $ using $ \\adict_k $ in their representation. The update of both $ \\adict_k $ and $ \\adictco_k $ is done simultaneously via a rank-1 approximation, i.e. considering only the first eigenvector of $ E_k $ after performing a SVD.\n\n\\subsubsection{Online dictionary learning (ODL)}\nK-SVD algorithm has certain constraints, mainly with a potential local minimum while iteratively learning the dictionary \\citep{rubinstein2010dictionaries}. The algorithm is also limited to small numbers of samples due to its computational cost. Online dictionary learning (ODL) has been proposed by \\citet{mairal2010online} to learn $ \\dict $ from massive datasets. The use of stochastic gradient descent to update the dictionary for each example (or a group of them), and LARS algorithm for sparse coding, permits the learning over millions of samples. Algorithm \\ref{algo_ODL} summarizes this approach.\n\n\\begin{algorithm}[t]\n\\caption{Online dictionary learning algorithm by  \\citet{mairal2010online}} \\label{algo_ODL}\n\\begin{algorithmic}[1]\n\t\\State Input: \n\t\\begin{itemize}\n\t\t\\item a set of $ \\mathcal{S}(\\x) $ of $\\dimtl $ input variable $ \\x_t \\in \\R^\\dimsh$;\n\t\t\\item $\\lambda \\in \\R $ : regularization parameter ($ \\lambda \\geq 0 $)\n\t\t\\item $ \\dict_0 \\in \\R^{\\dimsh \\times K}$: initial dictionary\n\t\\end{itemize}\n\t\\State $ \\mathbf{G}_0 \\gets  0$, $ \\mathbf{H}_0 \\gets 0 $\n\t\\For {$ t = 1, 2, ..., \\dimtl$}\n\t\t\\State Draw $ \\x_t $ from $\\mathcal{S}(\\x)$\n\t\t\\State Sparse coding:\n\t\t\\begin{equation}\n\t\t\t\\adictco_t = \\argmin_{\\adictco \\in \\R^K} \\left\\lbrace \\x_t - \\dict_{t-1}\\adictco +\\lambda \\normone{\\adictco}\\right\\rbrace\n\t\t\\end{equation}\n\t\t\\State $ \\mathbf{G}_t \\gets \\mathbf{G}_{t-1}+\\adictco_t \\adictco_t^\\mytrans$\n\t\t\\State $ \\mathbf{H}_t \\gets \\mathbf{H}_{t-1}+\\adictco_t \\x_t^\\mytrans$\n\t\t\\State Update $ \\dict_t $:\n\t\t\\begin{equation}\n\t\t\t\\begin{split}\n\t\t\t\\dict_t = & \\argmin_{\\dict \\in \\mathcal{C}} \\left\\lbrace \\frac{1}{t} \\sum\\limits_{i=1}^{t}\\frac{1}{2} \\normtwo{\\x_i - \\dict\\adictco_i} + \\lambda \\normone{\\adictco_i} \\right\\rbrace \\\\\n\t\t\t=& \\argmin_{\\dict \\in \\mathcal{C}} \\left\\lbrace \\frac{1}{t} \\sum\\limits_{i=1}^{t}\\frac{1}{2} \\mytrace{\\dict^\\mytrans\\dict \\mathbf{G}_t} - \\mytrace{\\dict^\\mytrans \\mathbf{H}_t} \\right\\rbrace\n\t\t\t\\end{split}\n\t\t\\end{equation}\n\t\\EndFor\n\t\\State Return $ \\dict_\\dimtl $\n\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Learning coupled dictionaries}\n\\label{joint_learning}\nIn this section, DL is used to solve the problem of reconstructing HR fields from LR ones. The approach is inspired by the \\textit{single image super-resolution} application \\citep{yang2010image,yang2012coupled,zeyde2012single}, i.e. estimating HR images with finer details from LR ones. The approach jointly learns coupled dictionaries at LR and HR from given training samples. These dictionaries are forced to represent the data using the same coefficients. In the prediction phase, the projection coefficients are estimated from the LR images and then combined with the learned HR dictionary to reconstruct the HR images. \n\n\\subsection{Patch-based approach}\n\\label{subsec:patch_based_estimation}\n\\begin{figure}\n\\centering\n\t\\includegraphics[width=0.9\\textwidth]{./images/DL/ScSR.png}\n\t\\caption{\\label{fig:ScSR} An example of single image super-resolution using coupled dictionary learning and patch-wise approach. Photo credit: \\citet{yang2010image}.}\n\\end{figure}\n\nDL requires a sparse coding step, i.e. solving the $ l^1 $-penalty optimization problem. The computation complexity is $ \\mathcal{O}(\\dimsh^3+\\dimtl\\dimsh^2) $ \\citep{efron2004least}, where $ \\dimsh $ is the dimension of the fields and $ \\dimtl $ is the number of samples. Since $ \\dimsh \\gg \\dimtl$ in most cases, the complexity is $ \\mathcal{O}(\\dimsh^3) $, which is a very heavy procedure. The computation is therefore intractable with the whole field. To overcome this difficulty, the ``\\textit{patch-wise}'' approach uses small patches instead of the whole fields. These patches are extracted from the original fields at all positions by moving pixel-by-pixel in both horizontal and vertical directions. Let $ \\dimptl $ be the total number of patches, and $ \\dimpsh $ be their dimension ($\\dimptl \\gg \\dimpsh $), the computation complexity becomes $ \\mathcal{O}(\\dimptl\\dimpsh^2) $, which is tractable when $ \\dimpsh $ is small. In the reconstruction phase, since one pixel belongs to several intersecting patches, the estimated field is reconstructed by aggregating all possible estimates of each pixel after putting them back into the whole scene.\n\nThe path-wise approach comes with several advantages. First, it localizes the information. A shared dictionary can be learned to represent all type of images with different contents. Second, it reduces tremendously the computation. Standard images are of dimension few millions, while typical patch sizes are around $ 8 \\times 8 $, which is a few orders of magnitude smaller. Last, since the learning is on small patches, the number of samples required for the algorithm to converge is much smaller. From a single image, millions of small patches can be extracted for learning. Working with the original image, the number of training samples is necessary at least one order of magnitude higher than its dimension, which is already millions of pixels. \n\nTo formulate the patch-based approach, let $ \\z_t \\in \\R^{\\dimsh} $ be a snapshot of a high-resolution field as a column vector. The operator $ \\extracthigh{k}:\\R^{\\dimsh} \\mapsto \\R^{\\dimpsh} $ is to extract the 2D patch and put them in a lexicographical order to form a column vector $ \\patchhigh{k} \\mydef \\extracthigh{k} \\z_t \\in \\R^\\dimpsh $, where $ \\dimpsh $ is the size of 2D patches $ \\patchhigh{k} $. If the overlapping is such that all patches are translated pixel-by-pixel, the total number of patches is $ \\left( \\sqrt{\\dimsh} - \\sqrt{\\dimpsh} + 1 \\right)^2 $. The reconstruction of the whole image is done as:\n\\begin{equation}\n\\hat{\\z}_t= \\left[ \\sum\\limits_{k} \\left(\\extracthigh{k}\\right)^{\\mytrans}\\extracthigh{k}\\right]^{-1}\\sum\\limits_{k} \\left(\\extracthigh{k}\\right)^{\\mytrans}\\hat{\\mybold{p}}_h^k\n\\end{equation}\nwhere $ \\hat{\\mybold{p}}_h^k $ and $ \\hat{\\z}_t $ are the estimates of the reference $ \\patchhigh{k} $ and $ \\z_t $ respectively. The term $ \\left(\\extracthigh{k}\\right)^{\\mytrans}: \\R^{n} \\mapsto \\R^{\\dimsh}$ puts the equivalent patch into the global 2D scene and zero-pad elsewhere. The term $ \\left(\\extracthigh{k}\\right)^{\\mytrans}\\extracthigh{k} $ just counts the number of estimates for each pixels. Its inversion plays the role of a normalization factor. In practice, the whole process is done by estimating each pixel as its mean or median of all estimates from all patches that it belongs to. \n\n\\subsection{The approach}\n\\label{sec:chap3_theapproach}\nLet assume that small patches from the field can be represented as a linear combination of several atoms from the learned dictionary. This assumption is the so-called ``\\textit{Sparse-Land}'' prior \\citep{zeyde2012single}. The idea is to learn coupled dictionaries by imposing that the representation coefficients are the same at low and high resolution. The following section recalls the main ideas. More details can be found in \\citet{zeyde2012single}.\n\nSuppose that $ \\z_t \\in \\R^{\\dimsh}$ is the true high resolution velocity field. The corresponding low-resolution field $ \\y_t \\in \\R^{\\dimsl} $ $(\\dimsl < \\dimsh) $ is obtained as:\n\\begin{equation}\n\\y_t = \\Sub_s\\LPF_s\\z_t + \\mybold{v}_t\n\\label{eq:DL_approach1}\n\\end{equation}\nwhere $ \\mybold{v}_t $ is a random noise, $ \\LPF_s $ is an anti-aliasing low-pass filter, and $ \\Sub_s $ is a subsampling operator. The presence of $ \\LPF_s $ is to avoid the problem of aliasing when subsampling the field. In the case of direct subsampling, this filter is omitted from the above model. The goal is to find a HR estimate $ \\hat{\\z}_t $ containing both large and small scales. The most naive and simple idea is to interpolate from $ \\y $, i.e. $ \\hat{\\z}_t = \\Interp_s\\y_t \\in \\R^{\\dimsh}$. However, it will give no access to small-scale information above the cutoff frequency defined by the low-resolution grid. The coupled dictionary approach permits to learn small scales from training data and uses it for the reconstruction. \n\nDL uses the patch-based approach, where the couples of LR and HR patches are extracted from the LR and HR fields respectively. Let $ \\patchhigh{k} = \\mathcal{R}_h^k \\z_t \\in \\R^\\dimpsh $ be the $ k-${th} HR patch. By assuming the Sparse-Land model for high and low resolution training fields, each patch can be estimated as a linear combination of atoms in a dictionary:\n\\begin{equation}\n\\patchhigh{k} = \\dict_h \\adictco^k + \\mybold{\\epsilon}^k\n\\label{eq:DL_approach2}\n\\end{equation} \nwhere $ \\dict_h  \\in  \\R^{\\dimpsh \\times K}$ is the HR dictionary, $ \\adictco^k \\in \\R^K$ is the coefficient vector and $ \\mybold{\\epsilon}^k $ is the reconstruction error. The dictionary is redundant ($ K > \\dimpsh $) and the coefficients are sparse ($ \\Arrowvert \\adictco^k \\Arrowvert_0 < \\dimtrunc $), with the sparsity constraint $ \\dimtrunc \\ll K $. The corresponding LR patch $ \\patchlow{k} \\in \\R^\\dimpsl $ is: \n\\begin{equation}\n\t\\patchlow{k} = \\extractlow{k} \\y_t = \\extractlow{k} \\Sub_s\\LPF_s\\z_t + \\extractlow{k}\\mybold{v}_t\n\\label{eq:DL_approach3}\n\\end{equation}\t\n$ \\extractlow{k} $ is just an extraction operator, and $ \\Sub_s\\LPF_s $ is a transformation operator going from HR to LR fields. Since $ \\Sub_s $ and $ \\LPF_s $ are spatially independent operators, there exit local $ \\Sub_s^{loc} $ and $ \\LPF_s^{loc} $ that transform HR to LR patches:\n\\begin{equation}\n\t\\patchlow{k} =  \\Sub_s^{loc}\\LPF_s^{loc}\\patchhigh{k} + \\mybold{v}_\\ell^k\n\t\\label{eq:DL_approach4}\n\\end{equation}  \nwhere $ \\mybold{v}_\\ell^k $ is a random noise of the same dimension as the LR patches. From equations \\ref{eq:DL_approach2} and \\ref{eq:DL_approach4}, one can write:\n\\begin{equation}\n\\begin{split}\n\t\\patchlow{k} &= \\Sub_s^{loc}\\LPF_s^{loc}\\dicthigh \\adictco^k + \\Sub_s^{loc}\\LPF_s^{loc}\\mybold{\\epsilon}^k + \\mybold{v}_\\ell^k \\\\\n\t\t\t\t &= \\Sub_s^{loc}\\LPF_s^{loc}\\dicthigh \\adictco^k + \\tilde{\\mybold{v}}_\\ell^k\n\\end{split}\n\\label{eq:DL_approach5}\t\n\\end{equation}\nwhere $ \\tilde{\\mybold{v}}_\\ell^k \\mydef \\Sub_s^{loc}\\LPF_s^{loc}\\mybold{\\epsilon}^k + \\mybold{v}_\\ell^k$ is also a random noise term. Denoting $ \\dictlow \\mydef \\Sub_s^{loc}\\LPF_s^{loc}\\dicthigh  $, the above equation illustrates that there exists also a Sparse-Land model for LR patches. These models for LR and HR patches also share the same sparse coefficient $ \\adictco^k $. The LR dictionary is also a downsampled version of the HR one.\n\n\\subsection{Joint learning methods}\n\\label{sec:joint_learning_methods}\nIn practice, $ \\Sub_s\\LPF_s $ or $ \\Sub_s^{loc}\\LPF_s^{loc} $ are usually not given. \\citet{yang2010image} has addressed this problem by proposing the approach to jointly learn coupled dictionaries. \\citet{zeyde2012single} follow the main idea with some modifications. All approaches contains two main steps: \\textit{learning phase} and \\textit{reconstruction phase}. The learning phase can be done \\textit{offline}, i.e. training \\textit{a priori} from the data. With learned dictionaries, the reconstruction phase can be \\textit{online}.\n\nGiven the training HR velocity fields $ \\z_t \\in \\R^{\\dimsh} $, corresponding LR fields are virtually extracted as $ \\y_t=\\Sub_s\\LPF_s\\z_t \\in \\R^{\\dimsl}$. Couples of LR and HR patches $ \\left\\lbrace  \\patchlow{k},\\patchhigh{k}  \\right\\rbrace $ are extracted from the training fields as $ \\patchlow{k}= \\extractlow{k} \\y_t\\in  \\R^\\dimpsl $ and $ \\patchhigh{k}= \\extracthigh{k} \\z_t\\in  \\R^\\dimpsh $, where $ \\dimpsl $ and $ \\dimpsh $ are the size of LR and HR patches respectively, and $ \\dimpsh/\\dimpsl = \\dimsh / \\dimsl $. Let $ \\mathbf{P}_\\ell $ and $ \\mathbf{P}_h $ denote matrices of all LR and HR patches:\n\\begin{equation}\n\t\\begin{split}\n\t\t\\mathbf{P}_\\ell&=\\left[\\patchlow{1} \\:\\: \\patchlow{2} \\:\\: ... \\:\\: \\patchlow{\\dimptl}\\right]_{\\dimpsl \\times \\dimptl} \\\\\n\t\t\\mathbf{P}_h&=\\left[\\mybold{p}_h^1 \\:\\: \\mybold{p}_h^2 \\:\\: ... \\:\\: \\mybold{p}_h^{\\dimptl}\\right]_{\\dimpsh \\times \\dimptl}\n\t\\end{split}\n\t\\label{eq:jointlearning1}\n\\end{equation}\nwhere $ \\dimptl $ is the total number of patches, and $ \\dimptl = \\left(\\sqrt{\\dimsl} - \\sqrt{\\dimpsl} + 1\\right)^2 \\times \\dimtl$ at most, where $ \\dimtl $ is the number of training planes. The LR patches are collected by one-pixel overlapping, while HR ones are obtained by overlapping $ \\dimpsh/\\dimpsl $ pixels to ensure the same number of LR and HR patches. Coupled dictionaries $ \\left\\lbrace \\dicthigh ,\\dictlow  \\right\\rbrace $ are learned from the coupled training patches $ \\left\\lbrace \\mathbf{P}_h ,\\mathbf{P}_\\ell  \\right\\rbrace $ imposing to share the same sparse representation:\n\\begin{equation}\n\\begin{cases}\n\t\\mathbf{P}_h \\approx \\dicthigh \\dictco\\\\\n\t\\mathbf{P}_\\ell \\approx \\dictlow \\dictco\\\\\n\\end{cases}\n\\end{equation}            \nThe first learning approach is proposed by \\cite{yang2010image}, which aims at solving an optimization problem:\n\\begin{equation}\n\\left\\lbrace \\dicthigh ,\\dictlow, \\dictco  \\right\\rbrace = \\argmin_{\\dicthigh ,\\dictlow ,A} \\left\\lbrace \\frac{1}{\\dimpsh} \\Vert \\mathbf{P}_h-\\dicthigh \\dictco\\Vert^2_2 + \\frac{1}{\\dimpsl} \\Vert \\mathbf{P}_\\ell-\\dictlow \\dictco\\Vert^2_2 + \\lambda_1 \\left( \\frac{1}{\\dimpsh}+\\frac{1}{\\dimpsl} \\right) \\Vert \\dictco \\Vert_1 \\right\\rbrace\n\\label{eq:jointlearning2}\n\\end{equation}\n$ \\dictco $ is the shared sparse coefficients, which ensures a compromise between small reconstruction errors of patches and sparsity constraint. The two normalization terms $ 1/\\dimpsl  $ and $ 1/\\dimpsh $ are to balance the two mean-square error terms. The above cost function can be re-written as:\n\\begin{equation}\n\\dict = \\argmin_{\\dict,\\dictco} \\left\\lbrace \\Vert \\mathbf{P}-\\dict \\dictco\\Vert^2_2 + \\lambda_1 \\Vert \\dictco \\Vert_1 \\right \\rbrace\n\\label{eq:jointlearning3}\n\\end{equation}\nwhere\n\\begin{equation}\n\\mathbf{P}= \\begin{bmatrix} \\frac{1}{\\sqrt{\\dimpsh}}\\mathbf{P}_h \\\\ \\frac{1}{\\sqrt{\\dimpsl}}\\mathbf{P}_\\ell \\end{bmatrix}, \\:\\: \\dict= \\begin{bmatrix} \\frac{1}{\\sqrt{\\dimpsh}}\\dicthigh  \\\\ \\frac{1}{\\sqrt{\\dimpsl}}\\dictlow  \\end{bmatrix}\n\\label{eq:jointlearning4}\n\\end{equation}\nThis problem can be solved using the standard DL algorithms.\n\nThe second approach is proposed by \\citet{zeyde2012single}, which contains a direct model to estimate the HR dictionary. The LR dictionary is first learned from LR patches:\n\\begin{equation}\n\\left\\lbrace \\dictlow ,\\dictco \\right\\rbrace =\\argmin_{\\dictlow, \\dictco}  \\left\\lbrace \\normtwo{\\mathbf{P}_\\ell-\\dictlow \\dictco} + \\lambda_1\\Vert \\dictco \\Vert_1 \\right \\rbrace\n\\label{eq:jointlearning5}\n\\end{equation}\nAssuming that the representation of HR patches $ \\mathbf{P}_h $ via the HR dictionary $ \\dicthigh  $ will share the same sparse code $ \\dictco $, HR dictionary is estimated as:\n\\begin{equation}\n\\dicthigh  = \\argmin_{\\dicthigh } \\left\\lbrace \\Vert \\mathbf{P}_h-\\dicthigh \\dictco\\Vert^2_2  \\right \\rbrace\n\\label{eq:jointlearning6}\n\\end{equation}\nfor which the solution is easy to obtain by a pseudo-inverse:\n\\begin{equation}\n\\dicthigh =\\mathbf{P}_h \\dictco^{\\dagger}=\\mathbf{P}_h\\dictco^{\\mytrans}(\\dictco\\dictco^{\\mytrans})^{-1}\n\\label{eq:jointlearning7}\n\\end{equation}\n\nAs originally proposed for image super-resolution where sharp edges are important, \\citet{yang2010image,yang2012coupled,zeyde2012single} use different pre-processing techniques before learning coupled dictionaries. Interpolated images $ \\Interp_s\\y_t $ of the same dimension as HR ones are considered as LR images. \\citet{yang2010image,yang2012coupled} couple HR patches, i.e. $ \\patchhigh{k}=\\extracthigh{k}\\z_t$,  with the derivatives of interpolated LR images $ \\varmathbb{F} \\Conv \\Interp_s\\y_t $. The operator $ \\Conv $ is the convolution operator. These derivatives are obtained from the convolution of four different 1D kernels $ \\varmathbb{F} $ of first and second order:\n\\begin{equation}\n\t\\left[ \\begin{matrix} -1 & 0 & 1 \\end{matrix} \\right] , \\:\\: \\left[ \\begin{matrix} -1 & 0 & 1 \\end{matrix} \\right]^{\\mytrans} , \\:\\: \\left[ \\begin{matrix} 1 & 0 & -2 & 0 & 1 \\end{matrix} \\right] , \\:\\: \\left[ \\begin{matrix} 1 & 0 & -2 & 0 & 1 \\end{matrix} \\right]^{\\mytrans}\n\\label{eq:jointlearning8}\n\\end{equation}\nLR patches are then extracted as $\\patchlow{k}= \\extracthigh{k}(\\varmathbb{F} \\Conv \\Interp_s\\y_t) $. \\citet{zeyde2012single} couples the same features $ \\varmathbb{F} \\Conv \\Interp_s\\y $, but with the residual between HR and interpolated images, i.e. $ \\patchhigh{k}=\\extracthigh{k}(\\z_t-\\Interp_s\\y_t) $. Moreover, the dimension is reduced using PCA, which corresponds to an adaptive low-pass filter. This step in practice is important, since applying the four filters to low resolution fields bring redundant and superfluous information and lead to unnecessary heavy computation. \n\n\\begin{table}\n\t\\caption{\\label{tab:DLapproaches}\n\tNotations for three different methods of coupled dictionaries learning as proposed by \\citet{yang2010image,zeyde2012single}. The dimension of LR and HR patches are $ \\dimpsl $ and $ \\dimpsh $ respectively.}\n\t\\vspace{.5cm}\n\t\\centering\n\t\\begin{tabular}{ccccccc} \n\t\t\\toprule \\multirow{2}{*}{Notation}&\\multicolumn{1}{c}{}&\\multicolumn{2}{c}{Patch extraction}&\\multicolumn{1}{c}{}&\\multicolumn{2}{c}{Patch dimension}\\\\\n\t\t\\cmidrule{3-4} \\cmidrule{6-7}\n\t & & {LR} & {HR} & & {LR} & {HR} \\\\\n\t\t\\midrule \n\t\tSR1  &&  $ \\extractlow{k} \\Sub_s\\LPF_s\\z_t $  & $ \\extractlow{k} \\z_t $ && $ \\dimpsl $ & $ \\dimpsh $\\\\\n\t\tSR2  &&  $ \\extractlow{k} \\Interp_s\\Sub_s\\LPF_s\\z_t $  & $ \\extractlow{k} \\z_t $ && $ \\dimpsh $ & $ \\dimpsh $\\\\\n\t\tSR3  &&  $ \\extractlow{k} \\extracthigh{k}(\\varmathbb{F} \\Conv \\Interp_s\\y_t) $  & $ \\extractlow{k} \\left\\lbrace \\z_t - \\Interp_s\\y_t\\right\\rbrace$ && $ 4\\dimpsh $ & $ \\dimpsh $ \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\nBased on the above works by \\citet{yang2010image,zeyde2012single}, we study three different approaches, namely ``\\textit{SR1}'',``\\textit{SR2}'' and ``\\textit{SR3}'', to learn coupled dictionaries. Descriptions of LR and HR patches with their sizes are summarized in table \\ref{tab:DLapproaches}. The dimension of LR patches when using derivatives is $ 4 \\dimpsh $; However in practice, it is reduced significantly via PCA while retaining $ 99.9 \\% $ of energy content.\n\n\\subsection{Reconstruction using learned dictionaries}\nHaving the coupled dictionaries at hand and given a LR field $ \\y^\\ext $, the objective is to reconstruct the HR $ \\z^\\ext $. The superscript ``$ \\ext $'' stands for ``\\textit{external}'', meaning outside of the training planes. First, all LR patches $ \\mathbf{P}^\\ext_\\ell$ are extracted from $ \\y^\\ext $ with the overlapping of one pixel. $ \\mathbf{P}^\\ext_\\ell$ is then centered by removing the mean of each patch $ m_l $. Next, the sparse code $ \\dictco $ are estimated by solving the regularized least-squares problem:\n\\begin{equation}\n\\dictco^\\ext =\\argmin_{\\dictco^\\ext} \\left\\lbrace \\Vert \\mathbf{P}_\\ell-\\dictlow \\dictco^\\ext\\Vert^2_2 + \\lambda_2 \\Vert \\dictco^\\ext \\Vert_1 \\right\\rbrace \n\\label{eq:DLrec1}\n\\end{equation}\nHR patches are estimated using this shared code and putting back the mean $ m_l $:\n\\begin{equation}\n\\hat{\\mathbf{P}}^\\ext_h = \\sqrt{\\frac{\\dimpsh}{\\dimpsl}} \\dicthigh \\dictco^\\ext + m_l\n\\label{eq:DLrec2}\n\\end{equation}\nFinally, the HR field is reconstructed by solving an optimization problem:\n\\begin{equation}\n\\hat{\\z}^\\ext = \\argmin_{\\z^\\ext} \\left\\lbrace\\sum\\limits_{k} \\Arrowvert \\extracthigh{k}\\hat{\\z}^\\ext- \\hat{\\mybold{p}}_h^k\\Arrowvert^2_2 \\right\\rbrace\n\\label{eq:DLrec3}\n\\end{equation}\nThis problem aims to find the best compromise between all estimates, and the closed-form least-squares solution is:\n\\begin{equation}\n\\hat{\\z}^\\ext= \\left[ \\sum\\limits_{k} \\left(\\extracthigh{k}\\right)^{\\mytrans}\\extracthigh{k}\\right]^{-1}\\sum\\limits_{k} \\left(\\extracthigh{k}\\right)^{\\mytrans}\\hat{\\mybold{p}}_h^k\n\\label{eq:DLrec4}\n\\end{equation}\nThis is the overlapping procedure as discussed in section \\ref{subsec:patch_based_estimation}. A pseudo algorithm of the whole process including the learning and reconstruction phases is summarized in algorithm \\ref{algo_SR}.\n\n\\begin{algorithm}\n\\caption{Coupled dictionary learning for reconstruction of high-resolution fields from low-resolution ones} \\label{algo_SR}\n\\begin{algorithmic}[1]\n\t\\State \\textbf{Input}:\n\t\\begin{itemize}\n\t\t\\item training high-resolution fields $ \\left\\lbrace \\z_t \\right\\rbrace, t=1,2,...,\\dimtl$\n\t\t\\item testing low-resolution field $ \\y^\\ext $\n\t\\end{itemize}\n\t\\State \\textbf{Step 1}: \\textit{Learning phase} (offline)\n\t\\begin{itemize}\n\t\t\\item Extract virtual low-resolution fields the same way as $ \\y^\\ext $ is recorded: \n\t\t\\begin{equation}\n\t\t\t\\label{eq:algo_SR_1}\n\t\t\t\\y_t \\mydef \\Sub_s\\LPF_s\\z_t + \\mybold{v}_t\n\t\t\\end{equation}\n\t\t\\item Extract and join coupled patches $ \\left\\lbrace \\mathbf{P}_l,\\mathbf{P}_h \\right\\rbrace $ from the fields $ \\left\\lbrace \\y_t, \\z_t \\right\\rbrace, t=1,2,...,\\dimtl $:\n\t\t\\begin{equation}\n\t\t\t\\label{eq:algo_SR_2}\t\t\n\t\t\t\\mathbf{P} \\mydef \\left[ \\frac{1}{\\sqrt{\\dimpsh}}\\mathbf{P}_h ; \\frac{1}{\\sqrt{\\dimpsl}}\\mathbf{P}_\\ell \\right]\n\t\t\\end{equation}\n\t\t\\item Learn the joint dictionary $ \\dict \\mydef \\left[\\frac{1}{\\sqrt{\\dimpsh}}\\dicthigh; \\frac{1}{\\sqrt{\\dimpsl}}\\dictlow \\right] $ as:\n\t\t\\begin{equation}\n\t\t\t\\label{eq:algo_SR_3}\t\t\n\t\t\t\\left(\\dict, \\dictco\\right) = \\argmin_{\\dict,\\dictco} \\left\\lbrace \\Vert \\mathbf{P}-\\dict \\dictco\\Vert^2_2 + \\lambda_1 \\Vert \\dictco \\Vert_1 \\right\\rbrace\n\t\t\\end{equation}\n\t\\end{itemize}\t\n\t\\State \\textbf{Step 2}: \\textit{Reconstruction phase} (online)\n\t\\begin{itemize}\n\t\t\\item Extract LR patches: $ \\mathbf{P}_\\ell ^\\ext \\in \\R^{\\dimpsl \\times \\dimptl}$ from $ \\y^\\ext $\n\t\t\\item Estimate the sparse code:\n\t\t\\begin{equation}\n\t\t\t\\label{eq:algo_SR_4}\t\t\n\t\t\t\\dictco^\\ext = \\argmin_{\\dictco^\\ext} \\left\\lbrace \\Vert \\mathbf{P}_\\ell^\\ext-\\dictlow \\dictco^\\ext\\Vert^2_2 + \\lambda_2 \\Vert \\dictco^\\ext \\Vert_1 \\right\\rbrace \n\t\t\\end{equation}\n\t\t\\item Reconstruct HR patches $ \\hat{\\mathbf{P}}_h^\\ext = \\dicthigh\\dictco^\\ext  \\in \\R^{\\dimpsh \\times \\dimptl} $\n\t\\end{itemize}\n\t\\State \\textbf{Output:} Reconstruct HR field $ \\z^\\ext $ from $  \\hat{\\mathbf{P}}_h^\\ext  $ by overlapping.\n\\end{algorithmic}\n\\end{algorithm}\n \n\\section{Dictionary learning for isotropic turbulence fields}\nThe section applies dictionary learning approach to the DNS database of the isotropic turbulence discussed in chapter \\ref{sec:data_isotropic}. This data is chosen because the fields are periodic, isotropic and homogeneous. These properties will facilitate all computations and the handling of boundary conditions. Two main problems are addressed. First, the efficiency of the representation using dictionary learning will be studied, comparing with other approaches such as wavelet transform or PCA. Second, the coupled dictionaries approach is discussed to solve the problem of reconstructing HR velocity fields from LR measurements. \n\nTo compare with other approaches, we consider a similar configuration as in chapter \\ref{chap_linearregression} to study regression models. The reference HTHS data is subsampled to obtain the measurements of HTLS $ \\{\\y_t\\} $ and LTHS $ \\{\\x_t\\} $ (see figure \\ref{fig:space-time_measurements}). The subsampling ratios are $ \\dimsh/\\dimsl = 4 \\times 4$ in space and $ \\dimth/\\dimtl = 6 $ in time, corresponding to a moderate amount of energy losses in every directions. We will use $ \\{\\x_t\\} $ only for the training, then uses $ \\{\\y_t\\} $ to predict $ \\{\\z_t\\} $.\n\n\\subsection{On the choice of parameters}\n\\label{subsec:DL_choice_params}\n\\begin{table} \n\t\\caption{\\label{tab:DLparams}\n\tSet of parameters for coupled dictionaries approach (notations are consistent with Algorithm \\ref{algo_SR}): sparsity constrains $ \\lambda_1 $ for learning and $ \\lambda_2 $ for reconstruction; dimension of LR patches $ \\dimpsl $ and HR patches $ \\dimpsh $; number of atoms $ \\dimdict $; number of training patches $ \\dimptl $ }\n\t\\vspace{.5cm}\n\t\\centering\n\t\\begin{tabular}{cccccc} \n\t\t\\toprule\n\t\t{$\\lambda_1$} & {$\\lambda_2$} & {$\\sqrt{\\dimpsl}$} & {$\\sqrt{\\dimpsh}$} & {$\\dimdict$} & {$ \\dimptl $} \\\\ \n\t\t\\midrule \n\t\t$ 0.1 \\sim 0.2 $  &  $ 10^{-5} $  & 4  & 16 & $ 2(\\dimpsl \\times \\dimpsh) $ & $~ 10^5 $ \\\\ %\\addlinespace\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\nResults in the following sections are obtained with a consistent set of parameters presented in table \\ref{tab:DLparams}. Notations are consistent with the algorithm \\ref{algo_SR} to learn coupled dictionaries. This section briefly discusses these choices.\n\nThe first set of parameters are sparsity constraints $ \\lambda_1 $ and $ \\lambda_2 $. For the learning phase, $ \\lambda_1 $ is about $ 0.1 \\sim 0.2 $ to learn either the coupled dictionaries in equation \\ref{eq:jointlearning2} or the LR dictionary in equation \\ref{eq:jointlearning5}. This constraint imposes that the reconstruction of training patches uses only $ 10\\sim15 $ nonzero coefficients in average, corresponding to the sparsity level of $ 0.90\\sim0.95 $ (only $ 5 \\sim 10\\% $ coefficients are nonzero). As will be seen latter in figure \\ref{fig:Sparsity_vs_NRMSE}, this is a strong constraint. However, decreasing $ \\lambda_1 $, i.e. reducing the sparsity level, downgrades reconstruction results of coupled dictionaries. This is probably the \\textit{overfitting} problem discussed in chapter \\ref{chap_linearregression}. With small $ \\lambda_1 $, the dictionaries represent well the training data but with a poor generalization capability. For reconstruction phase, $ \\lambda_2 $ is chosen to be close to zero. In such case, the sparsity level of $ \\dictco^\\ext $ in equation \\ref{eq:algo_SR_4} is very low, i.e. the maximum number of atoms is used to reconstruct $ \\mathbf{P}^\\ext_\\ell $.\n\nThe second set of parameters are to describe the training patches. The sizes of the LR and HR patches are $ \\dimpsl = 4 \\times 4 $ and $ \\dimpsh = 16 \\times 16 $, respectively. The LR patch size is small compared to the whole LR field of size $ \\dimsl = 16 \\times 16 $, permitting to localize the information. Numerical experiments show a slight improvement when increasing this size, but it leads to a high computation requirements and a large number of training planes. Coupled patches are extracted from $ 37 \\times 16 $ LTHS planes for training. From each snapshot, a total of $ (16-4+1) \\times (16-4+1) =169$ LR patches can be extracted using one-pixel overlapping. The same number of corresponding HR patches are also extracted from HR training fields. Around $ m=10^5 $ couples of LR-HR patches are chosen randomly from the whole set of $ 37 \\times 16 \\times 169 $ patches in total and used to train the coupled dictionaries. The objective is to reduce the computational cost, since many patches are very similar. \n\nThe last parameter is the number of atoms. There is no general rule, but new findings using non-parametric approaches of learning dictionaries with an adaptive number of atoms \\citep{dang2016towards} show that the needed level of redundancy maybe not very high. Numerical experiments in this work show that a good size is about two times the dimension of input variables. For the case of coupled dictionary learning, the choice is $ K = 2(\\dimpsh+\\dimpsl) $, where $ (\\dimpsh+\\dimpsl) $ is the dimension of the coupled LR and HR patches.\n\n\\subsection{Efficiency of representations: a comparative study} \nSince the sparsity may play a key role, this section compares the efficiency of different representations. ``\\textit{Efficiency}'' means the quality of the approximation with respect to different sparsity levels. Mathematical predefined representation using wavelets, learned bases using PCA and dictionary learning methods are compared. Both KSVD \\citep{aharon2006ksvd} and ODL \\citep{mairal2010online} are investigated. The representations are learned from the LTHS planes $ \\left\\lbrace \\x_t \\right\\rbrace $ in the cases of PCA and DL. These representations are then tested on random subsampled fields from HTHS planes $ \\z_t $ that are different from the set of $ \\{\\x_t\\} $ used for learning. Reconstruction errors are estimated by comparing with reference fields. \n\n\\begin{figure}[t]\n\\centering\n\t\\includegraphics[width=0.45\\textwidth]{./images/DL/DLstat/PCA_patchsize04.eps}\n\t\\includegraphics[width=0.45\\textwidth]{./images/DL/DLstat/D_HR_lambda005.eps}\n\t\\caption{\\label{fig:PODvsDL} Dictionaries leaned by PCA and ODL from the set of HR patches of size $ \\dimpsh = 16 \\times 16 $. With ODL, only 256 atoms are chosen from 512 atoms.}\n\\end{figure}\n\nFigure \\ref{fig:PODvsDL} shows the adaptive dictionaries learned by PCA (left) and ODL (right) as ranked by their energy contents. The redundant dictionary by ODL has two times more atoms compared to PCA, which contains exactly $ \\dimpsh = 16 \\times 16 $ atoms as the dimension of the input patches. Only 256 over 512 atoms obtained by ODL are shown to be comparable with the PCA dictionary. The atoms are completely different in the two dictionaries. PCA dictionary has a sharp decline of variance content. Also, since the number of training patches is sufficiently large, the atoms look similar to discrete cosine transform (DCT) basis functions, which have modulated sine-wave patterns. The redundant dictionary from ODL contains more ``patterns'' for each level of scale, which is expected to be more adaptive to the data for sparse representation. \n\nUsing a wavelet transform, there is no learning since the bases are predefined. The fields are decomposed into approximation and detail coefficients (horizontal, vertical and diagonal). The common Daubechies wavelet is used for its compact support and fast computation. The transform is performed on full fields. To test the sparsity effects, different thresholds are used. Detail coefficients larger than each threshold are retained while setting others to zeros, while approximation coefficients are kept unchanged. Inverse wavelet transform reconstructs the fields using these unchanged approximation and filtered detail coefficients. The sparsity is defined as the ratio of nonzero coefficients $ \\dimtrunc $ (including both approximation and retained detail coefficients after filtering) and the dimension of the field $ \\dimsh $. The NRMSE between reconstructed fields $ \\hat{\\z}_t $ and reference ones $ \\z_t $ is estimated as in equation \\ref{eq:NRMSE} to qualify the reconstruction for each level of sparsity $ (1- \\dimtrunc/\\dimsh )$.\n\nWith PCA, the dictionary $ \\dict $ is learned from training patches $ \\mathbf{P}_h $ extracted from all $ \\left\\lbrace \\x_t \\right\\rbrace, t=1,...,\\dimtl $. Its atoms  $ \\left\\lbrace \\adicthigh{i} \\right\\rbrace $ are ranked by their variances $ \\lambda_i $, i.e. $ \\lambda_1 > \\lambda_2 > ... > \\lambda_{\\dimsh} $. The dimensionality is reduced such that the retained information from only the first $ \\dimtrunc $ principal components ($ \\dimtrunc < \\dimpsh $) is maximized. For a new field $ \\z_t $, $ \\mathbf{P}_h $ are extracted and projected onto the first $ \\dimtrunc $ vectors:\n\\begin{equation}\n\t\\adictco_i = \\frac{\\mathbf{P}_h \\mydot  \\adicthigh{i}}{\\normtwo{\\adicthigh{i}}} \\:, i=1,2,...,\\dimtrunc\n\t\\label{eq:DL_efficiency3}\t\n\\end{equation}\nThe filtered patches are estimated by combining the projected coefficients with the corresponding functions:\n\\begin{equation}\n\t\\hat{\\mathbf{P}}_h = \\sum\\limits_{i=1}^{\\dimtrunc} {\\adictco_i \\adicthigh{i}}\n\t\\label{eq:DL_efficiency4}\n\\end{equation}\nFinally, the reconstructed field $ \\hat{\\z}_t $ is estimated by one-pixel overlapping as discussed in section \\ref{subsec:patch_based_estimation}. The sparsity level is defined as $ 1-\\dimtrunc/\\dimpsh $, where the patch size at HR is $ \\dimpsh = 16 \\times 16 $. NRMSEs are estimated using equation \\ref{eq:NRMSE}. \n\nKSVD and ODL learn $ \\dict $ from $ \\mathbf{P}_h $ \\textit{a priori} with a high sparsity level ($ \\lambda =0.2$, corresponding to about $ 15 $ non-zero coefficients). In the reconstruction step, all possible patches $ \\mathbf{P}_h $ are extracted from each field $ \\z_t $. The sparse code is estimated using LARS algorithm to solve:\n\\begin{equation}\n\t\\dictco = \\argmin_{\\dictco} \\left\\lbrace \\normtwo{\\mathbf{P}_h - \\dict \\dictco_t} + \\lambda \\normone{\\dictco} \\right\\rbrace\n\t\\label{eq:DL_efficiency2}\t\n\\end{equation}\nThe efficiency of the learned dictionary $ \\dict $ is studied by varying $ \\lambda $ in this step. For each $ \\lambda $, $ \\dictco $ is estimated and then used to re-estimate the patches $ \\hat{\\mathbf{P}}_h = \\dict \\dictco$ before reconstructing the global scene $ \\hat{\\z}_t $. Sparsity is measured as the average of $ 1- \\normzero{\\adictco_t}/\\dimpsh $, where $ \\adictco_t $ is the $ t- $th row of $ \\dictco $. NRMSEs are estimated the same way as of wavelet transform or PCA.\n\n\\begin{figure}[t]\n\\centering\n\t\\includegraphics[width=\\textwidth]{./images/DL/DLstat/Sparsity_vs_NRMSE_PCA_ODL_KSVD_WL_Dau_patchsize04.eps}\n\t\\caption{\\label{fig:Sparsity_vs_NRMSE} Sparsity vs error outside (left) and zoom in the region of low sparsity at semi-log scale (right) for different representations: wavelet (Daubechies), PCA, dictionary learning (ODL or KSVD). Wavelet transform is for the whole fields of size $ 96 \\times 96$, while PCA and DL are for patches of size $ \\dimpsh = 16 \\times 16 $.}\n\\end{figure}\n\nFigure \\ref{fig:Sparsity_vs_NRMSE} shows the curves of NRMSE as functions of sparsity levels. These errors are estimated from five testing planes equally far from neighboring LTHS snapshots. All curves behave similarly as reducing the error when sparsity decreases. At high levels (larger than 0.5), there is a clear benefit of using DL. With the same number of non-zero coefficients, both ODL and KSVD give lower errors than PCA and wavelet transform. Few atoms from DL better represent the data than high variance principal components of PCA or predefined ones. Comparing the two DL methods, ODL is better than KSVD. When using more non-zero coefficients, errors by DL methods saturate at nonzero values. Since DL provides only an approximate solution. Wavelet transform and PCA give zero NRMSEs when using all coefficients because the transforms are exact.\n\nThe above comparisons demonstrate the advantages of representations using learned dictionaries over predefined ones. Comparing redundant and orthogonal representations, i.e. DL versus PCA, redundant dictionaries represent the fields more efficiently. They achieve the same level of error using less atoms. This suggests also that the sparsity and redundancy priors can be good candidates to help solving the ill-posed inverse problem of reconstructing HR fields from LR ones. Comparing the two common DL methods, ODL shows clear advantages both in term of efficient representation and computation effort and will be used in the rest of this chapter. \n \t\n\\subsection{Reconstruction of high resolution fields- subsampling cases}\nTo compare to other methods, LR fields are first subsampled from HR ones by a factor of $ 4 \\times 4 $, i.e. $ \\y_t = \\Sub_s \\z_t $, where $ \\Sub_s: \\R^\\dimsh \\mapsto \\R^\\dimsl $, $ \\dimsh/\\dimsl = 4 \\times 4 $. Coupled LR and HR patches are extracted to train the dictionaries. Due to direct subsampling, the aliasing, which has not been addressed in previous works, will play an important role. This section investigates the ability of dictionary learning approaches to handle this aliasing problem.\n\n\\subsubsection*{Learning step}\n\\begin{figure}[t]\n\\centering\n\t\\includegraphics[width=\\textwidth]{./images/DL/SR_sspacing04/subsampling/coupleddictionary_HRLR_lambda010.eps}\n\t\\caption{\\label{fig:D_HR_LR} Coupled dictionary of high and low resolution patches, with LR patches are of size $ 4\\times 4 $, directly subsampled from their equivalent HR patches of size $ 16 \\times 16 $. The regularization parameter $ \\lambda $ for join learning are chosen such that about 16 non-zero coefficients are retained for reconstructing the joint patches of the training.}\n\\end{figure}\n\n\\begin{figure}[t]\n\\centering\n\t\\includegraphics[width=\\textwidth]{./images/DL/SR_sspacing04/subsampling/coupleddictionary_HRHRinterp_lambda010.eps}\n\t\\caption{\\label{fig:D_HR_HRinterp} Coupled dictionary of high and low resolution patches, where LR patches are of size $ 4\\times 4 $, directly subsampled from their equivalent HR patches of size $ 16 \\times 16 $. The regularization parameter $ \\lambda $ for join learning are chosen such that about 16 non-zero coefficients are retained for reconstructing the joint patches of the training.}\n\\end{figure}\n\nODL \\citep{mairal2010online} is used to learn a joint dictionary of HR and LR from the LTHS planes. The subsampling ratio in space is $ \\dimsh/\\dimsl = 4 \\times 4 $, while the training samples are taken every $ \\dimth/\\dimtl = 6 $ snapshots in streamwise direction. From a total of $ 37 \\times 16 $ training planes, small patches of size $ 4 \\times 4 $ at LR are extracted via the extraction operator $ \\extractlow{k} $, coupled with HR patches of size $ 16 \\times 16 $ by $ \\extracthigh{k} $. The choice of parameters is discussed in section \\ref{subsec:DL_choice_params}.\n\nThree approaches \\textit{SR1}, \\textit{SR2} and \\textit{SR3} (table \\ref{tab:DLapproaches}) are investigated. The interpolation step in \\textit{SR2} plays only the role of transforming the field from LR to the same dimension as the HR one. The content should be rather the same, since the interpolation does not introduce any small-scale information. However, starting from the interpolated fields can bring the benefit of having a good large-scale information \\textit{a priori}. The model will focus on small scales only. This approach have shown to be beneficial in many image processing problems.\n\nFigure \\ref{fig:D_HR_LR} shows dictionaries for HR and LR patches and figure \\ref{fig:D_HR_HRinterp} shows dictionaries for HR and interpolated LR patches. In both figures, atoms are sorted according to their variances $ \\normtwo{\\adictco_i} $ when learning the dictionary (from the top-left). The most significant atoms contain mostly large scales, while less significant ones represent high-frequency contents. Coupled atoms show similar patterns. The relation between LR and HR patches are now encoded in the relation between LR and HR dictionaries. The assumption of coupled representations in this case also implies that LR atoms are approximately subsampled from the HR ones as shown in equation \\ref{eq:DL_approach5}. \n\n\\subsubsection*{Reconstruction step}\nHaving learned dictionaries $ \\{\\dicthigh,\\dictlow \\} $ at hand, from given $ \\y^\\ext $ different from the training data, the HR field $ \\z^\\ext $ is reconstructed by using algorithm \\ref{algo_SR}. $ \\y^\\ext $ is also assumed to be directly subsampled from $ \\z^\\ext $ the same way as in the training data, i.e. $ \\y^\\ext = \\Sub_s \\z^\\ext $. From $ \\y^\\ext $, all LR patches $ \\mathbf{P}_l^\\ext $ with one-pixel overlapping are extracted. The sparse code is estimated by solving the optimization problem in equation \\ref{eq:algo_SR_4}. $ \\dictco^\\ext $ is then used to reconstruct HR patches as $ \\hat{\\mathbf{P}}_h^\\ext = \\dicthigh \\dictco^\\ext $ and put back into the global scene of $ \\hat{\\z}^\\ext $. \n\nLR and HR patches of sizes $ \\dimpsl = 4 \\times 4 $ and $ \\dimpsh = 16 \\times 16$ respectively are extracted from all training planes. The sparse code $ \\dictco^\\ext $ is estimated from LR patches. Each row has at most $ \\normzero{\\dictco^\\ext} = \\dimpsl = 16 $ nonzero coefficients. It means that HR patches are reconstructed from maximum $ 16 $ atoms within $ \\dicthigh $, a strong constraint on the reconstruction accuracy (see figure \\ref{fig:Sparsity_vs_NRMSE}). The nature of the data also affects the accuracy in the sense how good is the Sparse-Land prior. Also, this constraint addresses the problem of designing more efficient representations of the data to reduce the error when using the same number of atoms. \n\nUsing all three approaches presented in table \\ref{tab:DLapproaches}, the models can reconstruct the fields in the same accuracy as the spline interpolation but not better. This is due to the severe situation where the presence of aliasing makes equation \\ref{eq:DL_approach5} a very crude assumption. The subsampling of a small atoms brings a very strong aliasing effect that coupled dictionaries could not efficiently handle. The next section will study the capability of the present approach when the aliasing problem is absent from the LR data.\n\n\\subsection{Reconstruction of high resolution fields- the downsampling case}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{./images/DL/SR_sspacing04/downsampling/dictionary_couplefeatures_patchesHR.eps}\n\t\\caption{Dictionary of the residual between HR and interpolated LR.}\n\t\\label{fig:SR_dictionary_residual}\n\\end{figure}\n\nThis section investigates the possibility of the current approach to estimate the HR fields given the LR ones in the case of downsampling, i.e. with anti-aliasing prefiltering:\n\\begin{equation}\n\\y_t = \\Sub_s \\LPF_s \\z_t\n\\end{equation}\nwhere $ \\Sub_s $ and $ \\LPF_s $ are the spatial subsampling and low pass filter respectively. Bicubic filter in Matlab built-in function \\textit{imresize} is used for the prefiltering and interpolation step. It was shown also in section \\ref{sec:chap3_theapproach} that the assumptions Sparse-Land model at HR also lead to the relation $ \\mathbf{P}_\\ell =  \\Sub_s^\\ext \\LPF_s^\\ext \\mathbf{P}_h$ between LR and HR dictionaries. $ \\Sub_s^\\ext $ and $ \\LPF_s^\\ext $ are local versions of $ \\Sub_s $ and $ \\LPF_s $ applying to patches. \n\nWe compare the three methods of coupled dictionary learning, the so-called \\textit{SR1}, \\textit{SR2} or \\textit{SR3}, presented in table \\ref{tab:DLapproaches}. To recall \\textit{SR1} and \\textit{SR2} couple either LR or interpolated LR patches with HR ones, while \\textit{SR3} couples the residuals with the features of derivatives. The procedure follows the previous section of subsampled fields, with learning parameters in table \\ref{tab:DLparams}. HR patches $ \\mathbf{P}_h$ are extracted from LTHS fields and coupled with LR patches $ \\mathbf{P}_\\ell$. The dictionaries are trained \\textit{offline} from $ \\{\\mathbf{P}_h, \\mathbf{P}_\\ell\\}$, and used in \\textit{online} reconstruction stage for all HTLS measurements to reconstruct HTHS fields. \n\nWe use three quantities for comparisons: the average NRMSE between reconstructed and reference velocity fields estimated using equation \\ref{eq:NRMSE}, the 2D energy spectra of the velocity fields and of the errors. These three quantities give a complete view to qualify different approaches. Only the most difficult planes, which are equally far from LTHS measurements, are used to estimate the errors. Error estimated using these planes will better represent the generalization capability of the approaches.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{./images/DL/SR_sspacing04/downsampling/NRMSE_compare_all_spacespacing_04.eps}\n\t\\caption{Means and standard deviations of NRMSEs estimated between reference and reconstructed fields of all middle planes (at the center of blocks bounded by the two LTHS planes). The reconstructions are by spline interpolation and super-resolution using three different methods:: \\textit{SR1}, \\textit{SR2} and \\textit{SR3} (see table \\ref{tab:DLapproaches}). NRMSEs are $ 0.267 \\pm 0.021 $, $ 0.235 \\pm 0.019 $, $ 0.233 \\pm 0.018 $ and $ 0.230 \\pm 0.019 $ respectively. The NRSME of spline interpolation in the equivalent subsampling case is 0.276 (dashed black line).}\n\t\\label{fig:NRMSE_compare_all_spacespacing_04}\n\\end{figure}\n\nFigure \\ref{fig:NRMSE_compare_all_spacespacing_04} shows the average NRMSEs of different reconstructions, either interpolation or reconstruction by coupled dictionaries using \\textit{SR1}, \\textit{SR2} or \\textit{SR3} approaches. The three DL models reduce NRMSEs by $ 11.99 \\% $, $ 12.73 \\% $ and $ 13.86 \\% $ respectively compared to the simple interpolation. \\textit{SR3} gives the most accurate reconstructions by coupling the residuals, essentially contain only small scales, with derivatives of large-scale structures.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.75\\textwidth]{./images/DL/SR_sspacing04/downsampling/spectra2d_spacespacing_04.eps}\n\t\\caption{2D spectra of all planes used to computed the NRMSEs in figure \\ref{fig:NRMSE_compare_all_spacespacing_04}, from reference, interpolation and SR by three different methods: \\textit{SR1}, \\textit{SR2} and \\textit{SR3} (see table \\ref{tab:DLapproaches}). For scales from $ 0.5k_c $ to $ 1.5 k_c$, energy losses of SR fields compared to reference ones is $ 24\\% $, $ 22\\% $ and $ 21\\% $ respectively, while that of interpolation is $85 \\% $.}\n\t\\label{fig:spectra2d_spacespacing_04}\n\\end{figure}\n\nTo further understand the quality of the reconstructed fields at different scales, figure \\ref{fig:spectra2d_spacespacing_04} shows the 2D spectra of reference fields and different reconstructed ones. All methods capture good large scales till about $ 0.5 k_c $, where $ k_c $ is the cutoff wave number defined by the subsampling ratio. The interpolation, starting from the downsampled fields with prefiltering step to avoid aliasing, loses already energy at large scales and capture almost no small scales. By coupling the dictionaries, the reconstructed fields recover the large-scale information with some small scales. If considering only the scales between $ 0.5k_c $ and $ 1.5k_c $, the energy loss of interpolated fields is $ 85\\% $, while those are $ 24\\% $, $ 22\\% $ and $ 21\\% $  for \\textit{SR1}, \\textit{SR2} and \\textit{SR3} respectively. The benefit of SR is significant in this most interesting range of scales. Larger than $ 1.5k_c $, all reconstructions are not reliable. Smaller than $ 0.5 k_c $, spectra of all reconstructed fields are already very accurate. \n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\textwidth]{./images/DL/SR_sspacing04/downsampling/errspectra2d_nonnormalized_normalized_timespacing_06_spacespacing_04.eps}\n\t\\caption{(Left) 2D spectra of errors, which are the different between the reference and reconstruction by interpolation and three different SR methods as described in \\ref{sec:joint_learning_methods}. (Right) 2D spectra of errors normalized by the energy spectrum of the reference (the black curve in figure \\ref{fig:spectra2d_spacespacing_04}).}\n\t\\label{fig:errspectra2d_nonnormalized_normalized_timespacing_06_spacespacing_04}\n\\end{figure}\n\nFigure \\ref{fig:errspectra2d_nonnormalized_normalized_timespacing_06_spacespacing_04} (left) shows the spectra of the errors, which are the differences between the reference and reconstructed fields by all methods. Errors are very low at small wave numbers, reach a maximum around $ k_c $ and reduce at higher wave numbers. Integrals of these curves give the mean-square errors of each reconstruction method. To better qualify the error at each scale, the curves are normalized by the energy spectrum of the reference (the black curve in Figure \\ref{fig:spectra2d_spacespacing_04}). The normalized spectra of errors are interpreted as the percentage of error at each scale. The interpolation gives very small relative errors at large scales, but grow rapidly near $ k_c $. Error spectra of all SR methods collapse at $ 0.5k_c $ and reach a maximum of $ 100 \\% $ error at around $ 1.5k_c $. Smaller than $ 0.5k_c $, \\textit{SR1} and \\textit{SR2} gives slightly higher errors compared to \\textit{SR3}. \\textit{SR3} is more accurate since it starts from the interpolated large scales, while those information are re-estimated by \\textit{SR1} and \\textit{SR2}. Also, \\textit{SR3} focuses more on the missing information of small scales by using derivatives as features and following the patterns of larger ones. \n\nFrom the above comparisons, coupled dictionary approaches demonstrate clear benefits compared to the simple interpolation, with errors reduced by about $ 15\\% $. From the energy spectra or spectra of errors, the benefits mostly come from the range of scales between $ 0.5k_c $ and $ 1.5k_c $, where $ k_c $ is the cutoff defined by the grid of LR measurements. The loss of energy in this range is reduced from $ 80\\% $ with interpolation to $ 20\\% $ by DL approaches. The spectra of the errors also show that most of benefits come from this range of scales, before reaching $ 100\\% $ at around $ 1.5k_c $.\n\n\\section{Concluding remarks}\nThis chapter has discussed the possibilities of applying dictionary learning, a successful approach in the field of signal and image processing, to turbulence studies. The method finds a representation for the data by generalizing principal component analysis to sparse representation in a redundant dictionary. \\textit{Redundancy} means that the number of atoms can be larger than the dimension of input vectors, ignoring the orthogonality constraint of PCA. This implies the \\textit{sparsity}, i.e. the representation is composed by a linear combination of only a few atoms. These properties make the learned dictionary a more adaptive representation of the data. Sparsity can also play the role of a prior about the system when solving the inverse problem of HR field reconstruction. \n\nTo investigate the efficiency of DL in representing the data, the learned dictionaries by this approach have been compared against PCA and predefined wavelet dictionaries. Reconstruction errors as functions of sparsity, i.e. the number of atoms used, are shown as the measure of efficiency. Adaptive dictionaries show some superiority compared to the predefined ones. The benefits are mainly from the high sparsity levels, when less than half the number of coefficients are non-zero. \n\nDL is then used to reconstruct HR velocity fields from LR measurements. The approach is called \\textit{coupled dictionary learning}, inspired from the single image super-resolution application \\citet{yang2010image,zeyde2012single}. By learning coupled representations of LR and HR fields from the data, a nonlinear relation is established and generalized to perform the reconstruction task. With the same idea, different preprocessing techniques are tested. The coupling can be between HR and LR fields or their interpolation. Another approach focuses more on the small-scale information by coupling the small scales with the derivatives of interpolated fields. \n\nThe first attempt is for the configuration where LR fields are directly subsampled from HR ones without any anti-aliasing prefiltering step. This is \\textit{a priori} not a favorable case due to the presence of aliasing terms. However, it is worth studying since this setup mimics what would happen in a real experiment. It is interesting also to see how well learned dictionaries can handle aliasing. Results show that DL is inoperative to recover some small scales on top of the interpolated large-scale information. \n\nTo understand whether the failure comes from the approach or from the aliasing, another case is investigated where LR fields are downsampled from the HR ones with a prefiltering step. The same approach with  identical parameters is used. Results show significant improvements of reconstruction accuracy, with about $ 15 \\% $ reduction of NRMSEs compared to interpolation. Spectral analyses also show that most benefits are at the frequency range of $ 0.5 k_c$ to $ 1.5k_c $, where $ k_c $ is the cutoff wave number corresponding to the downsampling ratio. In term of energy, simple interpolation loses $ 85 \\% $ in this range scales, while this loss is reduced to about $ 20 \\% $ with DL approaches.\n\nThe above results demonstrate the capability and limitations of DL approaches in solving the reconstruction problem in turbulence. The corresponding prior, which is the duality between sparsity and redundancy, is robust. The first attempt has not succeeded to reconstruct HR fields from direct subsampled LR ones due to the aliasing problem. This attempt addresses also the question on designing a good sensing system or post-processing techniques to deal with aliasing terms if exist.\n\nThis chapter has presented a similar configuration as regression models to learn the mapping function between large and small scales. However, the learning is localized thanks to the patch-wise approach. This property of dictionary learning approach can be beneficial when applying to other configurations where the training and testing samples are of different scenes. For example, the training HR fields could be a small region of the whole field, while LR one can be larger. In such case, dictionary approach is the only candidate among all methods presented in this thesis. \n\n\n", "meta": {"hexsha": "0a4268e84adf3a0d8bd7575c8a0828d991e40639", "size": 70924, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/manuscripts/final_ver1/corps/dictionarylearning.tex", "max_stars_repo_name": "linhvannguyen/PhDworks", "max_stars_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-01T14:41:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T07:08:06.000Z", "max_issues_repo_path": "thesis/manuscripts/final_ver1/corps/dictionarylearning.tex", "max_issues_repo_name": "vanlinhnguyen/PhDworks", "max_issues_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_issues_repo_licenses": ["MIT"], "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/manuscripts/final_ver1/corps/dictionarylearning.tex", "max_forks_repo_name": "vanlinhnguyen/PhDworks", "max_forks_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_forks_repo_licenses": ["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.7945205479, "max_line_length": 1536, "alphanum_fraction": 0.7657492527, "num_tokens": 19026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.616709559324155}}
{"text": "\\Lecture{Jayalal Sarma}{Oct 21, 2020}{17}{Generating Functions(continued)}{Pragnya}{$\\alpha$}{JS}\n\n\\section{Introduction}\nIn this section we'll see some examples of ordinary generating functions and get introduced to exponential generating functions.\n\n\\subsection{Example 3 : }\nTo show two combinatorial qualities are equal it sufficies to show that they have same generating functions. Consider the following,\n$$ B_n(m) = \\{(x_1, x_2, \\dots x_n) ~|~ \\forall i ~ x_i \\in \\Z , \\sum |x_i| \\leq m \\}$$\nlet $b_{n,m} = |B_n(m)|$. Let's see properties of  $b_{n,m}$ :\n\\begin{enumerate}\n    \\item $b_{n, m} = \\sum_{k=0}^n {n \\choose k}{m \\choose k} 2^k$.\n    \\item $b_{n, m} = b_{m, n}$. This can also be proved using bijection.\n    \\item $b_{n, m} = d_{m, n}$. \n\\end{enumerate}\nWe'll prove property $3$ by showing they have same generating functions.\n\\begin{align*}\n    B_{x,y} &= \\sum_{n,m \\geq 0} b_{n, m} x^n y^m\\\\\n    &= \\sum_{n,m \\geq 0} (\\sum_{k=0}^n {n \\choose k}{m \\choose k} 2^k) x^n y^m \\\\\n    &= \\sum_{n,m,k \\geq 0}{n \\choose k}{m \\choose k} 2^k x^n y^m \\\\\n    &= \\sum_{k \\geq 0} 2^k \\sum_{n,m \\geq 0} {n \\choose k}{m \\choose k} x^n y^m \\\\\n    &= \\sum_{k \\geq 0} 2^k (\\sum_{n \\geq 0} {n \\choose k} x^n)(\\sum_{m \\geq 0} {m \\choose k} y^m) \\\\\nB_{x, y}&= \\sum_{k \\geq 0} 2^k (x^k \\sum_{n \\geq 0} {n \\choose k} x^{n-k})(y^k \\sum_{m \\geq 0} {m \\choose k} y^{m-k})\n\\end{align*}\nConsider $\\frac{1}{(1-x)^{k+1}}$ : \n$$\\frac{1}{(1-x)^{k+1}} = \\frac{1}{(1-x)}.\\frac{1}{(1-x)}. \\dots \\frac{1}{(1-x)} ~(k+1 ~times)$$\nCoefficient of $x^{n-k}$ in $\\frac{1}{(1-x)^{k+1}}$ is equivalent to no.of solutions of $a_1 + a_2 + \\dots + a_{k+1} = n-k$ which is $ = {(n-k) + (k+1) -1 \\choose n-k} = {n \\choose k}$.\nHence\n$$ \\sum_{n \\geq 0} {n \\choose k} x^{n-k} = \\frac{1}{(1-x)^{k+1}} $$\nSimilarly \n$$ \\sum_{m \\geq 0} {m \\choose k} y^{m-k} = \\frac{1}{(1-y)^{k+1}} $$\nSubstituting them in the above derived $B_{x, y}$ - \n\\begin{align*}\n    B_{x, y} &= \\sum_{k \\geq 0} 2^k x^k y^k \\frac{1}{(1-x)^{k+1}} \\frac{1}{(1-y)^{k+1}} \\\\\n    &= \\sum_{k \\geq 0} (2xy)^k \\frac{1}{(1-x)^{k+1}} \\frac{1}{(1-y)^{k+1}} \\\\\n    &= \\frac{1}{(1-x)(1-y)} \\sum_{k \\geq 0} \\frac{(2xy)^k}{(1-x)^k(1-y)^k} \\\\\n    &= \\frac{1}{(1-x)(1-y)} \\sum_{k \\geq 0} (\\frac{(2xy)}{(1-x)(1-y)}) ^k \\\\\n    &= \\frac{1}{(1-x)(1-y)} \\frac{1}{1- \\frac{2xy}{(1-x)(1-y)}} \\\\\n    &= \\frac{1}{(1-x)(1-y) - 2xy} \\\\\n    B(x, y) &=  \\frac{1}{1 - x - y - xy} = D(x, y)\n\\end{align*}\nSince $b_{n, m}$ and $d_{n, m}$ have same generating functions, $b_{n, m} = d_{n, m}$. Hence $b_{n, m}$ also satisfies recurrence relation of $d_{n, m}$ - \n$$ b_{n, m} = b_{n-1, m} + b_{n, m-1} + b_{n-1, m-1}$$\n\n\n\\subsection{Example 4 : Stirling number of second kind} \nAs discussed in previous lectures, number of ways to partition set $\\{1, 2, 3 \\dots n \\}$ into $k$ non-empty parts is called stirling number of second kind. Let's represent by $S_{n,k}$. It's recurrence relation is given by -  \n$$S_{n, k} = S_{n-1, k-1} + k S_{n-1, k} $$\nLHS : number of ways to partition set $\\{1, 2, 3 \\dots n \\}$ into $k$ non-empty parts $ = S_{n, k}$ \\\\\nRHS : \\begin{parts}\n\\item If element $1$ occurs in a singleton set. No.of ways to partition remaining $n-1$ elements to $k-1$ sets $= S_{n-1, k-1}$.\n\\item If element $1$ doesn't occur in a singleton set. Then we can partition remaining $n-1$ elements to $k$ sets and add element $1$ to one of these $k$ sets $=  k S_{n-1, k}$\n\\end{parts}\nWe can also see that $S_{0,0} = 1 ,~ S_{n, 0} = 0 ,~ S_{0, k} = 0$.\n%$S_{x, y} = {\\sum_{n, k \\geq 0} ^ {\\infty} S_{n,k} x^n y^k}$ \\\\\n%\\begin{equation}\n\\begin{align*}\n S(x, y) &= {\\sum_{n, k \\geq 0} ^ {\\infty} S_{n,k} x^n y^k} \\\\\n&= S_{0,0}~x^0y^0 + {\\sum_{n = 0, k \\geq 1}^ {\\infty} S_{0,k}~x^0y^k} + {\\sum_{n \\geq 1, k = 0}^ {\\infty} S_{n,0}~x^n y^0} + {\\sum_{n \\geq 1, k \\geq 1}^ {\\infty} S_{n,k}~x^n y^k}  \\\\\n &= 1 + \\sum_{n \\geq 1 , k \\geq 1} ^ {\\infty} S_{n,k} ~ x^n y^k  \\\\\n &= 1 + \\sum_{n \\geq 1 , k \\geq 1} S_{n-1, k-1}~ x^n y^k + \\sum_{n \\geq 1, k \\geq 1} k S_{n-1, k}~ x^n y^k \\\\\n &= 1 + xy \\sum_{n \\geq 1, k \\geq 1} S_{n-1, k-1} x^{n-1} y^{k-1} + x\\sum_{n \\geq 1, k \\geq 1} k S_{n-1, k}~ x^{n-1} y^k \\\\\n &= 1 + xy~ S(x, y) + x \\sum_{n \\geq 0, k \\geq 1} k S_{n, k}~ x^{n} y^k \\\\\n &= 1 + xy~ S(x, y) + \\frac{\\partial}{\\partial y} S(x,y)\n\\end{align*}\nNote : $\\frac{\\partial}{\\partial y} S(x, y) = \\sum_{n \\geq 0, k \\geq 1} k S_{n,k}~x^n y^{k-1}$ \n\n\nConsider $y^k$ coefficients on both sides : \n\\begin{equation}\n  \\begin{split}\n    LHS &= \\sum_{n \\geq 0} S_{n, k} x^n \\\\\n    RHS &= x\\sum_{n \\geq 0} S_{n, k-1} x^n + xk \\sum_{n \\geq 0} S_{n, k}x^n\n\\end{split}  \n\\end{equation}\nEquating LHS and RHS :\n\\begin{align*}\n\\sum_{n \\geq 0} S_{n, k}~ x^n &= x\\sum_{n \\geq 0} S_{n, k-1} ~x^n + xk \\sum_{n \\geq 0} S_{n, k}~x^n \\\\\n\\sum_{n \\geq 0} S_{n, k} ~x^n &= \\frac{x}{1-xk}  \\sum_{n \\geq 0} S_{n, k-1}~ x^n   \\\\\n&= \\frac{x}{1-xk} \\frac{x}{1-x(k-1)} \\sum_{n \\geq 0} S_{n, k-2}~ x^n \\\\\n&= \\frac{x}{1-xk} \\frac{x}{1-x(k-1)} \\dots \\frac{x}{1-x(k-(k-1))}\n\\sum_{n \\geq 0} S_{n, 0}~ x^n \\\\\n&= \\frac{x^k}{(1-x)(1-2x)\\dots (1-kx)} \\times 1 ~( Note : S_{0,0} = 1, S_{n, 0} = 0) \\\\\n\\sum_{n \\geq 0} S_{n, k}~ x^n &= x^k \\times (\\frac{A_1}{1-x} + \\frac{A_2}{1-2x} + \\dots +  \\frac{A_k}{1-kx})\n\\end{align*}\nSolving for $A_1, A_2, \\dots A_k $ we'll get $A_r = (-1)^{k-r} \\frac{r^{k-1}}{(r-1)! (k-r)!}$. \\\\\n$S_{n,k}$ is the coefficient of $x^n$ in RHS. i.e., \n\\begin{align*}\nS_{n,k} &= coeff~ of ~x^n ~in~ x^k \\times (\\frac{A_1}{1-x} + \\frac{A_2}{1-2x} + \\dots +  \\frac{A_k}{1-kx}) \\\\\n&= coeff ~ of ~ x^{n-k} ~ in ~ \\sum_{r=1}^k \\frac{A_r}{1-rx}\n\\end{align*}\nCoefficient of $x^{p}$ in $\\frac{1}{1-rx} = r^p$. hence,\n\\begin{align*}\nS_{n,k} &= \\sum_{r=1}^k A_r r^{n-k} \\\\\n&= \\sum_{r=1}^k (-1)^{k-r} \\frac{r^{k-1}}{(r-1)! (k-r)!} ~ r^{n-k}\\\\\nS_{n,k} &= \\sum_{r=1}^k (-1)^{k-r} \\frac{r^{n}}{(r-1)! (k-r)!}\n\\end{align*}\nThe above expression is Stirling number of second kind\n%\\end{equation}\n%$$ = S_{0,0}~x^0y^0 + {\\sum_{n = 0, k \\geq 1}^ {\\infty} S_{0,k}~x^0y^k} + {\\sum_{n \\geq 1, k = 0}^ {\\infty} S_{n,0}~x^ny^0} + {\\sum_{n \\geq 1, k \\geq 1}^ {\\infty} S_{n,k}~x^ny^k} $$ \\\\\n%$&= 1 + \\sum_{\\substack{n \\geq 1 \\\\ k \\geq 1}} ^ {\\infty} S_{n,k} ~ x^n y^k$\n\n\\section{Exponential generating functions}\nIn ordinary generating functions we associate sequence, ${(a_n)}_{n \\geq 0}$ with $G(x) = \\sum_{n \\geq 0} a_n x^n$. In $G(x)$ we chose basis $\\{ 1, x, x^2, x^3 \\dots\\}$ for set of all polynomials in one variable. But there are many other basis for set of polynomials, like $\\{1, x, x(x-1), x(x-1)(x-2), \\dots\\}$. We chose basis $\\{ 1, x, x^2, x^3 \\dots\\}$ because it has combinatorial meaning. Other such meaning full basis are $\\{\\frac{x^n}{n!}\\}_{n \\in \\N}$, $\\{e^{-x} \\frac{x^n}{n!}\\}_{n \\in \\N}$ and $\\{\\frac{1}{n^x}\\}_{n \\in \\N}$. In this lecture we'll explore exponential generating functions which use basis $\\{\\frac{x^n}{n!}\\}_{n \\in \\N}$ . \\\\\nSo  ${(a_n)}_{n \\geq 0}$ is associated with $E(x) = \\sum_{n \\geq 0} a_n \\frac{x^n}{n!}$ . Let's see a few examples - \n\\begin{align*}\n(1, 1, 1, \\dots ) &\\xrightarrow[generating function]{exponential} \\sum_{n \\geq 0} \\frac{x^n}{n!} = e^x    \\\\\n&\\xrightarrow[generating function]{ordinary} \\sum_{n \\geq 0} x^n = \\frac{1}{1-x} \\\\\n(1!, 2!, 3!, \\dots) &\\xrightarrow[generating function]{exponential} \\sum_{n \\geq 0} n! \\frac{x^n}{n!} = \\sum_{n \\geq 0} x^n = \\frac{1}{1-x}\n\\end{align*}\n$\\frac{1}{1-x}$ is ordinary generating function(ogf) of $(1, 1, 1, \\dots )$ and exponential generating function(egf) of $(1!, 2!, 3!, \\dots )$.\\\\\n\\\\\n\\textbf{\\Large {Operations of EGF}}\n\\begin{parts}\n\\item{\\textbf{Addition :} } It's similar to ogf.\n    \\begin{align*}\n        \\{a_n\\}_{n \\geq 0} &\\xrightarrow[]{egf} E(x) \\\\\n        \\{b_n\\}_{n \\geq 0} &\\xrightarrow[]{egf} F(x) \\\\\n        \\{a_n + b_n \\}_{n \\geq 0} &\\xrightarrow[]{egf} E(x) + F(x) \\\\\n    \\end{align*}\n\\item {\\textbf{Shifting :} } Multiplying ogf by $x$ shifts the sequence to left as seen in earlier lectures.  \n    \\begin{align*}\n        \\{a_0, a_1, a_2 \\dots \\} &\\xrightarrow[]{egf} E(x) \\\\\n        \\{0, a_0, a_1, a_2 \\dots \\} &\\xrightarrow[]{egf} xE(x) \\\\\n    \\end{align*}\nDifferentiating egf function will shift the sequence to right.\n\\begin{gather*}\n    \\{a_0, a_1, a_2 \\dots \\} \\xrightarrow[]{egf} ~~ E(x) \\endline\n        \\{a_1, a_2, a_3 \\dots \\} \\xrightarrow[]{egf} \\frac{d}{dx} E(x) \\\\\n        \\frac{d}{dx} E(x) = \\sum_{n \\geq 1} a_n~ \\frac{n. x^{n-1}}{n!} = \\sum_{n \\geq 1} a_n~ \\frac{x^{n-1}}{(n-1)!} =  \\sum_{n \\geq 0} a_{n+1}~ \\frac{x^{n}}{n!}\n\\end{gather*}\n\\item {\\textbf{Multiplication :} }   EGFs are used if the sequence counts labelled structures like permutations, derangements and partitions. Let $(a_n)_{n \\geq 0}$, $(b_n)_{n \\geq 0}$ count arrangements  of type $A$ and type $B$ respectively using $n$ labelled objects. If we want to count type $C$ arrangements, that can be obtained by a unique split of $n$ objects into two sets and then arranging first set according to type $A$ and second set according to type $B$ - \\\\\n No.of arrangements of type $C$ of size $n, c_n = \\sum_{k=0}^n {n \\choose k} a_k b_{n-k}$.\\\\\n Now Let's see how multiplication of $A(x)$(egf of $A$) and $B(x)$(egf of $B$) is useful \n \\begin{align*}\n     A(x).B(x) &= (\\sum_{n=0}^{\\infty} a_n \\frac{x^n}{n!})(\\sum_{n=0}^{\\infty} b_n \\frac{x^n}{n!}) \\\\\n     &= \\sum_{n=0}^{\\infty}(\\sum_{k=0}^{n} \\frac{a_k}{k!}.\\frac{b_{n-k}}{(n-k)!}) x^n \\\\\n     &= \\sum_{n=0}^{\\infty}(\\sum_{k=0}^{n} \\frac{n!}{k!(n-k)!} a_k b_{n-k}) \\frac{x^n}{n!} \\\\\n     &= \\sum_{n=0}^{\\infty}(\\sum_{k=0}^{n} {n \\choose k} a_k b_{n-k}) \\frac{x^n}{n!} \\\\\n     &= \\sum_{n=0}^{\\infty} c_n \\frac{x^n}{n!} \\\\\n     A(x).B(x) &= C(x)\n \\end{align*}\n \n Now Let's see few examples of egf \n \\subsection{Derangements } Recall that we've discussed derangements in PIE and recurrence relations. Now let's derive it using egf. Let $D_n$ represent set of derangements of $n$ objects and let $d_n = |D_n|$. we can see that $d_0 = 1 ,~ d_1 = 0,~ d_2 = 1$. Recall the recurrence relation : $$ d_{n+2} = (n+1)(d_{n+1} + d_n)$$\n \\begin{align*}\n     D(x) &= \\sum_{n=0}^{\\infty} d_n \\frac{x^n}{n!} \\\\\n     D'(x) &= \\sum_{n=0}^{\\infty} d_{n+1} \\frac{x^n}{n!} ~(by ~shifting ~operation)\\\\\n     &= \\sum_{n=1}^{\\infty} n(d_n + d_{n-1}) \\frac{x^n}{n!} \\\\\n     &= \\sum_{n=1}^{\\infty} nd_n \\frac{x^n}{n!} + \\sum_{n=1}^{\\infty} nd_{n-1} \\frac{x^n}{n!} \\\\\n     &= x \\sum_{n=1}^{\\infty} d_n \\frac{x^{n-1}}{(n-1)!} + x \\sum_{n=1}^{\\infty} d_{n-1} \\frac{x^{n-1}}{(n-1)!} \\\\\n     &= x \\sum_{n=0}^{\\infty} d_{n+1} \\frac{x^n}{n!} + x \\sum_{n=0}^{\\infty} d_n \\frac{x^n}{n!} \\\\\n     D'(x) &= xD'(x) + xD(x) \\\\\n     (1-x)D'(x) &= xD(x) \\\\\n     \\frac{D'(x)}{D(x)} &= \\frac{x}{1-x} = \\frac{1}{1-x} - 1\n \\end{align*}\nIntegrating on both sides\n     $$\\ln{D(x)} = \\ln{(1-x)} - x + c$$\nSince $D(0) = d_0 = 1 \\implies c=0$.\n    $$\\ln{D(x)} = \\ln{(1-x)} - x$$\n    $$D(x) = \\frac{e^{-x}}{1-x} = \\sum_{n=0}^{\\infty} d_n \\frac{x^n}{n!}$$\nTo get $d_n$ we need coefficient of $\\frac{x^n}{n!}$ in LHS.\n$$e^{-x} \\frac{1}{1-x} = (\\sum_{n=0}^{\\infty} (-1)^n \\frac{x^n}{n!})(\\sum_{n=0}^{\\infty} n! \\frac{x^n}{n!})$$\nCoefficient of $\\frac{x^n}{n!}$ by multiplication property = $\\sum_{k=0}^{n} {n \\choose k} a_k b_{n-k}$\n\\begin{align*}\n    d_n = \\sum_{k=0}^{n} {n \\choose k} (-1)^{n-k} k!  \n    = \\sum_{k=0}^{n} (-1)^{n-k} k! {n \\choose k}\n\\end{align*}\n$d_n$ is count of derangements of $n$ objects.\n\n\\subsection{Bell Numbers}\nLet $S_{n,k}$ represent number of ways of partitioning \\{$1, 2 ,3 \\dots n $\\} into $k$ non empty blocks and $B_n$ represent number of ways of partitioning \\{$1, 2 ,3 \\dots n $\\} ($B_0 = 1$). By definitions, \n$$B_n = \\sum_{k=0}^n S_{n,k}$$\nEquivalent intrepretation :  Consider a number whose prime factorization is square free i.e., $k \\in \\N$ such that $k = p_1p_2 \\dots p_n$ where $\\{p_1, p_2, \\dots p_n\\}$ are distinct primes. Number of ways of writing $k$ as product of natural numbers $\\geq 2 = $ number of ways of partitioning  $\\{p_1, p_2, \\dots p_n\\}$  $= B_n$. \\\\\nRecurrence Relation : \n $$ B_n = \\sum_{k=0}^{n-1} {{n-1} \\choose k} B_k $$ \n% LHS : Number ways of partitioning  \\{$1, 2 ,3 \\dots n $\\}. \\\\\n% RHS : \\begin{parts}\n% \\item If $1$ occurs in singleton set. No.of such partitions  = $B_{n-1}$\n% \\item If $1$ occurs in set with two elements. No.of ways element can be chosen $ = n-1$.No.of such partitions  = ${{n-1} \\choose 1}B_{n-2}$.\n% \\item $1$ occurs in set with $k+1$ elements. No.of ways elements in this set can be chosen $ = {n-1 \\choose k}$. No.of such partitions  = ${{n-1} \\choose k}B_{n-(k+1)}$.\n \\end{parts}\n% Hence total $= \\sum_{k=0}^{n-1} {{n-1} \\choose k} B_{n-k-1}  = \\sum_{k=0}^{n-1} {{n-1} \\choose n-k-1} B_{n-k-1} = \\sum_{n-k-1=0}^{n-1} {{n-1} \\choose k} B_{k} = \\sum_{k=0}^{n-1} {{n-1} \\choose k} B_{k} $ \\\\\n Let's derive closed form expression for $B_n$ :\n \\begin{align*}\n     B(x) &= \\sum_{n=0}^{\\infty} B_n \\frac{x^n}{n!} \\\\\n     B'(x) &= \\sum_{n=0}^{\\infty} B_{n+1} \\frac{x^n}{n!} ~(by ~ shifting ~rule) \\\\\n     &= \\sum_{n=0}^{\\infty} (\\sum_{k=0}^{\\n} {n \\choose k} B_k) \\frac{x^n}{n!} \\\\\n     &= \\sum_{n=0}^{\\infty} (\\sum_{k=0}^{\\n} {n \\choose k}. ~1 B_k) \\frac{x^n}{n!} \\\\\n     &= (\\sum_{n=0}^{\\infty} B_n \\frac{x^n}{n!})(\\sum_{n=0}^{\\infty} 1 \\frac{x^n}{n!}) ~(by ~ multiplication ~rule) \\\\\n     B'(x) &= B(x) . e^x \\\\\n     \\frac{B'(x)}{B(x)} &= e^x\n \\end{align*}\n Integrating on both sides \n $$\\ln{B(x)} = e^x + c$$\n Since $B(0) = B_0 = 1 \\implies c = -1$. Hence,\n %$$ B(x) = e^{e^x - 1} = \\frac{e^{e^x}}{e}$$\n \\begin{align*}\n     B(x) &= e^{e^x - 1} \\\\\n     &= \\frac{e^{e^x}}{e} \\\\\n     &= \\frac{1}{e} (\\sum_{k=0}^{\\infty} \\frac{(e^x)^k}{k!}) \\\\\n     &= \\frac{1}{e} (\\sum_{k=0}^{\\infty} \\frac{e^{kx}}{k!}) \\\\\n     &= \\frac{1}{e} (~\\sum_{k=0}^{\\infty} \\frac{1}{k!}~ (\\sum_{n=0}^{\\infty} \\frac{(kx)^n}{n!})~) \\\\\n     &= \\frac{1}{e} (~\\sum_{n=0}^{\\infty} \\frac{x^n}{n!}~ (\\sum_{k=0}^{\\infty} \\frac{k^n}{k!})~)\\\\\nB(x)&= \\sum_{n=0}^{\\infty} \\frac{1}{e} (\\sum_{k=0}^{\\infty} \\frac{k^n}{k!}) \\frac{x^n}{n!} \\\\\n    B_n &= \\frac{1}{e} (\\sum_{k=0}^{\\infty} \\frac{k^n}{k!})\n \\end{align*}\n We've derived closed form expression for bell number. Above expression for $B_n$ is also called as Dobinski's formula.\n \n\\end{parts}\n", "meta": {"hexsha": "d4fd87d0b74cd2fdd231cba4a22a3bda5231c3f3", "size": 14054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week06_part2.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": "week06_part2.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": "week06_part2.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": 66.9238095238, "max_line_length": 651, "alphanum_fraction": 0.5472463356, "num_tokens": 6389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.782662489091802, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6166841908149476}}
{"text": "\\chapter{MIP Heuristics}\nMixed Integer Program Heuristics can be applied in each MIP problem independently from the context. These do not consider the specific formulation of the TSP problem however they could have good applicability. In this report two MIP Heuristics will be discussed and compared with the metaheuristics.\n\n\\section{Hard-fixing}\nA simple idea to reduce the complexity of the problem is to get an initial solution like an incumbent, fix some active edges and resolve the subproblem with CPLEX. This is exactly the idea behind hard fixing approach.\\\\\nThe implementation proposed is applied in sTSP problem, with the optimization of the general callback (\\texttt{subtour\\_callback\\_general}).\nThe algorithm can be divided in steps:\n\\begin{enumerate} \\label{hard-fix-step}\n\t\\item Calculate an initial solution: in our implementation this is done by CPLEX with \\texttt{subtour\\_callba \\\\ ck\\_general} and \\texttt{CPX\\_PARAM\\_INTSOLLIM} set to 1. When the first incumbent is available, the optimization terminate and a solution is obtained.\n\t\\item Fix a percentage of edges (fixing rate $ f_r $): edges are fixed using \\texttt{CPXchgbds} method that change the upper and lower bound of the decision variables. The fixing percentage is an important parameter: fixing too much edges leads to a fast resolution of the subproblem, however increase the risk of obtaining the same solution and fall in a loop. Fixing too low edges involves slower resolution. In the first iteration $ f_r = 0.9 $.\n\t\\item CPLEX optimization with time limit: After the fixing phase, the problem is optimized with \\texttt{CPX\\_mipopt} and a short time limit is set (in our implementation $50 $s).\n\t\\item Fixing rate update: after the last phase, if the returned solution is improved better than a fixed gap ($  good\\_gap $), it is considered a good solution and the $ f_r $ increases by a constant ($ incr\\_f_r $) until a max ($ max\\_f_r $), otherwise if the new solution is not increased enough (less than $ optimal\\_gap $), then $ f_r $ decreases of a constant ($ decr\\_f_r $) until a min ($ min\\_f_r $). Note that $ good\\_gap $ and $ optimal\\_gap $ are expressed as fraction of the current best lower bound.\n\t\\item Check end condition: if the time limit is reached or $ f_r = 0.0 $ and the solution is not improved in the last iteration, then the solution is returned. In the second case, the best solution is found. If no ending condition is satisfied, the algorithm continue with point 3.\n\\end{enumerate}\n\n\\section{Local-Branching}\nThe Local Branching is a relatively recent algorithm developed by Matteo Fischetti and Andrea Lodi, who wanted to propose an alternative method to Hard Fixing. The Hard Fixing idea, as stated above, fix randomly a percentage of edges and optimize the problem, Local Branching, instead, let the MIP model to fix the percentage of edges automatically and than optimize. \\\\\nConsider $ x^H $ as non optimal tour and $ \\chi $ the fraction of edges to fix, Local Branching add\n\\begin{equation}\n \\sum_{ e\\in E: x_e^H = 1 } x_e \\ge \\chi n\n\\end{equation}\nto automatically fix the desired number of edges. \\\\\nIn this paper, the structure of the algorithm is very similar to that of Hard Fixing. Initialization is analogous to Point 1 (\\ref{hard-fix-step})\nIn the CPLEX optimization with time limit (Point 3), the time limit is a little higher and is set to 300 according to the choice of the fixing rate update. Thus, $ \\chi n $ assume values in $ \\{3, 5, 10, 15, 20\\}$. It starts from the first value of 3 which is kept until better solutions are found. It is updated to the next value as soon as the algorithm returns a non-improving solution. This choice is motivated by the idea that keeping a low fixing rate allows you to find a solution in a short time and therefore not reach the time limit, which instead is set with a higher value to allow a longer search when the value increase. If the last value is reached and there is still no improvement solution, then the value is doubled until either a better solution is found or the number of nodes of the problem is reached. In the latter case, it is assigned the entire remaining time to find the best tour. In fig. \\ref{fig:local_branching_a280} there is an example of the lower bound trend executed on \\textit{a280.tsp} instance.\\\\\n\\begin{figure}[!h]\n\t\\centering\n\t\\includegraphics[width=0.5\\columnwidth]{../res/local_branching_a280.png}\n\t\\caption{Solution cost profile.}\n\t\\label{fig:local_branching_a280}\n\\end{figure}\n\nThe exit conditions evaluate both the time limit and the gap calculated by CPLEX, obtainable through the \\texttt{generic\\_callback} using \\texttt{CPX\\_CALLBACKCONTEXT\\_GLOBAL\\_PROGRESS} as \\texttt{Context}. \nFor a detailed explanation of the reasons for this algorithm refer to \\cite{article}.\n\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}{\\columnwidth}\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lmip_meta_LA_time.png}\n\t\t\\caption{}\n\t\t\\label{fig:Lmip_meta_LA_time}\n\t\\end{subfigure}\n\t\\begin{subfigure}{\\columnwidth}\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lmip_meta_LA_lb.png}\n\t\t\\caption{}\n\t\t\\label{fig:Lmip_meta_LA_lb}\n\t\\end{subfigure}\n\\caption{Comparison of mip heuristics and meta heuristics. \\texttt{n\\_greedy\\_best\\_two\\_opt} is the first part of \\texttt{vns} therefore it is faster, however the last one introduce a little improvement in the solutions cost. Most of the times \\texttt{hard\\_fixing} can find the best solution of sTSP, indeed it find the shorter tours of the analyzed heuristics. }\n\\label{fig:Lmip_meta_LA}\n\\end{figure}\n\n%\\section{RINS}\n%\\section{Feasibility Pump}\n%\\section{Proximity Search}\n%\\section{Polishing}\n", "meta": {"hexsha": "86f97317dafcd8badff55b0bcceef84d157b451f", "size": 5639, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/mip-heuristics.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/mip-heuristics.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/mip-heuristics.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": 100.6964285714, "max_line_length": 1033, "alphanum_fraction": 0.7767334634, "num_tokens": 1427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6166841868205838}}
{"text": "\\paragraph{Question 3.}\n\nTry to simplify the regular expressions\n\\(\\lparen \\epsilon \\, \\disjM{} \\, a\\kleeneM{} \\, \\disjM{} \\,\n  b\\kleeneM{} \\, \\disjM{} \\, a \\, \\disjM{} \\, b \\rparen\\kleeneM\\) and\n\\(a \\lparen a \\, \\disjM{} \\, b \\rparen\\kleeneM{} b \n  \\, \\disjM{} \\, \\lparen a b \\rparen\\kleeneM{} \\, \\disjM{} \\, \\lparen\n  b a \\rparen\\kleeneM\\).\n", "meta": {"hexsha": "756c69484a69a20da7d45e8c67a7aa60196e1a39", "size": 343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp_question_03.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": "regexp_question_03.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": "regexp_question_03.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.1111111111, "max_line_length": 69, "alphanum_fraction": 0.5801749271, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6166841868205838}}
{"text": "\\vsssub\n\\subsubsection{~$S_{ln}$: Cavaleri and Malanotte-Rizzoli 1981} \\label{sec:LN1}\n\\vsssub\n\n\\opthead{LN1}{Pre-WAM}{H. L. Tolman}\n\n\\noindent \nA linear input source term is useful to allow for the consistent spin-up of a\nmodel from quiescent conditions, and to improve initial wave growth\nbehavior. The parameterization of \\cite{art:CMR81} is available in \\ws, with a\nfilter for low-frequency energy as introduced by \\cite{tol:JPO92}. The input\nterm can be expressed as\n\\begin{equation}\n\\cS_{lin}(k,\\theta) = 80 \\left( \\frac{\\rho_a}{\\rho_w} \\right ) ^2\n  g^{-2}  k^{-1} \\max \\left [ 0 , u_* \\cos (\\theta - \\theta_w) \\right ]^4 \\: G\n   \\:\\:\\: , \\label{eq:CMR81}\n\\end{equation}\n\n\\noindent\nwhere $\\rho_a$ and $\\rho_w$ are the densities of air and water, respectively,\nand where $G$ is the filter function\n\n\\begin{equation}\nG = \\exp \\left [ - \\left ( \\frac{f}{f_{filt}} \\right ) ^{-4} \\right ]\n\\:\\:\\: . \\label{eq:GSln}\n\\end{equation}\n\n\\noindent\nIn \\cite {tol:JPO92} the filter frequency $f_{filt}$ was given as the\nPierson-Moskowitz frequency $f_{PM}$, which in turn was estimated as in\nEq.~(\\ref{eq:f_PM}).  In the present implementation, the filter can be related\nto both $f_{PM}$ and the cut-off frequency of the prognostic part of the\nspectrum $f_{hf}$ as defined in Eq.~(\\ref{eq:tail_E_f})\n\n\\begin{equation}\nf_{filt} = \\max \\left [ \\alpha_{PM} f_{PM} , \\alpha_{hf} f_{hf} \\right ]\n\\:\\:\\: ,\n\\end{equation}\n\n\\noindent\nwhere the constants $\\alpha_{PM}$ and $\\alpha_{hf}$ are user-defined. Default\nvalues of these constants are set to $\\alpha_{PM} = 1$ and $\\alpha_{hf} =\n0.5$.  Addition of the dependency on $f_{hf}$ assures consistent growth\nbehavior at all fetches, without the possibility of low-frequency linear\ngrowth to dominate at extremely short fetches.\n\n", "meta": {"hexsha": "8c9a3bb9adeea1b7d94f7aba654d60ecbae99376", "size": 1764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/eqs/LN1.tex", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "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": "WW3/manual/eqs/LN1.tex", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-31T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:17:45.000Z", "max_forks_repo_path": "WW3/manual/eqs/LN1.tex", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-01T09:29:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-01T09:29:46.000Z", "avg_line_length": 37.5319148936, "max_line_length": 78, "alphanum_fraction": 0.701814059, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.6926419894793248, "lm_q1q2_score": 0.6166551579546801}}
{"text": "\\section{Sets and Functions}\r\n\\subsection{Naive Set Theory}\r\n\\begin{definition}[Naive definition of sets]\r\n    A set is any\r\n    \\footnote{Not quite, see later.}\r\n    collection of (mathematical) objects.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\mathbb N,\\mathbb Q,\\mathbb R,\\mathbb C,\\mathbb Z,[0,1],\\{1,2,3\\},\\ldots$\r\n\\end{example}\r\nA set is determined by its members: $(a\\in A\\iff a\\in B)\\iff(A=B)$.\r\nHence, the set is not ordered per se: $\\{1,3,7\\}=\\{7,1,3\\},\\{1,3,3,7\\}=\\{1,3,7\\}$.\r\nFrom the second example, we also know that there is no multiple membership.\\\\\r\nOf course, we would want to make new sets from old.\r\n\\begin{definition}\r\n    A set $A$ is a subset of another set $B$ iff $x\\in A\\implies x\\in B$.\r\n    We write it as $A\\subset B$ or $A\\subseteq B$.\r\n\\end{definition}\r\nSo $A=B$ is equivalent to $A\\subset B$ and $B\\subset A$.\r\n\\begin{example}\r\n    $\\{1,7\\}\\subset \\{1,3,7\\}\\subset\\mathbb N\\subset\\mathbb Z\\subset \\mathbb Q\\subset\\ldots, [0,1]\\subset\\mathbb R$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Given a set $A$ and a property $P$ on $A$, we can form the set of all elements in $A$ having property $P$, $\\{x\\in A:P(x)\\}$\r\n\\end{definition}\r\n\\begin{example}\r\n    We can construct the primes by $\\{n\\in\\mathbb N:\\text{$n$ is prime}\\}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Given sets $A,B,U$ such that $A,B\\subset U$, we can construct their union by\r\n    $$A\\cup B=\\{x\\in U:x\\in A\\lor x\\in B\\}$$\r\n    and intersection by\r\n    $$A\\cap B=\\{x\\in U:x\\in A\\land x\\in B\\}$$\r\n    We say $A,B$ are disjoint if $A\\cap B=\\varnothing$.\\\\\r\n    We also have the minus action\r\n    $$A\\setminus B=\\{x\\in A:x\\notin B\\}$$\r\n\\end{definition}\r\nWe can view $A\\cap B$ as a subset selection, since $A\\cap B=\\{x\\in A:x\\in B\\}$.\r\nUnions and intersections are commutative and associatives.\r\nAlso, the union is distributive over the intersection: $A\\cup (B\\cap C)=(A\\cup B)\\cap (A\\cup C)$.\r\nThe intersection is distributive over the union as well: $A\\cap (B\\cup C)=(A\\cap B)\\cup (A\\cap C)$.\r\nOne can easily check them.\\\\\r\nWe can also have arbitrary unions and intersections.\r\n\\begin{definition}\r\n    For $A_i\\subset U$ where $i\\in I$ for some index set $I$, the union of all $A_i$'s can be defined by\r\n    $$\\bigcup_{i\\in I}A_i=\\{x\\in U:\\exists i\\in I,x\\in A_i\\}$$\r\n    the intersection by\r\n    $$\\bigcap_{i\\in I}A_i=\\{x\\in U:\\forall i\\in I,x\\in A_i\\}$$\r\n\\end{definition}\r\nIt coincides with our previous definition in the finite case due to the associativity and commutativity of unions and intersections.\r\n\\begin{definition}\r\n    In $\\mathbb R$, let $A_n=[1-1/n,1+1/n],n\\in\\mathbb N$, so $\\bigcup_{n\\in\\mathbb N}A_n=[0,2],\\bigcap_{n\\in N}A_n=\\{1\\}$, note that there is no limiting operation going on here.\\\\\r\n    Let let $A_n=(1-1/n,1+1/n),n\\in\\mathbb N$, so $\\bigcup_{n\\in\\mathbb N}A_n=(0,2),\\bigcap_{n\\in N}A_n=\\{1\\}$\r\n\\end{definition}\r\n\r\n\\begin{definition}\r\n    Given two objects $a,b$, you can form the ordered pair $(a,b)$,\r\n    And that $(a,b)=(c,d)$ iff $a=c,b=d$.\r\n    For sets $A,B$, one can form the collection $A\\times B=\\{(a,b):a\\in A,b\\in B\\}$, which is called the product, or Cartesian product of $A,B$.\r\n\\end{definition}\r\n\\begin{example}\r\n    The plane $\\mathbb R^2$ can be viewed as $\\mathbb R\\times\\mathbb R$.\r\n\\end{example}\r\nSimilarly, we can construct things like $\\mathbb R^n$ by recognising the collection of all ordered $n$-tuples.\\\\\r\nNote that if we wish to do it, we could define $(a,b)$ by the set $\\{\\{a\\},\\{a,b\\}\\}$.\r\nOne can check that $(a,b)=(c,d)\\iff a=c,b=d$ under this notion.\r\n\\footnote{Quoting the lecturer, ``You're completely nuts if you really think of this in that way'}\r\n\\begin{definition}\r\n    For any set $A$, we can form the power set of $A$, written as $\\mathbb P(A)$ or $2^A$,\r\n    \\footnote{Different from the lecturer, the author of this set of notes prefers the latter notation.}\r\n    which is set of all subsets of $A$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $X=\\{1,2\\}$, then $2^X=\\{\\varnothing, \\{1\\},\\{2\\},\\{1,2\\}\\}$.\r\n\\end{example}\r\n\\begin{remark}\r\n    Warning: Given a set $A$, we know we can form $\\{x\\in A:P(x)\\}$, but you should not form $\\{x:P(x)\\}$.\r\n    Suppose we could form $X=\\{x:x\\notin x\\}$, then do we have $X\\in X$?\r\n    Indeed, this gives a contradiction.\\\\\r\n    This is called the Russel's Paradox.\r\n\\end{remark}\r\nSimilarly, there is not an universal set $U$ such that $\\forall x,x\\in V$, because it would induce the Russel's Paradox.\r\nWe can only guarantee that a given set exists if it is obtained, in some way, from known sets.\r\n\\subsection{Finite Sets and Their Sizes}\r\n\\begin{definition}\r\n    A set $A$ has size $n$ where $n\\in\\mathbb N_0$ if we can write $A=\\{a_1,a_2,\\ldots,a_n\\}$ such that $a_i$'s are distinct.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $\\{1,3,7\\}$ has size $3$.\\\\\r\n    2. $\\varnothing$ has size $0$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    If a set has size $n$ and size $m$, then $m=n$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    It's trivial but whatever.\\\\\r\n    Indeed, if $A$ has size $n$ and size $m$ with $n>m$, then if $m=0$ it is trivial, otherwise, removing an element from $A$ gives a set of sizes $n-1,m-1$, so it is done by induction on $m$.\r\n\\end{proof}\r\n\\begin{proposition}\\label{2power}\r\n    If $A$ has size $n$, then $2^A$ has size $2^n$.\r\n\\end{proposition}\r\nIt is obvious when $n=0$, so we assume henceforth it is not.\r\n\\begin{proof}\r\n    We can relabel the element in $A$ by $\\{1,2,\\ldots,n\\}$.\r\n    So to specify a subset $S$, we must specify if $1\\in S$, $2\\in S$, and so on, so the size of $2^A$ is $2\\times 2\\times 2\\times\\cdots\\times 2$ $n$ times, which is $2^n$.\r\n\\end{proof}\r\n\\begin{proof}[Alternative proof]\r\n    Induction on $n$.\r\n\\end{proof}\r\nThe alternative proof can be viewed as a more formal version of the first proof.\\\\\r\nWe are tired of saying ``the size of blah blah blah'' so we write $|A|$ to denote the size of $A$.\\\\\r\nA set of size $n$ is sometimes called an $n$-set.\r\n\\begin{definition}[Binomial Coefficients]\r\n    Let $A=\\{1,2,\\ldots,n\\}$ for $n\\ge 1$, then the binomial coefficient is defined as\r\n    $$\\binom{n}{k}=\\{S\\subset A:|S|=k\\}$$\r\n    is the number of ways to choose a $k$-set from an $n$-set.\r\n\\end{definition}\r\n\\begin{example}\r\n    $$\\binom{4}{2}=6$$\r\n    by listing.\r\n\\end{example}\r\nWe always have $\\binom{n}{n}=\\binom{n}{0}=1,\\binom{n}{1}=n$ and $\\binom{n}{k}=\\binom{n}{n-k}$.\r\nAlso, by Proposition \\ref{2power}, we instantly have\r\n$$\\binom{n}{0}+\\binom{n}{1}+\\cdots+\\binom{n}{n}=2^n$$\r\nIn addition,\r\n$$\\binom{n}{k}=\\binom{n-1}{k-1}+\\binom{n-1}{k}$$\r\nsince both size counted the number of $k$-sets in an $n$-set, that is, the number of $k$-sets which include some specified element and the number of $k$ sets which do not include.\r\nHence we have the Pascal's triangle.\r\n\\begin{proposition}\r\n    $$\\binom{n}{k}=\\frac{n(n-1)(n-2)\\cdots (n-k+1)}{k!}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We first count the number of ordered $k$-sets is $n(n-1)(n-2)\\cdots (n-k+1)$.\r\n    But here we have overcounted each $k$-sets by $k(k-1)(k-2)\\cdots 1=k!$, therefore the formula.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    When $n$ is big, $\\binom{n}{k}\\sim n^k/k!$.\r\n\\end{corollary}\r\nAn appplication of the binomial coefficient is the binomial theorem.\r\n\\begin{theorem}[Binomial Theorem]\r\n    $$(a+b)^n=\\sum_{k=0}^n\\binom{n}{k}a^{n-k}b^k$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    When we expand $(a+b)^n=(a+b)(a+b)\\cdots (a+b)$ where there are altogether $n$ brackets, we obtain terms of the form $a^{n-k}b^{k}$ where $0\\le k\\le n$.\r\n    But the number of terms that we get in each is the number of ways to choose $k$ (or equivalently, $n-k$) brackets from the $n$ brackets, so it is $\\binom{n}{k}$, thus the theorem.\r\n\\end{proof}\r\nIn particular, $(1+x)^n=1+nx+\\binom{n}{2}x^2+\\cdots +x^n$, hence for given $n$, $(1+x)^n\\sim 1+nx$ when $x$ is small, and we can get better approximations when we take more term(s).\\\\\r\nNow, how do sizes of unions and intersections (for finite sets) relate to each other?\r\n\\begin{example}\r\n    We have $|A\\cup B|=|A|+|B|-|A\\cap B|$, and $|A\\cup B\\cup C|=|A|+|B|+|C|-|A\\cap B|-|B\\cap C|-|C\\cap A|+|A\\cap B\\cap C|$.\r\n\\end{example}\r\n\\begin{theorem}[Inclusion/Exclusion Principle]\r\n    For finite sets $(S_i)_{i=1}^n$, $|S_1\\cup S_2\\cup\\cdots\\cup S_n|$ equals\r\n    $$\\sum_i|S_i|-\\sum_{i<j}|S_{ij}|+\\sum_{i<j<k}|S_{ijk}|-\\cdots+(-1)^{n+1}\\sum_{i_1<i_2<\\ldots <i_n}S_{i_1i_2\\ldots i_n}$$\r\n    Where $S_{k_1k_2\\ldots k_r}=S_{k_1}\\cap S_{k_2}\\cap \\cdots\\cap S_{k_r}$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider $x\\in |S_1\\cup S_2\\cup\\cdots\\cup S_n|$, suppose we can choose the maximal $k$ such that there is a $k$-set $A$ contained in $\\{1,2,\\ldots, n\\}$ such that $x\\in S_a$ for each $a\\in A$.\r\n    Then, the number of times that $x$ is counted is\r\n    $$k-\\binom{k}{2}+\\binom{k}{3}-\\cdots+(-1)^{k+1}\\binom{k}{k}=1-(1-1)^k=1$$\r\n    by Binomial Theorem.\r\n    So each element is counted exactly once, hence the theorem is proved.\r\n\\end{proof}\r\n\\subsection{Functions}\r\n\\begin{definition}[Intuitive Definition of Functions]\r\n    For sets $A,B$, a function $f:A\\to B$ is a ``rule'' that assigns each element $a$ in $A$ exactly one element, called $f(a)$ in $B$.\r\n\\end{definition}\r\n\\begin{definition}[Rigourous Definition of Functions]\r\n    A function $f:A\\to B$ is a set $f\\subset A\\times B$ such that if $(a,b),(a,c)\\in f$ for $a\\in A$ and $b,c\\in B$, then $b=c$ (equivalently $(a,b)=(a,c)$).\r\n    In other words, $\\forall a\\in A,\\exists!b\\in B,(a,b)\\in f$.\r\n    We write $f(a)=b$.\r\n\\end{definition}\r\n$A$ is called the domain of $f$ and $B$ is called the range (or codomain) of $f$.\r\nThe set $\\{f(a):a\\in A\\}$ is called the image of $f$.\r\n\\begin{example}\r\n    1. We can have a function $f:\\mathbb R\\to\\mathbb R$ given by $f(x)=x^2$.\\\\\r\n    2. (non-example) But $f:\\mathbb R\\to\\mathbb R$ by $f(x)=1/x$ is not a function since it does not have value at $0$.\\\\\r\n    3. (non-example) The function $f:\\mathbb R\\to\\mathbb R$ by $f(x)=\\pm\\sqrt{x^2}$ is not a function due to multiple value.\\\\\r\n    4. $A=\\{1,2,3,4,5\\},B=\\{1,2,3,4\\}$ and $f:A\\to B$ by $1\\mapsto 1,2\\mapsto 3,3\\mapsto 4,4\\mapsto 3,5\\mapsto 5$ is a function.\\\\\r\n    5. $A=B=\\{1,2,3\\}$ and $f:A\\to B$ by $1\\mapsto 2,2\\mapsto 1,3\\mapsto 3$ is a function.\\\\\r\n    6. $A=B=\\{1,2,3,4\\}$ and $f:A\\to B$ by $1\\mapsto 1,2\\mapsto 2,3\\mapsto 4,4\\mapsto 4$.\\\\\r\n    7. $A=\\{1,2,3,4,5\\}, B=\\{1,2,3,4\\}$ and $f:A\\to B$ by $1\\mapsto 2,2\\mapsto 1,3\\mapsto 3,4\\mapsto 4,5\\mapsto 4$.\r\n\\end{example}\r\nNote that it can be ambiguous if we just say $f(x)=x^2$ since we may not know about the domain (and range).\r\nWe can only define a function with knowing about the domain and the range.\r\nNote also that we do not have to have a ``closed form'' of a function, which is frankly ridiculous to do so.\r\n\\begin{definition}\r\n    A function $f:A\\to B$ is called injective if $\\forall x,y\\in A,x\\neq y\\implies f(x)\\neq f(y)$, or equivalently, $\\forall x,y\\in A,f(x)=f(y)\\implies x=y$.\\\\\r\n    It is called surjective if $\\forall b\\in B,\\exists a\\in A,f(a)=b$, or equivalently, $B$ is the image of $f$.\r\n\\end{definition}\r\nOne can easily classify the above examples by injective/non-injective and surjective/non-surjective.\r\n\\begin{definition}\r\n    If a function $f$ is both injective and surjective, we say it is bijective, or that it is a bijection.\r\n\\end{definition}\r\nNote that a bijection pair up elements in $A$ and $B$.\r\nIt is also called a 1-1 correspondence.\r\nExample 5 above is an example of a bijection.\r\nNote that injectivity and surjectivity depend strongly on the domain and range of the function.\r\n\\begin{remark}\r\n    If $A,B$ are finite and $f:A\\to B$.\r\n    If $|A|>|B|$, $f$ cannot be injective.\r\n    If $|A|<|B|$, $f$ cannot be surjective.\\\\\r\n    If $|A|=|B|$, then surjectivity, injectivity and bijectivity are equivalent.\r\n    Thus any $f:A\\to A$ cannot biject $A$ to a proper subset $A'\\subsetneq A$.\r\n    But this is not necessarily true for infinite (i.e. not finite) sets, for example, the ``adding-$1$'' function is a bijection $\\mathbb N\\to\\mathbb N\\setminus\\{1\\}$ (assuming $\\mathbb N$ starts with $1$), this also shows that injectivity does not imply surjective.\r\n    Also the function $\\mathbb N\\to\\mathbb N$ by $1\\mapsto 1$ and $n\\mapsto n-1$ for $n\\ge 2$ is surjective but not injective.\r\n\\end{remark}\r\nWe have more examples of functions.\r\n\\begin{example}\r\n    1. For any set $A$, we have the identity function $A\\to A$ which sends each element to itself\r\n    It is a bijection.\\\\\r\n    2. Given a set $X$ and a subset $A\\subset X$, the function $\\chi_A:X\\to\\{0,1\\}$ by $\\chi_A(x)=1$ if $x\\in S$ and $\\chi_A(x)=0$ otherwise is a function.\r\n    This is called the indicator (or characteristic) function of $A$.\\\\\r\n    3. A sequence on a set $X$ is a function $\\mathbb N\\to X$.\\\\\r\n    4. The addition and multiplication, say on $\\mathbb N$, are functions $\\mathbb N\\times\\mathbb N\\to\\mathbb N$.\\\\\r\n    5. A finite set $A$ has set $m$ if and only if there is a bijection $\\{1,2,3,\\ldots,m\\}\\to A$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $f:A\\to B,g:B\\to C$, then the composition $g\\circ f$ is a function $A\\to C$ defined by $(g\\circ f)(a)=g(f(a))$.\r\n\\end{definition}\r\nNote that function compositions are not necessarily commutative (if $A=C$).\r\n\\begin{example}\r\n    If $A=B=C=\\mathbb R$ and $f: x\\mapsto 2x,g: x\\mapsto x+1$, then $f\\circ g: x\\mapsto 2x+2,g\\circ f:x\\mapsto 2x+1$, which are indeed different.\r\n\\end{example}\r\nHowever, function compositions are associative.\r\n\\begin{proposition}\r\n    If $f:A\\to B,g:B\\to C,h:C\\to D$, then $h\\circ (g\\circ f)=(h\\circ g)\\circ f$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $\\forall x\\in A, (h\\circ (g\\circ f))(x)=h(g(f(x)))=((h\\circ g)\\circ f)(x)$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    $f:A\\to B$ is invertible if and only if there is some other function $g:B\\to A$ such that $f\\circ g=\\operatorname{id}_B,g\\circ f=\\operatorname{id}_{A}$.\r\n    We say $g$ is the inverse of $f$.\r\n    Note that $g$ is invertible as well with inverse $f$.\r\n\\end{definition}\r\n\\begin{example}\r\n    Consider $f:\\mathbb R\\to\\mathbb R$ by $f(x)=2x+1$, consider $g:\\mathbb R\\to\\mathbb R$ by $g(x)=(x-1)/2$, then $\\forall x\\in\\mathbb R,(f\\circ g)(x)=(g\\circ f)(x)=x$, thus $f$ is invertible and $g$ is the inverse of $f$.\r\n\\end{example}\r\n\\begin{remark}\r\n    Note that we have to check both sides.\r\n    Consider $f_0:\\mathbb N\\to\\mathbb N$ by $f_0(x)=x+1$ and $f_1:\\mathbb N\\to\\mathbb N$ by $f_1(x)=x-1$ for $x>1$ and $f_1(1)=1$, then $f_1\\circ f_0=\\operatorname{id}_{\\mathbb N}$ but $f_0\\circ f_1\\neq\\operatorname{id}_{\\mathbb N}$.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    A function is invertible if and only if it is a bijection.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\subsection{Equivalence Relations}\r\n\\begin{definition}\r\n    Let $A$ be a set, then a relation $R$ is a subset of $A\\times A$.\r\n    We say $x,y\\in A$ are related, or $xRy$, if $(x,y)\\in R$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. On $\\mathbb N$, the relation $aRb\\iff a\\equiv b\\pmod{7}$ is a relation.\\\\\r\n    2. On $\\mathbb N$, $aRb\\iff a|b$ is a relation.\\\\\r\n    3. On any set, $aRb\\iff a\\neq b$ is a relation.\\\\\r\n    4. On $\\mathbb N$, $aRb\\iff a=b\\pm 1$.\\\\\r\n    5. On $\\mathbb N$, $aRb\\iff |a-b|\\le 2$.\\\\\r\n    6. On $\\mathbb N$, $aRb\\iff (a,b<5\\lor a,b\\ge 5)$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A relation $R$ is reflexive iff $\\forall x\\in A, xRx$.\r\n\\end{definition}\r\nThe first, second, fifth and sixth examples above are reflexive relations.\r\n\\begin{definition}\r\n    A relation $R$ is symmetric iff $\\forall x,y\\in A, xRy\\implies yRx$\r\n\\end{definition}\r\nThe first, third, fourth, fifth and sixth examples above are symmetric relations.\r\n\\begin{definition}\r\n    A relation $R$ is transitive iff $\\forall x,y,z\\in A, (xRy\\land yRz)\\implies xRz$\r\n\\end{definition}\r\nThe first, second and sixth exampels above are transitive relations.\r\n\\begin{definition}\r\n    We say $R$ is an equivalence relation if it is reflexive, symmetric and transitive.\r\n\\end{definition}\r\nThe first and sixth relations above are equivalence relations.\r\n\\begin{example}\\label{partition}\r\n    Let $X$ be a set, then consider a partition $\\{C_i\\}_{i\\in I}$ of $X$.\r\n    That is, $C_i\\neq \\varnothing$, $i\\neq j\\implies C_i\\cap C_j=\\varnothing$ and $X=\\bigcup_{i\\in I}C_i$.\r\n    Then $xRy\\iff \\exists i\\in I, x,y\\in C_i$ is a equivalence relation.\r\n\\end{example}\r\n\\begin{proposition}\\label{eq_class}\r\n    All equivalence relations on $X$ can be written in the form of Example \\ref{partition}.\r\n\\end{proposition}\r\n\\begin{definition}\r\n    For an equivalence relation $R$ on a set $X$ and $x\\in X$, the equivalence class containing $x$, written as $C_x$ or $[x]$, is $\\{y\\in X:xRy\\}=\\{y\\in X:yRx\\}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    In the first example, $[2]=6+7\\mathbb Z=[16]=[23]=\\ldots$.\r\n    Note that we have $7$ equivalence classes in total, namely $i+7\\mathbb Z,i\\in\\{0,1,2,3,4,5,6\\}$.\r\n\\end{example}\r\n\\begin{proof}[Proof of Proposition \\ref{eq_class}]\r\n    let $X$ be the set with the equivalence relation $R$.\r\n    We shall show that the equivalence classes partitions $X$.\r\n    Note that $x\\in [x]$, so their union is $X$, so it remains to show that different equivalence classes are disjoint.\r\n    If $y\\in [x]$ and $y\\in [z]$, then for any $w\\in [x]$, we know $wRx,xRy$, so $wRy$, but $yRz$, so $wRz$, therefore $w\\in [z]$, hence $[x]\\subset [z]$.\r\n    Similarly $[z]\\subset [x]\\implies [x]=[z]$.\r\n\\end{proof}\r\nHence equivalence relation is just a partition of the set.\r\n\\begin{definition}\r\n    The collection $X/R=\\{[x]:x\\in X\\}$ is called the quotient of $X$ with respect to an equivalence relation $R$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $xRy\\iff x\\equiv y\\pmod{7}$ is an equivalence relation on $\\mathbb Z$.\r\n    It gives the quotient $\\mathbb Z/R=\\{i+7\\mathbb Z:i\\in \\{0,1,2,3,4,5,6\\}\\}$.\\\\\r\n    2. $(a,b)R(c,d)\\iff ad=bc$ is an equivalence relation on $\\mathbb Z\\times\\mathbb N$.\r\n    So we could construct $\\mathbb Q$ by $\\mathbb Q=(\\mathbb Z\\times\\mathbb N)/R$.\r\n    The equivalence classes are like, for example, $[(1,2)]=\\{(1,2),(2,4),(4,8),\\ldots\\}$.\r\n    In that way we can recognize $a/b=[(a,b)]$.\r\n\\end{example}\r\n\\begin{definition}\r\n    The quotient map (or projection map) $q:X\\to X/R$ is defined by $q(x)=[x]$.\r\n\\end{definition}\r\nThis is well-defined since equivalence classes partitions the set $X$.\r\n", "meta": {"hexsha": "d15097efa272cc4b7f49ee467726814e39189f90", "size": 18229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/set.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": "6/set.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": "6/set.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": 57.5047318612, "max_line_length": 268, "alphanum_fraction": 0.6491305063, "num_tokens": 6490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6166080379226071}}
{"text": "\\lab{Applications}{Wave Phenomena}{Wave Phenomena}\n\\label{lab:waveeqn}\n\n\\section*{Advection Equation}\nThe advection equation (or transport equation) is given by $u_t + s u_x = 0$, where $s$ is a nonzero constant.\nConsider the Cauchy problem\n\\begin{align*}\n\t& u_t + su_x = 0, \\quad -\\infty < x < \\infty,\\\\\\\n\t& u(x,0) = f(x).\n\\end{align*}\nThe function $f(x)$ may be thought of as an initial wave or signal.\nThe general solution of this initial boundary value problem is $u(x,t) = f(x-st)$ (check this!).\nThe solution $u(x,t)$ is a travelling wave that takes the signal $f(x)$ and moves it along at a constant speed $s$ - to the right if $s > 0$, and to the left if $s < 0$.\n\n\\section*{Wave Equation}\nMany different wave phenomena can be described using a hyperbolic PDE called the wave equation.\nThese wave phenomena occur in fields such as electromagnetics, fluid dynamics, and acoustics.\nThis equation is given by\n\\begin{align}\n\tu_{tt} &= s^2 \\triangle u.\n\\end{align}\nThe 1D equation can be derived in the context of many physical models; a common derivation describes the motion of a string vibrating in a plane.\nAnother nice derivation uses Hooke's law from the theory of elasticity.\n\nAfter making the change of variables $(\\xi,\\eta) = (x-st, x + st)$ and using the chain rule, we find that the 1D wave equation $u_{tt} = s^2 u_{xx}$ is equivalent to $u_{\\xi \\eta} = 0$.\nThe general solution of this last equation is\n\\[u(\\xi, \\eta) = F(\\xi) + G(\\eta)\\]\nfor some scalar functions $F$ and $G$.\nIn $(x,t)$ coordinates the solution is\n\\[u(x,t) = F(x-st) + G(x+st)\\]\nThus the general solution of the wave equation is the sum of two parts: one is a signal travelling to the right with constant speed $|s|$, and the other is a signal travelling to the left with speed $|s|$.\n\nThe wave equation is usually seen in the context of an initial boundary value problem.\nThis takes the form\n\\begin{align*}\n\tu_{tt} &= s^2 u_{xx}, \\quad 0 < x < l, \\quad t > 0,\\\\\n\tu(0,t) &= u(l,t) = 0, \\\\\n\tu(x,0) &= f(x),\\\\\n\tu_t(x,0) &= g(x).\n\\end{align*}\n\n\\subsection*{Numerical solution of the wave equation}\nWe look to approximate $u(x,t)$ on a grid of points $(x_j,t_m)_{j=0,m=0}^{J,M}$.\nDenote the approximation to $u(x_j,t_m)$ by $U_{j}^{m}$.\nRecall that the centered approximations in space and time are\n\\begin{align*}\nD_{tt} U_{j}^{m} = \\frac{U_{j}^{m+1} -2 U_{j}^{m} + U_{j}^{m-1}}{(\\triangle t)^2} ,\\\\\nD_{xx} U_{j}^{m} = \\frac{U_{j+1}^{m} -2 U_{j}^{m} + U_{j-1}^{m}}{(\\triangle x)^2} .\n\\end{align*}\n% \\[u_{tt}(x_j,t_m) = \\frac{u(x_j,t_m+k) -2 u(x_j,t_m) + u(x_j,t_m-k)}{k^2} + \\mathcal{O}(k^2)\\]\n% \n% \\[u_{xx}(x_j,t_m) = \\frac{u(x_j+h,t_m) -2 u(x_j,t_m) + u(x_j-h,t_m)}{k^2} + \\mathcal{O}(h^2)\\]\nThe resulting method is given by\n\\begin{align*}\n\t&\\frac{U_{j}^{m+1} -2 U_{j}^{m} + U_{j}^{m-1}}{(\\triangle t)^2} = s^2 \\frac{U_{j+1}^{m} -2 U_{j}^{m} + U_{j-1}^{m}}{(\\triangle x)^2}, \\\\\n\t% &U_{j,m+1} = 2 U_{j,m} - U_{j,m-1} + \\lambda ^2 (U_{j+1,m} -2 U_{j,m} + U_{j-1,m}), \\\\\n\t&U_{j}^{m+1} =  - U_{j}^{m-1} + 2 (1-\\lambda^2) U_{j}^{m} + \\lambda ^2 (U_{j+1}^{m} + U_{j-1}^{m}),\n\\end{align*}\nwhere $ \\lambda  =  s(\\triangle t)/(\\triangle x)$.\nThis method may be written in matrix form as\n\\[U^{m+1} = AU^{m} - U^{m-1} \\]\nwhere\n\\[A =\n\\left[\\begin{array}{cccc}2(1-\\lambda^2) & \\lambda^2 &  &  \\\\ \\lambda^2 & 2(1-\\lambda^2) & \\lambda^2 &  \\\\ \\ddots & \\ddots & \\ddots &  \\\\ & \\lambda^2 & 2(1-\\lambda^2) & \\lambda^2 \\\\  &  & \\lambda^2 & 2(1-\\lambda^2)\\end{array}\\right]\\]\nand\n\\[U^m = \\left[\\begin{array}{c}U_{1}^{m} \\\\U_{2}^{m} \\\\\\vdots \\\\U_{J-1}^{m}\\end{array}\\right]\\]\n\n% \\[\\left[\\begin{array}{c}U_{1,j+1} \\\\U_{2,j+1} \\\\\\vdots \\\\U_{m-1,j+1}\\end{array}\\right] =\n% \\left[\\begin{array}{cccc}2(1-\\lambda^2) & \\lambda^2 &  &  \\\\ \\lambda^2 & 2(1-\\lambda^2) & \\lambda^2 &  \\\\ \\ddots & \\ddots & \\ddots &  \\\\ & \\lambda^2 & 2(1-\\lambda^2) & \\lambda^2 \\\\  &  & \\lambda^2 & 2(1-\\lambda^2)\\end{array}\\right]\n% \\left[\\begin{array}{c}U_{1,j} \\\\U_{2,j} \\\\\\vdots \\\\U_{m-1,j}\\end{array}\\right]  -\n% \\left[\\begin{array}{c}U_{1,j-1} \\\\U_{2,j-1} \\\\\\vdots \\\\U_{m-1,j-1}\\end{array}\\right]\\]\nIn the matrix equation above, we have already used the boundary conditions to determine that $U_{0}^{m} = U_{J}^{m} = 0$ at each time $t_m$.\nNote that, to obtain the approximation $U_{j}^{m+1}$ of $u(x_j,t_{m+1})$, the method uses the value of the approximation at \\emph{the previous two time steps}.\nWe can find the solution for the first two time steps by using the initial conditions.\nUsing the initial conditions directly gives an approximation at $t = t_0 = 0:$\n\\[U_{j}^{0} = f(x_j), \\quad 1 \\leq j \\leq J-1\\]\n\nTo obtain an approximation at the second time step, we consider the Taylor expansion\n\\begin{align*}\n\tu(x_j,t_1) &= u(x_j, 0) + u_t(x_j,0) \\triangle t + u_{tt}(x_j,0) \\frac{\\triangle t^2}{2} + u_{ttt}(x_j,t_1^*) \\frac{\\triangle t^3}{6}.\n\\end{align*}\nRecalling that the solution $u(x,t)$ satisfies the wave equation, we substitute in expressions from our initial conditions:\n\\begin{align*}\n\tu(x_j,t_1) &= u(x_j, 0) +  g(x_j) \\triangle t+ s^2 f''(x_j)\\frac{\\triangle t^2}{2} +  u_{ttt}(x_j,t_1^*) \\frac{\\triangle t^3}{6}.\n\\end{align*}\nIgnoring the third order term, we obtain a second order approximation for the second time step:\n\\[U_{j}^{1}= U_{j}^{0} + g(x_j) \\triangle t+ s^2 f''(x_j) \\frac{\\triangle t^2}{2}, \\quad 1 \\leq j \\leq J-1\\]\nor if $f$ is not readily differentiable,\n% & U_{j,1}= U_{j,0} + g(x_j) \\triangle t+ c^2  \\frac{f(x_{j+1}) -2 f(x_{j}) + f(x_{j-1})}{(\\triangle x)^2}\\frac{\\triangle t^2}{2}.\n\\[U_{j}^{1}= U_{j}^{0} + g(x_j) \\triangle t+ \\frac{\\lambda^2}{2} (f(x_{j+1}) -2 f(x_{j}) + f(x_{j-1}))\\]\nThis method is conditionally stable; the CFL condition is that $\\lambda \\leq 1$.\n\n\\begin{problem}\nConsider the initial boundary value problem\n\\begin{align*}\n\tu_{tt} &= u_{xx}, \\\\\n\tu(0,t) &= u(1,t) = 0, \\\\\n\tu(x,0) &= \\sin(2 \\pi x),\\\\\n\tu_t(x,0) &= 0.\n\\end{align*}\nNumerically approximate the solution $u(x,t)$ at $t = .5$.\nUse $J=5$ subintervals in the $x$ dimension and $M=5$ subintervals in the $t$ dimension.\nCompare your results with the analytic solution $u(x,t) = \\sin{(2 \\pi x)} \\cos{(2 \\pi t)}$.\nThis function is known as a standing wave.\n\\end{problem}\n\n\\begin{problem}\nConsider the initial boundary value problem\n\\begin{align*}\n\tu_{tt} &= u_{xx}, \\\\\n\tu(0,t) &= u(1,t) = 0, \\\\\n\tu(x,0) &= .2e^{-m^2(x-1/2)^2}\\\\\n\tu_t(x,0) &= -.4m^2(x-1/2)e^{-m^2(x-1/2)^2}.\n\\end{align*}\nThe solution of this problem is a Gaussian pulse.\nIt travels to the right at a constant speed.\nThis solution models, for example, a wave pulse in a stretched string.\nNote that the fixed boundary conditions reflect the pulse back when it meets the boundary.\n\nNumerically approximate the solution $u(x,t)$ at $t = 1$ (set $m=20$).\nUse 200 subintervals in space and 220 in time, and animate your results.\nThen use 200 subintervals in space and 180 in time.\nNote that the stability condition is not satisfied for the second mesh.\n% Compare your results with the analytic solution $u(x,t) = \\sin{(2 \\pi x)} \\cos{(2 \\pi t)}$.\n\\end{problem}\n\n\\begin{problem}\nConsider the initial boundary value problem\n\\begin{align*}\n\tu_{tt} &= u_{xx}, \\\\\n\tu(0,t) &= u(1,t) = 0, \\\\\n\tu(x,0) &= .2e^{-m^2(x-1/2)^2}\\\\\n\tu_t(x,0) &= 0.\n\\end{align*}\nThe initial condition separates into two smaller, slower-moving pulses, one travelling to the right and the other to the left.\nThis solution models, for example, a plucked guitar string\n\nNumerically approximate the solution $u(x,t)$ at $t = 2$ (set $m=20$).\nUse 200 subintervals in space and 440 in time, and animate your results.\nIt is rather easy to see that the solution to this problem is the sum of two travelling waves, one travelling to the left and the other to the right, as described earlier.\nHow can the solution to the first problem also be shown to be the sum of two travelling waves?\n\\end{problem}\n\n\\begin{problem}\nConsider the initial boundary value problem\n\\begin{align*}\n\tu_{tt} &= u_{xx}, \\\\\n\tu(0,t) &= u(1,t) = 0, \\\\\n\tu(x,0) &= \\begin{cases} 1/3 & \\text{if } 5/11 < x < 6/11,\\\\\n\t0 & \\text{otherwise}\n\t\\end{cases}\\\\\n\tu_t(x,0) &= 0.\n\\end{align*}\n\nNumerically approximate the solution $u(x,t)$ at $t = 2$.\nUse 200 subintervals in space and 440 in time, and animate your results.\nEven though the method is second order and stable for this discretization, since the initial condition is discontinuous there are large dispersive errors.\nThe finite volume method can be used to smooth out the numerical solution.\n\\end{problem}\n\n\\section*{Travelling Wave Solutions of an Evolution Equation}\nRecall that the advection (transport) equation with initial conditions, given by\n\\begin{align*}\n\t&{ }u_t + su_x  = 0, \\quad -\\infty < x < \\infty, \\\\\n\t&{ }u(x,0) = f(x),\n\\end{align*}\nhas as its general solution $u(x,t) = f(x -st)$.\nConsider a general evolutionary PDE of the form\n\\begin{align}\nu_t = G(u,u_x, u_{xx}, \\ldots)\n\\label{evol_pde}\n\\end{align}\nAn interesting question to ask is whether \\eqref{evol_pde} has travelling wave solutions: 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$?\nThese travelling waves are often significant physically.\nFor example, in a PDE modelling insect population dynamics a travelling wave could represent a swarm of locusts; in a PDE describing a combustion process a travelling wave could represent an explosion or detonation.\n\n% Travelling 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 travelling 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}\nWe will examine the process of studying travelling wave solutions using Burgers' equation, a nonlinear PDE from gas dynamics.\nIt 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}\nwhere $u$ and $\\nu$ represent the velocity and viscosity of the gas, respectively.\nIt 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\nLet us look for a travelling wave solution $u(x,t) = \\hat{u}(x-st)$ for Burgers equation.\nWe 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 travelling wave is stationary in this coordinate system.\nThis new frame of reference corresponds to an observer moving along with the wave, so that the wave appears stationary as the observer studies it.\nThus, $\\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\nFrom here on we will drop the bar notation for simplicity.\nWe seek a travelling wave solution with asymptotically constant boundary conditions; that is,  $\\lim_{x \\to \\pm \\infty}\\hat{u}(x) = u_{\\pm}$\n% \\begin{align*}\n% \\lim_{x \\to -\\infty}u(x) &= u_-,\\\\\n% \\lim_{x \\to +\\infty}u(x) &= u_+\n% \\end{align*}\nboth exist, and  $\\lim_{x \\to \\pm \\infty} \\hat{u}'(x) = 0$.\nWe will suppose that $u_- > u_+ > 0$.\n\n% A travelling wave solution $u(\\xi)$ of Burgers' equation will satisfy the ordinary differential equation\n% \\[ -s u' + u u' = \\nu u''.\\]\n\nNote that to this point we still don't know the speed of the travelling wave.\nIntegrating 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*}\nThus given boundary conditions $u_{\\pm}$ at $\\pm \\infty$, the speed of the travelling wave must be $s = \\frac{u_- + u_+}{2}$.\n\nUsually at this point, the travelling wave must be numerically solved using the profile ODE (\\eqref{eqn:Burgers_ode} for Burgers equation).\nHowever, the profile ODE for Burgers is simple enough that it is possible to obtain an analytic solution.\nThe travelling 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)\\]\nwhere $a = (u_- - u_+)/2$ and $\\delta$ is fixed real number.\nWe get a family of solutions because any translation of a travelling wave solution is also a travelling wave solution.\n\n\\subsection*{Stability of travelling waves}\nSuppose that an evolutionary PDE\n\\begin{align}\nu_t = G(u,u_x, u_{xx}, \\ldots).\n\\label{eqn:evol_pde_repeat}\n\\end{align}\nhas a travelling wave solution $u(x,t) = \\hat{u}(x-st)$.\nAn interesting question to consider is whether the mathematical solution, $\\hat{u}$, has a physical analogue.\nIn other words, does the travelling wave show up in real life?\nThis question is the start of the mathematical study of stability of travelling waves.\n\nWe begin by translating \\eqref{eqn:evol_pde_repeat} into the moving frame $(x,t) \\to (\\bar{x},\\bar{t}) = (x-st, t)$.\nIn this frame the PDE becomes\n\\begin{align*}\nu_t - su_x = G(u,u_x, u_{xx}, \\ldots).\n\\end{align*}\nIn these coordinates the travelling wave is stationary.\nThus, the solution of\n\\begin{align*}\n\\begin{split}\nu_t - su_x &= G(u,u_x, u_{xx}, \\ldots), \\\\\nu(x,t = 0) &= \\hat{u}(x),\n\\end{split}\n\\end{align*}\nis given by $u(x,t) = \\hat{u}(x)$.\nWe say that the travelling 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}\nu_t - su_x &= G(u,u_x, u_{xx}, \\ldots), \\\\\nu(x,t = 0) &= v(x),\n\\end{split}\n\\end{align*}\nconverges to some translation of $\\hat{u}$ as $t \\to \\infty$.\nUsing this definition to prove stability of a travelling wave is a nontrivial task.\n\n\\subsection*{Visualizing stability of the travelling wave solution of Burgers' equation}\nThe travelling wave solution of Burgers' equation is a stable wave.\nTo view this numerically, we discretize the PDE\n\\[u_t -su_x + uu_x = u_{xx}\\]\nusing 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\nD_{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\nSubstituting 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*}\nU_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*}\nwhere $K_1 = \\frac{ \\triangle t }{4 \\triangle x}$ and $K_2 = \\frac{ \\triangle t}{2(\\triangle x)^2}$.\n\n\\begin{problem}\nNumerically 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*}\nfor $t \\in [0,1]$.\nLet the perturbation $v(x)$ be given by\n\\[v(x) = 3.5(\\sin{(3x)} + 1)\\frac{1}{\\sqrt{2\\pi}} \\exp{(-x^2/2)}\\]\nAnd let the initial condition be $u(x, 0) = \\hat{u}(x) + v(x)$\nApproximate 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$.\nUse 150 intervals in space and 350 steps in time.\nAnimate your results.\nYou should see the solution converge to a translate of the travelling wave $\\hat{u}$.\n\nHint: This difference scheme is no longer a linear equation.\nWe have a nonlinear equation in $U^{n+1}$.\nWe can still solve this function using Newton's method or some other similar solver.\nIn this case, use \\li{scipy.optimize.fsolve}.\n\\end{problem}", "meta": {"hexsha": "46b81422f8124992e853530af7456d14d8e163d1", "size": 17197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/WaveEqn/waveeqn.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/WaveEqn/waveeqn.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/WaveEqn/waveeqn.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.5732087227, "max_line_length": 241, "alphanum_fraction": 0.656393557, "num_tokens": 6236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6166080321486744}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb,amsthm,commath,mathtools}\n\\usepackage[margin=1in]{geometry}\n\\usepackage[english]{babel}\n\\usepackage{subcaption}\n\\usepackage{graphicx}\n\n\\usepackage{opexpl}\n\\usepackage{parskip}\n\n\\usepackage{hyperref}\n\n\\author{Vincent Kuhlmann}\n\\title{Opexpl demonstration}\n\\begin{document}\n\t\\maketitle\n\n\\section{In center of mass frame}\n\tIn the center of mass there is\n\\begin{align*}\n\t&m_1v_{1,m} + m_2v_{2,m} = 0\\\\\n\t&m_1v_{1,m}^2 + m_2v_{2,m}^2 = 2\\dfrac{m_1m_2^2gd + m_1^2m_2gd}{(m_1 + m_2)^2}.\n\\end{align*}\n\n\tFrom this we solve\n\\begin{align*}\n\t&\\hphantom{{}\\implies{}}{}m_2^2v_{2,m}^2/m_1 + m_2v_{2,m}^2 = 2\\dfrac{m_1m_2^2gd + m_1^2m_2gd}{(m_1 + m_2)^2}\\\\\n\t&\\implies v_{2,m}^2 = \\dfrac{2}{m_2^2/m_1 + m_2}\\dfrac{m_1m_2^2gd + m_1^2m_2gd}{(m_1 + m_2)^2}\\\\\n\t%\t\t&\\implies v_{2,m} = \\dfrac{\\sqrt{m_1^2m_2^2 + m_1^3m_2}\\sqrt{2gd}}{\\sqrt{m_2^2 + m_2m_1}\\left(m_1 + m_2\\right)}\\\\\n\t&\\optag{op:posRootv2m}\\implies v_{2,m} = \\dfrac{m_1}{m_1 + m_2}\\sqrt{2gd}\\dfrac{\\sqrt{m_1m_2^2 + m_1^2m_2}}{\\sqrt{m_1m_2^2 + m_1^2m_2}} = \\dfrac{m_1}{m_1 + m_2}\\sqrt{2gd}\\\\\n\t&\\implies v_{2,m} - v_{1,m} = \\left(1 + m_2/m_1\\right)\\dfrac{m_1}{m_1 + m_2}\\sqrt{2gd}\\\\\n\t&\\implies v_{2,m} - v_{1,m} = \\sqrt{2gd}.\n\\end{align*}\n\\opexpl{op:posRootv2m}{We can't have $ v_{2,m} < 0 $, because conservation of momentum would imply $ v_{1,m} \\geq 0 > v_{2,m} $, meaning particle~1 goes right through particle~2. This is not allowed here.}\n\n%\t\\begin{OpExplMult}\n%\t\t\\ExplItem aa\n%\t\\end{OpExplMult}\n\n%\t\\begin{align*}\n%\t\t&\\implies v_{2,m} - v_{1,m} = \\dfrac{m_1 + m_2}{m_1}\\dfrac{\\sqrt{m_1^2m_2^2 + m_1^3m_2}\\sqrt{2gd}}{\\sqrt{m_2^2 + m_2m_1}\\left(m_1 + m_2\\right)}\\\\\n%\t\t&\\implies v_{1,m} + v_{2,m} = \\left(m_1 - m_2\\right)\\dfrac{\\sqrt{m_2 + m_1}}{\\sqrt{m_2 + m_1}}\\dfrac{\\sqrt{2gd}}{m_1 + m_2}\\\\\n%\t\t&\\implies v_{1,m} + v_{2,m} = \\dfrac{m_1 - m_2}{m_1 + m_2}\\sqrt{2gd}.\n%\t\\end{align*}\n\nThis is the relative speed between the particles.\n\n\\section{In restframe of particle 2 before collision}\nWe see\n\\begin{align*}\n\t&m_1v_1^2 + m_2v_2^2 = 2m_1gd\\\\\n\t&m_1v_1 + m_2v_2 = m_1\\sqrt{2gd}\\\\\n\t&\\implies m_2v_2^2 + \\dfrac{1}{m_1}\\left(m_1\\sqrt{2gd} - m_2v_2\\right)^2 = 2m_1gd\\\\\n\t&\\implies m_1m_2v_2^2 - 2m_1m_2\\sqrt{2gd}v_2 + m_2^2v_2^2 = 0\\\\\n\t&\\implies (v_2 = 0)\\mbox{ of }\\left(v_2(m_1 + m_2) = 2m_1\\sqrt{2gd}\\right)\\\\\n\t&\\optag{op:posv2}\\implies v_2(m_1 + m_2) = 2m_1\\sqrt{2gd}.\n\\end{align*}\n\\opexpl{op:posv2}{We need $ v_2 > 0 $ because of conservation of momentum, and the fact particle~1 can't go right through particle~2.}\n\n\tThis yields\n\\begin{align*}\n\t&v_2 - v_1 = (1 + m_2/m_1)v_2 - \\dfrac{1}{m_1}\\left(m_1v_1 + m_2v_2\\right)\\\\\n\t&\\implies v_2 - v_1 = (1 + m_2/m_1)v_2 - \\sqrt{2gd}\\\\\n\t&\\implies %(v_2 - v_1 = -\\sqrt{2gd})\\mbox{ of }\n\tv_2 - v_1 = 2\\sqrt{2gd} - \\sqrt{2gd} = \\sqrt{2gd}.\n\\end{align*}\n\n\\end{document}\n", "meta": {"hexsha": "8c070bc28944a67b6312b9ba8134cd10255a903d", "size": 2824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "demo.tex", "max_stars_repo_name": "vkuhlmann/opexpl", "max_stars_repo_head_hexsha": "3b7b1a91e09c447720ac4694263c52ecdcf2ebb2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo.tex", "max_issues_repo_name": "vkuhlmann/opexpl", "max_issues_repo_head_hexsha": "3b7b1a91e09c447720ac4694263c52ecdcf2ebb2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "demo.tex", "max_forks_repo_name": "vkuhlmann/opexpl", "max_forks_repo_head_hexsha": "3b7b1a91e09c447720ac4694263c52ecdcf2ebb2", "max_forks_repo_licenses": ["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.7746478873, "max_line_length": 205, "alphanum_fraction": 0.6497875354, "num_tokens": 1453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6166080319550351}}
{"text": "\\chapter{Feature Selection \\label{chapter:featureselection}}\n\nModern clinical datasets tend to suffer from an overabundance of features. In fact, there are often more available features than there are training examples. Not all of these features will contribute equal information about the outcome. Including dozens or hundreds of predictors in a supervised learning model does not guarantee higher accuracy; in fact, it is more likely to lead to models that are unnecessarily complex and overfit (see Chapter~\\ref{chapter:biasvariance}). Even when features are related to the outcome, they may contribute information that is redundant with other features in the study. \n\nIn cases like these, the model designer will either need to choose a subset of features manually or incorporate some form of \\textbf{feature selection}: a process that automatically or semi-automatically decides which features are most relevant to the model and discards the others. The goal of feature selection is to remove useless and redundant features in a principled way. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Example: The Pima Indians Dataset}\n\nThe so-called ``Pima Indians diabetes dataset'' was collected in the 1980s. It includes information on 768 women from the Pima people, who live near Phoenix, Arizona. The Pima were, as of the late 1980s, under continuous study by the National Institute of Diabetes and Digestive and Kidney Diseases because of their high incidence of diabetes\\footnote{The causative factors behind this high diabetes rate are not clear. Some scholars believe that it was driven by a sudden shift in diet during the last century from traditional agricultural crops to processed foods, together with a decline in physical activity \\cite{schulz2006effects}.}. There are eight predictors in the dataset and one outcome. The predictors are:\n\\begin{center}\n\\texttt{ \\small\n\\begin{tabular}{lp{0.6\\textwidth}}\n\\toprule\nPredictor & Description \\\\\n\\midrule\nPregnancies & Number of times pregnant \\\\\nGlucose & Plasma glucose concentration in a two-hour oral glucose tolerance test \\\\\nBloodPressure & Diastolic blood pressure (mm Hg) \\\\\nSkinThickness & Triceps skin fold thickness (mm) \\\\\nInsulin & Two-hour serum insulin ($\\mu$U/mL) \\\\\nBMI & Body mass index (weight in kg/(height in m)$^2$) \\\\\nDiabetesPedigreeFunction & Diabetes pedigree function (developed by research team; described in paper) \\\\\nAge & Age in years \\\\\n\\bottomrule\n\\end{tabular}\n}\n\\end{center}\n\nThe outcome is whether or not the woman went on to develop type II diabetes within $5$~years from the time of the survey. \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Correlograms}\n\nFor datasets with a manageable number of features, A good way to alert oneself to the presence of highly correlated predictors is to create a \\textbf{correlogram}, or scatterplot matrix, which looks at associations between all pairs of variables. A correlogram for the Pima dataset is below.\n\n\\begin{center}\n\\includegraphics[width=\\textwidth]{img/pima-ggpairs.png}\n\\end{center}\n\n\\begin{question}{}\nThis correlogram quantifies correlation using a metric called the \\textbf{Pearson correlation coefficient}. Which pairs of predictors are the most tightly correlated? Are they positively or negatively correlated? How might you modify your dataset to eliminate redundancies in the information contributed by the different predictors?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Univariate vs. Multivariate Models \\label{section:redund}}\n\nThe presence of correlations will affect different types of models in different ways, and some suffer more than others. In the clinical research literature, the standard approach to assessing and accounting for correlations is to start with \\textbf{univariate} models, in which each predictor's association with the outcome is studied on its own. Those predictors that display some association with the outcome are then incorporated into larger \\textbf{multivariate} models.\n\nHere are the results of eight univariate logistic regression models that capture the effect of each predictor in the Pima dataset on the outcome of diabetes vs. no diabetes. The coefficients on each predictor are called the \\textbf{unadjusted} coefficients, and the p-values on the predictor-specific hypothesis tests are called unadjusted $p$-values. The exponentiated coefficients are called unadjusted odds ratios\\footnote{See Chapter~\\ref{chapter:logreg} if you don't understand why you're exponentiating or where the term ``odds ratio'' comes from. The odds ratio compares the odds of having a positive outcome among two groups separated by a one unit difference of the predictor in question, all else being the same.}.\n\\vspace{-3mm}\n\n\\begin{center} \n\\texttt{ \\small\n\\begin{tabular}{llll}\n\\toprule\nPredictor & Unadjusted  & Unadjusted  & Unadjusted  \\\\\n& Coefficient & Odds Ratio & P-value \\\\\n\\midrule\nPregnancies & 0.137 & 1.147 & $<$0.001 \\\\\nGlucose & 0.038 & 1.039 & $<$0.001 \\\\\nBloodPressure & 0.007 & 1.007 & 0.073 \\\\\nSkinThickness & 0.010 & 1.010 & 0.039 \\\\\nInsulin & 0.002 & 1.002 & $<$0.001 \\\\\nBMI & 0.094 & 1.100 & $<$0.001 \\\\\nDiabetesPedigreeFunction & 1.083 & 2.953 & $<$0.001 \\\\\nAge & 0.042 & 1.043 & $<$0.001 \\\\\n\\bottomrule\n\\end{tabular}\n}\n\\end{center}\n\nNow, here is a multivariate logistic regression model that includes all eight predictors. The coefficients, exponentiated coefficients, and p-values are often called \\textbf{adjusted}. \n\n\\vspace{-3mm}\n\\begin{center} \n\\texttt{ \\small\n\\begin{tabular}{llll}\n\\toprule\nPredictor & Adjusted  & Adjusted  & Adjusted  \\\\\n& Coefficient & Odds Ratio & P-value \\\\\n\\midrule\nPregnancies & 0.123 & 1.131 & $<$0.001 \\\\\nGlucose & 0.035 & 1.036 & $<$0.001 \\\\\nBloodPressure & -0.013 & 0.987 & 0.011 \\\\\nSkinThickness & 0.001 & 1.001 & 0.929 \\\\\nInsulin & -0.001 & 0.999 & 0.186 \\\\\nBMI & 0.090 & 1.094 & $<$0.001 \\\\\nDiabetesPedigreeFunction & 0.945 & 2.573 & 0.002 \\\\\nAge & 0.015 & 1.015 & 0.111 \\\\\n\\bottomrule\n\\end{tabular}\n}\n\\end{center}\n\nAlternatively, one might say that the odds ratios here measure the effect of each predictor, \\textbf{controlling for} the effects of the other predictors.\n\n\\begin{question}{}\nHow can the odds ratio for Insulin be so close to 1.0 yet its p-value so low? (Hint: See Section~\\ref{section:sehyp}.)\n\\end{question}\n\n\\begin{question}{}\nWhy might the coefficient and p-value for SkinThickness change so much in the shift from unadjusted to adjusted? \n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Filter Methods}\n\nThe approach of creating univariate models and then incorporating the best-performing predictors into multivariate models is part of a broader class of feature selection methods called \\textbf{filter methods}. Filter methods select subsets of variables as a preprocessing step, independently of the  supervised learning model that will eventually be implemented. These methods use \\textbf{proxy measures} to rank variables; the proxy measure is often chosen to be computationally fast so that large numbers of features can be sifted through quickly.\n\nA predetermined threshold of the proxy measure is usually used to determine which features pass to the multivariate modeling stage. Alternatively, the modeler may decide on a fixed number of features to include. Some examples of filter methods include:\n\n\\begin{itemize}\n\\item Any kind of univariate model (e.g. univariate logistic or linear regression)\n\\item Any kind of hypothesis test (e.g. t-test, chi-squared test; see Chapter~\\ref{chapter:hypothesistesting})\n\\item Any kind of correlation coefficient (e.g. Pearson, Spearman)\n\\item Mutual information\\footnote{The mutual information, in another format, is the most common splitting criterion used for decision trees; see Chapter~\\ref{chapter:decisiontrees}. In the case of continuous variables, the sums are replaced by integrals.} \n$$ MI(X_i,Y) = \\sum_x \\sum_y P(X_i = x, Y = y) \\log \\frac{P(X_i = x, Y = y)}{P(X_i = x) P(Y = y)} $$\n\\item Variance thresholding (simply remove features with low variance)\n\\end{itemize}\n\n\\begin{question}{}\nIf you wanted to use the univariate logistic regression models above in Section~\\ref{section:redund} as a filter for a downstream model (potentially not even multivariate logistic regression - it could be a decision tree, etc.), how would you rank them and how would you decide on an appropriate cutoff? \n\\end{question}\n\n\\begin{question}{}\nHow would you apply a filter-based selection method in a case where you had dozens of different predictors of different types (e.g. some categorical, some binary, some numeric)? \n\\end{question}\n\n\\begin{question}{}\nHow might you choose the appropriate threshold for a filter-based method in a data-driven way? \n\\end{question}\n\n\\begin{question}{}\nWhat is problematic about testing each potential feature, one at a time?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Wrapper Methods}\n\nFilter methods are just one possible approach to feature selection. An alternative to filter methods are \\textbf{wrapper methods}. These methods use a search algorithm to traverse the space of possible features, evaluating each subset by running the chosen model using that subset. They are generally computationally intensive (e.g., imagine trying to find the optimal subset of 10,000 features, or even 50) so \\textbf{heuristics} generally have to be used to pare down the search space. Some examples of wrapper methods include:\n\n\\begin{itemize}\n\\item \\textbf{Exhaustive search.} Try all possible subsets of features. If there are $m$ features, this means trying $2^m$ possible subsets.\n\\item \\textbf{Forward selection.} Start with a baseline (e.g., intercept only) model. Add in each of $m$ possible predictors individually and take the best one based on some performance criterion. Repeat, adding one predictor at each step, until the performance criterion stops getting better or you run out of predictors. \n\\item \\textbf{Backward elimination.} Start with a complete model (all predictors included). Try removing each predictor and take the one whose removal causes the performance criterion to increase the most. Repeat, removing one predictor at each step, until the performance criterion stops getting better or you are left with no predictors (null model). \n\\item \\textbf{Forward-backward selection.} A combination of forward selection and backward elimination. \n\\item \\textbf{Simulated annealing.} Add or remove predictors with some probability depending on how well the model is doing. At each stage, if the new model is better, accept it; it becomes the new baseline. If the new model is worse, accept it with some probability, $p$, that decreases over time according to a ``cooling schedule''. This helps prevent the variable selection process from getting stuck in local optima. \n\\end{itemize}\n\n\\begin{question}{}\nWhy is exhaustive search problematic for almost any reasonably sized $m$?\n\\end{question}\n\n\\vspace{2mm}\n\n\\begin{question}{}\nHere is the output of forward selection for the Pima example, using R's \\emph{MASS} package and the \\textbf{Akaike Information Criterion (AIC)} as the model performance metric.\n{\\footnotesize\n\\begin{verbatim}\nStart:  AIC=995.48\nOutcome ~ 1\n                           Df Deviance    AIC\n+ Glucose                   1   808.72 812.72\n+ BMI                       1   920.71 924.71\n+ Age                       1   950.72 954.72\n+ Pregnancies               1   956.21 960.21\n+ DiabetesPedigreeFunction  1   970.86 974.86\n+ Insulin                   1   980.81 984.81\n+ SkinThickness             1   989.19 993.19\n+ BloodPressure             1   990.13 994.13\n<none>                          993.48 995.48\n\nStep:  AIC=812.72\nOutcome ~ Glucose\n\n                           Df Deviance    AIC\n+ BMI                       1   771.40 777.40\n+ Pregnancies               1   784.95 790.95\n+ DiabetesPedigreeFunction  1   796.99 802.99\n+ Age                       1   797.36 803.36\n<none>                          808.72 812.72\n+ SkinThickness             1   807.07 813.07\n+ Insulin                   1   807.77 813.77\n+ BloodPressure             1   808.59 814.59\n\nStep:  AIC=777.4\nOutcome ~ Glucose + BMI\n\n                           Df Deviance    AIC\n+ Pregnancies               1   744.12 752.12\n+ Age                       1   755.68 763.68\n+ DiabetesPedigreeFunction  1   762.87 770.87\n+ Insulin                   1   767.79 775.79\n+ BloodPressure             1   769.07 777.07\n<none>                          771.40 777.40\n+ SkinThickness             1   770.20 778.20\n\nStep:  AIC=752.12\nOutcome ~ Glucose + BMI + Pregnancies\n\n                           Df Deviance    AIC\n+ DiabetesPedigreeFunction  1   734.31 744.31\n+ BloodPressure             1   738.43 748.43\n+ Age                       1   742.10 752.10\n<none>                          744.12 752.12\n+ Insulin                   1   742.43 752.43\n+ SkinThickness             1   743.60 753.60\n\nStep:  AIC=744.31\nOutcome ~ Glucose + BMI + Pregnancies + \n          DiabetesPedigreeFunction\n\n                Df Deviance    AIC\n+ BloodPressure  1   728.56 740.56\n+ Insulin        1   731.51 743.51\n<none>               734.31 744.31\n+ Age            1   732.51 744.51\n+ SkinThickness  1   733.06 745.06\n\nStep:  AIC=740.56\nOutcome ~ Glucose + BMI + Pregnancies + \n          DiabetesPedigreeFunction + \n          BloodPressure\n\n                Df Deviance    AIC\n+ Age            1   725.46 739.46\n+ Insulin        1   725.97 739.97\n<none>               728.56 740.56\n+ SkinThickness  1   728.00 742.00\n\nStep:  AIC=739.46\nOutcome ~ Glucose + BMI + Pregnancies + \n          DiabetesPedigreeFunction + \n          BloodPressure + Age\n\n                Df Deviance    AIC\n+ Insulin        1   723.45 739.45\n<none>               725.46 739.46\n+ SkinThickness  1   725.19 741.19\n\nStep:  AIC=739.45\nOutcome ~ Glucose + BMI + Pregnancies + \n          DiabetesPedigreeFunction + \n          BloodPressure + Age + Insulin\n\n                Df Deviance    AIC\n<none>               723.45 739.45\n+ SkinThickness  1   723.45 741.45\n\\end{verbatim} \n}\nWhat does the final model look like? Which predictor is missing from the final model? Note: AIC is an estimate of out-of-sample prediction error and depends on the likelihood; thus it does not work for models that do not calculate some form of likelihood.\n\\end{question}\n\n\\vspace{2mm}\n\n\\begin{question}{}\nHere is the output of backward selection for the Pima example, again using R's \\emph{MASS} package and AIC as the model performance metric.\n{\\footnotesize\n\\begin{verbatim}\nStart:  AIC=741.45\nOutcome ~ Pregnancies + Glucose + BloodPressure + SkinThickness + \n    Insulin + BMI + DiabetesPedigreeFunction + Age\n\n                           Df Deviance    AIC\n- SkinThickness             1   723.45 739.45\n- Insulin                   1   725.19 741.19\n<none>                          723.45 741.45\n- Age                       1   725.97 741.97\n- BloodPressure             1   729.99 745.99\n- DiabetesPedigreeFunction  1   733.78 749.78\n- Pregnancies               1   738.68 754.68\n- BMI                       1   764.22 780.22\n- Glucose                   1   838.37 854.37\n\nStep:  AIC=739.45\nOutcome ~ Pregnancies + Glucose + BloodPressure + Insulin + BMI + \n    DiabetesPedigreeFunction + Age\n\n                           Df Deviance    AIC\n<none>                          723.45 739.45\n- Insulin                   1   725.46 739.46\n- Age                       1   725.97 739.97\n- BloodPressure             1   730.13 744.13\n- DiabetesPedigreeFunction  1   733.92 747.92\n- Pregnancies               1   738.69 752.69\n- BMI                       1   768.77 782.77\n- Glucose                   1   840.87 854.87\n\\end{verbatim}\n}\nWhat does the final model look like? How does it compare to the model obtained through forward selection?\n\\end{question}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Embedded Methods}\n\nThe third and final class of feature selection methods are called \\textbf{embedded methods}. Embedded methods perform feature selection during the process of model training. They are usually specific to a particular type of model. \n\n\\subsection{Decision Trees}\n\nOne example of an embedded method is a decision tree (see Chapters~\\ref{chapter:decisiontrees}, \\ref{chapter:randomforests}, and \\ref{chapter:boosting}), which implicitly performs feature selection by placing the most informative predictors at the top of the tree and ignoring those that are unassociated with the outcome. \n\n\\vspace{2mm}\n\n\\begin{question}{}\nHere is the decision tree produced by CART, using information gain/mutual information as the splitting criterion as usual:\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/pima-decision-tree.png}\n\\end{center}\nWhich features were selected for this tree and which were ignored? How were the features transformed from their original forms in the dataset?\n\\end{question}\n\n\\subsection{Regularized Models}\n\nAnother example of an embedded method is \\textbf{regularization}. The easiest way to understand regularization is through our discussion of maximum likelihood estimation for GLMs in Chapter~\\ref{chapter:glms}. The goal of maximum likelihood estimation is to find the set of model coefficients, $\\beta$s, that maximize the joint probability (likelihood) of our observed data given the model. The trouble with this is that more complex models, with more parameters, will generally fit the data better: i.e. produce a higher likelihood.\n\nRegularization addresses this by introducing a penalty term on the likelihood that is proportional to the size of the parameters. In $L_1$ regularization, a.k.a. \\textbf{Lasso}, the penalty term is proportional to the absolute values of the coefficients. It looks like this:\n$$ \\lambda \\sum_{j=1}^p \\vert \\beta_j \\vert $$\nwhere $p$ is the number of predictors. This creates a tradeoff in the model between the likelihood and the number of parameters. During optimization, the model will set the coefficients on predictors to zero if including those predictors does not sufficiently improve the likelihood. The relative importance of the penalty term and likelihood is adjusted using the parameter $\\lambda$. We will see regularized regression methods in much greater detail in Chapter~\\ref{chapter:lassoridge}. \n\n\\vspace{2mm} \n\n\\begin{question}{}\nHere is the raw model output from the multivariate logistic regression model that includes all eight predictors:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/cor-example-multivar.png}\n\\end{center}\nNow let's consider what happens when we use a $L_1$ regularized logistic regression model, produced using the R package \\emph{glmnet}. Here is what happens to the model's error (assessed using $10$-fold cross validation; measured using a metric called \\textbf{binomial deviance}) when we vary $\\lambda$:\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{img/pima-glmnet-plot.png}\n{\\small\n\\begin{verbatim}\nMeasure: Binomial Deviance \n\n      Lambda Measure      SE Nonzero\nmin 0.004468  0.9686 0.02647       7\n1se 0.028723  0.9922 0.02118       5\n\\end{verbatim}\n}\n\\end{center}\nWe choose $\\lambda$ to be equal to the value that produces the minimum deviance. Here are the coefficients of the final model:\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{img/pima-glmnet-output.png}\n\\end{center}\nCompare this output to the results of models obtained through forward and backward selection methods, as well as to the full (unregularized) logistic regression model. What are the advantages and disadvantages of the regularization approach vs. wrappers and filters?\n\\end{question}\n", "meta": {"hexsha": "673c798a10db6bdcb0cbead275a6d9bd79086040", "size": 19735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-feature-selection.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-feature-selection.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-feature-selection.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": 55.9065155807, "max_line_length": 724, "alphanum_fraction": 0.7067646314, "num_tokens": 4974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799928951399098, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6166080281057466}}
{"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 XV 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{Double Integrals over General Regions $-$ 15.2}\n\nFirst of all, $f$ must be continuous on a region $D$:\n\n$$\\{(x,y)|a\\leq x\\leq b, g_1(x)\\leq y\\leq g_2(x)\\}$$\n\nSuch regions are categorized as Type I, and may be found using the following:\n\n$$\\iint_D f(x,y)\\,dA=\\int_a^b\\int_{g_1(x)}^{g_2(x)} f(x,y)\\,dy\\,dx$$\n\nA Type II equation must meet the same criteria as Type I, but with functions of $x$:\n\n$$\\{(x,y)|c\\leq y\\leq d, h_1(x)\\leq x\\leq h_2(x)\\}$$\n\nSuch regions may be solved using the following:\n\n$$\\iint_D f(x,y)\\,dA=\\int_c^d\\int_{h_1(y)}^{h_2(y)} f(x,y)\\,dx\\,dy$$\n\nIf the region, $D$, is neither Type I nor II, then the regions may be broken into two parts, $D_1$ and $D_2$:\n\n$$\\iint_D f(x,y)\\,dA=\\iint_{D_1} f(x,y)\\,dA+\\iint_{D_2} f(x,y)\\,dA$$\n\nFurthermore, if the function being integrated is a constant, $c$, then:\n\n$$\\iint_D c\\,dA=cA(D)$$\n\nWhere $A(D)$ represents the area of the region $D$\n\nThis property may be used if $m\\leq f(x,y)\\leq M$ to achieve:\n\n$$mA(D) \\leq \\iint_D f(x,y)\\,dA \\leq MA(D)$$\n\n\n\\end{document}\n", "meta": {"hexsha": "5293a9c0d376f28014d3598a33249faaa79a83f3", "size": 2454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture15.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/Lecture15.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/Lecture15.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": 27.5730337079, "max_line_length": 188, "alphanum_fraction": 0.5770171149, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754471, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.6165701018982417}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{mhchem}\n\\usepackage{stmaryrd}\n\\usepackage{graphicx}\n\\usepackage[export]{adjustbox}\n\\graphicspath{ {./images/} }\n\\usepackage{bbold}\n\n\\begin{document}\n\\section{Contents}\n1 Convolutional Neural Networks $\\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots$\n\n$1.1$ Variational problems $\\ldots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .$\n\n$1.2$ Introduction $\\ldots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .$\n\n$1.3$ Finite element methods $\\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots$\n\n1.3.1 Linear finite element $\\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots .$\n\n$1.3 .2 \\quad$ Bilinear element $\\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots$\n\nReferences $\\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots$\n\n\\includegraphics[max width=\\textwidth]{2022_01_06_c2f144dbff0f0a17cc7dg-2}\n\n\\section{Convolutional Neural Networks}\n\\subsection{Variational problems}\nLemma 1. Assume that $u$ is continuous in $(0,1)$, then the following statements are equivalent\n\n(1) $u(x)=0$.\n\n(2) $\\int_{0}^{1} u(x) v(x) d x=0$ for any smooth (compactly supported) function $v$ in $(0,1)$.\n\nDefine function $v:[0,1] \\rightarrow R$ and define space\n$$\nV=\\{v: v \\text { is continuous and } v(0)=v(1)=0\\}\n$$\nGiven any $f:[0,1] \\rightarrow R$, consider\n$$\nJ(v)=\\frac{1}{2} \\int_{0}^{1}\\left|v^{\\prime}\\right|^{2} d x-\\int_{0}^{1} f v d x\n$$\nFind $u \\in V$ such that\n$$\nu=\\underset{v \\in V}{\\arg \\min } J(v)\n$$\nwhich is equivalent to: Find $u \\in V$ such that\n$$\n\\left\\{\\begin{array}{l}\n-u^{\\prime \\prime}=f, 0<x<1, \\\\\nu(0)=u(1)=0 .\n\\end{array}\\right.\n$$\nProof. For any $v \\in V, t \\in R$, let $g(t)=J(u+t v)$. Since $u=\\arg \\min _{v \\in V} J(v)$ means $g(t) \\geq g(0) .$ Hence, for any $v \\in V, 0$ is the global minimum of the function $g(t)$. Therefore $g^{\\prime}(0)=0$ implies\n$$\n\\int_{0}^{1} u^{\\prime} v^{\\prime} d x=\\int_{0}^{1} f v d x \\quad \\forall v \\in V\n$$\nBy integration by parts, which is equivalent to\n$$\n\\int_{0}^{1}\\left(-u^{\\prime \\prime}-f\\right) v d x=0 \\quad \\forall v \\in V \\text {. }\n$$\nBy variational principal Lemma 1, we obtain\n$$\n\\left\\{\\begin{array}{l}\n-u^{\\prime \\prime}=f, 0<x<1, \\\\\nu(0)=u(1)=0 .\n\\end{array}\\right.\n$$\n$\\square$\n\nLet $V_{h}$ be finite element space and $\\left\\{\\varphi_{1}, \\varphi_{2}, \\cdots \\varphi_{n}\\right\\}$ be a nodal basis of the $V_{h} .$ Let $\\left\\{\\psi_{1}, \\psi_{2}, \\cdots, \\psi_{n}\\right\\}$ be a dual basis of $\\left\\{\\varphi_{1}, \\varphi_{2}, \\cdots \\varphi_{n}\\right\\}$, namely $\\left(\\varphi_{i}, \\psi_{j}\\right)=\\delta_{i j} .$\n$$\nJ\\left(v_{h}\\right)=\\frac{1}{2} \\int_{0}^{1}\\left|v_{h}^{\\prime}\\right|^{2} d x-\\int_{0}^{1} f v_{h} d x .\n$$\nLet\n$$\nu_{h}=\\sum_{i=1}^{n} v_{i} \\varphi\n$$\nthen\n$$\nu_{h}=\\underset{v h \\in V_{h}}{\\arg \\min } J\\left(v_{h}\\right)\n$$\nis equivalent to: Find $u_{h} \\in V_{h}$\n$$\na\\left(u_{h}, v_{h}\\right)=\\left\\langle f, v_{h}\\right\\rangle \\quad \\forall v_{h} \\in V_{h} .\n$$\nwhere\n$$\na\\left(u_{h}, v_{h}\\right)=\\int_{0}^{1} u_{h}^{\\prime} v_{h}^{\\prime} d x\n$$\nWhich is equivalent to: Find $u_{h} \\in V_{h}$\n$$\na\\left(u_{h}, v_{h}\\right)=\\left\\langle f, v_{h}\\right\\rangle \\quad \\forall v_{h} \\in V_{h},\n$$\nwhich is equivalent to solving $\\underline{A} \\mu=b$, where $\\underline{A}=\\left(a_{i j}\\right)_{i j}^{n}$ and $a_{i j}=a\\left(\\varphi_{j}, \\varphi_{i}\\right)$ and $b_{i}=\\int_{0}^{1} f \\varphi_{i} d x .$ Namely\n$$\n\\frac{1}{h}\\left(\\begin{array}{ccccc}\n2 & -1 & & & \\\\\n-1 & 2 & -1 & & \\\\\n& \\ddots & \\ddots & \\ddots & \\\\\n& & -1 & 2 & -1 \\\\\n& & & -1 & 2\n\\end{array}\\right)\\left(\\begin{array}{c}\n\\mu_{1} \\\\\n\\mu_{2} \\\\\n\\vdots \\\\\n\\mu_{n}\n\\end{array}\\right)=\\left(\\begin{array}{c}\nb_{1} \\\\\nb_{2} \\\\\n\\vdots \\\\\nb_{n}\n\\end{array}\\right) .\n$$\nWhich can be rewritten as\n$$\n\\frac{-\\mu_{i-1}+2 \\mu_{i}-\\mu_{i+1}}{h}=b_{i}, \\quad 1 \\leq i \\leq n, \\quad \\mu_{0}=\\mu_{n+1}=0\n$$\nUsing the convolution notation, (1.9) can be written as\n$$\nA * \\mu=b\n$$\nwhere $A=\\frac{1}{h}[-1,2,-1]$\n\n\\subsection{Introduction}\nLet us first briefly describe finite difference methods and finite element methods for the numerical solution of the following boundary value problem\n$$\n-\\Delta u=f, \\text { in } \\Omega, \\quad u=0 \\text { on } \\partial \\Omega, \\quad Q=(0,1)^{2} .\n$$\nFor the $x$ direction and the $y$ direction, we consider the partition:\n$$\n\\begin{aligned}\n&0=x_{0}<x_{1}<\\cdots<x_{n+1}=1, \\quad x_{i}=\\frac{j}{n+1}, \\quad(i=0, \\cdots, n+1) \\\\\n&0=y_{0}<y_{1}<\\cdots<y_{n+1}=1, \\quad y_{j}=\\frac{j}{n+1}, \\quad(j=0, \\cdots, n+1)\n\\end{aligned}\n$$\nSuch a uniform partition in the $x$ and $y$ directions leads us to a special example in two dimensions, a uniform square mesh $\\mathbb{R}_{h}^{2}=\\{(i h, j h) ; i, j \\in \\mathbb{Z}\\}$ (Figure 1.2). Let $\\Omega_{h}=\\Omega \\cap \\mathbb{R}_{h}^{2}$, the set of interior mesh points and $\\partial \\Omega_{h}=\\partial \\Omega \\cap \\mathbb{R}_{h}^{2}$, the set of boundary mesh points.\\\\\n\n\\includegraphics[max width=\\textwidth]{2022_01_06_c2f144dbff0f0a17cc7dg-5}\n\nFig. 1.1. Two-dimensional uniform grid for finite element and finite difference\n\n\\subsection{Finite element methods}\nWe consider two finite elements: continuous linear element and bilinear element. These two finite element methods find $u_{h} \\in V_{h}$ such that\n$$\n\\left(\\nabla u_{h}, \\nabla v_{h}\\right)=\\left(f, v_{h}\\right), \\forall v_{h} \\in V_{h} .\n$$\nThe above formulation can be written as\n$$\n\\underline{A u}=\\underline{f}\n$$\nwith $\\underline{A}_{(j-1) n+i,(l-1) n+k}=\\left(\\nabla \\phi_{k l}, \\nabla \\phi_{i j}\\right), f_{(j-1) n+i,(l-1) n+k}=\\left(f, \\phi_{i j}\\right) .$\n\nBasis functions $\\phi_{i j}$ satisfy\n$$\n\\phi_{i j}\\left(x_{k}, y_{l}\\right)=\\delta_{(i, j),(k, l)}\n$$\n\n\\subsubsection{Linear finite element}\nContinuous linear finite element discretization of (1.11) on the left triangulation in Fig 1.2. The discrete space for linear finite element is\n$$\n\\mathcal{V}_{h}=\\left\\{v_{h}:\\left.v_{h}\\right|_{K} \\in P_{1}(K) \\text { and } v_{h} \\text { is globally continuous }\\right\\}\n$$\nDenote $E_{i, j}=\\left[x_{i}, x_{i+1}\\right] \\times\\left[y_{i}, y_{i+1}\\right]=K_{i, j}^{U} \\cup K_{i, j}^{D} .$ For linear element case,\n\n\\includegraphics[max width=\\textwidth]{2022_01_06_c2f144dbff0f0a17cc7dg-6}\n\nIt is easy to verify that the formulation for the linear element method is\n\n(1.16) $4 u_{i, j}-\\left(u_{i+1, j}+u_{i-1, j}+u_{i, j+1}+u_{i, j-1}\\right)=f_{i, j}, \\quad u_{i, j}=0$ if $i$ or $j \\in\\{0, n+1\\}$,\n\nwhere\n$$\nf_{i, j}=\\int_{\\Omega} f(x, y) \\phi_{i, j}(x, y) \\mathrm{d} x \\mathrm{~d} y \\approx h^{2} f\\left(x_{i}, y_{j}\\right)\n$$\nProposition 1. The mapping A* has following properties\n\n    \\begin{enumerate}\n      \\item A is symmetric, namely\n    \\end{enumerate}\n$$\n(A * u, v)_{l^{2}}=(u, A * v)_{l^{2}} .\n$$\n\n    \\begin{enumerate}\n      \\setcounter{enumiii}{2}\n      \\item $(A * v, v)_{F}>0$, if $v \\neq 0$.\n\n      \\item $A * u=f$ if and only if\n\n    \\end{enumerate}\n$$\nu \\in \\underset{v \\in \\mathcal{V}_{h}}{\\arg \\min } J(v)=\\frac{1}{2}(A * v, v)-(f, v)\n$$\n\n    \\begin{enumerate}\n      \\setcounter{enumiii}{4}\n      \\item The eigenvalues $\\lambda_{k l}$ and eigenvectors $u^{k l}$ of A are given by\n    \\end{enumerate}\n$$\n\\begin{gathered}\n\\lambda_{k l}=4\\left(\\sin ^{2} \\frac{k \\pi}{2(n+1)}+\\sin ^{2} \\frac{l \\pi}{2(n+1)}\\right), \\\\\nu_{i j}^{k l}=\\sin \\frac{k i \\pi}{n+1} \\sin \\frac{l j \\pi}{n+1}, 1 \\leq i \\leq n, 1 \\leq j \\leq n,\n\\end{gathered}\n$$\nand $\\rho(A)<8 .$ Furthermore,\n$$\n\\lambda_{n, n}=8 \\cos ^{2} \\frac{\\pi}{2(n+1)} \\approx 8\\left(1-\\left(\\frac{\\pi}{2(n+1)}\\right)^{2}\\right) \\approx 8-\\frac{2 \\pi^{2}}{(n+1)^{2}}\n$$\n\n\\subsubsection{Bilinear element}\nContinuous bilinear finite element discretization of (1.11) on the right mesh in Fig. 1.2. The discrete space for linear finite element is\n$$\n\\mathcal{V}_{h}=\\left\\{v_{h}:\\left.v_{h}\\right|_{K} \\in\\{1, x, y, x y\\} \\text { and } v_{h} \\text { is globally continuous }\\right\\}\n$$\nFor bilinear element case, we have\n$$\n\\begin{aligned}\n\\left(\\nabla \\mathbf{u}_{h}, \\nabla \\mathbf{v}_{h}\\right)=& \\sum_{i, j=1}^{n} \\int_{E_{i, j}} \\nabla \\mathbf{u}_{h}, \\nabla \\mathbf{v}_{h} d x d y \\\\\n=& \\sum_{i, j=1}^{n} \\int_{E_{i, j}}\\left(\\frac{\\left(u_{i+1, j}-u_{i, j}\\right)\\left(y_{j+1}-y\\right)}{h^{2}}+\\frac{\\left(u_{i, j+1}-u_{i+1, j+1}\\right)\\left(y-y_{j}\\right)}{h^{2}}\\right) \\\\\n&\\left(\\frac{\\left(v_{i+1, j}-v_{i, j}\\right)\\left(y_{j+1}-y\\right)}{h^{2}}+\\frac{\\left(v_{i, j+1}-v_{i+1, j+1}\\right)\\left(y-y_{j}\\right)}{h^{2}}\\right) \\\\\n&+\\left(\\frac{\\left(u_{i, j+1}-u_{i, j}\\right)\\left(x_{i+1}-x\\right)}{h^{2}}+\\frac{\\left(u_{i+1, j}-u_{i+1, j+1}\\right)\\left(x-x_{i}\\right)}{h^{2}}\\right) \\\\\n=&\\left(\\frac{\\left(v_{i, j+1}-v_{i, j}\\right)\\left(x_{i+1}-x\\right)}{h^{2}}+\\frac{\\left(v_{i+1, j}-v_{i+1, j+1}\\right)\\left(x-x_{i}\\right)}{h^{2}}\\right) d x d y\n\\end{aligned}\n$$\nwhere $A=\\left(\\begin{array}{ccc}-1 & -1 & -1 \\\\ -1 & 8 & -1 \\\\ -1 & -1 & -1\\end{array}\\right)$ and $A * u$ is given by $(1.20)$\n\nAnd we have\n\n(1.20) $8 u_{i j}-\\left(u_{i+1, j}+u_{i-1, j}+u_{i, j+1}+u_{i, j-1}+u_{i+1, j+1}+u_{i-1, j-1}+u_{i-1, j+1}+u_{i+1, j-1}\\right)=f_{i, j}$, and $u_{i, j}=0$ if $i$ or $j \\in\\{0, n+1\\} .$ References\n\n\n\\end{document}", "meta": {"hexsha": "abf66f5505946b50f762e9bfc02d488741eeaa44", "size": 9280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Module4/m4_01/d01femtoconvolution_video_notes.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": "Module4/m4_01/d01femtoconvolution_video_notes.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": "Module4/m4_01/d01femtoconvolution_video_notes.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.9915966387, "max_line_length": 380, "alphanum_fraction": 0.6060344828, "num_tokens": 3905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893340314393, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6165700965015202}}
{"text": "\n\\subsection{Finding neighbours}\n\nSay we have a distance function and a sample. How can we identify the \\(k\\)-nearest neighbours?\n\nWe can find the distance for all points, sort this and take the top \\(k\\) observations.\n", "meta": {"hexsha": "9c1ae63432b78fde713b6c5bdf8b189e4b5f4646", "size": 219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/04-01-neighbours.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/distance/04-01-neighbours.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/distance/04-01-neighbours.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.2857142857, "max_line_length": 95, "alphanum_fraction": 0.7579908676, "num_tokens": 49, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933183101077, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6165700890676684}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Hyper Perplex Numbers}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn exo-2 split binion has the form\n\\begin{equation}\n    a_{0} + a_{1} S + a_{2} W + a_{3} SW + a_{4} X + a_{5} SX + a_{6} WX + a_{7} SWX\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the exo-1 split binions.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "f3a733e50011f6ccbb7a89213010c5444964ba05", "size": 2153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/Q.tex", "max_stars_repo_name": "meirizarrygelpi/plexifications", "max_stars_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_stars_repo_licenses": ["MIT"], "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/Q.tex", "max_issues_repo_name": "meirizarrygelpi/plexifications", "max_issues_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_issues_repo_licenses": ["MIT"], "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/Q.tex", "max_forks_repo_name": "meirizarrygelpi/plexifications", "max_forks_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_forks_repo_licenses": ["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.9318181818, "max_line_length": 84, "alphanum_fraction": 0.2052949373, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6165648976641062}}
{"text": "% !TeX root = main.tex\n\n\\chapter{Prefix Sum and Histogram}\n\\glsresetall\n\\label{chapter:prefixsum}\n\n\\section{Prefix Sum}\n\\label{sec:prefixSum}\n\nPrefix sum is a common kernel used in many applications, e.g., recurrence relations, \ncompaction problems, string comparison, polynomial evaluation, histogram, radix sort, and quick sort \\cite{blelloch1990prefix}. Prefix sum requires restructuring in order to create an efficient FPGA design.\n\nThe prefix sum is the cumulative sum of a sequence of numbers. Given a sequence of inputs $in_n$, the prefix sum $out_n$ is the summation of the first $n$ inputs, namely $out_n = in_0 + in_1 + in_2 + \\cdots + in_{n-1} + in_n$. The following shows the computation for the first four elements of the output sequence $out$.\n\\begin{align*} \nout_0 & = in_0 &\\\\\nout_1 & = in_0 + in_1 &\\\\\nout_2 & = in_0 + in_1 + in_2 \\\\\nout_3 & = in_0 + in_1 + in_2 + in_3 \\\\\n\\cdots\n\\end{align*}\n\nOf course, in practice we don't want to store and recompute the sum of all of the previous inputs, so the prefix sum is often computed by the recurrence equation:\n\\begin{equation}\nout_n = out_{n-1} + in_n\n\\end{equation}\n\nThe disadvantage of the recurrence equation is that we must compute $out_{n-1}$ before computing $out_n$, which fundamentally limits the parallelism and throughput that this computation can be performed.  In contrast, the original equations have obvious parallelism where each output can be computed independently at the expense of a significant amount of redundant computation.  C code implementing the recurrence equation is shown in Figure \\ref{fig:prefixsumSW}. Ideally, we'd like to achieve $II=1$ for the loop in the code, but this can be challenging even for such simple code.  Implementing this code with \\VHLS results in behavior like that shown in Figure \\ref{fig:prefixsumSW}.\n\\begin{figure}\n\\begin{minipage}{.5\\textwidth}\n\\lstinputlisting{examples/prefixsumBO.cpp}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\centering\n\\includesvg{prefixsumBO_behavior}\n\\end{minipage}\n\\caption{ Code for implementing prefix sum, and its accompanying behavior. }\n\\label{fig:prefixsumSW}\n\\end{figure}\n\nThe way this code is written, each output is written into the output memory \\lstinline|out[]| and then in the next iteration is read back out of the memory again.  Since the memory read is has a latency of one, data read from memory cannot be processed until the following clock cycle.  As a result, such a design can only achieve a loop II of 2.  In this case there is a relatively easy way to rewrite the code: we can simply perform the accumulation on a separate local variable, rather than reading the previous value back from the array.  Avoiding extra memory accesses in favor of register storage is often advantageous in processor code, but in HLS designs it is often more significant since other operations are rarely a performance bottleneck.  Code that does this is shown in Figure \\ref{fig:prefixsum_optimized}.\n\n\\begin{figure}\n\\begin{minipage}{.5\\textwidth}\n\\lstinputlisting{examples/prefixsum_optimized.cpp}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\centering\n\\includesvg{prefixsum_optimized_behavior}\n\\end{minipage}\n\\caption{ Code for implementing an optimized prefix sum, and its accompanying behavior. }\n\\label{fig:prefixsum_optimized}\n\\end{figure}\n\nYou might ask why the compiler is not able to optimize the memory loads and stores automatically in order to improve the II of the design.  It turns out that \\VHLS is capable of optimizing loads and stores to array, but only for reads and writes within the scope of a single basic block.  You can see this if we unroll the loop, as shown in Figure \\ref{fig:prefixsum_unrolled}.  Note that we also have to add appropriate \\lstinline{array_partition} s in order to be able to read and write multiple values at the interfaces.   In this case, \\VHLS is able to eliminate most of the read operations of the \\lstinline{out[]} array within the body of the loop, but we still only achieve a loop II of 2.  In this case the first load in the body of the loop is still not able to be removed.  We can, however, rewrite the code manually to use a local variable rather than read from the \\lstinline{out[]} array.\n\n\\begin{figure}\n\\begin{minipage}{.5\\textwidth}\n\\lstinputlisting{examples/prefixsum_unrolled.cpp}\n\\end{minipage}\n\\begin{minipage}{.5\\textwidth}\n\\raggedleft\n\\includesvg{prefixsum_unrolled_behavior}\n\\end{minipage}\n\\caption{ Optimizing the prefixsum code using \\lstinline{unroll}, \\lstinline{pipeline}, and \\lstinline{array_partition} directives. }\n\\label{fig:prefixsum_unrolled}\n\\end{figure}\n\n%results in the following message:\n%\\lstinputlisting[basicstyle=\\ttfamily\\footnotesize]{examples/prefixsumBO.message}\n\n%\\begin{figure}\n%\\lstinputlisting{examples/prefixsumBO.cpp}\n%\\caption{ The initial code for implementing prefix sum. }\n%\\label{fig:prefixsumSW}\n%\\end{figure}\n\nIdeally, when we unroll the inner loop, we the perform more operations per clock and reduce the interval to compute the function. If we unroll by a factor of two, then the performance doubles. A factor of four would increase the performance by factor four, i.e., the performance scales in a linear manner as it is unrolled. While this is mostly the case, as we unroll the inner loop there are often some aspects of the design that don't change.  Under most circumstances, such as when the iteration space of loops execute for a long time, these aspects represent a small fixed overhead which doesn't contribute significantly to the performance of the overall function.  However, as the number of loop iterations decreases, these fixed portions of the design have more impact.  The largest fixed component of a pipelined loop is the depth of the pipeline itself.  The control logic generate by \\VHLS for a pipelined loop requires the pipeline to completely flush before code after the loop can execute.\n\n\\begin{exercise}\nUnroll the \\lstinline{for} loop corresponding to the prefix sum code in Figure \\ref{fig:prefixsum_optimized} by different factors in combination with array partitioning to achieve a loop II of 1.  How does the \\lstinline{prefixsum} function latency change? What are the trends in the resource usages? Why do you think you are seeing these trends? What happens when the loop becomes fully unrolled?\n\\end{exercise}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .7\\textwidth]{images/architectures_prefixsum}\n\\caption{ Part a) displays an architecture corresponding to the code in Figure~\\ref{fig:prefixsumSW}. The dependence on the \\lstinline{out[]} array can prevent achieving a loop II of 1. Computing the recurrence with a local variable, as shown in the code in Figure~\\ref{fig:prefixsum_optimized}, is able to reduce the latency in the recurrence and achieve a loop II of 1.}\n\\label{fig:architecture_prefixsum}\n\\end{figure}\n\nFigure~\\ref{fig:architecture_prefixsum} shows the hardware architecture resulting from synthesizing the code from Figure \\ref{fig:prefixsumSW} and Figure~\\ref{fig:prefixsum_optimized}.   In part a), we can see that the `loop' in the circuit includes the output memory that stores the \\lstinline{out[]} array, whereas in part b), the loop in the circuit includes only a register that stores the accumulated value and the output memory is only written.  Simplifying recurrences and eliminating unnecessary memory accesses is a common practice in optimizing HLS code.\n\n%This \\lstinline{A} variable maps to a hardware register. A register is helpful because a it can be read to and written from on every cycle. Unlike a memory, which has limited number of read and write ports, the register value can be read from and subsequently sent to a large number of places that need that data on every cycle with very limited penalty. The only major issues is wire routing, which in the grand scheme of things is not much additional overhead in terms of resources. Nor does it typically incur a large penalty in terms of performance. \n\n\\note{Could add a whole part about doing reduction. Probably not necessary.}\n\\note{Should have something here about what to do with floating point accumulation.  This is fundamentally more problematic than what's above (which is relatively easily handled by improving store->load optimization.}\n\nThe goal of this section is to show that even a small changes in the code can sometimes have a significant effect on the hardware design. Some changes may not necessarily be intuitive, but can be identified with feedback from the tool.\n\n\\section{Histogram}\n\\label{sec:histogram}\n\nA Histogram models the probability distribution of a discrete signal. Given a sequence of discrete input values, the histogram counts the number of times each value appears in the sequence.  When normalized by the total number of input values, the histogram becomes the probability distribution function of the sequence.  Creating a histogram is a common function used in image processing, signal processing, database processing, and many other domains.  In many cases, it is common to quantize high-precision input data into a smaller number of intervals or \\term{bins} as part of the histogram computation.  For the purpose of this section, we will skip the actual process by which this is done and focus on what happens with the binned data.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .7\\textwidth]{images/histogram_introd}\n\\caption{ An example of a histogram.  }\n\\label{fig:histogram_introd}\n\\end{figure}\n\nFigure~\\ref{fig:histogram_introd} provides a simple example of a histogram.  The data set consists of a sequence of binned values, in this case represented by an integer in $[0,4]$. The corresponding histogram, consisting of a count for each bin, is shown below along with a graphical representation of the histogram, where the height of each bar corresponding to the count of each separate value.  Figure~\\ref{fig:histogramSW} shows baseline code for the \\lstinline{histogram} function.\n\n\\begin{figure}\n\\lstinputlisting{examples/histogramSW.cpp}\n\\caption{ Original code for calculating the histogram. The \\lstinline{for} loop iterates across the input array and increments the corresponding element of the \\lstinline{hist} array. }\n\\label{fig:histogramSW}\n\\end{figure}\n\nThe code ends up looking very similar to the prefix sum in the previous section.  The difference is that the prefix sum is essentially only performing one accumulation, while in the \\lstinline|histogram| function we compute one accumulation for each bin.  The other difference is that in the prefix sum we added the input value each time, in this case we only add 1.  When pipelining the inner loops using the \\lstinline|pipeline| directive, we return to the same problem as with the code in Figure \\ref{fig:prefixsumSW}, where we can only achieve a loop II of 2 due to the recurrence through the memory.   This is due to the fact that we are reading from the \\lstinline{hist} array and writing to the same array in every iteration of the loop.  \nFigure~\\ref{fig:architecture_histogram} shows the hardware architecture for the code in Figure~\\ref{fig:histogramSW}. You can see that the \\lstinline{hist} array has a read and write operation. The \\lstinline{val} variable is used as the index into the \\lstinline{hist} array, and the variable at that index is read out, incremented, and written back into the same location.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .5\\textwidth]{images/architectures_histogram}\n\\caption{ An architecture resulting from the code in Figure \\ref{fig:histogramSW}. The \\lstinline{val} data from the \\lstinline{in} array is used to index into the \\lstinline{hist} array. This data is incremented and stored back into the same location.}\n\\label{fig:architecture_histogram}\n\\end{figure}\n\n\\section{Histogram Optimization and False Dependencies}\nLet's look deeper at the recurrence here.  In the first iteration of the loop, we read the \\lstinline{hist} array at some location $x_0$ and write back to the same location $x_0$.  The read operation has a latency of one clock cycle, so the write has to happen in the following clock.  Then in the next iteration of the loop, we read at another location $x_1$.  Both $x_0$ and $x_1$ are dependent on the input and could take any value, so we consider the worst case when generating the circuit.  In this case, if $x_0 == x_1$, then the read at location $x_1$ cannot begin until the previous write has completed.  As a result, we must alternate between reads and writes.  \n\nIt turns out that we must alternate between reads and writes as long as $x_0$ and $x_1$ are independent.  What if they are {\\em not} actually independent?  For instance, we might know that the source of data never produces two consecutive pieces of data that actually have the same bin.  What do we do now?  If we could give this extra information to the HLS tool, then it would be able to read at location $x_1$ while writing at location $x_0$ because it could guarantee that they are different addresses.   In \\VHLS, this is done using the \\lstinline|dependence| directive.\n\nThe modified code is shown in Figure \\ref{fig:histogram_dependence}.  Here we've explicitly documented (informally) that the function has some preconditions.  In the code, we've added an \\lstinline|assert()| call which checks the second precondition.\nin \\VHLS, this assertion is enabled during simulation to ensure that the simulation testvectors meet the required precondition.  The \\lstinline|dependence| directive captures the effect of this precondition on the circuit, generated by the tool.  Namely, it indicates to \\VHLS that reads and writes to the \\lstinline|hist| array are dependent only in a particular way.  In this case, \\lstinline|inter|-iteration dependencies consisting of a read operation after a write operation (RAW) have a distance of 2.  In this case a distance of $n$ would indicate that read operations in iteration $i+n$ only depend on write operations in iteration $i$.  In this case, we assert that \\lstinline|in[i+1] != in[i]|, but it could be the case that \\lstinline|in[i+2] == in[i]| so the correct distance is 2.\n\n\\begin{figure}\n\\lstinputlisting{examples/histogram_dependence.cpp}\n\\caption{ An alternative function for computing a histogram.  By restricting the inputs and indicating this restriction to \\VHLS via the \\lstinline|dependence| directive, II=1 can be achieved without significantly altering the code. }\n\\label{fig:histogram_dependence}\n\\end{figure}\n\n\\begin{exercise}\nIn Figure \\ref{fig:histogram_dependence}, we added a precondition to the code, checked it using an assertion, and indicated the effect of the precondition to the tool using the \\lstinline|dependence| directive.  What happens if your testbench violates this precondition?  What happens if you remove the \\lstinline|assert()| call?  Does \\VHLS still check the precondition?   What happens if the precondition is not consistent with the \\lstinline|dependence| directive?\n\\end{exercise}\n\nUnfortunately, the \\lstinline{dependence} directive doesn't really help us if we are unwilling to accept the additional precondition.  It's also clear that we can't directly apply same optimization as with the \\lstinline|prefixsum| function, since we might need to use all of the values stored in the \\lstinline|hist| array.  Another alternative is implement the \\lstinline|hist| array with a different technology, for instance we could partition the \\lstinline|hist| array completely resulting in the array being implemented with \\gls{ff} resources.  Since the data written into a \\gls{ff} on one clock cycle is available immediately on the next clock cycle, this solves the recurrence problem and can be a good solution when a small number of bins are involved.  The architecture resulting from such a design is shown in Figure \\ref{fig:histogram_partitioned}.  However, it tends to be a poor solution when a large number of bins are required.  Commonly histograms are constructed with hundreds to thousands of bins and for large data sets can require many bits of precision to count all of the inputs.   This results in a large number of FF resources and a large mux, which also requires logic resources.  Storing large histograms in \\gls{bram} is usually a much better solution.\n\n\\begin{figure}\n\\centering\n\\note{fixme!}\n\\includegraphics[width=  .5\\textwidth]{images/architectures_histogram}\n\\caption{ An architecture resulting from the code in Figure \\ref{fig:histogramSW} when the \\lstinline|hist| array is completely partitioned.}\n\\label{fig:histogram_partitioned}\n\\end{figure}\n\nReturning to the code in Figure~\\ref{fig:histogramSW}, we see that there are really two separate cases that the architecture must be able to handle.  One case is when the input contains consecutive values in the same bin.  In this case, we'd like to use a simple register to perform the accumulation with a minimal amount of delay.  The second case is when the input does not contain consecutive values in the same bin, in which case we need to read, modify, and write back the result to the memory.  In this case, we can guarantee that the read operation of the \\lstinline|hist| array can not be affected by the previous write operation.   We've seen that both of these cases can be implemented separately, perhaps we can combine them into a single design.  The code to accomplish this is shown in Figure~\\ref{fig:histogramOpt1}. This code uses a local variable \\lstinline|old| to store the bin from the previous iteration and another local variable \\lstinline{accu} to store the count for that bin.  Each time through the loop we check to see if we are looking at the same bin as the previous iteration.  If so, then we can simply increment \\lstinline|accu|.  If not, then we need to store the value in \\lstinline|accu| in the \\lstinline|hist| array and increment the correct value in the \\lstinline|hist| array instead.  In either case, we update \\lstinline|old| and \\lstinline|accu| to contain the current correct values.  The architecture corresponding to this code is shown in Figure \\ref{fig:architecture_histogram_restructured}.  \n\nIn this code, we still need a \\lstinline|dependence| directive, just as in Figure \\ref{fig:histogram_dependence}, however the form is slightly different.  In this case the read and write accesses are to two different addresses in the same loop iteration.  Both of these addresses are dependent on the input data and so could point to any individual element of the \\lstinline|hist| array.  Because of this, \\VHLS assumes that both of these accesses could access the same location and as a result schedules the read and write operations to the array in alternating cycles, resulting in a loop II of 2.  However, looking at the code we can readily see that \\lstinline|hist[old]| and \\lstinline|hist[val]| can never access the same location because they are in the \\lstinline|else| branch of the conditional \\lstinline|if(old == val)|.  Within one iteration (an \\lstinline|intra|-dependence) a read operation after a write operation (\\lstinline|RAW|) can never occur and hence is a \\lstinline|false| dependence.  In this case we are not using the \\lstinline|dependence| directive to inform the tool about a precondition of the function, but instead about a property of the code itself. \n\n\\begin{figure}\n\\lstinputlisting{examples/histogram_opt1.cpp}\n\\caption{ Removing the read after write dependency from the \\lstinline{for} loop. This requires an \\lstinline{if/else} structure that may seem like it is adding unnecessary complexity to the design. However, it allows for more effective pipelining despite the fact that the datapath is more complicated. }\n\\label{fig:histogramOpt1}\n\\end{figure}\n\n\\begin{exercise}\nSynthesize the code from Figure \\ref{fig:histogramSW} and Figure \\ref{fig:histogramOpt1}. What is the initiation interval (II) in each case? What happens when you remove the \\lstinline{dependence} directive from the code in Figure \\ref{fig:histogramOpt1}? How does the loop interval change in both cases? What about the resource usage?\n\\end{exercise}\n\n\\begin{aside}\nFor the code in Figure \\ref{fig:histogramOpt1}, you might question why a tool like \\VHLS cannot determine this property.  In fact, while in some simple cases like this one better code analysis could propagate the \\lstinline|if| condition property into each branch, we must accept that there are some pieces of code where properties of memory accesses are actually undecidable.  The highest performance in such cases will only be achieved in a static schedule with the addition of user information.  Several recent research works have looked to improve this by introducing some dynamic control logic into the design\\cite{winterstein13dynamic, liu17elasticflow, dai17dynamic}.\n\\end{aside}\n\nA pictorial description of the restructured code from Figure \\ref{fig:histogramOpt1} is shown in Figure \\ref{fig:architecture_histogram_restructured}. Not all of the operations are shown here, but the major idea of the function is there. You can see the two separate \\lstinline{if} and \\lstinline{else} regions (denoted by dotted lines). The \\lstinline{acc} variable is replicated twice in order to make the drawing more readable; the actual design will only have one register for that variable.  The figure shows the two separate datapaths for the \\lstinline{if} and the \\lstinline{else} clause with the computation corresponding to the \\lstinline{if} clause on the top and the \\lstinline{else} clause datapath on the bottom. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .6\\textwidth]{images/architectures_histogram_restructured}\n\\caption{ A depiction of the datapath corresponding to the code in Figure \\ref{fig:histogramOpt1}. There are two separate portions corresponding to the \\lstinline{if} and \\lstinline{else} clauses. The figure shows the important portions of the computation, and leaves out some minor details. }\n\\label{fig:architecture_histogram_restructured}\n\\end{figure}\n\n\\section{Increasing Histogram Performance}\n\nWith some effort, we've achieved a design with a loop II of 1.  Previously we have seen how further reducing the execution time of a design can be achieved by partial unrolling of the inner loop.  However, with the \\lstinline|histogram| function this is somewhat difficult for several reasons.  One reason is the challenging recurrence, unless we can break up the input data in some fashion, the computation of one iteration of the loop must be completed with the computation of the next iteration of the loop. A second reason is that with a loop II of 1, the circuit performs a read and a write of the \\lstinline|hist| array each clock cycle, occupying both ports of a \\gls{bram} resource in the FPGA.   Previously we have considered \\gls{arraypartitioning} to increase the number of memory ports for accessing an array, but there's not a particularly obvious way to partition the \\lstinline|hist| array since the access order depends on the input data.\n\nAll is not lost, however, as there is a way we can expose more parallelism by decomposing the histogram computation into two stages.  In the first stage, we divide the input data into a number of separate partitions.  The histogram for each partition can be computed independently using a separate instance, often called a \\gls{pe}, of the histogram solution we've developed previously.  In the second stage, the individual histograms are combined to generate the histogram of the complete data sets.  This partitioning (or mapping) and merging (or reducing) process is very similar to that adopted by the MapReduce framework \\cite{dean08mapreduce} and is a common pattern for parallel computation.  The map-reduce pattern is applicable whenever there is recurrence which includes a commutative and associative operation, such as addition in this case. This idea is shown in Figure~\\ref{fig:architecture_histogram_parallel}. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .9\\textwidth]{images/architectures_histogram_parallel}\n\\caption{The histogram computation implemented using a map-reduce pattern.  The processing element (PE) in Part a) is the same architecture as shown in Figure \\ref{fig:architecture_histogram_restructured}. The \\lstinline|in| array is partitioned and each partition is processed by a separate \\gls{pe}. The merge block combines the individual histograms to create the final histogram.  }\n\\label{fig:architecture_histogram_parallel}\n\\end{figure}\n\nThe code for implementing this architecture is shown in Figure \\ref{fig:histogram_parallel}. The \\lstinline{histogram_map} function implements the `map' portion of the map-reduce pattern and will be instantiated multiple times. The code is very similar to the code in Figure \\ref{fig:histogramOpt1}. The main difference is that we have added the additional code to initialize the \\lstinline|hist| array.  The \\lstinline{histogram_map} function takes an input array \\lstinline{in} which will contain a partition of the data being processed and computes the histogram of that partition in the \\lstinline|hist| array.   The \\lstinline{histogram_reduce} function implements the `reduce' portion of the pattern.  It takes as input a number of partial histograms and combines them into complete histogram by adding together the count for each histogram bin.  In our code example in Figure \\ref{fig:histogram_parallel}, we have only two processing elements, thus the merge has two input arrays \\lstinline{hist1} and \\lstinline{hist2}. This can easily be extended to handle more processing elements.\n\nThe new \\lstinline{histogram} function takes as an input two partitions of the input data, stored in the \\lstinline{inputA} and \\lstinline{inputB} arrays.  It computes the histogram of each partition using the \\lstinline {histogram_map} function, which are then stored in the \\lstinline{hist1} and \\lstinline{hist2} arrays. These are feed into the \\lstinline{histogram_reduce} function which combines them and stores the result in the \\lstinline{hist} array, which is the final output of the top level function \\lstinline{histogram}. \n\n\\begin{figure}\n\\lstinputlisting{examples/histogram_parallel.cpp}\n\\caption{ Another implementation of histogram that uses task level parallelism and pipelining. The histogram operation is split into two sub tasks, which are executed in the two \\lstinline{histogram_map} functions. These results are combined in the final histogram result using the \\lstinline{histogram_reduce} function. The \\lstinline{histogram} function is the top level function that connects these three functions together. }\n\\label{fig:histogram_parallel}\n\\end{figure}\n\n\\begin{exercise}\nModify the code in Figure \\ref{fig:histogram_parallel} to support a parameterizable number \\lstinline|NUM_PE| of \\glspl{pe}? Hint: You'll need to combine some of the arrays into a single array that is correctly partitioned and add some loops that depend on \\lstinline|NUM_PE|.  What happens to the throughput and task interval as you vary the number of \\glspl{pe}? \n\\end{exercise}\n\nWe use the \\lstinline{dataflow} directive in the \\lstinline{histogram} function in order to enable a design with \\gls{taskpipelining}.   In this case there are three processes: two instances of the \\lstinline{histogram_map} function and one instance of the \\lstinline{histogram_reduce} function. Within a single task, the two \\lstinline{histogram_map} processes can execute concurrently since they work on independent data, while the \\lstinline{histogram_reduce} function must execute after since it uses the results from the  \\lstinline{histogram_map} processes. Thus, the \\lstinline{dataflow} directive essentially creates a two stage task pipeline with the \\lstinline{histogram_map} functions in the first stage and the \\lstinline{histogram_reduce} function in the second stage.   As with any dataflow design, the interval of the entire \\lstinline{histogram} function depends upon the maximum initiation interval of the two stages. The two \\lstinline{histogram_map} functions in the first stage are the same and will have the same interval ($II_\\mathrm{histogram\\_map}$). The \\lstinline{histogram_reduce} function will have another interval ($II_\\mathrm{histogram\\_reduce}$). The interval of the toplevel \\lstinline{histogram} function $II_\\mathrm{histogram}$ is then $\\max (II_\\mathrm{histogram\\_map}, II_\\mathrm{histogram\\_reduce})$.\n\n\\begin{exercise}\nWhat happens when you add or change the locations of the \\lstinline{pipeline} directives? For example, is it beneficial to add a \\lstinline{pipeline} directive to the \\lstinline{for} loop in the \\lstinline{histogram_reduce} function? What is the result of moving the \\lstinline{pipeline} directive into the \\lstinline{histogram_map} function, i.e., hoisting it outside of the \\lstinline{for} loop where it currently resides? \n\\end{exercise}\n\nThe goal of this section was to walk through the optimization the histogram computation, another small but important kernel of many applications. The key takeaway is that there are often limits to what tools can understand about our programs.  In some cases we must take care in how we write the code and in other cases we must actually give the tool more information about the code or the environment that the code is executing in.  In particular, properties about memory access patterns often critically affect the ability of HLS to generate correct and efficient hardware.  In \\VHLS, these properties can be expressed using the \\lstinline|dependence| directive.  Sometimes these optimizations might even be counter-intuitive, such as the addition of the \\lstinline{if/else} control structure in \\ref{fig:histogramOpt1}.  In other cases optimizations might require some creativity, as in applying the map-reduce pattern in Figures \\ref{fig:architecture_histogram_parallel} and \\ref{fig:histogram_parallel}.  \n\n\\section{Conclusion}\nIn this section, we've looked at the prefix sum and histogram kernels.  Although these functions seem different, they both contain recurrences through a memory access.  These recurrences can limit throughput if the memory access is not pipelined.  In both cases, by rewriting the code we can remove the recurrence.  In the case of the prefix sum, this is much easier since the access patterns are deterministic.  In the case of the histogram we must rewrite the code to address the recurrence or ensure that recurrence never happens in practice.   In either case we needed a way to describe to \\VHLS information about the environment or about the code itself that the tool was unable to determine for itself.  This information is captured in the \\lstinline{dependence} directive.  Lastly, we looked at ways of parallelizing both algorithms yet further, so that they could process a number of data samples each clock cycle.", "meta": {"hexsha": "33bdd3574be8bedc24306c41d385fa605ec893ac", "size": 30720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prefix_histogram.tex", "max_stars_repo_name": "mithro/pp4fpgas", "max_stars_repo_head_hexsha": "ddede5bd337f4fa33915d7e4ca98f97a7b31413a", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 418, "max_stars_repo_stars_event_min_datetime": "2018-05-09T17:28:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T05:51:12.000Z", "max_issues_repo_path": "prefix_histogram.tex", "max_issues_repo_name": "jmuuu/pp4fpgas", "max_issues_repo_head_hexsha": "f604b68289b0a9998ace596c57ea7209f2d60fd5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-05-13T16:26:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T06:06:57.000Z", "max_forks_repo_path": "prefix_histogram.tex", "max_forks_repo_name": "jmuuu/pp4fpgas", "max_forks_repo_head_hexsha": "f604b68289b0a9998ace596c57ea7209f2d60fd5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 107, "max_forks_repo_forks_event_min_datetime": "2018-05-12T16:43:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T22:59:42.000Z", "avg_line_length": 139.6363636364, "max_line_length": 1538, "alphanum_fraction": 0.7965494792, "num_tokens": 7142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8104789109591831, "lm_q1q2_score": 0.6164913126022805}}
{"text": "\\documentclass[11pt,a4paper]{report}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{gensymb}\n\\usepackage{tikz}\n\\usepackage{pgfplots}\n\\usetikzlibrary{positioning}\n\\usepackage{geometry}\n\\geometry{\n    left=2cm,\n    right=0.64cm,\n    top=0.64cm,\n    bottom=2cm\n}\n\\usepackage{multicol}\n\\setlength{\\columnsep}{1cm}\n\\graphicspath{ {images/} }\n\n\\begin{document}\n\n\\chapter{Semester 2 Examination 2015-2016\\\\CZ4041 Machine Learning}\n\n\\begin{multicols*}{2}\n\n\\section{Question 1}\n\\noindent \\textbf{Question 1a}\n\\noindent Information given in the question:\n\\begin{itemize}\n  \\item $P(D) = 0.001$\n  \\item $P(\\sim D) = 0.999$\n  \\item $P(T_1|D) = 0.9$\n  \\item $P(T_2|D) = 0.95$\n  \\item $P(T_1|\\sim D) = 0.01$\n  \\item $P(T_2|\\sim D) = 0.1$\n\\end{itemize}\n\n\\begin{equation*}\n\\begin{split}\nP(D|T_1 T_2) &= \\frac{P(T_1 | D) P(T_2 | D) P(D)}{P(T_1 T_2)}\\\\\n&= \\frac{0.9 \\times 0.95 \\times 0.001}{P(T_1 T_2)}\\\\\n&= \\frac{0.855 \\times 10^{-3}}{P(T_1 T_2)}\n\\end{split}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{split}\nP(\\sim D|T_1 T_2) &= \\frac{P(T_1 | \\sim D) P(T_2 | \\sim D) P(\\sim D)}{P(T_1 T_2)}\\\\\n&= \\frac{0.01 \\times 0.1 \\times 0.999}{P(T_1 T_2)}\\\\\n&= \\frac{0.999 \\times 10^{-3}}{P(T_1 T_2)}\n\\end{split}\n\\end{equation*}\n\n\\noindent Since $P(\\sim D|T_1 T_2) > P(D|T_1 T_2)$, we predict that the patient does not have the disease.\\\\\n\n\\noindent \\textbf{Question 1b}\n\n\\noindent Let action $a_1$ be the action predicting the patient to have the disease, and action $a_2$ be the action predicting the patient to not have the disease.\n\n$$R(a_1|T_1 T_2) = 1 - P( D | T_1 T_2)$$\n$$R(a_2|T_1 T_2) = 1 - P( \\sim D | T_1 T_2)$$\n\n\\noindent We choose the action with minimum risk. Since $P(\\sim D|T_1 T_2) > P(D|T_1 T_2)$, thus $R(a_2|T_1 T_2) < R(a_1|T_1 T_2)$, so the action $a_2$ has lower risk. As a result, we predict that the patient does not have the disease.\\\\\n\n\\noindent \\textbf{Question 1c}\n\n\\noindent Information given in the question:\n\\begin{itemize}\n  \\item $\\lambda_{12} = 0.05$\n  \\item $\\lambda_{21} = 1$\n\\end{itemize}\n\n\\noindent Where $\\lambda_{12}$ is the lost occur when the action is predict the patient to have disease $a_1$, but the ground truth is the patient do not have the disease $\\sim D$. The lost $\\lambda_{21}$ is defined in similar way. The risks are:\n\n\\begin{equation*}\n\\begin{split}\nR(a_1|T_1 T_2) &= \\lambda_{12} P(\\sim D | T_1 T_2)\\\\\n&= 0.05 \\times \\frac{0.999 \\times 10^{-3}}{P(T_1 T_2)}\\\\\n&= \\frac{0.4995 \\times 10^{-3}}{P(T_1 T_2)}\n\\end{split}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{split}\nR(a_2|T_1 T_2) &= \\lambda_{21} P( D | T_1 T_2)\\\\\n&= 1 \\times \\frac{0.855 \\times 10^{-3}}{P(T_1 T_2)}\\\\\n&= \\frac{0.855 \\times 10^{-3}}{P(T_1 T_2)}\\\\\n\\end{split}\n\\end{equation*}\n\n\\noindent Since $R(a_1|T_1 T_2) < R(a_2|T_1 T_2)$, we predict that the patient has the disease.\n\n\\section{Question 2}\n\\noindent \\textbf{Question 2a}\n\n\\noindent We define the inputs to Hidden Layer as:\n\n$$X = \\begin{bmatrix} X_1 \\\\ X_2 \\end{bmatrix}$$\n\n\\noindent The weight from Input Layer to Hidden Layer is:\n\n$$W =\n\\begin{bmatrix}\nw_{13} & w_{23} \\\\\nw_{14} & w_{24}\n\\end{bmatrix}$$\n\n\\noindent The activation function is:\n\n$$\nf(u) =\n\\begin{cases}\n1 & u \\ge 0\\\\\n-1 & u < 0\n\\end{cases}\n$$\n\n\\noindent The output of the Hidden Layer (which is also the input to Output Layer) is:\n\n$$Z = f(W X)$$\n\n\\noindent The weight from Hidden Layer to Output Layer is:\n\n$$V =\n\\begin{bmatrix}\nw_{35} & w_{45}\n\\end{bmatrix}$$\n\n\\noindent The output of Output Layer is:\n\n$$y = f(V Z)$$\n\n\\noindent For each $X$, we calculate $y$:\n\n\\begin{center}\n\\begin{tabular}{|c | c | c | c |}\n\\hline\n$X_1$ & $X_2$  & $y$ & Predict \\\\ \\hline\n2     & -0.5   & 1   & +       \\\\\n1     & 1      & 1   & -       \\\\\n3     & 1      & 1   & -       \\\\\n2     & -2     & -1  & +       \\\\\n1.5   & 2      & 1   & -       \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent The error rate is $80\\%$.\\\\\n\n\\noindent \\textbf{Question 2b}\n\n\\noindent We define $X$ as:\n\n$$X =\n\\begin{bmatrix}\n2 & -0.5 \\\\\n1 & 1 \\\\\n3 & 1 \\\\\n2 & -2 \\\\\n1.5 & 2\n\\end{bmatrix}$$\n\n\\noindent The pairwise inner products between the five data points is:\n\n$$X X^{T} =\n\\begin{bmatrix}\n4.25 & 1.50 &  5.50 &  5.00  &  2.00\\\\\n1.50 & 2.00 &  4.00 &  0.00  &  3.50\\\\\n5.50 & 4.00 & 10.00 &  4.00  &  6.50\\\\\n5.00 & 0.00 &  4.00 &  8.00  & -1.00\\\\\n2.00 & 3.50 &  6.50 & -1.00  &  6.25\n\\end{bmatrix}$$\n\n\\noindent \\textbf{Question 2c}\n\n\\begin{tikzpicture}\n\\begin{axis}[\n    enlargelimits=false,\n    axis equal\n]\n\\addplot+[\n    nodes near coords,\n    only marks,\n    point meta=explicit symbolic\n]\ntable[meta=label] {\n    x   y   label\n    2  -0.5 ID1\n    1   1   ID2\n    3   1   ID3\n    2  -2   ID4\n    1.5 2   ID5\n    7   4   ID6\n    5   0.2 Q2d\n};\n\\addplot [\n    domain=0:7,\n    samples=2,\n    color=red,\n]\n{0.25};\n\\end{axis}\n\\end{tikzpicture}\n\n\\noindent The decision boundary is $y=0.25$.\\\\\n\n\\noindent \\textbf{Question 2d}\n\n\\noindent Predict the test data point to be + class.\n\n\\section{Question 3}\n\n\\noindent \\textbf{Question 3a}\n\n\\noindent If we discard the last eigenvector to reduce the dimension to 2:\n\n$$\\text{POV} = \\frac{9.78 + 2.11}{9.78 + 2.11 + 0.11} = 0.991$$\n\n\\noindent If we discard the last eigenvector to reduce the dimension to 1:\n\n$$\\text{POV} = \\frac{9.78}{9.78 + 2.11 + 0.11} = 0.815$$\n\n\\noindent \\textbf{Question 3b}\n\n$$z = U_{\\text{reduce}} x^{T}$$\n$$U_{\\text{reduce}} = \\begin{bmatrix}\n0.78 & -0.54 & 0.32 \\\\\n0.04 & 0.56 & 0.83\n\\end{bmatrix}$$\n\n\\begin{center}\n\\begin{tabular}{| c | c | c |}\n\\hline\nData  & Original    & Reduced\\\\ \\hline\n$x_1$ & $(2,0,2)$   & $(2.20,1.74)$   \\\\\n$x_2$ & $(-1,0,-1)$ & $(-1.10,0.87)$  \\\\\n$x_3$ & $(3,-3,0)$  & $(3.96,-1.56)$  \\\\\n$x_4$ & $(-3,2,-2)$ & $(-4.06,-0.66)$ \\\\\n$x_5$ & $(-1,1,1)$  & $(-1.00,1.35)$  \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent \\textbf{Question 3c}\n\n\\begin{center}\n\\begin{tabular}{| c | c  c  c  c  c |} \\hline\n      & $x_1$  & $x_2$   & $x_3$  & $x_4$  & $x_5$   \\\\ \\hline\n$x_1$ & 0      & 3.4128  & 3.7400 & 6.7043 & 3.2237  \\\\\n$x_2$ & 3.4128 & 0       & 5.6132 & 3.3320 & 0.49031 \\\\\n$x_3$ & 3.7400 & 5.6132  & 0      & 8.0703 & 5.7506  \\\\\n$x_4$ & 6.7043 & 3.3320  & 8.0703 & 0      & 3.6611  \\\\\n$x_5$ & 3.2237 & 0.49031 & 5.7506 & 3.6611 & 0       \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent We merge $x_2$ and $x_5$:\n\n\\begin{center}\n\\begin{tabular}{| c | c  c  c  c  |} \\hline\n               & $x_2 \\cap x_5$  & $x_1$   & $x_3$  & $x_4$  \\\\ \\hline\n$x_2 \\cap x_5$ & 0               & 3.2237  & 5.6132 & 3.3320 \\\\\n$x_1$          & 3.2237          & 0       & 3.7400 & 6.7043 \\\\\n$x_3$          & 5.6132          & 3.7400  & 0      & 8.0703 \\\\\n$x_4$          & 3.3320          & 6.7043  & 8.0703 & 0      \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent We merge $x_2 \\cap x_5$ with $x_1$:\n\n\\begin{center}\n\\begin{tabular}{| c | c  c  c |} \\hline\n                        & $x_2 \\cap x_5 \\cap x_1$ & $x_3$  & $x_4$  \\\\ \\hline\n$x_2 \\cap x_5 \\cap x_1$ & 0                       & 3.7400 & 3.3320 \\\\\n$x_3$                   & 3.7400                  & 0      & 8.0703 \\\\\n$x_4$                   & 3.3320                  & 8.0703 & 0      \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent We merge $x_2 \\cap x_5 \\cap x_1$ with $x_4$:\n\n\n\\begin{center}\n\\begin{tabular}{| c | c  c |} \\hline\n                                 & $x_2 \\cap x_5 \\cap x_1 \\cap x_4$ & $x_3$  \\\\ \\hline\n$x_2 \\cap x_5 \\cap x_1 \\cap x_4$ & 0                                & 3.7400 \\\\\n$x_3$                            & 3.7400                           & 0      \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\\noindent Finally we merge $x_3$ to $x_2 \\cap x_5 \\cap x_1 \\cap x_4$.\n\n\\begin{tikzpicture}[sloped]\n\\node (a) at (0,0) {a};\n\\node (b) at (1,0) {b};\n\\node (c) at (2,0) {c};\n\\node (d) at (3,0) {d};\n\\node (e) at (4,0) {e};\n\\node (dummy) at (3.5,5) {};\n\n\\node (ab)    at (0.5,0.4903) {};\n\\node (abc)   at (1.5,3.00) {}; % change the value abit from 3.22\n\\node (abcd)  at (2.5,3.30) {};\n\\node (abcde) at (3.5,3.74) {};\n\n\\draw  (a)    |- (ab.center);\n\\draw  (b)    |- (ab.center);\n\\draw  (ab)   |- (abc.center);\n\\draw  (c)    |- (abc.center);\n\\draw  (abc)  |- (abcd.center);\n\\draw  (d)    |- (abcd.center);\n\\draw  (abcd) |- (abcde.center);\n\\draw  (e)    |- (abcde.center);\n\\draw (abcde) |- (dummy.center);\n\n\\end{tikzpicture}\n\n\\noindent \\textbf{Question 3d}\n\\noindent [Help wanted!]\\\\\n\n\\section{Question 4}\n\n\\noindent \\textbf{Question 4a}\n\\noindent [Copied and pasted from lecture notes] Steps:\n\\begin{itemize}\n\\item Train C1 with dataset D1\n\\item Test C1 with dataset D2\n\\item Find error samples and an equal amount of correct samples and form D3\n\\item Train C2 with dataset D3\n\\item Find error samples and equal amount of correct samples and form D4\n\\item Train C1and C2 with dataset D4\n\\item Find errors and equal number of correct samples and form D5\n\\item Train C3 with D5...\n\\end{itemize}\n\n\\noindent \\textbf{Question 4b}\n\\noindent [Help wanted!]\\\\\n\n\\noindent \\textbf{Question 4c i}\n\n\\begin{equation*}\n\\begin{split}\nP(A) &= \\sum_{B,E} P(A,B,E)\\\\\n     &= \\sum_{B,E} P(A | B,E) P(B,E)\\\\\n     &= \\sum_{B,E} P(A | B,E) P(B) P(E)\\\\\n     &=       P(A |      B,     E) P(     B) P(     E) +\\\\\n     &\\ \\ \\ \\ P(A |      B,\\sim E) P(     B) P(\\sim E) +\\\\\n     &\\ \\ \\ \\ P(A | \\sim B,     E) P(\\sim B) P(     E) +\\\\\n     &\\ \\ \\ \\ P(A | \\sim B,\\sim E) P(\\sim B) P(\\sim E)\\\\\n     &=       0.95 \\times 0.01 \\times 0.02 +\\\\\n     &\\ \\ \\ \\ 0.90 \\times 0.01 \\times 0.98 +\\\\\n     &\\ \\ \\ \\ 0.25 \\times 0.99 \\times 0.02 +\\\\\n     &\\ \\ \\ \\ 0.01 \\times 0.99 \\times 0.98  \\\\\n     &= 0.02366\\\\\nP(\\sim A) &= 0.9763\n\\end{split}\n\\end{equation*}\n\n\\noindent \\textbf{Question 4c ii}\n\n\\begin{equation*}\n\\begin{split}\nP(S) &= \\sum_{A} P(S,A)\\\\\n     &= \\sum_{A} P(S|A)P(A)\\\\\n     &=      P(S|     A)P(     A) +\\\\\n     &\\ \\ \\ \\ P(S|\\sim A)P(\\sim A)\\\\\n     &= 0.70 \\times 0.02366 + 0.05 \\times 0.9763\\\\\n     &= 0.06538\n\\end{split}\n\\end{equation*}\n\n\\noindent \\textbf{Question 4c iii}\n\n\\begin{equation*}\n\\begin{split}\nP(S|B) &= \\sum_{A} P(S,A|B)\\\\\n       &= \\sum_{A} \\frac{P(S,A,B)}{P(B)}\\\\\n       &= \\sum_{A} \\frac{P(S|A,B)P(A,B)}{P(B)}\\\\\n       &= \\sum_{A} \\frac{P(S|A,B)P(A|B)P(B)}{P(B)}\\\\\n       &= \\sum_{A} P(S|A,B)P(A|B)\\\\\n       &= \\sum_{A} P(S|A)P(A|B)\\\\\n       &=      P(S|     A)P(     A|B)+\\\\\n       &\\ \\ \\ \\ P(S|\\sim A)P(\\sim A|B)\\\\\n       &= 0.70 \\times P(A|B) + 0.05 \\times P(\\sim A|B)\\\\\n\\end{split}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{split}\nP(A|B)      &= \\sum_{E} P(A,E|B)\\\\\n            &= \\sum_{E} \\frac{P(A,E,B)}{P(B)}\\\\\n            &= \\sum_{E} \\frac{P(A|E,B)P(E,B)}{P(B)}\\\\\n            &= \\sum_{E} \\frac{P(A|E,B)P(E)P(B)}{P(B)}\\\\\n            &= \\sum_{E} P(A|E,B)P(E)\\\\\n            &= P(A|E,B)P(E) + P(A|\\sim E,B)P(\\sim E)\\\\\n            &= 0.95 \\times 0.02 + 0.90 \\times 0.98\\\\\n            &= 0.901\\\\\nP(\\sim A|B) &= 0.099\\\\\nP(S|B)      &= 0.70 \\times 0.901 + 0.05 \\times 0.099\\\\\n            &= 0.6357\n\\end{split}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{split}\nP(B|S) &= \\frac{P(S|B)P(B)}{P(S)}\\\\\n       &= \\frac{0.6357 \\times 0.01}{0.06538}\\\\\n       &= 0.09723\n\\end{split}\n\\end{equation*}\n\n\n\\end{multicols*}\n\\end{document}", "meta": {"hexsha": "1aa180f5dcf71b0e52a6a39663f374b77ae225f0", "size": 10970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cz4041/cz4041-15-16-2.tex", "max_stars_repo_name": "Andyccs/ntucs-pyp", "max_stars_repo_head_hexsha": "b0bcf074b86da28e3b6af08d618652487e7e880c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-04-30T07:06:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-27T13:40:06.000Z", "max_issues_repo_path": "cz4041/cz4041-15-16-2.tex", "max_issues_repo_name": "Andyccs/information-retrieval-pyp", "max_issues_repo_head_hexsha": "b0bcf074b86da28e3b6af08d618652487e7e880c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-05-03T05:07:30.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-04T12:27:15.000Z", "max_forks_repo_path": "cz4041/cz4041-15-16-2.tex", "max_forks_repo_name": "Andyccs/information-retrieval-pyp", "max_forks_repo_head_hexsha": "b0bcf074b86da28e3b6af08d618652487e7e880c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-05-02T06:19:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-15T12:21:15.000Z", "avg_line_length": 26.5617433414, "max_line_length": 246, "alphanum_fraction": 0.5424794895, "num_tokens": 4820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6164913056381867}}
{"text": "\\documentclass[a4paper]{scrartcl}\n\\usepackage{amssymb, amsmath} % needed for math\n\\usepackage[utf8]{inputenc} % this is needed for umlauts\n\\usepackage[ngerman]{babel} % this is needed for umlauts\n\\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf\n\\usepackage[margin=2.5cm]{geometry} %layout\n\\usepackage{hyperref}   % links im text\n\\usepackage{parskip} % no indentation on new paragraphs\n\\usepackage{color}\n\\usepackage{framed}\n\\usepackage{enumerate}  % for advanced numbering of lists\n\\usepackage{algorithm,algpseudocode}\n\\usepackage{braket} % needed for \\Set\n\\clubpenalty  = 10000   % Schusterjungen verhindern\n\\widowpenalty = 10000   % Hurenkinder verhindern\n\n\\hypersetup{\n  pdfauthor   = {Martin Thoma},\n  pdfkeywords = {Google Code Jam, Round 1C 2013, Pogo},\n  pdftitle    = {Proof of correctness for an algorithm for pogo}\n}\n\n% From http://www.matthewflickinger.com/blog/archives/2005/02/20/latex_mod_spacing.asp\n% Thanks!\n\\makeatletter\n\\def\\imod#1{\\allowbreak\\mkern10mu({\\operator@font mod}\\,\\,#1)}\n\\makeatother\n\n\\renewcommand{\\algorithmicrequire}{\\textbf{Input: }}\n\\renewcommand{\\algorithmicensure}{\\textbf{Output: }}\n\n\\newenvironment{myindentpar}[1]%\n {\\begin{list}{}%\n         {\\setlength{\\leftmargin}{#1}}%\n         \\item[]%\n }\n {\\end{list}}\n\n\\begin{document}\n\\section{The Problem}\nYou're on a two-dimensional grid $\\mathbb{Z} \\times \\mathbb{Z}$ and\nhave to find a way to get to one coordinate $(x,y) \\in \\mathbb{Z} \\times \\mathbb{Z}$. You start at\n$(0, 0)$.\n\nIn your\n$i$-th step you move either $\\underbrace{(+i,0)}_{=: E}$,\n$\\underbrace{(-i,0)}_{=: W}$, $\\underbrace{(0,+i)}_{=: N}$ or\n$\\underbrace{(0,-i)}_{=: S}$.\n\n\\section{The algorithm}\n\\begin{algorithm}\n    \\begin{algorithmic}\n        \\Function{calculateSteps}{$x \\in \\mathbb{Z}$, $y \\in \\mathbb{Z}$}\n            \\State $s \\gets 0$\n            \\State $dist \\gets |x| + |y|$\n            \\\\\n            \\While{$\\overbrace{\\frac{s^2 + s}{2} < dist}^\\text{condition 1}$ or $\\overbrace{\\frac{s^2 + s}{2} \\not\\equiv dist \\imod{2}}^\\text{condition 2}$}\n                \\State $s \\gets s + 1$\n            \\EndWhile\n            \\\\\n            \\State \\Return $s$\n        \\EndFunction\n    \\end{algorithmic}\n    \\caption{Algorithm to calculate the minimum amount of steps}\n    \\label{alg:calculateSteps}\n\\end{algorithm}\n\n\\clearpage\n\n\\begin{algorithm}[ht!]\n    \\begin{algorithmic}[ht!]\n        \\Function{solvePogo}{$x \\in \\mathbb{Z}$, $y \\in \\mathbb{Z}$}\n            \\State $s_{\\min} \\gets$ \\Call{calculateSteps}{$x, y$}\n            \\\\\n            \\State $solution \\gets \\varepsilon$\n            \\For{$i$ in $s_{\\min}, \\dots, 1$}\n                \\If{$|x| > |y|$}\n                    \\If{$x > 0$}\n                        \\State $solution \\gets solution + E$\n                        \\State $x \\gets x - i$\n                    \\Else\n                        \\State $solution \\gets solution + W$\n                        \\State $x \\gets x + i$\n                    \\EndIf\n                \\Else\n                    \\If{$y > 0$}\n                        \\State $solution \\gets solution + N$\n                        \\State $y \\gets y - i$\n                    \\Else\n                        \\State $solution \\gets solution + S$\n                        \\State $y \\gets y + i$\n                    \\EndIf\n                \\EndIf\n            \\EndFor\n            \\\\\n            \\State \\Return \\Call{reverse}{$solution$}\n        \\EndFunction\n    \\end{algorithmic}\n    \\caption{Algorithm to solve the pogo problem}\n    \\label{alg:solvePogo}\n\\end{algorithm}\n\n\\section{Correctness}\n\\subsection{calculateSteps}\nLet $x,y \\in \\mathbb{Z}$ and $s := \\Call{calculateSteps}{x, y}$.\n\nLet $s_{\\min}$ be the minimum amount of necessary steps to get from $(0,0)$\nto $(x,y)$ when you move $i$ units in your $i$'th step.\n\n\\textbf{Theorem: } $s = s_{\\min}$\n\nIt's enough to proof $s \\geq s_{\\min}$ and $s \\leq s_{\\min}$.\n\n\\begin{myindentpar}{1cm}\n\\textbf{Theorem: } $s \\leq s_{\\min}$ (we don't make too many steps)\n\n\\textbf{Proof: }\n\\begin{myindentpar}{1cm}\nWe have to get from $(0,0)$ to $(x, y)$. As we may only move in\ntaxicab geometry we have to use the taxicab distance measure $d_1$:\n\\[d_1 \\left (p, q \\right ) := \\sum_{i=1}^2 |p_i -q_i|\\]\n\nSo in our scenario:\n\\[d_1 \\left ((0,0), (x,y) \\right ) = |x| + |y|\\]\n\nThis means we have to move at least $|x| + |y|$ units to get\nfrom $(0,0)$ to $(x, y)$. As we move $i$ units in the $i$'th step,\nwe have to solve the following equations for $s_{\\min1}$:\n\\begin{align}\n    \\sum_{i=1}^{s_{\\min1}} i          &\\geq |x| + |y| &&\\text{ and } &|x| + |y|      &> \\sum_{i=1}^{s_{\\min1} - 1} i\\\\\n    \\frac{s_{\\min1}^2 + s_{\\min1}}{2} &\\geq |x| + |y| &&             &               &> \\sum_{i=1}^{s_{\\min1} - 1} i &\n\\end{align}\n\nThis is what algorithm \\ref{alg:calculateSteps} check with \\texttt{condition 1}.\nAs the algorithm increases $s$ only by one in each loop, it makes\nsure that $\\sum_{i=1}^{s_{\\min1} - 1} i$ is bigger than $|x| + |y|$.\n\nYou can undo moves by going back. But this will always make an even\nnumber undone. When you go $(+i, 0)$ and later $(-j, 0)$ it is the\nsame as if you've been going $(i-j, 0)$. So $2\\cdot i$ steps got undone.\nBut $2\\cdot i$ is an even number. You will never be able to undo\nan odd number of moved units. This means, the parity of the minimum\nnumber of units you would have to move if you would move one unit per\nstep has to be the same as the parity of the moves you actually do.\nThis is exactly what \\texttt{condition 2} makes sure.\n\nSo we need at least $s$ steps $\\Rightarrow s \\leq s_{\\min} \\square$\n\\end{myindentpar}\n\n\\textbf{Theorem: } $s \\geq s_{\\min}$ (we make enough steps)\n\n\\textbf{Proof: }\n\\begin{myindentpar}{1cm}\nWe chose $s$ in a way that \\texttt{condition 1} is true.\nAs we have to go $i \\in 1,\\dots,s$, we can get every possible sum $\\Sigma \\in \\Set{-\\frac{s^2+s}{2}, \\dots +\\frac{s^2+s}{2}}$\nwith a subset of $\\Set{1, \\dots, s}$\\footnote{This can easily be proved by induction over $\\Sigma$.}.\nThis means we can make a partition $(A, \\underbrace{\\Set{1, \\dots, s} \\setminus A}_{=: B})$\nsuch that $|\\sum_{i \\in A} i| = |x|$ and $|\\sum_{i \\in B} i|-2\\cdot j = |y|$.\nThis means, we can reach $(x,y)$ from $(0,0)$.\n\\end{myindentpar}\n\\end{myindentpar}\n\n\\subsection{solvePogo}\n\\textbf{Theorem: } \\Call{solvePogo}{$x,y$} returns a valid, minimal sequence of steps to get from $(0, 0)$ to $(x,y)$\n\n\\textbf{Proof: }\n\\begin{myindentpar}{1cm}\nAs $s_{\\min}$ is the minimum amount of steps you need to get from\n$(0,0)$ to $(x,y)$, \\Call{solvePogo}{$x,y$} will return a minimal\nsequence of steps to get from $(0, 0)$ to $(x,y)$ (see proof above).\n\nWe only have to prove that the sequence of steps that \\Call{solvePogo}{$x,y$}\nis valid, i.e. that you will get from $(0,0)$ to $(x,y)$ with the given\nsequence.\n\nTODO.\n\\end{myindentpar}\n\n\\end{document}\n", "meta": {"hexsha": "3e63f61b5e6303f8badac27bab20ce6148731824", "size": 6782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/proof-of-correctness-pogo/proof-of-correctness-pogo.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": "documents/proof-of-correctness-pogo/proof-of-correctness-pogo.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": "documents/proof-of-correctness-pogo/proof-of-correctness-pogo.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": 37.6777777778, "max_line_length": 156, "alphanum_fraction": 0.602034798, "num_tokens": 2251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6164913003251633}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[colorlinks]{hyperref}\n\\usepackage{amsmath,esint,bm}\n\\title{Divergence Theorem}\n\\author{Naitree Zhu}\n\\date{Last modified: \\today}\n\\begin{document}\n\\maketitle\nIn vector calculus, the Divergence theorem\\footnote{For more information:\\url{http://en.wikipedia.org/wiki/Divergence_theorem}}, also known as Gauss's theorem or Ostrogradsky's theorem,is a result that relates the flow (that is, flux) of a vector field through a surface to the behavior of the vector field inside the surface.\n\nMore precisely, the divergence theorem states that the outward flux of a vector field through a closed surface is equal to the volume integral of the divergence over the region inside the surface. Intuitively, it states that \\emph{the sum of all sources minus the sum of all sinks gives the net flow out of a region.}\n\nIn physics and engineering, the divergence theorem is usually applied in three dimensions. However, it generalizes to any number of dimensions. In one dimension, it is equivalent to the fundamental theorem of calculus. In two dimensions, it is equivalent to Green's theorem.\n\nThe theorem is a special case of the more general Stokes' theorem.\n\n\\part{Mathematical statement}\nSuppose \\textit{V} is a subset of $R^{n}$ (in the case of n = 3, \\textit{V} represents a volume in 3D space) which is compact and has a piecewise smooth boundary \\textit{S}. If $\\boldsymbol{F}$ is a continuously differentiable vector field defined on a neighborhood of \\textit{V}, then we have:\n\\begin{equation}\n\\iiint_V \\nabla\\cdot\\boldsymbol{F}\\mathrm{d}V = \\oiint_S \\boldsymbol{F}\\cdot\\mathrm{d}\\boldsymbol{S}\n\\end{equation}\nThe closed manifold $\\partial V$ is quite generally the boundary of \\textit{V} oriented by outward-pointing normals.\n\\section*{Corollaries}\nBy applying the divergence theorem in various contexts, other useful identities can be derived:\n\\begin{itemize}\n\\item Applying the divergence theorem to the product of a scalar function \\textit{g} and a vector field $\\boldsymbol{F}$, the result is\n\\begin{equation}\n\\iiint_V \\left[\\boldsymbol{F}\\cdot\\left(\\nabla g\\right) + g\\left(\\nabla\\cdot\\boldsymbol{F}\\right)\\right]\\mathrm{d}V=\\oiint_S g\\boldsymbol{F}\\cdot\\mathrm{d}\\boldsymbol{S}\n\\end{equation}\nA special case of this is $\\mathbf{F}=\\nabla f$, in which case the theorem is the basis for Green's identities.\n\\item Applying the divergence theorem to the product of a scalar function, \\textit{f}, and a non-zero constant vector, the following theorem can be proven(Proof is \\hyperlink{proof1}{here}):\n\\begin{equation}\n\\iiint_V \\nabla f \\mathrm{d}V=\\oiint_S f\\mathrm{d}\\boldsymbol{S}\n\\end{equation}\n\\item Similarly, applying the divergence theorem to the cross-product of a vector field $\\mathbf{F}$ and a non-zero constant vector, the following theorem can be proven(Proof is \\hyperlink{proof2}{here}):\n\\begin{equation}\n\\iiint_V \\nabla\\times\\boldsymbol{F}\\mathrm{d}V=\\oiint_S \\mathrm{d}\\boldsymbol{S}\\times\\boldsymbol{F}\n\\end{equation}\n\\end{itemize}\n\\part{Generalizations}\n\\section{Multiple dimensions}\nOne can use the \\emph{general} Stokes' Theorem to equate the n-dimensional volume integral of the divergence of a vector field \\textbf{F} over a region \\textit{U} to the (n-1)-dimensional surface integral of \\textbf{F} over the boundary of \\textit{U}:\n\\begin{equation}\n\\int_U \\nabla\\cdot\\boldsymbol{F}\\mathrm{d}V_{n}=\\oint_{\\partial U} \\boldsymbol{F}\\cdot\\hat{n}\\mathrm{d}S_{n-1}\n\\end{equation}\nThis equation is also known as the Divergence theorem.\n\nWhen n = 2, this is equivalent to Green's theorem.\n\nWhen n = 1, it reduces to the Fundamental theorem of calculus.\n\\part{History}\nThe theorem was first discovered by Lagrange in 1762, then later independently rediscovered by Gauss in 1813, by Ostrogradsky, who also gave the first proof of the general theorem, in 1826, by Green in 1828, etc. Subsequently, variations on the divergence theorem are correctly called Ostrogradsky's theorem, but also commonly Gauss's theorem, or Green's theorem.\n\\part{2-dimensional version}\n\\begin{equation}\n\\iint_S \\nabla\\cdot\\bm{F}\\mathrm{d}S=\\oint_L \\bm{F}\\cdot\\hat{n}\\mathrm{d}l\n\\end{equation}\nwhere $\\hat{n}$ is the outward-pointing unit normal vector, and the direction of line integral observes right-hand rule.\n\nBy expansion in Cartesian coordinates, it's easily seen that Green theorem is essentially an identical formula with a different form.\n\\part{Proofs}\n\\section{Proof to eq.~(3)}\n\\[\n\\iiint_V \\nabla f \\mathrm{d}V=\\oiint_S f\\mathrm{d}\\boldsymbol{S}\n\\]\n\\hypertarget{proof1}{Proof}:\n\nIf the vector field $\\mathbf{F}=f\\mathbf{C}$, where $\\mathbf{C}$ is an arbitrary nonzero constant vector, then \n\\[\n\\nabla\\cdot\\boldsymbol{F}=\\boldsymbol{C}\\cdot\\nabla f\n\\]\nApply divergence theorem\n\\begin{align*}\n\\int_V \\nabla\\cdot\\boldsymbol{F}\\mathrm{d}V\n&=\\boldsymbol{C}\\cdot\\oint_S f\\mathrm{d}\\boldsymbol{S}\\\\\n&=\\boldsymbol{C}\\cdot\\int_V \\nabla f\\mathrm{d}V\n\\end{align*}\nSince \\textbf{C} is nonzero and arbitrary, it cannot always be perpendicular to $\\oint_S f\\mathrm{d}\\boldsymbol{S}$ and $\\int_V \\nabla f\\mathrm{d}V$. So it's only logical that\n\\[\n\\iiint_V \\nabla f \\mathrm{d}V=\\oiint_S f\\mathrm{d}\\boldsymbol{S}\n\\]\n\\section{Proof to eq.~(4)}\n\\hypertarget{proof2}{Proof}:\nBy setting $\\mathbf{G}=\\mathbf{C}\\times\\mathbf{F}$, where \\textbf{C} is arbitrary nonzero vector, eq.~(4) can be proved, similar to the proof above.\n\nUsing:\n\\[\n\\nabla\\cdot\\left(\\boldsymbol{a}\\times\\boldsymbol{b}\\right)=\\boldsymbol{b}\\cdot\\left(\\nabla\\times\\boldsymbol{a}\\right)-\\boldsymbol{a}\\cdot\\left(\\nabla\\times\\boldsymbol{b}\\right)\n\\]\nthen,\n\\begin{align*}\n\\int_V \\boldsymbol{G}\\cdot\\mathrm{d}V&=-\\boldsymbol{C}\\cdot\\int_V \\nabla\\times\\boldsymbol{F}\\mathrm{d}V\\\\&=\\int_S \\left(\\boldsymbol{C}\\times\\boldsymbol{F}\\right)\\cdot\\mathrm{d}\\boldsymbol{S}\\\\&=\\boldsymbol{C}\\cdot\\int_S \\boldsymbol{F}\\times\\mathrm{d}\\boldsymbol{S}\n\\end{align*}\nWith the similar logic applied with \\textbf{C} in the proof above, we get\n\\[\n\\iiint_V \\nabla\\times\\boldsymbol{F}\\mathrm{d}V=\\oiint_S \\mathrm{d}\\boldsymbol{S}\\times\\boldsymbol{F}\n\\]\n\\end{document}", "meta": {"hexsha": "b7031244390faf99628a4b2b1806588780ce9e7e", "size": 6036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/Divergence theorem/Divergence theorem.tex", "max_stars_repo_name": "Naitreey/notes-and-knowledge", "max_stars_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-05-16T06:06:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-12T08:46:18.000Z", "max_issues_repo_path": "math/Divergence theorem/Divergence theorem.tex", "max_issues_repo_name": "Naitreey/notes-and-knowledge", "max_issues_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-04-06T01:46:22.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-13T03:11:33.000Z", "max_forks_repo_path": "math/Divergence theorem/Divergence theorem.tex", "max_forks_repo_name": "Naitreey/notes-and-knowledge", "max_forks_repo_head_hexsha": "48603b2ad11c16d9430eb0293d845364ed40321c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-04-11T11:02:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-27T11:59:09.000Z", "avg_line_length": 62.2268041237, "max_line_length": 363, "alphanum_fraction": 0.7614314115, "num_tokens": 1842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6164811596371422}}
{"text": "\\documentclass[a4paper,10pt]{article}\n%\\documentclass[a4paper,10pt]{scrartcl}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{lineno}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{times}\n\\usepackage[T1]{fontenc}  % to get the appropriate fonts for icelandic thorn\n\\usepackage{textcomp}\n\\usepackage{natbib}\n\\usepackage{placeins}\n\\usepackage{listings}\n\\usepackage{xcolor}\n\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codered}{rgb}{1.0,0.0,0.0}\n\\definecolor{codeblue}{rgb}{0.0,0,1.0}\n\\definecolor{codeyellow}{rgb}{1.0,0.7,0.0}\n\\definecolor{backcolour}{rgb}{0.95,0.95,0.92}\n\n\\lstdefinestyle{mystyle}{\n\tbackgroundcolor=\\color{backcolour},   \n\tcommentstyle=\\color{codered},\n\tkeywordstyle=\\color{codeblue},\n\tnumberstyle=\\tiny\\color{codegreen},\n\tstringstyle=\\color{codeyellow},\n\tbasicstyle=\\ttfamily\\footnotesize,\n\tbreakatwhitespace=false,         \n\tbreaklines=true,                 \n\tcaptionpos=b,                    \n\tkeepspaces=true,                 \n\tnumbers=left,                    \n\tnumbersep=5pt,                  \n\tshowspaces=false,                \n\tshowstringspaces=false,\n\tshowtabs=false,                  \n\ttabsize=2\n}\n\n\\lstset{style=mystyle}\n\\DeclareMathOperator{\\atantwo}{arctan2}\n\n\\title{Lomb-Scargle Algorithm Documentation}\n\\author{Matt James}\n\\date{}\n\n\\pdfinfo{%\n  /Title    ()\n  /Author   ()\n  /Creator  ()\n  /Producer ()\n  /Subject  ()\n  /Keywords ()\n}\n\n\\begin{document}\n\\maketitle\n\t\n\\section{Description of Lomb-Scargle Periodogram}\n\nEverything in this document is pieced together from \\citet{Lomb1976,Scargle1983,Hocke1998}. This algorithm will calculate the power, $P$, amplitude, $A$, and phase, $\\phi$, of a wave with a given frequency, $f$, within an irregularly sampled time series of length $n$ samples.\n\nLet us consider sinusoidal waves of the form \n\\begin{equation}\n\ty_f(t_i) = a \\cos{\\omega(t_i - \\tau)} + b \\sin{\\omega(t_i - \\tau)}, \\label{EqWave}\n\\end{equation}\nwhere $\\omega = 2 \\pi f$ and $1 \\le i \\le n$.\n\n$\\tau$ is defined in \\citet{Scargle1983} as\n\\begin{equation}\n\t\\tan{2 \\omega \\tau} = \\frac{\\sum_{i=1}^{n} \\sin{2 \\omega t_i}}{\\sum_{i=1}^{n} \\cos{2 \\omega t_i}},\n\\end{equation}\nwhich can easily be rewritten as\n\\begin{equation}\n\t\\tau = \\frac{\\atantwo{\\left( \\sum_{i=1}^{n} \\sin{2 \\omega t_i}, \\sum_{i=1}^{n} \\cos{2 \\omega t_i} \\right)}}{2 \\omega}\n\\end{equation}\n\nThe constants $a$ and $b$ are defined as\n\\begin{equation}\n\ta = \\frac{\\sqrt{\\frac{2}{n}}\\sum_{i=1}^{n}y_i \\cos{\\omega (t+i - \\tau)}}{\\left( \\sum_{i=1}^{n} \\cos^2{\\omega (t+i - \\tau)} \\right)^{\\frac{1}{2}}}\n\\end{equation}\nand\n\\begin{equation}\nb = \\frac{\\sqrt{\\frac{2}{n}}\\sum_{i=1}^{n}y_i \\sin{\\omega (t+i - \\tau)}}{\\left( \\sum_{i=1}^{n} \\sin^2{\\omega (t+i - \\tau)} \\right)^{\\frac{1}{2}}}.\n\\end{equation}\n\nThe periodogram is calculated using \n\\begin{equation}\n\tP(\\omega) = \\frac{1}{2\\sigma^2}\\frac{n}{2} (a^2 + b^2),\n\\end{equation}\nwhere $\\sigma = \\frac{1}{n-1}\\sum_{i=1}^{n} y_i^2$ is the variance (assuming that the mean has been subtracted from the data already).\n\nThe amplitude is calculated using \n\\begin{equation}\n\tA(\\omega) = \\sqrt{\\frac{4\\sigma^2}{n}P(\\omega)}\n\\end{equation}\nor, equivalently,\n\\begin{equation}\n\tA(\\omega) = \\sqrt{a^2 + b^2}.\n\\end{equation}\n\nEquation \\ref{EqWave} can be expressed differently:\n\\begin{equation}\n\ty_f(t_i) = A(\\omega) \\cos{\\left[\\omega (t_i - \\tau) + \\phi \\right]},\n\\end{equation}\nwhere the wave phase is given by,\n\\begin{equation}\n\t\\phi = -\\atantwo(b,a).\n\\end{equation}\n\n\\section{Example Python Code}\nThe code used in this module is based on the following Python code.\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\\begin{lstlisting}[language=Python]\ndef LombScargle(t,x,f):\n\t'''\n\tCalculates the Lomb-Scargle periodogram using the method defined in\n\tHocke 1998. This method assumes that any mean is removed from the\n\tdata.\n\t'''\n\t\n\t#preformat the input variables\n\tt = np.array([t],dtype='float64').flatten()\n\tx = np.array([x],dtype='float64').flatten()\n\tf = np.array([f],dtype='float64').flatten()\n\t\n\t#get array sizes\n\tnf = np.size(f)\n\tn = np.size(t)\n\t\n\t#create output arrays (Power, amplitude, phase, a, b)\n\tP = np.zeros((nf,),dtype='float64')\n\tA = np.zeros((nf,),dtype='float64')\n\tphi = np.zeros((nf,),dtype='float64')\n\ta = np.zeros((nf,),dtype='float64')\n\tb = np.zeros((nf,),dtype='float64')\n\t\n\t#convert f to omega\n\tw = 2*np.pi*f\n\t\n\t#calculate variance (sigma**2)\n\to2 = np.sum(x**2)/(n-1)\n\t\n\t#loop through each frequency\n\tfor i in range(0,nf):\n\t\t#calculate sums to get Tau\n\t\tss2w = np.sum(np.sin(2*w[i]*t))\n\t\tsc2w = np.sum(np.cos(2*w[i]*t))\n\t\n\t\t#calculate Tau\n\t\tTau = np.arctan2(ss2w,sc2w)/(2*w[i])\n\t\t\n\t\t#calculate w(t - Tau)\n\t\twtT = w[i]*(t - Tau)\n\t\t\n\t\t#calculate some more sums\n\t\tsyc = np.sum(x*np.cos(wtT))\n\t\tsys = np.sum(x*np.sin(wtT))\n\t\tsc2 = np.sum(np.cos(wtT)**2)\n\t\tss2 = np.sum(np.sin(wtT)**2)\n\t\n\t\t#get a  and b\n\t\trt2n = np.sqrt(2/n)\n\t\ta[i] = rt2n*syc/np.sqrt(sc2)\n\t\tb[i] = rt2n*sys/np.sqrt(ss2)\n\t\n\t#calculate the periodogram\n\ta2b2 = a**2 + b**2\n\tP[:] = (n/(4*o2))*a2b2\n\t\n\t#calculate amplitude\n\tA[:] = np.sqrt(a2b2)\n\t\n\t#calculate phase\n\tphi[:] = -np.arctan2(b,a)\n\t\n\treturn P,A,phi,a,b\n\\end{lstlisting}\n\\bibliographystyle{agu08}\n\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "a080b6169918b37cbdd95ac104dd64fdc603df22", "size": 5132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "wavespec/__data/liblombscargle/doc/lsdoc.tex", "max_stars_repo_name": "mattkjames7/wavespec", "max_stars_repo_head_hexsha": "2928ac3f4fb921a21caba3663b0d7c22e43692fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-04T15:08:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-04T15:08:57.000Z", "max_issues_repo_path": "wavespec/__data/liblombscargle/doc/lsdoc.tex", "max_issues_repo_name": "mattkjames7/wavespec", "max_issues_repo_head_hexsha": "2928ac3f4fb921a21caba3663b0d7c22e43692fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wavespec/__data/liblombscargle/doc/lsdoc.tex", "max_forks_repo_name": "mattkjames7/wavespec", "max_forks_repo_head_hexsha": "2928ac3f4fb921a21caba3663b0d7c22e43692fa", "max_forks_repo_licenses": ["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.5913978495, "max_line_length": 276, "alphanum_fraction": 0.6549103663, "num_tokens": 1803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6164811476528191}}
{"text": "\\section{Introduction}\n\nA skeleton is a lower dimensional entity which represents shape of it's parent object. It being simpler than the parent object, operations like pattern recognition, approximation, similarity estimation, collision detection, animation, matching and deformation can be performed efficiently on it than on the parent object. \n\nSkeletons can be computed via various mathematical formulations such as Medial Axis Transform (MAT),  Chordal Axis Transform (CAT), Thinning etc. Table \\ref{Medials} briefly summarizes these methods of Midcurves creation and their strengths-weaknesses.\n\n\\begin{table}\n\\caption{Current Medial Computation Methods}\n\\begin{tabular}[htbp]{@{} p{0.14\\linewidth}  p{0.22\\linewidth}  p{0.22\\linewidth}  p{0.23\\linewidth} @{}} \\toprule\n{\\bf Method } & {\\bf Medial }  & {\\bf Description} & {\\bf Comments}\\\\\n\\midrule\n%------------------------------------------------------------------------------------------------------------------------------------\n\\raisebox{-.9\\height}{MAT \\cite{Ramanathan2004}} &\n\\raisebox{-.9\\height}{\\includegraphics[scale=0.3]{..//Common/images/MAT.png} }&\nLocii of centers of maximal disk traversing within boundary &\nComputable for any shape. But has unwanted branches. Sensitive to boundary perturbations. \\\\\n\n\n%------------------------------------------------------------------------------------------------------------------------------------\n\\raisebox{-.9\\height}{CAT \\cite{Quadros2008}}&\n\\raisebox{-.9\\height}{\\includegraphics[scale=0.45]{..//Common/images/CAT.png}}&\nCreates triangulation first then joins midpoints of sides &\nGaps at end. Expensive triangulation. \\\\\n\n\n%------------------------------------------------------------------------------------------------------------------------------------\n{Straight Skeleton \\cite{Henrik2004}} &\n\\raisebox{-.9\\height}{\\includegraphics[scale=0.3]{..//Common/images/Straight.png}} &\nGoes on thinning from boundary. &\nBisectors mot equidistant. Has unnecessary branches.\\\\\n\n\\bottomrule\n\\end{tabular}\n\\label{Medials}\n\\end{table}\n\n\nIn this paper we focus on 2D planar sketch profiles.  Even in 2D profiles, shapes vary enormously. At the first level of simplification, we would deal with 2D polygons only(with an assumption that curved shapes can be converted to polygonal shape by faceting). Divide-and-Conquer is one of the widely used strategy for dealing with complex models. Shape decomposition partitions given shape into sub-shapes and then skeletonization can be performed on simpler sub-polygons. \n\nA polygon can be decomposed into convex regions by dividing at all reflex(concave) vertices. Generally criterion for decomposition is to produce a minimum number of convex components or to minimize the total length of the boundary of these components. Within the minimum component criterion methods further classification could be based on whether or not Steiner points (brand new, non polygonal vertices) are allowed. \n\n", "meta": {"hexsha": "d74d9cf75b703a2af83ebebee9e864400dc5b932", "size": 2943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TalksPublications/MidcurveNN_Vixra/Introduction_Midcurves_etes_paper.tex", "max_stars_repo_name": "yogeshhk/MidcurveNN", "max_stars_repo_head_hexsha": "98e11abdac1c6ab5c76e59dcbdd9ce8c08549a67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2019-06-08T03:25:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T19:35:38.000Z", "max_issues_repo_path": "TalksPublications/MidcurveNN_Vixra/Introduction_Midcurves_etes_paper.tex", "max_issues_repo_name": "yogeshhk/MidcurveNN", "max_issues_repo_head_hexsha": "98e11abdac1c6ab5c76e59dcbdd9ce8c08549a67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-10-06T08:10:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-08T01:33:44.000Z", "max_forks_repo_path": "TalksPublications/MidcurveNN_Vixra/Introduction_Midcurves_etes_paper.tex", "max_forks_repo_name": "yogeshhk/MidcurveNN", "max_forks_repo_head_hexsha": "98e11abdac1c6ab5c76e59dcbdd9ce8c08549a67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-07-06T05:16:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T09:35:03.000Z", "avg_line_length": 70.0714285714, "max_line_length": 474, "alphanum_fraction": 0.6755011893, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7931059462938814, "lm_q1q2_score": 0.6164811419510561}}
{"text": "\\chapter{Abelian categories}\nIn this chapter I'll translate some more familiar concepts into categorical language;\nthis will require some additional assumptions about our category,\nculminating in the definition of a so-called ``abelian category''.\nOnce that's done, I'll be able to tell you what this ``diagram chasing'' thing is all about.\n\nThroughout this chapter, ``$\\injto$'' will be used for monic maps and ``$\\surjto$'' for epic maps.\n\n\\section{Zero objects, kernels, cokernels, and images}\n\\prototype{In $\\catname{Grp}$, the trivial group and homomorphism\nare the zero objects and morphisms.\nIf $G$, $H$ are abelian then the cokernel\nof $\\phi : G \\to H$ is $H/\\img \\phi$.}\n\nA \\vocab{zero object} of a category is an object $0$ which is both initial and terminal;\nof course, it's unique up to unique isomorphism.\nFor example, in $\\catname{Grp}$ the zero object is the trivial group, \nin $\\catname{Vect}_k$ it's the zero-dimensional vector space consisting of one point, and so on.\n\\begin{ques}\n\tShow that $\\catname{Set}$ and $\\catname{Top}$ don't have zero objects.\n\\end{ques}\nFor the rest of this chapter, all categories will have zero objects.\n\nIn a category $\\AA$ with zero objects, any two objects $A$ and $B$ thus have a distinguished morphism\n\\[ A \\to 0 \\to B \\]\nwhich is called the \\vocab{zero morphism} and also denoted $0$.\nFor example, in $\\catname{Grp}$ this is the trivial homomorphism.\n\nWe can now define:\n\\begin{definition}\n\tConsider a map $A \\taking f B$.\n\tThe \\vocab{kernel} is defined as the equalizer of this map and the map $A \\taking 0 B$.\n\tThus, it's a map $\\ker f : \\Ker f \\injto A$ such that\n\t\\begin{diagram}\n\t\t\\Ker f && \\\\\n\t\t\\dInj^{\\ker f} & \\rdDashed^0 & \\\\\n\t\tA & \\rTo_f & B\n\t\\end{diagram}\n\tcommutes, and moreover any other map with the same property factors uniquely through $\\Ker A$\n\t(so it is universal with this property).\n\tBy \\Cref{prob:equalizer_monic}, $\\ker f$ is a monic morphism, \n\twhich justifies the use of ``$\\injto$''.\n\\end{definition}\nNotice that we're using $\\ker f$ to represent the map and $\\Ker f$ to represent the object\nSimilarly, we define the cokernel, the dual notion:\n\\begin{definition}\n\tConsider a map $A \\taking f B$.\n\tThe \\vocab{cokernel} of $f$ is a map $\\coker f: B \\surjto \\Coker f$ such that\n\t\\begin{diagram}\n\t\tA & \\rTo^f & B \\\\\n\t\t& \\rdDashed_0 & \\dSurj_{\\coker f} \\\\\n\t\t&& \\Coker f\n\t\\end{diagram}\n\tcommutes, and moreover any other map with the same property factors\n\tuniquely through $\\Coker f$ (so it is universal with this property).\n\tThus it is the ``coequalizer'' of this map and the map $A \\taking 0 B$.\n\tBy the dual of \\Cref{prob:equalizer_monic}, $\\coker f$ is an epic morphism,\n\twhich justifies the use of ``$\\surjto$''.\n\\end{definition}\nThink of the cokernel of a map $A \\taking f B$ as ``$B$ modulo the image of $f$'', e.g.\n\\begin{example}\n\t[Cokernels]\n\tConsider the map $\\Zc6 \\to D_{12} = \\left\\langle r,s \\mid r^6=s^2=1, rs=sr\\inv\\right\\rangle$.\n\tThen the cokernel of this map in $\\catname{Grp}$ is $D_{12} / \\left\\langle r \\right\\rangle \\cong \\Zc 2$.\n\\end{example}\nThis doesn't always work out quite the way we want since in general the image of\na homomorphism need not be normal in the codomain.\nNonetheless, we can use this to define:\n\\begin{definition}\n\tThe \\vocab{image} of $A \\taking f B$ is the kernel of $\\coker f$.\n\tWe denote $\\Img f = \\Ker(\\coker f)$.\n\tThis gives a unique map $\\img f : A \\to \\Img f$.\n\\end{definition}\nWhen it exists, this coincides with our concrete notion of ``image''.\nPicture:\n\\begin{diagram}\n\tA & \\rTo^f & B \\\\\n\t& \\rdTo(1,2)~{\\exists!} \\rdDashed(3,2)^{0\\qquad\\qquad} \\ruInj(1,2) & & \\rdSurj(1,2)^{\\coker f} \\\\\n\t& \\Img f & \\rDashed^0 & \\Coker f\n\\end{diagram}\nNote that by universality of $\\Img f$,\nwe find that there is a unique map $\\img f : A \\to \\Img f$ that makes the entire diagram commute.\n\n\\section{Additive and abelian categories}\n\\prototype{$\\catname{Ab}$, $\\catname{Vect}_k$, or more generally $\\catname{Mod}_R$.}\nWe can now define the notion of an additive and abelian category,\nwhich are the types of categories where this notion is most useful.\n\n\\begin{definition}\n\tAn \\vocab{additive category} $\\AA$ is one such that:\n\t\\begin{itemize}\n\t\t\\ii $\\AA$ has a zero object, and any two objects have a product.\n\t\t\\ii More importantly: every $\\Hom_\\AA(A, B)$ forms an \\emph{abelian group} (written additively)\n\t\tsuch that composition distributes over addition:\n\t\t\\[ (g+h)\\circ f = g\\circ f + h\\circ f\n\t\t\t\\quad\\text{and}\\quad\n\t\t\tf\\circ(g+h) = f\\circ g + f \\circ h. \\]\n\t\tThe zero map serves as the identity element for each group.\n\\end{itemize}\n\\end{definition}\n\\begin{definition}\n\tAn \\vocab{abelian category} $\\AA$ is one with the additional properties that\n\tfor any morphism $A \\taking f B$,\n\t\\begin{itemize}\n\t\t\\ii The kernel and cokernel exist, and\n\t\t\\ii The morphism factors through the image so that $\\img(f)$ is epic.\n\t\\end{itemize}\n\tSo, this yields a diagram\n\t\\begin{diagram}\n\t\t\\Ker(f) & \\rInj^{\\quad\\ker(f)} & A & \\rSurj^{\\img(f)\\quad} & \\Img(f) & \\rInj & B & \\rSurj^{\\coker(f)} \\Coker(f).\n\t\\end{diagram}\n\\end{definition}\n\n\\begin{example}[Examples of abelian categories]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\catname{Vect}_k$, $\\catname{Ab}$ are abelian categories,\n\t\twhere $f+g$ takes its usual meaning.\n\t\t\\ii Generalizing this, the category $\\catname{Mod}_R$ of $R$-modules is abelian.\n\t\t\\ii $\\catname{Grp}$ is not even additive, because there is no way to assign\n\t\ta commutative addition to pairs of morphisms.\n\t\\end{enumerate}\n\\end{example}\n\nIn general, once you assume a category is abelian, all the properties you would want\nof these kernels, cokernels, \\dots\\ that you would guess hold true.\nFor example,\n\\begin{proposition}[Monic $\\iff$ trival kernel]\n\tA map $A \\taking f B$ is monic if and only if its kernel is $0 \\to A$.\n\tDually, $A \\taking f B$ is epic if and only if its cokernel is $B \\to 0$.\n\\end{proposition}\n\\begin{proof}\n\tThe easy direction is:\n\t\\begin{exercise}\n\t\tShow that if $A \\taking f B$ is monic, then $0 \\to A$ is a kernel.\n\t\t(This holds even in non-abelian categories.)\n\t\\end{exercise}\n\tOf course, since kernels are unique up to isomorphism, monic $\\implies$ $0$ kernel.\n\tOn the other hand, assume that $0 \\to A$ is a kernel of $A \\taking f B$.\n\tFor this we can exploit the group structure of the underlying homomorphisms now.\n\tAssume the diagram\n\t\\begin{diagram}\n\t\tZ & \\pile{\\rTo^g \\\\ \\rTo_h} & A & \\rTo^f & B\n\t\\end{diagram}\n\tcommutes.\n\tThen $(g - h) \\circ f = g \\circ f - h \\circ f = 0$, and we've arrived at a commutative diagram.\n\t\\begin{diagram}\n\t\tZ && \\\\\n\t\t\\dTo^{g-h} & \\rdDotted^0 & \\\\\n\t\tA & \\rTo_f & B\n\t\\end{diagram}\n\tBut since $0 \\to A$ is a kernel it follows that $g-h$ factors through $0$,\n\tso $g-h = 0 \\implies g = h$, which is to say that $f$ is monic.\n\\end{proof}\n\\begin{proposition}[Isomorphism $\\iff$ monic and epic]\n\tIn an abelian category,\n\ta map is an isomorphism if and only if it is monic and epic.\n\\end{proposition}\n\\begin{proof}\n\tOmitted. (The Mitchell embedding theorem\n\tpresented later implies this anyways for\n\tmost situations we care about,\n\tby looking at a small sub-category.)\n\\end{proof}\n\n\\section{Exact sequences}\n\\prototype{$0 \\to G \\to G \\times H \\to H \\to 0$ is exact.}\nExact sequences will seem exceedingly unmotivated until you learn about homology groups,\nwhich is one of the most natural places that exact sequences appear.\nIn light of this, it might be worth trying to read the chapter on homology groups\nsimultaneously with this one.\n\nFirst, let me state the definition for groups, to motivate the general categorical definition.\nA sequence of groups\n\\[ G_0 \\taking{f_1} G_1 \\taking{f_2} G_2 \\taking{f_3} \\dots \\taking{f_n} G_n \\]\nis \\emph{exact} at $G_k$ if the image of $f_k$ is the kernel of $f_{k+1}$.\nWe say the entire sequence is exact if it's exact at $k=1,\\dots,n-1$.\n\\begin{example}\n\t[Exact sequences]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The sequence\n\t\t\\[ 0 \\to \\Zc 3\n\t\t\t\\overset{\\times 5}{\\injto} \\Zc{15}\n\t\t\t\\surjto \\Zc{5}\n\t\t\t\\to 0 \\]\n\t\tis exact.\n\t\tActually, $0 \\to G \\injto G \\times H \\surjto H \\to 0$ is exact in general.\n\t\t(Here $0$ denotes the trivial group.)\n\t\t\\ii For groups, the map $0 \\to A \\to B$ is exact if and only if $A \\to B$ is injective.\n\t\t\\ii For groups, the map $A \\to B \\to 0$ is exact if and only if $A \\to B$ is surjective.\n\t\\end{enumerate}\n\\end{example}\n\nNow, we want to mimic this definition in a general \\emph{abelian} category $\\AA$.\nSo, let's write down a criterion for when $A \\taking f B \\taking g C$ is exact.\nFirst, we had better have that $g \\circ f = 0$,\nwhich encodes the fact that $\\img(f) \\subseteq \\ker(g)$.\nAdding in all the relevant objects, we get the commutative diagram below.\n\\begin{diagram}\n\tA && \\rDashed^0 && C \\\\\n\t\\dSurj^{\\img f} & \\rdTo(2,1)^f & B & \\ruTo(2,1)^g & \\uDashed_0 \\\\\n\t\\Img f & \\ruInj(2,1)_{\\iota} & \\rDotted_{\\exists!} & \\luInj(2,1) & \\Ker g \\\\\n\\end{diagram}\nHere the map $A \\surjto \\Img f$ is epic since we are assuming $\\AA$ is an abelian category.\nSo, we have that\n\\[ 0 = (g \\circ \\iota) \\circ \\img f = g \\circ (\\iota \\circ \\img f) = g \\circ f = 0 \\]\nbut since $\\img f$ is epic, this means that $g \\circ \\iota = 0$.\nSo there is a \\emph{unique} map $\\Img f \\to \\Ker g$, and we require that this diagram commutes.\nIn short,\n\\begin{definition}\n\tLet $\\AA$ be an abelian category. The sequence\n\t\\[ \\dots \\to A_{n-1} \\taking{f_n} A_n \\taking{f_{n+1}} A_{n+1} \\to \\dots \\]\n\tis \\vocab{exact} at $A_n$ if $f_n \\circ f_{n+1} = 0$ and\n\tthe canonical map $\\Img f_n \\to \\Ker f_{n+1}$ is an isomorphism.\n\tThe entire sequence is exact if it is exact at each $A_i$.\n\t(For finite sequences we don't impose condition on the very first and very last object.)\n\\end{definition}\n\n\\begin{exercise}\n\tShow that, as before, $0 \\to A \\to B$ is exact $\\iff$ $A \\to B$ is monic.\n\\end{exercise}\n\n\\section{The Freyd-Mitchell embedding theorem}\nWe now introduce the Freyd-Mitchell embedding theorem,\nwhich essentially says that any abelian category can be realized as a concrete one.\n\n\\begin{definition}\n\tA category is \\vocab{small} if $\\obj(\\AA)$ is a set (as opposed to a class),\n\ti.e.\\ there is a ``set of all objects in $\\AA$''.\n\tFor example, $\\catname{Set}$ is not small because there is no set of all sets.\n\\end{definition}\n\n\\begin{theorem}\n\t[Freyd-Mitchell embedding theorem]\n\tLet $\\AA$ be a small abelian category.\n\tThen there exists a ring $R$ (with $1$ but possibly non-commutative)\n\tand a full, faithful, exact functor onto the category of left $R$-modules.\n\\end{theorem}\nHere a functor is \\vocab{exact} if it preserves exact sequences.\nThis theorem is good because it means\n\\begin{moral}\n\tYou can basically forget about all the weird definitions\n\tthat work in any abelian category.\n\\end{moral}\nAny time you're faced with a statement about an abelian category,\nit suffices to just prove it for a ``concrete'' category\nwhere injective/surjective/kernel/image/exact/etc.\\\nagree with your previous notions.\nA proof by this means is sometimes called \\emph{diagram chasing}.\n\n\\begin{remark}\n\tThe ``small'' condition is a technical obstruction\n\tthat requires the objects $\\AA$ to actually form a set.\n\tI'll ignore this distinction,\n\tbecause one can almost always work around it\n\tby doing enough set-theoretic technicalities.\n\\end{remark}\n\nFor example, let's prove:\n\\begin{lemma}\n\t[Short five lemma]\n\tIn an abelian category, consider the commutative diagram\n\t\\begin{diagram}\n\t\t0 & \\rTo & A & \\rInj^p & B & \\rSurj^q & C & \\rTo & 0 \\\\\n\t\t&& \\dTo^\\cong_\\alpha && \\dTo_\\beta && \\dTo^\\cong_\\gamma && \\\\\n\t\t0 & \\rTo & A' & \\rInj^{p'} & B' & \\rSurj^{q'} & C' & \\rTo & 0\n\t\\end{diagram}\n\tand assume the top and bottom rows are exact.\n\tIf $\\alpha$ and $\\gamma$ are isomorphisms, then so is $\\beta$.\n\\end{lemma}\n\n\\begin{proof}\n\tWe prove that $\\beta$ is epic (with a similar proof to get monic).\n%\tOne can show that it's possible to take a small subcategory of $\\AA$\n%\tcontaining the $10$ elements and $13$ arrows above, as well as all necessary\n%\tkernels, cokernels, et cetera.\n%\t(Essentially, let $\\BB_0$ be the diagram above and let $\\BB_{i+1}$ add in any needed objects;\n%\tthen $\\bigcup \\BB_i$ is a set-sized category).\n\tBy the embedding theorem we can treat the category as $R$-modules over some $R$.\n\tThis lets us do a so-called ``diagram chase'' where we move elements around the picture,\n\tusing the concrete interpretation of our category as $R$-modules.\n\n\tLet $b'$ be an element of $B'$.\n\tThen $q'(b') \\in C'$, and since $\\gamma$ is surjective, we have a $c$ such that $\\gamma(c) = b'$,\n\tand finally a $b \\in B$ such that $q(b) = c$.\n\tPicture:\n\t\\begin{diagram}\n\t\tb \\in B & \\rMapsto^q & c \\in C \\\\\n\t\t\\dDashed_\\beta && \\dMapsto^\\cong_\\gamma \\\\\n\t\tb' \\in B' & \\rMapsto^{q'} & c' \\in C'\n\t\\end{diagram}\n\tNow, it is not necessarily the case that $\\beta(b) = b'$.\n\tHowever, since the diagram commutes we at least have that\n\t\\[ q'(b') = q'(\\beta(b)) \\]\n\tso $b' - \\beta(b) \\in \\Ker q' = \\Img p'$, and there is an $a' \\in A'$ such that\n\t$p'(a') = b' - \\beta(b)$;\n\tuse $\\alpha$ now to lift it to $a \\in A$.\n\tPicture:\n\t\\begin{diagram}\n\t\ta \\in A && b \\in B && \\\\\n\t\t\\dMapsto && && \\\\\n\t\ta' \\in A' & \\rMapsto & b'-\\beta(b) \\in B' & \\rMapsto & 0 \\in C'\n\t\\end{diagram}\n\tThen, we have\n\t\\[\n\t\t\\beta(b + q(a)) = \\beta b + \\beta p a\n\t\t= \\beta b + p' \\alpha a\n\t\t= \\beta b + (b' - \\beta b)\n\t\t= b'\n\t\\]\n\tso $b' \\in \\Img \\beta$ which completes the proof that $\\beta'$ is surjective.\n\\end{proof}\n\n\\section{Breaking long exact sequences}\n\\prototype{First isomorphism theorem.}\n\nIn fact, it turns out that any exact sequence breaks into short exact sequences.\nThis relies on:\n\\begin{proposition}[``First isomorphism theorem'' in abelian categories]\n\t\\label{prop:break_exact}\n\tLet $A \\taking f B$ be an arrow of an abelian category.\n\tThen there is an exact sequence\n\t\\[ 0 \\to \\Ker f \\taking{\\ker f} A \\taking{\\img f} \\Img f \\to 0. \\]\n\\end{proposition}\n\n\\begin{example}\nLet's analyze this theorem in our two examples of abelian categories:\n\\begin{enumerate}[(a)]\n\t\\ii In the category of abelian groups, \n\tthis is basically the first isomorphism theorem.\n\t\\ii In the category $\\catname{Vect}_k$,\n\tthis amounts to the rank-nullity theorem, \\Cref{thm:rank_nullity}.\n\\end{enumerate}\n\\end{example}\nThus, any exact sequence can be broken into short exact sequences, as\n\\begin{diagram}\n\t&& 0 & & 0 && 0 && 0 \\\\\n\t&&& \\rdDotted(1,1) C_n \\ruDotted(1,1) &&&& \\rdDotted(1,1) C_{n+2} \\ruDotted(1,1) & \\\\\n\t\\dots & \\rTo & A_{n-1} \\ruDotted(1,1) & \\rTo^{f_{n-1}} & \\rdDotted(1,1) A_n & \\rTo^{f_n} &\n\tA_{n+1} \\ruDotted(1,1)  & \\rTo^{f_{n+1}} & \\rdDotted(1,1) \\dots \\\\\n\t& \\rdDotted(1,1) C_{n-1} \\ruDotted(1,1) &&&& \\rdDotted(1,1) C_{n+1} \\ruDotted(1,1) &&& \\\\\n\t0 \\ruDotted(1,1) && \\rdDotted(1,1) 0 && 0 \\ruDotted(1,1) && \\rdDotted(1,1) 0 &&\n\\end{diagram}\nwhere $C_k = \\img f_{k-1} = \\ker f_k$ for every $k$.\n\n\\section\\problemhead\n\n\\begin{problem}\n\t[Four lemma]\n\tIn an abelian category, consider the commutative diagram\n\t\\begin{diagram}\n\t\tA & \\rTo^p & B & \\rTo^q & C & \\rTo^r & D \\\\\n\t\t\\dSurj_\\alpha && \\dInj_\\beta && \\dTo_\\gamma && \\dInj_\\delta \\\\\n\t\tA' & \\rTo_{p'} & B' & \\rTo_{q'} & C' & \\rTo_{r'} & D'\n\t\\end{diagram}\n\twhere the first and second rows are exact.\n\tProve that if $\\alpha$ is epic, and $\\beta$ and $\\delta$ are monic,\n\tthen $\\gamma$ is epic.\n\t\\begin{soln}\n\t\tLet $c \\in C$ with $\\gamma(c) = 0$.\n\t\tWe show $c = 0$.\n\t\tThis proceeds in a diagram chase:\n\t\t\\begin{itemize}\n\t\t\t\\ii Note that $0 = r'(\\gamma(c)) = \\delta(r(c))$, and since $\\delta$\n\t\t\tis injective, it follows that $r(c) = 0$.\n\t\t\t\\ii Since the top row is exact,\n\t\t\tit follows $c = q(b)$ for some $b \\in B$.\n\t\t\t\\ii Then $q'(\\beta(b)) = 0$,\n\t\t\tso if we let $b' = \\beta(b)$,\n\t\t\tthen $b' \\in \\ker(q')$.\n\t\t\tAs the bottom row is exact, there exists $a'$ with $p'(a') = b'$.\n\t\t\t\\ii Since $\\alpha$ is injective,\n\t\t\tthere is $a \\in A$ with $\\alpha(a') = a$.\n\t\t\t\\ii Since $\\beta$ is injective,\n\t\t\tit follows that $p(a) = b$.\n\t\t\t\\ii Since the top row is exact, and $b$ is in the image of $p$,\n\t\t\tit follows that $0 = q(b) = c$ as needed.\n\t\t\\end{itemize}\n\n\n\t\\end{soln}<++>\n\\end{problem}\n\n\\begin{problem}\n\t[Five lemma]\n\t\\gim\n\tIn an abelian category, consider the commutative diagram\n\t\\begin{diagram}\n\t\tA & \\rTo^p & B & \\rTo^q & C & \\rTo^r & D & \\rTo^s & E \\\\\n\t\t\\dSurj_\\alpha && \\dTo^\\cong_\\beta && \\dTo_\\gamma && \\dTo^\\cong_\\delta && \\dInj_\\eps \\\\\n\t\tA' & \\rTo_{p'} & B' & \\rTo_{q'} & C' & \\rTo_{r'} & D' & \\rTo_{s'} & E'\n\t\\end{diagram}\n\twhere the first and second rows are exact.\n\tProve that if $\\alpha$ is epic, $\\eps$ is monic, and $\\beta$, $\\delta$ are isomorphisms,\n\tthen $\\gamma$ is an isomorphism as well.\n\tThus this is a stronger version of the short five lemma.\n\\end{problem}\n\n\\begin{sproblem}\n\t[Snake lemma]\n\t\\yod\n\tIn an abelian category, consider the diagram\n\t\\begin{diagram}\n\t\t&& A & \\rTo^f & B & \\rSurj^g & C & \\rTo & 0 \\\\\n\t\t&& \\dTo_a && \\dTo_b && \\dTo_c && \\\\\n\t\t0 & \\rTo & A' & \\rInj_{f'} & B' & \\rTo_{g'} & C' && \n\t\\end{diagram}\n\twhere the first and second rows are exact sequences.\n\tProve that there is an exact sequence\n\t\\[ \\Ker a \\to \\Ker b \\to \\Ker c \\to \\Coker a \\to \\Coker b \\to \\Coker c. \\]\n\\end{sproblem}\n", "meta": {"hexsha": "69e18d2b9a0f0f54f1c52c5fec0eae4132d5e103", "size": 16964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/cats/abelian.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/cats/abelian.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/cats/abelian.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": 41.0750605327, "max_line_length": 114, "alphanum_fraction": 0.6737208206, "num_tokens": 5815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6164811416606577}}
{"text": "\\chapter{angular momentum solutions}\n\\begin{abox}\n\tPractice set 1 solutions\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\t\\item The Hamiltonian of an electron in a constant magnetic field $\\vec{B}$ is given by $H=\\mu \\vec{\\sigma} \\cdot \\vec{B}$. where $\\mu$ is a positive constant and $\\vec{\\sigma}=\\left(\\sigma_{1}, \\sigma_{2}, \\sigma_{3}\\right)$ denotes the Pauli matrices. Let $\\omega=\\mu B / \\hbar$ and $I$ be the $2 \\times 2$ unit matrix. Then the operator $e^{i H t / \\hbar}$ simplifies to\n\t\t\\exyear{NET JUNE 2011}\n\t\\end{minipage}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $I \\cos \\frac{\\omega t}{2}+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\sin \\frac{\\omega t}{2}$\n\t\t\\task[\\textbf{B.}]$I \\cos \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\sin \\omega t$\n\t\t\\task[\\textbf{C.}]$I \\sin \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\cos \\omega t$\n\t\t\\task[\\textbf{D.}]$I \\sin 2 \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\cos 2 \\omega t$\n\t\\end{tasks}\n\\begin{answer}\n\t$H=\\mu \\vec{\\sigma} \\vec{B}$ where $\\vec{\\sigma}=\\left(\\sigma_{1}, \\sigma_{2}, \\sigma_{3}\\right)$ are pauli spin matrices and $\\vec{B}$ are constant magnetic field. $\\vec{\\sigma}=\\left(\\sigma_{1} \\hat{i}, \\sigma_{2} \\hat{j}, \\sigma_{3} \\hat{k}\\right), \\vec{B}=\\left(B_{x} \\hat{i}+B_{y} \\hat{j}+B_{z} \\hat{k}\\right)$ and Hamiltonion $H=\\mu \\vec{\\sigma} \\cdot \\vec{B}$ in matrices form is given by\n\t$$\n\tH=\\mu\\left(\\begin{array}{cc}\n\tB_{z} & B_{x}-i B_{y} \\\\\n\tB_{x}+i B_{y} & -B_{z}\n\t\\end{array}\\right) .\n\t$$\n\tEigenvalue of given matrices are given by $+\\mu \\mathrm{B}$ and $-\\mu \\mathrm{B} . H$ matrices are not diagonals so $e^{i H t / \\hbar}$ is equivalent to\n\t$$\n\tS^{-1}\\left(\\begin{array}{cc}\n\te^{\\frac{i \\mu B t}{\\hbar}} & 0 \\\\\n\t0 & e^{\\frac{-i \\mu B t}{\\hbar}}\n\t\\end{array}\\right) S\n\t$$\n\twhere $S$ is unitary matrices\\\\\n\tand $\\quad S^{-1}=S=\\left(\\begin{array}{cc}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)$.\\\\\n\t$S^{-1}\\left(\\begin{array}{cc}e^{\\frac{i \\mu B t}{\\hbar}} & 0 \\\\ 0 & e^{\\frac{-i \\mu B t}{\\hbar}}\\end{array}\\right) S=\\left(\\begin{array}{cc}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)\\left(\\begin{array}{cc}e^{\\frac{i \\mu B t}{\\hbar}} & 0 \\\\ 0 & e^{\\frac{-i \\mu B t}{\\hbar}}\\end{array}\\right)\\left(\\begin{array}{cc}\\frac{1}{\\sqrt{2}} & \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} & -\\frac{1}{\\sqrt{2}}\\end{array}\\right)$,\\\\ where $\\omega=\\mu \\mathrm{B} / \\hbar$.\\\\\n\t$e^{i H t / \\hbar}=\\left(\\begin{array}{cc}\\cos \\omega t & i \\sin \\omega t \\\\ i \\sin \\omega t & \\cos \\omega t\\end{array}\\right)$,\\\\\n\t which is equivalent to $I \\cos \\omega t+i \\sigma_{x} \\sin \\omega t$ can be written\n\tas $I \\cos \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\sin \\omega t$, where $\\sigma_{x}=\\frac{i \\vec{\\sigma} \\cdot B}{B}$\\\\\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item  In a system consisting of two spin $\\frac{1}{2}$ particles labeled 1 and 2, let $\\vec{S}^{(1)}=\\frac{\\hbar}{2} \\vec{\\sigma}^{(1)}$ and $\\vec{S}^{(2)}=\\frac{\\hbar}{2} \\vec{\\sigma}^{(2)}$ denote the corresponding spin operators. Here $\\vec{\\sigma} \\equiv\\left(\\sigma_{x}, \\sigma_{y}, \\sigma_{z}\\right)$ and $\\sigma_{x}, \\sigma_{y}, \\sigma_{z}$ are the three Pauli matrices.\\\\\n\t$\\text { In the standard basis the matrices for the operators } S_{x}^{(1)} S_{y}^{(2)} \\text { and } S_{y}^{(1)} S_{x}^{(2)} \\text { are respectively, }$\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cc}\n\t\t1 & 0 \\\\\n\t\t0 & -1\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{rr}\n\t\t-1 & 0 \\\\\n\t\t0 & 1\n\t\\end{array}\\right)$\n\t\\task[\\textbf{B.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cc}\n\t\ti & 0 \\\\\n\t\t0 & -i\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{rr}\n\t\t-i & 0 \\\\\n\t\t0 & i\n\t\\end{array}\\right)$\n\t\\task[\\textbf{C.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t\t0 & 0 & 0 & -i \\\\\n\t\t0 & 0 & i & 0 \\\\\n\t\t0 & -i & 0 & 0 \\\\\n\t\ti & 0 & 0 & 0\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t\t0 & 0 & 0 & -i \\\\\n\t\t0 & 0 & -i & 0 \\\\\n\t\t0 & i & 0 & 0 \\\\\n\t\ti & 0 & 0 & 0\n\t\\end{array}\\right)$\n\t\\task[\\textbf{D.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t\t0 & 1 & 0 & 0 \\\\\n\t\t1 & 0 & 0 & 0 \\\\\n\t\t0 & 0 & 0 & -i \\\\\n\t\t0 & 0 & i & 0\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t\t0 & -i & 0 & 0 \\\\\n\t\ti & 0 & 0 & 0 \\\\\n\t\t0 & 0 & 0 & 1 \\\\\n\t\t0 & 0 & 1 & 0\n\t\\end{array}\\right)$\n\\end{tasks}\n\\begin{answer}\n$\\mathrm{S}_{\\mathrm{x}}^{(1)} \\mathrm{S}_{\\mathrm{y}}^{(2)}=\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{ll}\n\t0 & 1 \\\\\n\t1 & 0\n\\end{array}\\right) \\otimes\\left(\\begin{array}{cc}\n\t0 & -\\mathrm{i} \\\\\n\t\\mathrm{i} & 0\n\\end{array}\\right) \\Rightarrow \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & 0 & 0 & -\\mathrm{i} \\\\\n\t0 & 0 & \\mathrm{i} & 0 \\\\\n\t0 & -\\mathrm{i} & 0 & 0 \\\\\n\t\\mathrm{i} & 0 & 0 & 0\n\\end{array}\\right)$\\\\\n$S_{y}^{(1)} S_{x}^{(2)}=\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cc}\n\t0 & -i \\\\\n\ti & 0\n\\end{array}\\right) \\otimes\\left(\\begin{array}{cc}\n\t0 & 1 \\\\\n\t1 & 0\n\\end{array}\\right) \\Rightarrow \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & 0 & 0 & -i \\\\\n\t0 & 0 & -i & 0 \\\\\n\t0 & i & 0 & 0 \\\\\n\ti & 0 & 0 & 0\n\\end{array}\\right)$\t\\\\\nThe correct option is \\textbf{c}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { These two operators of above QUESTION satisfy the relation }$\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left\\{S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right\\}=S_{z}^{(1)} S_{z}^{(2)}$\n\t\\task[\\textbf{B.}]$\\left\\{S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right\\}=0$\n\t\\task[\\textbf{C.}]$\\left[S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right]=i S_{z}^{(1)} S_{z}^{(2)}$\n\t\\task[\\textbf{D.}] $\\left[S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right]=0$\n\\end{tasks}\n\\begin{answer}\n We have matrix $S_{x}^{(1)} S_{y}^{(2)}$ and $S_{y}^{(1)} S_{x}^{(2)}$ from question 6(A) so commutation is given by $\\left[S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right]=0 .$\\\\\n The correct option is \\textbf{(d)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The component along an arbitrary direction $\\hat{n}$, with direction $\\operatorname{cosines}\\left(n_{x}, n_{y}, n_{z}\\right)$, of the spin of a spin $-\\frac{1}{2}$ particle is measured. The result is\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] 0\n\t\\task[\\textbf{B.}]$\\pm \\frac{\\hbar}{2} n_{z}$\n\t\\task[\\textbf{C.}]$\\pm \\frac{\\hbar}{2}\\left(n_{x}+n_{y}+n_{z}\\right)$\n\t\\task[\\textbf{D.}]$\\pm \\frac{\\hbar}{2}$\n\\end{tasks}\n\\begin{answer}\n\t$S_{x}=\\frac{\\hbar}{2}\\left(\\begin{array}{ll}\n\t\t0 & 1 \\\\\n\t\t1 & 0\n\t\\end{array}\\right), S_{y}=\\frac{\\hbar}{2}\\left(\\begin{array}{ll}\n\t\t0 & -i \\\\\n\t\ti & 0\n\t\\end{array}\\right), S_{z}=\\frac{\\hbar}{2}\\left(\\begin{array}{ll}\n\t\t1 & 0 \\\\\n\t\t0 & -1\n\t\\end{array}\\right)$\\\\\n\t$\\overrightarrow{\\mathrm{n}}=\\mathrm{n}_{\\mathrm{x}} \\hat{\\mathrm{i}}+\\mathrm{n}_{\\mathrm{y}} \\hat{\\mathrm{j}}+\\mathrm{n}_{\\mathrm{z}} \\hat{\\mathrm{k}} \\text { and } n_{x}^{2}+n_{y}^{2}+n_{z}^{2}=1, \\vec{S}=S_{x} \\hat{i}+S_{y} \\hat{j}+S_{z} \\hat{k}$\\\\\n\t$\\vec{n} \\cdot \\vec{S}=n_{x}\\left(\\begin{array}{cc}\n\t\t0 & \\frac{\\hbar}{2} \\\\\n\t\t\\frac{\\hbar}{2}\n\t\\end{array}\\right)+n_{y}\\left(\\begin{array}{cc}\n\t\t0 & -\\frac{i \\hbar}{2} \\\\\n\t\t\\frac{i \\hbar}{2} & 0\n\t\\end{array}\\right)+n_{z}\\left(\\begin{array}{cc}\n\t\t\\frac{\\hbar}{2} & 0 \\\\\n\t\t0 & \\frac{-\\hbar}{2}\n\t\\end{array}\\right)$\\\\\n\t$\\vec{n} \\cdot \\vec{S}=\\left(\\begin{array}{ll}\n\t\tn_{z} \\frac{\\hbar}{2} & \\frac{\\hbar}{2}\\left(n_{x}-i n_{y}\\right) \\\\\n\t\t\\frac{\\hbar}{2}\\left(n_{x}+i n_{y}\\right) & -n_{z} \\frac{\\hbar}{2}\n\t\\end{array}\\right)$\\\\\n\tLet $\\lambda$ is eigen value of $\\vec{n} \\cdot \\vec{S}$\n\t$$\n\t\\left|\\begin{array}{ll}\n\tn_{z} \\frac{\\hbar}{2}-\\lambda & \\frac{\\hbar}{2}\\left(n_{x}-i n_{y}\\right. \\\\\n\t\\frac{\\hbar}{2}\\left(n_{x}+i n_{y}\\right) & -n_{z} \\frac{\\hbar}{2}-\\lambda\n\t\\end{array}\\right|=0\n\t$$\n\t$\\Rightarrow-\\left(\\frac{\\mathrm{n}_{\\mathrm{z}} \\hbar}{2}-\\lambda\\right)\\left(\\frac{\\mathrm{n}_{\\mathrm{z}} \\hbar}{2}+\\lambda\\right)-\\frac{\\hbar^{2}}{4}\\left(\\mathrm{n}_{\\mathrm{x}}^{2}+\\mathrm{n}_{\\mathrm{y}}^{2}\\right)=0 \\Rightarrow-\\left(\\frac{n_{z}^{2} \\hbar^{2}}{4}-\\lambda^{2}\\right)-\\frac{\\hbar^{2}}{4}\\left(n_{x}^{2}+n_{y}^{2}\\right)=0$\\\\\n\t$\\Rightarrow-\\frac{\\hbar^{2}}{4}\\left(n_{x}^{2}+n_{y}^{2}+n_{z}^{2}\\right)+\\lambda^{2}=0 \\Rightarrow \\lambda=\\pm \\frac{\\hbar}{2}$\\\\\n\tThe correct option is \\textbf{(d)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item In a basis in which the $z$ - component $S_{z}$ of the spin is diagonal, an electron is in a spin state $\\psi=\\left(\\begin{array}{c}(1+i) / \\sqrt{6} \\\\ \\sqrt{2 / 3}\\end{array}\\right) .$ The probabilities that a measurement of $S_{2}$ will yield the values $\\hbar / 2$ and $-\\hbar / 2$ are, respectively,\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $1 / 2$ and $1 / 2$\n\t\\task[\\textbf{B.}]$2 / 3$ and $1 / 3$\n\t\\task[\\textbf{C.}]$1 / 4$ and $3 / 4$\n\t\\task[\\textbf{D.}]$1 / 3$ and $2 / 3$\n\\end{tasks}\n\\begin{answer}\nEigen state of $S_{z}$ is $\\left|\\phi_{1}\\right\\rangle=\\left(\\begin{array}{l}1 \\\\ 0\\end{array}\\right)$ and $\\left|\\phi_{2}\\right\\rangle=\\left(\\begin{array}{l}0 \\\\ 1\\end{array}\\right)$ corresponds to Eigen value $\\frac{\\hbar}{2}$ and $-\\frac{\\hbar}{2}$ respectively.\n$$\nP\\left(\\frac{\\hbar}{2}\\right)=\\frac{\\left|\\left\\langle\\phi_{1} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\left|\\frac{1+i}{\\sqrt{6}}\\right|^{2}=\\frac{2}{6}=\\frac{1}{3}, \\quad P\\left(-\\frac{\\hbar}{2}\\right)=\\frac{\\left|\\left\\langle\\phi_{2} \\mid \\psi\\right\\rangle\\right|^{2}}{\\langle\\psi \\mid \\psi\\rangle}=\\frac{2}{3}\n$$\nThe correct option is \\textbf{(d)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item A spin $-\\frac{1}{2}$ particle is in the state $\\chi=\\frac{1}{\\sqrt{11}}\\left(\\begin{array}{c}1+i \\\\ 3\\end{array}\\right)$ in the eigenbasis of $S^{2}$ and $S_{2}$. If we measure $S_{z}$, the probabilities of getting $+\\frac{h}{2}$ and $-\\frac{h}{2}$, respectively are\n\t\\exyear{NET DEC 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{2}$ and $\\frac{1}{2}$\n\t\\task[\\textbf{B.}]$\\frac{2}{11}$ and $\\frac{9}{11}$\n\t\\task[\\textbf{C.}] 0 and 1\n\t\\task[\\textbf{D.}]$\\frac{1}{11}$ and $\\frac{3}{11}$\n\\end{tasks}\n\\begin{answer}\n\t$P\\left(\\frac{\\hbar}{2}\\right)=\\left|\\frac{1}{\\sqrt{11}}(10)\\left(\\begin{array}{c}1+i \\\\ 3\\end{array}\\right)\\right|^{2}=\\frac{1}{11} \\times 2=\\frac{2}{11} \\quad \\because\\langle\\psi \\mid \\psi\\rangle=1$\\\\ $P\\left(-\\frac{\\hbar}{2}\\right)=\\left|\\frac{1}{\\sqrt{11}}(01)\\left(\\begin{array}{c}1+i \\\\ 3\\end{array}\\right)\\right|^{2}=\\frac{9}{11}$\\\\\n\ti.e. probability of $S_{z}$ getting $\\left(\\frac{\\hbar}{2}\\right)$ and $\\left(-\\frac{\\hbar}{2}\\right)$\\\\\n\tThe correct option is \\textbf{b}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\\item Let $\\vec{\\sigma}=\\left(\\sigma_{1}, \\sigma_{2}, \\sigma_{3}\\right)$, where $\\sigma_{1}, \\sigma_{2}, \\sigma_{3}$ are the Pauli matrices. If $\\vec{a}$ and $\\vec{b}$ are two arbitrary constant vectors in three dimensions, the commutator $[\\vec{a} \\cdot \\vec{\\sigma}, \\vec{b} \\cdot \\vec{\\sigma}]$ is equal to (in the following $I$ is the identity matrix)\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $(\\vec{a} \\cdot \\vec{b})\\left(\\sigma_{1}+\\sigma_{2}+\\sigma_{3}\\right)$\n\t\\task[\\textbf{B.}]$2 i(\\vec{a} \\times \\vec{b}) \\cdot \\vec{\\sigma}$\n\t\\task[\\textbf{C.}]$(\\vec{a} \\cdot \\vec{b}) I$\n\t\\task[\\textbf{D.}]$|\\vec{a}||\\vec{b}| I$\n\\end{tasks}\n\\begin{answer}\n\t$\\vec{a}=a_{1} \\hat{i}+a_{2} \\hat{j}+a_{3} \\hat{k}, \\vec{b}=b_{1} \\hat{i}+b_{2} \\hat{j}+b_{3} \\hat{k}, \\sigma=\\sigma_{x} \\hat{i}+\\sigma_{y} \\hat{j}+\\sigma_{z} \\hat{k}$\n\t\n\t\\begin{align*}\n\t&{[\\vec{a} \\cdot \\vec{\\sigma}, \\vec{b} \\cdot \\vec{\\sigma}]=\\left[a_{1} \\sigma_{x}+a_{2} \\sigma_{y}+a_{3} \\sigma_{z}, b_{1} \\sigma_{x}+b_{2} \\sigma_{y}+b_{3} \\sigma_{z}\\right]} \\\\\n\t&{[\\vec{a} \\cdot \\vec{\\sigma}, \\vec{b} \\cdot \\vec{\\sigma}]=a_{1} b_{1}\\left[\\sigma_{x}, \\sigma_{x}\\right]+a_{1} b_{2}\\left[\\sigma_{x}, \\sigma_{y}\\right]+a_{1} b_{3}\\left[\\sigma_{x}, \\sigma_{z}\\right]+a_{2} b_{1}\\left[\\sigma_{y}, \\sigma_{x}\\right]+a_{2} b_{2}\\left[\\sigma_{y}, \\sigma_{y}\\right]} \\\\\n\t&+a_{2} b_{3}\\left[\\sigma_{y}, \\sigma_{z}\\right]+a_{3} b_{1}\\left[\\sigma_{z}, \\sigma_{x}\\right]+a_{3} b_{2}\\left[\\sigma_{z}, \\sigma_{y}\\right]+a_{3} b_{3}\\left[\\sigma_{z}, \\sigma_{z}\\right] \\\\\n\t&=a_{1} b_{1} \\cdot 0+a_{1} b_{2} \\cdot 2 i \\sigma_{z}-2 i a_{1} b_{3} \\sigma_{y}-a_{2} b_{1} \\cdot 2 i \\sigma_{z}+0+a_{2} b_{3} \\cdot 2 i \\sigma_{x}+a_{3} b_{1} \\cdot 2 i \\sigma_{y}-a_{3} b_{2} \\cdot 2 i \\sigma_{x}+0 \\\\\n\t&\\Rightarrow[\\vec{a} \\cdot \\vec{\\sigma}, \\vec{b} \\cdot \\vec{\\sigma}]==2 i(\\vec{a} \\times \\vec{b}) \\cdot \\vec{\\sigma}\n\t\\end{align*}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{i}$ are the components of the angular momentum operator $\\vec{L}$, then the operator $\\sum_{i=1,2,3}\\left[\\vec{L}, L_{i}\\right]$ equals\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{L}$\n\t\\task[\\textbf{B.}]$2 \\vec{L}$\n\t\\task[\\textbf{C.}]$3 \\vec{L}$\n\t\\task[\\textbf{D.}]$-\\vec{L}$\n\\end{tasks}\n\\begin{answer}\n\t Let $\\vec{L}=L_{x} \\hat{i}+L_{y} \\hat{j}+L_{z} \\hat{k}$\n\t\\begin{align*}\n\t&x=1, y=2, z=3 \\\\\n\t&{\\left[\\vec{L}, L_{x}\\right]=\\left[L_{y}, L_{x}\\right] j+\\left[L_{z}, L_{x}\\right] \\hat{k}=-i \\hbar L_{z} \\hat{j}+L_{y} \\hat{k} i \\hbar} \\\\\n\t&{\\left[\\left[\\vec{L}, L_{x}\\right], L_{x}\\right]=i \\hbar\\left[-L_{z}, L_{x}\\right] \\hat{j}+\\left[L_{y}, L_{x}\\right] i \\hbar-i \\hbar . i \\hbar L_{y} \\hat{j}-(i \\hbar) L_{z}(i \\hbar) L_{z}(i \\hbar) \\cdot \\hat{k}=\\hbar^{2}\\left[L_{y} \\hat{j}+L_{z} \\hat{k}\\right]} \\\\\n\t&\\text { similarly, }\\left[\\left[\\vec{L}, L_{y}\\right] L_{y}\\right]=\\hbar^{2}\\left[L_{x} \\hat{i}+L_{z} \\hat{k}\\right] \\\\\n\t&{\\left[\\left[\\vec{L}, L_{z}\\right] L_{z}\\right]=\\hbar^{2}\\left[L_{x} \\hat{i}+L_{y} \\hat{j}\\right]} \\\\\n\t&\\sum_{i=1,2,3}[[L, L i] L i]=2 \\hbar^{2}\\left[L_{x} \\hat{i}+L_{y} \\hat{j}+L_{z} \\hat{k}\\right]=2 \\vec{L} \\quad \\text { put } \\hbar=1\n\t\\end{align*}\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian for a spin- $\\frac{1}{2}$ particle at rest is given by $H=E_{0}\\left(\\sigma_{z}+\\alpha \\sigma_{x}\\right)$, where $\\sigma_{x}$ and $\\sigma_{z}$ are Pauli spin matrices and $E_{0}$ and $\\alpha$ are constants. The eigenvalues of this Hamiltonian are\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\pm E_{0} \\sqrt{1+\\alpha^{2}}$\n\t\\task[\\textbf{B.}]$\\pm E_{0} \\sqrt{1-\\alpha^{2}}$\n\t\\task[\\textbf{C.}]$E_{0}$ (doubly degenerate)\n\t\\task[\\textbf{D.}]$E_{0}\\left(1 \\pm \\frac{1}{2} \\alpha^{2}\\right)$\n\\end{tasks}\n\\begin{answer}\n\t$ H=E_{0}\\left(\\dot{\\sigma}_{z}+\\alpha \\sigma_{x}\\right)=E_{0}\\left[\\left(\\begin{array}{cc}1 & 0 \\\\ 0 & -1\\end{array}\\right)+\\alpha\\left(\\begin{array}{ll}0 & 1 \\\\ 1 & 0\\end{array}\\right)\\right] \\Rightarrow H=E_{0}\\left(\\begin{array}{cc}1 & \\alpha \\\\ \\alpha & -1\\end{array}\\right)$\n\tif $\\lambda$ is eigen value, then\n\t$$\n\tH-\\lambda I=0 \\Rightarrow E_{0}\\left(\\begin{array}{cc}\n\t(1-\\lambda) & \\alpha \\\\\n\t\\alpha & -(1+\\lambda)\n\t\\end{array}\\right)=0, \\quad \\lambda=\\pm E_{0} \\sqrt{1+\\alpha^{2}}\n\t$$\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\hat{L}_{x}, \\hat{L}_{y}, \\hat{L}_{z}$ are the components of the angular momentum operator in three dimensions the commutator $\\left[\\hat{L}_{x}, \\hat{L}_{x} \\hat{L}_{y} \\hat{L}_{z}\\right]$ may be simplified to\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar L_{x}\\left(\\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$i \\hbar \\hat{L}_{z} \\hat{L}_{y} \\hat{L}_{x}$\n\t\\task[\\textbf{C.}] $i \\hbar L_{x}\\left(2 \\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t&:\\left[L_{x}, L_{x} L_{y} L_{z}\\right]=L_{x}\\left[L_{x}, L_{y} L_{z}\\right]+\\left[L_{x}, L_{x}\\right] L_{y} L_{z} \\\\\n\t\t&=L_{x}\\left[L_{x}, L_{y}\\right] L_{z}+L_{x} L_{y}\\left[L_{x}, L_{z}\\right]+0=L_{x}\\left[i \\hbar L_{z}\\right] L_{z}+L_{x} L_{y}\\left(-i \\hbar L_{y}\\right) \\\\\n\t\t&=i \\hbar L_{x} L_{z}^{2}-i \\hbar L_{x} L_{y}^{2}=i \\hbar L_{x}\\left(L_{z}^{2}-L_{y}^{2}\\right)\n\t\\end{align*}\n\tThe correct option is \\textbf{(a)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian of a spin $\\frac{1}{2}$ particle in a magnetic field $\\vec{B}$ is given by $H=-\\mu \\cdot \\vec{B} \\cdot \\vec{\\sigma}$, where $\\mu$ is a real constant and $\\vec{\\sigma}=\\left(\\sigma_{x}, \\sigma_{y}, \\sigma_{z}\\right)$ are the Pauli spin matrices. If $\\vec{B}=\\left(B_{0}, B_{0}, 0\\right)$ and the spin state at time $t=0$ is an eigenstate of $\\sigma_{x}$, then of the expectation values $\\left\\langle\\sigma_{x}\\right\\rangle,\\left\\langle\\sigma_{y}\\right\\rangle$ and $\\left\\langle\\sigma_{z}\\right\\rangle$\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] only $\\left\\langle\\sigma_{x}\\right\\rangle$ changes with time\n\t\\task[\\textbf{B.}] only $\\left\\langle\\sigma_{y}\\right\\rangle$ changes with time\n\t\\task[\\textbf{C.}]only $\\left\\langle\\sigma_{z}\\right\\rangle$ changes with time\n\t\\task[\\textbf{D.}]all three change with time\n\\end{tasks}\n\\begin{answer}\n $\\left\\langle\\sigma_{x}\\right\\rangle,\\left\\langle\\sigma_{y}\\right\\rangle$ and $\\left\\langle\\sigma_{z}\\right\\rangle$ will changes with time because Eigen state of $\\sigma_{x}$ ie $\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{l}1 \\\\ 1\\end{array}\\right)$ and $\\frac{1}{\\sqrt{2}}\\left(\\begin{array}{c}1 \\\\ -1\\end{array}\\right)$ and can be written in basis of eigen state of $H=-\\mu \\cdot \\vec{B} \\cdot \\vec{\\sigma}=-B_{0}\\left(\\begin{array}{cc}0 & 1-i \\\\ 1+i & 0\\end{array}\\right)$\\\\\n THe correct option is \\textbf{(d)}\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 2 solutions\n\t\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { For a spin-s particle, in the eigen basis of } \\vec{S}^{2}, S_{x} \\text { the expectation value }\\left\\langle s m\\left|S_{x}^{2}\\right| s m\\right\\rangle \\text { is }$\n\t\\exyear{GATE 2010}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\hbar^{2}\\left\\{s(s+1)-m^{2}\\right\\}}{2}$\n\t\\task[\\textbf{B.}] $\\hbar^{2}\\left\\{s(s+1)-2 m^{2}\\right\\}$\n\t\\task[\\textbf{C.}]$\\hbar^{2}\\left\\{s(s+1)-m^{2}\\right\\}$\n\t\\task[\\textbf{D.}]$\\hbar^{2} m^{2}$\n\\end{tasks}\n\\begin{answer}\n\\begin{align*}\n\t&\\left\\langle s m\\left|S_{x}^{2}\\right| s m\\right\\rangle=\\frac{1}{4}\\left\\langle s m\\left|\\left(S_{+}+S_{-}\\right)^{2}\\right| s m\\right\\rangle=\\frac{1}{4}\\left\\langle s m\\left|S_{+}^{2}+S_{-}^{2}+S_{+} S_{-}+S_{-} S_{+}\\right| s m\\right\\rangle \\\\\n\t&=\\frac{1}{4}\\left\\langle s m\\left|S_{+} S_{-}+S_{-} S_{+}\\right| s m\\right\\rangle=\\frac{\\hbar^{2}}{2}\\left[s(s+1)-m^{2}\\right] \\quad\\left[\\because S_{+} S_{-}+S_{-} S_{+}=2\\left(S^{2}-S_{z}^{2}\\right)\\right]\n\\end{align*}\nThe correct option is \\textbf{(a)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{x}, L_{y}$ and $L_{z}$ are respectively the $x, y$ and $z$ components of angular momentum operator $L$. The commutator $\\left[L_{x} L_{y}, L_{z}\\right]$ is equal to\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar\\left(L_{x}^{2}+L_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$2 i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{answer}\n\t$\\left\\lfloor L_{x} L_{y}, L_{z}\\right\\rfloor=L_{x}\\left[L_{y} L_{z}\\right]+\\left[L_{x}, L_{z}\\right] L_{y}=i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\\\\\n\tThe correct option is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Which one of the following commutation relations is NOT CORRECT? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[L^{2}, L_{z}\\right]=0$\n\t\\task[\\textbf{B.}]$\\left\\lfloor L_{x}, L_{y}\\right\\rfloor=i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$\\left[L_{z}, L_{+}\\right]=\\hbar L_{+}$\n\t\\task[\\textbf{D.}]$\\left[L_{z}, L_{-}\\right]=\\hbar L_{-}$\n\\end{tasks}\n\\begin{answer}\nThe correct option is \\textbf{(d)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item A spin-half particle is in a linear superposition $0.8|\\uparrow\\rangle+0.6|\\downarrow\\rangle$ of its spin-up and spindown states. If $|\\uparrow\\rangle$ and $|\\downarrow\\rangle$ are the eigenstates of $\\sigma_{z}$, then what is the expectation value up to one decimal place, of the operator $10 \\sigma_{z}+5 \\sigma_{x}$ ? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{answer}\n\\begin{align*}\n\t&\\psi\\rangle=.8|\\uparrow\\rangle+.6|\\downarrow\\rangle=0.8\\left(\\begin{array}{l}\n\t\t1 \\\\\n\t\t0\n\t\\end{array}\\right)+0.6\\left(\\begin{array}{l}\n\t\t0 \\\\\n\t\t1\n\t\\end{array}\\right)=\\left(\\begin{array}{l}\n\t\t0.8 \\\\\n\t\t0.6\n\t\\end{array}\\right) \\\\\n\t&\\text { Operator } A=10 \\sigma_{z}+5 \\sigma_{x}=10\\left(\\begin{array}{cc}\n\t\t1 & 0 \\\\\n\t\t0 & -1\n\t\\end{array}\\right)+5\\left(\\begin{array}{ll}\n\t\t0 & 1 \\\\\n\t\t1 & 0\n\t\\end{array}\\right) \\Rightarrow A=\\left(\\begin{array}{cc}\n\t\t10 & 5 \\\\\n\t\t5 & -10\n\t\\end{array}\\right) \\\\\n\t&\\qquad\\langle A\\rangle=\\langle\\psi|A| \\psi\\rangle=\\left(\\begin{array}{ll}\n\t\t0.8 & 0.6\n\t\\end{array}\\right)\\left(\\begin{array}{cc}\n\t\t10 & 5 \\\\\n\t\t5 & -10\n\t\\end{array}\\right)\\left(\\begin{array}{l}\n\t\t0.8 \\\\\n\t\t0.6\n\t\\end{array}\\right)=(8.8-1.2)=7.6\n\\end{align*}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\vec{L}$ is the orbital angular momentum and $\\bar{S}$ is the spin angular momentum, then $\\vec{L} \\cdot \\vec{S}$ does not commute with\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $S_{z}$ \n\t\\task[\\textbf{B.}]$L^{2}$\n\t\\task[\\textbf{C.}]$S^{2}$\n\t\\task[\\textbf{D.}]$(\\vec{L}+\\vec{S})^{2}$\n\\end{tasks}\n\\begin{answer}\nThe correct option is \\textbf{(d)}\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{+}$and $L_{-}$are the angular momentum ladder operators then the expectation value of $\\left(L_{+} L_{-}+L_{-} L_{+}\\right)$in the state $|l=1, m=1\\rangle$ of an atom is $\\hbar^{2}$\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{answer}\n\t$\\left(L_{+} L_{-}+L_{-} L_{+}\\right)=2\\left(L^{2}-L_{z}^{2}\\right)=2\\left(l .(l+1)-m^{2}\\right) \\hbar^{2}=2 \\hbar^{2}$\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item The Pauli matrices for three spin $-\\frac{1}{2}$ particles are $\\vec{\\sigma}_{1}, \\vec{\\sigma}_{2}$ and $\\vec{\\sigma}_{3}$, respectively. The dimension of the Hilbert space required to define an operator $\\hat{O}=\\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2} \\times \\vec{\\sigma}_{3}$ is\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{answer}\n\t$\\sigma_{2} \\times \\sigma_{3} \\text { has dimension of } 4 \\text { and } \\sigma_{1} . \\sigma_{2} \\times \\sigma_{3} \\text { has dimension of } 2 \\times 4=8$\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item Let the Hamiltonian for two spin-1/2 particles of equal masses $m$, momenta $\\vec{p}_{1}$ and $\\vec{p}_{2}$ and positions $\\vec{r}_{1}$ and $\\vec{r}_{2}$ be $H=\\frac{1}{2 m} p_{1}^{2}+\\frac{1}{2 m} p_{2}^{2}+\\frac{1}{2} m \\omega^{2}\\left(r_{1}^{2}+r_{2}^{2}\\right)+k \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}$, where $\\vec{\\sigma}_{1}$ and $\\vec{\\sigma}_{2}$ denote the corresponding Pauli matrices, $\\hbar \\omega=0.1 \\mathrm{eV}$ and $k=0.2 \\mathrm{eV}$. If the ground state has net spin zero, then the energy (in $\\mathrm{eV}$ ) is\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{answer}\n$H=\\frac{1}{2 m} p_{1}^{2}+\\frac{1}{2 m} p_{2}^{2}+\\frac{1}{2} m \\omega^{2}\\left(r_{1}^{2}+r_{2}^{2}\\right)+k \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}$\n\\begin{align*}\n&\\vec{\\sigma}=\\overrightarrow{\\sigma_{1}}+\\vec{\\sigma}_{2} \\Rightarrow \\vec{\\sigma}^{2}=\\sigma_{1}^{2}+\\sigma_{2}^{2}+2 \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2} \\Rightarrow 2 \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}=\\vec{\\sigma}^{2}-\\sigma_{1}^{2}-\\sigma_{2}^{2} \\\\\n&\\Rightarrow 2 \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}=0-3 I-3 I=-6 I \\Rightarrow \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}=-3\n\\end{align*}\nNow energy $E=2 \\times \\frac{3}{2} \\hbar \\omega+k(-3)=3 \\times(0.1)+(0.2)(-3)=-0.3 \\mathrm{eV}$\t\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\vec{s}_{1}$ and $\\vec{s}_{2}$ are the spin operators of the two electrons of a He atom, the value o $\\left\\langle\\vec{s}_{1} \\cdot \\vec{s}_{2}\\right\\rangle$ for the ground state is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{3}{2} \\hbar^{2}$\n\t\\task[\\textbf{B.}]$-\\frac{3}{4} \\hbar^{2}$\n\t\\task[\\textbf{C.}] 0\n\t\\task[\\textbf{D.}] $\\frac{1}{4} \\hbar^{2}$\n\\end{tasks}\n\\begin{answer}\n\t$\\vec{s}=\\vec{s}_{1}+\\vec{s}_{2}, s_{1}=\\frac{1}{2}, s_{1}=\\frac{1}{2}, s=0,1$\\\\ $$\\left\\langle\\vec{s}_{1} \\cdot \\vec{s}_{2}\\right\\rangle=\\frac{s(s+1) \\hbar^{2}-s_{1}\\left(s_{1}+1\\right) \\hbar^{2}-s_{2}\\left(s_{2}+1\\right) \\hbar^{2}}{2}$$\n\tFor $$s=1,\\left\\langle\\vec{s}_{1} \\cdot \\vec{s}_{2}\\right\\rangle=\\frac{2 \\hbar^{2}-\\frac{3}{4} \\hbar^{2}-\\frac{3}{4} \\hbar^{2}}{2}=\\frac{3}{4} \\hbar^{2}$$\n\t$$\n\ts=0,\\left\\langle\\vec{s}_{1} \\cdot \\vec{s}_{2}\\right\\rangle=\\frac{0 \\hbar^{2}-\\frac{3}{4} \\hbar^{2}-\\frac{3}{4} \\hbar^{2}}{2}=-\\frac{3}{4} \\hbar^{2}\n\t$$\n\tThe correct option is \\textbf{(b)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\sigma_{x}, \\sigma_{y} \\text { and } \\sigma_{z} \\text { are the Pauli matrices. The expression } 2 \\sigma_{x} \\sigma_{y}+\\sigma_{y} \\sigma_{x} \\text { is equal to }$\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-3 i \\sigma_{z}$\n\t\\task[\\textbf{B.}]$-i \\sigma_{z}$\n\t\\task[\\textbf{C.}]$i \\sigma_{z}$\n\t\\task[\\textbf{D.}]$3 i \\sigma_{z}$\n\\end{tasks}\n\\begin{answer}\n\t$2 \\sigma_{x} \\sigma_{y}+\\sigma_{y} \\sigma_{x} \\Rightarrow \\sigma_{x} \\sigma_{y}+\\sigma_{x} \\sigma_{y}+\\sigma_{y} \\sigma_{x} \\Rightarrow \\sigma_{x} \\sigma_{y}=i \\sigma_{z}$\\\\\n\tThe correct option is \\textbf{(c)}\n\\end{answer}\n\\begin{minipage}{\\textwidth}\n\t\\item For the Hamiltonian $H=a_{0} I+\\vec{b} \\cdot \\vec{\\sigma}$ where $a_{0} \\in R, \\vec{b}$ is a real vector, $I$ is the $2 \\times 2$ identity matrix, and $\\vec{\\sigma}$ are the Pauli matrices, the ground state energy is\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $|b|$\n\t\\task[\\textbf{B.}]$2 a_{0}-|b|$\n\t\\task[\\textbf{C.}]$a_{0}-|b|$\n\t\\task[\\textbf{D.}]$a_{0}$\n\\end{tasks}\n\\begin{answer}\n$a_{0} I+\\vec{b} \\cdot \\vec{\\sigma}=a_{0}\\left(\\begin{array}{cc}\n\t1 & 0 \\\\\n\t0 & 1\n\\end{array}\\right)+b_{x}\\left(\\begin{array}{cc}\n\t0 & 1 \\\\\n\t1 & 0\n\\end{array}\\right)+b_{y}\\left(\\begin{array}{cc}\n\t0 & -i \\\\\n\ti & 0\n\\end{array}\\right)+b_{z}\\left(\\begin{array}{cc}\n\t1 & 0 \\\\\n\t0 & -1\n\\end{array}\\right)=\\left(\\begin{array}{cc}\n\ta_{0}+b_{z} & b_{x}-i b_{y} \\\\\n\tb_{x}+i b_{y} & a_{0}-b_{z}\n\\end{array}\\right)$\\\\\n$H=a_{0} I+\\vec{b} \\cdot \\vec{\\sigma}=\\left(\\begin{array}{cc}\n\ta_{0}+b_{z} & b_{x}-i b_{y} \\\\\n\tb_{x}+i b_{y} & a_{0}-b_{z}\n\\end{array}\\right)$\\\\\nFor eigen value $\\left(\\begin{array}{cc}a_{0}+b_{z}-\\lambda & b_{x}-i b_{y} \\\\ b_{x}+i b_{y} & a_{0}-b_{z}-\\lambda\\end{array}\\right)=0$\n$$\n\\begin{aligned}\n&\\left(a_{0}+b_{z}-\\lambda\\right)\\left(a_{0}-b_{z}-\\lambda\\right)-\\left(b_{x}^{2}+b_{y}^{2}\\right)=0 \\\\\n&\\lambda_{1}=a_{0}-|b|, \\lambda_{1}=a_{0}+|b|\n\\end{aligned}\n$$\nThe correct option is \\textbf{(c)}\n\\end{answer}\n\\end{enumerate}\n", "meta": {"hexsha": "5fecd5a4cbf52ddb4df50bc816c2555b3ea6ddc4", "size": 26994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/angular momentum solutions.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/angular momentum solutions.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/angular momentum solutions.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": 53.5595238095, "max_line_length": 538, "alphanum_fraction": 0.600133363, "num_tokens": 11794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7931059438487662, "lm_q1q2_score": 0.6164811400504683}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\usepackage{amsmath, amsthm, amssymb, commath, graphicx, bbold, endnotes, graphicx, subfigure, multirow, setspace, siunitx}\n\\usepackage{amsmath}\n\\usepackage[font=footnotesize]{caption}\n\\usepackage[top=1.25in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}\n\\linespread{1}\n\\setlength{\\parindent}{30pt}\n\n\\title{Cosmological Parameters and Conversions Memo}\n\\author{Ruby Byrne}\n\\date{October 2018}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Parallel to the Line-of-Sight}\n\nFrom Morales and Hewitt 2004, frequency $\\Delta f$ is related to the co-moving line-of-sight distance $\\Delta r_z$ by\n\\begin{equation}\n\\Delta f \\approx \\frac{f_{21} E(z)}{D_H (1+z)^2} \\Delta r_z\n\\end{equation}\nThe Fourier inverse of $\\Delta f$ is $\\eta$ and the Fourier inverse of $\\Delta r_z$ is $k_z$. These are related by\n\\begin{equation}\n\\eta \\approx \\frac{D_H (1+z)^2}{2 \\pi f_{21} E(z)} k_z\n\\end{equation}\n$f_{21}$ is the frequency of the 21-cm signal, so $f_{21} = \\frac{c}{0.21 \\si{m}}$. $D_H$ is the Hubble distance. From Hogg 2000,\n\\begin{equation}\nD_H = \\frac{c}{H_0} = 3000 \\frac{\\si{Mpc}}{h}\n\\end{equation}\nwhere $H_0$ is the Hubble constant in the present epoch and $h$ is a dimensionless quantity that is thought to be $0.6 < h < 0.9$ (the \\textit{IDL} function \\texttt{cosmology\\_measures} defaults $h=0.71$). $H_0$ is related to $h$ by\n\\begin{equation}\nH_0 = 100 \\frac{h\\si{km}}{\\si{s.Mpc}}\n\\end{equation}\nAgain from Morales and Hewitt 2004,\n\\begin{equation}\nE(z) = \\sqrt{\\Omega_M(1+z)^3+\\Omega_k(1+z)^2+\\Omega_{\\Lambda}}\n\\end{equation}\nwhere $\\Omega_M$ is the matter constant, $\\Omega_k$ is the curvature constant, and $\\Omega_{\\Lambda}$ is the ``lambda'' constant (whatever that is). \n\nThe \\textit{IDL} function \\texttt{cosmology\\_measures} defaults these parameters to $\\Omega_M=0.27$, $\\Omega_k=0$, and $\\Omega_{\\Lambda}=0.73$. Plugging these to $E(z)$ for $z=7$ in gives $E(7) \\approx 11.79$. Therefore at $z=7$, the conversion between $\\eta$ and $k_z$ is given by\n\\begin{equation}\nk_z \\approx \\left(5.51\\times10^5 \\frac{h}{\\si{s.Mpc}}\\right) \\eta\n\\end{equation}\n\n\n\\section{Perpendicular to the Line-of-Sight}\n\nFrom Morales and Hewitt 2004, sky positions $\\theta_x$ and $\\theta_y$ are related to co-moving distances $r_x$ and $r_y$ according to\n\\begin{equation}\n\\theta_x = \\frac{r_x}{D_M(z)}, \\quad \\theta_y = \\frac{r_y}{D_M(z)}\n\\end{equation}\nThe Fourier inverses of $\\theta_x$ and $\\theta_y$ are $u$ and $v$ and the Fourier inverses of $r_x$ and $r_y$ are $k_x$ and $k_y$. These are related by\n\\begin{equation}\nu = \\frac{k_x D_M(z)}{2 \\pi}, \\quad v = \\frac{k_y D_M(z)}{2 \\pi}\n\\end{equation}\n$D_M$ is the ``transverse co-moving distance.''\n\nFrom Hogg 2000,\n\\begin{equation}\n  D_M=\\begin{cases}\n    D_H \\frac{1}{\\sqrt{\\Omega_k}} \\text{sinh}(\\sqrt{\\Omega_k}D_C/D_H), & \\text{for $\\Omega_k>0$}\\\\\n    D_C, & \\text{for $\\Omega_k=0$}\\\\\n    D_H \\frac{1}{\\sqrt{\\Omega_k}} \\text{sin}(\\sqrt{\\Omega_k}D_C/D_H), & \\text{for $\\Omega_k<0$}\n  \\end{cases}\n\\end{equation}\n$D_C$ is the co-moving distance and is defined as\n\\begin{equation}\nD_C = D_H \\int_0^z \\frac{dz'}{E(z')} = D_H \\int_0^z \\frac{dz'}{\\sqrt{\\Omega_M(1+z')^3+\\Omega_k(1+z')^2+\\Omega_{\\Lambda}}}\n\\end{equation}\n\nThis integral must be evaluated numerically. With $z=7$, $\\Omega_M=0.27$, $\\Omega_k=0$, and $\\Omega_{\\Lambda}=0.73$ as above and evaluating the integral with \n\\textit{Mathematica}, we get that\n\\begin{equation}\nD_C \\approx D_H(2.09) = 6.27 \\times 10^3 \\frac{\\si{Mpc}}{h}\n\\end{equation}\nThis integral is also evaluated by \\textit{IDL}'s \\texttt{cosmology\\_measures} function. Since we are assuming $\\Omega_k=0$, $D_M=D_C$ and\n\\begin{equation}\nD_M \\approx 6.27 \\times 10^3 \\frac{\\si{Mpc}}{h}\n\\end{equation}\nTo convert from $(u, v)$ coordinates to $(k_x,k_y)$ coordinates, we therefore get\n\\begin{equation}\nk_x \\approx \\left(1.00\\times10^{-3} \\frac{h}{\\si{Mpc}}\\right)u, \\quad k_y \\approx \\left(1.00\\times10^{-3} \\frac{h}{\\si{Mpc}}\\right)v\n\\end{equation}\n\n\\end{document}", "meta": {"hexsha": "8a4f2466a7e20282926c85052388b22b6f758f82", "size": 3958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "002_Cosmological_Units/Cosmological_Units.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": "002_Cosmological_Units/Cosmological_Units.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": "002_Cosmological_Units/Cosmological_Units.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": 46.023255814, "max_line_length": 281, "alphanum_fraction": 0.6960586155, "num_tokens": 1468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568417, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.6164811299667331}}
{"text": "% ----------------------------------------------------------------------\n\\section{Incompressible Isotropic Elasticity with Infinitesimal Strain (Bathe)}\n\nIn this section we apply a similar approach to the one we use for the\nelasticity equation to the case of an incompressible material. We only\nconsider the quasistatic case (neglect inertia) without faults. As the\nbulk modulus ($K$) approaches infinity, the volumetric strain\n($\\Tr(\\epsilon)$) approaches zero and the pressure remains finite,\n$p = -K \\Tr(\\epsilon)$. We consider pressure $p$ as an independent\nvariable and decompose the stress into the pressure and deviatoric\ncomponents. As a result, we write the stress tensor in terms of both\nthe displacement and pressure fields,\n\\begin{equation}\n  \\tensor{\\sigma}(\\vec{u},p) = \\tensor{\\sigma}^\\mathit{dev}(\\vec{u}) - p\\tensor{I}.\n\\end{equation}\n\nThe strong form is\n\\begin{gather}\n  % Solution\n  \\vec{s}^T = \\left( \\vec{u} \\quad \\ p \\right)^T, \\\\\n  % Elasticity\n  \\vec{f}(t) + \\tensor{\\nabla} \\cdot \\left(\\tensor{\\sigma}^\\mathit{dev}(\\vec{u}) - p\\tensor{I}\\right) = \\vec{0} \\text{ in }\\Omega, \\\\\n  % Pressure\n  \\vec{\\nabla} \\cdot \\vec{u} + \\frac{p}{K} = 0 \\text{ in }\\Omega, \\\\\n  % Neumann\n  \\tensor{\\sigma} \\cdot \\vec{n} = \\vec{\\tau} \\text{ on }\\Gamma_\\tau, \\\\\n  % Dirichlet\n  \\vec{u} = \\vec{u}_0 \\text{ on }\\Gamma_u, \\\\\n  p = p_0 \\text{ on }\\Gamma_p.\n\\end{gather}\nWe place all terms for the elasticity and pressure equations on the\nleft-hand-side, consistent with PETSc TS implicit time stepping.\n\n\\begin{table}[htbp]\n  \\caption{Mathematical notation for incompressible elasticity with\n    infinitesimal strain.}\n  \\label{tab:notation:incompressible:elasticity}\n  \\begin{tabular}{lcp{3.5in}}\n    \\toprule\n    {\\bf Category} & {\\bf Symbol} & {\\bf Description} \\\\\n    \\midrule\n    Unknowns & $\\vec{u}$ & Displacement field \\\\\n    & $p$ & Pressure field ($p>0$ corresponds to negative mean stress \\\\\n    Derived quantities & $\\tensor{\\sigma}$ & Cauchy stress tensor \\\\\n                   & $\\tensor{\\epsilon}$ & Cauchy strain tensor \\\\\n    Common constitutive parameters & $\\rho$ & Density \\\\\n  & $\\mu$ & Shear modulus \\\\\n  & $K$ & Bulk modulus \\\\\nSource terms & $\\vec{f}$ & Body force per unit volume, for example $\\rho \\vec{g}$ \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{table}\n\nUsing trial functions $\\trialvec[u]$ and $\\trialscalar[p]$ and\nincorporating the Neumann boundary conditions, we write the weak form\nas\n\\begin{gather}\n  % Displacement\n  \\int_\\Omega \\trialvec[u] \\cdot \\vec{f}(t) + \\nabla \\trialvec[u] : \\left(-\\tensor{\\sigma}^\\mathit{dev}(\\vec{u}) + p\\tensor{I}\n  \\right)\\, d\\Omega + \\int_{\\Gamma_\\tau} \\trialvec[u] \\cdot \\vec{\\tau}(t) \\, d\\Gamma, = 0 \\\\\n  % Pressure\n  \\int_\\Omega \\trialscalar[p] \\cdot \\left(\\vec{\\nabla} \\cdot \\vec{u} + \\frac{p}{K} \\right) \\, d\\Omega = 0.\n\\end{gather}\n\n\\subsection{Residual Pointwise Functions}\n\nIdentifying $F(t,s,\\dot{s})$, we have\n\\begin{gather}\n  \\label{eqn:incompressible:elasticity:displacement}\n  F^u(t,s,\\dot{s}) = \\int_\\Omega \\trialvec[u] \\cdot \\eqnannotate{\\vec{f}(t)}{f_0^u} + \\nabla \\trialvec[u] :\n  \\eqnannotate{\\left(-\\tensor{\\sigma}^\\mathit{dev}(\\vec{u}) + p\\tensor{I}\\right)}{f_1^u}  \\, d\\Omega\n  + \\int_{\\Gamma_\\tau} \\trialvec[u] \\cdot \\eqnannotate{\\vec{\\tau}(t)}{f_0^u} \\, d\\Gamma, \\\\\n%\n  \\label{eqn:incompressible:elasticity:pressure}\n  F^p(t,s,\\dot{s}) = \\int_\\Omega \\trialscalar[p] \\cdot \\eqnannotate{\\left(\\vec{\\nabla} \\cdot \\vec{u} + \n\\frac{p}{K} \\right)}{f_0^p} \\, d\\Omega.\n\\end{gather}\n\n\\subsection{Jacobians Pointwise Functions}\n\nWith two fields we have four Jacobian pointwise functions for the LHS:\n\\begin{align}\n  % JF uu\n  J_F^{uu} &= \\frac{\\partial F^u}{\\partial u} + s_\\mathit{tshift} \\frac{\\partial F^u}{\\partial \\dot{u}} =\n             \\int_\\Omega \\nabla \\trialvec[u] : \\frac{\\partial}{\\partial u}(-\\tensor{\\sigma}^\\mathit{dev}) \\, d\\Omega \n             = \\int_\\Omega \\trialscalar[u]_{i,k} \\, \\eqnannotate{\\left(-C^\\mathit{dev}_{ikjl}\\right)} {J_{f3}^{uu}}  \\, \\basisscalar[u]_{j,l}\\, d\\Omega \\\\\n  % JF up\n  J_F^{up} &= \\frac{\\partial F^u}{\\partial p} + s_\\mathit{tshift} \\frac{\\partial F^u}{\\partial \\dot{p}} =\n             \\int_\\Omega \\nabla\\trialvec[u] : \\tensor{I} \\basisscalar[p] \\,  d\\Omega\n             = \\int_\\Omega \\trialscalar[u]_{i,k} \\eqnannotate{\\delta_{ik}}{J_{f2}^{up}} \\, \\basisscalar[p] \\, d\\Omega \\\\\n  % JF pu\n  J_F^{pu} &= \\frac{\\partial F^p}{\\partial u} + s_\\mathit{tshift} \\frac{\\partial F^p}{\\partial \\dot{u}} =\n             \\int_\\Omega \\trialscalar[p] \\left(\\vec{\\nabla}  \\cdot \\basisvec[u]\\right) \\, d\\Omega\n             = \\int_\\Omega \\trialscalar[p] \\eqnannotate{\\delta_{jl}}{J_{f1}^{pu}} \\basisscalar[u]_{j,l} \\, d\\Omega\\\\\n  % JF pp\n  J_F^{pp} &= \\frac{\\partial F^p}{\\partial p}  + s_\\mathit{tshift} \\frac{\\partial F^p}{\\partial \\dot{p}} =\n             \\int_\\Omega \\trialscalar[p] \\eqnannotate{\\frac{1} {K}}{J_{f0}^{pp}} \\basisscalar[p] \\, d\\Omega\n\\end{align}\n\nFor isotropic, linear incompressible elasticity, the deviatoric elastic constants are:\n\\begin{align}\n    C_{1111} &= C_{2222} = C_{3333} = +\\frac{4}{3} \\mu \\\\\n    C_{1122} &= C_{1133} = C_{2233} = -\\frac{2}{3} \\mu \\\\\n    C_{1212} &= C_{1313} = C_{2323} = \\mu\n\\end{align}\n", "meta": {"hexsha": "1b72db5332590c4d2852b352743ff009b2aaef49", "size": 5144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/userguide/governingeqns/incompressible_elasticity.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/incompressible_elasticity.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/incompressible_elasticity.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": 48.5283018868, "max_line_length": 154, "alphanum_fraction": 0.634525661, "num_tokens": 1801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6164651050776853}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n%opening\n\\title{Actor Critic Agent}\n\\author{Marco Marini}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nDescription of Actor Critic Agent and definitions of performance indicators\n\\end{abstract}\n\n\\tableofcontents\n\n\\section{Actor Critic Agent}\n\nThe Policy Actor Critic Agent is composed by an artificial neural network (ANN) that generates the differential state value of critic component and the policy parameters for action selection of each actor (the action space dimensions) from the state input signals.\nAt each iteration with the environment, the agent computes the average reward $r_\\pi$ and the differential TD error $ \\delta_t $\n\\begin{equation}\n\\delta_t = R_{t+1} - \\bar R + \\hat v(S_{t+1}) - \\hat v(S_t)\t\n\\end{equation}\n\nThe differential TD error indicate how different is the differential state value determined by the current reward from the estimated differential state value.\n\nIf the error is positive the agent changes the policy reinforcing the current strategy. It increments the probabilities of selected actions and at the same time reduces the probabilities of the other actions.\n\nIf the error is negative the agent changes the policy weakening the current strategy. It reduces the probabilities of selected actions and increments the probabilities of the other actions.\n\nThe magnitude of changes is proportional to the TD Error by a $ \\alpha_i $ parameter for each $ i $ actor that allows to control the convergence of the algorithm.\n\nThe TD error is used to determine the updated output values and train the AAN with these expected outputs.\n\n\\subsection{Discrete Policy Actor}\n\nThe policy actor computes the probabilities $ \\pi(a|s) $ of choose action $ a $ at status $ s $.\nThe probabilities are the softmax function of the action preferences $ h(s,a,\\vec \\theta) $ given by the ANN \n\\begin{align}\n\t\\pi(a|s, \\vec \\theta)\n\t&= \\frac{e^{h_a(s,a,\\vec{\\theta})}}{\\sum_{b \\in A} e^{h(s,b,\\vec{\\theta})}}\n\\end{align}\n\nTo train the ANN the agent updates the $ \\vec \\theta $ parameters at each step $ t $\n\\begin{align}\n\t\\vec \\theta_{t+1} =\n\t\\vec \\theta_t + \\alpha \\delta_t \\nabla \\ln \\pi(A_t|S_t, \\vec \\theta_t) \n\\end{align}\n\nThe policy gradient function is\n\\begin{align*}\n\\begin{split}\n\t\\nabla \\ln \\pi(A_t|S_t, \\vec \\theta)\n\t& = \\frac{1}{\\pi(A_t|S_t, \\vec \\theta)}\n\t\\nabla \\pi(A_t|S_t, \\vec \\theta)\n\t\\\\\n\t\\pi(a|s, \\vec \\theta)\n\t&= \\frac{e^{h_a(s,a,\\vec{\\theta})}}{D(s,\\vec \\theta)}\n\t\\\\\n\tD(s,\\vec \\theta)\n\t&= \\sum_{b \\in A} e^{h(s,b,\\vec{\\theta})}\n\t\\\\\n\t\\nabla \\pi(A_t|S_t, \\vec \\theta)\n\t& =\n\t\\frac{1}{D^2(S_t,\\vec \\theta)}\n\t\\left[\n\t\tD(S_t, \\vec \\theta) \\nabla e^{h(S_t,A_t,\\vec \\theta)} - e^{h(S_t,A_t,\\vec \\theta)} \\nabla D(S_t, \\vec \\theta)\n\t\\right] \n\t\\\\\n\t& =\t\\frac{1}{D^2(S_t,\\vec \\theta)}\n\t\\left[\n\t\tD(S_t, \\vec \\theta) e^{h(S_t,A_t,\\vec \\theta)} \\nabla h(S_t,A_t,\\vec \\theta)\n\t\t- e^{h(S_t,A_t,\\vec \\theta)} \\nabla D(S_t, \\vec \\theta)\n\t\\right] \n\t\\\\\n\t& =\n\t\\frac{\\pi(A_t|S_t,\\vec \\theta)}{D(S_t,\\vec \\theta)}\n\t\\left[\n\t\tD(S_t, \\vec \\theta) \\nabla h(S_t,A_t,\\vec \\theta)\n\t\t- \\nabla D(S_t, \\vec \\theta)\n\t\\right] \n\t\\\\\n\t\\nabla D(s,\\vec \\theta)\n\t&= \\sum_{b \\in A} \\nabla e^{h(s,b,\\vec \\theta)}\n\t\\\\\n\t&= \\sum_{b \\in A} e^{h(s,b,\\vec \\theta)}\t\\nabla h(s,b,\\vec \\theta)\n\t\\\\\n\t\\nabla \\pi(A_t|S_t, \\vec \\theta)\n\t& =\n\t\\frac{\\pi(A_t|S_t,\\vec \\theta)}{D(S_t,\\vec \\theta)}\n\t\\left[\n\t\tD(S_t, \\vec \\theta) \\nabla h(S_t,A_t,\\vec \\theta)\n\t\t- \\sum_{b \\in A} e^{h(s,b,\\vec \\theta)}\t\\nabla h(s,b,\\vec \\theta)\n\t\\right] \n\\end{split}\n\\end{align*}\n\nLet be\n\\begin{align*}\n\tI(a, b) = 1, \\Rightarrow a = b\n\t\\\\\n\tI(a,b) = 0 \\Rightarrow a \\ne b\n\\end{align*}\nthen\n\\begin{align*}\n\\begin{split}\n\t\\sum_{b \\in A} I(At, b) \\nabla h(St, b), \\vec \\theta)\n\t&= \\nabla h(St, At), \\vec \\theta)\n\t\\\\\n\t\\nabla \\pi(A_t|S_t, \\vec \\theta)\n\t&=\n\t\\frac{\\pi(A_t|S_t,\\vec \\theta)}{D(S_t,\\vec \\theta)}\n\t\\sum_{b \\in A}\n\t\\left[\n\t\tD(S_t, \\vec \\theta) I(A_t,b)\n\t\t-  e^{h(S_t,b,\\vec \\theta)}\n\t\\right] \t\n\t\\nabla h(S_t,b,\\vec \\theta)\n\t\\\\\n\t\\nabla \\ln \\pi(A_t|S_t, \\vec \\theta)\n\t&=\n\t\\sum_{b \\in A}\n\t\\left[\n\t\tI(A_t,b)\n\t\t-  \\pi(S_t,b,\\vec \\theta)\n\t\\right] \t\n\t\\nabla h(S_t,b,\\vec \\theta)\n\t\\\\\n\t\\delta_h(S_t, A_t, b, \\theta_t)\n\t&= \\delta_t\n\t\\left[\n\t\tI(A_t,b) - \\pi(S_t,b,\\vec \\theta)\n\t\\right] \n\t\\\\\n\t\\vec \\theta_{t+1}\n\t&=\n\t\\vec \\theta_t +\n\t\\sum_{b \\in A}\n\t\\alpha \\delta_h(S_t, A_t, b, \\theta_t)  \\nabla h(S_t,b,\\vec \\theta_t)\n\\end{split}\n\\end{align*}\n\nThe same result is obtained by training the network with labels\n\\begin{align}\n\\begin{split}\n\th^*(S_t,A_t,b) = h(S_t,b,\\vec \\theta_t) + \n\t\\alpha \\delta_h(S_t, A_t, b, \\vec \\theta_t)\n\\end{split}\n\\end{align}\n\n\\subsection{Gaussian policy actor}\n\nThe Gaussian policy actor computes the probabilities $ \\pi(a|s) $ of choose a continuous action $ a $ at status $ s $ as a normal distributed function of two parameters $ \\mu(s, \\vec \\theta_\\mu) $ and $ \\sigma(s,\\vec \\theta_h) $.\n\n\\begin{align}\n\t\\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)\n\t&= \\frac{1}{\\sigma(s,\\vec \\theta_h) \\sqrt{2 \\pi}} e^{-\\frac{(a - \\mu(s, \\vec \\theta_\\mu))^2}{\\sigma(s, \\vec \\theta_h)^2}}\n\t\\\\\n\t\\sigma(s, \\vec \\theta_h)\n\t&\t= e^{h(s, \\vec \\theta_h)}\t\n\\end{align}\n\nTo train the ANN the agent updates the $ \\vec \\theta_\\mu, \\vec \\theta_h $ parameters at each step $ t $\n\\begin{align}\n\t\\vec \\theta_{\\mu t+1}\n\t&= \\vec \\theta_{\\mu t}\n\t+ \\alpha_\\mu \\delta_t \\nabla \\ln \\pi(A_t|S_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{h t})\n\t\\\\\n\t\\vec \\theta_{h+1}\n\t&= \\vec \\theta_{h t}\n\t+ \\alpha_h \\delta_t \\nabla \\ln \\pi(A_t|S_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{h t})\n\\end{align}\n\nThe policy gradient functions for $\\vec \\theta_\\mu $ is\n\\begin{align*}\n\t\\nabla \\ln \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)\n\t& = \\pi^{-1}(a|s,\\vec \\theta_\\mu, \\vec \\theta_h) \\nabla \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)\n\t\\\\\n\t& = \\pi^{-1}(a|s,\\vec \\theta_\\mu, \\vec \\theta_h) \\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)}{\\partial \\mu(s, \\vec \\theta_\\mu)} \\nabla \\mu(s, \\vec \\theta_\\mu)\n\t\\\\\n\t\\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)}{\\partial \\mu(s, \\vec \\theta_\\mu)}\n\t& = - \\frac{1}{\\sigma^3(s, \\vec \\theta_h) \\sqrt{2 \\pi} } e^{-\\frac{(a-\\mu(s, \\vec \\theta_\\mu))^2}{\\sigma^2(s, \\vec \\theta_h)}} \\frac{\\partial }{\\partial \\mu(s,\\vec \\theta_\\mu)} (a-\\mu(s, \\vec \\theta_\\mu))^2\n\t\\\\\n\t& = -\\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)  (-2) (a - \\mu(s, \\vec \\theta_\\mu)) \\sigma^{-2}(s, \\vec \\theta_h)\n\t\\\\\n\t\\nabla \\ln \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)\n\t& = \\frac{2 [a - \\mu(s, \\vec \\theta_\\mu)]}{\\sigma^2(s, \\vec \\theta_h)} \\nabla \\mu(s, \\vec \\theta_\\mu)\n\\end{align*}\nThe policy gradient functions for $\\vec \\theta_h $ is\n\\begin{align*}\n\t\\nabla \\ln \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )\n\t& = \\pi^{-1}(a|s,\\vec \\theta_\\mu, \\vec \\theta_h ) \\nabla \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)\n\t\\\\\n\t& = \\pi^{-1}(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )\n\t\\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )}{\\partial h(s, \\vec \\theta_h)} \\nabla h(s, \\vec \\theta_h)\n\t\\\\\t\n\t\\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )}{\\partial h(s, \\vec \\theta_h)}\n\t&= \\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )}{\\partial \\sigma(s, \\vec \\theta_h)}\n \t\\frac{\\partial \\sigma(s, \\vec \\theta_h)}{\\partial h(s, \\vec \\theta_h)}\n\t\\\\\n\t\\frac{\\partial \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )}{\\partial \\sigma(s, \\vec \\theta_h)}\n\t& = \\frac{\n\t\\left\\{\n\t\t\\sigma(s,\\vec \\theta_h) \\frac{\\partial}{\\partial \\sigma(s,\\vec \\theta_h)}\n\t\t\\left[\n\t\t\te^{-\\frac{(a-\\mu(s, \\vec \\theta_\\mu))^2}{\\sigma^2(s,\\vec \\theta_h)}}\n\t\t\\right]\n\t\t- e^{-\\frac{(a-\\mu(s, \\vec \\theta_\\mu))^2}{\\sigma^2(s, \\vec \\theta_h)}}\n\t\\right\\}}{\\sigma^2(s,\\vec \\theta_h) \\sqrt{2 \\pi}}\t\n\t\\\\\n\t& = \\frac{\n\te^{-\\frac{(a-\\mu(s, \\vec \\theta_\\mu))^2}{\\sigma^2(s,\\vec \\theta_h)}}\n\t\\left\\{\n\t\t-\\sigma(s,\\vec \\theta_h)\n\t\t(a-\\mu(s,\\vec \\theta_\\mu))^2\n\t\t\\frac{\\partial}{\\partial \\sigma(s,\\vec \\theta_h)}\n\t\t\\left[\n\t\t\t\\sigma^{-2}(s,\\vec \\theta_h)\n\t\t\\right]\n\t\t- 1\n\t\\right\\} }{\\sigma^2(s,\\vec \\theta_h) \\sqrt{2 \\pi}}\t\n\t\\\\\n\t& = \\frac{\\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h)}{\\sigma(s,\\vec \\theta_h)}\n\t\\left\\{\n\t\t2 \\frac{(a-\\mu(s,\\vec \\theta_\\mu))^2} {\\sigma^2(s,\\vec \\theta_h)} - 1\n\t\\right\\}\n\t\\\\\n\t\\frac{\\partial \\sigma(s,\\vec \\theta_h)}{\\partial h(s,\\vec \\theta_h)}\n\t&= e^{h(s, \\vec \\theta_h)}\n\t\\\\\n\t&= \\sigma(s, \\vec \\theta_h)\n\t\\\\\n\t\\nabla \\ln \\pi(a|s,\\vec \\theta_\\mu, \\vec \\theta_h )\n\t& = 2 \\frac{(a-\\mu(s,\\vec \\theta_\\mu))^2} {\\sigma^2(s,\\vec \\theta_h)} - 1\n\\end{align*}\n\nLet be\n\\begin{align*}\n\t\\delta_\\mu(s, a, \\vec \\theta_\\mu, \\vec \\theta_h )\n\t&= \\delta_t 2 \\frac{a - \\mu(s, \\vec \\theta_\\mu)}{\\sigma^2(s, \\vec \\theta_h)}\n\t\\\\\n\t\\delta_h(s, a, \\vec \\theta_\\mu, \\vec \\theta_h )\n\t&= \\delta_t \n\t\\left[\n\t\t2 \\frac{(a-\\mu(s,\\vec \\theta_\\mu))^2} {\\sigma^2(s,\\vec \\theta_h)} - 1\n\t\\right]\n\\end{align*}\n\nThe $ \\vec \\theta_\\mu, \\vec \\theta_h $ parameters are updated by\n\\begin{align*}\n\t\\vec \\theta_{\\mu t+1}\n\t&= \\vec \\theta_{\\mu t} + \\alpha_\\mu \\delta_\\mu(S_t, A_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{h t} ) \n\t\\\\\n\t\\vec \\theta_{h t+1}\n\t&= \\vec \\theta_{h t} + \\alpha_h \\delta_h(S_t, A_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{ht} ) \n\\end{align*}\n\nThe same result is obtained by training the network with labels\n\\begin{align}\n\t\\mu^*(S_t) = \\mu(S_t,\\vec \\theta_{\\mu t}) + \n\t\\alpha_\\mu \\delta_\\mu(S_t, A_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{ht})\n\t\\\\\n\th^*(S_t) = h(S_t,\\vec \\theta_{\\mu t}) + \n\\alpha_h \\delta_h(S_t, A_t, \\vec \\theta_{\\mu t}, \\vec \\theta_{ht})\n\\end{align}\n\n\\subsection{Learning process}\n\nInitially the agent do not have any experience and the differential state value generated by the ANN starts from a random initial estimation. The same is for the behavior generated by the actors where the preferences are random initialized.\n\nSince the very first interactions the agent generates wrong differential state value estimation with high value of TD Error. Consequently the agent easily changes the policy behavior, trying different policies with the exploration of both the policy and state space. It tries to improve the average reward, the value state estimation at the same time selecting better policies.\n\nDifferent factors influence the learning process.\nExternal agent factors like the number of states, actions and policies not yet explored tent to generate high error rate.\nThe error increases as the agent experiences new environment states or try new policies, but as the agent faces states already visited it can exploit the past experiences reducing the error and improving the state value estimation and the policy.\n\nInstead the agent internal factor, such as the ANN approximation, generates errors that can be reduced only to a low-bound limit value.\n\nThe ANN learning parameters can influence both in the quality of approximated functions and in the  speed of adaptation.\n\nHigh value of step-size parameter $ \\eta $ increases the correction of weights increasing consequently the speed of adaptation, but can easily generate corrective value too big bringing the network to not converging behaviors.\nOn the other hand small value of step-size parameter weakens the correction of weights decreasing the speed of adaptation.\n\nAlso the actor parameters $ \\alpha_i $, which modulate the policy changes from the critic, influence the improvement capacity.\nHigh value of $ \\alpha_i $ determine strong policy changes even in the face of small errors, making it difficult a fine correction, the other way around very small value of $ \\alpha_a $ bring very little variations on policy without improvement.\n\nIf the actor parameters that govern the policy have a limited range of values we may choose an $ \\alpha_i = \\alpha^*_i $ so that the average of corrections is $ \\varepsilon_i $ a fraction of the limited range.\n\nFor the discrete policy actors we calculate the average of squared preferences variations $ \\Delta^2h_{i} $\n\\begin{align*}\n\th^*_{ia}(t) - h_{ia}(t)&=\t\\Delta h_{ia}(t)\n\t\\\\\n\t&=\t\\alpha_i \\delta_{h_{ia}}(t)\n\t\\\\\n\t\\Delta^2h_{i}(t)&=\t\t\t\\frac{1}{m} \\sum_a^m \\Delta h_{ia}(t)\n\t\\\\\n\t\\Delta^2h_{i}&=\t\t\t\\frac{1}{n} \\sum_t^n \\Delta^2 h_{i}(t)\n\t\\\\\n\t&=\t\t\t\\frac{1}{n}\\frac{1}{m}\\sum_t^n \\sum_a^m \\Delta^2 h_{ia}(t)\n\t\\\\\n\t&=\t\\alpha^2_i\\frac{1}{n}\\frac{1}{m}\\sum_t^n \\sum_a^m  \\delta^2_{h_{ia}}(t)\n\t\\\\\n\t\\Delta^2h_i &=\t\\varepsilon^2_i\n\t\\\\\n\t\\alpha^*_i&=\t\\frac{\\varepsilon_i}{\\sqrt{\\frac{1}{n} \\frac{1}{m}\\sum_t^n \\sum_a^m \\delta^2 h_{ia}(t)}}\n\\end{align*}\nif $ \\alpha_i $ is the value used in the session then\n\\begin{align}\n\t\\alpha^*_i&=\t\\frac{\\varepsilon_i}{\\sqrt{\\frac{1}{n} \\frac{1}{m} \\sum_t^n \\sum_a^m \\Delta^2 h_{ia}(t)}} \\alpha_i\n\\end{align}\n\nFor the Gaussian policy actors we calculate the average of squared parameter variations $ \\Delta^2\\mu_i$ and $ \\Delta^2 h_{i\\sigma} $\n\\begin{align*}\n\t\\mu^*_i(t) - \\mu_i(t)&=\t\\Delta \\mu_i(t)\n\t\\\\\n\t&=\t\\alpha_{i\\mu} \\delta_{i\\mu}(t)\n\t\\\\\n\t\\Delta^2\\mu_{i}&=\t\t\t\\frac{1}{n} \\sum_t^n \\Delta^2 \\mu_i(t)\n\t\\\\\n\t&=\t\\alpha^2_{i\\mu}\\frac{1}{n}\\sum_t^n  \\delta^2_{\\mu_{i}}(t)\n\t\\\\\n\t\\Delta^2\\mu_i &=\t\\varepsilon^2_{i\\mu}\n\t\\\\\n\t\\alpha^*_{i\\mu}&=\t\\frac{\\varepsilon_{i\\mu}}{\\sqrt{\\frac{1}{n} \\sum_t^n \\delta^2 \\mu_i(t)}}\n\\end{align*}\nif $ \\alpha_{i\\mu} $ is the value used in the session then\n\\begin{align}\n\t\\alpha^*_{i\\mu}&=\t\\frac{\\varepsilon_{i\\mu}}{\\sqrt{\\frac{1}{n} \\sum_t^n  \\Delta^2 \\mu_i(t)}} \\alpha_{i\\mu}\n\\end{align}\n\n\\begin{align*}\n\th^*_{i\\sigma}(t) - h_{i\\sigma}(t)&=\t\\Delta h_{i\\sigma}(t)\n\t\\\\\n\t&=\t\\alpha_{i\\sigma} \\delta_{ih_\\sigma}(t)\n\t\\\\\n\t\\Delta^2h_{i\\sigma}&=\t\t\t\\frac{1}{n} \\sum_t^n \\Delta^2 h_{i\\sigma}(t)\n\t\\\\\n\t&=\t\\alpha^2_{i\\sigma}\\frac{1}{n}\\sum_t^n  \\delta^2_{ih_\\sigma}(t)\n\t\\\\\n\t\\Delta^2h_{i\\sigma} &=\t\\varepsilon^2_{i\\sigma}\n\t\\\\\n\t\\alpha^*_{i\\sigma}&=\t\\frac{\\varepsilon_{i\\sigma}}{\\sqrt{\\frac{1}{n} \\sum_t^n \\delta^2 h_{i\\sigma}(t)}}\n\\end{align*}\nif $ \\alpha_{i\\sigma} $ is the value used in the session then\n\\begin{align}\n\t\\alpha^*_{i\\sigma}&=\t\\frac{\\varepsilon_{i\\sigma}}{\\sqrt{\\frac{1}{n} \\sum_t^n  \\Delta^2 h_{i\\sigma}(t)}} \\alpha_{i\\sigma}\n\\end{align}\n\n\\subsection{Performance}\n\nThe average reward is the main indicators of learning quality, since the agent interacts with the environment the average reward grows up.\n\nBecause the process is adaptive the average reward can vary a lot during the interaction with the environment therefore it is necessary to evaluate the trend of the indicator. The logarithmic regression can be used to evaluate the performance\n\\begin{align}\n\tr_\\pi(t) & = \\ln (mt + q)\n\\end{align}\n\nAn increasing trend indicates the agent is selecting better policies and is getting higher and higher rewards.\nA decreasing trend indicates the agent is not selecting good policies, this may be caused by low $ \\alpha_a $ or $ \\eta $ parameters.\n\nAnother indicator of performance is the squared TD error, as for the average reward it is necessary to evaluated the trend.\nThe error has not negative values that should approach zero when the agent select the local best policy. The exponential regression can be used to evaluate the performance\n\\begin{align}\n\t\\delta^2(t) & = e^{(mt + q)}\n\\end{align}\n\nA decreasing trend indicates the estimation of value states is getting better.\nAn increasing trend indicates the estimation of value states is getting worse it may be caused by the ANN which cannot correct the estimation due to $ \\eta $ parameter too high.\n\nBoth the critic and actors approximate the value function and policy function with neural network.\nTo monitor the learning activity of ANN we compute the MSE of estimated functions.\n\n\nThe ANN is feed with normalized values label $ O^*_i $ so that the values are in the range $ -1, +1 $ by linear transformation\n\n\\begin{align*}\n\tO_i &= (O_C, O_{Ai})\n\t\\\\\n\tO_C &= m_c \\delta_t + q_c\n\t\\\\\n\tO_{Ai} &= m_{ai} \\delta_{hi} + q_{ai}\n\\end{align*}\n\nThe MSE of ANN is\n\\begin{align*}\n\tJ(t)&\t= \\sum_i [O^*_i(t) - O_i(t)]^2\n\\end{align*}\nand the MSE after the training is\n\\begin{align*}\n\tJ'(t)&\t= \\sum_i [O^*_i(t) - O'_i(t)]^2\n\\end{align*}\n\nThe ratio between the total MSE after and before the training activity indicates the quality of such activity.\n\\begin{align}\n\\begin{split}\n\tK(t)&\t= \\frac{J'(t)}{J(t)}\n\\end{split}\n\\end{align}\n\nA ratio $ K(t) \\ge 1 $ means the error after training gets worst due a step-size parameter $ \\alpha $ too high.\nA ratio $ K(t) = 1 $  means no change on error and therefore no improvement. This can be affected by a local minimum reached or a step-size parameter too low with very poor capacity of learning.\nA ratio $ K(t) < 1 $ means an improvement of neural network due to correct step-size parameter.\nA ratio $ K(t) = 0 $ means a perfect fit of neural network.\n\nWe can classify the steps in three class:\n\\begin{description}\n\n\t\\item[$ C_0 $]\n\tThe steps that created a bad approximation with an increased of MSE ($ J > \\varepsilon \\cup K > 1$)\n\n\t\\item[$ C_1 $]\n\tThe steps that create a trivial approximation with a small reduction of MSE ($ J > \\varepsilon \\cup K_0 \\le K \\le 1 $ with $ K_0 = 0.9$ )\n\n\t\\item[$ C_2 $]\n\tThe remaining steps that have a small MSE or that have reduced significantly the MSE\n\\end{description}\n\nThe ideal distribution should have \n\n\\begin{align}\n\\begin{split}\n\tC_0 & = 0\n\t\\\\\n\tC_1 & = 0\n\t\\\\\n\tC_2 & = 1\n\\end{split}\n\\end{align}\n\nA step parameter $ \\eta $ too high generates over correction increasing $ C_0 $ and reducing $ C_2 $.\n\nAn $ \\eta $ parameter too small generates under corrections increasing $ C_1 $ and reducing $ C_2 $.\n\nBecause it is difficult to determine the effects of step parameter changes on the result MSE, an empirical way to reduce or increment the parameter is applied, for example increasing or reducing by exponential factors ($ \\dots $, $ \\times 0.01 $, $ \\times 0.03 $, $ \\times 0.1$, $\\times 0.3 $, $ \\times 3 $, $ \\times 10 $, $ \\times 30$, $\\times 100 $, $ \\dots $).\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{ann.png}\n\t\\caption{Step classification}\n\t\\label{fig:steps}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "d056dc4e855c0e28c8a1b1238f1ef44af26a9eec", "size": 17683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/ActorCritiAgent.tex", "max_stars_repo_name": "m-marini/scalarl", "max_stars_repo_head_hexsha": "8883a672da955ebac2f4b536c3879f04b58c6c74", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-20T16:54:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-20T16:54:32.000Z", "max_issues_repo_path": "docs/ActorCritiAgent.tex", "max_issues_repo_name": "m-marini/scalarl", "max_issues_repo_head_hexsha": "8883a672da955ebac2f4b536c3879f04b58c6c74", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 68, "max_issues_repo_issues_event_min_datetime": "2019-01-30T20:30:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-09T12:41:45.000Z", "max_forks_repo_path": "docs/ActorCritiAgent.tex", "max_forks_repo_name": "m-marini/scalarl", "max_forks_repo_head_hexsha": "8883a672da955ebac2f4b536c3879f04b58c6c74", "max_forks_repo_licenses": ["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.5592841163, "max_line_length": 377, "alphanum_fraction": 0.6682689589, "num_tokens": 6152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7025300636233415, "lm_q1q2_score": 0.6164538233376229}}
{"text": "%\\section{Surface flux}\n{\\bf \\Large \n\\begin{tabular}{ccc}\n\\hline\n  Corresponding author & : & Seiya Nishizawa\\\\\n\\hline\n\\end{tabular}\n}\n\n\n\\subsection{Monin-Obukhov similarity}\nFirst of all, we assume that in the boundary layer\n1. fluxes are constant, and 2. variables are horizontally uniform.\n\nRelations between flux and vertical gradient are:\n\\begin{align}\n  \\frac{kz}{u_*} \\frac{\\partial u}{\\partial z} &= \\phi_m\\left(\\frac{z}{L}\\right), \\label{eq: flux-gradient u} \\\\\n  \\frac{kz}{\\theta_*} \\frac{\\partial \\theta}{\\partial z} &= \\phi_h\\left(\\frac{z}{L}\\right), \\label{eq: flux-gradient t} \\\\\n  \\frac{kz}{q_*} \\frac{\\partial q}{\\partial z} &= \\phi_q\\left(\\frac{z}{L}\\right),\n\\end{align}\nwhere $k$ is the Von Karman constant.\n$L$ is the Monin-Obukhov scale height:\n\\begin{equation}\n  L = \\frac{\\theta u_*^2}{kg\\theta_*},\n\\end{equation}\nwhere $g$ is gravity.\nThe scaling velocity, $u_*$, temperature, $\\theta_*$,\nand water vapor, $q_*$, are defined from the vertical eddy fluxes of momentum, sensible heat, and water vapor:\n\\begin{align}\n  \\overline{u'w'} &= -u_*u_*, \\\\\n  \\overline{w'\\theta'} &= - u_*\\theta_*, \\\\\n  \\overline{w'q'} &= - u_*q_*.\n\\end{align}\n\nThe integration between roughness length $z_0$ to height $z$ of the lowest model level, eqs. (\\ref{eq: flux-gradient u}) and (\\ref{eq: flux-gradient t}) becomes:\n\\begin{align}\n  u(z) &= \\frac{u_*}{k} \\left\\{\\ln(z/z_0)-\\Phi_m(z/L)+\\Phi_m(z_0/L)\\right\\}, \\\\\n  \\Delta\\theta &= R\\frac{\\theta_*}{k} \\left\\{\\ln(z/z_0)-\\Phi_h(z/L)+\\Phi_h(z_0/L)\\right\\},\n\\end{align}\nwhere $\\Delta\\theta = \\theta-\\theta_0$,\nand\n\\begin{align}\n  \\Phi_m(z) = \\int^z \\frac{1-\\phi_m(z')}{z'} dz', \\\\\n  \\Phi_h(z) = \\int^z \\frac{R-\\phi_h(z')}{R z'} dz'.\n\\end{align}\n\n\n\\subsection{Louis’s (1979) Model}\nLouis (1979) introduced a parametric model of vertical eddy fluxes.\n\nThe $L$ becomes:\n\\begin{equation}\n  L = \\frac{\\theta u^2}{g\\Delta\\theta}\n    \\frac{\\ln(z/z_0)-\\Phi_h(z/L)+\\Phi_h(z_0/L)}{\\left\\{\\ln(z/z_0)-\\Phi_m(z/L)+\\Phi_m(z/L)\\right\\}^2}.\n\\end{equation}\nThe bulk Richardson number for the layer $Ri_B$ is:\n\\begin{equation}\n  Ri_B = \\frac{gz\\Delta\\theta}{\\theta u^2},\n\\end{equation}\nand its form implies a relationship with the Monin-Obukhov scale height $L$.\nThe fluxes can then be written as:\n\\begin{align}\n  u_*^2 &= a^2 u^2 F_m\\left(\\frac{z}{z_0},Ri_B\\right), \\label{eq: u_*^2} \\\\\n  u_*\\theta_* &= \\frac{a^2}{R} u \\Delta \\theta F_h\\left(\\frac{z}{z_0},Ri_B\\right), \\label{eq: u_*t_*}\n\\end{align}\nwhere\n$R$ is ratio of the drag coefficients for momentum and heat in the neutral limit(the turbulent Prandtl number),\nand\n\\begin{equation}\n  a^2 = \\frac{k^2}{\\left\\{\\ln\\left(z/z_0\\right)\\right\\}^2}\n\\end{equation}\nis the drag coefficient under neutral conditions.\n\nFor unstable conditions ($Ri_B<0$),\n$F_i$s ($i=m,h$) could be:\n\\begin{equation}\n  F_i = 1 - \\frac{b Ri_B}{1 + c_i \\sqrt{|Ri_B|}},\n  \\label{eq: F_i unstable}\n\\end{equation}\nunder the consideration that\n$F_i$ must behave as $1/u$ (i.e., $\\sqrt{|Ri_B|}$) in the free convection limit ($u \\to 0$) and becomes $1$ under neutral conditions ($Ri_B \\to 0$).\nOn the other hand, under stable conditions ($Ri_b$), Louis (1979) adopted the following form for $F_i$:\n\\begin{equation}\n  F_i = \\frac{1}{(1 + b' Ri_B)^2}.\n  \\label{eq: F_i stable}\n\\end{equation}\n\nThe constants are estimated as $R=0.74$ by Businger et al. (1971),\nand $b=2b'=9.4$ by Louis (1979).\nBy dimensional analysis:\n\\begin{equation}\n  c_i = C^*_i a^2 b \\sqrt{\\frac{z}{z_0}},\n\\end{equation}\nand $C^*_m = 7.4, C^*_h = 5.3$, which result best fits curves.\n\n\n\\subsection{Uno et al.’s (1995) Model}\nUno et al. (1995) extended the Louis Model,\nconsidering differences in roughness lengths related to momentum and temperature, i.e., $z_0$ and $z_t$, respectively.\n\nThe potential temperature difference between $z=z$ and $z=z_t$,\n$\\Delta\\theta_t$, is:\n\\begin{align}\n  \\Delta\\theta_t\n  &= R\\frac{\\theta_*}{k}\\left\\{\\ln(z_0/z_t) - \\Phi_h(z_0/L) + \\Phi_h(z_t/L)\\right\\} + \\Delta\\theta_0, \\nonumber \\\\\n  &= R\\frac{\\theta_*}{k}{\\ln(z_0/z_t)} + \\Delta\\theta_0, \\nonumber \\\\\n  &= \\Delta\\theta_0 \\left\\{\\frac{R\\ln(z_0/z_t)}{\\Psi_h} + 1\\right\\},\n\\end{align}\nwhere $\\Delta\\theta_0 = \\theta_z - \\theta_{z_0} (=\\Delta\\theta)$:\n\\begin{equation}\n  \\Psi_h = \\int_{z_0}^z\\frac{\\phi_h}{z'}dz', \\label{eq: Psi_h}\n\\end{equation}\nand $\\phi_h$ is assumed to be $R$ in the range $z_t < z < z_0$.\nThus:\n\\begin{equation}\n  \\Delta\\theta_0 = \\Delta\\theta_t \\left\\{\\frac{R\\ln(z_0/z_t)}{\\Psi_h}+1\\right\\}^{-1},\n  \\label{eq: Delta t_0}\n\\end{equation}\nor equivalently,\n\\begin{equation}\n  Ri_{B0} = Ri_{Bt} \\left\\{\\frac{R\\ln(z_0/z_t)}{\\Psi_h}+1\\right\\}^{-1}.\n  \\label{eq: Ri_B0}\n\\end{equation}\n\nFrom eqs. (\\ref{eq: u_*^2}) and (\\ref{eq: u_*t_*}):\n\\begin{equation}\n  \\Delta\\theta_0 = \\frac{R\\theta_*}{k}\\ln\\left(\\frac{z}{z_0}\\right)\\frac{\\sqrt{F_m}}{F_h},\n\\end{equation}\nwhile\n\\begin{equation}\n  \\Delta\\theta_0 = \\frac{\\theta_*}{k}\\Psi_h,\n\\end{equation}\nfrom eqs. (\\ref{eq: flux-gradient t}) and (\\ref{eq: Psi_h}).\nTherefore:\n\\begin{equation}\n  \\Psi_h = R\\ln\\left(\\frac{z}{z_0}\\right)\\frac{\\sqrt{F_m}}{F_h}.\n  \\label{eq: Psi}\n\\end{equation}\n\nBecause $\\Psi_h$ depends on $Ri_{B0}$,\n$Ri_{B0}$ cannot be calculated from $Ri_{Bt}$ with eq. (\\ref{eq: Ri_B0})\ndirectly, so numerical iteration is required to obtain $Ri_{B0}$\n\\footnote{In the stable case, it can be solved analytically\nwith eq. (\\ref{eq: F_i stable}), but the solution is too complicated.}.\nStarting from $Ri_{Bt}$ as the first estimation of $Ri_{B0}$,\nthe second estimate by the Newton-Raphson iteration becomes:\n\\begin{equation}\n  \\hat{Ri}_{B0} = Ri_{Bt} - \\frac{Ri_{Bt}R\\ln(z_0/z_t)}{\\ln(z_0/z_t) + \\hat{\\Psi}_h},\n  \\label{eq: Ri_B0 estimation}\n\\end{equation}\nwhere $\\hat{\\Psi}_h$ is the estimate of $\\Psi_h$ using $Ri_{Bt}$ instead of $Ri_{B0}$.\nApproximate values for $F_m, F_h$, and $\\Psi_h$ are re-calculated\nbased on the $\\hat{Ri}_{B0}$, and then $\\Delta\\theta_0$, and the surface fluxes $u_*^2$ and $u_*\\theta_*$ are calculated from eqs. (\\ref{eq: Delta t_0}), (\\ref{eq: u_*^2}), and (\\ref{eq: u_*t_*}), respectively.\n\n\n\n\n\\subsection{Discretization}\n\n\\def\\half{\\frac{1}{2}}\n\nAll the fluxes are calculated based on the velocity at the first full-level (k=1)\n($z=\\Delta z/2$).\nThe absolute velocities $U$ are:\n\\begin{align}\n  U_{i+\\half,j,1}^2 &=\n    \\left\\{\\frac{2(\\rho u)_{i+\\half,j,1}}{\\rho_{i,j,1}+\\rho_{i+1,j,1}}\\right\\}^2\n  + \\left\\{\\frac{(\\rho v)_{i,j-\\half,1} + (\\rho v)_{i,j+\\half,1} + (\\rho v)_{i+1,j-\\half,1} + (\\rho v)_{i+1,j+\\half,1}}{2(\\rho_{i,j,1}+\\rho_{i+1,j,1})}\\right\\}^2 \\nonumber \\\\\n &+ \\left\\{\\frac{(\\rho w)_{i,j,1+\\half} + (\\rho w)_{i+1,j,1+\\half}}{2(\\rho_{i,j,1}+\\rho_{i+1,j,1})}\\right\\}^2, \\\\\n  U_{i,j+\\half,1}^2 &=\n    \\left\\{\\frac{(\\rho u)_{i-\\half,j,1} + (\\rho u)_{i+\\half,j,1} + (\\rho u)_{i-\\half,j+1,1} + (\\rho u)_{i+\\half,j+1,1}}{2(\\rho_{i,j,1}+\\rho_{i,j+1,1})}\\right\\}^2 \\nonumber\\\\\n &+ \\left\\{\\frac{2(\\rho v)_{i,j+\\half,1}}{\\rho_{i,j,1}+\\rho_{i,j+1,1}}\\right\\}^2\n  + \\left\\{\\frac{(\\rho w)_{i,j,1+\\half} + (\\rho w)_{i,j+1,1+\\half}}{2(\\rho_{i,j,1}+\\rho_{i,j+1,1})}\\right\\}^2, \\\\\n  U_{i,j,1}^2 &=\n    \\left\\{\\frac{(\\rho u)_{i-\\half,j,1} + (\\rho u)_{i+\\half,j,1}}{2\\rho_{i,j,1}}\\right\\}^2\n  + \\left\\{\\frac{(\\rho v)_{i,j-\\half,1} + (\\rho v)_{i,j+\\half,1}}{2\\rho_{i,j,1}}\\right\\}^2\n  + \\left\\{\\frac{(\\rho w)_{i,j,1+\\half}}{2\\rho_{i,j,1}}\\right\\}^2,\n\\end{align}\nIt is here of note that $(\\rho w)_{i,j,\\half}=0$.\nThe potential temperatures $\\theta$ are:\n\\begin{align}\n  \\theta_{i,j,1} &= \\frac{(\\rho \\theta)_{i,j,1}}{\\rho_{i,j,1}}, \\\\\n  \\bar{\\theta}_{i+\\half,j,1} &= \\frac{\\theta_{i,j,1}+\\theta_{i+1,j,1}}{2}, \\\\\n  \\bar{\\theta}_{i,j+\\half,1} &= \\frac{\\theta_{i,j,1}+\\theta_{i,j+1,1}}{2}.\n\\end{align}\n\nThe roughness lengths, $z_0, z_t$, and $z_q$ are calculated from\neqs. (\\ref{eq: z_0}), (\\ref{eq: z_t}), and (\\ref{eq: z_q}),\nin which the friction velocity $u_*$ is estimated as:\n\\begin{equation}\n  u_* = \\sqrt{C_{m0}} U,\n\\end{equation}\nwhere $C_{m0}$ is a constant bulk coefficient,\nand we use $1.0 \\times 10^{-3}$ as its value.\n\nFrom eq. (\\ref{eq: Ri_B0}), the $Ri_{Bt}$, which is the first guess of the $Ri_{B0}$, is:\n\\begin{equation}\n  Ri_{Bt} = \\frac{gz_1(\\theta_1-\\theta_{sfc})}{\\bar{\\Theta}U^2},\n\\end{equation}\nwith the assumption that $\\theta_{z_t} = \\theta_{sfc}$.\nThe estimation of $\\hat{\\Psi}_h$ is calculated with $Ri_{Bt}$ from\neqs. (\\ref{eq: Psi}), (\\ref{eq: F_i unstable}), and (\\ref{eq: F_i stable}).\nThe final estimation of $Ri_{B0}$ is obtained from eq. (\\ref{eq: Ri_B0 estimation}),and the final estimation of $\\Psi_h$ is obtained with $Ri_{B0}$.\n\nNow we can calculate the bulk coefficients, $C_m, C_h$, and $C_e$ for moments, heat, and vapor:\n\\begin{align}\n  C_m &= \\frac{k^2}{\\ln(z_1/z_0)}F_m(Ri_{B0}), \\\\\n  C_h &= \\frac{k^2}{R\\ln(z_1/z_0)}F_h(Ri_{B0})\\left\\{\\frac{R\\ln(z_0/z_t)}{\\Psi_h}+1\\right\\}^{-1}, \\\\\n  C_e &= \\frac{k^2}{R\\ln(z_1/z_0)}F_h(Ri_{B0})\\left\\{\\frac{R\\ln(z_0/z_e)}{\\Psi_h}+1\\right\\}^{-1}.\n\\end{align}\nThe fluxes are:\n\\begin{align}\n  \\overline{\\rho u'w'} &= - C_m U \\rho u, \\\\\n  \\overline{\\rho v'w'} &= - C_m U \\rho v, \\\\\n  \\overline{\\rho w'w'} &= - C_m U \\rho w, \\\\\n  \\overline{\\rho \\theta'w'} &= - C_h U \\{\\rho \\theta - \\rho \\theta_{sfc}\\}, \\\\\n  \\overline{\\rho q'w'} &= -C_e U \\rho ( q - q_{evap} ),\n\\end{align}\nwhere $q_{evap}$ is the saturation value at the surface.\n\n\n", "meta": {"hexsha": "e59b0f8c3441efe5b81372056ccec5f6334b419d", "size": 9211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/descriptions/surface_flux.tex", "max_stars_repo_name": "slayoo/scale", "max_stars_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-06-14T11:12:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T05:29:55.000Z", "max_issues_repo_path": "doc/descriptions/surface_flux.tex", "max_issues_repo_name": "slayoo/scale", "max_issues_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-29T03:38:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-30T05:08:47.000Z", "max_forks_repo_path": "doc/descriptions/surface_flux.tex", "max_forks_repo_name": "slayoo/scale", "max_forks_repo_head_hexsha": "ca4b476ad55cb728b2009f0427ce3f7161ecfcf7", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-10T10:39:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-28T22:20:41.000Z", "avg_line_length": 41.490990991, "max_line_length": 210, "alphanum_fraction": 0.6348930626, "num_tokens": 3708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6164538169094659}}
{"text": "\\section{M/D/1 Queues}\n\\label{sec:M-D-1-queues}\n\nA $M/D/1$ is a queue where \n(i) the arrival process is Poissonian with rate $\\lambda$,\n(ii) the service process is deterministic,\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-D-1-queue}\t\n\t\\centering\n\t\\includegraphics{fig/M-D-1-Queue}\n\t\\caption{An M/D/1 queue and its corresponding CTMC.}\n\t\\end{figure}", "meta": {"hexsha": "d888c010e747a2c2b9e2eb8ceac2ac9f03aa6052", "size": 440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-d-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-d-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-d-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": 27.5, "max_line_length": 58, "alphanum_fraction": 0.7204545455, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.616387360766911}}
{"text": "\\input{../../../doc/latex/Styles/wpg_notation_define.tex}\n\\chapter{WPG v.04}\n\nThis version of the pattern generator is based on triple integrator with\npiece-wise constant \\acs{CoP} velocity. The control input is position of the\n\\acs{CoP}. Apart from that it is very similar to the \\acs{WPG} proposed in\n\\cite{Herdt2010auro}, for more information refer to \\cite{Sherikov2016phd}.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Variables}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Footstep positions}\nAny preview horizon contains $1$ fixed and $0$ or more variable footstep\npositions.  Let $M$ be the number of variable steps in the preview horizon,\n$\\FRAME{p_j}$ -- frame fixed to $j$-th footstep with $j = 0 \\dots M$ ($0$-th\nfootstep is fixed), $\\fp_j = (p^x_j, p^y_j)$ -- position of the $j$-th footstep\non the ground plane.\n\n\nCoordinate transformation matrix from the frame fixed to the $j$-th footstep to\nthe global frame is defined as\n%\n\\begin{equation}\n    \\M[p_j][]{R} =\n    \\begin{bmatrix}\n        \\cos{\\theta_j}  &   -\\sin{\\theta_j} \\\\\n        \\sin{\\theta_j}  &   \\cos{\\theta_j} \\\\\n    \\end{bmatrix}\n\\end{equation}\n%\nOrientations $\\theta_j$ of the footsteps are predetermined to avoid\nnolinearity. Position of the $j$-th footstep in the global frame can be found\nas\n%\n\\begin{equation}\n    \\fp_j = \\fp_0 + \\sum_{i=1}^{j}  \\M[p_{i-1}][]{R} \\fp[p_{i-1}]_j,\n\\end{equation}\n%\nwhich leads to\n%\n\\begin{equation}\n    \\begin{bmatrix}\n        \\fp_0\\\\\n        \\fp_1\\\\\n        \\vdots\\\\\n        \\fp_M\\\\\n    \\end{bmatrix}\n    =\n    \\V{1}_M\n    \\kron\n%    \\begin{bmatrix}\n%        \\M{I}\\\\\n%        \\M{I}\\\\\n%        \\vdots\\\\\n%        \\M{I}\\\\\n%    \\end{bmatrix}\n    \\fp_0\n    +\n    \\begin{bmatrix}\n        \\M{0}           & \\M{0}             & \\dots & \\M{0}             \\\\\n        \\M[p_{0}][]{R}  & \\M{0}             & \\dots & \\M{0}             \\\\\n        \\vdots          & \\vdots            & \\dots & \\vdots            \\\\\n        \\M[p_{0}][]{R}  & \\M[p_{1}][]{R}    & \\dots & \\M[p_{M-1}][]{R}  \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\fp[p_0]_1\\\\\n        \\vdots\\\\\n        \\fp[p_{M-1}]_M\\\\\n    \\end{bmatrix}.\n\\end{equation}\n%\nIt is preferable to express variable footstep positions in a frame fixed to the\npreceding footstep in order to impose simple bounds on variable footstep\npositions.\n\n\nThe number of sampling intervals in the preview horizon is denoted by $N \\ge\nM$. The footstep position corresponding to $k$-th ($k = 1,\\dots,N$) sampling\ninterval is denoted as $\\fph_k = (\\hat{p}^x_k, \\hat{p}^y_k)$. These positions\ncan be found using a selection matrices as\n%\n\\begin{equation}\n\\begin{split}\n    \\underbrace{\n    \\begin{bmatrix}\n        \\fph_1 \\\\\n        \\vdots \\\\\n        \\fph_N\n    \\end{bmatrix}\n    }_{\\FPh}\n    & =\n    \\underbrace{\n    \\begin{bmatrix}\n        \\M{I}   &  \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &  \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{0}   &  \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{0}   &  \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{0}   &  \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\vdots  &  \\vdots  &   \\ddots  &   \\vdots \\\\\n        \\M{0}   &  \\M{0}   &   \\dots   &   \\M{I} \\\\\n    \\end{bmatrix}\n    }_{\\M{I}_{\\mathit{fps}}}\n    \\begin{bmatrix}\n        \\fp_0 \\\\\n        \\fp_1 \\\\\n        \\vdots\\\\\n        \\fp_M \\\\\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        \\M{I}   \\\\\n        \\M{I}   \\\\\n        \\M{0}   \\\\\n        \\M{0}   \\\\\n        \\M{0}   \\\\\n        \\vdots  \\\\\n        \\M{0}   \\\\\n    \\end{bmatrix}\n    \\fp_0\n    +\n    \\begin{bmatrix}\n        \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\vdots  &   \\ddots  &   \\vdots \\\\\n        \\M{0}   &   \\dots   &   \\M{I} \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\fp_1 \\\\\n        \\vdots\\\\\n        \\fp_M\\\\\n    \\end{bmatrix}\\\\\n    & =\n%    \\underbrace{\n%    \\begin{bmatrix}\n%        \\M{I}   \\\\\n%        \\M{I}   \\\\\n%        \\M{I}   \\\\\n%        \\M{I}   \\\\\n%        \\M{I}   \\\\\n%        \\vdots  \\\\\n%        \\M{I}   \\\\\n%    \\end{bmatrix}\n%    }_{\\M{V}_0}\n    \\underbrace{\n        \\V{1}_N\n        \\kron\n        \\fp_0\n    }_{\\V{V}_0}\n    +\n    \\underbrace{\n    \\begin{bmatrix}\n        \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{0}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\M{I}   &   \\dots   &   \\M{0} \\\\\n        \\vdots  &   \\ddots  &   \\vdots \\\\\n        \\M{0}   &   \\dots   &   \\M{I} \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\M[p_{0}][]{R}  & \\M{0}             & \\dots & \\M{0}             \\\\\n        \\vdots          & \\vdots            & \\dots & \\vdots            \\\\\n        \\M[p_{0}][]{R}  & \\M[p_{1}][]{R}    & \\dots & \\M[p_{M-1}][]{R}  \\\\\n    \\end{bmatrix}\n    }_{\\M{V}}\n    \\underbrace{\n    \\begin{bmatrix}\n        \\fp[p_0]_1\\\\\n        \\vdots\\\\\n        \\fp[p_{M-1}]_M\\\\\n    \\end{bmatrix}\n    }_{\\FP},\n\\end{split}\n\\end{equation}\n%\nwhere $\\M{V}$ has the following structure\n%\n\\begin{equation}\n    \\M{V}\n    =\n    \\begin{bmatrix}\n        \\M{0}           &   \\dots   &   \\M{0} \\\\\n        \\M{0}           &   \\dots   &   \\M{0} \\\\\n        \\M[p_{0}][]{R}  &   \\dots   &   \\M{0} \\\\\n        \\M[p_{0}][]{R}  &   \\dots   &   \\M{0} \\\\\n        \\M[p_{0}][]{R}  &   \\dots   &   \\M{0} \\\\\n        \\vdots          &   \\ddots  &   \\vdots \\\\\n        \\M[p_{0}][]{R}  &   \\dots   &   \\M[p_{M-1}][]{R} \\\\\n    \\end{bmatrix}\n    =\n    \\underbrace{\n        \\begin{bmatrix}\n            \\M{0}   &   \\dots   &   \\M{0} \\\\\n            \\M{0}   &   \\dots   &   \\M{0} \\\\\n            \\M{I}   &   \\dots   &   \\M{0} \\\\\n            \\M{I}   &   \\dots   &   \\M{0} \\\\\n            \\M{I}   &   \\dots   &   \\M{0} \\\\\n            \\vdots  &   \\ddots  &   \\vdots \\\\\n            \\M{I}   &   \\dots   &   \\M{I} \\\\\n        \\end{bmatrix}\n    }_{\\M{I}_R \\kron \\M{I}}\n    \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n    \\M{I}_R\n    =\n    \\begin{bmatrix}\n        0   &   \\dots   &   0 \\\\\n        0   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        \\vdots  &   \\ddots  &   \\vdots \\\\\n        1   &   \\dots   &   1 \\\\\n    \\end{bmatrix}.\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Positions of the CoP}\nPosition of the center of pressure in the end of $k$-th ($k = 1,\\dots,N$)\nsampling interval is denoted as $\\cop_k = (z^x_k, z^y_k)$. The current\n\\acs{CoP} position is $\\cop_0$. In order to obtain simple bounds on the\n\\acs{CoP} positions instead of general constraints, their positions are\nexpressed in the local frames fixed to the respective feet, \\emph{i.e.}\n%\n\\begin{equation}\n    \\cop_k = \\fph_k + \\M[\\hat{p}_k][]{R} \\cop[\\hat{p}_k]_k.\n\\end{equation}\n%\nOrientation matrices $\\M[\\hat{p}_k][]{R}$ can also be selected with\n$\\M{I}_{\\mathit{fps}}$\n%\n\\begin{equation}\n    \\begin{bmatrix}\n        \\M[\\hat{p}_1][]{R}\\\\\n        \\vdots\\\\\n        \\M[\\hat{p}_N][]{R}\\\\\n    \\end{bmatrix}\n    =\n    \\M{I}_{\\mathit{fps}}\n    \\begin{bmatrix}\n        \\M[p_0][]{R}\\\\\n        \\vdots\\\\\n        \\M[p_M][]{R}\\\\\n    \\end{bmatrix}\n\\end{equation}\n%\nAll positions of the \\acs{CoP} within the preview horizon are\n%\n\\begin{equation}\n    \\begin{split}\n        \\begin{bmatrix}\n            \\cop_1 \\\\\n            \\vdots \\\\\n            \\cop_N \\\\\n        \\end{bmatrix}\n        & =\n        \\FPh\n        +\n        \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        \\underbrace{\n        \\begin{bmatrix}\n            \\cop[\\hat{p}_1]_1 \\\\\n            \\vdots \\\\\n            \\cop[\\hat{p}_N]_N \\\\\n        \\end{bmatrix}\n        }_{\\V{Z}}\n        =\n        \\M{V}_0\n        +\n        \\M{V} \\FP\n        +\n        \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        \\CoP\\\\\n        & =\n        \\V{1}_N\n        \\kron\n        \\fp_0\n        +\n        \\left(\n            \\M{I}_R \\kron \\M{I}\n        \\right)\n        \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\n        \\FP\n        +\n        \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        \\CoP\n    \\end{split}\n\\end{equation}\n%\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Model of the system}\n\nThe model has the following form\n%\n\\begin{align}\n    \\cstate_{k+1} =& \\M{A} \\cstate_k + \\M{B} \\cop_{k+1}\\\\\n    \\dcop_k =& \\M{D} \\cstate_k + \\M{E} \\cop_{k+1}.\n\\end{align}\n%\n\nAfter condensing we obtain\n%\n\\begin{align}\n    \\begin{bmatrix}\n        \\cstate_1 \\\\\n        \\vdots\\\\\n        \\cstate_{N}\\\\\n    \\end{bmatrix}\n    =&\n    \\M{U}_x \\cstate_0\n    +\n    \\M{U}_u\n    \\begin{bmatrix}\n        \\cop_1 \\\\\n        \\vdots \\\\\n        \\cop_N \\\\\n    \\end{bmatrix} \\\\\n%\n    \\underbrace{\n    \\begin{bmatrix}\n        \\dcop_0 \\\\\n        \\vdots\\\\\n        \\dcop_{N-1}\\\\\n    \\end{bmatrix}\n    }_{\\dCoP}\n    =&\n    \\M{O}_x \\cstate_0\n    +\n    \\M{O}_u\n    \\begin{bmatrix}\n        \\cop_1 \\\\\n        \\vdots \\\\\n        \\cop_N \\\\\n    \\end{bmatrix} \\\\\n\\end{align}\n%\nor\n%\n\\begin{align}\n    \\cState\n    =&\n    \\M{U}_x \\cstate_0\n    +\n    \\M{U}_u\n    \\left(\n        \\M{V}_0\n        +\n        \\M{V} \\FP\n        +\n        \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        \\CoP\n    \\right)\\\\\n%\n    \\dCoP\n    =&\n    \\M{O}_x \\cstate_0\n    +\n    \\M{O}_u\n    \\left(\n        \\M{V}_0\n        +\n        \\M{V} \\FP\n        +\n        \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        \\CoP\n    \\right)\\\\\n\\end{align}\n%\n\nThe unknowns $\\CoP$ and $\\FP$ can be grouped together\n%\n\\begin{align}\n    \\cState\n    =&\n    \\underbrace{\n    \\begin{bmatrix}\n        \\M{U}_u \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}   &   \\M{U}_u \\M{V} \\\\\n    \\end{bmatrix}\n    }_{\\M{S}}\n    \\underbrace{\n    \\begin{bmatrix}\n        \\CoP\\\\\n        \\FP\\\\\n    \\end{bmatrix}\n    }_{\\V{X}}\n    +\n    \\underbrace{\n    \\M{U}_x \\cstate_0\n    +\n    \\M{U}_u \\M{V}_0\n    }_{\\V{s}}\\\\\n%\n    \\dCoP\n    =&\n    \\underbrace{\n    \\begin{bmatrix}\n        \\M{O}_u \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}   &   \\M{O}_u \\M{V} \\\\\n    \\end{bmatrix}\n    }_{\\M{S}_{\\dot{z}}}\n    \\underbrace{\n    \\begin{bmatrix}\n        \\CoP\\\\\n        \\FP\\\\\n    \\end{bmatrix}\n    }_{\\V{X}}\n    +\n    \\underbrace{\n    \\M{O}_x \\cstate_0\n    +\n    \\M{O}_u \\M{V}_0\n    }_{\\V{s}_{\\dot{z}}}\\\\\n\\end{align}\n%\nor\n%\n\\begin{align}\n    \\cState\n    =&\n    \\begin{bmatrix}\n        \\left(\\M{I} \\bkron \\M{U}_u^x \\right) \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        &\n        \\left(\\M{I} \\bkron \\M{U}_u^x \\right)\n        \\left(\n            \\M{I}_R \\kron \\M{I}\n        \\right)\n        \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\\\\\n    \\end{bmatrix}\n    \\V{X}\n    \\\\\n    &\n    +\n    \\left(\\M{I} \\bkron \\M{U}_x^x \\right)\n    \\cstate_0\n    +\n    \\left(\\M{I} \\bkron \\M{U}_u^x \\right)\n    \\left(\\V{1}_N \\kron \\fp_0 \\right)\n    \\\\\n    =&\n    \\begin{bmatrix}\n        \\left(\\M{I} \\bkron \\M{U}_u^x \\right) \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        &\n        \\left(\n            \\M{I}\n            \\bkron\n            \\left(\n                \\M{U}_u^x\n                \\M{I}_R\n            \\right)\n        \\right)\n        \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\\\\\n    \\end{bmatrix}\n    \\V{X}\n    \\\\\n    &\n    +\n    \\left(\\M{I} \\bkron \\M{U}_x^x \\right)\n    \\cstate_0\n    +\n    \\left(\n        \\M{I}\n        \\bkron\n        \\left(\n            \\M{U}_u^x\n            \\V{1}_N\n        \\right)\n    \\right)\n    \\fp_0\n    \\\\\n\\end{align}\n%\nand\n%\n\\begin{align}\n    \\dCoP\n    =&\n    \\begin{bmatrix}\n        \\left(\\M{I} \\bkron \\M{O}_u^x \\right) \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        &\n        \\left(\\M{I} \\bkron \\M{O}_u^x \\right)\n        \\left(\n            \\M{I}_R \\kron \\M{I}\n        \\right)\n        \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\\\\\n    \\end{bmatrix}\n    \\V{X}\n    \\\\\n    &\n    +\n    \\left(\\M{I} \\bkron \\M{U}_x^x \\right) \\cstate_0\n    +\n    \\left(\\M{I} \\bkron \\M{O}_u^x \\right)\n    \\left(\\V{1}_N \\kron \\fp_0 \\right)\n    \\\\\n    = &\n    \\begin{bmatrix}\n        \\left(\\M{I} \\bkron \\M{O}_u^x \\right) \\diag{k = 1 \\dots N}{\\M[\\hat{p}_k][]{R}}\n        &\n        \\left(\n            \\M{I}\n            \\bkron\n            \\left(\n                \\M{O}_u^x\n                \\M{I}_R\n            \\right)\n        \\right)\n        \\diag{k = 0...M-1}{ \\M[p_{k}][]{R} }\\\\\n    \\end{bmatrix}\n    \\V{X}\n    \\\\\n    &\n    +\n    \\left(\\M{I} \\bkron \\M{U}_x^x \\right) \\cstate_0\n    +\n    \\left(\n        \\M{I}\n        \\bkron\n        \\left(\n            \\M{O}_u^x\n            \\V{1}_N\n        \\right)\n    \\right)\n    \\fp_0\n    \\\\\n\\end{align}\n%\n\nVelocity of the \\acs{CoM} can be expressed as\n%\n\\begin{equation}\n    \\cVel =\n        \\diag{N}{\\M{I}_{v}} \\cState =\n        \\diag{N}{\\M{I}_{v}} \\left( \\M{S}\\V{X} + \\V{s} \\right)=\n        \\M{S}_v \\V{X} + \\V{s}_v\n\\end{equation}\n%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Constraints}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{CoP positions}\nSimple bounds in the case when supports are rectangular.\n\n\\begin{equation}\n    \\ubarV{z}_k \\le \\cop[\\hat{p}_k]_k \\le \\barV{z}_k, \\quad k = 1 \\dots N\\\\\n\\end{equation}\n\n\\begin{equation}\n    \\ubarV{Z} \\le \\CoP \\le \\barV{Z}\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Foot positions}\nSimple bounds when feasible regions are rectangular.\n\n\\begin{equation}\n    \\ubarV{p}_j \\le \\fp[p_{j-1}]_j \\le \\barV{p}_j, \\quad j = 1 \\dots M\n\\end{equation}\n\n\\begin{equation}\n    \\ubarV{P} \\le \\FP \\le \\barV{P}\n\\end{equation}\n\nOnly initial and final double supports are handled, the respective constraints\ncan also be represented as simple bounds provided that the feet are aligned.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Objectives}\nThree objectives are minimized: difference between the actual and reference\n\\acs{CoM} velocity\n%\n\\begin{equation}\n    \\NORME{\\cVel - \\cVel_{ref}} = \\NORME{\\M{S}_v \\V{X} + \\V{s}_v - \\cVel_{ref}},\n\\end{equation}\n%\nthe \\acs{CoP} velocity\n%\n\\begin{equation}\n    \\NORME{\\dCoP} = \\NORME{\\M{S}_{\\dot{z}} \\V{X} + \\V{s}_{\\dot{z}}},\n\\end{equation}\n%\ndistance between the \\acs{CoP} positions and the centers of the feet\n%\n\\begin{equation}\n    \\NORME{\\CoP}.\n\\end{equation}\n%\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{QP}\n\\begin{equation}\n\\begin{split}\n    \\MINIMIZE{\\CoP, \\FP}  & \\frac{\\alpha}{2} \\NORM{\\cVel - \\cVel_{ref}}^2 +\n                              \\frac{\\beta}{2}  \\NORM{\\dCoP}^2 +\n                              \\frac{\\gamma}{2} \\NORM{\\CoP}^2\\\\\n    \\SUBJECTTO          & \\ubarV{Z} \\le \\CoP \\le \\barV{Z} \\\\\n                        & \\ubarV{P} \\le \\FP \\le \\barV{P}\n\\end{split}\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Reference velocity}\n\\begin{equation}\n\\begin{split}\n    &\\NORM{\\cVel - \\cVel_{ref}}^2\n    =\n    \\NORM{\\M{S}_v \\V{X} + \\V{s}_v   -  \\cVel_{ref}}^ 2\n    = \\\\\n    &\n    \\V{X}^T \\M{S}_v^T \\M{S}_v \\V{X}\n    +\n    \\V{X}^T \\M{S}_v^T \\V{s}_v\n    -\n    \\V{X}^T \\M{S}_v^T \\cVel_{ref}\\\\\n    &\n    +\n    \\V{s}_v^T \\M{S}_v \\V{X}\n    +\n    \\cancel{\\V{s}_v^T \\V{s}_v}\n    -\n    \\cancel{\\V{s}_v^T \\cVel_{ref}} \\\\\n    &\n    -\n    \\cVel_{ref}^T \\M{S}_v \\V{X}\n    -\n    \\cancel{\\cVel_{ref}^T \\V{s}_v}\n    +\n    \\cancel{\\cVel_{ref}^T \\cVel_{ref}}\n\\end{split}\n\\end{equation}\n\nOmitting the  constant terms we obtain\n\\begin{equation}\n    \\frac{\\alpha}{2} \\V{X}^T \\M{S}_v^T \\M{S}_v \\V{X}\n    -\n    \\alpha \\cVel_{ref}^T \\M{S}_v \\V{X}\n    +\n    \\alpha \\V{s}^T_v \\M{S}_v \\V{X}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{CoP velocity}\n\\begin{equation}\n    \\NORM{\\dCoP}^2 =\n    \\NORM{\\M{S}_{\\dot{z}} \\V{X} + \\V{s}_{\\dot{z}}}^2 =\n        \\V{X}^T \\M{S}_{\\dot{z}}^T \\M{S}_{\\dot{z}} \\V{X}\n        +\n        \\V{X}^T \\M{S}_{\\dot{z}}^T \\V{s}_{\\dot{z}}\n        +\n        \\V{s}_{\\dot{z}}^T \\M{S}_{\\dot{z}} \\V{X}\n        +\n        \\cancel{\\V{s}_{\\dot{z}}^T \\V{s}_{\\dot{z}}}\n\\end{equation}\n\nOmitting the constant terms we obtain\n\\begin{equation}\n    \\frac{\\beta}{2}\n    \\V{X}^T \\M{S}_{\\dot{z}}^T \\M{S}_{\\dot{z}} \\V{X}\n    +\n    \\beta\n    \\V{s}_{\\dot{z}}^T \\M{S}_{\\dot{z}} \\V{X}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Displacement from the reference CoP}\n\\begin{equation}\n    \\frac{\\gamma}{2} \\NORM{\\CoP}^2\n        = \\frac{\\gamma}{2} \\CoP^T \\CoP\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Objective in the matrix form}\n\\begin{equation}\n\\begin{split}\n    \\MINIMIZE{\\V{X}}    & \\frac{1}{2} \\V{X}^T\\M{H}\\V{X} + \\V{h}^T \\V{X}\n\\end{split}\n\\end{equation}\n\n\\begin{equation}\n    \\M{H} =\n        \\alpha \\M{S}_v^T \\M{S}_v\n        +\n        \\beta  \\M{S}_{\\dot{z}}^T \\M{S}_{\\dot{z}}\n        +\n        \\gamma\n            \\begin{bmatrix}\n                \\M{0} & \\M{0} & \\M{0}\\\\\n                \\M{0} & \\M{I} & \\M{0}\\\\\n                \\M{0} & \\M{0} & \\M{0}\\\\\n            \\end{bmatrix}\\\\\n\\end{equation}\n\n\\begin{equation}\n    \\V{h} =\n        -\n        \\alpha \\cVel_{ref}^T \\M{S}_v\n        +\n        \\alpha \\V{s}_v^T \\M{S}_v\n        +\n        \\beta  \\V{s}_{\\dot{z}}^T \\M{S}_{\\dot{z}}\n\\end{equation}\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Hierarchical least squares problem}\n\\begin{description}\n    \\item[Level 1:]\n        \\begin{equation}\n        \\begin{split}\n            & \\ubarV{Z} \\le \\CoP \\le \\barV{Z} \\\\\n            & \\ubarV{P} \\le \\FP \\le \\barV{P}\n        \\end{split}\n        \\end{equation}\n\n    \\item[Level 2:]\n        \\begin{equation}\n        \\begin{split}\n            & \\sqrt{\\frac{\\alpha}{2}} \\M{S}_v \\V{X} = \\sqrt{\\frac{\\alpha}{2}} \\left(\\cVel_{ref} - \\V{s}_v\\right) \\\\\n            & \\sqrt{\\frac{\\beta}{2}} \\M{S}_{\\dot{z}} \\V{X} = \\sqrt{\\frac{\\beta}{2}} \\V{s}_{\\dot{z}}\\\\\n            & \\sqrt{\\frac{\\gamma}{2}} \\CoP = 0\\\\\n        \\end{split}\n        \\end{equation}\n\\end{description}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Swing foot trajectory}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Polynomial and boundary conditions}\nTrajectory is generated using cubic polynomial of the form\n\\begin{equation}\n    at^3 + bt^2 + ct + d = y_{swing},\n\\end{equation}\nwhere $t$ is time instance; $a,b,c,d$ are coefficients; and $y_{swing}$ is position of the swing\nfoot at time $t$.\n\nDerivatives of the cubic polynomial are\n\\begin{equation}\n\\begin{split}\n    & 3at^2 + 2bt + c = \\dot{y}_{swing},\\\\\n    & 6at + 2b = \\ddot{y}_{swing},\\\\\n    & 6a = \\dddot{y}_{swing}.\\\\\n\\end{split}\n\\end{equation}\n\nThere are four boundary conditions for the polynomial, the first two are defined for\nthe current swing foot state at $t_i = 0$:\n\\begin{equation}\\label{wpg04.eq.swtraj_bc1}\n\\begin{split}\n    & d = y_{swing,i}, \\\\\n    & c = \\dot{y}_{swing,i}, \\\\\n\\end{split}\n\\end{equation}\nwhere $y_{swing,i}$ and $\\dot{y}_{swing,i}$ are initial position and velocity; the other two\nconditions for landing time instance $t_f$ are:\n\\begin{equation}\\label{wpg04.eq.swtraj_bc2}\n\\begin{split}\n    & at_f^3 + bt_f^2 + ct_f + d = y_{swing,f},\\\\\n    & 3at^2 + 2bt + c = \\dot{y}_{swing,f},\\\\\n\\end{split}\n\\end{equation}\nwhere $y_{swing,f}$ and $\\dot{y}_{swing,f}$ are final position and velocity.\nTrajectories along $z$ axis and $x,y$ axes are computed separately. Final position\n$y_{swing,f}^z$ for trajectory along $z$ axis is set to the step height during the first\nhalf of the support and to $0$ during the second half:\n\\begin{equation}\n    y_{swing,f}^z =\n    \\left\\{\n        \\begin{array}{ll}\n            h_{step}    & t \\le \\frac{1}{2}T_{support}; \\\\\n            0           & t > \\frac{1}{2}T_{support}. \\\\\n        \\end{array}\n    \\right.\n\\end{equation}\nThe final $x,y$ positions are set to the next landing position computed as\n\\begin{equation}\n    \\begin{bmatrix}\n        y_{swing,f}^x\\\\\n        y_{swing,f}^y\\\\\n    \\end{bmatrix}\n    =\n    \\M{V}_{land}\\FP,\n\\end{equation}\nwhere\n\\begin{equation}\n    \\M{V}_{land} =\n    \\begin{bmatrix}\n        \\M[p_0][]{R} & \\M{0}\n    \\end{bmatrix}.\n\\end{equation}\nVelocity at the end of trajectory is set to zero.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Computation of the desired acceleration}\n\nWhole body control requires current acceleration (at time $t_i$) of the swing foot,\nwhich can be found as\n\\begin{equation}\\label{wpg04.eq.swtraj_acc1}\n    2b = \\ddot{y}_{swing,i}.\n\\end{equation}\nHence it is necessary to find coefficient $b$ from equations~\\eqref{wpg04.eq.swtraj_bc1}\nand~\\eqref{wpg04.eq.swtraj_bc2}.\n\nSubstitution of~\\eqref{wpg04.eq.swtraj_bc1} to~\\eqref{wpg04.eq.swtraj_bc2} using $\\dot{y}_{swing,f} = 0$\nyields\n\\begin{equation}\\label{wpg04.eq.swtraj_bc3}\n\\begin{split}\n    & at_f^3 + bt_f^2 + \\dot{y}_{swing,i}t_f + y_{swing,i} = y_{swing,f},\\\\\n    & 3at_f^2 + 2bt_f + \\dot{y}_{swing,i} = 0.\\\\\n\\end{split}\n\\end{equation}\n\nTrivial algebraic operations on~\\eqref{wpg04.eq.swtraj_bc3} and~\\eqref{wpg04.eq.swtraj_acc1}\nlead to the following equation:\n\\begin{equation}\\label{wpg04.eq.swtraj_acc2}\n    \\ddot{y}_{swing,i}\n    =\n    \\frac{6(y_{swing,f} - y_{swing,i})}{t_f^2} - \\frac{4\\dot{y}_{swing,i}}{t_f}\n    =\n    \\frac{6}{t_f^2}y_{swing,f} -\n    \\underbrace{\n        \\frac{6}{t_f^2}y_{swing,i} - \\frac{4}{t_f} \\dot{y}_{swing,i}\n    }_{\\mbox{constant}}.\n\\end{equation}\n\nConsequently\n\\begin{equation}\n    \\V{\\ddot{y}}_{swing}\n    =\n    \\begin{bmatrix}\n        \\ddot{y}_{swing,i}^x\\\\\n        \\ddot{y}_{swing,i}^y\\\\\n        \\ddot{y}_{swing,i}^z\\\\\n    \\end{bmatrix}\n    =\n    \\underbrace{\n        \\frac{6}{t_f^2}\n        \\begin{bmatrix}\n            \\M{V}_{land} \\\\\n            \\M{0}\n        \\end{bmatrix}\n    }_{\\M{V}_{sa}}\n    \\FP\n    +\n    \\underbrace{\n        \\frac{6}{t_f^2}\n        \\begin{bmatrix}\n            \\M{0} \\\\\n            y_{swing,f}^z\n        \\end{bmatrix}\n        -\n        \\frac{6}{t_f^2}\n        \\V{y}_{swing,i}\n        -\n        \\frac{4}{t_f}\n        \\V{\\dot{y}}_{swing,i}\n    }_{\\V{b}_{sa}},\n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Computation of the initial jerk}\nJerk at the beginning of the swing foot trajectory characterizes behaviour of the\npolynomial near this point. High values of the jerk indicate rapid change of\nacceleration, which in turn increases error in trajectory tracking using piece-wise\nconstant acceleration. Due to this reason we penalize the jerk at the starting point\nof trajectory. Obviously, only $x,y$ components are penalized, since $z$ component\nis directly computed.\n\nThe jerk can be computed as:\n\\begin{equation}\\label{wpg04.eq.swtraj_jerk}\n    \\dddot{y}_{swing,i}\n    =\n    - \\frac{12(y_{swing,f} - y_{swing,i})}{t_f^3} + \\frac{6\\dot{y}_{swing,i}}{t_f^2}\n    =\n    - \\frac{12}{t_f^3}y_{swing,f}\n    +\n    \\underbrace{\n        \\frac{12}{t_f^3}y_{swing,i} + \\frac{6}{t_f} \\dot{y}_{swing,i}\n    }_{\\mbox{constant}}.\n\\end{equation}\n\nTherefore $x,y$ components of the jerk are expressed as\n\\begin{equation}\n    \\V{\\dddot{y}}_{swing}^{x,y}\n    =\n    \\begin{bmatrix}\n        \\dddot{y}_{swing,i}^x\\\\\n        \\dddot{y}_{swing,i}^y\\\\\n    \\end{bmatrix}\n    =\n    \\underbrace{\n        -\n        \\frac{12}{t_f^3}\n        \\M{V}_{land}\n    }_{\\M{V}_{sj}}\n    \\FP\n    +\n    \\underbrace{\n        \\frac{12}{t_f^3}\n        \\V{y}_{swing,i}\n        +\n        \\frac{6}{t_f^2}\n        \\V{\\dot{y}}_{swing,i}\n    }_{\\V{b}_{sj}}\n    =\n    \\underbrace{\n        \\begin{bmatrix}\n            \\M{0}   &   \\M{0}   &   \\M{V}_{sj}\n        \\end{bmatrix}\n    }_{\\M{A}_{sj}}\n    \\V{X}_{mpc}\n    +\n    \\V{b}_{sj}\n    .\n\\end{equation}\n\\input{../../../doc/latex/Styles/wpg_notation_undefine.tex}\n", "meta": {"hexsha": "f6026b5c8bee1155c28b1775e91d57d11d05e81d", "size": 23596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "extra_modules/wpg04/doc/wpg04.tex", "max_stars_repo_name": "bip-team/humoto-module-vertical-CoM", "max_stars_repo_head_hexsha": "665d7c192eaed69135e7b25f1b56bd531317f4bb", "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": "extra_modules/wpg04/doc/wpg04.tex", "max_issues_repo_name": "bip-team/humoto-module-vertical-CoM", "max_issues_repo_head_hexsha": "665d7c192eaed69135e7b25f1b56bd531317f4bb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-11-06T21:22:03.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T22:17:26.000Z", "max_forks_repo_path": "extra_modules/wpg04/doc/wpg04.tex", "max_forks_repo_name": "bip-team/humoto-modules-comanoid", "max_forks_repo_head_hexsha": "665d7c192eaed69135e7b25f1b56bd531317f4bb", "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.1288604899, "max_line_length": 115, "alphanum_fraction": 0.4574080353, "num_tokens": 8800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6163873556537312}}
{"text": "\\documentclass[a4paper,12pt]{article}\n\\usepackage{amsmath}\n\\begin{document}\n\n% From http://www.eecs.tufts.edu/~khan/Courses/Spring2013/EE194/Lecs/Lec9and10.pdf\n% and http://www.cs.unc.edu/~wens/WAFR2014-Sun.pdf\n%   (which references http://maeresearch.ucsd.edu/skelton/publications/weiwei_ilqg_CDC43.pdf)\n% and http://arl.cs.utah.edu/pubs/ISRR2013.pdf\n\n\\section{Backwards Pass}\n\nLet's start with some definitions for the standard LQR controller.\n$c_t(\\boldsymbol{x}, \\boldsymbol{u})$ is the cost for the iteration $t$ given that we are at $\\boldsymbol{x}$ and are going to apply $\\boldsymbol{u}$ for one cycle.\n$v_t(\\boldsymbol{x})$ is the optimal cost-to-go for the starting point $\\boldsymbol{x}$ at step $t$.\n$v_N(\\boldsymbol{x})$ may be defined to be a different final cost from $v_t(\\boldsymbol{x})$ if need be, where $N$ is the horizon.\n\n$$\\begin{array}{rcl}\nc_t(\\boldsymbol{x}, \\boldsymbol{u}) &=&\n  \\frac{1}{2}\n    \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} Q_t & P_t^T \\\\ P_t & R_t \\end{bmatrix}\n    \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix} +\n  \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} \\boldsymbol{q}_t \\\\ \\boldsymbol{r}_t \\end{bmatrix} +\n  q_t \\\\\nv_{t + 1}(\\boldsymbol{x}) &=&\n  \\frac{1}{2} \\boldsymbol{x}^T S_{t + 1} \\boldsymbol{x} + \\boldsymbol{x}^T \\boldsymbol{s}_{t + 1} + s_{t + 1} \\\\\n\ng_t(\\boldsymbol{x}_t, \\boldsymbol{u}_t) = \\boldsymbol{x}_{t + 1}(\\boldsymbol{u}_t) &=&\n  A_{t} \\boldsymbol{x}_t + B_t \\boldsymbol{u}_t + \\boldsymbol{c}_{t} \\\\\n\nv_{t}(\\boldsymbol{x}_t, \\boldsymbol{u}_t) &=&\n  v_{t+1}(\\boldsymbol{x}_{t+1}) +\n  c_t(\\boldsymbol{x}_t, \\boldsymbol{u}_t) \\\\\\\n &=&\n  v_{t+1}(g_t(\\boldsymbol{x}_{t}, \\boldsymbol{u}_t)) +\n  c_t(\\boldsymbol{x}_t, \\boldsymbol{u}_t)\n  \\\\\n\\end{array}$$\n\nNow, let's calculate $v_t(\\boldsymbol{x})$ given $v_{t+1}(\\boldsymbol{x})$ and the step cost from $c_t(\\boldsymbol{x})$.\nThis tells us the cost of applying $\\boldsymbol{u}$ starting from $\\boldsymbol{x}$.\nWe will then optimize over all $\\boldsymbol{u}$ to find the optimal next state and cost for that state.\nThis lets us then use dynamic programing methods to work out the optimal $\\boldsymbol{x}$ and $\\boldsymbol{u}$ at each timestep.\n\nWe want to get a quadratic solution of the form\n$$v_{t}(\\boldsymbol{x}) =\n  \\frac{1}{2} \\boldsymbol{x}^T S_{t} \\boldsymbol{x} + \\boldsymbol{x}^T \\boldsymbol{s}_{t} + s_{t}$$ for each step.\n\n$$\\begin{array}{rcl}\nv_{t}(\\boldsymbol{x}, \\boldsymbol{u}) &=&\n  \\frac{1}{2} \\left( A_{t}\\boldsymbol{x} + B_{t}\\boldsymbol{u} + \\boldsymbol{c}_{t}\\right)^T\n    S_{t + 1}\n    \\left( A_{t}\\boldsymbol{x} + B_{t}\\boldsymbol{u} + \\boldsymbol{c}_{t}\\right) +\n  \\left( A_{t}\\boldsymbol{x} + B_{t}\\boldsymbol{u} + \\boldsymbol{c}_{t}\\right)^T \\boldsymbol{s}_{t + 1} +\n  s_{t + 1} + \\\\ &&\n  \\frac{1}{2}\n    \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} Q_{t} & P_{t}^T \\\\ P_{t} & R_{t} \\end{bmatrix}\n    \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix} +\n  \\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} \\boldsymbol{q}_{t} \\\\ \\boldsymbol{r}_{t} \\end{bmatrix} +\n    q_{t}\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T A_{t}^T S_{t + 1} A_{t} \\boldsymbol{x} +\n    \\boldsymbol{u}^T B_{t}^T S_{t + 1} A_{t} \\boldsymbol{x} +\n    \\boldsymbol{c}_t^T S_{t + 1} A_{t} \\boldsymbol{x} + \\right. \\\\ &&\n    \\left. \\boldsymbol{x}^T A_{t}^T S_{t + 1} B_{t} \\boldsymbol{u} +\n    \\boldsymbol{u}^T B_{t}^T S_{t + 1} B_{t} \\boldsymbol{u} +\n    \\boldsymbol{c}_t^T S_{t + 1} B_{t} \\boldsymbol{u} + \\right. \\\\ &&\n    \\left. \\boldsymbol{x}^T A_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{u}^T B_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t\n  \\right) + \\\\ &&\n  \\boldsymbol{x}^T A_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{u}^T B_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} +\n  s_{t + 1} + \\\\ &&\n  \\frac{1}{2} \\left(\\boldsymbol{x}^T Q_t \\boldsymbol{x} + \\boldsymbol{u}^T P_t \\boldsymbol{x} + \\boldsymbol{x}^T P_t^T \\boldsymbol{u} + \\boldsymbol{u}^T R_t \\boldsymbol{u} \\right) + \\boldsymbol{x}^T \\boldsymbol{q}_t + \\boldsymbol{u}^T \\boldsymbol{r}_t + q_t\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} A_{t} + Q_t \\right) \\boldsymbol{x} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} \\right. + \\\\ &&\n    \\left. \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) \\boldsymbol{u} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) \\boldsymbol{u} \\right) + \\\\ &&\n  \\boldsymbol{x}^T \\left(A_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{q}_t \\right)+\n\n  \\boldsymbol{u}^T \\left( B_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{r}_t \\right) +\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} +\n  q_t + \\\\ &&\n  \\frac{1}{2} \\left( \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n     \\boldsymbol{x}^T A_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{u}^T B_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T S_{t + 1} B_{t} \\boldsymbol{u} +\n    \\boldsymbol{c}_t^T S_{t + 1} A_{t} \\boldsymbol{x} \\right)\n\\end{array}$$\n\nNow, let's find the optimal $\\boldsymbol{u}$.  Do this by evaluating $\\frac{\\partial}{\\partial \\boldsymbol{u}} v_t(\\boldsymbol{x}, \\boldsymbol{u}) = 0$.\n\n$$\\begin{array}{rcl}\n\\frac{\\partial}{\\partial \\boldsymbol{u}} v_{t}(\\boldsymbol{x}, \\boldsymbol{u}) &=& \\frac{1}{2} \\left( 2 \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) + 2 \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) + 2 \\boldsymbol{c}_t^T S_{t + 1} B_{t} \\right) + \\\\&&\\boldsymbol{s}_{t + 1}^T B_{t} + \\boldsymbol{r}_t^T \\\\\n\n\\frac{\\partial}{\\partial \\boldsymbol{u}} v_{t}(\\boldsymbol{x}, \\boldsymbol{u}) &=& \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) + \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) + \\boldsymbol{c}_t^T S_{t + 1} B_{t} + \\boldsymbol{s}_{t + 1}^T B_{t} + \\boldsymbol{r}_t^T \\\\\n0 &=& \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) + \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) + \\boldsymbol{c}_t^T S_{t + 1} B_{t} + \\boldsymbol{s}_{t + 1}^T B_{t} + \\boldsymbol{r}_t^T\n\\end{array}$$\n$$\\begin{array}{rcl}\n\\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) &=& - \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) - \\boldsymbol{c}_t^T S_{t + 1} B_{t} - \\boldsymbol{s}_{t + 1}^T B_{t} - \\boldsymbol{r}_t^T \\\\\n\\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) \\boldsymbol{u} &=& - \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} - B_t^T S_{t + 1} \\boldsymbol{c}_t - B_{t}^T \\boldsymbol{s}_{t + 1}- \\boldsymbol{r}_t \\\\\n\\boldsymbol{u} &=& - \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) ^{-1} \\left( \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} + B_t^T S_{t + 1} \\boldsymbol{c}_t + B_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{r}_t \\right)\n\\end{array}$$\n\nThis gives us the optimal $\\boldsymbol{u}$.  There are some substitutions defined here from the 2013 paper which make it easier to read.\nNote: the 2014 paper uses different letters for these same quantities\\dots\n\\\\\n$$\\begin{array}{rcl}\nC_t &=& B^T_t S_{t + 1} A_t + P_t \\\\\nE_t &=&  B_{t}^T S_{t + 1} B_{t} + R_t \\\\\nL_t &=& - E_t ^{-1} C_t \\\\\n\n\\boldsymbol{e}_t &=& B_t^T S_{t + 1} \\boldsymbol{c}_t + B_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{r}_t \\\\\n\\boldsymbol{l}_t &=&  - E^{-1}_t \\boldsymbol{e}_t \\\\\n\nD_t &=& A_t^T S_{t + 1} A_t + Q_t \\\\\n\\boldsymbol{d}_t &=& A_t^T S_{t + 1} \\boldsymbol{c}_t + A_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{q}_t\n\\\\\n\\boldsymbol{u} &=& L_t \\boldsymbol{x} + \\boldsymbol{l}_t\n\\end{array}$$\n\nWith these, we can simplify $\\boldsymbol{u}$ a bit and make it look like the 2014 paper has it.\n\n$$\\begin{array}{rcl}\n  \\boldsymbol{u} &=& -E_t^{-1} \\left( C_t \\boldsymbol{x} + \\boldsymbol{e}_t \\right) \\\\\n  \\boldsymbol{u} &=& -E_t^{-1} C_t \\boldsymbol{x} - E_t^{-1} \\boldsymbol{e}_t\n\\end{array}$$\n\nFor reference, here are some equivalences between the symbols used in the 2013\npaper (the ones we use) and the 2014 paper.\nTODO(Brian): Figure out where the ones in the 2014 paper are defined instead of\nguessing by pattern-matching.\n\\\\ \\begin{tabular}{ | r | l | }\n  \\hline\n  2013 paper (ours) & 2014 paper \\\\\n  \\hline\n  $C_t$ & $E_t$ \\\\\n  $D_t$ & $C_t$ \\\\\n  $\\boldsymbol{d}_t$ & $\\boldsymbol{c}_t$ \\\\\n  $E_t$ & $D_t$ \\\\\n  $\\boldsymbol{e}_t$ & $\\boldsymbol{d}_t$ \\\\\n  \\hline\n\\end{tabular} \\\\\n\nNow, let's solve for the new cost function.\n\n$$\\begin{array}{rcl}\nv_{t}(\\boldsymbol{x}, \\boldsymbol{u}) &=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} A_{t} + Q_t \\right) \\boldsymbol{x} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} \\right. + \\\\ &&\n    \\left. \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) \\boldsymbol{u} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) \\boldsymbol{u} \\right) + \\\\ &&\n  \\boldsymbol{x}^T \\left(A_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{q}_t \\right)+\n\n  \\boldsymbol{u}^T \\left( B_{t}^T \\boldsymbol{s}_{t + 1} +\n  \\boldsymbol{r}_t \\right) +\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} +\n  q_t + \\\\ &&\n  \\frac{1}{2} \\left( \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n     \\boldsymbol{x}^T A_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{u}^T B_{t}^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T S_{t + 1} B_{t} \\boldsymbol{u} +\n    \\boldsymbol{c}_t^T S_{t + 1} A_{t} \\boldsymbol{x} \\right)\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} A_{t} + Q_t \\right) \\boldsymbol{x} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} \\right. + \\\\ &&\n    \\left. \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) \\boldsymbol{u} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) \\boldsymbol{u} \\right) + \\\\ &&\n\n  \\boldsymbol{x}^T \\left(A_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{q}_t +\n    \\frac{1}{2} A_{t}^T S_{t + 1} \\boldsymbol{c}_t \\right) + \\\\ &&\n\n  \\boldsymbol{u}^T \\left( B_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{r}_t +\n    \\frac{1}{2} B_{t}^T S_{t + 1} \\boldsymbol{c}_t \\right) + \\\\ &&\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\left( A_t \\boldsymbol{x} +\n    B_t \\boldsymbol{u} + \\boldsymbol{c}_t \\right) + \\\\ &&\n\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} A_{t} + Q_t \\right) \\boldsymbol{x} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} A_{t} + P_t \\right) \\boldsymbol{x} \\right. + \\\\ &&\n    \\left. \\boldsymbol{x}^T \\left( A_{t}^T S_{t + 1} B_{t} + P_t^T \\right) \\boldsymbol{u} +\n    \\boldsymbol{u}^T \\left( B_{t}^T S_{t + 1} B_{t} + R_t \\right) \\boldsymbol{u} \\right) + \\\\ &&\n\n  \\boldsymbol{x}^T \\left(A_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{q}_t +\n    A_{t}^T S_{t + 1} \\boldsymbol{c}_t \\right) + \\\\ &&\n\n  \\boldsymbol{u}^T \\left( B_{t}^T \\boldsymbol{s}_{t + 1} + \\boldsymbol{r}_t +\n    B_{t}^T S_{t + 1} \\boldsymbol{c}_t \\right) + \\\\ &&\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T D_t \\boldsymbol{x} +\n    \\boldsymbol{u}^T C_t \\boldsymbol{x} +\n    \\boldsymbol{x}^T C_t^T \\boldsymbol{u} +\n    \\boldsymbol{u}^T E_t \\boldsymbol{u} \\right) + \\\\ &&\n\n  \\boldsymbol{x}^T \\boldsymbol{d}_t +\n  \\boldsymbol{u}^T \\boldsymbol{e}_t + \\\\ &&\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T D_t \\boldsymbol{x} +\n    \\left( L_t \\boldsymbol{x} + \\boldsymbol{l}_t \\right)^T C_t \\boldsymbol{x} \\right. + \\\\ &&\n    \\left. \\boldsymbol{x}^T C_t^T \\left( L_t \\boldsymbol{x} + \\boldsymbol{l}_t \\right) +\n    \\left( L_t \\boldsymbol{x} + \\boldsymbol{l}_t \\right)^T E_t \\left( L_t \\boldsymbol{x} + \\boldsymbol{l}_t \\right) \\right) + \\\\ &&\n\n  \\boldsymbol{x}^T \\boldsymbol{d}_t +\n  \\left( L_t \\boldsymbol{x} + \\boldsymbol{l}_t \\right)^T \\boldsymbol{e}_t + \\\\&&\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t\n\\\\\n&=&\n  \\frac{1}{2} \\left(\n    \\boldsymbol{x}^T D_t \\boldsymbol{x} + \\right.\n    \\boldsymbol{x}^T L_t^T C_t \\boldsymbol{x} + \\boldsymbol{l}_t^T C_t \\boldsymbol{x} + \\\\ &&\n\n    \\left. \\boldsymbol{x}^T C_t^T L_t \\boldsymbol{x} + \\boldsymbol{x}^T C_t^T \\boldsymbol{l}_t +\n\n    \\boldsymbol{x}^T L_t^T E_t L_t \\boldsymbol{x} +\n    \\boldsymbol{l}_t^T E_t L_t \\boldsymbol{x} +\n    \\boldsymbol{x}^T L_t^T E_t \\boldsymbol{l}_t +\n    \\boldsymbol{l}_t^T E_t \\boldsymbol{l}_t \\right) + \\\\&&\n\n  \\boldsymbol{x}^T \\boldsymbol{d}_t +\n  \\boldsymbol{x}^T L_t^T \\boldsymbol{e}_t + \\boldsymbol{l}^T_t \\boldsymbol{e}_t + \\\\&&\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n    \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t\n\\\\\n&=&\n  \\frac{1}{2}\n    \\boldsymbol{x}^T \\left(\n      D_t +\n     L_t^T C_t +\n     C_t^T L_t +\n     L_t^T E_t L_t\n      \\right) \\boldsymbol{x} + \\\\ &&\n\n  \\boldsymbol{x}^T \\left(\n    \\frac{1}{2} \\left( C_t^T \\boldsymbol{l}_t +\n    L_t^T E_t \\boldsymbol{l}_t \\right) +\n    \\boldsymbol{d}_t +\n    L_t^T \\boldsymbol{e}_t \\right) +\n    \\frac{1}{2} \\left( \\boldsymbol{l}_t^T E_t L_t + \\boldsymbol{l}_t^T C_t \\right) \\boldsymbol{x} + \\\\ &&\n\n  \\frac{1}{2} \\boldsymbol{l}_t^T E_t \\boldsymbol{l}_t +\n    \\boldsymbol{l}^T_t \\boldsymbol{e}_t +\n\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t +\n    \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t\n\\\\\n&=&\n  \\frac{1}{2}\n    \\boldsymbol{x}^T \\left(\n      D_t +\n     L_t^T C_t +\n     C_t^T L_t +\n     L_t^T E_t L_t\n      \\right) \\boldsymbol{x} + \\\\ &&\n\n  \\boldsymbol{x}^T \\left(\n    C_t^T \\boldsymbol{l}_t +\n    L_t^T E_t \\boldsymbol{l}_t +\n    \\boldsymbol{d}_t +\n    L_t^T \\boldsymbol{e}_t \\right) + \\\\ &&\n\n  \\frac{1}{2} \\boldsymbol{l}_t^T E_t \\boldsymbol{l}_t +\n    \\boldsymbol{l}^T_t \\boldsymbol{e}_t +\n\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t +\n    \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t\n\\end{array}$$\n\nOk, let's now pull out the 3 variables of interest and do further simplification.\n\n$$\\begin{array}{rcl}\nv_{t}(\\boldsymbol{x}) &=&\n  \\frac{1}{2} \\boldsymbol{x}^T S_{t} \\boldsymbol{x} + \\boldsymbol{x}^T \\boldsymbol{s}_{t} + s_{t} \\\\\nS_t &=&\n     D_t +\n     L_t^T C_t +\n     C_t^T L_t +\n     L_t^T E_t L_t \\\\\n    &=&\n     D_t -\n     C_t^T E_t^{-1} C_t -\n     C_t^T E_t^{-1} C_t +\n     C_t^T E_t^{-1} C_t \\\\\n    &=& D_t - C_t^T E_t^{-1} C_t\n\\\\\n\\boldsymbol{s}_t &=&\n    \\left( C_t^T + L_t^T E_t \\right) \\boldsymbol{l}_t +\n    \\boldsymbol{d}_t +\n    L_t^T \\boldsymbol{e}_t \\\\\n\n  &=&\n    \\left( C_t^T - C_t^T E_t^{-1} E_t \\right) \\boldsymbol{l}_t +\n    \\boldsymbol{d}_t -\n    C_t^T E_t^{-1} \\boldsymbol{e}_t \\\\\n  &=& \\boldsymbol{d}_t - C_t^T E_t^{-1} \\boldsymbol{e}_t\n\\\\\ns_t &=&\n  \\frac{1}{2} \\boldsymbol{l}_t^T E_t \\boldsymbol{l}_t +\n    \\boldsymbol{l}^T_t \\boldsymbol{e}_t +\n\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t +\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t\n\\\\\n&=&\n\\frac{1}{2} \\boldsymbol{e}_t^T E_t^{-1} E_t E_t^{-1} \\boldsymbol{e}_t -\n  \\boldsymbol{e}_t^T E_t^{-1} \\boldsymbol{e}_t +\n\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1} + q_t +\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t\n\\\\\n&=&\nq_t - \\frac{1}{2} \\boldsymbol{e}_t^T E_t^{-1} \\boldsymbol{e}_t +\n\n  \\frac{1}{2} \\boldsymbol{c}_t^T S_{t + 1} \\boldsymbol{c}_t +\n  \\boldsymbol{c}_t^T \\boldsymbol{s}_{t + 1} + s_{t + 1}\n\\end{array}$$\n\nFor better or worse, everything but the constant term matches both the 2013\npaper (which has no constant term) and the 2014 paper.\nThe constant term does not match the 2014 paper, but we're pretty sure it's\ncorrect (extended\\_lqr\\_derivation.py verifies what we have).\nThe 2014 paper has this for the constant term instead:\n$$\\begin{array}{rcl}\ns_t &=&\n  q_t - \\frac{1}{2} \\boldsymbol{e}_t^T E_t^{-1} \\boldsymbol{e}_t\n\\end{array}$$\n\n\\section{Forwards Pass}\n\nLet's define the forwards pass to build the cost-to-come function.\nWe must use the same cycle cost, $c_t(\\boldsymbol{x}, \\boldsymbol{u})$, as the backwards pass.\nThe initial cost $v_0(\\boldsymbol{x})$ needs to evaluate to $0$ at $\\boldsymbol{x}_0$ since\nthere is no cost needed to get from $\\boldsymbol{x}_0$ to $\\boldsymbol{x}_0$.\n\n$$\\begin{array}{rcl}\n\\bar v_{t}(\\boldsymbol{x}) &=&\n  \\frac{1}{2} \\boldsymbol{x}^T \\bar S_{t} \\boldsymbol{x} + \\boldsymbol{x}^T \\boldsymbol{\\bar s}_{t} + \\bar s_{t} \\\\\n\n\\bar g_t(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u}) = \\boldsymbol{x}_{t}(\\boldsymbol{u}) &=&\n  \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t} \\\\\n\n\\bar c_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u}) &=& c_t(\\bar g_{t}(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u}), \\boldsymbol{u}) \\\\\n\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u}) &=&\n  \\bar v_{t}(\\boldsymbol{x}_{t}) +\n  \\bar c_t(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u}_t)\n  \\\\\n&=&\n  \\bar v_{t}(\\bar g_t(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u})) +\n c_t(\\bar g_{t}(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u}), \\boldsymbol{u}) \\\\\n  \\\\\n\\end{array}$$\n\nIt is important to note that the optimal $\\boldsymbol{u}$ used to get from $\\boldsymbol{x}_t$ to $\\boldsymbol{x}_{t+1}$\nwhen evaluating $g_t(\\boldsymbol{x}, \\boldsymbol{u})$ is the same optimal $\\boldsymbol{u}$\nused to get from $\\boldsymbol{x}_{t+1}$ to $\\boldsymbol{x}_t$ when evaluating $\\bar g_{t}(\\boldsymbol{x}_{t + 1}, \\boldsymbol{u})$.\nConveniently, this means that the $\\boldsymbol{u}_t$, $L_t$, and $\\boldsymbol{l}_t$ calculated in both the forwards and backwards passes is the same.\n\nLike before, we want to get a quadratic solution of the form\n$$\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}) =\n  \\frac{1}{2} \\boldsymbol{x}_{t+1}^T \\bar S_{t + 1} \\boldsymbol{x}_{t+1} + \\boldsymbol{x}_{t+1}^T \\boldsymbol{\\bar s}_{t + 1} + \\bar s_{t + 1}$$ for each step.\n\n$$\\begin{array}{rcl}\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u}) &=&\n    \\frac{1}{2} \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T\n        \\bar S_{t}\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) + \\\\ &&\n    \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) ^T \\boldsymbol{\\bar s}_{t} + \\bar s_{t} +  \\\\&&\n  \\frac{1}{2}\n    \\begin{bmatrix} \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} Q_t & P_t^T \\\\ P_t & R_t \\end{bmatrix}\n    \\begin{bmatrix} \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) \\\\ \\boldsymbol{u} \\end{bmatrix} + \\\\&&\n  \\begin{bmatrix} \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n    \\begin{bmatrix} \\boldsymbol{q}_t \\\\ \\boldsymbol{r}_t \\end{bmatrix} +\n  q_t \\\\\n\n  &=&\n    \\frac{1}{2} \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T\n        \\bar S_{t}\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) + \\\\ &&\n    \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) ^T \\boldsymbol{\\bar s}_{t} + \\bar s_{t} +  \\\\&&\n\n      \\frac{1}{2} \\left(\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T Q_t \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) + \\right. \\\\&&\n        \\boldsymbol{u}^T P_t \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) + \\\\&&\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T P_t^T \\boldsymbol{u} + \\\\&&\n        \\left. \\boldsymbol{u}^T R_t \\boldsymbol{u} \\right) + \\\\&&\n\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T \\boldsymbol{q}_t + \\boldsymbol{u}^T \\boldsymbol{r}_t + q_t \\\\\n\n  &=&\n    \\frac{1}{2} \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T\n      \\left( \\bar S_{t} + Q_t \\right)\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) + \\\\ &&\n    \\left(\\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) ^T \\boldsymbol{\\bar s}_{t} + \\bar s_{t} +  \\\\&&\n\n      \\frac{1}{2} \\left(\n        \\boldsymbol{u}^T P_t \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right) \\right. + \\\\&&\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T P_t^T \\boldsymbol{u} + \\\\&&\n        \\left. \\boldsymbol{u}^T R_t \\boldsymbol{u} \\right) + \\\\&&\n\n        \\left( \\bar A_{t} \\boldsymbol{x}_{t + 1} + \\bar B_t \\boldsymbol{u} + \\boldsymbol{\\bar c}_{t}\\right)^T \\boldsymbol{q}_t + \\boldsymbol{u}^T \\boldsymbol{r}_t + q_t \\\\\n\n  &=& \\frac{1}{2} \\left(\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t + \\right. \\\\&&\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t + \\\\&&\n      \\left. \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t \\right) + \\\\&&\n\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\boldsymbol{\\bar s}_t +\n      \\boldsymbol{u}^T \\bar B_t^T \\boldsymbol{\\bar s}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t +\n\n      \\bar s_t + \\\\ &&\n\n      \\frac{1}{2} \\left( \\boldsymbol{u}^T P_t \\bar A_{t} \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{u}^T P_t \\bar B_{t} \\boldsymbol{u} +\n      \\boldsymbol{u}^T P_t \\boldsymbol{\\bar c}_{t} \\right) + \\\\&&\n      \\frac{1}{2} \\left( \\boldsymbol{x}_{t+1}^T \\bar A^T_t P_t^T \\boldsymbol{u} +\n      \\boldsymbol{u}^T \\bar B^T_{t} P_t^T \\boldsymbol{u} +\n      \\boldsymbol{\\bar c}_t^T P^T_t \\boldsymbol{u} \\right) + \\\\&&\n\n      \\frac{1}{2} \\boldsymbol{u}^T R_t \\boldsymbol{u} + \\\\&&\n\n        \\boldsymbol{x}^T_{t + 1} \\bar A^T_t \\boldsymbol{q}_t +\n        \\boldsymbol{u}^T \\bar B^T_t \\boldsymbol{q}_t +\n      \\boldsymbol{\\bar c}_t^T  \\boldsymbol{q}_t +\n\n        \\boldsymbol{u}^T \\boldsymbol{r}_t + q_t\n\\end{array}$$\n\nNow, let's find the optimal $\\boldsymbol{u}$.\nDo this by evaluating\n$\\frac{\\partial}{\\partial \\boldsymbol{u}} \\bar v_t(\\boldsymbol{x}, \\boldsymbol{u}) = 0$.\n\n$$\\begin{array}{rcl}\n\\frac{\\partial}{\\partial \\boldsymbol{u}} \\bar v_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u})\n  &=& \\frac{1}{2} \\left(\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n\n      \\left(\\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1}\\right)^T + \\right. \\\\&&\n\n      2 \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n      \\left( \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t \\right)^T + \\\\&&\n      \\left. \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\right) + \\\\&& \n      \\boldsymbol{\\bar s}_t ^T \\bar B_t + \\\\&&\n\n      \\frac{1}{2} \\left( P_t \\bar A_{t} \\boldsymbol{x}_{t + 1}\\right) ^T +\n      \\frac{1}{2} \\boldsymbol{x}_{t+1}^T \\bar A^T_t P_t^T + \\\\&&\n\n      \\frac{1}{2} \\boldsymbol{u}^T \\left( P_t \\bar B_{t} + \\bar B_t^T P_t^T \\right) +\n      \\frac{1}{2} \\boldsymbol{u}^T \\left( \\bar B^T_{t} P_t^T + P_t \\bar B_t \\right) + \\\\&&\n      \\frac{1}{2} \\left( P_t \\boldsymbol{\\bar c}_{t} \\right)^T +\n      \\frac{1}{2} \\boldsymbol{\\bar c}^T_{t} P_t^T +\n\n      \\boldsymbol{u}^T R_t + \\\\&&\n\n        \\left(\\bar B^T_t \\boldsymbol{q}_t\\right)^T +\n\n        \\boldsymbol{r}_t^T \\\\\n\n  &=&\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t + \\\\&& \n\n      \\boldsymbol{\\bar s}_t ^T \\bar B_t + \\\\&&\n\n      \\boldsymbol{x}_{t+1}^T \\bar A^T_t P_t^T + \\\\&&\n\n      \\boldsymbol{u}^T \\left( \\bar B^T_{t} P_t^T + P_t \\bar B_t \\right) + \\\\&&\n      \\boldsymbol{\\bar c}^T_{t} P_t^T +\n\n      \\boldsymbol{u}^T R_t + \\\\&&\n\n      \\boldsymbol{q}_t^T \\bar B_t +\n      \\boldsymbol{r}_t^T \\\\\n0 &=&\n      \\boldsymbol{x}_{t + 1}^T \\left( \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t + \\bar A^T_t P_t^T \\right) + \\\\&&\n\n      \\boldsymbol{u}^T \\left(\n          \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n          \\bar B^T_{t} P_t^T + P_t \\bar B_t + R_t\n      \\right) + \\\\&&\n\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n      \\boldsymbol{\\bar s}_t^T \\bar B_t +\n      \\boldsymbol{\\bar c}^T_{t} P_t^T +\n      \\boldsymbol{q}_t^T \\bar B_t +\n      \\boldsymbol{r}_t^T \\\\\n\\end{array}$$\n\n$$\\begin{array}{rcl}\n      \\boldsymbol{u}^T \\left(\n          \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n          \\bar B^T_{t} P_t^T + P_t \\bar B_t + R_t\n      \\right)\n &=&\n      - \\boldsymbol{x}_{t + 1}^T \\left( \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t + \\bar A^T_t P_t^T \\right) - \\\\&&\n\n\n      \\left( \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n      \\boldsymbol{\\bar s}_t^T \\bar B_t +\n      \\boldsymbol{\\bar c}^T_{t} P_t^T +\n      \\boldsymbol{q}_t^T \\bar B_t +\n      \\boldsymbol{r}_t^T \\right) \\\\\n\n\\left(\n    \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n    \\bar B^T_{t} P_t^T + P_t \\bar B_t + R_t\n\\right) \\boldsymbol{u}\n   &=&\n      - \\left( \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t + P_t \\bar A_t \\right) \\boldsymbol{x}_{t + 1} - \\\\&&\n\n      \\left( \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t  +\n      \\bar B_t^T \\boldsymbol{\\bar s}_t +\n      P_t \\boldsymbol{\\bar c}_{t} +\n      \\bar B_t^T \\boldsymbol{q}_t +\n      \\boldsymbol{r}_t \\right) \\\\\n\\end{array}$$\n\nSome substitutions to use for simplifying:\n\n$$\\begin{array}{rcl}\n\\bar C_t &=& \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t + P_t \\bar A_t \\\\\n\\bar E_t &=&\n    \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t +\n    \\bar B^T_{t} P_t^T + P_t \\bar B_t + R_t \\\\\n\\bar L_t &=& - \\bar E_t^{-1} \\bar C_t \\\\\n\n\\boldsymbol{\\bar e}_t &=&\n      \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t  +\n      \\bar B_t^T \\boldsymbol{\\bar s}_t +\n      P_t \\boldsymbol{\\bar c}_{t} +\n      \\bar B_t^T \\boldsymbol{q}_t +\n      \\boldsymbol{r}_t \\\\\n\\boldsymbol{\\bar l}_t &=& - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\\\\n\n\\bar D_t &=& \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\\\\n\\boldsymbol{\\bar d}_t &=&\n      \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t +\n      \\bar A_t^T \\left( \\boldsymbol{\\bar s}_t + \\boldsymbol{q}_t \\right) \\\\\n\n\\boldsymbol{u} &=& - \\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\\\\n\\boldsymbol{u} &=& \\bar L_t \\boldsymbol{x}_{t + 1} + \\boldsymbol{\\bar l}_t \\\\\n\n\\bar E_t \\boldsymbol{u} &=& -\\bar C_t \\boldsymbol{x}_{t + 1} - \\boldsymbol{\\bar e}_t\n\\end{array}$$\n\nNow, let's solve for the new cost function.\n\n$$\\begin{array}{rcl}\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u})\n  &=& \\frac{1}{2} \\left(\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t + \\right. \\\\&&\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{u}^T \\bar B_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t + \\\\&&\n      \\left. \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar A_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\bar B_t \\boldsymbol{u} +\n      \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t \\right) + \\\\&& \n\n      \\boldsymbol{x}_{t + 1}^T \\bar A_t^T \\boldsymbol{\\bar s}_t +\n      \\boldsymbol{u}^T \\bar B_t^T \\boldsymbol{\\bar s}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t +\n\n      \\bar s_t + \\\\ &&\n\n      \\frac{1}{2} \\left( \\boldsymbol{u}^T P_t \\bar A_{t} \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{u}^T P_t \\bar B_{t} \\boldsymbol{u} +\n      \\boldsymbol{u}^T P_t \\boldsymbol{\\bar c}_{t} \\right) + \\\\&&\n      \\frac{1}{2} \\left( \\boldsymbol{x}_{t+1}^T \\bar A^T_t P_t^T \\boldsymbol{u} +\n      \\boldsymbol{u}^T \\bar B^T_{t} P_t^T \\boldsymbol{u} +\n      \\boldsymbol{\\bar c}_t^T P^T_t \\boldsymbol{u} \\right) + \\\\&&\n\n      \\frac{1}{2} \\boldsymbol{u}^T R_t \\boldsymbol{u} + \\\\&&\n\n        \\boldsymbol{x}^T_{t + 1} \\bar A^T_t \\boldsymbol{q}_t +\n        \\boldsymbol{u}^T \\bar B^T_t \\boldsymbol{q}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{q}_t +\n\n        \\boldsymbol{u}^T \\boldsymbol{r}_t + q_t \\\\\n\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}, \\boldsymbol{u})\n  &=& \\frac{1}{2} \\left(\n      \\boldsymbol{x}_{t + 1}^T \\bar D_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{x}_{t + 1}^T \\bar C_t^T \\boldsymbol{u} +\n      \\boldsymbol{u}^T \\bar C_t \\boldsymbol{x}_{t + 1} +\n      \\boldsymbol{u}^T \\bar E_t \\boldsymbol{u} \\right) + \\\\&&\n\n      \\boldsymbol{x}_{t + 1}^T \\boldsymbol{\\bar d}_t +\n\n      \\boldsymbol{u}^T \\boldsymbol{\\bar e}_t + \\\\&&\n\n      \\frac{1}{2} \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t + \\boldsymbol{\\bar c}_t^T \\boldsymbol{q}_t + \\bar s_t + q_t \\\\\n\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1})\n  &=& \\frac{1}{2} \\left(\n      \\boldsymbol{x}_{t + 1}^T \\bar D_t \\boldsymbol{x}_{t + 1} + \\right. \\\\ &&\n      \\boldsymbol{x}_{t + 1}^T \\bar C_t^T \\left( -\\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right) + \\\\&&\n      \\left( -\\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right)^T \\bar C_t \\boldsymbol{x}_{t + 1} + \\\\&&\n      \\left. \\left( -\\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right)^T \\bar E_t \\left( -\\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right) \\right) + \\\\&&\n\n      \\boldsymbol{x}_{t + 1}^T \\boldsymbol{\\bar d}_t +\n\n      \\left( -\\bar E_t^{-1} \\bar C_t \\boldsymbol{x}_{t + 1} - \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right)^T \\boldsymbol{\\bar e}_t + \\\\&&\n\n      \\frac{1}{2} \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t + \\boldsymbol{\\bar c}_t^T \\boldsymbol{q}_t + \\bar s_t + q_t \\\\\n\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1})\n  &=& \\frac{1}{2}\n      \\boldsymbol{x}_{t + 1}^T \\left(\\bar D_t - \\bar C_t^T \\bar E_t^{-1} \\bar C_t \\right) \\boldsymbol{x}_{t + 1} + \\\\ &&\n\n      \\boldsymbol{x}_{t + 1}^T \\left(\\boldsymbol{\\bar d}_t\n      - \\bar C_t^T \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right)\\\\&&\n\n      - \\frac{1}{2} \\boldsymbol{\\bar e}_t^T \\bar E_t^{-1} \\boldsymbol{\\bar e}_t +\n      \\frac{1}{2} \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t + \\boldsymbol{\\bar c}_t^T \\boldsymbol{q}_t + \\bar s_t + q_t \\\\\n\\end{array}$$\n\nOk, let's now pull out the 3 variables of interest and do further simplification.\n\n$$\\begin{array}{rcl}\n\\bar v_{t + 1}(\\boldsymbol{x}_{t+1}) &=& \\frac{1}{2} \\boldsymbol{x}_{t + 1}^T \\bar S_{t + 1} \\boldsymbol{x}_{t + 1} + \\boldsymbol{x}_{t + 1}^T \\boldsymbol{\\bar s}_{t + 1} + \\bar s_{t+1} \\\\\n  \\bar S_{t + 1} &=& \\bar D_t - \\bar C_t^T \\bar E_t^{-1} \\bar C_t \\\\\n  \\boldsymbol{\\bar s}_{t + 1} &=&\n       \\left(\\boldsymbol{\\bar d}_t - \\bar C_t^T \\bar E_t^{-1} \\boldsymbol{\\bar e}_t \\right)\\\\\n\n\\bar s_{t+1} &=&\n      - \\frac{1}{2} \\boldsymbol{\\bar e}_t^T \\bar E_t^{-1} \\boldsymbol{\\bar e}_t +\n      \\frac{1}{2} \\boldsymbol{\\bar c}_t^T \\left( \\bar S_t + Q_t \\right) \\boldsymbol{\\bar c}_t +\n      \\boldsymbol{\\bar c}_t^T \\boldsymbol{\\bar s}_t + \\boldsymbol{\\bar c}_t^T \\boldsymbol{q}_t + \\bar s_t + q_t \\\\\n\\end{array}$$\n\n\\newpage\n\\section{Detailed work for a few transformations}\n\n$$\\begin{array}{l}\n\\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n\\begin{bmatrix} Q_{t} & P_{t}^T \\\\ P_{t} & R_{t} \\end{bmatrix}\n\\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix} \\\\\n\n\\begin{bmatrix} \\boldsymbol{x}_1 & \\boldsymbol{x}_2 & \\boldsymbol{u}_1 & \\boldsymbol{u}_2 \\end{bmatrix}\n\\left[\\begin{array}{cc|cc}\n    Q_{t11} & Q_{t12} & P_{t11} & P_{t21} \\\\\n    Q_{t21} & Q_{t22} & P_{t12} & P_{t22} \\\\\n    \\hline\n    P_{t11} & P_{t12} & R_{t11} & R_{t12} \\\\\n    P_{t21} & P_{t22} & R_{t21} & R_{t22} \\\\\n\\end{array}\\right]\n\\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix}\n\\\\\n\\begin{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} Q_{t11} \\\\ Q_{t21} \\\\ P_{t11} \\\\ P_{t21} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} Q_{t12} \\\\ Q_{t22} \\\\ P_{t12} \\\\ P_{t22} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} P_{t11} \\\\ P_{t12} \\\\ R_{t11} \\\\ R_{t21} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} P_{t21} \\\\ P_{t22} \\\\ R_{t12} \\\\ R_{t22} \\end{bmatrix} &\n\\end{bmatrix}\n\\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix}\n\\\\\n\\begin{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} Q_{t11} \\\\ Q_{t21} \\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} Q_{t12} \\\\ Q_{t22} \\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} P_{t11} \\\\ P_{t12} \\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n    \\begin{bmatrix} P_{t21} \\\\ P_{t22} \\end{bmatrix}\n\\end{bmatrix}\n\\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} + \\\\ \\quad\n\\begin{bmatrix}\n    \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n      \\begin{bmatrix} P_{t11} \\\\ P_{t21} \\end{bmatrix} &\n    \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n      \\begin{bmatrix} P_{t12} \\\\ P_{t22} \\end{bmatrix} &\n    \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n      \\begin{bmatrix} R_{t11} \\\\ R_{t21} \\end{bmatrix} &\n    \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n      \\begin{bmatrix} R_{t12} \\\\ R_{t22} \\end{bmatrix} &\n\\end{bmatrix}\n\\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\\\ \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix}\n\\\\\n\\begin{bmatrix} \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} Q_{t11} \\\\ Q_{t21} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} Q_{t12} \\\\ Q_{t22} \\end{bmatrix}\\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} +\n\\begin{bmatrix} \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} P_{t11} \\\\ P_{t12} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} P_{t21} \\\\ P_{t22} \\end{bmatrix}\\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} + \\\\ \\quad\n\\begin{bmatrix} \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} P_{t11} \\\\ P_{t21} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} P_{t12} \\\\ P_{t22} \\end{bmatrix}\\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{x}_1 \\\\ \\boldsymbol{x}_2 \\end{bmatrix} +\n\\begin{bmatrix} \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} R_{t11} \\\\ R_{t21} \\end{bmatrix} &\n  \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix} \\cdot\n  \\begin{bmatrix} R_{t12} \\\\ R_{t22} \\end{bmatrix}\\end{bmatrix}\n  \\begin{bmatrix} \\boldsymbol{u}_1 \\\\ \\boldsymbol{u}_2 \\end{bmatrix}\n\\\\\n\\boldsymbol{x}^T Q_t \\boldsymbol{x} + \\boldsymbol{u}^T P_t \\boldsymbol{x} + \\boldsymbol{x}^T P_t^T \\boldsymbol{u} + \\boldsymbol{u}^T R_t \\boldsymbol{u}\n\\end{array}$$\n\\\\ \\\\\n$$\\begin{array}{l}\n\\begin{bmatrix} \\boldsymbol{x} \\\\ \\boldsymbol{u} \\end{bmatrix}^T\n\\begin{bmatrix} \\boldsymbol{q}_{t} \\\\ \\boldsymbol{r}_{t} \\end{bmatrix}\n\\\\\n\\begin{bmatrix} \\boldsymbol{x}_1 & \\boldsymbol{x}_2 & \\boldsymbol{u}_1 & \\boldsymbol{u}_2 \\end{bmatrix}\n\\begin{bmatrix} \\boldsymbol{q}_{t1} \\\\ \\boldsymbol{q}_{t2} \\\\ \\boldsymbol{r}_{t1} \\\\ \\boldsymbol{r}_{t1} \\end{bmatrix}\n\\\\\n\\boldsymbol{x}^T \\boldsymbol{q}_t + \\boldsymbol{u}^T \\boldsymbol{r}_t\n\\end{array}$$\n\n\\end{document}\n", "meta": {"hexsha": "52d09496b895c37aec13beeeaff4c50351f1e4ec", "size": 37811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "y2014/control_loops/python/extended_lqr.tex", "max_stars_repo_name": "Ewpratten/frc_971_mirror", "max_stars_repo_head_hexsha": "3a8a0c4359f284d29547962c2b4c43d290d8065c", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-06-18T03:22:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T15:23:43.000Z", "max_issues_repo_path": "y2014/control_loops/python/extended_lqr.tex", "max_issues_repo_name": "Ewpratten/frc_971_mirror", "max_issues_repo_head_hexsha": "3a8a0c4359f284d29547962c2b4c43d290d8065c", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2021-06-18T03:22:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-18T22:14:15.000Z", "max_forks_repo_path": "y2014/control_loops/python/extended_lqr.tex", "max_forks_repo_name": "Ewpratten/frc_971_mirror", "max_forks_repo_head_hexsha": "3a8a0c4359f284d29547962c2b4c43d290d8065c", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-08-19T19:20:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T07:33:18.000Z", "avg_line_length": 49.29726206, "max_line_length": 341, "alphanum_fraction": 0.591362302, "num_tokens": 16185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6163651132575617}}
{"text": "\\subsection{Full Decomposition}\n\\SecLabel{full}\n\nThe full decomposition of $\\pi$ is obtained from the decompositions of mini-block ciphers $T$ and $U$. First, let me describe the whitening linear layers. \n\nRecall the whitening linear layer $L^{\\top}$ $L$ was described in the beginning of \\SecRef{multi}. Let $L_{in} \\in \\linbij{8}$ be given by\n$$\nL_{in} \\eqdef l_{\\swaplsb} \\circ l_{\\eta} \\circ l_{\\delta} \\circ L^{\\top},\n$$\nwhere $L$ was described in the beginning of \\SecRef{multi}, $l_{\\eta}, l_{\\delta}, l_{\\swaplsb} \\in \\linbij{8}$ are given by\n\\begin{align*}\n    l_{\\delta}(x, k) &\\eqdef (x \\oplus \\delta(k), k), \\\\\n    l_{\\eta}(x, k) &\\eqdef (\\eta(x), \\delta(k)), \\\\\n    l_{\\swaplsb}(x, k) &\\eqdef (x, \\swaplsb(k)).\n\\end{align*}\nLet $L_{out} \\in \\linbij{8}$ be given by\n$$\nL_{out} \\eqdef \\invtop{L} \\circ l_{\\alpha},\n$$\nwhere $l_{\\alpha} \\in \\linbij{8}$ is given by\n\\begin{align*}\n    l_{\\alpha}(x, k) &\\eqdef (x \\oplus \\alpha(k), k), \\\\\n\\end{align*}\n\nThe matrix representations of $L_{in}$ and $L_{out}$ are as follows:\n\\begin{equation}\n    \\Label{eq:lin}\nL_{in} = \\matb{\n0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\\\\n1 & 1 & 1 & 0 & 1 & 1 & 1 & 1 \\\\\n1 & 0 & 0 & 0 & 1 & 0 & 1 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n},~~\nL_{out} = \\matb{\n1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\\\n1 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\\\\n1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n}.\n\\end{equation}\n\nThe final decomposition of $\\pi$ using the linear layers $L_{in}, L_{out}$ and the nonlinear components are given in \\FigRef{final}. An algorithmic representation of the decomposition is shown in Algorithm~\\Ref{alg:pimulti}.\n\n\\FigTex{final.tex}\n\n\\begin{algorithm}\n    \\caption{\\Label{alg:pimulti}\n    Computing $\\pi$: $v = \\pi(u)$ using finite field multiplications.\n    }\n    \\begin{algorithmic}[1]\n        \\State{$(x, k) \\gets L_{in}(u)$}\n        \\If{$r = 0$}\n            \\State{$x \\gets \\zeta_0(x)$}\n        \\Else\n            \\State{$x \\gets \\zeta_+(x \\fmult \\inv(k))$} \\Comment{in $\\fielde{4} \\simeq \\field{}[X]/(X^4 + X^3 + 1)$}\n        \\EndIf\n        \\State{$(x, k) \\gets (k, x)$}\n        \\State{$x \\gets \\beta(x \\fmult \\gamma(k))$} \\Comment{in $\\fielde{4} \\simeq \\field{}[X]/(X^4 + X^3 + 1)$}\n        \\State{$v \\gets L_{out}(x,k)$}\n        \\State{\\Return{$v$}}\n    \\end{algorithmic}\n\\end{algorithm}", "meta": {"hexsha": "6acc3171598c052c29972c0764ec5ef7f3e96299", "size": 2555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strKuz/12full.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/12full.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/12full.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": 36.5, "max_line_length": 224, "alphanum_fraction": 0.5307240705, "num_tokens": 1115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6163651107141419}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Statistics}\n\\label{chap:stats}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Expectation Value and Variance}\n\\label{stats:expval_and_var}\n\nThe expectation value \\cref{eq:stats:exp_relations} and variance \\cref{eq:stats:var_relations} are introductory, yet essential, statistical measures.\nTheir definitions and interesting properties are reproduced here for reference.\nNote that $s$ is the unbiased sample variance,\nand the sample mean $\\bar{x}$ has $\\mu_{\\bar{x}} = \\mu$, and standard error $\\sigma_{\\bar{x}} = \\sigma / \\sqrt{n}$,\nwhere $\\mu$ and $\\sigma$ are from the parent population.\n\n\\begin{subequations}\\label{eq:stats:exp_relations}\n\\begin{align}\n\\expvalE{X} = \\expval{X} &= \\sum_{j=1}^{m} x_{j} \\, p_{j} = \\int_{-\\infty}^{\\infty} x f\\left(x\\right) \\, \\dd{x} \\label{eq:stats:exp_relations:def} \\\\\n\\bar{x} = \\mu &= \\frac{1}{n} \\sum_{j=1}^{m} x_{j}\\,,\\,\\text{for uniform}~p_{j} \\label{eq:stats:exp_relations:mean} \\\\\n\\expval{X+Y} &= \\expval{X} + \\expval{X} \\label{eq:stats:exp_relations:add} \\\\\n\\expval{a X} &= a \\expval{X} \\label{eq:stats:exp_relations:mult} \\\\\n\\expval{a} &= a \\,\\, \\implies \\, \\expval{\\expval{X}} = \\expval{X} \\label{eq:stats:exp_relations:self} \\\\\n\\expval{X Y}^{2} &\\leq \\expval{X^{2}} \\expval{Y^{2}} \\label{eq:stats:exp_relations:cbs_ineq}\n\\end{align}\n\\end{subequations}\n\n\\begin{subequations}\\label{eq:stats:var_relations}\n\\begin{align}\n\\sigma_{X}^{2} = \\variance{X} &= \\expval{\\left(x-\\expval{x}\\right)^{2}} = \\expval{X^{2}} - \\expval{X}^{2} \\label{eq:stats:var_relations:def} \\\\\ns^{2} &= \\frac{1}{n-1} \\sum_{j=1}^{m} \\left( x_{j} - \\expval{x}\\right)^{2} \\label{eq:stats:var_relations:sample} \\\\\ns_{\\bar{x}} &= \\frac{s}{\\sqrt{n}} \\label{eq:stats:var_relations:standard_error_of_mean} \\\\\n\\variance{X+a} &= \\variance{X} \\label{eq:stats:var_relations:add} \\\\\n\\variance{a X} &= a^{2} \\, \\variance{X} \\label{eq:stats:var_relations:mult} \\\\\n\\variance{a X \\pm b Y} &= a^{2} \\, \\variance{X} + b^{2} \\, \\variance{Y} \\pm 2 \\, ab \\, \\cov{X}{Y} \\label{eq:stats:var_relations:linear} \\\\\n\\variance{X \\mid Y} &= \\expval{\\left(X - \\expval{X \\mid Y}\\right)^{2} \\mid Y} \\label{eq:stats:var_relations:conditional1} \\\\\n\\variance{X} &= \\expval{\\variance{X \\mid Y}} + \\variance{\\expval{X \\mid Y}} \\label{eq:stats:var_relations:conditional2}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Covariance and Correlation}\n\\label{stats:corr_covar}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Covariance}\n\\label{stats:corr_covar:covariance}\n\nThe covariance between two variables $u$ and $v$,\n\n\\begin{equation}\\label{eq:stats:covar}\n\\begin{split}\n\\sigma_{u,v}^{2} = \\cov{u}{v} &= \\frac{1}{m}\\sum_{j=1}^{m}\\left(u_{j}-\\expval{u}\\right)\\left(v_{j}-\\expval{v}\\right) \\\\\n&= \\expval{\\left(u-\\expval{u}\\right)\\left(v-\\expval{v}\\right)} \\\\\n&= \\expval{u v} - \\expval{u}\\expval{v}\\,,\n\\end{split}\n\\end{equation}\n\n\\noindent is a measure of their joint variability,\n\\ie a measure of any linear relationship which may exist between them.\nIt is helpful to remember the following covariance relations:\n\n\\begin{subequations}\\label{eq:stats:covar_relations}\n\\begin{align}\n\\cov{X}{X} &= \\variance{X}, \\label{eq:stats:covar_relations:var} \\\\\n\\cov{X + a}{Y + b} &= \\cov{X}{Y}, \\label{eq:stats:covar_relations:add} \\\\\n\\cov{a\\,X}{b\\,Y} &= ab\\,\\cov{X}{Y}, \\label{eq:stats:covar_relations:mult} \\\\\n\\cov{X}{Y}^{2} &\\leq \\variance{X}\\variance{Y}. \\label{eq:stats:covar_relations:inequality}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Pearson Correlation}\n\\label{stats:corr_covar:pearson}\n\nThe Pearson correlation coefficient,\n\n\\begin{equation}\\label{eq:stats:corr:pearson}\n\\rho_{u,v} = \\corr{u}{v} = \\frac{\\sigma_{u,v}^{2}}{\\sigma_{u}\\sigma_{v}} = \\frac{\\cov{u}{v}}{\\sigma_{u}\\sigma_{v}}\\,,\n\\end{equation}\n\n\\noindent is a convenient dimensionless version, normalized to $-1 \\leq \\rho \\leq 1$.\nExample distributions can be found in \\cref{fig:stats:corr_ex:pearson}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.95\\textwidth]{figures/stats/corr_ex}\n\\caption{\nExample distributions for\nuncorrelated ($\\rho \\approx 0$),\ncorrelated ($\\rho \\approx 1$),\nand anticorrelated ($\\rho \\approx -1$)\nvariables $u$ and $v$ \\cite{DougNotes}.\n}\n\\label{fig:stats:corr_ex:pearson}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Spearman Correlation}\n\\label{stats:corr_covar:spearman}\n\nThe Spearman rank correlation coefficient $r_{s}$ \\cref{eq:stats:corr:spearman} is a non-parametric measure\nused to quantify how well two variables are monotonically related,\n\\ie measure the degree of rank ordering between two variables across the available data points.\nIn contrast to the Pearson correlation coefficient,\na linear relationship between the variables is not assumed,\nonly that they increase or decrease in a consistent manner.\nThe Spearman correlation is simply the Pearson correlation of the variable's ranks,\nwhere the rank function $R\\left(x_{i}\\right)$ returns the order,\n$1, 2, 3, \\ldots, m$, of a data point $x_{i}$ after being sorted\\footnote{Ties\ncan be handled via dense ranking $1,2,2,3$, fractional ranking $1,2.5,2.5,4$, or arbitrarily broken with ordinal ranking $1,2,3,4$, \\ie row numbering.}.\nA comparison to the Pearson correlation coefficient can be found in \\cref{fig:stats:corr_ex:spearman}.\n\n\\begin{equation}\\label{eq:stats:corr:spearman}\nr_{s} = \\rho_{R\\left(u\\right),R\\left(v\\right)} = \\frac{\\cov{R\\left(u\\right)}{R\\left(v\\right)}}{\\sigma_{R\\left(u\\right)}\\sigma_{R\\left(v\\right)}}\\,.\n\\end{equation}\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[c]{0.48\\textwidth}\\centering\n    \\includegraphics[width=\\textwidth]{figures/stats/spearman_corr_non_para}\n  \\caption{Non-Parametric}\n  \\label{fig:stats:corr_ex:spearman:non_para}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[c]{0.48\\textwidth}\\centering\n    \\includegraphics[width=\\textwidth]{figures/stats/spearman_corr_outliers}\n  \\caption{Outliers}\n  \\label{fig:stats:corr_ex:spearman:outliers}\n  \\end{subfigure}\n\\caption{\nComparisons of the Spearman rank correlation and Pearson correlation coefficients,\nadapted from\n\\href{https://en.wikipedia.org/wiki/File:Spearman_fig1.svg}{Skbkekas} and\n\\href{https://en.wikipedia.org/wiki/File:Spearman_fig3.svg}{Skbkekas}.\nNote that non-parametric Spearman rank correlation\nonly measures the monotonic nature of the data, not its linearity,\nand is more resilliant to outliers.\n\\label{fig:stats:corr_ex:spearman}\n}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Covariance Matrix}\n\\label{stats:corr_covar:covar_matrix}\n\nThe covariance matrix,\n\n\\begin{align}\n  \\mathbf{M} = \\begin{pmatrix}\n    \\sigma_1^2   & \\cov{1}{2} & \\cov{1}{3} & \\ldots \\\\\n    \\cov{1}{2}   & \\sigma_2^2 & \\cov{2}{3} & \\ldots \\\\\n    \\cov{1}{3}   & \\cov{2}{3} & \\sigma_3^2 & \\ldots \\\\\n    \\vdots       & \\vdots     & \\vdots     & \\ddots\n  \\end{pmatrix}\\,,\n\\end{align}\n\n\\noindent with elements $M_{ij} = \\expval{\\left(u_{i} - \\expval{u}_{i}\\right)\\left(u_{j}-\\expval{u}_{j}\\right)}$\nis the higher dimensional extension of the covariance.\nWe can visualize the covariance between variables with\nGaussian error ellipses given by the probability distribution\n\n\\begin{equation}\\label{eq:stats:P_error_ellipse_k}\nP\\left(x_{1},x_{2},\\ldots,x_{k}\\right) = \\frac{1}{(2\\pi)^{k/2}}\\frac{1}{\\abs{\\mathbf{M}}^{1/2}}\\exp\\left[-\\frac{1}{2}\\left(\\vb{x}-\\vb*{\\mu}\\right)^{\\transpose}\\mathbf{M}\\left(\\vb{x}-\\vb*{\\mu}\\right)\\right]\\,,\n\\end{equation}\n\n\\noindent where the ellipse semi-axes are directed along the eigenvectors of $\\mathbf{M}$.\nIn two dimensions it is easier to see the equation of the error ellipse itself:\n\n\\begin{equation}\\label{eq:stats:P_error_ellipse_2}\n\\begin{split}\nP\\left(u,v\\right) &= \\frac{1}{2\\pi\\sigma_{u}\\sigma_{v}}\\frac{1}{\\sqrt{1-\\rho^{2}}}\\exp\\bigg\\{-\\frac{1}{2}\\bigg[ \\\\\n&\\frac{1}{(1-\\rho)^{2}}\\left(\\frac{\\left(u-\\expval{u}\\right)^{2}}{\\sigma_{u}^{2}}+\\frac{\\left(v-\\expval{v}\\right)^{2}}{\\sigma_{v}^{2}}-\\frac{2\\rho \\left(u-\\expval{u}\\right)\\left(v-\\expval{v}\\right)}{\\sigma_{u}\\sigma_{v}}\\right)\\bigg]\\bigg\\}\\,.\n\\end{split}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Central Limit Theorem (CLT)}\n\\label{stats:CLT}\n\nThe central limit theorem (CLT) states that\nif we take samples of size $n$ from an independent random variable multiple times,\nfrom any distribution\\footnote{Where the mean is defined, \\ie not the Cauchy or other pathological distributions.},\nthe sample means will tend to the normal distribution.\nIn practice, we typically require $\\num{30} \\lesssim n$ points per sample before we say the CLT applies.\nThe CLT is an important result in statistics as it lets us\ntreat many problems in a normally distributed framework,\nin particular finding confidence intervals for the sample mean,\nand hypothesis testing for sample means with a \\ttest or ANOVA.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bayes' Theorem}\n\\label{stats:Bayes_rule}\n\nBayes' theorem follows from the probability of the intersection of two events $A$ and $B$:\n\n\\begin{equation}\\label{eq:stats:intersection}\nP\\left(A \\cap B\\right) = P\\left(A \\mid B\\right) P\\left(B\\right) = P\\left(B \\mid A\\right) P\\left(A\\right).\n\\end{equation}\n\n\\noindent Dividing by $P\\left(B\\right)$ we have:\n\n\\begin{equation}\\label{eq:stats:Bayes_rule}\n\\begin{split}\nP\\left(A \\mid B\\right) &= \\frac{P\\left(B \\mid A\\right) P\\left(A\\right)}{P\\left(B\\right)}\\,, \\\\\n&= \\frac{P\\left(B \\mid A_{i}\\right) P\\left(A_{i}\\right)}{\\sum_{j} P\\left(B \\mid A_{j}\\right)P\\left(A_{j}\\right)}\\,, \\\\\n\\text{Posterior} &= \\frac{\\text{Likelihood} \\times \\text{Prior}}{\\text{Normalization}}\\,.\n\\end{split}\n\\end{equation}\n\n\\subsubsection{Example: Medical Testing}\n\\label{stats:Bayes_rule:medical_test}\n\nExample: Testing for disease with a \\SI{2}{\\percent} incidence rate in the wider population.\nThe test has a \\SI{99}{\\percent} true positive rate and a \\SI{5}{\\percent} false positive rate.\nWhat is the probability an individual has the disease if their test is positive?\n\n% https://www.wolframalpha.com/input/?i=(0.99*0.02)%2F((0.99*0.02)%2B(0.05*(1%E2%88%920.02)))\n\\begin{equation}\\label{eq:stats:Bayes_rule:medical_test_1}\n\\begin{split}\nP\\left(\\text{Infected} \\mid +\\right) &= \\frac{P\\left(+ \\mid \\text{Infected}\\right) P\\left(\\text{Infected}\\right)}{P\\left(+\\right)}\\,, \\\\\n &= \\frac{P\\left(+ \\mid \\text{Infected}\\right) P\\left(\\text{Infected}\\right)}{\nP\\left(+ \\mid \\text{Infected}\\right)P\\left(\\text{Infected}\\right) + P\\left(+ \\mid \\text{Healthy}\\right)P\\left(\\text{Healthy}\\right)}\\,, \\\\\n&= \\frac{\\num{0.99} \\times \\num{0.02}}{\\num{0.99} \\times \\num{0.02} + \\num{0.05} \\times \\left(1-\\num{0.02}\\right)}\\,, \\\\\n&\\approx \\num{0.288}\\,.\n\\end{split}\n\\end{equation}\n\n\\noindent And if we then run a second, independent, test which also comes back positive?\n\n% https://www.wolframalpha.com/input/?i=(0.99*0.288)%2F((0.99*0.288)%2B(0.05*(1%E2%88%920.288)))\n\\begin{equation}\\label{eq:stats:Bayes_rule:medical_test_2}\n\\begin{split}\nP\\left(\\text{Infected} \\mid ++\\right) &= \\frac{P\\left(+ \\mid \\text{Infected}\\right) P\\left(\\text{Infected} \\mid +\\right)}{\nP\\left(+ \\mid \\text{Infected}\\right)P\\left(\\text{Infected} \\mid +\\right) + P\\left(+ \\mid \\text{Healthy}\\right)P\\left(\\text{Healthy} \\mid +\\right)}\\,, \\\\\n&= \\frac{\\num{0.99} \\times \\num{0.288}}{\\num{0.99} \\times \\num{0.288} + \\num{0.05} \\times \\left(1-\\num{0.288}\\right)}\\,, \\\\\n&\\approx \\num{0.889}\\,.\n\\end{split}\n\\end{equation}\n\n\\noindent Note that if we ran both tests the first time we would still have:\n\n% https://www.wolframalpha.com/input/?i=(0.99%5E2*0.02)%2F((0.99%5E2*0.02)%2B(0.05%5E2*(1%E2%88%920.02)))\n\\begin{equation}\\label{eq:stats:Bayes_rule:medical_test_3}\n\\begin{split}\nP\\left(\\text{Infected} \\mid ++\\right) &= \\frac{P\\left(++ \\mid \\text{Infected}\\right) P\\left(\\text{Infected}\\right)}{P\\left(++\\right)}\\,, \\\\\n&= \\frac{\\num{0.99}^{2} \\times \\num{0.02}}{\\num{0.99}^{2} \\times \\num{0.02} + \\num{0.05}^{2} \\times \\left(1-\\num{0.02}\\right)}\\,, \\\\\n&\\approx \\num{0.889}\\,.\n\\end{split}\n\\end{equation}\n\n\\subsubsection{Example: Biased Coin}\n\\label{stats:Bayes_rule:biased_coin}\n\nConsider the case of a bag of $n$ fair coins and $m$ biased coins.\nLet $P\\left(H \\mid \\stcomp{F}\\right) \\equiv p_{H}$ be the \\apriori probability of heads $H$ for an biased coin $\\stcomp{F}$.\nDrawing one coin from the bag, you flip it multiple times recording $h$ heads and $t$ tails.\nWhat is the probability you have drawn an biased coin, $P\\left(\\stcomp{F} \\mid h,t\\right)$?\n\n\\begin{equation}\\label{eq:stats:Bayes_rule:biased_coin_setup}\n\\begin{gathered}\nP\\left(F\\right) = \\frac{n}{n+m}\\,,\\quad P\\left(\\stcomp{F}\\right) = \\frac{m}{n+m}\\,, \\\\\nP\\left(H \\mid F\\right) = \\frac{1}{2}\\,,\\quad P\\left(h,t \\mid F\\right) = \\left(\\frac{1}{2}\\right)^{h}\\,\\left(\\frac{1}{2}\\right)^{t} = \\frac{1}{2^{h+t}}\\,, \\\\\nP\\left(h,t \\mid \\stcomp{F}\\right) = P\\left(H \\mid \\stcomp{F}\\right)^{h} P\\left(\\stcomp{H} \\mid \\stcomp{F}\\right)^{t} = p_{H}^{h} \\left(1-p_{H}\\right)^{t}.\n\\end{gathered}\n\\end{equation}\n\n\\begin{equation}\\label{eq:stats:Bayes_rule:biased_coin_solution}\n\\begin{split}\nP\\left(\\stcomp{F} \\mid h,t\\right) &= \\frac{\nP\\left(h,t \\mid \\stcomp{F}\\right) P\\left(\\stcomp{F}\\right)}{\nP\\left(h,t \\mid \\stcomp{F}\\right) P\\left(\\stcomp{F}\\right) + P\\left(h,t \\mid F\\right) P\\left(F\\right)} \\\\\n&= \\frac{\nm\\,p_{H}^{h} \\left(1-p_{H}\\right)^{t}}{\nm\\,p_{H}^{h} \\left(1-p_{H}\\right)^{t} + n\\,2^{-h-t}}\\,.\n\\end{split}\n\\end{equation}\n\nSome example values are provided in \\cref{tab:Bayes_rule:biased_coin}.\n\n\\begin{table}[H]\n\\centering\n\\begingroup\n\\renewcommand*{\\arraystretch}{1}\n\\input{tables/coin_examples/bayes_biased_coin/bayes_biased_coin_example.tex}\n\\endgroup\n\\caption{\n$P\\left(\\stcomp{F} \\mid h,t\\right)$ for various values of $h$, $t$, and $p_{H}$ when $m = 50$, $n = 50$.\n}\n\\label{tab:Bayes_rule:biased_coin}\n\\end{table}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Coin Problems}\n\\label{stats:coin_problems}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Making an Biased Coin Fair}\n\\label{stats:coin_problems:biased_to_fair}\n% https://fivethirtyeight.com/features/can-you-make-an-unfair-coin-fair/\n% https://fivethirtyeight.com/features/can-you-snatch-defeat-from-the-jaws-of-victory/\n% https://youtu.be/-SANBbv0-Hw\n% https://math.stackexchange.com/a/146614 for additional references\n\nIf we are given an biased coin with $P\\left(H\\right) = p \\neq \\num{0.5}$\nwe can construct a fair coin\\footnote{The solution is credited to John von Neumann, who really did work on everything!} by\nflipping the biased coin $m$ times and selecting outcomes with an equal probability of occurring, while disregarding all other outcomes.\nFor example, with $m=2$ flips we have the outcomes listed in \\cref{tab:coin_problems:biased_to_fair:m2_outcomes}:\n\n\\begin{table}[H]\n\\centering\n\\begingroup\n\\renewcommand*{\\arraystretch}{1}\n\\input{tables/coin_examples/biased_to_fair/m2_outcomes.tex}\n\\endgroup\n\\caption{\nMaking an biased coin fair in $m=2$ flips.\n}\n\\label{tab:coin_problems:biased_to_fair:m2_outcomes}\n\\end{table}\n\nNote that we are disregarding $p^{2} + \\left(1-p\\right)^{2}$ percent of flips\nand this method will become increasingly inefficient as $p$ moves away from $\\num{0.5}$.\nWe can improve the efficiency by increasing $m$ and reassigning the\noutcomes\\footnote{For $m = \\num{4}$, disregard $P\\left(HHHH \\parallel TTTT\\right) = p^{4} + \\left(1-p\\right)^{4} < p^{2} + \\left(1-p\\right)^{2}$,\\newline\n$HT \\parallel HHHT \\parallel HHTT \\parallel TTHT \\to H$,\\newline\n$TH \\parallel TTTH \\parallel TTHH \\parallel HHTH \\to T = H^{-1}$.} such that\nwe decrease the average number of flips required.\nIf we need to simulate something with more outcomes, like a 6 sided die,\nwe can increase $m$ until we have enough equal outcomes, or combinations of outcomes.\n\nWe can also ask, for what values of $p$ is a fair outcome ensured in $m$ flips?\nTo solve, create $P\\left(\\text{Outcome}\\right)$ for all possible outcomes of $m$ flips.\nThen, sum all possible combinations\\footnote{Excluding the combination with all outcomes where $\\sum P\\left(\\text{Outcome}\\right) = 1$.} of $P\\left(\\text{Outcome}\\right)$\nand try to solve $\\sum P\\left(\\text{Outcome}\\right) = \\num{0.5}$.\nThis partitions the outcomes into two assignments without disregarding any outcomes, \\ie no flips are wasted.\nFor example, with $m=2$ and \\cref{tab:coin_problems:biased_to_fair:m2_outcomes}, we solve\n$p^{2}$, $p\\left(1-p\\right)$, $\\left(1-p\\right)^{2}$,\n$p^{2} + p\\left(1-p\\right)$, $p\\left(1-p\\right) + \\left(1-p\\right)^{2}$, and $p^{2} + \\left(1-p\\right)^{2} = \\num{0.5}$\nseparately for $0<p<1$.\nThe valid $p$ are then\n$p = 1/\\sqrt{2}$ with $HH \\to H$,\n$p = \\num{0.5}$ with $HH \\parallel TT \\to H$,\nand $p = 1 - 1/\\sqrt{2}$ with $TT \\to H$;\neverything else $\\to T$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Making an Fair Coin Biased}\n\\label{stats:coin_problems:fair_to_biased}\n\nIn the opposite direction, we can also make a fair coin biased\nwith $P\\left(H\\right) = p = 1/N$ by flipping it\n$m = \\text{ceil}\\left(\\log_{2}N\\right)$ times\nand reassigning the outcomes such that $H^{m} \\to H$,\n$N-1$ other outcomes $\\to T$, and we disregard any remaining $m-N$ outcomes.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Uniform Distribution}\n\\label{stats:uniform}\n\nThe uniform distribution, \\cref{eq:stats:uniform:P} and \\cref{fig:dist:uniform},\nis the simplest probability distribution\nhaving a constant probability $1/(a+b)$ over the interval $a$ to $b$.\n\n\\begin{equation}\\label{eq:stats:uniform:P}\nP\\left(x;\\,a,\\,b\\right) = \\begin{cases}\n\\frac{1}{b-a} & a \\leq x \\leq b \\,, \\\\\n0 & \\text{otherwise} \\,,\n\\end{cases}\n\\end{equation}\n\nIt is illustrative to compute the mean and variance of the uniform distribution from $P(x)$ directly:\n\n\\begin{subequations}\\label{eq:stats:uniform:mean_variance}\n\\begin{align}\n\\expval{x} &= \\int_{-\\infty}^{\\infty} x P\\left(x\\right) \\, \\dd{x} = \\frac{1}{b-a} \\int_{a}^{b} x \\, \\dd{x} = \\frac{1}{2(b-a)}\\left(b^{2} - a^{2}\\right) = \\frac{1}{2}\\left(a + b\\right)\\,, \\label{eq:stats:uniform:mean_variance:mean} \\\\\n\\variance{x} &= \\expval{x^{2}} - \\expval{x}^{2} = \\frac{1}{b-a} \\int_{a}^{b} x^{2} \\, \\dd{x} - \\expval{x}^{2} = \\cdots = \\frac{1}{12}\\left(b-a\\right)^{2}\\,. \\label{eq:stats:uniform:mean_variance:variance}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Binomial Distribution}\n\\label{stats:binomial}\n\nThe binomial distribution, \\cref{eq:stats:binomial:P} and \\cref{fig:dist:binomial},\ngives the probability of observing $k$ successes in $n$ independent Boolean trials,\nwhen $p$ is the probability of success in any one trial.\n\n\\begin{subequations}\\label{eq:stats:binomial}\n\\begin{align}\nP\\left(k;\\,n,p\\right) &= \\binom{n}{k} p^{k} \\left(1-p\\right)^{n-k}, \\label{eq:stats:binomial:P} \\\\\n\\binom{n}{k} &\\equiv \\frac{n!}{k!\\left(n-k\\right)!}\\,. \\label{eq:stats:binomial_coefficient}\n\\end{align}\n\\end{subequations}\n\n\\noindent Here \\cref{eq:stats:binomial_coefficient} is the binomial coefficient,\nrepresenting the number of unordered combinations\nwhich select $k$ elements from $n$ elements; $n$ choose $k$.\n\nThe mean and variance of the binomial distribution are:\n\n\\begin{subequations}\\label{eq:stats:binomial:mean_variance}\n\\begin{align}\n\\expval{k} &= \\sum_{k=0}^{n} k P\\left(k;\\,n,p\\right) = n p\\,, \\label{eq:stats:binomial:mean} \\\\\n\\sigma^{2} &= n p\\left(1-p\\right). \\label{eq:stats:binomial:variance}\n\\end{align}\n\\end{subequations}\n\n\\subsubsection{Bernoulli Distribution}\n\\label{stats:binomial:bernoulli}\n\nFor the special case when $n=1$, we have the Bernoulli distribution:\n\n\\begin{equation}\\label{eq:stats:bernoulli}\nP\\left(k;\\,p\\right) = p^{k} \\left(1-p\\right)^{1-k}, \\quad \\expval{k} = p\\,, \\quad \\sigma^{2} = p\\left(1-p\\right).\n\\end{equation}\n\n\\subsubsection{Negative Binomial Distribution}\n\\label{stats:binomial:negative}\n\nIf we are interested in the probability of\nobserving $k$ successes before we observe $r$ failures,\nwe can slightly modify the binomial distribution to be\nthe ``negative''\\footnote{Negative as in $\\binom{k+r-1}{k} = \\left(-1\\right)^{k} \\binom{-r}{k}$.} binomial distribution:\n\n\\begin{subequations}\\label{eq:stats:binomial:neg:P}\n\\begin{align}\nP\\left(k;\\,r,p\\right) = \\binom{k+r-1}{k} p^{k} \\left(1-p\\right)^{r}\\,,\n\\end{align}\n\\end{subequations}\n\n\\noindent where $p$ is still the probability of a success.\nNote that since we stop on the $r^{\\text{th}}$ failure,\nwe need to only arrange the $k$ successes in the first $k+r-1$ trials.\n\nThe mean and variance are then:\n\n\\begin{subequations}\\label{eq:stats:binomial:neg:mean_variance}\n\\begin{align}\n\\expval{k} &= r p / \\left(1-p\\right)\\,, \\label{eq:stats:binomial:neg:mean} \\\\\n\\sigma^{2} &= r p / \\left(1-p\\right)^{2}. \\label{eq:stats:binomial:neg:variance}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Poisson Distribution}\n\\label{stats:poisson}\n\nFor rare processes with $p \\ll 1$, and thus $\\lambda \\equiv n\\,p \\ll 1$,\nthe binomial distribution reduces\\footnote{See\none \\href{https://medium.com/@andrew.chamberlain/deriving-the-poisson-distribution-from-the-binomial-distribution-840cc1668239}{derivation here}.\nIn practice, $\\num{20} \\lesssim n$, $\\lambda = n\\,p \\lesssim \\num{10}$ is a reasonable standard.} to the\nPoisson distribution:\n\n\\begin{equation}\\label{eq:stats:poisson:P}\nP\\left(k;\\,\\lambda\\right) = \\frac{\\lambda^{k}}{k!}\\,e^{-\\lambda}\\,, \\\\\n\\end{equation}\n\n\\noindent where $\\lambda$ is the expected number of events in a given interval,\n$\\lambda = \\left(\\text{event density}\\right) \\times \\left(\\text{interval}\\right)$.\nNote that $\\lambda$ has dimensionless units of counts of events\\footnote{Although\nwe are typically considering $\\lambda$ events in a given time interval,\n$\\lambda_{\\text{Poisson}}$ is not a rate, yet!} and does not have to be an integer.\nWhen events occur independently and at a constant rate,\nwhich is low enough that no events occur simultaneously within our measurement resolution,\nthe event count per time interval will follow the Poisson distribution.\nSuch a situation is known as a Poisson process.\nA plot of the distribution can be found in \\cref{fig:dist:poisson}.\n\nInterestingly, the mean and variance of the Poisson distribution are identical and equal to $\\lambda$:\n\n\\begin{equation}\\label{eq:stats:poisson:mean_variance}\n\\expval{k} = \\sigma^{2} = \\lambda\\,.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Exponential Distribution}\n\\label{stats:exp}\n\nIf we sample the time intervals between Poisson distributed events\\footnote{Assuming the first event occurs at $T$,\n$P\\left(T > t\\right) = P_{\\text{Poisson}}\\left(k=0;\\,\\lambda_{\\text{Poisson}} \\equiv \\lambda\\,t\\right) = e^{-\\lambda t}$,\n$P\\left(t\\right) = \\dv{t} P\\left(T \\leq t\\right) = \\dv{t} 1 - e^{-\\lambda t} = \\lambda e^{-\\lambda t}$.\nHere we have used the Poisson distribution to find the CDF,\nthen differentiated to find the PDF.\n$\\lambda$ is now a rate, unlike $\\lambda_{\\text{Poisson}}$!} we\narrive at the exponential distribution,\n\n\\begin{equation}\\label{eq:stats:exp:P}\nP\\left(x;\\,\\lambda\\right) = \\begin{cases}\n\\lambda e^{-\\lambda x} & x \\geq 0 \\,, \\\\\n0 & x < 0 \\,,\n\\end{cases}\n\\end{equation}\n\n\\noindent with rate parameter $\\lambda$ events per unit $x$.\nA plot of the distribution can be found in \\cref{fig:dist:exp}.\n\nThe mean and standard deviation of the exponential distribution are identical and equal to $1/\\lambda$:\n\n\\begin{equation}\\label{eq:stats:exp:mean_variance}\n\\expval{x} = \\sigma = \\frac{1}{\\lambda}\\,, \\quad \\sigma^{2} = \\frac{1}{\\lambda^{2}}\\,.\n\\end{equation}\n\nThe exponential distribution is memoryless\\footnote{The exponential (geometric) distribution is the only real number (integer) memoryless probability distribution.} \\cref{eq:stats:exp:memoryless},\n\\ie the time until a future event occurs does not depend on the time elapsed at the present.\n\n\\begin{equation}\\label{eq:stats:exp:memoryless}\nP\\left(T > t + s \\mid T > s\\right) = P\\left(T > t\\right)\\,, \\quad \\forall s,t \\geq 0.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Example: Cars Driving By}\n\\label{stats:cars}\n\nAfter watching a patch of road,\nyou notice that on average cars are spaced \\SI{5}{\\minute} apart.\nAssume the cars are traveling independently\\footnote{Not a good assumption\nin real life as cars will clump up in traffic, \\ie become correlated.\nBetter examples include\nradioactive decay,\nphoton arrival from a distant star,\nsupport tickets being created\\ldots} of one another.\n\n\\subsubsection{Questions}\n\\label{stats:cars:questions}\n\n\\begin{enumerate}[noitemsep]\n  \\item What is $P\\left(\\text{Observing \\num{5} cars in the next \\SI{6}{\\minute}}\\right)$?\\label{item:stats:cars:1}\n  \\item If \\SI{20}{\\percent} of the cars are red, what is $P\\left(\\text{Observing \\num{5} red cars in the next \\SI{6}{\\minute}}\\right)$?\\label{item:stats:cars:2}\n  \\item What is $P\\left(\\text{Observing \\num{2} or more cars in the next \\SI{10}{\\minute}}\\right)$?\\label{item:stats:cars:3}\n  \\item \\num{100} cars have just driven by, how many are expected in the next hour?\\label{item:stats:cars:4}\n  \\item If we start watching the road at a random time, how long should we expect to wait until we see our first car?\\label{item:stats:cars:5}\n\\end{enumerate}\n\n\\subsubsection{Solutions}\n\\label{stats:cars:solutions}\n\n\\begin{itemize}[noitemsep]\n  % https://www.wolframalpha.com/input/?i=%281.2%5E5+%2F+5%21%29*e%5E-1.2\n  \\item[\\cref{item:stats:cars:1}.] $k = 5$, $\\lambda = \\frac{1\\,\\text{car observed}}{\\SI{5}{\\minute}} \\times \\SI{6}{\\minute} = \\num{1.2}$, $P_{\\text{Poisson}} = \\frac{\\num{1.2}^{5}}{5!} e^{-1.2} = \\num{0.006}$.\n  % https://www.wolframalpha.com/input/?i=%280.24%5E5+%2F+5%21%29*e%5E-0.24\n  \\item[\\cref{item:stats:cars:2}.] $\\lambda = \\frac{\\num{0.2} \\times 1\\,\\text{car observed}}{\\SI{5}{\\minute}} \\times \\SI{6}{\\minute} = \\num{0.24}$, $P_{\\text{Poisson}} = \\num{5.2e-6}$.\n  % https://www.wolframalpha.com/input/?i=1+-+3e%5E-2\n  \\item[\\cref{item:stats:cars:3}.] $\\lambda = \\frac{1}{\\SI{5}{\\minute}} \\times \\SI{10}{\\minute} = \\num{2}$, $P\\left(2 \\leq k \\right) = 1 - P_{\\text{Poisson}}\\left(k < 2 \\right) = 1 - \\left( \\frac{2^{0}}{0!} e^{-2} + \\frac{2^{1}}{1!} e^{-2}\\right) \\newline = 1 - 3 e^{-2} = \\num{0.6}$.\n  \\item[\\cref{item:stats:cars:4}.] The cars are independent, so the prior $k$ cars are irrelevant -- gambler's fallacy. $\\expval{k} = \\lambda = \\frac{1}{\\SI{5}{\\minute}} \\times \\SI{60}{\\minute} = \\num{12}$.\n  \\item[\\cref{item:stats:cars:5}.] We can use the exponential distribution with $\\lambda_{\\text{Exp}} = \\frac{1}{\\SI{5}{\\minute}}$, $\\expval{t} = \\frac{1}{\\lambda} = \\SI{5}{\\minute}$,\\newline as one would expect\\ldots\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Gaussian Distribution}\n\\label{stats:gaus}\n\nIn the other direction, for common processes $\\mu \\equiv n\\,p \\gg 1$,\nthe binomial distribution becomes\\footnote{See\none \\href{http://scipp.ucsc.edu/~haber/ph116C/NormalApprox.pdf}{derivation here}.} the\nwell-known Gaussian, or normal, distribution,\n\n\\begin{equation}\\label{eq:stats:gaus:P}\nP\\left(x;\\,\\mu,\\sigma\\right) = \\frac{1}{\\sqrt{2\\pi}\\,\\sigma} \\exp\\left( -\\frac{1}{2} \\left(\\frac{x-\\mu}{\\sigma}\\right)^{2} \\right)\\,,\n\\end{equation}\n\n\\noindent with mean $\\mu$ and variance $\\sigma^{2}$.\nA plot of the distribution can be found in \\cref{fig:dist:gaus}.\n\nIt is helpful to remember that\n\n\\begin{equation}\\label{eq:stats:gaus:sigmas}\n\\begin{split}\n\\mu \\pm 1\\sigma &\\approx \\SI{68}{\\percent}\\,, \\\\\n\\mu \\pm 2\\sigma &\\approx \\SI{95}{\\percent}\\,, \\\\\n\\mu \\pm 3\\sigma &\\approx \\SI{99}{\\percent}\\,,\n\\end{split}\n\\end{equation}\n\n\\noindent while the full width at half maximum (FWHM) $\\Gamma = 2\\sqrt{2 \\ln{2}}\\,\\sigma \\approx \\num{2.355} \\sigma$.\nNote that the standard normal distribution has $\\mu = 0$ and $\\sigma =1$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Student's \\texorpdfstring{$t$}{t}-Distribution}\n\\label{stats:t_dist}\n\nIf we take a sample of size $m$ from a normal distribution\nwe arrive at Student's \\tdist.\nLetting $\\nu = m-1$ be the number of degrees of freedom,\nStudent's \\tdist has the form:\n\n\\begin{equation}\\label{eq:stats:t_dist:P}\nP\\left(t;\\,\\nu\\right) = \\frac{\n\\Gamma\\left(\\frac{\\nu+1}{2}\\right)\n}{\n\\sqrt{\\nu \\pi}\\,\\Gamma\\left(\\frac{\\nu}{2}\\right)\n} \\left(1+\\frac{t^{2}}{\\nu}\\right)^{-\\frac{\\nu+1}{2}}\\,,\n\\end{equation}\n\n\\noindent where $\\Gamma\\left(z\\right)$ is the gamma function\\footnote{$\\Gamma\\left(z\\right) = \\int_{0}^{\\infty} x^{z-1} e^{-x} \\, \\dd{x}$,\nwhich simplifies to $\\Gamma\\left(n\\right)=\\left(n-1\\right)!$ for integer $n$.}.\nThe distribution, \\cref{fig:dist:student_t}, has a mean of \\num{0} for $\\nu > 1$,\nand variance of $\\infty$ for $\\nu =2$ and $\\nu / \\left(\\nu-2\\right)$ for $\\nu > 2$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{\\texorpdfstring{$\\chi^{2}$-Distribution}{Chi-Squared Distribution}}\n\\label{stats:chi2_dist}\n\nThe \\chiSqdist with $\\nu$ degrees of freedom,\n\\cref{eq:stats:chi2_dist:P} and \\cref{fig:dist:chi2},\nis created by summing the squares of $\\nu$ independent standard normal random variables.\nIt therefore has a mean of $\\nu$ and variance of $2\\nu$, and is\nprimary useful for conducting {\\chiSqtest}s.\n\n\\begin{equation}\\label{eq:stats:chi2_dist:P}\nP\\left(x;\\,\\nu\\right) = \\frac{\nx^{\\frac{\\nu}{2} - 1} e^{-\\frac{x}{2}}\n}{\n2^{\\frac{\\nu}{2}} \\Gamma\\left(\\frac{\\nu}{2}\\right)}.\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{\\texorpdfstring{$F$}{F}-Distribution}\n\\label{stats:F_dist}\n\nThe \\Fdist with degrees of freedom $d_{1}$ and $d_{2}$,\n\\cref{eq:stats:F_dist:X,eq:stats:F_dist:P} and \\cref{fig:dist:F},\nis formed by dividing two $\\chi^{2}$-distributed random variables\n$S_{1}$ and $S_{2}$ with their respective degrees of freedom:\n\n\\begin{subequations}\\label{eq:stats:F_dist}\n\\begin{align}\nX_{\\Fdist} &= \\frac{S_{1}/d_{1}}{S_{2}/d_{2}}, \\label{eq:stats:F_dist:X} \\\\\nP\\left(x;\\,d_{1},d_{2}\\right) &= \\frac{1}{x B\\left(d_{1}/2, d_{2}/2\\right)} \\sqrt{\\frac{\\left(d_{1} x\\right)^{d_{1}} d_{2}^{d_{2}}}{\\left(d_{1} x + d_{2}\\right)^{d_{1}+d_{2}}}}, \\label{eq:stats:F_dist:P}\n\\end{align}\n\\end{subequations}\n\n\\noindent where $B\\left(x,y\\right)$ is the beta function\\footnote{$B\\left(x,y\\right) = \\int_{0}^{1} t^{x-1} \\left(1-t\\right)^{y-1} \\, \\dd{t} = \\Gamma\\left(x\\right)\\Gamma\\left(y\\right) / \\Gamma\\left(x+y\\right)$.}.\n\nThe \\Fdist has a complicated\nmean and variance\\footnote{Mean: $d_{2}/\\left(d_{2}-2\\right)$ for $2 < d_{2}$.\nVariance: $2 d_{2}^{2}\\left(d_{1}+d_{2}-2\\right)/\\left(d_{1}\\left(d_{2}-2\\right)^{2}\\left(d_{2}-4\\right)\\right)$ for $4 < d_{2}$.},\nand is primary useful for conducting {\\Ftest}s such as ANOVA.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Geometric Distribution}\n\\label{stats:geo_dist}\n\nThe geometric distribution gives the probability of\nrequiring $k$ independent Boolean trials to observe one success\\footnote{With the success occurring in trial $k$.},\n\\cref{eq:stats:geo:P_trials} and \\cref{fig:dist:geometric_trials},\nor the probability of observing $k$ failed trials before the first success,\n\\cref{eq:stats:geo:P_failures} and \\cref{fig:dist:geometric_failures}.\nAs usual $p$ is the probability of success for any single trial.\nNote that $k$ is indexed differently depending on the framing of the problem.\n\n\\begin{subequations}\\label{eq:stats:geo}\n\\begin{align}\nP_{\\text{Trials}}\\left(k;\\,p\\right) &= \\left(1-p\\right)^{k-1}\\,p,\\quad k \\in \\left\\{1,2,3,\\ldots\\right\\}, \\label{eq:stats:geo:P_trials} \\\\\nP_{\\text{Failures}}\\left(k;\\,p\\right) &= \\left(1-p\\right)^{k}\\,p,\\quad k \\in \\left\\{0, 1,2,3,\\ldots\\right\\}. \\label{eq:stats:geo:P_failures}\n\\end{align}\n\\end{subequations}\n\nThe mean and standard deviation of the geometric distribution are:\n\n\\begin{subequations}\\label{eq:stats:geo_dist:mean_variance}\n\\begin{gather}\n\\expval{k}_{\\text{Trials}} = \\frac{1}{p}\\,, \\quad \\expval{k}_{\\text{Failures}} = \\frac{1-p}{p}\\,, \\label{eq:stats:geo_dist:mean} \\\\\n\\sigma^{2} = \\frac{1-p}{p^{2}}\\,. \\label{eq:stats:geo_dist:variance}\n\\end{gather}\n\\end{subequations}\n\nLike the exponential distribution, its continuous analogue, the geometric distribution is memoryless \\cref{eq:stats:exp:memoryless}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Hypergeometric Distribution}\n\\label{stats:hypergeo_dist}\n\nThe hypergeometric distribution, \\cref{eq:stats:hypergeometric:P} and \\cref{fig:dist:hypergeometric},\ngives the probability of obtaining $k$ ``successes'' in $n$ draws, {\\em without replacement},\nfrom a population of size $N$ which contains $K$ successes.\nOne example is getting $k$ red balls, \\ie successes,\nout of $n$ draws from a bag of $K$ red and $N-K$ white balls.\n\n\\begin{equation}\\label{eq:stats:hypergeometric:P}\nP\\left(k;\\,N,K,n\\right) = \\frac{\\binom{K}{k}\\binom{N-K}{n-k}}{\\binom{N}{n}}\\,.\n\\end{equation}\n\nThe mean and standard deviation of the hypergeometric distribution are:\n\n\\begin{subequations}\\label{eq:stats:hypergeometric:neg:mean_variance}\n\\begin{gather}\n\\expval{k} = n K / N = n p, \\label{eq:stats:hypergeometric:mean} \\\\\n\\sigma^{2} = n \\frac{K}{N} \\frac{N-K}{N} \\frac{N-n}{N-1} = n p \\left(1-p\\right) \\frac{N-n}{N-1}\\,. \\label{eq:stats:hypergeometric:variance}\n\\end{gather}\n\\end{subequations}\n\nThe hypergeometric distribution should not be confused with the geometric distribution,\nand is far more similar to the binomial distribution where $p = K/N$ and we draw with replacement.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Kurtosis and Skewness}\n\\label{stats:kurtosis_skewness}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Confidence Intervals}\n\\label{stats:CI}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hoeffding's Inequality}\n\\label{stats:CI:hoeffding}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Outliers}\n\\label{stats:outliers}\n% TODO\n% interquartile range (IQR)\n\n\\begin{equation}\\label{eq:stats:outlier_IQR_def}\n\\expval{x} \\pm \\num{1.5}\\, \\text{IQR}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bootstrapping}\n\\label{stats:bootstrapping}\n\nThe bootstrap method can be a great solution when presented with difficult problems\naround measuring uncertainties or even conducting hypothesis tests.\nWith bootstrapping we can estimate the uncertainty on any well defined quantity,\neven when the uncertainty itself does not have an explicit expression,\n\\eg finding the confidence intervals for the median\nor coefficient of determination $R^{2}$ of linear regression.\n\nWe begin with an original sample of size $n$ drawn from the larger population,\nand generate $1 \\ll m$ bootstrap samples by resampling $n$ points from the sample with replacement,\nas illustrated in \\cref{fig:bootstrapping}.\nThe statistic of interest is computed on each of the bootstrapped samples\nbefore being combined into an overall distribution.\nAssuming the original population is independent and identically distributed (\\iid)\\footnote{Note\nthat the \\iid assumption is less stringent than\nthe usual assumption of normality via the central limit theorem (CLT) of \\cref{stats:CLT},\nallowing bootstrapping to be used in cases were $n$ may be to small for other methods.},\nthe resulting bootstrapped distribution will approximate the true sampling distribution\nand we can use it to estimate the uncertainty on the statistic.\nThe \\SI{95}{\\percent} confidence interval of the statistic in question\ncan be found by simply\\footnote{There are\nmore advanced methods for determining the confidence interval not covered here,\nparticularly for asymmetric distributions.} identifying\nthe boundaries of the central \\SI{95}{\\percent} of bootstrapped sample values.\nLikewise, the standard error of the statistic is the standard deviation of the bootstrapped distribution.\n\nIf the bootstrapped distribution is not symmetrical,\nwhich may be the case when working with measures of variance like the standard deviation,\nthe bootstrapped result may be biased.\nIn these cases, one potential correction is to shift the bootstrapped distribution\nsuch that the original sample statistic and mean of the bootstrapped distribution agree.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.7\\textwidth]{figures/stats/bootstrapping.jpeg}\n\\caption{\nIllustration of the bootstrapping method\nby \\href{https://towardsdatascience.com/bootstrapping-statistics-what-it-is-and-why-its-used-e2fa29577307}{Trist'n Joseph}.\nNote that the $m$ resamples are done with replacement.\nThe final bootstrapped distribution is built by measuring the statistic in question on all of the bootstrapped samples,\nand can be used to estimate the statistic's uncertainty.\n}\n\\label{fig:bootstrapping}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hypothesis Testing}\n\\label{stats:bootstrapping:hypo}\n\nAs we can construct confidence intervals, bootstrapping can also be used for hypothesis testing.\nN{a\\\"i}vely we can test the null hypothesis by checking if the value in question,\ntypically \\num{0}, lands within the confidence interval or not.\nWe can also estimate the \\pvalue of a parameter by shifting the original sample distribution such that\nit satisfies the null hypothesis, \\eg shift all the data points by $\\delta$ such that the sample has $\\expval{x} = \\num{0}$.\nWe then bootstrap the shifted sample to produce the bootstrapped distribution as normal.\nThe \\pvalue is then the proportion of the bootstrapped distribution\nwith values differing from the null hypothesis by the observed difference or more,\n\\eg $P\\left(\\delta \\leq \\abs{x}\\right)$ in the prior example.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Poisson Bootstrapping}\n\\label{stats:bootstrapping:poisson}\n\nFor large sample sizes $n$, instead of drawing $m$ bootstrap samples with replacement,\nwhich can be computationally expensive,\nwe can use the single sample,\nbut give each data point a weight $w$ drawn\nfrom the Poisson distribution with $\\lambda = 1$.\nThe set of weights is then generated $m$ times.\nFormally, the methods are equivalent as for large $n$\nthe binomial probability of including a given data point approaches the Poisson probability with $\\lambda = 1$.\nPoisson Bootstrapping is commonly used in particle physics,\nin particular see the direct balance $\\gamma\\text{+Jet}$ calibration\nin the dissertation \\cite{mepland_dissertation}, Appendix E.1.4.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bayesian Statistics}\n\\label{stats:Bayes}\n% TODO\n\n% \\cref{stats:Bayes_rule}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Bayesian Conjugate Prior}\n\\label{stats:Bayes:conjugate_prior}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Bayes Estimator}\n\\label{stats:Bayes:estimator}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Approximate Bayesian Computation (ABC)}\n\\label{stats:Bayes:ABC}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bias of a Predictor}\n\\label{stats:bias}\n% TODO\n\n\\begin{equation}\\label{eq:stats:bias}\n\\bias{\\hat{f}\\left(x\\right)} = \\expval{\\hat{f}\\left(x\\right)} - f\\left(x\\right)\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Kullback-Leibler Divergence}\n\\label{stats:kld}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Causal Inference}\n\\label{stats:causal_inference}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Markov Chains}\n\\label{misc:markov_chains}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Markov Chain Monte Carlo (MCMC)}\n\\label{misc:MCMC}\n% TODO\n\n% Markov Chain Monte Carlo (MCMC) is a Monte Carlo (MC) method\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{\\pymcThree}% would rather have the \\textsc caps than italics\n\\label{misc:MCMC:PyMC3}\n% TODO\n% TODO \\pymcThree\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Sampling from Probability Distributions}\n\\label{misc:sampling_prob_dist}\n\nMost programming languages have built-in functions to generate\npseudo-random numbers from common probability distributions,\nsuch as the Poisson \\cref{eq:stats:poisson:P} or Gaussian \\cref{eq:stats:gaus:P} distributions.\nHowever, in some cases we may wish to sample from an unsupported esoteric function.\nIn these situations we can turn to inverse transform sampling and rejection sampling,\nto give just two examples from many possible computational methods,\nto construct the desired distribution from an existing random number generator.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Inverse Transform Sampling}\n\\label{misc:sampling_prob_dist:inverse}\n% https://www.youtube.com/watch?v=9ixzzPQWuAY\n\nIf we know the explicit form of the target probability density function (PDF), $X = P\\left(x\\right)$,\ncan integrate it to find the cumulative distribution function (CDF), $F_{X}\\left(x\\right) = \\int_{-\\infty}^{x} P\\left(t\\right) \\, \\dd{t}$,\nand furthermore can invert the CDF\\footnote{The inverse CDF\nis known as the percent point function, \\texttt{ppf},\nin \\href{https://docs.scipy.org/doc/scipy/reference/stats.html}{\\scipy}.}, $F^{-1}_{X}\\left(u\\right)$ for $0 \\leq u \\leq 1$,\nwe can explicitly transform the uniform distribution $U\\left(x\\right)$ into $P\\left(x\\right)$ as:\n\n\\begin{equation}\\label{eq:stats:sampling_prob_dist:inverse}\nF^{-1}_{X}\\left(U\\right) = P\\left(x\\right) = X\\,.\n\\end{equation}\n\nTo prove the method, assuming that $F^{-1}_{X}$ exists, we can do:\n\n\\begin{subequations}\\label{eq:stats:sampling_prob_dist:inverse_proof}\n\\begin{align}\nP\\left(F^{-1}_{X}\\left(U\\right) \\leq x\\right) &= P\\left(U \\leq F_{X}\\left(x\\right) \\right) \\label{eq:stats:sampling_prob_dist:inverse_proof:inverse} \\\\\n&= F_{X}\\left(x\\right)\\,,\\label{eq:stats:sampling_prob_dist:inverse_proof:def} \\\\\nP\\left(U \\leq y\\right) &= y\\,, \\label{eq:stats:sampling_prob_dist:inverse_proof:U}\n\\end{align}\n\\end{subequations}\n\n\\noindent where in \\cref{eq:stats:sampling_prob_dist:inverse_proof:inverse} we have applied $F$ to both sides of the inner inequality,\nand in \\cref{eq:stats:sampling_prob_dist:inverse_proof:def} we have used the definition of the uniform distribution \\cref{eq:stats:sampling_prob_dist:inverse_proof:U}.\nAs $P\\left(F^{-1}_{X}\\left(U\\right) \\leq x\\right) = F_{X}\\left(x\\right) = P\\left(X \\leq x\\right)$\nwe can compare terms and see \\cref{eq:stats:sampling_prob_dist:inverse}.\n\nThe inverse sampling method can be seen graphically \\cref{fig:stats:sampling_prob_dist:inverse} being used to generate the normal distribution.\n\n%\\begin{figure}\n%\\centering\n%\\includegraphics[width=0.7\\textwidth]{figures/stats/inverse_transform_sampling_normal_dist}\n%\\caption{\n%Example application of the inverse sampling method to generate the normal distribution, adapted from \\href{https://en.wikipedia.org/wiki/File:Inverse_transform_sampling.png}{Olivier Ricou}.\n%}\n%\\label{fig:stats:sampling_prob_dist:inverse}\n%\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Rejection Sampling}\n\\label{misc:sampling_prob_dist:reject}\n% https://www.youtube.com/watch?v=OXDqjdVVePY\n\nWhile inverse transform sampling is a computationally efficient method\nits assumptions will not be met by all interesting PDFs,\nin particular if we do not have an explicit, invertible CDF.\nIn these cases we can turn to rejection sampling instead,\nwhich can handle more general PDFs at the cost of a lower computational efficiency.\n\nIn rejection sampling, we assume we know the PDF of the random variable to be sampled from,\nup to a normalization constant $A$ \\cref{eq:stats:sampling_prob_dist:reject:X}.\nWe then choose a different PDF, $g\\left(x\\right)$ which is easy for us to sample from.\nAny $g\\left(x\\right)$ covering the range of $x$ will do,\nbut the method is more efficient the closer we can get $g\\left(x\\right)$ to match $f\\left(x\\right)$.\n$g\\left(x\\right)$ is then scaled by a known constant $M$\nsuch that it is always larger than $f\\left(x\\right)$ \\cref{eq:stats:sampling_prob_dist:reject:f_condition}\nas illustrated in \\cref{fig:stats:sampling_prob_dist:reject}.\nFinally, we sample random $x$ values from $g\\left(x\\right)$ and accept them with probability \\cref{eq:stats:sampling_prob_dist:reject:P_accept}.\nThe accepted $x$ values will have the same distribution as $X$.\n\n\\begin{subequations}\\label{eq:stats:sampling_prob_dist:reject}\n\\begin{align}\nX = P\\left(x\\right) &= \\frac{1}{A} f\\left(x\\right), \\label{eq:stats:sampling_prob_dist:reject:X} \\\\\n\\forall x, \\quad f\\left(x\\right) & \\leq M g\\left(x\\right), \\label{eq:stats:sampling_prob_dist:reject:f_condition} \\\\\nP\\left(\\text{Accept} \\mid x\\right) &= \\frac{f\\left(x\\right)}{M g\\left(x\\right)}\\,. \\label{eq:stats:sampling_prob_dist:reject:P_accept}\n\\end{align}\n\\end{subequations}\n\n\\begin{figure}[H]\n  \\centering\n  \\savebox{\\largestimage}{\n    \\includegraphics[width=0.47\\textwidth,trim={3.0cm 0.5cm 3.0cm 0.1cm},clip]{figures/stats/inverse_transform_sampling_normal_dist}% trim={<left> <lower> <right> <upper>}\n  }% Store largest image in a box\n\n  \\begin{subfigure}[b]{0.48\\textwidth}\\centering\n    \\usebox{\\largestimage}\n    \\vspace{0.01cm}\n  \\caption{Inverse Sampling}\n  \\label{fig:stats:sampling_prob_dist:inverse}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[b]{\\wd\\largestimage}\\centering\n    \\raisebox{\\dimexpr.5\\ht\\largestimage-.5\\height}{% Adjust vertical height of smaller image\n      \\includegraphics[width=\\textwidth]{figures/stats/rejection_sampling}}\n  \\caption{Rejection Sampling}\n  \\label{fig:stats:sampling_prob_dist:reject}\n  \\end{subfigure}\n\\caption{\nIllustrations of the inverse sampling and rejection sampling methods, adapted from \\href{https://en.wikipedia.org/wiki/File:Inverse_transform_sampling.png}{Olivier Ricou} and \\href{https://www.data-blogger.com/2016/01/24/the-mathematics-behind-rejection-sampling/}{Kevin Jacobs}.\n  \\label{fig:stats:sampling_prob_distr}\n}\n\\end{figure}\n\nFor a proof of why the rejection sampling method works see \\cref{eq:stats:sampling_prob_dist:reject:proof} below\nwhich hinges on Bayes' Theorem from \\cref{stats:Bayes_rule} in \\cref{eq:stats:sampling_prob_dist:reject:proof:x_given_Accept}\nalong with other basic definitions from probability theory.\n\n\\begin{subequations}\\label{eq:stats:sampling_prob_dist:reject:proof}\n\\begin{align}\nP\\left(x \\mid \\text{Accept}\\right) &= \\frac{P\\left(\\text{Accept} \\mid x\\right) P\\left(x\\right)}{P\\left(\\text{Accept}\\right)} = \\frac{1}{P\\left(\\text{Accept}\\right)} \\frac{f\\left(x\\right)}{M \\cancel{g\\left(x\\right)}} \\cancel{g\\left(x\\right)}, \\label{eq:stats:sampling_prob_dist:reject:proof:x_given_Accept} \\\\\nP\\left(\\text{Accept}\\right) &= \\int_{-\\infty}^{\\infty} P\\left(\\text{Accept} \\mid x\\right) g\\left(x\\right) \\, \\dd{x} \\label{eq:stats:sampling_prob_dist:reject:proof:P_Accept1} \\\\\n&= \\int_{-\\infty}^{\\infty} \\frac{f\\left(x\\right)}{M g\\left(x\\right)} g\\left(x\\right) \\, \\dd{x} = \\frac{1}{M} \\int_{-\\infty}^{\\infty} f\\left(x\\right) \\, \\dd{x} = \\frac{A}{M}, \\label{eq:stats:sampling_prob_dist:reject:proof:P_Accept2} \\\\\n\\implies P\\left(x \\mid \\text{Accept}\\right) &= \\frac{f\\left(x\\right)/M}{A/M} = \\frac{1}{A} f\\left(x\\right) = P\\left(x\\right) = X. \\label{eq:stats:sampling_prob_dist:reject:proof:conclusion}\n\\end{align}\n\\end{subequations}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Metropolis-Hastings Algorithm}\n\\label{misc:sampling_prob_dist:metropolis_hastings}\n% TODO\n", "meta": {"hexsha": "192560dc569c9f6a5ef61877df3b809b729e9fe6", "size": 49115, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/stats.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/stats.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/stats.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": 48.5806132542, "max_line_length": 308, "alphanum_fraction": 0.6589840171, "num_tokens": 15098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484144, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.6163650978564735}}
{"text": "\\section{Hierarchical Information Content}\n\\label{sec:hic}\n\nWe construct a measure for the structural complexity of a system. As motivated\nin section~\\ref{sec:finding_complexity}, we want the complexity to grow at\nthe compositions of ordered and disordered subsystems in a hierarchical\nstructure. We construct the overall complexity from the sum of the complexity at\neach composition.\n\nAssume we are given a hierarchical system with $L$ levels. We construct the\nglobal system complexity from the local complexity computed at each of the\n$L-1$ compositions between consecutive levels. The local complexity measures\nare given by the difference in mutual information of the system at level\n$\\ell$ and that of the subsystem at level $\\ell - 1$. We denote by $X^{\\ell}$ the\nstate variable at the $\\ell$-th level of the hierarchy. Following\n\\citet{simon1991architecture}, we define the span of a level as the\nnumber of elements from the $\\ell - 1$ subsystem used to construct the state\n$X^\\ell$. For now we assume the span to be constant with a value of two for\nevery level. We later generalize to larger spans.\n\nAs an example, the state variable $X^\\ell$ could be a molecule in an artificial\nchemistry constructed from two atoms. Alternatively, $X^{\\ell}$ could be an $n\n\\times n$ state of a cellular automata constructed from two $(\\nicefrac{n}{2})\n\\times n$ sub-states. As an example from nature, $X^{\\ell}$ could be a string\nof $2^\\ell$ base pairs of DNA constructed from two substrings of length $2^{\\ell\n- 1}$.\n\nThe complexity at the $\\ell$-th composition is computed from the squared\ndifference of the mutual information of the span between level $\\ell$ and level\n$\\ell + 1$:\n\\begin{equation}\n    C_\\ell = \\left[ I(X^{\\ell + 1}; Y^{\\ell + 1}) - I(X^{\\ell}; Y^{\\ell}) \\right]^2\n\\end{equation}\nThe mutual information can be computed from the Shannon entropy and conditional\nentropy when $X^\\ell$ is discrete or the differential entropy when $X^\\ell$ is\ncontinuous~\\citep{cover1999elements}:\n\\begin{equation}\n\\label{eq:mutual_information}\nI(X^\\ell; Y^\\ell) = H(X^\\ell) - H(X^\\ell \\mid Y^\\ell).\n\\end{equation}\nThe mutual information is large when the $\\ell$-th level is highly ordered and\nsmall when it is highly disordered. Hence, the values $C_\\ell$ will be large\nexactly at the transition points between order and disorder (or vice-versa).  We\nuse the level complexities $C_\\ell$ to construct the overall system complexity.\n\n\\begin{definition}[Hierarchical Information Content]\n\\label{def:hic}\n  The Hierarchical Information Content (HIC) of a hierarchical system $S$ with\n  $L$ levels is given by:\n  \\begin{equation}\n    \\label{eq:hic}\n    \\hic(S) = \\sum_{l=1}^{L-1} C_\\ell = \\sum_{l=1}^{L-1} \\left[ I(X^{\\ell+1}; Y^{\\ell+1}) - I(X^\\ell; Y^\\ell) \\right]^2.\n  \\end{equation}\n\\end{definition}\n\n\\paragraph{Generalizing to larger spans:} Using a larger span requires\ngeneralizing the mutual information to multiple variables. The interaction\ninformation is one such generalization~\\citep{mcgill1954multivariate}. The\ninteraction information of a set of variables is defined recursively as:\n\\begin{equation}\n    \\label{eq:interaction_information}\n    I(X_1^\\ell; \\ldots; X_{n+1}^\\ell) = I(X_1^\\ell; \\ldots; X_n^\\ell) - I(X_1^\\ell; \\ldots; X_n^\\ell \\mid X_{n+1}^\\ell),\n\\end{equation}\nwhere the conditional mutual information is given by:\n\\begin{equation}\n    \\label{eq:conditional_mutual_information}\n    I(X; Y \\mid Z) = \\sum_{Z} P(Z) I(X; Y).\n\\end{equation}\n\n\\paragraph{Estimating information criteria:} Computing the mutual information\nin equation~\\ref{eq:mutual_information} requires computing the entropy of the\nstate variables $H(X^\\ell)$ and the conditional entropy $H(X^\\ell \\mid\nY^\\ell)$. Estimating these quantities directly requires models for the\ndistributions $P(X^\\ell)$ and $P(X^\\ell \\mid Y^\\ell)$. For state variables with\na small domain these distributions can likely be estimated efficiently from\ncounts. However, for larger state variables sample efficiency becomes an issue.\nIn these cases more sophisticated density estimation techniques should be used.\nSuitable techniques can be found in most modern statistical learning or machine\nlearning texts (see for example \\citet{friedman2001elements}).\n\n\\paragraph{Specifying the hierarchy:} In some cases, the hierarchical structure\nof the system may be self-evident. This might be the case if the system has a\nnatural tree-like structure. However, in the general case, both the boundaries\nbetween levels and the sub-modules which make up the state at the next level up\nmust be specified. This is introduces a degree subjectivity to the HIC which\neffects its ability to faithfully capture the complexity of the system.\n\nAs an example consider measuring the HIC of a sequence of DNA. We might define\nthe state $X^\\ell$ to be a subsequence of $2^\\ell$ nucleotides. On the other\nhand there may be some natural structure in the DNA to take advantage of. For\nexample, codons are sequences of three nucleotides which each code for a\nspecific amino acid.  These would make a good definition for a state variable.\n\n\\subsection{Examples}\n\nWe attempt to build intuition for the definition of HIC through some simple\nexamples.\n\n\\begin{example}\n  \\label{ex:constant}\n  As a first example, consider the state $S = [0, 0, \\ldots, 0]$,\n  a constant sequence of all $0$s. At any level for any neighborhood, the mutual\n  information $I(X^\\ell; Y^\\ell) = 0$. Hence the terms $C_\\ell = 0$ for all\n  $\\ell$ and the overall $\\hic(S) = 0$.\n\\end{example}\n\n\\begin{example}\n  \\label{ex:uniform}\n  Let $S = [x_1, x_2, \\ldots]$ consist of a sequence of independent draws from a\n  multinomial uniform distribution over $K$ categories. Assuming a span of $2$,\n  the variable $X^\\ell$ consists of $2^\\ell$ of the $x_i$ primitives and hence\n    can take on any of $K^{(2^\\ell)}$ values. Consider the mutual information of level\n  $\\ell$:\n  \\begin{equation}\n    I(X^\\ell; Y^\\ell) = H(X^\\ell) - H(X^\\ell \\mid Y^{\\ell}) = 2^\\ell \\log K - 2^\\ell \\log K = 0\n  \\end{equation}\n  Hence all of the $C_\\ell = 0$ and $\\hic(S) = 0$.\n\\end{example}\n\nAs examples~\\ref{ex:constant} and \\ref{ex:uniform} show, the HIC behaves as\nexpected when the system exhibits complete order or complete disorder. In both\nof these examples the HIC was zero because the mutual information at each level\nwas zero. In the following example, we see slightly more interesting behavior,\nwhere the mutual information at each level is nonzero, but the resulting HIC\nis.\n\n\\begin{example}\n  \\label{ex:repeats}\n  Let $S = [0, 1, 0, 1, \\ldots]$ consist of a sequence of alternating zeros and\n  ones.\n\n  The first level $X^1$ takes on the two values $\\{0, 1\\}$ with equal\n  probability hence $H(X^1) = \\log 2$. However given the neighbor $Y^1$ the\n  value of $X^1$ is deterministic and hence $H(X^1 \\mid Y^1) = 0$. Thus the\n  overall mutual information is $I(X^1; Y^1) = \\log 2$.\n\n  The second level $X^2$ takes on two values $\\{[0, 1], [1, 0]\\}$ with\n  equal probability, and we have $H(X^2) = \\log 2$. Again $X^2$ is fully\n  determined by $Y^2$ thus $H(X^2 \\mid Y^2) = 0$ and $I(X^2, Y^2) = \\log 2$.\n  Combining these to produce $C^2$ yields:\n  \\begin{equation}\n    C_2 = (I(X^2; Y^2) - I(X^1; Y^1))^2 = (\\log 2 - \\log 2)^2 = 0.\n  \\end{equation}\n  The above argument generalizes to all levels of the hierarchy so $\\hic(S) = 0$.\n\\end{example}\n\nIn example \\ref{ex:repeats} we used overlapping windows to construct $X^2$. If\nwe had chosen disjoint windows the HIC would be small but nonzero. Depending on\nthe problem this may be desirable in that the alternating sequence should be\nconsidered slightly more complex than a constant sequence. This is where\nsubjectiveness comes in. The designer should select from these choices\nbased on the setting at hand.\n\n\\subsection{Comparison to Statistical Complexity}\n\\label{statistical_complexity}\n\nThe statistical complexity of \\citet{crutchfield1989inferring} measures the\ncomplexity of a system by observing the number of distinct future distributions\ngiven the present and past states.  Statistical complexity infers a set of\n``causal states'' by collapsing the state variables representing the current\nand past time into equivalence classes which all lead to indistinguishable\nfuture distributions. The entropy of the distribution of these causal states\nthen serves as a measure of the complexity of the process. For futures which\nare ordered or unchanging, the system will have one or a small number of causal\nstates and the entropy will be small. Similarly, for futures which are\nuniformly random, the future distributions will be indistinguishable given the\npast and present, and the states will similarly collapse into a single or small\nnumber of causal states. Thus random processes will also have low statistical\ncomplexity.\n\nLet $X_t$ represent the state variable at the $t$-th time step for a system\nwith $N$ state variables per time step. The past light cone\n$\\mathcal{X}_{\\textrm{P}}$ of $X_t$ with a history of $T_{\\textrm{P}}$ time\nsteps is given by:\n\\begin{equation}\n    \\mathcal{X}_{\\textrm{P}} =\n        \\{X_{i, j} \\mid i = t - 1, \\ldots, t - T_{\\textrm{P}}\n            \\;\\;\\land\\;\\; j = 1, \\ldots, N\n            \\;\\;\\land\\;\\; X_{i, j} \\rightarrow X_t \\},\n\\end{equation}\nwhere $A \\rightarrow B$ means the state $A$ can influence $B$ (\\emph{i.e.} $B$\nis a function of $A$). The future light cone $\\mathcal{X}_{\\textrm{F}}$ of\n$X_t$ with a future of $T_{\\textrm{F}}$ time steps is similarly defined as:\n\\begin{equation}\n    \\mathcal{X}_{\\textrm{F}} =\n        \\{X_{i, j} \\mid i = t + 1, \\ldots, t + T_{\\textrm{F}}\n            \\;\\;\\land\\;\\; j = 1, \\ldots, N\n            \\;\\;\\land\\;\\; X_t \\rightarrow X_{i, j} \\}.\n\\end{equation}\nIn words, the past light cone of $X_t$ is the set of states which can influence\n$X_t$ and the future light cone is the set of states which can be influenced by\n$X_t$.\n\nEach past light cone and state variable $X_t$ defines a conditional\ndistribution over future light cones $P(\\mathcal{X}_{\\textrm{F}} \\mid\n\\mathcal{X}_{\\textrm{P}}, X_t)$. We can measure the similarity between two such\nconditional distributions using a statistical divergence $D(P_i \\| P_j)$. A\ncausal state $C$ represents a set of states $C = \\{(\\mathcal{X}_{\\textrm{P}},\nX_t)\\}$ where $D(P_i \\| P_j) = 0$ for every pair $(\\mathcal{X}_{\\textrm{P}},\nX_t)_i$ and $(\\mathcal{X}_{\\textrm{P}}, X_t)_j$ in $C$. In other words, the\ndistribution of future light cones of $(\\mathcal{X}_{\\textrm{P}}, X_t)_i$ and\n$(\\mathcal{X}_{\\textrm{P}}, X_t)_j$ are indistinguishable. In practice, we\nrelax $D(P_i \\| P_j) < \\tau$ for some predefined threshold due to finite\nsample sizes. Furthermore, we only require that $D(P_i \\| P_j) < \\tau$ be\nsatisfied for a single $(\\mathcal{X}_{\\textrm{P}}, X_t)_j$ in $C$ instead of\nall such states.\n\nUnlike HIC, statistical complexity is a measure of process complexity. We can\nuse it to observe how the complexity of a system changes over time. We can also\nuse statistical complexity as a measure of the global complexity of the system\nby applying it to every state at every time step; as we do in this work.\n\nPerhaps more importantly, statistical complexity can be computed in many\ncases without much difficulty. The distributions of future light cones given\npast light cones and state variables can be estimated for reasonable values of\n$T_\\textrm{P}$ and $T_\\textrm{F}$. \\citet{shalizi2004quantifying} estimate the\nlocal statistical complexity of circular cellular automata and show\nqualitatively that the measure correlates well to with the perceived complexity\nof the automata.\n", "meta": {"hexsha": "bc54c01948d3e616d159d2d5a0c8404ff4688033", "size": 11541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/hic.tex", "max_stars_repo_name": "awni/hic", "max_stars_repo_head_hexsha": "74ba29fe55e8592424557558253208f25df640c8", "max_stars_repo_licenses": ["MIT"], "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/hic.tex", "max_issues_repo_name": "awni/hic", "max_issues_repo_head_hexsha": "74ba29fe55e8592424557558253208f25df640c8", "max_issues_repo_licenses": ["MIT"], "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/hic.tex", "max_forks_repo_name": "awni/hic", "max_forks_repo_head_hexsha": "74ba29fe55e8592424557558253208f25df640c8", "max_forks_repo_licenses": ["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.4590909091, "max_line_length": 120, "alphanum_fraction": 0.7341651503, "num_tokens": 3273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6163625852279419}}
{"text": "%\n% 111\n%\n\\chapter{The Theory of Residues; Application to the Evaluation of Definite Integrals}\n\n\\Section{6}{1}{Residues}\n\nIf the function $f(z)$ has a pole of order $m$ at $z=a$, then, by the\ndefinition of a pole, an equation of the form\n$$\nf(z)\n=\n\\frac{a_{-m}}{ (z-a)^{m} }\n+ \\frac{ a_{-m+1} }{ (z-a)^{m-1} }\n+ \\cdots\n+ \\frac{a_{-1}}{z-a}\n+ \\phi(z),\n$$\nwhere $\\phi(z)$ is analytic near and at $a$, is true near $a$.\n\nThe coefficient $a_{-1}$ in this expansion is called the \\emph{residue}\\index{Residues!defined} of the\nfunction $f(z)$ relative to the pole $a$.\n\nConsider now the value of the integral $\\int_{\\alpha} f(z) \\dmeasure z$, where the path of\nintegration is a circle\\footnote{The existence of such a circle is\n  implied in the definition of a pole as an isolated singularity.}\n$\\alpha$, whose centre is the point $a$ and whose radius $\\rho$ is so small\nthat $\\phi(z)$ is analytic inside and on the circle.\n\nWe have\n$$\n\\int_{\\alpha} f(z) \\dmeasure z\n=\n\\sum_{r=1}^{m}\na_{r}\n\\int_{\\alpha} \\frac{\\dmeasure z}{ (z-a)^{r}}\n+\n\\int_{\\alpha} \\phi(z) \\dmeasure z.\n$$\n\nNow $\\int_{\\alpha} \\phi(z) \\dmeasure z = 0$ by \\hardsectionref{5}{2};\nand (putting $z-a = \\rho e^{i\\theta}$) we have, if $r \\neq 1$,\n$$\n\\int_{\\alpha} \\frac{ \\dmeasure z}{ (z-a)^{r} }\n=\n\\int_{0}^{2\\pi} \\frac{\\rho e^{i\\theta} i \\dmeasure \\theta}{ \\rho^{r}\n  e^{ri\\theta}}\n=\n\\rho^{-r+1}\n\\int_{0}^{2\\pi} e^{(1-r)i\\theta} i \\dmeasure \\theta\n=\n\\rho^{-r+1}\n\\thebracket{ \\frac{e^{(1-r) i \\theta}}{1-r} }_{0}^{2\\pi}\n=\n0.\n$$\n\nBut, when $r = 1$, we have\n$$\n\\int_{\\alpha}\n\\frac{\\dmeasure z}{z - a}\n=\n\\int_{0}^{2\\pi} i \\dmeasure \\theta\n=\n2\\pi i.\n$$\n\nHence finally\n$$\n\\int_{\\alpha} f(z) \\dmeasure z = 2 \\pi i a_{-1}.\n$$\n\nNow let $C$ be any contour, containing in the region interior to it a\nnumber of poles $a,b,c,\\ldots$ of a function $f(z)$, with residues\n$a_{-1}, b_{-1}, c_{-1},\\ldots$\nrespectively; and suppose that the function $f(z)$ is\nanalytic throughout $C$ and its interior, except at these poles.\n\nSurround the points $a,b,c,\\ldots$ by circles\n$\\alpha,\\beta,\\gamma,\\ldots$\nso small that their respective centres are the only singularities\ninside or on each circle; then the function $f(z)$ is analytic in the\nclosed region bounded by $C$, $\\alpha,\\beta,\\gamma,\\ldots$.\n%\n% 112\n%\n\nHence, by \\hardsectionref{5}{2} corollary TODO,\n\\begin{align*}\n  \\int_{C} f(z) \\dmeasure z\n  =&\n  \\int_{\\alpha} f(z) \\dmeasure z\n  + \\int_{\\beta} f(z) \\dmeasure z\n  + \\cdots\n  \\\\\n  =&\n  2\\pi i a_{-1} + 2\\pi i b_{-1} + \\cdots.\n\\end{align*}\n\nThus we have the \\emph{theorem of residues}, namely that\n\\emph{if $f(z)$ be analytic throughout a contour $C$ and its interior\n  except at a number of poles inside the contour, then\n  $$\n  \\int_{C} f(z) \\dmeasure z = 2\\pi i \\sum R,\n  $$\nwhere $\\sum R$ denotes the sum of the residues of the function $f(z)$ at\nthose of its poles which are situated within the contour $C$.}\n\nThis is an extension of the theorem of \\hardsubsectionref{5}{2}{1}.\n\n%\\begin{Remark} TODO:\\alpha or a?\nNote. If $a$ is a simple pole of $f(z)$ the residue of $f(z)$ at that pole\nis $\\lim_{z\\rightarrow a} (z-a) f(z)$.\n%\\end{Remark}\n\n\\Section{6}{2}{The evaluation of definite integrals.}\n\nWe shall now apply the result of \\hardsectionref{6}{1} to evaluating\nvarious classes of definite integrals; the methods to be employed in\nany particular case may usually be seen from the following typical\nexamples.\n\n\\Subsection{6}{2}{1}{The evaluation of the integrals of certain\n  periodic functions taken between the limits $0$ and\n  $2\\pi$.\\index{Integrals!of periodic functions}\\index{Periodic\n    functions!integrals involving}}\nAn integral of the type\n$$\n\\int_{0}^{2\\pi} R(\\cos \\theta, \\sin \\theta) \\dmeasure \\theta,\\index{Trigonometrical integrals}\n$$\nwhere the integrand is a rational function of $\\cos\\theta$ and\n$\\sin\\theta$ finite on the range of integration, can be evaluated by\nwriting $e^{i\\theta}=z$; since\n$$\n\\cos\\theta = \\half(z+z^{-1}),\n\\quad\n\\sin\\theta = \\frac{1}{2i} (z-z^{-1}),\n$$\nthe integral takes the form $\\int_{C} S(z) \\dmeasure z$, where $S(z)$\nis a rational function of $z$ finite on the path of integration $C$, the\ncircle of radius unity whose centre is the origin.\n\nTherefore, by \\hardsectionref{6}{1}, \\emph{the integral is equal to\n  $2\\pi i$ times the sum of the residues of $S(z)$ at those of its\n  poles which are inside that circle.}\n\n\\begin{wandwexample}\n  If $0 < p < 1$,\n  $$\n  \\int_{0}^{2\\pi}\n  \\frac{\\dmeasure \\theta}{ 1 - 2p\\cos\\theta + p^{2}}\n  =\n  \\int_{C} \\frac{ \\dmeasure z}{ i (1-pz) (z-p) }.\n  $$\n  The only pole of the integrand inside the circle is a simple pole at\n  $p$; and the residue there is\n  $$\n  \\lim_{z \\rightarrow p} \\frac{z-p}{ i (1-pz)(z-p)}\n  =\n  \\frac{1}{i (1-p^{2})}.\n  $$\n%\n% 113\n%\n  Hence\n  $$\n  \\int_{0}^{2\\pi} \\frac{\\dmeasure\\theta}{1 - 2p\\cos\\theta + p^{2}}\n  =\n  \\frac{2\\pi}{1-p^{2}}.\n  $$\n\\end{wandwexample}\n\n\\begin{wandwexample}\n  If $0 < p < 1$,\n  \\begin{align*}\n    \\int_{0}^{2\\pi} \\frac{ \\cos^{2} 3\\theta}{1-2p\\cos 2\\theta + p^{2}}\n    \\dmeasure \\theta\n    =&\n    \\int_{C} \\frac{\\dmeasure z}{iz}\n    \\theparen{ \\half z^{3} + \\half z^{-3}}^{2}\n    \\frac{1}{ (1-pz^{2})(1-pz^{-2})}\n  \\end{align*}\n  where $\\sum R$ denotes the sum of the residues of\n  $ \\frac{ (z^{6} + 1)^{2} }{ 4z^{5} (1-pz^{2})(z^{2}-p)} $ at its poles\n  inside $C$; these poles are $0, -p^{\\half}, p^{\\half}$;\n  and the residues at them are\n  $ -\\frac{1+p^{2}+p^{4}}{4p^{3}},\n  \\frac{(p^{3}+1)^{2}}{ 8p^{3}(1-p^{2})},\n  \\frac{(p^{3}+1)^{2}}{ 8p^{3}(1-p^{2})}$; %TODO:same?\n  and hence the integral is equal to\n  $$\n  \\frac{\\pi (1-p+p^{2})}{1-p}.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  If $n$ be a positive integer,\n  $$\n  \\int_{0}^{2\\pi} e^{\\cos\\theta} \\cos(n\\theta - \\sin\\theta)\n  \\dmeasure \\theta\n  =\n  \\frac{2\\pi}{n!},\n  \\quad\n  \\int_{0}^{2\\pi}\n  e^{\\cos\\theta} \\sin(n\\theta - \\sin\\theta) \\dmeasure \\theta\n  =\n  0.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  If $a>b>0$,\n  $$\n  \\int_{0}^{2\\pi}\n  \\frac{\\dmeasure \\theta}{ (a+b\\cos\\theta)^{2}}\n  =\n  \\frac{2\\pi a}{ (a^{2}-b^{2})^{3/2} },\n  \\quad\n  \\int_{0}^{2\\pi}\n  \\frac{\\dmeasure\\theta}{ (a+b\\cos^{2}\\theta)^{2}}\n  =\n  \\frac{\\pi(2a+b)}{ a^{3/2} (a+b)^{3/2}}.\n  $$\n\\end{wandwexample}\n\\Subsection{6}{2}{2}{The evaluation of certain types of integrals\n  taken between the limits $-\\infty$ and $+\\infty$.}\nWe shall now evaluate $\\int_{-\\infty}^{\\infty} Q(x) \\dmeasure x$,\nwhere $Q(z)$ is a function such that (i) it is analytic when the\nimaginary part of $z$ is positive or zero (except at a finite number\nof poles), (ii) it has no poles on the real axis and (iii) as\n$\\absval{z}\\rightarrow\\infty$, $zQ(z) \\rightarrow 0$ uniformly for all\nvalues of $\\arg z$ such that $0 \\leq \\arg z \\leq \\pi$; provided that\n(iv) when $x$ is real, $x Q(x) \\rightarrow 0$, as\n$x \\rightarrow \\pm\\infty$, in such a way\\footnote{The condition\n  $x Q(x)\\rightarrow 0$ is not in itself sufficient to secure the\n  convergence of\n  $\\int^{\\infty} Q(x) \\dmeasure x$;\n  consider $Q(x) = (x \\log x)^{-1}$.}\nthat $\\int_{0}^{\\infty} Q(x) \\dmeasure x$ and\n$\\int_{-\\infty}^{0} Q(x) \\dmeasure x$ both converge.\n\nGiven $\\eps$, we can choose $\\rho_{0}$ (independent of $\\arg z$) such\nthat $\\absval{z Q(z)} < \\eps/\\pi$ whenever\n$\\absval{z} > \\rho_{0}$ and $0 \\leq \\arg z \\leq \\pi$.\n\nConsider $\\int_{C} Q(z) \\dmeasure z$ taken round a contour $C$\nconsisting of the part of the real axis joining the points $\\pm\\rho$\n(where $\\rho > \\rho_{0}$) and a semicircle $\\Gamma$, of radius $\\rho$,\nhaving its centre at the origin, above the real axis.\n\nThen, by \\hardsectionref{6}{1}, $\\int_{C} Q(z) \\dmeasure z = 2 \\pi i\n\\sum R$, where $\\sum R$ denotes the sum of the residues of $Q(z)$ at\nits poles above the real axis.\\footnote{$Q(z)$ has no poles above the\n  real axis outside the contour.}\n\n%\n% 114\n%\nTherefore\n$$\n\\absval{\n  \\int_{-\\rho}^{\\rho} Q(z) \\dmeasure z\n  -\n  2 \\pi i \\sum R\n}\n=\n\\absval{\n  \\int_{\\Gamma} Q(z) \\dmeasure z\n}.\n$$\n\nIn the last integral write $z = \\rho e^{i\\theta}$, and then\n\\begin{align*}\n  \\absval{ \\int_{\\Gamma} Q(z) \\dmeasure z  }\n  &=\n  \\absval{\n    \\int_{0}^{\\pi} Q(\\rho e^{i\\theta}) \\rho e^{i\\theta} i\n    \\dmeasure\\theta\n  }\n  \\\\\n  &<\n  \\int_{0}^{\\pi} (\\eps / \\pi) \\dmeasure \\theta\n  \\\\\n  &= \\eps\n\\end{align*}\nby \\hardsubsectionref{4}{6}{2}.\n\nHence\n$$\n\\lim_{\\rho\\rightarrow\\infty}\n\\int_{-\\rho}^{\\rho} Q(z) \\dmeasure z\n=\n2\\pi i \\sum R.\n$$\n\nBut the meaning of $\\int_{-\\infty}^{\\infty} Q(x) \\dmeasure x$;\nis $\\lim_{\\rho,\\sigma\\rightarrow\\infty}\\int_{-\\rho}^{\\sigma} Q(x)\n\\dmeasure x$;\nand since\n$\\lim_{\\sigma\\rightarrow\\infty}\\int_{0}^{\\sigma} Q(x) \\dmeasure x$\nand\n$\\lim_{\\rho\\rightarrow\\infty}\\int_{-\\rho}^{0} Q(x) \\dmeasure x$\nboth exist, this double limit is the same as\n$\\lim_{\\rho\\rightarrow\\infty}\\int_{-\\rho}^{\\rho} Q(x) \\dmeasure x$.\n\nHence we have proved that\n$$\n\\int_{-\\infty}^{\\infty} Q(x) \\dmeasure x = 2\\pi i \\sum R.\n$$\n\nThis theorem is particularly useful in the special case when $Q(x)$ is a\nrational function.\n\n%\\begin{smallfont}\n[Note. Even if condition (iv) is not satisfied, we still have\n$$\n\\int_{0}^{\\infty}\n\\thebrace{\n  Q(x) + Q(-x)\n} \\dmeasure x\n=\n\\lim_{\\rho\\rightarrow\\infty} \\int_{-\\rho}^{\\rho} Q(x) \\dmeasure x\n= 2 \\pi i \\sum R.]\n$$\n%\\end{smallfont}\n\n\\begin{wandwexample}\n  The only pole of $(z^{2} + 1)^{-3}$ in the upper half plane is a\n  pole at $z=i$ with residue there $-\\frac{3}{16} i$. Therefore\n  $$\n  \\int_{-\\infty}^{\\infty} \\frac{\\dmeasure x}{ (x^{2}+1)^{3} }\n  =\n  \\frac{3}{8} \\pi.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\nIf $a > 0, b > 0$, shew that\n$$\n\\int_{-\\infty}^{\\infty}\n\\frac{x^{4} \\dmeasure x}{ (a + bx^{2})^{4} }\n=\n\\frac{\\pi}{ 16 a^{3/2} b^{5/2}}.\n$$\n\\end{wandwexample}\n\\begin{wandwexample}\n  By integrating $\\int e^{-\\lambda z^{2}} \\dmeasure z$ round a\nparallelogram whose corners are $-R, R, R + ai, -R + ai$ and making $R\n\\rightarrow \\infty$, shew that, if $\\lambda > 0$, then\n  $$\n  \\int_{-\\infty}^{\\infty} e^{-\\lambda x^{2}} \\cos (2\\lambda a x)\n\\dmeasure x = e^{-\\lambda a^{2}} \\int_{-\\infty}^{\\infty} e^{-\\lambda\nx^{2}} \\dmeasure x = 2 \\lambda^{-\\half} e^{-\\lambda a^{2}}\n\\int_{0}^{\\infty} e^{-x^{2}} \\dmeasure x.\n  $$\n\\end{wandwexample}\n\\Subsubsection{6}{2}{2}{1}{Certain infinite integrals involving sines\nand cosines.}\nIf $Q(z)$ satisfies the conditions (i), (ii) and (iii) of\n\\hardsectionref{6}{2}{2}, and $m > 0$,\nthen $Q(z) e^{miz}$ also satisfies those conditions.\n\n%\n% 115\n%\n\nHence\n$\n\\int_{0}^{\\infty}\n\\thebrace{\n  Q(x) e^{mix} + Q(-x) e^{-mix}\n}\n\\dmeasure x\n$\nis equal to $2\\pi i \\sum R'$, where\n$\\sum R'$ means the sum of the residues of $Q(z) e^{mix}$ at its poles\nin the upper half plane; and so\n\\begin{itemize}\n\\item % (i)\n  If $Q(x)$ is an even function\\index{Even functions}, i.e. if $Q (- x) = Q (x)$,\n  $$\n  \\int_{0}^{\\infty} Q(x) \\cos(mx) \\dmeasure x\n  =\n  \\pi i \\sum R'.\n  $$\n\\item %(ii)\n  If $Q(x)$ is an odd function\\index{Odd functions},\n  $$\n  \\int_{0}^{\\infty} Q(x) \\sin(mx) \\dmeasure x\n  =\n  \\pi \\sum R'.\n  $$\n\\end{itemize}\n\\Subsubsection[Jordan's lemma.]{6}{2}{2}{2}{Jordan's lemma.\\footnote{TODO:Jordan, Cours d'Aiiahjse, ii. (1894), pp. 285, 286.}\\index{Jordan's lemma}}\n\nThe results of \\hardsubsubsectionref{6}{2}{2}{1} are true if $Q(z)$ be\nsubject to the less stringent condition $Q(z) \\rightarrow 0$ uniformly\nwhen\n$O \\leq \\arg z \\leq \\pi$ as $\\absval{z} \\rightarrow \\infty$ in\nplace of the condition $z Q(z) \\rightarrow 0$ uniformly.\n\nTo prove this we require a theorem known as Jordan's lemma, viz.\n\n\\emph{If $Q(z) \\rightarrow 0$ uniformly with regard to $\\arg z$ as\n  $\\absval{z} \\rightarrow \\infty$ when $0 \\leq \\arg z \\leq \\pi$,\n  and if $Q(z)$ is analytic when both $\\absval{z} > c$ (a constant)\n  and $0 \\leq \\arg z \\leq \\pi$, then\n  $$\n  \\lim_{\\rho\\rightarrow\\infty}\n  \\theparen{ \\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z  }\n  =\n  0,\n  $$\n  where $\\Gamma$ is a semicircle of radius $\\rho$ above the real axis with centre at\n  the origin.}\n\nGiven $\\eps$, choose $\\rho_{0}$ so that $\\absval{Q(z)} < \\eps/\\pi$\nwhen $\\absval{z} > \\rho_{0}$ and\n$0 \\leq \\arg z \\leq \\pi$;\nthen, if $\\rho > \\rho_{0}$,\n$$\n\\absval{ \\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z }\n=\n\\absval{\n  \\int_{0}^{\\pi}\n  e^{mi (\\rho \\cos\\theta + i\\rho \\sin\\theta)}\n  Q(\\rho e^{i\\theta})\n  \\rho e^{i \\theta}\n  i \\dmeasure \\theta\n}.\n$$\nBut $\\absval{ e^{mi\\rho\\cos\\theta} } = 1$, and so\n\\begin{align*}\n  \\absval{ \\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z }\n  <&\n  \\int_{0}^{\\pi} (\\eps/\\pi) \\rho e^{-m\\rho\\sin\\theta} \\dmeasure\\theta\n  \\\\\n  =&\n  (2\\eps/\\pi)\n  \\int_{0}^{\\half\\pi} \\rho e^{-m\\rho\\sin\\theta} \\dmeasure\\theta.\n\\end{align*}\n\nNow $\\sin\\theta \\geq 2\\theta/\\pi$, when\\footnote{This inequality\n  appears obvious when we draw the graphs $y = \\sin x$, $y = 2x/\\pi$;\n  it may be proved by shewing that $(\\sin\\theta)/\\theta$ decreases as\n  $\\theta$ increases from $0$ to $\\half\\pi$.\n} $0 \\leq \\theta \\leq \\half\\pi$, and so\n\\begin{align*}\n  \\absval{ \\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z }\n  <&\n  (2\\eps/\\pi)\n  \\int_{0}^{\\half\\pi}\n  \\rho e^{-2m\\rho\\theta/\\pi} \\dmeasure\\theta\n  \\\\\n  =&\n  (2\\eps/\\pi) \\cdot (\\pi/2m)\n  \\thebracket{ -e^{-2m\\rho\\theta/\\pi} }_{0}^{\\half\\pi}\n  \\\\\n  <&\n  \\eps/m.\n\\end{align*}\n\n%\n% 116\n%\n\nHence\n$$\n\\lim_{\\rho\\rightarrow\\infty} \\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z = 0.\n$$\n\nThis result is Jordan's lemma.\n\nNow\n$$\n\\int_{0}^{\\rho}\n\\thebrace{\n  e^{mix} Q(x) + e^{-mix} Q(-x)\n}\n\\dmeasure x\n=\n2 \\pi i \\sum R'\n-\n\\int_{\\Gamma} e^{miz} Q(z) \\dmeasure z,\n$$\nand, making $\\rho\\rightarrow\\infty$, we see at once that\n$$\n\\int_{0}^{\\infty}\n\\thebrace{\n  e^{mix} Q(x) + e^{-mix} Q(-x)\n}\n\\dmeasure x\n=\n2 \\pi i \\sum R',\n$$\nwhich is the result corresponding to the result of \\hardsubsubsectionref{6}{2}{2}{1}.\n\n\\begin{wandwexample}\n  Shew that, if $a > 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ \\cos x}{x^{2} + a^{2}} \\dmeasure x\n  =\n  \\frac{\\pi}{2a} e^{-a}.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $a \\geq 0, b \\geq 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ \\cos 2ax - \\cos 2bx}{x^{2}}\n  \\dmeasure x\n  =\n  \\pi (b-a)\n  $$\n  (Take a contour consisting of a large semicircle of radius $\\rho$, a\n  small semicircle of radius $\\delta$, both having their centres at the\n  origin, and the parts of the real axis joining their ends; then\n  make $\\rho \\rightarrow \\infty, \\delta \\rightarrow 0$.)\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $b > 0, m \\geq 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{3x^{2} - a^{2}}{ (x^{2} + b^{2})^{2} }\n  \\cos mx\n  \\dmeasure x\n  =\n  \\frac{\\pi e^{-mb}}{4b^{3}}\n  \\thebrace{\n    3b^{2} - a^{2} - mb(3b^{2}+a^{2})\n  }.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $k > 0, a > 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ x \\sin ax }{x^{2} + k^{2}}\n  \\dmeasure x\n  =\n  \\half \\pi e^{-ka}.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $m \\geq 0$, $a > 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ \\sin mx }{ x (x^{2} + a^{2})^{2} }\n  \\dmeasure x\n  =\n  \\frac{\\pi}{2a^{4}}\n  -\n  \\frac{\\pi e^{-ma}}{4a^{3}}\n  \\theparen{ m + \\frac{2}{a} }.\n  $$\n  (Take the contour of example TODO.)\n\\end{wandwexample}\n\\begin{wandwexample}\nShew that, if the real part of $z$ be positive,\n$$\n\\int_{0}^{\\infty} (e^{-t} - e^{-tz}) \\frac{\\dmeasure t}{t} = \\log z.\n$$\n[We have\n\\begin{align*}\n  \\int_{0}^{\\infty} (e^{-t} - e^{-tz}) \\frac{\\dmeasure t}{t}\n  =&\n  \\lim_{\\delta\\rightarrow 0,\\, \\rho\\rightarrow\\infty}\n  \\thebrace{\n    \\int_{\\delta}^{\\rho} \\frac{e^{-t}}{t} \\dmeasure t\n    -\n    \\int_{\\delta}^{\\rho} \\frac{e^{-tz}}{t} \\dmeasure t\n  }\n  \\\\\n  =&\n  \\lim_{\\delta\\rightarrow 0,\\, \\rho\\rightarrow\\infty}\n    \\thebrace{\n    \\int_{\\delta}^{\\rho} \\frac{e^{-t}}{t} \\dmeasure t\n    -\n    \\int_{\\delta z}^{\\rho z} \\frac{e^{-u}}{u} \\dmeasure u\n  }\n  \\\\\n  =&\n  \\lim_{\\delta\\rightarrow 0,\\, \\rho\\rightarrow\\infty}\n    \\thebrace{\n    \\int_{\\delta}^{\\delta z} \\frac{e^{-t}}{t} \\dmeasure t\n    -\n    \\int_{\\rho}^{\\rho z} \\frac{e^{-t}}{t} \\dmeasure t,\n  },\n\\end{align*}\nsince $t^{-1} e^{-t}$ is analytic inside the\nquadrilateral whose corners are $\\delta, \\delta z, \\rho z, \\rho$.\n\n%\n% 117\n%\n\nNow $\\int_{\\rho}^{\\rho z} t^{-1} e^{-t} \\dmeasure t \\rightarrow 0$\nwhen $\\Re(z) > 0$; and\n$$\n\\int_{\\delta}^{\\delta z} t^{-1} e^{-t} \\dmeasure t\n= \\log z\n-\n\\int_{\\delta}^{\\delta z} t^{-1} (1 - e^{-t}) \\dmeasure t\n\\rightarrow\n\\log z,\n$$\nsince $t^{-1} (1 - e^{-t}) \\rightarrow 1$ as $t \\rightarrow 0$.]\n\\end{wandwexample}\n\\Subsection{6}{2}{3}{Principal values of\n  integrals.\\index{Integrals!principal values of}\\index{Principal part\n  of a function!value of an integral}}\n%\\begin{smallfont}\nIt was assumed in TODO that the function $Q(x)$ had no\npoles on the real axis; if the function has a finite number of \\emph{simple}\npoles on the real axis, we can obtain theorems corresponding to those\nalready obtained, except that the integrals are all principal values\n(\\hardsectionref{4}{5}) and $\\sum R$ has to be replaced by\n$\\sum R + \\half \\sum R_{0}$, where $\\sum R_{0}$ means the\nsum of the residues at the poles on the real axis. To obtain this\nresult we see that, instead of the former contour, we have to take as\ncontour a circle of radius $\\rho$ and the portions of the real axis joining\nthe points\n$$\n-\\rho, \\ a-\\delta_{1};\n\\quad\na+\\delta_{1}, \\ b-\\delta_{2};\n\\quad\nb+\\delta_{2}, \\ c-\\delta_{3},\n\\ \\ldots\n$$\nand small semicircles above the real axis of radii\n$\\delta_{1},\\delta_{2},\\ldots$ with\ncentres $a, b, c, \\ldots$ where $a, b, c, \\ldots$ are the poles of\n$Q(z)$ on the real axis; and then we have to make\n$\\delta_{1}, \\delta_{2}, \\ldots \\rightarrow 0$;\ncall these semicircles $\\gamma_{1},\\gamma_{2},\\ldots$.\nThen instead of the equation\n$$\n\\int_{-\\rho}^{\\rho} Q(z) \\dmeasure z\n+\n\\int_{\\Gamma} Q(z) \\dmeasure z\n=\n2 \\pi i \\sum R,\n$$\nwe get\n$$\nP \\int_{-\\rho}^{\\rho} Q(z) \\dmeasure z\n+\n\\sum_{n}\n\\lim_{\\delta_{n} \\rightarrow 0}\n\\int_{\\gamma_{n}} Q(z) \\dmeasure z\n+\n\\int_{\\Gamma} Q(z) \\dmeasure z\n=\n2 \\pi i \\sum R.\n$$\n\nLet $a'$ be the residue of $Q(z)$ at $a$; then writing\n$z = a + \\delta_{1} e^{i\\theta}$ on $\\gamma_{1}$ we get\n$$\n\\int_{\\gamma_{1}} Q(z) \\dmeasure z\n=\n\\int_{\\pi}^{0}\nQ(a + \\delta_{1} e^{i\\theta})\n\\delta_{1} e^{i\\theta} i \\dmeasure \\theta.\n$$\nBut $Q(a + \\delta_{1} e^{i\\theta}) \\rightarrow a'$\nuniformly as $\\delta_{1} \\rightarrow 0$; and therefore\n$\n\\lim_{\\delta_{1} \\rightarrow 0} \\int_{\\gamma_{1}} Q(z) \\dmeasure z\n=\n- \\pi i a'\n$;\nwe thus get\n$$\nP \\int_{-\\rho}^{\\rho} Q(z) \\dmeasure z\n+\n\\int_{\\Gamma} Q(z) \\dmeasure z\n=\n2 \\pi i \\sum R\n+\n\\pi i \\sum R_{0},\n$$\nand hence, using the arguments of \\hardsubsectionref{6}{2}{2}, we get\n$$\nP \\int_{-\\infty}^{\\infty} Q(x) \\dmeasure x\n=\n2 \\pi i \\theparen{ \\sum R + \\half \\sum R_{0} }.\n$$\n\nThe reader will see at once that the theorems of TODO have\nprecisely similar generalisations.\n\nThe process employed above of inserting arcs of small circles so as to\ndiminish the area of the contour is called \\emph{indenting} the contour.\n%\\end{smallfont}\n\\Subsection{6}{2}{4}{Evaluation of integrals of the form\n  $\\int_{0}^{\\infty} x^{a-1} Q(x) \\dmeasure x.$}\nLet $Q(x)$ be a rational function of $x$ such that it has no poles on the\npositive part of the real axis and\n$x^{a} Q(x) \\rightarrow 0$ both when $x \\rightarrow 0$ and when\n$x \\rightarrow \\infty$.\n\n%\n% 118\n%\n\nConsider $\\int (-z)^{a-1} Q(z) \\dmeasure z$ taken round the contour\n$C$ shewn in the figure TODO, consisting of the arcs of circles of\nradii $\\rho,\\delta$ and the straight lines joining their end points;\n$(-z)^{a-1}$ is\nto be interpreted as\n$$\n\\exp \\thebrace{ ( a-1) \\log (- z) }\n$$\nand\n$$\n\\log (-z) = \\log \\absval{z} + \\arg (-z),\n$$\nwhere\n$$\n-\\pi \\leq \\arg (-z) \\leq \\pi; %TODO:is overlap correct?\n$$\nwith these conventions the integrand is one-valued and analytic on and\nwithin the contour save at the poles of $Q(z)$.\n\nHence, if $\\sum r$ denote the sum of the residues of $(-z)^{a-1} Q(z)$\nat all its poles,\n$$\n\\int_{C} (-z)^{a-1} Q(z) \\dmeasure z = 2 \\pi i \\sum r.\n$$\n\nOn the small circle write $-z = \\delta e^{i\\theta}$, and the integral\nalong it becomes\n$- \\int_{\\pi}^{-\\pi} (-z)^{a} Q(z) i \\dmeasure \\theta$,\nwhich tends to zero as $\\delta \\rightarrow 0$.\n\nOn the large semicircle write $-z = \\rho e^{i\\theta}$, and the\nintegral along it becomes $- \\int_{-\\pi}^{\\pi} (-z)^{n} Q(z) i\n\\dmeasure\\theta$, which tends to zero as $\\rho \\rightarrow \\infty$.\n\nOn one of the lines we write $-z = x e^{\\pi i}$ on the other\n$-z = x e^{-\\pi i}$ and $(-z)^{a-1}$ becomes $x^{a-1} e^{\\pm (a-1) \\pi i}$.\n\nHence\n$$\n\\lim_{\\delta\\rightarrow 0,\\ \\rho\\rightarrow\\infty}\n\\int_{\\delta}^{\\rho}\n\\thebrace{\n  x^{a-1} e^{-(a-1)\\pi i} Q(x)\n  -\n  x^{a-1} e^{(a-1)\\pi i} Q(x)\n}\n\\dmeasure x\n=\n2 \\pi i \\sum r;\n$$\nand therefore\n$$\n\\int_{0}^{\\infty} x^{a-1} Q(x) \\dmeasure x\n=\n\\pi \\cosec (a\\pi) \\sum r.\n$$\n\n%TODO: change corollary environment\nCorollary. If $Q(x)$ have a number of simple poles on the positive\npart of the real axis, it may be shewn by indenting the contour that\n$$\nP \\int_{0}^{\\infty} x^{a-1} Q(x) \\dmeasure x\n=\n\\pi \\cosec (a\\pi) \\sum r\n-\n\\pi \\cot (1\\pi) \\sum r',\n$$\nwhere $\\sum r'$ is the sum of the residues of $z^{a-1} Q(z)$ at these poles.\n\\begin{wandwexample}\nIf $0 < a < 1$,\n$$\n\\int_{0}^{\\infty} \\frac{x^{a-1}}{1+x} \\dmeasure x\n=\n\\pi \\cosec a\\pi,\n\\quad\nP \\int_{0}^{\\infty} \\frac{x^{a-1}}{1+x} \\dmeasure x\n=\n\\pi \\cot a\\pi\n$$\n\\end{wandwexample}\n%\n% 119\n%\n\\begin{wandwexample}\n  If $0 < z < 1$ and $-\\pi < a < \\pi$,\n  $$\n  \\int_{0}^{\\infty} \\frac{t^{z-1}}{ t+e^{ia} } \\dmeasure t\n  =\n  \\frac{ \\pi e^{i(z-1)a}}{\\sin \\pi z}.\n  $$\n\\addexamplecitation{Minding.}\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $- 1 < z < 3$, then\n  $$\n  \\int_{0}^{\\infty} \\frac{ x^{z} }{ (1+x^{2})^{2} } \\dmeasure x\n  =\n  \\frac{ \\pi (1-z) }{ 4 \\cos \\half\\pi z}.\n  $$\n\\end{wandwexample}\n\\begin{wandwexample}\n  Shew that, if $-1 < p < 1$ and $-\\pi < \\lambda < \\pi$, then\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ x^{-p} \\dmeasure x }{ 1 + 2x \\cos\\lambda + x^{2} }\n  =\n  \\frac{\\pi}{\\sin p\\pi} \\frac{\\sin p\\lambda}{\\sin \\lambda}.\n  $$\n  \\addexamplecitation{Euler.}\n\\end{wandwexample}\n\\Section{6}{3}{Cauchy's integral.}\nWe shall next discuss a class of contour-integrals which are\nsometimes found useful in analytical investigations.\n\nLet $C$ be a contour in the $z$-plane, and let $f(z)$ be a function\nanalytic inside and on $C$. Let $\\phi(z)$ be another function which is\nanalytic inside and on $G$ except at a finite number of poles; let the\nzeros of $\\phi(z)$ in the interior\\footnote{$\\phi(z)$ must not have\n  any zeros or poles on $C$.} of $C$ be $a_{1},a_{2},\\ldots$, and let\ntheir degrees of multiplicity be $r_{1},r_{2},\\ldots$; and let its\npoles in the interior of $C$ be $b_{1},b_{2},\\ldots$, and let their\ndegrees of multiplicity be $s_{1},s_{2},\\ldots$.\n\nThen, by the fundamental theorem of residues,\n$ \\frac{1}{2\\pi i} \\int_{C} f(z) \\frac{\\phi'(z)}{\\phi(z)} \\dmeasure z $\nis equal to the sum of the residues of\n$f(z) \\frac{\\phi'(z)}{\\phi(z)}$\nat its poles inside $C$.\n\nNow\n$f(z) \\frac{\\phi'(z)}{\\phi(z)}$\ncan have singularities only at the poles and zeros of $\\phi(z)$.\nNear one of the zeros, say $a_{1}$, we have\n$$\n\\phi(z)\n=\nA (z-a_{1})^{r_{1}}\n+ B (z-a_{1})^{r_{1}+1}\n+ \\cdots.\n$$\n\nTherefore\n$$\n\\phi'(z)\n=\nA r_{1} (z-a_{1})^{r_{1}-1}\n+ B (r_{1}+1) (z-a_{1})^{r_{1}}\n+ \\cdots,\n$$\nand\n$$\nf(z) = f(a_{1}) + (z-a_{1}) f'(a_{1}) + \\cdots.\n$$\n\nTherefore\n$\n\\thebrace{f(z) \\frac{\\phi'(z)}{\\phi(z)}\n  -\n  \\frac{ r_{1} f(a_{1}) }{ z - a_{1} }\n}\n$ is analytic at $a_{1}$.\n\nThus the residue of $f(z) \\frac{\\phi'(z)}{\\phi(z)}$, at the point\n$z=a_{1}$, is $r_{1} f(a_{1})$.\n\nSimilarly the residue at $z=b_{1}$ is\n$-s_{1} f(b_{1})$; for near $z=b_{1}$, we have\n$$\n\\phi(z)\n=\nC (z-b_{1})^{-s_{1}}\n+ D (z-b_{1})^{-s_{1} + 1}\n+ \\cdots,\n$$\nand\n$$\nf(z)\n=\nf(b_{1})\n+ (z - b_{1}) f'(b_{1})\n+ \\cdots,\n$$\nso\n$\nf(z) \\frac{ \\phi'(z) }{\\phi(z)}\n+\n\\frac{ s_{1} f(b_{1}) }{ z-b_{1} }\n$\nis analytic at $b_{1}$.\n\nHence\n$$\n\\frac{1}{2\\pi i}\n\\int_{C} f(z) \\frac{ \\phi'(z) }{\\phi(z)} \\dmeasure z\n=\n\\sum r_{1} f(a_{1})\n-\n\\sum s_{1} f(b_{1}),\n$$\nthe summations being extended over all the zeros and poles of\n$\\phi(z)$.\n\n\\Subsection{6}{3}{1}{The number of roots of an equation contained\n  within a contour.\\index{Roots of an equation, number of!(inside a contour)}}\nThe result of the preceding paragraph can be at once applied to find\nhow many roots of an equation $\\phi(z) = 0$ lie within a contour $C$.\n\nFor, on putting $f(z) = 1$ in the preceding result, we obtain the\nresult that\n$$\n\\frac{1}{2\\pi i}\n\\int_{C} \\frac{ \\phi'(z) }{\\phi(z)} \\dmeasure z\n$$\nis equal to the excess of the number of zeros over the number of poles\nof $\\phi(z)$ contained in the interior of $C$, each pole and zero\nbeing reckoned according to its degree of multiplicity.\n\n%\n% 120\n%\n\\begin{wandwexample}\n  Shew that a polynomial $\\phi(z)$ of degree $m$ has $m$ roots.\n  \\index{Equation of degree $m$ has $m$ roots}\\index{Roots of an\n    equation!number of}\n\nLet\n$$\n\\phi(z)\n=\na_{0} z^{m} + a_{1} z^{m-1} + \\cdots + a_{m},\n\\quad\n(a_{0} \\neq 0).\n$$\nThen\n$$\n\\frac{ \\phi'(z) }{ \\phi(z) }\n=\n\\frac{ m a_{m}z^{m-1} + \\cdots + a_{m-1} }{ a_{0}z^{m} + \\cdots a_{m}}.\n$$\nConsequently, for large values of $\\absval{z}$,\n$$\n\\frac{ \\phi'(z) }{ \\phi(z) }\n=\n\\frac{m}{z} + O\\theparen{ \\frac{1}{z^{2}} }\n$$\nThus, if $C$ be a circle of radius $\\rho$ whose centre is at the origin, we\nhave\n$$\n\\frac{1}{2 \\pi i} \\int_{C} \\frac{\\phi'(z)}{\\phi(z)} \\dmeasure z\n=\n\\frac{m}{2 \\pi i} \\int_{C} \\frac{ \\dmeasure z }{z}\n+\n\\frac{1}{2 \\pi i} \\int_{C} O\\theparen{ \\frac{1}{z^{2}} } \\dmeasure z\n=\nm + \\frac{1}{2 \\pi i} \\int_{C} O\\theparen{ \\frac{1}{z^{2}} } \\dmeasure z.\n$$\n\nBut, as in \\hardsectionref{6}{2}{2},\n$$\n\\int_{C} O\\theparen{ \\frac{1}{z^{2}} } \\dmeasure z\n\\rightarrow\n0\n$$\nas $\\rho\\rightarrow\\infty$; and hence as $\\phi(z)$ has no poles in the\ninterior of $C$, the total number of zeros of $\\phi(z)$ is\n$$\n\\lim_{\\rho\\rightarrow\\infty}\n\\frac{1}{2\\pi i}\n\\int_{C} \\frac{ \\phi'(z) }{\\phi(z)} \\dmeasure z\n=\nm.\n$$\n\\end{wandwexample}\n\\begin{wandwexample}\nIf at all points of a contour $C$ the inequality\n$$\n\\absval{ a_{k} z^{k} }\n>\n\\absval{\n  a_{0}\n  + a_{1} z\n  + \\cdots\n  + a_{k-1} z^{k-1}\n  + a_{k+1} z^{k+1}\n  + \\cdots\n  + a_{m} z^{m}\n}\n$$\nis satisfied, then the contour contains $k$ roots of the equation\n$$\na_{m} z^{m} + a_{m-1} z^{m-1} + \\cdots a_{1} z + a_{0} = 0.\n$$\n\nFor write\n$$\nf(z)\n=\na_{m} z^{m} + a_{m-1} z^{m-1} + \\cdots a_{1} z + a_{0}.\n$$\n\nThen\n\\begin{align*}\n  f(z)\n  &=\n  a_{k} z^{k}\n  \\theparen{ 1 +\n    \\frac{ a_{m}z^{m}\n      + \\cdots\n      + a_{k+1}z^{k+1}\n      + a_{k-1}z^{k-1}\n      + \\cdots\n      + a_{0}\n    }{ a_{k} z^{k} }\n  }\n  \\\\\n  &= a_{k} z^{k} (1 + U),\n\\end{align*}\nwhere $\\absval{U} \\leq a \\leq 1$ on the contour, $a$ being\nindependent\\footnote{$\\absval{U}$ is a continuous function of $z$ on\n  $C$, and so \\emph{attains} its upper bound\n  (\\hardsubsectionref{3}{6}{2}). Hence its upper bound $a$ must be\n  less than $1$.} of $z$.\n\nTherefore the number of roots of $f(z)$ contained in $C$\n$$\n= \\frac{1}{2 \\pi i} \\int_{C} \\frac{f'(z)}{f(z)} \\dmeasure z\n= \\frac{1}{2 \\pi i}\n\\int_{C} \\theparen{ \\frac{k}{z}\n  + \\frac{1}{1+U} \\frac{ \\dd U }{ \\dd z }\n} \\dmeasure z\n$$\n\nBut $\\int_{C} \\frac{\\dd z}{z} = 2 \\pi i$; and, since $\\absval{U} < 1$,\nwe can expand $(1 + U)^{-1}$ in the uniformly convergent series\n$$\n1 - U + U^{2} - U^{3} + \\cdots,\n$$\nso\n$$\n\\int_{C} \\frac{1}{1+U} \\frac{\\dd U}{\\dd z} \\dmeasure z\n=\n\\thebracket{\n  [U - \\half U^{2} + \\frac{1}{3} U^{3} - \\cdots]\n}_{C}\n=\n0.\n$$\n\nTherefore the number of roots contained in $C$ is equal to $k$.\n\\end{wandwexample}\n\\begin{wandwexample}\nFind how many roots of the equation\n$$\nz^{6} + 6z + 10 = 0\n$$\nlie in each quadrant of the Argand diagram.\n\\addexamplecitation{Clare, 1900.}\n\\end{wandwexample}\n%\n% 121\n%\n\n\\Section{6}{4}{Connexion between the zeros of a function and the zeros of its\nderivative.}\\index{Zeros of a function!connected with zeros of its derivative}\nMacdonald\\footnote{TODO} has shewn that \\emph{if $f(z)$ be a function of $z$\nanalytic throughout the interior of a single closed contour $C$, defined\nby the equation $\\absval{f(z)} = M$, where $M$ is a constant, then the\nnumber of zeros of $f(z)$ in this region exceeds the number of zeros of\nthe derived function $f'(z)$ in the same region by unity.}\n\nOn $C$ let $f(z) = M e^{i\\theta}$; then at points on $C$\n$$\nf'(z) = M e^{i\\theta} i \\frac{\\dd \\theta}{\\dd z},\n\\quad\nf''(z)\n=\nM e^{i\\theta}\n\\thebrace{\n  i \\frac{ \\dd^{2} \\theta }{ \\dd z^{2} }\n  -\n  \\theparen{ \\frac{\\dd \\theta}{\\dd z} }^{2}\n}.\n$$\nHence, by \\hardsectionref{6}{3}{1}, the excess of the number of zeros\nof $f(z)$ over the number of zeros of $f'(z)$\ninside\\footnote{$f'(z)$ does not vanish on $C$ unless $C$ has a node\n  or other singular point; for, if $f = \\phi + i\\psi$,\n  where $\\phi$ and $\\psi$ are real, since\n  $i \\frac{\\partial f}{\\partial x} = \\frac{\\partial f}{\\partial y}$,\n  it follows that if $f'(z) = 0$ at any point, then\n  $\\frac{\\partial \\phi}{\\partial x},\n  \\frac{\\partial \\phi}{\\partial y},\n  \\frac{\\partial \\psi}{\\partial x},\n  \\frac{\\partial \\psi}{\\partial y}$\n  all vanish; and these are sufficient conditions for a singular point\n  on  $\\phi^{2} + \\psi^{2} = M^{2}$.\n} $C$ is\n$$\n\\frac{1}{2\\pi i}\n\\int_{C} \\frac{ f'(z) }{f(z)} \\dmeasure z\n-\n\\frac{1}{2\\pi i}\n\\int_{C} \\frac{ f''(z) }{ f'(z) } \\dmeasure z\n=\n-\\frac{1}{2 \\pi i}\n\\int_{C} \\theparen{\n  \\left.\n    \\frac{ \\dd^{2} \\theta }{ \\dd z^{2} }\n  \\right/\n  \\frac{\\dd\\theta}{\\dd z}\n  } \\dmeasure z.\n$$\nLet $s$ be the arc of $C$ measured from a fixed point and let $\\psi$\nbe the angle the tangent to $C$ makes with $Ox$; then\n\\begin{align*}\n-\\frac{1}{2 \\pi i}\n\\int_{C} \\theparen{\n  \\left.\n    \\frac{ \\dd^{2} \\theta }{ \\dd z^{2} }\n  \\right/\n  \\frac{\\dd\\theta}{\\dd z}\n  } \\dmeasure z\n  &=\n  - \\frac{1}{2 \\pi i}\n  \\thebracket{ \\log \\frac{\\dd\\theta}{\\dd z} }_{C}\n  \\\\\n  &=\n  - \\frac{1}{2 \\pi i}\n  \\thebracket{\n    \\log \\frac{\\dd\\theta}{\\dd s}\n    -\n    \\log \\frac{\\dd z}{\\dd s}\n  }_{C}\n  .\n\\end{align*}\nNow $\\log \\frac{\\dd \\theta}{\\dd s}$ is purely real and its initial\nvalue is the same as its final value; and\n$\\log \\frac{\\dd z}{\\dd s} = i \\psi$; hence the excess of the number of\nzeros of $f(z)$ over the number of zeros of\n$f'(z)$ is the change in $\\psi/2\\pi$ in describing the curve $C$; and it is\nobvious\\footnote{For a formal proof, see TODO} that if $C$ is any\nordinary curve, $\\psi$ increases by $2\\pi$ as the point of contact of\nthe tangent describes the curve $C$; this gives the required result.\n\\begin{wandwexample}\n  Deduce from Macdonald's result the theorem that a\n  polynomial of degree $n$ has $n$ zeros.\n\\end{wandwexample}\n\\begin{wandwexample}\n  Deduce from Macdonald's result that if a function $f(z)$,\n  analytic for real values of $z$, has all its coefficients real, and all\n  its zeros real and different, then between two consecutive zeros of\n  $f(z)$ there is one zero and one only of $f'(z)$.\n\\end{wandwexample}\nREFERENCES.\n\nM. C. Jordan, Cours dJ Analyse, 11. (Paris, 1894), Ch. vi.\n\nE. Goursat, Cours d' Analyse (Paris, 1911), Ch. xiv.\n\nE. LiNDELOF, Le Calcid des Residus (Paris, 1905), Ch. il.\n\n%\n% 122\n%\n\nMiscellaneous Examples.\n\\begin{enumerate}\n\\item  A function $\\phi(z)$ is zero when $z=0$, and is real when $z$\n  is real, and is analytic when $\\absval{z} \\leq 1$; if $f(x,y)$ is\n  the coefficient of $i$ in $\\phi(x + iy)$, prove that if $-1 < x < 1$,\n  $$\n  \\int_{0}^{2\\pi}\n  \\frac{x \\sin\\theta }{ 1 - 2x\\cos\\theta + x^{2}}\n  f(\\cos\\theta, \\sin\\theta)\n  \\dmeasure\\theta\n  =\n  \\pi \\phi(x).\n  $$\n  \\addexamplecitation{Trinity, 1898.}\n\\item\n  By integrating $\\frac{e^{\\pm aiz}}{e^{2\\pi z}-1}$ round a contour formed by the rectangle whose\n  corners are $0, R, R+i, i$ (the rectangle being indented at $0$ and\n  $i$) and making $R\\rightarrow\\infty$,\n  shew that\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{ \\sin ax }{e^{2 \\pi x} - 1}\n  \\dmeasure x\n  =\n  \\frac{1}{4}\n  \\frac{ e^{a} + 1 }{ e^{a} - 1 }\n  -\n  \\frac{1}{2a}.\n  $$\n  \\addexamplecitation{Legendre.}\n\n\\item\n  By integrating $\\log (-z) Q(z)$ round the contour of\n  \\hardsubsectionref{6}{2}{4}, where $Q(z)$ is a rational function such\n  that  $z Q(z) \\rightarrow 0$ as $\\absval{z} \\rightarrow 0$ and as\n  $\\absval{z} \\rightarrow \\infty$, shew that if $Q(z)$ has no poles\n  on the positive part of the real axis,\n  $\\int_{0}^{\\infty} Q(x) \\dmeasure x$ is equal to minus\n  the sum of the residues of $\\log(-z) Q(z)$ at the poles of\n  $Q(z)$; where the imaginary part of $\\log(-z)$ lies between $\\pm\\pi$.\n\n\\item\n  Shew that, if $a > 0, b > 0$,\n  $$\n  \\int_{0}^{\\infty}\n  e^{a \\cos bx} \\sin (a \\sin bx) \\frac{\\dmeasure x}{x}\n  =\n  \\half \\pi \\theparen{ e^{a} - 1 }.\n  $$\n\n\\item\n  Shew that\n  $$\n  \\int_{0}^{\\half\\pi}\n  \\frac{a \\sin 2x}{1 - 2a \\cos 2x + a^{2}}\n  x \\dmeasure x\n  =\n  \\begin{cases}\n    \\frac{1}{4} \\pi \\log (1+a), & (-1<a<1)\n    \\\\\n    \\frac{1}{4} \\pi \\log (1+a^{-1}), & (a^{2} > 1).\n  \\end{cases}\n  $$\n%  \\addexamplecitation{Cauchy.}\n\\item Shew that\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{\\sin \\phi_{1}x}{x}\n  \\frac{\\sin \\phi_{2}x}{x}\n  \\cdots\n  \\frac{\\sin \\phi_{n}x}{x}\n  \\cos a_{1} x\n  \\cdots\n  \\cos a_{m} x\n  \\frac{ \\sin ax }{x}\n  \\dmeasure x\n  =\n  \\frac{\\pi}{2} \\phi_{1} \\phi_{2} \\cdots \\phi_{n},\n  $$\n  if $\\phi_{1}, \\phi_{2}, \\ldots \\phi_{n}, a_{1}, a_{2}, \\ldots a_{m}$\n  be real and $a$ be positive and\n  $$\n  a\n  >\n  \\absval{\\phi_{1}}\n  + \\absval{\\phi_{2}}\n  + \\cdots\n  + \\absval{\\phi_{n}}\n  + \\absval{a_{1}}\n  + \\cdots\n  + \\absval{a_{m}}.\n  $$\n  \\addexamplecitation{TODO Stormer, Acta Math, xix.}\n  %\n\\item\n  If a point $z$ describes a circle $C$ of centre $a$, and if\n  $f(z)$ be analytic throughout $C$ and its interior except at a\n  number of poles inside $C$, then the point $u=f(z)$ will\n  describe a closed curve $\\gamma$ in the $u$-plane.\n  Shew that if to each element of $\\gamma$ be attributed\n  a mass proportional to the corresponding element of $C$, the centre of\n  gravity of $\\gamma$ is the\n  point $r$, where $r$ is the sum of the residues of\n  $\\frac{f(z)}{z-a}$ at its poles in the interior of $C$.\n  \\addexamplecitation{TODO Amigues, Noiiv. Ann. de Math. (.3), xii. (1893), pp. 142-148.}\n  %\n\\item  Shew that\n  $$\n  \\int_{-\\infty}^{\\infty}\n  \\frac{\\dmeasure x}{ (x^{2}+b^{2}) (x^{2}+a^{2})^{2} }\n  =\n  \\frac{\\pi (2a+b)}{ 2a^{3}b(a+b)^{2}}.\n  $$\n\\item\n  Shew that\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{\\dmeasure x}{(a+bx^{2})^{n}}\n  =\n  \\frac{\\pi}{ 2^{n} b^{\\half} }\n  \\frac{1 \\cdot 3 \\cdots (2n-3)}{1 \\cdot 2 \\cdots (n-1)}\n  \\frac{1}{ a^{n-\\half} }.\n  $$\n%\n% 123\n%\n\n\\item\n  If $F_{n}(z)= \\prod_{m=1}^{n-1} \\prod_{p=1}^{n-1} (1-z^{mp})$, shew that the series\n  $$\n  f(z)\n  =\n  - \\sum_{n=2}^{\\infty}\n  \\frac{F_{n}(zn^{-1})}{ (z^{n}n^{-n} -1) n^{n-1} }\n  $$\n  is an analytic function when $z$ is not a root of any of the equations\n  $z^{n} = n^{n}$; and that the sum of the residues of $f(z)$ contained in the\n  ring-shaped space included between two circles whose centres are at\n  the origin, one having a small radius and the other having a radius\n  between $n$ and $n + 1$, is equal to the number of prime numbers less than\n  $n + 1$. \\addexamplecitation{TODO Laurent, A' oiiv. Aim. de Math. (3), xviii. (1899), pp.\n  234-241.}\n\n\\item\n  If $A$ and $B$ represent on the Argand diagram two given roots (real\n  or imaginary) of the equation $f(z) = 0$ of degree $n$, with real or\n  imaginary coefficients, shew that there is at least one root of the\n  equation $f'(z) = 0$ within a circle whose centre is the middle point\n  of $AB$ and whose radius is $\\half AB \\cot \\frac{\\pi}{n}$.\n  \\addexamplecitation{TODO Grace, Proc. Camb. Phil. Soc. XI.}\n\\item\n  Shew that, if $0<\\nu<1$,\n  $$\n  \\frac{e^{2\\pi i \\nu x}}{1 - e^{2\\pi i x}}\n  =\n  \\frac{1}{2\\pi i}\n  \\lim_{n\\rightarrow\\infty}\n  \\sum_{k=-n}^{n} \\frac{e^{2k\\nu\\pi i}}{k-x}.\n  $$\n  [Consider\n  $\n  \\int \\frac{e^{(2\\nu-1) z \\pi i}}{\\sin \\pi z}\n  \\frac{\\dmeasure z}{z-x}\n  $\n  round a circle of radius $n+\\half$; and make $n\\rightarrow\\infty$.]\n  \\addexamplecitation{TODO Kronecker, Journal fiir Math, cv.}\n\\item\n  Shew that, if $m > 0$, then\n  \\begin{align*}\n    \\int_{0}^{\\infty}\n    \\frac{\\sin^{n} mt}{t^{n}} \\dmeasure t\n    \\\\\n    =\n    \\frac{\\pi m^{n-1}}{2^{n} (n-1)!}\n    \\theparen{\n      n^{n-1}\n      -\n      \\frac{n}{1} (n-2)^{n-1}\n      +\n      \\frac{n(n-1)}{2} (n-4)^{n-1}\n      -\n      \\frac{n(n-1)(n-2)}{3!} (n-6)^{n-1}\n      +\n      \\cdots\n    }.\n  \\end{align*}\n  Discuss the discontinuity of the integral at $m = 0$.\n\n\\item\n  If $A + B + C + \\cdots = 0$ and $a, b, c, \\ldots$ are positive, shew that\n  $$\n  \\int_{0}^{\\infty}\n  \\frac{A \\cos ax + B \\cos bx + \\cdots + K \\cos kx}{x}\n  \\dmeasure x\n  =\n  -A \\log a\n  -B \\log b\n  - \\cdots\n  -K \\log k.\n  $$\n  \\addexamplecitation{Wolstenholme.}\n\\item\n  By considering\n  $\n  \\int \\frac{e^{x(k+ti)}}{k+ti} \\dmeasure t\n  $\n  taken round a rectangle indented at the origin, shew\n  that, if $k > 0$,\n  $$\n  i \\lim_{\\rho\\rightarrow\\infty}\n  \\int_{-\\rho}^{\\rho}\n  \\frac{e^{x(k+ti)}}{k+ti} \\dmeasure t\n  =\n  \\pi i\n  +\n  \\lim_{\\rho\\rightarrow\\infty}\n  P \\int_{-\\rho}^{\\rho} \\frac{e^{xti}}{t} \\dmeasure t,\n  $$\n  and hence deduce, by using the contour of\n  \\hardsubsubsectionref{6}{2}{2}{2} example\n  TODO:citeEx2, or its reflexion in the real axis\n  (according as $x \\geq 0$ or $x < 0$), that\n  $$\n  \\lim_{\\rho\\rightarrow\\infty}\n  \\frac{1}{\\pi}\n  \\int_{-\\rho}^{\\rho}\n  \\frac{e^{x(k+ti)}}{k+ti} \\dmeasure t\n  =\n  2,\\, , 1,\\, \\textrm{or } 0,\n  $$\n  according as $x>0$, $x = 0$, or $x < 0$.\n\n  [This integral is known as Cauchy's discontinuous factor.]\n%\n\\item\n  Shew that, if $0 < a < 2, b > 0, r > 0$, then\n  $$\n  \\int_{0}^{\\infty}\n  x^{a-1}\n  \\sin (\\half a\\pi - bx )\n  \\frac{r \\dmeasure x}{x^{2} + r^{2}}\n  =\n  \\half \\pi r^{a-1} e^{-br}.\n  $$\n%\n% 124\n%\n\n\\item\n  Let $t>0$ and let\n  $\n  \\sum_{n=-\\infty}^{\\infty}\n  e^{-n^{2} \\pi t}\n  =\n  \\psi(t).\n  $\n\n  By considering\n  $\n  \\int \\frac{e^{-z^{2} \\pi t}}{e^{2\\pi i z} - 1} \\dmeasure z\n  $\n  round a rectangle whose corners are\n  $\\pm (N+\\half) \\pm i$, where $N$ is an integer,\n  and making $N \\rightarrow \\infty$, shew that\n  $$\n  \\psi(t)\n  =\n  \\int_{-\\infty - i}^{\\infty - i}\n  \\frac{e^{-z^{2} \\pi t}}{e^{2\\pi i z} - 1} \\dmeasure z\n  -\n  \\int_{-\\infty + i}^{\\infty + i}\n  \\frac{e^{-z^{2} \\pi t}}{e^{2\\pi i z} - 1} \\dmeasure z.\n  $$\n\n  By expanding these integrands in powers of\n  $e^{-2\\pi i z}, e^{2\\pi i z}$\n  respectively\n  and integrating term-by-term, deduce from \\hardsubsectionref{6}{2}{2} example TODO that\n  $$\n  \\psi(t)\n  =\n  \\frac{1}{ \\sqrt{\\pi t} }\n  \\psi(1/t)\n  \\int_{-\\infty}^{\\infty} e^{-x^{2}} \\dmeasure x.\n  $$\n\n  Hence, by putting $t = 1$ shew that\n  $$\n  \\psi(t) = t^{-\\half} \\psi(1/t).\n  $$\n\n  (This result is due to TODOPoisson, Journal de VEcole foly technique, xii.\n  (cahier xix), (1823), p. 420; see also Jacobi, Journal fiir Math,\n  xxxvi. (1848), p. 109 [Ges. Werke, ii. (1882), p. 188].)\n\n\\item\n  Shew that, if $t>0$,\n  $$\n  \\sum_{-\\infty}^{\\infty}\n  e^{-n^{2} \\pi t - 2 n \\pi a t}\n  =\n  t^{-\\half}\n  e^{\\pi a^{2} t}\n  \\thebrace{\n    1\n    +\n    2\n    \\sum_{n=1}^{\\infty}\n    e^{-n^{2} \\pi / t} \\cos 2n\\pi a\n  }.\n  $$\n  \\addexamplecitation{TODOPoisson, Mem. de I'Acad. des Sci. vi. (1827), p. 592; Jacobi,\n  Journal fur Math. ill. (1828), pp. 403-404 [Ges. Werke, i. (1881), pp.\n  264-265]; and Landsberg, Journal fur Math. CXI. (1893), pp. 234-253;\n  see also \\hardsubsectionref{21}{5}{1}.)}\n\n\\end{enumerate}", "meta": {"hexsha": "2e2b7d0d432880ece967d950605e14eb07616441", "size": 38807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch06.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-ch06.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-ch06.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.0975117687, "max_line_length": 149, "alphanum_fraction": 0.5987321875, "num_tokens": 15619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.6163057241889199}}
{"text": "\n\\subsection{Atomic formulae}\n\nAtomic formulae are those without operators taking more than one input.\n\nLiterals, and negative literals, are types of atomic formula.\n\nA literal is a formula with no operators.\n\n\\(\\theta \\)\n\nThese are also known as positive literals.\n\nNegative literals are the negation of a literal.\n\n\\(\\neg \\theta \\)\n\n\\subsection{Well-formed formulae}\n\nA well-formed formula is one which can be given a truth value.\n\nThe following is not a well-formed formula:\n\n\\(\\theta \\land \\)\n\n", "meta": {"hexsha": "4ccad85ba902894957eee51a276b6f9710f46ff9", "size": 498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/02-05-formulae.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-05-formulae.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-05-formulae.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.1538461538, "max_line_length": 71, "alphanum_fraction": 0.7550200803, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127455162774, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6163057177364653}}
{"text": "In this section it is explained how to impose an external flux or atmospheric exchange of one or a few constituents into the model. This feature can be used to for example incorporate the flux of dissolved oxygen as a result of aeration in a water quality model or to model the influx of contaminant, organic matter and nutrients separate from the inflows. Several influx models are provided in GIFMod as described below: \n\\begin{itemize}\n\\item \\textbf{Constant influx model: } In this model the flux is assumed to be constant: \n\\begin{equation}\n\\label{eq:28}\nJ_{ext} = k_{ext}\n\\end{equation}\nSo the external influx of a constituent will be calculated as: \n\\begin{equation}\n\\label{eq:29}\n\\dot{m} = A_s k_{ext}\n\\end{equation}\n\n\\item \\textbf{Constant rate model: } In this model the flux is assumed to be proportional to the difference between the concentration of a constituent and a saturation concentration $C_s$: \n\\begin{equation}\n\\label{eq:30}\nJ_{ext} = k_{ext}(C_s-C)\n\\end{equation}\nWhich is applied volumetrically. So the external influx of a constituent will be calculated as: \n \\begin{equation}\n\\label{eq:30a}\n\\dot{m} = k_{ext}(C_s-C) \\sout{V}\n\\end{equation}\n\n\\item \\textbf{Free surface model: } The free surface model is used for open-channel reaeration where the flow depth and velocity affect the rate of aeration. The for of the flux equation is consistent with the forms suggested by \\citep{oconnor1956,churchill1964,owens1964some,isaacs1968,langbein1967}:\n\\begin{equation}\n\\label{eq:31}\nJ_{ext} = k_{ext}v^{\\alpha_{ext}}H^{\\beta_{ext}}(C_s-C)\n\\end{equation}\n\n\n\\item \\textbf{Soil model: } Aeration in soils is expected to be limited by the area of air-water interface. In this model it is assumed that the area of the air-water interface is proportional to the moisture content and air content of the soil. The external flux equation for soils is therefore considered as: \n\n\\begin{equation}\n\\label{eq:32}\nJ_{ext} = k_{ext}\\theta (\\theta_s-\\theta) (C_s-C)\n\\end{equation}\nWhich is applied volumetrically. So the external influx of a constituent will be calculated as: \n \\begin{equation}\n\\label{eq:33}\n\\dot{m} = k_{ext}\\theta (\\theta_s-\\theta) (C_s-C) \\sout{V}\n\\end{equation}\n\\end{itemize}\n\\subsubsection{External Flux Properties: }\nAn external flux model must be added by right-clicking \\textbf{Project Explorer}$\\rightarrow$\\textbf{Water Quality}$\\rightarrow$\\textbf{External Fluxes} and clicking on \\textbf{Add External Flux} and then be assigned to individual blocks through the \\textbf{External Flux} property of the block. \n\nBelow properties that can be assigned to a \\textbf{External flux} model are described: \n\n\\begin{itemize}\n\\item \\textbf{Name: } This is the name of the external flux model. The name is used to assign the model to individual blocks. \n\\item \\textbf{Coefficient: } Here the value of $k_{ext}$ in Eqs. (\\ref{eq:28}, \\ref{eq:30}, \\ref{eq:31}, \\ref{eq:32}) can be entered. This is needed for all external flux models. \n\\item \\textbf{Constituent: } This indicate the constituent that will be released as a result of the external flux. \n\\item \\textbf{Depth exponent: } The value of $\\beta_{ext}$ in the free surface model. \n\\item \\textbf{Model: } Here the type of the model to be used for the external flux will be selected. \n\\item \\textbf{Saturation: } The value of saturation concentration $C_s$ used in the \\textbf{constant rate}, \\textbf{free surface}, \\textbf{soil} will be entered here. \n\\textbf{Solid: } Indicates the solid phase (soil or particles) that the external flux will be assigned to. If left empty the influx occur as dissolved. \n\\item \\textbf{Transfer Rate Expression: } This property allows the user to type in an expression to be used for the calculation of the external flux rates. \n\\item \\textbf{Velocity Exponent: } The value of $\\alpha_{ext}$ in free surface model (Eq. \\ref{eq:31}). \n\\end{itemize}\n\n\\input{Aeration_ex.tex}", "meta": {"hexsha": "ab75da4e2510c31426dcc21624b66824297b0300", "size": 3878, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GIFMod User's Manual/External_Flux.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/External_Flux.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/External_Flux.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": 63.5737704918, "max_line_length": 422, "alphanum_fraction": 0.7607013925, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6163057177364651}}
{"text": "\\section{Extensions to the Problem}\nFor the bulk of this thesis, we have looked at many-to-one matching problems with one-sided preferences, as this setting makes the most sense for the student-seminar application. However, there is a wide range of similar problems and extensions that are also worth mentioning. This section will present some of those problems and key results from the literature. \n\n\\subsection{Two-Sided Preferences}\\label{extensions:two-sided}\nIn many practical one-to-many matching schemes, both parties will express preferences over the other. For instance, many countries use such schemes for matching students to university programs, which can be viewed as an instance of a one-to-many matching problem with two-sided preferences. A similar problem exists in the United States, where graduating medical students need to be matched to residency positions in hospitals. \n\nSince we are considering two-sided preferences now, it is not possible to simply transform this problem into a weighted bipartite graph anymore, since edges now have two weights. It could be possible to use the product of those two weights as an edge weight; however, in practice different mechanisms are being used that do not rely on the graph representation of the problem.\n\n\\subsubsection{Stable Matchings}\nIn the context of two-sided preferences, \\emph{Stability} is a commonly used optimality criteria that matchings should fulfill. It can be seen as the two-sided preference extension to Pareto-optimality and is defined as follows. Given a set $H$ of hospitals and a set $R$ of residents, a matching $M$ of an instance $I$ is stable iff there is no pair $(r_i, h_j) \\in M, r_i \\in R, h_j \\in H$ with:\n\\begin{itemize}\n    \\item $r_i$ and $h_j$ are on each other's preference lists\n    \\item either $r_i$ is assigned in $M$, or $r_i$ prefers $h_j$ to $M(r_i)$\n    \\item either $h_j$ is undersubscribed in $M$, or $h_j$ prefers $r_i$ to it is least preferred assigned resident in $M(h_j)$\n\\end{itemize}\nSimply put, in a stable matching $M$, no pair of agents $(r_i, h_j)$ should have an incentive to give up their current match to get matched to each other.\n\n\\subsubsection{Algorithm}\nGale and Shapley \\cite{GaleShapleyOrig} proved that for every instance of the problem, there exists a stable matching that can be computed using a linear-time algorithm. There are two variants of the algorithm, one that computes a resident-optimal, hospital pessimal matching and one that does the opposite. That means that in the first case, each resident is matched to the best hospital among all stable matchings, while each hospital is matched to the worst set of residents among all stable matchings \\cite{Gusfield}. In the context of student seminar matchings, it would make sense to use the resident/student optimal algorithm, which goes as follows \\cite{Gusfield}:\n\\begin{algorithm} % enter the algorithm environment\n    \\caption{Resident-oriented Deferred Acceptance Algorithm} \n    \\label{alg:resident-oriented-algorithm} \n    \\begin{algorithmic} % enter the algorithmic environment\n        \\Require set of residents with preferences $R$, set of hospitals $H$\n        \\Ensure Stable Matching M\n        \\While{Some resident $r$ is free and has a non-empty preference list} \n        \\State $h:=$ first hospital on $r$'s preference list\n        \\If{$h$ is fully subscribed}\n            \\State $r':=$ worst resident provisionally assigned to h\n            \\State unassign $r'$ from $h$\n        \\EndIf\n        \\State provisionally assign $r$ to $h$\n\n        \\If{$h$ is fully subscribed}\n            $s:=$ worst resident provisionally assigned to $h$\n            \\ForEach{successor $s'$ of $s$ on $h$'s list}\n                \\State remove $s'$ and $h'$ from each other's list\n            \\EndFor\n        \\EndIf\n\n        \\EndWhile\n    \\end{algorithmic}\n\\end{algorithm}\n\nAn advantage of using this algorithm for matching students to seminars is that the order in which students are processed does not matter. Gusfield shows that for any permutation of the input, each hospital is assigned the same number of residents, the same set of residents is unassigned and each undersubscribed hospital is matched to the same set of residents \\cite{Gusfield}.\n\n\\subsection{Many-to-Many Matchings}\nA natural extension of the many-to-one matching setting is the many-to-many matching problem. It could very well be a requirement that students need to be matched to more than one seminar. In that case, we need to differentiate between one- and two-sided preferences again:\n\n\\subsubsection{One-sided Preferences}\nMany-to-many matching scenarios with one-sided preferences are also commonly referred to as the \\emph{Course allocation} problem, which is a combinatorial assignment problem with the goal of assigning students to courses, based on the students' preferences \\cite{CourseAllocation}. Compared to the student and seminar scenario we now allow students to get matched to more than one course. \n\nA common mechanism for solving course allocation problems is using an \\emph{Auction model} or \\emph{Bidding points mechanism} in which students are given a set amount of artificial currency, which they then use to bid on seats in classes. After all bids are submitted, the system assigns the seats to the highest bidders. The bids can be used to infer students' preferences; however, the true preferences may differ significantly, which makes this mechanism less desirable \\cite{Bidding}.\n\nAnother commonly used mechanism is the \\emph{Draft}, in which students are asked to pick a course with remaining seats based on a draft order. Intuitively, this mechanism is an extension of RSD (Section \\ref{algo-rsd}), where the whole process is repeated until no student makes a pick anymore. Such draft mechanisms are commonly used in course allocation settings; one example being Harvard Business School \\cite{CourseAllocation}. However, it has been shown that students have successfully manipulated the draft due to the fact that this mechanism is not strategy-proof.\n\nA mechanism that is more robust towards strategic manipulation is a \\emph{proxy bidding mechanism} presented by Kominers et al. \\cite{CourseAllocation}. The mechanism uses proxies that act on behalf of the students by using their true preferences in the draft.\n\n\\subsubsection{Two-sided Preferences}\nFor the case of two-sided preferences, we have to slightly modify the definition of Stability again to accommodate for the fact that each entity can be assigned more than once: Given the set of hospitals $H$ and residents $R$, let $h \\in H$ and $r \\in R$, so that $h$ and $r$ are acceptable to each other, unmatched and the following holds true: \n\\begin{itemize}\n    \\item either $h$ has unfilled places or prefers $r$ to one of his matched partners \\textbf{and}\n    \\item either $r$ has unfilled places or prefers $h$ to one of his matched partners\n\\end{itemize}\nUsing this definition of stability, Gusfield \\cite{Gusfield} proposes that an algorithm can be constructed using ideas from the hospital-oriented and resident-oriented (see Algorithm \\ref{alg:resident-oriented-algorithm}) algorithm that finds a stable matching that's optimal for either of the sets. Again, such a stable matching exists for any instance of the problem \\cite{Gusfield}.\n\n\\subsection{Online Variants}\\label{sec:online-variants}\nWhen solving the \\emph{online-variant} of the problem, the whole input is not available from the start. That means that the input needs to be processed piece by piece, or more formally: Given a bipartite weighted graph $(U, V, E)$, where $U$ is known to the algorithm, vertices in $V$ are unknown, but arrive one at a time, while also revealing their incident edges, find a matching that maximizes some objective function. These algorithms could be of interest in the case of a first-come first-serve course allocation system, or in other areas such as DVD-rental or online-advertisement allocation systems \\cite{Mehta:Online}.\n\nIn the case of student-seminar assignments, we would assume that the set of courses and their capacities is known beforehand, and the students arrive later. One of the algorithms we have seen in Section \\ref{chapter:algorithms} can be used for this problem, namely the RSD-algorithm. As a matter of fact, the algorithm will produce the same results for the offline and online case, given that the order in which students are processed is identical.\n\n\\subsubsection{Online Maximum Cardinality Matching}\nThere has been lots of research in particular on finding maximum-cardinality matchings with online inputs. The online-inputs are classified by how much information the algorithm possesses about the input order. For now, we will only consider the \\emph{adversarial order}, where we assume no knowledge of the query sequence, which means that only $U$ is known at the beginning of the algorithm, while we have no knowledge of $V$ and $E$ or the order they appear in \\cite{Mehta:Online}. To measure performance, we will use the \\emph{competitive ratio} of an algorithm which is defined as follows. Given an instance of the problem $I$, the value of the objective function for the online algorithm is given as $ALG(I)$, and the value of the objective function for the best offline algorithm is given as $OPT(I)$. The competitive ratio is now computed as follows: $C.R.=\\frac{ALG(I)}{OPT(I)}$ \\cite{Mehta:Online}.\n\nA simple algorithm for this online problem is a greedy algorithm, which matches arriving vertices to any available neighbor, or a random approach that matches arriving vertices to a random neighbor. These mechanisms achieve a competitive ratio of $\\frac{1}{2}$ \\cite{Mehta:Online}. An optimal, yet simple algorithm was introduced by Karp et al. \\cite{Karp:Online}, which achieves a competitive ratio of $1 - \\frac{1}{e} \\simeq 0.63$. The algorithm, called Ranking, begins by permuting the known vertices of $U$ in a random permutation $\\pi$, i.e. we assign a random priority number to each $u \\in U$. Each incoming vertex $v \\in V$ is then assigned to an available neighbor, with the smallest value of $\\pi(u)$. In detail, the algorithm looks like this:\n\n\\begin{algorithm} % enter the algorithm environment\n    \\caption{Ranking} \n    \\label{alg:ranking} % and a label for \\ref{} commands later in the document\n    \\begin{algorithmic} % enter the algorithmic environment\n        \\State \\textbf{Offline:} Pick a random, uniform permutation $\\pi$ of U\n        \\ForEach {arriving vertex $v \\in V $}\n            \\If{$v$ has no available neighbors}\n                \\State continue\n            \\EndIf\n            \\State Match $v$ to the neighbor $u \\in U$ with the smallest value $\\pi(u)$\n        \\EndFor\n    \\end{algorithmic}\n\\end{algorithm}", "meta": {"hexsha": "32ba5d2f41405dca1af219e31155b459f91d0c0d", "size": 10724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/7_extensions.tex", "max_stars_repo_name": "aaronoe/bachelorarbeit", "max_stars_repo_head_hexsha": "b267dc2eb69cc7a1c2421b76277f69517957375d", "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/7_extensions.tex", "max_issues_repo_name": "aaronoe/bachelorarbeit", "max_issues_repo_head_hexsha": "b267dc2eb69cc7a1c2421b76277f69517957375d", "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": "chapters/7_extensions.tex", "max_forks_repo_name": "aaronoe/bachelorarbeit", "max_forks_repo_head_hexsha": "b267dc2eb69cc7a1c2421b76277f69517957375d", "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": 120.4943820225, "max_line_length": 908, "alphanum_fraction": 0.7657590451, "num_tokens": 2445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6163035464359232}}
{"text": "\\documentclass{article}\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{amsmath}\n\\usepackage{amsfonts}\n\n\\newcommand{\\R}{\\mathbb{R}}\n\n\\title{The effect of homophily in hierarchical systems}\n\n\\renewcommand{\\S}{\\mathcal{S}}\n\n\\begin{document}\n\n\\maketitle\n\n\n\\section{Mathematical formulation of base model}\n\n\\begin{itemize}\n    \\item Given a hierarchical system with \\(K\\) levels.\n    \\item Level \\(0\\leq k < K\\) has capacity \\(C_k\\)\n    \\item The first level (\\(k=0\\)) has the most capacity and capacity is\n        monotonically decreasing: \\(C_0 \\geq C_1 \\geq \\dots \\geq C_{k-2} \\geq C_{k-1} = 1\\).\n    \\item There are 2 types of agents: \\(j\\in\\{0, 1\\}\\).\n\\end{itemize}\n\nConsider a state space \\(\\S\\):\n\n\\begin{equation}\\label{eqn:state_space}\n    \\S = \\left\\{s \\in \\mathbb{Z} ^ {K \\times 2} _ {\\geq 0}\\left|\n        \\begin{array}{l}\n        s_{i0} + s_{i1} \\leq C_i\\text{ for all }0\\leq i \\leq K - 1\\\\\n        s_{K-1} = (1, 0)\\\\\n        \\sum_{i=0}^{K - 1}s_{i0} + s_{i1} \\in\\left\\{\\sum_{i=0}^{K - 1}C_i, \\sum_{i=0}^{K - 1}C_i - 1\\right\\}\\\\\n\n        \\end{array}\n                \\right.\\right\\}\n\\end{equation}\n%TODO comment on top row\nWhere \\(s_{ij}\\) denotes the number of individuals of type \\(j\\) at level \\(i\\).\n\nFor example,\n\n\\begin{itemize}\n    \\item Let \\(K = 3\\)\n    \\item Let \\(C = (4, 3, 1)\\)\n\\end{itemize}\n\nThen:\n\n\\[\n    s = \\begin{pmatrix}\n        3 & 1 \\\\\n        2 & 1 \\\\\n        1 & 0 \\\\\n    \\end{pmatrix}\n\\]\n\ncorresponds to a system with 3 agents of first type and 1 of second type at the\nfirst level, 2 of first type and 1 of second type at the second level and 1 of\neach type at the 3rd level.\n\nThe constraints on \\(\\S\\) ensure that either all positions are filled or a\nsingle position is available. Thus at any stage either all spots are full and\nsomeone will retire or there will be a spot available and someone will be\nhired/promoted.\n\nThe size of the state space is then given by:\n\n\\begin{equation}\n    |S| = \\prod_{i=0}^{K - 2}\\left(2C_i + 1\\right)\n\\end{equation}\n\nGiven two elements \\(s^{(1)}, s^{(2)}\\in \\S\\) the transition rates are given by:\n\n\\begin{equation}\\label{eqn:transition_rates}\n    Q_{s_1, s_2} =\n        \\begin{cases}\n            \\mu_{ij},& \\text{ if }s^{(2)} - s^{(1)} = -e_{ij}\n            \\text{ and }s^{(1)}_{i0} + s^{(1)}_{i1} = C_i\\text{ for all }i\\\\\n           \\text{max}(rs_{i + 1,j} + s_{i + 1, \\bar j}, 1),& \\text{ if }s^{(2)} - s^{(1)} = e_{ij} - e_{i-1, j}\n                                     \\text{ and }s^{(1)}_{i0} + s^{(1)}_{i1} < C_{i}\n                                     \\text{ and }i > 0\\\\\n           \\lambda_{j},&\\text{ if }s^{(2)} - s^{(1)} = e_{0j}\n                        \\text{ and }s^{(1)}_{00} + s^{(1)}_{01} = C_{0} - 1\\\\\n        \\end{cases}\n\\end{equation}\n\nWhere:\n\n\\begin{itemize}\n    \\item \\(\\mu_{ij}\\) is the retirement rate of agents of type \\(j\\) at level\n        \\(i\\).\n    \\item \\(r > 1\\) is a constant that reflects the homophily effect.\n    \\item \\(\\lambda_j\\) is the hiring rate of individuals of type \\(j\\).\n\\end{itemize}\n\n% TODO Add some examples.\n\n\\section{Mathematical formulation of model with competence}\n\nThe base model described in the previous section does not take into account the\ncompetence of the individuals. Let's consider the above example of:\n\n\\begin{itemize}\n    \\item \\(K = 3\\) and \\(C = (4, 3, 1)\\)\n\\end{itemize}\n\nA possible state \\(s\\) for the above configuration when competence is taken into\naccount is:\n\n\\[\n    s = \\begin{pmatrix}\n        (1, 0.1) & (1, 0.2) & (1, 0.3) & (0, 0.5) \\\\\n        (1, 0.2) & (1, 0.3) & (0, 0.8) \\\\\n        (1, 0.7) \\\\\n    \\end{pmatrix}\n\\]\n\nNote that this is a possible state for the configurations of \\(K\\) and \\(C\\) but\nnot the only one. The competence of each individual can be any real number between\n\\([0, 1]\\), thus there are an infinite number of possible states.\n\nThe set of possible states, denoted as \\(S\\), is given by,\n\n\\begin{equation}\\label{eqn:state_space}\n    \\S = \\left\\{\n        s \\in (\\{0, 1\\}, \\R^{[0,1]}) ^ {K \\times C}  \\left|\n        \\begin{array}{l}\n         s_{i,j} = (l_{i, j}, c_{i, j}) \\quad \\forall i \\in [0, K -1] \\quad \\forall j \\in [C_i - 1, C_i] \\\\\n        \\text{ where } l_{i, j} \\in \\{0, 1\\} \\text{ and } c_{i, j} \\in \\R^{[0,1]} \\\\\n        |s_{k - 1}| = 1  \\\\\n        l_{k -1, 1} = 0\n    \\end{array}\n    \\right.\\right\\}\n\\end{equation}\n\nwhere \\(s_{i, j}\\) is a tuple of \\((l_{i, j}, c_{i, j})\\) where \\(l_{i, j}\\) is the\ntype of individual \\(j\\) at level \\(i\\) and \\(c_{i, j}\\) is the individual's\ncompetence.\n\nPromotion in the competence model assumes that individuals of the same type give a random\nbonus to the competence of individuals like them.\nThus for a state \\(s\\) where a promotion is happening at level \\(i\\), the promotion\nprobability of an individual \\(j\\) at level \\(i - 1\\) is given by:\n\n\\begin{equation}\n    P(i, j) =\n    \\frac{\n    \\displaystyle \\sum_{t = 1} ^ {C_{i -1} - 1} \\text{max}((1 - |l_{i-i, t} - l_{i, j}|) \\gamma_t, 1) \\ c_{i, j}}\n    {\n    \\displaystyle \\sum_{\\bar{j}=1}^{C_i} \\sum_{t = 1} ^ {C_{i -1} - 1} \\text{max}((1 - |l_{i-i, t} - l_{i, j}|) \\gamma_t, 1) \\ c_{i, \\bar{j}}\n    },\n\\end{equation}\n\nwhere \\(\\gamma_{t} > 1\\) is randomly sampled at each \\(t\\) from \\([0, \\Gamma]\\).\n\nThus, the transition rates between two states are given by:\n\n\\begin{equation}\\label{eqn:transition_rates}\n        \\begin{cases}\n            \\mu_{ij},& |s_i| = C_i\\text{ for all }i\\\\\n            P(i, j), & |s_i| < C_{i} \\text{ and }i > 0\\\\\n           \\lambda_{(l, c)},& |s_{0}| = C_0 - 1\\\\\n        \\end{cases}\n\\end{equation}\n\nWhere:\n\n\\begin{itemize}\n    \\item \\(\\mu_{ij}\\) is the retirement rate of the agent \\(j\\) at level\n        \\(i\\).\n    \\item \\(\\lambda_{(l, c)}\\) is the hiring rate of an individual \\(l\\) that has\n    a competence \\(c\\).\n\\end{itemize}\n\nThe competence of the system is the total competence of the individuals in the\nsystem regarding their type.\n\n\\begin{equation}\\label{eqn:state_space}\n    \\sum_{i = 0} ^ {K - 1} \\sum_{j=1} ^ {C_i} c_{i, j}\n\\end{equation}\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "b8947dda75ebf1ee036bc8c88cc55102b86959e2", "size": 6102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "drvinceknight/HierarchicalPromotion", "max_stars_repo_head_hexsha": "8fce38c4dc9b21f50a8ef769482fd6a82cf0e6a3", "max_stars_repo_licenses": ["MIT"], "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": "drvinceknight/HierarchicalPromotion", "max_issues_repo_head_hexsha": "8fce38c4dc9b21f50a8ef769482fd6a82cf0e6a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-10-01T06:47:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-18T13:10:20.000Z", "max_forks_repo_path": "main.tex", "max_forks_repo_name": "drvinceknight/HierarchicalPromotion", "max_forks_repo_head_hexsha": "8fce38c4dc9b21f50a8ef769482fd6a82cf0e6a3", "max_forks_repo_licenses": ["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.6165803109, "max_line_length": 141, "alphanum_fraction": 0.5806293019, "num_tokens": 2212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.61624043323956}}
{"text": "\\documentclass[12pt]{article}\r\n\\usepackage{amsmath}\r\n\\usepackage{txfonts}\r\n\r\n%- Abbreviations.\r\n\\newcommand{\\psf}{\\mathbf{H}}\r\n\\newcommand{\\G}{\\mathbf{G}}\r\n\\newcommand{\\p}{\\mathbf{p}}\r\n\\newcommand{\\phat}{\\mathbf{\\hat p}}\r\n\\newcommand{\\hhat}{\\mathbf{\\hat h}}\r\n\\newcommand{\\x}{\\mathbf{x}}\r\n\\newcommand{\\xhat}{\\mathbf{\\hat x}}\r\n\\newcommand{\\y}{\\mathbf{y}}\r\n\\newcommand{\\rvect}{\\mathbf{r}}\r\n\\newcommand{\\W}{\\mathbf{W}}\r\n\\newcommand{\\A}{\\mathbf{A}}\r\n\\newcommand{\\avec}{\\mathbf{a}}\r\n\\newcommand{\\F}{\\mathbf{F}}\r\n\\newcommand{\\V}{\\mathbf{V}}\r\n\\newcommand{\\diag}{\\mathrm{diag}}\r\n\r\n\\newcommand{\\ddx}{\\frac{\\partial}{\\partial \\mathbf{x}}}\r\n\\newcommand{\\ddxi}{\\frac{\\partial}{\\partial x_i}}\r\n\r\n\\newcommand{\\Nsn}{\\textbf{XXX}}\r\n\\newcommand{\\Nspec}{\\textbf{YYY}}\r\n\r\n\r\n\\newcommand{\\rem}[1]{\\textbf{[\\textsl{#1}]}}\r\n\\newcommand{\\szf}[1]{\\textbf{\\textsl{SZF: #1}}}\r\n\r\n% -----------------------------------------------------------------------------\r\n% Document\r\n\r\n\\begin{document}\r\n\r\n\\title{CubeFit $\\chi^2$ gradient calculation}\r\n\\author{S.~Bongard, Kyle~Barbary, Clare~Saunders}\r\n\\maketitle\r\n\\begin{abstract}\r\nIn CubeFit, one of the fitting steps is to fit the galaxy model to the\r\ndata while holding other parameters (such as positions) fixed. The\r\ngalaxy model has on the order of one million parameters. The ability to\r\nanalytically calculate the gradient (a vector of length $\\sim$ 1\r\nmillion) on the fit $\\chi^2$ is essential in order to carry out the fit\r\nefficiently. This note explains the derivation of the gradient function.\r\n\\end{abstract}\r\n\r\n\r\n\\section{The Gradient}\r\n\r\nThe $\\chi^2$ in the galaxy fit is given by\r\n\r\n\\begin{equation}\r\n\\chi^2 = (\\y - \\G\\x)^T \\W (\\y - \\G\\x)\r\n\\end{equation}\r\n\r\n\\noindent where $\\y$ is the data, $\\x$ is the model parameters, $\\W$\r\nis the weight matrix (inverse covariance matrix; diagonal in our case)\r\nand $\\G$ is the operator that translates the model into the data\r\nframe. $\\G$ includes the effect of PSF convolution, shift operation\r\nand cropping. Note that we are supposing that we can represent all\r\nthese operations as a matrix $\\G$, but we will not show this until a\r\nlater section. Remember also that this is all in real space.  Carrying\r\non,\r\n\r\n\\begin{eqnarray*}\r\n  \\label{eq:5}\r\n  \\ddx \\chi^{2} & = & \\ddx \\left( (\\y - \\G\\x)^{T} \\W (\\y - \\G\\x) \\right)\\\\\r\n                & = & \\ddx \\left( (\\G \\x)^{T} \\W \\G \\x \\right)\r\n                    - \\ddx \\left( (\\G \\x)^{T} \\W \\y \\right)\r\n                    - \\ddx \\left( \\y^{T} \\W \\G \\x \\right) \\\\\r\n                & = & \\ddx \\left( \\x^{T} \\G^{T} \\W \\G \\x \\right)\r\n                    - \\ddx \\left( \\x^{T} \\G^{T} \\W \\y \\right)\r\n                    - \\ddx \\left( (\\G^{T} \\W \\y)^{T} \\x \\right)\r\n\\end{eqnarray*}\r\n\r\n\\noindent where in the second line we have simply separated terms, dropping the\r\nconstant term $\\y^T \\W \\y$, and in the third line we have used the property\r\nthat $(\\mathbf{A}\\mathbf{B})^T = \\mathbf{B}^T\\mathbf{A}^T$ and assumed that\r\n$\\W = \\W^T$ (the weight matrix is symmetric).\r\n\r\nWe note that $(\\G^{T} \\W \\y)^{T}$ and $\\G^{T} \\W \\y$ are vectors ($\\y$ is a\r\nvector). The first two terms of the equation are thus of the form\r\n$\\ddx \\x^T \\avec$ and $\\ddx \\avec^T \\x$. These are both simply equal to\r\n$\\avec$ as $\\x^T \\avec$ and $\\avec^T \\x$ are dot products between the\r\nconstant vector $\\avec$ and $\\x$, so the partial derivative with respect to\r\n$\\x$ is just $\\avec$. Making this substitution, we have\r\n\r\n\\begin{equation}\r\n\\ddx \\chi^{2} = \\ddx \\left( \\x^{T} \\G^{T} \\W \\G \\x \\right) - 2 \\G^T \\W \\y \r\n\\end{equation}\r\n\r\n\\noindent The first term has the form $\\ddx \\x^T\\A\\x$, with\r\n$\\A = \\G^T \\W \\G$. It helps to write this out:\r\n\r\n\\begin{eqnarray*}\r\n  \\ddxi \\x^{T}\\A\\x & = & \\ddxi \\left( \\sum_{j} x_{j} \\sum_l A_{j,l} x_{l}  \\right) \\\\\r\n                   & = & \\sum_l A_{i,l} x_{l} + \\sum_j A_{j,i} x_{j} \\\\\r\n                   & = & \\left( \\A \\x + \\A^{T} \\x␇ \\right)_{i}\r\n\\end{eqnarray*}\r\n\r\n\\noindent or without the $i$ subscripts,\r\n\r\n\\begin{equation}\r\n  \\ddx \\x^T\\A\\x = (\\A + \\A^T) \\x\r\n\\end{equation}\r\n\r\n\\noindent Substituting this in (with $\\A = \\G^T \\W \\G$), we finally get:\r\n\r\n\\begin{eqnarray*}\r\n\\ddx \\chi^{2} & = & \\left( \\G^T \\W \\G \\x + (\\G^T \\W \\G)^T \\x \\right)\r\n                 - 2 \\G^T \\W \\y \\\\\r\n             & = & 2 \\G^T \\W \\G \\x - 2 \\G^T \\W \\y \\\\\r\n             & = & -2 \\G^T \\W ( \\y - \\G \\x ) \\\\\r\n             & = & -2 \\G^T \\W \\rvect \\\\\r\n\\end{eqnarray*}\r\n\r\n\\noindent where $\\rvect$ is shorthand for the residual\r\n$\\y - \\G \\x$. But what is the matrix $\\G$ and what is $\\G^T$?\r\nFor that we need to digress about\r\nFourier transforms as matricies (in the next section).\r\n\r\n\\section{Discrete Fourier Transform: Matrix Form}\r\n\r\nThe discrete Fourier transform of a vector $x_n$ is\r\n\r\n\\begin{equation}\r\n\\hat{x}_k = \\sum_{n=0}^{N-1} x_n e^{-i 2 \\pi k n / N}\r\n\\end{equation}\r\n\r\n\\noindent We can write this in matrix form,\r\n\r\n\\begin{equation}\r\n\\xhat = \\left( \\begin{array}{cccc}\r\n   e^{-i 2\\pi 0 \\cdot 0 / N} & e^{-i 2\\pi 0\\cdot 1 / N} & e^{-i 2\\pi 0 \\cdot 2 / N} & \\cdots \\\\\r\n   e^{-i 2\\pi 1 \\cdot 0 / N} & e^{-i 2\\pi 1 \\cdot1 / N} & e^{-i 2\\pi 1 \\cdot 2 / N} & \\cdots \\\\\r\n   e^{-i 2\\pi 2 \\cdot 0 / N} & e^{-i 2\\pi 2 \\cdot 1 / N} & e^{-i 2\\pi 2 \\cdot 2 / N} & \\cdots \\\\\r\n   \\vdots & \\vdots & \\vdots & \\ddots\r\n   \\end{array} \\right)\r\n   \\left( \\begin{array}{c} x_0 \\\\ x_1 \\\\ x_2 \\\\ \\vdots \\end{array} \\right)\r\n\\end{equation}\r\n\r\n\\noindent For a shorthand, we will call the square matrix $\\mathbf{F}$\r\n\r\n\\begin{equation}\r\n\\xhat = \\F \\x\r\n\\end{equation}\r\n\r\nSimilarly, the inverse transform can be written\r\n\r\n\\begin{equation}\r\nx_n = \\frac{1}{N} \\sum_{k=0}^{N-1} \\hat{x}_k e^{i 2 \\pi k n / N}\r\n\\end{equation}\r\n\r\n\\noindent or\r\n\r\n\\begin{equation}\r\n   \\mathbf{x} = \\frac{1}{N} \\left( \\begin{array}{cccc}\r\n   e^{i 2\\pi 0 \\cdot 0 / N} & e^{i 2\\pi 1 \\cdot 0 / N} & e^{i 2\\pi 2 \\cdot 0 / N} & \\cdots \\\\\r\n   e^{i 2\\pi 0 \\cdot 1 / N} & e^{i 2\\pi 1 \\cdot 1 / N} & e^{i 2\\pi 2 \\cdot 1 / N} & \\cdots \\\\\r\n   e^{i 2\\pi 0 \\cdot 2 / N} & e^{i 2\\pi 1 \\cdot 2 / N} & e^{i 2\\pi 2 \\cdot 2 / N} & \\cdots \\\\\r\n   \\vdots & \\vdots & \\vdots & \\ddots\r\n   \\end{array} \\right)\r\n   \\left( \\begin{array}{c} \\hat{x}_0 \\\\ \\hat{x}_1 \\\\ \\hat{x}_2 \\\\ \\vdots \\end{array} \\right)\r\n\\end{equation}\r\n\r\n\\noindent or as shorthand,\r\n\r\n\\begin{equation}\r\n\\x = \\F^{-1} \\xhat\r\n\\end{equation}\r\n\r\n\\noindent Now, note that the matrix $\\F$ has the property\r\n\r\n\\begin{equation}\r\n\\F^{-1} = \\frac{1}{N} \\bar{\\F}\r\n\\end{equation}\r\n\r\n\\noindent where $\\bar{\\F}$ is the element-wise complex conjugate of $\\F$.\r\n\r\n\r\n\\section{The $\\G$ matrix }\r\n\r\nThe $\\G$ matrix represents the operations applied to the model to put\r\nit \"in the data frame\". These are (1) convolve model by PSF (2) shift\r\nmodel to align with data (3) crop model indicies that extend past the\r\ndata (model is spatially larger than data). Convolution in real space\r\nis equivalent to element-wise multiplication (the Hadamard product) in\r\nFourier space (and this is indeed how the convolution is implemented\r\nin CubeFit). While element-wise multiplication can be written\r\n$\\mathbf{a} \\circ \\mathbf{b}$, we will find it useful to write it as\r\n$\\diag(\\mathbf{a}) \\mathbf{b}$, where diag() is an operator\r\nthat translates a vector into a square diagonal matrix with the same\r\nentries.\r\n\r\nConvolution of the galaxy model $\\x$ by a real-space PSF $\\p$ can thus be\r\nwritten as\r\n\\begin{equation}\r\n\\F^{-1} \\diag(\\F \\p) \\F \\x\r\n\\end{equation}\r\n\r\nSimilarly, spatial shifts are implemented as element-wise multiplication in\r\nFourier space. the key point being that we can\r\nsubsume this shift vector (or rather the Fourier transform of it) into\r\n$\\F \\p = \\phat$. Therefore, we can write $\\G$ as\r\n\r\n\\begin{equation}\r\n\\G = \\F^{-1} \\diag(\\phat) \\F\r\n\\end{equation}\r\n\r\nWe are now interested in calculating $\\G^T$ as it appears in the\r\nequation for $\\ddx \\chi^{2}$. Simply taking the transpose, we get\r\n$\\G^{T} = \\F^T \\diag(\\phat)^{T} \\F^{-1T}$, but we would like\r\nto rewrite this in a form that has the Fourier transforms in the same\r\norder as in $\\G$. Since $\\G$ is a real operator, we have $\\G =\r\n\\bar{\\G}$, and thus $\\G^T = \\bar{\\G}^T$. We will use this along with\r\nthe relation between the forward and reverse Fourier transform derived\r\nabove ($\\F^{-1} = \\frac{1}{N} \\bar{F}$), and the fact that the\r\ntranspose of a diagonal matrix is the matrix itself. We find:\r\n\r\n\\begin{eqnarray*}\r\n  \\G^{T} & = & \\F^{T} \\diag(\\phat)^{T} \\F^{-1T}\\\\\r\n        & = & \\overline{\\F^{T} \\diag(\\phat)^{T} \\F^{-1T}} \\\\\r\n        & = & \\bar{\\F}^T \\overline{\\diag(\\phat)^T} \\bar{\\F}^{-1T} \\\\\r\n        & = & N\\F^{-1} \\overline{\\diag(\\phat)} \\frac{1}{N}\\F \\\\\r\n        & = & \\F^{-1} \\overline{\\diag(\\phat)} \\F\\\\\r\n\\end{eqnarray*}\r\n\r\n\\noindent If we now write the residual $\\rvect = \\y - \\G\\x$, we\r\nfinally find that the derivative of $\\chi^{2}$ is:\r\n\r\n\\begin{eqnarray*}\r\n \\ddx \\chi^2 & = & -2 \\G^T \\W \\rvect \\\\\r\n             & = & -2 \\F^{-1} \\overline{\\diag(\\phat)} \\F \\W \\rvect\r\n\\end{eqnarray*}\r\n\r\n\\noindent In CubeFit, the operator $\\G^T = \\F^{-1}\r\n\\overline{\\diag(\\phat)} \\F$ is currently implemented by the method\r\n\\verb|AtmModel.gradient_helper()|.\r\n\r\n\\section{Fitting galaxy and sky simultaneously}\r\n\r\nIn another step in CubeFit, we fit the galaxy model to multiple epochs\r\nof data simultaneously, while adjusting the sky for each epoch on each\r\niteration.  On each iteration, the sky is calculated by taking the\r\nweighted average of the residual ($\\y - \\G \\x$) at each wavelength and\r\nsubtracting that to form the new residual. We need to take this into\r\naccount in the $\\chi^2$ gradient: qualitatively, increasing any given\r\nmodel pixel will result in a lower sky estimate, and the sky estimate\r\nfeeds back into the $\\chi^2$. The actual $\\chi^2$ we're using involves\r\nthe residual $\\y - \\G\\x - \\mathrm{avg}(\\y - \\G\\x)$. where avg() is a\r\nweighted average over wavelength. Fortunately, this weighted average\r\ncan be represented by a matrix multiply. For example,\r\n\r\n\\begin{equation}\r\n  \\left( \\begin{array}{cccc}\r\n   \\frac{w_0}{w_0 + w_1} & \\frac{w_1}{w_0 + w_1} & 0 & 0 \\\\\r\n   \\frac{w_0}{w_0 + w_1} & \\frac{w_1}{w_0 + w_1} & 0 & 0 \\\\\r\n   0   & 0   & \\frac{w_2}{w_2 + w_3} & \\frac{w_3}{w_2 + w_3} \\\\\r\n   0   & 0   & \\frac{w_2}{w_2 + w_3} & \\frac{w_3}{w_2 + w_3} \\\\\r\n   \\end{array} \\right)\r\n   \\left( \\begin{array}{c} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{array} \\right)\r\n\\end{equation}\r\n\r\n\\noindent yields a vector whose first two entries are the weighted\r\naverage across the first two entries of $\\x$ and whose last two\r\nentries are the weighted average across the last two entries of\r\n$\\x$. Call this matrix $\\V$. The weighted average of the residual is then\r\n$\\V (\\y - \\G\\x)$ and the $\\chi^2$ for each epoch is\r\n\r\n\\begin{eqnarray*}\r\n\\chi^2 &=& (\\y - \\G\\x - \\V(\\y - \\G\\x))^T \\W (\\y - \\G\\x - \\V(\\y - \\G\\x)) \\\\\r\n       &=& ((I - \\V)(\\y - \\G\\x))^T \\W ((I - \\V)(\\y - \\G\\x)) \\\\\r\n       &=& (\\y - \\G\\x)^T (I - \\V)^T \\W (I - \\V) (\\y - \\G\\x)\r\n\\end{eqnarray*}\r\n\r\n\\noindent where in the third line we have used the equality\r\n$(\\mathbf{A}\\mathbf{B})^T = \\mathbf{B}^T \\mathbf{A}^T$. This is the\r\nsame as the original $\\chi^2$ equation, but with $\\W$ replaced by $(I\r\n- \\V)^T \\W (I - \\V)$. This is a constant, so our original result for the\r\n$\\chi^2$ gradient holds under this replacement:\r\n\r\n\\begin{eqnarray*}\r\n\\W \\rvect &\\to& (I - \\V)^T \\W (I - \\V) \\rvect \\\\\r\n          &\\to& (I - \\V)^T \\W \\mathbf{r'} \\\\\r\n          &\\to& \\W \\mathbf{r'} - \\V^T \\W \\mathbf{r'}\r\n\\end{eqnarray*}\r\n\r\n\\noindent where $\\mathbf{r'} = (I - \\V)(\\y - \\G\\x)$ is the residual after\r\nsubtracting the ``sky.''\r\n\r\nPractically, how do we calculate $\\V^T \\W \\mathbf{r'}$? In other words, if\r\nmultiplication by $\\V$ is equivalent to a weighted average by wavelength,\r\nwhat is $\\V^T$? In our minimal example from above, it would be\r\n\r\n\\begin{equation}\r\n  \\V^T \\x\r\n  = \\left( \\begin{array}{cccc}\r\n    \\frac{w_0}{w_0 + w_1} & \\frac{w_0}{w_0 + w_1} & 0 & 0 \\\\\r\n    \\frac{w_1}{w_0 + w_1} & \\frac{w_1}{w_0 + w_1} & 0 & 0 \\\\\r\n    0   & 0   & \\frac{w_2}{w_2 + w_3} & \\frac{w_2}{w_2 + w_3} \\\\\r\n    0   & 0   & \\frac{w_3}{w_2 + w_3} & \\frac{w_3}{w_2 + w_3} \\\\\r\n    \\end{array} \\right)\r\n    \\left( \\begin{array}{c} x_0 \\\\ x_1 \\\\ x_2 \\\\ x_3 \\end{array} \\right)\r\n  = \\left( \\begin{array}{c}\r\n    \\frac{w_0}{w_0 + w_1} (x_0 + x_1) \\\\\r\n    \\frac{w_1}{w_0 + w_1} (x_0 + x_1) \\\\\r\n    \\frac{w_2}{w_2 + w_3} (x_2 + x_3) \\\\\r\n    \\frac{w_3}{w_2 + w_3} (x_2 + x_3)\r\n    \\end{array} \\right)\r\n\\end{equation}\r\n\r\n\\noindent Looking at the result, we can see this is equivalent to, for\r\neach wavelength, taking the ratio of the sum of the input vector and\r\nthe sum of $\\W$ and multiplying the result by $\\W$. In Python (where\r\nwe are representing $\\W$ and $\\x$ with 3-d arrays), $\\V^T \\W \\mathbf{r'}$\r\nwould be\r\n\r\n\\begin{verbatim}\r\ntmp = np.sum(w * rprime, axis=(1, 2)) / np.sum(w, axis=(1, 2))\r\nvtwrprime = w * tmp[:, None, None]\r\n\\end{verbatim}\r\n\r\n\\noindent where $\\W$ is \\verb|w| and $\\mathbf{r'}$ is \\verb|rprime|, and the\r\nfull replacement for $\\W \\rvect$ would be:\r\n\r\n\\begin{verbatim}\r\nw * rprime - vtwrprime\r\n\\end{verbatim}\r\n\r\n\\section{Fitting SN and Data Positions}\r\n\r\nIn the final step of CubeFit, we fit simultaneously the position of\r\nthe data with respect to the galaxy and the position of the SN with\r\nrespect to the galaxy. Here, we calculate the analytic gradient of the\r\n$\\chi^2$ function used in this fit.\r\n\r\n\\begin{eqnarray*}\r\n\\chi^2 &=& \\sum_{t, \\lambda} \\sum_i w_i (d_i - (scene)_i)^2 \\\\\r\n       &=& \\sum_{t, \\lambda} \\sum_i w_i (d_i - (sky + g_i + SN s_i))^2\r\n\\end{eqnarray*}\r\n\r\n\\noindent where the first sum is over epochs and wavelengths and the\r\nsecond sum is over pixels at a give wavelength. $g_i$ and $s_i$ depend\r\non the positions that we are optimizing, as do $sky$ and $SN$, which\r\nare determined based on the galaxy model, $\\vec{g}$ and SN model,\r\n$\\vec{s}$.  The derivative of $\\chi^2$ with respect to the position\r\n$x_j$ of the data is\r\n\r\n\\begin{eqnarray*}\r\n\\frac{d\\chi^2}{dx_\\ast} &=& \\sum_{t, \\lambda} \\sum_i -2 w_i (d_i - (scene)_i) \\frac{d(scene)_i}{dx_\\ast} \\\\\r\n                     &=& \\sum_{t, \\lambda} \\sum_i -2 w_i (d_i - (scene)_i) \\frac{d}{dx_\\ast} (sky + g_i + SN s_i) \\\\\r\n                     &=&  \\sum_{t, \\lambda} \\sum_i -2 w_i (d_i - (scene)_i) \\left(\\frac{d(sky)}{dx_\\ast} + \\frac{dg_i}{dx_\\ast} + \\frac{d(SN)}{dx_\\ast} s_i + SN \\frac{ds_i}{dx_\\ast}\\right)\r\n\\end{eqnarray*}\r\n\r\n\\noindent If $x_\\ast$ is an SN position parameter then $dg_i/dx_\\ast = 0$,\r\nbut otherwise all terms above are nonzero: $sky$ and $SN$\r\ndepend on $x_\\ast$ through their dependence on $\\vec{g}$ and\r\n$\\vec{s}$. The derivatives $dg_i/dx_\\ast$ and $ds_i/dx_\\ast$ are fairly\r\nsimple to compute. $\\vec{g}$ and $\\vec{s}$ are computed via\r\nmultiplication by a phase shift array in Fourier space. The phase\r\nshift array is the only part that depends on position and everything\r\nelse is just multiplication. So all we need to do is to subsitute the\r\nderivative on the phase shift array, then carry out all calculations\r\nas we normally would.\r\n\r\nWe must also determine the gradient in $sky$ and $SN$ with respect to\r\nposition.  We start by defining some quantities for\r\nconvenience (in the left column), and taking their derivatives with respect to\r\ndata and SN positions. (Note that $s_i$ is affected by both positions, $g_i$ is only affected by the data position.)\r\n\r\n\\begin{displaymath}\r\n%denom = AC - B^2\r\n\\begin{array}{ccc}\r\nA = \\sum_i w_i s_i^2    & \\frac{dA}{dx_\\ast} = \\sum_i 2 w_i s_i \\frac{ds_i}{dx_\\ast}   &   (x_\\ast \\in \\{x_{data}, x_{sn}\\}) \\\\\r\nB = \\sum_i w_i s_i    & \\frac{dB}{dx_\\ast} = \\sum_i w_i \\frac{ds_i}{dx_\\ast} \\\\\r\nC = \\sum_i w_i         & \\frac{dC}{dx_\\ast} = 0 \\\\\r\nD = \\sum_i w_i d_i     & \\frac{dD}{dx_\\ast} = 0 \\\\% wd\r\nE = \\sum_i w_i d_i s_i  & \\frac {dE}{dx_\\ast} = \\sum_i w_i d_i  \\frac{ds_i}{dx_\\ast} \\\\ % wdsn\r\nF = \\sum_i w_i g_i     & \\frac{dF}{dx_{data}} = \\sum_i w_i \\frac{dg_i}{dx_{data}}   &    \\frac{dF}{dx_{sn}} = 0 \\\\ % wgal\r\nG = \\sum_i w_i g_i s_i  & \\frac{dG}{dx_{data}} = \\sum_i w_i \\left(g_i \\frac{ds_i}{dx_{data}} + s_i \\frac{dg_i}{dx_{data}} \\right) & \\frac{dG}{dx_{sn}} = \\sum_i w_i g_i \\frac{ds_i}{dx_{sn}} % wgalsn\r\n\\end{array}\r\n\\end{displaymath}\r\n\r\n\\noindent where $i$ ranges over all pixels at the given wavelength,\r\n$s_i$ is the SN model (scaled to 1) $g_i$ is the galaxy model, $d_i$\r\nis the data and $w_i$ is the weight of the data. The SN amplitude, a\r\nscalar here, is given by\r\n\r\n\\begin{equation}\r\nSN = (-DB + EC + FB - GC) / (AC - B^2)\r\n\\end{equation}\r\n\r\n\\noindent (Derivation not shown.) Taking the derivative with\r\nrespect to $x_\\ast$,\r\n\r\n\\begin{eqnarray*}\r\n\\frac{d(SN)}{dx_\\ast} &=& \\frac{-D'B - DB' + E'C + EC' + F'B + FB' - G'C - GC'}{AC - B^2} + \\\\\r\n                     & & (SN) \\frac{A'C + AC' - 2BB'}{AC-B^2} \\\\\r\n                     &=& \\frac{-DB' + E'C + F'B + FB' - G'C}{AC - B^2} + (SN) \\frac{A'C - 2BB'}{AC-B^2}\r\n\\end{eqnarray*}\r\n\r\nSimilar to the SN amlitude, the sky is given by\r\n\r\n\\begin{equation}\r\nsky = (DA - EB - FA + GB) / (AC - B^2)\r\n\\end{equation}\r\n\r\n\\noindent The derivative is\r\n\r\n\\begin{eqnarray*}\r\n\\frac{d(sky)}{dx_\\ast} &=& \\frac{D'A + DA' - E'B - EB' - F'A - FA' + G'B + GB'}{AC - B^2} + \\\\\r\n                   & &  + (sky) \\frac{A'C + AC' - 2BB'}{AC-B^2} \\\\\r\n                   &=& \\frac{DA' - E'B - EB' - F'A - FA' + G'B + GB'}{AC - B^2} + (sky) \\frac{A'C - 2BB'}{AC-B^2}\r\n\\end{eqnarray*}\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "88ccce31ee36a565339f6b3b73f3d6a4268bd071", "size": 17187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/gradient.tex", "max_stars_repo_name": "kbarbary/cubefit", "max_stars_repo_head_hexsha": "d242985d2cf9fafb297da9903ba8ede3ac8a57a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-07-23T22:49:50.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-04T07:26:31.000Z", "max_issues_repo_path": "docs/gradient.tex", "max_issues_repo_name": "kbarbary/cubefit", "max_issues_repo_head_hexsha": "d242985d2cf9fafb297da9903ba8ede3ac8a57a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2015-06-02T00:08:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-27T01:28:58.000Z", "max_forks_repo_path": "docs/gradient.tex", "max_forks_repo_name": "kbarbary/cubefit", "max_forks_repo_head_hexsha": "d242985d2cf9fafb297da9903ba8ede3ac8a57a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-09-24T16:41:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-25T19:20:12.000Z", "avg_line_length": 40.9214285714, "max_line_length": 198, "alphanum_fraction": 0.6014429511, "num_tokens": 6277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6161188564545755}}
{"text": "\\subsection{Position space representation}\n\nFirst we define the time integral of the Lagrangian of the classical oscillator given in Eq.~(\\ref{eq_5}), over a period $T=2\\pi/\\omega$ as\n\\begin{equation} \\label{eq_b1}\n  \\Delta_{\\varepsilon} = \\frac{1}{T} \\int_0^T dt' \\; L(\\zeta,\\dot{\\zeta},t').\n\\end{equation}\nAdditionally, performing this integral, we can obtain a more simplified result\n\\begin{equation} \\label{eq_b2}\n  \\Delta_{\\varepsilon} = \\frac{(eE)^2}{4m_e(\\omega_0^2 - \\omega^2)}.\n\\end{equation}\nNext, we define another parameter\n\\begin{equation} \\label{eq_b3}\n  \\xi =\n  \\int_0^t dt' \\; L(\\zeta,\\dot{\\zeta},t') -\n  \\Delta_{\\varepsilon} t,\n\\end{equation}\nand after simplifying, we can identify\n\\begin{equation} \\label{eq_b4}\n  \\xi =\n  \\frac{(eE)^2\\qty(3\\omega^2 - \\omega_0^2)}{8m_e\\omega(\\omega_0^2 - \\omega^2)^2} \\sin(2\\omega t),\n\\end{equation}\nwhich is a periodic function in time. Using these parameters, we can factorize the wave function given in Eq.~(\\ref{eq_2}) as linearly time dependent part and periodic time dependent part as follows\n\\begin{equation} \\label{eq_b5}\n  \\begin{aligned}\n    \\psi_{\\alpha}&(x,y,t)  =\n    \\exp(\\frac{i}{\\hbar}\\qty[-\\epsilon_nt + \\Delta_{\\varepsilon} t ])\n    \\frac{1}{\\sqrt{L_x}} \\chi_n\\big(y - y_0 - \\zeta(t)\\big)\n    \\\\\n    & \\times\n    \\text{exp}\\bigg(\n     \\frac{i}{\\hbar}\\bigg[\n     p_x x +\n     \\frac{eEy}{\\omega}\\cos(\\omega t) \\\\\n     & \\quad+\n     m_e\\dot{\\zeta(t)}\\big[y-\\zeta(t)\\big]\n     + \\int_0^{t}dt'L(\\zeta,\\dot{\\zeta},t') - \\Delta_{\\varepsilon} t  \\bigg]\n     \\bigg).\n  \\end{aligned}\n\\end{equation}\nThis leads to separate the linear time dependent phase component as the quasienergies\n\\begin{equation} \\label{eq_b6}\n  \\varepsilon_{n} =\n  \\hbar \\omega_0\\qty(n + \\frac{1}{2}) - \\Delta_{\\varepsilon},\n\\end{equation}\nwhile rest of the components as time-periodic Floquet modes\n\\begin{equation} \\label{eq_b7}\n  \\begin{aligned}\n    \\phi_{n,m}(x,y,t) =  &\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\left(y - y_0 - \\zeta(t)\\right)\n    \\text{exp}\\bigg(\n     \\frac{i}{\\hbar}\\bigg[\n     p_x x \\\\\n     & +\n     \\frac{eE[y - y_0]}{\\omega}\\cos(\\omega t) \\\\\n     & +\n     m_e\\dot{\\zeta}(t)\\big[y - y_0 -\\zeta(t)\\big]\n     + \\xi \\bigg]\\bigg).\n  \\end{aligned}\n\\end{equation}\n\n\\subsection{Momentum space representation}\n\nWe perform continuous Fourier transform over the considering confined space $A=L_xL_y$ on the Floquet modes given in Eq.~(\\ref{eq_7}) to realize the Floquet modes in momentum space\n\\begin{equation} \\label{eq_b8}\n  \\begin{aligned}\n    \\phi_{n,m}&(k_x,k_y,t) \\\\\n    & =\n    \\exp(\n     \\frac{-i\\gamma(t)}{\\hbar}\n     y_0)\n    \\exp(\\frac{-i}{\\hbar}\n    \\qty[\n    m_e \\dot{\\zeta}(t) \\zeta(t) - \\xi\n    ])\\\\\n    & \\quad\\times\n    \\int_{-L_y/2}^{L_y/2} dy\\; \\exp(-i\\qty[k_y - \\gamma(t)]y)\n    \\chi_{n}\\qty[y - \\mu(t)] \\\\\n     & \\quad\\times\n     \\frac{1}{\\sqrt{L_x}}\n     \\int_{-L_x/2}^{L_x/2} dx\\;\n     \\exp(-ik_x x)\n     \\exp( \\frac{i p_x }{\\hbar}x ).\n  \\end{aligned}\n\\end{equation}\nHere we used new two parameters\n\\begin{equation} \\label{eq_b9a}\n  \\mu(t) = \\frac{eE\\sin(\\omega t)}{m_e(\\omega_0^2 - \\omega^2)} + y_0,\n\\end{equation}\nand\n\\begin{equation} \\label{eq_b9b}\n  \\gamma(t) =\n  \\frac{eE\\omega_0^2\\cos(\\omega t)}{\\hbar\\omega(\\omega_0^2 - \\omega^2)}.\n\\end{equation}\nSubsequenty, using the Fourier transform identity \\cite{bruus04}\n\\begin{equation} \\label{eq_b10}\n  \\int_{L_x} dx\\;\n  \\exp( -ik_x x + \\frac{i p_x }{\\hbar}x ) =\n  L_x \\delta_{k_x,\\frac{p_x}{\\hbar}},\n\\end{equation}\nwe can derive\n\\begin{equation} \\label{eq_b11}\n  \\begin{aligned}\n    \\phi_{n,m}&(k_x,k_y,t)  =\n    \\Phi_{n,m}(k_y,t)\n    \\delta_{k_x,\\frac{p_x}{\\hbar}}\\\\\n    & \\times\n    \\exp(\n     \\frac{-i\\gamma(t)}{\\hbar}\n     y_0)\n    \\exp(\\frac{-i}{\\hbar}\n    \\qty[\n    m_e \\dot{\\zeta}(t) \\zeta(t) - \\xi\n    ]),\n  \\end{aligned}\n\\end{equation}\nwhere we can define $\\Phi_{n,m}(k_y,t)$ as\n\\begin{equation} \\label{eq_b12}\n  \\begin{aligned}\n    \\Phi_{n,m}(k_y,t) =\n    \\sqrt{L_x}\n    \\int_{-L_y/2}^{L_y/2} dy\\; &\n    \\chi_{n}\\qty[y - \\mu(t)] \\\\\n    & \\times\n    \\exp(\n      -i\\qty[k_y - \\gamma(t)]\n      y).\n  \\end{aligned}\n\\end{equation}\nSubstituting ${k'_y} = k_y -\\gamma(t)$ with $y' = y -\\mu(t)$, and assuming that the size of the considered 2DEG sample in $y$-direction is considerably large ($L_y \\rightarrow \\infty$), we can obtain\n\\begin{equation} \\label{eq_b13}\n  \\Phi_{n,m}({k'_y} ,t) =\n  {\\sqrt{L_x}} e^{-i {k'_y}\\mu}\n  \\int_{-\\infty}^{\\infty} dy'\\;\n  \\chi_{n}\\qty(y')\n  \\exp(-i{k'_y} y').\n\\end{equation}\nMoreover, we can identify that the above integral represents the Fourier transform of $\\{\\chi_n\\}$ functions. In addition, using the symmetric conditions of the Fourier transform for Gauss-Hermite functions $\\theta_n(x)$ \\cite{celeghini21}\n\\begin{equation} \\label{eq_b14}\n  \\mathcal{FT}[\\theta_n(\\kappa x),x,k] = \\frac{i^n}{|\\kappa|}\\theta_n(k/\\kappa),\n\\end{equation}\nwe can simply the Eq.~(\\ref{eq_b13}) as\n\\begin{equation} \\label{eq_b15}\n  \\Phi_{n,m}({k'_y} ,t) =\n    \\sqrt{L_x}e^{-i {k'_y}\\mu}\n    \\tilde{\\chi}_{n}\\qty({k'_y}),\n\\end{equation}\nwith\n\\begin{equation} \\label{eq_b16}\n  \\tilde{\\chi}_{n}\\qty(k) =\n  \\frac{i^n}{\\sqrt{2^{n} n! \\sqrt{\\pi}}}\n  \\qty(\\frac{1}{\\kappa})^{1/2}\n  e^{-\\frac{k^2}{2 \\kappa^2}}\n  \\mathcal{H}_{\\alpha} \\qty(\\frac{k}{\\kappa}).\n\\end{equation}\nFinally, substitute Eq.~(\\ref{eq_b15}) back into Eq.~(\\ref{eq_b11}) and this leads to\n\\begin{equation} \\label{eq_b17}\n  \\begin{aligned}\n    \\phi_{n,m}(k_x,k_y,t)  = &\n    {\\sqrt{L_x}}\n    \\tilde{\\chi}_{n}\\qty(k_y - b\\cos(\\omega t)) \\\\\n    & \\times\n    \\text{exp}\\left(\n      i\\xi\n      -ik_y  \\qty[d\\sin(\\omega t) + \\frac{\\hbar k_x}{eB}]\n    \\right),\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{eq_b18}\n  b \\equiv\n  \\frac{eE\\omega_0^2}{\\hbar\\omega(\\omega_0^2 - \\omega^2)},\n\\end{equation}\nand\n\\begin{equation} \\label{eq_b19}\n  d \\equiv\n \\frac{eE}{m_e(\\omega_0^2 - \\omega^2)}.\n\\end{equation}\nIt is necessary to notice that $k_x$ is quantized with $k_x = 2\\pi m/L_x ~,~ m \\in \\mathbb{Z}$.\n", "meta": {"hexsha": "7ac572fe09b127150b92303b3c21b9786e010a6f", "size": 5905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/v1.0/sections/appendix_b.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/v1.0/sections/appendix_b.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/v1.0/sections/appendix_b.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.9888268156, "max_line_length": 239, "alphanum_fraction": 0.617273497, "num_tokens": 2342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6161188468085572}}
{"text": "\\section{Example Proof for Monoid Laws}\n\\label{sec:example}\nIn this section we use equational reasoning (see section \\ref{sec:equationalreasoning}) to prove the left identity law of the monoid type class (see section \\ref{sec:monoid}) for a new type.\nThe following example is based on a blog post of Gabriel Gonzales \\cite{gonzales14}. We simplified the types of a plugin and extended the example with an additional plugin implementation.\n\nSuppose we want to build a plugin system. A plugin in our example is an \\verb|IO| action that takes a \\verb|Char| value and does some work with it (e.g. log to a file, potentially with side effects). Hence, a plugin is of type \\verb|Char -> IO ()|. Listing \\ref{lst:logtoplugin} shows the definition of the plugin \\verb|logto|. It writes the first argument of type \\verb|Char| to a file named \\verb|log.txt|.\n\n\\begin{lstlisting}[caption={Definition of a plugin that writes a character to a file.}, label={lst:logtoplugin}]\nimport System.IO\nlogto :: Char -> IO ()\nlogto c  = do\n  handle <- openFile \"log.txt\" WriteMode\n  hPutChar handle c\n\\end{lstlisting}\n\nListing \\ref{lst:applyingaSinglePlugin} shows an application of the \\verb|logto| plugin. We read a character \\verb|c| from the standard input and call \\verb|logto c|.\n\n\\begin{lstlisting}[caption={Calling the {\\ttfamily logto} IO action in main}, label={lst:applyingaSinglePlugin}]\nmain = do\n    c <- getChar\n    logto c\n\\end{lstlisting}\n\nListing \\ref{lst:print2stdout} shows an additional plugin that prints the character to the standard output. \n\n\\begin{lstlisting}[caption={Definition of the plugin {\\ttfamily print2stdout}}, label={lst:print2stdout}]\nprint2stdout :: Char -> IO ()\nprint2stdout c = putChar c\n\\end{lstlisting}\nIn order to extend the program from listing \\ref{lst:applyingaSinglePlugin}, we want to be able to compose several plugins.\nListing \\ref{lst:composition} gives an example of the composition of the plugins \\verb|logto| and \\verb|printstdout|. We apply the \\verb|mappend| function from the \\verb|Monoid| type class to \\verb|logto| and \\verb|print2stdout|. Both arguments are of type \\verb|Char -> IO ()|. The return value is also of type \\verb|Char -> IO ()|. Listing \\ref{lst:composition} only works if \\verb|mappend| is implemented for the type \\verb|Char -> IO ()|. We will give an implementation later in this section.\n\n\\begin{lstlisting}[caption={Composition of two plugins}, label={lst:composition}]\ncomposedPlugin :: Char -> IO ()\ncomposedPlugin  = logto `mappend` print2stdout\n\\end{lstlisting}\n\nIn addition, we demand that the order in which we evaluate the plugins must not matter. The plugins have to work independently of each other. For example, the behavior of the plugins \\verb|composed1| and \\verb|composed2| from listing \\ref{lst:evaluateorder} should be the same (\\verb|donothing| is another plugin of type \\verb|Char -> IO ()|).\n\n\\begin{lstlisting}[caption={The order in which we evaluate the plugins does not matter}, label={lst:evaluateorder}]\ncomposed1 = logto `mappend` (print2stdout `mappend` donothing)\ncomposed2 = (logto `mappend` print2stdout) `mappend` donothing\n\\end{lstlisting}\n\nThe monoid laws state that \\verb|mappend| must be associative. Hence, if we can prove that our implementation of \\verb|mappend| satisfies the monoid laws, we can combine them, using the monoid function \\verb|mappend| and we are able to add plugins without concerning about the order of evaluation. In addition, they are easier to use because they will behave as expected.\n\nThe plugins are of type \\verb|Char -> IO ()|. Instead of writing a specialized instance for \\verb|Char -> IO ()|, we use the general implementation of section \\ref{sec:monoid}.\nThe instance implementation is repeated for convenience:\n\n\\begin{lstlisting}[caption={Monoid instance},label={lst:monoidinstance2}]\n{-# LANGUAGE FlexibleInstances #-}\n{-# LANGUAGE OverlappingInstances #-}\n\ninstance (Applicative f, Monoid a) => Monoid (f a) where\n  mempty = pure mempty\n  mappend = liftA2 mappend\n\\end{lstlisting}\nThe generalization has the advantage of not having that to prove the type class law only once for all types that match the general type declaration. The process of verifying a program is cumbersome and time consuming. Hence, the generalization of proofs is desirable.\n\nWe will verify that the definition \\ref{lst:monoidinstance2} satisfies the left identity law of the \\verb|Monoid| type class in two steps. First, we describe, why the instance implementation of listing \\ref{lst:monoidinstance2} makes the type \\verb|Char -> IO ()| part of the \\verb|Monoid| type class. Then we prove that the left identity law from section \\ref{sec:monoid} holds for the \\verb|Monoid| instance implementation of listing \\ref{lst:monoidinstance2}. We will assume that the instance implementation of listing \\ref{lst:monoidinstance2} is a \\verb|Monoid| in the first step.\n\n\\subsection{Generalization of the plugin type }\n\\label{sec:generalization}\n\nIn order to use the instance implementation of listing \\ref{lst:monoidinstance2}, the type \\verb|(->) Char| (that is the type of a Haskell function) has to be part of the type class \\verb|Applicative| and the type \\verb|IO ()| has to be part of the type class \\verb|Monoid|. \\verb|IO ()| is a \\verb|Monoid| if the type \\verb|IO| is an \\verb|Applicative| and \\verb|()| is a \\verb|Monoid|.\n\nHere is an overview of all the steps of the argumentation:\n\\begin{enumerate}\n\\item Show that \\verb|Char -> IO ()| is a \\verb|Monoid|.\n\\item Show that \\verb|(->) Char| is an \\verb|Applicative| and \\verb|IO ()| is a \\verb|Monoid|.\n\\item Show that \\verb|IO| is an \\verb|Applicative| and \\verb|()| is a \\verb|Monoid|.\n\\end{enumerate}\n\nWe show the required properties in reversed order.\n\n\\begin{etaremune}\n\\item The standard library provides a \\verb|Monoid| instance for \\verb|()| \\cite{monoid} and an \\verb|Applicative| instance for \\verb|IO| \\cite{control.applicative}. All type class instances of the standard library obey the corresponding type class laws \\cite{Lipovaca}. \n\n\\item If the implementation from listing \\ref{lst:monoidinstance2} satisfies the monoid laws then \\verb|IO ()| is a \\verb|Monoid| because \\verb|IO| is part of the \\verb|Applicative| type class \\cite{control.applicative} and \\verb|()| is a \\verb|Monoid|. The type \\verb|(->) r| (that's the type of Haskell functions) is a part of the \\verb|Applicative| type class \\cite{control.applicative}.\n\n\\item \nIf the implementation from listing \\ref{lst:monoidinstance2} satisfies the monoid laws then \\verb|Char -> IO ()| is a \\verb|Monoid| because \\verb|(->) Char| is an \\verb|Applicative| and \\verb|IO ()| is a \\verb|Monoid|. The compiler will use the instance implementation for the \\verb|Monoid| type class from listing \\ref{lst:monoidinstance2} for the type \\verb|Char -> IO ()| because it matches the type\n\\begin{verbatim}\n(Applicative f, Monoid b) => Monoid (f b)\n\\end{verbatim}\n\n\\end{etaremune} \n\nNotice that we rely heavily on the assumption that listing \\ref{lst:monoidinstance2} satisfies the monoid laws. The next section will prove that the implementation is correct.\n\n\\subsection{Proof}\n\\label{sec:exampleproof}\n\nIn this section we will show that the implementation in listing \\ref{lst:monoidinstance2} satisfies the left identity law of the \\verb|Monoid| type class (see section \\ref{sec:monoid}).\nThe left identity law demands that:\n\\begin{verbatim}\nmappend mempty x = x\n\\end{verbatim}\n\nWe use equational reasoning to show that the left-hand side is equal to \\verb|x|. First we use the definitions of \\verb|mappend| and \\verb|mempty| of listing \\ref{lst:monoidinstance2} to substitute the left-hand side. Furthermore we look up the definition of \\verb|liftA2| in the source code \\cite{control.applicative} to evaluate the expression. \nListing \\ref{lst:lifta2} shows the definition of \\verb|liftA2|.\n\n\\begin{lstlisting}[caption={Function definition of {\\ttfamily liftA2}},label={lst:lifta2}]\nliftA2 f x y = (pure f <*> x) <*> y\n\\end{lstlisting}\n\n\\begin{verbatim}\nmappend mempty x                    -- apply def. mappend\n= liftA2 mappend mempty x           -- apply def. mempty\n= liftA2 mappend (pure mempty) x    -- apply def. of liftA2\n= (pure mappend <*> pure mempty) <*> x\n\\end{verbatim}\n\nTo resolve this expression further, we use the laws of the \\verb|Applicative| type class described in the appendix \\ref{sec:applicatives}.\nOne law of the \\verb|Applicative| type class states:\n\\begin{verbatim}\npure f <*> pure x = pure (f x)\n\\end{verbatim}\nWe can use this property to substitute the left-hand side. Next we write \\verb|mappend mempty| as lambda function \\verb|\\a -> mappend mempty a| and use the monoid law\n\\begin{verbatim}\nmappend mempty x = x\n\\end{verbatim}\nto simplify the expression. In the last step we use the first applicative law\n\\begin{verbatim}\npure id <*> v = v\n\\end{verbatim}\n to rewrite the expression as \\verb|x|.\n\\begin{verbatim}\n(pure mappend <*> pure mempty) <*> x    -- 3. applicative law\n= pure (mappend mempty) <*> x           -- transform to lambda\n= pure (\\a -> mappend mempty a) <*> x   -- 1. monoid law \n= pure (\\a -> a) <*> x                  -- a -> a = id\n= pure id <*> x                         -- 1. applicative law\n= x\n\\end{verbatim}\n\nThat completes the proof.\n\nThe example demonstrated several ideas:\n\\begin{itemize}\n\\item Type classes allow us to generalize definitions. A proof for the generalization is valid for all specializations.\n\\item To prove a type class law we can use equational reasoning.\n\\item Type class laws (or properties) allow to prove further properties.\n\\end{itemize}\n\n", "meta": {"hexsha": "8a1bbe7f6bd375e14af8fbfa12390fc1abcd9280", "size": 9539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example.tex", "max_stars_repo_name": "Hofmaier/robertson", "max_stars_repo_head_hexsha": "a9659af0af3c5780230e8fe3cb64350f57fc8226", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example.tex", "max_issues_repo_name": "Hofmaier/robertson", "max_issues_repo_head_hexsha": "a9659af0af3c5780230e8fe3cb64350f57fc8226", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example.tex", "max_forks_repo_name": "Hofmaier/robertson", "max_forks_repo_head_hexsha": "a9659af0af3c5780230e8fe3cb64350f57fc8226", "max_forks_repo_licenses": ["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.3356164384, "max_line_length": 585, "alphanum_fraction": 0.7456756473, "num_tokens": 2540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867825403176, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6160752781648355}}
{"text": "\\section{Conclusion}\nWe are interested in answering a basic question of how to forecast a time series variable of interest when there is uncertainly about parameter instability. Specifically, which model should be used for forecasting: the break model or the stable one? If uncertainty is strong and we decide to combine forecasts from two models, what is the optimal rule in terms of some information criterion about assigning weights? Built upon Hansen's Mallows' model averaging method, we propose using the cross-validation criterion to combine forecasting models. In the literature of model selection, CV is shown to be robust to heteroscedasticity than other information criteria, such as, AIC, BIC and Mallows'. Without assuming conditional heteroscedasticity, we show that CV model averaging is approximately equivalent to Mallows' model averaging. But in many empirical applications related to macroeconomic time series or financial time series, researchers usually can not avoid explicitly dealing with heteroscedasticity for analysis and forecast. This motivates our generalization of the model averaging method by allowing for conditional heteroscedasticity.\n\nResearchers have found that in many applications, equally weighted forecasts perform better than other complex combination methods. This forecast combination puzzle has cast double on the use of complicated model averaging methods. Both CV and Cp weights are easy to compute and do not rely on direct weight estimation as in the Granger-Ramanathan forecast combination. This feature should be appealing to practitioners and professional forecasters because simplicity can help reduce the excess noise introduced by using complex weighting methods. This may help explain why our methods forecast better than equal weight in both controlled simulation and in forecasting U.S. and Taiwan quarterly GDP growth rates out-of-sample.\n\n", "meta": {"hexsha": "eff3d0475380f0b260285e9f116529324c1f3490", "size": 1900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/conclusion.tex", "max_stars_repo_name": "anwenyin/ooscombo", "max_stars_repo_head_hexsha": "4f747c7ba0c7bde2a4ae13fdc112a24e01f25bf7", "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": "Tex/conclusion.tex", "max_issues_repo_name": "anwenyin/ooscombo", "max_issues_repo_head_hexsha": "4f747c7ba0c7bde2a4ae13fdc112a24e01f25bf7", "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/conclusion.tex", "max_forks_repo_name": "anwenyin/ooscombo", "max_forks_repo_head_hexsha": "4f747c7ba0c7bde2a4ae13fdc112a24e01f25bf7", "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": 316.6666666667, "max_line_length": 1149, "alphanum_fraction": 0.8357894737, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.6160752763121424}}
{"text": "\\section{2D DP}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest common subsequence}\n  \\begin{exampleblock}{LCS: longest common subsequence (Problem 7.5)}\n\t\\[\n\t  X = X_{1} \\cdots X_{m} \\quad Y = Y_{1} \\cdots Y_{n}\n\t\\]\n\n\t\\begin{enumerate}[(1)]\n      \\item Find (the length of) an LCS of $X$ and $Y$\n    \\end{enumerate}\n  \\end{exampleblock}\n\n  \\begin{align*}\n\tX &= \\langle A,\\textcolor{blue}{B},\\textcolor{blue}{C},\\textcolor{blue}{B},D,\\textcolor{blue}{A},B \\rangle  \\\\\n\tY &= \\langle \\textcolor{blue}{B},D,\\textcolor{blue}{C},A,\\textcolor{blue}{B},\\textcolor{blue}{A} \\rangle \\\\\n\tZ &= \\langle B,C,B,A \\rangle\n  \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest common subsequence}\n  \\begin{description}\n\t\\item[Subproblem:] $L[i,j]$: the length of an LCS of $X[1 \\cdots i]$ and $Y[1 \\cdots j]$\n\t\\item[Goal:] $L[m,n]$\n\t  \\pause\n\t\\item[Make choice:] Is $X_{i} = Y_{j}$?\n\t\\item[Recurrence:] \\textcolor{red}{(Proof!)}\n\t  \\begin{displaymath}\n\t\tL[i,j] = \\left\\{ \\begin{array}{ll}\n\t\t  L[i-1, j-1] + 1 & \\textrm{if $X_{i} = Y_{j}$}\\\\\n\t\t  \\max \\set{L[i-1,j], L[i,j-1]} & \\textrm{if $X_{i} \\neq Y_{j}$}\n\t\t\\end{array} \\right.\n\t  \\end{displaymath}\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tL[0,j] &= 0, \\; 0 \\le j \\le n \\\\\n\t\tL[i,0] &= 0, \\; 0 \\le i \\le m \n\t  \\end{align*}\n\t\\item[Time:] $\\Theta(mn)$\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest common subsequence}\n  \\begin{exampleblock}{Longest common subsequence (Problem 7.5)}\n\t\\[\n\t  X = X_{1} \\cdots X_{m} \\quad Y = Y_{1} \\cdots Y_{n}\n\t\\]\n\n\t\\begin{enumerate}[(1)]\n\t  \\setcounter{enumi}{1}\n\t  \\item Allowing repetition of $X$\n\t  \\item Allowing repetition $\\le k$ of $X$\n\t\\end{enumerate}\n  \\end{exampleblock}\n\n  \\pause\n  \\begin{displaymath}\n\tL[i,j] = \\left\\{ \\begin{array}{ll}\n\t  L[\\textcolor{red}{i}, j-1] + 1 & \\textrm{if $X_{i} = Y_{j}$}\\\\\n\t  \\max \\set{L[i-1,j], L[i,j-1]} & \\textrm{if $X_{i} \\neq Y_{j}$}\n\t\\end{array} \\right.\n  \\end{displaymath}\n\n  \\pause\n  \\[\n\tX \\implies X^{(k)} \\triangleq X_{1}^{(k)} \\cdots X_{m}^{(k)}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest common substring}\n  \\centerline{What about longest common \\emph{substring}?}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Shortest common supersequence}\n  \\begin{exampleblock}{Shortest common supersequence (Problem 7.6)}\n\t\\[\n\t  X = X_{1} \\cdots X_{m} \\quad Y = Y_{1} \\cdots Y_{n}\n\t\\]\n\n\t\\begin{itemize}\n\t  \\item Find (the length of) a shortest common subsequence of $X$ and $Y$\n\t\\end{itemize}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Shortest common supersequence}\n  \\begin{description}\n\t\\item[Subproblem:] $L[i,j]$: the length of an SCS of $X[1 \\cdots i]$ and $Y[1 \\cdots j]$\n\t\\item[Goal:] $L[m,n]$\n\t  \\pause\n\t\\item[Make choice:] Is $X_{i} = Y_{j}$?\n\t\\item[Recurrence:] \n\t  \\begin{displaymath}\n\t\tL[i,j] = \\left\\{ \\begin{array}{ll}\n\t\t  L[i-1, j-1] + 1 & \\textrm{if $X_{i} = Y_{j}$}\\\\\n\t\t  \\min \\set{L[i-1,j] + 1, L[i,j-1] + 1} & \\textrm{if $X_{i} \\neq Y_{j}$}\n\t\t\\end{array} \\right.\n\t  \\end{displaymath}\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tL[0,j] &= j, \\; 0 \\le j \\le n \\\\\n\t\tL[i,0] &= i, \\; 0 \\le i \\le m \n\t  \\end{align*}\n  \\end{description}\n\n  \\pause\n  \\begin{alertblock}{Remark}\n\t\\[\n\t  \\max(m,n) \\le L(m,n) \\le m+n\n\t\\]\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Shortest common supersequence}\n  \\[\n\tX[1 \\dots m] \\qquad Y[1 \\dots n]\n  \\]\n\n  \\begin{align*}\n\tr &= |\\text{LCS}(X,Y)| \\\\\n\tt &= |\\text{SCS}(X,Y)|  \n  \\end{align*}\n\n  \\pause\n  \\[\n\tX \\cap Y = \\emptyset \\implies r = 0 \\quad t = m + n\n  \\]\n\n  \\pause\n  \\[ \n\tX \\prec Y \\implies r = m \\quad t = n\n  \\]\n\n  \\pause\n  \\[\n\tr + t = m + n\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String shuffling}\n  \\begin{exampleblock}{String shuffling (Problem 7.7)}\n\t\\begin{itemize}\n\t  \\item Strings $X[1 \\dots m], Y[1 \\dots n], Z[1 \\dots k]$\n\t  \\item Is $X \\oplus Y = Z$?\n\t\\end{itemize}\n\n\t\\begin{enumerate}[(1)]\n\t  \\item Reduced to LCS:\n\t\t\\[\n\t\t  (Z' \\triangleq Z \\setminus \\text{LCS}(X, Z)) = Y\n\t\t\\]\n\t  \\item $O(mn)$\n\t  \\item Minimum \\# deleted characters to ensure $X \\oplus Y = Z$ in $O(mnk)$\n\t\\end{enumerate}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String shuffling}\n  \\[\n\t(Z' \\triangleq Z \\setminus \\text{LCS}(X, Z)) = Y\n  \\]\n\n  \\vspace{0.60cm}\n  \\begin{columns}\n\t\\column{0.50\\textwidth}\n\t  \\[\n\t\t\\text{``YES''} \\implies X \\oplus Y = Z\n\t  \\]\n\n\t  \\uncover<2->{\n\t\t\\begin{align*}\n\t\t  X &= \\textcolor{red}{A}C \\\\\n\t\t  Y &= CB \\\\\n\t\t  Z &= CB\\textcolor{red}{A} \n\t\t\\end{align*}\n\t  }\n\t\\column{0.50\\textwidth}\n\t  \\[\n\t\t\\text{``NO''} \\implies X \\oplus Y \\neq Z\n\t  \\]\n\t  \n\t  \\uncover<3->{\n\t\t\\begin{align*}\n\t\t  X &= \\textcolor{red}{A} \\\\\n\t\t  Y &= AB \\\\\n\t\t  Z &= \\textcolor{red}{A}BA \n\t\t\\end{align*}\n\t  }\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String shuffling}\n  \\begin{description}\n\t\\item[Subproblem:] $S[i,j]$: Is $X[1 \\dots i] \\oplus Y[1 \\dots j] = Z[1 \\dots r \\triangleq i + j]$?\n\t\\item[Goal:] $S[m,n]$\n\t  \\pause\n\t\\item[Make choice:] Is $Z[r] = X[i] \\lor Z[r] = Y[j]$?\n\t\\item[Recurrence:] \n\t  \\begin{align*}\n\t\tS[i,j] = &(Z[r] = X[i] \\land S[i-1,j]) \\lor \\\\\n\t\t\t&(Z[r] = Y[j] \\land S[i,j-1])\n\t  \\end{align*}\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tS[0,j] &= (Z = Y), \\; \\forall 0 \\le j \\le n  \\\\\n\t\tS[i,0] &= (Z = X), \\; \\forall 0 \\le i \\le m\n\t  \\end{align*}\n\t\\item[Time:] $O(mn)$\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String shuffling}\n  \\begin{description}\n\t\\item[Subproblem:] $D[i,j,r]$: minimum \\# deleted characters to ensure $X[1 \\dots i] \\oplus Y[1 \\dots j] = Z[1 \\dots r]$\n\t\\item[Goal:] $D[m,n,k]$\n\t  \\pause\n\t\\item[Make choice:] Is $Z[r] = X[i] \\lor Z[r] = Y[j]$?\n\t\\item[Recurrence:] \n\t  \\[\n\t\tD[i,j,r] = \\min \\left\\{ \\begin{array}{ll}\n\t\t  D[i-1, j, r-1] & \\text{if } Z[r] = X[i] \\\\\n\t\t  D[i, j-1, r-1] & \\text{if } Z[r] = Y[j] \\\\\n\t\t  1 + D[i-1, j, r] & \\\\\n\t\t  1 + D[i, j-1, r] & \\\\\n\t\t  1 + D[i, j, r-1] & \\\\\n\t\t\\end{array} \\right.\n\t  \\]\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tD[0,j,r] &= j + r - 2|\\text{LCS}(Y[1 \\dots j], Z[1 \\dots r])| \\\\\n\t\tD[i,0,r] &=\ti + r - 2|\\text{LCS}(X[1 \\dots i], Z[1 \\dots r])| \\\\\n\t\tD[i,j,0] &= i + j\n\t  \\end{align*}\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest contiguous substring both forward and backward}\n  \\begin{exampleblock}{Longest contiguous substring both forward and backward (Problem 7.8)}\n    \\begin{itemize}\n      \\item String $T[1 \\cdots n]$\n      \\item Find a longest contiguous substring (LCS) both forward and backward\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{center}\n\td\\textcolor{blue}{ynam}icprogramming\\textcolor{blue}{many}times\n  \\end{center}\n\n  \\begin{itemize}\n\t\\item Subproblem $L[i]$: the length of an LCS in $T[1 \\cdots i]$\n\t\\item Subproblem $L[i,j]$: the length of an LCS in $T[i \\cdots j]$\n  \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest contiguous substring both forward and backward}\n  \\begin{description}\n\t\\item[Subproblem:] $L[i,j]$: the length of an LCS \\textcolor{red}{starting with $T_{i}$ and ending with $T_{j}$}\n\t\\item[Goal:] $\\max\\limits_{1 \\le i \\le j \\le n} L[i,j]$\n\t  \\pause\n\t\\item[Make choice:] Is $T_{i} = T_{j}$?\n\t\\item[Recurrence:] \n\t  \\begin{displaymath}\n\t\tL[i,j] = \\left\\{ \\begin{array}{ll}\n\t\t  0 & \\textrm{if $T_{i} \\neq T_{j}$}  \\\\\n\t\t  L[i+1,j-1] + 1 & \\textrm{if $T_{i} = T_{j}$}\n\t\t\\end{array} \\right.\n\t  \\end{displaymath}\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tL[i,i] &= 0, \\; 0 \\le i \\le n  \\\\\n\t\tL[i,i+1] &= \\left\\{ \\begin{array}{ll}\n\t\t  1 & \\text{if } T_{i} = T_{i+1}  \\\\\n\t\t  0 & \\text{if } T_{i} \\neq T_{i+1}\n\t\t  \\end{array} \\right.\n\t  \\end{align*}\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[fragile]{Longest contiguous substring both forward and backward}\n  Code: three ways of filling the table\n  \\fignocaption{width = 0.50\\textwidth}{figs/three-ways-filling-table.png}\n\n  \\begin{algorithmic}\n\t\\ForAll{$d \\gets 2 \\dots n-1$}\n\t  \\ForAll{$i \\gets 1 \\dots n-d$}\n\t    \\State $j \\gets i + d$\n\t\t\\State $\\dots$\n\t  \\EndFor\n    \\EndFor\n\n\t\\State \\Return $\\max\\limits_{1 \\le i \\le j \\le n} L[i,j]$\n  \\end{algorithmic}\n\n  % \\begin{center}\n  %     \\begin{verbatim}\n  %       for d = 2 to n-1\n  %         for i = 1 to n-d\n  %           j = i + d\n  %           ...\n  %       return max_{1 <= i <= j <= n} L[i,j]\n  %    \\end{verbatim}\n  % \\end{center}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Longest palindrome subsequence}\n  \\begin{exampleblock}{Longest palindrome subsequence (Problem 7.10)}\n\t\\begin{enumerate}[(1)]\n      \\item Find (the length of) a longest palindrome subsequence of $S[1 \\cdots n]$\n    \\end{enumerate}\n  \\end{exampleblock}\n\n  \\begin{description}\n\t\\item[Subproblem:] $L[i,j]$: the length of an LSP of $S[i \\cdots j]$\n\t\\item[Goal:] $L[1,n]$\n\t  \\pause\n\t\\item[Make choice:] Is $S[i] = S[j]$?\n\t\\item[Recurrence:] \n\t  \\begin{displaymath}\n\t\tL[i,j] = \\left\\{ \\begin{array}{ll}\n\t\t  L[i+1, j-1] + 2 & \\text{if } S[i] = S[j]  \\\\\n\t\t  \\max\\set{L[i+1,j], L[i,j-1]} & \\text{if } S[i] \\neq S[j]\n\t\t\\end{array} \\right.\n\t  \\end{displaymath}\n\t  \\pause\n\t\\item[Init:]\n\t  \\begin{align*}\n\t\tL[i,i] &= 1, \\; \\forall 1 \\le i \\le n  \\\\\n\t\t\\textcolor{red}{L[i,i+1]} &= 2, \\; \\text{if } S[i] = S[i+1], \\; \\forall 1 \\le i \\le n-1\n\t  \\end{align*}\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Palindrome splitting}\n  \\begin{exampleblock}{Palindrome splitting (Problem 7.10)}\n\t\\begin{enumerate}[(1)]\n\t  \\setcounter{enumi}{1}\n\t  \\item Split a string $S[1 \\dots n]$ into minimum number of palindromes (\\# cuts)\n    \\end{enumerate}\n  \\end{exampleblock}\n\n  \\begin{description}\n\t\\item[Subproblem:] $C[i,j]$: minimum number of cuts for string $S[i \\dots j]$\n\t\\item[Goal:] $C[1,n] + 1$\n\t  \\pause\n\t\\item[Make choice:] Where is the first cut?\n\t\\item[Recurrence:] \n\t  \\[\n\t\tC[i,j] = \\left\\{ \\begin{array}{ll}\n\t\t  0\t\\; \\text{ if } S[i \\dots j] \\text{ is a palindrome} & \\\\\n\t\t  \\min\\limits_{i+1 \\le k \\le j-1} C[i,k-1] + 1 + C[k,j] & \\text{ o.w.}\n\t\t\\end{array} \\right.\n\t  \\]\n\t  \\pause\n\t\\item[Init:] $C[i,i] = 0$\n\t\\item[Time:] $O(n^3)$\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Palindrome splitting}\n  \\begin{exampleblock}{Palindrome splitting (Problem 7.10)}\n\t\\begin{enumerate}[(1)]\n\t  \\setcounter{enumi}{1}\n\t  \\item Split a string $S[1 \\dots n]$ into minimum number of palindromes\n    \\end{enumerate}\n  \\end{exampleblock}\n\n  \\begin{description}\n\t\\item[Subproblem:] $P[i]$: minimum number of palindromes for $S[1 \\cdots i]$\n\t\\item[Goal:] $P[n]$\n\t  \\pause\n\t\\item[Make choice:] Where does the last palindrome start from?\n\t\\item[Recurrence:] \n\t  \\[\n\t\tP[i] = \\min_{\\begin{subarray}{c}\n\t\t\t1 \\le k \\le i \\\\\n\t\t\tS[k \\dots i] \\text{ is a palindrome}\n\t\t  \\end{subarray}} P[k-1] + 1\n\t  \\]\n\t  \\pause\n\t\\item[Init:] $P[0] = 1$\n\t\\item[Time:] $O(n^3)$ \\emph{vs.} $O(n^2)$\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String splitting}\n  \\begin{exampleblock}{String splitting (Problem 7.11)}\n    \\begin{itemize}\n      \\item Split a string $S$ into many pieces\n      \\item Cost $|S| = n \\implies n$\n      \\item Given locations of $m$ cuts: $\\textcolor{gray}{C_{0}}, C_{1}, \\cdots, C_{m}, \\textcolor{gray}{C_{m+1}}$\n      \\item Find the minimum cost of splitting $S$ into $m+1$ pieces $S_{0} \\cdots S_{m}$\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{String splitting}\n  \\begin{description}\n\t\\item[Subproblem:] $C[i,j]$: the minimum cost of splitting substring $S_{i} \\cdots S_{j-1}$ using cuts $C_{i+1} \\cdots C_{j-1}$\n\t\\item[Goal:] $C[0,m+1]$\n\t  \\pause\n\t\\item[Make choice:] What is the first cut in $C_{i+1} \\cdots C_{j-1}$?\n\t\\item[Recurrence:] \n\t  \\[\n\t\tC[i,j] = \\min_{i < k < j} \\left(C[i,k] + C[k,j] + l(S_{i} \\cdots S_{j-1}) \\right)\n\t  \\]\n\t  \\pause\n\t\\item[Init:] $C[i, i+1] = 0$\n  \\end{description}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "3a007fb44311f84c71b8ac1b3a986a0655316739", "size": 11727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/alg-tutorial-dp-20170619/sections/2d-dp.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/alg-tutorial-dp-20170619/sections/2d-dp.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/alg-tutorial-dp-20170619/sections/2d-dp.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": 28.1223021583, "max_line_length": 128, "alphanum_fraction": 0.5595634007, "num_tokens": 4662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6160752763121424}}
{"text": "\\section{Ensemble Methods}\n\n% ===\n\\subsection{Bagging\n\\enskip\\normalfont\\sffamily (\\textbf{B}ootstrap \\textbf{agg}regation)}\n\n\\begin{enumerate}\n    \\item Draw $M$ bootstrap sets $Z'_1, \\ldots, Z'_M$\n    \\item Train $M$ base models $b^{(1)}, \\ldots, b^{(M)}$\n    \\item \\textbf{Aggregate:}\n        $\\bbar^{(M)}(\\bm x) =\n        \\left\\{\n        \\begin{array}{@{}l@{\\enskip}l@{}}\n            \\frac1M \\sum_{t\\leq M} b^{(t)}(\\bm x)           & \\text{regr.} \\\\\n            \\mathrm{sign}\\paren{ \\sum_t b^{(t)}(\\bm x) }    & \\text{class.}\n        \\end{array}\\right.$\n\\end{enumerate}\n\n\\emph{Why it works:}\nSmall \\textit{variance} (weak learners),\nsmall \\textit{covariance} (almost indep. since $Z'_i \\neq Z'_j$).\n\\\\\\vspace{-2pt}For finite range $y$ and large enough $M$:\n\\\\\\enskip\n$\\E*[\\substack{Y\\mid X\\\\ Z, Z'}]{(y - \\bbar^{(M)}(\\bm x))^2}\n\\leq \\E*[\\substack{Y\\mid X\\\\ Z, Z'}]{(y - b(\\bm x))^2}$\n\n\\emph{Random Forest:}\\enskip\nAt each splitting step, u.a.r. choose $m$ of $p$ features and split only one (best) feature.\n$\\to$ reduce \\textit{correlation} between trees.\n\n\\textbf{Validation:}\\enskip\n\\textit{Out-of-bag error} $\\to$ validate each $\\bm x_i$ with trees that didn't use it for training.\n\n% ===\n\\subsection{Boosting}\n\n\\textit{Sequentially} train weak learners on all data, but \\rotatebox[origin=c]{45}{$\\to$}weight of misclass. samples (\\rotatebox[origin=c]{-45}{$\\!\\to$}bias).\n\n% \\emph{FSAM {\\normalfont\\sffamily (forward stagewise additive modeling)}:}\n\n\\emph{AdaBoost:}\\enskip\nStat. learning (\\textit{forward stagewise additive modeling}) with \\textbf{exp. loss}, trains max-margin ($= y_i \\bbar(\\bm x_i)$), self-avg. and interpolating (\\rotatebox[origin=c]{-45}{$\\!\\to$}overfitting) classifiers.\n\n\\begin{highlightbox}\n    \\textit{\\scriptsize [Init]:} $\\bbar^{(0)} \\leftarrow 0$,\\enskip $w_i \\leftarrow 1/n \\:\\forall i\\leq n$ \\\\\n    for $t = 1 \\ldots M$:\n    \\begin{itemize}[leftmargin=25pt]\n        \\item[\\textit{\\scriptsize [Train]:}]\n            $b^{(t)} = \\arg\\min_b \\mathcal L^w(b) \\color{gray} = \\sum_i w_i \\mathbb I \\{b(\\bm x_i) \\neq y_i\\}$\n        \\item[\\textit{\\scriptsize [Eval]:}]\n            $\\mathrm{err}_t = \\mathcal L^w(b^{(t)})$\n        \\item[\\textit{\\scriptsize [Aggr]:}]\n            $\\bbar^{(t)} = \\bbar^{(t-1)} + \\alpha_t b^{(t)}$;\\enskip\n            $\\alpha_t = \\frac12 \\log(\\frac{1}{\\mathrm{err}_t} - 1)$\n        \\vspace{-2pt}\n        \\item[\\textit{\\scriptsize [Reweight]:}]\n            $w_i = w_i \\cdot \\exp(\\alpha_t \\mathbb I\\brace{b^{(t)}(\\bm x_i) \\neq y_i})$\n            {\\small normalize!}\n    \\end{itemize}\n    Return $\\bbar^{(M)}(\\bm x) = \\mathrm{sign}(\\sum_t \\alpha_t b^{(t)}(\\bm x))$\n\\end{highlightbox}\n\n% ===\n", "meta": {"hexsha": "ca2051be6c0e7c7ee69c07ab2c20e4bd39400cc2", "size": 2644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/07_ensembles.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/07_ensembles.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/07_ensembles.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.3125, "max_line_length": 219, "alphanum_fraction": 0.5945537065, "num_tokens": 967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6160752744594493}}
{"text": "\\documentclass[parskip=half]{scrartcl}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[citestyle=authoryear-icomp,bibstyle=authoryear]{biblatex}\n\\usepackage{booktabs}\n\\usepackage[style=british]{csquotes}\n\\usepackage{fontspec}\n\\usepackage{mathtools}\n\\usepackage{ntheorem}\n\\usepackage{siunitx}\n\n\\usepackage{tikz}\n\\usetikzlibrary{angles,calc,intersections,quotes}\n\n\\usepackage[p,osf]{cochineal}\n\\usepackage[cochineal,vvarbb]{newtxmath}\n\\usepackage[cal=boondoxupr,calscaled=1.0]{mathalfa}\n\n\\newfontfamily\\dispfamily{Cabin}[Scale=0.95]\n\\addtokomafont{disposition}{\\dispfamily}\n\n\\MakeAutoQuote{«}{»}\n\\DeclareMathOperator{\\Res}{Res}\n\n\\addbibresource{cable.bib}\n\n\\newcommand{\\Int}[2]{\\int_{#1}^{#2}\\!}\n\\newcommand{\\D}{\\mathop{}\\!d}\n\n\\newcommand{\\cZ}{\\mathcal{Z}}\n\\newcommand{\\cC}{\\mathcal{C}}\n\n\\theoremstyle{nonumberplain}\n\\newtheorem{lemma*}{Lemma}\n\\newenvironment{proof}{\\textbf{Proof.}}{\\hfill$\\square$}\n\n\\title{Analytic solutions to the cable equation}\n\n\\author{Sam Yates}\n%\\date{July 29, 2019}\n\n\\sisetup{mode=text}\n\n\\begin{document}\n\n% Work-around for siunitx vs newtxmath bug\n\\ExplSyntaxOn\n    \\cs_undefine:N \\c__siunitx_minus_tl\n    \\tl_const:Nn \\c__siunitx_minus_tl { - }\n\\ExplSyntaxOff\n\n\\maketitle\n\n\\section{The cable equation}\n\nThe cable equation describes the evolution of the potential\non a long, thin, conducting cable in a conducting medium, separated\nby a leaky dielectric. It assumes that the behaviour\ncan be modelled entirely as a one dimensional problem,\nin terms of the linear conductivity of the cable $\\sigma$,\nand the conductance $g$ and capacitance $c$ per unit length of the\ndielectric. The potential $v(x, t)$ then satisfies\n\\begin{equation}\n    (\\sigma v')' = c \\dot v + g v.\n\\end{equation}\nwhere $f'$ denotes the derivative of $f$ with respect to the first\nvariable, and $\\dot{f}$ the derivative with respect to the second.\nThe quantities $\\sigma$, $g$, and $c$ are functions of position,\nand will depend on the electrical and geometrical properties of\nthe system.\n\nFor a cable of radius $r(x)$ with constant bulk resistivity\n$R_L$, areal capacitance $C_M$ and areal surface resistivity\n$R_M$, these parameters are given by\n\\begin{align}\n    \\sigma(x) &= \\pi r(x)^2 / R_L, \\\\\n    g(x) &= 2 \\pi r(x) \\sqrt{1 + r'(x)^2} / R_M, \\\\\n    c(x) &= 2 \\pi r(x) \\sqrt{1 + r'(x)^2} C_M.\n\\end{align}\nLetting $\\theta(x) = \\arctan r'(x)$, the cable equation becomes\n\\begin{equation}\n    \\label{eq:constelec}\n    \\frac{R_M}{2 R_L}\\left(\n        2\\sin\\theta\\cdot v' + r \\cos\\theta\\cdot v''\n    \\right) =\n    R_M C_M \\dot v + v.\n\\end{equation}\n\n\\section{Analytic solutions for $v(x, t)$}\n\nTwo important special cases for the cable equation are the cylinder,\nwith $r(x)$ constant and $\\theta(x)=0$, and the conical frustum,\nwith $\\theta(x)$ constant and $r(x)=x\\tan\\theta$.\n\nGiven constant electrical properties, as in \\eqref{eq:constelec},\na zero voltage at $t=0$, and Neumann boundary conditions, what\nis $v(x, t)$? The Rallpack 1 model \\autocite{bhalla1992} is\nan example of such a passive cable model, and is discussed in\nAppendix \\ref{ap:rallpack}.\n\n\\subsection{The cylinder}\n\nSuppose the cable lies on the interval $[0, B]$, with initial\nvoltage zero, zero current\nat $x=0$, and fixed injected current $I$ at $x=B$. The boundary\nconditions are then $v(x,0) = 0$, $v'(0, t) = 0$, and $v'(B, t) = -E$,\nwhere $-E = I\\cdot R_L/\\pi r^2$.\n\nA change of variables gives\n\\begin{equation}\n    v(x, t) = -\\lambda E\\cdot u(x/\\lambda, t/\\tau),\n\\end{equation}\nwhere\n\\begin{equation}\n    \\lambda = \\sqrt{\\frac{R_M r}{2 R_L}}, \\quad \\tau = R_M C_M, \\quad b = B/\\lambda,\n\\end{equation}\nand $u$ satisfies\n\\begin{equation}\n    \\begin{aligned}\n        u''(x, t) &= \\dot u(x, t) + u(x, t),\\\\\n        u(x, 0) &= 0,\\\\\n        u'(0, t) &= 0,\\\\\n        u'(b, t) &= 1.\n    \\end{aligned}\n    \\label{eq:ucyl}\n\\end{equation}\n\nThe corresponding time-invariant problem has solution $\\hat u(x)$ where\n\\begin{equation}\n    \\hat u'' = \\hat u,\\quad \\hat u'(0) = 0,\\quad \\hat u'(b) = 1,\n\\end{equation}\ngiving\n\\begin{equation}\n    \\hat u(x) = \\frac{\\cosh x}{\\sinh b}.\n\\end{equation}\n\nConsider separable transient solutions $u(x,t)-\\hat u(x)$, with zero derivative\nat $x=0$ and $x=b$, of the form $\\psi(x)\\eta(t)$. From \\eqref{eq:ucyl},\n$\\eta(t)=e^{-\\lambda t}$ for some $\\lambda$ and $\\psi$ satisfies\n\\begin{gather}\n    \\label{eq:efncyl}\n    \\psi'' + (\\lambda-1)\\psi = 0,\\\\\n    \\label{eq:efncylbc}\n    \\quad \\psi'(0)=\\psi'(b)=0.\n\\end{gather}\nThis is a regular Sturm-Liouville problem\n\\autocite[see e.g.][Theorem~2.1, p.~146]{reid1980} with discrete non-negative eigenvalues\n$\\lambda_k-1$ and corresponding orthogonal eigenfunctions $\\psi_k$,\n\\begin{equation}\n    \\langle \\psi_k, \\psi_{k'} \\rangle =\n    \\Int{0}{b} \\psi_k(x)\\psi_{k'}(x) \\D x =0\\quad\\text{if $k\\neq k'$}.\n\\end{equation}\n\nThe least eigenvalue corresponds to $\\lambda_0 = 1$ with eigenfunction\n$\\psi_0(x)=1$.\n\nFor $\\lambda>1$, \\eqref{eq:efncyl} gives\n$\\psi(x) = c_1\\cos\\sqrt{\\lambda-1}x + c_2\\sin\\sqrt{\\lambda-1}x$. From $\\psi'(0)=0$,\nwe have $c_2=0$. From $\\psi'(b)=1$, it follows $c_1=0$ or $\\sqrt{\\lambda-1}b = k\\pi$\nfor some positive integer $k$. Consequently we have eigenvalues and eigenfunctions,\n\\begin{gather}\n    \\label{eq:lkcyl}\n    \\lambda_k = 1+\\left(\\frac{k\\pi}{b}\\right)^{\\mathrlap{2}},\\\\\n    \\psi_k(x) = \\cos \\frac{k\\pi x}{b}.\n\\end{gather}\nfor integers $k\\geq 0$, including the constant $\\lambda=1$ case.\n\nThe time-dependent solution $u(x, t)$ then is\n\\begin{equation}\n    u(x,t) = \\hat u(x) - \\sum_{k=0}^{\\infty} a_k e^{-\\lambda_k t}\\psi_k(x),\n\\end{equation}\nwith $a_k$ determined by the initial conditions,\n\\begin{equation}\n    0 = \\langle u(x,0), \\psi_k(x) \\rangle\n    = \\langle \\hat u(x), \\psi_k(x) \\rangle\n    - a_k\\langle \\psi_k(x), \\psi_k(x)\\rangle,\n\\end{equation}\nwith\n\\begin{align}\n    \\langle \\hat u(x), \\psi_k(x) \\rangle\n    = \\frac{1}{\\sinh b}\\Int{0}{b}\\cosh x\\cos\\frac{k\\pi}{b}x \\D x\n    = (-1)^k\\lambda_k^{-1},\n    \\intertext{and}\n    \\langle \\psi_k(x), \\psi_k(x) \\rangle\n    = \\Int{0}{b}\\cos^2 \\frac{k\\pi}{b}x \\D x\n    =\n    \\begin{cases}\n        b & \\text{if $k=0$,}\\\\\n        \\frac{b}{2} & \\text{otherwise.}\\\\\n    \\end{cases}\n\\end{align}\nConsequently,\n\\begin{equation}\n    \\label{eq:cylseries}\n    u(x,t) = \\frac{\\cosh x}{\\sinh b} - \\frac{1}{b}e^{-t} -\n    \\frac{2}{b}\\sum_{k=1}^{\\infty} (-1)^k \\lambda_k^{-1} e^{-\\lambda_k t} \\cos\\frac{k\\pi x}{b},\n\\end{equation}\nwith $\\lambda_k$ given in \\eqref{eq:lkcyl}. A discussion on the residuals in this series can\nbe found in Appendix~\\ref{ap:cylcomp}.\n\nNote that the time derivative $\\dot u(x,t)$ can be expressed in terms of Jacobi theta functions:\n\\begin{equation}\n    \\begin{aligned}\n        \\dot u(x,t) &= \\frac{1}{b}e^{-t}\\left(1+2\\sum_{k=1}^{\\infty} (-1)^ke^{-\\frac{\\pi^2 k^2 t}{b}}\\cos\\frac{k\\pi x}{b}\\right)\\\\\n        &= \\frac{1}{b}e^{-t}\\theta_4\\left(\\frac{\\pi x}{2 b}\\middle| \\frac{i\\pi t}{b^2}\\right).\n    \\end{aligned}\n\\end{equation}\n\n\\subsection{The tapered cable}\n\nConsider the cable as a conical frustum on the interval $[A, B]$ with radius\n$r(x) = x \\tan\\theta$ and boundary conditions $v'(A, t) = 0$, $v'(B, t) = -E$,\nand $v(x, 0) = 0$ (see Figure \\ref{fig:tapered}). A fixed injecting current $I$\nat $x=B$ corresponds to $-E=I\\cdot R_L/\\pi r(B)^2$. Reparameterizing gives\n\\begin{equation}\n    v(x, t) = -\\lambda E\\cdot u(x/\\lambda, t/\\tau),\n\\end{equation}\nwhere\n\\begin{equation}\n    \\lambda = \\frac{R_M\\sin\\theta}{2 R_L}, \\quad \\tau = R_M C_M, \\quad a = A/\\lambda, \\quad b = B/\\lambda,\n\\end{equation}\nand $u$ satisfies\n\\begin{equation}\n    \\label{eq:conu}\n    \\begin{aligned}\n        x u''(x, t) + 2 u'(x, t) &= \\dot u(x, t) + u(x, t),\\\\\n        u(x, 0) &= 0,\\\\\n        u'(a, t) &= 0,\\\\\n        u'(b, t) &= 1.\n    \\end{aligned}\n\\end{equation}\n\n\\begin{figure}[tbh]\n    \\begin{tikzpicture}[scale=0.8]\n        \\coordinate (origin) at (0,0);\n        \\coordinate (b0) at (15,0);\n        \\coordinate (b1) at ($ (b0) + (0,1.8) $);\n        \\coordinate (a0) at (5,0);\n\n        \\path [name path=tangent] (origin) -- (b1);\n        \\path [name path=avert] (a0) -- +(0,2);\n        \\path [name intersections={of=tangent and avert, by=a1}];\n\n        \\coordinate (a-1) at ($ (a1)!2!(a0) $);\n        \\coordinate (b-1) at ($ (b1)!2!(b0) $);\n\n        \\draw [name path=axis, dashed] (origin) -- (b0);\n\n        \\draw let \\p1 = (a1), \\n2 = {0.2*\\y1} in\n            (a1) arc (90:270:\\n2 and \\y1);\n\n        \\draw let \\p1 = (a1), \\n2 = {0.2*\\y1} in\n            [densely dotted] (a-1) arc (-90:90:\\n2 and \\y1);\n\n        \\draw let \\p1 = (b1), \\n2 = {0.2*\\y1} in\n            (b0) ellipse (\\n2 and \\y1);\n\n        \\draw (a1) -- (b1) (a-1) -- (b-1);\n        \\draw [dotted] (origin) -- (a1) (origin) -- (a-1);\n\n        \\pic [draw, \"$\\theta$\", angle radius = 15ex, angle eccentricity=1.2] {angle = b0--origin--b1};\n\n        \\coordinate (lright) at ($ (b1)!2!(b0) - (0,40pt) $);\n        \\coordinate (lleft) at ($ (origin) + (lright) - (b0) $);\n\n        \\path (lleft) node (x0label) { $x=0$ };\n        \\path (lright) node (xblabel) { $x=B =b\\lambda $ };\n        \\path ($ (lleft)!(a0)!(lright) $) node (xalabel) { $x=A =a\\lambda$ };\n\n        \\draw [dotted] ($ (a-1)-(0,2ex) $) -- ($ (xalabel)+(0,2ex) $);\n        \\draw [dotted] ($ (b-1)-(0,2ex) $) -- ($ (xblabel)+(0,2ex) $);\n        \\draw [dotted] ($ (origin)-(0,2ex) $) -- ($ (x0label)+(0,2ex) $);\n    \\end{tikzpicture}\n    \\caption{Tapered cable coordinates.}\n    \\label{fig:tapered}\n\\end{figure}\n\nProceeding similarly to the cylinder problem, the solution can be presented as a sum of\na time-invariant solution $\\hat u$ and a series of transients that are solutions to\na Sturm--Liouville problem.\n\nThe time-invariant problem is\n\\begin{equation}\n    \\begin{gathered}\n        x\\hat u''(x) + 2\\hat u'(x) - \\hat u(x) = 0,\\\\\n        \\hat u'(a) = 0,\\quad \\hat u'(b) = 1.\n    \\end{gathered}\n\\end{equation}\n\nMultiplying by $x$ gives a differential equation of the form\n\\begin{equation}\n    \\label{eq:conicmu}\n    x^2 g''(x) + 2x g'(x) + \\mu x g(x) = 0\n\\end{equation}\nfor some $\\mu$. This has solutions in terms of Bessel functions.\nIf $\\cC_\\nu$ is a solution to the Bessel equation\n\\begin{equation}\n    z^2 f''(z) + z f'(z) - (z^2 - \\nu^2) f(z) = 0,\n\\end{equation}\nthen $g(x) = x^{-\\frac{1}{2}}\\cC_1(\\alpha x^\\frac{1}{2})$ satisfies\n\\begin{equation}\n    \\label{eq:besg}\n    x^2 g''(x) + 2x g'(x) + \\frac{\\alpha^2}{4} x g(x) = 0.\n\\end{equation}\nSimilarly, if $\\cZ_\\nu$ is a solution to the modified Bessel equation\n\\begin{equation}\n    z^2 f''(z) + z f'(z) - (z^2 + \\nu^2) f(z) = 0,\n\\end{equation}\nthen $g(x) = x^{-\\frac{1}{2}}\\cZ_1(\\alpha x^\\frac{1}{2})$ satisfies\n\\begin{equation}\n    \\label{eq:modbesg}\n    x^2 g''(x) + 2x g'(x) - \\frac{\\alpha^2}{4} x g(x) = 0.\n\\end{equation}\n\nThe time-invariant solution $\\hat u(x)$ satisfies \\eqref{eq:modbesg} with $\\alpha=2$, and so\ncan be written as\n\\begin{equation}\n    \\hat u(x) = \\frac{1}{\\sqrt{x}} \\left(c_1 I_1(2\\sqrt{x}) - c_2 K_1(2\\sqrt{x})\\right),\n\\end{equation}\nwith derivative\n\\begin{equation}\n    \\hat u'(x) = \\frac{1}{x} \\left(c_1 I_2(2\\sqrt{x}) + c_2 K_2(2\\sqrt{x})\\right).\n\\end{equation}\nSolving for the boundary conditions $\\hat u'(a)=0$, $\\hat u'(b)=1$ then determines the coefficients\n$c_1$ and $c_2$, giving\n\\begin{equation}\n    \\label{eq:conuhat}\n    \\hat u(x) =\n    \\frac{b}{\\sqrt{x}}\\cdot\n    \\frac{K_2(2\\sqrt{a})I_1(2\\sqrt{x}) + I_2(2\\sqrt{a})K_1(2\\sqrt{x})}\n    {K_2(2\\sqrt{a})I_2(2\\sqrt{b})-I_2(2\\sqrt{a})K_2(2\\sqrt{b})}.\n\\end{equation}\n\nSeparable transient solutions $u(x,t)-\\hat u(x)$ will be of the form $e^{-\\lambda t}\\psi(x)$,\nwhere $\\psi(x)$ satisfies\n\\begin{gather}\n    \\label{eq:conpsi1}\n    x\\psi''(x) + 2\\psi'(x) + (\\lambda-1)\\psi(x) = 0\\\\\n    \\label{eq:conpsi2}\n    \\psi'(a) = \\psi'(b) = 0.\n\\end{gather}\nMultiplying \\eqref{eq:conpsi1} by $x$ gives\n\\begin{equation}\n    \\label{eq:conpsils}\n    x^2\\psi''(x) + 2x\\psi'(x) + (\\lambda-1)x \\psi(x) =\n    \\frac{d}{dx}(x^2\\psi'(x)) + (\\lambda-1)x \\psi(x) = 0,\n\\end{equation}\nwhich together with \\eqref{eq:conpsi2} forms a regular Sturm--Liouville problem with\nnon-negative eigenvalues $\\lambda_k-1$ and corresponding orthogonal eigenfunctions\n$\\psi_k(x)$ with respect to the weight function $\\rho(x) = x$.\n\nFor $\\lambda_0=1$, the eigenfunction is $\\psi_0(x)=1$. For $\\lambda_k>0$,\nequation \\eqref{eq:conpsils} is of the form \\eqref{eq:besg}, with $\\alpha=2\\sqrt{\\lambda_k-1}$.\nWriting $\\omega_k$ for $\\sqrt{\\lambda_k-1}$, we have\n\\begin{equation}\n    \\psi_k(x) = \\frac{1}{\\sqrt{x}} \\left(c_1^{(k)} J_1(2\\omega_k \\sqrt{x})) + c_2^{(k)} Y_1(2\\omega_k \\sqrt{x})\\right),\n\\end{equation}\nwith derivative\n\\begin{equation}\n    \\psi_k'(x) = - \\frac{\\omega_k}{x} \\left(c_1^{(k)} J_2(2\\omega_k\\sqrt{x})) + c_2^{(k)} Y_2(2\\omega_k\\sqrt{x})\\right).\n\\end{equation}\n\nThe boundary conditions $\\psi_k'(a) = \\psi_k'(b) = 0$ imply\n\\begin{gather}\n    f_2\\left(\\sqrt{\\tfrac{b}{a}}, 2\\omega_k\\sqrt{a}\\right) = 0,\n    \\intertext{where $f_\\nu$ is the cross-product Bessel function}\n    f_\\nu(q, x) = J_\\nu(qx)Y_\\nu(x)-J_\\nu(x)Y_\\nu(qx).\n\\end{gather}\nThe eigenvalues for $k>0$ are then $\\lambda_k=1+\\omega_k^2$ with\n\\begin{equation}\n    \\label{eq:conomegak}\n    \\omega_k =  \\frac{\\chi_{2, k}\\left(\\sqrt{\\scriptstyle \\frac{b}{a}}\\right)}{2\\sqrt{a}}.\n\\end{equation}\nwhere $\\chi_{\\nu, k}(q)$ is the $k$th positive root of $f_\\nu(q, x)=0$. These solutions\ncan be computed efficiently via a Newton--Raphson scheme \\autocite{sorolla2013}.\n$c_1^{(k)}$ and $c_2^{(k)}$ are then determined up to scale; for example, we can\nset\n\\begin{equation}\n    c_1^{(k)} = J_2(2\\omega_k\\sqrt{x})^{-1},\\qquad\n    c_2^{(k)} = -Y_2(2\\omega_k\\sqrt{x})^{-1},\n\\end{equation}\ngiving\n\\begin{equation}\n    \\label{eq:conpsik}\n    \\psi_k(x) =\\frac{1}{\\sqrt{x}}\\left(\n    \\frac{J_1(2\\omega_k\\sqrt{x})}{J_2(2\\omega_k\\sqrt{a})}\n    -\n    \\frac{Y_1(2\\omega_k\\sqrt{x})}{Y_2(2\\omega_k\\sqrt{a})}\n    \\right).\n\\end{equation}\n\nThe complete solution then will be\n\\begin{equation}\n    \\label{eq:conuxt}\n    u(x,t) = \\hat u(x) - \\sum_{k=0}^{\\infty} a_k e^{-\\lambda t} \\psi_k(x),\n\\end{equation}\nwhere the $a_k$ will be determined by the initial conditions.\n\nAs the $\\psi_k$ are\neigenfunctions of the Sturm-Liouville problem (\\ref{eq:conpsils}, \\ref{eq:conpsi2}), they\nare orthogonal with respect to the inner product with weight function $\\rho(x)=x$,\n\\begin{equation}\n    \\langle f, g \\rangle = \\Int{a}{b} xf(x)g(x) \\D x.\n\\end{equation}\nTaking the inner product of $\\langle u(x,0), \\psi_k(x)\\rangle$ then gives for each $k$,\n\\begin{equation}\n    a_k = \\frac{\\Int{a}{b} x \\hat u(x)\\psi_k(x) \\D x}{\\Int{a}{b} x \\psi_k(x)^2 \\D x}.\n\\end{equation}\n\nFor $k=0$,\n\\begin{equation}\n    \\begin{aligned}\n        a_0 &= \\frac{1}{b-a} \\cdot \\Int{a}{b} x \\hat u(x) \\D x\\\\\n        &= \\frac{1}{b-a} \\cdot \\left. x^2\\hat u'(x)\\right|_a^b\\\\\n        &= \\frac{b^2}{b-a}.\n    \\end{aligned}\n\\end{equation}\n(See Appendix \\ref{ap:conid} for the derivation of this and the following integrals.)\n\nFor $k>0$,\n\\begin{equation}\n    \\begin{aligned}\n        \\Int{a}{b} x \\hat u(x)\\psi_k(x) \\D x\n        &= \\frac{1}{1+\\omega_k^2} \\cdot \\left. (x^2\\hat u'(x)\\psi_k(x)-x^2\\hat u(x)\\psi'_k(x))\\right|_a^b\\\\\n        &= \\lambda_k^{-1} b^2\\psi_k(b),\n    \\end{aligned}\n\\end{equation}\nand\n\\begin{equation}\n    \\begin{aligned}\n        \\Int{a}{b} x \\psi_k(x)^2 \\D x\n        &= \\left.\n        x^2\\psi_k(x)^2 + \\frac{x^2}{\\omega_k^2}\\psi_k(x)\\psi'_k(x)\n        + \\frac{x^3}{\\omega_k^2}\\psi'_k(x)^2\n        \\right|_a^b\\\\\n        &= b^2\\psi_k(b)^2 - a^2\\psi_k(a)^2,\n    \\end{aligned}\n\\end{equation}\ngiving\n\\begin{equation}\n    a_k = \\frac{1}{\\lambda_k}\\cdot \\frac{b^2\\psi_k(b)}{b^2\\psi_k(b)^2-a^2\\psi_k(a)^2}.\n\\end{equation}\n\nThis gives the time-dependent solution\n\\begin{equation}\n    u(x,t) = \\hat u(x) - \\frac{b^2}{b-a}e^{-t} -\n    \\sum_{k=1}^{\\infty} \\lambda_k^{-1} e^{-\\lambda_k t}\n    \\frac{b^2\\psi_k(b)\\psi_k(x)}{b^2\\psi_k(b)^2-a^2\\psi_k(a)^2}\n\\end{equation}\nwhere $\\hat u$ is given by \\eqref{eq:conuhat}, $\\psi_k$ is given by \\eqref{eq:conpsik},\nand $\\lambda_k = 1 + \\omega_k^2$ is given by \\eqref{eq:conomegak}.\n\n\n\\section{Approximating the gradient}\n\nIn a finite volume discretization there\nwill be a computation of the approximation to the gradient\n$v'(x)$ as a linear combination of two (or potentially more)\nvalues of the discrete approximation of the voltage for points\nnear $x$.\n\nIf the coefficients in this approximation are constant in\ntime, they cannot account for source terms or values of the\nvoltage outside the points in question. The most faithful\nsuch approximation should then reproduce the exact gradient $v'(x)$\nin the source-free steady state form of the cable equation,\n\\begin{equation}\n    (\\sigma v')' = 0.\n\\end{equation}\n\nThe voltage $v$ is then determined by its values at\nany two distinct points $a$ and $b$,\n\\begin{equation}\n    \\frac{v(x) - v(a)}{v(b) - v(a)} =\n    \\frac{\\displaystyle \\Int{a}{x} \\sigma(z)^{-1} \\D z}\n         {\\displaystyle \\Int{a}{b} \\sigma(z)^{-1} \\D z},\n\\end{equation}\nand correspondingly, the gradient is\n\\begin{equation}\n    \\sigma(x) v'(x) =\n    \\frac{v(b) - v(a)}\n         {\\displaystyle\\Int{a}{b} \\sigma(z)^{-1} \\D z}.\n\\end{equation}\nIf $x$ is a point of discontinuity in $\\sigma$,\nthe flux $\\sigma(x)v'(x)$ is nonetheless well defined.\n\nFor a finite volume approximation, however, the available\nestimates may correspond instead to surface area-weighted means\nover control volumes. Consider two adjacent control volumes\non $[a, m]$ and $[m, b]$, with mean voltages $\\bar v_a$ and\n$\\bar v_b$ given in terms of a weight function $w(x)$:\n\\begin{align}\n    \\bar v_a &= w_a^{-1} \\Int{a}{m} w(x)v(x) \\D x,\\\\\n    \\bar v_b &= w_b^{-1} \\Int{m}{b} w(x)v(x) \\D x,\n\\end{align}\nwith normalizing constants $w_a$ and $w_b$. With $\\sigma v' = \\kappa$\nconstant,\n\\begin{equation}\n    \\begin{aligned}\n        \\bar v_a\n        &= w_a^{-1} \\Int{a}{m} w(x) \\left( v(m) + \\kappa \\Int{m}{x} \\sigma(y)^{-1} \\D y \\right) \\D x \\\\\n        &= v(m) + \\kappa \\cdot w_a^{-1} \\Int{a}{m} w(x) \\Int{m}{x} \\sigma(y)^{-1} \\D y \\D x,\n    \\end{aligned}\n\\end{equation}\nand similarly, \n\\begin{equation}\n    \\begin{aligned}\n        \\bar v_b\n        &= v(m) + \\kappa \\cdot w_b^{-1} \\Int{m}{b} w(x) \\Int{m}{x} \\sigma(y)^{-1} \\D y \\D x,\n    \\end{aligned}\n\\end{equation}\nTaking the difference then gives a solution for $\\kappa$,\n\\begin{equation}\n    \\kappa = (\\bar v_b - \\bar v_a) \\cdot \\left[\n        w_b^{-1}\\!\\Int{m}{b} w(x)\\! \\Int{m}{x} \\sigma(y)^{-1} \\D y \\D x\\,-\\,\n        w_a^{-1}\\!\\Int{a}{m} w(x)\\! \\Int{m}{x} \\sigma(y)^{-1} \\D y \\D x\n        \\right]^{\\mathrlap{-1}}.\n\\end{equation}\n\n\\newpage\n\\appendix\n\\section{The Rallpack 1 model}\n\\label{ap:rallpack}\n\nThe Rallpack suite \\autocite{bhalla1992} is a set of three models for the\nvalidation and benchmarking of cable-based neuron simulators. The first of\nthese comprises a cylindrical passive cable of length $L$ and diameter $d$,\nwith a constant current applied at $x=0$. The membrane resistive current\ndensity is given by $J = R_M^{-1}(v-E)$, where $E$ is a fixed reversal potential.\nThe values of the electrial and geometric parameters are given in\nTable~\\ref{tbl:rallpack1}.\n\nThe membrane potential can then be expressed as\n\\begin{equation}\n    v(x, t) = E - \\lambda I \\cdot u(\\frac{b-x}{\\lambda}, \\frac{t}{\\tau}),\n\\end{equation}\nwhere\n\\begin{equation}\n    \\lambda = \\sqrt{\\frac{R_M d}{4 R_L}},\\quad\n    \\tau = R_M C_M,\\quad\n    b = L/\\lambda,\n\\end{equation}\nand $u(x,t)$ is given by \\eqref{eq:cylseries}.\n\n\\begin{table}[htb]\n    \\centering\n    \\begin{tabular}{lll}\n        \\toprule\n\tParameter & {} & {Value} \\\\\n        \\midrule\n\tCable diameter                    & $d$    & \\SI{1.0}{\\um} \\\\\n\tCable length                      & $L$    & \\SI{1.0}{\\mm} \\\\\n\tBulk (axial) resistivity          & $R_L$  & \\SI{1.0}{\\ohm\\m} \\\\\n\tMembrane resistivity              & $R_M$  & \\SI{4.0}{\\ohm\\m\\squared} \\\\\n\tMembrane specific capacitance     & $C_M$  & \\SI{0.01}{\\F\\per\\m\\squared} \\\\\n\tMembrane reversal potential       & $E_M$  & \\SI{-65.0}{\\mV} \\\\\n\tInjected current                  & $I$    & \\SI{0.1}{\\nA} \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\caption{Rallpack 1 parameters}\n    \\label{tbl:rallpack1}\n\\end{table}\n\n\n\\section{Series computation for the voltage on the uniform cylinder}\n\\label{ap:cylcomp}\n\nHow many terms in the series \\eqref{eq:cylseries} need to be computed for a given tolerance?\nWe obtain bounds on the remainders in the series as follows.\n\nLet $u_n(x,t)$ be the partial sum up to $k=n-1$ in \\eqref{eq:cylseries}, and $r_n(x,t) = u(x,t) - u_n(x,t)$\nbe the remainder,\n\\begin{equation}\n    r_n(x,t) = -\\frac{2}{b}\\sum_{k=n}^{\\infty} (-1)^k\\lambda_k^{-1}e^{-\\lambda_k t}\\cos\\frac{k\\pi x}{b}.\n\\end{equation}\nThen $|r_n(x,t)|\\leq R_n(t)$ for all $x$, with\n\\begin{equation}\n    R_n(t) = \\frac{2}{b}\\sum_{k=n}^{\\infty} \\lambda_k^{-1}e^{-\\lambda_k t}\\\\\n    = \\frac{2t}{b}\\sum_{k=n}^{\\infty} l(k)^{-1}e^{-l(k)}\\\\\n\\end{equation}\nwhere\n\\[\n    l(z) = \\left(1+\\left(\\frac{z\\pi}{b}\\right)^2\\right)\\cdot t.\n\\]\nThe summand is monotonically decreasing in $k$, so\n\\begin{equation}\n    \\label{eq:rnigamma}\n    R_n(t)\n    \\leq \\frac{2t}{b}\\Int{n}{\\infty} l(k)^{-1}e^{-l(k)}\\D k\n    = \\frac{\\sqrt{t}}{b} \\Int{\\lambda_n t}{\\infty} e^{-z}z^{-\\frac{3}{2}} \\D z.\n\\end{equation}\n\nFor $a>0$, $s>0$, integrating by parts gives\n$\\displaystyle \\Int{a}{\\infty} e^{-z}z^{-s}\\D z < e^{-a}a^{-s}$,\nand so\n\\begin{equation}\n    R_n(t) < \\frac{1}{b t}\\lambda_n^{-3/2}e^{-\\lambda_n t}.\n\\end{equation}\n\n\\section{Identities and integrals for tapered cable eigenfunctions}\n\\label{ap:conid}\n\n\\newcommand{\\Fp}{\\smash{F^{\\mathrlap{\\prime}}}\\mkern-2.0mu}\n\\newcommand{\\Gp}{\\smash{G^{\\mathrlap{\\prime}}}\\mkern-2.0mu}\n\nLet\n\\begin{equation}\n    \\begin{aligned}\n        F_k(z) &= z^{-\\frac{k}{2}}\\cZ_k(2z^{1/2}),&\n        G_k(z) &= z^{-\\frac{k}{2}}\\cC_k(2\\omega z^{1/2}),\n    \\end{aligned}\n\\end{equation}\nwhere $C_k$ and $Z_k$ are solutions to the Bessel and modified Bessel equations\nrespectively,\n\\begin{equation}\n    \\begin{aligned}\n        \\cZ_k(z) &= c_1 I_k(z) + c_2 e^{i\\pi k} K_k(z),&\n        \\cC_k(z) &= c_3 J_k(z) + c_4 Y_k(z)\n    \\end{aligned}\n\\end{equation}\nfor some constants $c_1$, $c_2$, $c_3$, $c_4$.\n\n$F_k$ and $G_k$ are solutions of the differential equations\n\\begin{gather}\n    z f''(z) + (k+1) f'(z) - z = 0\\\\\n    \\intertext{and}\n    z g''(z) + (k+1) g'(z) + \\omega^2 z = 0\n\\end{gather}\nrespectively, following the identity (2) of \\autocite[p.~512]{lommel1879}.\n\nApplying the derivative and recurrence relations for Bessel functions\n\\autocite[\\S 10.6, \\S10.29]{nistdlmf} then gives the following identities,\n\\begin{align}\n    \\label{eq:fgrel}\n    \\Fp_k(z) &= F_{k+1}(z), & z \\Fp_k(z) &= -k F_k(z) + F_{k-1}(z),\\\\\n    \\Gp_k(z) &= -\\omega G_{k+1}(z), & z \\Gp_k(z) &= -k G_k(z) + \\omega G_{k-1}(z).\n\\end{align}\nWhen $k$ is an integer, these imply\n\\begin{equation}\n    \\begin{aligned}\n        F_{-k}(z) &= z^k F_k(z),\\\\\n        G_{-k}(z) &= (-z)^k G_k(z),\n    \\end{aligned}\n    \\qquad \\text{for $k\\in\\mathbb{Z}$}.\n\\end{equation}\n\nIn the following, derivatives will be respect to $z$, and the argument $z$ to\n$F_k$ and $G_k$ will be omitted where it is unambiguous.\n\n\\subsection*{The integral $\\Int{}{} z F_1 G_1 \\D z$}\n\nThe relations \\eqref{eq:fgrel} give the identities\n\\begin{equation}\n    \\begin{aligned}\n        \\label{eq:fgrel2}\n        (z^kF_k)' &= z^{k-1}F_{k-1}\\\\\n        (z^kG_k)' &= \\omega z^{k-1}G_{k-1}.\n    \\end{aligned}\n\\end{equation}\nConsequently\n\\begin{equation}\n    \\begin{aligned}\n        (z^2 F_2 G_1)' &= z F_1 G_1 + z^2 F_2 \\Gp_1 = z F_1 G_1 - \\omega z^2 F_2 G_2 \\\\\n        (z^2 F_1 G_2)' &= z F_1 G_1 + z^2 \\Fp_1 G_2 = z F_1 G_1 + z^2 F_2 G_2.\n    \\end{aligned}\n\\end{equation}\nCancelling the $F_2G_2$ term gives\n\\begin{equation}\n    (z^2 F_2 G_1 + \\omega z^2 F_1 G_2)' =\n    (1+\\omega^2) z F_1 G_1,\n\\end{equation}\nand so\n\\begin{equation}\n    (1+\\omega^2) \\Int{}{} z F_1 G_1 dz = z^2 F_2 G_1 + \\omega z^2 F_1 G_2 = z^2 \\Fp_1 G_1 - z^2 F_1 \\Gp_1.\n\\end{equation}\n\n\\subsection*{The integral $\\Int{}{} z F_1 \\D z$}\n\nAs observed in \\eqref{eq:fgrel2}, $(z^2 F_2)' = z F_1$, and so\n\\begin{equation}\n    \\Int{}{} z F_1 dz = z^2 F_2 = z^2 \\Fp_1.\n\\end{equation}\n\n\\subsection*{The integral $\\Int{}{} z G_1^2 \\D z$}\n\nFollowing the technique of \\autocite[p.533]{lommel1879},\n\\begin{equation}\n    \\begin{aligned}\n        (z^a G_k G_{m+1})'\n        &= a z^{a-1} G_k G_{m+1} + z^a(\\Gp_k G_{m+1} + G_k \\Gp_{m+1})\\\\\n        &= a z^{a-1} G_k G_{m+1} - \\omega z^a G_{k+1}G_{m+1} + z^{a-1} G_k(\\omega G_m - (m+1) G_{m+1})\\\\\n        &= (a-m-1) z^{a-1} G_k G_{m+1} + \\omega z^{a-1} (zG_{k+1}G_{m+1} - G_k G_m).\n    \\end{aligned}\n\\end{equation}\nThe last term is symmetric in $k$ and $m$, so\n\\begin{equation}\n    (z^a G_k G_{m+1} - z^a G_m G_{k+1})' =\n    (a-m-1) z^{a-1} G_k G_{m+1} - (a-k-1) z^{a-1} G_m G_{k+1}.\n\\end{equation}\nLetting $a=k+1$ then gives,\n\\begin{equation}\n    (z^{k+1} G_k G_{m+1} - z^{k+1} G_{k+1} G_m)' = (k-m) z^k G_k G_{m+1},\n\\end{equation}\nand in particular,\n\\begin{equation}\n    \\label{eq:intzg1sq}\n    \\Int{}{} z G_1^2 \\D z = z^2 G_1^2 - z^2 G_0 G_2.\n\\end{equation}\n\nThe result \\eqref{eq:intzg1sq} can be expressed in terms of just $G_1$ and $\\Gp_1$ by\napplication of the recurrence relationships:\n\\begin{equation}\n    \\label{eq:intzg1sqbis}\n    \\Int{}{} z G_1^2 \\D z = z^2 G_1^2 + \\frac{z^2}{\\omega^2} G_1 \\Gp_1 + \\frac{z^3}{\\omega^2} G^{\\prime 2}_1.\n\\end{equation}\n\n\n\\printbibliography\n\\end{document}\n", "meta": {"hexsha": "0c6d34a249bdbb9ec012169292aa395602202fde", "size": 25130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/math/cable_equation/cable_equation.tex", "max_stars_repo_name": "kanzl/arbor", "max_stars_repo_head_hexsha": "86b1eb065ac252bf0026de7cf7cbc6748a528254", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 53, "max_stars_repo_stars_event_min_datetime": "2018-10-18T12:08:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T22:03:51.000Z", "max_issues_repo_path": "doc/math/cable_equation/cable_equation.tex", "max_issues_repo_name": "kanzl/arbor", "max_issues_repo_head_hexsha": "86b1eb065ac252bf0026de7cf7cbc6748a528254", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 864, "max_issues_repo_issues_event_min_datetime": "2018-10-01T08:06:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T08:06:48.000Z", "max_forks_repo_path": "doc/math/cable_equation/cable_equation.tex", "max_forks_repo_name": "kanzl/arbor", "max_forks_repo_head_hexsha": "86b1eb065ac252bf0026de7cf7cbc6748a528254", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2019-03-03T16:18:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T10:39:51.000Z", "avg_line_length": 34.854368932, "max_line_length": 130, "alphanum_fraction": 0.6144846797, "num_tokens": 9824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6160752707540629}}
{"text": "\\subsubsection{Repeated Linear Factors}\r\n\\noindent\r\nIf $Q(x)$ has repeated roots, it factors into\r\n\\begin{equation*}\r\n\tQ(x) = R(x)(x-a)^k\\text{, }k \\geq 2\\text{ and }R(a) \\neq 0\r\n\\end{equation*}\r\nWhen making the common denominator for each repeated root of multiplicity $k$, we do\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{R(x)(x-a)^k} = \\left(\\text{Decomposition of }R(x)\\right) + \\frac{A_1}{x-a}+\\ldots+\\frac{A_k}{(x-a)^k}\r\n\\end{equation*}\r\nYou would then multiply each side by the denominator like in the linear factors case and solve for the coefficients. The only additional difficulty is that you might have to use previous results or solve a system of linear equations to get some of the constants.\r\n\r\n\\ifodd\\includeBackgroundReviewExamples\\input{./backgroundReview/algebraPreCalc/repeatedLinearFactors_example.tex}\\fi", "meta": {"hexsha": "829fb0cb403f34eb4ba272a59fd5271bf8b523a1", "size": 816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/algebraPreCalc/repeatedLinearFactors.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/algebraPreCalc/repeatedLinearFactors.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/algebraPreCalc/repeatedLinearFactors.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": 62.7692307692, "max_line_length": 263, "alphanum_fraction": 0.7414215686, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.616040825434771}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amssymb,latexsym,amsmath}\n%\\usepackage{epsfig}\n%\\usepackage{graphicx}  \n%\\DeclareGraphicsExtensions{.pdf, .jpg, .tif, .eps, .jpg}\n\n\\newif\\ifpdf\n\\ifx\\pdfoutput\\undefined\n\\pdffalse % we are not running PDFLaTeX                                        \n\\else\n\\pdfoutput=1 % we are running PDFLaTeX                                         \n\\pdftrue\n\\fi\n\\ifpdf\n\\usepackage[pdftex]{graphicx}\n\\else\n\\usepackage{graphicx}\n\\fi\n\\ifpdf\n\\DeclareGraphicsExtensions{.pdf, .jpg, .tif}\n\\else\n\\DeclareGraphicsExtensions{.eps, .jpg}\n\\fi\n\n\n\n\\textwidth = 6.5 in\n\\textheight = 9 in\n\\oddsidemargin = 0.0 in\n\\evensidemargin = 0.0 in\n\\topmargin = -0.5 in\n\\headheight = 0.0 in\n\\headsep = 0.0 in\n\\parskip = 0.2 in\n\\parindent = 0.0 in\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\newcommand{\\khat}{\\hat{\\mathbf k}}\n\\newcommand{\\uv}{\\mathbf u}\n%\\newcommand{\\omegav}{\\mathbf \\omega}\n\\newcommand{\\omegav}{\\mathbf w}\n\\newcommand{\\w}{\\mathbf w}\n\\newcommand{\\grad}{\\nabla}\n\\newcommand{\\curl}{\\grad \\times}\n\n\\DeclareMathOperator{\\Span}{span}\n\n\n\\title{The Boussinesq equations and Coordinate scalings in the\n  LANL-Sandia DNS code} \\author{Mark Taylor, Beth Wingate, Susan Kurien}\n\n\\begin{document}\n\\maketitle\n\n\\section{Scaling of the Domain}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=4.in]{box}\n\\caption{ }\n\\label{F:box}\n\\end{center}\n\\end{figure}\n\n\n\nWe would like to solve the NS equations in the box pictured in\nFig.~\\ref{F:box}.  The equations are\n\\[\n\\frac{ \\partial  \\uv }{\\partial t}  + (\\curl \\uv + f \\khat) \\times \\uv + \n\\grad \\pi + N \\theta \\khat = \\nu \\Delta \\uv\n\\]\n\\[\n\\grad \\cdot \\uv = 0\n\\]\n\\[\n\\frac{ \\partial  \\theta }{\\partial t}  + \\uv \\cdot \\grad \\theta - \nN \\uv \\cdot \\khat = \\kappa \\Delta \\theta\n\\]\nThe Schmidt number is $\\nu / \\kappa$.  \n\nWe refer to the coordinate system in the box in Fig.~\\ref{F:box} as\nthe primted coordinate system, and we now introduce a \nchange of variables, into the {\\em non-primed} coordinate\nsystem.  In the non-primed coordinate system, the domain because a \nunit cube:\n\\[\nx = x', \\qquad y=y', \\qquad  z = \\frac{z'}{h},\n\\]\nThe only change to our code is that:\n\\[\n\\frac{\\partial}{\\partial z'} = \\frac{1}{h} \\frac{\\partial}{\\partial z}\n\\]\nAnd thus \n\\[\n\\grad = \n\\begin{pmatrix} \\dfrac{\\partial}{\\partial x} \\\\[5mm]\n                \\dfrac{\\partial}{\\partial y} \\\\[5mm]\n                \\dfrac{1}{h} \\dfrac{\\partial}{\\partial z} \n\\end{pmatrix}\n \\qquad\n\\Delta  = \\left(\\frac{\\partial}{\\partial x}\\right)^2 + \n           \\left(\\frac{\\partial}{\\partial y}\\right)^2 +\n           \\left(\\frac{1}{h}\\frac{\\partial}{\\partial z}\\right)^2 \n\\]\nand\n\\[\n\\grad \\cdot \\uv = \\frac{\\partial u_1 }{\\partial x} + \n\\frac{\\partial u_2 }{\\partial y} + \n\\frac{1}{h} \\frac{\\partial u_3 }{\\partial z}\n\\]\nand  vorticity $\\omegav$ is given by\n\\begin{equation}\n\\label{E:vor}\n\\omegav = \\curl \\uv = \n\\begin{pmatrix}\n\\dfrac{\\partial u_3}{\\partial y} - \\dfrac{1}{h} \\dfrac{\\partial u_2}{\\partial z}  \\\\[5mm]\n\\dfrac{1}{h} \\dfrac{\\partial u_1}{\\partial z} -  \\dfrac{\\partial u_3}{\\partial x}  \\\\[5mm]\n\\dfrac{\\partial u_2}{\\partial x} - \\dfrac{\\partial u_1}{\\partial y}\n\\end{pmatrix}  \n\\end{equation}\n\n\nThe divergence free condition on $\\uv$ is solved by the choice\nof $\\pi$.  This involves, \nfor some vector field ${\\mathbf v}$, \nsolving an equation of the form \n\\[\n\\Delta \\pi = \\grad \\cdot {\\mathbf v}\n\\] \nThe remaining equations we write in component form:\n\\[\n\\begin{pmatrix} u_1 \\\\\n                u_2 \\\\\n                u_3 \\\\\n\\end{pmatrix}_t\n  + (\\omegav + f \\khat) \\times \n\\begin{pmatrix} u_1 \\\\\n                u_2 \\\\\n                u_3 \\\\\n\\end{pmatrix}\n+ \\grad \\pi +\n\\begin{pmatrix} 0 \\\\\n                0 \\\\\n                N \\theta \\\\\n\\end{pmatrix}\n= \\nu \n\\begin{pmatrix} \\dfrac{\\partial^2 u_1}{\\partial x^2} + \n                \\dfrac{\\partial^2 u_1}{\\partial y^2} + \n                \\dfrac{1}{h^2}\\dfrac{\\partial^2 u_1}{\\partial z^2}   \\\\[5mm]\n                \\dfrac{\\partial^2 u_2}{\\partial x^2} + \n                \\dfrac{\\partial^2 u_2}{\\partial y^2} + \n                \\dfrac{1}{h^2}\\dfrac{\\partial^2 u_2}{\\partial z^2}   \\\\[5mm]\n                \\dfrac{\\partial^2 u_3}{\\partial x^2} + \n                \\dfrac{\\partial^2 u_3}{\\partial y^2} + \n                \\dfrac{1}{h^2}\\dfrac{\\partial^2 u_3}{\\partial z^2}\n\\end{pmatrix}\n\\]\n\\[\n\\frac{ \\partial  \\theta }{\\partial t}  + \\uv \\cdot \\grad \\theta - \nN u_3  = \\kappa \\left(\n                \\dfrac{\\partial^2 \\theta}{\\partial x^2} + \n                \\dfrac{\\partial^2 \\theta}{\\partial y^2} + \n                \\dfrac{1}{h^2}\\dfrac{\\partial^2 \\theta}{\\partial z^2}\n\\right)\n\\]\n\n\n\nThus the only changes needed for our parallel DNS code are is that\nall derivatives in $z$ need to be scaled by $h$.\n\n\n\\section{Hyper Viscosity}\nConsider our scaled hyper viscosity term\n\\[\n\\frac{ \\partial  \\uv }{\\partial t} = \n\\sqrt{E(k_\\textrm{max})} \\,  k_\\textrm{max}^{-2\\eta + 1.5}  \\Delta^\\eta \\uv\n\\]\nWe first verify that the units are correct.  The units of\nenergy are $m^2/s^2$, so the units of the energy in a single\nspherical shell $E(k)$ is $m^3/s^2$.  Thus we have\n\\[\n\\frac{m}{s^2} = \\frac{m^{1.5}}{s} \\,\\frac{1}{m^{-2\\eta+1.5}}  \n                          \\,\\frac{1}{m^{2\\eta}}\n                           \\, \\frac{m}{s}\n\\]\nIn the frequency domain, \n\\[\n\\frac{ \\partial  u_3 }{\\partial t} = \n\\sqrt{E(k_\\textrm{max})} \\,  k_\\textrm{max}^{-2\\eta + 1.5}  \n( (2\\pi l)^2 + (2\\pi m)^2 + (2\\pi n/h)^2)^\\eta u_3\n\\]\n\n\\section{Resolution Condition}\n\nThe assumptions made in the hydrostatic equations implicitly assume\n(acording to Leslie) that \n\\[\n \\max{ k_h } << \\min{k_z}\n\\]\nwhich works out to (assuming 2/3 dealiasing)\n\\[\n   \\frac{N_x}{3} <<  \\frac{1}{h}\n\\]\n\n\n\n\\section{Computing Scalars}\nIntegrals per unit volume are approximated by the sum\n\\[\n<f,g> = \\frac{1}{h} \\iiint  f g  \\, dx' \\, dy' \\, dz' =   \\iiint  f g \\, dx \\, dy \\, dz\n=\\frac{1}{N_x N_y N_z} \\sum  f  g\n\\]\nWe also have that \n\\[\n\\frac{1}{N_x N_y N_z} \\sum  f  g = \\sum \\hat{f} \\hat{g}\n\\]\nso integrals can be computed in Fourier or grid space. \n\nAll other scalars (kinetic energy, helicity, various dissipation\nterms) are computed in physical coordinates.  So for example\n\\[\nk = <\\uv,\\uv> = <u_1,u_1> + <u_2,u_2> +  <u_3,u_3>\n\\]\nand the helicity \n\\[\n  h  = w_1 u_1  + w_2 u_2 + w_3 u_3\n\\]\nAs in example, using integer wave numbers $(l,m,n)$ (defined in the\nnext section), we have\n\\[\n< \\omegav , \\Delta \\uv> = \\sum (2 \\pi)^2 (l^2 + m^2 + (n/h)^2) \n\\, \\uv \\cdot \\omegav\n\\]\n\n\n\n\n\n\\section{Computing 3D Energy Spectra (in a spherical shell)}\nIf we choose to discretize our domain so that the \nmaximum wave number (in the primed coordinate system) is\nthe same in all diretions, then\n\\[\n\\Delta x' = \\Delta y' = \\Delta z'\n\\]\nOr\n\\[\nN_x  = N_y = N_z/h\n\\]\nwhere $N_x$ is the number of grid points in the $x$ direction.\nThe highest wave number is given by:\n\\[\nk_x = \\pi N_x, \\qquad k_y = \\pi N_y, \\qquad k_z = \\pi N_z/h \n\\]\n(Note that $\\pi$ appears in the wave numbers since our domain is\nof length 1 in the $x$ and $y$ diretions.)  The wave number spacing\nis given by\n\\[\n\\Delta k_x = 2 \\pi, \\qquad  \\Delta k_y = 2 \\pi, \\qquad  \\Delta k_z = 2 \\pi / h \n\\]\nIn our DNS code, we index our arrays of Fourier coefficients\nwith integers $(l,m,n)$, with $l=0 \\dots N_x/2$, \n$m=0 \\dots N_y/2$ and \n$n=0 \\dots N_z/2$.  The wave number spacing is given by\ngiven by\n\\[\nk_x = l \\Delta k_x,, \\qquad  k_y = m \\Delta k_y, \\qquad  k_z = n  \\Delta k_z\n\\]\nWe index the arrays containing power spectra\nsuch as $E(k)$ with integer wave number $k$, represents a shell or anulus\nof some chosen thickness centered around the wave number associated\nwith $k$.\n\nThe total energy is\n\\[\nE  = \\sum_{l,m,n}  |  {\\hat u_1}(l,m,n) |^2 +\n |  {\\hat u_2}(l,m,n) |^2 + \n |  {\\hat u_3}(l,m,n) |^2\n\\]\n\nThe standard energy spectrum is now, for integers $k$:\n\\[\nE(k)  = \\sum_{l,m,n}  |  {\\hat u_1}(l,m,n) |^2 +\n |  {\\hat u_2}(l,m,n) |^2 + \n |  {\\hat u_3}(l,m,n) |^2\n\\]\nwhere the sum is taken over all integers $(l,m,n)$ such that\n\\[\n(\\Delta k_z)^2 (k-1/2)^2 \\le (\\Delta k_x l)^2 + (\\Delta k_y m)^2 + (\\Delta k_z n)^2 <  (\\Delta k_z)^2 (k+1/2)^2 \n\\]\nwhere we have chosen to use a shell thickness of $\\Delta k_z$.\nScaling out the $2\\pi$, we get\n\\[\n(k-1/2)^2 \\le  h^2 \\left( l^2 + m^2 + (n/h)^2 \\right) < (k+1/2)^2\n\\]  \n\n\n\n\n\n\\section{Computing 2D Energy Spectra (in an annulus)}\nWe also compute a 2D spectra $E(k_h,k_z)$ by summing squares of Fourier\ncoefficients over annular regions in \n$x$ and $y$ of radius $k_h$.  \nwhere \n\\[\nk_h = \\sqrt{(k_x^2 + k_y^2)} = \\sqrt{(2\\pi l)^2 + (2\\pi m)^2}. \n\\]\nFrom this quantity, we can get $E(k_h,0)$, which \nrepresents the energy spectrum of the 2D field\nobtained by averaging the original 3D field  in the direction of rotation,\nand then summing the energy within spherical shells (an annulus for 2D fields).\nWe are also interested in \n\\begin{equation}\nE(k_h) = \\sum_{k_z=0}^{\\pi N_z/h} E(k_h,k_z) \n\\label{E:SPECb}\n\\end{equation}\nwhich represents \nthe energy spectrum of the full 3D field, but summed over\nthe annular region between concentric cylinders\n(whose axis are in the $z$ direction).  As with the spherical\nshell spectrum, Eq.~\\ref{E:SPECb} has the property that\nit partitions the energy into a set of discrete wave numbers, so\nthat the total energy \n\\[\nE = \\sum_{k_h} E(k_h)\n\\]\n\n\nThe 2D shell (annulus) thickness is now\ndetermined by the horizontal wavenumber spacings. In our code,\nwe use an integer index $k$ defined by $k_h = k \\Delta k_x$ and\ndefine\n\\begin{eqnarray*}\nE(k,j) = \\sum_{l,m}  |  {\\hat u_1}(l,m,n) |^2 +\n |  {\\hat u_2}(l,m,n) |^2 + \n |  {\\hat u_3}(l,m,n) |^2\n\\end{eqnarray*}\nwhere the sum is taken over fixed $n$ and all integers $(l,m)$ such that \n\\[\n(\\Delta k_h)^2 (j-1/2)^2 \\le (\\Delta k_x l)^2 + (\\Delta k_y m)^2  <  (\\Delta k_h)^2 (j+1/2)^2 \n\\]\nand with $k_x=k \\Delta k_x$ for integers $k$.  \nwe have chosen to use a shell thickness of $\\Delta k_h =\\Delta k_x = \\Delta\nk_y = 2\\pi$. Scaling out the $2\\pi$, we get\n\\[\n(j-1/2)^2 \\le  l^2 +  m^2 < (j+1/2)^2.\n\\]  \n\n\\section{Running the Model for the Boussinesq equations}\n\n\\noindent\nThis section discusses important elements of the inputfile and how to\nbuild the executable.\n\nWhen you've chosen scalar type = 4 in the gridsetup script (see\nbelow), you need to add a line to the input file right after the line\nfor the smagorinsky coefficient,\n\\noindent\n\\begin{verbatim}\n.\n.\n.\n107.08        ! Bous. parameter  Fr = .21/bous=107.08\n0e0           ! alpha (for NS-alpha model).  alpha>1 is in units of delx\n.0            ! smagorinsky\n1             ! max number of schmidt numbers for passive scalars\n1. 4          ! schmidt number = nu/kappa, ratio of viscous coeffs,type of scalar\n0             ! compute_structure_functions\n.\n.\n. \n\\end{verbatim}\n\n\nNote that the type in this file must match the type in the gridsetup\ncommand. Also note that if you want to the code to compute the\ntwo-point correlations of potential vorticity then you need to set the\nvalue of \\texttt{compute structure functions} to 1.\n\n\\noindent\nTo set up the model you need to use the following:\n\n\\begin{description}\n  \n\\item[1)] Example to set the FORTRAN arrays sizes before compiling:\n  ($32^3$ simulation on 8 processors, prognostic variables: $u,v,w$\n  and $\\theta$). Note the 4 on the end, which\n  indicates the type of scalar equations for the code to use \\\\\n \n  \\begin{verbatim}\n      ./gridsetup.py 1 1 8 32 32 32 2 2 2 0 0 0 4\n  \\end{verbatim}\n\n  \\noindent\n  This one sets up the problem for $128^3$ on 32 processors\n  like this:\n\n  \\begin{verbatim}\n   ./gridsetup.py 1 1 32 128 128 128 2 2 2 0 0 0 4\n  \\end{verbatim}\n\n\\item[2)] Then one makes the Boussinesq equations by\n  typing\\\\\n\n  \\begin{verbatim}\n  gmake dnsb\n  \\end{verbatim}\nthis  is identical to the dns code, except that it compiles in\nthe Boussinesq diagnostics (aspect\\_diag.F90) \ninstead of the usual turbulence\ndiagnostics (turb\\_diag.F90). \n\\end{description}\n\n\\noindent\n\n\\section{Comparing with Smith \\& Waleffe (SW99 and SW02)}\n\n\\subsection{Scalings and definitions}\n\n\\subsubsection*{$\\underline{\\text{Wave numbers}}$}\nWave numbers are dimensional and should be computed $k_f = 2 \\pi\nk_f^m$, where the superscript $m$ stands for Mark. \n\n\\subsubsection*{$\\underline{\\text{Rossby Number}}$}\nSW02 computes this Rossby number,\n\\begin{equation}\n  Ro = \\frac{(k_f^2 \\epsilon_f)^{1/3}}{\\text{fcor}}, \n\\end{equation}\nwhere each number in the equation is computed as,\n\\begin{description}\n   \\item[1)] $k_f = 2 \\pi k_f^m$\n   \\item[2)] $\\epsilon_f$ is computed as an average through the run using\n     scalars.m. It can also be found for each time in the output file\n     if one looks at the $d/dt$ line and hunts for the f parameter (for\n     the forcing).\n  \\item[3)] fcor is an input to the code. There is some question as to\n    whether we should divide by $fcor/2$ or $fcor$, see SW02 Eq 3.2\n\n\\end{description}\n\n\\subsubsection*{$\\underline{\\text{Froude number}}$}\n\nModifications to the dns code to accomodate this is to include the\naddition of a parameter {\\bf{bous}} which multiplies the vertical\nvelocity in the  density anomoly equation. The equations we actually\nsolve in the code are,\nWe would like to solve the NS equations in the box pictured in\nFig.~\\ref{F:box}.  The equations are\n\\[ \n\\frac{ \\partial  \\uv }{\\partial t}  + (\\curl \\uv + \\text{fcor} ~\\khat) \\times \\uv\n+  \n\\grad \\pi + \\text{bous}~ \\theta \\khat = \\nu \\Delta \\uv \n\\] \n\\[ \n\\grad \\cdot \\uv = 0 \n\\] \n\\[ \n\\frac{ \\partial  \\theta }{\\partial t}  + \\uv \\cdot \\grad \\theta -  \n\\text{bous} ~\\uv \\cdot \\khat = \\kappa \\Delta \\theta.\n\\] \nTherefore to compute a consistent Froude number,\n\\begin{equation}\nFr = \\frac{(\\epsilon_f k_f^2)^{1/3}}{\\text{bous}}.\n\\end{equation}\nBasically, $\\text{bous}$ in the code is the is the same as $N$ in SW02 eq\n2.1-2.3.\n\n\n\n\\subsubsection*{$\\underline{\\text{Time Scale}}$}\nTo be consistent with SM multiply the time in the output file by the\ntime scale from SM, $t_{sw02} = (\\epsilon_f (2 \\pi k_f)^2)^{1/3}$\n\n\n\\subsection{Test of rotation only, $\\text{bous} = 0$ (no stratification)}\n\nCompare figure (\\ref{fig:SW99Fig3}) and figure (r16ketime).\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{SW99Fig3}\n\\caption{From Smith and Waleffe 1999}\n\\label{fig:SW99Fig3}\n\\end{center}\n\\end{figure}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{r16ketime}\n\\caption{From sandia/lanl dns code for different kinds of hypeviscosity}\n\\label{fig:r16ketime}\n\\end{center}\n\\end{figure}\n\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{SW99Fig4}\n\\caption{From Smith and Waleffe 1999}\n\\label{fig:SW99Fig4}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{SW99Fig10}\n\\caption{From Smith and Waleffe 1999}\n\\label{fig:SW99Fig10}\n\\end{center}\n\\end{figure}\n\n\n\\subsection{Test of stratification only, $fcor=0$ (no rotation) }\n\nCompare figure (\\ref{fig:SW02Fig2}) to figure (\\ref{fig:t900})\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{SW02Fig2}\n\\caption{From Smith and Waleffe 2002}\n\\label{fig:SW02Fig2}\n\\end{center}\n\\end{figure}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=4.in]{t900}\n\\caption{From the sandia/lanl dns code for 3 different types of hyperviscosity.}\n\\label{fig:t900}\n\\end{center}\n\\end{figure}\n\n\n\n\n\nFirst test, $f=0, N\\ne0$. Choose $bous=107.08$ with hyperviscosity. Then\n\\begin{equation}\nFr = \\frac{\\left((.5)(2 \\pi 24)^{2}\\right)^{1/3}}{107.08}= .21\n\\end{equation} \nForcing is: \n\\begin{verbatim}\nsto_high_24.\n\\end{verbatim}\nA plot of the spectrum is in Figure \\ref{fig:norot} and should be\ncompared to SW02's Figure 2.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{frp21}\n\\caption{Spectrum from $200^3$ simulation of LANL/Sandia DNS code with\n  no rotation and $Fr=.21$. This is Smith and Waleffe 2002 Figure 3.}\n\\label{fig:norot}\n\\end{center}\n\\end{figure}\n\n\\subsection{Test of nontrivial rotation and stratification $N\\ne0, f\\ne0$ - }\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=6.in]{SW02Fig4}\n\\caption{From Smith and Waleffe 2002}\n\\label{fig:SW02Fig4}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[angle=-90,width=4.in]{SW02Fig5}\n\\caption{From Smith and Waleffe 2002}\n\\label{fig:SW02Fig5}\n\\end{center}\n\\end{figure}\n\n\n\\begin{eqnarray}\nFr &=& \\frac{\\left((.5)(2 \\pi 24)^{2}\\right)^{1/3}}{107.08}= .21 \\\\ \nRo &=& \\frac{\\left((.5)(2 \\pi 24)^{2}\\right)^{1/3}}{1.07077} = 21\n\\end{eqnarray} \nThis means $\\text{bous}=108.07$ and $\\text{fcor} =1.07077 $ . We try\nto produce the plots in Smith and Waleffe Figure 4 and 5.\n\nForcing is\n\\begin{verbatim}\nsto_high_24.\n\\end{verbatim}\n\n\\section{Test of projection routines in unit aspect ratio.  March 4, 2009, SK}\n\nThe projection of the boussinesq data onto the Craya-Herring normal\nmodes is in spectrum.F90 in the compute\\_project\\_ch subroutine. This\nroutine is called from analysis\\_spectral.F90 and decomposes a given\nsnapshot (gridspace) into its two wave and one vortical mode (SW02) in fourier space and computes the power spectra of those modes.\n\nAll our test cases were run to compare with the unit aspect ratio\ncases in SW02. We match the resolution ($128^3$), Ro, Fr and forcing\nwavenumber $k_f = 24$. Our energy input rate $\\epsilon_f = 0.5$.\n\n\\subsection{Case SW02: $128^3$ gridpoints, $N/f \\rightarrow \\infty$, $Fr = 0.21$, $Ro \\rightarrow \\infty$}\nFigure \\ref{Froude_time} shows the time evolution of the kinetic energy of the flow with the same nondimensional time and energy units used in SW02 namely:\n$$T = t(\\varepsilon_f k_f^2)^{1/3}$$\n$$energy = E(\\varepsilon_f/k_f)^{-2/3}$$\nThis case was run upto T = 1088 in these units. This figure should be compared with Fig. 1 in SW02 for the $Fr = 0.21$, $k_f = 24$ case.\n\\begin{figure}[ht]\n\\centering\n  \\includegraphics[scale = 0.5]{Comp_SW02_fig1_Nfinf_kf24}\n\\caption{Evolution in time of the kinetic energy. To be compared with $Fr = 0.21$, $k_f = 24$ curve in Figure 1 of SW02.\\label{Froude_time}}\n\\end{figure}\n\nThe figure \\ref{Froude_spec} shows the total and projected spectra for\nthis case at T=1088, to be compared with SW02, Fig. 2, plotted at T = 900.\nThe total and $k_h=0$ agree very well qualitatively.\n\\begin{figure}[ht]\n\\centering\n  \\includegraphics[scale = 0.7]{Comp_SW02_fig2}\n  \\caption{Total energy and the projected wave, vortical and $k_h=0$\n    spectral distributions at T = 690. To be compared with Figure 2 of\n    SW02. \\label{Froude_spec}}\n\\end{figure}\n\n\\subsection{Case SW02: $128^3$ gridpoints, $N/f = 100$, $Fr = 0.21$, $Ro = 21$} \nFigure \\ref{NF100_time} shows the time evolution of the kinetic energy of the flow with the same non-dimensional time and energy units used in SW02 namely:\n$$T = t(\\varepsilon_f k_f^2)^{1/3}$$\n$$energy = E(\\varepsilon_f/k_f)^{-2/3}$$\nThis case was run upto T = 1151 in these units. Note that SW02\nruns this case upto T=2200 (not shown in their Fig. 4) and plots their\nspectra at T=2200. Comparing Fig. \\ref{NF100_time} and the $N/f = 100$\ncurve of SW02 Fig. 4 upto time T = 800 (the maximum time-scale in\nSW02) we notice slight differences which can probably be attributed to\nthe slight difference in our peak forcing wavenumbers (ours is\n$k_f=24$, vs. SW02 $k_f=20$) and the fact that our $\\epsilon_f \\simeq\n0.5$ whereas SW02 fixed theirs at $\\epsilon_f = 1$. But the overall\nshape of the curve, the time at which it starts to grow after an\ninitial equilibrium ($\\approx T = 200$) is the same.\n\\begin{figure}[ht]\n\\centering\n  \\includegraphics[scale = 0.5]{Comp_SW02_fig4_Nf100}\n\\caption{Evolution in time of the kinetic energy. To be compared with $N/f = 100$ curve in Figure 4 of SW02.\\label{NF100_time}}\n\\end{figure}\n\nThe energy spectra of the total energy as well as the wave, vortical\nand $k_h=0$ VSHF modes is given in Fig. \\ref{NF100_spec}. This is\ncomputed at our latest time of $T=1151$, to be compared with the SW02\nFig. 5 computed at T = 2200. The differences can probably be\nattributed both to the later time of SW02 and the slight differences\nin our forcing wavenumber, energy input rate $\\epsilon_f$. But the\nqualitative agreement is good. The $k_h = 0$ VSHF modes carry most of\nthe energy in the peak low-wavenumbers. An unexplained difference is\nthe 'peaky' nature of the low-mode energy distribution ($5< k < 10$)\nin SW02 Fig. 5. This does not appear in our runs. We show in addition\nthe wave and vortical mode spectra which SW02 does not show. We do not\nshow the potential energy spectrum which SW02 does show.\n\\begin{figure}[ht]\n\\centering\n  \\includegraphics[scale = 0.7]{Comp_SW02_fig5}\n\\caption{Total energy and the projected wave, vortical and $k_h=0$ spectral distributions at T = 1151. To be compared with Figure 5 of SW02. \\label{NF100_spec}}\n\\end{figure}\n\n\\subsection{Case SW02: $128^3$ gridpoints, $N/f = 10$, $Fr = 0.21$, $Ro = 2.1$}\nFigure \\ref{NF10_time} shows the time evolution of the kinetic energy\nof the flow with the same non-linear time and energy units used in\nSW02. This case was run upto about T = 690 in those units. Note that SW02\nruns this case upto T=605. Comparing Fig. \\ref{NF10_time} and the $N/f = 10$\ncurve of SW02 Fig. 4 upto time T = 605 (the maximum time-scale in\nSW02) we notice slight differences which can probably be attributed to\nthe fact that our $\\epsilon_f \\simeq\n0.5$ whereas SW02 fixed theirs at $\\epsilon_f = 1$. But the overall\nshape of the curve, the time at which it starts to grow after an\ninitial equilibrium ($\\approx T = 200$) is the same.\n\\begin{figure}[ht]\n\\centering\n  \\includegraphics[scale = 0.5]{Comp_SW02_fig4_Nf10}\n\\caption{Evolution in time of the kinetic energy (NOT the total energy as it says in the title field). To be compared with $N/f = 10$ curve in Fig. 4 of SW02. \\label{NF10_time}}\n\\end{figure}\n\nThe energy spectra of the total energy for this run as well as the\nwave, vortical and $k_h=0$ VSHF modes is given in Fig.\n\\ref{NF10_spec}. This is computed at our latest time of $T=690$, to be\ncompared with the SW02 Fig. 9 computed at T = 605. The differences can\nprobably be attributed both to the slightly earlier time of SW02 and\nthe slight differences in our energy input rate $\\epsilon_f$. The\nqualitative agreement is good. An unexplained difference is the\n'peaky' nature of the low-mode energy distribution ($10< k < 15$) in\nSW02 Fig. 9, This does not appear in our runs although we do have a\nsmooth peaking of the energy in the same wavenumber range.  The $k_h =\n0$ (VSHF) modes carry most of the energy in the peak low-wavenumbers.\nThe PV (vortical) mode spectra also agree well in that they do not\ncontribute to the most energetic low wave numvers (corresponding to\nthe peak in the $k_h=0$ spectrum but they make the dominant\ncontribution to the low wavenumbers $k < 8$ but the energy in these\nlow modes is an order of magnitude less than the peak in $10< k <15$.\nWe also show in addition the wave modes which SW02 does not show. We\ndo not show the potential energy spectrum which SW02 does show.\n\\begin{figure}[ht]\n\\centering \n \\includegraphics[scale = 0.7]{Comp_SW02_fig9}\n \\caption{Total energy and the projected wave, vortical and $k_h=0$\n   spectral distributions computed at $T= 690$. To be compared with\n   Fig. 9 of SW02. \\label{NF10_spec}}\n\\end{figure}\n\n\\section{Test of projection routines and non-unit aspect ratio. July 9, 2009. SK}\nWe are trying to recover Figure 1 (dashed line) and Figure 2 in\nRemmel, Sukhatme and Smith, 2009.  Since our domain parameters our\ndifferent from those in Remmel et al 2009, we had to define the\nappropriate scales as follows:\n\n\\subsection{Scales}\n\\begin{table}[ht]\n\\begin{tabular}{lll}\n\\hline\\\\\nParameter & RSS09 & Sandia-LANL code\\\\\n\\hline\\\\\naspect ratio $A$ & 0.2 & 0.2\\\\\ndimension ($L_x \\times L_y\\times L_z$) & $10\\pi \\times 10\\pi \\times 2\\pi $ & $1  \\times 1 \\times A$ \\\\  \nresolution ($N_x \\times N_y \\times N_z$) & $80 \\times 400 \\times 400$ & $80 \\times 400 \\times 400$ \\\\\n$\\Delta k_x \\times \\Delta k_y \\times \\Delta k_z = \\frac{2\\pi}{L_x} \\times \\frac{2\\pi}{L_y} \\times \\frac{2\\pi}{L_z}$ & \n$0.2 \\times 0.2 \\times 1$ & $2\\pi \\times 2\\pi \\times 10\\pi$  \\\\\nenergy input rate $\\epsilon_f$ & 1 & 1 \\\\\nsmallest 3D $k$-shell &  $\\Delta k = \\Delta k_z = 1$ & $\\Delta k = \\Delta k_z = 10\\pi$\\\\  \nforcing shell $k_f = 4$ & $k_f = 4\\times \\Delta k_z = 4$ & $k_f = 4 \\times \\Delta k_z = 4\\times 10\\pi$\\\\\ndamped modes (fat shells) & $k \\leq 2.5$ & $k \\leq 2.5\\times 10\\pi $ \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nWith the above definitions, the various scales and $Ro$ and $Fr$ are\ndefined for each of the two simulations:\n\\begin{itemize}\n\\item typical velocity based on energy input rate and forcing scale\n  (which by choice is the same as the {\\it vertical scale}) $U =\n  ({\\epsilon_f}{H})^{1/3} = \\displaystyle(\\frac{\\epsilon_f}{k_f})^{1/3}$\n\\item typical vertical length scale $H = \\displaystyle\\frac{1}{k_f}$; \n\\item typical horizontal length scale $L = \\displaystyle\\frac{H}{A} = \\displaystyle\\frac{1}{A k_f}$;\n\\item $Ro = \\displaystyle\\frac{U}{Lf} = 0.05 \\implies f = \\displaystyle\\frac{U}{L Ro} = \\displaystyle\\frac{A \\epsilon_f^{1/3}  k_f^{2/3} } {Ro}$;\n\\item $Fr = \\displaystyle\\frac{U}{HN} = 0.05 \\implies N = \\displaystyle\\frac{U}{H Fr} = \\displaystyle\\frac{\\epsilon_f^{1/3}k_f^{2/3}}{Fr}$;\n\\item Nonlinear time $\\tau = (\\epsilon_f k_f^2)^{(-1/3)}$. We will use subscript $RSS$ or $S-L$ to denote the RSS09 or Sandia-LANL timescales respectively.\n\\item Energy scale ${\\cal E} = (\\epsilon_f /k_f)^{(2/3)}$. Again the corresponding subscripts will be used.\n\\end{itemize}\n\nRSS09 forces the eigenmodes randomly at each time-step. Sandia-LANL\ncode forces $u,v,w$ and $\\theta$ randomly at each time-step. These\nshould be equivalent.\n\nRemmel et al have a uniform drag added to the rhs of the equations, \n$-0.1 b$ where $b$ is any\nof $u,v,w,\\theta$, for all modes $k < 2.5$. In order to choose the\ncorresponding factor for the Sandia-LANL simulation we note that the\ndrag coefficient $d_r = 0.1$ has units of $T^{-1}$. Assuming the\nnon-dimensional product $\\tau d_r$, should be the same in each of our\nsimulations we can determine $d_r$ for the Sandia-LANL code. \n\nIn the RSS09 simulation, $\\tau d_r \\simeq 25$, and\ntherefore for the Sandia-LANL code the corresponding \n\\begin{itemize}\n\\item $d_r = 25/\\tau = 1$.\n\\end{itemize}\nIn order to get RSS09's dimensional time, we rescale our time by\n$\\tau_{RSS}/\\tau_{S-L}$. In order to get RSS09's dimensional energy,\nwe rescale our energy by ${\\cal E}_{RSS}/{\\cal E}_{S-L}$.\n\n\\subsection{Results}\nUnless otherwise stated, all the scalings are as defined above for the\nSandia-LANL domain convention. The input file is:\n\n\\begin{verbatim}\n\n8            ! input file type\n1             ! file I/O header type   1-5\nns_uvw       ! equations\nzero        ! initial condition:  KH-blob, KH-anal, iso12\n0           ! init condition subtype\nsto_high_t4  ! forcing:  none, iso, iso12, iso12w, iso23w\n2.0 1       ! forcing parameters (not used for iso12, n.n=f^2, n width of gaussian)\nvalue        ! viscosity type  (value, smallest, kediff, Re)\n0e-5        ! viscosity coefficient.  (300)\nhyper16_imp   ! hyper16      ! hyper16_imp ! hyper vis\n2.500         ! hyper vis value\nhypo0        ! hypo vis\n1          ! hypo vis value\n100          ! fcor  rotation\n0.2        ! Z sscaling  (aspect ratio)\n500.0            ! Bous. parameter  \n0e0           ! alpha (for NS-alpha model).  alpha>1 is in units of delx\n.0            ! smagorinsky\n1             ! max number of schmidt numbers for passive scalars\n1. 4            ! schmidt number = nu/kappa, ratio of viscous coeffs, type\n0            ! compute_structure functions (set to 1 to compute strfns)\n0            ! compute pdf functions\nfft-dealias  ! derivative method  (fft, fft-dealias, fft-sphere, 4th)\nperiodic     ! x bc  (periodic, no-slip)\nperiodic     ! y bc\nperiodic     ! z bc\n5          ! time to run\n1.5          ! adv cfl  (0 = disabled, use min_dt) .8\n0.25           ! vis cfl  (0 = disabled, use min_dt) .01\n0.000010             ! min_dt\n.1             ! max_dt\n0.0          ! restart_dt  (0 = restart output disabled)\n.1          ! diag_dt   (.scalars)\n.1            ! model_dt   (.spec,.scalars-bous, .bisostr, .isostr)\n-50          ! screen_dt (0 = disables, +ve = timesteps, -ve = time)\n.2          ! output_dt  (field data, 0 = output disabled, except for custom out times)\n0             ! also output the vorticity\n0           ! n_output_custom  number of custom output times\n00.00       ! custom output times, one per line\n\n\n\n\\end{verbatim}\n\n\nFigure \\ref{Fig1_H} is to be compared with RSS09 Fig. 1. \n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale = .7]{RSS09_Fig1_UH}\n\\caption{The time has been rescaled by $\\tau_{RSS}/\\tau_{S-L}$ and the energy has been rescaled by ${\\cal E}_{RSS}/{\\cal E}_{S-L}$. \\label{Fig1_H}}\n\\end{figure}\n\n\nFigure \\ref{Fig2_H} is to be compared with RSS09 Fig. 2.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale = .7]{RSS09_Fig2_UH}\n\\caption{Total, wave and vortical energy spectra at rescaled time = 30.\\label{Fig2_H}}\n\\end{figure}\n\n\n\\section{Bousinesq scalars we're interested in computing}\n\nWe'd like to compute the following (dimensional) quantities integrated\naround in the volume:\n\n\\begin{itemize}\n\\item[1.] Total energy and total energy dissipation\n\n\\begin{equation}\n\\frac{\\partial}{\\partial t} \\frac{1}{2} \\int_V  \n         \\left[  (u^2 + v^2 + w^2) +   \\theta^2\\right]  \n= \\frac{1}{2}\\int_V \\left[  \\nu \\nabla^2 (u^2 + v^2 + w^2)  \n                     + \\kappa \\nabla^2 \\theta^2\n                         \\right] \n\\end{equation}\n\n\\item[2.] Potential energy, $\\frac{1}{2} \\theta^2$ \n\n\\item[3.] Kinetic energy, $\\frac{1}{2} ( u^2 + v^2 + w^2 )$ \n  \n\\item[4.] Potential vorticity (q) and its production-dissipation which\n  should globally integrate to zero I think.\n  \\begin{equation}\n  \\frac{\\partial}{\\partial t} \\int_V   \n           \\left[ q \\right]  \n  = \\int_V \\left[ \\nu (\\nabla^2 \\mathbf\\omega) \\cdot \\mathbf{\\nabla}\n    (\\bar{\\theta})\n                       + \\kappa (\\nabla^2 \\mathbf{\\nabla} \\theta) \\cdot  \n                       (\\mathbf\\omega  \n                       + \\text{fcor} ~{\\bf{\\hat{z}}} ))  \n                           \\right]  \n  \\end{equation}\n  \n  Here $\\mathbf = \\mathbf\\nabla \\times \\mathbf u$ is the vorticity and\n  $\\bar\\theta = \\theta_o -\\text{bous}~ z + \\theta(x,y,z)$. Also, $q =\n  (\\mathbf\\omega + \\text{fcor}~\\mathbf{\\hat{z}}) \\cdot \\mathbf\\nabla\n  \\bar\\theta.$\n\n\\item[5.] Potential enstrophy $Q = q^2/2$ and its\n  production-dissipation. This is the important production-dissipation\n  rate we need for our two-point correlation.\n\n\\item[6.] Potential vorticity production-dissipation\n\n\\item[7.] Potential enstrophy\n  \\begin{equation} \n    \\frac{\\partial}{\\partial t} \\int_V   \\left[ Q \\right]   \n    = \\int_V \\left[ \\nu  ~q (~\\nabla^2 ~\\mathbf\\omega) \\cdot \\mathbf{\\nabla}\n      (\\bar{\\theta})   \n      + \\kappa  ~q ~\\nabla^2 (\\mathbf{\\nabla} \\theta) \\cdot  \n      (\\mathbf\\omega   \n      + \\text{fcor} ~{\\bf{\\hat{z}}} ))   \n    \\right]   \n  \\end{equation} \n\n\\item[8.] two-point correlation (coming)\n\n\\end{itemize}\n\n\\section{Comparing SW to KSW}\nIn the two-point correlation paper the equations we use are scaled\ndifferently than than we use in Mark's code (which are the same\nequations used in SW). To make comparisions with our results in the\ntwo-point correlation paper we have to keep in mind the following\nscalings. Note, these are relationships between {\\sl{dimensional}}\nquantities, not nondimensional quantities.\n\\begin{gather}\n\\tilde\\rho = (\\frac{b \\rho_o}{g})^{1/2} ~\\theta\\\\\n(\\frac{g}{\\rho_o b})^{1/2}~\\rho = (\\frac{g \\rho_o}{b}) - \\text{bous}\n~z + \\theta = \\bar\\theta \\\\\nN = \\text{bous} = (\\frac{g b}{\\rho_o})^{1/2}\\\\\npe_{\\text{ksw}} = \\frac{1}{2} \\theta^2 = \\frac{g}{\\rho_o b} \\tilde\\rho^2\\\\\nq_{\\text{ksw}} = (\\frac{g}{b \\rho_o})^{1/2} q_{\\text{SW}}\n\\end{gather}\n\n\\end{document}\n", "meta": {"hexsha": "6071d754a816effd072a310846f61034f6779449", "size": 31651, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rotation_doc/rotation.tex", "max_stars_repo_name": "fxie2/dns", "max_stars_repo_head_hexsha": "868b5463dc74e0833b4f31674bd5a2f01f492244", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-04-07T16:07:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T17:17:30.000Z", "max_issues_repo_path": "rotation_doc/rotation.tex", "max_issues_repo_name": "mkha1785/dns", "max_issues_repo_head_hexsha": "868b5463dc74e0833b4f31674bd5a2f01f492244", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-05-10T17:15:47.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-10T17:15:47.000Z", "max_forks_repo_path": "rotation_doc/rotation.tex", "max_forks_repo_name": "mkha1785/dns", "max_forks_repo_head_hexsha": "868b5463dc74e0833b4f31674bd5a2f01f492244", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-07-21T10:54:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T06:57:04.000Z", "avg_line_length": 34.7813186813, "max_line_length": 177, "alphanum_fraction": 0.6685096837, "num_tokens": 10688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6160408207194777}}
{"text": "\\section{Tactic}\nAlthough proofs can be automatically checked given the system above, it requires user to input the whole\nterm of the specific type, which is tedious, exhaustive, mostly anti-intuitive.\\par\nSo in this part, we introduced some tactics into the system \nto assist users in better writing the proof. With the help of\ntactics, the proof becomes more human-readable and intuitive.\\par\n\n\\subsection{\\it apply}\nThis tactic applies to any goal. The purpose of this tactic is to extract premises of\ncurrent goal.\n\n\\subsection*{Usage}\n\\begin{itemize}\n\\item $\\it apply\\ \\tt t.$ : $\\tt t$ is a term of a type whose consequent is the goal.\n\\item $\\it apply\\ \\tt t\\ \\it in\\ \\tt H.$ : $\\tt t$ is a term of a type whose antecedent is $\\tt H$.\n\\end{itemize}\n\n\\subsection*{Implementation}\nThe tactic {\\it apply} tries to match the current goal against the \nfinal consequent of the type of term. \nIf it succeeds, it returns as many subgoals as \nthe number of non-dependent premises of the type of term.\\par\nHere is an example:\n\\begin{center}\n\\begin{minted}{coq}\nn : nat\nm : nat\no : nat\ne : eq nat n m -> eq nat m o -> eq nat n o                  \n(* Current Goal *)      \neq nat n o                        \n\n(* $\\Downarrow$ apply n $\\Downarrow$ *)   \n\nn : nat                                         n : nat                                       \nm : nat                                         m : nat                                   \no : nat                                         o : nat                                   \ne : eq nat n m -> eq nat m o -> eq nat n o      e : eq nat n m -> eq nat m o -> eq nat n o       \n(* SubGoal 1 *)                                 (* SubGoal 2 *)          \neq nat m o                                      e : eq nat n m\n\\end{minted}\n\\end{center}\nBecause \\mintinline{coq}|e| has a type of \\mintinline{coq}|eq nat n m -> eq nat m o -> eq nat n o| \nand the goal is \\mintinline{coq}|eq nat n o|,\nthe goal is convertible to the \\textbf{consequent} of the type of \\mintinline{coq}|e|.\nWhen applied with \\mintinline{coq}|e|,\nall of the non-dependent premises of the type of \\mintinline{coq}|e| become subgoals.\n\nThe tactic {\\it apply $\\tt tm$ in $\\tt H$} tries to match the hypothesis $\\tt H$ against the \nantecedent of the type of $\\tt tm$. \nIf it succeeds, the hypothesis $\\tt H$ will be replaced by the consequent of $\\tt tm$.\n\\begin{center}\n\\begin{minted}{coq}\nn : nat\nm : nat\no : nat\nH : eq nat n m \ne : eq nat n m -> eq nat m o -> eq nat n o                  \n(* Current Goal *)      \neq nat m o -> eq nat n o                                        \n\n(* $\\Downarrow$ apply e in H $\\Downarrow$ *)\n\nn : nat                                                                         \nm : nat                                                                     \no : nat  \nH : eq nat m o -> eq nat n o\ne : eq nat n m -> eq nat m o -> eq nat n o\n(* SubGoal 1*)                                            \neq nat m o -> eq nat n o                                      \n\\end{minted}\n\\end{center}\nBecause \\mintinline{coq}|e| has a type of \n\\mintinline{coq}|eq nat n m -> eq nat m o -> eq nat n o| \nand $\\tt H$ is \\mintinline{coq}|eq nat n m|,\n$\\tt H$ is convertible to the \\textbf{antecedent} of the type of the term.\nWhen applied with \\mintinline{coq}|e|,\n$\\tt H$ is replaced by the consequent of $\\tt e$.\n\n\\subsection{\\it destruct}\n\nWhen {\\it destruct} is applied on a term, this term must be inductive type. Then {\\it destruct} will divide current goal\ninto several classified subgoals based on the constructors of the inductive type. During this process, no induction \nhypothesis is generated by {\\it destruct}; the {\\it destruct} uses {\\tt match} to handle classified discussion.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it destruct}\\ \\tt t.$ : $\\tt t$ is a term of inductive type. \n\\end{itemize}\n\n\\subsubsection*{Implementation}\n\nThis tactic not only divides current goal based on the constructors of the inductive\ntype, but requires the system to handle several equivalent relations proposed by the constructors as well.\\par\nHere is an example:\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\nn, m : nat                                                      \ne : eq nat n m                             n : nat  \nf : eq nat m m      (* destruct e => *)    f : eq nat n n    \n(* Current Goal *)                         (* Current Goal *)\neq nat m n                                 eq nat n n       \n\\end{minted}\n\\end{minipage}\n\\end{center}\nFrom the constructor \\mintinline{coq}|eq_refl : eq T x x| and the type of \\mintinline{coq}|e : eq nat n m|,\nwe have \\mintinline{coq}|m = n|, so any occurrence of \\mintinline{coq}|m| should be replaced by \\mintinline{coq}|n|.\\par\nIf some term depends on the destructed term, we should rewrite it.\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\nn, m : nat                               \ne : eq nat n m                           \nf : eq nat m m     \n(* Current Goal *)                       \neq nat m n                               \n\n(* $\\Downarrow$ destruct m $\\Downarrow$ *)  \n\nn : nat                    n : nat                  \ne0 : eq nat n O            e0 : eq nat n (S m0) \nf0 : eq nat O O            f0 : eq nat (S m0) (S m0) \n(* SubGoal 1 *)            (* SubGoal 2 *)\neq nat O n                 eq nat (S m0) n     \n\\end{minted}\n\\end{minipage}\n\\end{center}\nThe two cases above are viewed from user's perspective.\nOn the other hand, in the system we also need to construct the term for back substitution.\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\nn, m : nat                                     \ne : eq nat (S n) (S m)  \n(* Current Goal*)                              \neq nat (S m) (S n)                             \n\n(* $\\Downarrow$ destruct (S n) $\\Downarrow$ *)   \n\n(* The Proof Object *)\n(fun (n:nat)(m:nat)(e:eq nat (S n) (S m)) =>                                                                                \n    match (S n) as n0 in nat return (eq nat n0 (S m) -> eq nat (S m) n0) with \n    | O => fun e0 : eq nat O (S m) => (* SubGoal 1*)                          \n    | S n0 => fun e0 : eq nat (S n0) (S m) => (* SubGoal 2*)                  \n    end e)                                                  \n\\end{minted}\n\\end{minipage}\n\\end{center}\nAfter building the {\\it return type}, we can build the branches by applying {\\it type of branch}.\n\n\\subsection{\\it exact}\n\nThis tactic checks if the input term is actually of the goal's type. If so, the proof of the current goal is finished and the \nconstructed proof object is exactly the input term.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it exact}\\ \\tt t.$ : $\\tt t$ is a term of the goal's type. \n\\end{itemize}\n\n\\subsubsection*{Implementation}\nIt's easy to implement. Here is an example:\n\\begin{center}\n\\begin{minipage}{0.8\\textwidth}\n\\begin{minted}{coq}\nm : nat                                                      \n(* Current Goal *)  (* exact (eq_refl nat m) => *)  (* No More Goals *)\neq nat m m                                       \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it exists}\n\nThis tactic handles the exists qualifier. In our system, $\\tt\\exists (x:T),P\\ x$ is represented by $\\tt ex\\ T\\ P$.\n\nHere is the definition of $\\tt ex$.\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nInductive ex (A:Type) (P:A -> Type) : Type :=\n| ex_intro : forall (x:A), P x -> ex A P.    \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nThe proof of $\\tt\\exists (x:T), P\\ x$ needs the user to provide a value $\\tt x$\nand prove that it satisfies the predicate $\\tt P$.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it exists}\\ \\tt t.$ : If the goal is $\\tt ex\\ (x:T),P\\ t$, and $\\tt t$ is a term of type $\\tt T$. \n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThe tactic automatically generates the subgoal $\\tt P\\ x$.\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\n(* Current Goal *)                                                           \nex nat (fun (n:nat) => eq nat (S (S O)) (plus n n))\n\n(* $\\Downarrow$ exists S O $\\Downarrow$ *)\n\n(* SubGoal *)\neq nat (S (S O)) (plus (S O) (S O))\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nThe proof object built is\n\\begin{center}\n\\begin{minipage}{0.8\\textwidth}\n\\begin{minted}{coq}\nex_intro nat (fun (n:nat) => \n                eq nat (S (S O)) (plus n n)) (S O) (* SubGoal *)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it induction}\n\nThis tactic applies to any goal. \nThe argument term must be of inductive type and the tactic {\\it induction} generates subgoals, \none for each possible form of term, i.e., one for each constructor of the inductive type.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it induction}\\ \\tt t.$ : $\\tt t$ is a term of some inductive type.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\n\nThe tactic generates the predicate by the goal and automatically generates \nthe subgoals for every constructor of the inductive type.\nThe equivalence relations introduced by the constructors are also handled.\n\nIf the term is a hypothesis, {\\it induction} will find the dependencies, \nand try to move them and replace the subterms to solve the dependencies.\nAnd then erase the original hypothesis.\n\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\n                                                                   \nn : nat                                                            \n(* Current Goal *)   \neq nat (plus n O) n                       \n\n(* $\\Downarrow$ induction n $\\Downarrow$ *)\n\n(* SubGoal 1 *)    \neq nat (plus O O) O\n\nn0 : nat                     \ne : eq nat (plus n0 O) n0    \n(* SubGoal 2 *)              \neq nat (plus (S n0) O) (S n0)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nAfter {\\it induction}, all we need to prove is the property holds for \\mintinline{coq}|O| and \nfor any \\mintinline{coq}|n|, if \\mintinline{coq}|P n| holds,\nthen the two subgoals are generated and \\mintinline{coq}|n| is replaced by the constructors.\n\nThe case above is viewed from user's perspective.\nOn the other hand, in the system we also need to construct the term for back substitution.\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\nn : nat                               \n(* Current Goal*)                              \neq nat (plus n O) n                             \n\n(* $\\Downarrow$ induction n $\\Downarrow$ *)   \n\n(* The Proof Object *)\n(fun (n:nat) =>   \n    nat_rect \n    (fun (n0:nat) => eq nat (plus n0 O) n0)\n    (* SubGoal 1 *)\n    (fun (n0:nat) (e:eq nat (plus n0 O) n0) => (* SubGoal 2 *))\n    n)                                                      \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it intro}\n\nIf the current goal is a dependent product $\\tt \\forall x:T,\\ U$, \\textit{intro} puts \n$\\tt x:T$ in the context, and the new subgoal is $\\tt U$.\\par\nIf the current goal is a non-dependent product $\\tt \\forall \\_:T,\\ U$, \\textit{intro} renames\n$\\tt \\_$ into $\\tt s$ not in $\\tt T,U$ and context. Then put $\\tt s:T$ in the context, \nand the new subgoal becomes $\\tt U$.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it intro}\\ .$ : introduce the outermost argument of current goal and rename them automatically.\n\\item ${\\it intro}\\ a_1\\ a_2\\ \\cdots\\ a_n.$ : introduce $n$ outermost arguments of current goal and\ntry to rename them into $a_1,a_2,\\cdots,a_n$.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nSince the context automatically preserves the index, we\ncan safely move the arguments out into the context without worrying about the index.\n\nIf the argument is dependent in either the consequent or some hypotheses of the goal,\nthe argument is replaced by the appropriate constructor form in each of the resulting subgoals\nand induction hypotheses are added to the local context.\n\nHere is an example:\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\n                                                        P : Type\n(* Current Goal *)                (* intro P => *)      (* SubGoal *) \nforall (x:Type) (f:False), x                            forall (f:False), P\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it intros}\n\nIf the current goal is a dependent (or non-dependent) product with $m$ arguments, namely,\n$\\tt \\forall x_1:T_1,\\ \\forall x_2:T_2,\\ \\cdots\\ \\forall x_m:T_m,\\ U$ where $\\tt U$ is not a product type.\nThen \\textit{intros} will put these $m$ arguments into the context and rename automatically if necessary.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it intros}.$ : introduce all the argument of current goal and rename them automatically.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nKeep calling {\\it intro} until all the goal has no arguments.\\par\nHere is an example:\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\n                                                       x : Type\n                                                       f : False \n(* Current Goal *)                (* intros => *)      (* SubGoal *) \nforall (x:Type) (f:False), x                           x\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it left right}\nThese tactics apply to a goal that is of the disjunction type. Then we can proof one of the two sides to solve the goal.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n    \\item ${\\it left}.$\n    \\item ${\\it right}.$\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThe disjunction type in our system is defined as follows:\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nInductive or (A:Type) (B:Type) : Type :=\n| or_introl : A -> or A B\n| or_intror : B -> or A B. \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nThe tactic ${\\it left}$ builds the proof object with the \\mintinline{coq}|or_introl| constructor.\nThe tactic ${\\it right}$ builds the proof object with the \\mintinline{coq}|or_intror| constructor.\nHere is an example:\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\n(* Current Goal *)\nor (eq nat O O) (eq nat (S O) (S O))\n\n(* $\\Downarrow$ left $\\Downarrow$ *)\n\n(* The Proof Object *)\nor_introl (eq nat O O) (eq nat (S O) (S O)) (* SubGoal 1 *)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it split}\nThis tactic applies to a goal that is of the conjunction type. Then we need to proof the both sides to solve the goal.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it split}$.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThe conjunction type in our system is defined as follows:\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nInductive and (A:Type) (B:Type) : Type :=\n| conj : A -> B -> and A B.   \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nThe proof object is built with the \\mintinline{coq}|conj| constructor.\nHere is an example:\n\\begin{center}\n\\begin{minipage}{\\textwidth}\n\\begin{minted}{coq}\n(* Current Goal *)\nand (eq nat O O) (eq nat (S O) (S O))\n\n(* $\\Downarrow$ split $\\Downarrow$ *)\n\n(* The Proof Object *)\nconj (eq nat O O) (eq nat (S O) (S O)) (* SubGoal 1 *) (* SubGoal 2 *)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\n\\subsection{\\it reflexivity}\nThis tactic applies to a goal that has the form $\\tt eq\\ T\\ t\\ u$, it check that $\\tt t$ and $\\tt u$ \nare convertible and then solves the goal.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it reflexivity}.$\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThis tactic simply checks if the terms are convertible and build the proof object with \\mintinline{coq}|eq_refl| constructor.\n\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\nn : nat\n(* Current Goal *)  \neq nat n (plus O n)   \n\n(* reflexivity *)\n\n(* The Proof Object *)\nfun (n:nat) => eq_refl nat n\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it rewrite}\nThis tactic applies to any goal.\nThe type of term must have the form $\\tt eq\\ T\\ t\\ u$.\nThen the subterms $\\tt t$ in the goal will be rewritten by $\\tt u$.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it rewrite\\ \\tt H}.$ : $\\tt H$ should have the form $\\tt eq\\ T\\ t\\ u$, \nall the subterms $\\tt t$ in the goal will be replaced by $\\tt u$.\n\\item ${\\it rewrite\\ \\texttt{<-}\\ \\tt H}.$ : $\\tt H$ should have the form $\\tt eq\\ T\\ t\\ u$, \n    all the subterms $\\tt u$ in the goal will be replaced by $\\tt t$.\n\\item ${\\it rewrite\\ [\\texttt{<-}/\\texttt{->}]\\ \\tt H\\ \\it in\\ \\tt H1}.$ : \n    $\\tt H$ should have the form $\\tt eq\\ T\\ t\\ u$, for the {\\tt ->} case, all the \n    subterms $\\tt t$ in $\\tt H1$ will be replaced by $\\tt u$.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThis tactic builds the proof object with \\mintinline{coq}|eq_rect| or \\mintinline{coq}|eq_rect_r|.\n\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\n\\begin{minted}{coq}\na : nat                                        a : nat        \nb : nat                                        b : nat        \ne : eq nat a b                                 e : eq nat a b\n(* Current Goal *)     (* rewrite e => *)      (* SubGoal *)\neq nat b a                                     eq nat b b\n\n(* Proof Object *)\nfun (a:nat) (b:nat) (e:eq nat a b) =>\n  (fun (e0:eq nat b b) =>\n    eq_rect_r nat b (fun (n:nat) (e1:eq nat b n) =>\n      eq nat b n) e0 a e) (* SubGoal *)\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\subsection{\\it simpl}\nThis tactic applies to any goal, it tries to reduce a term to something still readable instead of fully normalizing it. \nIt performs a sort of strong normalization with a key difference:\n\\begin{center}\n\\begin{minipage}{0.7\\textwidth}\nit unfold a constant if and only if it leads to a $\\iota$-reduction, i.e., reducing a {\\tt match} or unfolding a {\\tt Fix}.\n\\end{minipage}\n\\end{center}\n\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it simpl}.$\n\\item ${\\it simpl\\ in}\\ \\tt H.$ : $\\tt H$ is a hypothesis.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\n\nThe tactic first applies $\\beta\\iota$-reduction, then it expands constants and tries to reduce \nfurther using $\\beta\\iota$-reduction, but when no $\\iota$ rule is applied after unfolding,\n$\\iota$-reductions are not applied. For instance, trying to use $\\it simpl$ on \n\\mintinline{coq}|eq nat (plus n O) n| changes nothing.\n\\begin{center}\n\\begin{minipage}{0.8\\textwidth}\n\\begin{minted}{coq}\nn : nat                                          e : nat\n(* Current Goal *)           (* simpl => *)      (* Current Goal *)\neq nat (plus n O) (plus O n)                     eq nat (plus n O) n\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\nThe tactic can also be applied to the hypotheses, and the same reduction rules applies.\n\\begin{center}\n\\begin{minted}{coq}\nn : nat                                                    n : nat                \ne : eq nat (plus n O) (plus O n)                           e : eq nat (plus n O) n\n(* Current Goal *)                 (* simpl in e => *)     (* Current Goal *)      \neq nat (plus n O) n                                        eq nat (plus n O) n         \n\\end{minted} \n\\end{center}\n\nThe tactic would never change the current built proof object and won't modify the proof objects built after it.\nIt is transparent in the proof tree.\n\n\\subsection{\\it exact}\n\nThis tactic checks if the input term is actually of the goal's type. If so, the proof of the current goal is finished and the \nconstructed proof object is exactly the input term.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it exact}\\ \\tt t.$ : $\\tt t$ is a term of the goal's type. \n\\end{itemize}\n\n\\subsubsection*{Implementation}\nIt's easy to implement. Here is an example:\n\\begin{center}\n\\begin{minipage}{0.8\\textwidth}\n\\begin{minted}{coq}\nm : nat                                                      \n(* Current Goal *)  (* exact eq_refl nat m => *)  (* No more goals *)\neq nat m m                                       \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\n\\subsection{\\it symmetry}\nThis tactic applies to a goal that has the form $\\tt eq\\ T\\ t\\ u$ \nand changes it into $\\tt eq\\ T\\ u\\ t$.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it symmetry}$.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nThis tactic builds the proof object use the pre-defined theorem \\mintinline{coq}|eq_sym|, here is an example for the proof object building.\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nm : nat\nn : nat\ne : eq nat m n                    \n(* Current Goal*)                              \neq nat n m                           \n\n(* $\\Downarrow$ symmetry $\\Downarrow$ *)   \n\n(* The proof object *)\nfun (m:nat) (n:nat) (e:eq nat m n) =>   \n    eq_sym nat m n (* SubGoal *)                                                \n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\n\\subsection{\\it unfold}\nThis tactic applies to any goal, the argument should denote a defined constant (i.e., not a hypothesis or a axiom).\nThe tactic applies the $\\delta$ rule to each occurrence of the constant in the current goal and then replaces it with its $\\beta\\iota$-normal form.\n\n\\subsubsection*{Usage}\n\\begin{itemize}\n\\item ${\\it unfold}\\ \\tt i.$ : $\\tt i$ is an identifier. \n\\item ${\\it unfold}\\ \\tt i\\ \\it in\\ \\tt H.$ : $\\tt i$ is an identifier and $\\tt H$ is a hypothesis.\n\\end{itemize}\n\n\\subsubsection*{Implementation}\nIt finds the occurrences of the constant and applies the $\\delta$ rule, the nameless index is automatically preserved.\n\n\n\\begin{center}\n\\begin{minipage}{0.8\\textwidth}\n\\begin{minted}{coq}\nDefinition addTwo (n : nat) : nat := S (S n).\n\nn : nat\nm : nat\ne : eq nat m n\n(* Current Goal *)\neq nat (addTwo n) (S (S m))\n\n(* $\\Downarrow$ unfold addTwo $\\Downarrow$ *)\n\nn : nat\nm : nat\ne : eq nat m n\n(* SubGoal *)\neq nat (S (S n)) (S (S m))\n\n(* $\\Downarrow$ symmetry $\\Downarrow$ *)   \n\n(* The proof object *)\n(fun (n:nat) (m:nat) (e:eq nat m n) => (* SubGoal *))                         \n\\end{minted}\n\\end{minipage}\n\\end{center}\n", "meta": {"hexsha": "4f435803c2b74fe966bd53a013ee811fe7372dbe", "size": 21670, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/tactic.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/tactic.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/tactic.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": 34.672, "max_line_length": 147, "alphanum_fraction": 0.5976926627, "num_tokens": 6057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743168019989179, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.6160408191535937}}
{"text": "\\documentclass{article}\n\n\\usepackage{enumitem}\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage{parskip}\n\\usepackage{graphicx}\n\\usepackage{mathtools}\n\\usepackage{mathrsfs}\n\\usepackage{amsmath,amsthm,hyperref}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\DeclareMathOperator{\\Tr}{tr}\n\\usepackage{bbm}\n\\usepackage{dsfont}\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\\DeclareMathOperator{\\Tr}{Tr}\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' /\n\n% my new commands\n\\newcommand\\partialkj{\\frac{\\partial^2}{\\partial\\theta_k\\partial\\theta_j}}\n\\makeatletter\n\\newcommand*\\bigcdot{\\mathpalette\\bigcdot@{.5}}\n\\newcommand*\\bigcdot@[2]{\\mathbin{\\vcenter{\\hbox{\\scalebox{#2}{$\\m@th#1\\bullet$}}}}}\n\\makeatother\n\\newcommand{\\minus}{\\scalebox{0.5}[1.0]{$-$}}\n\\newcommand{\\zero}{\\scalebox{0.6}[0.75]{$^{(0)}$}}\n\\newcommand{\\supx}[1]{\\scalebox{0.6}[0.75]{$^{(#1)}$}}\n\\newcommand{\\supi}{\\scalebox{0.6}[0.75]{$^{(i)}$}}\n\\newcommand{\\sumim}{\\begin{align*}\n    \\sum_{i=1}^m\n\\end{align*}\n}\n\\newcommand{\\sumzi}{\\begin{align*}\n    \\sum_{z\\supi}\n\\end{align*}\n}\n\n\\newcommand{\\bigDash}{\\scalebox{3.0}[1.0]{$-$}}\n\n\n\n%%%%%%%%%%%%%%%%%\n%     Title     %\n%%%%%%%%%%%%%%%%%\n\\title{Problem Set #4:  Unsupervised Learning and Reinforcement Learning}\n\\author{Eitan Joseph \\and Caroline Wang}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n%%%%%%%%%%%%%%%%%\n%   Problem 1   %\n%%%%%%%%%%%%%%%%%\n\\section*{Problem 1}\n\\textbf{EM for supervised learning}\\\\\nIn class we applied EM to the unsupervised learning setting. In particular, we represented $p(x)$ by marginalizing over a latent random variable \\begin{align*}\n    p(x) = \\sum_{z} p(x,z) = \\sum_{z} p(x|z)p(z)\n\\end{align*}\nHowever, EM can also be applied to the supervised learning setting, and in this problem we discuss a “mixture of linear regressors” model; this is an instance of what is often call the Hierarchical Mixture of Experts model. We want to represent $p(y|x)$, $x\\in \\mathbb{R}^n$ and $y\\in\\mathbb{R}$, and we do so by again introducing a discrete latent random variable\n\\begin{align*}\n    p(y|x) = \\sum_z p(y,z|x) = \\sum_{z} p(y|x,z) p(z|x) \n\\end{align*}\nFor simplicity we’ll assume that z is binary valued, that p(y|x, z) is a Gaussian density, and that $p(y|x)$ is given by a logistic regression model. More formally\n\\begin{align*}\n    p(z|x;\\phi ) =& g(\\phi^Tx)^z(1-g(\\phi^Tx))^{1-z}\\\\\n    p(y|x,z = i; \\theta_i) = &\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(\\frac{-(y-\\theta_i^Tx)^2}{2\\sigma^2}\\right)\\quad i = 0,1\n\\end{align*}where $\\sigma$ is a known parameter and $\\phi, \\theta_0, \\theta_1 \\in \\mathbb{R}$ are parameters of the model (here we use the subscript on $\\theta $ to denote two different parameter vectors, not to index a particular entry in these vectors).\\\\\nIntuitively, the process behind model can be thought of as follows. Given a data point $x$, we first determine whether the data point belongs to one of two hidden classes $z=0$ or $z = 1$, using a logistic regression model. We then determine $y$ as a linear function of $x$ (different linear functions for different values of z) plus Gaussian noise, as in the standard\nlinear regression model. For example, the following data set could be well-represented by the model, but not by standard linear regression.\n\\begin{enumerate}[label=(\\alph*)]\n    \\item Suppose $x$, $y$, and $z$ are all observed, so that we obtain a training set\n${(x\\supx{1}, y\\supx{1}, z\\supx{1}), . . . , (x\\supx{m}, y\\supx{m}, z\\supx{m})}$. Write the log-likelihood of the parameters,\nand derive the maximum likelihood estimates for $\\phi$, $\\theta_0$, and $\\theta_1$. Note that because $p(z|x)$ is a logistic regression model, there will not exist a closed form estimate of $\\phi$. In this case, derive the gradient and the Hessian of the likelihood with respect to $\\phi$; in practice, these quantities can be used to numerically compute the ML estimate.\\\\\\\\\n    \\textit{answer: }\\\\\\\\\n    The log-likelihood can be written as\n    \\begin{align*}\n         \\ell(\\phi,\\theta_0, \\theta_1)  =& \\sumim \\log p(y\\supi|x\\supi;\\phi,\\theta_0, \\theta_1)\\\\\n         = & \\sumim \\log p(y\\supi |x\\supi, z\\supi;\\theta_0, \\theta_1 )p(z\\supi | x\\supi;\\phi)\\\\\n         =& \\sumim \\mathds{1}\\{z\\supi=0\\}\\log \\left((1-g(\\phi^Tx\\supi))\\left(\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(\\frac{-(y\\supi-\\theta_k^Tx\\supi)^2}{2\\sigma^2}\\right)\\right)\\right)\\\\ &+ \\sumim \\mathds{1}\\{z\\supi=1\\}\\log \\left((g(\\phi^Tx\\supi))\\left(\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(\\frac{-(y\\supi-\\theta_1^Tx\\supi)^2}{2\\sigma^2}\\right)\\right)\\right)\n    \\end{align*}\n    The maximum likelihood estimation for $\\theta_k$ can be derived by taking the gradient with respect to $\\theta_k$ and setting the result to zero.\\begin{align*}\n        \\nabla_{\\theta_0}\\ell(\\phi,\\theta_0, \\theta_1) \\overset{\\mathrm{set}}{=}0\n    \\end{align*}\n    Then by extracting the non-relevant constants to $\\theta_k$: \\begin{align*}\n        &{}\\nabla_{\\theta_k}\\sumim-(y-\\theta_k^Tx\\supi)^2 = 0\\\\\n        &{}\\sumim-2(y\\supi-\\theta_k^Tx\\supi)\\cdot x\\supi=0\\\\\n        \\implies&{}\\sumim x\\supi y\\supi= \\sumim \\theta_k^Tx\\supi^Tx\\supi \\\\\n        \\implies&{}X^T\\Vec{y} = \\theta_k^T X^TX\\\\\n        \\implies&{}\\theta_k = (X^TX)^{-1}X^T\\Vec{y}\n    \\end{align*}Therefore the specific estimations for $\\theta_0$ and $\\theta_1$ are: \\begin{align*}\n        \\theta_0 = (X_0^TX_0)^{-1}X_0^T\\Vec{y_0}\\\\\n        \\theta_1 = (X_1^TX_1)^{-1}X_1^T\\Vec{y_1}\n    \\end{align*}\n    Where $X_0$, $y_0$, $X_1$, $y_1$ are the associated matrices and vectors derived in each of the two separate summations that combine to equal all of $z$.\\\\\n    \n    The next step is to find the gradient vector and the Hessian matrix respect with respect to $\\phi$.\\\\\n    We can once again remove the terms not relating to $\\phi$:\\begin{align*}\n        \\nabla_{\\phi } \\ell(\\phi,\\theta_0, \\theta_1)=& \\nabla_{\\phi}\\sumim \\mathds{1}\\{z\\supi=0\\}\\log (1-g(\\phi^Tx\\supi))+ \\sumim \\mathds{1}\\{z\\supi=1\\}\\log((g(\\phi^Tx\\supi))\\\\\n        =& \\nabla_{\\phi} \\sumim (1-z\\supi) \\log (1-g(\\phi^Tx\\supi))+ z\\supi \\log((g(\\phi^Tx\\supi))\n    \\end{align*}\n    From previous classes, the derivative of a sigmoid is known to be $\\frac{\\partial}{\\partial z}g(z) = g(z)(1-g(z))$, therefore \\begin{align*}\n        \\nabla_{\\phi }\\ell(\\phi,\\theta_0, \\theta_1) = &\\sumim - \\frac{1-z\\supi}{(1-g(\\phi^Tx\\supi))}\\frac{\\partial}{\\partial \\phi}g(\\phi^Tx\\supi)\\cdot x\\supi + \\frac{z\\supi}{g(\\phi^Tx\\supi)}\\frac{\\partial}{\\partial \\phi}g(\\phi^Tx\\supi)\\cdot x\\supi\\\\\n        =& \\sumim - \\frac{1-z\\supi}{(1-g(\\phi^Tx\\supi))}g(\\phi^Tx\\supi)(1-g(\\phi^Tx\\supi))\\cdot x\\supi + \\frac{z\\supi}{g(\\phi^Tx\\supi)}g(\\phi^Tx\\supi)(1-g(\\phi^Tx\\supi))\\cdot x\\supi\\\\\n        =& \\sumim -(1-z\\supi)g(\\phi^Tx\\supi) \\cdot x\\supi + z\\supi(1-g(\\phi^Tx\\supi))\\cdot x\\supi\\\\\n        =& \\sumim x\\supi (z\\supi -g(\\phi^Tx\\supi))\n    \\end{align*}\n    Finally, this tells us that the gradient is\\begin{align*}\n        \\nabla_{\\phi }\\ell(\\phi,\\theta_0, \\theta_1) = X^T(\\Vec{z}-\\Vec{g})\\quad \\text{where} \\quad \\Vec{g}_i = g(\\phi^Tx\\supi)\n    \\end{align*}\n    Based on the linear algebra review sheet, the Hessian Matrix can be derived by taking the derivative of the gradient, which is equivalent to looking at each $i$th entry of the gradient vector, taking the gradient of that entry, and setting that to be the $i$th column of the Hessian. The $i$th entry of the gradient vector is \\begin{align*}\n        x\\supi^T \\cdot (\\Vec{z} -\\Vec{g})\n    \\end{align*}and after taking the derivative with respect to that $i$th entry we get \\begin{align*}\n        \\nabla_{\\phi} x\\supi^T (\\Vec{z} -\\Vec{g}) = x\\supi^T  (\\Vec{g}\\cdot (1-\\Vec{g}))\\cdot x\\supi \n    \\end{align*}Which gives the matrix \\begin{align*}\n        H = X^TDX\\quad \\text{where} \\quad D_{ii} = g(\\phi^Tx\\supi)(1-g(\\phi^Tx\\supi))\n    \\end{align*}\n    \\item Now suppose $z$ is a latent (unobserved) random variable. Write the log-likelihood of the parameters, and derive an EM algorithm to maximize the log-likelihood. Clearly specify the E-step and M-step (again, the M-step will require a numerical solution, so find the appropriate gradients and Hessians). \\\\\\\\\n     \\textit{answer: }\\\\\\\\\n     The log-likelihood can now be written as\n     \\begin{align*}\n         \\ell(\\phi,\\theta_0, \\theta_1) \n         &{}= \\sumim\\log p(y\\supi|x\\supi;\\phi,\\theta_0, \\theta_1)\\\\\n         &{}= \\sumim\\log p(y\\supi|x\\supi,z\\supi;\\theta_0, \\theta_1) p(z\\supi|x\\supi;\\phi)\\\\\n         &{}= \\sumim\\log \\left(\\left(1-g(\\phi^Tx\\supi)\\right)^{1-z\\supi}\\left(\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(\\frac{-(y\\supi-\\theta_k^Tx\\supi)^2}{2\\sigma^2}\\right)\\right)\\right) \\\\&+ \\log \\left(\\left(g(\\phi^Tx\\supi)^{z\\supi}\\right)\\left(\\frac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(\\frac{-(y\\supi-\\theta_1^Tx\\supi)^2}{2\\sigma^2}\\right)\\right)\\right)\n     \\end{align*}\n     Since each $z\\supi$ is unobserved they cannot be separated explicitly into two cases - this is because we have no way of knowing how to separate the summation into two groups for each cluster of $z\\supi$ values when their values are hidden.\\\\\n     \n     In order to derive the new EM algorithm, instead of explicitly maximizing $\\ell$ we will use the same approach as explained in class which will be to repeatedly construct a lower-bound on $\\ell$ (E-step), and then optimize that lower-bound (M-step). \\\\\n     \n     In order to accomplish this, we first define $Q_i$ to be the distribution over $z_i$ for all $i$ (implying $\\sum_z Q_i(z) = 1$ and $Q_i(z) \\geq 0$). Next we write the following:\n     \\begin{align}\n         \\sumim\\log p(y\\supi|x\\supi;\\phi,\\theta_0, \\theta_1)&{}=\n         \\sumim \\log\\sum_{z\\supi} Q_i(z\\supi)\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\\\\\n         &{}\\geq\\sumim\\sum_{z\\supi} Q_i(z\\supi)\\log\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\n     \\end{align}\n     Where step (2) utilizes Jensen's Inequality.\\\\\\\\\n     We note here that the term\n     \\begin{align*}\n         \\sum_{z\\supi} Q_i(z\\supi)\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\n     \\end{align*}\n     is just the expectation over the quantity \n     \\begin{align*}\n        \\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\n     \\end{align*}\n     according to the distribution $Q_i$. By Jensen's Inequality we know that\n     \\begin{align*}\n         f\\left(\\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\\right]\\right) \\geq \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[f\\left(\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{Q_i(z\\supi)}\\right)\\right]\n     \\end{align*}\n     Since (2) holds true for any set of distributions $Q_i$ we can choose a specific distribution for $Q_i$ which makes the inequality hold with equality at $\\phi$, $\\theta_0$, $\\theta_1$. Since Jensen's Inequality holds with equality over a constant valued random variable it suffices to find $Q_i(z\\supi) = c \\times p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi) $ for some $c \\in \\mathbb{R}, c \\neq 0$. We can solve for $Q_i(z\\supi)$ using many iterations of Bayes' Theorem as follows:\n     \\begin{align*}\n         Q_i(z\\supi) &{}=\n         \\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{\\sum_{z\\supi}p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}\\\\\n         &{}=\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi|x\\supi;\\phi)}{p(y\\supi|x\\supi;\\theta_0, \\theta_1)}\\\\\n         &{}=\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_0, \\theta_1)p(z\\supi, x\\supi;\\phi)}{p(y\\supi|x\\supi;\\theta_0, \\theta_1)p(x\\supi;\\phi)}\\\\\n         &{}=\\frac{p(y\\supi, x\\supi, z\\supi;\\phi, \\theta_0, \\theta_1)}{p(y\\supi, x\\supi;\\phi, \\theta_0, \\theta_1)}\\\\\n         &{}= p(z\\supi|x\\supi, y\\supi;\\phi, \\theta_0, \\theta_1)\n     \\end{align*}\n     With this solved we can now write the following EM algorithm\n     \\begin{align*}\n         \\text{(E-step) For each i, j set}\\\\\n         &{}w_j^{(i)} := p(z\\supi = j | x\\supi, y\\supi;\\phi,\\theta_j)\\\\\n         \\text{(M-step) Update the parameters of}\\\\\n         &{}\\sumim\\sum_j w_j^{(i)}\\log\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_j)p(z\\supi|x\\supi;\\phi)}{w_j^{(i)}}\n     \\end{align*}\n     In order to maximize the equation in the M-step with respect to the parameters $\\phi$, $\\theta_0$, $\\theta_1$ we need to take the gradient with respect to each parameter and set the resulting expression to zero. We can first generalize the $\\theta$s as one gradient and solve\n     \\begin{align*}\n         \\nabla_{\\theta_k}\\sumim\\sum_j w_j^{(i)}\\log\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_j)p(z\\supi|x\\supi;\\phi)}{w_j^{(i)}} \\overset{set}= 0\n     \\end{align*}\n     After dividing out all the non variable multipliers and taking the gradient we are left with the equation\n     \\begin{align*}\n         &{}\\sumim-2(y\\supi-\\theta_k^Tx\\supi)x\\supi^T w_k^{(i)} = 0\\\\\n         \\implies&{}\\sumim x\\supi^T w_k^{(i)}y\\supi - x\\supi^T w_k^{(i)}\\theta_k^Tx\\supi = 0\\\\\n         \\implies&{}\\sumim x\\supi^T w_k^{(i)}\\theta_k^Tx\\supi = \\sumim x\\supi^T w_k^{(i)}y\\supi\\\\\n         \\implies&{}\\sumim x\\supi^T w_k^{(i)}\\theta_k^Tx\\supi = \\sumim x\\supi^T w_k^{(i)}y\\supi\\\\\n        \\implies&{}\\theta_k^T\\sumim x\\supi^T w_k^{(i)}x\\supi = \\sumim x\\supi^T w_k^{(i)}y\\supi\\\\\n        \\implies&{}\\theta_k^T =  \\sumim (x\\supi^T w_k^{(i)}x\\supi)^{-1}x\\supi^T w_k^{(i)}y\\supi\\\\\n        \\implies&{}\\theta_k = (X^T W X)^{-1}X^TWy \\quad \\text{where} \\quad W_{i,i} = w_k^{(i)}\\\\\n    \\end{align*}\n     Finally we must derive the gradient vector and Hessian matrix \\begin{align*}\n         &\\nabla_{\\phi } \\sumim\\sum_j w_j^{(i)}\\log\\frac{p(y\\supi|x\\supi, z\\supi;\\theta_j)p(z\\supi|x\\supi;\\phi)}{w_j^{(i)}}\\\\\n         =&\\nabla_{\\phi }\\sumim w_0^{(i)}\\log (1-g(\\phi^Tx\\supi))+ w_1^{(i)} \\log((g(\\phi^Tx\\supi))\n     \\end{align*}\n     Since $w_0^{(i)}=1-w_1^{(i)}$ we have\\begin{align*}\n         &\\nabla_{\\phi }\\sumim (1-w_1^{(i)})\\log (1-g(\\phi^Tx\\supi))+ w_1^{(i)} \\log((g(\\phi^Tx\\supi))\\\\\n         =&\\sum_ix\\supi (w_1^{(i)} -g(\\phi^Tx\\supi))\n     \\end{align*}The matrix representation turns out to be \\begin{align*}\n         \\nabla_{\\phi } = X^T (\\Vec{w}-\\Vec{g})\\quad \\text{where} \\quad\\Vec{g}_i = g(\\phi^Tx\\supi)\n     \\end{align*}\n    Finding the Hessian for $\\phi$ in part (b), yields the same result as part (a) \\begin{align*}\n         H = X^TDX\\quad \\text{where}\\quad D_{i,i} = g(\\phi^Tx\\supi)(1-g(\\phi^Tx\\supi))\n     \\end{align*}\n\\end{enumerate}\n\\section*{Problem 2}\n\\textbf{Factor Analysis and PCA}\\\\\nIn this problem we look at the relationship between two unsupervised learning algorithms we discussed in class: Factor Analysis and Principle Component Analysis.\\\\\nConsider the following joint distribution over (x, z) where $z\\in \\mathbb{R}^k$ is a latent random variable\\begin{align*}\n    z\\quad &\\sim \\quad \\mathscr{N}(0,I)\\\\\n    x|z\\quad &\\sim \\quad \\mathscr{N}(Uz,\\sigma^2I)\n\\end{align*}\nwhere $U\\in \\mathbb{R}^k$ is a model parameters and $\\sigma^2$ is assumed to be a known constant. This model is often called Probabilistic PCA. Note that this is nearly identical to the factor analysis model except we assume that the variance of $x|z$ is a known scaled identity matrix rather than the diagonal parameter matrix $\\Phi$\b, and we do not add an additional $\\mu$ term to\nthe mean (though this last difference is just for simplicity of presentation). However, as we will see, it turns out that as $\\sigma^2 \\xrightarrow[]{}0$, this model is equivalent to PCA.\\\\\nFor simplicity, you can assume for the remainder of the problem that $k = 1$, i.e., that $U$ is a column vector in $\\mathbb{R}^n$.\n\\begin{enumerate}[label=(\\alph*)]\n\\item Use the rules for manipulating Gaussian distributions to determine the joint distribution over $(x, z)$ and the conditional distribution of $z|x$. [Hint: for later parts of\nthis problem, it will help significantly if you simplify your solution for the conditional distribution using the identity we first mentioned in problem set #1: $(\\lamba I+BA)^{-1}B =\nB(\\lambada I + AB)^{-1}.]$\\\\\\\\\n    \\textit{answer:}\\\\\\\\\n    According to the definition of $x$, the expectation of $x$ is \\begin{align*}\n        E[x] = E[Uz+\\epsilon] = UE[z] + E[\\epsilon] = 0\n    \\end{align*} \n    where $\\epsilon \\sim \\mathscr{N}(0,\\sigma^2I)$ indicates the added covariance noise.\n    We can now obtain the four different components of the matrix $\\Sigma$ using the substitution $x=Uz+\\epsilon$\\begin{align*}\n        \\Sigma_{zz} =& E[zz^T] = I\\\\\n        \\Sigma_{xz} =& E[(Uz+\\epsilon)z^T] = (UE[zz^T] + E[\\epsilon z^T]) = U\\\\\n        \\Sigma_{zx} =& E[z(Uz+\\epsilon)^T] = U^TE[zz^T] + E[z\\epsilon^T] = U^T\\\\\n        \\Sigma_{xx} =& E[(Uz+\\epsilon)(Uz+\\epsilon)^T] = UU^TE[zz^T]+UE[z\\epsilon^T] + U^TE[\\epsilon z^T]+E[\\epsilon\\epsilon^T] = UU^T +\\sigma^2I\n    \\end{align*}\n    Therefore our join distribution is written\n    \\begin{align*}\n        \\begin{bmatrix}z \\\\ x\\end{bmatrix}\\quad \\sim \\quad  \\mathscr{N}\\left(\\begin{bmatrix}0 \\\\ 0\\end{bmatrix}, \\begin{bmatrix}I & U^T \\\\ U & UU^T+\\sigma^2I\\end{bmatrix}\\right)\n    \\end{align*} Then we can apply the formula to define the conditional distribution $z|x \\sim \\mathscr{N}(\\mu_{z|x}, \\Sigma_{z|x})$ such that \\begin{align*}\n        \\mu_{z|x} =& \\mu_z+\\Sigma_{zx}\\Sigma_{xx}^{-1}x = U^T(UU^T+\\sigma^2I)^{-1}x = \\frac{U^Tx}{UU^T+\\sigma^2}\\\\\n        \\Sigma_{z|x} =& \\Sigma_{zz}-\\Sigma_{zx}\\Sigma_{xx}^{-1}\\Sigma_{xz} = I-U^T(UU^T+\\sigma^2I)^{-1}U = 1-\\frac{U^TU}{UU^T+\\sigma^2}\n    \\end{align*}\n    In conclusion, \\begin{align*}\n        z|x \\quad \\sim \\quad \\mathscr{N}\\left(\\frac{U^Tx}{UU^T+\\sigma^2}, 1-\\frac{U^TU}{UU^T+\\sigma^2}\\right)\n    \\end{align*}\n\\item Using these distributions, derive an EM algorithm for the model. Clearly state the E-step and the M-step of the algorithm.\\\\\\\\\n    \\textit{answer:}\\\\\\\\\n    For the E-step, we need to compute $Q_i(z\\supi)$ where \n    \\begin{align*}\n        Q_i(z\\supi) = p(z\\supi |x\\supi ;U) \n    \\end{align*}\n   For the M-step we need to maximize the equation \\begin{align*}\n        &\\sumim \\int_{z\\supi}Q_i(z\\supi)\\log\\frac{p(x\\supi,z\\supi: U)}{Q_i(z\\supi)}\\\\\n        =&\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\log p(x\\supi |z\\supi; U)+\\log p(z\\supi ) -\\log(Q_i(z\\supi))\\right]\n    \\end{align*}Then we take the gradient with respect to $U$ and set it to $0$ in order to maximize the equation above.\n    \\begin{align*}\n        &\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[\\log p(x\\supi |z\\supi; U)]\\\\\n        =&\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\log\\frac{1}{\\sqrt{2\\pi^n}|\\sigma^2I|}\\exp \\left(-\\frac{1}{2\\sigma^2}(x\\supi -Uz\\supi)^T(x\\supi-Uz\\supi)\\right)\\right]\\\\\n        =&\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\frac{1}{2}\\log|\\sigma^2I|-\\frac{n}{2}\\log(2\\pi)-\\frac{1}{2\\sigma^2}(x\\supi -Uz\\supi)^T(x\\supi-Uz\\supi)\\right]\n    \\end{align*}We can drop the terms not dependent on $U$ before taking the gradient. \\begin{align*}\n        &\\nabla_U\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\frac{1}{2\\sigma^2}(x\\supi -Uz\\supi)^T(x\\supi-Uz\\supi)\\right]\\\\\n        =&-\\frac{1}{2\\sigma^2}\\sumim \\nabla_U\\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[\\Tr  z\\supi^TU^TUz\\supi-2\\Tr z\\supi^TUx\\supi\\right]\\\\\n        =&-\\frac{1}{2\\sigma^2}\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[2z\\supi z\\supi^TU^T-2z\\supi^Tx\\supi\\right]\\\\\n        =&-\\frac{1}{\\sigma^2}\\sumim \\left[U\\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi z\\supi^T]-x\\supi\\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi^T]\\right]\\overset{\\mathrm{set}}{=}0\\\\\n        \\implies &U = \\left(\\sumim x\\supi \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi^T]\\right)\\left(\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi z\\supi^T]\\right)^{-1}\n    \\end{align*}From the definition of $Q_i$ being Gaussian we know that \\begin{align*}\n    \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi^T] =& \\mu_{z\\supi|x\\supi}^T\\\\\n    \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}[z\\supi z\\supi^T] =& \\mu_{z\\supi|x\\supi}\\mu_{z\\supi|x\\supi}^T\n    \\end{align*}Therefore, the final update of the M-step is \\begin{align*}\n        U=\\left(\\sumim \\:x\\supi\\mu_{z\\supi|x\\supi}^T\\right)\\left(\\sumim \\mu_{z\\supi|x\\supi}\\mu_{z\\supi|x\\supi}^T\\right)^{-1}\n    \\end{align*}\n\\item As $\\sigma^2 \\xrightarrow[]{}0$, show that if the EM algorithm convergences to a parameter vector $U^*$ (and such convergence is guaranteed by the argument presented in class), then $U^*$ must be an eigenvector of the sample covariance matrix $\\Sigma = \\frac{1}{m}\\sum x\\supi x\\supi^T$\n— i.e., $U^*$ must satisfy\n\\begin{align*}\n    \\lambda U^* = \\Sigma U^*\n\\end{align*}\n    \\textit{answer:}\\\\\\\\\n    The first thing to notice is that as $\\sigma^2 \\xrightarrow[]{}0$ the E-step only needs to compute the means and not the variances, since $\\Sigma_{z|x}\\xrightarrow[]{}0$ as well. If we let $w \\in \\mathbb{R}^m$ be the vector that contains all the means such that $w_i = \\mu_{z\\supi|x\\supi}$ then we can compute the new E-step to be\n    \\begin{align}\n        w_i = \\mu_{z\\supi|x\\supi} =&{} U^T(\\sigma^2 I - UU^T)^{-1}(Uz\\supi + \\epsilon)\\\\\n        =&{} U^T (UU^T)^{-1}x\\supi\\\\\n        =&{} \\frac{U^Tx\\supi}{UU^T}\\\\\n        =&{} \\frac{x\\supi^TU}{U^TU}\n    \\end{align}\n    Where step (6) uses the fact that step (5) yields a Real. When this is written in matrix form we see that\n    \\begin{align*}\n        w = \\frac{XU}{U^TU}\n    \\end{align*}\n    Next we need to derive the new M-step. We can use the result from (b) in order to obtain the new update rule\n    \\begin{align}\n        U &{}= \\left(\\sumim \\:x\\supi\\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[z\\supi^T\\right]\\right)\\left(\\sumim \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[z\\supi z\\supi^T\\right]\\right)^{-1}\\\\\n        &{}= \\left(\\sumim \\:x\\supi\\mu_{z\\supi|x\\supi}^T\\right)\\left(\\sumim \\mu_{z\\supi|x\\supi}\\mu_{z\\supi|x\\supi}^T\\right)^{-1}\\\\\n        &{}= \\left(\\sumim \\:x\\supi w_i\\right)\\left(\\sumim w_i w_i\\right)^{-1}\n    \\end{align}\n    Where step (8) is derived from the definition of $Q_i$ being Guassian with mean $\\mu_{z\\supi|x\\supi}$ and variance $\\Sigma_{z\\supi|x\\supi}$ yielding\n    \\begin{align*}\n        \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[z\\supi^T\\right] &{}= \\mu_{z\\supi|x\\supi}^T\\\\\n        \\mathop{\\mathbb{E}}_{z\\supi \\mathtt{\\sim} Q_i}\\left[z\\supi z\\supi^T\\right] &{}= \\mu_{z\\supi|x\\supi}\\mu_{z\\supi|x\\supi}^T + \\Sigma_{z\\supi|x\\supi}\n    \\end{align*}\n    Now to write expression (9) in matrix form we see that\n    \\begin{align*}\n        \\left(\\sumim w_i w_i\\right)^{-1} &{}= \\frac{1}{w^Tw}\n    \\end{align*}\n    however to write the numerator in matrix form will be a little more difficult. We want to represent that each column of $X$ from $i\\in{1,...,m}$ gets multiplied by its the $i$th entry of $w$ and then summed together. We cannot simply write this as $X^Tw$ so we will instead have to construct a new diagonal matrix $W$ where $W_{i,i} = w_i$. Then, by multiplying $XW$ we get\n    \\begin{align*}\n        XW &{}=\n        \\begin{bmatrix}\n        | & | & &|\\\\\n        x\\supx{1} & x\\supx{2} & \\dots & x\\supx{m}\\\\\n        | & | & &|\n        \\end{bmatrix}_{n\\times m}\n        \\begin{bmatrix}\n        w_1 & & &\\\\\n        & w_2 & &\\\\\n        & & \\ddots &\\\\\n        & & & w_m\n        \\end{bmatrix}_{m\\times m}\\\\\n        &{}= \\begin{bmatrix}\n        | & | & &|\\\\\n        w_1x\\supx{1} & w_2x\\supx{2} & \\dots & w_mx\\supx{m}\\\\\n        | & | & &|\n        \\end{bmatrix}_{n\\times m}\n    \\end{align*}\n    Next we just need to sum up each column of $XW$ which we can accomplish by constructing new vector $\\Vec{1}\\in \\mathbb{R}^m$ such that $\\Vec{1}_i = 1$ for all $i\\in{1,...,m}$ and transforming it according to $XW$ as follows\n    \\begin{align*}\n    XW\\Vec{1} &{}= \\begin{bmatrix}\n        | & | & &|\\\\\n        w_1x\\supx{1} & w_2x\\supx{2} & \\dots & w_mx\\supx{m}\\\\\n        | & | & &|\n        \\end{bmatrix}_{n\\times m}\n    \\begin{bmatrix}\n        1\\\\\n        \\vdots\\\\\n        1\n    \\end{bmatrix}_{m\\times1}\\\\\n    &{}= \\left(\\sumim \\:x\\supi w_i\\right)\n    \\end{align*}\n    Finally we can write the expression for U in matrix form\n    \\begin{align*}\n        U = \\frac{XW\\Vec{1}}{w^T w}\n    \\end{align*}\n    We know that $U$ has converged when its value has not changed after the E-step, so we can substitute our value for $w$ in the E-step and set it equal to our original U.\n    \\begin{align*}\n        &{}U = \\frac{XW\\Vec{1}}{\\frac{U^TX^T XU }{(U^TU)^2}}\\\\\n        \\implies&{}(U^TX^T XU)U = (U^TU)^2 XW\\Vec{1}\\\\\n        \\implies&{}X^TXU = U^TU XW\\Vec{1}\\\\\n        \\implies&{}X^TXU = UU^T XW\\Vec{1} = U^T XW\\Vec{1}U\\\\\n        \\implies&{}\\Sigma U = \\lambda U\n    \\end{align*}\n    where we know that $\\Sigma = X^TX$ and we take $\\lambda = U^T XW\\Vec{1} \\in \\mathbb{R}$ and therefore proving the desired result.\n\\end{enumerate}\n\\section*{Problem 4}\n    \\textbf{Convergence of Policy Iteration}\\\\\n    In this problem we show that the Policy Iteration algorithm, described in the lecture notes, is guaranteed to find the optimal policy for an MDP. First, define $B^\\pi$ to be the Bellman operator for policy $\\pi$, defined as follows: if $V^\\prime = B(V)$, then\\begin{align*}\n        V^\\prime (s) = R(s)+\\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V(s^\\prime)\n    \\end{align*}\n\\begin{enumerate}[label=(\\alph*)]\n\\item Prove that if $V_1(s) \\leq  V_2(s$) for all $s\\in \\mathcal{S}$, then $B(V_1)(s) \\leq  B(V_2)(s)$ for all $s\\in \\mathcal{S}$.\\\\\\\\\n\\textit{answer:}\\\\\\\\\nGiven that $V_1(s) \\leq  V_2(s$) for all $s\\in \\mathcal{S}$, we can also write the inequality\n\\begin{align*}\n    &R(s) + V_1(s^\\prime) \\leq R(s) + V_2(s^\\prime)\\\\\n    \\implies& R(s) + \\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V_1(s^\\prime) \\leq R(s) + \\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V_2(s^\\prime)\n\\end{align*}\nHowever, it turns out that\n\\begin{align*}\n    &R(s) + \\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V_1(s^\\prime) = B(V_1)(s)\\\\\n    &R(s) + \\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V_2(s^\\prime) = B(V_2)(s)\n\\end{align*}\nSo we have shown that $B(V_1)(s) \\leq B(V_2)(s)$ for all $s \\in \\mathcal{S}$\n\\item Prove that for any $V$, \\begin{align*}\n    ||B^\\pi(V)-V^\\pi ||_\\infty\\leq \\gamma ||V-V^\\pi ||_\\infty\n\\end{align*}where $||V||_\\infty = \\max_{s\\in \\mathcal{S}}|V(s)|$. Intuitively, this means that applying the Bellman operator $B^\\pi $ to any value function $V$, brings that value function “closer” to the value function for $\\pi, V^\\pi $. This also means that applying $B^\\pi $ repeatedly (an infinite number of times):\\begin{align*}\n    B^\\pi(B^\\pi (B^\\pi\\dots B^\\pi(V)\\dots ))) \n\\end{align*}will result in the value function $V^\\pi$.\\\\\\\\\n\\textit{answer:}\\\\\\\\\nWe can first observe that \n\\begin{align*}\n    ||B^\\pi(V)-V^\\pi ||_\\infty &= \\max_{s\\in \\mathcal{S}}\\big |R(s)+\\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V(s^\\prime)-R(S)-\\gamma \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )V^\\pi(s^\\prime)\\big |\\\\\n    &= \\gamma \\max_{s\\in \\mathcal{S}}\\big |\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )(V(s^\\prime)-V^\\pi (s^\\prime))\\big |\n\\end{align*}\nThen since $P_{s,a}$ is a probability distribution it must be true that \\begin{align}\n    P_{s,\\pi(s)}(s^\\prime )\\geq 0\\\\\n    \\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime) = 1\n\\end{align} \nwe can apply the fact that for any $a, x\\in \\mathbb{R}^n$, if $\\sum_i a_i = 1$, and $a_i\\geq 0$, then $\\sum_i a_ix_i\\leq \\max_i x_i$ to (10) and (11) to write\n\\begin{align*}\n    \\gamma \\max_{s\\in \\mathcal{S}}\\big |\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime )(V(s^\\prime)-V^\\pi (s^\\prime))\\big |\\leq \\gamma\\max_{s^\\prime\\in \\mathcal{S}} |V(s^\\prime)-V^\\pi(s^\\prime)|\n\\end{align*}\nWhich is, by definition, the same inequality as\n\\begin{align*}\n     ||B^\\pi(V)-V^\\pi ||_\\infty\\leq \\gamma ||V-V^\\pi ||_\\infty\n\\end{align*}\n\\item Now suppose that we have some policy $\\pi$, and use Policy Iteration to choose a new policy $\\pi\\prime$ according to\n\\begin{align*}\n    \\pi^\\prime(s) = \\argmax_{a\\in A}\\sum_{s^\\prime\\in S}P_{s,a}(s^\\prime)V^\\pi (s^\\prime)\n\\end{align*}\nShow that this policy will never perform worse that the previous one — i.e., show that for all $s \\in \\mathcal{S}$, $V^\\pi(s) \\leq V^{\\pi^\\prime}(s)$.\\\\\\\\\n\\textit{answer:}\\\\\\\\\nWe know that\n\\begin{align*}\n    V^\\pi(s) &{}= R(s) + \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime)V^\\pi(s^\\prime)\\\\\n    &{}\\leq\\\\\n    B^{\\pi^\\prime}(V^\\pi)(s) &{}= R(S)+ \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi^\\prime(s)}(s^\\prime)V^\\pi(s^\\prime)\n\\end{align*}\ndue to the fact that\n\\begin{align*}\n    \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi(s)}(s^\\prime)V^\\pi(s^\\prime) \\leq \\gamma\\max_{a\\in A}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)V^\\pi(s^\\prime) = \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi^\\prime(s)}(s^\\prime)V^\\pi(s^\\prime)\n\\end{align*}\nWe can further expand this to show\n\\begin{align*}\n    B^{\\pi^\\prime}(V^\\pi)(s) &{}= R(S)+ \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi^\\prime(s)}(s^\\prime)V^\\pi(s^\\prime)\\\\\n    &{}= R(S)+ \\gamma\\max_{a\\in \\mathcal{A}}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)V^\\pi(s^\\prime)\\\\\n    &{}= R(S)+ \\gamma\\max_{a\\in \\mathcal{A}}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)(R(s^\\prime) + \\gamma\\sum_{s^{\\prime\\prime} \\in \\mathcal{S}}P_{s^\\prime,\\pi(s^\\prime)}(s^{\\prime\\prime})V^\\pi(s^{\\prime\\prime}))\\\\\n    &{}\\leq R(S)+ \\gamma\\max_{a\\in\\mathcal{ A}}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)(R(s^\\prime) + \\gamma\\max_{a^\\prime \\in \\mathcal{A}}\\sum_{s^{\\prime\\prime} \\in \\mathcal{S}}P_{s^\\prime,a^\\prime}(s^{\\prime\\prime})V^\\pi(s^{\\prime\\prime}))\\\\\n    &{}= B^{\\pi^\\prime}(B^{\\pi^\\prime}(V^\\pi))(s)\n\\end{align*}\nUsing part (b) we also know that\\begin{align*}\n    ||B^\\pi(V)-V^\\pi ||_\\infty\\leq \\gamma ||V-V^\\pi ||_\\infty\n\\end{align*}\nimplies that applying $B^\\pi$ repeatedly (an infinite number of times) results in the convergent identity \\begin{align*}\n    B^{\\pi^\\prime}(B^{\\pi^\\prime} (B^{\\pi^\\prime}\\dots B^{\\pi^\\prime}(V)\\dots ))) = V^{\\pi^\\prime}\n\\end{align*} which finally proves the desired result that $V^\\pi(s) \\leq V^{\\pi^\\prime}(s)$ for all $s \\in \\mathcal{S}$.\n\\item Use the proceeding exercises to show that policy iteration will eventually converge (i.e., produce a policy $\\pi^\\prime = \\pi$). Furthermore, show that it must converge to the optimal policy $\\pi^*$. For the later part, you may use the property that if some value function satisfies\n\\begin{align*}\n    V(s) = R(s) + \\gamma\\max_{a\\in A}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)V(s^\\prime)\n\\end{align*}\nthen $V = V^*$.\\\\\\\\\n\\textit{answer:}\\\\\\\\\nGiven that $|S|+|A| < \\infty$ (i.e. that the number of states and the number of \\\\\\m actions are both finite), we let $\\pi_n$ be the resulting policy after the $n$th iteration of the Policy Iteration, and let\n\\begin{align*}\n    \\lim_{n\\xrightarrow[]{}\\infty}\\pi_n = \\pi_{\\infty}\n\\end{align*}\nWe know from part (c) that $V^\\pi(s) \\leq V^{\\pi^\\prime}(s)$ for all s, where $\\pi^\\prime$ is the resulting policy after one iteration of Policy Iteration, therefore we have that\n\\begin{align*}\n    V^{\\pi_n}(s) \\leq V^{\\pi_\\infty} \\quad\\forall s \\in \\mathcal{S},  \\quad \\forall n < \\infty\n\\end{align*}\nHowever, since there are only $k = |A|^{|S|}$ possibly policies it must be the case that\n\\begin{align*}\n    \\lim_{n\\xrightarrow[]{}\\infty}\\pi_n = \\pi_{k}\n\\end{align*}\nTherefore Policy Iteration converges to $\\pi_{k}$ and further,\n\\begin{align*}\n    V^{\\pi_{k}}(s) =&{} R(s) + \\gamma\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,\\pi_{|A|^|S|}}(s^\\prime)V^{\\pi_{k}}\\\\\n    =&{} R(s) + \\gamma\\max_{a\\in \\mathcal{A}}\\sum_{s^\\prime \\in \\mathcal{S}}P_{s,a}(s^\\prime)V^{\\pi_{k}}\n\\end{align*}\nwhich proves that $V^{\\pi_{k}} = V^*$\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "571e916f9461bfc264cc1aef9e6bb82d3d112916", "size": 32013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Unsupervised Learning and Reinforcement Learning/Problem Set 4 - Unsupervised Learning and Reinforcement Learning.tex", "max_stars_repo_name": "EitanJoseph/Standford-Machine-Learning", "max_stars_repo_head_hexsha": "5b1609a3fc1c7f32494a70ebc3f89d2ed8aed941", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-01T02:53:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-01T02:53:32.000Z", "max_issues_repo_path": "Unsupervised Learning and Reinforcement Learning/Problem Set 4 - Unsupervised Learning and Reinforcement Learning.tex", "max_issues_repo_name": "EitanJoseph/Standford-Machine-Learning", "max_issues_repo_head_hexsha": "5b1609a3fc1c7f32494a70ebc3f89d2ed8aed941", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Unsupervised Learning and Reinforcement Learning/Problem Set 4 - Unsupervised Learning and Reinforcement Learning.tex", "max_forks_repo_name": "EitanJoseph/Standford-Machine-Learning", "max_forks_repo_head_hexsha": "5b1609a3fc1c7f32494a70ebc3f89d2ed8aed941", "max_forks_repo_licenses": ["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.9393258427, "max_line_length": 507, "alphanum_fraction": 0.630806235, "num_tokens": 12213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6160408175832992}}
{"text": "\\subsection{Exponents}\n\nEigenmath requires parentheses around negative exponents.\nFor example,\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n10^(-3)\n\\end{Verbatim}\n\n\\noindent\ninstead of\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n10^-3\n\\end{Verbatim}\n\n\\noindent\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\n\\noindent\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\n\\noindent\nwhich is unambiguous.\n\n\\bigskip\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\\begin{Verbatim}[formatcom=\\color{blue}]\nx^1/2\n\\end{Verbatim}\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\\begin{Verbatim}[formatcom=\\color{blue}]\nx^(1/2)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle x^{1/2}$\n", "meta": {"hexsha": "4341faa51c9b0cdde6e128415e24d4f9ab20bc75", "size": 1087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/exponents.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/exponents.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/exponents.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 17.8196721311, "max_line_length": 74, "alphanum_fraction": 0.739650414, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743168019989179, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6160408113021216}}
{"text": "\\lab{Finite Volume Methods}{Finite Volume Methods}\n\\label{lab:finitevolume}\n\nWhen solving a PDE numerically, how do we deal with discontinuous initial data?\nThe Finite Volume method has particular strength in this area.\nIt is commonly used for hyperbolic PDEs whose solutions can spontaneously develop discontinuities as they evolve in time.\nThese solutions are often called shock waves.\n\n\\section*{Conservation Laws}\nConsider the conservation law\n\\begin{align}\n\\label{eqn:1D_continuous}\nu_t + f(u)_x = 0,\n\\end{align}\nwhere $u$ is a (spatially) one-dimensional conserved quantity, and $f(u)$ is the flux of $u$.\nThe continuous integral formulation of  \\eqref{eqn:1D_continuous} states that\n\\begin{align*}\n\t\\frac{d}{dt}\\int_a^b u(x,t) dx + \\int_a^b f(u)_x \\,dx = 0.\n\\end{align*}\n$\\frac{d}{dt}\\int_a^b u(x,t) dx$ may be thought of as the time evolution of the total `mass' of $u$ across the domain $[a,b]$, and is dependent only on the flux through the boundaries, since\n\\begin{align*}\n\\frac{d}{dt}\\int_a^b u(x,t) dx = f(u(a))-f(u(b)).\n\\end{align*}\nThis fact is an important idea utilized by finite volume methods, which generally consider the evolution of $u$ not at a given point, but instead in volume-averaged regions.\nFor example, let $\\{x_i\\}$ be a grid of equally spaced points with spacing $\\Delta x$, and let $C_i$ be the $i$-th `volume' (subinterval) defined by $(x_{i-1/2},x_{i+1/2})$.\nWe are interested in the evolution of the volume average of $u$ over this interval,\n\\begin{align*}\nU_i^n  = \\frac{1}{\\Delta x}\\int_{C_i} u(x,t^n)dx,\n\\end{align*}\nwhere $\\{t^n\\}$ is the time discretization.\n\n\\begin{figure}\n\\centering\n\\includegraphics[trim= 20mm 195mm 0mm 30mm, clip]{flux_form.pdf}\n\\caption{A schematic of the fluxes for the finite volume method as indicated by \\eqref{eqn:flux_form}.}\n\\end{figure}\n\nThe evolution of these volume-averaged quantities will depend only on the flux through the cell edges, so that\n\\begin{align}\n\\label{eqn:1D_semi_continuous}\n\\frac{d}{dt}\\int_{C_i} u(x,t) dx = f(u(x_{i-1/2},t))-f(u(x_{i+1/2},t)).\n\\end{align}\nWe can then construct a time-stepping method where $\\sum_i U_i^n\\Delta x$ (the total `mass' of the system) is conserved from one time step $n$ to the next.\n\nLet $F^n_{i-1/2} = \\frac{1}{\\triangle t}\\int_{t^n}^{t^{n+1}} f(u(x_{i-1/2},t)) \\, dt$.\nThen\n\\begin{align*}\n\\int_{t^n}^{t^{n+1}} \\left[ \\frac{d}{dt}\\int_{C_i} u(x,t)\\, dx \\right]\n&{}= \\int_{C_i} u(x,t^{n+1}) - u(x,t^{n})\\, dx ,\\\\\n&{ }= \\triangle t \\left(F^n_{i-1/2} - F^n_{i+1/2}\\right).\n\\end{align*}\n\nThus, by integrating \\eqref{eqn:1D_semi_continuous} in time, we may approximate the evolution of the cell (`volume') averages with the method\n\\begin{align}\n\\label{eqn:flux_form}\nU_i^{n+1} = U_i^n - \\frac{\\Delta t}{\\Delta x} \\left(F^n_{i+1/2}-F^n_{i-1/2}\\right).\n\\end{align}\nwhere $U_i^n = \\frac{1}{\\triangle x} \\int_{C_i} u(x,t^n) \\, dt$.\n% where\n% \\begin{gather}\n% F_{i-1/2}^n = \\frac{1}{\\Delta t} \\int_{t_n}^{t_{n+1}}f(u(x_{i-1/2},t))dt.\n% \\end{gather}\nThis formulation guarantees the conservation properties that are so desirable for conservation laws, if the time-averaged fluxes $F_{i-1/2}^n$ can be discretized in a natural way.\n\nThe key contribution of finite volume methods is the computation of $F_{i-1/2}^n$.\nFor a truly nonlinear $f(u)$ this can be rather complicated and messy, and typically will involve solving what is usually referred to as the Riemann problem for the conservation law.\nThe interested student can look at \\cite{Le2002} for a very thorough introduction and discussion on the subject.\nWe will consider the linear problem in one dimension.\nThe analog to higher dimensions is obtained by considering the eigenvector decomposition of any linear system.\nNonlinear equations complicate things further.\n\n\\section*{The linear advection equation and upwinding}\nThe simplest conservation law describes the advection or transport of a quantity.\nThe PDE is given by\n\\begin{align}\nu_t + au_x = 0, \\label{eqn:fv_advection}\n\\end{align}\nand describes the motion of a concentration of some constituent $u$ by a constant velocity one-dimensional `wind' $a>0$.\n%(a slight generalization of this would be to consider $a=a(x)$, but the general concepts are exactly the same as those viewed here, just a more local consideration is necessary).\nIn higher dimensions this is an important problem in many fields, for example the transport of chemicals in the atmosphere and oceans, proper mixing of various properties in metallurgy, and the passing of information along a network.\n\nNote that whenever $u(x,t)$ is a solution of the advection equation, then $u(x-at,t_0)$ (for any fixed $t_0$) is also a solution.\nThus, if $u(x,0) = u_0(x)$ then the solution for all time can be represented by $u(x,t) = u_0(x-at)$.\nThis is an important property of \\eqref{eqn:fv_advection}, and gives a new meaning to the term advection: this equation merely takes the initial conditions and passively transports them with velocity $a$.\n\nFor this equation the computation of the flux appears straightforward: $F_{i-1/2}^n = a\\overline{U}^n_{i-1/2}$ where the $\\overline{U}^n_{i-1/2}$ refers to the time average of $U_{i-1/2}$ over the interval $t_n$ to $t_{n+1}$.\nLet us determine how to approximate this time average.\n% To understand how this might be done, note from Figure \\ref{something} that for the advection equation with $a>0$ the flux that determines $U_i^{n+1}$ will be dependent on the value of $U_{i-1}^n$ so that it makes sense that we approximate the flux here as $F_{i-1/2}^n = aU_{i-1}^n$ (recall that the $U_i^n$ are cell averages of the continuous quantity $u(x)$).\nNote from Figure \\ref{fig:fv_LW_reconstruction} that when $a>0$ the flux that determines $U_i^{n+1}$ will be dependent on the value of $U_{i-1}^n$. Thus, one possibility is to approximate the flux by $F_{i-1/2}^n = aU_{i-1}^n$.\nUsing this approximation of the flux together with the flux differencing formula \\eqref{eqn:flux_form} yields the first order upwind method, given by\n\\begin{align*}\nU_i^{n+1} = U_i^n - \\frac{a\\Delta t}{\\Delta x}\\left(U_i^n-U_{i-1}^n\\right).\n\\end{align*}\n% (recall that the $U_i^n$ are cell averages of the continuous quantity $u(x)$).\n% Similarly, if $a<0$ then $F_{i-1/2}^n = aU_{i}^n$.\n% This is called the first order upwind method\n% and gives a completely discretized version of the problem as \\eqref{eq:flux_form} with\n% \\begin{align*}\n% F_{i-1/2}^n = a^- U_i^n + a^+U_{i-1}^n,\n% \\end{align*}\n% where $a^- = \\min (a,0)$ and $a^+ = \\max (a,0)$.\n% Note that this formulation allows for an easy extension to the case where $a=a(x)$ is a more general function of $x$.\n% From now on we will consider the simpler case where $a>0$ is constant.\n% From now on we will consider $a>0$ only, the generalization to other cases is relatively straightforward.\n% In either case, the flux differencing formula \\eqref{eq:flux_form} yields\n% \\begin{align*}\n% U_i^{n+1} = U_i^n - \\frac{a\\Delta t}{\\Delta x}\\left(U_i^n-U_{i-1}^n\\right)\n% \\end{align*}\n% for the upwind method.\nAnother way to derive the upwind method is to instead suppose that what we want to do is reconstruct $u(x)$ at each time step $n$ inside each cell $(x_{i-1/2},x_{i+1/2})$from the mean values in that cell and its surrounding neighbors. This reconstructed $\\tilde{u}(x)^n$ is then defined piecewise for each cell $i$.\nThe solution at the next time step can be found as $\\tilde{u}^{n+1}(x) = \\tilde{u}^n(x-a\\triangle t)$ which allows us to determine the fluxes $F^n_{i-1/2}$ once we have settled on a method for determining $\\tilde{u}^n(x)$ in each cell.\nThe simplest approach is\n\\[\\tilde{u}^n(x) = U_i^n \\text{ for }x \\in (x_{i-1/2},x_{i+1/2})\\]\nThis leads to fluxes given by\n\\begin{align}\nF_{i-1/2}^n &= \\frac{a}{\\triangle t}\\int_{0}^{t_{n+1}-t_n} \\tilde{u}^n(x_{i-1/2},t)\\, dt , \\\\\n&= \\frac{a}{\\triangle t}\\int_{0}^{\\triangle t} \\tilde{u}^n(x_{i-1/2}-at)\\, dt  ,\\\\\n&= aU_{i-1}^n.\\nonumber\n\\end{align}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth, trim = 20mm 65mm 20mm 65mm, clip]\n{LW_reconstruction.pdf}\n\\caption{The piecewise linear reconstruction for the upwind and Lax-Wendroff methods.\nThe solid lines represent the simplest reconstruction of the cell averages leading to the upwind method, and the dashed lines are those whose slope is obtained via the Lax-Wendroff method.\nNote that the LW method introduces a spurious maximum at $i+3/2$ (the cell edge between $U_{i+1}$ and $U_{i+2}$) and the minimum at $i-3/2$ will be unphysical exaggerated.\nThe upwind method avoids this difficulties, but clearly loses a significant amount of the available information.\nThis provides the motivation for the slope limiters.}\n\\label{fig:fv_LW_reconstruction}\n\\end{figure}\n\nThe following code solves the problem\n\\begin{align}\n\\begin{split}\n\tu_t +a u_x &= 0, \\quad 0 < x < 1, \\\\\n\tu(x,t) &= f(x),\\\\\n\tu(0,t) &= u(1,t),\n\\end{split}\\label{eqn:fv_exercise}\n\\end{align}\nwhere $f$ represents a signal with two parts: one is smooth and the other is discontinuous.\nNotice that this PDE has periodic boundary conditions.\nEssentially we are evolving the signal around the unit circle.\nThis allows us to evolve the signal much further to test our numerical methods, since we only have to discretize the interval $[0,1]$ instead of a much larger domain.\nTo see how to implement the boundary conditions, consider a grid $0 = x_0< x_1< \\ldots< x_{N-1}< x_N = 1$ of evenly spaced points.\nSince $x_N = x_0$, it is sufficient to track $x_0, \\ldots , x_{N-1}$.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom math import floor\n\ndef upwind(u0, a, xmin, xmax, t_final, nt):\n    \"\"\" Solve the advection equation with periodic\n    boundary conditions on the interval [xmin, xmax]\n    using the upwind finite volume scheme.\n    Use u0 as the initial conditions.\n    a is the constant from the PDE.\n    Use the size of u0 as the number of nodes in\n    the spatial dimension.\n    Let nt be the number of spaces in the time dimension\n    (this is the same as the number of steps if you do\n    not include the initial state).\n    Plot and show the computed solution along\n    with the exact solution. \"\"\"\n    dt = float(t_final) / nt\n    # Since we are doing periodic boundary conditions,\n    # we need to divide by u0.size instead of (u0.size - 1).\n    dx = float(xmax - xmin) / u0.size\n    lambda_ = a * dt / dx\n    u = u0.copy()\n    for j in xrange(nt):\n        # The Upwind method. The np.roll function helps us\n        # account for the periodic boundary conditions.\n        u -= lambda_ * (u - np.roll(u, 1))\n    # Get the x values for the plots.\n    x = np.linspace(xmin, xmax, u0.size+1)[:-1]\n    # Plot the computed solution.\n    plt.plot(x, u, label='Upwind Method')\n    # Find the exact solution and plot it.\n    distance = a * t_final\n    roll = int((distance - floor(distance)) * u0.size)\n    plt.plot(x, np.roll(u0, roll), label='Exact solution')\n    # Show the plot with the legend.\n    plt.legend(loc='best')\n    plt.show()\n\n# Define the initial conditions.\n# Leave off the last point since we're using periodic\n# boundary conditions.\nnx = 30\nnt = nx * 3 // 2\nx = np.linspace(0., 1., nx+1)[:-1]\nu0 = np.exp(-(x - .3)**2 / .005)\narr = (.6 < x)  &  (x < .7 )\nu0[arr] += 1.\n\n# Run the simulation.\nupwind(u0, 1.2, 0, 1, 1.2, nt)\n\\end{lstlisting}\n\nTry running the previous code block with \\li{nx} set to $30$, $60$, $120$, and $240$.\nYou will notice that the numerical solution diffuses with time.\nIt diffuses especially fast at the points of discontinuity.\n\n\\begin{comment}\nAnother way to derive the upwind method is to instead suppose that what we want to do is reconstruct $u(x)$ at each time step $n$ inside each cell $(x_{i-1/2},x_{i+1/2})$ from the mean values in that cell and its surrounding neighbors.\nThis reconstructed $\\tilde{u}(x)^n$ is then defined piecewise for each cell $i$.\nThe solution at the next time step can be found as $\\tilde{u}^{n+1}(x) = \\tilde{u}^n(x-a\\Delta t)$ which allows us to determine the fluxes $F_{i-1/2}^n$ once we have settled on a method for determining $\\tilde{u}^n(x)$ in each cell.\nThe simplest approach is\n\\begin{gather*}\n\\tilde{u}^n(x) = U^n_i \\mbox{ for } x \\in (x_{i-1/2},x_{i+1/2}).\n\\end{gather*}\n% This leads to fluxes given by\n% \\begin{gather}\n% F_{i-1/2}^n = \\frac{a}{\\Delta t} \\int_{t_n}^{t_{n+1}}\\tilde{u}(x_{i-1/2}-a(t-t_n),t)dt = \\frac{a}{\\Delta t} \\int_{t_n}^{t_{n+1}}U_i^n dt = aU_i^n.\n% \\end{gather}\nIn either case, we can see that using the flux differencing formula \\eqref{eq:flux_form} that\n\\begin{gather}\nU_i^{n+1} = U_i^n - \\frac{a\\Delta t}{\\Delta x}\\left(U_i^n-U_{i-1}^n\\right)\n\\end{gather}\nfor the upwind method.\n\\end{comment}\n\n\\section*{Piecewise linear reconstruction and slope limiters}\nThe upwind method is formally only first order, and actually does relatively poorly in terms of actually transporting the initial data with velocity $a$.\nYou can notice from the example code that the upwind method has errors that are `diffusive' meaning that the initial data is diffused as time evolves, losing the peaks and fine details.\nThis is because the error for the upwind method is on the order of the second derivative of $u$ which is of a diffusive nature.\nTo get an improved method, consider a better reconstruction inside each cell, i.e.\n\\begin{gather}\n\\tilde{u}^n(x) = U_i^n + m_i^n(x-x_i) \\mbox{ for } x \\in (x_{i-1/2},x_{i+1/2})\n\\end{gather}\nwhere the slope of this linear reconstruction $m_i^n$ is determined as a function of the neighboring cell averages at time $n$ and $U_i^n$ itself.\nThen the flux is given by\n\\begin{align}\n\\begin{split}\nF_{i-1/2}^n\n&= \\frac{a}{\\triangle t}\\int_{0}^{t_{n+1}-t_n} \\tilde{u}^n(x_{i-1/2}-at)\\, dt  ,\\\\\n&= \\frac{a}{\\triangle t}\\int_{0}^{\\triangle t} U_{i-1}^n + m_i^n(x_{i-1/2} - at - x_i), \\\\\n&= a \\left( U_{i-1}^n + \\frac{m_{i-1}^n}{2} (\\triangle x - a \\triangle t)\\right).\n\\end{split}\n\\label{eqn:finite_volume_improved_flux}\n\\end{align}\nOne of the most natural approaches is to just estimate the slope depending on the cell $i$ and a neighboring cell $i+1$ or $i-1$.\nThis leads to two popular methods, the Lax-Wendroff method and the Beam-Warming method (that really is the name).\nThe Lax-Wendroff method has a slope chosen as\n\\begin{gather}\nm_i^n = \\frac{U^n_{i+1}-U_{i}^n}{\\Delta x}.\n\\end{gather}\n% This leads to\n% \\begin{gather}\n% U_i^{n+1} = U_i^n - \\frac{\\Delta t}{2\\Delta x} a \\left(U_{i+1}^n-U_{i-1}^n\\right) + \\frac{1}{2}\\left(\\frac{\\Delta t}{\\Delta x}\\right)^2 a^2 \\left(U_{i-1}^n - 2U_i^n+U_{i+1}^n\\right)\n% \\end{gather}\nwhich it turns out is formally second-order accurate.\nIt turns out though that the errors for this method are dispersive, meaning that near very steep gradients, the method will generate very rapid oscillations (due to the third derivative of $u$ not being approximated accurately).\nAnother way to consider how these errors arise is to notice from Figure \\ref{fig:fv_LW_reconstruction} that if the piecewise linear reconstruction is advocated by some positive wind $a$ then there will be places where the discontinuous nature of the reconstruction will introduce spurious maxima or minima into the solution.\nThese become the spurious waves seen in simulations using the Lax-Wendroff method.\n\nA solution to this dilemma between balancing the diffusive and dispersive errors comes from constructing slopes $m_i^n$ that ensure no such non-monotonic transport takes place.\nThe basic idea is to constrain the slope so that the reconstructed piecewise linear function $\\tilde{u}^n(x)$ will not generate unphysical extremal values when it is advocated by some finite wind $a$.\nThe Minmod limiter chooses the slope as\n\\begin{gather}\nm_i^n = minmod\\left(\\frac{U_i^n-U_{i-1}^n}{\\Delta x},\\frac{U_{i+1}^n-U_{i}^n}{\\Delta x}\\right)\n\\end{gather}\nwhere\n\\begin{gather}\nminmod(a,b) = \\left\\{\\begin{array}{ccc}a  \\mbox{ if } |a| < |b|  \\mbox{ and } ab>0\\\\\nb  \\mbox{ if } |b|<|a|  \\mbox{ and } ab>0\\\\ 0  \\mbox{ if } ab < 0 .\\end{array}\\right.\n\\end{gather}\n\n% \\begin{itemize}\n% \\item Minmod limiter\n% \\begin{gather}\n% m_i^n = minmod\\left(\\frac{U_i^n-U_{i-1}^n}{\\Delta x},\\frac{U_{i+1}^n-U_{i^n}}{\\Delta x}\\right)\n% \\end{gather}\n% where\n% \\begin{gather}\n% minmod(a,b) = \\left\\{\\begin{array}{ccc}a  \\mbox{ if } |a| < |b|  \\mbox{ and } ab>0\\\\\n% b  \\mbox{ if } |b|<|a|  \\mbox{ and } ab>0\\\\ 0  \\mbox{ if } ab < 0 .\\end{array}\\right.\n% \\end{gather}\n% \\item Superbee limiter\n% \\begin{gather}\n% m_i^n = maxmod(m^{(1)}_i,m^{(2)}_i)\n% \\end{gather}\n% where the maxmod function selects $m^{(k)}_i$ with the larger modulus, and\n% \\begin{gather}\n% m^{(1)}_i = minmod \\left(\\frac{U_{i+1}^n-U_i^n}{\\Delta x},2\\frac{U_i^n-U_{i-1}^n}{\\Delta x}\\right)\\\\\n% m^{(2)}_i = minmod \\left( 2\\frac{U_{i+1}^n-U_i^n}{\\Delta x},\\frac{U_i^n-U_{i-1}^n}{\\Delta x}\\right).\n% \\end{gather}\n% \\item Monotonized central-difference limiter\n% \\begin{gather}\n% m_i^n = minmod\\left(\\frac{U_{i+1}^n-U_{i-1}^n}{2\\Delta x},2\\frac{U_i^n-U_{i-1}^n}{\\Delta x},2\\frac{U_{i+1}^n-U_i^n}{\\Delta x}\\right)\n% \\end{gather}\n% \\end{itemize}\n\n% \\begin{problem}\n% Code up the Superbee and Minmod %MC\n% limiters for an advection problem with constant wind.\n% Use different initial data that is smooth or has steep gradients (such as the square wave in the example code) to see which of the three limiters may be more optimal.\n% \\end{problem}\n\n\\begin{problem}\nImplement the Lax Wendroff method and use it to solve \\eqref{eqn:fv_exercise}.\nCompare it to the upwind method for $N = 30, 60, 120$, and 240.\nYou should be able to tell that the Lax Wendroff method approximates the smooth portion of the signal much better, as it does not struggle with diffusion.\nUnfortunately, it has some difficulty with the discontinuous portion, where unphysical oscillations are seen.\nRecall that we saw something similar in the waves lab when there were discontinuous initial conditions.\n\nHint: Use equations \\ref{eqn:finite_volume_improved_flux} and \\ref{eqn:flux_form}.\n\\end{problem}\n\n\\begin{problem}\nImplement the Minmod method and use it to solve \\eqref{eqn:fv_exercise}.\nCompare it to the upwind and Lax Wendroff methods for $N = 30, 60, 120$, and 240.\nBe sure to vectorize the minmod operation.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{FiniteVolume_Comparisons.pdf}\n\\caption{Solutions of \\eqref{eqn:fv_exercise} at time $t = 1.2$ using various methods.\nHere the advection coefficient is $a = 1.2$, and there are  $N = 100$ subintervals in space, 150 subintervals in time.}\n\\label{fig:fv_Comparisons}\n\\end{figure}\n\n\\section*{Beyond piecewise linear reconstructions}\nAs you can imagine, using a linear approximation is not the only option.\nThere are a host of high order finite volume methods that consider polynomial reconstructions of $\\tilde{u}^n$ inside each cell.\nThe key is then to use some nonlinear limiting technique that will ensure that when $\\tilde{u}^n(x)$ is advocated that no new extrema are introduced.\nChoosing the correct limiter for the given application then becomes an art unto itself. ", "meta": {"hexsha": "94e27d92186b392a21ccc6a22e9a07ca5bfe61f5", "size": 18870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FiniteVolume/finitevolume.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/FiniteVolume/finitevolume.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/FiniteVolume/finitevolume.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": 57.3556231003, "max_line_length": 364, "alphanum_fraction": 0.7138844727, "num_tokens": 5995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6160408003012408}}
{"text": "%!TEX root = ../main.tex\n\n\\section{Vectors problems}\n\\label{sec:vec_problems}\n\n\\vspace{-2mm}\n\nYou learned a bunch of vector formulas and you saw some vector diagrams,\nbut did you really learn how to solve problems with vectors?\nThere is only one way to find out: test yourself by solving problems.\n\nI've said it before and I don't want to repeat myself too much,\nbut it's worth saying again: the more problems you solve, the better you'll understand the material.\nIt's now time for you to try the following vector problems to make sure you're on top of things.\n\n\\medskip\n\n{ \\small\n\n\\begin{problems}{ch3}\n\n\t\\begin{problem}\n\t\tGiven the vectors $\\vec{u}=(1,1,1)$, $\\vec{v} = (2,3,1)$, and $\\vec{w}=(-1,-1,2)$,\n\t\tcompute the following products:\n\t\t\n\t\t\\threecol\n\t\t\t\\textbf{a)}~$\\vec{u} \\cdot \\vec{v}$\n\n\t\t\t\\textbf{b)}~$\\vec{u} \\cdot \\vec{w}$\n\t\t\t\n\t\t\t\\textbf{c)}~$\\vec{v} \\cdot \\vec{w}$\n\t\t\\endthreecol\n\t\t\n\t\t\\threecol\n\t\t\t\\textbf{d)}~$\\vec{u} \\times \\vec{v}$\n\n\t\t\t\\textbf{e)}~$\\vec{u} \\times \\vec{w}$\n\t\t\t\n\t\t\t\\textbf{f)}~$\\vec{v} \\times \\vec{w}$\n\t\t\\endthreecol\n\t\t\n\t\t\\begin{answer}\\textbf{a)}~$6$.\n\t\t\t\t\t\\textbf{b)}~$0$.\n\t\t\t\t\t\\textbf{c)}~$-3$.\n\t\t\t\t\t\\textbf{d)}~$(-2, 1, 1)$.\n\t\t\t\t\t\\textbf{e)}~$(3, -3, 0)$.\n\t\t\t\t\t\\textbf{f)}~$(7, -5, 1)$.\\end{answer}\n\t\\end{problem}\n\n\n\t\\begin{problem}\n\t\tGiven the vectors $\\vec{p} =(1,1,0,3,3)$ and $\\vec{q}=(1,2,3,4,5)$, calculate the following expressions:\n\t\t\\threecol\n\t\t\t\\textbf{a)}~$\\vec{p}+\\vec{q}$\n\t\t\t\n\t\t\t\\textbf{b)}~$\\vec{p}-\\vec{q}$\n\t\t\t\n\t\t\t\\textbf{c)}~$\\vec{p} \\cdot \\vec{q}$\n\t\t\\endthreecol\n\t\t\n\t\t\\begin{answer}\\textbf{a)}~$(2,3,3,7,8)$.\n\t\t\t\t\t\\textbf{b)}~$(0,-1,-3,-1,-2)$.\n\t\t\t\t\t\\textbf{c)}~$30$.\\end{answer}\n\t\\end{problem}\n\n\n\t\\begin{problem}\n\t\tFind a unit vector that is perpendicular to both  $\\vec{u}=(1, 0, 1)$ and $\\vec{v} =(1, 2, 0)$.\n\t\t\\begin{hint}\n\t\t\tUse the cross product.\n\t\t\\end{hint}\n\t\t\\begin{answer}$(-\\frac{2}{3}, \\frac{1}{3}, \\frac{2}{3})$ or $(\\frac{2}{3}, -\\frac{1}{3}, -\\frac{2}{3})$.\\end{answer}\n\t\t\\begin{solution}See \\href{http://bit.ly/1cOa8yo}{\\texttt{bit.ly/1cOa8yo}} for calculations.\n\t\t\\end{solution}\n\t\\end{problem}\n\n\t\\begin{problem}\n\t\tFind a vector that is orthogonal to both $\\vec{u}_1 = (1, 0, 1)$ and $\\vec{u}_2 =(1, 3, 0)$, \n\t\t and whose dot product with the vector  $\\vec{v}= (1, 1, 0)$ is equal to $8$.\n\t\t%\t\\begin{hint}\n\t\t%\t\\end{hint}\n\t\t\\begin{answer}$(12, -4, -12)$.\\end{answer}\n\t\t\\begin{solution}\n\t\t\tAny multiple of the vector $\\vec{u}_1 \\times \\vec{u}_2 = (-3,1,3)$ \n\t\t\tis perpendicular to both $\\vec{u}_1$ and \t$\\vec{u}_2$.\n\t\t\tWe must find a multiplier $t \\in \\mathbb{R}$ such that \n\t\t\t$t(-3,1,3) \\cdot (1, 1, 0) = 8$.\n\t\t\tComputing the dot product we find $-3t + t = 8$, so $t=-4$.\n\t\t\tThe vector we're looking for is $(12, -4, -12)$.\n\t\t\tSee \\href{http://bit.ly/1nmYH8T}{\\texttt{bit.ly/1nmYH8T}} for calculations.\n\t\t\\end{solution}\n\t\\end{problem}\n\n\n\\end{problems}\n\n} % /small\n\n", "meta": {"hexsha": "cc881beb0147510892b7feff7f4201db39760f7f", "size": 2833, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sources/original/problems/chapter3_problems.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/problems/chapter3_problems.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/problems/chapter3_problems.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": 28.6161616162, "max_line_length": 118, "alphanum_fraction": 0.5979527003, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.6160148131140248}}
{"text": "In this section, we first define the problem we address, then the mathematical notation we use, and finally our  evaluation metrics.\n\n%In this section, we will define our addressing problem with the notation. Also, the background about this paper will be provided.\n\n\n\\subsection{Problem definition}\n\nThe problem we address in this paper is related to the need of an AUI \nto ease the task of monitoring alerts in\nlarge-scale displayed networks. The new interface is expected\nto filter irrelevant information to provide localized context for\neach event or alert (defined loosely as a relevant related content localized in time, space, and/or keyword usage). Hence, we define the problem we are addressing in this\npaper as a problem of filter optimization.\nWe assume that selection of information elements to display in visual interface is obtained via settings of three filters that can jointly express a global filter. These three sub-filters are the following:\n\n\n%The problem we address in this paper is the proper display of portion in the network for user's easy to investigate large-scale network elements. The new system is expected to filter information to provide localized and relevant element in the interface. This problem is able to be defined as a filter search/recommendation problem, We expect to employ standard IR theory to solve this problem based on our argument about the similarity of AUI and IR system. We assume that display of the elements in the network is obtained via three filters that can jointly express a global filter. These three sub-filters are:\n\\begin{itemize}\n\\item Time: expresses the time window of a retrieved set. \n\\item Keyword: expresses a set of keyword to include or exclude from a retrieved set.\n\\item Location: expresses a bounding box of a retrieved set. The location can be expressed as longitude/latitude values, or pure coordinates obtained using a given display layout. \n\\end{itemize}\n\nThe problem we study is how to optimize one or multiple filter selection settings to maximize retrieval of relevant content. \n%best set of elements that is assessed using one of the metrics described above, i.e., expected precision, expected recall, or expected F1-score\n\n\\subsection{Mathematical Notation}\nThroughout this paper, we present all algorithms for Greedy and Optimal search using the following mathematical notation:\n\n\\begin{itemize}\n\\item An element $j$, for which three types of metadata are associated: (i) a textual content, which is composed of a set of terms of size $n$, (ii) a timestamp $t_e$, which may represent the creation date of $j$, and (iii) a position coordinates $(x_{e},y_{e})$.\n\\item Three variables $I(j)$, $B(j)$ and $S(j)$ are associated to each element $j$. $I(j)$ refers to whether element $j$ is in the retrieved set (E). $B(j)$ is the boolean variable about relevance of element $j$. $S(j)$ is a probabilistic score of  element $j$ being relevant. Note that $I(j)$ is correlated with the UI system. $B(j)$ and $S(j)$ are independent of the system. %$\\emph{I(j), B(j)} \\in \\{0, 1\\}$, $\\emph{S(j)} \\in \\left[0, 1\\right]$. \nAlso, $B(j)$ follows a \\emph{Bernoulli} distribution with parameter $S(j)$, and hence, the expectation of $B(j)$ is $S(j)$, i.e., \n  $\\mathbb{E_S}[B(j)] = S(i)$.\n\n\n\n\n%which allows to derive the expectation of \\emph{B(j)} as follows:\n%\\begin{equation}\n % \\mathbb{E_S}[B(j)] = 0*(1 - S(i))+ 1*S(i) = S(i)\n%\\end{equation}\n\n\\item A global collection of elements $GC$ with size $m$. %Two subsets of $GC$ are particularly important in this research: retrieved set $E$ and relevant set $RS$.  \n\\item A retrieved set $E$ with $E \\subseteq  GC$, for which we use $E^*$ to refer to any subset, i.e., $E^*\\subseteq E$. This variable depends on our user-interface filter system. Note that size of $E$ can be represented the sum of $I(j)$ among the global collection. Therefore, we have $|E| = \\sum_{j=1}^m I(j)$.\n\\item A relevant set $RS$ of $|RS|$ elements, which contains all relevant elements. This is independent of the UI-filter system. Note that size of $RS$ is equal to the sum of $B(j)$ among the global collection. Therefore, we have $|RS| = \\sum_{j=1}^m B(j)$. %However, $B(j)$ is not available for our estimation of $RS$ size in practice. We have to use expected $RS$ size $|RS|$, $\\mathbb{E_S}|RS|$, to approximate $|RS|$.\n%\\begin{equation}\n  %|RS| \\approx \\mathbb{E_S}|RS| = \\sum_{j=1}^m \\mathbb{E_S}[B(j)] = \\sum_{j=1}^m S(j)\n%\\end{equation}\n\n\\item A keyword query $Q_k=\\{\\neg t_{1}^{*},\\dots \\neg t_{k}^{*}\\}$, which expresses query term exclusion, i.e., find elements that don't contain the terms $t_{1}^{*},\\dots t_{k}^{*}$.\n\\item  A time query $Q_t=[t_{start},t_{end}]$, which expresses the search for elements in the time window $[t_{start},t_{end}]$.\n\\item A position query $Q_p=[(x_{min},y_{min}),(x_{max},y_{max})]$, which expresses the search of elements falling in the bounding box represented by the  lower and upper bound coordinates -- respectively $(x_{min},y_{min})$ and $(x_{max},y_{max})$.\n\\item A query filter $Q$, which combines the three sub-filters $Q_k$, $Q_t$, and $Q_p$ in a conjunction, i.e., $Q=[Q_k\\wedge Q_t\\wedge Q_p]$. \n\n\\end{itemize}\n\n\n\n\n\n\n\n%The goal is to explore an algorithm to obtain an optimal filter setting to retrieve a set of elements with maximum score of the specific metric.\n\n\n\n%\\subsection{Comparison to standard IR search}\n%The comparison between information retrieval for web search and information retrieval for filtering in AUIs can be summarized in Table \\ref{tbl:Comparaison2IR}. Obviously , there are important differences between web search and filtering for AUIs, especially in the indirect selection of results through filter settings. This unexplored field provides new possibilities and challenges of research in this novel information retrieval setting:\n%\\begin{itemize}\n%\\item Evaluation metrics and human factors: Are there new evaluation metrics specific to this AUI filtering setting? What evaluation metrics correlate with AUI user performance? \n%\\item Optimization and algorithms: How do we optimally select filter settings to maximize evaluation metrics in expectation? How can we interpret simple heuristics like average and cumulative relevance? (Answer: expected precision.) How do MILPs, relaxed LP approximations with guarantees, or greedy approaches compare in terms of time and metric quality? Are there properties of different filters (1D for time, 2D for bounding box, or discrete choices for property selection) that lend themselves to specialized greedy approaches? \n%\\item Robustness: As the signal-to-noise ratio varied in the quality of the relevance scoring, how do various algorithms perform? \n%\\item Explanation: Can we provide explanations for filter settings to allow users to understand the reasons for the suggestions? \n%\\item Personalization and learning: Can we learn from observations of manual adaption of the suggested filter settings to understand how to improve the third-party scoring systems? \n%\\item Collaborative filtering: Can we generalize learning across multiple\n%users in a collaborative filtering approach? \n%\\item Learning from implicit feedback: How can we leverage implicit user\n%feedback such as clicks and dwell time to indirectly measure the relevance\n%of filtered content and improve system performance.\n%\\end{itemize}\n\n%\\subsection{Optimization technique definition}\n\n%The \\emph{greedy algorithm} is an algorithmic paradigm that aims to obtain a global optimum of a problem in terms of making the locally optimal decision at each step \\cite{Black2005}. In a search problem, a greedy algorithm does not in general produce an optimal solution, but it still yields locally optimal solutions that approximate a global optimum in a reasonable time.\n\n%The greedy algorithms described in this paper are coupled with a \\emph{Top-down} search strategy, which basically begins with the whole search space, and then partition into several sub-spaces in a lower level for the local optimization search heuristic.\n\n%An \\emph{optimization-based} search is the problem of finding the best solution from all feasible solutions. Usually, the standard form of an optimization problem is defined as the minimization/maximization of a given objective function subject to a set of constraints. \n\n%The search problem will be transformed into Mixed integer linear programming (MILP), which involves problems in which only some of the variables, $x_{i}$, are constrained to be integers, while other variables are allowed to be non-integers.\n\n\n\n\\subsection{Evaluation metrics}\n\nWe adopt the Boolean relevance framework of IR and thus assume that all information elements $j$ have a ground truth relevance assessment $B(j)$ available at evaluation time.  \n%%However, unlike previous document-based methods for estimating relevance at retrieval-time, we do not rely on text associated with information elements and instead rely on a third-party to supply an estimated probability (score) of relevance $S(j)$. \n%Traditionally, Boolean labels indicate the relevance of documents is used to evaluate retrieval sets (e.g., precision). \n%In practice, IR models are based on probabilistic scores to measure relevance of the elements, such as TF-IDF and cosine similarity.  \n%In practice, we are able to employ third-party technique to provide probabilistic scores to measure relevance of the document in IR system, such as TF-IDF and cosine similarity. Consequently,\nBecause filters are equivalent to Boolean retrieval (they either select or do not select content as relevant) and we have a probabilistic estimate of relevance $S(j)$, we propose to evaluate\nexpected variants of standard precision, recall, and F1-score.\n%Boolean retrieval evaluation metrics based on the relaxation of Boolean labels to probabilistic scores resulting in expected metrics, i.e., \\emph{expected precision} (EP), \\emph{expected recall} (ER) and \\emph{expected F1-Score} (EF1).\nSpecifically because the filter that selects all information elements would maximize expected recall, the filter that selects the highest probability singleton information element would maximize expected precision, we focus on expected F1-score as a trade-off to balance expected precision and recall.\n\nGiven a retrieved information element set $E$, a relevant element set $RS$ selected by a filter setting, the global information element collection $GC$ with size $m$, the precision of a retrieved set $P(E)$ is defined as follows:\n\\begin{equation}\n   P(E) = \\dfrac{\\sum_{j \\in RS} B(j)}{|E|} = \\dfrac{\\sum_{j=1}^m B(j)I(j)}{\\sum_{j=1}^m I(j)} \n\\end{equation}\nThe relaxation of the Boolean label $B(j)$ to probabilistic score $S(j)$ gives the following definition of \\emph{expected precision}: \n\\begin{equation}\nEP(E)=\\mathbb{E_{S}}[\\dfrac{\\sum_{j=1}^{m}B(j)I(j)}{\\sum_{j=1}^{m}I(j)}]=\\dfrac{\\sum_{j=1}^{m}\\mathbb{E_{S}}[B(j)]I(j)}{\\sum_{j=1}^{m}I(j)}=\\dfrac{\\sum_{j=1}^{m}S(j)I(j)}{\\sum_{j=1}^{m}I(j)}\n\\end{equation}\nSimilarly the recall of a retrieved set $R(E)$ is defined as:\n\\begin{equation}\n   R(E) = \\dfrac{\\sum_{j \\in RS} B(j)}{|RS|} = \\dfrac{\\sum_{j=1}^m B(j)I(j)}{|RS|} \n\\end{equation}\nTaking a 1st order Taylor expansion, we have the following expectation approximation %$\\mathbb{E}(X/Y)\\approx\\dfrac{\\mathbb{E}(X)}{\\mathbb{E}(Y)}$ \n$\\mathbb{E}(X/Y)\\approx \\mathbb{E}(X)/ \\mathbb{E}(Y)$ for two dependent random variables $X$ and $Y$~\\cite{Kempen2000}. Hence, \nwe can now define an \\emph{approximated expected recall}: \n%Given a retrieved element set $E$  and a relevant element set $RS$ among a global element collection $GC$ with size $m$, we propose the following definition of \\emph{expected precision} (EP), \\emph{expected recall} (ER) and \\emph{expected F1-Score} (EF1):\n\\begin{equation}\n   \t\\emph{ER(E)}=\\mathbb{E_{S}}[\\dfrac{\\sum_{j=1}^{m}B(j)I(j)}{|RS|}] \\approx \\dfrac{\\sum_{j=1}^{m}\\mathbb{E_{S}}[B(j)]I(j)}{\\mathbb{E_{S}}[|RS|]} = \\dfrac{\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m S(j)} \n\\end{equation}\nFinally, we define the \\emph{approximated expected F1-Score} using the \\emph{expected precision} and the \\emph{approximated expected recall} as follows: \n\\begin{align}\n    \\emph{EF1(E)}  \\approx \\dfrac{2\\times EP\\times ER}{EP+ER} = \\dfrac{2\\times\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m I(j) + \\sum_{j=1}^m S(j)}\n\\end{align}\n  \n  \n%Conventional metrics are based on Boolean relevance label $B(j)$ instead of probabilistic score $S(j)$. To link standard precision with our expected precision,  The definition of standard precision $P(RS)$ is as follows:\n\n\n%Now, we  derive expectation of precision $P(RS)$ as follows:\n%\\begin{align}\n%\t\\mathbb{E_S}[P(E)] &= \\mathbb{E_S}[\\dfrac{\\sum_{j=1}^m B(j)I(j)}{\\sum_{j=1}^m I(j)}] = \\dfrac{\\sum_{j=1}^m %\\mathbb{E_S}[B(j)]I(j)}{\\sum_{j=1}^m I(j)} \\notag \\\\\n%    &= \\dfrac{\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m I(j)} = EP(E)\n   \t%\\mathbb{E_S}[R(RS)] &= \\dfrac{\\sum_{j=1}^m \\mathbb{E_S}[B(j)] I(j)}{\\sum_{j=1}^m \\mathbb{E_S}[B(j)]} = \\dfrac{\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m S(j)} = ER(RS)  \\\\\n    %\\mathbb{E_S}[F1(RS)] &= \\dfrac{2*\\sum_{j=1}^m \\mathbb{E_S}[B(j)]I(j)}{\\sum_{j=1}^m I(j) + \\sum_{j=1}^m \\mathbb{E_S}[B(j)]} \\notag \\\\\n    %&= \\dfrac{2*\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m I(j) + \\sum_{j=1}^m S(j)} = EF1(RS)\n%\\end{align}\n\n\n\n\n%\\begin{equation}\n%\\emph{\\ensuremath{EP(RS)}}=\\dfrac{{\\displaystyle \\sum_{j\\in RS}S(j)}}{|RS|} =  \\dfrac{\\sum_{j=1}^m S(j)I(j)}{\\sum_{j=1}^m I(j)} \n%\\end{equation}\n\n%Analogously, we define the  \\emph{expected recall} (ER) as follows:\n%\\begin{equation}\n%\\emph{\\ensuremath{ER(RS)}}=\\dfrac{{\\displaystyle \\sum_{j\\in RS}S(j)}}{|RE|} = \\dfrac{\\sum_{i=1}^m S(i)I(i)}{\\sum_{i=1}^m S(i)} = \\dfrac{\\sum_{i=1}^m S(i)I(i)}{C}  \n%\\end{equation}\n\n%\\noindent where $|RE|$ is the size of the entire relevant element set. Finally, we define the  \\emph{expected F1-Score} (EF1) as follows:\n\n%\\begin{equation}\n%\\emph{\\ensuremath{EF1(RS)}}=\\dfrac{2\\times EP\\times ER}{EP+ER} = \\dfrac{2*\\sum_{i=1}^m S(i)I(i)}{\\sum_{i=1}^m I(i) + C}\n%\\end{equation}\n\nIn Figure \\ref{fig:F1_vs_EF1}, we experimentally show that while EF1 is only an approximation of the true expectation, EF1 serves as an excellent surrogate for F1, which is our main concern when considering filter optimization.  That is, maximizing EF1 score with respect to a noisy classifier (noise decreases to 0 as $\\lambda \\to 1$) is strongly correlated with maximizing F1 score evaluated on the ground truth.   Specifically, while the EF1 and F1 scores are not perfectly calibrated along the diagonal, there is a linear correlation in that as the EF1 score increases for a scenario, the F1-score proportionally increases on average (as shown by the best fit linear regression in the plots).\n\n\n\n\\begin{figure}[H]\n\\begin{centering}\n\\par\\end{centering}\n\\begin{centering}\n\\includegraphics[width=8.5cm]{imgs/Enron_results/scatter_plot_EF1\\lyxdot vs\\lyxdot F1}\n\\par\\end{centering}\n\\caption{Scatter plot showing EF1-Score vs. F1-Score.}\n\\label{fig:F1_vs_EF1}\n\\end{figure}\n\n\n\n\n\n", "meta": {"hexsha": "f06c9ebd3736d4f4e0824908d45eb7dc0237fbe4", "size": 14927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/SIGIR2018/Framework.tex", "max_stars_repo_name": "D3Mlab/visir", "max_stars_repo_head_hexsha": "cd1860984dee8d7aba368857e734ad11c14124c8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-10T07:40:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-10T07:40:04.000Z", "max_issues_repo_path": "Documents/SIGIR2018/Framework.tex", "max_issues_repo_name": "D3Mlab/viz-ir", "max_issues_repo_head_hexsha": "cd1860984dee8d7aba368857e734ad11c14124c8", "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/SIGIR2018/Framework.tex", "max_forks_repo_name": "D3Mlab/viz-ir", "max_forks_repo_head_hexsha": "cd1860984dee8d7aba368857e734ad11c14124c8", "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": 82.9277777778, "max_line_length": 696, "alphanum_fraction": 0.7391974275, "num_tokens": 4150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7090191276365463, "lm_q1q2_score": 0.6160147981393379}}
{"text": "\\section{Homogeneous Systems}\r\n\\noindent\r\nHomogeneous systems of linear equations have the form\r\n\\begin{equation*}\r\n\t\\vec{x}' = A\\vec{x}\r\n\\end{equation*}\r\nWe'll see how to find solutions to these types of systems using the eigenvalue method. Finding solutions to these systems will allow us to find homogeneous solutions to heterogeneous systems of equations.\r\n\r\n% Eigenvalue Method\r\n\\input{./linearSystems/homogeneousSystems/eigenvalueMethod.tex}", "meta": {"hexsha": "e511b9d8cf422859a19598941a4c8805ff76c529", "size": 447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/homogeneousSystems.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/homogeneousSystems.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/homogeneousSystems.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": 44.7, "max_line_length": 205, "alphanum_fraction": 0.7897091723, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6159862780504274}}
{"text": "\\section{Coordinates, Differentials and Gradients}\r\n\\subsection{Differentials and First-Order Changes}\r\nRecall that if $f=f(u_1,\\ldots,u_n)$, then we write $\\mathrm df=(\\partial f/\\partial u_i)\\,\\mathrm du_i$ (the summation convention is being used).\r\nThose $\\mathrm du_i$ are formal objects called differential forms which are quite abstract geometrical notions that are way beyond the scope of this course.\r\nThese differential forms are taken as linearly independent the same way as vectors are.\r\nSimilarly, if $\\underline{x}=\\underline{x}(u_1,u_2,\\ldots,u_n)$, then $\\mathrm d\\underline{x}=(\\partial \\underline{x}/\\partial u_i)\\,\\mathrm du_i$.\r\n\\begin{example}\r\n    If $f(u,v,w)=u^2-v^2+e^w$, then $\\mathrm df=2u\\,\\mathrm du-2v\\,\\mathrm dv+e^w\\,\\mathrm dw$.\r\n    If $\\underline{x}=(u^2,v^2,w^2)^\\top$, then $\\mathrm d\\underline{x}=(2u\\,\\mathrm du,2v\\,\\mathrm dv,2w\\,\\mathrm dw)^\\top$.\r\n\\end{example}\r\nDifferential forms give a great tool to describe first-order changes.\r\nIf we perturb a multivariable function $f(u_1,\\ldots,u_n)$, then we can have\r\n$$f(u_1+\\epsilon_1,\\ldots,u_n+\\epsilon_n)=f(u_1,\\ldots,u_n)+\\frac{\\partial f}{\\partial u_i}\\epsilon_i+o(\\|\\underline{\\epsilon}\\|)$$\r\nWe can get the chain rule ``for free'' by using this notion.\r\nSuppose we change our coordinates by $v_i=v_i(u_1,\\ldots,u_n)$ and $F(u_1,\\ldots,u_n)=f(v_1,\\ldots,v_n)$, so\r\n$$\\frac{\\partial F}{\\partial u_i}\\,\\mathrm du_i=dF=df=\\frac{\\partial f}{\\partial v_j}\\,\\mathrm dv_j=\\frac{\\partial f}{\\partial v_j}\\frac{\\partial v_j}{\\partial u_i}\\,\\mathrm du_i$$\r\nTherefore\r\n\\begin{theorem}\r\n    $$\\frac{\\partial F}{\\partial u_i}=\\frac{\\partial f}{\\partial v_j}\\frac{\\partial v_j}{\\partial u_i}$$\r\n\\end{theorem}\r\nNote that the summation convention is implicitly used.\r\n\\subsection{Coordinates in Line Elements}\r\nSay $u,v$ are coordinates for $\\mathbb R^2$ by relating them to Cartesians in the form $x=x(u,v),y=y(u,v)$ such that these smooth functions can be inverted smoothly to give $u=u(x,y),v=v(x,y)$.\r\n\\begin{example}\r\n    Consider the polar coordinate $(r,\\theta)$ with the relationship $x=r\\cos\\theta,y=r\\sin\\theta$.\r\n    We can invert to have $r=\\sqrt{x^2+y^2},\\tan\\theta=x/y$.\r\n    \\footnote{This is not quite invertible at $(x,y)=(0,0)$.\r\n    Just saying.}\r\n\\end{example}\r\n\\begin{example}\r\n    1. The Cartesian coordinate in $\\mathbb R^2$ is $\\underline{x}=\\underline{x}(x,y)=(x,y)^\\top$.\r\n    \\footnote{For future reference, any column vector in this course are implicitly written as per the standard basis unless otherwise specified.}\r\n    Note that $\\underline{x}_x,\\underline{x}_y$ give the standard basis, so $\\mathrm d\\underline{x}=(\\mathrm dx,\\mathrm dy)^\\top$.\\\\\r\n    2. The polar coordinate defined above, $\\underline{x}=(r\\cos\\theta,r\\sin\\theta)^\\top$ has\r\n    $$\\underline{x}_r=(\\cos\\theta,\\sin\\theta),\\underline{x}_\\theta=(-r\\sin\\theta,r\\cos\\theta)$$\r\n    which becomes an orthonormal basis (which depends on $(r,\\theta)$) if we normalize.\r\n    So the line element has\r\n    $$\\mathrm d\\underline{x}=\\begin{pmatrix}\r\n        \\cos\\theta\\\\\\sin\\theta\r\n    \\end{pmatrix}\\,\\mathrm dr+r\\begin{pmatrix}\r\n        -\\sin\\theta\\\\\\cos\\theta\r\n    \\end{pmatrix}\\,\\mathrm d\\theta$$\r\n    So small change in the line element can result in a large change in the coordinate $\\mathrm d\\theta$.\r\n    The basis vectors above give the rotation basis.\r\n\\end{example}\r\n\\begin{definition}\r\n    We say $u,v,w$ are set of orthogonal curvilinear coordinates for $\\mathbb R^3$ if the unit vectors $\\underline{e}_u=\\underline{x}_u/\\|\\underline{x}_u\\|,\\underline{e}_v=\\underline{x}_v/\\|\\underline{x}_v\\|,\\underline{e}_w=\\underline{x}_w/\\|\\underline{x}_w\\|$ always forms a right-handed system of orthonormal vectors.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The scale factors are\r\n    $$h_{u}=\\left|\\frac{\\partial \\underline{x}}{\\partial u}\\right|,h_{v}=\\left|\\frac{\\partial \\underline{x}}{\\partial v}\\right|,h_{w}=\\left|\\frac{\\partial \\underline{x}}{\\partial w}\\right|$$\r\n\\end{definition}\r\nSo the factors are the scaling factors for a little change in the corresponding coordinates.\r\n\\begin{definition}\r\n    The cylindral polar coordinates are $(\\rho,\\phi,z)$ where\r\n    $$\\underline{x}=\\underline{x}(\\rho,\\phi,z)=(\\rho\\cos\\phi,\\rho\\sin\\phi,z)^\\top$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    The spherical polar coordinates are $(r,\\theta,\\phi)$ where\r\n    $$\\underline{x}=\\underline{x}(r,\\theta,\\phi)=(r\\cos\\phi\\sin\\theta, r\\sin\\phi\\sin\\theta,r\\cos\\theta)$$\r\n\\end{definition}\r\n\\subsection{The Gradient Operator}\r\nFor $f:\\mathbb R^3\\to\\mathbb R$, define the gradientof $f$, $\\nabla f$, by\r\n$$f(\\underline{x}+\\underline{h})=f(\\underline{x})+\\nabla f(\\underline{x})\\cdot\\underline{h}+o(\\underline{h})$$\r\n\\begin{definition}\r\n    The directional derivative of $f$ in direction $\\underline{v}$ by\r\n    $$D_{\\underline{v}}f(\\underline{x})=\\lim_{t\\to 0}\\frac{f(\\underline{x}+t\\underline{v})-f(\\underline{x})}{t}$$\r\n    So $f(\\underline{x}+t\\underline{v})=f(\\underline{x})+tD_{\\underline{v}}f(\\underline{x})+o(t)$.\r\n\\end{definition}\r\nSo if we let $\\underline{h}=t\\underline{v}$, we have\r\n$$f(\\underline{x}+t\\underline{v})=f(\\underline{x})+\\nabla f(\\underline{x})\\cdot t\\underline{v}+o(t)$$\r\nSo we have $\\nabla f(\\underline{x})\\cdot \\underline{v}=D_{\\underline{v}}f(\\underline{x})$.\r\nBy Cauchy-Schwartz, to maximize a dot product we will have to make the two vectors parallel, so\r\n\\begin{proposition}\r\n    $\\nabla f(\\underline{x})$ is the direction of greatest increase of $f$ at $\\underline{x}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Cauchy-Schwartz.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. $f(\\underline{x})=|\\underline{x}|^2/2$, so\r\n    $$f(\\underline{x}+\\underline{h})=(\\underline{x}+\\underline{h})\\cdot(\\underline{x}+\\underline{h})/2=f(\\underline{x})+\\underline{x}\\cdot\\underline{h}+o(\\underline{h})$$\r\n    Hence $\\nabla f(\\underline{x})=\\underline{x}$.\\\\\r\n    2. For generic curve $t\\mapsto \\underline{x}(t)$ and a function $F$, we want to evaluate $(F\\circ \\underline{x})^\\prime$, so\r\n    $$F(\\underline{x}(t+\\delta t))=F(\\underline{x}(t)+\\underline{\\delta x})=F(\\underline{x}(t))+\\nabla f(\\underline{x}(t))\\cdot\\underline{\\delta x}+o(\\underline{\\delta x})$$\r\n    where $\\underline{\\delta x}=\\underline{x}(t+\\delta t)-\\underline{x}(t)=t\\underline{x}^\\prime(t)+o(t)$.\r\n    So plugging it in we have\r\n    $$\\frac{\\mathrm dF}{\\mathrm dt}=\\nabla F(\\underline{x}(t))\\cdot \\underline{x}^\\prime(t)$$\r\n    3. Consider a surface in $\\mathbb R^3$ by $S=\\{\\underline{x}:f(\\underline{x})=0\\}$ where $f:\\mathbb R^3\\to\\mathbb R$.\r\n    Take curve $t\\mapsto \\underline{x}(t)$ such that $\\underline{x}\\in S$ for all $t$, then $0=\\underline{x}^\\prime(t)\\cdot\\nabla F(\\underline{x}(t))$, so $\\nabla F$ is perpendicular to the tangent to the curve.\r\n    Hence necessarily $\\nabla F$ is the normal to $S$.\r\n\\end{example}\r\n\\subsection{Computing the Gradient}\r\nFor general orthogonal curvilinear coordinate, it might be hard to calculate $\\nabla f$ since we do not usually know how to change the coordinates to accomodate the change $\\underline{h}$.\\\\\r\nBut it is easy in Cartesians.\r\nJust evaluating the directional derivatives at the basis vectors reveals:\r\n\\begin{proposition}\r\n    $$\\nabla f=\\begin{pmatrix}\r\n        \\partial f/\\partial x\\\\\r\n        \\partial f/\\partial y\\\\\r\n        \\partial f/\\partial z\r\n    \\end{pmatrix}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We have\r\n    $$(\\nabla f(\\underline{x}))_i=\\nabla f(\\underline{x})\\cdot\\underline{e_i}=D_{\\underline{e_i}}f(\\underline{x})$$\r\n    As desired.\r\n\\end{proof}\r\n\\begin{example}\r\n    Again we take $f(\\underline{x})=|\\underline{x}|^2/2$, then $(\\nabla f(\\underline{x}))_i=x_i$, so $\\nabla f(\\underline{x})=\\underline{x}$ as before.\r\n\\end{example}\r\nIn Cartesians, we know the line elements $\\mathrm d\\underline{x}=\\mathrm dx_i\\underline{e_i}$ which allows us to calculate easily.\r\nBut we have $\\mathrm df=D_{\\underline{e_i}}f\\,\\mathrm dx_i$ in any coordinate.\r\nSo immediately we have\r\n\\begin{proposition}\r\n    $\\mathrm df=\\nabla f\\cdot\\mathrm d\\underline{x}$\r\n\\end{proposition}\r\nwhich is coordinate independent.\r\n\\begin{proof}\r\n    Just calculate the right hand side.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $u,v,w$ be a set of curvilinear coordinates, then we have\r\n    $$\\nabla f=\\frac{1}{h_u}\\frac{\\partial f}{\\partial u}\\underline{e_u}+\\frac{1}{h_v}\\frac{\\partial f}{\\partial v}\\underline{e_v}+\\frac{1}{h_w}\\frac{\\partial f}{\\partial w}\\underline{e_w}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $\\mathrm df=\\nabla f\\cdot\\mathrm d\\underline{x}$ independent of coordinate.\r\n    We also know that $\\mathrm d\\underline{x}=h_u\\underline{e_u}\\,\\mathrm du+h_v\\underline{e_v}\\,\\mathrm dv+h_w\\underline{e_w}\\,\\mathrm dw$.\r\n    Write $\\nabla f=(\\nabla f)_u\\underline{e_u}+(\\nabla f)_v\\underline{e_v}+(\\nabla f)_w\\underline{e_w}$, then\r\n    $$\\nabla f\\cdot \\mathrm d\\underline{x}=h_u(\\nabla f)_u\\,\\mathrm du+h_v(\\nabla f)_v\\,\\mathrm dv+h_w(\\nabla f)_w\\,\\mathrm dw$$\r\n    In addition,\r\n    $$\\mathrm df=\\frac{\\partial f}{\\partial u}\\,\\mathrm du+\\frac{\\partial f}{\\partial v}\\,\\mathrm dv+\\frac{\\partial f}{\\partial w}\\,\\mathrm dw$$\r\n    But they are equal.\r\n    Since $\\mathrm du,\\mathrm dv,\\mathrm dw$ are linearly independent, we have\r\n    $$(\\nabla f)_u=\\frac{1}{h_u}\\frac{\\partial f}{\\partial u},(\\nabla f)_v=\\frac{1}{h_v}\\frac{\\partial f}{\\partial v},(\\nabla f)_w=\\frac{1}{h_w}\\frac{\\partial f}{\\partial w}$$\r\n    As desired.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. For cylindral coordinates $(\\rho,\\phi,z)$, we have\r\n    $$\\nabla f=\\frac{\\partial f}{\\partial\\rho}\\underline{e_\\rho}+\\frac{1}{\\rho}\\frac{\\partial f}{\\partial\\phi}\\underline{e_\\phi}+\\frac{\\partial f}{\\partial z}\\underline{e_z}$$\r\n    Then in the previous example where $f(\\underline{x})=|\\underline{x}|^2/2=(\\rho^2+z^2)/2\\implies\\nabla f=\\rho\\underline{e_\\rho}+z\\underline{e_z}=\\underline{x}$\\\\\r\n    2. For spherical coordinates $(r,\\theta,\\phi)$, we can do the same thing,\r\n    $$\\nabla f=\\frac{\\partial f}{\\partial r}\\underline{e_r}+\\frac{1}{r}\\frac{\\partial f}{\\partial\\theta}\\underline{e_\\theta}+\\frac{1}{r\\sin\\theta}\\frac{\\partial f}{\\partial \\phi}\\underline{e_\\phi}$$\r\n    Using the same example $f(\\underline{x})=r^2/2\\implies \\nabla f=r\\underline{e_r}=\\underline{x}$.\r\n\\end{example}\r\n\\begin{note}\r\n    We talked about the functions about position vectors under different coordinates,\r\n    $$f(\\underline{x})=f(\\underline{x}(x,y,z))=f(\\underline{x}(r,\\theta,\\phi))$$\r\n    So when we are talking about $f$, sometimes we are telling\r\n    $$\\tilde{f}(x,y,z)=f(\\underline{x}(x,y,z)),\\tilde{\\tilde{f}}(r,\\theta,\\rho)=f(\\underline{x}(r,\\theta,\\rho))$$\r\n    Or other coordinate we might find interesting.\r\n    We are actually talking about a pullback here which might be clear in a couple of years' time.\r\n\\end{note}", "meta": {"hexsha": "2ef9594b63660ea163902fdc2812ea86bb16da16", "size": 10679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/diff.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": "2/diff.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": "2/diff.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": 69.7973856209, "max_line_length": 320, "alphanum_fraction": 0.6776851765, "num_tokens": 3444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.6158913752787721}}
{"text": "\\problemname{Limbo: Part 1}\n\n\\noindent Dominick Cobb and Arthur are ``extractors\" who perform corporate espionage. Using experimental military technology that gives them access to shared dream worlds, they infiltrate their targets' subconscious to extract valuable information. Cobb and his entourage are contacted by a mysterious Japanese syndicate and given a seemingly impossible task: instead of extracting information, do the opposite -- plant a new idea in the target's mind.\\\\\n\nCobb notes that when using dream-sharing technology, time slows down by different factors depending on whose dream is being entered. Their target is to convince Cepshun, the heir of an energy conglomerate, to dissolve his father's company. Before Cobb starts, he notes that it would be important to figure out the passage of time to ensure that the operation can be completed smoothly.\\\\\n\nIn Cepshun's dreams, there are multiple different layers of consciousness, each of which controls a different area of Cepshun's dreams and memories. Cobb needs to move between several dreams to reach his destination dream -- some of them belonging to Cepshun, and some of them belonging to his entourage. The factor by which time slows down on each level is best visualized by all of the positive integers arranged in an infinite triangle, where the first row has the single integer $1$, the second row has the next two integers, the third row has the next three, and so forth. The first $4$ levels are depicted below:\n\n\\begin{verbatim}\n      1\n     2 3\n    4 5 6\n   7 8 9 10\n    etc...\n\\end{verbatim}\n\nThe initial time factor for reality is $1$. To enter the next dream level, Cobb can either descend left (into a dream by Cepshun) or right (into a dream by his entourage). For example, if he descends right, left, right, then he'll end up at dreams with time factors of $3$, then $5$, and finally $9$. Note the interesting property that for any pair of whole numbers $L$ and $R$, Cobb will always end up on the same time factor if he moves left $L$ times total and right $R$ times total, regardless of the order in which he makes the moves.\\\\\n\nCobb wants to know the slowness of time inside his target dream, which he can reach by descending left $L$ times and right $R$ times.\n\n\\section*{Input}\nThe first line of input consists of a single integer $T$ ($1 \\leq T \\leq 100$), the number of test cases.\\\\\n$T$ lines follow, each of which is a test case consisting of two space-separated integers, $L$ and $R$ ($0 \\leq L, R \\leq 10^{9}$), specifying the number of times Cobb needs to descend left and right, respectively.\n\n\\section*{Output}\nFor each test case, print, on a separate line, the factor by which time slows down in the target's dream at $(L, R)$.\\\\\nNote: the answer can be large, and may not necessarily fit in a 32-bit integer.\\\\\n", "meta": {"hexsha": "780c66ca9130ab47022da50658f8f1b903bfe36b", "size": 2816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "limbo1/problem_statement/problem.en.tex", "max_stars_repo_name": "csecutsc/utscode2", "max_stars_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-30T15:06:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T06:50:25.000Z", "max_issues_repo_path": "limbo1/problem_statement/problem.en.tex", "max_issues_repo_name": "csecutsc/utscode2", "max_issues_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "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": "limbo1/problem_statement/problem.en.tex", "max_forks_repo_name": "csecutsc/utscode2", "max_forks_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T04:10:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T04:10:51.000Z", "avg_line_length": 100.5714285714, "max_line_length": 618, "alphanum_fraction": 0.7631392045, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6158835151570027}}
{"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 XI 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\\subsection{Second Order Partial Derivatives}\n\nAlthough the order of second partial differentiation usually does not matter, sometimes the second order partial derivatives may not be equal. Differentiating $\\frac{\\partial f}{\\partial x}$ by $\\frac{\\partial}{\\partial y}$ results in $\\frac{\\partial^2f}{\\partial y \\partial x}$. If one differentiates in the reversed order, this yields $\\frac{\\partial^2f}{\\partial x \\partial y}$, where the order of partial differentiation is read from right to left.\\\\\n\n\\textit{Example Where $\\frac{\\partial^2f}{\\partial y \\partial x}=\\frac{\\partial^2f}{\\partial x \\partial y}$:}\n\n$$f(x,y)=x^3+x^2y^3-2y^2$$\n$$\\frac{\\partial f}{\\partial x}=3x^2+2xy^3$$\n$$\\frac{\\partial f}{\\partial y}=3x^2y^2-4y$$\n$$\\frac{\\partial^2f}{\\partial y \\partial x}=6xy^2$$\n$$\\frac{\\partial^2f}{\\partial x \\partial y}=6xy^2$$\n\\begin{center}$\\therefore \\frac{\\partial^2f}{\\partial x \\partial y}=\\frac{\\partial^2f}{\\partial y \\partial x}$\\footnote{In most cases, $\\frac{\\partial^2f}{\\partial x \\partial y}=\\frac{\\partial^2f}{\\partial y \\partial x}$}\\end{center}\n\n\\subsection{Clairaut's Theorem}\n\nIf $\\frac{\\partial^2f}{\\partial x \\partial y}$ and $\\frac{\\partial^2f}{\\partial y \\partial x}$ are continuous at point $(a, b)$, then $\\frac{\\partial^2f}{\\partial x \\partial y}=\\frac{\\partial^2f}{\\partial y \\partial x}$ at $(a, b)$\\footnote{This rule applies to any nth order derivative}\n\n\\subsection{Laplace's Differential Equations}\n\nNamed after Pierre Laplace, the partial differential equation looks like this:\n\n$$\\frac{\\partial^2u}{\\partial x^2} + \\frac{\\partial^2u}{\\partial y^2}=0$$\n\nAny function that fits the criteria is called a \\bold{harmonic function}\n\n\\subsection{Wave Equations}\n\nAny wave, whose displacement is defined by the function $u(x,t)$ must satisfy the wave equation:\n\n$$\\frac{\\partial^2u}{\\partial t^2}=a^2\\frac{\\partial^2u}{\\partial x^2}$$\n\n\\section{Tangent Plane Approximation and Total Differentials $-$ 14.4}\n\nThe tangent plane approximation function is given by:\n\n$$z-z_o=f_x(x_o,y_o)(x-x_o)+f_y(x_o,y_o)(y-y_o)$$\n\nThe definition of a total differential is:\n\n$$dz = \\frac{\\partial z}{\\partial x}dx + \\frac{\\partial z}{\\partial y}dy$$\n\n$dz$ represents the change in the plane approximation\n\n\\end{document}\n", "meta": {"hexsha": "e206927213085a0d856e21ebb7893e90be5579af", "size": 3660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture11.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/Lecture11.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/Lecture11.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.9696969697, "max_line_length": 454, "alphanum_fraction": 0.643442623, "num_tokens": 1074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.6158835136471729}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{renyi}\n\\section*{\\hspace*{-1.6cm} renyi}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nMeasure Renyi information.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nR = renyi(tfr)\nR = renyi(tfr,t)\nR = renyi(tfr,t,f)\nR = renyi(tfr,t,f,alpha)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty renyi} measures the Renyi information relative to a 2-D\n        density function {\\ty tfr} (which can be eventually a\n        time-frequency representation). Renyi information of order $\\alpha$\n        is defined as\\,:\n\\begin{eqnarray*}\nR_x^{\\alpha} = \\frac{1}{1-\\alpha}\\\nlog_2\\left\\{\\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty}\n\\mbox{tfr}_x^{\\alpha}(t,\\nu)\\ dt\\ d\\nu\\right\\}\n\\end{eqnarray*}\n\nThe result produced by this measure is expressed in {\\it bits} : if one\nelementary signal yields zero bit of information ($2^0$), then two well\nseparated elementary signals will yield one bit of information ($2^1$),\nfour well separated elementary signals will yield two bits of information\n($2^2$), and so on.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty tfr} & {\\ty (M,N)} 2-D density function (or mass function). Eventually\n             {\\ty tfr} can be a time-frequency representation, in which case\n             its first row must correspond to the lower frequencies\\\\\n        {\\ty t} & abscissa vector parametrizing the {\\ty tfr} matrix. {\\ty t} can be a\n            non-uniform sampled vector (eventually a time vector)\n                                                & {\\ty (1:N)}\\\\     \n        {\\ty f} & ordinate vector parametrizing the {\\ty tfr} matrix. {\\ty f} can be a\n            non-uniform sampled vector (eventually a frequency vector)\n                                                & {\\ty (1:M)}\\\\      \n        {\\ty alpha} & rank of the Renyi measure        & {\\ty 3}\\\\\n \\hline {\\ty R} & the alpha-rank Renyi measure (in bits if {\\ty tfr} is a time- \n            frequency matrix).\\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\n\\newpage\n\n{\\bf \\large \\sf Examples}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\n\\begin{verbatim}\n         s=atoms(64,[32,.25,16,1]); [tfr,t,f]=tfrsp(s); \n         R1=renyi(tfr,t,f,3) \n         ans =\n               0.9861\n\n         s=atoms(64,[16,.2,16,1;48,.3,16,1]); [tfr,t,f]=tfrsp(s); \n         R2=renyi(tfr,t,f,3) \n         ans =\n               1.9890\n         \n\\end{verbatim}\nWe can see that if {\\ttfamily R} is set to 0 for one elementary atom by\nsubtracting {\\ttfamily R1}, we obtain a result close to 1 bit for two atoms\n({\\ttfamily R2-R1}=1.0029).\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] W. Williams, M. Brown, A. Hero III, ``Uncertainty, information and\n   time-frequency distributions'', SPIE Advanced Signal Processing\n   Algorithms, Architectures and Implementations II, Vol. 1566,\n   pp. 144-156, 1991.\n\\end{minipage}\n\n\n", "meta": {"hexsha": "cc288b20d8b0970a4f6745d46f049d251367e291", "size": 3339, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/renyi.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/renyi.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/renyi.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 30.3545454545, "max_line_length": 86, "alphanum_fraction": 0.616951183, "num_tokens": 1110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6158834994688855}}
{"text": "\n\\subsection{Chapter 2}\n\n\\begin{p}%{55}\n{Given a manifold $M$, define charts for $TM$ starting from charts $\\varphi_\\alpha:U_\\alpha\\rightarrow \\R^n$ as follows. Let $V_\\alpha$ be the subset of $TM$ given by $V_\\alpha=\\{v\\in TM:\\pi(v)\\in U_\\alpha\\}$. Show that every point in $TM$ lies in some set $V_\\alpha$. Define\nmaps $\\psi_\\alpha:V_\\alpha\\rightarrow \\R^n\\times \\R^n$ by $\\psi_\\alpha(v)=(\\varphi_\\alpha(\\pi(v)),(\\varphi_\\alpha)_*v)$, where we think of $(\\varphi_\\alpha)_*v$, which is really a tangent vector to $\\R^n$, as\na vector in $\\R^n$. Give $TM$ the topology in which open sets are the unions of sets of the form $O\\subset V_\\alpha$ such that $\\psi_\\alpha(O)\\subset \\R^n\\times \\R^n$ is open. Check that $\\psi_\\alpha$ are charts, so that $TM$ is a manifold. Check that $\\pi:TM\\rightarrow M$ is smooth.}\n\\end{p}\n{Every point $v$ in $TM$ is in some $V_\\alpha$ since $v$ is the tangent vector at some point $p$ (as given by $p=\\pi(v)$), and every point $p$ is in some set $U_\\alpha$. To establish that $\\psi_\\alpha$ are charts and $TM$ is a smooth manifold, note that $\\varphi_\\alpha$ is smooth and so is the pushforward, so $\\psi_\\alpha$ is smooth, too. Transition functions\nfrom one chart to another are likewise smooth, since these are compositions of smooth $\\psi_\\alpha$ and $\\psi^{-1}_\\beta$ which overlap on some open set. The projection $\\pi$ is smooth because we can define \nthe $\\R^{2n}\\rightarrow \\R^n$ version of the map by just ignoring the last $n$ coordinates. But this map is just $\\varphi_\\alpha\\circ\\pi\\circ\\psi_\\alpha^{-1}$, so $\\pi$ must be smooth.}\n\n\\begin{p}%{56}\n{Given bundles $\\pi:E\\rightarrow M$ and $\\pi':E'\\rightarrow M'$, show that the maps $\\psi:E\\rightarrow E'$ and $\\phi:M\\rightarrow M'$ are a bundle morphism iff $\\pi'\\circ\\psi=\\phi\\circ\\pi$. Show that\n$\\psi$ uniquely determines $\\phi$.}\n\\end{p}\n{Bundle morphisms respect the bundle structure, i.e.~the split into fiber and base. If $\\pi'\\circ\\psi=\\phi\\circ\\pi$, then the fiber in $E$ over $p$ must be mapped to the fiber in $E'$ over $p'=\\phi(p)$, or else the relationship would not hold. Conversely, if the fibers are mapped to the appropriate base\npoints, then it doesn't matter if we do the tangent space map first or second.}\n\n\\begin{p}%{57}\n{Check that $\\phi_*$ is smooth when we make the tangent bundle into a manifold as in the previous exercise.}\n\\end{p}\n{(typo on the ``previous'' exercise?) A map between two manifolds is smooth if it takes smooth functions on the first manifold to smooth functions on the second. Points in the manifold in \nquestion are vectors $v$, so functions of them are 1-forms $\\om$. Using an exact 1-form $df$ we have\n$df(v)=v(f)$. When $v=\\phi_*(u)$ we get $df(\\phi_*(u))=\\phi_*(u)(f)=u(\\phi^*f))=u(f\\circ\\phi)$, which is \nsmooth.}\n\n\\begin{p}%{58}\n{Show that if $\\phi:M\\rightarrow M'$ is a diffeomorphism, then $\\phi_*:TM\\rightarrow TM'$ is a bundle isomorphism.}\n\\end{p}\n{When $\\phi$ is an isomorphism, the tangent spaces $T_pM$ and $T_\\phi(p)M'$ are \nisomorphic, since the smooth functions on $M$ get mapped isomorphically to smooth functions on $M'$. Since\nthe pushforward is smooth and linear, it's an isomorphism of the tangent spaces.}\n\n\\begin{p}%{59}\n{Show that for any manifold $M$, the tangent bundle $\\pi:TM\\rightarrow M$ is locally trivial.}\n\\end{p}\n{The induced charts $\\psi_\\alpha$ give us a trivialization, with $\\R^n$ as the standard fiber.}\n\n\\begin{p}%{60}\n{Describe a bundle that is not locally trivial.}\n\\end{p}\n{}\n\n\\begin{p}%{61}\n{Check that the tangent bundle of a manifold is a vector bundle.}\n\\end{p}\n{To be a vector bundle, the \nlocal trivialization must be fiberwise linear. The standard fiber for a tangent bundle is $\\R^n$, and the  \ntrivialization is linear because it is just the pushforward (exercise 17, part I).}\n\n\\begin{p}%{62}\n{A 1-dimensional bundle is called a (real or complex) line bundle. Check that the M\\\"obius strip is a real line bundle if we regard the standard fiber as being $\\R$.}\n\\end{p}\n{Locally the M\\\"obius strip is just $\\R^2$, so the trivialization is linear.}\n\n\\begin{p}%{63}\n{Show that if a vector bundle morphism is a diffeomorphism, its inverse is a vector bundle morphism.}\n\\end{p}\n{}\n\n\\begin{p}%{64}\n{Show that a (smooth (typo?)) section of the tangent bundle is a vector field.}\n\\end{p}\n{A section of the tangent bundle\nassigns to each point in the base space vector in its tangent space. From this we obtain a \nvector field from the pointwise action of the tangent vectors. The output of the vector field is again a \nsmooth function since the\nsection is smooth; the directional derivative (function value) changes smoothly from point to point since\nthe tangent vectors do.}\n\n\\begin{p}%{65}\n{Show that $\\Gamma(E)$ is a module over $C^\\infty(M)$.}\n\\end{p}\n{The first two conditions are defined \nin the text. The other two are simply: $(fg)s=f(gs)$ since $(fg)s:=((fg)s)(p)=(fg)(p)s(p)=f(p)g(p)s(p)=f(gs)(p)$ for\n$f,g\\in C^\\infty (M)$. }\n\n\\begin{p}%{66}\n{Show that every section of the M\\\"obius strip (viewed as a real line bundle over $S^1$) vanishes somewhere. Conclude that hte M\\\"obius strip hos no basis of sections, hence is not trivial.}\n\\end{p}\n{can't cut the M\\\"obius strip and make a cylinder unless there's a zero somewhere.}\n\n\\begin{p}%{67}\n{Show that the dual vector bundle really is a vector bundle. Also, show that given a basis\nof section $e_i$ of a vector bundle $E$, there is a unique dual basis $e^i$ of sections of $E^*$ such that for each point $p\\in M$, $e^i(p)$ is the basis of $E^*_p$ dual to the basis $e_i(p)$ of $E_p$.}\n\\end{p}\n{The basic idea, I think, is that since $E|_U$ is locally equivalent to \n$U\\times \\mathbb{R}^n$ for any open set $U$, then since $E^*$ just replaces \n$E_p$ with $E^*_p$ everywhere, \n$E^*|_U$ must be locally equivalent to $U\\times (\\mathbb{R}^n)^*=U\\times \\mathbb{R}^n$. \nThis makes $E^*$ a manifold. To see that it is a vector bundle, just use the canonical dual basis when \nmapping $E_p^*$ to $\\mathbb{R}^n$. \n}\n\n\\begin{p}%{68}\n{Show that if $s$ is a section of a vector bundle $E$ over $M$ and $\\lambda$ is a \nsection of $E^*$, there is a smooth function $\\lambda(s)$ on $M$ given by \n\\[\\lambda(s)(p)=\\lambda(p)(s(p))\\] for all $p\\in M$. Show that $\\lambda(s)$ depends $C^\\infty(M)$-linearly on $\\lambda$ and $s$.}\n\\end{p}\n{Locally, the vector bundles are trivial, so locally the section\nlooks like a function from $M$ to $V$ ($V^*$), where $E_p=\\{p\\}\\times V$. We can then \napply $\\lambda$ to $s$ pointwise to obtain the function. It is smooth since the sections are smooth. \n$\\lambda(s)$ is linear over $\\lambda$ and $s$ since the action of the cotangent vector on the tangent vector is linear in each argument. We get the $C^\\infty(M)$ part since the action is pointwise and smooth.}\n\n\\begin{p}%{69}\n{Show that a section of the cotangent bundle is the same as a 1-form.}\n\\end{p}\n{A 1-form is a\nmap taking vector fields to functions on the manifold. Interpreting vector fields as sections of\nthe tangent bundle, means that a 1-form is a map from sections of $TM$ to functions on $M$. By the\nprevious exercise we see that a section of $T^*M$ is just such a map, so a section of the cotangent\nbundle is a 1-form.}\n\n\\setcounter{p}{76}\n\n\\begin{p}%{77}\n{Show that the conditions $g_{\\alpha\\alpha}=1$ and $g_{\\alpha\\beta}g_{\\beta\\gamma}g_{\\gamma\\alpha}=1$ imply $g_{\\beta\\alpha}^{-1}=g_{\\alpha\\beta}$. Show that for any sequences $\\alpha_1,\\dots,\\alpha_n$ and $\\beta_1,\\dots,\\beta_m$ with $\\alpha_1=\\beta_1$ and $\\alpha_n=\\beta_m$, they \nimply $$g_{\\alpha_1\\alpha_2}\\cdots g_{\\alpha_{n-1}\\alpha_n}=g_{\\beta_1\\beta_2}\\cdots g_{\\beta_{m-1}\\beta_m}.$$\n}\n\\end{p}\n{Letting $\\gamma=\\alpha$ in the cocyle condition yields $g_{\\alpha\\beta}g_{\\beta\\alpha}g_{\\alpha\\alpha}=1$. Then using $g_{\\alpha\\alpha}=1$ we obtain\n$g_{\\alpha\\beta}g_{\\beta\\alpha}=1$, so $g_{\\beta\\alpha}^{-1}=g_{\\alpha\\beta}$. Now\nobserve that $g_{\\alpha_1\\alpha_{n-1}}g_{\\alpha_{n-1}\\alpha_n}=g_{\\alpha_1\\alpha_n}$ since\nmultiplying by the inverse of the righthandside gives $g_{\\alpha_1\\alpha_{n-1}}g_{\\alpha_{n-1}\\alpha_n}g_{\\alpha_n\\alpha_1}=1$. By induction we can expand this expression to\n$g_{\\alpha_1\\alpha_2}\\cdots g_{\\alpha_{n-1}\\alpha_n}$. Similarly, we can start with\n$g_{\\beta_1\\beta_{m-1}}g_{\\alpha_{m-1}\\beta_m}=g_{\\alpha_1\\alpha_n}$ and obtain $g_{\\beta_1\\beta_2}\\cdots g_{\\beta_{m-1}\\beta_m}$, so they must be equal.}\n\n\n\\newpage\n\\includepdf[pages=-]{src/gfkg223.pdf}\n\\includepdf[pages=-]{src/gfkg224.pdf}\n\\includepdf[pages=-]{src/gfkg225.pdf}\n\n\n\n\\setcounter{p}{85}\n\\begin{p}%86\n{Using a local trivialization of $E$ over $U_\\alpha\\subseteq M$ write the $G$-connection $D$ as the standard flat connection plus a vector potential: $D=D^0+A$. Show that the vector potential $A'$ for $D'$ is given in local coordinates by $$A'_\\mu=gA_\\mu g^{-1}+g\\partial\\mu g^{-1}.$$ Show that\nsince $A_\\mu$ lives in $\\mathfrak{g}$, so does $A_\\mu'$. (Hint: show that if $A_\\mu$ lives in $\\mathfrak{g}$ and $g\\in G$, then $g A_\\mu g^{-1}$ lives in $\\mathfrak{g}$. Also show that if \n$g\\in\\mathcal{G}$, $g\\partial_\\mu g^{-1}$ lives in $\\mathfrak{g}$.) Conclude that $D'$ is a $G$-connection.}\n\\end{p}\n{$D'_\\mu(s)=gD_\\mu(g^{-1}s)=gD_\\mu^0(g^{-1}s)+gA_\\mu(g^{-1}s)$. The local trivialization \nmeans that we have chosen a basis of sections $\\{e_j\\}$ such that $D_\\mu^0(s^je_j)=(\\partial_\\mu s^j)e_j$. The action of $g$ can be represented by $g=\\rho(g)^j_k e_j\\otimes e^k$ and the corresponding\nflat covariant derivative is just $D_\\mu^0(g)=(\\partial_\\mu \\rho(g)^j_k)e_j\\otimes e^k$. Inserting these expressions into $D'_\\mu(s)$ gives \n\\begin{align}\nD'_\\mu(s)&=g D_\\mu(g^{-1}s)=gD_\\mu^0(g^{-1}s)+gA_\\mu(g^{-1}s)\\\\\n&=g\\left(\\partial_\\mu \\rho(g^{-1})^k_j s^j\\right) e_k+gA_\\mu g^{-1}s\n=D_\\mu^0(s)+g\\left(\\partial_\\mu \\rho(g^{-1})^k_j \\right)s^j e_k+gA_\\mu g^{-1}s\\\\\n&=D_\\mu^0(s)+gD_\\mu^0(g^{-1})s+gA_\\mu g^{-1}s=D_\\mu^0(s)+(g\\partial_\\mu g^{-1})s+gA_\\mu g^{-1}s,\n\\end{align}\nwhere in the last equality we've abuse notation somewhat. Hence the vector potential has changed\naccording to the prescribed form. For $g\\in\\mathcal{G}$, $g\\partial_\\mu g^{-1}$ lives in $\\mathfrak{g}$ for the following reason. Really this expression is $\\rho(g)^j_\\ell \\partial_\\mu \\rho(g^{-1})^{\\ell}_k(x^\\nu)$ and $\\rho(g)(x^\\nu)=\\exp\\left(-c_j(x^\\nu)h^j\\right)$, where\n$h^j$ is a generator set for the Lie algebra $\\mathfrak{g}$. Thus, $g\\partial_\\mu g^{-1}=(\\partial_\\mu c_j(x^\\nu))g h^jg^{-1}$, which is\nan element of $\\mathfrak{g}$. \n }\n\n \\begin{p}%87\n \\end{p}\n\n \\newpage\n\n\\includepdf[pages=-]{src/gfkg226.pdf}\n\n", "meta": {"hexsha": "0a2f505ba8bf56d3f4423fe1efec05ad45973c96", "size": 10479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/II2.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/II2.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/II2.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": 63.5090909091, "max_line_length": 361, "alphanum_fraction": 0.6949136368, "num_tokens": 3494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799253, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.6158834949393956}}
{"text": "\\documentclass[a4paper,12pt]{extarticle}\n\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage{xcolor}\n\n\\renewcommand\\familydefault{\\sfdefault}\n\\usepackage{tgheros}\n\\usepackage[defaultmono]{droidmono}\n\n\\usepackage{amsmath,amssymb,amsthm,textcomp}\n\\usepackage{enumerate}\n\\usepackage{multicol}\n\\usepackage{tikz}\n\n\\usepackage{geometry}\n\\geometry{left=25mm,right=25mm,%\nbindingoffset=0mm, top=20mm,bottom=20mm}\n\n\n\\linespread{1.3}\n\n\\newcommand{\\linia}{\\rule{\\linewidth}{0.5pt}}\n\n% custom theorems if needed\n\\newtheoremstyle{mytheor}\n    {1ex}{1ex}{\\normalfont}{0pt}{\\scshape}{.}{1ex}\n    {{\\thmname{#1 }}{\\thmnumber{#2}}{\\thmnote{ (#3)}}}\n\n\\theoremstyle{mytheor}\n\\newtheorem{defi}{Definition}\n\n% my own titles\n\\makeatletter\n\\renewcommand{\\maketitle}{\n\\begin{center}\n\\vspace{2ex}\n{\\huge \\textsc{\\@title}}\n\\vspace{1ex}\n\\\\\n\\linia\\\\\n\\@author \\hfill \\@date\n\\vspace{4ex}\n\\end{center}\n}\n\\makeatother\n%%%\n\n% custom footers and headers\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\lhead{}\n\\chead{}\n\\rhead{}\n\\lfoot{Intro to Kalman Filter}\n\\cfoot{}\n\\rfoot{Page \\thepage}\n\\renewcommand{\\headrulewidth}{0pt}\n\\renewcommand{\\footrulewidth}{0pt}\n%\n\n% code listing settings\n\\usepackage{listings}\n\\lstset{\n    language=Python,\n    basicstyle=\\ttfamily\\small,\n    aboveskip={1.0\\baselineskip},\n    belowskip={1.0\\baselineskip},\n    columns=fixed,\n    extendedchars=true,\n    breaklines=true,\n    tabsize=4,\n    prebreak=\\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\hookleftarrow}},\n    frame=lines,\n    showtabs=false,\n    showspaces=false,\n    showstringspaces=false,\n    keywordstyle=\\color[rgb]{0.627,0.126,0.941},\n    commentstyle=\\color[rgb]{0.133,0.545,0.133},\n    stringstyle=\\color[rgb]{01,0,0},\n    numbers=left,\n    numberstyle=\\small,\n    stepnumber=1,\n    numbersep=10pt,\n    captionpos=t,\n    mathescape=true,\n    escapeinside={\\%*}{*)}\n}\n\n%%%----------%%%----------%%%----------%%%----------%%%\n\n\\begin{document}\n\n\\title{ Kalman Filter }\n\n\\author{ Dhruv Patel }\n\n\\maketitle\n\n\\section*{ What is Kalman Filter ? }\n\n\nKalman Filter or simply \\emph{KF}, is one of the many techniques to implement Bayes Filters. It was invented by Swerling (1958) and Kalman (1960) as a technique for filtering and prediction in \\emph{linear Gaussian Systems}. The Kalman Filter implements belief computation for continuous states. It is not applicable to discrete or hybrid state spaces.\n\n% Pseudo Code - Kalman Filter\n\n\\begin{lstlisting}\nAlgorithm Kalman Filter($\\mu_{t-1}, \\Sigma_{t-1}, u_t, z_t$):\n\t# Prediction Step : ref. as Motion Model\n\t$\\overline{\\mu}_t =  A_t * \\mu_{t-1}  + B_t * u_t$\n\t$\\overline{\\Sigma}_t = A_t * \\Sigma_{t-1} * A_t^T  +  R_t$\n\t# Update Step : ref. as Measurement Model\n\t$K_t = \\overline{\\Sigma}_t * C_t^T * (C_t * \\Sigma_t * C_t^T  +  Q_t)^{-1}$\n\t$\\mu_t = \\overline{\\mu}_t + K_t * (z_t - C_t * \\overline{\\mu}_t)$\n\t$\\Sigma_t = ( I - K_t * C_t ) * \\overline{\\Sigma}_t$\n\treturn $\\mu_t , \\Sigma_t$\n\t\n\\end{lstlisting}\n\n\nThe Kalman Filter represents beliefs by the moments parameterization : At time $t$, the belief $bel(x_t)$is represented by the mean $\\mu_t$ and the covariance $\\Sigma_t$. The input of the Kalman filter is the belief at time $t-1$, represented by $\\mu_{t-1}$ and $\\Sigma_{t-1}$. To update these parameters, Kalman filters require the control $u_t$ and the measurement $z_t$. The output is the belief at time $t$, represented by $\\mu_t$ and $\\Sigma_t$. This predicted belief $\\mu_t$ and $\\Sigma_t$ is calculated representing the belief $\\overline{bel}(x_t)$ one time step later, but before incorporating the measurement $z_t$. This belief is obtained by incorporating the control $u_t$. The update of the covariance considers the fact that states depend on previous states through the linear matrix $A_t$. This matrix is multiplied twice into the covariance, since the covariance is a quadratic matrix.\n\n\nThe belief $\\overline{bel}(x_t)$ is subsequently transformed into the desired belief $bel(x_t)$, by incorporating the measurement $z_t$. The variable $K_t$, is called \\emph{Kalman Gain}. It specifies the degree to which the measurement is incorporated into the new state estimate. The key concept here is the \\emph{innovation}, which is the difference between the actual measurement $z_t$ and the expected measurement $C_t$. Finally, the new covariance of the posterior belief is calculated, adjusting for the information gain resulting from the measurement.\n\n\nThe \\emph{Kalman Filter} is computationally quite efficient. In many applications - such as the robot mapping applications - the measurement space is much lower dimensional than the state space, and the update is dominated by the $O(n^2)$ operations.\n\n\n\\section*{ A brief explanation about the variables }\n\nThe state transition probability $ p( x_t | u_t, x_{t-1} ) $ must be a linear function in its arguments with added Gaussian noise. This is expressed by the following equation : \n\\begin{equation} \\label{eq1}\nx_t =  A_t * x_{t-1}  +  B_t * u_t  +  \\varepsilon_t\n\\end{equation}\nHere, $x_t$ and $x_{t-1}$ are state vectors, and $u_t$ is the control vector at time $t$. These vectors are column vectors. They are of the form\n\\begin{equation}\nx_t = \\left( \\begin{array}{c} x_{1,t} \\\\ x_{2,t} \\\\ . \\\\ . \\\\  x_{n,t} \\end{array} \\right)\n\\mbox{~and~}\nu_t = \\left( \\begin{array}{c} u_{1,t} \\\\ u_{t,2} \\\\ . \\\\ . \\\\ u_{m,t} \\end{array} \\right)\n\\end{equation}\n$A_t$ and $B_t$ are matrices. $A_t$ is a square matrix of size $ n \\times n $, where $n$ is the dimension of the state vector $x_t$. $B_t$ is of size $ n \\times m$, with $m$ being the dimension of the control vector $u_t$. By multiplying the state and control vector with the matrices $A_t$ and $B_t$, respectively, the state transition function becomes \\emph{linear} in its arguments. Thus, Kalman Filters assume linear system dynamics.\n\nThe random variable $\\varepsilon_t$ in (1) is a Gaussian random vector that models the uncertainty introduced by the state transition. It is of the same dimension as the state vector. It has zero mean, and its covariance will be denoted by $R_t$. A state transition probability of the form (1) is called a \\emph{linear Gaussian}, to reflect the fact that it is linear in its arguments with additive Gaussian noise. \n\nThe measurement probability $ p(z_t | x_t ) $ must also be \\emph{linear} in its arguments, with added Gaussian noise :\n\\begin{equation}\nz_t = C_t * x_t + \\delta_t\n\\end{equation}\nHere, $C_t$ is a matrix of size $k \\times n$, where $k$ is the dimension of the measurement vector $z_t$. The vector $\\delta_t$ describes the measurement noise. The distribution of $\\delta_t$ is a multivariate Gaussian with zero mean and covariance $Q_t$.\n\n\n\\vfill\n\n\\section*{ Given Problem }\n\nHere, we have been given a simple target tracking problem in one-dimensional space. The state contains three components : position (one-dimensional), velocity and acceleration and it can be expressed as below.\n\\begin{equation}\nx = \\left( \\begin{array}{c} x_k \\\\ \\dot{x}_k \\\\ \\ddot{x}_k \\end{array} \\right)\n\\end{equation}\nwhere, $x_k$ is the position, $\\dot{x}_k$ is the velocity and $\\ddot{x}_k$ is the acceleration at time '$k$'. $T$ is the size of sample time step.\n\nThe process equation for target motion is given by the following kinematic equation:\n\\begin{equation}\n\\left[ \\begin{array}{c} x_k \\\\ \\dot{x}_k \\\\ \\ddot{x}_k \\end{array} \\right] = \n\\left[ \\begin{array}{ccc} 1 & T & \\frac1{2}T^2 \\\\ 0 & 1 & T \\\\ 0 & 0 & 1  \\end{array} \\right] * \\left[ \\begin{array}{c} x_{k-1} \\\\ \\dot{x}{k-1} \\\\ \\ddot{x}{k-1} \\end{array} \\right] + \\upsilon_{k-1}\n\\end{equation}\nand \n\\begin{equation}\n\\upsilon_{k-1} \\sim N(0, Q)\n\\end{equation}\nwhere,\n$ Q = \\sigma^2 * \\left[ \\begin{array}{ccc} \\frac{T^4}{4} & \\frac{T^3}{2} & \\frac{T^2}{2} \\\\ \\frac{T^3}{2} & 2T^3 & T^2 \\\\ \\frac{T^2}{2} & T^2 & T^2  \\end{array} \\right] $, $\\sigma$ represents intensity of Gaussian noise.\n\nTargets are usually tracked with the help of sensors such as radars or lidars which provide the position of the target. Hence, the measurement equation can be written as:\n\\begin{equation}\ny_k = \n\\left[ \\begin{array}{ccc} 1 & 0 & 0 \\end{array} \\right] * \\left[ \\begin{array}{c} x_k \\\\ \\dot{x}_k \\\\ \\ddot{x}_k \\end{array} \\right] + \\omega\n\\end{equation}\nwhere, $y_k$ is the measurement and $\\omega \\sim N(0, R) $ is the measurement noise. \n\n\\hfill\n\nFor the given problem, obtain the estimate of its state over a period of $ 20 ~sec $. Assume time step $ T = 0.1 ~sec $. \n\n\n\n\n\n\n\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "016a2c8b37563f7f5f40c6b2ee814006bbfedc65", "size": 8432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/Kalman_Filter.tex", "max_stars_repo_name": "ruvate/kalman.filter", "max_stars_repo_head_hexsha": "37ee3a45308c8de89e040ad2130fe737cdcaa327", "max_stars_repo_licenses": ["MIT"], "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/Kalman_Filter.tex", "max_issues_repo_name": "ruvate/kalman.filter", "max_issues_repo_head_hexsha": "37ee3a45308c8de89e040ad2130fe737cdcaa327", "max_issues_repo_licenses": ["MIT"], "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/Kalman_Filter.tex", "max_forks_repo_name": "ruvate/kalman.filter", "max_forks_repo_head_hexsha": "37ee3a45308c8de89e040ad2130fe737cdcaa327", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-29T02:51:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-29T02:51:03.000Z", "avg_line_length": 42.5858585859, "max_line_length": 900, "alphanum_fraction": 0.7056451613, "num_tokens": 2587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6157964063459351}}
{"text": "\\chapter{Fourier Transform}\n\\begin{enumerate}\n\t\\item Let $F(k)$ is the Fourier exponential transform of $f(x)$ and $G(k)$ be the Fourier Transform of $g(x)=f(x+a)$. Then $G(k)$ is given by\n\t(Use the Fourier integral $F(k)=\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{+\\infty} f(x) e^{i k x} d x$ )\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$e^{i a k} f(k)$\n\t\t\\task[\\textbf{b.}]$e^{-i a k} F(-k)$\n\t\t\\task[\\textbf{c.}] $e^{-i a k} F(k)$\n\t\t\\task[\\textbf{d.}] $e^{-i a k} f(k)$\n\t\\end{tasks}\n\t\\item The value of a function is given by $f(x)=\\left\\{\\begin{array}{cc}1 & 0<x<1 \\\\ -1 & 1<x<2 \\\\ 0 & x>2\\end{array}\\right.$, the Fourier cosine transform of $f(x)$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{2 \\sin \\omega+\\sin 2 \\omega}{\\omega}\\right)$\n\t\t\\task[\\textbf{b.}]$\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{2 \\sin \\omega-\\sin 2 \\omega}{\\omega}\\right)$\n\t\t\\task[\\textbf{c.}]$\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{\\sin \\omega-\\sin 2 \\omega}{\\omega}\\right)$\n\t\t\\task[\\textbf{d.}] $\\sqrt{\\frac{2}{\\pi}}\\left(\\frac{2 \\sin \\omega}{\\omega}\\right)$\n\t\\end{tasks}\n\t\\item Consider the function $\\delta_{n}(x)=\\frac{n}{\\sqrt{\\pi}} \\exp \\left(-n^{2} x^{2}\\right)$. For $n \\rightarrow \\infty$ The Fourier transform of the function is given by\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\delta(x)=\\int_{-\\infty}^{+\\infty} e^{-i k x} d k$\n\t\t\\task[\\textbf{b.}]$\\delta(x)=\\frac{1}{2 \\pi} \\int_{-\\infty}^{+\\infty} e^{i k x} d k$\n\t\t\\task[\\textbf{c.}]$\\delta(x)=\\frac{1}{2 \\pi} \\int_{-\\infty}^{+\\infty} e^{-i k x} d k$\n\t\t\\task[\\textbf{d.}] 0\n\t\\end{tasks}\n\t\\item For the function $f(t)=\\delta(t-x)$, the Fourier cosine integral is defined as $g_{c}(\\omega)=\\sqrt{\\frac{2}{\\pi}} \\int_{0}^{\\infty} f(t) \\cos \\omega t d t$. Its Fourier transform is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\sqrt{\\frac{2}{\\pi}} \\cos \\omega x$\n\t\t\\task[\\textbf{b.}]$\\sqrt{\\frac{2}{\\pi}}$\n\t\t\\task[\\textbf{c.}]$\\sqrt{\\frac{2}{\\pi}} \\sin \\omega x$\n\t\t\\task[\\textbf{d.}] $i \\sqrt{\\frac{2}{\\pi}}$\n\t\\end{tasks}\n\t\\item Inverse cosine transform of $g_{c}(\\omega)=\\sqrt{\\frac{2}{\\pi}} \\cos \\omega x$ is:\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\delta(t+x)$\n\t\t\\task[\\textbf{b.}]$\\delta(t-x)$\n\t\t\\task[\\textbf{c.}]$\\delta(t-x)(t+x)$\n\t\t\\task[\\textbf{d.}] $\\delta^{2}(x-t)(x+t)$\n\t\\end{tasks}\n\t\\item $f(t)=\\frac{\\hbar}{2 \\pi i} \\int_{-\\infty}^{+\\infty} \\frac{e^{-i \\omega t} d \\omega}{\\left(E_{0}-i \\Gamma / 2-\\hbar \\omega\\right)}$ The value of $f(t)$ is given by\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}](a) $f(t)= \\begin{cases}e^{-\\Gamma t / 2 \\hbar} e^{-i E_{0} t / \\hbar} & , t>0 \\\\ 0 & , t<0\\end{cases}$\n\t\t\\task[\\textbf{b.}]$f(t)= \\begin{cases}e^{\\sqrt{1 / 2 \\hbar}} e^{-1 E_{0} t / \\hbar} & , t>0 \\\\ 0 & , t<0\\end{cases}$\n\t\t\\task[\\textbf{c.}]$f(t)= \\begin{cases}e^{-\\Gamma t / 2 \\hbar} e^{-i E_{0} t / \\hbar} & , t>0 \\\\ 0 & , t<0\\end{cases}$\n\t\t\\task[\\textbf{d.}] $f(t)= \\begin{cases}e^{-\\Gamma t / 2 h} e^{-i E_{0} t / h} & , t>0 \\\\ e^{-i E_{0} t / \\hbar} & , t<0\\end{cases}$\n\t\\end{tasks}\n\t\\item The Fourier transform of function $h(t)=t e^{-t^{2}}$ is \n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $j \\pi f e^{-\\pi^{2} f^{2}}$\n\t\t\\task[\\textbf{b.}]$-j \\pi f e^{-\\pi^{2} f^{2}}$\n\t\t\\task[\\textbf{c.}]$j \\pi f e^{-\\pi^{2} f^{2} / 4}$\n\t\t\\task[\\textbf{d.}] $-j \\pi f e^{-\\pi^{2} f^{2} / 4}$\n\t\\end{tasks}\n\t\\item The graph of a real periodic function $f(x)$ for the range $[-\\infty, \\infty]$ is shown below\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=5cm]{FT-Assignment-05}\n\t\\end{figure}\n\tWhich of the following graphs represents the real part of its Fourier transform?\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]\t\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.2cm,width=3cm]{FT-Assignment-01}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{b.}]\n\t\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=2.2cm,width=3cm]{FT-Assignment-02}\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.2cm,width=3cm]{FT-Assignment-03}\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.2cm,width=3cm]{FT-Assignment-04}\n\t\t\\end{figure}\n\t\\end{tasks}\n\t\\item The Fourier transform of the function $h(t)=\\left\\{\\begin{array}{cc}\\beta e^{-a t}, & t>0 \\\\ 0, & t<0\\end{array}\\right.$, is given by\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$H(f)=\\frac{\\alpha}{\\sqrt{\\alpha^{2}+(2 \\pi f)^{2}}} e^{j \\tan ^{-1}\\left[-2 \\pi f^{\\prime \\alpha]}\\right.}$\n\t\t\\task[\\textbf{b.}]$H(f)=\\frac{\\beta}{\\sqrt{\\alpha^{2}+(2 \\pi f)^{2}}} e^{j \\tan ^{-1}[-2 \\pi f / \\beta]}$\n\t\t\\task[\\textbf{c.}]$H(f)=\\frac{\\beta}{\\sqrt{\\alpha^{2}+(2 \\pi f)^{2}}} e^{\\tan ^{-1}[2 \\pi f / \\alpha]}$\n\t\t\\task[\\textbf{d.}] $H(f)=\\frac{\\beta}{\\sqrt{\\alpha^{2}+(2 \\pi f)^{2}}} e^{j \\tan ^{-1}[-2 \\pi f / \\alpha]}$\n\t\\end{tasks}\n\t\\item The Fourier transform of $f(x)=\\left\\{\\begin{array}{cl}-1 & -1<x<0 \\\\ 1 & 0<x<1 \\\\ 0 & \\text { otherwise }\\end{array}\\right.$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}] $\\frac{i}{\\omega} \\sqrt{\\frac{2}{\\pi}}(\\cos \\omega+1)$\n\t\t\\task[\\textbf{b.}] $\\frac{i}{\\omega} \\sqrt{\\frac{2}{\\pi}}(\\cos \\omega-1)$\n\t\t\\task[\\textbf{c.}]$-\\frac{i}{\\omega} \\sqrt{\\frac{2}{\\pi}}(1+\\cos \\omega)$\n\t\t\\task[\\textbf{d.}] $\\frac{i}{\\omega} \\sqrt{\\frac{2}{\\pi}}(1-\\cos \\omega)$\n\t\\end{tasks}\n\t\\item The Fourier transform of $f(x)= \\begin{cases}x, & 0<x<a \\\\ 0, & \\text { otherwise }\\end{cases}$ is\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{\\sqrt{2 \\pi} \\cdot \\omega^{2}}\\left[e^{-i \\omega n a}(1+i a \\omega)-1\\right]$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{\\sqrt{2 \\pi} \\cdot \\omega^{2}}\\left[e^{-i \\omega a}(1-i a \\omega)-1\\right]$\n\t\t\\task[\\textbf{c.}] $\\frac{1}{\\sqrt{2 \\pi} \\cdot \\omega^{2}}\\left[e^{-1 \\text { tox }}(1+i a \\omega)+1\\right]$\n\t\t\\task[\\textbf{d.}] $\\frac{1}{\\sqrt{2 \\pi} \\cdot \\omega^{2}}\\left[e^{-i \\omega a}(1-i a \\omega)+1\\right]$\n\t\\end{tasks}\n\t\n\t\n\t\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "d46d911a337eebe6523b7e9870600a7aac06296b", "size": 5788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Fourier Transform.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-Fourier Transform.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-Fourier Transform.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": 53.5925925926, "max_line_length": 190, "alphanum_fraction": 0.5710089841, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6157964063459351}}
{"text": "\\chapter{Unique factorization (finally!)}\nTook long enough.\n\n\\section{Motivation}\nSuppose we're interested in solutions to the\nDiophantine equation $n = x^2 + 5y^2$ for a given $n$.\nThe idea is to try and ``factor'' $n$ in $\\ZZ[\\sqrt{-5}]$,\nfor example \\[ 6 = (1+\\sqrt{-5})(1-\\sqrt{-5}). \\]\nUnfortunately, this is not so simple, because as I've said before\nwe don't have unique factorization of elements:\n\\[ 6 = 2 \\cdot 3 = \\left( 1+\\sqrt{-5} \\right)\\left( 1-\\sqrt{-5} \\right). \\]\nOne reason this doesn't work is that we don't have a notion of a\n\\emph{greatest common divisor}.\nWe can write $(35, 77) = 7$, but what do we make of $(3, 1+\\sqrt{-5})$?\n\nThe trick is to use ideals as a ``generalized GCD''.\nRecall that by $(a,b)$ I mean the ideal $\\{ax + by \\mid x,y \\in \\ZZ[\\sqrt{-5}] \\}$.\nYou can see that $(35, 77) = (7)$,\nbut $(3, 1+\\sqrt{-5})$ will be left ``unsimplified'' because it doesn't\nrepresent an actual value in the ring.\nUsing these \\emph{sets} (ideals) as elements,\nit turns out that we can develop a full theory\nof prime factorization, and we do so in this chapter.\n\nIn other words, we use the ideal $(a_1, \\dots, a_m)$\nto interpret a ``generalized GCD'' of $a_1$, \\dots, $a_m$.\nIn particular, if we have a number $x$ we want to represent,\nwe encode it as just $(x)$.\n\nGoing back to our example of $6$,\n\\[ (6) = (2) \\cdot (3)\n\t= \\left( 1+\\sqrt{-5} \\right) \\cdot \\left( 1-\\sqrt{-5} \\right). \\]\nPlease take my word for it that in fact,\nthe complete prime factorization of $(6)$ into prime ideals is\n\\[\n\t(6)\n\t= (2,1-\\sqrt{-5})^2 (3,1+\\sqrt{-5})(3,1-\\sqrt{-5})\n\t= \\kp^2 \\kq_1 \\kq_2. \\]\nIn fact, $(2) = \\kp^2$, $(3) = \\kq_1 \\kq_2$,\n$(1+\\sqrt{-5}) = \\kp \\kq_1$, $(1-\\sqrt{-5}) = \\kp \\kq_2$.\nSo $6$ indeed factorizes uniquely into ideals,\neven though it doesn't factor into elements.\n\nAs one can see above,\nideal factorization is more refined than element factorization.\nOnce you have the factorization into \\emph{ideals},\nyou can from there recover all the factorizations into \\emph{elements}.\nThe upshot of this is that if we want to write $n$ as $x^2+5y^2$,\nwe just have to factor $n$ into ideals,\nand from there we can recover all factorizations into elements,\nand finally all ways to write $n$ as $x^2+5y^2$.\nSince we can already break $n$ into rational prime factors\n(for example $6 = 2 \\cdot 3$ above)\nwe just have to figure out how each rational prime $p \\mid n$ breaks down.\nThere's a recipe for this, \\Cref{thm:factor_alg}!\nIn fact, I'll even tell you what is says in this special case:\n\\begin{itemize}\n\t\\ii If $t^2+5$ factors as $(t+c)(t-c) \\pmod p$,\n\tthen $(p) = (p, c+\\sqrt{-5})(p, c-\\sqrt{-5})$.\n\t\\ii Otherwise, $(p)$ is a prime ideal.\n\\end{itemize}\nIn this chapter we'll develop this theory of unique factorization in full generality.\n\n%We saw earlier that in rings, such as $\\ZZ[\\sqrt{-5}]$, unique factorization can fail:\n%\\[ 6 = 2 \\cdot 3 = \\left( 1 - \\sqrt{-5} \\right)\\left( 1 + \\sqrt{5} \\right). \\]\n%I mentioned that we thus turned to the notion of \\emph{ideals},\n%and defined the notion of a prime ideal.\n%Then I said\n%\\begin{quote}\n%\tI now must regrettably inform you that prime factorization is still\n%\tnot true even with the notion of a ``prime'' ideal\n%\t(though not I haven't told you how to multiply two ideals yet).\n%\tBut it will work in the situations we care about most:\n%\tthis is covered in the chapter on Dedekind domains.\n%\\end{quote}\n%I can be precise about what's going to happen now.\n%We'll define a Dedekind domain, which in particular includes all rings of integers $\\OO_K$.\n%Then prime factorization will work in Dedekind domains, and we'll throw a small party.\n\n\\begin{remark}\n\tIn this chapter, I'll be using the letters $\\ka$, $\\kb$, $\\kp$, $\\kq$\n\tfor ideals of $\\OO_K$.\n\tWhen fractional ideals arise, I'll use $I$ and $J$ for them.\n\\end{remark}\n\n\\section{Ideal arithmetic}\n\\prototype{$(x)(y) = (xy)$. In any case, think in terms of generators.}\nFirst, I have to tell you how to add and multiply two ideals $\\ka$ and $\\kb$.\n\\begin{definition}\n\tGiven two ideals $\\ka$ and $\\kb$ of a ring $R$, we define\n\t\\begin{align*}\n\t\t\\ka + \\kb &\\defeq \\left\\{ a+b \\mid a \\in \\ka, b \\in \\kb \\right\\} \\\\\n\t\t\\ka \\cdot \\kb &\\defeq \\left\\{ a_1b_1 + \\dots + a_n b_n\n\t\t\t\\mid a_i \\in \\ka, b_i \\in \\kb \\right\\}.\n\t\\end{align*}\n\\end{definition}\n(Note that infinite sums don't make sense in general rings, which is why in $\\ka \\cdot \\kb$\nwe cut off the sum after some finite number of terms.)\nYou can readily check these are actually ideals.\nThis definition is more natural if you think about it in terms of \nthe generators of $\\ka$ and $\\kb$.\n\\begin{proposition}[Ideal arithmetic via generators]\n\tSuppose $\\ka = \\left( a_1, a_2, \\dots, a_n \\right)$\n\tand $\\kb = \\left( b_1, \\dots, b_m \\right)$ are ideals in a ring $R$.\n\tThen\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\ka + \\kb$ is the ideal generated by $a_1, \\dots, a_n, b_1, \\dots, b_m$.\n\t\t\\ii $\\ka \\cdot \\kb$ is the ideal generated by $a_i b_j$,\n\t\tfor $1 \\le i \\le n$ and $1 \\le j \\le m$.\n\t\\end{enumerate}\n\\end{proposition}\n\\begin{proof}\n\tPretty straightforward; just convince yourself that this result is correct.\n\\end{proof}\nIn other words, for sums you append the two sets of generators together,\nand for products you take products of the generators.\nNote that for principal ideals, this coincides with ``normal'' multiplication,\nfor example\n\\[ (3) \\cdot (5) = (15) \\]\nin $\\ZZ$.\n\\begin{remark}\nNote that for an ideal $\\ka$ and an element $c$,\nthe set \\[ c \\ka = \\left\\{ ca \\mid a \\in \\ka \\right\\} \\]\nis equal to $(c) \\cdot \\ka$.\nSo ``scaling'' and ``multiplying by principal ideals'' are the same thing.\nThis is important, since we'll be using the two notions interchangably.\n\\end{remark}\n\nFinally, since we want to do factorization we better have some notion of divisibility.\nSo we define:\n\\begin{definition}\n\tWe say $\\ka$ divides $\\kb$ and write $\\ka \\mid \\kb$ if $\\ka \\supseteq \\kb$.\n\\end{definition}\nNote the reversal of inclusions!\nSo $(3)$ divides $(15)$, because $(15)$ is contained in $(3)$;\nevery multiple of $15$ is a multiple of $3$.\n\nFinally, the \\vocab{prime ideals} are defined as in \\Cref{def:prime_ideal}:\n$\\kp$ is prime if $xy \\in \\kp$ implies $x \\in \\kp$ or $y \\in \\kp$.\nThis is compatible with the definition of divisibility:\n\\begin{exercise}\n\tA nonzero proper ideal $\\kp$ is prime\n\tif and only if whenever $\\kp$ divides $\\ka \\kb$,\n\t$\\kp$ divides one of $\\ka$ or $\\kb$.\n\\end{exercise}\nAs mentioned in \\Cref{rem:unit_sign_issue},\nthis also lets us ignore multiplication by units: $(-3) = (3)$.\n\n\\section{Dedekind domains}\n\\prototype{Any $\\OO_K$ is a Dedekind domain.}\nWe now define a Dedekind domain as follows.\n\\begin{definition}\n\tAn integral domain $\\mathcal A$ is a \\vocab{Dedekind domain}\n\tif it is Noetherian, integrally closed, and\n\t\\emph{every nonzero prime ideal of $\\mathcal A$ is in fact maximal}.\n\t(The last condition is the important one.)\n\\end{definition}\nHere there's one new word I have to define for you, but we won't make much use of it.\n\\begin{definition}\n\tLet $R$ be an integral domain and let $K$ be its field of fractions.\n\tWe say $R$ is \\vocab{integrally closed} if\n\tthe only elements $a \\in K$ which are roots of \\emph{monic} polynomials in $R$\n\tare the elements of $R$ (which are roots of the trivial $x-r$ polynomial).\n\\end{definition}\nThe \\emph{interesting} condition in the definition\nof a Dedekind domain is the last one: prime ideals and maximal ideals\nare the same thing.\nThe other conditions are just technicalities,\nbut ``primes are maximal'' has real substance.\n\\begin{example}[$\\ZZ$ is a Dedekind domain]\n\tThe ring $\\ZZ$ is a Dedekind domain.\n\tNote that\n\t\\begin{itemize}\n\t\t\\ii $\\ZZ$ is Noetherian (for obvious reasons).\n\t\t\\ii $\\ZZ$ has field of fractions $\\QQ$.\n\t\tIf $f(x) \\in \\ZZ[x]$ is monic, then by the rational root theorem\n\t\tany rational roots are integers\n\t\t(this is the same as the proof that $\\ol\\ZZ \\cap \\QQ = \\ZZ$).\n\t\tHence $\\ZZ$ is integrally closed.\n\t\t\\ii The nonzero prime ideals of $\\ZZ$ are $(p)$,\n\t\twhich also happen to be maximal.\n\t\\end{itemize}\n\\end{example}\n\nThe case of interest is a ring $\\OO_K$ in which we wish to do factorizing.\nWe're now going to show that for any number field $K$, the ring $\\OO_K$ is a Dedekind domain.\nFirst, the boring part.\n\\begin{proposition}[$\\OO_K$ integrally closed and Noetherian]\n\tFor any number field $K$, the ring $\\OO_K$ is integrally closed and Noetherian.\n\\end{proposition}\n\\begin{proof}\n\tBoring, but here it is anyways for completeness.\n\n\tSince $\\OO_K \\cong \\ZZ^{\\oplus n}$, we get that it's Noetherian.\n\n\tNow we show that $\\OO_K$ is integrally closed.\n\tSuppose that $\\eta \\in K$ is the root of some polynomial with coefficients in $\\OO_K$.\n\tThus\n\t\\[ \\eta^n = \\alpha_{n-1} \\cdot \\eta^{n-1} + \\alpha_{n-2} \\cdot \\eta^{n-2}\n\t\t+ \\dots + \\alpha_0 \\] \n\twhere $\\alpha_i \\in \\OO_K$. We want to show that $\\eta \\in \\OO_K$ as well.\n\n\tWell, from the above, $\\OO_K[\\eta]$ is finitely generated\\dots\n\tthus $\\ZZ[\\eta] \\subseteq \\OO_K[\\eta]$ is finitely generated.\n\tSo $\\eta \\in \\ol\\ZZ$, and hence $\\eta \\in K \\cap \\ol\\ZZ = \\OO_K$.\n\\end{proof}\nNow let's do the fun part.\nWe'll prove a stronger result, which will re-appear repeatedly.\n\\begin{theorem}[Important: prime ideals divide rational primes]\n\tLet $\\OO_K$ be a ring of integers\n\tand $\\kp$ a nonzero prime ideal inside it.\n\tThen $\\kp$ contains a rational prime $p$.\n\tMoreover, $\\kp$ is maximal.\n\\end{theorem}\n\\begin{proof}\n\tTake any $\\alpha \\neq 0$ in $\\kp$.\n\tIts Galois conjugates are algebraic integers\n\tso their product $\\Norm(\\alpha)/\\alpha$ is in $\\OO_K$\n\t(even though each individual conjugate need not be in $K$).\n\tConsequently, $\\Norm(\\alpha) \\in \\kp$,\n\tand we conclude $\\kp$ contains some integer.\n\n\tThen take the smallest positive integer in $\\kp$, say $p$.\n\tWe must have that $p$ is a rational prime, since otherwise $\\kp \\ni p = xy$\n\timplies one of $x,y \\in \\kp$.\n\tThis shows the first part.\n\n\tWe now do something pretty tricky to show $\\kp$ is maximal.\n\tLook at $\\OO_K / \\kp$;\n\tsince $\\kp$ is prime it's supposed to be an integral domain\\dots\\ \n\tbut we claim that it's actually finite!\n\tTo do this, we forget that we can multiply on $\\OO_K$.\n\tRecalling that $\\OO_K \\cong \\ZZ^{\\oplus n}$ as an abelian group,\n\twe obtain a map\n\t\\[ {\\FF_p}^{\\oplus n} \\cong \\OO_K / (p) \\surjto \\OO_K / \\kp. \\]\n\tHence $\\left\\lvert \\OO_K / \\kp \\right\\rvert \\le p^n$ is \\emph{finite}.\n\tSince finite integral domains are fields (\\Cref{prob:finite_domain_field})\n\twe are done.\n\\end{proof}\nSince every nonzero prime $\\kp$ is maximal, we now know that $\\OO_K$ is a Dedekind domain.\nNote that this tricky proof is essentially inspired by the solution to \\Cref{prob:dedekind_sample}.\n\n\n\\section{Unique factorization works}\nOkay, I'll just say it now!\n\\begin{moral}\n\tUnique factorization works perfectly in Dedekind domains!\n\\end{moral}\n\\begin{theorem}[Prime factorization works]\n\tLet $\\ka$ be a nonzero proper ideal of a Dedekind domain $\\mathcal A$.\n\tThen $\\ka$ can be written as a finite product of nonzero prime ideals $\\kp_i$, say\n\t\\[ \\ka = \\kp_1^{e_1} \\kp_2^{e_2} \\dots \\kp_g^{e_g} \\]\n\tand this factorization is unique up to the order of the $\\kp_i$.\n\n\tMoreover, $\\ka$ divides $\\kb$ if and only if for every prime ideal $\\kp$,\n\tthe exponent of $\\kp$ in $\\ka$ is less than the corresponding exponent in $\\kb$.\n\\end{theorem}\n%% Ofer joke\n% As ideals, you and I are coprime because together we are (1).\n\nI won't write out the proof, but I'll describe the basic method of attack.\nSection 3 of \\cite{ref:ullery} does a nice job of explaining it.\nWhen we proved the fundamental theorem of arithmetic, the basic plot was:\n\\begin{enumerate}[(1)]\n\t\\ii Show that if $p$ is a rational prime\\footnote{\n\t\tNote that the kindergarten definition of a prime is\n\t\tthat ``$p$ isn't the product of two smaller integers''.\n\t\tThis isn't the correct definition of a prime:\n\t\tthe definition of a prime is that $p \\mid bc$\n\t\tmeans $p \\mid b$ or $p \\mid c$.\n\t\tThe kindergarten definition is something called ``irreducible''.\n\t\tFortunately, in $\\ZZ$, primes and irreducibles are the same thing,\n\t\tso no one ever told you that your definition of ``prime'' was wrong.}\n\tthen $p \\mid bc$ means $p \\mid b$ or $p \\mid c$.  (This is called Euclid's Lemma.)\n\t\\ii Use strong induction to show that every $N > 1$ can be written as the product of primes (easy).\n\t\\ii Show that if $p_1 \\dots p_m = q_1 \\dots q_n$ for some primes (not necessarily unique),\n\tthen $p_1 = q_i$ for some $i$, say $q_1$.\n\t\\ii Divide both sides by $p_1$ and use induction.\n\\end{enumerate}\nWhat happens if we try to repeat the proof here?\nWe get step 1 for free, because we're using a better definition of ``prime''.\nWe can also do step 3, since it follows from step 1.\nBut step 2 doesn't work,\nbecause for abstract Dedekind domains\nwe don't really have a notion of size.\nAnd step 4 doesn't work because we don't yet have a\nnotion of what the inverse of a prime ideal is.\n\nWell, it turns out that we \\emph{can} define the inverse $\\ka\\inv$ of an ideal,\nand I'll do so by the end of this chapter.\nYou then need to check that $\\ka \\cdot \\ka\\inv = (1) = \\mathcal A$.\nIn fact, even this isn't easy.\nYou have to check it's true for prime ideals $\\kp$,\n\\emph{then} prove prime factorization,\nand then prove that this is true.\nMoreover, $\\ka\\inv$ is not actually an ideal, so you need to\nwork in the field of fractions $K$ instead of $\\mathcal A$.\n\nSo the main steps in the new situation are as follows:\n\\begin{enumerate}[(1)]\n\t\\ii First, show that every ideal $\\ka$ divides $\\kp_1 \\dots \\kp_g$\n\tfor some finite collection of primes.\n\t(This is an application of Zorn's Lemma.)\n\t\\ii Define $\\kp\\inv$ and show that $\\kp \\kp\\inv = (1)$.\n\t\\ii Show that a factorization exists (again using Zorn's Lemma).\n\t\\ii Show that it's unique, using the new inverse we've defined.\n\\end{enumerate}\n\nFinally, let me comment on how nice this is if $\\mathcal A$ is a PID (like $\\ZZ$).\nThus every element $a \\in \\mathcal A$ is in direct correspondence with an ideal $(a)$.\nNow suppose $(a)$ factors as a product of ideals $\\kp_i = (p_i)$, say,\n\\[ (a) = (p_1)^{e_1} (p_2)^{e_2} \\dots (p_n)^{e_n} . \\]\nThis verbatim reads \\[ a = u p_1^{e_1} p_2^{e_2} \\dots p_n^{e_n} \\]\nwhere $u$ is some unit (recall \\Cref{def:unit}).\nHence, Dedekind domains which are PID's satisfy unique factorization\nfor \\emph{elements}, just like in $\\ZZ$.\n(In fact, the converse of this is true.)\n\n\\section{The factoring algorithm}\nLet's look at some examples from quadratic fields.\nRecall that if $K = \\QQ(\\sqrt{d})$, then\n\\[\n\t\\OO_K =\n\t\\begin{cases}\n\t\t\\ZZ[\\sqrt d] & d \\equiv 2,3 \\pmod 4 \\\\\n\t\t\\ZZ\\left[ \\frac{1+\\sqrt d}{2} \\right] & d \\equiv 1 \\pmod 4.\n\t\\end{cases}\n\\]\nAlso, recall that the norm of $a+b\\sqrt{-d}$ is given by $a^2+db^2$.\n\n%In what follows, we are going to often use the trick that\n%\\[ \\ZZ[\\alpha] \\cong \\ZZ[x] / (f) \\]\n%where $f$ is the minimal polynomial of $\\alpha$.\n\n\\begin{example}[Factoring $6$ in the integers of $\\QQ(\\sqrt{-5})$]\n\tLet $\\OO_K = \\ZZ[\\sqrt{-5}]$ arise from $K = \\QQ(\\sqrt{-5})$.\n\tWe've already seen that\n\t\\[ (6) = (2) \\cdot (3) = \\left( 1+\\sqrt{-5} \\right)\\left( 1-\\sqrt{-5} \\right) \\]\n\tand you can't get any further with these principal ideals.\n\tBut let\n\t\\[ \\kp = \\left( 1+\\sqrt{-5}, 2 \\right) = \\left( 1-\\sqrt{-5}, 2 \\right)\n\t\t\\quad\\text{and}\\quad \\kq_1 = (1+\\sqrt{-5},3),\n\t\t\\; \\kq_2 = (1-\\sqrt{-5},3). \\]\n\tThen it turns out $(6) = \\kp^2\\kq_1\\kq_2$.\n\tMore specifically, $(2) = \\kp^2$, $(3) = \\kq_1\\kq_2$,\n\tand $(1+\\sqrt{-5}) = \\kp\\kq_1$ and $(1-\\sqrt{-5}) = \\kp\\kq_2$.\n\t(Proof in just a moment.)\n\\end{example}\nI want to stress that all our ideals are computed relative to $\\OO_K$.\nSo for example, \\[ (2) = \\left\\{ 2x \\mid x \\in \\OO_K \\right\\}. \\]\n\nHow do we know in this example that $\\kp$ is prime/maximal?\n(Again, these are the same since we're in a Dedekind domain.)\nAnswer: look at $\\OO_K / \\kp$ and see if it's a field.\nThere is a trick to this: we can express\n\\[ \\OO_K = \\ZZ[\\sqrt{-5}] \\cong \\ZZ[x] / (x^2+5). \\]\n%\\begin{ques}\n%\tConvince yourself this is true.\n%\t(More generally, if $\\theta \\in \\ol\\ZZ$ has minimal polynomial $p$,\n%\tthen $\\ZZ[\\theta] \\cong \\ZZ[x] / (p)$).\n%\\end{ques}\nSo when we take \\emph{that} mod $\\kp$, we get that\n\\[ \\OO_K / \\kp = \\ZZ[x] / (x^2+5, 2, 1+x) \\cong \\FF_2[x] / (x^2+5,x+1) \\]\nas rings.\n\\begin{ques}\n\tConclude that $\\OO_K / \\kp \\cong \\mathbb F_2$,\n\tand satisfy yourself that $\\kq_1$ and $\\kq_2$ are also maximal.\n\\end{ques}\nI should give an explicit example of an ideal multiplication: let's compute\n\\begin{align*}\n\t\\kq_1\\kq_2 &= \\left( (1+\\sqrt{-5})(1-\\sqrt{-5}), 3(1+\\sqrt{-5}), 3(1-\\sqrt{-5}), 9 \\right) \\\\\n\t&= \\left( 6, 3+3\\sqrt{-5}, 3-3\\sqrt{-5}, 9 \\right) \\\\\n\t&= \\left( 6, 3+3\\sqrt{-5}, 3-3\\sqrt{-5}, 3 \\right) \\\\\n\t&= (3)\n\\end{align*}\nwhere we first did $9-6=3$ (think Euclidean algorithm!),\nthen noted that all the other generators don't contribute\nanything we don't already have with the $3$\n(again these are ideals computed in $\\OO_K$).\nYou can do the computation for $\\kp^2$, $\\kp\\kq_1$, $\\kp\\kq_2$ in the same way.\n\nFinally, it's worth pointing out that we should quickly\nverify that $\\kp \\neq (x)$ for some $x$;\nin other words, that $\\kp$ is not principal.\nAssume for contradiction that it is.\nThen $x$ divides both $1+\\sqrt{-5}$ and $2$, in the sense\nthat $1+\\sqrt{-5} = \\alpha_1 x$ and $2 = \\alpha_2 x$\nfor some $\\alpha_1, \\alpha_2 \\in \\OO_K$.\n(Principal ideals are exactly the ``multiples'' of $x$, so $(x) = x \\OO_K$.)\nTaking the norms, we find that $\\Norm_{K/\\QQ}(x)$ divides both \n\\[ \\Norm_{K/\\QQ}(1+\\sqrt{-5}) = 6 \\quad\\text{and}\\quad \\Norm_{K/\\QQ}(2) = 4. \\]\nSince $\\kp \\neq (1)$, $x$ cannot be a unit, so its norm must be $2$.\nBut there are no elements of norm $2 = a^2+5b^2$ in $\\OO_K$.\n\n\\begin{example}[Factoring $3$ in the integers of $\\QQ(\\sqrt{-17})$]\n\tLet $\\OO_K = \\ZZ[\\sqrt{-17}]$ arise from $K = \\QQ(\\sqrt{-17})$.\n\tWe know $\\OO_K \\cong \\ZZ[x] / (x^2+17)$.\n\tNow\n\t\\[\n\t\t\\OO_K / 3\\OO_K \\cong \\ZZ[x] / (3,x^2+17)\n\t\t\\cong \\FF_3[x] / (x^2-1).\n\t\\]\n\tThis already shows that $(3)$ cannot be a prime (i.e.\\ maximal) ideal,\n\tsince otherwise our result should be a field.\n\tAnyways, we have a projection\n\t\\[ \\OO_K \\surjto \\FF_3[x] / \\left( (x-1)(x+1) \\right). \\]\n\tLet $\\kq_1$ be the pre-image of $(x-1)$ in the image, that is,\n\t\\[ \\kq_1 = (3, \\sqrt{-17}-1). \\]\n\tSimilarly, \\[ \\kq_2 = (3, \\sqrt{-17}+1). \\]\n\tWe have $\\OO_K / \\kq_1 \\cong \\FF_3$, so $\\kq_1$ is maximal (prime).\n\tSimilarly $\\kq_2$ is prime.\n\tMagically, you can check explicitly that\n\t\\[ \\kq_1 \\kq_2 = (3). \\]\n\tHence this is the factorization of $(3)$ into prime ideals.\n\\end{example}\n\nThe fact that $\\kq_1 \\kq_2 = (3)$ looks magical, but it's really true:\n\\begin{align*}\n\t\\kq_1\\kq_2\n\t&= (3, \\sqrt{-17}-1) (3, \\sqrt{-17}+1) \\\\\n\t&= (9, 3\\sqrt{-17}+3, 3\\sqrt{-17}-3, 18) \\\\\n\t&= (9, 3\\sqrt{-17}+3, 6) \\\\\n\t&= (3, 3\\sqrt{-17}+3, 6) \\\\\n\t&= (3).\n\\end{align*}\nIn fact, it turns out this always works in general:\ngiven a rational prime $p$, there is an algorithm\nto factor $p$ in any $\\OO_K$ of the form $\\ZZ[\\theta]$.\n\n\\begin{theorem}[Factoring algorithm / Dedekind-Kummer theorem]\n\t\\label{thm:factor_alg}\n\tLet $K$ be a number field.\n\tLet $\\theta \\in \\OO_K$ with $[\\OO_K : \\ZZ[\\theta]] = j < \\infty$,\n\tand let $p$ be a prime not dividing $j$.\n\tThen $(p) = p \\OO_K$ is factored as follows:\n\t\\begin{quote}\n\t\tLet $f$ be the minimal polynomial of $\\theta$ and\n\t\tfactor $\\ol f$ mod $p$ as\n\t\t\\[ \\ol f \\equiv \\prod_{i=1}^g (\\ol f_i)^{e_i} \\pmod p. \\]\n\t\tThen $\\kp_i = (f_i(\\theta), p)$ is prime for each $i$\n\t\tand the factorization of $(p)$ is\n\t\t\\[ \\OO_K \\supseteq (p) = \\prod_{i=1}^g \\kp_i^{e_i}. \\]\n\t\\end{quote}\n\tIn particular, if $K$ is monogenic with $\\OO_K = \\ZZ[\\theta]$ then $j=1$\n\tand the theorem applies for all primes $p$.\n\\end{theorem}\nIn almost all our applications in this book, $K$ will be monogenic; i.e.\\ $j=1$.\nHere $\\ol \\psi$ denotes the image in $\\FF_p[x]$ of a polynomial $\\psi \\in \\ZZ[x]$.\n\n\\begin{ques}\n\tThere are many possible pre-images $f_i$ we could have chosen\n\t(for example if $\\ol{f_i} = x^2+1 \\pmod 3$, we could pick $f_i = x^2 + 3x + 7$.)\n\tWhy does this not affect the value of $\\kp_i$?\n\\end{ques}\n\nNote that earlier, we could check the factorization worked\nfor any particular case. \nThe proof that this works is much the same, but we need one extra tool, the ideal norm.\nAfter that we leave the proposition as \\Cref{prob:prove_factoring_algorithm}.\n\nThis algorithm gives us a concrete way to compute prime factorizations of $(p)$\nin any monogenic number field with $\\OO_K = \\ZZ[\\theta]$. To summarize the recipe:\n\\begin{enumerate}\n\t\\ii Find the minimal polynomial of $\\theta$, say $f \\in \\ZZ[x]$.\n\t\\ii Factor $f$ mod $p$ into irreducible polynomials\n\t${\\ol f_1}^{e_1} {\\ol f_2}^{e_2} \\dots {\\ol f_g}^{e_g}$.\n\t\\ii Compute $\\kp_i = (f_i(\\theta), p)$ for each $i$.\n\\end{enumerate}\nThen your $(p) = \\kp_1^{e_1} \\dots \\kp_g^{e_g}$.\n\n\\begin{exercise}\n\tFactor $(29)$ in $\\QQ(i)$ using the above algorithm.\n\\end{exercise}\n\n%\\begin{remark}\n%\tWhat if $K$ isn't monogenic?\n%\tIt turns out that we can still apply the\n%\tfactoring algorithm to ``almost all primes'' as follows.\n%\tSuppose $K$ is a number field and $\\alpha \\in \\OO_K$ such that\n%\t$[\\OO_K : \\ZZ[\\alpha]] = j < \\infty$.\n%\tThen as long as $p \\nmid j$, we can apply the above algorithm\n%\twith $f$ the minimal polynomial of $\\alpha$.\n%\tThe formulation we presented above was the special case where $j=1$.\n%\\end{remark}\n\n\\section{Fractional ideals}\n\\prototype{Analog to $\\QQ$ for $\\ZZ$, allowing us to take inverses of ideals.\nPrime factorization works in the nicest way possible.}\nWe now have a neat theory of factoring ideals of $\\mathcal A$,\njust like factoring the integers.\nNow note that our factorization of $\\ZZ$ naturally gives a way to factor\nelements of $\\QQ$; just factor the numerator and denominator separately.\n\nLet's make the analogy clearer.\nThe analogue of a rational number is as follows.\n\n\\begin{definition}\n\tLet $\\mathcal A$ be a Dedekind domain with field of fractions $K$.\n\tA \\vocab{fractional ideal} $J$ of $K$ is a set of the form \n\t\\[ J = \\frac{1}{x} \\cdot \\ka \\quad \\text{where $x \\in \\mathcal A$, and $\\ka$ is an integral ideal.} \\]\n\tFor emphasis, ideals of $\\mathcal A$ will be sometimes referred to as \\vocab{integral ideals}.\n\\end{definition}\n\nYou might be a little surprised by this definition:\none would expect that a fractional ideal should be of the form $\\frac{\\ka}{\\kb}$\nfor some integral ideals $\\ka$, $\\kb$.\nBut in fact, it suffices to just take $x \\in \\mathcal A$ in the denominator.\nThe analogy is that when we looked at $\\OO_K$, we found that we only needed\ninteger denominators: $\\frac{1}{4-\\sqrt3} = \\frac{1}{13}(4+\\sqrt3)$.\nSimilarly here, it will turn out that we only need to look at $\\frac1x \\cdot \\ka$\nrather than $\\frac{\\ka}{\\kb}$, and so we define it this way from the beginning.\nSee \\Cref{prob:fractional_ideal_alt_def} for a different equivalent definition.\n\n\\begin{example}[$\\frac52\\ZZ$ is a fractional ideal]\n\tThe set \\[ \\frac52 \\ZZ = \\left\\{ \\frac52n \\mid n \\in \\ZZ \\right\\} = \\half (5) \\]\n\tis a fractional ideal of $\\ZZ$.\n\\end{example}\n\nNow, as we prescribed, the fractional ideals form a multiplicative group:\n\\begin{theorem}[Fractional ideals form a group]\n\tLet $\\mathcal A$ be a Dedekind domain and $K$ its field of fractions.\n\tFor any integral ideal $\\ka$, the set\n\t\\[ \\ka\\inv = \\left\\{ x \\in K\n\t\t\t\\mid x\\ka \\subseteq (1) = \\mathcal A \\right\\} \\]\n\tis a fractional ideal with $\\ka \\ka\\inv = (1)$.\n\\end{theorem}\n\\begin{definition}\n\tThus nonzero fractional ideals of $K$ form a group under multiplication\n\twith identity $(1) = \\mathcal A$.\n\tThis \\vocab{ideal group} is denoted $J_K$.\n\\end{definition}\n\n\\begin{example}[$(3)\\inv$ in $\\ZZ$]\n\tPlease check that in $\\ZZ$ we have\n\t\\[ (3)\\inv = \\left\\{ \\frac 13 n \\mid n \\in \\ZZ \\right\\} = \\frac 13 \\ZZ. \\]\n\\end{example}\n\nIt follows that every fractional ideal $J$ can be uniquely written as\n\\[ J = \\prod_i \\kp_i^{n_i} \\cdot \\prod \\kq_i^{-m_i} \\]\nwhere $n_i$ and $m_i$ are positive integers.\nIn fact, $\\ka$ is an integral ideal if and only if all its exponents are nonnegative,\njust like the case with integers.\nSo, a perhaps better way to think about fractional ideals is\nas products of prime ideals, possibly with negative exponents.\n\n\\section{The ideal norm}\nOne last tool is the ideal norm,\nwhich gives us a notion of the ``size'' of an ideal.\n\\begin{definition}\n\tThe \\vocab{ideal norm} (or absolute norm)\n\tof a nonzero ideal $\\ka \\subseteq \\OO_K$ is defined as\n\t$\\left\\lvert \\OO_K / \\ka \\right\\rvert$ and denoted $\\Norm(\\ka)$.\n\\end{definition}\n\\begin{example}[Ideal norm of $(5)$ in the Gaussian integers]\n\tLet $K = \\QQ(i)$, $\\OO_K = \\ZZ[i]$.\n\tConsider the ideal $(5)$ in $\\OO_K$.\n\tWe have that \n\t\\[ \\OO_K / (5) \\cong \\{ a+bi \\mid a,b \\in \\Zc5 \\} \\]\n\tso $(5)$ has ideal norm $25$,\n\tcorresponding to the fact that $\\OO_K/(5)$ has $5^2=25$ elements.\n\\end{example}\n\n\\begin{example}[Ideal norm of $(2+i)$ in the Gaussian integers]\n\tYou'll notice that \\[ \\OO_K / (2+i) \\cong \\FF_5 \\]\n\tsince mod $2+i$ we have both $5 \\equiv 0$ and $i \\equiv -2$.\n\t(Indeed, since $(2+i)$ is prime we had better get a field!)\n\tThus $\\Norm\\left( (2+i) \\right) = 5$; similarly $\\Norm\\left( (2-i) \\right) = 5$.\n\\end{example}\n\nThus the ideal norm measures how ``roomy'' the ideal is:\nthat is, $(5)$ is a lot more spaced out in $\\ZZ[i]$ than it is in $\\ZZ$.\n(This intuition will be important when we will actually view $\\OO_K$ as a lattice.)\n\n\\begin{ques}\n\tWhat are the ideals with ideal norm one?\n\\end{ques}\n% Regrettably, ideals with more elements have smaller norms.\n\nOur example with $(5)$ suggests several properties of the ideal norm\nwhich turn out to be true:\n\\begin{lemma}[Properties of the absolute norm]\n\tLet $\\ka$ be a nonzero ideal of $\\OO_K$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\Norm(\\ka)$ is finite.\n\t\t\\ii For any other nonzero ideal $\\kb$, $\\Norm(\\ka\\kb) = \\Norm(\\ka)\\Norm(\\kb)$.\n\t\t\\ii If $\\ka = (a)$ is principal, then $\\Norm(\\ka) = \\Norm_{K/\\QQ}(a)$.\n\t\t% \\ii The ideal norm $\\Norm(\\ka)$ equals the GCD of $\\Norm_{K/\\QQ}(\\alpha)$ across\n\t\t% all $\\alpha \\in \\ka$. In particular, if $\\ka = (\\alpha)$ is principal\n\t\t% then $\\Norm(\\ka) = \\Norm_{K/\\QQ}(\\alpha)$.\n\t\\end{enumerate}\n\\end{lemma}\nI unfortunately won't prove these properties, though we already did (a) in our proof that $\\OO_K$\nwas a Dedekind domain.\n% Anyways, this lemma provides another way to show an ideal isn't principal.\n\n%\\begin{example}[Example of an Ideal Norm]\n%\tLet $K = \\QQ(\\sqrt 3)$, so $\\OO_K = \\ZZ[\\sqrt 3]$.\n%\t% \\ii The norm of the principal ideal $(4+\\sqrt 3)$ is the norm of the element, $(4+\\sqrt3)(4-\\sqrt3) = 13$.\n%\t% \\ii\n%\tConsider $\\ka = (2, \\sqrt3)$.\n%\t\tWe need to have \n%\t\t\\[ \\Norm(\\ka) \\mid \\gcd(\\Norm_{K/\\QQ}(2), \\Norm_{K/\\QQ}(3)) = \\gcd(4, 3) = 1. \\]\n%\t\tSo in fact, $\\Norm(\\ka) = 1$. Surprise!\n%\t\tThis actually means $\\ka = (1)$,\n%\t\twhich in hindsight also follows from the fact that\n%\t\t$\\sqrt 3 \\in \\ka$, thus $\\sqrt 3 \\cdot \\sqrt 3 \\in \\ka$ and $3 \\in \\ka$;\n%\t\tbut $2 \\in \\ka$ so $1 \\in \\ka$.\n%\\end{example}\n\nThe fact that $\\Norm$ is completely multiplicative lets us also consider the norm\nof a fractional ideal $J$ by the natural extension\n\\[ J = \\prod_i \\kp_i^{n_i} \\cdot \\prod_i \\kq_i^{-m_i} \n\t\\quad \\implies \\quad\n\t\\Norm(J) \\defeq \\frac{\\prod_i \\Norm(\\kp_i)^{n_i}}{\\prod_i \\Norm(\\kq_i)^{m_i}}. \\]\nThus $\\Norm$ is a natural group homomorphism $J_K \\to \\QQ \\setminus \\{0\\}$.\n\n\n\\section\\problemhead\n\\begin{problem}\n\tShow that there are three different factorizations of $77$ in $\\OO_K$,\n\twhere $K = \\QQ(\\sqrt{-13})$.\n\\end{problem}\n\n\\begin{problem}\n\tLet $K = \\QQ(\\cbrt 2)$;\n\ttake for granted that $\\OO_K = \\ZZ[\\cbrt 2]$.\n\tFind the factorization of $(5)$ in $\\OO_K$.\n\\end{problem}\n\n\\begin{problem}\n\t[Fermat's little theorem]\n\tLet $\\kp$ be a prime ideal in some ring of integers $\\OO_K$.\n\tShow that for $\\alpha \\in \\OO_K$,\n\t\\[ \\alpha^{\\Norm(\\kp)} \\equiv \\alpha \\pmod{\\kp}. \\]\n\t\\begin{hint}\n\t\tCopy the proof of the usual Fermat's little theorem.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIf $\\alpha \\equiv 0 \\pmod{\\kp}$ it's clear, so assume this isn't the case.\n\t\tThen $\\OO_K/\\kp$ is a finite field with $\\Norm(\\kp)$ elements.\n\t\tLooking at $(\\OO_K/\\kp)^\\ast$, it's a multiplicative group with $\\Norm(\\kp)-1$ elements,\n\t\tso $\\alpha^{\\Norm(\\kp)-1} \\equiv 1 \\pmod{\\kp}$, as desired.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{dproblem}\n\tLet $\\mathcal A$ be a Dedekind domain with field of fractions $K$,\n\tand pick $J \\subseteq K$.\n\tShow that $J$ is a fractional ideal if and only if\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $J$ is closed under addition and multiplication\n\t\tby elements of $\\mathcal A$, and\n\t\t\\ii $J$ is finitely generated as an abelian group.\n\t\\end{enumerate}\n\tMore succinctly: $J$ is a fractional ideal $\\iff$ $J$ is a finitely generated $\\mathcal A$-module.\n\t\\label{prob:fractional_ideal_alt_def}\n\t\\begin{hint}\n\t\tClear denominators!\n\t\\end{hint}\n\t\\begin{sol}\n\t\tSuppose it's generated by some elements in $K$; we can write them as\n\t\t$\\frac{\\beta_i}{\\alpha_i}$ for $\\alpha_i, \\beta_i \\in \\mathcal A$.\n\t\tHence\n\t\t\\[ J = \\left\\{ \\sum_i \\gamma_i \\cdot \\frac{\\beta_i}{\\alpha_i}\n\t\t\\mid \\alpha_i, \\beta_i, \\gamma_i \\in \\OO_K \\right\\}. \\]\n\t\tNow ``clear denominators''. Set $\\alpha = \\alpha_1 \\dots \\alpha_n$,\n\t\tand show that $\\alpha J$ is an integral ideal.\n\t\\end{sol}\n\\end{dproblem}\n\n\\begin{problem}\n\t\\label{prob:prove_factoring_algorithm}\n\tIn the notation of \\Cref{thm:factor_alg}, let $I = \\prod_{i=1}^g \\kp_i^{e_i}$.\n\tAssume for simplicity that $K$ is monogenic, hence $\\OO_K = \\ZZ[\\theta]$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Prove that each $\\kp_i$ is prime.\n\t\t\\ii Show that $(p)$ divides $I$.\n\t\t\\ii Use the norm to show that $(p) = I$.\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\t(a) is straightforward.\n\t\tFor (b) work mod $p$.\n\t\tFor (c) use norms.\n\t\\end{hint}\n\t\\begin{sol}\n\tFor part (a), note that the $\\kp_i$ are prime\n\tjust because \n\t\\[ \\OO_K / \\kp_i\n\t\t\\cong (\\ZZ[x] / f) / (p, f_i)\n\t\t\\cong \\FF_p[x] / (f_i) \\]\n\tis a field, since the $f_i$ are irreducible.\n\n\tWe check (b).\n\t\tComputing the product modulo $p$ yields\\footnote{%\n\t\t\tFor example, suppose we want to know that $(3, 1+\\sqrt{7})(3, 1-\\sqrt{7})$ is contained in $(3)$.\n\t\t\tWe could do the full computation and get $(9, 3+3\\sqrt{7}, 3-3\\sqrt{7}, 6)$.\n\t\t\tBut if all we care about is that every element is divisible by $3$, we could have just taken ``mod $3$''\n\t\t\tat the beginning and looked at just $(1+\\sqrt{7})(1-\\sqrt{7}) = (6)$;\n\t\t\tall the other products we get will obviously have factors of $3$.\n\t\t}\n\t\t\\[ \\prod_{i=1}^{g} (f_i(\\theta))^{e_i}\n\t\t\t\\equiv (f(\\theta)) \\equiv 0 \\pmod p \\]\n\t\tso we've shown that $I \\subseteq (p)$.\n\n\tFinally, we prove (c) with a size argument.\n\t\tThe idea is that $I$ and $(p)$ really should have the same size;\n\t\tto nail this down we'll use the ideal norm.\n\t\tSince $(p)$ divides $I$, we can write\n\t\t$ (p) = \\prod_{i=1}^g \\kp_i^{e_i'} $\n\t\twhere $e_i' \\le e_i$ for each $i$.\n\t\tRemark $\\OO_K / (p) \\cong \\Zc p[x] / (f)$ has size $p^{\\deg f}$.\n\t\tSimilarly, $\\OO_K / (\\kp_i)$ has degree $p^{\\deg f_i}$ for each $i$.\n\t\tCompute $\\Norm( (p) )$ using the $e_i'$ now and compare the results.\n%\t\tHence\n%\t\t\\[ p^{\\deg f} = \\Norm(p)\n%\t\t= \\prod_{i=1}^r \\Norm(\\kp_i)^{e_i'}\n%\t\t= p^{e_1' \\deg f_1 + \\dots + e_g' \\deg f_g}. \\]\n%\t\tHence\n%\t\t\\[ e_1' \\deg f_1 + \\dots e_g' \\deg f_g = \\deg f. \\]\n%\t\tOn the other hand, it's obvious that \\[ \\deg f = e_1 \\deg f_1 + \\dots + e_g \\deg f_g. \\]\n%\t\tAs $e_i' \\le e_i$ for each $i$, we can only have $e_i = e_i'$.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "a08e58b16a48e5dc5b5d5d5c35266687f20fd8a3", "size": 31188, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/dedekind.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/dedekind.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/dedekind.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": 43.0773480663, "max_line_length": 110, "alphanum_fraction": 0.6686866744, "num_tokens": 10524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6157963990304696}}
{"text": "\\documentclass{article}\n\n\\begin{document}\n\n\\section*{1.}\n\n\\[ (1 + i_1)^{m_1} =  (1 + i_2)^{m_2} \\]\n\n\\[ (1 + 0.18)^{1} =  (1 + i_2)^{12} \\]\n\n\\[ (1 + 0.18)^{1/12} =  1 + i_2 \\]\n\n\\[ (1 + 0.18)^{1/12} - 1 = i_2 \\]\n\n\\section*{2.}\n\n\n\n\n\n\\end{document}", "meta": {"hexsha": "269af217ea5f3cef93e5ccdf80b1e58c45a37bd7", "size": 244, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parcial_1.tex", "max_stars_repo_name": "Youngermaster/Tutorials", "max_stars_repo_head_hexsha": "4fb5a01ba0bf3e8820f61d88ff398f3a09776f29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "parcial_1.tex", "max_issues_repo_name": "Youngermaster/Tutorials", "max_issues_repo_head_hexsha": "4fb5a01ba0bf3e8820f61d88ff398f3a09776f29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "parcial_1.tex", "max_forks_repo_name": "Youngermaster/Tutorials", "max_forks_repo_head_hexsha": "4fb5a01ba0bf3e8820f61d88ff398f3a09776f29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 11.619047619, "max_line_length": 40, "alphanum_fraction": 0.4385245902, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6157963990304696}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 10.2 Trigonometric, Cosine, and Sine Fourier Transforms\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis subroutine computes discrete trigonometric, cosine, and sine transforms\nin up to six dimensions using the FFT. In the one dimensional case, the\nvalues $y$ and the Fourier coefficients $\\alpha $ and $\\beta $ are related\nby:\n\\begin{multline}\ny_j=\\frac 12\\alpha _0+\\,\\sum_{k=1}^{(N/2)-1}\\left[ \\alpha _k\\cos \\frac{2\\pi\njk}N+\\beta _k\\sin \\frac{2\\pi jk}N\\right]\\\\\n+\\frac 12\\alpha _{N/2}(-1)^j,\\quad j=0,1,...,N-1\\tag{1S}\n\\end{multline}\\vspace{-10pt}\n\\renewcommand{\\theequation}{\\arabic{equation}A}\n\\begin{equation}\n\\begin{split}\n\\alpha _k&=\\frac 2N\\sum_{j=0}^{N-1}y_j\\cos \\frac{2\\pi jk}N,\\quad\nk=0,1,...,\\frac N2\\\\\n\\beta _k&=\\frac 2N\\sum_{j=0}^{N-1}y_j\\sin \\frac{2\\pi jk}N,\\quad\nk=1,2,...,\\frac N2-1\n\\end{split}\n\\end{equation}\\vspace{-10pt}\n\\begin{multline}\ny_j=\\frac 12\\alpha _0+\\sum_{k=1}^{N-1}\\alpha _k\\cos \\frac{\\pi jk}N+\\frac\n12\\alpha _N(-1)^j,\\\\\nj=0,1,...,N\\tag{2S}\n\\end{multline}\\vspace{-20pt}\n\\begin{multline}\n\\alpha _k=\\frac 2N\\left[ \\frac 12y_0+\\sum_{j=1}^{N-1}y_j\\cos \\frac{\\pi jk}%\nN+\\frac 12y_N(-1)^k\\right] ,\\\\\nk=0,1,...,N\n\\end{multline}\\vspace{-20pt}\n\\begin{equation}\n\\hspace{-5pt}y_j=\\sum_{k=1}^{N-1}\\beta _k\\sin \\frac{\\pi jk}N,\\quad j=1,2,...,N-1%\n\\tag{3S}\n\\end{equation}\\vspace{-10pt}\n\\begin{equation}\n\\hspace{-5pt}\\beta _k=\\frac 2N\\sum_{j=1}^{N-1}y_j\\sin\n\\frac{\\pi jk}N,\\quad k=1,2,...,N-1\n\\end{equation}\nwhere $N =2^{\\text{M}(1)}$, ($N_i=2^{\\text{M}(i)}$, $i=1$, ..., ND in the\nmulti-dimensional case.) In the equation labels above, the numeral 1, 2,\nor~3 denotes the Trigonometric, Cosine, or Sine transform, respectively,\nwhile the letter S or A denotes Synthesis or Analysis.\n\\renewcommand{\\theequation}{\\arabic{equation}}\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision, One-Dimensional Transform}\n\n\\begin{description}\n\\item[\\bf INTEGER]  \\ {\\bf M}(1){\\bf , ND, MS}\n\\item[\\bf REAL]  \\ {\\bf A}$(\\geq \\mu $)\\quad $[\\mu =2^{\\text{M}(1)}+1$\nfor a Cosine transform, and $=2^{\\text{M}(1)}$ for a Trigonometric transform or\nSine transform.]\n\\item[\\bf REAL]  \\ {\\bf S}$(\\geq \\nu {-}1$)\\quad $[\\nu =2^{\\text{M}(1)-2}$ for\na Trigonometric transform and $=2^{\\text{M}(1)-1}$ for a Cosine or Sine\ntransform.]\n\\item[\\bf CHARACTER TCS, MODE]  \\\n\\end{description}\n\nOn the initial call set MS to~0 to indicate the array S() does not yet\ncontain a sine table. Assign values to A(), TCS, MODE, M(), and ND = 1\nfor a one-dimensional transform.\n$$\n\\fbox{{\\bf CALL STCST(A, TCS, MODE, M, ND, MS, S)}}\n$$\nOn return A() will contain computed values. S() will contain the sine\ntable used in computing the Fourier transform. MS may have been changed.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A()]  [inout] If MODE selects analysis, A() contains $y$ on input and $%\n\\alpha $\\ and/or\\ $\\beta $ on output. If MODE selects synthesis, A()\ncontains $\\alpha $\\ and/or\\ $\\beta $ on input and $y$ on output. Let $N\n=2^{\\text{M}(1)}.$\n\nWhen A() contains $y$'s, the element $y_j$ is stored in A($j+1)$.\nThe range of $j$ is $[0, N-1]$ for the Trigonometric transform, $%\n[0, N]$ for the Cosine transform, and $[1, N-1]$ for\nthe Sine transform.\n\nFor the Trigonometric transform, the $\\alpha $'s and $\\beta $'s\nare stored as A($1)=\\alpha _0$, A($2)=\\alpha _{N/2}$, and ${%\n\\textstyle A}(2k+1)=\\alpha _k$, A($2k+2)=\\beta _k$, $k=1$, 2, ..., ($N/2)-1.$\n\nFor the Cosine transform, the $\\alpha $'s are stored as A($k+1)=\\alpha _k$,\n$k=0$, 1, ..., $N$.\n\nFor the Sine transform, the $\\beta $'s are stored as A($k+1)=\\beta\n_k$, $k=1$, 2, ..., $N-1$. Although the value contained in A(1) is\nirrelevant for the Sine transform, the subroutine does access this location,\nso A(1) must contain a valid floating-point number on entry and its value\nwill generally be changed on return.\n\n\\item[TCS]  [in] The character variable TCS selects the type of transform to\nbe done.\n\n$^{\\prime }\\text{T}^{\\prime }$ or $^{\\prime }\\text{t}^{\\prime }$ selects the Trigonometric\ntransform (Formula 1A or~1S).\n\n$^{\\prime }\\text{C}^{\\prime }$ or $^{\\prime }\\text{c}^{\\prime }$ selects the Cosine\ntransform (Formula 2A or~2S).\n\n$^{\\prime }\\text{S}^{\\prime }$ or $^{\\prime }\\text{s}^{\\prime }$ selects the Sine\ntransform (Formula 3A or~3S).\n\n\\item[MODE]  [in] The character variable MODE selects Analysis or Synthesis.\n\n$^{\\prime }\\text{A}^{\\prime }$ or $^{\\prime }\\text{a}^{\\prime }$ selects Analysis (Formula\n1A, 2A, or~3A).\n\n$^{\\prime }\\text{S}^{\\prime }$ or $^{\\prime }\\text{s}^{\\prime }$ selects Synthesis\n(Formula 1S, 2S, or~3S).\n\n\\item[M()] [in] Defines $N=2^{\\text{M}(1)}$.  The number of real data\npoints is $N$+1, $N$, and $N{-}$1, for the Cosine, Trigonometric, and Sine\ntransforms respectively.  Require 0~$\\leq \\text{M(1)} \\leq 31\\ (\\leq 30$\nfor the cosine or sine transform).  If M(1) is~0, no action is taken.\n\n\\item[ND]  [in] Number of dimensions, =1 for one-dimensional transforms.\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 M(1) $>$ 0, the\nsubroutine sets $\\text{MS}_{out} = \\max (\\text{M}(1), \\text{MS}_{in})$\nfor the Trigonometric transforms and to $\\text{MS}_{out} = \\max\n(\\text{M}(1)+1, \\text{MS}_{in})$ for the Cosine or Sine transforms.\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 \\text{NT})$, $j=1$, 2, ..., NT $-$ 1, see MS above.\n\\end{description}\n\n\\subsubsection{Program Prototype, Multi-dimensional Transforms}\n\n{\\bf INTEGER} \\ {\\bf M}($\\geq $ ND){\\bf , ND, MS}\n\n{\\bf REAL} \\ {\\bf A}($\\mu _1$, $\\mu _2$, ..., $\\geq \\mu _{ND})$\\quad $[\\mu\n_k=2^{\\text{M}(k)}+1$ for a Cosine transform and $=2^{\\text{M}(k)}$ for a\nTrigonometric or Sine transform.]\n\n{\\bf REAL} \\ {\\bf S}($\\geq \\max (\\nu _1$, $\\nu _2$, ..., $\\nu _{ND})-1)$%\n\\quad $[\\nu _k=2^{\\text{M}(k)-2}$ for a Trigonometric transform\nand $=2^{\\text{M}(k)-1}$\nfor a Cosine or Sine transform.]\n\n{\\bf CHARACTER TCS*($\\geq $ ND), MODE*($\\geq $ ND)}\n\nOn the initial call set MS to~0 to indicate the array S() does not yet\ncontain a sine table. Assign values to A(), TCS, MODE, M(), and ND.\n$$\n\\fbox{{\\bf CALL STCST(A, TCS, MODE, M, ND, MS, S)}}\n$$\nOn return A() contains the transformed data and S() contains the sine table\nused in computing the Fourier transform. The value of MS may have been\nchanged.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A()]  [inout] Array used for input and output data, see Functional\nDescription below for specification of the storage of items in A().\n\n\\item[TCS]  [in] The character TCS$(k$:$k)$ selects the type of transform to\nbe done in the $k^{th}$ dimension.\n\n$^{\\prime }\\text{T}^{\\prime }$ or $^{\\prime }\\text{t}^{\\prime }$ selects the Trigonometric\ntransform (Formula 1A or~1S).\n\n$^{\\prime }\\text{C}^{\\prime }$ or $^{\\prime }\\text{c}^{\\prime }$ selects the Cosine\ntransform (Formula 2A or~2S).\n\n$^{\\prime }\\text{S}^{\\prime }$ or $^{\\prime }\\text{s}^{\\prime }$ selects the Sine\ntransform (Formula 3A or~3S).\n\n\\item[MODE]  [in] The character MODE$(k$:$k)$ selects Analysis or Synthesis\nin the $k^{th}$ dimension.\n\n$^{\\prime }\\text{A}^{\\prime }$ or $^{\\prime }\\text{a}^{\\prime }$ selects Analysis (Formula\n1A, 2A, or~3A).\n\n$^{\\prime }\\text{S}^{\\prime }$ or $^{\\prime }\\text{s}^{\\prime }$ selects Synthesis\n(Formula 1S, 2S, or~3S).\n\n\\item[M()]  [in] In the $k^{th}$ dimension, $k=1$, ..., ND, define $%\nN_k=2^{\\text{M}(k)}$. The index range for the values $y_j$ in the $k^{th}$\ndimension is $[0,N_k-1]$ for the Trigonometric transform, $[0,N_k]$ for the\nCosine transform, and $[1,N_k-1]$ for the Sine transform. Require $0 \\leq\n\\text{M}(k)\\leq 31\\ (\\leq 30$ for the cosine or sine transform).  If\nM($k)=0$, no action is taken with respect to dimension $k$.\n\n\\item[ND]  [in] Number of dimensions, 1 $\\leq $ ND $\\leq $ 6.\n\n\\item[MS]  [inout]  As for MS in the one dimensional case above, except,\nif there is no error and  M($k) >$ 0 for some $k$, the\nsubroutine sets $\\text{MS}_{out} = \\max\n(\\mu _1$, $\\mu _2$, ..., $\\mu_{ND})$, $\\text{MS}_{in}$), where $\\mu _k=\n\\text{M}(k)$ for the Trigonometric transform,\nand $=\\text{M}(k)+1$ for the Cosine or Sine transform.  NT is defined\nin terms of $\\text{MS}_{out}$ as described in Section~B.2 above.\n\n\\item[S()]  [inout] When the sine table has been computed, S($j)=\\sin \\pi\nj/(2\\times \\text{NT})$, $j=1$, 2, ..., NT $-$ 1, see MS above.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange STCST to DTCST, and the REAL type statements to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nGiven%\n\\begin{equation*}\nf(t)=\\frac{2\\sinh t}{\\sinh \\pi t}\n\\end{equation*}\nobtain an estimate of $\\varphi (\\omega )=\\int_0^Tf(t)\\cos \\omega t\\,dt$ and\ncompare it with $\\varphi (\\omega )=\\sin (1)/(\\cosh \\omega +\\cos (1))$, the true\nsolution. Let $T$ and $\\Omega $ denote the largest values of $t$ and $\\omega $\nto be used in the computation. As was done below Eq.\\,(18) in Chapter~16.0,\nwe introduce the approximations%\n\\begin{multline*}\n\\varphi (\\omega ) = \\int_0^Tf(t)\\cos \\omega t\\,dt\\\\\n\\approx \\frac TN\\!\\left[ \\frac 12f(t_0)+\\!\\sum_{j=1}^{N-1}f(t_j)\\cos\n\\omega t_j+\\frac 12f(t_N)\\cos \\omega t_N\\right]\n\\end{multline*}\nwhere $t_j=j{T}/N$. With $\\omega _k=k\\pi /{T}$, we get%\n\\begin{equation*}\\hspace{-15pt}\n\\varphi (\\omega _k)\\!\\approx \\!\\frac T2\\frac 2N\\!\\left[ \\frac\n12f(t_0)\\!+\\!\\!\\sum_{j=1}^{N-1}\\!f(t_j)\\cos \\frac{\\pi jk}N\\!+\\!\\frac\n12f(t_N)(-1)^k\\!\\right]\n\\end{equation*}\nwhich except for the factor $T/2$ has the form of Eq.\\,(2A) above. Good\nresults are obtained by balancing the error due to a finite $T$ with the\nerror due to aliasing $(i.e$. use of a finite $\\Omega )$. Thus we want to\nselect $T$ and $\\Omega $ so that%\n\\begin{equation}\n\\int_T^\\infty |f(t)|\\,dt\\approx \\frac 2{\\pi -1}e^{-(\\pi -1)T}\\text{,\nand}\n\\end{equation}\\vspace{-10pt}\n\\begin{equation}\n\\int_\\Omega^\\infty |\\varphi (\\omega )|\\,d\\omega \\approx 2\\sin (1)e^{-\\Omega}\n\\end{equation}\nare of the same order of magnitude. Since%\n\\begin{equation*}\n\\int_T^\\infty |f(t)|\\,dt<10^{-4}\\int_0^T|f(t)|\\,dt\\quad \\text{for }T\\geq 10.\n\\end{equation*}\nthere is no point in choosing $T>10$. With $T=10$, $N=64$ gives $\\Omega =(%\nN \\pi /{T})=6.4\\pi $. The right hand sides of Equations (4) and (5) are\nthen $\\approx 4.7\\times 10^{-10}$ and $3.1\\times 10^{-9}$ respectively.\n\nThe program at the end of this chapter carries out the above calculations,\nbut prints results only for every $10^{th}$ value of $k$ to save space.\n\n\\subsection{Functional Description}\n\nThe one-dimensional transforms computed by this subroutine are given by\nequations (1S), (1A), ..., (3S), (3A). The multi-dimensional transform is\naccomplished by applying the appropriate one-dimensional transforms in each\ndimension. To define the relation between input and output contents of the\nA() array in the multi-dimensional case we introduce a 4-argument function,\nT(*,*,*,*), in which the first argument can take the values $%\n^{\\prime }\\text{T}^{\\prime }$,$^{\\prime }\\text{C}^{\\prime }$,\nor $^{\\prime }\\text{S}^{\\prime }$\nto denote Trigonometric, Cosine, or Sine, and the second argument can take\nthe values $^{\\prime }\\text{A}^{\\prime }$ or $^{\\prime }\\text{S}^{\\prime }$\nto denote Analysis or Synthesis. The third and fourth arguments are integers.\nThere is also an implied argument, M, which together with the first\nargument contributes to the definition of $N$ and $\\mu $.\n\\begin{equation*}\n\\hspace{-15pt}N=2^M\n\\end{equation*}\\vspace{-30pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{T}^{\\prime }{,}^{\\prime }\n\\text{S}^{\\prime },j,k)=\\begin{cases}\n1/2 & k=0\\\\\n\\cos (\\pi jk/N)& k=2,4,...,N\\!-\\!2\\\\\n\\sin (\\pi j(k-1)/N)& k=3,5,...,N\\!-\\!1\\\\\n(1/2)(-1)^j& k=1\n\\end{cases}\n\\end{equation*}\\vspace{-10pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{T}^{\\prime }{,}^{\\prime }\n\\text{A}^{\\prime },j,k)\\!=\\!\\frac 2N\n\\begin{cases}\n\\cos (\\pi jk/N)&\\!\\!j\\!=\\!0,2,...,N\\!-\\!2 \\\\\n\\sin (\\pi (j\\!-\\!1)k/N)&\\!\\!j\\!=\\!3,5,...,N\\!-\\!1 \\\\\n(-1)^k,&\\!\\!j\\!=\\!1\n\\end{cases}\n\\end{equation*}\\vspace{-15pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{C}^{\\prime }{,}^{\\prime }\n\\text{S}^{\\prime },j,k)=\n\\begin{cases}\n1/2& k=0 \\\\\n\\cos (\\pi jk/N)& k=1,2,...,N-1 \\\\\n(1/2)(-1)^j& k=N\n\\end{cases}\n\\end{equation*}\\vspace{-15pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{C}^{\\prime }{,}^{\\prime }%\n\\text{A}^{\\prime },j,k)=\\frac 2N\\text{T(}%\n^{\\prime }\\text{C}^{\\prime },^{\\prime }\\text{S}^{\\prime },j,k)\n\\end{equation*}\\vspace{-15pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{S}^{\\prime }{,}^{\\prime }%\n\\text{S}^{\\prime },j,k)=\\sin \\frac{\\pi jk}N\n\\end{equation*}\\vspace{-15pt}\n\\begin{equation*}\n\\hspace{-15pt}\\text{T(}^{\\prime }\\text{S}^{\\prime }{,}^{\\prime }%\n\\text{A}^{\\prime },j,k)=\\frac 2N\\text{T(}^{\\prime }\\text{S}^{\\prime},%\n^{\\prime }\\text{S}^{\\prime },j,k)\n\\end{equation*}\\vspace{-15pt}\n\\begin{equation*}\n\\hspace{-15pt}\\mu _i=\n\\begin{cases}\n2^{\\text{M}(i)}& \\text{for a Trigonometric or Sine transform} \\\\\n2^{\\text{M}(i)}+\\!1& \\text{for a Cosine transform}\n\\end{cases}\n\\end{equation*}\n\nThe array A has its contents replaced according to the formula%\n\\begin{multline*}\n\\hspace{-5pt}A(j_1,j_2,...,j_{ND})=\\sum_{k_1=1}^{\\mu _1}\\cdots\n\\sum_{k_{ND}=1}^{\\mu_{ND}}A(k_1,k_2,...,k_{ND})\\\\\\hspace{-15pt}\n\\times \\text{T(TCS(1:1), MODE(1:1), }j_1-1,k_1-1)\\times \\cdots\\\\\n\\hspace{-15pt}\\times \\text{T(TCS(ND:ND), MODE(ND:ND), }j_{ND}-1,k_{ND}-1),\n\\end{multline*}\nwhere $j_i=1,2,...,\\mu _i$ and storage conventions with respect to each\ndimension are defined as for the one dimensional transforms.\n\nThe computational procedure for the trigonometric transform in the\none-dimensional case is almost identical to the procedure used in SRFT1.\n(See the second paragraph below Eq.\\,10 in Chapter~16.0 to see why this is\nso.)\n\nThe procedure for the cosine transform uses the trigonometric transform and\nthe identity%\n\\begin{equation*}\n\\hspace{-0pt}\\cos \\frac{\\pi j(2k+1)}N=\\frac{\\sin (2\\pi j(k+1)/N)-\\sin\n(2\\pi jk/N)}{2\\sin (\\pi j/N)}.\n\\end{equation*}\nThis is used to transform%\n\\begin{equation*}\ny_j=\\frac 12\\eta _0+\\frac 12\\eta _N(-1)^j+\\sum_{k=1}^{N-1}\\eta _k\\cos \\frac{%\n\\pi jk}N\n\\end{equation*}\nto%\n\\begin{multline*}\ny_j=\\frac 12\\eta _0+\\frac 12\\eta _N(-1)^j+\\sum_{k=1}^{(N/2)-1}\\eta _{2k}\\cos\n\\frac{2\\pi jk}N\\\\\n+\\frac 1{2\\sin (\\pi j/N)}\\sum_{k=1}^{(N/2)-1}(\\eta\n_{2k-1}-\\eta _{2k+1})\\sin \\frac{2\\pi jk}N.\n\\end{multline*}\nLet $Y_j$ be the result from the trigonometric transform with $\\alpha\n_k=\\eta _{2k}$, $k=0$, 1, ..., $N/2$ and $\\beta _k=\\eta _{2k-1}-\\eta _{2k+1}$%\n, $k=1,2,...,(N/2)-1$. It follows that%\n\\begin{eqnarray*}\n   y_j+y_{N-j}   & = & Y_j+Y_{N-j} \\\\\n   y_j-y_{N-j}  & = & \\frac{Y_j-Y_{N-j}}{2\\sin (\\pi j/N)}\n\\end{eqnarray*}\nand thus one can compute $y_j$ from $Y_j$. The computational\nprocedure is to compute the $\\alpha $'s and $\\beta $'s\nfrom the $\\eta $'s (the $\\alpha $'s require no\ncomputation), use the trigonometric transform to get the $Y$'s, and\nthe $Y$'s to compute the $y$'s. The inverse transform is\nexactly the same except for a factor of 2/$N$ as is clear from\nEqs.\\,(2S) and (2A).\n\nThe sine transform is obtained in a very similar way to the cosine\ntransform. Details can be found in \\cite{Krogh:1970:SCT}.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nRequire 1 $\\leq $ ND $\\leq $ 6, and $0 \\leq \\text{M}(k)\\leq 31$ for the\nTrigonometric transform, $0 \\leq \\text{M}(k)\\leq 30$ for the Cosine and\nSine transforms.  Require that TCS and MODE have only the allowed values.\nOn violation of any of these conditions the subroutine issues an error\nmessage using the error processing procedures of Chapter~19.2 with\nseverity level $=2$ to cause execution to stop.  A return will be made\nwith MS $=-2$ instead of stopping if the statement ``CALL\\ ERMSET($-1$)''\nis executed before calling 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} \\\\\nDTCST & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n DFFT, DTCST, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSTCST & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n ERFIN, ERMSG, IERM1, IERV1, SFFT, STCST}\\\\\n\\end{tabular}\n\nSubroutine designed and written by: Fred T. Krogh, JPL, August~1969, revised\nJanuary~1988.\n\n\n\\begcode\n\n\\medskip\\\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSTCST}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{stcst}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSTCST}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{stcst}}\n\\end{document}\n", "meta": {"hexsha": "10307ff79c1f84d5b974b8f97c8b62243176462c", "size": 17746, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch10-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/ch10-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/ch10-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": 40.423690205, "max_line_length": 98, "alphanum_fraction": 0.6622900935, "num_tokens": 6581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959543, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6157963947925925}}
{"text": "\\chapter*{Appendix C: Nonlinear Pyramidal Wavelet Transform (WT-PMT)}\n\\addcontentsline{toc}{chapter}{Appendix C: Pyramidal Wavelet Transform (PMWT)}\n\nOne of the advantages of the pyramidal wavelet transform over the pyramidal\nmedian transform (PMT) is the ability to have robust noise estimation in the \ndifferent scales, while the advantage of the PMT is a better separation\nof the structures in the scales. Using the PMT, \na strong structure (like a bright star, cosmic rays, bad pixels, etc.) will \nnot be spread over all scales as when using a wavelet transform. In fact, when\nthere is no signal in a given region, a wavelet transform would be better, and\nif a strong signal appears, it is the PMT that we would like to use. So the \nidea arises \nto try to merge both transforms, and to adapt the analysis at each position\nand at each scale, depending on the amplitude of the coefficient we measure.\n\nA possible algorithm to perform this on an image $I$ is the following:\n\\begin{enumerate}\n\\item Let $c_j = I$, and $j=0$.\n\\item Filter the the image $c_j$ by the median: we get $m_j$\n\\item Set $c_j^* = c_j$ and $d_j= c_j - m_j$\n\\item For all pixels $k$ do \\\\\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \n if $\\mid d_j(k) \\mid > k \\sigma_j$ then $c_j^*(k) = m_j(k)$\n\\item Smooth $c_j^*$  by a B$_3$-spline: we get $b_j$\n\\item Set $w_j = c_j - b_j$\n\\item  $c_{j+1} = dec(b_j)$ (where the decimation operation, dec, entails 1 pixel replacing\neach 2 $\\times$2 subimage).\nLet $j=j+1$ and return to step 2 if $j < N_s$ ($N_s$ being the number of scales).\n\\end{enumerate}\nIn this algorithm, the linear filtering relative to the wavelet transform is\nnot applied to the strong features contained in the image. Indeed, significant\npixel values are detected at step 4, and are replaced by the median. Regions\ncontaining no bright object are treated as if the pyramidal wavelet \ntransform  is used. The parameter $k$ used at step 4 must be large enough\nin order to be sure that noise is not filtered by the median ($k=5$ seems\nhigh enough). As this transform merges the wavelet transform and the PMT, \nwe call it the PMWT transform. \nPMWT takes more time than the PMT, but this algorithm has the\nadvantages of the PMT without the drawbacks. The reconstruction is the\nsame as for the PMT.\n\n\n\\chapter*{Appendix D: Half Pyramidal Wavelet Transform}\n\\addcontentsline{toc}{chapter}{Appendix D: Half Pyramidal Wavelet Transform}\n\nAt each iteration of the pyramidal transform, there is a smoothing and \na decimation of the image. But the smoothing is not strong enough to\nreduce the cut-off frequency by a factor two. The decimation then violates\nShannon's theorem. To avoid this problem, which may create artifacts, \nBijaoui \\cite{wave:bijaoui97}\nproposed not to decimate the image at the first iteration of the algorithm.\nThis means that the two first scales have the same size as the original image\n(instead of just one in the standard pyramidal transform). Then the two first\niterations are identical as in the \\`a trous algorithm. For the\nfollowing iterations, there is a decimation and the filtering is done\nas for the second iteration (i.e.\\ by taking pixels interspersed by \none pixel for the filtering).\n\n\\newpage\n$ $\n\n", "meta": {"hexsha": "56f5b5e98288bab0eb57feb8b20058b02f95c478", "size": 3194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/annex_wavemed.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_mr1/annex_wavemed.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_mr1/annex_wavemed.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": 51.5161290323, "max_line_length": 91, "alphanum_fraction": 0.7570444584, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920068519376, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6157963942124481}}
{"text": "%{\n\\begin{octave}\n%}\nsheffieldmlToolboxes;\n%{\n\\end{octave}\n\n\\title{SheffieldML - MATLAB Software}\n\n\\begin{document}\n\\section{Examples}\n\n\\section{Gaussian Process Models}\n\n\\subsection{Functions from Gaussians}\n\nThis example shows how points which look like they come from a\nfunction to be sampled from a Gaussian distribution. The sample is 25\ndimensional and is from a Gaussian with a particular covariance.\n\n\\begin{octave}\n%}\ndemGpSample\n%{\n\\end{octave}\n\n\\begin{center}\n\\inputdiagram{gpSample}\\hfill\\inputdiagram{gpCovariance}\n\n\\emph{Left} A single, 25 dimensional, sample from a Gaussian\ndistribution. \\emph{Right} the covariance matrix of the Gaussian\ndistribution.\n\n\\end{center}\n\n\n\\subsection{Joint Distribution over two Variables}\n\nGaussian processes are about conditioning a Gaussian distribution\non the training data to make the test predictions. To illustrate this\nprocess, we can look at the joint distribution over two variables.\n\n\\begin{octave}\n%}\n demGpCov2D([1 2])\n%{\n\\end{octave}\n\nGives the joint distribution for $f_1$ and\n$f_2$. The plots show the joint distributions as well\nas the conditional for $f_2$ given\n$f_1$.\n\n\\begin{center}\n\\inputdiagram{demGpCov2D1_2_3} 0.5\\textwidth \\inputdiagram{demGpCov2D1_5_3} 0.5\\textwidth \n\n\\emph{Left} Blue line is\ncontour of joint distribution over the variables $f_1$\nand $f_2$. Green line indicates an observation of\n$f_1$. Red line is conditional distribution of\n$f_2$ given $f_1$. \\emph{Right} Similar\nfor $f_1$ and $f_5$.  \n\\end{center}\n\n\n\n\\subsection{Different Samples from Gaussian Processes}\n\nA script is provided which samples from a Gaussian process with the\nprovided covariance function.\n\n\\begin{octave}\n%}\n gpSample('rbf', 10, [1 1], [-3 3], 1e5)\n%{\n\\end{octave}\n\nwill give 10 samples from an RBF covariance function with a\nparameter vector given by [1 1] (inverse width 1, variance 1) across\nthe range -3 to 3 on the $x$-axis. The random seed will be set to\n1e5.\n\n\\begin{octave}\n%}\n gpSample('rbf', 10, [16 1], [-3 3], 1e5)\n%{\n\\end{octave}\n\nis similar, but the inverse width is now set to 16 (length scale 0.25).\n\n\\begin{center}\\inputdiagram{gpSampleRbfSamples10Seed100000InverseWidth1Variance1} 0.5\\textwidth \\inputdiagram{gpSampleRbfSamples10Seed100000InverseWidth16Variance1} 0.5\\textwidth \\emph{Left} samples from an RBF style covariance function\nwith length scale 1. \\emph{Right} samples from an RBF style covariance\nfunction with length scale 0.25.  \n\\end{center}\n\nOther covariance functions can be sampled, an interesting one is\nthe MLP covariance which is non stationary and can produce point\nsymmetric functions,\n\n\n\\begin{octave}\n%}\n gpSample('mlp', 10, [100 100 1], [-1 1], 1e5)\n%{\n\\end{octave}\n\ngives 10 samples from the MLP covariance function where the `bias\nvariance' is 100 (basis functions are centered around the origin\nwith standard deviation of 10) and the `weight variance' is\n100.\n\n\\begin{octave}\n%}\n gpSample('mlp', 10, [100 1e-16 1], [-1 1], 1e5)\n%{\n\\end{octave}\n\ngives 10 samples from the MLP covariance function where the `bias\nvariance' is approximately zero (basis functions are placed on\nthe origin) and the `weight variance' is 100.\n\n\\begin{center}\\inputdiagram{gpSampleMlpSamples10Seed100000WeightVariance100BiasVariance100Variance1} 0.5\\textwidth \\inputdiagram{gpSampleMlpSamples10Seed100000WeightVariance100BiasVariance1e-16Variance1}\n0.5\\textwidth \\emph{Left} samples from an MLP style covariance\nfunction with bias and weight variances set to 100. \\emph{Right}\nsamples from an MLP style covariance function with weight variance 100\nand bias variance approximately zero.  \n\\end{center}\n\n\n\\subsection{Posterior Samples}\n\nGaussian processes are non-parametric models. They are specified by their covariance function and a mean function. When combined with data observations a posterior Gaussian process is induced. The demos below show samples from that posterior.\n\n\\begin{octave}\n%}\n  gpPosteriorSample('rbf', 5, [1 1], [-3 3], 1e5)\n%{\n\\end{octave}\n\nand \n\n\\begin{octave}\n%}\n  gpPosteriorSample('rbf', 5, [16 1], [-3 3], 1e5)\n%{\n\\end{octave}\n\n\\begin{center}\\inputdiagram{gpPosteriorSampleRbfSamples5Seed100000InverseWidth1Variance1bw} 0.5\\textwidth \\inputdiagram{gpPosteriorSampleRbfSamples5Seed100000InverseWidth16Variance1bw} 0.5\\textwidth \n\n\\emph{Left} samples from the posterior induced by an RBF style covariance function\nwith length scale 1 and 5 `training' data points taken from a sine wave. \\emph{Right} Similar but for a length scale of 0.25.  \n\\end{center}\n\n\\subsection{Simple Interpolation Demo}\n\nThis simple demonstration plots, consecutively, an increasing\nnumber of data points, followed by an interpolated fit through the\ndata points using a Gaussian process. This is a noiseless system, and\nthe data is sampled from a GP with a known covariance function. The\ncurve is then recovered with minimal uncertainty after only nine data\npoints are included. The code is run with\n\n\\begin{octave}\n%}\n demInterpolationGp\n%{\n\\end{octave}\n\n\\begin{center}\n\n\\inputdiagram{demInterpolation3} 0.5\\textwidth \\inputdiagram{demInterpolation4} 0.5\\textwidth\n\nGaussian process prediction \\emph{left} after two points with a new\ndata point sampled \\emph{right} after the new data point is included\nin the prediction. \n\n\\inputdiagram{demInterpolation7} 0.5\\textwidth \\inputdiagram{demInterpolation8} 0.5\\textwidth\n\nGaussian process prediction \\emph{left} after five points with a four\nnew data point sampled \\emph{right} after all nine data points are\nincluded. \n\\end{center}\n\n\\subsection{Simple Regression Demo}\n\nThe regression demo very much follows the format of the\ninterpolation demo. Here the difference is that the data is sampled\nwith noise. Fitting a model with noise means that the regression will\nnot necessarily pass right through each data point.\n\nThe code is run with\n\n\\begin{octave}\n%}\n demRegressionGp\n%{\n\\end{octave}\n\n\n\\begin{center}\n\\inputdiagram{demRegression3} 0.5\\textwidth \\inputdiagram{demRegression4} 0.5\\textwidth\n\nGaussian process prediction \\emph{left} after two points with a new\ndata point sampled \\emph{right} after the new data point is included\nin the prediction. \n\n\\inputdiagram{demRegression7} 0.5\\textwidth \\inputdiagram{demRegression8} width 0.5\\textwidth\n\nGaussian process prediction \\emph{left} after five points with a four\nnew data point sampled \\emph{right} after all nine data points are\nincluded. \n\\end{center}\n\n\\subsection{Optimizing Hyper-parameters}\n\nOne of the advantages of Gaussian processes over pure kernel\ninterpretations of regression is the ability to select the hyper\nparameters of the kernel automatically. The demo\n\n\\begin{octave}\n%}\n demOptimiseGp\n%{\n\\end{octave}\n\nshows a series of plots of a Gaussian process with different length\nscales fitted to six data points. For each plot there is a\ncorresponding plot of the log likelihood. The log likelihood peaks for\na length scale equal to 1. This was the length scale used to generate\nthe data.\n\n\\begin{center}\\inputdiagram{demOptimiseGp1} 0.33\\textwidth \\inputdiagram{demOptimiseGp3} 0.33\\textwidth \\inputdiagram{demOptimiseGp5}\n0.33\\textwidth \\inputdiagram{demOptimiseGp7} 0.33\\textwidth \\inputdiagram{demOptimiseGp9} 0.33\\textwidth \\inputdiagram{demOptimiseGp11} 0.33\\textwidth \\inputdiagram{demOptimiseGp13} 0.33\\textwidth \\inputdiagram{demOptimiseGp15} 0.33\\textwidth \\inputdiagram{demOptimiseGp17}\n0.33\\textwidth\n\nFrom top left to bottom right, Gaussian process\nregression applied to the data with an increasing length scale. The\nlength scales used were 0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8 and\n16. \n\n\\inputdiagram{demOptimiseGp18} 0.5\\textwidth \n\nLog-log plot of\nthe log likelihood of the data against the length scales. The log\nlikelihood is shown as a solid line. The log likelihood is made up of\na data fit term (the quadratic form) shown by a dashed line and a\ncomplexity term (the log determinant) shown by a dotted line. The data\nfit is larger for short length scales, the complexity is larger for\nlong length scales. The combination leads to a maximum around the true\nlength scale value of 1.\n\n\\end{center}\n\n\\subsection{Regression over Motion Capture Markers}\n\nAs a simple example of regression for real data we consider a motion capture data set. The data is <a href=\"http://accad.osu.edu/research/mocap/mocap_data.htm\">from Ohio State University</a>. In the example script we perform Gaussian process regression with time as the input and the x,y,z position of the marker attached to the left ankle. To demonstrate the behavior of the model when the marker is lost, we remove data from This code can be run with\n\n\\begin{verbatim}  \ndemStickGp1 \n\\end{verbatim} \n\n\\begin{octave}\n%}\nload('demStickGp1');\n% Plot results\nfillColor = [0.7 0.7 0.7];\ntTest = linspace(0, 2, 200)';\n[mu, varSigma] = gpPosteriorMeanVar(model, tTest);\n\nfor i = 1:length(outputIndex);\n  figure\n  fill([tTest; tTest(end:-1:1)], ...\n       [mu(:, i); mu(end:-1:1, i)] ...\n       + 2*[sqrt(varSigma(:, i)); -sqrt(varSigma(end:-1:1, i))], ...\n       fillColor,'EdgeColor',fillColor)\n  hold on;\n  plot(t(testIndex), y(testIndex, outputIndex(i)), 'ko');\n  b=plot(tTrain, yTrain(:, i), 'k.');\n  a = plot(tTest, mu(:, i), 'k-');\n  set(gca, 'xlim', [0 2])\n  set(a, 'linewidth', 2);\n  fileName = ['dem' capName 'Gp' num2str(experimentNo) 'Out' num2str(i)];\n  printLatexPlot(fileName, '../tex/diagrams', 0.3*textWidth, options);\nend\n%{\n\\end{octave}\n\nThe code will optimize hyper parameters and show plots of the posterior process through the training data and the missing test points.\n\nThe result of the script is given in the plot below.  \n\n\\begin{center}\n\\inputdiagram{demStickGp1Out1} 0.3\\textwidth \\inputdiagram{demStickGp1Out2} 0.3\\textwidth\"> <\\inputdiagram{demStickGp1Out3} width\n=\"0.3\\textwidth\"> Gaussian process regression through the x (left), y (middle) and z (right) position of the left ankle. Training data is shown as black spots, test points removed to simulate a lost marker are shown as circles, posterior mean\nprediction is shown as a black line and two standard deviations are\ngiven as grey shading.\\end{center}\n\nNotice how the error bars are tight except in the region where the training data is missing and in the region where the training data disappears.\n\n\\subsection{Sparse Pseudo-input Gaussian Processes}\n\nThe sparse approximation used in this toolbox is based on the\nSparse Pseudo-input Gaussian Process model described by <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Snelson:pseudo05&printAbstract=1\">Snelson\nand Ghahramani</a>. Also provided are the extensions suggested by <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Quinonero:unifying05\">Qui&ntilde;onero-Candela\nand Rasmussen</a>. They provide a unifying terminology for describing\nthese approximations which we shall use in what follows.\n\nThere are three demos provided for Gaussian process regression in\n1-D. They each use a different form of likelihood approximation. The\nfirst demonstration uses the `projected latent variable'\napproach first described by <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Csato:sparse02&printAbstract=1\">Csato\nand Opper</a> and later used by <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Seeger:fast03&printAbstract=1\">Seeger\n<i>et al.</i></a>. In the terminology of Qui&ntilde;onero-Candela and\nRasmussen (QR-terminology) this is known as the `deterministic\ntraining conditional' (DTC) approximation.\n\nTo use this approximation the following script can be run.\n\n\\begin{octave}  \n%}\ndemSpgp1dGp1 \n%{\n\\end{octave} \n\nThe result of the script is\ngiven in the plot below.  \n\n\\begin{center}<\\inputdiagram{demSpgp1dGp1} width\n=\"0.5\\textwidth\"> Gaussian process using the DTC approximation with nine\ninducing variables. Data is shown as black spots, posterior mean\nprediction is shown as a black line and two standard deviations are\ngiven as grey shading.\\end{center}\n\nThe improved approximation suggested by Snelson and Ghahramani, in\nQR-terminology this is known as the fully independent training\nconditional (FITC). To try this approximation run the following script\n\n\\begin{octave}\n%}  \ndemSpgp1dGp2 \n%{\n\\end{octave}\n\nThe result of the script is given on the left of the plot below.\n\n\\begin{center}\\inputdiagram{demSpgp1dGp2} width=\"0.49\\textwidth\"><img\nsrc=\"demSpgp1dGp3} width=\"0.49\\textwidth\">\n\n\\emph{Left}: Gaussian process using the FITC approximation with nine\ninducing variables. Data is shown as black spots, posterior mean\nprediction is shown as a black line and two standard deviations are\ngiven as grey shading. \\emph{Right}: Similar but for the PITC\napproximation, again with nine inducing variables.\\end{center}\n\nAt the <a href=\"http://www.dcs.shef.ac.uk/ml/gprt/\">Sheffield\nGaussian Process Round Table</a> Lehel Csato pointed out that the\nBayesian Committee Machine of <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?group=bcm&printAbstract=1\">Schwaighofer\nand Tresp</a> can also be viewed within the same framework. This idea\nis formalised in <a\nhref=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Quinonero:unifying05&printAbstract=1\">Qui&ntilde;onero-Candela\nand Rasmussen's</a> review. This approximation is known as the\n`partially independent training conditional' (PITC) in\nQR-terminology. To try this approximation run the following script\n\n\\begin{octave}\n%}\n demSpgp1dGp3\n%{\n\\end{octave}\n\nThe result of the script is given on the right of the plot above.\n\nFinally we can compare these results to the result from the full\nGaussian process on the data with the correct hyper-parameters. To do\nthis the following script can be run.\n\n\\begin{octave}\n%}\n demSpgp1dGp4\n%{\n\\end{octave}\n\nThe result of the script is given in the plot below.\n\n\\begin{center}\\inputdiagram{demSpgp1dGp4} width=\"0.5\\textwidth\"> Full Gaussian\nprocess on the toy data with the correct hyper-parameters. Data is\nshown as black spots, posterior mean prediction is shown as a black\nline and two standard deviations are given as grey shaded\narea.\\end{center}\n\n\\section{Gaussian Process Latent Variable Model Examples}\n\nThe three approximations outlined above can be used to speed up learning in the GP-LVM. They have the advantage over the IVM approach taken in the <a href=\"http://ml.sheffield.ac.uk/~neil/gplvm/\">original GP-LVM toolbox</a> that the algorithm is fully convergent and the final mapping from latent space to data space takes into account all of the data (not just the points in the active set).\n\nAs well as the new sparse approximation the new toolbox allows the GP-LVM to be run with dynamics as suggested by <a href=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Wang:gpdm05&printAbstract=1\">Wang <i>et al.</i></a>.\n\nFinally, the new toolbox allows the incorporation of `back constraints' in learning. Back constraints force the latent points to be a smooth function of the data points. This means that points that are close in data space are constrained to be close in latent space. For the standard GP-LVM points close in latent space are constrained to be close in data space, but the converse is not true.\n\nVarious combinations of back constraints and different approximations are used in the exmaples below.\n\n\\subsection{Oil Data}\n\nThe `oil data' is commonly used as a bench mark for visualisation algorithms. For more details on the data see <a href=\"http://www.ncrg.aston.ac.uk/GTM/3PhaseData.html\">this page</a>.\n\nThe <a href=\"http://ml.sheffield.ac.uk/~neil/gplvmcpp\">C++ implementation of the GP-LVM</a> has details on training the full GP-LVM with this data set. Here we will consider the three different approximations outlined above.\n\n\\subsubsection{FITC Approximation}\n\nIn all the examples we give there will be 100 points in the active set. We first considered the FITC approximation. The script \\texttt{demOilFgplvm1.m} runs the FITC approximation giving the result on the left of the figure shown below.\n\n\\begin{center}\\inputdiagram{demOilFgplvm1} width=\"0.49\\textwidth\">\\inputdiagram{demOilFgplvm2} width=\"49%\">\n\\emph{Left}: GP-LVM on the oil data using the FITC approximation without back constraints. The phases of flow are shown as green circles, red crosses and blue plusses.  One hundred inducing variables are used. \\emph{Right}: Similar but for a back-constrained GP-LVM, the back constraint is provided by a multi-layer perceptron with 15 hidden nodes.\\end{center}\n\nBack constraints can be added to each of these approximations. In the example on the right we used a back constraint given by a multi-layer perceptron with 15 hidden nodes. This example can be recreated with \\texttt{demOilFgplvm2.m}.\n\n\\subsubsection{DTC Approximation}\n\nThe other approximations can also be used, in the figures below we give results from the DTC approximation. The can be recreated using \\texttt{demOil3.m} and \\texttt{demOil4.m}.\n\n\\begin{center}\\inputdiagram{demOilFgplvm3} width=\"49%\">\\inputdiagram{demOilFgplvm4} width=\"49%\">\n\\emph{Left}: GP-LVM on the oil data using the DTC approximation without back constraints. The phases of flow are shown as green circles, red crosses and blue plusses.  One hundred inducing variables are used. \\emph{Right}: Similar but for a back-constrained GP-LVM, the back constraint is provided by a multi-layer perceptron with 15 hidden nodes.\\end{center}\n\n\\subsubsection{PITC Approximation}\n\nWe also show results using the PITC approximation, these results can be recreated using the scripts \\texttt{demOilFgplvm5.m} and \\texttt{demOilFgplvm6.m}.\n\n\\begin{center}\\inputdiagram{demOilFgplvm5} width=\"49%\">\\inputdiagram{demOilFgplvm6} width=\"49%\">\n\\emph{Left}: GP-LVM on the oil data using the PITC approximation without back constraints. The phases of flow are shown as green circles, red crosses and blue plusses.  One hundred inducing variables are used. \\emph{Right}: Similar but for a back-constrained GP-LVM, the back constraint is provided by a multi-layer perceptron with 15 hidden nodes.\\end{center}\n\n\\subsubsection{Variational DTC Approximation}\n\nFinally we also show results using the variational DTC approximation of Titsias, these results can be recreated using the scripts \\texttt{demOilFgplvm7.m} and \\texttt{demOilFgplvm8.m}.\n\n\\begin{center}\\inputdiagram{demOilFgplvm7} width=\"49%\">\\inputdiagram{demOilFgplvm8} width=\"49%\">\n\\emph{Left}: GP-LVM on the oil data using the variational DTC approximation without back constraints. The phases of flow are shown as green circles, red crosses and blue plusses.  One hundred inducing variables are used. \\emph{Right}: Similar but for a back-constrained GP-LVM, the back constraint is provided by a multi-layer perceptron with 15 hidden nodes.\\end{center}\n\n\n\\subsection{Back Constraints and Dynamics}\n\nFirst we will demonstrate the dynamics functionality of the toolbox. We raw x-y-z values from a motion capture data set, the \\texttt{Figure Run 1} example available <a href=\"http://accad.osu.edu/research/mocap/mocap_data.htm\">from Ohio State University</a>. To run without dynamics use the script:\n\\texttt{\n demStickFgplvm1\n\\end{octave}\n\nThe results are given on the left of the figure below.\n\n\\begin{center}\\inputdiagram{demStickFgplvm1} width=\"49%\">\nGP-LVM on the motion capture data without dynamics in the latent space. \\end{center}\n\nNotice that the sequence (which is a few strides of a man running) is split into several sub-sequences. These sub-sequences are aligned to the strides of the man. By introducing a dynamics prior, we can force the sequence to link up. Samples from the dynamics prior used are shown in the plot below.\n\n\\begin{center}\\inputdiagram{dynamicsSamp1} width=\"49%\">\\inputdiagram{dynamicsSamp2} width=\"49%\">\n\\inputdiagram{dynamicsSamp3} width=\"49%\">\\inputdiagram{dynamicsSamp4} width=\"49%\">\nSamples from the dynamics prior which is placed over the latent space. This prior has \\emph{Left}: GP-LVM on the motion capture data without dynamics in the latent space. \\emph{Right}: GP-LVM with dynamics. Samples from the dynamics prior used are given in the figure above.\\end{center}\n\nThis prior is used in the model to obtain the results below,\n\n\\begin{octave}\n demStickFgplvm2\n\\end{octave}\n\n\\begin{center}\\inputdiagram{demStickFgplvm2} width=\"49%\">\nGP-LVM with dynamics. Samples from the dynamics prior used are given in the figure above.\\end{center}\n\nNote now the circular form of the latent space. \n\nBack constraints can also be used to achieve a similar effect,\n\n\\begin{octave}\n demStickFgplvm3\n\\end{octave}\n\n\\begin{center}\\inputdiagram{demStickFgplvm3} width=\"49%\">\nGP-LVM with back constraints. A RBF kernel mapping was used to form the back constraints with the inverse width set to 1e-4 (\\emph{i.e.}length scale set to 100).\\end{center}\n\n\\subsection{Loop Closure in Robotics}\n\nIn on-going work with Dieter Fox and Brian Ferris at the University of Washington we are interested in loop closure for robotic navigation, included as an example is a data set of a robot completing a loop while reading wireless access point signal strengths. To produce a neat track and close the loop it turns out it is necessary to use dynamics and back constraints as seen in the images below. These results can be recreated with \\texttt{demRobotWireless1.m} through \\texttt{demRobotWireless4.m}.\n}\n\n\\begin{center}\\inputdiagram{demRobotWireless1} width=\"49%\">\\inputdiagram{demRobotWireless2} width=\"49%\">\n\\inputdiagram{demRobotWireless3} width=\"49%\">\\inputdiagram{demRobotWireless4} width=\"49%\">\nUse of back constraints and dynamics to obtain loop closure in a robot navigation example. \\emph{Top Left}: GP-LVM without back constraints or dynamics, \\emph{Top right}: GP-LVM with back constraints, no dynamics, \\emph{Bottom Left}: GP-LVM with dynamics, no back constraints, \\emph{Bottom right}: GP-LVM with back constraints and dynamics. \\end{center}\n\n\\subsection{Vocal Joystick and Vowel Data}\n\nAnother ongoing piece of work with Jeff Bilmes and Jon Malkin involves embedding vowel sounds in a two dimensional space as part of <a href=\"http://ssli.ee.washington.edu/vj\">vocal joystick</a> system. Jon has provided a simple data set of 2,700 examples of different vowels. These are embedded in a two dimensional latent space with and without back constraints.\n\n\\begin{center}\\inputdiagram{demVowels2} width=\"49%\">\\inputdiagram{demVowels3} width=\"49%\">\n\\emph{Left}: embedding of the vowel data without back constraints, \\emph{Right}: embedding of the vowel data with back constraints. $/a/$ - red cross, $/ae/$ - green circle, $/ao/$ - blue plus, $/e/$ - cyan asterix, $/i/$ - magenta square, $/ibar/$ - yellow diamond, $/o/$ - red down triangle, $/schwa/$ - green up triangle, $/u/$ - blue left triangle.\n\\end{center}\n\n\\subsection{Larger Human Motion Data Sets}\n\nFor <a href=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Lawrence:larger07&printAbstract=1\">an AISTATS paper</a> we recreated an experiment from <a href=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Taylor:motion06&printAbstract=1\">Taylor <em>et al.</em>'s NIPS paper</a>. They created a data set from a motion capture data in the <a href=\"http://mocap.cs.cmu.edu\">CMU data base</a> of running and walking. The data set can now be recreated using the <a href=\"/~neil/datasets/\">DATASETS toolbox</a>. We repeated missing data experiments by Taylor et al.. The model learning for these experiments can be recreated with:\n\n\\begin{octave}\n demCmu35gplvm1\n\\end{octave}\n\nfor the four dimensional latent space, \\texttt{demCmu35gplvm2} for the three dimensional latent space and \\texttt{demCmu35gplvm3} for the five dimensional latent space. The test data reconstruction can then be performed for all models with \\texttt{demCmu35gplvmReconstruct}. Taylor <i>et al.</i>'s nearest neighbour results can be recreated using \\texttt{demCmu35TaylorNearestNeighbour}.\n\nData was pre-processed by mapping angles to be between -180 and 180 and scaling the data such that the variance of each dimension was one.\nThe quality of the trained model was evaluated using a missing data problem with a test sequence of data. The model was required to fill in either upper body angles or right leg angles. Results for the GP-LVM and nearest neighbour in both scaled space and original angle space are given in the table below.\n\\begin{center}\n<table>\n<tr>\n<td></td><td align=\"center\">Leg</td><td align=\"center\">Leg</td><td align=\"center\">Body</td><td align=\"center\">Body</td>\n</tr>\n<tr>\n<td></td><td align=\"center\">Cumulative</td><td align=\"center\">RMS</td><td align=\"center\">Cumulative</td><td align=\"center\">RMS</td>\n</tr>\n<tr>\n<td></td><td align=\"center\">Scaled</td><td align=\"center\">Angles</td><td align=\"center\">Scaled</td><td align=\"center\">Angles</td>\n</tr>\n<tr>\n<td>GP-LVM ($q$=3)</td><td align=\"right\">11.4</td><td align=\"right\">3.40</td><td align=\"right\"><b>16.9</b></td><td align=\"right\"><b>2.49</b></td>\n</tr>\n<tr>\n<td>GP-LVM ($q$=4)</td><td align=\"right\"><b>9.7</b></td><td align=\"right\"><b>3.38</b></td><td align=\"right\">20.7</td><td align=\"right\">2.72</td>\n</tr>\n<tr>\n<td>GP-LVM ($q$=5)</td><td align=\"right\">13.4</b></td><td align=\"right\">4.25</td><td align=\"right\">23.4<td align=\"right\">2.78</td>\n</tr>\n<tr>\n<td>Scaled NN</td><td align=\"right\">13.5</b></td><td align=\"right\">4.44</td><td align=\"right\">20.8<td align=\"right\">2.62</td>\n</tr>\n<tr>\n<td>Nearest Neighbour</td><td align=\"right\">14.0</b></td><td align=\"right\">4.11</td><td align=\"right\">30.9<td align=\"right\">3.20</td>\n</tr>\n</table>\n\\end{center}\nThe cumulative scaled error is a recreation of the error reported in Taylor <i>et al.</i> which was the average (across angles) cumulative sum (across time) of the squared errors in the down-scaled (\\emph{i.e.} variance one) space of angles. We also present the root mean squared angle error for each joint which we find to be a little easier to interpret.\n\nTaylor <i>et al.</i> used a slightly different representation of\nthe data set which included the absolute $x$ and $z$\nposition of the root node and rotation around the $y$-axis. For\nthis data set, this information does help, principally because the\nsubject seems to start in roughly the same position at the beginning\nof each sequence. However, in general absolute position will not help,\nso we discarded it in favour of a representation of these values in\nterms of differences between frames. Finally Taylor <i>et al.</i>\nconcatenated two frames to form each data point for the model. We\nchose not to do this as we wanted to test the ability of the Gaussian\nprocess dynamics to fully recreate the data set. There results are given in their paper and summarised below.\n\n\\begin{center}\n<table>\n<tr>\n<td></td><td align=\"center\">Leg</td><td align=\"center\">Body</td>\n</tr>\n<tr>\n<td></td><td align=\"center\">Cumulative</td><td align=\"center\">Cumulative</td>\n</tr>\n<tr>\n<td></td><td align=\"center\">Scaled</td><td align=\"center\">Scaled</td>\n</tr>\n<td>Binary Latent Variable Model</td><td align=\"right\"><b>11.7</b></td><td align=\"right\"><b>8.8</b></td>\n</tr>\n<tr>\n<td>Scaled NN</td><td align=\"right\">22.2</td><td align=\"right\">20.5</td>\n</tr>\n</table>\n\\end{center}\nFinally we show a plot of reconstructions of two of the angles in the data.\n\n\\begin{center}\\inputdiagram{demCmu35gplvmLegReconstruct1_8} width=\"0.5\\textwidth\">\\inputdiagram{demCmu35gplvmLegReconstruct1_9} width=\"0.5\\textwidth\">\\end{center}\nPrediction for first two angles of the right hip joint (see plots in <a href=\"http://ml.sheffield.ac.uk/~neil/publications/bibpage.cgi?keyName=Taylor:motion06&printAbstract=1\">Taylor <i>et al.</i></a> for comparison). Dotted line is nearest neighour in scaled space, dashed line is GP-LVM with 4-D latent space.\\end{center}\n\n\n\n\\section{Informative Vector Machines}\n\n\\section{\\texttt{demClassificationOneIvm1}}\n\nThe first example given is \\texttt{demClassificationOneIvm1} which is a simple classification data set, where only one direction of the input is relevant in determining the decision boundary. An ARD MLP kernel is used in combination with a linear kernel. The ARD parameters in the linear and MLP kernel are constrained to be the same by the line:\n\n\\begin{octave}\n\n% Constrain the ARD parameters in the MLP and linear kernels to be the same.\n\nmodel.kern = cmpndTieParameters(model.kern, {[4, 7], [5, 8]});\n\n\\end{octave}\n\nThe resulting classification is shown below.\n\n\\begin{center}\\inputdiagram{demClassificationOneIvm1}\n\nDecision boundary from the \\texttt{demClassificationOneIvm1.m} example. Postive class is red circles, negative class green crosses and active points are yellow dots. Decision boundary shown in red, contours at 0.25 and 0.75 probability shown in blue.\\end{center}\n\n\n\n\n\\section{\\texttt{demClassificationTwoIvm1}}\n\nThe second example attempts to learn a Gaussian process give data that is sampled from a Gaussian process. The code is \\texttt{demClassificationTwoIvm1}. The underlying Gaussian process is based on an RBF kernel with variance inverse width 10. The IVM learns an inverse width of 15 and gives the classification is shown below.\n\n\\begin{center}\\inputdiagram{demClassificationTwoIvm1}\n\nDecision boundary from the \\texttt{demClassificationTwoIvm1.m} example. Postive class is red circles, negative class green crosses and active points are yellow dots. Decision boundary shown in red, contours at 0.25 and 0.75 probability shown in blue.\\end{center}\n\n\n\\section{\\texttt{demOrderedOneIvm1}}\n\nIn this example the ordered categorical noise model is used (ordinal regression). The data is a simple data set for which a linear one dimensional model suffices. The IVM is given a combination of an RBF and linear kernel with ARD.For the ordered categorical case there are several parameters associated with the noise model (in particular the category widths), these are learnt too. The model learns that the system is linear and only one direction is important. The resulting classification is given below.\n\n\n\n\\begin{center}\\inputdiagram{demOrderedOneIvm1}\n\nDecision boundary from the \\texttt{demOrderedOneIvm1.m} example. Class 0 - red cross, Class 1 - green circles, Class 2 - blue crosses, Class 3 - cyan asterisks, Class 4 - pink squares, Class 5 - yellow diamonds. Class 6 - red triangles. Active points are yellow dots, note that because the kernel is linear by now the most informative points tend to be at the extrema. Decision boundaries shown in red, contours at 0.25 and 0.75 probability shown in blue.\\end{center}\n\n\n\n\\section{\\texttt{demOrderedTwoIvm1}}\n\nAnother example with the ordered categorical noise model, here the data is radial, the categories being along the radius of a circle. The IVM is given a combination of an RBF and linear kernel with ARD. Again there are several parameters associated with the noise model, and these are learnt using \\texttt{ivmOptimiseNoise}. The resulting classification is given below.\n\n\n\n\\begin{center}\\inputdiagram{demOrderedTwoIvm1}\n\nDecision boundary from the \\texttt{demOrderedTwoIvm1.m} example. Class 0 - red cross, Class 1 - green circles, Class 2 - blue crosses, Class 3 - cyan asterisks, Class 4 - pink squares, Class 5 - yellow diamonds. Class 6 - red triangles. Active points are yellow dots, note that because the kernel is linear by now the most informative points tend to be at the extrema. Decision boundaries shown in red, contours at 0.25 and 0.75 probability shown in blue.\\end{center}\n\n\n\n\n\n\\section{\\texttt{demRegressionOneIvm1}}\n\nIn this example the Gaussian noise model is used (standard regression). The data is sampled from a Gaussian process, only one input dimension is important. The IVM is given a combination of an RBF and linear kernel with ARD. The resulting regression is given below.\n\n\n\n\\begin{center}\\inputdiagram{demRegressionOneIvm1}\n\nRegression from the example \\texttt{demRegressionOneIvm1.m}. Targets are red dots and active points are yellow dots.\\end{center}\n\n\n\n\\section{\\texttt{demRegressionTwoIvm1}}\n\nA second example with Gaussian noise, sampled from a Gaussian process, but this time with differing length scales.\n\n\n\n\\begin{center}\\inputdiagram{demRegressionTwoIvm1}\n\nRegression from the example \\texttt{demRegressionTwoIvm1.m}. Targets are red dots and active points are yellow dots.\\end{center}\n\n\n\n\\section{Benchmark Data Sets}\n\n\n\nThe function \\texttt{ivmGunnarData} allows you to test the IVM on Gunnar Raetsch's benchmark data sets. Download the data sets, <a href=\"http://ida.first.fraunhofer.de/projects/bench/benchmarks.htm\">from here</a> and expand the ringnorm data set into '\\$DATASETSDIRECTORY/gunnar/ringnorm'. Then run the following script.\n\n\n\n\n\n\\begin{octave}\n%}\nivmGunnarData('ringnorm', 1, {'rbf', 'bias', 'white'}, 1, 100)\n%{\n\\end{octave}\n\\begin{verbatim}\n\nFinal model:\n\nIVM Model:\n\n Noise Model:\n\n  Probit bias on process 1: 0.0439\n\n  Probit Sigma2: 0.0000\n\n Kernel:\n\n  Compound kernel:\n\n    RBF inverse width: 0.0866 (length scale 3.3984)\n\n    RBF variance: 1.2350\n\n    Bias Variance: 8.2589\n\n    White Noise Variance: 0.0000\n\nTest Error 0.0183\n\nModel likelihood -56.7120\n\n\\end{verbatim}\n\n\n\nYou can try any of the data sets by replacing ringnorm with the relevant data set (note that they don't all work with only 100 active points inas in the example above, for example the 'banana' data set needs 200 active points to get a reasonable result,\n\n\n\n\\begin{octave}\n\n ivmGunnarData('banana', 1, {'rbf', 'bias', 'white'}, 1, 200)\n\\end{octave}\n\n\\begin{verbatim}\nFinal model:\n\nIVM Model:\n\n Noise Model:\n\n  Probit bias on process 1: 0.1067\n\n  Probit Sigma2: 0.0000\n\n Kernel:\n\n  Compound kernel:\n\n    RBF inverse width: 1.6411 (length scale 0.7806)\n\n    RBF variance: 0.2438\n\n    Bias Variance: 0.0000\n\n    White Noise Variance: 0.0148\n\nTest Error 0.1129\n\nModel likelihood 175.3588\n\n\\end{verbatim}\n\n\n\n\n\n\\begin{center}\n\\inputdiagram{demBanana1}\n\nDecision boundary from the banana example. Postive class is red circles, negative class green crosses and active points are yellow dots. Decision boundary shown in red, contours at 0.25 and 0.75 probability shown in blue.\n\\end{center}\n\n\n\n\\section{Null Category Noise Model}\n\n\n\n\\section{Examples}\n\n\n\nThe toy data example in the papers can be recreated using:\n\n\n\n\\begin{octave}\n\n demUnlabelledOneIvm1\n\n\\end{octave}\n\n\n\nand leads to the decision boundary given below. A standard IVM based classifier can be run on the data using\n\n\n\n\\begin{octave}\n\n demUnlabelledOneIvm2\n\n\\end{octave}\n\n\n\n\\begin{center}\\inputdiagram{demUnlabelledOneIvm1}\\inputdiagram{demUnlabelledOneIvm2}\n\nThe null category noise model run on toy data. \\emph{Top}: using the null category, the true nature of the decision boundary is recovered. \\emph{Bottom}: the standard IVM, does not recover the true decision boundary.\\end{center}\n\n\n\nThe other USPS digit classification example given in the NIPS paper can be re-run with:\n\n\n\n\\begin{octave}\n\n demThreeFiveIvm\n\n\\end{octave}\n\n\n\nBe aware that this code can take some time to run. The results, in the form of averaged area under ROC curve against probability of missing label, can be plotted using\n\n\n\n\n\n\\begin{octave}\n%}\n demThreeFiveResults\n%{\n\\end{octave}\n\n\\begin{center}\n\n\\inputdiagram{demThreeFive} \n\nPlot of average area under ROC curve against probability of label being present. The red line is the standard IVM based classifier, the blue dotted line is the null category noise model based classifier, the green dash-dot line is the a normal SVM and the mauve dashed line is the transductive SVM.\n\n\\end{center}\n\n\n\n\n\\end{document}\n%}", "meta": {"hexsha": "ba05aaa7ed3f6703c6696f39f73a670c6816b080", "size": 35259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "html/vignette.tex", "max_stars_repo_name": "lawrennd/GPmat", "max_stars_repo_head_hexsha": "c96e814f47ad0ab84dd5c0329eb4dd6eb991e5fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-30T00:07:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T00:07:33.000Z", "max_issues_repo_path": "html/vignette.tex", "max_issues_repo_name": "lawrennd/GPmat", "max_issues_repo_head_hexsha": "c96e814f47ad0ab84dd5c0329eb4dd6eb991e5fc", "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": "html/vignette.tex", "max_forks_repo_name": "lawrennd/GPmat", "max_forks_repo_head_hexsha": "c96e814f47ad0ab84dd5c0329eb4dd6eb991e5fc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-05-28T09:59:44.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-06T18:04:53.000Z", "avg_line_length": 42.4807228916, "max_line_length": 659, "alphanum_fraction": 0.7711506282, "num_tokens": 9689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6157963918034375}}
{"text": "\n\\subsection{Monte-Carlo Tree Search}\n\n\\subsubsection{Introduction}\n\nIn search tree, each node has wins/total.\n\nSo start with just root in 0/0.\n\nAlgo:\n\n\\begin{itemize}\n\\item Start at root\n\\item Take n choices to arrive at node which has not been explored (or until w/l state)\n\\item play randomly from there\n\\item Back prob up (eg if win, then 1/1 for path back to root, or 0/1 if loss)\n\\end{itemize}\n\nWins/simulation count\n\nSo deterministic when choosing paths, up until play randomly.\n\n", "meta": {"hexsha": "a23fcda2129f2f30f6b6655db6fc6baa56a9ae13", "size": 487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/gameTheoryDeep/03-01-MCTS.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-01-MCTS.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-01-MCTS.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.1739130435, "max_line_length": 87, "alphanum_fraction": 0.7535934292, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6157963790013727}}
{"text": "%!TEX root = ../notes.tex\n\\section{February 8, 2022}\n\n\\subsection{Dirichlet Convolutions}\n\n\\begin{definition}[Dirichlet Convolution]\n    Let $f, g$ be arithmetic functions. Then the \\ul{Dirichlet convolution/product} of $g$ and $g$ it\n    \\begin{align*}\n        (f * g)(n) : & = \\sum_{d_1d_2=n}f(d_1)g(d_2) \\\\\n                     & = \\sum_{d\\mid n}f(d) g(n/d)\n    \\end{align*}\n\\end{definition}\n\nWe do check that this has properties that we want it to have, like associativity:\n\\begin{align*}\n    ((f * g) * h)(n) & = (f * (g * h))(n)                      \\\\\n                     & = \\sum_{d_1d_2d_3=n} f(d_1)g(d_2)h(d_3)\n\\end{align*}\nIt is also clearly commutative.\n\nWe also have that this product has a multiplicative identity.\n\n\\begin{definition}\n    Let $I : \\ZZ_+\\to \\{0, 1\\}$ be given by\n    \\[I(n) = \\begin{cases}\n            1 & \\text{if } n = 1 \\\\\n            0 & \\text{otherwise}\n        \\end{cases}\\]\n    Then $I$ is an identity for $*$, in the sense that $f * I = I * f = f$.\n\\end{definition}\n\n\\begin{lemma}\n    If $f$ is an arithmetic function such that $f(1)\\neq 0$, then there exists an arithmetic function $g$ such that $f * g = I$.\n\n    It is given recursively by\n    \\begin{align*}\n        g(1) & = \\frac{1}{f(1)}                                         \\\\\n        g(n) & = -\\frac{1}{f(1)}\\cdot \\sum_{d\\mid n, d < n} g(d) f(n/d)\n    \\end{align*}\n\\end{lemma}\n\\begin{proof}\n    We want to show that given $g$ and $g$ defined as above, we have that $f * g = I$.\n\n    $n=1$: \\[g(1)\\cdot f(1) = \\frac{1}{f(1)}f(1) = 1\\]\n\n    $n > 1$: \\begin{align*}\n        \\sum_{d\\mid n}g(d) f(n/d) & = g(n)\\cdot f(1) + \\sum_{d\\mid n, n<n}g(d) f(n/d)                   \\\\\n                                  & = -\\frac{1}{f(1)}\\cdot \\sum_{d\\mid n, d < n} g(d) f(n/d) \\cdot f(1)\n        + \\sum_{d\\mid n, n<n}g(d) f(n/d)                                                                \\\\\n                                  & = 0\n    \\end{align*}\n    So $g$ is indeed an inverse of $f$ since they produce the identity function $I$.\n\\end{proof}\n\n\\subsection{M\\\"obius Inversion}\nThe motivation of this is: given a summatory function of multiplicative functions, can we recover the multiplicative function?\n\\begin{definition}[M\\\"obius $\\mu$ Function]\n    We define $\\mu : \\ZZ_+ \\to \\{-1, 0, 1\\}$ given by\n    \\[\\mu(n) = \\begin{cases}\n            (-1)^k & \\text{if $n = p_1p_2\\dots p_k$ if $p_i$ are pairwise distinct primes} \\\\\n            0      & \\text{otherwise}\n        \\end{cases}\\]\n    \\emph{(We note that $\\mu(1) = 1$.)}\n\\end{definition}\n\n\\begin{lemma}\n    $\\mu$ is a multiplicative function.\n\\end{lemma}\n\\begin{proof}\n    Let $m, n\\in\\ZZ_+$ such that $(m, n) = 1$. We write\n    \\begin{align*}\n        m & = p_1^{e_1}p_2^{e_2}\\cdots p_k^{e_k} \\\\\n        n & = q_1^{f_1}q_2^{f_2}\\cdots q_l^{f_l} \\\\\n    \\end{align*}\n    \\begin{description}\n        \\item[Case 1]\n            Some exponent $e_i$ or $f_i \\geq 2$. Then we have that \\[\\mu(mn) = \\mu(m)\\mu(n) = 0\\]\n        \\item[Case 2]\n            We have that \\begin{align*}\n                m & =p_1p_2\\cdots p_k \\\\\n                n & =q_1q_2\\cdots q_l\n            \\end{align*}\n            where $p_i$ and $q_i$ are all pairwise distinct. Then $\\mu(m) = (-1)^k$ and $\\mu(n) = (-1)^l$, so $\\mu(m) = \\mu(n) = (-1)^{k+l}$.\n\n            Since these are coprime $(m, n) = 1$, then we have that $\\mu(mn) = (-1)^{k+l}$.\n    \\end{description}\n    Which is as intended, giving that $\\mu$ is a multiplicative function.\n\\end{proof}\n\n\\begin{lemma}\n    We have the property:\n    \\begin{align*}\n        \\sum_{d\\mid n}\\mu(d) = 0 \\qquad \\forall n\\geq 2.\n    \\end{align*}\n    Which tells us that the summatory function of $\\mu$ is $I$.\n\\end{lemma}\n\\begin{proof}\n    We define\n    \\begin{align*}\n        f(n) := \\sum_{d\\mid n}\\mu(d) \\qquad \\text{is multiplicative}\n    \\end{align*}\n    We check this on prime powers, for prime $p$ and $e\\geq 1$:\n    \\begin{align*}\n        f(p^e) & = \\mu(1) + \\mu(p) + \\mu(p^2) + \\cdots + \\mu(p^e) \\\\\n               & = 1 - 1 + 0 + \\cdots + 0 = 0\n    \\end{align*}\n    so we're done since $f$ is multiplicative and is $0$ for all power of primes.\n\\end{proof}\n\n\\begin{lemma}\n    Let $i: \\ZZ_+\\to \\{1\\}$ be the constant $1$ function.\n    \\[i * \\mu = \\mu * i = I\\]\n\\end{lemma}\n\\begin{proof} In the case of $n=1$, we have $i(1)\\mu(1) = 1$.\n\n    For $n > 1$, we have $(i * \\mu)(n) = \\displaystyle \\sum_{d\\mid n}\\mu(d) = 0$ from above.\n\\end{proof}\n\nWe see here that summatory functions can be seen as Dirichlet products: the summatory function $F$ of $f$ is $F = f * i$. What we said about summatory functions being multiplicative boils down to Dirichlet convolutions preserving multiplicativity.\n\n\\recall that summatory functions inherit multiplicativity. In fact, this holds for Dirichlet products as well. If $f, g$ are multiplicative, then so is $f * g$.\n\nThe proof is parallel to the proof for summatory functions, for \\cref{lemma:summatory-preserves-multiplicativity}.\n\n\\begin{theorem}[M\\\"obius Inversion]\n    Let\n    \\begin{align*}\n        F(n) & = \\sum_{d\\mid n} f(d)                         \\\\\n        \\intertext{Then we have }\n        f(n) & = \\sum_{d\\mid n}\\mu(d)\\cdot F(n/d) = \\mu * F.\n    \\end{align*}\n\\end{theorem}\n\\begin{proof}\n    $F = f * i$, then \\[F * \\mu = (f * i) * \\mu = f * (i * \\mu) = f * I = f.\\]\n    which was simpler than I expected\\dots\n\\end{proof}\n\n\\begin{corollary}\\label{cor:summatory-multiplicativity-original-multiplicative}\n    If $F$ is the summatory function of $f$, and $F$ is multiplicative, then $f$ is also multiplicative, as $f = \\mu * F$ and $\\mu$ is multiplicative and convolutions with multiplicative functions are multiplicative.\n\\end{corollary}\n\\begin{corollary}\n    \\Cref{cor:summatory-multiplicativity-original-multiplicative} gives another proof that $\\phi$ is multiplicative, as \\[\\sum_{d\\mid n}\\phi(d) = \\phi * i = \\mathrm{id}.\\]\n\\end{corollary}\n\n\\subsection{Applications of M\\\"obius Inversion}\n\\subsubsection{Cyclotomic Polynomials}\n\n\\recall the $n^\\mathrm{th}$ cyclotomic polynomial $\\Phi_n(x)$ is the unique irreducible polynomial in $\\ZZ[x]$ dividing $x^n - 1$ but no $x^k - 1$ for $k < n$.\n\nThus \\[\\Phi_n(x) = \\prod_{\\substack{1\\leq k < n \\\\ (k, n) = 1}} \\left(x - e^{2\\pi i k / n}\\right)\\]\nas the roots of this polynomial are exactly the primitive $n^\\mathrm{th}$ roots of unity. We have that \\[\\prod_{d\\mid n}\\Phi_d(x) = x^n - 1.\\]\nBy M\\\"obius inversion, if\n\\begin{align*}\n    G(n) & = \\prod_{d\\mid n}g(d),\n    \\intertext{then we have that}\n    g(n) & = \\prod_{d\\mid n}G(d)^{\\mu(n/d)}\n\\end{align*}\nIn particular, taking $G(n) = x^n - 1$ (with particular $x\\in\\CC$) as an arithmetic function, we have \\[\\Phi_n(x) = \\prod_{d\\mid n}(x^d - 1)^{\\mu(n/d)}\\qquad (x\\in \\CC)\\]\nApplying this identity for enough $x\\in \\CC$ yields this as an identity of polynomials.\n\n\\subsubsection{Dynatomic Polynomials}\nThe roots of cyclatomic polynomials are roots of unity. Dynatomic polynomials have as roots the periodic points (of certain periods) of a polynomial.\n\n\\begin{definition}\n    Let $K$ be a field, and let $f\\in K[x]$ of degree $d\\geq 2$. Let \\[f^n = \\underbrace{f\\circ f\\circ \\cdots \\circ f}_{n\\text{ times}}\\]\n    then $P\\in \\overline{K}$\\footnote{Algebraic numbers in field $K$, the field you get by adjoining all roots of polynomials in $K[x]$.} is said to be \\ul{periodic} under $f$ if\n    \\[f^n(P) = P\\qquad \\text{for some $n\\geq 1$}\\]\n\\end{definition}\n\\begin{example}\n    Let $f(x) = x^2 - 1$. $0$ is a period point under $f$:\n    \\[0\\longmapsto -1\\longmapsto 0\\]\n    and its \\ul{period} is $2$.\n\n    \\begin{remark*}\n        If $n$ is the smallest positive integer such that $f^n(p) = p$ ($p$ periodic), then we call $n$ the \\ul{exact period} of $p$ under $f$.\n    \\end{remark*}\n\\end{example}\n\\begin{definition}\n    The $n^\\mathrm{th}$ dynatomic polynomial of $f$ is \n    \\[\\Phi_{f,n}(x) := \\prod_{d\\mid n}\\left(f^d(x) - x\\right)^{\\mu(n/d)}\\]\n\\end{definition}\nWe hope that $\\Phi_{f, n}(x)$ has as its roots the points of exact period $n$\\dots This hope is dashed\\dots \n\\begin{example}\n    $f(x) = x^2 - \\frac{3}{4}$. \n    \\begin{align*}\n        f^2(x) - x &= \\left(x - \\frac{3}{2}\\right)\\left(1 - \\frac{1}{2}\\right)^3 \\\\\n        f(x) - x &= \\left(x-\\frac{3}{2}\\right)\\left(x + \\frac{1}{2}\\right)\n    \\end{align*}\n    Thus \\[\\frac{f^2(x) - x}{f(x) - x} = \\left(x + \\frac{1}{2}\\right)^2\\]\n    But $x=-\\frac{1}{2}$ is \\ul{fixed} under $f$. \n\\end{example}", "meta": {"hexsha": "84dd41298cb6e7696c535f1ae18bc9153a81ff61", "size": 8357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-02-08.tex", "max_stars_repo_name": "jchen/math1560-notes", "max_stars_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-02T15:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T20:28:48.000Z", "max_issues_repo_path": "lectures/2022-02-08.tex", "max_issues_repo_name": "jchen/math1560-notes", "max_issues_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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-08.tex", "max_forks_repo_name": "jchen/math1560-notes", "max_forks_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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": 43.7539267016, "max_line_length": 247, "alphanum_fraction": 0.5784372382, "num_tokens": 2957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.7690802264851918, "lm_q1q2_score": 0.6157963790013726}}
{"text": "\\section{Dynamic Programming}\n\\lst{Knapsack}{$\\mathcal{O}(n\\sum_{i = 1}^n p_i)$}{dynamicProgramming/knapsack.cc}\n\\lst{TSP}{$\\mathcal{O}(n 2^n)$}{dynamicProgramming/tsp.cc}\n\\lst{Subset Sum}{$\\mathcal{O}(n\\sum_{i = 1}^n v_i)$}{dynamicProgramming/subSetSum.cc}\n\\lst{Edit Distance}{$\\mathcal{O}(nm)$}{dynamicProgramming/editDistance.cc}\n\\lst{Longest Increasing Subsequence}{$\\mathcal{O}(n\\log n)$}{dynamicProgramming/lis.cc}\n\\lst{Longest Common Subsequence}{$\\mathcal{O}(nm)$}{dynamicProgramming/lcs.cc}\n", "meta": {"hexsha": "bdd0ffa493d757f6b87ed02d9fb79e70cbc99ef8", "size": 500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/dynamicProgramming.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/dynamicProgramming.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/dynamicProgramming.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": 62.5, "max_line_length": 87, "alphanum_fraction": 0.734, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6157631987800374}}
{"text": "\\hypertarget{k-nearest-neighbor-k-nn}{%\n\\chapter{k-Nearest Neighbor (k-NN)}\\label{k-nearest-neighbor-k-nn}}\n\\section{Introduction}\nK-NN algorithm assumes the similarity between the new case/data and\navailable cases and put the new case into the category that is most\nsimilar to the available categories. K-NN algorithm stores all the\navailable data and classifies a new data point based on the similarity.\nThis means when new data appears then it can be easily classified into a\nwell suite category by using K- NN algorithm. K-NN algorithm can be used\nfor Regression as well as for Classification but mostly it is used for\nthe Classification problems.\n\nK-NN is a non-parametric algorithm, which means it does not make any\nassumption on underlying data. It is also called a lazy learner\nalgorithm because it does not learn from the training set immediately\ninstead it stores the dataset and at the time of classification, it\nperforms an action on the dataset. K-NN algorithm at the training phase\njust stores the dataset and when it gets new data, then it classifies\nthat data into a category that is much similar to the new data.\n\\section{Creating Theoretical Model}\nStep-1: Select the number K of the neighbors. \\(k\\)=5 is preferred.\n\nStep-2: Calculate the Euclidean distance of \\(k\\) number of neighbors.\n\\[\nEuclidean\\ Distance = \\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}\n\\]\n\nStep-3: Take the K nearest neighbors as per the calculated Euclidean\ndistance. We may use other means of finding sum of distance calculations\nas well with Minkowski by setting \\(p\\) to \\(1\\) and \\(2\\) for using\nManhattan and Euclidean, respectivly.\n\\[\n||x_1-x_2|| = (\\sum_{i=1}^{n}|x_i-y_i|^p)^\\frac{1}{p}\n\\]\n\nStep-4: Among these k neighbors, count the number of the data points in\neach category.\n\nStep-5: Assign the new data points to that category where the neighbor is maximum.\n\\section{Implementation}\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{1}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{k+kn}{import} \\PY{n+nn}{numpy} \\PY{k}{as} \\PY{n+nn}{np}\n\\PY{k+kn}{import} \\PY{n+nn}{pandas} \\PY{k}{as} \\PY{n+nn}{pd}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{model\\PYZus{}selection} \\PY{k+kn}{import} \\PY{n}{train\\PYZus{}test\\PYZus{}split}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{preprocessing} \\PY{k+kn}{import} \\PY{n}{StandardScaler}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{neighbors} \\PY{k+kn}{import} \\PY{n}{KNeighborsClassifier}\n\\PY{k+kn}{from} \\PY{n+nn}{sklearn}\\PY{n+nn}{.}\\PY{n+nn}{metrics} \\PY{k+kn}{import} \\PY{n}{confusion\\PYZus{}matrix}\\PY{p}{,} \\PY{n}{accuracy\\PYZus{}score}\n\\PY{k+kn}{import} \\PY{n+nn}{matplotlib}\\PY{n+nn}{.}\\PY{n+nn}{pyplot} \\PY{k}{as} \\PY{n+nn}{plt}\n\\PY{k+kn}{from} \\PY{n+nn}{matplotlib}\\PY{n+nn}{.}\\PY{n+nn}{colors} \\PY{k+kn}{import} \\PY{n}{ListedColormap}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{2}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{dataset} \\PY{o}{=} \\PY{n}{pd}\\PY{o}{.}\\PY{n}{read\\PYZus{}csv}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{./data/ads.csv}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{X} \\PY{o}{=} \\PY{n}{dataset}\\PY{o}{.}\\PY{n}{iloc}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{p}{[}\\PY{l+m+mi}{1}\\PY{p}{,} \\PY{l+m+mi}{2}\\PY{p}{]}\\PY{p}{]}\\PY{o}{.}\\PY{n}{values}\n\\PY{n}{y} \\PY{o}{=} \\PY{n}{dataset}\\PY{o}{.}\\PY{n}{iloc}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{o}{\\PYZhy{}}\\PY{l+m+mi}{1}\\PY{p}{]}\\PY{o}{.}\\PY{n}{values}\n\\PY{n}{dataset}\\PY{o}{.}\\PY{n}{head}\\PY{p}{(}\\PY{l+m+mi}{10}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{2}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n   Gender  Age  EstimatedSalary  Purchased\n0    Male   19            19000          0\n1    Male   35            20000          0\n2  Female   26            43000          0\n3  Female   27            57000          0\n4    Male   19            76000          0\n5    Male   27            58000          0\n6  Female   27            84000          0\n7  Female   32           150000          1\n8    Male   25            33000          0\n9  Female   35            65000          0\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{3}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{X\\PYZus{}test}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}test} \\PY{o}{=} \\PY{n}{train\\PYZus{}test\\PYZus{}split}\\PY{p}{(}\\PY{n}{X}\\PY{p}{,} \\PY{n}{y}\\PY{p}{,} \\PY{n}{test\\PYZus{}size} \\PY{o}{=} \\PY{l+m+mf}{0.25}\\PY{p}{,} \\PY{n}{random\\PYZus{}state} \\PY{o}{=} \\PY{l+m+mi}{0}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{4}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{sc} \\PY{o}{=} \\PY{n}{StandardScaler}\\PY{p}{(}\\PY{p}{)}\n\\PY{n}{X\\PYZus{}train} \\PY{o}{=} \\PY{n}{sc}\\PY{o}{.}\\PY{n}{fit\\PYZus{}transform}\\PY{p}{(}\\PY{n}{X\\PYZus{}train}\\PY{p}{)}\n\\PY{n}{X\\PYZus{}test} \\PY{o}{=} \\PY{n}{sc}\\PY{o}{.}\\PY{n}{transform}\\PY{p}{(}\\PY{n}{X\\PYZus{}test}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{5}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{classifier} \\PY{o}{=} \\PY{n}{KNeighborsClassifier}\\PY{p}{(}\\PY{n}{n\\PYZus{}neighbors} \\PY{o}{=} \\PY{l+m+mi}{5}\\PY{p}{,} \\PY{n}{metric} \\PY{o}{=} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{minkowski}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{n}{p} \\PY{o}{=} \\PY{l+m+mi}{2}\\PY{p}{)}\n\\PY{n}{classifier}\\PY{o}{.}\\PY{n}{fit}\\PY{p}{(}\\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{5}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\nKNeighborsClassifier()\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{6}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{y\\PYZus{}pred} \\PY{o}{=} \\PY{n}{classifier}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{X\\PYZus{}test}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{y\\PYZus{}pred}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{y\\PYZus{}test}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\n[0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0\n 0 0 1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1\n 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 1]\n[0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0\n 0 0 1 0 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1\n 0 0 0 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 0 0 0 1 0 1 1 1]\n    \\end{Verbatim}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{7}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{confusion\\PYZus{}matrix}\\PY{p}{(}\\PY{n}{y\\PYZus{}test}\\PY{p}{,} \\PY{n}{y\\PYZus{}pred}\\PY{p}{)}\\PY{p}{)}\n\\PY{n+nb}{print}\\PY{p}{(}\\PY{n}{accuracy\\PYZus{}score}\\PY{p}{(}\\PY{n}{y\\PYZus{}test}\\PY{p}{,}\\PY{n}{y\\PYZus{}pred}\\PY{p}{)}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{Verbatim}[commandchars=\\\\\\{\\}]\n[[64  4]\n [ 3 29]]\n0.93\n    \\end{Verbatim}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{8}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{X\\PYZus{}set}\\PY{p}{,} \\PY{n}{y\\PYZus{}set} \\PY{o}{=} \\PY{n}{X\\PYZus{}train}\\PY{p}{,} \\PY{n}{y\\PYZus{}train}\n\\PY{n}{X1}\\PY{p}{,} \\PY{n}{X2} \\PY{o}{=} \\PY{n}{np}\\PY{o}{.}\\PY{n}{meshgrid}\\PY{p}{(}\\PY{n}{np}\\PY{o}{.}\\PY{n}{arange}\\PY{p}{(}\\PY{n}{start} \\PY{o}{=} \\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{l+m+mi}{0}\\PY{p}{]}\\PY{o}{.}\\PY{n}{min}\\PY{p}{(}\\PY{p}{)} \\PY{o}{\\PYZhy{}} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{n}{stop} \\PY{o}{=} \\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{l+m+mi}{0}\\PY{p}{]}\\PY{o}{.}\\PY{n}{max}\\PY{p}{(}\\PY{p}{)} \\PY{o}{+} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{n}{step} \\PY{o}{=} \\PY{l+m+mf}{0.01}\\PY{p}{)}\\PY{p}{,}\n                     \\PY{n}{np}\\PY{o}{.}\\PY{n}{arange}\\PY{p}{(}\\PY{n}{start} \\PY{o}{=} \\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{l+m+mi}{1}\\PY{p}{]}\\PY{o}{.}\\PY{n}{min}\\PY{p}{(}\\PY{p}{)} \\PY{o}{\\PYZhy{}} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{n}{stop} \\PY{o}{=} \\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{p}{:}\\PY{p}{,} \\PY{l+m+mi}{1}\\PY{p}{]}\\PY{o}{.}\\PY{n}{max}\\PY{p}{(}\\PY{p}{)} \\PY{o}{+} \\PY{l+m+mi}{1}\\PY{p}{,} \\PY{n}{step} \\PY{o}{=} \\PY{l+m+mf}{0.01}\\PY{p}{)}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{figure}\\PY{p}{(}\\PY{n}{dpi}\\PY{o}{=}\\PY{l+m+mi}{100}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{contourf}\\PY{p}{(}\\PY{n}{X1}\\PY{p}{,} \\PY{n}{X2}\\PY{p}{,} \\PY{n}{classifier}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{np}\\PY{o}{.}\\PY{n}{array}\\PY{p}{(}\\PY{p}{[}\\PY{n}{X1}\\PY{o}{.}\\PY{n}{ravel}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{X2}\\PY{o}{.}\\PY{n}{ravel}\\PY{p}{(}\\PY{p}{)}\\PY{p}{]}\\PY{p}{)}\\PY{o}{.}\\PY{n}{T}\\PY{p}{)}\\PY{o}{.}\\PY{n}{reshape}\\PY{p}{(}\\PY{n}{X1}\\PY{o}{.}\\PY{n}{shape}\\PY{p}{)}\\PY{p}{,}\n             \\PY{n}{alpha} \\PY{o}{=} \\PY{l+m+mf}{0.5}\\PY{p}{,} \\PY{n}{cmap} \\PY{o}{=} \\PY{n}{ListedColormap}\\PY{p}{(}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{red}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{green}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\\PY{p}{)}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlim}\\PY{p}{(}\\PY{n}{X1}\\PY{o}{.}\\PY{n}{min}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{X1}\\PY{o}{.}\\PY{n}{max}\\PY{p}{(}\\PY{p}{)}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{ylim}\\PY{p}{(}\\PY{n}{X2}\\PY{o}{.}\\PY{n}{min}\\PY{p}{(}\\PY{p}{)}\\PY{p}{,} \\PY{n}{X2}\\PY{o}{.}\\PY{n}{max}\\PY{p}{(}\\PY{p}{)}\\PY{p}{)}\n\\PY{k}{for} \\PY{n}{i}\\PY{p}{,} \\PY{n}{j} \\PY{o+ow}{in} \\PY{n+nb}{enumerate}\\PY{p}{(}\\PY{n}{np}\\PY{o}{.}\\PY{n}{unique}\\PY{p}{(}\\PY{n}{y\\PYZus{}set}\\PY{p}{)}\\PY{p}{)}\\PY{p}{:}\n    \\PY{n}{plt}\\PY{o}{.}\\PY{n}{scatter}\\PY{p}{(}\\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{n}{y\\PYZus{}set} \\PY{o}{==} \\PY{n}{j}\\PY{p}{,} \\PY{l+m+mi}{0}\\PY{p}{]}\\PY{p}{,} \\PY{n}{X\\PYZus{}set}\\PY{p}{[}\\PY{n}{y\\PYZus{}set} \\PY{o}{==} \\PY{n}{j}\\PY{p}{,} \\PY{l+m+mi}{1}\\PY{p}{]}\\PY{p}{,} \\PY{n}{color} \\PY{o}{=} \\PY{n}{ListedColormap}\\PY{p}{(}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{red}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{,} \\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{green}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\\PY{p}{)}\\PY{p}{(}\\PY{n}{i}\\PY{p}{)}\\PY{p}{,} \\PY{n}{label} \\PY{o}{=} \\PY{n}{j}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{xlabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Age}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{ylabel}\\PY{p}{(}\\PY{l+s+s1}{\\PYZsq{}}\\PY{l+s+s1}{Estimated Salary}\\PY{l+s+s1}{\\PYZsq{}}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{legend}\\PY{p}{(}\\PY{p}{)}\n\\PY{n}{plt}\\PY{o}{.}\\PY{n}{show}\\PY{p}{(}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{center}\n    \\adjustimage{max size={0.9\\linewidth}{0.9\\paperheight}}{./figures/KNN1.png}\n    \\end{center}\n    { \\hspace*{\\fill} \\\\}\n    \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{9}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{k}{def} \\PY{n+nf}{make\\PYZus{}predection}\\PY{p}{(}\\PY{n}{age}\\PY{p}{,} \\PY{n}{salary}\\PY{p}{)}\\PY{p}{:}\n    \\PY{k}{return} \\PY{n}{classifier}\\PY{o}{.}\\PY{n}{predict}\\PY{p}{(}\\PY{n}{sc}\\PY{o}{.}\\PY{n}{transform}\\PY{p}{(}\\PY{p}{[}\\PY{p}{[}\\PY{n}{age}\\PY{p}{,}\\PY{n}{salary}\\PY{p}{]}\\PY{p}{]}\\PY{p}{)}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{10}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{make\\PYZus{}predection}\\PY{p}{(}\\PY{l+m+mi}{25}\\PY{p}{,} \\PY{l+m+mi}{130000}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{10}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\narray([1], dtype=int64)\n\\end{Verbatim}\n\\end{tcolorbox}\n        \n    \\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]\n\\prompt{In}{incolor}{11}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n\\PY{n}{make\\PYZus{}predection}\\PY{p}{(}\\PY{l+m+mi}{5}\\PY{p}{,} \\PY{l+m+mi}{100}\\PY{p}{)}\n\\end{Verbatim}\n\\end{tcolorbox}\n\n            \\begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0]\n\\prompt{Out}{outcolor}{11}{\\boxspacing}\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\narray([0], dtype=int64)\n\\end{Verbatim}\n\\end{tcolorbox}", "meta": {"hexsha": "2ca571cb546b3fec47f9d476916c51bf672eebd8", "size": 13160, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MCA/Machine Learning/Project file/Tex source/k-Nearest Neighbor.tex", "max_stars_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_stars_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-13T12:34:51.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-02T18:54:22.000Z", "max_issues_repo_path": "MCA/Machine Learning/Project file/Tex source/k-Nearest Neighbor.tex", "max_issues_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_issues_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MCA/Machine Learning/Project file/Tex source/k-Nearest Neighbor.tex", "max_forks_repo_name": "muhammadmuzzammil1998/CollegeStuff", "max_forks_repo_head_hexsha": "618cec9ebfbfd29a2d1e5a182b90cfb36b38a906", "max_forks_repo_licenses": ["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.5098039216, "max_line_length": 563, "alphanum_fraction": 0.5886778116, "num_tokens": 5798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6156897254899868}}
{"text": "\\FloatBarrier\n\\section{Combined Dynamics} \\label{sec:combined}\n\nIt is possible to define a set of dynamics to run a combination of the dynamics. \nThe resulting dynamic is defined as \n\\begin{equation}\n\\dot{ x } = \\sum_{d\\in \\mathcal{D}} \\gamma_d V_d( x ),\n\\end{equation}\nwhere $\\mathcal{D}=\\{ Logit, RD, Smith, BNN \\}$ denotes the set of available dynamics, $V_d()$ is the differential equation of the $d\\th$ dynamic and $\\gamma_d$ is the weight assigned to it.\nThe dynamics should be defined in a cell array, e.g., \n\\begin{lstlisting}\ndynamics = {'bnn', 'rd'};\n\\end{lstlisting}\nThe combination is made making a linear combination between each dynamic listed in the cell array. The weight assigned to each dynamic is defined in the vector \\verb|gamma|. In this case we assign \n\\begin{lstlisting}\ngamma = [.25, .75]; \n\\end{lstlisting}\n\nFig. \\ref{fig:rps_combined} shows an example of the combined dynamics for the rock-paper-scissors game. Note that the evolution of the system is not confined to a limit cycle, as happened with the replicator dynamics in Fig.  \\ref{fig:finite1}.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_combined.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test_combined_simplex}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_combined_ev.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test_combined_ev}\n  \\end{subfigure}\n  \\caption{Evolution of the combination of replicator dynamics and BNN dynamics.}\n  \\label{fig:rps_combined}\n\\end{figure}\n\n\n\n", "meta": {"hexsha": "d0f73d2dc62a1c9a1c1adf5b37d5d122343551ad", "size": 1630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/combined_dynamics.tex", "max_stars_repo_name": "carlobar/PDToolbox_matlab", "max_stars_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-08-13T09:50:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T09:22:42.000Z", "max_issues_repo_path": "docs/combined_dynamics.tex", "max_issues_repo_name": "sjtudh/PDToolbox_matlab", "max_issues_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-07-25T13:04:08.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-03T21:16:17.000Z", "max_forks_repo_path": "docs/combined_dynamics.tex", "max_forks_repo_name": "sjtudh/PDToolbox_matlab", "max_forks_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-07-16T00:40:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T10:20:34.000Z", "avg_line_length": 40.75, "max_line_length": 244, "alphanum_fraction": 0.7404907975, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6154669787282334}}
{"text": "\\section{Alternative Estimators}\nIn this section we present a detailed overview of two alternative estimators which in theory exhibit better finite sample properties. \n\\par Both of these estimators, the Jackknife IV estimator and the LIML estimator, fall under the broader class of k-class estimators. These estimators are partially robust ie less sensitive to weak instruments; with weak instruments, they are more reliable than 2SLS estimates. Conventional asymptotic approximations are used for their inference.\n\n\\subsection{Jackknife Instrumental Variables Estimator}\nFor an intuitive sense of the functioning of the jackknife instrumental variables estimator, consider the term `jackknife' as presented in statistical literature. The  jackknife estimator of a parameter is found by leaving out each observation from a dataset, calculating the estimate and computing the average of these calculations. Given a sample of size $N$, the jackknife estimate is found by aggregating the estimates of each sub-sample of size $(N-1)$. In a similar vein, the estimator we describe in this section replaces the usual fitted values from the reduced form regression of the two-stage least squares by `omit-one' fitted values.\n\\par The key feature of the JIVE estimator is that it eliminates the correlation between the fitted values and the structural equation errors, as explain in detail below. The fitted value of the standard 2SLS estimator is only asymptotically independent of the structural error ($\\varepsilon_i$), but the JIVE is independent even in finite samples.\n\\par The derivation we present in this section is adopted from \\cite{angrist1999jackknife}. To derive the expression formally, consider again the expressions for $\\hat\\beta_{OPT}$ and $\\hat\\beta_{2SLS}$ from section 2.2, equations (2.4) and (2.5). $\\hat\\beta_{OPT}$ employed the optimal instrument $\\mathbf Z\\pi$ and $\\hat\\beta_{2SLS}$ used an estimate of $\\mathbf Z\\pi$, denoted by $\\mathbf Z\\hat \\pi$. Now we introduce the new estimator for $\\beta$ by using a different estimate of the optimal instrument, $Z_{i}\\tilde{\\pi}$. \n\n\\par From the formulation of approximate bias of the 2SLS estimator we presented in section 2.4.2 (equation 2.11), it is clear that increasing the number of instruments while keeping the explanatory/predictive power of the instruments constant, leads to an increase in the bias of $\\hat\\beta_{2SLS}$. However, we can see that for the optimal estimator, increasing the number of instruments while keeping $Z_i\\pi$ fixed will have no effect on the properties of $\\hat\\beta_{OPT}$. Thus, for finite samples in the presence of many instruments, $\\hat\\beta_{2SLS}$ fares much worse than $\\hat\\beta_{OPT}$. \n\\par Recall the representation of the 2SLS estimator using the projection matrix $P_Z$ from Section 2 (equation 2.8). We can see that the first-stage fitted values $\\mathbf Z\\hat{\\pi}$ can be written as:\n\n\\begin{equation}\n\\mathbf Z\\hat{\\pi} = P_Z\\mathbf X = \\mathbf Z \\pi + P_Z\\eta\n\\end{equation}\n\nThe term $P_Z\\eta$ in the above equation is correlated with the error term of the first-stage $\\eta$ (see equation 1.2) and hence with the structural error term $\\varepsilon$. Put differently, since $\\hat \\pi$ is estimated on the full sample which includes the $i$th observation, it is correlated with $\\eta_i$, which is correlated with $\\varepsilon_i$. This correlation is given by:\n\n\\begin{equation}\nE[\\varepsilon_{i}Z_{i}\\hat{\\pi}]\n=E[E[\\varepsilon_i Z_i\\hat\\pi|\\mathbf Z]]\n=E[Z_i(\\mathbf Z^\\prime \\mathbf Z)^{-1} Z_i^\\prime] \\cdot E[\\varepsilon_i \\eta_i|\\mathbf Z]]\n=E[Z_i(\\mathbf Z^\\prime \\mathbf Z)^{-1} Z_i^\\prime \\cdot \\sigma_{\\varepsilon\\eta}^\\prime]\n=(K/N)\\cdot\\sigma_{\\varepsilon\\eta}'\n\\end{equation}\n\nDue to this correlation between $\\hat \\pi$ and $\\varepsilon_i$, $\\hat\\beta_{2SLS}$ is biased for $\\beta$. While the correlation disappears asymptotically, it holds implications in finite samples. \n\n\\par In devising the new instrument, we attempt to keep the correlation in (4.2) equal to zero. The problem stems from $\\hat \\pi$ being estimated on the full sample which includes the $i$th observation. For the new estimator which has the constructed instrument $Z_{i}\\tilde{\\pi}$, $\\tilde\\pi$ is estimated not on the full sample but on the sample with the $i$th observation removed. Therefore, the new estimated instrument will be independent of $\\varepsilon_i$ even in finite samples.\n\n    \nThe $i$th row of the estimated instrument for 2SLS, $\\mathbf Z\\hat{\\pi}$, where $\\hat{\\pi}=(\\mathbf Z'\\mathbf Z)^{-1}(\\mathbf Z'\\mathbf X)$, is given by\n\\begin{equation}\nZ_{i}\\hat{\\pi}= Z_{i}({\\mathbf Z}'\\mathbf Z)^{-1}(\\mathbf Z'\\mathbf X)\n\\end{equation}\n \nRemove the $i$th row from the matrices of regressors and instruments and denote them by $\\mathbf X(i)$ and $\\mathbf Z(i)$. Thus JIVE removes the dependence between $Z_{i}\\hat{\\pi}$ and the regressor $X_{i}$.\n\nThe corresponding estimate of $\\pi$ and the constructed instrument will be:\n\\begin{equation}\n\\tilde{\\pi}(i)=(\\mathbf Z(i)'\\mathbf Z(i))^{-1}(\\mathbf Z(i)'\\mathbf X(i))\n\\end{equation}\n\n\\begin{equation}\nZ_{i}\\tilde{\\pi}(i)=Z_{i}(\\mathbf Z(i)'\\mathbf Z(i))^{-1}(\\mathbf Z(i)'\\mathbf X(i)Y)\n\\end{equation}\n$\\varepsilon_{i}$ and $X_{j}$ are independent when $i\\neq j$, so it follows that\n\\begin{equation}\nE[\\varepsilon_{i}Z_{i}\\tilde{\\pi}(i)]=E[Z_{i}(\\mathbf Z(i)'\\mathbf Z(i))^{-1}(\\mathbf Z(i)')E[\\mathbf X(i)\\varepsilon_{i}|\\mathbf Z]]=0\n\\end{equation}\n\nHence, now we have $E[\\varepsilon_{i}Z_{i}\\tilde{\\pi}(i)]=0$, so we have removed the correlation between the fitted values and the structural error presented in equation (4.2).\n\\par The JIVE estimator is equal to:\n\n\\begin{equation}\n\\hat{\\beta}_{JIVE}=(\\mathbf {\\hat{X}}_{JIVE}'\\mathbf X)^{-1}(\\mathbf {\\hat{X}}_{JIVE}'\\mathbf Y)\n\\end{equation}\nwhere $\\hat{X}_{JIVE}$ is $N\\times L$ dimensional matrix with the $i$ th row $Z_{i}\\tilde{\\pi}(i)$. \\\\\n\n\n\\par \\cite{blomquist1999small} summarize the construction of the JIVE estimator by providing the following algorithm:  \n\n\n%\\vspace{0.6cm}\n\\begin{algorithm}\n\\caption{Jackknife Instrumental Variables Estimator}\\label{alg:euclid}\n\\begin{algorithmic}[1]\n\\State Use all observations but the $i$th to estimate parameters of the first-stage equation.\n\\State Combine the estimated first stage parameters with the instruments for the $i$th observation, $Z_i$, to construct a fitted value for the $i$th observation $X_i$.\n\\State Repeat steps 1 and 2 for all N observations.\n\\State Regress Y on the fitted values and the exogenous regressors.\n\\end{algorithmic}\n\\end{algorithm}\n\nThe estimator for $Z_i\\pi$, $Z_{i}\\tilde{\\pi}(i)$ is consistent.\n$\\hat{\\beta}_{JIVE}$ has the same probability limit and first-order asymptotic distribution as $\\hat{\\beta}_{OPT}$ and $\\hat{\\beta}_{2SLS}$, under conventional fixed model asymptotics (\\cite{stock2002survey}).\n\n\\subsection{Limited Information Maximum-Likelihood Estimator}\n\nLimited Information Maximum Likelihood (LIML) is an alternative method to estimate the parameters of the structural equation. It was formalized by \\cite{anderson1949estimation}.\\\\\nWe follow the same model as described in Section 2, and extend it as shown below: \n\\begin{equation}\n \\mathbf{Y} = \\mathbf{X}\\beta + \\varepsilon = \\mathbf{X_0}\\beta_0 + \\mathbf{X_1}\\beta_1 + \\varepsilon\n\\end{equation}\n\\begin{equation}\n \\mathbf{X_1} = \\mathbf{Z}\\pi + \\eta = \\mathbf{Z_0}\\pi_0 + \\mathbf{Z_1}\\pi_1 + \\eta\n\\end{equation}\nwhere $\\mathbf{Z_0} = \\mathbf{X_0}$.\\\\\nHere, $\\mathbf{X_0}$ is the matrix of exogenous variables and $\\mathbf{X_1}$ of endogenous variables. $\\mathbf{Z_0} = \\mathbf{X_0}$ is the matrix of included exogenous variables, $\\mathbf{Z_1}$ is the matrix of excluded exogenous variables.\nBecause the LIML estimator is based on the structural equation for $\\mathbf{Y}$ combined with the first-stage equation for $\\mathbf{X_1}$, it is called `limited information'. LIML estimator is given by:\n\\begin{equation}\n\\hat\\beta_{LIML}=(\\mathbf X'(\\mathbf I-\\hat\\kappa \\mathbf M_Z)\\mathbf X)^{-1}\\mathbf X'(\\mathbf I-\\hat\\kappa \\mathbf M_Z)\\mathbf Y\n\\end{equation}\n\\par The LIML estimator has some excellent properties when the number of excluded instruments (number of columns in matrix $\\mathbf X_1$) in the first-stage equation and the sample size are large. Although the LIML estimator and the 2SLS estimator are asymptotically equivalent in the standard large sample theory, they are quite different in case of many instruments or many weak instruments. It has no finite moments, which implies that its density tends to have very thick tails. \\cite{anderson2010asymptotic} show that the LIML estimator shows asymptotic optimality with many weak instruments.", "meta": {"hexsha": "0c104c89e7ed6e03e2425163b17718c7cdf3de67", "size": 8631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch04.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": "ch04.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": "ch04.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": 91.8191489362, "max_line_length": 645, "alphanum_fraction": 0.7550689376, "num_tokens": 2430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6154669726363837}}
{"text": "\\documentclass{article}\n\\usepackage{eecstex}\n\\usepackage{pgfplots}\n\\usepackage{physics}\n\n\\DeclareMathOperator{\\rect}{rect}\n\n\\title{Homework 01}\n\\author{Bryan Ngo}\n\\date{2022-01-19}\n\n\\begin{document}\n\n\\maketitle\n\n\\setcounter{section}{1}\n\n\\section{}\n\n\\subsection{}\n\n\\begin{theorem}\n    The system \\(L\\) is not time invariant.\n\\end{theorem}\n\\begin{proof}\n    We can represent a time-delayed signal as a linear combination of the other 3 signals.\n    We can represent the 3 input signals in a matrix\n    \\begin{equation}\n        \\bm{X} =\n        \\begin{bmatrix}\n           -2 & -2 & 0 \\\\\n           1 & 1 & 1 \\\\\n           -2 & 0 & 1 \n        \\end{bmatrix}\n    \\end{equation}\n    Then, we can find the linear combination necessary to create a time delayed signal (for example, \\(x_2[n - 1]\\)) by solving the system of equations\n    \\begin{equation}\n        \\bm{Xa} =\n        \\begin{bmatrix}\n            0 \\\\\n            -2 \\\\\n            1\n        \\end{bmatrix}\n    \\end{equation}\n    where we get \\(\\bm{a} = \\begin{bmatrix}\n        -\\frac{3}{2} & \\frac{3}{2} & -2\n    \\end{bmatrix}^\\top\\).\n    Thus, we have\n    \\begin{equation}\n        x_2[n - 1] = -\\frac{3}{2} x_1[n] + \\frac{3}{2} x_2[n] - 2x_3[n]\n    \\end{equation}\n    Calculating \\(-\\frac{3}{2} y_1[n] + \\frac{3}{2} y_2[n] - 2y_3[n]\\),\n    we get the following plot:\n    \\begin{center}\n        \\begin{tikzpicture}\n            \\begin{axis}[\n                xlabel=\\(n\\), ylabel={\\(L\\{x_2[n - 1]\\}\\)},\n                title={Time invariance counterexample},\n                axis lines=middle\n            ]\n            \\addplot[\n                ycomb,\n                color=blue,\n                mark=*\n            ]\n            coordinates {\n                (-2, -4)\n                (-1, 2)\n                (0, 3)\n                (1, -9)\n                (2, -4)\n                (3, -3)\n            };\n            \\end{axis}\n        \\end{tikzpicture}\n        \\begin{tikzpicture}\n            \\begin{axis}[\n                xlabel=\\(n\\), ylabel={\\(y_2[n - 1]\\)},\n                title={Expected output signal},\n                axis lines=middle\n            ]\n            \\addplot[\n                ycomb,\n                color=blue,\n                mark=*\n            ]\n            coordinates {\n                (0, -1)\n                (1, 1)\n                (2, -3)\n                (3, -0)\n                (4, -1)\n            };\n            \\end{axis}\n        \\end{tikzpicture}\n    \\end{center}\n    So the system is \\emph{not} time-invariant.\n\\end{proof}\n\n\\subsection{}\n\nWe can represent the delta function as\n\\begin{equation}\n    \\delta[n] = \\frac{1}{2} (x_1[n] - x_2[n] + 2x_3[n])\n\\end{equation}\nUsing the properties of linear systems, we can find the impulse response\n\\begin{equation}\n    h[n] = \\frac{1}{2} (y_1[n] - y_2[n] + 2y_3[n])\n\\end{equation}\nwhich gives us the following plot:\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(n\\), ylabel={\\(L\\{\\delta[n]\\}\\)},\n            title={Impulse response},\n            axis lines=middle\n        ]\n        \\addplot[\n            ycomb,\n            color=blue,\n            mark=*\n        ]\n        coordinates {\n            (-2, 2)\n            (-1, 1)\n            (0, -2)\n            (1, 3)\n            (2, 2)\n            (3, 1)\n        };\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\\section{}\n\n\\begin{align}\n    y[n] - ay[n - 1] &= x[n] \\\\\n    y[0] &= 1\n\\end{align}\n\n\\subsection{}\n\nBy counterexample, consider \\(x[n] = \\delta[n]\\) and \\(n = 1\\),\n\\begin{equation}\n    y[1] = a\n\\end{equation}\nThen, consider \\(x[n - 1] = \\delta[n - 1]\\) and \\(n = 1\\),\n\\begin{equation}\n    y[1] - a y[0] = \\delta[0] \\implies y[1] = 1 + a\n\\end{equation}\nwhereas \\(y[n - 1] = y[0] = 1\\) by the initial condition.\nSo the system is not time-invariant.\n\n\\subsection{}\n\nGiven the initial condition \\(y[0] = 1\\), scaling the input does not change this fact, so the system \\emph{cannot} be linear.\n\n\\subsection{}\n\nThe system is still not time-invariant due to the same counterexample as above.\nThe system is now linear as we can see because we no longer have an affine transformation at \\(y[0]\\).\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    y[n] = h[n] \\ast (\\cos[\\omega_0 n] x[n]) = \\sum_{k \\geqslant 0} \\frac{1}{1 + k} \\cos[\\omega_0 (n - k)] x[n - k]\n\\end{equation}\n\n\\subsection{}\nProving linearity, suppose we are given the system responses \\(x_1[n] \\iff y_1[n]\\) and \\(x_2[n] \\iff y_2[n]\\),\n\\begin{align}\n    T\\{ax_1[n] + bx_2[n]\\} &= h[n] \\ast (\\cosine[\\omega_0 n] (ax_1[n] + bx_2[n])) \\\\\n    &= h[n] \\ast (\\cos[\\omega_0 n] ax_1[n] + \\cos[\\omega_0 n] bx_2[n]) \\\\\n    &= a (h[n] \\ast \\cos[\\omega_0 n] x_1[n]) + b (h[n] \\ast \\cos[\\omega_0 n] x_2[n]) \\\\\n    &= ay_1[n] + by_2[n]\n\\end{align}\nFor time invariance,\n\\begin{align}\n    T\\{x[n - n_0]\\} &= h[n] \\ast (\\cosine[\\omega_0 n] x[n - n_0]) \\\\\n    y[n - n_0] &= h[n - n_0] \\ast (\\cosine[\\omega_0 (n - n_0)] x[n - n_0])\n\\end{align}\nThe two are clearly not the same, so our system is not time invariant and thus not LTI.\n\n\\subsection{}\n\nWe can bound the cosine function with 1.\nSimilar to Example 2.18 in Oppenheim \\& Schafer, if \\(|x[n]| < B_x\\),\n\\begin{equation}\n    |y[n]| = \\sum_{k \\geqslant 0} \\frac{1}{1 + k} B_x = B_x \\sum_{k \\geqslant 1} \\frac{1}{k}\n\\end{equation}\nwhich is a divergent harmonic series.\n\n\\subsection{}\n\nThe system is causal since the \\(y[n]\\) consists of a memoryless multiplication by a cosine function and convolution with a causal LTI system, which makes the system overall causal.\n\n\\newpage\n\\section{}\n\n\\subsection{}\n\nWe can model the frequency response as\n\\begin{equation}\n    H(e^{j \\omega}) =\n    \\begin{cases}\n        1 & |\\omega| < \\frac{\\pi}{2} \\\\\n        0 & \\text{elsewhere}\n    \\end{cases}\n\\end{equation}\nFinding the inverse Fourier transform,\n\\begin{align}\n    h[n] &= \\frac{1}{2\\pi} \\int_{-\\pi}^\\pi H(e^{j \\omega}) e^{j \\omega n} \\, d\\omega \\\\\n    &= \\frac{1}{2\\pi} \\int_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} e^{j \\omega n} \\, d\\omega = \\frac{1}{2\\pi} \\eval{\\frac{e^{j \\omega n}}{jn}}_{-\\frac{\\pi}{2}}^{\\frac{\\pi}{2}} \\\\\n    &= \\frac{1}{2\\pi j n} \\left(e^{j \\frac{\\pi}{2} n} - e^{-j \\frac{\\pi}{2} n}\\right) = \\frac{\\sin\\left[\\frac{\\pi}{2} n\\right]}{\\pi n}\n\\end{align}\n\n\\subsection{}\n\nThe system is not causal, since \\(h[-1] = \\frac{1}{\\pi} \\neq 0\\).\n\n\\subsection{}\n\nThis is a specific case of Example 2.18 in Oppenheim \\& Schafer.\nEach term of the absolute sum of the sinc function only decreases on the order of \\(\\frac{1}{n}\\), so we can treat the sum as the harmonic series, which diverges.\nThus, the low pass filter is not BIBO stable.\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    y[n] = \\frac{1}{6} \\sum_{k = 0}^5 x[n - k]\n\\end{equation}\n\n\\subsection{}\n\nUsing Equation 2.123 from Oppenheim \\& Schafer with \\(M = 5\\),\n\\begin{align}\n    H(e^{j \\omega}) &= \\frac{1}{6} \\frac{\\sin(3\\omega)}{\\sin\\left(\\frac{\\omega}{2}\\right)} e^{-j \\frac{5}{2} \\omega} \\\\\n    |H(e^{j \\omega})| &= \\frac{1}{6} \\left|\\frac{\\sin(3\\omega)}{\\sin\\left(\\frac{\\omega}{2}\\right)}\\right| \\\\\n    \\angle H(e^{j \\omega}) &= -\\frac{5}{2} \\omega \\\\\n\\end{align}\nThe zero crossings are \\(\\omega = \\frac{k\\pi}{3}\\) for nonzero \\(k \\in \\Z\\), by solving for the equation \\(\\sin(3\\omega) = 0\\).\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(\\omega\\), ylabel={\\(|H(e^{j \\omega})|\\)},\n            title={Magnitude of Frequency Response},\n            axis lines=middle,\n            ymin=0, ymax=1,\n            width=0.4\\textwidth\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=n, y=q6a-mag\n        ]{q6a-mag.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(\\omega\\), ylabel={\\(\\angle H(e^{j \\omega})\\)},\n            title={Phase of Frequency Response},\n            axis lines=middle,\n            width=0.4\\textwidth\n        ]\n        \\addplot[color=blue] table[\n            col sep=comma,\n            x=n, y=q6a-ang\n        ]{q6a-ang.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\n\n\\subsection{}\n\nLet \\(\\omega_1 = \\frac{\\pi}{3}\\).\nThen, the output \\(y[n]\\) is as shown:\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(n\\), ylabel={\\(y[n]\\)},\n            title={Convolution Sum},\n            axis lines=middle,\n            width=0.4\\textwidth\n        ]\n        \\addplot[ycomb, mark=*, color=blue] table[\n            col sep=comma,\n            x=n, y=q6b\n        ]{q6b.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\nThe transient at the start of the convolution sum comes from at the beginning of the MAF, where the positive terms from the first 2 inputs of the cosine function.\nThe settling of the convolution sum comes from the fact that the sum of a sinusoid without a vertical shift over 1 period is 0. Since the MAF has a window of size 6, and the cosine has a period of 6 as well, once the window is filled by the cosine, it we get 0.\nFor any value of the convolution sum afterwards, it remains 0 due to the MAF now being saturated with a constant 1 period of the cosine, which has a sum of 0.\n\n\\newpage\n\\section{}\n\n\\begin{equation}\n    y[n] = \\mathcal{P}\\{x[n - 2], x[n - 1], x[n], x[n + 1], x[n + 2]\\}\n\\end{equation}\n\n\\subsection{}\n\nWe can transform the problem into a least-squares problem:\n\\begin{equation}\n    \\begin{bmatrix}\n        x[-2] \\\\\n        x[-1] \\\\\n        x[0] \\\\\n        x[1] \\\\\n        x[2]\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n        1 & -2 & 4 \\\\\n        1 & -1 & 1 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1 \\\\\n        1 & 2 & 4\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        a_0 \\\\\n        a_1 \\\\\n        a_2\n    \\end{bmatrix}\n\\end{equation}\nBy the least squares formula \\(\\bm{\\hat{a}} = (\\bm{P}^\\top \\bm{P})^{-1} \\bm{P}^\\top \\bm{x}\\), we get that\n\\begin{align}\n    \\begin{bmatrix}\n        a_0 \\\\\n        a_1 \\\\\n        a_2\n    \\end{bmatrix}\n    &=\n    \\frac{1}{35} \\begin{bmatrix}\n        -3 & 12 & 17 & 12 & -3 \\\\\n        -7 & -3.5 & 0 & 3.5 & 7 \\\\\n        5 & -2.5 & -5 & -2.5 & 5\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        x[-2] \\\\\n        x[-1] \\\\\n        x[0] \\\\\n        x[1] \\\\\n        x[2]\n    \\end{bmatrix} \\\\\n    \\implies y[0] &= a_0 = \\frac{1}{35} (-3x[-2] + 12x[-1] + 17x[0] + 12x[1] - 3x[2])\n\\end{align}\n\n\\subsection{}\n\n\\begin{equation}\n    \\begin{bmatrix}\n        x[-1] \\\\\n        x[0] \\\\\n        x[1] \\\\\n        x[2] \\\\\n        x[3]\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n        1 & -2 & 4 \\\\\n        1 & -1 & 1 \\\\\n        1 & 0 & 0 \\\\\n        1 & 1 & 1 \\\\\n        1 & 2 & 4\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        a_0 \\\\\n        a_1 \\\\\n        a_2\n    \\end{bmatrix}\n\\end{equation}\nwhich gives us the solution\n\\begin{equation}\n    y[1] = a_0 = \\frac{1}{35} (-3x[-1] + 12x[0] + 17x[1] + 12x[2] - 3x[3])\n\\end{equation}\n\n\\subsection{}\n\nThe system is linear since it entirely consists of additions and scalar multiplications.\nThe system is time-invariant since for any shift \\(n_0\\), the corresponding \\(x[n - n_0]\\) is simply shifted and put into the solution, which is what is expected for a time-shifted output.\nThe system is stable since if \\(x[n]\\) is bounded by \\(B_x\\), \\(y[n]\\) is bounded by \\(B_x\\).\nSince the system is LTI, the system has a frequency response.\nWe do not actually need to perform a regression for every \\(n\\), since the coefficient matrix multiplying the set of \\(x[n - k]\\) is constant.\n\n\\subsection{}\n\nWe can see that points further from the operating point have the largest weights, while weights further away have smaller and even negative weights.\nThis means that it better represents a distribution around a local region, and does not flatten out features as drastically as a standard MAF.\n\n\\end{document}\n", "meta": {"hexsha": "2af6020e3f931f831d428ae348b3686712d6f540", "size": 11667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw01/hw01.tex", "max_stars_repo_name": "bdngo/ee-123", "max_stars_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw01/hw01.tex", "max_issues_repo_name": "bdngo/ee-123", "max_issues_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw01/hw01.tex", "max_forks_repo_name": "bdngo/ee-123", "max_forks_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_forks_repo_licenses": ["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.3879093199, "max_line_length": 261, "alphanum_fraction": 0.542555927, "num_tokens": 3901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6154312290765378}}
{"text": "\\section{Arbitrage theory in continuous markets}\n\nWe now develop an heuristic model for continuous-time markets. We shall omit most technical definitions, details and proofs. It is an amalgam of the presentations found in \\textcite{bjork2004arbitrage}, \\textcite{brigo2007interest}, \\textcite{duffie2010dynamic}, \\textcite{jameswebber2000interest}, \\textcite{musielarutkowski2005martingale} and \\textcite{wu2009interest}. A rigorous treatment for the subject can be found, for example, in \\textcite{musielarutkowski2005martingale}. The fundamentals of this model are the same as the simple discrete model introduced earlier, but due to technicalities, it is not as intuitive.\n\nWe consider a probability space $(\\Omega, \\F, \\Pf)$ and a finite time interval $\\left[ 0, T' \\right]$. Here $\\Pf$ is the physical probability measure on $(\\Omega, \\F)$, $\\Omega$ is the sample path space with a $\\sigma$-algebra $\\F$. The flow of new information is handled with a filtration\\footnote{A filtration $(\\F_t)$ is a collection $\\sigma$-sub-algebras of $\\F$ with $\\F_s \\subseteq \\F_t$ for all $0 \\leq s \\leq t \\leq T$.} $(\\F_t)$. We also assume some technical conditions for the filtrations. Every $\\Pf$-null set\\footnote{$\\Pf$-null set is a set $A \\in \\F$ with $\\Pf (A) = 0$.} must be a member of $\\F_0$ and\n  \\begin{align}\n    \\F_t = \\bigcap_{t < s} \\F_s\n  \\end{align}\nfor all $t \\geq 0$.\n\nWe assume that the price $S_i$ of a market assets are modeled with It\\'{o}-processes\\footnote{See \\ref{sec:itoprocess}}, so\n  \\begin{align}\n    \\label{generalassetpriceprocess}\n    S_i(t,\\omega) = S_i (0) + \\int_0^t \\mu (t,\\omega) \\dx t + \\int_0^t \\sigma(t, \\omega ) \\dx W_i (t, \\omega),\n  \\end{align}\nwhere $S_i(0)$ is a deterministic constant and $W_i$ is a Brownian motion. The second integral is an It\\'{o}-integral and the functions $\\mu$ and $\\sigma$ are assumed to be $\\F_t$-adapted and to satisfy technical conditions so that integrability and the existence of solutions are always guaranteed\\footnote{It is usually assumed, for example, that $\\int_0^{T^*} \\left| \\mu(t, \\omega) \\right| \\dx t < \\infty$ and $\\int_0^{T^*} \\sigma(t, \\omega)^2 \\dx t < \\infty$ almost surely}. We usually write the Equation \\ref{generalassetpriceprocess} as\n  \\begin{align}\n    \\dx S_i(t, \\omega) = \\mu (t,\\omega) \\dx t + \\sigma(t, \\omega ) \\dx W_i (t, \\omega),\n  \\end{align}\nbut we note that Brownian motions are $\\Pf$-surely not differentiable. We assume that the assets all these assets can be bought and sold freely, and the trading shall not affect price process.\n\nWe also shall omit $\\omega$ from the argument of functions for readability, when it is not absolutely necessary.\n\nSuppose that there are $n$ tradable assets and let $S = (S_1, S_2, \\ldots, S_n)$ be the price vector for these assets. The trading strategy (or a portfolio) $w$ is a predictable stochastic process $w(t,\\omega) \\in \\R^n$. This means that while the strategy is a random variable, it is not omniscient and uses only information available up to that point. It is left-continuous, so given the history up to that point, it is deterministic. The corresponding portfolio value process is given by\n  \\begin{align}\n    V^w (t) = (w(t))^{\\top} S(t)\n  \\end{align}\nand a self-financing trading strategy satisfies\n\t\\begin{align}\n\t\tV^w(t) - V^w(0) = \\int_0^t w^{\\top}(u) \\ \\dx S(u),\n\t\\end{align}\nor\n  \\begin{align}\n    \\dx V^w = (w(t))^{\\top} \\dx S(t) .\n  \\end{align}\nThis means that for self-financing portfolio, there is no inflow or outflow of money from the portfolio and all the value changes are due to changes of prices. An arbitrage\\footnote{We note that this type of arbitrage is not strong enough to disallow doubling strategies.} is a self-financing portfolio with a value process $V^w (t)$ such that\n  \\begin{align}\n    V^w(0) &= 0, \\\\\n    \\Pf (V^w(t) \\geq 0 ) &= 1 \\textup{ and } \\\\\n    \\Pf (V^w(t) > 0 ) &> 0.\n  \\end{align}\n for some $0 \\leq t \\leq T'$. An arbitrage is an opportunity to gain without any associated risk. A market without arbitrage opportunities is arbitrage-free. \n  \nA contingent claim (or $T$-derivative or $T$-claim) is a $\\F_T$-measurable random variable $X$. We say that the is attainable if there is such self-financing trading strategy $w$ that\n  \\begin{align}\n    V^w(T) = X(T)\n  \\end{align}\nalmost surely. The strategy $w$ is thus replicating the pay-off of $X$. As usually, we say that the market is complete if every contingent claim is attainable.\n  \nAs earlier, a deflator is strictly positive It\\^{o}-process and a num\\'{e}raire is an asset with always positive price process. If $D$ is deflator, then the relative (or discounted) market price process is\n  \\begin{align}\n    S^D(t) = ( S_i(t) / D(t) )\n  \\end{align}\nfor all $0 \\leq t \\leq T'$. A measure $\\Pm$ on the space $(\\Omega, \\F)$ is an equivalent martingale measure (EMM) with respect to the deflator $D$ if it is equivalent\\footnote{Meaning that the measures have the same null sets.} to $\\Pf$ and if\n  \\begin{align}\n    S^D(s) = \\E_{\\Pm} ( \\ S^D(t) \\ | \\ \\F_s \\ )\n  \\end{align}\nfor all $0 \\leq s < t$. This means that discounted price processes are martingales under an EMM.  A weaker condition is an equivalent local martingale measure (ELMM) which requires only that the measures are equivalent and discounted price process are local martingale under the ELMM.\n\nWe will only consider trading strategies that will satisfy the condition that\n  \\begin{align}\n    \\int_0^t w(s)^{\\top} \\dx S^D(s)\n  \\end{align}\nare martingales under the the measure $\\Pm$ as this guarantees that no doubling strategies are permissable\\footnote{Thus the expected values of portfolios are always bounded.}.\n  \nThe first fundamental theorem of asset pricing says that if an equivalent martingale measure exists, then the market is arbitrage-free. As we have seen, in discrete time model, these are equivalent conditions. But in continuous models, this in not true. \\textcite{delbaenschachermayer1994general} showed that under certain conditions, the absence of arbitrage implies that an equivalent local martingale measure exists. We shall not delve in these technicalities further in this thesis.\n\nThe second fundamental theorem of asset pricing ties the uniqueness of this EMM to the ability to hedge every derivative contract. If we assume that the market is arbitrage free and an equivalent martingale measure exists for a deflator $D$, then the market is complete if and only if the equivalent martingale measure for deflator $D$ is unique.\n\nAs in discrete setting, we have three distinct cases: the model has no EMM, it has several EMMs or the EMM is unique. \n\nIdeally the EMM is unique and the model is complete and it allows no arbitrage. Traditionally the discounting in the EMM has been done with respect to the risk-free rate, but \\textcite{gemanelkarouirochet1995changes} showed that the choice of the so-called num\\'{e}raire is actually arbitrary as long as it is strictly positive non-dividend paying asset process. Different num\\'{e}raires produces different EMMs, but if we assume that payoffs are square integrable random variables, then the change of num\\'{e}raire does not change replicating portfolios. Thus the price is unique as long as the derivative can be hedged. If $S_0$ is the num\\'{e}raire, $X$ is a $T$-derivate with replicating self-financing portfolio's value process given by $V^w(t)$, then we have that $X(T) = V^w(T)$ and every discounted value processes of self-financing portfolio is martingale under the EMM $\\Pm_0$ associated with discounting process $S_0$. Thus\n  \\begin{align}\n    \\frac{V^w(t) }{ S_0(t) } = \\E_{\\Pm_0} \\left( \\frac{V^w(T)}{S_0(T)} | \\F_t \\right) = \\E_{\\Pm_0} \\left( \\frac{X(T)}{S_0(T)} | \\F_t \\right)\n  \\end{align}\nmeaning that \n  \\begin{align}\n    \\label{discountedexpectedvalue}\n    V^w(t) = S_0(t) \\E_{\\Pm_0} \\left( \\frac{V^w(T)}{S_0(T)} | \\F_t \\right) = S_0(t) \\E_{\\Pm_0} \\left( \\frac{X(T)}{S_0(T)} | \\F_t \\right) .\n  \\end{align}\nSince there are no arbitrage opportunities, $X(t) = V^w(t)$, where $V^w(t)$ is given by the equation (\\ref{discountedexpectedvalue}). This has to hold even if the replicating portfolio is not unique.\n\nIf the model has several EMMs, then arbitrage is not possible but there are derivatives that may not be hedged. In this model, a claim that can be replicated has a unique price. Claims that may not be replicated may have multiple prices corresponding to different EMMs. \n\nThis usually means that calibrating prices are taken carefully selected from the most liquid instruments. We can also use more generalized versions of hedging. We could take the set of all sensible portfolio strategies that promise almost surely a payoff that is equal or greater than the contingent claim. A reasonable price candidate for a derivative is the minimum maintenance price of these portfolio strategies.\n\nThe worst case is the absence of EMM. This means that the model has arbitrage and pricing cannot be done.\n\nThe num\\'{e}raire can be freely chosen. \\cite{gemanelkarouirochet1995changes} showed that if the market is arbitrage-free, $M$ and $N$ are arbitrary num\\'{e}raires, then there exists such EMMs $\\Pm_M$ and $\\Pm_n$ that\n\t\\begin{align}\n\t\t\\frac{X(t)}{M(t)} &= \\E_{\\Pm_M} \\left( \\frac{X(T)}{M(T)} | \\F_t \\right), \\\\\n\t\t\\frac{X(t)}{N(t)} &= \\E_{\\Pm_N} \\left( \\frac{X(T)}{N(T)} | \\F_t \\right)\n\t\\end{align}\nfor any asset $X$ and $0 \\leq t \\leq T$. The Radon-Nikod\\'{y}m derivate\\footnote{See \\ref{sec:radonnikodymtheorem}} is\n\t\\begin{align}\n\t\t\\xi(t) = \\frac{\\dx \\Pm_M}{\\dx \\Pm_N} = \\frac{M(t) N(0)}{M(0) N(t)} .\n\t\\end{align}\nThis implies that\n\t\\begin{align}\n\t\tX(t) &= M(t) \\E_{\\Pm_M} \\left( \\frac{X(T)}{M(T)} | \\F_t \\right) \\\\ \n\t\t&= N(t) \\E_{\\Pm_N} \\left( \\frac{X(T)}{N(T)} | \\F_t \\right)\n\\end{align}\nand the price is unique, if the claim can be replicated. Also\n\t\\begin{align}\n\t\t\\label{expectationbyradonnikodymderivative}\n\t\t\\E_{\\Pm_M} \\left( Y(T) | \\F_t \\right) = \\frac{\\E_{\\Pm_N} \\left( Y(T) \\xi(T)  | \\F_t \\right)}{\\xi(t)} \n\t\\end{align}\nholds for any random variable $Y$.\n\n\\subsection{Risk-free measure}\n\nThe bank account $\\Bank(t) > 0$ is a common num\\'{e}raire and the EMM $\\Pm_0$ induced by it is often called as the risk-free measure. If $X$ is a portfolio and the market is arbitrage-free, then\n\t\\begin{align}\n\t\t\\label{pricingunderriskneutralmeasure}\n\t\tX(t) &= \\Bank(t) \\E_{\\Pm_0} \\left( \\frac{X(T)}{B(T)} | \\F_t \\right) \\\\\n\t\t\t&= \\E_{\\Pm_0} \\left( \\frac{B(t)}{B(T) } X(T) | \\F_t \\right) \\\\\n\t\t\t&= \\E_{\\Pm_0} \\left( D(t,T) X(T)  | \\F_t \\right),\n\t\\end{align}\nwhere $D(t,T)$ is the stochastic discount factor. If $X(t) = \\Bond(t,T)$, then $\\Bond(T,T)=1$ and we note that\n\t\\begin{align}\n\t\t\\Bond(t,T) = \\E_{\\Pm_0} \\left( D(t,T) \\ | \\ \\F_t \\right) .\n\t\\end{align}\nThis shows that price of a bond is expected value of the corresponding stochastic discount factor under the risk-free measure (or any other EMM). Also if\n\t\\begin{align}\n\t\t\\Bank(t) = \\e^{ \\int_0^t r(s) \\ \\dx s },\n\t\\end{align}\nthen\n\t\\begin{align}\n\t\tD(t,T) = \\frac{\\Bank(t)}{\\Bank(T)} = \\e^{ - \\int_t^T r(s) \\ \\dx s },\n\t\\end{align}\nhence\n\t\\begin{align}\n\t\tX(t) &= \\E_{\\Pm_0} \\left( \\e^{ - \\int_t^T r(s) \\ \\dx s } X(T)  | \\F_t \\right) . \n\\end{align}\t\n\nUnder the risk-neutral measure, the discounted process $X(t) / B(t)$ will be a martingale.\n\t\n\\subsection{Black-Scholes--model}\n\nIn the celebrated Black-Scholes--model there are two assets, a stock and a bank account, with given dynamics\n  \\begin{align}\n    \\label{stockprocessinblackscholes}\n    \\dx S(t) &= \\mu S(t) \\dx t + \\sigma S(t) \\dx W(t) \\\\\n    \\dx \\Bank (t) &= r \\Bank(t) \\dx t, \n  \\end{align}\nunder the physical measure $\\Pf$, where $\\mu, r$ and $\\sigma > 0$ are given constants and the Brownian motion $W(t)$ is the sole source of uncertainty. This means that the stock price follows geometric Brownian motion and $\\Bank (t) = \\Bank (0) \\e^{rt}$. To simplify the notation we assume that $\\Bank (0) = 1$. We denote the discounted stock price as $S^\\Bank(t) = S(t) / \\Bank (t)$ and the discount factor is deterministic $\\DF (t,T) = \\e^{r(T-t)}$. Now $g(t,x) = \\e^{-rt} x$ and a simple application of It\\^{o}'s lemma\\footnote{See \\ref{sec:itoprocess}.} yields that\n  \\begin{align}\n    \\dx S^\\Bank(t) &= ( \\frac{\\partial g}{\\partial t} + \\mu \\frac{\\partial g}{\\partial x} + \\frac{1}{2} \\sigma^2 \\frac{\\partial^2 g}{\\partial x^2} ) \\dx t + \\sigma \\frac{\\partial g}{\\partial x} \\dx W(t) \\\\\n      &= ( -r \\e^{-rt} S(t) + \\e^{-rt} \\mu S(t) + 0 ) \\dx t + \\sigma \\e^{-rt} S(t) \\dx W(t) \\\\\n      &= ( \\mu - r ) S^\\Bank(t) \\dx t + \\sigma S^\\Bank(t) \\dx W(t) .\n  \\end{align}\nWe can now use Girsanov's theorem\\footnote{See \\ref{sec:girsanov}.} to change the probability measure in order to make the discounted stock price process driftless. We note the bank account discounted by itself is trivially driftless under any measure. Now the market price of risk\n\t\\begin{align}\n\t\t\\lambda = \\frac{r - \\mu}{\\sigma}\n\t\\end{align}\nis the only possible Girsanov kernel that makes the new measure an equivalent martingale measure. So there is an unique EMM $\\Pm$ for the deflator $B(t)$. hence Black-Scholes model is arbitrage-free and complete. Under this measure $\\dx W^{\\Pm}(t) = \\dx W(t) - \\frac{r - \\mu}{\\sigma} \\dx t$ is a Brownian motion. Therefore\n  \\begin{align}\n    \\dx S^\\Bank(t) &= \\sigma S^\\Bank(t) \\dx W^{\\Pm}(t), \\\\\n    \\dx \\Bank (t) &= r \\Bank (t) \\dx t, \\\\\n    \\label{BlackScholesProcessesUnderEMM}\n    \\dx S(t) &= r S(t) \\dx t + \\sigma S(t) \\dx W^{\\Pm}(t)\n  \\end{align}\nunder the EMM $\\Pm$. In other words, the discounted stock price is a martingale and under this measure the drift of the stock price is changed to the risk-free rate $r$. Since the bank account is deterministic, the change of measure does not affect it. The arbitrage-free price of the derivate is at time $0$ is given by\n  \\begin{align}\n    X(0) &= \\E_{\\Pm} \\left( X(T) / \\Bank (0,T) | \\F_0 \\right) \\\\ &= \\e^{-rT} \\E_{\\Pm} \\left( X(T) | \\F_0 \\right) .\n  \\end{align}\nSince the stock price process under the risk-free measure is a geometric Brownian motion, we know that\n  \\begin{align}\n    \\log (S(T) ) &= \\log (S(0) ) + \\left( r  - \\frac{1}{2} \\sigma^2 \\right) T + \\sigma W^{\\Pm}(T) \\\\ &\\sim N \\left( \\log (S(0) ) + \\left( r  - \\frac{1}{2} \\sigma^2 \\right), \\sigma^2 T \\right)\n  \\end{align}\nunder the measure $\\Pm$. Similarly, we could use the stock price $S(t)$ as the numerator. \n\nIf we pick $X(T) = (S(T)-K)^+$, the price of a call option on the stock at the time $T$, then\n\t\\begin{align}\n\t\t\\E_{\\Pm} \\left( (S(T)-K)^+ | \\F_0 \\right) &= \\E_{\\Pm} \\left( (S(T)-K) \\1_{ \\{ S(T) > K\\} } | \\F_0 \\right) \\\\\n\t\t&= \\E_{\\Pm} \\left( S(T) \\1_{ \\{ S(T) > K\\} } | \\F_0 \\right) - K \\Pm \\left( S(T) > K | \\F_0 \\right)\n\t\\end{align}\nand the standard calculations will yield that\n  \\begin{align}\n    X(T) &= S(0) N(d_+)  -  \\e^{-rT} K N(d_-) , \\\\\n    d_{\\pm} &= \\frac{\\log S/K + (r \\pm \\sigma^2/2 )T }{\\sigma \\sqrt{T}},\n  \\end{align}\nwhich is the celebrated Black-Scholes formula.\n\nWe shall also give a heuristic derivation of the Black-Scholes differential equation. If $X(t,S(t))$ is a smooth value process of a derivative, then by It\\'{o}'s lemma, we have that\n  \\begin{align}\n    \\label{itolemmatoderivateinblackscholes}\n    \\dx X = \\left( \\frac{\\partial X}{\\partial t} + \\mu S \\frac{\\partial X}{\\partial S} + \\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial X^2}{\\partial S^2} \\right) \\dx t + \\sigma S \\frac{\\partial X}{\\partial S} \\dx W .\n  \\end{align}\nNow we assume that we can replicate this derivative with a combination of $\\delta_S(t,S)$ stocks and $\\delta_B(t,S)$ bonds. This portfolio has a value \n\t\\begin{align}\n\t\tV(t,S) = \\delta_S S(t) + \\delta_B B(t)\n\t\\end{align}\nand the value follows the process\n\t\\begin{align}\n\t\t\\dx V &= \\delta_S \\dx S + \\delta_B \\dx B \\\\\n\t\t\t&= \\delta_S (\\mu S \\dx t + \\sigma S \\dx W ) + \\delta_B r B \\dx t \\\\\n\t\t\t&= (\\delta_S \\mu S + \\delta_B rB) \\dx t + \\delta_S \\sigma S \\dx W \\\\\n\t\t\t&= (\\delta_S \\mu S + r (V - \\delta_S S)) \\dx t + \\delta_S \\sigma S \\dx W\n\t\\end{align}\nAs $\\dx V = \\dx X$, then the coefficients of $\\dx W$ terms must coincide. Thus\n\t\\begin{align}\n\t\t\\label{replicating_delta}\n\t\t\\delta_S \\sigma S = \\sigma S \\frac{\\partial X}{\\partial S},  \t\t\n\t\\end{align}\nwhich implies that $\\delta_S = \\frac{\\partial X}{\\partial S}$.\n\nNow we consider a portfolio of one derivative and $-\\frac{\\partial X}{\\partial S}$ stocks. The value of this portfolio is\n  \\begin{align}\n    V = X - \\frac{\\partial X}{\\partial S} S\n  \\end{align}\nand if the portfolio is self-financing, then\n  \\begin{align}\n    \\dx V &= \\dx X - \\frac{\\partial X}{\\partial S} \\dx S \\\\\n      &= \\left( \\frac{\\partial X}{\\partial t} + \\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial X^2}{\\partial S^2} \\right) \\dx t\n  \\end{align}\nafter substitution of equations \\ref{stockprocessinblackscholes} and \\ref{itolemmatoderivateinblackscholes}. Since there is no diffusion, the portfolio is riskless and the absence of arbitrage implies that \n  \\begin{align}\n    \\dx V = rV \\dx t = \\left( rX - r S\\frac{\\partial X}{\\partial S} \\right) \\dx t .\n  \\end{align}\nBy equating these, we get the Black-Scholes differential equation\n  \\begin{align}\n  \t\\label{BlackScholesDifferentialEquation}\n    \\frac{\\partial X}{\\partial t} + r S\\frac{\\partial X}{\\partial S} + \\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial X^2}{\\partial S^2} - r X = 0\n  \\end{align}\nor equivalently\n \t\\begin{align}\n\t\t\\frac{\\partial X}{\\partial t} + \\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial X^2}{\\partial S^2} = r ( X - S\\frac{\\partial X}{\\partial S}) .\n\t\\end{align}\nThe left side is a linear combination of \"theta\", the time decay of the value, and \"gamma\", the second derivative of the value with respect to the price of the underlying. The right side of the equation contains the replicating portfolio.\n\nThe derivative with pay-out $h(S(T))$ satisfies Equation \\ref{BlackScholesDifferentialEquation}. In order to apply Feynman-Kac theorem\\footnote{See \\ref{sec:faynmankac}.}, we need to find a process with drift $rS(t)$ and diffusion $\\sigma S(t)$ under some measure. Under the EMM, the discounted asset price is a martingale, so it grows with the rate risk-free rate $r$. So the price process under the EMM is process we need in order to use Feynman-Kac theorem. We have the EMM $\\Pm$ and, by Equation \\ref{BlackScholesProcessesUnderEMM},\n\t\\begin{align}\n\t\t\\dx S(t) &= r S(t) \\dx t + \\sigma S(t) \\dx W^{\\Pm}(t) ,\t\t\n\t\\end{align}\nwhere $W^{\\Pm}(t)$ is a Brownian motion under $\\Pm$. We may now apply Feynman-Kac theorem and it follows that\n\t\\begin{align}\n\t\th(S(t)) = \\e^{ -r(T-t) } \\E_{\\Pm} ( h(S_T) \\ | \\ \\F_t) .\n\t\\end{align}\n\t\n\\iffalse\n\t\n\\subsubsection{Black-Scholes--model with continuous dividend yield}\n\nIf $X(t)$ is the price of call option on stock $S(t)$ with strike $K$ at the time $T$ that pays continuous dividend yield $q$, then the extension of Black-Scholes--model gives the price\n\t\\begin{align}\n\t\tX(t) &= \\e^{-r(T-t)} \\left( F(t)N(d_+) - KN(d_-) \\right), \\\\\n\t\tF(t) &= S(t)  \\e^{(r-q)(T-t)}, \\\\\n\t\td_{\\pm} &= \\frac{\\log \\frac{S(t)}{K} + (r-q \\pm \\frac{1}{2} \\sigma^2)(T-t)}{\\sigma \\sqrt{T-t}}\t\t\n\t\\end{align}\n\t\nSuppose now that assets $S_i(t)$ pay continuous dividend yields $q_i$. Suppose that an option gives right to swap asset $S_1$ with asset $S_2$ at the time $T$. \n\n\\fi\n\n\\subsection{Black-76--model}\n\\label{blackformula}\n\nBlack model (or Black-76--model) is an extension of Black-Scholes--model (\\cite{black1976pricing}) and it is used to price futures. It also assumes that the risk-free interest rate is a constant. The model assumes that futures price of an asset follows log-normal distribution with constant volatility parameter. The price of a call option on a future contract has price at time $t$ is given by the Black's formula\n\\begin{align}\n\\e^{-r(T-t)} \\left( F N(d_+) - K N(d_-) \\right)\n\\end{align}\nwith\n\\begin{align}\nd_{\\pm} = \\frac{\\log \\frac{F}{K} \\pm \\frac{\\sigma^2}{2} (T-t) }{ \\sigma \\sqrt(T-t) } .\n\\end{align}\nHere $K$ is the strike price at the maturity $T$, $r$ is the risk-free rate and $\\sigma$ is the constant volatility of the log-normal distribution. The futures price process is $F(t)$. The Black's formula is used to price interest rate caps, floors and swaptions and the market practice is to quite these instruments in terms of Black's volatilities.\n\t\n\\subsection{$T$-forward measure}\n\nSince $\\Bond(t,T) > 0$, $T$-bond is a num\\'{e}raire. The EMM induced by this as called $T$-forward measure $\\Pm_T$. Since $\\Bond(T,T) = 1$, we have that\n\\begin{align}\nX(t) = \\Bond(t,T) \\E_{\\Pm_T} \\left( X(T) | \\F_t \\right)\n\\end{align}\nfor every $0 \\leq t \\leq T$ and attainable claim $X$. The forward rate was defined as\n\\begin{align}\n\\Rflt(t,T,S) &= \\frac{1}{\\dayc(T,S)} \\left( \\frac{\\Bond(t,T)}{\\Bond(t,S)} - 1 \\right) .\n\\end{align}\nThus\n\\begin{align}\n\\Rflt(t,T,S) \\Bond(t,S)  &= \\frac{\\Bond(t,T)-\\Bond(t,S)}{\\dayc(T,S)}  ,\n\\end{align}\nwhere the right side is a bond portfolio. As $\\Bond(T,T) = 1$, we know that \n\\begin{align}\n\\frac{\\Bond(t,T)-\\Bond(t,S)}{\\dayc(T,S)} &= \\Bond(t,T) \\E_{\\Pm_T} \\left( \\Rflt(T,T,S) | \\F_t \\right) \n\\end{align}\nNow we have that shown that\n\\begin{align}\n\\Rflt(t,T,S) &= \\E_{\\Pm_T} \\left( \\Rflt(T,S) | \\F_t \\right) \n\\end{align}\nmeaning that the forward rate is expected value of spot rate under the $T$-forward measure.\t\n\nSimilarly\n\\begin{align}\nP(t,T) \\E_{\\Pm_T} \\left( r(T) | \\F_t \\right) &= \\E_{\\Pm_0} \\left( D(t,T) r(T) | \\F_t \\right) \\\\\n&= \\E_{\\Pm_0} \\left( r(T) \\e^{-\\int_t^T r(s) \\dx s} | \\F_t \\right) \\\\\n&= \\E_{\\Pm_0} \\left( \\frac{\\partial}{\\partial T} \\e^{-\\int_t^T r(s)} | \\F_t \\right) \\\\\n&= \\frac{\\partial}{\\partial T} \\E_{\\Pm_0} \\left( \\e^{-\\int_t^T r(s)} | \\F_t \\right) \\\\\n&= \\frac{\\partial}{\\partial T} P(t,T) ,\n\\end{align}\nwhich implies that\n\\begin{align}\nf(t,T) = \\E_{\\Pm_T} \\left( r(T) | \\F_t \\right) \n\\end{align}\nmeaning that the instantaneous forward rate is the expected value of the short-rate under $T$-forward measure. \n\nThe Equation \\ref{expectationbyradonnikodymderivative} implies that  \n\\begin{align}\n\\xi (t) = \\frac{\\Bond(t,T)}{\\Bond(0,T) \\Bank(t)}\n\\end{align}\nis the Radon-Nikod\\'{y}m-derivative of $T$-forward measure $\\Pm_T$ with respect to risk-free measure $\\Pm_0$.\n\n\n\\subsection{Change of num\\'{e}raire}\n\nNow we consider an arbitrage free market model with assets $N$ and $M$, which are num\\'{e}raires. If $X$ is a contingent $T$-claim, then we know that arbitrage free price of $X$ at the time $t$ must be\n  \\begin{align}\n    V_t (X) &= N(t) \\E_{\\Pm_N} \\left( \\frac{X(T)}{N(T)} | \\F_t \\right) \\\\\n            &= M(t) \\E_{\\Pm_M} \\left( \\frac{X(T)}{M(T)} | \\F_t \\right)\n  \\end{align}\nwhere $\\Pm_N, \\Pm_M$ are the martingale measure corresponding to the num\\'{e}raires $N$ and $M$. Thus\n  \\begin{align}\n    \\E_{\\Pm_N} \\left( \\frac{X(T)}{N(T)} | \\F_t \\right) &= \\E_{\\Pm_M} \\left( \\frac{M(t)}{N(t)} \\frac{X(T)}{M(T)} | \\F_t \\right) \\\\\n      &= \\E_{\\Pm_M} \\left( L_T(t) \\frac{X(T)}{N(T)} | \\F_t \\right),\n  \\end{align}\nwhere\n  \\begin{align}\n    L_T(t) = \\frac{N(T) / N(t)}{ M(T) / M(t) } = \\frac{M(t)}{N(t)} \\frac{N(T)}{M(T)} .\n  \\end{align}\nNow $L_T(t)$ is a $\\Pm_N$-martingale \nSince $X$ is an arbitrary $\\F_T$-measurable random variable, we have heuristically shown the following fundamental result. For the proof, see \\cite{gemanelkarouirochet1995changes}.\n  \n\\begin{thm}\nLet $\\Pm_N$ be the EMM associated with num\\'{e}raire $N$ and $\\Pm_M$ be the EMM associated with num\\'{e}raire $M$. Under some technical conditions, the Radon-Nikod\\'{y}m derivate of $\\Pm_M$ with respect to $\\Pm_N$ is\n  \\begin{align}\n    \\frac{\\dx \\Pm_N}{\\dx \\Pm_M} = \\frac{N(T) / N(t)}{ M(T) / M(t) } .\n  \\end{align}\n\\end{thm}\n\nSince $Z(t,T) > 0$ for all pairs $(t,T)$ we may use zero-coupon bonds as num\\'{e}raire. We denote $\\Pm_T$ as the equivalent martingale measure given by the $T$-bond. Thus if $X$ is a contingent $T$-claim, then we know that arbitrage free price of $X$ at the time $t$ must be\n  \\begin{align}\n    V_t (X) &= Z(t,T) \\E_{\\Pm_T} \\left( X(T) \\right) .\n  \\end{align}\n\n\\iffalse\n \nTähän jotakin siitä, että Björk s. 357.\n\nIf $X(T) = (S(T) - K)^+$ is a final pay-out of a contingent claim $X$ for some asset $S$ and fixed $K$, then\n  \\begin{align}\n    V_t (X) &= \\E_{\\Pm} \\left( \\frac{X(T)}{B(T)} | \\F_t \\right) \\\\\n            &= \\E_{\\Pm} \\left( \\frac{ (S(T) - K) \\1_{ \\{S_T > K \\} } }{B(T)} | \\F_t \\right) \\\\\n            &= \\E_{\\Pm} \\left( \\frac{ S(T) }{ B(T) } \\1_{ \\{S_T > K \\} } | \\F_t \\right) - K \\E_{\\Pm} \\left( \\frac{\\1_{ \\{S_T > K \\} } }{B(T)} | \\F_t \\right) .\n  \\end{align}\nIf $S$ is also a num\\'{e}raire we may write\n  \\begin{align}\n    \\E_{\\Pm} \\left( \\frac{ S(T) }{ B(T) } \\1_{ \\{S_T > K \\} } | \\F_t \\right) &= \\E_{\\Pm_S} \\left( L_S(T) \\frac{ S(T) }{ B(T) } \\1_{ \\{S_T > K \\} } | \\F_t \\right) \\\\\n    &= \\E_{\\Pm_S} \\left( \\frac{ S(t) }{ B(t) } \\1_{ \\{S_T > K \\} } | \\F_t \\right) \\\\\n    &= \\frac{ S(t) }{ B(t) } \\Pm_S ( S_T > K )\n  \\end{align}\nwhere we used likelihood ratio\n  \\begin{align}\n    L_S (T) = \\frac{ S(t) }{ B(t) } \\frac{ B(T) }{ S(T) }\n  \\end{align}\nto change measure from risk-free measure $\\Pm$ to the martingale measure $\\Pm_S$ with num\\'{e}raire $S$. The second term is\n  \\begin{align}\n    \\E_{\\Pm} \\left( \\frac{\\1_{ \\{S_T > K \\} } }{B(T)} | \\F_t \\right) &= \\E_{\\Pm_T} \\left( L_T(T) \\frac{\\1_{ \\{S_T > K \\} } }{B(T)} | \\F_t \\right) \\\\\n    &= \\E_{\\Pm_T} \\left( \\frac{ Z(t,T) }{ B(t) } \\1_{ \\{S_T > K \\} } | \\F_t \\right) \\\\\n    &= \\frac{ Z(t,T) }{ B(t) } \\Pm_T ( S_T > K )\n  \\end{align}\nwhere we used $Z(T,T) = 1$ and likelihood ratio\n  \\begin{align}\n    L_T (t) = \\frac{ Z(t,T) }{ B(t) } \\frac{ B(T) }{ Z(T,T) }\n  \\end{align}\nto change measure from risk-free measure $\\Pm$ to the $T$-forward measure $\\Pm_T$. Thus\n  \\begin{align}\n    V_t (X) &= \\frac{ S(t) }{ B(t) } \\Pm_S ( S_T > K ) - K \\frac{ Z(t,T) }{ B(t) } \\Pm_T ( S_T > K )\n  \\end{align}\nand especially\n  \\begin{align}\n    V_0 (X) &= S(0) \\Pm_S ( S_T > K ) - K Z(0,T) \\Pm_T ( S_T > K ) .\n  \\end{align}\n  \n \\fi\n  \n\n \n\n", "meta": {"hexsha": "f4fdb2f6013c1f3d36085278c4454251e34eeaf4", "size": 25686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "market.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": "market.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": "market.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": 66.030848329, "max_line_length": 934, "alphanum_fraction": 0.6624620416, "num_tokens": 8864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.6154312284884017}}
{"text": "% !TEX root=../main.tex\n\n\\begin{comment}\nConsider a feature matrix $\\X \\in \\Real^{N \\times D}$,\nwhere $N$ denotes the number of data points and $D$ the number of features for each point.\nFor example, $N$ could be the number of images in some photo collection, and $D$ the number of pixels used to represent each image.\nThe goal of anomaly detection is to determine which rows of $\\X$ are anomalous, in the sense of being dissimilar to all other rows. We will use $\\X_{n :}$ to denote the $n$th row of $\\X$.\n\\end{comment}\n\n%\\subsection{A tour of anomaly detection methods}\n\nAnomaly detection is a well-studied topic in Data Science~\\cite{chandola2007outlier,charubook}. Unsupervised anomaly detection aims at discovering\nrules to separate normal and anomalous data in the absence of labels. One-Class SVM (OC-SVM) is a popular unsupervised approach to detect anomalies, which constructs\na smooth boundary around the majority of probability mass of data~\\cite{Scholkopf:2001}. OC-SVM will be  described in detail in Section~\\ref{sec:ocsvm}.\nIn recent times, several approaches of feature selection and feature extraction methods have been proposed for complex, high-dimensional\ndata for use with OC-SVM ~\\cite{cao2003comparison,neumann2005combined}.\nFollowing the unprecedented success of using deep autoencoder networks, as feature extractors, in tasks as diverse as visual, speech anomaly detection~\\cite{chong2017abnormal,marchi2017deep}, several hybrid models that combine feature extraction using deep learning and OC-SVM\nhave appeared~\\cite{sohaib2017hybrid,erfani2016high}. The benefits of leveraging pre-trained transfer learning  representations for anomaly detection in hybrid models was made evident by the results obtained, using two publicly available~\\footnote{Pretrained-models:http://www.vlfeat.org/matconvnet/pretrained/.} pre-trained CNN models: ImageNet-MatConvNet-VGG-F (VGG-F) and  ImageNet-MatConvNet-VGG-M (VGG-M)~\\cite{andrews2016transfer}. However, these hybrid OC-SVM approaches are decoupled in the sense that the feature learning is task agnostic and not customized for anomaly detecion. Recently a deep model which trains a neural network by minimizing the volume of a hypersphere that encloses the network representations of the data is proposed ~\\cite{pmlrv80ruff18a}, our approach differs from this approach by combining the ability of deep networks to extract progressively rich representation of data alongwith the one-class objective, which obtains the hyperplane to separate all the normal data points from the origin.\n %In this paper, we formulate and evaluate a new architecture for anomaly detection in complex, high-dimensional domains by integrating the one-class objective into neural network arhitecture. The proposed one-class neural network (OC-NN) model is trained using standard back-propogation algorithm to learn, rich differentiable features customized for anomaly detection. To the best of our knowledge, this is the first method proposed which\n%combines the ability of deep networks to extract progressively rich representation of data\n%with the one-class objective of creating a tight envelope around normal data to improve the performance\n%for anomaly detection.\n\n\\begin{comment}\n\\subsection{Deep hybrid OC-SVM Models.}\nA popular hybrid approach followed in unsupervised anomaly detection is to couple feature reduction and extraction methods alongwith SVMs~\\cite{cao2003comparison,neumann2005combined,shen2008feature,widodo2007combination}. Several hybrid models have been proposed to leverage the representational power of deep learning to address scalability issues of SVMs~\\cite{song2017hybrid,you2017hybrid,sohaib2017hybrid}. Deep learning architectures such as sparse stacked autoencoder (SAE)-based deep neural networks (DNNs)~\\cite{sohaib2017hybrid}, deep belief networks (DBNs)~\\cite{erfani2016high} are adopted for extracting robust features. DBNs are generative models consisting of multiple layers of latent variables (\"hidden units\"). The advantages of using DBNs are two-fold: (a) their ability to perform non-linear dimensionality reduction (b) learn high dimensional data representations. A DBN can be trained efficiently in a greedy layer-wise fashion by using a Restricted Boltzmann Machine (RBM)~\\cite{hinton2010practical}. A Restricted Boltzmann machine model can be defined by joint energy function on the hidden variable $h_k$ with $K$ dimension and visible input variable $x_d$ with $D$ dimension as seen in Equation~\\ref{energy}. The model parameters $W^P_{dk}$ encode the pairwise compatibility between $x_d$ and $h_k$ while the  parameters $W^B_k$ and $W^C_d$ are biases which, selectively activates either $h_k$ or $x_d$.\n\n\\begin{align}\n\\label{energy}\n    E_W(\\mbf{x},\\mbf{h})&=\n-\\sum_{d=1}^D\\sum_{k=1}^K W^P_{dk}x_dh_k - \\sum_{k=1}^KW^B_k h_k - \\sum_{d=1}^D W^C_d x_d\n\\end{align}\n\nIn the context of anomaly detection for images, the $\\mbf{x}$ variables may represent (e.g  pixels of the image). The hidden units are binary vector of length $K$ less than original dimension of image $D$. Training an RBM implies finding the values of the parameters such that the energy is minimised. One possible approach is to maximise the log-likelihood of $x$ that is estimated by its gradient with respect to the model parameters using Contrastive Divergence (CD). The DBN consisting of stack of RBMs model encodes rich feature representations of the input within hidden units. While a hybrid model consisting of DBN, trained to extract generic underlying features, as inputs to one-class SVM trained are shown to be effective~\\cite{erfani2016high}. The experiments in the aforementioned work were performed on real-datasets comprising 1D inputs, synthetic data or texture images, which have lower dimensionality and different data distribution compared to colour images or long protein sequences.\n\\end{comment}\n\n%%%%%\n\\subsection{Robust Deep Autoencoders for anomaly detection}\nBesides the hybrid approaches which use OC-SVM with deep learning features another approach for anomaly detection is to use deep autoencoders.\nInspired by RPCA~\\cite{xu2010robust}, unsupervised anomaly detection techniques such as robust deep autoencoders can be used to separate\nnormal from anomalous data~\\cite{zhou2017anomaly,chalapathy2017robust}.\nRobust Deep Autoencoder (RDA) or Robust Deep Convolutional Autoencoder (RCAE) decompose input data $X$ into two parts $X = L_D + S$, where $L_D$ represents the latent representation the hidden layer of the autoencoder. The matrix  $S$ captures noise and outliers which are hard to reconstruct as shown in Equation~\\ref{eqn:robust-ae}. The decomposition is carried out by optimizing the objective function shown in Equation~\\ref{eqn:robust-ae}.\n\n\\begin{equation}\n\t\\label{eqn:robust-ae}\n\t\\min_{\\theta, S} + ||L_D - D_{\\theta}(E_{\\theta}(L_D)) ||_{2}+ \\lambda \\cdot \\| S^T \\|_{2,1}\n\\end{equation}\n \\hspace{1.8cm}   $s.t. \\hspace{0.2cm} X - L_D -S = 0 $\n\n\n\nThe above optimization problem is solved using a combination of backpropagation and Alternating Direction Method of Multipliers (ADMM) approach~\\cite{boyd2004convex}. In our experiments  we have carried out a detailed comparision between OC-NN and approaches based on robust autoencoders.\n\n\\begin{comment}\nNotice that in the constraint of Equation~\\ref{eqn:robust-ae} we split the input data X into two\nparts, $L_D$ and $S$. $L_D$ is the input to an autoencoder $D_{\\theta}(E_{\\theta}(L_D))$ and\nwe train this autoencoder by minimizing the reconstruction error\n $||L_D - D_{\\theta}(E_{\\theta}(L_D)) ||_{2}$ through back-propagation. $S$, on the other\nhand, contains noise and outliers which are learnt applying proximal methods following Alternating Direction Method of Multipliers (ADMM) ~\\cite{boyd2004convex}. While $\\lambda$ tuning parameter is selected in a semi-supervised fashion through grid-search for optimal $F1$ score.\nRDA could be leveraged to detect anomalies similar to OC-SVM setting. The results obtained using our proposed approach of OC-NN are comparable to the results obtained on anomaly detection task on both MNIST and Cifar-10 datasets, as illustrated in Table~\\ref{tbl:mnist-usps-anomaly-results-summary} and Table~\\ref{tbl:cifar-10-pfam-anomaly-results-summary}.\n\\end{comment}\n\n\\subsection{One-Class SVM for anomaly detection}\n\\label{sec:ocsvm}\n\nOne-Class SVM (OC-SVM) is a widely used approach to discover anomalies in an unsupervised fashion~\\cite{scholkopf2002support}. OC-SVMs are a special case of support vector machine, which learns a  hyperplane to separate all the data points from the origin in a reproducing kernel Hilbert space (RKHS) and maximises the distance from this hyperplane to the origin. Intuitively in OC-SVM all the data points are considered as positively labeled instances and the origin\nas the only negative labeled instance. More specifically, given a training data $\\X$, a set without any class information, and $\\Phi(\\X)$  a RKHS map function\nfrom the input space to the feature space $F$,  a\nhyper-plane or linear decision function $f(\\X_{n :})$ in the feature space $F$ is constructed as\n$f( \\X_{n :} ) = w^T \\Phi(\\X_{n :}) - \\bias$,  to separate as many as possible of the mapped vectors\n${ \\Phi(\\X_{n :}), n: 1,2,...,N}$ from the origin. Here  $w$ is the norm perpendicular to the hyper-plane and $\\bias$ is the bias of the hyper-plane. In order to\nobtain $w$ and $\\bias$, we need to solve the\nfollowing optimization problem,\n\n\\begin{equation}\n\\label{eqn:ocsvm-objective}\n \\min_{w,\\bias} \\frac{1}{2} \\| w \\|_{2}^2+ \\frac{1}{\\nu} \\cdot \\frac{1}{N} \\sum_{n = 1}^N \\max( 0, \\bias - \\langle w, \\Phi(\\X_{n :}) \\rangle ) - \\bias.\n\\end{equation}\n\nwhere $\\nu \\in (0,1)$, is a parameter that\ncontrols a trade off between maximizing the distance of the\nhyper-plane from the origin and the number of data points\nthat are allowed to cross the hyper-plane (the false positives).\n%When $\\nu$ is small, fewer data fall on the same side of the hyper-plane as the origin in the\n%feature space $F$.\n\n\n\n", "meta": {"hexsha": "95d8dd1b99ba1b2c8fc62a496279d96c208c5028", "size": 9995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ARXIV_DAD_Survey/src/background.tex", "max_stars_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey", "max_stars_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 107, "max_stars_repo_stars_event_min_datetime": "2019-01-11T12:06:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T12:03:57.000Z", "max_issues_repo_path": "ARXIV_DAD_Survey/src/background.tex", "max_issues_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey_Arxiv_WorkingDocument", "max_issues_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ARXIV_DAD_Survey/src/background.tex", "max_forks_repo_name": "raghavchalapathy/Deep-Learning-for-Anomaly-Detection-A-Survey_Arxiv_WorkingDocument", "max_forks_repo_head_hexsha": "aa775990a4b23306885979c4ef8e8cb3ed00441b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-01-15T02:42:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-06T07:59:29.000Z", "avg_line_length": 112.3033707865, "max_line_length": 1428, "alphanum_fraction": 0.7845922961, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6154312194980561}}
{"text": "\\section{Poisson and Laplace Equations}\r\n\\subsection{The Boundary Value Problem}\r\nMany problems in mathematical physics can be reduced to the form:\r\n$$\\nabla^2\\phi=F$$\r\nwhere $F$ is known.\r\nThis form of equations are called Poisson's Equation.\r\nIn particular, if $F\\equiv 0$, this is called Laplace's Equation.\r\nWe would want to solve them in either all of $\\mathbb R^n$ or on some domain $\\Omega\\subset\\mathbb R^n$.\r\nWe are, sometimes, only interested in the cases $n=2,3$.\r\nNote that we require $\\phi$ to be well-defined and smooth on all of $\\Omega$.\r\nFor example, it is true that $\\nabla^2(1/|\\underline{x}|)=0$ for $\\underline{x}\\neq\\underline{0}$, however it is not true for any domain containing $\\underline{0}$.\r\nWe would want to solve this PDE subject to some boundary conditions, so $\\phi$ will have predetermined behaviour in $\\partial\\Omega$ or as $|\\underline{x}|\\to\\infty$ when working in $\\mathbb R^n$.\\\\\r\nTwo widely studied boundary conditions are the Dirichlet Problem\r\n$$\\begin{cases}\r\n    \\nabla^2\\phi=F\\text{, on $\\Omega$}\\\\\r\n    f\\text{, on $\\partial\\Omega$}\r\n\\end{cases}$$\r\nand the Neumann Problem\r\n$$\\begin{cases}\r\n    \\nabla^2\\phi=F\\text{, on $\\Omega$}\\\\\r\n    \\partial\\phi/\\partial\\underline{n}=\\underline{n}\\cdot\\nabla\\phi=g\\text{, on $\\partial\\Omega$}\r\n\\end{cases}$$\r\nBeware that we must interpret boundary data (or boundary conditions) correctly.\r\nWe want $\\phi$ or $\\partial\\phi/\\partial\\underline{n}$ to approach the boundary data continuously as $\\underline{x}$ tends towards the boundary.\r\nSo apart from requiring $\\phi$ to be $C^2$ in $\\Omega$, it must also extend to $\\partial\\Omega$ continuously.\r\n\\begin{example}[Non-example]\r\n    If we want to solve the Navier-Stokes Equation\r\n    $$\\frac{\\partial\\underline{u}}{\\partial t}+(\\underline{u}\\cdot\\nabla)\\underline{u}-\\nu\\nabla^2\\underline{u}=-\\nabla p,\\nabla\\cdot\\underline{u}=0,\\underline{u}(\\underline{x},0)=\\underline{u_0}(\\underline{x})$$\r\n    but ignore the condition on continuous extension we said earlier, then the following solution satisfies the equation\r\n    $$\\underline{u}=\\begin{cases}\r\n        0\\text{, if $t>0$}\\\\\r\n        \\underline{u_0}\\text{, if $t=0$}\r\n    \\end{cases},p\\equiv 0$$\r\n    But obviously we are not getting a million for it.\r\n\\end{example}\r\n\\begin{example}\r\n    Let $r=|\\underline{x}|$, we consider the Dirichlet Problem\r\n    $$\\begin{cases}\r\n        \\nabla^2\\phi=r\\text{, for $r<a$}\\\\\r\n        \\phi=1\\text{, for $r=a$}\r\n    \\end{cases}$$\r\n    By symmetry, we want to write $\\phi=\\phi(r)$, so\r\n    $$r=\\nabla^2\\phi=\\frac{1}{r^2}\\frac{\\mathrm d}{\\mathrm dr}\\left( r^2\\frac{\\mathrm d\\phi}{\\mathrm dr} \\right)\\implies \\phi=\\frac{r^3}{12}-\\frac{A}{r}+B$$\r\n    The boundary condition then implies\r\n    $$\\phi(r)=1+\\frac{r}{12}(r^2-a^2)$$\r\n\\end{example}\r\nConsider now a generic linear problem, say $L\\phi=F$ in $\\Omega$ and $B\\phi=f$ on $\\partial\\Omega$ where $L,B$ are linear differential operators.\r\nSuppose $\\phi_1,\\phi_2$ are solutions to the system, then if we let $\\psi=\\phi_1-\\phi_2$, we have $L\\psi=B\\psi=0$.\r\nIf we can show that this solves to $\\psi=0$, then we know the uniqueness of the solution to our original equation.\r\nSo solution to a linear problem is unique iff the only solution to the corresponding homogeneous problem is $0$.\r\n\\begin{proposition}\r\n    Solution to the Dirichlet Problem is unique.\r\n    Solution to the Neumann Problem is unique up to a constant.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider the homogeneous problem\r\n    $$\\begin{cases}\r\n        \\nabla^2\\psi=0\\text{, in $\\Omega$}\\\\\r\n        B\\psi=0\\text{, in $\\partial\\Omega$}\r\n    \\end{cases}$$\r\n    where $B\\psi=\\psi$ in the Dirichlet case and $B\\psi=\\partial\\psi/\\partial\\underline{n}$ in the Neumann case.\r\n    Consider\r\n    $$I[\\phi]=\\int_\\Omega|\\nabla\\psi|^2\\,\\mathrm dV\\ge 0$$\r\n    But we have\r\n    \\begin{align*}\r\n        I[\\phi]&=\\int_\\Omega\\nabla\\cdot(\\psi\\nabla\\psi)-\\psi\\nabla^2\\psi\\,\\mathrm dV\\\\\r\n        &=\\int_\\Omega\\nabla\\cdot(\\psi\\nabla\\psi)\\,\\mathrm dV\\\\\r\n        &=\\int_{\\partial\\Omega}\\psi\\nabla\\psi\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=\\int_{\\partial\\Omega}\\psi\\frac{\\partial\\phi}{\\partial\\underline{n}}\\,\\mathrm dS\\\\\r\n        &=0\r\n    \\end{align*}\r\n    in both cases, $\\nabla\\psi=0$ thoughout $\\Omega$, so $\\psi$ is continuous throughout $\\Omega$.\r\n    So for the Dirichlet Problem we have $\\psi\\equiv 0$ and $\\psi$ is constant in the Neumann Problem.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the charge distribution (where $r=\\underline{\\underline{x}}$),\r\n    $$\\rho(\\underline{x})=\\begin{cases}\r\n        0\\text{, if $r<a$}\\\\\r\n        F(r)\\text{, if $r\\ge a$}\r\n    \\end{cases}$$\r\n    The corresponding potential $\\phi$ for electric field $\\underline{E}=-\\nabla\\phi$ would have\r\n    $$\\nabla^2\\phi=-\\epsilon_0^{-1}\\rho$$\r\n    On $r<a$, we have $\\nabla^2\\phi=0$, so by symmetry, we write $\\phi=\\phi(r)$.\r\n    Note that on $r=a$, $\\phi=\\phi(a)$ is a constant.\r\n    We can see that $\\phi(r)=\\phi(a)$ on $r<a$ actually works, but by the preceding proposition, it is the solution on $r<a$, so $\\underline{E}\\equiv \\underline{0}$ on $r<a$.\\\\\r\n    This looks like the Newton's Shell Theorem.\r\n\\end{example}\r\n\\subsection{Gauss's Flux Method}\r\nThere is a clever way to get particular solutions to Poisson's Equation when the forcing term has spherical symmetry.\r\nSuppose the forcing term is in the form $F(r)$ where $r=|\\underline{x}|$, and we are interested in a particular solution of the equation $\\nabla^2\\phi=F(r)$.\r\nWe want to look for solutions of the form $\\phi=\\phi(r)$, in which case $\\nabla\\phi=\\phi^\\prime(r)\\underline{e_r}$.\r\nIf we integrate this over the ball $|\\underline{x}|\\le R$, then since $\\nabla^2=\\nabla\\cdot\\nabla$,\r\n$$\\int_{|\\underline{x}|\\le R}F\\,\\mathrm dV=\\int_{|\\underline{x}|\\le R}\\nabla^2\\phi\\,\\mathrm dV=\\int_{|\\underline{x}|=R}\\nabla\\phi\\cdot\\mathrm d\\underline{S}$$\r\nby Divergence Theorem.\r\nNote that $\\mathrm d\\underline{S}=\\underline{e_r}\\mathrm dS$, so\r\n$$\\int_{|\\underline{x}|=R}\\nabla\\phi\\cdot\\mathrm d\\underline{S}=\\int_{|\\underline{x}|=R}\\phi^\\prime(r)\\,\\mathrm dS=\\phi^\\prime(R)\\int_{|\\underline{x}|=R}\\mathrm dS=4\\pi R^2\\phi^\\prime(R)$$\r\nDefine\r\n$$Q(R)=\\int_{|\\underline{x}|\\le R}F(r)\\,\\mathrm dV$$\r\nthen $Q(R)=4\\pi R^2\\phi^\\prime(R)$.\r\nIf $F$ is interpreted as the charge density, then we can interpret $Q(R)$ as total charge (or other stuff) inside the ball of radius $R$.\r\nWe can integrate this to get a particular solution.\r\nIn particular, we observe that $\\phi^\\prime(R)=Q(R)/(4\\pi R^2)$, which is just the inverse square law.\r\n\\begin{example}\r\n    Consider charge density\r\n    $$\\rho(r)=\\begin{cases}\r\n        \\rho_0\\text{, if $r\\le a$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    The electric field corresponding to $\\rho$ satisfies $\\nabla\\cdot\\underline{E}=\\epsilon_0^{-1}\\rho$.\r\n    In electrostatics, $\\underline{E}=-\\nabla\\phi$ for a potential $\\phi$, so we have\r\n    $$\\nabla^2\\phi=-\\frac{\\rho}{\\epsilon_0}$$\r\n    By previous calculations\r\n    $$\\phi^\\prime(R)=-\\frac{1}{4\\pi\\epsilon_0}\\frac{Q(R)}{R^2},Q(R)=\\begin{cases}\r\n        4\\pi R^3\\rho_0/3\\text{, if $R\\le a$}\\\\\r\n        Q=Q(a)=4\\pi a^3\\rho_0/3\\text{, otherwise}\r\n    \\end{cases}$$\r\n    So for $r>a$, we have\r\n    $$\\phi^\\prime(r)=-\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\implies\\underline{E}(r)=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\underline{e_r}$$\r\n    Let $a\\to 0$ in such a way that $a^3\\rho_0$ remains constant (so we change $\\rho_0$), so $Q$ remains constant.\r\n    Therefore the electric field induced by a point charge $Q$ at $\\underline{x}=\\underline{0}$ would have\r\n    $$\\underline{E}(\\underline{x})=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{r^2}\\underline{e_r}=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{|\\underline{x}|^3}\\underline{x},\\phi(\\underline{x})=\\frac{1}{4\\pi\\epsilon_0}\\frac{Q}{|\\underline{x}|}$$\r\n    for $r>0$ and $\\phi(\\infty)=0$.\r\n\\end{example}\r\nJust an aside, if we want the existece of solutions to $-\\nabla^2\\phi=\\epsilon_0^{-1}\\rho(\\underline{x})$, Gauss proved that it suffices to consider equations of the form $K\\sigma=f$ which looks like linear algebra, but in a infinite dimensional vector spaces, where we no longer have sequential compactness.\r\nThis induces the study of functional analysis and operator theory.\\\\\r\nSuppose we have $F=F(\\rho)$ where $\\rho=x^2+y^2$.\r\nTo solve $\\nabla^2\\varphi=F(\\rho)$, it is natural to try solutions of the form $\\varphi=\\varphi(\\rho)$.\r\nIn this case, $\\nabla\\varphi=\\varphi^\\prime(\\rho)\\underline{e_\\rho}$, so obviously we want to integrate it over a cylinder $V$ of height $1$, $V=\\{0\\le\\rho\\le R,0\\le\\phi\\le 2\\pi,z_0\\le z\\le z_0+1\\}$, as $\\underline{e_\\rho}\\perp\\underline{e_z}$,\r\n$$Q(R)=\\int_VF\\,\\mathrm dV=\\int_{\\partial V}\\nabla\\varphi\\cdot\\mathrm d\\underline{S}=\\varphi^\\prime(R)2\\pi R\\implies\\varphi^\\prime(R)=\\frac{Q(R)}{2\\pi R}$$\r\nNote that by calculation we have\r\n$$Q(R)=2\\pi\\int_0^RF(\\rho)\\rho\\,\\mathrm d\\rho\\implies\\varphi^\\prime(\\rho)=\\frac{1}{R}\\int_0^RF(\\rho)\\rho\\,\\mathrm d\\rho$$\r\n\\begin{example}\r\n    Due to conflicts of notation we write $s^2=x^2+y^2$ instead of $\\rho$ (as we want to do electromagnetism).\r\n    Suppose we have charge density\r\n    $$\\rho(s)=\\begin{cases}\r\n        \\rho_0\\text{, for $s\\le a$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    For electrostatic potential $\\varphi$, we still have $-\\nabla^2\\varphi=\\epsilon_0^{-1}\\rho$, so\r\n    $$\\varphi^\\prime(R)=-\\frac{1}{\\epsilon_0R}\\int_0^R\\rho(s)s\\,\\mathrm ds=\\begin{cases}\r\n        -\\epsilon_0^{-1}R^{-1}\\rho_0R^2/2\\text{, if $R\\le a$}\\\\\r\n        -\\epsilon_0^{-1}R^{-1}\\rho_0a^2/2\\text{, otherwise}\\\\\r\n    \\end{cases}$$\r\n    Then shrink $a\\to 0$ with $\\rho_0a^2$ fixed, then we have $\\underline{E}\\propto s^{-1}\\underline{e_s}$, which is similar to the superposition a bunch of point charges in a line.\r\n\\end{example}\r\n\\subsection{The Superposition Principle}\r\nFor a linear problem, we can (most of the time) solve them by their defining property of being linear.\r\nSay if we have $L\\psi_n=F_n$, then $L(\\sum_n\\psi_n)=\\sum_nF_n$.\r\nThis allows us to superpose solutions.\r\nIf we write a forcing term $F$ as $\\sum_nF_n$ and solve for $\\psi_n$ individually, then we can obtain the required solution by summing up all of them.\r\n\\begin{example}\r\n    1. Recall the solutions for an electric potential $\\phi$ and electric field $\\underline{E}=-\\nabla\\phi$.\r\n    For charge distribution with spherical symmetry, can be found by e.g. Gauss's flux method.\r\n    If we shrink the radius to $0$, we obtain a point charge $Q_{\\underline{a}}$ for at $\\underline{a}$ where\r\n    $$\\phi(\\underline{x})=\\frac{Q_{\\underline{a}}}{4\\pi\\epsilon_0}\\frac{1}{|\\underline{x}-\\underline{a}|}$$\r\n    and $\\rho(\\underline{x})=Q_{\\underline{a}}\\delta(\\underline{x}-\\underline{a})$.\r\n    For consistency with Gauss's Law, we shall (and indeed can) obtain\r\n    $$\\nabla^2\\left( -\\frac{1}{4\\pi}\\frac{1}{|\\underline{x}-\\underline{a}|} \\right)=\\delta(\\underline{x}-\\underline{a})$$\r\n    Now consider the electric potential due to $2$ charges $Q_{\\underline{a}},Q_{\\underline{b}}$ at $\\underline{x}=\\underline{a},\\underline{b}$.\r\n    The charge distribution would be $Q_{\\underline{a}}\\delta(\\underline{x}-\\underline{a})+Q_{\\underline{b}}\\delta(\\underline{x}-\\underline{b})$, so we can superpose the solutions correspondingly in Gauss's Law to get the potential\r\n    $$\\phi(\\underline{x})=\\frac{Q_{\\underline{a}}}{4\\pi\\epsilon_0}\\frac{1}{|\\underline{x}-\\underline{a}|}+\\frac{Q_{\\underline{b}}}{4\\pi\\epsilon_0}\\frac{1}{|\\underline{x}-\\underline{b}|}$$\r\n    2. We want to find the potential outside the solid sphere $|\\underline{x}|\\le R$ of uniform charge density $\\rho_0$, from which several spheres $|\\underline{x}-\\underline{a_i}|\\le R_i$ with $i=1,2,\\ldots,n$ are removed (given that the spheres do not cross the boundary).\r\n    To find the solution, we can superpose the solution for the charge distribution $\\rho_0$ for $|\\underline{x}|\\le R$ and the solutions for the charge distribution $-\\rho_0$ for $|\\underline{x}-\\underline{a_i}|\\le R_i$.\r\n    So\r\n    $$\\phi(\\underline{x})=\\frac{1}{4\\pi\\epsilon_0}\\left( \\frac{Q}{|\\underline{x}|}-\\sum_{i=1}^n\\frac{Q_i}{|\\underline{x}-\\underline{a_i}|} \\right),Q=\\frac{4}{3}\\pi R^3\\rho_0,Q_i=\\frac{4}{3}\\pi R_i^3\\rho_0$$\r\n    for $|\\underline{x}|>R$.\r\n\\end{example}\r\n\\subsection{Integral Solutions}\r\nIn the examples above, we found solutions by superposing (or superimposing) potentials corresponding to charges in different points, which gives solutions of the form\r\n$$\\sum_i\\frac{Q_i}{4\\pi\\epsilon_0}\\frac{1}{|\\underline{x}-\\underline{a_i}|}$$\r\nThis leads to a more general form of superposition of potentials, by thinking of each infinitesimal part as individual point charges, which is just a integral in the following form:\r\n$$\\int_{\\mathbb R^3}\\frac{F(\\underline{y})}{|\\underline{x}-\\underline{y}|}\\,\\mathrm dV(\\underline{y})$$\r\nUp to some factor.\r\n\\begin{proposition}\r\n    The unique solution to the Dirichlet problem\r\n    $$\\begin{cases}\r\n        \\nabla^2\\phi=F\\text{, in $\\mathbb R^3$}\\\\\r\n        \\phi(\\underline{x})\\to 0\\text{ as $|\\underline{x}|\\to\\infty$}\r\n    \\end{cases}$$\r\n    (Assuming $F$ decreases sufficiently rapidly as $|\\underline{x}|\\to\\infty$) is\r\n    $$\\phi(\\underline{x})=-\\frac{1}{4\\pi}\\int_{\\mathbb R^3}\\frac{F(\\underline{y})}{|\\underline{x}-\\underline{y}|}\\,\\mathrm dV$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The solution can be verified by using\r\n    $$\\nabla\\left( -\\frac{1}{4\\pi}\\frac{1}{|\\underline{x}-\\underline{a}|} \\right)=\\delta(\\underline{x}-\\underline{a})$$\r\n    And differentiating under the integral sign.\r\n\\end{proof}\r\nTo justify (in an applied way, of course) the identity used above, we use the divergence theorem,\r\n\\begin{align*}\r\n    \\int_{|\\underline{x}|\\le R}\\nabla^2\\left( \\frac{1}{|\\underline{x}|} \\right)\\,\\mathrm dV&=\\int_{|\\underline{x}|=R}\\nabla\\left( \\frac{1}{r} \\right)\\cdot\\mathrm d\\underline{S}\\\\\r\n    &=-\\frac{1}{R^2}\\int_{|\\underline{x}|=R}\\underline{e_r}\\cdot\\underline{e_r}\\,\\mathrm dS\\\\\r\n    &=\\frac{1}{R^2}4\\pi R^2\\\\\r\n    &=4\\pi\r\n\\end{align*}\r\nwhich is true for any $R>0$, so it is natural (or maybe not) to write the identity.\\\\\r\nThe solution can be regarded as the sum of contributions to the potential to any possible volume elements (that actually contribute).\r\n\\subsection{Harmonic Functions}\r\nIf $\\phi=\\phi(\\underline{x})$ satisfies Laplace's Equation $\\nabla^2\\phi=0$, then $\\phi$ is harmonic.\r\n\\begin{proposition}[Mean-Value Property]\r\n    If $\\varphi$ is harmonic on some open $\\Omega\\subset\\mathbb R^3$, then\r\n    $$\\varphi(\\underline{a})=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}-\\underline{a}|=r}\\varphi(\\underline{x})\\,\\mathrm dS$$\r\n    where $\\underline{a}\\in\\Omega$ and the ball centered at $\\underline{a}$ with radius $r$ is contained in $\\Omega$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Define a function\r\n    \\begin{align*}\r\n        f(r)&=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}-\\underline{a}|=r}\\varphi(\\underline{x})\\,\\mathrm dS\\\\\r\n        &=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}|=r}\\varphi(\\underline{x}+\\underline{a})\\,\\mathrm dS\\\\\r\n        &=\\frac{1}{4\\pi r^2}\\int_0^{2\\pi}\\int_0^\\pi \\varphi(\\underline{a}+r\\underline{e_r})r^2\\sin\\theta\\,\\mathrm d\\theta\\,\\mathrm d\\phi\\\\\r\n        &=\\frac{1}{4\\pi}\\int_0^{2\\pi}\\int_0^\\pi \\varphi(\\underline{a}+r\\underline{e_r})\\sin\\theta\\,\\mathrm d\\theta\\,\\mathrm d\\phi\r\n    \\end{align*}\r\n    So differentiating this gives\r\n    \\begin{align*}\r\n        f^\\prime(r)&=\\frac{1}{4\\pi}\\int_0^{2\\pi}\\int_0^\\pi \\nabla\\varphi(\\underline{a}+r\\underline{e_r})\\cdot\\underline{e_r}\\sin\\theta\\,\\mathrm d\\theta\\,\\mathrm d\\phi\\\\\r\n        &=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}|=r}\\nabla\\varphi(\\underline{a}+\\underline{x})\\cdot\\mathrm d\\underline{S}\\\\\r\n        &=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}|\\le r}\\nabla^2\\varphi(\\underline{a}+\\underline{x})\\,\\mathrm dV\\\\\r\n        &=0\r\n    \\end{align*}\r\n    So $f$ is constant.\r\n    Let $r\\to 0$ gives $f\\equiv \\varphi(\\underline{a})$.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    For a smooth function $\\varphi$\r\n    $$\\nabla^2\\varphi=\\lim_{r\\to 0}\\frac{6}{r^2}\\left(\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}-\\underline{a}|=r}\\varphi(\\underline{x})\\,\\mathrm dS-\\varphi(\\underline{a})\\right)$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider the function\r\n    $$g(r)=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}-\\underline{a}|=r}\\varphi(\\underline{x})\\,\\mathrm dS-\\varphi(\\underline{a})$$\r\n    then use the same trick as above, we have\r\n    $$g^\\prime(r)=\\frac{1}{4\\pi r^2}\\int_{|\\underline{x}|\\le r}\\nabla^2\\varphi(\\underline{x})\\,\\mathrm dV$$\r\n    But\r\n    \\begin{align*}\r\n        \\int_{|\\underline{x}|\\le r}\\nabla^2\\varphi(\\underline{x})\\,\\mathrm dV&=\\int_{|\\underline{x}|\\le r}\\nabla^2\\varphi(\\underline{a})\\,\\mathrm dV+\\left( \\int_{|\\underline{x}|\\le r}\\nabla^2\\varphi(\\underline{x})-\\nabla^2\\varphi(\\underline{a})\\,\\mathrm dV \\right)\\\\\r\n        &=\\frac{4\\pi r^3}{3}\\nabla^2\\varphi(\\underline{a})+o(r^3)\r\n    \\end{align*}\r\n    as $r\\to 0$.\r\n    So\r\n    $$g^\\prime(r)=\\frac{r}{3}\\nabla^2\\varphi(\\underline{a})+o(r)$$\r\n    But then $g^\\prime(r)=g^\\prime(0)+rg^\\prime(0)+o(r)$ by Taylor's Theorem, so $g^\\prime(0)=0,g^{\\prime\\prime}(0)=3^{-1}\\nabla^2\\varphi(\\underline{a})$.\r\n    So\r\n    $$g(r)=g(0)+rg^\\prime(0)+r^2\\frac{g^{\\prime\\prime}(0)}{2}+o(r^2)=\\frac{r^2}{6}\\nabla^2\\varphi(\\underline{a})+o(r^2)$$\r\n    So taking the stated limit gives the solution.\r\n\\end{proof}\r\nSo the Laplacian measures how much the value of the function at the point differs from the average of the values on the infinitesimal sphere centered at the same point.\r\n\\begin{proposition}[Maximum Principle]\r\n    If $\\varphi$ is harmonic on an open, path-connected $\\Omega\\in\\mathbb R^3$, then there is an $\\underline{a}\\in\\Omega$ such that $\\varphi(\\underline{x})\\le\\varphi(\\underline{a})$ throughout $\\Omega$, then $\\varphi$ is constant.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $\\varphi$ is harmonic, then the mean-value property holds, so\r\n    $$\\varphi(\\underline{a})=\\frac{1}{4\\pi\\epsilon^2}\\int_{|\\underline{x}-\\underline{a}|=\\epsilon}\\varphi(\\underline{x})\\,\\mathrm dS$$\r\n    for $\\epsilon$ sufficiently small.\r\n    If $\\varphi(\\underline{x})\\le\\varphi(\\underline{a})$ throughout $\\Omega$, then\r\n    $$0=\\frac{1}{4\\pi\\epsilon^2}\\int_{|\\underline{x}-\\underline{a}|=\\epsilon}\\varphi(\\underline{a})-\\varphi(\\underline{x})\\,\\mathrm dS$$\r\n    But the integrand is nonnegative, so we must have $\\varphi(\\underline{x})=\\varphi(\\underline{a})$ for any $\\underline{x}$ in the sphere we are integrating, hence the ball enclosed.\r\n    Now take any $\\underline{y}\\in\\Omega$ and consider a path joining $\\underline{a}$ and $\\underline{y}$.\r\n    Then by compactness, there is a finite collection of spheres in $\\Omega$ whose interior covers the path.\r\n    But then each adjascent two of them will share at least one interior points, and if $f$ achieve $f(\\underline{a})$ at that point, then $f(\\underline{x})\\le f(\\underline{a})$ for any $\\underline{x}$ in each ball, so use the argument inductively gives $f(\\underline{y})=f(\\underline{a})$.\r\n\\end{proof}\r\nOne can also prove the last part without introducing compactness:\r\nAssuming that we have already shown that for any $\\underline{b}\\in\\Omega$ with $\\varphi(\\underline{b})=\\alpha=\\varphi(\\underline{a})$, there is some $\\epsilon>0$ such that $\\varphi(\\underline{x})=\\varphi(\\underline{b})=\\alpha$ for any $|\\underline{x}-\\underline{b}|<\\epsilon$ (by e.g. the first part of our proof above).\r\nConsider the set $\\varphi^{-1}(\\{\\alpha\\})$, which is closed by continuity and open by above, which contradicts the path-connectedness (hence connectedness) of $\\Omega$.", "meta": {"hexsha": "3a04b0cb18b72c93e6a638408f17d1ca9d18875b", "size": 19412, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/poislap.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": "7/poislap.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": "7/poislap.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.3754789272, "max_line_length": 321, "alphanum_fraction": 0.6637646816, "num_tokens": 6474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.6154238654856433}}
{"text": "\\documentclass[12pt]{article}\n\\newcommand{\\m}{\\mathrm{m}}\n\\newcommand{\\cm}{\\mathrm{cm}}\n\\newcommand{\\s}{\\mathrm{s}}\n\\newcommand{\\dd}{\\mathrm{d}}\n\\newcounter{problem}\n\\begin{document}\\thispagestyle{empty}\n\n\\section*{NYU General Physics 1---Problem set 10}\n\n\\paragraph{Problem~\\theproblem:}\\refstepcounter{problem}%\nConsider a function $$x(t) = A\\,\\sin(\\omega\\,t + \\phi) \\quad,$$ where\n$A$, $\\omega$, and $\\phi$ are constants.  Now consider the\n``differential equation'' $$m\\,\\frac{\\dd^2 x}{\\dd t^2} = -k\\,x\n\\quad.$$ Take two derivatives of $x(t)$ and plug the answer into the left-hand\nside of the differential equation.  Under what conditions will the\ngiven $x(t)$ satisfy the differential equation?  That is, what needs\nto be true about $A$, $\\omega$, and $\\phi$?  How is the story\ndifferent if you have $\\cos$ instead of $\\sin$?\n\n\\paragraph{Problem~\\theproblem:}\\refstepcounter{problem}%\nConsider a string stretched in the $x$ direction, waving transversely\n(look it up), with the $y$ displacement being a function of position\n$x$ and time $t$ according to\n$$ y(x,t) = A\\,\\cos(\\frac{2\\pi\\,x}{\\lambda} - \\frac{2\\pi\\,t}{T}) $$\nwhere $A$ is an amplitude, $\\lambda$ is the wavelength, and $T$ is\nthe period.  For definiteness, set $A=1\\,\\cm$, $\\lambda=0.75\\,\\m$, and\n$T=0.25\\,\\s$.\n\n\\textsl{(a)} Draw a picture of $y(t)$ over the time period $0<t<1\\,\\s$\nfor the position $x=0.0\\,\\m$\n\n\\textsl{(b)} Draw a picture of $y(x)$ over the spatial interval $0<x<3\\,\\m$\nfor the time $t=0.00\\,\\s$\n\n\\textsl{(c)} Draw a picture of $y(x)$ over the spatial interval $0<x<3\\,\\m$\nfor the time $t=0.05\\,\\s$.\n\n\\textsl{(c)} Draw a picture of $y(x)$ over the spatial interval $0<x<3\\,\\m$\nfor the time $t=0.10\\,\\s$.\n\n\\textsl{(d)} Which way is the wave moving, and how fast?\n\n\\paragraph{Problem~\\theproblem:}\\refstepcounter{problem}%\n\\textsl{(a)}~For an ideal gas, find out what the ``intensive''\nproperties are.  What combinations of them have units of speed?  Can\nyou find more than one?  Find the true speed of sound on the internet\nand check your dimensional answer(s) for standard temperature and\npressure.  How far off are you and are you upset by that?\n\n\\textsl{(b)} An organ pipe of length $L$ (filled with air at STP)\nsupports a standing wave (like the standing wave on the string done in\nlecture) but with $L$ being one-quarter wavelength.  What length $L$\ndo you need to make a pipe that plays the note middle C?  Use the\nWikipedia-reported value for the speed of sound $c_s$ in air at STP,\nand use the fact that frequency $f$ and wavelength $\\lambda$ are\nrelated to the speed of sound $c_s$ in the most trivial way possible\ngiven their dimensions!\n\n\\end{document}\n", "meta": {"hexsha": "f9fb8b3225715e2a796a8949b1df5b3786269194", "size": 2650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/gp1_ps10.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/gp1_ps10.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/gp1_ps10.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": 43.4426229508, "max_line_length": 78, "alphanum_fraction": 0.7018867925, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6154238533002593}}
{"text": "\\section{Bedrock Erosion}\\label{erosion.sec.hb}\nSediments are produced at the ice base by eroding the hard bedrock. Here, sediment production depends on basal velocities (and thus basal thermal regime) and ice thickness:\n\\begin{equation}\n  \\dot{E} = -f|\\vec{u}_{\\text{bas}}|H\n\\end{equation}\nAs an alternative, sediment production could also be proportional to the product of basal velocities and basal shear stresses, $\\vec{\\tau}$, i.e.\n\\begin{equation}\n  \\dot{E} = f\\vec{u}_{\\text{bas}}\\cdot\\vec{\\tau}.\n\\end{equation}\nThe total amount of eroded bedrock is then\n\\begin{equation}\n  E=\\int_{0}^t\\dot{E}dt'\n\\end{equation}\n\n\\section{Basic Transport Parameterisation}\\label{erosion.sec.basic_trans}\nThe simple parameterisation assumes that sediment velocities are proportional to the basal ice velocities and that the maximum thickness of the deforming bed is a linear function of basal shear stress:\n\\begin{equation}\n  z_{\\text{max}} = a+b|\\vec{\\tau}_b|.\n\\end{equation}\n\n\\input{\\dir/transport.tex}\n\n\\section{Isostatic Adjustment}\nSediment movement affects isostatic adjustment. This isostatic effect is taken into account by modifying the unloaded (no ice sheet) equilibrium bedrock topography. $h_0$:\n\\begin{equation}\n  h_0=h_0^\\ast+E-w_{\\text{seds}}\n\\end{equation}\nwhere $w_{\\text{seds}}$ is the equilibrium bedrock depression due to erosion. $w_{\\text{seds}}$ can be calculated using either the local or elastic lithosphere approximation (see my thesis).\n", "meta": {"hexsha": "ee278b17e0ec69ef1d07d66c8e09a39dc44d20f4", "size": 1454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "models/glc/cism/glimmer-cism/doc/ext/erosion/theory.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/ext/erosion/theory.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/ext/erosion/theory.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": 50.1379310345, "max_line_length": 201, "alphanum_fraction": 0.7661623109, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.6791786926816161, "lm_q1q2_score": 0.6153289869628101}}
{"text": "\\section{Advection} \\label{sec:adv}\nAdvection is a fluid flow transporting something with it as it flows. This can be temperature, gas, solids or other fluids. In our case we will be looking at temperature.\n\n\\subsection{Thermal Diffusion}\nAs of this time, what you notice if you run the model is that the winds only get stronger and stronger (and the model is hence blowing up, which means that the numbers increase so dramatically \nthat it is no longer realistic). This is because there is no link yet between the velocities of the atmosphere and the temperature. Currently, any air movement does not affect the temperature \nin the atmosphere of our model while it does in reality. So we need to change some calculations to account for that. Thermal diffusion helps with spreading out the temperatures and tempering \nthe winds a bit.\n\nThe diffusion equation, as written in \\autoref{eq:diffusion}, describes how the temperature spreads out over time\\cite{diffusion}. The symbols in the equation represent:\n\n\\begin{itemize}\n    \\item $u$: A vector consisting out of 4 elements: $x, y, z, t$. $x, y, z$ are the local coordinates and $t$ is time.\n    \\item $\\alpha$: The thermal diffusivity constant.\n    \\item $\\nabla^2$: The Laplace operator, more information in \\autoref{sec:laplace}.\n    \\item $\\bar{u}$: The time derivative of $u$, or in symbols $\\frac{\\delta u}{\\delta t}$.\n\\end{itemize}\n\n\\begin{equation}\n    \\label{eq:diffusion}\n    \\bar{u} = \\alpha \\nabla^2 u\n\\end{equation}\n\nNow to get this into code we need the following algorithms \\autoref{alg:laplacian} and \\autoref{alg:diffusion}. \\autoref{alg:laplacian} implements the laplacian operator, whereas \n\\autoref{alg:diffusion} implements the diffusion calculations.  $\\nabla^2$ in \\autoref{alg:diffusion} represents the call to \\autoref{alg:laplacian}.\n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of diffusion}\n    \\label{alg:diffusion}\n    $T_a \\leftarrow T_a + \\delta t \\alpha_a \\nabla^2(T_a)$ \\;\n    $T_p \\leftarrow T_p + \\delta t \\alpha_p \\nabla^2(T_p)$ \\;\n\\end{algorithm}\n\n\\subsection{Adding in Advection}\nWith thermal diffusion in place, the temperature will spread out a bit, however air is not transported yet. This means that the winds we simulate are not actually moving any air. Advection is\ngoing to change that. The advection equation is shown in \\autoref{eq:advection}. The symbols are:\n\n\\begin{itemize}\n    \\item $\\psi$: What is carried along (in our case temperature, \\si{K}).\n    \\item $t$: The time (\\si{s}).\n    \\item $u$: The fluid velocity vector (\\si{ms^{-1}}).\n    \\item $\\nabla$: The divergence operator (as explained in \\autoref{sec:laplace}).\n\\end{itemize}\n\n\\begin{equation}\n    \\label{eq:advection}\n    \\frac{\\delta \\psi}{\\delta t} + \\nabla \\cdot (\\psi u) = 0\n\\end{equation}\n\nWith the divergence functon defined in \\autoref{alg:divergence}, we now need to adjust \\autoref{alg:diffusion} to incorporate this effect. The resulting algorithm can be found in \n\\autoref{alg:advection}. Here $\\nabla$ represents the function call to \\autoref{alg:divergence}.\n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of advection}\n    \\label{alg:advection}\n    $T_{add} \\leftarrow T_a + \\delta t \\alpha_a \\nabla^2(T_a) + \\nabla(T_a)$ \\;\n    $T_a \\leftarrow T_a + T_{add}[5:-5, :] \\text{ //Only add } T_{add} \\text{ to } T_a \\text{ for indices in the interval } [-nlat + 5, nlat - 5]$. \\;\n    $T_p \\leftarrow T_p + \\delta t \\alpha_p \\nabla^2(T_p)$ \\;\n\\end{algorithm}\n\nNow that we have the air moving, we also need to account for the moving of the density. This is because moving air to a certain place will change the air density at that place if the air at that \nplace does not move away at the same rate. Say we are moving air to $x$ at $y \\ ms^{-1}$. If air at $x$ moves at a rate $z \\ ms^{-1}$ and $z \\neq y$ then the air density at $x$ will change.\nThe equation we will need for that is the mass continuity equation as shown in \\autoref{eq:mass continuity} \\cite{masscontinue}.\n\n\\begin{equation}\n    \\label{eq:mass continuity}\n    \\frac{\\delta \\rho}{\\delta t} + \\nabla \\cdot (\\rho v) = 0\n\\end{equation}\n\nUsing this equation means that we will no longer assume that the atmosphere is incompressible. Therefore we need to change a few things in the code. First we need to change the $\\rho$ in \n\\autoref{alg:stream3}. Since $\\rho$ is no longer constant we need to access the right value of $\\rho$ by specifying the indices. So $\\rho$ will change to $\\rho[lat, lon]$. Furthermore we need\nto calculate $\\rho$ after the movement of air has taken place, so we need to change \\autoref{alg:advection} as well to include the calculations for $\\rho$. The new version can be found in \n\\autoref{alg:advectionv2}. Again the $\\nabla$ represents the call to \\autoref{alg:divergence}.\n\n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of advection}\n    \\label{alg:advectionv2}\n    $T_{add} \\leftarrow T_a + \\delta t \\alpha_a \\nabla^2(T_a) + \\nabla(T_a)$ \\;\n    $T_a \\leftarrow T_a + T_{add}[5:-5, :] \\text{ //Only add } T_{add} \\text{ to } T_a \\text{ for indices in the interval } [-nlat + 5, nlat - 5]$. \\;\n    $\\rho \\leftarrow \\rho + \\delta t \\nabla \\rho$ \\;\n    $T_p \\leftarrow T_p + \\delta t \\alpha_p \\nabla^2(T_p)$ \\;\n\\end{algorithm}\n\nCurrently the advection does not work like it should. This is probably due to boundary issues, where we get too close to the poles and it starts freaking out there \\cite{simon}. So to fix this \nwe are going to define boundaries and assume that the advection only works within those boundaries. We only let it change by half of the values. The changes are incorporated in \n\\autoref{alg:advectionfix}. The reason why we mention this seperately, in contrast to the other fixes that we have incorporated throughout the manual already, is the accompanying change with the \nboundary. \n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of advection}\n    \\label{alg:advectionfix}\n    $T_{add} \\leftarrow T_a + \\delta t \\alpha_a \\nabla^2(T_a) + \\nabla(T_a)$ \\;\n    $T_a \\leftarrow T_a - 0.5T_{add}[adv\\_bound:-adv\\_boun, :] \\text{ //Only subtract } T_{add} \\text{ to } T_a \\text{ for indices in the interval } [-nlat + adv\\_boun, nlat - adv\\_boun]$. \\;\n    $\\rho[adv\\_boun: -adv\\_boun, :] \\leftarrow \\rho - 0.5(\\delta t \\nabla \\rho) \\text{ //Only change the density for indices in the interval } [-nlat + adv\\_boun, nlat - adv\\_boun]$ \\;\n    $T_p \\leftarrow T_p + \\delta t \\alpha_p \\nabla^2(T_p)$ \\;\n\\end{algorithm}\n\n\\subsection{Layers, layers and layers}\nWith the atmospheric layers, and all matrices that have an extra dimension to account for it, we need to add the correct indices to the advection algorithm \\autoref{alg:advectionfix}. Let us \nadd it, with \\autoref{alg:advection layer} as a result. Here the ':' means all indices of the 3 dimensional matrix. Also keep in mind that the potential temperature is described and discussed in \n\\autoref{sec:thermal pot}. \n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of advection}\n    \\label{alg:advection layer}\n    $T_{add} \\leftarrow T_a + \\delta t \\alpha_a \\nabla^2(T_{pot}) + \\nabla(T_{pot})$ \\;\n    $T_{add} \\leftarrow 0.5T_{add}[adv\\_boun:-adv\\_boun, :, :] \\text{ //Only halve } T_{add} \\text{ for indices in the interval } [-nlat + adv\\_boun, nlat - adv\\_boun]$. \\;\n    $T_{add}[-adv\\_boun:, :, :] \\leftarrow 0 \\text{//Only replace by 0 in the interval [0, adv\\_boun]}$ \\;\n    $T_{add}[:adv\\_boun, :, :] \\leftarrow 0 \\text{//Only replace by 0 in the interval [nlat - adv\\_boun, nlat]}$ \\;\n    $T_{pot} \\leftarrow T_{pot} - T_{add}[adv\\_boun:-adv\\_boun, :, :] \\text{ //Only subtract } T_{add} \\text{ from } T_{pot} \\text{ for indices in the interval }$\n        $[-nlat + adv\\_boun, nlat - adv\\_boun]$. \\;\n\\end{algorithm}\n\n\\subsection{Adiabatic Motion} \\label{sec:thermal pot}\nUp until now, we have been moving air and the density of the atmosphere. However we have not transported any temperature yet. What this means is that if we have a packet of air (see it as a box\nfilled with air, but the box is invisible) $P$ which is at the planet surface. There $P$ has temperature $T_1$. If we then move $P$ to a layer higher up in the atmosphere, $P$ will still have \nthe same temperature, which is wrong because the density differs. Due to this difference, there is either more or less pressure applied to the box of air which means that $P$ will contract or \nexpand. This obviously changes it's temperature as the air molecules are closer together/further away from each other. Therefore the energy spread is different which affects the temperature. \nFor a visual representation, please consult \\autoref{fig:thermal potential}.\n\n\\begin{figure}\n    \\label{fig:thermal potential}\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{figures/potential_temperature.jpg}\n    \\caption{Visual representation of why we need Thermal Potential \\cite{simon}.}\n\\end{figure}\n\nAs seen in \\autoref{fig:thermal potential}, the packet of air (next to $T_1$) moves up into a higher layer of the atmosphere and ends up at the top (next to $T_2$). The packet has grown bigger, \nas the density in that atmospheric layer is lower and hence the air expands. Because the same energy is in that packet, but it has expanded, the temperature of that packet drops which gives us \n$T_2 < T_1$. The light blue graph in the background shows how the density behaves the higher you go, meaning at the far right (when we are at the highest point) the density is quite low and at \nthe far left (when we are at the planet surface) the density is quite high. The yellow graph shows the temperature of the air at that height, which behaves similarly to the density graph.\n\nThermal potential or potential temperature, is the temperature that the packet of air would be if it is at the planet surface. So take the packet at $T_2$ in \\autoref{fig:thermal potential}. If we move that down to the \nsurface, then it would be temperature $T$ which is then equal to the thermal potential. The equation corresponding to thermal potential is shown in \\autoref{eq:thermal potential} \n\\cite{thermalPotential}. The symbols in \\autoref{eq:thermal potential} mean:\n\n\\begin{itemize}\n    \\item $T$: The temperature of the packet of air (\\si{K}).\n    \\item $p_0$: Reference pressure, usually the pressure at the planet surface (\\si{Pa}).\n    \\item $p$: Pressure of the packet of air (\\si{Pa}).\n    \\item $R$: Gas constant as defined in \\autoref{sec:gas constant} (\\si{JK^{-1}mol^{-1}}).\n    \\item $C_a$: Specific heat capacity of air at a constant pressure (\\si{Jkg^{-1}K^{-1}}).\n\\end{itemize}\n\n\\begin{subequations}\n    \\begin{equation}\n        \\label{eq:thermal potential}\n        \\theta = T(\\frac{p_0}{p})^{\\frac{R}{C_a}}\n    \\end{equation}\n    \\begin{equation}\n        \\label{eq:potential temp}\n        T = \\theta(\\frac{p}{p_0})^{\\frac{R}{C_a}}\n    \\end{equation}\n\\end{subequations}\n\nIf we now re-arrange \\autoref{eq:thermal potential} so that we have $T$ on one side and the rest on the other side, we get \\autoref{eq:potential temp}. With this we can convert temperature into \npotential temperature and vice versa. The whole process of moving temperature around is called adiabatic motion. Now it is time to get this into code. For this to work we need to translate both \n\\autoref{eq:thermal potential} and \\autoref{eq:potential temp} into code and create an overarching function that calls the previously mentioned equations. Let us start with \n\\autoref{eq:thermal potential} which is described in \\autoref{alg:temp to pot}. Note that $\\frac{R}{C_a}$ does not change as they are constants, therefore we can precompute them which saves \na bit of time (namely $O(n)$ divisions, where $n$ is the length of $p$). Also note that we can inverse the process by inserting a minus in the exponent and swapping $T_a$ \nand $\\theta$, which can easily be done in the call to \\autoref{alg:temp to pot}.\n\n\\begin{algorithm}\n    \\caption{Converting temperature into potential temperature}\n    \\label{alg:temp to pot}\n    \\SetKwInOut{Input}{Input}\n    \\SetKwInOut{Output}{Output}\n    \\Input{temperature of the atmosphere (or potential temperature) $T_a$, air pressure $p$, boolean $back$}\n    \\Output{potential temperature $\\theta$}\n    \\uIf{$back$}{\n        $\\kappa \\leftarrow \\frac{R}{C_a}$ \\;\n    }\\uElse{\n        $\\kappa \\leftarrow -\\frac{R}{C_a}$ \\;\n    }\n    \\For{$k \\leftarrow 0$ \\KwTo $p.length$}{\n        $\\theta[:, :, k] \\leftarrow T_a[:, :, k] (\\frac{p_z[k]}{p_z[0]})^{\\kappa}$\n    }\n    \\Return{$\\theta$}\n\\end{algorithm}\n\nNow we only need to do one more thing, replace the algorithm that calculates $T_{pot}$ as a result of advection. Let us do that in \\autoref{alg:advection pot}, where \\texttt{ThermalAdv} is the \ncall to \\autoref{alg:divergence}.\n\n\\begin{algorithm}\n    \\caption{The main calculations for calculating the effects of advection}\n    \\label{alg:advection pot}\n    $T_{add} \\leftarrow T_{pot} + \\nabla(T_{pot}, p_z)$\\;\n    $T_{add} \\leftarrow 0.5T_{add}[adv\\_boun:-adv\\_boun, :, :] \\text{ //Only halve } T_{add} \\text{ for indices in the interval } [-nlat + adv\\_boun, nlat - adv\\_boun]$. \\;\n    $T_{add}[-adv\\_boun:, :, :] \\leftarrow 0 \\text{//Only replace by 0 in the interval [0, adv\\_boun]}$ \\;\n    $T_{add}[:adv\\_boun, :, :] \\leftarrow 0 \\text{//Only replace by 0 in the interval [nlat - adv\\_boun, nlat]}$ \\;\n    $T_{pot} \\leftarrow T_{pot} - T_{add}[adv\\_boun:-adv\\_boun, :, :] \\text{ //Only subtract } T_{add} \\text{ from } T_{pot} \\text{ for indices in the interval }$\n        $[-nlat + adv\\_boun, nlat - adv\\_boun]$. \\;\n\\end{algorithm}", "meta": {"hexsha": "8cfb2d646bf300ccf7203564b2180b70b8b78953", "size": 13624, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex-docs/topics/advection.tex", "max_stars_repo_name": "davleop/claude", "max_stars_repo_head_hexsha": "09ee880d502dcad8cc1a8d2fd681978b812d32dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 175, "max_stars_repo_stars_event_min_datetime": "2020-06-15T16:29:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T21:53:34.000Z", "max_issues_repo_path": "tex-docs/topics/advection.tex", "max_issues_repo_name": "davleop/claude", "max_issues_repo_head_hexsha": "09ee880d502dcad8cc1a8d2fd681978b812d32dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2020-06-26T06:47:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-08T09:17:45.000Z", "max_forks_repo_path": "tex-docs/topics/advection.tex", "max_forks_repo_name": "davleop/claude", "max_forks_repo_head_hexsha": "09ee880d502dcad8cc1a8d2fd681978b812d32dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2020-06-24T10:39:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T08:07:56.000Z", "avg_line_length": 70.2268041237, "max_line_length": 219, "alphanum_fraction": 0.7136670581, "num_tokens": 3958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.615266697795776}}
{"text": "% This section contains the content for the Terms and Definitions\n\\numberedformat\n\\chapter{Terms and Definitions}\nThe following terms and definitions are used in this document.\n%% Modify below this line %%\n\\label{sec:termsanddefs}\n\n\\term{LUT definition}\nLook-up tables are an array of size n where each entry has an index associated with it starting from $0$ and ending at $(n-1)$, (e.g. $lut[0], lut[1], \\ldots , lut[n-1]$). Each entry contains the output value of the LUT for a particular input value. In a fully enumerated LUT, there is an entry for each possible input code. With a particular input bit depth $b$, the size $n$ equals $2^b$.\n\n\\term{Sampled LUT}\nIn a sampled LUT, there is a smaller set of entries representing sampled positions of the input code range.  By default, the minimum input code value is looked up in $lut[0]$ and the maximum input code value is looked up in $lut[n-1]$.  Other output code values are found directly if the input code is one of the sampled positions, otherwise the output values are interpolated between the two nearest sample entries in the LUT.\n\n\\term{Interpolation}\nWhen an input value falls between two sampled positions in a LUT, the output value must be calculated as a proportion of the distance along some function that connects the two nearest values in the LUT. Multiple interpolation types are possible, and higher-order interpolations such as piece-wise cubic interpolation use more than just the adjacent entry to determine the shape of the function. The simplest interpolation type, linear, is a straight line between the points. An example of linear interpolation is provided below.\n\nEx: with a table of the sampled input values in $inValue[i]$ where $i$ ranges from $0$ to $(n-1)$, and a table of the corresponding output values in $outValue[j]$ where $j$ is equal to $i$,\n\n\\begin{center}\n\\begin{tabularx}{3in}{ccXcc}\n\tindex $i$ & inValue && index $j$ & outValue \\\\ \\hline\n\t0 & 0 && 0 & 0 \\\\\n\t$\\vdots$ & $\\vdots$ && $\\vdots$ & $\\vdots$ \\\\\n\t$n-1$ & 1 && $n-1$ & 1000 \\\\\n\\end{tabularx}\n\\end{center}\n\nthe $output$ resulting from $input$ can be calculated after finding the nearest $inValue[i] < input$. \n\nWhen $inValue[i] = input$, the result is evaluated directly.\n\n\\begin{center}\n$output = \\dfrac{input-inValue[i]}{inValue[i+1]-inValue[i]} \\times (outValue[j+1]-outValue[j])+outValue[j]$\t\n\\end{center}\n \n\\term{Tetrahedral Interpolation}\nThis is a type of interpolation for 3D LUTs in which the color space is subdivided by tetrahedra arranged to cover the entire 3D volume.  There are multiple ways to subdivide this space, however for color processing, this specification uses the form where each cube is split along the main (and usually neutral) diagonal into 6 tetrahedra.\n\n\\term{\\texttt{IndexMap} definition}\nThe mapping of input code values to indexes of the table is modifiable allowing for remapping the range of applicable input values, changing the spacing of the input sampling function, and reshaping of the index function for lookups into the LUT. An \\texttt{IndexMap} in its simplest form allows the definition of the range of input and output floating-point values that are normalized to 0 to 1.0 for accessing a 1DLUT or a 3DLUT. This extension to the LUT format is fully described in Appendix C. The \\texttt{IndexMap} is primarily intended for improved implementation of floating-point LUTs and is not necessary for integer LUTs.\n\n\\term{1D LUT definition}\nA color transform using a 1D LUT has as input a 1-component color value from which it finds the nearest index position whose $inValue$ is less than or equal to the implicit input values for the table. The transform algorithm then calculates the output value by interpolation between $outValue$ entries in the table. A 1DLUT shall be applied equally to all channels in a 3-component color calculation.\n\n\\term{3by1D LUT definition}\nA 3by1DLUT is a particular case of a 1DLUT in which a 3-component pixel is the input value, and each component is looked up separately in its own 1DLUT which may differ from each other.\n\n\\term{3DLUT definition}\nIn a 3D LUT, the value range of the 3 color components defines the coordinate system of a 3D cube. A single position is found within the volume of the cube from the 3 input values, and a set of the nearest corresponding table entries are identified (between 4 to 8 table entries, depending on the interpolation algorithm). The 3-component output value is calculated by interpolating those nearest table entries from the 3DLUT.\n\n\\note{For examples of 3D cube interpolation, look at ``Efficient color transformation implementation'' by Bala and Klassen in Digital Color Imaging Handbook, ed: Sharma, CRC Press, 2003, pg 694-702}\n\n\\term{MATRIX definition}\nA matrix can be used for linear conversion of 3 color component pixels from one color space to another.\n\nThe 3-component input value vector is multiplied by the matrix to create the new 3-component output value vector. Matrix color transforms in this format use the column vector convention:\n\n\\begin{equation}\n    \\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    \\begin{bmatrix}\n        r\\\\\n        g\\\\\n        b\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        R\\\\\n        G\\\\\n        B\n    \\end{bmatrix}\n\\end{equation}\n\nwhere $[R, G, B]$ is the result of multiplying input $[r, g, b]$ by the matrix $[a]$.\n\n\\term{ASC CDL}\nThe American Society of Cinematographers' Color Decision List (ASC CDL). This provides a universal method of exchanging basic color correction parameters and specifies a particular color processing equation.", "meta": {"hexsha": "6df0f754c2437a628a79eb8ba73d835fcc0aefd4", "size": 5664, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/LaTeX/S-2014-006/termsanddefs.tex", "max_stars_repo_name": "KelSolaar/aces-dev", "max_stars_repo_head_hexsha": "76ea982a988d278dd12b563602771f46a5da3b83", "max_stars_repo_licenses": ["AMPAS"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-01-04T18:12:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-27T06:46:50.000Z", "max_issues_repo_path": "documents/LaTeX/S-2014-006/termsanddefs.tex", "max_issues_repo_name": "colour-science/aces-dev", "max_issues_repo_head_hexsha": "86284e2f145a89e3612f05ec7ea5a3e9d92cc779", "max_issues_repo_licenses": ["AMPAS"], "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/LaTeX/S-2014-006/termsanddefs.tex", "max_forks_repo_name": "colour-science/aces-dev", "max_forks_repo_head_hexsha": "86284e2f145a89e3612f05ec7ea5a3e9d92cc779", "max_forks_repo_licenses": ["AMPAS"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.8, "max_line_length": 632, "alphanum_fraction": 0.7524717514, "num_tokens": 1435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6151907875950632}}
{"text": "\\section{Conclusion}\n\nIn this study, we provide a theoretical review of measurement-based quantum computing. We provide the definition and essential properties of graph states essential to measurement-based quantum computing. Using these mathematical objects, we define a cluster and build an abstract machine called a one-way quantum computer on top of it. We show how this machine can be used to perform universal quantum computation. In order to prove this, we define a procedure for simulating any circuit-based quantum algorithm using the one-way computer up to a unitary transformation, composed of Pauli x and z operations, called the by-product operator. Lastly, we provide  Deutsch's algorithm as an example to demonstrate this procedure. Our simulation outcomes using Paddle Quantum show that the procedure indeed works. ", "meta": {"hexsha": "5cd69c685b472ff75fa49bd0f41070b50f951c39", "size": 831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/final/sections/conclusion.tex", "max_stars_repo_name": "kurabirko/phys400", "max_stars_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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": "documents/final/sections/conclusion.tex", "max_issues_repo_name": "kurabirko/phys400", "max_issues_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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": "documents/final/sections/conclusion.tex", "max_forks_repo_name": "kurabirko/phys400", "max_forks_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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": 277.0, "max_line_length": 809, "alphanum_fraction": 0.8231046931, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6151907828313902}}
{"text": "\\documentclass[13pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{tikz}\n\\usepackage[braket, qm]{qcircuit}\n\\usepackage{physics}\n\\usepackage{pgfplots}\n\\usepgfplotslibrary{units}\n\\usetikzlibrary{patterns}\n\\usepackage{siunitx}\n\\usetikzlibrary{angles, quotes}\n\\usepackage{amssymb}\n\\usetikzlibrary{angles, arrows.meta, quotes}\n\\pgfplotsset{compat=1.17}\n\n\\usepackage{minted}\n\\usepackage[most]{tcolorbox}\n\\definecolor{lightgreen}{rgb}{0.56, 0.93, 0.56}\n\\definecolor{moonstoneblue}{rgb}{0.45, 0.66, 0.76}\n\n\\newtcblisting{myminted}{%\n    listing engine=minted,\n    minted language=c,\n    listing only,\n    breakable,\n    enhanced,\n    minted options = {\n        linenos,\n        breaklines=true,\n        breakbefore=.,\n        fontsize=\\footnotesize,\n        numbersep=2mm\n    },\n    overlay={%\n        \\begin{tcbclipinterior}\n            \\fill[gray!25] (frame.south west) rectangle ([xshift=4mm]frame.north west);\n        \\end{tcbclipinterior}\n    }\n}\n\n\\title{Simons's Algorithm Tutorial}\n\\author{Ishaan Shah}\n\\date{November 2020}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{The Problem}\n\\indent Given a function (implemented as a black box) $f: \\{0, 1\\}^n \\rightarrow \\{0, 1\\}^n$, promised to satisfy the property that, for some non zero binary string $s \\in \\{0, 1\\}^n$\n$$f(x) = f(y) \\Leftrightarrow x = y\\ \\text{or}\\ x = y \\oplus s$$\nFind the secret string $s$ in least possible queries. It is important to note that the function $f(x)$ given to us is in the form of a black box which means we cannot extract the bit string by looking at the circuit inside.\n\nFor example consider the following truth table for $n = 2$ and $s=10$\n\\begin{center}\n    \\begin{tabular}{|c|c|}\n        \\hline\n        x & $f(x)$ \\\\\n        \\hline\n        00 & 10 \\\\\n        01 & 01 \\\\\n        10 & 10 \\\\\n        11 & 01 \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\n\n\n\\section{Algorithm}\n\\subsection{The classical way}\n\\indent The classical algorithm is pretty straightforward. We find the output for $0^n$ and store it. Then we find outputs of successive binary strings until we find the output we got for $0^n$. The input for which this is true will be the secret bit string. We can easily see that the time complexity for this is $\\mathcal{O}(2^n)$ and space complexity is $\\mathcal{O}(1)$.\n\n\\subsection{The quantum way}\nBefore we begin to understand how Simon's algorithm works, we have to look at a smaller sub-algorithm namely the \\textbf{Fourier Sampling}.\n\n\\subsubsection*{Fourier Sampling}\nFourier sampling is the process of applying $n$ Hadamard Gates to a system of $n$ qubits and measuring the result.\n\nIf the input to the circuit is denoted by $\\ket{\\psi}$ and then the output $\\ket{\\psi'}$ is given by\n$$\\ket{\\psi'} = \\sum_{y \\in \\{0, 1\\}^n}\\frac{(-1)^{y\\cdot\\psi}}{2^{n/2}}\\ket{y}$$\n\nNow that we know how Fourier sampling works lets move on to the actual algorithm. The actual algorithm consists of three steps\n\n\\subsubsection{Step 1 - Superposition}\nIn the first step, we create an equal superposition of all the possible bit strings of length $n$. This can easily be done by initialising $n$ qubits to $0$ and  passing them through $n$ Hadamard gates. So now the state of our $n$ qubits will be given by\n$$ \\ket{\\psi} = \\sum_{y \\in \\{0, 1\\}^n}\\frac{1}{2^{n/2}}\\ket{y}$$\n\n\\subsubsection{Step 2 - Apply $f(x)$ and measure}\nAfter creating the superposition described below, we pass the vector $\\ket{\\psi}$ into the black box provided to us. Now we measure the output qubits that we get from the black box which causes the input vector $\\ket{\\psi}$ to collapse to the following state\n$$ \\ket{\\psi} = \\frac{1}{\\sqrt{2}}\\ket{z} + \\frac{1}{\\sqrt{2}}\\ket{z \\oplus s} \\qquad \\text{...where} \\ z \\in \\{0, 1\\}^n$$\n\n\\subsubsection{Step 3 - Fourier sampling}\nNow we apply the Fourier sampling algorithm to the input which is in the above mentioned state. After applying $n$ Hadamard gates to the $n$ input bits the state of the vector $\\ket{\\psi}$ becomes\n\\begin{align*}\n    \\ket{\\psi} &= \\sum_{y \\in \\{0, 1\\}^n}\\left(\\frac{(-1)^{y\\cdot z} + (-1)^{y\\cdot(z \\oplus s)}}{2^{(n+1)/2}}\\right)\\ket{y} \\\\\n    &= \\sum_{y \\in \\{0, 1\\}^n}\\left(\\frac{(-1)^{y\\cdot z}[1 + (-1)^{y\\cdot s}]}{2^{(n+1)/2}}\\right)\\ket{y}s\n\\end{align*}\n\nWhen we measure the input register $\\ket{\\psi}$ after Fourier sampling we will get a vector $\\ket{y}$ such that $y\\cdot s = 0\\ \\text{mod}\\ 2$. This will happen because the probability all $y\\text{s}$ which have an odd dot product will become 0.\n\nNow we have a way to find some vector $\\ket{y}$ such that,\n$$y_n s_n \\oplus y_{n-1} s_{n-1} \\oplus \\cdots \\oplus y_1 s_1 = 0$$\nTo find the secret bit string $s$ we have to get $n-1$ independent linear equations as above. It can be shown that the probability of finding these $n-1$ equations in $n$ tries is $\\frac{1}{4}$. So if we perform the measurements $10n$ times the probability that we don't get independent equations is $0.05$ which is very less. After getting the equations they can be solved to find the secret string $s$ using Gaussian elimination, which takes $\\mathcal{O}(n^3)$ time.\n\n\\section{Implementation}\n\\subsection{Implementing the Oracle}\n\\indent There are many ways in which we can implement the oracle for Simon's Algorithm, here we look at one such implementation. Our basic goal is to create a 2-1 mapping from domain to range of $f(x)$. This can be realised by the following procedure -\n\\begin{itemize}\n    \\item Encode the secret string using the $X$ gate wherever there is a 1.\n    \\item Copy the input register to output register using $CNOT$ gates.\n    \\item We know that $s \\neq 0^n$, so there exists at least one bit in $s$ which has the value 1. Let us call this bit as the \\textbf{MSB} bit. We now apply $CCNOT$ gate on output bit which is controlled by the corresponding secret bit and the input \\textbf{MSB} bit. This creates a 2-1 mapping.\n    \\item Now we randomly flip some of the output qubits to further obfuscate the oracle. This step is optional and can be made even more complex so to make it harder to guess the secret string $s$.\n\\end{itemize}\n\\vspace{1pt}\n\\begin{equation*}\n    \\Qcircuit @C=1.0em @R=0.0em @!R {\n\t \t\\lstick{ {input}_{0} :  } & \\qw \\barrier[0em]{8} & \\qw & \\ctrl{3} & \\qw & \\qw \\barrier[0em]{8} & \\qw & \\ctrl{6} & \\ctrl{7} & \\ctrl{8} \\barrier[0em]{8} & \\qw & \\qw \\barrier[0em]{8} & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {input}_{1} :  } & \\qw & \\qw & \\qw & \\ctrl{3} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {input}_{2} :  } & \\qw & \\qw & \\qw & \\qw & \\ctrl{3} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{0} :  } & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\gate{X} & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{1} :  } & \\qw & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{2} :  } & \\qw & \\qw & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\targ & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{0} :  } & \\gate{X} & \\qw & \\qw & \\qw & \\qw & \\qw & \\ctrl{-3} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{1} :  } & \\gate{X} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\ctrl{-3} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{2} :  } & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\ctrl{-3} & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t }\n\\end{equation*}\n\\vspace{1pt}\n\\begin{center}\n\\footnotesize{Circuit for Simon's oracle for $s=110$}\n\\end{center}\n\n\\subsubsection*{Qiskit implementation}\nFollowing is the code for the Oracle using IBM's Qiskit library. The complete source along with the test function can be found in the Github repository.\n\\begin{tcolorbox}[\n    enhanced,\n    attach boxed title to top left={xshift=6mm,yshift=-3mm},\n    title=Oracle Code,\n    boxed title style={size=small,sharp corners},\n    sharp corners,\n]\n\\begin{minted}{python}\nimport itertools\nimport random\nimport time\nfrom typing import List, Tuple\n\nfrom qiskit import (Aer, ClassicalRegister,\n                    QuantumCircuit, QuantumRegister,\n                    execute)\nfrom qiskit.circuit import Gate\n\nrandom.seed(time.monotonic())\n\n\ndef simons_oracle(size: int, secret_input: List[int] = None):\n    \"\"\" Returns a quantum gate which acts as\n        an Oracle for Simon's Algorithm\n    \"\"\"\n    # Register holding the secret string\n    secret = QuantumRegister(size, \"secret\")\n\n    # Input and Output registers\n    input = QuantumRegister(size, \"input\")\n    output = QuantumRegister(size, \"output\")\n\n    # Initialize circuit\n    oracle = QuantumCircuit(input, output, secret)\n\n    # Generate random secret string\n    if not secret_input:\n        secret_input = [0 for i in range(size)]\n        while secret_input.count(0) == size:\n            secret_input = [\n                random.choice([0, 1]) for i in range(size)\n            ]\n\n    # Encode it in the quantum register\n    for i in range(size):\n        if secret_input[i]:\n            oracle.x(secret[i])\n\n\\end{minted}\n\\end{tcolorbox}\n\\begin{tcolorbox}[\n    enhanced,\n    attach boxed title to top left={xshift=6mm,yshift=-3mm},\n    title=Oracle Code,\n    boxed title style={size=small,sharp corners},\n    sharp corners,\n]\n\\begin{minted}{python}\n    # Copy input register to output register\n    for i in range(size):\n        oracle.cx(input[i], output[i])\n\n    # Find msb of secret string\n    msb = secret_input.index(1)\n\n    # Create 2-1 mapping\n    for i in range(size):\n        oracle.ccx(input[msb], secret[i], output[i])\n\n    # Randomly flip qubits for further obfuscation\n    for i in range(size):\n        if i % 3 == 0:\n            oracle.x(output[i])\n\n    return oracle.to_gate(label=\"oracle\"), secret_input\n\\end{minted}\n\\end{tcolorbox}\n\\subsection{Implementing the algorithm}\nThe implementation of actual Simon's algorithm is pretty straightforward. After we get the set of equations we need, we use Gaussian elimination to solve them and find the secret string.\n\\vspace{1pt}\n\\begin{equation*}\n    \\Qcircuit @C=1.0em @R=0.0em @!R {\n\t \t\\lstick{ {input}_{0} :  } & \\gate{H} & \\multigate{8}{Oracle} & \\gate{H} & \\meter & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {input}_{1} :  } & \\gate{H} & \\ghost{Oracle} & \\gate{H} & \\qw & \\meter & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {input}_{2} :  } & \\gate{H} & \\ghost{Oracle} & \\gate{H} & \\qw & \\qw & \\meter & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{0} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{1} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {output}_{2} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{0} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{1} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{ {secret}_{2} :  } & \\qw & \\ghost{Oracle} & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\t \t\\lstick{c0:} & {/_{_{3}}} \\cw & \\cw & \\cw & \\dstick{0} \\cw \\cwx[-9] & \\dstick{1} \\cw \\cwx[-8] & \\dstick{2} \\cw \\cwx[-7] & \\cw & \\cw\\\\\n\t }\n\\end{equation*}\n\\vspace{1pt}\n\\begin{center}\n\\footnotesize{Simon's Algorithm circuit for $n=3$}\n\\end{center}\n\\subsubsection*{Qiskit implementation}\nFollowing is the code for the the actual algorithm using IBM's Qiskit library. The complete source can be found in the Github repository.\n\\begin{tcolorbox}[\n    enhanced,\n    attach boxed title to top left={xshift=6mm,yshift=-3mm},\n    title=Simon's Algorithm Code,\n    boxed title style={size=small,sharp corners},\n    sharp corners,\n]\n\\begin{minted}{python}\nimport sys\n\nfrom qiskit import (Aer, ClassicalRegister,\n                    QuantumCircuit, QuantumRegister,\n                    execute)\nfrom qiskit.visualization import plot_histogram\n\nfrom simons_oracle import simons_oracle\n\n\n# Get backend\nbackend = Aer.get_backend('qasm_simulator')\n\n# Length of input\nn = None\ntry:\n    n = int(sys.argv[1])\nexcept IndexError:\n    n = 4\nexcept ValueError:\n    print(\"Invalid size\")\n    sys.exit(1)\n\n# Secret input (optional)\nsecret_input = None\ntry:\n    secret_input = sys.argv[2]\n    secret_input = [int(bit) for bit in secret_input]\n    if len(secret_input) != n:\n        print(\"Length of secret string and size \"\n              \"of input should be the same\")\n        exit(1)\nexcept IndexError:\n    pass\n\n\n# Initialise input, output and secret registers\ninput = QuantumRegister(n, \"input\")\noutput = QuantumRegister(n, \"output\")\nsecret = QuantumRegister(n, \"secret\")\nresult = ClassicalRegister(n)\n\\end{minted}\n\\end{tcolorbox}\n\n\\begin{tcolorbox}[\n    enhanced,\n    attach boxed title to top left={xshift=6mm,yshift=-3mm},\n    title=Simon's Algorithm Code,\n    boxed title style={size=small,sharp corners},\n    sharp corners,\n]\n\\begin{minted}{python}\n(oracle, secret_input) = simons_oracle(n, secret_input)\nprint(f\"Secret string - \"\n      f\"{''.join([str(bit) for bit in secret_input])}\")\n\n# Initialize circuit\ncircuit = QuantumCircuit(input, output, secret, result)\n\n# Actual circuit\ncircuit.h(input)\ncircuit.append(oracle, [*input, *output, *secret])\ncircuit.h(input)\n\n# Perform measurement\ncircuit.measure(input, result)\n\nprint(circuit.draw())\n\n# Take the top results and create a matrix out\n# of it to solve the equations\nres = execute(circuit, backend).result().get_counts()\nres = sorted(res, key=lambda k: res[k])[:2**(n-1)]\n\n# Convert to proper integer matrix\nmat = [[int(bit) for bit in bit_string] for bit_string in res]\nfor row in mat:\n    row.reverse()\n\n# Perform Gaussian Elimination\nx, y = len(mat), n\ncur_row, cur_col = 0, 0\nwhile cur_row < x and cur_col < y:\n    if mat[cur_row][cur_col] == 0:\n        non_zero_row = -1\n        for j in range(cur_row+1, x):\n            if mat[j][cur_col] == 1:\n                non_zero_row = j\n                break\n        if non_zero_row == -1:\n            cur_col += 1\n            continue\n        else:\n            (mat[cur_col], mat[non_zero_row]) =\n                (mat[non_zero_row], mat[cur_row])\n\\end{minted}\n\\end{tcolorbox}\n\\begin{tcolorbox}[\n    enhanced,\n    attach boxed title to top left={xshift=6mm,yshift=-3mm},\n    title=Simon's Algorithm Code,\n    boxed title style={size=small,sharp corners},\n    sharp corners,\n]\n\\begin{minted}{python}\n    for j in range(cur_row+1, x):\n        if mat[j][cur_col] == 1:\n            for k in range(y):\n                mat[j][k] = mat[j][k] ^ mat[cur_row][k]\n\n    cur_row += 1\n\nmat = list(filter(lambda row: row.count(0) < y, mat))\n\n# Solve the reduced matrix\nsol = [-1 for i in range(n)]\nfor i in range(n-1):\n    if not mat[i][i]:\n        sol[i] = 1\n        for j in range(i+1, n):\n            sol[j] = 0\n        break\n\nif sol.count(-1) == n:\n    sol[-1] = 1\n\nstart = sol.index(1)-1\nfor i in range(start, -1, -1):\n    cnt = 0\n    for j in range(n):\n        if sol[j] == 1 and mat[i][j] == 1:\n            cnt += 1\n    sol[i] = cnt % 2\n\nprint(f'Calculated Secret String: '\n      f'{\"\".join([str(bit) for bit in sol])}')\n\\end{minted}\n\\end{tcolorbox}\n\\section{Conclusion}\nHence we have devised an algorithm which can solve a problem in polynomial time ($\\mathcal{O}(n^3)$) with the help of quantum computers for which the best known solution is exponential time ($\\mathcal{O}(2^n)$) using classical computer. This disproves the \\textbf{Church-Turing Hypothesis} and shows the potential power of quantum computers.\n\\end{document}.\n", "meta": {"hexsha": "231223c0654ebc67abd096f0b486bf07784baab3", "size": 15203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Sheets/SimonsAlgorithm/SimonsAlgorithm.tex", "max_stars_repo_name": "ishaanshah/Cuantum-Qomputing", "max_stars_repo_head_hexsha": "79035133f148f37d049f3e009408b17262115efd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-04T12:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-04T12:45:43.000Z", "max_issues_repo_path": "Sheets/SimonsAlgorithm/SimonsAlgorithm.tex", "max_issues_repo_name": "ishaanshah/Cuantum-Qomputing", "max_issues_repo_head_hexsha": "79035133f148f37d049f3e009408b17262115efd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sheets/SimonsAlgorithm/SimonsAlgorithm.tex", "max_forks_repo_name": "ishaanshah/Cuantum-Qomputing", "max_forks_repo_head_hexsha": "79035133f148f37d049f3e009408b17262115efd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-24T04:34:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-24T04:34:35.000Z", "avg_line_length": 39.6945169713, "max_line_length": 468, "alphanum_fraction": 0.6395448267, "num_tokens": 4827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6151907814033784}}
{"text": "\\section{Task 1}\nUsing List-Homomorphism promotions listed below (from \\cite[Slide 40]{l1intro})\nprove the following invariant:\n\\begin{verbatim}\n(reduce myop e) . (map f)\n          ==\n(reduce myop e) . (map ( (reduce myop e) . (map f) ) ) . distr_p\n\\end{verbatim}\n\n\\noindent The promotions are as follows:\n\\begin{enumerate*}\n  \\item (map $f$) . (map $g$) $\\equiv$ map($f$ . $g$)\n  \\item (map $f$) . (reduce (++) []) $\\equiv$ (reduce (++) []) . (map (map $f$))\n  \\item (reduce $\\odot$ $e_\\odot$) . (reduce (++) []) $\\equiv$ (reduce $\\odot$ $e_\\odot$) . (map (reduce $\\odot$ $e_\\odot$))\n\\end{enumerate*}\n\n\\begin{verbatim}\n(reduce myop e) . (map f)\n\n(reduce myop e) . (map f)               . (reduce (++) []) . distr_p # From assignment tip\n\n(reduce myop e) . (reduce (++) [])      . (map (map f))    . distr_p # By 2\n\n(reduce myop e) . (map (reduce myop e)) . (map (map f))    . distr_p # By 3\n\n(reduce myop e) . (map ((reduce myop e) . (map f)) )       . distr_p # By 1\n\\end{verbatim}\n\n\\noindent The last line is the form that we wished to create and we have proven\nthat the invariant holds.\n", "meta": {"hexsha": "c61c58ce9126c20e7d4aaac7b5f0f167c60e570b", "size": 1091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment1/report/task1.tex", "max_stars_repo_name": "martinnj/PMPH2015", "max_stars_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignment1/report/task1.tex", "max_issues_repo_name": "martinnj/PMPH2015", "max_issues_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment1/report/task1.tex", "max_forks_repo_name": "martinnj/PMPH2015", "max_forks_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_forks_repo_licenses": ["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.1935483871, "max_line_length": 124, "alphanum_fraction": 0.5857011916, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.615163188666973}}
{"text": "\\section{Logistic Regression I}\n\n\\begin{frame}\n  \\frametitle{Logistic Regression}\n\n  Logistic Regression is a \\structure{discriminative model}, because it models \\\\\n  the posterior probabilities $p(y|\\vec{x})$ directly.\n\\end{frame}\n\n\n\\subsection{Posteriors and the Logistic Function}\n\n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function}\n \n  For two classes $y\\in\\{0, 1\\}$ we get:\n  \n  \\begin{eqnarray*}\n    p(y=0| \\vec x) \n      &=& \\pause \\frac{p(y=0) \\cdot p(\\vec x | y=0)}{p(\\vec x)} \\\\[.5cm] \\pause \n      &=& \\frac{p(y=0) \\cdot p(\\vec x | y=0)}{p(y=0)p(\\vec x |y=0)+p(y=1)p(\\vec x| y=1)} \\\\[.5cm] \\pause\n      &=& \\frac{1}{1+\\frac{p(y=1)p(\\vec x| y=1)}{p(y=0)p(\\vec x| y=0)}}\n  \\end{eqnarray*}\n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function \\cont}\n\n  \\begin{eqnarray*}\n    p(y=0| \\vec x) \n      &=& \\frac{1}{1+\\frac{p(y=1)p(\\vec x| y=1)}{p(y=0)p(\\vec x| y=0)}} \\\\[.3cm] \\pause\n      &\\phantom{=}& \\mbox{\\small (\\structure{Trick:} extend with exponential and logarithm)} \\\\[.3cm] \\pause\n      &=& \\frac{1}{1+e^{\\log \\frac{p(y=1)p(\\vec x| y=1)}{p(y=0)p(\\vec x| y=0)} } } \\\\[.3cm] \\pause\n      &=& \\frac{1}{1+e^{-\\log\\frac{p(y=0)}{p(y=1)} - \\log\\frac{p(\\vec x| y=0)}{p(\\vec x|y=1)}}}\\\\[0.3cm] \\pause\n      &=& \\frac{1}{1+e^{-\\log\\frac{p(y=0|\\vec x)}{p(y=1|\\vec x)}}}\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function \\cont}\n\n  We see that the posterior for class $y = 0$ can be written in terms of \\\\\n  a \\structure{logistic function}:\n%\n  \\begin{eqnarray*}\n    p(y=0| \\vec x) &=& \\frac{1}{1+e^{-F(\\vec{x})}}\n  \\end{eqnarray*}\n  \\pause\n\n  And thus the posterior for the other class $y = 1$:\n%\n  \\begin{eqnarray*}\n    p(y=1| \\vec x) &=& \\pause 1- p(y=0| \\vec x) \\\\[.3cm] \\pause\n                   &=& \\frac{e^{-F(\\vec x)}}{1+e^{-F(\\vec{x})}} \\\\[.3cm] \\pause\n                   &=&  \\frac{1}{1+e^{F(\\vec{x})}}\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function \\cont}\n\n  \\begin{citeblock}{Definition}\n\n    The {\\em logistic function} (also called {\\em sigmoid function}) is defined by\n    \\begin{eqnarray*}\n      g(x) &=& \\frac{1}{1+e^{-x}}\n    \\end{eqnarray*}\n    where $x\\in \\real$.\n  \\end{citeblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function \\cont}\n\n  The derivative of the sigmoid function fulfills the nice property:\n\n  \\begin{eqnarray*}\n    g'(x) &=& \\left( \\frac{1}{1+e^{-x}} \\right)' = \\pause \\left( (1+e^{-x})^{-1}\\right)'= \\pause \\frac{1}{(1+e^{-x})^2}\\cdot e^{-x} \\\\[.3cm] \\pause\n          &=& \\frac{1}{(1+e^{-x})} \\cdot \\frac{e^{-x}}{(1+e^{-x})} \\\\[.3cm] \\pause\n          &=& \\frac{1}{(1+e^{-x})} \\cdot \\frac{1}{(1+e^{x})} \\\\[.3cm] \\pause\n          &=& g(x)g(-x) \\\\[.3cm] \\pause\n          &=& g(x)(1-g(x)) \\quad.\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Posteriors and the Logistic Function \\cont}\n \n  \\begin{figure}\n    \\resizebox{.85\\linewidth}{!}{\n      \\alt<4->{\n        \\input{\\texfigdir/sigmoid4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/sigmoid3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/sigmoid2.pstex_t}\n      }{\n        \\input{\\texfigdir/sigmoid1.pstex_t}\n      }}}\n    }\n    \\caption{Sigmoid function: $g(ax)=1/(1+e^{-ax})$ for $a=1,2,3,4$}\n    \\label{f:sigmoid}\n  \\end{figure}\n\\end{frame}\n\n\n\\input{nextTime.tex}\n\n\\subsection{Decision Boundary}\n\n\\begin{frame}\n  \\frametitle{Decision Boundary}\n\n  The \\structure{decision boundary} $\\delta(\\vec x)=0$ (zero level set) in feature space separates the two classes. \\\\[.3cm]\n  Points $\\vec x$ on the decision boundary satisfy:\n \n  \\begin{eqnarray*}\n    {p(y=0|\\vec{x})}&=& {p(y=1|\\vec x)}\n  \\end{eqnarray*}\n \n  and thus\n \n  \\begin{eqnarray*}\n    \\log \\frac{p(y=0|\\vec{x})}{p(y=1|\\vec x)} &=& \\pause \\log 1 = 0 \\quad.\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n \n  \\begin{lemma}\n    The decision boundary is given by $F(\\vec x) = 0$.\n  \\end{lemma}\n  \\pspread\n \n  \\structure{Proof:}\n%\n  \\begin{eqnarray*}\n    \\log \\frac{p(y=0|\\vec{x})}{p(y=1|\\vec x)} &=& F(\\vec x) = 0\\\\[.3cm] \\pause\n    \\frac{p(y=0|\\vec{x})}{p(y=1|\\vec x)} &=& e^{F(\\vec x)} \\\\[.3cm] \\pause\n    {p(y=0|\\vec{x})}&=& e^{F(\\vec x)} {p(y=1|\\vec x)} \\\\[.3cm]\n    % {p(y=0|\\vec{x})}&=& e^{F(\\vec x)}\\left( {1-p(y=0|\\vec x)}\\right)\n  \\end{eqnarray*} \n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n \n  Now we use that the posteriors sum up to one:\n  \n  \\begin{eqnarray*}\n    {p(y=0|\\vec{x})}&=& e^{F(\\vec x)}\\left( {1-p(y=0|\\vec x)}\\right) \\\\ \\\\\n    \\pause {p(y=0|\\vec{x})}&=& \\frac{e^{F(\\vec x)}}{1+e^{F(\\vec x)}} \\\\ \\\\\n    \\pause {p(y=0|\\vec{x})}&=& \\frac{1}{1+e^{-F(\\vec x)}} \n  \\end{eqnarray*} \n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n \n  \\begin{figure}\n    \\resizebox{1\\linewidth}{!}{\n      \\alt<4->{\n        \\input{\\texfigdir/logit3.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/logit2.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/logit1.pstex_t}      \n      }{\n        \\input{\\texfigdir/logit0.pstex_t}\n      }}}\n    }\n    \\caption{Two Gaussians and their posteriors: {\\color{bl3} $\\sigma_0$}={\\color{gr3}$ \\sigma_1$}= 0.25,  {\\color{bl3} $\\mu_0=-2$},\n              {\\color{gr3} $\\mu_1=1$}}\n    \\label{f:logit}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n  \n  \\begin{ovalblock}{Example}\n    \\footnotesize\n    Let us assume both classes have normally distributed $d$-dimensional feature vectors:\n \n    \\begin{eqnarray*}\n      p(\\vec x | y) &=& \\frac{1}{ \\sqrt{ \\det{(2 \\pi \\mat{\\Sigma}_y})} } \n                        e^{-\\frac{1}{2} (\\vec{x} - \\vec{\\mu}_y)^T \\mat{\\Sigma}_y^{-1} (\\vec{x} - \\vec{\\mu}_y)  }\n    \\end{eqnarray*}\n    \\pause\n \n    Then we can write the posterior of $y=0$ in terms of a logistic function:\n \n    \\begin{eqnarray*}\n      p(y=0|\\vec x) &=& \\frac{1}{1+e^{-F(\\vec x)}} = \\frac{1}{1+e^{ - \\left( \\vec x^T \\mat A \\vec x + \\vec \\alpha^T\\vec x + \\alpha_0 \\right) } } \\\\ \\\\\n      \\pause F(\\vec x) &=& \\log \\frac{p(y=0|\\vec x)}{p(y=1|\\vec x)} = \\log \\frac{p(y=0)p(\\vec x | y=0) }{p(y=1)p(\\vec x|y =1)}\n    \\end{eqnarray*}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n\n  \\begin{ovalblock}{Example cont.}\n    \\footnotesize\n    \\begin{eqnarray*}\n      F(\\vec x) &=&\n        \\log\\frac{p(y=0)}{p(y=1)} +\n        \\log\n        \\frac{\n          \\frac{1}{ \\sqrt{ \\det{( 2 \\pi \\mat{\\Sigma}_0)}} }\n          e^{ -\\frac{1}{2} (\\vec{x} - \\mat{\\mu}_0)^T \\mat{\\Sigma}_0^{-1} (\\vec{x} - \\vec{\\mu}_0) }         \n        }{\n          \\frac{1}{ \\sqrt{ \\det{(2 \\pi \\mat{\\Sigma}_1)}} }\n          e^{ -\\frac{1}{2} (\\vec{x} - \\vec{\\mu}_1)^T \\mat{\\Sigma}_1^{-1} (\\vec{x} - \\vec{\\mu}_1)}\n        }\n    \\end{eqnarray*}\n    \\pause\n \n    This function has the constant component:\n% \n    \\begin{eqnarray*}\n      c &=& \\log \\frac{p(y=0)}{p(y=1)}+\\frac{1}{2}\n            \\log \\frac{ { \\det{(2\\pi\\mat{\\Sigma}_1)}}}\n                      { { \\det{(2\\pi\\mat{\\Sigma}_0)}}}\n    \\end{eqnarray*}\n    \\pause \n    \n    We observe:\n    \\begin{itemize}\n      \\small\n      \\item Priors imply a constant offset of the decision boundary. \n      \\item If priors and covariance matrices of both classes are identical, this offset is $c=0$.\n    \\end{itemize}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n\n  \\begin{ovalblock}{Example cont.}\n    \\small\n    Furthermore we have:\n    \\begin{eqnarray*}\n      \\log{ \n        \\frac{e^{ - \\frac{1}{2} (\\vec{x} - \\vec{\\mu}_0)^T \\mat{\\Sigma}_0^{-1} (\\vec{x} - \\vec{\\mu}_0)} }\n             {e^{ - \\frac{1}{2} (\\vec{x} - \\vec{\\mu}_1)^T \\mat{\\Sigma}_1^{-1} (\\vec{x} - \\vec{\\mu}_1)} }\n      } & = & \\\\[.3cm]\n      & & \\pause \\hspace{-5cm} =\n      \\frac{1}{2} \n      \\left(\n        (\\vec{x} - \\vec{\\mu}_1)^T \\mat{\\Sigma}_1^{-1} (\\vec{x} - \\vec{\\mu}_1) - (\\vec{x} - \\vec{\\mu}_0)^T \\mat{\\Sigma}_0^{-1} (\\vec{x} - \\vec{\\mu}_0)\n      \\right) \\\\[.3cm]\n      & & \\hspace{-5cm} \\pause =\n      \\frac{1}{2} \n      \\left(\n        \\vec{x}^T (\\mat{\\Sigma}_1^{-1} - \\mat{\\Sigma}_0^{-1}) \\vec{x} \n        -2 (\\vec{\\mu}_1^T \\mat{\\Sigma}_1^{-1} - \\vec{\\mu}_0^T \\mat{\\Sigma}_0^{-1} ) \\vec{x} + \\right.\\\\\n        & & \\left. \\hspace{-4cm} \n        + \\vec{\\mu}_1^T \\mat{\\Sigma}_1^{-1} \\vec{\\mu}_1 - \\vec{\\mu}_0^T \\mat{\\Sigma}_0^{-1} \\vec{\\mu}_0\n      \\right)\n    \\end{eqnarray*}\n  \\end{ovalblock}\n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n  \n  \\begin{ovalblock}{Example cont.}\n    \\small\n    Now we have:\n    \\begin{eqnarray*}\n      \\mat{A}        &=& \\frac{1}{2} (\\mat{\\Sigma}_1^{-1} - \\mat{\\Sigma}_0^{-1}) \\\\[.5cm]\n      \\vec{\\alpha}^T &=& \\vec{\\mu}_0^T \\mat{\\Sigma}_0^{-1} - \\vec{\\mu}_1^T \\mat{\\Sigma}_1^{-1} \\\\[.5cm]\n      \\alpha_0       &=& \\log \\frac{p(y=0)}{p(y=1)} + \\frac{1}{2}\n                         \\left(\n                           \\log\n                             \\frac{ \\det{( 2 \\pi \\mat{\\Sigma}_1)}}\n                                  { \\det{( 2 \\pi \\mat{\\Sigma}_0)}} + \n                             \\vec{\\mu}_1^T \\mat{\\Sigma}_1^{-1} \\vec{\\mu}_1 -\n                             \\vec{\\mu}_0^T \\mat{\\Sigma}_0^{-1} \\vec{\\mu}_0\n                         \\right)\n    \\end{eqnarray*}\n  \\end{ovalblock}\n\\end{frame}\n  \n  \n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n  \n  \\begin{figure}\n    \n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<4->{\n        \\input{\\texfigdir/plot_decision_boundary.pstex_t}\n      }\n{\\alt<3>{\n        \\input{\\texfigdir/gaussian2.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/gaussian1.pstex_t}\n      }{\n        \\input{\\texfigdir/gaussian0.pstex_t}\n      }}}\n    }\n    \\caption{Two Gaussian sample sets and the decision boundary}\n  \\end{figure}\n\\end{frame}\n \n \n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n\n  \\structure{Quadratic polynomials in the 2 variables $x_1$ and $x_2$}\n\n  \\begin{eqnarray*}\n    F(\\vec{x}) \n      &=& \\vec x^T \\mat A \\vec x + \\vec \\alpha^T\\vec x + \\alpha_0 \\\\\n      &=& a x_1^2 + b x_1 x_2 + c x_2^2 + d x_1 + e x_2 + f \\stackrel{!}{=} 0\n  \\end{eqnarray*}\n  \\vspace{-0.75cm}\n\n  \\begin{figure}\n  \\copyrightbox[b]{\n    \\subfloat[circles and ellipses]{\n      \\makebox[.3\\linewidth]{\n        \\href{http://en.wikipedia.org/wiki/File:Conic_sections_with_plane.svg}{\n          \\includegraphics[height=3cm]{\\pngdir/conic_section_circle_ellipse.\\png}\n        }\n      }\n    }\n    \\subfloat[parabolas]{\n      \\makebox[.3\\linewidth]{\n        \\href{http://en.wikipedia.org/wiki/File:Conic_sections_with_plane.svg}{\n          \\includegraphics[height=3cm]{\\pngdir/conic_section_parabola.\\png}\n        }\n      }\n    }\n    \\subfloat[hyperbolas]{\n      \\makebox[.3\\linewidth]{\n        \\href{http://en.wikipedia.org/wiki/File:Conic_sections_with_plane.svg}{\n          \\includegraphics[height=3cm]{\\pngdir/conic_section_hyperbola.\\png}\n        }\n      }\n    }\n  }{Pbroks13,  \\href{https://creativecommons.org/licenses/by/3.0} {CC BY 3.0}, via Wikimedia Commons}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary \\cont}\n\n  \\structure{Posterior probability}\n\n  \\begin{center}\n    \\resizebox{.85\\linewidth}{!}{\n      \\input{\\texfigdir/plot_posterior.pstex_t}\n    }\n  \\end{center}\n\\end{frame}\n\n\\input{nextTime.tex}\n \n\\begin{frame}\n  \\frametitle{Decision Boundary in Distributions with Equal Dispersion}\n \n  \\begin{ovalblock}{Example cont.}\n    \\small\n    If both classes share the same covariances i.\\,e.\\ $\\mat\\Sigma= \\mat\\Sigma_0=\\mat\\Sigma_1$, then the argument of the sigmoid function is linear in the components of $\\vec{x}$.\n   \n    \\begin{eqnarray*}\n      \\mat{A}        &=& \\mat{0} \\\\[.5cm]\n      \\vec{\\alpha}^T &=& (\\vec{\\mu}_0 - \\vec{\\mu}_1)^T \\mat{\\Sigma}^{-1} \\\\[.5cm]\n      \\alpha_0       &=& \\log \\frac{p(y=0)}{p(y=1)} + \n                         \\frac{1}{2}(\\vec{\\mu}_1 - \\vec{\\mu}_0)^T \\mat{\\Sigma}^{-1} (\\vec{\\mu}_1 - \\vec{\\mu}_0)  \n     \\end{eqnarray*}\n  \\end{ovalblock}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary in Distributions with Equal Dispersion \\cont}\n   \n  \\begin{figure}\n    \\resizebox{.6\\linewidth}{!}{\n      \\alt<2>{\n        \\input{\\texfigdir/gaussian3.pstex_t}\n      }{\n        \\input{\\texfigdir/gaussian5.pstex_t}\n      }\n    }    \n    \\caption{Identical covariances lead to linear decision boundary}\n  \\end{figure}\n\\end{frame}\n\n\n% \\begin{frame}\n%   \\frametitle{Decision Boundary \\cont}\n%   \n%   \\begin{figure}\n%     \\includegraphics[width=0.7\\textwidth]{\\psdir/gauss_both.\\ps}\n%     \\caption{Quadratic and linear decision boundary in comparison}\n%   \\end{figure}\n% \\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary in Distributions with Equal Dispersion \\cont}\n\n  \\structure{Note:}\n  \n  \\begin{itemize}\n    \\item If the class conditionals are Gaussians and share the same covariance, the argument of the exponential function is affine in $\\vec x$.\n    \\item This result is even true for a more general family of pdfs and not limited to Gaussians.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Decision Boundary in Distributions with Equal Dispersion \\cont}\n\n  \\begin{citeblock}{Definition}\n    \nThe {\\em exponential family} is a class of pdf's that can be written in the following canonical form\n    \\begin{eqnarray*}\n      p(\\vec x;\\vec \\theta, \\phi) &=& e^{\\frac{\\vec\\theta^T \\cdot \\vec  x -b(\\vec \\theta)}{a(\\phi)}+c(\\vec x,\\phi)}\n    \\end{eqnarray*}\n    where $\\vec \\theta\\in \\real^d$ is the {\\em location parameter vector}, $\\phi$ the {\\em dispersion parameter}.\n  \\end{citeblock}\n\\end{frame}\n\n\n%  \\begin{ovalblock}{Example}\n%     Binomial, Poisson, hypergeometric, exponential probability density functions or Gaussians belong to the exponential family.\n%  \\end{ovalblock}\n\n\n\\begin{frame}\n  \\frametitle{Exponential Family}\n\n  \\structure{Gaussian Probability Density Function \\phantom{\\cont}}\n\n  \\begin{displaymath}\n    \\mathcal{N}(\\vec{x}; \\vec{\\mu},\\mat{\\Sigma}) = \\frac{1}{ \\sqrt{ \\det{(2 \\pi \\mat{\\Sigma}_y})} } \n                    e^{-\\frac{1}{2} (\\vec{x} - \\vec{\\mu})^T \\mat{\\Sigma}^{-1} (\\vec{x} - \\vec{\\mu})  } \n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\centering\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss1.pstex_t}       \n      }\n    }\n    \\quad\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss2.pstex_t}\n      }\n    }\n    \\quad\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss3.pstex_t}\n      }\n    }\n\n    \\caption{Gaussian probability density functions with $\\vec\\mu = (0, 0)^T$}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Exponential Family}\n\n  \\structure{Gaussian Probability Density Function \\cont}\n%\n  \\begin{displaymath}\n    \\mathcal{N}(\\vec{x}; \\vec{\\mu},\\mat{\\Sigma}) = \\frac{1}{ \\sqrt{ \\det{(2 \\pi \\mat{\\Sigma}_y})} } \n                    e^{-\\frac{1}{2} (\\vec{x} - \\vec{\\mu})^T \\mat{\\Sigma}^{-1} (\\vec{x} - \\vec{\\mu})  } \n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\centering\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss4.pstex_t}\n      }\n    }\n    \\quad\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss5.pstex_t}\n      }\n    }\n    \\quad\n    \\subfloat{\n      \\resizebox{.3\\linewidth}{!}{\n        \\input{\\texfigdir/gauss6.pstex_t}\n      }\n    }\n\n    \\caption{Gaussian probability density functions with $\\vec\\mu = (0, 0)^T$}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Exponential Family \\cont}\n\n  \\structure{Exponential Probability Density Function}\n%\n  \\begin{displaymath}\n    f_\\lambda(x) = \\left\\{ \n                 \\begin{array}{ll}\n                   \\lambda e^{-\\lambda x} & x \\ge 0 \\\\\n                   0                      & x < 0 \\\\\n                 \\end{array}\n               \\right.\n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\resizebox{.65\\linewidth}{!}{\n      \\alt<4->{\n        \\input{\\texfigdir/exponential4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/exponential3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/exponential2.pstex_t}\n      }{\n        \\input{\\texfigdir/exponential1.pstex_t}\n      }}}\n    }\n    \\caption{Exponential probability density functions}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Exponential Family \\cont}\n\n  \\structure{Binomial Probability Mass Function}\n%\n  \\begin{displaymath}\n    B(k; p,n) = {n \\choose k} p^k (1-p)^{n-k}\n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\resizebox{.65\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/binomial3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/binomial2.pstex_t}\n      }{\n        \\input{\\texfigdir/binomial1.pstex_t}\n      }}\n    }\n    \\caption{Binomial probability mass functions for $n=20$}\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Exponential Family \\cont}\n\n  \\structure{Poisson Probability Mass Function}\n%\n  \\begin{displaymath}\n    P_\\lambda(X=k) = \\frac{\\lambda^k}{k!} e^{-\\lambda}\n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\resizebox{.70\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/poisson3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/poisson2.pstex_t}\n      }{\n        \\input{\\texfigdir/poisson1.pstex_t}\n      }}\n    }\n    \\caption{Poisson probability mass functions}\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Exponential Family \\cont}\n\n  \\structure{Hypergeometric Probability Mass Function}\n\n  \\begin{displaymath}\n    h(k; N,M,n) = \\frac{{M \\choose k}{N-M \\choose n-k}}{{N \\choose n}}\n  \\end{displaymath}\n%\n  \\begin{figure}\n    \\resizebox{.65\\linewidth}{!}{\n      \\alt<3->{\n        \\input{\\texfigdir/hypergeometric3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/hypergeometric2.pstex_t}\n      }{\n        \\input{\\texfigdir/hypergeometric1.pstex_t}\n      }}\n    }\n    \\caption{Hypergeometric probability mass functions}\n  \\end{figure}\n\\end{frame}\n\n\\begin{frame}\n   \\frametitle{Decision Boundary \\cont}\n\n   \\begin{lemma}\n     If all class-conditional densities are members of the same exponential family of probability density functions with equal dispersion $\\phi$, the decision boundary $F(\\vec x)=0$ is linear in the components of $\\vec x$.\n   \\end{lemma}\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n\n  \\begin{itemize}\n    \\item Posteriors can be rewritten in terms of a logistic function. \\pause\n    \\item Given the decision boundary $F(\\vec x)=0$, we can write down the posterior $p(y|\\vec x)$ right away. \\pause\n    \\item Decision boundary for normally distributed feature vectors for each class is a quadratic function. \\pause\n    \\item If Gaussians share the same covariances, the decision boundary is a linear function.\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 T. Hastie, R. Tibshirani, and J. Friedman: \\\\\n      \\structure{The Elements of Statistical Learning --}\\\\\n      \\structure{ Data Mining, Inference, and Prediction},\\\\\n      2nd edition, Springer, New York, 2009. \\\\[.3cm]\n    \\item David W. Hosmer, Stanley Lemeshow: \\\\\n      \\structure{Applied Logistic Regression}, 2nd Edition, \\\\\n      John Wiley \\& Sons, Hoboken, 2000.\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 How can we model the posterior probabilities? \\\\[1cm] \\pause\n    \\item Formulate the criterion for the decision boundary! \\\\[1cm] \\pause\n    \\item Describe the shape of the decision boundary for a Gaussian with different and same class covariances! \\\\[1cm] \\pause\n    \\item What effect does a change of the priors have on the decision boundary?\n  \\end{itemize}\n\\end{frame}\n\n\n\n", "meta": {"hexsha": "b6a02d7b778c2df398445de2b51273e0de0d1c57", "size": 19589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03_logistic_regression.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": "03_logistic_regression.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": "03_logistic_regression.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.9350073855, "max_line_length": 222, "alphanum_fraction": 0.5777732401, "num_tokens": 6873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6150871000194765}}
{"text": "\\section{Multivariate amplitude distributions}\n\\label{sec:epochs}\n\nIn Sect. \\ref{subsec:key_concepts} we introduce the fundamental quantities\nused in the distribution definitions. An example of the non-stationarity in\nfinancial markets is shown in Sect. \\ref{subsec:non_stationarity}. Finally, in\n\\ref{subsec:epochs} we explain the methodology to see how the returns are to a\ngood approximation multivariate Gaussian distributed or multivariate Algebraic\ndistributed.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Key concepts}\\label{subsec:key_concepts}\n\nConsider time series $S_{k} \\left( t \\right)$, $k = 1, 2, \\ldots, K$ of stock\nprices for $K$ companies. The values $S_{k} \\left( t \\right)$ are taken in\nfixed time steps $\\Delta t$. In general, the data contain an exponential\nincrease due to the drift. Thus, to measure the correlations independently of\nthis trend, it is better to use logarithmic differences instead of returns\n\\begin{equation}\n    G_{k} \\left( t \\right) = \\ln S_{k} \\left( t + \\Delta t \\right) -\n    \\ln S_{k} \\left(t \\right) = \\ln \\frac{S_{k} \\left( t + \\Delta t \\right)}\n    {S_{k} \\left(t \\right)}.\n\\end{equation}\nAnyway, logarithmic differences and returns almost coincide if the time steps\n$\\Delta t$ are sufficiently short \\cite{subtle_nature,empirical_facts}\n\\begin{equation}\n    G_{k} \\left(t\\right) \\approx r_{k} \\left(t\\right)\n    = \\frac{S_{k} \\left( t + \\Delta t \\right) - S_{k} \\left( t \\right)}\n    {S_{k} \\left( t \\right)}.\n\\end{equation}\nThe returns are well known to have distributions with heavy tails, the smaller\n$\\Delta t$, the heavier \\cite{non_stationarity_fin_guhr}. Furthermore, the\nsample standard deviations $\\sigma_{k}$, referred to as volatilities, strongly\nfluctuate for different time windows of the same length $T$\n\\cite{non_stationarity_fin_guhr,volatility_change}.\n\nThe mean of the logarithmic differences reads \\cite{exact_distributions_guhr}\n\\begin{equation}\n    \\left\\langle G_{k} \\left( t \\right) \\right\\rangle_{T} = \\frac{1}{T}\n    \\sum_{t = 1}^{T} G_{k} \\left( t \\right).\n\\end{equation}\nTo compare the different $K$ companies, it is necessary to normalize the time\nseries. The normalized time series are defined by\n\\cite{non_stationarity_fin_guhr,exact_distributions_guhr}\n\\begin{equation}\n    M_{k} \\left( t \\right) = \\frac{G_{k} \\left( t \\right) - \\left\\langle\n    G_{k} \\left( t \\right) \\right\\rangle} {\\sqrt{\\left\\langle G_{k}^{2}\n    \\left( t \\right) \\right\\rangle_{T} - \\left\\langle G_{k} \\left( t \\right)\n    \\right\\rangle^2_{T}}},\n\\end{equation}\nwhere\n\\begin{equation}\n    \\sigma_{k} = \\sqrt{\\left\\langle G_{k}^{2}\n    \\left( t \\right) \\right\\rangle_{T} - \\left\\langle G_{k} \\left( t \\right)\n    \\right\\rangle^2_{T}}\n\\end{equation}\nis the volatility of the $k$ company in the time window of length $T$. These\nvalues can be viewed as the elements of a $K \\times T$ rectangular matrix $M$.\nWith these normalizations and rescalings, correlations can be measured in such\na way that all companies and all stocks are treated on equal footing.\n\nThe correlation coefficient for the stocks $k$ and $l$ is defined as\n\\cite{non_stationarity_fin_guhr}\n\\begin{equation}\n    C_{kl} = \\left\\langle M_{k} \\left( t \\right) M_{l} \\left( t \\right)\n    \\right\\rangle_{T} = \\frac{1}{T} \\sum_{t=1}^{T} M_{k} \\left( t \\right) M_{l}\n    \\left( t \\right),\n\\end{equation}\nwhich can be written as\n\\begin{equation}\n    C_{kl} = \\frac{\\left\\langle G_{k} \\left( t \\right) G_{l} \\left( t \\right)\n    \\right\\rangle_{T} - \\left\\langle G_{k} \\left( t \\right) \\right\\rangle_{T}\n    \\left\\langle G_{l} \\left( t \\right) \\right\\rangle_{T}}\n    {\\sigma_{k} \\sigma_{l}}.\n\\end{equation}\nThe coefficients $C_{kl}$ are the elements of a $K \\times K$ square matrix $C$,\nthe correlation matrix. The limiting values of these correlation coefficients\n\\begin{equation}\n    C_{kl}^{\\text{lim}} =\n    \\left\\{\n    \\begin{array}{cc}\n    +1 & \\text{completely correlated}  \\\\\n    0  & \\text{completely uncorrelated}\\\\\n    -1 & \\text{completely anticorrelated}\n    \\end{array}\n    \\right. .\n\\end{equation}\nThe time average of $C_{kl}$ can be viewed as the matrix product of the\nrectangular matrix $M$ ($K \\times T$) with its transpose matrix $M^{\\dagger}$\n($T \\times K$), divided by $T$. Thus, the correlation matrix can be written in\nthe form\n\\begin{equation}\n    C = \\frac{1}{T} M M^{\\dagger}.\n\\end{equation}\nThe correlation matrix $C$ is real and symmetric. Using the correlation matrix\n$C$ is possible to define the covariance matrix\n\\cite{exact_distributions_guhr,credit_risk_guhr,portfolio_distributions_guhr,asset_correlations_guhr,stochastic_cov_guhr}\n\\begin{equation}\n    \\Sigma = \\sigma C \\sigma ,\n\\end{equation}\nwhere the diagonal matrix $\\sigma$ contains respectively, the volatilities\n$\\sigma_{k}$, $k = 1, \\ldots, K$.\n\nTo ease the comparison between works, we will use covariance matrices as in\n\\cite{non_stationarity_fin_guhr}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Non-stationarity}\\label{subsec:non_stationarity}\n\nIn general, in non-stationary complex systems crucial parameters or\ndistributions of observables change in an erratic, unpredictable way over time.\nIn financial markets, the change of the $K \\times K$ correlation matrix $C$ as\na whole in time is an example of non-stationary. Fig.\n\\ref{fig:correlation_matrices} shows two large correlation matrices of\nlogarithmic differences of stock prices for companies in the Standard \\&\nPoor's 500 (S\\&P 500) stock market index ordered according to the Global\nIndustry Classification Standard (GICS). The time series were measured in\nsuccessive quarters. The stripes in these correlation matrices indicate the\nstructuring of the market in industrial sectors\n\\cite{state_crisis_7,non_stationarity_fin_guhr}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]\n    {figures/05_correlation_matrix.png}\n    \\caption{Correlation matrices of $K = 421$ companies for the fourth quarter\n             of 2005 (left) and the first quarter of 2006 (right), the darker,\n             the stronger the correlation. The companies are sorted according\n             to industrial sectors.}\n    \\label{fig:correlation_matrices}\n\\end{figure}\n\nIn Fig. \\ref{fig:correlation_matrices} it can be seen that the matrices look\ndifferent for the successive quarters, because the business relations between\nthe companies and the market expectations of the traders change in time.\nDespite the difference, the coarse structure remains similar, indicating some\nstability of the industrial sectors.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Choice of amplitude in each of the epochs}\\label{subsec:epochs}\n\nWe use the same methodology from T. A. Schmitt et al.\n\\cite{non_stationarity_fin_guhr} to show that to a good approximation, the\nreturns can be multivariate Gaussian distributed or multivariate algebraic\ndistributed, depending on the epochs window length choice. All of this, if the\ncovariance matrix $\\Sigma$ is fixed within the epochs.\n\nWe start from the assumption that the $K$ dimensional vectors\n$r \\left( t \\right) = \\left( r_{1} \\left( t \\right), \\ldots, r_{K} \\left( t \\right) \\right)$\nfor a fixed return interval $\\Delta t$ is given by the multivariate Gaussian\ndistribution\n\\begin{equation}\\label{eq:gaussian_distribution}\n    P_{G} \\left( r| \\Sigma_{ep} \\right) =\n    \\frac{1}{\\sqrt{\\det 2 \\pi \\Sigma_{ep} }}\n    \\exp \\left( - \\frac{1}{2} r^{\\dagger} \\Sigma_{ep}^{-1} r \\right).\n\\end{equation}\nTo test the assumption, we divide the time series in windows of length $T$\nwhere the sampled covariances can be viewed as constant within these windows.\n\nTo carry out the data analysis, whether for the multivariate Gaussian\ndistribution or the multivariate algebraic distribution, we choose all pairs of\nreturns, normalize the epochs (mean $\\mu = 0$ and variance $\\sigma^{2} = 1$)\nand create two-component vectors\n$\\left( r_{k} \\left( t \\right), r_{l} \\left( t \\right) \\right)$. For each pair,\nwe evaluate the $2 \\times 2$ sample covariance matrix\n$\\Sigma^{\\left(k, l \\right)}$. Then we diagonalize the covariance matrix as\n$\\Sigma = U \\Lambda U^{\\dagger}$, such that\n$\\Sigma^{-1/2} = U \\Lambda^{-1/2} U^{\\dagger}$, where $U$ is an orthogonal\n$K \\times K$  matrix and $\\Lambda$ is the diagonal matrix of the eigenvalues\n$\\Lambda_{K}$. We rotate the two-component returns vectors into the eigenbasis\nof $\\Sigma^{\\left(k, l \\right)}$,\n\\begin{equation}\n    \\left(\\tilde{r}_{1} \\left(t \\right), \\tilde{r}_{2} \\left(t \\right) \\right)\n    = U \\left(r_{k} \\left(t \\right), r_{l} \\left(t \\right) \\right)\n\\end{equation}\nand normalize the axis with the eigenvalues as\n\\begin{equation}\n    \\frac{\\tilde{r}_{1} \\left(t \\right)}{\\sqrt{\\Lambda_{1}}} \\text{ and }\n    \\frac{\\tilde{r}_{2} \\left(t \\right)}{\\sqrt{\\Lambda_{2}}}.\n\\end{equation}\nFinally, we aggregate all the components into a single univariate distribution,\nas all of them are now comparable.\n\nNow we need to find the one dimensional function related to the multivariate\nGaussian distribution in Eq. \\ref{eq:gaussian_distribution} to compare with the\nempirical  single univariate distributions. In the Gaussian case, we know that\n\\begin{align}\n    P_{G}^{\\left( ij \\right)} \\left( r^{\\left( ij \\right)} |\n    \\Sigma_{ep}^{\\left( ij \\right)} \\right)\n    &= \\int d \\left[ r \\right]_{\\ne i,j} P_{G} \\left( r | \\Sigma_{ep} \\right)\\\\\n    &= \\frac{1}{\\sqrt{\\det 2 \\pi \\Sigma_{ep}^{\\left( ij \\right)}}}\n    \\exp \\left( -\\frac{1}{2} r^{\\left( ij \\right) \\dagger}\n    \\Sigma_{ep}^{\\left( ij \\right)^{ - 1}} r^{\\left( ij \\right)} \\right)\n\\end{align}\nis the corresponding bivariate model where\n\\begin{equation}\n    r^{\\left(ij\\right)}=\\left[\\begin{array}{c}\n    r_{i}\\\\\n    r_{j}\n    \\end{array}\\right]\\text{ and } \\Sigma_{ep}^{\\left(ij\\right)}\n    =\\left[\\begin{array}{cc}\n    \\Sigma_{ep,ii} & \\Sigma_{ep,ij}\\\\\n    \\Sigma_{ep,ji} & \\Sigma_{ep,jj}\n    \\end{array}\\right]\n\\end{equation}\nare the two-component return vector and the $2 \\times 2$ covariance matrix.\n$\\Sigma_{ep,ij}$ is just the $\\left( ij \\right)$ element of $\\Sigma_{ep}$.\nDiagonalizing\n\\begin{equation}\n    \\Sigma_{ep}^{\\left(ij\\right)}=U^{\\left(ij\\right)}\n    \\Lambda_{ep}^{\\left(ij\\right)}U^{\\left(ij\\right)\\dagger}\n\\end{equation}\nwith the $2 \\times 2$ rotation matrix $U^{\\left( ij \\right)}$ and the\neigenvalue matrix\n\\begin{equation}\n    \\Lambda_{ep}^{\\left( ij \\right)} = \\text{diag}\n    \\left( \\Lambda_{ep,1}^{\\left( ij \\right)},\n    \\Lambda_{ep,2}^{\\left( ij \\right)} \\right).\n\\end{equation}\nWe rotate into the eigenbasis\n\\begin{equation}\n    \\bar{r}^{\\left(ij\\right)}=\\left[\\begin{array}{c}\n    \\bar{r}_{1}^{\\left(ij\\right)}\\\\\n    \\bar{r}_{2}^{\\left(ij\\right)}\n    \\end{array}\\right]=U^{\\left(ij\\right)\\dagger}r^{\\left(ij\\right)}\n\\end{equation}\nsuch that\n\\begin{align}\n    P_{G}^{\\left(ij\\right)}\\left(r^{\\left(ij\\right)}|\n    \\Sigma_{ep}^{\\left(ij\\right)}\\right)\n    &=P_{G}^{\\left(ij\\right)}\\left(\\bar{r}^{\\left(ij\\right)}|\n    \\Lambda_{ep}^{\\left(ij\\right)}\\right)\\\\\n    &=\\frac{1}{\\sqrt{2\\pi\\Lambda_{ep,1}^{\\left(ij\\right)}}}\n    \\exp\\left(-\\frac{\\bar{r}_{1}^{\\left(ij\\right)^{2}}}{2\\Lambda_{ep,1}\n    ^{\\left(ij\\right)}}\\right)\n    \\,\\frac{1}{\\sqrt{2\\pi\\Lambda_{ep,2}^{\\left(ij\\right)}}}\n    \\exp\\left(-\\frac{\\bar{r}_{2}^{\\left(ij\\right)^{2}}}{2\\Lambda_{ep,2}\n    ^{\\left(ij\\right)}}\\right).\n\\end{align}\nThe univariate rotated distribution is\n\\begin{align}\n    \\tilde{P}_{G}^{\\left(ij\\right)}\\left(\\tilde{r}\\right)\n    &=\\intop_{-\\infty}^{+\\infty}d\\bar{r}_{2}^{\\left(ij\\right)}\n    P_{G}^{\\left(ij\\right)}\\left(\\bar{r}^{\\left(ij\\right)}|\n    \\Lambda_{ep}^{\\left(ij\\right)}\\right)\\vert_{\\bar{r}_{1}^{\\left(ij\\right)}/\n    \\sqrt{\\Lambda_{ep,1}^{\\left(ij\\right)}}=\\tilde{r}}\\,\n    \\frac{d\\bar{r}_{1}^{\\left(ij\\right)}}{d\\tilde{r}}\\\\\n    & =\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{1}{2}\\tilde{r}^{2}\\right),\n\\end{align}\nwhich is the standard Gaussian distribution with mean $\\mu = 0$ and variance\n$\\sigma^2 = 1$.\n\nTo check the validity of our assumption, in Fig.\n\\ref{fig:gaussian_agg_returns_epoch} we plot the daily adjusted closing\naggregated returns distribution of 200 companies from the S\\&P 500 dataset,\nwith a $\\Delta t = 1d$ and an epoch window length $T = 25d$. For the\nunivariate distribution case we observe a good agreement with the one\ndimensional Gaussian distribution, as expected.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.6\\columnwidth]\n    {figures/05_gaussian_agg_returns_short_epoch.png}\n    \\caption{Aggregated distribution of returns ($\\tilde{r}$) for fixed\n             covariance of 200 companies selected from the S\\&P 500\n             dataset. $\\Delta t = 1d$ and epoch window length $T=25d$.}\n    \\label{fig:gaussian_agg_returns_epoch}\n\\end{figure}\n\nTo model heavy tails, we assume that the $K$ dimensional vectors\n$r \\left( t \\right) = \\left( r_{1} \\left( t \\right), \\ldots, r_{K} \\left( t \\right) \\right)$\nfor a fixed return interval $\\Delta t$ is given by the multivariate algebraic\ndistribution\n\\begin{align}\n    P_{A} \\left( r | \\Sigma_{ep} \\right)\n    &= \\frac{\\alpha_{K1lm}}{\\left( 1 + \\frac{1}{m} r^{\\dagger}\n    \\Sigma^{-1}_{ep} r \\right)^{l}}\\label{eq:algebraic_distribution} \\\\\n    \\alpha_{K1lm} &= {\\sqrt{\\frac{2}{m}}}^{K}\n    \\frac{\\Gamma \\left( l \\right)}{\\Gamma \\left( l - K/2 \\right)}\n    \\frac{1}{\\sqrt{\\det 2 \\pi \\Sigma_{ep}}}.\n\\end{align}\nTo test the new assumption and compare the different time step data, we repeat\nthe same method to rotate and scale the returns to then get the aggregate\ndistribution of returns. Once more, we need to find the corresponding one\ndimensional functions related to the multivariate algebraic distribution in Eq.\n\\ref{eq:algebraic_distribution} to compare with the empirical single univariate\ndistributions.\n\nWe know that the algebraic model from Eq. \\ref{eq:algebraic_distribution}\nrelates to the Gaussian model from Eq. \\ref{eq:gaussian_distribution} via\n\\begin{equation}\n    P_{A}\\left(r|\\Sigma_{ep}\\right)\n    =\\intop_{0}^{\\infty}\\chi_{2\\left(l-K/2\\right)}^{2}\\left(z\\right)\\,\n    P_{G}\\left(r|\\frac{m}{2}\\Sigma_{ep}\\right)dz.\n\\end{equation}\nWe immediately find\n\\begin{align}\n    P_{A}^{\\left(ij\\right)}\\left(r^{\\left(ij\\right)}|\n    \\Sigma_{ep}^{\\left(ij\\right)}\\right)\n    & =\\int d\\left[r\\right]_{\\ne i,j}P_{A}\\left(r|\\Sigma_{ep}\\right)\\\\\n    & =\\intop_{0}^{\\infty}dz\\,\\chi_{2\\left(l-K/2\\right)}^{^{2}}\\left(z\\right)\n    \\frac{1}{\\sqrt{\\det2\\pi\\frac{m}{2}\\Sigma_{ep}^{\\left(ij\\right)}}}\n    \\exp\\left(-\\frac{z}{2m}r^{\\left(ij\\right)\\dagger}\n    \\Sigma_{ep}^{\\left(ij\\right)^{-1}}r^{\\left(ij\\right)}\\right)\\\\\n    & =\\frac{1}{\\sqrt{\\det2\\pi\\Sigma_{ep}^{\\left(ij\\right)}}}\n    \\intop_{0}^{\\infty}dz\\,\\chi_{2\\left(l-K/2\\right)}^{^{2}}\\left(z\\right)\n    \\frac{z}{m}\\exp\\left(-\\frac{z}{2m}r^{\\left(ij\\right)\\dagger}\n    \\Sigma_{ep}^{\\left(ij\\right)^{-1}}r^{\\left(ij\\right)}\\right).\n\\end{align}\nUsing\n\\begin{equation}\n    \\chi_{q+2}^{2}\\left(z\\right)=\\frac{1}{q}\\chi_{q}^{2}\\left(z\\right)z\n\\end{equation}\nwe have\n\\begin{align}\n    P_{A}^{\\left(ij\\right)}\\left(r^{\\left(ij\\right)}|\n    \\Sigma_{ep}^{\\left(ij\\right)}\\right)\n    &=\\frac{2\\left(l-K/2\\right)}{m\\sqrt{\\det2\\pi\\Sigma_{ep}^{\\left(ij\\right)}}}\n    \\intop_{0}^{\\infty}dz\\,\\chi_{2\\left(l+1-K/2\\right)}^{2}\\left(z\\right)\n    \\exp\\left(-\\frac{z}{2m}r^{\\left(ij\\right)\\dagger}\n    \\Sigma_{ep}^{\\left(ij\\right)^{-1}}r^{\\left(ij\\right)}\\right)\\\\\n    & =\\frac{2\\left(l-K/2\\right)}{m\\sqrt{\\det2\\pi\\Sigma_{ep}\n    ^{\\left(ij\\right)}}}\\frac{1}{2^{l+1-K/2}\\Gamma\\left(l+1-K/2\\right)}\n    \\intop_{0}^{\\infty}dz\\,z^{l-K/2}\n    \\exp\\left[-\\frac{z}{2}\\left(1+\\frac{1}{m}r^{\\left(ij\\right)\\dagger}\n    \\Sigma_{ep}^{\\left(ij\\right)^{-1}}r^{\\left(ij\\right)}\\right)\\right]\\\\\n    &=\\frac{2l-K}{m\\sqrt{\\det2\\pi\\Sigma_{ep}^{\\left(ij\\right)}}}\n    \\frac{1}{\\left(1+\\frac{1}{m}r^{\\left(ij\\right)\\dagger}\n    \\Sigma_{ep}^{\\left(ij\\right)^{-1}}r^{\\left(ij\\right)}\\right)^{l+1-K/2}}\n    \\label{eq:using_chi}.\n\\end{align}\nRotating into the eigenbasis, we can integrate out one of the variables\n\\begin{equation}\n    \\tilde{P}_{A}^{\\left(ij\\right)}\\left(\\bar{r}_{1}^{\\left(ij\\right)}|\n    \\Lambda_{ep,1}^{\\left(ij\\right)}\\right)\n    =\\intop_{-\\infty}^{+\\infty}d\\bar{r}_{2}^{\\left(ij\\right)}\n    P_{A}^{\\left(ij\\right)}\\left(\\bar{r}^{\\left(ij\\right)}|\n    \\Lambda_{ep}^{\\left(ij\\right)}\\right).\n\\end{equation}\nUsing Eq. \\ref{eq:using_chi}, we have\n\\begin{align}\n    \\tilde{P}_{A}^{\\left(ij\\right)}\\left(\\bar{r}_{1}^{\\left(ij\\right)}|\n    \\Lambda_{ep,1}^{\\left(ij\\right)}\\right)\n    &=\\frac{2\\left(l-K/2\\right)}{\\sqrt{m}\\sqrt{2\\pi\\Lambda_{ep,1}\n    ^{\\left(ij\\right)}}}\\frac{1}{2^{l+1-K/2}\\Gamma\\left(l+1-K/2\\right)}\n    \\intop_{0}^{\\infty}dz\\,z^{l-K/2-1/2}\\exp\\left[-\\frac{z}{2}\n    \\left(1+\\frac{1}{m}\\frac{\\bar{r}_{1}^{\\left(ij\\right)^{2}}}\n    {\\Lambda_{ep,1}^{\\left(ij\\right)}}\\right)\\right]\\\\\n    &=\\frac{2\\left(l-K/2\\right)}{\\sqrt{m}\\sqrt{2\\pi\\Lambda_{ep,1}^\n    {\\left(ij\\right)}}}\\frac{2^{l+1/2-K/2}\n    \\Gamma\\left(l+1/2-K/2\\right)}{2^{l+1-K/2}\n    \\Gamma\\left(l+1-K/2\\right)}\\frac{1}{\\left(1+\\frac{1}{m}\n    \\frac{\\bar{r}_{1}^{\\left(ij\\right)^{2}}}\n    {\\Lambda_{ep,1}^{\\left(ij\\right)}}\\right)^{l-\\left(K-1\\right)/2}}\\\\\n    &=\\sqrt{\\frac{2}{m}}\\frac{\\Gamma\\left(l-\\left(K-1\\right)/2\\right)}\n    {\\Gamma\\left(l-K/2\\right)}\\frac{1}{\\sqrt{2\\pi\\Lambda_{ep,1}\n    ^{\\left(ij\\right)}}}\\frac{1}{\\left(1+\\frac{1}{m}\n    \\frac{\\bar{r}_{1}^{\\left(ij\\right)^{2}}}\n    {\\Lambda_{ep,1}^{\\left(ij\\right)}}\\right)^{l-\\left(K-1\\right)/2}}.\n\\end{align}\nGoing over to the rescaled variable\n\\begin{equation}\n    \\tilde{r} = \\frac{\\bar{r}^{\\left( ij \\right)}}{\\sqrt{\\Lambda_{ep,1}\n    ^{\\left( ij \\right)}}}\n\\end{equation}\nwe arrive at\n\\begin{equation}\n    \\tilde{P}_{A}^{\\left(ij\\right)}\\left(\\tilde{r}\\right)\n    =\\frac{1}{\\sqrt{2\\pi}}\\sqrt{\\frac{2}{m}}\n    \\frac{\\Gamma\\left(l-\\left(K-1\\right)/2\\right)}{\\Gamma\\left(l-K/2\\right)}\n    \\frac{1}{\\left(1+\\frac{1}{m}\\tilde{r}^{2}\\right)^{l-\\left(K-1\\right)/2}}\n\\end{equation}\nwhich is the algebraic distribution to be fitted to the aggregated returns.\nIn this case we have three parameters: $K$, $l$ and $m$. $K$ is the number of\ncompanies used and is known from the data. $l$ and $m$ are the shape parameters\nof the distribution and have to be determined by fitting. In the model, the\nexpectation value $\\langle r r^{\\dagger} \\rangle$ serves as an estimator for\nthe sample covariances. We find\n\\begin{equation}\n    \\langle r r^{\\dagger} \\rangle_{Y} = \\beta_{Y} \\Sigma_{ep}\n\\end{equation}\nwith\n\\begin{equation}\n    \\beta_{Y}=\\begin{cases}\n    1, & \\text{if }Y=G\\\\\n    \\frac{m}{2l-K-2}, & \\text{if }Y=A\n\\end{cases}.\n\\end{equation}\nDue to its very definition, we have $\\beta_{G} = 1$ for the multivariate\nGaussian, but a different value $\\beta_{A}$ for the algebraic distribution. The\nrelation in the latter case then suggest the useful fixing\n\\begin{equation}\\label{eq:m_relation}\n    m = 2l - K - 2\n\\end{equation}\nalso for finite values of $l$ and $m$. Only with this choice, $\\Sigma_{ep}$ can\nbe estimated by the sample covariance matrix, otherwise only up to some factor.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=\\columnwidth]\n    {figures/05_algebraic_agg_returns_short_epoch.png}\n    \\caption{Semilog plot (left) and loglog plot (right) of the aggregated\n             distribution of returns ($\\tilde{r}$) for fixed covariance of 200\n             companies selected from the S\\&P 500 dataset. $\\Delta t = 1d$ and\n             epoch window length $T=55d$. The empirical data is compared with\n             the best fit of one dimensional algebraic distribution with shape\n             parameter $l=104$.}\n    \\label{fig:algebraic_agg_returns_epoch}\n\\end{figure}\n\nHaving these details in mind and to check the validity of our assumption, in\nFig. \\ref{fig:algebraic_agg_returns_epoch} we plot the daily adjusted closing\naggregated returns distribution of 200 companies from the S\\&P 500 dataset,\nwith a $\\Delta t = 1d$ and an epoch window length $T = 55d$. Using Eq.\n\\ref{eq:m_relation} to compute $m$, we found that $l = 104$ fits well with the\naggregated returns. We plot the one dimensional Gaussian distribution as a\nreference.\n\nWe know that the aggregated returns have internal Gaussian and algebraic\nstructures depending on the epochs window length. The larger the value of $T$,\nthe heavier the tails and the smaller the stationary assumption within the\nepochs. However, during the epochs analysis we found an unusual behavior when\nwe used small epochs window lengths.\n\nUsing the methodology described in the work of Schmitt et al.\n\\cite{non_stationarity_fin_guhr}, we wanted to find which was the best value of\nthe epochs window length to fit the Gaussian and algebraic case. We used epochs\nwindow lengths $T = 10, 25, 40, 55$ days and $\\Delta t = 1d$. In Fig.\n\\ref{fig:window_comparison} can be seen the difference between epochs\nwindow lengths of the aggregated distribution of returns for fixed covariance\nof different amounts of random companies selected from the S\\&P 500 dataset.\nThe first interesting characteristic is that with few companies there is enough\ninformation to obtain the general behavior. This, because we are selecting\npairs of stocks from the dataset, such that the order of the selected stocks\ndoes not matter and without repetition, i.e. a combination. Thus, even with\na small number of companies, the results are statistically relevant. Then, We\nchoose random numbers of companies within our dataset to show this\ncharacteristic. We can see how for $T=25d$ (top right) there is a good agreement\nwith the Gaussian distribution, and how for values larger than $T=25d$, as\n$T=40d$ (bottom left) and $T=55d$ (bottom right), the aggregated returns have\nfat tails. However, for $T=10d$ (top left), the aggregated returns have a\nplatykurtic behavior. This particular behavior is unusual and makes us wonder\nif somehow there is an artifact in the methodology we are using, that is\naffecting the other epochs window lengths as well.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=0.8\\columnwidth]\n    {figures/05_window_comparison.png}\n    \\caption{Aggregated distribution of returns ($\\tilde{r}$) for fixed\n             covariance of different number of companies selected from the S\\&P\n             500 dataset. $\\Delta t = 1d$ and different epochs window lengths\n             $T=10d$ (top left), $T=25d$ (top right), $T=40d$ (bottom left) and\n             $T=55d$ (bottom right).}\n    \\label{fig:window_comparison}\n\\end{figure}\n\nWe consider two different causes for this situation in the small epochs window\nlengths. First, it could be an ergodicity defect because only the length of the\ntime window of the epochs shows an effect. Second, the platykurtic behavior\nlike in local normalization plots \\cite{local_normalization} could be a\ndetrending method. It is possible that we get this behavior from normalizing\neach epoch to mean $\\mu = 0$ and $\\sigma^{2}=1$.\n\nTo check what is the real cause of this behavior we will use simulations.\nWith these simulations we know which parameters we are using, and we have a\ncontrolled environment. Thus, we can evaluate where the problem is with the\nmethod.", "meta": {"hexsha": "8b06d6ad2570920bb807a1294814d4ff95c9b8da", "size": 23089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/exact_distributions_financial_paper/sections/05_epochs.tex", "max_stars_repo_name": "juanhenao21/exact_distributions_financial", "max_stars_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-20T18:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-15T07:25:50.000Z", "max_issues_repo_path": "paper/exact_distributions_financial_paper/sections/05_epochs.tex", "max_issues_repo_name": "juanhenao21/exact_distributions_financial", "max_issues_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_issues_repo_licenses": ["MIT"], "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/exact_distributions_financial_paper/sections/05_epochs.tex", "max_forks_repo_name": "juanhenao21/exact_distributions_financial", "max_forks_repo_head_hexsha": "02eb058e5f963fbccb9029aae3fb6e15def7a93a", "max_forks_repo_licenses": ["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.3354700855, "max_line_length": 121, "alphanum_fraction": 0.6836155745, "num_tokens": 7478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6150240702039764}}
{"text": "% ------------------------------------------------------------ %\n%\n% CUHK Mathematics\n% MATH3060: Mathematical Analysis III\n%\n% ------------------------------------------------------------ %\n\n\\documentclass[a4paper,12pt]{article}\n\\usepackage{standalone}\n\\input{sty/setup.sty}\n\n\\begin{document}\n\\title{MATH3060: Mathematical Analysis III}\n\\input{sty/cover.sty}\n\n\\remark{}\n\n\\input{sty/header.sty}\n\n\\section{Fourier Series}\n\\subsection{Introduction to Fourier Series}\n\\subsubsection{Trigonometric Series}\n\\begin{dft}\n  A \\textbf{trigonometric series} on $[-\\pi,\\pi]$ is a series of functions in the form\n\n  $$\\sum_{n=0}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\n  where $a_{n},b_{n}\\in\\R$. Furthermore, if $a_{n}=0$ for all $n$, the series is called a \\textbf{sine series}. Similarly, if $b_{n}=0$ for all $n$, the series is called a \\textbf{cosine series}.\n\\end{dft}\\n\n\nNote that it is possible to pull out the zeroth term of the sum, making the series in the form\n\n$$a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\nhence it can be assumed that $b_{0}=0$.\\n\n\n\\begin{pst}\n  Let $(a_{n}),(b_{n})$ be infinite series. If\n  \n  $$\\abs{a_{n}},\\abs{b_{n}}\\leq\\frac{C}{n^{s}}$$\\s\n  \n  for some $C>0$ and $s>1$, then their corresponding series $\\sum_{n=0}^{\\infty}\\abs{a_{n}}$ and $\\sum_{n=0}^{\\infty}\\abs{b_{n}}$ are convergent.\n\\end{pst}\n\n\\begin{pst}\n  If $\\sum_{n=0}^{\\infty}\\abs{a_{n}}$ and $\\sum_{n=0}^{\\infty}\\abs{b_{n}}$ are convergent, then by Weierstrass M-test,\n  \n  $$\\sum_{n=0}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n  \n  is uniformly and absolutely convergent.\n\\end{pst}\n\n\\begin{pst}\n  Let $\\phi(x)=a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$ be a continuous function on $[-\\pi,\\pi]$. If $\\sum\\abs{a_{n}},\\sum\\abs{b_{n}}<\\infty$, then $\\phi(x)$ is $2\\pi$-periodic.\n\\end{pst}\n\n\\propdisp\n\n\\subsubsection{Fourier Series}\n\\begin{dft}\n  Let $f$ be a $2\\pi$-periodic function on $\\R$ which is Riemann integrable on $[-\\pi,\\pi]$, then the \\textbf{Fourier series} (or \\textbf{Fourier expansion}) of $f$ is the trigonometric series\n\n  $$a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\n  with Fourier coefficients of $f$\n\n  $$a_{0}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(y)\\diff y$$\\s\n\n  $$a_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(y)\\cos(ny)\\diff y$$\\s\n\n  $$b_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(y)\\sin(ny)\\diff y$$\\s\n\\end{dft}\\n\n\nNote that $a_{0}$ is actually the average of $f$ over $[-\\pi,\\pi]$. Fourier series depends on the global information of $f$ on $[-\\pi,\\pi]$ instead of a point in $f$. Fourier series also depends only on $f\\!\\mid\\!_{(-\\pi,\\pi)}$, which means the end points of the closed interval are independent.\\n\n\n\\begin{pst}\n  Let $f_{1},f_{2}$ are Fourier series where $f_{1}\\equiv f_{2}$ almost everywhere on $[-\\pi,\\pi]$, then $f_{1}$ and $f_{2}$ are the same Fourier series.\n\\end{pst}\n\n\\subsubsection{Motivation of Fourier Series}\nRecall the form of a Fourier series as\n\n$$f(x)=a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\nfor all $x\\in\\R$. If $f$ is uniformly convergent,\n\n$$\\begin{aligned}[t]\n  &\\int_{-\\pi}^{\\pi}f(x)\\cos(mx)\\diff x\\\\\n  =\\;&a_{0}\\int_{-\\pi}^{\\pi}\\cos(mx)\\diff x+\\sum_{n=1}^{\\infty}\\brr{a_{n}\\int_{-\\pi}^{\\pi}\\cos(nx)\\cos(mx)\\diff x+b_{n}\\int_{-\\pi}^{\\pi}\\sin(nx)\\cos(mx)\\diff x}\n\\end{aligned}$$\\s\n\nNote that\n\n$$\\int_{-\\pi}^{\\pi}\\cos(mx)\\diff x=\\begin{cases}\n  2\\pi\\erm{if }m=0\\\\\n  0\\erm{if }m\\neq 0\n\\end{cases}$$\\s\n\n$$\\int_{-\\pi}^{\\pi}\\cos(nx)\\cos(mx)\\diff x=\\begin{cases}\n  \\pi\\erm{if }m=n\\\\\n  0\\erm{if }m\\neq n\n\\end{cases}$$\\s\n\n$$\\int_{-\\pi}^{\\pi}\\sin(nx)\\cos(mx)\\diff x=0\\;\\forall m,n\\geq 1$$\\s\n\nwhich will deduce\n\n$$a_{0}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)\\diff x,\\;a_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)\\cos(mx)\\diff x$$\\s\n\nUsing similar method but instead of $\\cos(mx)$, $\\sin(mx)$ will deduce\n\n$$b_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)\\sin(mx)\\diff x$$\n\n\\subsection{Complex Fourier Series}\n\\subsubsection{Definition of Complex Fourier Series}\n\\begin{dft}\n  Let $f$ be a $2\\pi$-periodic function on $\\C$ which is Riemann integrable on $[-\\pi,\\pi]$, then its \\textbf{complex Fourier series} is a Fourier series of the form\n\n  $$\\sum_{-\\infty}^{\\infty}c_{n}e^{inx}$$\n\n  where $\\brc{c_{n}}_{-\\infty}^{\\infty}$ is a \\textbf{bisequence} of complex numbers defined by\n\n  $$c_{n}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)e^{-inx}\\diff x$$\\s\n  \n  for all integers $n$. Moreover, $\\sum_{-\\infty}^{\\infty}c_{n}e^{inx}$ is said to be convergent at $x$ if\n\n  $$\\lim_{N\\to+\\infty}\\sum_{-N}^{N}c_{n}e^{inx}$$\\s\n\n  exists.\n\\end{dft}\\n\n\nNote that for a complex-valued function $f=u+iv$,\n\n$$\\int_{a}^{b}f=\\int_{a}^{b}u+i\\int_{a}^{b}v$$\\s\n\nIn other words, $f$ is said to be integrable if both $u$ and $v$ are integrable.\n\n\\subsubsection{Motivation of Complex Fourier Series}\nRecall the form of a complex Fourier series as\n\n$$f(x)=\\sum_{-\\infty}^{\\infty}c_{n}e^{inx}$$\\s\n\nfor all $x\\in\\C$. If $f$ converges nicely,\n\n$$\\int_{-\\pi}^{\\pi}e^{-imx}\\diff x=\\sum_{-\\infty}^{\\infty}c_{n}\\int_{-\\pi}^{\\pi}e^{i(n-m)x}\\diff x$$\\s\n\nNote that\n\n$$\\int_{-\\pi}^{\\pi}e^{i(n-m)x}\\diff x=\\begin{cases}\n  2\\pi\\erm{if }n=m\\\\\n  0\\erm{if }n\\neq m\n\\end{cases}$$\\s\n\nwhich will deduce\n\n$$c_{n}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)e^{-inx}\\diff x$$\n\n\\subsubsection{Relations between Real and Complex Fourier Series}\nIn this section the relationship between (real) Fourier series and complex Fourier series for a real-valued function $f$ is discussed. Note that\n\n$$\\begin{aligned}[t]\n  c_{n}&=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)e^{-inx}\\diff x\\\\\n  &=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)(\\cos(nx)-i\\sin(nx))\\diff x\\\\\n  &=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)\\cos(nx)\\diff x-\\frac{i}{2\\pi}\\int_{-\\pi}^{\\pi}f(x)\\sin(nx)\\diff x\n\\end{aligned}$$\\s\n\nwhich will deduce\n\n$$c_{n}=\\begin{cases}\n  (a_{n}-ib_{n})/2&\\erm{if }n\\geq 1\\\\\n  0&\\erm{if }n=0\\\\\n  (a_{-n}+ib_{-n})/2&\\erm{if }n\\leq -1\n\\end{cases}$$\\s\n\n\\begin{pst}\n  Let $f$ be a real-valued function, then its complex Fourier coefficient $c_{-n}=\\overline{c_{n}}$.\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $f$ be a $2\\pi$-periodic real function which is differentiable on $[-\\pi,\\pi]$ with $f'$ integrable on $[-\\pi,\\pi]$. Denote the Fourier coefficients of $f$ and $f'$ by $\\brc{a_{n}(f), b_{n}(f); c_{n}(f)}$ and $\\brc{a_{n}(f'), b_{n}(f'); c_{n}(f')}$ respectively, then\n  \n  $$\\begin{cases}\n    a_{n}(f')=nb_{n}(f)\\\\\n    b_{n}(f')=-na_{n}(f)\n  \\end{cases}\\text{ and }c_{n}(f')=inc_{n}(f)$$\n\\end{pst}\\n\n\nNote that one of the advantages of using complex Fourier series is to compute derivatives with more convenience.\n\n\\subsection{Fourier Series and Extensions}\n\\subsubsection{Extensions of Periodic Functions}\nFor any Riemann integrable function $f$ on $[-\\pi,\\pi]$, one can define the Fourier coefficients to form a Fourier series. On the other hand, we can restrict $f$ to $(-\\pi,\\pi]$ and extend periodically to a $2\\pi$-periodic function $\\tilde{f}$ on $\\R$. The function $f$ and its extension $\\tilde{f}$ have the same Fourier series.\\n\n\nHere the $\\sim$ symbol in\n\n$$f(x)\\sim a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\nrepresents $f(x)$ has the Fourier series on the right hand side. The equal sign $=$ is not used since the series may not converge.\\n\n\n\\begin{exm}\n  Let $f(x)=x$ be a function in $[-\\pi,\\pi]$. Find the Fourier series of $f$.\\n\n\n  \\ans The Fourier coefficients are\n\n  $$a_{0}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}x\\diff x=0$$\\s\n\n  $$a_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}x\\cos(nx)\\diff x=0$$\\s\n\n  $$b_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}x\\sin(nx)\\diff x=(-1)^{n+1}\\frac{2}{n}$$\\s\n\n  Therefore\n\n  $$f(x)\\sim\\sum_{n=1}^{\\infty}(-1)^{n+1}\\frac{2}{n}\\sin(nx)$$\\s\n\n  which is a sine series.\n\\end{exm}\\n\n\nWith the example above, the following proposition can be introduced by observation:\\n\n\n\\begin{pst}\n  Let $f$ be a real function, then its Fourier series is a sine series if $f$ is odd, and it is a cosine series if $f$ is even.\n\\end{pst}\\n\n\nNote that the Fourier series may not be the same as the original function, especially when there are discontinuous points like $\\pm\\pi$. Also, the convergence of Fourier series is not clear since some terms like $\\sum(1/n)$ does not converge. \n\n\\subsubsection{Big-O and Little-O Notations}\n\\begin{dft}\n  Let $\\brc{x_{n}}$ be a sequence, then the \\textbf{big-O notation}, denoted by $O$, paired with $x_{n}$ is defined as\n\n  $$x_{n}=O(n^{s})\\Leftrightarrow\\abs{x_{n}}\\leq Cn^{s}$$\\s\n\n  for some constant $C>0$, as $n\\to\\infty$. Similarly, the \\textbf{little-O notation}, denoted by $o$, paired with $x_{n}$ is defined as\n\n  $$x_{n}=o(n^{s})\\Leftrightarrow\\frac{\\abs{x_{n}}}{n^{s}}\\to 0$$\\s\n\n  as $n\\to\\infty$.\n\\end{dft}\\n\n\n\\begin{exm}\n  Find the correlation of\n  \n  $$x_{n}=\\frac{2(-1)^{n+1}}{n}\\sin(nx)$$\\s\n\n  using big-O notation.\\n\n\n  \\ans Since $\\abs{x_{n}}\\leq 2/n$, $x_{n}=O(1/n)$.\n\\end{exm}\\n\n\n\\begin{exm}\n  Find the correlation of\n\n  $$x_{n}=\\log(n)$$\\s\n\n  using little-O notation.\\n\n\n  \\ans Since $\\abs{\\log(n)}/n\\to 0$ as $n\\to\\infty$, $x_{n}=o(n)$.\n\\end{exm}\n\n\\subsubsection{Fourier Series of Unusual Periodic Functions}\nLet $f$ be a $2T$-periodic function. Note that $g(x)=f(Tx/\\pi)$ is a $2\\pi$-periodic function, then\n\n$$g(x)\\sim a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$$\\s\n\nwith\n\n$$a_{0}=\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi}g(x)\\diff x$$\\s\n\n$$a_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}g(x)\\cos(nx)\\diff x$$\\s\n\n$$b_{n}=\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}g(x)\\sin(nx)\\diff x$$\\s\n\nalong with the substitution $y=Tx/\\pi$ implies\n\n$$f(y)\\sim a_{0}+\\sum_{n=1}^{\\infty}\\brr{a_{n}\\cos\\brr{\\frac{n\\pi}{T}y}+b_{n}\\sin\\brr{\\frac{n\\pi}{T}y}}$$\\s\n\nwith\n\n$$a_{0}=\\frac{1}{2T}\\int_{-T}^{T}f(y)\\diff y$$\\s\n\n$$a_{n}=\\frac{1}{T}\\int_{-T}^{T}f(y)\\cos\\brr{\\frac{n\\pi}{T}y}\\diff y$$\\s\n\n$$b_{n}=\\frac{1}{T}\\int_{-T}^{T}f(y)\\sin\\brr{\\frac{n\\pi}{T}y}\\diff y$$\\s\n\nSuch Fourier series is called Fourier series of $2T$-periodic function $f$.\n\n\\subsection{Convergence of Fourier Series}\n\\subsubsection{Riemann-Lebesgue Lemma}\nRecall the definition of a step function on $[-\\pi,\\pi]$ as a function of the form\n\n$$s(x)=\\sum_{j=0}^{N-1}s_{j}\\chi_{I_{j}}$$\\s\n\nwhere $-\\pi=a_{0}<a_{1}<\\cdots<a_{N}=\\pi$, $I_{0}=[a_{0},a_{1}]$ and $I_{j}=(a_{j},a_{j+1}]$ for $1\\leq j\\leq N-1$. The characteristic function (or indicator function)\n\n$$\\chi_{E}=\\begin{cases}\n  1\\erm{if }x\\in E\\\\\n  0\\erm{if }x\\not\\in E\n\\end{cases}$$\\s\n\n\\begin{pst}\n  For every step function $s$ integrable on $[-\\pi,\\pi]$, there exists a constant $C>0$ depending on $s$ such that\n  \n  $$\\abs{a_{n}(s)},\\abs{b_{n}(s)}\\leq\\frac{C}{n}$$\\s\n\n  for all $n\\geq 1$. $a_{n}(s)$ and $b_{n}(s)$ are Fourier coefficients of $s$.\\n\n\n  \\prf Let\n  \n  $$s(x)=\\sum_{j=0}^{N-1}s_{j}\\chi_{I_{j}}$$\\s\n  \n  be the step function, then for $n\\geq 1$,\n\n  $$\\begin{aligned}[t]\n    \\pi a_{n}(s)&=\\int_{-\\pi}^{\\pi}s(x)\\cos(nx)\\diff x\\\\\n    &=\\sum_{j=0}^{N-1}s_{j}\\int_{a_{j}}^{a_{j+1}}\\cos(nx)\\diff x\\\\\n    &=\\sum_{j=0}^{N-1}s_{j}\\frac{\\sin(na_{j+1})-\\sin(na_{j})}{n}\n  \\end{aligned}$$\\s\n\n  which implies $\\abs{a_{n}(s)}\\leq\\frac{C}{n}$. The proof for $\\abs{b_{n}(s)}$ is similar.\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $f$ be integrable on $[-\\pi,\\pi]$, then for all $\\epsilon>0$, there exists a step function $s$ such that $s\\leq f$ on $[-\\pi,\\pi]$ and\n\n  $$\\int_{-\\pi}^{\\pi}(f-s)<\\epsilon$$\\s\n\n  \\prf Since $f$ is Riemann integrable, the function can be approximated with Darboux lower sum. For all $\\epsilon>0$, there exists a partition $-\\pi=a_{0}<a_{1}<\\cdots<a_{N}=\\pi$ such that\n\n  $$\\int_{-\\pi}^{\\pi}f-\\sum_{j=0}^{N-1}m_{j}(a_{j+1}-a_{j})<\\epsilon$$\\s\n\n  where $m_{j}=\\inf\\brc{f(x)\\srm x\\in[a_{j},a_{j+1}]}$. Define the step function\n\n  $$s(x)=\\sum_{j=0}^{N-1}m_{j}\\chi_{I_{j}}$$\\s\n\n  then $s\\leq f$ and\n  \n  $$\\int_{-\\pi}^{\\pi}s(x)\\diff x=\\sum_{j=0}^{N-1}m_{j}(a_{j+1}-a_{j})$$\\s\n\n  implies the result.\n\\end{pst}\\n\n\nWith the propositions above, the \\textbf{Riemann-Lebesgue Lemma} can be introduced:\\n\n\n\\begin{thm}\n  The Fourier coefficients of any $2\\pi$-periodic function $f$ integrable on $[-\\pi,\\pi]$ converge to $0$ as $n\\to\\infty$.\\n\n\n  \\prf By \\rpst[\\sctd{1}], for any $\\epsilon>0$, there exists a step function $s$ such that $s\\leq f$ and\n\n  $$\\int_{-\\pi}^{\\pi}(f-s)<\\frac{\\epsilon}{2}$$\\s\n\n  On the other hand, by \\rpst[\\sctd{2}], there exists $n_{0}>0$ such that\n\n  $$\\abs{a_{n}(s)}<\\frac{\\epsilon}{2}$$\\s\n\n  for all $n\\geq n_{0}$. For instance, $n_{0}=[2C/\\epsilon]+1$ with the constant $C$ in \\rpst[\\sctd{2}]. Note that\n\n  $$\\begin{aligned}[t]\n    \\abs{a_{n}(f)-a_{n}(s)}&=\\frac{1}{\\pi}\\abs{\\int_{-\\pi}^{\\pi}(f-s)(x)\\cos(nx)\\diff x}\\\\\n    &\\leq\\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}(f-s)\\erm{as }f\\geq s\\\\\n    &\\leq\\frac{\\epsilon}{2\\pi}\n  \\end{aligned}$$\\s\n\n  Hence,\n\n  $$\\begin{aligned}[t]\n    \\abs{a_{n}(f)}&\\leq\\abs{a_{n}(s)}-\\abs{a_{n}(f)-a_{n}(s)}\\\\\n    &<\\frac{\\epsilon}{2}+\\frac{\\epsilon}{2\\pi}<\\epsilon\n  \\end{aligned}$$\\s\n\n  for all $n\\geq n_{0}$, which means $a_{n}(f)\\to 0$ as $n\\to\\infty$. The proof for $b_{n}(f)$ is similar to that above.\n\\end{thm}\n\n\\subsubsection{Lipschitz Continuity at Points}\n\\begin{dft}\n  Let $f\\sim a_{0}+\\sum_{n=1}^{\\infty}(a_{n}\\cos(nx)+b_{n}\\sin(nx))$ be a function which has a Fourier series, then the \\textbf{$n$-th partial sum} of Fourier series of $f$, denoted by $(S_{n}f)(x)$, is given by\n\n  $$(S_{n}f)(x)=a_{0}+\\sum_{k=1}^{n}(a_{k}\\cos(kx)+b_{k}\\sin(kx))$$\n\\end{dft}\\n\n\n\\begin{dft}\n  Let $f$ be a function on $[a,b]$, then $f$ is called \\textbf{Lipschitz continuous} at a point $x_{0}\\in[a,b]$ if there exists $L>0$ and $\\delta>0$ such that\n\n  $$\\abs{f(x)-f(x_{0})}\\leq L\\abs{x-x_{0}}$$\\s\n\n  for all $\\abs{x-x_{0}}<\\delta$.\n\\end{dft}\\n\n\nNote that both $L$ and $\\delta$ may depend on the point $x_{0}$. Below is a proposition on extending Lipschitz continuity from a point to an interval:\\n\n\n\\begin{pst}\n  If $f$ is Lipschitz continuous at $x_{0}\\in[a,b]$ and $f$ is bounded on $[a,b]$, then there exists $L'>0$ which may depends on $x_{0}$ such that\n\n$$\\abs{f(x)-f(x_{0})}\\leq L'\\abs{x-x_{0}}$$\\s\n\nfor all $x\\in[a,b]$.\\n\n\n\\prf By \\rdft[\\sctd{1}], there exists $L,\\delta>0$ such that\n\n$$\\abs{f(x)-f(x_{0})}\\leq L\\abs{x-x_{0}}$$\\s\n\nfor all $\\abs{x-x_{0}}<\\delta$. If $\\abs{x-x_{0}}\\geq\\delta$, then\n\n$$\\begin{aligned}[t]\n  \\abs{f(x)-f(x_{0})}&\\leq\\abs{f(x)}+\\abs{f(x_{0})}\\\\\n  &\\leq 2M\\leq \\frac{2M\\abs{x-x_{0}}}{\\delta}\n\\end{aligned}$$\\s\n\nwhere $M=\\sup_{[a,b]}\\abs{f}\\geq 0$. Pick $L'=\\max\\brc{L,2M/\\delta}>0$, then\n\n$$\\abs{f(x)-f(x_{0})}\\leq L'\\abs{x-x_{0}}$$\\s\n\nfor all $x\\in[a,b]$.\n\\end{pst}\n\n\\subsubsection{Dirichlet Kernels}\n\\begin{dft}\n  The \\textbf{Dirichlet kernel}, denoted by $D_{n}(z)$, is defined by\n\n  $$D_{n}(z)=\\begin{cases}\n    (\\sin((n+1/2)z))/(2\\pi\\sin(z/2))\\erm{if }z\\neq 0\\\\\n    (2n+1)/(2\\pi)\\erm{if }z=0\n  \\end{cases}$$\n\\end{dft}\\n\n\n\\begin{pst}\n  Below are the properties of Dirichlet kernels:\n\n  \\begin{alist}\n    \\item Integral of a Dirichlet kernel $\\int_{-\\pi}^{\\pi}D_{n}(z)\\diff z=1$.\n    \\item $D_{n}(z)$ is even, continuous, $2\\pi$-periodic on $[-\\pi,\\pi]$ and\n    \n    $$D_{n}\\brr{\\frac{2k\\pi}{2n+1}}=0$$\\s\n\n    for all $k=-n,-n+1,\\cdots,n$.\n    \\item The maximum\n    \n    $$\\max_{[-\\pi,\\pi]}D_{n}(z)=D_{n}(0)=\\frac{2n+1}{2\\pi}$$\n    \\item For all $0<\\delta<\\pi/2$,\n    \n    $$\\int_{0}^{\\delta}\\abs{D_{n}(z)}\\diff z\\to+\\infty$$\\s\n\n    as $n\\to+\\infty$\n  \\end{alist}\n\n  \\prf\\prt[a]{zr} This can be achieved by integrating\n\n  $$\\int_{-\\pi}^{\\pi}\\brr{\\frac{1}{2}+\\sum_{k=1}^{n}\\cos(kz)}\\diff z$$\\s\n  \n  \\prtc[d]{zr} Let $0<\\delta<\\pi/2$, then for all $n\\in\\N$, there exists $N\\in\\N$ such that\n\n  $$N<\\frac{n+1/2}{\\pi}\\delta\\leq N+1$$\\s\n\n  where $N\\to\\infty$ as $n\\to\\infty$. Note that\n  \n  $$\\begin{aligned}[t]\n    \\int_{0}^{\\delta}\\abs{D_{n}(z)}\\diff z&=\\int_{0}^{\\delta}\\frac{\\abs{\\sin(n+1/2)z}}{2\\pi\\abs{\\sin(z/2)}}\\diff z\\\\\n    &=\\int_{0}^{(n+1/2)\\delta}\\frac{\\abs{\\sin(t)}}{2\\pi\\abs{\\sin(t/(2n+1))}}\\brr{\\frac{2\\diff t}{2n+1}}\\erm{where }t=\\brr{n+\\frac{1}{2}}z\\\\\n    &=\\frac{1}{\\pi}\\int_{0}^{(n+1/2)\\delta}\\frac{\\sin(t)}{t}\\frac{t/(2n+1)}{\\abs{\\sin(t/(2n+1))}}\\diff t\\\\\n    &\\geq\\frac{1}{\\pi}\\int_{0}^{(n+1/2)\\delta}\\frac{\\sin(t)}{t}\\diff t\\erm{since }\\frac{\\sin(x)}{x}<1\\text{ for }0<x\\\\\n    &\\geq\\frac{1}{\\pi}\\int_{0}^{N\\pi}\\frac{\\sin(t)}{t}\\diff t\\\\\n    &=\\frac{1}{\\pi}\\sum_{k=1}^{N}\\int_{(k-1)\\pi}^{k\\pi}\\frac{\\sin(t)}{t}\\diff t\\\\\n    &=\\frac{1}{\\pi}\\sum_{k=1}^{N}\\int_{0}^{\\pi}\\frac{\\abs{\\sin(s)}}{s+(k-1)\\pi}\\diff s\\erm{where }s=t-(k-1)\\pi\\\\\n    &\\geq\\frac{1}{\\pi}\\sum_{k=1}^{N}\\int_{0}^{\\pi}\\frac{\\abs{\\sin(s)}}{k\\pi}\\diff s\\erm{since }t\\leq k\\pi\\\\\n    &=\\frac{1}{\\pi^{2}}\\brr{\\int_{0}^{\\pi}\\abs{\\sin(s)}\\diff s}\\sum_{k=1}^{N}\\frac{1}{k}=\\frac{2}{\\pi^{2}}\\sum_{k=1}^{N}\\frac{1}{k}\n  \\end{aligned}$$\\s\n\n  But since the sum of harmonic series $\\sum_{k=1}^{N}(1/k)$ diverges when $N\\to\\infty$ as $n\\to\\infty$,\n\n  $$\\lim_{n\\to\\infty}\\int_{0}^{\\delta}\\abs{D_{n}(z)}\\diff z=+\\infty$$\n\\end{pst}\\n\n\nWith the definition and properties of Dirichlet kernels, the following proposition can be introduced.\\n\n\n\\begin{pst}\n  Let $f$ be a $2\\pi$-periodic function integrable on $[-\\pi,\\pi]$. Suppose that $f$ is Lipschitz continuous at $x$, then the sequence $\\brc{S_{n}f(x)}$ converges to $f(x)$ as $n\\to+\\infty$.\\n\n\n  \\prf Let $f$ be a function that is Lipschitz continuous at a point $x_{0}\\in[-\\pi,\\pi]$. By splitting\n  \n  $$(S_{n}(f))(x_{0})-f(x_{0})=I_{1}+I_{2}$$\\s\n\n  into integrals $I_{1}$ and $I_{2}$ concentrated in $[-\\delta,\\delta]$ and essentially, outside the interval, respectively. Note that by \\rpst[\\sctd{1}],\n\\end{pst}\\n\n\n\\begin{exm}\n  Let $f(x)=x$ be a $2\\pi$-periodic function integrable on $[-\\pi,\\pi]$. Its Fourier series\n\n  $$x\\sim 2\\sum_{n=1}^{\\infty}\\frac{(-1)^{n+1}}{n}\\sin(nx)$$\\s\n\n  clearly implies that $f(x)$ is Lipschitz continuous at any $x\\in(-\\pi,\\pi)$.\n\\end{exm}\\n\n\n\\begin{pst}\n  Let $f$ be a $2\\pi$-periodic function integrable on $[-\\pi,\\pi]$. Suppose that for $x_{0}\\in[-\\pi,\\pi]$, the following are satisfied:\n\n  \\begin{alist}\n    \\item The left-hand limit and right-hand limit both exist, which is\n    \n    $$f(x^{-}_{0})=\\lim_{x\\to x^{-}_{0}}f(x),f(x^{+}_{0})=\\lim_{x\\to x^{+}_{0}}f(x)$$\n\n    \\item There exists $L>0$ and $\\delta>0$ such that\n    \n    $$\\begin{cases}\n      \\abs{f(x)-f(x^{+}_{0})}\\leq L(x-x_{0})\\erm{where }0<x-x_{0}<\\delta\\\\\n      \\abs{f(x)-f(x^{-}_{0})}\\leq L(x_{0}-x)\\erm{where }0<x_{0}-x<\\delta\n    \\end{cases}$$\n  \\end{alist}\n\n  then\n\n  $$S_{n}f(x)\\to\\frac{f(x^{+}_{0})+f(x^{-}_{0})}{2}$$\\s\n\n  as $n\\to+\\infty$.\n\\end{pst}\\n\n\n\\begin{exm}\n  Let $f(x)=x$ be a $2\\pi$-periodic function integrable on $[-\\pi,\\pi]$, where $f$ is discontinuous at $x=\\pi$. Note that $f(\\pi^{-})=\\pi$ and $f(\\pi^{+})=-\\pi$.\\n\n  \n  Now assume $\\delta=\\frac{\\pi}{2}$. For $0<x-\\pi<\\delta$,\n\n  $$\\begin{aligned}[t]\n    \\abs{f(x)-f(\\pi^{+})}&=\\abs{f(x-2\\pi)-(-\\pi)}\\\\\n    &=\\abs{x-2\\pi+\\pi}\\\\\n    &=x-\\pi\\leq L(x-\\pi)\n  \\end{aligned}$$\\s\n\n  where $L=1$. The approach for $0<\\pi-x<\\delta$ is similar. Therefore, by \\rpst[\\sctd{1}],\n  \n  $$S_{n}f(x)\\to\\frac{f(\\pi^{+})+f(\\pi^{-})}{2}=0$$\\s\n\n  as $n\\to+\\infty$.\n\\end{exm}\n\n\\subsubsection{Lipschitz Condition and Uniform Convergence}\n\\begin{dft}\n  Let $f$ be a function on $[a,b]$, then it is said to satisfy \\textbf{Lipschitz condition} if there exists $L>0$ such that\n\n  $$\\abs{f(x)-f(y)}\\leq L\\abs{x-y}$$\\s\n\n  for all $x,y\\in[a,b]$.\n\\end{dft}\\n\n\nNote that Lipschitz condition is uniform since $L$ is independent of any choice of $x,y$. Also, if $f$ satisfies a Lipschitz condition, $f$ is Lipschitz continuous at every point on $[a,b]$.\\n\n\n\\begin{pst}\n  Let $f$ be a $2\\pi$-periodic function satisfying a Lipschitz condition, then its Fourier series converge uniformly to $f$ itself.\n\\end{pst}\n\n\\subsection{Weierstrass Approximation Theorem}\n\\subsubsection{Piecewise Linear Functions}\nRecall that a continuous function is piecewise linear if there exists a partition such that the function is linear within each subinterval.\\n\n\n\\begin{pst}\n  Let $f$ be a continuous function on $[a,b]$, then for all $\\epsilon>0$, there exists a continuous and piecewise linear function $g$ with $g(a)=f(a)$, $g(b)=f(b)$ such that\n\n  $$\\nrm{f-g}_{\\infty}<\\epsilon$$\\s\n\n  where\n\n  $$\\nrm{f-g}_{\\infty}=\\sup_{[a,b]}\\abs{f(x)-g(x)}$$\n\\end{pst}\n\n\\subsubsection{Trigonometric Polynomials}\n\\begin{dft}\n  A \\textbf{trigonometric polynomial} is of the form $P(\\cos(x),\\sin(x))$ where $P(x,y)$ is a polynomial of $2$ variables.\n\\end{dft}\\n\n\nNote that a trigonometric polynomial is a finite Fourier series, and vice versa.\\n\n\n\\begin{pst}\n  Let $f$ be a continuous function on $[0,\\pi]$, then for all $\\epsilon>0$, there exists a trigonometric polynomial $h$ such that $\\nrm{f-h}_{\\infty}<\\epsilon$.\n\\end{pst}\n\n\\subsubsection{General Theorem}\nBelow is the \\textbf{Weierstrass Approximation Theorem}:\\n\n\n\\begin{thm}\n  Let $f\\in C[a,b]$, then for all $\\epsilon>0$, there exists a polynomial $q$ such that $\\nrm{f-q}_{\\infty}<\\epsilon$.\n\\end{thm}\n\n\\subsection{Mean Convergence of Fourier Series}\n\\subsubsection{Bracket Products}\n\\begin{dft}\n  Let $f,g$ be Riemann integrable functions on $[-\\pi,\\pi]$, then the \\textbf{bracket product} (or \\textbf{$L^{2}$-product}, \\textbf{$L^{2}$ inner product}) of $f$ and $g$ is given by\n\n  $$\\bra{f,g}_{2}=\\int_{-\\pi}^{\\pi}f(x)g(x)\\diff x$$\n\\end{dft}\\n\n\nNote that for complex functions, the bracket product is defined by\n\n$$\\bra{f,g}_{2}=\\int_{-\\pi}^{\\pi}f\\overline{g}$$\\s\n\n\\begin{dft}\n  Let $f,g$ be Riemann integrable functions on $[-\\pi,\\pi]$, then the \\textbf{$L^{2}$-norm} of $f$ is given by\n\n  $$\\nrm{f}_{2}=\\sqrt{\\bra{f,f}_{2}}$$\\s\n\n  Also, the \\textbf{$L^{2}$-distance} between $f$ and $g$ is given by $\\nrm{f-g}_{2}$.\n\\end{dft}\n\n\\subsubsection{Mean Convergence}\n\\begin{dft}\n  Let $f,f_{n}$ be Riemann integrable functions on $[-\\pi,\\pi]$, then $f_{n}\\to f$ in \\textbf{$L^{2}$-sense} if $\\nrm{f_{n}-f}_{2}\\to 0$ as $n\\to\\infty$.\n\\end{dft}\\n\n\nThis definition brings out why such idea is called mean convergence:\n\n$$\\lim_{n\\to\\infty}\\int_{-\\pi}^{\\pi}(f_{n}-f)^{2}\\to 0$$\\s\n\nis actually a variation of root mean square. Note that $L^{2}$-norm and $L^{2}$-distance are not norm and distance in a strict sense since\n\n$$\\begin{cases}\n  \\nrm{f}_{2}=0&\\not\\Rightarrow f=0\\\\\n  \\nrm{f-g}_{2}=0&\\not\\Rightarrow f=g\n\\end{cases}$$\\s\n\nin $R[-\\pi,\\pi]$. It is only true for almost everywhere. Also, although it is not hard to show that $f_{n}\\to f$ uniformly implies $\\nrm{f_{n}-f}_{2}\\to 0$, its converse does not hold. Consider the following counterexample:\\n\n\n\\begin{exm}\n  Let\n\n  $$f_{n}(x)=\\begin{cases}\n    1\\erm{if }x\\in[0,1/n]\\\\\n    0\\erm{otherwise}\n  \\end{cases}$$\\s\n\n  be a function, then $\\nrm{f_{n}}_{2}^{2}=\\int_{-\\pi}^{\\pi}f_{n}^{2}=1/n$, which tends to $0$ as $n\\to\\infty$. In this way, $f_{n}\\to 0$ in $L^{2}$-sense. However, $f_{n}\\not\\to 0$ uniformly or even pointwisely.\n\\end{exm}\n\n\\subsection{Applications to Fourier Series}\n\\subsubsection{Minimizers}\nConsider the functions on $[-\\pi,\\pi]$\n\n$$\\begin{cases}\n  \\varphi_{0}=\\frac{1}{\\sqrt{2\\pi}}\\\\\n  \\varphi_{n}=\\frac{1}{\\sqrt{\\pi}}\\cos(nx)\\\\\n  \\psi_{n}=\\frac{1}{\\sqrt{\\pi}}\\sin(nx)\n\\end{cases}$$\\s\n\nNote that\n\n$$\\begin{cases}\n  \\bra{\\varphi_{m},\\varphi_{n}}_{2}=\\begin{cases}\n    1\\erm{if }m=n\\\\\n    0\\erm{if }m\\neq n\n  \\end{cases}\\\\\n  \\bra{\\psi_{m},\\psi_{n}}_{2}=\\begin{cases}\n    1\\erm{if }m=n\\\\\n    0\\erm{if }m\\neq n\n  \\end{cases}\\\\\n  \\bra{\\varphi_{m},\\psi_{n}}_{2}=0\\erm{for all }m,n\n\\end{cases}$$\\s\n\ntherefore\n\n$$\\brc{\\frac{1}{\\sqrt{2\\pi}},\\frac{1}{\\sqrt{\\pi}}\\cos(nx),\\frac{1}{\\sqrt{\\pi}}\\sin(nx)}_{n=1}^{\\infty}$$\\s\n\ncan be regarded as an orthogonal basis in $R[-\\pi,\\pi]$.\\n\n\n\\begin{dft}\n  The $(2n+1)$ dimensional vector subspace of $R[-\\pi,\\pi]$ spanned by the first $(2n+1)$ trigonometric functions, denoted by $E_{n}$, is defined by\n\n  $$E_{n}=\\mathrm{span}\\brc{\\frac{1}{\\sqrt{2\\pi}},\\frac{1}{\\sqrt{\\pi}}\\cos(kx),\\frac{1}{\\sqrt{\\pi}}\\sin(kx)}_{k=1}^{n}$$\n\\end{dft}\\n\n\nIn general, if there is an orthogonal set (or ortogonal family) $\\brc{\\phi_{n}}_{n=1}^{\\infty}$ in $R[-\\pi,\\pi]$, let\n\n$$S_{n}=\\mathrm{span}\\bra{\\phi_{1},\\phi_{2},\\cdots,\\phi_{n}}$$\\s\n\nbe an $n$-dimensional subspace spanned by the first $n$ functions in the orthogonal set, then for any $f\\in R[-\\pi,\\pi]$, the \\textbf{minimization problem} is\n\n$$\\inf\\brc{\\nrm{f-g}_{2}\\srm g\\in S_{n}}$$\\s\n\n\\begin{pst}\n  The unique minimizer of\n\n  $$\\inf\\brc{\\nrm{f-g}_{2}\\srm g\\in S_{n}}$$\\s\n\n  is attained at the function\n\n  $$g=\\sum_{k=1}^{n}\\bra{f,\\phi_{k}}_{2}\\phi_{k}\\in S_{n}$$\\s\n\n  \\prf Note that to minimize $\\nrm{f-g}_{2}$ is equivalent to minimize $\\nrm{f-g}_{2}^{2}$. For all $g\\in S_{n}$,\n\n  $$g=\\sum_{k=1}^{n}\\beta_{k}\\phi_{k}\\Rightarrow\\nrm{f-g}_{2}^{2}=\\int_{-\\pi}^{\\pi}\\abs{f-\\sum_{k=1}^{n}\\beta_{k}\\phi_{k}}^{2}$$\\s\n\n  Let $\\Phi(\\beta)=\\nrm{f-g}_{2}^{2}$, then\n\n  $$\\begin{aligned}[t]\n    \\Phi(\\beta)&=\\int_{-\\pi}^{\\pi}\\abs{f-\\sum_{k=1}^{n}\\beta_{k}\\phi_{k}}^{2}\\\\\n    &=\\brr{\\int_{-\\pi}^{\\pi}f^{2}}-2\\sum_{k=1}^{\\infty}\\brr{\\frac{\\beta_{k}}{\\sqrt{2}}}\\brr{\\sqrt{2}\\bra{f,\\phi_{k}}_{2}^{2}}+\\sum_{k=1}^{n}\\beta_{k}^{2}\\\\\n    &\\geq\\brr{\\int_{-\\pi}^{\\pi}f^{2}}-\\sum_{k=1}^{\\infty}\\brr{\\frac{\\beta_{k}^{2}}{2}+2\\bra{f,\\phi_{k}}_{2}^{2}}+\\sum_{k=1}^{n}\\beta_{k}^{2}\\erm{since }2ab\\leq a^{2}+b^{2}\\\\\n    &=\\brr{\\int_{-\\pi}^{\\pi}f^{2}}-2\\sum_{k=1}^{n}\\bra{f,\\phi_{k}}_{2}^{2}+\\frac{1}{2}\\sum_{k=1}^{n}\\beta_{k}^{2}\\to\\infty\n  \\end{aligned}$$\\s\n\n  as\n\n  $$\\nrm{\\beta}=\\sqrt{\\sum_{k=1}^{n}\\beta_{k}^{2}}\\to\\infty$$\\s\n\n  Hence $\\Phi(\\beta)$ attains its minimum at some finite point $\\beta$. By some calculus, the minimum required is given by $\\beta_{k}=\\bra{f,\\phi_{k}}_{2}$ for all $1\\leq k\\leq n$.\n\\end{pst}\\n\n\nNote that the minimizer $g$ of $\\nrm{f-g}_{2}$ over $S_{n}$ is called the \\textbf{orthogonal projection} of $f$ on $S_{n}$, denoted by $P_{n}(f)$. With the notation of orthogonal projection,\n\n$$\\mathrm{dist}(f,S_{n})=\\nrm{f,P_{n}(f)}_{2}$$\\s\n\n\\begin{crl}\n  For a $2\\pi$-periodic function $f$ integrable on $[-\\pi,\\pi]$ and $n\\geq 1$, $\\nrm{f-S_{n}(f)}_{2}\\leq\\nrm{f-g}_{2}$ where $S_{n}(f)$ represents the $n$-th partial sum of the Fourier series of $f$, for all\n\n  $$g=\\alpha_{0}+\\sum_{k=1}^{n}(\\alpha_{k}\\cos(kx)+\\beta_{k}\\sin(kx))$$\\s\n\n  with real coefficients.\\n\n\n  \\prf By the definition of Fourier coefficients $S_{n}(f)=P_{n}(f)$ of $E_{n}$,\n\n  $$\\begin{cases}\n    a_{0}=\\frac{1}{\\sqrt{2\\pi}}\\bra{f,\\frac{1}{\\sqrt{2\\pi}}}_{2}\\\\\n    a_{n}\\cos(nx)=\\frac{1}{\\sqrt{\\pi}}\\bra{f,\\frac{1}{\\sqrt{\\pi}}\\cos(nx)}_{2}\\cos(nx)\\\\\n    b_{n}\\sin(nx)=\\frac{1}{\\sqrt{\\pi}}\\bra{f,\\frac{1}{\\sqrt{\\pi}}\\sin(nx)}_{2}\\sin(nx)\n  \\end{cases}$$\n\\end{crl}\n\n\\propdisp\n\\subsubsection{Measure Zeroes of Fourier Series}\n\\begin{thm}\n  Let $f$ be $2\\pi$-periodic integrable function on $[-\\pi,\\pi]$, then the $n$-th partial sum of the Fourier series of $f$ converges to $f$ in $L^{2}$-sense. In other words,\n\n  $$\\lim_{n\\to\\infty}\\nrm{S_{n}(f)-f}_{2}=0$$\\s\n\n  \\prf For any $\\epsilon>0$, there exists a $2\\pi$-periodic Lipschitz continuous function $g$ such that $\\nrm{f-g}_{2}<\\epsilon/2$. This can be achieved by finding a step function approximating $f$. By \\rpst[\\sctd{11}], there exists $N>0$ such that\n\n  $$\\nrm{g-S_{N}(g)}_{\\infty}<\\frac{\\epsilon}{2\\sqrt{2\\pi}}$$\\s\n\n  where $\\nrm{\\cdot}_{\\infty}$ represents the uniform convergence. This induces\n\n  $$\\nrm{g-S_{N}(g)}_{2}=\\sqrt{\\int_{-\\pi}^{\\pi}(g-S_{N}(g))^{2}}\\leq\\sqrt{2\\pi\\nrm{g-S_{n}(g)}_{\\infty}^{2}}=\\frac{\\epsilon}{2}$$\\s\n\n  By the corollary of \\rpst[\\sctd{1}],\n\n  $$\\nrm{f-S_{N}(f)}_{2}\\leq\\nrm{f-S_{N}(g)}_{2}\\leq\\nrm{f-g}_{2}+\\nrm{g-S_{n}(g)}_{2}<\\frac{\\epsilon}{2}+\\frac{\\epsilon}{2}=\\epsilon$$\\s\n\n  Finally, since $E_{N}\\subset E_{n}$ for all $n\\geq N$,\n\n  $$\\nrm{f-S_{n}(f)}_{2}\\leq\\nrm{f-S_{N}(f)}_{2}<\\epsilon$$\\s\n\n  for any $n\\geq N$, thus\n\n  $$\\lim_{n\\to\\infty}\\nrm{S_{n}(f)-f}_{2}=0$$\n\\end{thm}\\n\n\n\\begin{crl}\n  Let $f_{1}$ and $f_{2}$ be $2\\pi$-periodic integrable functions on $[-\\pi,\\pi]$ with the same Fourier series, then $f_{1}=f_{2}$ almost everywhere, or $f_{1}=f_{2}$ except a set of measure zero. Furthermore, if $f_{1}$ and $f_{2}$ are both continuous on $[-\\pi,\\pi]$, then $f_{1}=f_{2}$.\\n\n\n  \\prf Let $f=f_{1}-f_{2}$, then $a_{n}(f)=b_{n}(f)=0$ gives $S_{n}(f)=0$ for any $n\\geq 0$. Therefore\n\n  $$\\lim_{n\\to\\infty}\\nrm{S_{n}(f)-f}_{2}=0\\Rightarrow \\nrm{f}_{2}=0$$\\s\n\n  and by theory of Riemann integrals, $f=0$ almost everywhere. If $f_{1},f_{2}$ are continuous, $f^{2}\\mathrm{cts}\\geq 0\\Rightarrow f^{2}\\equiv 0$.\n\\end{crl}\\n\n\nNote that a set $E$ is said to be measure zero if for any $\\epsilon>0$, there exists countably many intervals $\\brc{I_{k}}$ such that $E\\subset\\bigcup_{k}I_{k}$ and $\\sum_{k}\\abs{I_{k}}<\\epsilon$.\n\n\\subsubsection{Parserval's Identity}\nBelow is the \\textbf{Parserval's Identity}:\\n\n\n\\begin{pst}\n  Let $f$ be a $2\\pi$-periodic function $f$ integrable on $[-\\pi,\\pi]$, then\n\n  $$\\nrm{f}_{2}^{2}=2\\pi a_{0}^{2}+\\pi\\sum_{n=1}^{\\infty}(a_{n}^{2}+b_{n}^{2})$$\\s\n\n  where $a_{0},a_{n},b_{n}$ are Fourier coefficients of $f$.\\n\n\n  \\prf Note that\n\n  $$\\begin{cases}\n    \\sqrt{2\\pi}a_{0}=\\bra{f,\\frac{1}{\\sqrt{2\\pi}}}_{2}\\\\\n    \\sqrt{\\pi}a_{n}=\\bra{f,\\frac{1}{\\sqrt{\\pi}}\\cos(nx)}_{2}\\erm{for all }n\\geq 1\\\\\n    \\sqrt{\\pi}b_{n}=\\bra{f,\\frac{1}{\\sqrt{\\pi}}\\sin(nx)}_{2}\\erm{for all }n\\geq 1\n  \\end{cases}$$\\s\n\n  then by corollary of \\rpst[\\sctd{2}],\n\n  $$\\begin{aligned}[t]\n    \\bra{f,S_{N}(f)}_{2}&=\\bra{(f-S_{N}(f))+S_{N}(f),S_{N}(f)}_{2}\\\\\n    &=\\bra{S_{N}(f),S_{N}(f)}_{2}\\erm{since }(f-S_{N}(f))\\text{ is orthogonal}\\\\\n    &=\\int_{-\\pi}^{\\pi}\\brr{a_{0}+\\sum_{k=1}^{\\infty}a_{k}\\cos(kx)+b_{k}\\sin(kx)}^{2}\\diff x\n  \\end{aligned}$$\\s\n\n  Finally by \\rthm[\\sctd{1}],\n\n  $$\\begin{aligned}[t]\n    0&=\\lim_{N\\to\\infty}\\nrm{f-S_{N}(f)}_{2}^{2}\\\\\n    &=\\lim_{N\\to\\infty}(\\nrm{f}_{2}^{2}-2\\bra{f,S_{N}(f)}_{2}+\\nrm{S_{N}(f)}_{2}^{2})\\\\\n    &=\\lim_{N\\to\\infty}(\\nrm{f}_{2}^{2}-2\\nrm{S_{N}(f)}_{2}^{2}+\\nrm{S_{N}(f)}_{2}^{2})\\\\\n    &=\\lim_{N\\to\\infty}(\\nrm{f}_{2}^{2}-\\nrm{S_{N}(f)}_{2}^{2})\n  \\end{aligned}$$\\s\n\n  therefore\n\n  $$\\nrm{f}_{2}^{2}=\\lim_{N\\to\\infty}\\brr{2\\pi a_{0}^{2}+\\pi\\sum_{n=1}^{N}(a_{n}^{2}+b_{n}^{2})}$$\n\\end{pst}\n\n\\pagebreak\n\n\\section{Metric Spaces}\n\\subsection{Introduction of Metric Spaces}\n\\subsubsection{Definition of Metrics Spaces}\n\\begin{dft}\n  Let $X$ be a nonempty set, then a \\textbf{metric} on $X$ is a function\n\n  $$d:X\\times X\\to[0,+\\infty)$$\\s\n\n  such that the following properties is satisfied for all $x,y,z\\in X$:\n\n  \\begin{alist}\n    \\item Metric is nonnegative, or $d(x,y)\\geq 0$. Equality holds if and only if $x=y$.\n    \\item Metric is symmetric, or $d(x,y)=d(y,x)$.\n    \\item Metric is subadditive (satisfies triangle inequality), or $d(x,y)\\leq d(x,z)+d(z,y)$.\n  \\end{alist}\n\n  The pair $(X,d)$ is called a \\textbf{metric space}.\n\\end{dft}\\n\n\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then the \\textbf{metric ball} of radius $r$ centered at $x$, denoted by $B_{r}(x)$, is defined as\n\n  $$B_{r}(x)=\\brc{y\\in X\\srm d(x,y)<r}$$\n\\end{dft}\n\n\\subsubsection{Examples of Metric Spaces}\n\\begin{exm}\n  Below are some examples of metric spaces:\n\n  \\begin{alist}\n    \\item $(\\R,\\abs{x-y})$ is a metric space.\n    \\item Let $X=\\R^{n}$. Denote the metrics\n    \n    $$\\begin{cases}\n      d_{k}(x,y)=\\sqrt[k]{\\sum\\abs{x_{i}-y_{i}}^{k}}\\\\\n      d_{\\infty}(x,y)=\\max\\abs{x_{i}-y_{i}}\n    \\end{cases}$$\\s\n\n    where $1\\leq i\\leq n$, then $(\\R^{n},d_{1})$, $(\\R^{n},d_{2})$, $(\\R^{n},d_{\\infty})$ are metric spaces.\n    \\item Let $C[a,b]$ be the set of all (real) continuous functions on $[a,b]$ and\n    \n    $$\\begin{cases}\n      d_{k}(f,g)=\\sqrt[k]{\\int_{a}^{b}\\abs{f-g}^{k}}\\\\\n      d_{\\infty}(f,g)=\\max\\brc{\\abs{f(x)-g(x)}\\srm x\\in[a,b]}\n    \\end{cases}$$\\s\n\n    for all $f,g\\in C[a,b]$, then $(C[a,b], d_{1})$, $(C[a,b], d_{2})$, $(C[a,b], d_{\\infty})$ are metric spaces.\n  \\end{alist}\n\\end{exm}\\n\n\n\\begin{exm}\n  Let $X=R[a,b]$ be the set of Riemann integrable functions on $[a,b]$ and\n\n  $$d_{1}(f,g)=\\int_{a}^{b}\\abs{f-g}$$\\s\n\n  However, part (a) of \\rdft[\\sctd{3}] is not satisfied since $d_{1}(f,g)=0$ only implies $f=g$ almost everywhere, but not exactly $f=g$. $d_{1}$ is then not a suitable metric on $R[a,b]$.\\n\n\n  In order to fix this problem, consider $X=R[a,b]/\\sim$ where $\\sim$ is an equivalent relation on $R[a,b]$ defined by\n\n  $$f\\sim g\\Leftrightarrow f=g\\text{ almost everywhere}$$\\s\n\n  Denote\n  \n  $$\\overline{f}=\\brc{g\\in R[a,b]\\srm f\\sim g}$$\\s\n\n  and its corresponding metric\n\n  $$\\tilde{d_{k}}(\\overline{f},\\overline{g})=d_{k}(f,g)$$\\s\n\n  then $(X,\\tilde{d_{1}})$ and $(X,\\tilde{d_{2}})$ are metric spaces.\n\\end{exm}\\n\n\nNote that $\\tilde{d_{2}}$ in the example above is in fact $L^{2}$-distance defined in the last section.\n\n\\subsubsection{Normed Spaces}\n\\begin{dft}\n  Let $X$ be a nonempty set, then a \\textbf{norm} on $X$ is a function\n\n  $$\\nrm{\\cdot}:X\\to[0,+\\infty)$$\\s\n\n  such that the following properties is satisfied for all $x,y\\in X$ and $\\alpha\\in\\R$:\n\n  \\begin{alist}\n    \\item Norm is nonnegative, or $\\nrm{x}\\geq 0$. Equality holds if and only if $x=0$.\n    \\item Norm is absolutely scalable, or $\\nrm{\\alpha x}=\\abs{\\alpha}\\nrm{x}$.\n    \\item Norm is subadditive, or $\\nrm{x+y}\\leq\\nrm{x}+\\nrm{y}$.\n  \\end{alist}\n\n  The pair $(X,\\nrm{\\cdot})$ is called a \\textbf{normed space}. Furthermore, a metric $d$ is said to be \\textbf{induced} by the norm $\\nrm{\\cdot}$ if $d(x,y)=\\nrm{x-y}$.\n\\end{dft}\\n\n\n\\begin{exm}\n  Below are some examples of norms:\n\n  \\begin{alist}\n    \\item Let $\\nrm{x}_{k}=\\sqrt[k]{\\sum\\abs{x_{i}}^{k}}$ and $\\nrm{x}_{\\infty}=\\max\\brc{x_{i}}$, then $\\nrm{\\cdot}_{1}$, $\\nrm{\\cdot}_{2}$ and $\\nrm{\\cdot}_{\\infty}$ are norms on $\\R^{n}$.\n    \\item Let $\\nrm{f}_{k}=\\sqrt[k]{\\int_{a}^{b}\\abs{f}^{k}}$ and $\\nrm{f}_{\\infty}=\\max\\brc{f(x)}$, then $\\nrm{\\cdot}_{1}$, $\\nrm{\\cdot}_{2}$ and $\\nrm{\\cdot}_{\\infty}$ are norms on $C[a,b]$.\n  \\end{alist}\n\\end{exm}\\n\n\nNote that a norm can induce a metric, but not all metrics are induced from norm.\\n\n\n\\begin{exm}\n  Let $X$ be a nonempty set and\n\n  $$d(x,y)=\\begin{cases}\n    1\\erm{if }x\\neq y\\\\\n    0\\erm{if }x=y\n  \\end{cases}$$\\s\n\n  be a metric on $X$. Note that $X$ is not necessary a vector space, so $d$ is not induced by a norm. Moreover, even $X$ is a vector space,\n\n  $$d(\\alpha x,\\alpha y)\\neq\\abs{\\alpha}d(x,y)$$\\s\n\n  when $\\abs{\\alpha}\\neq 1$ and $x\\neq y$.\n\\end{exm}\\n\n\nSuch metric $d$ in the above example is called a \\textbf{discrete metric} on $X$.\n\n\\subsubsection{Metric Subspaces}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then for any nonempty set $Y\\subset X$, $(Y,d)$ is called a \\textbf{metric subspace} of $(X,d)$.\n\\end{dft}\\n\n\nNote that a metric subspace of a normed space may not be also a normed space, only if the subset is also a vector subspace.\n\n\\subsection{Limits and Continuity}\n\\subsubsection{Limits and Convergence in Metric Spaces}\nWith the understanding of metric spaces, one can extend the definition of limits and convergence to any metric space:\\n\n\n\\begin{dft}\n  Let $\\brc{x_{n}}$ be a sequence in a metric space $(X,d)$, then the sequence is said to be \\textbf{converge} to $x\\in X$, denoted by $x_{n}\\to x$, if\n\n  $$\\lim_{n\\to\\infty}d(x_{n},x)=0$$\n\\end{dft}\\n\n\n\\begin{pst}\n  Let $\\brc{x_{n}}$ be a sequence in a metric space $(X,d)$. If $x_{n}\\to x$ and $x_{n}\\to y$, then $x=y$.\n\\end{pst}\\n\n\n\\begin{exm}\n  Below are some examples on convergence in metric spaces:\n\n  \\begin{alist}\n    \\item Convergence in $(\\R^{n},d_{2})$ is the usual convergence in advanced calculus.\n    \\item Convergence in $(C[a,b],d_{\\infty})$ is the uniform convergence of sequence of functions in $C[a,b]$.\n  \\end{alist}\n\\end{exm}\n\n\\subsubsection{Strength of Convergence}\nThere are many metrics suitable for the same nonempty set $X$, so it is natural to think of comparing among those metrics.\\n\n\n\\begin{dft}\n  Let $d$ and $\\rho$ be different metrics defined on $X$, then $\\rho$ is said to be \\textbf{stronger than} $d$ (or $d$ is \\textbf{weaker than} $\\rho$) if there exists a constant $C>0$ such that\n\n  $$d(x,y)\\leq C\\rho(x,y)$$\\s\n  \n  for all $x,y\\in X$. $d$ and $\\rho$ are \\textbf{equivalent} to each other if $d$ is stronger and weaker than $\\rho$ at the same time. In other words, there exists $C_{1},C_{2}>0$ such that\n\n  $$d(x,y)\\leq C_{1}\\rho(x,y)\\leq C_{2}d(x,y)$$\\s\n\n  for all $x,y\\in X$.\n\\end{dft}\\n\n\nNote that the equivalence of metrics defined above is an equivalent relation.\\n\n\n\\begin{pst}\n  Let $d$ and $\\rho$ be different metrics defined on $X$. If $\\rho$ is stronger than $d$ and a sequence $\\brc{x_{n}}$ converges in $(X,\\rho)$, then the sequence also converges in $(X,d)$ with the same limit. If $\\rho$ is equivalent to $d$, then $\\brc{x_{n}}$ converges in $(X,\\rho)$ if and only if it converges in $(X,d)$ also.\n\\end{pst}\\n\n\n\\begin{exm}\n  Recall the metrics $d_{1}$, $d_{2}$ and $d_{\\infty}$ on $\\R^{n}$, then\n\n  $$\\begin{cases}\n    d_{1}(x,y)\\leq nd_{\\infty}(x,y)\\leq nd_{1}(x,y)\\\\\n    d_{2}(x,y)\\leq\\sqrt{n}d_{\\infty}(x,y)\\leq\\sqrt{n}d_{2}(x,y)\n  \\end{cases}$$\\s\n\n  shows that $d_{1}$, $d_{2}$ and $d_{\\infty}$ are equivalent metrics.\n\\end{exm}\\n\n\n\\begin{exm}\n  Recall the metrics $d_{1}$ and $d_{\\infty}$ on $C[a,b]$, then\n\n  $$d_{1}(f,g)\\leq(b-a)d_{\\infty}(f,g)$$\\s\n\n  shows that $d_{\\infty}$ is stronger than $d_{1}$. However, $d_{1}$ is not stronger than $d_{\\infty}$, so $d_{1}$ and $d_{\\infty}$ are not equivalent.\n\\end{exm}\n\n\\subsubsection{Continuity in Metric Spaces}\n\\begin{dft}\n  Let $f:(X,d)\\to(Y,\\rho)$ be a mapping between two metric spaces, then $f$ is \\textbf{continuous} at a point $x\\in X$ if $f(x_{n})\\to f(x)$ in $(Y,\\rho)$ whenever $x_{n}\\to x$ in $(X,d)$. $f$ is continuous on a set $E\\in X$ if it is continuous at every point in $E$.\n\\end{dft}\\n\n\n\\begin{pst}\n  Let $f:(X,d)\\to(Y,\\rho)$ be a mapping between two metric spaces and $x_{0}\\in X$ be a point, then $f$ is continuous at $x_{0}$ if and only if for any $\\epsilon>0$, there exists $\\delta>0$ such that\n\n  $$\\rho(f(x),f(x_{0}))<\\epsilon\\erm{for all }\\brc{x\\in X\\srm d(x,x_{0})<\\delta}$$\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $f:(X,d)\\to(Y,\\rho)$ and $g:(Y,\\rho)\\to(Z,m)$ be mappings between metric spaces, then if $f$ is continuous at $x$ and $g$ is continuous at $f(x)$, then $g\\circ f$ is also continuous at $x$. Similarly, if $f$ is continuous at $X$ and $g$ is continuous at $Y$, then $g\\circ f$ is also continuous at $X$.\n\\end{pst}\\n\n\n\\begin{exm}\n  Let $(X,d)$ be a metric space and $A\\subset X$ be a nonempty set. Further define $\\rho_{A}:X\\to\\R$ by\n\n  $$\\rho_{A}(x)=\\underset{y\\in A}{\\inf}d(y,x)$$\\s\n\n  which is the shortest distance from $x$ to the subset $A$. Show that\n\n  $$\\abs{\\rho_{A}(x)-\\rho_{A}(y)}\\leq d(x,y)$$\\s\n\n  for any $x,y\\in X$.\\n\n\n  \\ans For fixed $x,y\\in X$, along with the definition of $\\rho_{A}$, for all $\\epsilon>0$, there exists $z\\in A$ such that $\\rho_{A}(y)+\\epsilon>d(z,y)$. Hence\n\n  $$\\rho_{A}(x)\\leq d(z,x)\\leq d(z,y)+d(y,x)<d(y,x)+\\rho_{A}(y)+\\epsilon$$\n\n  rearranging the equation gives\n\n  $$\\rho_{A}(x)-\\rho(A)(y)<d(x,y)+\\epsilon$$\\s\n\n  Note that since $x$ and $y$ are interchangable, and $\\epsilon$ is arbitrary,\n\n  $$\\abs{\\rho_{A}(x)-\\rho_{A}(y)}\\leq d(x,y)$$\n\\end{exm}\\n\n\nIn fact the example above shows that $\\rho_{A}$ is continuous (and even Lipschitz continuous) since $d(x_{n},x)\\to 0$ implies $\\rho_{A}(x_{n})\\to\\rho_{A}(n)$. This actually mean there are many continuous functions on a metric space.\\n\n\nFor simplicity, define\n\n$$\\begin{cases}\n  d(x,F)=\\inf\\brc{d(x,y)\\srm y\\in F}\\\\\n  d(E,F)=\\inf\\brc{d(x,y)\\srm x\\in E,y\\in F}\n\\end{cases}$$\\s\n\nfor subsets $E$ and $F$.\n\n\\subsection{Open and Closed Sets}\n\\subsubsection{Open Sets}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a set $G\\in X$ is called an \\textbf{open set} if for any $x\\in G$, there exists $\\epsilon>0$ such that\n\n  $$B_{\\epsilon}(x)=\\brc{y\\srm d(x,y)<\\epsilon}\\subset G$$\n\\end{dft}\\n\n\nNote that $\\epsilon$ may vary depending on the choice of $x$, and the empty set $\\phi$ is considered an open set. Therefore, the proposition applies:\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space and $G_{\\alpha}$ be a collection of open sets, then the following are true:\n\n  \\begin{alist}\n    \\item $X$ and $\\phi$ are open sets.\n    \\item Arbitrary union of open sets $\\bigcup_{\\alpha}G_{\\alpha}$ is an open set.\n    \\item Finite intersection of open sets $\\bigcap_{i=1}^{n}G_{i}$ is an open set.\n  \\end{alist}\n\\end{pst}\n\n\\subsubsection{Closed Sets}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a set $F\\in X$ is called an \\textbf{closed set} if $X\\setminus F$ is an open set.\n\\end{dft}\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space and $F_{\\alpha}$ be a collection of closed sets, then the following are true:\n\n  \\begin{alist}\n    \\item $X$ and $\\phi$ are closed sets.\n    \\item Finite union of closed sets $\\bigcup_{j=1}^{n}F_{j}$ is an closed set.\n    \\item Arbitrary intersection of closed sets $\\bigcap_{\\alpha}F_{\\alpha}$ is an closed set.\n  \\end{alist}\n\\end{pst}\\n\n\n\\begin{crl}\n  Let $(X,d)$ be a metric space, then $X$ and $\\phi$ are both open and closed.\n\\end{crl}\n\n\\subsubsection{Applications of Open and Closed Sets}\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then a sequence $\\brc{x_{n}}$ converges to $x$ if and only if for all open set $G$ containing $x$, there exists $n_{0}$ such that $x_{n}\\in G$ for all $n\\geq n_{0}$.\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then a set $A\\subset X$ is closed if and only if whenever $\\brc{x_{n}}\\subset A$ and $x_{n}\\to x$ as $n\\to\\infty$ implies that $x\\in A$.\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $f:(X,d)\\to(Y,\\rho)$ be a mapping between metric spaces, then the following applies:\n\n  \\begin{alist}\n    \\item $f$ is continuous at $x$ if and only if for all open set $G\\subset Y$ containing $f(x)$, $f^{-1}(G)$ contains $B_{\\epsilon}(x)$ for some $\\epsilon>0$.\n    \\item $f$ is continuous at $x$ if and only if for all open set $G\\subset Y$, $f^{-1}(G)$ is open in $X$.\n  \\end{alist}\n\\end{pst}\\n\n\nIn this case, $f$ is also continuous at $x$ if and only if for all closed set $F\\subset Y$, $f^{-1}(F)$ is closed in $X$.\n\n\\propdisp\n\\subsection{Points in Metric Space}\n\\subsubsection{Boundary Points and Closures}\n\\begin{dft}\n  Let $E$ be a set in a metric space $(X,d)$, then a point $x\\in X$ (which is not necessary in $E$) is called a \\textbf{boundary point} of $E$ if for all open set $G\\subset X$ containing $x$,\n\n  $$G\\cap E\\neq\\phi\\text{ and }G\\setminus E\\neq\\phi$$\\s\n\n  In other words, this is satisfied when $G\\cap(X\\setminus E)\\neq\\phi$. The \\textbf{boundary} of $E$, denoted by $\\partial E$, is the set of boundary points of $E$. The \\textbf{closure} of $E$, denoted by $\\overline{E}$, is defined as $\\overline{E}=E\\cup\\partial E$.\n\\end{dft}\\n\n\nFor the conditions of a boundary point in the definition above, it suffices to check $G$ of the form $B_{\\epsilon}(x)$ for all small $\\epsilon>0$, or even $B_{1/n}(x)$ for all $n\\geq 1$. Also note that $X$ and $X\\setminus E$ shares the same boundary no matter the choice of $E$, or\n\n$$\\partial E=\\partial X\\setminus E\\erm{for all }E\\subset X$$\\s\n\n\\subsubsection{Properties of Boundaries and Closures}\n\\begin{pst}\n  Below are some properties of boundaries and closures:\n\n  \\begin{alist}\n    \\item The boundary of an empty set is an empty set, or $\\partial\\phi=\\phi$.\n    \\item For all $E\\subset X$, $\\partial E$ is a closed set.\n    \\item If $E$ is a closed set, $\\overline{E}=E$.\n  \\end{alist}\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $E$ be a subset of a metric space $(X,d)$, then the following applies:\n\n  \\begin{alist}\n    \\item $x\\in\\overline{E}$ if and only if $B_{r}(x)\\cap E\\neq\\phi$ for all $r>0$.\n    \\item If $A\\subset B$, $\\overline{A}\\subset\\overline{B}$ for all $A,B\\subset(X,d)$.\n    \\item $\\overline{E}$ is closed.\n    \\item $\\overline{E}$ is the smallest closed set containing $E$, or $\\overline{E}=\\cap\\brc{G\\subset E\\srm G\\text{ is closed}}$.\n  \\end{alist}\n\\end{pst}\n\n\\subsubsection{Interior Points}\n\\begin{dft}\n  Let $E$ be a subset of a metric space $(X,d)$, then a point $x$ is called an \\textbf{interior point} of $E$ if there exists an open set $G$ such that $x\\in G$ and $G\\subset E$. The \\textbf{interior} of $E$, denoted by $E^{0}$, is the set of interior points of $E$.\n\\end{dft}\\n\n\n\\begin{pst}\n  Below are the properties of interiors:\n\n  \\begin{alist}\n    \\item Interior of $E$, $E^{0}$ is open.\n    \\item Interior of $E$ is the set without boundary, or $E^{0}=E\\setminus\\partial E$.\n    \\item Interior of $E$, $E^{0}=X\\setminus\\overline{X\\setminus E}$.\n    \\item Interior of $E$, $E^{0}=\\cup\\brc{G\\subset E\\srm G\\text{ is open}}$.\n  \\end{alist}\n\\end{pst}\n\n\\subsection{Elementary Inequalities for Functions}\n\\subsubsection{Young's Inequality}\n\\begin{thm}\n  By \\textbf{Young's Inequality}, for $a,b>0$ and $p>1$,\n\n  $$ab\\leq\\frac{a^{p}}{p}+\\frac{b^{q}}{q}\\erm{with }\\frac{1}{p}+\\frac{1}{q}=1$$\\s\n\n  Equality holds when $a^{p}=b^{q}$.\n\\end{thm}\\n\n\nNote that $q=\\frac{p}{p-1}>1$ is called the \\textbf{conjugate} of $p$. Also specifically if $p=2$, the inequality reduces to $2ab\\leq a^{2}+b^{2}$.\n\n\\subsubsection{Holder's Inequality}\nFor the following inequality, denote the norm\n\n$$\\nrm{f}_{p}=\\brr{\\int_{a}^{b}\\abs{f(x)}^{p}\\diff x}^{1/p}$$\\s\n\n\\begin{thm}\n  Let $f,g\\in R[a,b]$ be Riemann integrable functions and $p>1$, then by \\textbf{Holder's Inequality},\n\n  $$\\int_{a}^{b}\\abs{f(x)g(x)}\\diff x\\leq\\brr{\\int_{a}^{b}\\abs{f(x)}^{p}\\diff x}^{1/p}\\brr{\\int_{a}^{b}\\abs{f(x)}^{q}\\diff x}^{1/q}$$\\s\n\n  where $q$ is the conjugate of $p$. Equality holds when one of the following conditions is satisfied:\n\n  \\begin{alist}\n    \\item $f$ or $g$ equals to $0$ almost everywhere.\n    \\item There exists a constant $\\lambda>0$ such that $\\abs{g(x)}^{q}=\\lambda\\abs{f(x)}^{p}$ almost everywhere.\n  \\end{alist}\n\\end{thm}\\n\n\nNote that Holder's Inequality can be written in norm form $\\nrm{fg}_{1}=\\nrm{f}_{p}\\nrm{g}_{q}$. Holder's Inequality also holds for limiting cases $(p,q)\\to(1,\\infty)$ and $(p,q)\\to(\\infty,1)$.\n\n\\subsubsection{Minkowski's Inequality}\n\\begin{thm}\n  By \\textbf{Minkowski's Inequality}, for any $f,g\\in R[a,b]$ and $p>1$,\n  \n  $$\\nrm{f+g}_{p}\\leq\\nrm{f}_{p}+\\nrm{g}_{p}$$\\s\n\n  Equality holds when one of the following conditions is satisfied:\n\n  \\begin{alist}\n    \\item $f$ or $g$ equals to $0$ almost everywhere.\n    \\item $\\nrm{f}_{p},\\nrm{g}_{p}>0$ and there exists a constant $\\lambda>0$ such that $g(x)=\\lambda f(x)$ almost everywhere.\n  \\end{alist}\n\\end{thm}\n\n\\pagebreak\n\n\\section{Contraction Mapping Principle}\n\\subsection{Complete Metric Space}\n\\subsubsection{Definition of Complete Metric Space}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a sequence $\\brc{x_{n}}$ in $(X,d)$ is a \\textbf{Cauchy sequence} if for any $\\epsilon>0$, there exists $n_{0}$ such that $d(x_{n},x_{m})<\\epsilon$ for all $n,m>n_{0}$.\n\\end{dft}\\n\n\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then the metric space is \\textbf{complete} if every Cauchy sequence in the metric space converges. A subset $E$ is complete if the induce metric subspace $(E,d)$ with $d=d\\!\\mid_{E\\times E}$ is complete. In other words, every Cauchy sequence in $E$ converges with limit in $E$.\n\\end{dft}\\n\n\nNote that convergent sequence is a Cauchy sequence.\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then the following applies:\n\n  \\begin{alist}\n    \\item Every complete set in $X$ is closed.\n    \\item If $X$ is complete, then every closed set in $X$ is complete.\n  \\end{alist}\n\\end{pst}\\n\n\n\\begin{exm}\n  Below are the examples of complete metric space:\n\n  \\begin{alist}\n    \\item $(\\R,\\text{standard})$ is complete.\n    \\item $[a,b]$, $(-\\infty,b]$ and $[a,\\infty)$ are complete.\n  \\end{alist}\n\n  Below are the counterexamples of complete metric space:\n\n  \\begin{alist}\n    \\item $[a,b)$ where $b$ is finite, is not complete since $x_{n}=b-1/n\\to b\\not\\in[a,b)$.\n    \\item $\\Q$ is not complete.\n  \\end{alist}\n\\end{exm}\n\n\\subsubsection{Completion of Metric Spaces}\n\\begin{dft}\n  A metric space $(X,d)$ is said to be \\textbf{isometrically embedded} in metric space $(Y,\\rho)$ if there exists a mapping $\\Phi:X\\to Y$ such that $d(x,y)=\\rho(\\Phi(x),\\Phi(y))$. If such mapping exists, $\\Phi$ is called an \\textbf{isometric embedding} (or a \\textbf{metric preserving map}) from $(X,d)$ to $(Y,\\rho)$.\n\\end{dft}\\n\n\nNote that $\\Phi$ must be injective and continuous.\n\n\\begin{dft}\n  Let $(X,d)$ and $(Y,\\rho)$ be metric spaces, then $(Y,\\rho)$ is called a completion of $(X,d)$ if the following statements are satisfied:\n\n  \\begin{alist}\n    \\item $(Y,\\rho)$ is complete.\n    \\item There exists an isometric embedding $\\Phi$ such that the closure $\\overline{\\Phi(X)}=Y$.\n  \\end{alist}\n\\end{dft}\\n\n\n\\begin{exm}\n  Let $(X,d)=(\\Q,\\text{induced metric})$ and $(Y,\\rho)=(\\R,\\text{standard})$. Since $\\Q\\subset\\R$, $(Y,\\rho)$ is complete. Further let $\\Phi:(X,d)\\to(Y,\\rho)$ where $\\Phi(q)=q$, since $\\Q$ is dense in $\\R$, $\\overline{\\Phi(\\Q)}=\\overline{\\Q}=\\R$. Therefore, $(Y,\\rho)$ is a completion of $(X,d)$.\n\\end{exm}\\n\n\n\\begin{thm}\n  Every metric space has a completion.\n\\end{thm}\\n\n\nNote that the definition of isometric embedding can be extended to bijection as below:\\n\n\n\\begin{dft}\n  Let $(X,d)$ and $(Y,\\rho)$ be metric spaces, then they are called \\textbf{isometric} if there exists a bijective isometric embedding between $(X,d)$ and $(Y,\\rho)$.\n\\end{dft}\\n\n\nNote that the inverse of a bijective isometric embedding is also an isometric embedding. Also, the two metric spaces are regarded as the same if they are isometric.\\n\n\n\\begin{thm}\n  If metric spaces $(Y,\\rho)$ and $(Y',\\rho')$ are both completions of a metric space $(X,d)$, then $(Y,\\rho)$ and $(Y',\\rho')$ are isometric. In other words, completion is unique up to isometry.\n\\end{thm}\n\n\\subsection{Introduction to Contraction Mapping Principle}\n\\subsubsection{General Theorem}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a map $T:(X,d)\\to (X,d)$ is called a \\textbf{contraction} if there exists a constant $\\gamma\\in(0,1)$ such that\n  \n  $$d(Tx,Ty)\\leq\\gamma d(x,y)$$\\s\n\n  for all $x,y\\in X$. A point $x\\in X$ is called a \\textbf{fixed point} of $T$ if $Tx=x$.\n\\end{dft}\\n\n\nNote that $Tx$ is the notation for $T(x)$ but not the multiplication. With the definition of a contraction, below is the \\textbf{Contraction Mapping Principle} (or the \\textbf{Banach Fixed Point Theorem}):\\n\n\n\\begin{thm}\n  Every contraction in a complete metric space admit a fixed point.\n\\end{thm}\n\n\\subsubsection{Perturbation of Identity}\n\\begin{dft}\n  A normed space $(X,\\nrm{\\cdot})$ is a \\textbf{Banach space} if it is complete as a metric space with respect to the induced metric $d(x,y)=\\nrm{x-y}$ for all $x,y\\in X$.\n\\end{dft}\n\n\\begin{exm}\n  Below are some examples of Banach space:\n\n  \\begin{alist}\n    \\item $(\\R^{n},\\nrm{\\cdot}_{p})$ is a Banach space if $p>1$.\n    \\item $(C[a,b],\\nrm{\\cdot}_{\\infty})$ is a Banach space.\n  \\end{alist}\n\\end{exm}\n\n\\begin{thm}\n  Let $(X,\\nrm{\\cdot})$ be a Banach space, and $\\Phi:\\overline{B_{r}(x_{0})}\\to X$ satisfies $\\Phi(x_{0})=y_{0}$. Suppose that $\\Phi=\\mathrm{Id}_{X}+\\Psi$ such that there exists a constant $\\gamma\\in(0,1)$ such that\n\n  $$\\nrm{\\Psi(x_{2})-\\Psi(x_{1})}\\leq\\gamma\\nrm{x_{2}-x_{1}}$$\\s\n\n  for all $x_{1},x_{2}\\in\\overline{B_{r}(x_{0})}$, then by \\textbf{Perturbation of Identity}, for all $y\\in\\overline{B_{R}(y_{0})}$ where $R=(1-\\gamma)r$, there exists unique $x\\in\\overline{B_{r}(x_{0})}$ such that $\\Phi(x)=y$.\n\\end{thm}\n\n\\begin{exm}\n  Show that $3x^{4}-x^{2}+x=-0.05$ has a real root.\\n\n\n  \\prf Notice that $3x^{4}-x^{2}+x=0$ has a root $x=0$. Let $\\Phi(x)=x+\\Psi(x)$ where $\\Psi(x)=3x^{4}-x^{2}$, then $\\Phi(0)=0$. For $x_{1},x_{2}\\in\\overline{B_{r}(0)}$,\n\n  $$\\begin{aligned}[t]\n    \\abs{\\Psi(x_{1})-\\Psi(x_{2})}&=\\abs{3x_{1}^{4}-x_{1}^{2}-3x_{2}^{4}+x_{2}^{2}}\\\\\n    &=\\abs{3(x_{1}^{4}-x_{2}^{4})-(x_{1}^{2}-x_{2}^{2})}\\\\\n    &=\\abs{3(x_{1}^{3}+x_{1}^{2}x_{2}+x_{2}^{2}x^{1}+x_{2}^{3})-(x_{1}+x_{2})}\\abs{x_{1}-x_{2}}\\\\\n    &=\\abs{12r^{3}+2r}\\abs{x_{1}-x_{2}}\n  \\end{aligned}$$\\s\n\n  Choose $r>0$ such that $\\gamma=12r^{3}+2^{r}<1$ and $R=(1-\\gamma)r\\geq 0.05$ so that $-0.05\\in\\overline{B_{R}(0)}$. Pick $r=1/4$, then $\\gamma=11/16$ and $R=5/64$. By Perturbation of Identity, for all $y\\in\\overline{B_{R}(0)}$, there exists $x\\in\\overline{B_{r}(0)}$ such that $\\Phi(x)=y$. Therefore, there exists a real root for $3x^{4}-x^{2}+x=-0.05$ since $-0.05\\in\\overline{B_{R}(0)}$.\n\\end{exm}\\n\n\nThe example above can be summarized into the following proposition:\\n\n\n\\begin{pst}\n  Let $\\Phi(x)=x+\\Psi(x)$ where $\\Psi(x):U\\to\\R^{n}$ be a $C^{1}$-function on some open set $U\\subset\\R^{n}$ containing $0$, such that\n\n  $$\\Psi(0)=0\\text{ and }\\lim_{x\\to 0}\\frac{\\partial\\Psi_{i}}{\\partial x_{j}}(x)=0$$\\s\n\n  for all $i,j$, then there exists $r>0$ and $R>0$ such that for all $y\\in B_{R}(0)$, $\\Phi(x)=y$ has a unique solution $x\\in B_{r}(0)$.\n\\end{pst}\n\n\\subsection{Inverse Function Theorem}\n\\subsubsection{Introduction to Inverse Function Theorem}\nRecall the chain rule: let $G:U\\subset\\R^{n}\\to\\R^{m}$ and $F:V\\subset\\R^{m}\\to\\R^{l}$ be differentiable functions where $U,V$ open in $\\R^{n},\\R^{m}$ respectively, and $G(U)\\subset V$. Then $H=F\\circ G:U\\to\\R^{l}$ differentiable and $DH(x)=DF(G(x))DG(x)$ where\n\n$$DG(x)=\\brr{\\frac{\\partial G_{i}}{\\partial x_{j}}(x)}_{i,j}$$\\s\n\nand similarly for $DF$ and $DH$. Besides the proposition is required:\\n\n\n\\begin{pst}\n  Let $F:B\\to\\R^{n}$ be $C^{1}$ function, where $B$ is a ball in $\\R^{n}$, then for any $x_{1},x_{2}\\in B$,\n\n  $$F(x_{1})-F(x_{2})=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))\\diff t}\\cdot(x_{1}-x_{2})$$\\s\n\n  in component form $F=(F_{1},\\cdots,F_{n})$. In other words,\n\n  $$F_{i}(x_{1})-F_{i}(x_{2})=\\sum_{j=1}^{n}\\brr{\\int_{0}^{1}\\frac{\\partial F_{i}}{\\partial x_{j}}(x_{2}+t(x_{1}-x_{2}))\\diff t}(x_{1}-x_{2})_{j}$$\n\\end{pst}\\n\n\nFinally, recall that if $F:U\\subset\\R^{n}\\to\\R^{m}$ be differentiable at a point $p$ in an open set $U$ of $\\R^{n}$, then\n\n$$F(p+x)-F(p)=DF(p)x+o(\\abs{x})$$\\s\n\nfor all $x=(x_{1},\\cdots,x_{n})$ sufficiently small (or $\\abs{x}$ small) where $o(\\abs{x})$ is a remaining term such that\n\n$$\\frac{o(\\abs{x})}{\\abs{x}}\\to 0\\text{ as }\\abs{x}\\to 0$$\\s\n\n\\begin{dft}\n  The condition in Inverse Function Theorem that $DF(x_{0})$ is invertible is called the \\textbf{nondegeneracy condition}.\n\\end{dft}\\n\n\nNote that nondegeneracy condition is necessary for the differentiability of local inverse.\\n\n\n\\begin{pst}\n  Let $F:U\\subset\\R^{n}\\to\\R^{n}$ be a $C^{1}$ function where $U$ is an open set and $x_{0}\\in U$. Suppose there exists open $V$ such that $x_{0}\\in V\\subset U$ and $F\\!\\mid\\!_{V}$ has a differentiable inverse, then $DF(x_{0})$ is nonsingular (or invertible).\n\\end{pst}\\n\n\nBelow is the \\textbf{Inverse Function Theorem}:\\n\n\n\\begin{thm}\n  Let $F:U\\to\\R^{n}$ be a $C^{1}$ map from an open set $U\\to\\R^{n}$. Suppose $x_{0}\\in U$ and $DF(x_{0})$ is invertible (as a matrix or linear transformation), then there exists open sets $V,W$ containing $x_{0},F(x_{0})$ respectively such that the restriction of $F$ on $V$ is a bijection onto $W$ with a $C^{1}$ inverse.\\n\n  \n  Moreover, the inverse is $C^{k}$ when $F$ is $C^{k}$ where $1\\leq k\\leq\\infty$, in $V$.\\n\n\n  \\prf\\prt[a]{zr} Consider the special case where $x_{0}=0,y_{0}=F(x_{0})=F(0)=0$, then $DF(0)=I$, which is the identity. Let $\\Psi(x)=-x+F(x)$. As $0\\in U$ and $U$ is open, there exists $r_{0}>0$ such that $\\overline{B_{r_{0}}(0)}\\subset U$. Then\n\n  $$\\Psi(x_{1})-\\Psi(x_{2})=-x_{1}+F(x_{1})+x_{2}-F(x_{2})$$\\s\n\n  By \\rpst[\\sctd{3}],\n\n  $$\\begin{aligned}[t]\n    \\Psi(x_{1})-\\Psi(x_{2})&=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))\\diff t}\\cdot(x_{1}-x_{2})-(x_{1}-x_{2})\\\\\n    &=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))\\diff t-I}\\cdot(x_{1}-x_{2})\\\\\n    &=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))-DF(0)\\diff t}\\cdot(x_{1}-x_{2})\n  \\end{aligned}$$\\s\n\n  Since $F$ is $C^{1}$, for all $\\epsilon>0$, there exists $0<r\\leq r_{0}$ such that\n\n  $$\\nrm{DF(x)-DF(0)}<\\epsilon$$\\s\n\n  for all $x\\in\\overline{B_{r}(0)}$, where\n\n  $$\\nrm{(b_{ij})}=\\sqrt{\\sum_{i,j}b_{ij}^{2}}$$\\s\n\n  for any $n\\times n$ matrix $(b_{ij})$.\\n\n  \n  Since $\\overline{B_{r}(0)}$ is convex, $x_{1},x_{2}\\in\\overline{B_{r}(0)}$ implies $x_{2}+t(x_{1}-x_{2})\\in\\overline{B_{r}(0)}$. Hence for all $\\epsilon>0$, there exists $0<r\\leq r_{0}$ such that\n\n  $$\\nrm{DF(x_{2}+t(x_{1}-x_{2}))-DF(0)}<\\epsilon$$\\s\n\n  for all $x_{1},x_{2}\\in\\overline{B_{r}(0)}$ and $t\\in(0,1)$. Therefore choosing $\\epsilon=1/2$ gives\n\n  $$\\abs{\\Psi(x_{1})-\\Psi(x_{2})}\\leq\\frac{1}{2}\\abs{x_{1}-x_{2}}$$\\s\n\n  for all $x_{1},x_{2}\\in\\overline{B_{r}(0)}$.\\n\n\n  \\prtc[b]{zr} Choose $r>0$ as in Part (a), then for all $y\\in B_{r/2}(0)$, there exists $x\\in B_{r}(0)$ such that $F(x)=y$. This is true because of Perturbation of Identity (\\rthm[\\sctd{6}]) with $\\epsilon=1/2$. The local inverse $G$ of $F$,\n\n  $$G:B_{r/2}(0)\\to G(B_{r/2}(0))\\subset B_{r}(0)$$\\s\n\n  satisfies\n\n  $$\\abs{G(y_{1})-G(y_{2})}\\leq\\frac{1}{1-\\epsilon}\\abs{y_{1}-y_{2}}=2\\abs{y_{1}-y_{2}}$$\\s\n\n  for all $y_{1},y_{2}\\in B_{r/2}(0)$ with $G(B_{r/2}(0))$ open in $B_{r}(0)$.\\n\n\n  \\prtc[c]{zr} Since $DF(0)=I$, assume that $DF(x)$ is invertible for all $x\\in B_{r}(0)$ for $r>0$ given in Part (a). Further let $W=B_{r/2}(0)=B_{R}(0)$, and $V=G(W)\\ni 0$, then $G:W\\to V$ (and similarly $F:V\\to W$). If $G$ is differentiable, by chain rule $DF(G(y))DG(y)=I$ for all $y\\in W$. Rewriting the equation gives $DG(y)=(DF)^{-1}(G(y))$.\\n\n\n  For any $y_{1}\\in W$ such that $y_{1}+y\\in W$,\n\n  $$y=(y_{1}+y)-y_{1}=F(G(y_{1}+y))-F(G(y_{1}))$$\\s\n\n  let $x_{1}=G(y_{1}+y)$ and $x_{2}=G(y_{1})$, then by \\rpst[\\sctd{3}],\n\n  $$\\begin{aligned}[t]\n    y&=F(x_{1})-F(x_{2})=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))\\diff t}\\cdot(x_{1}-x_{2})\\\\\n    &=\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))-DF(x_{2})\\diff t}\\cdot(x_{1}-x_{2})+DF(x_{2})(x_{1}-x_{2})\n  \\end{aligned}$$\\s\n\n  Hence\n\n  $$\\begin{aligned}[t]\n    (DF)^{-1}(x_{2})y&=(DF)^{-1}(x_{2})\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))-DF(x_{2})\\diff t}\\cdot(x_{1}-x_{2})\\\\\n    &+(x_{1}-x_{2})\n  \\end{aligned}$$\\s\n\n  In other words, $G(y_{1}+y)-G(y_{1})=(DF)^{-1}(G(y_{1}))y+R$ where\n\n  $$R=(DF)^{-1}(x_{2})\\brr{\\int_{0}^{1}DF(x_{2}+t(x_{1}-x_{2}))-DF(x_{2})\\diff t}\\cdot(x_{1}-x_{2})$$\\s\n\n  By Part (b), $\\abs{x_{1}-x_{2}}\\leq 2\\abs{y}$, so $\\abs{x_{1}-x_{2}}\\to 0$ as $\\abs{y}\\to 0$ and\n\n  $$\\frac{\\abs{R}}{\\abs{y}}\\leq 2\\nrm{(DF)^{-1}(x_{2})}\\int_{0}^{1}\\nrm{DF(x_{2})-DF(x_{2}+t(x_{1}-x_{2}))}\\diff t$$\\s\n\n  With the assumption that $F$ is $C^{1}$,\n\n  $$\\lim_{\\abs{y}\\to 0}\\frac{\\abs{R}}{\\abs{y}}=0$$\\s\n\n  Therefore $G(y_{1}+y)-G(y)=(DF)^{-1}(G(y_{1}))y+o(\\abs{y})$ which implies $G$ is differentiable at $y_{1}\\in W$ and $DG(y_{1})=(DF)^{-1}(G(y_{1}))$.\\n\n\n  Finally, for the special case, it is assumed that $DF$ is continuous and invertible on $B_{r}(0)$, then by linear algebra $(DF)^{-1}$ is also continuous. Then $DG(y)=(DF)^{-1}(G(y))$ is also continuous, and implies $G$ is $C^{1}$. Using induction and differentiating the identity $DG(y)=(DF)^{-1}(G(y))$ will finish the fact that $F$ is $C^{k}$ implies $G$ is $C^{k}$.\n\\end{thm}\\n\n\n\\subsubsection{Diffeomorphisms}\n\\begin{dft}\n  Let $F:V\\to W$ be a $C^{k}$ map where $V$ and $W$ are open sets in $\\R^{n}$, then $F$ is called a \\textbf{$C^{k}$-diffeomorphism} if $F^{-1}$ exists and is also $C^{k}$.\n\\end{dft}\\n\n\nWith the definition of diffeomorphisms, the Inverse Function Theorem can be rephrased as follows:\n\n\\begin{thm}\n  Let $F:U\\to\\R^{n}$ be a $C^{k}$ map from an open set $U\\to\\R^{n}$. Suppose $x_{0}\\in U$ and $DF(x_{0})$ is invertible (as a matrix or linear transformation), then $F$ is a $C^{k}$-diffeomorphism between some open sets $V,W$ of $x_{0},F(x_{0})$ respectively.\n\\end{thm}\\n\n\nAlso, if $F:V\\to W$ is a $C^{k}$-diffeomorphism, then for all function $\\varphi:W\\to\\R$, there corresponds a function $\\psi=\\varphi\\circ F:V\\to\\R$. Conversely, for all function $\\psi=V\\to\\R$, there corresponds a function $\\varphi=\\psi\\circ F^{-1}:W\\to\\R$. Moreover, $\\varphi$ is $C^{k}$ if and only if $\\psi$ is $C^{k}$. Thus every $C^{k}$-diffeomorphism gives rise to a \\textbf{local $C^{k}$-change of coordinates}.\n\n\\subsubsection{Examples of Inverse Function Theorem}\nBelow are some examples about the Inverse Function Theorem:\\n\n\n\\begin{exm}\n  Let $F:(0,\\infty),(-\\infty,\\infty)\\to\\R^{2}$ such that $F(r,\\theta)=(r\\cos(\\theta),r\\sin(\\theta))$, then\n  \n  $$DF=\\begin{rmatrix}\n    \\cos(\\theta) & -r\\sin(\\theta)\\\\\n    \\sin(\\theta) & r\\cos(\\theta)\n  \\end{rmatrix}$$\\s\n\n  is invertible for all $(r,\\theta)$. By the Inverse Function Theorem, $F$ is locally invertible at every point $(r,\\theta)\\in(0,\\infty)\\times(-\\infty,\\infty)$. However, $F$ is not globally invertible as $F(r,\\theta+2\\pi)=F(r,\\theta)$ implies it is not injective.\n\\end{exm}\\n\n\n\\begin{exm}\n  Let $U$ be an open interval $(a,b)\\in\\R$, then a $C^{1}$ function $f:(a,b)\\to\\R$ with $f'\\neq 0$ implies $f$ is strictly increasing or decreasing, so global inverse exists. Therefore $1$-dimensional case has stronger result than higher dimensions.\n\\end{exm}\n\n\\subsubsection{Implicit Function Theorem}\nA theorem similar to Inverse Function Theorem is the \\textbf{Implicit Function Theorem}:\\n\n\n\\begin{thm}\n  Let $U$ be an open set in $\\R^{n}\\times\\R^{m}$, and $F:U\\to\\R^{m}$ is a $C^{1}$ map. Suppose that $(x_{0},y_{0})\\in U$ satisfies $F(x_{0},y_{0})=0$ and $D_{y}F(x_{0},y_{0})$ is invertible in $\\R^{m}$, then the following applies:\n\n  \\begin{alist}\n    \\item There exists an open set of the form $V_{1}\\times V_{2}\\in U$ containing $(x_{0},y_{0})$ and a $C^{1}$ map\n    \n    $$\\varphi:V_{1}\\subset\\R^{n}\\times V_{2}\\subset\\R^{m}$$\\s\n    \n    with $\\varphi(x_{0})=y_{0}$ such that $F(x,\\varphi(x))=0$ for all $x\\in V_{1}$.\n    \\item $\\varphi:V_{1}\\to V_{2}$ is $C^{k}$ when $F$ is $C^{k}$ where $1\\leq k\\leq\\infty$.\n    \\item Assume $DF_{y}$ is invertible in $V_{1}\\times V_{2}$, then if $\\psi:V_{1}\\to V_{2}$ is another $C^{1}$ map satisfying $F(x,\\psi(x))=0$, then $\\psi\\equiv\\varphi$.\n  \\end{alist}\n\\end{thm}\\n\n\nNote that if\n\n$$F=\\begin{rmatrix}\n  F_{1}(x_{1},\\cdots,x_{n},y_{1},\\cdots,y_{m})\\\\\n  \\vdots\\\\\n  F_{m}(x_{1},\\cdots,x_{n},y_{1},\\cdots,y_{m})\n\\end{rmatrix}$$\\s\n\nthen\n\n$$D_{y}F=\\begin{rmatrix}\n  \\partial F_{1}/\\partial y_{1} & \\cdots & \\partial F_{1}/\\partial y_{m}\\\\\n  \\vdots & \\ddots & \\vdots\\\\\n  \\partial F_{m}/\\partial y_{1} & \\cdots & \\partial F_{m}/\\partial y_{m}\n\\end{rmatrix}$$\\s\n\nis an $m\\times m$ matrix and can be regarded as a linear transformation from $\\R^{m}$ to $\\R^{m}$. In general, for a map $F$ such that $DF(x_{0},y_{0})$ has rank $m$, then one can rearrange the independent variables to make the $m\\times m$ surmatrix corresponding to the last $m$ columns of the Jacobian matrix invertible, which is the situation in the theorem. Hence the condition $DF_{y}(x_{0},y_{0})$ is invertible in the Implicit Function Theorem can be generalized to $\\mathrm{rank}DF(x_{0},y_{0})=m$.\n\n\\subsection{Picard-Lindelof Theorem}\n\\subsubsection{Initial Value Problems}\n\\begin{dft}\n  Let $f$ be a function defined on\n\n$$R=[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$$\\s\n\nwhere $(t_{0},x_{0})\\in\\R^{2}$ and $a,b>0$. An \\textbf{initial value problem} (or \\textbf{Cauchy problem}) is of the form\n\n$$\\begin{cases}\n  \\diff x/\\diff t=f(t,x)\\\\\n  x(t_{0})=x_{0}\n\\end{cases}$$\n\\end{dft}\\n\n\nThis means one has to find $x(t)$ defined in an interval\n\n$$x:[t_{0}-a',t_{0}+a']\\to[x_{0}-b,x_{0}+b]$$\\s\n\nfor some $0<a'\\leq a$ such that $x(t)$ is differentiable, $x(t_{0})=x_{0}$ and\n\n$$\\frac{\\diff x}{\\diff t}(t)=f(t,x(t))$$\\s\n\nfor all $t\\in[t_{0}-a',t_{0}+a']$.\\n\n\n\\begin{exm}\n  Consider the initial value problem\n\n  $$\\begin{cases}\n    \\diff x/\\diff t=1+x^{2}\\\\\n    x(0)=0\n  \\end{cases}$$\\s\n\n  Note that $f(t,x)=1+x^{2}$ is smooth on $[-a,a]\\times[-b,b]$ for any $a,b>0$, but the solution $x(t)=\\tan(t)$ is defined only on $(-\\pi/2,\\pi/2)$. Therefore, even for a nice function $f$, it is still possible that $a'<a$.\n\\end{exm}\n\n\\subsubsection{Picard-Lindelof Theorem for Differential Equations}\nRecall the defintion of Lipschitz condition:\\n\n\n\\begin{dft}\n  Let $f$ be a function defined in $R:[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$, then $f$ satisfies the Lipschitz condition (uniform in $t$) if there exists a Lipschitz constant $L>0$ such that for all $(t,x_{1}),(t,x_{2})\\in R$,\n\n  $$\\abs{f(t,x_{1})-f(t,x_{2})}\\leq L\\abs{x_{1}-x_{2}}$$\n\\end{dft}\\n\n\nAlso recall the properties related to Lipschitz condition:\\n\n\n\\begin{pst}\n  The following statements are true:\n\n  \\begin{alist}\n    \\item $f(t,\\cdot)$ is Lipschitz continuous in $x$ for all $t\\in[t_{0}-a,t_{0}+a]$.\n    \\item If $L$ is a Lipschitz constant for $f$, then any $L'>L$ is also a Lipschitz constant.\n    \\item Continuity does not imply Lipschitz continuity. For example, $f(t,x)=tx^{1/2}$ is continuous but not Lipschitz continuous near $0$.\n    \\item If $R=[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$ and $f(t,x):R\\to\\R$ is $C^{1}$, then $f(t,x)$ satisfies the Lipschitz condition. In fact, for some $y\\in[x_{0}-b,x_{0}+b]$,\n    \n    $$\\abs{f(t,x_{1})-f(t,x_{2})}=\\abs{\\frac{\\partial f}{\\partial x}(t,y)(x_{2}-x_{1})}$$\\s\n\n    Hence $\\abs{f(t,x_{1})-f(t,x_{2})}\\leq L\\abs{x_{1}-x_{2}}$ for\n    \n    $$L=\\max\\brc{\\abs{\\frac{\\partial f}{\\partial x}(t,x)}\\srm (t,x)\\in R}$$\n  \\end{alist}\n\\end{pst}\\n\n\n\\begin{pst}\n  Under assumption of \\rthm[\\sctd{1}], every solution $x$ of the initial value problem from $[t_{0}-a',t_{0}+a']$ to $[x_{0}-b,x_{0}+b]$ satisfies the equation\n\n  $$x(t)=x_{0}+\\int_{t_{0}}^{t}f(t,x(t))\\diff t$$\\s\n\n  Conversely, every $x(t)\\in C[t_{0}-a',t_{0}+a']$ satisfying the equation above is $C^{1}$ and solves the initial value problem.\\n\n\n  \\prf This is a result of Fundamental Theorem of Calculus.\n\\end{pst}\\n\n\nBelow is the \\textbf{Picard-Lindelof Theorem}:\\n\n\n\\begin{thm}\n  Let $f$ be a continuous function on $R:[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$ where $(t_{0},x_{0})\\in\\R^{2}$ and $a,b>0$ If $f$ satisfies Lipschitz condition on $R$ (uniform in $t$), then there exists $a'\\in(0,a]$ and $x\\in C^{1}[t_{0}-a',t_{0}+a']$ such that\n\n  $$x_{0}-b\\leq x(t)\\leq x_{0}+b$$\\s\n\n  for all $t\\in[t_{0}-a',t_{0}+a']$ and solving the initial value problem. Furthermore, $x$ is the unique solution in $[t_{0}-a',t_{0}+a']$.\\n\n\n  \\prf For $a'>0$ to be chosen later, let\n\n  $$X=\\brc{\\varphi\\in C[t_{0}-a',t_{0}+a']\\srm\\varphi(t_{0})=x_{0},\\varphi(t)\\in[x_{0}-b,x_{0}+b]}$$\\s\n\n  with uniform metric $d_{\\infty}$ on $X$. Note that $X$ is a closed subset in the complete metric space $(C[t_{0}-a',t_{0}+a'],d_{\\infty})$, so $(X,d_{\\infty})$ is complete.\\n\n\n  Define $T$ on $X$ by\n\n  $$(T\\varphi)(t)=x_{0}+\\int_{t_{0}}^{t}f(s,\\varphi(s))\\diff s$$\\s\n\n  Note that it is well-defined since $\\varphi(s)\\in[x_{0}-b,x_{0}+b]$. To show $T\\varphi\\in X$, one requires $(T\\varphi)(t)\\in[x_{0}-b,x_{0}+b]$. Let $M=\\sup\\brc{\\abs{f(t,x)}\\srm (t,x)\\in R}$, then for all $t\\in[t_{0}-a',t_{0}+a']$,\n\n  $$\\begin{aligned}[t]\n    \\abs{(T\\varphi)(t)-x_{0}}&=\\abs{\\int_{t_{0}}^{t}f(s,\\varphi(s))\\diff s}\\\\\n    &\\leq M\\abs{t-t_{0}}\\leq Ma'\n  \\end{aligned}$$\\s\n\n  Choose $0<a'\\leq b/M$ gives $\\abs{(T\\varphi)(t)-x_{0}}\\leq b$ and so $T\\varphi\\in X$. Notice that $T:X\\to X$ is a mapping from $(X,d_{\\infty})$ to itself. For contraction,\n\n  $$\\begin{aligned}[t]\n    \\abs{(T\\varphi_{1}-T\\varphi_{2})(t)}&=\\abs{(x_{0}+\\int_{t_{0}}^{t}f(s,\\varphi_{1}(s))\\diff s)-(x_{0}+\\int_{t_{0}}^{t}f(s,\\varphi_{2}(s))\\diff s)}\\\\\n    &\\leq\\int_{t_{0}}^{t}\\abs{f(s,\\varphi_{1}(s))-f(s,\\varphi_{2}(s))}\\diff s\\\\\n    &\\leq L\\int_{t_{0}}^{t}\\abs{\\varphi_{1}(s)-\\varphi_{2}(s)}\\diff s\\\\\n    &\\leq L\\abs{t-t_{0}}\\underset{[t_{0}-a',t_{0}+a']}{\\sup}\\brc{\\varphi_{1}(s)-\\varphi_{2}(s)}\\\\\n    &\\leq La'd_{\\infty}(\\varphi_{1},\\varphi_{2})\n  \\end{aligned}$$\\s\n\n  Therefore if $La'=\\gamma<1$, $T$ is a contraction since $d_{\\infty}(T\\varphi_{1},T\\varphi_{2})\\leq\\gamma d_{\\infty}(\\varphi_{1},\\varphi_{2})$.\\n\n\n  In conclusion, if $0<a'<\\min\\brc{a,b/M,1/L}$, then $T$ is a contraction on a complete metric space. By Contraction Mapping Principle, $T$ admits a unique fixed point $x(t)\\in X$.\n\\end{thm}\\n\n\nNote that the existence part of Picard-Lindelof Theorem still holds with $f(t,x)$ being continuous only. However, the solution may not be unique. Consider the following example:\\n\n\n\\begin{exm}\n  Let $f(t,x)=\\abs{x}^{1/2}$ on $\\R\\times\\R$. Note that $f$ is continuous but not Lipschitz continuous. Then the initial value problem\n\n  $$\\begin{cases}\n    \\diff x/\\diff t=\\abs{x}^{1/2}\\\\\n    x(0)=0\n  \\end{cases}$$\\s\n\n  has solutions\n  \n  $$x_{1}=0,x_{2}=\\frac{1}{4}\\abs{t}t$$\\s\n  \n  for all $t\\in\\R$.\n\\end{exm}\\n\n\nOn the other hand, uniqueness of Picard-Lindelof Theorem holds regardless of the size of the interval of existence.\n\n\\subsubsection{Picard-Lindelof Theorem for Systems}\n\\begin{thm}\n  Consider the initial value problem\n\n  $$\\begin{cases}\n    \\diff\\mathbf{x}/\\diff t=\\mathbf{f}(t,\\mathbf{x})\\\\\n    \\mathbf{x}(t_{0})=\\mathbf{x}_{0}\n  \\end{cases}$$\\s\n\n  where\n\n  $$\\mathbf{x}(t)=\\begin{rmatrix}\n    x_{1}(t)\\\\\n    \\vdots\\\\\n    x_{n}(t)\n  \\end{rmatrix}\\in[x_{1}-b,x_{1}+b]\\times\\cdots\\times[x_{n}-b,x_{n}+b]$$\\s\n\n  $$\\mathbf{x}_{0}=\\begin{rmatrix}\n    x_{1}\\\\\n    \\vdots\\\\\n    x_{n}\n  \\end{rmatrix},\\mathbf{f}(t,x)=\\begin{rmatrix}\n    f_{1}(t,x)\\\\\n    \\vdots\\\\\n    f_{n}(t,x)\n  \\end{rmatrix}\\in C^{1}(R)$$\\s\n\n  with\n\n  $$R=[t_{0}-a,t_{0}+a]\\times[x_{1}-b,x_{1}+b]\\times\\cdots\\times[x_{n}-b,x_{n}+b]$$\\s\n\n  satisfying the Lipschitz condition (uniform in $t$),\n\n  $$\\abs{\\mathbf{f}(t,\\mathbf{x})-\\mathbf{f}(t,\\mathbf{y})}\\leq L\\abs{\\mathbf{x}-\\mathbf{y}}$$\\s\n\n  for all $(t,\\mathbf{x}),(t,\\mathbf{y})\\in R$ and some constant $L>0$. There exists a unique solution $\\mathbf{x}\\in C^{1}[t_{0}-a',t_{0}+a']$ with\n\n  $$\\mathbf{x}(t)\\in[x_{1}-b,x_{1}+b]\\times\\cdots\\times[x_{n}-b,x_{n}+b]$$\\s\n\n  for all $t\\in[t_{0}-a',t_{0}+a']$ to the initial value problem, where $a'$ satisfies\n\n  $$0<a'<\\min\\brc{a,\\frac{b}{M},\\frac{1}{L}}$$\\s\n\n  with\n\n  $$M=\\underset{j=1,\\cdots,n}{\\max}\\underset{R}{\\sup}\\abs{f_{j}(t,\\mathbf{x})}$$\n\\end{thm}\\n\n\nNote that the Picard-Lindelof Theorem for systems can be applied to initial value problems for higher order ordinary differential equations:\n\n$$\\begin{cases}\n  \\diff^{m}x/\\diff t^{m}=f(t,x,\\diff x/\\diff t,\\cdots,\\diff^{m-1}x/\\diff t^{m-1})\\\\\n  x(t_{0})=x_{0}\\\\\n  \\diff x/\\diff t(t_{0})=x_{1}\\\\\n  \\vdots\\\\\n  \\diff^{m-1}x/\\diff t^{m-1}=x_{m-1}\n\\end{cases}$$\\s\n\nby letting\n\n$$\\mathbf{x}=\\begin{rmatrix}\n  x\\\\\n  \\diff x/\\diff t\\\\\n  \\vdots\\\\\n  \\diff^{m-1}x/\\diff t^{m-1}\n\\end{rmatrix}$$\\s\n\nthen\n\n$$\\frac{\\diff\\mathbf{x}}{\\diff t}=\\begin{rmatrix}\n  \\diff x/\\diff t\\\\\n  \\diff^{2}x/\\diff t^{2}\\\\\n  \\vdots\\\\\n  \\diff^{m}x/\\diff t^{m}\n\\end{rmatrix}=\\mathbf{f}(t,\\mathbf{x})$$\\s\n\nwith\n\n$$\\mathbf{x}(t_{0})=\\begin{rmatrix}\n  x_{0}\\\\\n  x_{1}\\\\\n  \\vdots\\\\\n  x_{m-1}\n\\end{rmatrix}$$\n\n\\pagebreak\n\n\\section{Space of Continuous Functions}\n\\subsection{Arzela-Ascoli Theorem}\n\\subsubsection{Compact Sets}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then the vector space of all bounded continuous functions is denoted by\n\n  $$C_{b}(X)=\\brc{f\\in C(X)\\srm\\abs{f(x)}\\leq M,\\forall x\\in X,\\exists M}$$\n\\end{dft}\\n\n\nIt is simple to see that $C_{b}(X)\\subset C(X)$, where $C(X)$ is the set of continuous functions on $X$.\\n\n\n\\begin{exm}\n  If $G$ is a nonempty bounded open set in $\\R^{n}$, then $C_{b}(\\overline{G})=C(\\overline{G})$ as $\\overline{G}$ is closed and bounded, then $f\\in C(\\overline{G})$ has to be bounded.\n\\end{exm}\\n\n\nRecall that a norm $\\nrm{\\cdot}$ on a real vector space $X$ is defined by the following properties:\n\n\\begin{alist}\n  \\item $\\nrm{x}\\geq 0$ is nonnegative, and $\\nrm{x}=0$ if and only if $x=0$.\n  \\item $\\nrm{\\alpha x}=\\abs{\\alpha}\\nrm{x}$ for all $\\alpha\\in\\R$.\n  \\item Triangle inequality holds, or $\\nrm{x+y}\\leq\\nrm{x}+\\nrm{y}$\n\\end{alist}\n\nA vector space with norm $(X,\\nrm{\\cdot})$ is called a norm space. Note that a norm space has a natural metric $d(x,y)=\\nrm{x-y}$.\\n\n\n\\begin{dft}\n  Let $C_{b}(X)$ be the vector space of all bounded continuous functions, then the \\textbf{supnorm} is a norm on $C_{b}(X)$ defined by\n\n  $$\\nrm{f}_{\\infty}=\\underset{x\\in X}{\\sup}\\abs{f(x)}$$\n\\end{dft}\\n\n\nIt is always assumed $C_{b}(X)$ with metric $d_{\\infty}(f,g)=\\nrm{f-g}_{\\infty}$ given by the supnorm.\\n\n\n\\begin{pst}\n  $(C_{b}(X),d_{\\infty})$ is a complete metric space, for any metric space $(X,d)$.\n\\end{pst}\\n\n\nNote that $(C_{b}(X),d_{\\infty})$ is a Banach space since it is a complete normed vector space. $C_{b}(X)$ is usually of infinite dimensional (for example $X=\\R^{n}$ or a subset with nonempty interior in $\\R^{n}$ like $X=[0,1]$), but it also could be of finite dimensional (for example $X=\\brc{p_{1},\\cdots,p_{n}}$ as a finite set of discrete metrics, which gives $X\\to\\R^{n}$ a linear bijection).\\n\n\nA reason for studying $C_{b}(X)$ instead of $C(X)$ is the fact that $C(X)$ may contain unbounded function and the supnorm is not defined (for example $X=\\R$). However, in some cases, it is still possible to define a metric on $C(X)$:\\n\n\n\\begin{exm}\n  Let $X=\\R^{n}$ and $\\overline{B_{n}(0)}=\\brc{\\abs{x}\\leq n}$ for all positive integers $n$. For all $f\\in C(\\R^{n})$, define\n\n  $$d(f,g)=\\sum_{n=1}^{\\infty}\\frac{1}{2^{n}}\\frac{\\nrm{f-g}_{\\infty,\\overline{B_{n}(0)}}}{1+\\nrm{f-g}_{\\infty,\\overline{B_{n}(0)}}}$$\\s\n\n  where $\\nrm{\\cdot}_{\\infty,\\overline{B_{n}(0)}}$ is the supnorm on the closed ball $\\overline{B_{n}(0)}$, then $d$ is a complete metric on $C(\\R^{n})$.\n\\end{exm}\\n\n\nFinally, recall the Bolzano-Weierstrass Theorem in $\\R^{n}$:\\n\n\n\\begin{thm}\n  Every bounded sequence has a convergent subsequence. Similarly, every bounded set contains a convergent sequence.\n\\end{thm}\n\n$C_{b}(X)$ may not have Bolzano-Weierstrass property. Consider the following example:\\n\n\n\\begin{exm}\n  Observe that $C_{b}([0,1])=C[0,1]$. Let $f_{n}(x)=x^{n}$ where $x\\in[0,1]$ for all $n$, then $\\nrm{f_{n}}_{\\infty}=1$. The pointwise limit\n\n  $$f_{n}(x)\\to\\begin{cases}\n    1\\erm{if }x=1\\\\\n    0\\erm{otherwise}\n  \\end{cases}$$\\s\n\n  implies that no subsequence converges in $C_{b}[0,1]$.\n\\end{exm}\\n\n\nBecause of this, further condition are required to find convergent sequences in subsets of $C_{b}(X)$.\\n\n\n\\begin{dft}\n  Let $(X,d)$ be a metric space. A set $E\\subset X$ is called a \\textbf{precompact} set if every sequence in $E$ contains a convergent subsequence with limit in $X$ (which is not necessary in $E$). If the limit is further restricted within $E$, then $E$ is called a \\textbf{compact} set.\n\\end{dft}\\n\n\n\\begin{pst}\n  A compact set is a closed precompact set.\\n\n  \n  \\prf Let $(X,d)$ be a metric space and $\\brc{x_{n}}\\subset E$ be a sequence in $E\\subset X$. If $E$ is precompact, there exists a subsequence $\\brc{x_{n_{j}}}$ with limit $z\\in X$. If $E$ is closed, the limit $z\\in E$, which implies compactness.\n\\end{pst}\\n\n\nAlso recall that by Bolzano-Weierstrass Theorem, $E\\subset\\R^{n}$ is precompact implies $E$ is bounded. Therefore $E$ is compact implies $E$ is closed and bounded.\n\n\\propdisp\n\\subsubsection{Equicontinuity}\n\\begin{dft}\n  Let $(X,d)$ be a metric space. A subset $C$ of $C(X)$ is said to be \\textbf{equicontinuous} if for all $\\epsilon>0$, there exists $\\delta>0$ such that $\\abs{f(x)-f(y)}<\\epsilon$ for all $f\\in C$ and $x,y\\in X$ where $d(x,y)<\\delta$.\n\\end{dft}\\n\n\nIn fact, equicontinuity is based on uniform continuity, but at the same time extends $\\delta$ to fulfill every function $f\\in C$. Therefore, equicontinuity implies every function in $C$ is uniformly continuous. Then, it is simple to see that if $C$ is equicontinuous, any $C'\\subset C$ is also equicontinuous.\\n\n\nThere are other ways to show that a set is equicontinuous. Recall that a function $f$ is Holder continuous if there exists a Holder exponent $\\alpha\\in(0,1)$ such that\n\n$$\\abs{f(x)-f(y)}\\leq L\\abs{x-y}^{\\alpha}$$\\s\n\nfor some constant $L$. $f$ is Lipschitz continuous if the equation holds for $\\alpha=1$. A set $C$ is equicontinuous too if every function $f\\in C$ is Holder continuous or Lipschitz continuous.\n\nAnother method for equicontinuity requires the following definition:\\n\n\n\\begin{dft}\n  A set $C$ is said to be \\textbf{convex} (in $\\R^{n}$) if $x+t(y-x)\\in C$ for all $x,y\\in C$ and $t\\in[0,1]$.\n\\end{dft}\\n\n\n\\begin{pst}\n  Let $C$ be a subset of $C(\\overline{G})$ where $\\overline{G}$ is a convex in $\\R^{n}$. Suppose that each function in $C$ is differentiable and there is a uniform bound on their partial derivatives:\n\n  $$\\nrm{\\frac{\\partial f}{\\partial x_{i}}}_{\\infty}\\leq M$$\\s\n\n  for all $f\\in C(\\overline{G})$ and $i$, then $C$ is equicontinuous.\n\\end{pst}\\n\n\n\\begin{pst}\n  Let $A=\\brc{z_{j}}$ be a countable set and $f_{n}:A\\to\\R$ where $n=1,2,\\cdots$ be a sequence of functions defined on $A$. Suppose for each $z_{j}\\in A$, $\\brc{f_{n}(z_{j})}$ is a bounded sequence in $\\R$, then there exists a subsequence $\\brc{f_{n_{k}}}$ of $\\brc{f_{n}}$ such that for all $z_{j}\\in A$, $\\brc{f_{n_{k}}(z_{j})}$ is convergent.\n\\end{pst}\n\n\\subsubsection{Ascoli's Theorem}\nBelow is the \\textbf{Ascoli's Theorem}:\\n\n\n\\begin{thm}\n  Suppose $G$ is a bounded nonempty open set in $\\R^{m}$, then a set $\\mathcal{E}\\subset C(\\overline{G})=C_{b}(\\overline{G})$ is precompact if $\\mathcal{E}$ is bounded (in supnorm) and equicontinuous.\n\\end{thm}\\n\n\nNote that Ascoli's Theorem remains valid for bounded and equicontinuous subsets of $C(G)$ where $G$ is not necessary to take closure. This is because equicontinuity implies uniform continuity of $G$, which can be further extended to uniform continuity of $\\overline{G}$. However, boundedness of the domain $\\overline{G}$ cannot be removed:\\n\n\n\\begin{exm}\n  Let $\\overline{G}=[0,\\infty)\\subset\\R$, then take $\\varphi\\in C^{1}[0,1]$ such that $\\varphi\\not\\equiv 0$ and $\\varphi(x)=0$ when $x\\in[0,1]\\setminus[1/2,3/4]$. Further define\n\n  $$f_{n}(x)=\\begin{cases}\n    \\varphi(x-n)&\\erm{if }x\\in[n,n+1]\\\\\n    0&\\erm{otherwise}\n  \\end{cases}$$\\s\n\n  It is easy to check that $f_{n}\\in C(\\overline{G})$ and\n\n  $$\\nrm{f_{n}}_{\\infty,\\overline{G}}=\\nrm{\\varphi}_{\\infty,[0,1]}>0$$\\s\n\n  Thus $\\mathcal{E}=\\brc{f_{n}}$ is a bounded subset of $C(\\overline{G})$. By chain rule,\n\n  $$\\nrm{\\frac{\\diff f_{n}}{\\diff x}}_{\\infty,\\overline{G}}=\\nrm{\\frac{\\diff\\varphi}{\\diff x}}_{\\infty,[0,1]}>0$$\\s\n\n  Then \\rpst[\\sctd{3}] states that $\\mathcal{E}$ is also equicontinuous.\\n\n  \n  Suppose there exists a subsequence $\\brc{f_{n_{j}}}$ of $\\brc{f_{n}}$ converges to the same $f\\in C(\\overline{G})$ in $d_{\\infty}$. In other words, $f_{n_{j}}\\to f$ uniformly on $\\overline{G}$ implies pointwise convergence $f_{n_{j}}(x)\\to f(x)$ for all $x\\in\\overline{G}$. However, for fixed $x$, $f_{n}(x)=0$ for all $n\\geq x$, so it is expected to have\n\n  $$\\lim_{j\\to+\\infty}f_{n_{j}}(x)\\to 0$$\\s\n\n  which shows that $f(x)=0$ for all $x\\in\\overline{G}$. This is a contraction since\n\n  $$0<\\nrm{\\varphi}_{\\infty,[0,1]}=\\nrm{f_{n_{j}}}_{\\infty,\\overline{G}}=\\nrm{f_{n_{j}}-f}_{\\infty,\\overline{G}}\\to 0$$\\s\n\n  Therefore $\\mathcal{E}$ is bounded and equicontinuous, but Ascoli's Theorem doesn't hold.\n\\end{exm}\n\n\\subsubsection{Arzela's Theorem}\nBelow is the \\textbf{Arzela's Theorem}, which is the converse of Ascoli's Theorem:\\n\n\n\\begin{thm}\n  Suppose $G$ is a bounded nonempty open set in $\\R^{m}$, then every precompact set in $C(\\overline{G})$ must be bounded and equicontinuous.\n\\end{thm}\n\n\\subsection{Applications to Ordinary Differential Equations}\n\\subsubsection{Improvement to Picard-Lindelof Theorem}\nConsider the initial value problem\n\n$$\\begin{cases}\n  \\diff x/\\diff t=f(t,x)\\\\\n  x(t_{0})=x_{0}\n\\end{cases}$$\\s\n\nwith $f$ being continuous (but not necessary Lipschitz) on $R=[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$. Of course this is not expected to give a unique result, but existence can be proved. The idea of proof is as follows:\n\n\\begin{nlist}\n  \\item By Weierstrass Approximation Theorem (on $\\R^{2}$), there exists a sequence $\\brc{p_{n}}$ of polynomials such that $d_{\\infty}(p_{n},f)\\to 0$ (in $C(R)$).\n  \\item By Picard-Lindelof Theorem, since every $p_{n}$ satisfies Lipschitz condition (uniform in $t$), there exists $a'_{n}>0$ with\n  \n  $$a'_{n}=\\min\\brc{a,\\frac{b}{M_{n}},\\frac{1}{L_{n}}}$$\\s\n\n  where $M_{n}=\\nrm{p_{n}}_{\\infty,R}$ and $L_{n}$ be Lipschitz constant of $p_{n}$ on $R$, such that there exists a unique solution $x_{n}\\in C^{1}[t_{0}-a'_{n},t_{0}+a'_{n}]$ to the approximated initial value problem\n\n  $$\\begin{cases}\n    \\diff x_{n}/\\diff t=p_{n}(t,x_{n})\\\\\n    x_{n}(t_{0})=x_{0}\n  \\end{cases}$$\\s\n\n  for all $t\\in[t_{0}-a'_{n},t_{0}+a'_{n}]$.\n  \\item By Ascoli's Theorem, there exists a convergent subsequence $\\brc{x_{n_{k}}}$ of $\\brc{x_{n}}$ such that $x_{n_{k}}\\to x$ for some function $x(t)$. It is hoped that such $x$ is the required solution.\n\\end{nlist}\n\nHowever, since $f$ is not assumed to satisfy the Lipschitz condition, one cannot expect $\\brc{L_{n}}$ is bounded. In fact, $\\brc{L_{n}}$ is unbounded, otherwise $f$ satisfies Lipschitz condition. Here\n\n$$a'_{n}=\\min\\brc{a,\\frac{b}{M_{n}},\\frac{1}{L_{n}}}\\to 0$$\\s\n\nthen there is no proper interval for existence of the solution. On the other hand, as $p_{n}\\to f$ in $(C(R),d_{\\infty})$, $M_{n}\\leq M$ for some $M>0$. Therefore, in order to implement the plan above, it is required to improve Picard-Lindelof Theorem:\\n\n\n\\begin{pst}\n  Under the setting of Picard-Lindelof Theorem, there exists a unique solution $x(t)$ on the interval $[t_{0}-a',t_{0}+a']$ with $x(t)\\in[x_{0}-b,x_{0}+b]$, where $a'$ is any number satisfying\n\n  $$0<a'<a^{*}=\\min\\brc{a,\\frac{b}{M}}$$\n\\end{pst}\n\n\\subsubsection{Cauchy-Peano Theorem}\nBelow is the \\textbf{Cauchy-Peano Theorem}:\\n\n\n\\begin{thm}\n  Consider the initial value problem\n\n  $$\\begin{cases}\n    \\diff x/\\diff t=f(t,x)\\\\\n    x_{t_{0}}=x_{0}\n  \\end{cases}$$\\s\n\n  where $f$ is continuous on $R=[t_{0}-a,t_{0}+a]\\times[x_{0}-b,x_{0}+b]$, then there exists $a'\\in(0,a)$ and a $C^{1}$ function\n\n  $$x:[t_{0}-a,t_{0}+a]\\to[x_{0}-b,x_{0}+b]$$\\s\n\n  solving the initial value problem.\n\\end{thm}\n\n\\subsection{Baire Category Theorem}\n\\subsubsection{Denseness}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a set $E\\subset X$ is said to be \\textbf{dense} if for all $x\\in X$ and $\\epsilon>0$, $B_{\\epsilon}(x)\\cap E\\neq\\emptyset$.\n\\end{dft}\\n\n\nNote that $X$ is naturally dense in $(X,d)$, and if $E$ is dense in $X$, its closure $\\overline{E}=X$.\\n\n\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a set $E\\subset X$ is said to be \\textbf{nowhere dense} if its closure does not contain any ball. In other words, $\\overline{E}$ has empty interior.\n\\end{dft}\\n\n\n\\begin{exm}\n  Set of integers $\\Z$ is nowhere dense in $\\R$. However, although set of rationals $\\Q$ has empty interior, its closure $\\overline{\\Q}=\\R$ has nonempty interior, so $\\Q$ is not nowhere dense.\n\\end{exm}\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space and $E\\subset X$ be a set, then $E$ is nowhere dense if and only if $X\\setminus\\overline{E}$ is dense in $X$.\\n\n\n  \\prf If $E$ is nowhere dense, for all $x\\in X$ and any $r>0$, $B_{r}(x)\\not\\subset\\overline{E}$, which implies $B_{r}(x)\\cap(X\\setminus\\overline{E})\\neq\\emptyset$, so $X\\setminus\\overline{E}$ is dense. The converse follows the reverse order.\n\\end{pst}\\n\n\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a point $x\\in X$ is called an \\textbf{isolated point} if $\\brc{x}$ is open in $X$.\n\\end{dft}\\n\n\nNote that $\\brc{x}$ is always closed in a metric space. Therefore, $\\brc{x}$ is both open and closed if and only if $x$ is an isolated point.\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then the following applies:\n\n  \\begin{alist}\n    \\item If $E$ is nowhere dense in $X$, $\\overline{E}$ is nowhere dense in $X$. Also, $E'$ is nowhere dense in $X$ if $E'\\subset E$.\n    \\item The union of finitely many nowhere dense sets in $X$ is nowhere dense in $X$.\n    \\item If $(X,d)$ has no isolated point, then every finite set is nowhere dense.\n  \\end{alist}\n\\end{pst}\\n\n\nNow consider the following example in infinite dimensional normed spaces:\\n\n\n\\begin{exm}\n  Let $M[a,b]$ be a space of bounded functions on $[a,b]$, then\n  \n  $$\\nrm{f}_{\\infty}=\\underset{[a,b]}{\\sup}\\abs{f(x)}$$\\s\n\n  is well-defined and is a norm on $M[a,b]$. It is clear that $(C[a,b],d_{\\infty})$ is a metric (and vector) subspace of $(M[a,b],d_{\\infty})$. Show that $C[a,b]$ is nowhere dense in $M[a,b]$.\\n\n\n  \\ans Note that $C[a,b]$ is closed because uniform limit of continuous functions is continuous. It is left to show that for all $B_{\\epsilon}^{\\infty}(f)\\subset M[a,b]$,\n\n  $$B_{\\epsilon}^{\\infty}(f)\\cap(M[a,b]\\setminus C[a,b])\\neq\\emptyset$$\\s\n\n  If $f\\in M[a,b]\\setminus C[a,b]$, the result is already achieved. For any $f\\in C[a,b]$, let\n\n  $$g(x)=\\begin{cases}\n    f(x)+\\epsilon/2\\erm{if }x\\in[a,b]\\cap\\Q\\\\\n    f(x)-\\epsilon/2\\erm{if }x\\in[a,b]\\setminus\\Q\n  \\end{cases}$$\\s\n\n  such that $\\nrm{g-f}_{\\infty}=\\epsilon/2$ implies $g\\in B_{\\epsilon}^{\\infty}(f)$. Since both $[a,b]\\cap\\Q$ and $[a,b]\\setminus\\Q$ are dense in $[a,b]$,\n\n  $$\\underset{x\\to a}{\\limsup}g(x)=f(a)+\\frac{\\epsilon}{2}$$\\s\n\n  and\n\n  $$\\underset{x\\to a}{\\liminf}g(x)=f(a)-\\frac{\\epsilon}{2}$$\\s\n\n  shows that $g\\in M[a,b]\\setminus C[a,b]$. Therefore $B_{\\epsilon}^{\\infty}(f)\\cap(M[a,b]\\setminus C[a,b])\\neq\\emptyset$, and $C[a,b]$ is nowhere dense in $M[a,b]$.\n\\end{exm}\n\n\\subsubsection{First Category and Second Category}\n\\begin{dft}\n  Let $(X,d)$ be a metric space, then a set $E\\subset X$ is called \\textbf{first category} (or \\textbf{meager}) if it can be expressed as a countable union of nowhere dense sets. If $E$ is not of first category, then $E$ is called \\textbf{second category}.\\n\n\n  $E$ is said to be \\textbf{residual} if its complement is of first category.\n\\end{dft}\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then the following applies:\n\n  \\begin{alist}\n    \\item Every subset of a set of first category is of first category.\n    \\item The union of countable many sets of first category is of first category.\n    \\item If $(X,d)$ has no isolated point, every countable subset of $X$ is of first category.\n  \\end{alist}\n\\end{pst}\\n\n\nWith the proposition above, a similar proposition for residual sets can be made by taking complements:\\n\n\n\\begin{pst}\n  Let $(X,d)$ be a metric space, then the following applies:\n\n  \\begin{alist}\n    \\item Every subset containing a residual set is residual.\n    \\item The intersection of countable many residual sets is residual.\n    \\item If $(X,d)$ has no isolated point, complement of any countable set is residual.\n  \\end{alist}\n\\end{pst}\\n\n\n\\begin{exm}\n  Let $(\\R,d_{1})$ be a metric space. Since $\\R$ has no isolated points, $\\brc{q}$ is nowhere dense for any $q\\in\\Q$, so $\\Q$ is of first category since it is a countable union of $\\brc{q}$. On the other hand, the set of irrational numbers $\\I=\\R\\setminus\\Q$ is residual in $\\R$.\n\\end{exm}\n\n\\subsubsection{General Theorem}\nBelow is the \\textbf{Baire Category Theorem}:\\n\n\n\\begin{thm}\n  Any set of first category in a complete metric space has empty interior. In other words, any countable intersection of open dense sets in a complete metric space is dense.\n\\end{thm}\\n\n\nWith Baire Category Theorem, there are some corollaries to follow:\\n\n\n\\begin{crl}\n  Let $(X,d)$ be a complete metric space. Suppose that $X=\\bigcup_{n=1}^{\\infty}E_{n}$ with $E_{n}$ are closed subsets. Then at least one of there $E_{n}$ has nonempty interior.\n\\end{crl}\\n\n\n\\begin{crl}\n  A set of first category in a complete metric space cannot be a residual set, and vice versa.\n\\end{crl}\n\n\\subsubsection{Applications of Baire Category Theorem}\n\\begin{pst}\n  Let $f\\in C[a,b]$ be differentiable at $x$, then it is Lipschitz continuous at $x$.\\n\n\n  \\prf By assumption, for any $\\epsilon=1>0$, there exists $\\delta_{0}>0$ such that for all $y\\in(x-\\delta_{0},x+\\delta_{0})\\setminus\\brc{x}$ and $y\\in[a,b]$,\n\n  $$\\abs{\\frac{f(y)-f(x)}{y-x}-f'(x)}<1$$\\s\n\n  implies\n\n  $$\\abs{f(y)-f(x)}\\leq(1+\\abs{f'(x)})\\abs{y-x}$$\\s\n\n  for all $y\\in(x-\\delta_{0},x+\\delta_{0})\\cap[a,b]$. If $[a,b]\\setminus(x-\\delta_{0},x+\\delta_{0})=\\emptyset$, it is already done. Consider for $y\\in[a,b]\\setminus(x-\\delta_{0},x+\\delta_{0})$ if such set is nonempty, $\\abs{y-x}\\geq\\delta_{0}$, hence\n\n  $$\\begin{aligned}[t]\n    \\abs{f(y)-f(x)}&\\leq\\abs{f(y)}+\\abs{f(x)}\\\\\n    &\\leq 2\\nrm{f}_{\\infty}\\\\\n    &\\leq\\frac{2\\nrm{f_{\\infty}}}{\\delta_{0}}\\abs{y-x}=L'\\abs{y-x}\n  \\end{aligned}$$\\s\n\n  Finally, let $L=\\max\\brc{1+\\abs{f'(x)},L'}$, then $\\abs{f(y)-f(x)}\\leq L\\abs{y-x}$ for all $y\\in[a,b]$.\n\\end{pst}\\n\n\nWith the proposition above, the following theorem can be introduced:\\n\n\n\\begin{thm}\n  The set of all continuous, nowhere differentiable functions forms a residual set in $C[a,b]$ and hence dense in $C[a,b]$.\n\\end{thm}\n\n\\input{sty/footer.sty}\n\n\\begin{reflist}\n  \\item Elias M. Stein, Rami Shakarchi, \\textit{Fourier Analysis: An Introduction (Princeton Lectures in Analysis)}, Princeton, 2003\n  \\item Walter Rudin, \\textit{Principles of Mathematical Analysis}, McGraw-Hill (3rd Edition), 1976\n\\end{reflist}\n\n\\end{document}", "meta": {"hexsha": "355cfb1640fc035198fe90f5b8c2615a1fc362e4", "size": 88017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/math3060.tex", "max_stars_repo_name": "nablamath/notes", "max_stars_repo_head_hexsha": "e268c0e7f723ee870ca6cacf93fc91dca4368e6b", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-05T16:43:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-05T16:43:38.000Z", "max_issues_repo_path": "tex/math3060.tex", "max_issues_repo_name": "nablamath/notes", "max_issues_repo_head_hexsha": "e268c0e7f723ee870ca6cacf93fc91dca4368e6b", "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/math3060.tex", "max_forks_repo_name": "nablamath/notes", "max_forks_repo_head_hexsha": "e268c0e7f723ee870ca6cacf93fc91dca4368e6b", "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.5174528302, "max_line_length": 506, "alphanum_fraction": 0.6266971153, "num_tokens": 34790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484144, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.6150240662740631}}
{"text": "\n\n\\section{Calculation}\n\nWe start on the $E_2$ page. \nOn the zeroth column, we get only the cohomology of $U(2)$, hence we at least see\n\n\\adjustbox{scale=0.9, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3 &   &   &   &   &   &   &   &   \\\\\n3 & a_3    &   &   &   &   &   &   &   &   \\\\\n2 & 0      &   &   &   &   &   &   &   &   \\\\\n1 & a_1    &   &   &   &   &   &   &   &   \\\\\n0 & 1      &   &   &   &   &   &   &   &   \\\\\n  & 0      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\n\\end{tikzcd}\n}\n\nSince we know that $H^*(V_2(\\mathbb{C}^4))$ has no elements in degree $1$, \nwe know that $H^2(G_2(\\mathbb{C}^4))\\cong H^1(V_2(\\mathbb{C}^4))$, \nas the generator $a_1$ has to be killed by a differential. \nCall the generator for the group $H^2(G_2(\\mathbb{C}^4))$ that is the image of $a_1$ for $x$. \nBy multiplications by the other generators and itself we then know we have\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3                   &   & a_1a_3x &   & a_1a_3x^2 &   & a_1a_3x^3 &   & a_1a_3x^4 \\\\\n3 & a_3                      &   & a_3x    &   & a_3x^2    &   & a_3x^3    &   & a_3x^4    \\\\\n2 &                          &   &         &   &           &   &           &   &           \\\\\n1 & a_1 \\arrow[rrd, \"\\cong\"] &   & a_1x    &   & a_1x^2    &   & a_1x^3    &   & a_1x^4    \\\\\n0 & 1                        &   & x       &   & x^2       &   & x^3       &   & x^4       \\\\\n  & 0                        & 1 & 2       & 3 & 4         & 5 & 6         & 7 & 8        \n\\end{tikzcd}\n}\n\nWe know that the differential is a derivation, \nhence we get that $d_2(a_1x)=d_2(a_1)x+(-1)^{|x|}a_1d_2(x) = d_2(a_1)x = x^2$ since $d_2(x)=0$. \nThe same calculation for higher powers of $x$ and for $a_1a_3$ and $a_1a_3x$, \ngives us isomorphisms all the way to the right\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3 \\arrow[rrd, \"\\cong\"] &   & a_1a_3x \\arrow[rrd, \"\\cong\"] &   & a_1a_3x^2 \\arrow[rrd, \"\\cong\"] &   & a_1a_3x^3 \\arrow[rrd, \"\\cong\"] &   & a_1a_3x^4 \\\\\n3 & a_3                         &   & a_3x                         &   & a_3x^2                         &   & a_3x^3                         &   & a_3x^4    \\\\\n2 &                             &   &                              &   &                                &   &                                &   &           \\\\\n1 & a_1 \\arrow[rrd, \"\\cong\"]    &   & a_1x \\arrow[rrd, \"\\cong\"]    &   & a_1x^2 \\arrow[rrd, \"\\cong\"]    &   & a_1x^3 \\arrow[rrd, \"\\cong\"]    &   & a_1x^4    \\\\\n0 & 1                           &   & x                            &   & x^2                            &   & x^3                            &   & x^4       \\\\\n  & 0                           & 1 & 2                            & 3 & 4                              & 5 & 6                              & 7 & 8        \n\\end{tikzcd}\n}\n\nHere we see a problem. \nThe generator $a_3$ never gets killed by a differential, \nbut the cohomology of $V_2(\\mathbb{C}^4))$ has no elements in degree $3$, \nso it cant survive. \nThe only degree a differential starting from $a_3$ can land in is $4$, \nand the only possible non-zero cohomology in degree 4 comes from $H^4(G_2(\\mathbb{C}^4))$, \nwhich by the likes of it so far has already been killed by a $d_2$ differential. \nHence we got to have a $d_4$ differential hitting another generator in $H^4(G_2(\\mathbb{C}^4))$, \nhence we need higher dimensional cohomology in this degree. \nWe call this new generator which is the image of $a_3$ under the $d_3$ differential for $y$. \nLooking back at the $E_2$ page, we then have new elements\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3 \\arrow[rrd, \"\\cong\"] &   & a_1a_3x \\arrow[rrd, \"\\cong\"] &   & {a_1a_3x^2, a_1a_3y} \\arrow[rrd, \"\\cong\"] &   & {a_1a_3x^3, a_1a_3xy} \\arrow[rrd, \"\\cong\"] &   & {a_1a_3x^4, a_1a_3y^2} \\\\\n3 & a_3                         &   & a_3x                         &   & {a_3x^2, a_3y}                            &   & {a_3x^3, a_3xy}                            &   & {a_3x^4, a_3y^2}       \\\\\n2 &                             &   &                              &   &                                           &   &                                            &   &                        \\\\\n1 & a_1 \\arrow[rrd, \"\\cong\"]    &   & a_1x \\arrow[rrd, \"\\cong\"]    &   & {a_1x^2, a_1y} \\arrow[rrd, \"\\cong\"]       &   & {a_1x^3, a_1xy} \\arrow[rrd, \"\\cong\"]       &   & {a_1x^4, a_1y^2}       \\\\\n0 & 1                           &   & x                            &   & {x^2, y}                                  &   & {x^3, xy}                                  &   & {x^4, y^2}             \\\\\n  & 0                           & 1 & 2                            & 3 & 4                                         & 5 & 6                                          & 7 & 8                     \n\\end{tikzcd}\n}\n\nNow, what does this new information and new elements give us? \nBy the same calculation as previously, we get that $d_2(a_1y) = xy$, \nbut here have more information. \nWe know that $H^*(V_2(\\mathbb{C}^4))$ has a generator in degree $5$, \nand this new generator $a_1y$ is the only generator left in total degree $5$ in the spectral sequence. \nThus it can't die by a $d_2$ differential. \nAnd since it's image is $xy$, this image has to be zero, which gives us the first of two relations on the cohomology ring of our Grassmannian, namely $xy=0$. \nHence, as far as we know so far, our $E_2$ page looks like this: \n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3 \\arrow[rrd, \"\\cong\"] &   & a_1a_3x \\arrow[rrd, \"\\cong\"] &   & {a_1a_3x^2, a_1a_3y} \\arrow[rrd, \"\\cong\"] &   & a_1a_3x^3 \\arrow[rrd, \"\\cong\"] &   & {a_1a_3x^4, a_1a_3y^2} \\\\\n3 & a_3                         &   & a_3x                         &   & {a_3x^2, a_3y}                            &   & a_3x^3                         &   & {a_3x^4, a_3y^2}       \\\\\n2 &                             &   &                              &   &                                           &   &                                &   &                        \\\\\n1 & a_1 \\arrow[rrd, \"\\cong\"]    &   & a_1x \\arrow[rrd, \"\\cong\"]    &   & {a_1x^2, a_1y} \\arrow[rrd, \"\\cong\"]       &   & a_1x^3 \\arrow[rrd, \"\\cong\"]    &   & {a_1x^4, a_1y^2}       \\\\\n0 & 1                           &   & x                            &   & {x^2, y}                                  &   & x^3                            &   & {x^4, y^2}             \\\\\n  & 0                           & 1 & 2                            & 3 & 4                                         & 5 & 6                              & 7 & 8                     \n\\end{tikzcd}\n}\n\nAs far as I'm aware, we can't squeeze any more information out of the $E_2$ page yet. \nLet us pass to the $E_3$ page and see which generator we are left with after all the isomorphisms kill the generators. \nWe have\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 &     &   &   &   & a_1a_3y &   &   &   & {a_1a_3y^2} \\\\\n3 & a_3 &   &   &   & a_3y    &   &   &   & a_3y^2                 \\\\\n2 &     &   &   &   &         &   &   &   &                        \\\\\n1 &     &   &   &   & a_1y    &   &   &   & {a_1y^2}       \\\\\n0 & 1   &   &   &   & y       &   &   &   & y^2                    \\\\\n  & 0   & 1 & 2 & 3 & 4       & 5 & 6 & 7 & 8                     \n\\end{tikzcd}\n}\n\nand we see that all the $d_3$ differentials either start or land in places which are zero, \nhence $E_3 = E_4$. On the $E_4$ page however, \nwe know that we at least have one differential, \nnamely the one we used to justify the generator $y$'s existence. \nBy the derivation property of the differentials, \nwe also get that $d_4(a_1a_3y)=a_1y^2$, \nhence we at least have an $E_4$ page looking like\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 &                              &   &   &   & a_1a_3y \\arrow[rrrrddd, \"\\cong\"] &   &   &   & a_1a_3y^2 \\\\\n3 & a_3 \\arrow[rrrrddd, \"\\cong\"] &   &   &   & a_3y                             &   &   &   & a_3y^2    \\\\\n2 &                              &   &   &   &                                  &   &   &   &           \\\\\n1 &                              &   &   &   & a_1y                             &   &   &   & a_1y^2    \\\\\n0 & 1                            &   &   &   & y                                &   &   &   & y^2       \\\\\n  & 0                            & 1 & 2 & 3 & 4                                & 5 & 6 & 7 & 8        \n\\end{tikzcd}\n}\n\nWe are also lucky enough to know that $H^*(V_2(\\mathbb{C}^4))$ has a generator in degree $7$, \nwhich we see is $a_3y$ since it is the only one left in the correct total degree. \nBut what happens to the differential $d_4(a_3y) = y^2$ you ask? Do we have $y^2=0$ then, \nsame as last time? \nActually, no. \nSince we know that $a_1y$ and $a_3y$ both are non-zero generators in $H^*(V_2(\\mathbb{C}^4))$, \ntheir product $a_1a_3y^2$ is also a generator in degree $12$, \nhence it has to be non-zero, \nand then $y^2$ has to be non-zero in $H^8(G_2(\\mathbb{C}^4))$. \nBut, it still has to die in the spectral sequence though, \nand the solution is the second relation on the cohomology ring, \nnamely $x^4=y^2$. \nThis ensures that $y^2$ is already killed on the $E_2$ page, \nand hence that $a_3y$ isn't killed on the $E_4$ page.\n\nTo retrospectively correct some things now that we have all the information, \nwe first note that we were lucky we didn't bother writing more that $8$ columns, \nbecause everything in row $0$ and columns above $8$ either is a product of $x$'s and $y$'s, \nor contain powers of $x$ greater or equal to $5$ or powers of $y$ greater or equal to $3$, \nmaking $x^5 = xx^4=xy^2=(xy)y=0$ and $y^3=yx^4=0$. \nHence our generators $a_1x^4$ and $a_1a_3x^4$ never was killed by any $d_2$ differentials, \nsince their images are $x^5=0$ and $a_3x^5=0$ respectively. \nHence we still have $a_1x^4=a_1y^2$ and $a_1a_3x^4=a_1a_3y^2$ on the $E_4$ page. \nAlso, we get that $a_3x^4=a_3y^2$, \nwhich means that $a_3y^2$ was killed by a $d_2$ differential on the $E_2$ page, \nand hence it does not show up on the $E_4$ page. \nThe final form of the $E_2$ page is then\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 & a_1a_3 \\arrow[rrd] &   & a_1a_3x \\arrow[rrd] &   & {a_1a_3x^2, a_1a_3y} \\arrow[rrd] &   & a_1a_3x^3 \\arrow[rrd] &   & a_1a_3x^4=a_1a_3y^2 \\\\\n3 & a_3                &   & a_3x                &   & {a_3x^2, a_3y}                   &   & a_3x^3                &   & a_3x^4=a_3y^2       \\\\\n2 &                    &   &                     &   &                                  &   &                       &   &                     \\\\\n1 & a_1 \\arrow[rrd]    &   & a_1x \\arrow[rrd]    &   & {a_1x^2, a_1y} \\arrow[rrd]       &   & a_1x^3 \\arrow[rrd]    &   & a_1x^4=a_1y^2       \\\\\n0 & 1                  &   & x                   &   & {x^2, y}                         &   & x^3                   &   & x^4=y^2             \\\\\n  & 0                  & 1 & 2                   & 3 & 4                                & 5 & 6                     & 7 & 8                  \n\\end{tikzcd}\n}\n\nand the final form of the $E_4$ page is\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 &                              &   &   &   & a_1a_3y \\arrow[rrrrddd, \"\\cong\"] &   &   &   & a_1a_3y^2 \\\\\n3 & a_3 \\arrow[rrrrddd, \"\\cong\"] &   &   &   & a_3y                             &   &   &   &           \\\\\n2 &                              &   &   &   &                                  &   &   &   &           \\\\\n1 &                              &   &   &   & a_1y                             &   &   &   & a_1y^2    \\\\\n0 & 1                            &   &   &   & y                                &   &   &   &           \\\\\n  & 0                            & 1 & 2 & 3 & 4                                & 5 & 6 & 7 & 8        \n\\end{tikzcd}\n}\n\nSince all higher degree differentials, \ni.e. $d_5$ and above miss any generators due to being too long, \nwe have $E_5=E_{\\infty}$. \nWe can also see this because we have arrived at the correct cohomology ring for $V_2(\\mathbb{C}^4)$, \nnamely the final page\n\n\\adjustbox{scale=0.8, center}{\n\\begin{tikzcd}[column sep=small]\n4 &   &   &   &   &      &   &   &   & a_1a_3x^4=a_1a_3y^2 \\\\\n3 &   &   &   &   & a_3y &   &   &   &                     \\\\\n2 &   &   &   &   &      &   &   &   &                     \\\\\n1 &   &   &   &   & a_1y &   &   &   &                     \\\\\n0 & 1 &   &   &   &      &   &   &   &                     \\\\\n  & 0 & 1 & 2 & 3 & 4    & 5 & 6 & 7 & 8                  \n\\end{tikzcd}\n}\n\nHence we are done, \nand we have found the correct cohomology ring for our Grassmannian $G_2(\\mathbb{C}^4)$. \nBy all our extensive calculations and work, \nwe finally can say that $H^*(G_2(\\mathbb{C}^4)) = \\mathbb{Z}(x,y)/(xy, x^4-y^2)$ or if we add the degrees into the names of the generators, \n$H^*(G_2(\\mathbb{C}^4)) = \\mathbb{Z}(a_2, a_4)/(a_2a_4, a_2^4-a_4^2)$. \nHence the calculation is finished, and we are done. ", "meta": {"hexsha": "826905d5ad976c403741e9dfda4e207cf731c04d", "size": 12893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/calculation.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/calculation.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/calculation.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": 63.5123152709, "max_line_length": 195, "alphanum_fraction": 0.427906616, "num_tokens": 4615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6150098326965904}}
{"text": "\\section{The \\sortheap algorithm}\n\\Label{sec:sortheap}\n\nWhereas in the \\cxx Standard Library \\cite[\\S 28.7.7.4]{cxx-17-draft}\n\\sortheap works on a range of random access iterators,\nour version operates on an array of \\valuetype.\nWe therefore use the following signature for \\sortheap\n\n\\begin{lstlisting}[style = acsl-block]\n\n    void sort_heap(value_type* a, size_type n);\n\\end{lstlisting}\n\nThe function \\sortheap rearranges the elements of a given heap \\inl{a[0..n-1]}\nin increasing order.\nThus, applying \\sortheap to the heap in Figure~\\ref{fig:heap-array}\nproduces the increasing array in Figure~\\ref{fig:sortheap-array-post}.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.65\\linewidth]{Figures/sort_heap_array_post.pdf}\n\\caption{\\Label{fig:sortheap-array-post}Array after the call of \\sortheap}\n\\end{figure}\n\n\\FloatBarrier\n\n\\subsection{Formal specification of \\sortheap}\n\nThe following listing shows our specification of \\sortheap.\nThe formal specification of \\sortheap must ensure that the\nresulting array is increasing.\nFurthermore the multiset contained by the array must be the same\nas in the pre-state of the function.\nThe postconditions \\inl{increasing} and \\inl{reorder} express these properties, respectively.\nThe specification effort is relatively simple because we can reuse\n\n\\input{Listings/sort_heap.h.tex}\n\n\\clearpage\n\n\\subsection{Implementation of \\sortheap}\n\nThe implementation of \\sortheap is relatively simple because it relies on\n\\specref{popheap} performing essential work.\nOur implementation of \\sortheap repeatedly calls \\popheap\nto extract the maximum of the shrinking heap and adding it\nto the part of the array that is already in increasing order.\nThe loop invariants of \\sortheap describe the content of the array\nin two parts.\nThe first \\inl{i} elements form a heap and are described by the \\inl{heap}\ninvariant.\nThe last \\inl{n-i} elements are already arranged in increasing order.\n\nAs already mentioned in the introduction of Chapter~\\ref{cha:binary-search},\nwe use the predicate \\logicref{WeaklyIncreasing} for the loop annotation \\inl{increasing}.\nThus, after leaving the loop we have in fact ``only'' shown that \\inl{WeaklyIncreasing(a, n)}\nholds.\nIn order to derive from this fact the final assertion \\inl{increasing} that uses\nthe predicate \\logicref{Increasing} we rely on lemma \\logicref{WeaklyIncreasingIncreasing}.\n\n\\input{Listings/sort_heap.c.tex}\n\nTo verify the property \\inl{reorder} we rely on the lemmas \\logicref{MultisetReorder}\nthat express that the properties \n\n\\begin{itemize}\n\\item \\inl{MultisetReorder\\{K,L\\}(a, 0, i)} and\n\\item \\inl{Unchanged\\{Old,Here\\}(a, i, n)}\n\\end{itemize}\n\nimply the desired loop invariant \\inl{MultisetReorder\\{K,L\\}(a, 0, n)}.\n\n%\\clearpage\n\n", "meta": {"hexsha": "8125998ca8f4deb18616a28df8dab9b6a7df3b0c", "size": 2731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/heap/sort_heap.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/heap/sort_heap.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/heap/sort_heap.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": 36.4133333333, "max_line_length": 93, "alphanum_fraction": 0.7832295862, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6150098221283341}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Curvature of a 2-sphere}\n\nThis examples uses standard methods to compute the scalar curvature of a 2-sphere.\n\n\\begin{cadabra}\n   {\\theta, \\varphi}::Coordinate.\n   {\\alpha, \\beta, \\gamma, \\delta, \\rho, \\sigma, \\mu, \\nu, \\lambda}::Indices(values={\\varphi, \\theta}, position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   g_{\\alpha\\beta}::Metric.\n   g^{\\alpha\\beta}::InverseMetric.\n\n   Chr := \\Gamma^{\\alpha}_{\\mu\\nu} -> 1/2 g^{\\alpha\\beta} (  \\partial_{\\nu}{g_{\\beta\\mu}}\n                                                           + \\partial_{\\mu}{g_{\\beta\\nu}}\n                                                           - \\partial_{\\beta}{g_{\\mu\\nu}} ).\n\n   Rabcd := R^{\\rho}_{\\sigma\\mu\\nu} ->   \\partial_{\\mu}{\\Gamma^{\\rho}_{\\sigma\\nu}}\n                                       - \\partial_{\\nu}{\\Gamma^{\\rho}_{\\sigma\\mu}}\n                                       + \\Gamma^{\\rho}_{\\beta\\mu} \\Gamma^{\\beta}_{\\sigma\\nu}\n                                       - \\Gamma^{\\rho}_{\\beta\\nu} \\Gamma^{\\beta}_{\\sigma\\mu}.\n\n   Rab := R_{\\sigma\\nu} -> R^{\\rho}_{\\sigma\\rho\\nu}.\n\n   R := R -> R_{\\sigma\\nu} g^{\\sigma\\nu}.\n\n   gab:={ g_{\\theta\\theta}   = r**2,\n          g_{\\varphi\\varphi} = r**2 \\sin(\\theta)**2 }.   # cdb(gab,gab)\n\n   complete   (gab, $g^{\\alpha\\beta}$)                   # cdb(iab,gab)\n\n   evaluate   (Chr, gab, rhsonly=True)                   # cdb(Chr,Chr)\n\n   substitute (Rabcd, Chr)\n   evaluate   (Rabcd, gab, rhsonly=True)                 # cdb(Rabcd,Rabcd)\n\n   substitute (Rab, Rabcd)\n   evaluate   (Rab, gab, rhsonly=True)                   # cdb(Rab,Rab)\n\n   substitute (R, Rab)\n   evaluate   (R, gab, rhsonly=True)                     # cdb(R,R)\n\\end{cadabra}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{align*}\n   &\\cdb{iab}\\\\[10pt]\n   &\\cdb{Chr}\\\\[10pt]\n   &\\cdb{Rabcd}\\\\[10pt]\n   &\\cdb{Rab}\\\\[10pt]\n   &\\cdb{R}\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      &\\cdb{iab}\\\\[10pt]\n      &\\cdb{Chr}\\\\[10pt]\n      &\\cdb{Rabcd}\\\\[10pt]\n      &\\cdb{Rab}\\\\[10pt]\n      &\\cdb{R}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "58260567aecbd6f60c2a447a1d4e925475f4fbfa", "size": 2215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/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": "cadabra/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": "cadabra/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": 30.3424657534, "max_line_length": 125, "alphanum_fraction": 0.5060948081, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6149353022394207}}
{"text": "\\chapter{Solomonoff theory}\n\nWhy was Raymond J. Solomonoff \\cite{SolAlpProb2011, GacsVitanyiSolomonoff}\ninterested in predicting sequences of bits?\n\nMarcus Hutter approached intelligence from \\emph{algorithmic} complexity theory (Solomonoff induction)\n\\cite{DefineMachIntel}.\nWarren D. Smith approached intelligence from \\emph{computational} complexity theory\n(NP-completeness)\n\\cite{WdsIntel, WdsIntelSlide}\n\n\\section{Generalization of Solomonoff theory}\n\nLet \\(\\Bit = \\{0,1\\}\\).\nLet \\(\\Bits = \\Bit^*\\) where \\(*\\) is the Kleene star.\nLet \\(f : \\Bits \\to \\Bits\\).\nLet \\(p : \\Bits \\to [0,1]\\) be the input distribution.\nDefine \\(q~y\\) as the probability of finding an input \\(x\\) such that \\(f~x = y\\).\nSolomonoff used a universal Turing machine for \\(f\\),\nbut I'm interested on the consequences of relaxing this constraint.\n\nBijection allows us to use \\(\\Nat\\) or any other countable set instead of \\(\\Bits\\).\nLet \\(f : \\Nat \\to \\Nat\\) be a function.\nWe say that \\emph{\\(x\\) \\(f\\)-explains \\(y\\)} iff \\(f~x = y\\).\nLet \\(p : \\Nat \\to [0,1]\\) be the input distribution.\nDefine \\(q~y\\) as the probability of finding an \\(x\\) such that \\(f~x = y\\).\nWe call an input such as \\(x\\) a \\emph{hypothesis}.\n\n\\newcommand\\preimage{\\fun{preimage}}\n\nLet \\(f\\) be a binary relation.\nWe define \\(\\preimage~f~y = \\{ x ~|~ f~x~y \\}\\).\n\n\\section{Generalizing Kolmogorov complexity}\n\nSchmidh\\\"uber generalized Kolmogorov complexity to super Turing machines \\cite{SchmidhuberKolmogorov}.\n\nThe Kolmogorov complexity of a string\nis the length of the shortest program that generates that string.\nThis complexity depends on the machine.\nFormally, we define \\(\\kolmogorov~f~y\\),\nthe Kolmogorov complexity of \\(y\\) with respect to \\(f\\),\nas the length of the shortest \\(x\\) that satisfies \\(f~x = y\\).\n\nWe can relax the constraint of \\(f\\) so that \\(f\\)\nnow only needs to be a surjective relation.\nWe can relax it further so that it is a relation.\nHowever, if \\(f\\) is not surjective,\nthe Kolmogorov complexity will be partial\n(undefined for some inputs).\nThat seems to be as general as logic allows.\n\nWe can relax the measure \\(m : A \\to \\Real\\) into a function \\(m : A \\to B\\)\nand an ordering \\(c\\).\n\n\\[\n    \\kolmogorov~c~m~f = \\minimumBy~c \\circ \\map~m \\circ \\preimage~f\n\\]\n\nNote the notation:\nIf \\(f\\) is a binary relation,\nwe overload the notation \\(f\\)\nto also mean the binary predicate\nthat is the indicator function of the relation \\(f\\).\nWe conflate a predicate and its extension.\nWe write \\(f~x~y\\) to mean \\((x,y) \\in f\\).\nThe type of the expression \\(f~x~y\\) is \\(\\Bool\\).\n\nWe can generalize Kolmogorov complexity.\nInstead of a space of strings and the length of strings,\nwe can use a measure space.\nFurthermore, we can generalize the function into relation.\nLet \\(m : A \\to \\Real\\) be a measure on \\(A\\).\nLet \\(f \\subseteq A \\times A\\) be a binary relation.\nFormally,\n\\[\n    \\kolmogorov~m~f~y = \\minimum~(\\map~m~(\\preimage~f~y))\n\\]\nor, more pointfreely,\n\\begin{equation}\n    \\kolmogorov~m~f = \\minimum \\circ \\map~m \\circ \\preimage~f\n\\end{equation}\n\nWe define \\(\\kolmogorov~m~f~y\\) as the measure of an \\(x\\)\nthat both minimizes \\(m\\) and satisfies \\(f~x~y\\).\nTherefore \\(\\kolmogorov\\) is a constrained optimization problem.\nThe classical Kolmogorov complexity is a special case of \\(\\kolmogorov\\)\nwhere \\(m\\) computes the length of a bitstring\nand \\(f\\) is a universal Turing machine.\n\nThe Kolmogorov complexity is incomputable due to the halting problem.\nIt does not even have a brute-force algorithm.\nHowever, Levin search allows us to approximate it.\n", "meta": {"hexsha": "2e77efbc9b281c9d6bbf6bf152b75ed47bf21139", "size": 3541, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/solomonoff.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/solomonoff.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/solomonoff.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": 37.670212766, "max_line_length": 102, "alphanum_fraction": 0.7127929963, "num_tokens": 1064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6149352919585369}}
{"text": "\n\\subsection{The Fisher equation}\n\nThe Fisher equation shows the relationship between the real and nominal interest rates.\n\n\\((1+i)=(1+r)(1+\\pi )\\)\n\nFor small values:\n\n\\(i\\approx r+\\pi \\)\n\n", "meta": {"hexsha": "63770a9ade598a3dae18e29b348eb3efde4f13a5", "size": 189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/neoKeynesian/02-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/economics/neoKeynesian/02-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/economics/neoKeynesian/02-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": 15.75, "max_line_length": 87, "alphanum_fraction": 0.6984126984, "num_tokens": 49, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7341195385342972, "lm_q1q2_score": 0.6149131809493492}}
{"text": "\\documentclass[t]{beamer}\n\\usetheme{Copenhagen}\n\\setbeamertemplate{headline}{} % remove toc from headers\n\\beamertemplatenavigationsymbolsempty\n\n\\usepackage{amsmath, tikz, bm, tkz-euclide}\n\\usetkzobj{all}\n\n\\title{Trig Functions of Any Angle}\n\\author{}\n\\date{}\n\n\\AtBeginSection[]\n{\n  \\begin{frame}\n    \\frametitle{Objectives}\n    \\tableofcontents[currentsection]\n  \\end{frame}\n}\n\n\\begin{document}\n\n\\begin{frame} \n\\maketitle\n\\end{frame}\n\n\\begin{frame}{From Right Triangle Trig to the Coordinate Plane}\nIn this section, adjacent, opposite and hypotenuse\n\\begin{center}\n\\begin{tikzpicture}\n    \\tkzDefPoints{0/0/A, 3/0/C, 3/2/B}\n    \\tkzMarkRightAngle[color=red](A,C,B)\n    \\tkzDrawPolygon(A,B,C)\n    \\tkzLabelSegment[below](A,C){adjacent}\n    \\tkzLabelSegment[right](B,C){opposite}\n    \\tkzLabelSegment[above left](A,B){hypotenuse}\n\\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{From Right Triangle Trig to the Coordinate Plane}\nbecome\n\\begin{center}\n    \\begin{tikzpicture}\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$x$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3) node [right] {$y$};\n    \\draw [color=red] (2.5,0) rectangle (2.25,0.25);\n    \\draw (0,0) -- (2.5,0) -- (2.5,2) -- cycle;\n    \\node at (1.25,0) [below] {$\\bm{x}$};\n    \\node at (2.5,1) [right] {$\\bm{y}$};\n    \\node at (1.25,1) [above] {$\\bm{r}$};\n    \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{From Right Triangle Trig to the Coordinate Plane}\nwhere $r$ represents the radius of the circle shown below.\n\n\\begin{center}\n    \\begin{tikzpicture}\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$x$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3) node [right] {$y$};\n    \\draw [color=red] (2.5,0) rectangle (2.25,0.25);\n    \\draw (0,0) -- (2.5,0) -- (2.5,2) -- cycle;\n    \\node at (1.25,0) [below] {$\\bm{x}$};\n    \\node at (2.5,1) [right] {$\\bm{y}$};\n    \\node at (1.25,1) [above] {$\\bm{r}$};\n    \\draw [dashed] (0,0) circle (3.2cm);\n    \\node at (0,0) [below left] {$A$};\n    \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{From Right Triangle Trig to the Coordinate Plane}\nThe biggest difference between this section and the last is that in this section, trig ratios can be positive, negative, zero, or undefined, since $x$ and $y$ can each be positive, negative, or zero. \n\\end{frame}\n\n\\section{Calculate the 6 Trig Ratios for a Point in the Coordinate Plane}\n\n\\begin{frame}{The 6 Trig Ratios}\nIn the coordinate plane, the six trig ratios become \\newline\\\\\n\\begin{center}\n    \\begin{tabular}{c|c}\n        $\\sin A = \\dfrac{y}{r}$  &   \\onslide<2->{$\\csc A = \\dfrac{r}{y}$}    \\\\[0.35in]\n        $\\cos A = \\dfrac{x}{r}$ &   \\onslide<2->{$\\sec A = \\dfrac{r}{x}$}   \\\\[0.35in]\n        $\\tan A = \\dfrac{y}{x}$ &   \\onslide<2->{$\\cot A = \\dfrac{x}{y}$}   \\\\\n    \\end{tabular}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example 1a}\nFor the given point, find the exact values of the 6 trig functions for the angle drawn in standard form.   \\newline\\\\\n(a)     \\quad $(3,-4)$\n\\begin{align*}\n\\onslide<2->{3^2 + 4^2 &= r^2}\t\\\\[8pt]\n\\onslide<3->{r &= \\sqrt{25} = 5} \\\\\n\\end{align*}\n\\begin{tabular}{p{0.4\\textwidth}p{0.4\\textwidth}}\n\\onslide<4->{$\\sin A = \\frac{-4}{5}$}\t&\t\\onslide<7->{$\\csc A = \\frac{5}{-4}$}\t\\\\[8pt]\n\\onslide<5->{$\\cos A = \\frac{3}{5}$}\t&\t\\onslide<8->{$\\sec A = \\frac{5}{3}$}\t\\\\[8pt]\n\\onslide<6->{$\\tan A = \\frac{-4}{3}$}\t&\t\\onslide<9->{$\\cot A = \\frac{3}{-4}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 1b}\n(b)\t\\quad $(-8,-15)$\n\\begin{align*}\n\\onslide<2->{8^2 + 15^2 &= r^2}\t\\\\[8pt]\n\\onslide<3->{r &= \\sqrt{289} = 17} \\\\\n\\end{align*}\n\\begin{tabular}{p{0.4\\textwidth}p{0.4\\textwidth}}\n\\onslide<4->{$\\sin A = \\frac{-15}{17}$}\t\t\t\t\t&\t\\onslide<7->{$\\csc A = \\frac{17}{-15}$}\t\\\\[8pt]\n\\onslide<5->{$\\cos A = \\frac{-8}{17}$}\t\t\t\t\t&\t\\onslide<8->{$\\sec A = \\frac{17}{-8}$}\t\\\\[8pt]\n\\onslide<6->{$\\tan A = \\frac{-15}{-8} = \\frac{15}{8}$}\t&\t\\onslide<9->{$\\cot A = \\frac{8}{15}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 1c}\n(c)\t\\quad $(-1,5)$\n\\begin{align*}\n\\onslide<2->{1^2 + 5^2 &= r^2}\t\\\\[8pt]\n\\onslide<3->{r &= \\sqrt{26}} \\\\\n\\end{align*}\n\\begin{tabular}{p{0.4\\textwidth}p{0.4\\textwidth}}\n\\onslide<4->{$\\sin A = \\frac{5}{\\sqrt{26}} = \\frac{5\\sqrt{26}}{26}$}\t&\t\\onslide<7->{$\\csc A = \\frac{\\sqrt{26}}{5}$}\t\\\\[8pt]\n\\onslide<5->{$\\cos A = \\frac{-1}{\\sqrt{26}} = \\frac{-\\sqrt{26}}{26}$}\t&\t\\onslide<8->{$\\sec A = \\frac{\\sqrt{26}}{-1} = -\\sqrt{26}$}\t\\\\[8pt]\n\\onslide<6->{$\\tan A = \\frac{5}{-1} = -5$}\t&\t\\onslide<9->{$\\cot A = \\frac{-1}{5}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\n\\section{Find the Exact Values of the Trig Ratios of Special Angles in the Coordinate Plane}\n\n\\begin{frame}\nIf we put a 45-45-90 triangle in the second quadrant of the coordinate plane, it would resemble the following:\n\n\\begin{center}\n    \\begin{tikzpicture}[scale=0.8]\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-3,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\tkzLabelAngle[pos=0.75](C,A,B){$45^\\circ$}\n    \\onslide<2->{\\draw [->, >=stealth, color=blue] (0:1) arc (0:135:1) node [midway, above right, color=blue] {$135^\\circ$};}\n    \\onslide<4->{\\draw[->, >=stealth] (-1.75,-1) node [below] {Reference Angle} -- (-0.75,0);}\n    \\end{tikzpicture}\n\\end{center}\n\\pause\n\nThe hypotenuse, $r$, would have rotated $180^\\circ - 45^\\circ = 135^\\circ$.  \n\\end{frame}\n\n\\begin{frame} \nIn the second quadrant, $x$-coordinates are negative and $y$-coordinates are positive ($r$ is always positive). Thus, the values would be\n\n\\begin{center}\n    \\begin{tikzpicture}\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelAngle[pos=0.75](C,A,B){$45^\\circ$}\n    \\node at (-1,0) [below] {$-1$};\n    \\node at (-2,1) [left] {$1$};\n    \\node at (135:1.75) [right] {$\\sqrt{2}$};\n    \\end{tikzpicture}\n\\end{center}\n\\pause\nSo $\\sin 135^\\circ = \\frac{\\sqrt{2}}{2}$, $\\cos 135^\\circ = -\\frac{\\sqrt{2}}{2}$, and $\\tan 135^\\circ = -1$.\n\\end{frame}\n\n\\begin{frame}{Example 2a}\nFind the exact values of the 6 trig functions for each of the following.\t\\newline\\\\\n(a)\t\\quad $135^\\circ = \\frac{3\\pi}{4}$\t\\newline\\\\\n\\begin{minipage}{0.25\\textwidth}\n\\begin{tikzpicture}[scale=0.8]\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\onslide<1->{\\tkzLabelAngle[pos=0.75](C,A,B){$45^\\circ$}}\n    \\node at (-1,0) [below] {$-1$};\n    \\node at (-2,1) [left] {$1$};\n    \\node at (135:1.75) [right] {$\\sqrt{2}$};\n    \\end{tikzpicture}\n\\end{minipage}\n\\begin{minipage}{0.65\\textwidth}\n\\begin{tabular}{p{0.43\\textwidth}p{0.53\\textwidth}}\n\\onslide<1->{$\\sin 135^\\circ = \\frac{\\sqrt{2}}{2}$}\t\t&\t\\onslide<2->{$\\csc 135^\\circ = \\frac{\\sqrt{2}}{1} = \\sqrt{2}$}\t\\\\[11pt]\n\\onslide<1->{$\\cos 135^\\circ = -\\frac{\\sqrt{2}}{2}$}\t&\t\\onslide<3->{$\\sec 135^\\circ = \\frac{\\sqrt{2}}{-1} = -\\sqrt{2}$}\t\\\\[11pt]\n\\onslide<1->{$\\tan 135^\\circ = -1$}\t\t\t\t\t\t&\t\\onslide<4->{$\\cot 135^\\circ = -1$}\t\\\\\n\\end{tabular}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 2b}\n(b)\t\\quad $225^\\circ = \\frac{5\\pi}{4}$\t\\newline\\\\\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-3,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\onslide<2->{\\tkzLabelAngle[pos=-0.75](B,A,C){$45^\\circ$}}\n    \\draw [->, >=stealth, color=blue] (0:1.2) arc (0:225:1.2) node [midway, above right, color=blue] {$225^\\circ$};\n\\end{tikzpicture}\n\\end{frame}\n\n\\begin{frame}{Example 2b}\n\\begin{center}\n\\begin{tikzpicture}\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelAngle[pos=-0.75](C,A,B){$45^\\circ$}\n    \\tkzLabelSegment[midway](A,C){$-1$}\n    \\tkzLabelSegment[midway, left](C,B){$-1$}\n    \\tkzLabelSegment[below](A,B){$\\sqrt{2}$}\n\\end{tikzpicture} \n\\end{center}\n\\begin{tabular}{p{0.5\\textwidth}p{0.5\\textwidth}}\n\\onslide<2->{$\\sin 225^\\circ = \\frac{-1}{\\sqrt{2}} = -\\frac{\\sqrt{2}}{2}$}\t&\t\\onslide<5->{$\\csc 225^\\circ = \\frac{\\sqrt{2}}{-1} = -\\sqrt{2}$}\t\\\\[11pt]\n\\onslide<3->{$\\cos 225^\\circ = \\frac{-1}{\\sqrt{2}} = -\\frac{\\sqrt{2}}{2}$}\t&\t\\onslide<6->{$\\sec 225^\\circ = \\frac{\\sqrt{2}}{-1} = -\\sqrt{2}$}\t\\\\[11pt]\n\\onslide<4->{$\\tan 225^\\circ = \\frac{-1}{-1} = 1$}\t\t\t\t\t\t\t&\t\\onslide<7->{$\\cot 225^\\circ = \\frac{-1}{-1} = 1$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 2c}\n(c) \\quad $315^\\circ = \\frac{7\\pi}{4}$\t\\newline\\\\\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, 2/0/C, 2/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-3,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\onslide<2->{\\tkzLabelAngle[pos=0.75](B,A,C){$45^\\circ$}}\n    \\draw [->, >=stealth, color=blue] (0:1.2) arc (0:315:1.2) node [midway, above left, color=blue] {$315^\\circ$};\n\\end{tikzpicture}\n\\end{frame}\n\n\\begin{frame}{Example 2c}\n\\begin{center}\n\\begin{tikzpicture}\n    \\tkzDefPoints{0/0/A, 2/0/C, 2/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelAngle[pos=0.75](C,A,B){$45^\\circ$}\n    \\tkzLabelSegment[midway](A,C){$1$}\n    \\tkzLabelSegment[midway, right](C,B){$-1$}\n    \\tkzLabelSegment[below, left, yshift=-0.2cm](A,B){$\\sqrt{2}$}\n\\end{tikzpicture} \n\\end{center}\n\\begin{tabular}{p{0.5\\textwidth}p{0.5\\textwidth}}\n\\onslide<2->{$\\sin 315^\\circ = \\frac{-1}{\\sqrt{2}} = -\\frac{\\sqrt{2}}{2}$}\t&\t\\onslide<5->{$\\csc 315^\\circ = \\frac{\\sqrt{2}}{-1} = -\\sqrt{2}$}\t\\\\[11pt]\n\\onslide<3->{$\\cos 315^\\circ = \\frac{1}{\\sqrt{2}} = \\frac{\\sqrt{2}}{2}$}\t&\t\\onslide<6->{$\\sec 315^\\circ = \\frac{\\sqrt{2}}{1} = \\sqrt{2}$}\t\\\\[11pt]\n\\onslide<4->{$\\tan 315^\\circ = \\frac{-1}{1} = -1$}\t\t\t\t\t\t\t&\t\\onslide<7->{$\\cot 315^\\circ = \\frac{1}{-1} = -1$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 2d}\n(d) \\quad $120^\\circ = \\frac{2\\pi}{3}$\t\\newline\\\\\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/4/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-3,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\onslide<2->{\\tkzLabelAngle[pos=0.75](B,A,C){$60^\\circ$}}\n    \\draw [->, >=stealth, color=blue] (0:1) arc (0:120:1) node [midway, above right, color=blue] {$120^\\circ$};\n\\end{tikzpicture}\n\\end{frame}\n\n\\begin{frame}{Example 2d}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -2/0/C, -2/4/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelAngle[pos=0.75](C,A,B){$60^\\circ$}\n    \\tkzLabelSegment[midway,below](A,C){$-1$}\n    \\tkzLabelSegment[midway, left](C,B){$\\sqrt{3}$}\n    \\tkzLabelSegment[right, xshift=0.2cm](A,B){$2$}\n\\end{tikzpicture} \n\\end{center}\n\\begin{tabular}{p{0.5\\textwidth}p{0.5\\textwidth}}\n\\onslide<2->{$\\sin 120^\\circ = \\frac{\\sqrt{3}}{2}$}\t\t\t\t\t&\t\\onslide<5->{$\\csc 120^\\circ = \\frac{2}{\\sqrt{3}} = \\frac{2\\sqrt{3}}{3}$}\t\\\\[11pt]\n\\onslide<3->{$\\cos 120^\\circ = \\frac{-1}{2}$}\t\t\t\t\t\t&\t\\onslide<6->{$\\sec 120^\\circ = \\frac{2}{-1} = -2$}\t\\\\[11pt]\n\\onslide<4->{$\\tan 120^\\circ = \\frac{\\sqrt{3}}{-1} = -\\sqrt{3}$}\t&\t\\onslide<7->{$\\cot 120^\\circ = \\frac{-1}{\\sqrt{3}} = -\\frac{\\sqrt{3}}{3}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 2e}\n(e) \\quad $150^\\circ = \\frac{5\\pi}{6}$\t\\newline\\\\\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -3.5/0/C, -3.5/2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-4,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\onslide<2->{\\tkzLabelAngle[pos=1](B,A,C){$30^\\circ$}}\n    \\draw [->, >=stealth, color=blue] (0:1) arc (0:150:1) node [midway, above right, color=blue] {$150^\\circ$};\n\\end{tikzpicture}\n\\end{frame}\n\n\\begin{frame}{Example 2e}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -3.5/0/C, -3.5/2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelSegment[below](A,C){$-\\sqrt{3}$}\n    \\tkzLabelSegment[left](C,B){1}\n    \\tkzLabelSegment[above, xshift = 0.2cm](A,B){2}\n    \\tkzLabelAngle[pos=1](B,A,C){$30^\\circ$}\n\\end{tikzpicture}\n\\end{center}\n\\begin{tabular}{p{0.5\\textwidth}p{0.5\\textwidth}}\n\\onslide<2->{$\\sin 150^\\circ = \\frac{1}{2}$}\t\t\t\t\t&\t\\onslide<5->{$\\csc 150^\\circ = \\frac{2}{1} = 2$}\t\\\\[11pt]\n\\onslide<3->{$\\cos 150^\\circ = \\frac{-\\sqrt{3}}{2}$}\t\t\t&\t\\onslide<6->{$\\sec 150^\\circ = \\frac{2}{-\\sqrt{3}} = -\\frac{2\\sqrt{3}}{3}$}\t\\\\[11pt]\n\\onslide<4->{$\\tan 150^\\circ = \\frac{1}{-\\sqrt{3}} = -\\frac{\\sqrt{3}}{3}$}\t&\t\\onslide<7->{$\\cot 150^\\circ = \\frac{-\\sqrt{3}}{1} = -\\sqrt{3}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Example 2f}\n(a) \\quad $210^\\circ = \\frac{7\\pi}{6}$\t\\newline\\\\\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -3.5/0/C, -3.5/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\draw [<->, >=stealth] (-4,0) node [left] {$180^\\circ$} -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) node [below] {$270^\\circ$} -- (0,3) node [above] {$90^\\circ$};\n    \\onslide<2->{\\tkzLabelAngle[pos=-1](B,A,C){$30^\\circ$}}\n    \\draw [->, >=stealth, color=blue] (0:1.5) arc (0:210:1.5) node [midway, above right, color=blue] {$210^\\circ$};\n\\end{tikzpicture}\n\\end{frame}\n\n\\begin{frame}{Example 2f}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.7]\n    \\tkzDefPoints{0/0/A, -3.5/0/C, -3.5/-2/B}\n    \\tkzDrawPolygon[fill=yellow!40](A,B,C)\n    \\tkzMarkRightAngle[color=red](B,C,A)\n    \\tkzLabelSegment[above](A,C){$-\\sqrt{3}$}\n    \\tkzLabelSegment[left](C,B){$-1$}\n    \\tkzLabelSegment[below, xshift = 0.2cm](A,B){2}\n    \\tkzLabelAngle[pos=-1](B,A,C){$30^\\circ$}\n\\end{tikzpicture}\n\\end{center}\n\\begin{tabular}{p{0.5\\textwidth}p{0.5\\textwidth}}\n\\onslide<2->{$\\sin 210^\\circ = \\frac{-1}{2}$}\t\t\t\t\t&\t\\onslide<5->{$\\csc 210^\\circ = \\frac{2}{-1} = -2$}\t\\\\[11pt]\n\\onslide<3->{$\\cos 210^\\circ = \\frac{-\\sqrt{3}}{2}$}\t\t\t&\t\\onslide<6->{$\\sec 210^\\circ = \\frac{2}{-\\sqrt{3}} = -\\frac{2\\sqrt{3}}{3}$}\t\\\\[11pt]\n\\onslide<4->{$\\tan 210^\\circ = \\frac{-1}{-\\sqrt{3}} = \\frac{\\sqrt{3}}{3}$}\t&\t\\onslide<7->{$\\cot 210^\\circ = \\frac{-\\sqrt{3}}{-1} = \\sqrt{3}$}\t\\\\\n\\end{tabular}\n\\end{frame}\n\n\\begin{frame}{Quadrantal Angles}\nA \\alert{quadrantal angle} is an angle whose terminal side lies on an axis.  \\newline\\\\  \\pause\n\n\nFinding the values of the trig functions for quadrantal angles can be found by using any point on the axes.\n\\end{frame}\n\n\\begin{frame}{Quadrantal Angles}\nFor simplicity, we will use combinations of 0s and 1s. Below is the point we will use for $0^\\circ$.\n\\begin{center}\n    \\begin{tikzpicture}[scale=0.8]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (2,0) circle (2pt) node [below] {$(1,0)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (2,0);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n    \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Quadrantal Angles}\nSo, for $0^\\circ$, we have $x=1, \\, y=0, \\, \\text{and } r=1$. Thus  \\newline\\\\ \n\n\\begin{center}\n\\begin{tabular}{p{0.3\\textwidth}p{0.5\\textwidth}}\n    \\onslide<2->{$\\sin 0 = \\frac{0}{1} = 0$}  &\n    \\onslide<5->{$\\csc 0 = \\frac{1}{0} = \\text{undefined}$}  \\\\[18pt]\n    \\onslide<3->{$\\cos 0 = \\frac{1}{1} = 1$}  &\n    \\onslide<6->{$\\sec 0 = \\frac{1}{1} = 1$}  \\\\[18pt]\n    \\onslide<4->{$\\tan 0 = \\frac{0}{1} = 0$}  &\n    \\onslide<7->{$\\cot 0 = \\frac{1}{0} = \\text{undefined}$}   \\\\\n\\end{tabular}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}{Example 3a}\nFind the exact values of each of the 6 trig functions for the following angles.   \\newline\\\\\n(a) \\quad $90^\\circ = \\frac{\\pi}{2}$    \\newline\\\\  \\pause\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (0,2) circle (2pt) node [right] {$(0,1)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [right] {$r=1$} (0,2);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<3->{\\sin 90^\\circ &= \\frac{1}{1} = 1} \\\\[18pt]\n    \\onslide<4->{\\cos 90^\\circ &= \\frac{0}{1} = 0} \\\\[18pt]\n    \\onslide<5->{\\tan 90^\\circ &= \\frac{1}{0} = \\text{undefined}} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 3a}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (0,2) circle (2pt) node [right] {$(0,1)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [right] {$r=1$} (0,2);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<2->{\\csc 90^\\circ &= \\frac{1}{1} = 1} \\\\[18pt]\n    \\onslide<3->{\\sec 90^\\circ &= \\frac{1}{0} = \\text{undefined}} \\\\[18pt]\n    \\onslide<4->{\\cot 90^\\circ &= \\frac{0}{1} = 0} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 3b}\n    (b) \\quad $180^\\circ = \\pi$    \\newline\\\\  \\pause\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (-2,0) circle (2pt) node [below] {$(-1,0)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (-2,0);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<3->{\\sin 180^\\circ &= \\frac{0}{1} = 0} \\\\[18pt]\n    \\onslide<4->{\\cos 180^\\circ &= \\frac{-1}{1} = -1} \\\\[18pt]\n    \\onslide<5->{\\tan 180^\\circ &= \\frac{0}{-1} = 0} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 3b}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (-2,0) circle (2pt) node [below] {$(-1,0)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (-2,0);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<2->{\\csc 180^\\circ &= \\frac{1}{0} = \\text{undefined}} \\\\[18pt]\n    \\onslide<3->{\\sec 180^\\circ &= \\frac{1}{-1} = -1} \\\\[18pt]\n    \\onslide<4->{\\cot 180^\\circ &= \\frac{-1}{0} = \\text{undefined}} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 3c}\n(c) \\quad $270^\\circ = \\frac{3\\pi}{2}$    \\newline\\\\  \\pause\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (0,-2) circle (2pt) node [right] {$(0,-1)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [left] {$r=1$} (0,-2);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<3->{\\sin 270^\\circ &= \\frac{-1}{1} = -1} \\\\[18pt]\n    \\onslide<4->{\\cos 270^\\circ &= \\frac{0}{1} = 0} \\\\[18pt]\n    \\onslide<5->{\\tan 270^\\circ &= \\frac{-1}{0} = \\text{undefined}} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Example 3c}\n\\begin{minipage}{0.5\\textwidth}\n\\begin{tikzpicture}[scale=0.7]\n    \\draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};\n    \\draw [<->, >=stealth] (0,-3) -- (0,3);\n    \\draw [fill=black] (0,-2) circle (2pt) node [right] {$(0,-1)$};\n    \\draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [left] {$r=1$} (0,-2);\n    \\node at (0,3) [right] {$90^\\circ$};\n    \\node at (-3,0) [left] {$180^\\circ$};\n    \\node at (0,-3) [right] {$270^\\circ$};\n\\end{tikzpicture}\n\\end{minipage}\n\\hspace{0.35cm}\n\\begin{minipage}{0.3\\textwidth}\n\\begin{align*}\n    \\onslide<2->{\\csc 270^\\circ &= \\frac{1}{-1} = -1} \\\\[18pt]\n    \\onslide<3->{\\sec 270^\\circ &= \\frac{1}{0} = \\text{undefined}} \\\\[18pt]\n    \\onslide<4->{\\cot 270^\\circ &= \\frac{0}{-1} = 0} \\\\\n\\end{align*}\n\\end{minipage}\n\\end{frame}\n\n\\begin{frame}{Angles Not Between 0 and $360^\\circ$ or 0 and $2\\pi$}\n    For angles not within 1 standard rotation, use \\alert{coterminal angles} to bring the angle within 1 rotation and then apply the rules of the previous notes.  \\newline\\\\  \n    \n    For instance, $\\cos\\left(\\frac{9\\pi}{4}\\right) = \\cos\\left(\\frac{\\pi}{4}\\right)$\n\\end{frame}\n\n\\end{document}\n", "meta": {"hexsha": "7dff7e866edbe317ae5d591f502fbae788c51d10", "size": 21679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Trig_Functions_of_Any_Angle(BEAMER).tex", "max_stars_repo_name": "BryanBain/Trig_BEAMER", "max_stars_repo_head_hexsha": "3639d0202fc691738d26f922d9e84f0a0d62b42a", "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": "Trig_Functions_of_Any_Angle(BEAMER).tex", "max_issues_repo_name": "BryanBain/Trig_BEAMER", "max_issues_repo_head_hexsha": "3639d0202fc691738d26f922d9e84f0a0d62b42a", "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": "Trig_Functions_of_Any_Angle(BEAMER).tex", "max_forks_repo_name": "BryanBain/Trig_BEAMER", "max_forks_repo_head_hexsha": "3639d0202fc691738d26f922d9e84f0a0d62b42a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-26T15:49:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-26T15:49:06.000Z", "avg_line_length": 40.5214953271, "max_line_length": 200, "alphanum_fraction": 0.5741039716, "num_tokens": 9397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.6149131712043829}}
{"text": "\n\\subsection{The infintesimal jackknife}\n\n\\subsubsection{The jackknife as a weighting}\n\nIn the jackknife we calculate the statistic leaving one observation out.\n\nThis is the same as weighting observations and giving one a weighting of \\(0\\) and the others \\(1\\).\n\n\\subsubsection{The infintesimal jackknife}\n\nFor the infintesimal jackknife we reduce the weight not to \\(0\\), but by an infintesimal amount.\n\n", "meta": {"hexsha": "a11501f3ca6791a6ecd6ba8579a5ca177e8a86f3", "size": 406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/jackknife/01-02-jackknifeInf.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-02-jackknifeInf.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-02-jackknifeInf.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.0, "max_line_length": 100, "alphanum_fraction": 0.7832512315, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6148911577587991}}
{"text": "\\chapter{Kernel density estimation}\n\\section{Bandwidth and Kernel function}\nIn this chapter we are dealing with marks secured by students in various subject, along with  explanatory variables about the students viz., gender, ethnicity etc.. For our analysis for student's performance together with scores in mathematics, reading and writing tests, we consider students attendance for the test preparation course. We drop rest of the variables. Following is the sample for first few entries of the dataset;\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{llrrr}\n  \\hline\n & test preparation course & math score & reading score & writing score \\\\ \n  \\hline\n1 & none &  72 &  72 &  74 \\\\ \n  2 & completed &  69 &  90 &  88 \\\\ \n  3 & none &  90 &  95 &  93 \\\\ \n  4 & none &  47 &  57 &  44 \\\\ \n  5 & none &  76 &  78 &  75 \\\\ \n  6 & none &  71 &  83 &  78 \\\\ \n  7 & completed &  88 &  95 &  92 \\\\ \n  8 & none &  40 &  43 &  39 \\\\ \n  9 & completed &  64 &  64 &  67 \\\\ \n  10 & none &  38 &  60 &  50 \\\\ \n   \\hline\n\\end{tabular}\n\\end{table}\n\nIn this exercise we are suppose to implement kernel density estimation. The data entries i.e. math score are integers variables. Kernel density estimation help us visualize the “shape” of data, even though its discrete. Essentially it is sort of continuous replacement for the discrete histogram. Kernel estimation uses a weighted sum of observations dependent on their distance from the variable. The precise definition is as follows, for the given data $X_1, X_2,..., X_n$, a kernel density estimator is \n$$\\widehat{f}_{n,h}(x)= \\frac{1}{nh}\\sum_{1 = j}^n K\\left(\\frac{x-X_j}{h}\\right), \\: x\\in \\RR .$$ \nwhere $K: \\RR \\rightarrow \\RR$, such that $\\int_{-\\infty}^{\\infty}K(x)dx=1$ is known as kernel and $h>0$ is called the bandwidth. $h$ is smoothing parameter which basically governs how many distinct observations are taken into account around certain location. Thus it has a strong influence on the resulting estimate. Examples of some classical kernels is illustrated below in Figure \\ref{fig:types_kernels8}.\n    \n\\begin{figure}[thb]\n\\centering\n\\includegraphics[width=0.75\\textwidth, keepaspectratio]{ex8/types_kernels.png}\n\\caption{Classical examples of kernels often used for density estimation. }\n\\label{fig:types_kernels8}\n\\end{figure}\n\nTo visualise and examine the influence of the choice of bandwidth and kernel we have considered the math score variable from the data. First we fit a kernel density with different bandwidths using the Epanechnikov kernel (See Figure \\ref{fig:diff_bandwidth8}) and then use different kernels with a fixed bandwidth Figure\\ref{fig:diff_ker8} ). We can clearly see the influence of the choice of bandwidth.  The estimated curves get smoother with higher and higher $h$. For bandwidth $= 2$ it fluctuates highly. \nFor the values  of $h$ between $5$  and  $12$ seems reasonable where as for for  higher values, like $30$ density curve gets  too  smooth and it certainly does not represent the shape of the data distribution anymore. Since, visually it appears that the most reasonable bandwidth lies between $5$ and $12$, I have fixed $h= 8$ for the next analysis (See Figure \\ref{fig:diff_ker8}). We will now compare different kernels choices with a fix bandwidth $h= 8$.\n\n\\begin{figure}[tbh]\n\\centering\n\\begin{subfigure}[c]{\\textwidth}\n\\includegraphics[width=0.93\\textwidth, keepaspectratio]{ex8/diff_bandwidths.png}\n\\subcaption{Epanechnikov kernel with different bandwidths.}\n\\label{fig:diff_bandwidth8}\n\\end{subfigure}\n\\begin{subfigure}[c]{\\textwidth}\n\\includegraphics[width=0.98\\textwidth, keepaspectratio]{ex8/diff_ker.png}\n\\subcaption{Different kernels with fixed bandwidth $h=8$.}\n\\label{fig:diff_ker8}\n\\end{subfigure}\n\\caption{Kernel density estimations for the math score  (first plot) and kernels (second plot).}\n\\label{6fit}\n\\end{figure}\n\n%Comment on the effect of the bandwidth and of the kernel function on kernel density estimators\nIf we observe closely Figure \\ref{fig:types_kernels8}, we can see that, the different shapes of the kernels shows how observations with certain weights at different distances influence the height of the density estimation at specific points. Therefore, the shape and some basic properties of the resulting density estimations depend highly on the choice of the kernel. The rectangular kernel for example will always result in a piece-wise constant estimation, which is not continuous.  The triangular kernel will give us a piece-wise linear density and the Gaussian kernel will result in smooth estimations. In Figure \\ref{fig:diff_ker8} we can see that for the rectangular kernel the result is a step function, where as the rest of the kernels seem smoother. But as mentioned before the curve for the triangular kernel is piece-wise linear. Rectangular, triangular and Epanechnikov look quite similar with respect to the shape of the overall distribution. The Gaussian kernel produces a flatter curve that puts more mass to the tails. This might be because, of the differences in support of kernels. The support of the Gaussian kernel $\\RR$ and its $ [ -1,1] $ for the other kernels. Thus, as we can also see in Figure \\ref{fig:types_kernels8} Gaussian kernel puts more mass to the tails.\n\n\\section{Cross validation for optimal bandwidth}  \nNow we want to consider a more formal approach to examine the best bandwidth. Above we just did a graphical examination. To get the best fitting curve a common approach is trying to minimise the mean integrated square error (MISE) for the estimator $\\hat{f}_{n,h}(x)$ of $f(x)$, which is given by $$MISE(\\hat{f}_{n,h})=E\\left[\\int\\left(\\hat{f}_{n,h}(x)-f(x)\\right)^2dx\\right].$$ Because the real $f$ is unknown one minimises an unbiased estimator of the $h$-dependent part of the MISE, called the cross-validation criterion: $$CV(h)=\\int\\left(\\hat{f}_{n,h}(x)\\right)^2dx-\\frac{2}{n(n-1)h}\\sum_{i=1}^{n} \\sum_{j\\neq i} K\\left(\\frac{X_j - X_i}{h}\\right).$$\n\\begin{figure}[!tb]\n\\centering\n\\includegraphics[width=0.9\\textwidth, keepaspectratio]{ex8/CV1.png}\n\\caption{CV values for 40 different bandwidths. Red point shows minimum of the curve. Other points show the results for the \\texttt{optimize} function in R with different limits (see legend).}\n\\label{6CV1}\n\\end{figure} \n\nImplementing a function computing the CV for a given estimation we can use the minimising $h_{CV}=\\argmin _{h>0} CV(h)$.\nAfterwards we compared the results with the functions \\texttt{bw.ucv} and \\texttt{bw.bcv} of the package \\texttt{density}, which compute the optimal bandwidth for an unbiased (\\texttt{ucv}) or biased (\\texttt{bcv}) CV implementation for Gaussian kernels. \nTherefore I used the Epanechnikov kernel as well as the Gaussian kernel in my implementation to compare all results for the maths score. To find the minimizer of my function, I used the R function \\texttt{optimize}. Before comparing the optimisation of my own CV function a little note about the disadvantages of using \\texttt{optimize} here is important. \nTo get a first idea of the shape of CV for different $h$ as a curve I took 40 equidistant points in the interval $[1,25]$ - because it seemed as a (maximal) reasonable region for bandwidths in this case -  and computed CV there. Afterwards I took the minimum out of this observations as first reference point ($h=1.62$). After using the R implemented optimisation with limits 0 and 30, I was surprised by the result ($h=11.50$). As \\texttt{optimize} just searches for local minima and starting points for the iteration are chosen as a golden section distance between the given limits, the result also depends highly on those borders. Obviously CV is a strongly fluctuating function as I got different results for every trial, none of them was near the first, say, 'scanned minimum'. Figure \\ref{6CV1} shows the results. All in all, without an analytical examination of CV as a function one cannot be sure to really found the optimal bandwidth or even to be close to it. In the following I won't discuss this issue any more- I will use a combined strategy by first scanning the interval $[1, 20]$ with 40 points to get the area of small values visually and by taking the minimum. Afterwards I will use \\texttt{optimize} limited to this region to get a local minimum. This should in total result in a somehow precise and at least acceptable minimum. The results for all three tests and the different methods are shown together in Table \\ref{6table}. For the math score and the best bandwidth with a Epanechnikov kernel we use the above optimal $h=1.62$. \n\\begin{figure}[p]\n\\centering\n\\includegraphics[width=\\textwidth, keepaspectratio]{ex8/CVplots.png}\n\\caption{CV against $h$ for math score and Gaussian kernel (first row), reading score (second row) and writing score (third row). Last two for Epanechnikov  kernel (left) and Gaussian kernel (right)}\n\\label{6CVs}\n\\end{figure}\n\nFirst, observe (see Figure \\ref{6CVs}) that for the Gaussian kernel the problem of fluctuating CV function is not that worse but the usage of the \\texttt{optimize} function still improves the optimal bandwidth a bit. For the Epanechnikov kernel we have the same problem for every test. All in all the CV curves look very similar for math, reading and writing score. Therefore we get quite similar results for optimal bandwidths. As expected the values of my own optimisation for the Gauss kernel are similar to those of the R functions but differ from the optimal bandwidth for the Epanechnikov kernel. For every score the resulting CVs just differ on the presented scale between the kernels where always the Epanechnikov kernel gives a better result. Therefore we use this bandwidth an the Epanechnikov kernel for the last part of the exercise. \n\n\\begin{table}[!t]\n\\centering\n\\begin{tabular}{lrrrrrrrr}\n  \\hline\n & \\multicolumn{2}{r}{Epa} &  \\multicolumn{2}{r}{Gau}&  \\multicolumn{2}{r}{\\texttt{bw.bcv}}&  \\multicolumn{2}{r}{\\texttt{bw.ucv}} \\\\  \n\\hline\n & h & CV & h & CV & h & CV & h & CV \\\\ \n  \\hline\nmath & 1.62 & -0.0197 & 4.83 & -0.0186 & 4.26 & -0.0186 & 4.65 & -0.0186 \\\\ \n  reading & 1.41 & -0.0212 & 4.19 & -0.0191 & 4.40 & -0.0191 & 3.77 & -0.0191 \\\\ \n  writing & 1.41 & -0.0203 & 4.52 & -0.0184 & 4.18 & -0.0184 & 4.28 & -0.0184 \\\\ \n   \\hline\n\\end{tabular}\n\\caption{Optimal bandwidths $h$ and corresponding CV for math, reading and writing score and different methods. First two columns are optimum of self-written function with Epanechnikov kernel (Epa) and Gaussian kernel (Gau) respectively, last two columns with R function in the package \\texttt{density}.}\n\\label{6table}\n\\end{table}\n\n\n\\section{Comparison of groups}\nNow we use the kernel density estimation for a comparison of those students attending a preparation course and those that did not. Therefore we fit a curve for both groups using the optimal bandwidth we got in the previous examinations and the Epanechnikov kernel. For the bandwidth we use a common value equal to the mean of the three optimal bandwidths (this is just for a simplification of the code and does not change the results crucially). \n\nThe result is shown in Figure \\ref{6groups}. I decided to plot the histograms above each other, so that there is no confusion about the positioning and because one can still distinguish the bars with just two groups. We see that for the math score the whole distribution of scores is not changed very much in the shape but just shifted to the right, i.e. to better grades. For the other two scores we can recognise that the distribution of students with the preparation course is a bit more left skewed. This is just slightly visible for the reading score and a bit more distinct for the writing score. This is probably due to the fact that the student get better in total but the limit of the score is at 100. Psychologists call this effect \\textit{ceiling effect}. This is maybe also the reason why the distribution has a smaller variation, especially for the writing score again. Summing up, we recognize better performance of students doing a preparation course. This is especially visible for the writing score. Apparently, one cannot train maths as easily as writing.\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[width=\\textwidth, keepaspectratio]{ex8/groups.png}\n\\caption{Histogram and kernel density estimate for two groups of students in different colors and the three scores, math (left), reading (middle) and writing (right).}\n\\label{6groups}\n\\end{figure} \n", "meta": {"hexsha": "e6a5933b2f9583594502406d5d864d8de139c014", "size": 12406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex8/ex8.tex", "max_stars_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_stars_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex8/ex8.tex", "max_issues_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_issues_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex8/ex8.tex", "max_forks_repo_name": "dnanad/Advanced-Statistical-Data-Analysis", "max_forks_repo_head_hexsha": "09114b8840466cc3637bd447ff9adf584c811cde", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 114.8703703704, "max_line_length": 1552, "alphanum_fraction": 0.7628566823, "num_tokens": 3231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.614891149619823}}
{"text": "\\section{Taylor Series}\\label{sec:taylorseries}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\nWe have seen that some functions can be represented as series, which\nmay give valuable information about the function. So far, we have seen\nonly those examples that result from manipulation of our one\nfundamental example, the geometric series. We would like to start with\na given function and produce a series to represent it, if possible.\n\nSuppose that $\\ds f(x)=\\sum_{n=0}^\\infty a_nx^n$ on some interval of\nconvergence centered at 0. Then we know that we can compute derivatives of $f$ by\ntaking derivatives of the terms of the series. Let's look at the first\nfew in general:\n\\begin{align*}\n  f'(x)&=\\sum_{n=1}^\\infty n a_n x^{n-1}=a_1 + 2a_2x+3a_3x^2+4a_4x^3+\\cdots\t\\\\\n  f''(x)&=\\sum_{n=2}^\\infty n(n-1) a_n x^{n-2}=2a_2+3\\cdot2a_3x\n    +4\\cdot3a_4x^2+\\cdots\t\\\\\n  f'''(x)&=\\sum_{n=3}^\\infty n(n-1)(n-2) a_n x^{n-3}=3\\cdot2a_3\n    +4\\cdot3\\cdot2a_4x+\\cdots\t\\\\\n\\end{align*}\n\nBy examining these it's not hard to discern the general pattern. The\n$k$th derivative must be\n\\begin{align*}\n  f^{(k)}(x)&=\\sum_{n=k}^\\infty n(n-1)(n-2)\\cdots(n-k+1)a_nx^{n-k}\t\\\\\n  &=k(k-1)(k-2)\\cdots(2)(1)a_k+(k+1)(k)\\cdots(2)a_{k+1}x+{}\t\\\\\n  &\\qquad {}+(k+2)(k+1)\\cdots(3)a_{k+2}x^2+\\cdots\t\\\\\n\\end{align*}\nWe can express this more clearly by using factorial notation:\n\\[\n  f^{(k)}(x)=\\sum_{n=k}^\\infty {n!\\over (n-k)!}a_nx^{n-k}=\n  k!a_k+(k+1)!a_{k+1}x+{(k+2)!\\over 2!}a_{k+2}x^2+\\cdots\n\\]\n\nWe can solve for $a_n$ by substituting $x=0$ in the formula for $f^{(k)}(x)$:\n\\[f^{(k)}(0)=k!a_k+\\sum_{n=k+1}^\\infty {n!\\over (n-k)!}a_n0^{n-k}=k!a_k,\\]\n\\[a_k={f^{(k)}(0)\\over k!}.\\]\nNote that the original series for $f$ yields $f(0)=a_0$.\n\nSo if a function $f$ can be represented by a series, we can easily find such a series.\nGiven a function $f$, the series\n\\[\\sum_{n=0}^\\infty {f^{(n)}(0)\\over n!}x^n\\]\nis called the \\dfont{Maclaurin \nseries} for $f$.\n\n\\begin{example}{Maclaurin Series}{MacSeriesOne}\nFind the Maclaurin series for $f(x)=1/(1-x)$.\n\\end{example}\n\\begin{solution}\nWe need to\ncompute the derivatives of $f$ (and hope to spot a pattern).\n\\begin{align*}\n  f(x)&=(1-x)^{-1}\t\\\\\n  f'(x)&=(1-x)^{-2}\t\\\\\n  f''(x)&=2(1-x)^{-3}\t\\\\\n  f'''(x)&=6(1-x)^{-4}\t\\\\\n  f^{(4)}(x)&=4!(1-x)^{-5}\t\\\\\n  &\\vdots\t\\\\\n  f^{(n)}(x)&=n!(1-x)^{-n-1}\t\\\\\n\\end{align*}\n\nSo\n\\[a_n={f^{(n)}(0)\\over n!}={n!(1-0)^{-n-1}\\over n!}=1\\]\nand the Maclaurin series is\n\\[\\sum_{n=0}^\\infty 1\\cdot x^n=\\sum_{n=0}^\\infty x^n,\\]\nthe geometric series.\n\\end{solution}\n\nA warning is in order here. Given a function $f$ we may be able to\ncompute the Maclaurin series, but that does not mean we have found a\nseries representation for $f$. We still need to know where the series\nconverges, and if, where it converges, it converges to $f(x)$. While\nfor most commonly encountered functions the Maclaurin series does\nindeed converge to $f$ on some interval, this is not true of all\nfunctions, so care is required.\n\nAs a practical matter, if we are interested in using a series to\napproximate a function, we will need some finite number of terms of\nthe series. Even for functions with messy derivatives we can compute\nthese using computer software like Sage. If we want to describe a series\ncompletely, we would like to be able to write down a formula for a typical\nterm in the series. Fortunately, a few of the most important functions are very\neasy.\n\n\\begin{example}{Maclaurin Series}{MacSeriesTwo}\nFind the Maclaurin series for $\\sin x$.\n\\end{example}\n\\begin{solution}\nComputing the first few derivatives is simple: $f'(x)=\\cos x$, $f''(x)=-\\sin x$,\n$f'''(x)=-\\cos x$, $\\ds f^{(4)}(x)=\\sin x$, and then the pattern\nrepeats. The values of the derivative when $x=0$ are:\n1, 0, $-1$, 0, 1, 0, $-1$, 0,\\dots, and so the Maclaurin series is\n\\[\n  x-{x^3\\over 3!}+{x^5\\over 5!}-\\cdots=\n  \\sum_{n=0}^\\infty (-1)^n{x^{2n+1}\\over (2n+1)!}.\n\\]\n\nWe should always determine the radius of convergence:\n\\[\n  \\lim_{n\\to\\infty} {|x|^{2n+3}\\over (2n+3)!}{(2n+1)!\\over |x|^{2n+1}}\n  =\\lim_{n\\to\\infty} {|x|^2\\over (2n+3)(2n+2)}=0,\n\\]\nso the series converges for every $x$. Since it turns out that this\nseries does indeed converge to $\\sin x$ everywhere, we have a series\nrepresentation for $\\sin x$ for every $x$.\n\\end{solution}\n\nSometimes the formula for the $n$th derivative of a function $f$ is\ndifficult to discover, but a combination of a known Maclaurin series\nand some algebraic manipulation leads easily to the Maclaurin series\nfor $f$.\n\n\\begin{example}{Maclaurin Series}{MacSeriesThree}\nFind the Maclaurin series for $x\\sin(-x)$.\n\\end{example}\n\\begin{solution}\nTo get from $\\sin x$ to $x\\sin(-x)$ we substitute $-x$ for $x$ and\nthen multiply by $x$. We can do the same thing to the series for $\\sin\nx$:\n\\[\n  x\\sum_{n=0}^\\infty (-1)^n{(-x)^{2n+1}\\over (2n+1)!}\n  =x\\sum_{n=0}^\\infty (-1)^{n}(-1)^{2n+1}{x^{2n+1}\\over (2n+1)!}\n  =\\sum_{n=0}^\\infty (-1)^{n+1}{x^{2n+2}\\over (2n+1)!}.\n\\]\n\\end{solution}\n\nAs we have seen, a power series can be centered at a point\nother than zero, and the method that produces the Maclaurin series can\nalso produce such series.\n\n\\begin{example}{Taylor Series}{TaylorSeriesOne}\nFind a series centered at $-2$ for $1/(1-x)$.\n\\end{example}\n\\begin{solution}\nIf the series is $\\ds\\sum_{n=0}^\\infty a_n(x+2)^n$ then looking at the\n$k$th derivative:\n$$k!(1-x)^{-k-1}=\\sum_{n=k}^\\infty {n!\\over (n-k)!}a_n(x+2)^{n-k}$$\nand substituting $x=-2$ we get\n$\\ds k!3^{-k-1}=k!a_k$ and $\\ds a_k=3^{-k-1}=1/3^{k+1}$, so the series is\n$$\\sum_{n=0}^\\infty {(x+2)^n\\over 3^{n+1}}.$$\n\\end{solution}\n\nSuch a series is called the \n\\dfont{Taylor series} for the function,\nand the general term has the form\n\\[{f^{(n)}(a)\\over n!}(x-a)^n.\\]\n\nA Maclaurin series is simply a Taylor series with $a=0$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:taylorseries}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFor each function, find the Maclaurin series or Taylor series centered\nat $a$, and the radius of convergence.\n\n\\begin{enumerate}\n\t\\item $\\cos x$\n\t\\item $\\ds e^x$\n\t\\item $1/x$, $a=5$\n\t\\item $\\ln x$, $a=1$\n\t\\item $\\ln x$, $a=2$\n\t\\item $\\ds 1/x^2$, $a=1$\n\t\\item $\\ds 1/\\sqrt{1-x}$\n\t\\item Find the first four terms of the Maclaurin series for $\\tan\n\tx$ (up to and including the $\\ds x^3$ term).\n\t\\item Use a combination of Maclaurin series and algebraic\n\tmanipulation to find a series centered at zero for\n\t$\\ds x\\cos (x^2)$.\n\t\\item Use a combination of Maclaurin series and algebraic\n\tmanipulation to find a series centered at zero for\n\t$\\ds xe^{-x}$.\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item $\\ds\\sum_{n=0}^\\infty (-1)^n x^{2n}/(2n)!$, $R=\\infty$\n\t\\item $\\ds\\sum_{n=0}^\\infty x^n/n!$, $R=\\infty$\n\t\\item $\\ds\\sum_{n=0}^\\infty (-1)^n{(x-5)^n\\over 5^{n+1}}$, $R=5$\n\t\\item $\\ds\\sum_{n=1}^\\infty (-1)^{n-1}{(x-1)^n\\over n}$, $R=1$\n\t\\item $\\ds\\ln(2)+\\sum_{n=1}^\\infty (-1)^{n-1}{(x-2)^n\\over n 2^n}$, $R=2$\n\t\\item $\\ds\\sum_{n=0}^\\infty (-1)^n(n+1)(x-1)^n$, $R=1$\n\t\\item $\\ds1+\\sum_{n=1}^\\infty {1\\cdot3\\cdot5\\cdots(2n-1)\\over\n\t\tn!2^n} x^n=1+\\sum_{n=1}^\\infty {(2n-1)!\\over 2^{2n-1}(n-1)!\\,n!}x^n$, $R=1$\n\t\\item $\\ds x+x^3/3$\n\t\\item $\\ds\\sum_{n=0}^\\infty (-1)^n x^{4n+1}/(2n)!$\n\t\\item $\\ds\\sum_{n=0}^\\infty (-1)^n x^{n+1}/n!$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "714bf519a7e580edaf362a9a005ab9c8de5b3d39", "size": 7353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-10-taylor-series.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": "9-sequences-and-series/9-10-taylor-series.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": "9-sequences-and-series/9-10-taylor-series.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": 31.5579399142, "max_line_length": 86, "alphanum_fraction": 0.6368829049, "num_tokens": 2912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6148911407781049}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[english]{babel}\n\\usepackage{graphicx}\n\\usepackage{multicol}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\\usepackage{amsthm}\n\\usepackage{geometry}\n\\geometry{a4paper} \n\\usepackage{fancyhdr}\n\\usepackage{xcolor}\n\\usepackage{amssymb}\n\\usepackage{multicol}\n\\usepackage{float}\n\\theoremstyle{definition}\n\\newtheorem{definition}{Defintion}[section]\n\\newtheorem{exmp}{Example}[section]\n\\newtheorem{theorem}{Theorem}\n\n\\begin{document}\n\\author{Fractals}\n\\title{\\textbf{Functions}}\n\\maketitle\n\\tableofcontents\n\\noindent\n\\section{Introduction}\n\\subsection{Defintions}\n\n\\begin{definition}\n    A function \\(f\\) from a set \\(X\\) to a set \\(Y\\) is a relation that assigns to each element in\n    set \\(X\\) exactly one element in set \\(Y\\).\n\\end{definition}\n\n\\begin{definition}\n    The domain is the set of \\(X\\) (a.k.a. the input).\n\\end{definition}\n\n\\begin{definition}\n    The range is a subset of Y (a.k.a. the output).\n\\end{definition}\n\n\\subsection{Existence of a Function}\n\\begin{theorem}[\\textbf{Vertical Line Test}]\n    if you can draw a Vertical line that passes through more than one point of a\n    relation on a grap, it's not a function, if you cannot, it's a function.\n\n\\end{theorem}\n\n\n\\begin{exmp}\n    what the domain and range of the function \\(f(x) = \\sqrt{16 - x^2}\\)?\n\\end{exmp}\n\n\\(sloution\\) Note that if \\(a < 0 \\), then \\( \\sqrt{a}\\) is undefined for reals,\nThus, \\(16 - x^2 \\ge 0 \\Rrightarrow \\) \\framebox[\\width]{\n    \\(-4 \\le x \\le 4\\)\n} since \\(x^2 \\ge 0\\), we have that \\(0 \\le 16 - x^2 \\le 16\\),\nso the range is \\framebox[\\width]{ \\(0 \\le y \\le 4\\) }\n\n\n\\section{Combinations of Functions}\n\\begin{theorem}[\\textbf{common function Combinations}]\n    The following are some common combinations of functions:\n    \\begin{itemize}\n        \\item \\textbf{Sum} \\((f+g)(x) = f(x) + g(x)\\)\n        \\item \\textbf{Differnce} \\((f-g)(x) = f(x) - g(x)\\)\n        \\item \\textbf{Product} \\((fg)(x) = f(x)g(x)\\)\n        \\item \\textbf{Quotient} \\((\\dfrac{f}{g} )(x) = \\dfrac{f(x)}{g(x)} \\)\n              where \\(g(x) \\ne 0\\)\n        \\item \\textbf{Compostion} \\((f\\circ g)(x) = f(g(x))\\)\n    \\end{itemize}\n\n\\end{theorem}\n\n\\begin{exmp}\n    if \\(f(x) = 2x + 3\\) and \\(\\quad g(x) = 2x - 3\\), then what is \\(fg(4)\\)?\n\\end{exmp}\n\\(sloution\\) \\( (fg)(x) = (2x+3)(2x-3) \\) Thus \\((fg)(4) = 55\\).\n\\subsection{Domain and Range of a Composite Function}\nThe domain of a composite function is the intersection of domains of the starting\nand final function.\n\n\\noindent\nThe range of a composite function is the range of the final function restricted by the\nstarting function.\n\n\\begin{exmp}\n    let \\(f(x) = \\dfrac{1}{x+2}\\) and \\( \\dfrac{x}{x-3} \\).\n    Then \\(g(x)\\) is the starting function and \\( f(g(x)) \\) is the final\n    function. Find the domain and range of \\(f(g(x))\\).\n\\end{exmp}\n\n\\noindent\n\\(sloution\\) \\(f(g(x)) = \\dfrac{1}{\\dfrac{x}{x-3} + 2}\\) so \\(x \\ne 3\\),\nimpleing the domain is \\framebox[\\width]{ \\(x \\ne 2,3\\) }.\n\n\\begin{exmp}\n    If \\(f(x) = \\sqrt{x}\\) and \\(g(x) = x - 1\\), what is the domain and range\n    of \\((g\\circ f)(x)\\)?\n\\end{exmp}\n\\noindent\n\\(sloution\\) \\((g\\circ f)(x) = \\sqrt{x} - 1\\) it's obivious that \\(x \\ge 0\\),\nand all other values work, so the domain is \\framebox[\\width]{ \\(0 \\le x < \\infty \\ \\)}\n. Since \\( \\sqrt{x} \\ge 0\\)we have \\((g\\circ f)(x) \\ge -1\\), with no other restrictions,\nso the range is \\framebox[\\width]{ \\([-1,\\infty] \\) }.\n\n\\section{Types of Functions}\n\\subsection{Piecewise-Defined Function}\nA piecewise function is a function that is defined by two or more equations over a\nspecified domain.\n\n\\begin{exmp}\n    let \\(f(x) = |x|\\) Then\n    \\[ f(x) =\n        \\begin{cases}\n            x  & \\text{if } x \\ge 0 \\\\\n            -x & \\text{if } x < 0\n        \\end{cases}\n    \\]\n\n\\end{exmp}\n\n\\begin{exmp}\n    What are the domain and range of the piecewise function as follows?\n    \\[\n        f(x) =\n        \\begin{cases}\n            x^2 + 1 & x < 0   \\\\\n            x - 1   & x \\ge 0\n        \\end{cases}\n    \\]\n\\end{exmp}\n\n\\(sloution\\). The domain includes \\(x < 0 \\) and \\(x \\ge 0\\),\nwhich is all values, so the domain is\n\\framebox[\\width]{ \\((-\\infty, \\infty)\\) }. for \\(x \\ge 0\\), we have \\(f(x) = x - 1\\),\nso the range is \\(y \\ge -1\\). For \\(x < 0\\) we have \\(f(x) = x^2 + 1\\), so the range is \\(y > 1\\).\nThus the range together is \\framebox[\\width]{ \\([-1, \\infty )\\) }\n\n\\section{Properties of Functions}\n\\subsection{Odd and Even Functions}\nA function \\(f\\) is even if \\(f(x) = f(-x)\\)\n\n\n\\begin{figure}[ht]\n    \\begin{small}\n        \\begin{center}\n            \\includegraphics[width=0.75\\textwidth]{../out/even.png}\n        \\end{center}\n        \\caption{Graph of an even function.}\n        \\label{fig: Even Function}\n    \\end{small}\n\\end{figure}\n\n\\pagebreak\nA function \\(f\\) is odd if \\(f(x) = - f(-x)\\)\n\n\\begin{figure}[H]\n    \\begin{small}\n        \\begin{center}\n            \\includegraphics[width=0.75 \\textwidth]{../out/odd.png}\n        \\end{center}\n        \\caption{Graph of an odd function.}\n        \\label{fig: Odd Function}\n\n    \\end{small}\n\\end{figure}\n\nNote that\n\\begin{itemize}\n    \\item Reflecting an even function across the y-axis yields the same function, and\n    \\item Rotating an odd function across the x-axis also yields the same function.\n\\end{itemize}\n\n\\begin{theorem}[Parity of Functions Comes From Its Components]\n    if \\(h(x) = f(x) + g(x)\\)then\n    \\(h(x)\\) is even if \\(f(x)\\) and \\(g(x)\\) are both even,\n    and \\(h(x)\\) is odd if \\(f(x)\\) and \\(g(x)\\) are both odd.\n\\end{theorem}\n\n\\begin{exmp}\n    Is \\(f(x) = x^3 - 2x\\) odd, even, neither?  \\\\\n\n    \\(sloution\\) Note thr \\(f(-x) = -x^3 + 2x = -f(x)\\) implying it's odd.\n\\end{exmp}\n\n\\section{Inverse Functions}\nAn inverse function is a function that reverses function \\(f\\).\nIf \\(f\\) is a function mapping \\(x\\) to \\(y\\),\nthen the inverse function of \\(f\\) maps \\(y\\) back to x. The\ninverse function of f is usually denoted by \\(f^{-1}\\)\n\n\\begin{itemize}\n    \\item If \\(f^{-1}\\) exists, Then \\(f^{-1}(f(x)) = f(f^{-1}(x)) = x\\).\n    \\item The graph of the inverse is the graph of the function reflected across\n          \\(y = x\\).2\n\\end{itemize}\n\n\n\\begin{exmp}\n    what's the inverse function of \\(f(x) = \\dfrac{3x-5}{2}? \\)\n    \\\\\n\n    \\(sloution\\) if we switch \\(x\\) and \\(y\\) we get \\(x = \\dfrac{3y-5}{2}\n    \\Rightarrow \\) \\framebox[1.1\\width]{\\(f^{-1}(x) = \\dfrac{2x+5}{3}\\)}.\n\\end{exmp}\n\\subsection{Existence of an Inverse Function}\n\\begin{definition}[One to one]\n    If a function satisfies the property that each x-value corresponds to one y-value, and\n    each y-value corresponds to one x-value, then the function is one-to-one.\n\\end{definition}\n\\begin{theorem}[Inverse Function Criterion]\n    If a function \\(f\\) is one-to-one, then its inverse is a function. More specifically, f is\n    one-to-one if \\(f\\) is increasing/decreasing on its entire domain\n\\end{theorem}\n\\begin{theorem}[Horizontal Line Test]\n    If you can draw a horizontal line passing through more than one point of a function\n    on a graph, its inverse is not a function. If you cannot, it is a function.\n\\end{theorem}\nThis makes a lot of sense, since the graph of the inverse is just the function flipped\nacross the \\(y = x\\) line. This also makes it a lot easier to draw graphs.\n\n\\begin{exmp}\n    Does the function \\(f(x) = \\sqrt{x-2} + 3\\) have an inverse function?\n\n    \\begin{figure}[H]\n        \\begin{small}\n            \\begin{center}\n                \\includegraphics[width=0.75 \\textwidth]{../out/inverse.png}\n            \\end{center}\n            \\caption{Graph of square root function.}\n            \\label{fig: invetable Function}\n\n        \\end{small}\n    \\end{figure}\n\\end{exmp}\n\\section{problmes}\nTO BE ADDED \n\\end{document}\n", "meta": {"hexsha": "e54f45da8aed93c79d97e7a02eabe80d46a4495b", "size": 7665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "basic/functions/src/functions.tex", "max_stars_repo_name": "GUC-Fractals/math-curriculum", "max_stars_repo_head_hexsha": "a11336def018106bd31e56e5eb9ac9225d4a072a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-06T09:36:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-06T09:36:30.000Z", "max_issues_repo_path": "basic/functions/src/functions.tex", "max_issues_repo_name": "GUC-Fractals/math-curriculum", "max_issues_repo_head_hexsha": "a11336def018106bd31e56e5eb9ac9225d4a072a", "max_issues_repo_licenses": ["MIT"], "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/functions/src/functions.tex", "max_forks_repo_name": "GUC-Fractals/math-curriculum", "max_forks_repo_head_hexsha": "a11336def018106bd31e56e5eb9ac9225d4a072a", "max_forks_repo_licenses": ["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.9375, "max_line_length": 98, "alphanum_fraction": 0.6194390085, "num_tokens": 2522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6148911407781049}}
{"text": "% Created 2018-04-11 mié 19:09\n\\documentclass[a4paper]{scrartcl}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{fixltx2e}\n\\usepackage{graphicx}\n\\usepackage{longtable}\n\\usepackage{float}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{marvosym}\n\\usepackage{wasysym}\n\\usepackage{amssymb}\n\\usepackage{hyperref}\n\\tolerance=1000\n\\usepackage{khpreamble}\n\\usepackage{pgfplots}\n\\author{Kjartan Halvorsen}\n\\date{Due Friday 2017-03-15}\n\\title{Computerized control - homework 4}\n\\hypersetup{\n  pdfkeywords={},\n  pdfsubject={},\n  pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}}\n\\begin{document}\n\n\\maketitle\n\n\\section*{An observer for the harmonic oscillator model}\n\\label{sec-1}\nThe harmonic oscillator model, which in continuous-time has poles in \\(\\pm i\\omega\\), can be described in discrete-time as the state-space model\n\\begin{equation}\n\\begin{aligned}\nx(kh+h) &= \\underbrace{\\bbm \\cos\\omega{}h & \\frac{1}{\\omega} \\sin\\omega h\\\\ -\\omega\\sin\\omega h & \\cos\\omega h\\ebm}_{\\Phi(h)} x(kh) + \\underbrace{\\bbm \\frac{1}{\\omega^2}(1-\\cos\\omega h)\\\\\\frac{1}{\\omega}\\sin\\omega h\\ebm}_{\\Gamma(h)} u(kh)\\\\\ny(kh) &= \\underbrace{\\bbm 1 & 0\\ebm}_{C} x(kh)\n\\end{aligned}\n\\end{equation}\n\n\\begin{enumerate}\n\\item Determine the eigenvalues of \\(\\Phi(h)\\) (the discrete-time poles of the system). Verify that the poles are the same as obtained through the relationship \\(p = \\mexp{\\lambda h}\\) where \\(\\lambda\\) is the continuous-time pole and $p$ is the discrete-time pole.\n\\item Form the observability matrix \\[W_c = \\bbm C\\\\ C\\Phi(h) \\ebm\\] and determine for which values of $h$ the system becomes unobservable.\n\\item The observer for the system is given by the state-space system\n\\[ \\hat{x}(kh+h) = (\\Phi - KC) \\hat{x}(kh) + \\Gamma(h) u(kh) + Ky(kh) \\]\nLet \\(\\omega h = \\frac{\\pi}{6}\\) and determine a gain vector \\(K = \\bbm k_1 & k_2 \\ebm\\transp \\) that gives a deadbeat observer, i.e. an observer with characteristic polynomial \\(z^2\\) and poles in the origin.\n\\end{enumerate}\n\n\\section*{Active suspension}\n\\label{sec-2}\nA model of the front suspension of a motorcycle is shown in the figure \\ref{fig:quarter}. This model can also be a so-called \\emph{quarter model} for the suspension of a car.  The system consists of two masses. The \\emph{sprung mass} is the larger of the two masses, and is about half the mass of the motorcyle and rider. The other mass is the much smaller \\emph{unsprung mass}, which consists of the mass of the wheel, tyre and part (approximately half) of the suspension system. The two masses are connected by two passive elements: a spring and a damper, as well as an active element: a linear force actuator. The unsprung mass is connected to the ground via a spring representing the tyre (sometimes there is also a damper included in the model of the tyre).\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.65\\linewidth]{../figures/active-suspension-nodamper}\n\\caption{Active suspension model. The heights $h_1(t)$, $h_2(t)$ and $h_g(t)$ are measured with respect to a stationary frame of reference. The vehicle is moving to the right.}\n\\label{fig:quarter}\n\\end{center}\n\\end{figure}\n\nThe reference height of the road surface is $h_g = h_0$. When the vehicle is travelling on a horizontal road of this height and the system is in equilibrium, the height of the two masses will be $h_1=h_{1,0}$ and $h_2 = h_{2,0}$, respectively. Introduce deviations from these reference heights\n\\begin{align*}\nh_1(t) &= h_{1,0} + z_1(t)\\\\\nh_2(t) &= h_{2,0} + z_2(t)\\\\\nh_g(t) &= h_{0} + w(t)\n\\end{align*}\n\nA slightly more complex model is discussed \\href{http://ctms.engin.umich.edu/CTMS/index.php?example=Suspension&section=ControlStateSpace}{here}. That model also includes a damping in the tyre. You are welcome to study the example. \n\n\\subsection*{Determine the state space model}\n\\label{sec-2-1}\nThere are four forces acting on the sprung mass\n\\begin{center}\n\\begin{tikzpicture}\n\\node (M1) [draw, align=center, minimum width=3.5cm,minimum height=2cm] {Body mass};\n\\draw[->, thick] (M1.center) -- node[left, near end] {$m_1g$} ++(0, -3cm);\n\\draw[<-, thick] (M1.south) ++(-1cm, 0) -- node[left, near end] {$F_s$} ++ (0, -3cm);\n\\draw[<-, thick] (M1.south) ++(1cm, 0) -- node[left, near end] {$F_d$} ++ (0, -3cm);\n\\draw[<-, thick] (M1.south) ++(0.2cm, 0) -- node[right, near end] {$u$} ++ (0, -1.76cm);\n\\end{tikzpicture}\n\\end{center}\nThe equation of motion in the vertical direction becomes\n\\begin{equation}\n \\begin{split}\n m_1 \\ddot{z}_1 &= \\sum_i F_i = -m_1g + \\underbrace{m_1g -k_1(z_1-z_2)}_{F_s} + \\underbrace{\\big(-b_1(\\dot{z}_1 - \\dot{z}_2) \\big) }_{F_d} + u  = -k_1(z_1 - z_2) - b_1(\\dot{z}_1 - \\dot{z}_2) + u\\\\\n                &= -k_1z_1 -b_1\\dot{z}_1 + k_1z_2 + b_1\\dot{z}_2 + u. \n \\end{split}\n \\label{eq:eom1}\n \\end{equation}\nOn the unsprung mass, there are five forces acting:\n\\begin{center}\n\\begin{tikzpicture}\n\\node (M2) [draw, align=center, minimum width=3.5cm,minimum height=2cm] {Suspension mass};\n\\draw[->, thick] (M2.center) -- node[left, near end] {$m_2g$} ++(0, -3cm);\n\\draw[<-, thick] (M2.north) ++(-1cm, 0) -- node[left, near end] {$F_s$} ++ (0, 3cm);\n\\draw[<-, thick] (M2.north) ++(1cm, 0) -- node[left, near end] {$F_d$} ++ (0, 3cm);\n\\draw[<-, thick] (M2.north) ++(0cm, 0) -- node[right, near end] {$u$} ++ (0, 1.76cm);\n\\draw[<-, thick] (M2.south) ++(0.2cm, 0) -- node[right, near end] {$F_t$} ++ (0, -3.76cm);\n\\end{tikzpicture}\n\\end{center}\nThe equation of motion in the vertical direction becomes\n\\begin{equation}\n\\begin{split}\nm_2\\ddot{z}_2 &= -m2_g - \\underbrace{\\big(m_1g -k_1(z_1-z_2)\\big)}_{F_s}\n - \\underbrace{\\big(- b_1(\\dot{z}_1-\\dot{z}_2)\\big)}_{F_d}\n - \\underbrace{\\big( (m_1 + m_2)g - k_2(z_2 - w) \\big)}_{F_t} - u\\\\\n               &= (k_1)z_1 + b_1\\dot{z}_1 - (k_1+k_2)z_2 - b_1\\dot{z}_2 + k_2w - u\n \\end{split}\n \\end{equation}\n\nUse the state-vector     \n\\[ x = \\bbm x_1\\\\x_2\\\\x_3\\\\x_4 \\ebm = \\bbm z_1\\\\ \\dot{z}_1 \\\\ z_2\\\\ \\dot{z}_2 \\ebm \\]\nand let the velocity of the sprung mass $y(t) = \\dot{z}_1(t)$ be the output of the system. \n\\textbf{Set up the continous-time state-space model}\n\\begin{equation*}\n\\begin{aligned}\n\\dot{x}(t) &= Ax(t) + B_u u(t) + B_w w(t)\\\\\ny(t) &= C x(t)\n\\end{aligned}\n\\end{equation*}\nNote that there are two input signals: The active suspension force $u(t)$ and the disturbance from the road $w(t)$.\n\n\\subsection*{Simulate step-responses}\n\\label{sec-2-2}\nImplement the model in matlab. Use the following values for the parameters\n\\begin{center}\n\\begin{tabular}{l}\n$m1 = 140$\\\\\n$m2 = 14$\\\\\n$k1 = 4.6\\cdot{}10^4$\\\\\n$k2 = 3.0\\cdot{}10^5$\\\\\n$b1 = 10^3$\\\\\n\\end{tabular}\n\\end{center}\nHere is some code to help you\n\\begin{verbatim}\nm1 = 140;\nm2 = 14;\nk1 = 4.6e4;\nk2 = 3.0e5;\nb1 = 1e3;\n\nA =   % Your code here\n\nBu = [0  \n     1/m1\n     0\n     -1/m2 ];\nBw = [ 0\n      0\n      0\n      k2/m2];\nC =   % Your code here\nD=[0];\nsys_uy=ss(A,Bu,C,D); % System with only u(t) as input\nsys_wy=ss(A,Bw,C,D); % System with only w(t) as input\n\n% Step responses\nfigure(1)\nclf\nsubplot(121)\nstepplot(1000*sys_uy);\ntitle('Response from u (step 1kN)')\nxlabel('Time [s]')\nylabel('y [m/s]')\nsubplot(122)\nstepplot(0.1*sys_wy);\ntitle('Response from w (step 0.1m)')\nxlabel('Time [s]')\nylabel('y [m/s]')\n\\end{verbatim}\n\n\n\\subsection*{Sample the system}\n\\label{sec-2-3}\n\\begin{enumerate}\n\\item The system is quite oscillative, as the step-responses show. Plot the poles of the continuos-time system using \\texttt{pzmap} \n\\begin{verbatim}\nfigure(2)\npzmap(sys_uy)\n\\end{verbatim}\nChoose a sampling period $h$, such that $\\omega_0h = 0.8$, where $\\omega_0$ is the natural frequency (in radians per second) of the fastest poles.\n\\item Sample the system numerically using \\texttt{c2d} in matlab:\n\\begin{verbatim}\nh = % Your code here\nsys_uy_d  = c2d(sys_uy, h); % Zero-order-hold sampling\nsys_wy_d  = c2d(sys_wy, h); % Zero-order-hold sampling\n\\end{verbatim}\n\\end{enumerate}\n\n\\subsection*{Determine a state feedback}\n\\label{sec-2-4}\n\\begin{enumerate}\n\\item First determine the desired poles. The system is fourth order, so we need to choose four poles for the closed-loop system. Assume we want the closed-loop system to have more or less the same speed as the two fastest open-loop poles (same distance from the origin), but more damped.  Determine the four desired closed-loop continuous-time poles, and then translate them to discrete time:\n\\begin{verbatim}\np_c = [ ] % Your four desired closed-loop poles in continuous-time here\np_d = exp(p_c*h) % The corresponding four discrete-time poles\n\\end{verbatim}\n\\item Determine the feedback gain vector \\(L\\), and form the closed-loop system. Matlab will happily do the calculations for you:\n\\begin{verbatim}\n[Phi, Gamma_u, C, D] = ssdata(sys_uy_d) % Get the matrices\n[Phi, Gamma_w, C, D] = ssdata(sys_wy_d) \nL = place(Phi, Gamma_u, p_d)    \nsys_wy_d_closed = ss(Phi-Gamma_u*L, Gamma_w, C, D, h); % Closed-loop system from w to y\n\\end{verbatim}\n\\end{enumerate}\n\n\\subsection*{Simulate the closed-loop response}\n\\label{sec-2-5}\nCheck the performance of your closed-loop system. Let the disturbance (road profile) look as below\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{axis} [\n   width = 12cm, height = 4cm,\n   xlabel = {$t$ [s]},\n   ylabel = {$w(t) [m]$},\n   xmin = -0.5, xmax = 10,\n   ymin = -0.5, ymax = 0.5,\n   ]\n   \\draw[thick] (axis cs: -0.5,0) -- (axis cs: 0,0) -- (axis cs: 0,0.3) -- (axis cs: 2,0.3) -- (axis cs: 2,-0.3) -- (axis cs: 4,-0.3) -- (axis cs: 4, 0) -- (axis cs: 10,0);\n   \\end{axis}\n   \\end{tikzpicture}\n   \\end{center}\n\nIn matlab:\n\\begin{verbatim}\nT = ( 0:ceil(10/h) )*h; % Discrete time-vector from 0 to 10 seconds\nw = zeros(size(T));\nind_before_2 = find(T < 2);\nw(ind_before_2) = 0.3;\nind_between_2_and_4 = intersect( find(T>2), find(T<4) );\nw(ind_between_2_and_4) = -0.3;\n\n[y, Tsim, x] = lsim(sys_wy_d_closed, w, T);\n[yo, Tsim, xo] = lsim(sys_wy_d, w, T); % Simulate system without feedback\n\nfigure(3)\nset(gcf, 'position', [100, 100, 900, 700])\nfor i=1:4\n    subplot(5,1,i)\n    stairs(T, x(:,i), 'color', [0, 0.447, 0.741])\n    hold on\n    stairs(T, xo(:,i), 'color', [0.85, 0.325, 0.098])\n    ylabel(sprintf('state %d', i))\n    xlabel('Time [s]')\nend\nlegend('Closed-loop response', 'Open-loop response')\nsubplot(5,1,5)\nstairs(T, -L*x', 'color', [0, 0.447, 0.741])\nylabel('Control signal [N]')\n\\end{verbatim}\n\n\\textbf{Comment on the figures!} For instance: How do the closed-loop system response compare to the open-loop response? What was the maximum active suspension force (\\(\\max u(t)\\))? \n\n\n\\section*{Solutions}\n\\label{sec-3}\n\n\\subsection*{An observer for the harmonic oscillator model}\n\\label{sec-3-1}\n\\begin{enumerate}\n\\item The eigenvalues are given by the roots of \\(\\det (zI - \\Phi)\\). Writing \\(\\cos\\omega h = c\\) and \\(\\sin\\omega h = s\\) for simplicity, we get\n\\begin{equation*}\n\\begin{aligned}\n\\det (zI - \\Phi) &= \\det \\left( \\bbm z & 0\\\\0 & z\\ebm - \\bbm c & \\frac{s}{\\omega}\\\\-\\omega s & c\\ebm \\right) = \\det \\bbm z-c & -\\frac{s}{\\omega}\\\\ \\omega s & z-c\\ebm \\\\\n&= (z-c)^2 + s^2\n\\end{aligned}\n\\end{equation}\nwith roots on the unit circle:\n\\[ z = c \\pm is = \\cos\\omega h \\pm i \\sin\\omega h.\\]\nUsing the relationship \\(z = \\mexp{sh}\\) between the s-plane and the z-plane we get for the continous-time poles \\(s=\\pm i\\omega\\)\n\\[ z = \\mexp{\\pm i\\omega h} = \\cos\\omega h \\pm i\\sin\\omega h \\]\nusing Euler's formula.\n\\item The observability matrix becomes\n\\[ W_c = \\bbm C\\\\C\\Phi \\ebm = \\bbm 1 & 0\\\\ c & \\frac{s}{\\omega},\\] so\n\\[ \\det W_c = \\frac{1}{\\omega} \\sin\\omega h \\]\nwhich is zero for \\(\\omega h = k\\pi, \\; k=1,2,\\ldots\\). So observability is lost for\n\\[ h = \\frac{k\\pi}{\\omega}, \\; k=1,2\\ldots. \\]\n\\item With \\(\\omega=1\\) and \\(h=\\frac{\\pi}{6}\\) we get \\(\\cos\\omega h = \\sqrt{3}/2\\) and \\(\\sin\\omega h = 1/2\\). This gives\n\\end{enumerate}\n\\[ \\Phi = \\frac{1}{2} \\bbm \\sqrt{3} & 1\\\\-1 & \\sqrt{3} \\ebm\\].\nThe characteristic polynomial of the observer becomes\n\\begin{equation*}\n\\begin{aligned}\n\\det \\big(zI - (\\Phi - KC)\\) &= \\det  \\left( \\bbm z & 0\\\\0 & z\\ebm - \\frac{1}{2} \\bbm \\sqrt{3} - 2k_1 & 1\\\\-1-2k_2 & \\sqrt{3}\\ebm\\\\\n&= \\det \\bbm z-\\frac{\\sqrt{3}-2k_1}{2} & -\\frac{1}{2}\\\\\\frac{1+2k_2}{2} & z - \\frac{\\sqrt{3}}{2} \\ebm\\\\\n&= (z-\\frac{\\sqrt{3}-2k_1}{2})(z - \\frac{\\sqrt{3}}{2}) + \\frac{1+2k_2}{4}\\\\\n&= z^2 - (\\sqrt{3}-k_1)z + \\frac{1}{4}\\big( \\sqrt{3}(\\sqrt{3}-2k_1) + 1 + 2k_2\\big)\\\\\n&= z^2 - (\\sqrt{3}-k_1)z + \\frac{1}{4}\\big(-2\\sqrt{3}k_1 + 2k_2 + 4\\big)\n\\end{aligned}\n\\end{equation*}\nSetting coefficient equal to the coefficients of the desired characteristic polynomial \\(z^2\\) gies\n\\begin{align*}\n\\sqrt{3}-k_1 &= 0 \\quad \\Rightarrow \\quad k_1 = \\sqrt{3}\\\\\n-2\\sqrt{3}k_1 + 2k_2 + 4 &= 0 \\quad \\Rightarrow \\quad k_2 = 3-2 = 1\n\\end{align*}\n\n\\subsection*{Active suspension}\n\\label{sec-3-2}\n\\subsubsection*{State space model}\n\\label{sec-3-2-1}\nWith the state vector \n \\[ x = \\bbm x_1\\\\x_2\\\\x_3\\\\x_4 \\ebm = \\bbm z_1\\\\ \\dot{z}_1 \\\\ z_2\\\\ \\dot{z}_2 \\ebm \\]\n we can write the four first-order differential equations of the state space model\n \\begin{align*}\n  \\dot{x}_1 &= \\dot{z}_1 = x_2\\\\\n  \\dot{x}_2 &= \\ddot{z}_1 = \\frac{1}{m_1}\\Big(-k_1z_1 -b_1\\dot{z}_1 + k_1z_2 + b_1\\dot{z}_2 + u\\Big)\\\\\n            &= -\\frac{k_1}{m_1}x_1 - \\frac{b_1}{m_1}x_2 + \\frac{k_1}{m_1}x_3 + \\frac{b_1}{m_2}x_4 + \\frac{1}{m_1} u\\\\\n  \\dot{x}_3 &= \\dot{z}_2 = x_4\\\\\n  \\dot{x}_4 &= \\ddot{z}_2 = \\frac{1}{m_2} \\Big(k_1z_1 + b_1\\dot{z}_1 - (k_1+k_2)z_2 - b_1\\dot{z}_2 + k_2w - u\\Big)\\\\ \n            &= \\frac{k_1}{m_2} x_1 + \\frac{b_1}{m_2} x_2 - \\frac{k_1+k_2}{m_2}x_3 + -\\frac{b_1}{m_2}x_4 + \\frac{k_2}{m_2}w - \\frac{1}{m_2}u.\n\\end{align*}\nIn state-space form, this can be written\n\\begin{align*}\n\\dot{x} &= \\bbm 0 & 1 & 0 & 0\\\\ \n-\\frac{k_1}{m_1} & -\\frac{b_1}{m_1} & \\frac{k_1}{m_1} & \\frac{b_1}{m_1}\\\\\n0 & 0 & 0 & 1\\\\\n\\frac{k_1}{m_2} & \\frac{b_1}{m_2} & -\\frac{k_1+k_2}{m_2} & -\\frac{b_1}{m_2}\\ebm\n\\bbm x_1\\\\x_2\\\\x_3\\\\x_4 \\ebm + \\bbm 0\\\\0\\\\0\\\\\\frac{k_2}{m_2} \\ebm w + \\bbm 0\\\\\\frac{1}{m_1}\\\\0\\\\-\\frac{1}{m_2} \\ebm u \\\\\ny &= \\bbm 0 & 1 & 0 & 0 \\ebm x.\n\\end{align*}\n\n\\subsubsection*{step-responses}\n\\label{sec-3-2-2}\nThe figure below shows the step-responses of both the continuous- and the sampled systems.\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{active-susp-plant-response}\n\\end{center}\n\n\\subsubsection*{Sampling the system}\n\\label{sec-3-2-3}\n\\begin{enumerate}\n\\item The pole-zero map below shows that the fast poles have a distance of \\(\\omega = 156\\) rad/s to the origin. The rule-of-thumb (chapter 2.9 in the textbook) tells us that we should have \\(\\omega h \\approx 0.2 -- 0.6\\). For instance,\n\\[ h = \\frac{0.6}{156} \\approx \\unit{0.004}{\\second}. \\]\n\\item Sampling the system is straightforward \n\\begin{verbatim}\nh = 0.004;\nsys_uy_d = c2d(sys_uy, h); % The system from input u to y\nsys_wy_d = c2d(sys_wy, h); % From input w to y\n\\end{verbatim}\n\\end{enumerate}\n\\subsubsection*{State feedback}\n\\label{sec-3-2-4}\n\\begin{enumerate}\n\\item Desired closed-loop poles. The idea is to choose the poles to be equally fast, but more damped than the fast poles of the plant. For instance we can choose the set of four poles  \n\\[ p_{1,2} = -\\zeta_1\\omega_n \\pm i \\sqrt{1 - \\zeta_1^2}\\omega_n,  \\quad\n               p_{3,4} = -\\zeta_2\\omega_n \\pm i \\sqrt{1 - \\zeta_2^2}\\omega_n \\]\nwith natural frequency \\(\\omega_n = 156\\), and damping ratio \\(\\zeta_1 = 0.8\\) and \\(\\zeta_2 = 0.6\\).\n\\item The feedback vector is calculated by Matlab and gives\n$\\backslash$[ L = \\bbm l$_{\\text{1}}$ \\& l$_{\\text{2}}$ \\& l$_{\\text{3}}$ \\& l$_{\\text{4}}$ \\ebm = \\bbm 1.89$\\cdot$ 10$^{\\text{6}}$ \\& 3.85 $\\cdot$ 10$^{\\text{4}}$ \\& -3.23$\\cdot$ 10$^{\\text{5}}$ \\& 6.20 $\\cdot$ 10$^{\\text{2}\\ebm}$.\n\\end{enumerate}\n\n\\subsubsection*{Simulations}\n\\label{sec-3-2-5}\nWith the state feedback proposed, the response is as shown in the figure below.\n\\begin{center}\n\\includegraphics[width=\\linewidth]{../matlab/active-suspension-sim-crop}\n\\end{center}\nWe can see that the closed-loop response of \\(z_1\\) and \\(\\dot{z}_1\\) are both very well damped, and has much smaller amplitude than the open-loop system. The control signal shows quite large peak (30-50 kN) at the onset of the disturbances. \n\n\\subsubsection*{Choosing the closed-loop poles too slow.}\n\\label{sec-3-2-6}\nThere is a potential problem with choosing the closed-loop poles (much) slower than the open-loop poles in this exercise. Slow poles in discrete-time means close to 1. The reason is that state feedback does not change the numerator in the pulse transfer function from input to output.  So, if the open-loop pulse transfer function from disturbance to output signal is\n\\[ H_w(z) = C (zI-\\Phi)^{-1} \\Gamma_w = \\frac{\\beta(z)}{\\alpha(z)},\\]\nthen the closed-loop transfer function will be \n\\[ H_c(z) = C \\big(zI -(\\Phi-\\Gamma_u L)\\big)^{-1}\\Gamma_w = \\frac{\\beta(z)}{\\alpha_c(z)}.\\]\nThe denominator is obtained by design (choice of pole placement) to have the roots (desired closed-loop poles) \\(p_{d,1}\\),  \\(p_{d,2}\\),  \\(p_{d,3}\\),  \\(p_{d,4}\\), so   \n\\[ H_c(z) = \\frac{\\beta(z)}{(z-p_{d,1})(z-p_{d,2})(z-p_{d,3})(z-p_{d,4})}.\\]\nThe static gain becomes\n\\[ H_c(1) = \\frac{\\beta(1)}{(1-p_{d,1})(1-p_{d,2})(1-p_{d,3})(1-p_{d,4})},\\]\nwhich can be much larger than the open-loop static gain \\(H_w(1)\\), if the closed-loop poles are much closer to 1 than the open-loop poles. \n% Emacs 24.5.1 (Org mode 8.2.10)\n\\end{document}", "meta": {"hexsha": "d45dce490c4cd862dbd1cc494e6b7bb372ebe99f", "size": 17233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/historical/hw4-ss-active-suspension-spring18.tex", "max_stars_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_stars_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-07T05:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-22T09:46:13.000Z", "max_issues_repo_path": "homework/historical/hw4-ss-active-suspension-spring18.tex", "max_issues_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_issues_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-06-12T20:44:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-12T20:49:00.000Z", "max_forks_repo_path": "homework/historical/hw4-ss-active-suspension-spring18.tex", "max_forks_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_forks_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-14T03:55:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-14T03:55:27.000Z", "avg_line_length": 46.2010723861, "max_line_length": 762, "alphanum_fraction": 0.6621598097, "num_tokens": 6477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6148911407781049}}
{"text": "\n\\subsection{The equation of exchange}\n\nAs there’s only so much stuff out there, an increase in the amount of money moving around with cause inflation.\n\nThis can be shown as:\n\n\\(MV=PQ\\)\n\nThe amount of money (M) multiplied by the velocity at which money moves (V) must be equal to the average price (P) multiplied by the quantity of stuff (Q). This isn’t a theory, it’s an accounting identity.\n\n", "meta": {"hexsha": "b90e19d1dd6d94e2d64a42eada5148b60638f454", "size": 394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/money/02-01-equationExchange.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/money/02-01-equationExchange.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/money/02-01-equationExchange.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.8333333333, "max_line_length": 205, "alphanum_fraction": 0.7512690355, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6148262927679573}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\n\n\n\n\n% collectivised from: https://www.overleaf.com/learn/latex/Theorems_and_proofs#Theorem_styles\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\\theoremstyle{remark}\n\\newtheorem*{remark}{Remark}\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n%\n\\begin{document}\n%Plan\n%   1. Introduction\n%       Original problem: US graphs and edge coloration with \\omega = 2. \n%       Known for delta 2. we know delta is at most 5. Concept of direction.\n%   2. On a grid    \n%       \"what we will do here: ... \". RK: if not all on a grid are US, all US are on a grid. Thus any result on on a grid graph is true for US. \n%       2.1 On a grid - definition. \n%       2.2 Additional concepts: Type 1/2 diagonals, order on the diagonals.\n%       2.3 Algorithm \n%       2.4 Complexity\n%   3. Applications\n%       3.1 US graphs: chromatic index of 4\n%       3.2 angles & directions\n\\section{Introduction}\nThe original problem is to study the chromatic index of triangle-free \\textit{unit square intersection graphs},\nwhich are graphs that are obtained for a family of unit squares. \nEach square is represented by a vertex in a graph, and each edge represent the fact that two squares are intersecting. \\\\\nWe already know that when the maximum degree $\\Delta$ is $2$, there may exists graphs of type 2, for instance any odd cycle. We can also observe that\nwhen two unit squares intersects, there is a corner of each inside the other; from this observation follows that there cannot be \na triangle-free unit square graph with $\\Delta \\ge 5$. \\\\\nIn what follows, we provide a proof that there cannot be a graph of type 2 when $\\Delta = 4$. The proof will be done by introducing a new way to\nrepresent the graphs by using a grid; and we will call them \\textit{on a grid} graphs.\n\n\\section{Graphs on-a-grid}\nWe present in this section a proof that unit square graphs are also \\textit{on a grid} graphs. \n\\subsection{On a grid}\n\\begin{definition}[On a grid]\n    A graph is said \\textit{on a grid} if:\n    \\begin{itemize}\n        \\item All the edges are either parallels or perpendicular.\n        \\item All the edges are of integer lengths.\n        \\item No edge is overlapping or containing an other edge in more than one point.\n    \\end{itemize}\n\\end{definition}\n\nInstead of using the usual directions of the cartesian plane, we will rotate all the edges by $\\tfrac{\\pi}{4}$ as it will be more convenient later.\nThe graph represented in Fig.1. is \\textit{on a grid}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.2]{tex_images/on_a_grid_g1.png}\n    \\caption{$G_1$ is on a grid.}\n\\end{figure}\n\n\\begin{remark}\n    $G_1$ has exactly $10$ edges.\n\\end{remark}\n\n\\subsection{Additional concepts}\n\n\\begin{definition}[Direction of intersection]\n    Let $a, b$ be two unit squares. We say that $a$ intersects $b$ in UR direction (resp. UL, DL, DR) if the up-right (resp up-left, down-left, down-right) corner\n    of $a$ is inside $b$.     \n\\end{definition}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale = 0.3]{tex_images/same_diagonals.png}\n    \\caption{Illustration of direction of intersections.}\n\\end{figure}\n\nFor instance, in Fig. 2, $D$ intersect $F$ in direction DR, $G$ in direction UR and $A$ in direction UL. Conversely, $A$ intersect $D$ in direction DR.\n\n\\begin{lemma}\n    If $a$ intersect both $b$ and $c$ in the same direction, then $a, b$ and $c$ forms a triangle.\n\\end{lemma}\n\n\\begin{proof}\n    Notice that they would all share a common point in a certain corner of $a$.\n\\end{proof}\n\n\\begin{definition}[Diagonals]\n    Let $a$ and $b$ be two squares. They are said to be on the same \\textit{Type 1 diagonal} (resp. Type 2) if you can find a sequence $\\{s_1, ... s_k\\}$ of squares such that:\n    \\begin{itemize}\n        \\item $s_1 = a$\n        \\item $s_k = b$\n        \\item $\\forall i \\in \\{1, .. , k-1\\}$, $s_i$ intersects $s_{i+1}$ in UL or DR (resp. UR or DL) direction.\n    \\end{itemize}    \n    A diagonal is a set of points (possibly trivial) that are on the same diagonal. \n\\end{definition}\n\n\\begin{remark}\n    We will denote the diagonal as follows : $D:= \\{d_1, ... , d_k\\}$. In this case $d_1$ is the highest square of the diagonal, meaning that $d_1$ intersect $d_2$ in DR direction in the case of a type 1 diagonal, and so on.\n\\end{remark}\n\nIn Fig. 2 we can denote the following diagonals:\\\\\nType 1: $\\{(A, D, F), (E), (I), (G, H)\\}$\\\\\nType 2: $\\{(A), (D,G), (F, E, I, H)\\}$\\\\\n\n\n\\begin{lemma}\n    Let $D$, $E$ be two diagonals of the same type. If we can find $d \\in D$; $e \\in E$ such that $d$ intersect $e$ in some direction X, then: \\\\\\\n    $\\forall d' \\in D$, $\\forall e' \\in E$, either $e'\\cap d' = \\emptyset$ or $d'$ intersect $e'$ in direction X.\n\\end{lemma}\n\n\\begin{proof}\n    Without loss of generality, let $D:=\\{d_1, ... d_k\\}$ and $E:= \\{e_1, ... e_l\\}$ be two distinct diagonals of Type 1. \n    Suppose $d_1$ intersect $e_1$ in direction DL. \\\\\n    Let $(i,j)$ be the smallest couple different from $(1,1)$ such that $d_i \\cap e_j \\ne \\emptyset$. Observe that as $D$ and $E$ are Type 1, the only possibility is that \n    $d_i$ intersect $e_j$ in direction UR or DL.\n\\end{proof}\n\nWe can now use the previous lemma to define a partial order on our diagonals.\n\n\\begin{definition}[Order on diagonals]\n    Let $D_1$, $D_2$ two diagonals of Type 1 (resp Type 2). We say that $D_1$ is \\textit{directly higher} than $D_2$, or $D_1 >_d D_2$ if:\n    $\\exists d_1 \\in D_1, \\exists d_2 \\in D_2$ such that $d_1$ intersects $d_2$ in DL (resp. UR) direction. \\\\ \\\\\n    We say that $D_1$ is higher than $D_2$, or $D_1 > D_2$ if we can find a sequence of diagonals $\\{s_1, ... , s_k\\}$ such that:\n    \\begin{itemize}\n        \\item $s_1 = D_1$\n        \\item $s_k = D_2$\n        \\item $\\forall i \\in \\{1, ..., k-1\\}, s_i >_d s_{i+1}$\n    \\end{itemize} \n\\end{definition}\n\n%% TODO: explain why we cant have D >_d E and E >_d D at the same time \n\n\\begin{remark}\n    Note that $>_d$ is not an order as it is not transitive. \n\\end{remark}\n\n\n\\subsection{From unit squares to the grid}\n\nWe present here an algorithm to obtain a on a grid graph given a family of unit squares.\\\\\nStart by identifying all the diagonals: to do so,\n\n\\section{Some applications}\n\\subsection{Edge coloration}\n\nOne can easily see that any on a grid graph has a chromatic index of at most $4$. As every triangle-free unit square graph is also on a grid, \nit follows that no graph of type 2 can exist for these if $\\Delta = 4$.\n\n\\begin{theorem}\n    Let $G$ be a unit square graph, with $\\Delta = 4$ and $\\omega = 2$. Then $\\chi'(G) = 4$.\n\\end{theorem}\n\n\\begin{proof}\n    It is sufficient to show it is true for all graphs that are on a grid. \\\\\n    Let $G$ be on a grid. Delete for a moment all the edges that correspond to type 1 diagonals. There subsits only paths. \n    As all paths can be colored using only two colors, assign color 1 or 2 to all the remaining edges. \\\\\n    Do the same thing for the type 2 diagonals with colors 3 and 4. \\\\\n    As all the edges of $G$ are either on a type 1 or a type 2 diagonal, all the edges are assigned to a color. If two edges are on the same type of diagonals, either they\n    have different colors or they are not adjacent. If two edges are on different type of diagonals, they have different colors. Therefore, this coloration is acceptable.\n\\end{proof}\n\n\\subsection{Directions in cycles}\n\n\n\\end{document}", "meta": {"hexsha": "d00b9f783a1146b3edee02080d8092a28ec1edb4", "size": 7481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/on_a_grid/on_a_grid.tex", "max_stars_repo_name": "Qiselong/Internship-GSCOP21", "max_stars_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_stars_repo_licenses": ["MIT"], "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/on_a_grid/on_a_grid.tex", "max_issues_repo_name": "Qiselong/Internship-GSCOP21", "max_issues_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_issues_repo_licenses": ["MIT"], "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/on_a_grid/on_a_grid.tex", "max_forks_repo_name": "Qiselong/Internship-GSCOP21", "max_forks_repo_head_hexsha": "c33b09fb889181d5d40c785e964f7748a82dc61f", "max_forks_repo_licenses": ["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.0058823529, "max_line_length": 224, "alphanum_fraction": 0.6862718888, "num_tokens": 2247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6148262860827001}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{geometry}\n\\usepackage{enumerate}\n\\usepackage{natbib}\n\\usepackage{float}%稳定图片位置\n\\usepackage{graphicx}%画图\n\\usepackage[english]{babel}\n\\usepackage{a4wide}\n\\usepackage{indentfirst}%缩进\n\\usepackage{enumerate}%加序号\n\\usepackage{multirow}%合并行\n\n\n\\begin{document}\n\\newpage\n\\section{Problem 1}\n\\subsection{(a)}\n$$I_c=I_s \\exp(\\frac{q V_{BE}}{KT}-1)(1+\\frac{V_{CE}}{V_A})=10^{-16}\\exp(\\frac{0.7}{0.0259}-1)(1+\\frac{V_{CE}}{100})=5.47\\cdot10^{-5}*(1+0.01*V_{OUT})$$\n$$V_{OUT}=V_{CC}-R_c*I_c=3-5000I_c$$\n$$V_{OUT}=2.72(V)$$\n$$I_c=\\frac{3-2.9}{5000}=5.6\\cdot10^{-5}(A)$$\n$$gm=\\frac{q\\cdot I_c}{KT}=\\frac{5.6\\cdot10^{-5}}{0.0259}=2.162\\cdot10^{-3}$$\n$$r_0=\\frac{V_A}{I_c}=\\frac{100}{2.07\\cdot 10^{-5}}=1.79\\cdot10^{6}(\\Omega)$$\n$$A_v=-gm(R_c||r_0)=-2.162\\cdot10^{-3}\\cdot\\frac{5000*1.79\\cdot10^{6}}{5000+1.79\\cdot10^{6}}=-10.78$$\n\\subsection{(b)}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.25]{P1.png}\n\\end{figure}\n$$A_v=\\frac{18}{-1.7}=-10.6$$\nThe slope is about -10.6, which is a little bigger than calculated one in (a)\n\\subsection{(c)}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.25]{P2.png}\n\\end{figure}\n$$|A_v|=|\\frac{(2.8-2.9)}{0.69-0.7}|\\approx10$$\nThe value is very close to part (b) and (a) but the absolute value is a bit smaller.\n\\subsection{(d)}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.25]{P3.png}\n\\end{figure}\n$$|A_v|=|\\frac{(2.96-2.9)}{0.65-0.7}|\\approx47.2$$\nThe value is much more greater than calculated one in previous part, I think it's because the amplitude is so big that the input signal can't be considered as a small signal any more. As a result, the derivative for $V_{BE}$ can't be applied any more gm has changed.\n\\end{document}", "meta": {"hexsha": "406edce887063a620308b275c47fb8886caa7f4e", "size": 1757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE311SemiConductorCircuit/HW/HW4/HW/HW.tex", "max_stars_repo_name": "PANDApcd/SemiConductorCircuit", "max_stars_repo_head_hexsha": "430ffaeea0830dc3105883374dd729fe9f86cc55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "VE311SemiConductorCircuit/HW/HW4/HW/HW.tex", "max_issues_repo_name": "PANDApcd/SemiConductorCircuit", "max_issues_repo_head_hexsha": "430ffaeea0830dc3105883374dd729fe9f86cc55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "VE311SemiConductorCircuit/HW/HW4/HW/HW.tex", "max_forks_repo_name": "PANDApcd/SemiConductorCircuit", "max_forks_repo_head_hexsha": "430ffaeea0830dc3105883374dd729fe9f86cc55", "max_forks_repo_licenses": ["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.6041666667, "max_line_length": 266, "alphanum_fraction": 0.6841206602, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6148262827400713}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\n\\title{Piecewise Polynomial Path Planner (P4)}\n\\author{Tucker Haydon}\n\\date{Spring 2019}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nThis document describes the underlying theory for the piecewise polynomial path\nplanner.\n\n\\section{Polynomial Theory}\n\\subsection{Problem Statement}\nGiven a set of waypoints and corresponding arrival times, construct a\npiecewise-continuous polynomial trajectory through these waypoints that minimizes\nthe norm of a specified derivative. Furthermore, the trajectory --- or any\nderivative of the trajectory --- may be subject to linear inequality\nconstraints.\n\\bigbreak\n\\noindent Mathematically, the problem may be stated so: given a set of $m$ waypoints \n%\n\\begin{equation}\n  \\mathbf{W} = \n  \\begin{bmatrix}\n    \\vec{w}_{0} & \\vec{w}_{1} & \\vec{w}_{2} & \\hdots & \\vec{w}_{m}\n  \\end{bmatrix}\n  \\in \\mathcal{R}^a\n\\end{equation}\n%\nand a set of times to arrive at these waypoints \n\\begin{equation}\n  \\vec{T} = \n  \\begin{bmatrix}\n    t_{0} & t_{1} & t_{2} & \\hdots & t_{m}\n  \\end{bmatrix}\n\\end{equation}\n%\ndetermine a set of $n$'th-order piecewise-continuous polynomials that smoothly connect these waypoints\n%\n\\begin{equation}\n  \\vec{p}(t) = \n  \\begin{cases}\n    p_{0}(t) = \\sum_{k=0}^{n} p_{0,k} \\cdot (\\frac{1}{k!} t^{k}) & t_{0} \\leq t < t_{1} \\\\ \n    p_{1}(t) = \\sum_{k=0}^{n} p_{1,k} \\cdot (\\frac{1}{k!} t^{k}) & t_{1} \\leq t < t_{2} \\\\ \n    \\vdots \\\\\n    p_{m}(t) = \\sum_{k=0}^{n} p_{m,k} \\cdot (\\frac{1}{k!} t^{k}) & t_{m-1} \\leq t < t_{m}\n  \\end{cases}\n\\end{equation}\n%\nwhile minimizing the squared norm of the $r$'th derivative\n%\n\\begin{equation}\n  \\min\n  \\int_{t_{0}}^{t_{m}} \\frac{d^{r}}{dt^{r}}|| \\vec{p}(t) ||^{2} dt\n\\end{equation}\n%\nsubject to continuity and path constrains (see sections \\ref{} \\& \\ref{}).\n\\bigbreak\n\\noindent This problem construction and the following solution follow those of Mellinger\nand Kumar \\cite{mellinger2011minimum}.\n\n\\subsection{Polynomial Basis}\nTrajectories for quadcopters may be specified with no more than four independent\ndimensions: x, y, z, and yaw. Any more dimensions (roll, pitch) introduce\nconstraints that may render certain specified trajectories infeasible. For\nexample, a quadcopter cannot be simultaneously stationary and have a non-zero\nroll angle \\cite{mellinger2011minimum}.\n\nImportantly, the x, y, z, and yaw dimensions may be specified\n\\textit{independently}: each dimension of the polynomial basis functions may be\nconsidered alone, permitting scalar analysis. The following section uses a\n3rd-order polynomial, but the analysis generalizes to any order polynomial.\n\nConsider a 3rd-order polynomial representing the first section of trajectory.\n\\begin{equation*}\n  p_{0}(t) = \\frac{1}{0!}t^{0}x_{0} + \\frac{1}{1!}t^{1}v_{0}\n           + \\frac{1}{2!}t^{2}a_{0} + \\frac{1}{3!}t^{3}j_{0}\n\\end{equation*}\n%\nThis expression may be divided into two components: a vector of coefficients and\na vector of basis functions.\n\\begin{equation*}\n  p_{0}(t) = \n  \\underbrace{\n  \\begin{bmatrix}\n    x_{0} & v_{0} & a_{0} & j_{0}\n  \\end{bmatrix}\n  }_{\\text{coefficients}}\n  \\underbrace{\n  \\begin{bmatrix}\n    \\frac{t^{0}}{0!} \\\\[6pt]\n    \\frac{t^{1}}{1!} \\\\[6pt]\n    \\frac{t^{2}}{2!} \\\\[6pt]\n    \\frac{t^{3}}{3!}\n  \\end{bmatrix}\n  }_{\\text{basis functions}}\n\\end{equation*}\n%\nOr in vector form\n\\begin{equation*}\n  p_{0}(t) = \\vec{x}^{T} \\vec{t}\n\\end{equation*}\n\n\\subsection{Polynomial Optimization}\nFor each section in the trajectory, the $r$'th derivative must be minimized.\n\\begin{align*}\n    x_{i} &= \\text{arg} \\min_{\\vec{x}} \\int_{t_{i}}^{t_{i+1}} \\bigg[ \\frac{d^{r}\n    p(\\tau)}{d \\tau^{r}} \\bigg]^2 dt \\\\\n        &= \\text{arg} \\min_{\\vec{x}} \\int_{t_{i}}^{t_{i+1}} \\bigg[ \\frac{d^{r}\n    p(\\tau)}{d \\tau^{r}}\\bigg]^T \\bigg[ \\frac{d^{r} p(\\tau)}{d \\tau^{r}}\\bigg]\n    dt \\\\\n        &= \\text{arg} \\min_{\\vec{x}} \\int_{t_{i}}^{t_{i+1}} \\vec{x}^T \\frac{d^{r}\n    \\vec{t}(\\tau)}{d \\tau^{r}}^{T} \\frac{d^{r} \\vec{t}(\\tau)}{d \\tau^{r}}\n    \\vec{x} dt \\\\\n        &= \\text{arg} \\min_{\\vec{x}} \\vec{x}^{T} \\int_{t_{i}}^{t_{i+1}} \\frac{d^{r}\n    \\vec{t}(\\tau)}{d \\tau^{r}}^{T} \\frac{d^{r} \\vec{t}(\\tau)}{d \\tau^{r}} dt\n    \\vec{x}\n\\end{align*}\n%\nBy defining\n\\begin{equation*}\n  \\mathbf{Q} = \\int_{t_{i}}^{t_{i+1}} \\frac{d^{r} \\vec{t}(\\tau)}{d\n  \\tau^{r}}^{T} \\frac{d^{r} \\vec{t}(\\tau)}{d \\tau^{r}} dt\n\\end{equation*}\n%\nand noting that the time-varying components will be integrated out by the\ndefinite integral, the optimization problem may be written as\n\\begin{equation*}\n  x_{i} = \\text{arg} \\min_{\\vec{x}} \\vec{x}^{T} \\mathbf{Q} \\vec{x}\n\\end{equation*}\n%\nThe structure of the integrand of $\\mathbf{Q}$ is revealed by first computing the initial couple\nderivatives of $\\vec{t}(\\tau)$.\n\\begin{align*}\n  \\vec{t(\\tau)} &= \n  \\begin{bmatrix}\n    \\frac{\\tau^{0}}{0!} & \\frac{\\tau^{1}}{1!} & \\frac{\\tau^{2}}{2!} & \\hdots\n  \\end{bmatrix} \\\\\n  \\frac{d \\vec{t(\\tau)}}{d\\tau} &= \n  \\begin{bmatrix}\n    0 & \\frac{\\tau^{0}}{0!} & \\frac{\\tau^{1}}{1!} & \\hdots\n  \\end{bmatrix} \\\\\n  \\frac{d^{2} \\vec{t(\\tau)}}{d\\tau^{2}} &= \n  \\begin{bmatrix}\n    0 & 0 & \\frac{\\tau^{0}}{0!} & \\hdots\n  \\end{bmatrix} \\\\\n\\end{align*}\n%\nNotice that successive derivatives pre-pad zeros and shift the vector\nto the right. \n\nThe integrand of $\\mathbf{Q}$ is found by taking the outer product of the\nderivative of the time vector with itself.\n\\begin{align*}\n  \\vec{t(\\tau)}^{T} \\vec{t(\\tau)} &= \n  \\begin{bmatrix}\n    \\frac{t^{0}}{0!} \\frac{t^{0}}{0!} & \\frac{t^{0}}{0!} \\frac{t^{1}}{1!} &\n    \\frac{t^{0}}{0!} \\frac{t^{2}}{2!}  & \\hdots \\\\[6pt]\n    \\frac{t^{1}}{1!} \\frac{t^{0}}{0!} & \\frac{t^{1}}{1!} \\frac{t^{1}}{1!} &\n    \\frac{t^{1}}{1!} \\frac{t^{2}}{2!}  & \\hdots \\\\[6pt]\n    \\frac{t^{2}}{2!} \\frac{t^{0}}{0!} & \\frac{t^{2}}{2!} \\frac{t^{1}}{1!} &\n    \\frac{t^{2}}{2!} \\frac{t^{2}}{2!}  & \\hdots \\\\[6pt]\n    \\vdots & \\vdots & \\vdots & \\ddots\n  \\end{bmatrix} \\\\\n  \\frac{d\\vec{t(\\tau)}}{d\\tau}^{T} \\frac{d\\vec{t(\\tau)}}{d\\tau} &= \n  \\begin{bmatrix}\n    0 & 0 & 0 & \\hdots \\\\[6pt]\n    0 & \\frac{t^{0}}{0!} \\frac{t^{0}}{0!} & \\frac{t^{0}}{0!} \\frac{t^{1}}{1!} & \\hdots \\\\[6pt]\n    0 & \\frac{t^{1}}{1!} \\frac{t^{0}}{0!} & \\frac{t^{1}}{1!} \\frac{t^{1}}{1!} & \\hdots \\\\[6pt]\n    \\vdots & \\vdots & \\vdots & \\ddots\n  \\end{bmatrix} \\\\\n  \\frac{d^{2}\\vec{t(\\tau)}}{d\\tau^{2}}^{T} \\frac{d^{2}\\vec{t(\\tau)}}{d\\tau^{2}} &= \n  \\begin{bmatrix}\n    0 & 0 & 0 & \\hdots \\\\[6pt]\n    0 & 0 & 0 & \\hdots \\\\[6pt]\n    0 & 0 & \\frac{t^{0}}{0!} \\frac{t^{0}}{0!} & \\hdots \\\\[6pt]\n    \\vdots & \\vdots & \\vdots & \\ddots\n  \\end{bmatrix} \\\\\n\\end{align*}\n% \nNotice that the outer product of successive derivatives pre-pads columns and rows\nwith zeros and shift rows down and columns to the right. This admits a\nconvenient way to compute the integrand of $\\mathbf{Q}$: take the outer product of\n$\\vec{t}(\\tau)$ with itself and shift the rows and columns by the power of the\nderivative.\n\\begin{equation*}\n  \\frac{d^{r}\\vec{t(\\tau)}}{d\\tau^{r}}^{T} \\frac{d^{r}\\vec{t(\\tau)}}{d\\tau^{r}}\n  = \\text{shift}(\\vec{t}(\\tau)^{T} \\vec{t}(\\tau), r) \n\\end{equation*}\n\\\\\nTo compute $\\mathbf{Q}$, the matrix integrand must be integrated. Integrating a\nmatrix is as easy as integrating its components element-wise. The polynomial\nstructure of the components of $\\mathbf{Q}$ admit and easy-to-compute integral\nformula:\n\\begin{equation*}\n  \\int \\frac{\\tau^{i}}{i!} \\frac{\\tau^{j}}{j!} d\\tau =\n  \\frac{\\tau^{i+j+1}}{i!j!(i+j+1)!}\n\\end{equation*}\n\\\\\nFinally, a careful observer might note that the structure of problem permits one\nto swap the shift and integrate operations. Instead of shifting all elements and\nthen integrating, one could integrate all elements and then shift. This\nsimplifies implementation in a for-loop-based subroutine.\n\\bigbreak\n\\noindent In summary, to compute $\\mathbf{Q}$:\n\\begin{enumerate}\n  \\item Compute the outer product of $\\vec{t}(\\tau)$ with itself\n  \\item Integrate the outer product\n  \\item Shift the rows and columns of the integrated matrix by the order of the\n    derivative\n\\end{enumerate}\n\n\\subsection{Relaxing Arrival Time}\nUntil this point, one very important topic has been overlooked: timing. Users\nmay specify arbitrary arrival times for waypoints. When times are too large, too\nsmall, or a combination of the both, numerical accuracy problems occur and many\noptimizers struggle to find sufficiently accurate solutions. To prevent this\nfrom occurring, segment time is normalized to $t \\in [0,1]$. Stated otherwise,\nevery segment in a trajectory is assumed to start at $t=0$ and end at $t=1$.\n\n\nThis new timing scheme is referred to as the \\textit{computational time} while\nthe original timing scheme is referred to as the \\textit{physical time}.\nTransforming the problem from physical time to computational time requires one\nto determine the segment index a particular time is, subtracting the start time,\nand normalized by the total segment time. The inverse transform is defined in a\nsimilar manner.\n\n\\subsection{Time Scaling}\nLet $t \\in [0, t_{f}]$ represent the physical time along a segment and $\\tau \\in\n[0, 1]$ represent the computational time along a segment. The two are related by\na scaling factor.\n%\n\\begin{equation}\n  t = \\alpha \\tau\n\\end{equation}\n%\nPath constraints are specified using physical time, but the polynomial functions\nand optimization use computational time. These two timing schemes must be\nreconciled. Let a constraint be defined as:\n%\n\\begin{equation*}\n  \\frac{dp(\\tau)}{dt} < \\kappa\n\\end{equation*}\n%\nChange of basis using $\\tau = t / \\alpha$ and $d\\tau = dt / \\alpha$. Substitute\nand rearrange:\n%\n\\begin{equation}\n  \\frac{dp(\\tau)}{d\\tau} < \\alpha \\kappa\n\\end{equation}\n%\nConstraints on higher derivatives are derived using the same process.\n\\begin{equation}\n  \\frac{dp^{n}(\\tau)}{dt^{n}} < \\kappa \\rightarrow\n  \\frac{dp^{n}(\\tau)}{d\\tau^{n}} < \\alpha^{n} \\kappa\n\\end{equation}\n%\nContinuity constraints (discussed in the next section) merit special\nconsideration. These constraints require that the $n$th derivative of the end of\na segment match the $n$th derivative of the following segment. Since the time\nscaling of each segment may be different, the constraint manifests so:\n\\begin{equation}\n  \\frac{dp_{k}^{n}(\\tau)}{d\\tau^{n}} \\frac{1}{\\alpha_{k}^{n}} =\n  \\frac{dp_{k+1}^{n}(\\tau)}{d\\tau^{n}} \\frac{1}{\\alpha_{k+1}^{n}}\n\\end{equation}\n\n\\subsection{Continuity Constraints}\nMost piecewise-continuous problems require some sort of continuity --- the\nposition, velocity, or acceleration must not instantaneously change at endpoints\nof the piecewise trajectory. Typically this is motivated by real-life\nconstraints: a quadcopter cannot instantaneously teleport or change its\nvelocity from 1 m/s to -3 m/s.\n\nConsider the first two segments of a scaler third-order piecewise polynomial\ntrajectory. Let the optimization vector contain the coefficients for both\nsegments of the trajectory.\n\\begin{equation*}\n  \\vec{x} =\n  \\begin{bmatrix}\n    x_{0} & v_{0} & a_{0} & j_{0} & x_{1} & v_{1} & a_{1} & j_{1}\n  \\end{bmatrix}^{T}\n\\end{equation*}\n%\nThe new quadratic matrix is a block-diagonal of the segment quadratic matrices.\n\\begin{equation*}\n  \\mathbf{Q} = \n  \\begin{bmatrix}\n    \\mathbf{Q}_{0} & \\mathbf{0} \\\\\n    \\mathbf{0} & \\mathbf{Q}_{1}\n  \\end{bmatrix}\n\\end{equation*}\n%\nThe new optimization function is:\n\\begin{equation*}\n  J = \\vec{x}^T \\mathbf{Q} \\vec{x}\n\\end{equation*}\n\nFor the function to be continuous, the first segment must be equal to the second\nsegment at the boundary point.\n\\begin{equation*}\n  p_{0}(t=1) - p_{1}(t=0) = 0 \\\\\n\\end{equation*}\n%\nWritten in matrix form:\n\\begin{equation*}\n  \\underbrace{\n  \\begin{bmatrix}\n    1/0! & 1/1! & 1/2! & 1/3! & -1/0! & 0 & 0 & 0 \\\\ \n  \\end{bmatrix}\n  }_{\\mathbf{A}}\n  \\underbrace{\n  \\begin{bmatrix}\n    x_{0} \\\\ \n    v_{0} \\\\\n    a_{0} \\\\\n    j_{0} \\\\\n    x_{1} \\\\\n    v_{1} \\\\\n    a_{1} \\\\\n    j_{1}\n  \\end{bmatrix}\n  }_{\\vec{x}}\n  =\n  \\vec{0}\n\\end{equation*}\n%\nOr equivalently\n\\begin{equation*}\n  \\vec{l} \\leq \\mathbf{A} \\vec{x} \\leq \\vec{u}\n\\end{equation*}\n%\nwhere both $\\vec{l}$ and $\\vec{u}$ are $\\vec{0}$ in this case. Continuity\nconstraints for arbitrary derivatives may be specified in a similar manner by\nleveraging the fact that the derivative of $\\vec{t}$ is a shifted version of\nitself. The derivatives may be formulated in the same $\\vec{l} \\leq \\mathbf{A}\n\\vec{x} \\leq \\vec{u}$. Without further justification, all continuity and\nwaypoint constraints may be formulated as bounded linear constraints.\n\n\n\\subsection{Path Constraints}\nPath constraints are necessary for any non-trivial path. For example, quadcopters\noften have input constraints and can't fly faster than or accelerate faster than\na certain limit. Alternatively, if obstacles are present, the position of the\npath should be constrained to be outside of obstacles.\n\nIn coordination with the continuity constraints, path constraints can be\nformulated in the form:\n\\begin{equation*}\n  \\vec{l} \\leq \\mathbf{A} \\vec{x} \\leq \\vec{u}\n\\end{equation*}\nUnfortunately, these constraints are linear --- they cannot be used to describe\nnon-linear constraints. For example, if a quadcopter is limited to a total\nacceleration of 0.5 m/$s^2$, then the two-norm magnitude of its acceleration\nshould be bounded. The two-norm magnitude is a non-linear constraint and cannot\nbe expressed. However, one could approximate it by specifying an arbitrary number of planes\ntangent-to or inscribed-in the hypersphere that delimits the two-norm. It's not\nperfect, but it enables the quadratic programming solver to find a solution\nfast.\n\nFinally, path constraints introduce one additional complication: violation of\ndimensional independence. Previously, I claimed that the dimensions are\nindependent and thus can be considered standalone as scalar polynomials. In the\npresence of path constraints, this is not necessarily true. Two dimensions can\nbe linked together by a path constraint. For example, consider approximating a\ntwo-norm magnitude by requiring:\n\\begin{align*}\n  x + y &< 1 \\\\\n  x - y &< 1 \\\\\n  -x + y &< 1 \\\\\n  -x - y &< 1\n\\end{align*}\nClearly these two dimensions are now linked. Despite this dependency, the scalar\nanalysis still holds. The dependency is managed by the quadratic programming\nsolver.\n\nOne last note: if there were no interdimensional dependence, a multi-dimensional\nproblem could be broken down into multiple scalar dimensional problems and\nsolved simultaneously by multiple solvers distributed over multiple threads.\nHowever, it's usually the case that at least one path constraint introduces\ninterdimensional dependence and this technique cannot be leveraged.\n\n\n\n\n\\subsection{Quadratic Programming}\nThe problem of finding these piecewise polynomials can be cast as a quadratic\nprogramming problem:\n%\n\\begin{equation}\n  \\begin{split}\n    \\min_{\\vec{x}} \\quad& \\frac{1}{2} \\vec{x}^T \\mathbf{Q} \\vec{x}  \\\\\n    \\text{s.t.} \\quad& \\vec{l} \\leq \\mathbf{A} \\vec{x} \\leq \\vec{u}\n  \\end{split}\n\\end{equation}\n%\n\\href{https://osqp.org}{OSQP} is used to solve the QP problem \\cite{osqp}.\n\n\\bibliography{main}\n\\bibliographystyle{IEEEtran}\n\n\\end{document}\n", "meta": {"hexsha": "cf3d455375ac185f92b328da287ab714b29bd533", "size": 15064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/main.tex", "max_stars_repo_name": "TuckerHaydon/MinimumSnap", "max_stars_repo_head_hexsha": "474ec8edfec45adb4291f945736772c335dc9cc8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-29T07:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-31T03:37:48.000Z", "max_issues_repo_path": "doc/tex/main.tex", "max_issues_repo_name": "TuckerHaydon/MinimumSnap", "max_issues_repo_head_hexsha": "474ec8edfec45adb4291f945736772c335dc9cc8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-04-16T23:00:18.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-09T18:37:04.000Z", "max_forks_repo_path": "doc/tex/main.tex", "max_forks_repo_name": "TuckerHaydon/MinimumSnap", "max_forks_repo_head_hexsha": "474ec8edfec45adb4291f945736772c335dc9cc8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-04-18T21:44:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-05T09:55:09.000Z", "avg_line_length": 36.8312958435, "max_line_length": 102, "alphanum_fraction": 0.6776420605, "num_tokens": 5051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6148262769948281}}
{"text": "\\chapter*{Part One: Count Based Language Modeling}\n\\addcontentsline{toc}{chapter}{Part One}\n\n\n\n    % \\begin{lstlisting}[style=latexFrameTB, caption={Example of Sleek Template packages usage.}, gobble=8]\n    %     \\usepackage[english]{babel}\n    %     \\usepackage[noheader]{packages/sleek}\n    %     \\usepackage{packages/sleek-title}\n    % \\end{lstlisting}\n\n\n\\subsection*{Theoretical Problem A}\nThe assignment is to solve for the maximum likelihood estimate (MLE) of a bigram language model, where the likelihood function is given by\n\n\\begin{equation*}\n    \\prod_{t=1}^{T} p_{\\theta_{u,v}}(w_t | w_{t-1})\n\\end{equation*}\n\nFor brevity, I will refer to  $p_{\\theta_{u,v}}$ as simply \\theta. \n\nIf we define our corpus to consist of many two word pairs, or bigrams, we can re-write the likelihood as\n\n\\begin{equation*}\n    \\prod_{t=1}^{T} \\theta^{c(u,v)}\n\\end{equation*}\n\nwhere $c(u,v)$ represents the count of how many times the bigram $u,v$ appears in the corpus.\n\nIt is convenient to rewrite our function in terms of the log likelihood:\n\\begin{equation*}\n    \\sum_{t=1}^{T} c(u,v) * \\ln{\\theta}\n\\end{equation*}\n\nWe want to maximize the log likelihood in terms subject to the constraint that the probabilities $\\theta$ sum to 1:\n\\begin{equation*}\n    \\sum_{u,v\\in \\mathcal{V}} \\theta = 1\n\\end{equation*}\n\nWe introduce a Lagrangian multiplier to solve the problem in the form \n\\begin{equation*}\n    \\mathcal{L}(\\theta,\\lambda) = L(\\theta) - \\lambda f(\\theta)\n\\end{equation*},\nyielding\n\\begin{equation*}\n    \\mathcal{L}(\\theta,\\lambda) = \\sum_{t=1}^{T} c(u,v) * \\ln(\\theta) - \\lambda (\\sum_{u,v\\in \\mathcal{V}}\\theta -1)\n\\end{equation*}\n\nTaking the partial derivatives gives the following system of equations:\n\n\\begin{equation*}\n    \\frac{\\partial}{\\partial \\theta} = \\frac{c(u,v)}{\\theta} - \\lambda = 0\n\\end{equation*}\n\n\\begin{equation*}\n    \\frac{\\partial}{\\partial \\lambda} = \\sum \\theta - 1 = 0\n\\end{equation*}\n\nSolve the system of linear equations:\n\n\\begin{equation*}\n    \\theta = \\frac{c(u,v)}{\\lambda}\n\\end{equation*}\n\n\\begin{equation*}\n    \\sum \\frac{c(u,v)}{\\lambda} = 1\n\\end{equation*}\n\n\\begin{equation*}\n    \\lambda = \\frac{1}{\\sum c(u,v)}\n\\end{equation*}\n\nThe final solution to the system of equations is the MLE of the bigram model:\n\\begin{equation*}\n    {\\hat \\theta_{u,v}} = \\frac{c(u,v)}{\\sum_{u,v\\in \\mathcal{V}}c(u,v)}\n\\end{equation*}\n\n\\subsection*{Theoretical Problem B}\n\nThe assignment is to show that for the case of a unigram language model, given a prior distribution of a Dirichlet distribution, setting all values in parameter vector $\\beta$ results in a posterior distribution with mean equal to the Laplace smoothing estimate:\n\n\\begin{equation*}\n    \\hat{\\theta}_u = \\frac{c(u) + \\alpha}{T + \\alpha|\\mathcal{V}'}\n\\end{equation*}\n\nThe posterior is defined as:\n\\begin{equation*}\n    p(\\pi|D;\\beta) = \\frac{p(D|\\pi)p(\\pi;\\beta)}{p(D)}\n\\end{equation*}\n\nThe density function for the prior is:\n\\begin{equation*}\n    p(\\pi;\\beta) = \\frac{1}{B(\\beta)}\\prod_{u \\in \\mathcal{V}}\\pi_u^{\\beta_u - 1}\n\\end{equation*}\n\nThe likelihood model of $p(D|\\pi)$ is given by:\n\\begin{equation*}\n    \\prod \\pi_u^{c(u)}\n\\end{equation*}\nwhere we multiply over probabilities over all words in the corpus and account for duplicates with the count term in the exponent. \n\nPlugging the density function (ignoring the normalizing constant $B(\\beta)$) and likelihood model into the posterior gives\n\\begin{equation*}\n    p(\\pi|D;\\beta) = \\frac{\\prod \\pi_u^{c(u)} * \\frac{1}{B(\\beta)}\\prod_{u \\in \\mathcal{V}}\\pi_u^{\\beta_u - 1}}{p(D)}\n\\end{equation*}\n\n\\begin{equation*}\n    = \\frac{\\prod \\pi_u^{c(u) + \\alpha - 1}}{p(D)}\n\\end{equation*}\n\nThe numerator of this equation is itself a Dirichlet distribution with parameter vector $\\beta' = c(u) + \\alpha -1$. Because we are changing the observed data by applying a smoothing constant, p(D) becomes trivial. Our result is proportional and the $p(D)$ term does not impact the result. Observe that the expected value of the $\\beta'$ distribution is \n\n\\begin{equation*}\n    \\mathbb{E_{p(\\pi|D;\\beta')}} = \\frac{c(u) + \\alpha}{\\sum_u^{\\mathcal{V}} c(u) + \\alpha}\n\\end{equation*}\n\nWe have increased the count of every word in our corpus by $\\alpha$, meaning the size of the corpus has increased by $\\alpha$ times the number of unique words. This yields\n\n\\begin{equation*}\n    \\mathbb{E_{p(\\pi|D;\\beta')}} = \\frac{c(u) + \\alpha}{T + \\alpha|\\mathcal{V}|} = \\theta_u\n\\end{equation*}\nwhere $T$ is the size of the original corpus. \n\n\\chapter*{Part Two: RNN Language Modeling}\n\\addcontentsline{toc}{chapter}{Part Two}\n\n\\subsection*{Computational Problem A}\n\nIn order to determine if a substring is part of BPL, I observe that one must know three quantities: the number of \"(\", the number of \")\", and if an illegal \")\" has ever been observed. A \")\" is illegal if there is not already a matching \"(\". \n\nMy hidden state is a column vector with elements \\begin{bmatrix}\n    \"(\" count \\\\ \")\" count \\\\ Illegal \\\\\n\\end{bmatrix}. The initial hidden state is given by \n\\begin{equation*}\n    h_0 = \\begin{bmatrix}\n        -1 \\\\ -1 \\\\ 0 \\\\\n    \\end{bmatrix}\n\\end{equation*}\n\n\n$x_t$ is a vector representing either \"(\" or \")\", where I map \\begin{bmatrix}\n    1 && 0 && 0\n\\end{bmatrix} to  \"(\" and \\begin{bmatrix}\n    0 && 1 && 0\n\\end{bmatrix} to \")\".\n\nW and U are unnecessary in my BPL model, and are set to 1. The update function is given by the piecewise function \n\n\\begin{equation*}\n    f (x) = \n     \\begin{cases} \n        x & x * \\begin{bmatrix}\n            1 && -1 && 0\n        \\end{bmatrix}\\geq 0 \\\\\n        x + \\begin{bmatrix}\n            0 \\\\ 0 \\\\ 1 \\\\\n        \\end{bmatrix} & x * \\begin{bmatrix}\n            1 && -1 && 0\n        \\end{bmatrix}< 0 \\\\\n     \\end{cases}\n  \n\\end{equation*}\n\nIf $h_t \\lbrack 0 \\rbrack - h_t \\lbrack 1 \\rbrack $ is 0 and $h_t \\lbrack 2 \\rbrack $ is 0 then $x_t$ is in BPL.\n\n\\subsection*{Vanilla Recursive Neural Network Implementation}\n\nNote to the teaching assistant: I apologize for some weak analysis in the implementation sections. I finished all my code several days ago, but forgot to check the notebook into Github and lost all of my code on Monday night when Chrome crashed. \n\nMy vanilla RNN is essentially a wrapper around either an RNNCell or an LSTMCell. The forward function takes a matrix of input ids representing a batch of sentences, and maps them to an embedding. We then initialize a hidden state to zeros, and iterate over the embeddings symbol by symbol for the 50 symbol sequence. At every step the previous hidden state $h_{t-1}$ is fed back into the model, as well as the next embedding column. \n\nThe perplexity of just my basic model is shown below in Figure \\label{firsttry}. \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{resources/png/no_bias_1e3.png}\n    \\noskipcaption{Perplexity of a vanilla RNN over 10 epochs with learning rate 1e-3}\n    \\label{firsttry}\n\\end{figure}\n\nThe fact that the perplexity gets worse with more training implies that perhaps my optimizer is descending too far, and passing over the maximum for a local maxima. My perplexity rating is far away from the target somewhere in the 70s, so I decided to use a new architecture. Long Short Term Memory or LSTM incorporate a feedback mechanism in addition to the feed-forward method of an RNN. This allows the network to develop connections over longer sequences, potentially allowing for context a vanilla RNN can't achieve. My LSTM has perplexity ~78 as shown in Figure \\label{secondtry}.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{resources/png/LSTM_05e3.png}\n    \\noskipcaption{Perplexity of a LSTM RNN over 10 epochs with learning rate 5e-4}\n    \\label{secondtry}\n\\end{figure}\n\n\\subsection*{Sequence to Sequence Model}\nA sequence to sequence model interprets an input sequence through an input neural network called an encoder, and then feeds the final layer of the encoder through a decoder to produce the output sequence. \n\nMy decoder contains a Gated Recurrent Unit, which functions similar to an LSTM but it also can \"forget\". I chose it because some research indicates GRUs function well on smaller vocabularies (\"Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling\", Chung et al), although I did not have time to compare to other architectures. \n\nAdditionally I feed the output of my GRU through a linear layer. Empirically this improved my BLEU score by about 0.5, although I do not have great intuition for why. \n\nThe first attempt at a decoder with a single layer GRU and no linear layer achieved a perplexity score in the mid 40s (Figure \\label{seq1}).\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{resources/png/seq2seq1layer.png}\n    \\noskipcaption{Single layer GRU Decoder perplexity}\n    \\label{seq1}\n\\end{figure}\n\nAdding a second GRU layer and the hidden layer resulted in a perplexity in the low 30s, with a BLEU score of 6.83 (Figure \\label{seq2}). \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{resources/png/seq.png}\n    \\noskipcaption{Double layer GRU with linear output Decoder perplexity}\n    \\label{seq1}\n\\end{figure}\n\nOne thing I noticed about my decoder is the output produces some seemingly unrelated predictions sometimes; the following example is taken from the training data:\n\n    Src :  Tôi đoán các bạn đều đã biết về lịch sử của &quot; đàn quay &quot; trong tiếng Pháp là &quot; <unk> à <unk> &quot;  \\hline\n    Trg :  I see you &apos;re all up on the history of hurdy-gurdy -- &quot; <unk> <unk> <unk> . &quot; \\hline\n    Pred:  I think you know what most of the most popular TEDTalks &quot; is &quot; <unk> . &quot; \\hline\n\nI looked it up, and there is a sentence about TEDTalks right next to a sentence relating to hurdy-gurdies in the training data. I suspect my batch data is getting entangled. This could be fixed by duplicating some of the training data but with sentences rearranged more randomly, or by playing with the batch size parameters. \n\nAnother error is that the prediction seems to sometimes follow the most likely path, regardless of sentence context. \n\nSrc :  Tôi muốn cho các bạn biết về sự to lớn của những nỗ lực khoa học đã góp phần làm nên các dòng tít bạn thường thấy trên báo . \\hline\nTrg :  I &apos;d like to talk to you today about the scale of the scientific effort that goes into making the headlines you see in the paper . \\hline\nPred:  I want to tell you about the most important thing that you &apos;ve learned in the first place of the brain that works in the front of the job . \\hline\n\nIn this example it starts out alright, but I suspect addressing a second person after stating \"I want to tell you\" is more common than \"scientific effort...\". If my model had beam search, it could explore multiple paths instead of just taking the likely followup to a shorter sequence. \n\n\n\\chapter*{Appendix}\n\\subsection*{Vanilla RNN}\n\\begin{python}\n    class RNN(nn.Module):\n\n    def __init__(self, input_size, hidden_size, src_embed, generator, LSTM=True):\n      \"\"\"\n      Inputs:\n        - `input_size`: a positive integer corresponding to the size of the\n            word embeddings\n        - `hidden_size`: a positive integer representing the dimensionality of\n            the RNN's hidden state vector\n        - `src_embed`: an nn.Embedding object representing the lookup table for\n            input (source) sentences\n        - `generator`: a `Generator` object. Essentially a linear mapping\n            followed by a softmax. You should not call it within this class; it\n            is called in the SimpleLossCompute class above\n      \"\"\"\n      super(RNN, self).__init__()\n      # `input_size`, `hidden_size`, and `output_size` are all int.\n\n      self.hidden_size = hidden_size\n      self.src_embed = src_embed\n      self.generator = generator\n      self.use_lstm = LSTM\n      # hint: unless you choose to implement the RNN update equations yourself\n      #       you will want a `self.rnn` module that does that for you, which\n      #       is where the RNNCell/LSTMCell/GRUCell modules come in handy\n\n      self.rnn = nn.RNNCell(input_size, hidden_size, bias=False, device=device)\n      self.lstm = nn.LSTMCell(input_size, hidden_size, device=device)\n\n\n    def forward(self, input_ids):\n      \"\"\"\n      Given a sequence of words (represented as IDs), compute and return the\n      hidden state at each timestep (equivalently, for each input word).\n      Input:\n        - `input_ids`: a 2d-tensor of shape\n           (batch_size, MAX_SENT_LENGTH_PLUS_SOS_EOS) representing a batch of\n           sentences from the dataset (with IDs instead of words)\n\n      Returns:\n        - `hiddens`: a 3d-tensor of shape\n            (batch_size, MAX_SENT_LENGTH_PLUS_SOS_EOS, hidden_size) representing\n            the hidden state of the model at each timestep\n      \"\"\"\n      # hint: pay close attention to the shapes of your tensors; you may find\n      #       pytorch's `permute()` method for tensors useful\n\n      ### Your code here!\n      bsize, fsize = input_ids.size()\n\n      hsize = self.hidden_size\n\n      embedding = self.src_embed(input_ids)\n      embedding = embedding.transpose(0,1).contiguous()\n \n      hidden = self.init_hidden(bsize)\n      output = []\n      if self.use_lstm:\n        cell_state = self.init_hidden(bsize)\n        for i in range(fsize):\n          hidden, cell_state = self.lstm(embedding[i], (hidden, cell_state))\n          output.append(hidden)\n      else:\n        for index in range(fsize):\n          hidden = self.rnn(embedding[index], hidden)\n          output.append(hidden)\n      \n      output = torch.stack(output, dim=1)\n      return output\n\n    def init_hidden(self, batch_size):\n      \"\"\"\n      Input:\n        - `batch_size`: a positive integer\n\n      Returns:\n        - `hidden`: a 2d-tensor of shape (batch_size, hidden_size) representing\n            the initial hidden state of the RNN\n      \"\"\"\n      # Use to initialize hidden state everytime before running a sentence.\n      hidden = torch.zeros(batch_size, self.hidden_size).to(device)\n      return hidden\n\\end{python}\n\n\\subsection*{Seq2Seq}\n\\begin{python}\n    class Decoder(nn.Module):\n  \"\"\"An RNN decoder without attention.\"\"\"\n\n  def __init__(self, input_size, hidden_size, dropout=0.):\n    \"\"\"\n      Inputs:\n        - `input_size`, `hidden_size`, and `dropout` the same as in Encoder.\n    \"\"\"\n    super(Decoder, self).__init__()\n\n    # hint 1: while the encoder just needed a single RNN layer, more will be\n    #         required for the decoder.\n    # hint 2: think about what you'll need in init_hidden(self, encoder_finals)\n    # hint 3: what will you use to compute the pre_output (see docstring of\n    #         forward function)?\n\n    ### Your code here!\n    print(\"Creating Decoder with input size {} and hidden size {}\".format(input_size, hidden_size))\n    self.bsize = input_size\n    self.hsize = hidden_size\n    self.nlayers = 2\n    \n    self.gru = nn.GRU(input_size=input_size, \n                      hidden_size=hidden_size, \n                      num_layers=self.nlayers, \n                      batch_first=True, dropout=dropout, \n                      bidirectional=False, device=device)\n    \n    self.lin = nn.Linear(input_size, hidden_size, device=device)\n\n  def forward_step(self, prev_embed, hidden):\n    \"\"\"Helper function for forward below:\n       Perform a single decoder step (1 word).\n\n       Inputs:\n      - `prev_embed`: a 3d-tensor of shape (batch_size, 1, embed_size)\n          representing the padded embedded word vectors at this step in training\n      - `hidden`: a 3d-tensor of shape (1, batch_size, hidden_size) representing\n          the current hidden state.\n\n      Returns:\n      - `hidden`: a 3d-tensor of shape (1, batch_size, hidden_size)\n          representing the current decoder hidden state.\n      - `pre_output`: a 3d-tensor of shape (batch_size, 1, hidden_size)\n          representing the total decoder output for one step\n    \"\"\"\n    # hint: you'll want to do more here than just run self.rnn (think about\n    #       what you should do to the output of the self.rnn in order to\n    #       compute the `pre_output`)\n\n    pre_output, hidden = self.gru(prev_embed, hidden)\n    x = pre_output.to(device)\n    pre_output = self.lin(x)\n    return hidden, pre_output\n    \n  def forward(self, inputs, encoder_finals, hidden=None, max_len=None):\n    \"\"\"Unroll the decoder one step at a time.\n\n    Inputs:\n      - `inputs`: a 3d-tensor of shape (batch_size, max_seq_length, embed_size)\n          representing a batch of padded embedded word vectors of target\n          sentences (for teacher-forcing during training).\n      - `encoder_finals`: a 3d-tensor of shape\n          (num_enc_layers, batch_size, hidden_size) representing the final\n          encoder hidden states used to initialize the initial decoder hidden\n          states.\n      - `hidden`: a 3d-tensor of shape (1, batch_size, hidden_size) representing\n          the value to be used to initialize the initial decoder hidden states.\n          If None, then use `encoder_finals`.\n      - `max_len`: an int representing the maximum decoding length.\n\n    Returns:\n      - `hidden`: a 3d-tensor of shape\n          (num_layers, batch_size, hidden_size) representing the final hidden\n          state for each element in the batch.\n      - `pre_output_vectors`: a 3d-tensor of shape\n          (batch_size, max_len, hidden_size) representing the raw decoder\n          outputs (before mapping to a `trg_vocab_size`-dim vector).\n    \"\"\"\n\n    # The maximum number of steps to unroll the RNN.\n    if max_len is None:\n      max_len = inputs.size(1)\n\n    # Initialize decoder hidden state.\n    if hidden is None:\n      hidden = self.init_hidden(encoder_finals)\n\n    # hint: you'll want to keep track of the `pre_output` for each timestep,\n    #       but you only need the final `hidden` state\n\n    ### Your code here!\n    bsize,fsize,hsize = inputs.size()\n    pre_output_vectors = []\n    for i in range(fsize):\n      input = torch.unsqueeze(inputs[:,i,:], 1)\n      hidden, pre_output = self.forward_step(input, hidden)\n      pre_output_vectors.append(pre_output)\n\n    pre_output_vectors = torch.stack(pre_output_vectors, dim=1).squeeze(2)\n    return hidden, pre_output_vectors\n\n  def init_hidden(self, encoder_finals):\n    \"\"\"Use encoder final hidden state to initialize decoder's first hidden\n       state.\n\n       Input: `encoder_finals` is same as in forward()\n\n       Returns: \n         - `decoder_init_hiddens`: a 3d-tensor of shape \n              (num_layers, batch_size, hidden_size) representing the initial\n              hidden state of the decoder for each element in the batch \n    \"\"\"\n    # hint: think about whether or not an activation function is needed here\n\n    ### Your code here!\n    \n    decoder_init_hiddens = torch.ones(self.nlayers,1,1,device=device) * encoder_finals\n\n    return decoder_init_hiddens\n\\end{python}\n\n", "meta": {"hexsha": "954d814e7cf39aff8ce4b65b75f2aea742abc6e9", "size": 18872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework_1/report/content.tex", "max_stars_repo_name": "RichardMuri/MIT_6864", "max_stars_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_stars_repo_licenses": ["MIT"], "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/report/content.tex", "max_issues_repo_name": "RichardMuri/MIT_6864", "max_issues_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_issues_repo_licenses": ["MIT"], "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/report/content.tex", "max_forks_repo_name": "RichardMuri/MIT_6864", "max_forks_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_forks_repo_licenses": ["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.6004514673, "max_line_length": 586, "alphanum_fraction": 0.6884802883, "num_tokens": 5018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.8791467611766711, "lm_q1q2_score": 0.6147472595122757}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[top=1.5cm,bottom=1.5cm]{geometry}\n\\usepackage[T1]{fontenc}\n\\usepackage{url}\n\\usepackage{hyperref}\n\\usepackage{xcolor}\n% \n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{ifthen}\n\\usepackage{mathpartir}\n\\usepackage{mathtools}\n\\input{macros}\n% \n\\begin{document}\n\n\\title{CO663: Language $\\lggeT$ --- double}\n\n\\date{\\vspace{-7ex}} \n\\maketitle\n\n% \\pagenumbering{gobble}\n\n\\newcommand{\\lazyeval}[1]{\\framebox{\\parbox[c][#1]{\\textwidth}{\n      \\color{white}{h}% \n    }}}\n\n\n\\section{Correct implementation}\n\nA function that doubles its argument can be defined as follows:\n%\n\\[\n\\text{double} \\defi \n\\clam{\\tynat}{x}\n{\n  \\citer{\\ez}{v}{\\esucc{\\esucc{\\var{v}}}}{\\var{x}}\n}\n\\]\n\n\nWe can convince ourselves that it works as expected by applying it to\nsome parameter (${\\esucc{\\ez}}$ or 1)  and evaluate it.\n\\begin{enumerate}\n\\item Instantiate the function: \\[\n  \\semrule\n  {\\tsemrulename{lav}}\n  {\\,}\n  {\\jtrans\n    {\\capp{\\text{double}}{\\esucc{\\ez}}}\n    {\n      \\citer{\\ez}{v}{\\esucc{\\esucc{\\var{v}}}}{{\\esucc{\\ez}}}\n    }}\n  \\]\n\\item Iterate once (and using $\\alpha$-renaming, for safety):\n  \\[\n  \\semrule\n  {\\tsemrulename{rs}}\n  {\\,}\n  {\n    \\jtrans\n    {\n      \\citer{\\ez}{v}{\\esucc{\\esucc{\\var{v}}}}{{\\esucc{\\ez}}}\n    }\n    {\n      \\subs\n      {\\esucc{\\esucc{\\var{v}}}}\n      {\n        \\citer{\\ez}{v'}{\\esucc{\\esucc{\\var{v'}}}}{{{\\ez}}}\n      }\n      {v}\n    }\n  }\n  \\]\n\\item Applying the substitution, we obtain\n  \\[\n  {\\esucc{\\esucc{\n        \\citer{\\ez}{v'}{\\esucc{\\esucc{\\var{v'}}}}{{{\\ez}}}\n      }}}\n  \\]\n\\item Reducing one more time:\n  \\[\n  \\semrule\n  {\\tsemrulename{ss}}\n  {\n    \\semrule\n    {\\tsemrulename{ss}}\n    {\n      \\semrule\n      {\\tsemrulename{r0}}\n      {\\,}\n      { \\jtrans{{{\n            \\citer{\\ez}{v'}{\\esucc{\\esucc{\\var{v'}}}}{{{\\ez}}}\n          }}}\n      {{{\\ez}}}}\n    }\n    { \\jtrans{{\\esucc{\n            \\citer{\\ez}{v'}{\\esucc{\\esucc{\\var{v'}}}}{{{\\ez}}}\n          }}}\n      {{\\esucc{\\ez}}}}\n  }\n  {\n    \\jtrans{\\esucc{\\esucc{\n          \\citer{\\ez}{v'}{\\esucc{\\esucc{\\var{v'}}}}{{{\\ez}}}\n        }}}\n    {\\esucc{\\esucc{\\ez}}}\n  }\n  \\]\n\\end{enumerate}\n\n\n\n\n\\section{Wrong implementation}\n\nIf we use $\\var{x}$ instead of $\\var{v}$ in the inductive case, we\nget:\n\\[\n\\text{baddouble} \\defi \n\\clam{\\tynat}{x}\n{\n  \\citer{\\ez}{v}{\\esucc{\\esucc{\\var{\\underline{x}}}}}{\\var{{x}}}\n}\n\\]\n\nWe can convince ourselves that it \\emph{does not} work as expected by\napplying it to some parameter (${\\esucc{\\ez}}$ or 1) and evaluate it.\n% \n\\begin{enumerate}\n\\item Instantiate the function: \n  % \n  \\[\n  \\semrule\n  {\\tsemrulename{lav}}\n  {\\,}\n  {\\jtrans\n    {\\capp{\\text{baddouble}}{\\esucc{\\ez}}}\n    {\n      \\citer{\\ez}{v}{\\esucc{\\esucc{\\esucc{\\ez}}}}{{\\esucc{\\ez}}}\n    }}\n  \\]\n\\item   Iterate once (and using $\\alpha$-renaming, for safety):\n  \\[\n  \\semrule\n  {\\tsemrulename{rs}}\n  {\\,}\n  {\n    \\jtrans\n    {\n      \\citer{\\ez}{v}{\\esucc{\\esucc{\\esucc{\\ez}}}}{{\\esucc{\\ez}}}\n    }\n    {\n      \\subs\n      {\\esucc{\\esucc{\\esucc{\\ez}}}}\n      {\n        \\citer{\\ez}{v'}{\\esucc{\\esucc{\\esucc{\\ez}}}}{\\ez}\n      }\n      {v}\n    }\n  }\n  \\]\n\\item Applying the substitution, we obtain (note that $\\var{v}$ does\n  not appear in the term, so there is nothing to replace).\n  \\[\n  {\\esucc{\\esucc{\\esucc{\\ez}}}}\n  \\]\n\\item ${\\esucc{\\esucc{\\esucc{\\ez}}}}$ is a value, so we stop\n  here. Notice that the final result is $3$! \n\\end{enumerate}\n\n\n\n\n\\end{document}\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "77b0d223067a32678e0840eca6cee6b0b0c1932f", "size": 3477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/double.tex", "max_stars_repo_name": "julien-lange/CO663-slides", "max_stars_repo_head_hexsha": "40bc888c7389ae9554bfddc90d22b078c6e5d5d6", "max_stars_repo_licenses": ["MIT"], "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/double.tex", "max_issues_repo_name": "julien-lange/CO663-slides", "max_issues_repo_head_hexsha": "40bc888c7389ae9554bfddc90d22b078c6e5d5d6", "max_issues_repo_licenses": ["MIT"], "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/double.tex", "max_forks_repo_name": "julien-lange/CO663-slides", "max_forks_repo_head_hexsha": "40bc888c7389ae9554bfddc90d22b078c6e5d5d6", "max_forks_repo_licenses": ["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.1043956044, "max_line_length": 69, "alphanum_fraction": 0.54932413, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6146666190268752}}
{"text": "\\documentclass{article}\n\\usepackage{eecstex}\n\\usepackage{pgfplots}\n\n\\title{EE 123 HW 04}\n\\author{Bryan Ngo}\n\\date{2022-02-11}\n\n\\begin{document}\n\n\\maketitle\n\n\\setcounter{section}{2}\n\n\\section{}\n\n\\subsection{}\n\nEach circular convolution in the overlap-save method will result in a length \\(2^v - P + 1\\) signal.\nThen, the cost of the FFT and IFFT is \\(\\frac{2^v}{2} \\log_2(2^v) = v 2^{v - 1}\\).\nThen, there is a \\(2^v\\)-pointwise multiplication.\nThe total number of multiplications is \\(2^v (v + 1)\\).\nThus, the FFT for each sample will require\n\\begin{equation}\n    \\frac{2^v (v + 1)}{2^v - P + 1}.\n\\end{equation}\ncomplex multiplications per output sample.\n\n\\subsection{}\n\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(v\\), ylabel={Cost},\n            title={Complex Multiplications},\n            axis lines=middle,\n            width=0.4\\textwidth\n        ]\n        \\addplot[ycomb, mark=*, color=blue] table[\n            col sep=comma,\n            x=v, y=cost\n        ]{q3.csv};\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\nwith a minimum cost of \\(v = 12\\).\nThe direct evaluation would cost \\(500\\) complex multiplications per output sample, since that is the length of a given sample.\n\n\\subsection{}\n\n\\begin{equation}\n    \\lim_{v \\to \\infty} \\frac{2^v (v + 1)}{2^v - P + 1} = \\lim_{v \\to \\infty} \\frac{v + 1}{1 - \\left(\\frac{P - 1}{2^v}\\right)} = v\n\\end{equation}\nThus, for \\(P = 500\\), the direct method will be more efficient for \\(v > 500\\).\n\n\\newpage\n\\section{Fun with FFT}\n\n\\begin{enumerate}\n    \\item For \\(0 \\leqslant k < N\\), \\(H[k] = X_r[k] + W_{2N}^k X_i[k]\\).\n    \\item For \\(0 \\leqslant k < N\\), \\(H[k + N] = X_r[k] - W_{2N}^k X_i[k]\\).\n    \\item \\(X[k] = \\frac{1}{2} (H[k] + H[k + N]) + \\frac{j}{2} W_{2N}^{-k} (H[k] - H[k + N])\\), which takes 3 multiplications and 3 additions.\n\\end{enumerate}\n\n\\newpage\n\\section{Hadamard Transform}\n\n\\subsection{}\n\n\\begin{equation}\n    H_3 =\n    \\begin{bmatrix}\n        1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n        1 & -1 & 1 & -1 & 1 & -1 & 1 & -1 \\\\\n        1 & 1 & -1 & -1 & 1 & 1 & -1 & -1 \\\\\n        1 & -1 & -1 & 1 & 1 & -1 & -1 & 1 \\\\\n        1 & 1 & 1 & 1 & -1 & -1 & -1 & -1 \\\\\n        1 & -1 & 1 & -1 & -1 & 1 & -1 & 1 \\\\\n        1 & 1 & -1 & -1 & -1 & -1 & 1 & 1 \\\\\n        1 & -1 & -1 & 1 & -1 & 1 & 1 & -1\n    \\end{bmatrix}\n\\end{equation}\nThe order that represents increasing frequency content is the sequency ordering.\n\n\\subsection{}\n\n\\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{q5b.png}\n\\end{center}\n\n\\newpage\n\\section{}\n\n\\subsection{}\n\n\\begin{align}\n    X[3k] &= \\sum_{n = 0}^{N - 1} x[n] W_N^{3kn} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{3kn} + \\sum_{n = \\frac{N}{3}}^{\\frac{2N}{3} - 1} x[n] W_N^{3kn} + \\sum_{n = \\frac{2N}{3}}^{N - 1} x[n] W_N^{3kn} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{3kn} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{N}{3}\\right] W_N^{3kn} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{2N}{3}\\right] W_N^{3kn} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\left(x[n] + x\\left[n + \\frac{N}{3}\\right] + x\\left[n + \\frac{2N}{3}\\right]\\right) W_N^{3kn} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\underbrace{\\left(x[n] + x\\left[n + \\frac{N}{3}\\right] + x\\left[n + \\frac{2N}{3}\\right]\\right)}_{x_1[n]} W_{\\frac{N}{3}}^{kn}\n\\end{align}\n\n\\subsection{}\n\n\\begin{align}\n    X[3k + 1] &= \\sum_{n = 0}^{N - 1} x[n] W_N^{n(3k + 1)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{n(3k + 1)} + \\sum_{n = \\frac{N}{3}}^{\\frac{2N}{3} - 1} x[n] W_N^{n(3k + 1)} + \\sum_{n = \\frac{2N}{3}}^{N - 1} x[n] W_N^{n(3k + 1)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{n(3k + 1)} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{N}{3}} W_N^{n(3k + 1)} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{2N}{3}} W_N^{n(3k + 1)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\left(x[n] + x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{N}{3}} + x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{2N}{3}}\\right) W_N^{n(3k + 1)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\underbrace{\\left(x[n] + x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{N}{3}} + x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{2N}{3}}\\right) W_N^n}_{x_2[n]} W_{\\frac{N}{3}}^{kn} \\\\\n    X[3k + 2] &= \\sum_{n = 0}^{N - 1} x[n] W_N^{n(3k + 2)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{n(3k + 2)} + \\sum_{n = \\frac{N}{3}}^{\\frac{2N}{3} - 1} x[n] W_N^{n(3k + 2)} + \\sum_{n = \\frac{2N}{3}}^{N - 1} x[n] W_N^{n(3k + 2)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} x[n] W_N^{n(3k + 2)} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{2N}{3}} W_N^{n(3k + 2)} + \\sum_{n = 0}^{\\frac{N}{3} - 1} x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{4N}{3}} W_N^{n(3k + 2)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\left(x[n] + x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{2N}{3}} + x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{4N}{3}}\\right) W_N^{n(3k + 2)} \\\\\n    &= \\sum_{n = 0}^{\\frac{N}{3} - 1} \\underbrace{\\left(x[n] + x\\left[n + \\frac{N}{3}\\right] W_N^{\\frac{N}{3}} + x\\left[n + \\frac{2N}{3}\\right] W_N^{\\frac{2N}{3}}\\right) W_N^{2n}}_{x_3[n]} W_{\\frac{N}{3}}^{kn}\n\\end{align}\n\n\\subsection{}\n\n\\begin{center}\n    \\includegraphics[width=0.7\\textwidth]{q6c.png}\n\\end{center}\n\n\\subsection{}\n\n\\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{q6d.png}\n\\end{center}\n\n\\newpage\n\\section{}\n\n\\begin{enumerate}\n    \\item \\(|X[k]| \\leqslant N\\) for \\(k = 0\\).\n    \\item We want \\(x[n]\\) to be a constant under the DFT, so we can cancel out the complex exponential terms to obtain \\(x[n] = e^{j \\theta} W_N^{-kn}\\) for all \\(\\theta \\in \\R\\), and \\(k, n \\in \\Z\\).\n\\end{enumerate}\n\n\\newpage\n\\section{}\n\n\\subsection{}\n\n\\begin{equation}\n    H_4[k] = \\sum_{k = 0}^3 h[n] W_4^{kn} = 1 - W_4^k = 1 - (-j)^k = \\{0, 1 + j, 2, 1 - j\\}\n\\end{equation}\n\\begin{center}\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            xlabel=\\(k\\), ylabel={\\(|H_4[k]|\\)},\n            title={Magnitude of 4-point DFT},\n            axis lines=middle\n        ]\n        \\addplot[\n            ycomb,\n            color=blue,\n            mark=*\n        ]\n        coordinates {\n            (0, 0)\n            (1, 2^0.5)\n            (2, 2)\n            (3, 2^0.5)\n        };\n        \\end{axis}\n    \\end{tikzpicture}\n\\end{center}\nThe DFT is not even, not odd, is conjugate symmetric.\nThe DFT is a high-pass filter since it lets in \\(\\omega = \\pi\\), which is the highest frequency, and blocks out \\(\\omega = 0\\), the DC frequency.\n\n\\subsection{}\n\nIt is not possible to uniquely identify \\(x[n]\\) since the expression\n\\begin{equation}\n    X[k] = \\frac{Y[k]}{H[k]}\n\\end{equation}\ninvolves \\(H[0] = 0\\), so the expression is undefined at \\(k = 0\\), meaning that\n\\begin{equation}\n    X[k] =\n    \\begin{cases}\n        C & k \\equiv 0 \\pmod{4} \\\\\n        \\frac{Y[k]}{1 - (-j)^k} & k \\in [1, 3] \\pmod{4}\n    \\end{cases}\n\\end{equation}\nfor some \\(C \\in \\C\\).\n\n\\subsection{}\n\nUsing Parseval's theorem for the DFT,\n\\begin{align}\n    \\sum_{n = 0}^3 |x[n]|^2 &= \\frac{1}{4} \\sum_{k = 0}^3 |X[k]|^2 = D \\\\\n    &= \\frac{1}{4} \\left(|X[0]|^2 + |X[1]|^2 + |X[2]|^2 + |X[3]|^2\\right) \\\\\n    \\implies X[k] &=\n    \\begin{cases}\n        \\pm \\sqrt{4D - \\frac{1}{\\sqrt{2}} |Y[1]|^2 - \\frac{1}{2} |Y[2]|^2 - \\frac{1}{\\sqrt{2}} |Y[3]|^2} & k \\equiv 0 \\pmod{4} \\\\\n        \\frac{Y[k]}{1 - (-j)^k} & k \\in [1, 3] \\pmod{4}\n    \\end{cases}\n\\end{align}\n\n\\subsection{}\n\nUsing the frequency shift property of the DFT,\n\\begin{equation}\n    \\tilde{Y}[k] = X[k] \\tilde{H}[(k + 1)_N]\n\\end{equation}\nAssuming nothing else about \\(x[n]\\),\n\\begin{equation}\n    X[k] =\n    \\begin{cases}\n        \\frac{Y[k]}{1 - (-j)^{k + 1}} & k \\in [0, 2] \\pmod{4} \\\\\n        C & k \\equiv 3 \\pmod{4}\n    \\end{cases}\n\\end{equation}\nfor \\(C \\in \\C\\).\nAssuming the sum holds from the previous part,\n\\begin{equation}\n    X[k] =\n    \\begin{cases}\n        \\frac{Y[k]}{1 - (-j)^{k + 1}} & k \\in [0, 2] \\pmod{4} \\\\\n        \\pm \\sqrt{4D - \\frac{1}{\\sqrt{2}} |Y[0]|^2 - \\frac{1}{2} |Y[1]|^2 - \\frac{1}{\\sqrt{2}} |Y[2]|^2} & k \\equiv 3 \\pmod{4} \\\\\n    \\end{cases}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "462db2a521e40659de50857e42455bf2cd364689", "size": 8028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw04/hw04.tex", "max_stars_repo_name": "bdngo/ee-123", "max_stars_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hw04/hw04.tex", "max_issues_repo_name": "bdngo/ee-123", "max_issues_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw04/hw04.tex", "max_forks_repo_name": "bdngo/ee-123", "max_forks_repo_head_hexsha": "d10fe34fdb95f2d7785eeaec9c578991aca9054d", "max_forks_repo_licenses": ["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.68, "max_line_length": 258, "alphanum_fraction": 0.5159441953, "num_tokens": 3529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6146568516380954}}
{"text": "\\section{Error Analysis\\label{sec:error}}\nAs with other approximation-based quadrature methods, \\qbkix has two primary sources of error: the quadrature error $e_Q$ incurred as a result of evaluating potential at the check points and the extrapolation error $e_E$ due to evaluating the polynomial approximation of the potential at the target point, assuming $\\Pcoarse$ is admissible. Let\n%This is assumes that the approximation error of geometry and boundary data is less than $\\etrg$.\n\\begin{align}\ne_Q(\\vx) &=\\left|\\sum_{s=0}^p (u(c_s) - \\hat{u}(c_s,\\Pfine) )\\ell_s(t_\\vx)\\right|,\n  \\label{eq:err-quad}\\\\\ne_E(\\vx) &= \\left|u(\\vx) - \\sum_{s=0}^p u(c_s)\\ell_s(t_\\vx)\\right|,\n  \\label{eq:err-ext} \\\\\ne_\\lbl{hedgehog}(\\vx) &\\leq e_Q(\\vx) + e_E(\\vx),\n  \\label{eq:err-hedgehog} \\\\\n\\end{align}\nwhere $u(\\vx)$ and $\\hat{u}(\\vx, \\Pfine)$ are defined in \\cref{eq:double_layer,eq:double_layer_disc} and $\\ell_s(t)$ is the $s$-th Lagrange polynomial defined on the points $\\{0,1,\\hdots, p\\}$.\nWe define $t_\\vx$ such that $\\vx = -\\vn(\\vy)(R + t_\\vx r)$, so $t_\\vx = \\frac{\\|\\vx - \\vy\\| - R}{r}$. \nIn this section, we first prove that we achieve high-order accuracy with our singular/near-singular evaluation scheme in \\cref{sec:singular-eval} with respect to extrapolation order $p$ and quadrature order $q$.\n%We then derive a heuristic inspired by the approaches taken in \\cite{aT2, elliott2011estimates} to estimate the quadrature error at a point $\\vx$ in the domain.\n%Our error heuristic applies an estimate similar to \\cite{aT2} in the principal curvature directions, specialized for our algorithmic framework.\n%Using a low-order approximation of the surface closest to $\\vx$, we can accurately estimate the quadrature accuracy due to local surface curvature without performing Newton iterations, which become costly in \\threed.\nWe then detail the impact of surface approximation on overall solution accuracy.\n\n%In this section, we describe how to ensure that $\\err{Q}$ and $\\err{E}$ are $O(\\err{target})$. \n%In practice, we actually want $ \\err{hedgehog} \\leq \\err{target}$; we achieve this by following the discussions in \\cref{sec:algo,sec:extrap_error,sec:quad_error_heuristic} with $\\err{target}/2$ in place $\\err{target}$. \n%We will drop the factors of two for clarity of exposition.\n\n\\subsection{Quadrature error\\label{sec:quad_error}}\nWe briefly state a tensor-product variation of known Clenshaw-Curtis quadrature error results as applied to smooth functions in \\threed.  \nThis estimate is derived based on assumptions detailed in \\cref{app:proof_of_error_quad_high_order} that, in general, are difficult to verify in practice and may not hold for all functions we consider.\nFor this reason, we refer to it as a heuristic.\n\n\\begin{heuristic}\n    Let the boundary $\\Gammah$ be discretized by quadrature patches over the domains $[-h,h]$ and the boundary condition $f$ in \\cref{eq:pde} be at least $C^k$.\n  Apply the $q$-th order Clenshaw-Curtis quadrature rule to the double-layer potential $u(\\vx)$ given in \\cref{eq:double_layer_patches} and let $\\vx$ be in the interior of $\\Omega$. \n  Then for all sufficiently large $q$:\n\\begin{align}\n  e_\\lbl{Q}(\\vx) &%= \\sum_{i=1}^N R^2_n\\left[\\frac{\\partial G(\\vx,P_i(u,v))}{\\partial \\vn}\\phi(P_i(u,v)) J_{P_i}(u,v)\\right]\n  \\lesssim  \\frac{128h^{k+1}}{15\\pi k(2q + 1 - k)^{k}} \\tilde{V}, \\\\ \n  \\shortintertext{where}\n  \\tilde{V} &= \\max_{i=1,\\hdots,N} \\max_{\\alpha,\\beta\\leq k}\\left\\| \\frac{\\partial^{\\alpha+\\beta}}{\\partial u^\\alpha\\partial v^\\beta}\\left(\\frac{\\partial G(\\vx,\\vP_i(s,t))}{\\partial \\vn}\\phi(\\vP_i(s,t)) g_{\\vP_i}(s,t)\\right)\\right\\|_T,\n  \\label{eq:error_quad_gen_target}\n\\end{align}\n $g_\\vP$ is the determinant of the metric tensor of a patch $\\vP$ implicit in \\cref{eq:double_layer_patches}, $\\lesssim$ means \"approximately less than or equal to,\" and $\\|\\zeta\\|_T = \\|\\zeta^\\prime/\\sqrt{1-x^2}\\|_1$.\n  %\\begin{equation}\n  %e_Q \\leq \\frac{128N}{15\\pi(2q + 1 - k)^{k}} \\max_{i} \\tilde{V}_{k_i}\\left( \\frac{\\partial G(\\vx,P_i)}{\\partial \\vn(\\vy)}\\phi(P_i) J_{P_i}\\right)\n  %\\end{equation}\n  \\label{heuristic:error_quad_high_order}\n\\end{heuristic}\n\nThis heuristic captures the qualitative behavior of the error. \nWe present the derivation of \\Cref{heuristic:error_quad_high_order} in \\cref{app:proof_of_error_quad_high_order}.\n\\edit{}{The presence of the derivatives of $\\phi$ in \\cref{heuristic:error_quad_high_order} largely captures two troublesome cases for integral equations: (a) when the underlying singularities of $f$ are close to $\\Gamma$; and (b) when pieces of non-local are nearly touching.\nBoth of these cases, if not properly resolved with adaptive refinement, can induce singularities in the harmonic extension of $\\phi$ and cause \\qbkix to accumulate error.\nThese sources of error are handled by \\cref{criteria:2,criteria:3} in \\cref{sec:geom_criteria} and the algorithms to enforce them.\n}\n\nAs $\\vx \\to \\Gammah$, the value of $k$ required in \\Cref{heuristic:error_quad_high_order} grows rapidly due to growing higher order derivatives of the integrand. \nSuch large values of $q$ and $k$ imply that smooth quadrature rules are cost-prohibitive; this is the problem that singular/near-singular quadrature schemes like \\qbkix aim to address.\nThis means that \\cref{heuristic:error_quad_high_order} is insufficient for direct application to \\cref{eq:double_layer_patches}, as we know. \nMoreover, this estimate is too loose to determine whether \\qbkix or smooth quadrature is required to evaluate the potential.\nThe assumption in \\cref{sec:adaptive_upsampling} addresses this problem by providing a cheap, reasonably robust criterion for refinement that is motivated by existing analyses \\cite{aT2,barnett2014evaluation} instead of relying on \\Cref{heuristic:error_quad_high_order}.\n\n\n\\subsection{Extrapolation error\\label{sec:extrap_error}}\n%Before beginning a discussion of the extrapolation error of \\qbkix, it is important to keep in mind the well-known relationship between polynomial interpolation of order $p$ and a local expansion of order $p$.\n%For a fixed $p$ in exact arithmetic, letting the interpolation interval size tend to zero produces a Taylor expansion of order $p$ centered at the interval's origin.\nA reasonable critique of \\qbkix is its reliance on an equispaced polynomial interpolant to extrapolate values of $u$ to the target point.\nDespite using the first-kind barycentric interpolation formula \\cite{webb2012stability}, polynomial interpolation and extrapolation in equispaced points is well-known for an exponentially growing Lebesgue constant and poor stability properties as the number of points $p$ increases \\cite{trefethen1991two,platte2011impossibility}.\nRecently \\cite{DT} demonstrated stable extrapolation in equispaced $p+1$ points\nusing least-sqaures polynomials of degree $\\sqrt{p}$.\nHowever, these results are asymptotic in nature and don't tell the full story for small to moderate values of $p$, as in the \\qbkix context.\n\n\\begin{figure}[!htb]\n      \\centering\n      \\includegraphics[width=.45\\linewidth]{figs/extrapolation_error_schematic.pdf}\n  \\mcaption{fig:extrap-err-setup}{Diagram of extrapolation setup}{ The toy setup used to study the extrapolation error of a singular function. We choose a simple point singularity $\\mu(t) = \\frac{1}{\\|t - q\\|}$ where $q = (\\rho, 0, 0)$ (black star) with $\\rho =-.1$.\n  We choose samples at the points $t_i = (R+ir, 0,0)$ for $i=0,\\hdots, p$ (black dots) and extrapolate the values $\\mu(t_0),\\hdots, \\mu(t_p)$ to $t=0$ (green dot).\n    }\n\\end{figure}\n\nWe begin our discussion with a simple representative experiment in equispaced extrapolation.\n\\Cref{fig:extrap-err-setup} depicts a minimal extrapolation setup in \\threed of a simple singular function $\\mu(t) = 1/\\|t-q\\|$ along a line, with $q = (\\rho, 0, 0)$ and $\\rho = -.1$.\nWe extrapolate exact values of $\\mu$ from $p$ points, located at $t_i = (R + ir,0,0)$, to the origin.\nThis closely mimics the worse-case extrapolation error in \\oned of a function analytic in a Bernstein ellipse with a real axis intercept of $\\rho+R+ rp/2$.\nWe repeat this for a large range of values of $r$ and $R$ for various values of $p$. \nThe log of the relative error is plotted in \\Cref{fig:extrap-err-p6,fig:extrap-err-p8,fig:extrap-err-p10,fig:extrap-err-p12,fig:extrap-err-p14} as a function of the relative extrapolation interval size $rp/R$ and the scaled extrapolation distance $R/\\rho$.\n\nAs mentioned in \\cite[Section 3.4]{RBZ}, the adaptive refinement of $\\Pcoarse$ resolves the boundary data $f$, and therefore $u$ and $\\phi$, on the length scale $L$ of the patch.\nThis means we can reasonably assume that the distance of the nearest singularity is $O(L)$ from $\\Gammah$, i.e., $\\rho = \\lambda L$ for some $\\lambda$.\nIn the context of \\qbkix, we know that $R=bL(P)$ and $r=aL(P)$.\n\\Cref{fig:extrap-err-p6,fig:extrap-err-p8,fig:extrap-err-p10,fig:extrap-err-p12,fig:extrap-err-p14}\nare a study of extrapolation error as a function of $a/b$, $b/\\lambda$ and $p$.\n\n\n\\begin{figure}[!htb]\n  \\centering\n  \\hfill\n\n  %\\captionsetup[subfigure]{labelformat=empty}\n%  \\begin{subfigure}{.4\\textwidth}\n%      \\centering\n%      \\includegraphics[width=\\linewidth]{extrapolation_error_schematic.pdf}\n%    \\caption{\\label{fig:extrap-err-setup}}\n%  \\end{subfigure}%\n  \\begin{subfigure}{.33\\textwidth}\n      \\centering\n      \\includegraphics[width=\\linewidth]{figs/extrapolation_error_plot_p6.pdf}\n    \\caption{\\label{fig:extrap-err-p6}}\n  \\end{subfigure}\n  \\begin{subfigure}{.33\\textwidth}\n      \\centering\n      \\includegraphics[width=\\linewidth]{figs/extrapolation_error_plot_p8.pdf}\n    \\caption{\\label{fig:extrap-err-p8}}\n  \\end{subfigure}%\n    \\begin{subfigure}{.33\\textwidth}\n      \\centering\n      \\includegraphics[width=\\linewidth]{figs/extrapolation_error_plot_p10.pdf}\n    \\caption{\\label{fig:extrap-err-p10}}\n  \\end{subfigure}\n  \\begin{subfigure}{.33\\textwidth}\n      \\centering\n      \\includegraphics[width=\\linewidth]{figs/extrapolation_error_plot_p12.pdf}\n    \\caption{\\label{fig:extrap-err-p12}}\n  \\end{subfigure}%\n  \\begin{subfigure}{.33\\textwidth}\n      \\centering\n      \\includegraphics[width=\\linewidth]{figs/extrapolation_error_plot_p14.pdf}\n    \\caption{\\label{fig:extrap-err-p14}}\n  \\end{subfigure}%\n  \\mcaption{fig:extrap-experiment}{Empirical extrapolation error behavior}{We sweep over a range of $R$ and $r$ values to vary \\Cref{fig:extrap-err-setup} and plot the log of the relative error in\n    \\Cref{fig:extrap-err-p6,fig:extrap-err-p8,fig:extrap-err-p10,fig:extrap-err-p12,fig:extrap-err-p14}, for values $p=6,8,10,12,14$, in increasing order, from (a) to (e).\nIn these figures, the $x$-axis is the extrapolation distance $R$ normalized by $\\rho$ and the $y$-axis is the ratio $rp/R$.%: the total size of the approximation interval ($rp$) relative to the extrapolation distance $R$.\nThe top of the $y$-axis corresponds to $r=R$; $rp/R = 1$ corresponds to our choice of the parameter $a$.\nAssuming that $\\rho = O(L)$, $r/R = a/b$ and $R/\\rho = b/\\lambda$ for some constant $\\lambda$.\n}\n\\end{figure}\nThere are several important observations to make from these plots: \n\\begin{itemize}\n  \\item Extrapolation error decreases as $R/\\rho$ decreases, as expected.\n  \\item For a fixed value of $R/\\rho$, the extrapolation error \\textit{decreases} rapidly as $rp$ decreases, up to a certain value $r^*p$.\nThis is somewhat counterintuitive, since this means placing points closer together and extrapolating a further distance relative to $rp$.\nFor a fixed $p$ in exact arithmetic, letting the interpolation interval size tend to zero produces an order $p$ Taylor expansion of the solution $u$ centered at the interval's origin, which accounts for this phenomenon.\n\n%\\note[MJM]{Another interpretation of this result is from the perspective of Bernstein ellipses.\n%Since $u$ is $C^\\infty$ in a large neighborhood around the interval of interest, we can reason that the Bernstein parameter of the corresponding \\oned approximation problem is growing as we decrease $rp$, thus increasing the convergence rate with respect to $R/\\rho$.}\n\n  \\item Beyond $r^*p$, the extrapolation error \\textit{increases}.\n    The effects of finite precision eventually pollutes the convergence behavior described above. \n    Moreover, the spacing $r^*$ appears to be a function of $p$.\n    For $p=6$, $r$ can be reduced to $1/p$ without any numerical issues, but\n    by $p=14$, only $r>\\frac{1}{2}$ is a safe choice for extrapolation.\n\\end{itemize}\nWe do not aim to rigorously analyze these phenomena in this work. \nWe highlight them to provide empirical evidence that equispaced extrapolation is a reasonable, but not optimal, choice for our problem of singular/near-singular integration and to provide some intuition for our parameter choices.\n\nThe following simple result describes the behavior of the extrapolation error in \\cref{eq:err-ext}.\n\\begin{theorem}\n    Let $u(\\vc(t))$ be the solution to \\cref{eq:pde} given by \\cref{eq:double_layer}, restricted to the line $\\vc(t)$ in \\threed intersecting $\\vx$, let $\\vc(t)$ be given by \n  \\begin{equation}\n    \\vc(t) = \\vsx - (R + tr)\\vn(\\vsx),\n    \\label{eq:check_point_param}\n  \\end{equation}\n  where $\\vsx$ is the closest point on $\\Gammah$ to $\\vx$, $R=bL_{\\vsx}$, $r=aL_{\\vsx}$, $\\vn(\\vsx)$ is the outward surface normal at $\\vsx$, and let $|u^{(p)}(\\vc(t))|$ be bounded above by $C_p$ on the interval $[-R, R+pr]$.\n  Let $\\mathfrak{P}(t)$ be the $p$-th order polynomial interpolant of $u(\\vc(t))$ constructed from the check points $\\vc_0, \\hdots, \\vc_p$, where $\\vc_i = \\vc(i)$. Then the extrapolation error associated with \\qbkix behaves according to:\n\\begin{equation}\n  |u(\\vc(t_\\vx)) - \\mathfrak{P}(t_\\vx)| \\leq \\frac{C_p}{(p+1)!}|R + rp|^p = \\frac{C_p}{(p+1)!}|b+ap|^p\\cdot | L|^p,\n  \\label{eq:extrap_err_init}\n\\end{equation}\nwhere $t_\\vx = \\frac{\\|\\vx - \\vsx\\| - R}{r}$.\n\\label{thm:extrap_error}\n\\end{theorem}\n\n\\begin{proof}\n\n    We know that for a smooth function $f$ and points $x_0, \\hdots x_p$ in a \\oned interval $I_0$, for some $\\xi \\in I_0$, the following relation holds for all $x \\in I_0$:\n\\begin{equation}\n    f(x) - \\mathfrak{P}(x) = \\frac{f^{(p)}(\\xi)}{(p+1)!}\\prod_{i=0}^p(x-x_i).\n  \\label{eq:exterp_err_init}\n\\end{equation}\nLet $\\mathfrak{P}$ be the $p$th order polynomial interpolating the points $x_0,\\hdots x_p$.\nIn the \\qbkix setup, since $R+rp$ is the distance of the furthest check point to $\\vy$, we know that $x - x_i < R +rp$ for each $i$.\nSince $f(t) = u(\\vc(t))$ is harmonic, and therefore $C^\\infty$, in $\\Omega$, $|f^{(p)}(\\xi)|$ can be uniformly bounded on $I_0$ by some constant $C_p$,\nNoting that $R = bL$ and $r=aL$ yields our result.\n\\end{proof}\n\nFor fixed values of $a$ and $b$, as we let $L\\to 0$, the extrapolation error is bounded by $O(L^p)$.\nIn practice, however, this means that we can choose $a$ and $b$ to minimize the constant factor $|b+ap|^p$ in \\cref{thm:extrap_error}.\nSince $p>1$, $a$ must be chosen to balance out the contribution of $p$, yet our extrapolation study shows that we can't simply set $a=0$.  \nWe therefore choose $a \\leq 1/p$ for $p=6$ and 8, motivated by \\cref{fig:extrap-err-p6,fig:extrap-err-p8}.\nMoreover, since $b < 1$, we can choose $a \\leq b/p$, which allows $a$ and $b$ to decay at the same rate.\n%In exact arithmetic, $a$ controls how close the convergence order is to $p$.\n%By holding $b$ fixed and letting $a\\to 0$, we recover a $p$th order Taylor expansion of $u$ centered at $c_0$.\n%Convergence to an approximate Taylor series is critical to the success of \\qbkix and can be seen in \\cref{fig:extrap-experiment}:\n%we can improve extrapolation accuracy for a fixed value of $b$ by decreasing $a$, until numerical errors take over.\nThe advantage of choosing $a \\leq b/p$ is that $b$ is a single parameter that controls the accuracy of \\qbkix.\nSince we have fixed the quadrature order $q=20$ to satisfy the assumption in \\cref{sec:adaptive_upsampling}, a smaller value of $b$ will trigger more upsampling in \\cref{alg:adaptive_upsampling}, keeping quadrature error fixed while reducing extrapolation error.\n\nIt is important to keep in mind that \\cref{thm:extrap_error} only provides insight for moderate values of $p$; our conclusions are largely irrelevant for large $p$.\nWe use  $p = 6$ and $a = b/6$, leaving the construction of an optimal extrapolation extrapolation scheme to future work. \n\n\\subsection{Geometry approximation error\\label{sec:error_geom}}\nLet $\\theta$ be a \\edit{}{smooth} scalar function defined on the surface of $\\partial \\Omega$ with $|\\theta| \\leq 1$ and let $\\delta$ be a small real constant.\nSuppose the boundary of the domain $\\Omega$ is perturbed by $\\delta$ along the normal field of $\\partial\\Omega$, scaled by $\\theta$, to produce the perturbed domain $\\Omega_\\delta$ with boundary $\\partial \\Omega_\\delta$.\nMore concretely, for $\\vy \\in \\partial\\Omega$ and $\\vy_\\delta\\in \\partial \\Omega_\\delta$, $\\vy_\\delta= \\vy + \\delta\\theta\\vn(\\vy)$.\nWe can define the \\textit{Eulerian shape derivative} of $u$ with respect to $\\theta$, denoted $u_\\theta$, at a point $\\vx \\in \\Omega_\\delta \\cap \\Omega$ as the rate of change in $u$ at $\\vx$ as $\\delta \\rightarrow 0$.\nThis quantity is of interest to us because the solution to \\cite[Equation 2]{morse2020robust} on $\\Omega_\\delta \\cap \\Omega$ can be written as $u + \\delta u_\\theta$, where $u$ is the solution to \\cite[Equation 2]{morse2020robust} on $\\Omega$.\nMoreover, we can compute the shape derivative by solving a Laplace problem on the unperturbed domain \\cite{pironneau1982optimal}:\n\\begin{equation}\n\\Delta u_\\theta= 0\\;\\mbox{in $\\Omega$, } u_\\theta = -  \\theta \\frac{\\partial u}{\\partial n} \\mbox{on $\\partial\\Omega$.}\n\\label{eq:shape-deriv}\n\\end{equation}  \nwhere $u$ is the solution of the \\cite[Equation 2]{morse2020robust} on $\\Omega$.\nFor small $\\delta$, this means that the error in the solution introduced by a boundary perturbation along the field $\\theta$ can be estimated by  $\\delta \\sup_{\\Omega} \\| u_\\theta \\|$.\nAssuming the boundary is smooth and the gradient of the solution $u$ is bounded, then\n\\begin{equation}\n\\| u_\\theta \\| \\leq C_g \\sup_{\\partial\\Omega} \\left| \\theta  \\frac{\\partial u}{\\partial n} \\right| \\leq\nC_g \\sup_{\\partial\\Omega} \\left| \\frac{\\partial u}{\\partial n}\\right|\n\\label{eq:shape-deriv-bound}\n\\end{equation}\nfor some real constant $C_g$.\nThe right-hand side of \\cref{eq:shape-deriv-bound} yields a constant $C_g^\\prime$, such that if $\\err{g} <  \\zeta\\etrg/C_g^\\prime$ for some $\\zeta < 1$,  the change in the solution is less than $\\etrg$ for a sufficiently small $\\err{g}$.\n%\\note[DZ]{Need to find (again) a reference saying this, as this is not true for general boundaries}\nThe constant depends implicitly on the surface geometry: for example, if an area element of $\\partial\\Omega$ is close to a sharp, concave corner, then  $\\frac{\\partial u}{\\partial n}$ can be arbitrarily large. \n\n\n\\subsection{Limitations \\label{sec:limitations}}\nOur error discussion reveals several limitations of our method. \nThe first and most apparent shortcoming is that extrapolation instability fundamentally limits convergence order. \nHowever, for reasonable orders of convergence, up to 14, we have discussed an empirical scheme to choose parameters to maximize the available convergence behavior.\nMoreover, low-order surface geometries used in engineering applications will likely limit the convergence rate before it is limited by the extrapolation order, making this a non-issue in practical scenarios.\n\nAnother downside of the chosen extrapolation approach is lack of direct extension of \\linebreak \\qbkix to oscillatory problems like the Helmholtz equation.\nDue to the limitation on the values of $p$, we can't guarantee the ability to resolve high-frequency oscillations in the solution.\nA new extrapolation procedure is required to do so robustly without compromising efficiency.\n\nIn \\cite{wala20193d}, the authors demonstrate a relationship between the truncation error of a \\qbx expansion and the local curvature of $\\Gammah$. \nOur scheme also is susceptible to this form of error and we do not address nor analyze this in this work.\nThis is a subtle problem that requires a detailed analysis of the surface geometry with respect to the chosen extrapolation scheme.\n%We leave this to a future work that produces an optimal extrapolation approach in the boundary integral context.\nAnother  limitation is the lack of an accurate error estimate to serve as an upsampling criteria in place of the criteria in \\cref{sec:adaptive_upsampling}, such as \\cite{klinteberg2019accurate}. \nExtending \\cite{klinteberg2019accurate} to \\threed surfaces is non-trivial and whether the size of $\\Pfine$ would be reduced enough to outweigh the added cost of the additional Newton iterations required by their scheme remains to be seen.\n\nFinally, for certain accuracy targets and geometries, the algorithm above may lead to an impractically high number of patches in $\\Pcoarse$ and $\\Pfine$. \nGeometries with nearly-touching non-local regions, as shown in \\cref{fig:torii}, will see large amounts of refinement.\nIf the nearly-touching embeddings $\\gamma_r$ are close enough, i.e., less than $10^{-10}$ apart, there is little hope of an accurate solution with a fixed computational budget.\nWe allow the user to enforce a minimal patch size $L_\\lbl{min}$, limiting the time and memory consumption at the expense of not reaching the requested target accuracy. \n", "meta": {"hexsha": "6f241d1b66c656e43c206899de85480d81613957", "size": 21367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hedgehog/error.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/error.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/error.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": 87.5696721311, "max_line_length": 344, "alphanum_fraction": 0.7410492816, "num_tokens": 6146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6146568507487494}}
{"text": "\\chapter{Statistics - Basic}\n\n\\textit{In any chapter in this book, especially in this chapter, I will assume (1) you have really basic knowledge on statistics, e.g., what ``Gaussian'', ``probability'', ``standard normal distribution'', ``random variable'' means and/or (2) you know how to use Google so that you can find concepts which you don't know. The reasons we cannot touch much of the mathematical details are because what we have to deal with in this class is rather a practical usages of statistics in astronomy, and because I have not been a good math student.}\n\nLet's start with a question. \n\\begin{ex}\n  For the \\textbf{same star}, consider the following three scenarios:\n  \\begin{itemize}\n    \\item Case A: Researcher 1 says $ m_1 =  \\m{14.0} \\pm \\m{0.1} $; Researcher 2 says $ m_2 = \\m{15.0} \\pm \\m{1.0} $.\n    \\item Case B: Researcher 1 says $ m_1 =  \\m{14.0} \\pm \\m{0.1} $; Researcher 2 says $ m_2 = \\m{15.0} \\pm \\m{0.3} $.\n    \\item Case C: Researcher 1 says $ m_1 =  \\m{14.0} \\pm \\m{0.1} $; Researcher 2 says $ m_2 = \\m{15.0} \\pm \\m{0.1} $.\n  \\end{itemize}\n  For each of the three cases: Are the two studies coincide? If so, with how much confidence would you say so? Wait, but what does that ``$ \\pm $'' sign means in rigorous mathematical sense?\n\\end{ex}\n\nSome of the previous course takers answered that they coincide, because the ``3-sigma rule'' says, e.g., for case A, $ m_1 = \\m{14.0} \\pm \\m{0.3} $ \\& $ m_2 = \\m{15.0} \\pm \\m{3.0} $ overlaps with each other. Crudely speaking, this makes sense, but it is of course not the ``publication level'' reasoning.\n\nTo give you the answer: It is an ill-defined question. The answer can change based on many factors; to pick one, the number of observations each reasercher used for the determination of the magnitude. If we assume that number is 5 for both researchers, for example, we can give some meaningful answers: We \\textit{cannot reject} $ m_1 = m_2 $ for case A \\& B with 90 \\% confidence, and we \\textit{can reject} $ m_1 = m_2 $ for case C with 90 \\% confidence. Depending on the confidence level, the answer may also change. Note that the expression that \\textit{can/cannot reject} is very important! You should \\textbf{NOT} say you \\textit{accept $ m_1 = m_2 $}, never ever. Let me explain why throughout this chapter.\n\n\n\\section{The $ n $-$ \\sigma $} \\label{sec: n-sigma notation}\nMaybe you are familiar of the 1-$ \\sigma $, 2-$ \\sigma $, and 3-$ \\sigma $ words (cf. \\cref{fig:nsigmawiki}). For example, mean $ \\pm 1$-$ \\sigma $ contains $ 68.27\\cdots \\% $ of the total area of a normal distribution. Similarly 3-$ \\sigma $ conatains $ 99.73\\cdots \\% $ of it, so it is very unlikely to get a sample outside of the mean $ \\pm 3 $-$ \\sigma $. \n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=0.5\\linewidth]{figs/nsigma_wiki}\n  \\caption{A test sampling from Gaussian (normal) distribution (from Wikimedia).}\n  \\label{fig:nsigmawiki}\n\\end{figure}\n\nIn this sense, the ``$ n $-$ \\sigma $'' is defined as the $ x $-axis value which gives the integrated area of certain value. More precisely, we have to call this confidence interval (CI):\n\n\\begin{defn}[$ n $-$ \\sigma $ Confidence Interval; CI]\n  $ n $-$ \\sigma $ \\textbf{confidence interval} is defined as \\textit{an} interval which contains $ \\Phi(n) - \\Phi(-n) $ of the total area, usually centered at the mean or median, where $ \\Phi := (2\\pi)^{-1/2} \\int_{-\\infty}^{x} e^{t^2/2} dt $ is the cumulative distrubution function of standard normal distribution. \n\\end{defn}\n\nFollowing this definition, 1-$ \\sigma $ CI is the interval such that the integrated area is $ 0.6827\\cdots $ of the total area. Similarly, 2-$ \\sigma $ CI is that with $ 0.9545\\cdots $, 3-$ \\sigma $ CI is that with $ 0.9973\\cdots $, etc. The term CI is not necessarily limited to Gaussian (normal) distribution: You can apply it to any distribution, and give an interval such as $ 0.11 ^{+0.03}_{-0.01} $ as the 1-$ \\sigma $ CI, for instance.\n\nSometimes it is more convenient to call, e.g., 1-$ \\sigma $ CI as the $ 68.27\\cdots \\% $ CI. We also define the \\textit{significance level} $ \\alpha $ as 100\\% minus this percentage, i.e., the 1-$ \\sigma $ CI is of significance level $ \\alpha = 1 - 0.6827\\cdots = 0.3173\\cdots $:\n\\begin{equation}\n  \\text{1-}\\sigma \\text{ CI}\n  \\quad \\equiv \\quad \n  68.27\\cdots \\% \\text{ CI}\n  \\quad \\equiv \\quad \n  \\text{CI of significance level } 0.3173 \\cdots ~.\n\\end{equation}\nIn physical and astronomical sciences we often use the terminology of ``$ n $-$ \\sigma $ CI'', but in mathematics and other branches of sciences and engineering, the ``$ k $\\,\\% CI'' or the ``significance level $ \\alpha $'' are used dominantly. Among them, 90\\,\\%, 95\\,\\%, and 99\\,\\% CIs, i.e., CIs with significance level $ \\alpha = 0.10,\\, 0.05,$ and $ 0.01 $ are found frequently.\n\nBecause when we say ``$ n $-$ \\sigma $'', we are just omitting the term ``CI'' at the end of it, this is not $ n $ times the standard deviation ($ \\sigma $): What we mean by ``$ n $-$ \\sigma $'' is actually ``$ n $-$ \\sigma $ CI'' and is \\textit{not necessarily} $ n \\times \\sigma $. They are the same for, e.g., Gaussian distribution, because the $ n $-$ \\sigma $ terminology is \\textit{defined} using it. For Gaussian (normal) distribution, which is a distribution that appears very often in natural sciences, such as 2-$ \\sigma $ is nothing but 2 times the standard deviation ($ \\sigma $). For almost all of the distributions other than Gaussian, this is not the case.\n\n\n\n\\section{The Meaning of $ \\pm $ Sign}\nSimple answer: The $ \\pm $ sign means the 1-$ \\sigma $ confidence interval (CI). It is also called the ``\\textbf{error-bar}''. \n\nMathematically speaking, the $ \\pm $ sign, i.e., the 1-$ \\sigma $ CI, does \\textit{not} fully describe the uncertainty. The best way to show or describe the uncertainty is to show a graph of \\textbf{probability distribution function} (\\textbf{pdf} or p.d.f.) as in \\cref{fig:figposterior01}. In many publications or books, people do not show this, because (1) the distribution is very similar to Gaussian or a widely known distribution and it is clearly written in the text or assumed as all the readers know that, (2) detailed calculation is not of interest and/or does not affect the final result, (3) the writer is lazy. \n\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[width=1\\linewidth]{figs/fig_posterior01}\n\\caption{The probability distribution function (pdf) of two examples of distributions, namely, Gaussian and an asymmetric distributions. I used a chi-square distribution for the latter for plotting purpose.}\n\\label{fig:figposterior01}\n\\end{figure}\n\n\nThe uncertainty ranges shown in \\cref{fig:figposterior01} ($ 4.0 \\pm 0.1 $ and $ 3.0^{+3.0}_{-2.0} $) are determined such that the lower/upper bounds include $ 68.27 \\cdots \\% $ of the total area. It is trivial for a Gaussian distribution: mean $ \\pm $ 1-$ \\sigma $. But if the distribution is asymmetric (right panel of the figure), there are few choices to set such bounds. First and the most widely used one is to set the bounds such that the distance between upper/lower bounds are minimized (but include $ 68.27 \\cdots \\% $ of the total area). Second is to make it symmetric while include $ 68.27 \\cdots \\% $ of the total area, so that you can use $ \\pm $ sign for simplicity ($ 3.0 \\pm 2.3 $ for example). Third choice would be something like FWHM: find $ x $-axis values such that the pdf value is $ 0.5 \\times \\mathrm{pdf_{max}} $. The last two bounds are simple to calculate but not as accurate as the first choice.\n\nVery assymetric probability distributions appear, e.g., in cosmological sciences\\footnote{Google ``posterior distribution cosmological constants''.}, and exhaustive statiscal analyses are conducted on such models to \\textit{reject} (I repeat; \\textit{reject, not accept}) cosmological models. The reason is that, in cosmology, we have only one single sample (our universe), and the statistical analyses given the observational data is of utmost importance. Of course similar exhaustive statistical analyses should be conducted on any research field if the data/object/target is of such importance. We don't do that in many observational studies purely because (1) we don't have human power to do all that and (2) the results won't change much (but no one in history thoroughly checked this).\n\n\n\n\\section{Caveat on the ``$ n $-$ \\sigma $ CI'' Notation}\nLet me emphasize again: What we mean by ``$ n $-$ \\sigma $'' is actually ``$ n $-$ \\sigma $ CI'' and is \\textit{not necessarily} $ n \\times \\sigma $. \n\nIt maybe is tempting to convert the 1-$ \\sigma $ CI to the 3-$ \\sigma $ CI. For instance, from \\cref{fig:figposterior01}, $ 4.0 \\pm 0.1 $ and $ 3.0^{+3.0}_{-2.0} $ to $ 4.0 \\pm 0.3 $ and $ 3.0^{+9.0}_{-6.0} $. This is true for the former (Gaussian) but wrong for the latter (non-Gaussian). The lower bound of the second parameter now become negative ($ 3.0 - 6.0 = -3.0 $), which is not even physically correct if this parameter is defined to be positive. What you have to do is, get the 3-$ \\sigma $ CI which should contain $ 0.9973\\cdots $ of the total area from the distribution given in \\cref{fig:figposterior01}. There can be at least three choices to do it, which I mentioned in the previous section.\n\n\n\\section{Central Limit Theorem (CLT)}\nThe Central Limit Theorem (CLT) is at the heart of all the observational or experimental sciences. It is stated as\\footnote{For strict definitions of random sample, population, independence, the statement of CLT in mathematical senses, etc, I recommend mathematical statistics textbooks.}\n\n\\begin{thm}[Central Limit Theorem; CLT] \\label{thm: clt}\n  Consider a random sample (observation, measurement, etc) with size $ n $ and the mean value of this sample is $ \\bar{X} $. Then $ (\\bar{X} - \\mu) / (\\sigma / \\sqrt{n}) $ approaches the standard normal distribution ($ \\mathcal{Z} $) as $ n \\rightarrow \\infty $, where $ \\mu $ and $ \\sigma^2 $ are the (finite) mean and variance of the population:\n  \\begin{equation}\n    \\frac{\\bar{X} - \\mu}{\\sigma / \\sqrt{n}} \\sim \\mathcal{Z}  \\quad (\\mathrm{as~} n \\rightarrow \\infty)~.\n  \\end{equation}\n\\end{thm}\n\nThe standard deviation (second moment) is sometimes undefined. An example is the Cauchy distribution, and I will show you later with an example when this distribution can appear. There is one more important theorem, which we usually skip to mention:\n\n\\begin{thm}[Sample Variance Distribution] \\label{thm: s and sigma}\n  Consider a random sample (observation, measurement, etc) with size $ n $ and the sample variance is $ S^2 $. Then $ (n - 1) S^2 / \\sigma^2 $ follows a chi-squared distribution with degrees of freedom $ (n - 1) $, where $ \\sigma^2 $ is the variance of the population:\n  \\begin{equation}\n    \\frac{(n - 1) S^2}{\\sigma^2 } \\sim \\chi^2_{(n-1)}\n  \\end{equation}\n\\end{thm}\n\nAlso the definition of the Student $ t $-distribution\\footnote{This definition is directly copied from Walpole et al. p.177}:\n\n\\begin{defn}[Student $ t $-distribution]\\label{def: t-distn}\n  Let $ Z $ be a standard normal random variable and $ V $ a chi-squared random variable with $ v $ degrees of freedom. If $ Z $ and $ V $ are independent, then the distribution of the random variable $ T $, where\n  \\begin{equation}\n    T = \\frac{Z}{\\sqrt{V /v}}\n  \\end{equation}\n  is given by the density function\n  \\begin{equation}\n    h(t) = \\frac{\\Gamma \\qty[ \\frac{v+1}{2} ]}{\\Gamma \\qty[\\frac{v}{2}] \\sqrt{\\pi v}}\n      \\qty( 1 + \\frac{t^2}{v} )^{-\\frac{(v+1)}{2}}\n    \\quad ~, \\quad\n    -\\infty < t < \\infty ~.\n  \\end{equation}\n  This is known as the Student $ t $-distribution with $ v $ degrees of freedom.\n\\end{defn}\n\nWe can see that the $ t $-distribution approaches the standard normal distribution as the degrees of freedom $ v \\rightarrow \\infty $, because the power term takes the $ e^{-t^2 / 2} $ form. \n\n\n\\begin{thm}[Practical Usage of the CLT] \\label{thm: practical clt}\n  Consider a random sample (observation, measurement, etc) with size $ n $ large enough and the mean value of this sample is $ \\bar{X} $. If $ \\mu $, $ \\sigma^2 $, and $ S^2 $ are the (finite) mean and variance of the population, and the sample variance, respectively:\n  \\begin{equation}\n    \\frac{\\bar{X} - \\mu}{S / \\sqrt{{n}}} \\sim T_{(n - 1)} ~.\n  \\end{equation}\n\\end{thm}\n\nSometimes people empirically say $ n \\ge 30 $ is enough. This really depends on the situation and I will skip this issue here. The sketch of the proof of the theorem is simple. By the definition of the $ t $-distribution and Thm \\ref{thm: s and sigma}, \n\\begin{equation}\n  T = \\frac{Z}{\\sqrt{V /v}} = \\frac{ \\frac{\\bar{X} - \\mu}{\\sigma / \\sqrt{n}} }\n  {\\sqrt{ \\frac{(n - 1) S^2}{\\sigma^2 } / (n-1)}}\n  = \\frac{\\bar{X} - \\mu}{S / \\sqrt{{n}}}\n\\end{equation}\nso the theorem is plausible. For your information, the sample variance is defined as\n\\begin{equation}\n  S^2 := \\frac{1}{n - 1} \\sum_{i=1}^{n} (X - \\bar{X})^2 \n\\end{equation}\nand the sample standard deviation $ S $ is the square root of this.\n\nNote here the difference between Thm \\ref{thm: clt} and Thm \\ref{thm: practical clt}: $ \\sigma $ is changed to $ S $, and the standard normal distribution is changed to the $ t $-distribution of $ (n - 1) $ degrees of freedom. Since the true variance $ \\sigma^2 $ is unknown, it is difficult to use the CLT (Thm \\ref{thm: clt}) directly. But thanks to Thm \\ref{thm: s and sigma}, we can use the variance of the sample, $ S^2 $, which is measurable, and utilize the $ t $-distribution, which is slightly bothersome than the standard normal distribution but still useful. \n\nAlso be aware that CLT says the \\textit{expectation value of the mean} is normally distributed, not the \\textit{sample} is so.\n\n\\begin{ex}[Coin Tossing and the CLT]\n  Consider a coin-tossing experiment and assign $ \\pm 1 $ to heads and tails. Each experiment will give you $ \\pm 1 $, but never $ 0 $. Meanwhile, we know a fair coin should have $ \\mu = 0 $ (same probability of heads and tails). After $ n = 100 $ experiments, say you obtained $ \\bar{X} = 0.01 $ and $ S = 0.1 $, so\n  \\begin{equation*}\n    T = \\frac{\\bar{X} - \\mu}{S / \\sqrt{{n}}}\n      = \\frac{0.01 - \\mu}{0.1 / \\sqrt{100}} \n      = 1 - 100 \\mu ~.\n  \\end{equation*}\n  Since $ T \\sim t_{99} $, the significance level $ \\alpha = 0.05 $ confidence interval, i.e., the confidence interval containing $ 100 (1 - \\alpha) \\% = 95 \\% $, can be\n  \\begin{equation*}\n    t_{99, 0.025} < T < t_{99, 0.975}\n    \\quad \\rightarrow \\quad\n      - 1.9842 < 1 - 100 \\mu < 1.9842\n    \\quad \\rightarrow \\quad\n      \\mu \\in [-0.0098,\\, 0.0298] ~.\n  \\end{equation*}\n  The notation $ t_{\\nu, x} $ means the input argument of the $ t $-distribution with the degrees of freedom $ \\nu $ such that $ \\int_{-\\infty}^{t_{99, x}} h(t) dt = x $. Thus, to get the two-tail CI of significance level $ \\alpha $, we need to calculate $ t_{\\nu, \\alpha / 2} $ and $ t_{\\nu, 1 - \\alpha / 2} $. For a symmetric distribution like $ t $ here, $ t_{\\nu, 1 - \\alpha / 2} = - t_{\\nu, \\alpha / 2} $. This is very widely used standard notation.\n  \n  If you just calculated without pondering about the meaning of the caculation, you may be surprised that your next experiment gives either $ +1 $ or $ -1 $, while the expectation is $ \\mu \\in [-0.0098, 0.0298] $. This is because the result from CLT is, as described, about the \\textit{mean} of the samples, not the \\textit{single sample}. Thus, the error-bar from the CLT is not necessarily predicting the possible range of \\textit{future experiments}, but it just confines the \\textit{position of the mean}.\n\\end{ex}\nThe range which predicts the future experiments is called the prediction interval. You may learn the prediction interval (PI) to clarify this difference.\n\nThe two-tail significance level $ \\alpha $ interval of the $ t $-distribution calculable in python by\n\\begin{python}\nfrom scipy.stats import t\nalpha = 0.95\nnu = 99\n\n# Note that the alpha below is NOT the significance level, \n# but the area under the curve!\nlo, hi = t.interval(alpha=alpha, df=nu)\nprint(f\"Confidence Interval: [{lo:.4f}, {hi:.4f}]\")\n\\end{python}\n\n\n\\subsubsection*{Note: Uncertainty of Median}\nThe 1-$ \\sigma $ error-bar of the median is more difficult to handle than that of the mean (CLT: Thm \\ref{thm: clt}). But we can get a result from simplifying assumptions, which are not necessarily true for real observations:\n\n\\begin{thm}[Uncertainty of Median]\n  Consider $ n (\\gg 1) $ samples are independently drawn from $ X \\sim \\mathcal{G}(\\mu, \\sigma^2) $, a general continuous distribution with finite mean and variance $ \\mu $ and $ \\sigma^2 $ with pdf $ p(x) $. The uncertainty of the median estimator is \n  \\begin{equation}\\label{eq: err median general}\n    \\Delta \\mathrm{med} \\approx \\frac{1}{2 p(\\nu_0) \\sqrt{n - 1}}\n  \\end{equation}\n  and if $ \\mathcal{G} =  \\mathcal{N} $, i.e., a normal distribution,\n  \\begin{equation}\\label{eq: err median}\n    \\Delta \\mathrm{med} \n      \\approx \\sqrt{\\frac{\\pi / 2}{n - 1}} s \n      = \\sqrt{\\frac{\\pi}{2} \\frac{n}{n - 1}} \\Delta \\mathrm{mean}\n      \\approx 1.25 \\Delta \\mathrm{mean}\n       ~,\n  \\end{equation}\n  where $ s $ is the sample standard deviation and $ \\Delta \\mathrm{mean} = s / \\sqrt{n} $ is the error-bar of the mean from Thm \\ref{thm: practical clt}.\n\\end{thm}\n\\begin{proof}[of general distribution]\nTo prove it, say the true median is $ \\nu_0 $ and samples $ \\{ x_1, \\cdots, x_n \\} $ are sorted as increasing order. For an integer $ m $, set $ n = 2m + 1 $, because $ n \\gg 1 $. The sample median is then $ \\nu = x_{m + 1} $.\nThe probability of having sample median $ \\nu $ is calculable by noting that we have to sample $ m $ of sample with $ x_i \\le \\nu $ and the other $ m $ with $ x_i > \\nu $:\n\\begin{equation*}\n  f(\\nu) = \\frac{n!}{m! m!} q^m (1 - q)^{m} ~,\n\\end{equation*}\nwhere $ q = q(\\nu) = \\mathbb{P} \\{ X_i \\le \\nu \\} = \\int_{-\\infty}^{\\nu} p(x) dx $. $ p(x) $ is the pdf of the normal distribution. \n\nThe Taylor expansionof $ q $ at $ \\nu = \\nu_0 $:\n\\begin{equation*}\n\\begin{aligned}\n  q(\\nu) &= q(\\nu_0) + \\frac{1}{1!} q'(\\nu_0) (\\nu - \\nu_0) + O\\qty( (\\nu - \\nu_0)^2 )\\\\\n    &\\approx \\frac{1}{2} + q'(\\nu_0) (\\nu - \\nu_0) \\\\\n    &\\equiv \\frac{1}{2} + p(\\nu_0) (\\nu - \\nu_0) ~.\n\\end{aligned}\n\\end{equation*}\nThen \n\\begin{equation*}\n\\begin{aligned}\n  f(\\nu) &\\approx \\frac{n!}{m! m!}\n    \\qty[ \\frac{1}{2} + p(\\nu_0) (\\nu - \\nu_0) ]^m\n    \\qty[ \\frac{1}{2} - p(\\nu_0) (\\nu - \\nu_0) ]^m \\\\\n    &= \n    \\frac{n!}{m! m!}\n    \\qty[ \\frac{1}{4} \\qty( 1 - 4 p(\\nu_0)^2 (\\nu - \\nu_0 )^2) ]^m \\\\\n    &= \n    \\frac{n!}{m! m! 4^m}\n    \\qty[ 1 - \\frac{4 m p(\\nu_0)^2 (\\nu - \\nu_0 )^2}{m} ]^m \\\\\n    &\\approx \n    \\frac{n!}{m! m! 4^m}\n    e^{ -4 m p(\\nu_0)^2 (\\nu - \\nu_0 )^2 } ~.\n\\end{aligned}\n\\end{equation*}\nThis has the form of Gaussian distribution ($ \\propto e^{-(x - \\mu)^2 / 2\\sigma^2} $) with mean $ \\nu_0 $ and variance $ \\frac{1}{4 (n-1) p(\\nu_0)^2} $ since $ m = (n - 1) / 2 $. Thus, \n\\begin{equation}\n  \\nu \\sim \\mathcal{N} \\qty( \\nu_0, \\frac{1}{4 (n-1) p(\\nu_0)^2} )\n  \\quad\\rightarrow \\quad\n  \\Delta \\mathrm{med} \\approx \\frac{1}{2 p(\\nu_0) \\sqrt{n - 1}} ~.\n\\end{equation}\nQ.E.D.\n\\end{proof}\n\n\\begin{proof}[of Gaussian distribution]\nNow if $ p(x) $ is a Gaussian, median is equal to mean, so the pdf becomes $ p(\\nu_0) = p(\\mu) = \\frac{1}{\\sqrt{2\\pi} \\sigma} $, and\n\\begin{equation*}\n  \\nu \\sim \\mathcal{N} \\qty( \\nu_0, \\frac{\\pi / 2}{n - 1} \\sigma^2 ) ~.\n\\end{equation*}\nIf we denote $ A = \\sqrt{(n - 1) / (\\pi / 2)} $, the statistic $ Z = A \\frac{\\nu - \\nu_0}{\\sigma} $ will follow the standard normal distribution. On the other hand, $ V = \\frac{(n - 1) s^2}{\\sigma^2} $ follows the chi-squared distribution of degrees of freedom $ (n - 1) $ by Thm \\ref{thm: s and sigma}. Then \n\\begin{equation*}\n  T = \\frac{Z}{\\sqrt{V / (n - 1)}}\n    = A \\frac{\\nu - \\nu_0}{s}\n\\end{equation*}\nwill follow a $ t $-distribution with degrees of freedom $ (n - 1) $ by Def \\ref{def: t-distn}. $ T $ is nearly a Gaussian when $ n $ is large (rule-of-thumb: when $ n \\gtrsim 30 $), so \n\\begin{equation}\n  \\nu \\mathrel{\\dot{\\sim}} \\mathcal{N} \\qty( \\nu_0, \\frac{\\pi / 2}{n - 1} s^2 )\n  \\quad\\rightarrow \\quad\n  \\Delta \\mathrm{med} \\approx \\sqrt{\\frac{\\pi / 2}{n - 1}} s  ~.\n\\end{equation}\nQ.E.D.\n\\end{proof}\n\n\n\n\\section{Meaning of the Confidence Interval}\nI circunvented the definition of the CI so far. It is defined as\n\n\\begin{defn}[Confidence Interval; CI] \n  A confidence interval of significance level $ \\alpha $ of a parameter $ X $ is the interval of $ X $ value such that if we conduct the identical parameter estimation process in many \\textit{parallel universes} (i.e., ensemble) which have the identical true value $ X_\\mathrm{true} $, fraction of $ (1 - \\alpha) $ of such universes could have calculated a CI such that the $ X_\\mathrm{true} $ is included in that CI.\n\\end{defn}\n\nThis is not a practically meaningful definition, but philosophically important. Let me give an example to elaborate the meaning of this.\n\n\\begin{ex}[Meaning of the Confidence Interval]\n  Imagine there are many \\textit{parallel universes} and the same observer observes the same star in each universe. Because of random errors (which we will learn later but that includes Poisson photon noise, readout noise, etc), the observer at each universe will obtain slightly different observational results. The observers will observe the star for $ n $ times, and calculate their own mean and error-bar as $ \\bar{X} $ and $ S / \\sqrt{n} $ from their observations. Note again that  $ S / \\sqrt{n} $ is the uncertainty of the \\textit{mean} value.\n\n  For visualization, the true magnitude of the star is $ \\mu = \\m{14.0} $ and true standard deviation of the observation $ \\sigma = \\m{0.2} $ with $ n = 9 $ are used for the generation of \\cref{fig:figclt01}. The universe ID 0 of both the upper and lower panels show roughly $ m = \\m{14.0} \\pm \\m{0.1} $. That is, when the true magnitude and true standard deviation are given as $ \\m{14.0} $ and $ \\m{0.2} $, an observer at one of the universes (in our case universe ID 0) got $ m = \\m{14.0} \\pm \\m{0.1} $, and that is our universe. \n\\end{ex}\n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[width=1\\linewidth]{figs/fig_clt01}\n  \\caption{Simulation to show the concept of CI and CLT. Black crosses are the observation in each universe, and the circles are the mean and its uncertainty from the CLT $ S / \\sqrt{n} $. Red circles are the univserses where the confidence interval contains the true mean $ \\mu = \\m{14.0} $ and blue circles are the others. In the title, the fraction of the universes which contains the true mean within their own confidence intervals out of \\texttt{n\\_univ} simulated universes is shown. This fraction approaches $ 0.6827\\cdots $ as the number of universe gets infinity.}\n  \\label{fig:figclt01}\n\\end{figure}\n\nI will close this section with an excerpt from Walpole p.234:\n\n\\textit{The interpretation of a CI is often misunderstood. It is tempting to conclude that the parameter falls inside the CI with probability of(, e.g.,) 0.95. (But this is not ture.) A CI merely suggests that if the experiment is conducted and data are observed again and again, about 95\\% of such intervals will contain the true parameter.}\n\n\n\n\\section{Answer to the Question}\nIn statistics, the \\textit{null hypothesis}, denoted $ H_0 $, is the one that is the simplest, and that has value if it is \\textit{rejected} (not \\textit{accepted}). The \\textit{alternative hypothesis}, $ H_1 $, is another possibility if $ H_0 $ is not true. In the simplest case, $ H_1 $ is the complementary of $ H_0 $. For example, $ H_0: \\mu = 0 $ and $ H_1: \\mu \\neq 0 $. \n\nLet's consider the opening question: $ m = \\m{14.0} \\pm \\m{0.1} $. Now you understand that $ \\m{14.0} $ means that the mean value\\footnote{It can actually be the median value, most probable value, or whatever the representative value.} from the observation, and $ \\pm \\m{0.1} $ means the uncertainty or the error-bar of the Gaussian probability distribution of that mean value, $ S / \\sqrt{n} $. If it were not Gaussian, the author should have given more information. Note that the sample standard deviation is $ \\sqrt{n} $ times the error-bar.\n\nTo answer the question, we set the hypotheses\\footnote{There are some ``standard'' ways to set the hypotheses, and it may seem very sudden if you are not familiar with these. Please refer to basic applied statistics textbooks for more examples, e.g., p.246 and p.264 of Walpole et al.}:\n\\begin{equation}\n  H_0 : m_1 = m_2 \n  \\sep\n  H_1 : m_1 \\neq m_2 ~,\n\\end{equation}\nwhere $ m_1 = \\m{14.0} \\pm \\m{0.1} $ and $ m_2 $ is the other (from researcher 2). $ m_1 $ and $ m_2 $ here means the ``true'' magnitude of the star, not the measured value! If it were the measured value, they are just different, since one is 14.0 and the other is 15.0. The two true means may be different because (1) researchers may have mistakenly observed different star, (2) the star is maybe a variable (including binary), (3) explanet occulted some part of the star, or any other scenario is possible.\n\nNow we have to choose which formula to use. When two measurements with $ \\bar{x}_1 \\pm s_1 $ and $ \\bar{x}_2 \\pm s_2 $ from the number of observations $ n_1 $ and $ n_2 $ are given, and $ \\mu_1 $ and $ \\mu_2 $ are the true means of two sampling distributions that will be tested under the hypothesis testing, there are two different formulae:\n\\begin{itemize}\n\\item The true variances are unknown and different (Satterthwhite approximation\\footnote{SatterthwhiteFE (1946, Biometrics Bulletin, 2, 110), ``An Approximate Distribution of Estimates of Variance Components.''}):\n\\begin{equation}\n  t = \\frac{(\\bar{x}_1 - \\bar{x}_2) - (\\mu_1 - \\mu_2) }{\\sqrt{s_1^2 / n_1 + s_2^2 / n_2}}\n\\end{equation}\nfollows the $ t $-distribution with degrees of freedom\n\\begin{equation}\n  \\nu \\approx \n    \\frac{\\qty( s_1^2 / n_1 + s_2^2 / n_2 )^2}\n    {\\frac{ \\qty(s_1^2 / n_1)^2 }{n_1 - 1}\n      + \\frac{ \\qty(s_2^2 / n_2)^2 }{n_2 - 1}} ~.\n\\end{equation}\n\\item The true variances are unknown but the same:\n\\begin{equation}\n  t = \\frac{(\\bar{x}_1 - \\bar{x}_2) - (\\mu_1 - \\mu_2) }{s_p \\sqrt{1 / n_1 + 1 / n_2}}\n\\end{equation}\nfollows the $ t $-distribution with degrees of freedom $ \\nu = n_1 + n_2 - 2 $ and\n\\begin{equation}\n  s_p = \\frac{(n_1 - 1) s_1^2 + (n_2 - 1) s_2^2}{\\nu} ~.\n\\end{equation}\n\\end{itemize}\nWhich one will you choose? To answer our original question, it is more reasonable to assume the true variances are not necessarily identical, because they may have used different instruments at different sky conditions. So I will use the first choice.\n\nTo apply the formula, you need the number of observations from each researcher, i.e., the $ n_1 $ and $ n_2 $ values. As I mentioned, it is an ill-defined question since this numbers are not given. So let me assume $ n_1 = n_2 = n = 5 $. The question can be reformulated as $ \\bar{x}_1 = 14.0 $, $ \\bar{x}_2 = 15.0 $, $ s_1 = 0.1 \\sqrt{n} $, and $ s_2 = 1.0\\sqrt{n},\\, 0.3\\sqrt{n}, \\, 0.1\\sqrt{n} $, where I dropped the magnitude sign for brevity. Under the null hypothesis ($ H_0: \\mu_1 = \\mu_2 $), $ \\mu_1 - \\mu_2 = 0 $. For the three $ s_2 $ values, \n\\begin{equation}\n\\begin{aligned}\n  t &= \\frac{(14.0 - 15.0) - 0}{\\sqrt{(s_1^2 + s_2^2) / n}}\n  \\quad &&\\rightarrow \\quad\n  t &&= & -0.995 ,\\, && -3.162 ,\\, && -7.07 \\\\\n  \\nu &= (s_1^2 + s_2^2) (n-1)\n  \\quad &&\\rightarrow \\quad\n  \\nu &&= & 4.08, \\, && 4.32, \\, && 8.0 \\\\\n  &&&&&\\approx & 4 ,\\, && 4 ,\\, && 8 \\\\\n\\end{aligned}\n\\end{equation}\nThe values are in the order for $ s_2 = (1.0,\\, 0.3, \\, 0.1)\\sqrt{n} $ cases. The (two-tail) significance level $ \\alpha $ test is listed in \\cref{tab: CI}.\n\n\\begin{table}[ht!]\n\\centering\n\\caption{The confidence interval calculation for the example question.}\n\\label{tab: CI}\n\\begin{tabular}{c|c||c|c}\nCI \\% & significance level $ \\alpha $ and $ \\frac{\\alpha}{2} $& $ \\nu = 4 $ case & $ \\nu = 8 $ case \\\\\n\\hline\n90 \\% & 0.10 \\& 0.05   & $ [-2.1318, 2.1318] $ & $ [-1.8595, 1.8595] $ \\\\\n95 \\% & 0.05 \\& 0.025  & $ [-2.7764, 2.7764] $ & $ [-2.3060, 2.3060] $ \\\\\n99 \\% & 0.01 \\& 0.005  & $ [-4.6041, 4.6041] $ & $ [-3.3554, 3.3554] $ \\\\\n\\end{tabular}\n\\end{table}\n\nThe answers to the questions are, assuming $ n_1 = n_2 = 5 $,\n\\begin{itemize}\n\\item Case A ($ t = -0.995 $ with $ \\nu = 4 $): The $ t $ value is inside of all three CIs. Thus, we cannot reject $ H_0 $ under 90 \\%, 95 \\%, and 99 \\% CI criterion (cannot reject under the significance level $ \\alpha = 0.10,\\, 0.05,\\, 0.01 $).\n\\item Case B ($ t = -3.162 $ with $ \\nu = 4 $): The $ t $ value is inside of 90 \\% and 95 \\% CI but outside of the 99 \\% CI. Thus, we reject $ H_0 $ with $ \\alpha = 0.10 $ and $ 0.05 $, but cannot reject it with $ \\alpha = 0.01 $.\n\\item Case C ($ t = -7.07 $ with $ \\nu = 8 $): We reject $ H_0 $ with all the three $ \\alpha = 0.10,\\, 0.05,\\, 0.01 $.\n\\end{itemize}\n\\vspace{\\parskip}\n\nBy \\textit{rejecting the null hypothesis}, $ H_0: m_1 = m_2 $, we mean that it is unlikely that the true magnitude value of the two studies are identical. By \\textit{failing in rejecting the null hypothesis}, we mean that it is impossible to conclude whether $ m_1 $ and $ m_2 $ are the same under the given significance level. \n\nThe results are as expected: For Case A, the error-bar of $ m_2 $ is too large, which means it is almost impossible to reject the claim that $ m_1 = m_2 $, so the we always fail to reject the null hypothesis. For Case C, the error-bars are too small and thus $ m_1 $ is of course vastly different from $ m_2 $, so the null hypothesis is always rejected.\n\n%\\footnote{You may wonder what if we have $ n = 1 $. The $ \\nu $ is undetermined and all the calculation seem to meaningless, but of course we can have error-bars for each single observation. That is not considered in this example since here we are simply assuming the mean is inferred from $ n $ observations under the CLT, and we need $ n > 1 $ to calculate the sample variance $ S^2 $. I will not consider the error-bars of each observations. Such a detailed statistical analyses should follow some well-developed and specific statistical routines available in your research field.}.\n%In this example we do not care about the error-bar of each observation but the final error-bar of the mean value from researchers. If we want to consider the error-bars of every observations, this kind of classical statistical method gets very complicated and almost impossible to give meaningful results. You then need Bayesian approach and Monte Carlo simulation technique.\n\n\n\n\n\\section{Probability Distributions and Poisson Noise}\nThere are a myriad of probability distributions (PDs) in math, due to hard works of mathematicians lived in the era of frequentist statistics. In this section, I will just give some definitions and properties of few of them, which are frequently visited by astronomical literatures.\n\n\\subsection{Binomial Distribution}\nFirst, let me define Bernoulli process:\n\\begin{defn}[Bernoulli Process]\nA Bernoulli process is a process (experiments) which has the following properties (Walpole p.102):\\newpage\n\\begin{enumerate}\n  \\item Repeated trials where each trial (outcome) is classified as either a success (1) or failure (0).\n  \\item The success probability ($ p $) should remain constant throughout the process.\n  \\item Each trial (outcome) must be independent to each other.\n\\end{enumerate}\n\\end{defn}\n\nA coin-tossing experiment can be a Bernoulli process: The probability of success (heads; H) $ p = 0.5 $ and failure (tails; T) is $ q = 1 - p = 0.5 $. Each coin-tossing is independent of each other. The probability to have the outcome ``HHT'' in this order is $ p \\cdot p \\cdot q = 1/8 $.\n\nA binomial distribution arises when we describe the probability distribution of the number $ X $ which is the number of success in $ n $ Bernoulli trials (Walpole p.102). \n\n\\begin{defn}\nA random variable $ X $ follows a binomial distribution ($ X \\sim \\mathrm{Binom}(n, p) $) has the probability distribution\n  \\begin{equation}\\label{def: binom}\n    b(x; n, p) = \\binom{n}{x} p^x (1 - p)^{n - x}\n  \\end{equation}\nfor the success probability $ p $ of $ n $ Bernoulli trials.\n\\end{defn}\n\nFor the reason why we use a word ``binomial'', see math textbooks such as Walpole p.103. This distribution has mean, variance, and standard deviation of:\n\\begin{thm}[Binomial Distribution Mean and Variance] \\label{thm: binom mean var std}\nA binomial distribution with parameters $ n $ and $ p $, it has\n  \\begin{equation}\\label{eq: binom mean var std}\n    \\mathrm{mean} = np \\quad;\\quad\n    \\mathrm{var} = npq \\quad;\\quad\n    \\mathrm{std} = \\sqrt{npq} ~.\n  \\end{equation}\n\\end{thm}\n\\begin{proof}[of Binomial Dsitribution Mean and Variance]\nConsider $ O_i $ is the outcome of each Bernoulli trial, i.e., 1 if success and 0 if failure, of the $ i $-th trial. Then $ X = \\sum_{i=1}^{n} O_i $. The expected value of $ X $ is $ E(X) = E(\\sum_{i=1}^{n} O_i) = E(O_1) + \\cdots + E(O_n) $ since they are independent, and this becomes $ E(X) = np $.\n\nFor variance, we use a relationship $ \\mathrm{Var}(O_i) = E(O_i^2) - (E(O_i))^2 $. But since the value $ O_i^2 $ is identical to $ O_i $, $ E(O_i^2) = E(O_i) $, so $ \\mathrm{Var}(O_i) = p(1-p) \\equiv pq $ for $ q := 1-p $. $ X = \\sum_{i=1}^{n} O_i $ gives $ \\mathrm{Var}(X) = \\sum_{i=1}^{n} \\mathrm{Var}(O_i) = npq $.\n\\end{proof}\n\n\n\\subsection{Poisson Distribution}\nThe Poisson process is a fancy naming for some special ``counting''. In astronomy, we count photons (well, actually the CCD counts the photoelectrons) over time. This is why Poisson process is dealt with so much weight in astronomy. In social sciences we can count the death toll over time, in experiments we could count the lattice of a randomly shaped crystal over the distance. A formal definition of Poisson process is\\footnote{See, e.g., \\url{http://dept.stat.lsa.umich.edu/~ionides/620/notes/poisson_processes.pdf} and \\url{https://www.probabilitycourse.com/chapter11/11_1_2_basic_concepts_of_the_poisson_process.php}}\n\n\\begin{defn}[Poisson Process 1] \\label{def: Pois1}\nThe Poisson process $ N(t) $ for $ t \\ge 0 $ ($ t $ can be time, distance, or similar things), with rate $ \\lambda $ is defined by\n\\begin{enumerate}\n\\item $ N(0) = 0 $\n\\item $ N(t) $ has independent increment\n\\item $ N(t_2) - N(t_1) $ follows Poisson distribution of rate $ \\lambda (t_2 - t_1) $ for $ t_1 < t_2 $.\n\\end{enumerate}\n\\end{defn}\n\nThe definition of Poisson distribution is given below. It can be proven that it is identical to \\newpage\n\\begin{defn}[Poisson Process 2] \\label{def: Pois2}\nThe Poisson process $ N(t) $ for $ t \\ge 0 $ ($ t $ can be time, distance, or similar things), with rate $ \\lambda $ is defined by\n  \\begin{enumerate}\n    \\item $ N(0) = 0 $\n    \\item $ N(t) $ has independent increment\n    \\item $ \\mathbb{P}(N(h) = 1) = \\lambda h + o(h) $ for small $ h $.\n    \\item $ \\mathbb{P}(N(h) \\ge 2) = o(h) $ for small $ h $.\n  \\end{enumerate}\n\\end{defn}\nHere $ o(h) $ is any function such that $ \\lim_{h \\rightarrow 0} o(h) / h = 0 $. The last two items in this second definition can be re-phrased like this:\n\\begin{itemize}\n\\item [3.] For a very small interval $ h $, the probability of one single ``counting'' (Poisson process) occurs in that interval is proportional to the length of $ h $.\n\\item [4.] For a very small interval $ h $, the probability of two or more ``counting'' (Poisson process) occurs in that interval is nearly 0.\n\\end{itemize}\nThese must be independent of whether the counting happened outside of the interval, because the second item of the definition states the increment is independent.\n\n\n\\begin{defn}[Poisson Distribution] \\label{def: Pois pdf}\nA random variable $ X $ which describes a Poisson process of rate $ \\lambda $ follows the Poisson distribution ($ X \\sim \\mathrm{Pois}(\\lambda t) $) and has the following pdf\n\\begin{equation} \\label{eq: Pois pdf}\n  p(x; \\lambda t) = \\frac{(\\lambda t)^{x}}{x!} e^{-\\lambda t}\n\\end{equation}\nfor non-negative integer $ x $.\n\\end{defn}\n\n\\begin{thm}[Poisson Distribution Mean and Variance] \\label{thm: Pois mean std}\nThe mean, variance, and the standard deviation of the Poisson distribution $ p(x; \\lambda t) $ are\n\\begin{equation}\\label{eq: Pois mean std}\n  \\mathrm{mean} = \\lambda t\n  \\sep\n  \\mathrm{var} = \\lambda t\n  \\sep\n  \\mathrm{std} = \\sqrt{\\lambda t} ~.\n\\end{equation}\n\\end{thm}\nThe reason we use $ \\lambda t $ not just $ \\lambda $ is clear from Thm \\ref{thm: Pois mean std}: the mean changes as $ t $ changes, and we want to express $ p(x; \\mathrm{mean}) $ rather than $ p(x; \\mathrm{mean} / t) $. For instance, if the photon influx is $ \\lambda = \\SI{10}{photons / s} $, the mean of photon count is a function of time as $ \\lambda t $, so for $ t = \\SI{10}{s} $, the pdf is $ p(x; \\SI{100}{photons}) $. If the particles are distributed with mean density along the line of sight $ \\lambda = \\SI{0.1}{particle / m} $, the mean of particles along the line of sight is a function of the reaching distance $ \\lambda d $, so the pdf for $ d = \\SI{5}{m} $ is $ p(x; \\SI{0.5}{particles}) $. We, therefore, \\textbf{frequently denote a Poisson distribution of \\textit{mean} $ m $}, instead of \\textit{rate} $ \\lambda $.\n\n\\subsection{Relationships Between Distributions}\nThere are some relationships I want to emphasize because they will be used to understand statistical processes in astronomy. \n\n\\begin{thm}[Binomial to Poisson]\nFor $ X \\sim \\mathrm{Binom}(n, p) $, if (1) $ n \\rightarrow \\infty $, (2) $ p \\rightarrow 0 $ and (3) $ np \\xrightarrow{n \\rightarrow \\infty} \\mu < \\infty $, \n  \\begin{equation}\\label{eq: binom to pois}\n    X \\simdot \\mathrm{Pois}(x; \\mu = np)\n  \\end{equation}\n\\end{thm}\n\nAlthough I did not describe the Gaussian (normal) distribution, I am assuming you are familiar with it. One thing to note is that, both binomial and Poisson distributions are discrete ones, while normal distribution is continuous one. Therefore, the approximations given below, which approximate binomial and Poisson to normal distribution, should be used with care when the discreteness is important.\n\n\\begin{thm}[Binomial to Normal] \\label{thm: binom to normal}\nFor $ X \\sim \\mathrm{Binom}(n, p) $, it has mean $ np $ and variance $ npq $ (see Thm \\ref{thm: binom mean var std}). Then, if $ n \\rightarrow \\infty $,\n  \\begin{equation}\\label{eq: binom to normal}\n    X \\simdot \\mathcal{N}(np, npq)\n  \\end{equation}\n\\end{thm}\n\n\\begin{thm} [Poisson to Normal] \\label{thm: pois to normal}\nFor $ X \\sim \\mathrm{Pois}(\\lambda t) $, it has mean $ \\lambda t $ and variance $ \\lambda t $ (see Thm \\ref{thm: Pois mean std}). Then, if $ \\lambda t \\rightarrow \\infty $,\n  \\begin{equation}\\label{eq: pois to normal}\n    X \\simdot \\mathcal{N}(\\lambda t, \\lambda t)\n  \\end{equation}\n\\end{thm}\nAlthough I will omit here, the proof uses Stirling's formula $ x! \\approx \\sqrt{2\\pi x} x^x e^{-x} $ and $ \\ln[ (1 + \\varepsilon)^{\\lambda t (1 + \\varepsilon) + 1 / 2 }] \\approx \\lambda t \\varepsilon + \\lambda t \\varepsilon^2 / 2 $, where $ x = \\lambda t ( 1 + \\varepsilon ) $ with $ \\lambda t \\gg 1 $ and $ \\varepsilon \\ll 1 $. Stirling's formula has relative error of less than 1 \\% when $ x = 1 $ and is almost negligible for any $ x $ of interest in many cases. Considering all the approximations in the proof, we can safely assume that Poisson distribution is quite Gaussian (normal) in many astronomical contexts, unless $ x $ is very small. In practical sense, $ \\lambda t > 100 $ is large enough, and in astronomical uses, an error, i.e., error-bar, arise from small mean ($ \\lambda t \\lesssim 50 $), is not very large compared to other approximations we use in date reduction.\n\n\n\\begin{ex}[Babies in Hospital 1]\n\\textit{(Problem provided by prof. Jae-Kwang Kim at the Dept. of Math at KAIST in 2018)}\n\nThere are two hospitals A/B, and new babies are born every day. At A/B, $ N_A = 45 $ and $ N_B = 15 $ babies are born everyday, respectively. They both recorded the number of days when $ \\ge 60\\,\\% $ of the babies have XX chromosome, say $ N'_A $ and $ N'_B $. Which will have higher value? For simplicity, assume a baby can only have either XX or XY chromosome, and the probability of being either of these is the same ($ P_X = P_Y = 0.5 $).\n\nFor a hospital, assuming the events are independent, the probability of having $ \\ge 60\\,\\% $ of XX babies is\n\\begin{equation*}\n  p_{A, B} \n    = \\sum_{k= \\lceil 0.6N_{A, B} \\rceil}^{N_{A, B}} \\binom{N_{A, B}}{k} P_X^k P_Y^{N_{A, B}-k}\n    = 0.5^{N_{A, B}} \\sum_{k= \\lceil 0.6N_{A, B} \\rceil}^{N_{A, B}} \\binom{N_{A, B}}{k} ~,\n\\end{equation*}\nfor the case of hospitals A/B, respectively. A simple calculation gives this probability are $ p_A = 0.0899 $ ($ \\lceil 0.6N_A \\rceil = 27 $ for A) and $ p_B = 0.304 $ ($ \\lceil 0.6N_B \\rceil = 9 $ for B) for hospitals A and B, respectively. For 1 year, 365 days, we can calculate $ N'_A = 32.8 $ and $ N'_B = 111.0 $. Therefore, $ N'_B > N'_A $. \n\\end{ex}\n\nIn the problem above, we found hospital B will have more XX babies than A. But with what confidence? In principle, you can just calculate using binomial distribution, but there's a simpler workaround.\n\nDefine a random variable $ N_i $, such that it is 1 when $ \\ge 60\\,\\% $ of the babies have XX chromosome on the $ i $-th date; otherwise, 0. Then the expectation of $ N_i $ is $ E(N_i) = p_{A, B} $, for the case of hospitals A/B, respectively. Since $ N_i^2 $ must have identical value as $ N_i $, $ E(N_i^2) = p_{A, B} $. Then the variance becomes $ V(N_i) = E(N_i^2) - E^2(N_i) = p_{A, B} - p_{A, B}^2 = p_{A, B}(1 - p_{A, B}) \\equiv p_{A, B} q_{A, B} $.\n\nThe total number of days is $ N_{A, B} = \\sum_{i=1}^{365} N_i $, and if $ N_i $ are all independent, \n\\begin{equation*}\n\\begin{aligned}\n  \\mu_{A, B} &= E(N_{A, B}) &&= E\\qty(\\sum_{i} N_i) = np_{A, B} \\\\\n  \\sigma_{A, B} &= V(N_{A, B}) &&= V\\qty(\\sum_{i} N_i) = n \\times V(N_i) = np_{A, B}q_{A, B}\n\\end{aligned}\n\\end{equation*}\nwhere $ n = 365 $. Note that $ N $ follows binomial distribution, which is approximated as Gaussian distribution in this case (roughly speaking when $ p $ is not close to 0 or 1 and $ np $ is large enough). Therefore, $ N_{A, B} \\simdot \\mathcal{N} \\qty( \\mu_{A, B}, \\sigma_{A, B}^2 ) $, or\n\\begin{equation*}\n  N_A \\simdot \\mathcal{N}(32.8,\\, 29.9) = \\mathcal{N}(32.8,\\, 5.46^2) \\quad;\\quad\n  N_B \\simdot \\mathcal{N}(111.0,\\, 77.2) = \\mathcal{N}(111.0,\\, 8.79^2)\n\\end{equation*}\nSince this is a case when $ \\mu $ and $ \\sigma $ are known, we can use standard normal $ z $ statistic for confidence calculation. Take null hypothesis as $ H_0 : d = N_A - N_B = 0 $ and then $ z = \\frac{\\mu_A - \\mu_B}{\\sqrt{\\sigma_A^2 + \\sigma_B^2}} = 12.4 $. That means, we are confident with 12.4-$ \\sigma $, which is much larger than 99.999 \\%. More realistic null hypothesis is $ H_0 : d = N_A - N_B < 0 $, but this will have only small effect to the result.\n\n\n\\subsection{Usage in Astronomy}\nAs mentioned, photon counting is a key process in observational astronomy, and it is tightly bound to Poisson process. I will try to clarify this concept by the examples below.\n\n\\begin{ex}[Photon Counting and Poisson Process]\nThe photon counting process of astronomy resembles the Poisson Process. If $ N(t) $ is the number of photons during the exposure time $ t $, it is trivial that the first two items of Def \\ref{def: Pois2} is satisfied. The number of photons arriving in an infinitesimal time interval $ h = dt $ must be 0 or 1, but not larger than 1. To illustrate, if a total 10,000 photon should come during 10 sec of exposure, we can take $ h = 1\\,\\mathrm{ns} \\,(\\ll \\SI{10}{s} / 10,000 = \\SI{1}{ms}) $ to meet this condition. Thus, photon counting is a Poisson process.\n\\end{ex}\n\nIn reality, however, photon counting is done by electronic devices, such as CCD. Before going deeper into the subtlety, let me give another example dealing with photon noise:\n\n\\begin{ex}[Photon Counting and Poisson Noise] \\label{ex: poisnoise}\nWe saw the photon counting is a Poisson process; let me further assume the photoelectron counting process on CCD is, too (photoelectrons are generated by these photons when they excite bound electrons). Thus, we can use \\cref{eq: Pois pdf,eq: Pois mean std}. \n\nFor example, if we collected $ \\lambda t = 10,000 $ electrons during the exposure time $ t $, the 1-$ \\sigma $ uncertainty (1-$ \\sigma $ CI) or the standard deviation of this counting is $ \\sqrt{10,000} = 100 $, so we denote $ N = 10,000 \\pm 100 $. Since the $ \\lambda t $ is large enough, Thm \\ref{thm: pois to normal} says this is just a Gaussian distribution of mean 10,000 and standard deviation 100 (1 \\% of the mean). Since magnitude is $ (\\mathrm{const}) - 2.5 \\lg (\\mathrm{count}) $, differentiation gives a first-order estimation of the uncertainty in the magnitude $ \\Delta m = \\qty | -\\frac{2.5}{\\ln 10} \\frac{\\Delta (\\mathrm{count})}{\\mathrm{count}} | = \\m{0.011} $ (error-bar), which is small enough for some scientific purposes. \n\nNote that the term $ \\frac{\\Delta (\\mathrm{count})}{\\mathrm{count}} = \\frac{1}{\\sqrt{\\mathrm{count}}} $ is inversely proportional to the square root of count itself. The more we collect the count, i.e., the longer the exposure time, we will get smaller error-bar.\n\\end{ex}\n\nNow a tricky part comes in:\n\\begin{ex}[Photon Counting and Poisson Noise in ADU] \\label{ex: poisnoise adu}\nIn CCD, the number of photon ($ N_\\gamma $) will generate certain number of photoelectrons ($ N_e $), and this is measured by the electric potential (roughly speaking, $ \\mathrm{potential} = V_e \\propto N_\\mathrm{e} e $ where $ e $ is the electron charge). This voltage will be translated into integer numbers by electric circuit, and this integer is said to have a unit ADU (analog-to-digital unit) or DN (data number). In summary, a conversion of this order happens: $ N_\\gamma \\rightarrow N_e \\rightarrow V_e \\rightarrow N_\\mathrm{ADU} $. We define the (electron) gain $ g \\,[\\mathrm{electrons/ADU}] $ such that $ N_e = g N_\\mathrm{ADU} $. \n\nIf $ g = \\SI{2}{e/ADU} $ and $ N_e = 10,000 $ as in the previous example, $ N_\\mathrm{ADU} = 5,000 $. If $ N_\\mathrm{ADU} $, i.e., the ADU counting is a Poisson process, we must hace $ N_\\mathrm{ADU} = 5000 \\pm 71 $, which gives magnitude error $ \\Delta m_\\mathrm{ADU} = \\qty | -\\frac{2.5}{\\ln 10} \\frac{71}{5000} | = \\m{0.015} $. The error-bar has changed! What has just happened?\n\nThe key here is that we only checked the photon counting process is a Poisson process. Rigorously speaking, photoelectron counting and ADU counting are \\textbf{not Poisson processes}.\n\\end{ex}\n\nThen what process it is for photoelectron counting?\n\\begin{ex}[Photoelectron Follows a Binomial Distribution]\\label{ex: photoelectron binom}\nAny device which collect photon does not actually collect photon, but they output \\textit{something} which is proportional to the number of photons incident to it. In CCD, the output is the number of electrons which is measured by electric potential. The key here is the \\emph{conversion of photon into \\emph{something} must be a probabilistic process}. In CCD, the conversion happens with a paramter called the quantum efficiency (QE). Therefore, for a fixed number of photon, $ N_\\gamma $, which follows a Poisson distribution $ N_\\gamma \\sim \\mathrm{Pois}(N_\\gamma) $, the outcome, $ N_e $, will follow a binomial distribution $ N_e \\sim \\mathrm{Binom}(N_\\gamma, QE) $. Verbally put, ``photoelectron will follow a binomial distribution with the paramter $ n $ which follows a Poisson distribution and the parameter $ p $ which is believed to be fixed thanks to engineering process''.\n\n% https://www.facebook.com/groups/astro.r/permalink/2836140943148559/\nAlthough I will not give a proof, $ N_e \\sim \\mathrm{Binom}(n=\\mathrm{Pois}(N_\\gamma), p=QE) $ is approximated as $ N_e \\simdot \\mathrm{Pois}(N_\\gamma QE) $. In observation, since $ N_e \\approx N_\\gamma QE \\gg 1 $, $ N_e \\simdot \\mathcal{N}(N_e, N_e) $ (Thm \\ref{thm: pois to normal}).\n\\end{ex}\n\nHow about the ADU count?\n\n\\begin{ex}[ADU is Approximately Gaussian]\nThe ADU counting is a very strange thing: For electron gain $ g $, ADU increase by 1 for every $ g $ electrons, i.e., a step function which is very difficult to deal with in analytical sense. Regardless of its final distribution, it is clear that this conversion to the original $ N_e $ will destroy the original distribution. Fortunately, the count $ N_e $ or $ N_\\mathrm{ADU} $ is large enough in most observations, so that the discreteness of conversion is ignorable. Hence, we can treat them as if a smooth continuous convertable variables by $ N_e = g N_\\mathrm{ADU} $. Then \n\\begin{equation}\\label{eq: adu distribution}\n  N_\\mathrm{ADU} \\simdot \\mathcal{N}(N_e/g, N_e/g^2) \\quad\\mathrm{or}\\quad\n  N_\\mathrm{ADU} \\simdot \\mathcal{N}(N_\\mathrm{ADU}, N_\\mathrm{ADU}/g)\n\\end{equation}\nThat means $ N_\\mathrm{ADU} $ follows a Gaussian, but not like usual Poisson distribution (because ADU counting is not a Poisson process). Going back to Ex \\ref{ex: poisnoise adu}, we have to divide the error-bar of the count by the gain, so $ \\Delta m_\\mathrm{ADU} = \\qty | -\\frac{2.5}{\\ln 10} \\frac{\\sqrt{5000/g}}{5000} | = \\m{0.011} $, which is identical result as Ex \\ref{ex: poisnoise}.\n\\end{ex}\nFor a mathematical treatment of the ADU conversion (step function), you may find some research papers useful\\footnote{See, e.g., Merline W. J. \\& Howell S. B. 1995, Exp. Astron. \\textbf{6}, \\textit{163}, ``A REALISTIC MODEL FOR POINT-SOURCES IMAGED ON ARRAY DETECTORS: THE MODEL AND INITIAL RESULTS''.}.\n\n\n\\section{Error Propagation}\nWhen we have to calculate the uncertainty of a parameter derived from other parameters that have their own uncertainties, what we usually use is the \\textit{error propagation}. For example, $ \\mathrm{g'} = 14.0 \\pm 0.1 $ and $ \\mathrm{r'} = 15.0 \\pm 0.1 $, what is the uncertainty of the $ \\mathrm{g' - r'} $ color? Many astronomers will say it is $ -1.0 \\pm 0.14 $, where the error here is $ \\sqrt{\\sigma_\\mathrm{g'}^2 + \\sigma_\\mathrm{r'}^2} $ ($ \\sigma $ is the error-bar). If the temperature is $ T = 100 \\pm 1 \\si{K} $, what is the fractional uncertainty of bolometric luminosity ($ L = \\sigma_\\mathrm{SB} T^4 $)? Now people will say $ \\Delta L / L \\approx \\frac{4 \\sigma_\\mathrm{SB} T^3 \\Delta T }{\\sigma_\\mathrm{SB} T^4} = 4 \\Delta T / T = 4 \\% $. \n\nThe way how we do this is that, for a function $ f = f(x| a, b, c) $ where $ (a, b, c) $ is a set of parameters:\n\\begin{equation}\\label{eq: error propagation}\n  (\\Delta f)^2 \\approx \n    \\qty(\\frac{\\partial f}{\\partial a} \\Delta a)^2\n    + \\qty(\\frac{\\partial f}{\\partial b} \\Delta b)^2\n    + \\qty(\\frac{\\partial f}{\\partial c} \\Delta c)^2 ~.\n\\end{equation}\nHere, $ (\\Delta f)^2 $ is the variance of the function $ f $, $ \\Delta X $ is the standard error (such that $ X \\pm \\Delta X $ is the 1-$ \\sigma $ CI for $ X $), and we frequently use $ \\Delta f $, the standard error of $ f $, as \\emph{the error-bar}. \nIf any parameters are dependent, we need a covariance term $ \\sigma_{ab} $ for instance, and this is one of the reasons why the above error-propagation is only an approximation. This formula itself is similar to getting the gradient. In different notation, e.g., sum of pixel values, $ I := \\sum_{i} I_i $, which is reasonable to assume $ I_i $'s are independent, the identical formula becomes\n\\begin{equation}\\label{eq: error propagation 2}\n  (\\Delta I)^2 \n    \\equiv \\left ( \\Delta \\left ( \\sum I_i\\right ) \\right )^2 \n    = \\sum_{i} (\\Delta I_i)^2 ~.\n\\end{equation}\n\nNote that this is only an approximation, and in reality, we need more complicated calculation. Also it is impossible to know how accurate this approximation is, before you conduct detailed calculation. The reason astronomers use it in spite of the pitfall is because most cases we are only interested in the \\emph{rough} estimation of the error-bar. \n\n\n\n\n\\section{The Chi-Square Minimization}\nYou may have heard of it, or simply the \\textit{least square} something. Least square or the chi-square minimization is a process to find the set(s) of model parameters which has the biggest (or bigger than threshold) \\textit{likelihood} in Bayesian statistics. The set of ``best'' model parameters is the one with the largest likelihood, so we call it the maximum likelihood estimator, \\textbf{MLE}.\n\nConsider independent and identically distributed (\\textit{i.i.d.}) random variables\\footnote{Random variables $ X_{i} $ for $ i = 0, \\cdots, N $ are called i.i.d. if they (1) follow identical probability distribution, say $ f(x) $, and (2) $ f(X = x) = f(X_1 = x_1) \\times \\cdots \\times f(X_N = x_N) $, where $ x = (x_1, \\cdots , x_N) $ (same for $ X $). }, e.g., flux as a function of $ \\lambda $. It is independent because the measurement at each wavelength itself is independent from that of any other wavelength. It is identically distributed because and we will assume each error-bar is Gaussian. The second assumption is not necessarily correct, and actually that happens many times (e.g., flux is Gaussian distributed but magnitude is not, because it is log of Gaussian distribution).\n\nWe will study Bayes' theorem later, but let me introduce it first to grap the meaning of chi-square statistic:\n\\begin{align*}\n  P(\\mathbf{\\theta}|D, I) &= \\frac{P(D|\\mathbf{\\theta}, I) P(\\mathbf{\\theta}|I)}{P(D, I)} \\\\\n  P(\\theta|D, I) &\\propto P(D | \\theta, I) P(\\theta|I)\n\\end{align*}\nWhen we have data points, $ (x_i, y_i) $, which are all independent, and $ y \\sim N(y_i, \\sigma_i^2) $. Then one of the most na\\\"{i}ve goodness-of-fit statistic variables can be the square-sumed error:\n\\begin{equation}\\label{eq: sse}\n  \\mathrm{SSE} = \\sum_{i} (y_i - f(x_i| \\theta))^2\n\\end{equation}\nSince $ y_i $ are all Gaussian, the probability of obtaining such data is obtained from the multiplication law:\n\\begin{equation*}\n  P(D = \\{y_i\\}) = \\prod_i A e^{-(f(x_i|\\theta)-y_i)^2/2\\sigma_i^2} \n\\end{equation*}\nor taking log:\n\\begin{equation}\n  \\ln P(D = \\{y_i\\}) = \\ln A - \\sum_i \\frac{ (f(x_i|\\theta) - y_i)^2}{2\\sigma_i^2}\n\\end{equation}\nNow getting parameters which maximize $ P $ is identical to (1) getting them which maximize $ \\ln P $, and this is also identical to (2) getting them which mininize the summation in the exponent. Therefore, the exponent, which is chi-square statistic:\n\\begin{equation}\\label{eq: chi-square statistic}\n  \\chi^2 = \\sum_i \\frac{(y_i - f(x_i | \\theta))^2}{\\sigma_i^2} ~,\n\\end{equation}\nshould be minimized to get the most probable answer to the fitting problem. If the error-bars of all data points are identical, $ \\sigma_i $ is nothing but a constant, so minimizing chi-square is identical to minimizing SSE.\n\n\n\n\\section{Interpolation}\nWhen we fit an analytic function to the data, we usually use a statistic (e.g., the chi-square value or the BIC) that indicates the goodness-of-fit (also called figure of merit). But what if we don't know or not interested in the true analytic function behind the scene? For example, for aperture trace or sense function in spectroscopy, we have absolutely no idea what is the true analytic function. In this situation, \\textbf{interpolation} comes in. \n\n\\begin{defn}[Interpolation]\nAn interpolation function is a function that smoothly connects \\textit{all} the observed data points.\n\\end{defn}\n\nFor instance, a linear interpolation is a function which connects all the data points with linear segments as in \\cref{fig:interpolation}. In cubic spline, you fit a 3rd order polynomial function (total 4 unknowns). For points $ (x_i, y_i) $ where $ i = 0 \\ldots n $, we want to obtain $ n $ spline curves $ S_i(x) $ for $ i = 0 \\ldots n-1 $. All such interpolation functions should be \\textit{smoothly connected} to each other by\n\\begin{itemize}\n  \\item $ S_i (x_i ) = y_i      \\quad(i = 0 , \\ldots , n-1). $\n  \\item $ S_{i-1} (x_i ) = y_i  \\quad(i = 1 , \\ldots , n). $\n  \\item $ S^\\prime_i (x_i) = S^\\prime_{i-1} (x_i)\\quad(i = 1 , \\ldots , n-1). $\n  \\item $ S^{\\prime\\prime}_i (x_i) = S^{\\prime\\prime}_{i-1} (x_i) \\quad(i = 1 , \\ldots , n-1). $\n  \\item $ S^{\\prime\\prime}_0 (x_0) = S^{\\prime\\prime}_{n-1} (x_n) =0 $.\n\\end{itemize}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.7\\linewidth]{figs/interpolation}\n  \\caption{A display of linear/cubic spline interpolations and spline fittings.}\n  \\label{fig:interpolation}\n\\end{figure}\n\nIn python, you can use\n\\begin{python}\nfrom scipy.interpolate import UnivariateSpline\n# linear spline interpolation\ninterp_1 = UnivariateSpline(x, y, s=0, k=1)\n# cubic spline interpolation\ninterp_3 = UnivariateSpline(x, y, s=0, k=3)\n\n# use it as y_interp_1 = interp_1(x_values)\n\\end{python}\nThe parameter \\texttt{s} is the smoothing factor. That is, \n\\begin{equation}\n  \\sum_{i=1}^{n} w_i^2 (y_i - S(x_i))^2 \\le s ~.\n\\end{equation}\nIf no error-bar is present, we can just ignore $ w_i $ (weights), and if there exists $ \\sigma_i $, we can use $ w_i = 1/\\sigma_i $, and the above equation becomes nothing but a chi-square. In that case, the $ \\chi^2 $ smaller than the total degrees of freedom (roughly the number of data points) is a good measure, so \\pyth{s = len(x)} is a good guess for spline fitting. If you put $ s = 0 $, it means $ S(x_i) $ must be the same as $ y_i $, i.e., the fitted function must go through all the data points: this is the interpolation. \n\nFrom the figure, cubic spline interpolation is more smooth and the linear one looks too discrete, so you may always want to use cubic version. A caveat is that cubic spline has large fluctuation when there is any large scatter, as seen from $ x = 5 $ and $ x = 6 $. This ``shooting'' effect is severe when you fit a sense function (spectroscopic flux calibration) to a spectroscopic standard star: if the star has an absorption line, the cubic fit will be problematic near that wavelength region. \n\n\n\\section{Change of Variables}\nIn a formal error-propagation calculation, the change of variables is very important, because sometimes the physical paramters which describe the function you are interested in may be different from the observables which you obtain from expeirments or observations. We actually do the change of variables without much mathematical instroduction. An example is when $ m = -2.5 \\lg I $, we differentiate it to get $ \\Delta m = \\frac{2.5}{\\ln 10} \\frac{\\Delta I}{I} \\approx 1.086 \\frac{\\Delta I}{I}$ (as in Ex \\ref{ex: poisnoise}). This way, we changed the error of the variable $ I $ to that of $ m $. Formally, if a conversion happens from parameters (or random variables) $ X_1,\\,\\cdots,\\, X_M $ to $ Y_1,\\,\\cdots,\\, Y_M $, we use Jacobian\n\\begin{equation}\\label{eq: change_of_var}\n\\begin{aligned}\n  f(Y_1,\\,\\cdots,\\, Y_M) \\delta Y_1 \\cdots \\delta Y_M \n    &= g(X_1,\\,\\cdots,\\, X_M) \\delta X_1 \\cdots \\delta X_M \n  \\\\\n  f(Y_1,\\,\\cdots,\\, Y_M) \n    &= \\qty| \\pdv{(Y_1,\\,\\cdots,\\, Y_M)}{(X_1,\\,\\cdots,\\, X_M)} | g(X_1,\\,\\cdots,\\, X_M)\n\\end{aligned}\n\\end{equation}\nwhere, e.g., \n\\begin{equation}\\label{eq: jacobian}\n  \\qty| \\pdv{(Y_1,\\, Y_2)}{(X_1,\\, X_2)} | :=\n  \\mqty| \\pdv{Y_1}{X_1} & \\pdv{Y_1}{X_2} \\\\ \\pdv{Y_2}{X_1} & \\pdv{Y_2}{X_2} | ~.\n\\end{equation}\n\n\\begin{ex}[Cauchy distribution: Lighthouse Problem]\\label{ex: lighthouse}\n\\textit{(This is taken from Sivia (\\S 2.4), which is recited from GullSF 1988, which also adopted it from ``Cambridge Part 1A examples sheet''.)}\n\nConsider a lighthouse at $ (x, y) = (\\alpha, \\beta) $. The lighthous emits an infinitely thin lightray to a uniformly random direction $ \\theta $ (angle counterclockwise from $ -y $ direction), as in \\cref{fig: lighthouse}. What is the probability distribution of $ x_k $ for the $ k $-th position on the shore which receives the light?\n\nSicne $ \\theta $ is uniformly distributed, the pdf is $ f(\\theta_k | \\alpha, \\beta) = 1/\\pi $ (uniform over $ \\pm \\pi/2 $; You may use $ 1/2\\pi $ considering uniform over $ \\pm \\pi $, but that will change the result only by up to a multiplication of a constant, 2). Since $ \\tan \\theta_k = (x_k - \\alpha)/\\beta $, the change of variable gives\n\\begin{equation*}\n  g(x_k | \\alpha, \\beta) = \\pdv{\\theta_k}{x_k} f(\\theta_k | \\alpha, \\beta)\n    = \\frac{1}{\\pi} \\frac{\\beta}{\\beta^2 + (x_k - \\alpha)^2} ~.\n\\end{equation*}\nThis is the Cauchy distribution with the ``$ \\gamma $'' parameter equals $ \\beta $. \n\nMathematically, Cauchy distribution does not have a mean (simple proof can be $ \\lim_{a\\rightarrow \\infty} \\int_{-a}^{+a} g(x) dx = 0$ is not equal to $ \\lim_{a\\rightarrow \\infty} \\int_{-2a}^{+a} g(x) dx = \\infty $). Also the standard deviation cannot be defined since the mean of $ x^2 $ also diverges. If $ \\mu $ and $ \\sigma $ are undefined, the CLT in the form of Thm \\ref{thm: clt} cannot be used.\n\\end{ex}\n\n\n\\begin{figure}\n\\centering\n\n\n\\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        \n\n\\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]\n%uncomment if require: \\path (0,300); %set diagram left start at 0, and has height of 300\n\n%Shape: Axis 2D [id:dp9054512614951153] \n\\draw  (29,194.2) -- (420.5,194.2)(68.15,34) -- (68.15,212) (413.5,189.2) -- (420.5,194.2) -- (413.5,199.2) (63.15,41) -- (68.15,34) -- (73.15,41)  ;\n%Shape: Star [id:dp4847863660698495] \n\\draw   (192.25,81) -- (195.85,88.15) -- (203.9,89.29) -- (198.08,94.85) -- (199.45,102.71) -- (192.25,99) -- (185.05,102.71) -- (186.42,94.85) -- (180.6,89.29) -- (188.65,88.15) -- cycle ;\n%Straight Lines [id:da9248807400548928] \n\\draw  [dash pattern={on 0.84pt off 2.51pt}]  (192.25,93) -- (192.25,195) ;\n%Straight Lines [id:da9932130816919462] \n\\draw  [dash pattern={on 0.84pt off 2.51pt}]  (192.25,93) -- (67.5,93) ;\n%Straight Lines [id:da5299276212835915] \n\\draw    (192.25,93) -- (289.11,192.57) ;\n\\draw [shift={(290.5,194)}, rotate = 225.79] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;\n\n% Text Node\n\\draw (417,199.4) node [anchor=north west][inner sep=0.75pt]    {$x$};\n% Text Node\n\\draw (51,21.4) node [anchor=north west][inner sep=0.75pt]    {$y$};\n% Text Node\n\\draw (187,198.4) node [anchor=north west][inner sep=0.75pt]    {$\\alpha $};\n% Text Node\n\\draw (52,82.4) node [anchor=north west][inner sep=0.75pt]    {$\\beta $};\n% Text Node\n\\draw (194,111.4) node [anchor=north west][inner sep=0.75pt]    {$\\theta _{k}$};\n% Text Node\n\\draw (282,198.4) node [anchor=north west][inner sep=0.75pt]    {$x_{k}$};\n% Text Node\n\\draw (356,180) node [anchor=north west][inner sep=0.75pt]   [align=left] {sea};\n% Text Node\n\\draw (356,196) node [anchor=north west][inner sep=0.75pt]   [align=left] {land};\n\n\n\\end{tikzpicture}\n\n\\label{fig: lighthouse}\n\\caption{A schematic diagram for the lighthouse problem.}\n\\end{figure}\n", "meta": {"hexsha": "0e81a27b909665dc87d8437f0218aff41b133c60", "size": 62501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Books/chaps/01_stats.tex", "max_stars_repo_name": "ysBach/SNU_AOclass", "max_stars_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-03-23T06:14:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T01:49:51.000Z", "max_issues_repo_path": "Books/chaps/01_stats.tex", "max_issues_repo_name": "ysBach/SNU_AOclass", "max_issues_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-05-04T17:21:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-24T11:41:55.000Z", "max_forks_repo_path": "Books/chaps/01_stats.tex", "max_forks_repo_name": "ysBach/SNU_AOclass", "max_forks_repo_head_hexsha": "e2e364b08c2e6e129c267db9cbd76cfd0ab77527", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-05-10T14:19:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T09:18:08.000Z", "avg_line_length": 84.8046132972, "max_line_length": 924, "alphanum_fraction": 0.6893969696, "num_tokens": 19724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6146568446271278}}
{"text": "\\section{Solving Equations}\r\n\\noindent\r\nNow that we can take the Laplace transform and its inverse of most of the common functions we've seen when solving differential equations, we can use Laplace transforms as another tool to solve differential equations.\\\\\r\n\r\n\\noindent\r\nThere is a general pattern to how we'll use Laplace transforms to solve differential equations.\r\n\\begin{enumerate}[label=\\arabic*)]\r\n\t\\item If needed, arrange the equation into a convenient form in the $t$ domain.\r\n\t\\item Take the Laplace transform of both sides.\r\n\t\\item Use algebra, especially partial fraction decomposition and completing the square, to arrange items into a convenient form in the $s$ domain.\r\n\t\\item Take the inverse Laplace transform of both sides and solve.\r\n\\end{enumerate}\r\n\r\n% Examples\r\n\\input{./laplaceTransforms/solvingEquations/solvingEquations_examples.tex}", "meta": {"hexsha": "84912f0580c5b4e84419a351b7ab9bca48f9e93f", "size": 861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/solvingEquations/solvingEquations.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/solvingEquations/solvingEquations.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/solvingEquations/solvingEquations.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": 57.4, "max_line_length": 220, "alphanum_fraction": 0.7897793264, "num_tokens": 190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080671950640463, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.614656843717022}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\marginpar{Monday\\\\ 2020-11-9, \\\\ compiled \\\\ \\today}\n\nWe have a parameter vector \\(\\vec{x}\\), and in a step in our MCMC we want to move to a new parameter \\(\\vec{y}\\). \nWe start off with a transition proposal distributed according to the distribution \\(Q\\), which can depend on \\(\\vec{x}\\).\nThis \\(Q\\) may, for example, be a simple Gaussian. \n\nThen, we have an acceptance/rejection step: we accept the step with a probability \n%\n\\begin{align}\n\\alpha (y | x) = \\min \\qty(\\frac{p(\\vec{y}) Q(\\vec{x} | \\vec{y})}{p(\\vec{x}) Q(\\vec{y} | \\vec{x})}, 1)\n\\,,\n\\end{align}\n%\nwhere \\(p\\) is the posterior.\nIf we are using a Gaussian \\(Q\\), it is symmetric, therefore we only have \\(\\alpha = \\min (p(\\vec{y}) / p (\\vec{x}), 1)\\). \nIf the posterior is higher in \\(\\vec{y}\\) than in \\(\\vec{x}\\) we always accept the step, else we accept it sometimes. \n\nWe need to check whether the MC is ergodic: the transition probability reads \n%\n\\begin{align}\nT(y | x) &= \\alpha Q = \n\\min \\qty(\\frac{p(\\vec{y}) Q(\\vec{x} | \\vec{y})}{p(\\vec{x}) Q(\\vec{y} | \\vec{x})}, 1)\nQ(\\vec{y} | \\vec{x})  \\\\\n&= \\frac{1}{p(\\vec{x}) Q(\\vec{y} |\\vec{x})} \\min \\qty[p(\\vec{y} ) Q(\\vec{x} | \\vec{y}), p(\\vec{x}) Q(\\vec{y} | \\vec{x})]\nQ(\\vec{y} | \\vec{x})  \\\\\n&= \\frac{1}{p(\\vec{x})} \\min \\qty[p(\\vec{y} ) Q(\\vec{x} | \\vec{y}), p(\\vec{x}) Q(\\vec{y} | \\vec{x})]\n\\,,\n\\end{align}\n%\ntherefore we have \n%\n\\begin{align}\nT(\\vec{y} | \\vec{x}) p(\\vec{x}) = \\min \\qty[p(\\vec{y} ) Q(\\vec{x} | \\vec{y}), p(\\vec{x}) Q(\\vec{y} | \\vec{x})]\n= T(\\vec{x} | \\vec{y}) p(\\vec{y})\n\\,,\n\\end{align}\n%\nwhich is precisely the \\textbf{detailed balance} condition, with the stationary distribution being precisely \\(p\\), the posterior. \n\nSince we only need to compute ratios of the posterior, we never need to compute the evidence. \n\n\\subsection{Gibbs sampling}\n\nWe start from a parameter vector \\(\\vec{x}\\), and we only update the \\(i\\)-th parameter, keeping the others fixed, according to the conditional probability for that parameter given all the others: \\(\\mathbb{P}(\\theta _i | \\theta_1 , \\hat{\\theta}_i, \\theta _n)\\). \nHere we always accept the step. \n\nWe update each parameter separately (using the old values), and then move the full parameter vector together. \nIt is a special case of Metropolis-Hastings with \\(Q\\) being the conditional probability and acceptance probability equal to 1. \nWe might want to use it if we have easy access to the conditional distribution. \n\nThe issue is always convergence: we have convergence theorems for \\(N \\to \\infty \\), but we need \\emph{fast} convergence practically. \n\nWe can compute averages and standard deviations as \n%\n\\begin{align}\n\\expval{\\theta _i} &\\approx \\frac{1}{N} \\sum _{k=1}^{N} \\theta^{(k)}_i  \\\\\n\\sigma^2_{\\theta _i} &\\approx \\frac{1}{N} \\sum _{k=1}^{N} \\abs{\\theta^{(k)}_i}^2 - \\expval{\\theta _i}^2\n\\,.\n\\end{align}\n\nThis is not done over \\emph{all} the points, but only over the ones calculated after convergence. \n\nMarginalization is done as such: \n%\n\\begin{align}\np(\\theta_2) = \\int \\dd{\\theta _1} p(\\theta_1 , \\theta _2 ) \n= \\int \\dd{\\theta _1} p(\\theta_1 | \\theta _2) p(\\theta_1 )\n\\,.\n\\end{align}\n\nWe can simply build a marginal histogram by neglecting a coordinate and then binning. \n\n\\subsection{Convergence}\n\nHow do we verify convergence? This is the complicated part.\nWe can do a trace plot: \n%\n\\begin{align}\n\\Tr[ - \\log \\mathcal{P}] = - \\sum _{k=1}^{M} \\frac{1}{k} \\log \\mathcal{P}(\\theta^{(k)}_i | \\vec{d})\n\\,,\n\\end{align}\n%\nwhich should converge to a fixed maximum value after some time. \nHowever, we might not have covered a representative region of the full posterior. \n\nA standard technique is to start \\(M\\) different chains, and for each compute the average separately. \n\nWe can compute the average of each chain, \\(\\overline{\\theta}^{J}\\) (where \\(J = 1 \\dots M\\)); and the total average \\(\\overline{\\theta}\\) over all the chains. \nWe can also estimate the variance of each chain, \\(w^{J}\\): \n%\n\\begin{align}\nw^{J} = \\frac{1}{n-1} \\sum_{i=1}^{n} \\qty(\\theta^{J}_{i} - \\overline{\\theta}^{J})^2\n\\,,\n\\end{align}\n%\nwhere the \\(n-1\\) is the Bessel correction, needed because we use the estimated average instead of the true average. \n\nThrough manipulation, we can show that \n%\n\\begin{align}\nw^{J} &= \\frac{n}{n-1} s_J - \\frac{n}{n-1} \\var{\\overline{\\theta}^{J}}\n\\,,\n\\end{align}\n%\nwhere \\(\\var{\\overline{\\theta}^J} = (\\overline{\\theta}^{J} - \\mu )^2\\) is an estimator for the variance of the \\emph{mean} of the parameter vector, while \\(s_J\\) is the estimator of the true variance of the chain. \nFlipping the expression we can find \n%\n\\begin{align}\ns_J = \\frac{n-1}{n} w^{J} + \\var{\\overline{\\theta}^{J}}\n\\,.\n\\end{align}\n\nWe can estimate the variance of the chain mean as \n%\n\\begin{align}\n\\widehat{\\var{\\overline{\\theta}}} = \\frac{1}{M-1} \\sum _{J=1}^{M} (\\overline{\\theta}^{J}- \\overline{\\theta})^2 = \\frac{B}{n}\n\\,,\n\\end{align}\n%\nand then we can average the single chain variance estimators: \n%\n\\begin{align}\nW = \\frac{1}{M} \\sum _{J=1}^{M} w^{J}\n\\,,\n\\end{align}\n%\nso then we get the estimator \n%\n\\begin{align}\n\\hat{V} = \\frac{n-1}{n} W + \\frac{B}{n}\n\\,,\n\\end{align}\n%\nand then we can define \\(\\hat{R} = \\hat{V} / W\\): we expect \\(B/n\\) to become irrelevant asymptotically. \nIf \\(\\hat{R}\\) is of order 1 then we can say that we have converged. \nTypically, we say that when \\(\\hat{R} \\lesssim \\num{1.02}\\) we have converged. \n\n\\todo[inline]{Add more calculations}\n\nThese tests are not fool-proof: we try to falsify the hypothesis of convergence, and at a certain point we stop trying to do so. \n\n\\end{document}\n", "meta": {"hexsha": "b6e3d7cecfcaa155da1c51ae9f836a925da162f4", "size": 5569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostatistics_cosmology/nov09.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_third_semester/astrostatistics_cosmology/nov09.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_third_semester/astrostatistics_cosmology/nov09.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": 38.1438356164, "max_line_length": 263, "alphanum_fraction": 0.6581073801, "num_tokens": 1864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6146315645932251}}
{"text": "% $Id$\n%\n% Author: David Fournier\n% Copyright (c) 2008 Regents of the University of California\n%\n\nThe Vector Autoregressive Moving Average Garch process combines\nthe Vector Autoregressive Moving Average (\\textsc{varma})\nprocesses with the Vector Garch (generalized \nautoregressive conditional heteroscedastic) processes.\n\n\n\\section{Formulation of the \\textsc{varma garch} process}\n\nThe \\textsc{varma garch} process of type $(p,q,r,s)$ is given by a \nseries $Y_t$ for $t=-p+1,\\ldots,n$, where for each value of $t$,\n$Y_t$ is an $m$-dimensional vector.\nFor $t>0$, the $Y_t$ are assumed to satisfy a relationship of the form\n\\begin{equation}\n  Y_t=\\mu +\\sum_{l=1}^p A_l (Y_{t-l}-\\mu)\n    +\\sum_{l=0}^q B_l \\epsilon_{t-l}            \n  \\label{eq1}\n\\end{equation}\nwhere the $\\mu$ is an $m$-dimensional vector, \n$A_l$ and $B_l$ are $m\\times m$ matrices, $B_0$ is the identity\nmatrix,  and the\n$\\epsilon_t$ are multivariate (normal) random vectors,\nwith means~$0$.  Covariance matrices $\\Sigma_t$ and\n $\\hbox{\\rm E}(\\epsilon_t\\epsilon_{t^\\prime})=0$ if $t\\ne t^\\prime$.\nLet\n\\begin{equation}\n  r_t=Y_t-\\mu -\\sum_{l=1}^p A_l (Y_{t-l}-\\mu)\n  \\label{eqc1}\n\\end{equation}\nbe the vector of model residuals or ``shocks.''\\footnote{For the moving\naverage model ($q>0$), one might argue that since the previous values\nof $r_t$ have been observed, the shock part of $r_t$, say,\n$d_t$, is given by $d_t=r_t-\\sum_{l=1}^q B_l r_{t-l}$,\nbut this has not been done at present.}\nThese residuals are\nassumed to contribute to the covariance matrix in the next time period.\nThe $\\Sigma_t$ evolve according to one of several relationships.\n\n\\subsubsection{The \\textsc{dvec} relationship}\n\\begin{equation}\n  \\Sigma_t=\\Omega+\n        \\sum_{l=1}^r F_l\\bigotimes r_{t-l}r_{t-l}^\\prime  \n         +\\sum_{l=1}^sG_l\\bigotimes \\Sigma_{t-l}\n  \\label{eqc}\n\\end{equation}\nIn equation~(\\ref{eqc}), the matrices \n$F_l$ and $G_l$ are symmetric and the operator\n`$\\bigotimes$' denotes the element-wise product of matrices.\nThis parameterization does not restrict the resulting matrix to\nbe positive definite, so some care is necessary to ensure the\nstability of the resulting~model.\n\n\\subsubsection{The \\textsc{bekk} relationship}\n\\begin{equation}\n\\Sigma_t=\\Omega+\n       \\sum_{l=1}^r F_l\\, r_{t-l}\\, r_{t-l}^\\prime\\, F_l^\\prime \n        + \\sum_{l=1}^s\\, G_l\\, \\Sigma_{t-l}\\, G_l^\\prime\n  \\label{eq2}\n\\end{equation}\n\n\\subsubsection{\\textsc{dveci} and \\textsc{bekkai} parameterizations}\nThe basic \\textsc{dvec} and \\textsc{bekk} parameterizations can be extended by  modifying\ncomponents of the $r_t$ to reflect the asymmetric response\nto positive and negative values.\n\\begin{align}\n    \\nonumber \\eta_{ij} =&\\epsilon_{ij}/\\alpha_j &\\textrm{if } \\epsilon_{ij} \\ge 0\\\\\n    \\eta_{ij} =&\\epsilon_{ij}\\alpha_j                    &\\textrm{if }  \\epsilon_{ij} < 0\n\\end{align}\nThis modified form will be referred to as the \\textsc{dveci} and \\textsc{bekkai} parameterizations.\n\\begin{equation}\n\\Sigma_t=\\Omega+\n        \\sum_{l=1}^r F_t\\bigotimes \\eta_{t-l}\\, \\eta_{t-l}^\\prime  \n         +\\sum_{l=1}^sG_l\\bigotimes \\Sigma_{t-l}\n  \\label{eqd}\n\\end{equation}\n\\begin{equation}\n  \\Sigma_t=\\Omega+\n       \\sum_{l=1}^r F_l\\, \\eta_{t-l}\\, \\eta_{t-l}^\\prime\\, F_l^\\prime \n        + \\sum_{l=1}^sG_l\\, \\Sigma_{t-l}\\, G_l^\\prime\n   \\label{eqe}\n\\end{equation}\n\n\n\\section{Setting a value for $\\Sigma_1$}\n\nThe value for the parameters in $\\Sigma_1$ are often poorly determined \nand simply letting them be free parameters can lead to \ninstability and initial\ntransient effects in the model. To stabilize the parameterization, we have \ncalculated $\\Sigma_1$ through $\\Sigma_{\\max\\{r,s\\}}$ from the condition\n\\begin{equation}\n  \\widehat\\Omega=\\Sigma+\\sum_{l=1}^q B_l\\Sigma B_l^\\prime \n\\end{equation}\nwhere \n\\begin{equation}\n  \\widehat\\Omega=\\frac{1}{n}\\sum_{t=1}^n\\hat\\epsilon_t\\, \\hat\\epsilon_t^\\prime \n\\end{equation} \ndenotes the empirical covariance matrix formed from the\nmodels residuals \n\\begin{equation}\n  \\hat\\epsilon_t=Y_t-\\mu-\\sum_{l=1}^p A_l (Y_{t-l}-\\mu).\n\\end{equation}\n\n\n\\section{Ensuring that the $\\Sigma_t$ are positive definite}\n\nThe \\textsc{dvec} parameterization can produce matrices that are not\npositive definite, and the \\textsc{bekk} parameterization can produce matrices\nthat are almost not positive definite (much as a positive number can\nget arbitrarily close to zero). At worst, this will lead to a failure\nin the model to converge and at best, it makes the estimation somewhat\nunstable. To improve model performance, the \\textsc{bekk} and \\textsc{dvec}\noperations are followed by a modification of the resulting $\\Sigma_t$ that\n makes them more positive definite. The first problem is to get a notion of what is meant by ``small'' for a particular problem. \nThis is accomplished by first scaling the \n$\\Sigma_t$ to produce a matrix $\\Lambda_t$ where\n\\begin{equation}\n  \\Lambda_{ij}=\\frac{\\Sigma_{t_{ij}}}{\\sqrt{\\Sigma_{t_{ij}}\\Sigma_{t_{ij}}}}\n\\end{equation}\nThe terms $\\Lambda_{ii}$ are then bounded above {$1.0\\e{-3}$,  i.e., they are replaced in a differentiable fashion with numbers that are $\\ge 1.0\\e{-3}$ using\nthe \\texttt{posfun} function.\nIn addition, the correlation matrix \n$\\Lambda_{ij}/\\sqrt{\\Lambda_{t_{ij}}\\Lambda_{t_{ij}}}$ is\ndecomposed via a Choleski decomposition, the divisors of\n which is forced to be $> 0.3$ in a differentiable fashion using the\n\\texttt{posfun} function.\n\\X{\\fontindexentry{tt}{posfun} function}\nThe\nabove operations leave a matrix that is sufficiently positive definite\nand close enough to $\\Sigma_1$ unchanged.\n\n\n\\section{Missing data}\n\nMissing data points are included into the model as parameters to\nbe estimated. If there are a substantial number of missing data\npoints, this will induce bias into the estimates.\n\n\n\\section{The likelihood function}\n\nThe model was fit by maximum-likelihood or, more correctly, by\nfinding the mode of the Bayesian posterior distribution.\nA robust likelihood function that is a mixture of a normal\ndistribution and a Cauchy distribution is employed.  The amount of robustness\ncan be changed by the user.\n\n\n\\section{Model selection}\n\nModel selection consists of fitting the model to the data for various values\nof the parameters $(p,q,r,s)$ and trying to determine the simplest model\nthat adequately fits the data, if any. \n\nThe two criteria which are used for this are the likelihood ratio test\nand investigation of the residuals in the form of the Box-Ljung statistic.\nThe likelihood-ratio test is used for general model selection, while\nthe Box-Ljung statistic is used to investigate whether or not the model\ncan adequately fit the changes in the covariance matrices $\\Sigma_t$\nthat occur over time.\n\n\n\\section{The Box-Ljung statistic}\n\nThe following Box-Ljung\nstatistic was employed \nto test the ability of the model to model the time varying covariance\nstructure of the time series. This statistic is calculated from the\nestimated standardized residuals $z_t$, for $t=1,\\ldots n$,\nwhere for each $t$, $z_t$ is an $m$-dimensional vector.\nThe $z_i$ are obtained in the calculations necessary to calculate the\nlog-likelihood~\\mbox{function}.\n\\begin{align}\n  \\hat\\mu_j&=\\frac{1}{ n}\\sum_{i=1}^n z_{ij}\\\\\n  z_{ij}^{\\prime}&=z_{ij}-\\hat\\mu_j\\\\\n  \\hat\\sigma_{jk}&=\\frac{1}{ n}\\sum_{i=1}^n z_{ij}^\\prime z_{ik}^\\prime\\\\\n  \\gamma_{ijk}&=\n       \\frac{\n            \\frac{1}{ n-l}\\sum_{i=1}^{n-l}\n         (z_{ij}^\\prime z_{ik}^\\prime-\\hat\\sigma_{jk})\n         (z_{i,j+l}^\\prime z_{i,k+l}^\\prime-\\hat\\sigma_{jk})\n            }{                              \n            \\frac{1}{ n}\\sum_{i=1}^n\n         (z_{ij}^\\prime z_{ik}^\\prime-\\hat\\sigma_{jk})^2\n       }\n\\end{align}\n\nUnder the null hypothesis that the model is adequate, and if the\n$z_i$ are normally distributed, then the sum\n$$LB(K)_{ij}=n\\sum_{k=1}^k w_k \\gamma_{ijk}^2$$\nis asymptotically distributed as a $\\chi^2$ random variables \nwith~$K$ degrees of freedom. Here, $w_k=(n+2)/(n-k)$.\n\n\n\\section{Analysis of simulated data}\n\nOne method to get an idea how well a statistical model works is to\nuse it with simulated data where the true values of the parameters being estimated\nare known.\nA simple simulator that can generate data sets is included with the\n\\texttt{mgarch} package. The simulator generated a 4-dimensional set of\n1,000 observations. A type~$1,1,1,1$ process was simulated and\nanalyzed.\n\nThe following plots show the actual and predicted values for the\ndiagonal variance and correlation terms for the analysis with\na type $1,1,1,1$~model.\n\n\\includegraphics[height=2.5in, width=\\textwidth]{covarplot11.png}\n\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{covarplot11.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{covarplot22.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{covarplot33.png}\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{covarplot44.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot21.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot31.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot32.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot41.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot42.png}\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{corrplot43.png}\n\n\n\n\\section{Analysis of real data}\n\nThe data consist of daily observations of the German Mark/US Dollar and Japanese Yen/US dollar exchange rates, as well as the SP-500 and Tokyo \n (\\textsc{tokyose}) stock exchange indices. For this data set, $m=4$, and there\nwere $1301$ time periods with $211$ missing values.  \n\n\\subsection{Model Parameters log-likelihood directory $p,q,r,s$.}\n\\begin{lstlisting}\nVARMA\n0,0,0,0   221         -1382.56      000\n1,0,0,0   241         -1322.47      100\n1,1,0,0   253         -1308.57      110\n\nVARMA with DVEC\n0,0,1,1   241         -1050.87 \n1,1,2,1   283         -928.518 \n1,2,1,1   289         -924.755  \n\nVARMA with DVECI\n1,1,2,1a  287         -887.764 \n1,2,1,1a  293         -888.531 \n\\end{lstlisting}\n\n\\bigskip\n\\subsection{Ljung-Box statistic ($\\chi^2$ with 10 degrees of freedom).}\n\\begin{lstlisting}\nVARMA\n0,0,0,0         138.953  52.902  26.351 19.171\n                 52.902 222.502 154.708 59.681\n                 26.351 154.708  60.328 87.031\n                 19.171  59.681  87.031 68.889\n\n\n1,1,0,0         154.977  74.511  19.329 11.472\n                 74.511 177.016 130.295 59.084\n                 19.329 130.295  47.499 72.724\n                 11.472  59.084  72.724 49.329\n\nVARMA with DVEC\n0,0,1,1           3.728 13.180 17.682 17.633\n                 13.180 11.496 25.846  6.016\n                 17.682 25.846  7.610  6.791\n                 17.633  6.016  6.791 13.398\n\n\n1,1,1,1           4.239  9.519 10.866 10.885\n                  9.519  6.434 21.734  8.047\n                 10.866 21.734  4.089  8.318\n                 10.885  8.047  8.318 12.814\n\n1,2,1,1           5.660 10.348 11.029 11.557\n                 10.348  7.011 21.727  7.039\n                 11.029 21.727  4.819  7.908\n                 11.557  7.039  7.908 10.684\n\n1,1,2,1           6.920 11.698 11.464 12.593\n                 11.698  4.914 24.677  8.179\n                 11.464 24.677  2.399  8.855\n                 12.593  8.179 8.855 10.985\n\nVARMA with DVECI\n1,2,1,1a          4.352  9.658  9.402  8.542\n                  9.658  7.646 17.516  8.416O\n                  9.402 17.516  5.795  7.108\n                  8.542  8.416  7.108 10.483\n\n1,1,2,1a          4.785 17.077  8.760 10.487\n                 17.077  6.718 18.563  9.736\n                  8.760 18.563  3.270  8.525\n                 10.487  9.736  8.525 10.253\n\\end{lstlisting}\n\nWhile the model $1,1,2,1a$ produced almost as high a\nlog-likelihood value as model $1,2,1,1a$, the superior\nperformance of the latter model with respect to the \nBox-Ljung statistic might prompt us to consider it the model of choice.\n\nThe following plots show the actual and predicted values for the diagonal variance and\ncorrelation terms. %fixed\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/covarplot11.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/covarplot22.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/covarplot33.png}\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/covarplot44.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot21.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot31.png}\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot32.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot41.png}\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot42.png}\n\n\n\\includegraphics[height=2.5in, width=\\textwidth]{example/corrplot43.png}\n\n\n\\bigskip\n\n\n\\section{Input format}\n\nBy default, the stand-alone version of the model attempts to read in the\ndata from a file named \\texttt{mgarch.dat}.  This can be changed by a command line option.\nA reasonable command line option would be:\n\\begin{lstlisting}\n  mgarch -ind datafile -nox -nohess\n\\end{lstlisting}\nThe command\n\\begin{lstlisting}\n  mgarch -?\n\\end{lstlisting}\nwill print out a list of command line options.\n\nPart of a data file is shown below. The first line describes the data\nand specifies the form of the model. The \\texttt{delta} flag determines whether or not\nthe parameters that measure asymmetric response in the \\textsc{arch} component of the\nmodel are estimated. The robustness number controls the amount of\nrobustness in the likelihood function. A value between~0.0 and~0.5 is\nprobably appropriate. A value of~10,000 is used to indicate missing values\nin the~data.\n\\begin{lstlisting}\n# number of     dimension    p q r s  delta  robustness\n# observations                        flag\n  1301            4          0 0 1 1   0        0\n-0.473592      -0.30815      -0.199577      -0.154677\n0.140859      -0.256788      -0.823379      -0.947582\n-0.80579      -0.833361      2.439394      1.208645\n-1.542773      -0.855767      0.469603      -0.433346\n10000          10000          1.445218      0.462298\n6.014853      4.964597      -0.189343      -0.231408\n-1.064758      -1.700819      -3.143447      0.62605\n-0.608465      -2.618972      1.641306      2.127487\n-5.242424      2.902805      2.60543        -0.668981\n2.205787      2.026769      -1.42811      -0.141505\n // ..........................................\n\n10000           10000        -1.072871      0.365977\n-0.208759      1.51892      -0.59516        -0.029556\n-2.413508      -2.578193      2.045828      -0.2362\n0.890598      0.119672      -0.415587      0.029485\n-2.797967      0.943489      -1.377787      0.283592\n1.405865      1.915963      -0.696567      0.450668\n10000          10000        -0.31709      0.255885\n2.971906      -1.704494      0.835319      0.286408\n-3.451449      1.233715      -1.144007      -0.322157\n1.342827      0.376409      0.279213      0.226602\n\\end{lstlisting}\n\n\n\\section{Output files}\n\nSince the model produces a lot of output, it is a good idea to run it in its own directory,\nso files can be easily deleted. The independent variables of the\noptimization are in a file named \\texttt{mgarch.par}. (\\texttt{mgarch.bar} is an equivalent binary file.)\nA more user-friendly report is in the file \\texttt{mgarch.rep}.\nThe estimated covariances and correlations are in files named \\texttt{covar.XX} and \\texttt{correl.XX}.\n\nThe model selection criteria have identified the model~1.1.1a\nas the best of the models considered for these data.\n\nSome parameters of interest are:\n\\begin{lstlisting}\n# alpha:\n 0.394461 0.538978 1.19337 0.969918\n# A1:\n -0.0531276 0.772529 -0.187692 -0.131215\n 0.0898897 -0.399746 -0.142294 -0.106079\n 0.0740065 0.248345 -0.0629680 -0.212928\n 0.0918460 -0.0575289 -0.0700786 0.0537302\n# B1:\n -0.00719450 -0.344793 0.115020 0.00516664\n -0.0943230 0.474330 0.147845 0.0936166\n -0.0860047 -0.243294 0.0187986 0.217280\n -0.0815394 0.0843289 0.00782384 -0.0539808\n# F:\n -0.109526 -0.0292127 -0.122395 0.0548869\n 0.000332929 -0.0964482 0.0153865 -0.0346829\n -0.0148848 -0.0146167 -0.117961 -0.0529385\n -0.00504663 -0.000547068 0.00413882 -0.133956\n# G:\n 0.930026 -0.269741 0.136401 0.427047\n -0.0345549 -0.981606 0.00281003 -0.00411475\n 0.0976783 -0.0132467 -0.976596 0.0306139\n 0.117971 -0.0134465 0.00647385 -0.955173\n\\end{lstlisting}\nFor the four parameters $\\alpha_i$, a value $<1$ indicates\nthat negative values seem to have a larger effect on changes\nin the covariance structure than do positive ones. This effect seems\nto be much larger in the dollar cross rates than in the\nstock exchanges indices.\n\n\n\\section{The code for the \\textsc{bekkgarch} model}\n\nThe code for the \\textsc{bekkgarch} model follows. Additional\ncomments have been added to the~code.\n\\begin{lstlisting}\nDATA_SECTION\n  // This section describes the data inputs to the model.\n  // By default they are read in from the file bekkgarch.dat.\n  init_int na  // number of time periods\n  init_int m   // dimension of the vector time series\n  init_int p   // degree of autoregression must be >=0\n  init_int q   // degree of moving average mult be >=0\n  init_int ra   // degree of arch must be>=0\n  init_int sg   // degree of arch must be>=0\n  init_int delta_switch // turns on asymmetric response to shocks\n  init_number robustness  // amount of robustness probably something \n              // between 0 and .05 is right\n  int n\n  int msquared \n !!  n=na-p;  // number of obs for conditional likelihood\n  init_matrix cY(-p+1,n,1,m)  // the vector time series of observations\n  int nmiss\n LOC_CALCS \n  msquared=m*m;\n  int ii=0;\n  int j;\n  int i;\n  for (i=-p+1;i<=n;i++)\n    for (j=1;j<=m;j++)\n      if (cY(i,j)==10000) ii++;\n  nmiss=ii;\n END_CALCS \n  ivector rowmiss(1,nmiss)\n  ivector colmiss(1,nmiss)\n LOC_CALCS \n  ii=1;\n  for (i=1;i<=n;i++)\n    for (j=1;j<=m;j++)\n      if (cY(i,j)==10000) {\n        rowmiss(ii)=i;\n        colmiss(ii)=j;\n        ii++;\n      }\n END_CALCS \n  int m1\n  int beginSigma\n  matrix Idm(1,m,1,m)\n  ivector beginF(1,ra)\n  ivector beginG(1,sg)\n  ivector beginA(1,p)\n  ivector beginB(1,q)\n  int nstart\n LOC_CALCS\n  nstart=0;\n  if (nmiss>0) nstart=1;\n  m1=m*(m+1)/2;  // \"size\" of n x n symmetric matrix\n  Idm=identity_matrix(1,m); \n  if (p) beginA.fill_seqadd(1+nstart,1);\n  if (q) beginB.fill_seqadd(p+1+nstart,1);\n  if (ra) beginF.fill_seqadd(p+q+1+nstart,1);\n  if (sg) beginG.fill_seqadd(p+q+1+nstart,1);\n  beginSigma=p+q+1+nstart;\n END_CALCS \nPARAMETER_SECTION\n LOC_CALCS\n  int mm=m;\n  int dstart;\n  if (delta_switch>0)\n    dstart=p+q+2+nstart;\n  else\n    dstart=-1;\n END_CALCS\n  // the initial values for the time series and disturbance as\n  // estimated parameters\n  init_bounded_vector mudev(1,m,-100,100,-1)\n  init_bounded_vector delta(1,m,.1,1.9,dstart)\n  vector mu(1,m)\n  vector esd(1,m)\n  vector muemp(1,m)  // empirical covariance matrix\n  matrix Y(-p+1,n,1,m)  // the vector time series of observations\n  init_matrix_vector A1(1,p,1,mm,1,mm,beginA)  // pars for the AR coff matrices\n  3darray A(1,p,1,m,1,m)  // pars for the AR coff matrices\n  init_matrix_vector B1(1,q,1,mm,1,mm,beginB) // pars for the MA coff matrices\n  3darray B(0,q,1,m,1,m)  // has the additional B(0)=Id\n  3darray Bt(0,q,1,m,1,m)  // has the additional B(0)=Id\n  4darray cov(1,n,0,q,1,m,1,m)  // the m x m blocks for the covariance\n  3darray TB_S(0,q,1,m,1,m)\n  matrix Omega(1,m,1,m)\n  3darray B_S(0,q,1,m,1,m)\n  init_bounded_vector v_Sigma(1,m1,-10,10.1,beginSigma);  // pars for Sigma\n  matrix Semp(1,m,1,m)  \n  matrix SSemp(1,m,1,m)  \n  matrix ch_Sigma(1,m,1,m)  \n  init_bounded_vector_vector Fcoff(1,ra,1,msquared,-1.000,1.0,beginF)  \n  3darray F(1,ra,1,m,1,m)  \n  3darray tF(1,ra,1,m,1,m)  \n  init_bounded_vector_vector Gcoff(1,sg,1,msquared,-.98,.98,beginG)  \n LOC_CALCS\n  if (ra)\n  {\n    int mmin,mmax;\n    mmin=Fcoff(1).indexmin();\n    mmax=Fcoff(1).indexmax();\n    for (int ij=mmin;ij<=mmax;ij++) if (value(Fcoff(1)(ij))==0.0) \n      Fcoff(1)(ij)=0.02;\n  }\n  if (sg)\n  {\n    int mmin,mmax;\n    mmin=Gcoff(1).indexmin();\n    mmax=Gcoff(1).indexmax();\n    for (int ij=mmin;ij<=mmax;ij++) if (value(Gcoff(1)(ij))==0.0) \n      Gcoff(1)(ij)=0.001;\n  }\n END_CALCS\n  3darray G(1,sg,1,m,1,m)  \n  3darray tG(1,sg,1,m,1,m)  \n  3darray Sigma(1,n,1,m,1,m)  \n  init_bounded_vector missvals(1,nmiss,-5.0,5.0);\n  vector arpart(1,m)\n  matrix r(1,n,1,m)\n  3darray rr(1,n,1,m,1,m)\n  vector vecr(1,n*m)   // VEC[r]\n  vector y(1,n*m)\n  number ldet\n  objective_function_value f\n  matrix Yv(-p+1,n,1,m)  // after subtracting off the mean\n !! int q1m=(q+1)*m; \n !!CLASS  banded_symmetric_dvar_matrix S(1,n*m,q1m);\nPROCEDURE_SECTION\n  int t; int i; int j;\n  fill_matrices_with_independent_parameters();\n  Y=cY;\n  add_missing_values();\n  calculate_time_series_mean();\n  calculate_the_residuals(); \n  calculate_the_empirical_covariance();\n  SSemp=get_initial_sigma();\n  dvariable fpen=calculate_the_sub_variances_BEKK();\n  calculate_the_sub_covariances();\n  calculate_the_covariance_matrix();\n  int ierr=0;\n  // choleski decomposition of a banded symmetric matrix\n  // produces a banded lower triangular matrix\n  dvariable fpen1=0.0;\n  banded_lower_triangular_dvar_matrix blt=choleski_decomp_positive(S,\n    1.e-6,fpen1);\n  fpen+=fpen1;\n  // solve for y=inv(blt)*vecr\n  y=solve(blt,vecr);\n  int ss=0;\n  dvariable lno=ln_det(Sigma(1),ss);\n  f+=norm2(log(delta));\n  for (i=1;i<=q;i++) f+=norm2(B1(i));\n  f+=norm2(v_Sigma);\n  for (i=1;i<=ra;i++) f+=norm2(F(i));\n  for (i=1;i<=sg;i++) f+=norm2(G(i));\n  dvariable lndet=0.0;\n  for (i=1;i<=n*m;i++) lndet+=log(blt(i,i)); \n  // robust log-likelihood function -- mixture of normal and \n  // tiny bit of cauchy \n  dvar_vector y2= square(y);\n  if (robustness>1.e-20)  \n    f+= lndet - sum(log(mfexp(-0.5*y2)+robustness/(1.0+y2)));\n  else\n    f+= lndet - sum(log(mfexp(-0.5*y2)+.0001/(1.0+y2)));\n\n  f+=fpen;\n  (*ad_printf)(\"f = %lf\\n\",value(f));\nFUNCTION fill_matrices_with_independent_parameters\n  int ii=1; int i=1; int iii;\n  double d=sqrt(0.1);\n  if  (!sg) d=1.0;\n  ch_Sigma.initialize();\n  // this is the choleski decomp parameterization of the\n  // covariance matrix\n  for (i=1;i<=m;i++) \n    for (int j=1;j<=i;j++) {\n      if (i==j)ch_Sigma(i,i)+=d;\n      ch_Sigma(i,j)+=v_Sigma(ii++);\n    }   \n  for (iii=1;iii<=ra;iii++) {\n    if (iii==1 || active(Fcoff(iii))) {\n      ii=1;\n      F(iii).initialize();\n      tF(iii).initialize();\n      for (i=1;i<=m;i++) {\n        for (int j=1;j<=m;j++) \n          F(iii)(i,j)=Fcoff(iii)(ii++);\n      }\n    }\n    tF(iii)=trans(F(iii));\n  } \n\n  for (iii=1;iii<=sg;iii++) {\n    if (iii==1 || active(Gcoff(iii))) {\n      ii=1;\n      G(iii).initialize();\n      tG(iii).initialize();\n      for (i=1;i<=m;i++) {\n        for (int j=1;j<=m;j++) {\n          G(iii)(i,j)=Gcoff(iii)(ii++);\n        }   \n        if (iii==1) G(iii)(i,i)+=0.90;\n      }\n    }\n    tG(iii)=trans(G(iii));\n  }\n  B.initialize();\n  A.initialize();\n  // B(0) is the identity matrix\n  B(0)=Idm;\n  for (i=1;i<=p;i++) A(i)=A1(i);\n  for (i=1;i<=q;i++) B(i)=B1(i);\n  for (i=0;i<=q;i++) Bt(i)=trans(B(i));\n  \nFUNCTION calculate_the_residuals \n  int t; int j;\n  mu=muemp+mudev;\n  for (t=-p+1;t<=0;t++) Yv(t)=Y(t)-mu;\n  for (t=1;t<=n;t++) {\n    Yv(t)=Y(t)-mu;\n    calculate_autoregressive_part(t);\n    r(t)=Yv(t)-arpart;\n  }\n  int ii=0;\n  // this corresponds to the VEC operator\n  for (int i=1;i<=n;i++) \n    for (j=1;j<=m;j++) vecr(++ii)=r(i,j);\n  \nFUNCTION void calculate_the_residuals2(dvar_matrix& e)\n  int t; int j;\n  mu=muemp+mudev;\n  for (t=-p+1;t<=0;t++) Yv(t)=Y(t)-mu;\n  for (t=1;t<=n;t++) {\n    Yv(t)=Y(t)-mu;\n    calculate_autoregressive_part(t);\n    e(t)=Yv(t)-arpart;\n    for (j=1;j<=q;j++) {\n      if (t<=j) break;\n      e(t)-=B(j)*e(t-j);\n    }  \n  }\n  \nFUNCTION calculate_the_sub_covariances\n  int i; int k; int l;\n  int qq=0;\n  for ( l=1;l<=q;l++) {\n    if (!active(B1(l))) break;\n    qq=l;\n  }\n  cov.initialize();\n  for (i=1;i<=n;i++) {\n    for (int l=0;l<=qq;l++) {\n      if (i<=l) break;\n      for (int k=0;k<=qq-l;k++) {\n        int ilk=i-l-k;\n        if (ilk<1) ilk=1;\n        cov(i,l)+=B(l+k)*Sigma(ilk)*Bt(k);\n      }\t\n    }\n  }  \t\n  \nFUNCTION calculate_the_empirical_covariance\n  int i;\n  Semp.initialize();\n  ivector sgn(1,m);\n  esd.initialize();\n  for (i=1;i<=n;i++) {\n    esd+=square(r(i));\n  }\n  esd/=n;\n  esd=sqrt(esd);\n  if (active(delta)) {\n    dvar_vector mult_neg=elem_div(esd,delta);\n    dvar_vector mult_pos=elem_prod(esd,delta);\n    for (i=1;i<=n;i++) {\n      sgn.initialize();\n      dvar_vector sr=sfabs(elem_div(r(i),esd));\n      for (int j=1;j<=m;j++)\n        if (r(i,j)<0) \n          sr(j)=-sr(j)*mult_neg(j);\n        else\n          sr(j)=sr(j)*mult_pos(j);\n      rr(i)=outer_prod(sr,sr);\n    }\n    Semp=empirical_covariance(r);\n  }\n  else\n  {\n    for (i=1;i<=n;i++) {\n      rr(i)=outer_prod(r(i),r(i));\n      Semp+=rr(i);\n    }\n    Semp/=n;\n  }\n  for (int j=1;j<=m;j++)\n    esd(j)=sqrt(Semp(j,j));\n  \n  \nFUNCTION dvariable calculate_the_sub_variances_diagonal_vector_garch(void)\n  int i; int k; int ii; int jj;\n  dvar_vector norms(1,n);\n  dvariable fpen=0.0;\n  dvariable fpen1;\n  Omega=ch_Sigma*SSemp*trans(ch_Sigma);\n  Sigma.initialize();\n  // set the first Sigma equal to the empirical covariance\n  int rsmax=mymax(ra,sg);\n  Sigma(1)=SSemp;\n  //cout << Sigma(1) << endl;\n  dvar_matrix SS=scale(Sigma(1),esd);\n  //cout << SS << endl;\n  fpen+=positivize_sigma(SS);\n  //cout << SS << endl;\n  dvariable ns=norm(SS);\n   norms(1)=ns;\n  fpen1=0.0;\n  dvariable bn=mf_upper_bound(ns,1000.0,fpen1);\n  if (fpen1>0.0) {\n    SS*=(bn/ns);\n    fpen+=fpen1;\n  }\n  Sigma(1)=unscale(SS,esd);\n  for (i=2;i<=rsmax;i++) {\n    Sigma(i)=Sigma(1);\n    norms(i)=norms(1);\n  }\n\n  int mmin=Sigma(1).indexmin(); \n  int mmax=Sigma(1).indexmax(); \n  dvar_vector s(mmin,mmax);\n  for (i=rsmax+1;i<=n;i++) {\n    Sigma(i)=Omega;\n    if (ra) Sigma(i)+=elem_prod(F(1),rr(i-1));\n    for (ii=2;ii<=ra;ii++) {\n      if (active(Fcoff(ii)))\n        Sigma(i)+=elem_prod(F(ii),rr(i-ii));\n    }\n    \n    if (sg) Sigma(i)+=elem_prod(G(1),Sigma(i-1));\n    for (ii=2;ii<=sg;ii++) {\n      if (active(Gcoff(ii)))\n        Sigma(i)+=elem_prod(G(ii),Sigma(i-ii));\n    }\n    \n    // \"positivize\" the\n    // correlation matrix\n    dvar_matrix SS=scale(Sigma(i),esd);\n    fpen+=positivize_sigma(SS);\n    dvariable ns=norm(SS);\n    norms(i)=ns;\n    fpen1=0.0;\n    dvariable bn=mf_upper_bound(ns,1000.0,fpen1);\n    if (fpen1>0.0) {\n      SS*=(bn/ns);\n      fpen+=fpen1;\n    }\n    Sigma(i)=unscale(SS,esd);\n  }\n  dvector trend(1,n);\n  trend.fill_seqadd(-1,2.0/(n-1));\n  cout << \"norms*trend/norm(norms)\" << endl; \n  dvariable npen=norms*trend/norm(norms); \n  cout << norms*trend/norm(norms) << endl; \n  fpen+=npen;\n  if (fpen>1.0)\n    cout << \" fpen = \" << fpen << endl;\n  return fpen;\n  \nFUNCTION dvariable calculate_the_sub_variances_BEKK(void)\n  int i; int k; int ii; int jj;\n  dvar_vector norms(1,n);\n  dvariable fpen=0.0;\n  dvariable fpen1;\n  Omega=ch_Sigma*SSemp*trans(ch_Sigma);\n  Sigma.initialize();\n  // set the first Sigma equal to the empirical covariance\n  int rsmax=mymax(ra,sg);\n  Sigma(1)=SSemp;\n  dvar_matrix SS=scale(Sigma(1),esd);\n  fpen+=positivize_sigma(SS);\n  dvariable ns=norm(SS);\n   norms(1)=ns;\n  fpen1=0.0;\n  dvariable bn=mf_upper_bound(ns,1000.0,fpen1);\n  if (fpen1>0.0) {\n    SS*=(bn/ns);\n    fpen+=fpen1;\n  }\n  Sigma(1)=unscale(SS,esd);\n  for (i=2;i<=rsmax;i++) {\n    Sigma(i)=Sigma(1);\n    norms(i)=norms(1);\n  }\n\n  int mmin=Sigma(1).indexmin(); \n  int mmax=Sigma(1).indexmax(); \n  dvar_vector s(mmin,mmax);\n  for (i=rsmax+1;i<=n;i++) {\n    Sigma(i)=Omega;\n    if (ra) Sigma(i)+=F(1)*rr(i-1)*tF(1);\n    for (ii=2;ii<=ra;ii++) {\n      if (active(Fcoff(ii)))\n        Sigma(i)+=F(ii)*rr(i-ii)*tF(ii);\n    }\n    \n    if (sg) Sigma(i)+=G(1)*Sigma(i-1)*tG(1);\n    for (ii=2;ii<=sg;ii++) {\n      if (active(Gcoff(ii)))\n        Sigma(i)+=G(ii)*Sigma(i-ii)*tG(ii);\n    }\n    \n    // \"positivize\" the\n    // correlation matrix\n    dvar_matrix SS=scale(Sigma(i),esd);\n    fpen+=positivize_sigma(SS);\n    dvariable ns=norm(SS);\n    norms(i)=ns;\n    fpen1=0.0;\n    dvariable bn=mf_upper_bound(ns,1000.0,fpen1);\n    if (fpen1>0.0) {\n      SS*=(bn/ns);\n      fpen+=fpen1;\n    }\n    Sigma(i)=unscale(SS,esd);\n  }\n  dvector trend(1,n);\n  trend.fill_seqadd(-1,2.0/(n-1));\n  cout << \"norms*trend/norm(norms)\" << endl; \n  dvariable npen=norms*trend/norm(norms); \n  cout << norms*trend/norm(norms) << endl; \n  fpen+=npen;\n  if (fpen>1.0)\n    cout << \" fpen = \" << fpen << endl;\n  {\n    //ofstream ofs(\"sigma\");\n    \n    //for (int i=1;i<=n;i++)\n      //ofs << Sigma(i) << endl << endl;\n  }\n  return fpen;\n  \nFUNCTION dvar_matrix scale(dvar_matrix& M,dvar_vector& sd)\n   int mmin=sd.indexmin();\n   int mmax=sd.indexmax();\n   dvar_matrix SM(mmin,mmax,mmin,mmax);\n   for (int i=mmin;i<=mmax;i++)\n     for (int j=mmin;j<=mmax;j++)\n       SM(i,j)=M(i,j)/(sd(i)*sd(j));\n   return SM;\n       \nFUNCTION dvar_matrix unscale(dvar_matrix& M,dvar_vector& sd)\n   int mmin=sd.indexmin();\n   int mmax=sd.indexmax();\n   dvar_matrix SM(mmin,mmax,mmin,mmax);\n   for (int i=mmin;i<=mmax;i++)\n     for (int j=mmin;j<=mmax;j++)\n       SM(i,j)=M(i,j)*(sd(i)*sd(j));\n   return SM;\n       \nFUNCTION dvar_matrix get_initial_sigma(void)\n   int i,j,k,l,ll,m2,r,s;\n   m2=m*m;\n   dvar_matrix M(1,m2,1,m2);\n   \n   dvar_vector v=VEC(Semp);\n   M=identity_matrix(1,m2);\n   for (ll=1;ll<=q;ll++) \n   {\n     for (i=1;i<=m;i++) \n     {\n       for (j=1;j<=m;j++) \n       {\n         int col=(i-1)*m+j;\n         for (r=1;r<=m;r++)\n         {\n           for (s=1;s<=m;s++) \n           {\n             int row=(r-1)*m+s;\n             M(row,col)+=B(ll)(r,i)*B(ll)(s,j);\n           }\n         }\n       }\n     }\n   } \n   v=solve(M,v);\n   dvar_matrix tmp= MAT(v,m,m);\n   return tmp;\n  \nFUNCTION calculate_the_covariance_matrix\n  int ioffset; int joffset; int i1; int i; int j1;\n  int k; int l;\n  int qq=0;\n  for ( l=1;l<=q;l++) {\n    if (!active(B1(l))) break;\n    qq=l;\n  }\n  S.initialize();\n  for (i=1;i<=n;i++) {\n    ioffset=(i-1)*m;  \n    for (int k=0;k<=qq;k++) {\n      //if (k>0 && !active(B1)) break;\n      joffset=(i-k-1)*m;  \n      if (joffset<0) break;\n      for (i1=1;i1<=m;i1++) {  \n        int up;\n        if (k==0) \n\t  up=i1;\n\telse  \n\t  up=m;\n        for (j1=1;j1<=up;j1++) {  \n          int i2=i1+ioffset;\n\t  int j2=j1+joffset;\n          S(i1+ioffset,j1+joffset)=cov(i,k,i1,j1);\n        }  \t\n      }  \n    }    \n    if (S(1,1) < 0)\n      cout << S(1,1) << endl;\n  }\n\nFUNCTION void calculate_autoregressive_part(int t)\n  // The user can put in any (nonlinear) function desired here\n  arpart.initialize();\n  for (int j=1;j<=p;j++) arpart+=A(j)*Yv(t-j);\n  \nREPORT_SECTION\n  int i; int ii; int jj, t;\n  for (ii=1;ii<=m;ii++)  \n  {\n    for (jj=1;jj<=ii;jj++)  \n    {\n      ofstream ofs((char*)(\"covar.\" + str(ii) +str(jj)));\n      ofstream ofs1((char*)(\"correl.\" + str(ii) +str(jj)));\n      dvar_matrix Covariance(1,m,1,m);\n      for (i=1;i<=n;i++) {\n        Covariance=Sigma(i);\n        for(int j=1;j<=q;j++)\n          if ( (i-j)>0 ) Covariance+=B(j)*Sigma(i-j)*trans(B(j));\n        ofs << Covariance(ii,jj) << endl;\n        ofs1 << Covariance(ii,jj)/\n          sqrt(Covariance(ii,ii)*Covariance(jj,jj))<< endl;\n      }\n    }\n  }\n  \n  {\n    dvar_matrix ymat=MAT(y,n,m);\n    for (int i=1;i<=m;i++) {\n       ofstream ofs1((char*)(\"yres.\" + str(i)));\n       dvector tmp(1,n);\n       for (t=1;t<=n;t++) \n         tmp(t)=value(ymat(t,i));\n       ivector hist=histogram(-20,20,81,tmp);\t \n         ofs1 << column_print(hist) << endl;\n    }  \n  }   \n  report << \"The means\" << endl;\n  report << mu << endl;\n  for (i=1;i<=p;i++) {\n    report  << \"A(\"<< i << \")\" << endl;\n    report << setfixed() << setprecision(3) << A(i) << endl;\n  }  \n  report << endl;\n  for (i=1;i<=q;i++) {\n    report  << \"B(\"<< i << \")\" << endl;\n    report << setfixed() << setprecision(3) << B(i) << endl;\n  }  \n  report << endl;\n  report  << \"delta\" << endl;\n  report << setfixed() << setprecision(3) << delta << endl;\n  report << endl;\n  report  << \"Omega\" << endl;\n  report << setfixed() << setprecision(3) << Omega << endl;\n  report << endl;\n  for (i=1;i<=ra;i++) {\n    report  << \"F(\"<< i << \")\" << endl;\n    report << setfixed() << setprecision(3) << F(i) << endl;\n  }  \n  report << endl;\n  for (i=1;i<=sg;i++) {\n    report  << \"G(\"<< i << \")\" << endl;\n    report << setfixed() << setprecision(3) << G(i) << endl;\n  }  \n  report << endl;\n  //report << setfixed() << setw(8) << setprecision(1) << S << endl;\n  {  // calculate predicted observations for next 20 time periods\n     // for graphs  results are in t.1 t.2 etc\n     int npreds=20;\n     dvar_matrix e(1,n,1,m);\n     calculate_the_residuals2(e);\n   \n     dvar_matrix Z(n+1,n+npreds,1,m);\n     Z.initialize();\n   \n     for (int t=n+1;t<=n+npreds;t++) {\n       Z(t)+=mu;\n       for (int i=1;i<=p;i++) {\n         if (t-i>n)\n           Z(t)+=A(i)*(Z(t-i)-mu); \n         else \n           Z(t)+=A(i)*(Y(t-i)-mu); \n       }\n       for (i=1;i<=q;i++) {\n         if (t-i<=n && t-i>0)\n           Z(t)+=B(i)*e(t-i); \n       }\t   \n     }  \t \n     for (i=1;i<=m;i++) {\n       ofstream ofs1((char*)(\"pred\" + str(i)));\n       for (t=-p+1;t<=n;t++) \n         ofs1 << Y(t,i) << endl;\n       for (t=n+1;t<=n+npreds;t++) \n         ofs1 << Z(t,i) << endl;\n     }  \n   }  \n   dmatrix T(1,m,1,m);\n   dmatrix chi(1,m,1,m);\n   T.initialize();\n   dmatrix Aut(1,m,1,m);\n   Aut.initialize();\n   const int K=10;\n   d3_array gamma(1,K,1,m,1,m);\n   dmatrix cr(1,n,1,m);\n   for (i=1;i<=n;i++)\n   {\n     cr(i)=value(y((i-1)*m+1,i*m).shift(1));\n     T+=outer_prod(cr(i),cr(i));\n   }\n   T=T/n;\n   for (i=2;i<=n;i++)\n   {\n     Aut+=outer_prod(cr(i-1),cr(i));\n   }\n   Aut=Aut/(n-1);\n   for (i=1;i<=m;i++)\n   {\n     for (int j=1;j<=m;j++)\n     {\n       Aut(i,j)/=sqrt(T(i,i)*T(j,j));\n     }\n   }\n   gamma.initialize();\n   for (int j=1;j<=m;j++)\n   {\n     for (int k=1;k<=m;k++)\n     {\n       for (int l=1;l<=10;l++)\n       {\n         double tmp=0;\n         for (i=1;i<=n-l;i++)\n         {\n           gamma(l,j,k)+=(cr(i,j)*cr(i,k)-T(j,k))*(cr(i+l,j)*cr(i+l,k)-T(j,k));\n           tmp+=square(cr(i,j)*cr(i,k)-T(j,k));\n         }\n         gamma(l,j,k)/=tmp;\n       }\n     }\n   }\n \n   chi.initialize();\n   for (int l=1;l<=K;l++)\n   {\n     chi+=n*(n+2)/(n-l)*square(gamma(l));\n   }\n   \n   report << \"Covariance of standardized residuals\" << endl;\n   report << T << endl;\n   report << \"Lag 1 autocorellation of standardized residuals\" << endl;\n   report << Aut << endl;\n   report << \"Ljung Box statistic based on chi squared with \" << K  \n          << \" degrees of freedom\" << endl;\n   report << chi << endl;\n    \nFUNCTION add_missing_values\n  for (int ii=1;ii<=nmiss;ii++) { \n    Y(rowmiss(ii),colmiss(ii))=missvals(ii);\n  }  \t  \n  ofstream ofs(\"testy\");\n  ofs << Y << endl;\n  \nFUNCTION calculate_time_series_mean\n  muemp.initialize();\n  for (int i=-p+1;i<=n;i++) muemp+=Y(i);\n  muemp/=(n+p);\n  \nFUNCTION dvariable positivize_sigma(dvar_matrix& TS)\n  int ii,jj;\n  dvariable fpen=0.0;\n  int mmin=TS.indexmin();\n  int mmax=TS.indexmax();\n  dvar_vector s(mmin,mmax);\n  for (ii=mmin;ii<=mmax;ii++)\n    s(ii)=sqrt(posfun(TS(ii,ii),1.e-3,fpen));\n  for (ii=mmin;ii<=mmax;ii++)\n    for (jj=mmin;jj<=mmax;jj++) \n      TS(ii,jj)/=(s(ii)*s(jj));\n  TS=positive_definite_matrix(TS,.3,fpen);\n  for (ii=mmin;ii<=mmax;ii++)\n    for (jj=mmin;jj<=mmax;jj++) \n      TS(ii,jj)*=(s(ii)*s(jj));\n  return fpen;\n\nGLOBALS_SECTION\n  // some C++ compilers don't supply this!\n  int mymax(int x,int y)\n  {\n    if (x>y) \n      return x;\n    else\n      return y;\n  }\n\nTOP_OF_MAIN_SECTION\n  \n  ofstream ofs(\"Error.log\");\n  arrmblsize=5000000;  \n  gradient_structure::set_GRADSTACK_BUFFER_SIZE(560000);\n  gradient_structure::set_CMPDIF_BUFFER_SIZE(15000000);\n  gradient_structure::set_MAX_NVAR_OFFSET(1000);\n\\end{lstlisting}\n\n", "meta": {"hexsha": "b8040a5539141e90f71a22e4bad9167e96a0b1fb", "size": 35504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manuals/admb/magarch-april2000.tex", "max_stars_repo_name": "johnrsibert/admb", "max_stars_repo_head_hexsha": "063ec863a9f23f6c6afbc7d481af0476b8d63645", "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/magarch-april2000.tex", "max_issues_repo_name": "johnrsibert/admb", "max_issues_repo_head_hexsha": "063ec863a9f23f6c6afbc7d481af0476b8d63645", "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/magarch-april2000.tex", "max_forks_repo_name": "johnrsibert/admb", "max_forks_repo_head_hexsha": "063ec863a9f23f6c6afbc7d481af0476b8d63645", "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": 30.4755364807, "max_line_length": 158, "alphanum_fraction": 0.6179585399, "num_tokens": 12479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370423, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6146315645447551}}
{"text": "\\chapter{Normalised LMS and Affine Projection Algorithm}\n\\label{ch:NLMS_APA}\n\\section{Review of the Basics}\n\\subsection{Inversion of a 2 by 2 Block Matrix}\nLet $\\vect{A}$ and $\\vect{M}_1=\\vect{D}-\\vect{C}\\vect{A}^{-1}\\vect{B}$ be non-singular matrices. Then\n\\bmath\n  \\bbmtx\n    \\vect{A} & \\vect{B}\\\\\n    \\vect{C} & \\vect{D}\n  \\ebmtx^{-1} =\n  \\bbmtx\n    \\vect{A}^{-1}+\\vect{A}^{-1}\\vect{B}\\vect{M}_1^{-1}\\vect{C}\\vect{A}^{-1} & -\\vect{A}^{-1}\\vect{B}\\vect{M}_1^{-1}\\\\\n    -\\vect{M}_1^{-1}\\vect{C}\\vect{A}^{-1} & \\vect{M}_1^{-1}\n  \\ebmtx\\ .\n  \\label{eq:block_inv1}\n\\emath\nLet instead $\\vect{D}$ and $\\vect{M}_2=\\vect{A}-\\vect{B}\\vect{D}^{-1}\\vect{C}$ be non-singular matrices. Then\n\\bmath\n  \\bbmtx\n    \\vect{A} & \\vect{B}\\\\\n    \\vect{C} & \\vect{D}\n  \\ebmtx^{-1} =\n  \\bbmtx\n    \\vect{M}_2^{-1} & -\\vect{M}_2^{-1}\\vect{B}\\vect{D}^{-1}\\\\\n    -\\vect{D}^{-1}\\vect{C}\\vect{M}_2^{-1} & \\vect{D}^{-1}+\\vect{D}^{-1}\\vect{C}\\vect{M}_2^{-1}\\vect{B}\\vect{D}^{-1}\n  \\ebmtx\\ .\n  \\label{eq:block_inv2}\n\\emath\nThe matrices $\\vect{M}_1$ and $\\vect{M}_2$ are said to be the \\textit{Schur complement} of $\\vect{A}$ and $\\vect{D}$, respectively.\n\n\\subsection{The Method of Lagrange Multipliers}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/const_opt}\n  \\caption{Optimisation problem with a single equality constraint. The points $\\vect{x}_u$ and $\\vect{x}_c$ are the unconstrained and the constrained minimum, respectively.}\n  \\label{fig:const_opt}\n\\end{figure}\n\\noindent The method of Lagrange multipliers can be used to solve optimisation problems with equality constraints\\footnote{The method of Lagrange multipliers can also be used to solve the more general problem with inequality constraints, but we do not consider this here.}\n\\begin{gather}\n  \\begin{alignedat}{2}\n      &\\underset{\\vect{x}}{\\text{optimise}} &\\quad f(\\vect{x}) &\\\\\n      &\\text{subject to}&\\quad \\vect{h}(\\vect{x}) &= \\vect{0}\n  \\end{alignedat}\n  \\label{eq:constr_opt}\n\\end{gather}\nConsider the optimisation problem in Fig.~\\ref{fig:const_opt} with the cost function $f(\\vect{x})$ and the constraints $\\vect{h}(\\vect{x})=\\vect{0}$. At the constrained optimum $\\vect{x}_c$, the gradients of $f(\\vect{x})$ and $\\vect{h}(\\vect{x})$ are parallel. Thus,\n\\begin{alignat*}{2}\n  \\vect{\\nabla}f(\\vect{x}) &= \\lambda \\vect{\\nabla}h(\\vect{x}) &\\qquad &\\text{(single constraint)}\\\\\n  \\vect{\\nabla}f(\\vect{x}) &= \\sum_{m=1}^M\\lambda_m \\vect{\\nabla}h_m(\\vect{x})= \\vect{\\nabla}\\vect{h}(\\vect{x})\\vect{\\lambda} &\\qquad &\\text{(multiple constraints)}\n\\end{alignat*}\nThe vector $\\vect{\\lambda}$ contains the Lagrange multipliers, and they ensure that the gradients have the same direction and length.\n\nIf we define the Lagrangian function\n\\bmath\n  L(\\vect{x},\\vect{\\lambda}) = f(\\vect{x}) - \\vect{\\lambda}^T\\vect{h}(\\vect{x})\\ ,\n\\emath\nthen its critical points satisfy\n\\begin{alignat}{2}\n  \\vect{\\nabla}_{\\vect{x}} L(\\vect{x},\\vect{\\lambda}) &= \\vect{0}\\quad\\iff&\\quad\\vect{\\nabla}f(\\vect{x}) &= \\vect{\\nabla}\\vect{h}(\\vect{x})\\vect{\\lambda}\\label{eq:grad_lagr_func}\\\\\n  \\vect{\\nabla}_{\\vect{\\lambda}} L(\\vect{x},\\vect{\\lambda}) &= \\vect{0}\\quad\\iff&\\quad\\vect{h}(\\vect{x}) &= \\vect{0}\\ .\\label{eq:grad_lagr_func_const}\n\\end{alignat}\n\\eq{eq:grad_lagr_func} is the same as what we previously derived from Fig.~\\ref{fig:const_opt}, and \\eq{eq:grad_lagr_func_const} is simply the constraints of our optimisation problem. Thus, the solutions to the system of equations given by \\eq{eq:grad_lagr_func} and \\eq{eq:grad_lagr_func_const} are indeed the critical points of our optimisation problems. In order to find the optimum, we need to classify the critical points as either minimums, maximums, or saddle points. The classification of the critical points for any pair of cost function and constraints is beyond the scope of these lecture notes. We refer the interested reader to \\cite[pp.~294--308]{Antoniou2007}. Alternatively, we may formulate the constrained optimisation problem in \\eq{eq:constr_opt} as the sequential unconstrained optimisation problem \\cite[ch.~5]{Boyd2004}\n\\bmath\n  \\max_{\\vect{\\lambda}}\\left\\{\\underset{\\vect{x}}{\\text{optimise}}\\ L(\\vect{x},\\vect{\\lambda}) \\right\\}\\ .\n  \\label{eq:constr_opt_nested}\n\\emath\nWe could solve this optimisation problem by applying the five step recipe for unconstrained optimisation in Sec.~\\ref{ssec:optimisation} to first the inner optimisation problem and then the outer optimisation problem.\n\nWe are here not concerned with these general methods. Instead, we consider the simpler problem of minimising a quadratic cost function with linear equality constraints.\n\n\\subsubsection{Quadratic Cost Function with Linear Equality Constraints}\nWe consider the following equality constrained minimisation problem\n\\begin{gather}\n  \\begin{alignedat}{2}\n      &\\min_{\\vect{x}} &\\quad f(\\vect{x}) &= \\frac{1}{2}\\vect{x}^T\\vect{Px}+\\vect{q}^T\\vect{x}+r\\\\\n      &\\text{subject to}&\\quad \\vect{h}(\\vect{x}) &= \\vect{Ax}-\\vect{b}=\\vect{0}\n  \\end{alignedat}\n  \\label{eq:constr_opt_quad_lin}\n\\end{gather}\nin which the cost function is quadratic and the equality constraints are linear. We assume that $\\vect{P}$ is an $N\\times N$ p.d. matrix so that $f(\\vect{x})$ is a convex function. Moreover, we assume that $\\vect{A}$ is a full rank $M\\times N$ matrix with $M\\leq N$. The Langrangian function is \n\\bmath\n  L(\\vect{x},\\vect{\\lambda}) = \\frac{1}{2}\\vect{x}^T\\vect{Px}+\\vect{q}^T\\vect{x}+\\vect{r} - \\vect{\\lambda}^T(\\vect{Ax}-\\vect{b})\n\\emath\nand its gradient w.r.t. $\\vect{x}$ is\n\\bmath\n  \\vect{\\nabla}_{\\vect{x}} L(\\vect{x},\\vect{\\lambda}) = \\vect{Px}+\\vect{q}-\\vect{A}^T\\vect{\\lambda}\\ .\n\\emath\nThe system of equations given by \\eq{eq:grad_lagr_func} and \\eq{eq:grad_lagr_func_const} are therefore\n\\bmath\n  \\bbmtx\n     \\vect{P} & -\\vect{A}^T\\\\\n    -\\vect{A} &  \\vect{0}\n  \\ebmtx\n  \\bbmtx\n    \\vect{x}\\\\\n    \\vect{\\lambda}\n  \\ebmtx = \n  \\bbmtx\n    -\\vect{q}\\\\\n    -\\vect{b}\n  \\ebmtx\\ .\n\\emath\nSince the cost function $f(\\vect{x})$ is assumed to be convex, there is only one point satisfying this system of equations. By using the $2\\times 2$ block matrix inversion rule in \\eq{eq:block_inv1}, we obtain that this point $(\\vect{x}_c,\\vect{\\lambda}_c)$ is\n\\begin{align}\n  \\vect{\\lambda}_c &= (\\vect{AP}^{-1}\\vect{A}^T)^{-1}(\\vect{AP}^{-1}\\vect{q}+\\vect{b})\\label{eq:constr_opt_quad_lin_minlam}\\\\\n  \\vect{x}_c &= \\vect{P}^{-1}(\\vect{A}^T\\vect{\\lambda}_c-\\vect{q})\\ .\n  \\label{eq:constr_opt_quad_lin_minx}\n\\end{align}\nThus, the solution to the constrained minimisation problem in \\eq{eq:constr_opt_quad_lin} is $\\vect{x}_c$ given by \\eq{eq:constr_opt_quad_lin_minx}.\n\n\\section{Overview over Adaptive Filters based on the Mean-Squared Error Cost Function}\nAn overview over the adaptive filters is shown in Fig.~\\ref{fig:overview}. Recall that we have the following important properties for the steepest descent algorithm and the stochastic gradient methods.\n\\subsubsection{Steepest Descent (SD)}\n\\begin{itemize}\n  \\item Since the statistics is assumed known, the gradient and filter coefficients are deterministic functions.\n  \\item SD is of limited practical usage, but illustrates nicely how adaptive filters function an how they are analysed.\n  \\item SD is the \"ideal\" (first-order) adaptive filter.\n\\end{itemize}\n\\subsubsection{Stochastic Gradient Methods (SGMs)}\n\\begin{itemize}\n  \\item Since the statistics is unknown, the gradient and filter coefficients are stochastic processes.\n  \\item They are generally easy to implement and hard to analyse.\n  \\item They are approximations to the steepest descent algorithm.\n\\end{itemize}\n\n\\subsection{Model for the Analysis of SGMs}\n\\label{ssec:analysis_model}\nIn order to make the SGMs easier to analyse, a model is typically assumed for the relationship between the input signal $u(n)$ and the desired signal $d(n)$. Fig.~\\ref{fig:sys_id_block_diagram} shows one of the most popular models used for the analysis of adaptive filters.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/sys_id_block_diagram}\n  \\caption{Block diagram showing the model used to analyse adaptive filters.}\n  \\label{fig:sys_id_block_diagram}\n\\end{figure}\nDefine\n\\begin{align}\n  \\vect{w}_o &= \\bbmtx w_{o,0} & \\cdots & w_{o,M-1} \\ebmtx^T\\\\\n  \\vect{w}(n) &= \\bbmtx w_0(n) & \\cdots & w_{M-1}(n) \\ebmtx^T\\\\\n  \\vect{u}(n) &= \\bbmtx u(n) & \\cdots & u(n-M+1) \\ebmtx^T\\\\\n  \\vect{\\Delta}\\vect{w}(n) &= \\vect{w}_o-\\vect{w}(n)\n\\end{align}\nwhere $\\vect{\\Delta}\\vect{w}(n)$ is referred to as the weight error.\n\\subsubsection{Assumptions}\nFrom Fig.~\\ref{fig:sys_id_block_diagram}, we have that\n\\bmath\n  d(n) = z(n)+v(n) = \\vect{u}^T(n)\\vect{w}_o + v(n)\\ .\n\\emath\nMoreover, we assume that\n\\begin{enumerate}\n  \\item $v(n)$ is white noise with variance $\\sigma_v^2$.\n  \\item $v(n)$ and $u(n)$ are uncorrelated.\n  \\item $\\vect{u}(n)$ is a white process with correlation matrix $\\vect{R}_u$. This assumption implies that $\\vect{u}(n)$ and $\\vect{w}(n)$ are uncorrelated.\n\\end{enumerate}\n\\subsubsection{Equations}\nWe have that\n  \\begin{align}\n    e(n) &= d(n) - y(n) =  v(n) + \\vect{u}^T(n)\\vect{w}_o - \\vect{u}^T(n)\\vect{w}(n)\\\\\n         &= \\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n)+ v(n)\n  \\end{align}\nThus, at the optimum where $\\vect{\\Delta}\\vect{w}(n)=\\vect{0}$, we have that\n\\bmath\n  J_1(\\vect{w}_o) = J_\\textup{min} = J_1(v^2(n)) = \\sigma_v^2\\ .\n\\emath\nThe cost function can be written as\n\\begin{align}\n  J_1(\\vect{w}(n)) &= E[e^2(n)] = E[v^2(n)] + E[\\vect{\\Delta}\\vect{w}^T(n)\\vect{u}(n)\\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n)]\\notag\\\\\n  &= \\sigma_v^2 + E[E[\\vect{\\Delta}\\vect{w}^T(n)\\vect{u}(n)\\vect{u}^T(n)\\vect{\\Delta}\\vect{w}(n)|\\vect{\\Delta}\\vect{w}(n)]]\\notag\\\\\n  &= J_\\textup{min} + E[\\vect{\\Delta}\\vect{w}^T(n)\\vect{R}_u\\vect{\\Delta}\\vect{w}(n)]\\ .\n\\end{align}\nWhen viewed as a function of $n$, the cost function is called the learning curve.\n\n\\subsection{How to Analyse Adaptive Filters}\nAdaptive filters can be analysed in several ways.\n\\begin{description}\n  \\item[Transient Performance] How does the filter handle an abrupt change in the statistics of $u(n)$, and how fast does it converge to steady-state?\n  \\item[Steady-state Performance] How does the filter perform in a WSS environment after all transients have died out?\n  \\item[Tracking Performance] How does the filter handle slow variations in the statistics of $u(n)$ and/or $d(n)$?\n  \\item[Numerical Precision Effects] What happens when the filter is implemented on a finite precision computer?\n  \\item[Computational Complexity] How much processing time does the algorithm require?\n\\end{description}\n\\subsubsection{Important Values and Functions}\nWhen analysing adaptive filters, we typically quantify their performance in terms of the following values and functions.\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/learning_curve_sgm}\n  \\caption{The cost function (same as the MSE), the minimum MSE, and the excess MSE.}\n  \\label{fig:learning_curve_sgm}\n\\end{figure}\n\\begin{alignat}{2}\n  &J_1(\\vect{w}(n))  &\\quad &\\text{(Mean-Square Error (MSE))}\\\\\n  &J_1(\\vect{w}_o) = J_\\textup{min} &\\quad &\\text{(Minimum MSE (MMSE))}\\\\\n  &J_\\textup{ex} = J_1(\\vect{w}(\\infty))-J_\\textup{min} &\\quad &\\text{(Excess MSE (EMSE))}\\\\\n  &\\mathcal{M} = \\frac{ J_\\textup{ex}}{J_\\textup{min}} &\\quad &\\text{(Misadjustment)}\\\\\n  &E[\\|\\vect{\\Delta}\\vect{w}(\\infty)\\|^2]  &\\quad &\\text{(Mean-Square Deviation (MSD))}\\\\\n  &\\lambda_\\textup{max}  &\\quad &\\text{(Maximum Eigenvalue of $\\vect{R}_u$)}\\\\\n  &\\lambda_\\textup{min}  &\\quad &\\text{(Minimum Eigenvalue of $\\vect{R}_u$)}\\\\\n  &\\kappa(\\vect{R}_u) = \\frac{\\lambda_\\textup{max}}{\\lambda_\\textup{min}} &\\quad &\\text{(Condition number of $\\vect{R}_u$)}\n\\end{alignat}\nIn adaptive filtering, some people use the term eigenvalue spread $\\chi(\\vect{R}_u)$ instead of the condition number. The MSE, the EMSE, the MSD, and the misadjustment depend on the adaptive filtering algorithm. Conversely, the remaining parameters depend on the desired signal and the input signal and are thus independent of the adaptive filtering algorithm. In Fig.~\\ref{fig:learning_curve_sgm}, some of the quantities are shown.\n\n\\section{LMS Revisited}\nRecall the steepest descent algorithm\n\\bmath\n  \\vect{w}(n+1) = \\vect{w}(n)-\\frac{\\mu}{2}\\vect{g}(\\vect{w}(n))\n\\emath\nwhere\n\\bmath\n  \\vect{g}(\\vect{w}(n)) = 2\\vect{R}_u\\vect{w}(n)-2\\vect{r}_{ud} = -2E[\\vect{u}(n)e(n)]\n\\emath\nis the gradient of $J_1(\\vect{w}(n))$. Replacing the gradient with the simple estimate \n\\bmath\n  \\hat{\\vect{g}}(\\vect{w}(n)) = -2\\vect{u}(n)e(n)\n\\emath\nleads to the LMS algorithm\n\\begin{align}\n  \\vect{w}(n+1) &= \\vect{w}(n) + \\mu\\vect{u}(n)e(n)\\\\\n                &= (\\vect{I}-\\mu\\vect{u}(n)\\vect{u}^T(n))\\vect{w}(n) + \\mu\\vect{u}(n)d(n)\\ .\n\\end{align}\nIn order to analyse the LMS algorithm, we use the analysis model in Sec.~\\ref{ssec:analysis_model}.\n\n\\subsection{Transient Analysis}\nWe would like that\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*}\n\\subsubsection{Convergence in the Mean}\nWe have that\n\\bmath\n  \\vect{\\Delta}\\vect{w}(n+1) = (\\vect{I}-\\mu\\vect{u}(n)\\vect{u}^T(n))\\vect{\\Delta}\\vect{w}(n) + \\mu\\vect{u}(n)v(n)\n\\emath\nfrom which we get\n\\bmath\n  E[\\vect{\\Delta}\\vect{w}(n+1)] = (\\vect{I}-\\mu\\vect{R}_u)E[\\vect{\\Delta}\\vect{w}(n)]\\ .\n\\emath\nThus, the LMS algorithm is stable in the mean if (same as for SD)\n\\bmath\n  0 < \\mu < \\frac{2}{\\lambda_\\textup{max}}\\ .\n\\emath\nSince $\\lambda_\\textup{max}$ is unknown and hard to estimate, we can bound it by\n\\bmath\n  \\lambda_\\textup{max} \\leq \\textup{tr}(\\vect{R}_u) = ME[u^2(n)] \\leq M S_\\textup{max}\\ .\n\\emath\nEstimating the power $E[u^2(n)]$ or the maximum is the power spectral density $S_\\textup{max}$ is fairly easy.\n\n\\subsubsection{Convergence in the Mean-Square}\nWe assume that $\\vect{u}(n)$ has a Gaussian distribution with zero-mean and covariance matrix $\\vect{R}_u$. Then, as we have shown in Appendix~\\ref{app:lms_analysis}, we get that the LMS algorithm is stable in the mean-square if the step-size satisfies\n\\bmath\n  f(\\mu) = \\frac{\\mu}{2}\\sum_{m=1}^M \\frac{\\lambda_m}{1-\\mu\\lambda_m} < 1\\ .\n\\emath\nFor small step-sizes $\\mu \\ll 1/\\lambda_\\textup{max}$, we have\n\\bmath\n  f(\\mu) \\approx \\frac{\\mu}{2}\\sum_{m=1}^M\\lambda_m = \\frac{\\mu}{2}\\tr{\\vect{R}_u} < 1\\ .\n\\emath\nThus, stability in the mean-square requires that the step-size satisfies\n\\bmath\n  0 < \\mu < \\frac{2}{\\tr{\\vect{R}_u}}\\ .\n\\emath\n\n\\subsection{Steady-State Analysis}\nFrom Appendix~\\ref{app:lms_analysis}, we have that\n\\begin{alignat}{2}\n  &\\text{EMSE:}&\\quad J_\\textup{ex} &= J_1(\\vect{w}(\\infty))-J_\\textup{min} = J_\\textup{min}\\frac{f(\\mu)}{1-f(\\mu)}\\\\\n  & &\\quad &\\approx \\frac{\\mu}{2}J_\\textup{min}\\tr{\\vect{R}_u}\\\\\n  &\\text{Misadjustment:}&\\quad \\mathcal{M} &= \\frac{ J_\\textup{ex}}{J_\\textup{min}} = \\frac{f(\\mu)}{1-f(\\mu)}\\\\\n  & &\\quad &\\approx \\frac{\\mu}{2}\\tr{\\vect{R}_u}\\\\\n  &\\text{MSD:} &\\quad E[\\|\\vect{\\Delta}\\vect{w}(\\infty)\\|^2] &\\approx \\frac{\\mu}{2} J_\\textup{min} M\n\\end{alignat}\nHere, the approximations are valid for small step-sizes. We see that the EMSE is approximately proportional to the input power. This is a problem and referred to as \\textit{gradient noise amplification}.\n\n\\section{Normalised LMS Adaptive Filters}\nRecall that we can bound the maximum eigenvalue by\n\\bmath\n  \\lambda_\\textup{max} \\leq \\textup{tr}(\\vect{R}_u) = ME[u^2(n)]\\ .\n\\emath\nAn estimate of the power could be\n\\bmath\n  \\hat{E}[u^2(n)] = \\frac{1}{M}\\vect{u}^T(n)\\vect{u}(n) = \\frac{1}{M}\\|\\vect{u}(n)\\|^2\\ .\n\\emath\nThis leads to the following bound on the step-size\n\\bmath\n  0 < \\mu < \\frac{2}{\\|\\vect{u}(n)\\|^2}\\quad\\iff\\quad 0 < \\mu\\|\\vect{u}(n)\\|^2 < 2\\ .\n\\emath\nWe may define the time-varying step-size\n\\bmath\n  \\mu(n) = \\frac{\\beta}{\\|\\vect{u}(n)\\|^2}\\ ,\\qquad 0<\\beta<2\\ .\n\\emath\nThen, the LMS algorithm is\n\\bmath\n  \\vect{w}(n+1) = \\vect{w}(n) + \\frac{\\beta}{\\|\\vect{u}(n)\\|^2}\\vect{u}(n)e(n)\n\\emath\nwhich is called the normalised LMS (NLMS) algorithm. The NLMS bypasses the problem of gradient noise amplification by normalising the gradient estimate by the input power. However, this normalisation causes numerical problems when the input power is close to zero. In order to avoid this, we introduce the regularisation parameter $\\epsilon$, which is a small positive constant, into the NLMS algorithm\n\\bmath\n  \\boxed{\\vect{w}(n+1) = \\vect{w}(n) + \\frac{\\beta}{\\epsilon+\\|\\vect{u}(n)\\|^2}\\vect{u}(n)e(n)}\\ .\n\\emath\n\\subsubsection{Fast Computation}\nThe power estimate may be computed very efficiently by writing it in a recursive manner\n\\begin{align}\n  \\|\\vect{u}(n)\\|^2 &= \\sum_{m=0}^{M-1}u^2(n-m) = u^2(n) - u^2(n-M) + \\sum_{m=1}^{M}u^2(n-m)\\notag\\\\\n  &= u^2(n) - u^2(n-M) + \\|\\vect{u}(n-1)\\|^2\\ .\n\\end{align}\nIt should be noted that the use of this recursion can be problematic in practice due to accumulated rounding errors \\cite[p.~227]{Sayed2003}. These rounding errors may potentially cause the norm to be negative.\n\n\\subsection{Transient Analysis}\nIn order to analyse the NLMS algorithm, we use the analysis model in Sec.~\\ref{ssec:analysis_model}. If $\\sigma_v^2=0$, the NLMS algorithm converges in the mean and the mean-square if \\cite[p.~325]{Haykin2001}\n\\bmath\n  \\boxed{0<\\beta<2}\\ .\n\\emath\nMoreover, the optimal step-size is\n\\bmath\n  \\beta_o = 1\\ .\n\\emath\nIf $\\sigma_v^2>0$, the optimal step-size is more complicated and can be found in \\cite[p.~325]{Haykin2001}.\n\n\\subsection{Steady-State Analysis}\nAssuming the analysis model in Sec.~\\ref{ssec:analysis_model}, it can be shown that \\cite[pp.~300--302,p.~474]{Sayed2003}\n\\begin{alignat}{2}\n  &\\text{EMSE:}&\\quad J_\\textup{ex} &= J_1(\\vect{w}(\\infty))-J_\\textup{min}\\notag\\\\\n  & &\\quad &\\approx \\frac{\\beta}{2} J_\\textup{min}\\tr{\\vect{R}_u}E\\left[\\frac{1}{\\|\\vect{u}(n)\\|^2}\\right]\\geq\\frac{\\beta}{2} J_\\textup{min}\\\\\n  &\\text{Misadjustment:}&\\quad \\mathcal{M} &= \\frac{ J_\\textup{ex}}{J_\\textup{min}} \\approx \\frac{\\beta}{2}\\tr{\\vect{R}_u}E\\left[\\frac{1}{\\|\\vect{u}(n)\\|^2}\\right]\\geq\\frac{\\beta}{2}\\\\\n  &\\text{MSD:} &\\quad E[\\|\\vect{\\Delta}\\vect{w}(\\infty)\\|^2] &\\approx \\frac{\\beta}{2} J_\\textup{min} E\\left[\\frac{1}{\\|\\vect{u}(n)\\|^2}\\right] \\geq \\frac{\\beta J_\\textup{min}}{2\\tr{\\vect{R}_u}}\n\\end{alignat}\nwhere the inequality follows from that $E[x^{-1}]\\geq E[x]^{-1}$. The approximations are valid for small values of $\\beta$ and $\\epsilon$. Note that the approximation of the misadjustment no longer depends on the input power. This is a consequence of the normalisation of the LMS gradient with $\\|\\vect{u}(n)\\|^2$. Moreover, it should be noted that there exist several other approximations to the EMSE and the MSD than presented above \\cite[p.~474]{Sayed2003}.\n\n\\subsection{Computational Cost}\nTable~\\ref{tab:comp_cost_nlms} shows the computational cost of the NLMS algorithm in terms of the number of multiplications, additions or subtractions, and divisions. From the table, we see that the total number of flops is $6M+2$. If we use the fast computation of the normalisation constant, the computational cost is reduced to $4M+7$ flops as shown in Table~\\ref{tab:comp_cost_nlms_fast}. Thus, the NLMS algorithm has a linear complexity in the filter length $\\mathcal{O}(M)$ for both versions of the NLMS algorithm.\n\\begin{table}[htbp]\n  \\centering\n  \\begin{tabular}{l c c c}\n    \\toprule\n    Term & $\\times$ & $+$ or $-$ & $/$ \\\\\n    \\midrule\n    $\\|\\vect{u}(n)\\|^2$ & $M$ & $M-1$ & \\\\\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    $\\beta e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ & $1$ & $1$ & $1$\\\\\n    $\\beta\\vect{u}(n)e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ & $M$ & & \\\\\n    $\\vect{w}(n)+\\beta \\vect{u}(n)e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ &  & $M$ &\\\\\n    \\midrule\n    Total & $3M+1$ & $3M$ & $1$ \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Computational cost of the NLMS algorithm.}\n  \\label{tab:comp_cost_nlms}\n\\end{table}\n\\begin{table}[htbp]\n  \\centering\n  \\begin{tabular}{l c c c}\n    \\toprule\n    Term & $\\times$ & $+$ or $-$ & $/$ \\\\\n    \\midrule\n    $\\|\\vect{u}(n)\\|^2$ & 2 & 2 & \\\\\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    $\\beta e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ & $1$ & $1$ & $1$\\\\\n    $\\beta\\vect{u}(n)e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ & $M$ & & \\\\\n    $\\vect{w}(n)+\\beta \\vect{u}(n)e(n)/(\\epsilon+\\|\\vect{u}(n)\\|^2)$ &  & $M$ & \\\\\n    \\midrule\n    Total & $2M+3$ & $2M+3$ & $1$ \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Computational cost of the NLMS algorithm with fast update of the normalisation factor.}\n  \\label{tab:comp_cost_nlms_fast}\n\\end{table}\n\n\\subsection{Another Derivation of the NLMS Algorithm}\nWe have two requirements to the adaptive filter.\n\\begin{enumerate}\n  \\item If we filter the input sample at time $n$ through the filter at time $n+1$, the error should be zero. That is,\n  \\bmath\n    d(n) - \\vect{u}^T(n)\\vect{w}(n+1) = 0\\ .\n  \\emath\n  There are an infinite number of solutions that satisfy this requirement if $M>1$.\n  \\item Among all the filter coefficient vectors $\\vect{w}(n+1)$ satisfying the first requirements, we select the vector resulting in the smallest change from iteration $n$ to $n+1$. That is, $\\|\\vect{w}(n+1)-\\vect{w}(n)\\|^2$ should be as small as possible.\n\\end{enumerate}\nThese two requirements lead to the following constrained minimisation problem\n\\begin{gather}\n  \\begin{alignedat}{2}\n      &\\min_{\\mathclap{\\vect{w}(n+1)}} &\\quad f(\\vect{w}(n+1))&=\\|\\vect{w}(n+1)-\\vect{w}(n)\\|^2\\\\\n      &\\text{s.t.}&\\quad h(\\vect{w}(n+1)) &= d(n) - \\vect{u}^T(n)\\vect{w}(n+1) = 0\n  \\end{alignedat}\n  \\label{eq:nlms_opt}\n\\end{gather}\nThis optimisation problem has a quadratic cost function and a single linear equality constraint, and it is therefore on the same form as \\eq{eq:constr_opt_quad_lin} with\n\\begin{align}\n  \\vect{x} &= \\vect{w}(n+1)\\\\\n  \\vect{A} &= -\\vect{u}^T(n)\\\\\n  \\vect{b} &= -d(n)\\\\\n  \\vect{P} &= 2\\vect{I}\\\\\n  \\vect{q} &= -2\\vect{w}(n)\\\\\n  \\vect{r} &= \\|\\vect{w}(n)\\|^2\\ .\n\\end{align}\nThus, from \\eq{eq:constr_opt_quad_lin_minlam} and \\eq{eq:constr_opt_quad_lin_minx}, we readily obtain the solution to the optimisation problem in \\eq{eq:nlms_opt}. The solution is given by\n\\begin{align}\n  \\lambda &= -\\frac{2}{\\|\\vect{u}(n)\\|^2}e(n)\\\\\n  \\vect{w}(n+1) &= \\vect{w}(n)+\\frac{1}{\\|\\vect{u}(n)\\|^2}\\vect{u}(n)e(n)\\ .\n\\end{align}\nThe last equation is identical to the NLMS algorithm with $\\beta=1$ and $\\epsilon=0$.\n\n\\section{Affine Projection Adaptive Filters}\nWe may extend the requirements to the adaptive filter in the following way.\n\\begin{enumerate}\n  \\item If we filter the input sample at time $n-k$ for $k=0,1,\\ldots,K-1<M$ through the filter at time $n+1$, the corresponding errors should be zero. That is,\n  \\bmath\n    d(n-k) - \\vect{u}^T(n-k)\\vect{w}(n+1) = 0\\ ,\\quad k=0,1,\\ldots,K-1<M\\ .\n  \\emath\n  If we define\n  \\begin{align}\n    \\vect{U}(n) &= \\bbmtx\\vect{u}(n) & \\vect{u}(n-1) & \\cdots & \\vect{u}(n-K+1)\\ebmtx\\\\\n    \\vect{d}(n) &= \\bbmtx d(n) & d(n-1) & \\cdots & d(n-K+1)\\ebmtx^T\\ ,\n  \\end{align}\n  we may write\n  \\bmath\n    \\vect{d}(n)-\\vect{U}^T(n)\\vect{w}(n+1) = \\vect{0}\\ .\n  \\emath\n  If $K=M$ and $\\vect{U}(n)$ has full rank, there is only one filter coefficient vector $\\vect{w}(n+1)$ satisfying this requirement. It is given by\n  \\bmath\n    \\vect{w}(n+1) = \\vect{U}^{-T}(n)\\vect{d}(n)\\ .\n  \\emath\n  When this is not the case, there are an infinite number of solutions that satisfy this requirement, and we therefore need a second requirement.\n  \\item Among all the filter coefficient vectors $\\vect{w}(n+1)$ satisfying the first requirements, we select the vector resulting in the smallest change from iteration $n$ to $n+1$. That is, $\\|\\vect{w}(n+1)-\\vect{w}(n)\\|^2$ should be as small as possible.\n\\end{enumerate}\nNote that for $K=1$, the requirements are identical to the requirements leading to the NLMS algorithm. The affine projections algorithm (APA) can therefore be viewed as a generalisation of the NLMS algorithm. We may formulate the requirements as a constrained optimisation problem\n\\begin{gather}\n  \\begin{alignedat}{2}\n      &\\min_{\\mathclap{\\vect{w}(n+1)}} &\\quad f(\\vect{w}(n+1)) &=\\|\\vect{w}(n+1)-\\vect{w}(n)\\|^2\\\\\n      &\\text{s.t.}&\\quad \\vect{h}(\\vect{w}(n+1)) &=  \\vect{d}(n)-\\vect{U}^T(n)\\vect{w}(n+1) = \\vect{0}\n  \\end{alignedat}\n  \\label{eq:apa_opt}\n\\end{gather}\nThis optimisation problem has a quadratic cost function and $K\\leq M$ linear equality constraints, and it is therefore on the same form as \\eq{eq:constr_opt_quad_lin} with\n\\begin{align}\n  \\vect{x} &= \\vect{w}(n+1)\\\\\n  \\vect{A} &= -\\vect{U}^T(n)\\\\\n  \\vect{b} &= -\\vect{d}(n)\\\\\n  \\vect{P} &= 2\\vect{I}\\\\\n  \\vect{q} &= -2\\vect{w}(n)\\\\\n  \\vect{r} &= \\|\\vect{w}(n)\\|^2\\ .\n\\end{align}\nThus, from \\eq{eq:constr_opt_quad_lin_minlam} and \\eq{eq:constr_opt_quad_lin_minx}, we readily obtain the solution to the optimisation problem in \\eq{eq:apa_opt}. The solution is given by\n\\begin{align}\n  \\vect{\\lambda} &= -2\\left(\\vect{U}^T(n)\\vect{U}(n)\\right)^{-1}\\vect{e}(n)\\\\\n  \\vect{w}(n+1) &= \\vect{w}(n)+\\vect{U}(n)\\left(\\vect{U}^T(n)\\vect{U}(n)\\right)^{-1}\\vect{e}(n)\\ .\n\\end{align}\n\nFrom this result, we see that the APA reduces to the NLMS algorithm for $K=1$. Usually, we add a regularisation parameter $\\epsilon$ and a step-size parameter $\\beta$ to the algorithm and obtain\n\\bmath\n  \\boxed{\\vect{w}(n+1) = \\vect{w}(n)+\\beta\\vect{U}(n)\\left(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n)\\right)^{-1}\\vect{e}(n)}\\ .\n\\emath\nAs for the NLMS algorithm, $\\epsilon$ is a small positive value which bypasses numerical problems when $\\vect{U}^T(n)\\vect{U}(n)$ is ill-conditioned.\n\nFor $K>1$, The computational complexity of the APA is higher than that of the NLMS algorithm since we have to invert a $K\\times K$ matrix. Although there exist fast ways of doing this \\cite[pp.~339--340]{Haykin2001}, the APA is more expensive than the NLMS algorithm.\n\n\\subsection{Transient Analysis}\nIn order to analyse the APA, we use the analysis model in Sec.~\\ref{ssec:analysis_model}. If $\\sigma_v^2=0$, the APA converges in the mean and the mean-square if \\cite[p.~337]{Haykin2001}\n\\bmath\n  \\boxed{0<\\beta<2}\\ .\n\\emath\nMoreover, the optimal step-size is\n\\bmath\n  \\beta_o = 1\\ .\n\\emath\nIf $\\sigma_v^2>0$, the optimal step-size is more complicated and can be found in \\cite[p.~337]{Haykin2001}.\n\n\\subsection{Steady-State Analysis}\nAssuming the analysis model in Sec.~\\ref{ssec:analysis_model}, it can be shown that \\cite[p.~327]{Sayed2003}\n\\begin{alignat}{2}\n  &\\text{EMSE:}&\\quad J_\\textup{ex} &= J_1(\\vect{w}(\\infty))-J_\\textup{min}\\notag\\\\\n  & &\\quad &\\approx \\frac{\\beta}{2} J_\\textup{min}\\tr{\\vect{R}_u}E\\left[\\frac{K}{\\|\\vect{u}(n)\\|^2}\\right]\\geq\\frac{\\beta}{2} J_\\textup{min}K\\\\\n  &\\text{Misadjustment:}&\\quad \\mathcal{M} &= \\frac{ J_\\textup{ex}}{J_\\textup{min}} \\approx \\frac{\\beta}{2}\\tr{\\vect{R}_u}E\\left[\\frac{K}{\\|\\vect{u}(n)\\|^2}\\right]\\geq\\frac{\\beta K}{2}\n\\end{alignat}\nwhere the inequality follows from that $E[x^{-1}]\\geq E[x]^{-1}$. The approximations are valid for small values of $\\beta$ and $\\epsilon$. It should be noted that there exist several other approximations to the EMSE than presented above \\cite[p.~325]{Sayed2003}. For more accurate expressions and for an expression for the mean-square deviation, see \\cite[pp.~510--512]{Sayed2003} and \\cite{Shin2004}.\n\n\\subsection{Computational Cost}\nTable~\\ref{tab:comp_cost_apa} shows the computational cost of the APA algorithm in terms of the number of multiplications and additions or subtractions. We have assumed that the cost of inverting a $K\\times K$ matrix is $K^3$ multiplications and additions \\cite[p.~240]{Sayed2003}. From the table, we see that the total number of flops is $2M(K^2+2K)+2K^3+K^2+M$. Thus, the APA has a complexity of $\\mathcal{O}(MK^2)$. Note that there exist faster ways of implementing the APA \\cite[pp.~339-340]{Haykin2001}.\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)$ & $MK$ & $(M-1)K$ \\\\\n    $\\vect{e}(n)=\\vect{d}(n)-\\vect{U}^T(n)\\vect{w}(n)$ & & $K$ \\\\\n    $\\vect{U}^T(n)\\vect{U}(n)$ & $MK^2$ & $(M-1)K^2$ \\\\\n    $\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n)$ & & $K$ \\\\\n    $(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n))^{-1}$ & $K^3$ & $K^3$ \\\\\n    $(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n))^{-1}\\vect{e}(n)$ & $K^2$ & $K(K-1)$ \\\\\n    $\\vect{U}(n)(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n))^{-1}\\vect{e}(n)$ & $MK$ & $M(K-1)$ \\\\\n    $\\beta\\vect{U}(n)(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n))^{-1}\\vect{e}(n)$ & $M$ &  \\\\\n    $\\vect{w}(n)+\\beta\\vect{U}(n)(\\epsilon\\vect{I}+\\vect{U}^T(n)\\vect{U}(n))^{-1}\\vect{e}(n)$ &  & $M$\\\\\n    \\midrule\n    Total & $M(K^2+2K+1)+K^3+K^2$ & $M(K^2+2K)+K^3$\\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Computational cost of the APA.}\n  \\label{tab:comp_cost_apa}\n\\end{table}\n", "meta": {"hexsha": "7fcf8ab77e8c2d416759ecf9937dcff56dc3f896", "size": 28736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/NLMS_APA.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/NLMS_APA.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/NLMS_APA.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": 57.702811245, "max_line_length": 842, "alphanum_fraction": 0.6689518374, "num_tokens": 10218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6146315567280273}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{locfreq}\n\\section*{\\hspace*{-1.6cm} locfreq}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nFrequency localization characteristics.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[fm,B] = locfreq(x)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty locfreq} computes the frequency localization characteristics of\n        signal {\\ty x}. The definition used for the averaged frequency\n        and the frequency spreading are the following\\,:\n\\begin{eqnarray*}\nf_m &=& \\frac{1}{E_x}\\ \\int_{-\\infty}^{+\\infty} \\nu\\ |X(\\nu)|^2\\ d\\nu\\\\\nB &=& 2\\ \\sqrt{\\frac{\\pi}{E_x}\\ \\int_{-\\infty}^{+\\infty} (\\nu-f_m)^2\\\n|X(\\nu)|^2\\ d\\nu }\n\\end{eqnarray*}\nwhere $E_x$ is the energy of the signal and $X(\\nu)$ the Fourier transform\nof $x(t)$. With this definition (and the one used in {\\ty loctime}), the\nHeisenberg-Gabor inequality writes $B\\ T\\geq 1$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & signal\\\\\n\\hline  {\\ty fm}    & averaged normalized frequency center\\\\\n        {\\ty B}     & frequency spreading\\\\\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         z=amgauss(160,80,50).*fmconst(160,0.2);\n         [fm,B]=locfreq(z); [fm,B]\n         ans = \n               0.2000    0.0200\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nloctime.\n\\end{verbatim}\n\\end{minipage}\n\n\n\n\n", "meta": {"hexsha": "436e2295563339de03059607cf9a31c67cb07a24", "size": 1899, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/locfreq.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/locfreq.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/locfreq.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 22.8795180723, "max_line_length": 76, "alphanum_fraction": 0.6345444971, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6146315566795574}}
{"text": "%!TEX root = ../notes.tex\n\\section{May 3, 2022}\n\\subsection{Minkowski, Lagrange, and Waring Walk Into a Bar\\dots}\n\\subsubsection{Four Squares Theorem and Waring's Problem}\n\\begin{theorem}[Lagrange, 1770]\n    Every nonnegative integer can be written as a sum of four square integers.\n\\end{theorem}\nIn the same year, Waring asserted, in his book, that\n\\begin{theorem}[Waring, 1770]\n    For every integer $k\\geq 2$, there is a $g(k)$ such that every nonnegative integer can be written as a sum of at most $g(k)$ $k$th powers.\n\\end{theorem}\nHe claimed that $g(3) = 9$ and $g(4) = 19$. We note that $23$ and $239$ require $9$ cubes, and $79$ requires $19$ fourth powers. $g(3) = 9$ is a result of Wieferich-Kemper (1909) and $g(4) = 19$ is a result of Balasubramanian, Dress, Deshouillers (1986). Hilbert proved this theorem in $1909$.\n\nThere is also a `capital $G$' version of this question, which is an asymptotic best bound of $g(k)$.\n\n$4 \\leq G(3) \\leq 7$. This is currently unknown.\n\n$G(4) = 16$, which we do know. So, your mileage may very much vary on these.\n\n\\subsubsection{Lattices and Minkowski's Theorem}\n\\begin{definition}[Lattice]\n    Let $e_1, e_2, \\dots, e_n$ be a set of basis vectors for $\\RR^n$. Then the additive subgroup of $(\\RR^n, +)$ generated by $e_1, e_2, \\dots, e_n$ is called a \\ul{lattice}.\n\\end{definition}\n\\begin{example}\n    The most obvious lattice in $\\RR^n$ is $\\ZZ^n$, where we take $e_i$ to be the standard basis vectors.\n\n    We can take $\\alpha\\ZZ^n$ by some $0\\neq \\alpha\\in\\RR$ is also an obvious lattice.\n\n    We can also take things like $\\frac{1}{2}\\ZZ\\times \\ZZ\\subseteq\\RR^2$.\n\\end{example}\n\n\\begin{definition}[Fundamental Domain]\n    If $L$ is a lattice generated by $e_1, e_2, \\dots, e_n$ in $\\RR^n$, then the \\ul{fundamental domain} of $L$ is the set\n    \\[\\left\\{ \\sum a_i e_i \\mid a_i\\in\\RR, 0\\leq a_i < 1 \\right\\}\\]\n\\end{definition}\n\\begin{example}\n    If we take $\\ZZ^2\\subseteq\\RR^2$, then the fundamental domain is the square with corners $(0, 0)$ to $(1, 1)$, with some dotted lines.\n\\end{example}\n\\begin{definition}[Convex, Symmetric]\n    A set $X\\subseteq\\RR^n$ is \\ul{convex} if forall $x, y\\in X$,\n    \\[\\lambda x + (1 - \\lambda)y \\in X\\]\n    for all $0\\leq \\lambda \\leq 1$.\n\n    A set $X$ is \\ul{symmetric} if $x\\in X$ implies $-x\\in X$.\n\\end{definition}\n\\begin{example}\n    A triangle is convex but not symmetric. An ellipse about the origin is convex and symmetric. An annulus is symmetric but not convex.\n    \\begin{center}\n        \\includegraphics[width=0.9\\textwidth]{images/shapes.png}\n    \\end{center}\n\\end{example}\n\\begin{theorem}[Minkowski, p.140 \\cite{stewart2015algebraic}]\n    Let $L$ be an $n$-dimensional lattice in $\\RR^n$ with fundamental domain $T$, and let $X$ be a bounded symmetric convex subset of $\\RR^n$. If\n    \\[\\Vol(X) > 2^n\\Vol(T)\\]\n    then $X$ contains a non-zero point of $L$.\n\\end{theorem}\n\\begin{example}\n    If we have the $\\ZZ^2$ example, if we have a `dotted' open square with area $4$, we just about not contain any nonzero points. If we add anything in, we'll have a nontrivial point.\n    \\begin{center}\n        \\includegraphics[width=0.4\\textwidth]{images/square.png}\n    \\end{center}\n\\end{example}\n\n\\begin{proof}[Proof of 4 squares theorem using Minkowski's Theorem]\n    We first prove this statement for primes, then extend to all positive integers. We first have\n    \\[2 = 1^2 + 1^2 + 0^2 + 0^2.\\]\n    So suppose we're trying to prove $p\\in\\ZZ_+$ is an odd prime.\n    \\begin{claim*}\n        The equation $r^2 + s^2 + 1\\equiv 0\\pmod{p}$ has a solution $(r, s)\\in\\ZZ^2$.\n    \\end{claim*}\n    \\emph{Why?} Every element of $\\ZZ/p\\ZZ$ is a sum of $2$ squares\\dots\n\n    So let us select such an $r, s$. Consider the lattice $\\Lambda\\subseteq\\ZZ^4$ that is given by\n    \\[\\Lambda = A\\ZZ^4,\\]\n    where\n    \\[A = \\begin{pmatrix}\n            p & 0 & r & s  \\\\\n            0 & p & s & -r \\\\\n            0 & 0 & 1 & 0  \\\\\n            0 & 0 & 0 & 1\n        \\end{pmatrix}.\\]\n    We make an observation of the particular nature of the points in this lattice.\n\n    If $\\bvec{t}= (t_1, t_2, t_3, t_4)\\in\\ZZ^4$, and $\\bvec{x} = (x_1, x_2, x_3, x_4)$ where $\\bvec{x} = A\\bvec{t}$, then\n    \\begin{align*}\n        x_1^2 + x_2^2 + x_3^2 + x_4^2\n         & = (pt_1 + rt_3 + st_4)^2 + (pt_2 + st_3 - rt_4)^2 + t_3^2 + t_4^2 \\\\\n         & \\equiv (rt_3 + st_4)^2 + (st_3 - rt_4)^2 + t_3^2 + t_4^2\\pmod{p}  \\\\\n         & = (1 + r^2 + s^2)(t_3^2 + t_4^2)\\pmod{p}                          \\\\\n         & = 0\\pmod{p}\n    \\end{align*}\n    Geometrically, the idea is if we can get the norm to be small enough, we know the sum is exactly $p$.\n\n    Let's find an appropriate radius for our ball. A $4$-dimensional ball of radius $R$ has volume\n    \\[\\pi^2R^4/2\\]\n    choose $R$ such that\n    \\begin{align*}\n        16p^2 & < \\frac{\\pi^2 R^4}{2}\\approx 4.93 R^4 \\\\\n        4p    & < \\approx 2.22 R^2                    \\\\\n        2p    & < \\approx 1.11 R^2\n    \\end{align*}\n    The next condition is $R^2 < 2p$. So we want $R$ such that\n    \\[R^2 < 2p < \\approx 1.11 R^2\\]\n    If we take $R^2 = 1.9p$ works.\n\n    Let $X$ be the ball centered at the origin with radius $\\sqrt{1.9p}$. Let $T$ be the fundamental domain for $\\Lambda = A\\ZZ^4$. Then we have $\\Vol(T) = \\det(A) = p^2$.\n\n    Then $\\Vol(X) > 2^n\\Vol(T) = 16p^2$. Applying Minkowski's theorem, we conclude that $X$ \\emph{must} contain some nonzero lattice point of $\\Lambda$.\n\n    If we let $\\bvec{x} = (x_1, x_2, x_3, x_4)$ be this point. Then since $\\bvec{x}\\in X$, so\n    \\[x_1^2 + x_2^2 + x_3^2 + x_4^2 < R^2 < 2p.\\]\n    so $p\\mid x_1^2 + x_2^2 + x_3^2 + x_4^2$ and $x_1^2 + x_2^2 + x_3^2 + x_4^2 < 2p$, and it's a nonzero point, so this forces\n    \\[x_1^2 + x_2^2 + x_3^2 + x_4^2 = p,\\]\n    which is as desired for primes.\n\n    In the arbitrary case for arbitrary $n$, note that\n    \\begin{align*}\n         & (a^2 + b^2 + c^2 + d^2)(A^2 + B^2 + c^2 + D^2)                \\\\\n         & = (aA - bB - cC - dD)^2 + (aB + bA + cD - dC)^2 +             \\\\\n         & \\phantom{=}\\ \\ (aC - bD + cA + dB)^2 + (aD + bC - cB + dA)^2.\n    \\end{align*}\n    so composite $n$ is also a sum of 2 squares.\n\\end{proof}\n\n\\begin{center}\n    \\emph{\\dots and that's the course! }\n\\end{center}\n", "meta": {"hexsha": "5b22276fbc936b2fcaaeead172c4eb196aa7b8de", "size": 6197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-05-03.tex", "max_stars_repo_name": "jchen/math1560-notes", "max_stars_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-02T15:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T20:28:48.000Z", "max_issues_repo_path": "lectures/2022-05-03.tex", "max_issues_repo_name": "jchen/math1560-notes", "max_issues_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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-05-03.tex", "max_forks_repo_name": "jchen/math1560-notes", "max_forks_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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": 48.4140625, "max_line_length": 293, "alphanum_fraction": 0.6078747781, "num_tokens": 2293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140728, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6146315566310875}}
{"text": "\\documentclass[aps,superscriptaddress,preprint,amsmath,floatfix,byrevtex]{article}\n\\usepackage[pdftex]{graphicx}\n\\usepackage{textcomp}\n\\usepackage{amsmath}\n\\usepackage{dcolumn}\n\n\\oddsidemargin 0.1in\n\\evensidemargin 0.1in\n\\textwidth 6.7in\n\n\\newcommand{\\lrbar}{\\bar{l}_{\\rho}^{\\mathrm{2D}}}\n\n\\begin{document}\n\\title{Derivation of the mean radial displacement, $\\lrbar$, in 2 dimensions}\n\\author{Markus Dittrich}\n\\date{\\today}\n\n%\\pacs{}\n\\maketitle\n\n\\section{Introduction}\nIn the following we derive an expression for the mean radial displacement, $\\lrbar$,\nfor diffusing 2D molecules in analogy to the well known expression for $\\bar{l}_r$\nin three dimensions. \n\n\n\\section{Derivation}\nStarting point is the solution of the diffusion equation in 2 dimensions\n\\begin{equation}\n\\frac{\\partial c(\\rho,t)}{\\partial t} = D \\nabla^2 c(\\rho,t)\n\\end{equation}\nwhich, for a point source of $M$ molecules released at the origin at time $t=0$ \ncan be shown to be\n\\begin{equation}\nc(\\rho,t) = \\frac{M}{4 \\pi Dt} e^{- \\frac{\\rho^2}{4Dt}}\n\\end{equation}\n(see also Eqs. 3.1, 3.2 in \\cite{KERR2008}). Therefore, the probability\ndensity for a molecule being in a radial shell of thickness $d\\rho$ around the \norigin is given by\n\\begin{equation}\np^{\\mathrm{2D}} (\\rho,t) = \\frac{(2 \\pi \\rho) d\\rho}{4\\pi Dt}  e^{- \\frac{\\rho^2}{4Dt}} \n\\end{equation}          \nor, in normalized coordinates $\\tilde{\\rho} = \\frac{\\rho}{\\lambda}$ with the \nnormalization constant $\\lambda = \\sqrt{4Dt}$\n\\begin{equation}\np^{\\mathrm{2D}} (\\tilde{\\rho},t) = 2 e^{-\\tilde{\\rho}^2} (\\tilde{\\rho} d\\tilde{\\rho})\n  \\;\\;\\;\\; .\n\\end{equation}\nHence, the mean radial displacement of a 2D molecule is given by\n\\begin{equation}\n\\lrbar = 2 \\lambda \\int_0^{\\infty}  \\tilde{\\rho}^2 e^{- \\tilde{\\rho}^2} d\\tilde{\\rho}\n\\end{equation}\nSince\n\\begin{eqnarray}\n\\int_0^{\\infty} t^{2n} e^{-at^2} dt &=& \\frac{\\Gamma(n+\\frac{1}{2})}{2a^{n+\\frac{1}{2}}} \n  \\nonumber \\\\\n\\Rightarrow \\int_0^{\\infty}  \\tilde{\\rho}^2 e^{- \\tilde{\\rho}^2} d\\tilde{\\rho} &=& \n  \\frac{\\Gamma(\\frac{3}{2})}{2} = \\frac{\\sqrt{\\pi}}{4} \n\\end{eqnarray}\nand from this\n\n\\begin{equation}\n\\boxed{\n\\lrbar = 2 \\lambda \\frac{\\sqrt{\\pi}}{4} = \\sqrt{\\pi D t}\n}\n\\end{equation}\n\n\\begin{thebibliography}{99}\n\\bibitem{KERR2008} R. Kerr, T.M. Bartol, B. Kaminsky, M. Dittrich, J.C.J. Chang, S. Baden, \nT.J. Sejnowski, and J.R. Stiles, Fast Monte Carlo Simulation Methods for Biological \nReaction-Diffusion Systems in Solution and on Surfaces (2008),\nSIAM J. Sci. Comput., 30:3126-3149. \n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "bd5db12adb973febafadbf82b6e3b418f8cb53ac", "size": 2517, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/lr_bar_2D.tex", "max_stars_repo_name": "mcellteam/mcell", "max_stars_repo_head_hexsha": "3920aec22c55013b78f7d6483b81f70a0d564d22", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2015-03-25T16:36:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T14:28:43.000Z", "max_issues_repo_path": "docs/lr_bar_2D.tex", "max_issues_repo_name": "mcellteam/mcell", "max_issues_repo_head_hexsha": "3920aec22c55013b78f7d6483b81f70a0d564d22", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-02-12T22:15:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:43:24.000Z", "max_forks_repo_path": "docs/lr_bar_2D.tex", "max_forks_repo_name": "mcellteam/mcell", "max_forks_repo_head_hexsha": "3920aec22c55013b78f7d6483b81f70a0d564d22", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-01-15T23:20:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T06:18:00.000Z", "avg_line_length": 33.1184210526, "max_line_length": 91, "alphanum_fraction": 0.687326182, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6146315448332909}}
{"text": "\\section{Lines}\nIn this section we will discuss how to represent lines in 3D, and some related problems, including finding the line at the intersection of two planes, and finding the intersection point of a plane and a line.\n\n\\subsection{Line representation}\nUnlike 2D lines and planes, 3D lines don't have a nice representation as a single equation on coordinates like $ax+by=c$ or $ax+by+cz=d$. We could represent them as the intersection of two planes, like\n\\begin{align*}\na_1x+b_1y+c_1z &= d_1 \\\\\na_2x+b_2y+c_2z &= d_2\n\\end{align*}\nbut this representation is not very convenient to work with, and there are many pairs planes we could choose.\n\n\\centerFig{line3d-0}\n\nInstead, we will work with a parametric representation: we take a point $O$ on the line and a vector $\\vv{d}$ parallel to the line and say that the points belonging to the line are all points\n\\[P = O + k \\vv{d}\\]\nwhere $k$ is a real parameter.\n\n\\centerFig{line3d-1}\n\nNote that here, $\\vv{d}$ plays the same role as $\\vv{v}$ did for 2D lines (see section~\\ref{ss:line-rep}).\n\nIf we are given two points $P,Q$ on the line, we can set $O=P$ and $\\vv{d}=\\vv{PQ}$, so we implement the structure like this:\n\\begin{lstlisting}\nstruct line3d {\n    p3 d, o;\n    // From two points P, Q\n    line3d(p3 p, p3 q) : d(q-p), o(p) {}\n    // From two planes p1, p2 (requires T = double)\n    line3d(plane p1, plane p2); // will be implemented later\n    \n    // Will be defined later:\n    // - these work with T = int\n    double sqDist(p3 p);\n    double dist(p3 p);\n    bool cmpProj(p3 p, p3 q);\n    // - these require T = double\n    p3 proj(p3 p);\n    p3 refl(p3 p);\n    p3 inter(plane p) {return o - d*p.side(o)/(d|p.n);}\n};\n\\end{lstlisting}\n\n\\subsection{Distance from a line}\nA point $P$ is on a line $l$ described by $O,\\vv{d}$ if and only if $\\vv{OP}$ is parallel to $\\vv{d}$. This is the case when $\\crossv{d}{OP} = \\vv{0}$.\n\n\\centerFig{line3d-2}\n\nMore generally, this product $\\crossv{d}{OP}$ also gives us information about the distance to the line: the distance from $l$ to $P$ is equal to\n\\[\\frac{\\big\\|\\crossv{d}{OP}\\big\\|}{\\big\\|\\vv{d}\\big\\|}\\]\n%Note that this expression also works for 2D lines; indeed, the norm of $\\crossv{d}{OP}$ is equivalent to the \n\\begin{lstlisting}\ndouble sqDist(p3 p) {return sq(d*(p-o))/sq(d);}\ndouble dist(p3 p) {return sqrt(sqDist(p));}\n\\end{lstlisting}\n\n\\subsection{Sorting along a line}\\label{ss:sort-line3d}\nJust like we did with 2D lines in section~\\ref{ss:sort-line}, we can sort points according to their position along a line $l$. To find out if a point $P$ should come before another point $Q$, we simply need to check whether\n\\[\\vv{d}\\cdot P < \\vv{d}\\cdot Q\\]\nso we can use the following comparator:\n\\begin{lstlisting}\nbool cmpProj(p3 p, p3 q) {return (d|p) < (d|q);}\n\\end{lstlisting}\n\n\\subsection{Orthogonal projection and reflection}\nLet's say we want to project $P$ on a line $l$, that is find the closest point to $P$ on $l$.\nOur usual approach to projecting things, which is to move $P$ perpendicularly until it touches $l$, doesn't work as well here: indeed, there are many possible directions that are perpendicular to $l$.\n\n\\centerFig{line3d-3}\n\nInstead we will start from $O$ and move along the line until we reach the projection of $P$. We have seen in the previous section that taking the dot product with $\\vv{d}$ tells us how far some point is along $l$. In fact, if we compute $\\dotv{d}{OP}$, this tells us the (signed) distance from $O$ to the projection of $P$, multiplied by $\\normv{d}$. So we can find the projection this way:\n\\begin{lstlisting}\np3 proj(p3 p) {return o + d*(d|(p-o))/sq(d);}\n\\end{lstlisting}\n\nOnce we've found the projection $P'$, we can find the reflection $P''$ easily, since it is twice as far in the same direction: we have $P'' = P' + \\vv{PP'}$, which becomes $2P'-P$ if we allow vector operations on points.\n\\begin{lstlisting}\np3 refl(p3 p) {return proj(p)*2 - p;}\n\\end{lstlisting}\n\n\\subsection{Plane-line intersection}\\label{ss:plane-line}\nLet's say we have a plane $\\Pi$, represented by vector $\\vv{n}$ and real $d$, and a line $l$, represented by point $O$ and $\\vv{d}$. To find an intersection between them, we need to find a point $O+k\\vv{d}$ that lies on $\\Pi$, that is, such that\n\\[\\vv{n}\\cdot\\left(O+k\\vv{d}\\right) = d\\]\n\n\\centerFig{line3d-4}\n\nSolving for $k$, we find\n\\[k = \\frac{d - \\vv{n}\\cdot O}{\\dotv{n}{d}} = \\frac{-\\side_{\\Pi}(O)}{\\dotv{n}{d}}\\]\nwhich can be implemented directly:\n\\begin{lstlisting}\np3 inter(plane p) {return o - d*p.side(o)/(p.n|d);}\n\\end{lstlisting}\n\nNote that this is undefined when $\\dotv{n}{d}=0$, that is, when $\\Pi$ and $l$ are parallel.\\footnote{We take a closer look at criteria for parallelism and perpendicularity in section~\\ref{s:angles}.}\n \n\\subsection{Plane-plane intersection}\nIf we are given two non-parallel planes $\\Pi_1$ and $\\Pi_2$ (defined by $\\vv{n_1}$, $d_1$ and $\\vv{n_2}$, $d_2$), how can we find their common line?\n\nFirst we need to find its direction $\\vv{d}$. Clearly, the direction needs to be parallel to both planes, so it must be perpendicular to both $\\vv{n_1}$ and $\\vv{n_2}$. Thus we take $\\vv{d} = \\crossv{n_1}{n_2}$.\n\nThen we need to find an arbitrary point $O$ that is on both planes. Here, we will actually compute the closest such point to the origin. It is given by\n\\[O = \\frac{\\big(d_1\\vv{n_2} - d_2\\vv{n_1}\\big)\\times\\vv{d}}{\\big\\|\\vv{d}\\big\\|^2}\\]\n\nLet's analyze this expression. It is the sum of two vectors,\n\\begin{align*}\n\\vv{v_1} &= \\frac{d_1}{\\big\\|\\vv{d}\\big\\|^2}\\left(\\crossv{n_2}{d}\\right) \\\\\n\\vv{v_2} &= -\\frac{d_2}{\\big\\|\\vv{d}\\big\\|^2}\\left(\\crossv{n_1}{d}\\right)\n\\end{align*}\nBecause $\\vv{v_1}$ is perpendicular to $\\vv{n_2}$, it is parallel to $\\Pi_2$, while $\\vv{v_2}$ is perpendicular to $\\vv{n_1}$ and thus parallel to $\\Pi_1$. So we can see $\\vv{v_1}$ as the vector that leads from the origin to $\\Pi_1$ while staying parallel to $\\Pi_2$, and $\\vv{v_2}$ as the vector that leads from the origin to $\\Pi_2$ while staying parallel to $\\Pi_1$.\n\n\\centerFig{line3d-5}\n\nLet's verify that $O$ is on $\\Pi_1$, that is, $\\vv{n_1}\\cdot O = \\vv{n_1}\\cdot(\\vv{v_1} + \\vv{v_2}) = d_1$. Since $\\vv{v_2}$ is perpendicular to $\\vv{n_1}$, clearly $\\dotv{n_1}{v_2} = 0$. What remains is\n\\begin{align*}\n\\dotv{n_1}{v_1}\n&= \\frac{d_1}{\\big\\|\\vv{d}\\big\\|^2}\\left(\\crossv{n_2}{d}\\right)\\cdot\\vv{n_1} \\\\\n&= \\frac{d_1}{\\big\\|\\vv{d}\\big\\|^2}\\Big(\\crossv{n_1}{n_2}\\Big)\\cdot\\vv{d} \\\\\n&= \\frac{d_1}{\\big\\|\\vv{d}\\big\\|^2}\\left(\\dotv{d}{d}\\right) \\\\\n&= d_1\n\\end{align*}\nwhere between the first two lines, we used the fact that the mixed product is conserved if we swap its arguments in a circular way (see exercise~\\ref{ex:mixed-props}).\n\nWe prove similarly that $O$ is on $\\Pi_2$. Finally we note that both $\\vv{v_1}$ and $\\vv{v_2}$ are perpendicular to $\\vv{d}$, so the vector from the origin to $O$ is perpencular to $\\vv{d}$, the direction of the line. Therefore it must necessarily arrive on the line at the closest point to the origin.\n\nWe can implement this as the following constructor:\n\\begin{lstlisting}\nline3d(plane p1, plane p2) {\n    d = p1.n*p2.n;\n    o = (p2.n*p1.d - p1.n*p2.d)*d/sq(d);\n}\n\\end{lstlisting}\n\n\\subsection{Line-line distance and nearest points}\nConsider line $l_1$ defined by $O_1 + k\\vv{d_1}$ and line $l_2$ defined by $O_2 + k\\vv{d_2}$.\nIf they are parallel, the distance between them is easy to find: just find the distance from $l_1$ to $O_2$.\nOtherwise, they are either intersecting or skew, in which case the question is a bit more complex.\n\n\\centerFig{line3d-6}\n\nLet's call $C_1$ the point of $l_1$ that is closest to $l_2$, and $C_2$ the point on $l_2$ that is closest to $l_1$.\nDirection $\\vv{C_1C_2}$ should be perpendicular to both $l_1$ and $l_2$.\nIndeed, if it were not, it would be possible to get a smaller distance by moving either $C_1$ or $C_2$.\nSo $\\vv{C_1C_2}$ is parallel to $\\vv{n}=\\crossv{d_1}{d_2}$.\n\n\\centerFig{line3d-7}\n\nBecause of this, we could compute the distance as\n\\[|C_1C_2| = \\frac{\\big|\\dotv{C_1C_2}{n}\\big|}{\\normv{n}}\\]\nWe don't know $C_1$ or $C_2$ yet, but since the dot product doesn't change when one of the vectors moves perpendicular to the other, we can move $C_1$ to $O_1$ and $C_2$ to $O_2$, so that we get\n\\[\\frac{\\big|\\dotv{C_1C_2}{n}\\big|}{\\normv{n}} = \\frac{\\big|\\dotv{O_1C_2}{n}\\big|}{\\normv{n}} = \\frac{\\big|\\dotv{O_1O_2}{n}\\big|}{\\normv{n}}\\]\nwhich gives the following implementation:\n\\begin{lstlisting}\ndouble dist(line3d l1, line3d l2) {\n    p3 n = l1.d*l2.d;\n    if (n == zero) // parallel\n        return l1.dist(l2.o);\n    return abs((l2.o-l1.o)|n)/abs(n);\n}\n\\end{lstlisting}\n\nNow, how can we find $C_1$ and $C_2$ themselves? Let's call $\\Pi_2$ the plane that contains $l_2$ and is parallel to $n_2$; its normal is $\\vv{n_2} = \\crossv{d_2}{n}$. Then $C_1$ is the intersection between that plane and line $l_1$, so we can use the formula obtained in section~\\ref{ss:plane-line} to find it:\n\\[C_1 = O_1 + \\frac{\\dotv{O_1O_2}{n_2}}{\\dotv{d_1}{n_2}}\\]\n\n\\centerFig{line3d-8}\n\nThis is implemented in a straightforward way. If we want $C_2$ instead we just have to swap $l_1$ and $l_2$.\n\\begin{lstlisting}\np3 closestOnL1(line3d l1, line3d l2) {\n    p3 n2 = l2.d*(l1.d*l2.d);\n    return l1.o + l1.d*((l2.o-l1.o)|n2)/(l1.d|n2);\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "99deabfcb028cf590b19bd076ccaec2f943f958d", "size": 9228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/line3d.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/line3d.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/line3d.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": 53.6511627907, "max_line_length": 390, "alphanum_fraction": 0.683029909, "num_tokens": 3162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6145807344605521}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n\\begin{document}\n\n\\section*{Limits}\n\n\\[\\lim_{x \\to 0^{+}} \\frac{1}{x} = \\infty\\]\n\n\\[\\lim_{x \\to 0^{-}} \\frac{1}{x} = -\\infty\\]\n\n\\[\\lim_{x \\to \\pm\\infty} \\frac{1}{x} = 0\\]\n\n\n\\end{document}", "meta": {"hexsha": "99e150ac1ab1851b2ad455ca4da8ed6cdb6f4178", "size": 266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/limits.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/limits.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/limits.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": 15.6470588235, "max_line_length": 44, "alphanum_fraction": 0.5902255639, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.6926419894793246, "lm_q1q2_score": 0.6145151548674128}}
{"text": "\\chapter{Conclusion and Future Works}\n\\label{chap_conc}\nThis thesis presents a study of deep multi-layer kernels on supervised and unsupervised learning algorithms. In the supervised learning settings, multi-layer kernels are studied on structured output prediction problems and discriminant analysis methods. In the unsupervised learning settings, multi-layer kernels are used for feature learning task. In particular, we used MKMs and MKL for building a feature learning framework with kernel machines whose architecture and training is equivalent to existing deep learning algorithms.\n\nIn the unsupervised feature learning model with MKMs we experimented with single kernel (arc-cosine kernel) and mixed kernels. In some cases, the mixed kernel version was found to be superior than their single kernel counterparts. Features learned by the MKMs were visualized with tSNE algorithm to understand the separability of different classes.\n\nInstead of using single kernel in each layer, a convex combination of multiple kernels were tried out using an unsupervised MKL formulation. The training of this model was done in a greedy layer-by-layer fashion. Experimental results indicates that, this ML-MKL model is superior to single-kernel MKMs. Though we had conducted empirical study on object recognition datasets like \\textit{cifar10} and text classification datasets like \\textit{20-newsgroups}, the results were not very impressive. In the case of \\textit{20-newsgroups} classification, multiple layers might be making the similarity information in the kernel matrix more noisy, since the performance was degrading after each layer is added.  The empirical studies on supervised learning settings also gave fruitful results. The KFDA algorithm with multi-layer kernels showed competitive performance with state of the art deep learning algorithms. Structured output learning algorithms also works well when multi-layer kernels were used.\n\n\\section{Future Works}\nThe empirical study conducted in this thesis is giving many insights, from which we can list out some potential future directions to explore.\n\nThe complexity of the model in terms of the number of layers and number of kernels in each layer are set by using  cross-validation techniques in our experiments. The optimal number of layers and optimal number of kernels in each layer characterizes the structure of ML-MKL. A thoretical study on the optimal structure of ML-MKL model is a future extension for this work.\n\nThe training of ML-MKL framework in the current implementation is performed in a greedy layer-by-layer fashion, by iteratively adding layers. This can be thought of as unsupervised pre-training done in typical deep learning algorithms. Then we can devise a supervised fine-tuning mechanism for this model, by taking class labels into account, which may change either the kernel parameters or weights.\n\nThe deep learning algorithms are found to be particularly effective for learning complex decision functions. Structured output prediction tasks like parse tree prediction, protein segment alignment prediction etc. need very complex decision functions. Thus, the deep multi-layer kernel machines can be studied in such domains.\n\nThe results from KFDA with multi-layer kernels is having some interesting aspects. The algorithm is performing well, either when using a highly non-linear arc-cosine kernel or when very large number of layers are used in the kernel function. The obscurity behind the need of such complex kernels for \ndiscriminant analysis can be explored further.\n", "meta": {"hexsha": "bc6516cc4f6f500055c418aa9782aa1611afded5", "size": 3558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter6.tex", "max_stars_repo_name": "akhilpm/Masters-Project", "max_stars_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_stars_repo_licenses": ["MIT"], "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/chapter6.tex", "max_issues_repo_name": "akhilpm/Masters-Project", "max_issues_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_issues_repo_licenses": ["MIT"], "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/chapter6.tex", "max_forks_repo_name": "akhilpm/Masters-Project", "max_forks_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 177.9, "max_line_length": 1000, "alphanum_fraction": 0.8268690275, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.614479111034609}}
{"text": "\\documentclass[11 pt]{scrartcl}\n\\usepackage[header, margin, koma]{tyler}\n\n\\newcommand{\\hwtitle}{Hard Counting Problems}\n\n\\newif\\ifproblemsol\n\\problemsolfalse\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyhead[l]{\\hwtitle{}}\n\\fancyhead[r]{Tyler Zhu}\n\\cfoot{\\thepage}\n\n\\begin{document} \n\\title{\\Large \\hwtitle{}}\n\\author{\\large Tyler Zhu}\n\\date{\\large\\today}\n\n\\maketitle \n\nThese are some pretty arbitrary, hard counting problems. They are more so for testing your general ability to see connections in counting well than how well you bookkeep. Safe travels.  \n\n\\section{Warm up}\n\\begin{problem}\n    How many cubic polynomials $f(x)$ with positive integer coefficients are there such that $f(1) = 9$?\n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    Let $f(x) = ax^3+bx^2+cx+d$. The only condition on $f(x)$ is that $f(1) = 9$, which means $a + b + c + d = 9$. Since $a,b,c,d$ are positive integers, there are $\\binom{8}{3} = 56$ such polynomials. \n\\end{proof}\n\\fi\n\n\\section{Assorted Candies}\n\\begin{problem}\n    Prove $\\sum_{k=0}^n \\binom{n}{k} 2^k = 3^n$ with a combinatorial argument. \n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    Suppose we're trying to create a $n$-bead string with 3 colors; red, blue and green. We can either have 3 chocies for each spot for a total of $3^n$, or pick the $n-k$ spots which will be red, and then fill in the remaining $k$ spots with either blue or green for a total of $\\binom{n}{k}2^k$ for each choice of $k$. \n\\end{proof}\n\\fi\n\n\\begin{problem}\n    Let $a_1, a_2, \\dots, a_n$ be a sequence of arbitrary natural numbers. Define $b_k$ to be the number of elements $a_i$ for which $a_i \\geq k$. Prove that $a_1 + a_2 + \\dots + a_n = b_1 + b_2 + \\cdots$. \n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    The idea is to double count. Drawing a picture is the best way to see this: for each $a_i$, draw $a_i$ circles vertically. Then the LHS is counting the number of circles going vertically, while the RHS is counting them horizontally. \n    \n    Formally, one way to count is simply to sum the $a_i$'s. Another way to count uses the fact that they are natural numbers. All the $b_i$ start at 0. Then, for any given $a_i$, $b_1$ through $b_{a_i}$ will have all their values increased by $1$, increasing the total on the RHS by $a_i$. Hence the total contributions of all $a_i$ to the RHS is just $a_1 + \\dots + a_n$. \n\\end{proof}\n\\fi\n\n\\begin{problem}\n    How many ways are there to insert $+$’s between the digits of 111111111111111 (fifteen 1’s) so that the result will be a multiple of 30?\n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    No matter how many $+$'s we insert, the result will always be a multiple of $3$ since there are fifteen 1's. For it to be a multiple of 10, we need exactly 10 numbers, which means we're adding 9 $+$'s. There are 14 gaps, so our answer is $\\binom{14}{9}$.\n\\end{proof}\n\\fi\n\n\n\\begin{problem}\n    Compute \n    \\[ \\sum_{n_{60}=0}^2\\sum_{n_{59}=0}^{n_{60}}\\dots \\sum_{n_2=0}^{n_3} \\sum_{n_1=0}^{n_2}\\sum_{n_0=0}^{n_1} 1.\\]\n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    Another way of phrasing the problem is to find the number of solutions to $0\\leq n_0 \\leq n_1 \\leq n_2 \\leq \\dots \\leq n_{60} \\leq 2$. This corresponds to the number of right-up walks on a $61\\times 2$ grid from the bottom left to the top right, which we all know to be $\\binom{63}{2}$. \n    \n    Alternatively, notice that every solution is of the form $(0,\\dots, 0, 1, \\dots, 1, 2, \\dots, 2)$, so we only need to specify the number of 0s, 1s, and 2s. This is equivalent to solving the equation $x+y+z = 61$ for nonnegative $x,y,z$, which (by stars and bars) has $\\binom{63}{2}$ solutions.\n\\end{proof}\n\\fi\n\n\\begin{problem}\n    There’s a new (virtual) game show featuring $N$ people where a few lucky contestants get to compete for the ultimate prize: a roll of toilet paper. The game works as follows: everyone lines up in front of a jar of ping pong balls numbered 1 through 100 and one-by-one randomly select a ball until everyone has one. Then the winning number is announced, and anyone with the winning number wins the prize. \n    \\alphanum\n        \\ii Suppose the winning number is 42. What’s the probability that if $N=3$, then the third person wins the game?\n        \\ii If $N = 100$, what’s the probability that the third person wins the game now? \n        \\ii You and a friend are watching the game (for $N = 100$) and after all of the balls have been drawn, you both decide to bet on the results. Your friend picks contestant 42, thinking they must have the winning number, but before you can pick a contestant, 98 of them groan in realization that they have losing numbers, which leaves you with no choice but to bet on contestant 20. What’s the probability that you win the bet? \n    \\enumend\n\\end{problem}\n\\ifproblemsol\n\\begin{proof}[Solution]\n\\alphanum\n    \\ii By symmetry, $\\frac{1}{100}$. One can also compute it out to be $\\frac{99}{100}\\cdot \\frac{98}{99}\\frac{1}{98} = \\frac{1}{100}$. \n    \\ii As above, by symmetry, $\\frac{1}{100}$. Computation also works. \n    \\ii This is just the Monty Hall problem in disguise, where you choose to switch! Once the other 98 doors (contestant's numbers) were revealed, all of the $\\frac{99}{100}$ probability went into contest 20's chances, so you have a $\\frac{99}{100}$ probability of winning the bet.  \n\\enumend\n\\end{proof}\n\\fi\n\n\n\\section{Dessert}\nThese aren't actually relevant to course material; please don't do them unless you really want to! \n\n\\begin{exercise}\n    Let $(a_1,a_2, \\dots, a_{12})$ be a permutation of $(1,2,\\dots,12)$ for which \n    \\[ a_1>a_2>a_3>a_4>a_5>a_6 \\text{ and } a_6<a_7<a_8<a_9<a_{10}<a_{11}<a_{12}. \\]\n    An example of such a permutation is $(6,5,4,3,2,1,7,8,9,10,11,12)$. Find the number of such permutations. \n\\end{exercise}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    First, $a_6 = 1$ in every permutation, as it must be the smallest number. We can build any such permutation by picking the five numbers that go on the left and filling them in decreasing order. Then the remaining numbers must fill out the other six on the right, so there are $\\binom{11}{5}$ such ways to pick them. \n\\end{proof}\n\\fi\n\n\\begin{exercise}\n    Let $N$ denote the number of $7$-tuples of sets $S_1, S_2, \\dots,S_7$, not necessarily distinct, for which \n    \\[ S_1 \\subseteq S_2 \\subseteq \\cdots \\subseteq S_7 \\subseteq \\{1,2,3,4,5,6,7\\}.\\] \n    Find $N$. \n\\end{exercise}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    For each number, if it appears in a set $S_i$, then it appears in all sets $S_j$ where $j \\geq i$. So for each number, we have 7 ways to pick the first set it starts appearing in, or none at all, for a total of 8 choices. Thus $N = 8^7$. \n\\end{proof}\n\\fi\n\n\\begin{exercise}\n    In a shooting match a marksman must break eight targets arranged in three hanging columns of 3, 3 and 2 targets respectively. Whenever a target is broken, it must be the lowest unbroken target in its column. In how many different orders can the eight targets be broken? \n\\end{exercise}\n\\ifproblemsol\n\\begin{proof}[Solution]\n    Consider a string such as $AAABBBCC$ as a set of instructions, where the appearance of an $A$ means shoot at the lowest hanging target in the first column, $B$ means shoot in the second column, and $C$ means shoot in the third column. Then every permutation of this string gives a new way to break the eight targets, for a total of $\\frac{8!}{3!3!2!}$. \n\\end{proof}\n\\fi\n\n\\end{document}\n", "meta": {"hexsha": "9915041406e030d181bfd3322e5425b0b96aeabd", "size": 7447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CS70/hard_counting/hard_counting.tex", "max_stars_repo_name": "cbugwadia32/course-notes", "max_stars_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-07-20T19:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T01:19:16.000Z", "max_issues_repo_path": "CS70/hard_counting/hard_counting.tex", "max_issues_repo_name": "cbugwadia32/course-notes", "max_issues_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CS70/hard_counting/hard_counting.tex", "max_forks_repo_name": "cbugwadia32/course-notes", "max_forks_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-13T08:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-07T17:21:17.000Z", "avg_line_length": 56.8473282443, "max_line_length": 434, "alphanum_fraction": 0.7114274204, "num_tokens": 2299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303137346446, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6144791071986105}}
{"text": "This document contains a list of steps for approximating uncertainties of measured magnitudes in ASP 3231 project.\n\n\\section{Find uncertainty of star's flux}\n\n\\begin{itemize}\n  \\item Measure twenty background fluxes by choosing apertures in the regions without stars.\n  \\item Note that the radius of the apertures for measuring fluxes should be equal to the radius used to measure the fluxes of the stars in that image.\n  \\item Calculate standard deviation of these fluxes. We will use it to approximate the uncertainty of the flux u(f) from the stars for that image (I don't know why we can do this, but ok).\n\\end{itemize}\n\n\n\\section{Calculate uncertainty of reference star’s magnitude in photometric image}\n\n\\begin{itemize}\n  \\item The magnitude $m_2$ of a reference star is calculated from photometric calibration equation:\n  \\begin{equation}\n  m_2 = z - 2.5 \\log_{10}(f/t) + k \\ A,\n  \\end{equation}\n  where z, and k are constants, $f$ is flux of a reference star measured in photometric image, $A$ is the average air mass index of the stacked images.\n  \\item Next we calculate $u(m_2)$ (uncertainty of $m_2$) by propagating uncertainties  $u(f)$ and $u(A)$. The uncertainty of the air mass $u(A)$ is standard deviation of air mass indices of the stacked images.\n  \n  \\item Assuming $f$ and $A$ are independent, we calculate uncertainty of m2 using first order approximation:\n  \n  \\begin{equation}\n    u(m_2) = \\sqrt{ \\left[ \\frac{2.5}{f} \\frac{1}{\\ln(10)} u(f) \\right]^2 + \\left[ a \\ u(A)\\right]^2}.\n  \\end{equation}\n\\end{itemize}\n\n\n\\section{Calculate uncertainty of star’s magnitude in non-photometric image for one reference star}\n\n\\begin{itemize}\n  \\item The magnitude $m_1$ of a star in non-photometric image is calculated from equation\n  \\begin{equation}\n  m_1 = m_2 - 2.5 \\log_{10} \\left( \\frac{f_1}{f_2} \\right),\n  \\label{eq_star_magnitude}\n  \\end{equation}\n  where $m_2$ is magnitude of a reference star, $f_1$ is the flux of the star we want, and $f_2$ is flux of a reference star. Both fluxes $f_1$ and $f_2$ are measured in non-photometric image. \n  \n  \\item We calculate the uncertainty of $m_1$, assuming all variables in \\autoref{eq_star_magnitude} are independent, and thus using first order approximation \n  \\begin{equation}\n  u(m_1) = \\sqrt{[u(m_2)]^2 + \\left[ 2.5 \\frac{u(f)}{\\ln(10)} \\right]^2 \\left( \\frac{1}{f_1^2} + \\frac{1}{f_2^2} \\right)},\n  \\label{eq_uncertainty_of_magnitude}\n  \\end{equation}\n  where u(f) is the uncertainty of flux measurement in non-photometric image for the star we want.\n\n\\end{itemize}\n\n\n\\section{Calculate final uncertainty of star's magnitude}\n\n\\begin{itemize}\n   \\item We use multiple reference stars to calculate a star's magnitudes using \\autoref{eq_star_magnitude}. So if we have three reference stars $a$, $b$ and $c$, we will calculate three magnitudes for each star: $m_a, m_b, m_c$.\n  \n  \\item We calculate the final magnitude of the star $m$ by taking the middle magnitude of $m_a, m_b, m_c$.\n  \n  \n  \\item For the uncertainty of the magnitude we take  the uncertainty of the middle magnitude. Not that we do not calculate the average of $m_a, m_b, m_c$, because if we do so and use the simple error propagation formula we will get:\n  \\[\n  u(m) = \\frac{\\sqrt{u(m_a)^2 + u(m_b)^2 + u(m_c)^2}}{3}.\n  \\]\n  \n  This approach assumes $m_a, m_b, m_c$ are independent measurements. But this $m_a, m_b, m_c$  are not independent, since in each measurement the star's flux $f_1$ is the same (\\autoref{eq_star_magnitude}), and $m_2$ and $f_2$ are also the same for all stars. Therefore, if we did that, our uncertainty would be significantly underestimated.\n  \n  \\item We report star's magnitude $m$, its uncertainty $u(m)$ and publish in The International Journal Of Tourism Sciences.\n\n\\end{itemize}\n\n", "meta": {"hexsha": "4611bb3a05efca6a6a19b18cffd40082684bc32f", "size": 3753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/approximating_uncertainties/parts/work.tex", "max_stars_repo_name": "evgenyneu/asp3231_project", "max_stars_repo_head_hexsha": "59e8e3c87bd7a585e9678d1ce8ba5a573af10997", "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/approximating_uncertainties/parts/work.tex", "max_issues_repo_name": "evgenyneu/asp3231_project", "max_issues_repo_head_hexsha": "59e8e3c87bd7a585e9678d1ce8ba5a573af10997", "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": "doc/approximating_uncertainties/parts/work.tex", "max_forks_repo_name": "evgenyneu/asp3231_project", "max_forks_repo_head_hexsha": "59e8e3c87bd7a585e9678d1ce8ba5a573af10997", "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": 54.3913043478, "max_line_length": 342, "alphanum_fraction": 0.7287503331, "num_tokens": 1086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6143857640418103}}
{"text": "\nIn the last chapter, we reviewed some algorithms for solving unconstrained optimization problems, especially those summation form problem arising from machine learning.\nIn this chapter we care about optimization problems with regularization term, which is a special case of the composite optimization problem.\nRegularization term may helps to have special structure of solutions, like sparsity.\nFirstly, we will introduce proximal gradient method, since it is one of the most fundamental method for solving composite problem.\nIt also called \\emph{Forward-Backward splitting} method from the point of view of operators.\nAnd then we will introduce simple dual averaging method and regularized dual averaging method, as well as the connections between algorithms.\nFinally, we will introduce results of these algorithms when solves $\\ell_1$ regularized problem, and give out some convergence analysis.\n\n\n\\section{Proximal Gradient}\nDefinition of proximal operator:\n\\begin{equation}\n\t\\begin{split}\n\t\tProx_{\\alpha R} (y)\n\t\t& =\\mathop{\\arg \\min}_x \\left\\lbrace \\frac{1}{2\\alpha} \\|x-y\\|^2_2+R(x) \\right \\rbrace\\\\\n\t\t& =\\mathop{\\arg \\min}_x \\left\\lbrace \\frac{1}{2} \\|x-y\\|^2_2+\\alpha R(x) \\right \\rbrace.\n\t\\end{split}\n\\end{equation}\n\n\\subsection{Convex problem}\nThe problem\n\\begin{equation}\n\t\\min_w \\phi(w),\n\\end{equation}\nwhere $\\phi$ is convex (convexity $\\mu$) and smooth (Lipschitz $L$ of gradient).\n\\begin{enumerate}\n\t\\item Convexity is local \\emph{lower} first ($\\mu=0$) or second ($\\mu>0$) order bound of function $\\phi$.\n\t\\item Lipschitz continuous of gradient is local \\emph{upper} second order bound of $\\phi$.\n\t\\item $\\mu \\leq L$.\n\\end{enumerate}\n\n\\subsection{Proximal gradient  (PG) for convex problem}\nProximal gradient method solves subproblem which the objective function is second order approximation to $\\phi$.\nThe iteration takes the following form:\n\\begin{equation}\n\t\\begin{split}\n\t\tw_{t+1}&= \\mathop{\\arg \\min}_w \\left\\lbrace \\phi(w_t)+\\nabla \\phi(w_t)^T (w-w_t)+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 \\right \\rbrace\\\\\n\t\t&=\\mathop{\\arg \\min}_w \\left\\lbrace \\nabla \\phi(w_t)^T w+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 \\right \\rbrace\\\\\n\t\t&=\\mathop{\\arg \\min}_w \\left\\lbrace \\frac{1}{2\\alpha_t} \\|w-(w_t-\\alpha_t \\nabla \\phi(x_t))\\|^2_2 \\right \\rbrace\\\\\n\t\t&=Prox_{0} (w_t-\\alpha_t \\nabla \\phi(w_t)).\n\t\\end{split}\n\\end{equation}\nHere $\\alpha_t$ is parameter.\nAnd regularization term can be viewed as $0$.\nIt is equivalent to explicit gradient descent\n\\begin{equation}\n\tw_{t+1}=w_t -\\alpha_t \\nabla \\phi(w_{t}).\n\\end{equation}\n\nHere\n$$\\alpha_t=\\frac{1}{\\lambda_{\\max} (\\nabla^2 \\phi(w))}$$\nwas suggested.\n\n\\subsection{Proximal point algorithm (PPA) for convex problem}\nProximal point algorithm\n\\begin{equation}\n\t\\begin{split}\n\t\tw_{t+1}&= \\mathop{\\arg \\min}_w \\left\\lbrace \\phi(w)+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 \\right \\rbrace\\\\\n\t\t&= Prox_{\\alpha \\phi} (w_t). \n\t\\end{split}\n\\end{equation}\nIt is equivalent to implicit gradient descent\n\\begin{equation}\n\tw_{t+1}=w_t -\\alpha_t \\nabla \\phi(w_{t+1}).\n\\end{equation}\n\nAnd these method can combined with stochastic technique for summation problem, then we can easily obtain proximal stochastic gradient and proximal stochastic point algorithm.\n\n\\subsection{Convex composite problem}\nThe composite problem has the following form\n\\begin{equation}\\label{composite problem}\n\t\\min_w \\phi(w)=f(w)+\\Psi(w),\n\\end{equation}\nwhere $f$ is convex (convexity $\\mu$) and smooth (Lipschitz $L$ of gradient) and the regularizer $\\Psi$ is convex and nonsmooth.\nHere $\\Psi$ can be, for example\n\\begin{enumerate}\n\t\\item $\\ell_1$ regularization: $\\lambda \\|w\\|_1$.\n\t$\\lambda$ is parameter determine the sparsity of solution.\n\tWe will discuss some results when $\\Psi(w)=\\lambda \\|w\\|_1$ in next section.\n\t\\item $\\ell_2$ regularization: $\\frac{\\lambda}{2} \\|w\\|_2$. $\\ell_2$ regularizer also called weight decay.\n\tIt helps to avoid overfitting of machine learning models.\n\t\\item mixed regularization: $\\lambda_1 \\|w\\|_1 + \\frac{\\lambda_2}{2} \\|w\\|_2$.\n\t\\item Indicator function.\n\\end{enumerate}\n\nRecall that the first order necessary condition\n\\begin{equation}\n\t0 \\in \\nabla f(w_\\star) + \\partial \\Psi(w_\\star).\n\\end{equation}\n\\subsection{Gradient descent (GD) for convex composite problem}\nExplicit gradient descent applied for (\\ref{composite problem}) has\n\\begin{equation}\n\tw_{t+1} = w_t -\\alpha_t (\\nabla f(x_t) + \\partial \\Psi(w_{t})).\n\\end{equation}\nIt is equal to\n\\begin{equation}\n\t\\frac{1}{\\alpha_t} (w_{t+1}-w_t) +\\nabla \\Psi(w_t) + \\partial \\Psi(w_{t})=0.\n\\end{equation}\nThe subgradient operator works on $\\Psi(w_t)$, so it will not helps to obtain special structure of next point $w_{t+1}$.\n\n\\subsection{Proximal gradient for convex composite problem}\n\\begin{align}\n\tw_{t+1}&= \\mathop{\\arg \\min}_w \\left\\lbrace f(w_t)+\\nabla f(w_t)^T (w-w_t)+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 +\\Psi(w) \\right \\rbrace\\\\\n\t&=\\mathop{\\arg \\min}_w \\left\\lbrace \\nabla f(w_t)^T w+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 +\\Psi(w) \\right \\rbrace\\\\\n\t&=\\mathop{\\arg \\min}_w \\left\\lbrace \\frac{1}{2\\alpha_t} \\|w-(w_t-\\alpha_t \\nabla \\Psi(w_t))\\|^2_2 +\\Psi(w) \\right \\rbrace\\\\\n\t&=Prox_{\\alpha_t \\Psi} (w_t-\\alpha_t \\nabla f(w_t)).\n\\end{align}\nIt is equivalent to solve the equation (KKT condition of subproblem)\n\\begin{equation}\n\t\\nabla f(w_t) + \\frac{1}{\\alpha_t} (w_{t+1}-w_t) +\\partial \\Psi(w_{t+1}) = 0.\n\\end{equation}\nThat is implicit gradient descent.\n\\begin{equation}\n\tw_{t+1} = w_t -\\alpha_t (\\nabla \\Psi(w_t) + \\partial \\Psi(w_{t+1})).\n\\end{equation}\nWe can also write it in the formulation:\n\\begin{equation}\n\t\\frac{1}{\\alpha_t} (w_{t+1}-w_t) +\\nabla f(w_t) + \\partial \\Psi(w_{t+1})=0,\n\\end{equation}\nand it actually using the approximation\n\\begin{equation}\n\t\\frac{1}{\\alpha_t} (w_{t+1}-w_t) +\\nabla f(w_t) \\approx \\nabla f(w_{t+1}).\n\\end{equation}\nFrom the formula we can see, PG can produce better sparsity than GD.\nBecause the function $\\partial R(\\cdot)$ operates on $w_t$ in GD, while operates on $w_{t+1}$ in PG.\n\n\n\\section{Simple dual averaging and Regularized dual averaging algorithms}\n\n\\subsection{Empirical risk minimization}\nThe expected risk minimization arising from machine learning has the following form:\n\\begin{equation}\\label{expected risk minimization}\n\t\\min_{w}~~\\left\\lbrace \\phi(w)= \\mathbf{E}_z f(w,z)\\right\\rbrace,\n\\end{equation}\nwhere $z$ is an input-output pair of data, $f(w,z)$ is loss function.\n\nAnd the regularized expected risk minimization has the following form\n\\begin{equation}\\label{regularized expected risk minimization}\n\t\\min_{w}~~\\left\\lbrace \\phi(w)= \\mathbf{E}_z f(w,z)+\\Psi(w)\\right\\rbrace,\n\\end{equation}\nwhere $\\Psi(w)$ is a regularization term, for example, $\\ell_1$ regularization in obtaining sparse solutions.\n\nThe empirical risk minimization is approximation of (\\ref{expected risk minimization})\n\\begin{equation}\\label{approximated optmization}\n\t\\min_{w}~~\\left\\lbrace \\phi(w)=\\frac{1}{T}\\sum_{t=1}^{T} f(w,z_t)\\right\\rbrace,\n\\end{equation}\n\nAnd the regularized empirical risk minimization\n\\begin{equation}\\label{approximated regularized optimization}\n\t\\min_{w}~~\\left\\lbrace \\phi(w)=\\frac{1}{T} \\sum_{t=1}^{T} f(w,z_t)+\\Psi(w)\\right\\rbrace,\n\\end{equation}\nwhere $f$ is convex (convexity $\\mu$) and smooth (Lipschitz $L$ of gradient) and $\\Psi$ is convex but nonsmooth.\n%Here $\\Psi$ can be, for example\n%\\begin{enumerate}\n%\t\\item $\\lambda \\|x\\|_1$.\n%\t$\\lambda$ is parameter determine the sparsity of solution.\n%\tWe will take $R(x)=\\lambda \\|x\\|_1$ as example.\n%\t\\item Indicator function.\n%\\end{enumerate}\n\n%\\begin{equation}\n%\\min_w f(w)+\\lambda \\|w\\|_1\n%\\end{equation}\n\n\\subsection{Simple dual averaging (SDA)}\nSimple dual averaging method takes the form\n\\begin{equation}\n\tw_{t+1} = \\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{t}\\sum_{\\tau=1}^{t} \\left<g_{\\tau}(w_\\tau), w \\right> + \\frac{\\beta_t}{t} h(w) \\right\\}.\n\\end{equation}\n\nSince $g_\\tau(w_\\tau)$ is constant in current iteration, we use $g_\\tau$ instead for simplicity in the following.\nIf we choose $h(w)=\\frac{1}{2} \\|w-w_0\\|^2_2$, where $w_0=\\arg \\min\\limits_w h(w)$ is also an initial point then we can conclude\n\\begin{equation}\n\tw_{t+1}=w_0 - \\frac{1}{\\beta_t} \\sum_{\\tau=1}^{t} g_\\tau=w_0-\\frac{t}{\\beta_t} \\bar g_t.\n\\end{equation}\nWe assume $\\beta_t=t^\\alpha$.\nThen, we can write SDA as recursion\n\\begin{equation}\\label{RDA}\n\t\\begin{split}\n\t\tw_{t+1} & =w_0- \\frac{1}{t^{\\alpha}} \\sum_{\\tau=1}^{t} g_\\tau\\\\\n\t\t& =w_0 -\\frac{1}{t^{\\alpha}} \\left( \\frac{(t-1)^{\\alpha}}{(t-1)^{\\alpha}} \\sum_{\\tau=1}^{t-1} g_\\tau +g_t \\right)\\\\\n\t\t& =\\left( 1-\\frac{(t-1)^{\\alpha}}{t^{\\alpha}} \\right) w_0+ \\frac{(t-1)^{\\alpha}}{t^{\\alpha}}\\left( w_0 - \\frac{1}{(t-1)^\\alpha}\\sum_{\\tau=1}^{t} g_\\tau \\right) - \\frac{1}{t^{\\alpha}} g_t\\\\\n\t\t& =\\left( 1-\\left( 1-\\frac{1}{t} \\right)^{\\alpha} \\right) w_0 + \\left( 1-\\frac{1}{t} \\right)^{\\alpha} w_t -\\frac{1}{t^{\\alpha}} g_t .\n\t\\end{split}\n\\end{equation}\nHere $\\left( 1-\\left( 1-\\frac{1}{t} \\right)^{\\alpha} \\right) \\rightarrow 0$ and $\\left( 1-\\frac{1}{t} \\right)^{\\alpha} \\rightarrow 1$ as $t \\rightarrow \\infty$.\nSo SDA can be viewed as perturbation of SGD.\nWe proved convergence of SDA in stochastic setting in the appendix.\n\n\\subsection{Regularized dual averaging (RDA)}\t\nEach iteration of regularized dual averaging method takes \n\\begin{equation}\\label{RDA subproblem}\n\tw_{t+1}=\\mathop{\\arg\\min}_w \\left\\{\\frac{1}{t} \\sum_{\\tau=1}^{t} \\left<g_{\\tau},w\\right>+\\Psi(w)+\\frac{\\beta_t}{t}h(w)\\right\\}.\n\\end{equation}\nThe first term $\\sum_{\\tau=1}^{t} \\left<g_{\\tau},w\\right>$ is linear function obtained by averaging all previous subgradients.\nThe third term $h(w)$ is strongly convex function, and $\\beta_t$ is a nonnegative and nondecreasing sequence which determines the convergence of algorithm.\nThe closed form solution of subproblem (\\ref{RDA subproblem}) can be found such that the computational effort per iteration is only $O(n)$, the same as the SGD method.\n\n\\begin{enumerate}\n\t\\item Proximal gradient method (PG) can be written in forward backward splitting (FOBOS)\n\t\\begin{equation}\n\t\tw_{t+1}=\\mathop{\\arg \\min}_w \\left\\{ \\left<g_t, w \\right> + \\Psi(w)+\\frac{1}{2\\alpha_t}\\|w-w_t\\|_2^2  \\right\\}.\n\t\\end{equation}\n\t\\begin{equation*}\n\t\t\\Updownarrow\n\t\\end{equation*}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tw_{t+\\frac{1}{2}} &=w_t - \\alpha_t g_t \\\\\n\t\t\tw_{t+1} &=\\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{2}\\|w-w_{t+\\frac{1}{2}}\\|^2_2 +\\alpha_t \\Psi(w) \\right\\}.\n\t\t\\end{split}\n\t\\end{equation}\n\tHere $\\alpha_t=\\frac{1}{\\sqrt{t}}$ to obtain best convergence rate.\n\t\n\t\\item RDA also can be written in the form of forward-backward splitting (when $h(w)=\\frac{1}{2}\\|w-w_0\\|^2_2$):\n\t\\begin{align}\n\t\tw_{t+1}&=\\mathop{\\arg\\min}_w \\left\\{ \\left<\\bar g_t,w\\right>+\\frac{\\beta_t}{2t}\\|w-w_0\\|^2_2+\\Psi(w)\\right\\}\\\\\n\t\t& =\\mathop{\\arg\\min}_w \\left\\{ \\frac{\\beta_t}{2t} \\frac{2t}{\\beta_t}\\bar g_t^T w +\\frac{\\beta_t}{2t}\\|w-w_0\\|^2_2+\\Psi(w)\\right\\}\\\\\n\t\t& =\\mathop{\\arg\\min}_w \\left\\{ \\frac{\\beta_t}{2t}\\|w-(w_0+\\frac{t}{\\beta_t} \\bar g_t)\\|^2_2+\\Psi(w)\\right\\}\\\\\n\t\t&=\\mathop{\\arg\\min}_w \\left\\{ \\frac{1}{2}\\|w-(w_0+\\frac{t}{\\beta_t} \\bar g_t)\\|^2_2+\\frac{t}{\\beta_t}\\Psi(w)\\right\\}\n\t\\end{align}\n\t\\begin{equation*}\n\t\t\\Updownarrow\n\t\\end{equation*}\n\t\\begin{align}\n\t\tw_{t+\\frac{1}{2}} &=w_0-\\frac{t}{\\beta_t} \\bar g_t \\\\\n\t\tw_{t+1} &= \\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{2}\\|w-w_{t+\\frac{1}{2}}\\|^2_2 + \\frac{t}{\\beta_t}\\Psi(w) \\right\\}.\n\t\\end{align}\n\tThe forward operator is actually SDA method.\n\tHere $\\beta_t = \\sqrt{t}$ when $\\Psi$ is convex, and $\\beta_t=\\ln t$ when $\\Psi$ is strongly convex.\n\\end{enumerate}\n\n\\section{$\\ell_1$ regularization and sparsity}\nIn this section, we will consider a kind special regularized problem with $\\ell_1$ regularization.\n\\begin{equation}\n\t\\min_w f(w)+\\lambda \\|w\\|_1\n\\end{equation}\nSince $\\ell_1$ regularization can produce sparse solution.\n\nHere we give out the closed form solution of proximal gradient method and RDA applied for the $\\ell_1$ regularization\n\n\n\\begin{enumerate}\n\t\\item Proximal gradient:\n\t\\begin{equation}\n\t\tw_{t+1}=\\mathop{\\arg \\min}_w \\left\\lbrace g_t^T w+\\frac{1}{2\\alpha_t} \\|w-w_t\\|^2_2 +\\lambda \\|w\\|_1 \\right \\rbrace\n\t\\end{equation}\n\tThe entry-wise closed form solution is\n\t\\begin{equation}\n\t\tw_{t+1}^{(i)}=\n\t\t\\begin{cases}\n\t\t\tw_t^{(i)}-\\alpha_t (g_t^{(i)} +\\lambda), & w_t^{(i)}-\\alpha_t g_t^{(i)} > \\alpha_t \\lambda\\\\\n\t\t\t0, & |w_t^{(i)}-\\alpha_t g_t^{(i)}| \\leq \\alpha_t \\lambda\\\\\n\t\t\tw_t^{(i)}-\\alpha_t (g_t^{(i)} -\\lambda), & w_t^{(i)}-\\alpha_t g_t^{(i)} < -\\alpha_t \\lambda\n\t\t\\end{cases}\n\t\\end{equation}\n\tHere $\\alpha_t=\\frac{1}{\\sqrt{t}}$.\n\t\n\t\\item RDA:\n\t\\begin{equation}\n\t\tw_{t+1}=\\mathop{\\arg \\min}_w \\left\\lbrace \\bar g_t^T w+\\frac{\\beta_t}{2t} \\|w-w_0\\|^2_2 +\\lambda \\|w\\|_1 \\right \\rbrace\n\t\\end{equation}\n\tThe entry-wise closed form solution:\n\t\\begin{equation}\n\t\tw_{t+1}^{(i)}=\n\t\t\\begin{cases}\n\t\t\tw_0^{(i)}-\\frac{t}{\\beta_t} (\\bar g_t^{(i)} +\\lambda), & w_0^{(i)}-\\frac{t}{\\beta_t}\\bar g_t^{(i)} > \\frac{t}{\\beta_t}\\lambda\\\\\n\t\t\t0, & | w_0^{(i)}-\\frac{t}{\\beta_t}\\bar g_t^{(i)}| \\leq  \\frac{t}{\\beta_t} \\lambda\\\\\n\t\t\tw_0^{(i)}-\\frac{t}{\\beta_t} (\\bar g_t^{(i)} -\\lambda), & w_0^{(i)}-\\frac{t}{\\beta_t}\\bar g_t^{(i)} < - \\frac{t}{\\beta_t}\\lambda\n\t\t\\end{cases}\n\t\\end{equation}\n\tHere $\\frac{t}{\\beta_t}=\\sqrt{t}$.\n\t\n\t\\item We can conclude the general case from above. \n\tAssume we have the forward-backward splitting\n\t\\begin{align}\n\t\tw_{t+\\frac{1}{2}} & \\\\\n\t\tw_{t+1} &= \\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{2}\\|w-w_{t+\\frac{1}{2}}\\|^2_2 +  \\theta_t\\Psi(w) \\right\\}.\n\t\\end{align}\n\tThen, the entry-wise closed form solution has the form:\n\t\\begin{equation}\n\t\tw_{t+1}^{(i)}=\n\t\t\\begin{cases}\n\t\t\tw_{t+1/2}^{(i)}- \\theta_t \\lambda, & w_{t+1/2}^{(i)} > \\theta_t\\lambda\\\\\n\t\t\t0, & | w_{t+1/2}^{(i)}| \\leq  \\theta_t \\lambda\\\\\n\t\t\tw_{t+1/2}^{(i)} +\\theta_t\\lambda, & w_{t+1/2}^{(i)} < - \\theta_t\\lambda\n\t\t\\end{cases}\n\t\\end{equation}\n\tThe coefficient $\\theta_t$ of $\\Psi$ also determine the sparsity of the solution.\n\tThere is a trade-off between fast convergence and sparsity of solution.\n\tLarge $\\theta_t$ in the backward operator would produce more sparse solution while it takes $w_{t+1}$ far away from $w_{t+1/2}$.\n\t\\textcolor{red}{Question: what is the best choice of $\\theta_t$ to guarantee both fast convergence and sparsity of solution.}\n\t\n\t\\item \n\tTry\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\tw_{t+\\frac{1}{2}} &=w_t -  \\frac{1}{\\sqrt{t}} g_t \\\\\n\t\t\tw_{t+1} &=\\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{2}\\|w-w_{t+\\frac{1}{2}}\\|^2_2 +\\sqrt{t} \\Psi(w) \\right\\}.\n\t\t\\end{split}\n\t\\end{equation}\n\tThe entry-wise closed form solution is\n\t\\begin{equation}\n\t\tw_{t+1}^{(i)}=\n\t\t\\begin{cases}\n\t\t\tw_t^{(i)}-\\alpha_t g_t^{(i)} -\\sqrt{t}\\lambda, & w_t^{(i)}-\\alpha_t g_t^{(i)} > \\sqrt{t} \\lambda\\\\\n\t\t\t0, & |w_t^{(i)}-\\alpha_t g_t^{(i)}| \\leq \\sqrt{t} \\lambda\\\\\n\t\t\tw_t^{(i)}-\\alpha_t g_t^{(i)} +\\sqrt{t}\\lambda, & w_t^{(i)}-\\alpha_t g_t^{(i)} < -\\sqrt{t} \\lambda\n\t\t\\end{cases}\n\t\\end{equation}\n\tIt's equivalent to\n\t\\begin{equation}\n\t\tw_{t+1}=\\mathop{\\arg \\min}_w \\left\\lbrace g_t^T w+\\frac{\\sqrt{t}}{2} \\|w-w_t\\|^2_2 + t\\lambda \\|w\\|_1 \\right \\rbrace\n\t\\end{equation}\n\tIt's approximation of\n\t\\begin{equation}\n\t\tf(w) + t \\lambda \\|w\\|_1.\n\t\\end{equation}\n\tWe can easily conclude that this iteration will not converge.\n\t\n\t\\item Why RDA takes $\\sqrt{t}$ threshold and Proximal gradient takes $\\frac{1}{\\sqrt{t}}$ and they all converges?\n\\end{enumerate}\n\n\nNow comparing the threshold $\\lambda_{PG}=\\alpha_t \\lambda$ of PG and the threshold $\\lambda_{RDA}=\\lambda$ of RDA:\nwith $\\alpha_t=\\frac{1}{\\sqrt{t}}$, we have $\\lambda_{PG} \\rightarrow 0$ as $t \\rightarrow 0$.\nIt is clear that RDA uses a much more aggressive truncation threshold, thus is able to generate significantly more sparse solutions.\n\n\\section{Convergence analysis}\n\\subsection{Convergence of SDA}\nThroughout we assume\n\\begin{enumerate}\n\t\\item SDA method applied for empirical risk minimization, so in this section, we discuss\n\t\\begin{equation*}\n\t\t\\phi(w)=\\frac{1}{T}\\sum_{t=1}^{T} f(w,z_t)\n\t\\end{equation*}\n\t\n\t\\item\n\t$\\phi(w)$ is differentiable and strongly convex. So there exists a constant $\\mu >0$ such that \n\t\\begin{equation}\n\t\t\\phi(y) \\geq \\phi(x) + \\nabla \\phi(x)^T (y-x)+\\frac{\\mu}{2} \\|y-x\\|^2.\n\t\\end{equation}\n\t\n\t\\item\n\t$\\nabla \\phi$ is Lipschitz so that\n\t\\begin{equation}\n\t\t\\|\\nabla \\phi(x) - \\nabla \\phi(y)\\| \\leq L \\|x-y\\|.\n\t\\end{equation}\n\tAnd we can obtain the following relation:\n\t\\begin{equation}\n\t\t\\phi(y) \\leq \\phi(x)+\\nabla \\phi(x)^T (y-x) +\\frac{L}{2} \\|y-x\\|.\n\t\\end{equation}\n\tThus $\\mu \\leq L$.\n\t\n\t\\item\n\t$g_t(w) = \\nabla f(w,z_t)$ and $\\|g_t\\|\\leq M$ for all $w$ and $z_t$.\n\t\n\t\\item\n\t$\\|w_0- w_\\star\\| \\leq D$.\n\t\n\t\\item Let $\\partial g(w)$ denote the subgradient set of $f$ at $w$, namely,\n\t\n\t\n\\end{enumerate}\nOther important remarks:\n\\begin{enumerate}\n\t\\item $w_0=0$ will not improve the convergence rate of SDA, because $\\|w_0-w_\\star\\|$ not changed in this case.\n\t\n\t\\item Another important technique in our proof is\n\t\\begin{equation}\n\t\t2\\langle a, b\\rangle \\leq \\epsilon a^2 +\\frac{1}{\\epsilon} b^2\n\t\\end{equation}\n\twhere $\\epsilon>0$.\n\t\n\t\\item Cauchy-Shwartz inequality:\n\t\\begin{equation}\n\t\t\\langle a, b\\rangle \\leq \\|a\\| \\|b\\|\n\t\\end{equation}\n\t\n\t\\item $\\|a+b\\| \\leq \\|a\\|+\\|b\\|$\n\\end{enumerate}\nFor simplicity, denote SDA as following iteration\n\\begin{equation}\n\tw_{t+1}=(1-\\lambda_t)w_0+\\lambda_t w_t - \\gamma_t g_t,\n\\end{equation}\nwhere $\\lambda_t= \\left( 1-\\frac{1}{t} \\right)^\\alpha <1$ and $\\gamma_t= \\frac{1}{t^\\alpha}$.\n\n\\subsubsection{Convergence of $\\mathbb{E}\\left[ \\phi(\\bar{w}) \\right] -\\phi(w_\\star)$}\nLet's make no assumptions about strongly convexity of $\\phi(w)$ here, i.e. $\\mu=0$.\n\n\\begin{lemma}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\\\\\n\t\t\t&\\leq\n\t\t\t\\lambda_t\\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\n\t\t\t+\\gamma_t(\\gamma_t+\\lambda_t-1) M^2 + (1-\\lambda_t)(1-\\gamma_t) D^2.\n\t\t\\end{split}\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tWe have\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[ \\|(1-\\lambda_t)w_0+\\lambda_t w_t - \\gamma_t g_t - w_\\star\\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[ \\| \\lambda_t(w_t-w_\\star) -\\gamma_t g_t +(1-\\lambda_t)(w_0-w_\\star)\\|^2 \\right]\\\\\n\t\t\\notag\n\t\t&=\\mathbb{E}\\left[ \\|\\lambda_t(w_t-w_\\star) - \\gamma_t g_t\\|^2 \\right]\n\t\t+2\\mathbb{E}\\left[ \\left<\\lambda_t(w_t-w_\\star) - \\gamma_t g_t, (1-\\lambda_t)(w_0-w_\\star) \\right> \\right]\\\\ \\label{ineq}\n\t\t&+\\mathbb{E}\\left[ \\|(1-\\lambda_t)(w_0-w_\\star)\\|^2 \\right].\n\t\\end{align}\n\tThe first term in (\\ref{ineq}) has\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[ \\|\\lambda_t(w_t-w_\\star) - \\gamma_t g_t\\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[ \\| \\lambda_t(w_t-w_\\star) \\|^2 \\right]-\n\t\t2\\mathbb{E}\\left[ \\left<\\lambda_t(w_t-w_\\star),\\gamma_t g_t \\right> \\right]+\\mathbb{E}\\left[ \\|\\gamma_t g_t\\|^2 \\right]\\\\\n\t\t&\\leq \\lambda_t^2 \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\left<w_t-w_\\star,g_t \\right> \\right]\n\t\t+\\gamma_t^2 M^2\\\\\n\t\t\\label{ineq1.1}\n\t\t&=\\lambda_t^2 \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\left<\\nabla \\phi(w_t),w_t-w_\\star \\right> \\right]\n\t\t+\\gamma_t^2 M^2\\\\\n\t\t\\label{ineq1.2}\n\t\t&\\leq \\lambda_t^2 \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]+\\gamma_t^2 M^2.\n\t\\end{align}\n\t(\\ref{ineq1.1}) follows because...\n\t(\\ref{ineq1.2}) is a consequence of the inequality\n\t\\begin{equation}\n\t\t\\left<\\nabla\\phi(w_t), w_t-w_\\star \\right> \\geq \\phi(w_t)-\\phi(w_\\star).\n\t\\end{equation}\n\twhich holds because $\\phi$ is convex.\n\t\n\tThe second term in (\\ref{ineq}) has\n\t\\begin{align}\n\t\t&2\\mathbb{E}\\left[ \\left<\\lambda_t(w_t-w_\\star) - \\gamma_t g_t,(1-\\lambda_t)(w_0-w_\\star) \\right> \\right]\\\\\n\t\t&=2\\lambda_t(1-\\lambda_t)\\mathbb{E}\\left[ \\left<w_t-w_\\star,w_0-w_\\star \\right> \\right]\n\t\t-2\\gamma_t(1-\\lambda_t) \\mathbb{E}\\left[ \\left<g_t,w_0-w_\\star \\right> \\right]\\\\\n\t\t&\\leq \\lambda_t(1-\\lambda_t) \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2+\\|w_0-w_\\star\\|^2 \\right]\n\t\t+\\gamma_t(1-\\lambda_t) \\color{red}{\\mathbb{E}\\left[ \\|g_t\\|^2+\\|w_0-w_\\star\\|^2 \\right]}\\\\\n\t\t&= \\lambda_t(1-\\lambda_t) \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2\\right]+ \\lambda_t(1-\\lambda_t)D^2 +\\gamma_t(1-\\lambda_t)(M^2+D^2).\n\t\\end{align}\n\t\n\tThe last term in (\\ref{ineq}) has\n\t\\begin{align}\n\t\t\\mathbb{E}\\left[ \\|(1-\\lambda_t)(w_0-w_\\star)\\|^2 \\right]\\leq (1-\\lambda_t)^2 D^2.\n\t\\end{align}\n\t\n\tSummary above, we have\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\\\\\n\t\t\\notag\n\t\t&\\leq \\lambda_t^2 \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]+\\gamma_t^2 M^2\n\t\t+\\lambda_t(1-\\lambda_t) \\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2\\right]\\\\\n\t\t&+ \\lambda_t(1-\\lambda_t)D^2 + \\gamma_t(1-\\lambda_t)(M^2+D^2)\n\t\t+ (1-\\lambda_t)^2 D^2\\\\\n\t\t&=\\lambda_t\\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\n\t\t+\\gamma_t(\\gamma_t-\\lambda_t+1) M^2 + (1-\\lambda_t)(1+\\gamma_t) D^2.\n\t\\end{align}\n\\end{proof}\n\n\\begin{theorem}\n\t\\begin{equation}\n\t\t\\mathbb{E}\\left[\\phi(\\bar{w}) \\right]-\\phi(w_\\star) \\leq\n\t\t\\frac{D^2+M^2\\sum_{t=0}^{n}\\frac{\\gamma_t^2}{\\lambda_t}\n\t\t\t+(M^2+D^2)\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}\n\t\t\t+D^2\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}}{2\\sum_{t=0}^{n}\\gamma_t}\n\t\\end{equation}\n\twhere $\\bar{w}:=(\\sum_{t=0}^{n}\\gamma_t)^{-1} \\sum_{t=0}^{n}\\gamma_t w_t$.\n\\end{theorem}\n\\begin{proof}\n\tSince $\\lambda_t<1$, we have\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\lambda_t \\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\\\\\n\t\t\t&\\leq \\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\\\\\n\t\t\t&\\leq\n\t\t\t\\lambda_t\\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t\t-2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\n\t\t\t+\\gamma_t(\\gamma_t - \\lambda_t+1) M^2 + (1-\\lambda_t)(1+\\gamma_t) D^2.\n\t\t\\end{split}\n\t\\end{equation}\n\tArranging the bound: by telescoping $t$ from $0$ to $n$,\n\t\\begin{equation}\\label{ineq2}\n\t\t\\begin{split}\n\t\t\t&2\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\\\\\n\t\t\t&\\leq -\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\n\t\t\t+\\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{\n\t\t\t\t\\gamma_t(\\gamma_t-\\lambda_t+1) M^2 + (1-\\lambda_t)(1+\\gamma_t) D^2\n\t\t\t}{\\lambda_t}\\\\\n\t\t\t&=-\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star \\|^2 \\right]\n\t\t\t+\\mathbb{E}\\left[ \\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{M^2\\gamma_t^2+\\gamma_t(1-\\lambda_t)\\left( M^2+D^2 \\right)+(1-\\lambda_t)D^2}{\\lambda_t},\n\t\t\\end{split}\n\t\\end{equation}\n\twe have\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&2\\sum_{t=0}^{n} \\gamma_t \\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\\\\\n\t\t\t&\\leq\n\t\t\t-\\mathbb{E}\\left[ \\|w_{n+1}-w_\\star\\|^2-\\|w_0-w_\\star\\|^2 \\right]\\\\\n\t\t\t&+M^2\\sum_{t=0}^{n}\\frac{\\gamma_t^2}{\\lambda_t}\n\t\t\t+(M^2+D^2)\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}\n\t\t\t+D^2\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}\n\t\t\\end{split}\n\t\\end{equation}\n\tand then dividing by the sum of $\\gamma_t$, we have for any $n$\n\t\\begin{equation}\n\t\t\\frac{1}{\\sum_{t=0}^{n}\\gamma_t} \\sum_{t=0}^{n}\\gamma_t\\mathbb{E}\\left[ \\phi(w_t)-\\phi(w_\\star) \\right]\n\t\t\\leq\n\t\t\\frac{D^2+M^2\\sum_{t=0}^{n}\\frac{\\gamma_t^2}{\\lambda_t}\n\t\t\t+(M^2+D^2)\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}\n\t\t\t+D^2\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}}{2\\sum_{t=0}^{n}\\gamma_t}.\n\t\\end{equation}\n\tThen, by convexity (Jensen's inequality), we have\n\t\\begin{equation}\n\t\t\\mathbb{E}\\left[\\phi(\\bar{w}) \\right]-\\phi(w_\\star) \\leq\n\t\t\\frac{D^2+M^2\\sum_{t=0}^{n}\\frac{\\gamma_t^2}{\\lambda_t}\n\t\t\t+(M^2+D^2)\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}\n\t\t\t+D^2\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}}{2\\sum_{t=0}^{n}\\gamma_t}\n\t\\end{equation}\n\\end{proof}\n\nSince $\\lambda_t=\\left( 1-\\frac{1}{t} \\right)^\\alpha \\sim 1-\\frac{\\alpha}{t}$ and $\\gamma_t=\\frac{1}{t^\\alpha}$, we have ($\\alpha \\neq 1$)\n\\begin{equation}\n\t\\sum_{t=1}^{n} \\gamma_t = \\int_{1}^{n} \\frac{1}{\\tau^\\alpha} d \\tau\n\t=n^{1-\\alpha}.\n\\end{equation}\nSimilarly, we have $\\sum_{t=0}^{n} \\frac{\\gamma_t^2}{\\lambda_t}=n^{1-2\\alpha}$,  $\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}= \\alpha n^{-\\alpha}$, \nand $\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}=\\alpha\\ln n$.\nThen\n\\begin{equation}\n\t\\begin{split}\n\t\t&\\frac{D^2+M^2\\sum_{t=0}^{n}\\frac{\\gamma_t^2}{\\lambda_t}\n\t\t\t+(M^2+D^2)\\sum_{t=0}^{n}\\frac{\\gamma_t(1-\\lambda_t)}{\\lambda_t}\n\t\t\t+D^2\\sum_{t=0}^{n}\\frac{1-\\lambda_t}{\\lambda_t}}{2\\sum_{t=0}^{n}\\gamma_t}\\\\\n\t\t&=\\frac{D^2+M^2 n^{1-2\\alpha}+\\alpha(M^2+D^2)n^{-\\alpha} +\\alpha D^2 \\ln n}{2n^{1-\\alpha}}\\\\\n\t\t&=\\frac{D^2}{2n^{1-\\alpha}} + \\frac{M^2}{2} n^{-\\alpha}  +\\frac{\\alpha(M^2+D^2)}{2}n^{-1} + \\frac{\\alpha D^2}{2} \\frac{\\ln n}{n^{1-\\alpha}}.\n\t\\end{split}\n\\end{equation}\nSo, the best choice of $\\alpha$ is $\\frac{1}{2}$.\nIn this case, the simple dual averaging iteration reads\n\\begin{equation}\n\tw_{t+1} = \\mathop{\\arg \\min}_w \\left\\{ \\frac{1}{t}\\sum_{\\tau=1}^{t} \\left<g_{\\tau}(w_\\tau), w \\right> + \\frac{\\sqrt{t}}{t} h(w) \\right\\}\n\\end{equation}\nThis result is the same with [Nesterov, 2009]'s suggest, the regularization parameter should be $O(\\frac{1}{\\sqrt{t}})$.\nThe convergence rate is $O(\\frac{\\ln t}{\\sqrt{t}})$.\n\n\\subsubsection{Convergenc of $\\mathbb{E}\\left[ \\|w_{t+1}-w_\\star\\| \\right]$}\nIn this section, we ask for the assumption on the strongly convex of $\\phi$.\n\n\\begin{lemma}\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t\t&\\leq \\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star\\|^2 \\right]\n\t\t\t+\\gamma_t^2\\mathbb{E}\\left[\\|\\nabla \\phi(w_t)-g_t\\|^2 \\right]\n\t\t\\end{split}\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t g_t -w_\\star\\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t) +\\gamma_t(\\nabla \\phi(w_t)-g_t) -w_\\star\\|^2 \\right]\\\\\n\t\t\\notag\n\t\t&=\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star\\|^2 \\right]\\\\\n\t\t\\notag\n\t\t&+2\\gamma_t\\mathbb{E}\\left[\\left<\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star , \\nabla \\phi(w_t)-g_t\\right> \\right]\\\\\n\t\t\\label{ineq2.2}\n\t\t&\\gamma_t^2\\mathbb{E}\\left[\\|\\nabla \\phi(w_t)-g_t\\|^2 \\right]\\\\\n\t\t\\label{ineq2.3}\n\t\t&=\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star\\|^2 \\right]\n\t\t+\\gamma_t^2\\mathbb{E}\\left[\\|\\nabla \\phi(w_t)-g_t\\|^2 \\right]\n\t\\end{align}\n\t(\\ref{ineq2.2}) follows because $\\mathbb{E}\\left[g(w,z_t) \\right]=\\nabla\\phi(w)$ for all $w$ and $g(w,z_t)$ is independent of $z_t$.\n\tThus we have\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\left<\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star , \\nabla \\phi(w_t)-g(w_t,z_t)\\right> \\right]\\\\\n\t\t\t&=\\mathbb{E}_{z_0,\\dots,z_{t-1}}\\left[\\mathbb{E}_{z_t}\\left[\\left< \\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star , \\nabla \\phi(w_t)-g(w_t,z_t) \\right>| z_0,\\dots,z_{t-1} \\right] \\right]\\\\\n\t\t\t&=0\n\t\t\\end{split}\n\t\\end{equation}\n\\end{proof}\nNote that the first term in (\\ref{ineq2.3}) is completely independent of $z_t$ while the second term is a variance term concerning the second moments of the subgradient at the current iterate and at the optimum.\nWe can bound each of these terms separately.\n\n\\begin{lemma}\n\tFor the first term\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star\\|^2 \\right]\\\\\n\t\t\t&\\leq\n\t\t\t(2-\\lambda_t)\\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)\\|^2\\right]\n\t\t\t+(1-\\lambda_t)(2-\\lambda_t)\\mathbb{E}\\left[ \\|w_0-w_\\star\\|^2\\right]\n\t\t\\end{split}\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[\\|\\lambda_t w_t +(1-\\lambda_t)w_0 -\\gamma_t \\nabla\\phi(w_t)-w_\\star\\|^2 \\right]\\\\\n\t\t&=\\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)+(1-\\lambda_t)(w_0-w_\\star)\\|^2\\right]\\\\\n\t\t\\notag\n\t\t&=\\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)\\|^2\\right]\\\\\n\t\t\\notag\n\t\t&+2(1-\\lambda_t)\\mathbb{E}\\left[ \\left<\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)+(1-\\lambda_t)(w_0-w_\\star), w_0-w_\\star\\right>\\right]\\\\\n\t\t&+(1-\\lambda_t)^2\\mathbb{E}\\left[ \\|w_0-w_\\star\\|^2\\right]\\\\\n\t\t\\notag\n\t\t&\\leq \\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)\\|^2\\right]\n\t\t+(1-\\lambda_t)\\left( \\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)\\|^2\\right]+\\mathbb{E}\\left[ \\|w_0-w_\\star\\|^2\\right] \\right)\\\\\n\t\t&+(1-\\lambda_t)^2\\mathbb{E}\\left[ \\|w_0-w_\\star\\|^2\\right]\\\\\n\t\t\\label{ineq2.4}\n\t\t&=(2-\\lambda_t)\\mathbb{E}\\left[ \\|\\lambda_t (w_t-w_\\star)-\\gamma_t \\nabla\\phi(w_t)+\\gamma_t\\nabla\\phi(w_\\star)\\|^2\\right]\n\t\t+(2-\\lambda_t)(1-\\lambda_t)\\mathbb{E}\\left[ \\|w_0-w_\\star\\|^2\\right]\n\t\\end{align}\n\t(\\ref{ineq2.4}) follows because $w_\\star$ is the optimal solution, so $\\nabla\\phi(w_\\star)=0$.\n\\end{proof}\n\n\\begin{lemma}\n\tSince $\\phi$ is strongly convex and has a Lipschitz continuous gradient, it follows that\n\t\\begin{equation}\n\t\t\\mathbb{E}\\left[ \\|\\lambda_t(w_t-w_\\star)-\\gamma_t(\\nabla\\phi(w_t)-\\nabla\\phi(w_\\star))\\|^2\\right]\n\t\t\\leq\n\t\t\\max\\{ |\\lambda_t-\\gamma_t L|,|\\lambda_t-\\gamma_t \\mu|  \\}^2\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right].\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\t\\begin{align}\n\t\t&\\mathbb{E}\\left[ \\|\\lambda_t(w_t-w_\\star)-\\gamma_t(\\nabla\\phi(w_t)-\\nabla\\phi(w_\\star))\\|^2\\right]\\\\\n\t\t&=\\lambda_t^2\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right] -2\\lambda_t\\gamma_t\\mathbb{E}\\left[ \\left<w_t-w_\\star, \\nabla\\phi(w_t)-\\nabla\\phi(w_\\star) \\right>\\right]\n\t\t+\\mathbb{E}\\left[\\|\\nabla\\phi(w_t)-\\nabla\\phi(w_\\star)\\|^2 \\right]\\\\\n\t\t\\label{ineq2.1}\n\t\t&\\leq \\lambda_t^2 \\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t-2\\lambda_t \\gamma_t \\mu\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t+\\gamma_t^2 L^2 \\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\\\\\n\t\t&=(\\lambda_t^2-2\\lambda_t\\gamma_t\\mu+\\gamma_t^2 L^2)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\\\\\n\t\t&\\leq \\max\\{ |\\lambda_t-\\gamma_t L|,|\\lambda_t-\\gamma_t \\mu|  \\}^2\n\t\t\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right].\n\t\\end{align}\n\tThe second term in (\\ref{ineq2.1}) due to the strongly convex of $\\phi$ and the last term of (\\ref{ineq2.1}) due to the Lipschitz continuous of $\\nabla\\phi$.\n\\end{proof}\n\nFor the second term, we must make some assumption about the statistics of the random function\n\\begin{equation}\n\t\\psi(w;z_t):=g(w,z_t)-\\nabla \\phi(w).\n\\end{equation}\n\\begin{lemma}\n\tWhen $t$ is large enough, we have\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\n\t\t\t\\leq (1-2\\gamma_t\\ell+\\gamma_t^2L^2)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{\\alpha}{t}D^2\n\t\t\t+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right].\n\t\t\\end{split}\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tAbove all, we can obtain the following result\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t\t&\\leq(2-\\lambda_t)\\max\\{ |\\lambda_t-\\gamma_t L|,|\\lambda_t-\\gamma_t \\mu|  \\}^2\n\t\t\t\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]+(2-\\lambda_t)(1-\\lambda_t)D^2\\\\\n\t\t\t&+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right]\\\\\n\t\t\t&=(2-\\lambda_t)(\\lambda_t^2-2\\lambda_t\\gamma_t \\mu +\\gamma_t^2 L^2)\n\t\t\t\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]+(2-\\lambda_t)(1-\\lambda_t)D^2\\\\\n\t\t\t&+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right]\\\\\n\t\t\\end{split}\n\t\\end{equation}\n\tSince $\\lambda_t=(1-\\frac{1}{t})^\\alpha\\approx 1-\\frac{\\alpha}{t}$, we have\n\t$$\n\t(2-\\lambda_t)(1-\\lambda_t)\n\t=2-3\\lambda_t+\\lambda_t^2\n\t\\approx 2-3(1-\\frac{\\alpha}{t})+(1-\\frac{2\\alpha}{t})\n\t=\\frac{\\alpha}{t}\n\t$$\n\tand\n\t\\begin{align}\n\t\t&(2-\\lambda_t)(\\lambda_t^2-2\\lambda_t\\gamma_t \\mu +\\gamma_t^2 L^2)\\\\\n\t\t&=2\\lambda_t^2-4\\lambda_t\\gamma_t\\mu+2\\gamma_t^2 L^2\n\t\t-\\lambda_t^3+2\\lambda_t^2 \\gamma_t\\mu-\\lambda_t\\gamma_t^2 L^2\\\\\n\t\t&=(2\\lambda_t^2-\\lambda_t^3)+(-4\\lambda_t+2\\lambda_t^2)\\gamma_t\\mu\n\t\t+(2-\\lambda_t)\\gamma_t^2 L^2\\\\\n\t\t&\\approx (2(1-\\frac{2\\alpha}{t})-(1-\\frac{3\\alpha}{t}))\n\t\t+(-4(1-\\frac{\\alpha}{t})+2(1-\\frac{2\\alpha}{t}))\\gamma_t\\mu\n\t\t+(1+\\frac{\\alpha}{t})\\gamma_t^2 L^2\\\\\n\t\t&=(1-\\frac{\\alpha}{t}) - 2\\gamma_t\\mu + (1+\\frac{\\alpha}{t})\\gamma_t^2 L^2\n\t\\end{align}\n\tSo we have\n\t\\begin{align}\n\t\t\\notag\n\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t&=((1-\\frac{\\alpha}{t}) - 2\\gamma_t\\mu + (1+\\frac{\\alpha}{t})\\gamma_t^2 L^2)\n\t\t\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]+\\frac{\\alpha}{t}D^2\n\t\t+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right]\\\\\n\t\t\\notag\n\t\t&=(1-2\\gamma_t\\mu+\\gamma_t^2L^2)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t+\\frac{\\alpha}{t}D^2\n\t\t+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right]\\\\\n\t\t\\label{ineq2.5}\n\t\t&+\\frac{\\alpha}{t}(\\gamma_t^2L^2-1)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\\\\\n\t\t&\\leq (1-2\\gamma_t\\mu+\\gamma_t^2L^2)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t+\\frac{\\alpha}{t}D^2\n\t\t+\\gamma_t^2 \\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right].\n\t\\end{align}\n\tThe last term in (\\ref{ineq2.5}) would be smaller than zero if $t$ is large enough due to the diminishing $\\gamma_t$.\n\\end{proof}\n\nLet's explore some possibilities on $\\psi$.\n\n\\begin{enumerate}\n\t\\item  {$\\psi=0$}\\\\\n\tIn the case when there is no randomness at all and we are just following the gradient.\n\tSo we can have the upper bound\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t\\|w_{t+1}-w_\\star\\|^2\n\t\t\t&\\leq(1-2\\gamma_t\\mu+\\gamma_t^2L^2)\\|w_t-w_\\star\\|^2\n\t\t\t+\\frac{\\alpha}{t}D^2\\\\\n\t\t\t&\\leq \\max\\{ |1-\\gamma_t L|,|1-\\gamma_t \\mu|  \\}^2 \\|w_t-w_\\star\\|^2\n\t\t\t+\\frac{\\alpha}{t}D^2.\n\t\t\\end{split}\n\t\\end{equation}\n\tSetting $\\alpha=0$, and $\\gamma_t=\\frac{2}{L+\\mu}$ for all $t$, we find that\n\t\\begin{align}\n\t\t\\|w_{t+1}-w_\\star\\| &\\leq \\left( \\frac{L-\\mu}{L+\\mu} \\right)\\|w_t-w_\\star\\|\\\\\n\t\t&=\\left( \\frac{L-\\mu}{L+\\mu} \\right)^t D\n\t\\end{align}\n\tThat is, a constant step-size policy converges at a linear rate.\n\t\n\t\\item {$\\psi$ bounded}\\\\\n\tThe simplest non-trivial assumption is that the deviations are bounded:\n\t\\begin{equation}\n\t\t\\|\\psi(w;z_t)\\| \\leq P\n\t\\end{equation}\n\tfor some universal constant $P$.\n\tIn this case, we have the upper bound\n\t\\begin{align}\n\t\t\\notag\n\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t&\\leq(1-2\\gamma_t\\mu+\\gamma_t^2L^2)\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t+\\frac{\\alpha}{t}D^2\n\t\t+\\gamma_t^2 P^2\n\t\\end{align}\n\t\\begin{theorem}\n\t\tsimple dual averaging method can achieve $O(1/\\sqrt{t})$ rate by choosing $\\alpha=\\frac{1}{2}$ and \n\t\t\\begin{equation}\n\t\t\t\\gamma_t=\\frac{1}{\\sqrt{t}\\ell}.\n\t\t\\end{equation}\n\t\tAnd\n\t\t\\begin{equation}\n\t\t\t\\mathbb{E}\\left[\\|w_{t}-w_\\star\\|^2 \\right]\\leq\n\t\t\t\\frac{1}{\\sqrt{t}}\n\t\t\t\\left(\\frac{L^2+\\mu^2}{\\mu^2} D^2+\\frac{P^2}{\\mu^2}\\right)\n\t\t\\end{equation}\n\t\\end{theorem}\n\t\\begin{proof}\n\t\tIn this case, it follows by induction.\n\t\t\n\t\tTo verify this inequality, note that for $t=0$, the right hand side is greater than $\\|w_0-w_\\star\\|^2=D^2$ due to $\\mu \\leq L$.\n\t\t\n\t\tAssuming that the inequality holds for $t$, observe\n\t\t\\begin{align}\n\t\t\t\\notag\n\t\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t\t&\\leq (1-\\frac{2}{\\sqrt{t}}+\\frac{L^2}{t\\mu^2})\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{\\alpha}{t}D^2+\\frac{1}{t\\ell^2} P^2\\\\\n\t\t\t&=(1-\\frac{2}{\\sqrt{t}})\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{1}{t}\\left(\\frac{L^2}{\\mu^2}\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&\\leq (1-\\frac{2}{\\sqrt{t}})\\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{1}{t}\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&\\leq (1-\\frac{2}{\\sqrt{t}}) \\frac{1}{\\sqrt{t}} \\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\n\t\t\t+\\frac{1}{t}\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&=\\left( \\sqrt{t}-1 \\right) \\frac{1}{t}\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&=\\frac{(\\sqrt{t}-1)\\sqrt{t+1}}{t} \\frac{1}{\\sqrt{t+1}}\n\t\t\t\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&\\leq \\frac{\\sqrt{t-1}\\sqrt{t+1}}{t} \\frac{1}{\\sqrt{t+1}}\n\t\t\t\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\\\\\n\t\t\t&\\leq \\frac{1}{\\sqrt{t+1}}\n\t\t\t\\left(\\frac{L^2}{\\mu^2}D^2+\\alpha D^2+\\frac{P^2}{\\mu^2}\\right)\n\t\t\t=\\frac{1}{\\sqrt{t+1}}\n\t\t\t\\left(\\frac{L^2+\\mu^2}{\\mu^2} D^2+\\frac{P^2}{\\mu^2}\\right).\n\t\t\\end{align}\n\t\\end{proof}\n\t\n\t\\item {$\\psi$ Lipschitz}\\\\\n\t\n\t\n\tIf we add additional assumptions about the behavior of $\\phi$, we can derive considerably faster convergence.\n\tIn particular, suppose $\\psi$ is Lipschitz in expectation:\n\t\\begin{equation}\n\t\t\\mathbb{E} \\left[ \\|\\psi(w)\\|^2 \\right] \\leq \\theta^2 \\|w-w_\\star\\|^2 \\quad \\forall w.\n\t\\end{equation}\n\tIn this case, we have a bound of the form\n\t\\begin{equation}\n\t\t\\begin{split}\n\t\t\t&\\mathbb{E}\\left[\\|w_{t+1}-w_\\star\\|^2 \\right]\\\\\n\t\t\t&\\leq \\left( \\max\\{ |1-\\gamma_t L|,|1-\\gamma_t \\mu|  \\}^2+\\gamma_t^2 \\theta^2 \\right) \\mathbb{E}\\left[\\|w_t-w_\\star\\|^2 \\right]\n\t\t\t+\\frac{\\alpha}{t}D^2.\n\t\t\\end{split}\n\t\\end{equation}\n\tNow we can always select a constant $\\gamma_t$ (i.e. $\\alpha=0$) that provides a linear convergence rate.\n\tIndeed, if $\\theta \\le \\sqrt{\\mu L}$, then setting $\\gamma_t=\\frac{2}{\\mu+L}$ gives\n\t\\begin{equation}\n\t\t\\mathbb{E}\\left[\\|w_{t}-w_\\star\\|^2 \\right]\n\t\t\\leq \\left( 1-\\frac{4(L/\\mu -\\theta^2/\\mu^2)}{(1+L/\\mu)^2} \\right)^t D^2.\n\t\\end{equation}\n\tOtherwise, setting $\\gamma_t=\\frac{\\mu}{\\mu^2 + \\theta^2}$, we achieve\n\t\\begin{equation}\n\t\t\\mathbb{E}\\left[\\|w_{t}-w_\\star\\|^2 \\right]\n\t\t\\leq \\left( 1+\\mu^2/\\theta^2 \\right)^{-t} D^2.\n\t\\end{equation}\n\\end{enumerate}\n\n\\subsection{Convergence of RDA}\nFor clarity, we have the following general assumptions:\n\\begin{itemize}\n\t\\item The regularization term $\\Psi(w)$ is a closed convex function with convexity parameter $\\sigma$ and $\\text{dom}\\Psi$ is closed.\n\t\\item For each $t\\geq 1$, $f_t(w)$ is convex and subdifferentiable on dom$\\Psi$.\n\t\\item $h(w)$ is strongly convex on dom$\\Psi$ and subdifferentiable on rint(dom$\\Psi$) and also satisfies\n\t\\begin{equation}\\label{assumpation7}\n\t\tw_0=\\arg\\min_w h(w)\\in \\text{Arg}\\min_w \\Psi(w).\n\t\\end{equation}\n\t\n\tWithout loss of generality, assume $h(w)$ has convexity parameter 1 and $\\min_w h(w)=0$.\n\t\\item There exist a constant $G$ such that \n\t\\begin{equation}\\label{assumpation12}\n\t\t\\|g_t\\|_{\\ast}\\leq G,~\\forall t\\geq 1.\n\t\\end{equation}\n\t\\item Require $\\{\\beta\\}_t$ be a nonnegative and nondecreasing sequence and \n\t\\begin{equation}\\label{assumpation13}\n\t\t\\max\\{\\sigma,\\beta_1\\}>0.\n\t\\end{equation}\n\\end{itemize}\nFor general convex regularizations $\\Psi(w)$, The RDA method ensure the $R_t(w) = O(\\sqrt{t})$ regret bound and $O(\\frac{1}{\\sqrt{t}})$ convergence rate with $\\beta_t=O(\\sqrt{t})$, which are same to the results of online subgradient method.\nFor strongly convex regularizations, setting $\\beta_t=O(\\ln t)$ yields the improved regret bound $O(\\ln t)$ and $O(\\frac{\\ln t}{t})$ convergence rate. The ideas of the detailed proofs are that we first found the regret bound for RDA method and then prove the convergence of cost function $\\phi(\\bar{w_t})$ and primal variables $w_{t+1}$ based on the regret bound. \n\\subsubsection{Regret bounds}\nThe learner's \\emph{regret} of online learning is the difference between his cumulative loss and the cumulative loss of the optimal fixed hypothesis, which is defined by\n\\begin{equation}\\label{regret}\n\tR_t(w)=\\sum_{\\tau=1}^{t}(f_{\\tau}(w_{\\tau})+\\Psi(w_{\\tau})) - \\sum_{\\tau=1}^{t}(f_{\\tau}(w)+\\Psi(w)),\n\\end{equation}\nand bounded by\n\\begin{equation}\n\t\\Delta_t = \\beta_t D^2 +\\frac{G^2}{2}\\sum\\limits_{\\tau=0}^{t-1}\\frac{1}{\\sigma\\tau+\\beta_\\tau}+\n\t\\frac{2(\\beta_0 -\\beta_1)G^2}{(\\beta_1+\\sigma)^2},\n\\end{equation}\nwhere $\\beta_0=\\max\\{\\sigma, \\beta_1\\}$. We could always set $\\beta_1\\geq \\sigma$ so that $\\beta_0=\\beta_1$ and therefore $\\frac{2(\\beta_0 -\\beta_1)G^2}{(\\beta_1+\\sigma)^2}$ vanishes.\n\\begin{lemma}\\label{lemma_regret}\n\tLet the sequence $\\{w_t\\}_{t\\geq 1}$ and $\\{g_t\\}_{t\\geq 1}$ be generated by RDA method, and assume (\\ref{assumpation12}) and (\\ref{assumpation13}) hold. Then for any $t\\geq 1$ and any $w\\in \\mathcal{F}_D=\\{w\\in\\text{dom}\\Psi|h(w)\\leq D^2\\}$, we have\n\t\\begin{itemize}\n\t\t\\item [(a)] The regret defined in (\\ref{regret}) is bounded by $\\Delta_t$\n\t\t\\begin{equation}\n\t\t\tR_t(w)\\leq \\Delta_t\n\t\t\\end{equation}\n\t\t\\item [(b)] The primal variables are bounded as\n\t\t\\begin{equation}\n\t\t\t\\|w_{t+1}-w\\|^2\\leq \\frac{2}{\\sigma t+\\beta_t}(\\Delta_t-R_t(w)).\n\t\t\\end{equation}\n\t\\end{itemize}\n\\end{lemma}\n\\textbf{Proof of Part (a)} First, we define the following $gap$ sequence which measures the quality of the solutions $w_1,..,w_t$:\n\\begin{equation}\\label{52}\n\t\\delta_t = \\max\\limits_{w\\in \\mathcal{F}_D} \\left\\{ \\sum\\limits_{\\tau=1}^{t} \n\t\\big( \\langle g_{\\tau},w_{\\tau}-w \\rangle  + \\Psi(w_{\\tau}) \\big) - t \\Psi(w)\\right\\},~\n\tt=1,2,3,....\n\\end{equation}\nand $\\delta_t$ is an upper bound on the regret $R_t(w)$ for all $w\\in \\mathcal{F}_D$, to see this, we use the convexity of $f_t(w)$ in the following:\n\\begin{equation}\\label{53}\n\t\\delta_t \\geq \\sum_{\\tau=1}^{t} \\left(f_{\\tau}(w_{\\tau}) - f_{\\tau}(w) + \\Psi(w_{\\tau})\\right) -t \\Psi(w) = R_t(w).\t\n\\end{equation}\nThen, We are going to derive an upper bound on $\\delta_t$. For this purpose, we subtract $\\sum_{\\tau=1}^{t} \\langle g_{\\tau},w_0 \\rangle$ in (\\ref{52}), which leads to \n\\begin{equation}\\label{54}\n\t\\delta_t = \\sum\\limits_{\\tau=1}^{t} \\left( \\langle g_{\\tau},w_{\\tau}-w_0 \\rangle  + \\Psi(w_{\\tau})\\right) +\n\t\\max\\limits_{w\\in \\mathcal{F}_D} \\left\\{ \\langle s_t,w_0 -w \\rangle  - t \\Psi(w) \\right\\},\n\\end{equation}\nthe maximization term in (\\ref{54}) is in fact $U_t(-s_t)$, therefore, by applying Lemma \\ref{lemma9}, we have\n\\begin{equation}\\label{55}\n\t\\delta_t\\leq \\sum\\limits_{\\tau=1}^{t} \\big( \\langle g_{\\tau},w_{\\tau}-w_0 \\rangle  + \\Psi(w_{\\tau})\\big) +V_t(-s_t)+\\beta_t D^2.\n\\end{equation}\nNext, we show that $\\Delta_t$ is an upper bound for the right-hand side of inequality (\\ref{55}). We consider $\\tau \\geq 2$ and $\\tau =1$ respectively.\\\\\nFor any $\\tau \\geq 2$, we have\n$$\nV_{\\tau}(-s_{\\tau})+\\Psi(w_{\\tau+1})\\leq V_{\\tau-1}(-s_{\\tau-1})+\\langle-g_{\\tau},w_{\\tau}-w_0\\rangle+\\frac{\\|g_{\\tau}\\|^2_{\\ast}}{2(\\sigma(\\tau-1)+\\beta_{\\tau -1})},\n$$\nwhere (\\ref{49}),(\\ref{42}),(\\ref{48}) and (\\ref{47}) are used. Therefore, we have\n$$\n\\langle g_{\\tau},w_{\\tau}-w_0\\rangle +\\Psi(w_{\\tau+1})\\leq \nV_{\\tau-1}(-s_{\\tau-1}) - V_{\\tau}(-s_{\\tau}) + \\frac{\\|g_{\\tau}\\|^2_{\\ast}}{2(\\sigma(\\tau-1)+\\beta_{\\tau -1})},~~\\forall\\tau\\geq 2.\n$$\nFor $\\tau =1$, we have a similar inequality\n$$\n\\langle g_{1},w_1-w_0\\rangle +\\Psi(w_2)\\leq \nV_{0}(-s_{0}) - V_{1}(-s_{1}) + \\frac{\\|g_{1}\\|^2_{\\ast}}{2\\beta_0} +(\\beta_0-\\beta_1)h(w_2),\n$$\nwhere the last term comes from (\\ref{50}). Summing the above inequalities for $\\tau=1,...,t$ and noting that $V_0(-s_0)=V_0=0$, we arrive at\n$$\n\\sum\\limits_{\\tau=1}^{t} \\big( \\langle g_{\\tau},w_{\\tau}-w_0 \\rangle  + \\Psi(w_{\\tau+1}) +V_t(-s_t) \\leq\n(\\beta_0-\\beta_1)h(w_2)+\\frac{1}{2} \\sum\\limits_{\\tau=1}^{t}  \\frac{\\|g_{\\tau}\\|^2_{\\ast}}{2(\\sigma(\\tau-1)+\\beta_{\\tau -1})}.\n$$ \nUsing $\\Psi(w_{t+1})\\geq \\Psi(w_0)$ and adding the nonpositive quantity $\\Psi(w_1)-\\Psi(w_{t+1})$ to the left hand side of the above inequality yields\n\\begin{equation}\\label{56}\n\t\\sum\\limits_{\\tau=1}^{t} \\big( \\langle g_{\\tau},w_{\\tau}-w_0 \\rangle  + \\Psi(w_{\\tau}) +V_t(-s_t) \\leq\n\t(\\beta_0-\\beta_1)h(w_2)+\\frac{1}{2} \\sum\\limits_{\\tau=1}^{t}  \\frac{\\|g_{\\tau}\\|^2_{\\ast}}{2(\\sigma(\\tau-1)+\\beta_{\\tau -1})}.\n\\end{equation}\nCombing (\\ref{53}), (\\ref{55}) and (\\ref{56}) and using Lemma \\ref{lemma12}, we conclude\n$$\nR_t(w)\\leq \\delta_t\\leq \\Delta_t.\n$$\n\\textbf{Proof of Part (b)} First, We start with the optimality condition for the minimization problem in (\\ref{RDA subproblem}): there exist subgradients $b_{t+1}\\in \\partial \\Psi(w_{t+1})$ and $d_{t+1}\\in \\partial h(w_{t+1})$ such that\n\\begin{equation}\\label{57}\n\t\\langle s_t+tb_{t+1}+\\beta_t d_{t+1},w-w_{t+1} \\rangle \\geq 0,~~ \\forall w\\in \\text{dom} \\Psi.\n\\end{equation}\nBy the strong convexity of $h$ and $\\Psi$, we have for any $w\\in \\text{dom} \\Psi$\n\\begin{align}\n\t&\\Psi(w) \\geq \\Psi(w_{t+1})+\\langle b_{t+1},w-w_{t+1} \\rangle+\\frac{\\sigma}{2} \\|w_{t+1}-w\\|^2,\\label{58}\\\\\n\t&h(w) \\geq h(w_{t+1})+\\langle d_{t+1},w-w_{t+1} \\rangle+\\frac{1}{2} \\|w_{t+1}-w\\|^2,\\label{59}\n\\end{align}\nMultiplying both sides of (\\ref{58}) by t and both sizes of (\\ref{59}) by $\\beta_t$, then adding them together, we have\n\\begin{equation}\\label{60}\n\t\\begin{split}\n\t\t\\frac{1}{2}(\\sigma t+\\beta_t)\\|w_{t+1}-w\\|^2 \n\t\t&\\leq \\beta_t h(w)-\\beta_t h(w_{t+1})-\\langle tb_{t+1}+\\beta_t d_{t+1},w-w_{t+1} \\rangle +t\\Psi(w)-t\\Psi(w_{t+1})\\\\\n\t\t&\\leq \\beta_t h(w)-\\beta_t h(w_{t+1})+\\langle s_t,w-w_{t+1} \\rangle +t\\Psi(w)-t\\Psi(w_{t+1})\\\\\n\t\t&\\leq \\beta_t h(w)+\\{\\langle -s_t,w_{t+1}-w_0 \\rangle -t\\Psi(w_{t+1})-\\beta_t h(w_{t+1})\\} +t\\Psi(w)+\\langle s_t,w-w_0 \\rangle\\\\\n\t\t&\\leq \\beta_t h(w)+V_t(-s_t) +t\\Psi(w)+\\langle s_t,w-w_0 \\rangle,\\\\\n\t\\end{split}\n\\end{equation}\nthe second and fourth inequalities hold by using (\\ref{57}) and (\\ref{V}).\\\\\nThen, we rewrite the right-hand side of (\\ref{60}) by expanding $\\langle s_t,w-w_0 \\rangle$, adding and subtracting $\\sum\\limits_{\\tau =1}^{t}\\Psi(w_{\\tau})$ to get\n\\begin{equation*}\n\t\\beta_t h(w)+ \\left\\{ V_t(-s_t)+ \\sum\\limits_{\\tau =1}^{t}\\big( \\langle g_{\\tau} ,w_{\\tau}-w_0\\rangle +\\Psi(w_{\\tau}) \\big) \\right\\}  \n\t+\\left\\{ \\sum\\limits_{\\tau =1}^{t}\\big( \\langle g_{\\tau} , w - w_{\\tau}\\rangle +t\\Psi(w)-\\sum\\limits_{\\tau =1}^{t}\\Psi(w_{\\tau}) \\right\\},\n\\end{equation*}\nthe terms in the first braces are exactly the left-hand side of (\\ref{56}) and those in the second braces are bounded by $-R_t(w)$.\\\\\nFinally, putting everything together, using Lemma \\ref{lemma12} and assumption \\ref{assumpation12}, we have\n\\begin{equation}\n\t\\begin{split}\n\t\t\\frac{1}{2}(\\sigma t+\\beta_t)\\|w_{t+1}-w\\|^2 &\\leq \\beta_t h(w)+\n\t\t(\\beta_0-\\beta_1)h(w_2)+\\frac{1}{2}\\sum\\limits_{\\tau =1}^{t}\\frac{\\|g_{\\tau}\\|^2_{\\ast}}{\\sigma(\\tau -1)+\\beta_{\\tau -1}}-\n\t\tR_t(w)\\\\\n\t\t&\\leq \\Delta_t-R_t(w).\n\t\\end{split}\n\\end{equation}\n\n\\subsubsection{Convergence rates}\n\\begin{theorem}\\label{2}\n\tAssume there exists an optimal solution $w^{\\star}$ to the problem (1) that satisfies $h(w^{\\star})\\leq D^2$ for some $D>0$, and let $\\phi^{\\star}=\\phi(w^{\\star}).$ Let the sequences $\\{w_t\\}_{t\\geq 1}$ be generated by RDA method, and assume $\\|g_t\\|_{\\ast}\\leq G$ for some constant $G$. Then for any $t\\geq 1$,\n\t\\begin{itemize}\n\t\t\\item[(a)] the expected cost associated with the random variable $\\bar{w}_t$ is bounded as\n\t\t$$\n\t\t\\mathbf{E}\\phi(\\bar{w}_t)-\\phi^{\\star}\n\t\t\\leq \\frac{1}{t}\\Delta_t.\n\t\t$$\n\t\t\\item[(b)] the primal variables are bounded as \n\t\t$$\n\t\t\\mathbf{E}\\|w_{t+1}-w^{\\star}\\|^2\\leq \\frac{2}{\\sigma t+\\beta_t}\\Delta_t.\n\t\t$$\n\t\\end{itemize}\n\\end{theorem}\n\\textbf{Proof} First, from the definition (\\ref{regret}), We have the regret at $w^{\\star}$\n$$\nR_t(w^{\\star})=\\sum_{\\tau=1}^{t}(f(w_{\\tau},z_{\\tau})+\\Psi(w_{\\tau})) - \\sum_{\\tau=1}^{t}(f(w^{\\star},z_{\\tau})+\\Psi(w^{\\star})),\n$$\nLet $\\mathbf{z}[t]$ denote the collection of i.i.d. random variables $(z_,...,z_t)$. We note that the random variable $w_{\\tau}$, where $1\\leq w \\geq t$, is a function of $(z_1,...,z_{\\tau -1})$ and is independent of $(z_{\\tau},...,z_t)$. Therefore\n$$\n\\mathbf{E}_{\\mathbf{z}[t]}\\left( f(w_{\\tau},z_{\\tau})+\\Psi(w_{\\tau})\\right)=\n\\mathbf{E}_{z[\\tau-1]} \\left( \\mathbf{E}_{\\tau} f(w_{\\tau},z_{\\tau})+\\Psi(w_{\\tau})\\right)=\n\\mathbf{E}_{z[\\tau-1]}\\phi(w_{\\tau})=\n\\mathbf{E}_{z[t]}\\phi(w_{\\tau}),\n$$\nand \n$$\n\\mathbf{E}_{\\mathbf{z}[t]}\\left( f(w^{\\star},z_{\\tau})+\\Psi(w^{\\star})\\right)=\n\\mathbf{E}_{\\tau} f(w^{\\star},z_{\\tau})+\\Psi(w^{\\star}) = \\phi(w^{\\star}) = \\phi^{\\star}.\n$$\nSince $\\phi^{\\star}=\\phi(w^{\\star})=\\min\\limits_w\\phi(w)$, we have the expected regret\n\\begin{equation}\\label{exp_regret}\n\t\\mathbf{E}_{\\mathbf{z}[t]} R_t(w^{\\star})=\\sum_{\\tau=1}^{t} \\mathbf{E}_{\\mathbf{z}[t]} \\phi(w_\\tau)-t\\phi^{\\star}\\geq 0.\n\\end{equation}\nThen, by convexity of $\\phi$, we have  \n\\begin{equation}\\label{convexinequ}\n\t\\phi(\\bar{w}_t)=\\phi\\left(\\frac{1}{t} \\sum_{\\tau=1}^{t} w_\\tau  \\right) \\leq\n\t\\frac{1}{t}\\sum_{\\tau=1}^{t}\\phi\\left( w_\\tau  \\right).\n\\end{equation}\nFinally, from (\\ref{convexinequ}) and (\\ref{exp_regret}), we have\n$$\n\\mathbf{E}_{\\mathbf{z}[t]} \\phi(\\bar{w}_t)-\\phi^{\\star} \\leq \n\\frac{1}{t}\\left(\\sum_{\\tau=1}^{t}\t\\mathbf{E}_{\\mathbf{z}[t]}\\phi( w_\\tau)-t\\phi^{\\star}\\right) =\n\\frac{1}{t}\\mathbf{E}_{\\mathbf{z}[t]} R_t(w^{\\star}).\n$$\nThen part (a) follows from that of Lemma \\ref{lemma_regret}. Similarly and obviously, part (b) follows from that of Lemma \\ref{lemma_regret} and (\\ref{exp_regret}).\n\\\\\nSome conclusions from the theorem:\n\\begin{enumerate}\n\t\\item \n\tFrom the part (a) of Theorem \\ref{2}, the expected cost associated with the random variable $\\bar{w}_t$ is bounded as\n\t\\begin{equation}\\label{convergencephi}\n\t\t\\mathbf{E}\\phi(\\bar{w}_t)-\\phi^{\\star}\n\t\t\\leq \\frac{1}{t} \\left(a \\beta_t +b\\sum\\limits_{\\tau=0}^{t-1}\\frac{1}{\\sigma\\tau+\\beta_\\tau}\\right),\n\t\\end{equation}\n\twhere $a$ and $b$ are some positive constants and $\\sigma$ is the convexity parameter of $\\Psi(w)$. Here, we consider $\\ell_1$ regularization function $\\Psi(w)=\\|w\\|_1$ and it is a convex but not strongly convex function, which means $\\sigma=0$.\\\\\n\tNow, we consider how to choose $\\beta_t$ for $t\\geq 1$ and $\\beta_0 = \\beta_1$. First if $\\beta_t = t$, we have $\\frac{1}{t}\\cdot a t = a$, which means the expected cost does not converge. Then assume $\\beta_t=t^{\\alpha}$ and $\\alpha\\neq 1$, the right hand side of the inequality (\\ref{convergencephi}) becomes \n\t$$\n\t\\frac{1}{t} \\left(a t^{\\alpha} +b\\sum\\limits_{\\tau=0}^{t-1}\\frac{1}{\\tau^{\\alpha}}\\right) \\leq \n\t\\frac{1}{t} \\left[ a t^{\\alpha} +b \\big( 2+ \\sum\\limits_{\\tau=2}^{t-1}\\frac{1}{\\tau^{\\alpha}} \\big) \\right] \\leq\n\t\\frac{1}{t} \\left[ a t^{\\alpha} +b \\big( 2+ \\int_{1}^{t-1} \\frac{1}{\\tau^{\\alpha}} \\big) \\right] \t\t    \\sim\n\tO(t^{\\alpha-1} + t^{-\\alpha}),\n\t$$\n\tfrom above, we see that if $0<\\alpha<1$, the expected cost converges and the optimal convergence rate $O(t^{-\\frac{1}{2}})$ achieves when $\\alpha=\\frac{1}{2}$.\n\t\\item \n\tFrom the part (b) of Theorem \\ref{2}, the primal variables are bounded as \n\t$$\n\t\\mathbf{E}\\|w_{t+1}-w^{\\star}\\|^2\\leq \\frac{2}{\\sigma t+\\beta_t}\\left(a \\beta_t +b\\sum\\limits_{\\tau=0}^{t-1}\\frac{1}{\\sigma\\tau+\\beta_\\tau}\\right)\n\t= \\frac{2}{\\beta_t}\\left(a \\beta_t +b\\sum\\limits_{\\tau=0}^{t-1}\\frac{1}{\\beta_\\tau}\\right).\n\t$$\n\tThus $\\mathbf{E}\\|w_{t+1}-w^{\\star}\\|^2$ is bounded by a constant.\n\t\\item \n\tNext, we consider how the coefficients $\\gamma$ of $\\beta_t = \\gamma \\sqrt{t}$ and $\\lambda$ of $\\Psi(w)=\\lambda \\| w \\|_1$ affect the performance of convergence and accuracy. Note that in (\\ref{convergencephi}), $a=D^2$ and $b=G^2$, where $h(w)\\leq D^2$ and $\\|g_t\\|_2 \\leq G$. We rewrite (\\ref{convergencephi}) as\n\t$$\n\t\\mathbf{E}\\phi(\\bar{w}_t)-\\phi^{\\star} = \n\t\\mathbf{E}_{z_\\tau}\\big(f(\\bar{w_t},z_{\\tau})-f(w^{\\star},z_{\\tau})\\big)+\\lambda\\big(\\|\\bar{w_t}\\|_1-\\|{w_t}^{\\star}\\|_1\\big)\n\t\\leq\n\t(\\gamma D^2 +\\frac{G^2}{\\gamma})\\frac{1}{\\sqrt{t}}\n\t$$\n\t\\begin{itemize}\n\t\t\\item \n\t\tMinimizing $\\left(\\gamma D^2 +\\frac{G^2}{\\gamma}\\right)$ yields $\\gamma = \\frac{G}{D}$.\n\t\t\\item \n\t\t$\\lambda$ stays at the left hand side of the inequality above.\n\t\\end{itemize}\n\\end{enumerate}\n\n\n\\subsubsection{Some Lemmas}\nFirst of all, we define some functions:\n\\begin{align}\n\t&U_t(s)=\\max\\limits_{w\\in \\mathcal{F}_D} \\{ \\langle s,w-w_0  \\rangle-t\\Psi(w)\\},\\label{U}\\\\\n\t&V_t(s)=\\max\\limits_{w} \\{ \\langle s,w-w_0  \\rangle-t\\Psi(w) - \\beta_t h(w)\\}\\label{V}.\n\\end{align}\nThe maximum in (\\ref{U}) is always achieved because $\\mathcal{F}_D=\\{w\\in\\text{dom}\\Psi|h(w)\\leq D^2\\}$ is a nonempty compact set. Because of (\\ref{assumpation13}), we have $\\sigma t+\\beta_t \\geq \\beta_0 > 0$ for all $t\\geq0$, which means  $t\\Psi(w)+\\beta_t h(w)$ are all strongly convex, therefore the maximum in (\\ref{V}) is always achieved and unique. As a result, we have $\\text{dom} U_t= \\text{dom} V_t = E^{\\ast}$ for all $t\\geq 0$. Moreover, by the assumption (\\ref{assumpation7}), both of the functions are nonnegative.\\\\\nLet $s_t$ denote the sum of the subgradients obtained up to time $t$ in RDA method,that is\n\\begin{equation}\\label{42}\n\ts_t=\\sum\\limits_{\\tau =1}^{t} g_{\\tau} = t \\bar{g}_t,\n\\end{equation}\nand $\\pi_t(s)$  denotes the unique maximizer in the definition of $V_t(s)$\n\\begin{equation}\n\t\\begin{split}\n\t\t\\pi_t(s) &= \\arg\\max\\limits_{w} \\{ \\langle s,w-w_0  \\rangle-t\\Psi(w) - \\beta_t h(w)\\}\\\\\n\t\t&= \\arg\\min\\limits_{w} \\{ \\langle -s,w \\rangle + t\\Psi(w) + \\beta_t h(w)\\},\n\t\\end{split}\n\\end{equation}\nwhich then gives \n\\begin{equation}\n\tw_{t+1} = \\pi_t(-s_t).\n\\end{equation}\n\\begin{lemma}\\label{lemma9}\n\tFor any $s\\in E^{\\ast}$ and $t\\geq 0$, we have\n\t\\begin{equation}\n\t\tU_t(s)<V_t(s)+\\beta_t D^2.\n\t\\end{equation} \n\\end{lemma}\t\n\\begin{proof}\n\tStarting with the definition of $U_t(s)$ and using $\\mathcal{F}_D=\\{w\\in\\text{dom}\\Psi|h(w)\\leq D^2\\}$,\n\t$$\n\t\\begin{aligned}\n\tU_t(s) &= \\max_{w\\in\\mathcal{F}_D} \\{\\langle s,w-w_0\\rangle - t \\Psi(w) \\} \\\\\n\t&=\\max_w \\min_{\\beta \\geq 0} \\{\\langle s,w-w_0\\rangle - t \\Psi(w) +\\beta(D^2-h(w)) \\} \\\\\n\t&\\leq \\min_{\\beta \\geq 0} \\max_w  \\{\\langle s,w-w_0\\rangle - t \\Psi(w) +\\beta(D^2-h(w)) \\} \\\\\n\t&\\leq  \\max_w  \\{\\langle s,w-w_0\\rangle - t \\Psi(w) +\\beta(D^2-h(w)) \\} \\\\\n\t&= V_t(s) +\\beta_t D^2.\n\t\\end{aligned}\n\t$$\n\tFor the second equality and the first inequality above, we used standard duality arguments and the max-min inequality.\n\\end{proof}\n\\begin{lemma}\\label{lemma10}\n\tThe function $V_t$ is convex and differentiable. Its gradient is given by\n\t\\begin{equation}\\label{47}\n\t\t\\nabla V_t(s)=\\pi_t(s)-w_0\n\t\\end{equation}\n\tMoreover, the gradient Lipschitz continuous with constant $1/(\\sigma t+\\beta_t)$, that is\n\t\\begin{equation}\n\t\t\\|\\nabla V_t(s_1)-\\nabla V_t(s_2) \\| \\leq \\frac{1}{\\sigma t+ \\beta_t}\\|s_1 - s_2\\|_{\\ast},~~ \\forall s_1,s_2\\in E^{\\ast}.\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tIndeed, $V_t(s)$ is convex as a maximum of functions, which are linear in $s$.\n\tIt is differentiable since $\\pi_t(s)$ is unique.\n\tLet us prove that its gradient is Lipschitz continuous.\n\tConsider two points $s_1$ and $s_2$.\n\tFor the sake of notation, without loss of generality we assume that the functions $\\Psi(\\cdot)$ and $h(\\cdot)$ are differentiable.\n\tFrom the first-order optimality conditions we have\n\t\\begin{equation}\n\t\t\\langle s_1 - t \\nabla \\Psi(\\pi_t(s_1)) -\\beta_t \\nabla h(\\pi_t(s_1)), \\pi_t(s_2)- \\pi_t(s_1) \\rangle \\leq 0,\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\langle s_2 - t \\nabla \\Psi(\\pi_t(s_2)) -\\beta_t \\nabla h(\\pi_t(s_2)), \\pi_t(s_1)- \\pi_t(s_2) \\rangle \\leq 0.\n\t\\end{equation}\n\tAdding these inequalities and using convexity of $\\Psi(\\cdot)$ and strongly convex of $h(\\cdot)$, we continue as follows:\n\t\\begin{align*}\n\t\t\\langle s_1-s_2 , \\pi_t(s_1) - \\pi_t(s_2) \\rangle\n\t\t&\\geq \\langle t( \\nabla \\Psi(\\pi_t(s_1)) -\\nabla \\Psi(\\pi_t(s_2)) )+ \\beta_t (\\nabla h(\\pi_t(s_1)) -\\nabla h(\\pi_t(s_2)) ) , \\pi_t(s_1) -\\pi_t(s_2) \\rangle \\\\\n\t\t& \\geq t \\langle ( \\nabla \\Psi(\\pi_t(s_1)) -\\nabla \\Psi(\\pi_t(s_2)) ), \\pi_t(s_1) -\\pi_t(s_2) \\rangle + \\beta_{t} \\langle (\\nabla h(\\pi_t(s_1)) -\\nabla h(\\pi_t(s_2)) ) , \\pi_t(s_1) -\\pi_t(s_2) \\rangle\\\\\n\t\t& \\geq t \\sigma \\|\\pi_t(s_1)- \\pi_t(s_2)\\|^2_2 + \\beta_{t} \\|\\pi_t(s_1)- \\pi_t(s_2)\\|^2_2\\\\\n\t\t&= (\\sigma t+ \\beta_{t}) \\|\\pi_t(s_1)- \\pi_t(s_2)\\|^2_2\n\t\\end{align*}\n\ti.e.\n\t\\begin{equation}\n\t\t\\langle s_1-s_2, \\nabla V_t(s_1) - \\nabla V_t (s_2) \\rangle \\geq (\\sigma t +\\beta_t) \\|\\pi_t(s_1)- \\pi_t(s_2)\\|^2_2\n\t\\end{equation}\n\\end{proof}\nA direct consequence of Lemma (\\ref{lemma10}) is the following inequality:\n\\begin{equation}\\label{48}\n\tV_t(s+g)\\leq V_t(s) + \\langle g , \\nabla V_t (s) \\rangle +\\frac{1}{2(\\sigma t+\\beta_t)}\\|g\\|_{\\ast}^2,~~ \\forall s,g\\in E^{\\ast}.\n\\end{equation}\n\\begin{lemma}\\label{lemma11}\n\tFor each $t\\geq 1$, we have\n\t\\begin{equation}\n\t\tV_t (-s_t) +\\Psi(w_{t+1})\\leq V_{t-1}(-s_t)+(\\beta_{t-1}-\\beta_t)h(w_{t+1}).\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tWe start with the definition of $V_{t-1}(-s_t):$\\\\\n\t$$\n\t\\begin{aligned}\n\tV_{t-1}(-s_t) &= \\max_w \\{ \\langle  -s_t,w-w_0    \\rangle -(t-1)\\Psi(w) - \\beta_{t-1}h(w) \\} \\\\\n\t&\\geq \\langle  -s_t,w_{t+1}-w_0    \\rangle -(t-1)\\Psi(w_{t+1}) - \\beta_{t-1}h(w_{t+1}) \\\\\n\t&= \\{ \\langle  -s_t,w-w_0    \\rangle -t\\Psi(w) - \\beta_{t}h(w) \\} +\\Psi(w_{t+1})+(beta_t-\\beta_{t-1})h(w_{t+1})). \\\\\n\t\\end{aligned}\n\t$$\n\tThe expression in the last braces above is precisely $V_t(-s_t)$, then making the substitution and rearranging terms give the desired result.\n\\end{proof}\nSince $h(w_{t+1})\\geq 0$ and the sequence $\\{\\beta_t\\}_{t\\geq 1}$ is nondecreasing, we have\n\\begin{align}\n\t&V_t(-s_t)+\\Psi(w_{t+1})\\leq V_{t-1}(-s_t),&\\forall t\\geq 2,\\label{49}\\\\\n\t&V_t(-s_1)+\\Psi(w_2)\\leq V_{0}(-s_1)+(\\beta_0-\\beta_1)h(w_2),&\\forall t=1.\\label{50}\n\\end{align}\n\\begin{lemma}\\label{lemma12}\n\tAssume $\\max \\{ \\sigma,\\beta_1 \\}>0$. Let $h(w)=\\frac{1}{\\sigma}\\Psi(w)$ if $\\sigma\\geq 0$. Then\n\t\\begin{equation}\\label{51}\n\t\th(w_2)< \\frac{2\\|g_1\\|^2_{\\ast}}{(\\beta_1+\\sigma)^2}.\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tFor $t=1$, we have $w_1=w_0$, $\\Psi(w_1)=\\Psi(w_0)=0$, $h(w_1)=h(w_0)=0$, and $\\bar{g}_1=g_1$. Since $w_2$ is the minimizer in (\\ref{RDA}) for $t=1$, we have\n\t$$\n\t\\langle g_1,w_2 \\rangle +\\Psi(w_2) +\\beta_1 h(w_2) \\leq \\langle g_1,w_1 \\rangle + \\Psi(w_1)+\\beta_1 h(w_1) = \\langle g_1,w_1 \\rangle.\n\t$$\n\tTherefore,\n\t$$\n\t\\Psi(w_2) + \\beta_1 h(w_2)\\leq \\langle g_1,w_1-w_2 \\rangle \\leq \\|g_1\\|_{*}\\|w_2-w_1\\|.\n\t$$\n\tOn the other hand, by strongly convexity of $\\Psi(w)$ and $h(w)$, we have\n\t$$\n\t\\Psi(w_2) + \\beta_1 h(w_2)\\geq \\frac{\\sigma+\\beta_1}{d2} \\|w_2-w_1\\|^2.\n\t$$\n\tCombining the last two inequalities together, we have\n\t$$\n\t\\Psi(w_2) + \\beta_1 h(w_2)\\leq \\frac{2\\|g_1\\|_{*}^{2}}{\\sigma+\\beta_1}.\n\t$$\n\tIf $\\sigma=0$, we must have $\\beta_1>0$. In this case, since $\\Psi(w_2)\\geq 0$, we have\n\t$$\n\th(w_2)\\leq \\frac{2\\|g_1\\|^2_{*}}{\\beta_1^2}=\\frac{2\\|g_1\\|^2_{*}}{(\\sigma+\\beta_1)^2}.\n\t$$\n\tIf $\\sigma>0,$ we have $\\Psi(w) = \\sigma h(w)$ by assumption and therefore\n\t$$\n\t\\Psi(w_2) + \\beta_1 h(w_2) = (\\sigma + \\beta_1) h(w_2)\\leq \\frac{2\\|g_1\\|_{*}^{2}}{\\sigma+\\beta_1},\n\t$$\n\tthen we finished the proof.\n\\end{proof}\n\n\\begin{lemma}\n\tmax-min inequality:\n\t\\begin{equation}\n\t\t\\max_x \\min_y f(x,y) \\leq \\min_y \\max_x f(x,y).\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tDenote\n\t\\begin{equation}\n\t\tg(x) = \\min_y f(x,y),\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\th(y) =\\max_x f(x,y).\n\t\\end{equation}\n\tLet\n\t\\begin{equation}\n\t\ta= \\mathop{\\arg \\max}_x g(x),\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\tb = \\mathop{\\arg \\min}_y h(y).\n\t\\end{equation}\n\tThen we have\n\t\\begin{equation}\n\t\t\\max_x \\min_y f(x,y) =\\max_x g(x) =g(a),\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\t\\min_y \\max_x f(x.y) = \\min h(y) = h(b).\n\t\\end{equation}\n\tSo,\n\t\\begin{equation}\n\t\tg(a)= \\min_y f(a,y) \\leq f(a,b),\n\t\\end{equation}\n\tand\n\t\\begin{equation}\n\t\th(b) = \\max_x f(x,b) \\geq f(a,b).\n\t\\end{equation}\n\tFinally, we have\n\t\\begin{equation}\n\t\t\\max_x \\min_y f(x,y) =g(a) \\leq f(a,b) \\leq h(b) =\\min_x \\max_y f(x,y).\n\t\\end{equation}\n\tThis is the so-called weak duality.\n\t\n\tThe strong duality holds when there exist $(a,b)$ such that\n\t\\begin{equation}\n\t\tg(a) = h(b),\n\t\\end{equation}\n\\end{proof}\n\n\\iffalse\n\\section{Alternative Convergence Proofs for SDA and RDA}\n\\subsection{SDA Convergence Analysis}\nIn this section, we analyze the convergence of the SDA algorithm\n\\begin{equation}\\label{SDE_iteration}\n    x_n = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^{n-1} \\langle g_i, x\\rangle + \\sqrt{n}\\|x\\|_2^2\\right),~x_1 = 0\n\\end{equation}\nwhere $g_i\\in \\partial f(x_i)$.\n\nLet us first analyze the consequences of the definition of $x_n$ as an argmin. We note that if\n$z$ is any other point, then\n\\begin{equation}\n    \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, x_n\\rangle + \\sqrt{n}\\|x_n\\|_2^2 \\leq \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, z\\rangle + \\sqrt{n}\\|z\\|_2^2\n\\end{equation}\nso that\n\\begin{equation}\\label{minimum_property}\n    \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, x_n - z\\rangle \\leq \\sqrt{n}\\|z\\|_2^2 - \\sqrt{n}\\|x_n\\|_2^2\n\\end{equation}\n\nThis is crucial in the proof of the following theorem\n\\begin{theorem}\n Assume that $f$ is convex and Lipschitz with constant $M$, i.e. $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f(x)$ and let\n $x^*\\in \\arg\\min_x f(x)$. Then the\n iterates of (\\ref{SDE_iteration}) satisfy\n \\begin{equation}\n     f(\\bar{x}_n) - f(x^*) \\leq \\frac{2(\\|x^*\\|_2^2 + M^2)}{\\sqrt{n}}\n \\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^nx_i$ is the average of the first $n$ iterates.\n\\end{theorem}\n\\begin{proof}\nWe consider the average of the first $n$ iterates $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^nx_i$. Note 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^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle\n\\end{equation}\nWe rewrite the sum above as follows\n\\begin{equation}\\label{eq45}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle = \\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}\nFrom observation (\\ref{minimum_property}) we obtain\n\\begin{equation}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle \\leq \\sqrt{n+1}\\|x^*\\|_2^2 - \\sqrt{n+1}\\|x_{n+1}\\|_2^2\n\\end{equation}\nand\n\\begin{equation}\n    \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle \\leq \\langle g_i, x_i - x_{i+1}\\rangle + \\sqrt{i}\\|x_{i+1}\\|_2^2 - \\sqrt{i}\\|x_{i}\\|_2^2\n\\end{equation}\nPlugging this into equation (\\ref{eq45}) and noting that $\\sqrt{i} - \\sqrt{i - 1} \\geq \\frac{1}{2\\sqrt{i}}$ for $i > 1$ to get\n\\begin{equation}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq \\sqrt{n+1}\\|x^*\\|_2^2 - \\|x_1\\|_2^2 - \\displaystyle\\sum_{i = 2}^{n+1}\\frac{\\|x_i\\|_2^2}{2\\sqrt{i}} + \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle\n\\end{equation}\nThrowing away the negative terms above we see that\n\\begin{equation}\\label{eq61}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq \\sqrt{n+1}\\|x^*\\|_2^2 + \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle\n\\end{equation}\nFinally, we bound the last sum above as\n\\begin{equation}\\label{eq65}\n    \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle \\leq \\displaystyle\\sum_{i=1}^n \\|g_i\\|_2\\|x_i - x_{i+1}\\|_2 \\leq M\\displaystyle\\sum_{i=1}^n\\|x_i - x_{i+1}\\|_2\n\\end{equation}\nIn order to bound this last part, we need to write out $x_i - x_{i+1}$ explicitly. We see that\n$$ x_i = \\frac{1}{2\\sqrt{i}}\\displaystyle\\sum_{j = 1}^{i-1} g_j\n$$\nand thus\n$$ x_i - x_{i+1} = \\left(\\frac{1}{2\\sqrt{i}} - \\frac{1}{2\\sqrt{i+1}}\\right)\\displaystyle\\sum_{j = 1}^{i-1} g_j - \\frac{1}{2\\sqrt{i+1}} g_{i+1}\n$$\nutilizing $\\frac{1}{\\sqrt{i}} - \\frac{1}{\\sqrt{i+1}} \\leq \\frac{1}{2i^{3/2}}$ and the triangle inequality, we see that\n\\begin{equation}\n    \\|x_i - x_{i+1}\\|_2 \\leq \\frac{3}{4\\sqrt{i}}M \\leq \\frac{M}{\\sqrt{i}}\n\\end{equation}\nWe now plug this into equation (\\ref{eq65}) to get\n\\begin{equation}\n    \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle \\leq  M^2 \\displaystyle\\sum_{i=1}^n \\frac{1}{\\sqrt{i}} \\leq 2M^2 \\sqrt{n}\n\\end{equation}\nPluggin this into equation (\\ref{eq61}) we get\n\\begin{equation}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq \\sqrt{n+1}\\|x^*\\|_2^2 + 2M^2 \\sqrt{n} \\leq 2\\sqrt{n}(\\|x^*\\|_2^2 + M^2)\n\\end{equation}\nThus we obtain\n\\begin{equation}\n     f(\\bar{x}_n) - f(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle \\leq \\frac{2(\\|x^*\\|_2^2 + M^2)}{\\sqrt{n}}\n\\end{equation}\nas desired.\n\\end{proof}\n\n\\subsection{RDA Convergence Analysis}\nWe consider the optimization problem\n\\begin{equation}\n    \\arg\\min_x f(x) + R(x)\n\\end{equation}\nwhere $R(x)$ is a convex regularization term, which in our application is taken to be $\\|\\cdot\\|_1$. We analyze the convergence of the RDA algorithm\n\\begin{equation}\\label{RDA_iteration}\n    x_n = \\arg\\min_x \\left(\\displaystyle\\sum_{i = 1}^{n-1} \\langle g_i, x\\rangle + \\sqrt{n}\\|x\\|_2^2 + nR(x)\\right)\n\\end{equation}\nwith $g_i\\in \\partial f(x_i)$.\n\nNote that by completing the square, (\\ref{RDA_iteration}) can be written as\n\\begin{equation}\n    x_{n+\\frac{1}{2}} = \\frac{1}{2\\sqrt{n}}\\displaystyle\\sum_{i=1}^n g_i,~x_n = P_{\\sqrt{n}R}(x_{n+\\frac{1}{2}}) = \\arg\\min_x \\|x - x_{n+\\frac{1}{2}}\\|_2^2 + \\sqrt{n}R(x)\n\\end{equation}\n\nFor example, if $R = \\|\\cdot\\|_1$, we see that\n\\begin{equation}\n    P_{\\sqrt{n}R}(x_{n+\\frac{1}{2}}) = \n    \\begin{cases}\n     x_{n+\\frac{1}{2}} + \\frac{1}{2}\\sqrt{n} & \\text{if $x_{n+\\frac{1}{2}} < -\\frac{1}{2}\\sqrt{n}$} \\\\\n     0 & \\text{if $|x_{n+\\frac{1}{2}}| \\leq \\frac{1}{2}\\sqrt{n}$} \\\\\n     x_{n+\\frac{1}{2}} - \\frac{1}{2}\\sqrt{n} & \\text{if $x_{n+\\frac{1}{2}} > \\frac{1}{2}\\sqrt{n}$}\n    \\end{cases}\n\\end{equation}\n\nBefore we begin our convergence proof, let us note a simple observation. Since $x_n$ is given by the $\\arg\\min$ in (\\ref{RDA_iteration}), if\n$z$ is any point, we have\n\\begin{equation}\n    \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, x_n\\rangle + \\sqrt{n}\\|x_n\\|_2^2 + nR(x_n)\\leq \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, z\\rangle + \\sqrt{n}\\|z\\|_2^2 + nR(z)\n\\end{equation}\nso that\n\\begin{equation}\\label{minimum_property}\n    \\displaystyle\\sum_{i = 0}^{n-1} \\langle g_i, x_n - z\\rangle \\leq \\sqrt{n}\\|z\\|_2^2 + nR(z) - \\sqrt{n}\\|x_n\\|_2^2 - nR(x_n)\n\\end{equation}\n\n\nAdditionally, we will need the following well-known lemma.\n\\begin{lemma}\\label{non-expansive}\n The proximal map $P_R$ is non-expansive for any convex function $R$, i.e.\n \\begin{equation}\n     \\|P_R(x) - P_R(y)\\|_2 \\leq \\|x - y\\|_2\n \\end{equation}\n\\end{lemma}\n\\begin{proof}\n Let $x^\\prime = P_R(x)$ and $y^\\prime = P_R(y)$. Then the definition of the proximal map implies that $\\Delta x = x - x^\\prime\\in \\partial R(x^\\prime)$ and likewise for the $y$s. Thus we have\n \\begin{equation}\n     \\langle x - y, x^\\prime - y^\\prime\\rangle = \\|x^\\prime - y^\\prime\\|_2^2 + \\langle\\Delta x - \\Delta y, x^\\prime - y^\\prime\\rangle \\geq \\|x^\\prime - y^\\prime\\|_2^2\n \\end{equation}\n This last inequality follows from the convexity of $R$ and the fact that $\\Delta x \\in \\partial R(x^\\prime)$ and $\\Delta y \\in \\partial R(y^\\prime)$. The Cauchy-Schwartz inequality\n now implies that\n \\begin{equation}\n     \\|x^\\prime - y^\\prime\\|_2 \\leq \\|x - y\\|_2\n \\end{equation}\n as desired.\n\\end{proof}\n\n\nLetting $\\phi(x)$ denote $f(x) + R(x)$, we have the following convergence result.\n\\begin{theorem}\n Assume that $f$ is convex and Lipschitz with constant $M$, i.e. $\\|g\\|_2 \\leq M$ for all $g\\in \\partial f(x)$, and\n that $R$ is convex and Lipschitz with constant $N$ and bounded below. Let\n $x^*\\in \\arg\\min_x \\phi(x)$. Then the\n iterates of (\\ref{RDA_iteration}) satisfy\n \\begin{equation}\n\\phi(\\bar{x}_n) - \\phi(x^*) \\leq \\frac{2\\|x^*\\|_2^2 + 3M^2}{\\sqrt{n}} + \\frac{(R(x^*) - \\inf_x R(x)) + MN\\log(n)}{n}\n\\end{equation}\n where $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^nx_i$ is the average of the first $n$ iterates.\n\\end{theorem}\n\\begin{proof}\nConsider the average of the first $n$ iterates $\\bar{x}_n = \\frac{1}{n}\\sum_{i = 1}^nx_i$. Note that\n\\begin{align}\\label{eq157}\n    \\phi(\\bar{x}_n) - \\phi(x^*) \\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (\\phi(x_i) - \\phi(x^*)) &\\leq \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle\\\\ \n    & + \\frac{1}{n}\\displaystyle\\sum_{i = 1}^n (R(x_i) - R(x^*))\n\\end{align}\nsince $\\phi(x) = f(x) + R(x)$ and $g_i\\in\\partial f(x_i)$.\nWe rewrite the sum in (\\ref{eq157}) as follows\n\\begin{equation}\\label{eq45}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle = \\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}\nBy setting $z = x^*$ in observation (\\ref{minimum_property}) we obtain\n\\begin{align}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_{n+1} - x^*\\rangle &\\leq \\sqrt{n+1}\\|x^*\\|_2^2 - \\sqrt{n+1}\\|x_{n+1}\\|_2^2 \\\\\n    & + (n+1)R(x^*) - (n+1)R(x_{n+1})\n\\end{align}\nand setting $z = x_{i+1}$ we get\n\\begin{align}\n    \\displaystyle\\sum_{j = 1}^i\\langle g_j, x_i - x_{i+1}\\rangle &\\leq \\langle g_i, x_i - x_{i+1}\\rangle + \\sqrt{i}\\|x_{i+1}\\|_2^2 - \\sqrt{i}\\|x_{i}\\|_2^2 \\\\\n    & + iR(x_{i+1}) - iR(x_i)\n\\end{align}\nPlugging this into equation (\\ref{eq45}) and noting that $\\sqrt{i} - \\sqrt{i - 1} \\geq \\frac{1}{2\\sqrt{i}}$ for $i > 1$, we get\n\\begin{align}\n    \\displaystyle\\sum_{i = 1}^n \\langle g_i, x_i - x^*\\rangle &\\leq \\sqrt{n+1}\\|x^*\\|_2^2 + (n+1)R(x^*) - \\displaystyle\\sum_{i = 1}^{n+1} R(x_i) \\\\\n    & - \\displaystyle\\sum_{i = 1}^{n+1}\\frac{\\|x_i\\|_2^2}{2\\sqrt{i}} + \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle\n\\end{align}\nPlugging this into equation (\\ref{eq157}) and throwing away the negative terms we see that\n\\begin{equation}\\label{eq61}\n    n(\\phi(\\bar{x}_n) - \\phi(x^*)) \\leq \\sqrt{n+1}\\|x^*\\|_2^2 + R(x^*) - R(x_{n+1}) + \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle\n\\end{equation}\nWe bound the last sum above using Cauchy-Schwartz as\n\\begin{equation}\\label{eq65}\n    \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle \\leq \\displaystyle\\sum_{i=1}^n \\|g_i\\|_2\\|x_i - x_{i+1}\\|_2 \\leq M\\displaystyle\\sum_{i=1}^n\\|x_i - x_{i+1}\\|_2\n\\end{equation}\nFinally, we must bound $\\|x_i - x_{i+1}\\|_2$. For this, we recall that by (\\ref{RDA_iteration})\n\\begin{equation}\\label{eq201}\n    x_i = \\arg\\min_x \\left(\\displaystyle\\sum_{j = 1}^{i-1} \\langle g_j, x\\rangle + \\sqrt{i}\\|x\\|_2^2 + iR(x)\\right)\n\\end{equation}\nand note that by multiplying the objective in (\\ref{RDA_iteration}) by $\\sqrt{\\frac{i}{i+1}}$ we have\n\\begin{equation}\\label{eq205}\n    x_{i+1} = \\arg\\min_x \\left(\\sqrt{\\frac{i}{i+1}}\\displaystyle\\sum_{j = 1}^{i} \\langle g_j, x\\rangle + \\sqrt{i}\\|x\\|_2^2 + \\sqrt{i(i+1)}R(x)\\right)\n\\end{equation}\nThe objective in equation (\\ref{eq205}) (which I will denote $O_{i+1}$) is strongly convex with strong convexity parameter $2\\sqrt{i}$. This means \nthat for any $z$ and $g_z\\in \\partial O_{i+1}(z)$, we have\n\\begin{equation}\\label{eq210}\n    \\|z - x_{i+1}\\|_2 \\leq \\frac{1}{\\sqrt{i}}\\|g_z\\|_2\n\\end{equation}\nsince $x_{i + 1} = \\arg\\min_x O_{i+1}(x)$. We wish to set $z = x_i$, but we need a $g_z$ first. Recall that since $x_i$ \nis the minimizer in equation (\\ref{eq201})\nwe have\n\\begin{equation}\n    0 = \\displaystyle\\sum_{j = 1}^{i-1} g_j + 2\\sqrt{i}x_i + i\\lambda\n\\end{equation}\nwith $\\lambda\\in \\partial R(x_i)$. Using this and taking the subdifferential of $O_{i+1}$ we see that\n\\begin{equation}\n    \\displaystyle\\sum_{j = 1}^{i-1} \\left(\\sqrt{\\frac{i}{i+1}} - 1\\right)g_j + \\sqrt{\\frac{i}{i+1}}g_i + (\\sqrt{i(i+1)} - i)\\lambda \\in \\partial O_{i+1}(x_i)\n\\end{equation}\nWe can bound the norm of this expression using the triangle inequality and our bounds on the elements in the subdifferentials of $f$ and\n$R$ by\n\\begin{equation}\n    \\frac{3}{2}M + \\frac{1}{2\\sqrt{i}}N\n\\end{equation}\nPlugging this into equation (\\ref{eq210}) and setting $z = x_i$, we see that\n\\begin{equation}\n    \\|x_i - x_{i+1}\\|_2 \\leq \\frac{3}{2\\sqrt{i}}M + \\frac{1}{2i}N\n\\end{equation}\nWe now plug this into equation (\\ref{eq65}) to get\n\\begin{equation}\n    \\displaystyle\\sum_{i=1}^n\\langle g_i, x_i - x_{i+1}\\rangle \\leq \\frac{3M^2}{2} \\displaystyle\\sum_{i=1}^n \\frac{1}{\\sqrt{i}} + \\frac{MN}{2}\\displaystyle\\sum_{i=1}^n \\frac{1}{i}\\leq 3M^2 \\sqrt{n} + MN\\log(n)\n\\end{equation}\nPlugging this into equation (\\ref{eq61}) we get\n\\begin{equation}\n    n(\\phi(\\bar{x}_n) - \\phi(x^*)) \\leq \\sqrt{n+1}\\|x^*\\|_2^2 + R(x^*) - R(x_{n+1}) + 3M^2 \\sqrt{n}+ MN\\log(n)\n\\end{equation}\nand finally\n\\begin{equation}\n     \\phi(\\bar{x}_n) - \\phi(x^*) \\leq \\frac{2\\|x^*\\|_2^2 + 3M^2}{\\sqrt{n}} + \\frac{(R(x^*) - \\inf_x R(x)) + MN\\log(n)}{n}\n\\end{equation}\nas desired.\n\\end{proof}\n\\fi\n", "meta": {"hexsha": "887a3c9f39fbe3383ba67218c6764219d69797ee", "size": 71239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ChRDA.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/ChRDA.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/ChRDA.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": 48.6605191257, "max_line_length": 529, "alphanum_fraction": 0.6405480144, "num_tokens": 29695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6143857623985791}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\begin{document}\n\t\\section{Karatsuba Multiplication}\n\t\n\tTwo numbers $l$ and $r$, can be written in the following way:\t\n\t\\begin{align*}\t\n\tl &= a*10^N + b\\\\  \n\tr &= c*10^N + d\\\\\n\t\\end{align*}\n\tIn this case their multiplication can be written\n\t\\begin{align*}\n\tl*r &= (a*10^N + b)*(c*10^N + d)\\\\ \n\t&= (a*c*10^{2N})+(a*d*10^N)+(b*c*10^N)+(b*d)\\\\  \n\t&= (a*c*10^{2N})+([(a*d)+(b*c)]*10^N)+]+(b*d)  \n\t\\end{align*}\n\tbut $(a*d)+(b*c)$ is equal to\n\t\\begin{align*}\n\t&= (a*d)+(b*c)\\\\\n\t&= (a+b)*(c+d) - ac - bd\\\\\n\t&= a*c + a*d + b*c + b*d - a*c - b*d\\\\\n\t&= a*d + b*c\n\t\\end{align*}\n\tnow we can change two multiplications $(a*d)$ and $(b*c)$ to just one: $(a+b)*(c+d)$, given that we have already calculated $a*c$ and $b*d$.  \n\t\n\tThis gives us the final form:\t\n\t\\begin{align*}\n\tl*r &= (a*c*10^{2N})\\\\&+([(a+b)*(c+d) - a*c - b*d]*10^N)\\\\&+(b*d)\n\t\\end{align*}\n\t\n\tSee:\\\\\n\t\\url{https://academic.microsoft.com/#/detail/204623740}\\\\\\\\\n\t\\url{https://scholar.google.co.uk/scholar?q=Multiplication+of+Many-Digital+Numbers+by+Automatic+Computers&btnG=&hl=en&as_sdt=0%2C5}\\\\\\\\\n\t\\url{http://cstheory.stackexchange.com/questions/21564/why-did-kolmogorov-publish-karatsubas-algorithm}\\\\\n\t\\\\\n\tThe Art of Computer Programming, Volume II, page 294, section 4.3.3\n\\end{document}", "meta": {"hexsha": "4a3640dcb7cb2a9242b2407c04627378ce72cffb", "size": 1420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/coursera-princeton-algorithms-1/karatsubamultiplication.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": "courses/coursera-princeton-algorithms-1/karatsubamultiplication.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": "courses/coursera-princeton-algorithms-1/karatsubamultiplication.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": 33.8095238095, "max_line_length": 143, "alphanum_fraction": 0.6197183099, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.614385759282418}}
{"text": "% arara: indent: {overwrite: true, trace: on}\n% A sample chapter file- it contains a lot of\n% environments, including tabulars, align, etc\n%\n% Don't try and compile this file using pdflatex etc, just\n% compare the *format* of it to the format of the\n% sampleAFTER.tex\n%\n% In particular, compare the tabular and align-type\n% environments before and after running the script\n\n\\section{Polynomial functions}\n \\reformatstepslist{P} % the steps list should be P1, P2, \\ldots\n In your previous mathematics classes you have studied \\emph{linear} and\n \\emph{quadratic} functions. The most general forms of these types of\n functions can be represented (respectively) by  the functions $f$\n and $g$ that have formulas\n \\begin{equation}\\label{poly:eq:linquad}\n \tf(x)=mx+b, \\qquad g(x)=ax^2+bx+c\n \\end{equation}\n We know that $m$ is the slope of $f$, and that $a$ is the \\emph{leading coefficient}\n of $g$. We also know that the \\emph{signs} of $m$ and $a$ completely\n determine the behavior of the functions $f$ and $g$. For example, if $m>0$\n then $f$ is an \\emph{increasing} function, and if $m<0$ then $f$ is\n a \\emph{decreasing} function.  Similarly, if $a>0$ then $g$ is\n \\emph{concave up} and if $a<0$ then $g$ is \\emph{concave down}. Graphical\n representations of these statements are given in \\cref{poly:fig:linquad}.\n\n \\begin{figure}[!htb]\n \t\\setlength{\\figurewidth}{.2\\textwidth}\n \t\\begin{subfigure}{\\figurewidth}\n \t\t\\begin{tikzpicture}\n \t\t\t\\begin{axis}[\n \t\t\t\t\tframed,\n \t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\txtick={-11},\n \t\t\t\t\tytick={-11},\n \t\t\t\t]\n \t\t\t\t\\addplot expression[domain=-10:8]{(x+2)};\n \t\t\t\\end{axis}\n \t\t\\end{tikzpicture}\n \t\t\\caption{$m>0$}\n \t\\end{subfigure}\n \t\\hfill\n \t\\begin{subfigure}{\\figurewidth}\n \t\t\\begin{tikzpicture}\n \t\t\t\\begin{axis}[\n \t\t\t\t\tframed,\n \t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\txtick={-11},\n \t\t\t\t\tytick={-11},\n \t\t\t\t]\n \t\t\t\t\\addplot expression[domain=-10:8]{-(x+2)};\n \t\t\t\\end{axis}\n \t\t\\end{tikzpicture}\n \t\t\\caption{$m<0$}\n \t\\end{subfigure}\n \t\\hfill\n \t\\begin{subfigure}{\\figurewidth}\n \t\t\\begin{tikzpicture}\n \t\t\t\\begin{axis}[\n \t\t\t\t\tframed,\n \t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\txtick={-11},\n \t\t\t\t\tytick={-11},\n \t\t\t\t]\n \t\t\t\t\\addplot expression[domain=-4:4]{(x^2-6)};\n \t\t\t\\end{axis}\n \t\t\\end{tikzpicture}\n \t\t\\caption{$a>0$}\n \t\\end{subfigure}\n \t\\hfill\n \t\\begin{subfigure}{\\figurewidth}\n \t\t\\begin{tikzpicture}\n \t\t\t\\begin{axis}[\n \t\t\t\t\tframed,\n \t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\txtick={-11},\n \t\t\t\t\tytick={-11},\n \t\t\t\t]\n \t\t\t\t\\addplot expression[domain=-4:4]{-(x^2-6)};\n \t\t\t\\end{axis}\n \t\t\\end{tikzpicture}\n \t\t\\caption{$a<0$}\n \t\\end{subfigure}\n \t\\caption{Typical graphs of linear and quadratic functions.}\n \t\\label{poly:fig:linquad}\n \\end{figure}\n\n Let's look a little more closely at the formulas for $f$ and $g$ in\n \\cref{poly:eq:linquad}. Note that the \\emph{degree}\n of $f$ is $1$ since the highest power of $x$ that is present in the\n formula for $f(x)$ is $1$. Similarly, the degree of $g$ is $2$ since\n the highest power of $x$ that is present in the formula for $g(x)$\n is $2$.\n\n In this section we will build upon our knowledge of these elementary\n functions. In particular, we will generalize the functions $f$ and $g$ to a function $p$ that has\n any degree that we wish.\n\n %===================================\n %   Author: Hughes\n %   Date:   March 2012\n %===================================\n \\begin{essentialskills}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{problem}[Quadratic functions]\n \tEvery quadratic function has the form $y=ax^2+bx+c$; state the value\n \tof $a$ for each of the following functions, and hence decide if the\n \tparabola that represents the function opens upward or downward.\n \t\\begin{multicols}{2}\n \t\t\\begin{subproblem}\n \t\t\t$F(x)=x^2+3$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$a=1$; the parabola opens upward.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$G(t)=4-5t^2$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$a=-5$; the parabola opens downward.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$H(y)=4y^2-96y+8$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$a=4$; the parabola opens upward.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$K(z)=-19z^2$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m=-19$; the parabola opens downward.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\\end{multicols}\n \tNow let's generalize our findings for the most general quadratic function $g$\n \tthat has formula $g(x)=a_2x^2+a_1x+a_0$. Complete the following sentences.\n \t\\begin{subproblem}\n \t\tWhen $a_2>0$, the parabola that represents $y=g(x)$ opens $\\ldots$\n \t\t\\begin{shortsolution}\n \t\t\tWhen $a_2>0$, the parabola that represents the function opens upward.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tWhen $a_2<0$, the parabola that represents $y=g(x)$ opens $\\ldots$\n \t\t\\begin{shortsolution}\n \t\t\tWhen $a_2<0$, the parabola that represents the function opens downward.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n \\end{essentialskills}\n\n \\subsection*{Power functions with positive exponents}\n \tThe study of polynomials will rely upon a good knowledge\n \tof power functions| you may reasonably ask, what is a power function?\n \t\\begin{pccdefinition}[Power functions]\n \t\tPower functions have the form\n \t\t\\[\n \t\t\tf(x) = a_n x^n\n \t\t\\]\n \t\twhere $n$ can be any real number.\n\n \t\tNote that for this section we will only be concerned with the\n \t\tcase when $n$ is a positive integer.\n \t\\end{pccdefinition}\n\n \tYou may find assurance in the fact that you are already very comfortable\n \twith power functions that have $n=1$ (linear) and $n=2$ (quadratic). Let's\n \texplore some power functions that you might not be so familiar with.\n \tAs you read \\cref{poly:ex:oddpow,poly:ex:evenpow}, try and spot\n \tas many patterns and similarities as you can.\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{pccexample}[Power functions with odd positive exponents]\n \t\t\\label{poly:ex:oddpow}\n \t\tGraph each of the following functions, state their domain, and their\n \t\tlong-run behavior as $x\\rightarrow\\pm\\infty$\n \t\t\\[\n \t\t\tf(x)=x^3,   \\qquad  g(x)=x^5, \\qquad h(x)=x^7\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\tThe functions $f$, $g$, and $h$ are plotted in \\cref{poly:fig:oddpow}.\n \t\t\tThe domain of each of the functions $f$, $g$, and $h$ is $(-\\infty,\\infty)$. Note that\n \t\t\tthe long-run behavior of each of the functions is the same, and in particular\n \t\t\t\\begin{align*}\n \t\t\t\tf(x)\\rightarrow\\infty                           & \\text{ as } x\\rightarrow\\infty  \\\\\n \t\t\t\t\\mathllap{\\text{and }}   f(x)\\rightarrow-\\infty & \\text{ as } x\\rightarrow-\\infty\n \t\t\t\\end{align*}\n \t\t\tThe same results hold for $g$ and $h$.\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t\\begin{figure}[!htb]\n \t\t\\begin{minipage}{.45\\textwidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-1.5,xmax=1.5,\n \t\t\t\t\t\tymin=-5,ymax=5,\n \t\t\t\t\t\txtick={-1.0,-0.5,...,1.0},\n \t\t\t\t\t\tminor ytick={-3,-1,...,3},\n \t\t\t\t\t\tgrid=both,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\tlegend pos=north west,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-1.5:1.5]{x^3};\n \t\t\t\t\t\\addplot expression[domain=-1.379:1.379]{x^5};\n \t\t\t\t\t\\addplot expression[domain=-1.258:1.258]{x^7};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-1,-1)} node[axisnode,anchor=north west]{$(-1,-1)$};\n \t\t\t\t\t\\addplot[soldot]coordinates{(1,1)} node[axisnode,anchor=south east]{$(1,1)$};\n \t\t\t\t\t\\legend{$f$,$g$,$h$}\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{Odd power functions}\n \t\t\t\\label{poly:fig:oddpow}\n \t\t\\end{minipage}%\n \t\t\\hfill\n \t\t\\begin{minipage}{.45\\textwidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-2.5,xmax=2.5,\n \t\t\t\t\t\tymin=-5,ymax=5,\n \t\t\t\t\t\txtick={-2.0,-1.5,...,2.0},\n \t\t\t\t\t\tminor ytick={-3,-1,...,3},\n \t\t\t\t\t\tgrid=both,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\tlegend pos=south east,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.236:2.236]{x^2};\n \t\t\t\t\t\\addplot expression[domain=-1.495:1.495]{x^4};\n \t\t\t\t\t\\addplot expression[domain=-1.307:1.307]{x^6};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-1,1)} node[axisnode,anchor=east]{$(-1,1)$};\n \t\t\t\t\t\\addplot[soldot]coordinates{(1,1)} node[axisnode,anchor=west]{$(1,1)$};\n \t\t\t\t\t\\legend{$F$,$G$,$H$}\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{Even power functions}\n \t\t\t\\label{poly:fig:evenpow}\n \t\t\\end{minipage}%\n \t\\end{figure}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{pccexample}[Power functions with even positive exponents]\\label{poly:ex:evenpow}%\n \t\tGraph each of the following functions, state their domain, and their\n \t\tlong-run behavior as $x\\rightarrow\\pm\\infty$\n \t\t\\[\n \t\t\tF(x)=x^2, \\qquad G(x)=x^4, \\qquad H(x)=x^6\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\tThe functions $F$, $G$, and $H$ are plotted in \\cref{poly:fig:evenpow}. The domain\n \t\t\tof each of the functions is $(-\\infty,\\infty)$. Note that the long-run behavior\n \t\t\tof each of the functions is the same, and in particular\n \t\t\t\\begin{align*}\n \t\t\t\tF(x)\\rightarrow\\infty                          & \\text{ as } x\\rightarrow\\infty  \\\\\n \t\t\t\t\\mathllap{\\text{and }}   F(x)\\rightarrow\\infty & \\text{ as } x\\rightarrow-\\infty\n \t\t\t\\end{align*}\n \t\t\tThe same result holds for $G$ and $H$.\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t\\begin{doyouunderstand}\n \t\t\\begin{problem}\n \t\tRepeat \\cref{poly:ex:oddpow,poly:ex:evenpow} using (respectively)\n \t\t\\begin{subproblem}\n \t\t\t$f(x)=-x^3,   \\qquad  g(x)=-x^5, \\qquad h(x)=-x^7$\n \t\t\t\\begin{shortsolution}\n \t\t\t\tThe functions $f$, $g$, and $h$ have domain $(-\\infty,\\infty)$ and\n \t\t\t\tare graphed below.\n\n \t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\tframed,\n \t\t\t\t\t\t\txmin=-1.5,xmax=1.5,\n \t\t\t\t\t\t\tymin=-5,ymax=5,\n \t\t\t\t\t\t\txtick={-1.0,-0.5,...,0.5},\n \t\t\t\t\t\t\tminor ytick={-3,-1,...,3},\n \t\t\t\t\t\t\tgrid=both,\n \t\t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\t\tlegend pos=north east,\n \t\t\t\t\t\t]\n \t\t\t\t\t\t\\addplot expression[domain=-1.5:1.5]{-x^3};\n \t\t\t\t\t\t\\addplot expression[domain=-1.379:1.379]{-x^5};\n \t\t\t\t\t\t\\addplot expression[domain=-1.258:1.258]{-x^7};\n \t\t\t\t\t\t\\legend{$f$,$g$,$h$}\n \t\t\t\t\t\\end{axis}\n \t\t\t\t\\end{tikzpicture}\n\n \t\t\t\tNote that\n \t\t\t\t\\begin{align*}\n \t\t\t\t\tf(x)\\rightarrow-\\infty                         & \\text{ as } x\\rightarrow\\infty  \\\\\n \t\t\t\t\t\\mathllap{\\text{and }}   f(x)\\rightarrow\\infty & \\text{ as } x\\rightarrow-\\infty\n \t\t\t\t\\end{align*}\n \t\t\t\tThe same is true for $g$ and $h$.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$F(x)=-x^2,   \\qquad  G(x)=-x^4, \\qquad H(x)=-x^6$\n \t\t\t\\begin{shortsolution}\n \t\t\t\tThe functions $F$, $G$, and $H$ have domain $(-\\infty,\\infty)$ and\n \t\t\t\tare graphed below.\n\n \t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\tframed,\n \t\t\t\t\t\t\txmin=-2.5,xmax=2.5,\n \t\t\t\t\t\t\tymin=-5,ymax=5,\n \t\t\t\t\t\t\txtick={-1.0,-0.5,...,0.5},\n \t\t\t\t\t\t\tminor ytick={-3,-1,...,3},\n \t\t\t\t\t\t\tgrid=both,\n \t\t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\t\tlegend pos=north east,\n \t\t\t\t\t\t]\n \t\t\t\t\t\t\\addplot expression[domain=-2.236:2.236]{-x^2};\n \t\t\t\t\t\t\\addplot expression[domain=-1.495:1.495]{-x^4};\n \t\t\t\t\t\t\\addplot expression[domain=-1.307:1.307]{-x^6};\n \t\t\t\t\t\t\\legend{$F$,$G$,$H$}\n \t\t\t\t\t\\end{axis}\n \t\t\t\t\\end{tikzpicture}\n\n \t\t\t\tNote that\n \t\t\t\t\\begin{align*}\n \t\t\t\t\tF(x)\\rightarrow-\\infty                          & \\text{ as } x\\rightarrow\\infty  \\\\\n \t\t\t\t\t\\mathllap{\\text{and }}   F(x)\\rightarrow-\\infty & \\text{ as } x\\rightarrow-\\infty\n \t\t\t\t\\end{align*}\n \t\t\t\tThe same is true for $G$ and $H$.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\end{problem}\n \t\\end{doyouunderstand}\n\n \\subsection*{Polynomial functions}\n \tNow that we have a little more familiarity with power functions,\n \twe can define polynomial functions. Provided that you were comfortable\n \twith our opening discussion about linear and quadratic functions (see\n \t$f$ and $g$ in \\cref{poly:eq:linquad}) then there is every chance\n \tthat you'll be able to master polynomial functions as well; just remember\n \tthat polynomial functions are a natural generalization of linear\n \tand quadratic functions. Once you've studied the examples and problems\n \tin this section, you'll hopefully agree that polynomial functions\n \tare remarkably predictable.\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{pccdefinition}[Polynomial functions]\n \t\tPolynomial functions have the form\n \t\t\\[\n \t\t\tp(x)=a_nx^n+a_{n-1}x^{n-1}+\\ldots+a_1x+a_0\n \t\t\\]\n \t\twhere $a_n$, $a_{n-1}$, $a_{n-2}$, \\ldots, $a_0$ are real numbers.\n \t\t\\begin{itemize}\n \t\t\t\\item We call $n$ the degree of the polynomial, and require that $n$\n \t\t\t      is a non-negative integer;\n \t\t\t\\item $a_n$, $a_{n-1}$, $a_{n-2}$, \\ldots, $a_0$ are called the coefficients;\n \t\t\t\\item We typically write polynomial functions in descending powers of $x$.\n \t\t\\end{itemize}\n \t\tIn particular, we call $a_n$ the \\emph{leading} coefficient, and $a_nx^n$ the\n \t\t\\emph{leading term}.\n\n \t\tNote that if a polynomial is given in factored form, then the degree can be found\n \t\tby counting the number of linear factors.\n \t\\end{pccdefinition}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{pccexample}[Polynomial or not]\n \t\tIdentify the following functions as polynomial or not; if the function\n \t\tis a polynomial, state its degree.\n \t\t\\begin{multicols}{3}\n \t\t\t\\begin{enumerate}\n \t\t\t\t\\item $p(x)=x^2-3$\n \t\t\t\t\\item $q(x)=-4x^{\\nicefrac{1}{2}}+10$\n \t\t\t\t\\item $r(x)=10x^5$\n \t\t\t\t\\item $s(x)=x^{-2}+x^{23}$\n \t\t\t\t\\item $f(x)=-8$\n \t\t\t\t\\item $g(x)=3^x$\n \t\t\t\t\\item $h(x)=\\sqrt[3]{x^7}-x^2+x$\n \t\t\t\t\\item $k(x)=4x(x+2)(x-3)$\n \t\t\t\t\\item $j(x)=x^2(x-4)(5-x)$\n \t\t\t\\end{enumerate}\n \t\t\\end{multicols}\n \t\t\\begin{pccsolution}\n \t\t\t\\begin{enumerate}\n \t\t\t\t\\item $p$ is a polynomial, and its degree is $2$.\n \t\t\t\t\\item $q$ is \\emph{not} a polynomial, because $\\frac{1}{2}$ is not an integer.\n \t\t\t\t\\item $r$ is a polynomial, and its degree is $5$.\n \t\t\t\t\\item $s$ is \\emph{not} a polynomial, because $-2$ is not a positive integer.\n \t\t\t\t\\item $f$ is a polynomial, and its degree is $0$.\n \t\t\t\t\\item $g$ is \\emph{not} a polynomial, because the independent\n \t\t\t\t      variable, $x$, is in the exponent.\n \t\t\t\t\\item $h$ is \\emph{not} a polynomial, because $\\frac{7}{3}$ is not an integer.\n \t\t\t\t\\item $k$ is a polynomial, and its degree is $3$.\n \t\t\t\t\\item $j$ is a polynomial, and its degree is $4$.\n \t\t\t\\end{enumerate}\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{pccexample}[Typical graphs]\\label{poly:ex:typical}\n \t\t\\Cref{poly:fig:typical} shows graphs of some polynomial functions;\n \t\tthe ticks have deliberately been left off the axis to allow us to concentrate\n \t\ton the features of each graph. Note in particular that:\n \t\t\\begin{itemize}\n \t\t\t\\item \\cref{poly:fig:typical1} shows a degree-$1$ polynomial (you might also\n \t\t\t      classify the function as linear) whose leading coefficient, $a_1$, is positive.\n \t\t\t\\item \\cref{poly:fig:typical2} shows a degree-$2$ polynomial (you might also\n \t\t\t      classify the function as quadratic) whose leading coefficient, $a_2$, is positive.\n \t\t\t\\item \\cref{poly:fig:typical3} shows a degree-$3$ polynomial whose leading coefficient, $a_3$,\n \t\t\t      is positive| compare its overall\n \t\t\t      shape and long-run behavior to the functions described in \\cref{poly:ex:oddpow}.\n \t\t\t\\item \\cref{poly:fig:typical4} shows a degree-$4$ polynomial whose leading coefficient, $a_4$,\n \t\t\t      is positive|compare its overall shape and long-run behavior to the functions described in \\cref{poly:ex:evenpow}.\n \t\t\t\\item \\cref{poly:fig:typical5} shows a degree-$5$ polynomial whose leading coefficient, $a_5$,\n \t\t\t      is positive| compare its overall\n \t\t\t      shape and long-run behavior to the functions described in \\cref{poly:ex:oddpow}.\n \t\t\\end{itemize}\n \t\\end{pccexample}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{figure}[!htb]\n \t\t\\begin{widepage}\n \t\t\\setlength{\\figurewidth}{\\textwidth/6}\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-10:8]{(x+2)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$a_1>0$}\n \t\t\t\\label{poly:fig:typical1}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4:4]{(x^2-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$a_2>0$}\n \t\t\t\\label{poly:fig:typical2}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-7.5:7.5]{0.05*(x+6)*x*(x-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$a_3>0$}\n \t\t\t\\label{poly:fig:typical3}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.35:5.35,samples=100]{0.2*(x-5)*x*(x-3)*(x+2)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$a_4>0$}\n \t\t\t\\label{poly:fig:typical4}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-5.5:6.3,samples=100]{0.01*(x+2)*x*(x-3)*(x+5)*(x-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$a_5>0$}\n \t\t\t\\label{poly:fig:typical5}\n \t\t\\end{subfigure}\n \t\t\\end{widepage}\n \t\t\\caption{Graphs to illustrate typical curves of polynomial functions.}\n \t\t\\label{poly:fig:typical}\n \t\\end{figure}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{doyouunderstand}\n \t\t\\begin{problem}\n \t\tUse \\cref{poly:ex:typical} and \\cref{poly:fig:typical} to help you sketch\n \t\tthe graphs of polynomial functions that have negative leading coefficients| note\n \t\tthat there are many ways to do this! The intention with this problem\n \t\tis to use your knowledge of transformations- in particular, \\emph{reflections}-\n \t\tto guide you.\n \t\t\\begin{shortsolution}\n \t\t\t$a_1<0$:\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-10:8]{-(x+2)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$a_2<0$\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4:4]{-(x^2-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$a_3<0$\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-7.5:7.5]{-0.05*(x+6)*x*(x-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$a_4<0$\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.35:5.35,samples=100]{-0.2*(x-5)*x*(x-3)*(x+2)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$a_5<0$\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t\txtick={-11},\n \t\t\t\t\t\tytick={-11},\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-5.5:6.3,samples=100]{-0.01*(x+2)*x*(x-3)*(x+5)*(x-6)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\\end{shortsolution}\n \t\t\\end{problem}\n \t\\end{doyouunderstand}\n\n \t\\fixthis{poly: Need a more basic example here- it can have a similar\n \t\tformat to the multiple zeros example, but just keep it simple; it should\n \tbe halfway between the 2 examples surrounding it}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{pccexample}[Multiple zeros]\n \t\tConsider the polynomial functions $p$, $q$, and $r$ which are\n \t\tgraphed in \\cref{poly:fig:moremultiple}.\n \t\tThe formulas for $p$, $q$, and $r$ are as follows\n \t\t\\begin{align*}\n \t\t\tp(x) & =(x-3)^2(x+4)^2       \\\\\n \t\t\tq(x) & =x(x+2)^2(x-1)^2(x-3) \\\\\n \t\t\tr(x) & =x(x-3)^3(x+1)^2\n \t\t\\end{align*}\n \t\tFind the degree of $p$, $q$, and $r$, and decide if the functions bounce off or cut\n \t\tthrough the horizontal axis at each of their zeros.\n \t\t\\begin{pccsolution}\n \t\t\tThe degree of $p$ is 4. Referring to \\cref{poly:fig:bouncep},\n \t\t\tthe curve bounces off the horizontal axis at both zeros, $3$ and $4$.\n\n \t\t\tThe degree of $q$ is 6. Referring to \\cref{poly:fig:bounceq},\n \t\t\tthe curve bounces off the horizontal axis at $-2$ and $1$, and cuts\n \t\t\tthrough the horizontal axis at $0$ and $3$.\n\n \t\t\tThe degree of $r$ is 6. Referring to \\cref{poly:fig:bouncer},\n \t\t\tthe curve bounces off the horizontal axis at $-1$, and cuts through\n \t\t\tthe horizontal axis at $0$ and at $3$, although is flattened immediately to the left and right of $3$.\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t\\setlength{\\figurewidth}{0.25\\textwidth}\n \t\\begin{figure}[!htb]\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-6,xmax=5,\n \t\t\t\t\t\tymin=-30,ymax=200,\n \t\t\t\t\t\txtick={-4,-2,...,4},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-5.63733:4.63733,samples=50]{(x-3)^2*(x+4)^2};\n \t\t\t\t\t\\addplot[soldot]coordinates{(3,0)(-4,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=p(x)$}\n \t\t\t\\label{poly:fig:bouncep}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-3,xmax=4,\n \t\t\t\t\t\txtick={-2,...,3},\n \t\t\t\t\t\tymin=-60,ymax=40,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot+[samples=50] expression[domain=-2.49011:3.11054]{x*(x+2)^2*(x-1)^2*(x-3)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-2,0)(0,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=q(x)$}\n \t\t\t\\label{poly:fig:bounceq}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-2,xmax=4,\n \t\t\t\t\t\txtick={-1,...,3},\n \t\t\t\t\t\tymin=-40,ymax=40,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-1.53024:3.77464,samples=50]{x*(x-3)^3*(x+1)^2};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-1,0)(0,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=r(x)$}\n \t\t\t\\label{poly:fig:bouncer}\n \t\t\\end{subfigure}\n \t\t\\caption{}\n \t\t\\label{poly:fig:moremultiple}\n \t\\end{figure}\n\n \t\\begin{pccdefinition}[Multiple zeros]\\label{poly:def:multzero}\n \t\tLet $p$ be a polynomial that has a repeated linear factor $(x-a)^n$. Then we say\n \t\tthat $p$ has a multiple zero at $a$ of multiplicity $n$ and\n \t\t\\begin{itemize}\n \t\t\t\\item if the factor $(x-a)$ is repeated an even number of times, the graph of $y=p(x)$ does not\n \t\t\t      cross the $x$ axis at $a$, but `bounces' off the horizontal axis at $a$.\n \t\t\t\\item if the factor $(x-a)$ is repeated an odd number of times, the graph of $y=p(x)$ crosses the\n \t\t\t      horizontal axis at $a$, but it looks `flattened' there\n \t\t\\end{itemize}\n \t\tIf $n=1$, then we say that $p$ has a \\emph{simple} zero at $a$.\n \t\\end{pccdefinition}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{pccexample}[Find a formula]\n \t\tFind formulas for the polynomial functions, $p$ and $q$, graphed in \\cref{poly:fig:findformulademoboth}.\n \t\t\\begin{figure}[!htb]\n \t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\\begin{axis}[framed,\n \t\t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\t\txtick={-4,-2,...,4},\n \t\t\t\t\t\t\tminor xtick={-3,-1,...,3},\n \t\t\t\t\t\t\tytick={-8,-6,...,8},\n \t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\tgrid=both]\n \t\t\t\t\t\t\\addplot expression[domain=-3.25842:2.25842,samples=50]{-x*(x-2)*(x+3)*(x+1)};\n \t\t\t\t\t\t\\addplot[soldot]coordinates{(1,8)}node[axisnode,inner sep=.35cm,anchor=west]{$(1,8)$};\n \t\t\t\t\t\t\\addplot[soldot]coordinates{(-3,0)(-1,0)(0,0)(2,0)};\n \t\t\t\t\t\\end{axis}\n \t\t\t\t\\end{tikzpicture}\n \t\t\t\t\\caption{$p$}\n \t\t\t\t\\label{poly:fig:findformulademo}\n \t\t\t\\end{subfigure}\n \t\t\t\\hfill\n \t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\\begin{axis}[framed,\n \t\t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\t\txtick={-4,-2,...,4},\n \t\t\t\t\t\t\tminor xtick={-3,-1,...,3},\n \t\t\t\t\t\t\tytick={-8,-6,...,8},\n \t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\tgrid=both]\n \t\t\t\t\t\t\\addplot expression[domain=-4.33:4.08152]{-.25*(x+2)^2*(x-3)};\n \t\t\t\t\t\t\\addplot[soldot]coordinates{(2,4)}node[axisnode,anchor=south west]{$(2,4)$};\n \t\t\t\t\t\t\\addplot[soldot]coordinates{(-2,0)(3,0)};\n \t\t\t\t\t\\end{axis}\n \t\t\t\t\\end{tikzpicture}\n \t\t\t\t\\caption{$q$}\n \t\t\t\t\\label{poly:fig:findformulademo1}\n \t\t\t\\end{subfigure}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:findformulademoboth}\n \t\t\\end{figure}\n \t\t\\begin{pccsolution}\n \t\t\t\\begin{enumerate}\n \t\t\t\t\\item We begin by noting that the horizontal intercepts of $p$ are $(-3,0)$, $(-1,0)$, $(0,0)$ and $(2,0)$.\n \t\t\t\t      We also note that each zero is simple (multiplicity $1$).\n \t\t\t\t      If we assume that $p$ has no other zeros, then we can start by writing\n \t\t\t\t      \\begin{align*}\n \t\t\t\t      \tp(x) & =(x+3)(x+1)(x-0)(x-2) \\\\\n \t\t\t\t      \t     & =x(x+3)(x+1)(x-2)     \\\\\n \t\t\t\t      \\end{align*}\n \t\t\t\t      According to \\cref{poly:fig:findformulademo}, the point $(1,8)$ lies\n \t\t\t\t      on the curve $y=p(x)$.\n \t\t\t\t      Let's check if the formula we have written satisfies this requirement\n \t\t\t\t      \\begin{align*}\n \t\t\t\t      \tp(1) & = (1)(4)(2)(-1) \\\\\n \t\t\t\t      \t     & = -8\n \t\t\t\t      \\end{align*}\n \t\t\t\t      which is clearly not correct| it is close though. We can correct this by\n \t\t\t\t      multiplying $p$ by a constant $k$; so let's assume that\n \t\t\t\t      \\[\n \t\t\t\t      \tp(x)=kx(x+3)(x+1)(x-2)\n \t\t\t\t      \\]\n \t\t\t\t      Then $p(1)=-8k$, and if this is to equal $8$, then $k=-1$. Therefore\n \t\t\t\t      the formula for $p(x)$ is\n \t\t\t\t      \\[\n \t\t\t\t      \tp(x)=-x(x+3)(x+1)(x-2)\n \t\t\t\t      \\]\n \t\t\t\t\\item The function $q$ has a zero at $-2$ of multiplicity $2$, and zero of\n \t\t\t\t      multiplicity $1$ at $3$ (so $3$ is a simple zero of $q$); we can therefore assume that $q$ has the form\n \t\t\t\t      \\[\n \t\t\t\t      \tq(x)=k(x+2)^2(x-3)\n \t\t\t\t      \\]\n \t\t\t\t      where $k$ is some real number. In order to find $k$, we use the given ordered pair, $(2,4)$, and\n \t\t\t\t      evaluate $p(2)$\n \t\t\t\t      \\begin{align*}\n \t\t\t\t      \tp(2) & =k(4)^2(-1) \\\\\n \t\t\t\t      \t     & =-16k\n \t\t\t\t      \\end{align*}\n \t\t\t\t      We solve the equation $4=-8k$ and obtain $k=-\\frac{1}{4}$ and conclude that the\n \t\t\t\t      formula for $q(x)$ is\n \t\t\t\t      \\[\n \t\t\t\t      \tq(x)=-\\frac{1}{4}(x+2)^2(x-3)\n \t\t\t\t      \\]\n \t\t\t\\end{enumerate}\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n\n \t\\fixthis{Chris: need sketching polynomial problems}\n \t\\begin{pccspecialcomment}[Steps to follow when sketching polynomial functions]\n \t\t\\begin{steps}\n \t\t\t\\item \\label{poly:step:first} Determine the degree of the polynomial,\n \t\t\tits leading term and leading coefficient, and hence determine\n \t\t\tthe long-run behavior of the polynomial| does it behave like $\\pm x^2$ or $\\pm x^3$\n \t\t\tas $x\\rightarrow\\pm\\infty$?\n \t\t\t\\item Determine the zeros and their multiplicity. Mark all zeros\n \t\t\tand the vertical intercept on the graph using solid circles $\\bullet$.\n \t\t\t\\item \\label{poly:step:last}  Deduce the overall shape of the curve, and sketch it. If there isn't\n \t\t\tenough information from the previous steps, then construct a table of values.\n \t\t\\end{steps}\n \t\tRemember that until we have the tools of calculus, we won't be able to\n \t\tfind the exact coordinates of local minimums, local maximums, and points\n \t\tof inflection.\n \t\\end{pccspecialcomment}\n \tBefore we demonstrate some examples, it is important to remember the following:\n \t\\begin{itemize}\n \t\t\\item our sketches will give a good representation of the overall\n \t\t      shape of the graph, but until we have the tools of calculus (from MTH 251)\n \t\t      we can not find local minimums, local maximums, and inflection points algebraically. This\n \t\t      means that we will make our best guess as to where these points are.\n \t\t\\item we will not concern ourselves too much with the vertical scale (because of\n \t\t      our previous point)| we will, however, mark the vertical intercept (assuming there is one),\n \t\t      and any horizontal asymptotes.\n \t\\end{itemize}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2012\n \t%===================================\n \t\\begin{pccexample}\\label{poly:ex:simplecubic}\n \t\tUse \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $p$\n \t\tthat has formula\n \t\t\\[\n \t\t\tp(x)=\\frac{1}{2}(x-4)(x-1)(x+3)\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\t\\begin{steps}\n \t\t\t\t\\item $p$ has degree $3$. The leading term of $p$ is $\\frac{1}{2}x^3$, so the leading coefficient of $p$\n \t\t\t\tis $\\frac{1}{2}$. The long-run behavior of $p$ is therefore similar to that of $x^3$.\n \t\t\t\t\\item The zeros of $p$ are $-3$, $1$, and $4$; each zero is simple (i.e, it has multiplicity $1$).\n \t\t\t\tThis means that the curve of $p$ cuts the horizontal axis at each zero. The vertical\n \t\t\t\tintercept of $p$ is $(0,6)$.\n \t\t\t\t\\item We draw the details we have obtained so far on \\cref{poly:fig:simplecubicp1}. Given\n \t\t\t\tthat the curve of $p$ looks like the curve of $x^3$ in the long-run, we are able to complete a sketch of the\n \t\t\t\tgraph of $p$ in \\cref{poly:fig:simplecubicp2}.\n\n \t\t\t\tNote that we can not find the coordinates of the local minimums, local maximums, and inflection\n \t\t\t\tpoints| for the moment we make reasonable guesses as to where these points are (you'll find how\n \t\t\t\tto do this in calculus).\n \t\t\t\\end{steps}\n\n \t\t\t\\begin{figure}[!htbp]\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\t\t\tymin=-10,ymax=15,\n \t\t\t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\t\t\tytick={-5,5},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-3,0)(1,0)(4,0)(0,6)}node[axisnode,anchor=south west]{$(0,6)$};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:simplecubicp1}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\hfill\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\t\t\tymin=-10,ymax=15,\n \t\t\t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\t\t\tytick={-5,5},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-3,0)(1,0)(4,0)(0,6)}node[axisnode,anchor=south west]{$(0,6)$};\n \t\t\t\t\t\t\t\\addplot[pccplot] expression[domain=-3.57675:4.95392,samples=100]{.5*(x-4)*(x-1)*(x+3)};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:simplecubicp2}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\caption{$y=\\dfrac{1}{2}(x-4)(x-1)(x+3)$}\n \t\t\t\t\\label{poly:fig:simplecubic}\n \t\t\t\\end{figure}\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2012\n \t%===================================\n \t\\begin{pccexample}\\label{poly:ex:degree5}\n \t\tUse \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $q$\n \t\tthat has formula\n \t\t\\[\n \t\t\tq(x)=\\frac{1}{200}(x+7)^2(2-x)(x-6)^2\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\t\\begin{steps}\n \t\t\t\t\\item $q$ has degree $4$. The leading term of $q$ is\n \t\t\t\t\\[\n \t\t\t\t\t-\\frac{1}{200}x^5\n \t\t\t\t\\]\n \t\t\t\tso the leading coefficient of $q$ is $-\\frac{1}{200}$. The long-run behavior of $q$\n \t\t\t\tis therefore similar to that of $-x^5$.\n \t\t\t\t\\item The zeros of $q$ are $-7$ (multiplicity 2), $2$ (simple), and $6$ (multiplicity $2$).\n \t\t\t\tThe curve of $q$ bounces off the horizontal axis at the zeros with multiplicity $2$ and\n \t\t\t\tcuts the horizontal axis at the simple zeros. The vertical intercept of $q$ is $\\left( 0,\\frac{441}{25} \\right)$.\n \t\t\t\t\\item We mark the details we have found so far on \\cref{poly:fig:degree5p1}. Given that\n \t\t\t\tthe curve of $q$ looks like the curve of $-x^5$ in the long-run, we can complete \\cref{poly:fig:degree5p2}.\n \t\t\t\\end{steps}\n\n \t\t\t\\begin{figure}[!htbp]\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\t\t\tymin=-10,ymax=40,\n \t\t\t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\t\t\tytick={-5,0,...,35},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-7,0)(2,0)(6,0)(0,441/25)}node[axisnode,anchor=south west]{$\\left( 0, \\frac{441}{25} \\right)$};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:degree5p1}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\hfill\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\t\t\tymin=-10,ymax=40,\n \t\t\t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\t\t\tytick={-5,0,...,35},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-7,0)(2,0)(6,0)(0,441/25)}node[axisnode,anchor=south west]{$\\left( 0, \\frac{441}{25} \\right)$};\n \t\t\t\t\t\t\t\\addplot[pccplot] expression[domain=-8.83223:7.34784,samples=50]{1/200*(x+7)^2*(2-x)*(x-6)^2};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:degree5p2}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\caption{$y=\\dfrac{1}{200}(x+7)^2(2-x)(x-6)^2$}\n \t\t\t\t\\label{poly:fig:degree5}\n \t\t\t\\end{figure}\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2012\n \t%===================================\n \t\\begin{pccexample}\n \t\tUse \\crefrange{poly:step:first}{poly:step:last} to sketch a graph of the function $r$\n \t\tthat has formula\n \t\t\\[\n \t\t\tr(x)=\\frac{1}{100}x^3(x+4)(x-4)(x-6)\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\t\\begin{steps}\n \t\t\t\t\\item $r$ has degree $6$. The leading term of $r$ is\n \t\t\t\t\\[\n \t\t\t\t\t\\frac{1}{100}x^6\n \t\t\t\t\\]\n \t\t\t\tso the leading coefficient of $r$ is $\\frac{1}{100}$. The long-run behavior of $r$\n \t\t\t\tis therefore similar to that of $x^6$.\n \t\t\t\t\\item The zeros of $r$ are $-4$ (simple), $0$ (multiplicity $3$), $4$ (simple),\n \t\t\t\tand $6$ (simple). The vertical intercept of $r$ is $(0,0)$. The curve of $r$\n \t\t\t\tcuts the horizontal axis at the simple zeros, and goes through the axis\n \t\t\t\tat $(0,0)$, but does so in a flattened way.\n \t\t\t\t\\item We mark the zeros and vertical intercept on \\cref{poly:fig:degree6p1}. Given that\n \t\t\t\tthe curve of $r$ looks like the curve of $x^6$ in the long-run, we complete the graph\n \t\t\t\tof $r$ in \\cref{poly:fig:degree6p2}.\n \t\t\t\\end{steps}\n\n \t\t\t\\begin{figure}[!htbp]\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-5,xmax=10,\n \t\t\t\t\t\t\t\tymin=-20,ymax=10,\n \t\t\t\t\t\t\t\txtick={-4,-2,...,8},\n \t\t\t\t\t\t\t\tytick={-15,-10,...,5},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-4,0)(0,0)(4,0)(6,0)};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:degree6p1}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\hfill\n \t\t\t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\t\\begin{axis}[\n \t\t\t\t\t\t\t\txmin=-5,xmax=10,\n \t\t\t\t\t\t\t\tymin=-20,ymax=10,\n \t\t\t\t\t\t\t\txtick={-4,-2,...,8},\n \t\t\t\t\t\t\t\tytick={-15,-10,...,5},\n \t\t\t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\t\t]\n \t\t\t\t\t\t\t\\addplot[soldot] coordinates{(-4,0)(0,0)(4,0)(6,0)};\n \t\t\t\t\t\t\t\\addplot[pccplot] expression[domain=-4.16652:6.18911,samples=100]{1/100*(x+4)*x^3*(x-4)*(x-6)};\n \t\t\t\t\t\t\\end{axis}\n \t\t\t\t\t\\end{tikzpicture}\n \t\t\t\t\t\\caption{}\n \t\t\t\t\t\\label{poly:fig:degree6p2}\n \t\t\t\t\\end{subfigure}%\n \t\t\t\t\\caption{$y=\\dfrac{1}{100}(x+4)x^3(x-4)(x-6)$}\n \t\t\t\\end{figure}\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{pccexample}[An open-topped box]\n \t\tA cardboard company makes open-topped boxes for their clients. The specifications\n \t\tdictate that the box must have a square base, and that it must be open-topped.\n \t\tThe company uses sheets of cardboard that are $\\unit[1200]{cm^2}$. Assuming that\n \t\tthe base of each box has side $x$ (measured in cm), it can be shown that the volume of each box, $V(x)$,\n \t\thas formula\n \t\t\\[\n \t\t\tV(x)=\\frac{x}{4}(1200-x^2)\n \t\t\\]\n \t\tFind the dimensions of the box that maximize the volume.\n \t\t\\begin{pccsolution}\n \t\t\tWe graph $y=V(x)$ in \\cref{poly:fig:opentoppedbox}. Note that because\n \t\t\t$x$ represents the length of a side, and $V(x)$ represents the volume\n \t\t\tof the box, we necessarily require both values to be positive; we illustrate\n \t\t\tthe part of the curve that applies to this problem using a solid line.\n\n \t\t\t\\begin{figure}[!htb]\n \t\t\t\t\\centering\n \t\t\t\t\\begin{tikzpicture}\n \t\t\t\t\t\\begin{axis}[framed,\n \t\t\t\t\t\t\txmin=-50,xmax=50,\n \t\t\t\t\t\t\tymin=-5000,ymax=5000,\n \t\t\t\t\t\t\txtick={-40,-30,...,40},\n \t\t\t\t\t\t\tminor xtick={-45,-35,...,45},\n \t\t\t\t\t\t\tminor ytick={-3000,-1000,1000,3000},\n \t\t\t\t\t\t\twidth=.75\\textwidth,\n \t\t\t\t\t\t\theight=.5\\textwidth,\n \t\t\t\t\t\tgrid=both]\n \t\t\t\t\t\t\\addplot[pccplot,dashed,<-] expression[domain=-40:0,samples=50]{x/4*(1200-x^2)};\n \t\t\t\t\t\t\\addplot[pccplot,-] expression[domain=0:34.64,samples=50]{x/4*(1200-x^2)};\n \t\t\t\t\t\t\\addplot[pccplot,dashed,->] expression[domain=34.64:40,samples=50]{x/4*(1200-x^2)};\n \t\t\t\t\t\t\\addplot[soldot] coordinates{(20,4000)};\n \t\t\t\t\t\\end{axis}\n \t\t\t\t\\end{tikzpicture}\n \t\t\t\t\\caption{$y=V(x)$}\n \t\t\t\t\\label{poly:fig:opentoppedbox}\n \t\t\t\\end{figure}\n\n \t\t\tAccording to \\cref{poly:fig:opentoppedbox}, the maximum volume of such a box is\n \t\t\tapproximately $\\unit[4000]{cm^2}$, and we achieve it using a base of length\n \t\t\tapproximately $\\unit[20]{cm}$. Since the base is square and each sheet of cardboard\n \t\t\tis $\\unit[1200]{cm^2}$, we conclude that the dimensions of each box are $\\unit[20]{cm}\\times\\unit[20]{cm}\\times\\unit[30]{cm}$.\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n\n \\subsection*{Complex zeros}\n \tThere has been a pattern to all of the examples that we have seen so far|\n \tthe degree of the polynomial has dictated the number of \\emph{real} zeros that the\n \tpolynomial has. For example, the function $p$ in \\cref{poly:ex:simplecubic}\n \thas degree $3$, and $p$ has $3$ real zeros; the function $q$ in \\cref{poly:ex:degree5}\n \thas degree $5$ and $q$ has $5$ real zeros.\n\n \tYou may wonder if this result can be generalized| does every polynomial that\n \thas degree $n$ have $n$ real zeros? Before we tackle the general result,\n \tlet's consider an example that may help motivate it.\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   June 2012\n \t%===================================\n \t\\begin{pccexample}\\label{poly:ex:complx}\n \t\tConsider the polynomial function $c$ that has formula\n \t\t\\[\n \t\t\tc(x)=x(x^2+1)\n \t\t\\]\n \t\tIt is clear that $c$ has degree $3$, and that $c$ has a (simple) zero at $0$. Does\n \t\t$c$ have any other zeros, i.e, can we find any values of $x$ that satisfy the equation\n \t\t\\begin{equation}\\label{poly:eq:complx}\n \t\t\tx^2+1=0\n \t\t\\end{equation}\n \t\tThe solutions to \\cref{poly:eq:complx} are $\\pm i$.\n\n \t\tWe conclude that $c$ has $3$ zeros: $0$ and $\\pm i$; we note that \\emph{not\n \t\tall of them are real}.\n \t\\end{pccexample}\n \t\\Cref{poly:ex:complx} shows that not every degree-$3$ polynomial has $3$\n \t\\emph{real} zeros; however, if we are prepared to venture into the complex numbers,\n \tthen we can state the following theorem.\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   June 2012\n \t%===================================\n \t\\begin{pccspecialcomment}[The fundamental theorem of algebra]\n \t\tEvery polynomial function of degree $n$ has $n$ roots, some of which may\n \t\tbe complex, and some may be repeated.\n \t\\end{pccspecialcomment}\n \t\\fixthis{Fundamental theorem of algebra: is this wording ok? do we want\n \tit as a theorem?}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   June 2012\n \t%===================================\n \t\\begin{pccexample}\n \t\tFind all the zeros of the polynomial function $p$ that has formula\n \t\t\\[\n \t\t\tp(x)=x^4-2x^3+5x^2\n \t\t\\]\n \t\t\\begin{pccsolution}\n \t\t\tWe begin by factoring $p$\n \t\t\t\\begin{align*}\n \t\t\t\tp(x) & =x^4-2x^3+5x^2 \\\\\n \t\t\t\t     & =x^2(x^2-2x+5)\n \t\t\t\\end{align*}\n \t\t\tWe note that $0$ is a zero of $p$ with multiplicity $2$. The other zeros of $p$\n \t\t\tcan be found by solving the equation\n \t\t\t\\[\n \t\t\t\tx^2-2x+5=0\n \t\t\t\\]\n \t\t\tThis equation can not be factored, so we use the quadratic formula\n \t\t\t\\begin{align*}\n \t\t\t\tx & =\\frac{2\\pm\\sqrt{(-2)^2}-20}{2(1)} \\\\\n \t\t\t\t  & =\\frac{2\\pm\\sqrt{-16}}{2}          \\\\\n \t\t\t\t  & =1\\pm 2i\n \t\t\t\\end{align*}\n \t\t\tWe conclude that $p$ has $4$ zeros: $0$ (multiplicity $2$), and $1\\pm 2i$ (simple).\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   June 2012\n \t%===================================\n \t\\begin{pccexample}\n \t\tFind a polynomial that has zeros at $2\\pm i\\sqrt{2}$.\n \t\t\\begin{pccsolution}\n \t\t\tWe know that the zeros of a polynomial can be found by analyzing the linear\n \t\t\tfactors. We are given the zeros, and have to work backwards to find the\n \t\t\tlinear factors.\n\n \t\t\tWe begin by assuming that $p$ has the form\n \t\t\t\\begin{align*}\n \t\t\t\tp(x) & =(x-(2-i\\sqrt{2}))(x-(2+i\\sqrt{2}))                           \\\\\n \t\t\t\t     & =x^2-x(2+i\\sqrt{2})-x(2-i\\sqrt{2})+(2-i\\sqrt{2})(2+i\\sqrt{2}) \\\\\n \t\t\t\t     & =x^2-4x+(4-2i^2)                                              \\\\\n \t\t\t\t     & =x^2-4x+6\n \t\t\t\\end{align*}\n \t\t\tWe conclude that a possible formula for a polynomial function, $p$,\n \t\t\tthat has zeros at $2\\pm i\\sqrt{2}$ is\n \t\t\t\\[\n \t\t\t\tp(x)=x^2-4x+6\n \t\t\t\\]\n \t\t\tNote that we could multiply $p$ by any real number and still ensure\n \t\t\tthat $p$ has the same zeros.\n \t\t\\end{pccsolution}\n \t\\end{pccexample}\n \t\\investigation*{}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Find a formula from a graph]\n \tFor each of the polynomials in \\cref{poly:fig:findformula}\n \t\\begin{enumerate}\n \t\t\\item count the number of times the curve turns round, and cuts/bounces off the $x$ axis;\n \t\t\\item approximate the degree of the polynomial;\n \t\t\\item use your information to find the linear factors of each polynomial, and therefore write a possible formula for each;\n \t\t\\item make sure your polynomial goes through the given ordered pair.\n \t\\end{enumerate}\n \t\\begin{shortsolution}\n \t\t\\Vref{poly:fig:findformdeg2}:\n \t\t\\begin{enumerate}\n \t\t\t\\item the curve turns round once;\n \t\t\t\\item the degree could be 2;\n \t\t\t\\item based on the zeros, the linear factors are $(x+5)$ and $(x-3)$; since the\n \t\t\t      graph opens downwards, we will assume the leading coefficient is negative: $p(x)=-k(x+5)(x-3)$;\n \t\t\t\\item $p$ goes through $(2,2)$, so we need to solve $2=-k(7)(-1)$ and therefore $k=\\nicefrac{2}{7}$, so\n \t\t\t      \\[\n \t\t\t      \tp(x)=-\\frac{2}{7}(x+5)(x-3)\n \t\t\t      \\]\n \t\t\\end{enumerate}\n \t\t\\Vref{poly:fig:findformdeg3}:\n \t\t\\begin{enumerate}\n \t\t\t\\item the curve turns around twice;\n \t\t\t\\item the degree could be 3;\n \t\t\t\\item based on the zeros, the linear factors are $(x+2)^2$, and $(x-1)$;\n \t\t\t      based on the behavior of $p$, we assume that the leading coefficient is positive, and try $p(x)=k(x+2)^2(x-1)$;\n \t\t\t\\item $p$ goes through $(0,-2)$, so we need to solve $-2=k(4)(-1)$ and therefore $k=\\nicefrac{1}{2}$, so\n \t\t\t      \\[\n \t\t\t      \tp(x)=\\frac{1}{2}(x+2)^2(x-1)\n \t\t\t      \\]\n \t\t\\end{enumerate}\n \t\t\\Vref{poly:fig:findformdeg5}:\n \t\t\\begin{enumerate}\n \t\t\t\\item the curve turns around 4 times;\n \t\t\t\\item the degree could be 5;\n \t\t\t\\item based on the zeros, the linear factors are $(x+5)^2$, $(x+1)$, $(x-2)$, $(x-3)$;\n \t\t\t      based on the behavior of $p$, we assume that the leading coefficient is positive, and try $p(x)=k(x+5)^2(x+1)(x-2)(x-3)$;\n \t\t\t\\item $p$ goes through $(-3,-50)$, so we need to solve $-50=k(64)(-2)(-5)(-6)$ and therefore $k=\\nicefrac{5}{384}$, so\n \t\t\t      \\[\n \t\t\t      \tp(x)=\\frac{5}{384}(x+5)^2(x+1)(x-2)(x-3)\n \t\t\t      \\]\n \t\t\\end{enumerate}\n \t\\end{shortsolution}\n \t\\end{problem}\n\n\n \t\\begin{figure}[!htb]\n \t\t\\setlength{\\figurewidth}{0.3\\textwidth}\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-2,ymax=5,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4.5:3.75]{-1/3*(x+4)*(x-3)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-4,0)(3,0)(2,2)} node[axisnode,above right]{$(2,2)$};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:findformdeg2}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-3,xmax=2,\n \t\t\t\t\t\tymin=-2,ymax=4,\n \t\t\t\t\t\txtick={-2,...,1},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.95:1.75]{1/3*(x+2)^2*(x-1)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-2,0)(1,0)(0,-1.33)}node[axisnode,anchor=north west]{$(0,-2)$};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:findformdeg3}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-100,ymax=150,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4.5:3.4,samples=50]{(x+4)^2*(x+1)*(x-2)*(x-3)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-4,0)(-1,0)(2,0)(3,0)(-3,-60)}node[axisnode,anchor=north]{$(-3,-50)$};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:findformdeg5}\n \t\t\\end{subfigure}\n \t\t\\caption{}\n \t\t\\label{poly:fig:findformula}\n \t\\end{figure}\n\n\n\n\n \t\\begin{exercises}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{problem}[Prerequisite classifacation skills]\n \tDecide if each of the following functions are linear or quadratic.\n \t\\begin{multicols}{3}\n \t\t\\begin{subproblem}\n \t\t\t$f(x)=2x+3$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$f$ is linear.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$g(x)=10-7x$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$g$ is linear\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$h(x)=-x^2+3x-9$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$h$ is quadratic.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$k(x)=-17$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$k$ is linear.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$l(x)=-82x^2-4$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$l$ is quadratic\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$m(x)=6^2x-8$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m$ is linear.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\\end{multicols}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{problem}[Prerequisite slope identification]\n \tState the slope of each of the following linear functions, and\n \thence decide if each function is increasing or decreasing.\n \t\\begin{multicols}{4}\n \t\t\\begin{subproblem}\n \t\t\t$\\alpha(x)=4x+1$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m=4$; $\\alpha$ is increasing.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$\\beta(x)=-9x$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m=-9$; $\\beta$ is decreasing.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$\\gamma(t)=18t+100$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m=18$; $\\gamma$ is increasing.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$\\delta(y)=23-y$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$m=-1$; $\\delta$ is decreasing.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\\end{multicols}\n \tNow let's generalize our findings for the most general linear function $f$\n \tthat has formula $f(x)=mx+b$. Complete the following sentences.\n \t\\begin{subproblem}\n \t\tWhen $m>0$, the function $f$ is $\\ldots$\n \t\t\\begin{shortsolution}\n \t\t\tWhen $m>0$, the function $f$ is $\\ldots$  \\emph{increasing}.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tWhen $m<0$, the function $f$ is $\\ldots$\n \t\t\\begin{shortsolution}\n \t\t\tWhen $m<0$, the function $f$ is $\\ldots$  \\emph{decreasing}.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Polynomial or not?]\n \tIdentify whether each of the following functions is a polynomial or not.\n \tIf the function is a polynomial, state its degree.\n \t\\begin{multicols}{3}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=2x+1$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial (you might also describe $p$ as linear). The degree of $p$ is 1.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=7x^2+4x$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial (you might also describe $p$ as quadratic). The degree of $p$ is 2.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=\\sqrt{x}+2x+1$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is not a polynomial; we require the powers of $x$ to be integer values.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=2^x-45$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is not a polynomial; the $2^x$ term is exponential.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=6x^4-5x^3+9$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial, and the degree of $p$ is $6$.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=-5x^{17}+9x+2$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial, and the degree of $p$ is 17.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=4x(x+7)^2(x-3)^3$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial, and the degree of $p$ is $6$.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=4x^{-5}-x^2+x$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is not a polynomial because $-5$ is not a positive integer.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$p(x)=-x^6(x^2+1)(x^3-2)$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$p$ is a polynomial, and the degree of $p$ is $11$.\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\\end{multicols}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Polynomial graphs]\n \tThree polynomial functions $p$, $m$, and $n$ are shown in \\crefrange{poly:fig:functionp}{poly:fig:functionn}.\n \tThe functions have the following formulas\n \t\\begin{align*}\n \t\tp(x) & = (x-1)(x+2)(x-3)           \\\\\n \t\tm(x) & = -(x-1)(x+2)(x-3)          \\\\\n \t\tn(x) & = (x-1)(x+2)(x-3)(x+1)(x+4)\n \t\\end{align*}\n \tNote that for our present purposes we are not concerned with the vertical scale of the graphs.\n \t\\begin{subproblem}\n \t\tIdentify both on the graph {\\em and} algebraically, the zeros of each polynomial.\n \t\t\\begin{shortsolution}\n \t\t\t$y=p(x)$ is shown below.\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.5:3.5,samples=50]{(x-1)*(x+2)*(x-3)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-2,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$y=m(x)$ is shown below.\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.5:3.5,samples=50]{-1*(x-1)*(x+2)*(x-3)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-2,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\t$y=n(x)$ is shown below.\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-90,ymax=70,\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4.15:3.15,samples=50]{(x-1)*(x+2)*(x-3)*(x+1)*(x+4)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-4,0)(-2,0)(-1,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n\n \t\t\tThe zeros of $p$ are $-2$, $1$, and $3$; the zeros of $m$ are $-2$, $1$, and $3$; the zeros of $n$ are\n \t\t\t$-4$, $-2$, $-1$, and $3$.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tWrite down the degree, how many times the curve of each function `turns around',\n \t\tand how many zeros it has\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item The degree of $p$ is 3, and the curve $y=p(x)$ turns around twice.\n \t\t\t\t\\item The degree of $q$ is also 3, and the curve $y=q(x)$ turns around twice.\n \t\t\t\t\\item The degree of $n$ is $5$, and the curve $y=n(x)$ turns around 4 times.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n\n \t\\begin{figure}[!htb]\n \t\t\\begin{widepage}\n \t\t\\setlength{\\figurewidth}{0.3\\textwidth}\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\tytick={-5,5},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.5:3.5,samples=50]{(x-1)*(x+2)*(x-3)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-2,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=p(x)$}\n \t\t\t\\label{poly:fig:functionp}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\tytick={-5,5},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-2.5:3.5,samples=50]{-1*(x-1)*(x+2)*(x-3)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-2,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=m(x)$}\n \t\t\t\\label{poly:fig:functionm}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-5,xmax=5,\n \t\t\t\t\t\tymin=-90,ymax=70,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4.15:3.15,samples=100]{(x-1)*(x+2)*(x-3)*(x+1)*(x+4)};\n \t\t\t\t\t\\addplot[soldot]coordinates{(-4,0)(-2,0)(-1,0)(1,0)(3,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{$y=n(x)$}\n \t\t\t\\label{poly:fig:functionn}\n \t\t\\end{subfigure}\n \t\t\\caption{}\n \t\t\\end{widepage}\n \t\\end{figure}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Horizontal intercepts]\\label{poly:prob:matchpolys}%\n \tState the horizontal intercepts (as ordered pairs) of the following polynomials.\n \t\\begin{multicols}{2}\n \t\t\\begin{subproblem}\\label{poly:prob:degree5}\n \t\t\t$p(x)=(x-1)(x+2)(x-3)(x+1)(x+4)$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$(-4,0)$, $(-2,0)$, $(-1,0)$, $(1,0)$, $(3,0)$\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$q(x)=-(x-1)(x+2)(x-3)$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$(-2,0)$, $(1,0)$, $(3,0)$\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\n \t\t\t$r(x)=(x-1)(x+2)(x-3)$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$(-2,0)$, $(1,0)$, $(3,0)$\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\t\\begin{subproblem}\\label{poly:prob:degree2}\n \t\t\t$s(x)=(x-2)(x+2)$\n \t\t\t\\begin{shortsolution}\n \t\t\t\t$(-2,0)$, $(2,0)$\n \t\t\t\\end{shortsolution}\n \t\t\\end{subproblem}\n \t\\end{multicols}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   March 2012\n \t%===================================\n \t\\begin{problem}[Minimums, maximums, and concavity]\\label{poly:prob:incdec}\n \tFour polynomial functions are graphed in \\cref{poly:fig:incdec}. The formulas\n \tfor these functions are (not respectively)\n \t\\begin{gather*}\n \t\tp(x)=\\frac{x^3}{6}-\\frac{x^2}{4}-3x, \\qquad q(x)=\\frac{x^4}{20}+\\frac{x^3}{15}-\\frac{6}{5}x^2+1\\\\\n \t\tr(x)=-\\frac{x^5}{50}-\\frac{x^4}{40}+\\frac{2x^3}{5}+6, \\qquad s(x)=-\\frac{x^6}{6000}-\\frac{x^5}{2500}+\\frac{67x^4}{4000}+\\frac{17x^3}{750}-\\frac{42x^2}{125}\n \t\\end{gather*}\n \t\\begin{figure}[!htb]\n \t\t\\begin{widepage}\n \t\t\\setlength{\\figurewidth}{.23\\textwidth}\n \t\t\\centering\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-8,-6,...,8},\n \t\t\t\t\t\tgrid=major,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-5.28:4.68,samples=50]{-x^5/50-x^4/40+2*x^3/5+6};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:incdec3}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txmin=-10,xmax=10,ymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-8,-6,...,8},\n \t\t\t\t\t\tgrid=major,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-6.08:4.967,samples=50]{x^4/20+x^3/15-6/5*x^2+1};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:incdec2}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txmin=-6,xmax=8,ymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-4,-2,...,6},\n \t\t\t\t\t\tytick={-8,-4,4,8},\n \t\t\t\t\t\tminor ytick={-6,-2,...,6},\n \t\t\t\t\t\tgrid=both,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-4.818:6.081,samples=50]{x^3/6-x^2/4-3*x};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:incdec1}\n \t\t\\end{subfigure}\n \t\t\\hfill\n \t\t\\begin{subfigure}{\\figurewidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\tframed,\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\txmin=-10,xmax=10,ymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-4,4,8},\n \t\t\t\t\t\tytick={-8,-4,4,8},\n \t\t\t\t\t\tminor xtick={-6,-2,...,6},\n \t\t\t\t\t\tminor ytick={-6,-2,...,6},\n \t\t\t\t\t\tgrid=both,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-9.77:8.866,samples=50]{-x^6/6000-x^5/2500+67*x^4/4000+17/750*x^3-42/125*x^2};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:incdec4}\n \t\t\\end{subfigure}\n \t\t\\caption{Graphs for \\cref{poly:prob:incdec}.}\n \t\t\\label{poly:fig:incdec}\n \t\t\\end{widepage}\n \t\\end{figure}\n \t\\begin{subproblem}\n \t\tMatch each of the formulas with one of the given graphs.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ is graphed in \\vref{poly:fig:incdec1};\n \t\t\t\t\\item $q$ is graphed in \\vref{poly:fig:incdec2};\n \t\t\t\t\\item $r$ is graphed in \\vref{poly:fig:incdec3};\n \t\t\t\t\\item $s$ is graphed in \\vref{poly:fig:incdec4}.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tApproximate the zeros of each function using the appropriate graph.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ has simple zeros at about $-3.8$, $0$, and $5$.\n \t\t\t\t\\item $q$ has simple zeros at about $-5.9$, $-1$, $1$, and $4$.\n \t\t\t\t\\item $r$ has simple zeros at about $-5$, $-2.9$, and $4.1$.\n \t\t\t\t\\item $s$ has simple zeros at about $-9$, $-6$, $4.2$, $8.1$, and a zero of multiplicity $2$ at $0$.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tApproximate the local maximums and minimums of each of the functions.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ has a local maximum of approximately $3.9$ at $-2$, and a local minimum of approximately $-6.5$ at $3$.\n \t\t\t\t\\item $q$ has a local minimum of approximately $-10$ at $-4$, and $-4$ at $3$; $q$ has a local maximum of approximately $1$ at $0$.\n \t\t\t\t\\item $r$ has a local minimum of approximately $-5.5$ at $-4$, and a local maximum of approximately $10$ at $3$.\n \t\t\t\t\\item $s$ has a local maximum of approximately $5$ at $-8$, $0$ at $0$, and $5$ at  $7$; $s$ has local minimums\n \t\t\t\t      of approximately $-3$ at $-4$, and $-1$ at $3$.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tApproximate the global maximums and minimums of each of the functions.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ does not have a global maximum, nor a global minimum.\n \t\t\t\t\\item $q$ has a global minimum of approximately $-10$; it does not have a global maximum.\n \t\t\t\t\\item $r$ does not have a global maximum, nor a global minimum.\n \t\t\t\t\\item $s$ has a global maximum of approximately $5$; it does not have a global minimum.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tApproximate the intervals on which each function is increasing and decreasing.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ is increasing on $(-\\infty,-2)\\cup (3,\\infty)$, and decreasing on $(-2,3)$.\n \t\t\t\t\\item $q$ is increasing on $(-4,0)\\cup (3,\\infty)$, and decreasing on $(-\\infty,-4)\\cup (0,3)$.\n \t\t\t\t\\item $r$ is increasing on $(-4,3)$, and decreasing on $(-\\infty,-4)\\cup (3,\\infty)$.\n \t\t\t\t\\item $s$ is increasing on $(-\\infty,-8)\\cup (-4,0)\\cup (3,5)$, and decreasing on $(-8,-4)\\cup (0,3)\\cup (5,\\infty)$.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tApproximate the intervals on which each function is concave up and concave down.\n \t\t\\begin{shortsolution}\n \t\t\t\\begin{itemize}\n \t\t\t\t\\item $p$ is concave up on  $(1,\\infty)$, and concave down on  $(-\\infty,1)$.\n \t\t\t\t\\item $q$ is concave up on $(-\\infty,-1)\\cup (1,\\infty)$, and concave down on $(-1,1)$.\n \t\t\t\t\\item $r$ is concave up on $(-\\infty,-3)\\cup (0,2)$, and concave down on $(-3,0)\\cup (2,\\infty)$.\n \t\t\t\t\\item $s$ is concave up on $(-6,-2)\\cup (2,5)$, and concave down on $(-\\infty,-6)\\cup (-2,2)\\cup (5,\\infty)$.\n \t\t\t\\end{itemize}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tThe degree of $q$ is $5$. Assuming that all of the real zeros of $q$ are\n \t\tshown in its graph, how many complex zeros does $q$ have?\n \t\t\\begin{shortsolution}\n \t\t\t\\Vref{poly:fig:incdec2} shows that $q$ has $3$ real zeros\n \t\t\tsince the curve of $q$ cuts the horizontal axis $3$ times.\n \t\t\tSince $q$ has degree $5$, $q$ must have $2$ complex zeros.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Long-run behaviour of polynomials]\n \tDescribe the long-run behavior of each of polynomial functions in\n \t\\crefrange{poly:prob:degree5}{poly:prob:degree2}.\n \t\\begin{shortsolution}\n \t\t$\\dd\\lim_{x\\rightarrow-\\infty}p(x)=-\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow\\infty}p(x)=\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow-\\infty}q(x)=\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow\\infty}q(x)=-\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow-\\infty}r(x)=-\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow\\infty}r(x)=\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow-\\infty}s(x)=\\infty$,\n \t\t$\\dd\\lim_{x\\rightarrow\\infty}s(x)=\\infty$,\n \t\\end{shortsolution}\n \t\\end{problem}\n\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[True of false?]\n \tLet $p$ be a polynomial function.\n \tLabel each of the following statements as true (T) or false (F); if they are false,\n \tprovide an example that supports your answer.\n \t\\begin{subproblem}\n \t\tIf $p$ has degree $3$, then $p$ has $3$ distinct zeros.\n \t\t\\begin{shortsolution}\n \t\t\tFalse. Consider $p(x)=x^2(x+1)$ which has only 2 distinct zeros.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tIf $p$ has degree $4$, then $\\dd\\lim_{x\\rightarrow-\\infty}p(x)=\\infty$ and $\\dd\\lim_{x\\rightarrow\\infty}p(x)=\\infty$.\n \t\t\\begin{shortsolution}\n \t\t\tFalse. Consider $p(x)=-x^4$.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tIf $p$ has even degree, then it is possible that $p$ can have no real zeros.\n \t\t\\begin{shortsolution}\n \t\t\tTrue.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tIf $p$ has odd degree, then it is possible that $p$ can have no real zeros.\n \t\t\\begin{shortsolution}\n \t\t\tFalse. All odd degree polynomials will cut the horizontal axis at least once.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   May 2011\n \t%===================================\n \t\\begin{problem}[Find a formula from a description]\n \tIn each of the following problems, give a possible formula for a polynomial\n \tfunction that has the specified properties.\n \t\\begin{subproblem}\n \t\tDegree 2 and has zeros at $4$ and $5$.\n \t\t\\begin{shortsolution}\n \t\t\tPossible option: $p(x)=(x-4)(x-5)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tDegree 3 and has zeros at $4$,$5$ and $-3$.\n \t\t\\begin{shortsolution}\n \t\t\tPossible option: $p(x)=(x-4)(x-5)(x+3)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tDegree 4 and has zeros at $0$, $4$, $5$, $-3$.\n \t\t\\begin{shortsolution}\n \t\t\tPossible option: $p(x)=x(x-4)(x-5)(x+3)$. Note we could multiply $p$ by any real number, and still meet the requirements.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tDegree 4, with zeros that make the graph cut at $2$, $-5$, and a zero that makes the graph touch at $-2$;\n \t\t\\begin{shortsolution}\n \t\t\tPossible option: $p(x)=(x-2)(x+5)(x+2)^2$. Note we could multiply $p$ by any real number, and still meet the requirements.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tDegree 3, with only one zero at $-1$.\n \t\t\\begin{shortsolution}\n \t\t\tPossible option: $p(x)=(x+1)^3$. Note we could multiply $p$ by any real number, and still meet the requirements.\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n \t%===================================\n \t%   Author: Hughes\n \t%   Date:   June 2012\n \t%===================================\n \t\\begin{problem}[\\Cref{poly:step:last}]\n \t\\pccname{Saheed} is graphing a polynomial function, $p$.\n \tHe is following \\crefrange{poly:step:first}{poly:step:last} and has so far\n \tmarked the zeros of $p$ on \\cref{poly:fig:optionsp1}. Saheed tells you that\n \t$p$ has degree $3$, but does \\emph{not} say if the leading coefficient\n \tof $p$ is positive or negative.\n \t\\begin{figure}[!htbp]\n \t\t\\begin{widepage}\n \t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\theight=.5\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:optionsp1}\n \t\t\\end{subfigure}%\n \t\t\\hfill\n \t\t\\begin{subfigure}{.45\\textwidth}\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\textwidth,\n \t\t\t\t\t\theight=.5\\textwidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\t\\caption{}\n \t\t\t\\label{poly:fig:optionsp2}\n \t\t\\end{subfigure}%\n \t\t\\caption{}\n \t\t\\end{widepage}\n \t\\end{figure}\n \t\\begin{subproblem}\n \t\tUse the information in \\cref{poly:fig:optionsp1} to help sketch $p$, assuming that the leading coefficient\n \t\tis positive.\n \t\t\\begin{shortsolution}\n \t\t\tAssuming that $a_3>0$:\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-6.78179:8.35598,samples=50]{1/20*(x+5)*(x-2)*(x-6)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tUse the information in \\cref{poly:fig:optionsp1} to help sketch $p$, assuming that the leading coefficient\n \t\tis negative.\n \t\t\\begin{shortsolution}\n \t\t\tAssuming that $a_3<0$:\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-6.78179:8.35598,samples=50]{-1/20*(x+5)*(x-2)*(x-6)};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(2,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \tSaheed now turns his attention to another polynomial function, $q$. He finds\n \tthe zeros of $q$ (there are only $2$) and marks them on \\cref{poly:fig:optionsp2}.\n \tSaheed knows that $q$ has degree $3$, but doesn't know if the leading\n \tcoefficient is positive or negative.\n \t\\begin{subproblem}\n \t\tUse the information in \\cref{poly:fig:optionsp2} to help sketch $q$, assuming that the leading\n \t\tcoefficient of $q$ is positive. Hint: only one of the zeros is simple.\n \t\t\\begin{shortsolution}\n \t\t\tAssuming that $a_4>0$ there are $2$ different options:\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-8.68983:7.31809,samples=50]{1/20*(x+5)^2*(x-6)};\n \t\t\t\t\t\\addplot expression[domain=-6.31809:9.68893,samples=50]{1/20*(x+5)*(x-6)^2};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\begin{subproblem}\n \t\tUse the information in \\cref{poly:fig:optionsp2} to help sketch $q$, assuming that the leading\n \t\tcoefficient of $q$ is negative.\n \t\t\\begin{shortsolution}\n \t\t\tAssuming that $a_4<0$ there are $2$ different options:\n\n \t\t\t\\begin{tikzpicture}\n \t\t\t\t\\begin{axis}[\n \t\t\t\t\t\txmin=-10,xmax=10,\n \t\t\t\t\t\tymin=-10,ymax=10,\n \t\t\t\t\t\txtick={-8,-6,...,8},\n \t\t\t\t\t\tytick={-15},\n \t\t\t\t\t\twidth=\\solutionfigurewidth,\n \t\t\t\t\t]\n \t\t\t\t\t\\addplot expression[domain=-8.68983:7.31809,samples=50]{-1/20*(x+5)^2*(x-6)};\n \t\t\t\t\t\\addplot expression[domain=-6.31809:9.68893,samples=50]{-1/20*(x+5)*(x-6)^2};\n \t\t\t\t\t\\addplot[soldot] coordinates{(-5,0)(6,0)};\n \t\t\t\t\\end{axis}\n \t\t\t\\end{tikzpicture}\n \t\t\\end{shortsolution}\n \t\\end{subproblem}\n \t\\end{problem}\n", "meta": {"hexsha": "302fb6ab0d9675e9e5e7b04bde3890f90fecc27f", "size": 69952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-smaller.tex", "max_stars_repo_name": "digorithm/latex-linter", "max_stars_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_stars_repo_licenses": ["MIT"], "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/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-smaller.tex", "max_issues_repo_name": "digorithm/latex-linter", "max_issues_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_issues_repo_licenses": ["MIT"], "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/server/dependencies/latexindent.pl-master/test-cases/benchmarks/sampleBEFORE-smaller.tex", "max_forks_repo_name": "digorithm/latex-linter", "max_forks_repo_head_hexsha": "d6b63002cdcecf291e2abc7a399e0d7af4bd9038", "max_forks_repo_licenses": ["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.9410589411, "max_line_length": 158, "alphanum_fraction": 0.5903333715, "num_tokens": 24928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.826711787666479, "lm_q1q2_score": 0.614385743531311}}
{"text": "\\appendix\n\n\\chapter{Pangolin v1.0, a~conservative 2-D transport model for large scale\nparallel calculation}\n\\label{app:paper}\nThis paper was accepted by the \\gls{GMD} journal.\n\n\\input pangolin_paper\n\n\\chapter{Supplement}\n\\section{Proof: number of cells at the poles}\n\\label{sec:pole_area}\n\\def\\dphi{\\Delta\\phi}\n\\def\\dlamb{\\Delta\\lambda}\nHere, we demonstrate why the number of cells at the poles for the Pangolin grid\ncan be approximated by $3$. The latitude spacing is supposed to be \"small\"\nenough and the cells are supposed to be square at the Equator.\nWe first consider the surface of the band near the Equator, defined by \n$\\pi/2 - \\dphi \\le \\phi \\le \\pi/2$:\n\\begin{equation*}\n  S_{eq} = \\int_{0}^{2\\pi}\\int_{\\pi/2}^{\\pi/2 - \\dphi} r^2 \\sin\\phi \\mathrm{d}\\lambda\n  \\mathrm{d}\\phi \n      = 2\\pi r^2 \\sin \\dphi\n\\end{equation*}\nThe surface of the band near the North Pole ($0 \\le \\phi \\le \\dphi$) is:\n\\begin{equation*}\n  S_{pole} = \\int_{0}^{2\\pi}\\int_{0}^{\\dphi} r^2 \\sin\\phi \\mathrm{d}\\lambda\n  \\mathrm{d}\\phi \n      = 2\\pi r^2 (1-\\cos \\dphi)\n\\end{equation*}\nThe number of cells at the Equator is $2\\pi/\\dlamb=2\\pi/\\dphi$ so the area of the cells at\nthe Equator is:\n\\begin{equation*}\n  \\mathcal{A}_{eq}=\\frac{S_{eq}}{\\frac{2\\pi}{\\dphi}} = r^2 \\dphi \\sin \\dphi\n\\end{equation*}\nThe grid preserves the areas so the number of cells at the pole is:\n\\begin{equation*}\n  n_1 = \\Big \\lfloor\\frac{S_{pole}}{\\mathcal{A}_{eq}} \\Big \\rfloor \n      =\\Big \\lfloor\\frac{2\\pi(1-\\cos \\dphi)}{\\dphi \\sin\n  \\dphi } \\Big \\rfloor \n\\end{equation*}\nUsing small angles approximations, it gives:\n\\begin{equation*}\n  n_1 = \\Big \\lfloor \\frac{2\\pi(\\frac{\\dphi^2}{2})}{\\dphi^2} \\Big \\rfloor = \\lfloor \\pi\n  \\rfloor = 3\n\\end{equation*}\n\n\\section{MPI send modes}\n\\label{app:mpi_send}\nThe following is taken from\n\\url{http://www.mcs.anl.gov/research/projects/mpi/sendmode.html}:\n\n% Create a format entry-definition, each with a new paragraph\n\\def\\entry#1#2{\\leftskip=0pt \\texttt{#1}\\par\\noindent\n\\leftskip=1.5cm #2\\par\\indent}\n\n\\entry{MPI\\_Send}{will not return until you can use the send buffer. It may or may\nnot block (it is allowed to buffer, either on the sender or receiver side,\nor to wait for the matching receive). \nMay buffer; returns immediately and you can use the send buffer. A late\nadd-on to the MPI specification. Should be used only when absolutely\nnecessary.}\n\\entry{MPI\\_Ssend}{will not return until matching receive posted.}\n\\entry{MPI\\_Rsend}{may be used \\textbf{only} if matching receive already posted. User\nresponsible for writing a correct program.}\n\\entry{MPI\\_Isend}{\n    Nonblocking send. But not necessarily asynchronous. You can\n    \\textbf{not} reuse the send buffer until either a successful,\n    wait/test or you \\textbf{know} that the message has been received\n    (see \\texttt{MPI\\_Request\\_free}). Note also that while the I refers to\n    immediate, there is no performance requirement on \\texttt{MPI\\_Isend}.\n    An immediate send must return to the user without requiring\n    a matching receive at the destination. An implementation is\n    free to send the data to the destination before returning,\n    as long as the send call does not block waiting for a\n    matching receive. Different strategies of when to send the\n    data offer different performance advantages and\n    disadvantages that will depend on the application. \n  }\n\\entry{MPI\\_Ibsend}{buffered nonblocking.}\n\\entry{MPI\\_Issend}{\n    Synchronous nonblocking. Note that a Wait/Test will\n    complete only when the matching receive is posted. \n}\n\\entry{MPI\\_Irsend}{ As with MPI\\_Rsend, but nonblocking.}\n\n\\chapter{Design}\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.9\\linewidth]{pangolin_classes.pdf}\n  \\caption{Classes diagram for Pangolin, with the main classes.}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.4\\linewidth]{flowcharts/pangolin_run.pdf}\n  \\caption{Flowchart representing a full run in Pangolin. Input winds are\n    supposed to be divergence free: there were corrected either during their\n    generation (analytical winds) or during interpolation (real winds). As\n    temporal interpolation is linear, interpolated winds do not need to be corrected\n    either}\n  \\label{fig:pango_run}\n\\end{figure}\n", "meta": {"hexsha": "c4247f3564cf3a2fad3b45b2cf40d2b50c5898be", "size": 4229, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix.tex", "max_stars_repo_name": "alexDarcy/phd", "max_stars_repo_head_hexsha": "f39ef9de23e8c8e08c86f95b7501e1e91321ad2b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-08-28T10:05:20.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-28T10:05:20.000Z", "max_issues_repo_path": "appendix.tex", "max_issues_repo_name": "alexDarcy/thesis", "max_issues_repo_head_hexsha": "f39ef9de23e8c8e08c86f95b7501e1e91321ad2b", "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": "appendix.tex", "max_forks_repo_name": "alexDarcy/thesis", "max_forks_repo_head_hexsha": "f39ef9de23e8c8e08c86f95b7501e1e91321ad2b", "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": 40.6634615385, "max_line_length": 90, "alphanum_fraction": 0.7297233389, "num_tokens": 1287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6143267037114389}}
{"text": "\\section{Overview of Optimization Algorithms}\n\\label{sec:51algorithms}\n\n\\paragraph{Problem setting}\n\n\\minitoc{80mm}{7}\n\n\\usenotation{Ëopt}\nGenerally, \\term{unconstrained optimization problems} have the form\n\\begin{equation}\n  \\label{eq:unconstrainedOptimization}\n  \\xopt = \\vecargmin \\objfun(\\*x),\\quad\n  \\*x \\in \\real^d,\n\\end{equation}\nwhere $\\objfun\\colon \\real^d \\to \\real$ is the \\term{objective function.}\n\\term{Constrained optimization problems} are given by\n\\begin{equation}\n  \\label{eq:constrainedOptimization}\n  \\xopt = \\vecargmin \\objfun(\\*x),\\quad\n  \\*x \\in \\real^d\\;\\;\\text{s.t.}\\;\\;\n  \\ineqconfun(\\*x) \\le \\*0,\n\\end{equation}\nwhere\n$\\ineqconfun\\colon \\real^d \\to \\real^{m_{\\ineqconfun}}$\n($m_{\\ineqconfun} \\in \\nat$)\nis the \\term{(inequality) constraint function.}\nThis formulation also contains optimization problems\nwith equality constraints $\\eqconfun(\\*x) = \\*0$\nby setting $\\ineqconfun(\\*x) \\ceq (\\eqconfun(\\*x), -\\eqconfun(\\*x))$.\nEquality constraints can also be solved by incorporating them\ninto the unconstrained solver (e.g., see \\cite{Boyd04Convex}\nfor an equality-constrained Newton method).\n\nAs sparse grid surrogates $\\objfun = \\sgintp$ are only defined on the\nunit hyper-cube,\nthe choice of $\\*x$ has to be restricted to $\\clint{\\*0, \\*1}$.\nIn the case of \\eqref{eq:unconstrainedOptimization},\nthis results in a \\term{box-constrained optimization problem.}\nA simple method for applying unconstrained optimization algorithms\nto box-constrained problems is extending $\\sgintp$ to $\\real^d$ by\n$\\sgintp(\\*x) \\ceq +\\infty$ for all $\\*x \\in \\real^d \\setminus \\clint{\\*0, \\*1}$.\nHowever, more sophisticated\n%, algorithm-tailored\napproaches are also available \\cite{More87Optimization}.\n\n\\paragraph{Black-box optimization methods}\n\nProblems of the form \\eqref{eq:unconstrainedOptimization} or\n\\eqref{eq:constrainedOptimization} are \\term{black-box optimization problems,}\nwhere we cannot gain any insight into the structure or algebraic\nproperties of $\\objfun$.\nBlack-box optimization methods perform a series of evaluations\n$\\objfun(\\*x_k)$,\nchoosing the next evaluation point $\\*x_{k+1}$\nbased on the previous function values $\\objfun(\\*x_0), \\dotsc, \\objfun(\\*x_k)$.\nGradient-based methods differ from gradient-free approaches\nin such a way that they also take values\nof the gradient $\\gradient{\\*x}{\\objfun}(\\*x_k)$,\nof the Hessian $\\hessian{\\*x}{\\objfun}(\\*x_k)$, or\nof even higher-order derivatives into account.\n\nA vast range of optimization methods exists in literature.\nSome methods are better suited for specific optimization problems\nthan others.\nHowever, according to the ``no-free-lunch theorem''\nand under some assumptions \\cite{Wolpert97No},\nall methods perform equally well (or equally badly) in the mean of all possible\noptimization problems.\n\n\\paragraph{Local and global optima}\n\nMost optimization methods depend on an initial point $\\*x_0$ and\nonly find local optima,\nwhere \\eqref{eq:unconstrainedOptimization} or\n\\eqref{eq:constrainedOptimization} only holds for $\\*x$\nin a neighborhood of $\\xopt$.\nOne can globalize local methods to increase the probability\nof finding a global optimum with a Monte Carlo multi-start approach:\nThe local method is repeated with different pseudo-random initial points\nand the best local optimum is chosen as the result.\n\nIn the following,\nwe give a brief survey of a small selection of optimization methods\n(see\n\\cref{tbl:optimizationMethod},\n\\cref{fig:optimizationMethodGradientFree}, and\n\\cref{fig:optimizationMethodGradientBased}),\nhighlighting the key ingredients for each method.\n\n\\begin{table}\n  \\setnumberoftableheaderrows{1}%\n  \\begin{tabular}{%\n    >{\\kern\\tabcolsep}=l+l<{\\kern5mm}*{5}{+c}<{\\kern\\tabcolsep}%\n  }\n    \\toprulec\n    \\headerrow\n    Method&                 Type&                    C&    D&  S&    I\\\\\n    \\midrulec\n    Nelder--Mead&           Simplex heuristic&       \\no&  0&  \\no&  \\yes\\\\\n    Differential evolution& Evolutionary&            \\no&  0&  \\yes& \\yes\\\\\n    CMA-ES&                 Evolutionary&            \\no&  0&  \\yes& \\yes\\\\\n    Simulated annealing&    Temperature heuristic&   \\no&  0&  \\yes& \\no\\\\\n    PSO&                    Swarm heuristic&         \\no&  0&  \\yes& \\no\\\\\n    GP-LCB&                 Bayesian&                \\no&  0&  \\yes& \\no\\\\\n    \\midrulec\n    Gradient descent&       Descent&                 \\no&  1&  \\no&  \\yes\\\\\n    NLCG&                   Descent&                 \\no&  1&  \\no&  \\yes\\\\\n    Newton&                 Newton&                  \\no&  2&  \\no&  \\yes\\\\\n    BFGS&                   Quasi-Newton&            \\no&  1&  \\no&  \\yes\\\\\n    Rprop&                  Heuristic&               \\no&  1&  \\no&  \\yes\\\\\n    Levenberg--Marquardt&   Least sq., trust-region& \\no&  1&  \\no&  \\yes\\\\\n    \\midrulec\n    Log-barrier&            Interior-point&          \\yes& 0+& --&   \\yes\\\\\n    Squared penalty&        Penalty&                 \\yes& 0+& --&   \\yes\\\\\n    Augmented Lagrangian&   Penalty&                 \\yes& 0+& --&   \\yes\\\\\n    SQP&                    Quadratic subproblems&   \\yes& 2&  --&   \\no\\\\\n    \\bottomrulec\n  \\end{tabular}\n  \\caption[Selection of optimization methods]{%\n    Selection of optimization methods.\n    The columns show\n    if constrained problems are supported (C),\n    the order of required derivatives (D),\n    if the algorithm is stochastic (S), and\n    if the algorithm has been implemented in \\sgpp (I).%\n  }%\n  \\label{tbl:optimizationMethod}%\n\\end{table}\n\n\n\n\\subsection{Gradient-Free Unconstrained Optimization Methods}\n\\label{sec:511gradientFree}\n\n\\newcommand*{\\optImage}[1]{%\n  \\raisebox{-0.5\\height}{\\includegraphics{optimizationMethod_#1}}%\n}\n\n\\begin{figure}\n  \\optImage{1}\\quad\\optImage{2}\\quad\\optImage{3}%\n  \\\\[3mm]%\n  \\optImage{4}\\qquad\\optImage{5}\\qquad\\optImage{6}%\n  \\caption[Ideas of various gradient-free optimization methods]{%\n    Sketch of the ideas of gradient-free optimization methods.%\n  }%\n  \\label{fig:optimizationMethodGradientFree}%\n\\end{figure}\n\n\\paragraph{Nelder--Mead}\n\nThe \\term{Nelder--Mead method}\n\\multicite{Nelder65Simplex,Gao12Implementing,Valentin14Hierarchische}\nmaintains a list of $d + 1$ vertices of a $d$-dimensional simplex,\nsorted by ascending function value.\nIn each iteration,\nthe method performs one of the operations\n\\term{reflection,}\n\\term{expansion,}\n\\term{outer contraction,}\n\\term{inner contraction,} and\n\\term{shrinking}\non the vertices.\nTypically, convergence can be detected by\nchecking the size of the simplex,\nas the simplex tends to contract around local minima.\nHowever, there are counterexamples where the method converges to\na non-critical point for an only bivariate objective function\nthat is strictly convex and twice continuously differentiable\n\\cite{McKinnon98Convergence}.\n%For higher dimensionalities, the method quickly suffers from\n%the curse of dimensionality \\cite{Gao12Implementing}.\n\n\\paragraph{Differential evolution}\n\nThe method of \\term{differential evolution}\n\\multicite{%\n  Storn97Differential,%\n  Zielinski09Optimizing,%\n  Valentin14Hierarchische%\n}\nis an evolutionary meta-heuristic algorithm.\nBeing similar to genetic algorithms,\nthe method maintains a \\term{population} of $m$ points\nthat is iteratively updated according to pseudo-random \\term{mutations,}\nwhich are weighted sums of the points of the previous generation.\nThe mutated vector is \\term{crossed over} with the original vector\nentry by entry.\nThe resulting \\term{offspring} are only accepted if they lead to\nan improvement in terms of objective function value.\n%There are various stopping criteria\n%that are based on the function value or on the location of the population\n%\\cite{Zielinski09Optimizing}.\n\n\\paragraph{CMA-ES}\n\n\\term{CMA-ES (covariance matrix adaption, evolution strategy)}\n\\cite{Hansen03Reducing}\nis an evolutionary algorithm that addresses the issue\nthat simple evolution strategies do not prefer a search direction\ndue to the lack of gradients \\cite{Toussaint15Introduction}.\nThe name of the algorithm stems from the fact\nthat it keeps track of the \\term{covariance matrix} of the\nGaussian search distribution.\nAfter $m$ points have been sampled from the current distribution,\nthe mean of the distribution for the next iteration\nis calculated as the weighted mean of the $k$ best samples and\nthe covariance matrix is adapted accordingly.\nAn advantage of the method is that if the population is large enough,\nlocal minima are smoothed out \\cite{Toussaint15Introduction}.\n\n\\paragraph{Simulated annealing}\n\n\\term{Simulated annealing}\n\\multicite{Laarhoven87Simulated,Press07Numerical,Kiranyaz14Multidimensional}\nimitates the cooling of a solid by randomly drawing samples\nfrom a proposal distribution and calculating an \\term{acceptance probability}\nthat depends on the function value improvement as well as\non a \\term{temperature} $T$.\nThis temperature is slowly decreased in the course of the algorithm.\nSimulated annealing is closely connected to the\nMetropolis--Hastings algorithm for drawing random samples of arbitrary\nprobability distributions.\nIf run long enough,\n%(e.g., if the decrease rate of the temperature is small enough),\nsimulated annealing is guaranteed to find the global\noptimum \\cite{Toussaint15Introduction}.\n\n\\paragraph{Particle swarm optimization (PSO)}\n\nThe method of \\term{particle swarm optimization (PSO)}\n\\multicite{Kennedy95Particle,Zielinski09Optimizing,Kiranyaz14Multidimensional}\ncan be seen as another evolutionary algorithm\nthat stems from swarm intelligence.\nFor each \\term{particle} of the population,\nnot only the \\term{position} $\\*x_k$ is stored,\nbut also the current \\term{velocity} $\\*v_k$,\nthe best known position in a neighborhood of $\\*x_k$\n(which may be the whole swarm), and\nthe best known position of the $k$-th particle.\nThe next velocity $\\*v_{k+1}$ is computed as\na pseudo-randomly weighted sum of $\\*v_k$,\nthe vector from $\\*x_k$ to the best neighborhood position, and\nthe vector from $\\*x_k$ to the best own position.\n\n\\paragraph{GP-LCB}\n\n\\term{GP-LCB (Gaussian process, lower confidence bound)}\n\\multicite{Srinivas10Gaussian,Toussaint15Introduction} is an example\nfor a \\term{Bayesian optimization} strategy.\nThe objective function is treated as a stochastic process.\nA \\term{prior distribution} is updated according to the previous function\nevaluations to calculate the \\term{posterior distribution.}\nThe posterior distribution is used to form the \\term{acquisition function,}\nwhich in turn determines the point at which the objective\nfunction is evaluated next.\nThe GP-LCB method is obtained by choosing\n\\term{Gaussian processes} for the family of stochastic processes and\n\\term{lower confidence bounds} (which are the difference of the mean\nand a multiple of the standard deviation) for the acquisition function.\n\n\n\n\\subsection{Gradient-Based Unconstrained Optimization Methods}\n\\label{sec:512gradientBasedUnconstrained}\n\n\\begin{figure}\n  \\optImage{7}\\qquad\\optImage{8}\\qquad\\optImage{9}%\n  \\\\[3mm]%\n  \\optImage{10}\\quad\\optImage{11}\\quad\\optImage{12}%\n  \\caption[Ideas of various gradient-based optimization methods]{%\n    Sketch of the ideas of gradient-based or constrained\n    optimization methods.%\n  }%\n  \\label{fig:optimizationMethodGradientBased}%\n\\end{figure}\n\nMost gradient-based optimization algorithms determine in\neach iteration $k$ a unit \\term{search direction} $\\*d_k \\in \\real^d$\n($\\norm[2]{\\*d_k} = 1$) to update the current iterate $\\*x_k$:\n\\begin{equation}\n  \\*x_k\n  \\to \\*x_{k+1}\n  \\ceq \\*x_k + \\delta_k \\*d_k,\\qquad\n  \\delta_k\n  \\ceq \\argmin_{\\delta \\in \\posreal} \\objfun(\\*x_k + \\delta \\*d_k),\n\\end{equation}\nwhere $\\delta_k \\in \\posreal$ is the \\term{step size.}\nThe algorithms essentially differ in the\nchoice of the search direction $\\*d_k$,\nwhich should be oriented like the negative gradient\n($\\innerprod[2]{\\*d_k}{\\gradient{\\*x}{\\objfun}(\\*x_k)} < 0$).\nThe step size $\\delta_k$ can then be determined independently of the\nalgorithm via \\term{line search,}\nfor instance, the \\term{Armijo line search algorithm}\n\\multicite{Nocedal99Numerical,Ulbrich12Nichtlineare,Valentin14Hierarchische},\nwhich uses a heuristic acceptance criterion\nto find $\\delta_k$ with a good enough improvement.\n\n\\paragraph{Gradient descent}\n\n\\term{Gradient descent}\n\\multicite{%\n  Ulbrich12Nichtlineare,%\n  Valentin14Hierarchische,%\n  Toussaint15Introduction%\n}\n%is the simplest gradient-based optimization method,\n%since it\nchooses $\\*d_k\n\\propto -\\gradient{\\*x}{\\!\\objfun}(\\*x_k)$ (i.e., normalized).\nThe method suffers from slow convergence,\nif the Hessian $\\hessian{\\*x}{\\objfun}$ is ill-conditioned:\nOne can show that for strictly convex quadratic functions,\nthe error $\\objfun(\\*x_k) - \\objfun(\\xopt)$\n%to the optimal function value\ncan decrease in each iteration only by the factor of\n$(\\tfrac{\\lambda^{\\max} - \\lambda^{\\min}}{\\lambda^{\\max} + \\lambda^{\\min}})^2$,\n%$(\\lambda^{\\max} - \\lambda^{\\min})^2/(\\lambda^{\\max} + \\lambda^{\\min})^2$,\nwhere $\\lambda^{\\min}$ and $\\lambda^{\\max}$ are the minimum and maximum\neigenvalue of $\\hessian{\\*x}{\\objfun}$, respectively\n\\cite{Ulbrich12Nichtlineare}.\nIf the condition number\n$\\tfrac{\\lambda^{\\max}}{\\lambda^{\\min}}$\n%$\\lambda^{\\max}/\\lambda^{\\min}$\nof $\\hessian{\\*x}{\\objfun}$ is large,\nthen this factor will be very close to one.\n\n\\paragraph{NLCG}\n\nA possible remedy for this issue is the method of\n\\term{non-linear conjugate gradients (NLCG)}\n\\multicite{%\n  Nocedal99Numerical,%\n  Valentin14Hierarchische,%\n  Toussaint15Introduction%\n}.\nIt is equivalent to the CG method for\nsolving symmetric positive definite %\\spd\nlinear systems $\\mat{A} \\*x = \\*b$,\nif we optimize the strictly convex quadratic function\n$\\objfun(\\*x) \\ceq \\frac{1}{2} \\tr{\\*x} \\mat{A} \\*x - \\tr{\\*b} \\*x$\n\\multicite{Reinhardt13Nichtlineare,Valentin14Hierarchische}, i.e.,\nit finds the optimum after only $d$ steps for strictly convex\nquadratic functions.\nThe NLCG method quickly converges even for non-convex objective functions,\nas due to the Taylor theorem,\nthree times continuously differentiable functions\nwith positive definite Hessian are ``similar'' to a\nstrictly convex quadratic function in a neighborhood of $\\xopt$\n\\cite{Valentin14Hierarchische}.\n\n\\paragraph{Newton}\n\nThe \\term{Newton method}\n\\multicite{%\n  Ulbrich12Nichtlineare,%\n  Valentin14Hierarchische,%\n  Toussaint15Introduction%\n}\nreplaces the objective function with the second-order Taylor approximation\ngiven by\n$\\objfun(\\*x_k + \\*d_k)\n\\!\\approx\\! \\objfun(\\*x_k) +\n\\tr{(\\gradient{\\*x}{\\objfun}(\\*x_k))} \\*d_k \\,+\n\\frac{1}{2} \\tr{(\\*d_k)} (\\hessian{\\*x}{\\objfun}(\\*x_k)) \\*d_k$\nand determines the search direction such that $\\*x_k + \\*d_k$ is\nthe minimum of the approximation, i.e.,\n$\\*d_k \\propto\n-(\\hessian{\\*x}{\\objfun}(\\*x_k))^{-1} \\gradient{\\*x}{\\objfun}(\\*x_k)$.\nDespite converging for strictly convex quadratic functions in a single step,\nthe Hessian must not be ill-conditioned for the Newton method as well,\nas we have to solve a linear system with the matrix\n$\\hessian{\\*x}{\\objfun}(\\*x_k)$.\nHence, often a \\term{regularization/damping term} $\\lambda \\eye$\nfor some $\\lambda > 0$ is added to the Hessian.\n\n\\paragraph{BFGS}\n\nThe Newton method has the disadvantage that it needs to evaluate the\nHessian $\\hessian{\\*x}{\\objfun}$,\nwhich may be unavailable or too expensive.\n\\term{Quasi-Newton methods} such as the method of\n\\term{BFGS (Broyden, Fletcher, Goldfarb, Shanno)}\n\\multicite{%\n  Nocedal99Numerical,%\n  Ulbrich12Nichtlineare,%\n  Toussaint15Introduction%\n}\napproximate the Hessian by a solution of the secant equation\n$\\hessian{\\*x}{\\objfun}(\\*x_k) (\\*x_k - \\*x_{k-1}) \\approx\n\\gradient{\\*x}{\\objfun}(\\*x_k) - \\gradient{\\*x}{\\objfun}(\\*x_{k-1})$.\nAs the solution is not unique for $d > 1$,\nQuasi-Newton methods differ in which solution to choose.\nThe BFGS method performs a simple rank-one update.\n\n\\paragraph{Rprop}\n\n\\term{Rprop (resilient propagation)}\n\\multicite{Riedmiller93Direct,Toussaint15Introduction}\nconsiders the gradient entries $(\\gradient{\\*x}{\\objfun}(\\*x_k))_t$\nof each dimension $t = 1, \\dotsc, d$ separately\nand updates the entries $x_{k,t}$ of $\\*x_k$\naccording to the sign of the respective gradient entry,\nwhile adapting the step size dimension-wise.\nAlthough the algorithm is independent of the exact direction\nof $\\gradient{\\*x}{\\objfun}(\\*x_k)$,\nit was found to often work robustly in machine learning scenarios\n\\cite{Toussaint15Introduction}.\n\n\\paragraph{Levenberg--Marquardt}\n\nThe \\term{Levenberg--Marquardt method}\n\\multicite{Nocedal99Numerical,Freund07Stoer,Toussaint15Introduction}\ncan only solve \\term{non-linear least-squares problems,} i.e.,\nthe objective function must be of the form\n$\n  \\objfun(\\*x)\n  = \\norm[2]{\\*\\phi(\\*x)}^2\n  = \\sum_{i=1}^{m_{\\*\\phi}} \\abs{\\phi_i(\\*x)}^2\n$\nfor some function $\\*\\phi\\colon \\real^d \\to \\real^{m_{\\*\\phi}}$.\nIt is an improvement over the \\term{Gauss--Newton method}\n(which is in turn a slight modification of the Newton method)\nand can be obtained by replacing the line search in the\nGauss--Newton method with a \\term{trust-region approach.}\n\n\n\n\\subsection{Constrained Optimization Methods}\n\\label{sec:513gradientBasedConstrained}\n\nMethods for constrained optimization usually\nsolve a series of unconstrained \\term{auxiliary problems} with an arbitrary\nunconstrained optimization method.\nThe auxiliary function to be minimized is\nthe sum of the objective function and \\term{penalty terms,}\nwhich penalize if the current point $\\*x_k$ is near the boundary\nof the feasible domain or even outside.\nThe penalty terms slowly increase to enforce\nthe feasibility of the final result.\nConstrained optimization methods can roughly be divided\ninto \\term{interior-point or barrier methods,}\nwhere $\\*x_k$ always stays in the feasible domain,\nand \\term{penalty methods,}\nwhere intermediate solutions $\\*x_k$ may be infeasible,\nin which case the penalty term is applied.\n%(the penalty vanishes inside the domain).\n\nAt least for the interior-point methods,\na feasible initial solution $\\*x_0$ is required.\nWe can find an initial solution by solving another auxiliary problem\n\\cite{Toussaint15Introduction}, for instance\n\\begin{equation}\n  \\min_{(\\*x, s) \\in \\real^{d+1}} s\n  \\quad\\text{s.t.}\\quad\n  s \\ge 0,\\;\\;\n  \\ineqconfun(\\*x) \\le s \\cdot \\*1_{m_{\\ineqconfun}},\n\\end{equation}\nwhere $\\*1_{m_{\\ineqconfun}} \\in \\real^{m_{\\ineqconfun}}$\nis the all-one vector.\nAn initial solution for this problem can be explicitly given\n(for example, $\\*x_0 = \\*0$ and\n$s_0 = \\max(\\max(\\ineqconfun(\\*x_0)), 0)$).\n\n\\paragraph{Log-barrier}\n\nThe \\term{log-barrier method}\n\\multicite{Boyd04Convex,Reinhardt13Nichtlineare,Toussaint15Introduction}\nis an interior-point method that adds\na logarithmic \\term{barrier function term} to the objective function\nnear the boundary.\nThe method solves\n$\\min\\, [\\objfun(\\*x) - \\mu_k \\sum_{i=1}^{m_{\\ineqconfun}} \\log(-g_i(\\*x))]$\nfor some decreasing $\\mu_k \\in \\posreal$.\n\n\\paragraph{Squared penalty}\n\nThe \\term{squared penalty method}\n\\multicite{%\n  Polak71Computational,%\n  Ulbrich12Nichtlineare,%\n  Toussaint15Introduction%\n}\nreplaces the constrained problem with the penalized problem\n$\\min\\, [\\objfun(\\*x) + \\mu_k \\norm[2]{\\nonnegpart{\\ineqconfun(\\*x)}}^2]$,\nwhere $\\mu_k \\in \\posreal$ is a penalty parameter and\n$\\nonnegpart{\\cdot} \\ceq \\vecmax(\\cdot, \\*0)$ denotes the non-negative part.\nWith increasing $\\mu_k$, the constraint violation of the solution of\nthe penalized problem decreases, although it may happen\nthat it never vanishes.\n\n\\paragraph{Augmented Lagrangian}\n\nThe method of the \\term{augmented Lagrangian}\n\\multicite{Reinhardt13Nichtlineare,Toussaint15Introduction}\nconsiders the auxiliary problem\n\\begin{equation}\n  \\min_{\\*x \\in \\real^d} \\bracket*{\n    \\objfun(\\*x) + \\mu_k \\sum_{i=1}^{m_{\\ineqconfun}} [\\lambda_{k,i} > 0]\n    ((\\ineqconfun[i](\\*x))_{+})^2 + \\tr{\\*\\lambda_k} \\ineqconfun(\\*x)\n  },\n\\end{equation}\nwhere $[\\lambda_{k,i} > 0] \\in \\{0, 1\\}$ is defined as one\nif and only if $\\lambda_{k,i} > 0$, and\n$\\*\\lambda_k \\in \\nonnegreal^{m_{\\ineqconfun}}$ is an estimate of the\n\\term{Lagrangian multipliers.}\nThey are updated according to the penalty of the previous iteration,\ngenerating a ``virtual gradient'' that drastically decreases\nthe necessary magnitude of the penalty parameter $\\mu_k$\nto achieve feasibility of the solution \\cite{Toussaint15Introduction}.\n\n\\paragraph{Sequential quadratic programming (SQP)}\n\n\\term{Sequential quadratic programming (SQP) methods}\n\\multicite{%\n  Ulbrich12Nichtlineare,%\n  Reinhardt13Nichtlineare,%\n  Toussaint15Introduction%\n}\nare one of the most powerful method classes for constrained optimization.\nThey are motivated by the \\term{Karush--Kuhn--Tucker (KKT) conditions,}\nwhich are necessary to hold in any optimal point\n(similarly to critical points in unconstrained optimization).\nThe Newton method can be employed to solve the KKT conditions when\nwritten as a non-linear system of equations.\nThe linear system of the resulting \\emph{Newton--Lagrange method}\nis equivalent to the KKT conditions of a\n\\term{quadratic programming (QP) problem,}\nfor which objective and constraint functions have the\nform $\\objfun(\\*x) = \\frac{1}{2} \\tr{\\*x} \\mat{Q} \\*x + \\tr{\\*d} \\*x$ and\n$\\ineqconfun(\\*x) = \\mat{A} \\*x - \\*b$, respectively.\n%SQP methods solve one QP problem in each iteration (``sequentially'')\n%to determine the search direction.\n", "meta": {"hexsha": "90fb0a171c9188105ba67ba47d1d43764e1d3169", "size": 21182, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/51algorithms.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/51algorithms.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/51algorithms.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": 39.6666666667, "max_line_length": 81, "alphanum_fraction": 0.734680389, "num_tokens": 6119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6143266920086478}}
{"text": "\\section{Projects}\n\\textbf{SimpleNavierStokes.jl} (2020) \\\\\n{A \\link{https://github.com/Emadmasroor/SimpleNavierStokes.jl}{Julia package}, \\link{https://emadmasroor.github.io/blog/2020/12/16/CFD-tutorial-in-julia/}{blog post}, and open-source \\link{https://nextjournal.com/emadmasroor/CFD-tutorial-in-Julia}{notebook} to serve as a beginner's tutorial for writing incompressible Navier-Stokes solvers using the $\\omega-\\psi$ formulation.}\n", "meta": {"hexsha": "834384da11843d8fb5a02899c711bfd5a2b502b8", "size": 439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/projects.tex", "max_stars_repo_name": "Emadmasroor/Simple-CV", "max_stars_repo_head_hexsha": "cd687dd5d96f7d5148cf3968b10ab73f36b3e5a5", "max_stars_repo_licenses": ["MIT"], "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/projects.tex", "max_issues_repo_name": "Emadmasroor/Simple-CV", "max_issues_repo_head_hexsha": "cd687dd5d96f7d5148cf3968b10ab73f36b3e5a5", "max_issues_repo_licenses": ["MIT"], "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/projects.tex", "max_forks_repo_name": "Emadmasroor/Simple-CV", "max_forks_repo_head_hexsha": "cd687dd5d96f7d5148cf3968b10ab73f36b3e5a5", "max_forks_repo_licenses": ["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.75, "max_line_length": 378, "alphanum_fraction": 0.7813211845, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6143266909912938}}
{"text": "\\chapter{Word Factoring}\n\\label{chap:factoring}\n\\index{exact string matching|see{word fac\\-toring}}\n\\index{string matching|see{word factoring}}\n\\index{word factoring|(}\n\nLet us call \\emph{alphabet}\\index{word factoring!alphabet} a\nnon\\hyp{}empty, finite set of symbols, called\n\\emph{letters}\\index{word factoring!letter} and set in a\nsans\\hyp{}serif type, for example \\word{a}, \\word{b} etc. A\n\\emph{word}\\index{word factoring!word} is a finite series of letters,\nlike \\word{word}; in particular, a letter is a word, as in English. We\ndenote repetition of a letter or word with an exponent, for instance,\n\\(\\word{a}^3 = \\word{aaa}\\). Just as letters can be joined to make up\nwords, so can words: the word \\(u \\cdot v\\) is made of the letters of\nword~\\(u\\) followed by the letters of word~\\(v\\), for instance, if\n\\(u=\\word{back}\\) and \\(v=\\word{up}\\), then \\(u \\cdot v =\n\\word{backup}\\). This operation is associative: \\((u \\cdot v) \\cdot w\n= u \\cdot (v \\cdot w)\\). As a shorthand, the operator may be omitted:\n\\((uv)w = u(vw)\\). Catenation on words behave like a\nnon\\hyp{}commutative product, so it has a neutral element\n\\(\\varepsilon\\), called the \\emph{empty word}: \\(u \\cdot \\varepsilon =\n\\varepsilon \\cdot u = u\\).\n\nA word~\\(x\\) is a \\emph{factor}\\index{word factoring!factor} of a\nword~\\(y\\) if there exists two words \\(u\\)~and~\\(v\\) such that \\(y =\nuxv\\). The word~\\(x\\) is a \\emph{prefix}\\index{word factoring!prefix}\nof~\\(y\\), noted \\(x \\prefeq y\\), if~\\(u=\\varepsilon\\), that is, if \\(y\n= xv\\). Moreover, it is a \\emph{proper prefix}, noted \\(x \\pref y\\),\nif \\(v \\neq \\varepsilon\\). Given \\(y = uxv\\), the word~\\(x\\) is a\n\\emph{suffix}\\index{word factoring!suffix} of~\\(y\\) if \\(v =\n\\varepsilon\\). Furthermore, it is a \\emph{proper suffix} if \\(u \\neq\n\\varepsilon\\). Let \\(a\\)~be any letter and \\(x\\), \\(y\\)~any word, then\nthe prefix relation is easy to define by an inference system as\n\\begin{mathpar}\n\\inferrule*{}{\\varepsilon \\prefeq y}\n\\qquad\n\\inferrule{x \\prefeq y}{a \\cdot x \\prefeq a \\cdot y}\n\\end{mathpar}\n\nThe purpose being to write a functional program for factoring, we need\nto translate words and operations on them into terms of the\nlanguage. A letter is translated into a constant data constructor; for\nexample, \\word{a} becomes \\(\\fun{a}()\\). A word of more than one\nletter is mapped to a stack of mapped letters, such as \\word{hi} in\n\\([\\fun{h}(),\\fun{i}()]\\). The catenation of a letter and a word is\ntranslated as a push, like \\(\\word{a} \\cdot \\word{bed}\\) becomes\n\\([\\fun{a}(),\\fun{b}(),\\fun{e}(),\\fun{d}()]\\). The catenation of two\nwords is associated to stack catenation, so \\(\\word{ab} \\cdot\n\\word{cd}\\) leads to\\index{cat@\\fun{cat/2}}\n\\(\\fun{cat}([\\fun{a}(),\\fun{b}()],[\\fun{c}(),\\fun{d}()])\\).\n\n% The transposition of a word is the reversal of the stack implementing\n% the word.\n\nAs usual, the translation of the inference system defining\n\\((\\prefeqName)\\) into a function \\fun{pre/2}\\index{pre@\\fun{pre/2}}\nrequires that the cases corresponding to the axioms evaluate in\n\\(\\fun{true}()\\) and the cases left unspecified \\((\\nprefeqName)\\)\nevaluate in \\(\\fun{false}()\\):\n\\begin{equation*}\n\\fun{pre}(\\el,y) \\rightarrow \\fun{true}();\\quad\n\\fun{pre}(\\cons{a}{x},\\cons{a}{y}) \\rightarrow \\fun{pre}(x,y);\\quad\n\\fun{pre}(x,y) \\rightarrow \\fun{false}().\n\\end{equation*}\nThe inference system is now a formal specification for the program.\n\nA letter in a word can be uniquely characterised by a natural number,\ncalled \\emph{index}\\index{word factoring!index}, assuming that the\nfirst letter has index~\\(0\\) \\citep{Dijkstra_1982}. If\n\\(x=\\word{top}\\), then the letter at index~\\(0\\) is written\n\\(\\ind{x}{0}=\\word{t}\\) and the one at index~\\(2\\) is\n\\(\\ind{x}{2}=\\word{p}\\). A factor~\\(x\\) of~\\(y\\) can be identified by\nthe index of~\\(\\ind{x}{0}\\) in~\\(y\\). The end of the factor can also\nbe given; for example, \\(x=\\word{sit}\\) is a factor of\n\\(y=\\word{curiousity}\\) at index~\\(6\\), written \\(\\ind{y}{6,8} = x\\),\nmeaning \\(\\ind{y}{6} = \\ind{x}{0}\\), \\(\\ind{y}{7} = \\ind{x}{1}\\) and\n\\(\\ind{y}{8} = \\ind{x}{2}\\). Given two words \\(p\\)~and~\\(t\\),\ndetermining whether \\(p\\)~is a factor of~\\(t\\) is called\n\\emph{factoring~\\(p\\) in~\\(t\\)}.\n\nFactor matching is common in text editing, although it is usually\nbetter known as \\emph{exact string matching} in the academic field of\n\\emph{stringology} or \\emph{text\n  algorithmics} \\citep{CharrasLecroq_2004,CrochemoreHancartLecroq_2007}\n\\citep[\\S{}32]{CLRS_2009}. Because of the asymmetric nature of\nfactoring, the word~\\(p\\) is called the \\emph{pattern}\\index{word\n  factoring!pattern} and the word~\\(t\\) is the \\emph{text}\\index{word\n  factoring!text}.\n\n\\section{Na\\\"{\\i}ve factoring}\n\\label{sec:naive_factoring}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$|(}\n\nIn section~\\ref{def:linear_search}, \\vpageref{def:linear_search}, we\nintroduced the linear search\\index{linear search}, that is, the\nstepwise search for the occurrence of an item in a stack. We can\ngeneralise it to search for a series of items occurring consecutively\nin a stack, that is, to solve the factoring problem. This approach is\nqualified as being na\\\"{\\i}ve because it is a simple extension of a\nsimple idea and it is implied that it is not the most efficient.\n\nEverything starts with~\\(\\ind{p}{0}\\) and~\\(\\ind{t}{0}\\) being\ncompared, then, assuming \\(\\ind{p}{0} = \\ind{t}{0}\\), letters\n\\(\\ind{p}{1}\\) and~\\(\\ind{t}{1}\\) are, in turn, compared etc. until\none of the words is exhausted or a mismatch occurs. Assuming that\n\\(p\\)~is shorter than~\\(t\\), the former case means that \\(p\\)~is a\nprefix of~\\(t\\). In the latter case, \\(p\\)~is shifted so\n\\(\\ind{p}{0}\\) is aligned with \\(\\ind{t}{1}\\) and the comparisons are\nresumed from there. If \\(p\\)~cannot be shifted anymore because its end\nwould surpass the end of~\\(t\\), then it is not a factor. The essence\nof this procedure is summed up in \\fig~\\vref{fig:naive},\n\\begin{figure}[t]\n\\centering\n\\includegraphics[bb=75 621 352 715]{naive}\n\\caption{Na\\\"{\\i}vely matching pattern~\\(p\\) against text~\\(t\\)\n(failure in grey)\\label{fig:naive}}\n\\end{figure}\nwhere \\(\\ind{p}{i} \\neq \\ind{t}{j}\\) (the letters\n\\word{a}~and~\\word{b} are not relevant in themselves).\n\n% Wrapping figure better declared before a paragraph\n%\n%\\begin{wrapfigure}[15]{r}[0pt]{0pt}\n% [15] vertical lines\n% {r} right placement\n% [0pt] of margin overhang\n%\\end{wrapfigure}\n\n\\Fig~\\vref{fig:loc0}\n\\begin{figure}[t]\n\\centering \n\\includegraphics[bb=71 548 253 721]{loc0}\n\\caption{Na\\\"{\\i}ve factoring with \\fun{loc\\(_0\\)/2}\n\\label{fig:loc0}}\n\\end{figure}\nshows an abstract program implementing this scheme. The call\n\\(\\fun{loc}_0(p,t)\\)\\index{loc0@\\fun{loc\\(_0\\)/2}} evaluates in\n\\(\\fun{absent}()\\) if the pattern~\\(p\\) is not a factor of the\ntext~\\(t\\), otherwise in \\(\\fun{factor}(k)\\), where \\(k\\)~is the index\nin~\\(t\\) where~\\(p\\) occurs first. Conceptually, this design consists\nin combining a linear search for the first letter of the pattern and a\nprefix check for the rest of the pattern and text. It is important to\nverify whether the invariants implicit in general do not break in the\npresence of limit cases. For instance, in stack processing, set the\ndifferent stacks to be empty and interpret the result of single\nrewrites and entire evaluations. We have \\(\\fun{pre}(\\el,t)\n\\twoheadrightarrow \\fun{true}()\\), because \\(t = \\varepsilon \\cdot\nt\\). Accordingly, \\(\\fun{loc}_0(\\el,t) \\twoheadrightarrow\n\\fun{factor}(0)\\).\n\n\\paragraph{Refinements}\n\nWhile this program composition is intuitive, it is too long. We may\nremark that, after a call to \\fun{pre/2}\\index{pre@\\fun{pre/2}}\nevaluates in \\(\\fun{true}()\\), the interpretation ends with\n\\(\\fun{factor}(j)\\). Dually, a value \\(\\fun{false}()\\) is followed by\nthe call\n\\(\\fun{loc}_0(p,t,j+1)\\)\\index{loc0@\\fun{loc\\(_0\\)/3}}. Therefore,\ninstead of calling \\fun{pre/2} and then inspecting the resulting value\nto decide what to do next, we could have \\fun{pre/2} take the\nlead. This entails that it needs to receive additional arguments to be\nable to end with \\(\\fun{factor}(j)\\) or resume with\n\\(\\fun{loc}_0(p,t,j+1)\\), as expected. The corresponding code is shown\nin \\fig~\\ref{fig:loc1}.\n\\begin{figure}[t]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{loc}_1(p,t)   & \\rightarrow & \\fun{loc}_1(p,t,0).\\\\\n\\\\\n\\fun{loc}_1(\\cons{a}{p},\\el,j) & \\rightarrow & \\fun{absent}();\\\\\n\\fun{loc}_1(p,t,j) & \\rightarrow & \\fun{pre}_1(p,t,p,t,j).\\\\\n\\\\\n\\fun{pre}_1(\\el,t,p',t',j) & \\rightarrow & \\fun{factor}(j);\\\\\n\\fun{pre}_1(\\cons{a}{p},\\cons{a}{t},p',t',j)\n                   & \\rightarrow & \\fun{pre}_1(p,t,p',t',j);\\\\\n\\fun{pre}_1(p,t,p',\\cons{a}{t'},j) & \\rightarrow & \\fun{loc}_1(p',t',j+1).\n\\end{array}}\n\\end{equation*}\n\\caption{Refinement of \\fig~\\vref{fig:loc0}\n\\label{fig:loc1}}\n\\end{figure}\n\nFurther examination reveals that we can merge\n\\fun{loc\\(_1\\)/3}\\index{loc1@\\fun{loc\\(_1\\)/3}} and\n\\fun{pre\\(_1\\)/5}\\index{pre1@\\fun{pre\\(_1\\)/5}} into\n\\fun{pre/5}\\index{pre@\\fun{pre/5}} in\\index{word factoring!na\\\"{\\i}ve\n  $\\sim$!program} \\fig~\\vref{fig:loc}. This kind of progressive\ndesign, where a program is transformed into a guided series of\nequivalent programs is called a \\emph{refinement}. Here, each\nrefinement is more efficient than the preceding, but less legible than\nthe original, so each step must be cautiously checked.\n\\begin{figure}[h]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{loc}(p,t)   & \\xrightarrow{\\smash{\\pi}} & \\fun{pre}(p,t,p,t,0).\\\\\n\\\\\n\\fun{pre}(\\el,t,p',t',j) & \\xrightarrow{\\smash{\\rho}}\n                         & \\fun{factor}(j);\\\\\n\\fun{pre}(p,\\el,p',t',j) & \\xrightarrow{\\smash{\\sigma}}\n                         & \\fun{absent}();\\\\\n\\fun{pre}(\\cons{a}{p},\\cons{a}{t},p',t',j)\n                         & \\xrightarrow{\\smash{\\tau}}\n                         & \\fun{pre}(p,t,p',t',j);\\\\\n\\fun{pre}(p,t,p',\\cons{b}{t'},j) & \\xrightarrow{\\smash{\\upsilon}}\n                         & \\fun{pre}(p',t',p',t',j+1).\n\\end{array}}\n\\end{equation*}\n\\caption{Refinement of \\fig~\\vref{fig:loc1}\n\\label{fig:loc}}\n\\end{figure}\n\n\\paragraph{Termination}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!termination|(}\n\nWe want to show that the index in the text always increases, whether a\ncomparison fails or not, so we choose a lexicographic order on the\ndependency pairs of \\fun{pre/5}\\index{termination!dependency pair}\nmade of the fourth and second arguments (definition~\\eqref{def:lexico}\n\\vpageref{def:lexico}), where \\(s \\succ t\\) if~\\(t\\) is the immediate\nsubstack of~\\(s\\). The third rule satisfies \\((t',\\cons{a}{t}) \\succ\n(t',t)\\). The fourth rule is also ordered, because \\((\\cons{b}{t'},t)\n\\succ (t',t')\\).\\index{word factoring!na\\\"{\\i}ve\n  $\\sim$!termination|)}\\hfill\\(\\Box\\)\n\n\\paragraph{Completeness}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!completeness|(}\n\\index{induction!example|(}\n\nNote how, in rule~\\(\\sigma\\), the pattern~\\(p\\) can not be empty\nbecause the rules are ordered and that case would always match\nrule~\\(\\rho\\). The completeness of the definition of \\fun{pre/5}\ndeserves some attention and we need to justify why the call\n\\(\\fun{pre}(\\cons{a}{p},\\cons{b}{t},p',\\el,j)\\), with \\(a \\neq b\\),\ncannot happen. Perhaps surprisingly, a more general statement is\neasier to establish:\n\\begin{center}\n\\(\\fun{loc}(p,t) \\twoheadrightarrow \\fun{pre}(p_0,t_0,p_0',t_0',j)\\)\n\\textsl{implies} \\(t_0' \\succcurlyeq t_0\\),\n\\end{center}\nwhere (\\(\\succcurlyeq\\)) is the reflexive substack relation. Let us\nprove this property by \\emph{induction on the length of the\n  derivation}\\index{induction!$\\sim$ on the length of the\n  derivation}. More precisely, we want to establish the proposition\n\\begin{equation*}\n\\pred{Comp}{n} \\colon \\fun{loc}(p,t) \\xrightarrow{\\smash{n}}\n\\fun{pre}(p_0,t_0,p_0',t_0',j) \\Rightarrow t_0' \\succcurlyeq t_0.\n\\index{Comp@\\predName{Comp}}\n\\end{equation*}\n\\begin{itemize}\n\n  \\item The basis \\(\\pred{Comp}{0}\\) is easy to prove without\n    induction by means of rule~\\(\\pi\\): \\(\\fun{loc}(p,t)\n    \\xrightarrow{\\smash{\\pi}} \\fun{pre}(p,t,p,t,0)\\) and \\(t\n    \\succcurlyeq t\\) trivially holds.\n\n    \\item The induction hypothesis is \\(\\pred{Comp}{n}\\) and we want\n      to show that, under this assumption, \\(\\pred{Comp}{n+1}\\) holds\n      as well. In other words, let us suppose that \\(\\fun{loc}(p,t)\n      \\xrightarrow{\\smash{n}} \\fun{pre}(p_0,t_0,p_0',t_0',j)\\) implies\n      \\(t_0' \\succcurlyeq t_0\\) and we want to prove that\n      \\(\\fun{pre}(p_0,t_0,p_0',t_0',j) \\rightarrow\n      \\fun{pre}(p_1,t_1,p_1',t_1',k)\\) implies \\(t_1' \\succcurlyeq\n      t_1\\). This rewrite can only be by means of~\\(\\tau\\)\n      or~\\(\\upsilon\\). \n      \\begin{itemize}\n\n      \\item If~\\(\\tau\\), the induction hypothesis on the\n        left\\hyp{}hand side entails \\(t' \\succcurlyeq \\cons{a}{t}\\),\n        so \\(t' \\succcurlyeq t\\) in the right\\hyp{}hand side;\n\n      \\item otherwise, the right\\hyp{}hand side of~\\(\\upsilon\\)\n        trivially satisfies \\(t' \\succcurlyeq t'\\).\n\n      \\end{itemize}\n\\end{itemize}\nIn summary, \\(\\pred{Comp}{0}\\) is true and \\(\\pred{Comp}{n}\n\\Rightarrow \\pred{Comp}{n+1}\\). Therefore, the induction principle\nyields \\(\\forall n.\\pred{Comp}{n}\\), which, in turn, entails our\nformulation with~(\\(\\twoheadrightarrow\\)). Note how, in this case,\nthis proof technique reduces to mathematical induction\non~\\(n\\).\\hfill\\(\\Box\\)\n\\index{induction!example|)}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!completeness|)}\n\n\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Cost}\n\nIn the following cost analysis, let~\\(m\\) be the length of the\npattern~\\(p\\) and \\(n\\)~be the length of the text~\\(t\\). Moreover, as\nit is common with search algorithms, we discriminate on \\(p\\)~being a\nfactor of~\\(t\\) or not.\n\n\\paragraph{Minimum cost}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!minimum cost}\n\nIf \\(m \\leqslant n\\), the best case happens when the pattern is a\nprefix of the text, so the evaluation trace is \\(\\pi\\tau^m\\rho\\) and\n\\(\\B{\\fun{loc}}{m,n} = m + 2\\). If \\(m > n \\), the minimum cost is\n\\(\\B{\\fun{loc}}{m,n} = \\len{\\pi\\tau^n\\sigma} = n + 2\\). We can gather\nthese two cases in one formula:\n\\begin{equation*}\n\\B{\\fun{loc}}{m,n} = \\min\\{m,n\\} + 2.\\index{loc@$\\B{\\fun{loc}}{m,n}$}\n\\end{equation*}\n\n\\paragraph{Maximum cost}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!maximum cost|(}\n\nTo find the maximum cost, let us investigate the cases where the\npattern is a factor of the text and when it is not.\n\\begin{itemize}\n\n  \\item \\emph{The text contains the pattern.} The discovery of the\n    pattern must be delayed as much as possible, therefore the worst\n    case is when \\(w\\)~is a suffix of~\\(t\\) and every mismatch\n    involves the last letter of the pattern. An example is \\(p =\n    \\word{a}^{m-1}\\word{b}\\) and \\(t = \\word{a}^{n-1}\\word{b}\\). The\n    evaluation trace corresponding to this case is \\(\\pi\n    (\\tau^{m-1}\\upsilon)^{n-m} \\tau^m\\rho\\), whose length is\n    \\(mn-m^2+m+2\\).\n\n  \\item \\emph{The text does not contain the pattern.} The pattern is\n    not the prefix of any suffix of the text. The most delayed\n    comparison failure should occur at the last letter of the pattern,\n    like \\(p = \\word{a}^{m-1}\\word{b}\\) and \\(t = \\word{a}^{n}\\). The\n    cost is \\(\\len{\\pi(\\tau^{m-1}\\upsilon)^{n-m+1}\\tau^{m-1}\\sigma} =\n    mn - m^2 + 2m + 1\\).\n\n\\end{itemize}\nTherefore, the maximum cost is \\(\\W{\\fun{loc}}{m,n} = mn - m^2 + 2m +\n1\\) \\index{loc@$\\W{\\fun{loc}}{m,n}$}, when the pattern is not a factor\nof the text and \\(m \\geqslant 1\\). The previous analysis suggests an\nimprovement for that case, but would make the case when the text\ncontains the pattern the worst: just after rule~\\(\\tau\\), let us add\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!maximum cost|)}\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\fun{pre}([a],[b],p',t',j) \\rightarrow \\fun{absent}();\\index{pre@\\fun{pre/5}}\n\\end{equation*}\n\n\\paragraph{Average cost}\n\\index{word factoring!na\\\"{\\i}ve $\\sim$!average cost|(}\n\nLet us suppose that \\(0 < m \\leqslant n\\) and that the letters of\n\\(p\\)~and~\\(t\\) are chosen from the same alphabet, whose cardinal\nis~\\(\\breve{a} > 1\\). Na\\\"{\\i}ve factoring consists in matching a\npattern against the prefixes of the suffixes of a text, by decreasing\nlengths. Let~\\(\\OM{\\breve{a}}{m}\\) \\index{loc@$\\OM{\\breve{a}}{n}$} be\nthe average number of letter comparisons for comparing two words of\nlength~\\(m\\) over the alphabet~\\(\\breve{a}\\). The average number\n\\(\\OM{\\fun{loc}}{m,n}\\) of comparisons for na\\\"{\\i}ve factoring is\n\\begin{equation}\n\\OM{\\fun{loc}}{m,n} = (n-m+1)\\OM{\\breve{a}}{m} + \\OM{\\breve{a}}{m-1},\n\\label{eq:loc}\n\\end{equation}\nbecause there are \\(n-m+1\\) suffixes of length at least~\\(m\\) and\n\\(1\\)~suffix of length~\\(m-1\\), against which the pattern is matched.\n\nThe determination of \\(\\OM{\\breve{a}}{m}\\) is achieved by fixing the\npattern~\\(p\\) and letting the text~\\(t\\) vary over all possible\nletters. There are \\(\\breve{a}^{m}\\)~comparisons between\n\\(\\ind{p}{0}\\) and~\\(\\ind{t}{0}\\), as much as there are different\ntexts; if \\(\\ind{p}{0}=\\ind{t}{0}\\), there are\n\\(\\breve{a}^{m-1}\\)~comparisons between \\(\\ind{p}{1}\\)\nand~\\(\\ind{t}{1}\\), as much as there are different \\(\\ind{t}{1,m-1}\\)\netc. In total, there are\n\\begin{equation*}\n\\breve{a}^{m} + \\breve{a}^{m-1} + \\dots +\n\\breve{a} = \\breve{a}(\\breve{a}^{m} - 1)/(\\breve{a}-1)\n\\end{equation*}\ncomparisons. There are \\(\\breve{a}^m\\)~possible texts, hence the\naverage is\n\\begin{equation*}\n\\OM{\\breve{a}}{m}\n = \\frac{\\breve{a}(\\breve{a}^{m}-1)}{\\breve{a}^m(\\breve{a}-1)}\n = \\frac{\\breve{a}}{\\breve{a}-1}\\left(1\n                          - \\frac{1}{\\breve{a}^{m}}\\right)\n < \\frac{\\breve{a}}{\\breve{a}-1}\n \\leqslant 2.\n\\end{equation*}\nSince \\(\\OM{\\breve{a}}{1} = 1\\), we draw the following bounds from\nequation~\\eqref{eq:loc}:\n\\begin{equation*}\nn - m + 2 \\leqslant \\OM{\\fun{loc}}{m,n} < 2(n-m+2) \\leqslant 2n + 4.\n\\end{equation*}\nNa\\\"{\\i}ve factoring is thus efficient in average, but its hypothesis\nis unlikely to apply to random English texts. Moreover, notice how the\naverage cost gets down as the alphabet grows since \\(\\lim_{\\breve{a}\n  \\to \\infty}\\OM{\\breve{a}}{m} = 1\\).\\index{word\n  factoring!na\\\"{\\i}ve $\\sim$!average cost|)} \\index{word\n  factoring!na\\\"{\\i}ve $\\sim$|)}\n\n\n\\section{Morris-Pratt algorithm}\n\\index{word factoring!Morris-Pratt|(}\n\nIn case of mismatch, the na\\\"{\\i}ve algorithm resumes comparing the\nfirst letters of~\\(p\\) without using the information of the partial\nsuccess, to wit, we know \\(\\ind{p}{0,i-1} = \\ind{t}{j-i,j-1}\\) and\n\\(\\ind{p}{i} \\neq \\ind{t}{j}\\) (see \\fig~\\vref{fig:naive}).  The\nattempt at matching~\\(p\\) with \\(\\ind{t}{j-i+1,j-1}\\) could reuse\n\\(\\ind{t}{j-i+1,j-1} = \\ind{p}{1,i-1}\\), in other words,\n\\(\\ind{p}{0,i-2}\\)~is compared to~\\(\\ind{p}{1,i-1}\\), i.e., the\npattern~\\(p\\) is compared to a part of itself. If we know an\nindex~\\(k\\) such that \\(\\ind{p}{0,k-1} = \\ind{p}{i-k,i-1}\\), that is,\n\\(\\ind{p}{0,k-1}\\)~is a \\emph{border} of~\\(\\ind{p}{0,i-1}\\) (also\nknown as a \\emph{side}\\index{side|see{word factoring, border}}), then\nwe can resume by comparing~\\(\\ind{t}{j}\\)\nwith~\\(\\ind{p}{k}\\). Clearly, the greater~\\(k\\), the more comparisons\nare skipped, so we want to find the \\emph{maximum borders} of the\nprefixes of~\\(p\\).\n\n\\paragraph{Border}\n\\index{word factoring!border|(}\n\nThe border of a non\\hyp{}empty word~\\(y\\) is a proper prefix of~\\(y\\)\nwhich is also a suffix. For example, the word \\word{abacaba} has three\nborders: \\(\\varepsilon\\), \\word{a}~and~\\word{aba}. The last one is the\nmaximum border and we write\n\\(\\Border{}{\\underline{\\word{aba}}\\word{c}\\underline{\\word{aba}}} =\n\\word{aba}\\). Another example is \\(\\Border{}{\\word{abac}} =\n\\varepsilon\\), because \\(\\word{abac} =\n\\underline{\\varepsilon}\\word{abac}\\underline{\\varepsilon}\\). Maximum\nborders can overlap; consider, for example,\n\\(\\Border{}{\\underline{\\word{aaa}}\\word{a}} =\n\\Border{}{\\word{a}\\underline{\\word{aaa}}} = \\word{aaa}\\).\n\nThe speed\\hyp{}up brought by Morris and Pratt to the na\\\"{\\i}ve search\nis depicted in \\fig~\\vref{fig:mp}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=74 621 367 717]{mp}\n\\caption{Morris-Pratt algorithm (failure in grey)\n\\label{fig:mp}}\n\\end{figure}\nNotice that, contrary to na\\\"{\\i}ve factoring, letters in the text are\ncompared in a strictly increasing order (never having to\nbacktrack). Consider the complete run in \\fig~\\vref{fig:mp_ex} where,\nin the end,\n\\begin{figure}[t]\n\\centering\n\\includegraphics{mp_ex}\n\\caption{Morris\\hyp{}Pratt algorithm at work (no match found)\n\\label{fig:mp_ex}}\n\\end{figure}\n\\(p\\)~is not found to be a factor of~\\(t\\). As usual, letters on a\ngrey background correspond to mismatches. It is clear that\n\\(\\Border{}{a} = \\varepsilon\\), for all letters~\\(a\\).\n\nWe now have the choice of finding either \\(\\Border{}{ay}\\) or\n\\(\\Border{}{ya}\\), where \\(y\\)~is a non\\hyp{}empty word. Since we are\ninterested in knowing the maximum borders of all the prefixes of a\ngiven pattern, the latter is more suitable (\\(y \\pref ya\\)). The idea\nis to recursively consider \\(\\Border{}{y} \\cdot a\\): if it is a prefix\nof~\\(y\\), then \\(\\Border{}{ya} = \\Border{}{y} \\cdot a\\); otherwise, we\nseek the maximum border of the maximum border of~\\(y\\), namely,\n\\(\\Border{2}{y} \\cdot a\\) etc. until \\(\\Border{q}{y} \\cdot a\\) is a\nprefix of~\\(y\\) or else \\(\\Border{q}{y} = \\varepsilon\\). For example,\n\\(\\Border{}{y \\cdot \\word{a}} = \\Border{3}{y} \\cdot \\word{a}\\) in\n\\fig~\\vref{fig:max_B}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics{max_B}\n\\caption{\\(\\Border{}{y \\cdot \\word{a}}\n   = \\Border{}{\\Border{}{y} \\cdot \\word{a}}\n   = \\Border{}{\\Border{2}{y} \\cdot \\word{a}}\n   = \\Border{3}{y} \\cdot \\word{a}\\).\n\\label{fig:max_B}}\n\\end{figure}\n\n\\par\\vskip\\baselineskip\n\nFormally, for all words~\\({y \\neq \\varepsilon}\\) and any\nletter~\\(a\\),\n\\begin{equation}\n  \\Border{}{a}         := \\varepsilon;\\qquad\n  \\Border{}{y \\cdot a} := \\left\\{\n    \\begin{aligned}\n      & \\Border{}{y} \\cdot a,\n      && \\text{if \\(\\Border{}{y} \\cdot a \\prefeq y\\)};\\\\\n      & \\Border{}{\\Border{}{y} \\cdot a},\n      && \\text{otherwise.}\n    \\end{aligned}\n  \\right.\n\\label{eq:Border}\n\\end{equation}\nConsider the following examples where \\(y\\)~and~\\(\\Border{}{y}\\) are\ngiven:\n\\begin{align*}\n  y             &= \\word{abaabb},\n& \\Border{}{y}  &= \\varepsilon,\n& \\Border{}{y \\cdot \\word{b}}\n                &= \\Border{}{\\Border{}{y} \\cdot \\word{b}}\n                 = \\Border{}{\\word{b}} = \\varepsilon;\\\\\n  y             &= \\word{baaaba},\n& \\Border{}{y}  &= \\word{ba},\n& \\Border{}{y \\cdot \\word{a}}\n                &= \\Border{}{y} \\cdot \\word{a}\n                 = \\word{baa};\\\\\n  y             &= \\word{abbbab},\n& \\Border{}{y}  &= \\word{ab},\n& \\Border{}{y \\cdot \\word{a}}\n                &= \\Border{}{\\Border{}{y} \\cdot \\word{a}}\n                 = \\Border{2}{y} \\cdot \\word{a}\n                 = \\word{a}.\n\\end{align*}\n\\index{word factoring!border|)}\n\n\\paragraph{Failure function}\n\\index{word factoring!failure function|(}\n\nLet us note~\\(\\wlen{y}\\) the length of a word~\\(y\\). For a given\nword~\\(x\\), let us define a function \\(\\MPfailureName_{x}\\) on all its\nprefixes as\n\\begin{equation}\n  \\MPfailure{x}{}{\\wlen{y}}\n:= \\wlen{\\Border{}{y}},\\,\\; \\text{for\n    all \\(x\\) and \\(y \\neq \\varepsilon\\) such\n    that \\(y \\prefeq x\\)}.\\label{eq:MP_failure}\n\\end{equation}\nFor reasons which will be clear soon, this function is called the\n\\emph{failure function} of~\\(x\\). An equivalent definition is\n\\begin{equation*}\n  \\MPfailure{x}{}{i}\n= \\wlen{\\Border{}{\\ind{x}{0,i-1}}}, \\,\\;\n\\text{for all \\(x\\) and  \\(i\\) such that\n\\(0 < i \\leqslant \\wlen{x}\\)}.\n\\end{equation*}\nFor example, \\fig~\\vref{fig:mp_fail} shows the table of the maximum\nborders for the prefixes of the word \\word{abacabac}.\n\\begin{figure}\n\\centering\n\\includegraphics{mp_fail}\n\\caption{Failure function of \\word{abacabac}\n\\label{fig:mp_fail}}\n\\end{figure}\nIn \\fig~\\vref{fig:mp}, the length of the maximum border is~\\(k\\), so\n\\(k=\\MPfailure{p}{}{i}\\) and \\(\\smash{\\Ind{p}{\\MPfailure{p}{}{i}}}\\)\nis the first letter to be compared with~\\(\\ind{t}{j}\\) after the\nshift. Also, the figure assumes that \\({i>0}\\), so the border in\nquestion is defined. Equations \\eqref{eq:Border} \\vpageref{eq:Border}\ndefining the maximum border can be unfolded as follows:\n\\begin{align*}\n   \\Border{}{ya}\n&= \\Border{}{\\Border{}{y} \\cdot a},\n& \\Border{}{y} \\cdot a &\\nprefeq y;\\\\\n   \\Border{}{\\Border{}{y} \\cdot a}\n&= \\Border{}{\\Border{2}{y} \\cdot a},\n&  \\Border{2}{y} \\cdot a &\\nprefeq \\Border{}{y};\\\\\n&\\;\\;\\smash{\\vdots} & &\\;\\;\\smash{\\vdots}\\\\\n   \\smash{\\Border{}{\\Border{p-1}{y} \\cdot a}}\n&= \\smash{\\Border{}{\\Border{p}{y} \\cdot a}},\n& \\smash{\\Border{p}{y} \\cdot a} &\\nprefeq \\smash{\\Border{p-1}{y}};\n\\end{align*}\nand \\(\\varepsilon \\not\\in \\{y,\\Border{}{y}, \\dots,\n\\Border{p-1}{y}\\}\\). By transitivity, the equations entail\n\\(\\Border{}{ya} = \\Border{}{\\Border{p}{y} \\cdot a}\\). Two cases are\npossible: either \\(\\Border{p}{y} = \\varepsilon\\), so \\(\\Border{}{ya} =\n\\Border{}{a} = \\varepsilon\\), or the unfolding resumes until we find\nthe smallest \\(q > p\\) such that \\(\\Border{}{\\Border{q-1}{y} \\cdot a}\n= \\Border{}{\\Border{q}{y} \\cdot a}\\) with \\(\\Border{q}{y} \\cdot a\n\\prefeq \\Border{q-1}{y}\\). Because a border is a proper prefix, that\nis to say, \\(\\Border{}{y} \\pref y\\), we have \\(\\Border{2}{y} =\n\\Border{}{\\Border{}{y}} \\pref \\Border{}{y}\\), yielding \\(\\Border{q}{y}\n\\cdot a \\prefeq \\Border{q-1}{y} \\pref \\dots \\pref \\Border{}{y} \\pref\ny\\). Therefore \\(\\Border{q}{y} \\cdot a \\prefeq y\\), since \\({q > 0}\\),\nand \\(\\Border{}{ya} = \\Border{q}{y} \\cdot a\\). This reasoning\nestablishes that\n\\begin{equation*}\n\\Border{}{ya} = \n\\left\\{\n  \\begin{aligned}\n   & \\Border{q}{y} \\cdot a,\n   && \\text{if \\(\\Border{q}{y} \\cdot a \\prefeq y\\)};\\\\\n   & \\varepsilon, \n   && \\text{otherwise;}\n  \\end{aligned}\n\\right.\n\\end{equation*}\nwith the additional constraint that \\(q\\)~must be as small as\npossible. This form of the definition of~\\(\\BorderName\\) is simpler\nbecause it does not contain an embedded call like\n\\(\\Border{}{\\Border{}{y} \\cdot a}\\). We can now take the lengths of\neach sides of the equations, leading to\n\\begin{equation*}\n\\wlen{\\Border{}{ya}} = \n\\left\\{\n  \\begin{aligned}\n   & \\wlen{\\Border{q}{y} \\cdot a} = 1 + \\wlen{\\Border{q}{y}},\n   && \\text{if \\(\\Border{q}{y} \\cdot a \\prefeq y\\)};\\\\\n   & \\wlen{\\varepsilon} = 0,\n   && \\text{otherwise.}\n  \\end{aligned}\n\\right.\n\\end{equation*}\nIf~\\({ya \\prefeq x}\\), then \\(\\wlen{\\Border{}{ya}} =\n\\MPfailure{x}{}{\\wlen{ya}} = \\MPfailure{x}{}{\\wlen{y}+1}\\). Let \\(i :=\n\\wlen{y} > 0\\).\n\\begin{equation*}\n\\MPfailure{x}{}{i+1} =\n\\left\\{\n  \\begin{aligned}\n   & 1 + \\wlen{\\Border{q}{y}},\n   && \\text{if \\(\\Border{q}{y} \\cdot a \\prefeq y\\)};\\\\\n   & 0,\n   && \\text{otherwise.}\n  \\end{aligned}\n\\right.\n\\end{equation*}\nWe need to work on~\\(\\wlen{\\Border{q}{y}}\\) now. From the definition\nof~\\(\\MPfailureName\\) by equation~\\eqref{eq:MP_failure}\n\\vpageref{eq:MP_failure}, we deduce\n\\begin{equation}\n\\MPfailure{x}{q}{\\wlen{y}} = \\wlen{\\Border{q}{y}},\n\\,\\; \\text{with \\(y \\prefeq x\\)},\n\\label{eq:MP_failure_p}\n\\end{equation}\nwhich we can prove by complete induction on~\\(q\\). Let us call this\nproperty \\(\\pred{P}{q}\\). Trivially, we have \\(\\pred{P}{0}\\). Let us\nsuppose \\(\\pred{P}{n}\\) for all \\(n \\leqslant q\\): this is the\ninduction hypothesis. Let us suppose \\(y \\prefeq x\\) and prove now\n\\(\\pred{P}{q+1}\\):\n\\begin{equation*}\n  \\MPfailure{x}{q+1}{\\wlen{y}}\n= \\MPfailure{x}{q}{\\MPfailure{x}{}{\\wlen{y}}} \n= \\MPfailure{x}{q}{\\wlen{\\Border{}{y}}}\n\\doteq \\wlen{\\Border{q}{\\Border{}{y}}}\n= \\wlen{\\Border{q+1}{y}},\n\\end{equation*}\nwhere \\((\\smash{\\doteq})\\)~is a valid application of the induction\nhypothesis because \\(\\Border{}{y} \\pref y \\prefeq x\\). This proves\n\\(\\pred{P}{q+1}\\) and the induction principle entails that\n\\(\\pred{P}{n}\\) holds for all \\(n \\geqslant 0\\). Therefore, equation\n\\eqref{eq:MP_failure_p} allows us to refine our definition of\n\\(\\MPfailure{x}{}{i+1}\\) as follows, with \\(i>0\\):\n\\begin{equation*}\n\\MPfailure{x}{}{i+1} =\n\\left\\{\n  \\begin{aligned}\n   & 1 + \\MPfailure{x}{q}{i},\n   && \\text{if \\(\\Border{q}{y} \\cdot a \\prefeq y\\)};\\\\\n   & 0,\n   && \\text{otherwise.}\n  \\end{aligned}\n\\right.\n\\end{equation*}\nThere is one part of the definition \\eqref{eq:Border}\n\\vpageref{eq:Border} that we did not use: \\({\\Border{}{a} :=\n  \\varepsilon}\\). It implies \\(\\MPfailure{x}{}{1} =\n\\MPfailure{x}{}{\\wlen{a}} = \\wlen{\\Border{}{a}} = \\wlen{\\varepsilon} =\n0\\) and, since the definition of~\\(\\MPfailureName\\) implies\n\\(\\MPfailure{x}{}{1} = 1 + \\MPfailure{x}{}{0}\\), so\n\\(\\MPfailure{x}{}{0} = -1\\). Property `\\(\\Border{q}{y} \\cdot a \\prefeq\ny\\) and \\({ya \\prefeq x}\\) and \\({\\wlen{y} = i}\\)' implies any of the\nequalities \\(\\smash{\\Ind{y}{\\wlen{\\Border{q}{y}}}} = a \\Leftrightarrow\n\\smash{\\Ind{y}{\\MPfailure{x}{q}{i}}} = a \\Leftrightarrow\n\\smash{\\Ind{x}{\\MPfailure{x}{q}{i}}} = \\smash{\\Ind{x}{\\wlen{y}}}\n\\Leftrightarrow \\smash{\\Ind{x}{\\MPfailure{x}{q}{i}}} = \\ind{x}{i}\\).\nWe now know\n\\begin{equation*}\n \\MPfailure{x}{}{0}   = -1\\quad\\text{and}\\quad\n \\MPfailure{x}{}{i+1} =\n   \\left\\{\n     \\begin{aligned}\n       & 1 + \\MPfailure{x}{q}{i},\n       && \\text{if \\(\\Ind{x}{\\MPfailure{x}{q}{i}} = \\ind{x}{i}\\)};\\\\\n       & 0,\n       && \\text{otherwise;}\n     \\end{aligned}\n   \\right.\n\\end{equation*}\nwhere \\(q\\)~is the smallest nonzero natural satisfying the\ncondition. This can be further simplified into\n\\begin{equation*}\n\\MPfailure{x}{}{0} = -1\n\\quad \\text{and} \\quad\n\\MPfailure{x}{}{i+1} = 1 + \\MPfailure{x}{q}{i},\n\\end{equation*}\nwhere~\\(i \\geqslant 0\\) and \\(q>0\\)~is the smallest natural such that\n\\(\\MPfailure{x}{q}{i} = -1\\) or \\(\\smash{\\Ind{x}{\\MPfailure{x}{q}{i}}}\n= \\ind{x}{i}\\).\n\n\\mypar{Preprocessing}\n\\index{word factoring!Morris-Pratt preprocessing!definition|(}\n\nThe function call\n\\(\\fun{fail}_0(x,i)\\)\\index{fail0@\\fun{fail\\(_0\\)/2}}, defined in\n\\fig~\\vref{fig:fail0}, implements \\(\\MPfailure{x}{}{i}\\).\n\\begin{figure}[t]\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\framebox[\\columnwidth]{\\vbox{%\n\\begin{gather*}\n\\fun{fail}_0(x,0) \\rightarrow -1;\\quad\n\\fun{fail}_0(x,i) \\rightarrow\n          1 + \\fun{fp}(x,\\fun{nth}(x,i-1),\\fun{fail}_0(x,i-1)).\\\\\n\\fun{nth}(\\cons{a}{x},0) \\rightarrow a;\\quad\n\\fun{nth}(\\cons{a}{x},i) \\rightarrow \\fun{nth}(x,i-1).\n\\\\\n\\inferrule*{}{\\fun{fp}(x,a,-1) \\rightarrow -1;}\n\\quad\n\\inferrule\n  {\\fun{nth}(x,k) \\twoheadrightarrow a}\n  {\\fun{fp}(x,a,k) \\twoheadrightarrow k}\n\\,;\\quad\n\\fun{fp}(x,a,k) \\rightarrow \\fun{fp}(x,a,\\fun{fail}_0(x,k)).\n\\end{gather*}\n}}\n\\caption{The failure function \\(\\MPfailureName\\) as \\fun{fail\\(_0\\)/2}\n\\label{fig:fail0}}\n\\end{figure}\nThe function \\fun{fp/3}\\index{fp@\\fun{fp/3}} (\\emph{fixed point})\ncomputes \\(\\MPfailure{x}{q}{i-1}\\), starting with\n\\(\\fun{fail}_0(x,i-1)\\) and\n\\(\\fun{nth}(x,i-1)\\)\\index{nth@\\fun{nth/2}}, which denotes\n\\(\\ind{x}{i-1}\\) and is needed to check the condition\n\\(\\smash{\\Ind{x}{\\MPfailure{x}{q}{i-1}}} = \\ind{x}{i-1}\\). The\nequality test \\(\\MPfailure{x}{q}{i-1} = -1\\) is performed by the first\nrule of \\fun{fp/3}.\\index{word factoring!failure function|)}\n\nThe algorithm of Morris and Pratt requires that \\(\\MPfailure{x}{}{i}\\)\nbe computed for all indexes~\\(i\\) of the pattern~\\(x\\) and, since it\ndepends on the values of some calls \\(\\MPfailure{x}{}{j}\\), with \\(j <\ni\\), it is more efficient to compute \\(\\MPfailure{x}{}{i}\\) for\nincreasing values of~\\(i\\) and store them, so they can be reused\ninstead of being recomputed. This technique is called\n\\emph{memoisation}\\index{memoisation} (not to be confused with\nmemorisation). In this instance, the evaluation of\n\\(\\MPfailure{x}{}{i}\\) relies on the memo\n\\([\\pair{\\ind{x}{i-1}}{\\MPfailure{x}{}{i-1}},\n\\pair{\\ind{x}{i-2}}{\\MPfailure{x}{}{i-2}}, \\dots,\n\\pair{\\ind{x}{0}}{\\MPfailure{x}{}{0}}]\\). The memoising version of\n\\fun{fail\\(_0\\)/2} is named \\fun{fail/2}\\index{fail@\\fun{fail/2}} in\n\\fig~\\ref{fig:fail}.\n\\begin{figure}[b]\n\\centering\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\framebox[0.85\\columnwidth]{\\vbox{%\n\\begin{gather*}\n\\fun{fail}(p,0) \\rightarrow -1;\n\\quad\n\\fun{fail}(\\cons{\\pair{a}{k}}{p},i) \\rightarrow \n\\fun{fp}(p,a,k,i-1).\n\\\\\n\\inferrule*{}{\\fun{fp}(p,a,-1,i) \\rightarrow 0;}\\quad\n\\inferrule\n  {\\fun{suf}(p,i-k-1) \\twoheadrightarrow \\cons{\\pair{a}{k'}}{p'}}\n  {\\fun{fp}(p,a,k,i) \\twoheadrightarrow k+1}\\,;\\\\\n\\inferrule\n  {\\fun{suf}(p,i-k-1) \\twoheadrightarrow \\cons{\\pair{b}{k'}}{p'}}\n  {\\fun{fp}(p,a,k,i) \\twoheadrightarrow \\fun{fp}(p',a,k',k)}\\,.\n\\\\\n\\fun{suf}(p,0) \\rightarrow p;\\quad\n\\fun{suf}(\\cons{a}{p},i) \\rightarrow \\fun{suf}(p,i-1).\n\\end{gather*}\n}}\n\\caption{The failure function with memoisation\\label{fig:fail}}\n\\end{figure}\nHere, we work with the memo~\\(p\\), which is a reversed prefix, instead\nof~\\(x\\), so we need to know its length~\\(i\\) in order to know how\nmany letters must be discarded by \\fun{suf/2}\\index{suf@\\fun{suf/2}}\n(\\emph{suffix}): \\(\\fun{suf}(x,i-k-1)\\) instead of\n\\(\\fun{fail}_0(x,k)\\). Thanks to the memo, \\fun{fp/4} does not need to\ncall \\fun{fail/2}, just to look in~\\(p\\) with \\fun{suf/2}. Note that,\nas a small improvement, we also moved the increment: instead of \\(1 +\n\\fun{fp}(\\dots)\\) and \\(\\dots \\twoheadrightarrow k\\), we do now\n\\(\\fun{fp}(\\dots)\\) and \\(\\dots \\twoheadrightarrow k+1\\).\n\nLet us name \\fun{pp/1}\\index{pp@\\fun{pp/1}} (\\emph{preprocessing}) the\nfunction computing the stack \\([\\pair{\\ind{x}{0}}{\\MPfailure{x}{}{0}},\n\\pair{\\ind{x}{1}}{\\MPfailure{x}{}{1}}, \\dots,\n\\pair{\\ind{x}{m-1}}{\\MPfailure{x}{}{m-1}}]\\) for a pattern~\\(x\\) of\nlength~\\(m\\). Its definition is shown in \\fig~\\vref{fig:pp},\n\\begin{figure}[t]\n\\begin{equation*}\n\\boxed{%\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{pp}(x) & \\rightarrow & \\fun{pp}(x,\\el,0).\\\\\n\\\\\n\\fun{pp}(\\el,p,i) & \\rightarrow & \\fun{rev}(p);\\\\\n\\fun{pp}(\\cons{a}{x},p,i)\n  & \\rightarrow\n  & \\fun{pp}(x,\\cons{\\pair{a}{\\fun{fail}(p,i)}}{p},i+1).\n\\end{array}}\n\\end{equation*}\n\\caption{Preprocessing of a pattern~\\(y\\) by \\fun{pp/1}\n\\label{fig:pp}}\n\\end{figure}\nwhere \\fun{rev/1}\\index{rev@\\fun{rev/1}} is the reversal function\n(definition~\\eqref{def:rev} \\vpageref{def:rev}), and\n\\fun{pp/1}\\index{pp@\\fun{pp/1}} simply calls the failure function\n\\fun{fail/2} for each new index~\\(i\\) on the current memo~\\(p\\) and\ncreates a new memo by pairing the failure index with the current\nletter and pushing on the current memo\n(\\(\\cons{\\pair{a}{\\fun{fail}(p,i)}}{p}\\)). The stack reversal at the\nend is necessary because the memo contains the letters in reversed\norder with respect to the pattern. For example, the example in\n\\fig~\\vref{fig:mp_fail} leads to the evaluation\n\\begin{equation*}\n\\fun{pp}(x) \\twoheadrightarrow\n[\\pair{\\word{a}}{-1}, \\pair{\\word{b}}{0},\n\\pair{\\word{a}}{0}, \\pair{\\word{c}}{1},\n\\pair{\\word{a}}{0}, \\pair{\\word{b}}{1},\n\\pair{\\word{a}}{2}, \\pair{\\word{c}}{3}],\n\\end{equation*}\nwhere \\(x=\\word{abacabac}\\). If \\(x=\\word{ababaca}\\), then\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\fun{pp}(x) \\twoheadrightarrow\n[\\pair{\\word{a}}{-1}, \\pair{\\word{b}}{0},\n\\pair{\\word{a}}{0}, \\pair{\\word{b}}{1},\n\\pair{\\word{a}}{2}, \\pair{\\word{c}}{3},\n\\pair{\\word{a}}{0}].\n\\end{equation*}\n\\index{word factoring!Morris-Pratt preprocessing!definition|)}\n\n%\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost} \n\\index{word factoring!Morris-Pratt preprocessing!minimum cost|(}\n\nIt is clear from the definition~\\eqref{eq:Border} \\vpageref{eq:Border}\nthat the determination of the maximum border of a non\\hyp{}empty word\nrequires finding the maximum borders of some or all proper prefixes,\nso, if the word contains \\(n\\)~letters, at least \\(n-1\\) comparisons\nare needed, as the border of the first letter alone needs no\ncomparison. This lower bound is tight, as the following reasoning\nshows. Let us call \\emph{positive comparison}\\index{word\n  factoring!comparison!positive $\\sim$} a successful prefix test as\nfound in the definition of~\\(\\BorderName\\), that is, \\(\\Border{}{y}\n\\cdot a \\prefeq y\\). Dually, a \\emph{negative comparison}\\index{word\n  factoring!comparison!negative $\\sim$} is a failed prefix test. In\norder to minimise the number of calls to evaluate \\(\\Border{}{ya}\\),\nwe may notice that a positive comparison only entails the evaluation\nof~\\(\\Border{}{y}\\), whilst a negative comparison requires two:\n\\(\\Border{}{\\Border{}{y} \\cdot a}\\). Therefore, the first idea may be\nto assume that only positive comparisons occur:\n\\begin{equation*}\n\\Border{}{x} \\!\\eqn{n-2}\\! \n\\Border{}{\\ind{x}{0,n-2}} \\cdot \\ind{x}{n-1}\n\\!\\eqn{n-1}\\!\\! \\dots\n\\eqn{0}\\! \\Border{}{\\ind{x}{0}} \\cdot \\ind{x}{1,n-1}\n\\!=\\! \\ind{x}{1,n\\!-\\!1},\n\\end{equation*}\nwhere \\((\\smash{\\eqn{i}})\\)~implies \\(\\Border{}{\\ind{x}{0,i}} \\cdot\n\\ind{x}{i+1} \\prefeq \\ind{x}{0,i}\\), for \\(0 \\leqslant i \\leqslant\nn-2\\). Firstly, \\(i=0\\) and the corresponding positive comparison\nyields \\(\\ind{x}{0} = \\ind{x}{1}\\). Unfolding the other comparisons\nyields \\(\\ind{x}{0} = \\ind{x}{1} = \\dots = \\ind{x}{n-1}\\), so a best\ncase is \\(x=a^n\\), for any letter~\\(a\\).\n\nBut there is another case,\nbecause the outermost call to~\\(\\BorderName\\) after a negative\ncomparison does not imply a comparison if its argument is a single\nletter:\n\\begin{align*}\n\\Border{}{x}\n&\\eqn{n-2} \\Border{}{\\Border{}{\\ind{x}{0,n-2}} \\cdot \\ind{x}{n-1}}\\\\\n&\\eqn{n-3} \\Border{}{\\Border{}{\\Border{}{\\ind{x}{0,n-3}} \\cdot\n    \\ind{x}{n-2}} \\cdot \\ind{x}{n-1}}\\\\\n&\\;\\;\\;\\smash{\\vdots}\\\\\n&\\;\\mathrel{\\stackrel{\\smash[t]{0}}{=}}\n  \\Border{}{\\Border{}{\\ldots \\Border{}{\\Border{}{\\ind{x}{0}} \\cdot\n        \\ind{x}{1}} \\dots} \\cdot \\ind{x}{n-1}}\\\\\n&\\,\\,\\doteq\n  \\Border{}{\\Border{}{\\ldots \\Border{}{\\Border{}{\\ind{x}{1}} \\cdot\n            \\ind{x}{2}} \\dots} \\cdot \\ind{x}{n-1}}\\\\\n&\\;\\;\\;\\smash{\\vdots}\\\\\n&\\,\\,\\doteq \\Border{}{\\ind{x}{n-1}} = \\varepsilon.\n\\end{align*}\nwhere \\((\\smash{\\eqn{i}})\\)~implies \\(\\Border{}{\\ind{x}{0,i}} \\cdot\n\\ind{x}{i+1} \\nprefeq \\ind{x}{0,i}\\), for \\(0 \\leqslant i \\leqslant\nn-2\\) and \\((\\smash{\\doteq})\\) involves no comparisons. Starting with\n\\(i=0\\) yields \\(\\ind{x}{1} \\neq \\ind{x}{0}\\), then \\(i=1\\) leads to\n\\(\\ind{x}{2} \\neq \\ind{x}{0}\\) etc. so the consequences of all these\nnegative comparisons are \\(\\ind{x}{0} \\neq \\ind{x}{i}\\), for \\(1\n\\leqslant i \\leqslant n-2\\). The number of negative comparisons is\n\\(n-1\\), thus is minimal, but the shape of the word is different than\npreviously, as the first letter must differ from all the\nfollowing. Let \\(\\OB{\\fun{pp}}{n}\\)\\index{pp@$\\OB{\\fun{pp}}{n}$} be\nthe minimum number of comparisons involved in the evaluation of\n\\(\\fun{pp}(x)\\)\\index{pp@\\fun{pp/1}}, where the length of the\npattern~\\(x\\) is~\\(n\\). It is the same as the number of comparisons to\nevaluate \\(\\Border{}{\\ind{x}{0,n-2}}\\) when \\(\\ind{x}{0,n-2}\\)~is a\nbest case. Therefore,\n%\\begin{equation*}\n\\(\\OB{\\fun{pp}}{n} = n - 2\\).\n%\\end{equation*}\n\\index{word factoring!Morris-Pratt preprocessing!minimum cost|)}\n\n\\paragraph{Maximum cost}\n\\index{word factoring!Morris-Pratt preprocessing!maximum cost|(}\n\nThe determination of the maximum border of a word implies finding the\nmaximum borders of some or all proper prefixes, so, if we want to\nmaximise the number of comparisons, we may want to compute as many\nborders as possible. In order to do so, evaluating \\(\\Border{}{x}\\)\nwould lead to finding the maximum border of a factor of\nlength~\\(n-1\\), where \\(n\\)~is the length of~\\(x\\). The best case\n\\(x=a^{n}\\) showed that \\(\\Border{}{x} = \\ind{x}{1,n-1}\\), which fits\nour purpose, except we would like \\(\\Border{}{\\ind{x}{1,n-1}}\\). In\nother words, we add the constraint that the first comparison is\nnegative:\n\\begin{align*}\n\\Border{}{x}\n&\\eqn{n-1} \\Border{}{\\Border{}{\\ind{x}{0,n-2}} \\cdot \\ind{x}{n-1}}\\\\\n&\\eqn{n-2} \\Border{}{\\Border{}{\\ind{x}{0,n-3}} \\cdot \\ind{x}{n-2,n-1}}\\\\\n&\\;\\;\\;\\smash{\\vdots}\\\\\n&\\;\\mathrel{\\stackrel{\\smash[t]{1}}{=}}\n  \\Border{}{\\Border{}{\\ind{x}{0}} \\cdot \\ind{x}{1,n-1}}\n= \\Border{}{\\ind{x}{1,n-1}},\n\\end{align*}\nwhere \\((\\smash{\\eqn{n-1}})\\) supposes \\(\\Border{}{\\ind{x}{0,n-2}}\n\\cdot \\ind{x}{n-1} \\nprefeq \\ind{x}{0,n-2}\\), and\n\\((\\smash{\\eqn{i}})\\), with \\(1 \\leqslant i \\leqslant n-2\\),\ncorresponds to \\(\\Border{}{\\ind{x}{0,i}} \\cdot \\ind{x}{i+1} \\prefeq\n\\ind{x}{0,i}\\). These constraints imply \\(\\ind{x}{0} = \\ind{x}{1} =\n\\dots = \\ind{x}{n-2} \\neq \\ind{x}{n-1}\\), that is to say,\n\\(x=a^{n-1}b\\), with \\(a \\neq b\\). Up to now, the number of\ncomparisons is~\\(n-1\\), as in the minimal case, but the evaluation\ncontinues as follows:\n\\begin{equation*}\n\\Border{}{a^{i}b}\n\\eqn{i} \\Border{}{\\Border{}{a^{i}} \\cdot b}\\\\\n\\doteq \\Border{}{\\Border{}{a^{i-1}} \\cdot ab}\\\\\n\\doteq \\dots \\doteq \\Border{}{a^{i-1}b},\n\\end{equation*}\nfor \\(1 \\leqslant i \\leqslant n-2\\) and \\((\\smash{\\eqn{i}})\\) entails\nthe negative comparisons \\(\\Border{}{a^{i}} \\cdot b \\nprefeq a^{i}\\)\nand the positive comparisons \\((\\smash{\\doteq})\\), which we do not\ncount because we have in mind to find\n\\(\\OW{\\fun{pp}}{n}\\)\\index{pp@$\\OW{\\fun{pp}}{n}$}, so repeated\nevaluations of the same border do not entail repeated comparisons\nthanks to memoisation\\index{memoisation}. Thus, we have \\(n-2\\)\nnegative comparisons until \\(\\Border{}{b} = \\varepsilon\\), which, with\nthe \\(n-1\\) earlier positive comparisons, sum up \\(2n-3\\). Since\n\\(\\OW{\\fun{pp}}{n}\\) is the number of comparisons to compute\n\\(\\Border{}{\\ind{x}{0,n-2}}\\) without repetitions, we have\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\OW{\\fun{pp}}{n} = 2(n-1)-3 = 2n - 5.\n\\end{equation*}\n\\index{word factoring!Morris-Pratt preprocessing!maximum cost|)}\n\n\\vspace*{-20pt}\n\n\\mypar{Search}\n\\index{word factoring!Morris-Pratt!search|(}\n\nWe found above that \\(n-2 \\leqslant \\OC{\\fun{pp}}{n} \\leqslant 2n -\n5\\), where the bounds are tight if \\(n \\geqslant 3\\). To make use of\nthe value of \\(\\fun{pp}(p)\\), we could start by modifying the linear\nsearch in section~\\ref{sec:naive_factoring}, in particular the program\nin \\fig~\\ref{fig:loc} on page~\\pageref{fig:loc}, while keeping an eye\non \\fig~\\vref{fig:mp}. The result is displayed in\n\\fig~\\vref{fig:mp_def}. Note how the first argument of\n\\fun{mp/5}\\index{mp@\\fun{mp/5}}, \\(p\\), is the working copy and the\nthird, \\(p'\\), is the original which remains invariant (it is used to\nreset~\\(p\\) after a letter mismatch). Indexes~\\(i\\), \\(j\\) and~\\(k\\)\nare the same as in \\fig~\\vref{fig:mp}. The latter is none other than\nthe value computed by the failure function; variables \\(i\\)~and~\\(j\\)\nare incremented each time a letter in the pattern is successfully\nmatched against a letter in the text (third rule of \\fun{mp/5}) and\n\\(j\\)~is also incremented each time there is a mismatch of the first\nletter of the pattern (fourth rule of \\fun{mp/5}).\\index{word\n  factoring!Morris-Pratt!search|)}\n\\begin{figure}[h]\n\\centering\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\framebox[0.8\\columnwidth]{\\vbox{%\n\\begin{gather*}\n\\inferrule\n  {\\fun{pp}(p) \\twoheadrightarrow p'}\n  {\\fun{mp}(p,t) \\twoheadrightarrow \\fun{mp}(p',t,p',0,0)}.\n\\\\\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mp}(\\el,t,p',i,j)   & \\rightarrow & \\fun{factor}(j-i);\\\\\n\\fun{mp}(p,\\el,p',i,j)   & \\rightarrow & \\fun{absent}();\\\\\n\\fun{mp}(\\cons{\\pair{a}{k}}{p},\\cons{a}{t},p',i,j)\n                         & \\rightarrow & \\fun{mp}(p,t,p',i+1,j+1);\\\\\n\\fun{mp}(\\cons{\\pair{a}{-1}}{p},\\cons{b}{t},p',0,j)\n                         & \\rightarrow & \\fun{mp}(p',t,p',0,j+1);\\\\\n\\fun{mp}(\\cons{\\pair{a}{k}}{p},t,p',i,j)\n                         & \\rightarrow\n                         & \\fun{mp}(\\fun{suf}(p',k),t,p',k,j).\n\\end{array}\n\\end{gather*}}}\n\\caption{Morris-Pratt algorithm (search phase)\\label{fig:mp_def}}\n\\end{figure}\n\n\n\\addcontentsline{toc}{subsection}{Cost}\n\\paragraph{Minimum cost} \n\\index{word factoring!Morris-Pratt!minimum cost|(}\n\nLet\n\\(\\smash[t]{\\OB{\\fun{mp/5}}{m,n}}\\)\\index{mp@$\\OB{\\fun{mp/5}}{m,n}$}\nbe the minimum number of comparisons performed during the evaluation\nof \\fun{mp/5}, where \\(m\\)~is the length of the pattern and \\(n\\)~is\nthe length of the text. Just as with na\\\"{\\i}ve factoring, the best\ncase is when the pattern is a prefix of the text, so\n\\(\\OB{\\fun{mp/5}}{m,n} = m\\). Taking into account the preprocessing\nstage, the minimum number of comparisons\n\\(\\OB{\\fun{mp}}{m,n}\\)\\index{mp@$\\OB{\\fun{mp}}{m,n}$} of\n\\fun{mp/2}\\index{mp@\\fun{mp/2}} is\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\OB{\\fun{mp}}{m,n} = \\OB{\\fun{pp}}{m} + \\OB{\\fun{mp/5}}{m,n} = (m-2)\n+ m = 2m - 2.\n\\end{equation*}\n\\index{word factoring!Morris-Pratt!minimum cost|)}\n\n\\vspace*{-10pt}\n\n\\paragraph{Maximum cost}\n\\index{word factoring!Morris-Pratt!maximum cost|(}\n\nSince the Morris\\hyp{}Pratt algorithm only reads the text forwards,\nthe worst case must maximise the number of times the letters of the\ntext~\\(t\\) are compared with a letter in the pattern~\\(p\\). Therefore,\nthe first letter of the pattern cannot differ from all the letters of\nthe text, otherwise each letter of the text would be compared exactly\nonce. Let us assume the exact opposite: \\(\\ind{p}{0} = \\ind{t}{i}\\),\nwith \\(i \\geqslant 0\\). But this would also imply one comparison per\nletter in the text. The way to force the pattern to shift as little as\npossible is to further impose \\(\\ind{p}{1} \\neq \\ind{t}{i}\\), for\n\\(i>0\\). In short, this means that \\(ab \\prefeq p\\), with letters\n\\(a\\)~and~\\(b\\) such that \\(a \\neq b\\) and \\(t=a^n\\). A simple\ndrawing is enough to reveal that this configuration leads to the\nmaximum number of comparisons \\(\\OW{\\fun{mp/5}}{m,n} = 2n -\n1\\)\\index{mp@$\\OW{\\fun{mp/5}}{m,n}$}, as each letter in the text is\ncompared twice, except the first, which is compared once. Taking into\naccount the preprocessing stage, the maximum number of comparisons\n\\(\\OW{\\fun{mp}}{m,n}\\) \\index{mp@$\\OW{\\fun{mp}}{m,n}$} of\n\\fun{mp/2}\\index{mp@\\fun{mp/2}} satisfies\n\\begin{equation*}\n\\belowdisplayskip=0pt\n\\OW{\\fun{mp}}{m,n} = \\OW{\\fun{pp}}{m} + \\OB{\\fun{mp/5}}{m,n} = (2m-5)\n+ (2n-1) = 2(n + m - 3).\n\\end{equation*}\n\\index{word factoring!Morris-Pratt!maximum cost|)}\n\n\\vspace*{-10pt}\n\n\\mypar{Metaprogramming}\n\\index{word factoring!Morris-Pratt!metaprogramming|(}\n\nThe previous study leads to programs for the preprocessing and search\nphases that somewhat obscure the main idea supporting the algorithm of\nMorris and Pratt, to wit, the use of the maximum borders of the proper\nprefixes of the pattern and the forward\\hyp{}only reading of the\ntext. The reason for that somewhat unfortunate situation is that, for\nefficiency imperatives, we have to memoise\\index{memoisation} the\nvalues of the failure function and, instead of working with the\noriginal pattern, we proceed with a version of it augmented with these\nvalues. Also, the utilisation of stacks for modelling the pattern\nslows down and obfuscates the reading of the letters and the shifts.\n\nIf the pattern is fixed, a more legible approach is available,\nconsisting in the modification of the preprocessing stage so that a\ndedicated program is output. This kind of taylored method, where a\nprogram is the result of the execution of another, is called\n\\emph{metaprogramming}\\index{metaprogramming}. Of course, it is an\noption only if the time needed to output, compile and execute a\nprogram is amortised in the long run, which implies for the problem at\nhand that the pattern and the text are expected to be significantly\nlong or that the search is likely to be repeated with the same pattern\non other texts (or the remainder of the same text after an occurrence\nof the pattern has been found).\n\n% Wrapping figure better declared before a paragraph\n%\n\\setlength{\\intextsep}{0pt}\n\\begin{wrapfigure}[29]{r}[0pt]{0pt}\n% 29 vertical lines\n% {r} mandatory right placement\n% [0pt] of margin overhang\n\\centering\n\\includegraphics[bb=71 360 238 723]{metaprog}\n\\caption{Factoring \\word{abacabac} %in~\\(t\\) with a metaprogram\n\\label{fig:metaprog}}\n\\end{wrapfigure}\nThere is a graphical way to represent the contents of the table in\n\\fig~\\vref{fig:mp_fail} called \\emph{deterministic finite automaton}\n\\index{word factoring!Morris-Pratt!automaton} \\index{finite\n  automaton!deterministic $\\sim$} and shown in\n\\fig~\\vref{fig:abacabac}.\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=80 651 390 710]{abacabac}\n\\caption{Morris-Pratt automaton for the pattern \\word{abacabac}\n\\label{fig:abacabac}}\n\\end{figure}\nWe will here only describe informally automata; for a full treatment,\nsee \\cite{VanLeeuwen_1990c, HopcroftMotwaniUllman_2003,\n  Sakarovitch_2003}. Consider that the circles, called\n\\emph{states}\\index{states}, contain the values of~\\(i\\) from the\ntable. The edges, called \\emph{transitions}\\index{transition}, between\ntwo states are of two kinds: either solid and carrying a letter,\ncalled \\emph{label}\\index{label}, or dotted and going backwards. The\nsuccession of states throughout solid edges make the word\n\\(x=\\word{abacabac}\\). The rightmost state is distinguished by a\ndouble circling because it marks the end of~\\(x\\). There is a back\nedge between state~\\(i\\) and~\\(j\\) only if \\(\\MPfailure{x}{}{i} = j\\).\nThe leftmost state has an incoming, solid edge without a source and a\ndotted, outgoing edge. The former simply denotes the beginning of the\nword and the latter corresponds to the special value\n\\(\\MPfailure{x}{}{0} = -1\\).  What matters for us is that the\nintuitive support brought by an automaton also can be implemented\nintuitively, with each state corresponding to one function and the\noutgoing transitions associated with different rules of the definition\nof the state function. The example \\word{abacabac} is shown in\n\\fig~\\ref{fig:metaprog}. The automaton states, \\(0\\), \\(1\\), through\n\\(7\\), correspond to the functions \\fun{zero/2}, \\fun{one/2}\netc. through \\fun{seven/2}. Notice how\n\\fun{mp\\(_0\\)/1}\\index{mp0@\\fun{mp\\(_0\\)/1}} sets the index to~\\(0\\)\nwhen initialising the first state, that is, calling\n\\fun{zero/2}\\index{zero@\\fun{zero/2}}. The index~\\(j\\) plays the same\nrole as in \\fig~\\ref{fig:mp} on page~\\pageref{fig:mp}. The first rule\nof each function corresponds to a rightwards transition in the\nautomaton in \\fig~\\vref{fig:abacabac} and the second rule is a\nbackwards transition, that is, a failure, except in \\fun{zero/2},\nwhere it means that the pattern is shifted by one letter. The function\n\\fun{zero/2} has a third rule handling the case when the pattern is\nabsent in the text. We could add a similar rule to the other\nfunctions, as an optimisation, but we opt for brevity and let\nsuccessive failure rules bring us back to\n\\fun{zero/2}\\index{zero@\\fun{zero/2}}. The first rule of\n\\fun{seven/2}\\index{seven@\\fun{seven/2}} is special as well, because\nit is used when the pattern has been found. Note the index \\(j-6\\),\nclearly showing that the length of the pattern is part of the program,\nwhich is hence a metaprogram.\\index{word\n  factoring!Morris-Pratt!metaprogramming|)} \\index{word\n  factoring!Morris-Pratt|)}\n\n\\mypar{Knuth's variant}\n\\index{word factoring!Knuth-Morris-Pratt|(}\n\nIn \\fig~\\vref{fig:mp}, if \\(a = \\word{a}\\), then the sliding would\nimmediately lead to a comparison failure. Hence let us compare\n\\(\\smash{\\Ind{p}{\\MPfailure{p}{}{i}}}\\) to~\\(\\ind{t}{j}\\) only if\n\\(\\smash{\\Ind{p}{\\MPfailure{p}{}{i}}} \\neq \\ind{p}{i}\\). Else, we\nconsider the maximum border of the maximum border etc. until we find\nthe smallest~\\(q\\) such that \\(\\smash{\\Ind{p}{\\MPfailure{p}{q}{i}}}\n\\neq \\ind{p}{i}\\). This is an improvement by\n\\cite{KnuthMorrisPratt_1977}. There is an updated reprint by\n\\cite{Knuth_2010} and a treatment based on automata theory by\n\\cite{CrochemoreHancartLecroq_2007}, in its section~2.6. See also an\ninteresting derivation of the program by algebraic refinements in the\nbook by \\cite{Bird_2010}. In terms of the search automaton, when a\nfailure occurs at state~\\(i\\) on the letter~\\(a\\), we follow the back\nedge to state \\(\\MPfailure{x}{}{i}\\), but, if the normal transition\nis~\\(a\\) again, we follow another back edge etc. until there is a\ntransition different from~\\(a\\) or we have to shift the pattern. The\nimprovement proposed by Knuth consists in replacing \n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=82 646 388 720]{kmp_abac}\n\\caption{Knuth-Morris-Pratt automaton for the pattern \\word{abacabac}\n\\label{fig:kmp_abac}}\n\\end{figure}\nall these successive failure transitions by only one. For example, the\nautomaton in \\fig~\\ref{fig:kmp_abac} is Knuth's optimisation of the\none in \\fig~\\ref{fig:abacabac}.\n\n\\index{word factoring!Knuth-Morris-Pratt|)}\n\\index{word factoring|)}\n\n\\paragraph{Exercises}\n\n\\begin{enumerate}\n\n  \\item Find \\(\\M{\\fun{loc}}{m,n}\\).\n\n  \\item Prove that \\fun{pp/1} and \\fun{mp/2} terminate.\n\n  \\item Prove \\(\\fun{loc/2} = \\fun{mp/2}\\) (correctness of the\n    algorithm of Morris and Pratt).\n\n  \\item Find \\(\\B{\\fun{pp}}{m}\\) and \\(\\W{\\fun{pp}}{m}\\). (Mind\n    the cost of \\fun{suf/2}.)\n\n  \\item Find \\(\\B{\\fun{mp}}{m,n}\\) and \\(\\W{\\fun{mp}}{m,n}\\).\n\n  \\item Find a simple modification to avoid calling \\fun{rev/1} in\n  \\fig~\\vref{fig:pp}.\\label{factoring:trick}\n\n  \\item Modify \\fun{fail/2} so that \\fun{mp/2} implements the\n    Knuth\\hyp{}Morris\\hyp{}Pratt algorithm. Study the best and worst\n    cases of this variant and show that \\(\\OW{\\fun{pp}}{m} = 2m-6\\),\n    for \\(m \\geqslant 3\\).\n\n  \\item Write the metaprogram corresponding to the automaton in\n    \\fig~\\vref{fig:kmp_abac}.\n\n  \\item Write a function \\fun{rlw/2}\\index{rlw@\\fun{rlw/2}}\n    (\\emph{remove the last word}) such that \\(\\fun{rlw}(w,t)\\) is\n    rewritten into the text~\\(t\\) if the word~\\(w\\) is absent,\n    otherwise into~\\(t\\) without the last occurrence of~\\(t\\) in it.\n\n\\end{enumerate}\n", "meta": {"hexsha": "8e1282ac5accb45261b2a19463ecd2f6b7096a68", "size": 52813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "factoring.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": "factoring.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": "factoring.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": 43.8282157676, "max_line_length": 77, "alphanum_fraction": 0.6608789503, "num_tokens": 18719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6143266878816387}}
{"text": "\\documentclass[]{article}\n\\usepackage{kotex}\n\\usepackage{amsmath}\n\n%opening\n\\title{Systematic Unvertainty Note}\n\\author{}\n\n\\begin{document}\n\n\\maketitle\n\n중력가속도 실험에 대한 Systematic Uncertainty Estimation\n\nBased on Monte-Carlo Simulation\n\n\\section{Equation of Datapoints}\n\n\\paragraph{Basic Equation}\n\\begin{equation}\nh = \\frac{1}{2} g t^2\n\\end{equation}\n\\begin{equation}\nt = \\sqrt{2 \\frac{g}{h}}\n\\end{equation}\n\n\\paragraph{Basic Equation with uncertainty}\n\n\\begin{equation}\nh+\\delta h = \\frac{1}{2} g \\left(t+\\delta t\\right)^2\n\\end{equation}\n\n\\begin{equation}\nt = \\sqrt{2 \\frac{g}{h+\\delta h}} + \\delta t\n\\end{equation}\n\nwith following random distribution\n\n\\begin{table}[!h]\n\t\\begin{tabular}{c|cc}\n\t\tRandom Variable & Distribution & Reason\\\\\\hline\n\t\t$\\delta h$ & Gaussian Disribution & Measured by human-eye\\\\\n\t\t$\\delta t$ & Uniform Disribution & Measured by mechanical clock\n\t\\end{tabular}\t\n\\end{table}\n\nWith overlapped uncertainty (depending on measuring methods), the $\\delta h$ has different value for each datapoints.\n\n\n\\section{Case Overlapped Length Dependencies}\nIf measuring length for each data-points has dependencies with each previous data-point. Uncertainty for each data-points is needed to declared especially.\n\n\\subsection{Error Propagation}\n\n\\paragraph{Basic Equation of uncertainty}\n\\begin{equation}\n\\delta f = \\sqrt{\\sum_i\\left(\\frac{\\partial f}{\\partial x_i} \\delta x_i \\right)^2}\n\\end{equation}\n\n\\paragraph{Overlapped Uncertainty, Propagated for Summation}\n\n\\begin{equation}\n\\delta (f+g) = \\sqrt{(\\delta g)^2 + (\\delta f)^2  }\n\\end{equation}\nFor independent 2 formula $f$ and $g$.\n\nOverlapping uncertainties. With measuring length period $l$, number $i$, single measuring uncertainty $\\delta l_i$, Initial offset $b$ and its uncertainty $\\delta b$\n\nFirst term\n\\begin{align}\nh_0 &= b \\\\\nh_1 &= b + l + \\delta l_1 \\\\\nh_2 &= b + 2l +  \\delta l_1 +\\delta l_2\n\\end{align} \n\nwith regularity, following correlation can be assumed.\n\n\\begin{equation}\nh_n = b + n \\cdot l + \\sum_i{\\delta l_i}\n\\end{equation}\n\nUncertainty is \n\\begin{equation}\n\\delta h_i = \\sqrt{\\sum_i{\\left(\\delta l\\right)^2}}\n\\end{equation}\n$\\delta l$ is constant for each $n$, \n\n\\begin{equation}\n\\delta h_n = \\sqrt{n} \\delta l\n\\end{equation}\n\n\n\n\t\n\n\\end{document}\n", "meta": {"hexsha": "f7725cb05970781a48cc0b1d346927ebd94d8ce6", "size": 2239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/code/systematic_uncertainty_note/template_Article.tex", "max_stars_repo_name": "Isaac-Kwon/Isaac-Kwon.github.io", "max_stars_repo_head_hexsha": "9f4145dc3748c9c0364476c90efd78311d4fb62d", "max_stars_repo_licenses": ["MIT"], "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/code/systematic_uncertainty_note/template_Article.tex", "max_issues_repo_name": "Isaac-Kwon/Isaac-Kwon.github.io", "max_issues_repo_head_hexsha": "9f4145dc3748c9c0364476c90efd78311d4fb62d", "max_issues_repo_licenses": ["MIT"], "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/code/systematic_uncertainty_note/template_Article.tex", "max_forks_repo_name": "Isaac-Kwon/Isaac-Kwon.github.io", "max_forks_repo_head_hexsha": "9f4145dc3748c9c0364476c90efd78311d4fb62d", "max_forks_repo_licenses": ["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.0824742268, "max_line_length": 165, "alphanum_fraction": 0.7213041536, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6143266799667383}}
{"text": "\\input{PreambleCommon}\r\n\\input{../WeekTitles}\r\n\r\n\\newcommand{\\Fe}{ F_{\\mbox{ext}} }\r\n\\newcommand{\\Fg}{ F_{\\mbox{grav}} }\r\n\r\n\\begin{document}\r\n\\setfont\r\n\\pagestyle{fancy}\r\n\\renewcommand{\\Week}{8 }\r\n\\renewcommand{\\WeekTitle}{\\WeekTitleEight }\r\n\r\n\\fancyhead[LE,RO]{Week \\Week}  % default, usually only for first page\r\n\\fancyfoot{}\r\n\\sectionbox{Week \\#\\Week: \\WeekTitle}\r\n\r\n\\vspace{5mm}\r\n\\goals\r\n\\begin{itemize}\r\n\\item Express real world situations in terms of second order linear\r\n  differential equations.\r\n\\item Describe the difference between homogeneous and nonhomogeneous\r\n  second order linear differential equations.\r\n\\item Use MATLAB to solve linear and nonlinear second order\r\n  differential equations, both homogeneous and nonhomogeneous.\r\n\\end{itemize}\r\n\\vspace{5mm}\r\n\r\n\\newpage\r\n\r\n\\topic{Generating Numerical Solutions with MATLAB}\r\n\\subsection*{Generating Numerical Solutions with MATLAB}\r\n\r\n\\problem Search for ``ordinary differential equations'' in MATLAB help.  \\vsc\r\n\\vsc\r\n\r\nWhat form of differential equation does MATLAB assume we have?\r\n\r\n\\vsc\r\n\\vsc\r\n\r\n\r\n\\newpage\r\n\r\nNote that MATLAB has many different differential equation solvers. If\r\nusing MATLAB after this course, you may have to do some reading to\r\nidentify the properties of the equation you have, and what the most\r\nappropriate solving tool is.\r\n\r\n\\problem Which of the solvers is recommended as a ``first try''\r\nsolver?\r\n\r\n\\vsc\r\n\\vsc\r\n\r\n\\newpage\r\n\r\n\\subsection*{ode45}\r\nThe first solver to reach for in MATLAB is \\verb#ode45#.  To run it, we need\r\n\\begin{itemize} \r\n\\item the DE function {\\bf in form $\\displaystyle \\frac{dy}{dt} = f(t, y)$};\r\n\\vfill\r\n\\item the time span for the solution/simulation, $[t_0, t_{\\mbox{end}}]$; and\r\n\\vfill\r\n\\item the initial condition ($y(t_0))$\r\n\\vfill\r\n\\end{itemize}\r\n\r\n\\problem What will \\verb#ode45# compute for us, given that\r\ninformation?\r\n\\vfill\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\topic{Example - Temperature Model}\r\n\\subsection*{Temperature Model - Newton's Law of Heating and Cooling}\r\n\r\nThe temperature of an object, $y$, changes at a rate proportional to\r\nthe temperature difference between object, $y$, and its environment,\r\n$T_{\\mbox{ext}}$.\r\n\r\n\\problem Translate this law into a mathematical statement.\r\n\r\n\\vfill Solution interpretation: a {\\bf solution} to a differential\r\nequation is the same as a {\\bf prediction}.  \\vspace{1.5in}\r\n\r\n\\newpage \r\n\r\n{\\bf In MATLAB}\r\n\r\n$$\\frac{dy}{dt} = -k (y - T_{\\mbox{ext}})$$\r\n\r\n\r\n\\begin{verbatim}\r\n% Define temp DE in the form dy/dt = f(t, y)\r\n% and set other constants\r\nk = 0.7;  % /min\r\n\r\nT_ext = 20; % external/environment temp\r\n\r\nDE = @(t, y)   -k (y - T_ext);\r\n\r\n\\end{verbatim}\r\n\r\n\\newpage\r\n\r\n\\subsection*{Example - Step 2}\r\n\\begin{verbatim}\r\n% Solve based on initial condition\r\ny0 = 100;  % initial temperature\r\n\r\ntspan = [0, 30];  % interval for solution\r\n\r\n[t, y] = ode45(DE, tspan_, y0);\r\n\r\nplot(t, y);\r\n\\end{verbatim}\r\n\r\n\\newpage\r\n\r\nTo decipher and work with the output, it is critical that you\r\nunderstand what MATLAB provides.  \r\n\\begin{itemize}\r\n\\item The final values of \\verb#t# and \\verb#y# are \r\n\\vfill\r\n\\item \\verb#t# starts at\r\n\\vfill\r\n\\item \\verb#t# ends at\r\n\\vfill\r\n\\item \\verb#y# starts at\r\n\\vfill\r\n\\end{itemize}\r\n\r\n\\newpage\r\n\r\n\\subsection*{Basic Process}\r\nHow does MATLAB do it?\r\n\\vfill\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\topic{Second-Order Linear Equations - Spring System Intro}\r\n\\section*{Second-Order Linear Equations - Spring System}\r\n\r\nSo far we have seen examples of {\\bf first-order DEs}, or equations\r\nwith first derivatives of some unknown function.  \r\n\r\nIn the following examples, we will expand our study to differential\r\nequations with {\\bf second or higher derivatives}.\r\n\r\nOne classic source of differential equations of this type comes from\r\nanalyzing the forces on a block at the end of a spring.\r\n\\begin{center}\r\n\\includegraphics[width=0.5\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\\newpage\r\n\\begin{center}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\nWhile the mathematics behind this simple system will be very\r\ninteresting in their own right, we should also note at the outset that\r\nthe simple spring/mass model can be applied to a wide variety of\r\nnot-so-obviously related real-world problems.\r\n\r\n\\begin{center}\r\n\\includegraphics[width=0.30\\linewidth]{graphics/notes_08_SpringSystemCar}\r\n\\includegraphics[width=0.30\\linewidth]{graphics/notes_08_Sound-Attenuation} \\\\\r\n\\includegraphics[width=0.30\\linewidth]{graphics/notes_08_Tuned_Mass_Damper_atop_Taipei_101_-_27_March_2008}\r\n\\end{center}\r\n\r\n\\newpage\r\n\r\n\\topic{Spring System Analysis}\r\n\\subsection*{Spring System Analysis}\r\n\r\n\\begin{center}\r\n\\includegraphics[width=0.5\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\n\\problem In this system, how would you describe $x$ in words?\r\n\r\n\\newpage\r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\\problem Draw a free-body diagram for the mass.  Indicate the magnitude of the forces, assuming \r\n\\begin{itemize}\r\n\\item the mass of the block is $m$ kg, and\r\n\\item the spring constant (in $N/m$) is\r\n  given by the constant $k$.\r\n\\end{itemize}\r\n\r\n\\newpage\r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\nLet us work with our intuition about this system before beginning the mathematics.\r\n\r\n\\problem If the spring is very stiff, is $k$ large or small?  \\vfill\r\n\r\n\\newpage \r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\n{\\bf Definition:}: {\\em Period} is the length of time to\r\ncomplete one full cycle/oscillation.  \\vspace{0.2in}\r\n\r\n\\problem If we increase the stiffness of the spring, do you expect the\r\n{\\em period} of the oscillations to increase or decrease?  Why?\r\n\r\n\\vfill\r\n\r\nIf we increase the mass, do you expect\r\nthe \\emph{period} of the oscillations to increase or decrease? Why?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\n\\problem If we know $k$ and $m$, and assume that damping is\r\nnegligible, should we be able to determine the exact period of the\r\noscillations?  \\vfill\r\n\r\n\r\n\\vfill\r\n\r\nFrom the work so far, can we easily find the formula for the period?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\nThe spring system is an excellent introduction to higher-order differential equations because \r\n\\begin{itemize}\r\n\\item we all have an intuition about how it \\emph{should} work physically,\r\n\\item the mathematics and physics are simple, and\r\n\\item there's no obvious way to predict critical features (e.g. the\r\n  period) from the given information.\r\n\\end{itemize}\r\nWe clearly need some new tools!\r\n\r\n\\newpage\r\n\\topic{Spring System as a DE}\r\n\\subsection*{Spring System as a DE}\r\n\\begin{center}\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\n\\problem Use Newton's second law, $F = ma$, to construct an equation\r\ninvolving the position $x(t)$.  \\vfill\r\n\r\nWhat order of differential equation does $F=ma$ produce for this\r\nspring/mass system?\r\n\r\n\\vspace{1.3in}\r\n\r\n\\newpage\r\n\r\nTo simplify matters temporarily, let us assume that both\r\n  $k = 1 $ N/m and $m = 1$ kg. \r\n\r\n  \\problem Rewrite the previous differential equation using those\r\n  constants.  \\vspace{1.5in}\r\n\r\n  This differential equation invites us to find a function $x(t)$\r\n  whose second derivative is its own negative.  What function(s) would\r\n  satisfy that?  \\vfill\r\n\r\n\\newpage\r\n\r\n\\problem Having found two (and more) solutions to the differential\r\nequation for the spring/mass system, how does this family of solutions\r\nmap back to the spring system?\r\n\r\n\\begin{center}\r\n\\includegraphics[width=0.4\\linewidth]{graphics/notes_08_block}\r\n\\end{center}\r\n\r\n\\vfill\r\n\r\nIs our solution an exact or a numerical solution?\r\n\\vspace{1.3in}\r\n\r\n\r\n\\newpage\r\n\r\n\r\n\\topic{Mechanical Vibrations - Spring-Mass Wystem}\r\n\\section*{Mechanical Vibrations - Spring-Mass System}\r\n\r\nWe now consider an extension to the spring/mass system.\r\n\r\nConsider a mass $m$ hanging on the end of a vertical spring; the\r\nspring has a naturally stretched length corresponding to $x=0$.\r\n\r\nWe have now added a damper, which exerts a force proportional to the\r\nvelocity of the oscillating mass.\r\n\r\n\r\n\\includegraphics[width=0.4\\linewidth]{graphics/notes_08_hanging_mass}\r\n\r\n\\newpage\r\n\r\n\\problem Using Newton's second law, build a differential equation that\r\ngoverns the system.\r\n\r\n\\includegraphics[width=0.35\\linewidth]{graphics/notes_08_hanging_mass}\r\n\r\n\r\n% \\begin{itemize}\r\n% \\item Gravity acts downward and has a magnitude of $mg$ where $g$ is the\r\n%   acceleration due to gravity; $F_g = mg$.\r\n% \\item The spring acts upward and, by Hooke's law, has a magnitude proportional\r\n%   elongation.  If $y$ represents the displacement of the mass from the\r\n%   equilibrium position, then $F_s = -k(\\ell +y)$.\r\n% \\item Assuming that possible damping forces (i.e.\\ a dashpot) are directly\r\n%   proportional to the velocity of the mass, we have $F_d = - cy'$.\r\n% \\item There may be an external driving force $F(t)$.\r\n% \\end{itemize}\r\n% Summing the forces, we find that $m y'' = F_g + F_s + F_d + F(t) = mg -k(\\ell\r\n% +y) -cy' + F(t)$.  At equilibrium, we have $mg = k\\ell$ so the standard form of\r\n% the equation is\r\n% \\[\r\n% y'' + \\tfrac{c}{m} y' + \\tfrac{k}{m} y = \\tfrac{1}{m} F(t) \\, . \r\n% \\]\r\n\r\n\r\n\\newpage\r\n\\problem Consider a system with a mass of $0.5 \\; \\text{kg}$ with\r\nspring constant $k = 2 \\; \\text{N} \\cdot \\text{m}^{-1}$, with a\r\ndamping coefficient of $c = 0.5$ N/(m/s).  Assume the mass is\r\ndisplaced $0.4 \\; \\text{m}$ from equilibrium and released.\r\n\r\n\\problem Write the differential equation dictates the motion of the\r\nmass.\r\n\r\n\\vspace{1in}\r\n\r\nCan we find an easy solution to this differential equation as we did with the undamped\r\ncase?\r\n\\vfill\r\n\r\n\r\nCan MATLAB be used to build a numerical solution for the differential\r\nin its current form?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\r\n\\topic{Converting Higher-Order DEs to 1st Order Systems}\r\n\\subsection*{Converting Higher-Order DEs to 1st Order Systems}\r\nTo solve a higher-order DE using MATLAB, we need to convert it first\r\ninto a larger {\\bf first-order system} of differential equations.\r\n\r\n\r\n\\vspace{0.3in}\r\nNotation: In this section, \r\n\\begin{itemize} \r\n\\item vectors with be written with vector hats, e.g.\r\n  $\\vec{w}, \\vec{y}$,\r\n\\item elements of a vector will be noted with subscripts, e.g. $w_1$,\r\n  $y_2$, and\r\n\\item other scalars will be in lower-case, e.g. $c$, $\\lambda$.\r\n\\end{itemize}\r\n\r\n\\newpage\r\n\r\n\\begin{minipage}[t]{0.4\\linewidth}\r\n\\vspace{0pt}\r\nDamped Spring DE:\r\n\r\n$$ m x'' = -c x' -kx $$\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.6\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{center}\r\n\\includegraphics[width=0.5\\linewidth]{graphics/notes_08_hanging_mass}\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\\problem For the spring/mass DE, define a new vector of 2 variables,\r\n$\\vec{w}$, that will allow the conversion of the second-order system\r\nto a first-order system.\r\n\r\n\\vfill\r\n\r\nAlso see the MATLAB help menu entry on ``Ordinary Differential\r\nEquations'', referring to ``Higher Order ODEs''.\r\n\r\n\\newpage\r\n$$ m  x'' = -c x' -kx $$\r\n\\problem Define the derivative, $\\ds \\frac{d \\vec{w}}{dt}$, in terms\r\nof $\\vec{w}$ itself, making use of the DE as necessary.\r\n\r\n\\vfill\r\n\\vfill\r\n\r\nThis is now a {\\bf first-order system} of differential equations.  \\\\\r\nThe variable we are most interested in for this example is $w_1 = x$,\r\nthe {\\em position} of the mass.\r\n\r\n\\newpage\r\n\r\n\\topic{MATLAB Function Files}\r\n\\subsection*{MATLAB Function Files}\r\n\r\nOur differential equation is now sufficiently complicated that writing\r\nit out in one line is difficult.  We will need another MATLAB tool to\r\nproceed: a MATLAB function file.\r\n\r\n\r\n{\\bf Syntax} A MATLAB function file\r\n\\begin{itemize}\r\n\\item has as its first line the form \\\\\r\n\\verb#function ret = f(....)# \r\n\\item \\verb#ret# is the name of the {\\bf return variable} and must be\r\n  defined before the end of the function;\r\n\\item \\verb#f# should be the same as the filename, with the \\verb#.m# extension;\r\n\\item the \\verb#....# can be any list of input variables.\r\n\\end{itemize}\r\n\r\n\\newpage\r\n\\problem Define a new {\\bf MATLAB function \\texttt{.m} file} called\r\n\\verb#hypotenuse# that takes in two lengths, \\verb#a# and \\verb#b#,\r\nand returns the length of the hypotenuse for a right-angle triangle\r\nwith side lengths $a$ and $b$.\r\n\r\n\\newpage\r\n\\problem Define a new {\\bf MATLAB function \\texttt{.m} file} called\r\n\\verb#springDE# which computes the derivative of\r\n$\\ds \\frac{d \\vec{w}}{dt}$.\r\n\r\n\\begin{minipage}[t]{0.4\\linewidth}\r\n\\vspace{0pt}\r\n$$ m x'' = -c x' -kx $$\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.6\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{align*}\r\n  \\frac{dw_1}{dt} & = w_2 \\\\\r\n  \\frac{dw_2}{dt} & = \\left(\\frac{1}{m}\\right) (-c w_2 - k w_1)\r\n\\end{align*}\r\n\\end{minipage}\r\n\r\n\r\n\r\n\\newpage \r\n\\problem Write a MATLAB script that graphs the solution\r\n(i.e. predicted motion) for the system described earlier:\r\n\r\nA system with a mass of $0.5 \\; \\text{kg}$ with spring constant\r\n$k = 2 \\; \\text{N} \\cdot \\text{m}^{-1}$, with a damping coefficient of\r\n$c = 0.5$ N/(m/s).  Assume the mass is displaced $0.4 \\; \\text{m}$\r\nfrom equilibrium and released.\r\n\r\nInclude the graphical output from MATLAB on the next page.\r\n\r\n\\newpage\r\n\\hfill\r\n\\includegraphics[width=0.3\\linewidth]{graphics/notes_08_hanging_mass}\r\n\r\n\r\n\\newpage\r\n\\topic{Unforced Spring/Mass System - Patterns of Behaviour}\r\n\\subsection*{Unforced Spring/Mass System - Patterns of Behaviour}\r\n\r\nUsing MATLAB, we can now easily study the impact of different masses,\r\nspring constants, or damping strength on the behaviour of a\r\nspring/mass system.\r\n\r\n\\begin{minipage}[t]{0.4\\linewidth}\r\n\\vspace{0pt}\r\nDamped Spring DE:\r\n\r\n$$ m x'' = -c x' -kx $$\r\n\\end{minipage}\r\n\\begin{minipage}[t]{0.6\\linewidth}\r\n\\vspace{0pt}\r\n\\begin{center}\r\n\\includegraphics[width=0.5\\linewidth]{graphics/notes_08_hanging_mass}\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\\newpage\r\n\r\nA famous result in physics captures important differences in behaviour\r\ndepending on the relationship between $c$, $k$ and $m$.\r\n\\begin{itemize}\r\n\\item $c$ is 0, the system will be {\\bf undamped};\r\n\\item $c$ is {\\bf less} than $\\sqrt{4km}$, the system will be {\\bf under-damped};\r\n\\item $c$ is {\\bf equal} to $\\sqrt{4km}$, the system will be {\\bf\r\n    critically damped};\r\n\\item $c$ is {\\bf greater} than $\\sqrt{4km}$, the system will be {\\bf\r\n    over-damped};\r\n\\end{itemize}\r\n\r\n\\problem Using a spring constant of $k = 25$ N/m and mass $m = 1$ kg,\r\nfind the critical damping level.\r\n\r\n\\newpage\r\n\\problem Use MATLAB to obtain graphs for all four spring/mass cases.\r\n\r\n  \\begin{minipage}[h]{0.475\\linewidth}\r\n    \\begin{center}\r\n      \r\n   \\vspace{0pt} \r\n   \\includegraphics[width=0.9\\linewidth]{graphics/notes_08_spring_mass_axes}\\\\\r\nUndamped \r\n\r\n\\hrulefill\r\n\r\n   \\includegraphics[width=0.9\\linewidth]{graphics/notes_08_spring_mass_axes}\\\\\r\nCritically Damped\r\n    \\end{center}\r\n  \\end{minipage}\r\n  \\begin{minipage}[h]{0.475\\linewidth}\r\n    \\begin{center}\r\n      \r\n   \\vspace{0pt} \r\n   \\includegraphics[width=0.9\\linewidth]{graphics/notes_08_spring_mass_axes}\\\\\r\nUnder-Damped  \r\n\r\n\\hrulefill\r\n\r\n   \\includegraphics[width=0.9\\linewidth]{graphics/notes_08_spring_mass_axes}\\\\\r\nOver-Damped\r\n    \\end{center}\r\n  \\end{minipage}\r\n\r\n\\newpage\r\n\\topic{Spring/Mass with Periodic External Forces }\r\n\\subsection*{Spring/Mass with Periodic External Forces }\r\n\r\nWe now add another component to our spring system model: \\\\{\\bf\r\n  external forces}.\r\n\r\n \\includegraphics[width=0.25\\linewidth]{graphics/notes_08_hanging_mass}\r\n\r\n \\problem Write out the DE for the position of the mass, given the\r\n addition now of an external force, given by\r\n $F_{\\mbox{ext}} = A \\sin(Bt)$.  \\vfill\r\n\r\nWhat are analogous systems to this that you might have encountered\r\nbefore?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\problem Write a MATLAB script and a function that will let you\r\nsimulate the motion of the mass given an external force of the form\r\n$F_{\\mbox{ext}} = A \\sin(Bt)$.\r\n\r\n$$m x'' = -kx -c x' + A \\sin(Bt)$$\r\n\r\n\\vfill\r\n\r\nOnce you have the MATLAB code written, we can explore the solutions\r\nof/predictions for the spring/mass system for different scenarios, by\r\nchanging parameters in our MATLAB script.\r\n\r\n\\newpage\r\n\r\n\\topic{Simulations of the Forced Spring/Mass System}\r\n\\subsection*{Simulations of the Forced Spring/Mass System}\r\n\r\nFor the following systems, use $m = 1$ kg and $k = 25$ N/m, unless\r\notherwise specified.\r\n\r\n{\\bf Unforced Motion}\r\n\r\n\\problem Setting $F_{\\mbox{ext}} = 0$, review the effect of increasing\r\nthe damping coefficient $c$ on the behaviour of the mass.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n{\\bf Forced, but Undamped Motion}\r\n\r\nNow we turn off the damping (by setting $c=0$) to zero, and\r\nstart to apply the external force. \\\\\r\n\\problem Set $F_{\\mbox{ext}} = 10 \\sin(1.0 t)$ and display a graph of the resulting oscillations.   \\\\\r\n\r\n\\vfill\r\n\r\nExperiment with the frequency in $\\Fe$, in the range 0.5 to 3, or well\r\nabove 5.  Does the motion of the mass over time make sense?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\topic{Simulations - Resonance, Near-Resonance and Practical Resonance}\r\n\r\n{\\bf Resonance}\r\n\r\nIn unforced, undamped systems, there is a {\\bf natural frequency} for\r\nthe mass, given by $\\omega = \\sqrt{\\frac{k}{m}}$.\r\n\r\n\\problem Set $\\Fe = 1 \\sin(5t)$.  What is special about the frequency\r\n5 rad/s?\r\n\r\n\\vfill\r\n\r\nDescribe the graph of the solution.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\nGive the physical reasons for the graph seen in the\r\nsimulation.\\\\\r\n\r\n\\vfill\r\n\r\nThe condition of having the external force at {\\em exactly} the same\r\nfrequency as the natural vibrations is called {\\bf resonance.}  Note:\r\nfor true resonance, there must be {\\em no damping.}\r\n\r\n\\newpage\r\n\r\n{\\bf Near-Resonance}\r\n\r\nAdmittedly, resonance is a unique event requiring {\\bf perfect}\r\nmatching of the stimulating force with the natural frequency.\r\n\r\n\\problem Explore frequencies in $\\Fe$ {\\em close to} 5.  Describe the\r\nresulting solutions, both for their amplitude and any other response.\r\n\r\n\\vfill\r\n\r\nGive a physical reason for the shape of the graph for near-resonance\r\nresponse.\r\n\r\n\\vfill\r\n\r\nNote again that there is {\\em no damping} with this response.\r\n\r\n\\newpage\r\n\r\n{\\bf Adding in Friction - Practical Resonance}\r\n\r\nSet $F_{\\mbox{ext}} = 1 \\sin(5t)$ again, but set damping $c$ to 0.1.\r\n\r\n\\problem Compare this solution to the one without damping.\r\n\r\n\\vfill\r\n\r\nGradually increase the amount of damping.  Describe how the solution\r\nchanges.\r\n\r\n\\vfill\r\n\r\nHow is this more realistic than the undamped case?\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\topic{Transient and Steady-State Solutions}\r\n\\subsection*{Transient and Steady-State Solutions}\r\n\r\nMore generally, when there is damping in the spring/mass system and an\r\noscillatory external force, we can break the solution into two parts:\r\n{\\em transient} and {\\em steady state}.\r\n\r\n\\problem Set $F_{\\mbox{ext}} = 1 \\sin(t)$, and $c = 1$ for damping,\r\nwhich is fairly high for an oscillating system.  Describe the\r\nresulting behaviour.\r\n\r\n\\vfill\r\n\r\nDescribe specifically the {\\bf long run} behaviour.\r\n\r\n\\vfill\r\n\r\n\\newpage\r\n\r\n\\problem Describe an analogous physical scenario where you might have\r\nobserved transient oscillations transitioning into steady state\r\noscillations.\r\n\r\n\r\n\r\n\\newpage\r\n\r\nReminder: we study the simple damped spring/mass system in such depth\r\nbecause\r\n\\begin{itemize}\r\n\\item the system displays all the interesting mathematical solution\r\n  forms as we vary just a few parameters, \r\n\\item we hope that the simplicity of the system, and its resemblance\r\n  to familiar systems like swings or car shock absorbers, help to you\r\n  associate the mathematics with the real-world behaviour.\r\n\\item the DE for the spring/mass system is either identical or similar\r\n  to those for a surprising number of other real-world scenarios.\r\n\\end{itemize}\r\n\r\n\r\n\r\n\\newpage\r\n\r\n\\topic{Classifying Higher-Order DEs}\r\n\\subsection*{Classifying Higher-Order DEs}\r\n\r\nWhile working with DEs in MATLAB, we haven't had to distinguish\r\nbetween types of equations: so long as they can be re-written in the\r\nform $\\ds \\frac{dy}{dt} = f(t, y)$, or the vector form\r\n$\\ds \\frac{d\\vec{w}}{dt} = f(t, \\vec{w})$, MATLAB can produce a\r\nnumerical solution or prediction. \\\\[1ex]\r\n\r\nHowever, when looking at references or mathematical derivations, where\r\nDEs are solved exactly using by-hand methods, the method used is\r\nusually chosen based on the form of the DE, so being able to\r\ncategorize equations is a helpful skill.\r\n\r\n\\newpage\r\n\r\n\\problem Distinguish between the following classifications of\r\ndifferential equations, and given an example of each.\r\n\r\n{\\bf Linear vs Non-Linear}\r\n\\vfill\r\n\r\n{\\bf Linear Homogeneous and Linear Non-Homogeneous}\r\n\\vfill\r\n\r\n\r\n \r\n\r\n\\newpage \r\nClassify the following DEs based on the terms {\\em order}, {\\em\r\n  homogeneous} and {\\em linear}.\r\n\r\n\\vfill\r\n\r\n$x^2 y'' + x y' + y = 10$ \\vfill\r\n\r\n $ 100 y'' +  y = 4x^3$\r\n \\vfill\r\n\r\n $ (y'')^3 + y = 4 e^{x}$\r\n \\vfill\r\n\r\n $ 4 y^{(4)} - 10 y' + y = 0 $ \\vfill\r\n\r\n\r\n\\end{document}\r\n\r\n\r\n", "meta": {"hexsha": "3f91342483378948a2362be468a1969caed666bf", "size": 20979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/notes08.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": "Notes/notes08.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": "Notes/notes08.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": 27.4594240838, "max_line_length": 108, "alphanum_fraction": 0.7107107107, "num_tokens": 5839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6143266777336749}}
{"text": "\\documentclass[11pt,american,usenames,dvipsnames,svgnames,x11names,table]{article}\n\\input{../tex/portrait-1col}\n%\\input{../tex/landscape-2col}\n\\input{../tex/head}\n\\input{../tex/symbols}\n\\begin{document}\n\\input{../tex/clj-listings} \n\n\n\\title{Regression costs for decision trees}\n\n\n\\author{\\textsc{John Alan McDonald }}\n\n\n\\date{\\today}\n\\maketitle\n\nThe purpose of this document is work thru an alternative to $L_2$ cost\nthat is a bit more efficient to compute, and gives the same results when\nchoosing split predicates in decision tree growing.\n\n\\section{\\label{sub:Decision-trees}Greedy decision trees}\n\nA general binary decision tree consists of \n\\begin{itemize}\n\\item internal \\emph{split} nodes, each containing a predicate that determines\nwhether a record goes to the left or right child of that node.\n\\item terminal \\emph{leaf} nodes, each containing a leaf model function\nwhose value is the tree's prediction for any record that ends up in\nthat node. \n\\end{itemize}\n\nGreedy split optimization --- choose the best out of all feasible\nsplits, and repeat on the resulting child nodes until there are no\nfeasible splits --- is the most common way of growing decision trees.\nIt depends on several things:\n\\begin{enumerate}\n  \\item A cost function $c$ used to define 'best'.  \n  \\item An enumeration of splits to consider. Pure greedy splitting\n  considers all 'feasible' splits on all attributes.\n  \\begin{enumerate} \n    \\item For categorical attributes, that, in general, means considering every \n    partition of the categories into $2$ subsets. However, for some\n    important cost functions (eg Gini, $L_2$), it can be shown that the\n    optimal split can be found by sorting the categories by the\n    corresponding score function (eg the response mean for $L_2$ cost),\n    and then considering only splits by score.\n    \\item For numerical attributes, the most general split would come\n    from treating the distinct values like the categories of a\n    categorical variable. However, no one does that, mostly because\n    there are usually too many distinct values. Instead, only splits by\n    $\\leq$ vs $>$ one of the distinct values are considered.\n\\end{enumerate}\n\\item A feasibility test that determines whether a given split on a\ngiven attribute is allowed. The most common case here is to require both\nchildren of the split contain some minimum number of training records.\n\\end{enumerate}\n\n\\section{\\label{sec:numerical}Cost functions for $L_2$ numerical\nregression}\n\nLet $\\mathcal{T} = \\{ \\left( y,\\mathbf{x} \\right) \\}$ be the training\ndata in the node to be split.\nIt is a set of pairs of predictor record $\\mathbf{x}$ and ground truth\nresponse $y$, where $y\\in\\mathbb{R}$ for numerical regression.\nWe are considering splits on some particular predictor field $x_k$,\nwhich might be numerical or categorical.\n\nThe cost function for $L_2$ regression is the sum of squared deviations\nfrom the mean: \n\n$L_{2}\\left(\\mathcal{T}\\right)\n= \\sum_{y\\in\\mathcal{T}}\\,\\left(y-\\bar{y}_{\\mathcal{T}}\\right)^{2}$,\nwhere $\\bar{y}_{\\mathcal{T}}\n= \\frac{1}{\\#\\mathcal{T}}\\sum_{y\\in\\mathcal{T}}\\,y$.\n\nNote that computing this \\textit{accurately}, in an online fashion, for\nmoderate $\\#\\mathcal{T}$, the number of records in $\\mathcal{T}$, allowing for\nthe updating/downdating needed for fast split optimization, \nrequires some care. \n\nHowever, a little bit of algebra will let us use a simpler alternative\nto get the same splits. \n\n\nAny split partitions the training y-values\n$\\mathcal{T=}\\left\\{ y\\right\\} $ into left and right subsets: \n$\\mathcal{T}=\\mathcal{L}\\uplus\\mathcal{R}$.\nThe split cost is:\n\n\\begin{align*}\nc\\left(\\mathcal{L},\\mathcal{R}\\right)= & L_{2}\\left(\\mathcal{L}\\right)\n+ L_{2}\\left(\\mathcal{R}\\right)\\\\\n= & \\sum_{y\\in\\mathcal{L}}\\,\\left(y-\\bar{y}_{\\mathcal{L}}\\right)^{2}+\\sum_{y\\in\\mathcal{R}}\\,\\left(y-\\bar{y}_{\\mathcal{R}}\\right)^{2}\\\\\n= & \\sum_{y\\in\\mathcal{L}}\\left[y^{2}-2\\bar{y}_{\\mathcal{L}}y+\\bar{y}_{\\mathcal{L}}^{2}\\right]+\\sum_{y\\in\\mathcal{R}}\\left[y^{2}-2\\bar{y}_{\\mathcal{R}}y+\\bar{y}_{\\mathcal{R}}^{2}\\right]\\\\\n= & \\sum_{\\mathcal{L}\\uplus\\mathcal{R}}y^{2}-\\frac{\\left(\\sum_{\\mathcal{L}}y\\right)^{2}}{\\#\\mathcal{L}}-\\frac{\\left(\\sum_{\\mathcal{R}}y\\right)^{2}}{\\#\\mathcal{R}}\n\\end{align*}\n\nSince $\\sum_{\\mathcal{L}\\uplus\\mathcal{R}}y^{2}$ doesn't depend on\nthe split, minimizing $c\\left(\\mathcal{L},\\mathcal{R}\\right)$ is\nequivalent to minimizing $-\\left[\\frac{\\left(\\sum_{\\mathcal{L}}y\\right)^{2}}{\\#\\mathcal{L}}+\\frac{\\left(\\sum_{\\mathcal{R}}y\\right)^{2}}{\\#\\mathcal{R}}\\right]$,\nso we can use $\\frac{-\\left(\\sum_{\\mathcal{T}}y\\right)^{2}}{\\#\\mathcal{T}}$\nas our cost function in split optimization.\n\n\\section{Cost functions for $L_2$ vector-valued regression}\n\nLet $\\mathcal{T} = \\{ \\left( \\mathbf{y}, \\mathbf{x} \\right) \\}$ be the\ntraining data in the node to be split.\nHere the ground truth response $\\mathbf{y}$ is a vector, \n$\\mathbf{y}\\in\\mathbb{R}^m$, rather than a single number.\n\nThe cost function for $L_2$ vector-valued regression is the sum of\nsquared $L_2$ distances from the mean vector: \n\\begin{align*}\nL_{2}\\left(\\mathcal{T}\\right) \n= &\n\\sum_{y\\in\\mathcal{T}}\\,\\|\\mathbf{y}-\\bar{\\mathbf{y}}_{\\mathcal{T}}\\|_{2}^{2}\\\\\n= &\n\\sum_{y\\in\\mathcal{T}}\\sum_{i=0}^{m-1}\\,\\left(y_i-\\bar{y_i}_{\\mathcal{T}}\\right)^{2}\n\\end{align*}\n\nFollowing the same reasoning as in section~\\ref{sec:numerical}, we get\nfor a simpler cost:\n$$\nc\\left(\\mathcal{L},\\mathcal{R}\\right) = \n-\\left[\n\\frac{\n\\sum_{i=0}^{m-1} \\, \\left(\\sum_{\\mathcal{L}}y_i\\right)^{2}}\n{\\#\\mathcal{L}}\n\\; + \\;\n\\frac{\\sum_{i=0}^{m-1} \\,\n\\left(\\sum_{\\mathcal{R}}y_i\\right)^{2}}{\\#\\mathcal{R}}\\right] \n$$\n\n%\\bibliographystyle{plainurl}\n%\\bibliography{bib,cactus}\n\n\\end{document}\n", "meta": {"hexsha": "fb2dd76c283b346639d7b1a07176147b33bbd179", "size": 5665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/regression-cost/regression-cost-xelatex.tex", "max_stars_repo_name": "wahpenayo/taiga", "max_stars_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-02T01:14:37.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-30T14:29:40.000Z", "max_issues_repo_path": "doc/regression-cost/regression-cost-xelatex.tex", "max_issues_repo_name": "wahpenayo/taiga", "max_issues_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-10-24T18:35:41.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-24T18:35:41.000Z", "max_forks_repo_path": "doc/regression-cost/regression-cost-xelatex.tex", "max_forks_repo_name": "wahpenayo/taiga", "max_forks_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "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.4642857143, "max_line_length": 187, "alphanum_fraction": 0.7085613416, "num_tokens": 1798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324607730178, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6142920415195784}}
{"text": "\\chapter{Mappings between endofuncoids and topological spaces}\n\nOreder topologies reversely to set-theoretic inclusion. That is\nfor topologies~$t$ and~$s$ we set\n$t\\sqsubseteq s\\Leftrightarrow t\\supseteq s$. (Intuitively:\nThe less is the topology, the lesser are its open sets.)\n\nLet's study mappings between topological spaces and endofuncoids.\n\n\\begin{defn}\n  Let $t$ be a topology.\n  \\begin{enumerate}\n    \\item $F^{\\fullstar} t = \\bigsqcup_{x \\in \\Ob t} \\left( \\{ x \\} \\times\n    \\bigsqcap^{\\mathscr{F}} \\setcond{ E \\in t }{ x \\in\n    E } \\right)$;\n    \n    \\item $(F_{\\fullstar} t) E = \\bigcap \\setcond{ D \\in t }{ E \\subseteq D }$.\n  \\end{enumerate}\n\\end{defn}\n\n\\begin{prop}\n  Let $t$ be a topology.\n  \\begin{enumerate}\n    \\item $F^{\\fullstar} t$ is complete, reflexive, transitive funcoid.\n    \n    \\item $F_{\\fullstar} t$ is co-complete, reflexive, transitive funcoid.\n    \n    \\item $F^{\\fullstar}$ and $F_{\\fullstar}$ are injections.\n    \n    \\item $F_{\\fullstar} t = (F^{\\fullstar} t)^{- 1}$.\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  By theorem~\\bookref{top-two}.\n\\end{proof}\n\n\\begin{defn}\n  Let $f$ be an endofuncoid.\n  \\[ T f = \\setcond{ E \\in \\subsets \\Ob f }{\n     \\forall x \\in E : \\supfun{f} \\{ x \\} \\sqsubseteq E } . \\]\n\\end{defn}\n\n\\begin{prop}\n  $T f$ is a topology.\n\\end{prop}\n\n\\begin{proof}\n  \n  \\begin{description}\n    \\item[Union of open sets is open] $S \\subseteq T f \\Rightarrow \\forall E\n    \\in S \\forall x \\in E : \\supfun{f} x \\sqsubseteq E \\Rightarrow\n    \\forall x \\in \\bigcup S : \\supfun{f} x \\sqsubseteq \\bigcup S$\n    \n    \\item[Intersection of two open sets is open] Let $X, Y \\in T f$. Then\n    $\\forall x \\in X : \\supfun{f} x \\sqsubseteq X$ and $\\forall x \\in Y\n    : \\supfun{f} x \\sqsubseteq Y$. So if $x \\in X \\cap Y$ then $\\langle\n    f \\rangle x \\sqsubseteq X$ and $\\supfun{f} x \\sqsubseteq Y$, so\n    $\\supfun{f} x \\sqsubseteq X \\cap Y$. So $X \\cap Y \\in T f$.\n    \n    \\item[$\\Ob f$ is an open set] Obvious.\n  \\end{description}\n\\end{proof}\n\n\\begin{obvious}\n$T f = \\setcond{ E \\in \\subsets \\Ob f }{ \\langle\n\\Compl f \\rangle E \\sqsubseteq E }$.\n\\end{obvious}\n\nIn some reason when starting this research I assumed that the\nfollowing funcoid (for every endofuncoid~$f$) is a Kuratowski closure:\n\\[\n1 \\sqcup \\CoCompl f \\sqcup (\\CoCompl f)^2 \\sqcup \\ldots.\n\\]\nIt is not true:\n\n\\begin{example}\nThere exists such a co-complete endofuncoid~$f$ that\n$1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots$ is not transitive that\nis\n\\[(1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots)\\circ\n(1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots) \\ne\n1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots\n\\]\n\\end{example}\n\n\\begin{proof}\nTake $f=\\cl\\circ g$ where $g$ is the principal funcoid which maps\nevery real number~$a$ into the closed interval\n$\\left[ \\frac{- 1 - | a |}{2} ; \\frac{1 + | a |}{2} \\right]$.\n\nTake $X = \\left[ - \\frac{1}{2} ; \\frac{1}{2} \\right]$. $\\langle f^n\n\\rangle^{\\ast} X = \\left[ - 1 + \\frac{1}{2^{n + 1}} ; 1 - \\frac{1}{2^{n + 1}}\n\\right]$.\n\nWe have $\\langle 1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots \\rangle^{\\ast} X =] - 1 ;\n1 [$;\n\n$\\langle 1 \\sqcup f \\sqcup f^2 \\sqcup \\ldots \\rangle^{\\ast} \\langle 1 \\sqcup f\n\\sqcup f^2 \\sqcup \\ldots \\rangle^{\\ast} X = [- 1 ; 1]$.\n\nThus follows our inequality.\n\\end{proof}\n\nThat $F^{\\star}$ and $F_{\\star}$ are functors (if we map morphisms to\nthemselves except of changing the objects) follows from\nconjecture~\\bookref{top-cont}.\n\n\\begin{thm}\n$T$ (if we map morphisms to\nthemselves except of changing the objects) is a functor.\n\\end{thm}\n\n\\begin{proof}\n  Based on \\url{https://math.stackexchange.com/a/2792239/4876}\n\n  Let $f : \\mu \\rightarrow \\nu$ that is $f \\circ \\mu \\sqsubseteq \\nu \\circ f$.\n  We need to prove $f : T \\mu \\rightarrow T \\nu$ that is $E \\in T \\nu\n  \\Rightarrow \\langle f^{- 1} \\rangle^{\\ast} E \\in T \\mu$.\n\n  Suppose $E \\in T \\nu$ that is $\\langle \\nu \\rangle^{\\ast} E \\sqsubseteq E$.\n  We will prove $\\langle \\mu \\rangle^{\\ast} \\langle f^{- 1} \\rangle^{\\ast} E\n  \\sqsubseteq \\langle f^{- 1} \\rangle^{\\ast} E$.\n\n  \\fxnote{Can we use arbitrary filters rather than atoms?}\n\n  Really, let atom $y \\sqsubseteq \\langle \\mu \\rangle^{\\ast} \\langle f^{- 1}\n  \\rangle^{\\ast} E$. Then there exists atom $x \\sqsubseteq \\langle f^{- 1}\n  \\rangle^{\\ast} E$ such that $x \\mathrel{[\\mu]^{\\ast}} y$.\n\n  $x \\mathrel{[f \\circ \\mu]^{\\ast}} \\langle f \\rangle y$ and thus $x\n  \\mathrel{[\\nu \\circ f]^{\\ast}} \\langle f \\rangle y$, so $\\langle f \\rangle x\n  \\mathrel{[\\nu]^{\\ast}} \\langle f \\rangle y$. But $\\langle f \\rangle x\n  \\sqsubseteq E$, so $\\langle f \\rangle y \\sqsubseteq \\langle \\nu\n  \\rangle^{\\ast} E \\sqsubseteq E$, that is $\\langle \\mu \\rangle^{\\ast} \\langle\n  f^{- 1} \\rangle^{\\ast} E \\sqsubseteq E$.\n\\end{proof}\n\n\\begin{prop}\n  $f \\in \\mathrm{C} (\\mu, \\nu) \\Rightarrow f \\in \\mathrm{C} (\\mu^n, \\nu^n)$\n  for every endofuncoids $\\mu$ and $\\nu$ and positive natural\n  number~$n$.\n  \\fxnote{Move this proposition to the book.}\n\\end{prop}\n\n\\begin{proof}\n  $f \\circ \\mu \\sqsubseteq \\nu \\circ f$; $f \\circ \\mu \\circ \\mu \\sqsubseteq\n  \\nu \\circ f \\circ \\mu$; $f \\circ \\mu^2 \\sqsubseteq \\nu^2 \\circ f$; $f \\circ\n  \\mu^3 \\sqsubseteq \\nu^3 \\circ f$...\n\\end{proof}\n\n\\begin{prop}\n  For every endofuncoid $\\mu$:\n  \\begin{enumerate}\n    \\item $F_{\\fullstar} T \\mu \\sqsupseteq \\Compl \\mu$;\n    \\item $F^{\\fullstar} T \\mu \\sqsupseteq \\Compl \\mu$;\n    \\item $F_{\\fullstar} T \\mu \\sqsupseteq \\CoCompl \\mu$;\n    \\item $F^{\\fullstar} T \\mu \\sqsupseteq \\CoCompl \\mu$;\n  \\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\n  We will prove only the first two as the rest are dual.\n  \n  $\\langle F_{\\fullstar} T \\mu \\rangle^{\\ast} E =\n  \\bigcap \\setcond{ D \\in T \\mu\n  }{ D \\supseteq E } = \\bigcap \\setcond{ D \\in\n  \\subsets \\Ob \\mu }{ \\langle \\Compl\n  \\mu \\rangle^{\\ast} D \\sqsubseteq D \\wedge D \\supseteq E } \\sqsupseteq\n  \\bigsqcap \\setcond{ \\langle \\Compl \\mu \\rangle^{\\ast} D }{\n  D \\in \\subsets \\Ob \\mu, \\langle \\Compl \\mu\n  \\rangle^{\\ast} D \\sqsubseteq D \\wedge D \\supseteq E } \\sqsupseteq\n  \\langle \\Compl \\mu \\rangle^{\\ast} E$.\n  \n  $\\langle F^{\\fullstar} T \\mu \\rangle^{\\ast} \\{ x \\} = \\bigsqcap^{\\mathscr{F}}\n  \\setcond{ E \\in T \\mu }{ x \\in E } =\n  \\bigsqcap^{\\mathscr{F}} \\setcond{ E \\in \\Ob \\mu }{\n  x \\in E, \\left\\langle \\Compl \\mu \\right\\rangle^{\\ast} E\n  \\sqsubseteq E } \\sqsupseteq \\bigsqcap^{\\mathscr{F}} \\setcond{ \\langle\n  \\Compl \\mu \\rangle^{\\ast} E }{ E \\in \\Ob\n  \\mu, x \\in E, \\langle \\Compl \\mu \\rangle^{\\ast} E \\sqsubseteq E }\n  \\sqsupseteq \\langle \\Compl \\mu \\rangle^{\\ast} \\{ x \\}$.\n\\end{proof}\n\n\\begin{lem}\n  For every endofuncoid $\\mu$:\n  \\begin{enumerate}\n    \\item $F_{\\fullstar} T \\mu \\sqsubseteq 1 \\sqcup \\Compl \\mu \\sqcup\n    (\\Compl \\mu)^2 \\sqcup \\ldots$;\n    \n    \\item $F^{\\fullstar} T \\mu \\sqsubseteq 1 \\sqcup \\CoCompl \\mu \\sqcup\n    (\\CoCompl \\mu)^2 \\sqcup \\ldots$\n  \\end{enumerate}\n\\end{lem}\n\n\\begin{proof}\n  We will prove only the first as the second is dual.\n  \n  $\\langle 1 \\sqcup \\Compl \\mu \\sqcup (\\Compl \\mu)^2 \\sqcup \\ldots\n  \\rangle^{\\ast} E = E \\sqcup \\langle \\Compl \\mu \\rangle^{\\ast} E \\sqcup\n  \\langle (\\Compl \\mu)^2 \\rangle^{\\ast} E \\sqcup \\ldots$\n  \n  Take $D = E \\sqcup \\langle \\Compl \\mu \\rangle^{\\ast} E \\sqcup \\langle\n  (\\Compl \\mu)^2 \\rangle^{\\ast} E \\sqcup \\ldots$ We have $\\langle\n  \\Compl \\mu \\rangle^{\\ast} D \\sqsubseteq \\langle \\Compl \\mu\n  \\rangle^{\\ast} E \\sqcup \\langle (\\Compl \\mu)^2 \\rangle^{\\ast} E \\sqcup\n  \\ldots \\sqsubseteq D$. So\n  \n  $\\bigcap \\setcond{ D \\in \\subsets \\Ob \\mu }{\n  \\langle \\Compl \\mu \\rangle^{\\ast} D \\sqsubseteq D \\wedge D \\supseteq E\n  } \\subseteq D \\sqsubseteq \\langle 1 \\sqcup \\Compl \\mu \\sqcup\n  (\\Compl \\mu)^2 \\sqcup \\ldots \\rangle^{\\ast} E$.\n\\end{proof}\n\n\\begin{thm}\n  If we restrict the functor $T$ only to complete endofuncoids (=~complete\n  endoreloids), then $T$ is a left adjoint of both $F_{\\fullstar}$ and\n  $F^{\\fullstar}$.\n\\end{thm}\n\n\\begin{proof}\n  We will prove only for $F_{\\fullstar}$ as the other is dual.\n  \n  We will disprove $f \\in \\mathrm{C} (T \\mu, s) \\Leftrightarrow f \\in\n  \\mathrm{C} (\\mu, F_{\\fullstar} s)$ what is equivalent (because $F_{\\fullstar}$ is\n  full and faithful) to\n  \\[ f \\in \\mathrm{C} (F_{\\fullstar} T \\mu, F_{\\fullstar} s) \\Leftrightarrow f \\in\n     \\mathrm{C} (\\mu, F_{\\fullstar} s) ; \\]\n  $F_{\\fullstar} T \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f\n  \\Leftrightarrow \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f$.\n  \n  $F_{\\fullstar} T \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f \\Rightarrow\n  \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f$ because $F_{\\fullstar} T \\mu\n  \\sqsupseteq \\mu$.\n  \n  If $\\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f$ then $\\mu^n\n  \\sqsubseteq f^{- 1} \\circ (F_{\\fullstar} s)^n \\circ f = f^{- 1} \\circ F_{\\fullstar}\n  s \\circ f$. Also obviously $1 \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ\n  f$. Thus\n  \\[ 1 \\sqcup \\mu \\sqcup \\mu^2 \\sqcup \\ldots \\sqsubseteq f^{- 1} \\circ\n     F_{\\fullstar} s \\circ f \\]\n  and so $1 \\sqcup \\Compl \\mu \\sqcup (\\Compl \\mu)^2 \\sqcup \\ldots\n  \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f$. So $F_{\\fullstar} T \\mu\n  \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ F$.\n\\end{proof}\n\n\\fxnote{$F$ and $T$ are also a Galois connection, isn't it?}\n\n\\begin{example}\n  $T$ is a not left adjoint of both $F_{\\star}$ and $F^{\\star}$, with bijection\n  which preserves the ``function'' part of the morphism.\n\\end{example}\n\n\\begin{proof}\n  We will disprove only from $F_{\\fullstar}$ as the other is dual.\n  \n  We will disprove $f \\in \\mathrm{C} (T \\mu, s) \\Leftrightarrow f \\in \\mathrm{C}\n  (\\mu, F_{\\fullstar} s)$ what is equivalent\n  (because $F_{\\star}$ is full and faithful) to\n  \\[ f \\in \\mathrm{C} (F_{\\fullstar} T \\mu, F_{\\fullstar} s) \\Leftrightarrow f \\in\n     \\mathrm{C} (\\mu, F_{\\fullstar} s) ; \\]\n  $F_{\\fullstar} T \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f\n  \\Leftrightarrow \\mu \\sqsubseteq f^{- 1} \\circ F_{\\fullstar} s \\circ f$.\n  \n  This equivalence does not hold: Take $s$ the discrete space\n  on~$\\mathbb{R}$, $f=\\id_{\\mathbb{R}}$, and\n  $\\rsupfun{\\mu}X=X$ for finite sets~$X$ and $\\rsupfun{\\mu}X=\\top$\n  for infinite~$X$.\n\\end{proof}\n", "meta": {"hexsha": "f7ef077c610d0f17bf6a7ab1f2058612ba8df540", "size": 10015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-fcd-top.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-fcd-top.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-fcd-top.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "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.0925925926, "max_line_length": 85, "alphanum_fraction": 0.6261607589, "num_tokens": 3908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.614292031074603}}
{"text": "\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/notespreamble.tex\"}\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/extrapackages.tex\"}\n\\input{\"/Users/brandonwilliams/Documents/LaTeX Includes/extracommands.tex\"}\n\n\n\n\\begin{document}\n\n\n\\title{Homotopy Theory}\n\\author{Brandon Williams \\\\ \\texttt{mbw@math.sunysb.edu}}\n\\maketitle\n\n\n\n\\tableofcontents\n\n\n\n\n\n\n\n\\newpage\n\\section{Some Category Theory}\n\n\nA \\textbf{category} $\\mathscr C$ consists of a class of \\textbf{objects}, also denoted by $\\mathscr C$, a class of \\textbf{morphisms} $\\hom_{\\mathscr C}(X,Y)$ for any two objects $X$ and $Y$, and a binary operation $\\hom_{\\mathscr C}(X,Y) \\times \\hom_{\\mathscr C}(Y,Z) \\rightarrow \\hom_{\\mathscr C}(X,Z)$ called \\textbf{composition} and denoted by $(f,g) \\mapsto g \\circ f$, such that the following holds:\n\\begin{enumerate}\n\t\\item For morphisms $f \\in \\hom_{\\mathscr C}(X,Y), g \\in \\hom_{\\mathscr C}(Y,Z)$ and $g \\in \\hom_{\\mathscr C}(Z,W)$ we have associativity composition: $h \\circ (g \\circ f) = (h \\circ g) \\circ f$. \n\t\\item For each object $X$ there is a unique morphism $\\id_X \\in \\hom_{\\mathscr C}(X,X)$ such that for any morphism $f \\in \\hom_{\\mathscr C}(X,Y)$ we have $f \\circ \\id_X = f = \\id_Y \\circ f$.\n\\end{enumerate}\nWe will usually write $f : X \\rightarrow Y$ or $X \\stackrel{f}{\\rightarrow} Y$ as a shorthand for saying that $f$ is a morphism from $X$ to $Y$, and when the category $\\mathscr C$ is clear from context we will write $\\hom(X,Y)$ to denote the class of morphisms. A \\textbf{small category} is one in which the objects and morphisms are sets, and a \\textbf{locally small category} is one in which the morphisms are sets. The \\textbf{opposite} of a category $\\mathscr C$ is a category $\\mathscr C^\\op$ with the same objects, but $\\hom_{\\mathscr C^\\op}(X,Y) := \\hom_{\\mathscr C}(Y,X)$. Intuitively we are just ``flipping'' the arrows in $\\mathscr C$.\n\nA morphism $f : X \\rightarrow Y$ is said to be an \\textbf{isomorphism} if there is a morphism $g : Y \\rightarrow X$ such that $g \\circ f = \\id_X$ and $f \\circ g = \\id_Y$. A category where all morphisms are isomorphisms is called a \\textbf{groupoid}. An isomorphism is said to be an \\textbf{automorphism} if the domain and codomain of $f$ are the same object. The class of automorphisms of an object $X$ is denoted by $\\Aut_{\\mathscr C}(X)$, or just $\\Aut(X)$ when the category is clear from context. Many categories have their own notation for the class of automorphisms, such as $\\Homeo(X)$ for the category of topological spaces and $\\Diff(X)$ for the category of smooth manifolds.\n\nAn object $X$ is said to be \\textbf{initial} if there is a unique morphism from $X$ to any other object, and said to be \\textbf{terminal} if there is a unique morphism from any other object to $X$. We say that $X$ is a \\textbf{zero object} if it is both initial and terminal. If there is a family of morphism $0_{XY} : X \\rightarrow Y$ such that for all morphisms $f : X \\rightarrow Y$ and $g : Z \\rightarrow W$ we have $0_{YW} \\circ f = g \\circ 0_{XZ}$, then we call this family a \\textbf{family of zero morphisms}. If the category has a zero object, then these morphisms are unique, and so we call $0_{XY}$ \\emph{the} \\textbf{zero morphism} from $X$ to $Y$. \n\nA \\textbf{functor} between categories $F : \\mathscr C \\rightarrow \\mathscr D$ assigns an object $F(X) \\in \\mathscr D$ to each object $X \\in \\mathscr C$ and a morphism $F(f) : F(X) \\rightarrow F(Y)$ to each morphism $f : X \\rightarrow Y$ such that\n\\begin{enumerate}\n\t\\item $F(\\id_X) = \\id_{F(X)}$.\n\t\\item If $f : X \\rightarrow Y$ and $g : Y \\rightarrow Z$, then $F(g \\circ f) = F(g) \\circ F(f)$.\n\\end{enumerate}\nA \\textbf{cofunctor} between categories $F : \\mathscr C \\rightarrow \\mathscr D$ is a functor in the above sense, except it assigns a morphism $F(f) : F(Y) \\rightarrow F(X)$ to each morphism $f : X \\rightarrow Y$ such that\n\\begin{enumerate}\n\t\\item[$2^\\prime$.] If $f : X \\rightarrow Y$ and $g : Y \\rightarrow Z$, then $F(g \\circ f) = F(f) \\circ F(g)$.\n\\end{enumerate}\nIt is easy to see that a cofunctor $F : X \\rightarrow Y$ is just a functor $F : X^\\op \\rightarrow Y$, or equivalently $F : X \\rightarrow Y^\\op$.\n\nA \\textbf{natural transformation} $\\eta$ between functors $F,G : \\mathscr C \\rightarrow \\mathscr D$, written as $\\eta : F \\rightarrow G$, assigns each object $X \\in \\mathscr C$ a morphism $\\eta(X) : F(X) \\rightarrow G(X)$ such that for any morphism $f : X \\rightarrow Y$ we have the following commutative diagram\n\\[\n\\xymatrix\n@R=3pc\n@C=3pc\n{\n\tF(X) \\ar[r]^{F(f)} \\ar[d]_{\\eta(X)} & F(Y) \\ar[d]^{\\eta(Y)} \\\\\n\tG(X) \\ar[r]_{G(f)} & G(Y)\n}\n\\]\nWe can similarly define natural transformations between cofunctors. The natural transformation $\\eta$ is said to be a \\textbf{natural isomorphism} if $\\eta(X)$ is an isomorphism for all $X$, in which case the functors $F$ and $G$ are said to be \\textbf{naturally isomorphic}.\n\n\\begin{example}\nOne comes across the statement in linear algebra that a vector space $V$ is ``naturally'' isomorphic to its double dual $V^{**}$. In categorical terminology this means that the identity functor $\\id : \\Vect \\rightarrow \\Vect$ on the category of vector spaces is naturally isomorphic to the double dual functor $F : \\Vect \\rightarrow \\Vect$, where $F(V) = V^{**}$ and $F(f) = f^{**}$. \n\\end{example}\n\nMany times we can only deal with objects that are unique only up to isomorphism, and so we usually need some kind of extra naturality when dealing with these objects. For example, it is trivial to see that if $A$ is isomorphic to $B$, then there is a bijective correspondence $\\hom_{\\mathscr C}(A,C) \\leftrightarrow \\hom_{\\mathscr C}(B,C)$ for any object $C$. For if $f : A \\rightarrow B$ is an isomorphism, then the correspondence $h \\mapsto h \\circ f$ is a bijection $\\hom_{\\mathscr C}(A,C) \\rightarrow \\hom_{\\mathscr C}(B,C)$. So these hom-sets only depend on the isomorphism class of the objects. But, if $f : C \\rightarrow C'$ is a morphism, how are all the hom-sets $\\hom_{\\mathscr C}(A,C), \\hom_{\\mathscr C}(B,C), \\hom_{\\mathscr C}(A,C')$ and $\\hom_{\\mathscr C}(B,C')$ related? Well, in general they won't be related in any natural way, but if the bijective we described above is denoted by $\\varphi$, then we have the following commutative diagram\n\\[\n\\xymatrix\n{\n\t\\hom(A,C)  \\ar[r]^\\varphi \\ar[d]_{f_*} & \\hom(B,C) \\ar[d]^{f_*} \\\\\n\t\\hom(A,C') \\ar[r]_\\varphi & \\hom(B,C')\n}\n\\]\nwhere $f_*$ is the induced map. So, we say that $\\varphi$ is a natural bijective correspondence.\n\nThere are many useful constructions in category theory, such as products, coproducts, direct limits, inverse limits, etc., but these are all special cases of limits and colimits. Let $\\mathscr D$ be a small category and $\\mathscr C$ any category. A \\textbf{$\\mathscr D$-shaped diagram in $\\mathscr C$} is a functor $F : \\mathscr D \\rightarrow \\mathscr C$. A morphism of $\\mathscr D$-shaped diagrams $F$ and $F'$ is a natural transformation $F \\rightarrow F'$, and so they form a category denoted by $\\mathscr D(\\mathscr C)$. There is a canonical functor $\\Delta : \\mathscr C \\rightarrow \\mathscr D(\\mathscr C)$, called the diagonal functor, that assigns each object $X$ the constant diagram, which maps every object of $\\mathscr D$ to $X$ and every morphism to the identity. Note that a morphism $F : \\Delta(X) \\rightarrow \\Delta(Y)$ of constant diagrams must assign each object of $\\mathscr D$ the same morphism $X \\rightarrow Y$ by the commutativity of the natural transformation square, so we can think of morphisms of constant diagrams as just morphisms of the respective objects.\n\nGiven a $\\mathscr D$-shaped diagram $F$ in $\\mathscr C$, we define its \\textbf{limit} to be an object $\\lim F$ in $\\mathscr C$ and morphism $\\pi : \\Delta(\\lim F) \\rightarrow F$ such that for any object $X$ of $\\mathscr C$ and morphism of diagrams $\\varepsilon : \\Delta(X) \\rightarrow F$ there is a unique morphism $\\tilde\\varepsilon : \\Delta(X) \\rightarrow \\Delta(\\lim F)$ such that the following commutes\n\\[\n\\xymatrix\n{\n\t\\Delta(X) \\ar@{-->}[d]_{\\tilde\\varepsilon} \\ar@/_2.3pc/[dd]_{\\varepsilon} \\\\\n\t\\Delta(\\lim F) \\ar[d]_{\\pi} \\\\\n\tF\n}\n\\]\nThe existence and uniqueness of the morphism $\\tilde\\varepsilon$ for any $\\varepsilon$ ensures that limits are unique up to isomorphism, and so this is called the \\textbf{universal property} of the limit.\n\nWe can dualize this construction to define the \\textbf{colimit} of a $\\mathscr D$-shaped diagram in $\\mathscr C$. In particular, the colimit consists of an object $\\colim F$ in $\\mathscr C$ and morphism $\\iota : F \\rightarrow \\Delta(\\colim F)$ such that for any object $X$ of $\\mathscr C$ and morphism $\\eta : F \\rightarrow \\Delta(X)$ there is a unique morphism $\\tilde\\eta : \\Delta(\\colim F) \\rightarrow \\Delta(X)$ such that the following commutes\n\\[\n\\xymatrix\n{\n\t\\Delta(X) \\\\\n\t\\Delta(\\colim F) \\ar@{-->}[u]^{\\tilde\\eta} \\\\\n\tF \\ar[u]^\\iota \\ar@/^2.5pc/[uu]^{\\eta}\n}\n\\]\nAgain we have that colimits are unique up to isomorphism.\n\n\\begin{example}[Products]\n\\label{categorical product as a limit}\nLet $\\mathscr D$ be a category with two objects and no non-identity morphisms. Then a $\\mathscr D$-shaped diagram $F$ is simply a pair of objects $X,Y$ in $\\mathscr C$, and let us denote the limit by $P$. The morphism $\\pi : \\Delta(P) \\rightarrow F$ is just a pair of morphisms $\\pi_X : P \\rightarrow X$ and $\\pi_Y : P \\rightarrow Y$. Then the universal property of limits says that for any other object $P'$ and morphisms $\\pi_X' : P' \\rightarrow X$ and $\\pi_Y' : P' \\rightarrow Y$ there is a unique morphism $\\epsilon : P' \\rightarrow P$ such that the following diagram commutes\n\\[\n\\xymatrix\n@C=1pc\n{\n\t  & P' \\ar@{-->}[d]_{\\varepsilon} \\ar@/_1.5pc/[ddl]_{\\pi_X'} \\ar@/^1.5pc/[ddr]^{\\pi_Y'} \\\\\n\t  & P \\ar[dl]_{\\pi_X} \\ar[dr]^{\\pi_Y} & \\\\\n\tX & & Y\n}\n\\]\nIn category theory $P$ is most commonly known as the \\textbf{categorical product} of $X$ and $Y$ in $\\mathscr C$, and $\\pi_X$ and $\\pi_Y$ are called the natural projections. We denote the product, which is unique up to isomorphism, by $X \\times_{\\mathscr C} Y$, or just $X \\times Y$ when the category is understood.\n\nTherefore the product in category theory is just a special case of a limit when $\\mathscr D$ is the discrete category with two objects. More generally, suppose we have a collection of objects $\\lcb X_\\alpha \\rcb$ indexed by a set $\\Lambda$. We can think of $\\Lambda$ as a category whose objects are the elements of $\\Lambda$ and there are no non-identity morphisms. Then the product of the objects $\\lcb X_\\alpha \\rcb$ is just the limit of the $\\Lambda$-shaped diagram that maps each index $\\alpha$ to $X_\\alpha$.\n\\end{example}\n\n\\begin{example}[Coproducts]\nLet $\\mathscr D$ be the discrete category with two objects as in \\cref{categorical product as a limit} so that a $\\mathscr D$-shaped diagram $F$ is just a pair of objects $X,Y$ in $\\mathscr C$. Let $C$ denote the colimit of $F$, and let $\\iota_X : X \\rightarrow C$ and $\\iota_Y : Y \\rightarrow C$ be the morphisms provided by the colimit. Then the universal property of colimits says that for any other object $C'$ and morphisms $\\iota_X' : X \\rightarrow C'$ and $\\iota_Y' : Y \\rightarrow C'$ there is a unique morphism $\\eta : C \\rightarrow C'$ such that the following diagram commutes\n\\[\n\\xymatrix\n@C=1pc\n{\n\t  & C' \\\\\n\t  & C \\ar@{-->}[u]^{\\eta} & \\\\\n\tX \\ar[ur]^{\\iota_X} \\ar@/^1.5pc/[uur]^{\\iota_X'} & & Y \\ar[ul]_{\\iota_Y} \\ar@/_1.5pc/[uul]_{\\iota_Y'}\n}\n\\]\nIn category theory $C$ is most commonly known as the \\textbf{categorical coproduct} of $X$ and $Y$ in $\\mathscr C$, and $\\iota_X$ and $\\iota_Y$ are called the natural inclusions. We denote the coproduct, which is unique up to isomorphism, by $X \\sqcup_{\\mathscr C} Y$, or just $X \\sqcup Y$ when the category is understood.\n\\end{example}\n\n\\begin{example}[Equalizers]\n\\label{equalizer as a limit}\nLet $\\mathscr D$ be the category with two objects and two non-identity morphisms with same domain and range. We can write this schematically as $\\mathscr D = \\lcb \\xymatrix{ \\cdot \\ar@/_0.5pc/[r] \\ar@/^0.5pc/[r] & \\cdot } \\rcb$. Then a $\\mathscr D$-shaped diagram $F$ is simply a pair of objects $X,Y$ in $\\mathscr C$ and a pair of morphisms $f,g : X \\rightarrow Y$, which we can write as the diagram\n\\[\n\\xymatrix\n{\n\tX \\ar@/_0.5pc/[r]_g \\ar@/^0.5pc/[r]^f & Y\n}\n\\]\nLet $E$ denote the the limit of this diagram, and let $\\pi : F \\rightarrow \\Delta(E)$ be the morphism provided by the limit. This is just a pair of morphisms $\\pi_X : E \\rightarrow X$ and $\\pi_Y : E \\rightarrow Y$, but $\\pi_Y$ is determined from $\\pi_X,f,g$ since the commutativity of the natural transformation square requires that $\\pi_Y = f \\circ \\pi_X = g \\circ \\pi_Y$. The universal property of limits says that for any other object $E'$ and morphism $\\pi_X' : E' \\rightarrow X$ there is a unique morphism $\\varepsilon : E' \\rightarrow E$ such that the following diagram commutes\n\\[\n\\xymatrix\n{\n\tE \\ar[r]^{\\pi_X} & X \\ar@/_0.5pc/[r]_g \\ar@/^0.5pc/[r]^f & Y \\\\\n\tE' \\ar@{-->}[u]^{\\varepsilon} \\ar[ur]_{\\pi_X'}\n}\n\\]\nIn category theory $C$ is most commonly known as the \\textbf{equalizer} of $f,g : X \\rightarrow Y$ in $C$.\n\\end{example}\n\n\\begin{example}[Coequalizers]\nDualizing everything in \\cref{equalizer as a limit} gives us the definition of the \\textbf{coequalizer} of $f,g : X \\rightarrow Y$ as a colimit. Specifically, the coequalizer is an object $C$ and morphism $\\iota_Y : Y \\rightarrow C$ such that for any other object $C'$ and morphism $\\iota_Y' : Y \\rightarrow C$ there is a unique morphism $\\eta : C \\rightarrow C'$ such that the following diagram commutes\n\\[\n\\xymatrix\n{\n\tX \\ar@/_0.5pc/[r]_g \\ar@/^0.5pc/[r]^f & Y \\ar[r]^{\\iota_Y} \\ar[rd]_{\\iota'_Y} & C \\ar@{-->}[d]^{\\eta} \\\\\n\t & & C'\n}\n\\]\n\\end{example}\n\n\\begin{example}[Pullbacks]\n\\label{pullback as a limit}\nConsider the category $\\mathscr D = \\lcb \\cdot \\rightarrow \\cdot \\leftarrow \\cdot \\rcb$, that is, $\\mathscr D$ has three objects and two non-identity morphisms. A $\\mathscr D$-shaped diagram $F$ is just a diagram of the form $Y \\stackrel{g}{\\rightarrow} Z \\stackrel{f}{\\leftarrow} X$. Let $P$ be the pullback of this diagram with induced morphisms $f' : P \\rightarrow Y$ and $g' : P \\rightarrow X$. Technically we should also include another morphism $P \\rightarrow Z$, but it uniquely determined by $f,g,f',g'$ due to the commutativity square of the natural transformation. The universal property of this limit says that for any other object $P'$ and morphisms $f'' : P' \\rightarrow Y$ and $g'' : P' \\rightarrow X$ there is a unique morphism $\\epsilon : P' \\rightarrow P$ such that the following diagram commutes\n\\[\n\\xymatrix\n{\n\tP' \\ar@{-->}[rd]_{\\epsilon} \\ar@/_2pc/[rddd]_{f''} \\ar@/^2pc/[rrrd]^{g''} &   &   \\\\\n\t   & P \\ar[rr]^{g'} \\ar[dd]_{f'} & & X \\ar[dd]^{f} \\\\\n\t   & & & \\\\\n\t   & Y \\ar[rr]_{g} & & Z\n}\n\\]\nIn category theory we say that $P$ is the \\textbf{pullback} of $X \\stackrel{f}{\\rightarrow} Z \\stackrel{g}{\\leftarrow} Y$, and will be denoted by $X \\times_Z Y$. By the universal property there is a natural isomorphism $X \\times_Z Y \\cong Y \\times_Z X$.\n\\end{example}\n\n\\begin{example}[Pushouts]\nDualizing the construction in \\cref{pullback as a limit} gives us the definition of the \\textbf{pushout} of $Y \\stackrel{g}{\\leftarrow} Z \\stackrel{f}{\\rightarrow} X$. In particular, the pushout of this diagram is an object $P$ with morphisms $X \\stackrel{g'}{\\rightarrow} P$ and $Y \\stackrel{f'}{\\rightarrow} P$ such that for any other object $P'$ and morphisms $X \\stackrel{g''}{\\rightarrow} P'$ and $Y \\stackrel{f''}{\\rightarrow} P$ there is a unique morphism $\\eta : P \\rightarrow P'$ such that the following diagram commutes\n\\[\n\\xymatrix\n{\n\tZ \\ar[rr]^{f} \\ar[dd]_{g} & & X \\ar[dd]^{g'} \\ar@/^2pc/[rddd]^{g''} \\\\\n\t  & & \\\\\n\tY \\ar[rr]_{f'} \\ar@/_2pc/[rrrd]_{f''} & & P \\ar@{-->}[rd]^{\\eta} \\\\\n\t  & & & P'\n}\n\\]\nThe pushout will be denoted by $X \\cup_Z Y$. By the universal property there is a natural isomorphism $X \\cup_Z Y \\cong Y \\cup_Z X$.\n\\end{example}\n\n\\begin{example}[Inverse Limits]\nLet $\\Lambda$ be a partially ordered set with upper bounds. This means there is a binary relation $\\leq$ on $\\Lambda$ that is reflexive, antisymmetric, transitive and such that for any elements $i,j$ in $\\Lambda$ there is an element $k$ such that $i \\leq k$ and $j \\leq k$. Such a set is sometimes called a directed set. Consider the category $\\underleftarrow\\Lambda$ whose objects are the elements of $\\Lambda$ and such that there is a \\emph{unique} morphism $f_{ij} : j \\rightarrow i$ if $i \\leq j$. A $\\underleftarrow\\Lambda$-shaped diagram $F : \\underleftarrow\\Lambda \\rightarrow \\mathscr C$ in $\\mathscr C$ is called an \\textbf{inverse system} over $\\Lambda$ in $\\mathscr C$ (older references say projective system). The limit of this diagram is called the \\textbf{inverse limit} of the inverse system, and is written $\\invlim F$. \n\nLet us peel away the abstract nonsense for a moment to see what this definition really means. A $\\underleftarrow\\Lambda$-shaped diagram in $\\mathscr C$ is just a collection of objects $A_i$, indexed by $\\Lambda$, and one morphism $f_{ij} : A_j \\rightarrow A_i$ for each $i \\leq j$ such that $f_{ii} = \\id_{A_i}$ and $f_{ik} = f_{ij} \\circ f_{jk}$. The limit of this diagram is an object $A$ with morphisms $\\pi_i : A \\rightarrow A_i$ for each $i \\in \\Lambda$, such that $f_{ij} \\circ \\pi_j = \\pi_i$ (this comes from commutativity of the natural transformation square). The object $A$ has to be universal in the sense that if $A'$ is another object with morphisms $\\pi_i' : A' \\rightarrow A_i$ and $f_{ij} \\circ \\pi_j' = \\pi_i'$, then there is a unique morphism $\\varepsilon : A' \\rightarrow A$ such that $\\pi_i \\circ \\varepsilon = \\pi_i'$ for all $i \\in \\Lambda$. \n\\end{example}\n\n\\begin{example}[Direct Limits]\nDualizing the above gives the definition of direct limits in a category, but we spell out the details to make it more clear. Let $\\Lambda$ be a partially ordered set with upper bounds. Consider the category $\\underrightarrow\\Lambda$ whose objects are the elements of $\\Lambda$ and such that there is a \\emph{unique} morphism $f_{ij} : i \\rightarrow j$ if $i \\leq j$. A $\\underrightarrow\\Lambda$-shaped diagram $F : \\underrightarrow\\Lambda \\rightarrow \\mathscr C$ in $\\mathscr C$ is called a \\textbf{direct system} over $\\Lambda$ in $\\mathscr C$. The colimit of this diagram is called the \\textbf{direct limit} of the direct system, and is written $\\dirlim F$. \n\nLet us see what this means on a lower level. A $\\underrightarrow\\Lambda$-shaped diagram in $\\mathscr C$ is just a collection of objects $A_i$, indexed by $\\Lambda$, and one morphism $f_{ij} : A_i \\rightarrow A_j$ for each $i \\leq j$ such that $f_{ii} = \\id_{A_i}$ and $f_{ik} = f_{jk} \\circ f_{ij}$. The colimit of this diagram is an object $A$ with morphisms $\\iota_i : A_i \\rightarrow A$ for each $i \\in \\Lambda$, such that $\\pi_j \\circ f_{ij} = \\pi_i$ (this comes from commutativity of the natural transformation square). The object $A$ has to be universal in the sense that if $A'$ is another object with morphisms $\\iota_i' : A_i \\rightarrow A'$ and $\\iota_j' \\circ f_{ij} = \\iota_i'$, then there is a unique morphism $\\eta : A \\rightarrow A'$ such that $\\eta \\circ \\iota_i = \\iota_i'$ for all $i \\in \\Lambda$. \n\\end{example}\n\n\nLet us describe how $\\lim$ can be thought of as a functor $\\lim : \\mathscr D(\\mathscr C) \\rightarrow \\mathscr C$. The functor assigns a diagram $F$ in $\\mathscr D(\\mathscr C)$ the object $\\lim F$. For two diagrams $F,G$ let $\\pi_F,\\pi_G$ denote the morphisms from their limits to $F$. If $t : F \\rightarrow G$ is a morphism of these diagrams, then $t \\circ \\pi_F : \\Delta(\\lim F) \\rightarrow G$, so by the universal property of limits there is a unique morphism $\\tilde\\varepsilon : \\Delta(\\lim F) \\rightarrow \\Delta(\\lim G)$ such that the following commutes\n\\[\n\\xymatrix\n{\n\t\\Delta(\\lim F) \\ar@{-->}[d]_{\\tilde\\varepsilon} \\ar@/_2.3pc/[dd]_{t \\circ \\pi_F} \\\\\n\t\\Delta(\\lim G) \\ar[d]_{\\pi_G} \\\\\n\tG\n}\n\\]\nBut we remarked earlier that a morphism between constant diagrams must map every object to the same morphism, so we define $\\lim(t)$ be this unique morphism for $\\tilde\\varepsilon$. Doing something similar for $\\colim$ shows how it can be turned into a functor $\\mathscr D(\\mathscr C) \\rightarrow \\mathscr C$. \n\nGiven a functor $F : \\mathscr C \\rightarrow \\mathscr C'$ between categories and a diagram $G : \\mathscr D \\rightarrow \\mathscr C$ in $\\mathscr C$, we get an induced diagram $F \\circ G$ in $\\mathscr C'$. The functor $F$ is said to be \\textbf{continuous} if $F(\\lim G) = \\lim(F \\circ G)$ for all diagrams $G$, and otherwise is said to be \\textbf{discontinuous}. Similarly, if $F(\\colim G) = \\colim(F \\circ G)$ for all diagrams $G$, then $F$ is said to be \\textbf{cocontinuous}, and otherwise is said to be \\textbf{discocontinuous}. For example, the forgetful functor $\\Ab \\rightarrow \\Set$ on the category of abelian groups is continuous, however the forgetful functor $\\Setp \\rightarrow \\Set$ on the category of pointed sets is discocontinuous (coproducts are not preserved). A category such that limits of all diagrams exists is called \\textbf{complete}, and if all colimits exists then it is called \\textbf{cocomplete}. The following is a surprising theorem.\n\\begin{thm}\n\\label{complete and cocomplete characterization}\nA category is complete (cocomplete) if and only if all products (coproducts) and all equalizers (coequalizers) exist.\n\\end{thm}\n\n\\begin{example}\nWe will show a specific example of \\cref{complete and cocomplete characterization} by describing how a pullback can be formed as a product and equalizer, which is why we chose the notation $X \\times_Z Y$ for pullbacks. Suppose we have two morphisms $f : X \\rightarrow Z$ and $g : Y \\rightarrow Z$. Let $P$ be the product of $X$ and $Y$, with projections $\\pi_X : P \\rightarrow X$ and $\\pi_Y : P \\rightarrow Y$, and let $E$ be the equalizer of $f \\circ \\pi_X$ and $g \\circ \\pi_Y$, with induced natural map $\\pi : E \\rightarrow P$. We claim that $E$ with maps $\\pi_X \\circ \\pi$ and $\\pi_Y \\circ \\pi$ is the pullback of $f$ and $g$. To show this we need to verify the universal property of the limit. So, let $E'$ be any other object with maps $f' : E' \\rightarrow Y$ and $g' : E' \\rightarrow X$. By the universal property of products we have that there is a unique morphism $\\varepsilon : E' \\rightarrow P$. But, now by the universal property of equalizers, we have that there is a unique morphism $\\epsilon' : E' \\rightarrow E$. The diagram looks like the following\n\\[\n\\xymatrix\n{\n\tE' \\ar@/_2.5pc/[rrdddd]_{f'} \\ar@/^2.5pc/[rrrrdd]^{g'} \\ar@{-->}[rd]^{\\varepsilon'} \\ar@{-->}@/_1.5pc/[rrdd]_{\\varepsilon} &   &   & \\\\\n\t   & E \\ar@{-->}[rd]^{\\pi} &   & \\\\\n\t   &   & P \\ar[rr]^{\\pi_Y} \\ar[dd]_{\\pi_X} & & X \\ar[dd]^{f} \\\\\n\t   & & & & \\\\\n\t   &   & Y \\ar[rr]_{g} & & Z\n}\n\\]\nWe need to verify that $\\pi_Y \\circ \\pi \\circ \\varepsilon' = g'$, and this is true since $\\pi \\circ \\varepsilon' = \\varepsilon$ by universality of equalizers, and then $\\pi_Y \\circ \\varepsilon = g'$ by universality of products. We also need to verify that $\\pi_X \\circ \\pi \\circ \\varepsilon' = f'$, but this is similar to what we just showed. Therefore $E$ is the pullback of $f$ and $g$. By dualizing this we can also show that pushouts can be expressed as a coproduct and coequalizer.\n\\end{example}\n\nIn set theory we define the exponential of sets $Y^X$ to be the set of functions $X \\rightarrow Y$. There is an obvious map $e : Y^X \\times X \\rightarrow Y$ defined by $e(f,x) = f(x)$, and for any space $Z$ with function $Z \\times X \\rightarrow Y$ there is a unique $\\lambda : Z \\rightarrow Y^X$ such that $e \\circ (\\lambda \\times \\id) = g$, just take $\\lambda(z)(x) = g(z,x)$. We can easily generalize this to other categories. Let $\\mathscr C$ be a category with all finite products. The \\textbf{exponential object} of $X$ and $Y$ is an object denoted by $Y^X$ and morphism $e : Y^X \\times X \\rightarrow Y$ such that for any other object $Z$ and morphism $g : Z \\times X \\rightarrow Y$, there is a unique morphism $\\lambda : Z \\rightarrow Y^X$ such that the following diagram commutes\n\\[\n\\xymatrix\n{\n\tZ \\times X \\ar[rd]^{g} \\ar@{-->}[d]_{\\lambda \\times \\id_X} \\\\\n\tY^X \\times X \\ar[r]_-{e} & Y\n}\n\\]\nWe say that a category is \\textbf{cartesian closed} if it has all finite products and if all exponential objects exist.\n\n\n\nLet $\\mathscr C$ and $\\mathscr D$ be two locally small categories, and consider two functors $F : \\mathscr C \\rightarrow \\mathscr D$ and $G : \\mathscr D \\rightarrow \\mathscr C$. We say that $F$ is a \\textbf{left adjoint} of $G$ (or equivalently, $G$ is a \\textbf{right adjoint} to $F$) if the bifunctors \n\\[ \\hom_{\\mathscr D}(F(-),-) : \\mathscr C^\\op \\times \\mathscr D \\rightarrow \\Set \\]\n\\[ \\hom_{\\mathscr C}(-,G(-)) : \\mathscr C^\\op \\times \\mathscr D \\rightarrow \\Set \\]\nare naturally isomorphic. This means for every object $X$ in $\\mathscr C$ and object $Y$ in $\\mathscr D$, there is an isomorphism of sets\n\\[ \\hom_{\\mathscr D}(F(X),Y) \\cong \\hom_{\\mathscr C}(X,G(Y)) \\]\nwhich is natural in $X$ and $Y$ (meaning, morphisms on $X$ and $Y$ give us the obvious commuting diagrams). Sometimes the hom-sets of $\\mathscr C$ and $\\mathscr D$ can be given extra structure, in which case we can usually say the above isomorphism of sets is actually an isomorphism of the extra structures too. Adjoint functors are unique up to natural isomorphism. \n\n\\begin{example}\nLet $F : \\Grp \\rightarrow \\Set$ be the forgetful functor on the category of groups, and let $G : \\Set \\rightarrow \\Grp$ be the functor that sends a set to the free group generated by its elements. Then $F$ is a left adjoint of $G$.\n\\end{example}\n\n\\begin{example}\n\\label{forgetful functor on Top}\nThe forgetful functor $F : \\Top \\rightarrow \\Set$ on the category of topological spaces has both a left and right adjoint. Its left adjoint is the functor $D : \\Set \\rightarrow \\Top$ that gives a set the discrete topology, and its right adjoint is the functor $I : \\Set \\rightarrow \\Top$ that gives a set the indiscrete topology. A similar statement holds for the forgetful functor $\\Topp \\rightarrow \\Setp$ on the category of pointed topological spaces. Therefore, by the upcoming \\cref{adjoint functor continuity}, both of these forgetful functors are continuous and cocontinuous.\n\\end{example}\n\n\\begin{example}\n\\label{product-exponential adjoint}\nSuppose all exponential objects $Y^X$ exist for a fixed object $X$. Then the functor $-\\times X : \\mathscr C \\rightarrow \\mathscr C$ is the left adjoint of $-^X : \\mathscr C \\rightarrow \\mathscr C$. \n\\end{example}\n\nAdjoint functors have an amazing property.\n\\begin{thm}\n\\label{adjoint functor continuity}\nIf $F$ has a left (right) adjoint, and hence is a right (left) adjoint, then $F$ is continuous (cocontinuous).\n\\end{thm}\n\n\n\n\n\n\n\\newpage\n\\section{Some General Topology}\n\n\n\\subsection{Categories, Limits and Colimits in Topology}\n\nThe category of topological spaces and continuous maps will be denoted by $\\Top$, and the category of based topological spaces with base-point preserving continuous maps will be denoted by $\\Topp$. When it is understood that we are working in $\\Top$ or $\\Topp$, we will sometimes denote $\\hom_{\\Top}(X,Y)$ by $\\hom(X,Y)$ and $\\hom_{\\Topp}(X,Y)$ by $\\hom_*(X,Y)$. We saw in \\cref{forgetful functor on Top} that the forgetful functors on $\\Top$ and $\\Topp$ have left and right adjoints, hence the forgetful functors are continuous and cocontinuous, and so $\\Top $ and $\\Topp$ are complete and cocomplete. This means that the underlying set of any limit or colimit in $\\Top$ (resp. $\\Topp$) is just the limit or colimit taken in $\\Set$ (resp. $\\Setp$) and topologized by the universal property. For example, the product of topological spaces is just the cartesian product of their underlying sets, and the unversal property gives the product the Tychonoff topology. The product of based spaces $(X,x_0)$ and $(Y,y_0)$ is the cartesian product $X \\times Y$ with base point $(x_0,y_0)$. The coproduct of topological spaces is just the disjoint union of their underlying sets. \n\nHowever, the coproduct of pointed topological spaces $(X,x_0)$ and $(Y,y_0)$ is a little more complicated. If we just take the disjoint union $X \\sqcup Y$, then both $x_0$ and $y_0$ are in the coproduct, and which should we choose for the base point? Neither base point will suffice, so instead we glue together $X$ and $Y$ at their base points. This construction is called the \\textbf{wedge sum}, its the coproduct in the category of based sets, and is denoted by $X \\vee Y = \\lcb (x,y) \\in X \\times Y \\st x=x_0 \\text{ or } y=y_0 \\rcb$, with base point $(x_0,y_0)$. \n\nUnfortunately, the categories $\\Top$ and $\\Topp$ have too many pathological spaces, for example indiscrete spaces. Even the nicer category $\\Haus$ of Hausdorff spaces is still a little too unwieldy. This prevents $\\Top$ and $\\Haus$ from being cartesian closed, which is very important to have for homotopy theory since we like to think of homotopies as 1-parameter families of maps, i.e. we want $\\hom_{\\Top}(X \\times I,Y) \\cong \\hom_{\\Top}(X,Y^I)$. So we would like to find a subcategory of $\\Top$ where exponential objects exists, but also contains all the spaces we usually work with. Steenrod found such a category of spaces (see \\cite{steenrod67}). \n\nWe say that a topological space $X$ is \\textbf{compactly generated} if a subset $C$ is closed if and only if $C \\cap K$ is closed in $K$ for every compact set $K$ in $X$. Most spaces we work with are compactly generated, such as locally compact spaces, metric spaces, manifolds, and CW-complexes. Let $\\CGTop$ denote the full subcategory of $\\Top$ consisting of compactly generated topological spaces, and let $\\CGHaus$ denote the full subcategory of $\\CGTop$ consisting of Hausdorff spaces. Similarly define $\\CGTopp$ and $\\CGHausp$. There is a functor $k : \\Haus \\rightarrow \\CGHaus$ that re-topologizes a space $X$ by declaring a subset $C$ closed if and only if $C \\cap K$ is closed in $K$ for all compact subsets $K$ of $X$. One can show that $k$ is the identity on the subcategory $\\CGHaus$ and $k$ is the right adjoint of the inclusion functor $\\CGHaus \\rightarrow \\Haus$. The product in $\\CGHaus$ is not just the product in $\\Haus$ (the product of compactly generated spaces is not necessarily compactly generated), but we do have $X \\times_{\\CGHaus} Y = k(X \\times_\\Haus Y)$. Further, most importantly, the category $\\CGHaus$ \\emph{is} cartesian closed. The exponent object of $X$ and $Y$ is $k(Y^X)$, where $Y^X = \\hom_{\\Top}(X,Y)$ is given the compact-open topology. Similarly, $\\CGHausp$ is cartesian closed. We now have\n\\begin{prop}\n\\sloppyspace\n\\begin{enumerate}\n\t\\item For a space $X$ in $\\CGHaus$, the functor $-\\times X : \\CGHaus \\rightarrow \\CGHaus$ is the left adjoint of $-^X : \\CGHaus \\rightarrow \\CGHaus$. In particular, the function spaces $Z^{(X \\times Y)}$ and $(Z^Y)^X$ are naturally homeomorphic. \n\t\\item For a based space $X$ in $\\CGHausp$, the functor $-\\times X : \\CGHausp \\rightarrow \\CGHausp$ is the left adjoint of $-^X : \\CGHausp \\rightarrow \\CGHausp$. In particular, the function spaces $(Z,z_0)^{(X,x_0)\\times(Y,y_0)} = ((Z,z_0)^{(Y,y_0)})^{(X,x_0)}$.\n\\end{enumerate}\n\\end{prop}\nWe now see that $\\CGHaus$ and $\\CGHausp$ are very nice categories to do homotopy theory. Any time we consider a topological space, we are going to immediately apply the functor $k$ so that we can assume we always assume we are working in $\\CGHaus$. In fact, we are going to adopt this doctrine to the extreme by \\emph{redefining} $\\Top$ to be the category of compactly generated, Hausdorff spaces, and similarly for $\\Top_*$. \n\nThe category $\\Top^2$ consists of pairs of topological spaces $(X,A)$ such that $A \\subseteq X$, and a morphism $f : (X,A) \\rightarrow (Y,B)$ is a continuous map $f : X \\rightarrow Y$ such that $f(A) \\subseteq f(B)$. Similarly $\\Topp^2$ consists of pairs of topological spaces $(X,A)$ with base point in $A$ (and hence $X$ too), and a morphism is a morphism of pairs that preserves the base point. The product of pairs of spaces $(X,A)$ and $(Y,B)$ is simply $(X \\times Y,A \\times B)$, and the exponential $(Y,B)^{(X,A)}$ is the set of continuous maps $(X,A) \\rightarrow (Y,B)$. We could also define the category of $n$-tuples of spaces $\\Top^n$, but they will not be of use in these notes.\n\n\n\n\n\\subsection{Functors in Topology}\n\nSince $\\Top$ is cartesian closed, for a fixed space $X$ we get a functor $-^X : \\Top \\rightarrow \\Top$. For a map $f : Y \\rightarrow Z$, the induced map $f^X : Y^X \\rightarrow Z^X$ is defined by $f^X(g)(x) = f(g(x))$. If $X$ is based, then we get a functor $-^{(X,x_0)} : \\Topp \\rightarrow \\Topp$, where $(Y,y_0)^{(X,x_0)}$ is based at the constant map $y \\mapsto x_0$. For a based map $f : (Y,y_0) \\rightarrow (Z,z_0)$, the induced map is defined the exact same way as in the unbased case.\n\nWe saw earlier that the regular cartesian product is the categorical product in $\\Topp$ and serves as the left adjoint of $-^X$. There is another operation that is useful in $\\Topp$ and is the left adjoint of $X^-$. Given two pointed spaces $(X,x_0)$ and $(Y,y_0)$, we define their \\textbf{smash product} to be $X \\wedge Y = X \\times Y / X \\vee Y$, which is based at the equivalence class of $(x_0,y_0)$. If $f : X \\rightarrow Z$ and $g : Y \\rightarrow W$ are based, continuous maps, then $f \\wedge g : X \\wedge Y \\rightarrow Z \\wedge W$ is the based, continuous map that sends $[x,y]$ to $[f(x),g(y)]$. It is easy to show that this is well-defined, and so $\\wedge : \\Topp \\times \\Topp \\rightarrow \\Topp$ is a bifunctor. The following proposition makes precise the statement that the smash product in $\\Topp$ is like the tensor product in $\\RMod{R}$.\n\\begin{prop}\n\\label{wedge and exponential adjoint}\nFor a fixed space $Y$ in $\\Topp$, the functor $- \\wedge Y : \\Topp \\rightarrow \\Topp$ is the left adjoint of $Y^- : \\Topp \\rightarrow \\Topp$. In particular, the spaces\n\\[ \\hom_*(X \\wedge Y,Z) \\cong \\hom_*(X,Y^Z) \\]\nare naturally homeomorphic.\n\\end{prop}\n\nThe \\textbf{free path space} functor is just exponentiation by the unit interval, $-^I$, and the \\textbf{based path space} is just the based exponentiation by the unit interval based at 0, $-^{(I,0)}$. The \\textbf{free loop space} functor $\\Omega$ is just exponentiation by the circle, $\\Omega = -^{S^1}$, and the \\textbf{based loop space} functor $\\Omega_*$ is just exponentiation by the based circle, $\\Omega_* = -^{(S^1,1)}$, or equivalently, $\\Omega_* = -^{(I,\\lcb 0,1 \\rcb)}$, which is sometimes easier to user.\n\nThe \\textbf{free suspension} functor $\\Sigma : \\Top \\rightarrow \\Top$ assigns a space $X$ to $X \\times I / X \\times \\lcb 0,1 \\rcb$. Intuitively, we take the cylinder on $X$ and then pinch the ends. Given a continuous function $f : X \\rightarrow Y$, the induced map $\\Sigma f : \\Sigma X \\rightarrow \\Sigma Y$ is defined by $f([x,t]) = [f(x),t]$, which is easily verified to be well-defined. The \\textbf{based suspension} functor $\\Sigma_* : \\Topp \\rightarrow \\Topp$ assigns a space $X$ to $\\Sigma X / \\lcb x_0 \\rcb \\times I$, that is, we identify all the points $\\lcb x_0 \\rcb \\times I$ in the free suspension.  We base $\\Sigma_* X$ at the equivalence class of $(x_0,0)$. Induced maps are defined in the exact same way, and are clearly well-defined. It is easy to see that for a based space $X$, the based suspesion can be written as $\\Sigma_* X = X \\wedge S^1$. Note that some people refer to $\\Sigma$ as the unreduced suspension and $\\Sigma_*$ as the reduced suspension.\n\nBy \\cref{wedge and exponential adjoint} we have\n\\begin{cor}\n$\\Sigma_*$ is the left adjoint of $\\Omega_*$. In particular, the spaces\n\\[ \\hom_*(\\Sigma_* X,Y) \\cong \\hom_*(X,\\Omega_* Y) \\]\nare naturally isomorphic.\n\\end{cor}\n\n\n\n\\subsection{The Homotopy Category}\n\n\nWe want to consider homotopies in each of our categories $\\Top,\\Topp,\\Top^2$ and $\\Topp^2$. This can be done in one fell swoop by letting $I$ simultaneously denote 1.) just the unit interval, 2.) the unit interval based at 0, 3.) the pair of spaces $(I,I)$ and finally, 4.) the pair of spaces $(I,I)$ based at 0. Which interpretation of $I$ we use depends on which category we are working in. If $\\mathscr C$ is any of our four categories of spaces, two morphisms $f,g : X \\rightarrow Y$ in $\\mathscr C$ are said to be homotopic in $\\mathscr C$ if there is a map $H : X \\times I \\rightarrow Y$ in $\\mathscr C$ such that $H(x,0) = f(x)$ and $H(x,1) = g(x)$, and we write $f \\simeq g$. We will usually denote $H(-,t)$ by $H_t$. A homotopy in $\\Top$ is called a \\textbf{free homotopy} and in $\\Topp$ it is called a \\textbf{based homotopy}. A homotopy between maps $(X,A) \\rightarrow (Y,B)$ in $\\Top^2$ that fixes $A$ for all time, i.e. $H_t|A = \\id_A$, is called a \\textbf{homotopy relative $A$} and we write $f \\simeq g \\ (\\rel A)$. Note that a homotopy in $\\Topp$ could just as easily be defined as a map $H : X \\wedge I_+ \\rightarrow Y$ such that $H_0 = f$ and $H_1 = g$. \n\nThe notion of homotopy defines an equivalence relation on $\\hom_{\\mathscr C}(X,Y)$, and we call an equivalence class of maps a \\textbf{homotopy class}. The set of homotopy classes of between $X$ and $Y$ in $\\Top,\\Topp,\\Top^2,\\Topp^2$ is denoted by $[X,Y], [X,Y]_*, [(X,A),(Y,B)]$ and $[(X,A),(Y,B)]_*$ respectively. Note that $[X,Y]_*$ for based spaces is the same thing as $[(X,x_0),(Y,y_0)]$. We do not have a notation for the equivalence classes of maps up to homotopy (rel $A$), but it will be an important ingredient in these notes.\n\nLet $\\hTop$ denote the category whose objects are topological spaces, and $\\hom_{\\hTop}(X,Y) = [X,Y]$, and similarly for $\\Topp,\\Top^2,\\Topp^2$. These categories are called the homotopy category and based homotopy category of topological spaces and pairs of topological spaces. An isomorphism in one of these homotopy categories is called a \\textbf{homotopy equivalence}.\n\nThe functors $\\Omega$ and $\\Sigma$ (and their based counterparts) descend to functors on $\\hTop$ (and $\\hTopp$).\n\\begin{prop}\n\\label{suspension and loop space are adjoint}\n$\\Sigma_*$ is the left adjoint of $\\Omega_*$ in $\\hTopp$. In particular, the sets $[\\Sigma_* X,Y]_*$ and $[X,\\Omega_* Y]_*$ are naturally isomorphic.\n\\end{prop}\n\\begin{proof}\nNote that $[X,Y]_*$ is naturally isomorphic to $[S^0,\\hom_*(X,Y)]_*$, so \n\\[ [\\Sigma_*X,Y]_* \\cong [S^0,\\hom_*(\\Sigma_*X,Y)]_* \\cong [S^0,\\hom_*(X,\\Omega_*Y)]_* \\cong [X,\\Omega_*Y]_* \\]\nand all isomorphisms are natural.\n\\end{proof}\n\n\n\n\n\n\n\n\\subsection{$H$-groups and $H$-cogroups}\n\\label{H-groups and H-cogroups}\n\n\nTopological groups, spaces with a group structure such that the group operations are continuous, are very useful in geometry, but like most things from geometry they are far too restrictive for homotopy theory. We can reformulate the axioms of a group in terms of commutativity of certain digrams, and then define a homotopy theoretic topological group to be a space in which these diagrams only commute up to homotopy. Let $(X,x_0)$ be a based space, and let $x_0$ also denote the constant map $X \\rightarrow X$ that maps everything to $x_0$. A map $\\mu : X \\times X \\rightarrow X$ is said to be a \\emph{multiplication with homotopy identity $x_0$} if the following diagram\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX \\ar[r]^-{\\id \\times x_0} \\ar[rd]_\\id & X \\times X \\ar[d]_\\mu & X \\ar[l]_-{x_0 \\times \\id} \\ar[ld]^\\id \\\\\n\t & X &\n}\n\\]\ncommutes up to homotopy: $\\mu \\circ (\\id \\times x_0) \\simeq \\id \\simeq \\mu \\circ (x_0 \\times \\id)$. Note that $\\id \\times x_0$ is the map induced by $\\id$ and $x_0$ from the universal property of products. We say that $\\mu$ is \\emph{homotopy associative} if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX \\times X \\times X \\ar[r]^-{\\id \\times \\mu} \\ar[d]_-{\\mu \\times \\id} & X \\times X \\ar[d]^\\mu \\\\\n\tX \\times X \\ar[r]_\\mu & X\n}\n\\]\nA map $\\nu : X \\rightarrow X$ is said to be a \\emph{homotopy inverse} for $\\mu$ if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX \\ar[r]^-{\\nu \\times \\id} \\ar[rd]_{x_0} & X \\times X \\ar[d]_\\mu & X \\ar[l]_-{\\id \\times \\nu} \\ar[dl]^{x_0} \\\\\n\t& X &\n}\n\\]\nWe say that $(X,x_0)$ is an \\textbf{$H$-group} if it has a multiplication $\\mu$ with homotopy identity and inverse $\\nu$ such that $\\mu$ is homotopy associative. Further, we say that $X$ is a \\textbf{commutative $H$-group} if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n{\n\tX \\times X \\ar[rr]^-\\tau \\ar[rd]_\\mu & & X \\times X \\ar[dl]^\\mu \\\\\n\t & X\n}\n\\]\nwhere $\\tau$ is the flip map $\\tau(x,y) = (y,x)$. We think of $H$-groups as groups where the axioms only have to hold up to homotopy. An \\textbf{$H$-homomorphism} between $H$-groups $(X,x_0,\\mu_X)$ and $(Y,y_0,\\mu_Y)$ is a based map $f : X \\rightarrow Y$ such that the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=3pc\n{\n\tX \\times X \\ar[r]^-{\\mu_X} \\ar[d]_{f \\times f} & X \\ar[d]^f \\\\\n\tY \\times Y \\ar[r]_{\\mu_Y} & Y\n}\n\\]\n\nBy reversing all arrows and replacing products with coproducts we get the dual notion of $H$-cogroups, but we will also spell out the details. Let $(X,x_0)$ be a pointed space and let $x_0$ also denote the constant map. A map $\\mu' : X \\rightarrow X \\vee X$ is said to be a \\emph{comultiplication with homotopy coidentity $x_0$} if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX & X \\vee X \\ar[l]_-{\\id \\vee x_0} \\ar[r]^-{x_0 \\vee \\id} & X \\\\\n\t   & X \\ar[lu]^\\id \\ar[ru]_\\id \\ar[u]^{\\mu'}\n}\n\\]\nwhere $\\id \\vee x_0$ is the map induced by $\\id$ and $x_0$ from the universal property of coproducts. We say that $\\mu$ is \\emph{homotopy coassociative} if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX \\vee X \\vee X & X \\vee X \\ar[l]_-{\\id \\vee \\mu'} \\\\\n\tX \\vee X \\ar[u]^{\\mu' \\vee \\id} & X \\ar[u]_{\\mu'} \\ar[l]^-{\\mu'}\n}\n\\]\nA map $\\nu' : X \\rightarrow X$ is said to be a \\emph{homotopy coinverse} for $\\mu'$ if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=4pc\n{\n\tX & X \\vee X \\ar[l]_{\\nu' \\vee \\id} \\ar[r]^{\\id \\vee \\nu'} & X \\\\\n\t  & X \\ar[ul]^{x_0} \\ar[ur]_{x_0} \\ar[u]^{\\mu'}\n}\n\\]\nWe say that $(X,x_0)$ is an \\textbf{$H$-cogroup} if it has a comultiplication $\\mu'$ with homotopy coidentity and coinverse $\\nu'$ such that $\\mu'$ is homotopy coassociative. Further, we say that $X$ is a \\textbf{cocommutative $H$-cogroup} if the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n{\n\tX \\vee X \\ar[rr]^-\\tau & & X \\vee X \\\\\n\t& X \\ar[ul]^{\\mu'} \\ar[ur]_{\\mu'}\n}\n\\]\nwhere $\\tau$ is the flip map $\\tau(x,x_0) = (x_0,x)$ and $\\tau(x_0,x) = (x,x_0)$. An \\textbf{$H$-cohomomorphism} between $H$-cogroups $(X,x_0,\\mu_X')$ and $(Y,y_0,\\mu_Y')$ is a based map $f : X \\rightarrow Y$ such that the following diagram commutes up to homotopy\n\\[\n\\xymatrix\n@R=3pc\n@C=3pc\n{\n\tX \\vee X \\ar[d]_{f \\vee f} & X \\ar[l]_-{\\mu_X'} \\ar[d]^f \\\\\n\tY \\vee Y & Y \\ar[l]^-{\\mu_Y'}\n}\n\\]\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\comment{\n\\note{should all the stuff down here just be in the next section?}\n\nGiven two paths $\\alpha,\\beta : I \\rightarrow X$ such that $\\alpha(1) = \\beta(0)$, we can define their juxtaposition to be the path $\\beta*\\alpha : I \\rightarrow X$ defined by\n\\[ (\\beta * \\alpha)(t) = \\begin{cases} \\alpha(2t) & 0 \\leq t \\leq 1/2 \\\\ \\beta(2t-1) & 1/2 \\leq t \\leq 1 \\end{cases} \\]\nThis just means to traverse $\\alpha$ at double speed for half the time, and then traverse $\\beta$ at double speed for the rest of the time. If $\\alpha : I \\rightarrow X$ is a path from $a$ to $b$, then we define its \\emph{reverse} to be the path $\\overline\\alpha(t) = \\alpha(1-t)$, which goes from $b$ to $a$. Note that the loops $\\overline\\alpha * \\alpha$ and $\\alpha * \\overline\\alpha$ are homotopic to the constant loop relative end points. For a topological space $X$ we define $\\Pi(X)$, called the \\textbf{fundamental groupoid}, to be the category with objects points in $X$ and morphisms homotopy classes of paths relative end points. There is a lot more that can be said about these operations and constructions, but it will be covered in much greater generality in \\cref{H-groups and H-cogroups}. \n\n% This operation is not associative, but we do have $\\gamma * (\\beta * \\alpha) \\simeq (\\gamma * \\beta) * \\alpha (\\rel \\lcb 0,1 \\rcb)$, whenever this is defined. If we let $P_{a,b} X$ denote the space of paths that start at $a$ and end at $b$, then this operation is a map $* : P_{a,b} X \\times P_{b,c} X \\rightarrow P_{a,c} X$. In fact, this operation descends to the space of homotopy classes of paths relative end points. \n}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n\\begin{prop}\n\\sloppyspace\n\\begin{enumerate}\n\t\\item The based loop space $\\Omega_* X$ has a canonical $H$-group structure. Also, $\\Omega_* f$ is an $H$-group homomorphism for any based map $f : X \\rightarrow Y$.\n\t\\item The based suspension $\\Sigma_* X$ has a canonical $H$-cogroup structure. Also, $\\Sigma_* f$ is an $H$-cogroup cohomomorphism for any based map $f : X \\rightarrow Y$.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n\\sloppyspace\n\\begin{enumerate}\n\n\t\\item Let $\\alpha,\\beta$ be two paths in $X$ based at $x_0$. We define their product $\\mu(\\alpha,\\beta) = \\beta * \\alpha$ to be the path\n\t\\[ (\\beta * \\alpha)(t) = \\begin{cases} \\alpha(2t) & 0 \\leq t \\leq 1/2 \\\\ \\beta(2t-1) & 1/2 \\leq t \\leq 1 \\end{cases} \\]\n\tThis just means to traverse $\\alpha$ at double speed for half the time, and then traverse $\\beta$ at double speed for the rest of the time. First we show that the constant loop $x_0$ is a homotopy identity for $*$. We can find a homotopy $H$ between $\\alpha$ and $\\alpha * x_0$ by defining\n\t\\[ H(s,t) = \\begin{cases} x_0 & 0 \\leq s \\leq \\frac{t}{2} \\\\ \\alpha\\left( \\frac{2s-t}{2-t} \\right) & \\frac{t}{2} \\leq s \\leq 1 \\end{cases} \\]\n\tA similar homotopy can be defined to show $\\alpha \\simeq x_0 * \\alpha$, so $x_0$ is a homotopy identity for $*$. We define the homotopy inverse by $\\nu(\\alpha)(t) = \\overline{\\alpha}(t) = \\alpha(1-t)$. To show this is indeed the inverse, we use the following homotopy between $x_0$ and $\\alpha * \\overline\\alpha$\n\t\\[ H(s,t) = \\begin{cases} \\alpha(2st) & 0 \\leq s \\leq \\frac{1}{2} \\\\ \\alpha(2t(1-s)) & \\frac{1}{2} \\leq s \\leq 1 \\end{cases} \\]\n\tWe can do something similar to show $x_0 \\simeq \\overline\\alpha * \\alpha$. Finally, to show $*$ is homotopy associative we use the following homotopy between $\\gamma * (\\beta * \\alpha)$ and $(\\gamma * \\beta) * \\alpha$\n\t\\[ H(s,t) = \\begin{cases} \\end{cases} \\]\n\tFor a based map $f : X \\rightarrow Y$ we clearly have $f(\\beta*\\alpha) = f(\\beta) * f(\\alpha)$, so $\\Omega_* f$ is an $H$-group homomorphism.\n\t\n\t\\item Thinking of $\\Sigma_* X$ as $X \\times I / X \\times \\lcb 0,1 \\rcb \\cup \\lcb x_0 \\rcb \\times I$, we define the coproduct of $[x,t]$ to be\n\t\\[ \\mu'([x,t]) = \\begin{cases} ([x,2t],x_0) & 0 \\leq t \\leq \\frac{1}{2} \\\\ (x_0,[x,2t-1]) & \\frac{1}{2} \\leq t \\leq 1 \\end{cases} \\]\n\tThe inverse is defined by $\\nu'([x,t]) = [x,1-t]$. The homotopies that show these operations make $\\Sigma_* X$ into an $H$-cogroup are essentially the same as the homotopies we used for $\\Omega_* X$.\n\t\n\\end{enumerate}\n\\end{proof}\n\n\n\\begin{prop}\nLet $(X,x_0)$ be an $H$-cogroup and $(Y,y_0)$ an $H$-group. Then for any based spaces $(Z,z_0)$ and $(W,w_0)$ and based map $f : Z \\rightarrow W$ we have\n\\begin{enumerate}\n\t\\item The set $[(Z,z_0),(Y,y_0)]$ has a canonical group structure, and the induced map $f_* : [(W,w_0),(Y,y_0)] \\rightarrow [(Z,z_0),(Y,y_0)]$ is a homomorphism of groups.\n\t\\item The set $[(X,x_0),(Z,z_0)]$ has a canonical group structure, and the induced map $f_* : [(X,x_0),(Z,z_0)] \\rightarrow [(X,x_0),(W,w_0)]$ is a homomorphism of groups.\n\t\\item The group structures induced on $[(X,x_0),(Y,y_0)]$ by the above are \\emph{equal} (not just isomorphic), and this group is abelian.\n\\end{enumerate}\n\\end{prop}\n\\begin{proof}\n\\sloppyspace\n\\begin{enumerate}\n\n\t\\item Let $\\mu$ and $\\nu$ denote the $H$-group operations on $Y$. Given two maps $f,g : (Z,z_0) \\rightarrow (Y,y_0)$, we define their product $g * f$ as the composition\n\t\\[ Z \\stackrel{\\Delta}{\\longrightarrow} Z \\times Z \\stackrel{f \\times g}{\\longrightarrow} Y \\times Y \\stackrel{\\mu}{\\longrightarrow} Y \\]\n\twhere $\\Delta$ is the diagonal map $\\Delta(z) = (z,z)$. Note that we have switched the order of $f$ and $g$ in this composition since intuitively we want to think of $g * f$ as first apply $f$, then apply $g$. The inverse of $f$ is defined as $f^{-1} = \\nu \\circ f$, and the identity is the constant map $[c_{x_0}]$ at $x_0$. This operation descends to the homotopy classes of maps $[Z,Y]_*$, for if $F$ is a based homotopy between $f$ and $f'$ and $G$ is a based homotopy between $g$ and $g'$, then\n\t\\[ K(z,t) = \\mu(F(z,t),G(z,t)) \\]\n\tis a homotopy between $g * f$ and $g' * f'$, and\n\t\\[ I(z,t) = \\nu(F(z,t)) \\]\n\tis a homotopy between $\\nu \\circ f$ and $\\nu \\circ f'$. Show that these operations satisfy the group axioms is obvious.\n\t\n\t\\item Let $\\mu'$ and $\\nu'$ denote the $H$-cogroup operations on $X$. Given two maps $f,g : (X,x_0) \\rightarrow (Z,z_0)$, we define their product $g \\cdot f$ as the composition\n\t\\[ X \\stackrel{\\mu'}{\\longrightarrow} X \\vee X \\stackrel{f \\vee g}{\\longrightarrow} Z \\vee Z \\stackrel{\\Delta'}{\\longrightarrow} Z \\]\n\twhere $\\Delta'$ is the folding map $\\Delta'(z,z_0)=z=\\Delta'(z_0,z)$. Note that we have switched the order of $f$ and $g$ in this composition since intuitively we want to think of $g \\cdot f$ as first apply $f$, then apply $g$. The inverse of $f$ is defined as $f^{-1} = f \\circ \\nu'$, and the identity is the constant map $c_{x_0}$ at $x_0$. Showing that this operation descends to $[X,Z]_*$ is essentially the same as before, and the group axioms obviously hold.\n\t\n\t\\item We can see from the above that the homotopy class of the constant map $[x_0]$ is a mutual identity for $*$ and $\\cdot$. A very lengthly calculation shows that the operations distribute over each other, i.e. $([f] \\cdot [g]) * ([h] \\cdot [k]) = ([f] * [h]) \\cdot ([g] \\cdot [k])$. So the result follows from the following general lemma.\n\t\n\\end{enumerate}\n\\end{proof}\n\n\\begin{lem}[Eckmann-Hilton Principle]\n\\label{Eckmann-Hilton Principle}\n\\label{set with two binary operations}\nIf a set $X$ has two binary operations $\\cdot$ and $*$ defined such that the following holds.\n\\begin{enumerate}\n\t\\item There exists a mutual identity $e$, i.e. $x \\cdot e = e \\cdot x = x = x * e = e * x$.\n\t\\item The operations distribute over each other, i.e. $(x \\cdot y) * (w \\cdot z) = (x * w) \\cdot (y * z)$.\n\\end{enumerate}\nThen the binary operations are equal, associative and commutative.\n\\end{lem}\n\\begin{proof}\nThe operations are equal since\n\\[ x \\cdot y = (x * e) \\cdot (y * e) = (x * y) \\cdot (e * e) = x * y \\]\nAssociativity follows from\n\\[ x * (y * z) = (x \\cdot e) * (y \\cdot z) = (x * y) \\cdot (e * z) = (x \\cdot y) \\cdot z \\]\nCommutativity follows from\n\\[ x \\cdot y = (x * e) \\cdot (y * e) = (e * x) \\cdot (y * e) = (e \\cdot y) * (x * e) = y * x = y \\cdot x \\]\n\\end{proof}\n\nThus we have that $[-,(Y,y_0)] : \\hTopp \\rightarrow \\Grp$ is a cofunctor if $Y$ is an $H$-group, and $[(X,x_0),-] : \\hTopp \\rightarrow \\Grp$ is a functor if $X$ is an $H$-cogroup. \n\n\n\n\n\n\n\\newpage\n\\section{Fibrations}\n\n\\subsection{The Universal Test Diagram}\n\nIn geometry one naturally comes across fiber bundles when a collection of spaces is parameterized by another space. We want such a thing in homotopy theory too, but requiring local triviality is far too restrictive for the homotopy category. However, fiber bundles have another property  that is homotopy theoretic, called the homotopy lifting property. A continuous map $p : E \\rightarrow B$ is said to have the \\textbf{homotopy lifting property} with respect to a space $X$ if for every continuous map $H : X \\times I \\rightarrow B$ and $f : X \\rightarrow E$ there is a map $\\tilde{H} : X \\times I \\rightarrow E$ such that the following diagram commutes\n\\begin{equation}\n\\label{fibration test diagram}\n\\xymatrix\n@R=2.5pc\n@C=2.5pc\n{\n\tX \\ar[d]_{i_0} \\ar[r]^f & E \\ar[d]^{p} \\\\\n\tX \\times I \\ar[r]_H \\ar@{-->}[ru]^{\\tilde H} & B\n}\n\\end{equation}\nwhere $i_0$ is the inclusion of $X$ into $X \\times \\lcb 0 \\rcb$. We call this a \\emph{test diagram} for the homotopy lifting problem. Commutativity of the lower triangle means that $\\tilde H_t$ is a left of $H_t$ for all time $t$, and commutativity of the upper triangle means that the initial lift $\\tilde H_0$ is precisely the given map $f$. We say that $p : E \\rightarrow B$ is a \\textbf{fibration} if it has the homotopy lifting property with respect to all spaces $X$, and we say it is a \\textbf{Serre fibration} if it has the homotopy lifting property with respect to all discs $D^n$. Clearly such a map must be surjective. The fiber over a point $b \\in B$ in the base is denoted by $E_p = p^{-1}(b)$.\n\n\\begin{example}\n\\label{loop space and path space fibrations}\nThe prototypical example of a fibration is the \\emph{path space fibration}. Let $e_0 : B^I \\rightarrow B$ be evaluation at 0, $e_0(\\alpha)=\\alpha(0)$. Consider the homotopy lifting problem\n\\begin{equation}\n\\label{path space fibration test diagram}\n\\xymatrix\n@R=2.5pc\n@C=2.5pc\n{\n\tX \\ar[d]_{i_0} \\ar[r]^f & B^I \\ar[d]^{e_0} \\\\\n\tX \\times I \\ar[r]_-H \\ar@{-->}[ur]^{\\tilde H} & B\n}\n\\end{equation}\nWe need to construct $\\tilde H$ such that $\\tilde H(x,0)(s) = f(x)(s)$ and $\\tilde H(x,t)(0) = H(x,t)$. The following function accomplishes this\n\\begin{equation}\n\\label{homotopy interpolation trick}\n\\tilde H(x,t)(s) = \\begin{cases} H(x,1-(1+t)s) & 0 \\leq s \\leq \\frac{1}{1+t} \\\\ f(x)((1+t)s) & \\frac{1}{1+t} \\leq s \\leq 1 \\end{cases}\n\\end{equation}\nThis function is continuous since on the overlaps $s=\\frac{1}{1+t}$ we have that the first piece is $H(x,0)$ and the second piece is $f(x)(0)$, which are equal by commutativity of \\eqref{path space fibration test diagram}. Therefore $e_0 : B^I \\rightarrow I$ is a fibration. The fiber $p^{-1}(b)$ of any point in the base is the space of paths in $B$ that start at $b$, i.e. $(B,b)^{(I,0)}$. \n\nThe same argument shows that $e_0 : (B,b_0)^{(I,1)} \\rightarrow (B,b_0)$ is a fibration, called the \\emph{based path space fibration}. The fiber over some point $b \\in B$ is the space of paths starting at $b$ and ending at $b_0$. In particular, the fiber over $b_0$ is just the based loop space $\\Omega_* (B,b_0)$.\n\\end{example}\n\n\\begin{prop}\nA fiber bundle over a paracompact space is a fibration.\n\\end{prop}\n\n\\begin{prop}\nThe pullback of a fibration is a fibration.\n\\end{prop}\n\\begin{proof}\nLet $p : E \\rightarrow B$ be a fibration and let $g : Y \\rightarrow B$ be continuous. Consider the following test diagram for a homotopy lifting problem juxtaposed with the pullback square\n\\[\n\\xymatrix\n@R=3pc\n@C=3pc\n{\n\tX \\ar[d]_{i_0} \\ar[r]^-f & E \\times_B Y \\ar[d]_{p'} \\ar[r]^-{g'} & E \\ar[d]^p \\\\\n\tX \\times I \\ar[r]_-H & Y \\ar[r]_g & B\n}\n\\]\nThen the homotopy lifting problem $g \\circ H$ and $g' \\circ f$ can be solved since $E \\rightarrow B$ is a fibration, so we get a map $G : X \\times I \\rightarrow E$ such that $G \\circ i_0 = g' \\circ f$ and $p \\circ G = g \\circ H$. But, the maps $G$ and $H$ induce a map $\\tilde H : X \\times I \\rightarrow E \\times_B Y$ uniquely determined by the property that $p' \\circ \\tilde H = H$ and $g' \\circ \\tilde H = G$ (by the universal property of pullbacks). See the diagram\n\\[\n\\xymatrix\n@R=1pc\n@C=1pc\n{\n\t&  &  &  & & \\\\\n\t& X \\ar[dd]_{i_0} \\ar[rr]^-f & & E \\times_B Y \\ar[dd]_{p'} \\ar[rr]^-{g'} & & E \\ar[dd]^p \\\\\n\t& \\\\\n\t& X \\times I \\ar[rr]_-H \\ar@{-->}[uurr]^{\\tilde H} \\ar@{-->}`l/2pt[l]`u[luuu]`r[rrrruuu]^{G}[rrrruu] & & Y \\ar[rr]_g & & B\n}\n\\]\nBy the universal property of pullbacks we have that $f$ is the unique map that satisfies $p' \\circ f = H \\circ i_0$. However, $\\tilde H \\circ i_0$ satisfies this equation since $p' \\circ \\tilde H \\circ i_0 = H \\circ i_0$, hence $\\tilde H \\circ i_0 = f$, and we have shown that $p' : E \\times_B Y \\rightarrow Y$ is a fibration.\n\\end{proof}\n\nThere is a universal test diagram such that if it has a solution, then all test diagrams will have a solution. First note that by using the adjoint of $- \\times I$, which is $-^I$, we can rewrite the test diagram \\eqref{fibration test diagram} as\n\\begin{equation}\n\\label{alternative fibration test diagram}\n\\xymatrix\n{\n\tE \\ar[dd]_p &   & E^I \\ar[dd]^{p^I} \\ar[ll]_{e_0} \\\\\n\t  & X \\ar[ul]^f \\ar[rd]_H \\ar@{-->}[ru]^{\\tilde H} & \\\\\n\tB &   & B^I \\ar[ll]^{e_0}\n}\n\\end{equation}\nwhere $e_0$ denotes the evaluation at $t=0$ map. \n\n\\begin{prop}\nLet $p : E \\rightarrow B$ be a map and let $e_0' : E \\times_B B^I \\rightarrow E$ and $p' : E \\times_B B^I \\rightarrow B^I$ denote the induced maps by the pullback of $E \\stackrel{p}{\\rightarrow} B \\stackrel{e_0}{\\leftarrow} B^I$. If \\eqref{alternative fibration test diagram} can be solved for $X = E \\times_B B^I$, $f = e_0'$ and $H = p'$, then any test diagram can be solved.\n\\end{prop}\n\\begin{proof}\nLet $\\tilde H$ be a solution of \\eqref{alternative fibration test diagram} for $X = E \\times_B B^I$, $f=e_0'$ and $H=p'$. Then take any other space $X$ and consider its test diagram. By the universal property of pullbacks there is a unique map $\\varepsilon : X \\rightarrow E \\times_B B^I$ making the following commute\n\\[\n\\xymatrix\n{\n\tE \\ar[ddd]_p & & & E^I \\ar[ddd]^{p^I} \\ar[lll]_{e_0} \\\\\n\t  & & E \\times_B B^I \\ar[ull]^{e_0'} \\ar[rdd]_{p'} \\ar@{-->}[ru]^{\\tilde H} & \\\\\n\t  & X \\ar@{-->}[ur]^\\varepsilon \\ar[uul]^f \\ar[drr]_H & & \\\\\n\tB & & & B^I \\ar[lll]^{e_0}\n}\n\\]\nClearly $\\tilde H \\circ \\varepsilon$ is now a solution of the diagram for $X$. \n\\end{proof}\n\n\nTherefore if \\ref{alternative fibration test diagram} can be solved for $E \\times_B B^I$, then it can be solved for any space, and so $p : E \\rightarrow B$ would be a fibration. If $f : X \\rightarrow Y$ is any map (not necessarily a fibration), then the pullback $X \\times_Y Y^I$ is called the \\textbf{mapping path space} of $f$, and concretely is defined as\n\\begin{equation}\n\\label{mapping path space}\nP_f = \\lcb (x,\\alpha) \\in X \\times Y^I \\st f(x) = \\alpha(0) \\rcb\n\\end{equation}\n\nFor a map $p : E \\rightarrow B$ (not necessarily a fibration), let $s : E^I \\rightarrow P_p$ be the function $s(\\alpha) = (\\alpha(0), p \\circ \\alpha)$. A function $\\lambda : P_p \\rightarrow E^I$ such that $s \\circ \\lambda = \\id$ is called a \\textbf{path lifting function}. Given the initial data $(e,\\alpha) \\in E \\times B^I$ such that $\\alpha(0)=p(e)$, it gives us a lift to a path $\\tilde\\alpha = \\lambda(e,\\alpha)$ such that $\\tilde\\alpha(0)=e$ and $p \\circ \\tilde\\alpha = \\alpha$. \n\\begin{cor}\nA map $p : E \\rightarrow B$ is a fibration if and only if it has a path lifting function.\n\\end{cor}\n\\begin{proof}\nPath lifting functions provide solutions to the universal test diagram and conversely.\n\\end{proof}\n\n\n\\begin{example}\nLet $p : D^2 \\rightarrow D^1$ be the map $p(x,y) = x$, i.e. the projection of the unit disc onto the unit interval. This is clearly not a fiber bundle since $p^{-1}(1)$ is a point and $p^{-1}(0)$ is an interval. However, it is a fibration as it is easy to construct a path lifting function. \n\\end{example}\n\n\\subsection{The Homotopy Fiber}\n\nLocal triviality in fiber bundles gives us that the fiber above all points in the base space are homeomorphic (assuming the base is path connected). We will not have this with our weakened notion of fibration, but we get something good enough for homotopy theory. Let $\\alpha : I \\rightarrow B$ be a path, and consider the diagram\n\\begin{equation}\n\\label{translation of fibers diagram}\n\\xymatrix\n@R=3pc\n@C=3pc\n{\n\tE_{\\alpha(0)} \\ar@{^{(}->}[rr]^-i \\ar[d]_{i_0} &  & E \\ar[d]^p \\\\\n\tE_{\\alpha(0)} \\times I \\ar[r]_-{\\pi_I} \\ar@{-->}[urr]^{\\tilde H} & I \\ar[r]_\\alpha & B\n}\n\\end{equation}\nso that the composition of the bottom row is just the constant homotopy $(e,t) \\mapsto \\gamma(t)$. We can solve this homotopy lifting problem since $p$ is a fibration, so let $\\tilde H$ be this lifted homotopy. Then, since $p \\circ \\tilde H_1 = \\alpha(1)$ we have that $\\tilde H_1$ maps $E_{\\alpha(0)}$ to $E_{\\alpha(1)}$. Let $\\alpha_*$ denote this map; it is called the \\emph{translation of fibers} along $\\alpha$.\n\\begin{prop}\n\\label{fibration fibers are homotopy equivalent}\nThe map $\\alpha_* : E_{\\alpha(0)} \\rightarrow E_{\\alpha(1)}$ depends only on the homotopy class of $\\alpha$ relative end points, and is a homotopy equivalence. Further, if $\\gamma$ is a curve with $\\alpha(1) = \\gamma(0)$, then $(\\gamma * \\alpha)_* \\simeq \\gamma_* \\circ \\alpha_*$.\n\\end{prop}\n\\begin{proof}\nLet $\\alpha,\\beta : I \\rightarrow B$ be curves from $a$ to $b$ that are homotopic relative end points. Let $F : I \\times I \\rightarrow B$ be such a homotopy, i.e. $F_0 = \\alpha$ and $F_1 = \\beta$. These curves determine homotopies $\\tilde H^\\alpha, \\tilde H^\\beta : E_a \\times I \\rightarrow E$ that lift \n$\\alpha \\circ \\pi_I$ and $\\beta \\circ \\pi_I$ respectively. We want to show that $\\tilde H_1^\\alpha$ is homotopic to $\\tilde H_1^\\beta$, and that both of these maps are homotopy equivalences. If we let $J$ be the space\n\\[ J = \\lcb 0,1 \\rcb \\times I \\cup I \\times \\lcb 0 \\rcb \\subset I^2 \\]\nthen there is a homeomorphism of pairs $\\varphi : (I^2,I \\times \\lcb 0 \\rcb) \\rightarrow (I^2,J)$. Note that this homeomorphism of pairs implies $\\iota \\circ \\varphi = i_0$, where $\\iota$ is the inclusion $E_a \\times J \\hookrightarrow E_a \\times I \\times I$ and $i_0$ is the inclusion $E_a \\times I \\times \\lcb 0 \\rcb \\hookrightarrow E_a \\times I \\times I$. \n\nLet $f : E_a \\times J \\rightarrow E$ be the map that is $\\tilde H^\\alpha$ on $E_a \\times \\lcb 0 \\rcb \\times I$, $\\tilde H^\\beta$ on $E_a \\times \\lcb 1 \\rcb \\times I$, and $i \\circ \\pi_I$ on $E_a \\times I \\times \\lcb 0 \\rcb$. Then the following homotopy lifting problem\n\\[\n\\xymatrix\n@C=2.5pc\n@R=3pc\n{\n\tE_a \\times I \\times \\lcb 0 \\rcb \\ar[d]_{i_0} \\ar[r]^-\\varphi & E_a \\times J \\ar[r]^-f \\ar[dl]_{\\iota} & E \\ar[d]^p \\\\\n\tE_a \\times I \\times I \\ar[r]_-{\\pi_{I \\times I}} \\ar@{-->}[rru]^{\\tilde F} & I \\times I \\ar[r]_-F & B\n}\n\\]\ncan be solved to give a map $\\tilde F : E_a \\times I \\times I \\rightarrow E$ such that the whole diagram commutes. But then we see that $\\tilde F = f$ when restricted to $E_a \\times J$, so we have $\\tilde F(e,0,1) = f(e,0,1) = \\tilde H_1^\\alpha$ and $\\tilde F(e,1,1) = f(e,1,1) = \\tilde H_1^\\beta$, hence $\\tilde F(-,-,1) : E_a \\times I \\rightarrow E_b$ is a homotopy between $\\tilde H_1^\\alpha$ and $\\tilde H_1^\\beta$.\n\nIf $c_a$ denotes the constant path at $a$, then $c_{a*} : E_a \\rightarrow E_a$ is just the identity since the constant homotopy $(e,t) \\mapsto e$ is a lift in \\eqref{translation of fibers diagram}. If $\\gamma$ is a curve with $\\alpha(1)=\\gamma(0)$ and $\\tilde H^\\alpha$ and $\\tilde H^\\gamma$ are lifts like in \\eqref{translation of fibers diagram}, then $\\tilde H^\\gamma * \\tilde H^\\alpha$ is a lift of $\\gamma * \\alpha$, where this juxtaposition happens in the second variable. Therefore $(\\gamma * \\alpha)_* \\simeq \\gamma_* \\circ \\alpha_*$. Finally, we have $\\id_{E_a} \\simeq (c_a)_* \\simeq (\\alpha * \\overline\\alpha)_* = \\alpha_* \\circ \\overline\\alpha_*$, and similarly the other way around, so $\\alpha_*$ and $\\overline\\alpha_*$ are homotopy inverses of each other.\n\\end{proof}\n\n\\begin{cor}\n\\label{fiber of a fibration}\nAll fibers of a fibration over a path connected space are homotopy equivalent.\n\\end{cor}\n\n\\begin{cor}\nThe association $\\alpha \\mapsto \\alpha_*$ defines a functor $\\Pi(B) \\rightarrow \\hTop$. In particular, it defines a group homomorphism $\\pi_1(B) \\rightarrow \\Aut_{\\hTop}(E_a)$.\n\\end{cor}\n\nIn view of \\cref{fiber of a fibration}, we call the pre-image of any point in the base the \\textbf{fiber} of the fibration, although this definition only makes sense \\emph{up to homotopy}. A morphism of fibrations $p : E \\rightarrow B$ and $p' : E' \\rightarrow B'$ is a pair of maps $f : E \\rightarrow E'$ and $f' : B \\rightarrow B'$ such that $f' \\circ p = p' \\circ f$. Thus we can define the category of fibrations, denoted by $\\Fib{}$, and it is easy to see that the categorical product in $\\Fib{}$ is just $E \\times E' \\stackrel{p \\times p'}{\\longrightarrow} B \\times B'$. We will usually be concerned with the morphisms of fibrations that are of the form $B=B'$ and $f'=\\id$. We denote the full subcategory of fibrations over $B$ by $\\Fib{B}$. By thinking of the identity map on $I$ as a fibration, we can define the notation of a homotopy between morphisms in $\\Fib{}$, which we will call a \\textbf{fiber homotopy}, as well as fiber homotopy equivalences. The following is a useful result, but the proof is long, so we omit it.\n\n\\begin{prop}\n\\label{homotopy equivalence of fibrations is a fiber homotopy equivalence}\nIf $p : E \\rightarrow B$ and $p' : E' \\rightarrow B$ are fibrations, and $f : E \\rightarrow E'$ a homotopy equivalence such that $p = p' \\circ f$, then $f$ is a fiber homotopy equivalence.\n\\end{prop}\nThis theorem is somewhat surprising. Since $f$ is a homotopy equivalence, we can find a homotopy inverse $g : E' \\rightarrow E$, but there is no guarantee that $g$ preserves the fibers. This proposition ensures that we can homotope $g$ to make it preserve the fibers.\n\nThere is a canonical way of converting any map $f : X \\rightarrow Y$ into a fibration, at least up to homotopy. Consider the maps $h : X \\rightarrow P_f$, $h(x) = (x,c_{f(x)})$, and $p : P_f \\rightarrow Y$, $p(x,\\alpha)$, $p(x,\\alpha)=\\alpha(1)$, where $c_{f(x)}$ denotes the constant path at $f(x)$. Then the composition $X \\stackrel{h}{\\rightarrow} P_f \\stackrel{p}{\\rightarrow} Y$ is equal to $f$. \n\\begin{prop}\n\\label{canonical fibration}\n$h$ is a homotopy equivalence and $p$ is a fibration. If $f$ is already a fibration, then $h$ is a fiber homotopy equivalence between the fibrations $f$ and $p$.\n\\[\n\\xymatrix\n{\n\tX \\ar[rr]^h \\ar[rd]_f & & P_f \\ar[ld]^p \\\\\n\t& Y &\n}\n\\]\n\\end{prop}\n\\begin{proof}\nLet $k : P_f \\rightarrow X$ be defined by $k(x,\\alpha) = x$. Then $k \\circ h = \\id$, and $h \\circ k \\simeq \\id$ via the homotopy $H : P_f \\times I \\rightarrow X$\n\\[ H((x,\\alpha),t) = (x,\\alpha^t) \\]\nwhere $\\alpha^t$ is the path defined by $\\alpha^t(s)=\\alpha(st)$. We can easily see that $H_0 = h \\circ k$ and $H_1 = \\id$, so $h$ is a homotopy equivalence.\n\nTo see that $p$ is a fibration, consider the following test diagram\n\\[\n\\xymatrix\n@R=2.5pc\n@C=2.5pc\n{\n\tX \\ar[r]^g \\ar[d]_{i_0} & P_f \\ar[d]^p \\\\\n\tX \\times I \\ar[r]_-H \\ar@{-->}[ru]^-{\\tilde H} & Y\n}\n\\]\nWe can write $g(x) = (g_1(x),g_2(x))$, where $g_1 : X \\rightarrow X$ and $g_2 : X \\rightarrow Y^I$, and such that $f(g_1(x)) = g_2(x)(0)$. Similarly, the lift $\\tilde H : X \\times I \\rightarrow P_f$ that we need to construct will have two components $\\tilde H(x,t) = (\\tilde H_1(x,t),\\tilde H_2(x,t))$, where $\\tilde H_1 : X \\times I \\rightarrow X$ and $\\tilde H_2 : X \\times I \\rightarrow Y^I$. Commutativity of the upper triangle means we need $\\tilde H_1(-,0)=g_1, \\tilde H_2(-,0)=g_2$, and commutativity of the lower triangle means we need $\\tilde H_2(x,t)(1)=H(x,t)$. \n\nSo, we can just take $\\tilde H_1$ to be the constant homotopy $\\tilde H_1(x,t) = g_1(x)$. To define $\\tilde H_2$ we use the standard trick for interpolating between two functions that we used in \\eqref{homotopy interpolation trick}. In particular, we define\n\\[ \\tilde H_2(x,t)(s) = \\begin{cases} g_2(x)((1+t)s) & 0 \\leq s \\leq \\frac{1}{1+t} \\\\ H(a,(1+t)s-1) & \\frac{1}{1+t} \\leq s \\leq 1 \\end{cases} \\]\nIt is easy to see that this satisfies the conditions we need, and it is continuous on the overlap $s = \\frac{1}{1+t}$ since $g_2(x)(1) = H(a,0)$ by commutativity of the square in the test diagram.\n\\end{proof}\n\nSo, every map can be factored into a homotopy equivalence followed by a fibration, and we call it the \\textbf{canonical fibration} of $f$. We define the \\textbf{homotopy fiber} of any map $f : X \\rightarrow Y$ to be the fiber of its canonical fibration, and we denote it by $F_f$. Note that the homotopy fiber is precisely the pullback of the based path space fibration $e_0 : (Y,y_0)^{(I,1)} \\rightarrow (Y,y_0)$ along the map $f$, which is just\n\\begin{equation}\n\\label{homotopy fiber of a map}\nF_f = \\lcb (x,\\alpha) \\in X \\times Y^I \\st \\alpha(0) = f(x) \\text{ and } \\alpha(1)=y_0 \\rcb\n\\end{equation}\nIf $f$ is already a fibration, then the homotopy fiber is homotopy equivalent to the fiber of the fibration, and clearly fibrations that are fiber homotopy equivalent have homotopy equivalent fibers. \\Cref{canonical fibration} gives another meaning to the universality of the mapping path space $P_f$ as it is used to canonically convert any map into a fibration.\n\n\n\\begin{prop}\n\\label{homotopy fiber of fiber inclusion}\nLet $(E,e_0) \\stackrel{p}{\\rightarrow} (B,b_0)$ be a fibration with fiber $F=p^{-1}(b_0)$ based at $e_0$. Then the homotopy fiber of $F \\hookrightarrow E$ is homotopy equivalent to $\\Omega_* B$.\n\\end{prop}\n\\begin{proof}\nVerifying this directly is difficult because a concrete description of the homotopy fiber of $F \\hookrightarrow E$ in terms of $E$ and $B$ is quite messy. Instead, we find a simpler fibration that is fiber homotopy equivalent to the canonical fibration of $F \\hookrightarrow E$, and its fiber will be easier to compute. Since $p$ is a fibration, we can find a path lifting function $\\lambda : P_p \\rightarrow E^I$ such that $s \\circ \\lambda = \\id$, where $s(\\alpha)=(\\alpha(0),p \\circ \\alpha)$.\n\nConvert the inclusion $i : F \\hookrightarrow E$ into a fibration $q : P_i \\rightarrow E$, where $P_i \\simeq F$, and let $F_p$ be the homotopy fiber of $p : E \\rightarrow B$, with map $\\pi : F_p \\rightarrow E$ defined by $\\pi(e,\\beta)=e$. We already know that $\\pi$ is a fibration (being a pullback of the based path space fibration), and we claim that $\\pi$ is fiber homotopy equivalent to $q$. We define maps $g : P_i \\rightarrow F_p$ and $h : F_p \\rightarrow P_i$ by\n\\[ g(e,\\alpha) = (e,c_{b_0}) \\]\n\\[ h(e,\\beta) = \\left( \\lambda(e,\\beta)(1), c_{\\lambda(e,\\beta)(1)} \\right) \\]\nFirst we check that these maps do in fact map into their respective targets. If $(e,\\alpha) \\in P_i$, then $e \\in F$ and $\\alpha(0)=e$, hence $c_{b_0}(0)=b_0=p(e)$ and $c_{b_0}(1)=b_0$, so $g(e,\\alpha) \\in F_p$. On the other hand, if $(e,\\beta) \\in F_p$, then $\\beta(0)=e$ and $\\beta(1)=b_0$, so $\\lambda(e,\\beta)(1) \\in F$ (since $\\lambda$ liftings $\\beta$ and $\\beta$ ends at $b_0$), and clearly $c_{\\lambda(e,\\beta)(1)}(0) = \\lambda(e,\\beta)(1)$, therefore $h(e,\\beta) \\in P_i$. These maps are actually homotopy inverses of each other. \n\nIf we form the compositions\n\\[ g \\circ h(e,\\beta) = \\left( \\lambda(e,\\beta)(1), c_{b_0} \\right) \\]\n\\[ h \\circ g(e,\\alpha) = \\left( \\lambda(e,c_{b_0})(1), c_{\\lambda(e,c_{b_0})(1)} \\right) \\]\nthen we see that each of these components can easily be homotoped to the identity maps. For example, a homotopy $g \\circ h \\simeq \\id$ is given by\n\\[ H((e,\\beta),t) = (\\lambda(e,\\beta)(t),\\beta^t) \\]\nwhere for any path $\\gamma$ we define $\\gamma^t$ to be the path $\\gamma^t(s)=\\gamma(t+(1-t)s)$ so that $\\gamma^0=\\gamma$ and $\\gamma^1=c_{\\gamma(1)}$. Therefore $P_i$ is homotopy equivalent to $F_p$. Further, $g$ is a fibration map since $\\pi \\circ g = q$, so $g$ is actually a fiber homotopy equivalence by \\cref{homotopy equivalence of fibrations is a fiber homotopy equivalence}, and so the fibers of $\\pi$ and $q$ are homotopy equivalent. But, we can clearly see that\n\\[ \\pi^{-1}(e_0) = \\lcb (e,\\beta) \\in E \\times B^I \\st \\beta(0) = p(e) \\text{ and } \\beta(1) = b_0 \\text{ and } e = e_0 \\rcb \\]\nand so there is an obvious identification of $\\pi^{-1}(e_0)$ with $\\Omega_* B$.\n\\end{proof}\n\nStarting with a fibration $p : E \\rightarrow B$, we can form the sequence $\\Omega_* B \\hookrightarrow F_p \\stackrel{\\pi}{\\rightarrow} E \\stackrel{p}{\\rightarrow} B$. If we continued this and converted $\\Omega_* B \\hookrightarrow F_p$ into a fibration, and so on, we would get a sequence of maps\n\\[ \\cdots \\longrightarrow F_\\theta \\longrightarrow F_\\eta \\stackrel{\\theta}{\\longrightarrow} F_\\pi \\stackrel{\\eta}{\\longrightarrow} F_p \\stackrel{\\pi}{\\longrightarrow} E \\stackrel{p}{\\longrightarrow} B \\]\nBy \\cref{homotopy fiber of fiber inclusion} we have $F_\\pi \\simeq \\Omega_* B, F_\\eta = \\Omega_* E$, and so on. This means that, up to homotopy, we get a sequence of maps\n\\begin{equation}\n\\label{fiber sequence}\n\\cdots \\longrightarrow \\Omega_*^n F \\longrightarrow \\Omega_*^n E \\longrightarrow \\Omega_*^n B \\longrightarrow \\Omega_*^{n-1} F \\longrightarrow \\cdots \\longrightarrow \\Omega_* B \\longrightarrow F \\longrightarrow E \\longrightarrow B\n\\end{equation}\nsuch that any two consecutive maps is a fibration preceded by the inclusion of its fiber.\n\n\n\n\n\n\\subsection{Fiber Sequences}\n\n\nA composition $(X,x_0) \\stackrel{f}{\\rightarrow} (Y,y_0) \\stackrel{g}{\\rightarrow} (Z,z_0)$ is said to be an \\textbf{exact sequence} of pointed sets if $\\image f = g^{-1}(z_0)$. \n\n\\begin{prop}\nLet $p : E \\rightarrow B$ be a fibration with fiber $F = p^{-1}(b_0)$, and let $i : F \\rightarrow E$ be the inclusion of any fiber into $E$. Base the space of homotopy classes of maps $[Y,B]$ at constant at $b_0$. For any space $Y$, the induced sequence of sets\n\\[ [Y,F] \\stackrel{i_*}{\\longrightarrow} [Y,E] \\stackrel{p_*}{\\longrightarrow} [Y,B] \\]\nis exact.\n\\end{prop}\n\\begin{proof}\nFor $[g] \\in [Y,F]$ we have $p_* \\circ i_*([g]) = [p \\circ i \\circ g] = [c_{b_0}]$, hence $\\image i_* \\subseteq g_*^{-1}([c_{b_0}])$. For the other inclusion, let $[g] \\in [Y,E]$ such that $p_*[g] = [c_{b_0}]$. Let $G : Y \\times I \\rightarrow B$ be a homotopy between $p \\circ g$ and $c_{b_0}$, and let $\\tilde G : X \\times I \\rightarrow E$ be a solution of the following homotopy lifting problem\n\\[\n\\xymatrix\n@R=2.5pc\n@C=2.5pc\n{\n\tY \\ar[r]^g \\ar[d]_{i_0} & E \\ar[d]^p \\\\\n\tY \\times I \\ar[r]_-G \\ar@{-->}[ru]^{\\tilde G} & B\n}\n\\]\nThen $p \\circ \\tilde G(-,1) = G(-,1) = b_0$ and $H(-,1) : Y \\rightarrow F$, so $[g] = i_*[H(-,1)]$. \n\\end{proof}\n\\begin{prop}\n\\label{based fiber exact sequence}\nLet $p : E \\rightarrow B$ be a fibration with fiber $F = p^{-1}(b_0)$, and base $E$ and $F$ at the same point $e_0 \\in F$. Let $i : F \\rightarrow E$ be the inclusion of any fiber into $E$. For any space $(Y,y_0)$, the induced sequence of sets\n\\[ [Y,F]_* \\stackrel{i_*}{\\longrightarrow} [Y,E]_* \\stackrel{p_*}{\\longrightarrow} [Y,B]_* \\]\nis exact.\n\\end{prop}\n\nUsing \\eqref{fiber sequence} and \\cref{based fiber exact sequence} we now have\n\\begin{prop}[Puppe]\nLet $(Y,y_0)$ be a based space and $(E,e_0) \\rightarrow (B,b_0)$ a fibration with fiber $F = \\pi^{-1}(b_0)$ based at $e_0$. Then there is a long exact sequence of sets (for $i \\geq 0$), of groups (for $i \\geq 1$) and of abelian groups (for $i \\geq 2$)\n\\[ \\cdots \\rightarrow [Y,\\Omega_*^n F]_* \\rightarrow [Y,\\Omega_*^n E]_* \\rightarrow [Y,\\Omega_*^n B]_* \\rightarrow \\cdots \\rightarrow [Y,\\Omega_* B]_* \\rightarrow [Y,F]_* \\rightarrow [Y,E]_* \\rightarrow [Y,B]_* \\]\n\\end{prop}\n\n\n\n\n\n\n\n\n\\newpage\n\\section{Cofibrations}\n\n\\subsection{The Universal Test Diagram}\n\nIn homology one comes across certain ``nice'' pairs of spaces $(X,A)$ such that the homology of $(X,A)$ is essentially equal to the homology of the quotient $X/A$. These nice pairs of spaces also have the property that a homotopy defined on $A$ with a specified extension to $X$ at time $t=0$ can be extended to $X$ for all time. More generally, a map $i : A \\rightarrow X$ is said to have the \\textbf{homotopy extension property} with respect to a space $Y$, if for every $H : A \\times I \\rightarrow A$ and $f : X \\rightarrow X$ there exists a map $\\tilde H : X \\times I \\rightarrow X$ such that the following diagrams commutes\n\\[\n\\xymatrix\n@R=2.5pc\n@C=2.5pc\n{\n\tA \\ar[rr]^{i_0} \\ar[dd]_i & & A \\times I \\ar[dl]_H \\ar[dd]^{i \\times \\id} \\\\\n\t& Y & \\\\\n\tX \\ar[rr]_{i_0} \\ar[ru]^f & & X \\times I \\ar@{-->}[ul]_{\\tilde H}\n}\n\\] \nWe call this a \\emph{test diagram} for the homotopy extension problem. We say that $i : A \\rightarrow X$ is a \\textbf{cofibration} if it has the homotopy extension property with respect to all spaces $Y$. We call the quotient $X / i(A)$ the \\textbf{cofiber} of the cofibration.\n\n\\begin{prop}\nIf $X$ is a CW-complex and $A$ a subcomplex, then the inclusion $i : A \\hookrightarrow X$ is a cofibration.\n\\end{prop}\n\nRecall that a subspace $A \\subseteq X$ is said to be a retract of $X$ if there is a map $r : X \\rightarrow A$ such that $r|_A = \\id_A$. \n\n\n\n\n\\subsection{The Homotopy Cofiber}\n\n\n\\subsection{Cofiber Sequences}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\section{Homotopy Groups}\n\n\n\n\n\\newpage\n\\section{Obstruction Theory}\n\n\n\n\\newpage\n\\section{Classifying Spaces}\n\n\n\\subsection{The Brown Representability Theorem}\n\n\nLet $\\mathscr C$ be a locally small category. A cofunctor $F : \\mathscr C \\rightarrow \\Set$ is said to be \\textbf{representable} if there is a natural isomorphism of functors\n\\[ \\eta : F \\rightarrow \\hom_{\\mathscr C}(-,X) \\]\nfor some object $X$. The object $X$ is called a \\textbf{classifying object} for $F$, or if $\\mathscr C$ is a category of topological spaces we will call $X$ a \\textbf{classifying space}. For example, we will see later that the cohomology functor $H^n(-;G)$ is representable with classifying space $K(G,n)$ so that $H^n(X;G)$ is naturally isomorphic to $[X,K(G,n)]_*$. This turns a problem in understand a functor into understand morphisms between objects.\n\nWe are only going to be concerned with representability of functors in the homotopy category of CW-complexes. Consider a cofunctor $F : \\hCWp \\rightarrow \\Setp$. For a collection of based spaces $\\lcb X_\\alpha \\rcb$, let $i_\\beta : X_\\beta \\rightarrow \\bigvee_\\alpha X_\\alpha$ be the natural inclusions induced by the coproduct. The maps $F(i_\\beta) : F(\\bigvee_\\alpha X_\\alpha) \\rightarrow F(X_\\beta)$ then induce a map $f : F(\\bigvee_\\alpha X_\\alpha) \\rightarrow \\prod_\\beta F(X_\\beta)$ by the universal property of products. We say that $F$ satisfies the \\textbf{wedge axiom} if $f$ is a bijection for all collections $\\lcb X_\\alpha \\rcb$. We say that $F$ satisfies the \\textbf{weak wedge axiom} if $f$ is a bijection for all finite collections $\\lcb X_i \\rcb_{i=1}^n$. \n\nFor $(X;A,B)$ a CW-triad, i.e. $A$ and $B$ are subcomplexes of $X$ with $X = A \\cup B$, consider the following inclusions\n\\[\n\\xymatrix\n@R=.7pc\n{\n\t & A \\ar[rd]^{i_A} \\\\\n\tA \\cap B \\ar[ru]^{j_A} \\ar[rd]_{j_B} & & X \\\\\n\t & B \\ar[ru]_{i_B}\n}\n\\]\nWe say that $F$ satisfies the \\textbf{Mayer-Vietoris axiom} if for every CW-triad $(X;A,B)$ and every $x \\in F(A),y \\in F(B)$ such that\n\\[ F(j_A)(x) = F(j_B)(y) \\in F(A \\cap B) \\]\nthere exists an element $z \\in F(X)$ such that\n\\[ F(i_A)(z) = x \\ \\ \\ \\ \\ \\text{and} \\ \\ \\ \\ \\  F(i_B)(z) = y \\]\n\nThe functor $H^n(X-;G)$ satisfies both of these axioms. Note that the Mayer-Vietoris axiom is exactly what gives exactness at the middle group\n\\[ \\cdots \\longleftarrow H^k(A \\cap B) \\longleftarrow H^k(A) \\oplus H^k(B) \\longleftarrow H^k(X) \\longleftarrow \\cdots \\]\nin the Mayer-Vietoris sequence.\n\nWe will sketch the proof of the following amazing theorem through many propositions and lemmas.\n\\begin{thm}[Brown Representability Theorem]\nA cofunctor $F : \\hCWp \\rightarrow \\Setp$ is representable if and only if $F$ satisfies the wedge and Mayer-Vietoris axioms.\n\\end{thm}\n\\begin{proof}(Sufficiency)\nSuppose $F$ is representable with classifying space $X$. We will show that $[-,X]_*$ satisfies the wedge and Mayer-Vietoris axioms, which implies $F$ does too. \\todo{finish later}\n\\end{proof}\n\nFor a based CW-complex $(Y,y_0)$ and element $u \\in F(Y)$ we can define a natural transformation $T_u : [-,Y]_* \\rightarrow F$. For based CW-complex $(X,x_0)$, let $T_u(X) : [X,Y]_* \\rightarrow F(X)$ be the morphisms that maps $[f]$ to $F([f])(u)$. It is easy to see that $T_u$ is a natural transformation. We will inductively build spaces $Y_n$ and elements $u_n \\in F(Y_n)$ such that $T_{u_n}$ gets ``closer'' to being a natural isomorphism of functors. Taking the limit will give us a classifying space for the functor.\n\n\n\\subsection{Applications}\n\n\n\n\n\n\n\n\\newpage\n\\section{Simplicial Objects}\n\n\n\\subsection{The Simplicial Category}\n\n\nWe will model simplicial objects on a monoidal category called the simplicial category. We will describe this category in detail before discussing simplicial sets and objects. Let $\\Simp$ denote the category whose objects are the finite, totally ordered sets $[n] = \\lcb 0,1,\\ldots,n \\rcb$ for each $n \\geq 0$, and whose morphisms are regular set-theoretic functions $f : [n] \\rightarrow [m]$ such that $f(i) \\leq f(j)$ for all $i \\leq j$ in $[n]$. We will also add the object $[-1]=\\emptyset$ to the category, and so there is exactly one morphism from $\\emptyset$ to any other object (the empty function). This category is called the simplicial category, and clearly $\\emptyset$ is an initial object and $[0]$ is a terminal object. For each object $[n]$ in $\\Simp$ and $0 \\leq i \\leq n$ there is a collection of particularly simple morphisms:\n\\[ \\delta_i : [n-1] \\rightarrow [n] \\ \\ \\ \\ \\ \\delta_i(j) = \\begin{cases} j & j < i \\\\ j+1 & j \\geq i \\end{cases} \\]\n\\[ \\sigma_i : [n+1] \\rightarrow [n] \\ \\ \\ \\ \\ \\sigma_i(j) = \\begin{cases} j & j \\leq i \\\\ j-1 & j > i \\end{cases} \\]\nMore easily stated, $\\delta_i$ is the inclusion of $[n-1]$ into the complement of $i$ in $[n]$, and $\\sigma_i$ is the surjection of $[n+1]$ onto $[n]$ such that $\\sigma_i(i) = \\sigma_i(i+1) = i$. The morphisms $\\delta_i$ are called the face maps, and the morphisms $\\sigma_i$ are called the degeneracy maps. It is easy to check that these morphisms satisfy the following relations:\n\\begin{align*}\n\t\\delta_j \\circ \\delta_i &= \\delta_i \\circ \\delta_{j-1} \\ \\ \\ \\ \\ \\ i<j \\\\\n\t\\sigma_j \\circ \\sigma_i &= \\sigma_i \\circ \\sigma_{j+1} \\ \\ \\ \\ \\ i \\leq j\t \\\\\n\t\\sigma_j \\circ \\delta_i &= \\begin{cases} \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \\delta_i \\circ \\sigma_{j-1} & i < j \\\\ \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \\id & i=j \\text{ or } i = j+1 \\\\ \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \\delta_{i-1} \\circ \\sigma_j & i > j+1 \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t \\end{cases}\n\\end{align*}\nThe face and degeneracy maps generate all of the morphisms of $\\Simp$ in the sense that every morphism $f : [n] \\rightarrow [m]$ can be written as the composition of some $\\delta_i$'s and $\\sigma_j$'s. \n\nLet $f : [m] \\rightarrow [m']$ and $g : [n] \\rightarrow [n']$ be two morphisms in $\\Simp$. We define a bifunctor $+ : \\Simp \\times \\Simp \\rightarrow \\Simp$ by\n\\[ [m] + [n] = [m + n + 1] \\]\n\\[ f+g : [m+n+1] \\rightarrow [m'+n'+1] \\]\n\\[ (f+g)(j) = \\begin{cases} f(i) & 0 \\leq i \\leq m \\\\  g(i-m-1) + m' + 1 & m < i \\leq m+n+1 \\end{cases} \\]\nWith this definition we clearly have $\\emptyset + [n] = [n] = [n] + \\emptyset$ and $\\id_{\\emptyset} + f = f = f + \\id_{\\emptyset}$. This makes $\\Simp$ into a strict monoidal category with $\\emptyset$ as the unit. \n\n\n\n\n\\subsection{Simplicial Objects}\n\n\nWith the simplicial category defined we can say what we mean by a simplicial object. A simplicial object $X$ in a category $\\mathscr C$ is just a cofunctor $X : \\Simp \\rightarrow \\mathscr C$. When there is no cause for confusion we will sometimes use the notation $X_n$ to denote the object $X([n])$ of $\\mathscr C$, as well as $d_i = X(\\delta_i)$ and $s_i = X(\\sigma_i)$ to denote the induced face and degeneracy maps. We will let $s\\mathscr C$ denote the category of simplicial objects in $\\mathscr C$ with morphisms given by natural transformations, i.e. $s\\mathscr C$ is the functor category $\\mathscr C^{\\Delta}$. For example, $\\sSet$ is the category of simplicial sets and $\\sGrp$ is the category of simplicial groups. \n\nThis is a complicated definition, heavily encoded in abstract nonsense, so let us examine the definition in the case of a simplicial set. The idea of a simplicial set was around long before categories, so let us define this object in the classical sense and see why it is equivalent to the above definition. A simplicial set is a collection of sets $\\lcb K_n \\rcb_{n \\geq 0}$ with maps $d_i : K_n \\rightarrow K_{n-1}$ and $s_i : K_n \\rightarrow K_{n+1}$, $0 \\leq i \\leq n$, which satisfy the following:\n\\begin{align*}\n\td_i \\circ d_j &= d_{j-1} \\circ d_i \\ \\ \\ \\ \\ \\ i < j \\\\\n\ts_i \\circ s_j &= s_{j+1} \\circ s_i \\ \\ \\ \\ \\ \\ i \\leq j \\\\\n\td_i \\circ s_j &= \\begin{cases} s_{j-1} \\circ d_i & i < j \\\\ \\id & i=j \\text{ or } i=j+1 \\\\ s_j \\circ d_{i-1} & i > j+1 \\end{cases}\n\\end{align*}\nA simplicial map $f : K \\rightarrow L$ between simplicial sets is a collection of maps $f_n : K_n \\rightarrow L_n$ such that\n\\[ f_n \\circ d_i = d_i \\circ f_{n+1} \\]\n\\[ f_n \\circ s_i = s_i \\circ f_{n-1} \\]\nWe will see how a functor $X : \\Delta \\rightarrow \\Set$ gives such an object, and how a natural transformation between two such functors gives a morphism. Immediately we have that $X_n = X([n])$ is a set, and $d_i = X(\\delta_i) : X_n \\rightarrow X_{n-1}$ and $s_i = X(\\sigma_i) : X_{n+1} \\rightarrow X_n$. These maps satisfy the required identities:\n\\begin{align*}\n d_i \\circ d_j = X(\\delta_i) \\circ X(\\delta_j) = X(\\delta_j \\circ \\delta_i) = X(\\delta_i \\circ \\delta_{j-1}) = X(\\delta_{j-1}) \\circ X(\\delta_i) = d_{j-1} \\circ d_i \\ \\ \\ \\ &i<j \\\\\n s_i \\circ s_j = X(\\sigma_i) \\circ X(\\sigma_j) = X(\\sigma_j \\circ \\sigma_i) = X(\\sigma_i \\circ \\sigma_{j+1}) = X(\\sigma_{j+1}) \\circ X(\\sigma_i) = s_{j+1} \\circ s_i \\ \\ \\ \\ &i \\leq j \n\\end{align*}\nThe last identity involving $d_i \\circ s_j$ is just as easy to verify. So the functor $X$ has given us a simplicial set in the classical sense. Now let $f : X \\rightarrow Y$ be a natural transformation between two functors $X,Y : \\Delta \\rightarrow \\Set$. Then for each object $[n]$ in $\\Delta$ we have a morphism $f_n : X_n \\rightarrow Y_n$ such that for all morphisms $g : [n] \\rightarrow [m]$ we have a commutative diagram:\n\\[\n\\xymatrix\n{\n\tX_n \\ar[r]^{f_n} & Y_n \\\\\n\tX_m \\ar[r]_{f_m} \\ar[u]^{X(g)} & Y_m \\ar[u]_{Y(g)}\n}\n\\]\nHowever, we remarked earlier that any morphism $g : [n] \\rightarrow [m]$ can be factored into a composition of $\\delta_i$'s and $\\sigma_i$'s, so if we can verify the above diagram commutes for each $d_i = X(\\delta_i)$ and $s_i = X(\\sigma_i)$ we will have that it commutes for all morphisms $g$. The diagrams we need to check are:\n\\[\n\\xymatrix\n{\n\tX_{n-1} \\ar[r]^{f_{n-1}} & Y_{n-1} \\\\\n\tX_n     \\ar[r]_{f_n} \\ar[u]^{d_i} & Y_n \\ar[u]_{d_i}\n} \\ \\ \\ \\ \\ \\ \n\\xymatrix\n{\n\tX_n     \\ar[r]^{f_n} & Y_n \\\\\n\tX_{n+1} \\ar[r]_{f_{n+1}} \\ar[u]^{s_i} & Y_{n+1} \\ar[u]_{s_i}\n}\n\\]\nCommutativity of these diagrams is precisely the conditions we placed on the $f_n$'s to be a morphism of simplicial sets. Therefore the categorical definition of a simplicial set is equivalent to the classical notion of a simplicial set. The primary reason for defining simplicial sets as functors is that it allows us to abstract the idea of a simplicial set to other categories, such as groups and topological spaces.\n\n\n\n\n\\comment{\nThere is an important functor $F : \\Simp \\rightarrow \\Top$ such that $F([n])$ is the standard $n$-simplex\n\\[ F([n]) = \\lcb \\sum_{i=0}^n t_i e_i \\st 0 \\leq t_i \\leq 1, \\sum t_i = 1 \\rcb \\]\nwhere $\\lcb e_i \\rcb$ are the standard basis vectors in Euclidean space. If $f : [n] \\rightarrow [m]$ is a morphism in $\\Simp$, then $F(f) : F([n]) \\rightarrow F([m])$ is given by mapping $e_i$ to $e_{f(i)}$ and extending linearly. In particular we see that $\\delta_i$ is simply the inclusion of a face into $F([n])$ and $\\sigma_i$ is the projection of $F([n+1])$ onto one of its faces, hence the name face and degeneracy maps. The fact that morphisms in $\\Simp$ are order preserving means that we can give $F([n])$ the standard orientation, and the maps $F(f)$ will preserve orientations.\n}\n\n\n\n\\subsection{Geometric Realization}\n\nIn this section we will only consider simplicial sets. We will construct a very important functor $| \\cdot | : \\sSet \\rightarrow \\Top$ called geometric realization. First we will define the spaces on which our geometric realization is going to be modeled on. Let $\\Delta_n$ denote the $n$-simplex in $\\mathbb R^{n+1}$\n\\[ \\Delta_n = \\lcb (t_0,t_1,\\ldots,t_n) \\in \\mathbb R^{n+1} \\st 0 \\leq t_i \\leq 1, \\sum t_i = 1 \\rcb \\]\nWe have some natural face and degeneracy maps $\\delta_i : \\Delta_{n-1} \\rightarrow \\Delta_n$ and $\\sigma_i : \\Delta_{n+1} \\rightarrow \\Delta_n$ defined by\n\\[ \\delta_i(t_0,t_1,\\ldots,t_{n-1}) = (t_0,\\ldots,t_{i-1},0,t_i,\\ldots,t_{n-1}) \\]\n\\[ \\sigma_i(t_0,t_1,\\ldots,t_n) = (t_0,\\ldots,t_{i-1},t_i+t_{i+1},\\ldots,t_n) \\]\nThese maps are very similar to the $\\delta_i$'s and $\\sigma_i$'s in the simplicial category, but it will always be clear which maps are being used from the context. We can now define the geometric realization of a simplicial set $X$ by\n\\[ |X| = \\coprod_{n \\geq 0} X_n \\times \\Delta_n / \\sim \\]\nwhere the equivalence relation $\\sim$ is generated by\n\\[ (d_i x, y) \\sim (x, \\delta_i y) \\ \\ \\ \\ \\ x \\in X_n, \\ y \\in \\Delta_{n-1} \\]\n\\[ (s_i x, y) \\sim (x, \\sigma_i y) \\ \\ \\ \\ \\ x \\in X_n, \\ y \\in \\Delta_{n+1} \\]\n\n\\subsection{Nerve of a Category}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\section{Characteristic Classes}\n\n\n\n\n\n\n\n\n\n\\newpage\n\n\n\\bibliography{Homotopy-Theory-Bibliography}\n\\bibliographystyle{plain}\n\\addcontentsline{toc}{section}{\\refname}\n\n\n\\end{document}\n", "meta": {"hexsha": "99c50585be0d9312e04b36f6d384acb60e31737e", "size": 88872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homotopy-theory/homotopy-theory.tex", "max_stars_repo_name": "mbrandonw/my-math-notes", "max_stars_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2017-04-20T15:25:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T03:01:32.000Z", "max_issues_repo_path": "homotopy-theory/homotopy-theory.tex", "max_issues_repo_name": "mbrandonw/my-math-notes", "max_issues_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homotopy-theory/homotopy-theory.tex", "max_forks_repo_name": "mbrandonw/my-math-notes", "max_forks_repo_head_hexsha": "d208af0e6edd6293bbc939aa033bb9b5c0bedbce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-07-11T13:27:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-13T16:46:16.000Z", "avg_line_length": 80.5, "max_line_length": 1332, "alphanum_fraction": 0.6837699163, "num_tokens": 29068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6141763619651269}}
{"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 12: Gradient}\n\\author{}\n\\date{}\n\n\\begin{document}\n    \n\\maketitle\n\n\\section{Gradient}\n\n\\subsection{Introduce Gradient}\n\nAccording to the chain rule, suppose that there is a function $w = w(x, y, z)$, \nwhere $x = x(t)$, $y = y(t)$, and $z = z(t)$, then\n\\begin{gather*}\n  \\begin{split}\n    \\frac{dw}{dt} &= w_x \\frac{dx}{dt} + w_y \\frac{dy}{dt} + w_z \\frac{dz}{dt} \\\\\n                  &= <w_x, w_y, w_z> \\cdot <\\frac{dx}{dt}, \\frac{dy}{dt}, \\frac{dz}{dt}> \\\\\n                  &= \\nabla w \\cdot \\frac{d\\vec{r}}{dt} \\\\\n  \\end{split} \\\\\n  \\nabla w = <w_x, w_y, w_z> \\\\\n  \\frac{d\\vec{r}}{dt} = <\\frac{dx}{dt}, \\frac{dy}{dt}, \\frac{dz}{dt}> \\\\\n\\end{gather*}\nThe vector $<w_x, w_y, w_z>$ is called gradient, denoted as $\\nabla w$. \nGradients on different positions can have different directions and magnitude.\n\n\\subsection{A Property of Gradient}\n\n\\begin{theorem}\n  The gradient of a function is always perpendicular to the level surfaces of \n  the function, where a level surface means the set of points on the function \n  domain whose function values are equal to a constant.\n\\end{theorem}\nNotice that the level surfaces refer to points in the function domain, rather \nthan on the function graph. It doesn't include the dimension of the function \nvalue.\n\n\\begin{example}\n  Examine the relation between the gradient and the level surfaces for the \n  function $w = a_1x + a_2y + a_3z$.\n\n  \\begin{gather*}\n    \\frac{\\partial w}{\\partial x} = a_1 \\\\\n    \\frac{\\partial w}{\\partial y} = a_2 \\\\\n    \\frac{\\partial w}{\\partial z} = a_3 \\\\\n    \\nabla w = <a_1, a_2, a_3> \\\\\n  \\end{gather*}\n\n  The level surfaces of the function $w = a_1x + a_2y + a_3z = c$, where $c$ is \n  any constant, are a series of planes parallel to each other. For any level \n  surfaces of the function, the gradient $\\nabla w$ is a normal vector to it. \n  Therefore, the gradient is always perpendicular to the level surfaces for the \n  function $w = a_1x + a_2y + a_3z$.\n\\end{example}\n\n\\begin{example}\n  Examine the relation between the gradient and the level surfaces for the \n  function $w = x^2 + y^2$.\n\n  \\begin{gather*}\n    \\frac{\\partial w}{\\partial x} = 2x \\\\\n    \\frac{\\partial w}{\\partial y} = 2y \\\\\n    \\nabla w = <2x, 2y> = <x, y> \\\\\n  \\end{gather*}\n\n  The level surfaces of the function $w = x^2 + y^2 = c$, where $c$ is any \n  constant, are a series of circles whose centers are the origin. At any point \n  $(x_0, y_0)$ in the function domain, the gradient vector is $<x_0, y_0>$, \n  which has the same direction as the radius through $(x_0, y_0)$ on the level \n  surface $x^2 + y^2 = x_0^2 + y_0^2$. A circle's radius is always perpendicular \n  to the circle, hence the gradient vector is perpendicular to the level surface. \n  Therefore, the gradient is always perpendicular to the level surfaces for the \n  function $w = x^2 + y^2$.\n\\end{example}\n\nProof of the theorem:\n\nSuppose there is a curve $\\vec{r} = \\vec{r}(t)$ that always stays on a level \nsurface of a function $f$. The velocity vector $\\frac{d\\vec{r}}{dt}$ is tangent \nto the curve, and therefore tangent to the level surface on which the curve \nstays.\n\nBy chain rule, on any level surfaces it satisfies the following equation:\n\\begin{equation*}\n  \\frac{df}{dt} = \\nabla f \\cdot \\frac{d\\vec{r}}{dt} = 0\n\\end{equation*}\nTherefore, at any points of a curve that stays on a level surface:\n\\begin{equation*}\n  \\nabla f \\perp \\frac{d\\vec{r}}{dt}\n\\end{equation*}\nThe same reasoning applies to any curves on a level surface, so at any points on \na level surface, the gradient $\\nabla f$ is perpendicular to velocity vectors of \nevery direction, which are tangent to the level surface. Therefore, at any \npoints on a level surface, the gradient $\\nabla f$ is perpendicular to the \ntangent plane to the level surface.\n\n\\subsection{Application of Gradient}\n\nWe can use gradients to find the equation of the tangent line of a function \ngraph at any points.\n\n\\begin{example}\n  Find the equation of the tangent plane to the surface $x^2 + y^2 - z^2 = 4$ at \n  the point (2, 1, 1).\n\n  Solution:\n\n  The surface $x^2 + y^2 - z^2 = 4$ is a level surface of the function \n  $w = x^2 + y^2 - z^2$.\n  \\begin{gather*}\n    \\frac{\\partial w}{\\partial x} = 2x \\\\\n    \\frac{\\partial w}{\\partial y} = 2y \\\\\n    \\frac{\\partial w}{\\partial z} = -2z \\\\\n    \\nabla w = <2x, 2y, -2z> = <x, y, -z> \\\\\n  \\end{gather*}\n  Hence the gradient of the function at the point (2, 1, 1) is $<2, 1, -1>$. \n  According to the property of gradients, the gradient is perpendicular to the \n  tangent plane of the corresponding level surface at the point. Therefore, the \n  equation of the tangent plane is \n  \\[ 2x + y - z = c, \\textnormal{where c is a constant} \\]\n  Then we can substitute the coordinate of the point (2, 1, 1) into the plane \n  equation:\n  \\[ c = 2 \\times 2 + 1 \\times 1 - 1 \\times 1 = 4 \\]\n  Therefore, the equation of the tangent plane to the surface \n  $x^2 + y^2 - z^2 = 4$ at the point (2, 1, 1) is\n  \\[ 2x + y - z = 4 \\]\n\\end{example}\n\n\\section{Directional Derivatives}\n\n\\subsection{Introduce Directional Derivatives}\n\nHow to calculate the partial derivative towards any direction $\\vec{u}$, rather \nthan only along the $x$ axis and $y$ axis?\n\nSuppose there is a multivariable function $f(x, y)$, and an unit vector \n$\\hat{\\vec{u}} = <a, b>$. The partial derivative along a direction is the rate \nof change of the function value $f(x, y)$ over the arclength, hence we need the \ndifferential of the arclength along the direction of $\\hat{\\vec{u}}$, which is \ndenoted by $ds$. \n\nBy chain rule, we have\n\\begin{gather*}\n  df = \\frac{\\partial f}{\\partial x}dx + \\frac{\\partial f}{\\partial y}dy \\\\\n  \\frac{df}{ds} = \\frac{\\partial f}{\\partial x}\\frac{dx}{ds} + \\frac{\\partial f}{\\partial y}\\frac{dy}{ds} \\\\\n  \\frac{df}{ds} = <\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y}> \\cdot <\\frac{dx}{ds}, \\frac{dy}{ds}> \\\\\n  \\frac{df}{ds} = \\nabla f \\cdot \\frac{d\\vec{r}}{ds} \\\\\n\\end{gather*}\nTherefore, we need to describe the position vector $\\vec{r}$ along the straight \nline trajectory with the direction $\\vec{u}$ using the parameter $s$, the \narclength.\n\\begin{gather*}\n  \\begin{cases}\n    x(s) = x_0 + as \\\\\n    y(s) = y_0 + bs \\\\\n  \\end{cases} \\\\\n  \\frac{d\\vec{r}}{ds} = <a, b> \\\\\n  \\frac{d\\vec{r}}{ds} = \\vec{u} \\\\\n\\end{gather*}\nTherefore,\n\\begin{equation*}\n  \\begin{split}\n    \\frac{df}{ds} &= \\nabla f \\cdot \\frac{d\\vec{r}}{ds} \\\\\n                  &= \\nabla f \\cdot \\vec{u} \\\\\n  \\end{split}\n\\end{equation*}\nwhich is the formula for directional derivatives.\n\n\\begin{definition}\n  The instantaneous rate of change of a multivariable function $f$ at a given \n  direction $\\vec{u}$ is called the directional derivative, whose notation is \n  $\\frac{df}{ds}|_{\\vec{u}}$. The formula of directional derivatives is \n  \\[ \\frac{df}{ds}|_{\\vec{u}} = \\nabla f \\cdot \\vec{u} \\]\n\\end{definition}\n\n\\subsection{Geometric Interpretation of Directional Derivatives}\n\nFor a multivariable function $f$ with two independent variables, the geometric \ninterpretation of the function toward a direction $\\vec{u}$ is the slope of the \nslice of the function graph by a vertical plane parallel to $\\vec{u}$.\n\n\\begin{example}\n  Verify the formula of directional derivatives by finding the partial \n  derivative along the $x$ axis.\n\n  Suppose there is a multivariable function $f(x, y)$.\n  \\begin{equation*}\n    \\begin{split}\n      \\frac{\\partial f}{\\partial x} &= \\nabla f \\cdot \\vec{i} \\\\\n                                    &= <\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y}> \\cdot \\vec{i} \\\\\n                                    &= \\frac{\\partial f}{\\partial x} \\\\\n    \\end{split}\n  \\end{equation*}\n\\end{example}\n\n\\subsection{Max/Min of Directional Derivatives}\n\nAccording to the geometric interpretation of dot product of vectors:\n\\begin{equation*}\n  \\begin{split}\n    \\frac{df}{ds}|_{\\vec{u}} &= \\nabla f \\cdot \\vec{u} \\\\\n                             &= |\\nabla f| \\times |\\vec{u}| \\times \\cos\\theta \\\\\n                             &= \\cos\\theta \\times |\\nabla f| \\\\\n  \\end{split}\n\\end{equation*}\nWe can see that the directional derivative changes as the angle $\\theta$ between \nits direction and the gradient vector changes. It is obvious that at a given \npoint:\n\\begin{itemize}\n  \\item The directional derivative with the maximum value has the same direction \n    as the gradient, and the maximum value is the magnitude of the gradient. \n    Since the directional derivative along the direction of the gradient is \n    positive and has the maximum value, the gradient points to the direction \n    where the function value increases fastest.\n  \\item The directional derivative with the minimum value has the opposite \n    direction to the gradient, and the minimum value is the negative value of \n    the magnitude of the gradient.\n\\end{itemize}\n\n\\end{document}", "meta": {"hexsha": "bc3b8db527fe686c4d0ac924e1b4662966ce1015", "size": 9180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture12.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": "lecture12.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": "lecture12.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": 38.8983050847, "max_line_length": 120, "alphanum_fraction": 0.6687363834, "num_tokens": 2840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6141763602306411}}
{"text": "\\subsection{Air Thermoregulation}\n\\label{sec:airthermoregulation}\n\n\\textbf{Purpose}: Maintaining desired leaf-zone air temperature and circulating air.\n\n\\textbf{Function}:\n\\begin{itemize}\n    \\item \\textbf{Inputs}: Power, air temperature control signal (\\ref{sec:automation}), air circulation control signal (\\ref{sec:automation});\n    \\item \\textbf{Outputs}: $\\pm$Heat to environment, $\\mp$heat to surroundings, internal air circulation, internal air temperature sensor signal (\\ref{sec:automation});\n\\end{itemize}\n\n\\textbf{Method}:\n\\begin{enumerate}\n    \\item \\textit{Testing}:\n    \\begin{itemize}\n        \\item Heat pump direction and magnitude respond to control signal as expected;\n        \\item Fans operate as expected;\n        \\item Heat pump power exceeds maximum heat loss (temperature extremes)\\footnote{i.e. if X Watts leave the system at MAX$\\degree$C internal, and Y Watts enter the system at MIN$\\degree$C internal, the heat pump must transfer >X, >Y Watts.};\n        \\item Heat pump power exceeds that required to reach temperature extremes in under 120 seconds given the system's heat capacity;\n    \\end{itemize}\n    \\item \\textit{Process}:\n    \\begin{enumerate}\n        \\item Air is circulated throughout the environment;\n        \\item Temperature is measured, sent to control module;\n        \\item Control module controls heat pump speed and direction (heating vs. cooling);\n    \\end{enumerate}\n\\end{enumerate}\n\n\\textbf{Calculations}:\n\nAssuming an atmospheric pressure $P$ of 101.325kPa, a surroundings temperature range $T_{surr}$ of 22$\\degree$C, a system target temperature range $T_{sys-min}$, $T_{sys-max}$ of 10-35$\\degree$C, a molar mass of dry air\\footnote{Water vapour has a maximum concentration of 30g/kg at 30$\\degree$C, or 3\\%, which is negligible for mass and heat capacity calculations.} $M$ of 28.97 $\\frac g{mol}$, a specific heat capacity of dry air $c_p$ of $1.006 \\frac{J}{g*\\text{K}}$, a 4-unit (2x2 units, 16 faces) expanded configuration, and a face insulation RSI per mm of $0.0328\\text{m}^2~  \\degree \\text{C}~\\text{W}^{-1}~\\text{mm}^{-1}$ (See Section \\ref{sec:housing}):\\\\\n\\vspace{.05cm}\n\\begin{gather*}\n    \\label{eqn:heatloss}\n    Q_{loss}=\\frac{(T_{surr}-T_{sys-max}) * A}{\\text{RSI per mm} * \\ell}=\\frac{(22\\degree \\text{C}-35\\degree \\text{C}) * (16 \\text{ faces} * 0.5\\text{m} * 0.5\\text{m})}{0.0328 \\text{m}^2~  \\degree \\text{C}~\\text{W}^{-1}~\\text{mm}^{-1} * 25.4 \\text{mm}}=-62.42 W\\\\\\vspace{.05cm}\\\\\n    \\label{eqn:heatgain}\n    Q_{gain}=\\frac{(T_{surr}-T_{sys-min}) * A}{\\text{RSI per mm} * \\ell}=\\frac{(22\\degree \\text{C}-10\\degree \\text{C}) * (16 \\text{ faces} * 0.5\\text{m} * 0.5\\text{m})}{0.0328 \\text{m}^2~  \\degree \\text{C}~\\text{W}^{-1}~\\text{mm}^{-1} * 25.4 \\text{mm}}=57.61 W\\\\\\vspace{.05cm}\\\\\n    \\label{eqn:airmass}\n    m_{air}=\\frac{P*V*M}{R*T_{avg}}=\\frac{101325\\text{Pa}*(0.5\\text{m}*0.5\\text{m}*0.5\\text{m}*4\\text{ units})*28.97\\frac g{mol}}{8.314\\frac{J}{\\text{mol}*K}*300\\text{K}}=588.4g\\\\\n    \\vspace{1.5cm}\\\\\n    \\text{Continued on next page}\n\\end{gather*}\n\\vspace{1cm}\n\n\\begin{gather*}\n  \\label{eqn:heating}\n  W_{heating}=\\frac{m*c_p*(T_{surr}-T_{sys-max})}{t}=\\frac{588.4g*1.006\\frac{J}{g*\\text{K}}*(22\\degree \\text{C}-35\\degree \\text{C})}{120\\text{ sec}}=-64.13\\text{W}\\\\\n  \\label{eqn:cooling}\n  W_{cooling}=\\frac{m*c_p*(T_{surr}-T_{sys-min})}{t}=\\frac{588.4g*1.006\\frac{J}{g*\\text{K}}*(22\\degree \\text{C}-10\\degree \\text{C})}{120\\text{ sec}}=59.19\\text{W}\n\\end{gather*}\n\n$\\therefore$ A thermoelectric system able to transfer at least 70W (such as \\cite{peltier}, which transfers up to 85W) will supply enough power to heat/cool the system from ambient to extremes in 120 seconds and maintain temperature.\n\n\\begin{gather*}\n  \\label{eqn:thermalresistance-hot}\n  R_{\\theta~Peltier-Surr}=R_{\\theta~Peltier-Sink}+R_{\\theta~Sink-Air}\\le\\frac{T_{h~max} - T_{surr}}{Q_{max}}=\\frac{50\\degree C - 22\\degree C}{85W}=0.329\\degree \\text{C W}^{-1}\\\\\n  \\label{eqn:thermalresistance-cold}\n  R_{\\theta~Peltier-Sys}=R_{\\theta~Peltier-Sink}+R_{\\theta~Sink-Air}\n\\end{gather*}\n\n\\textbf{Features}:\n\\begin{itemize}\n    \\item \\textit{Circulation Fans}: Located in growth environment to circulate air even temperature distribution.\n    \\item \\textit{Temperature Sensors}: SHT31 \\cite{sht31} sensors on breakout boards located throughout the growth environment to measure air temperature. Informs a \\textbf{PID control loop} (\\ref{sec:automation}).\n    \\item \\textit{Heat Pump}: Pumps heat in or out of the growth environment. Is comprised of:\n    \\begin{itemize}\n        \\item \\textit{Peltier Device}: 85W bidirectional solid-state \\textbf{thermoelectric device} (aka Peltier tile) \\cite{peltier} pumps heat from one face to the other. Better space efficiency, less complexity (no liquids, pressurized fluids, etc.), and more precise than other methods.\n        \\item \\textit{Peltier Driver Circuit}: Controls magnitude and direction of Peltier device heat pump via a \\textbf{dimmable voltage source} and \\textbf{MOSFET H-bridge}, respectively. See Figure \\ref{fig:peltierdriver}.\n        \\item \\textit{Heat Sinks}: Aluminum blocks with fins hold and exchange heat between air and Peltier devices. One set on each side of the Peltier (inside and outside environment) builds \"heat pump\". Mating face coated with thermal compound for better transfer.\n        \\item \\textit{Heat Sink Fans}: Located on both sets of heat sinks for better heat dissipation.\n    \\end{itemize}\n\\end{itemize}\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{images/thermosim.png}\n  \\hfill\n  \\caption{Peltier driver circuit simulation (live version: \\cite{thermo-falstad})}\n  \\label{fig:peltierdriver}\n\\end{figure}", "meta": {"hexsha": "c61132f32b57cd87c2b64ebe727ef23cb9c69c34", "size": 5665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/solutionoverview/tex/subsystems/AirThermoregulation.tex", "max_stars_repo_name": "PeaPodTech/PeaPod", "max_stars_repo_head_hexsha": "19f956f4e7612d81c203a616ff505c4dc68b9964", "max_stars_repo_licenses": ["MIT"], "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/solutionoverview/tex/subsystems/AirThermoregulation.tex", "max_issues_repo_name": "PeaPodTech/PeaPod", "max_issues_repo_head_hexsha": "19f956f4e7612d81c203a616ff505c4dc68b9964", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-10-30T05:06:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-30T05:06:16.000Z", "max_forks_repo_path": "docs/solutionoverview/tex/subsystems/AirThermoregulation.tex", "max_forks_repo_name": "PeaPodTech/PeaPod", "max_forks_repo_head_hexsha": "19f956f4e7612d81c203a616ff505c4dc68b9964", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-24T02:21:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-24T02:21:18.000Z", "avg_line_length": 70.8125, "max_line_length": 663, "alphanum_fraction": 0.7043248014, "num_tokens": 1874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6141763480892405}}
{"text": "\\documentclass[]{revtex4-2}\n\\usepackage{amsmath}\n\n\\begin{document}\n    \\title{Assignment 5: Physics of Compact Objects}\n    \\author{Md Arif Shaikh}\n    \\affiliation{International Centre for Theoretical Sciences, Bengaluru}\n    \\email{arifshaikh.astro@gmail.com}\n    \\date{\\today}\n    \\maketitle\n    \\section*{Problem 1}\n    Show that, in the white dwarf interior, the Coulomb energy per free electron is\n    \\begin{equation}\n      \\label{eq:coulomb-energy}\n      \\epsilon_C = - \\frac{9}{10} \\left(\\frac{4\\pi}{3}\\right)^{1/3}Z^{2/3}e^2 n_e^{1/3},\n    \\end{equation}\n    where $Z$ is the atomic number, $e$ is the elementary charge and $n_e$ is the number density of free electrons.\n\n\\vspace{0.5cm}\n    \n\\noindent {\\bfseries Answer:} As temperature decreases, $T\\to0$, the ions are located in a lattice that maximizes the inter-ion separation. We can consider a spherical shell of the lattice of volume $4\\pi r_0^3/3 = 1/n_N$, where $n_N$ is the number density of the nuclei. The total energy of any one sphere is the sum of potential energies due to electron-electron ($e-e$) interactions and electron-ion ($e-i$) interactions.\n\nTo assemble a uniform sphere of $Z$ electrons requires energy\n\\begin{equation}\n  \\label{eq:e-e}\n  E_{e-e} = \\int_0^{r_0} \\frac{q dq}{r} = \\int_0^{r_0} - \\frac{Ze (r^3/r_0^3)d ( - Ze (r^3/r_0^3))}{r} = Z^2e^2 \\frac{3}{r_0^6}\\int_0^{r_0} r^4 dr = Z^2e^2 \\frac{3}{r_0^6}\\frac{r_0^5}{5} = \\frac{3}{5}\\frac{Z^2e^2}{r_0}.\n\\end{equation}\nOn the other hand, to assemble the electron sphere about the central nucleus of charge $Ze$ requires energy\n\\begin{equation}\n  \\label{eq:e-i}\n  E_{e-i} = Ze \\int_0^{r_0} \\frac{dq}{r} = - Ze \\int_0^{r_0} \\frac{3 dr Z e r}{r_0^3} = - \\frac{3}{2}\\frac{Z^2e^2}{r_0}.\n\\end{equation}\nSo, the total Coulomb energy of the shell is\n\\begin{equation}\n  \\label{eq:E_tot}\n  E_C = E_{e-e} + E_{e-i} =  \\frac{3}{5}\\frac{Z^2e^2}{r_0} - \\frac{3}{2}\\frac{Z^2e^2}{r_0} = - \\frac{9}{10}\\frac{Z^2e^2}{r_0}.\n\\end{equation}\nSo the Coulomb energy per electron is\n\\begin{equation}\n  \\label{eq:epsilon_c}\n  \\epsilon_C = \\frac{E_C}{Z} = -\\frac{9}{10}\\frac{Z e^2}{r_0} = - \\frac{9}{10}\\frac{Z e^2}{(3 Z/4\\pi n_e)^{1/3}} = - \\frac{9}{10} \\left(\\frac{4\\pi}{3}\\right)^{1/3}Z^{2/3}e^2n_e^{1/3},\n\\end{equation}\nwhere we have used\n\\begin{equation}\n  \\label{eq:n_e}\n  \\frac{4\\pi}{3} r_0^3 n_e = Z. \n\\end{equation}\n\\end{document}", "meta": {"hexsha": "5c59fb69fa1a7b6c6271b4d92768fe2cde1f602b", "size": 2352, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment-5/Assignment-5-prob-1.tex", "max_stars_repo_name": "md-arif-shaikh/Physics-Of-Compact-Objects", "max_stars_repo_head_hexsha": "103617c8d6f02a03727ece5e6dce9dcfb8e9482d", "max_stars_repo_licenses": ["MIT"], "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-5/Assignment-5-prob-1.tex", "max_issues_repo_name": "md-arif-shaikh/Physics-Of-Compact-Objects", "max_issues_repo_head_hexsha": "103617c8d6f02a03727ece5e6dce9dcfb8e9482d", "max_issues_repo_licenses": ["MIT"], "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-5/Assignment-5-prob-1.tex", "max_forks_repo_name": "md-arif-shaikh/Physics-Of-Compact-Objects", "max_forks_repo_head_hexsha": "103617c8d6f02a03727ece5e6dce9dcfb8e9482d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-17T02:18:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-17T02:18:16.000Z", "avg_line_length": 49.0, "max_line_length": 424, "alphanum_fraction": 0.6611394558, "num_tokens": 925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746404, "lm_q2_score": 0.8104788995148792, "lm_q1q2_score": 0.6141763480892404}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 2}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\n\\section{Random variables}\n\\begin{definition}\n\\textbf{A random variable} is a function $X: \\Omega \\to \\R$ with the property that $\\{ \\omega\\in \\Omega \\spacevert X(\\omega) \\leq x\\} \\in \\mathcal{F}$ for each $x \\in \\R$. Such a function is said to be $\\mathbf{\\mathcal{F}}$\\textbf{-measurable}. \n\\end{definition}\n\n\\begin{example}\nTossing two dice. We define \n\\begin{equation*}\n    X = \\begin{cases} 1 & \\text{get double ($i=j$)} \\\\ 0 & \\text{not double $(i\\neq j)$} \\end{cases}.\n\\end{equation*}\nThen $X = (i,j) \\in \\R$.\n\\end{example}\n\n\\begin{remark}\nWe are interested in $g(x) = \\Prob\\{ \\omega \\spacevert X(\\omega) = x \\}$. But sometimes it doesn't work very well. Probability triplet is defined as $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$. If $\\Omega$ is countable, then $g(x)$ is okay. But if $\\Omega$ is uncountable like intervals, then $\\Prob(X=x)$ doesn't make much sense because the cardinality is too large.\n\\end{remark}\n\n\\begin{definition}\nThe \\textbf{distribution function} of a random variable $X$ is the function $F: \\R \\to \n[0, 1]$ given by $F(x) = \\Prob(X \\leq x)$. \n\\end{definition}\n\n\\begin{example}\nThe distribution function of preceeding example is \n\\begin{equation*}\n    F(x) = \\begin{cases} 0 & x \\leq 0, \\\\ \\frac{30}{36} & 0 < x \\leq 1, \\\\ 1 & x > 1. \\end{cases}\n\\end{equation*}\n\\end{example}\n\nNotice that $\\{ \\omega \\spacevert X(\\omega) \\leq x\\}$ defines an event. It is an element in the corresponding $\\sigma$-field. Denote $A(x) = \\{ \\omega \\spacevert X(\\omega) \\leq x \\}$. Along with $A(x)$, we can define\n\\begin{equation*}\n    A^c(x) = \\{ \\omega \\spacevert X(\\omega) > x \\}, \\quad A(x, y) = A^c(x) \\cap A(y) = \\{ \\omega \\spacevert x < X(\\omega) \\leq y \\}.\n\\end{equation*}\nTow points worth noting:\n\\begin{enumerate}[(a)]\n    \\item $F$ must be defined for \\textbf{all} $x \\in \\R$.\n    \\item $A(x)$ should \\textbf{belongs to} $\\mathcal{F}$. Otherwise, we cannot talk about the probability of $\\Prob(A(x))$. Then the definition of distribution function is meaningless.\n\\end{enumerate}\n\n\\begin{lemma}\nA distribution function $F$ has the following properties:\n\\begin{enumerate}[(a)]\n    \\item $\\lim_{x \\to -\\infty}F(x) = 0$, $\\lim_{x\\to\\infty} F(x) = 1$,\n    \\item if $x < y$, then $F(x) \\leq F(y)$,\n    \\item $F$ is right-continuous, that is $F(x+h) \\to F(x)$ as $h \\downarrow 0$. (left-continuous is not necessary)\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{example}\n\\textbf{Indicator functions.} A particular class of Bernoulli variables is very useful in probability theory. Let $A$ be an event and let $I_A : \\Omega \\to \\R$ be the indicator function of $A$; that is,\n\\begin{equation*}\n    I_A(\\omega) = \\begin{cases} 1 & \\text{if $\\omega \\in A$}, \\\\ 0 & \\text{if $\\omega \\in A^c$}. \\end{cases}\n\\end{equation*}\nThen $I_A$ is a Bernoulli random variable taking the values 1 and 0 with probabilities $\\Prob(A)$ and $\\Prob(A^c)$ respectively. Suppose $\\{B_i \\spacevert i \\in I\\}$ is a family of disjoint events with $A \\subseteq \\bigcup_{i\\in I} B_i$. Then \n\\begin{equation*}\n    I_A = \\sum_{i} = I_{A\\cap B_i},\n\\end{equation*}\nan identity which is often useful.\n\\end{example}\n\n\\begin{lemma}\nLet $F$ be the distribution function of $X$. Then\n\\begin{enumerate}[(a)]\n    \\item $\\Prob(X>x) = 1-F(x)$, \n    \\item $\\Prob(x < X \\leq y) = F(y) - F(x)$,\n    \\item $\\Prob(X = x) = F(x) - \\lim_{y \\uparrow x} F(y)$.\n\\end{enumerate}\n\\end{lemma}\n\nA random variable $X$ with distribution function $F$ is said to have two ``tails\" given by \n\\begin{equation*}\n    T_1 (X) = \\Prob(X > x) = 1 - F(x), \\quad T_2(X) = \\Prob(X \\leq -x) = F(-x),    \n\\end{equation*}\nwhere $x$ is large and positive. The rates at which the $T_i$ decay to zero as $x\\to\\infty$ have a substantial effect on the existence or non-existence of certain associated quantities called the ``moments\" of the distribution. \n\n\n\\section{Different random variables}\n\\subsection{Discrete random variables}\n\\begin{definition}\nThe random variable $X$ is called \\textbf{discrete} if it takes values in some \\textbf{countable} subset $\\{ x_1, x_2, \\dots \\}$, only, of $\\R$. The discrete random variable $X$ has \\textbf{(probability) mass function} $f : \\R \\to [0, 1]$ given by $f(x) = \\Prob(X = x)$. \n\\end{definition}\nWe shall see that the distribution function of a discrete variable has jump discontinuities \nat the values $x_1 , x_2, \\dots$ and is constant in between; such a distribution is called \\emph{atomic}.\n\n\\subsection{Continuous random variables}\n\\begin{definition}\nThe random variable $X$ is called \\textbf{continuous} if its distribution function can \nbe expressed as \n\\begin{equation*}\n    F(x) = \\int_{-\\infty}^x f(u) du \\qquad x \\in \\R\n\\end{equation*}\nfor some \\textbf{integrable} function $f : \\R \\to [0, \\infty)$ called the \\textbf{(probability) density function} of $X$. \n\\end{definition}\nSome point worth noting:\n\\begin{enumerate}[(a)]\n    \\item The density function $f(x)$ is not unique. We can add some separate points to $f$, and it doesn't affect the integration.\n    \\item $F$ must be \\textbf{absolutely continuous}. This implies $F$ is continuous. We can also deduce that the probability at certain point must be zero. \\emph{i.e.}, $\\Prob(X=x) = 0$.\n\\end{enumerate}\n\nThere is another sort of random variable, called ``singular\".\n\n\n\\section{Random vectors}\n\\subsection{Definition}\nThe random vector is a function $X : \\Omega \\to \\R^n$. For example, $\\mathbf{X} = (X, Y)$ for $n=2$. We can also define the distribution function for such $X$. But we need to first introduce the ordering in $\\R^n$.\n\\begin{center}\n    By definition, $(x_1, y_1) < (x_2, y_2)$ if and only if $x_1 < x_2$  \\textbf{AND}  $y_1 < y_2$.\n\\end{center}\n\n\\begin{definition}\nThe \\textbf{joint distribution function} of a random vector $\\mathbf{X} = (X_1, X_2 \\dots, X_n)$ on the probability space $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$ is the function $F_{\\mathbf{X}} : \\R^n \\to [0, 1]$ given by $F_{\\mathbf{X}}(x) = \\Prob(\\mathbf{X} \\leq \\mathbf{x})$ for $\\mathbf{x} \\in \\R^n$. \n\\end{definition}\n\n\\begin{remark}\nThe joint probability $\\Prob(\\mathbf{X} \\leq \\mathbf{x}) = \\Prob(X_1 \\leq x_1, \\dots, X_n \\leq x_n)$. $\\{\\mathbf{X} \\leq \\mathbf{x} \\}$ is an abbreviation for the event $\\{\\omega \\in \\Omega \\spacevert \\mathbf{X}(w) \\leq \\mathbf{x}\\}$.\n\\end{remark}\n\n\\begin{lemma}\nThe joint distribution function $F_{X, Y}$ of the random vector $(X, Y)$ has the following properties: \n\\begin{enumerate}[(a)]\n    \\item $\\lim_{x, y\\to -\\infty} F_{X, Y}(x, y) = 0, \\lim_{x,y\\to\\infty} F_{X, Y}(x,y) = 1$,\n    \\item if $(x_1, y_1) \\leq (x_2, y_2)$, then $F_{X,Y}(x_1, y_1) \\leq F_{X, Y}(x_2, y_2)$,\n    \\item $F_{X,Y}$ is continuous from above, in that \n    \\begin{equation*}\n        F_{X,Y}(x+u, y+v) \\to F_{X,Y}(x,y) \\quad as \\quad u, v \\downarrow 0.\n    \\end{equation*}\n\\end{enumerate}\n\\end{lemma}\n\n\\subsection{Marginalization} \n\\begin{gather*}\n    \\lim_{y\\to\\infty} F_{X,Y} = F_X(x) = \\Prob(X \\leq x), \\\\\n    \\lim_{x\\to\\infty} F_{X,Y} = F_Y(y) = \\Prob(Y \\leq y).\n\\end{gather*}\nThe functions $F_X$ and $F_Y$ are called the ``marginal\" distribution functions of $F_{X,Y}$. $F_{X,Y}$ can determine two marginals $F_X$ and $F_Y$, but \\textbf{converse is NOT true}.\n\n\\subsection{Discrete and continuous distribution}\n\\begin{definition}\nThe random variables $X$ and $Y$ on the probability space $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$ are called \\textbf{(jointly) discrete} if the vector $(X, Y)$ takes values in some \\textbf{countable} subset of $\\R^2$ only. The jointly discrete random variables $X, Y$ have \\textbf{joint (probability) mass function} $f : \\R^2 \\to [0,1]$ given by $f(x, y) = \\Prob(X = x, Y = y)$. \n\\end{definition}\n\n\\begin{definition}\nThe random variables $X$ and $Y$ on the probability space $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$ are called \\textbf{(jointly) continuous} if their joint distribution function can be expressed as \n\\begin{equation*}\n    F_{X,Y}(x,y) = \\int_{u = -\\infty}^x \\int_{v = -\\infty}^y f(u,v)du dv \\qquad x, y\\in\\R,\n\\end{equation*}\nfor some \\textbf{integrable} function $f : \\R^2 \\to [0, \\infty)$ called the \\textbf{joint (probability) density function} of the pair $(X, Y)$. \n\\end{definition}\n\n\\end{document}", "meta": {"hexsha": "9fd4795bd3546e0d02f7a004e824f7ead8949ab9", "size": 8312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_2.tex", "max_stars_repo_name": "yuhan-zhao/freshman21-v1", "max_stars_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_drafts/MATH 2901/notes_2.tex", "max_issues_repo_name": "yuhan-zhao/freshman21-v1", "max_issues_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_drafts/MATH 2901/notes_2.tex", "max_forks_repo_name": "yuhan-zhao/freshman21-v1", "max_forks_repo_head_hexsha": "e4c5f7983a768554399193f47e8426976205330f", "max_forks_repo_licenses": ["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.3086419753, "max_line_length": 374, "alphanum_fraction": 0.6627767084, "num_tokens": 2847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.6141716107541824}}
{"text": "\\documentclass[gr-notes.tex]{subfiles}\n\n\\begin{document}\n\n\\setcounter{chapter}{7}\n\n\\chapter{The Einstein field equations}\n\n\\setcounter{section}{5}\n\n\\section{Exercises}\n\n\\textbf{3}\n\n(a) Calculate in geometrized units:\n\n(i) the Newtonian potential of the Sun at its surface\n%\n\\begin{displaymath}\n  \\phi =\n -G M_\\Sun / R_\\Sun \\approx\n -\\SI{1.476e3}{m} / \\SI{6.960e8}{m} \\approx\n  \\num{-2.12e-6}\n\\end{displaymath}\n\n(ii) the Newtonian potential of the Sun at the radius of Earth's orbit\n%\n\\begin{displaymath}\n  \\phi =\n -G M_\\Sun / \\SI{1}{AU} \\approx\n -\\SI{1.476e3}{m} / \\SI{1.496e11}{m} \\approx\n  \\num{-9.866e-9}\n\\end{displaymath}\n\n(iii) the Newtonian potential of the Earth at its surface\n%\n\\begin{displaymath}\n  \\phi =\n -G M_\\Earth / R_\\Earth \\approx\n -\\SI{4.434e-3}{m} / \\SI{6.371e6}{m} \\approx\n  \\num{-9.660e-10}\n\\end{displaymath}\n\n(iv) the Earth's orbital velocity\n\nHere I use the result from part (c), and find that\n%\n\\begin{displaymath}\n  v =\n  \\sqrt{-\\phi} \\approx\n  \\num{9.933e-5}\n\\end{displaymath}\n\n(b) If the potential due to the Sun at Earth's orbital radius is greater than the Earth's potential at its surface (as is shown above), then why do we feel the Earth's gravity more than the Sun's?\n\nWe don't feel the potential directly, we feel the gravitational acceleration it produces. Acceleration is obtained from the potential via $\\vb{a} = -\\grad\\phi$, and in the case of a circular orbit in a Newtonian potential:\n%\n\\begin{displaymath}\n  a =\n -\\grad\\phi =\n -\\pdv{r} (-G M / r) =\n -G m / r^2 =\n  \\phi / r.\n\\end{displaymath}\n%\nSo in the two cases mentioned, we need to divide by the radius once more, to obtain the acceleration.\n%\n\\begin{align*}\n  a_\\Sun &=\n  \\phi_\\Sun / \\SI{1}{AU} \\approx\n  \\SI{-6.595e-20}{\\per\\meter}\n  \\\\\n  a_\\Earth &=\n  \\phi_\\Earth / R_\\Earth \\approx\n  \\SI{-1.092e-16}{\\per\\meter}\n\\end{align*}\n%\nAs you can see, the acceleration due to the Earth is greater by a factor of $10^4$.\n\n(c) Show that a circular orbit in a Newtonian potential has an orbital velocity $v^2 = -\\phi$.\n\nWe saw above that $a = \\phi / r$, and we also know that centripetal acceleration is given by $a = -v^2 / r$. Equating the two we get $v^2 = -\\phi$.\n\n\n\\textbf{8}\n\n(a) Show that $\\tensor{R}{^\\alpha_{\\beta\\mu\\nu}} = \\eta^{\\alpha\\sigma} R_{\\alpha\\beta\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2}$.\n\n\\begin{align*}\n  \\tensor{R}{^\\alpha_{\\beta\\mu\\nu}} &=\n  g^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu} =\n  (\\eta^{\\alpha\\sigma} + h^{\\alpha\\sigma}) R_{\\sigma\\beta\\mu\\nu} =\n  \\eta^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu} + h^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu}\n  \\\\\n  h^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu} &=\n  \\frac{1}{2} h^{\\alpha\\sigma}\n  (h_{\\sigma\\nu,\\beta\\mu} + h_{\\beta\\mu,\\sigma\\nu} -\n   h_{\\sigma\\mu,\\beta\\nu} - h_{\\beta\\nu,\\sigma\\mu}) =\n  \\order*{[h_{\\alpha\\beta}]^2}\n\\end{align*}\n\n(b) Find $R_{\\alpha\\beta}$ to first order in $h_{\\mu\\nu}$.\n\n\\begin{align*}\n  \\tensor{R}{^\\alpha_{\\beta\\mu\\nu}} &\\approx\n  \\eta^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu}\n  \\\\\n  \\tensor{\\delta}{^\\mu_\\alpha} \\tensor{R}{^\\alpha_{\\beta\\mu\\nu}} &\\approx\n  R_{\\beta\\nu} \\approx\n  \\tensor{\\delta}{^\\mu_\\alpha} \\eta^{\\alpha\\sigma} R_{\\sigma\\beta\\mu\\nu} \\approx\n  \\eta^{\\mu\\sigma} R_{\\sigma\\beta\\mu\\nu}\n\\end{align*}\n\n(c) Show that $g_{\\alpha\\beta} R = \\eta_{\\alpha\\beta} \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2}$.\n\n\\begin{align*}\n  R &=\n  g^{\\mu\\nu} R_{\\mu\\nu} =\n  (\\eta^{\\mu\\nu} + h^{\\mu\\nu}) R_{\\mu\\nu} =\n  \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\eta^{\\mu\\gamma} \\eta^{\\nu\\lambda} R_{\\mu\\nu} =\n  \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2}\n  \\\\\n  g_{\\alpha\\beta} R &=\n  g_{\\alpha\\beta} \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2} =\n  (\\eta_{\\alpha\\beta} + h_{\\alpha\\beta})\n  \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2} =\n  \\eta_{\\alpha\\beta} \\eta^{\\mu\\nu} R_{\\mu\\nu} + \\order*{[h_{\\alpha\\beta}]^2}\n\\end{align*}\n\n(d) Use this to show that $G_{\\alpha\\beta} = R_{\\alpha\\beta} - \\frac{1}{2} \\eta_{\\alpha\\beta} R$.\n\n\\begin{displaymath}\n  G_{\\alpha\\beta} =\n  R_{\\alpha\\beta} - \\frac{1}{2} g_{\\alpha\\beta} R =\n  R_{\\alpha\\beta} - \\frac{1}{2} (\\eta_{\\alpha\\beta} \\eta^{\\mu\\nu} R_{\\mu\\nu}) =\n  R_{\\alpha\\beta} - \\frac{1}{2} \\eta_{\\alpha\\beta} R\n\\end{displaymath}\n\n(e) Now use this to simplify the calculation of Equation 8.32.\n\nI got stuck here. I began by expanding the expression in (d) using the results from previous sections, shown in Figure \\ref{fig:ch8-problem8e-i}. Then I expanded Equation 8.32, to get it in a more similar form, in Figures \\ref{fig:ch8-problem8e-ii} and \\ref{fig:ch8-problem8e-iii}. I did this with the hope of matching terms in the two equations, but was only able to match one. I believe something that would help me get further is Equation 8.33, $\\tensor{\\bar{h}}{^{\\mu\\nu}_{,\\nu}} = 0$.\n\n\\begin{figure}[ht]\n  \\centering\n  \\begin{subfigure}[b]{0.8\\textwidth}\n    \\includegraphics[width=\\textwidth]{img/ch8_problem_8e_part3}\n    \\caption{}\n    \\label{fig:ch8-problem8e-i}\n  \\end{subfigure}\n\n  \\begin{subfigure}[b]{0.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{img/ch8_problem_8e_part1}\n    \\caption{}\n    \\label{fig:ch8-problem8e-ii}\n  \\end{subfigure}\n  ~\n  \\begin{subfigure}[b]{0.3\\textwidth}\n    \\includegraphics[width=\\textwidth]{img/ch8_problem_8e_part2}\n    \\caption{}\n    \\label{fig:ch8-problem8e-iii}\n  \\end{subfigure}\n  \\caption{Incomplete solution to Problem 8.8 (e)}\n\\end{figure}\n\n\n\\textbf{9}\n\n(a)\n\n% I start this by making a simplification on Equation 8.32, by using Equation 8.33. In 8.32 we have the term $\\tensor{\\bar{h}}{_{\\mu\\nu}^{,\\mu\\nu}}$. If we can get this into the form of 8.33, we can cancel it out. This is easy to show\n% %\n% \\begin{displaymath}\n%   \\tensor{\\bar{h}}{_{\\mu\\nu}^{,\\mu\\nu}} =\n%   \\eta^{\\mu\\alpha} \\eta^{\\nu\\beta} \\tensor{\\bar{h}}{_{\\mu\\nu,\\mu\\nu}} =\n%   \\tensor{\\bar{h}}{^{\\alpha\\beta}_{,\\alpha\\beta}} = 0.\n% \\end{displaymath}\n% %\n% So Equation 8.32 then becomes\n% %\n% \\begin{displaymath}\n%   G_{\\alpha\\beta} =\n%  -\\frac{1}{2} [\n%     \\tensor{\\bar{h}}{_{\\alpha\\beta,\\mu}^{,\\mu}} -\n%     \\tensor{\\bar{h}}{_{\\alpha\\mu,\\beta}^{,\\mu}} -\n%     \\tensor{\\bar{h}}{_{\\beta\\mu,\\alpha}^{,\\mu}} +\n%     \\order*{[h_{\\alpha\\beta}]^2}\n%   ]\n% \\end{displaymath}\n\nI start by making a slight rewrite of Equation 8.32, changing the second $\\bar{h}$ term.\n%\n\\begin{displaymath}\n  \\eta_{\\alpha\\beta} \\tensor{\\bar{h}}{_{\\mu\\nu}^{,\\mu\\nu}} =\n  \\eta_{\\alpha\\beta} \\eta^{\\mu\\alpha} \\tensor{\\bar{h}}{_{\\mu\\nu,\\alpha}^{,\\nu}} =\n  \\tensor{\\bar{h}}{_{\\beta\\nu,\\alpha}^{,\\nu}}\n\\end{displaymath}\n%\nSo now the Einstein tensor can be written as\n%\n\\begin{displaymath}\n  G_{\\alpha\\beta} =\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{\\alpha\\beta,\\mu}^{,\\mu}} +\n    \\tensor{\\bar{h}}{_{\\beta\\nu,\\alpha}^{,\\nu}} -\n    \\tensor{\\bar{h}}{_{\\alpha\\mu,\\beta}^{,\\mu}} -\n    \\tensor{\\bar{h}}{_{\\beta\\mu,\\alpha}^{,\\mu}} +\n    \\order*{[h_{\\alpha\\beta}]^2}\n  ].\n\\end{displaymath}\n%\nFor $G_{00}$ we then have\n%\n\\begin{align*}\n  G_{00} &=\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{00,\\mu}^{,\\mu}} +\n    \\tensor{\\bar{h}}{_{0\\nu,0}^{,\\nu}} -\n    \\tensor{\\bar{h}}{_{0\\mu,0}^{,\\mu}} -\n    \\tensor{\\bar{h}}{_{0\\mu,0}^{,\\mu}} +\n    \\order*{[h_{00}]^2}\n  ]\n  \\\\ &=\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{00,\\mu}^{,\\mu}} -\n    \\tensor{\\bar{h}}{_{0\\mu,0}^{,\\mu}} +\n    \\order*{[h_{00}]^2}\n  ]\n  \\\\ &=\n -\\frac{1}{2} [\n    (\\tensor{\\bar{h}}{_{00,0}^{,0}} + \\tensor{\\bar{h}}{_{00,i}^{,i}}) -\n    (\\tensor{\\bar{h}}{_{00,0}^{,0}} + \\tensor{\\bar{h}}{_{0i,0}^{,i}}) +\n    \\order*{[h_{00}]^2}\n  ]\n  \\\\ &=\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{00,i}^{,i}} -\n    \\tensor{\\bar{h}}{_{0i,0}^{,i}} +\n    \\order*{[h_{00}]^2}\n  ],\n\\end{align*}\n%\nwhich contains no second time derivatives. For $G_{0i}$ I encountered a problem:\n%\n\\begin{align*}\n  G_{0i} &=\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{0i,\\mu}^{,\\mu}} +\n    \\tensor{\\bar{h}}{_{i\\nu,0}^{,\\nu}} -\n    \\tensor{\\bar{h}}{_{0\\mu,i}^{,\\mu}} -\n    \\tensor{\\bar{h}}{_{i\\mu,0}^{,\\mu}} +\n    \\order*{[h_{0i}]^2}\n  ]\n  \\\\ &=\n -\\frac{1}{2} [\n    \\tensor{\\bar{h}}{_{0i,\\mu}^{,\\mu}} -\n    \\tensor{\\bar{h}}{_{0\\mu,i}^{,\\mu}} +\n    \\order*{[h_{0i}]^2}\n  ]\n  \\\\ &=\n -\\frac{1}{2} [\n    (\\tensor{\\bar{h}}{_{0i,0}^{,0}} + \\tensor{\\bar{h}}{_{0i,j}^{,j}}) -\n    \\tensor{\\bar{h}}{_{0\\mu,i}^{,\\mu}} +\n    \\order*{[h_{0i}]^2}\n  ],\n\\end{align*}\n%\nwhich retains a second time derivative in the $\\tensor{\\bar{h}}{_{0i,0}^{,0}}$ term.\n\n(b)\n\nAccording to Schutz's solution it is not a contradiction, due in part to Equation 8.33. I don't fully understand the reason, though.\n\n\n\\textbf{11}\nWrite the gauge transformation and Lorentz gauge condition in four-tensor notation for Maxwell's equations. Draw an analogy with linearized gravity.\n\nFirst we rewrite $\\phi \\to \\phi - \\pdv*{f}{t}$ as $-A_0 \\to -A_0 - f_{,0}$, and cancelling the negatives we get $A_0 \\to A_0 + f_{,0}$. Combining this with $A_i \\to A_i + f_{,i}$, it is obvious that the gauge transformation generalizes to $A_\\alpha \\to A_\\alpha + f_{,\\alpha}$.\n\nThe Lorentz gauge condition is just slightly less obvious. We start by noting that $A_0 = -\\phi$, and therefore (in Minkowski space) $A^0 = \\eta^{0\\mu} A_\\mu = g^{00} A_0 = (-1) (-\\phi) = \\phi$. Then the Lorentz gauge condition  becomes $\\phi_{,0} + \\grad_i A^i = \\tensor{A}{^0_{,0}} + \\tensor{A}{^i_{,i}} = \\tensor{A}{^\\alpha_{,\\alpha}} = 0$. This is analogous to $\\tensor{\\bar{h}}{^{\\mu\\nu}_{,\\nu}}$.\n\n\n\n\\textbf{13}\nGive a physical justification for $\\abs{T^{00}} \\gg \\abs{T^{0i}} \\gg \\abs{T^{ij}}$ in a Newtonian system.\n\nThe first inequality is easy to see. $T^{00} = E / V = p^0 / V$, and $T^{0i} = p^i / V$. In the Newtonian limit, $\\abs{p^0} \\gg \\abs{p^i}$, and so it follows that $\\abs{T^{00}} \\gg \\abs{T^{0i}}$.\n\nThe second inequality is less obvious. In the Newtonian limit, forces must be relatively small, or else objects would be accelerated to relativistic speeds. By this argument, the stresses must also be relatively small, and so $T^{0i} \\gg T^{ij}$.\n\n\\textbf{17}\n\n(a) First I need to convert the orbital period into meters.\n%\n\\begin{displaymath}\n  T =\n  \\SI{200}{days} \\times\n  \\frac{\\SI{24}{hours}}{\\SI{1}{day}} \\times\n  \\frac{\\SI{3600}{seconds}}{\\SI{1}{hour}} \\times\n  c \\approx\n  \\SI{5.18e15}{\\meter}\n\\end{displaymath}\n%\nThen I use the potential to find the speed, which I relate to the circumference and orbital period, and solve for the mass.\n%\n\\begin{gather*}\n  \\phi = -G M / r\n  \\\\\n  v^2 = -\\phi\n\\end{gather*}\n\\begin{align*}\n  M &= v^2 r / G = C^3 / (2 \\pi T^2 G) \\approx\n  (\\SI{6e11}{\\meter})^3 / (2 \\pi (\\SI{5.18e15}{\\meter})^2 G)\n  \\\\ &\\approx\n  \\SI{1.281e3}{\\meter} \\times \\frac{1 M_\\Sun}{\\SI{1.476e3}{m}} \\approx\n  0.868 M_\\Sun\n\\end{align*}\n\n(b)\n\nUsing the above formula, I get a distribution of mass estimates, shown in Figure \\ref{fig:ch8-problem17b}. Closer to the black hole, the Newtonian approximation breaks down, and the ``effective mass'' blows up. Far from the black hole, we can see that the effective mass is in agreement for all of the sattelites, and so the Newtonian approximation is working again. Thus, I use the furthest sattelite to find that the black hole's mass is $68 M_\\Sun$.\n\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{img/ch8_problem_17b}\n  \\caption{Black hole mass estimates in Problem 8.17, as a function of sattelite circumference.}\n  \\label{fig:ch8-problem17b}\n\\end{figure}\n\n\n\n\\end{document}", "meta": {"hexsha": "c6100bff1ee48c913bd5a8c628d31bfdf7023c72", "size": 11214, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/textbook/tex/gr-ch8-notes.tex", "max_stars_repo_name": "dwysocki/ASTP-760", "max_stars_repo_head_hexsha": "da116f346bfa40fa3f9620782a2c85e9e9654e37", "max_stars_repo_licenses": ["MIT"], "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/textbook/tex/gr-ch8-notes.tex", "max_issues_repo_name": "dwysocki/ASTP-760", "max_issues_repo_head_hexsha": "da116f346bfa40fa3f9620782a2c85e9e9654e37", "max_issues_repo_licenses": ["MIT"], "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/textbook/tex/gr-ch8-notes.tex", "max_forks_repo_name": "dwysocki/ASTP-760", "max_forks_repo_head_hexsha": "da116f346bfa40fa3f9620782a2c85e9e9654e37", "max_forks_repo_licenses": ["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.8791540785, "max_line_length": 489, "alphanum_fraction": 0.6182450508, "num_tokens": 4352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6141235366466297}}
{"text": "\\chapter{Cryptol prelude functions}\n\n\\commentout{\n\\begin{code}\nprimsPlaceHolder=1;\n\\end{code}\n}\n\n\\paragraph*{Bitwise and logical operations}\n\\begin{Verbatim}\n    True, False : Bit\n    &&, ||, ^   : {a} (Logic a) => a -> a -> a\n    ~           : {a} (Logic a) => a -> a\n    ==>, /\\, \\/ : Bit -> Bit -> Bit\n\\end{Verbatim}\n\\paragraph*{Comparisons}\n\\begin{Verbatim}\n    ==, !=           : {a} (Eq a) => a -> a -> Bit\n    <, >, <=, >=     : {a} (Cmp a) => a -> a -> Bit\n    <$, >$, <=$, >=$ : {a} (SignedCmp a) => a -> a -> Bit\n    min, max         : {a} (Cmp a) => a -> a -> a\n    ===, !==         : {a, b} (Eq b) => (a -> b) -> (a -> b) -> a -> Bit\n\\end{Verbatim}\n\\paragraph*{Arithmetic}\n\\begin{Verbatim}\n    +, -, *           : {a} (Ring a) => a -> a -> a\n    negate            : {a} (Ring a) => a -> a\n    fromInteger       : {a} (Ring a) => Integer -> a\n    ^^                : {a, e} (Ring a, Integral e) => a -> e -> a\n    abs               : {a} (Cmp a, Ring a) => a -> a\n    /, %              : {a} (Integral a) => a -> a -> a\n    toInteger         : {a} (Integral a) => a -> Integer\n    lg2               : {n} (fin n) => [n] -> [n]\n    /$, %$            : {n} (fin n, n >= 1) => [n] -> [n] -> [n]\n    carry             : {n} (fin n) => [n] -> [n] -> Bit\n    scarry, sborrow   : {n} (fin n, n >= 1) => [n] -> [n] -> Bit\n    zext              : {m, n} (fin m, m >= n) => [n] -> [m]\n    sext              : {m, n} (fin m, m >= n, n >= 1) => [n] -> [m]\n    ratio             : Integer -> Integer -> Rational\n    /.                : {a} (Field a) => a -> a -> a\n    recip             : {a} (Field a) => a -> a\n    floor             : {a} (Round a) => a -> Integer\n    ceiling           : {a} (Round a) => a -> Integer\n    trunc             : {a} (Round a) => a -> Integer\n    roundAway         : {a} (Round a) => a -> Integer\n    roundToEven       : {a} (Round a) => a -> Integer\n\\end{Verbatim}\n\\paragraph*{GF(2) polynomial arithmetic}\n\\begin{Verbatim}\n    pdiv  : {u, v} (fin u, fin v) => [u] -> [v] -> [u]\n    pmod  : {u, v} (fin u, fin v) => [u] -> [1 + v] -> [v]\n    pmult : {u, v} (fin u, fin v) => [1 + u] -> [1 + v] -> [1 + u + v]\n\\end{Verbatim}\n\\paragraph*{Sequences}\n\\begin{Verbatim}\n    take      : {front, back, a} (fin front) => [front + back]a -> [front]a\n    drop      : {front, back, a} (fin front) => [front + back]a -> [back]a\n    #         : {front, back, a} (fin front) => [front]a -> [back]a -> [front + back]a\n    join      : {parts, each, a} (fin each) => [parts][each]a -> [parts * each]a\n    split     : {parts, each, a} (fin each) => [parts * each]a -> [parts][each]a\n    groupBy   : {each, parts, a} (fin each) => [parts * each]a -> [parts][each]a\n    transpose : {rows, cols, a} [rows][cols]a -> [cols][rows]a\n    reverse   : {n, a} (fin n) => [n]a -> [n]a\n    head      : {n, a} [1 + n]a -> a\n    tail      : {n, a} [1 + n]a -> [n]a\n    last      : {n, a} (fin n) => [1 + n]a -> a\n\\end{Verbatim}\n\\paragraph*{Indexing, updates}\n\\begin{Verbatim}\n    @       : {n, a, ix} (Integral ix) => [n]a -> ix -> a\n    !       : {n, a, ix} (fin n, Integral ix) => [n]a -> ix -> a\n    @@      : {n, k, ix, a} (Integral ix) => [n]a -> [k]ix -> [k]a\n    !!      : {n, k, ix, a} (fin n, Integral ix) => [n]a -> [k]ix -> [k]a\n    update     : {n, a, ix} (fin ix) => [n]a -> [ix] -> a -> [n]a\n    updateEnd  : {n, a, ix} (fin n, Integral ix) => [n]a -> ix -> a -> [n]a\n    updates    : {n, k, ix, a} (Integral ix, fin k) => [n]a -> [k]ix -> [k]a -> [n]a\n    updatesEnd : {n, k, ix, a} (fin n, Integral ix, fin k) => [n]a -> [k]ix -> [k]a -> [n]a\n\\end{Verbatim}\n\\paragraph*{Shifting, rotating}\n\\begin{Verbatim}\n    >>>, <<< : {n, ix, a} (fin n, Integral ix) => [n]a -> ix -> [n]a\n    >>, <<   : {n, ix, a} (Integral ix, Zero a) => [n]a -> ix -> [n]a\n    >>$      : {n, ix} (fin n, n >= 1, Integral ix) => [n] -> ix -> [n]\n\\end{Verbatim}\n\\paragraph*{Functional programming}\n\\begin{Verbatim}\n    iterate  : {a} (a -> a) -> a -> [inf]a\n    repeat   : {n, a} a -> [n]a\n    map      : {n, a, b} (a -> b) -> [n]a -> [n]b\n    zip      : {n, a, b} [n]a -> [n]b -> [n](a, b)\n    zipWith  : {n, a, b, c} (a -> b -> c) -> [n]a -> [n]b -> [n]c\n    foldl    : {n, a, b} (fin n) => (a -> b -> a) -> a -> [n]b -> a\n    foldl' : {n, a, b} (fin n, Eq a) => (a -> b -> a) -> a -> [n]b -> a\n    foldr    : {n, a, b} (fin n) => (a -> b -> b) -> b -> [n]a -> b\n    foldr' : {n, a, b} (fin n, Eq b) => (a -> b -> b) -> b -> [n]a -> b\n    scanl    : {n, b, a} (b -> a -> b) -> b -> [n]a -> [1 + n]b\n    scanr    : {n, a, b} (fin n) => (a -> b -> b) -> b -> [n]a -> [1 + n]b\n    sum : {n, a} (fin n, Eq a, Ring a) => [n]a -> a\n    product : {n, a} (fin n, Eq a, Ring a) => [n]a -> a\n    and, or  : {n} (fin n) => [n] -> Bit\n    all, any : {n, a} (fin n) => (a -> Bit) -> [n]a -> Bit\n    curry    : {a, b, c} ((a, b) -> c) -> a -> b -> c\n    uncurry  : {a, b, c} (a -> b -> c) -> (a, b) -> c\n    elem     : {n, a} (fin n, Eq a) => a -> [n]a -> Bit\n\\end{Verbatim}\n\\paragraph*{Miscellaneous}\n\\begin{Verbatim}\n    deepseq : {a, b} Eq a => a -> b -> b\n    rnf : {a} Eq a => a -> a\n    length : {n, a, b} (fin n, Literal n b) => [n]a -> b\n    zero    : {a} (Zero a) => a\n\\end{Verbatim}\n\\paragraph*{Representing exceptions}\n\\begin{Verbatim}\n    undefined : {a} a\n    error     : {a, n} (fin n) => String n -> a\n    assert    : {a, n} (fin n) => Bit -> String n -> a -> a\n    trace     : {n, a, b} [n][8] -> a -> b -> b\n    traceVal  : {n, a} [n][8] -> a -> a\n\\end{Verbatim}\n\\todo[inline]{\\texttt{error} and \\texttt{undefined} are not covered in\n  the book at the moment.}\n\n\\todo[inline]{What is the state of debugging (\\texttt{trace},\n  \\texttt{ASSERT}), randomness (\\texttt{random}), and pretty-printing\n  (\\texttt{format}) built-ins?}\n%\\paragraph*{Debugging}\n%\\begin{Verbatim}\n%    trace  : {a b c} ([a][8],b,c) -> c\n%    ASSERT : {a b} (Bit,[a][8],b) -> b\n%\\end{Verbatim}\n%\\paragraph*{Generating random numbers}\n%\\begin{Verbatim}\n%    random : {a b} (32 >= a) => [a] -> b\n%\\end{Verbatim}\n%\\paragraph*{Pretty printing}\n%\\begin{Verbatim}\n%    format\n%\\end{Verbatim}\n\n%    (%$) : {a} (Arith a) => a -> a -> a\n%    (/$) : {a} (Arith a) => a -> a -> a\n%    number : {val, rep} (Literal val rep) => rep\n%    elem : {n, a} (fin n, Cmp a) => a -> [n]a -> Bit\n%    fromThenTo :\n%      {first, next, last, a, len} (fin first, fin next, fin last,\n%                                   Literal first a, Literal next a, Literal last a, first != next,\n%                                   lengthFromThenTo first next last == len) =>\n%        [len]a\n%    fromTo :\n%      {first, last, a} (fin last, last >= first, Literal last a) =>\n%        [1 + (last - first)]a\n%    fromZ : {n} (fin n, n >= 1) => Z n -> Integer\n%    infFrom : {a} (Arith a) => a -> [inf]a\n%    infFromThen : {a} (Arith a) => a -> a -> [inf]a\n%    splitAt :\n%      {front, back, a} (fin front) =>\n%        [front + back]a -> ([front]a, [back]a)\n%    toInteger : {bits} (fin bits) => [bits] -> Integer\n%    trace : {n, a, b} (fin n) => [n][8] -> a -> b -> b\n%    traceVal : {n, a} (fin n) => [n][8] -> a -> a\n%    undefined : {a} a\n%    zext : {m, n} (fin m, m >= n) => [n] -> [m]\n%    sext : {m, n} (fin m, m >= n, n >= 1) => [n] -> [m]\n%    carry : {n} (fin n) => [n] -> [n] -> Bit\n%    scarry : {n} (fin n, n >= 1) => [n] -> [n] -> Bit\n%    sborrow : {n} (fin n, n >= 1) => [n] -> [n] -> Bit\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../main/Cryptol\"\n%%% End: \n", "meta": {"hexsha": "e9616faff62bbab836e1b3d8bfc4f9319f26ee14", "size": 7409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/ProgrammingCryptol/prims/Primitives.tex", "max_stars_repo_name": "emlisa3162/cryptol", "max_stars_repo_head_hexsha": "5a668a4594e386a084f6f0ceb231c69946971a50", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 773, "max_stars_repo_stars_event_min_datetime": "2015-01-08T15:43:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T04:26:02.000Z", "max_issues_repo_path": "docs/ProgrammingCryptol/prims/Primitives.tex", "max_issues_repo_name": "emlisa3162/cryptol", "max_issues_repo_head_hexsha": "5a668a4594e386a084f6f0ceb231c69946971a50", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1050, "max_issues_repo_issues_event_min_datetime": "2015-01-02T23:10:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T17:02:34.000Z", "max_forks_repo_path": "docs/ProgrammingCryptol/prims/Primitives.tex", "max_forks_repo_name": "axon-terminal/cryptol", "max_forks_repo_head_hexsha": "571f0dd249a72f830abd511caca87a971a91d07e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 117, "max_forks_repo_forks_event_min_datetime": "2015-01-01T18:45:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T15:40:57.000Z", "avg_line_length": 42.8265895954, "max_line_length": 99, "alphanum_fraction": 0.4235389391, "num_tokens": 3020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6138947325623826}}
{"text": "\\chapter{Complete UFC code for Poisson's equation}\n\\index{Poisson's equation}\n\\index{example code}\n\nIn this section, a simple example is given of UFC code generated by\nthe form compilers\nFFC~\\cite{www:ffc,logg:article:07,logg:article:09,logg:article:10,logg:article:11}\nand SyFi~\\cite{www:syfi} for Poisson's equation. The code presented\nbelow is generated for the bilinear form of Poisson's equation for\nstandard continuous piecewise linear Lagrange finite elements on a\ntwo-dimensional domain $\\Omega$,\n\\begin{equation}\n  a(v, u) = \\int_{\\Omega} \\nabla v \\cdot \\nabla u \\dx.\n\\end{equation}\n\nAlthough FFC and SyFi are two different form compilers, with very\ndifferent approaches to code generation, both generate code that\nconforms to the UFC specification and may thus be used interchangeably\nwithin any UFC-based system.\n\nIn the generated code, we have omitted the two functions\n\\texttt{evaluate\\_basis} and\n\\texttt{evaluate\\_basis\\_derivatives}\\footnotemark{} to save space.\n\n\\footnotetext{For FFC, this may be done by using the compiler flags\n  \\texttt{-fno-evaluate\\_basis} and\n  \\texttt{-fno-evaluate\\_basis\\_derivatives}.}\n\n\\section{Code generated by FFC}\n\\index{FFC}\n\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/poisson_ffc.h}\n\\normalsize\n\n\\section{Code generated by SyFi}\n\\index{SyFi}\n\nIn the following we list the complete code for the finite element,\nthe dofmap and the variational form for computing a stiffness matrix\nbased on linear Lagrangian elements in 2D.\n\nThe code below is generated for the assembler in PyCC and it therefore\nincludes some PyCC files, since the option \\texttt{SFC.options.include\\_from = \"pycc\"} was used during the code generation. If PyCC is not present, the option \\texttt{SFC.options.include\\_from = \"syfi\"} can be used, and this will result in some additional files that define the numbering scheme.\n\n\\subsection{Header file for linear Lagrange element in 2D}\n\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/fe_Lagrange_1_2D.h}\n\\normalsize\n\n\\subsection{Source file for linear Lagrange element in 2D}\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/fe_Lagrange_1_2D.cpp}\n\\normalsize\n\n\\subsection{Header file for the dofmap}\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/dof_map_Lagrange_1_2D.h}\n\\normalsize\n\n\\subsection{Source file for the dofmap}\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/dof_map_Lagrange_1_2D.cpp}\n\\normalsize\n\n\\subsection{Header file for the stiffness matrix form}\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/form__stiffness_form__Lagrange_1_2D.h}\n\\normalsize\n\n\n\\subsection{Source file for the stiffness matrix form}\n\\scriptsize\n\\VerbatimInput[frame=single,rulecolor=\\color{blue}]{code/stiffness_syfi/form__stiffness_form__Lagrange_1_2D.cpp}\n\\normalsize\n", "meta": {"hexsha": "35a28923226be8a670a2d83f457b31f061a33585", "size": 2934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ufc-2.0.5/doc/manual/chapters/examples.tex", "max_stars_repo_name": "szmurlor/fiver", "max_stars_repo_head_hexsha": "083251420eb934d860c99dcf1eb07ae5b8ba7e8c", "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/ufc-2.0.5/doc/manual/chapters/examples.tex", "max_issues_repo_name": "szmurlor/fiver", "max_issues_repo_head_hexsha": "083251420eb934d860c99dcf1eb07ae5b8ba7e8c", "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/ufc-2.0.5/doc/manual/chapters/examples.tex", "max_forks_repo_name": "szmurlor/fiver", "max_forks_repo_head_hexsha": "083251420eb934d860c99dcf1eb07ae5b8ba7e8c", "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": 38.1038961039, "max_line_length": 295, "alphanum_fraction": 0.80334015, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6138947208338016}}
{"text": "\\documentclass{article}\n\n\\usepackage{mathrsfs,amssymb,amsmath,amsfonts}\n\n\\newcommand*\\conj[1]{\\overline{#1}}\n\n\\begin{document}\n\n\\section{Let $e_0, e_1, ...$ be an orthonormal basis for $\\mathscr{H}$ and let $\\alpha_0, \\alpha_1, ...$ be complex numbers. Define $\\mathscr{D} = \\{ h \\in \\mathscr{H} :  \\sum_{0}^{\\infty} | \\alpha_n \\langle h, e_n \\rangle |^2 < \\infty \\}$ and let $Ah= \\sum_{0}^{\\infty} \\alpha_n \\langle h, e_n \\rangle e_n$ for $h$ in $\\mathscr{D}$. Then $A \\in \\mathscr{C}(\\mathscr{H})$ with dom $A=\\mathscr{D}$. Also, dom $A^*=\\mathscr{D}$ and $A^*h=\\sum_{0}^{\\infty} \\conj{\\alpha_n} \\langle h, e_n \\rangle e_n$ for all $h$ in $\\mathscr{D}$}\n\nExercise X.1.2: Prove claims in X.1.9\n\nSince Hilbert Spaces in the chapter are assumed to be separable, to show that $\\mathscr{D}$ is dense we must show that for every $h \\in \\mathscr{H}$, there exists a sequence $h_{\\bullet}$ in $\\mathscr{D}$ that converges to $h$. Let $h = \\sum_{0}^{\\infty} \\beta_n e_n$ where all but finite number of $\\beta_n$ are 0. ???\n\nNext we have to show that $A$ is closed, that is $\\{ h \\oplus Ah : h \\in \\mathscr{D}\\}$ is closed in $\\mathscr{H} \\oplus \\mathscr{H}$. Again since $\\mathscr{H}$ is separable, this amounts to showing that the limit of an arbitrary sequence $h_{\\bullet}$ of $\\mathscr{D}$ is still in $h \\oplus Ah$. Again not sure where to go from here.\n\nTo show that $A^*h=\\sum_{0}^{\\infty} \\conj{\\alpha_n} \\langle h, e_n \\rangle e_n$, start with $\\langle Ah, k \\rangle = \\langle h, A^*k \\rangle$. \n\n$ \\langle \\sum_{0}^{\\infty} \\alpha_n \\langle h, e_n \\rangle e_n, k \\rangle$\n\n\\end{document}", "meta": {"hexsha": "b01aea4887b80cb58c06b8acda9f1eb601ec2471", "size": 1590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "analysis/10_Unbounded_Operators/problems.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/10_Unbounded_Operators/problems.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/10_Unbounded_Operators/problems.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": 75.7142857143, "max_line_length": 527, "alphanum_fraction": 0.6610062893, "num_tokens": 590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6138696846999433}}
{"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% ============================================================\n\n% define the title\n\\title{SOC 4930/5050: Week 10 Equations}\n\\author{Christopher Prener, Ph.D.}\n\\date{October 30\\textsuperscript{th}, 2017}\n% ============================================================\n\\begin{document}\n% ============================================================\n\\maketitle % generates the title\n% ============================================================\n\n\\vspace{5mm}\n\\section{Pearson's r}\n\\begin{subequations}\n\\paragraph{Calculating r}\n\\begin{equation}\n\\scalebox{2} {$ r =\\frac { \\sum _{ i=1 }^{ n }{ (x-\\overline { x } )(y-\\overline { y } ) }  }{ (n-1){s}_{x}{s}_{y} } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Percent of Variance Explained}\n\\begin{equation}\n\\scalebox{2} {$ {r}^{2} $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Calculating Degrees of Freedom (v)}\n\\begin{equation}\n\\scalebox{2} {$ v=n-2 $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Calculating t}\n\\begin{equation}\n\\scalebox{2} {$ t=\\frac{r}{\\sqrt{\\frac{1-{r}^{2}}{v}}} $}\n\\end{equation}\n\\end{subequations}\n\n% ============================================================\n\\end{document}", "meta": {"hexsha": "f816f70fa7dab5eb1e5ff4c4b4856c734dc15768", "size": 1285, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-10-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-10-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-10-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": 25.1960784314, "max_line_length": 119, "alphanum_fraction": 0.5182879377, "num_tokens": 379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.613869680475326}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\n\\title {Jacobian Free Newton's Method for Non-Linear Systems with Composit Residual Functions via MAUD}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Problem Definition}\n\nComposite resids arise when solving a non-linear system whos residual evaluation is a function of two\nor more different components. For example, consider a non linear system with state variable vector, $u$, and\nresidual vector, $r$, computed via two components, $Y$ and $R$. Assume $u$ and $r$ are of size $n$.\n\n\\begin{equation}\n  u \\longrightarrow Y \\longrightarrow y \\longrightarrow R \\longrightarrow r\n\\end{equation}\n\n$y$ and $r$ are explicit functions of $u$ and $y$ respectively\n\n\\begin{align}\n  y = & Y(u) \\notag \\\\\n  r = & R(y)\n\\end{align}\n\nA composite residual function, $G$, is then defined\n\n\\begin{equation}\n  G(u) = R(Y(u))\n\\end{equation}\n\nThe problem definition is then given as follows\n\n\\begin{align}\n  Find &\\  u \\notag \\\\\n  s.t. &\\  G(u) = 0\n\\end{align}\n\n\\section{Traditional Newtons Method}\n\nThe Newton update, $\\Delta u$, is computed via\n\\begin{equation}\n  \\frac{\\partial G}{\\partial u} \\Delta u = -G(u)\n\\end{equation}\n\nExpanding the partial derivative of $G$ out to account for the composite residual function\ngives\n\n\\begin{equation}\n  \\frac{\\partial R}{\\partial y}  \\frac{\\partial Y}{\\partial u} \\Delta u = -R\\left(Y(u)\\right)\n  \\label{expanded_newton_iter}\n\\end{equation}\n\nIn order to compute $\\Delta u$, the partial derivatives\n$\\frac{\\partial R}{\\partial y}$ and  $\\frac{\\partial Y}{\\partial u}$ must first be computed.\nThen a matrix multiplication is performed ($\\mathcal{O}(n^3)$) to get $\\frac{\\partial G}{\\partial u}$.\nLastly the solution to a size $n$ linear system is found.\n\n\\section{MAUD Formulation}\n\nRepresenting the composite residual as a system of non linear equations using the MAUD yeilds\ntwo separate, but coupled, residual functions with $y$ and $r$ as state variables\nand $u$ as an input.\n\n\\begin{align}\n  A(u,y,r) & = y - Y(u) \\label{MAUD_y} \\\\\n  B(u,y,r) & = r - R(y) \\label{MAUD_r}\n  \\label{maud1}\n\\end{align}\n\nThe original problem formulation seeks to drive $r$ to 0. So we'll just assume\nthat $r$ is 0, then find values of $u$ and $y$ that drive\nthe remaining resids to 0. This gives a new system of equations:\n\n\\begin{align}\n  C(u,y) & = y - Y(u) = 0 \\label{y_resid} \\\\\n  D(r,y) & = R(y) = 0 \\label{r_resid}\n  \\label{maud2}\n\\end{align}\n\nYou can compute a Newton update for the non-linear system via\n\n\\begin{equation}\n  \\begin{bmatrix}\n    \\frac{\\partial C}{\\partial u} & \\frac{\\partial C}{\\partial y} \\\\\n    \\frac{\\partial D}{\\partial u} & \\frac{\\partial D}{\\partial y}\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\Delta u \\\\\n    \\Delta y\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n    -C(u,y) \\\\\n    -D(u,y)\n  \\end{bmatrix}\n\\end{equation}\n\n\\begin{equation}\n  \\begin{bmatrix}\n    -\\frac{\\partial Y}{\\partial u} & 1 \\\\\n    0 & \\frac{\\partial R}{\\partial y}\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    \\Delta u \\\\\n    \\Delta y \\\\\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n    Y(u) - y \\\\\n    - R(y)\n  \\end{bmatrix}\n\\end{equation}\n\nExpanding out the linear system yields\n\n\\begin{align}\n  -\\frac{\\partial Y}{\\partial u} \\Delta u + \\Delta y & = Y(u) - y   \\label{Delta_u} \\\\\n  \\frac{\\partial R}{\\partial y} \\Delta y & = -R(y)   \\label{Delta_y}\n\\end{align}\n\n\nMultiplying both sides by of Eqn.~\\ref{Delta_u} by $\\frac{\\partial R}{\\partial y}$ yields\n\n\\begin{equation}\n  -\\frac{\\partial R}{\\partial y} \\frac{\\partial Y}{\\partial u} \\Delta u + \\frac{\\partial R}{\\partial y} \\Delta y = Y(u) - y\n\\end{equation}\n\nNow, assuming that you always executed $Y$ first and then $R$, you know that $Y(u) - y$ will always be identically 0.\n\n\\begin{equation}\n  -\\frac{\\partial R}{\\partial y} \\frac{\\partial Y}{\\partial u} \\Delta u + \\frac{\\partial R}{\\partial y} \\Delta y = 0\n  \\label{newton_update_1}\n\\end{equation}\n\nFinally, substituting Eqn.~\\ref{Delta_y} into Eqn.~\\ref{newton_update_1} yeilds\n\n\\begin{equation}\n  \\frac{\\partial R}{\\partial y} \\frac{\\partial Y}{\\partial u} \\Delta u = -R(y)\n  \\label{maud_Delta_u_update}\n\\end{equation}\n\nWe now note that Eqn.~\\ref{maud_Delta_u_update} and Eqn.~\\ref{expanded_newton_iter} are equivalent, hence\nthe resulting $\\Delta u$ value computed via the traditional method and the MAUD method are also\nequivalent.\n\nHowever, the MAUD provides a computational savings. The partial derivatives $\\frac{\\partial R}{\\partial y}$\nand $\\frac{\\partial Y}{\\partial u}$ must still be computed. But the newton update, $\\Delta u$ can now be found\ndirectly via a single solution to a linear system of size $n$ without the expensive matrix\nmultiplication step needed with the traditional method.\n\n\\end{document}\n", "meta": {"hexsha": "b11c58ea2c61375a8ca94f718b6ce8b433fdb455", "size": 4658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/newton_solve_eqivilence.tex", "max_stars_repo_name": "naylor-b/OpenMDAO1", "max_stars_repo_head_hexsha": "49d82f6601b33db9bdcf7d146d030d55e3b62ef4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-01-11T20:13:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T03:46:05.000Z", "max_issues_repo_path": "theory/newton_solve_eqivilence.tex", "max_issues_repo_name": "naylor-b/OpenMDAO1", "max_issues_repo_head_hexsha": "49d82f6601b33db9bdcf7d146d030d55e3b62ef4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-19T23:14:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-22T17:30:57.000Z", "max_forks_repo_path": "theory/newton_solve_eqivilence.tex", "max_forks_repo_name": "naylor-b/OpenMDAO1", "max_forks_repo_head_hexsha": "49d82f6601b33db9bdcf7d146d030d55e3b62ef4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-04-12T22:13:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-07T10:02:59.000Z", "avg_line_length": 30.2467532468, "max_line_length": 123, "alphanum_fraction": 0.6878488622, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6138696804753259}}
{"text": "%\\ctparttext{\\color{black}\\begin{center}\n%\t\tEsta es una descripción de la parte de informática.\n%\\end{center}}\n\n%\\part{Parte de informática}\n\\chapter{Quantum Mechanics Model}\n\n\nQuantum Mechanics are a mathematical framework in which quantum physics are developed. In this section, we will develop a quantum mechanics model in order to understand quantum computing. The Quantum Postulates will be our guidance. They provide a connection between the physical world and the mathematical formalization. We will provide context and formalization for each postulate, so both the mathematical precision and intuition notions are developed at the same time. This development is based on \\cite{Nielsen2002}, \\cite{Manzano2020} and \\cite{Bayens2019}.\n\n\n\\section{Postulate 1: State Space}\n\n\nThe first postulate sets the environment in which we will operate: The State Space. It will be a Hilbert space associated to a physicial system. Let us rigorously define the necessary concepts using the Bra-ket notation. We will start by revisiting the required linear algebra.\n\n\n\\subsection{Bra-ket notation}\n\n\nLet $V$ be a complex vector space. That is, a vector space over $\\C$. We will restrict our study to finite complex vector spaces. If $z$ is a vector in $V$, we will denote its coordinates either as $z = (z_1, z_2, \\dotsc, z_n)$ or by column notation:\n\n$$ z = \n\\begin{pmatrix}\n\tz_1\\\\\n\tz_2 \\\\\n\t\\vdots \\\\\n\tz_n\n\\end{pmatrix}\n$$\n\nSince $V$ is a vector space we have two basic operations: (vector) addition and scalar multiplication.\n\nIn quantum mechanics, the usual notation is the Dirac's, also known as \\emph{bra-ket} notation. In this context, vectors in a complex vector space are denoted as $|\\varphi\\ra$ and are known as \\emph{kets}. The only exception to this is the zero vector, which will be denoted as $0 = (0, \\dotsc, 0)$ instead of $|0\\ra$ since $|0\\ra$ will be used as something completely different. A \\emph{vector subspace} $W$ of $V$ is a subset of $V$ closed for addition and scalar multiplication.\n\nA \\emph{base} of a vector space is a set of vectors $|v_1\\ra, \\dotsc, |v_n\\ra$ such that they are linearly independent and any given vector $|v\\ra$ can be written as a linear combination of them: $|v\\ra = \\sum_{i=1}^n \\alpha_i|v_i\\ra$. The \\emph{dimension} of a vector space is the number of elements in any of its bases, which is independent from the chosen base.\n\n\\begin{definition}\n\tGiven two complex vector spaces $V$ and $W$, a \\emph{linear operator} is an application $M: V \\rightarrow W $ that is linear in its inputs:\n\t\n\t$$ M \\Big( \\alpha |u\\ra + \\beta |w\\ra \\Big) = \\alpha M (|u\\ra) + \\beta M (|w\\ra) $$\n\\end{definition}\n\nIf $V$ to $W$ have dimensions $n$ and $m$ respectively, there is a bijection between the operators from $V$ to $W$ and the $n$ by $m$ matrices. Given an operator $M$, the obtained matrix $M'$ is called the \\emph{matrix representation} of the linear operator. Furthermore, $M(|u\\ra) = M' \\cdot |u\\ra$, so we usually denote the linear operator and its matrix representation by the same letter, and $M(|u\\ra)$ simply as $M|u\\ra$.\n\nWe will usually refer to linear operators simply as \\emph{operators}.\n\n\n\\subsection{Inner product and Hilbert Spaces}\n\n\nLet us define another operation within the complex vector spaces.\n\n\\begin{definition}\n\tLet $V$ be a complex vector space. An inner product $\\la \\cdot | \\cdot \\ra: V^2 \\rightarrow \\C$ is a function such that:\n\t\n\t\\quad 1) $\\la \\cdot | \\cdot \\ra$ is sesquilinear. That is,\n\t\n\t\\qquad 1.1) $\\la \\cdot | \\cdot \\ra$ is conjugate symmetric: for all $u,v$ in $V$, $\\la u | v \\ra = \\overline{\\la v | u \\ra}$.\n\t\n\t\\qquad 1.2) $\\la \\cdot | \\cdot \\ra$ is linear on the second variable: for all $u,v,w$ in $V$ and $\\alpha, \\beta$ in $\\C$:\n\t\n\t$$ \\la u  | \\alpha v + \\beta w \\ra = \\alpha \\la u | v \\ra + \\beta \\la u | w \\ra $$\n\t\n\t\\quad 2) $\\la \\cdot | \\cdot \\ra$ is definite positive. That is, for all $u$ in $V$, $\\la u | u \\ra \\geq 0$ and $\\la u | u \\ra = 0 \\Longleftrightarrow v = 0$.\n\\end{definition}\n\nGiven this properties it can easily be proven that $\\la \\cdot | \\cdot \\ra$ is also conjugate linear on the first variable. That is, for all $u,v,w$ in $V$ and $\\alpha, \\beta$ in $\\C$:\n\n$$ \\la \\alpha u + \\beta v  | w \\ra = \\overline{\\alpha} \\la u | w \\ra + \\overline{\\beta} \\la v | w \\ra $$\n\nWe will sometimes denote the inner product $\\la \\cdot | \\cdot \\ra$ as $( \\cdot , \\cdot )$ to simplify notation.\n\nTwo vectors are said to be \\emph{orthonormal} if their inner product is zero. We define the norm of a vector $|v\\ra$ by:\n\n$$\\parallel |v\\ra \\parallel \\ = \\sqrt{ \\la v|v\\ra }$$\n\nA \\emph{unit vector} is a vector $|v\\ra$ such that $\\parallel |v\\ra \\  \\parallel \\ = 1 $. We also say that $|v\\ra$ is \\emph{normalized}, and we can normalize any vector except the zero vector by dividing it by its norm.\n\nA base $|v_1\\ra, \\dotsc, |v_n\\ra$ is said to be \\emph{orthonormal} if every vector is a unit vector and they are pairwise orthogonal. That is, $\\la v_i|v_j\\ra = \\delta_{ij}$ where\n\n\\[\n\\delta_{ij} = \n\\begin{cases}\n\t1 & \\text{if } i = j  \\\\\n\t0 & \\text{if } i \\neq j\n\\end{cases}\n\\]\n\n\\begin{definition}\n\tAn \\emph{inner product space} is a vector space with an associated inner product. A \\textbf{Hilbert Space} is an inner product space that is also complete.\n\\end{definition}\n\nHausdorff's Theorem states that every finite normed space is complete, therefore every finite inner product space over $\\C$ is a Hilbert space \\cite{Paya2020}. Again, by Hausdorff's theorem, we know that every $n$ dimensional Hilbert space is isomorphic to $\\C^n$. Thus, $\\C^n$ is the canonical $n$ dimensional Hilbert space. Our study will be focused on these spaces.\n\nLet $\\alpha = a + i \\cdot b\\in \\C$. We define the \\emph{conjugate}, $\\bar \\alpha$, as $\\bar \\alpha = a - i \\cdot b$. The canonical inner product in $\\C^n$ is:\n\n$$ \\la u|v \\ra \\ = \\sum_{i=1}^n \\overline{u_i}v_j $$\n\nwhere $u = (u_1, \\dotsc, u_n)$ and $v = (v_1, \\dotsc, v_n)$, for every $u,v$ in $\\C^n$.\n\n\n\\subsection{Postulate 1 statement}\n\n\nThe reader should be familiar by now with the notation and the necessary linear algebra to formulate the first postulate.\n\n\\begin{postulate}\n\tAssociated to any isolated physical system is a complex vector space with an inner product (that is, a Hilbert space) known as the \\emph{state space} of the system. The system is completely described by its \\emph{state vector}, which is a unit vector in the system’s state space.\n\\end{postulate}\n\nAn important concern with this postulate is that it does not tell us which is the state space of a given system, nor its state vector. Although up to this point we cannot formally assure this, in quantum computing the state space will be fixed: $\\C^{2^n}$ for an n-qubits system. Our evolving state vector will be a vector $2^n$-vector.\n\nLet us start by modulating a simpler system: a single qubit system.\n\n\\begin{definition}\n\tA state vector of the state space $\\C^{2}$ is called a \\textbf{qubit}. Thus, $\\C^{2}$ may be called a single qubit state space.\n\\end{definition}\n\nSuppose $|0\\ra$, $|1\\ra$ form an orthonormal basis of a 2-dimensional Hilbert space. Then, any state vector in this state space may be described as:\n\n$$ |\\varphi\\ra = \\alpha|0\\ra + \\beta|1\\ra $$\n\nwhere $\\alpha,\\beta$ are complex numbers called \\emph{amplitudes}. Thus, the condition that $|\\varphi\\ra$ is a unit vector, $\\la\\varphi|\\varphi\\ra = 1$ is equivalent to $|\\alpha|^2 + |\\beta|^2 = 1$. This is known as the \\emph{normalization condition}.\n\nWe will always think of $|0\\ra$, $|1\\ra$ as a previously fixed orthonormal base. A linear combination of state vectors $\\sum_i a_i |\\varphi_i\\ra$ is called a \\emph{superposition} of the states $|\\varphi_i\\ra$ with amplitudes $a_i$ respectively. For example, the state\n\n$$ \\frac{|0\\ra - |1\\ra}{\\sqrt 2} $$\n\nis a superposition of the states $|0\\ra$ and $|1\\ra$ with amplitudes $1/\\sqrt 2$ and $-1/\\sqrt 2$ respectively.\n\n\n\\subsection{Quantum Computation Perspective: The Quantum Bit}\n\n\nThe bit is the minimum measure of information on classical computation and classical information theory. Everything in these fields is built from scratch based on bits. Likewise, quantum computing and quantum information theory are built upon the \\textbf{qubit}.\n\nWe have reached the qubit definition from quantum physics and pure mathematics, describing the qubit as a mathematical object independent of its physical implementation. By describing them as mathematical entities we will be able to explore their properties mathematically without having to worry about the physics underneath.  This allows us to construct the quantum computing and quantum information theories independently of the physical implementation.\n\nSo, intuitively, what is a qubit? Just like the classical bit, a qubit has a state. For the bit, the two only possible states are either $0$ or $1$. A qubit can take the states $|0\\ra$ and $|1\\ra$ -corresponding to the classical states $0$ and $1$- or it can be in a \\emph{linear combination} of them:\n\n$$ |\\varphi\\ra = \\alpha |0\\ra + \\beta |1\\ra $$\n\nWhere $\\alpha$ and $\\beta$ are complex numbers. Thus, we can describe a qubit as a vector in a two-dimensional complex Hilbert space (the canonical $\\C^{2}$), where $|0\\ra$ and $|1\\ra$ form an orthonormal basis called the \\emph{computational basis}. $|0\\ra$ and $|1\\ra$ will be called \\emph{computational basis states}.\n\nAt this point, the reader may ask themselves if a qubit may even physically exist, not just as a mathematical entity. After all, the first postulate states that given a \\emph{physical system}, there is an associated state space and vector states that describe the system. However, we define a qubit from state space ($\\C^{2}$) without considering a physical system. \n\nThe answer is positive: there are numerous physical systems such that their associated state spaces are ($\\C^{2}$). Thus, modeling a qubit. More intuitive examples are provided in section \\ref{qubit-examples} and a precise physical implementation is explained in section \\ref{sec:quantum-annealing-dwave}.\n\n\n\\section{Postulate 2: Measurement}\n\n\nThe second postulate describes how states are 'measured', that is, how an outside observer may look inside the system. In classical physics, consider a simple system of a moving particle. 'Measuring' would be recording, for instance, the particle mass and speed at a given time. That is, someone \\textbf{outside} the system would look \\textbf{into} the system to record some information. Lastly, in the classical computation model measuring a bit is simply retrieving its content.\n\nIn quantum physics, measuring has some unexpected and sometimes counter-intuitive properties. Let us provide some linear algebra context before formulating the second postulate.\n\n\n\\subsection{Outer product}\n\n\n\\begin{definition}\n\tLet $V, W$ be two vector spaces and $|v\\ra \\in V, |w\\ra \\in W$. We define the \\emph{outer product} between $|v\\ra$ and $|w\\ra$, $|w\\ra\\la v|$, as the only linear operator such that for any $|v'\\ra \\in V$, \n\t\n\t$$ (|w\\ra\\la v|) \\ |v'\\ra = |w\\ra\\la v|v'\\ra = \\la v|v'\\ra |w\\ra$$\n\\end{definition}\n\nThese identities provide a dual interpretation: the already known product of a complex value $\\la v|v'\\ra$ with a vector $|w\\ra$, and the application of the new operator, the outer product $|w\\ra\\la v|$ to the vector $|v'\\ra$. The outer product is defined so that this duality occurs.\n\nLet us consider linear combinations of outer products. By definition, $\\sum_i a_i |w_i\\ra\\la v_i|$ is the operator that transforms $|v'\\ra$ into $\\sum_i a_i |w_i\\ra\\la v_i|v'\\ra = \\sum_i a_i \\la v_i|v'\\ra |w_i\\ra$.\n\nThe most important result concerning outer products is the \\emph{completeness relation}:\n\n\\begin{proposition}[Completeness relation]\n\tLet $|i\\ra$ be any orthonormal basis of a finite vector space $V$. Then:\n\t\n\t$$ \\sum_i |i\\ra\\la i| = I $$\n\\end{proposition}\n\n\\begin{proof}\n\tLet $|v\\ra \\in H$. $|v\\ra$ can be expressed as $ \\sum_i v_i |i\\ra$ for some complex numbers $v_i$. Notice that $\\la i|v\\ra = v_i$. Therefor:\n\t\n\t$$|v\\ra = \\sum_i v_i |i\\ra = \\sum_i \\la i|v\\ra |i\\ra = \\sum_i |i\\ra\\la i|v\\ra = \\bigg( \\sum_i |i\\ra\\la i|\\bigg) |v\\ra$$\n\t\n\tSince $|v\\ra$ was arbitrary, this proves that $ \\sum_i |i\\ra\\la i | = I $.\n\\end{proof}\n\n\\begin{corollary}[Cauchy-Schwarz inequality]\n\tFor any two vectors $|v\\ra, |w\\ra$ in a Hilbert space,\n\t\n\t$$|\\la v|w\\ra|^2 \\leq \\la v|v\\ra\\la w|w\\ra$$\n\t\n\twhere the equality occurs if and only if $|v\\ra$ and $|w\\ra$ are linearly dependant\n\\end{corollary}\n\\begin{proof} \n\tWe provide a proof supposed that our Hilbert space is finite.\n\t\n\tLet $|v\\ra, |w\\ra$ be two vectors of a finite Hilbert space $H$. Since $H$ is finite, using the Gram-Schmidt procedure we may obtain a basis $|i\\ra$ where the first vector is $|w\\ra / \\sqrt{\\la w|w\\ra}$. Using the completeness relation $\\sum_i |i\\ra \\la i| = I$:\n\t\n\t$$\\la v|v\\ra \\la w|w\\ra = \\la v|I|v\\ra \\la w|w\\ra = \\la v| \\sum_i (|i\\ra \\la i|) |v\\ra \\la w|w\\ra = \\sum_i \\la v|i\\ra \\la i|v\\ra \\la w|w\\ra $$\n\t\n\tThe sum of a list of positive numbers is obviously greater than its first element, so:\n\t\n\t$$ \\sum_i \\la v|i\\ra \\la i|v\\ra \\la w|w\\ra \\geq  \\frac{\\la v|w\\ra \\la w|v\\ra}{\\la w|w\\ra} \\la w|w\\ra = \\la v|w\\ra \\la w|v\\ra  = | \\la w|v\\ra |^2 $$\n\t\n\tLastly, the equality occurs if and only if $\\la v|i\\ra = 0$ for every $|i\\ra \\neq |w\\ra / \\sqrt{\\la w|w\\ra}$. But since $|i\\ra$ is a base, this means $|v\\ra$ and $|w\\ra$ are linearly dependent.\t\n\\end{proof}\n\n\n\\subsection{Unitary and Hermitian operators}\n\n\nAnother way of looking at the inner product is the \\emph{adjoint}.\n\n\\begin{definition}\n\tLet $A$ be an operator between $\\C^n$ and $\\C^m$, finite dimensional Hilbert spaces. That is, $A \\in \\mathcal{M}_{n{\\times}m}(\\C)$. Then, its \\emph{adjoint} or \\emph{conjugate transpose} $A^\\dagger$ is defined by:\n\t\n\t$$ (A^\\dagger)_{ij} = \\bar A_{ji} $$\n\\end{definition}\n\nIf $|v\\ra$ is a vector, we can compute its adjoint by seeing it as a matrix. By convention, we will denote $|v\\ra^\\dagger = \\la v|$. Adjoints of vector are usually called \\emph{bras}, making given sense to the \\emph{bra-ket} notation since $\\la v| \\cdot |v\\ra = \\la v|v\\ra$, where $\\cdot$ denotes the dot product.\n\nSome useful algebraic identities associated to adjoints are:\n\n\\begin{itemize}\n\t\\item Given an operator $A \\in \\mathcal{M}_{n}(\\C)$, $A^\\dagger$ is the only operator such that for any two vectors $|u\\ra, |v\\ra \\in \\C^n$: $( |u\\ra, A|v\\ra) = ( A^\\dagger |u\\ra, |v\\ra)$\n\t\\item For any two operators $A,B$, $(AB)^\\dagger = B^\\dagger A^\\dagger$.\n\t\\item As a corollary, for any vector $|v\\ra$ and for any operator $A$, $(A|v\\ra)^\\dagger = \\la v|A^\\dagger$.\n\\end{itemize}\n\n\\begin{definition}\n\tAn operator $A$ is said to be \\emph{normal} if $AA^\\dagger = A^\\dagger A$.\n\\end{definition}\n\nCharacterization of normal operators is provided in Theorem \\ref{spectral-decomposition-theorem}. There are two particular cases of normal operators that will be of special interest to us:\n\n\\begin{definition}\n\tAn operator $A$ is said to be \\emph{Hermitian} if its adjoint is itself: $A^\\dagger = A$.\n\\end{definition}\n\n\\begin{definition}\n\tA matrix $U$ is said to be \\emph{unitary} if $UU^\\dagger = I$. Similarly, an operator is said to be \\emph{unitary} if $UU^\\dagger = I$. A unitary operator $U$ also fulfills that $U^\\dagger U = I$.\n\\end{definition}\n\nClearly, Hermitian and unitary operators are also normal. The importance of unitary matrices and operators in quantum computing lies in the following\n\n\\begin{proposition}\n\tUnitary operators preserve inner product between vectors. Thus, they also preserve the norm of a vector.\n\\end{proposition}\n\n\\begin{proof}\n\tLet $|u\\ra, |v\\ra \\in \\C^n$ and $U \\in \\mathcal{M}_n(\\C)$ be a unitary operator. Then:\n\t\n\t$$ ( U|u\\ra, U|v\\ra) = \\la u|U^\\dagger U|v\\ra = \\la u|I|v\\ra = \\la u|v\\ra = ( |u\\ra, |v\\ra) $$\n\t\n\tWhich proves the proposition.\n\\end{proof}\n\nAn important type of Hermitian operators is the projectors.\n\n\\begin{definition}\n\tLet $W$ be a $k$-dimensional subspace\t of the $d$-dimensional vector space $V$. Let $|1\\ra, \\dots, |d\\ra$ be an orthonormal base of $V$ where $|1\\ra, \\dots, |k\\ra$ is an orthonormal base of $W$. The \\emph{projector} onto the subspace $W$ is defined by:\n\t\n\t$$ P = \\sum_{i=1}^k |i \\ra\\la i| $$\n\\end{definition}\n\nIt can easily be shown that this definition is independent from the chosen base $|1\\ra, \\dots, |k\\ra$. Since $|v \\ra\\la v|$ is Hermitian for any vector $|v\\ra$, $P$ is also Hermitian: $P = P^\\dagger$. We will often refer to the subspace onto which $P$ projects simply as $P$ for comodity. The \\emph{orthonormal completement} of $P$ is $Q \\equiv I - P$. It can be verified the vector subspace $Q$ is spanned by the base $|k+1\\ra, \\dots, |d\\ra$.\n\nAs the reader may already imagine, n-qubits systems will be represented as vector states or \\emph{certain} state spaces. That is, as unitary vectors of certain Hilbert spaces. Thus, our definition of transformations on qubits must preserve their norm. These will be the qubits gates, which will be represented as unitary operators.\n\nOn the other hand, Hermitian operators will be key in order to study how a quantum system evolves with time using the Schrodinger equation in the third Postulate.\n\nFinally, projectors will be used on as particular way of measurement and will be further discussed in section \\ref{projective-measurement}, once systems with multiple qubits have been introduced.\n\n\n\\subsection{Postulate 2 statement}\n\n\nAs previously discussed, the second postulate describes how a quantum system may be measured.\n\n\\begin{postulate}\n\tQuantum measurement are described by a collection $\\{M_m\\}$ of \\emph{measurement operators}. These act on the state space associated to the physical system being measured. The index $m$ refers to the measurement outcomes that may occur. That is, if $|\\varphi\\ra$ is the vector state before measure, then the probability of the result $m$ occurring is:\n\t\n\t$$p(m) = \\la\\varphi|M_m^\\dagger M_m|\\varphi\\ra $$\n\t\n\tand the state of the system after the measurement is:\n\t\n\t$$ \\frac{M_m|\\varphi\\ra}{\\sqrt{p(m)}}$$\n\t\n\tFinally, the measurement operator satisfy the \\emph{completeness equation}: \n\t\n\t$$\\sum_m M_m^\\dagger M_m = I$$\n\\end{postulate}\n\nThe completeness equation is equivalent to the fact that the probabilities of the different possible outcomes add up to one:\n\n$$ \\sum_m p(m) = \\sum_m \\la\\varphi|M_m^\\dagger M_m|\\varphi\\ra = \\la\\varphi|\\sum_m (M_m^\\dagger M_m)|\\varphi\\ra = \\la\\varphi|\\varphi\\ra = 1 $$\n\nwhich holds for every state vector since they are unitary. Reciprocally, this equation occurring for every state vector $|\\varphi\\ra$ implies the completeness equation.\n\nThe reader may have already noticed a huge difference between classic and quantum measurement: The measured state \\textbf{changes} after the measurement. This means that we interfere with the system by merely looking into it! It will ultimately translate into huge differences between classical and quantum computing, such that we will generally not be able to clone a qubit (see theorem \\ref{no-cloning-theorem}).\n\nLet us look at an important example: \\emph{measurement of a qubit on the computational basis}. That is, measuring a qubit with two possible outcomes: $|0\\ra$ and $|1\\ra$. Although this is a particular case of projective measurement (further explained in section \\ref{projective-measurement}), it is worth introducing it now to deepen our understanding of qubits.\n\nTo obtain such results we use the operators $M_0 = |0\\ra \\la 0|$ and $M_1 = |1\\ra \\la 1|$. In order for $\\{M_0, M_1\\}$ to be a correct collection of measurement operators they must satisfy the completeness equation. Observe that each operator is Hemitian: $M_i^\\dagger = (|i\\ra \\la i|)^\\dagger = (\\la i|)^\\dagger (|i\\ra)^\\dagger = |i\\ra \\la i| = M_i$. Furthermore, $M_i^2 = |i\\ra \\la i|i\\ra \\la i| = |i\\ra \\la i| = M_i$.\n\nFinally, the computational basis is an orthonormal basis and therefore the completeness relation tells us that:\n\n$$ \\sum_i |i\\ra\\la i| = 1 $$\n\nWe can see that the completeness equation holds:\n\n$$ \\sum_i M_i^\\dagger M_i = \\sum_i M_i^2 = \\sum_i M_i = \\sum_i |i\\ra\\la i| = 1 $$\n\nLet's measure using this operators, also called \\emph{measure in the computational basis}, to better understand the measurement. Suppose the state being measured is $|\\varphi\\ra = \\alpha|0\\ra + \\beta|1\\ra$. Then, the probability of obtaining the outcome 0 is:\n\n$$ p(0) = \\la\\varphi|M_0^\\dagger M_0|\\varphi\\ra = \\la\\varphi|M_0|\\varphi\\ra = |a|^2 $$\n\nSimilarly, the probability of obtaining the outcome 1 is $p(1) = |b|^2$. Naturally, $ |a|^2 + |b|^2 = 1$. What happens after measuring? The post-measurement state will be, respectively if we measured 0 or 1:\n\n$$ \\frac{M_0|\\varphi\\ra}{|a|} = \\frac{a}{|a|}|0\\ra$$\n\n$$ \\frac{M_1|\\varphi\\ra}{|b|} = \\frac{b}{|b|}|1\\ra$$\n\nFactors like $a/|a|$ are known as \\emph{phases}. An importan result of quantum mechanics assures that multiplying by factors like these does not affect the state vector \\cite{Nielsen2002}, so we virtually obtained $|0\\ra$ and $|1\\ra$. We may appreciate now how dividing by $\\sqrt{p(m)}$ in the post-measurement state is only done so the resulting vector is a unit vector.\n\nSo if we measured a 0, the post-measurement vector will be $|0\\ra$ and vice-versa. Any measurements performed after the first one will yield exactly the same result. This behavior is called \\emph{qubit collapsing}.\n\nWe defined measurement to be independent of any basis so we may measure in the most convenient basis at each point. For example, we may use the following other basis:\n\n$$ |+\\ra = \\frac{1}{\\sqrt{2}}|0\\ra + \\frac{1}{\\sqrt{2}}|1\\ra = \\frac{|0\\ra + |1\\ra}{\\sqrt{2}} $$\n\n$$ |-\\ra = \\frac{1}{\\sqrt{2}}|0\\ra - \\frac{1}{\\sqrt{2}}|1\\ra = \\frac{|0\\ra - |1\\ra}{\\sqrt{2}} $$\n\nIt can easily be proven that $\\{|+\\ra, |-\\ra\\}$ is a basis and therefore it satisfies the completeness equation. In fact, the operators $M_+ = |+\\ra\\la +|$ and $M_- = |-\\ra\\la -|$ satisfy the completeness equation. Using this operators, measuring the qubit $|\\varphi\\ra = \\alpha|0\\ra + \\beta|1\\ra$ will output $+$ with probability:\n\n$$ p(+) = \\la\\varphi|M_+^\\dagger M_+|\\varphi\\ra = \\la\\varphi|M_+|\\varphi\\ra = \\la\\varphi|+\\ra\\la+|\\varphi\\ra = \\la\\varphi|+\\ra^2 = $$\n\n$$ = \\bigg ( \\frac{\\alpha}{\\sqrt{2}}\\la0|0\\ra + \\frac{\\alpha}{\\sqrt{2}}\\la1|0\\ra + \\frac{\\beta}{\\sqrt{2}}\\la0|1\\ra + \\frac{\\beta}{\\sqrt{2}}\\la1|1\\ra \\bigg )^2 = \\frac{(\\alpha + \\beta)^2}{2} $$\n\n$$ p(-) = \\frac{(\\alpha - \\beta)^2}{2} $$\n\nAnd, naturally, $p(+) + p(-) = 1$. So $|\\varphi\\ra$ will collapse to $|+\\ra$ with probability $(\\alpha + \\beta)^2/2$ when measured with this operators. Observe that the post-measurement state will never be $|0\\ra$ nor $|1\\ra$ in this case, we made the qubit collapse to the chosen state basis.\n\nFinally, there is a technical fineness between the first and second postulates worth mentioning. The first postulate was stated for an \\emph{isolated} physical system, but by measuring the system we interfere with it. However, measuring devices are also quantum systems, so together the measured and the measuring system form a larger isolated system (it may be necessary to include more quantum systems, but this can be done).\n\n\n\\subsection{Real life qubit examples}\n\\label{qubit-examples}\n\n\nIn classical computation, we may know the state of a bit by consulting it. That is, what can simply retrieve that information from the bit. The first difficulty we find in quantum computing is that once we \\emph{measure} a qubit it \\emph{collapses} to either $|0\\ra$ with probability $|\\alpha|^2$, or to $|1\\ra$ with probability $|\\beta|^2$. The obtained output reflects the qubit state \\emph{after} it has collapsed to either one of these states, so the outcome may only be either $|0\\ra$ or $|1\\ra$. This means that we may never retrieve directly the values $\\alpha$ and $\\beta$. Thus, being unable to clone a qubit. This is the main idea behind the no-cloning theorem \\ref{no-cloning-theorem}.\n\nWe can, however, initialize qubits in a certain state and apply some operations to them in order to alter their coefficients, thus knowing their exact value. However, once a single measurement is done, the qubit collapses and the $\\alpha$ and $\\beta$ values are 'lost'.\n\nSuperposition and collapsing might be counter-intuitive concepts, so let us look at them with an analogy. We can think of a perfect coin being tossed as the following qubit:\n\n$$ |+\\ra = \\frac{1}{\\sqrt{2}} |0\\ra + \\frac{1}{\\sqrt{2}} |1\\ra $$\n\nThis does \\textbf{not} represent a coin that has landed somehow on its side, but a spinning coin that has not landed yet. Upon measuring it, we 'make the coin land' and see the result: either heads or tails, and neither of the states in between. This example also describes the qubit collapse: once the coin has landed, we will see the same result every time we look at it -obviously-, just like every time a qubit is measured after the first measurement, the outcome will be the same since it has already collapsed. We will return to this state, also known as the Bell state, in section \\ref{postulate-4-section}.\n\nOn the other hand, this was quite an inaccurate example since the system is not really isolated, although it was interesting intuition-wise. One of the first (accurate) qubit models ever proposed was the Schrodinger's Cat \\cite{Schrodinger1935} \\cite{Trimmer1980}. In this hypothetical experiment, a cat would be locked in a room for an hour with a device that during that hour would \\emph{perhaps} trigger, killing the cat. On the other hand, with equal probability, it would not trigger at all. After the whole hour elapses, the cat would be alive and dead with equal probability, ending up in a halfway state. In this case, our computational bases would be the states alive and dead, and we achieve the state $|+\\ra$ after that hour. Once we open the room and check on the cat, our qubit collapses to either state and stays on it until further disturbance.\n\nAlthough a physical implementation is discussed in section \\ref{sec:quantum-annealing-dwave}, we cannot proceed any further without providing a more accurate and reproducible description of a qubit than 'a coin being tossed' and such a hypothetical cat experiment. A possible realization of a qubit is an electron in a single atom's orbit, as seen in Figure \\ref{fig 1.1}. An electron in an orbit may be in the so-called \\emph{ground} and \\emph{excited} states, $|0\\ra$ and $|1\\ra$ respectively, depending on its energy. By shining light to the electron with a certain energy and for a certain amount of time, one can make the electron move from the ground state to the excited state and vice versa. But most interestingly, one can apply the light to the electron during a smaller amount of time, moving the electron somehow 'halfway' between both states.\n\n\\begin{figure}[h]\n\t\\includegraphics[scale=.4]{atom.png}\n\t\\centering\n\t\\caption{Qubit represented by two electron orbits in an atom, \\cite{Nielsen2002}.}\n\t\\label{fig 1.1}\n\\end{figure}\n\n\n\\section{Postulate 3: Evolution}\n\\label{sec:postulate-3}\n\nThe third postulate of quantum mechanics modulates the evolution of a quantum system. That is, the evolution of the state vector that describes the system. In order to properly formalize it, the concepts of eigenvectors, eigenvalues, and Hermitian operators are required.\n\n\n\\subsection{Eigenvalues and eigenvectors}\n\n\n\\begin{definition}\n\tLet $V$ be a vector space and $A$ an operator on $V$. An \\emph{eigenvector} is a non zero vector $|v_\\lambda\\ra$ such that $A|v_\\lambda\\ra = \\lambda|v_\\lambda\\ra$ for a complex value $\\lambda$ called the associated \\emph{eigenvalue}.\n\\end{definition}\n\nEigenvalues and their associated eigenvectors will usually be denoted with the same letter for simplicity: $\\lambda$ and $|\\lambda\\ra$. We assume the reader is familiar with eigenvectors and values basic notions. For instance, that they may be calculated using the \\emph{characteristic equation}: $|I - \\lambda A| = 0$.\n\n\\begin{definition}\n\tA \\emph{diagonal representation} of an operator $A$ is a representation $\\sum_i \\lambda_i |\\lambda_i\\ra\\la\\lambda_i|$ where the $|\\lambda_i\\ra$ form an orthonormal set of A's eigenvectors and $\\lambda_i$ are the respective eigenvalues. An operator is said to be \\emph{diagonalizable} if it allows a diagonal representation. The \\emph{spectrum} of an operator is the set of its eigenvalues.\n\\end{definition}\n\n\\begin{exampleth}\n\tAs an example of this, let us consider the following matrix:\n\t\n\t$$ Z = \n\t\\begin{pmatrix}\n\t\t1 & 0 \\\\\n\t\t0 & -1 \n\t\\end{pmatrix}\n\t$$\n\t\n\tThis matrix is called the \\emph{Z Pauli} matrix. It is relevant for quantum computing and it will be introduced later on along with the rest of the Pauli matrices. For now, Let's compute its diagonalizable representation. Since it is already diagonal we can infer that its eigenvalues are $\\{1, -1\\}$. Computing the diagonal representation we realize that a pair orthonormal eigenvectors are $\\{|0\\ra, |1\\ra\\}$ respectively. Therefore:\n\t\n\t$$ Z = \n\t\\begin{pmatrix}\n\t\t1 & 0 \\\\\n\t\t0 & -1 \n\t\\end{pmatrix} = \n\t|0\\ra\\la0| - |1\\ra\\la1|\n\t$$\n\\end{exampleth}\n\nNormal operators have significant relevancy thanks to the following result:\n\n\\begin{theorem}[Spectral Decomposition Theorem]\n\\label{spectral-decomposition-theorem}\n\tAn operator $A$ is normal if and only if it is diagonalizable.\n\\end{theorem}\n\\begin{proof}\n\tSee Box 2.2 in page 72, \\cite{Nielsen2002}.\n\\end{proof}\n\nSince Hermitian and unitary operators are normal, it follows the next\n\n\\begin{corollary}\n\tAny Hermitian operator is diagonalizable. Any unitary operator is diagonalizable.\n\\end{corollary}\n\n\n\\subsection{Postulate 3 statement}\n\\label{postulate-3-section}\n\n\\begin{postulate}\n\tThe evolution of a \\emph{closed} quantum system is described by a \\emph{unitary transformation}. That is, the state $|\\varphi\\ra$ of the system at time $t_1$ is related to the state $|\\varphi'\\ra$ of the system at time $t_2$ by a unitary operator $U$ which depends only on the times $t_1$ and $t_2$,\n\t\n\t$$ |\\varphi'\\ra = U|\\varphi\\ra $$\n\\end{postulate}\n\nJust like the first postulate does not provide the state space or state vector of the system, the third postulate does not provide the unitary transformation that concretes this evolution. For our quantum computing case, we will be the ones to define the unitary transformation to the system. That is, the quantum circuit that transforms our qubit.\n\n\\begin{exampleth} Let's consider the \\emph{X Pauli matrix}, also known as the \\emph{bit flip} matrix:\n\t\n\t$$ \\sigma_1 = X = \n\t\\begin{pmatrix}\n\t\t0 & 1 \\\\\n\t\t1 & 0 \n\t\\end{pmatrix}\n\t$$\n\t\n\tIt is called the bit flip matrix because it takes $|0\\ra$ to $|1\\ra$ and vice-versa:\n\t\n\t$$  X|0\\ra = \n\t\\begin{pmatrix}\n\t\t0 & 1 \\\\\n\t\t1 & 0 \n\t\\end{pmatrix}\n\t\\begin{pmatrix}\n\t\t1 \\\\\n\t\t0 \n\t\\end{pmatrix}=\n\t\\begin{pmatrix}\n\t\t0 \\\\\n\t\t1 \n\t\\end{pmatrix} =\n\t|1\\ra\n\t$$\n\t\n\tThis product that we just computed is precisely what postulate 3 states: the evolution of our state vector following the unitary operator $X$: $X|0\\ra = |1\\ra$. Even though for an arbitrary system we do not know the specific unitary transformation the system follows, we can create systems that follow certain desired transformations. These are the basics of quantum gates and quantum circuits. \n\\end{exampleth}\n\nThe description of the system evolution provided by Postulate 3 only bears information for those fixed times $t_1$ and $t_2$. A continuous time-description of this evolution is provided by the Schrodinger equation, which provides a redefinition of the second postulate.\n\n\\begin{postulate 3'}\n\\label{postulate-3'}\n\tThe time evolution of the state of a \\emph{closed} quantum system is described by the Schrodinger equation:\n\t\n\t$$ i \\hbar \\frac{d|\\varphi\\ra}{dt} = H|\\varphi\\ra $$\n\t\n\twhere $\\hbar$ is \\emph{Planck’s constant}, $i$ is the imaginary unit and $H$ is a fixed Hermitian operator known as the $Hamiltonian$.\n\\end{postulate 3'}\n\nThere are several notes to make about this postulate. First, the Hamiltonian is fixed for the given system and it is not be confused with the \\emph{Hadamard quantum gate}, also represented by an $H$. Second, $\\hbar$ is a physical constant that can be absorbed into the Hamiltonian for our purposes, simplifying the equation. Finally, this is a differential equation, so by knowing the initial state space of the system and the exact Hamiltonian we may know the exact evolution of the system.\n\nLet us study the Hamiltonian in general. Since it is a Hermitian operator, it allows a spectral decomposition by theorem \\ref{spectral-decomposition-theorem}:\n\n$$ H = \\sum_E E |E\\ra\\la E| $$\n\nwhere $E$ are the eigenvalues and $|E\\ra$ the respective normalized eigenvectors. the states $|E\\ra$ are usually referred to as \\emph{energy eigenstates} or \\emph{stationary states}, and $E$ is the \\emph{energy} of the state $|E\\ra$. Furthermore, the lowest energy is called the \\emph{ground energy state} while the corresponding eigenstate is called the \\emph{ground state}.\n\n\\begin{exampleth} Suppose a single qubit system has a the following Hamiltonian:\n\t\n\t$$ H = \\hbar \\omega X = \\hbar \\omega\n\t\\begin{pmatrix}\n\t\t0 & 1 \\\\\n\t\t1 & 0 \n\t\\end{pmatrix}\n\t$$\n\t\n\tWhere $X$ is the first Pauli matrix, and $\\omega$ is a positive parameter. H eigenenergy states are the same as $X$ eigenstates: $(|0\\ra + |1\\ra)/2$ and $(|0\\ra - |1\\ra)/2$ with respective energies $\\hbar\\omega$ and $-\\hbar\\omega$. Thus, the ground state is $(|0\\ra - |1\\ra)/2$ with ground state energy $-\\hbar\\omega$.\n\\end{exampleth}\n\nLet us deduce the connection between the Hamiltonian perpestive of dinamics, Postulate 3', and the unitary operator perspective, postulate 3. We can solve the Schrodinguer equation, which can be proven to be:\n\n$$ |\\varphi(t_2)\\ra = \\text{exp} \\bigg(  \\frac{-iH(t_2-t_1)}{\\hbar} \\bigg) |\\varphi(t_1)\\ra $$\n\nWe define:\n\n$$ U(t_1, t_2) \\equiv \\text{exp} \\bigg(  \\frac{-iH(t_2-t_1)}{\\hbar} \\bigg) $$\n\nWhich is a unitary operator. In fact, any unitary operator $U$ may be expressed as $U = \\text{exp(iK)}$ for some Hermitian operator $K$. Thus, we obtained: \n\n$$ |\\varphi(t_2)\\ra = U(t_1, t_2) |\\varphi(t_1)\\ra $$\n\nFollowing this procedure, we have proven that there is a one to one correspondence between the continuous time-varying postulate 3' using the Hamiltonian and the more stationary discrete-time version using the unitary operator. Although the discrete-time vision is usually used in quantum computing, Quantum Annealing -the specific application of quantum mechanics used in this thesis- rests mostly on the Hamiltonian point of view. We will deepen in this architecture on section \\ref{sec:quantum-annealing-dwave}.\n\nIt is worth mentioning that both versions of this postulate assume our physical system to be \\emph{closed}. That is, there is no interaction with the system coming from the exterior. In reality, the only real closed system is the universe as a whole. However, we may recreate sufficiently closed systems so that they can be described with approximations as being closed. \n\nFurthermore, this severely interferes with postulate 2, where an outsider to the system may interfere with it by measuring it. The quantum system will evolve following postulate 3 until measurement is applied. Then they will evolve following the behavior described on postulate 2.\n\nIn practice, obtaining the Hamiltonian for a given quantum system is a really laborious work and usually needs experimental data \\cite{Nielsen2002}. However, for our computational purposes, we will be the ones designing the Hamiltonian such that our system evolves as desired. In particular, chapter \\ref{sec:qubo} describes in detail the construction of Hamiltonians for QUBO problems.\n\n\\subsection{Quantum Computing perspective: Quantum Gates}\n\nAlthough quantum annealing does not make use of quantum gates, they are the basis of quantum computing and they fully rely on postulate 3. Because of their importance, a brief overview of quantum gates is provided o¡in this section. However, a profound understanding of them will not be necessary to understand the rest of the thesis.\n\nQuantum computing is built upon the most simple operation we can compute on single qubits: quantum gates. Since state vectors are unit two-dimensional vectors, the operations we apply to them must preserve the norm. Thus, quantum gates will be represented by 2x2 unitary matrices. We have already introduce some of the most famous gates, the Pauli matrices:\n\n$$ X =\n\\begin{pmatrix}\n\t0 & 1 \\\\\n\t1 & 0 \n\\end{pmatrix}; \\quad\nY =\n\\begin{pmatrix}\n\t0 & -i \\\\\n\ti & 0 \n\\end{pmatrix}; \\quad\nZ =\n\\begin{pmatrix}\n\t1 & 0 \\\\\n\t0 & -1 \n\\end{pmatrix}\n$$\n\nSome of the others most important gates are the Hadamard gate (denoted as H), the phase gate (denoted as S), and the $\\pi/8$ gate (denoted as T):\n\n$$ H = \\frac{1}{\\sqrt 2}\n\\begin{pmatrix}\n\t1 & 1 \\\\\n\t1 & -1 \n\\end{pmatrix}; \\quad\nS =\n\\begin{pmatrix}\n\t1 & 0 \\\\\n\t0 & i \n\\end{pmatrix}; \\quad\nT =\n\\begin{pmatrix}\n\t1 & 0 \\\\\n\t0 & e^{i\\pi/4} \n\\end{pmatrix}\n$$\n\nAlthough we have not described the fundamentals of multiple qubits systems (postulate 4 is required for this), it is worth mentioning a simple two-qubits gate for the purpose of this section. Just like in classical computing, conditional operations are essential for the construction of complex quantum algorithms. The most basic conditional operation is the \\emph{controlled-NOT} gate, also referred to as the CNOT gate. This gate takes two bits $|c\\ra|t\\ra$, a control qubit, and a target qubit. It flips the target qubit if the first qubit is set to $|1\\ra$, producing the operation $|c\\ra|t\\ra \\rightarrow |c\\ra|c \\oplus t\\ra$, where $\\oplus$ denotes the exclusive-or operation. Therefore, if the control qubit is $|c\\ra = \\alpha|0\\ra + \\beta|1\\ra$, it will virtually flip the target qubit with probability $|\\beta|^2$ and leave it how it is with probability $|\\alpha|^2$.\n\nOne of the most important results of classical computation theory is that any boolean function may be constructed by only using AND, OR, and NOT gates, or by simply using NAND gates \\cite{Lau2006}. There is an equivalent result concerning quantum gates \\cite{Bayens2019}.\n\n\\begin{theorem}\n\tAny unitary matrix can be approximated by a combination of the Hadamard, CNOT, and $\\pi/8$ gates.\n\\end{theorem}\n\nIn this case, \\{H, CNOT, T\\} is called a \\emph{universal gate set}. In practice, is it efficient to build such any gate using only this gate set? The answer to the question is positive, as stated by the \\textbf{Solovay-Kitaev theorem} \\cite{Dawson2006}. However, this is out of the scope of this project. We provide a sketch proof of the previous theorem from \\cite{Bayens2019}.\n\n\\begin{proof}\n\tSee \\cite{Bayens2019}, Theorem 4.2\n\\end{proof}\n\nFurther study of quantum circuits falls out of the scope of this thesis since we will use the D-Wave architecture, which relies on quantum annealing instead of quantum circuits.\n\n\n\\section{Postulate 4: Composite systems}\n\n\nIn this section, we introduce the last postulate, which lets us understand the state space associated with a physical system composed of other minor systems. This will allow us to study multiple-qubits systems and state some of the most important results in quantum mechanics and quantum computing: The \\emph{Heisenberg uncertainty principle} and the no-cloning theorem.\n\n\n\\subsection{Tensor product}\n\n\nLet $V$ and $W$ be complex vector spaces with dimensions $m$ and $n$ respectively. Then, $V \\otimes W$, read '$V$ tensor $W$', is a $mn$ complex vector space. Let $|v\\ra$ and $|w\\ra$ be vectors in $V$ and $W$ respectively. Then, $|v\\ra \\otimes |w\\ra$ is in $V \\otimes W$. Furthermore, any element of $V \\otimes W$ may be expressed as a linear combinations of tensor products $|v\\ra \\otimes |w\\ra$ of elements from $V$ and $W$. We may describe elements of $V \\otimes W$ using the following equivalent notations: $|v\\ra \\otimes |w\\ra$, $|v\\ra|w\\ra$, $|v, w\\ra$ and even $|vw\\ra$.\n\nLet $|i\\ra$ and $|j\\ra$ be basis for $V$ and $W$ respectively. Then, $|i\\ra \\otimes |j\\ra = |ij\\ra$ is a basis for $V \\otimes W$. For example, consider the complex vector space $\\C^2$. Then\n\n$$ |0\\ra \\otimes |0\\ra + |1\\ra \\otimes |1\\ra = |00\\ra + |11\\ra $$\n\nis an element in $\\C^2 \\otimes \\C^2 \\cong \\C^4$ .\n\nAlthough the tensor product is generally described as an abstract construct, we may provide a more visual perspective using the \\emph{Kronecker product}. This is a matrix representation for the tensor product of finite vector spaces. Suppose $A = \\{a\\}_{ij}$ is a $n \\times m$ matrix and $B = \\{b\\}_{ij}$ is an $p \\times q$ matrix. Then $A \\otimes B$ is a $np \\times mq$, matrix with the following representation:\n\n$$ A \\otimes B = \n\\begin{pmatrix}\n\ta_{11}B & a_{12}B & \\dotsc & a_{1m}B \\\\\n\ta_{21}B & a_{22}B & \\dotsc & a_{2m}B \\\\\n\t\\vdots & \\vdots & \\vdots & \\vdots \\\\\n\ta_{n1}B & a_{n2}B & \\dotsc & a_{nm}B \\\\\n\\end{pmatrix}\n$$\n\nFor example:\n\n$$ \\begin{pmatrix}\n\t0 & 1 \\\\\n\t2 & 3\n\\end{pmatrix} \\otimes\n\\begin{pmatrix}\n\t10 & 20 \\\\\n\t30 & 40\n\\end{pmatrix} =\n\\begin{pmatrix}\n\t0 \\times \\begin{pmatrix} 10 & 20 \\\\ 30 & 40 \\end{pmatrix} &\n\t1 \\times \\begin{pmatrix} 10 & 20 \\\\ 30 & 40 \\end{pmatrix} \\\\\n\t2 \\times \\begin{pmatrix} 10 & 20 \\\\ 30 & 40 \\end{pmatrix} &\n\t3 \\times \\begin{pmatrix} 10 & 20 \\\\ 30 & 40 \\end{pmatrix}\n\\end{pmatrix} = \n$$\n$$ \n\\begin{pmatrix}\n\t0 \\times 10 & 0 \\times 20 & 1 \\times 10 & 1 \\times 20 \\\\\n\t0 \\times 30 & 0 \\times 40 & 1 \\times 30 & 1 \\times 40 \\\\\n\t2 \\times 10 & 2 \\times 20 & 3 \\times 10 & 3 \\times 20 \\\\\n\t2 \\times 30 & 2 \\times 40 & 3 \\times 30 & 3 \\times 40\n\\end{pmatrix} = \n\\begin{pmatrix}\n\t0 & 0 & 10 & 20 \\\\\n\t0 & 0 & 30 & 40 \\\\\n\t20 & 40 & 30 & 60 \\\\\n\t60 & 80 & 90 & 120\n\\end{pmatrix}\n$$\n\nBy definition, the tensor product satisfies:\n\n\\begin{itemize}\n\t\\item Let $\\alpha$ be a complex number. For any $|v\\ra$ in $V$ and $|w\\ra$ in $W$,\n\t$$ \\alpha(|v\\ra \\otimes |w\\ra) = (\\alpha|v\\ra) \\otimes |w\\ra = |v\\ra \\otimes (\\alpha|w\\ra) $$\n\t\n\t\\item For any $|v_1\\ra$, $|v_2\\ra$ in $V$ and $|w\\ra$ in $W$,\n\t$$ (|v_1\\ra + |v_2\\ra) \\otimes |w\\ra = |v_1\\ra \\otimes |w\\ra + |v_2\\ra \\otimes |w\\ra $$\n\t\n\t\\item For any $|v\\ra$ in $V$ and $|w_1\\ra$, $|w_2\\ra$ in $W$,\n\t$$ |v\\ra \\otimes (|w_1\\ra + |w_2\\ra) = |v\\ra \\otimes |w_1\\ra + |v\\ra \\otimes |w_2\\ra $$\n\\end{itemize}\n\nThe inner products of the spaces $V$ and $W$ may be use to extend and natural inner product the tensor space. Define:\n\n$$ \\bigg ( \\sum_i a_i |v_i\\ra \\otimes |w_i\\ra, \\sum_j b_j |v_j'\\ra \\otimes |w_j'\\ra \\bigg ) \\equiv\n\t\t\\sum_{ij} \\overline{a_i} b_j \\la v_i|v_j' \\ra \\la w_i|w_j' \\ra $$\n\nWith this product and the previous properties in mind, it can easily be proven that the tensor product of Hilbert spaces is a Hilbert space.\n\n\\begin{proposition}\n\tLet $H_1$ be and $H_2$ be two Hilbert spaces with respective orthonormal bases $B_1 = \\{|v_i\\ra\\}_{i=1,\\dots,n}$ and $B_2 = \\{|w_j\\ra\\}_{j=1,\\dots,m}$. Then, $H_1 \\otimes H_2$ is a Hilbert space with inner product given by\n\t\n\t$$ ( |v\\ra \\otimes |w\\ra, |v'\\ra \\otimes |w'\\ra) = \\la vw|v'w'\\ra = \\la v|v'\\ra\\la w|w'\\ra $$\n\t\n\tFor any $|v\\ra, |v'\\ra$ in $V$ and $|w\\ra, |w'\\ra$ in $W$. Furthermore, $B_1 \\otimes B_2 = \\{|v_i w_j\\ra\\}_{i,j}$ is an orthonormal basis of $H_1 \\otimes H_2$.\n\\end{proposition}\n\n\\begin{proof}\n\tBy definition, $H_1 \\otimes H_2$ is a complex vector space with $dim(H_1 \\otimes H_2) = dim(H_1) \\cdot dim(H_2)$. Furthermore, $B_1 \\otimes B_2 = \\{|v_i\\ra \\otimes |w_j\\ra\\}_{i,j} = \\{|v_i w_j\\ra\\}_{i,j}$ is a base of it. Let $|v_i w_j\\ra, |v_k w_l\\ra \\in B_1 \\otimes B_2$:\n\t\n\t$$ \\la v_i w_j|v_k w_l \\ra = \\la v_i|v_k \\ra \\la w_j|w_l \\ra = \\delta_{ik} \\delta_{jl} $$\n\t\n\twhich equals one if and only if $i = k$ and $j = l$, and zero otherwise. Thus, proving that $B_1 \\otimes B_2$ is orthonormal.\n\t\n\tFinally, for $H_1 \\otimes H_2$ to be a Hilbert space the product defined above needs to be, in fact, an inner product. It suffies to prove that it is definite positive. Let $|v\\ra \\in H_1 \\otimes H_2$. Since $B_1 \\otimes B_2$ is an orthonormal basis, there exist $\\alpha_{ij} \\in \\C$ such that:\n\t\n\t$$ |v\\ra = \\sum_{i,j} \\alpha_{ij} |v_i w_j\\ra $$\n\t\n\tBy linearity:\n\t\n\t$$ \\la v|v \\ra = \\sum_{i,j,k,l} \\overline{\\alpha_{ij}} \\alpha_{kl} \\la v_i w_j|v_k w_l \\ra = \\sum_{i,j,k,l} \\overline{\\alpha_{ij}} \\alpha_{kl} \\  \\delta_{ik} \\delta_{jl} = \\sum_{i,j} |\\alpha_{ij}|^2  \\geq 0 $$\n\t\n\twhere the equality holds if and only if $\\alpha_{ij} = 0 \\ \\forall i,j$.\n\\end{proof}\n\nFrom the inner product, the tensor space $H_1 \\otimes H_2$ naturally inherits the notions of adjoint, unitary, normality and Hermicity. We will denote a vector $|\\varphi\\ra$ tensored with itsel n times, $|\\varphi\\ra \\otimes \\overplace{n}{\\dotsc} \\otimes |\\varphi\\ra$, as $|\\varphi\\ra^{\\otimes n}$, and equivalently with Hilbert spaces: $H \\otimes \\overplace{n}{\\dotsc} \\otimes H$, as $H^{\\otimes n}$. For our quantum computing purposes, the following case holds particular relevance.\n\n\\begin{corollary}\n\tThe tensor product of $\\C^2$ with itself n times, $\\C^2 \\otimes \\overplace{n}{\\dotsc} \\otimes \\C^2$, is isomorphic to $\\C^{2^n}$.\n\\end{corollary}\n\n\\begin{proof}\n\tLet $H = \\C^2 \\otimes \\overplace{n}{\\dotsc} \\otimes \\C^2$. Since $dim(H) = dim(\\C^2)^n = 2^n$, $H$ is a Hilbert space with dimension $2^n$. Thus, by Hausdorff's Theorem \\cite{Paya2020}, it is isomorphic to the canonical complex vector space of dimension $2^n$, $\\C^{2^n}$.\n\\end{proof}\n\nIn the same way that the inner product was naturally extended to the tensor space, we may extend operators ensuring linearity. Let $A: V \\longrightarrow V'$ and $B: W \\longrightarrow W'$ two operators between Hilbert spaces. Then, we define $A \\otimes B: V \\otimes W \\longrightarrow V' \\otimes W'$ using the following equation:\n\n$$ (A \\otimes B)(|v\\ra \\otimes |w\\ra) \\equiv A|v\\ra \\otimes B|w\\ra $$\n\nWe extend this definition to every element of $V \\otimes W$ ensuring linearity:\n\n$$ (A \\otimes B) \\bigg(\\sum_i a_i |v_i\\ra \\otimes |w_i\\ra \\bigg) \\equiv \\sum_i a_i A|v_i\\ra \\otimes B|w_i\\ra $$\n\nIt can be shown that $A \\otimes B$ is a well-defined linear operator. In fact, any linear operator mapping $V \\otimes W$ to $V' \\otimes W'$ may be expressed as a linear combination of tensor product of linear operators mapping $V$ to $V'$ and $W$ to $W'$:\n\n$$ C = \\sum_i a_i A_i \\otimes B_i $$\n\nwhere by definition:\n\n$$ \\bigg( \\sum_i a_i A_i \\otimes B_i \\bigg)|v\\ra \\otimes |w\\ra = \\sum_i a_i A_i|v\\ra \\otimes B_i|w\\ra $$\n\n\n\\subsection{Postulate 4 statement}\n\\label{postulate-4-section}\n\nReaching the core of this section, suppose we consider two (or more) distinct physical systems. In order to describe the state of the composite system we need to make use of tensor product.\n\n\\begin{postulate}\n\tThe state space of a composite physical system is the tensor product of the state spaces of the component physical systems. Moreover, if we have systems numbered $1$ through $n$, and system number $i$ is prepared in the state $|\\varphi_i\\ra$, then the joint state of the total system is $|\\varphi_1\\ra \\otimes \\dotsc \\otimes |\\varphi_n\\ra$.\n\\end{postulate}\n\nLet us provide an intuitive notion of why is the tensor product used in order to describe composite systems. After all, we would expect that there exists a \\emph{somehow canonical way} os describing the product composition of systems, just like the cartesian product is used with vector spaces. Let us refer again to the so-called \\emph{superposition principle of quantum mechanics}. Let $|\\varphi\\ra$ and $|\\psi\\ra$ be two vector states of a system. Then, any superposition of the states, $\\alpha|\\varphi\\ra + \\beta|\\psi\\ra$, should also be another vector state, where $|\\alpha|^2 + |\\beta|^2 = 1$. Suppose we now have two systems $X$ and $Y$, with two vector states $|\\varphi_x\\ra$ and $|\\varphi_y\\ra$. Then, we could describe the state of the composite system $XY$ as some state $|\\varphi_x\\ra|\\varphi_y\\ra$. Studying the superposition principle on composite systems leads us naturally to the notion of tensor product. It is important to note that this development is not thorough, since we are not taking the superposition principle as a fundamental component of our description of quantum mechanics. It does help up to build an intuitive notion on why this tensor product is used.\n\nWe now introduce the \\emph{Bell State} or \\emph{EPR pair:}\n\n$$ |+\\ra = \\frac{ |00\\ra + |11\\ra }{ \\sqrt 2 } $$\n\nAlthough it may seem harmless at first glance, this state has been responsible for many surprises during the development of quantum physics \\cite{Bellt1964}. Let us have a first look into it, although we will come back to it later on.\n\nThe first thing to notice about this state is that it can be expressed as a single tensor product of state vector: $|+\\ra \\neq |a\\ra|b\\ra$. This means that this state is not describing two independent physical systems put together with their respective vector states independently, it describes a \\textbf{relation} between both systems too. It means that those systems are somehow interfering with each other. So we may affect one by disrupting the other.\n\nThis phenomenon is called \\emph{entaglement}. A state is called \\emph{entangled} when it cannot be expressed as the product of states of its component systems. This concept rests at the heart of the disparity between classic physics and quantum physics and it is key in quantum computing. It was deeply studied first by Einstein, Podolsky, and Rosen (EPR) \\cite{Einstein1935} and second by John Bell \\cite{Bellt1964}.\n\n\n\\subsection{Projective measurement}\n\\label{projective-measurement}\n\n\nIn this section, we explain an important particular case of measurement. In fact, this method of projective measurement is equivalent to Postulate 2, when they are combined with the capacity to perform unitary operations. It has huge relevancy in quantum computing and it is explained here because of its relation with composite systems. Let us state the alternative postulate:\n\n\\begin{postulate 2'}\n\tA projective measurement is described by an \\emph{observable}, $M$, a Hermitian operator on the state space of the system being described. The observable has a spectral decomposition:\n\t\n\t$$ M = \\sum_m m P_m$$\n\t\n\twhere $P_m$ is the projector onto the eigenspace with eigenvalue $m$. The possible outcomes of the measurement correspond to the eigenvalues, $m$, of the observable. Upon measuring the state $|\\varphi\\ra$, the probability of the result $m$ ocurring is:\n\t\t\n\t$$ p(m) = \\la \\varphi | P_m | \\varphi \\ra $$\n\t\n\tand the state of the system after the measurement, givent that outcome $m$ ocurred, is:\n\t\n\t$$ \\frac{P_m |\\varphi\\ra}{\\sqrt{p(m)}} $$\n\\end{postulate 2'}\n\nProjective measurements can be seen as a particular case of Postulate 2. Suppose the measurement operators from such postulate, in addition to satisying the completeness relation $\\sum_m M_m M_m^\\dagger = I$, also fulfill that $M_m$ are \\emph{orthogonal projectors}. That is, $M_m$ is Hermitian and $M_m M_{m'} = \\delta_{mm'} M_m \\ \\forall m,m'$. With these aditional restricions it holds that $M_m M_m^\\dagger = M_m M_m = M_m$. By choosing $P_m = M_m$ we see that projective measurements is a particular case of Postulate 2.\n\nThanks to the way projective measurements are expressed, they have nice and handy properties. Let us compute the average value of a projective measurement:\n\n\\begin{equation}\n\t\\begin{split}\n\t\tE(M)\t& = \\sum_m m p(m) \\\\\n\t\t\t\t& = \\sum_m m \\la \\varphi | P_m | \\varphi \\ra \\\\\n\t\t\t\t& = \\la \\varphi | \\bigg( \\sum_m m P_m \\bigg) | \\varphi \\ra \\\\\n\t\t\t\t& = \\la \\varphi | M | \\varphi \\ra\n\t\\end{split}\n\\end{equation}\n\nThe average value of an operator is usually written as $\\la M \\ra \\equiv \\la \\varphi | M | \\varphi \\ra$. The standar deviation associated to observations of $M$ is then written as:\n\n\\begin{equation}\n\t\\begin{split}\n\t[\\Delta(M)]^2\t& = \\big\\la (M - \\la M \\ra )^2 \\big\\ra\\\\\n\t\t\t\t\t& = \\la M^2 \\ra - \\la M \\ra^2\n\t\\end{split}\n\\end{equation}\n\nThis means that if we prepare our state $|\\varphi\\ra$ multiple times and measure it, the measures will follow a normal distribution with expected value $\\la M \\ra$ and standard deviation $\\Delta(M) = \\sqrt{\\la M^2 \\ra - \\la M \\ra^2}$. This formulation of standard deviation using observables provides us with an elegant proof of perhaps the most famous quantum mechanics result: The \\emph{Heisenberg uncertainty principle}. Such proof can be found in Box 2.4 from \\cite{Nielsen2002}.\n\nThere are two additional notations worth mentioning regarding projective measurement. Instead of providing an observable $M$, we will sometimes provide a complete set of orthogonal projectors. That is, a set $P_m$ such that $\\sum_i P_m = I$ and $P_m P_{m'} = \\delta_{mm'} P_m$. The corresponding implicit observable used in this case is $M = \\sum_m m P_m$. Finally, another widely used notation is to 'measure in a basis $|m\\ra$', where $|m\\ra$ form an orthonormal basis. This simply means that the chosen projectors are  $P_m = |m \\ra\\la m|$ and the observable is $M = \\sum_m m |m \\ra\\la m|$. This is the usual notation in quantum computing.\n\n\n\\subsection{Quantum Computing perspective: Multiple qubits}\n\n\nSuppose we have a pair of qubits. In the classical case, two bits can be in four possible states: 00, 01, 10, and 11. Similarly, the two qubits computational basis states are $|00\\ra$, $|01\\ra$, $|10\\ra$ and $|11\\ra$. We arrive at this natural notation by knowing that each qubit has $\\C^2$ as their associated state space and using the tensor product. Just like in the single qubit case, our two qubits system may be in a superposition of these four states:\n\n$$ |\\varphi\\ra = \\alpha_{00} |00\\ra + \\alpha_{01} |01\\ra + \\alpha_{10} |10\\ra + \\alpha_{11} |11\\ra $$\n\nCorrespondingly, the measurement of this system will result in either 00, 01, 10 or 11 since we are using the observable $\\sum_{x \\in \\{0,1\\}^2} x |x\\ra\\la x|$, where $\\{0,1\\}^2$ are the strings of length two where each character is either $0$ or $1$. In fact, it will yield state $x$ with probability $|\\alpha_x|^2$, being $\\alpha_x$ the coefficient associated with the state $|x\\ra$. The condition of the probabilities adding up to one is also called the \\emph{normalization condition} and can be expressed as $\\sum_{x \\in \\{0,1\\}^2} |\\alpha_x|^2 = 1$ for the two qubits case.\n\nThe fundamental differences with the single qubit case start on measurement. Of course, we can measure both qubits at the same time, but we could also measure only one of them. In order to achieve this we can use the projectors $P_0 = |00\\ra\\la00| + |01\\ra\\la01|$ and $P_1 = |10\\ra\\la10| + |11\\ra\\la11|$. Upon measuring, the system will collapse to $P_0|\\varphi\\ra / \\sqrt{p_0}$ with probability:\n\n$$ p_0 = \\la\\varphi|P_0|\\varphi\\ra = |\\alpha_{00}|^2 + |\\alpha_{01}|^2 $$\n\nSince these are the coefficients associated with the first qubit being $0$, this is the probability of first qubit being 0. Furthermore, our system will collapse to:\n\n$$ |\\varphi'\\ra = \\frac{ \\alpha_{00} |00\\ra + \\alpha_{01} |01\\ra }{ \\sqrt{|\\alpha_{00}|^2 + |\\alpha_{01}|^2} } $$\n\nNote the normalization term $\\sqrt{|\\alpha_{00}|^2 + |\\alpha_{01}|^2}$, which appears so the post-measurement state still satisfies the normalization condition. Naturally, after obtaining $0$ in the first qubit we can still obtain either $0$ or $1$ in the second qubit, with probabilities \n\n$$ \\frac{ |\\alpha_{00}|^2 }{ |\\alpha_{00}|^2 + |\\alpha_{01}|^2 }  \\ \\text{ and } \\ \n\\frac{ |\\alpha_{01}|^2 }{ |\\alpha_{00}|^2 + |\\alpha_{01}|^2 } $$\n\nrespectively, adding up to $1$. Correspondingly, the first qubit being measured will yield $1$ with probability $p_1 = |\\alpha_{10}|^2 + |\\alpha_{11}|^2$.\n\nAdditionally, the first qubit independently should satisfy the normalization condition. That is, its probabilities of being $0$ and $1$ upon measurement must add up to $1$. But those are $p_0$ and $p_1$, which add up to one because of the normalization condition for $|\\varphi\\ra$, as expected.\n\nLet us come back to the previously introduced \\emph{Bell State}:\n\n$$ |+\\ra = \\frac{ |00\\ra + |11\\ra }{ \\sqrt 2 } $$\n\nWhen measuring using the previously defined projectors $P_0$ and $P_1$ we obtain that the first qubit will collapse to either 0 or 1 with equal probability $p_0 = p_1 = 1/2$. Most importantly, in the first case the qubit will collapse to the state:\n\n$$ \\frac{ |00\\ra / \\sqrt 2 }{ \\sqrt p_0 } = |00\\ra $$\n\nMeaning that the second qubit also collapsed to 0. Note that we only affected the first qubit and the second one was disturbed. These are the consequences of entanglement, key in the appearance of impressive phenomenoms and discussions such as the EPR Paradox \\cite{Einstein1935}, \\cite{Bellt1964}.\n\nLet us finally consider the more general case. In an n-qubits system our computational (orthonormal) basis would consist of the sates $|x_1 x_2 \\dotsc x_n\\ra$, where $x_i \\in \\{0,1\\}$. As we already know, in a single qubit system we have two amplitudes $\\alpha_0$ and $\\alpha_1$. We have four amplitudes for a 2-qubits system, eight for a 3-qubits system... And $2^n$ for an n-qubits system. This means that the number of amplitudes grows exponentially as we add qubits to the system. An immense increment compared to the classical case where the quantity of information that our system holds grows linearly with the numbers of bits. Of course, it is not that simple, since there are huge limitations on how we may access this information in the quantum realm such as how a qubit collapses upon measurement and the no-cloning theorem. However, we can already glimpse the power of quantum computing versus the classical one.\n\n\n\\section{The no-cloning theorem}\n\n\nA first exposure to the basis of quantum computing is fundamentally incomplete without the no-cloning theorem. It lets us understand one of the fundamental inconveniences of quantum computing: the impossibilty of cloning arbitrary states.\n\nWe proceed by formalizing the copying mechanism. Let $H$ be a state space and $|\\varphi\\ra \\in H$ the state to be copied. Given another state $|\\varphi'\\ra \\in H$, we would like to copy $|\\varphi\\ra$ into $|\\varphi'\\ra$. Since we can prepare $|\\varphi'\\ra$ at will before the copying occurs, let  $|\\varphi'\\ra = |x_0\\ra$ be a fixed state. Then, our copying operation will take both states and produce the following result:\n\n$$ (|\\varphi\\ra \\otimes |x_0\\ra) \\xrightarrow{U} |\\varphi\\ra \\otimes |\\varphi\\ra $$\n\nOperations between n-qubits (n-qubits gates) must preserve their norm, thus they must be unitary $n \\times n$ matrices. In our case, $U$ is a $2 dim(H) \\times 2 dim(H)$ unitary matrix. Let us now state and prove the theorem.\n\n\\begin{theorem}[No-cloning Theorem]\n\\label{no-cloning-theorem}\n\tThere is no unitary operator $U: H^{\\otimes 2} \\longrightarrow H^{\\otimes 2}$ and state $|x_0\\ra \\in H$ such that for any arbitrary state $|\\varphi\\ra \\in H$ it holds\n\t\n\t$$ U |\\varphi\\ra |x_0\\ra = |\\varphi\\ra |\\varphi\\ra $$\n\\end{theorem}\n\\begin{proof}\n\tSuppose there exists such unitary operator $U$ and such state $|x_0\\ra$. Let $|\\varphi\\ra, |\\psi\\ra \\in H$. We may apply the copying operators to both of them:\n\t\n\t$$ U |\\varphi\\ra |x_0\\ra = |\\varphi\\ra |\\varphi\\ra $$\n\t$$ U |\\psi\\ra |x_0\\ra = |\\psi\\ra |\\psi\\ra $$\n\t\n\tTaking the inner product of both equations and using that $U$ is unitary results in:\n\t\n\t\\begin{equation*}\n\t\t\\begin{gathered}\n\t\t\t\\bigg( U |\\varphi\\ra |x_0\\ra, U |\\psi\\ra |x_0\\ra \\bigg) = \\bigg( |\\varphi\\ra |\\varphi\\ra, |\\psi\\ra |\\psi\\ra \\bigg) \\iff \\\\\n\t\t\t\\bigg( |\\varphi\\ra |x_0\\ra, |\\psi\\ra |x_0\\ra \\bigg) = \\la\\varphi|\\psi\\ra \\la\\varphi|\\psi\\ra \\iff \\\\\n\t\t\t\\la\\varphi|\\psi\\ra \\la x_0|x_0 \\ra = \\la\\varphi|\\psi\\ra^2\n\t\t\\end{gathered}\n\t\\end{equation*}\n\t\n\tSince $|x_0\\ra$ is a normalized vector, $\\la x_0|x_0 \\ra = 1$, and we obtain:\n\t\n\t$$\\la\\varphi|\\psi\\ra = \\la\\varphi|\\psi\\ra^2$$\n\t\n\tWhich only holds if $\\la\\varphi|\\psi\\ra$ equals to either $0$ or $1$, which means $|\\varphi\\ra$ and $|\\psi\\ra$ are either equal or orthonormal. But those vectors were arbitrary, thus such a general cloning operator is impossible. \n\\end{proof}\n", "meta": {"hexsha": "deb105544927e5cbc11860f81bfc9d24911a0913", "size": 59538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/chapter1_QuantumMechanicsModel.tex", "max_stars_repo_name": "Ocete/TFG", "max_stars_repo_head_hexsha": "baf0853276aef8f6fd6c5cccbe69ede7ca7987c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-05T22:40:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T22:40:37.000Z", "max_issues_repo_path": "thesis/chapters/chapter1_QuantumMechanicsModel.tex", "max_issues_repo_name": "Ocete/TFG", "max_issues_repo_head_hexsha": "baf0853276aef8f6fd6c5cccbe69ede7ca7987c3", "max_issues_repo_licenses": ["MIT"], "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/chapter1_QuantumMechanicsModel.tex", "max_forks_repo_name": "Ocete/TFG", "max_forks_repo_head_hexsha": "baf0853276aef8f6fd6c5cccbe69ede7ca7987c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-29T18:23:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-29T18:23:25.000Z", "avg_line_length": 69.0696055684, "max_line_length": 1185, "alphanum_fraction": 0.7211192852, "num_tokens": 17881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6138696773157014}}
{"text": "\\problemname{Conquest}\n\nNomads, Kingdoms, and Tribes are on the islands of the great seas.\nBridges span between islands allowing travel between them.\nIt is possible to get from every island to every other island\nthrough some sequence of bridges.\nThe islands were at peace until everything changed when the\nSpanning Nation attacked!\n\nInitially the Spanning Nation occupies island 1.  From that point\nforward, the Spanning Nation can attack any island that is directly\nconnected to some island already conquered by the\nSpanning Nation.  Thankfully wars are resolved without any fighting.\nThe Spanning Nation only attacks an island if the island's army is\nstrictly smaller than the Spanning Nation's army.  The smaller island\narmy will simply concede and join the Spanning Nation's army.\n\nAs the tactical advisor of the Spanning Nation, determine the maximum\npossible army size the Spanning Nation can have after making a series\nof attacks.\n\n\\section*{Input}\n\nThe first line contains the integer $N$ ($1 \\leq N \\leq 200\\,000$),\nwhich is the number of islands, and $M$ ($0 \\leq M \\leq 200\\,000$),\nthe number of bridges.\n\nThe next $M$ lines describe the bridges. Each of these lines contains\ntwo distinct integers $u$ and $v$ ($1 \\leq u, v \\leq N$), indicating\nthat there is a bridge between the islands $u$ and $v$.  There is at\nmost one bridge between any pair of islands.\n\nThe next $N$ lines describe the islands' army size in order. Each of these\nlines contains a single integer $s$ ($0 \\leq s \\leq 1\\,000$), which is the\narmy size of this island.\n\n\\section*{Output}\n\nDisplay the maximum possible army size of the Spanning Nation.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "2b4e426d7108c1136d8ee28d8507f51e328a507e", "size": 1695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/conquest/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/conquest/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/conquest/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": 37.6666666667, "max_line_length": 74, "alphanum_fraction": 0.7646017699, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.613869672026091}}
{"text": "\\chapter{Bonus: A hint of Pontryagin duality}\n\\label{ch:pontryagin}\n\nIn this short chapter we will give statements\nabout how to generalize our Fourier analysis\n(a bonus chapter \\Cref{ch:fourier})\nto a much wider class of groups $G$.\n\n\\section{LCA groups}\n\\prototype{$\\TT$, $\\RR$.}\nEarlier we played with $\\RR$,\nwhich is nice because in addition to being a topological space,\nit is also an abelian group under addition.\nThese sorts of objects which are both groups and spaces have a name.\n\\begin{definition}\n\tA group $G$ is a \\vocab{topological group}\n\tis a Hausdorff\\footnote{Some authors omit the Hausdorff condition.}\n\ttopological space equipped also with a group operation $(G, \\cdot)$,\n\tsuch that both maps\n\t\\begin{align*}\n\t\tG \\times G &\\to G \\quad\\text{ by }\\quad (x,y) \\mapsto xy \\\\\n\t\tG &\\to G \\quad\\text{ by }\\quad x \\mapsto x\\inv\n\t\\end{align*}\n\tare continuous.\n\\end{definition}\n\nFor our Fourier analysis, we need some additional conditions.\n\\begin{definition}\n\tA \\vocab{locally compact abelian (LCA) group} $G$\n\tis one for which the group operation is abelian,\n\tand moreover the topology is \\emph{locally compact}:\n\tfor every point $p$ of $G$,\n\tthere exists a compact subset $K$ of $G$\n\tsuch that $K \\ni p$, and $K$ contains some open neighborhood of $p$.\n\\end{definition}\n\nOur previous examples all fall into this category:\n\\begin{example}\n\t[Examples of locally compact abelian groups]\n\t\\listhack\n\t\\begin{itemize}\n\t\t\\ii Any finite group $Z$ with the discrete topology is LCA.\n\t\t\\ii The circle group $\\TT$ is LCA and also in fact compact.\n\t\t\\ii The real numbers $\\RR$ are an example of an LCA group\n\t\twhich is \\emph{not} compact.\n\t\\end{itemize}\n\\end{example}\n\nThese conditions turn out to be enough\nfor us to define a measure on the space $G$.\nThe relevant theorem, which we will just quote:\n\\begin{theorem}\n\t[Haar measure]\n\tLet $G$ be a locally compact abelian group.\n\tWe regard it as a measurable space\n\tusing its Borel $\\sigma$-algebra $\\SB(G)$.\n\tThere exists a measure $\\mu \\colon \\SB(G) \\to [0,\\infty]$,\n\tcalled the \\vocab{Haar measure},\n\tsatisfying the following properties:\n\t\\begin{itemize}\n\t\t\\ii $\\mu(gS) = \\mu(S)$ for every $g \\in G$ and measurable $S$.\n\t\tThat means that $\\mu$ is ``translation-invariant''\n\t\tunder translation by $G$.\n\t\t\\ii $\\mu(K)$ is finite for any compact set $K$.\n\t\t\\ii if $S$ is measurable, then $\\mu(S) = \\inf\\left\\{ \\mu(U) \\colon U \\supseteq S \\text{ open} \\right\\}$.\n\t\t\\ii if $U$ is open, then $\\mu(U) = \\sup\\left\\{ \\mu(S) \\colon S \\supseteq U \\text{ measurable} \\right\\}$.\n\t\\end{itemize}\n\tMoreover, it is unique up to scaling by a positive constant.\n\\end{theorem}\n\n\\begin{remark}\n\tNote that if $G$ is compact, then $\\mu(G)$ is finite (and positive).\n\tFor this reason the Haar measure on a LCA group $G$\n\tis usually normalized so $\\mu(G) = 1$.\n\\end{remark}\n\nFor this chapter, we will only use the first two properties at all,\nand the other two are just mentioned for completeness.\nNote that this actually generalizes the chapter where\nwe constructed a measure on $\\SB(\\RR^n)$,\nsince $\\RR^n$ is an LCA group!\n\nSo, in short: if we have an LCA group,\nwe have a measure $\\mu$ on it.\n\n\\section{The Pontryagin dual}\nNow the key definition is:\n\\begin{definition}\n\tLet $G$ be an LCA group.\n\tThen its \\vocab{Pontryagin dual} is the abelian group\n\t\\[ \\wh G \\defeq \\left\\{ \\text{continuous group homomorphisms }\n\t\t\t\\xi : G \\to \\TT \\right\\}. \\]\n\tThe maps $\\xi$ are called \\vocab{characters}.\n\tIt can be itself made into an LCA group.\\footnote{If you must\n\t\tknow the topology, it is the \\vocab{compact-open topology}:\n\t\tfor any compact set $K \\subseteq G$\n\t\tand open set $U \\subseteq \\TT$,\n\t\twe declare the set of all $\\xi$ with $\\xi\\im(K) \\subseteq U$ to be open,\n\t\tand then take the smallest topology\n\t\tcontaining all such sets. We won't use this at all.}\n\\end{definition}\n\\begin{example}\n\t[Examples of Pontryagin duals]\n\t\\listhack\n\t\\begin{itemize}\n\t\t\\ii $\\wh{\\ZZ} \\cong \\TT$,\n\t\tsince group homomorphisms $\\ZZ \\to \\TT$ are determined by the image of $1$.\n\t\t\\ii $\\wh{\\TT} \\cong \\ZZ$.\n\t\tThe characters are given by $\\theta \\mapsto n\\theta$ for $n \\in \\ZZ$.\n\t\t\\ii $\\wh{\\RR} \\cong \\RR$.\n\t\tThis is because a nonzero continuous homomorphism\n\t\t$\\RR \\to S^1$ is determined by the fiber above $1 \\in S^1$.\n\t\t(Algebraic topologists might see covering projections here.)\n\t\t\\ii $\\wh{\\ZZ/n\\ZZ} \\cong \\ZZ/n\\ZZ$,\n\t\tcharacters $\\xi$ being determined by the image $\\xi(1) \\in \\TT$.\n\t\t\\ii $\\wh{G \\times H} \\cong \\wh G \\times \\wh H$.\n\t\\end{itemize}\n\\end{example}\n\\begin{exercise}\n\t[$\\wh Z \\cong Z$, for those who read \\Cref{sec:FTFGAG}]\n\tIf $Z$ is a finite abelian group, show that $\\wh Z \\cong Z$,\n\tusing the results of the previous example.\n\tYou may now recognize that the bilinear form\n\t$\\cdot \\colon Z \\times Z \\to \\TT$\n\tis exactly a choice of isomorphism $Z \\to \\wh Z$.\n\tIt is not ``canonical''.\n\\end{exercise}\n\nTrue to its name as the dual,\nand in analogy with $(V^\\vee)^\\vee \\cong V$ for vector spaces $V$, we have:\n\\begin{theorem}\n\t[Pontryagin duality theorem]\n\tFor any LCA group $G$, there is an isomorphism\n\t\\[ G \\cong \\wh{\\wh G} \\qquad \\text{by} \\qquad\n\t\tx \\mapsto \\left( \\xi \\mapsto \\xi(x) \\right). \\]\n\\end{theorem}\n\nThe compact case is especially nice.\n\\begin{proposition}\n\t[$G$ compact $\\iff$ $\\wh G$ discrete]\n\tLet $G$ be an LCA group.\n\tThen $G$ is compact if and only if $\\wh G$ is discrete.\n\\end{proposition}\n\\begin{proof}\n\t\\Cref{prob:LCA_compact}.\n\\end{proof}\n\n\\section{The orthonormal basis in the compact case}\nLet $G$ be a compact LCA group,\nand work with its Haar measure.\nWe may now let $L^2(G)$ be the space of\nsquare-integrable functions to $\\CC$, i.e.\n\\[ L^2(G) = \\left\\{ f \\colon G \\to \\CC\n\t\\quad\\text{such that}\\quad \\int_G |f|^2 < \\infty \\right\\}. \\]\nThus we can equip it with the inner form\n\\[ \\left< f,g \\right> = \\int_G f \\cdot \\ol{g}. \\]\nIn that case, we get all the results we wanted before:\n\\begin{theorem}\n\t[Characters of $\\wh G$ forms an orthonormal basis]\n\t\\label{thm:god}\n\tAssume $G$ is LCA and compact (so $\\wh G$ is discrete).\n\tThen the characters\n\t\\[ (e_\\xi)_{\\xi \\in \\wh G}\n\t\t\\qquad\\text{by}\\qquad e_\\xi(x) = e(\\xi(x)) = \\exp(2\\pi i \\xi(x)) \\]\n\tform an orthonormal basis of $L^2(G)$.\n\tThus for each $f \\in L^2(G)$ we have\n\t\\[ f = \\sum_{\\xi \\in \\wh G} \\wh f(\\xi) e_\\xi \\]\n\twhere\n\t\\[ \\wh f(\\xi) = \\left< f, e_\\xi \\right>\n\t\t= \\int_G f(x) \\exp(-2\\pi i \\xi(x)) \\; d\\mu. \\]\n\\end{theorem}\nThe sum $\\sum_{\\xi \\in \\wh G}$ makes sense since $\\wh G$ is discrete.\nIn particular,\n\\begin{itemize}\n\t\\ii Letting $G = Z$ for a finite group $G$\n\tgives ``Fourier transform on finite groups''.\n\t\\ii The special case $G = \\ZZ/n\\ZZ$ has its\n\t\\href{https://en.wikipedia.org/wiki/Discrete_Fourier_transform#Definition}%\n\t{own Wikipedia page}: the ``discrete-time Fourier transform''.\n\t\\ii Letting $G = \\TT$ gives the ``Fourier series'' earlier.\n\\end{itemize}\n\n\\section{The Fourier transform of the non-compact case}\nIf $G$ is LCA but not compact, then Theorem~\\ref{thm:god} becomes false.\nOn the other hand, it's still possible to define $\\wh G$.\nWe can then try to write the Fourier coefficients anyways:\nlet \\[ \\wh f(\\xi) = \\int_G f \\cdot \\ol{e_\\xi} \\; d\\mu \\]\nfor $\\xi \\in \\wh G$ and $f \\colon G \\to \\CC$.\nThe results are less fun in this case, but we still have, for example:\n\\begin{theorem}\n\t[Fourier inverison formula in the non-compact case]\n\tLet $\\mu$ be a Haar measure on $G$.\n\tThen there exists a unique Haar measure $\\nu$ on $\\wh G$\n\t(called the \\vocab{dual measure}) such that:\n\twhenever $f \\in L^1(G)$ and $\\wh f \\in L^1(\\wh G)$, we have\n\t\\[ f(x) = \\int_{\\wh G} \\wh f(\\xi) \\xi(x) \\; d\\nu \\]\n\tfor almost all $x \\in G$ (with respect to $\\mu$).\n\tIf $f$ is continuous, this holds for all $x$.\n\\end{theorem}\nSo while we don't have the niceness of a full inner product from before,\nwe can still in some situations at least write $f$ as integral\nin sort of the same way as before.\n\nIn particular, they have special names for a few special $G$:\n\\begin{itemize}\n\t\\ii If $G = \\RR$, then $\\wh G = \\RR$,\n\tyielding the\n\t``\\href{https://en.wikipedia.org/wiki/Fourier_transform}{(continuous) Fourier transform}''.\n\t\\ii If $G = \\ZZ$, then $\\wh G = \\TT$,\n\tyielding the\n\t``\\href{https://en.wikipedia.org/wiki/Discrete-time_Fourier_transform}{discrete time Fourier transform}.\n\\end{itemize}\n\n\\section{Summary}\nWe summarize our various flavors of Fourier analysis\nfrom the previous sections in the following table.\nIn the first part $G$ is compact,\nin the second half $G$ is not.\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 Fourier analysis} & \\{\\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{Fourier transform on finite groups} & Z\n\t\t\t& \\xi \\in \\wh Z \\cong Z & e( i \\xi \\cdot x) \\\\\n\t\t\\text{Discrete Fourier transform} & \\ZZ/n\\ZZ & \\xi \\in \\ZZ/n\\ZZ\n\t\t\t& e(\\xi x / n) \\\\\n\t\t\\text{Fourier series} & \\TT \\cong [-\\pi, \\pi]  & n \\in \\ZZ\n\t\t\t& \\exp(inx) \\\\ \\hline\n\t\t\\text{Continuous Fourier transform} & \\RR & \\xi \\in \\RR\n\t\t \t& e(\\xi x) \\\\\n\t\t\\text{Discrete time Fourier transform} & \\ZZ & \\xi \\in \\TT \\cong [-\\pi, \\pi]\n\t\t \t& \\exp(i \\xi n) \\\\\n\t\\end{array}\n\\]\nYou might notice that the \\textbf{various names are awful}.\nThis is part of the reason I got confused as a high school student:\nevery type of Fourier series above has its own Wikipedia article.\nIf it were up to me, we would just use the term ``$G$-Fourier transform'',\nand that would make everyone's lives a lot easier.\n\n\n\n\\section{\\problemhead}\n\\begin{problem}\n\tIf $G$ is compact, so $\\wh G$ is discrete,\n\tdescribe the dual measure $\\nu$.\n\t\\begin{hint}\n\t\tYou can read it off \\Cref{thm:god}.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIt is the counting measure.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t\\label{prob:LCA_compact}\n\tShow that an LCA group $G$ is compact\n\tif and only if $\\wh G$ is discrete.\n\t(You will need the compact-open topology for this.)\n\t\\begin{hint}\n\t\tAfter Pontryagin duality,\n\t\twe need to show $G$ compact implies $\\wh G$ discrete\n\t\tand $G$ discrete implies $\\wh G$ compact.\n\t\tBoth do not need anything fancy:\n\t\tthey are topological facts.\n\t\\end{hint}\n\\end{problem}\n\n\\endinput\n\\section{Peter-Weyl}\nIn fact, if $G$ is a Lie group, even if $G$ is not abelian\nwe can still give an orthonormal basis of $L^2(G)$\n(the square-integrable functions on $G$).\nIt turns out in this case the characters are attached to complex\nirreducible representations of $G$\n(and in what follows all representations are complex).\n\nThe result is given by the Peter-Weyl theorem.\nFirst, we need the following result:\n\\begin{lemma}\n\t[Compact Lie groups have unitary reps]\n\tAny finite-dimensional (complex) representation $V$ of a compact Lie group $G$\n\tis unitary, meaning it can be equipped with a $G$-invariant inner form.\n\tConsequently, $V$ is completely reducible:\n\tit splits into the direct sum of irreducible representations of $G$.\n\\end{lemma}\n\\begin{proof}\n\tSuppose $B : V \\times V \\to \\CC$ is any inner product.\n\tEquip $G$ with a right-invariant Haar measure $dg$.\n\tThen we can equip it with an ``averaged'' inner form\n\t\\[ \\wt B(v,w) = \\int_G B(gv, gw) \\; dg. \\]\n\tThen $\\wt B$ is the desired $G$-invariant inner form.\n\tNow, the fact that $V$ is completely reducible follows from the fact\n\tthat given a subrepresentation of $V$, its orthogonal complement\n\tis also a subrepresentation.\n\\end{proof}\n\nThe Peter-Weyl theorem then asserts that the finite-dimensional irreducible\nunitary representations essentially give an orthonormal basis for $L^2(G)$,\nin the following sense.  Let $V = (V, \\rho)$ be such a representation of $G$,\nand fix an orthonormal basis of $e_1$, \\dots, $e_d$ for $V$ (where $d = \\dim V$).\nThe $(i,j)$th \\vocab{matrix coefficient} for $V$ is then given by \n\\[ G \\taking{\\rho} \\GL(V) \\taking{\\pi_{ij}} \\CC \\]\nwhere $\\pi_{ij}$ is the projection onto the $(i,j)$th entry of the matrix.\nWe abbreviate $\\pi_{ij} \\circ \\rho$ to $\\rho_{ij}$.\nThen the theorem is:\n\\begin{theorem}\n\t[Peter-Weyl]\n\tLet $G$ be a compact Lie group.\n\tLet $\\Sigma$ denote the (pairwise non-isomorphic) irreducible finite-dimensional\n\tunitary representations of $G$.\n\tThen\n\t\\[ \\left\\{ \\sqrt{\\dim V} \\rho_{ij}\n\t\t\t\\; \\Big\\vert \\; (V, \\rho) \\in \\Sigma,\n\t\t\t\\text{ and } 1 \\le i,j \\le \\dim V \\right\\}  \\]\n\tis an orthonormal basis of $L^2(G)$.\n\\end{theorem}\nStrictly, I should say $\\Sigma$ is a set of representatives of \nthe isomorphism classes of irreducible unitary representations,\none for each isomorphism class.\n\nIn the special case $G$ is abelian,\nall irreducible representations are one-dimensional.\nA one-dimensional representation of $G$ is a map\n$G \\injto \\GL(\\CC) \\cong \\CC^\\times$,\nbut the unitary condition implies it is actually a map $G \\injto S^1 \\cong \\TT$,\ni.e.\\ it is an element of $\\wh G$.\n", "meta": {"hexsha": "039c5ad97c06985b2a2d21dc54c5da84ee39191d", "size": 12690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/measure/pontryagin.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/measure/pontryagin.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/measure/pontryagin.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.2228915663, "max_line_length": 106, "alphanum_fraction": 0.6885736801, "num_tokens": 4109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.6138696688664667}}
{"text": "\\newpage\n\\subsection{Goal}\n\nExperimental study of the time complexity of different algorithms.\n\n\\subsection{Formulation of the problem}\n\nFor each n from 1 to 2000, measure the average computer execution time of programs implementing the algorithms and functions below for five runs.\nPlot the data obtained showing the average execution time as a function of n. Conduct the theoretical analysis of the time complexity of the algorithms in question and compare the empirical and theoretical time complexities.\n\n\\paragraph{I.}\nGenerate an $n$-dimensional random vector $v=[v_1,v_2,...,v_n]$ with non-negative elements.\nFor $v$, implement the following calculations and algorithms:\n\\begin{itemize}\n    \\item $f(v) = const$ (constant function);\n    \\item $f(v) = \\sum^{n}_{k = 1}{v_k}$ (the sum of elements);\n    \\item $f(v) = \\prod^{n}_{k = 1}{v_k}$ (the product of elements);\n    \\item supposing that the elements of $v$ are the coefficients of a polynomial $P$ of degree $n - 1$, calculate the value $P(1.5)$ by a direct calculation of $P(x) = \\sum^{n}_{k = 1}{v_kx^{k - 1}}$ (i.e. evaluating each term one by one) and by Horner's method by representing the polynomial as $P(x) = v_1 + x(v_2 + x(v_3 + ...))$;\n    \\item Bubble Sort of the elements of $v$;\n    \\item Quick Sort of the elements of $v$;\n    \\item Timsort of the elements of $v$.\n\\end{itemize}\n\n\\paragraph{II.}\nGenerate random matrices $A$ and $B$ of size $n \\times n$ with non-negative elements. Find the usual matrix product for $A$ and $B$.\n\n\\paragraph{III.}\nDescribe the data structures and design techniques used within the algorithms.\n\n\\subsection{Brief theoretical part}\n\nTime complexity is characteristic of algorithm, which provides information about the amount of time necessary to process given amount of data.\n\nThe time complexity of the algorithm is estimated by counting the number of elementary operations (addition, multiplication, etc.) performed by the algorithm for a given amount of data. It is assumed that each elementary operation requires a fixed amount of time.\n\nA \\textbf{constant function}, \\textbf{the sum of elements}, \\textbf{the product of elements}, and \\textbf{the calculation of the polynomial} are calculated in a single pass through the loop.\nThey use an iterative strategy.\n\n\\textbf{Bubble sort} is a simple sorting algorithm.\nThis sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order.\nAn iterative pattern is also used here.\n\n\\textbf{Quick Sort} is a sorting algorithm, which is commonly used in computer science.\nQuick Sort is a divide and conquer algorithm.\nIt creates two empty arrays to hold elements less than the pivot value and elements greater than the pivot value, and then recursively sort the sub arrays.\nThere are two basic operations in the algorithm, swapping items in place and partitioning a section of the array.\n\n\\textbf{TimSort} is a stable, adaptive iterative merge sort that requires a small number of comparisons when working with partially sorted arrays, while providing performance comparable to traditional merge sorting when working with random arrays.\n\n\\subsection{Results}\n\n\\paragraph{Constant function $f(v) = 1$.}\n\nWith the exception of one peak, which is related to the computing platform, the theoretical and empirical estimates are the same - $O(1)$ (Figure \\ref{ris:constant_function}).\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/constant_function.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the function $f(v) = \\sum^{n}_{k = 1}{v_k}$.}\n    \\label{ris:constant_function}\n\\end{figure}\n\n\\paragraph{Sum and product of elements.}\n\nDespite the $y$-axis spikes, these functions are approximated by a straight line and coincide with the theoretical estimate - $O(n)$ (Figure \\ref{ris:sum_function}, \\ref{ris:prod_function}).\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/sum_function.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the function $f(v) = \\prod^{n}_{k = 1}{v_k}$.}\n    \\label{ris:sum_function}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/prod_function.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the function $P(x) = \\sum^{n}_{k = 1}{v_kx^{k - 1}}$.}\n    \\label{ris:prod_function}\n\\end{figure}\n\n\\paragraph{Calculation of the polynomial.}\n\nThe direct calculation and the Horner's method also correspond to the theoretical estimate - $O(n)$ (Figure \\ref{ris:naive_poly_function}, \\ref{ris:horner_method_function}). It is worth noting that the result, when calculated directly, despite the use of long arithmetic, overflows the buffer when the length of vector is $>1750$.\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/naive_poly_function.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that\nimplements the function $P(x) = \\sum^{n}_{k = 1}{v_kx^{k - 1}}$.}\n    \\label{ris:naive_poly_function}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/horner_method_function.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the function $P(x) = v_1 + x(v_2 + x(v_3 + ...))$.}\n    \\label{ris:horner_method_function}\n\\end{figure}\n\n\\paragraph{Bubble Sort.}\n\nBubble sorting has an average time complexity of $O(n^2)$, which is shown on Figure \\ref{ris:bubble_sort}.\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/bubble_sort.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the Bubble Sort.}\n    \\label{ris:bubble_sort}\n\\end{figure}\n\n\\paragraph{Quick Sort and TimSort.}\n\nQuick sort and Timsort in the average case have a theoretical complexity of $O(n\\log{n})$ and are approximated by linear functions . This is confirmed by an empirical experiment (Figure \\ref{ris:quick_sort}, \\ref{ris:timsort}).\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/quick_sort.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that\nimplements the Quick Sort.}\n    \\label{ris:quick_sort}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/timsort.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the TimSort.}\n    \\label{ris:timsort}\n\\end{figure}\n\n\\paragraph{Matrix product.}\n\nIn the \\textit{numpy} library of the \\textit{Python} programming language, the \\textit{matmul} function implements a matrix product using the \\textit{Strassen} method and has a theoretical complexity of $O(n^{2.81})$ (Figure \\ref{ris:matmul}).\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/matmul.png}\n    \\caption{Empirical and theoretical time complexities of an algorithm that implements the matrix product.}\n    \\label{ris:matmul}\n\\end{figure}\n\n\\subsection{Conclusion}\n\nAs a result of this task, algorithms with different time complexity are implemented.\nIt is shown that the empirical time for the algorithms described above coincides with the theoretical time.\nStrategies for implementing algorithms are also described.\n\n\\subsection{Appendix}\n\nThe source code is located \\href{https://github.com/vanSultan/anal_dev_algo/tree/lab_01}{here}: \\url{https://github.com/vanSultan/anal_dev_algo/tree/lab_01}.\n", "meta": {"hexsha": "b879b8c4b90b451ac66e7609a0d7cf03fd89462c", "size": 7515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab_01/report/lab_01_body.tex", "max_stars_repo_name": "vanSultan/anal_dev_algo", "max_stars_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab_01/report/lab_01_body.tex", "max_issues_repo_name": "vanSultan/anal_dev_algo", "max_issues_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab_01/report/lab_01_body.tex", "max_forks_repo_name": "vanSultan/anal_dev_algo", "max_forks_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_forks_repo_licenses": ["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.1, "max_line_length": 334, "alphanum_fraction": 0.7552894212, "num_tokens": 1880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.6136678994385647}}
{"text": "% !TEX root = hott_intro.tex\n\n\\section{Propositions, sets, and the higher truncation levels}\n\\sectionmark{Truncation levels}\\label{chap:hierarchy}\n\n\\index{truncated type|(}\n\\index{truncation level|(}\n%Not all types have interesting higher groupoid structure. For example, we will see below that two natural numbers can only be equal in at most one way. Voevodsky articulated a useful notion to detect the homotopical complexity of types, which allows us to distinguish between contractible types (also called \\emph{$(-2)$-types}), \\emph{propositions} (also called \\emph{$(-1)$-types}), \\emph{sets} (\\emph{$0$-types}), and \\emph{$k$-types} for higher $k$.\n\n%We will see [later] that there are types that are not $k$-types for any $k$.\n\n\\subsection{Propositions and subtypes}\n\n\\index{proposition|(}\n\\begin{defn}\nA type $A$ is said to be a \\define{proposition} if there is a term of type\\index{is-prop(A)@{$\\isprop(A)$}}\n\\begin{equation*}\n\\isprop(A)\\defeq\\prd{x,y:A}\\iscontr(x=y).\n\\end{equation*}\nGiven a universe $\\UU$, we define $\\prop_\\UU$\\index{Prop@{$\\prop$}} to be the type of all small propositions, i.e.,\n\\begin{equation*}\n  \\prop_\\UU\\defeq\\sm{X:\\UU}\\isprop(X).\n\\end{equation*}\n\\end{defn}\n\n\\begin{eg}\\label{eg:prop_contr}\n  Any contractible type is a proposition by \\cref{ex:prop_contr}\\index{contractible type!is a proposition}\\index{is a proposition!contractible type}. In particular, the unit type is a proposition.\n\n  However, propositions do not need to be inhabited: the empty type is also a proposition, since\\index{empty type!is a proposition}\\index{is a proposition!empty type}\n\\begin{equation*}\n\\prd{x,y:\\emptyt}\\iscontr(x=y)\n\\end{equation*}\nfollows from the induction principle of the empty type.\n\\end{eg}\n\nIn the following lemma we prove that in order to show that a type $A$ is a proposition, it suffices to show that any two terms of $A$ are equal. In other words, propositions are types with \\define{proof irrelevance}.\n\n\\begin{thm}\\label{lem:isprop_eq}\n  Let $A$ be a type. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The type $A$ is a proposition.\n  \\item Any two terms of type $A$ can be identified, i.e., there is a dependent function\\index{is-prop'(A)@{$\\isprop'(A)$}}\\index{is-prop(A)@{$\\isprop(A)$}!is-prop(A) iff is-prop'(A)@{$\\isprop(A)\\leftrightarrow\\isprop'(A)$}}\n    \\begin{equation*}\n      \\isprop'(A)\\defeq\\prd{x,y:A}\\id{x}{y}.\n    \\end{equation*}\n  \\item The type $A$ is contractible as soon as it is inhabited, i.e., there is a function\\index{is-prop(A)@{$\\isprop(A)$}!is-prop(A) iff A to is-contr(A)@{$\\isprop(A)\\leftrightarrow(A\\to\\iscontr(A))$}}\n    \\begin{equation*}\n      A \\to \\iscontr(A).\n    \\end{equation*}\n  \\item The map $\\const_\\ttt : A\\to\\unit$ is an embedding.\\index{is-prop(A)@{$\\isprop(A)$}!is-prop(A) iff is-emb(const star)@{$\\isprop(A)\\leftrightarrow\\isemb(\\const_\\ttt)$}}\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  To show that (i) implies (ii), let $A$ be a proposition. Then its identity types are contractible, so the center of contraction of $\\id{x}{y}$ is identification $\\id{x}{y}$, for each $x,y:A$. \n\n  To show that (ii) implies (iii), suppose that $A$ comes equipped with $p:\\prd{x,y:A}\\id{x}{y}$. Then for any $x:A$ the dependent function $p(x):\\prd{y:A}\\id{x}{y}$ is a contraction of $A$. Thus we obtain the function\n  \\begin{equation*}\n    \\lam{x}(x,p(x)):A\\to\\iscontr(A).\n  \\end{equation*}\n\n  To show that (iii) implies (iv), suppose that $A\\to\\iscontr(A)$. We first make the simple observation that\n  \\begin{equation*}\n    (X\\to \\isemb(f))\\to \\isemb(f)\n  \\end{equation*}\n  for any map $f:X\\to Y$, so it suffices to show that $A\\to\\isemb(\\const_\\ttt)$. However, assuming we have $x:A$, it follows by assumption that $A$ is contractible. Therefore, it follows by \\cref{ex:contr_equiv} that the map $\\const_\\ttt:A\\to\\unit$ is an equivalence. Since it is an equivalence, it is an embedding by \\cref{cor:emb_equiv}.\n\n  To show that (iv) implies (i), note that if $A\\to\\unit$ is an embedding, then the identity types of $A$ are equivalent to contractible types and therefore they must be contractible.\n\\end{proof}\n\nIn the following lemma we show that propositions are closed under equivalences.\n\n\\begin{lem}\\label{lem:prop_equiv}\nLet $A$ and $B$ be types, and let $e:\\eqv{A}{B}$. Then we have\\index{proposition!closed under equivalences}\n\\begin{equation*}\n\\isprop(A)\\leftrightarrow\\isprop(B).\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nWe will show that $\\isprop(B)$ implies $\\isprop(A)$. This suffices, because the converse follows from the fact that $e^{-1}:B\\to A$ is also an equivalence. \n\nSince $e$ is assumed to be an equivalence, it follows by \\cref{cor:emb_equiv} that\n\\begin{equation*}\n\\apfunc{e} : (x=y)\\to (e(x)=e(y))\n\\end{equation*}\nis an equivalence for any $x,y:A$. If $B$ is a proposition, then in particular the type $e(x)=e(y)$ is contractible for any $x,y:A$, so the claim follows from \\cref{thm:contr_equiv}.\n\\end{proof}\n\n  In set theory, a set $y$ is said to be a subset\\index{subset} of a set $x$, if any element of $y$ is an element of $x$, i.e., if the condition\n  \\begin{equation*}\n    \\forall_z (z\\in y)\\to (z\\in x)\n  \\end{equation*}\n  holds. We have already noted that type theory is different from set theory in that terms in type theory come equipped with a \\emph{unique} type. Moreover, in set theory the proposition $x\\in y$ is well-formed for any two sets $x$ and $y$, whereas in type theory the judgment $a:A$ is only well-formed if it is derived using the postulated inference rules. Because of these differences we must find a different way to talk about subtypes.\n\n  Note that in set theory there is a correspondence between the subsets of a set $x$, and the \\emph{predicates} on $x$. A predicate on $x$ is just a proposition $P(z)$ that varies over the elements $z\\in x$. Indeed, if $y$ is a subset of $x$, then the corresponding predicate is the proposition $z\\in y$. Conversely, if $P$ is a predicate on $x$, then we obtain the subset\n  \\begin{equation*}\n    \\{z\\in x\\mid P(z)\\}\n  \\end{equation*}\n  of $x$. Now we have the right idea of subtypes in type theory: they are families of propositions.\n\n\\begin{defn}\nA type family $B$ over $A$ is said to be a \\define{subtype}\\index{subtype} of $A$ if for each $x:A$ the type $B(x)$ is a proposition. When $B$ is a subtype of $A$, we also say that $B(x)$ is a \\define{property}\\index{property} of $x:A$.\n\\end{defn}\n\nWe will show in \\cref{thm:subtype} that a type family $B$ over $A$ is a subtype of $A$ if and only if the projection map $\\proj 1:\\big(\\sm{x:A}B(x)\\big)\\to A$ is an embedding.\n\n\\index{proposition|)}\n\n\\subsection{Sets}\n\n\\index{set|(}\n\\begin{defn}\n  A type $A$ is said to be a \\define{set} if it comes equipped with a term of type\n  \\index{is-set(A)@{$\\isset(A)$}}\\index{is a set}\n\\begin{equation*}\n\\isset(A)\\defeq \\prd{x,y:A}\\isprop(\\id{x}{y}).\n\\end{equation*}\n\\end{defn}\n\n\\begin{lem}\nA type $A$ is a set if and only if it satisfies \\define{axiom K}\\index{axiom K}, i.e., if and only if it comes equipped with a term of type\\index{is-set(A)@{$\\isset(A)$}!is-set(A) iff axiom-K(A)@{$\\isset(A)\\leftrightarrow\\axiomK(A)$}}\n\\begin{equation*}\n\\axiomK(A)\\defeq\\prd{x:A}\\prd{p:\\id{x}{x}}\\id{\\refl{x}}{p}.\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nIf $A$ is a set, then $\\id{x}{x}$ is a proposition, so any two of its elements are equal. \nThis implies axiom $K$. \n\nFor the converse, if $A$ satisfies axiom $K$, then for any $p,q:\\id{x}{y}$ we have $\\id{\\ct{p}{q^{-1}}}{\\refl{x}}$, and hence $\\id{p}{q}$. This shows that $\\id{x}{y}$ is a proposition, and hence that $A$ is a set.\n\\end{proof}\n\n\\begin{thm}\\label{lem:prop_to_id}\nLet $A$ be a type, and let $R:A\\to A\\to\\UU$ be a binary relation on $A$ satisfying\n\\begin{enumerate}\n\\item Each $R(x,y)$ is a proposition,\n\\item $R$ is reflexive, as witnessed by $\\rho:\\prd{x:A}R(x,x)$,\n\\item There is a map\n  \\begin{equation*}\n    R(x,y)\\to (x=y)\n  \\end{equation*}\n  for each $x,y:A$.\n\\end{enumerate}\nThen any family of maps\n\\begin{equation*}\n\\prd{x,y:A}(\\id{x}{y})\\to R(x,y)\n\\end{equation*}\nis a family of equivalences. Consequently, the type $A$ is a set.\n\\end{thm}\n\n\\begin{proof}\nLet $f:\\prd{x,y:A}R(x,y)\\to(\\id{x}{y})$. \nSince $R$ is assumed to be reflexive, we also have a family of maps\n\\begin{equation*}\n\\pathind_x(\\rho(x)):\\prd{y:A}(\\id{x}{y})\\to R(x,y).\n\\end{equation*}\nSince each $R(x,y)$ is assumed to be a proposition, it therefore follows that each $R(x,y)$ is a retract of $\\id{x}{y}$. Therefore it follows that $\\sm{y:A}R(x,y)$ is a retract of $\\sm{y:A}x=y$, which is contractible. We conclude that $\\sm{y:A}R(x,y)$ is contractible, and therefore that any family of maps\n\\begin{equation*}\n  \\prd{y:A}(x=y)\\to R(x,y)\n\\end{equation*}\nis a family of equivalences.\n\nNow it also follows that $A$ is a set, since its identity types are equivalent to propositions, and therefore they are propositions by \\cref{lem:prop_equiv}. \n\\end{proof}\n\n\\begin{defn}\n  A map $f:A\\to B$ is said to be \\define{injective}\\index{injective function} if for any $x,y:A$ there is a map\n  \\begin{equation*}\n    (f(x)=f(y))\\to (x=y).\n  \\end{equation*}\n\\end{defn}\n\n\\begin{cor}\\label{cor:is-emb-is-injective}\n  Any injective map into a set is an embedding.\\index{is an embedding!injective map into a set}\n\\end{cor}\n\n\\begin{proof}\n  Let $f:A\\to B$ be an injective map between sets. Now consider the relation\n  \\begin{equation*}\n    R(x,y)\\defeq (f(x)=f(y)).\n  \\end{equation*}\n  Note that $R$ is reflexive, and that $R(x,y)$ is a proposition for each $x,y:A$. Moreover, by the assumption that $f$ is injective, we have\n  \\begin{equation*}\n    R(x,y)\\to (x=y)\n  \\end{equation*}\n  for any $x,y:A$. Therefore we are in the situation of \\cref{lem:prop_to_id}, so it follows that the map $\\apfunc{f} : (x=y)\\to (f(x)=f(y))$ is an equivalence.\n\\end{proof}\n\n\\begin{thm}\\label{thm:eq_nat}\nThe type of natural numbers is a set.\\index{is a set!natural numbers}\\index{natural numbers!is a set}\n\\end{thm}\n\n\\begin{proof}\nWe will apply \\cref{lem:prop_to_id}. Note that the observational equality $\\EqN:\\N\\to(\\N\\to\\UU)$ on $\\N$ (\\cref{defn:obs_nat}) is a reflexive relation by \\cref{ex:obs_nat_eqrel}, and moreover that $\\EqN(n,m)$ is a proposition for every $n,m:\\N$ (proof by double induction).\nTherefore it suffices to show that\n\\begin{equation*}\n\\prd{m,n:\\N}\\EqN(m,n)\\to (\\id{m}{n}).\n\\end{equation*}\nThis follows from the fact that observational equality is the \\emph{least} reflexive relation, which was shown in \\cref{ex:obs_nat_least}.\n\\end{proof}\n\n\\begin{comment}\n\\begin{thm}[Hedberg]\\label{thm:dec_eq}\nAny type with decidable equality is a set.\n\\end{thm}\n\n\\begin{proof}\nLet $A$ be a type, and let $d:\\prd{x,y:A}(\\id{x}{y})+\\neg(\\id{x}{y})$ be the witness that $A$ has decidable equality.\nWe first construct a reflexive binary relation $E:A\\to A\\to\\type$ such that each $E(x,y)$ is a proposition.\nFor every $x,y:A$, we first define a type family $E'(x,y):((\\id{x}{y})+\\neg(\\id{x}{y}))\\to\\type$ by\n\\begin{align*}\nE'(x,y,\\inl(p)) & \\defeq \\unit \\\\\nE'(x,y,\\inr(p)) & \\defeq \\emptyt.\n\\end{align*}\nNote that $E'(x,y,q)$ is a proposition for each $x,y:A$ and $q:(\\id{x}{y})+\\neg(\\id{x}{y})$. \nNow we set $E(x,y)\\defeq E'(x,y,d(x,y))$. Then $E$ is clearly reflexive, and a family of propositions.\nTherefore it remains to show that $E$ implies identity. \n\nSince $E$ is defined as an instance of $E'$, it suffices to construct a term of type\n\\begin{equation*}\n\\prd{x,y:A}\\prd{q:(\\id{x}{y})+\\neg(\\id{x}{y})} E'(q)\\to (\\id{x}{y}). \n\\end{equation*}\nBy induction of disjoint sums, it suffices to construct terms of types\n\\begin{align*}\n& \\prd{x,y:A}\\prd{p:\\id{x}{y}} \\unit\\to (\\id{x}{y}) \\\\\n& \\prd{x,y:A}\\prd{p:\\neg(\\id{x}{y})} \\emptyt\\to (\\id{x}{y}).\n\\end{align*}\nIn the first case, we take $\\lam{x}\\lam{y}\\lam{p}{t}p$, and the second case is by induction on the empty type.\n\\end{proof}\n\\end{comment}\n\\index{set|)}\n\n\\subsection{General truncation levels}\n\n\\begin{defn}\nWe define $\\istrunc{} : \\Z_{\\geq-2}\\to\\UU\\to\\UU$ by induction on $k:\\Z_{\\geq -2}$, taking\\index{is-trunc k(A)@{$\\istrunc{k}(A)$}}\n\\begin{align*}\n\\istrunc{-2}(A) & \\defeq \\iscontr(A) \\\\\n\\istrunc{k+1}(A) & \\defeq \\prd{x,y:A}\\istrunc{k}(\\id{x}{y}).\\qedhere\n\\end{align*}\nFor any type $A$, we say that $A$ is \\define{$k$-truncated}\\index{k-truncated type@{$k$-truncated type}|see {truncated type}}, or a \\define{$k$-type}\\index{k-type@{$k$-type}}, if there is a term of type $\\istrunc{k}(A)$. We say that a map $f:A\\to B$ is $k$-truncated if its fibers are $k$-truncated.\\index{k-truncated map@{$k$-truncated map}|see {truncated map}}\\index{truncated map}\n\\end{defn}\n\n%For the rest of this section, let $k:\\Z_{\\geq-2}$.\n\n\\begin{thm}\\label{thm:istrunc_next}\nIf $A$ is a $k$-type, then $A$ is also a $(k+1)$-type.\\index{is-trunc k(A)@{$\\istrunc{k}(A)$}!is-trunc k(A) to is-trunc k+1(A)@{$\\istrunc{k}(A)\\to\\istrunc{k+1}(A)$}}\n\\end{thm}\n\n\\begin{proof}\nWe have seen in \\cref{eg:prop_contr} that contractible types are propositions. This proves the base case.\nFor the inductive step, note that if any $k$-type is also a $(k+1)$-type, then any $(k+1)$-type is a $(k+2)$-type, since its identity types are $k$-types and therefore $(k+1)$-types.\n\\end{proof}\n\n\\begin{thm}\\label{thm:ktype_eqv}\nIf $e:\\eqv{A}{B}$ is an equivalence, and $B$ is a $k$-type, then so is $A$.\\index{truncated type!closed under equivalences}\n\\end{thm}\n\n\\begin{proof}\nWe have seen in \\cref{ex:contr_equiv} that if $B$ is contractible and $e:\\eqv{A}{B}$ is an equivalence, then $A$ is also contractible. This proves the base case.\n\nFor the inductive step, assume that the $k$-types are stable under equivalences, and consider $e:\\eqv{A}{B}$ where $B$ is a $(k+1)$-type. In \\cref{cor:emb_equiv} we have seen that\n\\begin{equation*}\n\\apfunc{e}:(\\id{x}{y})\\to(\\id{e(x)}{e(y)})\n\\end{equation*}\nis an equivalence for any $x,y$. Note that $\\id{e(x)}{e(y)}$ is a $k$-type, so by the induction hypothesis it follows that $\\id{x}{y}$ is a $k$-type. This proves that $A$ is a $(k+1)$-type.\n\\end{proof}\n\n\\begin{cor}\\label{cor:emb_into_ktype}\nIf $f:A\\to B$ is an embedding, and $B$ is a $(k+1)$-type, then so is $A$.\\index{truncated type!closed under embeddings}\n\\end{cor}\n\n\\begin{proof}\nBy the assumption that $f$ is an embedding, the action on paths\n\\begin{equation*}\n\\apfunc{f}:(\\id{x}{y})\\to (\\id{f(x)}{f(y)})\n\\end{equation*}\nis an equivalence for every $x,y:A$. Since $B$ is assumed to be a $(k+1)$-type, it follows that $f(x)=f(y)$ is a $k$-type for every $x,y:A$. Therefore we conclude by \\cref{thm:ktype_eqv} that $\\id{x}{y}$ is a $k$-type for every $x,y:A$. In other words, $A$ is a $(k+1)$-type.\n\\end{proof}\n\n\\begin{thm}\nLet $B$ be a type family over $A$. Then the following are equivalent:\\index{truncated family of types}\n\\begin{enumerate}\n\\item For each $x:A$ the type $B(x)$ is $k$-truncated. In this case we say that the family $B$ is \\define{$k$-truncated}.\n\\item The projection map\n\\begin{equation*}\n\\proj 1 : \\Big(\\sm{x:A}B(x)\\Big)\\to A\n\\end{equation*}\nis $k$-truncated.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nBy \\cref{ex:proj_fiber} we obtain equivalences\n\\begin{equation*}\n\\eqv{\\fib{\\proj 1}{x}}{B(x)}\n\\end{equation*}\nfor every $x:A$. Therefore the claim follows from \\cref{thm:ktype_eqv}.\n\\end{proof}\n\n\\begin{thm}\\label{thm:trunc_ap}\nLet $f:A\\to B$ be a map. The following are equivalent:\n\\begin{enumerate}\n\\item The map $f$ is $(k+1)$-truncated.\n\\item For each $x,y:A$, the map\n\\begin{equation*}\n\\apfunc{f} : (x=y)\\to (f(x)=f(y))\n\\end{equation*}\nis $k$-truncated. \n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nFirst we show that for any $s,t:\\fib{f}{b}$ there is an equivalence\n\\begin{equation*}\n\\eqv{(s=t)}{\\fib{\\apfunc{f}}{\\ct{\\proj 2(s)}{\\proj 2(t)^{-1}}}}\n\\end{equation*}\nWe do this by $\\Sigma$-induction on $s$ and $t$, and then we calculate\n\\begin{align*}\n(\\pairr{x,p}=\\pairr{y,q}) & \\eqvsym \\Eqfib_f((x,p),(y,q)) \\\\\n  & \\jdeq \\sm{\\alpha:x=y} p=\\ct{\\ap{f}{\\alpha}}{q} \\\\\n  & \\eqvsym \\sm{\\alpha:x=y} \\ct{\\ap{f}{\\alpha}}{q}=p \\\\\n& \\eqvsym \\sm{\\alpha:x=y} \\ap{f}{\\alpha}=\\ct{p}{q^{-1}} \\\\\n& \\jdeq \\fib{\\apfunc{f}}{\\ct{p}{q^{-1}}}.\n\\end{align*}\nBy these equivalences, it follows that if $\\apfunc{f}$ is $k$-truncated, then for each $s,t:\\fib{f}{b}$ the identity type $s=t$ is equivalent to a $k$-truncated type, and therefore we obtain by \\cref{thm:ktype_eqv} that $f$ is $(k+1)$-truncated.\n\nFor the converse, note that we have equivalences\n\\begin{align*}\n\\fib{\\apfunc{f}}{p} & \\eqvsym ((x,p)=(y,\\refl{f(y)})).\n\\end{align*}\nIt follows that if $f$ is $(k+1)$-truncated, then the identity type $(x,p)=(y,\\refl{f(y)})$ in $\\fib{f}{f(y)}$ is $k$-truncated for any $p:f(x)=f(y)$. We conclude by \\cref{thm:ktype_eqv} that the fiber $\\fib{\\apfunc{f}}{p}$ is $k$-truncated. \n\\end{proof}\n\n\\begin{cor}\\label{cor:prop_emb}\nA map is an embedding if and only if its fibers are propositions.\\index{is an embedding!-1-truncated map@{$(-1)$-truncated map}}\n\\end{cor}\n\n\\begin{cor}\\label{thm:subtype}\nA type family $B$ over $A$ is a subtype if and only if the projection map\n\\begin{equation*}\n\\proj 1 : \\Big(\\sm{x:A}B(x)\\Big)\\to A\n\\end{equation*}\nis an embedding.\n\\end{cor}\n\n\\begin{thm}\nLet $f:\\prd{x:A}B(x)\\to C(x)$ be a family of maps. Then the following are equivalent:\n\\begin{enumerate}\n\\item For each $x:A$ the map $f(x)$ is $k$-truncated.\n\\item The induced map \n\\begin{equation*}\n\\tot{f}:\\Big(\\sm{x:A}B(x)\\Big)\\to\\Big(\\sm{x:A}C(x)\\Big)\n\\end{equation*}\nis $k$-truncated.\n\\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\nThis follows directly from \\cref{lem:fib_total,thm:ktype_eqv}.\n\\end{proof}\n\n\\begin{exercises}\n\\exercise\n  \\begin{subexenum}\n  \\item Show that $\\succN:\\N\\to\\N$ is an embedding.\\index{succ N@{$\\succN$}!is an embedding}\\index{is an embedding!succ N@{$\\succN$}}\n  \\item Show that $n\\mapsto m+n$ is an embedding, for each $m:\\N$.\\index{add N@{$\\addN$}!add N(m) is an embedding@{$\\addN(m)$ is an embedding}}\\index{is an embedding!add N(m)@{$\\addN(m)$}} Moreover, conclude that there is an equivalence\n    \\begin{equation*}\n      \\fib{\\addN(m)}{n}\\simeq (m\\leq n).\n    \\end{equation*}\n  \\item Show that $n\\mapsto mn$ is an embedding\\index{mul N@{$\\mulN$}!mul N(m) is an embedding if m>0@{$\\mulN(m)$ is an embedding if $m>0$}}\\index{is an embedding!mul N(m) for m > 0@{$\\mulN(m)$ for $m>0$}}, for each $m>0$ in $\\N$. Conclude that the divisibility relation\\index{d {\"| n}@{$d\\mid n$}!is a proposition if d>0@{is a proposition if $d>0$}}\\index{is a proposition!d {\"| n} for d>0@{$d\\mid n$ for $d>0$}}\n    \\begin{equation*}\n      d\\mid n\n    \\end{equation*}\n    is a proposition for each $d,n:\\N$ such that $d>0$. \n  \\end{subexenum}\n\\exercise \\label{ex:diagonal}Let $A$ be a type, and let the \\define{diagonal} of $A$ be the map $\\delta_A:A\\to A\\times A$ given by $\\lam{x}(x,x)$. \n\\begin{subexenum}\n\\item Show that\n\\begin{equation*}\n{\\isequiv(\\delta_A)}\\leftrightarrow{\\isprop(A)}.\n\\end{equation*}\n\\item Construct an equivalence $\\eqv{\\fib{\\delta_A}{(x,y)}}{(x=y)}$ for any $x,y:A$.\n\\item Show that $A$ is $(k+1)$-truncated if and only if $\\delta_A:A\\to A\\times A$ is $k$-truncated.\n\\end{subexenum}\n\\exercise \\label{ex:istrunc_sigma}\n\\begin{subexenum}\n\\item Let $B$ be a type family over $A$. Show that if $A$ is a $k$-type, and $B(x)$ is a $k$-type for each $x:A$, then so is $\\sm{x:A}B(x)$. Conclude that for any two $k$-types $A$ and $B$, the type $A\\times B$ is also a $k$-type. Hint: for the base case, use \\cref{ex:contr_in_sigma,ex:contr_equiv}.\n\\item Show that for any $k$-type $A$, the identity types of $A$ are also $k$-types.\n\\item Show that any maps $f:A\\to B$ between $k$-types $A$ and $B$\nis a $k$-truncated map.\n\\item Use \\cref{ex:proj_fiber} to show that for any type family $B:A\\to \\UU$, if $A$ and $\\sm{x:A}B(x)$ are $k$-types, then so is $B(x)$ for each $x:A$. \n\\end{subexenum}\n\\exercise \\label{ex:eq_bool}Show that $\\bool$ is a set by applying \\cref{lem:prop_to_id} with the observational equality on $\\bool$ defined in \\cref{ex:obs_bool}.\n\\exercise \\label{ex:set_coprod}Show that for any two $(k+2)$-types $A$ and $B$, the disjoint sum $A+B$ is again a $(k+2)$-type. Conclude that $\\mathbb{Z}$ is a set.\n\\exercise Use \\cref{ex:contr_retr,ex:retr_id} to show that if $A$ is a retract of a $k$-type $B$, then $A$ is also a $k$-type.\n\\exercise Show that a type $A$ is a $(k+1)$-type if and only if the map $\\const_x:\\unit\\to A$ is $k$-truncated for every $x:A$.\n\\exercise 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$, and suppose that $g$ is $k$-truncated. Show that $f$ is $k$-truncated if and only if $h$ is $k$-truncated.\n% Suppose that $h$ is $k$-truncated and surjective. Show that $f$ is $(k+1)$-truncated if and only if $g$ is $(k+1)$-truncated.\n\\end{exercises}\n\\index{truncated type|)}\n\\index{truncation level|)}\n", "meta": {"hexsha": "b04152f7e04556b6edbaa33bc65ba600638d3e60", "size": 20697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/hierarchy.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/hierarchy.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/hierarchy.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": 50.2354368932, "max_line_length": 454, "alphanum_fraction": 0.6751703145, "num_tokens": 7296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.6136678877288783}}
{"text": "% !TEX root = index.tex\n\\maketitle\n\\tableofcontents\n\\newpage\n\n\\setcounter{section}{-1}\n\\section{Introduction \\& Motivation}\n\\epigraph{In mathematics you don't understand things. You just get used to them.}{John von Neumann}\n\nCohomology was introduced by Poincare in a series of papers named \\emph{Analysis Situs} and now forms the basis of modern Algebraic Topology.\nTo a topological space $X$ we can associate a sequence of vector spaces denoted\n\\begin{align*}\n    \\check H^i(X)\n\\end{align*}\nfor each $i \\in \\Z_{\\ge 0}$ called it's \\textbf{Cech Cohomology} (pronounced \\emph{check cohomology}). In a very loose sense, the dimension of  $\\check H^i(X)$ measures the $i^{th}$ dimensional holes in $X$.\\\\\n\nWhy care about the $i^{th}$ dimensional holes? We can use these to rigorously distinguish between spaces. For example, most proofs of the fact that $\\R^m$ is not homeomorphic\\footnote{Homeomorphism is the isomorphism for topological spaces.} to $\\R^n$ if $m \\neq n$ use some cohomology computation. We'll also see that a torus $S^1 \\times S^1$ has two \\emph{1-dimensional holes} which distinguishes it from a sphere $S^2$ which has none.\n\n\\begin{thm}\n  Two topological spaces $X$, $Y$ are homeomorphic only if\n  \\begin{align*}\n    \\check H^i(X) \\cong \\check H^i(Y)\n  \\end{align*} for all non-negative integers $i$.\n\\end{thm}\n\\begin{remark}\n  The above statement is not an \\emph{if and only if} statement. The other direction is easily shown to be false. You'll be able to come up with examples by yourself in a couple of days.\n\\end{remark}\n\nComputing the cohomology requires multiple steps. The goal of this class is to develop the relevant machinery and actually do some cohomology computations.\n\\begin{align*}\n \\xymatrix@R-2pc{\n X \\ar@{~>}[r] & \\U \\ar@{~>}[r] & \\L^\\bullet(\\U) \\ar@{~>}[r] & \\check H^*(X)\\\\\n \\mbox{Topological Space} & \\mbox{Good cover of } X & \\mbox{Cech Complex of } \\U & \\mbox{Cech Cohomology of } X\n }\n\\end{align*}\n\n\\noindent \\textbf{Note:} The number of stars (*) on the problems indicate their difficulty level. The non-starred marked problems are compulsory, the starred problems are optional.\n\n% We'll gradually define Cech cohomology. The strategy is the following.\n% \\begin{enumerate}\n% \t\\item For a space $ X$, find a good open cover $ \\U$\n% \t\\item Find the Cech complex (to be defined) $ \\L^\\bullet(\\U)$ associated $ \\U$\n% \t\\item Find the cohomology of the complex $H^*(\\L^\\bullet(\\U))$ which then equals the singular cohomology of the space $H^*(X, \\F)$.\n% \\end{enumerate}\n%\n% \\begin{remark}\n% \tWhen $X$ is a nice enough space (which includes most spaces you can think of) the Cech cohomology $\\check H^i(X; \\F)$ equals another purely topological invariant of $X$ called the \\textbf{singular homology}. And thus Cech cohomology provides a purely algebraic way of computing a topological invariant.\n% \\end{remark}\n", "meta": {"hexsha": "f8eae96ed04fe42c491405f0db321b733c74caa1", "size": 2848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "00.tex", "max_stars_repo_name": "apurvnakade/mc2018-cohomology-via-sheaves", "max_stars_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_stars_repo_licenses": ["MIT"], "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/mc2018-cohomology-via-sheaves", "max_issues_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_issues_repo_licenses": ["MIT"], "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/mc2018-cohomology-via-sheaves", "max_forks_repo_head_hexsha": "46b9ad5b473f98d3f9bb41449fe691b6b14fd7f4", "max_forks_repo_licenses": ["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.1224489796, "max_line_length": 437, "alphanum_fraction": 0.7243679775, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6136457261124432}}
{"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\n\\begin{document}\n\\section*{Geometric inequalities}\n\t\\begin{enumerate}\n\t\t\\item %vorrat 48\n\t\tProve the inequalities for $x \\in \\left(\\frac{-\\pi}{2},\\frac{\\pi}{2}\\right)$\n\t\t$$|\\tan x| \\geq |x| \\geq |\\sin x| \\geq  \\frac{2}{\\pi}|x|$$\n\t\t\\item %vorrat 49\n\t\tProve the inequalities for $0 < \\alpha < \\beta < \\frac{\\pi}{2}$\n\t\t$$\\frac{\\sin \\beta}{\\sin \\alpha} < \\frac{\\beta}{\\alpha} < \\frac{\\tan \\alpha}{\\tan \\beta}$$\n\t\t\\item % vorrat 52\n\t\tProve the inequalities where $a,b,c$ are lengths of triangles sides\n\t\t\\begin{enumerate}\n\t\t\t\\item $a^2 + b^2 + c^2 < 2 (ab + bc + ca)$\n\t\t\t\\item $a^4 + b^4 + c^4 < 2 (a^2b^2 + b^2c^2 + c^2a^2)$\n\t\t\\end{enumerate}  \n\t\t\\item % vorrat 53\n\t\tProve that $R \\geq 2r$ given that $R$ is the radius of circumcircle and $r$ is the radius of incircle of a triangle.\t\n\t\t\\item \\emph{(Ptolemy's inequality).}\n\t\tProve the inequality for any four points $A,B,C,D$ on a plane\n\t\t$$AC \\cdot BD \\leq AB \\cdot CD + AD \\cdot BC$$\t\n\t\tWhen does the equality hold?\n\t\t\\item \\emph{(Erdős-Mordell inequality).} % vorrat 62\n\t\tLet $P$ be a point in the interior of $\\triangle ABC$ and $X$, $Y$,$Z$ projections of $P$ to $BC$,$AC$,$AB$ respectively. Prove that\n\t\t$$PA+PB+PC \\geq 2(PX+PY+PZ)$$\n\t\tWhen does the equality hold?\n\t\t\\item %vorrat 63\n\t\tPoints $A,B,C,X,Y,Z,P$ are defined as before. Prove that\n\t\t$$AP \\cdot BC + BP \\cdot AC + CP \\cdot AB \\geq 4S_{\\triangle ABC} $$\n\t\t\\item %vorrat 64\n\t\tPoints $A,B,C,X,Y,Z,P$ are defined as before. Prove that\n\t\t$$AP \\cdot XP + BP \\cdot YP + CP \\cdot ZP \\geq 2(XP \\cdot YP + YP \\cdot ZP + ZP \\cdot XP) $$\n\t\t\\item %vorrat 65, imo 96\n\t\tGiven a convex hexagon $ABCDEF$ such that $AB \\parallel DE$, $BC \\parallel EF$, $CD \\parallel FA$ and with perimeter $P$. Let $R_A, R_C, R_E$ be the radii of circles $FAB,BCD,DEF$ respectively. Prove that\n\t\t$$R_A + R_C + R_C \\geq \\frac{P}{2} $$\n\t\t\n\t\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "bd571c80fa87faf4e2298ee681a986a665541111", "size": 2101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15_geometric_inequalities.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": "15_geometric_inequalities.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": "15_geometric_inequalities.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": 42.8775510204, "max_line_length": 206, "alphanum_fraction": 0.6496906235, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6136457229329347}}
{"text": "\\chapter{Geostrophic balance and coastal flow}\n\\label{chap:geostrophic}\n\n\\includegraphics[width=6.5in]{figs/Geostrophic/HaidaEddy}\n\n\\section{Geostrophic balance}\n\nThe second balance that involves the Coriolis force is the \\Wikiref{Geostrophic balance}, and is when the Coriolis force is in ``balance'' with the pressure gradient:\n\n\\begin{equation}\n    \\frac{du}{dt} = \\overunderbraces{\\br{2}{geostrophic}}\n    {- \\frac{1}{\\rho_0}\\frac{dP}{dx} & +fv & + \\frac{1}{\\rho}\\frac{d\\tau_{xz}}{dz}}\n    {&\\br{2}{Ekman}}\n\\end{equation}\n\\begin{equation}\n    \\frac{dv}{dt} = \\overunderbraces{\\br{2}{geostrophic}}\n    {- \\frac{1}{\\rho_0}\\frac{dP}{dy} & -fu & + \\frac{1}{\\rho}\\frac{d\\tau_{yz}}{dz}}\n    {&\\br{2}{Ekman}}\n\\end{equation}\n\\begin{marginfigure}\n    \\includegraphics{figs/Geostrophic/BalanceSketch}\n    \\caption{Sketch of geostrophic force-balance for a sea-level high and a sea-level low in the northern hemisphere, looking from above, and from the south for the high.  The flow will be clockwise around a hight and counter-clockwise.}\n    \\label{fig:BalanceSketch}  \n\\end{marginfigure}\nin which case the equations of motion simplify to:\n\\begin{eqnarray*}\n    -\\frac{1}{\\rho_0}\\frac{dP}{dx} & \\approx & -fv\\\\\n    -\\frac{1}{\\rho_0}\\frac{dP}{dy} & \\approx & +fu\\\\    \n\\end{eqnarray*}\nIn the northern hemisphere ($f>0$) this says that water turns to the right as in moves from high pressure to low.  This gives a clockwise circulation around an isolated high, or a counter-clockwise around an isolated low (\\fref{fig:BalanceSketch})\n\nCrucially, if we know the pressure gradient, we can directly calculate the geostrophic flow perpendicular to that pressure gradient from the equations above.  So, suppose the high in the cover figure is 16 cm, over 100 km.  The pressure difference due to this flow gives us an estimate of the velocity (assuming $f = 10^{-4}\\ \\mathrm{rad\\,s^{-1}}$)\n\\begin{equation}\n  |u| = \\left|\\frac{1}{f\\rho} \\frac{dP}{dx}\\right| = \\frac{1}{f\\rho}\\frac{\\Delta P}{\\Delta x} = \\frac{g}{f} \\frac{\\eta_C - \\eta_E}{\\Delta x} \\approx 0.16 \\ \\mathrm{m\\,s^{-1}}\n\\end{equation}\n\nThe equation applies everywhere in the fluid, and is only made complex by the presence of water with different densities making the flow have a pressure gradient that changes with depth.  An observation of this can be seen in \\fref{fig:InteriorEddy}, where there is a sea-surface high in the middle, but the pressure gradient inside the eddy is the other direction.  This causes the pressure gradient force to decrease with depth, and hence the geostrophic flow decays with depth as well. \n\n\\begin{figure}\n\\begin{center}\n    \\includegraphics[width=2in]{figs/Geostrophic/InteriorEddy}\n    \\caption{Observations of density inside an Eddy.  Note how the density contours tend to counteract the high sea-surface height.  Blue circles with crosses are into the page, and with dots are out of the page, and the size is sketched to be proportional to the speed of the flow.}\n    \\label{fig:InteriorEddy}  \n\\end{center}\n\\end{figure}\n\nAs discussed in \\fref{chap:EquationofState}, calculating the pressure gradient is simply a matter of calculating the pressure at two locations, and differencing, where the pressure is given by:\n\\begin{equation}\n  P(z) / \\rho_0 = \\frac{1}{\\rho_0}\\int_z^\\eta \\rho g\\ \\mathrm{d}z \\approx g\\eta + \\frac{1}{\\rho_0}\\int_z^0 \\rho g\\ \\mathrm{d}z\n\\end{equation}\nSo imagine one flank of the eddy, and that the eddy is made of two densities $\\rho_1 < \\rho_2$ (\\fref{fig:CounterPressure}).  In the upper layer \n\\begin{equation}\n  -\\frac{1}{\\rho_0} \\frac{dP}{dx}(z=z_1) = -\\frac{1}{\\Delta x} g (\\eta_B - \\eta_A).\n\\end{equation}\nIn the lower layer, things are a bit more complicated, so we just do it step by step:\n\\begin{equation}\n  P_A(z=z_2) = \\rho_1 g (\\eta_A - Z_A) + \\rho_2 g (Z_A - z_2)\n\\end{equation}\n\\begin{equation}\n  P_B(z=z_2) = \\rho_1 g (\\eta_B - Z_B) + \\rho_2 g (Z_B - z_2)\n\\end{equation}\nSo the total pressure gradient in the lower layer is approximated as \n\\begin{equation}\n  -\\frac{1}{\\rho_0}\\frac{P_B - P_A}{\\Delta x} = \\overbrace{-\\frac{1}{\\Delta x} g (\\eta_B - \\eta_A)}^{Surface} - \\overbrace{\\frac{1}{\\Delta x} g \\frac{\\left(\\rho_2 - \\rho_1\\right)}{\\rho_0} (Z_B - Z_A)}^{Internal}\n  \\label{eq:InternalExternal}\n\\end{equation}\n\nAccording to the geostrophic balance, then, the flow in the upper layer is into the page, and the one in the bottom layer is either into the page, but more slow, or even out of the page.  \n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics{figs/Geostrophic/CounterPressure}\n    \\caption{Two-layer approximation of pressure gradients in an eddy.}\n    \\label{fig:CounterPressure}  \n  \\end{center}\n\\end{figure}\n\n\\subsection{Thermal wind}\n\nThe example above makes it clear that lateral density differences can drive velocity differences in the vertical if the flow is in geostrophic balance.  This can easily be extended to the continuous case with some  manipulation of the momentum equations.  If we take the vertical derivative of the x- and y-momentum equations we arrive at:\n\\begin{eqnarray}\n    -\\frac{1}{\\rho_0}\\frac{d^2 P}{dx dz} & = & -f \\frac{dv}{dz} \\\\\n    -\\frac{1}{\\rho_0}\\frac{d^2 P}{dy dz} & = & f \\frac{du}{dz} \n\\end{eqnarray}\nbut $P = \\int_z^{\\eta}\\rho g \\mathrm{d}z$,  so we get the \\Wikiref{thermal wind} relation.\n\\begin{eqnarray}\n    -\\frac{1}{\\rho_0}\\frac{d \\rho}{dx} & = & -f \\frac{dv}{dz} \\\\\n    -\\frac{1}{\\rho_0}\\frac{d \\rho}{dy} & = & f \\frac{du}{dz} \n\\end{eqnarray}\nso, if we know the horizontal pressure gradient, we can immediately say how the velocity changes with depth (though we do not know the absolute velocity).  \n\n\\subsection{Level of no motion and ``dynamic height''}\n\nBack in the pre-satellite days, all oceanographers would have would be measurements of the density under the ocean, like those in \\fref{fig:InteriorEddy}.  Estimating the sea-surface height was impossible; imagine detecting 15 cm over 100 km in an ocean that is otherwise also moving due to tides, surface waves, relative to a poorly-constrained geoid.  However, oceanographers noted that most ocean currents, like the eddy, had tilted density surfaces, and that the currents at depth go to approximately zero.  \n\nUnder these assumptions, oceanographers would assume that the pressure gradient at a ``level of no motion'' was zero, so that the geostrophic flow was zero there as well. In order to get this level of no motion the  pressure  gradients inferred from the interior density measurements were assumed to be balanced by a pressure gradient from the surface at that depth.  So, for instance, in the simple two-layer case the \\fref{eq:InternalExternal}, the \\emph{Surface} term was equal and opposite in sign to the \\emph{Internal} term, if the deep layer was assumed to be not moving.  Note that this allows an estimate of the surface pressure gradient, and using the geostrophic balance, the surface velocities.  This surface pressure gradient is of course supplied by the sealevel interface being tilted, and  calculating these gradients is like calculating a ``dynamic height'' of the ocean.  \n\nAn example in \\fref{fig:DynamicHeight}, calculated in the 1980s looks strikingly similar to the sea surface heights in \\fref{chap:winddriven}.  In particular, where there is Ekman convergence in the subtropics there is a high of up to 2 m, and a low in the sub-polar regions where there is Ekman divergence.  The highs and lows are displaced to the west sides of the basins.  The steepest change in dynamic height correspond to the strongest currents, again largely concentrated on the west side of the basins, and associated with the Gulf Stream, Kurishio, East Australian current etc.  \n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics{figs/Geostrophic/DynamicHeight1500}\n    \\includegraphics{figs/Geostrophic/DynamicHeight2500}\n    \\caption{Dynamic height with a level of no motion at 1500 m (top) and 2500 m (bottom).  Note these are quite similar, strongly indicative that the dynamics are largely above these depths.  }\n    \\label{fig:DynamicHeight}  \n  \\end{center}\n\\end{figure}\n\nJust to summarize again how this is done:\n\\begin{enumerate}\n    \\item An interior pressure gradient is calculated at two ``stations'' as a function of depth using the density data from CTDs or other measurements.\n    \\item At a ``depth of no motion'' the pressure gradient is assumed to be zero, so a surface pressure gradient is added to the two points to make that be the case.\n    \\item If there are multiple stations in a line the surface pressure gradient is integrated to make a dynamic height with an arbitrary zero at some location. \n\\end{enumerate}\n \nWe will come back to \\emph{why} the dynamic height looks the way it does in the next chapter.\n\n\\section{Coastal upwelling, complete picture}\n\nUsing the Ekman and geostrophic balances we are now in a position to explain the coastal upwelling example in detail (i.e. \\fref{fig:PerlinFig3a}, one snapshot in detail in \\fref{fig:ShelfDetail}). \n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics{figs/Geostrophic/ShelfDetail}\n    \\caption{Data from \\fref{fig:PerlinFig3a}.}\n    \\label{fig:ShelfDetail}  \n  \\end{center}\n\\end{figure}\n\nFirst, the wind starts to blow towards the south; this sets up a southwards windstress $\\tau_y^w$ (\\fref{fig:CoastalStep1}, red circle).  When this flow is in a steady-state Ekman balance there will be an equal and opposite Coriolis force to the north (\\fref{fig:CoastalStep1}, magenta circle).  That implies an offshore Ekman transport to the west given by \n\\begin{equation}\n  u_{Ek}D = \\frac{\\tau_y^w}{\\rho_0 f}\n\\end{equation}\n\n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics[width=2.85in]{figs/Geostrophic/CoastalStep1}\n    \\caption{On a continental slope, initially at rest, a wind stress blows from north to south (dotted red circle)}\n    \\label{fig:CoastalStep1}  \n  \\end{center}\n\\end{figure}\n\nThe offshore Ekman transport drops the sealevel at the coast (\\fref{fig:CoastalStep2}, surface interface).   This creates a surface pressure gradient force that acts to push water back towards the coast (\\fref{fig:CoastalStep2}, red arrow).  Again, in \\emph{steady state} geostrophic balance, the pressure gradient force is balanced by a Coriolis force offshore, which must be generated by a geostrophic velocity to the south.  Note that this evolves in time with the deep water \\emph{initially} moving onshore, but then being turned south (to the right) by the Coriolis force.  \n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics[width=2.85in]{figs/Geostrophic/CoastalStep2}\n    \\caption{After the Ekman transport has been active for a while, the sea level drops at the coast (green surface), and an interior geostrophic balanced flow is set up.}\n    \\label{fig:CoastalStep2}  \n  \\end{center}\n\\end{figure}\n\nAt this point the flow cannot be in steady state because we are transporting water offshore in the surface Ekman layer, but not having any onshore transport to replace it.  Without this return flow, the sea surface will continue to increase its tilt.  The return flow happens in the bottom Ekman layer.  The interior geostrophic flow moves south, so there is a corresponding bottom stress to the north $\\tau_y^B$(\\fref{fig:CoastalStep3}, red circle at bottom).  In a steady Ekman balance, this implies a Coriolis force to the south, which implies a net Ekman transport onshore (\\fref{fig:CoastalStep3}, blue arrows, bottom), given by \n\\begin{equation}\n  u_{Ek}D = \\frac{\\tau_y^B}{\\rho_0 f}\n\\end{equation}\n\nThe offshore Ekman transport drops the sealevel at the coast (\\fref{fig:CoastalStep3})\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics[width=2.85in]{figs/Geostrophic/CoastalStep3}\n    \\caption{}\n    \\label{fig:CoastalStep3}  \n  \\end{center}\n\\end{figure}\n\nWhen is the whole flow balanced?  When $\\tau^B = \\tau^W$ so that the transport in the bottom Ekman layer is the same as the transport in the surface Ekman layer.  So, if we know the wind stress, and have a good estimate of the bottom \\Wikiref{drag co-efficient}, $C_D\\approx10^{-3}$, then we can guess what the mean geostrophic velocity is, and hence the size of the sea surface tilt.  For the Oregon shelf, $\\tau_y^W\\approx -0.15\\ \\mathrm{N\\,m^{-2}}$ (minus means to the south).  Than means that the geostrophic velocity $v_g \\approx 0.35\\ \\mathrm{m\\,s^{-1}}$ in order for $\\rho_0 C_D |v_g|^2$ to be large enough to provide the bottom stress to match.  This is approximately the same as the observations near the bottom.  \n\nWe can further calculate the sea-surface height drop across the 20-km width of the shelf from $g \\frac{d\\eta}{dx} = f v_g$ or $\\Delta \\eta =  0.08\\ \\mathrm{m}$ across the shelf.  \n\n\\subsection{Internal dynamics on shelf}\n\nThe final thing we notice about the shelf observations is that the  flow is slower towards the sea-floor than at the surface.  This is also largely explained by the geostrophic balance.  Note that the isopycnals tilt up towards the coast, counteracting the surface pressure gradient (also sketched in \\fref{fig:CoastalTilt}).  This means that the surface tilt is actually larger than we calculated above if the bottom velocity is to remain $0.38\\ \\mathrm{m\\,s^{-1}}$, leading to faster velocities near the surface.  \n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics[width=2.85in]{figs/Geostrophic/CoastalTilt}\n        \\caption{Sketch of pressure gradient changes if there are titled isopycnals (cyan line) in the section, as observed in the coastal data.  The tilted isopycnal counteracts the surface tilt, slowing the barotropic flow.  }\n    \\label{fig:CoastalTilt}  \n  \\end{center}\n\\end{figure}\n\n\\clearpage\n\\section{Exercises}\n\n\\paragraph{Geostrophic balance two stations}\n\nCalculate the geostrophic flow at two stations 50 km apart, assuming $f=10^{-4}\\ \\mathrm{rad\\,s^{-1}}$.  \nApproximate the density measured at each location as 50-m blocks of homogeneous density:\n\n\\begin{tabular}{l|cc}\n  $z\\ \\mathrm{[m]}$ & $\\rho_A \\mathrm{[kg\\,m^{-3}]}$ & $\\rho_B \\mathrm{[kg\\,m^{-3}]}$ \\\\\n  \\hline\n  0--50 & 1021& 1020 \\\\\n  50--100& 1022& 1021\\\\\n  100--150& 1024& 1023\\\\\n  150--200& 1025& 1024\\\\  \n\\end{tabular}\n\n\\begin{itemize}\n  \\item If the surface pressure gradient is zero, what is the internal pressure gradient at 50, 100, 150, and 200 m? (do not drop too many decimal places!)\n  \\item What is the direction and strength of the \\emph{geostrophic} velocity at the 4 depths?\n  \\item If there is a pressure gradient, what must its direction and strength be so that the geostrophic flow is zero at 200 m?\n  \\item How large must the surface difference be at the two stations? \n  \\item What is the new flow at the other depths in the presence of this surface gradient?\n\\end{itemize}\n\n\\paragraph{Geostrophic flow Gulf Stream}\n\nConsider the temperature section across the Gulf Stream (\\fref{fig:GulfStreamExample}).  Assuming a level of no motion at approximately 1500 m, what does \n\\begin{itemize}\n    \\item the sea-surface tilt look like?\n    \\item the interior velocity look like (just a sketch)?\n    \\item where would you expect the Gulf Stream to be the fastest?\n\\end{itemize}\n\n\\begin{figure}[hbt]\n  \\begin{center}\n    \\includegraphics[width=1.8in]{figs/Geostrophic/GulfStreamLoc}\n    \\includegraphics[width=2.7in]{figs/Geostrophic/GulfStreamTemp}\n    \\caption{Location of measurements in the Gulf Stream, and plot of temperature across the section \\citep{johnsetal95}.}\n    \\label{fig:GulfStreamExample}  \n  \\end{center}\n\\end{figure}\n\n", "meta": {"hexsha": "3ab25ece79b6f87ca1eff7bf7fceb104d9132b52", "size": 15445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chap10Geostrophic.tex", "max_stars_repo_name": "jklymak/Eos314Text", "max_stars_repo_head_hexsha": "5f58722b9ec9d44647425ba0461069ef2f218767", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-11T23:01:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-20T16:31:29.000Z", "max_issues_repo_path": "Chap10Geostrophic.tex", "max_issues_repo_name": "jklymak/Eos314Text", "max_issues_repo_head_hexsha": "5f58722b9ec9d44647425ba0461069ef2f218767", "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": "Chap10Geostrophic.tex", "max_forks_repo_name": "jklymak/Eos314Text", "max_forks_repo_head_hexsha": "5f58722b9ec9d44647425ba0461069ef2f218767", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-12-06T12:30:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T16:31:30.000Z", "avg_line_length": 68.0396475771, "max_line_length": 890, "alphanum_fraction": 0.7416639689, "num_tokens": 4447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6136457116062133}}
{"text": "\n\\subsection{Indirect utility functions}\n\nThe normal utility function is:\n\n\\(U=f(\\mathbf x)\\)\n\nWe have our demand:\n\n\\(x_{di}=x_{di}(I, \\mathbf p)\\)\n\n\\subsection{The indirect utility function}\n\nWe can plut this in to get:\n\n\\(U=g(I, \\mathbf p)\\)\n\n", "meta": {"hexsha": "3f52ece8c663bd4ac4ca35db1c94b2f9a32a5d9f", "size": 245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/economics/consumer/05-01-indirect.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/05-01-indirect.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/05-01-indirect.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.6111111111, "max_line_length": 42, "alphanum_fraction": 0.6775510204, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6136152303817761}}
{"text": "\\section{Glossary}\n\\smallskip \\hrule height 2pt \\smallskip\n \n \\begin{itemize}\n \t\\item \\textbf{complementary CDF} (CCDF, or survival function) - can ask how often the random variable is above a particular level.\n\t\tHas applications in statistical hypothesis testing, for example, because the one-sided p-value \n\t\t\tis the probability of observing a test statistic at least as extreme as the one observed.\n \t\\item \\textbf{confidence interval} - An interval that represents the expected range of an estimator if \n\t\tan experiment is repeated many times.\n\t\\item \\textbf{effect size} - any statistic that quantitatively measures the strength of a phenomenon.\n\t\\item \\textbf{jitter} - random noise added to data for purposes of visualization.  \n \t\\item \\textbf{oversampling} - The technique of increasing the representation of a sub-population in order to avoid errors due to small sample sizes.  \n\t\\item \\textbf{p-value} - the \\underline{\\textbf{p}}robability that, using a given statistical model, the statistical summary \n\t\t(such as the sample mean difference between two compared groups) would be the same as or more extreme \n\t\tthan the actual observed results\n\t\\item \\textbf{percentile rank} - The percentage of values in a distribution that are less than or equal to a given value.\n\t\\item \\textbf{quantizing} - The opposite of smoothing is discretizing, or quantizing.\n\t\\item \\textbf{rank} The index where an element appears in a sorted list.\n\t\\item \\textbf{raw moment} - A statistic based on the sum of data raised to a power.\r\n\t\tE.g. the correlation between two variables, the regression coefficient in a regression, the mean difference, ...\n\t\\item \\textbf{standard error}: - The RMSE of an estimate, which quantifies variability due to sampling error \n\t\t(but not other sources of error).\r\t\\item \\textbf{standard score} A value that has been standardized so that it is expressed in standard deviations from the mean.\n\n \\end{itemize}\n", "meta": {"hexsha": "0995eb53b7b492540392e1841c4d397491972653", "size": 1932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/glossary.tex", "max_stars_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_stars_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "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": "tex/glossary.tex", "max_issues_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_issues_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "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/glossary.tex", "max_forks_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_forks_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "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": 77.28, "max_line_length": 163, "alphanum_fraction": 0.7727743271, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6135651925338933}}
{"text": "% Created 2020-07-14 mar 10:56\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation,aspectratio=169]{beamer}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble}\n\\usepackage{amssymb}\n\\DeclareMathOperator{\\shift}{q}\n\\DeclareMathOperator{\\diff}{p}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{Control computarizado - Asignación de polos}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={Control computarizado - Asignación de polos},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.3.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Intro}\n\\label{sec:org70d5d08}\n\n\n\\section{2-dof controller}\n\\label{sec:org70b8192}\n\n\\begin{frame}[label={sec:orga124e5e}]{Two-degree-of-freedom controller}\n\\begin{center}\n\\includegraphics[width=0.8\\linewidth]{../../figures/2dof-block-explicit-no-delay}\n\\end{center}\n\\end{frame}\n\n\\section{Problem 5.3}\n\\label{sec:orga34f588}\n\\begin{frame}[label={sec:org4d6f90f}]{Åström \\& Wittenmark problem 5.3}\nConsider the system given by the pulse-transfer function\n\\[ H(z) = \\frac{z+0.7}{z^2 -1.8z + 0.81} \\]\nUse polynomial design (RST) to determine a controller such that the closed-loop system from command input to output has the characteristic polynomial\n\\[ A_c(z) = z^2 - 1.5z + 0.7. \\]\nLet the observer polynomial have as low order as possible, and place all observer poles in the origin (deadbeat observer). Consider three cases\n\\begin{description}\n\\item[{(a)}] Positional control with cancellation of the process zero\n\\item[{(b)}] Positional control with no cancellation of the zero\n\\item[{(c)}] Incremental controller with  no cancellation of the zero\n\\end{description}\n\\end{frame}\n\n\\begin{frame}[label={sec:org368a5ad}]{Why cancel the process zero?}\nBode plots of closed-loop systems (from reference signal to output) with and without cancellation of the process zero:\n\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{../../figures/aw5_3_bode}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:org91db4f3}]{Preliminary exercise}\nWhich of the closed-loop responses below  corresponds to (I) Positional control with zero cancellation (II), Positional control without zero cancellation, (III) Incremental control without zero cancellation.\n\\begin{center}\n\\includegraphics[width=0.45\\linewidth]{../../figures/aw5_3_refstep}\n\\includegraphics[width=0.45\\linewidth]{../../figures/aw5_3_diststep}\n\\end{center}\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "6a0ffd31b0f4610aae468e33f62bddbd4820cb34", "size": 2706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "polynomial-design/slides/lecture-problem-solving-RST-sp.tex", "max_stars_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_stars_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-07T05:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-22T09:46:13.000Z", "max_issues_repo_path": "polynomial-design/slides/lecture-problem-solving-RST-sp.tex", "max_issues_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_issues_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-06-12T20:44:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-12T20:49:00.000Z", "max_forks_repo_path": "polynomial-design/slides/lecture-problem-solving-RST-sp.tex", "max_forks_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_forks_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-14T03:55:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-14T03:55:27.000Z", "avg_line_length": 34.253164557, "max_line_length": 207, "alphanum_fraction": 0.766075388, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6135651900179054}}
{"text": "% !TEX root = main.tex\n%----------------------------------------------------------------------\n\n%----------------------------------------------------------------------\n\\chapter{The Bivariate Normal Distribution}\n\n%The normal distribution is based on the Gaussian integral\n%\\[\n%\\int_{-\\infty}^{\\infty} e^{-x^2} = \\sqrt{\\pi},\n%\\]\n\n%----------------------------------------------------------------------\n\\section{Bivariate transformations}\n\n% definition\n\\begin{definition}\\label{def:jacobian}\nLet $h:\\R^2\\to\\R^2$ and let $(u,v) = h(x,y)$. The \\emph{Jacobian determinant} of the transformation $h$ is the determinant of its $2\\times 2$ matrix of partial derivatives:\n\\[\nJ = \\begin{vmatrix}\n\\displaystyle\\frac{\\partial u}{\\partial x} & \\displaystyle\\frac{\\partial u}{\\partial y} \\\\[2ex]\n\\displaystyle\\frac{\\partial v}{\\partial x} & \\displaystyle\\frac{\\partial v}{\\partial y} \\\\[2ex]\n\\end{vmatrix}\n\\]\n\\end{definition}\n\n% theorem: continuous\n\\begin{theorem}\\label{thm:bivariate_transformation_pdf}\nLet $U$ and $V$ be jointly continuous random variables, let $f_{U,V}$ be their joint PDF, let $g:\\R^2\\to\\R^2$ be an injective transform over the support of $f_{U,V}$ and let $(X,Y) = g(U,V)$. Then the joint PDF of $X$ and $Y$ is given by\n\\[\nf_{X,Y}(x,y) = |J| f_{U,V}\\big[ g^{-1}(x,y) \\big]\n\\] \nwhere $J$ is the Jacobian determinant of the transformation $g^{-1}$,\n\\[\nJ = \n\\begin{vmatrix}\n\\displaystyle\\frac{\\partial u}{\\partial x} & \\displaystyle\\frac{\\partial u}{\\partial y} \\\\[2ex]\n\\displaystyle\\frac{\\partial v}{\\partial x} & \\displaystyle\\frac{\\partial v}{\\partial y} \\\\[2ex]\n\\end{vmatrix}\n\\]\nwhere $(u,v) = g^{-1}(x,y)$.\n\\end{theorem}\n\n% remark\n\\begin{remark}\nThe absolute value $|J|$ is a scale factor, which ensures that the transformed PDF $f_{X,Y}(x,y)$ integrates to one.\n\\end{remark}\n\n% example: jointly continuous\n\\begin{example}\nLet $U$ and $V$ be continuous random variables, and let $X=U+V$ and $Y=U-V$. \n\\ben\n\\it Find the joint PDF of $X$ and $Y$ in terms of the joint PDF of $U$ and $V$.\n\\it If $U,V\\sim\\text{Exponential}(1)$ are independent, find the joint PDF of $X$ and $Y$.\n\\een\n\\end{example}\n\n\\begin{solution}\n\\ben\n\n\\it % <<< (i)\n\\bit\n\\it The transformation $g:\\R^2\\to\\R^2$ is defined by $g(u,v) = (u+v,u-v)$. \n\\it To compute the inverse transformation $g^{-1}:\\R^2\\to\\R^2$, we solve the equations %$x=u+v$ and $y=u-v$ for $u$ and $v$.\n\\[\nx=u+v \\quad\\text{and}\\quad y=u-v.% \\quad \\text{for $u$ and $v$.}\n\\]\n\\it This yields $u = \\frac{1}{2}(x+y)$ and $v = \\frac{1}{2}(x-y)$.\n\\it Thus the inverse transformation is \n\\[\n(u,v) = g^{-1}(x,y) = \\left[\\frac{1}{2}(x+y),\\frac{1}{2}(x-y)\\right].\n\\]\n\\eit\nThe Jacobian determinant is given by\n\\[\nJ = \n\\begin{vmatrix}\n\\displaystyle\\frac{\\partial u}{\\partial x} & \\displaystyle\\frac{\\partial u}{\\partial y} \\\\[2ex]\n\\displaystyle\\frac{\\partial v}{\\partial x} & \\displaystyle\\frac{\\partial v}{\\partial y} \\\\\n\\end{vmatrix}\n=\n\\begin{vmatrix}\n1/2\t& 1/2 \\\\\n1/2 & -1/2 \\\\\n\\end{vmatrix}\n= -\\frac{1}{4} - \\frac{1}{4} = -\\frac{1}{2}.\n\\]\nHence the joint PDF of $X$ and $Y$ is\n\\begin{align*}\nf_{X,Y}(x,y)\n\t& = |J|f_{U,V}(u,v) \\\\\n\t& = \\left|-\\frac{1}{2}\\right| f_{U,V}\\left[\\frac{1}{2}(x+y),\\frac{1}{2}(x-y)\\right] \\\\\n\t& = \\frac{1}{2}f_{U,V}\\left[\\frac{1}{2}(x+y),\\frac{1}{2}(x-y)\\right].\n\\end{align*}\n\n\n\n\\it % <<< (ii)\nLet $U$ and $V$ be independent with $U,V\\sim\\text{Exponential}(1)$.\n\nBy independence, the joint PDF of $U$ and $V$ is \n\\[\nf_{U,V}(u,v) \n\t= \\begin{cases}\n\t\te^{-(u+v)}\t\t& u,v > 0 \\\\\n\t\t0\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nTo compute the support of $f_{X,Y}$, since $u>0$ and $v>0$ we have $x>0$, so\n\\bit\n\\it $\\min(y) = \\min(u-v) = -x$ (which occurs when $u=0$ and $v=x$), and\n\\it $\\max(y) = \\max(u-v) = x$ (which occurs when $u=x$ and $v=0$).\n\\eit\nThus, substituting for $u+v = \\frac{1}{2}(x+y) + \\frac{1}{2}(x-y) = x$, we obtain\n\\[\nf_{X,Y}(x,y) = \\begin{cases}\n\t\\frac{1}{2}e^{-x}\t& \\text{for } x > 0 \\text{ and } -x < y < x, \\\\\n\t0\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\n\\een\n\\end{solution}\n\n\n%----------------------------------------------------------------------\n\\section{The bivariate normal distribution}\n%----------------------------------------------------------------------\n\n%%----------------------------------------------------------------------\n%\\section{The sum of two random variables}\n%%----------------------------------------------------------------------\n%% theorem\n%\\begin{theorem}\\label{thm:convolution}\n%Let $X$ and $Y$ be jointly continuous random variables, and let $f_{X,Y}$ be their joint PDF. The random variable $X+Y$ has the following PDF:\n%\\[\n%f_{X+Y}(t) \n%\t= \\int_{-\\infty}^{\\infty} f_{X,Y}(x,t-x)\\,dx\n%\t= \\int_{-\\infty}^{\\infty} f_{X,Y}(t-y,y)\\,dy.\n%\\]\n%\\end{theorem}\n%\n%\\begin{proof}\n%Let $A = \\{(x,y):x+y\\leq z\\}\\subset\\R^2$. Then\n%\\[\n%\\prob(X+Y\\leq z)\n%\t= \\iint_A f(x,y)\\,dxdy\n%\t= \\int_{x=-\\infty}^{\\infty} \\int_{y=-\\infty}^{z-x}f_{X,Y}(x,y)\\,dy\\,dx\n%\\]\n%We change the variable of integration (in the inner integral), making the substitution $y=t-x$:\n%\\begin{align*}\n%F_{X+Y}(z) = \\prob(X+Y\\leq z)\n%\t& = \\int_{x=-\\infty}^{\\infty} \\int_{t=-\\infty}^{z}f_{X,Y}(x,t-x)\\,dt\\,dx \\\\\n%\t& = \\int_{t=-\\infty}^{z} \\int_{x=-\\infty}^{\\infty}f_{X,Y}(x,t-x)\\,dx\\,dt\n%\\end{align*}\n%where the final equality follows by reversing the order of integration. Thus the PDF of $X+Y$ is \n%\\[\n%f_{X+Y}(t) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,t-x)\\,dx \\qquad\\text{as required.}\n%\\]\n%\\end{proof}\n%\n%% corollary\n%\\begin{corollary}\\label{cor:convolution_independent}\n%If $X$ and $Y$ are independent, the PDF of $X+Y$ is the \\emph{convolution} of the marginal PDFs:\n%\\[\n%f_{X+Y}(t) \n%\t= \\int_{-\\infty}^{\\infty} f_X(x)f_Y(t-x)\\,dx\n%\t= \\int_{-\\infty}^{\\infty} f_X(t-y)f_Y(y)\\,dy.\n%\\]\n%\\end{corollary}\n\n%\\begin{remark}\n%The function $f_{X+Y}$ is called the \\emph{convolution} of $X$ and $Y$, and is often written as $f_{X+Y}=f_X\\ast f_Y$.\n%\\end{remark}\n\n%%----------------------------------------------------------------------\n%\\section{The sum of two standard normal variables}\n%%----------------------------------------------------------------------\n%% lemma: sums of normal random variables}\n%\\begin{lemma}\\label{lem:sum_of_standard_normal_variables}\n%If $U,V\\sim N(0,1)$ are independent, then $U+V\\sim N(0,2)$.\n%\\end{lemma}\n%\n%\\begin{proof}\n%Since $U$ and $V$ are independent, their joint PDF is\n%\\[\n%f(u,v)=f_U(u)f_V(v) = \\frac{1}{2\\pi}\\exp\\left(-\\frac{1}{2}(u^2 + v^2)\\right) \\qquad  u,v\\in\\R.\n%\\]\n%\n%Let $W=U+V$. Since $U$ and $V$ are independent, by Corollary~\\ref{cor:convolution_independent} we have\n%\\begin{align*}\n%f_W(w) \n%\t& = \\int_{-\\infty}^{\\infty} f_U(u)f_V(w-u)\\,du \\\\\n%\t& = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\exp\\left[-\\frac{1}{2}\\left(u^2 + (w-u)^2\\right)\\right]\\,du \\\\\n%\t& = \\frac{1}{2\\pi} e^{-\\frac{1}{4}w^2} \\int_{-\\infty}^{\\infty} \\exp\\left[-\\left(u-\\frac{w}{2}\\right)^2\\right]\\,du\n%\\end{align*}\n%We change the variable of integration, by making the substitution $t = \\displaystyle\\sqrt{2}\\left(u-\\frac{w}{2}\\right)$:\n%\\[\n%f_W(w) \n%\t= \\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{1}{4}w^2} \\int_{-\\infty}^{\\infty} \\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}w^2}\\,dv\n%\t= \\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{w^2}{4}},\n%\\]\n%which is the PDF of the $N(0,2)$ distribution\n%\\end{proof}\n%\n%Lemma~\\ref{lem:sum_of_standard_normal_variables} is a special case of the following theorem.\n%% theorem\n\n%%----------------------------------------------------------------------\n%\\section{The standard bivariate normal distributrion} \n%%----------------------------------------------------------------------\n\n\\begin{theorem}\\label{thm:sum_of_normal_variables}\nif $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma_2^2)$ are independent, then\n\\[\nX+Y\\sim N(\\mu_1+\\mu_2, \\sigma_1^2+\\sigma_2^2).\n\\]\n\\end{theorem}\n\n%The following corollary will be useful later on:\n% corollary\n\\begin{corollary}\\label{cor:lin_comb_std_normal}\nIf $U,V\\sim N(0,1)$ are independent, then $aU+bV\\sim N(0,a^2+b^2)$ for all $a,b\\in\\R$.\n\\end{corollary}\n%If $U$ and $V$ are independent standard normal variables, their joint PDF of is\n%\n%\\[\n%f(u,v)=f_U(u)f_V(v) = \\frac{1}{2\\pi}\\exp\\left(-\\frac{1}{2}(u^2 + v^2)\\right) \\qquad  u,v\\in\\R.\n%\\]\n\n% definition: standard bivariate normal\n\\begin{definition}\\label{def:standard_bivariate_normal}\nA pair of random variables $U$ and $V$ have the \\emph{standard bivariate normal distribution} if their joint PDF $f:\\R^2\\to[0,\\infty)$ can be written as\n\\[\nf_{U,V}(u,v) = \\frac{1}{2\\pi\\sqrt{1-\\rho^2}}\\exp\\left(-\\frac{1}{2(1-\\rho^2)}\\big(u^2 - 2\t\\rho uv + v^2\\big)\\right)\n\\]\nwhere $\\rho$ is a constant satisfying $-1 < \\rho < 1$.\n\\end{definition}\n\n% definition: bivariate normal\n\\begin{definition}\\label{def:bivariate_normal}\nA pair of random variables $X$ and $Y$ are said to have \\emph{bivariate normal distribution} with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$ and correlation $\\rho$, if their joint PDF can be written as\n%\\small\n\\[\nf_{X,Y}(x,y)\n\t= \\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1-\\rho^2}}\n\t\t\\exp\\left(-\\frac{1}{2(1-\\rho^2)}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \n\t\t\t-2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) \n\t\t\t\t+\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2 \\right]\\right)\n\\]\n\\normalsize\n\\end{definition}\n\n% technical result\nThe following lemma can be used to derive many properties of the bivariate normal distribution.\n\\begin{lemma}\\label{lem:trick}\nLet $U,V\\sim N(0,1)$ be independent, let $\\rho\\in(-1,+1)$. Then the random variables\n\\begin{align*}\nX & = \\mu_1 + \\sigma_1 U, \\\\\nY & = \\mu_2 + \\sigma_2\\big(\\rho U +\\sqrt{1-\\rho^2}V\\big)\n\\end{align*}\nhave bivariate normal distribution with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$, and correlation $\\rho$.\n\\end{lemma}\n\n% proof\n\\begin{proof}\nTo find the joint PDF of $X$ and $Y$, let $g(u,v)$ denote the transformation:\n\\[\ng(u,v) = \\big[\\mu_1 + \\sigma_1 u, \\mu_2 + \\sigma_2(\\rho u +\\sqrt{1-\\rho^2}v)\\big].\n\\]\nThe inverse transformation is\n\\[\ng^{-1}(x,y) \n\t= \\left(\\frac{x-\\mu_1}{\\sigma_1}, \\frac{1}{\\sqrt{1-\\rho^2}}\n  \\left[\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) -\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\right]\\right)\n\\]\nThe joint PDF of $X$ and $Y$ is $f_{X,Y}(x,y) = |J|f_{U,V}(u,v)$, where $J$ is the Jacobian determinant of the inverse transformation:\n\\[\nJ=\\begin{vmatrix}\n\\displaystyle\\frac{\\partial u}{\\partial x}  & \\displaystyle\\frac{\\partial u}{\\partial y}  \\\\[2ex]\n\\displaystyle\\frac{\\partial v}{\\partial x}  & \\displaystyle\\frac{\\partial v}{\\partial y} \n\\end{vmatrix}\n=\n\\begin{vmatrix}\n\\displaystyle\\frac{1}{\\sigma_1}  \t\t& \\displaystyle0 \\\\[2ex]\n\\displaystyle\\frac{1}{\\rho\\sigma_1}\t& \\displaystyle\\frac{1}{\\sigma_2\\sqrt{1-\\rho^2}} \n\\end{vmatrix}\n=\n\\frac{1}{\\sigma_1\\sigma_2\\sqrt{1-\\rho^2}}\n\\]\n\nBecause $U$ and $V$ are independent,\n\\[\nf_{U,V}(u,v)=f_U(u)f_V(v) = \\frac{1}{2\\pi}\\exp\\left(-\\frac{1}{2}(u^2 + v^2)\\right) \\qquad  u,v\\in\\R.\n\\]\nand since\n\\begin{align*}\nu^2 +v^2 \n\t&  = \\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \n\t\t\t+ \\frac{1}{1-\\rho^2}\\left[ \n\t\t\t\t\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2 \n\t\t\t\t\t- 2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_{2}}\\right) \n\t\t\t\t\t\t+\\rho^2\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \\right]  \\\\\n\t& =  \\frac{1}{1-\\rho^2}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \n\t\t\t\t-2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) \n\t\t\t\t\t+\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2\\right]\n\\end{align*}\nit follows that\n%\\small\n\\[\nf_{X,Y}(x,y)\n\t= \\frac{1}{2\\pi\\sigma_1\\sigma_1\\sqrt{1-\\rho^2}}\n\t\t\\exp\\left(\\frac{-1}{2(1-\\rho^2)}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \n\t\t\t-2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) \n\t\t\t\t+\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2 \\right]\\right)\n\\]\n\\normalsize\nas required.\n\\end{proof}\n\nThe following theorem shows that if $X$ and $Y$ have bivariate normal distribution, then any linear combination of $X$ and $Y$ is normally distributed.\n% theorem: linear combination\n\\begin{theorem}\\label{thm:lin_comb_bivar_normal}\nLet $X$ and $Y$ have bivariate normal distribution with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$, and correlation $\\rho$. Then\n%If $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma_2^2)$ then\n\\[\naX + bY \\sim N\\big(a\\mu_1 + b\\mu_2, a^2\\sigma_1^2 + 2ab\\sigma_1\\sigma_2\\rho + b^2\\sigma_2^2\\big)\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $Z=aX+bY$, let $U$ and $V$ be independent standard normal random variables, and let\n\\begin{align*}\nX' & = \\mu_1 + \\sigma_1 U \\\\\nY' & = \\mu_2 + \\sigma_2\\big(\\rho U +\\sqrt{1-\\rho^2}V\\big)\n\\end{align*}\n\nBy Lemma~\\ref{lem:trick}, $X$ and $Y$ have the same joint distribution as $X'$ and $Y'$, so $Z=aX+bY$ has the same distribution as \n\\[\nZ' = aX'+bY' = (a\\mu_1 + b\\mu_2) + (a\\sigma_1 + b\\sigma_2\\rho)U + b\\sigma_2\\sqrt{1-\\rho^2} V\n\\]\n\nBecause $U,V\\sim N(0,1)$ are independent, it follows by Corollary~\\ref{cor:lin_comb_std_normal} that\n\\[\nZ' \\sim N\\left(a\\mu_1 + b\\mu_2, a^2\\sigma_1^2 + 2ab\\sigma_1\\sigma_2\\rho + b^2\\sigma_2^2\\right),\n\\]\nso $Z=aX+bY$ has normal distribution, as required.\n\\end{proof}\n\n%----------------------------------------------------------------------\n\\section{Properties of the bivariate normal distribution} \n%----------------------------------------------------------------------\n\n% theorem: properties\n\\begin{theorem}\nLet $X$ and $Y$ have bivariate normal distribution with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$, and correlation $\\rho$. Then\n\\ben\n\\it $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma_2^2)$,\n\\it $\\rho$ is the correlation coefficient of $X$ and $Y$, and\n\\it $X$ and $Y$ are independent if and only if $\\rho=0$.\n\\een\n\\end{theorem}\n\n% proof\n\\begin{proof}\n%By Lemma~\\ref{lem:trick}, let us write\nLet $U,V\\sim N(0,1)$ and define\n\\begin{align*}\nX & = \\mu_1 + \\sigma_1 U \\\\\nY & = \\mu_2 + \\sigma_2\\big(\\rho U +\\sqrt{1-\\rho^2}V\\big)\n\\end{align*}\n\n\n\\ben\n\\it % (i)\nIn the proof of Theorem~\\ref{thm:lin_comb_bivar_normal}:\n\\bit \n\\it taking $a=1$ and $b=0$ yields $X\\sim N(\\mu_1,\\sigma_1^2)$, and\n\\it taking $a=0$ and $b=1$ yields $Y\\sim N(\\mu_2,\\sigma_2^2)$.\n\\eit\n\\it % (ii)\nUsing the fact that $\\cov(aX+b,cY+d)=ac\\cov(X,Y)$ for all $a,b,c,d\\in\\R$,\n\\begin{align*}\n\\cov(X,Y)\n\t& = \\cov\\big[\\mu_1 + \\sigma_1 U, \\mu_2 + \\sigma_2(\\rho U + \\sqrt{1-\\rho^2}V)\\big] \\\\\n\t& = \\sigma_1\\sigma_2\\cov(U, \\rho U + \\sqrt{1-\\rho^2}V) \\\\\n\t& = \\sigma_1\\sigma_2\\big[\\rho\\expe(U^2) + \\sqrt{1-\\rho^2}\\expe(UV)\\big] \\\\\n\t& = \\sigma_1\\sigma_2\\rho.\n\\end{align*}\nThus $\\rho = \\displaystyle\\frac{\\cov(X)}{\\sqrt{\\var(X)}\\sqrt{\\var(Y)}}$ as required.\n\n\n\\it % (iii)\nIf $X$ and $Y$ are independent, they are uncorrelated. If $X$ and $Y$ are uncorrelated then $\\rho=0$, so the joint PDF of $X$ and $Y$ satisfies\n\\begin{align*}\nf_{X,Y}(x,y)\n\t& = \\frac{1}{2\\pi\\sigma_1\\sigma_2}\\exp\\left(-\\frac{1}{2}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 + \\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2 \\right]\\right) \\\\\n\t& = \\frac{1}{\\sqrt{2\\pi}\\sigma_1}\\exp\\left(-\\frac{1}{2}\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2\\right)\n\t\t\t\\times \\frac{1}{\\sqrt{2\\pi}\\sigma_2}\\exp\\left(-\\frac{1}{2}\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2\\right) \\\\\n\t& = f_X(x)f_Y(y).\t\t\n\\end{align*}\nBecause this holds for all $x,y\\in\\R$, it follows that $X$ and $Y$ are independent. \n\\een\n\\end{proof}\n\n%----------------------------------------------------------------------\n\\section{Conditional distributions} \n%----------------------------------------------------------------------\n\n% theorem\n\\begin{theorem}\nLet $X$ and $Y$ have bivariate normal distribution with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$, and correlation $\\rho$.\nThen the conditional distribution of $Y$ given $X=x$ is also normal, with conditional mean and variance given by\n\\begin{align*}\n\\expe(Y|X=x)\t& = \\mu_2 + \\rho\\left(\\frac{\\sigma_2}{\\sigma_1}\\right)(x - \\mu_1), \\\\[2ex]\n\\var(Y|X=x) \t& = \\sigma_2^2(1-\\rho^2),\n\\end{align*}\nand the conditional mean and variance of $Y$ given $X$ is \n\\begin{align*}\n\\expe(Y|X)\t& = \\expe(Y) + \\frac{\\cov(X,Y)}{\\var(X)}\\big[X - \\expe(X)\\big], \\\\[2ex]\n\\var(Y|X) \t& = \\var(Y)(1-\\rho^2).\n\\end{align*}\n\\end{theorem}\n\n% proof\n\\begin{proof}\nLet $U,V\\sim N(0,1)$ be independent, and define the random variables\n\\begin{align*}\nX & = \\mu_1 + \\sigma_1 U, \\\\\nY & = \\mu_2 + \\sigma_2\\big[\\rho U +\\sqrt{1-\\rho^2}V\\big] \\\\\n\t& = \\mu_2 + \\sigma_2\\left[\\rho \\left(\\frac{X-\\mu_1}{\\sigma_1}\\right) +\\sqrt{1-\\rho^2}V\\right].\n\\end{align*}\nIf $X$ is fixed at $x$, then $Y$ is a linear transformation of $V$, so the conditional distribution of $Y$ given that $X=x$ is a normal distribution. \nFurthermore, since $\\expe(V)=0$ and $\\var(V)=1$ we have\n\\begin{align*}\n\\expe(Y|X=x) \t& = \\mu_2 + \\rho\\left(\\frac{\\sigma_2}{\\sigma_1}\\right)(x - \\mu_1) \\\\[2ex]\n\\var(Y|X=x)\t& = \\sigma_2^2(1-\\rho^2)\n\\end{align*}\nas required.\n\\end{proof}\n\n% remarks\n\\begin{remark}\n\\bit\n\\it\nGiven $X=x$, the conditional mean is obtained by adjusting $\\expe(Y)$ by an amount proportional to the difference between $X=x$ and its mean $\\expe(X)$. The size of this adjustment is determined by (1) the size of $Y$ relative to $X$, expressed by the ratio $\\sigma_2/\\sigma_1$, and (2) the correlation coefficient $\\rho$, which quantifies the linear dependence between $X$ and $Y$. Note that $\\rho=0$ implies that $\\expe(Y|X=x)=0$ for all $x$ (which is not surprising, given that uncorrelated normal variables are independent).\n\\it \nThe conditional variance $\\var(Y|X=x)$ quantifies the variability in $Y$ that is \\emph{not} explained by the fact that $X$ takes the value $x$. The squared correlation coefficient $\\rho^2$ thus quantifies the proportion of the overall variance $\\var(Y)$ accounted for by the fact that $X=x$. \n\\it\nThis idea of `explained' and `unexplained' variance is apparent in the law of total variance:\n\\[\n\\var(Y) = \\expe\\big[\\var(Y|X)\\big] + \\var\\big[\\expe(Y|X)\\big] \n\\]\n\t\\bit\n\t\\it $\\var(Y)$ is the total variance,\n\t\\it $\\expe\\big[\\var(Y|X)\\big]$ is the variance explained by $X$, and \n\t\\it $\\var\\big[\\expe(Y|X)\\big]$ is the variance not explained by $X$. \n\t\\eit\n\\eit\n\\end{remark}\n\n%----------------------------------------------------------------------\n\\section{Mulivariate transformations}\n%----------------------------------------------------------------------\n\n% definition\n\\begin{definition}\\label{def:jacobian}\nLet $h:\\R^n\\to\\R^n$ be a transformation of $n$ variables, and let $(x_1,x_2,\\ldots,x_n) = h(y_1,y_2,\\ldots,y_n)$. The \\emph{Jacobian} (or \\emph{Jacobian determinant}) of the transformation $h$ is the determinant of its $n\\times n$ matrix of partial derivatives:\n\\[\nJ = \n\\begin{vmatrix}\n\\displaystyle\\frac{\\partial x_1}{\\partial y_1} & \\displaystyle\\frac{\\partial x_1}{\\partial y_2} & \\cdots &  \\displaystyle\\frac{\\partial x_1}{\\partial y_n}\\\\[2ex]\n\\displaystyle\\frac{\\partial x_2}{\\partial y_1} & \\displaystyle\\frac{\\partial x_2}{\\partial y_2} & \\cdots &  \\displaystyle\\frac{\\partial x_2}{\\partial y_n}\\\\[2ex]\n\\vdots & \\vdots & \\ddots & \\vdots \\\\[2ex]\n\\displaystyle\\frac{\\partial x_n}{\\partial y_1} & \\displaystyle\\frac{\\partial x_n}{\\partial y_2} & \\cdots &  \\displaystyle\\frac{\\partial x_n}{\\partial y_n}\\\\[2ex]\n\\end{vmatrix}\n\\]\n\\end{definition}\n\n% theorem: continuous\n\\begin{theorem}\\label{thm:transf_injective_joint_continuous}\nLet $X=(X_1,X_2,\\ldots,X_n)$ be a vector of continuous random variables, let $f_X(x_1,x_2\\ldots,x_n)$ be their joint PDF, let $g:\\R^n\\to\\R^n$ be an injective transformation, and let $Y=(Y_1,Y_2,\\ldots,Y_n)$ be the continuous random vector defined by $Y=g(X)$, i.e.\\\n\\[\n(Y_1,Y_2,\\ldots,Y_n) = g(X_1,X_2,\\ldots,X_n)\n\\]\nIf the Jacobian of the inverse transformation $g^{-1}$ is continuous and non-zero over the range of the transformation, the joint PDF of $Y$ is\n\\[\nf_Y(y_1,y_2,\\ldots,y_n) = |J| f_X(x_1,x_2,\\ldots,x_n)\n\\]\nwhere \n\\[\n(x_1,x_2,\\ldots,x_n)=g^{-1}(y_1,y_2,\\ldots,y_n)\n\\]\nis the solution of $(y_1,y_2,\\ldots,y_n)=g(x_1,\\ldots,x_n)$.\n\\end{theorem}\n\n% remark\n\\begin{remark}\nThe scale factor $|J|$ ensures that $f_Y(y_1,y_2,\\ldots,y_n)$ integrates to one.\n\\end{remark}\n\n\n%==================================================================================================\n\\section{The multivariate normal distribution} \n%==================================================================================================\nThe bivariate normal distribution can be formulated using matrix notation. Let\n\\[\n\\mathbf{Z}\t\t= \\begin{pmatrix} X \\\\ Y \\end{pmatrix},\\quad\n\\mathbf{\\mu}\t= \\begin{pmatrix} \\mu_1 \\\\ \\mu_2 \\end{pmatrix}\\quad\\text{and}\\quad\n\\Sigma\t\t\t= \\begin{pmatrix} \\sigma^2_1 & \\rho\\sigma_1\\sigma_2 \\\\ \\rho\\sigma_1\\sigma_2 & \\sigma^2_2 \\end{pmatrix}\n\\]\n\nThe matrix $\\Sigma$ is called the \\emph{variance-covariance} matrix.\n\\bit\n\\it The determinant of $\\Sigma$ is \n\\[\n|\\Sigma| = (1-\\rho^2)\\sigma^2_1\\sigma^2_2.\n\\]\n\\it The inverse of $\\Sigma$ is\n\\[\n\\Sigma^{-1} = \\frac{1}{(1-\\rho^2)\\sigma^2_1\\sigma^2_2}\n\\begin{pmatrix} \n\t\\sigma^2_2  \t\t\t\t& -\\rho\\sigma_1\\sigma_2 \\\\\n\t-\\rho\\sigma_1\\sigma_2\t& \\sigma^2_1\n\\end{pmatrix}.\n\\]\n\\eit\n\nLet $\\mathbf{z} = (x,y)^T$ and consider the quadratic form \n\\begin{align*}\n\\big(\\mathbf{z}-\\mathbf{\\mu})^T \\Sigma^{-1}(\\mathbf{z}-\\mathbf{\\mu}\\big) \n\t& = \t\\frac{1}{(1-\\rho^2)\\sigma^2_1\\sigma^2_2}\\ \n\t\t\t\\begin{pmatrix} x-\\mu_1 \\\\ y-\\mu_2\t\\end{pmatrix}^T\n\t\t\t\\begin{pmatrix} \\sigma^2_2 & -\\rho\\sigma_1\\sigma_2 \\\\ -\\rho\\sigma_1\\sigma_2 & \\sigma^2_1 \\end{pmatrix}\n\t\t\t\\begin{pmatrix} x-\\mu_1 \\\\ y-\\mu_2\t\\end{pmatrix} \\\\\n\t& = \\frac{1}{(1-\\rho^2)}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2\n\t\t\t -2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) \n\t\t\t \t+\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2\\right]\n\\end{align*}\n\nThe PDF $f(x,y)$ of the bivariate normal distribution can therefore be written as\n\\[\nf(x,y) = \\frac{1}{2\\pi|\\Sigma|^{1/2}}\\exp\\left(-\\frac{1}{2}(\\mathbf{z}-\\mathbf{\\mu})^T \\Sigma^{-1} (\\mathbf{z}-\\mathbf{\\mu})\\right).\n\\]\t\t\n\nUsing this notation, we define the \\emph{multivariate normal distribution} as follows.\n\n\n\n% definition: multivariate normal\n\\begin{definition}\nA random vector $\\mathbf{Z}=(X_1,X_2,\\ldots,X_n)^T$ is said to have \\emph{multivariate normal distribution} with mean vector $\\mathbf{\\mu}= (\\mu_1,\\mu_2,\\ldots,\\mu_n)^T$ and variance-covariance matrix\n\\[\n\\Sigma\t\t\t= \\begin{pmatrix} \n\t\\sigma^2_1\t\t \t\t\t& \\rho_{12}\\sigma_1\\sigma_2  \t& \\ldots & \\rho_{1n}\\sigma_1\\sigma_n \\\\ \n\t\\rho_{21}\\sigma_1\\sigma_2 \t& \\sigma^2_2\t\t\t\t\t& \\ldots & \\rho_{2n}\\sigma_2\\sigma_n \\\\\n\t\\vdots\t\t\t\t\t\t& \\vdots\t\t\t\t\t\t& \\ddots & \\vdots \\\\\n\t\\rho_{n1}\\sigma_1\\sigma_n\t\t \t& \\rho_{n2}\\sigma_n\\sigma_2\t& \\ldots & \\sigma^2_n \\\\\n\t\\end{pmatrix}\n\\]\nif its joint density function can be written as\n\\[\nf(\\mathbf{z}) = \\frac{1}{2\\pi|\\Sigma|^{1/2}}\\exp\\left(-\\frac{1}{2}(\\mathbf{z}-\\mathbf{\\mu})^T \\Sigma^{-1} (\\mathbf{z}-\\mathbf{\\mu})\\right)\n\\]\t\t\n\\end{definition}\n\nwhere $\\mu_i = \\expe(X_i)$, $\\sigma_i^2 = \\var(X_i)$ and $\\rho_{ij} = \\displaystyle\\frac{\\expe(X_iX_j)}{\\sigma_i\\sigma_j}$.\n\n\n\\begin{exercise}\n\\begin{questions}\n%----------------------------------------\n% GS p100\n\\question\nLet $X$ and $Y$ have standard bivariate normal distribution, with joint PDF given by\n%\\[\n%f(x,y)\n%\t= \\frac{1}{2\\pi\\sigma_1\\sigma_2\\sqrt{1-\\rho^2}}\n%\t\t\\exp\\left(-\\frac{1}{2(1-\\rho^2)}\\left[\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)^2 \n%\t\t\t-2\\rho\\left(\\frac{x-\\mu_1}{\\sigma_1}\\right)\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right) \n%\t\t\t\t+\\left(\\frac{y-\\mu_2}{\\sigma_2}\\right)^2 \\right]\\right)\n%\\]\n\\[\nf(x,y) = \\frac{1}{2\\pi\\sqrt{1-\\rho^2}}\\exp\\left(-\\frac{1}{2(1-\\rho^2)}(x^2 - 2\\rho xy + y^2)\\right)\n\\]\nwhere $\\rho$ is a constant satisfying $-1 < \\rho < 1$. \n\\begin{parts}\n\\part\nCheck that $f(x,y)$ is indeed a joint PDF, by verifying that $f(x,y)\\geq 0$ and $\\displaystyle\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f(x,y)\\,dxdy = 1$.\n\\begin{answer}\nTODO\n\\end{answer}\n\\part\nCheck that $\\cov(X,Y) = \\displaystyle\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} xy f(x,y)\\,dxdy = \\rho$.\n\\begin{answer}\nTODO\n\\end{answer}\n\\part\nShow that if $X$ and $Y$ are uncorrelated, then they are independent.\n\\begin{answer}\nTODO\n\\end{answer}\n\\end{parts}\n%----------------------------------------\n\\question\n% GS p110\nLet $X$ and $Y$ have standard bivariate normal distribution. Find the conditional distribution of $Y$ given $X=x$, and hence show that $\\expe(Y|X) = \\rho X$.\n\\begin{answer}\nThe conditional distribution of $Y$ given $X=x$ is $N(\\rho x, 1-\\rho^2)$.\n\\end{answer}\n%----------------------------------------\n% GS 4.7.5\n\\question\nLet $X$ and $Y$ have standard bivariate normal distribution. Show that $X$ and $\\displaystyle Z=\\frac{Y-\\rho X}{\\sqrt{1-\\rho^2}}$ are independent standard normal random variables.\n\\begin{answer}\nTODO\n\\end{answer}\n%----------------------------------------\n% GS 4.7.6\n\\question\nLet $X$ and $Y$ have standard bivariate normal distribution, and let $Z=\\max\\{X,Y\\}$. Show that $\\expe(Z)=\\sqrt{(1-\\rho)/\\pi}$ and $\\expe(Z^2)=1$.\n\\begin{answer}\nTODO\n\\end{answer}\n%----------------------------------------\n\\question\nLet $U,V\\sim N(0,1)$. Show that the random variables $X = U+V$ and $Y = U-V$ are independent.\n\n\\begin{answer}\n\\bit\n\\it The transformation is $g(u,v) = (u+v,u-v)$. \n\\it To compute the inverse transformation, consider $x=u+v$ and $y=u-v$. \n\\it Solving these, we obtain $u = \\frac{1}{2}(x+y)$ and $v = \\frac{1}{2}(x-y)$.\n\\it Thus the inverse transformation is $(u,v) = g^{-1}(x,y) = \\left(\\frac{1}{2}(x+y),\\frac{1}{2}(x-y)\\right)$\n\\eit\n\nThe Jacobian determinant of $g^{-1}(x,y)$ is\n\\[\nJ = \n\\begin{vmatrix}\n\\frac{\\partial u}{\\partial x}  & \\frac{\\partial u}{\\partial y}  \\\\\n\\frac{\\partial v}{\\partial x}  & \\frac{\\partial v}{\\partial y} \n\\end{vmatrix}\n=\n\\begin{vmatrix}[r]\n\\frac{1}{2}   &  \\frac{1}{2} \\\\\n\\frac{1}{2}  & -\\frac{1}{2}\n\\end{vmatrix}\n=\n-\\frac{1}{2}\n\\]\nThe joint PDF of $U$ and $V$ is \n\\[\nf(u,v) = \\frac{1}{2\\pi \\sqrt{1-\\rho ^{2}}} \\exp\\left( -\\frac{u^2 + v^2 - 2\\rho uv}{2(1-\\rho^2)} \\right)\n\\]\n\nNow,\n\\begin{align*}\nu^2 + v^2 - 2\\rho uv\n\t& = \\left(\\frac{1}{2}(x+y)\\right)^2 +\\left(\\frac{1}{2}(x-y)\\right)^2 - 2\\rho\\left(\\frac{1}{2}(x+y)\\right)\\left(\\frac{1}{2}(x-y)\\right) \\\\\n\t& = \\frac{1}{2}x^2(1-\\rho ) + \\frac{1}{2}y^2(1+\\rho )\n\\end{align*}\t\n\nThe joint PDF of $X$ and $Y$ is therefore\n\\begin{align*}\nf(x,y) \n\t& = \\frac{1}{2} \\frac{1}{2\\pi\\sqrt{1-\\rho ^{2}}}\\exp\\left( -\\frac{x^{2} (1-\\rho )}{4(1-\\rho ^{2} )} -\\frac{y^{2} (1+\\rho )}{4(1-\\rho ^{2})}\\right) \\\\\n\t& = \\frac{1}{\\sqrt{4\\pi(1+\\rho)}}\\exp\\left(-\\frac{x^{2}}{4(1+\\rho)}\\right) \\times \\frac{1}{\\sqrt{4\\pi(1-\\rho)}}\\exp\\left(-\\frac{y^{2}}{4(1-\\rho )}\\right) \\\\\n\\end{align*}\nThis is the product of the PDF of a $N\\big(0,2(1+\\rho)\\big)$ variable and the PDF of a $N\\big(0,2(1-\\rho)\\big)$ variable. Thus $X$ and $Y$ are independent. \n\\end{answer}\n\n\\question\nLet $X$ and $Y$ have bivariate normal distribution with means $\\mu_1$ and $\\mu_2$, variances $\\sigma_1^2$ and $\\sigma_2^2$, and correlation $\\rho$. Show that the conditional distribution of $Y$ given $X=x$ is\n\\[\nN\\left(\\mu_2 + \\rho\\left(\\frac{\\sigma_2}{\\sigma_1}\\right)(x-\\mu_1), \\sigma_2^2(1-\\rho^2)\\right).\n\\]\n\\begin{answer}\nTODO\n\\end{answer}\n%----------------------------------------\n\\question\n\\begin{parts}\n\\part % << (i)\nLet $X$ and $Y$ be jointly continuous random variables, and let $f_{X,Y}$ be their joint PDF. Show that the PDF of the random variable $X+Y$ can be written as\n\\[\nf_{X+Y}(t) \n\t= \\int_{-\\infty}^{\\infty} f_{X,Y}(x,t-x)\\,dx\n\t= \\int_{-\\infty}^{\\infty} f_{X,Y}(t-y,y)\\,dy.\n\\]\n\\begin{answer}\nLet $A = \\{(x,y):x+y\\leq z\\}\\subset\\R^2$. Then\n\\[\n\\prob(X+Y\\leq z)\n\t= \\iint_A f(x,y)\\,dxdy\n\t= \\int_{x=-\\infty}^{\\infty} \\int_{y=-\\infty}^{z-x}f_{X,Y}(x,y)\\,dy\\,dx\n\\]\nWe change the variable of integration (in the inner integral), making the substitution $y=t-x$:\n\\begin{align*}\nF_{X+Y}(z) = \\prob(X+Y\\leq z)\n\t& = \\int_{x=-\\infty}^{\\infty} \\int_{t=-\\infty}^{z}f_{X,Y}(x,t-x)\\,dt\\,dx \\\\\n\t& = \\int_{t=-\\infty}^{z} \\int_{x=-\\infty}^{\\infty}f_{X,Y}(x,t-x)\\,dx\\,dt\n\\end{align*}\nwhere the final equality follows by reversing the order of integration. Thus the PDF of $X+Y$ is \n\\[\nf_{X+Y}(t) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,t-x)\\,dx \\qquad\\text{as required.}\n\\]\n\\end{answer}\n\\part % << (ii)\nHence, or otherwise, show that if $U,V\\sim N(0,1)$ are independent, then $U+V\\sim N(0,2)$. (This is a special case of Theorem~\\ref{thm:sum_of_normal_variables}.)\n\\begin{answer}\nBy part (a), if two random variables $X$ and $Y$ are independent, the PDF of $X+Y$ is the \\emph{convolution} of the marginal PDFs:\n\\[\nf_{X+Y}(t) \n\t= \\int_{-\\infty}^{\\infty} f_X(x)f_Y(t-x)\\,dx\n\t= \\int_{-\\infty}^{\\infty} f_X(t-y)f_Y(y)\\,dy.\n\\]\n$U$ and $V$ are independent, so their joint PDF is\n\\[\nf(u,v)=f_U(u)f_V(v) = \\frac{1}{2\\pi}\\exp\\left(-\\frac{1}{2}(u^2 + v^2)\\right) \\qquad  u,v\\in\\R.\n\\]\nLet $W=U+V$. Then because $U$ and $V$ are independent, \n\\begin{align*}\nf_W(w) \n\t& = \\int_{-\\infty}^{\\infty} f_U(u)f_V(w-u)\\,du \\\\\n\t& = \\frac{1}{2\\pi} \\int_{-\\infty}^{\\infty} \\exp\\left[-\\frac{1}{2}\\left(u^2 + (w-u)^2\\right)\\right]\\,du \\\\\n\t& = \\frac{1}{2\\pi} e^{-\\frac{1}{4}w^2} \\int_{-\\infty}^{\\infty} \\exp\\left[-\\left(u-\\frac{w}{2}\\right)^2\\right]\\,du\n\\end{align*}\nWe change the variable of integration, by making the substitution $t = \\displaystyle\\sqrt{2}\\left(u-\\frac{w}{2}\\right)$:\n\\[\nf_W(w) \n\t= \\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{1}{4}w^2} \\int_{-\\infty}^{\\infty} \\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}w^2}\\,dv\n\t= \\frac{1}{2\\sqrt{\\pi}} e^{-\\frac{w^2}{4}},\n\\]\nwhich is the PDF of the $N(0,2)$ distribution\n\\end{answer}\n\\end{parts}\n\n\n%----------------------------------------\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n\n", "meta": {"hexsha": "5ff35661102f80f00bfefd9d6f07db3cb547441f", "size": 29267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/14_bivariate_normal.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/14_bivariate_normal.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/14_bivariate_normal.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.4433962264, "max_line_length": 528, "alphanum_fraction": 0.6003690163, "num_tokens": 11167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6135651876314199}}
{"text": "\n\\subsection{Frequent patterns}\n\n\\subsubsection{Frequent patterns}\n\nA frequent itemset is one where the support is above a minimum.\n\nWe know that if an itemset is frequent, then all its subsets are also frequent.\n\nWe look for frequent patterns, \\(F\\), between the items \\(I\\).\n\nAn example of a frequent pattern is \\(\\{a,b\\}\\).\n\n", "meta": {"hexsha": "b689474cdb55a0b79272de10745dd71ef3c7884e", "size": 328, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/association/01-04-frequent.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-04-frequent.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-04-frequent.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.4285714286, "max_line_length": 79, "alphanum_fraction": 0.737804878, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006919925839874, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6135651754399863}}
{"text": "%gln\n\\section{General linear group}\n\nAs the most prominent example of a functor, we will now discuss the following construction. Let $R$, again, denote a unital commutative ring.\n\\begin{defi}\nLet $\\mathfrak{F}$ be a finite category and $\\mathrm{UCRng}$ the category of unital commutative rings. The bifunctor\n$$\\bao{rrcl}\n\\mathrm{Gl} : &\\mathfrak{F} \\times \\mathrm{UCRng} &\\longrightarrow &\\mathrm{Grp},\\\\\n& (I,R) &\\longmapsto& Gl(I,R) := Gl_{|I|}(R),\\\\\n\\ea$$\nis a pairing of a finite set $I$, a ring $R$ and its group of $R$ module automorphism on the generic module $R^I$.\n\\end{defi}\n\\begin{coro}\nWe  immediately get\n$$\\bao{rcl}\nGl_0(R) &=& Gl(\\emptyset,R) = \\{1_R\\} \\ \\mathrm{and}\\\\\nGl_1(R) &=& Gl(\\mathcal{P}(\\emptyset),R)\\\\ &=& R^\\times = U(R)\\\\ &:=& \\{r \\in R : \\exists r' \\in R,\\ r r' = 1\\}.\\\\\n\\ea\\\\$$\n\\end{coro}\nBoth statements are clearly a consequence of our above definition.\n\\begin{theo}\nLet $I \\in \\mathfrak{F}$ be fixed with $|I| = i$ and let $R \\in \\mathrm{UCRng}$ be an ID then\n$$\\mathrm{Gl}_i \\simeq \\mathrm{Hom}_{\\mathrm{UCRng}}(\\mathbb{Z}[X,Y]/\\left<\\det X \\cdot Y - 1\\right>,\\ \\cdot\\ )$$\nas functors.\n\\end{theo}\nBefore we proceed in proofing the theorem, let us dwell in the above formular for a moment. Firstly, $X$ stands for $\\{X_{kl} : 1 \\leq k, l \\leq i\\}$ - a set of $i^2$ variables and\n$$\\mathbb{Z}[X,Y]/\\left<\\det X \\cdot Y - 1\\right> = \\mathbb{Z}[X_{kl},Y : 1 \\leq k, l \\leq i]/\\left<\\det \\left(\\bao{ccc}\nX_{11} & \\ldots & X_{1i}\\\\\n\\vdots&&\\vdots\\\\\nX_{i1}&\\ldots&X_{ii}\\ea\\right) \\cdot Y - 1\\right>$$\nfor the ring of the polynomial ring over $\\mathbb{Z}$ in $i^2 + 1$ indeterminants, factored out the ideal generated by $\\det X \\cdot Y - 1$. Thus, the right hand side claims that the class of all (unital commutative) ring homomorphisms into some ring $R$ are functorially isomorphic to $i$-th general linear group $\\mathrm{Gl}_i(R)$. %In classical algebraic geometry we would get the zero set:\n\n%$$Z(\\det X \\cdot Y - 1) = \\left\\{x \\in \\mathbb{A}^{i^2}_R \\simeq M_i(R) : \\det x \\in \\mathrm{Gl}_1(R)\\right\\}$$\n%and its spectral interpretation:\n%$$\\mathfrak{Z}(\\det X \\cdot Y - 1) = \\left\\{\\prm \\in \\mathrm{Spec}(\\mathbb{Z}[X,Y]/\\left<\\det X Y - 1\\right>) : \\det X Y - 1 \\in \\prm\\right\\}$$\n\nGiven some ring homomorphism $\\varphi : A := \\mathbb{Z}[X,Y]/\\left<\\det X Y - 1\\right> \\longrightarrow R$, we get\n$$\\mathrm{Spec}(\\varphi) = \\left[\\prm \\in \\mathrm{Spec}(R) \\longmapsto \\varphi^{-1}(\\prm) := \\{f \\in A : \\varphi(f) \\in \\prm\\}\\right],$$\nin particular\n$$\\varphi^{-1}(\\prm) \\in \\mathrm{Spec}(A).$$\nClearly, $\\mrm{Spec}(A)$ contains the elements\n$$\\prm_\\mu :=  \\left\\{\\sum_{kl} \\lambda_{kl} (X_{kl} - \\mu_{kl}) : \\mu = \\left(\\bao{ccc}\\mu_{11}&\\ldots&\\mu_{1i}\\\\\\vdots&&\\vdots\\\\\\mu_{i1}&\\ldots&\\mu_{ii}\\\\\\ea\\right), \\lambda_{kl} \\in A,\\ \\lambda_\\mu (X - \\mu) \\in \\ker eval_{\\mu}\\right\\}$$\nmapping the monomial $X$ to $\\mu$. As $A$ is a UFD and $(X_{kl} - \\mu_{kl})$ cannot have any other divisors we conclude $$\\ker eval_\\mu \\in \\spec{A},$$\nas $\\det \\mu \\cdot Y - 1 \\in R[Y]$ has roots in $R$ (i.e.: for all $\\det \\mu \\in \\mrm{Gl}_1(R)$) and more importantly, $(0) \\in \\spec{R}$.\nHere, we are using the following diagram:\n$$\\xymatrix{\nA \\ar[rr]^{eval_\\mu}\\ar[rrd]_f&&R[Y]\\ar[d]^{eval_{\\det \\mu^{-1}}}\\\\\n&&R.\\\\\n}$$\nThus, the pairing\n$$\\bao{rrcl}\nV :& \\mrm{Gl}_i(R) \\subset \\affr{i^2+1} &\\longrightarrow& \\spec{\\zz[X,Y]},\\\\\n&\\left(\\mu_{k,l},\\frac{1}{\\det \\mu}\\right)_{1\\leq k,l \\leq i} &\\longmapsto& \\left<X_{kl} - \\mu_{kl}, Y - \\det \\mu^{-1}\\right>\n\\ea$$\nlets us consider all points in $\\mrm{Gl}_i(R)$ as an algebraic set also as (families of) prime ideals in $\\zz[X,Y]$.", "meta": {"hexsha": "007935780349bf6c477ec49c7fc23e5e636d1b49", "size": 3597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grp_scheme/gln.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": "grp_scheme/gln.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": "grp_scheme/gln.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": 65.4, "max_line_length": 393, "alphanum_fraction": 0.6313594662, "num_tokens": 1436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6135592756325157}}
{"text": "\\section{How fast will Raft elect a leader when split votes are possible?}\n\\label{leaderelection:split:total}\n\nGiven a split vote rate, we can estimate the total election time.\nRaft will elect a leader as soon as an election term\nsuccessfully completes without a split vote. When a split vote occurs,\nit's likely that all servers have reset their timers, since servers do\nthis when they grant a vote (this isn't quite true when logs\ndiffer; see Section~\\ref{leaderelection:logsdiff}). Thus, the\nnext election term has the same probability of success as an entirely\nnew election and will take just as long. In other words, each election\nterm is essentially memoryless, and the number of election terms\nrequired in an election can be modeled as a geometric distribution,\nwhere the probability of success is the probability that a split vote\ndoes not occur. Therefore, Raft elections are expected to complete in\n$\\dfrac{1}{1-\\text{split vote rate}}$ election terms on average.\n\nIf a split vote occurs in a particular election term, the election term\ntakes about $1+M_s$ time units plus a one-way network latency to reset\nthe server's election timers. We do not include the time for the\ncandidate to record its own vote on disk, since this time can be\noverlapped with the RequestVote messages (with this optimization, the\ncandidate may not count its own vote towards leadership until the vote\nis durably recorded). After the vote is split, the cluster must wait\nanother election timeout before the next election term begins. This\nrepeats for each split vote, then the time for an election with no split\nvotes (from Section~\\ref{leaderelection:nosplit}) is additional. Thus, the\ntotal time for an election, $E_s$, is:\n\\begin{align*}\nE_s &= \\Big(\\sum_\\text{split votes} \\text{time for split vote}\\Big)\n +\n  \\Big(\\text{time for election with no split vote}\\Big) \\\\\n%\nE_s &= \\Big(\\sum_\\text{split votes} (1 + M_s + L)\\Big)\n +\n  \\Big(1 + M_s + 2L + W - U(0,\\dfrac{1}{2})\\Big) & \\\\\n%\n\\Ex[E_s] &= \\Big((\\frac{1}{1-\\text{split vote rate}} - 1) \\times\n            (1 + \\frac{1}{s+1} + \\Ex[L])\\Big)\n +\n  \\Big(1 + \\frac{1}{s+1} + 2\\Ex[L] + \\Ex[W] - \\dfrac{1}{4}\\Big) \\\\\n%\n\\Ex[E_s] &= \\frac{1}{1-\\text{split vote rate}} \\times\n            \\Big(1 + \\frac{1}{s+1} + \\Ex[L]\\Big)\n            + \\Ex[L] + \\Ex[W] - \\dfrac{1}{4}\n\\end{align*}\nwhere $L$ is the one-way network latency and $W$ is the latency for a\ndurable disk write.\n\nHoward~\\cite{Howard:2014} suggests an optimization to decrease the time\nfor an election after split votes occur. The optimization separates\nfollowers' timeouts from candidates' timeouts, where candidates select\nsmaller timeouts from a distribution with a smaller range. This results\nin faster iterations once split votes have occurred, though it risks\nadditional split votes. The remainder of this chapter does not use this\noptimization.\n\n\\begin{figure}\n\\centering\n\\includegraphics[height=5.5in]{leaderelection/overall}\n\\hspace{-2em}\n\\vcaption[expected overall election time]{\nThe expected total election times for various clusters,\nas defined by $\\Ex[E_s]$, with a fixed one-way network latency.\nIt excludes the time to write to stable\nstorage (which is usually negligible). The timeout range and\nexpected overall election time are presented as multiples of the one-way\nnetwork latency ($l$), since $l$ is typically fixed in a given\ndeployment.\n}\n\\label{fig:leaderelection:theory:overall}\n\\end{figure}\n\nFigure~\\ref{fig:leaderelection:theory:overall} plots the expected time to\nelect a leader when the network latency is fixed, by combining the\nformula for $\\Ex[E_s]$ with the formula for $Pr(D_{c,s} \\leq l)$.\nFrom the graphs, a Raft cluster with a sufficiently broad timeout range\nwill usually elect a leader within 20 times the one-way network latency,\neven when running with a bare majority of available servers. This\nsuggests that most datacenter Raft deployments should be able to achieve\ntypical leader election times under \\SI{100}{\\milli\\second}. Even worst\ncase global deployments, with one-way latencies of\n\\SI{200}{\\milli\\second},\nshould be able to typically elect leaders within \\SI{4}{seconds}. (Election\ntimes may be larger if some servers are deployed on other planets.)\n\nEach of the curves has a knee. If the timeout range is chosen to be too\nshort, too many servers time out before others are able to collect\nvotes, resulting in poor election times. Once timeout ranges are\nsufficiently large (about 3--8 times the network latency, depending on\nthe cluster), the curves become linear with a slight upward slope:\nelections complete after few or no split votes, but they must wait\nlonger for each timeout to elapse.\n\nThe graphs provide insight into how to configure election timeouts: a\nconservative setting is probably best in practice. The minimum point on\nthe graphs represents the best average election time possible for each\ngiven cluster configuration. However, attaining this minimum time is\nquite risky, since the minimum is close to the knee in the curve. If the\nnetwork latency turns out to be slightly higher than anticipated in\npractice, that might push the system into the left region of the graph\nwhere election times skyrocket. It is better to configure systems\nfarther to the right, trading off a slightly higher average election\ntime in exchange for a more robust system. Thus, we recommend using a\ntimeout range that is ten times the one-way network latency (even if the\ntrue network latency is five times greater than anticipated, most clusters would\nstill be able to elect a leader in a timely manner).\n", "meta": {"hexsha": "1ae608ae8b4be24e40a8c649ac15d90f32ec7bf6", "size": 5548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "leaderelection/splittotal.tex", "max_stars_repo_name": "ahrtr/dissertation", "max_stars_repo_head_hexsha": "7ad82c250a28c4a4d2406f43756ab2f8837292b3", "max_stars_repo_licenses": ["CC-BY-3.0", "CC-BY-4.0"], "max_stars_count": 788, "max_stars_repo_stars_event_min_datetime": "2015-01-28T14:25:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T06:58:22.000Z", "max_issues_repo_path": "leaderelection/splittotal.tex", "max_issues_repo_name": "ahrtr/dissertation", "max_issues_repo_head_hexsha": "7ad82c250a28c4a4d2406f43756ab2f8837292b3", "max_issues_repo_licenses": ["CC-BY-3.0", "CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-09-27T18:10:33.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-24T23:22:22.000Z", "max_forks_repo_path": "leaderelection/splittotal.tex", "max_forks_repo_name": "ahrtr/dissertation", "max_forks_repo_head_hexsha": "7ad82c250a28c4a4d2406f43756ab2f8837292b3", "max_forks_repo_licenses": ["CC-BY-3.0", "CC-BY-4.0"], "max_forks_count": 125, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:47:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T02:46:49.000Z", "avg_line_length": 51.3703703704, "max_line_length": 80, "alphanum_fraction": 0.7664023071, "num_tokens": 1382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473628, "lm_q2_score": 0.7401743735019594, "lm_q1q2_score": 0.6135592662487024}}
{"text": "%% -*- coding:utf-8 -*-\n\\chapter{Tensor product. Structure of finite K-algebras}\nThis is a digression on commutative algebra. We introduce and study\nthe notion of tensor product of modules over a ring. We prove a\nstructure theorem for finite algebras over a field (a version of the\nwell-known \"Chinese remainder theorem\").\n\n\n\\section{Definition of tensor product}\n\n\\subsection{Summary for previous lectures}\nWe considered finite \\mynameref{def:fextension1} $L$ i.e\n$\\left[L:K\\right] < \\infty$. We also saw that if\n$L$ is generated by a finite number of \\mynameref{def:degsepelem}s \n$\\alpha_1, \\dots, \\alpha_r$ then the number of\n\\mynameref{def:homomorphism}s over $K$ from $L$ to $\\bar{K}$ denoted by\n$\\left|Hom_K\\left(L, \\bar{K}\\right)\\right|$ is equal to\n$\\left[L:K\\right]$. In general\n\\[\n\\left[L:K\\right]_{sep} = \n\\left|Hom_K\\left(L, \\bar{K}\\right)\\right| \\le\n\\left[L:K\\right].\n\\]\n\nFor $L = K\\left(\\alpha\\right)$ it is clear because the number of\nhomomorphisms is equal to the number of roots of the\n\\mynameref{def:minpolynomial} $P_{min}\\left(\\alpha, K\\right)$. In\ngeneral one can use induction and multiplicativity of the degree\n$\\left[L:K\\right]$ and number of homomorphisms (see theorem\n\\mynameref{thm:lec3_3}). Thus  separable extension was exactly an\nextension  which had the right number of homomorphisms into the\nalgebraic closure.\n\nOur next goal is to characterize the separability in the terms of\ntensor product.\n\n\\subsection{Tensor product}\n\n\\begin{definition}[Tensor product]\n  Let $A$ is a ring, $N$, $M$ are $A$-\\mynameref{def:module}s. The\n  tensor product $M \\otimes_A N$\n  is another $A$-\\mynameref{def:module} together with an\n  $A$-bilinear map $\\phi: M \\times N \\to M \\otimes_A N$ which has\n  ``\\mynameref{def:universalproperty}'' defined below\n  \\label{def:tensorproduct}\n\\end{definition}\n\n\\begin{definition}[Universal property]\n  $A$-bilinear map $\\phi: M \\times N \\to M \\otimes_A N$ has\n  ``universal property'' if\n  $\\forall P$ - $A$-\\mynameref{def:module} and\n  for $A$-bilinear $f: M \\times N \\to P$ (\n  i.e.\n  \\(\n  \\forall m, f_m:\n  N \\xrightarrow[n \\to f(m,n)]{} P\n  \\)\n  and\n  \\(\n  \\forall n, f_n:\n  M \\xrightarrow[m \\to f(m,n)]{} P\n  \\)\n  are \\mynameref{def:homomorphism}s of $A$-modules\n  ), then\n  $\\exists! \\tilde{f}$ - homomorphism of $A$-modules such that\n  $f = \\tilde{f} \\circ \\phi$\n  \\footnote{\n    That means that we have a \\mynameref{def:commutativediagram} there\n  }\n\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            { M \\times N & & P \\\\\n              & M \\otimes_A N & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[auto] {$ f $} (m-1-3)\n            edge node[auto] {$ \\phi $} (m-2-2)\n            (m-2-2) edge node[auto] {$ \\tilde{f} $} (m-1-3);\n  \\end{tikzpicture}\n  \\label{def:universalproperty}\n\\end{definition}\n\nThe property characterize the pair\n$\\left(\\phi, M \\otimes N\\right)$.\nReally if have another pair\n$\\left(\\overline{\\phi}, \\overline{M \\otimes N}\\right)$\nlike this one then by definition we have mutually inverse\nhomomorphisms of $A$-modules between them\n\n\\begin{lemma}[About uniqueness of object defined by universal\n    property]\n  \\footnote{\n    It is out of the lecture video and can be considered as an\n    explanation for the claim about having mutually inverse\n    homomorphisms of $A$-modules. The proof was taken from\n    \\cite{bib:KeithConradTensorProduct1}.\n  }\n  If we have two objects $\\left(\\phi, M \\otimes N\\right)$\n  and $\\left(\\overline{\\phi},\\overline{M \\otimes N}\\right)$\n  which both satisfies \\mynameref{def:universalproperty} than there is\n  an unique \\mynameref{def:isomorphism} between them: \n  \\[\n  \\left(\\phi, M \\otimes N\\right) \\cong \\left(\\overline{\\phi},\n  \\overline{M \\otimes N}\\right)\n  \\]\n\\begin{proof}\nLet $P = \\overline{M \\otimes N}$ and $f =\n\\overline{\\phi}$. In \nthe case we can consider the following diagram\n\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          { & & M \\otimes_A N & \\\\\n            M \\times N & & \\overline{M \\otimes_A N} \\\\\n            & & M \\otimes_A N & \\\\ };\n          %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n          \\path[->]\n          (m-2-1) edge node[auto] {$ \\phi $} (m-1-3)\n          (m-1-3) edge node[auto] {$ g = \\tilde{\\overline{\\phi}} $} (m-2-3)\n          (m-2-1) edge node[auto] {$ \\overline{\\phi} $} (m-2-3)\n          (m-2-1) edge node[auto] {$ \\phi $} (m-3-3)\n          (m-2-3) edge node[auto] {$ \\bar{g} = \\tilde{\\phi} $} (m-3-3);\n\\end{tikzpicture}\n\nAs soon as we fixed $\\overline{ M \\otimes_A N}$\nwe 2 unique homomorphisms (which are defined by the fixed\n$\\overline{ M \\otimes_A N}$) - \n$g :  M \\otimes_A N \\to \\overline{ M \\otimes_A N}$\nand\n$\\bar{g} :  \\overline{M \\otimes_A N} \\to M \\otimes_A N$.\nBoth $g$ and $\\bar{g}$ are linear and, as mentioned above, the pair is\nunique (if we fix $g$ we will have only one $\\bar{g}$ that corresponds\nto $g$). The composition $g \\circ \\bar{g}$ maps $M \\otimes_A N$ to\nitself. I.e. $\\forall x \\in M \\times N$ we have\n$\\bar{g}\\left(g\\left(\\phi\\left(x\\right)\\right)\\right) =\n\\phi\\left(x\\right)$. If $y = \\phi\\left(x\\right)$ then\n$\\bar{g}\\left(g\\left(y\\right)\\right) = y$. The last equation holds\n$\\forall y \\in Im\\left(\\phi\\right)$ i.e. $\\forall y \\in M \\otimes_A\nN$. Therefore $\\bar{g} = g^{-1}$. \n\\footnote {\n  Another explanation is the following: thus if we fix $g$ and choose\n  $\\bar{g} = g^{-1}$ we will get $g \\circ \\bar{g} = id_{M \\otimes_A\n    N}$ that satisfied all requirements. The choice is final because\n  we don't have a possibility to choose any other $\\bar{g}$ (it should\n  be unique).\n}\n\nThus we have an\n\\mynameref{def:isomorphism} and the isomorphism is unique as soon as the\nfunction $g$ is unique due the \\mynameref{def:universalproperty}.\n\nWe just prove an isomorphism existence between\n$M \\otimes N$ and $\\overline{M \\otimes N}$ but the tensor product is\ncharacterized not only by the module $M \\otimes N$\nbut also a bilinear map $\\phi$. Let $P = \\overline{M \\otimes N}$ thus\nwe can get that $\\bar{\\phi} = \\tilde{\\bar{\\phi}} \\circ \\phi$ is\ndetermined by the unique\nrelation $\\phi \\to \\bar{\\phi}$ as soon as\n$\\tilde{\\bar{\\phi}}$ is unique.\nAnalogues one can get the unique relation\n$\\bar{\\phi} \\to \\phi$.\n\\end{proof}\n\\label{lem:universalpropertyuniqueness}\n\\end{lemma}\n\nThe uniqueness does not mean existence and we should proof that such\nobject exists.\n\\begin{lemma}[About tensor product existence]\n  Tensor product defined via \\mynameref{def:universalproperty} exists\n  \\begin{proof}\n    Lets consider $\\mathcal{E}$ the maps (functions) from\n    $M \\times N$ to $A$ as sets which are $0$ almost everywhere\n    (i.e. outside of a finite set). For example we can consider delta\n    functions:\n    \\[\n    \\delta_{m,n} : M \\times N \\to A\n    \\]\n    such that\n    \\begin{eqnarray}\n      \\delta_{m,n}(m,n) = 1,\n      \\nonumber \\\\\n      \\delta_{m,n}(m',n') = 0 \\mbox{ if } (m,n) \\ne (m',n')\n      \\nonumber \n    \\end{eqnarray}\n    Then $\\mathcal{E}$ is a A-\\mynameref{def:freemodule} with basis\n    $\\delta_{m,n}$. Thus we have a map of sets $M \\times N \\to\n    \\mathcal{E}$ such that $(m,n) \\to \\delta_{m,n}$ which is not bilinear\n    but we can make it bilinear by means of changing $\\mathcal{E}$.\n    \n    Let $\\mathcal{F} \\subset \\mathcal{E}$ a submodule generated by\n    $\\delta_{m+m',n} - \\delta_{m,n} - \\delta_{m',n}$,\n    $\\delta_{m,n+n'} - \\delta_{m,n} - \\delta_{m,n'}$,\n    $\\delta_{am,n} - a\\delta_{m,n}$,\n    $\\delta_{m,an} - a\\delta_{m,n}$.\n    \\footnote{\n      The basis is chosen to be a bilinear $\\mod \\mathcal{F}$, for instance\n      $\\delta_{m+m',n} = \\delta_{m,n} + \\delta_{m',n} \\mod \\mathcal{F}$\n    }\n    \n    It can be shown that $M \\times N \\to \\mathcal{E}/\\mathcal{F}$ is\n    bilinear\n    \\footnote{\n      Follows from the basis choice\n    }\n    and has the desired \\mynameref{def:universalproperty}.\n\n    Really lets we have the following bilinear map:\n    $f: M \\times N \\to P$. Then we can consider the following linear\n    map (\\mynameref{def:homomorphism})\n    $f': \\mathcal{E} \\to P$ that sends $\\delta_{m,n}$ to\n    $f(n,m)$. Using the fact that $f$ is bilinear we can get\n    \\begin{eqnarray}\n      f'(\\delta_{m+m',n}) =\n      f(m+m', n) = f(m, n) + f(m', n) =\n      \\nonumber \\\\\n      =\n      f'(\\delta_{m,n}) + f'(\\delta_{m',n}).\n      \\nonumber\n    \\end{eqnarray}\n    With the same approach one can get the following relations\n    \\begin{eqnarray}\n      f'(\\delta_{m,n+n'}) = f'(\\delta_{m,n}) + f'(\\delta_{m,n'}),\n      \\nonumber \\\\\n      f'(\\delta_{am,n}) =  a f'(\\delta_{m,n}),\n      \\nonumber \\\\\n      f'(\\delta_{m,an}) = a f'(\\delta_{m,n})\n      \\nonumber\n    \\end{eqnarray}\n    with the $f'$ linearity we have\n    \\begin{eqnarray}\n      f'(\\delta_{m+m',n}) = f'(\\delta_{m,n} + \\delta_{m',n}),\n      \\nonumber \\\\\n      f'(\\delta_{m,n+n'}) = f'(\\delta_{m,n} + \\delta_{m,n'}),\n      \\nonumber \\\\\n      f'(\\delta_{am,n}) =  a f'(\\delta_{m,n}),\n      \\nonumber \\\\\n      f'(\\delta_{m,an}) = a f'(\\delta_{m,n})\n      \\nonumber\n    \\end{eqnarray}\n\n    The kernel $\\ker f' = \\mathcal{F}$ thus if we want to have a\n    homomorphism to $P$ we have to replace $\\mathcal{E}$ with\n    $\\mathcal{E}/\\mathcal{F}$ that is also denoted by\n    $M \\otimes_A N$. In the case we will replace $f'$ with\n    $\\tilde{f}\\left(\\delta_{m,n} \\mod \\mathcal{F}\\right) = f(m,n)$. As\n    soon as the images for the basis is fixed the mapping is unique.\n  \\end{proof}\n  \\label{lem:tensorproductexistence}\n\\end{lemma}\n\nWe will denote $\\phi\\left(m,n\\right) = \\delta_{m,n} \\mod \\mathcal{F}$ as\n$m \\otimes n$. I.e our tensor product can be considered as the \n$\\left(\\otimes, M \\otimes_A N\\right)$ pair.\n\n\n\\begin{remark}\n  Wrong idea is to define $M \\otimes_A N$\n  as a set of $m \\otimes n$. I.e.\n  $M \\otimes_A N \\neq \\{m \\otimes n\\}$. The $M \\otimes_A N$ is\n  generated by $m \\otimes n$ i.e. \n  $\\forall x \\in M \\otimes_A N$ we have\n  $x = \\sum_{i = 1}^k m_i \\otimes n_i$ i.e. each element is a finite\n  sum of $m \\otimes n$ and I cannot reduce these further\n  \\footnote{\n    i.e. $\\exists x \\in M \\otimes_A N$ such that\n    $\\exists! m \\in M, n \\in N: x = m \\otimes n$ but\n    $\\exists m_1, \\dots, m_k \\in M, n_1, \\dots, n_k \\in N :\n    x = \\sum_{i = 1}^k m_i \\otimes n_i$\n  }. \n\n\\end{remark}\n\n\\section{Tensor product of modules}\n\n\\subsection{Advantages of the universal property}\nNow, you can ask  why haven't I just defined the tensor product by\nthis construction? Why am I talking of this universal property? \nAnd the answer is because it is easier to prove things this way. \nSo advantages of the universal property is as follows: the proofs\nbecome easy.\n\n\\subsection{Several examples of universal property usage}\n\n\\begin{example}[Commutativity proof]\n  We want to prove that\n  \\[\n  M \\otimes_A N \\cong N \\otimes_A M\n  \\]\n\n  We have the following bilinear map:\n  $M \\times N \\to N \\otimes_A M$ for which the pair\n  $(m,n)$ is mapped to $n \\otimes m$. Thus from\n  \\mynameref{def:universalproperty} we have that there is a linear map\n  (homomorphism)\n  $\\alpha: M \\otimes_A N \\to N \\otimes_A M$:\n  \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            { M \\times N & & N \\otimes_A M \\\\\n              & M \\otimes_A N & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[auto] {$ (m,n) \\to n \\otimes m $} (m-1-3)\n            (m-1-1) edge node[description] {$ (m,n) \\to m \\otimes n $} (m-2-2)\n            (m-2-2) edge node[description] {$ \\alpha $} (m-1-3);\n  \\end{tikzpicture}\n\n  \n  With the same\n  construction we can also get the inverse map $a^{-1}$ that sends\n  $N \\otimes_A M$ to $M \\otimes_A N$:\n  \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            { M \\times N & & M \\otimes_A N \\\\\n              & N \\otimes_A M & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[auto] {$ (m,n) \\to m \\otimes n $} (m-1-3)\n            (m-1-1) edge node[description] {$ (m,n) \\to n \\otimes m $} (m-2-2)\n            (m-2-2) edge node[description] {$ \\alpha^{-1} $} (m-1-3);\n  \\end{tikzpicture}\n  \n\\end{example}\n\nAlso\n\\begin{corollary}\n\\[\nA \\otimes_A M \\cong M\n\\]\n\\begin{proof}\n  For the proof\n  \\footnote{\n    The proof is missed in the lectures\n  }\n  lets look at $A$. \n  Really $A$ can be considered as $A$-module because all\n  requirements from definition \\ref{def:module} are satisfied. The\n  following diagrams shows that there exist 2 homomorphisms:\n  $\\alpha: A \\otimes_A M \\to M$ and\n  $\\alpha^{-1}: M \\to A \\otimes_A M$ as result there is a homomorphism\n  $A \\otimes_A M \\cong M$:\n\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 \\times M & & M \\\\\n              & A \\otimes_A M & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[auto] {$ (a,m) \\to a \\cdot m $} (m-1-3)\n            (m-1-1) edge node[description] {$ (a,m) \\to a \\otimes_A m $} (m-2-2)\n            (m-2-2) edge node[description] {$ \\alpha $} (m-1-3);\n  \\end{tikzpicture}\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 \\times M & & A \\otimes_A M \\\\\n              & M & \\\\ };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-1-1) edge node[auto] {$ (a,m) \\to a \\otimes_A m $} (m-1-3)\n            (m-1-1) edge node[description] {$ (a,m) \\to a \\cdot m $} (m-2-2)\n            (m-2-2) edge node[description] {$ \\alpha^{-1} $} (m-1-3);\n  \\end{tikzpicture}\n  \n  In the diagrams $m \\in M$, as usual, and $a \\in A$.\n  \n\\end{proof}\n\\end{corollary}\n\nIf we have that $M$ is generated by $e_1, e_2, \\dots$ and\n$N$ is generated by $\\epsilon_1, \\epsilon_2, \\dots$ than\n$M \\otimes_A N$ is generated by pairs $e_i \\otimes \\epsilon_j$. It's\nobvious.\n\nMore complex fact is the following\n\\begin{proposition}\n  Let $M$ and $N$ are \\mynameref{def:freemodule}s\n  with corresponding basises $e_1, e_2, \\dots, e_n$ and\n  $\\epsilon_1, \\epsilon_2, \\dots, \\epsilon_m$ than\n  $M \\otimes_A N$ is also free module with basis $e_i \\otimes\n  \\epsilon_j$ where $1 \\le i \\le n$ and\n  $1 \\le j \\le m$.\n  \\begin{proof}\n    Lets define\n    $f_{i_0,j_0}: M \\times N \\to A$ as a map that sends\n    $\\left(\\sum a_i e_i, \\sum b_j \\epsilon_j\\right)$ to\n    $a_{i_0} b_{j_0}$. It's bilinear\n    \\footnote{\n      for example\n      $\\left(\\sum (a_i + a_i') e_i, \\sum b_j \\epsilon_j\\right)$ is\n      sent to  $(a_{j_0} + a_{j_0}') b_{j_0}$.\n    }\n    so it factors through the tensor product\n    $\\tilde{f}_{i_0, j_0} : M \\otimes_A N \\to A$. The map\n    $\\tilde{f}_{i_0, j_0}$ sends $e_{i_0} \\otimes \\epsilon_{j_0}$ to 1\n    and all others to 0.\n    \\footnote{\n      Because $f_{i_0, j_0} = \\tilde{f}_{i_0, j_0} \\phi$ i.e.\n      \\begin{eqnarray}\n      a_{i_0} b_{j_0} =\n      f_{i_0,j_0}\\left(\\sum a_i e_i, \\sum b_j\\epsilon_j\\right) =\n      \\nonumber \\\\\n      =  \\tilde{f}_{i_0,j_0}\\left(\n      \\phi\\left(\\sum a_i e_i, \\sum b_j\\epsilon_j\\right)\\right) = \n      \\nonumber \\\\\n      =\n      \\tilde{f}_{i_0,j_0}\\left(\\sum a_i e_i \\otimes \\sum b_j\n      \\epsilon_j\\right) =\n      \\sum_{i,j} a_i b_j \\tilde{f}_{i_0,j_0}(e_i \\otimes \\epsilon_j).\n      \\nonumber\n      \\end{eqnarray}\n    }\n    So if\n    \\[\n    \\sum \\alpha_{ij} e_i \\otimes \\epsilon_j = 0\n    \\]\n    then applying $\\tilde{f}_{i_0, j_0}$ for all indices one can get\n    that $\\forall i,j: \\alpha_{ij} = 0$.\n    \\footnote{\n      because $\\tilde{f}$ should be linear.\n    }\n  \\end{proof}\n  \\label{prop:lec4_1}\n\\end{proposition}\n\nIn particular for the \\mynameref{def:vectorspace} the tensor product is\ndefined in the same way (as just proved in the proposition\n\\ref{prop:lec4_1}): the tensor product of 2 vector spaces with\nbasises $e_1, e_2, \\dots, e_n$ and\n$\\epsilon_1, \\epsilon_2, \\dots, \\epsilon_m$ is another vector space\nwith the following basis $e_i \\otimes \\epsilon_j$ i.e. the definition\ndoes not take into consideration the \\mynameref{def:universalproperty}.\n\n\\begin{proposition}[Associative]\n  \\[\n  \\left(M_1 \\otimes_A M_2\\right) \\otimes_A M_3\n  \\cong\n  M_1 \\otimes_A \\left(M_2 \\otimes_A M_3\\right)\n  \\]\n  \\begin{proof}\n    There is just a scratch of the proof.\n    Introduce\n    $M_1 \\otimes_A M_2 \\otimes_A M_3$\n    as a universal object for 3-linear maps and show that 2 considered\n    parts are isomorphic each other.\n  \\end{proof}\n  \\label{prop:lec4_Associative}\n\\end{proposition}\n\n\\section{Base change}\n\nLet $A$ is a \\mynameref{def:ring} and $B$ is $A$-algebra. Let also $M$\nis an $A$-\\mynameref{def:module} and $N$ is $B$-module.\n\nI can of course make $N$ into $A$-module (just forgetting the\nadditional $A$-algebra structure). But we can also make $B$-module on\n$M$ (that is not a trivial thing) by considering $B \\otimes_A M$\n\\footnote{\n  In other words we can make a $B$-module from $A$-module $M$\n}\n.\nWe can introduce $B$-module structure on $B \\otimes_A M$ by\n\\footnote{\n  I.e. we introduced $B$-algebra operations for objects from\n  $B \\otimes_A M$. See also definition \\ref{def:kalgebra}.\n}\n\\[\nb \\cdot \\left(b' \\otimes m \\right) = \\left( b \\cdot b' \\right) \\otimes m \n\\]\n\n\\begin{example}[The complexification of a real vector space]\n  We can ``make'' $\\mathbb{R}^{2n}$ from $\\mathbb{C}^n$ by forgetting\n  the complex structure.\n  \\footnote{\n    In the case we have ring $A = \\mathbb{R}$ and $B = \\mathbb{C}$ -\n    $A$ algebra. $A$ - module is the following vector space\n    $M = \\mathbb{R}^{n}$ and $B$ - module is $N = \\mathbb{C}^n$.\n  }\n  The $\\mathbb{C}^n$ has the following basis $e_1, \\dots, e_n$.\n  The $\\mathbb{R}^{2n}$ has the following one\n  $e_1, \\dots, e_n, i e_1, \\dots, i e_n$. Now we forgot about\n  multiplication rules for $i = \\sqrt{-1}$ and denote $i e_i$ as\n  $v_i$. In the case the basis for $\\mathbb{R}^{2n}$ is the following\n  one: $e_1, \\dots, e_n, v_1, \\dots, v_n$.\n\n  But we can also do the following constructions\n  \\[\n  \\mathbb{R}^n \\rightarrow\n  \\mathbb{C}^n = \\mathbb{C} \\otimes \\mathbb{R}^n \\rightarrow\n  \\mathbb{R}^{2n}\n  \\]\n  for the $\\mathbb{C}^n$ basis we have\n  $1_{\\mathbb{C}} \\otimes e_1, \\dots, 1_{\\mathbb{C}} \\otimes e_n$ and\n  for\n  $\\mathbb{R}^{2n}$ -\n  $1 \\otimes e_1, \\dots, 1 \\otimes e_n, i \\otimes e_1, \\dots, i\n  \\otimes e_n$.\n  \\footnote{\n    some additional clarification:\n    $\\forall x \\in \\mathbb{C} \\otimes \\mathbb{R}^n$ we have\n    \\[\n    x = \\sum_{i=1}^n c_i \\otimes r_i e_i =\n    \\sum_{i=1}^n c_i r_i 1_{\\mathbb{C}} \\otimes e_i =\n    \\sum_{i=1}^n c_i' 1_{\\mathbb{C}} \\otimes e_i,\n    \\]\n    where $c_i,c_i'=c_i r_i \\in \\mathbb{C}, r_i \\in \\mathbb{R}$. Thus\n    we just got $\\mathbb{C}^n$. \n    From other side we can write $c_i$\n    as follows: $c_i = a_i + i b_i$, where $a_i, b_i \\in \\mathbb{R}$.\n    Therefore\n    \\[\n    x = \\sum_{i=1}^n a_i r_i 1 \\otimes e_i + \\sum_{i=1}^n b_i r_i i \\otimes e_i.\n    \\]\n    I.e. $x \\in \\mathbb{R}^{2n}$ and the basis in $\\mathbb{R}^{2n}$ is\n    formed by $1 \\otimes e_1, \\dots, 1 \\otimes e_n, i \\otimes e_1,\n    \\dots, i \\otimes e_n$.\n  }\n\n\\end{example}\n\n\\begin{proposition}\nIn general we have the following. If $M$ - free $A$ - module with\nbasis $e_1, \\dots, e_n$ then $B \\otimes_A M$ is a free $B$ module with\nbasis $1_B \\otimes e_1, \\dots, 1_B \\otimes e_n$.\n\\label{prop:lec4_Addon}\n\\begin{proof}\n  The proof is the same as at proposition \\ref{prop:lec4_1}. Again we\n  construct certain bilinear maps and say that those factor over the\n  tensor product and this implies that certain families are linearly\n  independent.\n\n  Really lets define bilinear map $f_{i_0}: B \\times M \\to A$ such that\n  \\[\n  f_{i_0}\\left(b, \\sum_{i=1}^n m_i e_i\\right) = b m_{i_0} e_{i_0}\n  \\]\n  so there exists a linear map $\\tilde{f}_{i_0}$ (homomorphism) such\n  that $f_{i_0} = \\tilde{f}_{i_0} \\phi$ or\n  \\begin{eqnarray}\n    f_{i_0}\\left(b, \\sum_{i=1}^n m_i e_i\\right) =\n    \\tilde{f}_{i_0} \\left(\n    \\phi\\left(b, \\sum_{i=1}^n m_i e_i\\right)\n    \\right)\n    \\nonumber \\\\\n    =\n    \\tilde{f}_{i_0}\\left(b \\otimes \\sum_{i=1}^n m_i e_i\\right) =\n    b \\tilde{f}_{i_0}\\left(1_B \\otimes \\sum_{i=1}^n m_i e_i \\right) =\n    b m_{i_0}\n    \\nonumber\n  \\end{eqnarray}\n  i.e. it sends $1_B \\otimes e_{i_0}$ to 1 and all others $1_B \\otimes\n  e_i$ to 0.\n  Thus the following sum $\\sum \\alpha_i 1_B \\otimes e_i$ is equal to 0\n  if and only if $\\alpha_i = 0$ i.e. $\\alpha_i 1_B \\otimes e_i$ forms a basis.\n\\end{proof}\n\\end{proposition}\n\n\\begin{remark}\nWe have the following maps.\n\\begin{itemize}\n  \\label{item:lec4_maps}\n\\item For A - modules:\n  $\\alpha: M \\xrightarrow[m  \\to 1_B \\otimes_A m]{} B \\otimes_A M$\n  which makes a $B$-module from an $A$-module.\n\\item For B - modules:\n  $\\mu: B \\otimes_A N \\xrightarrow[b \\otimes n \\to b n]{} N$.\n\\end{itemize}\n\\label{rem:lec4_maps}\n\\end{remark}\n\n\\begin{theorem}[Base-change]\n  Let $A$ is a \\mynameref{def:ring} and $B$ is $A$-algebra. Let also $M$\n  is an $A$-\\mynameref{def:module} and $N$ is $B$-module.\n  \\[\n  Hom_A\\left(M, N\\right)\n  \\leftrightarrow\n  Hom_B\\left(B \\otimes_A M, N\\right)\n  \\]\n  I.e. the homomorphisms\n  \\footnote{\n    $A$-homomorphisms between $A$ modules $Hom_A\\left(M, N\\right)$ are the\n    same as $B$-homomorphisms between $B$ modules\n    $Hom_B\\left(B \\otimes_A M, N\\right)$.\n  }\n  are the same or in other words the\n  corresponding groups of homomorphisms are isomorphic:\n  \\[\n  Hom_A\\left(M, N\\right)\n  \\cong\n  Hom_B\\left(B \\otimes_A M, N\\right)\n  \\]\n  \\label{thm:basechange}\n  \n  \\begin{proof}\n    First of all we have\n    \\footnote{\n      One homomorphism from  $Hom_B\\left(B \\otimes_A M, N\\right)$\n    }\n    \\mynameref{def:homomorphism} $f: B \\otimes_A M \\to N$. We also have\n    the following map (see remark \\ref{rem:lec4_maps}):\n    $\\alpha: M \\to B \\otimes_A M$. \n    Thus $f \\cdot \\alpha: M \\to N$ i.e.\n    we can set the following relation\n    \\[\n    \\hat{f} : Hom_B\\left(B \\otimes_A M, N\\right)\n    \\to Hom_A\\left(M, N\\right)\n    \\]\n    such that $\\hat{f}\\left(f\\right) = f \\alpha$.\n\n    In other direction we have $g: M \\to N$ thus\n    $id_B \\otimes g: B \\otimes_A M \\to B \\otimes_A N$ but\n    ( see remark \\ref{rem:lec4_maps}) we have\n    $\\mu: B \\otimes_A N \\to N$ i.e. we have the following relation\n    \\[\n    \\hat{g} : Hom_A\\left(M, N\\right) \\to\n    Hom_B\\left(B \\otimes_A M, N\\right)\n    \\]\n    such that\n    \\[\n    \\hat g(g) = \\mu \\cdot (id_B \\otimes g).\n    \\]   \n    And we can check that those maps ($\\hat{f}$ and $\\hat{g}$) are\n    mutually inverse. For the proof\n    \\footnote{\n      It's missed in the lectures\n    }\n    the fact consider the following diagram\n    \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              { M  & &  N \\\\\n                & B \\otimes_A M & & B \\otimes_A N \\\\ };\n              %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n              \\path[->]\n              ([yshift=1ex]m-1-1.east) edge node[description] {$ f \\alpha $}\n              ([yshift=1ex]m-1-3.west); \n              \\path[->]\n              ([yshift=-1ex]m-1-1.east) edge node[description] {$ g $}\n              ([yshift=-1ex]m-1-3.west);\n              \\path[->]\n              (m-1-1) edge node[description] {$ \\alpha $} (m-2-2)\n              (m-2-2) edge node[description] {$ f $} (m-1-3)\n              (m-2-2) edge node[description] {$ id_B \\otimes g $}\n              (m-2-4)\n              (m-2-4) edge node[description] {$ \\mu $} (m-1-3)\n              ;\n    \\end{tikzpicture}\n    \n    One can conclude, as soon as the diagram commutes\n    \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              { M  & &  N \\\\\n                & B \\otimes_A M & & B \\otimes_A N \\\\ };\n              %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n              \\path[->]\n              ([yshift=-1ex]m-1-1.east) edge node[description] {$ g $}\n              ([yshift=-1ex]m-1-3.west);\n              \\path[->]\n              (m-1-1) edge node[description] {$ \\alpha $} (m-2-2)\n              (m-2-2) edge node[description] {$ id_B \\otimes g $}\n              (m-2-4)\n              (m-2-4) edge node[description] {$ \\mu $} (m-1-3)\n              ;\n    \\end{tikzpicture}\n\n    \n    \\[\n    \\hat{f}\\left(\\hat{g}\\left(g\\right)\\right) =\n    \\mu \\cdot (id_B \\otimes g) \\cdot \\alpha = g.\n    \\]\n    I. e. $\\hat{f}\\circ\\hat{g} = id$\n    \\footnote {\n      Operation $\\circ$ is defined as follows $(\\hat{a} \\circ \\hat{b})(x) =\n      \\hat{a}(\\hat{b}(x))$ where $\\hat{a}, \\hat{b}$ are 2 maps acting\n      on a set $X$ and $x \\in X$.\n    }\n    or in other words $\\hat{f}$ and\n    $\\hat{g}$ are mutually inverse. \n  \\end{proof}\n\\end{theorem}\n\n\\section{Examples. Tensor product of algebras}\n\n\\begin{proposition}\n  If $I \\subset A$ - is an \\mynameref{def:ideal} so my $B$ - $A$ algebra\n  will be $B = A/I$ then\n  \\[\n  A/I \\otimes_A M \\cong M/IM\n  \\]\n  where $IM$ is a sub-module of $M$.\n  \\label{prop:lec4_prop2}\n  \\begin{proof}\n    We have map $\\alpha: M \\to B \\otimes_A M = A/I \\otimes_A M$\n    (see remark \\ref{rem:lec4_maps}) \n    which sends $m$ to $\\bar{1} \\otimes m$.\n    \\footnote{\n      $\\bar{1} = 1_A + I$\n    }\n    The map sends $IM$ to $0$\n    because\n    $\\forall i \\in I, m \\in M : im \\to \\bar{1} \\otimes im = \\bar{i} \\otimes m$\n    because the tensor product is over $A$ and everything is $A$\n    linear and as result $\\bar{1} \\otimes im = \\bar{i} \\otimes m$,\n    but $\\bar{i} \\otimes m = \\bar{0} \\otimes m = 0$.\n    \\footnote{\n      because\n      $\\bar{i} = 0 \\mod I$\n    }\n    Thus $\\alpha$ sends $IM$ to 0. So $\\alpha$ induces\n    $\\bar{\\alpha}: M/IM \\to A/I \\otimes_A M$ such that\n    $\\bar{\\alpha}\\left(\\bar{m}\\right) = \\bar{1} \\otimes m$.\n\n    For other direction we apply \\mynameref{thm:basechange}. The\n    following map (projection) of $A$-modules\n    \\[\n    M \\xrightarrow{m \\to \\bar{m}} M/IM\n    \\]\n    gives us the following map of $B$-modules\n    \\footnote{\n      the \\mynameref{thm:basechange} says that homomorphism of\n      $A$-modules $M \\to N$ is isomorphic to homomorphism of $B$\n      modules $B\\otimes_A M \\to N$. Using $N = M/IM$ we can get that\n      $B\\otimes_A M \\to M/IM$ is isomorphic (i.e. the same) to\n      $M \\to M/IM$. We also can get the same result just ignore $B$:\n      $B \\otimes_A M \\to M \\to M/IM$.\n    }\n    \\[\n    \\bar{\\beta}: B \\otimes_A M \\to M/IM\n    \\]\n    i.e.\n    \\[\n    \\bar{\\beta}: A/I \\otimes_A M \\to M/IM\n    \\]\n    that sends $\\bar{a} \\otimes m$ to $\\bar{am}$\n    Ones check again that this inverse to $\\bar{\\alpha}$.\n    \\footnote{\n      For example\n      \\(\n      \\bar{\\beta}\\left(\\bar{\\alpha}\\left(\\bar{m}\\right)\\right) =\n      \\bar{\\beta}\\left(\\bar{1} \\otimes m\\right) = \\overline{1 \\cdot m} = \\bar{m}\n      \\)\n    }\n  \\end{proof}\n\\end{proposition}\n\nSeveral examples:\n\\begin{example}\n  Let $\\mathbb{Z}/2\\mathbb{Z} \\otimes_\\mathbb{Z}\n  \\mathbb{Z}/3\\mathbb{Z}$ what will we obtain?\n  \\[\n  \\mathbb{Z}/2\\mathbb{Z} \\otimes_\\mathbb{Z} \\cong\n  ^{\\mathbb{Z}/3\\mathbb{Z}}/_{(2) \\cdot \\mathbb{Z}/3\\mathbb{Z}}\n  \\]\n  but 2 is invertible: $2^{-1} = -1 \\mod 3$\n  \\footnote{\n    I.e. there exist an invertible element $2^{-1} \\in\n    \\mathbb{Z}/3\\mathbb{Z} = \\mathbb{F}_3$ therefore\n    $1_{\\mathbb{F}_3} \\in 2 \\cdot \\mathbb{F}_3$ or\n    $2 \\cdot \\mathbb{F}_3 = \\mathbb{F}_3$ and as result\n    $(2) \\cdot \\mathbb{F}_3 = \\mathbb{F}_3$. I.e. $(2)$ is not a\n    \\mynameref{def:properideal} in $\\mathbb{F}_3$ because it is equal\n    to $\\mathbb{F}_3$.\n  }\n  thus\n  $(2)\\mathbb{Z}/3\\mathbb{Z} =\\mathbb{Z}/3\\mathbb{Z}$ and as result\n   \\[\n  \\mathbb{Z}/2\\mathbb{Z} \\otimes_\\mathbb{Z} \\cong\n  ^{\\mathbb{Z}/3\\mathbb{Z}}/_{ \\mathbb{Z}/3\\mathbb{Z}} = 0\n  \\]\n\\end{example}\n\n\\begin{example}\n  Another obvious example\n  \\footnote {\n    $B \\otimes_A A\\left[X\\right]$ has the following $B$-basis:\n    $\\{1_B \\otimes X^i\\}$ thus\n    $\\forall b \\in B \\otimes_A A\\left[X\\right]$ we can get\n    \\[\n    b = \\sum b_i \\cdot 1_B \\otimes X^i\n    \\]\n    and there is an obvious isomorphism\n    \\[\n    f: B \\otimes_A A\\left[X\\right]\n    \\xrightarrow[b \\to \\sum b_i X^i]{}\n    B\\left[X\\right]\n    \\]\n  }\n  \\[\n  B \\otimes_A A\\left[X\\right] \\cong B\\left[X\\right]\n  \\]\n  and more interesting one\n  \\[\n  B \\otimes_A A\\left[X\\right]/(P) \\cong B\\left[X\\right]/(P),\n  \\]\n  there $(P)$ becomes an ideal generated by $P$ in\n  $B\\left[X\\right]$.\n  \\label{ex:lec4_1}\n\\end{example}\n\n\\subsection{Tensor product of A-algebras}\n\nLet $B, C$ are $A$-algebras. The following maps form an algebra\nstructure on $A$:\n\\[\n\\alpha: A \\to B\n\\]\n\\[\n\\beta: A \\to C\n\\]\nNew $A$-algebra $B \\otimes_A C$: is a ring with respect to the\nfollowing operation\n\\footnote{\n  that makes it $A$-algebra (see \\mynameref{def:kalgebra})\n}\n\\begin{equation}\n\\left(b \\otimes c \\right) \\cdot \\left(b' \\otimes c'\\right) =\n\\left(b \\cdot b'\\right) \\otimes \\left(c \\cdot c'\\right)\n\\label{eq:lec4_algebra_tensor_product}\n\\end{equation}\n\nThe tensor product has the following \n\\begin{definition}[Universal property]\n  Let we have the following maps\n  \\begin{eqnarray}\n    \\alpha: A \\to B,\n    \\nonumber \\\\\n    \\beta: A \\to C,\n    \\nonumber \\\\\n    \\phi: B \\xrightarrow[b \\to b \\otimes 1_C ]{} B \\otimes_A C,\n    \\nonumber \\\\\n    \\psi: C \\xrightarrow[c \\to 1_B \\otimes c ]{} B \\otimes_A C\n    \\nonumber\n  \\end{eqnarray}\n\n  Then for any $A$-algebra $D$ one has\n  \\[\n  Hom_A\\left(B \\otimes_A C, D\\right)\n  \\leftrightarrow\n  Hom_A\\left(B, D\\right) \\times\n  Hom_A\\left(C, D\\right)\n  \\]\n  i.e. if I have some \\mynameref{def:homomorphism}\n  $h \\in Hom_A\\left(B \\otimes_A C, D\\right)$ this is the same as\n  giving 2 homomorphisms\n  $f \\in Hom_A\\left(B, D\\right)$ and\n  $g \\in Hom_A\\left(C, D\\right)$ such that all maps in the following\n  diagram commute (see \\mynameref{def:commutativediagram}).\n  \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            { D & & B \\otimes C & \\\\\n              & B & & C & \\\\\n              & & A & & \\\\\n            };\n            %\\draw[double,double distance=5pt] (m-1-1) – (m-1-3);\n            \\path[->]\n            (m-2-2) edge node[description] {$ \\phi $} (m-1-3)\n            (m-2-4) edge node[description] {$ \\psi $} (m-1-3)\n            (m-3-3) edge node[description] {$ \\alpha $} (m-2-2)\n            (m-3-3) edge node[description] {$ \\beta $} (m-2-4)\n            (m-1-3) edge [bend right=15] node[description]  {$ h $}\n            (m-1-1);\n            \\path[->, dashed]\n            (m-2-2) edge [bend left=15] node[description] {$ f $} (m-1-1)\n            (m-2-4) edge [bend left=15] node[description] {$ g $} (m-1-1)\n            ;\n  \\end{tikzpicture}\n\n  Thus if we have $h$ then we can define\n  $f = h \\cdot \\phi$ and $g = h \\cdot \\psi$. And conversely if I have\n  $f$ and $g$ then I can define $h$ by the following rule:\n  \\[\n  h\\left(b \\otimes c\\right) = f(b) \\cdot g(c)\n  \\]\n\\end{definition}\nThe main point for us is that the tensor product of the $A$-algebras is\nitself an $A$-algebra by this very simple rule, component-wise\nmultiplication (see (\\ref{eq:lec4_algebra_tensor_product})).  \n\nLet consider next example.\nWe will start with the following\n\\[\n\\mathbb{C} \\cong {\\mathbb{R}\\left[X\\right]}/{\\left(X^2 + 1\\right)}\n\\]\ntherefore with result from example \\ref{ex:lec4_1} one can get\n\\[\n\\mathbb{C} \\otimes_\\mathbb{R} \\mathbb{C}\n\\cong\n\\mathbb{C} \\otimes_\\mathbb{R}\n{\\mathbb{R}\\left[X\\right]}/{\\left(X^2 + 1\\right)}\n\\cong\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X^2 + 1\\right)}\n\\]\nbut by \\mynameref{thm:chineseremainder} \n\\[\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X^2 + 1\\right)}\n\\cong\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X + i\\right)}\n\\times\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X - i\\right)}\n\\cong\n\\mathbb{C} \\times \\mathbb{C}\n\\]\nAs result we have that\n$\\mathbb{C} \\otimes_\\mathbb{R} \\mathbb{C}$ is not a field\nbecause it\nhas zero divisors. How we can get the zero divisors? \nThe element $\\overline{X + i}$ is a zero divisor\nin\n\\(\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X^2 + 1\\right)}\n\\)\nbecause\n\\[\n\\left(X + i\\right) \\left(X - i\\right) \\equiv 0 \\mod {\\left(X^2 + 1\\right)}\n\\].\n\nAnother proof (not a part of the lecture) of the fact that $\\mathbb{C}\n\\otimes_\\mathbb{R} \\mathbb{C}$ is not a field consider the following\none\n\\[\n\\mathbb{C}\n\\otimes_\\mathbb{R} \\mathbb{C}\n\\cong\n^{\\mathbb{C}\\left[X\\right]}/_{\\left(X^2 + 1\\right)}\n\\]\nbut the polynomial $X^2 + 1 = \\left(X + i\\right)\\left(X - i \\right)$\nis reducible in $\\mathbb{C}\\left[X\\right]$ i.e. is not a\n\\mynameref{def:maxideal} (see theorem \\ref{thm:irreducibleideal}) and\nwith the theorem \\ref{thm:maxideal} the quotient by the polynomial is\nnot a field (see also claim \\ref{claim:lec1_sec14}).  \n\n\n\\section{Relatively prime ideals. Chinese remainder theorem}\n\n\\begin{definition}[Relatively prime ideals]\n  Let $A$ - \\mynameref{def:ring} and $I,J$ are \\mynameref{def:ideal}s.\n  $I$ and $J$ are relatively prime if $I + J = A$.\n  \\label{def:relprimeideals}\n\\end{definition}\n\n\\begin{lemma}\n  \\begin{enumerate}\n  \\item If $I,J$ are relatively prime then $IJ = I \\cap J$\n  \\item If $I_1, \\dots, I_k$ relatively prime with $J$ then\n    $\\prod_{i =1}^k I_i = I_1 \\dots I_k$ is also\n    relatively prime with $J$.\n  \\item If $I, J$ relatively prime then $I^k$ and $J^l$ are also\n    relatively prime for any $l$ and $k$.\n  \\end{enumerate}\n  \\begin{proof}\n    \\begin{enumerate}\n    \\item\n      The following one  $IJ \\subset I \\cap J$ is clear\n      \\footnote {\n        Assuming that $I$ and $J$ commute we have if\n        $x \\in IJ$ then $x \\in I$ and if\n        $x \\in JI$ then $x \\in J$ i.e. $x \\in I \\cap J$.\n      }\n      If $I$ and $J$ are relatively prime then $1_A = i + j$ for some\n      $i \\in I$ and $j \\in J$. Thus $\\forall x \\in I \\cap J$ we have the\n      following ones:\n      $x i \\in IJ$ and $x j \\in IJ$ and as result\n      \\[\n      x = x i + x j \\in IJ\n      \\]\n      i.e. $I \\cap J \\subset IJ$.\n    \\item Suppose for simplicity that $k = 2$. In the case we have\n      $1_A = i_1 + j_1 = i_2 + j_2$ where $i_1 \\in I_1, i_2 \\in I_2$ and\n      $j_1, j_2 \\in J$.\n      we also have\n      \\[\n      1_A = \\left(i_1 + j_1\\right) \\left(i_2 + j_2\\right) =\n      i_1 i_2 + \\left(j_1 i_2 + j_2 i_1 + j_1 j_2\\right)\n      \\in I_1 I_2 + J\n      \\]\n      thus $\\forall x \\in A$ we have\n      \\[\n      x = 1_A x =\n      i_1 i_2 x + \\left(j_1 i_2 + j_2 i_1 + j_1 j_2\\right) x\n      \\in I_1 I_2 + J,\n      \\]\n      i.e. $I_1 I_2 + J = A$ therefore $I_1 I_2$ and $J$ are\n      relatively prime. \n    \\item is obvious\n      \\footnote{\n        It follows from the 2 because we can assume $I_i = I$ and will\n        get that $\\forall k, I^k$ is relatively prime with $J$. From\n        other side we can assume $I_i = J$ and $J = I^k$ and conclude\n        that $J^l$ is relatively prime with $I^k$. \n      }\n    \\end{enumerate}\n  \\end{proof}\n  \\label{lem:aboutrelprimeideals}\n\\end{lemma}\n\n\\begin{theorem}[Chinese remainder]\n  \\label{thm:chineseremainder}\n  \n  Let $I_1, \\dots, I_n$ - ideals and map\n  $\\pi: A \\to A/I_1 \\times \\dots \\times A/I_n$ defined as follows\n  \\begin{equation}\n    \\pi(a) = \\left(a \\mod I_1, \\dots, a \\mod I_n\\right)\n    \\label{eq:lec4_crt_map}\n  \\end{equation}\n  The kernel $\\ker \\pi = I_1 \\cap \\dots \\cap I_n$.\n\n  The $\\pi$ is \\mynameref{def:surjection} if and only if $I_1, \\dots,\n  I_n$ are pairwise relatively prime.\n\n  In that case\n  \\[\n  A/\\cap I_k\n  \\cong\n  A/\\prod I_k\n  \\cong\n  \\prod \\left(A/I_k\\right)\n  \\]\n  \\footnote{\n    See \\mynameref{thm:firstisomorphism} where \n    $G = A$,\n    $H = A/I_1 \\times \\dots \\times A/I_n$, $\\phi = \\pi$ and  with\n    lemma \\ref{lem:aboutrelprimeideals} (as soon as $I_k$ pairwise\n    relatively prime)\n    \\[\n    \\ker \\phi = \\ker \\pi = I_1 \\cap \\dots \\cap I_n = I_1 \\dots I_n.\n    \\]\n  }\n  \\begin{proof}\n    Let $\\pi$ is \\mynameref{def:surjection}. In the case\n    $\\exists a_i \\in A$ such that\n    \\[\n    \\pi(a_i) = \\left(0, \\dots, 1 (\\mbox{ in }i\\mbox{-th place }),\n    0, \\dots, 0\\right)\n    \\]\n    i.e.\n    $a_i \\mod I_j = 0$ or $a_i \\in I_j$ for $i \\ne j$. We also have\n    $a_i \\mod I_i = 1$ thus $1 - a_i = k I_i$ i.e. $1 - a_i \\in I_i$. \n    Thus $\\forall j, \\exists a_i \\in I_j, a_k \\in I_i$ such that\n    $1 = a_i + a_k$ thus $A = I_j + I_i$ i.e. $I_i$ relatively prime\n    with any $I_j$.\n\n    Conversely if $I_i$ is relatively prime with any $I_j$ where $j\n    \\ne i$ then it also relatively prime with the product (see lemma\n    \\ref{lem:aboutrelprimeideals}) $\\prod_{j \\ne i} I_j$. In the case\n    $\\exists x_i \\in I_i, y_i \\in \\prod_{j \\ne i} I_j$ such that\n    $1 = x_i + y_i$ in the case\n    \\[\n    \\pi(y_i) = \\left(0, \\dots, 1 (\\mbox{ in }i\\mbox{-th place }),\n    0, \\dots, 0\\right)\n    \\]\n    and $\\forall b_i \\in A/I_i$\n    \\[\n    \\pi \\left(\\sum_{i = 1}^n b_i y_i\\right) =\n    \\left(b_1, \\dots, b_n\\right)\n    \\]\n    i.e. $\\pi$ is surjective.\n  \\end{proof}\n\\end{theorem}\n\nLet $K$ is a field and $A$ is a finite (finite dimensional vector\nspace) $K$-algebra.\n\n\\begin{proposition}\n  \\begin{enumerate}\n    \\item If $A$ is an \\mynameref{def:integraldomain} then $A$ is a\n      field.\n    \\item (replacing the first one) Any\n      \\mynameref{def:primeideal} of $A$ is a \\mynameref{def:maxideal}\n  \\end{enumerate}\n  \\begin{proof}\n     Well, I shall prove only the first part, the second part is just\n     a consequence of definitions. In fact, a factor over a prime\n     ideal, a quotient over a prime ideal is an integral domain, and a\n     quotient over a maximal ideal is a field.\n     \\footnote{\n       i.e. prime ideal is a maximal ideal \n     }\n     If you don't know this,\n     please look it up in any book.\n\n     Lets prove the first part. \\mynameref{def:integraldomain} means\n     that there is no zero divisors i.e. $\\forall a \\in A$\n     \\footnote{\n       $a \\ne 0_A$\n     }\n     multiplication by $a$ is \\mynameref{def:injection}. $A$ is finite\n     dimensional \\mynameref{def:vectorspace} (see above) that implies\n     that $\\times a$ is an \n     \\mynameref{def:isomorphism},\n     \\footnote{\n       $\\times a$ sends a vector space  into another vector space with\n       the same dimension. But with \\mynameref{lem:vsisomorphism} one\n       can get that the spaces are isomorphic each others and as\n       result the operation $\\times a$ is an \\mynameref{def:isomorphism}.\n     }\n     in particular \\mynameref{def:surjection} i.e. $\\exists b \\in A$\n     such that $b \\times a = 1$ i.e. $a$ is invertible therefore\n     $A$ is field.     \n  \\end{proof}\n  \\label{prop:lec4_ideals}\n\\end{proposition}\n\n\\section{Structure of finite algebras over a field. Examples}\n\n\\begin{myremark}\n  Let $A$ is a $K$-algebra and $m$ is a maximal ideal of $A$. Then\n  $A/m$ is also $K$-algebra.\n  \\label{rem:lec5_quotientkalgebra}\n  \\begin{proof}\n    Lemma \\ref{lem:lec1_homkalgebra} says that there is a ring homomorphism\n    between $K$ and $A$: $f_K: K \\to A$. There is also a canonical\n    homomorphism $f_A: A \\xrightarrow[a \\to \\bar{a}]{} A/m$. Therefore\n    we can define $f = f_A f_K: K \\to A/m$ and therefore with\n    lemma about \\mynameref{lem:lec1_homkalgebra} can conclude that $A/m$ is a\n    $K$-algebra.\n    \\footnote{\n      Thanks Zonglin Jiang for the proof.\n    }\n\n    Note that if $A$ is a field then $f_A$ is injection, $m=\\{0_K\\}$\n    and $A = A/m$. \n  \\end{proof}\n\\end{myremark}\n\n\\begin{theorem}[Structure of finite $K$-algebra]\n  Let $A$ be a finite $K$-algebra i.e.\n  $\\dim_K A < \\infty$. Then\n  \\begin{enumerate}\n  \\item There are only finitely many \\mynameref{def:maxideal}s\n    $m_1, \\dots, m_r$ in $A$\n  \\item Let $J = m_1 \\cap \\dots \\cap m_r = m_1 \\dots m_r$.\n    \\footnote{\n      Since the ideals are relatively prime the intersection is the\n      same as the product of the ideals\n    }\n    Then\n    $J^n = 0$ for some $n$\n  \\item\n    $A \\cong A/{m_1^{n_1}} \\times \\dots \\times A/{m_r^{n_r}}$ for\n    some $n_1, \\dots, n_r$.    \n  \\end{enumerate}\n  \\label{thm:structurefinitekalgebra}\n  \\begin{proof}\n    \\begin{enumerate}\n    \\item\n      Let $m_1, \\dots, m_i$ are maximal ideals. By\n      \\mynameref{thm:chineseremainder} we have\n      \\footnote{\n        Maximal ideals are relatively prime because\n        in a commutative ring with unity, every\n        \\mynameref{def:maxideal} is a\n        \\mynameref{def:primeideal} see also proposition\n        \\ref{prop:lec4_ideals}. \n      }\n      \\[\n      A/m_1 \\dots m_i \\cong\n      A/m_1 \\times \\dots \\times A/m_i.\n      \\]\n      We know that $A$ as well as $A/m_1 \\dots m_i$ and $A/m_k$ are\n      finite dimensional $K$-\\mynameref{def:vectorspace}\n      \\footnote {\n        See remark \\ref{rem:lec5_quotientkalgebra} and take into\n        consideration  \n        the theorem statement (see above) that says \n        $\\dim_K A < \\infty$. $A/m_1$ is a projection i.e.\n        $\\dim_K A/m_1 < \\dim_K A < \\infty$.\n      }\n      thus we have the\n      following relations\n      \\[\n      \\dim_K A \\ge \\dim_K  A/m_1 \\dots m_i  =\n      \\sum_{j=1}^i dim_K A/m_j \\ge i.\n      \\]\n      Therefore if $N$ the number of maximal ideals then\n      $\\dim_K A \\ge N$ i.e. the number of maximal ideal is limited by\n      the vector space dimension.\n    \\item\n      $J = m_1 \\cap \\dots \\cap m_r = m_1 \\dots m_r$ is finite\n      dimensional vector space over $K$\n      \\footnote{\n        We have $m_i \\subset A$ i.e. $\\dim_K m_i \\le \\dim_K A <\n        \\infty$. From other side $J = m_1 \\dots m_r = (m_1 \\cap \\dots \\cap\n        m_r) \\subset m_i, \\forall i \\in \\{1, \\dots, r\\}$.\n        Thus $\\dim_K J \\le \\dim_K m_i \\le \\dim_K A <\n        \\infty\\le $\n      }\n      as well as its powers\n      $J^k$.\n      We have the following sequence\n      \\footnote {\n        Let $j \\in J \\subset A$ and $x \\in JJ$.\n        Then $\\exists j \\in J$ such that $x = j j$\n        but $j j \\in J$ because $\\forall y \\in J: j y \\in J$.\n        As result $J^2 \\subseteq J$.\n      }\n      \\[\n      \\dots \\subseteq J^k \\subseteq \\dots \\subseteq\n      J^2 \\subseteq J.\n      \\]\n      and the sequence should stop somewhere\n      \\footnote {\n        On each step we should decrease the dimension if we don't\n        stop. The dimension is limited and as result the sequence\n        should stop.\n      }\n      i.e.\n      $\\exists n$ such that $J^n = J^{n+1}$. We claim that $J^n = 0$\n      in the case. Indeed if not we have the following basis of $J^n$:\n      $e_1, \\dots, e_s$. And as soon as $J^n = J J^n$ we can write a\n      vector $e_i \\in J^n$ as a vector from $J^n$ multiplied on an\n      object from $J$ i.e.\n      \\[\n      e_i = \\sum \\lambda_{ij} e_j,\n      \\]\n      there $e_j \\in J^n, \\lambda_{ij} \\in J$. Thus if\n      $M = id - \\lambda_{ij}$\n      \\[\n      M \\cdot \\left(\n      \\begin{array}{c}\n        e_1 \\\\\n        \\vdots \\\\\n        e_s\n      \\end{array}\n      \\right) = 0.\n      \\]\n      It's possible over ring\n      to find a matrix $\\tilde{M}$ such that\n      \\(\n      \\tilde{M} M = \\det M \\cdot id,\n      \\)\n      \\footnote{\n        If $M$ is a matrix over a field we can consider the following\n        2 cases:\n        \\begin{enumerate}\n        \\item $\\det M = 0$: we can assume that $\\tilde{M} = 0$\n        \\item $\\det M \\ne 0$: at the case $\\exists M^{-1}$ and\n          therefore $\\tilde{M} = \n          \\det M \\cdot M^{-1}$ will work.\n        \\end{enumerate}\n        For more common case we have to look at Adjugate matrix\n        \\cite{wiki:adjugatematrix} \n      }      \n      i.e.\n      \\begin{equation}\n      \\det M \\cdot \\left(\n      \\begin{array}{c}\n        e_1 \\\\\n        \\vdots \\\\\n        e_s\n      \\end{array}\n      \\right) = 0.\n      \\label{eq:lec4_det}\n      \\end{equation}\n      But $\\det M = 1 + \\lambda$ where $\\lambda \\in J$.\n      \\footnote{\n        Because the $\\det$ consists of the following \n        items $\\prod (1-\\lambda_{ii}) = 1 + (-1)^s\\prod \\lambda_{ii}$\n        and $\\prod \\lambda_{ij}$. The sum of the items ($\\det$)\n        consists of $1$ and another sum in which all items are from\n        $J$. Thus the second sum is an element of $J$ i.e.\n        $\\det M = 1 + \\sum \\prod \\lambda_{ij} = 1 + \\lambda$.\n      }\n      Since  $J = m_1 \\cap \\dots \\cap m_r$ then\n      $\\forall i: \\lambda \\in m_i$\n      so $\\nexists i$ such that $1 + \\lambda \\in m_i$\n      \\footnote{\n        We have that $m_i$ is a \\mynameref{def:maxideal} and therefore (by\n        its definition) it is a \\mynameref{def:properideal} i.e.\n        $1 \\notin m_i$. From other side if $1 + \\lambda \\in m_i$ then\n        $1 + \\lambda - \\lambda \\in m_i$ as soon as $\\lambda \\in\n        m_i$. I.e. we have a contradiction.  \n      }\n      thus $1 + \\lambda$ is invertable\n      \\footnote {\n        $0 \\in m_i$ thus if $1 + \\lambda \\notin m_i$ then\n        $1 + \\lambda \\ne 0$.\n      }\n      therefore $e_1 = \\dots = e_s = 0$\n      \\footnote{\n        Because $\\det M = 1 + \\lambda \\ne 0$\n      }\n    \\item Using part 2\n      $\\exists n_1, \\dots, n_r$ such that\n      $m_1^{n_1} \\dots m_r^{n_r} = 0$ (for example we can assume\n      $n_i = n$). Then by \\mynameref{thm:chineseremainder} \n      \\[\n      A \\cong\n      A/{m_1^{n_1}} \\times \\dots \\times A/{m_r^{n_r}}.\n      \\]\n      We used the following facts:\n      \\begin{itemize}\n      \\item $A = A /m_1^{n_1} \\dots m_r^{n_r}$\n        \\footnote{\n          Because $A = A/\\{0\\}$. For example if $I = \\{0\\}$ and\n          $x \\in A$ then $\\bar{x} \\in A/I$ if $\\bar{x} = x + I$. In\n          our case $\\bar{x} = x + \\{0\\} = x$ i.e. $\\forall x \\in A$ we\n          have $x \\in A/\\{0\\}$.\n          (See also \\mynameref{def:quotientring})\n        }\n      \\item $m_i^{n_i}$ are pairwise relatively prime\n        \\footnote{\n          As soon as $\\{m_i\\}$ - \\mynameref{def:maxideal}s and as result\n          \\mynameref{def:primeideal}s then with lemma\n          \\ref{lem:aboutrelprimeideals} one can get that\n          $\\forall i \\ne j$ $m_i^{n_i}$ is relatively prime with\n          $m_j^{n_j}$.\n        }\n      \\end{itemize}\n    \\end{enumerate}\n  \\end{proof}\n\\end{theorem}\n\n\\begin{remark}\n  The $n_i$s are not uniquely defined. For example (see also example\n  \\ref{ex:lec5_1}) \n  \\[\n  A = ^{K\\left[X\\right]}/_{\\left(X^2 \\left(X+1\\right)^3\\right)}.\n  \\]\n  We have 2 ideals there:\n  $m_1 = (X)$ and $m_2 = (X+1)$.\n  We of course have\n  \\[\n  A \\cong A/m_1^2 \\times A/m_2^3\n  \\]\n  but also we have\n  \\[\n  A \\cong A/m_1^3 \\times A/m_2^3\n  \\]\n  as soon as $m_1^2 = m_1^3$ in $A$:\n  $(X)^2 \\subset (X)^3$ but also\n  $(X)^3 \\subset (X)^2$\n  \\footnote{\n    $(X)^3 \\subset (X)^2$ - this is true for any polynomial\n    $P\\left(X\\right)$ because if\n    $P\\left(X\\right) \\in (X)^3$ then\n    $P\\left(X\\right) = X^3 P'\\left(X\\right) =\n    X^2 \\bar{P}\\left(X\\right) \\in (X)^2$ where\n    $\\bar{P}\\left(X\\right) = X P'\\left(X\\right)$\n\n    $(X)^2 \\subset (X)^3$ is the more complex one and it does not true\n    for any polynomial ring but this is true for our $A$.\n    Let $P\\left(X\\right) \\in \\left(X\\right)^2 \\subset\n    K\\left[X\\right]$ then\n    $P\\left(X\\right) = X^2 P'\\left(X\\right)$ but\n    $X^2 P'\\left(X\\right) \\equiv 0 \\mod X^2$.\n    From other side\n    $X^4 P'\\left(X\\right) \\equiv 0 \\mod X^2$\n    therefore\n    \\[\n    P\\left(X\\right) \\equiv X^3 X P'\\left(X\\right) \\mod X^2\n    \\]\n    i.e. $P\\left(X\\right) \\in (X)^3$.\n  }\n  \\label{rem:lec5_4}\n\\end{remark}\n\nSeveral examples:\n\\[\n\\mathbb{C} \\otimes_\\mathbb{R} \\mathbb{C} =\n\\mathbb{C} \\times \\mathbb{C}.\n\\]\n\nAnother example\n\\[\n\\mathbb{Q}\\left(\\sqrt{2}\\right)\n\\otimes_{\\mathbb{Q}}\n\\mathbb{Q}\\left(\\sqrt{3}\\right) =\n\\mathbb{Q}\\left(\\sqrt{2}, \\sqrt{3}\\right)\n\\]\nAnd you see that those algebras are Cartesian products of fields.\nSo all $n_i$'s may be taken equal to 1\n\\footnote{\n  Because $A/m^n$ (where $m$ is a maximal ideal) is a field if $n=1$\n}.\nIn other words, we don't have\n\\mynameref{def:nilpotent}s in our algebra\n\\footnote{\n  Cartesian products of fields has no nilpotent elements except 0\n  \\cite{ribenboim2001classical}.\n}. So, it is a reduced\nalgebras. Reduced, by definition, is without nilpotents.     \nIt's general phenomena because the presence of nilpotents is due to the\ninseparability of extensions come from inseparable extensions.  \n", "meta": {"hexsha": "59ac8ba904bcaf3fe2532ff5a6ab1e6c058d0795", "size": 48575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture4.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": "lecture4.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": "lecture4.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": 34.8207885305, "max_line_length": 80, "alphanum_fraction": 0.5995470921, "num_tokens": 17747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.6135592520547173}}
{"text": "% LaTeX file for a 1 page document\n\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{physymb}\n\\usepackage{braket}\n\\usepackage{array} \n\\title{EP 307 Assignment 4}\n\n\\author{Manish Goregaokar\\\\120260006}\n\n\\begin{document}\n\\maketitle\n\n\\section*{Problem 1}\n$$\\prod_{i\\neq s}\\frac{\\hat A-a_i}{a_s-a_i}$$\n\nIf $\\Ket{a}=\\sum c_i\\Ket{a_i}$, applying this operator we have \\begin{align*}\n\\prod_{i\\neq s}\\frac{\\hat A-a_i}{a_s-a_i}\\left(\\sum c_i\\Ket{a_i}\\right)&=\\sum_j\\left(\\prod_{i\\neq s}\\frac{\\hat A-a_i}{a_s-a_i}\\right)c_j\\Ket{a_j}\\\\\n&=\\left(\\prod_{i\\neq s}\\frac{\\hat A-a_i}{a_s-a_i}\\right)c_s\\Ket{a_s}\\\\&\\qquad\\text{Since the other terms have numerator cancelling out for $i=j$}\\\\\n&=\\left(\\prod_{i\\neq s}\\frac{a_s-a_i}{a_s-a_i}\\right)c_s\\Ket{a_s}\\\\\n&=c_s\\Ket{a_s}\n\\end{align*}\nThus the operator is $\\frac{\\Ket{a_s}\\Bra{a_s}}{\\Braket{a_s|a_s}}=p_s$ (projection operator)\n\\section*{Problem 2}\n\\newcommand{\\Tr}{\\mathrm{Tr}}\nTo prove:\n$$\\Tr(XY)=\\Tr(YX)$$\n\nThe trace of an operator can be denoted by $\\sum_i \\Braket{i|A|i}$, where $\\Bra{i},\\Ket{i}$ are basis vectors corresponding to the $i$th element being $1$ and the rest $0$. \n\nThus,\n\n\\begin{align*}\n\\Tr(AB) \n&= \\sum_i \\Braket{i|AB|i}\\\\\n&= \\sum_i  \\Braket{i|AIB|i}\\\\\n&= \\sum_i\\sum_j  \\Braket{i|A\\Ket{j}\\Bra{j}B|i}\\\\\n&= \\sum_i\\sum_j  \\Braket{j|A\\Ket{i}\\Bra{i}B|j}\\\\\n&= \\sum_j  \\Braket{j|BIA|j}\\\\\n&= \\Tr(BA)\n\\end{align*}\n\n\\section*{Problem 7}\n\nApplying $\\hat{A}=\\hat{Q}\\hat{C}+\\hat{C}\\hat{Q}$ to an eigenstate $\\Ket{\\psi_q}$, we get:\n\n\\begin{align*}\n\\hat{A}\\Ket{\\psi_q} &=(\\hat{Q}\\hat{C}+\\hat{C}\\hat{Q})\\Ket{\\psi_q}\\\\\n&= \\hat{Q}\\hat{C}\\Ket{\\psi_q}+\\hat{C}\\hat{Q}\\Ket{\\psi_q} \\\\\n&= \\hat{Q}\\Ket{\\psi_{-q}}+q\\hat{C}\\Ket{\\psi_q}\\\\\n&= -q\\Ket{\\psi_{-q}}+q\\Ket{\\psi_{-q}}\\\\\n&=0\n\\end{align*}\n\nIf $\\hat A\\Ket{\\psi_q}=0$, then $\\hat A\\left(\\sum a_q\\Ket{\\psi_q}\\right)=0$. We can say that the eigenvalue of $\\hat A$ is 0.\n\nFor a state $\\Ket{\\psi_q}$ to be an eigenstate of $\\hat C$, $c\\Ket{\\psi_q}=\\hat C\\Ket{\\psi_q}=\\Ket{\\psi_{-q}}$\n\nSince $\\Ket{\\psi_{-q}},\\Ket{\\psi_q}$ have different eigenvalues (except when $q=0$), they are linearly independent, and thus the  only possible value of $c$ is 0, which isn't an eigenstate.\n\nSo the only common eigenstate is $\\Ket{\\psi_0}$, provided that it is not a null vector.\n\\section*{Problem 9}\n\\newcommand{\\kpsi}{\\Ket{\\psi}}\n\\begin{align*}\n[\\hat x, \\exp\\left(\\frac{i\\hat p a}{\\hbar}\\right)]\\kpsi &= [\\hat x, \\exp\\left(\\frac{i(-i)\\hbar\\partial_x a}{\\hbar}\\right)]\\kpsi\\\\\n&=[\\hat x, \\exp(a\\partial_x)]\\kpsi\\\\\n&=  x \\sum_i \\frac1{i!}a^i\\partial^i_x\\kpsi - \\sum_i\\frac1{i!} a^i\\partial^i_x (x\\kpsi) \\\\\n&=  x \\sum_i \\frac1{i!}a^i\\partial^i_x\\kpsi - \\sum_i\\frac1{i!} a^i(x\\partial^i_x (\\kpsi) + \\partial_x^{i-1}i\\kpsi)\\\\\n&= - \\sum_i\\frac1{i!} a^i \\partial_x^{i-1}i\\kpsi\\\\\n&= - \\sum_i\\frac1{(i-1)!} a^i \\partial_x^{i-1}\\kpsi\\\\\n&= - a\\exp(a\\partial_x)\\Ket{\\psi}\\\\\n&= -a\\exp\\left(ia\\frac{\\hat p}{\\hbar}\\right)\\kpsi\\\\\n\\therefore [\\hat x, \\exp\\left(\\frac{i\\hat p a}{\\hbar}\\right)] &= -a\\exp\\left(ia\\frac{\\hat p}{\\hbar}\\right)\n\\end{align*}\n\n\\section*{Problem 11}\nThe first allowed state (ground state) in the new system will be the first odd wavefunction, i.e. when $n=1$. We need to calculate the probability that the current state ($n=0$) becomes $n=1$ in that region. Note that since the space is halved over a symmetric function, the wavefunctions will be normalized by an extra factor of $\\frac1{\\sqrt2}$\n\nSo, the overlap is \n\\begin{align*}\n\\int_0^\\infty \\psi_0(x)\\frac1{\\sqrt2}\\psi_1(x)\n&= \\int_0^\\infty  \\left(\\frac{\\alpha}{\\sqrt{\\pi}}\\right)^{\\frac12}e^{-\\alpha^2x^2/2}H_0(\\alpha x)\\left(\\frac{\\alpha}{\\sqrt{\\pi}2}\\right)^\\frac12 e^{-\\alpha^2x^2/2}H_2(\\alpha x)\\\\\n&= \\frac{\\alpha}{\\sqrt\\pi\\sqrt2}\\cdot \\int_0^\\infty e^{-\\alpha^2x^2}\\cdot 2\\alpha x\\\\\n&=\\frac{2\\alpha^2}{\\sqrt{2\\pi}} \\int_0^\\infty e^{-\\alpha^2x^2}\\cdot  x\\\\\n&=\\frac{2\\alpha^2}{\\sqrt{2\\pi}}\\frac{1}{2\\alpha^2}\n&=\\frac{1}{\\sqrt{2\\pi}}\n\\end{align*}\n\nThus the probability is $\\left(\\frac1{\\sqrt{2\\pi}}\\right)^2=\\boxed{\\frac{1}{2\\pi}}$\n\n\\section*{Problem 13}\n$$\\hat{A}=\\begin{pmatrix}a&0&0\\\\0&-a&0\\\\0&0&-a\\end{pmatrix},\\quad\\hat{B}=\\begin{pmatrix}b&0&0\\\\0&0&ib\\\\0&ib&0\\end{pmatrix}$$\n\nTo find eigenvectors of $\\hat B$, we can multiply it with the vector $X=\\begin{pmatrix}x\\\\y\\\\z\\end{pmatrix}$. We get $\\hat BX=\\begin{pmatrix}bx\\\\ibz\\\\iby\\end{pmatrix}=cX$, so for an eigenvector we either have $c=b,ibz=y,iby=z$ (giving $y=z=0$ for a general $b$, and eigenvector $\\begin{pmatrix}1\\\\0\\\\0\\end{pmatrix}$. If $c\\neq b$ we have $x=0$, and $y=\\pm z$ with eigenvalues $\\pm ib$\n\nTherefore the eigenvectors are:\n\n\\begin{enumerate}\n\\item $\\begin{pmatrix}1\\\\0\\\\0\\end{pmatrix}$  or $\\Ket{1}$ with eigenvalue $b$\n\\item $\\begin{pmatrix}0\\\\1\\\\1\\end{pmatrix}$ or $\\Ket{2}+\\Ket{3}$ with eigenvalue $ib$\n\\item $\\begin{pmatrix}0\\\\1\\\\-1\\end{pmatrix}$ or $\\Ket{2}-\\Ket{3}$ with eigenvalue $-ib$\n\\end{enumerate}\n\\hfill Ans. (a)\n\nNow,\n$$\\hat A\\hat B=\\left(\n\\begin{array}{ccc}\n a & 0 & 0 \\\\\n 0 & -a & 0 \\\\\n 0 & 0 & -a \\\\\n\\end{array}\n\\right) \\left(\n\\begin{array}{ccc}\n b & 0 & 0 \\\\\n 0 & 0 & i b \\\\\n 0 & i b & 0 \\\\\n\\end{array}\n\\right)=\\left(\n\\begin{array}{ccc}\n a b & 0 & 0 \\\\\n 0 & 0 & 0 \\\\\n 0 & 0 & 0 \\\\\n\\end{array}\n\\right)$$\n\nand \n\n$$\\hat B\\hat A= \\left(\n\\begin{array}{ccc}\n b & 0 & 0 \\\\\n 0 & 0 & i b \\\\\n 0 & i b & 0 \\\\\n\\end{array}\n\\right)\\left(\n\\begin{array}{ccc}\n a & 0 & 0 \\\\\n 0 & -a & 0 \\\\\n 0 & 0 & -a \\\\\n\\end{array}\n\\right)=\\left(\n\\begin{array}{ccc}\n a b & 0 & 0 \\\\\n 0 & 0 & 0 \\\\\n 0 & 0 & 0 \\\\\n\\end{array}\n\\right)$$\n\nAs $\\hat A\\hat B=\\hat B\\hat A$ in matrix form, the operators commute.\n\\hfill Ans. (b)\n\nThe eigenkets of $\\hat A$ can be easily seen to be $\\Ket{1}$ with eigenvalue $a$, and $l\\Ket{2}+m\\Ket{3}$ with eigenvalue $-a$ ($\\forall~l,m$)\n\nWe can see that the eigenkets of $B$ are also eigenkets of $A$. They are also orthogonal, after normalizing we have:\\\\~\\\\\n\n\\begin{tabular}{ >{$}c<{$} >{$}c<{$}  >{$}c<{$} }\n\\text{Orthonormal Eigenket} & \\text{Eigenvalue with }\\hat A & \\text{Eigenvalue with }\\hat B \\\\\n\\Ket{1} & b & a\\\\\n\\frac{\\Ket{2}+\\Ket{3}}{\\sqrt{2}} & ib & -a\\\\\n\\frac{\\Ket{2}-\\Ket{3}}{\\sqrt{2}} & -ib & -a\n\\end{tabular}\n\n\nThe eigenkets are not completely determined from the eigenvalues from individual eigenvalues, as the eigenvalue $-a$ has multiplicity 2 and thus has an entire space of eigenkets.\n\nHowever, knowing the eigenvalues from both operators completely specifies the eigenket, barring a constant.\n\\hfill Ans. (c)\n\\section*{Problem 16}\n\n$\\psi(x)=\\frac{1}{\\sqrt{2a}}$ in $[-a,a]$. The momentum space function can be found via the fourier transform, \\begin{align*}\n\\tilde{\\psi}(p)&=\\frac1{\\sqrt{2\\pi}}\\int_{-\\infty}^\\infty e^{-ikx}\\psi(x)dx\\\\\n&= \\frac1{\\sqrt{2\\pi}}\\int_{-a}^a\\frac{1}{\\sqrt{2a}} e^{-ikx}dx\\\\\n&=\\frac{i}{2k\\sqrt{a\\pi}} \\left.e^{-ikx}\\right|_{-a}^a\\\\\n&=\\frac{i}{2k\\sqrt{a\\pi}} \\left(e^{-ika}-e^{ika}\\right)\\\\\n&=\\frac{i}{2k\\sqrt{a\\pi}} \\cdot -2i\\sin ka\\\\\n\\therefore \\tilde{\\psi}(p)&=\\frac{\\sin \\left(\\frac{ap}{\\hbar} \\right)}{p\\sqrt{a\\pi}}\\qquad\\text{(Already normalized)}\n\\end{align*}\n\\hfill Ans.\n\nNow, \\begin{align*}\\sigma_x&=\\sqrt{\\Braket{x^2}-\\Braket{x}^2}\\\\\n&=\\sqrt{\\int \\psi^*(x)x^2\\psi(x)dx-0}\\\\\n&= \\sqrt{\\int_{-a}^a \\left(\\frac{1}{\\sqrt{2 a}}\\right)^2 x^2 dx}\\\\\n&= \\frac{a}{\\sqrt{3}}\n\\end{align*}\n\nAnd\n\n\\begin{align*}\\sigma_p&=\\sqrt{\\Braket{p^2}-\\Braket{p}^2}\\\\\n&=\\sqrt{\\int \\tilde{\\psi}^*(p)p^2\\tilde{\\psi}(p)dp-0}\\\\\n&= \\sqrt{\\int_{-\\infty}^\\infty \\left(\\frac{\\sin \\left(\\frac{a p}{\\hbar }\\right)}{\\sqrt{\\pi } \\sqrt{a} p}\\right)^2 p^2 dp - 0}\\qquad\\text{(The wavefunction is odd so the second term vanishes)}\\\\\n&=\\sqrt{\\infty}\n\\end{align*}\n\nThe product of the two uncertantainties is greater than $\\frac\\hbar2$\n\\section*{Problem 17}\n\n$$\\psi(x,t)=\\frac{1}{\\sqrt{2 \\pi  \\hbar }}\\int_{-\\infty }^{\\infty }  \\phi(p)  e^{-\\frac{t \\left(i p^2\\right)}{2 m}+i p x} \\, dp$$\n\nNow, we can rewrite this as $\\frac{1}{\\sqrt{2 \\pi  \\hbar }}\\int_{-\\infty }^{\\infty } e^{i p x} \\left(\\phi(p)  e^{-\\frac{t \\left(i p^2\\right)}{2 m}}\\right) \\, dp$\n\nwhich is an inverse fourier transform.\n\nThus, $\\tilde{\\psi}(p,t)=\\mathcal F(\\psi(x,t))=\\phi(p)  e^{-\\frac{t \\left(i p^2\\right)}{2 m}}$\\\\\nNow,\n\\begin{align*}\n\\Braket{p}&=\\int \\tilde{\\psi}^*(p,t)p\\tilde{\\psi}(p,t)dp\\\\\n&=\\int \\phi^*(p)  e^{\\frac{t \\left(i p^2\\right)}{2 m}}p\\phi(p)  e^{-\\frac{t \\left(i p^2\\right)}{2 m}}dp\\\\\n&= \\int \\phi^*(p) p \\phi(p) dp\n\\end{align*}\n\nThus, $\\Braket{\\hat p}$ is independant of time\\hfill Ans. (a)\n\nNote that $\\phi(p)=\\tilde{\\psi}(p,t=0)$\nNow, \n\n\\begin{align*}\n\\Braket{x}= \\int \\tilde{\\psi}^*(p,t)i\\hbar\\ud{}{p}\\tilde{\\psi}(p,t)dp\\\\\n&=\\int \\phi^*(p)e^{\\frac{t \\left(i p^2\\right)}{2 m}}i\\hbar\\left(\\pd{\\phi}{p}e^{-\\frac{t \\left(i p^2\\right)}{2 m}}+\\phi(p)\\frac{2pt}{2m}e^{-\\frac{t \\left(i p^2\\right)}{2 m}}\\right)dp\\\\\n&=\\int\\left( \\phi^*(p)i\\hbar\\pd{\\phi}{p} + \\frac{t}{m}\\phi^*(p)p\\phi(p)\\right) dp\\\\\n&= \\Braket{i\\hbar\\pd{}{p}}_{t=t_0} + \\frac{t}{m}\\Braket{p}_{t=t_0}\\\\\n\\therefore \\Braket{x}&=\\Braket{x}_{t=0} + \\frac{t}{m}\\Braket{p}_{t=0}\n\\end{align*}\n\nSince this is linear, we can shift by $t_0$ to get $\\boxed{\\Braket{x}=\\Braket{x}_{t=t_0} + \\frac{t-t_0}{m}\\Braket{p}_{t=t_0}}$\\hfill Ans. (b)\n\\section{Problem 19}\n$$\\hat H = \\frac{\\hat p^2}{2m}+V(x)$$\n\n\\begin{align*}\n[H,\\hat x]&=\\frac{\\hat p^2}{2m}x+V(x)x-x\\frac{\\hat p^2}{2m}+xV(x)\\\\\n&=-x\\frac{\\hat p^2}{2m}\\\\\n[[H,\\hat x],x]&=-x\\frac{\\hat p^2}{2m}x - -x^2\\frac{\\hat p^2}{2m}\\\\\n&=\\frac{x^2\\hat p^2}{2m}\n\\end{align*}\n\\end{document}\n", "meta": {"hexsha": "f0b8e47c2ec6b42540bd58fa08a70643ca2869e2", "size": 9354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 4/assign4.tex", "max_stars_repo_name": "CourseResources/CourseResources", "max_stars_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-28T05:59:31.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-28T05:59:31.000Z", "max_issues_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 4/assign4.tex", "max_issues_repo_name": "CourseResources/CourseResources", "max_issues_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Course material/EP 307 - Quantum Mechanics/Assignment 4/assign4.tex", "max_forks_repo_name": "CourseResources/CourseResources", "max_forks_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_forks_repo_licenses": ["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.6355932203, "max_line_length": 384, "alphanum_fraction": 0.6173829378, "num_tokens": 4086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.6135592504907484}}
{"text": "\\documentclass{article}\n\n\\usepackage{epsfig}\n\\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{fullpage}\n\\usepackage{commath}\n\\usepackage{amssymb}\n\\usepackage[space]{grffile}\n\\usepackage{algorithm, algorithmic}\n\n\\def\\E{\\mathbb{E}}\n\\def\\R{\\mathbb{R}}\n\\def\\bin{\\text{bin}}\n\\def\\bet{\\text{beta}}\n\\def\\range{\\text{range}}\n\\def\\vec{\\text{vec}}\n\n\\newcommand\\hide[1]{}\n\n\\title{HMM with Contexts in DNA Methylation Problem}\n\n\\author{Chicheng Zhang}\n\n\\begin{document}\n\\maketitle\n\n\n\\section{The Model}\n\nWe are given sequences $\\cbr{m_t, c_t}$, where at each time $t$ the methylation count is $m_t \\in \\cbr{0,1,\\ldots,n}$, and the context information is $c_t \\in [c]$. We model the data using a hidden Markov model with context information, that is, the underlying dynamics of the hidden states is driven by a Markov chain $\\cbr{y_t}$, where $y_t \\in [m]$.\n\nIt can be described by parameters $(\\pi, T, O)$, where $\\pi$ is the initial probability distribution $\\Pr(y_1)$ and $T$ is the transition matrix of the Markov chain $\\Pr(y_{t+1} | y_t)$, $O$ is the observation matrix, namely the conditional probability of methylation given hidden state and context $\\Pr(m_t | c_t, y_t)$. See Figure~\\ref{fig:contexthmm} for illustration.\n\n\\begin{figure}[h]\n\\centering\n\\scalebox{0.3}\n{\n\\includegraphics{hmm.png}\n}\n\\caption{Modeling DNA methylation using a Hidden Markov model with context information.}\n\\label{fig:contexthmm}\n\\end{figure}\n\nOur objective is to recover parameters $\\pi$, $T$ and $O$ based on iid samples drawn from this model.\n\n\\section{Algorithm based on Method of Moments}\n\nFor each $i$, consider recovering a block of observation matrix $O^{2, i} = \\Pr(m_t | c_t = i, y_t)$ separately. We make the assumption that $O^{2, i}$ is of full column rank. Then, the joint cooccurence tensor of $(m_1, m_2, m_3)$, when the context of observation 2 $c_2$ is $i$, has the following structure:\n\\[ \\E [m_1 \\otimes m_2 \\otimes m_3 | c_2 = i] = \\sum_j \\omega_j O^{1}_j \\otimes O^{2, i}_j \\otimes O^{3}_j \\]\nwhere $\\omega$ is the distribution of $y_2$ given $c_2$, $O^{1} = \\E[m_1 | y_2]$, $O^{2,i} = \\E[m_2 | y_2, c_2 = i]$, $O^{3} = \\E[m_3 | y_2]$.\nAt this point, standard tensor decomposition method can readily be applied to extract the columns of $O^{2, i}$.\n\nAlternatively, we have\n\\[ \\E [m_1 \\otimes m_3] = \\sum_j \\omega_j O^1_j \\otimes O^3_j \\]\nand\n\\[ \\E [m_1 \\otimes m_2 | c_2 = i] = \\sum_j \\omega_j O^{1}_j \\otimes O^{2, i}_j \\]\nThen standard symmetrization and orthogonalization routine can be applied to recover the columns of $O^{2, i}$.\n\n\\section{Binomial Hidden Markov Model}\nIn this section, we consider HMMs whose observation matrix has structured columns, that is, columns which are probability mass functions of binomial distribution. We first take a step back, considering HMMs without context information. (The approach can be easily generalized to the setting with context information.)\n\nIn this model, each element of $O$ can be written as $O_{i,j} = {n \\choose i} p_j^i (1-p_j)^{n-i}$, i.e. the probability that there are $i$ heads out of $n$ trials when flipping a coin with bias $p_j$. Instead of recovering $O$, we now turn to the task of recovering $p_j, j = 1,2,\\ldots,m$. A naive approach would be to first recover the columns of $O$, e.g. $O_j$, then get $p_j$ using the formula:\n\n\\[ p_j = \\sum_{i=0}^n \\frac{i}{n} {n \\choose i} p_j^i (1-p_j)^{n-i} = \\sum_{i=0}^n \\frac{i}{n} O_{i,j} \\]\n\n\\subsection{Exploiting Similarity between Observations}\nSometimes it will be beneficial to consider feature representations of observation other than one-hot encoding. Define feature map $\\phi: \\cbr{0,\\ldots,n} \\to \\R^D$, where $D$ can potentially be very large, even (uncountably) infinite. For example, $\\phi(m) = \\cbr{t^m (1-t)^{n-m}}_{t \\in [0,1]}$, $\\phi(m) = \\cbr{t^m (1-t)^{n-m}}_{t \\in \\cbr{0,0.1, \\ldots, 1}}$, or $\\phi(m) = \\cbr{ \\frac{1}{\\sqrt{2\\pi}} \\exp(-(t-m)^2/2)}_{t \\in \\R}$, etc.\n\nThen, standard method of moments can be applied, resulting in the following representation:\n\\[ \\E [\\phi(m_1) \\otimes \\phi(m_2) \\otimes \\phi(m_3)] = \\sum_j \\omega_j O^{1}_j \\otimes O^{2}_j \\otimes O^{3}_j \\]\nwhere $\\omega$ is the marginal distribution of $y_2$, $O^{1} = \\E[\\phi(m_1) | y_2]$, $O^{2} = \\E[\\phi(m_2) | y_2]$, $O^{3} = \\E[\\phi(m_3) | y_2]$.\n\nNow, to decompose this $D \\times D \\times D$ tensor, dimensionality reduction tricks should be applied. After getting an estimate of $O^{2} = \\E[\\phi(m_2) | y_2]$, we can recover $p_j$'s via algebraic manipulations.\n\n\n\\hide\n{\n\\section{Experiment Results}\n\\subsection{Setting}\nIn this set of experiments, we focus on the methylation data in cell type E1 and chromosome 1. At this point we do not take into account the contexts, and we further assume that the coverage in different segments are non-uniform. Let $l$ be the length of the input sequence, $s$ be the number of base segments merged to a single segment, and $n$ be the number of hidden states assumed.\n\nAlthough the ultimate goal is to recover the transition matrix and observation matrix of the hidden Markov model, at the current stage, we recover $\\E[\\phi(x, y)|h]$ for each value of $h$. Recall that $x = (c, \\mu)$ is the (coverage, methylation) count pair in each segment. The value of $p_h$ for each $h$ can be straightforwardly extracted from $\\E[\\phi(x, y)|h]$. The transition matrix can also be computed subsequently. We leave the recovery of all the parameters for future work.\n\n\n%In subsequent results, we show the entire $\\E[\\phi(x,y)|h]$, as opposed to a single number $p_h \\in [0,1]$. The reason is that we wish to recover more information about the hidden states learned, to get a better understanding of the HMM model.\n\n%-- what features $\\phi$ are you looking at?\n%-- why are you showing the entire $\\phi$ vector and not a single number?\nWe focus on two types of feature mappings $\\phi$, the first one is binning mapping:\n\\[ \\phi_{\\bin}(x,y) = \\begin{cases} {I(\\frac{\\mu}{c} \\in (y,y+h])} & c \\neq 0 \\\\ 0 & c = 0\\end{cases} \\]\nwhere $h$ is the width of the bins.\n\nThe second one is Beta map:\n\\[ \\phi(x,y) = \\frac{1}{B(\\mu+1, c-\\mu+1)}y^\\mu (1-y)^{c-\\mu} \\]\nIn this mapping there is no explicit notion of ``bin width\", but the value of $c$ can be thought of as a parameter controlling it: if the coverage $c$ is large, then the bin width is small, and vice versa.\n\nIn experiments, since it is impossible to write down $\\E[\\phi(x_1, \\cdot) \\otimes \\phi(x_2, \\cdot) \\otimes \\phi(x_3, \\cdot)]$ and perform tensor decomposition, we use discretization: compute an empirical version of $\\E[\\phi(x_1, y_1) \\otimes \\phi(x_2, y_2) \\otimes \\phi(x_3, y_3)]$, where $y_1, y_2, y_3$ is in $\\cbr{0,h,2h,\\ldots,1}$. By decomposing this tensor we are able to recover $\\E[\\phi(x, y) | h]$, where $y$ is in $\\cbr{0,h,2h,\\ldots,1}$. By mild regularity assumption on the distribution of $x$, this can give a fairly accurate estimate of $\\E[\\phi(x, y) | h]$ where $y$ ranges in the $[0,1]$ interval.\n\n\n\\subsection{Effect of Sample Size $l$}\nWe fix $m = 4$, $s = 1$, and vary the sample size (number of triples collected) $l =$ 1000, 10000, 20000, 40000, 80000, 160000, 320000. The samples are drawn without replacement from the original dataset. Figure~\\ref{fig:varyl} shows the result. Note that the value of $m$ is the number of hidden states assumed; for example if $m = 4$, then we get $4$ columns of $\\E[\\phi(x,y)|h]$. We observe that the output of the algorithm stablizes when $l \\geq 80000$.\n\n\\begin{figure}[H]\n\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 10000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 10000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 20000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 20000$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 40000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 40000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 80000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 80000$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 160000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 160000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 320000$}\n    \\end{subfigure}\n    \\\\\n    \\end{tabular}\n\n    \\caption{The observation columns recovered $\\E[\\phi(x,y)|h]$ in terms of $h$, for varying sample size $l$. The $x$-axis is the value of $t$, the $y$-axis is the value of $\\E[\\phi(x,y)|h]$.}\n    \\label{fig:varyl}\n\\end{figure}\n\n\\subsection{Effect of Specifying the Number of States}\n\nWe fix $l = 320000$, $s = 1$, and vary the number of states $m = 2,3,4,5,6,7,8,9$. Figure~\\ref{fig:varym} shows the columns of $\\E[\\phi(x,y)|h]$ recovered. The spectral algorithm provides reasonable results when $m \\leq 4$; when $m \\geq 5$, the algorithm started to recover observation columns that has a lot of negative entries.\n\n\n\\begin{figure}[H]\n\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 1_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 1$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 2_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 5_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 5$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns recovered $\\E[\\phi(x,y)|h]$ in terms of $h$, for varying number of states $m$. The $x$-axis is the value of $t$, the $y$-axis is the value of $\\E[\\phi(x,y)|h]$.}\n    \\label{fig:varym}\n\\end{figure}\n\n\\subsection{Binning Feature vs. Beta Feature}\n\nWe compare the experimental results using two types of feature maps $\\phi_{\\bin}$ and $\\phi_{\\bet}$. Although the two mappings are substantially different, their respective $\\E[\\phi(x,y)|h]$ have some similarities. In some sense, the beta mapping is performing a ``soft'' binning which takes into account the number count $c$ in $x$: fixing the value of methylation probability $m/c$, if $c$ is larger, then the beta mapping is closer to a binning mapping with smaller bin size. Figure~\\ref{fig:varyphi} shows the columns of the resulting $\\E[\\phi(x,y)|h]$ recovered. Generally, $\\phi_{\\bet}$ produces smoother observation columns.\n\n%-- double check this one experiment -- typo in file naming?\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n        \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E2_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = beta_full.pdf}\n        \\caption{$\\phi = \\phi_{\\bet}$ is beta mapping, $m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E2_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = binning_igz.pdf}\n        \\caption{$\\phi = \\phi_{\\bin}$ is binning mapping, $m = 3$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E2_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$\\phi = \\phi_{\\bet}$ is beta mapping, $m = 4$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E2_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = binning_igz.pdf}\n        \\caption{$\\phi = \\phi_{\\bin}$ is binning mapping, $m = 4$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns recovered $\\E[\\phi(x,y)|h]$ in terms of $h$, for $m = 4$ and two types of feature map $\\phi$. The $x$-axis is the value of $t$, the $y$-axis is the value of $\\E[\\phi(x,y)|h]$.}\n    \\label{fig:varyphi}\n\\end{figure}\n\n\\subsection{Effect of Number of Segments Combined}\nWe fix $l = 320000$, $m = 4$, and vary the number of merged segments $s = 1,2,3,4,5,6,7,8$. Figure~\\ref{fig:varys} shows the columns of the resulting $\\E[\\phi(x,y)|h]$. It can be seen that the recovered result is fairly insensitive to the choice of $s$.\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 1$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 2_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 3_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 4_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 5_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 5$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns recovered $\\E[\\phi(x,y)|h]$ in terms of $h$, for $m = 4$ and two types of feature map $\\phi$. The $x$-axis is the value of $t$, the $y$-axis is the value of $\\E[\\phi(x,y)|h]$.}\n    \\label{fig:varys}\n\\end{figure}\n}\n\n\\section{Possible Variants of Model}\n\n\\begin{figure}\n  \\caption{Possible Variants of the Model}\n  \\centering\n  \\includegraphics[width=0.8\\textwidth]{model_doubt.jpg}\n  \\label{fig:modeldoubt}\n\\end{figure}\n\nIn the data given, we are not able to observe the context information on exact positions.\nInstead, the data is grouped every 100 base pairs, where in each group, we observe\n32 numbers $\\cbr{(m_{t,i}, c_{t,i})}_{i=1}^{16}$, two for each context, representing\ntotal coverage and total methylation in context-location specific manner.\n\nWe can model the data in the following two graphical models (see Figure~\\ref{fig:modeldoubt}). The first one models\nthe sequence in each context separately. The hidden states are not only context specific,\nbut also location specific. It is not clear -- at least at this moment -- if we should\nalign the hidden states across different contexts.\n\nThe second model is to put the hidden state as the shared information across different\ncontexts. Then it assumes that given the hidden states, the 16 observations are conditionally\nindependent. We suspect this is too strong, and it might be preferable to assume the\n16 observations to have dependency and directly build a wholistic feature map based\non them altogether.\n\n\\section{Efficient Joint Parameter Estimation of Multiple HMMs}\nIn this section we study the following probem.\nSuppose we are given sequences drawn from two HMMs, and we have the prior knowledge that\nthe parameters of the two HMMs are close to each other.\nFurthermore, suppose we have computed the moments from training data\n(denoted as $P_{ij}, \\tilde P_{ij}$, $P_{ijk}, \\tilde P_{ijk}$ for all $(i,j,k)$ pairs).\nThe goal is to perform method of moments estimating the parameters of the two HMMs.\n\nIt is known that\n\\[ P_{i,j} = \\E[x_i \\otimes x_j] = \\sum_{l=1}^m w_l (O_i)_l \\otimes (O_j)_l \\]\nand\n\\[ P_{i,j,k} = \\E[x_i \\otimes x_j \\otimes x_k] = \\sum_{l=1}^m (O_i)_l \\otimes (O_j)_l \\otimes (O_k)_l \\]\n\n\\subsection{Algorithmic Primitive}\n\\paragraph{Matrix Regularized Least Squares} In subsequent discussions, the following optimization problem is often considered:\n\\[ \\min_{B \\in \\R^{n \\times k}} f(B) = \\| M - A B^T \\|_F^2 + \\lambda \\| B - \\tilde{B} \\|_F^2 \\]\nwhere $M \\in \\R^{m \\times n}$, $A \\in \\R^{m \\times k}$ are given.\n\nThis optimization problem an be solved by noticing it can be decomposed to functions with\nrespect to rows of $B$, that is, $B^{1}, \\ldots, B^{m}$.\nThis gives rise to the following optimization problem:\n\\[ \\min_{B^i \\in \\R^k} \\| M_i - A (B^i)^T \\|^2 + \\lambda \\| B^i - \\tilde B^i \\|^2 \\]\nTaking derivatives, we have\n\\[ 2 A^T A (B^i)^T - 2 A^T M_i + 2 \\lambda ((B^i)^T - (\\tilde B^i)^T) = 0 \\]\nthat is,\n\\[ (B^i)^T = (\\lambda I + A^T A)^{-1} (A^T M_i + \\lambda (\\tilde B^i)^T ) \\]\nhorizonally stacking the solution, we get\n\\[ B^T = (\\lambda I + A^T A)^{-1} (A^T M + \\lambda \\tilde B^T) \\]\nthat is, $B = (M^T A + \\lambda B)(\\lambda I + A^T A)^{-1}$.\n(As a sanity check, when $\\lambda = 0$, $B = (A^+ M)^T$, which is the correct solution.)\n\n\\paragraph{Weighted Extensions} It is sometimes desirable to consider the following\noptimization objective:\n\\[ \\min_{B \\in \\R^{n \\times k}} f(B) = \\| M - A B^T \\|_F^2 + \\lambda \\| C (B - \\tilde{B}) \\|_F^2 \\]\nwhere $C \\in \\R^{p \\times n}$ is a linear transformation (the objective aims to measure the\n$\\ell_2$ similarity of transformed $B$.)\nUnfortunately, the solution does not admit a succinct representation. But we can still\nwrite the solution. First, let $\\vec(B) = ((B^1)^T, (B^2)^T, \\ldots, (B^n)^T)$.\nWe rewrite the objective as:\n\\[ f(B) = \\sum_{i=1}^n \\| M_i - A (B^i)^T \\|_2^2 + \\sum_{j=1}^k \\| C B_j - C B_j \\|_2^2 \\]\nThus, we can formulate the problem as the following least squares problem:\n\\[\n   \\begin{bmatrix} M_{11} \\\\ \\ldots \\\\ M_{m1} \\\\ \\ldots \\\\ M_{1n} \\\\ \\ldots \\\\ M_{mn} \\\\ C^1 \\tilde B_1 \\\\ \\ldots \\\\ C^{n'} \\tilde B_1 \\\\ \\ldots \\\\ C^1 \\tilde B_k \\\\ \\ldots \\\\ C^{n'} \\tilde B_k \\end{bmatrix}\n   =\n   \\begin{bmatrix}\n     & A^1 & \\\\ & \\ldots & \\\\ & A^m & \\\\  & & & \\ldots & & & \\\\ & & & & & A^1 \\\\ & & & & & \\ldots \\\\ & & & & & A^m \\\\\n     C_{1,1} & & \\ldots & & C_{1,n} \\\\& & \\ldots \\\\ C_{n',1} & & \\ldots & & C_{n',n} \\\\ & & \\ldots \\\\\n      & & C_{1,1}  &  & \\ldots & & C_{1,n} \\\\& & & & \\ldots \\\\  & & C_{n',1}  &  & \\ldots & & C_{n',n}\n   \\end{bmatrix} \\cdot \\vec(B)\n\\]\nLetting the vector in the left hand side as $Y$ and the matrix on the right hand side as $H$, we get $\\vec(B) = H^+ Y$.\n\n\\paragraph{Basic Weighted Least Squares}\nSuppose we would like to solve the following least squares problem:\n\\[ \\min f(\\tau) = \\| T - \\sum_{i=1}^k \\tau_i T_i \\|_F^2 \\]\nThis is equivalent to solving the following equation:\n\\[\n  \\begin{bmatrix} T \\cdot T_1 \\\\ \\ldots \\\\ T \\cdot T_k \\end{bmatrix}\n  =\n  \\begin{bmatrix} T_1 \\cdot T_1 & \\ldots & T_1 \\cdot T_k \\\\ \\ldots & \\ldots & \\ldots \\\\ T_k \\cdot T_1 & \\ldots & T_k \\cdot T_k \\end{bmatrix} \\cdot \\tau\n\\]\nSpecifically, if $T_i = a_i \\cdot b_i \\cdot c_i$, then the equation becomes\n\\[\n  \\begin{bmatrix} T(a_1, b_1, c_1) \\\\ \\ldots \\\\ T(a_k, b_k, c_k) \\end{bmatrix}\n  =\n  \\begin{bmatrix} (a_1 \\cdot a_1) (b_1 \\cdot b_1) (c_1 \\cdot c_1) & \\ldots & (a_1 \\cdot a_k) (b_1 \\cdot b_k) (c_1 \\cdot c_k) \\\\ \\ldots & \\ldots & \\ldots \\\\ (a_k \\cdot a_1) (b_k \\cdot b_1) (c_k \\cdot c_1) & \\ldots & (a_k \\cdot a_k) (b_k \\cdot b_k) (c_k \\cdot c_k) \\end{bmatrix} \\cdot \\tau\n\\]\nthat is,\n\\[ \\tau = ((A^T A) \\circ (B^T B) \\circ (C^T C))^{-1}  \\begin{bmatrix} T(a_1, b_1, c_1) \\\\ \\ldots \\\\ T(a_k, b_k, c_k) \\end{bmatrix} \\]\n\n\n\\subsection{Basic Algorithm}\nDefine tensor $T = P_{123}(U_1,U_2,U_3) = \\sum_i w_i (U_1^TO_1)_i \\otimes (U_2^TO_2)_i \\otimes (U_3^TO_3)_i$\n\nGiven rank parameter $m$, we define objective function $F$ as follows:\n\\[ F(\\tau, A, B, C, \\tilde\\tau, \\tilde A, \\tilde B, \\tilde C) = \\| \\sum_{i=1}^m \\tau_i A_i \\otimes B_i \\otimes C_i - T \\|_F^2 + \\| \\sum_{i=1}^m \\tilde\\tau_i \\tilde A_i \\otimes \\tilde B_i \\otimes \\tilde C_i - \\tilde T \\|_F^2 + \\lambda \\| B - \\tilde B \\|_F^2 \\]\n\nWe have the following alternating minimization algorithm for the objective function.\n\n\\begin{algorithm}\n  \\caption{Efficient Joint Parameter Estimation; Basic Algorithm}\n\\begin{algorithmic}[H]\n\\STATE Randomly initialize $A, B, C, \\tau, \\tilde A, \\tilde B, \\tilde C, \\tilde \\tau$.\n\\FOR{$t=1,2,\\ldots$:}\n\\STATE Update $A$: $A \\gets \\del{\\del{\\lambda I + (\\tau \\tau^T) \\circ (B^T B) \\circ (C^T C)}^{-1} \\del{\\begin{bmatrix} \\tau_1 T(I, B_1, C_1) \\\\ \\ldots \\\\ \\tau_k T(I, B_k, C_k) \\end{bmatrix} + \\lambda \\tilde A^T}}^T$\n\\STATE Update $B$: $B \\gets \\del{\\del{\\lambda I + (\\tau \\tau^T) \\circ (A^T A) \\circ (C^T C)}^{-1} \\del{\\begin{bmatrix} \\tau_1 T(A_1, I, C_1) \\\\ \\ldots \\\\ \\tau_k T(A_k, I, C_k) \\end{bmatrix} + \\lambda \\tilde B^T}}^T$\n\\STATE Update $C$: $C \\gets \\del{\\del{\\lambda I + (\\tau \\tau^T) \\circ (A^T A) \\circ (B^T B)}^{-1} \\del{\\begin{bmatrix} \\tau_1 T(A_1, B_1, I) \\\\ \\ldots \\\\ \\tau_k T(A_k, B_k, I) \\end{bmatrix} + \\lambda \\tilde C^T}}^T$\n\\STATE Update $\\tau$: $\\tau \\gets ((A^T A) \\circ (B^T B) \\circ (C^T C))^{-1}  \\begin{bmatrix} T(A_1, B_1, C_1) \\\\ \\ldots \\\\ T(A_k, B_k, C_k) \\end{bmatrix}$\n\\STATE Update $\\tilde A$: $\\tilde A \\gets \\del{\\del{\\lambda I + (\\tilde \\tau \\tilde \\tau^T) \\circ (\\tilde B^T \\tilde B) \\circ (\\tilde C^T \\tilde C)}^{-1} \\del{\\begin{bmatrix} \\tilde\\tau_1 \\tilde T(I, \\tilde B_1, \\tilde C_1) \\\\ \\ldots \\\\ \\tilde\\tau_k \\tilde T(I, \\tilde B_k, \\tilde C_k) \\end{bmatrix} + \\lambda {\\tilde A}^T}}^T$\n\\STATE Update $\\tilde B$: $\\tilde B \\gets \\del{\\del{\\lambda I + (\\tilde \\tau \\tilde \\tau^T) \\circ (\\tilde A^T \\tilde A) \\circ (\\tilde C^T \\tilde C)}^{-1} \\del{\\begin{bmatrix} \\tilde\\tau_1 \\tilde T(\\tilde A_1, I, \\tilde C_1) \\\\ \\ldots \\\\ \\tilde\\tau_k \\tilde T(\\tilde A_k, I, \\tilde C_k) \\end{bmatrix} + \\lambda {\\tilde B}^T}}^T$\n\\STATE Update $\\tilde C$: $\\tilde C \\gets \\del{\\del{\\lambda I + (\\tilde \\tau \\tilde \\tau^T) \\circ (\\tilde A^T \\tilde A) \\circ (\\tilde B^T \\tilde B)}^{-1} \\del{\\begin{bmatrix} \\tilde\\tau_1 \\tilde T(\\tilde A_1, \\tilde B_1, I) \\\\ \\ldots \\\\ \\tilde\\tau_k \\tilde T(\\tilde A_k, \\tilde B_k, I) \\end{bmatrix} + \\lambda {\\tilde C}^T}}^T$\n\\STATE Update $\\tilde \\tau$: $\\tilde \\tau \\gets ((\\tilde A^T \\tilde A) \\circ (\\tilde B^T \\tilde B) \\circ (\\tilde C^T \\tilde C))^{-1}  \\begin{bmatrix} \\tilde T(\\tilde A_1, \\tilde B_1, \\tilde C_1) \\\\ \\ldots \\\\ \\tilde T(\\tilde A_k, \\tilde B_k, \\tilde C_k) \\end{bmatrix}$\n\\ENDFOR\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Algorithm Exploiting Three Views}\n\n\\subsection{Symmetrization }\n\nLet $U$ be the left singular vectors of $P_{i,1}$. It it known that $\\range(U) = \\range(O)$\nThis serves as the projection matrix for dimensionality reduction.\nWe operate on the following tensor:\n\\[ T = P_{123}(U,U,U)(S_1, I, S_3) \\]\nwhere $S_1 = (U^T P_{23} U)(U^T P_{13} U)^{-1}$ and $S_3 = (U^T P_{21} U)(U^T P_{31} U)^{-1}$.\nIt is known that\n\\[ T = \\sum_i w_i \\]\n\n\n\\end{document}\n", "meta": {"hexsha": "9fbab6861a37bfd88587acf0a091b57f905e041c", "size": 23477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kernelbin/model.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/model.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/model.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": 60.8212435233, "max_line_length": 631, "alphanum_fraction": 0.6587298207, "num_tokens": 8315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387956435734, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6135592489859116}}
{"text": "\\section{Exponential Functions}\\label{sec:ExpFunctions}\r\nAn \\dfont{exponential function} is a function of the form $f(x)=a^x$, where $a$ is a constant.\r\nExamples are $2^x$, $10^x$ and $(1/2)^x$.\r\nTo more formally define the exponential function we look at various kinds of input values.\r\n\r\nIt is obvious\r\nthat $\\ds a^5=a\\cdot a\\cdot a\\cdot a\\cdot a$ and $\\ds a^3=a\\cdot a\\cdot a$, \r\nbut when we consider an exponential function $\\ds a^x$ we can't\r\nbe limited to substituting integers for $x$. What does $\\ds a^{2.5}$ or\r\n$a^{-1.3}$ or $\\ds a^\\pi$ mean? And is it really true that\r\n$a^{2.5}a^{-1.3}=a^{2.5-1.3}$? The answer to the first question is\r\nactually quite difficult, so we will evade it; the answer to the\r\nsecond question is ``yes.''\r\n\r\nWe'll evade the full answer to the hard question, but we have to know\r\nsomething about exponential functions. You need first to understand\r\nthat since it's not ``obvious'' what $\\ds 2^x$ should mean, we are really\r\nfree to make it mean whatever we want, so long as we keep the behavior\r\nthat {\\em is} obvious, namely, when $x$ is a positive integer.\r\nWhat else do we want to be true about $\\ds 2^x$? We\r\nwant the properties of the previous two paragraphs to be true for all\r\nexponents: $\\ds 2^x2^y=2^{x+y}$ and $\\ds (2^x)^y=2^{xy}$.\r\n\r\nAfter the positive integers, the next easiest\r\nnumber to understand is 0: $\\ds 2^0=1$. You have presumably learned this\r\nfact in the past; why is it true?  It\r\nis true precisely because we want $\\ds 2^a2^b=2^{a+b}$ to be true about\r\nthe function $\\ds 2^x$. We need it to be true that $\\ds 2^02^x=2^{0+x}=2^x$,\r\nand this only works if $\\ds 2^0=1$. The same argument implies that $\\ds a^0=1$\r\nfor any $a$.\r\n\r\nThe next easiest set of numbers to\r\nunderstand is the negative integers: for example, $\\ds 2^{-3}=1/2^3$. \r\nWe know that whatever $\\ds 2^{-3}$ means it must be\r\nthat $\\ds 2^{-3}2^{3}=2^{-3+3}=2^0=1$, which means that $\\ds 2^{-3}$ must be\r\n$1/2^3$. In fact, by the same argument, once we know what $\\ds 2^x$ means\r\nfor some value of $x$, $\\ds 2^{-x}$ must be $\\ds 1/2^{x}$ and more generally\r\n$a^{-x}=1/a^x$.\r\n\r\nNext, consider an exponent $1/q$, where $q$ is a positive integer. We\r\nwant it to be true that $\\ds (2^x)^y=2^{xy}$, so $\\ds\r\n(2^{1/q})^q=2$. This means that $\\ds 2^{1/q}$ is a $q$-th root of 2,\r\n$\\ds 2^{1/q}=\\root q\\of{2\\ }$. This is all we need to understand that\r\n$2^{p/q}=(2^{1/q})^p=(\\root q\\of{2\\ })^p$ and\r\n$a^{p/q}=(a^{1/q})^p=(\\root q\\of{a\\ })^p$.\r\n\r\nWhat's left is the hard part: what does $\\ds 2^x$ mean when $x$ cannot be\r\nwritten as a fraction, like $\\ds x=\\sqrt{2\\ }$ or $\\ds x=\\pi$? What we know so\r\nfar is how to assign meaning to $\\ds 2^x$ whenever $x=p/q$. If we were to\r\ngraph $a^x$ (for some $a>1$) at points $x=p/q$ then we'd see something like this:\r\n$$\\includegraphics[width=2.5in]{images/exp1}$$\r\n\r\nThis is a poor picture, but it illustrates a series \r\nof individual points above the rational numbers\r\non the $x$-axis. There are really a lot of ``holes'' in the curve,\r\nabove $x=\\pi$, for example. But (this is the hard part) it is possible\r\nto prove that the holes can be ``filled in'', and that the resulting\r\nfunction, called $\\ds a^x$, really does have the properties we want,\r\nnamely that $\\ds a^xa^y=a^{x+y}$ and $\\ds (a^x)^y=a^{xy}$.\r\nSuch a graph would then look like this:\r\n$$\\includegraphics[width=2.5in]{images/exp2}$$\r\n\r\n\\begin{formulabox}[Three Types of Exponential Functions]\r\nThere are \\ifont{three kinds} of exponential functions $f(x)=a^x$ depending on whether $a>1$, $a=1$ or $0<a<1$:\r\n$$\\includegraphics[width=6in]{images/exp3}$$\r\n\\end{formulabox}\r\n \r\n\\subsection*{Properties of Exponential Functions}\r\nThe first thing to note is that if $a<0$ then problems can occur.\r\nObserve that if $a=-1$ then $(-1)^x$ is not defined for every $x$.\r\nFor example, $x=1/2$ is a square root and gives $(-1)^{1/2}=\\sqrt{-1}$ which is not a real number.\r\n\r\n\\begin{formulabox}[Exponential Function Properties]\r\n\\begin{itemize}\r\n\\item \\ifont{Only defined for positive $a$:} $a^x$ is only defined for all real $x$ if $a>0$\r\n\\item \\ifont{Always positive:} $a^x>0$, for all $x$\r\n\\item \\ifont{Exponent rules: }\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item $\\ds{a^xa^y=a^{x+y}}$\r\n\t\\item $\\ds{\\frac{a^x}{a^y}=a^{x-y}}$\r\n\t\\item $\\ds{\\left(a^x\\right)^y=a^{xy}=a^{yx}=\\left(a^y\\right)^x}$\r\n\t\\item $\\ds{a^xb^x=(ab)^x}$\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\item \\ifont{Long term behaviour:} If $a>1$, then $a^x\\to\\infty$ as $x\\to\\infty$ and $a^x\\to 0$ as $x\\to-\\infty$.\r\n\\end{itemize}\r\n\\end{formulabox}\r\n\r\nThe last property can be observed from the graph. If $a>1$, then as $x$ gets larger and larger, so does $a^x$.\r\nOn the other hand, as $x$ gets large and negative, the function approaches the $x$-axis, that is, $a^x$ approaches $0$.\r\n\r\n\\begin{example}{Reflection of Exponential}{ReflectionExponential}\r\nDetermine an equation of the function after reflecting $y=2^x$ about the line $x=-2$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFirst reflect about the $y$-axis to get $y=2^{-x}$.\r\nNow shift by $2\\times 2=4$ units to the \\ifont{left} to get $y=2^{-(x+4)}$.\r\nSide note: Can you see why this sequence of transformations is the same as reflection in the line $x=-2$?\r\nCan you come up with a general rule for these types of reflections?\r\n\\end{solution}\r\n\r\n\\begin{example}{Determine the Exponential Function}{DetermineExponentialFunction}\r\nDetermine the exponential function $f(x)=ka^x$ that passes through the points $(1,6)$ and $(2,18)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe substitute our two points into the equation to get:\r\n$$x=1,y=6\\to6=ka^1$$\r\n$$x=2,y=18\\to18=ka^2$$\r\nThis gives us $6=ka$ and $18=ka^2$.\r\nThe first equation is $k=6/a$ and subbing this into the second gives: $18=(6/a)a^2$.\r\nThus, $18=6a$ and $a=3$.\r\nNow we can see from $6=ka$ that $k=2$.\r\nTherefore, the exponential function is $$f(x)=2\\cdot 3^x.$$\r\n%\\vspace{-1cm}\r\n\\end{solution}\r\n\r\nThere is one base that is so important and convenient that we give it a special symbol.\r\nThis number is denoted by $e=2.71828\\ldots$ (and is an irrational number). \r\nIts \\ifont{importance} stems from the fact that it simplifies many formulas \r\nof Calculus and also shows up in other fields of mathematics.\r\n\r\n\\begin{example}{Domain of Function with Exponential}{DomainFunctionExponential}\r\nFind the domain of $\\ds f(x)=\\frac{1}{\\sqrt{e^x+1}}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFor domain, we cannot divide by zero or take the square root of negative numbers.\r\nNote that one of the properties of exponentials is that they are always positive!\r\nThus, $e^x+1>0$ (in fact, as $e^x>0$ we actually have that $e^x+1$ is at least one).\r\nTherefore, $e^x+1$ is never zero nor negative, and gives no restrictions on $x$.\r\nThus, the domain is $\\R$.\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:ExpFunctions}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nDetermine an equation of the function $y=a^x$ passing through the point $(3,8)$.\r\n\\begin{sol}\r\n$y=2^x$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the $y$-intercept of $f(x)=4^x+6$.\r\n\\begin{sol}\r\n$y=7$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the $y$-intercept of $f(x)=2\\left(\\frac{1}{2}\\right)^x$.\r\n\\begin{sol}\r\n$y=2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind the domain of $\\ds{y=e^{-x}+e^{\\frac{1}{x}}}$.\r\n\\begin{sol}\r\n$x\\neq 0$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "27a4ab23959e2b541578fa3dd1b20de3c2823aa3", "size": 7441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-3-exp-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-3-exp-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-3-exp-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.2784090909, "max_line_length": 120, "alphanum_fraction": 0.6637548717, "num_tokens": 2485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.6134609114051437}}
{"text": "\n\\subsection{Unitary time}\n\nWhy? What's the interpretation here? Is this an assumption, or just a modelling choice?\n\n\\(\\Psi (t_b-t_a)^* \\Psi (t_b-t_a)=e^{(t_b-t_a)X^*} e^{(t_b-t_a)X}\\)\n\n\\(\\Psi (t_b-t_a)^* \\Psi (t_b-t_a)=e^{(t_b-t_a)(X^*+X)}\\)\n\n\\(X=iH\\)\n\n\\(\\Psi (t_b-t_a)^* \\Psi (t_b-t_a)=e^{(t_b-t_a)(-iH+iH)}=I\\)\n\n\\(\\Psi (t_b-t_a)=e^{(t_b-t_a)iH}\\)\n\n", "meta": {"hexsha": "ce10b4bfdbf6456b8217566d513e988d247dd44d", "size": 351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/physics/QM/03-06-unitary.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/QM/03-06-unitary.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/QM/03-06-unitary.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.9375, "max_line_length": 87, "alphanum_fraction": 0.5754985755, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.6654105521116443, "lm_q1q2_score": 0.6134565171346784}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{courier}\n\\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue\n\\definecolor{mylilas}{RGB}{170,55,241}\n\\lstset{language=Matlab,%\n    basicstyle=\\footnotesize\\ttfamily,\n    breaklines=true,%\n    morekeywords={matlab2tikz},\n    keywordstyle=\\color{blue},%\n    morekeywords=[2]{1}, keywordstyle=[2]{\\color{black}},\n    identifierstyle=\\color{black},%\n    stringstyle=\\color{mylilas},\n    commentstyle=\\color{mygreen},%\n    showstringspaces=false,%without this there will be a symbol in the places where there is a space\n    numbers=none,%\n    numberstyle={\\tiny \\color{black}},% size of the numbers\n    numbersep=9pt, % this defines how far the numbers are from the text\n    emph=[1]{for,end,break},emphstyle=[1]\\color{red}, %some words to emphasise\n    %emph=[2]{word1,word2}, emphstyle=[2]{style},    \n}\n\n\n\\theoremstyle{definition}\n\\newtheorem{remark}{Remark}\n\\newtheorem{exercise}{\\color{red}Exercise}\n\\newtheorem{example}{Example}\n\n\\title[Programming finite elements in Matlab]{Programming finite elements in high-level languages with a focus on Matlab}\n\\author{Tom Gustafsson}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Variational problems}\n\nFinite element method for linear problems concerns the computer\nsolution of the following \\emph{variational problem}: find $u\n\\in U$ such that\n\\begin{equation}\n  a(u,v) = l(v),\n\\end{equation}\nfor every $v \\in V$. Here $U$ and $V$ are Hilbert spaces with the\nnorms $\\|\\cdot\\|_U$ and $\\|\\cdot\\|_V$, $a \\in \\mathcal{L}(U \\times V;\n\\mathbb{R})$ is a continuous bilinear form and $l \\in\n\\mathcal{L}(V;\\mathbb{R})$ is a continuous linear form.\n\nRecall that if $U=V$ the existence and uniqueness of the solution\nfollows from the Lax--Milgram theorem if the bilinear form $a$ is\n\\emph{coercive} in $V$. If $a$ is not coercive or if $U\\neq V$, a more\ngeneral theory is required, see Babu\\v{s}ka--Aziz~\\cite{BA72}.\n\n\\begin{remark}\n    The uniqueness aspect has no effect on the practical programming\nin the sense that using finite elements one can easily \\emph{try} to\ndiscretize and solve continuous problems that are not\nwell-posed. Usually such approaches lead to singular,\nnon-invertible, matrix systems.\n\\end{remark}\n\n\\section{Galerkin methods}\n\nSuppose that there exist finite dimensional subspaces $U_N \\subset U$\nand $V_M \\subset V$ with the dimensions $N$ and $M$, respectively. The\n\\emph{discrete variational problem} reads: find $u_N \\in U_N$ such\nthat\n\\begin{equation}\n  \\label{eq:dweakf}\n  a(u_N,v) = l(v),\n\\end{equation}\nfor every $v \\in V_M$.\n\n\\begin{remark}\n  If $U_N = V_M$, the resulting method is sometimes referred to as the\n  \\emph{Ritz--Galerkin method}. Otherwise, the term\n  \\emph{Petrov--Galerkin method} is used.\n\\end{remark}\n\nSuppose that $U_N = \\mathrm{span}\\,\\{\\varphi_i\\}_{i=1}^N$ and $V_N =\n\\mathrm{span}\\,\\{\\xi_i\\}_{i=1}^M$ for some basis functions $\\varphi_i\n\\in U_N$, $i\\in\\{1,\\cdots,N\\}$ and $\\xi_i \\in V_M$,\n$i\\in\\{1,\\cdots,M\\}$.\nThen we may expand the solution as\n\\begin{equation}\n  u_N = \\sum_{j=1}^N u_j \\varphi_j,\n\\end{equation}\nwhere $u_j \\in \\mathbb{R}$, $j\\in\\{1,\\cdots,N\\}$, are the degrees of\nfreedom. Substituting this expanded solution to \\eqref{eq:dweakf}\nleads to the matrix system\n\\begin{equation}\n  \\label{eq:matrixsystem}\n  A x = b,\n\\end{equation}\nwhere $A \\in \\mathbb{R}^{M \\times N}$, $A_{ij} = a(\\varphi_j, \\xi_i)$, $b \\in \\mathbb{R}^M$, $b_i = l(\\xi_i)$ and $x \\in \\mathbb{R}^N$, $x_i = u_i$.\n\n\\begin{exercise}\n  Derive \\eqref{eq:matrixsystem} from \\eqref{eq:dweakf}.\n\\end{exercise}\n\nThe programming aspect of the Galerkin method is focused on\nunderstanding and implementing the \\emph{assembly procedure} that\nconstructs the pair $(A,b)$ given a bilinear form $a$, linear form $l$\nand a set of basis functions. It is now \\emph{crucial} to understand\nthat given a basis and a bilinear form, we \\emph{always} have a corresponding\nmatrix that approximates the continuous operator.\n\n\\begin{remark}\n    In mathematical literature the finite dimensional spaces $U_N$ and\n$V_M$ are sometimes defined by limiting the set of arbitrary functions\nto, e.g., piecewise polynomial functions. In such cases the basis is\nimplicit in the sense that we must do additional work to find the\nbasis functions or evaluate them pointwise.  Thus, from a programming\npoint-of-view an explicit basis is usually more preferable.\n\\end{remark}\n\n\\subsection{On the choice of basis functions}\n\nLet us briefly discuss through examples how the choice of the basis\naffects to the properties of the matrix $A$. In the following examples\n$U=V$ and $U_N = V_M$.\n\n\\begin{example}\n  \\label{ex:diagonal}\n  Consider the bilinear and linear forms\n  \\begin{equation}\n    a(w,v) = \\int_0^1 w^\\prime v^\\prime\\,\\mathrm{d}x, \\quad l(v) = \\int_0^1 v\\,\\mathrm{d}x,\n  \\end{equation}\n  and the basis $\\{\\sin (\\pi (2n-1) x)\\}_{n=1}^N$. In terms of Matlab\n  code, we have\n  \\begin{lstlisting}\n    syms x\n    N=5;\n    dphi=diff(sin(pi*(1:2:(2*N))*x),x);\n    A=int(dphi'*dphi,x,0,1);\n  \\end{lstlisting}\n  which outputs the matrix\n  \\begin{equation}\n\\left(\\begin{array}{ccccc} \\frac{{\\pi}^2}{2} & 0 & 0 & 0 & 0\\\\ 0 & \\frac{9\\, {\\pi}^2}{2} & 0 & 0 & 0\\\\ 0 & 0 & \\frac{25\\, {\\pi}^2}{2} & 0 & 0\\\\ 0 & 0 & 0 & \\frac{49\\, {\\pi}^2}{2} & 0\\\\ 0 & 0 & 0 & 0 & \\frac{81\\, {\\pi}^2}{2} \\end{array}\\right).\n  \\end{equation}\n  Notice that the matrix is diagonal. This means that the solution\nwill be quick.  The corresponding linear form can be assembled and\nthe system solved with\n  \\begin{lstlisting}\n    b=int(sin(pi*(1:2:(2*N))*x),x,0,1)';\n    x=A\\b;\n  \\end{lstlisting}\n\\end{example}\n\n\\begin{exercise}\n  Draw the solution given by the Galerkin method in the previous example.\n\\end{exercise}\n\n\\begin{remark}\n  The usage of symbolic integration is not a good idea in general due\nto a high computational cost in comparison to numerical integration.\n\\end{remark}\n\n\\begin{example}\n  Consider the same bilinear form as in Example~\\ref{ex:diagonal}\n  and the polynomial basis $\\{x^n(1-x)^n\\}_{n=1}^N$. Now the matrix $A$ is\n  \\begin{equation}\n    \\left(\\begin{array}{ccccc} \\frac{1}{3} & \\frac{1}{15} & \\frac{1}{70} & \\frac{1}{315} & \\frac{1}{1386}\\\\ \\frac{1}{15} & \\frac{2}{105} & \\frac{1}{210} & \\frac{4}{3465} & \\frac{5}{18018}\\\\ \\frac{1}{70} & \\frac{1}{210} & \\frac{1}{770} & \\frac{1}{3003} & \\frac{1}{12012}\\\\ \\frac{1}{315} & \\frac{4}{3465} & \\frac{1}{3003} & \\frac{4}{45045} & \\frac{1}{43758}\\\\ \\frac{1}{1386} & \\frac{5}{18018} & \\frac{1}{12012} & \\frac{1}{43758} & \\frac{5}{831402} \\end{array}\\right).\n  \\end{equation}\n  Notice that this time the matrix is full and hence the solution of\nthe linear system requires more effort.\n\\end{example}\n\nBased on the examples, we can deduce that the choice of the basis (or,\nequivalently, the subspace $V_N$) has an effect on\n\\begin{itemize}\n  \\item the \\emph{sparsity\n    pattern} of the resulting matrix, and\n    \\item the \\emph{condition\nnumber}\\footnote{As given by the Matlab function \\emph{cond}.} which for the\nformer matrix is 81 whereas the condition number of the latter matrix\nis approximately $2.1 \\cdot 10^8$.\n\\end{itemize}\nMoreover, let $P_N : V \\rightarrow V_N$ be an orthogonal\nprojection. Using the continuity and coercivity of $a$, we get\n\\begin{align*}\n  \\|u-u_N\\|_V^2 &\\leq C^\\prime a(u-u_N,u-u_N) \\\\\n                &= C^\\prime a(u-u_N,u-P_N u) \\\\\n  &\\leq C \\|u-u_N\\|_V \\|u-P_N u\\|_V,\n\\end{align*}\nfor some $C, C^\\prime >0$. This leads to\n\\begin{equation}\n  \\|u-u_N\\|_V \\leq C \\|u-P_N u\\|_V,\n\\end{equation}\nwhich essentially means that the error (in the sense of $\\|u-u_N\\|_V$)\ndepends on \\emph{how well the space $V_N$ can represent functions of\nthe space $V$}. In an ``ideal case'' the exact solution belongs to the\ndiscrete space $V_N$ leading to zero error. In practice this is rarely\nthe case.\n\nEverything we have discussed so far applies to all Galerkin methods.\nNext we focus on a particular Galerkin method called the \\emph{finite\nelement method}.\n\n\\section{Finite element method}\n\nFinite element methods are special Galerkin methods where the basis\nfunctions are defined using a \\emph{mesh}. In the following we\nconsider two dimensional problems but many parts can be\nstraightforwardly generalized to three dimensional problems.\n\n\\subsection{Mesh}\n\nLet $\\Omega \\subset \\mathbb{R}^2$ a polygonal domain. We split the\ndomain $\\Omega$ into non-overlapping triangles or \\emph{elements} $T\n\\in \\mathcal{T}$ that satisfy\n\\begin{equation}\n  \\overline{\\Omega} = \\bigcup_{T \\in \\mathcal{T}} \\overline{T}.\n\\end{equation}\nThe collection of elements $\\mathcal{T}$ is called a mesh.  One\nfrequently encounters the notion of a \\emph{mesh parameter $h_T$ of a\ntriangle $T$} that describes the maximum edge length of $T$, i.e.,\n\\begin{equation}\n  h_T = \\max_{x,y \\in T} \\|x-y\\|,\n\\end{equation}\nwhere $\\|\\cdot\\|$ is the Euclidean norm. The mesh parameter of a\nmesh $\\mathcal{T}$ is then\n\\begin{equation}\n  h = \\max_{T \\in \\mathcal{T}} h_T.\n\\end{equation}\n\nLet $N$ be the number of vertices in the mesh and let $M$ be the\nnumber of elements.  In high-level array-based languages such as\nMatlab, a convenient way to represent triangular (and other) meshes is\nto use two matrices $p \\in \\mathbb{R}^{2 \\times N}$ and $t \\in\n\\mathbb{R}^{3 \\times M}$. In the former, each column corresponds to\n$x$ and $y$ coordinates of a vertex and in the latter each column\ncorresponds to the three indices of the vertices of an element.\n\n\\begin{example}\n  Using Matlab PDE Toolbox we can generate a triangular mesh for the\n  unit square with $h\\leq 0.1$ using the command\n\\begin{lstlisting}\n    [p,~,t]=initmesh(decsg([3 4 0 1 1 0 0 0 1 1]'),'Hmax',0.1)\n\\end{lstlisting}\n  The matrix $t$ given by \\emph{initmesh} has one extra row which\n  in case of multiple domains tells us the subdomain in which the\n  triangle lies. We do not need this information and therefore we\n  strip the last row as follows:\n\\begin{lstlisting}\n    t=t(1:3,:);\n\\end{lstlisting}\n  The mesh can now be visualized with\n\\begin{lstlisting}\n    trimesh(t',p(1,:),p(2,:));\n\\end{lstlisting}\n\\end{example}\n\n\\begin{exercise}\n  Visualize two meshes with different mesh parameters.\n\\end{exercise}\n\n\\subsection{Definition of the piecewise linear basis functions}\n\nIn this text we focus on the \\emph{piecewise linear basis}.  Each\nbasis function is defined so that it has value 1 in one vertex of the\nmesh and value 0 in all other vertices. Furthermore, the basis\nfunction is linear inside each element.\n\n\\begin{example}\n  Let us generate a mesh and visualize all the basis functions.\n  \\begin{lstlisting}\n    [p,~,t]=initmesh(decsg([3 4 0 1 1 0 0 0 1 1]'),'Hmax',0.5);\n    t=t(1:3,:);\n    figure;\n    % there is one basis function per node, loop over nodes\n    for itr = 1:size(p,2)\n        subplot(ceil(sqrt(size(p,2))),ceil(sqrt(size(p,2))),itr);\n        % the basis function is zero everywhere else ...\n        u=zeros(size(p,2),1);\n        % ... but one node.\n        u(itr)=1;\n        % draw the resulting surface\n        trisurf(t',p(1,:),p(2,:),u);\n        colormap parula;\n        shading interp;\n        view(2);\n    end\n  \\end{lstlisting}\n  From the resulting figure you can probably see why these\n  kind of basis functions are sometimes referred to as\n  the \\emph{hat functions}.\n\\end{example}\n\nThese kind of basis functions have some nice properties.\nFor example:\n\\begin{enumerate}\n\\item They are based on a mesh and hence any domain\n  that can be meshed is amenable to discretization.\n\\item The basis functions are nonzero on a very small area.\n  Therefore, most entries of the resulting system matrix are zero\n  and the matrix will be sparse.\n\\item We can easily project an arbitrary function to the\n  basis by evaluating it at the vertices of the mesh.\n\\end{enumerate}\n\n\\subsection{Assembly of finite elements}\n\nLet us denote by $\\varphi_i$, $i \\in \\{1, \\cdots, N\\}$ the set of\npiecewise linear basis functions defined by the mesh $\\mathcal{T}$\nof the domain $\\Omega$.\nConsider the bilinear form\n\\begin{equation}\n  a(w,v) = \\int_\\Omega \\nabla w \\cdot \\nabla v\\,\\mathrm{d}x.\n\\end{equation}\nOur goal is to construct the matrix $A \\in \\mathbb{R}^{N \\times N}$\nwith the entries $A_{ij} = a(\\varphi_j, \\varphi_i)$.  Since $N$ can be\nvery large and a large portion of the values $A_{ij}$ are zero, it is\nnot a good idea to evaluate each $a(\\varphi_j, \\varphi_i)$\nseparately. Instead, we evaluate \\emph{all nonzero terms} of the form\n\\begin{equation}\n  \\label{eq:integral}\n    \\int_T \\nabla \\varphi_j \\cdot \\nabla \\varphi_i\\,\\mathrm{d}x, \\quad T \\in \\mathcal{T}, \\quad i,j \\in \\{1,\\cdots,N\\},\n\\end{equation}\nand add them together appropriately to \\emph{assemble} $A$.\n\n\\begin{exercise}\n  Download the commented version of the Matlab class template with the command\n  \\begin{lstlisting}\n    unzip('http://super.org/file.zip')\n  \\end{lstlisting}\n  Read through \\emph{LinearAssembler.m} and try to run the tests with\n  \\begin{lstlisting}\n    run(LinearAssemblerTests)\n  \\end{lstlisting}\n\\end{exercise}\n\nNext we start introducing necessary concepts to implement the methods\nof the class \\verb|LinearAssembly|. We first implement the static\nmethods, secondly we write the constructor which does some\nprecomputations and finally implement the methods that assemble\nbilinear and linear forms.\n\n\\subsection{Reference element}\n\nEvaluation of the integral \\eqref{eq:integral} can be done\nsystematically by mapping it to the \\emph{reference triangle}\n$\\widehat{T}$ defined as\n\\begin{equation}\n  \\widehat{T} = \\{ (\\widehat{x}, \\widehat{y}) : \\widehat{x} \\geq 0,~ \\widehat{y} \\geq 0,~ \\widehat{x}+\\widehat{y}\\leq 1 \\}.\n\\end{equation}\nWe end up evaluating integrals of polynomials on the reference\ntriangle and for this we require \\emph{quadrature rules}. The idea of\nquadrature rules is to replace the integral with a sum, i.e., for\na given polynomial $p \\in P_n(\\widehat{T})$\nand triplets $(\\widehat{x}_k,\\widehat{y}_k,w_k)$, $k \\in \\{1, \\cdots, M\\}$,\nwe write\n\\begin{equation}\n  \\int_{\\widehat{T}} p(\\widehat{x},\\widehat{y}) \\,\\mathrm{d}\\widehat{x}\\,\\mathrm{d}\\widehat{y} \\approx \\sum_{k = 1}^{M} p(\\widehat{x}_k,\\widehat{y}_k) w_k.\n\\end{equation}\n\\begin{remark}\n  For any given polynomial order $n$ the quadrature rule can be exact\n  if $M$ and the triplets are chosen right. The construction of exact\n  rules is, however, non-trivial. See, e.g., Dunavant~\\cite{D85} where\n  an exact rule for second order polynomials is given by the triplets\n  \\begin{equation}\n    (\\tfrac{1}{3},\\tfrac{1}{3},\\tfrac{1}{6}), \\quad \n    (\\tfrac{2}{3},\\tfrac{1}{3},\\tfrac{1}{6}), \\quad \n    (\\tfrac{1}{3},\\tfrac{2}{3},\\tfrac{1}{6}).\n  \\end{equation}\n\\end{remark}\n\\begin{exercise}\n  Implement the method \\verb|localQuadrature|.\n\\end{exercise}\nLet $F_T : \\widehat{T} \\rightarrow T$ be an affine mapping of the form\n\\begin{equation}\n  \\begin{bmatrix} x \\\\ y \\end{bmatrix} = F_T(\\widehat{x},\\widehat{y}) = B_T\\begin{bmatrix} \\widehat{x} \\\\ \\widehat{y}\\end{bmatrix}+c_T, \n\\end{equation}\nwhere $B_T \\in \\mathbb{R}^{2 \\times 2}$ and $c_T \\in \\mathbb{R}^{2 \\times 1}$\ndepend on the location and the shape of the triangle $T$.\nNotice that we denote by $(x,y)$ points in the global\ncoordinate system and by $(\\widehat{x},\\widehat{y})$ points in the\ncoordinate system of the reference element.\n\\begin{exercise}\n  Find explicit expressions for $B_T$ and $c_T$ in terms of the\nvertices of the element $T$ and implement the method \\verb|affineMappings|.\n\\end{exercise}\n\\begin{exercise}\n  Implement the method \\verb|F| which maps points from the local coordinate\n  system to the global coordinate system using $B_T$ and $c_T$.\n\\end{exercise}\n\\subsection{Transforming the local basis}\nLet the local basis functions be defined as\n\\begin{equation}\n  \\widehat{\\varphi}_1(\\widehat{x},\\widehat{y}) = 1 - \\widehat{x} - \\widehat{y}, \\quad \\widehat{\\varphi}_2(\\widehat{x},\\widehat{y}) = \\widehat{x}, \\quad \\widehat{\\varphi}_3(\\widehat{x},\\widehat{y}) = \\widehat{y}.\n\\end{equation}\nOur goal is to describe the global basis functions $\\varphi_i$,\n$i\\in\\{1,\\cdots,N\\}$, using these local basis functions.\n\\begin{exercise}\n  Implement the method \\verb|localBasis|.\n\\end{exercise}\nLet $m$ be the column corresponding to the triangle $T$ in the element\nmatrix $t$. The global basis functions that are nonzero in element $T$\ncan be now defined as\n\\begin{equation}\n  \\label{eq:phi}\n  \\varphi_{e_i^{\\mathrm{T}}te_m}(F_T(\\widehat{x},\\widehat{y}))= \\widehat{\\varphi}_i(\\widehat{x},\\widehat{y}),\n\\end{equation}\nfor each $i \\in \\{1,2,3\\}$. Using the chain rule, we deduce that the\nderivatives transform as follows:\n\\begin{equation}\n  \\label{eq:dphi}\n  \\nabla \\varphi_{e_i^{\\mathrm{T}}te_m}(F_T(\\widehat{x},\\widehat{y})) = B_T^{-\\mathrm{T}} \\widehat{\\nabla} \\widehat{\\varphi}_i(\\widehat{x},\\widehat{y}),\n\\end{equation}\n\\begin{exercise}\n  Implement \\verb|globalBasis| which maps the local basis to global\nbasis using \\eqref{eq:phi} and \\eqref{eq:dphi}.\n\\end{exercise}\nFinally, the integral \\eqref{eq:integral} is transformed as\n\\begin{equation}\n  \\label{eq:integraltransform}\n    \\int_T \\nabla \\varphi_{e_j^{\\mathrm{T}}te_m} \\cdot \\nabla \\varphi_{e_i^{\\mathrm{T}}te_m}\\,\\mathrm{d}x = \\int_{\\widehat{T}} B_K^{-\\mathrm{T}}\\widehat{\\nabla} \\widehat{\\varphi}_j \\cdot B_K^{-\\mathrm{T}}\\widehat{\\nabla}\\widehat{\\varphi}_i|\\det B_K|\\,\\mathrm{d}\\widehat{x}.\n\\end{equation}\n\\begin{exercise}\n  Implement \\verb|determinant| for computing the determinant in \\eqref{eq:integraltransform}.\n\\end{exercise}\n\n\\begin{thebibliography}{1}\n\\bibitem{BA72} I.~Babu\\v{s}ka, A.~K.~Aziz. The Mathematical Foundations of the Finite Element Method with Applications to Partial Differential Equations. Academic Press (1972).\n\\bibitem{D85} D.~A.~Dunavant. High degree efficient symmetrical Gaussian quadrature rules for the triangle (1985).\n\\end{thebibliography}\n\n\\end{document}", "meta": {"hexsha": "e260736e2e116ce34bfa3a7607c75ffa5cfc8216", "size": 17755, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "kinnala/matlab-fem-course", "max_stars_repo_head_hexsha": "27b9f5648cc060ea118b8d356129cf3a7f90ca7d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-05T05:59:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T05:59:37.000Z", "max_issues_repo_path": "notes.tex", "max_issues_repo_name": "kinnala/matlab-fem-course", "max_issues_repo_head_hexsha": "27b9f5648cc060ea118b8d356129cf3a7f90ca7d", "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": "notes.tex", "max_forks_repo_name": "kinnala/matlab-fem-course", "max_forks_repo_head_hexsha": "27b9f5648cc060ea118b8d356129cf3a7f90ca7d", "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.9101382488, "max_line_length": 465, "alphanum_fraction": 0.707969586, "num_tokens": 5717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6133447722783683}}
{"text": "\\documentclass{article}\n\\usepackage{ws_template}\n\n\\usepackage{amsmath}\n\\usepackage{listings}\n\n\\title{homework sheet 01}\n\\author{\n\t\\name{Denys Sobchyshak}\\\\\n\t\\imat{03636581}\\\\\n\t\\email{denys.sobchyshak@gmail.com}\n\t\\And\n\t\\name{Sergey Zakharov}\\\\\n\t\\imat{03636642}\\\\\n\t\\email{ga39pad@mytum.de}\n}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Problem}\n\tTo find eigenvalues of the matrix A we have to solve $ det(A-\\lambda I)=0 $ which cane be derived from an eigenvelue equation. \\\\\n\t\\[\n\tdet(A-\\lambda I)= det\n\t\\begin{pmatrix} \n\t\t2-\\lambda & -1 & 0  \\\\ \n\t\t-1 & 2-\\lambda & -1 \\\\\n\t\t0 & -1 & 2-\\lambda\n\t\\end{pmatrix}\n\t=(2-\\lambda)^3-2(2-\\lambda)=(2-\\lambda)((2-\\lambda)^2-2)=0\n\t\\]\\\\\n\tThus we can see that the spectrum of the matrix is given by $\\lambda(A)=\\left\\{2, 2-\\sqrt{2},2+\\sqrt{2}\\right\\}$. To find the corresponding eigenvectors we substitute our eigenvalues into the eigenvalue equation.\\\\\n\t\\begin{enumerate}\n\t\t\\item For $\\lambda=2$:\\\\\n\t\t$\n\t\tA-2I=0 \\Rightarrow\n\t\t\\left(\\begin{array}{ccc|c}\n\t\t2-2 & -1 & 0 & 0 \\\\ \n\t\t-1 & 2-2 & -1 & 0\\\\ \n\t\t0 & -1 & 2-2 & 0\n\t\t\\end{array}\\right)\n\t\t\\Rightarrow \\left\\{\n\t\t\\begin{array}{cc}\n\t\tx=-z\\\\\n\t\ty=0\\\\\n\t\t\\end{array}\\right.\n\t\t$\\\\\n\t\tThus using $z=-1$ we get the next eigenvector $v_1=\\begin{pmatrix}1 \\\\0\\\\ -1\\end{pmatrix}$.\n\n\t\t\\item For $\\lambda=2-\\sqrt{2}$:\\\\\n\t\t$\n\t\tA-2I=0 \\Rightarrow\n\t\t\\left(\\begin{array}{ccc|c}\n\t\t2-2+\\sqrt{2} & -1 & 0 & 0 \\\\\n\t\t0 & -1 & 2-2+\\sqrt{2} & 0 \\\\\n\t\t-1 & 2-2+\\sqrt{2} & -1 & 0 \n\t\t\\end{array}\\right)\n\t\t\\Rightarrow \\left\\{\n\t\t\\begin{array}{cc}\n\t\tx=\\frac{y}{\\sqrt{2}}\\\\\n\t\ty=\\sqrt{2}z\\\\\n\t\tz=\\frac{y}{\\sqrt{2}}\\\\\n\t\t\\end{array}\\right.\n\t\t$\\\\\n\t\tThus using $z=1$ we get the next eigenvector $v_2=\\begin{pmatrix}1 \\\\\\sqrt{2}\\\\ 1\\end{pmatrix}$.\n\t\t\n\t\t\\item For $\\lambda=2+\\sqrt{2}$:\\\\\n\t\t$\n\t\tA-2I=0 \\Rightarrow\n\t\t\\left(\\begin{array}{ccc|c}\n\t\t2-2-\\sqrt{2} & -1 & 0 & 0 \\\\ \n\t\t-1 & 2-2-\\sqrt{2} & -1 & 0\\\\ \n\t\t0 & -1 & 2-2-\\sqrt{2} & 0\n\t\t\\end{array}\\right)\n\t\t\\Rightarrow \\left\\{\n\t\t\\begin{array}{cc}\n\t\tx=-\\frac{y}{\\sqrt{2}}\\\\\n\t\ty=-\\sqrt{2}z\\\\\n\t\tz=-\\frac{y}{\\sqrt{2}}\\\\\n\t\t\\end{array}\\right.\n\t\t$\\\\\n\t\tThus using $z=1$ we get the next eigenvector $v_3=\\begin{pmatrix}1 \\\\-\\sqrt{2} \\\\ 1\\end{pmatrix}$.\n\t\\end{enumerate}\n\tThe corresponding python/numpy code looks as follows:\\\\\n\t\\lstinputlisting[language=Python,firstline=21]{scripts/ws1-linear-algebra.py}\n\t\n\t\\section{Problem}\n\tIf $ x_1, x_2 ... x_n$ are linearly independent eigenvectors of $ B \\in  R^{n \\times n} $ and $ \\lambda_i $ are its eigenvalues then the following equation is satisfied: $ Bx_i = \\lambda_i x_i $.\n\tThis equation can be rewritten as $ BU = UD $ from here we get matrix $ B = UDU^{-1} $ as follows:\\\\\\\\\n\t$\n\tBU=B\\begin{bmatrix} X_{1} & X_{2} & \\cdots & X_n \\end{bmatrix}\n\t=\\begin{bmatrix} BX_{1} & BX_{2} & \\cdots & BX_n \\end{bmatrix}\n\t=\\begin{bmatrix} \\lambda_1X_{1} & \\lambda_2X_{2} & \\cdots & \\lambda_nX_n \\end{bmatrix}\\\\\n\t=\\begin{bmatrix} \n\t\\lambda_1x_{1,1} & \\lambda_2x_{2,1} & \\cdots & \\lambda_nx_{n,1} \\\\\n\t\\lambda_1x_{1,2} & \\lambda_2x_{2,2} & \\cdots & \\lambda_nx_{n,2} \\\\\n\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t\\lambda_1x_{1,n} & \\lambda_2x_{2,n} & \\cdots & \\lambda_nx_{n,n}\n\t\\end{bmatrix}\n\t=\\begin{bmatrix} \n\tx_{1,1} & x_{2,1} & \\cdots & x_{n,1} \\\\\n\tx_{1,2} & x_{2,2} & \\cdots & x_{n,2} \\\\\n\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\tx_{1,n} & x_{2,n} & \\cdots & x_{n,n}\n\t\\end{bmatrix}\n\t\\begin{bmatrix} \n\t\\lambda_1 & 0 & \\cdots & 0 \\\\\n\t0 & \\lambda_2 & \\cdots & 0 \\\\\n\t\\vdots & \\vdots & \\ddots & \\vdots \\\\\n\t0 & 0 & \\cdots & \\lambda_n\n\t\\end{bmatrix}\\\\\n\t=UD \\Leftrightarrow BUU^{-1}=B=UDU^{-1}\n\t$\n\t\\section{Problem}\n\t\\begin{itemize}\n\t\t\\item $B \\bar{x} = \\lambda \\bar{x} $. Suppose that $\\lambda$ and $\\bar{x}$ are possibly complex and  $x \\not=0$  .\n\t\tWe take conjugate transpose to get $\\bar{\\lambda} x^* = (\\lambda x)^* = (Ax)^* =x^*A^* = x^*A$  (because A is real and symmetric). Then $\\bar{\\lambda}^*x = (x^*A)x = x^*(Ax) = \\lambda x^*x$. $x^*x$ is nonzero and real. So we get $\\bar{\\lambda} = \\lambda$, which means that $\\lambda$ is real.\n\t\t\\item Assume $Av =\\lambda v$ and  $ Aw =\\mu w$. Then  \\[ \\lambda(v, w) = (\\lambda v, w) = (Av, w) = (v, A^T w) = (v, Aw) = (v, \\mu w) = \\mu (v, w) \\] is possible only if $(v, w) = 0$.\n\t\\end{itemize}\n\t\n\t\\section{Problem}\n\t\\begin{itemize}\n\t\t\\item $ |B| =  |UDU^{-1}| = |DU^{-1}U| = |D| = \\prod_i{\\lambda_i} $\n\t\t\\item $ tr(B) = tr(UDU^{-1}) = tr(DU^{-1}U) = tr(D) = \\sum_i{\\lambda_i} $\n\t\\end{itemize}\n\t\n\t\\section{Problem}\n\t\\begin{itemize}\n\t\t\\item $ h(x_0) = w_0 + w^T x_0 = 0 \\Rightarrow w^T x_0 = -w_0 $\n\t\t\\item $ h(x_1) = w_0 + w^T x_1 = 0 \\\\\n\t\th(x_2) = w_0 + w^T x_2 = 0 \\\\\n\t\th(x_1) - h(x_2) = w^T x_1 - w^T x_2 =  w^T (x_1 - x_2) = 0 $\n\t\t\\item Normal vector is defined as $\\nabla h(x) = w$. $ \\frac{\\nabla h(x)}{|| \\nabla h(x)||} = \\frac{w}{||w||}$ is a unit normal vector. So $ \\hat{w} = \\frac{w}{||w||}$ is a unit normal vector.\n\t\t\\item Distance can be found by projecting $(x - x_0)$ onto normal vector $w$. \\[ D = |proj_w(x-x_0)| =\\frac{w^T (x - x_0)}{||w||} = \\hat{w}(x-x_0) = \\frac{w^T x - w^T x_0}{||w||}  \\overset{w^T x_0 = -w_0}{= \\joinrel = \\joinrel = \\joinrel = \\joinrel = \\joinrel = \\joinrel =} \\frac{w^T x + w_0}{||w||} \\]\n\t\\end{itemize}\n\t\n\\end{document}", "meta": {"hexsha": "6879d5f6c46977080c5cf6cbd8c563a17f44722b", "size": 5120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tum/machine-learning/ws01-linear-algebra.tex", "max_stars_repo_name": "nyxcalamity/classwork", "max_stars_repo_head_hexsha": "dfe47a40fe57ec5e0ccfd672a8dcaf246386de99", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-02-10T19:12:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-03T00:08:40.000Z", "max_issues_repo_path": "tum/machine-learning/ws01-linear-algebra.tex", "max_issues_repo_name": "nyxcalamity/classwork", "max_issues_repo_head_hexsha": "dfe47a40fe57ec5e0ccfd672a8dcaf246386de99", "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": "tum/machine-learning/ws01-linear-algebra.tex", "max_forks_repo_name": "nyxcalamity/classwork", "max_forks_repo_head_hexsha": "dfe47a40fe57ec5e0ccfd672a8dcaf246386de99", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2016-05-02T11:00:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-20T03:55:35.000Z", "avg_line_length": 37.3722627737, "max_line_length": 304, "alphanum_fraction": 0.580078125, "num_tokens": 2285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6133447647603366}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} \n\\usepackage{graphicx}\n\\usepackage{setspace}\n\\usepackage{bm}\n\\usepackage{amsmath}\n\\usepackage{amssymb,amsmath}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{enumitem}\n\\usepackage{fancyvrb}\n\\usepackage{hyperref}\n\\usepackage{diagbox}\n\\usepackage{float}\n\\geometry{letterpaper}\n\\linespread{1.1}% \\geometry{landscape} % rotated page geometry\n\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codegray}{rgb}{0.5,0.5,0.5}\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\n\\definecolor{backcolour}{rgb}{0.95,0.95,0.92}\n\\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}\n\n\\lstdefinestyle{mystyle}{\n\tbackgroundcolor=\\color{backcolour},   \n\tcommentstyle=\\color{codegreen},\n\tkeywordstyle=\\color{magenta},\n\tnumberstyle=\\tiny\\color{codegray},\n\tstringstyle=\\color{codepurple},\n\tbasicstyle=\\footnotesize,\n\tbreakatwhitespace=false,         \n\tbreaklines=true,                 \n\tcaptionpos=b,                    \n\tkeepspaces=true,                 \n\tnumbers=left,                    \n\tnumbersep=5pt,                  \n\tshowspaces=false,                \n\tshowstringspaces=false,\n\tshowtabs=false,                  \n\ttabsize=2\n}\n\n\\lstset{style=mystyle}\n\n\\title{HW 2: State Estimation in Oil \\& Gas Well Drilling}\n\\date{16 Feb. 2018} \n\\author{Franklin Zhao \\\\ SID: 3033030808}\n\n\\begin{document}\n\t\n\t\\maketitle\n\t\\newcommand{\\tabitem}{~~\\llap{\\textbullet}~~}\n\t\\renewcommand\\theequation{\\arabic{equation}}\n\t\\renewcommand{\\figurename}{Fig.}\n\t\\renewcommand\\thesection{Problem \\arabic{section}:}\n\t\\renewcommand\\thesubsection{(\\alph{subsection})}\n\t\\onehalfspacing\n\t\n\\section{Dynamic System Modeling}\n\\subsection{}\n\\textbf{Modeling objective:} The objective is to formulate a mathmetical model that estimates the drill bit velocity given the table torque $T(t)$.\\\\\n\\textbf{Controllable input:} Table torque $\\bf{T(t)}$\\\\\n\\textbf{Uncontrollable input:} Frictional torque $\\bf{T_f(t)}$\\\\\n\\textbf{Measured output:} Table velocity $\\bf{\\omega_T(t)}$\\\\\n\\textbf{Performance output:} Bit velocity $\\bf{\\omega_B(t)}$\n\\subsection{}\nFor the top/table:\n\\begin{equation}\nJ_T\\ddot{\\theta}_T(t)=-k(\\theta_T(t)-\\theta_B(t))-b\\omega_T(t)+T(t)\n\\end{equation}\nFor the bottom/bit:\n\\begin{equation}\nJ_B\\ddot{\\theta}_B(t)=k(\\theta_T(t)-\\theta_B(t))-b\\omega_B(t)-T_f(t)\n\\end{equation}\n\\subsection{}\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\left[\n\\begin{array}{c}\n\\theta_T\\\\\n\\dot\\theta_T\\\\\n\\theta_B\\\\\n\\dot\\theta_B\n\\end{array}\\right]=\\underbrace{\\left[\n\\begin{array}{cccc}\n0&1&0&0\\\\\n-\\frac{k}{J_T}&-\\frac{b}{J_T}&\\frac{k}{J_T}&0\\\\\n0&0&0&1\\\\\n\\frac{k}{J_B}&0&-\\frac{k}{J_B}&-\\frac{b}{J_B}\n\\end{array}\\right]}_\\text{\\textbf{A}}\\left[\n\\begin{array}{c}\n\\theta_T\\\\\n\\dot\\theta_T\\\\\n\\theta_B\\\\\n\\dot\\theta_B\n\\end{array}\\right]+\\underbrace{\\left[\n\\begin{array}{c}\n0\\\\\n\\frac{1}{J_T}\\\\\n0\\\\\n0\n\\end{array}\n\\right]}_\\text{\\textbf{B}}T+\\left[\n\\begin{array}{c}\n0\\\\\n0\\\\\n0\\\\\n-\\frac{1}{J_B}\n\\end{array}\n\\right]T_f\n\\end{equation}\n\\begin{equation}\n\\dot\\theta_T=\\underbrace{\\left[\n\\begin{array}{cccc}\n0&1&0&0\n\\end{array}\n\\right]}_\\text{\\textbf{C}}\\left[\n\\begin{array}{c}\n\\theta_T\\\\\n\\dot\\theta_T\\\\\n\\theta_B\\\\\n\\dot\\theta_B\n\\end{array}\n\\right]\n\\end{equation}\n\\section{Observability Analysis}\n\\subsection{}\n\\lstinputlisting[language=Python]{2a.py}\n\\begin{Verbatim}\nRank of Observability Matrix for four-state system: 3\n\\end{Verbatim}\nSince $rank(\\mathcal{O})=3<4$, $(A,C)$ is not observable.\n\\subsection{}\n\\begin{equation}\n\\frac{\\partial}{\\partial t}\\left[\n\\begin{array}{c}\n\\theta\\\\\n\\dot\\theta_T\\\\\n\\dot\\theta_B\n\\end{array}\\right]=\\underbrace{\\left[\n\t\\begin{array}{ccc}\n\t0&1&-1\\\\\n\t-\\frac{k}{J_t}&-\\frac{b}{J_t}&0\\\\\n\t\\frac{k}{J_B}&0&-\\frac{b}{J_B}\n\t\\end{array}\\right]}_\\text{\\textbf{A}}\\left[\n\\begin{array}{c}\n\\theta\\\\\n\\dot\\theta_T\\\\\n\\dot\\theta_B\n\\end{array}\\right]+\\underbrace{\\left[\n\t\\begin{array}{c}\n\t0\\\\\n\t\\frac{1}{J_T}\\\\\n\t0\n\t\\end{array}\n\t\\right]}_\\text{\\textbf{B}}T+\\left[\n\\begin{array}{c}\n0\\\\\n0\\\\\n-\\frac{1}{J_B}\n\\end{array}\n\\right]T_f\n\\end{equation}\n\\begin{equation}\n\\dot\\theta_T=\\underbrace{\\left[\n\t\\begin{array}{cccc}\n\t0&1&0\n\t\\end{array}\n\t\\right]}_\\text{\\textbf{C}}\\left[\n\\begin{array}{c}\n\\theta\\\\\n\\dot\\theta_T\\\\\n\\dot\\theta_B\n\\end{array}\n\\right]\n\\end{equation}\n\\subsection{}\n\\lstinputlisting[language=Python]{2c.py}\n\\begin{Verbatim}\nRank of Observability Matrix for three-state system: 3\n\\end{Verbatim}\nSince $rank(\\mathcal{O})=3$, $(A,C)$ is observable.\n\\section{Measurement Data}\n\\lstinputlisting[language=Python]{3.py}\nThe plots of table torque and measured table velocity versus time are shown in Figure~\\ref{fig:3}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{3.png}      \n\t\\caption{Table torque and measured table velocity versus time}\n\t\\label{fig:3}\n\\end{figure}\n\\section{Luenberger Observer}\n\\subsection{}\nDenote $\\left[\n\\begin{array}{c}\n\\hat\\theta\\\\\n\\hat{\\dot\\theta}_T\\\\\n\\hat{\\dot\\theta}_B\n\\end{array}\n\\right]$ by $\\hat x(t)$, $\\hat{\\dot\\theta}_T$ by $\\hat y(t)$, $T(t)$ by $u(t)$, and the Luenberger observer equations will be:\n\\begin{equation}\\label{eq:luen1}\n\\dot{\\hat x}(t)=A\\hat x(t)+Bu(t)+L[y(t)-\\hat y(t)],\\ \\ \\ \\hat x(0)=\\hat{x}_0\n\\end{equation}\n\\begin{equation}\\label{eq:luen2}\n\\hat y(t)=C\\hat x(t)\n\\end{equation}\n\\lstinputlisting[language=Python]{4a.py}\n\\begin{Verbatim}\nEigenvalues of open-loop system: \n[-0.08338525+0.29860789j -0.08338525-0.29860789j -0.08322949+0.j        ]\n\\end{Verbatim}\n\\subsection{}\nThe eigenvalues I chose were $2.5\\lambda(A)$. The choice was justified in the RMSE error to be computed and converge speed to be shown in part (d). Basically I chose \\{5, 1, 2, 3, 2.5\\} and did the validation. It turned out that $2.5\\lambda(A)$ was the best choice.\n\\lstinputlisting[language=Python]{4b.py}\n\\begin{Verbatim}\nL:\n[[-25.125]\n[  0.375]\n[ -0.675]]\n\\end{Verbatim}\n\\subsection{}\nWrite Equation~(\\ref{eq:luen1})(\\ref{eq:luen2}) in LTI form, and we obtain $A_{lobs}$, $B_{lobs}$, $C_{lobs}$:\n\\begin{equation}\n\\dot{\\hat x}(t)=\\underbrace{(A-LC)}_{A_{lobs}}\\hat x(t)+\\underbrace{\\left[\n\\begin{array}{cc}\nB&L\n\\end{array}\n\\right]}_{B_{lobs}}\\left[\n\\begin{array}{c}\nu(t)\\\\\ny(t)\n\\end{array}\n\\right]\n\\end{equation}\n\\begin{equation}\n\\hat y(t)=C_{lobs}\\hat x(t)\n\\end{equation}\n\\subsection{}\nThe eigenvalues I chose were $2.5\\lambda(A)$:\n\\begin{Verbatim}\narray([-0.20846314+0.74651974j, -0.20846314-0.74651974j, -0.20807373+0.j])\n\\end{Verbatim}\n\\lstinputlisting[language=Python]{4d.py}\n\\begin{Verbatim}\nLuenberger Observer RMSE: 0.0991557694635\n\\end{Verbatim}\nThe result of Luenberger observer is shown in Figure~\\ref{fig:4}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{4.png}      \n\t\\caption{Luenberger observer result}\n\t\\label{fig:4}\n\\end{figure}\n\\newpage\n\\section{Kalman Filter (KF) Design}\n\\subsection{}\n\\begin{equation}\n\\dot{\\hat x}(t)=A\\hat x(t)+Bu(t)+L(t)(y(t)-\\hat y(t))\n\\end{equation}\n\\begin{equation}\n\\hat y(t)=C\\hat x(t)\n\\end{equation}\n\\begin{equation}\nL(t)=\\Sigma(t)C^TN^{-1}\n\\end{equation}\nwhere $\\Sigma(t)$ is the solution of the following differential equation:\n\\begin{equation}\n\\dot\\Sigma(t)=\\Sigma(t)A^T+A\\Sigma(t)+W-\\Sigma(t)C^TN^{-1}C\\Sigma(t),\\ \\ \\ \\Sigma(0)=\\Sigma_0\n\\end{equation}\nwhere $W$ and $N$ are covariance matrices of $w(t)$ and $n(t)$.\n\\subsection{}\n\\lstinputlisting[language=Python]{5b.py}\n\\begin{Verbatim}\nKalman Filter RMSE: 0.0560275348234 rad/s\n\\end{Verbatim}\nThe value of $W$ I tuned is listed as follow. Basically I determined the magnitude first. Then based on the plots in part (c), I tuned the diagonal elements, and finally tuned other elements. It turned out that the RMSE did not change too much, but $\\Sigma_{33}$ changed dramatically. \n\\begin{Verbatim}\nW = np.matrix([[0.0006, 0.005, 0.001], \n\t       [0.02,   0.003, 0.004], \n\t       [0.004,  0.001, 0.003]])\n\\end{Verbatim}\n\\subsection{}\n\\lstinputlisting[language=Python]{5c.py}\nThe result of Kalman Filter is shown in Figure~\\ref{fig:5}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{5.png}      \n\t\\caption{Kalman filter result}\n\t\\label{fig:5}\n\\end{figure}\n\\subsection{}\n\\lstinputlisting[language=Python]{5d.py}\n\\begin{Verbatim}\narray([-0.08707987+0.2849352j, -0.08707987-0.2849352j, -0.34475403+0.j])\n\\end{Verbatim}\nThe 1st and 2nd poles are very close to the eigenvalues I chose in the Luenberger observer, but the 3rd one is a bit more different.\n\\section{Extended Kalman Filter (EKF) Design}\nReplace Hooke's law with nonlinear spring torque relationship, and the EKF can be obtained:\n\\begin{equation}\n\\underbrace{\\frac{\\partial}{\\partial t}\\left[\n\\begin{array}{c}\n\\theta\\\\\n\\dot\\theta_T\\\\\n\\dot\\theta_B\n\\end{array}\n\\right]}_{\\hat x(t)}=\\underbrace{\\left[\n\\begin{array}{c}\n\\hat\\theta_T - \\hat\\theta_B\\\\\n\\frac{-k_1\\theta-k_2\\theta^3-b\\dot\\theta_T+T(t)}{J_T}\\\\\n\\frac{k_1\\theta+k_2\\theta^3-b\\dot\\theta_B}{J_B}\n\\end{array}\t\n\\right]}_{f(x(t),u(t))}+w(t),\\ \\ \\ x(0)=x_0\n\\end{equation} \n\\begin{equation}\n\\dot\\theta_T=\\underbrace{C\\left[\n\\begin{array}{c}\n\\theta\\\\\n\\dot\\theta_T\\\\\n\\dot\\theta_B\n\\end{array}\n\\right]}_{h(x(t),u(t))}+n(t)\n\\end{equation}\nHence, $F(t)$ and $H(t)$ can be derived:\n\\begin{equation}\nF(t)=\\frac{\\partial f}{\\partial x}(\\hat x(t),u(t))=\\left[\n\\begin{array}{ccc}\n0&1&-1\\\\\n\\frac{-k_1-3k_2\\hat\\theta^2}{J_T}&\\frac{-b}{J_T}&0\\\\\n\\frac{k_1+3k_2\\hat\\theta^2}{J_B}&0&\\frac{-b}{J_B}\n\\end{array}\n\\right]\n\\end{equation}\n\\begin{equation}\nH(t)=\\frac{\\partial h}{\\partial x}(\\hat x(t),u(t))=C=\\left[\n\\begin{array}{ccc}\n0&1&0\n\\end{array}\\right]\n\\end{equation}\n\\lstinputlisting[language=Python]{6.py}\n\\begin{Verbatim}\nExtended Kalman Filter RMSE: 0.0458628285791 rad/s\n\\end{Verbatim}\nThe result of EKF is shown in Figure~\\ref{fig:6}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{6.png}      \n\t\\caption{EKF result}\n\t\\label{fig:6}\n\\end{figure}\n\\end{document}", "meta": {"hexsha": "c51fa3bd60d000254219f7a322fd5d06931f54f2", "size": 9674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2 - State Estimation/ZHAO_FRANKLIN_HW2.tex", "max_stars_repo_name": "QinganZhao/Energy-Systems-and-Control", "max_stars_repo_head_hexsha": "ef55c598c2475f4fb3aa9cc9cdae89457e7bae16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-08T02:54:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-08T02:54:02.000Z", "max_issues_repo_path": "HW2 - State Estimation/ZHAO_FRANKLIN_HW2.tex", "max_issues_repo_name": "QinganZhao/Energy-Systems-and-Control", "max_issues_repo_head_hexsha": "ef55c598c2475f4fb3aa9cc9cdae89457e7bae16", "max_issues_repo_licenses": ["MIT"], "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 - State Estimation/ZHAO_FRANKLIN_HW2.tex", "max_forks_repo_name": "QinganZhao/Energy-Systems-and-Control", "max_forks_repo_head_hexsha": "ef55c598c2475f4fb3aa9cc9cdae89457e7bae16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-07T11:59:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T11:59:05.000Z", "avg_line_length": 27.64, "max_line_length": 285, "alphanum_fraction": 0.6903039074, "num_tokens": 3574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6132101632739733}}
{"text": "\\subsection{A Gluing Construction}\r\nIn previous parts, we saw that we can make $\\log$ is a complete analytic function.\r\nBut we are not entirely satisfied, as it is just a bunch of function elements related together, instead of a genuin function.\r\nWe shall construct a space as a ``bigger domain'' $R$ at which we can realise $\\log$ as a geniune function.\\\\\r\nThe idea is to consider the function elements we defined earlier and glue them together.\r\nWe define\r\n$$R=\\left( \\coprod_{n\\in\\mathbb Z}U_{I(n)} \\middle)\\right/\\sim$$\r\nwhere $z_1\\in U_{I(m)}$ and $z_2\\in U_{I(n)}$ have $z_1\\sim z_2$ iff $z_1=z_2$ as elements of $\\mathbb C$ and $f_{I(m)}(z_1)=f_{I(n)}(z_2)$.\r\nWe give $R$ the quotient topology.\r\nOne can imagine $R$ as an ``infinite multi-storey carpark'' that spirals up and down.\r\n\\begin{remark}\r\n    Since $F_{I(m)}\\approx F_{I(n)}$ for all $m,n\\in\\mathbb Z$, it follows that $R$ is path-connected by following the sequence of direct analytic continuations.\r\n\\end{remark}\r\nThen, with this construction, we can extend all the $f_{I(n)}$ on the $U_{I(n)}$ to a global function $f:R\\to\\mathbb C$ by $f([z])=f_{I(n)}(z)$ for $z\\in U_{I(n)}$.\r\n\\begin{proposition}\r\n    $f$ is well-defined.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Follows directly from our definition of the equivalence relation $\\sim$.\r\n\\end{proof}\r\nSimilarly, the natural inclusions $U_{I(n)}\\hookrightarrow\\mathbb C_\\star$ can be extended to a global function $\\pi:R\\to\\mathbb C_\\star$ with $\\pi([z])=z$.\r\nOne can also easily verify that $\\pi$ is well-defined.\r\nThere is a very nice relationship between $f,\\pi$ and the usual exponential map.\r\nIndeed, $\\exp\\circ f=\\pi$, which basically tells us $f$ has basically everything we want from $\\log$.\\\\\r\nWe can use these global functions together.\r\nDefine $\\Phi([z])=(\\pi([z]),f([z]))$, then $\\Phi$ is injective by definition of $\\sim$.\r\nTherefore $R$ is Hausdorff as $\\mathbb C^2$ is.\r\n\\begin{remark}\r\n    $\\Phi$ indeed identifies $R$ with the graph $\\{(w,z)\\in\\mathbb C^2:w=\\exp(z)\\}$.\r\n    So we can view $R$ alteratively as ``flipping'' the graph of $\\exp$.\r\n\\end{remark}", "meta": {"hexsha": "0a83a01ebeade11e3531d13ce0d68d731c143d9c", "size": 2093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/glue.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/glue.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/glue.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.5161290323, "max_line_length": 165, "alphanum_fraction": 0.6927854754, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.613210152830756}}
{"text": "\\section{Empirical relevance}\n\\begin{frame}{Empirical relevance: definition}\n    The \\alert{empirical relevance} $r_i(t)$ of node $i$ at time $t$ is defined as:\n\n    \\[\n        r_i(t) = \\frac{n_i(t)}{n_i^{PA}(t)}\n    \\]\n\n    \\begin{itemize}\n        \\item $n_i(t) = \\frac{\\Delta k_i^{in}(t, \\Delta t)}{L(t, \\Delta t)}$: ratio between:\n\n        \\begin{itemize}\n            \\begin{footnotesize}\n            \\item $\\Delta k_i^{in}(t, \\Delta t)$: \\# of incoming links received by node $i$ in the time window $[t, t+\\Delta t]$\n            \\item $L(t, \\Delta t)$: total \\# of links created within the same time window\n        \\end{footnotesize}\n        \\end{itemize}\n\n        \\item $n_i^{PA}(t) = \\frac{k_i^{in}(t)}{\\sum_j k_j^{in}(t)}$: expected value of $n_i(t)$ according to preferential attachment alone\n    \\end{itemize}\n\n    $r_i(t) > 1$ \\alert{$(< 1)$}: node $i$ at time $t$ outperforms \\alert{(underperforms)} in the competition for incoming links with respect to its preferencial attachment weight.\n\\end{frame}\n\n\\section{The Extended Fitness Model}\n\n\\begin{frame}{The Extended Fitness Model}\n    \\begin{itemize}\n        \\item \\textbf{PageRank's under-performance in time-dependent networks is a general feature.}\n        \\item We can validate this using a model more compatible with the idea that \\emph{a node is important if it's pointed by other important nodes.}\n    \\end{itemize}\n    \\begin{center}\n        \\alert{Extended Fitness Model} (EFM)\n    \\end{center}\n    \\begin{itemize}\n        \\item \\textbf{High-fitness nodes are more sensitive to fitness} than low-fitness nodes, when choosing their outgoing links.\n        \\item High-fitness nodes are then more likely to be pointed by other high-fitness nodes than low-fitness nodes.\n        \\item EFM is \\alert{more favorable} to PageRank than RM.\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{EFM:\\@ sensitivity to fitness}\n    Probability $\\Pi_{i;j}^{in}(t)$ that a link created by node $j$ at time $t$ ends in node $i$:\n    \\[\n        \\Pi_{i;j}^{in}(t) \\sim (k_i^{in}(t)+1)^{1-\\eta_j} \\, \\eta_i^{\\eta_j} \\, f_R(t-\\tau_i)\n    \\]\n    \\begin{itemize}\n        \\item Fitness $\\eta \\in [0, 1]$ to prevent negative exponents\n        \\item $\\Pi^{in}$ depends on the fitness of the target \\emph{and of the source} nodes (difference with RM).\n        \\item $k_i^{in}(t)$: indegree of node $i$ at time $t$.\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{PageRank vs.\\ indegree: correlation with fitness in EFM}\n    \\begin{figure}\n        \\begin{columns}\n\n        \\column{0.6\\textwidth}\n            \\includegraphics[width=1.0\\textwidth]{figures/PageRankEFM_heatmap}\n\n        \\column{0.4\\textwidth}\n            \\begin{footnotesize}\n            \\begin{itemize}\n                \\item $\\rho(A) = 2A^{-3}, \\; A \\in [1, \\infty]$\n                \\item $H$ nodes: high fitness; $\\eta \\in [10^{-5}, 1]$\n                \\item $(N-H)$ nodes: low fitness; $\\eta \\in [0, 10^{-5}]$\n                \\item $N=10000$, $H=250$\n            \\end{itemize}\n            \\end{footnotesize}\n        \\end{columns}\n        \\caption{Comparison of performance of PageRank and indegree (EFM data).}\n    \\end{figure}\n\\end{frame}\n", "meta": {"hexsha": "41de768fa81b0a2b0dc2628659856282db7a6b66", "size": 3142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/appendix.tex", "max_stars_repo_name": "pietrodn/csr_pagerank", "max_stars_repo_head_hexsha": "5c037e0e085b697c9c79950c9c4fe5cbcc494c6d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-09T14:36:59.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-09T14:36:59.000Z", "max_issues_repo_path": "sections/appendix.tex", "max_issues_repo_name": "pietrodn/csr_pagerank", "max_issues_repo_head_hexsha": "5c037e0e085b697c9c79950c9c4fe5cbcc494c6d", "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/appendix.tex", "max_forks_repo_name": "pietrodn/csr_pagerank", "max_forks_repo_head_hexsha": "5c037e0e085b697c9c79950c9c4fe5cbcc494c6d", "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.4594594595, "max_line_length": 180, "alphanum_fraction": 0.6107574793, "num_tokens": 953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.7057850278370111, "lm_q1q2_score": 0.6132049256584442}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{Append}\n\nThe operation $append$ will return a Collection with a Value added at a specified numeric Index.\n\\begin{schema}{Append[Collection, V, \\nat]}\n  coll?, coll! : Collection \\\\\n  v? : V \\\\\n  idx? : \\nat \\\\\n  append~\\_ : Collection \\cross V \\cross \\nat \\bij Collection\n  \\where\n  \\#~idx? = 1 \\\\\n  coll! = append(coll?, v?, idx?) @ \\\\\n  \\t1 let ~ ~ coll' == front(\\{~ i : \\nat ~| ~ i \\in 0~..~idx?\\} \\extract coll?) \\cat v? \\\\\n  \\t1 \\ \\ \\ ~~~ coll'' == \\{~ j : \\nat ~| ~ j \\in idx?~..~\\#~coll?\\} \\extract coll? \\\\\n  \\t1 = coll' \\cat coll'' \\implies \\\\\n  \\t2 (front(coll')  \\cat v? \\cat  coll'') ~ \\land \\\\\n  \\t2 (~ v? \\mapsto idx? \\in coll!) ~\\land \\\\\n  \\t2 (~\\#~ coll! = \\#~ coll? + 1)\n\\end{schema}\n$append$ results in the composition of $coll'$ and $coll''$ such that\n$$coll! = coll' \\cat coll'' ~ \\land ~idx? \\mapsto v? \\in coll!$$\n\\begin{itemize}\n\\item $coll'$ is the items in $coll?$ up to and including $idx?$ but the value at $idx?$ is replaced with $v?$ such that\n  $idx? \\mapsto coll?_{idx?} \\not \\in coll'$\n\\item $coll''$ is the items in $coll?$ from $idx?$ to $\\#~coll? \\implies coll?_{idx?} \\in coll''$\n\\end{itemize}\n The following example illustrates these properties.\n\\begin{argue}\n  X = \\langle x_{0}, x_{1}, x_{2} \\rangle \\\\\n  \\t1 x_{0} = 0 \\\\\n  \\t1 x_{1} = foo \\\\\n  \\t1 x_{2} = \\langle a, b, c \\rangle \\\\\n  \\t1 v? = bar \\\\\n  append(X, v?, 0) = \\langle bar, 0, foo, \\langle a, b, c \\rangle \\rangle \\\\\n  append(X, v?, 1) = \\langle 0, bar, foo, \\langle a, b, c \\rangle \\rangle \\\\\n  append(X, v?, 2) = \\langle 0, foo, bar, \\langle a, b, c \\rangle \\rangle \\\\\n  append(X, v?, 3) = \\langle 0, foo, \\langle a, b, c \\rangle, bar \\rangle \\\\\n  append(X, v?, 4) = append(X, v?, 3) \\iff 3 \\not \\in \\dom X\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "985033ec70e75a5804188b0ce9bd6ee2b64f642c", "size": 1811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/collections/append.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/collections/append.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/collections/append.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 43.119047619, "max_line_length": 120, "alphanum_fraction": 0.5726118167, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7057850216484837, "lm_q1q2_score": 0.6132049250760493}}
{"text": "\\section{Defining data for Oriented TQFT}\nThis is the defining data for $(d + 1)$-dimensional oriented TQFT.\nIt Closed $d$-dimensional $\\Sigma^d$\nhas vector space $V(\\Sigma^d)$.\nWhen $M^{d+1}$ is closed, meaning it has no boundary,\n$Z(M^{d+1})\\in\\mathbb{C}$ is just a number.\nIf $M^{d+1}$ has a boundary,\nthen $Z(M^{d+1})\\in V(\\partial M^{d+1})$.\nThis is a state.\n$Z$ is the path integral on the spacetime manifold.\nYou can think of it as a wave function over boundary conditions.\n\nThese are the axioms.\nAll manifolds have orientation.\n\n\\begin{enumerate}\n    \\item $Z$ and $V$ are functorial with respect to orientation-preserving\n    diffeomorphisms of $M^{d+1}$ and $\\Sigma^d$.\n    \\item $V$ should be ``involutory'' in the sense that\n    $V(\\bar{\\Sigma^d}) = V(\\Sigma^d)^*$.\n    Here the $*$ means dual vector space.\n    Over bar means hermitian conjugate.\n    \\item $Z$ and $V$ should be multiplicative.\n    \\item Non-triviality.\n    \\item $Z$ is hermitian.\n\\end{enumerate}\n\nLet's explain the axioms.\n\\begin{axiom}[Axiom 1]\n    Let $f:\\Sigma_1^d \\to \\Sigma_2^d$ be a diffeomorphism.\n    This defines an isomorphism\n    $\\mathcal{U}_f: V(\\Sigma_1^d)\\to V(\\Sigma_2^d)$.\n    If we also have $g: \\Sigma_2^d \\to \\Sigma_3^d$,\n    then\n    $\\mathcal{U}_g \\mathcal{U}_f = \\mathcal{U}_{gf}$.\n\n    If $f$ extends to\n    $\\tilde{f}: M_1^{d+1}\\to M_2^{d+1}$\n    where $\\partial M_1 = \\Sigma_1$\n    and $\\partial M_2 = \\Sigma_2$,\n    then\n    $\\mathcal{U}_f\\left( Z\\left( M_1^{d+1} \\right) \\right)\n    = Z\\left( M_2^{d=1} \\right)$.\n\\end{axiom}\nSuppose we have a diffeomorphism from one circle $\\Sigma_1 = S^1$ to another\ncircle.\nThen there will be an induced map $\\mathcal{U}_f$ from vector spaces between\nthen too.\n\n\\begin{question}\n    Isn't $Z$ a path integral that is a number?\n    Why is it a vector space?\n\\end{question}\nYou can think of $Z\\left( M_1^{d+1} \\right)$\nas a state,\nbecause like in path integrals you have boundary conditions,\nwhich are variable.\n\n\n\\begin{question}\n    What is a diffeomorphism?\n\\end{question}\nA diffeomorphism $f:X_1 \\to X_2$ is a smooth and continuous map.\n\n\\begin{question}\n    What is a manifold?\n\\end{question}\nManifolds can be broken up into charts $\\mathcal{U}_\\alpha$\nwith coordinate charts $\\phi: \\mathcal{U}_\\alpha\\to \\mathbb{R}^d$.\n\n\\begin{question}\nWhat is the relation between $\\mathcal{U}_{f}$ and\n$\\mathcal{U}_{\\tilde{f}}$?\n\\end{question}\nThey are actually the same.\n\n\\begin{question}\n    The extension from $f$ to $\\tilde{f}$ is not unique?\n\\end{question}\nIt's not unique.\n\n\\begin{question}\n    $\\mathcal{U}_f$ acting on the partition function\n    gives the other partition function.\n    This is the sum of all paths.\n\\end{question}\nDon't think of it like that.\nThis thing is only acting on the partition function.\nNow you're saying $Z$ is the sum of something\nand how does $U_{f}$ act on terms in the sum.\nI'm hesitant to say anything general about that.\nThere's no general clean answer.\nJust think of it as an abstract object $Z$\nwhich gives a state if there is a boundary\nand a number otherwise.\n\nLet's talk about axiom 3.\nImagine if I build a manifold by gluing simpler manifolds.\nThen I can build my vector spaces by some tensor products and multiplications.\nRecall that $\\sqcup$ is the disjoint union.\nThen we can state the axiom.\n\\begin{axiom}[Axiom 3]\n    Let\n    \\begin{align}\n        V\\left( \\Sigma_1^d \\sqcup \\Sigma_2^d  \\right)\n        =\n        V\\left( \\Sigma_1^d \\right) \\otimes\n        V\\left( \\Sigma_2^d \\right)\n    \\end{align}\n    Suppose the boundary is\n    \\begin{align}\n        \\partial M^{d+1} =\n        \\Sigma_1 \\sqcup \\bar{\\Sigma}_2\n    \\end{align}.\n    Then\n    \\begin{align}\n        Z\\left( M_1^{d=1} \\right) &\\in\n        V\\left( \\Sigma_1 \\right) \\otimes V\\left( \\bar{\\Sigma}_2 \\right)\\\\\n        &\\simeq V\\left( \\Sigma_1 \\right) \\otimes \\overbar{V(\\Sigma_2)}\n    \\end{align}\n    so we can think of $Z\\left( M^{d+1}_1 \\right)$\n    as a state in\n    $V\\left( \\Sigma_1 \\right)\\otimes V\\left( \\overbar{\\Sigma_2} \\right)$\n    or as a linear map from\n    $V\\left( \\Sigma_2 \\right)\\to V\\left( \\Sigma_1 \\right)$.\n\\end{axiom}\nI can think of this as a state in a tensor product of two spaces.\n\\begin{align}\n    Z\\left( M_1^{d+1} \\right)\n    = \\sum_{n,m} c_{n,m}\n    \\ket{n}_{V(\\Sigma_1)}\n    \\otimes \\ket{m}_{V(\\overbar{\\Sigma_2})}\n\\end{align}\nor you can think of it as\n\\begin{align}\n    Z\\left( M_1^{d+1} \\right)\n    = \\sum_{n,m} c_{n,m}\n    \\ket{n}_{V(\\Sigma_1)}\n    \\bra{m}_{V(\\overbar{\\Sigma_2})}\n\\end{align}\n\n\\begin{question}\nThis only applies when the boundary is a disjoint union of two manifolds?\n\\end{question}\nYou can always think of the boundary as $\\partial M^{d+1}=\\Sigma_1 \\sqcup\n\\emptyset$\n\n\\begin{question}\n    Why do we need the complex conjugate?\n\\end{question}\nIt's a state on $V(\\Sigma_1)\\otimes V(\\ovebar{\\Sigma_2})$.\nActually maybe it shouldn't be there,\nput a question mark there.\nActually, there should be no complex conjugate.\n\nWe can think of the path integral as a state on the vector space\n$V(\\Sigma_1)\\otimes\\overbar{V(\\Sigma_2)}$\nor as a map from\n$V(\\Sigma_2)\\to V(\\Sigma_1)$.\n\nI can think of a state as a map from the vector space to the empty manifold.\nI'm just moving pieces around no each side.\n\nIt's really nothing more than thinking of it as bras and kets.\nJust think of this as a definition.\nI have a state that lives on a tensor product of two vector spaces.\nI can think of it as an operator from one vector space to another.\nIt's really just that simple.\nThere's nothing more to that.\nForget that we called it the path integral.\nYou can think of any tensor product state as an operator from one space to\nanother.\n\n\\begin{question}\n    When you have 3 disjoint components of $\\Sigma$,\n    then how do you define orientation?\n    How do you decided which orientation to use?\n\\end{question}\nI don't think you need extra information about what the boundary orientation\nlooks like.\nIf this has + orientation, then are you saying that?\n\nActually I think there should be a star.\n\\begin{align}\n    Z\\left( M_1^{d+1} \\right)\n    = \\sum_{n,m} c_{n,m}^*\n    \\ket{n}_{V(\\Sigma_1)}\n    \\bra{m}_{V(\\overbar{\\Sigma_2})}\n\\end{align}\nWe'll come back to this.\n\nThe path integral is a state on the boundary.\n\nWe've done the multiplicative axiom for $V$.\nWe haven't gotten to the multiplicative axiom for $Z$ yet.\nWe want to glue together $M$s with common boundaries.\n\nSuppose that we have some manifold $M_1$\nand another manifold $M_2$.\nThe boundary $\\partial M_1 = \\Sigma_1 \\sqcup \\overbar{\\Sigma_2}$\nand the boundary\n$\\partial M_2 = \\Sigma_2 \\sqcup \\overbar{\\Sigma_3}$.\nThen $M=M_1 \\cup_{\\Sigma_2} M_2$.\nIf you think of these $Z$ as linear maps,\nthen we just compose the maps.\n\\begin{align}\n    Z(M) = Z(M_2)\\circ Z(M_1): V(\\Sigma_1) \\to V(\\Sigma_3)\n\\end{align}\nor equivalently,\nwe can think of $Z(M)$ as the inner product of these two states,\nwhere the inner product\n\\begin{align}\n    Z(M) =\n    {\\langle Z(M_1), Z(M_1) \\rangle}_{V(\\Sigma_2)}\n    \\in V(\\Sigma_1) \\otimes V(\\overbar{\\Sigma_3})\n\\end{align}\n\n\\begin{question}\n    The bar just means going counterclockwise right?\n\\end{question}\nYes.\n\n\nActually there are many ways of glueing manifolds.\nWhen I identify points together,\nI can actually identify with any points I want.\nSo in general we need a gluing map\n$\\phi: \\Sigma_2 \\to \\Sigma_2$\nwith\n$M = M_1 \\cup_\\phi M_2$.\n\nI'm going to use Axiom 1\nand this $\\phi$ map is going to define a corresponding map\n$\\mathcal{U}_\\phi: V(\\Sigma_2)\\to V(\\Sigma_2)$\nso\n\\begin{align}\n    Z\\left( M_1 \\cup_\\phi M_2 \\right)\n    =\n    Z(M_2) \\circ \\mathcal{U}_\\phi \\circ Z(M_1).\n\\end{align}\nOr equivalently\n$\\langle Z(M_2), \\mathcal{U}_\\phi Z(M_1)\\rangle_{V(\\Sigma_2)}$.\n$\\mathcal{U}_\\phi$ is an isomorphism between these two vector spaces.\n\nClosed $M^{d=1}$\ncan be obtained by gluing together\n$M_1$, $M_2$ along the their common boundary.\nFor example,\nif you wanted to calculate the path integral on a sphere,\nyou blue toegether the two on a common boundary.\n\nIf you want a torus,\nou glue\n\\begin{align}\n    T^2 = (S_1\\otimes I) \\union (S^1\\times I).\n\\end{align}\n\nThat was the only non-trivial axiom,\nthe rest are pretty simple.\n\nFunnily enough,.\nThis is about what happens when we have a non-empty manifold.\nthe next axiom is called non-triviality\n\n\\begin{axiom}[Axiom 4: non-triviality]\n    Consider a boundary $\\Sigma^d = \\emptyset$.\n    Then\n    V(\\emptyset) = V(\\emptyset) \\otimes V(\\emptyset)\n    and\n    \\begin{align}\n        V(\\emptyset) =\n        \\begin{cases}\n            0 & \\text{ordinal}\\\\\n            \\mathbb{C} & 1-dimensional\n        \\end{cases}\n        hence we have\n        \\begin{align}\n            V(\\phi) = \\mathbb{C}\n        \\end{align}\n    \\end{align}\n    If $M^{d+1}$ is closed,\n    $\\partial M^{d+1} = \\emptyset$,\n    then\n    $Z(M^{d+1}) \\in V(\\emptyset) \\simeq \\mathbb{C}$.\n    Consider the case\n    \\begin{align}\n        M^{d+1} = \\emptyset.\n    \\end{align}\n    Then\n    \\begin{align}\n        Z(\\emptyset) = Z\\emptyset) Z(\\emptyset)\n    \\end{align}\n    which implies\n    \\begin{align}\n        Z(\\emptyset) =\n        \\begin{cases}\n            0 &\\\\\n            1\n        \\end{cases}.\n    \\end{align}\n    Take $Z(\\emptyset)=1$.\n\\end{axiom}\n\nconsider $M^{d+1}= \\sigma^d \\times I$.\nThen\n\\begin{align}\n    Z\\left( \\Sigma^d \\times I \\right)\n    =\n    \\begin{cases}\n        0\\\\\n        II_{V(\\Sigma^d)}\n    \\end{cases}\n\\end{align}\nTake\n$Z(\\Sigma^d\\times I) = II_{V(\\Sigma^d)}\n= \\sum_{n=1}^{\\dim(V(\\Sigma^d))}\n\\ket{n}\\bra{n}$\nwhere $\\{\\ket{n}\\}$ is orthonormal basis in $V(\\Sigma^d)$.\nOr,\n\\begin{align}\n    Z(\\Sigma^d\\times I) =\n    \\sum_n\n    \\ket{n}_{V(\\Sigma^d)}\n    \\otimes\n    \\ket{n}_{V(\\Sigma)}^d.\n\\end{align}\n\nThe last axiom is simple.\n\\begin{axiom}[Hermitian]\n    $Z(\\overbar{M^{d+1}}) = Z(M^{d+1})^\\dagger$.\n\\end{axiom}\n\n\\section{Non-trivial consequences}\n\\subsection{Homotopy invariance of maps}\nThis has some non-trivial consequences.\nConsider $M_1^{d+1}=\\Sigma^d\\times I$\nand consider $M_2^{d+1}=\\Sigma^2\\times I$\nwith homotopy\n$F: M_1\\to M_2$.\nThen\n$\\mathcal{F}(\\Sigma^d, t)\n= f_t(\\Sigma^d)$\nfor $f_t: \\Sigma_d\\to \\Sigma^d$.\nThis defines a continuous family\n$\\mathcal{U}_{f_t}: \\Sigma^d\\to \\Sigma^d$ satisfying\n$\\mathcal{U}_{f_t} = \\mathcal{U}_{f_{t'}}$.\n\n[diagram here]\n\nIf I have a homotopy group with a homotopy of maps.\n\n\\subsection{Mapping Class Group}\nThat leads us to the important group for a manifold.\nFor every manifold, there is a mapping class group $\\Sigma^d$.\nColloquially, it's the group of ``large'' diffeomorphisms.\nYou would take all diffeomorphisms and mod out all those that are continuously\n\\begin{align}\n    \\mathrm{MCG}(\\Sigma^d) = \\frac{\\mathrm{Diff}(\\Sigma^d)}{\\mathrm{diff}_0(\\Sigma^d)}\n\\end{align}\nTwo diffeomorphisms are equivalent if they can be connected to each other.\n\nThis is the group taking all possible diffeomorphisms\nand modding out all the ones equivalent to the identity.\n\nThe mapping class group is related to the homotopy group,\nbut not the same thing.\nYou may not understand this,\nbut\n\\begin{align}\n    \\mathrm{MCG}(\\Sigma^d)\n    = \\mathrm{out}(\\pi_1(\\Sigma^d))\n\\end{align}\nIt's isomorphic to the group of all outer maps between loops.\nAn example of such a map that maps a non-trivial loop on an torus\nto the other type of non-trivial loop around the torus.\n\nIn TQFT,\nall my maps are smooth.\nIf my maps aren't smooth,\nI don't have something that takes me everywhere from the left to everywhere on\nthe right.\nIf I have a smooth map,\nthat's what allows me to take vector spaces on the left to vector space on the\nright.\nThe only reason I can go from left to right is because $\\mathcal{F}$ is a\ndiffeomorphism.\n\nThe punchline is this.\nFor each $g\\in \\mathrm{MCG}(\\Sigma^d)$,\nwe get some $\\mathcal{U}_g: V(\\Sigma^d) \\to V(\\Sigma^d)$.\nIf you figure out the $\\mathcal{U}_g$,\nyou can completely figure out the TQFT.\nThese $\\mathcal{U}_g$ are very important,\nand can basically characterise the TQFT.\n\nIs this the $S$ and $T$ matrices?\nYes.\nFor every element in the MCG  of a torus,\nthere is a linear map that acts on the ground state subspace on the system,\nhence the $S$ and $T$ matrices on the subspace.\nDon't worry if you've never heard of it.\n\nDo you have a concise reference to recommend for the last two lectures?\nThere's an article from Atiyah 1988.\nIt's basically called TQFT.\nMy whole representation is based on this article.\n\n\\begin{question}\n    Is it readable?\n\\end{question}\nIt's as readable as my lectures are understandable.\nIf you don't understand my lecture,\nthen I'm not sure.\nIt's not too bad,\nit doesn't assume you know that much.\n\nWe're basically done,\nbut there's one more consequence to talk about.\nThese TQFTs are very baby versions of TQFTs,\nand in real applications, we need some extra structure.\n", "meta": {"hexsha": "78168a09fc0dd8cc34081ddc96c456b7a5a33e9d", "size": 12659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys733/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": "phys733/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": "phys733/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": 30.0688836105, "max_line_length": 86, "alphanum_fraction": 0.6817284146, "num_tokens": 4085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6131985388201672}}
{"text": "\n\\chapter{\\projmr3 \\ Multi-Channel Data Set}\n\\index{multi-channel}\n\\section{Introduction}\n\nModern image processing applications often involve multispectral data.\nThis can be color images in R, G and B coordinates, observations of the same \narea but at different times, etc. Much effort in the compression application\ndomain\nhas been expended in recent years in order to compress efficiently such\ndata sets. The challenge is to have a data representation which takes\ninto account at the same time both the spatial and the spectral \n(or temporal) correlation. A three-dimensional transform-based coding\ntechnique has been proposed in \\cite{mc:saghri95}, consisting of\na one-dimensional spectral Karhunen-Lo\\`eve transform \n\\cite{ima:karhunen47} (KLT)\nand a two-dimensional spatial discrete cosine transform (DCT).\nThe KLT is used to decorrelate the spectral domain and the \nDCT is used to decorrelate the spatial domain.\nAll images are first decomposed into blocks, and each block uses its own\nKarhunen-Lo\\`eve transform instead of one single transform \nfor the whole image.\nLee \\cite{mc:lee99} has improved on this approach by introducing a varying\nblock size. The block size is defined using a quadtree, followed by \nbit allocation\nfor each block. The DCT transform can also be replaced by a wavelet \ntransform \\cite{mc:epstein92,mc:tretter95} (WT). \n\nWe present in this chapter how a Wavelet-KLT transform can be used for\nnoise removal. Decorrelating first the data in the spatial domain using \nthe WT and following that in the \nspectral domain, by the KLT, has the advantage of\nproviding us with robust noise modeling in the WT-KLT space, and hence to\nbe able \nto filter the transformed data in an efficient and effective \nway. We show also that\nthe correlation matrix can be computed by different methods based on  \nthe noise modeling. These methods are evaluated with a set of different \nimages. \n \nWe first present the Wavelet-KLT transform and how to model the \nnoise in this space. We then describe three different methods to \nfilter the coefficients, and finally illustrate these approaches with\n a set of experiments.\n\n% We are interested in having an entropy measurement \n% of such data sets, knowing that the correlation between two images \n% can be relatively high. A 3-dimensional wavelet transform is not \n% appropriate because the third dimension is generally completely different\n% from the two first. The standard case is the data set where we have \n% 2-dimensional spatial information versus a frequency band.\n \n\n\\section{The Wavelet-Karhunen-Lo\\`eve transform}\n\\subsection{Definition}\nThe Karhunen-Lo\\`eve transform, also often referred to as eigenvector,\nHotelling transform, or Principal Component Analysis (PCA)\n \\cite {ima:karhunen47,ima:loeve48,ima:hotelling33}\nallows us to transform  discrete signals into a sequence of uncorrelated \ncoefficients.\nConsidering a vector $D={d_1,..., d_L}$   \nof $L$ signals or images  of dimension N \n(i.e., $N$ pixels per image), \nwe denote $M = \\left\\{m_1, ..., m_L\\right\\}$ the \nmean vector of the population ($m_i$ is the mean of the ith\nsignal $d_i$). The covariance matrix $C$ of $D$ is defined by \n$C = (D-M)(D-M)^t$, and is of order $L \\times L$. \nEach element $c_{i,i}$ of $C$ is\nthe variance of $d_i$, and each element $c_{i,j}$ is the \ncovariance between $d_i$ and\n$d_j$. The KLT method consists of \napplying the following transform to all\nvectors $x_i = \\left\\{d_1(i),...,d_L(i)\\right\\}$ ($i=1..N$):\n\\begin{eqnarray}\ny_i = \\Lambda^{-\\frac{1}{2}}A(x_i-M)\n\\label{eqn_trans}\n\\end{eqnarray}\nwhere $\\Lambda$ is the diagonal matrix of eigenvalues of the covariance \nmatrix $C$, and $A$ is a matrix whose rows are formed \nfrom the eigenvectors\nof $C$ \\cite{ima:gonzalez93}, ordered following  \ndecreasing order of eigenvalues. \n\nBecause the rows of $A$ are orthonormal vectors, $A^{-1} = A^t$, and\nany vector $x_i$ can be recovered from its corresponding $y_i$ by:\n\\begin{eqnarray}\nx_i = \\Lambda^{\\frac{1}{2}}A^t y_i + M\n\\end{eqnarray}\n\nThe $\\Lambda$ matrix multiplication can be seen as a normalization.\nBuilding $A$ from the correlation matrix instead of the covariance matrix\nleads to another kind of normalization, \nand the $\\Lambda$ matrix can be suppressed \n($y_i = A(x_i-M)$ and $x_i = A^t y_i + M$). Then the norm of $y$ will \nbe equal to the norm of $x$.  \n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{ \n\\psfig{figure=fig_wtpca.ps,bbllx=1cm,bblly=11cm,bburx=19cm,bbury=27cm,width=12cm,height=10cm,clip=}\n}\n}}\n\\caption{WT-KLT transform flowchart. Each frame of the input data set is first wavelet\ntransformed, and a principal component analysis is applied at each resolution\nlevel.}\n\\label{fig_wtpca}\n\\end{figure}\n\nWe suppose now that we have $L$ observations of the same view, e.g.\\\nat different wavelengths (or at different epochs, etc.), and denote \nas $d_l$ one \nobservation, $W^{(l)}$ its wavelet transform, and $w_{l,j,k}$ one wavelet\ncoefficient at scale $j$ and at position $k$. \nThe standard approach would be to use an orthogonal wavelet transform, and\nto calculate the correlation matrix $C$ from the wavelet coefficients instead\nof the pixel values:\n\\begin{eqnarray}\nC_{m,n} =  \n \\frac{\\sum_{j=1}^{J} \\sum_{k=1}^{N_j} w_{m,j,k} w_{n,j,k}}\n                      {\\sqrt{\\sum_{j=1}^{J} \\sum_{k=1}^{N_j} w^2_{m,j,k}} \\sqrt{\\sum_{j=1}^{J} \\sum_{k=1}^{N_j} w^2_{n,j,k}}}\n\\label{Correlation_matrix1}\n\\end{eqnarray}\nwhere $J$ is the number of bands, and $N_j$ is the number of coefficients\nin the band $j$.\nIn \\cite{mc:lee99}, a more complex approach has been\nproposed, which  is to decompose the images into $N_b$ blocks and \napply a KLT o each block separately.  \nWe investigate here different approaches for data restoration.\n\n\n\\subsection{Correlation matrix and noise modeling}\nWe introduce a noise model into our calculation of the correlation matrix.\nIndeed, if the input sequence $D$ contains noise, then the \nwavelet coefficient \nare noisy too. Eigenvalues at the high scales are computed with \nnoisy WT coefficients and \nwe may lose the true underlying  correlation that exists \nbetween the input images $d_l$.\nThe expression of the correlation matrix has to be modified in order \nto allow us to take into account the noise.\nWe add a weighting term to each wavelet coefficient  which \ndepends on the signal to noise ratio.\nThe correlation matrix is calculated by:\n\\begin{eqnarray}\nC_{m,n} =\n {\\frac{ \\sum_{j=1}^{J} \\sum_{k=1}^{N_j}  p_j(w_{m,j,k}) w_{m,j,k} p_j(w_{n,j,k}) w_{n,j,k}}\n                      {\\sqrt{  \\sum_{j=1}^{J} \\sum_{k=1}^{N_j}  p^2_j(w_{m,j,k}) w^2_{m,j,k}} \\sqrt{\\sum_{j=1}^{J} \\sum_{k=1}^{N_j} p^2_j(w_{n,j,k}) w^2_{n,j,k}}}}\n\\label{Correlation_matrix2}\n\\end{eqnarray}\nwhere $p_j$ is a weighting function. The standard approach corresponds to the \nspecific case where $p_j(w_m) = 1$ (no weighting). By considering that only\nwavelet coefficients with high signal to noise ratio should be used for \nthe correlation matrix calculation, $p_j$ can be defined by:\n\\begin{eqnarray}\np_j(w) = \\left\\{\n  \\begin{array}{ll}\n  \\mbox{ 1 } & \\mbox{ if }  w \\mbox{ is significant} \\\\\n  \\mbox{ 0 } & \\mbox{ if }  w \\mbox{ is not significant}\n  \\end{array}\n  \\right.\n\\end{eqnarray}\nand a wavelet coefficient $w$ is said to be ``significant'' \nif its probability of being \ndue to noise is smaller than a given $\\epsilon$ value. In the case of\nGaussian noise, it suffices to compare  the wavelet coefficients $w$ to\na threshold level $t_j$. $t_j$ is generally taken as $\\lambda \\sigma_j$, where\n$\\sigma_j$ is the noise standard deviation at scale $j$, and $\\lambda$ is \nchosen\nbetween 3 and 5. The value of $\\lambda=3$ corresponds to a probability of \nfalse\ndetection of $0.27$\\%, for Gaussian statistics.\n\nThis hard weighting scheme may lead to problems if only a few coefficient are \nsignificant, and can be replaced by a soft weighting one, by\ndefining $p_j(w)$ by:\n\\begin{eqnarray}\np_j(w) =  1 - \\mathrm{Prob}(W > \\mid w \\mid)   \n\\end{eqnarray}\nwhere $\\mathrm{Prob}(W > \\mid w \\mid)$ is the probability that a wavelet\ncoefficient is larger than $w$ due to the noise. For Gaussian noise, we have:\n\\begin{eqnarray}\n   p_j(w)  & =  & 1 - \\frac{2}{\\sqrt{2 \\pi} \n\\sigma_j} \\int_{\\mid w  \\mid}^{+\\infty} \\exp(-W^2/2\\sigma^2_j) dW \\nonumber \\\\ \n & = & \\mbox{erf}(\\frac{\\mid w  \\mid }{\\sqrt{2}\\sigma_j})\n\\end{eqnarray}\n\n\\subsection{Scale and Karhunen-Lo\\`eve transform}\n\nWe can also analyze separately each band of the \nwavelet transform, and then apply one KLT per resolution level. This \nimplies calculating a correlation matrix $C^{(j)}$ for each band $j$.\n\n\\begin{eqnarray}\nC^{(j)}_{m,n} =   \n {\\frac{\\sum_{k=1}^{N_j} p_j(w_{m,j,k}) w_{m,j,k} p_j(w_{n,j,k}) w_{n,j,k}}\n                      {\\sqrt{\\sum_{k=1}^{N_j}  p^2_j(w_{m,j,k}) w^2_{m,j,k}}  \\sqrt{\\sum_{k=1}^{N_j} p^2_j(w_{n,j,k}) w^2_{n,j,k}}}}\n\\label{Correlation_matrix3}\n\\end{eqnarray}\n\nThis has the advantage to take into account more complex behavior of the\nsignal. Indeed, structures of different sizes may have a different \nspectral behavior (for example, stars and galaxies in astronomical images),\nand a band-by-band independent analysis allows us to better represent\nthis kind of data.\n\n\n\\subsection{The WT-KLT transform}\nThe final WT-KLT algorithm has these steps:\n\\begin{enumerate}\n\\item Estimate the noise standard deviation $\\sigma^{(l)}$ of each input\ndata set $d_l$.\n\\item Calculate the wavelet transform $W^{(l)}$ of its each input\ndata set $d_l$.\n\\item For each band $j$ of the wavelet transform, calculate\nthe correlation matrix $C^{(j)}$ relative to the vector \n$x_j = \\left\\{ W^{(1)}_j, W^{(2)}_j, ..., W^{(L)}_j \\right\\}$, where \n$W^{(l)}_j$ represents the band $j$ of the wavelet transform $W^{(l)}$ of $d_l$.\n\\item For each band $j$, we diagonalize the matrix $C^{(j)}$ and build the\ntransform matrix $A_j$ from the eigenvectors of $C^{(j)}$.\n\\item For each band $j$ and each position $k$, we apply the matrix $A_j$\nto the vector\n$x_{j,k} = \\left\\{ w_{1,j,k}, w_{2,j,k}, ..., w_{L,j,k} \\right\\}$:\n\\begin{eqnarray}\n  y_{j,k} = A_j x_{j,k}\n\\end{eqnarray}\n\\item The WT-KLT coefficients $c_{l,j,k}$ are derived from $y_{j,k}$ by\n$c_{l,j,k} = y_{j,k}(l)$. The $l$ index in the transformed coefficients\nno longer represent the observation number, but instead the \neigenvector number.\n$l=1$ indicates the main eigenvector while $l=L$  indicates  the last one.\n\\end{enumerate}\nThe mean vector $M$ disappears in this algorithm because the wavelet \ncoefficients are zero mean.\n\nFigre~\\ref{fig_wtpca} shows the flowchart of the WT-KLT transform.\n\n\n\\subsection{The WT-KLT reconstruction algorithms}\n \nThe reconstruction algorithm has these steps:\n\\begin{enumerate}\n\\item For each band $j$ and each position $k$, we apply the matrix $A_j^t$\nto the vector \n$y_{j,k} = \\left\\{ c_{1,j,k}, c_{2,j,k}, ..., c_{L,j,k} \\right\\}$\n\\begin{eqnarray}\n  x_{j,k} = A_j^t y_{j,k}\n\\end{eqnarray}\n\\item The wavelet coefficients $w_{l,j,k}$ are derived from $x_{j,k}$ by\n $ w_{l,j,k} = x_{j,k}(l)$.\n\\item An inverse wavelet transform of $W^{(l)}$ furnishes $d_l$.   \n\\end{enumerate}\n\n\n\n\n\\subsection{WT-KLT Transform of 1D Multichannel Data: wk1d\\_trans}\n\\index{wk1d\\_trans}\n\\label{sect_mc1d_trans}\nThe program \n{\\em wk1d\\_trans} computes the WT-KLT  transform of \na multichannel 1D signal (2D data set). \nThe wavelet transform (\\`a trous algorithm)\nis applied on each individual 1D signal, and the KL transform is applied for\neach resolution level, exept the last (smooth) scale. \nSo we have a set of eigenvectors for \neach resolution level $j$ $\\{e_{j,1}, \\dots, e_{j,N}\\}$.\nThe output is a set \n$N$ multiresolution transform files in FITS format (suffix ``.fits''). \nEigenvectors\nare stored by increasing importance. The ith multiresolution file \n($i = 1 \\dots N$)\ncontains the eigenvectors $\\{e_{1,i}, \\dots, e_{J-1,i}\\}$, where $J$ is the \nmaximum resolution level (last smooth array).\n{\\bf\n\\begin{center}\n USAGE: wk1d\\_trans option data\\_in prefix\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n \\item {\\bf [-n number\\_of\\_scales]} \\\\\n Number of scales used in the multiresolution transform.\n Default is 4.\n\\item {\\bf [-C]} \\\\\nWrite the correlation matrix to disk. \nThe file name is ``Correl\\_Matrix''. Default is not to do this.\n\\item {\\bf [-x CorrelMat\\_Method]}\n{\\small\n\\begin{itemize}             \n\\item{0:} One correlation matrix per band. \n\\item{1:} One correlation matrix for all bands. \n\\item{2:} One correlation matrix for all band, except the last scale. \n\\item{3:} Import correlation matrix.\n\\end{itemize}\nDefault is one correlation matrix per band.\n}             \n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nInput correlation matrix file name.\nOnly used when option ``-x 3'' is set. Default is not to avail of this.\n\\end{itemize}\n\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\item wk1d\\_trans input.fits wk \\\\\nCalculate the WT-KLT of the input data and store the eigenvectors\nin the files ``wk\\_ev\\_1.fits, ..., wk\\_ev\\_N.fits''. Each file number $i$ \ncontains a 2D data set. A given row $j$  represents eigenvector \nnumber $i$ at resolution level $j$. \n\\item wk1d\\_trans -C input.fits wk \\\\\nDitto, but write the calculated correlation matrix to disk.\n\\end{itemize}\n\n\\subsection{WT-KLT Reconstruction of 1D Multichannel Data: wk1d\\_trec}\n\\index{wk1d\\_trec}\nThe program \n{\\em wk1d\\_trec} computes the WT-KLT  transform of \na multichannel 1D signal (2D data set), and reconstructs the data from\na subset of eigenvectors. By default, only the first eigenvector is\nused at each resolution level.\n{\\bf\n\\begin{center}\n USAGE: wk1d\\_trec option data\\_in data\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-n number\\_of\\_scales]} \\\\\n Number of scales used in the multiresolution transform.\n Default is 4.\n\\item {\\bf [-C]} \\\\\nWrite the correlation matrix to disk. \nThe file name is ``Correl\\_Matrix''. Default is not to do this.\n\\item {\\bf [-x CorrelMat\\_Method]}\n{\\small\n\\begin{itemize}   \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm          \n\\item{0:} One correlation matrix per band. \n\\item{1:} One correlation matrix for all bands. \n\\item{2:} One correlation matrix for all band, except the last scale. \n\\item{3:} Import correlation matrix.\n\\end{itemize}\nDefault is one correlation matrix per band.\n}             \n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nInput correlation matrix file name.\nOnly used when option ``-x 3'' is set. Default is not to use this. \n\\item {\\bf [-F NbrEigenVect]} \\\\\nNumber of eigenvectors used for the reconstruction. \nDefault is set to the number of images.\n\\item {\\bf [-K EigenVect\\_Number]} \\\\\nEigenvector number which will not be used for the reconstruction. \n\\end{itemize}\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\item wk1d\\_trec input.fits output.fits \\\\\nComputes the WT-KLT  transform and reconstructs the data from\nthe first eigenvector of each resolution level.\n\\item wk1d\\_trec -F 3  input.fits output.fits \\\\\nUse the three first eigenvectors\n\\item wk1d\\_trec -F 7 -K 2 -K 3 -K 4 trans.fits output.fits \\\\\nUse four eigenvectors (i.e., eigenvectors 1,5,6,7).\n\\end{itemize}\n\n\n\\subsection{WT-KLT Transform of 2D Multichannel Data: wk\\_trans}\n\\index{wk\\_trans}\n\\label{sect_mc_trans}\nThe program \n{\\em wk\\_trans} computes the WT-KLT  transform of \na multichannel image (3D data set) containing $N$ frames \n($N < 500$). The wavelet transform\nis applied to each frame, and the KL transform is applied to each\nresolution level, exept the last (smooth) scale. \nSo we have a set of eigenvectors for \neach resolution level $j$ $\\{e_{j,1}, \\dots, e_{j,N}\\}$.\nThe output is a set \n$N$ multiresolution transform files (suffice ``.mr''). Eigenvectors\nare stored by increasing importance. The ith multiresolution file (i=1..N)\ncontains the eigenvectors $\\{e_{1,i}, \\dots, e_{J-1,i}\\}$, where $J$ is the \nmaximum resolution level (last smooth array).\nIf the output file name\ngiven by the user does not contain the ``.mr'' suffix, it is automatically\nadded. The ``.mr'' file is a FITS format file, and can be manipulated by\nany package dealing with FITS format.\n{\\bf\n\\begin{center}\n USAGE: wk\\_trans option image\\_in wtklt\\_transform\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]}\n\\itemsep=0.1truecm\n{\\small \n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\item linear wavelet transform: \\`a trous algorithm \n\\item B-spline wavelet transform: \\`a trous algorithm \n\\item wavelet transform in Fourier space \n\\item morphological median transform \n\\item morphological minmax transform \n\\item pyramidal linear wavelet transform \n\\item pyramidal B-spline wavelet transform \n\\item pyramidal wavelet transform in Fourier space: \n                     wavelet =  between two resolutions \n\\item  pyramidal wavelet transform in Fourier space: \n                     wavelet = difference between the square of two resolutions\n\\item  pyramidal median transform \n\\item  pyramidal Laplacian \n\\item  morphological pyramidal minmax transform \n\\item  decomposition on scaling function \n\\item  (bi-) orthogonal wavelet transform. \\\\ \nAntonini 7/9 filters ~\\cite{wave:antonini92} are used by default, with an \n$L_1$ normalization. The filters can be changed using the ``-T'' option, and\nan $L_2$ normalization is obtained by ``-L'' option.\n\\item  Feauveau wavelet transform \n\\item  Feauveau wavelet transform without undersampling \n\\item  G transform (non-redundant morphological min-max algorithm)\n\\item Haar wavelet transform (L2 normalization).\n\\item Half-pyramidal wavelet transform (HPWT)\n\\item Mixed HPWT and Median method\n\\item dyadic wavelet transform \n\\item Mixed WT and PMT method (WT-PMT) \n\\item Undecimated Haar transform: \\`a trous algorithm\n\\item Undecimated (bi-) orthogonal wavelet transform. \\\\\nAntonini 7/9 filters ~\\cite{wave:antonini92} are used by default, with an \n$L_1$ normalization. The filters can be changed using the ``-T'' option, and\nan $L_2$ normalization is obtained by ``-L'' option.\n\\end{enumerate}}\nDefault is 2.\n\\item {\\bf [-T type\\_of\\_filters]}  \n{\\small\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item Antonini 7/9 filters. \n\\item Daubechies filter 4. \n\\item Biorthogonal 2/6 Haar filters.\n\\item Biorthogonal 2/10 Haar filters.\n\\item Odegard 7/9 filters.\n\\item User's filters.\n\\end{enumerate}}\nDefault is Antonini 7/9 filters. \\\\\n This option is only available if the chosen transform method is\n the (bi-) orthogonal transform (-t 14 or -t 24).\n\\item {\\bf [-L]} \\\\\nUse an $L_2$ normalization. Default is $L_1$.\n% \\item {\\bf [-u]} \\\\\n% Number of undecimated scales used in the Undecimated Wavelet Transform\n% Default is all scales.\n \\item {\\bf [-n number\\_of\\_scales]} \\\\\n Number of scales used in the multiresolution transform.\n Default is 4.\n\\item {\\bf [-C]} \\\\\nWrite the correlation matrix to disk. \nThe file name is ``Correl\\_Matrix''. Default is not to do this.\n% \\item {\\bf [-p]} \\\\\n% Normalize the correlation matrix. Values on the diagonal are 1. \n% Default is no.\n\\item {\\bf [-x CorrelMat\\_Method]}\n{\\small\n\\begin{itemize}      \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm       \n\\item{0:} One correlation matrix per band. \n\\item{1:} One correlation matrix for all bands. \n\\item{2:} One correlation matrix for all band, except the last scale. \n\\item{3:} Import correlation matrix.\n\\end{itemize}\nDefault is one correlation matrix per band.\n}             \n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nInput correlation matrix file name.\nOnly used when option ``-x 3'' is set. Default is not to do this.\n\\end{itemize}\n\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\item wk\\_trans cube.fits wk \\\\\nCalculate the WK-KLT of a 3D data set. If the cube contains $N$ frames,\n$N$ files will be created (wk\\_ev\\_1.mr, ..., wk\\_ev\\_N.mr).\n\\item mr\\_extract -b 2 wk\\_ev\\_1.mr b2\\_1  \\\\\nExtract the second band from the multiresolution file ``wk\\_ev\\_1.mr''.\nThe file ``b2\\_1.fits'' contains an image which\ncorresponds to the first eigenvector at the second resolution level.\n\\end{itemize}\n\n\n\\subsection{WT-KLT Reconstruction of 2D Multichannel Data: wk\\_trec}\n\\index{wk\\_trec}\nThe program \n{\\em wk\\_trec} computes the WT-KLT  transform of \na multichannel image (3D data set), and reconstructs the data from\na subset of eigenvectors.\nThe output file contains the reconstruction. Most of the options are the\nsame as those described in section~\\ref{sect_mc_trans}.\n{\\bf\n\\begin{center}\n USAGE: wk\\_trans option image\\_in wtklt\\_transform\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-T type\\_of\\_filters]}  \nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-L]} \nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-n number\\_of\\_scales]}\n\\item {\\bf [-w]} \\\\\n Write to  disk the eigenvectors multiresolution files.\nFile names are: ``wk\\_ev\\_x.mr'',  where x is the eigenvector number.\nDefault is not to do this.\n\\item {\\bf [-C]}\nWrite the correlation matrix to disk. \nThe file name is ``Correl\\_Matrix''. Default is not to do this.\n\\item {\\bf [-x]} \n{\\small\n\\begin{itemize}       \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm      \n\\item{0:} One correlation matrix per band. \n\\item{1:} One correlation matrix for all bands. \n\\item{2:} One correlation matrix for all band, except the last scale. \n\\item{3:} Import correlation matrix.\n\\end{itemize}\nDefault is one correlation matrix per band.\n}             \n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nInput correlation matrix file name.\nOnly used when option ``-x 3'' is set. Default is not to do this.\n\\item {\\bf [-F NbrEigenVect]} \\\\\nNumber of eigenvectors used for the reconstruction. \nDefault is set to the number of images.\n\\item {\\bf [-K EigenVect\\_Number]} \\\\\nEigenvector number which will not be used for the reconstruction. \n\\end{itemize}\n\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item wk\\_trec in\\_cube.fits out\\_cube \\\\\nCalculate the WT-KLT transform, and reconstruct only from the \nfirst eigenvector of each scale.\n\\item wk\\_trec -F 5 in\\_cube.fits out\\_cube  \\\\\nCalculate the WT-KLT transform, and reconstruct from the \nfirst five eigenvectors of each scale.\n\\item wk\\_trec -F 5 -K 2 in\\_cube.fits out\\_cube  \\\\\nDitto, but do not use eigenvector number 2. Only 4 eigenvectors are\nused.\n\\item wk\\_trec -F 5 -K 2 -t24  trans.fits output.fits \\\\\nDitto, but use the undecimated wavelet transform instead of the \n\\`a trous algorithm.\n\\item wk\\_trec -F 5 -K 1 -K 3 -t24  trans.fits output.fits \\\\\nOnly three eigenvectors (i.e., eigenvectors numbered 2,4,5) are used. \n\\end{itemize}\n\n\n\\section{Noise Modeling in the WT-KLT Space}\nSince a WT-KLT coefficient $c$ is obtained by two successive linear \ntransforms, robust noise modeling can be derived in order to know \n the noise standard deviation associated with the $c$ value.\n\n\\subsection{Non-Gaussian noise}\nIf the noise in the data $D$ is Poisson, the Anscombe transformation \n\\cite{rest:anscombe48}\n\\begin{eqnarray}\nt(D) = 2\\sqrt{D + \\frac{3}{8}}\n\\end{eqnarray}\nacts as if the data arose from a\nGaussian white noise model, with $\\sigma = 1$, under the\nassumption that the mean value of $I$ is sufficiently large.\nThe arrival of photons, and their expression by electron counts, on CCD\ndetectors may be modeled by a Poisson distribution.  In addition, there is \nadditive Gaussian read-out noise. The Anscombe \ntransformation has been extended to take this combined noise into \naccount.  The  generalization of the variance stabilizing\nAnscombe formula is derived as \\cite{starck:book98}:\n\\begin{eqnarray}\nt(D) = \\frac{2}{g} \\sqrt{g D + \\frac{3}{8} g^2 + \\sigma^2 - g m}\n\\end{eqnarray}\nwhere $g$ is the electronic gain of the detector, $\\sigma$ and $m$ the standard deviation \nand the mean of the read-out noise. \n \nThis implies that for the filtering of an image with Poisson noise or\na mixture of Poisson and Gaussian noise, we will first pre-transform \nthe data $D$ into another one $t(D)$ with Gaussian noise. Then $t(D)$ \nwill be filtered, and the filtered data will be inverse-transformed.\n\nFor other kinds of noise, modeling must be performed in order to \ndefine the noise probability distribution of the wavelet coefficients \n\\cite{starck:book98}.   \nIn the following, we will consider only stationary Gaussian noise.\n\n\\subsection{Noise level on WT-KLT coefficients}\nAssuming a Gaussian noise standard deviation $\\sigma_l$ for each signal \nor image $d_l$, the noise in the wavelet space follows a Gaussian distribution\n$\\sigma_{l,j}$, $j$ being the scale index. For a bi-orthogonal wavelet \ntransform with a $L^2$ normalization, $\\sigma_{l,j} = \\sigma_{l}$ for all $j$.\nSince the WT-KLT coefficients are obtained from a linear transform, we can\neasily derive the noise standard deviation relative to a WT-KLT coefficient\nfrom the noise standard deviation relative to the wavelet coefficients.\nConsidering the noise standard deviation vector  \n$s = \\left\\{\\sigma_{1}, ..., \\sigma_{L} \\right\\}$, we apply the\nfollowing transformation:\n\\begin{eqnarray}\ny_j = A_j^2 s^2\n\\end{eqnarray}\nand the noise standard deviation relative to a WT-KLT coefficient \n$ c_{l}(j,k)$ is $\\sqrt{y_j(l)}$. \n\n\n\n\\section{Multichannel Data Filtering}\n\\index{filtering}\n\\subsection{Introduction}\nKLT based filtering methods have been proposed \nin the past \\cite{mc:andrews76,mc:lee91,mc:constant97} for single images.\nThe proposed idea was to decompose the image $I$ of $M \\times N$ pixels\ninto non-overlapping blocks $B_s$ of size $N_b \\times N_b$. Typically, $N_b$ takes\nvalues from 4 to 16. Let $\\lambda_1,\\lambda_2,...\\lambda_n$ be the \nsingular values of the matrix $I$ in decreasing order, and\nassuming that the matrix $I$ is noisy, the rank $r$ of $I$ \nhas been defined as \\cite{mc:constant88}\n\\begin{eqnarray}\n\\lambda_r \\ge \\epsilon_1 > \\lambda_{r+1}\n\\end{eqnarray}\nwhere $\\epsilon_1$ is the norm of the noise. In case of \na Gaussian distribution of zero mean, an upper bound is $\\sqrt{MN}\\sigma$\n\\cite{mc:constant97}.\nA filtered version of $I$ can be obtained by reconstructing each block\nonly from its $r$ first eigenvalues.\nAn original approach has been developed in \\cite{mc:natarajan95,mc:constant97}\nin order to find the optimal\n$\\epsilon$ value, based on the $\\epsilon$-compression ratio curve, using \na lossless compression method like JPEG. It has been found that the maximum \nof the second derivative of the curve furnishes the \noptimal $\\epsilon$ value \\cite{mc:natarajan95}.\n\nIn the case of multichannel data filtering, several different approaches \nmay be considered based on noise modeling. They are \npresented in this section, and evaluated in the next one.\n\n\\subsection{Reconstruction from a subset of eigenvectors}\nThe WT-KLT transform of a data set $D=\\left\\{d_1, ..., d_L\\right\\}$\nconsists of applying a KLT on the wavelet scales. Hence the vector\n$W_j = \\left\\{ W_j^{(1)}, ..., W_j^{(L)}\\right\\}$ of the scales \n$j$ of the wavelet\ntransforms $W^{l}$ can be decomposed uniquely as:\n\\begin{eqnarray}\n W_j = U_j \\Lambda_j^{1 \\over 2}  V_j^{-1} = \\sum_{i=1}^L \n \\sqrt{\\lambda_{j,i}}  {u}_{j,i} \n {v}_{j,i}^t\n\\end{eqnarray}\nwhere $\\Lambda_j$ is the diagonal matrix of eigenvalues of the correlation\nmatrix $C_j$,  $U_j$ and $V_j$ are orthogonal matrices with column vectors\n$u_{j,i}$ and $v_{j,i}$ which are respectively \n the eigenvectors of $W_j W_j^t$ and $W_j^t W_j$.\n\n% \\overrightarrow{u}_{j,i}\nThe filtered wavelet coefficients of the band $j$ can be obtained by:\n\\begin{eqnarray}\n\\tilde W_j =  \\sum_{i=1}^r \\sqrt{\\lambda_{j,i}}  {u}_{j,i} {v}_{j,i}^t\n\\end{eqnarray}\nwhere $r$ is the rank of the matrix.\n\n\n\\subsection{WT-KLT Coefficient Thresholding}\nHard thresholding can  be applied to the  WT-KLT coefficients\nin a fashion analogous to the thresholding of wavelet coefficients.\n\n\\subsubsection*{Example: astronomical source detection}\n\nFigure~\\ref{fig_exp_trans1} shows a simulation. We created\na dataset of 18 frames, each of them containing a source (i.e., a point\nsource, or idealized star) at the \nsame position, \nbut at different intensity levels. The source is a small Gaussian, and \nthe source SNR is defined as the ratio between the maximum of the source and \nthe noise standard deviation. Figure~\\ref{fig_exp_trans1} (top) shows the\nevolution of the SNR in the 18 frames. Frames two and ten \nare shown in Figure~\\ref{fig_exp_trans1}, middle \nleft and right. The source \nSNR ratio is respectively three and one. Figure~\\ref{fig_exp_trans1}, bottom\nleft and right, shows respectively frame ten filtered by the \n wavelet transform and the WT-KLT. The WT detects only noise, while the \nWT-KLT clearly identifies the source.\n\n\\begin{figure}[htb]\n\\centerline{\n\\vbox{\n\\hbox{ \n\\psfig{figure=transp1.ps,bbllx=0.1cm,bblly=18cm,bburx=11cm,bbury=25cm,width=8cm,height=5.2cm,clip=}\n}\n\\hbox{ \n\\psfig{figure=transp1.ps,bbllx=0.5cm,bblly=1cm,bburx=22cm,bbury=18cm,width=13.6cm,height=11.2cm,clip=}\n}\n}}\n\\caption{Simulation: the dataset is composed of 18 frames. \nEach of them contains a source (small Gaussian) at the same position, \nbut at different intensity levels. Top, plot of the source maximum value versus\nthe frame number. Middle, frames 2 and 10, and bottom, filtered version\nof the frame 10 by the wavelet transform and wavelet Karhunen-Lo\\`eve transform.}\n\\label{fig_exp_trans1}\n\\end{figure}\n\n\n\\subsection{Multiscale Entropy}\nThe multiscale entropy relative to a set of observations $D(1..M)$ can \nbe written as:\n\\begin{eqnarray}\nH(D) = \\sum_{l=1}^{L} \\sum_{j=1}^{J}  \\sum_{k=1}^{N_j} h(c_{l,j,k})\n\\end{eqnarray}\nwhere $J$ is the number of scales used in the wavelet transform\ndecomposition, $L$ the number of observations, $k$ a pixel position,\n $c$ WT-PCA coefficients, and $l$ denotes the eigenvector number.\n\nThe last scale of the wavelet transform is not used, as previously, so\nthis entropy measurement is background independent, which is really\nimportant because the background can vary from one wavelength to another.\n\nAs for a wavelet coefficients in the case of mono-channel data,\nwe know the noise standard deviation relative to a coefficient,\nand coefficients are of zero mean. Therefore, we can apply the same\nfiltering method. The filtered WT-PCA coefficients are found by minimizing\nfor each  $c_{l,j,k}$:\n\\begin{eqnarray}\nj(\\tilde c_{l,j,k}) = h_s(c_{l,j,k} -\\tilde c_{l,j,k}) \n                      + \\alpha h_n(\\tilde c_{l,j,k})\n\\label{eqn_func_mc}\n\\end{eqnarray}\n\n\\subsubsection*{Example}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{ \n\\psfig{figure=fig_simu20_noi12.ps,bbllx=3cm,bblly=2.8cm,bburx=18cm,bbury=17.4cm,width=7.5cm,height=8cm,clip=}\n}}\n\\caption{Simulation: Root Mean Square Error versus the  noise standard deviation.\nSee text.}\n\\label{fig_simu20_noi12}\n\\end{figure}\n\nFigure~\\ref{fig_simu20_noi12} relates to a simulation using the same dataset \nas in the previous example (i.e., \na dataset of 18 frames).\nAdditive noise was used, and the data were filtered. \nWe  calculated the Root Mean Square Error\n(RMSE) on each individual frame on a $5 \\times \n5$ square centered on the source.\nHence, the RMSE reflects well the photometric errors, and the addition\nof the 18 RMSE values, which we call IRMSE (Integrated RMSE), \nfurnishes us a reliable measurement of the filtering quality.\nThe simulation was repeated with 12 noise levels, and four\ndifferent filtering methods were compared. Figure~\\ref{fig_simu20_noi12}\nshows the IRMSE versus the noise standard deviation plot. The four\nmethods are (i) multiscale entropy aaplied to \nthe WT-KLT coefficients (diamond),\n(ii) reconstruction from a subset of eigenvectors of the KLT (triangle),\n(iii) multiscale entropy applied to each frame independently (square),\nand (iv) thresholding applied to the wavelet transform of each frame (star).\nThis simulation shows clearly that the approach proposed here, multiscale\nentropy applied to the WT-KLT coefficients, outperforms all other methods.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{ \n\\psfig{figure=fig_planck_simu8_noi12.ps,bbllx=2.5cm,bblly=2.8cm,bburx=18cm,bbury=17.4cm,width=7.5cm,height=8cm,clip=}\n}}\n\\caption{Planck Simulation: Root Mean Square Error versus the  noise standard deviation.\nSee text.}\n\\label{fig_planck_simu8_noi12}\n\\end{figure}\n\nThe same experiments were performed using a simulated Planck data set.\nPlanck is an upcoming European Space Agency mission to carry out measurements\nof the cosmic microwave background.\nThe data set contains ten images, each one being a linear combination of\n6 sky component images (CMB, SZ, free-free, etc.). As in the previous \nsimulation, noise was added, and the data were filtered\nby the four methods. The only difference is that the RMSE is calculated\non the full frames. Figure~\\ref{fig_planck_simu8_noi12} shows \nIRMSE versus the noise standard deviation plot. Diamonds, triangles, \nsquares and stars represent the same methods as before.\nAgain, the multiscale entropy applied to the WT-KLT coefficients outperforms \nthe other methods.\n\n\\subsection{WT-KLT Filtering of 1D Multichannel Data: wk1d\\_filter}\n\\label{sect_mc1d_filter}\n\\index{wk1d\\_filter}\nThe program \n{\\em wk1d\\_filter} filters \na multichannel signal (2D data set).\n{\\bf\n\\begin{center}\n USAGE: wk1d\\_filter option data\\_in data\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n \\itemsep=0.1truecm\n\n\\item {\\bf [-n number\\_of\\_scales]}\\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-g sigma]}\\\\\n The image contains Gaussian noise, and the standard deviation is\ngiven by {\\em sigma}. This option should be set only if the user\nknows the standard deviation of the noise. \n\\item {\\bf [-x]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n% \\item {\\bf [-p]} \\\\\n% Normalize the correlation matrix. Values on the diagonal are 1. \n% Default is no.\n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-y NoiseCorrelationType]}\n{\\small\n\\begin{itemize}             \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item{0:} Compute the correlation matrix with all wavelet coefficients. \n\\item{1:} Compute the correlation matrix only with significant wavelet coefficients. \n\\item{2:} Compute the correlation matrix with weighted wavelet coefficients. \n\\end{itemize}\n} \nDefault is 1.     \n\\item {\\bf [-s NSigma]} \\\\\nWavelet coefficients are significant when their absolute values are larger\nthan nsigma * SigmaNoise. This option has an effect when \nthe ``-y'' option is set to 1 or 2.\nDefault {\\em NSigma} value is  3. \n\\item {\\bf [-S NSigma]} \\\\\nThe WT-KLT coefficients are  at {\\em NSigma}*SigmaNoise.\nDefault is  3.\n\\item {\\bf [-P]}\\\\\nPositivity constraint. Default is not to enforce this.\n\\item {\\bf [-F NbrEigenVect]} \\\\\nNumber of eigenvectors used for the reconstruction. \nDefault is set to the number of images.\n\\item {\\bf [-K EigenVect\\_Number]} \\\\\nEigenvector number which will not be used for the reconstruction. \n\\item {\\bf [-C]}\\\\\nsee section~\\ref{sect_mc_trans}.  \n\\end{itemize}\n\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item wk1d\\_filter input.fits output.fits \\\\\nFilter the 1D multi-channel data set using the WT-KLT transform.\n\\item wk1d\\_filter -S 5 input.fits output.fits \\\\\nDitto, but smooth the WT-KLT at 5 sigma instead of 3. \n\\end{itemize}\n\n\\subsection{WT-KLT Filtering of 2D Multichannel Data: wk\\_filter}\n\\index{wk\\_filter}\n\\label{sect_mc_filter}\nThe program \n{\\em wk\\_filter} filters \na multichannel image (3D data set).\n{\\bf\n\\begin{center}\n USAGE: wk\\_filter option data\\_in data\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-T type\\_of\\_filters]}  \\\\ \nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-L]} \\\\\nsee section~\\ref{sect_mc_trans}.\n% \\item {\\bf [-u]} \\\\\n% see section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-g sigma]}\\\\\nNoise standard deviation. Default is automatically calculated.\n\\item {\\bf [-x]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n% \\item {\\bf [-p]} \\\\\n% Normalize the correlation matrix. Values on the diagonal are 1. \n% Default is no.\n\\item {\\bf [-O Input\\_CorrelMat\\_FileName]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-y NoiseCorrelationType]}\n{\\small\n\\begin{itemize}             \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item{0:} Compute the correlation matrix with all wavelet coefficients. \n\\item{1:} Compute the correlation matrix only with significant wavelet coefficients. \n\\item{2:} Compute the correlation matrix with weighted wavelet coefficients. \n\\end{itemize}\n} \nDefault is 1.     \n\\item {\\bf [-s NSigma]} \\\\\nWavelet coefficients are significant when their absolute values are larger\nthan nsigma * SigmaNoise. This option has an effect when \nthe ``-y'' option is set to 1 or 2.\nDefault {\\em NSigma} value is  3. \n\\item {\\bf [-S NSigma]} \\\\\nThe WT-KLT coefficients are  at {\\em NSigma}*SigmaNoise.\nDefault is  3.\n\\item {\\bf [-P]}\\\\\nPositivity constraint. Default is not to enforce this.\n\\item {\\bf [-b]}\\\\\nMaximum image constraint at 255.  Default is not to use this.\n\\item {\\bf [-w]}\\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-F NbrEigenVect]} \\\\\nNumber of eigenvectors used for the reconstruction. \nDefault is set to the number of images.\n\\item {\\bf [-K EigenVect\\_Number]} \\\\\nEigenvector number which will not be used for the reconstruction. \n\\item {\\bf [-C]}\\\\\nsee section~\\ref{sect_mc_trans}.  \n\\end{itemize}\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item wk\\_filter in\\_cube.fits out\\_cube.fits \\\\\nFilter the cube using all default options.\n\\item wk\\_filter -S 5 in\\_cube.fits out\\_cube.fits\\\\\nThreshold the WT-KLT coefficients at 5 sigma, instead of 3 sigma.\n\\item wk\\_filter -S 5 -t24 in\\_cube.fits out\\_cube.fits\\\\\nDitto, but use an undecimated wavelet transform.\n\\end{itemize}\n\n\\subsection{WT-KLT Filtering of 2D Multichannel Data by the Multiscale\nEntropy Method: wk\\_memfilter}\n\\index{wk\\_memfilter}\nThe program \n{\\em wk\\_memfilter} filters \na multichannel image (3D data set) by the multiscale entropy method.\n{\\bf\n\\begin{center}\n USAGE: wk\\_memfilter option cube\\_in cube\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-T type\\_of\\_filters]}  \\\\ \nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-L]} \\\\\nsee section~\\ref{sect_mc_trans}.    \n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-g sigma]}\\\\\nsee section~\\ref{sect_mc1d_filter}.\n\\item {\\bf [-x]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-O]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-y NoiseCorrelationType]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-s nsigma]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-P]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-b]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-w]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-F NbrEigenVect]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-K EigenVect\\_Number]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-C CvgParam]} \\\\\nConvergence parameter. Default is $1e-2$.\n\\item {\\bf [-G RegulParam]} \n Regularization parameter. Default is 1. \n\\item {\\bf [-U Type\\_of\\_Regularization]} \n{\\small\n\\begin{enumerate}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item Use a fixed user Alpha value.\n\\item Estimate the optimal Alpha.\n\\item Estimate one Alpha value per band.\n\\end{enumerate}}\nDefault is 1.\n\\item {\\bf [-D]} \\\\\nAlpha is modified using the data SNR. Default is no.\n\\item {\\bf [-i MaxIter]} \\\\\n Maximum number of iterations. Default is 20.\n\\end{itemize}\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item wk\\_memfilter -U 3 in\\_cube.fits out\\_cube.fits \\\\\nFiltering using one regularization parameter per resolution level.\n\\item wk\\_memfilter -U 3 -D in\\_cube.fits out\\_cube.fits \\\\\nDitto, but protect wavelet coefficients with high SNR from the regularization.\n\\item wk\\_memfilter -t24 -U 3 -D in\\_cube.fits out\\_cube.fits \\\\\nDitto, but use the undecimated wavelet transform.\n\\end{itemize}\n\n\n\n\\section{Filtering using the Haar-Multichannel Transform}\n\\subsection{Definition}\nWe have seen in \\proj \\ that the Haar transform \npresents some advantages, especially when the data contains Poisson noise.\n\nIn order to decorrelate the information both spatially and in wavelength (or in\ntime), a 2D-wavelet transform\nmust first be performed on each frame of the date cube $D(x,y,z)$. \nWe denote the result $w_{j,k_x,k_y,z}$, \nwhere $j$ is the scale index ($j \\in [1,J]$, and\nwhere $J$ is the number of scales), $k_x,k_y$ the \nspatial position in the scale ($k_x \\in [0,N_x-1]$, and $k_y \\in [0,N_y-1]$),\n and $z$ is the frame number. \nThis set must again be transformed in order to \ndecorrelate the information in the third dimension. We apply a 1D-transform\nto each vector $w_{j,k_x,k_y,z}$, \nand we get a new set of data $u_{j,j^{'},k_x,k_y,k_z}$,\nwhere $j^{'}$ and $k_z$ are respectively the scale index and position\nin the third dimension.\n\nUsing the unnormalized Haar transform, \na coefficient $u_{j+1,j^{'}+1,k,l,t}$ can be written\nas:\n\\begin{eqnarray}\nu_{j+1,j^{'}+1,k_x,k_y,k_z} \n   = \\sum_{i=2^{j^{'}+1}k_z}^{2^{j^{'}}k_z+2^{j^{'}}-1} w_{j+1,k_x,k_y,i} -\n     \\sum_{i=2^{j^{'}+1}k_z+2^{j^{'}}}^{2^{j^{'}+1}(k_z+1)-1} w_{j+1,k_x,k_y,i}\n\\end{eqnarray}\nWe assume now a constant background rate $\\lambda_i$ for each frame $i$ \nof the data cube. \nEach Haar wavelet coefficient $w_{j+1,k_x,k_y,i}$ is the difference between two\nrandom variables $X_i$ and $Y_i$, which follows a Poisson distribution of\nparameter $\\lambda_{j,i}$, where $\\lambda_{j,i}$ represents the rate per\npixel over $2^{j+1}$ pixels of the $i$th frame, and is equal to $2^{2j}\\lambda-i$.\nThen $u_{j+1,j^{'}+1,k_x,k_y,k_z}$ is the difference of \n two variables, $X=\\sum_i X_i$ and $Y=\\sum_i Y_i$, and both follow a Poisson\n distribution of parameter $\\sum_i \\lambda_{j,i}$.\nThe thresholding method described in \\proj \ncan therefore be used, using the correct $\\lambda$ value.\n\n\\subsubsection*{Filtering}\n\nThe multichannel filtering algorithm is:\n\\begin{enumerate}\n\\item For each frame $D(*,*,z)$, apply the 2D-Haar transform: we obtain \n$w_{j,k,l}(z)$.\n\\item For each scale $j$, and at each position $k_x,k_y$, \nextract the 1D vector\n $w_{j,k_x,k_y,*}$ and compute its wavelet transform. We get a new data set.\n\\item Threshold the coefficients using the correct $\\lambda value$.\n\\item Inverse 1D transform.\n\\item Inverse 2D transform.\n\\end{enumerate}\n\nFor non-constant background, a coarse to fine approach, as explained in\n\\proj, can be used.\n\n\\subsection{WT-KLT Filtering of 2D Multichannel Data by the Multiscale\nHaar Transform: ww\\_filter}\n\\index{ww\\_filter}\nThe program \n{\\em ww\\_filter} filters \na multichannel image (3D data set) by applying a 2D  WT following\nby a 1D WT in the third direction.\n{\\bf\n\\begin{center}\n USAGE: ww\\_filter option data\\_in data\\_out\n\\end{center}}\nwhere options are: \n\\begin{itemize} \n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item {\\bf [-t type\\_of\\_multiresolution\\_transform]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-T type\\_of\\_filters]}  \\\\ \nsee section~\\ref{sect_mc_trans}.\n\\item {\\bf [-L]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-n number\\_of\\_scales]} \\\\\nsee section~\\ref{sect_mc_trans}.  \n\\item {\\bf [-g sigma]}\\\\\nsee section~\\ref{sect_mc1d_filter}.\n\\item {\\bf [-s nsigma]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-S nsigma]} \\\\\nsee section~\\ref{sect_mc_filter}.  \n\\item {\\bf [-P]} \\\\\nsee section~\\ref{sect_mc_filter}. \n\\end{itemize}\n\\subsubsection*{Examples}\n\\begin{itemize}\n\\baselineskip=0.4truecm\n\\itemsep=0.1truecm\n\\item ww\\_filter -t 18 -T 3 input.fits output.fits \\\\\nFiltering using the Haar  wavelet transform.\n\\item ww\\_filter -t 24 -T 3 input.fits output.fits \\\\\nDitto, but use an undecimated wavelet transform.\n\\item ww\\_filter  -t 24 -T 3 -S 5 input.fits output.fits \\\\\nIncrease the thresholding level.\n\\end{itemize}\n\n\\newpage\n\n\\section{Independent Component Analysis}\n\\index{independent component analysis}\n\\index{blind source separation}\n\\index{ICA}\n\nThe idea of independent component analysis (ICA) originates from\nthe problem of {\\em blind source separation} (BSS), and consists of\nrecovering unobserved signals or ``sources'' from several observed mixtures\n\\cite{mc:cardoso98}. Assuming that $n$ statistically independent \nsignals $s_1(t), ..., s_n(t)$ are mixed by an unknown $n \\times n$ mixing  \nmatrix $A=[a_{ij}]$, we have:\n\\begin{eqnarray}\nX(t) = A S(t)\n\\end{eqnarray}\nwhere $S(t) = [ s_1(t), \\dots, s_n(t) ]^t$, and\n $X(t) = [ x_1(t), \\dots, x_n(t) ]^t$ represents the observed signals, with \n $x_i(t) = \\sum_{j=1}^n a_{ij} s_j(t)$.  \nThe challenge is to find how to achieve separation using as our\nonly assumption that\nthe source signals are statistically independent. The solution  \nconsists of finding \nan $n \\times n$ separating matrix $B$, $Y(t) = B S(t)$, such that   \n$Y$ is an estimate of S.\nThis is achieved by minimizing contrast functions $\\Phi$, which are defined \nin terms of the Kullback-Leibler divergence  $K$:\n\\index{Kullback-Leibler}\n\\begin{eqnarray}\n\\Phi(Y) = \\int p_Y(u) \\log{ {p_Y(u) \\over \\prod p_{Y_i}(u_i) }} du\n\\end{eqnarray}\n\nThe mutual information, expressed by the  Kullback-Leibler divergence, \nvanishes if and only if the variables\n$Y_i$ are mutually independent, and is strictly positive otherwise.\n\nICA has been used in astronomy to analyze multispectral \nimages \\cite{mc:bijaoui00} of the galaxy 3C 120 and to separate \n\\index{data!\\texttt{3}C120}\nthe Cosmic Microwave Background\n\\index{Cosmic Microwave Background}\nfrom other sky components \\cite{mc:bacci00}.\nAs for PCA, it has been shown \\cite{mc:zibu99,mc:zibu01} that applying \nICA to  wavelet transformed signals leads to better quality results,\nespecially in the presence of noise.\n\n\\subsection*{Example}\nFig.~\\ref{fig_ica1} shows three simulated signals. Six observed data sets\nwere derived from the three sources, by a linear combination\n(see Fig.~\\ref{fig_ica2}). Without any knowledge of the mixing matrix,\nthe JADE-ICA \\cite{mc:cardoso98} method was applied and the \nthree signals were\nreconstructed from the six observed data sets (see Fig.~\\ref{fig_ica3}).\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{ \n\\psfig{figure=fig_ica_source.ps,bbllx=2cm,bblly=12.5cm,bburx=20cm,bbury=25.5cm,width=9cm,height=7.5cm,clip=}\n}}\n\\caption{Example of three simulated sources.}\n\\label{fig_ica1}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{ \n\\psfig{figure=fig_ica_obs_signal.ps,bbllx=2cm,bblly=12.5cm,bburx=20cm,bbury=25.5cm,width=9cm,height=7.5cm,clip=}\n}}\n\\caption{Mixed sources. Each of these six signals is a linear combination\nof the three simulated sources.}\n\\label{fig_ica2}\n\\end{figure}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{ \n\\psfig{figure=fig_ica_demixing.ps,bbllx=2cm,bblly=12.5cm,bburx=20cm,bbury=25.5cm,width=9cm,height=7.5cm,clip=}\n}}\n\\caption{Reconstructed sources from the mixed signals.}\n\\label{fig_ica3}\n\\end{figure}\n\n\\subsection{JADE-ICA IDL Programs}\n \n\\subsubsection{JADE}\n\\label{jade}\n\\index{JADE}\n Apply the Independant Componant Method to a set of vectors using\nthe JADE method.\n{\\bf\n\\begin{center}\n USAGE:  jade, ObservSig, NbSource, DeMixingMat, Process, Verbose=Verbose\n\\end{center}}\nwhere\n\\begin{itemize}\n\\item {\\em  ObservSig:} Input Data (ObservSig = $A$ \\# original signal).\nObservSig$(i,*)$ = $i$th vector.\n\\item {\\em  NbSource:}  Input number of sources in the input signal.\n\\item {\\em DeMixingMat:} Output demixing matrix.\n\\item {\\em Process:} Output Reconstructed process = DeMixingMat \\# ObservSig.\nProcess$(i, *)$ = $i$th Process, with $i = 0.. {\\mathrm NbSource} - 1$.\n\\end{itemize}\n\n\n\\subsubsection{JADE1D}\nApply the Independant Componant Method to a set of vectors using\nthe JADE method. The routine is identical to jade routine, except\nthat the input-output vectors are ordered differently ($V(*,i)$ for\nthe $i$th vector, instead of $V(i,*)$).\n{\\bf\n\\begin{center}\n USAGE:  jade1d, ObservSig, NbSource, DeMixingMat, Process, Verbose=Verbose\n\\end{center}}\nwhere\n\\begin{itemize}\n\\item {\\em  ObservSig:} Input Data (ObservSig = $A$ \\# original signal).\n;                    ObservSig$(*,i)$ = $i$th vector.\n\\item {\\em  NbSource:}  Input number of sources in the input signal.\n\\item {\\em DeMixingMat:} Output demixing matrix.\n\\item {\\em Process:} Output Reconstructed process = DeMixingMat \\# ObservSig.\nProcess$(*, i)$ = $i$th Process, with $i = 0.. {\\mathrm NbSource} - 1$.\n\\end{itemize}\n\n\\subsubsection{JADE2D}\nApply the Independant Componant Method to a set of images using\nthe JADE method. The routine is an extension to 2d of jade1d routine.\nThe input set of images must be given with the following syntax:\nObservSig$(*, *, i)$ = $i$th image. If the ``/wave'' keyword is set,\na 2D wavelet transform is first perform on each image, JADE is applied\non the wavelet transformed images, and an inverse wavelet transform\nis applied on the reconstructed process. The wavelet transform is\nperformed by calling the program {\\em mr\\_transform}. \n{\\bf\n\\begin{center}\n USAGE: jade2d, ObservSig, NbSource, DeMixingMat, Process, wave=wave, optw=optw, Verbose=Verbose\n\\end{center}}\nwhere\n\\begin{itemize}\n\\item {\\em  ObservSig:} Input Data (ObservSig = $A$ \\# original signal).\nObservSig$(*,*,i)$ = $i$th vector.\n\\item {\\em  NbSource:}  Input Number of sources in the input signal.\n\\item {\\em DeMixingMat:} Output demixing matrix.\n\\item {\\em Process:} Output Reconstructed process = DeMixingMat \\# ObservSig.\nProcess$(*, *, i)$ = $i$th Process, with $i = 0.. {\\mathrm NbSource} - 1$.\n\\item {\\em wave::} if set, an bi-orthogonal wavelet transform is applied\non each image, and the component separation is performed\non the wavelet transformed images.\nThe inverse wavelet transform is then applied on the\nreconstructed process.\n\\item {optw:} string = options for the wavelet transformation\n\\end{itemize}\n\n\\subsubsection*{Examples:}\n\\begin{itemize}\n\\item jade2d,  ObservIma, NbSource, DeMixingMat, RecIma \\\\\nApply the JADE method to {\\em ObservIma}. \n\\item jade2d, ObservIma, NbSource, DeMixingMat, RecIma, /wave, optw='-n5'\\\\\nDitto, but applied a wavelet transform with five scales on each image.\n\\end{itemize}\n", "meta": {"hexsha": "abddb3b19a0f99fd502d1397cb426745f65f0ceb", "size": 50301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr3/mc_3d.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_mr3/mc_3d.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_mr3/mc_3d.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": 39.3899765074, "max_line_length": 163, "alphanum_fraction": 0.7329675354, "num_tokens": 15064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6131985360048055}}
{"text": "\\chapter{Introduction to Spreadsheets}\n\nFor many real-world problems, spreadsheets are the perfect\ntool. In this chapter, you will be introduced to how to use a\nspreadsheet. There are numerous spreadsheet programs: Google Sheets,\nMicrosoft Excel, Apple Numbers, OpenOffice Calc, etc.  All of them are\nvery similar. I will be using Google Sheets, but if you are using one\nof the others, you should be able to follow along.\n\nThe first spreadsheet program (VisiCalc) was introduced in 1979 as a\ntool for finance people to play ``what if'' games.  For example, a\ncompany might make a spreadsheet that told them how much more profit\nthey would make if they changed from using an expensive metal to using\na cheaper alloy.\\index{Spreadsheet}\n\nIn honor of its history, let's start by studying a business question:\nI have a friend who dreams of quitting her job to become a cooper. (A\ncooper makes barrels that are used for aging wine and whiskey.)  She\nsays:\n\\begin{itemize}\n\\item It costs \\$45 dollars in materials to build one barrel.\n\\item A barrel sells for \\$100 dollars.\n\\item The workshop/warehouse she wants to rent costs \\$2000 per month.\n\\item Taxes would take about 20\\% of her profits\n\\item She needs to make \\$4000 after taxes to live \n\\end{itemize}\n\nShe has asked you, ``How many barrels do I need to make each month to survive?''\n\n\\section{Solving It Symbolically}\n\nMany problems can be solved two ways: symbolically or\nnumerically.\\index{symbolic vs. numeric solutions} To solve this\nproblem symbolically, you would write out the facts as equations or\ninequalities and then do symbol manipulations until you ended up with\nan answer. In this case, you would let $b$ be the number of barrells\nand create the following inequality:\n\n$$(1.0 - 0.2)\\left(b(100 - 45) - 2000\\right) \\geq 4000$$\n\nYou would simplify it:\n\n$$(0.8)\\left(55 b - 2000\\right) \\geq 4000$$\n\nAnd simplify it more:\n\n$$44b - 1600 \\geq 4000$$\n\nIf that is true, then:\n\n$$44b \\geq 5600$$\n\nAnd if that is true, then:\n\n$$b \\geq \\frac{1400}{11}$$\n\n$1400/11$ is about 127.27, so she needs to make and sell 128 barrels\neach month.\n\nThat is a perfect answer, and we didn't need a spreadsheet at all. Two things:\n\\begin{itemize}\n\\item As problems get larger and more realistic, it gets much more difficult to solve them symbolically.\n\\item As soon as you say ``Yes, you need to make and sell 128 barrels\n  each month.'' Your friend will ask ``What if I make and sell 200\n  barrels? How much money will I make then?''\n\\end{itemize}\n\nSo we will use a spreadsheet to solve the problem numerically.\n\n\\section{Solving It Numerically (with a spreadsheet)}\n\n\nLet's get back to our example. Put labels in the A column:\n\\begin{itemize}\n\\item{Barrels produced (per month)}\n\\item{Materials cost (per barrel)}\n\\item{Sale price (per barrel)}\n\\item{Pre-tax earnings (per month)}\n\\item{Taxes (per month)}\n\\item{Take home pay (per month)}\n\\end{itemize}\n\nFormat them any way you like. It should look something like this:\n\n\\includegraphics[width=0.4\\textwidth]{BarrelLabels.png}\n\nIn the B column, the first four cells are values (not formulas):\n\\begin{itemize}\n\\item{115 formatted as a number with no decimal point}\n\\item{45 formatted as currency}\n\\item{100 formatted as currency}\n\\item{2000 formatted as currency}\n\\end{itemize}\n\nIt should look something like this:\n\n\\includegraphics[width=0.5\\textwidth]{BarrelValues.png}\n\nThe next three cells in the B column will have formulas:\n\\begin{itemize}\n\\item{B1 * (B3 - B2) - B4}\n\\item{0.2 * B5}\n\\item{B5 - B6}\n\\end{itemize}\n\nIt should look something like this:\n\n\\includegraphics[width=0.5\\textwidth]{BarrelFormulas.png}\n\nNow you can share this spreadsheet with your friend and she can put\ndifferent values into the cells for what-if games.  Like ``If I can\nget my materials cost down to \\$42 per barrel, what happens to my take\nhome pay?''\n\nSometimes it is nice to show a range of values for a variable or two.\nIn this case, it might be nice to show your friend what the numbers\nlook like if she produces 115, 120, 125, 130, 135, or 140 barrels per\nmonth.\n\nWe have one column, and now we need six. How do we duplicate cells?\n\\begin{enumerate}\n\\item Click B1 to select it and then shift click on B7 to select all seven cells.\n\\item Copy them. (There is probably a menu item for this.)\n\\item Click C1 to select it\n\\item Paste them.\n\\end{enumerate}\n\n\\includegraphics[width=0.5\\textwidth]{BarrelCopyPaste.png}\n\nWe want the first cell in the new column to be 120. You could just\ntype in 120, but lets do something more clever.  Put a formula into that\ncell: = B1 + 5.  Now the cell should show 120.\n\nWhy did we put in a formula? When we duplicate this column, this cell\nwill always have 5 more barrels than the cell to its left.\n\nNow lets duplicate the second column a few times. The easy way to do\nthis is to select the cells as you did before and drag the lower-right\ncorner to the right until column G is in the selection. When you end\nthe drag, the copies will appear:\n\n\\includegraphics[width=0.8\\textwidth]{BarrelDragPaste.png}\n\nNice, right? Now your friend can easily see how many barrels\ncorresponds to how much take-home pay. You know what she really wants? A graph.\n\n\\section{Graphing}\n\nGraphing is a little different on every different platform.  Here is what you want the graph to look like.\n\n\\includegraphics[width=0.8\\textwidth]{BarrelGraph.png}\n\nOn Google Sheets:\\index{spreadsheet!graphs}\n\n\\begin{enumerate}\n\\item Select cells B7 through G7. \n\\item Choose the menu item Insert -> Chart.\n\\item Choose the chart type (Line)\n\\item Add the X-axis to be B1 through G1.\n\\item Under the Customize tab, Set the label for the X-axis to be ``Barrels Made and Sold''.\n\\item Delete the chart title (which is the same as the Y-axis label).\n\\end{enumerate}\n\n\\section{Other Things You Should Know About Spreadsheets}\n\nYour spreadsheet document can have several ``Sheets''.  Each has its\nown grid of cells.  The sheet has a name; usually you call it\nsomething like ``Salaries''.  When you need to use a value from the\n``Salaries'' sheet in another sheet, you can specify ``Salaries!A2''\n-- that is, cell A2 on sheet ``Salaries''.  To flip between the sheets\nthere is usually a tab for each at the bottom of the document.\n\n\\includegraphics[width=0.5\\textwidth]{Sheets.png}\n\nBy default, the cell references are relative.  That is, when you write\na formula in cell H5 that references the value in cell G4, the cell\nremembers ``The cell that is one up and one to the left of me.''\nThus, if you copy that formula into B9, now that formula reads the\nvalue from A8.\n\nIf you want an absolute reference, you use \\$.  If H5 references\n\\$G\\$4, G4 will be used no matter where on the sheet the formula is\ncopied to.\n\nYou can use the \\$ on the row or colum.  In \\$A4, the column is\nabsolute and the row is relative.  In A\\$4, the row is absolute and\nthe column is relative.\n\n\\section{Challenge: Make a spreadsheet}\n\nYou have a company that bids on painting jobs. Make a\nspreadsheet to help you do bids. Here are the parameters:\n\\begin{itemize}\n\\item The client will tell you how many square meters of wall need to be painted.\n\\item Paint costs \\$0.02 per square meter of wall to cover\n\\item On average, a square meter of wall takes 0.02 hours to paint.\n\\item You can hire painters at \\$15 per hour.\n\\item You add 20\\% to your estimated costs for a margin of error and profit.\n\\end{itemize}\n\nMake a spreadsheet such that when you type in the square meters to be\npainted, the spreadsheet tells you how much you will spend on paint\nand labor.  It also tells you what your bid should be.\n", "meta": {"hexsha": "89d6fc7fd0b031ea52f8098ecfe96b3396e3ea2e", "size": 7552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Spreadsheets/intro-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/intro-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/intro-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": 37.0196078431, "max_line_length": 106, "alphanum_fraction": 0.7548993644, "num_tokens": 2009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6130650791543605}}
{"text": "\\chapter{Conclusion}\nIn conclusion, different MIP exact model have been developed to resolve the TSP problem and \\texttt{subtour\\_callback\\_general} has definitely obtain the best results in term of times. However no exact algorithm can resolve a problem with more than 1000 nodes in less than 600s. This must be considered in particular when the execution time is limited. In this case heuristics can be successfully applied to obtain a good solution (not the best) about 10 times faster. This result are confirmed with the performance profile in fig \\ref{fig:pp_Lbest}.\\\\\nFor the heuristics, \\texttt{best\\_two\\_opt} obtain really good results in term of execution time and cost optimization, indeed the best heuristic are the constructive ones combined with the iteration of \\texttt{best\\_two\\_opt}.\nThe constructive \\texttt{n\\_greedy} achieves the best performances as a heuristic alone but the use of the \\texttt{n\\_grasp} as a warm start brings a more variability.\n\\begin{figure}[!h]\n\t\\centering\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lbest_time.png}\n\t\t\\caption{Performance profile in time domain.}\n\t\t\\label{fig:Lbest_time}\n\t\\end{subfigure}\n\\hfill\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\columnwidth]{../res/Lbest_lb.png}\n\t\t\\caption{Performance profile in solution cost domain.}\n\t\t\\label{fig:Lbest_lb}\n\t\\end{subfigure}\n\t\\caption{Performance profile of the best models executed in the union of \\textit{data light} and \\textit{data average}.}\n\t\\label{fig:pp_Lbest}\n\\end{figure}", "meta": {"hexsha": "1b166e395823805741f9c231e0789892ad403df4", "size": 1567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/conclusion.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/conclusion.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/conclusion.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": 71.2272727273, "max_line_length": 552, "alphanum_fraction": 0.7849393746, "num_tokens": 415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7520125737597974, "lm_q1q2_score": 0.6130650757785171}}
{"text": "\\documentclass[letterpaper,12pt]{article}\n% \\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage{ifpdf}\n\n% \\usepackage[spanish,mexico]{babel}\n\\usepackage{multicol}\n\\usepackage{tikz}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\n%opening\n\\title{Lecture 2}\n\\author{Isaac Ayala Lozano}\n\n\\begin{document}\n\n% \\maketitle\n\n\n\n\\section{Lecture 2 - Exercise 8}\n\nCalculate the velocity, speed and acceleration for each \nposition vector.\n\n\n% --------------------------\n\n\\subsection{$\\vec{r}(t)= (\\cos (\\omega t), \\mathrm{e}^{\\omega t})$}\n\nThe first derivative of the vector gives us\n\n\\begin{equation*}\n \\vec{v}(t) = (- \\omega \\sin (\\omega t), \\omega \\mathrm{e}^{\\omega t})\n \\end{equation*}\n\nThe norm of the velocity vector gives us the speed.\n \n \\begin{equation*}\n  \\left \\| \\vec{v}(t) \\right \\| = \\sqrt{ \\omega^2 \\sin^2 (\\omega t) + \\omega ^2 \n\\mathrm{e}^{2 \\omega t}}\n \\end{equation*}\n\n The second derivative results in \n \n \\begin{equation*}\n  \\vec{a}(t) = (-\\omega ^2 \\cos (\\omega t) , \\omega ^2 \n\\mathrm{e}^{\\omega t})\n \\end{equation*}\n\nFigure \\ref{fig: vector 1} shows the plots for all three vectors with \nconditions $\\omega = 1$, and $t \\in \\left [ 0, 2 \\pi \\right ] $.\n \n\\begin{figure}[h]\n \\centering\n\n\\includegraphics[scale=0.65,keepaspectratio=true]{./img/graph01.png}\n \\caption{Position, Velocity and Acceleration plots for \n$\\vec{r}(t)= (\\cos (\\omega t), \\mathrm{e}^{\\omega t})$\n}\n \\label{fig: vector 1}\n\\end{figure}\n\n\n% -----------------------\n\n\\subsection{$\\vec{r}(t) = ( \\cos (\\omega t - \\phi), \\sin (\\omega t - \\phi))$}\n\nUsing the following trigonometric identities\n\n\\begin{equation*}\n \\begin{split}\n  \\sin (\\alpha \\pm \\beta) & = \\sin \\alpha \\cos \\beta \\pm \\cos \\alpha \\sin \\beta \n\\\\\n\\cos (\\alpha \\pm \\beta & = \\cos \\alpha \\cos \\beta \\mp \\sin \\alpha \\sin \\beta\n \\end{split}\n\\end{equation*}\n\nthe position vector can be rewritten as follows\n\n\\begin{equation*}\n \\vec{r} = (\n \\cos \\omega t \\cos \\phi + \\sin \\omega t \\sin \\phi,\n \\sin \\omega t \\cos \\phi - \\cos \\omega t \\sin \\phi\n )\n\\end{equation*}\n\nThe velocity, speed and acceleration are as follows\n\n \\begin{equation*}\n \\begin{split}\n \\vec{v}(t) & = ( - \\omega \\cos \\phi \\sin \\omega t + \\omega \\sin \\phi \\cos \n\\omega t, \\omega \\cos \\phi \\cos \\omega t + \\omega \\sin \\phi \\sin \\omega t) \\\\\n& = (- \\omega \\sin (\\omega t + \\phi), \\omega \\cos (\\omega t + \\phi))\n \\end{split}\n \\end{equation*}\n\n\n\\begin{equation*}\n \\left \\| \\vec{v}(t) \\right \\| = \\sqrt{ \\omega ^2 \\sin ^2 (\\omega t + \\phi) + \n\\omega ^ 2 \\cos ^2 (\\omega t + \\phi)}\n\\end{equation*}\n\n \\begin{equation*}\n \\begin{split}\n  \\vec{a}(t) & =  ( - \\omega ^2 \\cos \\phi \\cos \\omega t - \\omega ^2 \\sin \\phi \n\\sin \\omega t, - \\omega ^2 \\cos \\phi \\sin \\omega t + \\omega ^2 \\sin \\phi \\cos \n\\omega t)\\\\\n& = ( - \\omega ^2 \\cos (\\omega t - \\phi), -\\omega ^ 2 \\sin (\\omega t - \\phi))\n \\end{split}\n \\end{equation*}\n \n Figure \\ref{fig: vector 2} shows the plotted movement equations for the \nsystem. Notice that all three curves overlap when evaluated with $\\omega = 1$, \n $t \\in \\left [ 0, 2 \\pi \\right ] $ and $\\phi = \\frac{\\pi}{4}$.\n \n \\begin{figure}[h]\n \\centering\n\\includegraphics[scale=0.4,keepaspectratio=true]{./img/graph02.png}\n \\caption{Position, Velocity and Acceleration plots for \n$\\vec{r}(t) = ( \\cos (\\omega t - \\phi), \\sin (\\omega t - \\phi))$\n}\n \\label{fig: vector 2}\n\\end{figure}\n\n\n% ----------------------\n\n\n\\subsection{$\\vec{r}(t) = ( c \\cos ^3 (t), c \\sin ^3 (t))$}\n\nApply the chain rule to obtain the derivatives of $\\vec{r}(t)$.\n\n \\begin{equation*}\n  \\vec{v}(t) = (- 3 c \\cos ^2 (t) \\sin (t), 3 c \\sin ^ 2 (t) \\cos (t))\n \\end{equation*}\n\n\n\\begin{equation*}\n \\left \\| \\vec{v}(t) \\right \\| = \\sqrt{ 9 c^2 \\cos ^4 (t) \\sin^2 (t) + 9 c^2 \n\\sin ^4 (t) \\cos ^2 (t)}\n\\end{equation*}\n\n \\begin{equation*}\n  \\vec{a}(t) = (- 3 c \\cos ^3 (t) - 6 c \\sin ^2 (t) \\cos (t), -3 c \\sin ^3 (t) \n+ 6 c \\cos ^2 (t) \\sin (t))\n \\end{equation*}\n \n All three vectors are plotted in figure \\ref{fig: vector 3} with $t \\in \n\\left [ 0, 2 \\pi \\right ] $, and $c = 1$.\n \n \\begin{figure}[h]\n \\centering\n\n\\includegraphics[scale=0.4,keepaspectratio=true]{./img/graph03.png}\n \\caption{Position, Velocity and Acceleration plots for \n$\\vec{r}(t) = ( c \\cos ^3 (t), and c \\sin ^3 (t))$.\n}\n \\label{fig: vector 3}\n\\end{figure}\n\n\n% ---------------------------\n\n\n\\subsection{$\\vec{r}(t) = ( c (t - \\sin t), c (1 - \\cos t))$}\n \n  \\begin{equation*}\n  \\vec{v}(t) = (c (1 - \\cos (t) ), c \\sin (t))\n \\end{equation*}\n\n\n\\begin{equation*}\n \\left \\| \\vec{v}(t) \\right \\| = \\sqrt{ c^2 - c^2 \\cos ^2 (t) + c^2 \\sin ^2 (t)}\n\\end{equation*}\n\n \\begin{equation*}\n  \\vec{a}(t) = (c \\sin (t), c \\cos (t))\n \\end{equation*}\n \n Figure \\ref{fig: vector 4} shows the plots for all three equations evaluated \nwith $c = 1$ and $t \\in \n\\left [ 0, 2 \\pi \\right ] $.\n \n \\begin{figure}[h]\n \\centering\n\n\\includegraphics[scale=0.4,keepaspectratio=true]{./img/graph04.png}\n \\caption{Position, Velocity and Acceleration plots for \n$\\vec{r}(t) = ( c (t - \\sin t), c (1 - \\cos t))$\n}\n \\label{fig: vector 4}\n\\end{figure}\n \n\\end{document}\n", "meta": {"hexsha": "419fec1971f3040c66e9ca397e1fb3e677f54f5b", "size": 4980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture2/lecture2.tex", "max_stars_repo_name": "der-coder/CINVESTAV-System-Modeling-2019", "max_stars_repo_head_hexsha": "9345444113885181560940b3b4467c9555b8a85a", "max_stars_repo_licenses": ["MIT"], "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/lecture2.tex", "max_issues_repo_name": "der-coder/CINVESTAV-System-Modeling-2019", "max_issues_repo_head_hexsha": "9345444113885181560940b3b4467c9555b8a85a", "max_issues_repo_licenses": ["MIT"], "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/lecture2.tex", "max_forks_repo_name": "der-coder/CINVESTAV-System-Modeling-2019", "max_forks_repo_head_hexsha": "9345444113885181560940b3b4467c9555b8a85a", "max_forks_repo_licenses": ["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.0251256281, "max_line_length": 80, "alphanum_fraction": 0.5957831325, "num_tokens": 1845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.612850235672055}}
{"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*{maha.m} \n\n\\begin{par}\n\\textbf{Summary:} Point-wise squared Mahalanobis distance (a-b)*Q*(a-b)'. Vectors are row-vectors\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}  function K = maha(a, b, Q)\\end{verbatim}\n    \\begin{par}\n\\textbf{Input arguments:}\n\\end{par} \\vspace{1em}\n\\begin{verbatim}a   matrix containing n row vectors                                 [n x D]\nb   matrix containing n row vectors                                 [n x D]\nQ   weight matrix. Default: eye(D)                                  [D x D]\\end{verbatim}\n\\begin{par}\n\\textbf{Output arguments:}  K    point-wise squared distances                                    [n x n]\n\\end{par} \\vspace{1em}\n\\begin{par}\nCopyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.\n\\end{par} \\vspace{1em}\n\\begin{par}\nLast modified: 2013-03-21\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\nfunction K = maha(a, b, Q)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\nif nargin == 2                                                  % assume unit Q\n  K = bsxfun(@plus,sum(a.*a,2),sum(b.*b,2)')-2*a*b';\nelse\n  aQ = a*Q; K = bsxfun(@plus,sum(aQ.*a,2),sum(b*Q.*b,2)')-2*aQ*b';\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "98fafe506536b35887dcaa98bef7827116309aeb", "size": 1346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/maha.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/maha.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/maha.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": 28.0416666667, "max_line_length": 104, "alphanum_fraction": 0.587667162, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256631249076, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6128284199821042}}
{"text": "\\chapter{Homomorphisms and quotient groups}\n\\section{Generators and group presentations}\n\\prototype{$D_{2n} = \\left< r,s \\mid r^n=s^2=1\\right>$}\n\nLet $G$ be a group.\nRecall that for some element $x \\in G$,\nwe could consider the subgroup\n\\[ \\left\\{ \\dots, x^{-2}, x^{-1}, 1, x, x^2, \\dots \\right\\} \\]\nof $G$.\nHere's a more pictorial version of what we did:\n\\textbf{put $x$ in a box, seal it tightly, and shake vigorously}.\nUsing just the element $x$,\nwe get a pretty explosion that produces the subgroup above.\n\nWhat happens if we put two elements $x$, $y$ in the box?\nAmong the elements that get produced are things like\n\\[ xyxyx, \\quad x^2y^9x^{-5}y^3, \\quad y^{-2015}, \\quad \\dots\\]\nEssentially, I can create any finite product of $x$, $y$, $x\\inv$, $y\\inv$.\nThis leads us to define:\n\\begin{definition}\n\tLet $S$ be a subset of $G$.\n\tThe subgroup \\vocab{generated} by $S$,\n\tdenoted $\\left<S\\right>$,\n\tis the set of elements which can be written as a\n\tfinite product of elements in $S$ (and their inverses).\n\tIf $\\left<S\\right> = G$ then we say $S$ is a set of\n\t\\vocab{generators} for $G$,\n\tas the elements of $S$ together create all of $G$.\n\\end{definition}\n\\begin{exercise}\n\tWhy is the condition ``and their inverses''\n\tnot necessary if $G$ is  a finite group?\n\t(As usual, assume Lagrange's theorem.)\n\\end{exercise}\n\n\\begin{example}[$\\ZZ$ is the infinite cyclic group]\n\tConsider $1$ as an element of $\\ZZ = (\\ZZ, +)$.\n\tWe see $\\left<1\\right> = \\ZZ$, meaning $\\{1\\}$ generates $\\ZZ$.\n\tIt's important that $-1$, the inverse of $1$ is also allowed:\n\twe need it to write all integers as the sum of $1$ and $-1$.\n\\end{example}\n\nThis gives us an idea for a way to try and express groups compactly.\nWhy not just write down a list of generators for the groups?\nFor example, we could write\n\\[ \\ZZ \\cong \\left< a \\right> \\]\nmeaning that $\\ZZ$ is just the group generated by one element.\n\nThere's one issue: the generators usually satisfy certain properties.\nFor example, consider $\\Zc{100}$.\nIt's also generated by a single element $x$,\nbut this $x$ has the additional property that $x^{100} = 1$.\nThis motivates us to write\n\\[ \\Zc{100} = \\left< x \\mid x^{100} = 1 \\right>. \\]\nI'm sure you can see where this is going.\nAll we have to do is specify a set of generators and\n\\vocab{relations} between the generators,\nand say that two elements are equal if and only if\nyou can get from one to the other using relations.\nSuch an expression is appropriately called a \\vocab{group presentation}.\n\n\\begin{example}[Dihedral group]\n\tThe dihedral group of order $2n$ has a presentation\n\t\\[ D_{2n} = \\left< r, s\n\t\t\\mid r^n = s^2 = 1, rs = sr\\inv \\right>. \\]\n\tThus each element of $D_{2n}$ can be written uniquely in the form $r^\\alpha$\n\tor $sr^\\alpha$, where $\\alpha = 0, 1, \\dots, n-1$.\n\\end{example}\n\n\\begin{example}[Klein four group]\n\tThe \\vocab{Klein four group},\n\tisomorphic to $\\Zc2 \\times \\Zc2$, is given by the presentation\n\t\\[ \\left< a,b \\mid a^2=b^2=1, ab=ba \\right>. \\]\n\\end{example}\n\n\\begin{example}\n\t[Free group]\n\tThe \\vocab{free group on $n$ elements} is the group\n\twhose presentation has $n$ generators and no relations at all.\n\tIt is denoted $F_n$, so\n\t\\[\n\t\tF_n = \\left< x_1, x_2, \\dots, x_n \\right>.\n\t\\]\n\tIn other words, $F_2 = \\left<a,b\\right>$ is the set of strings\n\tformed by appending finitely many copies of $a$, $b$, $a\\inv$, $b\\inv$ together.\n\\end{example}\n\\begin{ques}\n\tNotice that $F_1 \\cong \\ZZ$.\n\\end{ques}\n\\begin{abuse}\n\tOne might unfortunately notice that ``subgroup generated by $a$ and $b$''\n\thas exactly the same notation as the free group $\\left<a,b\\right>$.\n\tWe'll try to be clear based on context which one we mean.\n\\end{abuse}\n\nPresentations are nice because they provide a compact way to write down groups.\nThey do have some shortcomings, though.\\footnote{%\nActually, determining whether two elements of a presentation are equal is undecidable.\nIn fact, it is undecidable to even determine if a group is finite from its presentation.}\n\n\\begin{example}\n\t[Presentations can look very different]\n\tThe same group can have very different presentations.\n\tFor instance consider\n\t\\[ D_{2n} = \\left< x,y \\mid x^2=y^2=1, (xy)^n=1. \\right>. \\]\n\t(To see why this is equivalent, set $x=s$, $y=rs$.)\n\\end{example}\n\n\\section{Homomorphisms}\n\\prototype{The ``mod out by $100$'' map, $\\ZZ \\to \\Zc{100}$.}\n\nHow can groups talk to each other?\n\nTwo groups are ``the same'' if we can write an isomorphism between them.\nAnd as we saw, two metric spaces are ``the same''\nif we can write a homeomorphism between them.\nBut what's the group analogy of a continuous map?\nWe simply drop the ``bijection'' condition.\n\n\\begin{definition}\n\tLet $G = (G, \\star)$ and $H = (H, \\ast)$ be groups.\n\tA \\vocab{group homomorphism} is a map $\\phi : G \\to H$\n\tsuch that for any $g_1, g_2 \\in G$ we have\n\t\\[ \\phi(g_1 \\star g_2) = \\phi(g_1) \\ast \\phi(g_2). \\]\n\\end{definition}\n\n\\begin{example}\n\t[Examples of homomorphisms]\n\tLet $G$ and $H$ be groups.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Any isomorphism $G \\to H$ is a homomorphism.\n\t\tIn particular, the identity map $G \\to G$ is a homomorphism.\n\t\t\\ii The \\vocab{trivial homomorphism} $G \\to H$ sends\n\t\teverything to $1_H$.\n\t\t\\ii There is a homomorphism from $\\ZZ$ to $\\Zc{100}$ by\n\t\tsending each integer to its residue modulo $100$.\n\t\t\\ii There is a homomorphism from $\\ZZ$ to itself by $x \\mapsto 10x$\n\t\twhich is injective but not surjective.\n\t\t\\ii There is a homomorphism from $S_n$ to $S_{n+1}$ by ``embedding'':\n\t\tevery permutation on $\\{1,\\dots,n\\}$ can be thought of as a permutation\n\t\ton $\\{1,\\dots,n+1\\}$ if we simply let $n+1$ be a fixed point.\n\t\t\\ii A homomorphism $\\phi: D_{12} \\to D_6$\n\t\tis given by $s_{12} \\mapsto s_6$\n\t\tand $r_{12} \\mapsto r_6$.\n\t\t\\ii Specifying a homomorphism $\\ZZ \\to G$ is the same as\n\t\tspecifying just the image of the element $1 \\in \\ZZ$. Why?\n\t\\end{enumerate}\n\\end{example}\nThe last two examples illustrates something: suppose we have a presentation of $G$.\nTo specify a homomorphism $G \\to H$, we only have to specify where each generator of $G$ goes, in such a way that the relations are all satisfied.\n\nImportant remark:\nthe right way to think about an isomorphism is as a ``bijective homomorphism''.\nTo be explicit,\n\\begin{exercise}\n\tShow that $G \\cong H$ if and only if there exist\n\thomomorphisms $\\phi \\colon G \\to H$ and $\\psi \\colon H \\to G$\n\tsuch that $\\phi \\circ \\psi = \\id_H$ and $\\psi \\circ \\phi = \\id_G$.\n\\end{exercise}\nSo the definitions of homeomorphism of metric spaces\nand isomorphism of groups are not too different.\n\nSome obvious properties of homomorphisms follow.\n\\begin{fact}\n\tLet $\\phi \\colon G \\to H$ be a homomorphism.\n\tThen $\\phi(1_G) = 1_H$ and $\\phi(g\\inv) = \\phi(g)\\inv$.\n\\end{fact}\n\\begin{proof}\n\tBoring, and I'm sure you could do it yourself if you wanted to.\n\\end{proof}\n\nNow let me define a very important property of a homomorphism.\n\\begin{definition}\n\tThe \\vocab{kernel} of a homomorphism $\\phi \\colon G \\to H$ is defined by\n\t\\[ \\ker \\phi \\defeq\n\t\t\\left\\{ g \\in G : \\phi(g) = 1_H \\right\\}.\n\t\t\\]\n\tIt is a \\emph{subgroup} of $G$\n\t(in particular, $1_G \\in \\ker \\phi$ for obvious reasons).\n\\end{definition}\n\\begin{ques}\n\tVerify that $\\ker\\phi$ is in fact a subgroup of $G$.\n\\end{ques}\nWe also have the following important fact, which we also encourage the reader to verify.\n\\begin{proposition}\n\t[Kernel determines injectivity]\n\tThe map $\\phi$ is injective if and only if $\\ker\\phi = \\{1_G\\}$.\n\\end{proposition}\n\nTo make this concrete, let's compute the kernel of each of our examples.\n\\begin{example}\n\t[Examples of kernels]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The kernel of any isomorphism $G \\to H$ is trivial,\n\t\tsince an isomorphism is injective.\n\t\tIn particular, the kernel of the identity map $G \\to G$ is $\\{1_G\\}$.\n\t\t\\ii The kernel of the trivial homomorphism $G \\to H$\n\t\t(by $g \\mapsto 1_H$) is all of $G$.\n\t\t\\ii The kernel of the homomorphism $\\ZZ \\to \\Zc{100}$ by $n \\mapsto \\ol n$\n\t\tis precisely \\[ 100\\ZZ = \\{\\dots, -200, -100, 0, 100, 200, \\dots \\}. \\]\n\t\t\\ii The kernel of the map $\\ZZ \\to \\ZZ$ by $x \\mapsto 10x$ is trivial: $\\{0\\}$.\n\t\t\\ii There is a homomorphism from $S_n$ to $S_{n+1}$ by ``embedding'',\n\t\tbut it also has trivial kernel because it is injective.\n\t\t\\ii A homomorphism $\\phi\\colon D_{12} \\to D_6$\n\t\tis given by $s_{12} \\mapsto s_6$ and $r_{12} \\mapsto r_6$.\n\t\tYou can check that\n\t\t\\[ \\ker \\phi = \\left\\{ 1, r_{12}^{3} \\right\\} \\cong \\Zc2. \\]\n\t\t\\ii Exercise below.\n\t\\end{enumerate}\n\\end{example}\n\\begin{exercise}\n\tFix any $g \\in G$.\n\tSuppose we have a homomorphism $\\ZZ \\to G$ by $n \\mapsto g^n$.\n\tWhat is the kernel?\n\\end{exercise}\n\n\\begin{ques}\n\tShow that for any homomorphism $\\phi: G \\to H$,\n\tthe image $\\phi\\im(G)$ is a subgroup of $H$.\n\tHence, we'll be especially interested in the case where $\\phi$ is surjective.\n\\end{ques}\n\n\\section{Cosets and modding out}\n\\prototype{Modding out by $n$: $\\ZZ / (n \\cdot \\ZZ) \\cong \\Zc n$.}\n\\emph{The next few sections are a bit dense.\nIf this exposition doesn't work for you, try \\cite{ref:gowers}.}\n\nLet $G$ and $Q$ be groups, and suppose there exists\na \\emph{surjective} homomorphism \\[ \\phi : G \\surjto Q. \\]\nIn other words, if $\\phi$ is injective then $\\phi : G \\to Q$ is a bijection,\nand hence an isomorphism.\nBut suppose we're not so lucky and $\\ker\\phi$ is bigger than just $\\{1_G\\}$.\nWhat is the correct interpretation of a more general homomorphism?\n\nLet's look at the special case where $\\phi : \\ZZ \\to \\Zc{100}$ is ``modding out by $100$''.\nWe already saw that the kernel of this map is\n\\[ \n\t\\ker \\phi = 100\\ZZ = \\left\\{ \\dots, -200, -100, 0, 100, 200, \\dots  \\right\\}.\n\\]\nRecall now that $\\ker \\phi$ is a subgroup of $G$.\nWhat this means is that \\textbf{$\\phi$ is indifferent to the subgroup $100\\ZZ$ of $\\ZZ$}:\n\\[ \\phi(15) = \\phi(2000 + 15) = \\phi(-300 + 15) = \\phi(700 + 15) = \\dots. \\]\nSo $\\Zc{100}$ is what we get when we ``mod out by $100$''. Cool.\n\nIn other words, let $G$ be a group and $\\phi : G \\surjto Q$\nbe a surjective homomorphism with kernel $N \\subseteq G$.\n\\begin{moral}\n\tWe claim that $Q$ should be thought of as the quotient of $G$ by $N$.\n\\end{moral}\nTo formalize this, we will define a so-called\n\\vocab{quotient group} $G/N$\nin terms of $G$ and $N$ only (without referencing $Q$)\nwhich will be naturally isomorphic to $Q$.\n\nFor motivation, let's give a concrete description of $Q$ using just $\\phi$ and $G$.\nContinuing our previous example, let $N = 100\\ZZ$ be our subgroup of $G$.\nConsider the sets\n\\begin{align*}\n\tN &= \\left\\{ \\dots, -200, -100, 0, 100, 200, \\dots \\right\\} \\\\\n\t1+N &= \\left\\{ \\dots, -199, -99, 1, 101, 201, \\dots \\right\\} \\\\\n\t2+N &= \\left\\{ \\dots, -198, -98, 2, 102, 202, \\dots \\right\\} \\\\\n\t&\\vdots \\\\\n\t99+N &= \\left\\{ \\dots, -101, -1, 99, 199, 299, \\dots \\right\\}.\n\\end{align*}\nThe elements of each set all have the same image when we apply $\\phi$,\nand moreover any two elements in different sets have different images.\nThen the main idea is to notice that\n\\begin{moral}\n\tWe can think of $Q$ as the group\n\twhose \\emph{elements} are the \\emph{sets} above.\n\\end{moral}\n\nThus, given $\\phi$ we define an equivalence relation $\\sim_N$\non $G$ by saying $x \\sim_N y$ for $\\phi(x) = \\phi(y)$.\nThis $\\sim_N$ divides $G$ into several equivalence classes in $G$\nwhich are in obvious bijection with $Q$, as above.\nNow we claim that we can write these equivalence classes very explicitly.\n\n% Also, for each $g \\in G$ define $\\ol g$ to be the equivalence class of $g$ under $\\sim_\\phi$.\n\\begin{exercise}\n\tShow that $x \\sim_N y$ if and only if $x = yn$ for some $n \\in N$\n\t(in the mod $100$ example, this means they ``differ by some multiple of $100$'').\n\tThus for any $g \\in G$, the equivalence class of $\\sim_N$ which contains $g$\n\tis given explicitly by \\[ gN \\defeq \\left\\{ gn \\mid n \\in N \\right\\}. \\]\n\\end{exercise}\n%Note that\n%\\[ \\phi(x) = \\phi(y)\n%\t\\implies 1_Q = \\phi(x)\\phi(y)\\inv = \\phi(xy\\inv)\n%\t\\implies xy\\inv \\in \\ker\\phi. \\]\n%Hence another way to describe $\\ol x$ is\n%\\[ \\ol g = gN = \\left\\{ gn \\mid n \\in N \\right\\}. \\]\n\nHere's the word that describes the types of sets we're running into now.\n\\begin{definition}\n\tLet $H$ be any subgroup of $G$ (not necessarily the kernel of some homomorphism).\n\tA set of the form $gH$ is called a \\vocab{left coset} of $H$.\n\\end{definition}\n\\begin{remark}\n\tAlthough the notation might not suggest it,\n\tkeep in mind that $g_1N$ is often equal to $g_2N$ even if $g_1 \\neq g_2$.\n\tIn the ``mod $100$'' example, $3+N = 103+N$.\n\tIn other words, these cosets are \\emph{sets}.\n\n\tThis means that if I write ``let $gH$ be a coset'' without telling you what $g$ is,\n\tyou can't figure out which $g$ I chose from just the coset itself.\n\tIf you don't believe me, here's an example of what I mean:\n\t\\[ x+100\\ZZ = \\left\\{ \\dots, -97, 3, 103, 203, \\dots \\right\\} \\implies x = {?}. \\]\n\tThere's no reason to think I picked $x=3$. (I actually picked $x=-13597$.)\n\t\\label{remark:coset_warning}\n\\end{remark}\n\\begin{remark}\n\tGiven cosets $g_1H$ and $g_2H$,\n\tyou can check that the map $x \\mapsto g_2g_1\\inv x$ is a bijection between them.\n\tSo actually, all cosets have the same cardinality.\n\\end{remark}\n\nSo, long story short,\n\\begin{moral}\n\tElements of the group $Q$ are naturally identified with left cosets of $N$.\n\\end{moral}\nIn practice, people often still prefer to picture elements of $Q$ as single points\n(for example it's easier to think of $\\Zc2$ as $\\{0,1\\}$\nrather than $\\big\\{ \\{\\dots,-2,0,2,\\dots\\}, \\{\\dots,-1,1,3,\\dots\\} \\big\\}$).\nIf you like this picture,\nthen you might then draw $G$ as a bunch of equally tall fibers (the cosets),\nwhich are then ``collapsed'' onto $Q$.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(9cm);\n\t\tfor (int i=1; i<=6; ++i) {\n\t\t\tdraw( (i,0)--(i,3.4) );\n\t\t\tdot( (i,0.6) );\n\t\t\tdot( (i,1) );\n\t\t\tdot( (i,1.7) );\n\t\t\tdot( (i,2.4) );\n\t\t\tdot( (i,2.8) );\n\t\t\tdot( (i,3) );\n\t\t\tlabel(rotate(90)*scale(1.4)*\"$\\Longleftarrow$\", (i+0.02,-0.9), dir(90));\n\t\t\tdot( (i,-1) );\n\t\t}\n\t\tlabel(\"$G$\", (0.5, 3));\n\t\tlabel(\"$Q$\", (0.5,-1));\n\t\\end{asy}\n\\end{center}\n\nNow that we've done this, we can give an \\emph{intrinsic}\ndefinition for the quotient group we alluded to earlier.\n\\begin{definition}\n\tA subgroup $N$ of $G$ is called \\vocab{normal} if it is the\n\tkernel of some homomorphism.\n\tWe write this as $N \\normalin G$.\n\\end{definition}\n\\begin{definition}\n\tLet $N \\normalin G$.\n\tThen the \\vocab{quotient group}, denoted $G/N$\n\t(and read ``$G$ mod $N$''),\n\tis the group defined as follows.\n\t\\begin{itemize}\n\t\t\\ii The elements of $G/N$ will be the left cosets of $N$.\n\t\t\\ii We want to define the product of two cosets $C_1$ and $C_2$ in $G/N$.\n\t\tRecall that the cosets are in bijection with elements of $Q$.\n\t\tSo let $q_1$ be the value associated to the coset $C_1$,\n\t\tand $q_2$ the one for $C_2$.\n\t\tThen we can take the product to be the coset corresponding to $q_1q_2$.\n\n\t\tQuite importantly,\n\t\t\\textbf{we can also do this in terms of representatives of the cosets}.\n\t\tLet $g_1 \\in C_1$ and $g_2 \\in C_2$,\n\t\tso $C_1 = g_1N$ and $C_2 = g_2N$.\n\t\tThen $C_1 \\cdot C_2$ should be the coset which contains $g_1g_2$.\n\t\tThis is the same as the above definition since\n\t\t$\\phi(g_1g_2) = \\phi(g_1)\\phi(g_2) = q_1q_2$;\n\t\tall we've done is define the product in terms of elements of $G$,\n\t\trather than values in $H$.\n\n\t\tUsing the $gN$ notation,\n\t\tand with \\Cref{remark:coset_warning} in mind,\n\t\twe can write this even more succinctly:\n\t\t\\[ (g_1N) \\cdot (g_2N) \\defeq (g_1g_2)N. \\]\n\t\\end{itemize}\n\\end{definition}\nAnd now you know why the integers modulo $n$ are often written $\\ZZ/n\\ZZ$!\n\\begin{ques}\n\tTake a moment to digest the above definition.\n\\end{ques}\nBy the way we've built it, the resulting group $G/N$ is isomorphic to $Q$.\nIn a sense we think of $G/N$ as ``$G$ modulo the condition that $n=1$\nfor all $n \\in N$''.\n\n\\section{(Optional) Proof of Lagrange's theorem}\nAs an aside, with the language of cosets\nwe can now show Lagrange's theorem in the general case.\n\\begin{theorem}\n\t[Lagrange's theorem]\n\t\\label{thm:lagrange_grp}\n\tLet $G$ be a finite group, and let $H$ be any subgroup.\n\tThen $\\left\\lvert H \\right\\rvert$ divides $\\left\\lvert G \\right\\rvert$.\n\\end{theorem}\n\nThe proof is very simple: note that the cosets of $H$\nall have the same size and form a partition of $G$\n(even when $H$ is not necessarily normal).\nHence if $n$ is the number of cosets,\nthen $n \\cdot \\left\\lvert H \\right\\rvert = \\left\\lvert G \\right\\rvert$.\n\n\\begin{ques}\n\tConclude that $x^{\\left\\lvert G \\right\\rvert}=1$\n\tby taking $H = \\left<x\\right> \\subseteq G$.\n\\end{ques}\n\n\\begin{remark}\n\tIt should be mentioned at this point that\n\tin general, if $G$ is a finite group and $N$ is normal,\n\tthen $|G/N| = |G| / |N|$.\n\\end{remark}\n\n\\section{Eliminating the homomorphism}\n\\prototype{Again $\\ZZ/n\\ZZ \\cong \\Zc n$.}\nLet's look at the last definition of $G/N$ we provided.\nThe short version is:\n\\begin{itemize}\n\t\\ii The elements of $G/N$ are cosets $gN$, which you can think\n\tof as equivalence classes of a relation $\\sim_N$\n\t(where $g_1 \\sim_N g_2$ if $g_1 = g_2n$ for some $n \\in N$).\n\t\\ii Given cosets $g_1N$ and $g_2N$ the group operation is \n\t\\[ g_1N \\cdot g_2N \\defeq (g_1g_2)N. \\]\n\\end{itemize}\nQuestion: where do we actually use the fact that $N$ is normal?\nWe don't talk about $\\phi$ or $Q$ anywhere in this definition.\n\nThe answer is in \\Cref{remark:coset_warning}.\nThe group operation takes in two cosets,\nso it doesn't know what $g_1$ and $g_2$ are.\nBut behind the scenes,\n\\textbf{the normal condition guarantees that the group operation can pick\nany $g_1$ and $g_2$ it wants and still end up with the same coset.}\nIf we didn't have this property, then it would be hard to define the\nproduct of two cosets $C_1$ and $C_2$ because it might make a difference\nwhich $g_1 \\in C_1$ and $g_2 \\in C_2$ we picked.\nThe fact that $N$ came from a homomorphism meant we could pick any representatives\n$g_1$ and $g_2$ of the cosets we wanted, because they all had the same $\\phi$-value.\n\nWe want some conditions which force this to be true without referencing $\\phi$ at all.\nSuppose $\\phi \\colon G \\to K$ is a homomorphism of groups with $H = \\ker\\phi$.\nAside from the fact $H$ is a group, we can get an ``obvious'' property:\n\\begin{ques}\n\tShow that if $h \\in H$, $g \\in G$,\n\tthen $ghg\\inv \\in H$.\n\t(Check $\\phi(ghg\\inv) = 1_K$.)\n\\end{ques}\n\\begin{example}[Example of a non-normal subgroup]\n\t\\label{ex:dihedral_normal_subgroup}\n\tLet $D_{12} = \\left<r,s \\mid r^6=s^2=1, rs=sr\\inv\\right>$.\n\tConsider the subgroup of order two $H = \\{1,s\\}$\n\tand notice that \\[ rsr\\inv = r(sr\\inv)= r(rs) = r^2s \\notin H. \\]\n\tHence $H$ is not normal, and cannot be the kernel of any homomorphism.\n\\end{example}\nWell, duh -- so what?\nAmazingly it turns out that that this is the \\emph{sufficient} condition we want.\nSpecifically, it makes the nice ``coset multiplication'' we wanted work out.\n\\begin{remark}\n\t[For math contest enthusiasts]\n\tThis coincidence is really a lot like functional equations at the IMO.\n\tWe all know that normal subgroups $H$ satisfy $ghg\\inv \\in H$;\n\tthe surprise is that from the latter seemingly weaker condition,\n\twe can deduce $H$ is normal.\n\\end{remark}\n\nThus we have a new criterion for ``normal'' subgroups which does not\nmake any external references to $\\phi$.\n\\begin{theorem}[Algebraic condition for normal subgroups]\n\tLet $H$ be a subgroup of $G$.\n\tThen the following are equivalent:\n\t\\begin{itemize}\n\t\t\\ii $H \\normalin G$.\n\t\t\\ii For every $g \\in G$ and $h \\in H$, $ghg\\inv \\in H$.\n\t\\end{itemize}\n\\end{theorem}\n\\begin{proof}\n\tWe already showed one direction.\n\n\tFor the other direction, we need to build a homomorphism with kernel $H$.\n\tSo we simply \\emph{define} the group $G/H$ as the cosets.\n\tTo put a group operation, we need to verify:\n\t\\begin{claim}\n\t\tIf $g_1' \\sim_H g_1$ and $g_2' \\sim_H g_2$ then $g_1'g_2' \\sim_H g_1g_2$.\n\t\\end{claim}\n\t\\begin{subproof}\n\t\tBoring algebraic manipulation (again functional equation style).\n\t\tLet $g_1' = g_1h_1$ and $g_2' = g_2h_2$, so we want to show that\n\t\t$g_1h_1g_2h_2 \\sim_H g_1g_2$.\n\t\tSince $H$ has the property, $g_2\\inv h_1g_2$ is some element of $H$, say $h_3$.\n\t\tThus $h_1 g_2 = g_2 h_3$, and the left-hand side becomes $g_1g_2(h_3h_2)$,\n\t\twhich is fine since $h_3h_2 \\in H$.\n\t\\end{subproof}\n\tWith that settled we can just \\emph{define} the\n\tproduct of two cosets (of normal subgroups) by \\[ (g_1H) \\cdot (g_2H) = (g_1g_2)H. \\]\n\n\tThus the claim above shows that this multiplication is well-defined\n\t(this verification is the ``content'' of the theorem).\n\tSo $G/H$ is indeed a group!\n\tMoreover there is an obvious ``projection'' homomorphism\n\t$G \\to G/H$ (with kernel $H$), by $g \\mapsto gH$.\n\\end{proof}\n%Another way to write the condition is\n%\\[ H = gHg\\inv \\defeq \\left\\{ ghg\\inv \\mid h \\in H \\right\\}. \\]\n%You should take a moment to check that these definitions are equivalent.\n\n\\begin{example}[Modding out in the product group]\n\tConsider again the product group $G \\times H$.\n\tEarlier we identified a subgroup\n\t\\[ G' =  \\left\\{ (g, 1_H) \\mid g \\in G \\right\\} \\cong G. \\]\n\tYou can easily see that $G' \\normalin G \\times H$.\n\t(Easy calculation.)\n\n\tMoreover, just as the notation would imply, you can check that\n\t\\[ (G \\times H) / (G') \\cong H. \\]\n\tIndeed, we have $(g, h) \\sim_{G'} (1_G, h)$ for all $g \\in G$ and $h \\in H$.\n\\end{example}\n\\begin{example}[Another explicit computation]\n\tLet $\\phi: D_8 \\to \\Zc 4$ be defined by \\[ r \\mapsto \\ol 2, \\quad s \\mapsto \\ol 2. \\] \n\tThe kernel of this map is $N = \\{1,r^2,sr,sr^3\\}$.\n\n\tWe can do a quick computation of all the elements of $D_8$ to get\n\t\\[ \\phi(1) = \\phi(r^2) = \\phi(sr) = \\phi(sr^3) = \\ol 0 \n\t\\text{ and }\n\t \\phi(r) = \\phi(r^3) = \\phi(s) = \\phi(sr^2) = \\ol 2. \\]\n\tThe two relevant fibers are \\[ \\phi\\pre(\\ol 0) = 1N = r^2N = srN = sr^3N = \\{1,r^2,sr,sr^3\\} \\] and \n\t\\[ \\phi\\pre(\\ol 2) = rN = r^3N = sN = sr^2N = \\{r,r^3,s,sr^2\\}. \\]\n\tSo we see that $|D_8/N| = 2$ is a group of order two, or $\\Zc 2$.\n\tIndeed, the image of $\\phi$ is \\[ \\left\\{ \\ol 0, \\ol 2 \\right\\} \\cong \\Zc 2. \\]\n\\end{example}\n\n\\begin{ques}\n\tSuppose $G$ is abelian.\n\tWhy does it follow that any subgroup of $G$ is normal?\n\\end{ques}\n\n\nFinally here's some food for thought:\nsuppose one has a group presentation for a group $G$\nthat uses $n$ generators.\nCan you write it as a quotient of the form $F_n / N$,\nwhere $N$ is a normal subgroup of $F_n$?\n\n\\section{(Digression) The first isomorphism theorem}\nOne quick word about what other sources usually say.\n\nMost textbooks actually \\emph{define} normal using the $ghg\\inv \\in H$ property.\nThen they define $G/H$ for normal $H$ in the way I did above,\nusing the coset definition\n\\[ (g_1H) \\cdot (g_2H) = g_1g_2H. \\]\nUsing purely algebraic manipulations (like I did) this is well-defined,\nand so now you have this group $G/H$ or something.\nThe underlying homomorphism isn't mentioned at all,\nor is just mentioned in passing.\n\nI think this is incredibly dumb.\nThe normal condition looks like it gets pulled out of thin air\nand no one has any clue what's going on,\nbecause no one has any clue what a normal subgroup actually should look like.\n\nOther sources like to also write the so-called first isomorphism theorem.\\footnote{\n\tThere is a second and third isomorphism theorem.\n\tBut four years after learning about them,\n\tI \\emph{still} don't know what they are.\n\tSo I'm guessing they weren't very important.}\nIt goes like this.\n\\begin{theorem}\n\t[First isomorphism theorem]\n\tLet $\\phi : G \\to H$ be a homomorphism.\n\tThen $G / \\ker \\phi$ is isomorphic to $\\phi\\im(G)$.\n\\end{theorem}\nTo me, this is just a clumsier way of stating the same idea.\n\nAbout the only merit this claim has is that if $\\phi$ is injective,\nthen the image $\\phi\\im(G)$ is an \\emph{isomorphic copy}\nof $G$ inside the group $H$.\n(Try to see this directly!)\nThis is a pattern we'll often see in other branches of mathematics:\nwhenever we have an \\emph{injective structure-preserving map},\noften the image of this map will be some ``copy'' of $G$.\n(Here ``structure'' refers to the group multiplication,\nbut we'll see some more other examples of ``types of objects'' later!)\n\nIn that sense an injective homomorphism $\\phi : G \\injto H$\nis an \\emph{embedding} of $G$ into $H$.\n\n\\section\\problemhead\n\\begin{problem}\n\t[18.701 at MIT]\n\tDetermine all groups $G$ for which the map $\\phi : G \\to G$ defined by \n\t\\[ \\phi(g) = g^2 \\] is a homomorphism.\n\t\\begin{hint}\n\t\tWrite it out: $\\phi(ab) = \\phi(a)\\phi(b)$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tAbelian groups: $abab =a^2b^2 \\iff ab= ba$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tConsider the dihedral group $G = D_{10}$.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Is $H = \\left< r \\right>$ a normal subgroup of $G$?\n\t\tIf so, compute $G/H$ up to isomorphism.\n\t\t\\ii Is $H = \\left< s \\right>$ a normal subgroup of $G$?\n\t\tIf so, compute $G/H$ up to isomorphism.\n\t\\end{enumerate}\n\t\\begin{hint}\n\t\tYes, no.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tYes to (a): you can check this directly\n\t\tfrom the $ghg\\inv$ definition.\n\t\tFor example, for (a)\n\t\tit is enough to compute $(r^a s) r^n (r^a s)\\inv = r^{-n} \\in H$.\n\t\tThe quotient group is $\\Zc2$.\n\n\t\tThe answer is no for (b) by following\n\t\t\\Cref{ex:dihedral_normal_subgroup}.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tDoes $S_4$ have a normal subgroup of order $3$?\n\t\\begin{hint}\n\t\tNo.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tA subgroup of order $3$ must be generated by\n\t\tan element of order $3$, since $3$ is prime.\n\t\tSo we may assume WLOG that $H = \\left< (1\\; 2 \\; 3) \\right>$\n\t\t(by renaming elements appropriately).\n\t\tBut then let $g = (3 \\; 4)$; one can check $gHg\\inv \\ne H$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tLet $G$ and $H$ be finite groups, where $\\left\\lvert G \\right\\rvert = 1000$\n\tand $\\left\\lvert H \\right\\rvert = 999$.\n\tShow that a homomorphism $G \\to H$ must be trivial.\n\t\\begin{hint}\n\t\t$\\gcd(1000,999)=1$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\t$G/\\ker G$ is isomorphic to a subgroup of $H$.\n\t\tThe order of the former divides $1000$;\n\t\tthe order of the latter divides $999$.\n\t\tThis can only occur if $G / \\ker G = \\{1\\}$\n\t\tso $\\ker G = G$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tLet $\\CC^\\times$ denote the nonzero complex numbers under multiplication.\n\tShow that there are five homomorphisms $\\Zc5 \\to \\CC^\\times$\n\tbut only two homomorphisms $D_{10} \\to \\CC^\\times$,\n\teven though $\\Zc5$ is a subgroup of $D_{10}$.\n\\end{problem}\n\n\\begin{problem}\n\t\\gim\n\tFind a non-abelian group $G$\n\tsuch that every subgroup of $G$ is normal.\n\t(These groups are called \\vocab{Hamiltonian}.)\n\t\\begin{hint}\n\t\tFind an example of order $8$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tQuaternion group.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[PRIMES entrance exam, 2017]\n\t\\gim\n\tLet $G$ be a group with presentation given by\n\t\\[ G = \\left< a,b,c \\mid\n\t\tab = c^2a^4, \\; bc = ca^6, \\; ac = ca^8, \\;\n\t\tc^{2018} = b^{2019}\n\t\t\\right>. \\]\n\tDetermine the order of $G$.\n\t\\begin{hint}\n\t\tTry to show $G$ is the dihedral group of order $18$.\n\t\tThere is not much group theory content here --- just manipulation.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tThe answer is $|G| = 18$.\n\n\t\tFirst, observe that by induction we have\n\t\t\\[ a^n c = ca^{8n} \\]\n\t\tfor all $n \\ge 1$.\n\t\tWe then note that\n\t\t\\begin{align*}\n\t\t\ta(bc) &= (ab)c \\\\\n\t\t\ta \\cdot ca^6 &= c^2 a^4 \\cdot c \\\\\n\t\t\tc a^8 \\cdot a^6 &= c^2 a^4 \\cdot c \\\\\n\t\t\ta^{14} &= c(a^4c) = c^2 a^{32}.\n\t\t\\end{align*}\n\t\tHence we conclude $c^2 = a^{-18}$.\n\t\tThen $ab = c^2a^4 \\implies b = a^{-15}$.\n\n\t\tIn that case, if $c^{2018} = b^{2019}$,\n\t\twe conclude $1 = a^{2018 \\cdot 18 - 2019 \\cdot 15} = a^{6039}$.\n\t\tFinally, \n\t\t\\begin{align*}\n\t\t\tbc &= ca^6 \\\\\n\t\t\ta^{-15} c &= ca^6 \\\\\n\t\t\ta^{-15} c^2 &= c(a^6c) = c^2 a^{48} \\\\\n\t\t\ta^{-33} &= a^{30} \\\\\n\t\t\t\\implies a^{63} &= 1.\n\t\t\\end{align*}\n\t\tSince $\\gcd(6039, 63) = 9$, we find $a^9 = 1$, hence finally $c^2 = 1$.\n\t\tSo the presentation above simplifies to\n\t\t\\[ G = \\left< a,c \\mid a^9=c^2=1, \\; ac = ca^{-1} \\right> \\]\n\t\twhich is the presentation of the dihedral group of order $18$.\n\t\t% a = r, r^9 = 1\n\t\t% b = r^3\n\t\t% c = s, s^2 = 2\n\t\tThis completes the proof.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Homophony group]\n\t\\gim\n    The homophony group (of English) is the group\n\twith $26$ generators $a$, $b$, \\dots, $z$\n\tand one relation for every pair of English words\n\twhich sound the same.\n\tFor example $knight = night$ (and hence $k=1$).\n\tProve that the group is trivial.\n\t\\begin{hint}\n\t\tGet yourself a list of English homophones, I guess.\n\t\tDon't try too hard.\n\t\tLetter $v$ is the worst; maybe $felt = veldt$?\n\t\\end{hint}\n\t\\begin{sol}\n\t\tYou can find many solutions by searching ``homophone group'';\n\t\tone is \\url{https://math.stackexchange.com/q/843966/229197}.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "d267945bab0c56b1253348578d924fd8f50c1d73", "size": 28378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/quotient.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/H113/quotient.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/H113/quotient.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.0402144772, "max_line_length": 146, "alphanum_fraction": 0.6746775671, "num_tokens": 9771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754371026368, "lm_q2_score": 0.841825655188238, "lm_q1q2_score": 0.6128283992998712}}
{"text": "\\chapter{Multi-layer Multiple Kernel Learning}\n\\label{chap_mlmkl}\nIn this chapter we  discuss the Multi-layer Multiple Kernel Learning (ML-MKL\\nomenclature{ML-MKL}{Multi-layer Multiple Kernel Learning}) framework developed using an unsupervised MKL algorithm. The organization of this chapter is as follows;  section \\ref{sec_mkl} gives  the discussion of  traditional MKL algorithm  in a supervised learning settings, in section \\ref{sec_umkl} the unsupervised MKL formulation is introduced, in section \\ref{sec_rw} the related works in ML-MKL domain is discussed, in section \\ref{sec_mlmkl} the proposed ML-MKL algorithm is discussed along with the experimental results and section \\ref{sec_conc} concludes this chapter.\n\n\n\\section{Multiple Kernel Learning}\n\\label{sec_mkl}\nMultiple Kernel Learning(MKL\\nomenclature{MKL}{Multiple Kernel Learning}) aims at learning a convex combination of a set of predefined base kernels for choosing an optimum kernel(\\cite{mkl} et al.). The primary aim of MKL algorithm is to automate the process of choosing the optimum kernel  for the learning task.\n\n\nTypically multiple kernel learning is formulated in a supervised learning settings. Suppose we are given $n$ datapoints $\\mathcal{D} = \\{(x_1, y_1), (x_2, y_2), \\ldots, (x_n, y_n)\\}$, where $x_i \\in \\mathbb{R}^d$ is the $i^{th}$ input data vector and $y_i$ is the label of the class to which $x_i$ belongs to. Then the MKL learning task is formulated as the following optimization problem.\n\\begin{equation}\n\\min_{k \\in \\mathcal{K}} \\min_{f \\in \\mathcal{H}_k} \\lambda \\norm{f}^2_{\\mathcal{H}_k} + \\sum_{i=1}^n l(y_i, f(x_i))\n\\end{equation}\nwhere $l(\\cdot)$ denotes the loss function(commonly used loss function is the hinge loss, defined as $l(t) = \\max(0, 1-t)$), $\\mathcal{H}_k$ is the RKHS corresponding to the kernel $k$, $\\mathcal{K}$ denotes the optimization domain of the candidate kernels, and $\\lambda > 0$ is the regularization parameter.\n\nThe optimizaion domain $\\mathcal{K}$ is the convex combination of a set of predefined base kernels, defined as follows\n\\[ \\mathcal{K} = \\Bigg\\{ k( \\cdot \\textrm{ , } \\cdot ) = \\sum_{t=1}^m \\mu_t k_t(\\cdot \\textrm{ , } \\cdot) \\textrm{ : } \\sum_{t=1}^m \\mu_t = 1, \\mu_t \\geq 0 \\Bigg\\} \\]\nwhere $k_t$ is the $t^{th}$ base kernel and $\\mu_t$ is the weight associated to the $t^{th}$ base kernel. The decision function $f(x)$ can be computed as a linear combination of kernel evaluations on all training samples;\n\\[ f(x) = \\sum_{i=1}^n \\alpha_i k(x_i, x) \\]\nwhere $\\alpha_i$'s are the coefficients. As per the definition of kernel $k$ in MKL, the decision function of the conventional MKL is expressed as\n\\begin{equation*}\n\\begin{aligned}\nf(x) &= \\sum_{i=1}^n \\alpha_i \\sum_{t=1}^m \\mu_t k_t(x_i, x) \\\\\n&= \\sum_{i=1}^n \\sum_{t=1}^m \\alpha_i \\mu_t k_t(x_i, x)\n\\end{aligned}\n\\end{equation*}\nIn this basic formulation, the optimization task has to identify both the optimal kernel $k$ from the domain $\\mathcal{K}$ and the optimal decision function $f$ from the RKHS $\\mathcal{H}_k$ simultaneously. In order to eliminate this problem \\cite{corinna} et al. proposed a two stage kernel learning algorithm which separates the kernel learning task from the decision function learning.\n\n\n\\section{Unsupervised MKL}\n\\label{sec_umkl}\nIn the KPCA based feature extraction stages, we were using only one kernel for the task. With the intuition that by using multiple kernels at each layer we would get more similarity information, we computed a convex combination of multiple kernels following the work in \\cite{zhuang} et al. Since we are using kernels for unsupervised feature extraction, traditional MKLs following supervised paradigm cannot be used here.\n\nThe goal of an unsupervised multiple kernel learning task is to find an optimal linear combination of the $m$ kernel functions as, i.e, $k^*(\\cdot \\textrm{ , } \\cdot) \\in \\mathcal{K}$. %where $K$ is defined as follows:\n%\\[ K = \\Bigg\\{ k( \\cdot \\textrm{ , } \\cdot ) = \\sum_{t=1}^m \\mu_t k_t(\\cdot \\textrm{ , } \\cdot) \\textrm{ : } \\sum_{t=1}^m \\mu_t = 1, \\mu_t \\geq 0 \\Bigg\\} \\]  \n%here $k_t$'s are the base kernels. \nIn order to determine the optimality of a linear combination of kernels, we used the following quality criteria\\cite{zhuang} et al.:\n\n\\begin{itemize}\n\\item A  good kernel should enable each training instances to be well reconstructed from the localized bases weighted by the kernel values. Formulating this requirment mathematically, for each $x_i$ we expect the optimal kernel should minimize the approximation error $\\norm{x_i-\\sum_j k_{ij}x_j}^2$, where $k_{ij} = k(x_i, x_j)$.\n\\item A good kernel should induce kernel values that are coincided with the local geometry of the training data. This is equivalent to finding the optimal kernel that minimizes the distortion over all trainig data, computed as $\\sum_{i,j}k_{ij} \\norm{x_i-x_j}^2 $.\n\\end{itemize}\n\nIn addition to this, the locality preserving principle can be exploited  by using a set of local bases for each $x_i \\in X$ denoted as $B_i$. By fixing the size of the local bases to some constant $N_B$,  the optimization problem of unsupervised MKL can be formulated as follows.\n\\[ \\min_{k \\in \\mathcal{K}} \\frac{1}{2}\\sum_{i=1}^n \\norm{x_i - \\sum_{x_j \\in B_i} k_{ij}x_j}^2 + \\gamma* \\sum_{i=1}^n \\sum_{x_j \\in B_i} k_{ij} \\norm{x_i-x_j}^2 \\]\n\nwhere $\\gamma$ is a tuning parameter, which controls the tradeoff between the coding error and the locality distortion. Converting to matrix notations the above problem becomes\n\\begin{equation}\n  \\min_{\\mu \\in \\Delta,D} \\frac{1}{2} \\norm{X(I-K \\circ D)}_F^2 + \\gamma* \\textrm{ tr }K\\circ D\\circ M(11^T)\n  \\label{obj_mat} \n\\end{equation}\n%\\begin{equation*}\n % \\begin{aligned}\n\\[ \\textrm{subject to } D \\in \\{0,1\\}^{n \\times n} \\]\n\\[  \\norm{d_i}_1 = N_B, i=1,2,\\ldots,n \\]\n\\[ \\Delta = \\Big\\{\\mu : \\mu^T\\textbf{1} = 1, \\mu \\geq 0 \\Big\\} \\textrm{ and } \\]\n\\[ [K]_{i,j} = \\sum_{t=1}^m \\mu_t k^t(x_i, x_j), 1\\leq i,j \\leq n \\]\n  %\\end{aligned}\n%\\end{equation*}\n\nThe matrix $D \\in \\{0,1\\}^{n \\times n}$ contains information about local bases of each $x_i$ as a column vector. In particular, each column vector $d_i \\in \\{0, 1\\}^n $ in $D$ has a 1 at those points $j$ where, $x_j \\in B_i$ and zero elsewhere(or $B_i = \\{ x_j : d_j \\neq 0 \\} $). The matrix M is defined as\n\\[ [M]_{ij} = x_i^Tx_i + x_j^Tx_j - 2x_i^Tx_j \\]\n\nIn equation \\ref{obj_mat} the notation `$\\circ$' denotes elementwise multiplication of two matrices, $\\norm{\\cdot}_F^2$ denotes the Frobenius norm of a matrix and `tr' denotes the trace of a matrix.\n\nIn their implementation(\\cite{zhuang}) Zhuang et.al solved the optimization problem in two stages in an alternating fashion, first by solving for $\\mu$ with a fixed $D$ (using convex optimization) and then solving for $D$ by fixing $\\mu$ (using a greedy mixed integer programming formulation). Since we are using a many layer architecture, the alternating optimization strategy is too costly; so we chose to do the optimization across $\\mu$ only by choosing $D$ beforehand. Specifically, the matrix $D$ is computed beforehand by taking $k$ nearest neighbours of $x_i$ from the training set and putting a one in those positions for $d_i$. Rest of the positions are filled with zeros. The resulting optimization problem will be  \n\\begin{equation}\n  \\begin{aligned}\n  \\min_{\\mu \\in \\Delta} \\frac{1}{2} \\norm{X(I-K \\circ D)}_F^2 + \\gamma* \\textrm{ tr }K\\circ D\\circ M(11^T)\n  \\end{aligned}\n\\end{equation}\n\\[ \\textrm{subject to } D \\in \\{0,1\\}^{n \\times n}, \\norm{d_i}_1 = N_B, i=1,2,\\ldots,n \\]\n\\[ \\Delta = \\Big\\{\\mu : \\mu^T\\textbf{1} = 1, \\mu \\geq 0 \\Big\\} \\]\n\nThe objective function can be formulated as a convex quadratic programming problem w.r.t to kernel weights $\\mu$ as shown below(derivation of the objective function $J(\\mu)$ is shown in Appendix \\ref{derivation1}).\n\\begin{equation}\nJ(\\mu) = \\mu^T \\Bigg( \\sum_{t=1}^m \\sum_{i=1}^n k_{t,i}k_{t,i}^T \\circ d_i d_i^T \\circ P \\Bigg)^T \\mu + z^T \\mu \n\\end{equation}\nwhere $[z]_t = \\sum_{i=1}^n (2 \\gamma v_i \\circ d_i - 2 p_i \\circ d_i)^T \\mathit{k}_{t,i} $, $P = X^TX$, and $\\mathit{k}_{t,i} = \\Big[ k^t(x_i, x_1), \\ldots, k^t(x_i, x_n) \\Big]^T $ is the $i^{th}$ column of the $t^{th}$ kernel matrix. $p$ and $v$ are columns of $P$ and $M$ corresponding to $x_i$ respectively.\n\n\\section{Related Works}\n\\label{sec_rw}\n\n\\cite{2l_mkl} et al. explored the idea of ML-MKL, in which at each layer they took a non-linear combination of kernels in the previous layer, forming a layered structure. They called such a model as deep multiple kernel learning framework. The architecture of their model is shown in figure \\ref{fig_2l_mkl}. The kernel function obtained at layer $l$ is having the following domain.\n\\[ \\mathcal{K}^{(l)} = \\bigg\\{ k^{(l)}(\\cdot, \\cdot) = g^{(l)}\\Big( \\big[k_1^{(l-1)},\\ldots, k_m^{(l)}(\\cdot, \\cdot) \\big] \\Big)  \\bigg\\} \\]\n\n\\begin{figure*}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[width=1.1\\textwidth,height=8.5cm]{figures/2lmkl}\n  \\caption{Architecture of ML-MKL model proposed by \\cite{2l_mkl} et al.}\n  \\label{fig_2l_mkl}\n\\end{figure*}\n\nwhere $g^{(l)}$ is a function to combine multiple $(l-1)$ level kernels, which must ensure the resulting combination is a valid kernel. Though this combination can be applied for any number of layers, optimization problem is difficult to solve beyond two layers. Hence \\cite{2l_mkl} et al. considered only 2-layer MKL in their empirical study. \n\nIn the 2-layer MKL, \\cite{2l_mkl} et al. defined the kernel domain by using an RBF kernel for the combination function. \n\\[ \\mathcal{K}^{(2)} = \\bigg\\{ k^{(2)}(x_i, x_j;\\bm{\\mu}) = exp\\Big( \\sum_{t=1}^m \\mu_t k_t^{(1)}(x_i, x_j) \\Big)  \\bigg\\}  \\colon \\bm{\\mu} \\in \\mathbb{R}_+^m \\]\n$\\mu_t$ is the weight of the $t^{(th)}$ antecedent layer kernel $k_t^{(1)}$(superscript (1) is used here because the antecedent layer is layer 1 in a 2-layer architecture). In order to prevent the kernel weight being too large, the kernel weights are also introduced into the optimization objective as a regularization term. Then the optimization objective becomes\n\\begin{equation}\n\\min_{k \\in \\mathcal{K}} \\min_{f \\in \\mathcal{H}_k} \\norm{f}^2_{\\mathcal{H}_k} + \\mathcal{C} \\sum_{i=1}^n l(y_i, f(x_i)) + \\sum_{t=1}^m \\mu_t\n\\end{equation}\nsolving the Lagrangian, we will get the dual objective function as\n\\[ \\min_{\\bm{\\mu}} \\max_{\\bm{\\alpha}} \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\sum_{i,j=1}^n \\alpha_i \\alpha_j y_i y_j k^{(2)}(x_i, x_j;\\bm{\\mu}) + \\sum_{t=1}^m \\mu_t \\]\n\\[ \\textrm{s.t } 0\\leq \\alpha_i\\leq \\mathcal{C}, \\sum_{i=1}^n \\alpha_i y_i = 0, \\mu_t \\geq 0, t=1, \\ldots, m \\]\nwhere $\\alpha = [\\alpha_1, \\alpha_2, \\ldots, \\alpha_n]^T$ is a vector of dual variables and $\\mu = [\\mu_1, \\mu_2, \\ldots, \\mu_m]^T$. The final decision function of the 2-layer MKL is given as\n\\[f(x;\\bm{\\alpha}, \\bm{\\mu}) = \\sum_{i=1}^n \\alpha_i y_i k^{(2)}(x_i, x;\\bm{\\mu}) + b \\]\nwhere $b$ is the bias term. Rewriting the optimization objective in terms of $\\alpha$ and $\\mu$, we have\n\\[ \\mathcal{J}(\\alpha, \\mu) = \\frac{1}{2} \\sum_{i,j=1}^n \\alpha_i \\alpha_j y_i y_j k^{(2)}(x_i, x_j;\\bm{\\mu}) - \\sum_{i=1}^n \\alpha_i - \\sum_{t=1}^m \\mu_t \\]\nThe optimization problem is solved in two stages\n\\begin{itemize}\n\\item by fixing $\\mu$ and solve for $\\alpha$.\n\\item by fixing $\\alpha$ and solve for $\\mu$.\n\\end{itemize}\nSince $k^{(2)}$ is positive definite $\\mathcal{J}(\\alpha, \\mu)$ is convex over $\\alpha$, thus an SVM solver can be used to solve the optimization over $\\alpha$. The optimization over $\\mu$ is solved using gradient ascent. In order to address the challenge of choosing the optimal set of base kernels, they proposed to choose base kernels iteratively inside $k^{(2)}$.\n\n\\cite{deep_mkl} et al. used backpropagation algorithm for designing the ML-MKL framework. The architecture of the model studied by them is shown in figure \\ref{fig_deep_mkl}. They defined the kernel domain at level $l$ as\n\n\\begin{figure*}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[width=1\\textwidth,height=6cm]{figures/back_prop_mlmkl}\n  \\caption{Architecture of ML-MKL model proposed by \\cite{deep_mkl} et al. The kernels in each layer are linearly combined and the resulting Gram matrix is passed to the next layer as input.}\n  \\label{fig_deep_mkl}\n\\end{figure*}\n\n\\[ \\mathcal{K}^{(l)} = \\big\\{ K^{(l)}(K^{(l-1)}; \\mu^{(l)}) = \\sum_{t=1}^m \\mu_t^{(l)} k_t^{(l)}(K^{(l-1)})  \\big\\} \\]\n\\[ \\textrm{s.t } \\mu_t^{(l)} \\geq 0, l = 1, \\ldots, L \\]\nwhere $k_t^{(l)}$ is the $k^{th}$ base kernel at layer $l$ and $\\mu_t^{(l)}$ denotes the weight of the $k^{th}$ base kernel at layer $l$. $L$ is the total number of layers. The feature extracted in the antecedent layer are combined linearly and passed to the next layer as input. The kernel weights are obtained by minimizing the mean squre error(denotes as $\\mathcal{E}$) of the predicted outputs.\n\\[ \\mathcal{E} = \\frac{1}{2n} \\sum_{i=1}^n \\norm{f(x_i) - y_i}^2 \\]\nwhere $f(x_i)$ is the value of the decision function for the input $x_i$, which is computed as\n\\[ f(x) = \\sum_{i=1}^n \\alpha_i y_i K^{(l)}(K^{(l-1)}; \\mu^{(l)}) + b \\]\nwhere $b$ is the bias term. The weights $\\mu^{(l)}$ in each layer are obtained using gradient descent algoritm.\n\\[ \\mu^{(l)} := \\mu^{(l)} + \\eta \\nabla \\mathcal{E}  \\textrm{ } l = 1, \\ldots, L \\]\n\\[ \\nabla \\mathcal{E} = \\Bigg\\{ \\frac{\\partial \\mathcal{E}}{\\partial \\mu_1^{(1)}}, \\cdots, \\frac{\\partial \\mathcal{E}}{\\partial \\mu_m^{(1)}}; \\cdots; \\frac{\\partial \\mathcal{E}}{\\partial \\mu_1^{(L)}}, \\cdots, \\frac{\\partial \\mathcal{E}}{\\partial \\mu_m^{(L)}}  \\Bigg\\}  \\]\nHere $\\eta$ is the learning rate parameter. The error obtained in the final layer are propagated back to all layers using backpropagation algorithm to update the kernel weight parameters $\\mu^{(l)}$ in each layer.\n\n\\section{Multi-layer Multiple Kernel Learning}\n\\label{sec_mlmkl}\nThe architectue of the proposed ML-MKL framework is shown in figure \\ref{fig_mlmkl}. It consists of many layers and in each layer the kernel PCA based feature extraction is performed using the combination of a set of predefined kernels. The dimensionality of the features thus obtained are reduced by using supervised feature selection techniques. The final output can be given to any classifier. Algorithm \\ref{algo1} summarizes the proposed ML-MKL algorithm.\n\n\\begin{algorithm}\n\\caption{ML-MKL Algorithm}\n\\textbf{Input}: data X, true labels y, no. of layers L, base kernels for each layer $K_{base}^{(l)} = \\{k_1^{(l)}, k_2^{(l)}, k_m^{(l)}\\}$, $N_B$, $\\gamma$\\;\n\\textbf{Output}: kernel weights $\\mu^l$ for each layer, predicted labels\\;\n1.Initialize $[M]_{ij} = x_i^Tx_i + x_j^Tx_j - 2x_i^Tx_j$, $\\bm{D} = d_1, d_2, \\ldots, d_n$ as row vectors, where $d_i = \\{1 \\textrm{ if } x_j \\in B_i \\textrm{ else } 0 \\forall x_j \\in X \\}$, $\\mu = \\frac{1}{m}$, $\\bm{P} = X^TX$\\;\n2.\\For{each layer l}{\n    a. $\\bm{W} = \\sum_{t=1}^m \\sum_{i=1}^n k_{t,i}^{(l)}k_{t,i}^{(l)^{T}} \\circ d_i d_i^T \\circ P$\\\\\n    b. $\\bm{[z]}_t^l = \\sum_{i=1}^n (2 \\gamma v_i \\circ d_i - 2 p_i \\circ d_i)^T \\mathit{k}_{t,i}^{(l)}$\\\\\n    c. $\\bm{\\mu}^{*^{l}} = \\mu^{l^{T}}W\\mu^l + z^{l^{T}}\\mu^l$\\\\\n    d. $\\bm{K}_{new} = \\sum_{t=1}^m \\mu_t^l * K_t^{(l)}$\\\\\n    e. extract principal components with $\\bm{K}_{new}$\\\\\n    f. select most informative features for layer $l$($X_{new}$)\\\\\n    g. $\\bm{P} = X_{new} ^T X_{new}$\n}\n3.Give the final set of features to any classifier\\;\n\\label{algo1}\n\\end{algorithm}\n\n\\begin{figure*}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[width=1.0\\textwidth,height=5.5cm]{figures/mlmkm}\n  \\caption{An ML-MKL with L layers of transformations. Each layer consists of many kernels for feature  extraction using kernel PCA and a supervised feature selection module.}\n  \\label{fig_mlmkl}\n\\end{figure*}\n\nThe experimental setup used here was the same as described in \\autoref{chap_mkm}. Table \\ref{tab_mlmkl} lists the results obtained with the proposed ML-MKL framework. The classifier used was  SVM with arc-cosine kernel. For \\textit{mnist-back-rand} dataset, the best result was obtained with a model consists of 4 layers and in each layer 7 kernels were used. In particular, each layer consisted of a mixture of one arc-cosine kernel and 6 gaussian kernels. For \\textit{mnist-back-image} dataset, the best ML-MKL model obtained had 2 layers and 5 kernels in each layer. In each layer a mixture of one arc-cosine kernel and 4 polynomial kernels were used. In the case of \\textit{mnist-rot-back-image} dataset the best result was fetched by a model having only one layer with 4 arc-cosine kernels in it. For \\textit{rectangles-image} dataset the best result was shown by a one layer ML-MKL model with one arc-cosine kernel and 6 Gaussian kernels.\n\n\n\\renewcommand{\\arraystretch}{2.1}\n\\begin{table*}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Dataset}} & \\multicolumn{7}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-8}\n  &$\\textrm{SVM}_{\\textrm{RBF}}$ & $\\textrm{SVM}_{\\textrm{Poly}}$ & NNet & DBN-3 & SAA-3 & DBN-1 & \\textbf{ML-MKL}\\\\\n  \\hline  \n  \\textit{back-rand} & 14.58 & 16.62 & 20.04 & \\textbf{6.73} & 11.28 & 9.80 & 8.43$\\pm 0.088$\\\\\n  \\hline\n  \\textit{back-image} & 22.61 & 24.01 & 27.41 & 16.31 & 23.00 & \\textbf{16.15} & 20.92$\\pm 0.092$\\\\\n  \\hline\n  \\textit{rot-back-image} & 55.18 & 56.41 & 62.16 & \\textbf{47.39} & 51.93 & 52.21 & 51.21$\\pm 0.811$\\\\\n  \\hline\n  \\textit{rect-image} & 24.04 & 24.05 & 33.20 & 23.69 & 24.05 & \\textbf{22.50} & 22.88$\\pm 0.124$\\\\\n  \\hline\n\\end{tabular}\n\\caption{Experimental Results of ML-MKL.}\n\\label{tab_mlmkl}\n\\end{table*}\n\\renewcommand{\\arraystretch}{1}\n\nFigures \\ref{fig_mbr_layers} and \\ref{fig_mbi_layers} illustrates the variation in classifier performance on \\textit{mnist-back-rand} and \\textit{mnist-back-image} datasets respectively when layers were added iteratively to the ML-MKL model. The value shown for each layer was the best error rate obtained after tuning the kernel parameters. The parameters were chosen greedily for each layer (with the expectation that subsequent layers would learn more valuable features from the current one) and no fine-tuning was performed with respect to the entire architecture.\n\n\\begin{figure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.8]{figures/mlmkl_rand}\n  \\caption{Change in classifier performance on \\textit{mnist-back-rand} dataset when adding layers iteratively.}\n  \\label{fig_mbr_layers}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.8]{figures/mlmkl_image}\n  \\caption{Change in classifier performance on \\textit{mnist-back-image} dataset when adding layers iteratively.}\n  \\label{fig_mbi_layers}\n\\end{figure}\n\nFigure \\ref{tsne_rand_mlmkl} shows the tSNE embedding of the features learned by ML-MKL algorithm. The visualization indicates that classes are well separated.\n\n\\begin{sidewaysfigure}\n  \\centering\n  \\captionsetup{justification=centering,margin=0.1cm}\n  \\includegraphics[scale=0.45]{figures/tsne_rand_mlmklbest}\n  \\caption{tSNE embedding of features obtained by ML-MKL algorithm for the \\textit{mnist-back-rand} dataset.}\n  \\label{tsne_rand_mlmkl}\n\\end{sidewaysfigure}\n\nTables \\ref{back_rand_kw} and \\ref{back_image_kw} shows the kernel weights of each kernel in the mixture at every layer for \\textit{mnist-back-rand} and \\textit{mnist-back-image} datasets respectively. In both cases $k_1$ is an acr-cosine kernel, and the remaining are Gaussian kernels for \\textit{mnist-back-rand} dataset and polynomial kernel for textit{mnist-back-image} dataset. The results in the table indicates that,  the contribution of individual kernels was highly varying in each layer (no single kernel had complete dominance over all layers in the feature learning process). \n\n\n\\renewcommand{\\arraystretch}{2.3}\n\\begin{table*}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Layers}} & \\multicolumn{7}{ |c| }{\\textbf{Kernel Weights}} \\\\\n  \\cline{2-8}\n  & $k_1$ & $k_2$ & $k_3$ & $k_4$ & $k_5$ & $k_6$ & $k_7$ \\\\\n  \\hline  \n  \\textit{Layer 1} & 0.2007 & 0.1331 & 0.1331 & 0.1332 & 0.1332 & 0.1333 & 0.1333\\\\\n  \\hline\n  \\textit{Layer 2} & 0.2711 & 0.1160 & 0.1181 & 0.1203 & 0.1225 & 0.1248 & 0.1271\\\\\n  \\hline\n  \\textit{Layer 3} & 0.1764 & 0.0999 & 0.1125 & 0.1266 & 0.1426 & 0.1607 & 0.1811\\\\\n  \\hline\n  \\textit{Layer 4} & 0.0598 & 0.0524 & 0.0747 & 0.1071 & 0.1547 & 0.2245 & 0.3269\\\\\n  \\hline\n  \\textit{Layer 5} & 0.0514 & 0.0493 & 0.0726 & 0.1069 & 0.1569 & 0.2295 & 0.3334\\\\\n  \\hline    \n\\end{tabular}\n\\caption{Kernel weights in each layer for the \\textit{mnist-back-rand} dataset}\n\\label{back_rand_kw}\n\\end{table*}\n\\renewcommand{\\arraystretch}{1}\n\n\\renewcommand{\\arraystretch}{2.3}\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Layers}} & \\multicolumn{5}{ |c| }{\\textbf{Kernel Weights}} \\\\\n  \\cline{2-6}\n  & $k_1$ & $k_2$ & $k_3$ & $k_4$ & $k_5$\\\\\n  \\hline  \n  \\textit{Layer 1} & 0.2445 & 0.1887 & 0.1888 & 0.1889 & 0.1891\\\\\n  \\hline\n  \\textit{Layer 2} & 0.3421 & 0.1603 & 0.1630 & 0.1659 & 0.1688\\\\\n  \\hline\n  \\textit{Layer 3} & 0.2035 & 0.1615 & 0.1843 & 0.2104 & 0.2403\\\\\n  \\hline\n  \\textit{Layer 4} & 0.0843 & 0.1409 & 0.1877 & 0.2508 & 0.3362\\\\\n  \\hline\n\\end{tabular}\n\\caption{Kernel weights in each layer for the \\textit{mnist-back-image} dataset}\n\\label{back_image_kw}\n\\end{table}\n\\renewcommand{\\arraystretch}{1}\n\nIn order to evaluate the contribution of each kernel, exploratory analysis was carried out to monitor the performance of individual kernels in each layer. The individual kernels performance were compared with the combined kernel's performance. Tables \\ref{back_rand_exp} and \\ref{back_image_exp} summarizes the results of this exploratory analysis on \\textit{mnist-back-rand} and \\textit{mnist-back-image} datasets respectively (here $K_{conv}$ is the result of combined kernel). The results clearly indicates that the combination was not always improving the performance in all layers. However, the best result in both datasets were obtained by a combined kernel.\n\n\\renewcommand{\\arraystretch}{2.1}\n\\begin{table*}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Layers}} & \\multicolumn{8}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-9}\n  & $k_1$ & $k_2$ & $k_3$ & $k_4$ & $k_5$ & $k_6$ & $k_7$ & $K_{conv}$\\\\\n  \\hline  \n  \\textit{Layer 1} & 11.46 & 9.92 & 10.06 & 10.04 & 10.1 & 9.87 & 10.06 & 11.62\\\\\n  \\hline\n  \\textit{Layer 2} & 10.36 & 9.87 & 9.90 & 9.89 & 9.92 & 9.82 & 9.81 & 9.52\\\\\n  \\hline\n  \\textit{Layer 3} & 9.46 & 11.07 & 10.33 & 9.85 & 9.70 & 9.56 & 9.01 & 9.18\\\\\n  \\hline\n  \\textit{Layer 4} & 9.26 & 9.06 & 8.95 & 8.96 & 8.93 & 8.72 & 9.00 & \\textbf{8.72}\\\\\n  \\hline\n  \\textit{Layer 5} & 9.18 & 9.07 & 9.02 & 9.20 & 9.22 & 9.36 & 9.47 & 9.15\\\\\n  \\hline    \n\\end{tabular}\n\\caption{Individual kernels performance evaluation for \\textit{mnist-back-rand} dataset}\n\\label{back_rand_exp}\n\\end{table*}\n\\renewcommand{\\arraystretch}{1}\n\n\\renewcommand{\\arraystretch}{2.1}\n\\begin{table}\n\\centering\n\\begin{tabular}{|c|c|c|c|c|c|c|}\n  \\hline\n  \\multirow{2}{*}{\\textbf{Layers}} & \\multicolumn{6}{ |c| }{\\textbf{Loss in Percentage}} \\\\\n  \\cline{2-7}\n  & $k_1$ & $k_2$ & $k_3$ & $k_4$ & $k_5$ & $K_{conv}$\\\\\n  \\hline  \n  \\textit{Layer 1} & 20.91 & 21.82 & 21.82 & 21.83 & 21.77 & 21.15\\\\\n  \\hline\n  \\textit{Layer 2} & 21.27 & 21.00 & 21.09 & 21.04 & 21.04 & \\textbf{20.83}\\\\\n  \\hline\n  \\textit{Layer 3} & 20.95 & 21.18 & 21.02 & 20.99 & 21.05 & 21.03\\\\\n  \\hline\n  \\textit{Layer 4} & 21.06 & 21.36 & 21.42 & 21.64 & 21.66 & 21.51\\\\\n  \\hline\n\\end{tabular}\n\\caption{Individual kernels performance evaluation for \\textit{mnist-back-image} dataset}\n\\label{back_image_exp}\n\\end{table}\n\\renewcommand{\\arraystretch}{1}\n\n\n\n\\section{Conclusion}\n\\label{sec_conc}\nIn this chapter we explored the concept of multiple kernel learning in MKMs. A linear combination of multiple kernels formulated purely from unlabelled data is used in each layer of MKMs. The learning process of the proposed ML-MKL algorithm employs a greedy layerwise training for each layer. Empirical results indicates that using (unsupervised) MKL  in MKMs improves the classifier performance. In our experimental analysis the classification accuracy of ML-MKL models was better than learning machines with shallow architectures and was comparable with existing deep architectures.\n\nExploratory analysis performed on the features learned by the ML-MKL model reveals much more interesting facts about the model. The contribution of kernels in each layer is measured in terms of individual kernel performance and the weights assigned to that kernel. However this information is insufficient to determine the optimal structural complexity required for modelling a problem.\n", "meta": {"hexsha": "b43ce505faa6a33b295b3b10274ec330ffe391bb", "size": 24812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter3.tex", "max_stars_repo_name": "akhilpm/Masters-Project", "max_stars_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_stars_repo_licenses": ["MIT"], "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/chapter3.tex", "max_issues_repo_name": "akhilpm/Masters-Project", "max_issues_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_issues_repo_licenses": ["MIT"], "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/chapter3.tex", "max_forks_repo_name": "akhilpm/Masters-Project", "max_forks_repo_head_hexsha": "cc10673e695cbc0531f6268d729760705890a116", "max_forks_repo_licenses": ["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.9607250755, "max_line_length": 944, "alphanum_fraction": 0.7035305497, "num_tokens": 8500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6128046574659036}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\n\\setcounter{chapter}{3}\n\n\\chapter{Schemes and algebraic spaces I}\n\nIn the previous lecture we saw the notion of a geometric context, and that this notion gives rise to manifolds and geometric spaces. We will now construct a context specific to algebraic geometry in which the manifolds are schemes and geometric spaces are algebraic spaces.\n\n\nIn order to understand the conrtuction of algebraic contexts we commence by recalling some elementary facts about (affine) algebraic varieties, .... Naively an algebraic variety is a set of solutions to a system of plynomial equations. ... An algebraic variety is determined a finite familyof polynomials $P_1, \\cdot P_r \\in \\mathbb C[x_1, \\cdots, x_n]$. X is then a solution a dset of solutions of the system $\\{P_i(x) = 0\\}_{1 \\le i \\le r}$, in ... terms we have\n\n\\[\nX = \\{ x \\in \\mathbb C^n ~|~ P_i(x) = 0 ~ \\forall i\\}\n\\]\nWe also then have the question of defining the ``algebraic functions'' on $X$. ... ring of algebraic functions on $X$ is witten as\n\n\\[\n\\mathcal O(X) = \\mathcal C[x_1, \\cdots x_n] / (P_1, \\cdots, P_r)\n\\]\n\nAn algebraic variety $X$ corresponds to the ring $C[x_1, \\cdots x_n] / (P_1, \\cdots, P_r)$. This ring is a commutative $\\mathbb C$-algebra of finite type (i.e. with a finite number of generators). Conversely, if $A$ is an commutative $C$-algebra of finite type, we can write\n\n\\[\nA \\simeq \\mathbb C[y_1, \\cdots, y_m]/(Q_1, \\cdots, Q_s)\n\\]\n\nand construct an algebraic variety in $\\mathbb C^m$ with the equation $Q_1(y) = \\cdots = Q_s(y) = 0$.\n\n\nthere's a correspondence between affines algebraic varies in $\\mathbb C$ (i.e. subvarieties of $\\mathbb C^n$ for some $n$), and commutative $\\mathbb C$-algebras of finite type. The starting point for the theory of schemes and considering commutative rings A (not necessarily commutative $\\mathbb C$-algebras of finite type) is the considering of the correspondenc between a geometric object $X$ and $A$ a ring of algebraic functions on $X$. The geometric objects associated with the ring are affine schemes, and a scheme is by definition a collection of affine schemes (much like a topological property is a collection of opens in $\\mathbb R^n$). We have the following two principles\n\n\\begin{prcp*}\n    Affine schemes are in correspondence with commutative rings\n\\end{prcp*}\n\\begin{prcp*}\n    Schemes are obtained from collections of affines schemes\n\\end{prcp*}\n\n\nFrom the combination two principles we obtain the following principles\n\n\\begin{prcp*}\n    Schemes are obtained from collections of commutative rings\n\\end{prcp*}\n\n\n\n\\section{Geometric contexts}\n\n\n\n\n\\end{document}", "meta": {"hexsha": "826e01f635ff65dce1231997e0e3eb42aa07e0e0", "size": 2648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/lecture3.tex", "max_stars_repo_name": "jakebian/OTIM-toen-mastercourse", "max_stars_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_stars_repo_licenses": ["MIT"], "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/lecture3.tex", "max_issues_repo_name": "jakebian/OTIM-toen-mastercourse", "max_issues_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_issues_repo_licenses": ["MIT"], "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/lecture3.tex", "max_forks_repo_name": "jakebian/OTIM-toen-mastercourse", "max_forks_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_forks_repo_licenses": ["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.1454545455, "max_line_length": 683, "alphanum_fraction": 0.7401812689, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.612804643266945}}
{"text": "\\chapter{Explicit One-Step Methods and Convergence}\n\n\\section{Introduction}\n\\begin{example}[Euler's method]\n  We begin this section with the method which serves as prototype for\n  a whole class of schemes which solves an IVP or rather the Volterra\n  integral equation numerically. Here, as always for problems with\n  infinite dimensional solution spaces, numerical solution refers to\n  finding an approximation by applying a discretization method, and\n  studying the error of this method.\n  \n  Consider the following problem: given an IVP of the form of \\slideref{Definition}{IVP},\n  calculate the value $u(T)$ at a later point in time $T$.\n  \n  To this end, we note first of all that for an IVP at the initial\n  point $0$, not only the function value $u(0) = u_0$ is known,\n  but also the derivative $u'(0) = f(0, u_0)$. Thus we are capable\n  to replace the solution $u(t)$ in blue by a straight line $y(t)$ in\n  red, which we can see on the left of Figure~\\ref{fig:explicit:Euler}.\n  \\begin{figure}[tp]\n    \\centering\n    \\includegraphics[width=.48\\textwidth]{fig/euler1}\n    \\includegraphics[width=.48\\textwidth]{fig/euler2}\n    \\caption{Derivation of the Euler method. Left: replacement of the\n\t\t\tsolution of the IVP by a line with slope and initial point given \n\t\t\tby the IVP. Right: Euler method with three subintervals.}\n    \\label{fig:explicit:Euler}\n  \\end{figure}\n  The figure suggests that in general the accuracy of this method may\n  not be very good. The first improvement is that we do not draw the\n  line through the whole interval from $0$ to $T$.  Instead, we\n  insert intermediate points and apply the method to each subinterval,\n  where we use the result of a previous interval as the initial point\n  for the next subinterval.  As a result one obtains a\n  chain of straight lines and the so-called \\define{Euler method}.\n\\end{example}\n\n\n\\input{definitions/partitioning}\n\n\\begin{definition}\n  In the following chapters we will regularly compare the solution of\n  an IVP with the results of discretization methods. Therefore, we\n  introduce the following convention for notations and symbols.\n  \n  \\defindex{solution!continuous}\\defindex{solution!exact} The solution\n  of the IVP is called the \\textbf{exact} or \\define{continuous\n    solution}\\defindex{exact solution}. The term ``continuous''\n  indicates here the solution of the non-discretized problem. Its\n  symbol is in general $u$ and we set as abbreviation\n  \\begin{gather*}\n    u_k = u(t_k).\n  \\end{gather*}\n  If $u$ is vector-valued we also use the alternative superscript\n  $u^{(k)}$ and $u_i^{(k)}$ for a entry of the vector $u(t_k)$.\n\n  \\defindex{solution!discrete} In general we write the\n  \\define{discrete solution} with the\n  symbol $y$. We write $y_k$ or $y^{(k)}$ for the value of the\n  discrete solution at the point in time $t_k$. In contrast to the\n  continuous solution, $y$ only defined at discrete time steps, unless\n  for special methods discussed later.\n\\end{definition}\n\n\\input{definitions/one-step}\n\n\\begin{remark}\n  \\label{remark:expl:first-step}\n  For one-step methods every step is \\emph{per definitionem} similar.\n  Therefore, it is sufficient to consider the first step only.  Hence,\n  we will define and analyze methods by stating the dependence of\n  $y_1$ on $y_0$ which then can be transferred to the general step\n  from $y_{n-1}$ to $y_{n}$. The general one-step method above then\n  reduces to\n  \\begin{gather*}\n    y_1 = y_0 + h \\verfahren(t_0, y_0).\n  \\end{gather*}\n  This implies that the values $y_k$ with $k\\ge 2$ are computed\n  through formula~\\eqref{eq:explicit:8} with the respective $h_k$ and\n  the same increment function.\n\\end{remark}\n\n\\input{theorems/euler-linear-1}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Error analysis}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{remark}\n  In Figure~\\ref{fig:explicit:Euler}, we observe that the error\n  consists of two parts at a given time $t_{k+1}$. First, an error on\n  the interval $I_k$ due to replacing the differential equation by the\n  discrete method. Second, we have to add the error which results from\n  the fact that our initial value $y_k$ is already not exact due to\n  previous errors. This situation is displayed in\n  Figure~\\ref{fig:forward-errors}. After one time step, a local error\n  has appeared. In the second time step, we already start with an\n  erroneous initial value. Therefore, we split the error into the\n  local error and an accumulated error. The local error compares\n  continuous and discrete solutions on a single interval with the same\n  initial value. In the analysis, we will have the options of using\n  the exact (right figure) or the approximated initial value (left figure).\n\n  \\begin{figure}[tp]\n    \\centering\n    \\includegraphics[width=.49\\textwidth]{fig/forward-error.tikz}\n    \\includegraphics[width=.49\\textwidth]{fig/backward-error.tikz}\n    \\caption{Local and accumulated errors. Exact solution in black,\n      the Euler method in red. On the left, in blue the exact solution\n      of an IVP on the second interval with initial value $y_1$. On\n      the right, in purple the second step of the Euler method, but with\n      exact initial value $u_1$.}\n    \\label{fig:forward-errors}\n  \\end{figure}\n\\end{remark}\n\n\\input{definitions/globalerror}\n\n\\input{definitions/truncation-error}\n\n\\begin{example}[Euler method]\n  To find out the order of consistency of the Euler method, we \n  consider the Taylor expansion of the solution at the point $t_{n-1}$:\n  \\begin{equation*}\n    u(t_n) = u(t_{n-1}) + h_n u'(t_{n-1}) + \\frac12 h_n^2 u''(\\zeta)\n  \\end{equation*}\n  \n  As a result the truncation error reduces to:\n  \n  \\begin{align*}\n    \\tau_n & = \\frac{u_n - u_{n-1}}{h_n} - F(h;t_{n-1},u(t_{n-1})) \\\\\n    & = \\frac{u_{n-1} + h_n f(t_{n-1},u_{n-1})\n      + \\frac12 h_n^2 u''(\\zeta) - u_{n-1}}{h_n} - f(t_{n-1}; u_{n-1}) \\\\\n    & = \\frac12 h_n u''(\\zeta)\n  \\end{align*}\n\n% For $u''(\\zeta)$ however there holds:\n% \\begin{equation*}\n%   u''(\\zeta) = \\diffq[\\zeta] f(\\zeta,u(\\zeta)) = \\pdiffq[\\zeta] f(\\zeta,u(\\zeta)) + \\pdiffq[u] f(\\zeta,u(\\zeta)) \\underbrace{u'(\\zeta)}_{= f(\\zeta,u(\\zeta))}\n% \\end{equation*}\n\nUnder the assumption that $f \\in C^1$ on a compact set around the graph\nof $u$, this term is bounded, yielding.\n\\begin{gather*}\n  | \\tau_n | \\le \\frac{h_n}{2} \\max_{\\zeta\\in I_n} \\abs{u''(\\zeta)}\n  = \\frac{h_n}{2} \\max_{\\zeta\\in I_n} \\bigl|\\partial_x f(\\zeta,\n    u(\\zeta)) + \\partial_u  f(\\zeta, u(\\zeta)) f(\\zeta, u(\\zeta))\\bigr|\n\\end{gather*}\nHere, we enter the assumption that $f$ is sufficiently smooth to\nconclude that the Euler method is consistent of order 1.\n\\end{example}\n\n\\input{theorems/gronwall-discrete}\n\n\\begin{proof}\n  Define the functions $w(t)$, $a(t)$, and $b(t)$ such that for $k\\ge\n  1$ and $t\\in [k-1,k)$ there holds\n  \\begin{gather*}\n    w(t) = w(t_{k-1}),\\quad\n    a(t) = b(t_{k-1}),\\quad\n    b(t) = b(t_{k-1}).\n  \\end{gather*}\n  These functions are bounded and piecewise continuous on any finite\n  interval. Thus, they are integrable on $[0,n]$. Therefore, the\n  continuous Grönwall inequality of Lemma~\\ref{Lemma:gronwall} applies\n  and proves the result.\n\\end{proof}\n\n\\input{theorems/stability-discrete}\n\n\\begin{proof}\n  Subtracting the equations\n  \\begin{align*}\n    \\eta_k(y) &= y_k-y_{k-1} - \\verfahren_{h_k}(t_{k-1},y_{k-1}),\n    \\\\\n    \\eta_k(y) &= z_k-z_{k-1} - \\verfahren_{h_k}(t_{k-1},z_{k-1}),\n  \\end{align*}\n  we obtain\n  \\begin{multline*}\n    y_k-z_k = y_{k-1} - z_{k-1} + \\eta_k(y) - \\eta_k(z)\n    \\\\\n    + h_k \\bigl(\n      F_{h_k}(t_{k-1},y_{k-1})-F_{h_k}(t_{k-1},z_{k-1})\n    \\bigr)\n    .\n  \\end{multline*}\n  Recursive application yields\n  \\begin{gather*}\n    \\abs{y_n-z_n} \\le \\abs{y_0-z_0}\n    + \\sum_{k=1}^n \\abs{\\eta_k(y)-\\eta_k(z)}\n    + \\sum_{k=1}^n L_h h_{k} \\abs{y_k-z_k}.\n  \\end{gather*}\n  The estimate now follows from the discrete Grönwall inequality in\n  Lemma~\\ref{Lemma:gronwall-discrete}.\n\\end{proof}\n\n\\begin{Corollary*}{finite-precision}{One-step methods with finite precision}\n  Let the one-step method $\\verfahren$ be run on a computer, yielding\n  a sequence $(z_n)$, such that each time step is executed in finite\n  precision arithmetic. Let $(y_n)$ be the mathematically correct\n  solution of the one-step method. Then, the difference\n  equation~\\eqref{eq:explicit:8} is fulfilled only up to machine\n  accuracy $\\epsilon_m$:\n  \\begin{align*}\n    y_0-z_0 &\\approx \\epsilon_m \\\\\n    \\abs{\\eta_k(y) - \\eta_k(z)} &= \\abs{\\eta_k(z)} \\approx \\epsilon_m \\abs{z_k}.\n  \\end{align*}\n  Then, the error between the true solution of the one-step method\n  $(y_n)$ and the computed solution is bounded by\n  \\begin{gather*}\n    \\abs{y_n-z_n} \\le e^{L_h(t_n-t_0)} n \\epsilon_m \\max_k\\abs{z_k}.\n  \\end{gather*}\n\\end{Corollary*}\n\n\\begin{Theorem*}{convergence-one-step}{Convergence of one-step methods}\n  Let the one-step method $F(.,.)$ be consistent of order $p$ and\n  discretely stable, that is, $F(.,.)$ is Lipschitz continuous in its\n  second argument. Let $f(t,u)\\in C^{p}$. Furthermore, let\n  $y_0 = u_0$. Let $h = \\max h_n$ and let there be a positive number\n  $\\gamma$ such that $\\min h_n = \\gamma h$. Then, the method converges\n  with order $p$ and there holds\n  \\begin{equation}\n    \\label{eq:convergence-onestep:1}\n    \\abs{u_n - y_n} \\le c e^{L_h(t_n-t_0)} h^p,\n  \\end{equation}\n  where the constant $c$ is independent of $h$.\n\\end{Theorem*}\n\n\\begin{proof}\n  Again we use the discrete stability theorem: with the definition of\n  the order of the method, we obtain\n  \\begin{gather}\n    \\label{eq:convergence-onestep:2}\n    \\abs{\\eta_k(u)-\\eta_k(y)} = \\abs{\\eta_k(u)} \\le c h^{p+1},\n  \\end{gather}\n  where $c$ depends on the derivatives of $u$ (and thus of $f$), but\n  not on $u_k-y_k$. On the other hand, we have\n  \\begin{gather*}\n    n \\le \\frac{t_n-t_0}{\\min h_n} \\le \\frac{t_n-t_0}{\\gamma h}.\n  \\end{gather*}\n  Thus, we obtain by summing up~\\eqref{eq:convergence-onestep:2} over all $n$\n  \\begin{gather*}\n    \\abs{u_n-y_n} \\le e^{L_h(t_n-t_0)}\\sum_{k=1}^n h_k^{p+1}\n    \\le c e^{L_h(t_n-t_0)} h^p.\n  \\end{gather*}\n\\end{proof}\n\n\\begin{corollary}\n  The Euler method converges of first order.\n\\end{corollary}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Runge-Kutta methods}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  We are searching for methods which approximate the solution to an\n  IVP numerically.  In fact we are not solving the IVP, but the Volterra\n  integral equation~\\eqref{eq:volterra}.  Hence we can consider\n  solving differential equations as a quadrature problem; with the\n  difficulty that the function, which we integrate, is not known. This\n  consideration leads to a class of methods for IVP, the\n  Runge-Kutta methods.\n\\end{intro}\n\n\\input{definitions/erk}\n\n\\begin{remark}\n  Pursuant to remark~\\ref{remark:expl:first-step} we present the\n  formula for the calculation of $y_1$ from $y_0$ on the interval from\n  $t_0=0$ to $t_1 = h$.  The formula for a later time step $k$ is\n  obtained by replacing $y_0$ and $t_0=0$ by $y_k$ and $t_k$,\n  respectively to obtain $y_{k+1}$.\n\\end{remark}\n\n\\begin{remark}\n  The intermediate values $\\rkg_i$ will not be saved separately in\n  typical implementations, because it is possible to execute the\n  method with the values $k_i$ alone. Nevertheless, the values\n  $\\rkg_i$ are useful for highlighting the structure of the method.\n\\end{remark}\n\n\\input{definitions/butcher-tableau-erk}\n\n\\begin{remark}\n  The first row of the tableau is to read in such a manner, that\n  $g_1 = y_0$ and $k_1$ is computed directly by $f(t_0, y_0)$. The\n  coefficients $a_{1j}$ and $c_0$ do not appear in formulas~\\eqref{eq:explicit:1a}\n  and~\\eqref{eq:explicit:1b} (or are considered zero).\n  \n  The further rows indicate the rules for the computation of the\n  further values $k_i$ in each case according to the\n  formulas~\\eqref{eq:explicit:1a} and~\\eqref{eq:explicit:1b}. The\n  the method is explicit since the computation of $k_i$ only involves\n  coefficients with index less than $i$.\n  \n  The last row below the line is then the short form of\n  formula~\\eqref{eq:explicit:1c} and lists quadrature weights.\n\n  We see, that the coefficients $a_{ij}$ form the strict lower\n  triangle of a square $s\\times s$-matrix $A$. Therefore, in order to\n  simplify the summation bounds, we implicitly complete this matrix\n  with values $a_{ij} = 0$ for $j\\ge i$.This way, the sum\n  in~\\eqref{eq:explicit:1a} can be taken from $1$ to $s$, independent\n  of $i$. We will also associate to an $s$-stage method the vector $b\n  = (b_1,\\dots,b_s)^T$.\n\\end{remark}\n\n\\begin{example}\n  The Euler method \\putindex{Euler method} has the \\putindex{Butcher\n    tableau}:\n  \\begin{gather*}\n    \\begin{array}{c|c}\n      0 & \\\\\n      \\hline\n        & 1 \\\\\n    \\end{array}\n  \\end{gather*}\n  That leads to the already known formula:\n  \\begin{equation*}\n    y_1 = y_0 + h f(t_0, y_0)\n  \\end{equation*}\n  The values $b_1=1$ and $c_1=0$ indicate that this is a quadrature\n  rule with a single point at the left end of the interval. Such a\n  rule is exact for constant polynomials and thus of order 1.\n\\end{example}\n\n\\input{definitions/rk2}\n\n\\begin{remark}\n  The modified Euler method uses an approximation to the value of\n  $f(h/2, u(h/2))$ in its quadrature, corresponding to the midpoint\n  quadrature rule. The Heun method is constructed analogous to the\n  trapezoidal rule. Both quadrature rules are of second order, and so\n  are these one-step methods.  Both methods were discussed by Runge in\n  his article of 1895~\\cite{Runge95}.\n\\end{remark}\n\n\\begin{Lemma}{Heun-consistency}\n  The Heun method and the modified Euler method are consistent of second\n  order\\footnote{Here and in the following proofs of consistency\n    order, we will always assume that all necessary derivatives of $f$\n  exist and are bounded. We say ``$f$ is sufficiently smooth''.}.\n\\end{Lemma}\n\n\\begin{proof}\n  The proof uses Taylor expansion of the continuous solution $u$ and\n  the discrete solution $y$ around $t_0$ with respect to $h$. First,\n  abbreviating $f_t = \\partial_t f(t_0,u_0)$ and\n  $f_u = \\partial_u f(t_0,u_0)$ and so forth\\footnote{Note that $f_u$,\n    $f_{u u}$ and so on are tensors of increasing rank.} and replacing\n  $u'(t_0)=f(t_0,u_0) = f$:\n  \\begin{multline}\n    \\label{eq:explicit:4}\n    u_1 = u(t_0+h) = u_0 + h f(t_0, u_0)\n    + \\frac{h^2}2\\bigl(f_t + f_u f\\bigr)\n    \\\\\n    + \\frac{h^3}6\\bigl(f_{t t}+2f_{t u}f+f_{u u}f^2+f_u f_t+f_u^2f\\bigr)\n    + \\dots.\n  \\end{multline}\n  For the discrete solution of the modified Euler step on the other\n  hand, there holds\n  \\begin{align*}\n    y_1 &= u_0 + h f\\left(t_0+\\frac h2, u_0+\\frac h2 f(t_0,u_0)\\right)\n    \\\\\n    &= u_0 + h f(t_0, u_0) + \\frac{h^2}2 \\bigl(f_t + f_u f\\bigr)\n    \\\\&\\hphantom{...}\n      + \\frac{h^3}8\\bigl(f_{t t}+2f_{t u}f+f_{u u}f^2+f_u f_t+f_u^2f\\bigr)\n        +\\dots.\n  \\end{align*}\n  Thus, $\\abs{u_1-y_1} = \\mathcal O(h^3)$ and the method is of second\n  order. The proof for the Heun method is left as an exercise.\n\\end{proof}\n\n\\begin{Example}{rk3}\n  \\defindex{Runge-Kutta method!three-stage}\n  The three stage Runge-Kutta method is\n\n  \\begin{gather*}\n    \\begin{aligned}\n      k_1 & = f(t_0, y_0) \\\\\n      k_2 & = f(t_0 + \\frac12 h, y_0 + \\frac12 h k_1) \\\\\n      k_3 & = f(t_0 + h, y_0 - h k_1 + 2 h k_2) \\\\\n      y_{n+1} & = y_0 + h ( \\frac16 k_1 + \\frac46 k_2 + \\frac16 k_3 ) \\\\\n    \\end{aligned}\n    \\qquad\n    \\begin{array}{c|ccc}\n      0 & \\\\\n      \\frac12 & \\frac12 \\\\\n      1 & -1 & 2 \\\\\n      \\hline\n        & \\frac16 & \\frac46 & \\frac16 \\\\\n    \\end{array}\n  \\end{gather*}\n  This method is obviously based on the Simpson rule.\n\\end{Example}\n\n\\begin{remark}\n  Computations become tedious very fast, in part due to the sum of\n  partial derivatives of $f(t,u)$. This can be simplified by\n  considering Runge-Kutta methods for the autonomized ODE (see\n  Definition~\\ref{Definition:autonomization})\n  \\begin{gather*}\n    \\begin{pmatrix} u' \\\\ t' \\end{pmatrix} = \n    \\begin{pmatrix} f(t,u) \\\\ 1 \\end{pmatrix}.\n  \\end{gather*}\n  Then, the Runge-Kutta method~\\eqref{eq:explicit:1} simplifies to\n  \\begin{gather}\n    \\label{eq:explicit:7a}\n    \\begin{split}\n      \\rkg_i &= y_0 +\n      \\sum_{j=1}^{i-1} \\rka_{ij} h f(\\rkg_j),\\quad i=1,\\dots,\\rks\n      \\\\\n      y_1 &= y_0 + \\sum_{j=1}^s b_j h f(g_j).\n    \\end{split}\n  \\end{gather}\n\\end{remark}\n\n\\begin{Lemma}{erk-autonomization}\n  An ERK is invariant under autonomization (or in short,\n  \\putindex{autonomizable}), if and only if\n  \\begin{gather}\n    \\label{eq:explicit:9}\n    c_i = \\sum_{j=1}^{i-1} a_{ij}, \\quad i=1,\\dots,s.\n  \\end{gather}\n\\end{Lemma}\n\n\\begin{proof}\n  Observing the last component of the vector $u$ in the previous\n  remark and the method applied to it yields the condition.\n\\end{proof}\n\n%HNW p. 145 and pp. 135/137\n\\begin{Lemma}{rk-order-3-4}\n  An autonomizable ERK with $s$ stages is consistent of third order, if\n  and only if the following conditions are met:\n  \\begin{subequations}\n    \\label{eq:explicit:11}\n    \\begin{align}\n      \\label{eq:explicit:12}\n      b_1 + \\dots + b_s &= 1, \\\\\n      \\label{eq:explicit:13}\n      b_1c_1 + \\dots + b_s c_s &= 1/2, \\\\\n      \\label{eq:explicit:14}\n      b_1c_1^2 + \\dots + b_s c_s^2 &= 1/3, \\\\\n      \\label{eq:explicit:15}\n      \\sum\\nolimits_{i,j} b_i a_{ij}c_j &= 1/6.\n    \\end{align}\n    It is consistent of fourth order, if and only if additionally\n    \\begin{align}\n    \\label{eq:explicit:16}\n    b_1c_1^3 + \\dots + b_s c_s^3 &= 1/4, \\\\\n    \\label{eq:explicit:18}\n    \\sum\\nolimits_{i,j} b_i a_{ij} c_j^2 &= 1/12, \\\\\n    \\label{eq:explicit:19}\n    \\sum\\nolimits_{i,j,k} b_i a_{ij} a_{jk} c_k &= 1/24,\\\\\n    \\label{eq:explicit:17}\n    \\sum\\nolimits_{i,j} b_i c_i a_{ij} c_j &= 1/8.\n  \\end{align}\n  \\end{subequations}\n\\end{Lemma}\n\n\\begin{remark}\n  We can rephrase these conditions, such that an ERK is of order $k$ if\n  the quadrature with\n  support points $c_i$ and corresponding weights $b_i$ is exact for\n  polynomials of degree $k-1$:\n  \\begin{gather*}\n    \\sum_{i=1}^{s} b_i p(c_i) = \\int_0^1 p(t)\\dt,\n    \\qquad \\forall p\\in \\P_{k-1}.\n  \\end{gather*}\n  Furthermore, for $k \\ge 3$\n  \\begin{gather*}\n    \\sum_{ij} b_i a_{ij} p(c_j) = \\int_0^1\\int_0^t p(s)\\ds\\dt,\n    \\qquad \\forall p\\in \\P_{k-2}.\n  \\end{gather*}\n  Additionally, for $k\\ge 4$\n  \\begin{xalignat*}2\n    \\sum_{ijk} b_i a_{ij} a_{jk} p(c_k) &= \\int_0^1\\int_0^t\\int_0^s p(r)\\dr \\ds \\dt,\n    &&\\forall p\\in \\P_{k-3},\\\\\n    \\sum_{ij} b_i p(c_i) a_{ij} q(c_j)\n    &= \\int_0^1 p(t) \\int_0^t q(s) \\ds\\dt\n    &&\\forall p\\in \\P_{k_1}, q\\in\\P_{k_2}, k_1+k_2 = k-2.\n  \\end{xalignat*}\n\\end{remark}\n\n\\input{theorems/taylor-u}\n\\begin{proof}\n  Taking derivatives of $u$ and replacing every occurrence of $u'$ by\n  $f(u)$. For scalar valued functions, we clarify this at the example\n  \\begin{align*}\n    u'(t) &= f(u(t)) \\\\\n    u''(t) &= \\bigl(u'(t)\\bigr)'\n    = f(u(t))' = f'(u(t))u'(t)\n    \\\\& = f'(u(t)) f(u(t))\n    \\\\\n    u^{(3)} &= \\bigl(u''(t)\\bigr)' = \\bigl(f'(u(t)) f(u(t))\\bigr)'\n    \\\\&= f''(u(t)) u'(t) f(u(t)) + f'(u(t)) f'(u(t)) u'(t)\n    \\\\& = f''(u(t)) f(u(t))^2 + f'(u(t))^2 f(u(t)).\n  \\end{align*}\n  After the concept is clear, we have to keep track of the vector\n  indices and compute with brute force.\n  It may be worth noting, that in the 4th order term, we used the fact\n  that we can swap summation indices and get\n  \\begin{gather*}\n    \\sum_{\\lambda,\\mu,\\nu} \\partial_{\\lambda\\mu} f_n \\partial_\\nu f_\\lambda f_\\mu f_\\nu\n    = \\sum_{\\lambda,\\mu,\\nu} \\partial_{\\lambda\\mu} f_n \\partial_\\nu f_\\mu f_\\lambda f_\\nu\n    = \\sum_{\\lambda,\\mu,\\nu} \\partial_{\\lambda\\nu} f_n \\partial_\\mu f_\\lambda f_\\mu f_\\nu\n    .\n  \\end{gather*}\n\\end{proof}\n\n\\input{theorems/taylor-y}\n\n\\begin{proof}\n  We begin with the observation that for an arbitrary function $\\phi$ holds\n  \\begin{gather*}\n     \\frac{d^{q}}{d h^{q}}\\bigl(h\\phi(h)\\bigr)\\bigg|_{h=0}\n     = \\left[ h \\frac{d^{q}}{d h^{q}} \\phi(h) + q h'\n       \\frac{d^{q-1}}{d h^{q-1}} \\phi + \\binom{q}{2}\n       h''\\dots\\right]_{h=0}\n     = q \\frac{d^{q-1}}{d h^{q-1}} \\phi.\n  \\end{gather*}\n  Next, we use~\\eqref{eq:explicit:1c} to obtain\n  \\begin{align*}\n    y(h) &= u_0, \\\\\n    y^{(q)}(h)\\big|_{h=0} &= q \\sum_{j=1}^s b_j \\frac{d^{q-1}}{d h^{q-1}} f(g_j)\\bigg|_{h=0}.\n  \\end{align*}\n  We observe $g_i(0) = u_0$. Further, from~\\eqref{eq:explicit:1a}, we\n  obtain\n  \\begin{align*}\n    g_i(h)\\big|_{h=0} &= u_0, \\\\\n    g_{i;n}^{(q)}(h)\\big|_{h=0} &= q \\sum_{j=1}^{i-1} a_{ij}\n                                  \\frac{d^{q-1}}{d h^{q-1}} f_n(g_{j})\\bigg|_{h=0}.\n  \\end{align*}\n  Here, $g_{i;n}$ refers to the component $k$ of vector\n  $g_i$. Finally, we need\n  \\begin{align*}\n    \\frac{d}{d h} f_n(g_i(h))\\big|_{h=0}\n    & = \\sum_{\\lambda} \\partial_{\\lambda} f_n g'_{i;\\lambda}\\\\\n    \\frac{d^2}{d h^2} f_n(g_i(h))\\big|_{h=0}\n    & = \\sum_{\\lambda,\\mu} \\partial_{\\lambda\\mu} f_n g'_{i;\\lambda} g'_{i;\\mu}\n      + \\sum_k \\partial_{\\lambda} f_n g''_{i;\\lambda}.\n  \\end{align*}\n  Summarizing, we obtain\n  \\begin{align*}\n    y'_n &= \\sum_{j=1}^s b_j f_n(g_j)\n    \\\\\n    y''_n &= 2 \\sum_{j=1}^s b_j\\frac{d}{d h} f_n(g_j)\n    = \\sum_{j=1}^s \\sum_{k=1}^{j-1} b_j a_{j k}\n            \\sum_{\\lambda} \\partial_{\\lambda} f_n f_\\lambda\n    \\\\\n    y'''_n &= 3 \\sum_{j=1}^s b_j\\frac{d^2}{d h^2} f_n(g_j)\n    \\\\&= 3 \\sum_{j=1}^s b_j \\left[\n      \\sum_{\\lambda,\\mu} \\partial_{\\lambda\\mu} f_n g'_{j;\\lambda} g'_{j;\\mu}\n      + \\sum_\\lambda \\partial_{\\lambda} f_n g''_{j;\\lambda}\\right]\n    \\\\&= 3 \\sum_{j=1}^s b_j \\left[\n        \\sum_{\\lambda,\\mu} \\partial_{\\lambda\\mu} f_n \\sum_{k=1}^{j-1} a_{j k}\n        f_\\lambda \\sum_{k=1}^{j-1} a_{j k}\n        f_\\mu + \\sum_{\\lambda} \\partial_{\\lambda} f_n 2 \\sum_{k=1}^{j-1}\n        a_{j k} \\sum_{l=1}^{k-1} a_{kl} \\sum_\\mu \\partial_\\mu f_\\lambda f_\\mu\n        \\right]\n  \\end{align*}\n\\end{proof}\n\n\\begin{proof}[Proof of Lemma~\\ref{Lemma:rk-order-3-4}]\n  The proof utilizes Taylor expansion of $u_1$ and $y_1$ provided in\n  Lemmas~\\ref{Lemma:taylor-u} and~\\ref{Lemma:taylor-y},\n  respectively. Once we have computed these expansions, we compare\n  coefficients in front of equal derivatives in order to get the result.\n\\end{proof}\n\n\\begin{remark}\n  Butcher introduced a graph theoretical method for order conditions\n  based on trees. While this simplifies the process of deriving these\n  conditions for higher order methods considerably, it is beyond the\n  scope of this course.\n\\end{remark}\n\n\\input{definitions/rk4}\n\n\\begin{remark}[Order conditions and quadrature]\n  The order conditions derived by excessive Taylor expansion have a\n  very natural interpretation through the analysis of quadrature\n  formulas for the Volterra integral equation, where $(h c_i)$ are the\n  quadrature points and the other values are quadrature weights.\n  First, we observe that\n  \\begin{gather*}\n    \\sum_i b_i f(g_i) \\quad\\text{approximates}\\quad\n    \\frac1h\\int_0^1 f(u(h s)\\ds.\n  \\end{gather*}\n  In this view,\n  conditions~\\eqref{eq:explicit:12}--\\eqref{eq:explicit:14}\n  and~\\eqref{eq:explicit:16} state that the formula $\\sum_i b_i\n  p(c_i)$ is an exact integral for polynomials of degree up to 3. In a\n  previous semester, we have made use of this property to prove that\n  the formula is of 4th order.\n\n  Equally, we deduce from formula~\\eqref{eq:explicit:1a} for $g_i$ that\n  \\begin{gather*}\n    \\sum_j a_{ij} f(g_j) \\quad\\text{approximates}\\quad\n    \\frac1h\\int_0^{c_i} f(u(h s)\\ds.\n  \\end{gather*}\n  The condition~\\eqref{eq:explicit:9} that the method be autonomizable\n  states nothing but that this be exact for constant functions. For\n  higher order, the accuracy of the value of $g_i$ only implicitly\n  enters the accuracy of the Runge-Kutta method by integrating this\n  value again. Thus, we actually look at approximations of integrals\n  of the form\n  \\begin{gather*}\n    \\int_0^1 \\phi(s) \\int_0^s \\psi(r) \\dr\\ds.\n  \\end{gather*}\n  Condition~\\eqref{eq:explicit:15} for 3rd order states, that this\n  condition must be true for linear polynomials $\\psi(r)$ and constant\n  $\\phi(s)$, thus, after the interior integration again a polynomial\n  of second order. Equally, conditions~\\eqref{eq:explicit:17}\n  and~\\eqref{eq:explicit:18} state this for linear polynomials\n  $\\psi(r)$ with linear $\\phi(s)$ and for quadratic polynomials\n  $\\psi(r)$ with constant $\\phi(s)$, respectively. Finally,\n  condition~\\eqref{eq:explicit:19} states that the quadrature has to\n  be exact for any linear polynomial $\\phi(\\tau)$ in\n  \\begin{gather*}\n    \\int_0^1 \\int_0^s \\int_0^r \\phi(\\tau) \\,\\diffd \\tau\\dr\\ds.\n  \\end{gather*}\n\\end{remark}\n\n\\begin{remark}[Butcher barriers]\n  The maximal order of an explicit Runge-Kutta method is limited\n  through the number of stages, or vice versa, a minimum number of\n  stages is required for a certain order. The \\define{Butcher barriers} state\n  that in order to achieve order $p$ one requires $\\rks$ stages, where\n  $p$ and $\\rks$ relate as follows:\n  \\begin{center}\n    \\input{tables/butcher-barriers}\n  \\end{center}\n  \n  These order bounds refer to systems of differential equations.  For\n  a simple equation they may be better. For instance, there exists a\n  five-stage method which solves the one dimensional IVP with order 5.\n\n  For $p = 10$ there is only known a method with $s = 17$ until now.\n  It is possible that there exists a method that needs less stages,\n  because currently no proof for a minimal number of stages is\n  available.\n\\end{remark}\n\n\\begin{Lemma}{erk-Lipschitz}\n  Let $f(t,u)$ admit the uniform \\putindex{Lipschitz condition}. Then,\n  every autonomizable ERK which is consistent of order one admits a\n  uniform Lipschitz condition.\n\\end{Lemma}\n\n\\begin{proof}\n  We observe that the \\putindex{increment function} is\n  \\begin{gather}\n    \\label{eq:explicit:7}\n    \\verfahren(0, y) = \\sum_{j=1}^s \\rkb_j f(h\\rkc_i, \\rkg_i(y)),\n  \\end{gather}\n  with $g_i(y)$ defined recursively by\n  \\begin{gather*}\n     g_i(y) = y + h \\sum_{j=1}^{i-1} \\rka_{ij} f(h\\rkc_j, \\rkg_j(y)).\n  \\end{gather*}\n  Let $L$ be the Lipschitz constant of $f$. Let\n  $d_i = \\abs{g_i(x)-g_i(y)}/\\abs{x-y}$. We have\n  \\begin{align*}\n    d_1 &= 1\n    \\\\\n    d_2 &= \\abs{x-y + h \\rka_{21}\n          \\Bigl(f\\bigl(h\\rkc_2,g_1(x)\\bigr)\n          -f\\bigl(\\rkc_2,g_1(x)\\bigr)\n          \\Bigr)}/\\abs{x-y}\n    \\\\ &\\le (1+ha_{21}L)\n         = (1+h\\rkc_{1}L)\n    \\\\\n    d_3 & \\le \\Bigl(1+\n          h L\\bigl(\\rka_{31}+\\rka_{32}(1+ha_{21}L)\\bigr)\\Bigr)\n    \\\\ &\\le \\bigl(1+h L c_3(1+h c_2L)\\bigr)\n    \\\\\n    d_4 & \\le \\Bigl(1+\n          h L c_4\\bigl(1+h L c_3(1+h L c_2)\\bigr)\\Bigr)\n    \\\\\n    d_s & \\le\n          \\Bigl(1+ h L c_s\\bigl(\n          1+\\dots(1+h L c_1)\\dots\\bigl)\\Bigl).\n  \\end{align*}\n  Since $c_i \\le 1$, the factor is bounded by\n  $d_s\\le(1+h L)^{s-1}$. Moreover, if $h L \\le 1$, we realize that\n  \\begin{gather*}\n    d_s = \\Bigl(1+ h L \\bigl(1+\\dots(1+h L)\\dots\\bigl)\\Bigl) \\le s.\n  \\end{gather*}\n  Finally, we enter this result into~\\eqref{eq:explicit:7} to obtain\n  \\begin{align*}\n    \\abs{\\verfahren(0,x)-\\verfahren(0,y)}\n    & \\le \\sum_{j=1}^s b_j L d_j \\abs{x-y}\n    \\\\\n    & \\le d_s L \\abs{x-y}.\n  \\end{align*}\n  Thus, the increment function $\\verfahren$ admits a Lipschitz\n  condition with constant $L_h = L(1+h L)^{s-1}$ for general step size\n  $h$ and $L_h = s L$ for $h\\le 1/L$.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Estimates of the local error\n  and time step control}\n  \\label{section:step_size_control}\n\n\\begin{intro}\n  In the preceding paragraphs, we have used a crude a priori estimate\n  of the local error based on high order derivatives of the right hand\n  side $f(t,u)$. In the case of a complex nonlinear system, such an\n  estimate is bound to be inefficient, since it involves global bounds\n  on the derivatives. Obviously, the local error cannot be computed\n  exactly either, because that would require or imply the knowledge of\n  the exact solution.\n\n  In this section, we discuss two methods which allow an estimate of\n  the truncation error from computed solutions. These estimates are\n  local in nature and therefore usually much sharper. Thus, they can\n  be used to control the step size, which in turn gives good control\n  over the balance of accuracy and effort. Nevertheless, it should be\n  pointed out that in these estimates there is an implicit assumption\n  that the true solution $u$ is sufficiently regular and the step size\n  is sufficiently small, such that the local error already follows\n  the theoretically predicted order.\n\n  Given an estimate for the local error, we can devise an algorithm\n  step size control, which controls the local error and thus in a\n  certain way the global error.\n\\end{intro}\n\n\\begin{algorithm}[Adaptive step size control]\n  Let there be an estimate for the local error based\n  on $\\abs{y_1 - \\hat y_1}$ . Then, the following algorithm can be used\n  to guarantee that the local error of a one-step method remains below\n  a threshold $\\epsilon$ in every time step:\n\n  \\begin{enumerate}\n  \\item Given $y_{k-1}$, compute $y_k$ and $\\hat y_k$ with time step $h_k$.\n  \\item Compute\n    \\begin{gather}\n      \\label{eq:explicit:30}\n      h_{\\text{opt}} = h_k \\left(\\frac{\\epsilon}{y_k - \\hat\n          y_k}\\right)^{\\frac1{p+1}}.\n    \\end{gather}\n  \\item If $h_{\\text{opt}} < h_k$ the time step is rejected: let\n    $h_k = h_{\\text{opt}}$ and recompute $y_k$ and $\\hat y_k$.\n  \\item If the time step was accepted, let $h_{k+1} = h_{\\text{opt}}$.\n    \\begin{enumerate}\n    \\item If $t_k+h_{k+1} > t_n$, let $h_{k+1} = t_n-t_k$.\n    \\end{enumerate}\n    Increase $k$ by one and proceed with the first step.\n  \\end{enumerate}\n\\end{algorithm}\n\n\\begin{remark}\n  It might happen, that the value $t_k$ is just below $t_n$ with a\n  difference close to machine accuracy. As a result, the next time step\n  with $h_{k+1} \\approx \\epsilon_m$ would suffer from round-off\n  errors. Therefore, it is advisable to avoid this situation by\n  expanding the last time step, if $t_n-t_k \\le c h_{k+1}$ where $c$\n  is a moderate constant of size around $1.1$.\n\\end{remark}\n\n\\begin{remark}\n  This algorithm controls and equilibrates the local\n  error. Nevertheless, the global estimate still retains the\n  exponential term. The error estimation techniques in this section\n  are thus not optimal controlling the global error, which involves\n  considerably more effort and will be discussed in a later course.\n\\end{remark}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Extrapolation methods}\n\n\\begin{intro}\n  Here, we estimate the \\putindex{local error} by a method called\n  \\putindex{Richardson extrapolation}. It is based on computing two\n  approximations with the same method, but different step size, say\n  an approximation $y_2$ with two steps of size $h$ and an\n  approximation $\\hat y_2$ with one step of size $2h$.\n\\end{intro}\n\n\\input{theorems/richardson}\n\n\\begin{proof}\n  For the proof we need a refined version of the local error estimates\n  as well as the global error estimate in\n  Theorem~\\eqref{Theorem:convergence-one-step} which can be obtained by\n  adding one more step of Taylor expansion. Then, we get for the local\n  error of a method of order $p$ estimates of the form\n  \\begin{gather}\n    \\label{eq:explicit:21}\n    e_1 = u_1 - y_1 = C h^{p+1} + \\mathcal O(h^{p+2}),\n  \\end{gather}\n  with a constant (vector) $C$ with not necessarily positive\n  entries. In the same way, we refine the estimate for error\n  propagation from basic Lipschitz continuity to\n  \\begin{gather}\n    \\label{eq:explicit:22}\n    e_{2;\\text{acc}} = \\left( \\identity + h \\frac{\\partial f}{\\partial y} +\n      \\mathcal O(h^2)\\right) \\bigl(u_1-y_1).\n  \\end{gather}\n  The local error on the second interval is of the same structure\n  as~\\eqref{eq:explicit:21}, but on the interval starting at $t_1$\n  with initial value $y_1 = y_0 + \\mathcal O(h)$.\n\n  Thus, we obtain for the error after two steps of size $h$:\n  \\begin{multline}\n    \\label{eq:explicit:25}\n    u_2-y_2\n    = \\underbrace{\\bigl(\\identity + \\mathcal O(h)\\bigr) C\n      h^{p+1}}_{\\text{local 2}}\n    + \\bigl(C+\\mathcal O(h)\\bigr) h^{p+1} + \\mathcal\n      O(h^{p+2})\n    \\\\  = 2C h^{p+2} + \\mathcal O(h^{p+2}).\n  \\end{multline}\n  We compare this to a single step for $\\hat y$ with\n  \\begin{gather}\n    \\label{eq:explicit:23}\n    u_2 - \\hat y_2 = C (2h)^{p+1} + \\mathcal O(h^{p+2}).\n  \\end{gather}\n  Subtracting equations~\\eqref{eq:explicit:25}\n  and~\\eqref{eq:explicit:23}, we obtain\n  \\begin{gather*}\n    y_2 - \\hat y_2 = \\bigl(2-2^{p+1}\\bigr)C h^{p+1} + \\mathcal O(h^{p+2}),\n  \\end{gather*}\n  such that\n  \\begin{gather}\n    \\label{eq:explicit:26}\n    C h^{p+1} = \\frac{y_2 - \\hat y_2}{2^{p+1}-2} + \\mathcal O(h^{p+2}).\n  \\end{gather}\n  We enter this result into~\\eqref{eq:explicit:25} to conclude\n  \\begin{gather}\n    \\label{eq:explicit:27}\n    u_2 - y_2 = \\frac{y_2 - \\hat y_2}{2^{p}-1} + \\mathcal O(h^{p+2}).\n  \\end{gather}\n  Adding $y_2$ on both sides, we see that\n  \\begin{gather}\n    \\label{eq:explicit:28}\n    \\tilde y_2 = y_2 + \\frac{y_2 - \\hat y_2}{2^{p}-1}\n  \\end{gather}\n  approximates $u_2$ of order $\\mathcal O(h^{p+2})$ and thus one order\n  better than $y_2$.\n\\end{proof}\n\n\\begin{remark}\n  Formula~\\eqref{eq:explicit:10} can be evaluated after computation of\n  $y_2$ and $\\hat y_2$ in order to obtain an estimate for the local\n  error of $y_2$. This estimate can be used to control the step size\n  control according to the algorithm above. We do not have an\n  estimate for the error of $\\tilde y$. Nevertheless, we expect its\n  values to be more accurate, such that we should use $\\tilde y$ as\n  approximation and initial value for the next time step.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Embedded Runge-Kutta methods}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nInstead of estimating the \\putindex{local error} by doubling the step size,\nembedded Runge-Kutta methods use two methods of different order to\nachieve the same effect. The key to efficiency is here, that the\ncomputed stages $g_i$ are the same for both methods, and only the\nquadrature weights $b_i$ differ.\n\n\\begin{definition}[Embedded Runge-Kutta methods]\n  \\defindex{Runge-Kutta method!embedded} An embedded $\\rks$-stage\n  Runge-Kutta method with orders of consistence $p$ and $\\hat p$\n  computes two solutions $y$ and $\\hat y$ with the same function\n  evaluations. For this purpose we will first compute contributions\n  $g_i$ and $k_i$ for $i=1,\\dots,\\rks$ as in the normal Runge-Kutta\n  method of stage $\\rks$. The function values at the end of the time\n  step result as follows\n  \\begin{gather}\n    \\begin{split}\n      y_1 &= y_0 + h \\sum \\rkb_i k_i \\\\\n      \\hat y_1 &= y_0 + h \\sum \\hat \\rkb_i k_i.\n    \\end{split}\n  \\end{gather}\n  The methods for $y$ and $\\hat y$ are consistent of order $p$ and\n  $\\hat p$, respectively. We let $\\hat p < p$, for example\n  $\\hat p = p-1$. \n  \n  This can be achieved by e.g. using the same mathod twice and omitting\n  $\\hat{b}_j$ for one $j \\in \\{1, \\dots, s\\}$.\n\\end{definition}\n\n\\input{definitions/embedded-butcher}\n\n\\begin{remark}\n  For higher order methods or functions $f(t,u)$ with complicated\n  evaluation, most of the work lies in computation of the\n  stages. Thus, the additional quadrature for the computation of $\\hat\n  y$ is almost for free. Nevertheless, due to the different orders of\n  approximation, $y$ is much more accurate and we obtain\n  \\begin{gather}\n    \\label{eq:explicit:29}\n    u_1 - \\hat y_1 = y_1 - \\hat y_1 + \\mathcal O(h^p).\n  \\end{gather}\n  Thus, $y_1 - \\hat y_1$ is a good estimate for the \\putindex{local\n    error} of $\\hat y_1$. This is the error which is used in step size\n  control below. Similar to Richardson extrapolation above, we use the\n  more accurate value $y_1$ for further computation, even if we do not\n  have a computable estimate for its local error.\n\\end{remark}\n\n\\input{definitions/dormand-prince-45.tex}\n\n\\begin{remark}\n  The Dormand-Prince method of orders 4 and 5 has become a standard\n  tool for the integration of IVP. It is the backbone of\n  \\texttt{ode45} in Matlab.\n\\end{remark}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Continuous Runge-Kutta methods}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  The Runge-Kutta methods discussed so far compute highly accurate\n  approximations to the solution $u(t)$ in the discrete points\n  $(t_k)_{k=1,\\dots,n}$. Such approximations are useful, if only the\n  value at the interval end $t_n=T$ is needed, or if the time steps\n  are sufficiently small in order to generate a plot of the solution\n  history. There are some problems though, where the values in\n  discrete points are not sufficient:\n  \\begin{enumerate}\n  \\item The step size control managed to use very large steps from\n    which for instance a plot cannot read easily. Thus, we require the\n    solution in the continuum between two time steps.\n  \\item Accurate approximations inside an interval are required. This\n    may be due to the fact that we want to measure the length of a\n    period of a periodic solution, or that the equation contains\n    switches which change discretely when the solution attains certain\n    values.\n  \\end{enumerate}\n  In all of these cases, we need an interpolation formula for these\n  intermediate values. Unfortunately, as the example of the classical\n  Runge-Kutta method shows, the values $g_i$ have questionable value\n  in this business. Therefore, in order to be better than linear\n  interpolation between $y_{k-1}$ and $y_k$, we have to consider\n  formulas, which provide the information for accurate interpolation\n  with low additional cost.\n\\end{intro}\n\n\\begin{definition}\n  \\defindex{Runge-Kutta method!continuous}\n  A continuous Runge-Kutta method is a method of the same type as in \n  definition~\\ref{Definition:erk}, for which the coefficients $\\rkb_i$ are replaced \n\tby continuous functions $\\rkb_i(\\theta)$ on the interval $[0,1]$.\n  For this reason the equation~\\eqref{eq:explicit:1c} is augmented by\n  \\begin{equation}\n    \\label{eq:explicit:24}\n    y(t_0+ \\theta h) = y_0 + \\sum\\limits_{i=1}^{s^*} \\rkb_i (\\theta) k_i.\n  \\end{equation}\n  Here the stage number $\\rks^*$ may be higher than $\\rks$. \n  Then additional intermediate values $k_i$ have to be generated.\n\\end{definition}\n\n\\begin{remark}\n  The local error $u(t_0+\\theta h) - y(t_0+\\theta h)$ is of order\n  $p^*$ if the derivative $\\partial_\\theta^k y$ approximates\n  $\\partial_\\theta^k u$ with an error of order $h^{p^*-k+1}$. Note that\n  the first derivatives involve the derivatives of $g_i$ with respect\n  to $h$.\n  \n  For a later time, we observe that the error of the initial value of\n  an interval is only $\\mathcal O(h^p)$. Thus, an optimal continuous\n  formula balancing the global error of the original method with the\n  local error of the continuous method should be of order\n  $p^*=p-1$.\n\\end{remark}\n\n\\begin{remark}\n  If $\\rks^* > \\rks$ choose $k_{\\rks+1} = k_1 = f(t_n,y_1)$ of the next time step.\n\\end{remark}\n\n\\input{definitions/rk4-continuous}\n\\input{definitions/dormand-prince-45-continuous}\n\n\\begin{remark}\n  Collocation methods will provide a natural way to obtain continuous\n  method in the next chapter.\n\\end{remark}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End: \n", "meta": {"hexsha": "5db4d1711d42ac8fab5dbf4a0fa5c69625fc95f1", "size": 39889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/explicit.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/explicit.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/explicit.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": 39.9289289289, "max_line_length": 159, "alphanum_fraction": 0.6530371782, "num_tokens": 12914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.612804643266945}}
{"text": "\\documentclass[a4paper]{scrartcl}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{pgfplots}\n\\usepackage{amsmath, enumerate, amssymb, multirow, fancyhdr, color, graphicx, lastpage, listings, tikz, pdflscape, subfigure, float, polynom, hyperref, tabularx, forloop, geometry, listings, fancybox, tikz, forest, tabstackengine, cancel, bbm}\n\\input kvmacros\n\\geometry{a4paper,left=3cm, right=3cm, top=3cm, bottom=3cm}\n\\pagestyle {fancy}\n\n\n\\begin{document}\n\n\nWe assume $\\sigma$ is the weight matrix of a weighted undirected graph, so $\\sigma_{ij} = \\sigma_{ji}$ and $\\sigma_{ij} = 1$ if there is an edge between $i$ to $j$ and $\\sigma_{ij} = 0$ if there is no edge between $i$ and $j$.\nFor simplicity we assume that nodes are not self connected, that is $\\sigma_{ii} = 0$.\n\n\\section*{(a)}\n\n{\n\\color{green}\nTODO: Note the $\\leq$ instead of the $=$ in the following. This propagates through all formulas below!\n}\n\nFor $M$ to be a matching, it needs to hold by definition, that $$\\forall i:  \\sum_j \\sigma_{ij} \\leq 1$$ \nThis is equivalent to saying $$ \\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]} = 1 $$\nwhere $\\mathbbm{1}$ is the indicator function.\n\nSo we find the probability distribution\n\n\\begin{align}\n    P(M) = \\frac{1}{Z}\\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]}\n\\end{align}\n\nWhere $Z$ is the normalization wich is the count of all matchings \n\\begin{align}\n    Z = \\sum_{M \\in \\mathcal{G}} \\mathbbm{1}_{\\left[ \\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]} = 1 \\right]} \n\\end{align}\nHere $\\mathcal{G}$ is the set of all subsets of the graph.\n\n\\section*{(b)}\n\nThe size of a matching $\\lvert M \\rvert$ is the count of its edges. With the adjecency matrix $\\sigma$ that is the sum of all its elements divided by two: $$ \\lvert M \\rvert = \\frac{\\sum_{i} \\sum_{j} \\sigma_{ij}}{2}$$\n\nWe simply introduce the size of a matching $\\lvert M \\rvert$ as a scaling factor in the probability distribution, to give larger weight to larger matchings:\n\n\\begin{align}\n    P(M) = \\frac{1}{Z} \\lvert M \\rvert \\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]}\n\\end{align}\n\nwhich has new normalization factor\n\n\\begin{align}\n    Z = \\sum_{M \\in \\mathcal{G}} \\lvert M \\rvert \\cdot \\mathbbm{1}_{\\left[ \\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]} = 1 \\right]} \n\\end{align}\n\n\n\n% We have the size $S = M=\\sum_{ij} \\sigma^{ij}$ and the normalized version $S^*=\\frac{M}{\\lvert E \\rvert}$.\n\n{\\color{red}\nTODO I feel like there would be a way to integrate the scalar $\\lvert M \\rvert$ into the factor (in the product) but i can't find it. (Nevermind i don't think so anymore, with clarification 2 we don't need it anyways)\n}\n\n\\section*{(c)}\n\nThe Graph is given as:\n\n\\begin{tikzpicture}\n    [scale=1,auto=left,every node/.style={circle,draw}]\n    \\node (n1) at (1,3) {1};\n    \\node (n2) at (3,3)  {2};\n    \\node (n3) at (4,2)  {3};\n    \\node (n4) at (3,1) {4};\n    \\node (n5) at (1,1)  {5};\n    \\node (n6) at (0,2)  {6};\n  \n    \\foreach \\from/\\to in {n1/n2,n1/n3,n2/n3,n1/n4,n2/n5,n3/n6}\n      \\draw (\\from) -- (\\to);\n  \n\\end{tikzpicture}\n\nAn ordered drawing of this graph is:\n\n\n\\begin{tikzpicture}\n    [scale=1,auto=left,every node/.style={circle,draw}]\n    \\node (n1) at (1,4) {1};\n    \\node (n2) at (3,3)  {2};\n    \\node (n3) at (5,4)  {3};\n    \\node (n4) at (1,1) {4};\n    \\node (n5) at (3,1)  {5};\n    \\node (n6) at (5,1)  {6};\n  \n    \\foreach \\from/\\to in {n1/n2,n1/n3,n2/n3,n1/n4,n2/n5,n3/n6}\n      \\draw (\\from) -- (\\to);\n  \n\\end{tikzpicture}\n  \n\n\n\n\n\nIn general the probability distribution found above is given as\n\\begin{align}\n    P(M) = \\frac{1}{Z}\\prod_i \\mathbbm{1}_{\\left[\\sum_j \\sigma_{ij} \\leq 1\\right]}\n\\end{align}\nWhich we can write as \n\\begin{align}\n    P(M) = \\frac{1}{Z} \\prod_i \\psi_i(\\partial M)\n\\end{align}\nwith factors\n\\begin{align}\n    \\psi_i(\\partial M) = \\mathbbm{1}_{\\left[ \\sum_j \\sigma_{ij} \\leq 1 \\right]}\n\\end{align}\n\nBy $\\partial M$ we denote, that each factor $\\psi_i$ is only connected to all nodes $\\sigma_{ij}$ for which there is a connection from $i$ to $j$, so for all nodes for which $\\sigma_{ij} = 1$ in the initial graph $G$.\n\n\nIn general to draw a factor graph we would start with a graph with all $\\sigma_{ij}$ connected to all factors $\\psi_i$. Then we can omit all $\\sigma_{ij}$ where $\\sigma_{ij} = 0$ in the initial graph $G$. Furthermore we can omit all connections from factors $\\psi_i$ to $\\sigma_{ij}$ if $i$ and $j$ are not connected. \n\nFor the graph given here this yields the factor graph:\n\n\\begin{tikzpicture}\n    [scale=1,auto=left,every node/.style={circle,draw}]\n    \\node (s12) at (4,6) {$\\sigma_{12}$};\n    \\node (s13) at (4,5) {$\\sigma_{13}$};\n    \\node (s23) at (4,4) {$\\sigma_{23}$};\n    \\node (s14) at (4,3) {$\\sigma_{14}$};\n    \\node (s25) at (4,2) {$\\sigma_{25}$};\n    \\node (s36) at (4,1) {$\\sigma_{36}$};\n  \n    \\node[rectangle] (f1) at (1,6) {$\\psi_{1}$};\n    \\node[rectangle] (f2) at (1,5) {$\\psi_{2}$};\n    \\node[rectangle] (f3) at (1,4) {$\\psi_{3}$};\n    \\node[rectangle] (f4) at (1,3) {$\\psi_{4}$};\n    \\node[rectangle] (f5) at (1,2) {$\\psi_{5}$};\n    \\node[rectangle] (f6) at (1,1) {$\\psi_{6}$};\n  \n\n\n    \\foreach \\from/\\to in {f1/s12,f1/s13,f1/s14,f2/s12,f2/s23,f2/s25,f3/s13,f3/s23,f3/s36,f4/s14,f5/s25,f6/s36}\n      \\draw (\\from) -- (\\to);\n  \n\\end{tikzpicture}\n\n\n\n{\\color{red}\nTODO Is this also so simple for the probability distribution scaled by matching size $\\lvert M \\rvert$? (Nevermind, is saw Clarification 2)\n}\n\n\n\n\n\n\n\n\n\n\n\n\\section*{(d)}\n\nThe general definitions are given as:\n\\begin{align}\n    \\nu_{i \\rightarrow a}^{(t + 1)}(x_i) &\\cong \\prod_{b \\in \\partial i \\backslash a} \\hat{\\nu}_{b \\rightarrow i}^{(t)}(x_i) \\\\\n    \\hat{\\nu}_{a \\rightarrow i}^{(t)}(x_i) &\\cong \\sum_{\\textbf{x}_{\\partial a} \\backslash i} \\psi_a (\\textbf{x}_{\\partial a}) \\prod_{j \\in \\partial a \\backslash i} \\nu_{j \\rightarrow a}^{(t)}(x_j) \\\\\n    P(x_i) &= \\nu_i^{(t)}(x_i) \\cong \\prod_{a \\in \\partial i} \\hat{\\nu}_{a \\rightarrow i}^{(t-1)}(x_i)\n\\end{align}\n\n\nIn our case we have messages from variable to factor:\n\\begin{align}\n    \\nu_{\\sigma_{ij}}^{(ij) \\rightarrow i} &\\cong \\prod_{b \\in \\partial (ij) \\backslash i} \\hat{\\nu}_{\\sigma_{ij}}^{b \\rightarrow (ij)} \\\\\n    &= \\hat{\\nu}_{\\sigma_{ij}}^{j \\rightarrow (ij)}\n\\end{align}\nThis simplification comes, since variable $(ij)$ only has one other neighbouring factor except $i$, which is $j$. \\\\\n\nAnd messages from factor to variable:\n\\begin{align}\n    \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} \\cong \\sum_{\\boldsymbol{\\sigma}_{\\partial i} \\backslash (ij)} \n    \\psi_i(\\boldsymbol{\\sigma}_{\\partial i}) \\prod_{(ik) \\in \\partial i \\backslash (ij)} \\nu_{\\sigma_{ik}}^{(ik) \\rightarrow i}\n\\end{align}\n\nFor our problem this leads to messages from factor to variable:\n\\begin{align}\n    \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} &\\cong \\sum_{\\boldsymbol{\\sigma}_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{il} \\leq 1 \\right]} \\prod_{(ik) \\in \\partial i \\backslash (ij)} \\nu_{\\sigma_{ik}}^{(ik) \\rightarrow i}\\\\\n\\end{align}\n\n\n{\n\\color{green}\nNote here that the sum is over all the values that the $\\sigma$ which are neighbours of $i$ could assume.\n}\n\n\nThe marginal is:\n\\begin{align}\n    P(\\sigma_{ij}) &\\cong \\prod_{b \\in \\partial (ij)} \\hat{\\nu}_{\\sigma_{ij}}^{b \\rightarrow (ij)} \\\\\n    &= \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} \\cdot \\hat{\\nu}_{\\sigma_{ij}}^{j \\rightarrow (ij)}\n\\end{align}\n\n\n\n{\n\\color{green}\nTODO: I don't know if we have to write something for the second hint, but this would be the following?\n}\n\nIn the following we find some derivations for the adjecent edges if $\\sigma_{ij} = 1$ and $\\sigma_{ij} = 0$:\n\nFor $\\sigma_{ij} = 1$ this leads to \n\\begin{align}\n    P(\\sigma_{ij} = 1) &\\cong \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} \\cdot \\hat{\\nu}_{\\sigma_{ij}}^{j \\rightarrow (ij)} \\\\\n    &= \\left[ \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{il} \\leq 1 \\right]} \\prod_{(ik) \\in \\partial i \\backslash (ij)} \\nu_{\\sigma_{ik}}^{(ik) \\rightarrow i} \\right]\n     \\cdot \\left[ \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{jl} \\leq 1 \\right]} \\prod_{(jk) \\in \\partial j \\backslash (ij)} \\nu_{\\sigma_{jk}}^{(jk) \\rightarrow j} \\right]\n\\end{align}\nWhich can only be $\\geq 0$ if \n\\begin{align}\n    \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{il} \\leq 1 \\right]} &= 1 \\\\\n    \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_{l \\backslash (l = j)} \\sigma_{il} + 1 \\leq 1 \\right]} &= 1 \\\\\n\\end{align}\nand \n\\begin{align}\n    \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{jl} \\leq 1 \\right]} &= 1 \\\\\n    \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_{l \\backslash (l = i)} \\sigma_{jl} + 1 \\leq 1 \\right]} &= 1\n\\end{align}\n\nThis is saying that all edges adjecent to $i$ and $j$ except edge $(ij)$ have to be zero, meaning non existant. \n\n\nFor $\\sigma_{ij} = 0$ we find with similar reasoning:\n\n\\begin{align}\n    P(\\sigma_{ij} = 0) &\\cong \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} \\cdot \\hat{\\nu}_{\\sigma_{ij}}^{j \\rightarrow (ij)} \\\\\n    &= \\left[ \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{il} \\leq 1 \\right]} \\prod_{(ik) \\in \\partial i \\backslash (ij)} \\nu_{\\sigma_{ik}}^{(ik) \\rightarrow i} \\right]\n     \\cdot \\left[ \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{jl} \\leq 1 \\right]} \\prod_{(jk) \\in \\partial j \\backslash (ij)} \\nu_{\\sigma_{jk}}^{(jk) \\rightarrow j} \\right]\n\\end{align}\nWhich can only be $\\geq 0$ if \n\\begin{align}\n    \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{il} \\leq 1 \\right]} &= 1 \\\\\n    \\sum_{\\sigma_{\\partial i} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_{l \\backslash (l = j)} \\sigma_{il} + 0 \\leq 1 \\right]} &= 1 \\\\\n\\end{align}\nand \n\\begin{align}\n    \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_l \\sigma_{jl} \\leq 1 \\right]} &= 1 \\\\\n    \\sum_{\\sigma_{\\partial j} \\backslash (ij)} \\mathbbm{1}_{\\left[\\sum_{l \\backslash (l = i)} \\sigma_{jl} + 0 \\leq 1 \\right]} &= 1\n\\end{align}\n\nWhich is saying that any one, but no more than one of the edges adjecent to $i$ except $(ij)$ may be 1 and that any one, but no more than one of the edges adjecent to $j$ except $(ij)$ may be 1. \nIf we use $c_i$ and $c_j$ as the count of edges adjecent to $i$ and $j$ except for edge $(ij)$ respectively, we can say that this allows $c_i+1$ configurations for the edges adjecent to $i$ and $c_j + 1$ configurations for the edges adjecent to $j$ (Any one may be 1 or all are 0).\n\nThese derivations are intuitively consistent with the definitions of the matching.\n\n\n\n\n\n{\n\\color{green}\nTODO i don't quite get the following, from the reasoning it makes sense but i don't see how it follows from the formulas\n\n\nFor $\\sigma_{ij}=1$, this leads to:\n\\begin{align}\n    P(\\sigma_{ij}=1) =  \\prod_{\\sigma_{ik} \\in \\partial a \\backslash i} v_{\\sigma_{ik} \\rightarrow i}(0)\n\\end{align}\nwich intuitively makes sense, since all the others have to be 0 in order for $\\sigma_{ij}$ to be 1.\\\\\nFor $\\sigma_{ij}=0$, this leads to:\n\\begin{align}\n    P(\\sigma_{ij}=1) = \\sum_{\\sigma_{ik} \\in \\partial i \\backslash \\sigma_{ij}} (\\mathbbm{1}^{(\\sum_{l \\backslash i} \\sigma_{il} = 1)} \\prod_{\\sigma_{ik} \\in \\partial a \\backslash i} v_{\\sigma_{ik} \\rightarrow i}(\\sigma_{ik}))\\\\\n\\end{align}\nhere the main difference is that the factor $\\Psi_{i}$ doesn't sum over $\\sigma_{ij}$ anymore, since it is set to 0.\n}\n\n\n\n\n\n{\n\\color{red}\nWe have the messages from variable to factor:\n\\begin{align}\n    \\hat{v}_{i \\rightarrow \\alpha}(x_i) = \\prod_{\\beta \\in \\partial \\alpha \\backslash i} \\hat{v}_{b \\rightarrow i}(x_i)\n\\end{align}\nand factor to variable:\n\\begin{align}\n    \\hat{v}_{\\alpha \\rightarrow i}(x_i) = \\sum_{x \\in \\partial \\alpha \\backslash i} (\\Psi_a(X_{\\partial a}) \\prod_{j \\in \\partial a \\backslash i} v_{j \\rightarrow a}(x_j))\n\\end{align}\n\nThe general BP marginal is:\n\\begin{align}\n    P(x_i) = v_i(x_i) = \\prod_{a \\in \\partial i} \\hat{v}_{\\alpha \\rightarrow i}(x_i)\n\\end{align}\n\nFor our problem, this leads to to message from factor to variable:\n\\begin{align}\n    \\hat{v}_{i \\rightarrow \\sigma_{ij}}(\\sigma_{ij}) &= \\sum_{\\sigma_{ik} \\in \\partial i \\backslash \\sigma{ij}} (\\mathbbm{1}^{(\\sum_l \\sigma^{il} = 1)} \\prod_{\\sigma_{ik} \\in \\partial a \\backslash i} v_{\\sigma_{ik} \\rightarrow i}(\\sigma_{ik}))\\\\\n\\end{align}\n\nThis means the marginal is:\n\\begin{align}\n    P(\\sigma_{ij}) = \\hat{v}_{i \\rightarrow \\sigma_{ij}}(\\sigma_{ij}) \\cdot \\hat{v}_{j \\rightarrow \\sigma_{ij}}(\\sigma_{ij})\n\\end{align}\nFor $\\sigma_{ij}=1$, this leads to:\n\\begin{align}\n    P(\\sigma_{ij}=1) =  \\prod_{\\sigma_{ik} \\in \\partial a \\backslash i} v_{\\sigma_{ik} \\rightarrow i}(0)\n\\end{align}\nwich intuitively makes sense, since all the others have to be 0 in order for $\\sigma_{ij}$ to be 1.\\\\\nFor $\\sigma_{ij}=0$, this leads to:\n\\begin{align}\n    P(\\sigma_{ij}=1) = \\sum_{\\sigma_{ik} \\in \\partial i \\backslash \\sigma_{ij}} (\\mathbbm{1}^{(\\sum_{l \\backslash i} \\sigma_{il} = 1)} \\prod_{\\sigma_{ik} \\in \\partial a \\backslash i} v_{\\sigma_{ik} \\rightarrow i}(\\sigma_{ik}))\\\\\n\\end{align}\nhere the main difference is that the factor $\\Psi_{i}$ doesn't sum over $\\sigma_{ij}$ anymore, since it is set to 0.\n\n\n}\n\n\n\n\n\n\n\\section*{(d)}\n{\n\\color{green}\nTODO: To get the full marginal we would need to do the full message passing. For the equations the following suffices:\n\n}\n\nFor one point marginal, see (c):\n\\begin{align}\n    P(\\sigma_{ij}) &\\cong \\hat{\\nu}_{\\sigma_{ij}}^{i \\rightarrow (ij)} \\cdot \\hat{\\nu}_{\\sigma_{ij}}^{j \\rightarrow (ij)}\n\\end{align}\n\n\nFor two point marginal, we have:\n\\begin{align}\n    P(\\sigma_{ij}, \\sigma_{kl}) = P(\\sigma_{kl} \\vert \\sigma_{ij}) P(\\sigma_{ij})\n\\end{align}\n\nIn addition to the one point marginal we need to  find $P(\\sigma_{kl} \\vert \\sigma_{ij})$ which is defined by:\n\\begin{align}\n    P(\\sigma_{kl} \\vert \\sigma_{ij} = x) &\\cong \\prod_{a} \\psi_a(\\boldsymbol{\\sigma}_{\\partial a}) \\mathbbm{1}_{\\left[ \\sigma_{ij} = x \\right]} \\\\\n    &= \\prod_{a} \\mathbbm{1}_{\\left[ \\sum_{l} \\sigma_{al} \\leq 1 \\right]} \\mathbbm{1}_{\\left[ \\sigma_{ij} = x \\right]}\n\\end{align}\n\nThis is, we add to the original factor graph a node of degree 1 connected to the variable node $\\sigma_{ij}$ which fixes $\\sigma_{ij} = x$ and run BP on this modified factor graph.\n\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "4f67579514acdb98f3a2dc820670e44d47a433f9", "size": 14358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment/assignment.tex", "max_stars_repo_name": "philippvb/APMLA-WS_21-22_material", "max_stars_repo_head_hexsha": "e2e3ccfe393f47b1e78ea481e59d98cb784b1f1e", "max_stars_repo_licenses": ["MIT"], "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/assignment.tex", "max_issues_repo_name": "philippvb/APMLA-WS_21-22_material", "max_issues_repo_head_hexsha": "e2e3ccfe393f47b1e78ea481e59d98cb784b1f1e", "max_issues_repo_licenses": ["MIT"], "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": "philippvb/APMLA-WS_21-22_material", "max_forks_repo_head_hexsha": "e2e3ccfe393f47b1e78ea481e59d98cb784b1f1e", "max_forks_repo_licenses": ["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.3314606742, "max_line_length": 318, "alphanum_fraction": 0.6450759159, "num_tokens": 5176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6128046398490794}}
{"text": "\\section{Gale Games}\n\\label{gale-games-sect}\n\nWe now apply Theorem \\ref{origgale-thm} to the study of bimatrix games.\nBy Proposition \\ref{nash-to-acl}, solving 2-{\\sc Nash} can be reduced to\n{\\sc Another Completely Labeled Facet}; if the polytope $P^\\Delta$ in\nTheorem \\ref{unit-vector-dual-thm} is cyclic, we can exploit\nTheorem~\\ref{origgale-thm} to translate this special case of 2-{\\sc Nash}\nto a problem on Gale strings.\n\n\nFirst of all, we have to define a labeling on Gale strings such that a\ncompletely labeled Gale string corresponds to a completely labeled facet\nof~$P^\\Delta$.\nWe say that $s\\in G(d,n)$ is a {\\em completely labeled Gale string}\nfor some labeling function $l_s:[n]\\to[d]$ if\n$\\{ l_s(i)\\,\\mid\\,s(i)=\\1\\text{ for }i\\in [n] \\}=[d]$.\nSince a string in $G(d,n)$ has exacty $d$ bits equal to \\1, a Gale string\nis completely labeled if and only if for each $j\\in [d]$ there is exactly\none $i\\in [n]$ such that $s(i)=\\1$ and $l_s(i)=j$.\n\nNotice that, given a labeling $l_s:[n]\\to[d]$, it may not always be\npossible to find a Gale string $s\\in G(d,n)$ that is completely labeled\nby $l_s$.\n\n\\begin{example}\n\\label{no-clgs}\nFor $l_s = 121314$, there are no completely labeled Gale strings.\n\nThe labels $l_s(i)=2,3,4$ appear only once in $l_s$, so we must have\n$s(2)=s(4)=s(6)=1$. We also must have $l_s(i)=1$ for exactly one $i=1,3,5$.\nThe candidate strings are then $s_1=\\1\\10\\10\\1$, $s_2=0\\1\\1\\10\\1$,\n$s_3=0\\10\\1\\1\\1$, but none of these satisfies the Gale Evenness Condition.\n\\end{example}\n\nA {\\em Gale game} is a unit vector game $(U,B)$ where\n$U=[e_{l(1)}\\cdots e_{l(d)}]$ for some labeling $l:[n]\\to [d]$ and\nfor which the dual of the best response polytope is a cyclic polytope\n$P^\\Delta=\\conv\\{ e_1,\\ldots,e_d,c_1,\\ldots,c_n \\}$.\nWe define the problem {\\sc Gale Nash} as in Table~\\ref{gale-nash-pbl}\n\n\\begin{problem}\n{Gale Nash}\n{A Gale game.}\n{A Nash equilibrium of the game.}\n\\label{gale-nash-pbl}\n\\end{problem}\n\nTheorem\n\\ref{unit-vector-dual-thm} gives the labeling (\\ref{vert-labeling-unitv})\nfor the $d+n$ vertices of $P^\\Delta$ as\n\\[\n\\arraycolsep.2em\n\\begin{array}{rcll}\nl_v(-e_i)&=&i\\quad & \\text{ for }i\\in [d],\\\\\nl_v(c_j)&=&l(j)\\quad & \\text{ for }j\\in [n].\n\\end{array}\n\\]\nWe define the labeling $l_s:[d+n]\\to [d]$ of $G(d,n)$ as\n\\begin{equation}\n\\label{gs-labeling-unitv}\n\\arraycolsep.2em\n\\begin{array}{rcll}\nl_s(i)&=&i\\quad & \\text{ for }i\\in [d],\\\\\nl_s(d+j)&=&l(j)\\quad & \\text{ for }j\\in [n].\n\\end{array}\n\\end{equation}\nThen the Gale strings $s\\in G(d,d+n)$ that are completely labeled by $l_s$\ncorrespond exactly to facets of $P^\\Delta$ that are completely labeled by $l_v$,\nwith the facet $F_0$ corresponding to the ``trivial'' completely labeled\nstring $\\1^d 0^n$.\n\n\\begin{example}\n\\label{c46-123432-ex}\nGiven the string of labels $l_s=123432$, there are four associated completely\nlabeled Gale strings in $G(4,6)$:\n$s_A=\\1\\1\\1\\100$, $s_B=\\1\\10\\1\\10$,\n$s_C=\\100\\1\\1\\1$ and\n$s_D=\\10\\1\\10\\1$. These correspond to the completely labeled facets\nfor the labeling shown in Figure \\ref{c46-123432-fig} on the left.\n\\begin{figure}[hbt]\n\\strut\\hfill\n\\includegraphics[width=50ex]{chapter-2/fig-gale-games/123432-facets.pdf}%\n\\hfill\n\\small\n\\begin{tabular}{c | c @{ } c @{ } c @{ } c @{ } c @{ } c @{ } c }\nfacet & {\\bf 1} & {\\bf 2} & {\\bf 3} & {\\bf 4} & {\\bf 3} & {\\bf 2}\\\\\n\\hline\n{\\bf\\it{A}} & \\1 & \\1 & \\1 & \\1 & 0 & 0 \\\\\n{\\bf\\it{B}} & \\1 & \\1 & 0 & \\1 & \\1 & 0 \\\\\n{\\bf\\it{C}} & \\1 & 0 & 0 & \\1 & \\1 & \\1 \\\\\n{\\bf\\it{D}} & \\1 & 0 & \\1 & \\1 & 0 & \\1\n\\end{tabular}\n\\hfill\\strut\n\\caption[A labeling of $C_4(6)$ and its completely labeled facets]{%\nThe cyclic polytope $C_4(6)$, where the labeling of the vertices\ncorresponds to the labeling of $G(4,6)$ given by $l_s=123432$.\n\nThe\ncompletely labeled\nfacets $A$, $B$, $C$ and $D$ correspond respectively to the completely Gale\nstrings  $s_A=\\1\\1\\1\\100$, $s_B=\\1\\10\\1\\10$, $s_C=\\100\\1\\1\\1$ and\n$s_D=\\10\\1\\10\\1$.\n}\n\\label{c46-123432-fig}\n\\end{figure}\n\\end{example}\n\nFrom this point forward, we will assume that the labeling\n$l_s:[d+n]\\to [d]$ satisfies\n$l_s(i)\\neq l_s(i+1)$. This can be done without loss of generality,\ngiven the following consideration.\nSuppose that $l_s(i)=l_s(i + 1)$ for some index $i$, and let $s$ be a\ncompletely labeled Gale string for $l_s$. Then only one of\n$s(i)$ and $s(i+1)$ can be equal to \\1 (it is possible that both\nare equal to~0), so $s(i)s(i+1)$ will never be part of a run of even length\nthat ``interferes'' with the Gale Evenness Condition. Therefore, we can\nidentify the indices $i$ and $i + 1$.\n\nWe can now define the problem \\anothergale\\ as in Table\n\\ref{another-gale}. For brevity, we change the notation from $d+n$ to $n$.\n\n\\begin{problem}\n{\\anothergale}\n{A labeling $l:[n]\\to[d]$, where $d<n$.\nA Gale string $s\\in G(d,n)$, completely labeled by $l$.}\n{A Gale string $s_0\\in G(d,n)$, completely labeled by $l$,\nsuch that $s_0 \\neq s$.}\n\\label{another-gale}\n\\end{problem}\n\nIt takes polynomial time to translate the facets of the cyclic polytope\n$C_d(d+n)$ % can be translated in polynomial time\ninto the corresponding Gale strings in $G(d,d+n)$, following\nthe proof of Theorem~\\ref{origgale-thm}.\nDefining the labeling $l_s$ from the labeling $l_v$ also takes\npolynomial time: for the labels $i\\in [d]$ it is immediate, for the labels\n$d+j$, where $j\\in [n]$, we have to check the $d\\times n$ matrix $U$\nof the imitation game.\nTherefore, by Proposition \\ref{nash-to-acl}, we have a reduction from\n{\\sc Gale Nash} to \\anothergale.\n\n\\begin{proposition}\n\\label{galenash-to-another-gale}\nThe problem {\\sc Gale Nash} of Table~\\ref{gale-nash-pbl} is\npolynomial-time reducible to the problem \\anothergale\\ of\nTable~\\ref{another-gale}.\n\\end{proposition}\n\nProposition~\\ref{galenash-to-another-gale} can be improved: it is enough to\nconsider the case where $d$ is even.\n\n\\begin{proposition}\n\\label{d-even-another-gale}\nThe problem \\anothergale\\ of Table~\\ref{another-gale} is reducible to\nthe case where $d$ is even.\n\\begin{proof}\nConsider an instance of the problem \\anothergale\\ with $d$ odd.\n\nLet $s_0'\\in G(d+1,n+1)$ be the string defined as\n\\[\n\\arraycolsep.2em\n\\begin{array}{ll}\ns_0'(i)=s_0(i) & \\text{ for }i\\in [n],\\\\\ns_0'(n+1)=1.\\quad &\n\\end{array}\n\\]\n% $s_0'(i)=s_0(i)$ for $i\\in [n]$ and $s_0'(n+1)=1$.\nThis is indeed a Gale string. It is trivial to see that there are\nexactly $d+1$ bits equal to \\1; furthermore, since $s_0$ is a Gale string,\nthe Gale Evenness Condition holds in all the interior runs of $s_0'$.\nLet now $l':[n+1]\\to[d+1]$ be the labeling defined as\n\\begin{equation}\n\\label{extended-labeling}\n\\arraycolsep.2em\n\\begin{array}{ll}\nl'(i)=l(i) & \\text{ for }i\\in [n],\\\\\nl'(n+1)=d+1.\\quad &\n\\end{array}\n\\end{equation}\nNotice that $s_0'$ is completely labeled by $l'$, since for every\nfor each $j\\in [d]$ there is exactly one $i\\in [n]$ such that\n$s_0'(i)=s_0(i)=\\1$ and $l_s(i)=j$, and the only occurrence of the label\n$d+1$ is at index $n+1$, where $s_0'(n+1)=\\1$.\n\nLet $s'$ be any bitstring of length $n+1$ such that $s'(n+1)=1$, and let\n$s$ be the bitstring of length $n$ such that $s(i)=s'(i)$ for $i\\in [n]$.\nFirst of all, notice that if $s'\\in G(d+1,n+1)$ then $s\\in G(d,n)$:\nit is obtained by removing a bit that is equal to \\1, and the Gale\nEvenness Condition still holds in all the interior runs.\nFurthermore, if $s'$ is completely labeled for $l'$, then $s'(n+1)=1$,\nsince the only occurrence of label $d+1$ is at index $n+1$ and for all\nthe other labels $j\\in [d]$ there is exactly one $i\\in [n]$ such that\n$s(i)=\\1$ and $l_s(i)=j$.\n\nTherefore, a solution for the original instance of \\anothergale\\ can be\nfound by solving the problem \\anothergale\\ with input $s_0'$ and $l'$ and\noutput $s'$, then considering the corresponding completely labeled Gale\nstring $s\\in G(d,n)$ defined as above.\n\\end{proof}\n\\end{proposition}\n", "meta": {"hexsha": "882d78f58af25dd294ed82c0b3265c7bfa9fb911", "size": 7760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-2/gale-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-2/gale-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-2/gale-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": 38.4158415842, "max_line_length": 80, "alphanum_fraction": 0.6807989691, "num_tokens": 2781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6128046388957074}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\title{A Simple Solver for Matrix Equations}\n\\author{Andrew Winkler, Ph.~D.}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Abstract}\n\nWe derive a solver for linear systems \\begin{math}{}Ax=b\\end{math}, which works for real, complex, rational,\nand certain other scalars. It is related to the Cholesky decomposition, but sidesteps creating a factorization\nto directly construct the solution. We include a C implementation of the most important case, that where\nreal numbers are represented as double precision numbers and the matrix \\begin{math}A\\end{math} is symmetric and positive semi-definite.\n\n\\section{Preliminaries}\n\nWe consider the linear system \\begin{math}{}Ax=b\\end{math}. If your only interest is in the real numbers,\nyou can skip the rest of this section with the notation that \\begin{math}{}A^*\\end{math} means the transpose of the matrix \\begin{math}{}A\\end{math}. In particular a number, which can be seen as a 1x1 matrix, is its own transpose.\n\nThe algorithm we describe works perfectly well for finite dimensional Hilbert spaces over various fields, to be described. However, since the method implicitly constructs a basis for the vector space, for ease of exposition and with no real loss of generality, we assume already chosen an orthonormal basis, with respect to which A is a matrix, and x and b are column vectors.\n\nWe can view rational numbers as lying in the larger field of real numbers; likewise the real numbers in the complex numbers, and the complex numbers in the quaternions. A quaternion satisfies \\begin{math}{}(a + bi +cj + dk)^* = (a -bi -cj -dk)\\end{math}, from which it is immediate that \\begin{math}{}q^*q = a^2 + b^2 + c^2 + d^2 >= 0\\end{math}. Moreover if \\begin{math}{}q^*q =0\\end{math} then \\begin{math}{}q =0\\end{math}. If\n\\begin{math}{}q* = q\\end{math} then \\begin{math}q\\end{math} is real, and conversely.\n\nThe algorithm assumes only that the field is some subfield of the quaternions, which is closed under this conjugation operation, which is the same thing as saying that if \\begin{math}{}\\alpha\\end{math} is in the field, so is \\begin{math}{}\\alpha^*\\alpha\\end{math}, or equivalently \\begin{math}{}\\alpha + \\alpha^*\\end{math}. This is of course true of the rationals, the reals, any subfield of the reals, the complexes, and the quaternions.\n\nRecall that the adjoint of a matrix \\begin{math}A\\end{math}, denoted \\begin{math}A^*\\end{math}, is the transpose of the matrix obtained from \\begin{math}A\\end{math} by replacing each number \\begin{math}{}a_{ij}\\end{math} by its complex/quaternion conjugate \\begin{math}{}a_{ij}^*\\end{math}.\n\n\\section{Linear Equations}\n\nWe seek all \\begin{math}{}x\\end{math} for which \\begin{math}{}Ax=b\\end{math}. We start by noticing that if\n\\begin{math}{}Ax=b\\end{math}, then also \\begin{math}{}A^*Ax=A^*b\\end{math}. The converse need not be true,\nbut \\begin{math}{}\\{x|Ax=b\\} \\subset \\{x|A^*Ax = A^*b\\}\\end{math}, and in fact it's the simplest sort of subset:\nit's either empty, or it's everything. To see this, note that if \\begin{math}{}A^*Ax_1 = A^*Ax_2 \\end{math},\nthen \\begin{math}{}A^*A(x_1-x_2)=0 \\end{math}, so \\begin{math}{}0=(x_1-x_2)^*A^*A(x_1-x_2)=(A(x_1-x_2))^*(A(x_1-x_2)) \\end{math}. But then \\begin{math}{}A(x_1-x_2)=0 \\end{math}, or \\begin{math}{}Ax_1 = Ax_2 \\end{math}.\n\nIn summary if \\begin{math}{}A^*Ax_1 = A^*Ax_2 = A^*b \\end{math}, then either \\begin{math}{}Ax_1 = Ax_2 = b \\end{math}, or else \\begin{math}{}Ax_1 = Ax_2 \\ne b \\end{math}, in which case there is no solution. \n\nSo having found all solutions to the auxiliary equation, either they are precisely the solutions to the original equation, or the original equation has no solutions, as determined by picking any one of the candidate solutions and computing \\begin{math}{}Ax\\end{math}.\n\nNotice that \\begin{math}{}(A^*A)^* = A^*A^{**} = A^*A\\end{math}, and that \\begin{math}{}x^*(A^*A)x=(Ax)^*(Ax) >= 0\\end{math}. Thus the general problem reduces to the special case considered in the next section.\n\n\\section{Linear Positive Equations}\n\nWe consider then the problem \\begin{math}{}Ax=b\\end{math} in the special case where\n\\begin{math}{}A^*=A\\end{math} and \\begin{math}{}x^*Ax >= 0\\end{math} for all \\begin{math}{}x\\end{math}. Such a matrix is called positive semi-definite.\n\nWe write \\begin{math}{}A\\end{math} as \\begin{math}{}\\begin{bmatrix}\\alpha & b^* \\\\ a & A^{'}\\end{bmatrix}\\end{math}. It is possible\nthat \\begin{math}{}A\\end{math} is 1x1 in which case all expressions involving\n\\begin{math}{}A\\end{math},\n\\begin{math}{}a\\end{math}, or\n\\begin{math}{}b\\end{math} are empty sums, and therefor 0. If \n\\begin{math}{}A\\end{math} is \n\\begin{math}{}n\\end{math} by\n\\begin{math}{}n\\end{math}, then \n\\begin{math}{}A^{'}\\end{math} is \n\\begin{math}{}n-1\\end{math} by\n\\begin{math}{}n-1\\end{math}, and\n\\begin{math}{}a\\end{math} and\n\\begin{math}{}b\\end{math} are \n\\begin{math}{}n-1\\end{math} column vectors, while\n\\begin{math}{}\\alpha\\end{math} is a scalar.\n\nSince \\begin{math}{}A=A^*\\end{math}, \n \\begin{math}{}\n\\begin{bmatrix}\\alpha & b^* \\\\ a & A^{'}\\end{bmatrix} = \n\\begin{bmatrix}\\alpha & b^* \\\\ a & A^{'}\\end{bmatrix}^* = \n\\begin{bmatrix}\\alpha^* & a^* \\\\ b & A^{'*}\\end{bmatrix} \\end{math}, so \n\\begin{math}{}\\alpha^*=\\alpha\\end{math}, \\begin{math}{}a=b\\end{math}, and\n\\begin{math}{}A^{'*} = A^{'}\\end{math}.\n\nMoreover, \n\\begin{math}{}\n0 <= \\begin{bmatrix}1\\\\0\\end{bmatrix}^*\\begin{bmatrix}\\alpha & a^* \\\\ a & A^{'}\\end{bmatrix}\\begin{bmatrix}1\\\\0\\end{bmatrix}\n= \\begin{bmatrix}1&0\\end{bmatrix}\\begin{bmatrix}\\alpha \\\\ a\\end{bmatrix}\n= \\alpha\n\\end{math}\n\n\\subsection{Case 1}\n\\begin{math}{}\\alpha=0\\end{math}\n\nThen in fact it's also true that \\begin{math}{}a=0\\end{math}. For \n\\begin{math}0 <= \\begin{bmatrix}\\chi\\\\a\\end{bmatrix}^*\\begin{bmatrix}0 & a^* \\\\ a & A^{'}\\end{bmatrix}\\begin{bmatrix}\\chi\\\\a\\end{bmatrix} = \\begin{bmatrix}\\chi^* & a^*\\end{bmatrix} \\begin{bmatrix}a^*a\\\\a\\chi+A^{'}a\\end{bmatrix}\n= \\chi^*a^*a + a^*a\\chi + a^*A^{'}a\n\\end{math}.\n\nNotice that it is here that we make use of the assumption that we started with\na positive semi-definite matrix.\n\nIf we restrict attention to rational numbers, then we get the equation of a line. The only lines that have no negative values are horizontal, so the slope \\begin{math}{}2a^*a\\end{math} must be zero, which means \\begin{math}{}a\\end{math} must be zero.\n\nOur equation simplifies to \n\\begin{math}{}\n\\begin{bmatrix}0 & 0 \\\\ 0 & A^{'}\\end{bmatrix}\\begin{bmatrix}\\chi\\\\x^{'}\\end{bmatrix} =\\begin{bmatrix}\\beta\\\\b^{'}\\end{bmatrix}\n\\end{math}, which reduces to the pair of equations \\begin{math}0=\\beta{}\\end{math}, and\n\\begin{math}{}A^{'}x^{'}=b^{'} \\end{math}. The first equation tells us that there can be no solution unless\n\\begin{math}{}\\beta=0\\end{math}. If, however, it is, then any solution \\begin{math}{}x^{'}\\end{math} of the\nsecond equation, which we note, satisfies the same properties we required of \n\\begin{math}{}A\\end{math}, can be combined with any number \\begin{math}{}z_n\\end{math} (where we use the dimension n to tag the variable, to prevent recursive name collisions)\ninto a solution, \\begin{math}{}A\\begin{bmatrix}z_n\\\\x^{'}\\end{bmatrix} = b\\end{math}\n\nIn particular, we can always take \\begin{math}{}z_n\\end{math} to be 0.\n\n\\subsection{Case 2}\n\\begin{math}{}\\alpha>0\\end{math}\n\nThen \n\\begin{math}{}\n\\begin{bmatrix}\\alpha & a^* \\\\ a & A^{'}\\end{bmatrix}\\begin{bmatrix}\\chi\\\\x^{'}\\end{bmatrix}=\\begin{bmatrix}\\beta\\\\b^{'}\\end{bmatrix}\n\\end{math}\nif and only if\n\\begin{math}{}\\alpha\\chi + a^*x^{'} = \\beta\\end{math} and\n\\begin{math}{}a\\chi + A^{'}x^{'} = b^{'}\\end{math}\nif and only if\n\\begin{math}{}\\alpha\\chi= \\beta - a^*x^{'} \\end{math} and\n\\begin{math}{}a\\chi + A^{'}x^{'} = b^{'}\\end{math}\nif and only if\n\\begin{math}{}\\chi= \\alpha^{-1}(\\beta - a^*x^{'})\\end{math} and\n\\begin{math}{}a\\alpha^{-1}(\\beta - a^*x^{'}) + A^{'}x^{'} = b^{'}\\end{math}\nif and only if\n\\begin{math}{}\\chi= \\alpha^{-1}(\\beta - a^*x^{'})\\end{math} and\n\\begin{math}{}a\\alpha^{-1}(- a^*x^{'}) + A^{'}x^{'} = b^{'}-a\\alpha^{-1}\\beta\\end{math}\nif and only if\n\\begin{math}{}\\chi= \\alpha^{-1}(\\beta - a^*x^{'})\\end{math} and\n\\begin{math}{}(A^{'} - a\\alpha^{-1}a^*)x^{'} = b^{'}-a\\alpha^{-1}\\beta\\end{math}\n\nSo if we can solve the second equation, the first equation shows us how to convert it into a solution\nof the original equation. Notice that if \n\\begin{math}{}b =0\\end{math}, then so is the derived right hand side; a homogeneous problem generates\na homogeneous subproblem.\n\nBut this second equation is again of the same form, because\n\\begin{gather}{}(A^{'} - a\\alpha^{-1}a^*)^* = \nA^{'*} - a^{**}\\alpha^{-1}a^* = \nA^{'} - a\\alpha^{-1}a^* \n\\end{gather}\nand moreover\n\\begin{gather}{}\n0 <= \\begin{bmatrix}-\\alpha^{-1}a^*x\\\\x\\end{bmatrix}^*\\begin{bmatrix}\\alpha & a^* \\\\ a & A^{'}\\end{bmatrix}\\begin{bmatrix}-\\alpha^{-1}a^*x\\\\x\\end{bmatrix}\n= \nx^*(A^{'} - a\\alpha^{-1}a^*)x\n\\end{gather}. So the derived submatrix is nonnegative, and positive if the original matrix is.\n\nAs in either case we have reduced to either the base case of dimension one or to a similar problem in one dimension smaller, the solution, whether it exists or\nnot, and whether or not multiple solutions exist, is complete.\n\n\\section{After-thought}\nThis section can be safely skipped by anyone whose interest is confined to\nthe real numbers, the complex numbers, the rational numbers, or even the quaternions.\n\nThe method works provided the scalars are taken from any subfield of the\nquaternions which is closed under the * operation. More precisely, we really\nneed \\begin{math}\\alpha^* = \\alpha\\end{math} if and only if \\begin{math}\\alpha\\end{math} is real, that \\begin{math}\\alpha^*\\alpha >= 0\\end{math}, and that \n\\begin{math}\\alpha^*\\alpha = 0\\end{math} only if \\begin{math}\\alpha=0\\end{math}.\n\nBut the method works, at least in some cases, even if the field is not *-closed.We can take the *-closure of any subfield of the quaternions, by intersecting all *-closed subfields containing it. Since the quaternions are *-closed, that *-closure is a *-closed subfield of the quaternions. We can then find all solutions composed of vectors having entries in the closure; it remains to determine\nwhich of those solutions, if any, lie in the original field. In the case where\n\\begin{math}A\\end{math} is positive, the solution is unique, and a solution whose entries lie in the original field does exist, so must coincide with the solution obtained by this method, which then must necessarily also have entries lying in the original field.\n\n\\section{Implementation Notes}\nAt each level of recursion, we only need to retain\n\\begin{math}{}a\\end{math},\n\\begin{math}{}\\alpha\\end{math}\nand\n\\begin{math}{}\\beta\\end{math}, allowing us to overwrite\n\\begin{math}{}A^{'}\\end{math}\nwith \\begin{math}{}(A^{'} - a\\alpha^{-1}a^*)\\end{math}\nand\n\\begin{math}{}b^{'}\\end{math} with\n\\begin{math}{}b^{'}-a\\alpha^{-1}\\beta\\end{math}\n.\n\nWe conclude with a C-language implementation of a solver for the positive semi-definite case, where\n\\begin{math}{}x^*Ax >=0 \\end{math} for all \\begin{math}{}x\\end{math}.\n\n\\begin{verbatim}\n$ cat positive_solver.h \nextern\ndouble * positive_solver(double ** A, double * b, int n);\n\n$ cat positive_solver.c\n/* \n * Andrew Winkler\n\nThis code solves the equation Ax=b, where A is a positive\nsemi-definite matrix, so that x^t A x >= 0 for all x,\nprovided a solution exists. If A is positive definite,\nit will be an isomorphism, but in general conditions\nmust be imposed on b, for it to lie in the range of A.\n\nIt has the virtue of dramatic simplicity - there's no need\nto explicitly construct the Cholesky decomposition, no need\nto do the explicit back-substitutions.  Yet it's essentially\nequivalent to that more labored approach, so its\nperformance/stability/memory, etc. should be at least as good.\n\nThere are two kinds of checks, both of which are disabled.\nThis means that a solution will be generated; it is up to\nthe caller to verify that the equation Ax=b is satisfied to\nthe desired precision. If it does not, then no solution exists.\n\nThe first kind of check is that Avec is 0 whenever A[0][0]\nis 0, which will always be true if A is positive semi-definite,\nbut which could become false because of any small perturbation\ncaused by roundoff error upstream in the computation of A.\nThe second kind of check is that b[0] is 0 whenever A[0][0] is 0,\nwhich is necessary for b to lie in the range of A. The checks are\ndisabled because the code does not deal with real numbers,\nbut rather floating point numbers; it's up to the user to decide\nwhat is \"close enough\" to zero.\n\n*/\n\n#include <stdlib.h>\n#include <stdio.h>\n#include \"positive_solver.h\"\n\nvoid _consistency_checker(double * v, int n) {\n    for (int i=0; i<n; i++) {\n        if ( v[i] != 0.0 ) exit(-1);\n    }\n}\n\nvoid _positive_solver(\n    double ** A, \n    double * b, \n    double * x, \n    int n\n    ) \n{\n  if (n < 1) exit(-1);\n\n  if (n == 1) {\n    if (A[0][0] == 0.0) {\n        /* _consistency_checker(b, 1); */\n        x[0] = 0.0;\n        return;\n    }\n    x[0] = b[0] / A[0][0];\n    return;\n  }\n\n  double * bvec = b + 1;\n  double * Avec = A[0] + 1;\n  double ** Asub = A + 1;\n  double * xvec = x + 1;\n\n  int m = n -1;\n\n  if (A[0][0] == 0.0) {\n      /*\n      _consistency_checker(b, 1);\n      _consistency_checker(Avec, m);\n      */\n  } else {\n      for(int j=0; j < m; j++){\n        bvec[j] -= Avec[j] * b[0] / A[0][0];\n        for(int i=0; i < m - j; i++)\n          Asub[i][j] -= Avec[i] * Avec[i+j] / A[0][0];\n      }\n  }\n\n  _positive_solver(Asub, bvec, xvec, m);\n\n  if (A[0][0] == 0.0) {\n      x[0] = 0.0;\n      return;\n  }\n\n  double p = 0; for(int k=0; k<m; k++) p += Avec[k] * xvec[k];\n\n  x[0] = (b[0] - p) / A[0][0];\n\n  return;\n}\n\n#include <malloc.h>\ndouble * positive_solver(\n    double ** A, \n    double * b, \n    int n\n    ) \n{\n  double * x = (double *) malloc(n * sizeof(double));\n  _positive_solver(A, b, x, n);\n  return x;\n}\n\n\\end{verbatim}\n\\end{document}\n", "meta": {"hexsha": "c003f6415ffc219e3d689c2095e02d474bcc09c1", "size": 13854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OPERATORS/AX_EQUALS_B/doc/linear_solver_orig.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": "OPERATORS/AX_EQUALS_B/doc/linear_solver_orig.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": "OPERATORS/AX_EQUALS_B/doc/linear_solver_orig.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": 47.1224489796, "max_line_length": 438, "alphanum_fraction": 0.6800202108, "num_tokens": 4590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6128046345244698}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{psfrag}\n\\usepackage{graphicx}\n\\usepackage{url}\n\\usepackage{amsmath,amsfonts}\n%\\usepackage{fullpage}\n\n\\newcommand\\br{{\\mathbf r}}\n\\newcommand\\w{{\\mathbf w}}\n\\newcommand\\bL{{\\mathbf L}}\n\\newcommand\\boldf{{\\mathbf f}}\n\\newcommand\\bz{{\\mathbf z}}\n\\newcommand\\bnabla{{\\boldsymbol \\nabla}}\n\\newcommand\\e{{\\mathbf e}}\n\\newcommand\\q{{\\mathbf q}}\n\n\\begin{document}\n\n\\section{Differential equations on the unit sphere}\n\nThe theoretical underpinnings of this package are described in \\cite{montgomerysmith:10}.\n\nThe objective of the software is to provide a systematic spherical harmonic method to numerically solve partial differential equations on the two\ndimensional sphere, $S = \\{\\br = (x,y,z):|\\br| = x^2+y^2+z^2 = 1\\}$, or in spherical coordinates, $\\br = (x,y,z) = (\\sin\\theta\n\\cos\\phi,\\sin\\theta\\sin\\phi,\\cos\\theta)$, where $0\\le\\theta\\le\\pi$, $0\\le\\phi\\le2\\pi$.  The partial differential equations considered here are of the\nform\n\\begin{equation}\n\\label{pde}\n\\frac\\partial{\\partial t}\\psi = F(\\br,\\bnabla) \\psi,\n\\end{equation}\nwhere $\\psi$ is a function (for example, the probability distribution function) defined on the sphere. Here $\\bnabla$ is the gradient operator\nrestricted to the sphere that is defined as\n\\begin{equation}\n\\begin{split}\n\\bnabla &= (\\nabla_x,\\nabla_y,\\nabla_z) \\\\\n&= \\left(\\cos\\theta\\cos\\phi\\frac{\\partial}{\\partial\\theta} - \\csc\\theta\\sin\\phi \\frac{\\partial}{\\partial\\phi},\\cos\\theta\\sin\\phi\\frac{\\partial}{\\partial\\theta} + \\csc\\theta\\cos\\phi \\frac{\\partial}{\\partial\\phi},-\\sin\\theta\\frac{\\partial}{\\partial\\theta} \\right) \\\\\n&= \\left((1-x^2)\\frac\\partial{\\partial x}-xy\\frac\\partial{\\partial y}-xz\\frac\\partial{\\partial z},\n         -xy\\frac\\partial{\\partial x}+(1-y^2)\\frac\\partial{\\partial y}-yz\\frac\\partial{\\partial z},\\right.\\\\\n&\\qquad\\qquad\\left.\n         -xz\\frac\\partial{\\partial x}-yz\\frac\\partial{\\partial y}+(1-z^2)\\frac\\partial{\\partial\n         z}\\right) .\n\\end{split}\n\\end{equation}\nIn the above, $F$ is a polynomial in six variables, with the proviso that it matters in which order the terms of each monomial part are written. We\nbelieve that this includes many of the published, if not all, of the partial differential equations that describe the evolution of\nthe orientation distribution function for short fiber suspensions.\n\nThe spherical harmonic approach converts equation~\\eqref{pde} to a\nsystem of ordinary differential equations written as\n\\begin{equation}\n\\label{spherical-pde}\n\\frac\\partial{\\partial t} \\hat\\psi_l^m = \\sum_{l'=0}^\\infty \\sum_{m'=-l'}^{l'} c_{l,l'}^{m,m'} \\hat\\psi_{l'}^{m'} ,\n\\end{equation}\nwhere $\\hat\\psi_l^m$ ($l \\ge 0$, $|m| \\le l$) are the spherical harmonic coefficients of $\\psi$, defined in\nequation~\\eqref{spherical-harmonic-coefficient} below, and $c_{l,l'}^{m,m'}$ are the coefficients defined through equation~\\eqref{decompose F}.\n\nThe software provides a systematic algorithm for calculating the coefficients $c_{l,l'}^{m,m'}$ appearing in equation~\\eqref{spherical-pde} (and also in equation~\\eqref{decompose F} below). This algorithm makes it possible to readily solve all differential\nequations on the unit sphere of the form shown in equation~\\eqref{pde}.\n\n\\section{Description of the model equations}\n\nTo illustrate the software, we consider variations of Jeffery's equation \\cite{jeffery:23} which describes the motion of fibers in a\nmoving fluid with vorticity $\\w$ and rate of deformation tensor $\\Gamma$. Jeffery's equation is\noften written in terms of the fiber orientation distribution function $\\psi$ and the fiber aspect ratio parameter $-1 \\le \\lambda\\le1$ as\n\\begin{equation}\n\\label{jeffery's}\n\\frac\\partial{\\partial t}\\psi = J \\psi := -\n\\tfrac12\\bnabla\\cdot(\\w \\times \\br \\psi + \\lambda(\\Gamma\\cdot\\br -\n\\Gamma:\\br\\br\\br) \\psi) ,\n\\end{equation}\nwhere we note that the right hand side is in the form of equation~\\eqref{pde}. A variation of equation~\\eqref{jeffery's} is Jeffery's equation with\nrotary diffusion as expressed by Bird \\cite{bird:87b} as\n\\begin{equation}\n\\label{jeffery's-folgar-tucker}\n\\frac\\partial{\\partial t}\\psi = J \\psi + \\bnabla\\cdot\\bnabla(D_r\n\\psi) ,\n\\end{equation}\nwhere $D_r$ captures the effect of fiber interaction and depends upon the flow kinetics. Folgar and Tucker \\cite{folgar:84} selected $D_r = C_I \\dot{\\gamma}$ where $\\dot{\\gamma} =\n\\left(\\frac12\\Gamma:\\Gamma\\right)^{1/2}$ and $C_I$ is a constant that depends upon the volume fraction and aspect ratio of the\nfibers.\n\nAnother example is anisotropic diffusion such as that proposed by Koch \\cite{koch:95} in the\ndifferential equation\n\\begin{equation}\n\\label{koch} \\frac\\partial{\\partial t}\\psi = J \\psi +\n\\bnabla\\cdot(I-\\br\\br)\\cdot D_r\\cdot\\bnabla\\psi = J \\psi +\n(\\bnabla-2\\br)\\cdot D_r\\cdot\\bnabla\\psi\n\\end{equation}\nwhere the anisotropic diffusion matrix $D_r$ is defined in terms of the model parameters $C_1$ and $C_2$ (see Koch \\cite{koch:95} for more detail) as\n\\begin{equation}\n\\label{kochDr}\nD_r = C_1 {\\dot\\gamma}^{-1} (\\Gamma:\\mathbb A:\\Gamma)I + C_2\n{\\dot\\gamma}^{-1} \\Gamma:\\mathcal A:\\Gamma .\n\\end{equation}\nIn the above, the $(I-\\br\\br)$ term serves to project vectors onto the surface of the sphere. We note that this term is not explicitly included in\nKoch's formula in \\cite{koch:95}, however it's existence is implied in the paragraph following the original introduction.\n\nThe anisotropic diffusion matrix $D_r$ defined in equation~\\eqref{kochDr} is written in terms of the 2nd, 4th and 6th order moment tensors of $\\psi$\nwhich are, respectively, defined as\n\\begin{equation}\n\\label{momenttensors}\n A := \\int_S \\psi \\br\\br \\, d\\br ,\\qquad\n\\mathbb A := \\int_S \\psi \\br\\br\\br\\br \\, d\\br ,\\qquad \\text{and}\n\\qquad \\mathcal A := \\int_S \\psi \\br\\br\\br\\br\\br\\br \\, d\\br .\n\\end{equation}\nIn these integrals, we adopt the common definition for the integral of a function $F(\\br)$ over the surface of the unit sphere as\n\\begin{equation}\n\\int_S F(\\br) \\, dr := \\int_{\\theta=0}^\\pi \\int_{\\phi=0}^{2\\pi}\nF(\\br) \\sin\\theta\\,d\\phi\\,d\\theta ,\n\\end{equation}\nand we note here that the moment tensors $A$, $\\mathbb A$, and $\\mathcal{A}$ can be expressed in terms of spherical harmonics as shown below in\nequation~\\eqref{moment tensor}.\n\nCare must be exercised in not confusing the differential geometry on the surface of the sphere $S$ with the differential geometry\nin the three dimensional space $\\mathbb R^3$ it is embedded in.  Thus, for example, integration by parts\nis the slightly unexpected form\n\\begin{equation}\n\\label{by-parts}\n\\int_S \\boldf \\cdot \\bnabla g\\, d\\br  = - \\int_S (\\bnabla\\cdot (I-\\br\\br)\\cdot\\boldf) g\\, d\\br = \\int_S ((2\\br - \\bnabla)\\cdot\\boldf)g \\, d\\br ,\n\\end{equation}\nwhich reduces to the usual integration by parts when $\\boldf$ is\ntangential to the surface of the sphere. We also recall the so\ncalled angular momentum operator\n\\begin{equation}\n\\label{ang-momentum-ops}\n\\bL = -i\\br\\times\\bnabla = (L_x,L_y,L_z) =\n-i\\left(y\\frac\\partial{\\partial z} - z\\frac\\partial{\\partial y} ,\nz\\frac\\partial{\\partial x} - x\\frac\\partial{\\partial z} ,\nx\\frac\\partial{\\partial y} - y\\frac\\partial{\\partial x} \\right) ,\n\\end{equation}\nwhere, as usual,  $i$ denotes the complex number satisfying $i^2=-1$.  Integration by parts for the angular momentum operator is more straightforward, that is,\n\\begin{equation}\n\\label{by-parts-l}\n\\int_S \\boldf \\cdot \\bL g\\, d\\br  = -\\int_S (\\bL\\cdot\\boldf) g\\, d\\br .\n\\end{equation}\nNote that $\\bL\\times\\bL = \\bnabla\\times\\bnabla = i\\bL$, and in particular $\\nabla_x$, $\\nabla_y$ and $\\nabla_z$\ndo not commute with each other. We also use the formulae $\\br\\cdot\\bnabla f=\\br\\cdot\\bL f=\\bL\\cdot(\\br f) = 0$ and $\\bnabla\\cdot(\\br f) = 2f$.\n\n\\section{Spherical harmonics solutions}\n\nAny square integrable function $\\psi$ defined on the unit sphere may be written as a Fourier series like representation in terms of the spherical\nharmonics $Y_l^m(\\theta,\\phi)$ for $l \\ge 0$ and $|m| \\le l$ as\n\\begin{equation}\n\\label{spherical-series}\n\\psi = \\sum_{l=0}^\\infty \\sum_{m=-l}^l\n\\hat\\psi_l^m Y_l^m ,\n\\end{equation}\nwhere $Y_l^m$ are the spherical harmonic functions as defined in \\cite{weisstein:06a}.\nThe coefficients $\\hat\\psi_l^m$ in equation~\\eqref{spherical-series}\nare evaluated from\n\\begin{equation}\n\\label{spherical-harmonic-coefficient}\n\\hat\\psi_l^m = \\int_S \\psi\n\\bar Y_l^m d\\br .\n\\end{equation}\n\nTo obtain the system of ordinary differential equations~\\eqref{spherical-pde}, we integrate equation~\\eqref{pde} against $\\bar Y_l^m$ over the unit\nsphere to obtain its adjoint or weak form as\n\\begin{equation}\n\\label{weakform}\n\\frac\\partial{\\partial t} \\int_S \\psi \\bar Y_l^m\n\\,d\\br = \\int_S \\psi F^*(\\br,\\bnabla) \\bar Y_l^m \\,d\\br ,\n\\end{equation}\nwhere the right hand side follows from integration by parts and the term $F^*$ denotes any polynomial $F$ in which each monomial term is written in\nreverse order with the substitution of $2\\br - \\bnabla$ for $\\bnabla$. Therefore, applying equation~\\eqref{weakform}, Jeffery's\nequation~\\eqref{jeffery's} is defined by\n\\begin{equation}\nJ^* = \\tfrac12(\\w\\cdot(\\br\\times\\bnabla) + \\lambda\\br\\cdot\\Gamma\\cdot\\bnabla),\n\\end{equation}\nSimilarly, the two extensions of Jeffery's equation that include diffusion appearing in equations~\\eqref{jeffery's-folgar-tucker} and~\\eqref{koch}\n(expressed as $\\frac\\partial{\\partial t}\\psi = F \\psi$), respectively become\n\\begin{equation}\n\\label{FStarFT}\nF^* = J^* + D_r \\bnabla\\cdot\\bnabla ,\n\\end{equation}\nand\n\\begin{equation}\nF^* = J^* + (\\bnabla-2\\br)\\cdot D_r\\cdot\\bnabla .\n\\end{equation}\nIn all cases, we can decompose\n\\begin{equation}\n\\label{decompose F}\nF^*(\\br,\\bnabla) \\bar Y_l^m = \\sum_{l'=0}^\\infty \\sum_{m'=-l'}^{l'} c_{l,l'}^{m,m'} \\bar Y_{l'}^{m'} ,\n\\end{equation}\nand therefore obtain the spherical harmonic representation shown in equation~\\eqref{spherical-pde} above.\n\n\\section{The ``spherical'' program algorithm}\n\nAn automated algorithm is implemented to compute the coefficients $c_{l,l'}^{m,m'}$ in equation~\\eqref{decompose F} for\nany differential equation satisfying the criteria given above (and, therefore, the $\\mathcal C_{l,m}$ in equation~\\eqref{moment tensor}). The\nalgorithm is to recursively apply the replacement rules described in equation~\\eqref{rules} until no further substitutions can be made. Here ``op''\ndenotes any of $z$, $L_z$, $L_+$, or $L_-$ operations, and $\\mathcal Y$ denotes any linear combination of the $\\bar Y_l^m$'s.\n\\begin{equation}\n\\label{rules}\n\\begin{split}\n\\text{op}(\\mathcal Y \\pm c \\bar Y_l^m) &\\to \\text{op}(\\mathcal Y) \\pm c \\, \\text{op}(\\bar Y_l^m), \\\\\nx \\mathcal Y &\\to  z i L_y(\\mathcal Y) - i L_y(z\\mathcal Y), \\\\\ny \\mathcal Y &\\to  i L_x(z\\mathcal Y) - z i L_x(\\mathcal Y), \\\\\nz\\bar Y_l^m &\\to \\sqrt{\\frac{(l+m)(l-m)}{(2l-1)(2l+1)}} \\bar Y_{l-1}^m + \\sqrt{\\frac{(l+m+1)(l-m+1)}{(2l+1)(2l+3)}} \\bar Y_{l+1}^m ,\\\\\n\\nabla_x \\mathcal Y &\\to z i L_y(\\mathcal Y) - y i L_z(\\mathcal Y),  \\\\\n\\nabla_y \\mathcal Y &\\to x i L_z(\\mathcal Y) - z i L_x(\\mathcal Y),  \\\\\n\\nabla_z \\mathcal Y &\\to y i L_x(\\mathcal Y) - x i L_y(\\mathcal Y),  \\\\\nL_x (\\mathcal Y) &\\to \\tfrac 12 \\left(L_+ (\\mathcal Y) + L_- (\\mathcal Y)\\right), \\\\\nL_y (\\mathcal Y) &\\to -\\tfrac i2 \\left(L_+ (\\mathcal Y) - L_- (\\mathcal Y)\\right), \\\\\nL_z \\bar Y_l^m &\\to -m\\bar Y_l^m ,\\\\\nL_+ \\bar Y_l^m &\\to - \\sqrt{(l+m)(l-m+1)}\\bar Y_l^{m-1}, \\\\\nL_- \\bar Y_l^m &\\to - \\sqrt{(l-m)(l+m+1)}\\bar Y_l^{m+1}\n\\end{split}\n\\end{equation}\nIt is important to note that $x \\bar Y_l^m$, $y \\bar Y_l^m$, $z \\bar Y_l^m$, $\\nabla_x\\bar Y_l^m$, $\\nabla_y \\bar Y_l^m$, and $\\nabla_z \\bar Y_l^m$\ninvolve $\\bar Y_{l'}^{m'}$ for $l'$ and $m'$ that differ from $l$ and $m$, respectively, by at most one.  The script described in the appendix uses\nthe recursive algorithm in equation~\\eqref{rules} to create threaded functions in the programming language\nC which in turn are used in an iterative procedure for computing the solution to the differential equation in equation~\\eqref{pde}.\n\nMoment tensors may be computed using this algorithm as well. For example, to compute the 6th order moment tensor $\\mathcal A$ in\nequation~\\eqref{momenttensors} we simply expand\n\\begin{equation}\n\\label{expand Y_0^0} \\br\\br\\br\\br\\br\\br \\bar Y_0^0 = \\sum_{l=0}^6\n\\sum_{m=-l}^l \\mathcal C_{l,m} \\bar Y_l^m,\n\\end{equation}\nwhere $\\mathcal C_{l,m}$ is the tensor of rank six composed of coefficients calculated by applying $x$, $y$ and $z$ to $\\bar Y_0^0$ six times using the algorithm. It follows that since $\\bar Y_0^0 = 1/\\sqrt{4\\pi}$, the 6th order orientation tensor\nbecomes\n\\begin{equation}\n\\label{moment tensor} \\mathcal A = \\sqrt{4\\pi} \\int_S \\psi\n\\br\\br\\br\\br\\br\\br \\bar Y_0^0 \\, d\\br = \\sqrt{4\\pi} \\sum_{l=0}^6\n\\sum_{m=-l}^l \\mathcal C_{l,m} \\hat\\psi_l^m ,\n\\end{equation}\nwhere the orthogonality of the spherical harmonics are used to simplify the final result.\n\n\\section{The ``spherical'' software package}\n\nThe program developed to implement our spherical harmonics\nsimulation procedure described above which computes the coefficients\nin equation~\\eqref{spherical-pde}, and then convert these terms into\na C program, may be found at\n\\url{https://github.com/stephenmontgomerysmith/spherical}. The\nprogram is written in \\emph{perl}, and makes use of either the\ncommercial computer algebra system \\emph{Mathematica} by Wolfram\nResearch, or the open-source computer algebra system \\emph{Maxima}.\nThe scripts are designed to work in a Unix like environment.\n\nThe program that evaluates spherical harmonics coefficients is a\n\\emph{perl} script which applies the rules in~\\eqref{rules}. It is\ninvoked with the command sequence ``{\\tt perl expand-method.pl}''.\nThe user may type in an expression involving {\\tt x}, {\\tt y}, {\\tt\nz}, {\\tt dx}, {\\tt dy}, {\\tt dz}, {\\tt lx}, {\\tt ly}, or {\\tt lz}\nrepresenting ``multiply by $x$,'' ``multiply by $y$,'' ``multiply by\n$z$,'' $\\nabla_x$, $\\nabla_y$, $\\nabla_z$, $L_x$, $L_y$, or $L_z$\nrespectively, or any number, including {\\tt I} for $i$, and any\nappropriate combination of parentheses, addition and subtraction,\nand ``{\\tt *}'' which represents composition of the operators.  It\noutputs a sequence of lines, which when added together, represents\nthe effect of the expression upon $\\bar Y_l^m$.  Each line has three\nentries separated by semicolons, $l'$;$m'$;$c$, and represents\n$c\\bar Y_{l+l'}^{m+m'}$.  The third entry is written in the\nprogramming language C, using complex numbers as described in\n\\cite{c:99}.  So, for example, the input\n\\begin{verbatim}\n%perl expand-method.pl\n> -2*I*(dy-y)\n\\end{verbatim}\nyields the output\n\\begin{verbatim}\n-1;-1;((l*sqrt(-1+l+m)*sqrt(l+m))/(sqrt(-1+2*l)*sqrt(1+2*l)))+(0)*I\n-1;1;((l*sqrt(-1+l-m)*sqrt(l-m))/(sqrt(-1+2*l)*sqrt(1+2*l)))+(0)*I\n1;-1;(((1+l)*sqrt(1+l-m)*sqrt(2+l-m))/(sqrt(1+2*l)*sqrt(3+2*l)))+(0)*I\n1;1;(((1+l)*sqrt(1+l+m)*sqrt(2+l+m))/(sqrt(1+2*l)*sqrt(3+2*l)))+(0)*I\n\\end{verbatim}\nThis result reflects the equation\n\\begin{equation*}\n\\begin{split}\n-2i(\\nabla_y - y)\\bar Y_l^m = &\n\\tfrac{l\\sqrt{(l+m-1)(l+m)}}{\\sqrt{(2l-1)(2l+1)}} \\bar Y_{l-1}^{m-1}\n+ \\tfrac{l\\sqrt{(l-m-1)(l-m)}}{\\sqrt{(2l-1)(2l+1)}} \\bar Y_{l-1}^{m+1} \\\\\n& + \\tfrac{(l+1)\\sqrt{(l-m+1)(l-m+2)}}{\\sqrt{(2l+1)(2l+3)}} \\bar Y_{l+1}^{m-1}\n+ \\tfrac{(l+1)\\sqrt{(l+m+1)(l+m+2)}}{\\sqrt{(2l+1)(2l+3)}} \\bar Y_{l+1}^{m+1} .\n\\end{split}\n\\end{equation*}\n\nThe program ``{\\tt perl expand-method.pl}'' is called by another\nscript invoked as ``{\\tt perl expand-iterate.pl <filename>}'' which\nconverts a configuration file into a C program to numerically solve\nthe spherical harmonics differential equation. For example,\nJeffery's equation (written here in weak form) with Koch diffusion\ncan be written as below\n\\begin{verbatim}\nvoid compute_psidot(complex* psidot, complex* psi,\n                    double lambda, double w[3], double g[3][3]) {\n  double a4[3][3][3][3], a6[3][3][3][3][3][3], Dr[3][3];\n\n  tensor4(psi,a4); tensor6(psi,a6);\n  ... compute Dr from g, a4 and a6 ...\n\n  @spherical_iterate {\n    psidot[@index] =\n      /* Jeffery's equation */\n        w[0]*@method(psi,0.5*y*dz-0.5*z*dy)\n      + w[1]*@method(psi,0.5*z*dx-0.5*x*dz)\n      + w[2]*@method(psi,0.5*x*dy-0.5*y*dx)\n      + lambda*g[0][0]*@method(psi,0.5*x*dx)\n      + lambda*g[0][1]*@method(psi,0.5*x*dy+0.5*y*dx)\n      + lambda*g[0][2]*@method(psi,0.5*x*dz+0.5*z*dx)\n      + lambda*g[1][1]*@method(psi,0.5*y*dy)\n      + lambda*g[1][2]*@method(psi,0.5*y*dz+0.5*z*dy)\n      + lambda*g[2][2]*@method(psi,0.5*z*dz)\n      /* Koch diffusion */\n      + Dr[0][0]*@method(psi,(dx-2*x)*dx)\n      + Dr[0][1]*@method(psi,(dx-2*x)*dy+(dy-2*y)*dx)\n      + Dr[0][2]*@method(psi,(dx-2*x)*dz+(dz-2*z)*dx)\n      + Dr[1][1]*@method(psi,(dy-2*y)*dy)\n      + Dr[1][2]*@method(psi,(dy-2*y)*dz+(dz-2*z)*dy)\n      + Dr[2][2]*@method(psi,(dz-2*z)*dz);\n  }\n}\n\\end{verbatim}\n\nTo calculate the coefficients for the moment tensors, as in\nequation~\\eqref{expand Y_0^0}, if the environmental variable {\\tt\nTENSOR} is set to a non-zero value, then {\\tt expand-method.pl}\napplies the input expression to $\\bar Y_0^0$, and outputs the\nanswers in floating point format.  So, for example the input\n\\begin{verbatim}\n%env TENSOR=1 perl expand-method.pl\n> x*y*z*z\n\\end{verbatim}\nyields\n\\begin{verbatim}\n2;-2;(0)+(-0.026082026547865053022)*I\n2;2;(0)+(0.026082026547865053022)*I\n4;-2;(0)+(-0.030116930096841707924)*I\n4;2;(0)+(0.030116930096841707924)*I\n\\end{verbatim}\nThis results reflects the 1233 component of 4th order moment tensor\n\\begin{equation*}\n\\mathbb A_{1233} =\ni\\sqrt{4\\pi}\\left(\\tfrac{\\sqrt{30}}{210}(\\hat\\psi_2^2-\\hat\\psi_2^{-2})\n+\\tfrac{\\sqrt{10}}{105}(\\hat\\psi_4^2-\\hat\\psi_4^{-2})\\right).\n\\end{equation*}\nThis is used by ``{\\tt perl make-tensor.pl $n$}'' and ``{\\tt perl\nmake-reverse-tensor.pl $n$}'', which create C programs to convert,\nrespectively, spherical harmonic coefficients to moment tensors of\nrank $n$, and vice-versa.\n\n\\bibliographystyle{plain}\n\\bibliography{info_08}\n\n\\end{document}\n", "meta": {"hexsha": "73cac62665fa7b9f328d1915529d174c2fb2aa4c", "size": 17725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/pde-sphere-software.tex", "max_stars_repo_name": "stephenmontgomerysmith/spherical", "max_stars_repo_head_hexsha": "d7ac6ed2b216e317d10051d8909c9978ca0270a1", "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/pde-sphere-software.tex", "max_issues_repo_name": "stephenmontgomerysmith/spherical", "max_issues_repo_head_hexsha": "d7ac6ed2b216e317d10051d8909c9978ca0270a1", "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/pde-sphere-software.tex", "max_forks_repo_name": "stephenmontgomerysmith/spherical", "max_forks_repo_head_hexsha": "d7ac6ed2b216e317d10051d8909c9978ca0270a1", "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": 50.787965616, "max_line_length": 264, "alphanum_fraction": 0.6990126939, "num_tokens": 6072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.6825737344123242, "lm_q1q2_score": 0.6127432353708888}}
{"text": "We wish to predict useful dependencies for a proof goal, or conjecture.\nFor this we define rankings, which are generated by predictors:\n\n\\begin{definition}\\defgls{rankings}\n  A ranking $r \\in \\rankings$ is a partial function which yields the likelyhood a\n  dependency $\\phi \\in \\depset$ is useful in the current context.\n\n  $$\n    r : \\depset \\rightharpoonup \\mathbb{R}\n  $$\n\\end{definition}\n\n\\begin{definition}\\defgls{predictors}\n  A predictor $P \\in \\predictors$ is a function which given an unproven conjecture $c \\in \\types$\n  computes the likelyhood a dependency $\\phi \\in \\depset$ is useful in proof of conjecture $c$.\n  In other words, for a conjecture $c \\in \\types$ it yields a ranking $r \\in \\rankings$.\n  $$\n    P : \\types \\rightarrow \\rankings\n  $$\n\\end{definition}\n\nA weak total ordered subset of definitions useful for conjecture $c$ is formed by sorting on the resulting value of type $\\mathbb{R}$.\nIn the next few chapters we define a few of these predictors.\n\n\\subsubsection{\\knn}\n\\input{document-approach-predictors-knn}\n\n\\subsubsection{\\knnadaptive}\n\\input{document-approach-predictors-knnadaptive}\n\n\\subsubsection{\\nb}\n\\input{document-approach-predictors-nb}\n\n\\subsubsection{Adarank}\n\\input{document-approach-predictors-adarank}\n\n\\subsubsection{Ensembles}\n\\input{document-approach-predictors-ensemble}\n", "meta": {"hexsha": "800997be9b865a1069ae8ec920fde87a8bc315b0", "size": 1322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/thesis/document-approach-predictors.tex", "max_stars_repo_name": "Wassasin/premiseselection", "max_stars_repo_head_hexsha": "c07c7d2d52605fd3d960ec4b5d952eb0aae4bb5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-11T14:59:32.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-11T14:59:32.000Z", "max_issues_repo_path": "documents/thesis/document-approach-predictors.tex", "max_issues_repo_name": "Wassasin/premiseselection", "max_issues_repo_head_hexsha": "c07c7d2d52605fd3d960ec4b5d952eb0aae4bb5b", "max_issues_repo_licenses": ["MIT"], "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/thesis/document-approach-predictors.tex", "max_forks_repo_name": "Wassasin/premiseselection", "max_forks_repo_head_hexsha": "c07c7d2d52605fd3d960ec4b5d952eb0aae4bb5b", "max_forks_repo_licenses": ["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.8974358974, "max_line_length": 134, "alphanum_fraction": 0.7556732224, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.682573734412324, "lm_q1q2_score": 0.6127432222934623}}
{"text": "\\section{Methodology for Library Evaluation}\n\nThe three dimensions of library evaluation are (i)efficiency, (ii)scalability, and (iii)reliability.    The overall evaluation of the library is the geometric mean of numerical measurements of each dimension.  Standard numerical measurements  for evaluating efficiency has been found in literature.  A similar approach may apply to the evaluation of scalability.  A numerical measure of reliability, unfortunately, requires further study.  The first section of this part will review methodology of hardware efficiency evaluation, which I believe applies to software efficiency evaluation as well.  In the rest three sections of this part, approaches to evaluate each dimension will be examined respectively.\n\n\\subsection{Measuring Hardware Efficiency}\nIn practice, hardware efficiency is measured by its performance regarding to a benchmark suite, which contains a set of test programs.  Performance is defined as the reciprocal of mean execution time of all tests\\cite{HePa06}.  This project will use geometric mean instead of weighted arithmetic mean for three reasons.\n\nFirstly and most importantly, as proved by Fleming and Wallace \\cite{Fleming}, geometric mean is the only correct average of normalised measurements.  As users often compare the performance of one system to another, performance is usually normalised to a reference system.  \n\n\\begin{comment}\n Precisely, let the benchmark suite has $n$ tests indexed from $1$ to $n$, performance of system A is calculated as:\n\n $performance_A$ \n= $\\frac{time_{ref}}{time_{A}}$\n= $\\frac{\\sqrt[n]{\\prod^{n}_{i=1} time_{ref_i}}}{\\sqrt[n]{\\prod^{n}_{i=1} time_{A_i}}}$\n= $\\sqrt[n]{\\prod^{n}_{i=1}{\\frac{time_{ref_i}}{time_{A_i}}}}$\n\n\\hspace{0.8 cm}where $time_{S_i}$ is the execution time of program $i$ on system $S$, \n\n\\hspace{1.0 cm} and $time_{S}$ is the time measurement of system $S$.\n\\end{comment}\n\nSecondly, the order of calculating means and normalisation is flexible in practice.  Therefore, the suite developer will only implement a generic tool for measuring unnormalised execution time. The work of comparing performance of two interested platforms will be left to users.  Besides, users are free to extend the benchmark suite.  When new tests are added to the benchmark suite, performance measure for old examples becomes a valid partial measure.\n\nFinally, statistic tools could be employed to verify the soundness of chosen suite.  For example, the geometric standard deviations is an indicator to assess the variability of the chosen suite.\n\n\n\\subsection{Measuring Library Efficiency}\nThe Methodology of measuring hardware efficiency also applies to measuring library efficiency, where both the library implementation and the running platform may differ.  \n\nTo test the efficiency of different distributed programming libraries, a set of benchmarking examples need to be identified.  To avoid unintentional optimisation in the TAkka implementation, benchmarks are scrupulously selected from existing applications written in other OTP-like libraries and modifications are made at the minimal level.  \n\nTheoretically, any program that involves a time measurement could be a candidate efficiency test.  Such examples could be easily found in both the correctness test suite and the scalability test suite.  However, we would like to exclude examples whose results significantly determine the overall measure.  To this end, statistic methods such as principal component analysis will be employed.\n\n\\subsection{Measuring Scalability}\n\nTo assess the scalability of different OTP-like libraries, suitable examples from the BenchErl suite\\cite{RELEASE} have been reimplemented using Akka and TAkka.  A summary of selected examples will be given at \\S\\ref{scalability}.\n\nSimilar to efficiency evaluation, geometric mean of scalability measures of all examples could be the indicator of the library scalability.  Unfortunately, numerical evaluation for scalability is not found in the literature.  This project will use linear regression techniques to analysis the scalability of an OTP-like library in two aspects: (i) the degrees to which the performance speedup deviate from the ideal linear relationship regarding to the number of active CPU cores.  (ii) the slope of the linear equation, assuming that the relationship between performance speedup and the number of active CPU cores is linear.\n\nFinally, scalability of OTP-like libraries will be tested on a variety of platforms.  The three candidate platforms are Beowulf cluster, Google App Engine, and Amazon EC2.\n\n\n\\subsection{Measuring Reliability}\n\nIdentify types of failures and their impact is a crucial part of reliability evaluation.  The next two months will be devoted to the study of possible failures that could be handled at the language level.  Methodology for numerically evaluating reliability requires more studies and careful verifications.\n\n\n", "meta": {"hexsha": "143929925600692d1fabd7b534f19fdabb2a264d", "size": 4921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "s1024484/ReviewReport/Oct2012/evaluation.tex", "max_stars_repo_name": "Jiansen/TAkka", "max_stars_repo_head_hexsha": "d2410190552aeea65c1da5f0ae05f08ba1f4d102", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-09-11T14:35:53.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T06:36:09.000Z", "max_issues_repo_path": "s1024484/ReviewReport/Oct2012/evaluation.tex", "max_issues_repo_name": "Jiansen/TAkka", "max_issues_repo_head_hexsha": "d2410190552aeea65c1da5f0ae05f08ba1f4d102", "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": "s1024484/ReviewReport/Oct2012/evaluation.tex", "max_forks_repo_name": "Jiansen/TAkka", "max_forks_repo_head_hexsha": "d2410190552aeea65c1da5f0ae05f08ba1f4d102", "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": 100.4285714286, "max_line_length": 707, "alphanum_fraction": 0.8047144889, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6127137344128389}}
{"text": "\\section{Asymptotic Analysis for Closed Systems}\n\\label{sec:Asymptotic-Analysis-Closed-Systems}\n\n\\begin{theorem}[Asymptotic Bounds for Closed Systems]\n\t\\label{thm:Asymptotic-Bounds-Closed-Systems}\n\tFor any closed system with load $N$, we have that\n\t\n\t\\begin{equation}\n\t\\label{eqn:Asymptotic-Bounds-Closed-Systems}\n\t\\begin{split}\n\tX & \\leq \\min \\Big\\{ \\frac{N}{D + \\expected{Z}} , \\frac{1}{D_{max}} \\Big\\} \\\\\n\t\\expected{R} & \\geq \\max\\{D , N \\cdot D_{max} - \\expected{Z} \\}\n\t\\end{split}\n\t\\end{equation}\n\t\n\twhere the first term in each clause is an asymptote for small $N$, and the second one for large $N$.\n\t\n\t\\begin{proof}\n\t\tSee \\cite{harchol2013performance} for a formal demonstration.\n\t\\end{proof}\n\\end{theorem}\n\nIt is possible to get even tighter bounds by using the \\textit{Balanced Bounds technique}, described in \\cite{lazowska1984quantitative}.\n\nThe lower and the upper bound intercept in \n\\begin{equation}\n\\label{eqn:Asymptotic-Bounds-Closed-Systems-Interception}\nN^{*} = \\frac{D + \\expected{Z}}{D_{max}}\n\\end{equation}\nThat is the point beyond which there must be some queueing in the system, because $\\expected{R} > D$.\n\nIf $N > N^{*}$, performance can be improved ($X$ increased and $\\expected{R}$ decreased) only decreasing $D_{max}$.\n\nIf $N >> N^{*}$, decreasing some $D_{i} < D_{max}$ have no effect.\nIf $N << N^{*}$, decreasing some $D_{i} < D_{max}$ have little effect.\n\nIn a batch system ($Z=0$), $N^{*}$ decreases, meaning that the domination of $D_{max}$ occurs with smaller load.\n\nThe bottleneck server is the server with demand $D_{max}$. It is the key limiting factor to performance improvement. Thus, the first step in improving performance is to identify the bottleneck server.\n\nThe asymptotic bounds hold for open systems only if $\\lambda . X \\rightarrow \\frac{1}{D_{max}}$.", "meta": {"hexsha": "1494fc9de213a1099646042400a004d3b6a04d99", "size": 1799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/asymptotic-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": "performance-modeling/sec/asymptotic-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": "performance-modeling/sec/asymptotic-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": 43.8780487805, "max_line_length": 200, "alphanum_fraction": 0.7165091718, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6126838991730835}}
{"text": "%\\section{A result on expectation}\n%\\begin{lemma}   \\label{MC} \n%Let $\\lambda\\ge 0$ be a probability density function such that \n%\\begin{equation}\n%  \\label{density}\n%\\int_{\\mathbb R^d}\\lambda(\\omega)dx =1.\n%\\end{equation}\n%\\begin{equation}\n%  \\label{E}\n%\\mathbb{E}g:=\\int_{\\mathbb{R}^d}\n%  g(\\omega)\\lambda(\\omega)d\\omega\n%\\end{equation}\n%and\n%\\begin{equation}\n%  \\label{En}\n%\\mathbb{\\bar E}h:=\\int_{\\mathbb{R}^d\\times \\mathbb{R}^d\\times\\ldots\\times \\mathbb{R}^d}\n%h(\\omega_1,\\omega_2,\\ldots,\\omega_n) \\lambda(\\omega_1) \\lambda(\\omega_n)\\ldots \\lambda(\\omega_n)\n%d\\omega_1d\\omega_2\\ldots d\\omega_n.\n%\\end{equation}\n%\n%Then for any $g\\in L^\\infty(\\mathbb{R}^d)$, we have\n%  \\begin{equation}\n%   \\mathbb{\\bar E}(\\mathbb{E}g-\\frac1n\\sum_{i=1}^n\n%    g(\\omega_i))^2=\\frac{1}{n}(\\mathbb{E}(g-\\mathbb{E}(g))^2) \n%\\le \\frac{1}{n}\\mathbb{E}(g^2)\\le \\frac{1}{n}\\|g\\|^2_{L^\\infty},\n%  \\end{equation}\n%  where \n%\\end{lemma}\n%\\begin{proof}\n% \\begin{equation}\n%    \\label{eqn}\n%    \\begin{aligned}\n%      &\\quad \\mathbb{\\bar E}\\left(\\mathbb{E} g-\\frac1n\\sum_{i=1}^ng(\\omega_i)\\right)^2 \\\\\n%  &=\\frac{1}{n^2} \\mathbb{\\bar E}\\left(n\\mathbb{E} g-\\sum_{i=1}^ng(\\omega_i)\\right)^2 \\\\\n%  &=\\frac{1}{n^2} \\mathbb{\\bar E}\\left(\\sum_{i=1}^n(\\mathbb{E} g-g(\\omega_i))\\right)^2 \\\\\n%  &=\\frac{1}{n^2} \\mathbb{\\bar E}\\sum_{i,j=1}^n(\\mathbb{E} g-g(\\omega_i))(\\mathbb{E} g-g(\\omega_j))\\\\\n%  &=\\frac{1}{n^2} \\mathbb{\\bar E}\\sum_{i=1}^n(\\mathbb{E} g-g(\\omega_i))^2\\\\\n%&+\\frac{1}{n^2} \\mathbb{\\bar E}\\sum_{i\\neq  j}^n((\\mathbb{E}g)^2-\\mathbb{E}(g)(g(\\omega_i)+\n%g(\\omega_j))+g(\\omega_i)g(\\omega_j)))\n%    \\end{aligned}\n%  \\end{equation}\n%We note that\n%$$\n%\\mathbb{\\bar E} g(\\omega_i)=\\mathbb{\\bar E} g(\\omega_j) =\\mathbb E(g) \n%$$\n%and, for $i\\neq j$, \n%$$\n%\\mathbb{\\bar E} ( g(\\omega_i)g(\\omega_j)) =\\mathbb{\\bar E} (\n%g(\\omega_i))\\mathbb{\\bar E}(g(\\omega_j))\n%=[\\mathbb E(g)]^2.\n%$$\n%Thus\n% \\begin{equation}\n%\\mathbb{\\bar E}\\sum_{i\\neq j}^n((\\mathbb{E}g)^2-\\mathbb\n%  E(g)(g(\\omega_i)+ g(\\omega_j))+(g(\\omega_i)g(\\omega_j)))=0.\n%  \\end{equation}\n%Furthermore\n%$$\n%\\mathbb{\\bar E}(\\mathbb{E} g-g(\\omega_i))^2\n%=\\mathbb{\\bar E}(\\mathbb{E} g-g(\\omega))^2 \n%=[\\mathbb{E} g]^2-2[\\mathbb E g(\\omega)]^2 +\\mathbb E(g^2) \n%=\\mathbb E(g^2) -[\\mathbb E(g)]^2 \n%\\le\\mathbb E(g^2) \n%$$\n%Consequently\n% \\begin{equation}\n%    \\label{eqn}\n%    \\begin{aligned}\n%      &\\quad \\mathbb{\\bar E}\\left(\\mathbb{E} g-\n%      \\frac1n\\sum_{i=1}^ng(\\omega_i)\\right)^2 \\\\\n%      &=\\frac{1}{n^2} \\mathbb{\\bar E}\\left(n\\mathbb{E} g-\n%      \\sum_{i=1}^ng(\\omega_i)\\right)^2 \\\\\n%      &=\\frac{1}{n^2} \\mathbb{\\bar E}\\left(\\sum_{i=1}^n(\\mathbb{E}\n%      g-g(\\omega_i))\\right)^2 \\\\\n%      &=\\frac{1}{n^2} \\sum_{i=1}^n(\\mathbb{\\bar E}(\\mathbb{E}      g-g(\\omega_i))^2) \\\\\n%      &=\\frac{1}{n}(\\mathbb{E}(g-\\mathbb{E}(g))^2) \\\\\n%      &=\\frac{1}{n}(\\mathbb{E}(g^2)-(\\mathbb{E}(g))^2) \\\\\n%      &\\le\\frac1n \\mathbb E(g^2)\\\\\n%      &\\le\\frac1n\\|g\\|^2_{L^\\infty}\n%    \\end{aligned}\n%  \\end{equation}\n%\\end{proof}\n%\n%The above result be extended to the following general case easily.\n%\\begin{lemma} \\label{MC1} Given $1\\le i\\le n$, let $\\Omega $ be a\n%  probability space with a probability measure $\\mu$ with density\n%  function $\\lambda\\ge 0$ ($1\\le i\\le n$), namely \n%$$\n%\\mu(G)=\\int_G \\lambda(\\omega)d\\mu, \\quad \n%\\mu(\\Omega)=1, \\quad G\\subset \\Omega.\n%$$\n%Define\n%\\begin{equation}\n%\\label{Ei}\n%\\mathbb{E}g:=\\int_{\\Omega}  g(\\omega)\\lambda(\\omega)d\\mu\n%\\end{equation}\n%and\n%\\begin{equation}\n%  \\label{En}\n%\\mathbb{\\bar E}h:=\\int_{\\Omega\\times\\Omega\\times\\ldots\\times\\Omega}\n%h(\\omega_1,\\omega_2,\\ldots,\\omega_n) \\lambda(\\omega_1) \\lambda(\\omega_n)\\cdots \\lambda(\\omega_n)\n%d\\mu_1d\\mu_2\\ldots d\\mu_n.\n%\\end{equation}\n%Then for any $g\\in L^\\infty(\\Omega)$, we have\n%  \\begin{equation}\n%    \\mathbb{\\bar E}(\\mathbb{E}g-\\frac1n\\sum_{i=1}^n\n%    g(\\omega_i))^2=\\frac{1}{n}(\\mathbb{E}(g-\\mathbb{E}(g))^2) \n%\\le \\frac{1}{n}\\|g\\|^2_{L^\\infty}.\n%  \\end{equation}\n%\\end{lemma} \n%\\section{Fourier transformation and Barron spaces}\n%Given a bounded domain $B\\subset\\mathbb R^d$, we consider the function\n%$$\n%f: B\\mapsto \\mathbb R\n%$$\n%Let \n%$$\n%f^e: \\mathbb R^d\\mapsto \\mathbb R\n%$$ \n%be any extension of $f$ so that\n%$$\n%f^e|_B=f(x), \\quad x\\in B. \n%$$\n%Most time, we will drop the superscript $``e\"$ to still use $f$ to\n%denote an extension of $f$. \n%\n%Consider the Fourier transform:\n%\\begin{equation}\n%  \\label{Fourier}\n%  \\hat f(\\omega)=\\frac{1}{(2\\pi)^d}\\int_{\\mathbb{R}^d}e^{-i\\omega\\cdot x}f(x)dx\n%  \\quad \\forall \\omega \\in \\mathbb R^d,\n%\\end{equation}\n%Using the Fourier inversion formula, we can have a Fourier\n%representation of $f(x)$ as follows\n%\\begin{equation}\n%  \\label{eqn1}\n%  f(x)=\\int_{\\mathbb{R}^d}e^{i\\omega\\cdot x}\\hat{f}(\\omega)d\\omega\n%  \\quad \\forall x \\in B,\n%\\end{equation}\n%From \\eqref{eqn1}, we have\n%\\begin{equation}\n%  \\label{f0}\n% f(x_B)=\\int_{\\mathbb{R}^d}e^{i\\omega\\cdot x_B}\\hat{f}(\\omega)d\\omega.\n%\\end{equation}\n%Let us write\n%\\begin{equation}\n%  \\label{theta-omega}\n%  \\hat{f}(\\omega)=e^{i\\theta(\\omega)}|\\hat{f}(\\omega)|.   \n%\\end{equation}\n%Since $f(x)$ is real-valued, it follows from \\eqref{eqn1} and\n%\\eqref{f0} that, for $x, x_B\\in B$\n%  \\begin{equation}\n%    \\label{eqn4.3}\n%    \\begin{aligned}\n%f(x)-f(x_B)\n%&={\\rm Re}\\int_{\\mathbb{R}^d}\n%(e^{i\\omega\\cdot x}-e^{i\\omega\\cdot x_B}) \n%\\hat{f}(\\omega)d\\omega \\\\\n%&={\\rm Re}\\int_{\\mathbb{R}^d}\n%(e^{i\\omega\\cdot x}-e^{i\\omega\\cdot x_B})  \n% e^{i\\theta\n%    (\\omega)}|\\hat{f}(\\omega)|d\\omega \\\\\n%    &=\\int_{\\mathbb{R}^d}(\\cos(\\omega\\cdot\n%    x+\\theta(\\omega))-\\cos(\\omega\\cdot x_B+\\theta(\\omega)))|\\hat{f}(\\omega)|d\\omega \\\\\n%&=\\int_{\\mathbb{R}^d}(\\cos(\\omega\\cdot(x-x_B)+\\theta_B(\\omega))-\\cos(\\theta_B(\\omega)))|\\hat{f}(\\omega)|d\\omega \\\\\n%&=\\int_{\\mathbb{R}^d}g(x,\\omega)|\\hat{f}(\\omega)|d\\omega \\\\\n%&=\\|f\\|_{B^m}\\int_{\\mathbb{R}^d}|\\omega|_B^{-m}g(x,\\omega)\\lambda^{m}(\\omega)d\\omega \n%%\\\\&=\\int_{\\mathbb{R}^d}\\|f\\|_{B^m}\n%%(\\cos(\\omega\\cdot x+\\theta(\\omega))-\\cos(\\omega\\cdot x_B+\\theta(\\omega)))\\lambda(\\omega)d\\omega \\\\\n%%  &=\\int_{\\mathbb{R}^d} g(x,\\omega)\\lambda(\\omega)d\\omega,\n%\\end{aligned}\n%  \\end{equation}\n%where\n%$$\n%\\theta_B(\\omega)=\\omega\\cdot x_B+\\theta(\\omega)\n%$$\n%and $g: B\\times \\mathbb{R}^d\\rightarrow \\mathbb{R}$\n%is given by\n%\\begin{equation}\\label{gz}\n%  g(x,\\omega):=\n%\\cos(\\omega\\cdot (x-x_B)+\\theta_B(\\omega))  -\\cos(\\theta_B(\\omega)),\n%\\end{equation}\n%\n%\\begin{equation}\n%\\label{lambda}\n%\\lambda^m(\\omega)=\\frac{|\\omega|_B^m|\\hat{f}(\\omega)|}{\\|f\\|_B^m}\n%\\end{equation}\n%is a  probability distribution density function. \n%\n%We define \n%\\begin{equation}\n%\\|f\\|_{B^m}:=\\int_{\\mathbb R^d}|\\omega|_B^m|\\hat{f}(\\omega)|d\\omega,\n%\\end{equation}\n%\\begin{equation}\n%\\|f\\|_{B^m}:=\\inf_{f^e|_B=f}\\int_{\\mathbb R^d}|\\omega|_B^m|\\hat{f^e}(\\omega)|d\\omega,\n%\\end{equation}\n%where \n%$$\n%|\\omega|_B:=\\sup\\limits_{x\\in B}|\\omega\\cdot(x-x_B)|\n%$$\n%We note that, if, for example,  $B=B_r=\\{x:|x|\\le r\\}$, we then have $|\\omega|_{B_r}\n%=r\\cdot |\\omega|$ if $x_B=0$.  In general\n%$$\n%|\\omega|_B\\le {\\rm diam}(B)|\\omega|. \n%$$\n%\n%We then obtain the following result. \n%\\begin{lemma}\n%\\label{lem2.2}\n%\\begin{equation}\n%\\frac{f(x)-f(x_B)}{\\|f\\|_{B^m}}\n%=\\int_{\\mathbb R^d} \\frac{g(x,\\omega)}{|\\omega|^m}\\lambda(\\omega)d\\omega =\\mathbb E_\\omega(\\frac{g(x, \\omega)}{|\\omega|_B^m})\n%\\end{equation}\n%and \n%$g$ is given by \\eqref{gz} and satisfies\n%\\begin{equation}\\label{g-bound1}\n%|g(x,\\omega)|\\le  \\min(2,|\\omega|_B)\\quad \\forall x\\in B,  \\omega\\in \\mathbb\n%R^d.  \n%\\end{equation}\n%\\end{lemma}\n%\n%\\begin{theorem}\n%\\label{thm:cos} For a probability measure $\\mu$ on $B$ and every\n%  function $f$ with $\\|\\hat f\\|_{L^1}< \\infty$, there exist\n% $\\omega_1,\\ldots,\\omega_n\\in \\mathbb R^d$ such that\n%\\begin{equation}\n% \\int_{B}\\left|f(x)-f(x_B)-\\frac{\\|\\hat f\\|_{L^1}}{n}\n%    \\sum_{i=1}^ng(x,\\omega_i)\\right|^2\\/d\\mu(x) \\le \\frac{4\\|\\hat f\\|^2_{L^1}}{n}.\n%\\end{equation}\n%\\end{theorem}\n%\\begin{theorem}\n%  \\label{thm2.1} For a probability measure $\\mu$ on $B$ and every\n%  function $f$ with $\\|f\\|_{B}< \\infty$, there exist\n%  $\\omega_1,\\ldots,\\omega_n\\in \\mathbb R^d$ such that\n%\\begin{equation}\n%\\int_{B}\\left|f(x)-f(x_B)-\\frac{\\|f\\|_{B}}{n} \\sum_{i=1}^n\\frac{g(x,\\omega_i)}{|\\omega_i|}\\right|^2\\/d\\mu(x) \\le \\frac{\\|f\\|^2_B}{n}.\n%\\end{equation}\n%\\end{theorem}\n%\\begin{proof}\n%Denote\n%$$\n%\\tilde f(x)=\\frac{f(x)-f(x_B)}{\\|f\\|_{B^m}}\n%$$\n%By Lemma \\ref{MC} and Lemma \\ref{lem2.2}, we have for $m=0,1$,\n%\\begin{equation}\n%    \\label{eqn3.10}\n%    \\begin{aligned}\n%      &\\quad \\mathbb{\\bar E}\\left(\\tilde f(x)-\\frac1n\\sum_{i=1}^n\\frac{g(x,\\omega_i)}{|\\omega|_B^m}\\right)^2 \\\\\n%      &=\\mathbb{\\bar E}(\\mathbb{E}_\\omega(\\frac{g(x,\\omega)}{|\\omega|_B^m})-\n%      \\frac1n\\sum_{i=1}^n \\frac{g(x,\\omega_i)}{|\\omega|_B^m})^2 \\\\\n%      &\\le\\frac{1}{n}\\max_{x\\in B, \\omega\\in \\mathbb R^d}\\frac{|g(x,\\omega)|^2}{|\\omega|_B^{2m}}\\\\\n%      &\\le \\frac{4^{1-m}}{n}\n%    \\end{aligned}\n%\\end{equation}\n%\n%By the Fubini's theorem,\n%  \\begin{equation}\n% \\label{eqn3.11}\n%  \\begin{aligned}\n% &\\quad  \\mathbb{\\bar E}\\int_B(\\tilde f(x)-\\frac1n\\sum_{i=1}^n\\frac{g(x,\\omega_i)}{|\\omega_i|_B^m})^2 \\mu(dx)\\\\\n% &=\\int_B \\mathbb{\\bar E} (\\tilde f(x)-\\frac1n\\sum_{i=1}^n\\frac{g(x,\\omega_i)}{|\\omega_i|_B^m})^2 \\mu(dx)\\\\\n%    &\\le \\frac{4^{1-m}}{n}.\n%  \\end{aligned}\n%  \\end{equation}\n%Therefore, there exists a sequence of $\\{\\omega_i\\}_{i=1}^n$ where\n%$\\omega_i\\in \\mathbb{R}^d$, such that \n%$$\n%\\int_B  (\\tilde\n%f(x)-\\frac1n\\sum_{i=1}^n\\frac{g(x,\\omega_i)}{|\\omega_i|_B^m})^2\n%\\mu(dx)\n%\\le \\frac{4^{1-m}}{n}.\n%$$\n%This complete the proof. \n%\\end{proof}\n%Recalling \\eqref{gz}, we have\n%\\begin{eqnarray*}\n%f_n\n%&\\equiv& f(0)+\\frac{\\| f\\|_B}{n} \\sum_{i=1}^n\\frac{g(\\cdot,\\omega_i)}{|\\omega_i|_B}\\\\\n%&=& f(0)+\\frac1n \\sum_{i=1}^n \\frac{\\|f\\|_B}{|\\omega_i|_B}(\\cos(\\omega_i\\cdot x+\\theta(\\omega_i))  -\\cos(\\theta(\\omega_i)))\\\\\n%&=& \n%\\frac1n \\sum_{i=1}^n \\frac{\\|f\\|_B}{|\\omega_i|_B}(\\cos(\\omega_i\\cdot\n%x+\\theta(\\omega_i))  +\\left(\n%f(0)-\\frac1n \\sum_{i=1}^n \\frac{\\|f\\|_B}{|\\omega_i|_B}\\cos(\\theta(\\omega_i)) \\right)\\\\\n%&=& \n%\\sum_{i=1}^n a_i\\cos(\\omega_i\\cdot x+b_i)  +c\n%\\end{eqnarray*}\n%where\n%$$\n%a_i=\\frac1n \\frac{\\|f\\|_B}{|\\omega_i|_B}, b_i=\\theta(\\omega_i), c=f(0)-\\frac1n \\sum_{i=1}^n \\frac{\\|f\\|_B}{|\\omega_i|_B}\\cos(\\theta(\\omega_i)).\n%$$\n%\n%\\begin{theorem}\n%  \\begin{equation}\n%\\min_{a_i,b_i,c\\in \\mathbb R^1, \\omega_i\\in \\mathbb R^d}\n%\\int_{B}|f(x)-\\sum_{i=1}^n a_i\\cos(\\omega_i\\cdot x+b_i)\n%-c|^2\\mu(dx)\\le \\frac{4\\|\\hat f\\|^2_{L^1(\\mathbb R^d)}}{n}.\n%  \\end{equation}\n% \\end{theorem}\n\n\\section{An improved analysis}\n\\subsection{Heaviside Function}\nDefine $g_i: [-1,1]\\mapsto \\mathbb R$ as\nfollows:\n\\begin{equation}\n  \\label{psi}\ng_i(t)=\\frac{1}{|\\omega_i|_B}[\\cos(|\\omega_i|_Bt+\\theta_B(\\omega_i))  -\\cos(\\theta_B(\\omega_i))],\n\\end{equation}\nIn view of \\eqref{gz}, we have\n\\begin{equation}\n  \\label{gpsi}\ng_i(s_i)=\\frac{g(x,\\omega_i)}{|\\omega_i|_B}, \\quad s_i=\\omega_i^B\\cdot(x-x_B),\\quad \\omega^B=\\frac{\\omega}{|\\omega|_B}\n\\end{equation}\nNow, we take an integer\n\\begin{equation}\n  \\label{k}\nk\\ge \\sqrt{n}  \n\\end{equation}\nand consider a partition of $[-1,1]$ with the following grid points\n$$\nt_j=jh_k, j=-k:k\n$$\nwith \n$$\n h_k=\\frac{1}{k}\\le \\frac{1}{\\sqrt{n}}.\n$$\nWe first take a piecewise constant interpolation for $g_i$ on $[0,1]$ to get\n$$\ng_{i,k}(t)=(\\Pi_kg_i)(t)=\\sum_{j=0}^{k-1}g_i(t_j) M_j(t),   \n$$\nwhere\n$$\nM_j(t)=M_0(\\frac{t-t_j}{h_k})\n$$\nand\n\\begin{equation}\n  \\label{cardinal}\nM_0(x)=\n\\left\\{\n  \\begin{array}{ll}\n0 & x\\le0 \\\\\n1 & 0< x\\le1    \\\\\n0 & x > 1    \n  \\end{array}\n\\right.\n\\end{equation}\nWe note that\n$$\nM_0(x)=H(x)-H(x-1)\n$$\nwhere $H$ is the Heaviside function\nThus\n$$\nM_0(\\frac{t-t_{j}}{h_k})\n=H(\\frac{t-t_{j}}{h_k})-H(\\frac{t-t_{j}}{h_k}-1)=H(\\frac{t-t_{j}}{h_k})-H(\\frac{t-t_{j+1}}{h_k})\n\\equiv H_{j}(t)-H_{j+1}(t).\n$$\nThus, since $g_i(t_0)=0, H_k=0$, we have\n\\begin{equation}  \\label{gi0}\ng_{i,k}(t)=\\sum_{j=0}^{k-1}g_i(t_j) M_j(t)\n=\\sum_{j=1}^{k-1}(g_i(t_j) - g_i(t_{j-1})) H_{j}(t), \\quad t\\in [0,1]\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\nNow we consider\n\\begin{equation}\nh_i(t) = g_i(-t), \\quad t\\in [0,1].\n\\end{equation}\nSimilar to \\eqref{gi0}, we have\n$$\n(\\Pi_kh_i)(t)=\\sum_{j=1}^{k-1}(h_i(t_j) - h_i(t_{j-1}))H_j(t)=\n=\\sum_{j=1}^{k-1}(g_i(-t_j) - g_i(-t_{j-1}))H_j(t)\n$$\nNamely\n$$\n(\\Pi_k g_i)(-t)=\\sum_{j=1}^{k-1}(g_i(-t_j) - g_i(-t_{j-1}))H_j(t), \\quad t\\in [0,1]\n$$\nor\n\\begin{equation}\\label{gi1}\n(\\Pi_k g_i)(t)=\\sum_{j=1}^{k-1}(g_i(-t_j) - g_i(-t_{j-1}))H_j(-t), \\quad t\\in [-1,0]\n\\end{equation}\nBy combining \\eqref{gi0} and \\eqref{gi1}, we get a piecewise constant\ninterpolation of $g_i$ on $[-1,1]$ as follows:\n\\begin{eqnarray}\ng_{i,k}(t)&=&\n\\sum_{j=1}^{k-1}(g_i(-t_j) - g_i(-t_{j-1}))H_j(-t)+\\sum_{j=1}^{k-1}(g_i(t_j) - g_i(t_{j-1})) H_{j}(t)\\nonumber \\\\ \n&=&\\sum_{j=1}^{k-1}[a_{ij}^-H_j(-t)+a_{ij}^+H_{j}(t)] \\label{gih}\n\\quad t\\in [-1,1]\n\\end{eqnarray}\nwhere \n$$\na_{ij}^{\\pm}=g_i(\\pm t_j) - g_i(\\pm t_{j-1})\n$$\nIt is easy to see that\n\\begin{equation}\n|g_i(t)-g_{i,k}(t)|\\le h_k, \\quad t\\in [-1,1].\n\\end{equation} \n\n\\begin{equation}\n\\|\\frac1n \\sum_{i=1}^n \\frac{g(\\cdot,\\omega_i)}{|\\omega_i|_B}-f^*\\|_{L^2(\\mu,B)}\\le h_k\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{fstar}\nf^*(x)=\n\\frac1n\\sum_{i=1}^ng_{i,k}(\\omega_i^B\\cdot (x-x_B)).\n\\end{equation}\nBy the approximation in last section, we have \n\\begin{equation}\n  \\|\\tilde f-f^*\\|_{L^2(\\mu,B)}\\le \\frac{2}{\\sqrt{n}}\n\\end{equation}\nLet us rewrite\n$$\nf^*(x)\n=\\sum_{i=1}^n\\sum_{j=1}^{k-1}[\\gamma_{ij}^- f_{ij}^-+ \\gamma_{ij}^+f_{ij}^+]\n$$\nwhere\n$$\n\\gamma_{ij}^{\\pm}=\\frac{|a^\\pm_{ij}|}{nd_i}, \nf^\\pm_{i,j}=d_i\\/{\\rm sign}(a^\\pm_{ij})H_j(\\pm \\omega_i^B\\cdot (x-x_B))\n$$\nand \n$$\nd_i=\\sum_{j=1}^{k-1}(|a^-_{ij}|+|a^+_{ij}|)\\le 2\n$$\nBy definition\n\\begin{equation}\n  \\label{gammaij}\n\\sum_{i=1}^n\\sum_{j=1}^{k-1}[\\gamma_{i,j}^-+\\gamma_{i,j}^+]=1.\n\\end{equation}\nWith re-numeration as\n$$\np_\\ell=\\gamma_{ij}^{\\pm}, f_\\ell = f_{ij}^{\\pm}, 1\\le \\ell \\le N=2n(k-1)\n$$\nWe have\n$$\nf^*(x)=\\sum_{\\ell=1}^N p_\\ell f_\\ell\n$$\nConsider \n$$\n\\mathcal N=\\{1,2,\\ldots, N\\}\n$$\nand \n$$\n\\bar f: \\mathcal N\\mapsto \\mathbb R^1\n$$\nsuch that\n$$\n\\bar  f(\\ell)=f_{\\ell}, \\ell\\in \\mathcal N\n$$\nWith the probability measure\n$$\n\\mu(\\mathcal M)=\\sum_{m\\in \\mathcal M}p_m \\quad \\mathcal M\\subset\\mathcal N.\n$$\nBy definition. \n$$\n\\mathbb E(\\bar  f) = f^*(x).\n$$\nBy the basic result on expectation in Lemma \\ref{MC1}, we have\n$$\n\\sum_{\\ell_1,\\ldots \\ell_n=1}^Np_{\\ell_1}\\cdots p_{\\ell_n}\\left(f^*(x)-\n{1\\over n}\\sum_{i=1}^n f_{\\ell_i}\\right)^2\n=\\mathbb E_{\\mathcal N^n} \\left(\\mathbb E(\\bar f)-{1\\over\n    n}\\sum_{i=1}^n  \\bar  f(\\ell_i)\\right)^2\\\\\n\\le\\frac1n \\|\\bar  f\\|_{\\infty}^2 \\le\\frac4n.\n$$\nBy taking the $L^2(\\mu,B)$ on the above inequality, we get\n$$\n\\sum_{\\ell_1,\\ldots \\ell_n=1}^Np_{\\ell_1}\\cdots p_{\\ell_n}\\|f^*-{1\\over n}\\sum_{i=1}^n f_{\\ell_i}\\|_{L^2(\\mu,B)}^2\n\\le\\frac4n.\n$$\nThus, there exisit $\\ell_1^*, \\ldots, \\ell_n^*\\in \\mathcal N$ such that\n$$\n\\|f^*-{1\\over n}\\sum_{i=1}^n f_{\\ell_i^*}\\|_{L^2(\\mu,B)}^2\n\\le\\frac4n.\n$$\nwhere\n$$\nf_n(x)={1\\over n}\\sum_{i=1}^n f_{\\ell_i^*}(x).\n$$\nThen we have \n\\begin{equation}\n\\|\\tilde f-f_n\\|^2_{L^2(\\mu,B)}\\le \\frac{9}{n}.\n\\end{equation}\nConsequently\n\\begin{equation}\n\\left\\|f(x)-f(x_B)-\\|f\\|_Bf_n\\right\\|^2_{L^2(\\mu,B)}\\le \\frac{9\\|f\\|^2_B}{n}.\n\\end{equation}\n\n\\subsection{Piecewise linear function}\nThe proof here is almost the same as the proof for Heaviside function in the last part. \n\nNow we take a piecewise linear interpolation for $g_i$ on $[0,1]$, since $g_i(t_0)=0$ , we get\n$$\ng_{i,k}(t)=(\\Pi_kg_i)(t)=\\sum_{j=1}^{k}[g_i(t_{j})-g_i(t_{j-1})]\\sigma_{j-1}(t),   \\quad t\\in [0,1]\n$$\nwhere\n$$\n\\sigma_j(t)=M_0(\\frac{t-t_j}{h_k})\n$$\nand\n\\begin{equation}\n\\label{cardinal}\nM_0(x)=\n\\left\\{\n\\begin{array}{ll}\n0 & x\\le0 \\\\\nx & 0< x\\le1    \\\\\n1 & x > 1    \n\\end{array}\n\\right.\n\\end{equation}\n%We note that\n%$$\n%M_0(x)=ReLU(x)-ReLU(x-1)\n%$$\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\nConsider\n\\begin{equation}\nh_i(t) = g_i(-t), \\quad t\\in [0,1].\n\\end{equation}\nSimilarly, we have\n$$\n(\\Pi_kh_i)(t)=\\sum_{j=1}^{k}(h_i(t_j) - h_i(t_{j-1}))\\sigma_{j-1}(t)=\n=\\sum_{j=1}^{k}(g_i(-t_j) - g_i(-t_{j-1}))\\sigma_{j-1}(t)\n$$\nNamely\n$$\n(\\Pi_k g_i)(-t)=\\sum_{j=1}^{k}(g_i(-t_j) - g_i(-t_{j-1}))\\sigma_{j-1}(t), \\quad t\\in [0,1]\n$$\nor\n\\begin{equation}\\label{gi1}\n(\\Pi_k g_i)(t)=\\sum_{j=1}^{k}(g_i(-t_j) - g_i(-t_{j-1}))\\sigma_{j-1}(-t), \\quad t\\in [-1,0]\n\\end{equation}\nCombine together we get a piecewise linear\ninterpolation of $g_i$ on $[-1,1]$ as follows:\n\\begin{eqnarray}\ng_{i,k}(t)&=&\n\\sum_{j=1}^{k}(g_i(-t_j) - g_i(-t_{j-1}))\\sigma_{j-1}(-t)+\\sum_{j=1}^{k}(g_i(t_j) - g_i(t_{j-1}))\\sigma_{j-1}(t)\\nonumber \\\\ \n&=&\\sum_{j=1}^{k}[a_{ij}^-\\sigma_{j-1}(-t)+a_{ij}^+\\sigma_{j-1}(t)] \\label{gih}\n\\quad t\\in [-1,1]\n\\end{eqnarray}\nwhere \n$$\na_{ij}^{\\pm}=g_i(\\pm t_j) - g_i(\\pm t_{j-1})\n$$\n%It is easy to see that\n%\\begin{equation}\n%|g_i(t)-g_{i,k}(t)|\\le h_k, \\quad t\\in [-1,1].\n%\\end{equation} \n%\\begin{equation}\n%\\|\\frac1n \\sum_{i=1}^n \\frac{g(\\cdot,\\omega_i)}{|\\omega_i|_B}-f^*\\|_{L^2(\\mu,B)}\\le h_k\n%\\end{equation}\n%where\n%\\begin{equation}\n%\\label{fstar}\n%f^*(x)=\n%\\frac1n\\sum_{i=1}^ng_{i,k}(\\omega_i^B\\cdot (x-x_B)).\n%\\end{equation}\n%\n%By Theorem \\ref{jones}, we have \n%\\begin{equation}\n%%\\|\\tilde f-f^*\\|_{1,B}\\le \\frac{C_1(d,B)}{\\sqrt{n}}\n%  \\|\\tilde f-f^*\\|_{L^2(\\mu,B)}\\le \\frac{2}{\\sqrt{n}}\n%\\end{equation}\n%here $C_1(d,B)=\\sqrt{\\mu(B)}[\\sqrt{(d+{\\rm diam}(B))}+{\\rm diam}(B)(1+d)]$.\n\n\n%Let us rewrite\n%$$\n%f^*(x)\n%=\\sum_{i=1}^n\\sum_{j=1}^{k}[\\gamma_{ij}^- f_{ij}^-+ \\gamma_{ij}^+f_{ij}^+]\n%$$\n%where\n%$$\n%\\gamma_{ij}^{\\pm}=\\frac{|a^\\pm_{ij}|}{nd_i}, \n%f^\\pm_{i,j}=d_i\\/{\\rm sign}(a^\\pm_{ij})\\sigma_{j-1}(\\pm \\omega_i^B\\cdot (x-x_B))\n%$$\n%and \n%$$\n%d_i=\\sum_{j=1}^{k}(|a^-_{ij}|+|a^+_{ij}|)\\le 2\n%$$\n%By definition\n%\\begin{equation}\n%\\label{gammaij}\n%\\sum_{i=1}^n\\sum_{j=1}^{k}[\\gamma_{i,j}^-+\\gamma_{i,j}^+]=1.\n%\\end{equation}\n%With re-numeration as\n%$$\n%p_\\ell=\\gamma_{ij}^{\\pm}, f_\\ell = f_{ij}^{\\pm}, 1\\le \\ell \\le N=2nk\n%$$\n%We have\n%$$\n%f^*(x)=\\sum_{\\ell=1}^N p_\\ell f_\\ell\n%$$\n%Consider \n%$$\n%\\mathcal N=\\{1,2,\\ldots, N\\}\n%$$\n%and \n%$$\n%\\bar f: \\mathcal N\\mapsto \\mathbb R^1\n%$$\n%such that\n%$$\n%\\bar f(\\ell)=f_{\\ell}, \\ell\\in \\mathcal N\n%$$\n%With the probability measure\n%$$\n%\\lambda(\\mathcal M)=\\sum_{m\\in \\mathcal M}p_m \\quad \\mathcal M\\subset\\mathcal N.\n%$$\n%By definition. \n%$$\n%\\mathbb E(\\bar f) = f^*(x).\n%$$\n%\n%By the basic result on expectation:\n%\\begin{equation}\n%\\begin{aligned}\n%&\\sum_{\\ell_1,\\ldots \\ell_n=1}^Np_{\\ell_1}\\cdots p_{\\ell_n}\\left((f^*(x)-\n%{1\\over n}\\sum_{i=1}^n f_{\\ell_i})^2\\right)\\\\\n%=&\\mathbb E_{\\mathcal N^n} \\left(\\mathbb E(\\bar f)-{1\\over\n%\tn}\\sum_{i=1}^n  \\bar f(\\ell_i)\\right)^2\n%\\le\\frac1n \\|\\bar f\\|_{\\infty}^2 \\le\\frac{4}{n}.\n%\\end{aligned}\n%\\end{equation}\n%\n%By taking the $L^2(\\mu,B)$ on the above inequality, we get\n%$$\n%\\sum_{\\ell_1,\\ldots \\ell_n=1}^Np_{\\ell_1}\\cdots p_{\\ell_n}\\|f^*-{1\\over n}\\sum_{i=1}^n f_{\\ell_i}\\|_{L^2(\\mu,B)}^2\n%\\le\\frac4n.\n%$$\n%Thus, there exisit $\\ell_1^*, \\ldots, \\ell_n^*\\in \\mathcal N$ such that\n%$$\n%\\|f^*-f_n(x)\\|_{L^2(\\mu,B)}^2\n%\\le\\frac4n.\n%$$\n%where\n%$$\n%f_n(x)={1\\over n}\\sum_{i=1}^n f_{\\ell_i^*}(x).\n%$$\n%Then we have \n%\\begin{equation}\n%\\|\\tilde f-f_n\\|^2_{L^2(\\mu,B)}\\le \\frac{9}{n}.\n%\\end{equation}\n\n%Consequently\n%\\begin{equation}\n%\\left\\|f(x)-f(x_B)-\\|f\\|_Bf_n\\right\\|^2_{L^2(\\mu,B)}\\le \\frac{9\\|f\\|^2_B}{n}.\n%\\end{equation}\n\nFollow the procedure in last section, and notice that $\\sigma(x)=ReLU(x)-ReLU(x-1)$, we obtain the following theorem.\n\n\n\\begin{theorem}\n\tFor a probability measure $\\mu$ on B and every function with $\\|f\\|_B<\\infty$, there exists $\\omega_1,\\dots,\\omega_n\\in\\mathbb{R}^d$ such that \n$$\n\\left\\|f(x)-f_n(x)\\right\\|^2_{L^2(\\mu,B)}\\le \\frac{C\\|f\\|^2_B}{n}.\n$$\nwhere $f_n(x)=\\sum_{i=1}^{n}a_iReLU(\\omega_i x+b_i)+c$.\n\\end{theorem}\n", "meta": {"hexsha": "09664d6f63e9e7756d01165db569a75533c88479", "size": 19538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/X-Approx.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/X-Approx.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/X-Approx.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": 29.5582450832, "max_line_length": 144, "alphanum_fraction": 0.5906950558, "num_tokens": 9123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6126838930066297}}
{"text": "% !TEX root = main.tex\n\n\\section{Mathematics}\n\n\\begin{itemize}\n\\item\nAn inline equation with TeX delimiters (dollars): $\\sum_{n=1}^{\\infty} a_n = 1$.\n\\item\nAn inline equation with LaTeX delimiters: \\(\\sum_{n=1}^{\\infty} a_n = 1\\).\n\\end{itemize}\n\n\\bigskip\nAn \\texttt{equation} environment:\n\\begin{equation}\n\\sum_{n=1}^{\\infty} a_n = 1.\n\\end{equation}\n\nAn \\texttt{equation*} environment:\n\\begin{equation*}\n\\sum_{n=1}^{\\infty}\\frac{1}{n^2} = \\frac{\\pi^2}{6}.\n\\end{equation*}\n\nA \\texttt{display} environment with LaTeX delimiters:\n\\[\nx = \\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}.\n\\]\n\nA \\texttt{display} environment with TeX delimiters (double-dollars):\n$$\nx = \\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}.\n$$\n\nA \\texttt{display} environment containing a \\texttt{text} command, which itself contains (inline) mathmode:\n\\[\nE=mc^2 \\text{ where $c$ is the speed of light}.\n\\]\n\n\\subsection{Labelled equations}\n\nAn equation with a label:\n\\begin{equation}\\label{eq:euler}\ne^{i\\pi}+1=0.\n\\end{equation}\n\nEquation -\\eqref{eq:euler}- is due to Euler.\n\nAn \\texttt{align} environment:\n\\begin{align}\\label{eq:polar}\nx & = r\\sin\\theta \\\\\ny & = r\\cos\\theta\n\\end{align}\n\n%\\bigskip\n%A labelled \\texttt{equation} environment:\n%\\begin{equation}\\label{eq:einstein}\n%E = mc^2\n%\\end{equation}\n%Equation -\\eqref{eq:einstein}- is due to AE. \n\n\\bigskip\nAn {\\tt equation} containing three {\\tt pmatrix} environments:\n\\begin{equation}\n\\begin{pmatrix}0 & 1 \\\\ 1 & 0\\end{pmatrix}\n\\qquad\n\\begin{pmatrix}0 & -i \\\\ i & 0\\end{pmatrix}\n\\qquad\n\\begin{pmatrix}1 & 0 \\\\ 0 & -1\\end{pmatrix}\n\\end{equation}\n\n", "meta": {"hexsha": "f3cafca718b02253832e4b078206faa17c7b6b21", "size": 1540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/test_article/_maths.tex", "max_stars_repo_name": "imagingbook/latextree", "max_stars_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-16T22:41:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-16T22:41:21.000Z", "max_issues_repo_path": "tex/test_article/_maths.tex", "max_issues_repo_name": "imagingbook/latextree", "max_issues_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_issues_repo_licenses": ["MIT"], "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_article/_maths.tex", "max_forks_repo_name": "imagingbook/latextree", "max_forks_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-11T09:38:25.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T15:30:21.000Z", "avg_line_length": 22.0, "max_line_length": 107, "alphanum_fraction": 0.6811688312, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6126838820408407}}
{"text": "% !TeX root = ../main.tex\n\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\section{Geometric transformation}\n\\begin{lemma}\\label{M:transform:distance}\nFor any point \\(p,q\\in N\\)\nand element \\(X\\in X\\left(n,\\lambda\\right)\\),\n\\[\n\\norm{\\left(Xp\\right)\\left(Xq\\right)}=\\norm{pq}\\text{.}\n\\]\n\\end{lemma}\n\\begin{proof}[\\proofof{M:transform:distance}]\nIf \\(\\lambda>0\\),\n\\begin{align*}\nX^{-1}&=X^T\\\\\n&=X^TI\\\\\nI&=X^TIX\\\\\ng&=X^TgX\\text{.}\n\\end{align*}\nIf \\(\\lambda\\to 0\\),\n\\begin{align*}\nX&\\to I\\\\\nX^T\n&\\to I^T\\\\\n&=I\\\\\ng&=g\\\\\ng&=IgI\\\\\ng&\\to X^TgX\\text{.}\n\\end{align*}\nIf \\(\\lambda<0\\),\n\\begin{align*}\nX^{-1}&=gX^Tg\\\\\nI&=gX^TgX\\\\\ng^{-1}&=X^TgX\\\\\ng&=X^TgX\\text{.}\n\\end{align*}\n\\begin{align*}\n\\norm{pq}\n&=\\sqrt{g\\left(q-p,q-p\\right)}\\\\\n&=\\sqrt{\\left(q-p\\right)^Tg\\left(q-p\\right)}\\\\\n\\norm{\\left(Xp\\right)\\left(Xq\\right)}\n&=\\sqrt{g\\left(Xq-Xp,Xq-Xp\\right)}\\\\\n&=\\sqrt{g\\left(X\\left(q-p\\right),X\\left(q-p\\right)\\right)}\\\\\n&=\\sqrt{\\left(X\\left(q-p\\right)\\right)^Tg\\left(X\\left(q-p\\right)\\right)}\\\\\n&=\\sqrt{\\left(q-p\\right)^TX^TgX\\left(q-p\\right)}\\\\\n&=\\sqrt{\\left(q-p\\right)^Tg\\left(q-p\\right)}\\\\\n&=\\norm{pq}\\qedhere\n\\end{align*}\n\\end{proof}\n\\end{document}", "meta": {"hexsha": "59b0a87e628bf0ac95aa3867912c0303eb1a6c57", "size": 1144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/transformation.tex", "max_stars_repo_name": "30MA19-02/proof", "max_stars_repo_head_hexsha": "24d95d419e5632a2cc08a9c9bc94e89e262afc04", "max_stars_repo_licenses": ["MIT"], "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/transformation.tex", "max_issues_repo_name": "30MA19-02/proof", "max_issues_repo_head_hexsha": "24d95d419e5632a2cc08a9c9bc94e89e262afc04", "max_issues_repo_licenses": ["MIT"], "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/transformation.tex", "max_forks_repo_name": "30MA19-02/proof", "max_forks_repo_head_hexsha": "24d95d419e5632a2cc08a9c9bc94e89e262afc04", "max_forks_repo_licenses": ["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.88, "max_line_length": 74, "alphanum_fraction": 0.6092657343, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6126838772415056}}
{"text": "\\chapter{Mathematical derivations of MOFA+} \\label{appendix:mofa}\n\n\\section{Deriving the variational inference algorithm}\n\nThe theoretical foundations for the variational inference scheme are described in \\Cref{section:variational_inference}. Just to brief, we need to define a variational distribution of a factorised form and subsequently look for the member of this family that most closely resembles the true posterior using the KL divergence as a \\textit{distance} metric. Following the mean-field principle, in MOFA+ we factorised the variational distribution as follows:\n\n\\begin{equation} \\begin{aligned}\n\tq(\\bfX) &= q \\left(\\{\\widehat{\\bfZ^\\bfg}, \\bfS^\\bfg, \\bf{\\alpha^g}, \\bf{\\theta^g}\\}, \\{\\widehat{\\bfW^m}, \\bfS^m, \\bf\\alpha^m, \\bf\\theta^m\\}, \\{ \\bf\\tau^{gm}\\} \\right)\\\\\n\t&= \\prod_{g=1}^{G} \\prod_{n=1}^{N_g} \\prod_{k=1}^{K} q(\\hat{z}_{nk}^g, s_{nk}^g) \\prod_{g=1}^{G} \\prod_{k=1}^{K} q(\\alpha_k^g) \\prod_{g=1}^{G} \\prod_{k=1}^{K} q(\\theta_k^g) \\\\\n\t&\\times \\prod_{m=1}^{M} \\prod_{d=1}^{D_m} \\prod_{k=1}^{K} q(\\hat{w}_{kd}^m,s_{kd}^m) \\prod_{m=1}^{M} \\prod_{k=1}^{K} q(\\alpha_k^m) \\prod_{m=1}^{M} \\prod_{k=1}^{K} q(\\theta_k^m)  \\\\\n\t&\\times \\prod_{g=1}^{G} \\prod_{m=1}^{M} \\prod_{d=1}^{D_m} q(\\tau_d^{gm})\n\\end{aligned} \\end{equation}\n\nHowever, inspired by \\cite{Titsias2011}, we did not adopt a fully factorised distribution as $\\hat{w}_k^m$ and $s_k^m$ can hardly be assumed to be independent.\n\nTo derive the variational updates we can proceed in two ways, as described in \\Cref{section:variational_inference}. One option is to use exploit the  mean-field assumption and use calculus of variations to find the optimal distribution $q(\\bfX)$ that maximises the lower bound $\\Lagr(\\bfX)$\\cite{Bishop2006,Murphy}. The alternative and possibly easier approach is to define a parametric form for the distribution $q(\\bfX)$ with some parameters $\\bTheta$ to be of the same form as the corresponding prior distribution $p(\\bfX)$. Then, one can find the gradients with respect to the parameters to obtain the coordinate ascent optimisation scheme. In our derivations we followed the first approach, but because we used conjugate priors the second one should converge to the same result.\\\\\nBelow we give the explicit update equations for every hidden variable in the MOFA+ model which are applied at each iteration of the variational inference algorithm.\n\n\\section{Variational update equations}\n\n\\paragraph*{Factors}\n\nFor every group $g$, sample $n$ and factor $k$: \\\\\n\nPrior distribution $p(\\hat{z}_{nk}^g,s_{nk}^g)$:\n\\begin{align}\n\tp(\\hat{z}_{nk}^g,s_{nk}^g) &= \\mathcal{N} (\\hat{z}_{nk}^g \\,|\\, 0, ~ 1/\\alpha_k^g)\\, \\text{Ber}(s_{nk}^g \\,|\\,\\theta_k^g)\n\\end{align}\n\nVariational distribution $q(\\hat{z}_{nk}^g,s_{nk}^g)$:\\\\\n\nUpdate for $q(s_{nk}^g)$:\n\\begin{equation}\n\tq(s^g_{nk}) = \\mathrm{Ber}(s^g_{nk}|\\gamma^g_{nk})\n\\end{equation}\nwith\n\\begin{equation} \\begin{aligned}\n\t&\\gamma^g_{nk} = \\frac{1}{1+\\exp(-\\lambda_{nk}^g)}\\\\\n\t& \\lambda_{nk}^g = \\la \\ln\\frac{\\theta}{1-\\theta} \\ra + 0.5\\ln\\frac{\\la\\alpha_k^g\\ra}{\\la\\tau_d^{gm}\\ra} - 0.5\\ln\\left( \\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la (w_{kd}^m)^2 \\ra + \\frac{\\la\\alpha_k^g\\ra}{\\la\\tau_d^{gm}\\ra} \\right) \\\\\n\t&+ \\frac{\\la\\tau_d^{gm}\\ra}{2} \\frac{ \\left( \\sum_{m=1}^M\\sum_{d=1}^{D_m} y_{nd}^{gm} \\la w^m_{kd} \\ra - \\sum_{j \\neq k} \\la s_{nj}^g\\hat{z}_{nj}^g\\ra \\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la w^m_{kd} \\ra \\la w^m_{jd} \\ra \\right)^2} {\\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la (w_{kd}^m)^2 \\ra + \\frac{\\la\\alpha_k^g\\ra}{\\la\\tau_d^{gm}\\ra} }\n\\end{aligned} \\end{equation}\n\nUpdate for $q(\\hat{z}_{nk}^g)$:\n\\begin{equation} \\begin{aligned}\n      q(\\hat{z}_{nk}^g|s_{nk}^g=0) &= \\mathcal{N} \\left(\\hat{z}_{nk}^g \\middle| 0, 1/\\alpha_k^g \\right) \\\\\n      q(\\hat{z}_{nk}^g|s_{nk}^g=1) &= \\mathcal{N} \\left( \\hat{z}_{nk}^g \\middle| \\mu_{z_{nk}^g}, \\sigma_{z_{nk}^g}^2\\right)\n  \\end{aligned} \\end{equation}\nwith\n\\begin{equation} \\begin{aligned}\n  \t\\mu_{z_{nk}^g} &= \\frac{ \\sum_{m=1}^M\\sum_{d=1}^{D_m} y_{nd}^{m,g} \\la w^m_{kd} \\ra - \\sum_{j \\neq k} \\la s_{nj}^g\\hat{z}_{nj}^g \\ra \\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la w^m_{kd} \\ra \\la w^m_{jd} \\ra } { \\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la (w_{kd}^m)^2 \\ra + \\frac{\\la\\alpha_k^g\\ra}{\\la\\tau_d^{gm}\\ra} }\\\\\n  \t\\sigma_{z_{nk}^g}^2 &= \\frac{ \\la\\tau_d^{gm}\\ra^{-1} } { \\sum_{m=1}^M\\sum_{d=1}^{D_m} \\la (w_{kd}^m)^2 \\ra + \\frac{\\la\\alpha_k^g\\ra}{\\la\\tau_d^{gm}\\ra} }\n\\end{aligned} \\end{equation}\n\n\n\\paragraph*{ARD prior on the factors}\n\nFor every group $g$ and factor $k$: \\\\\n\nPrior distribution:\n\\begin{align}\n\tp(\\alpha_k^g) &= \\Gdist{\\alpha_k^g}{a_0^\\alpha, b_0^\\alpha}\n\\end{align}\n\nVariational distribution $q(\\alpha_k^g)$:\n\\begin{equation}\n    q(\\alpha^g_{k}) = \\Gdist{\\alpha_k^g}{\\hat{a}_{gk}^{\\alpha}, \\hat{b}_{gk}^{\\alpha}}\n\\end{equation}\nwhere:\n\\begin{equation} \\begin{aligned}\n\t\\hat{a}_{gk}^\\alpha &= a_0^\\alpha + \\frac{N_g}{2}\\\\\n\t\\hat{b}_{gk}^\\alpha &= b_0^\\alpha +\\frac{ \\sum_{n=1}^{N_g} \\la (\\hat{z}_{nk}^g)^2 \\ra }{2}\n\\end{aligned} \\end{equation}\n\n\\paragraph*{Sparsity parameter of the Factors}\n\nFor every group $g$ and factor $k$: \\\\\n\nPrior distribution:\n\\begin{align}\n\tp(\\theta_k^g) &= \\Bdist{\\theta_k^g}{a_0^\\theta,b_0^\\theta}\n\\end{align}\n\nVariational distribution:\n\\begin{equation}\n\tq(\\theta_k^g) = \\Bdist{\\theta_k^g}{\\hat{a}_{gk}^{\\theta}, \\hat{b}_{gk}^{\\theta}}\n\\end{equation}\nwhere\n\\begin{equation}\n     \\begin{aligned}\n  \t\\hat{a}_{gk}^\\theta &= \\sum_{n=1}^{N_g} \\la s^g_{nk}\\ra + a_0^\\theta\\\\\n  \t\\hat{b}_{gk}^\\theta &= b_0^\\theta - \\sum_{n=1}^{N_g} \\la s^g_{nk}\\ra + N_g\n     \\end{aligned}\n\\end{equation}\n\n\\paragraph*{Feature weights}\nFor every view $m$, feature $d$ and factor $k$: \\\\\n\nPrior distribution $p(\\hat{w}_{kd}^m,s_{kd}^m)$:\n\\begin{align}\n\tp(\\hat{w}_{kd}^m,s_{kd}^m) &= \\mathcal{N} (\\hat{w}_{kd}^m \\,|\\, 0, ~ 1/\\alpha_k^m)\\, \\text{Ber}(s_{kd}^m \\,|\\,\\theta_k^m)\n\\end{align}\n\nVariational distribution $q(\\hat{w}_{kd}^m,s_{kd}^m)$:\\\\\n\nUpdate for $q(s_{kd}^m)$:\n\\begin{equation}\n\tq(s^m_{kd}) = \\mathrm{Ber}(s^m_{kd}|\\gamma^m_{kd})\n\\end{equation}\nwith\n\\begin{equation} \\begin{aligned}\n\t&\\gamma^m_{kd} = \\frac{1}{1+\\exp(-\\lambda_{kd}^m)}\\\\\n\t& \\lambda_{kd}^m = \\la \\ln\\frac{\\theta}{1-\\theta} \\ra + 0.5\\ln\\frac{\\la\\alpha_k^m\\ra}{\\la\\tau_d^{gm}\\ra} - 0.5\\ln\\left( \\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la (z_{nk}^g)^2 \\ra + \\frac{\\la\\alpha_k^m\\ra}{\\la\\tau_d^{gm}\\ra} \\right) \\\\\n\t&+ \\frac{\\la\\tau_d^{gm}\\ra}{2} \\frac{ \\left( \\sum_{g=1}^G\\sum_{n=1}^{N_g} y_{nd}^{gm} \\la z^g_{nk} \\ra - \\sum_{j \\neq k} \\la s_{jd}^m\\hat{w}_{jd}^m\\ra \\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la z^g_{nk} \\ra \\la z^g_{nj} \\ra \\right)^2} {\\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la (z_{nk}^g)^2 \\ra + \\frac{\\la\\alpha_k^m\\ra}{\\la\\tau_d^{gm}\\ra} }\n\\end{aligned} \\end{equation}\n\nUpdate for $q(\\hat{w}_{kd}^m)$:\n\\begin{equation} \\begin{aligned}\n      q(\\hat{w}_{kd}^m|s_{kd}^m=0) &= \\mathcal{N} \\left(\\hat{w}_{kd}^m \\middle| 0, 1/\\alpha_k^m \\right) \\\\\n      q(\\hat{w}_{kd}^m|s_{kd}^m=1) &= \\mathcal{N} \\left( \\hat{w}_{kd}^m \\middle| \\mu_{w_{kd}^m}, \\sigma_{w_{kd}^m}^2\\right)\n  \\end{aligned} \\end{equation}\nwith\n\\begin{equation} \\begin{aligned}\n  \t\\mu_{w_{kd}^m} &= \\frac{ \\sum_{g=1}^G\\sum_{n=1}^{N_g} y_{nd}^{gm} \\la z^g_{nk} \\ra - \\sum_{j \\neq k} \\la s_{jd}^m\\hat{w}_{jd}^m \\ra \\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la z^g_{nk} \\ra \\la z^g_{nj} \\ra } { \\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la (z_{nk}^g)^2 \\ra + \\frac{\\la\\alpha_k^m\\ra}{\\la\\tau_d^{gm}\\ra} }\\\\\n  \t\\sigma_{w_{kd}^m}^2 &= \\frac{ \\la\\tau_d^{gm}\\ra^{-1} } { \\sum_{g=1}^G\\sum_{n=1}^{N_g} \\la (z_{nk}^g)^2 \\ra + \\frac{\\la\\alpha_k^m\\ra}{\\la\\tau_d^{gm}\\ra} }\n\\end{aligned} \\end{equation}\n\n  \t% Taken together this means that we can update $q(\\hat{w}_{kd}^m,s_{kd}^m)$ using:\n  \t% \\begin{equation*}\n  \t% q(\\hat{w}_{kd}^m|s_{kd}^m) q(s_{kd}^m) = \\Ndist{ \\hat{w}_{kd}^m } { s_{kd}^m \\mu_{w_{kd}^m}, s_{kd}^m\\sigma_{w_{kd}^m}^2 + (1-s_{kd}^m)/\\alpha_k^m}    (\\new{\\gamma_{kd}^m})^{s_{kd}^m} (1-\\new{\\gamma_{kd}^m})^{1-s_{kd}}\n  \t% \\end{equation*}\n\n\n\\paragraph*{ARD prior on the weights}\n\nFor every view $m$ and factor $k$: \\\\\n\nPrior distribution $p(\\alpha_k^m)$:\n\\[\n\tp(\\alpha_k^m) = \\Gdist{\\alpha_k^m}{a_0^\\alpha, b_0^\\alpha}\n\\]\nVariational distribution $q(\\alpha_k^m)$:\n\\begin{equation}\n    q(\\alpha^m_{k}) = \\Gdist{\\alpha_k^m}{\\hat{a}_{mk}^{\\alpha}, \\hat{b}_{mk}^{\\alpha}}\n\\end{equation}\nwhere:\n\\begin{equation} \\begin{aligned}\n\t\\hat{a}_{mk}^\\alpha &= a_0^\\alpha + \\frac{D_m}{2}\\\\\n\t\\hat{b}_{mk}^\\alpha &= b_0^\\alpha +\\frac{ \\sum_{d=1}^{D_m} \\la (\\hat{w}_{kd}^m)^2 \\ra }{2}\n\\end{aligned} \\end{equation}\n\n\n\\paragraph*{Sparsity parameter of the weights}\n\nFor every view $m$ and factor $k$: \\\\\n\nPrior distribution:\n\\[\n\tp(\\theta_k^m) = \\Bdist{\\theta_k^m}{a_0^\\theta,b_0^\\theta}\n\\]\n\nVariational distribution:\n\\begin{equation}\n\tq(\\theta_k^m) = \\Bdist{\\theta_k^m}{\\hat{a}_{mk}^{\\theta}, \\hat{b}_{mk}^{\\theta}}\n\\end{equation}\nwhere\n\\begin{equation}\n     \\begin{aligned}\n  \t\\hat{a}_{mk}^\\theta &= \\sum_{d=1}^{D_m} \\la s^m_{kd}\\ra + a_0^\\theta\\\\\n  \t\\hat{b}_{mk}^\\theta &= b_0^\\theta - \\sum_{d=1}^{D_m} \\la s^m_{kd}\\ra + D_m\n     \\end{aligned}\n\\end{equation}\n\n\n\\paragraph*{Noise (Gaussian)}\n\nFor every view $m$, group $g$ and feature $d$:\\\\\n\nPrior distribution $p(\\tau_d^{gm})$:\n\\[\n\tp(\\tau_d^{gm}) = \\Gdist{\\tau_{dg}^m}{a_0^\\tau,b_0^\\tau},\n\\]\n\nVariational distribution $q(\\tau_d^{gm})$:\n\\begin{equation}\n\tq(\\tau_d^{gm}) = \\Gdist{\\tau_d^{gm}}{\\hat{a}_{d}^{gm} , \\hat{b}_{d}^{gm}}\n\\end{equation}\nwhere:\n\\begin{equation} \\begin{aligned}\n\t\\hat{a}_{d}^{gm} &= a_0^{\\tau} + \\frac{N_g}{2}\\\\\n\t\\hat{b}_{d}^{gm} &= b_0^{\\tau} + \\frac{1}{2} \\sum_{n=1}^{N_g}  \\la\\left(y_{nd}^{gm} - \\sum_k^{K} w_{kd}^m z_{nk}^{g}\\right)^2 \\ra\n\\end{aligned} \\end{equation}\n\n\n\\section{Evidence Lower Bound}\n\nAlthough computing the ELBO is not necessary in order to estimate the posterior distribution of the parameters, it is used to monitor the convergence of the algorithm. As shown in \\Cref{eq_elbo2}, the ELBO can be decomposed into a sum of two terms: (1) the expected log likelihood under the current estimate of the posterior distribution of the parameters and (2) the KL divergence between the prior and the variational distributions of the parameters:\\\\\n\n\\begin{equation} \\begin{aligned}\n    \\Lagr = \\E_{q(X)} \\ln p(Y|X) - \\KL\\left(q(X) \\middle|\\middle| p(X) \\right)\n\\end{aligned} \\end{equation}\n\n\n\\paragraph*{Log likelihood term}\n\nAssuming a Gaussian likelihood:\n\\begin{equation} \\begin{aligned}\n\t\\E_{q(X)} \\ln p(Y|X) = & -\\sum_{m=1}^M \\frac{ND_m}{2} \\ln(2\\pi) + \\sum_{g=1}^G \\frac{N_g}{2} \\sum_{m=1}^M \\sum_{d=1}^{D_m} \\la \\ln(\\tau_{d}^{gm}) \\ra \\\\\n\t&-\\sum_{g=1}^G \\sum_{m=1}^M \\sum_{d=1}^{D_m} \\frac{\\la \\tau_{d}^{gm} \\ra}{2} \\sum_{n=1}^{N_g} \\big( y_{nd}^{m,g} - \\sum_{k=1}^{K}\\la s_{kd}^m \\hat{w}_{kd}^m \\ra \\la z_{nk}^g \\ra \\big)^2\n\\end{aligned} \\end{equation}\n\n\n\\paragraph*{KL divergence terms}\n\nNote that $\\KL\\left(q(X) \\middle|\\middle| p(X) \\right) = \\E_q(q(X)) - \\E_q(p(X))$. \\\\\nBelow, we will write the analytical form for these two expectations.\n\n\\paragraph*{Weights}\n\n\\begin{equation} \\begin{aligned}\n    \\E_q[\\ln p(\\hat{W},S)] =& -\\sum_{m=1}^{M}\\frac{KD_m}{2}\\ln(2\\pi) + \\sum_{m=1}^{M}\\frac{D_m}{2}\\sum_{k=1}^{K} \\ln(\\alpha_k^m) - \\sum_{m=1}^{M} \\frac{\\alpha_k^m}{2} \\sum_{d=1}^{D_m} \\sum_{k=1}^{K} \\la (\\hat{w}_{kd}^m)^2 \\ra \\\\\n    & + \\la \\ln(\\theta) \\ra \\sum_{m=1}^{M} \\sum_{d=1}^{D_m} \\sum_{k=1}^{K} \\la s_{kd}^m \\ra + \\la \\ln(1-\\theta) \\ra \\sum_{m=1}^{M} \\sum_{d=1}^{D_m}\\sum_{k=1}^{K} (1- \\la s_{kd}^m \\ra)\n\\end{aligned} \\end{equation}\n\n\\begin{equation} \\begin{aligned}\n\t\\E_q[\\ln q(\\hat{W}, S)] =&-\\sum_{m=1}^{M}\\frac{KD_m}{2}\\ln(2\\pi) + \\frac{1}{2}\\sum_{m=1}^{M}\\sum_{d=1}^{D_m}\\sum_{k=1}^{K}\\ln(\\la s_{kd}^m \\ra \\sigma_{w_{kd}^m}^2 + (1-\\la s_{kd}^m \\ra)/\\alpha_k^m) \\\\\n\t&+ \\sum_{m=1}^{M} \\sum_{d=1}^{D_m} \\sum_{k=1}^{K} (1-\\la s_{kd}^m \\ra) \\ln(1 - \\la s_{kd}^m \\ra) - \\la s_{kd}^m \\ra \\ln \\la s_{kd}^m \\ra\n\\end{aligned} \\end{equation}\n\n\\paragraph*{Factors}\n\n\\begin{equation} \\begin{aligned}\n    \\E_q[\\ln p(\\hat{Z},S)] =& -\\sum_{g=1}^{G}\\frac{N_g K}{2}\\ln(2\\pi) + \\sum_{g=1}^{G}\\frac{N_g}{2}\\sum_{k=1}^{K} \\ln(\\alpha_k^g) - \\sum_{g=1}^{G} \\frac{\\alpha_k^g}{2} \\sum_{n=1}^{N_g} \\sum_{k=1}^{K} \\la (\\hat{z}_{nk}^g)^2 \\ra \\\\\n    & + \\la \\ln(\\theta) \\ra \\sum_{g=1}^{G} \\sum_{n=1}^{N_g} \\sum_{k=1}^{K} \\la s_{nk}^g \\ra + \\la \\ln(1-\\theta) \\ra \\sum_{g=1}^{G} \\sum_{n=1}^{N_g}\\sum_{k=1}^{K} (1- \\la s_{nk}^g \\ra)\n\\end{aligned} \\end{equation}\n\n\\begin{equation} \\begin{aligned}\n\t\\E_q[\\ln q(\\hat{Z}, S)] =&-\\sum_{g=1}^{G}\\frac{N_g K}{2}\\ln(2\\pi) + \\frac{1}{2}\\sum_{g=1}^{G}\\sum_{n=1}^{N_g}\\sum_{k=1}^{K}\\ln(\\la s_{nk}^g \\ra \\sigma_{z_{nk}^g}^2 + (1-\\la s_{nk}^g \\ra)/\\alpha_k^g) \\\\\n\t&+ \\sum_{g=1}^{G} \\sum_{n=1}^{N_g} \\sum_{k=1}^{K} (1-\\la s_{nk}^g \\ra) \\ln(1 - \\la s_{nk}^g \\ra) - \\la s_{nk}^g \\ra \\ln \\la s_{nk}^g \\ra\n\\end{aligned} \\end{equation}\n\n\\paragraph*{ARD prior on the weights}\n\n\\begin{equation} \\begin{aligned}\n\t\\E_q [\\ln p(\\balpha)] &= \\sum_{m=1}^{M}\\sum_{k=1}^{K}\\Big(a_0^\\alpha\\ln b_0^\\alpha +   (a_0^\\alpha - 1) \\la \\ln \\alpha_k \\ra - b_0^\\alpha \\la \\alpha_k \\ra - \\ln \\Gamma(a_0^\\alpha) \\Big) \\\\\n\t\\E_q [\\ln q(\\balpha)] &= \\sum_{m=1}^{M}\\sum_{k=1}^{K} \\Big( \\hat{a}_{k}^\\alpha \\ln \\hat{b}_{k}^\\alpha + (\\hat{a}_{k}^\\alpha - 1) \\la \\ln \\alpha_k \\ra - \\hat{b}_{k}^\\alpha \\la \\alpha_k \\ra - \\ln \\Gamma(\\hat{a}_{k}^\\alpha) \\Big)\n\\end{aligned} \\end{equation}\n\n\\paragraph*{Sparsity parameter of the weights}\n\n\\begin{equation} \\begin{aligned}\n\t  &\\E_q\\left[ \\ln p(\\btheta) \\right] = \\sum_{m=1}^M \\sum_{k=1}^K\\sum_{d=1}^{D_m}\\left( (a_0 - 1) \\times \\la \\ln(\\pi^m_{d, k}) \\ra + (b_0 -1) \\la \\ln(1 - \\pi^m_{d, k}) \\ra - \\ln (\\mathrm{B} (a_0, b_0))\\right) \\\\\n\t  &\\E_q\\left[ \\ln q(\\btheta) \\right] = \\sum_{m=1}^M \\sum_{k=1}^K\\sum_{d=1}^{D_m}\\left( (a^m_{k,d} - 1) \\times \\la \\ln(\\pi^m_{d, k}) \\ra + (b^m_{k,d} -1) \\la \\ln(1 - \\pi^m_{d, k}) \\ra - \\ln (\\mathrm{B} (a^m_{k,d}, b^m_{k,d})) \\right) \\\\\n\\end{aligned} \\end{equation}\n\n\\paragraph*{ARD prior on the Factors}\n\n\\begin{equation} \\begin{aligned}\n\t\\E_q [\\ln p(\\balpha)] &= \\sum_{g=1}^{G}\\sum_{k=1}^{K}\\Big(a_0^\\alpha\\ln b_0^\\alpha +   (a_0^\\alpha - 1) \\la \\ln \\alpha_k \\ra - b_0^\\alpha \\la \\alpha_k \\ra - \\ln \\Gamma(a_0^\\alpha) \\Big) \\\\\n\t\\E_q [\\ln q(\\balpha)] &= \\sum_{g=1}^{G}\\sum_{k=1}^{K} \\Big( \\hat{a}_{k}^\\alpha \\ln \\hat{b}_{k}^\\alpha + (\\hat{a}_{k}^\\alpha - 1) \\la \\ln \\alpha_k \\ra - \\hat{b}_{k}^\\alpha \\la \\alpha_k \\ra - \\ln \\Gamma(\\hat{a}_{k}^\\alpha) \\Big)\n\\end{aligned} \\end{equation}\n\n\\paragraph*{Sparsity parameter of the Factors}\n\\begin{equation} \\begin{aligned}\n\t  &\\E_q\\left[ \\ln p(\\btheta) \\right] = \\sum_{g=1}^G \\sum_{k=1}^K\\sum_{n=1}^{N_g}\\left( (a_0 - 1) \\times \\la \\ln(\\pi^g_{n, k}) \\ra + (b_0 -1) \\la \\ln(1 - \\pi^g_{n, k}) \\ra - \\ln (\\mathrm{B} (a_0, b_0))\\right) \\\\\n\t  &\\E_q\\left[ \\ln q(\\btheta) \\right] = \\sum_{g=1}^G \\sum_{k=1}^K\\sum_{n=1}^{N_g}\\left( (a^g_{k,n} - 1) \\times \\la \\ln(\\pi^g_{n, k}) \\ra + (b^g_{k,n} -1) \\la \\ln(1 - \\pi^g_{n, k}) \\ra - \\ln (\\mathrm{B} (a^g_{k,n}, b^g_{k,n})) \\right) \\\\\n\\end{aligned} \\end{equation}\n\n\\paragraph*{Noise}\n\n\\begin{equation} \\begin{aligned}\n\t\\E_q [\\ln p(\\btau)] &= \\sum_{m=1}^{M} D_m a_0^\\tau \\ln b_0^\\tau + \\sum_{g=1}^{G}\\sum_{m=1}^{M}\\sum_{d=1}^{Dm} (a_0^\\tau - 1) \\la \\ln \\tau_d^{gm} \\ra - \\sum_{g=1}^{G}\\sum_{m=1}^{M}\\sum_{d=1}^{Dm} b_0^\\tau \\la \\tau_d^{gm} \\ra - \\sum_{m=1}^{M} D_m \\ln \\Gamma(a_0^\\tau)\\\\\n\t\\E_q [\\ln q(\\btau)] &= \\sum_{g=1}^{G} \\sum_{m=1}^{M} \\sum_{d=1}^{D_m} \\left( \\hat{a}_{dgm}^\\tau \\ln \\hat{b}_{dgm}^\\tau + (\\hat{a}_{dgm}^\\tau - 1) \\la \\ln \\tau_d^{gm} \\ra - \\hat{b}_{dgm}^\\tau \\la \\tau_d^{gm} \\ra - \\ln \\Gamma(\\hat{a}_{dgm}^\\tau) \\right)\n\\end{aligned} \\end{equation}\n", "meta": {"hexsha": "107fe5edeee8b7210251c5a977cf6f25485793c0", "size": 15372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix/appendix1.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": "Appendix/appendix1.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": "Appendix/appendix1.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": 56.102189781, "max_line_length": 785, "alphanum_fraction": 0.6037600833, "num_tokens": 6988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430311279739, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6126838745072666}}
{"text": "\\subsection{Quivers}\\label{subsec:quivers}\n\n\\begin{definition}\\label{def:quiver}\n  A \\term{quiver} or \\term{directed multigraph} is an extension of \\hyperref[def:undirected_multigraph]{undirected multigraphs}. A quiver consists of the following:\n  \\begin{thmenum}\n    \\thmitem{def:quiver/vertices} A set \\( V \\) of \\term{vertices}.\n    \\thmitem{def:quiver/arcs} A disjoint from \\( V \\) set \\( A \\) of \\term{arcs}. It is conventional to call them arcs or even directed edges rather than simply edges.\n    \\thmitem{def:quiver/head} A \\term{head} function \\( h: A \\to V \\).\n    \\thmitem{def:quiver/tail} A \\term{tail} function \\( t: A \\to V \\).\n    \\thmitem{def:quiver/adjacency} We say that the arc \\( a \\) is a \\term{successor} of \\( b \\) and that \\( b \\) is a \\term{predecessor} of \\( a \\) if \\( t(a) = h(b) \\). We also say that \\( a \\) and \\( b \\) are \\term{consecutive}.\n\n    For vertices, we say that \\( w \\) is a successor of \\( v \\) and that \\( w \\) is consecutive to \\( w \\) if there exists an arc from \\( u \\) to \\( v \\).\n\n    \\thmitem{def:quiver/forgetful} For each quiver \\( Q = (V, A, h, t) \\), we have an \\enquote{underlying} undirected multigraph\n    \\begin{equation}\\label{eq:def:quiver/forgetful}\n      \\begin{aligned}\n        &G: A \\to V, \\\\\n        &G(a) \\coloneqq \\set{ h(a), t(a) }.\n      \\end{aligned}\n    \\end{equation}\n\n    All properties of \\( G \\) are inherited by \\( Q \\), although some of them do not really fit or need adaptation.\n\n    We denote this graph by \\( U(Q) \\coloneqq G \\) and will regard it as a forgetful functor --- see \\fullref{def:multigraph_orientation}.\n\n    \\thmitem{def:quiver/opposing} One adaptation is that the arcs \\( a \\) and \\( b \\) are called \\term{opposing} they are successors of each other and the term \\enquote{parallel} is reserved for arcs which are parallel in the sense of \\fullref{def:hypergraph/parallel_hyperedges} but not opposing.\n\n    \\thmitem{def:quiver/simple} If there are no parallel and opposing arcs or loops, we call the quiver \\term{simple}. The term \\term{simple directed graph} is more commonly used.\n\n    For a simple directed graph, we often write \\( G = (V, E) \\), where \\( E \\) is an \\hyperref[def:binary_relation/irreflexive]{irreflexive} binary relation.\n\n    We say that the simple directed graph is \\term{symmetric} if this relation is symmetric. For many purposes, symmetric directed graphs can be regarded as undirected --- see \\fullref{rem:symmetric_directed_graphs}.\n\n    \\thmitem{def:quiver/submodel} The \\term{subquivers} of \\( Q \\) are the precisely \\hyperref[def:undirected_multigraph/submodel]{subgraphs} of \\( G \\). In particular, the \\term{full subquivers} are the \\hyperref[def:undirected_multigraph/submodel]{full subgraphs}, that are maximal among the subgraphs with the same vertices.\n  \\end{thmenum}\n\n  \\begin{figure}\n    \\begin{equation}\\label{eq:fig:def:quiver}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/def__quiver.pdf}\n      \\end{aligned}\n    \\end{equation}\n    \\caption{A quiver with a pair of parallel arcs, a pair of opposing arcs and a loop. Removing the dashed arcs makes it a simple directed graph.}\\label{fig:def:quiver}\n  \\end{figure}\n\\end{definition}\n\n\\begin{example}\\label{ex:infinite_integer_graphs}\n  A very simple example of an infinite quiver is the \\hyperref[def:relation_closures/transitive]{transitive reduction} of the positive integers, i.e. the simple directed graph\n  \\begin{equation}\\label{eq:ex:infinite_integer_graphs/positive}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/ex__infinite_integer_graphs.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Since the graph is simple, we have\n  \\begin{equation*}\n    \\deg(n) = \\begin{cases}\n      1 = 0 + 1, &n = 0, \\\\\n      2 = 1 + 1, &n > 0 \\\\\n    \\end{cases}\n  \\end{equation*}\n  and thus \\( \\deg(G) = 2 \\).\n\n  The \\hyperref[def:categorical_diagram]{categorical diagrams} corresponding to this quiver is used to define direct limits in \\fullref{def:direct_and_inverse_limits/direct}.\n\n  Another related graph is based on the negative integers:\n  \\begin{equation}\\label{eq:ex:infinite_integer_graphs/negative}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/ex__infinite_integer_graphs.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  The \\hyperref[def:categorical_diagram]{categorical diagrams} corresponding to this quiver is used to define inverse limits in \\fullref{def:direct_and_inverse_limits/inverse}.\n\n  Finally, the union of the two with zero added gives us the following quiver:\n  \\begin{equation}\\label{eq:ex:infinite_integer_graphs/two_sided}\n    \\begin{aligned}\n      \\includegraphics[page=3]{output/ex__infinite_integer_graphs.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  All three graphs are infinite but \\hyperref[def:hypergraph/degree]{locally finite}.\n\\end{example}\n\n\\begin{definition}\\label{def:category_of_small_quivers}\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]{quivers} by \\( \\ucat{Quiv} \\) or, if the universe is clear from the context, simply by \\( \\cat{Quiv} \\). See \\fullref{def:category_size} for a further discussion of universes and categories.\n\n  A more \\enquote{categorical} definition, in which this category arises naturally, is given in \\fullref{ex:quivers_as_functors}.\n\n  For simple directed graphs, we denote the category using \\( \\cat{SimpQuiv} \\).\n\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(\\cat{Quiv}) \\) is the set of all \\( \\mscrU \\)-small quivers, i.e. the quivers \\( Q = (V, A, h, t) \\) such that \\( V \\) and \\( A \\) are both members of \\( \\mscrU \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{Quiv}(Q, R) \\) from \\( Q \\) to \\( R \\) is the set quiver homomorphisms. Given two quivers \\( Q = (V_Q, A_Q, h_Q, t_Q) \\) and \\( R = (V_R, A_R, h_R, t_R) \\), a \\term{quiver homomorphism} is a pair of functions\n    \\begin{equation}\\label{eq:def:category_of_small_quivers/homomorphism}\n      \\begin{cases}\n        f_V: V_Q \\to V_R \\\\\n        f_A: A_Q \\to A_R\n      \\end{cases}\n    \\end{equation}\n    such that\n    \\begin{align}\n      h_R \\bincirc f_A &= f_V \\bincirc h_Q \\label{eq:def:category_of_small_quivers/homomorphism/head} \\\\\n      t_R \\bincirc f_A &= f_V \\bincirc t_Q \\label{eq:def:category_of_small_quivers/homomorphism/tail}\n    \\end{align}\n\n    See \\fullref{ex:quivers_as_functors} for a categorical justification of this definition, including reducing the above conditions to the diagram \\eqref{eq:ex:quivers_as_functors/index/diagram}.\n\n    Clearly every quiver homomorphism is a \\hyperref[eq:def:category_of_small_hypergraphs/homomorphism]{hypergraph homomorphism}.\n\n    Note that \\enquote{quiver 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 quiver homomorphisms. Furthermore, it should be clarified whether we mean \\enquote{injective on vertices} or \\enquote{injective on arcs}, which is an important distinction in category theory --- see \\fullref{def:functor_invertibility}.\n\n    \\item The \\hyperref[def:category/composition]{composition of quiver morphisms} is pointwise composition --- the same as composition of hypergraph homomorphisms.\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the quiver \\( Q = (V, A, h, t) \\) is the pair of \\hyperref[def:multi_valued_function/identity]{identity functions} \\( (\\id_V, \\id_A) \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{definition}\\label{def:multigraph_orientation}\\mcite{nLab:oriented_graph}\n  Given an \\hyperref[def:undirected_multigraph]{undirected (multi)graph} \\( G = (V, E, \\mscrE) \\), constructing a quiver requires a choice of head and tail for every edge. We can view undirected graphs as equivalence classes of quivers. A head function is merely a \\hyperref[def:choice_function]{choice function} on the set \\( \\set{ \\mscrE(e) \\given e \\in E } \\), and a choice function can be provided by the \\hyperref[def:zfc/choice]{axiom of choice} even for infinite graphs.\n\n  For a given choice function \\( c \\), we denote by \\( O_c(G) = (V, E, h, t) \\) the quiver obtained by identifying the head \\( h(e) \\) with \\( c(\\mscrE(e)) \\) and the tail \\( t(e) \\) with the other endpoint of \\( e \\), if one exists, and with \\( h(e) \\) for loops. We call \\( O_c(G) \\) the \\term{orientation} induced by the choice function \\( c \\).\n\n  Note that \\( O_c \\) is not left adjoint to \\( U \\) --- see \\fullref{ex:def:category_adjunction/multgph_quiv}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:graphs_linear_algebra_and_topology}\n  As we shall see, the \\hyperref[def:hypergraph/adjacency]{adjacency} and \\hyperref[def:hypergraph/incidence]{incidence} of a quiver can be studied using linear algebra via \\hyperref[def:graph_adjacency_matrix]{adjacency} and \\hyperref[def:hypergraph_incidence_matrix]{incidence matrices}, while the \\hyperref[def:quiver_connectedness]{connectedness} can be studied using \\hyperref[def:quiver_connectedness]{topology} via \\hyperref[def:quiver_geometric_realization/embedding]{graph embeddings}.\n\\end{remark}\n\n\\begin{definition}\\label{def:quiver_incidence_matrix}\\mcite[ch. 1, sec. 2.1]{GondranMinoux1984Graphs}\n  Let \\( Q = (A, E, h, t) \\) be a finite quiver. Its \\term{incidence matrix}\n  \\begin{equation*}\n    M = \\seq{ M_{va} }_{v \\in V, a \\in A}\n  \\end{equation*}\n  has elements\n  \\begin{equation*}\n    M_{va} \\coloneqq \\begin{cases}\n      1,  &v = h(e) \\\\\n      -1, &v = h(e) \\\\\n      0,  &\\T{otherwise.}\n    \\end{cases}\n  \\end{equation*}\n\n  Compare this definition to \\fullref{def:hypergraph_incidence_matrix}.\n\\end{definition}\n\n\\begin{example}\\label{ex:quiver_matrices}\n  The \\hyperref[def:quiver_incidence_matrix]{incidence matrix} of the simple directed graph \\eqref{eq:fig:def:quiver} is\n  \\begin{equation}\\label{ex:quiver_matrices/incidence}\n    \\begin{blockarray}{cccccccc}\n        & e_1       & e_2       & e_3       & e_4       & e_5       & e_6       & e_7       \\\\\n      \\begin{block}{c(ccccccc)}\n      a & 1         & 1         &           &           &           &           &           \\\\\n      b & \\fbox{-1} &           & 1         &           &           &           &           \\\\\n      c &           & \\fbox{-1} &           & 1         & 1         &           &           \\\\\n      d &           &           & \\fbox{-1} & \\fbox{-1} &           & 1         &           \\\\\n      e &           &           &           &           & \\fbox{-1} &           & 1         \\\\\n      f &           &           &           &           &           & \\fbox{-1} & \\fbox{-1} \\\\\n      \\end{block}\n    \\end{blockarray}\n  \\end{equation}\n\n  It can be read column-by-column. Every column contains exactly two nonzero elements whose rows correspond to the head (positive) and tail (negative).\n\n  To obtain the incidence matrix for the underlying undirected graph \\eqref{eq:fig:def:undirected_multigraph}, we need to simply flip the sign of the boxed elements above.\n\n  The \\hyperref[def:graph_adjacency_matrix]{adjacency matrix} is,\n  \\begin{equation}\\label{ex:quiver_matrices/adjacency}\n    \\begin{blockarray}{cccccccc}\n        & a        & b        & c        & d        & e        & f \\\\\n    \\begin{block}{c(ccccccc)}\n      a &          & 1        & 1        &          &          &   \\\\\n      b & \\fbox{1} &          &          & 1        &          &   \\\\\n      c & \\fbox{1} &          &          & 1        & 1        &   \\\\\n      d &          & \\fbox{1} & \\fbox{1} &          &          & 1 \\\\\n      e &          &          & \\fbox{1} &          &          & 1 \\\\\n      f &          &          &          & \\fbox{1} & \\fbox{1} &   \\\\\n    \\end{block}\n    \\end{blockarray}\n  \\end{equation}\n  where the boxed elements are nonzero only in the adjacency matrix for \\eqref{eq:fig:def:undirected_multigraph} and not \\eqref{eq:fig:def:quiver}.\n\n  The matrix can be read either column-by-column or row-by-row.\n  \\begin{itemize}\n    \\item The \\( v \\)-th column lists the vertices \\( u \\) such that there is an arc from \\( u \\) to \\( v \\).\n    \\item The \\( u \\)-th row lists the vertices \\( v \\) such that there is an arc from \\( v \\) to \\( u \\).\n  \\end{itemize}\n\\end{example}\n\n\\begin{proposition}\\label{thm:graph_undirected_iff_adjacency_matrix_is_symmetric}\n  Every square finite matrix over the two-element field \\hyperref[thm:ring_of_integers_modulo_zero_divisors]{\\( \\BbbF_2 \\)} corresponds to a \\hyperref[def:quiver]{quiver} without parallel arcs.\n\n  If the matrix is symmetric, we obtain its underlying \\hyperref[def:undirected_multigraph]{undirected graph}.\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{remark}\\label{rem:symmetric_directed_graphs}\n  It is sometimes convenient to conflate symmetric \\hyperref[def:quiver/simple]{simple directed graphs} with \\hyperref[def:undirected_multigraph]{simple undirected graphs}.\n\n  This is partially justified by \\fullref{thm:graph_undirected_iff_adjacency_matrix_is_symmetric}.\n\\end{remark}\n\n\\begin{definition}\\label{def:quiver_path}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver}.\n\n  \\begin{thmenum}\n    \\thmitem{def:quiver_path/directed} A \\term{directed path} or simply \\term{path} in \\( Q \\) a finite or infinite sequence of \\hyperref[def:quiver/adjacency]{consecutive arcs} with a specified head vertex. Formally, it is a sequence \\( p = (v, e_1, e_2, \\ldots) \\), where \\( h(e_k) = t(e_{k-1}) \\) for every index \\( k \\).\n\n    This is a simplification of \\fullref{def:undirected_multigraph_path} since every arc has a head and tail. It is also too restrictive for some purposes.\n\n    The definitions of \\hyperref[def:undirected_multigraph_path/endpoints]{path endpoints}, \\hyperref[def:undirected_multigraph_path/empty]{empty path}, \\hyperref[def:undirected_multigraph_path/length]{length}, \\hyperref[def:undirected_multigraph_path/domain]{domain}, \\hyperref[def:undirected_multigraph_path/concatenation]{concatenation} and \\hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vector} of a directed path are inherited from \\fullref{def:undirected_multigraph_path}.\n\n    \\thmitem{def:quiver_path/cycle} A \\term{directed cycle} is a directed path whose endpoints coincide. The term \\term{circuit} is also used, for example in \\cite[ch. 1, sec. 3.2]{GondranMinoux1984Graphs}. A quiver without cycles is called \\term{acyclic} and a simple acyclic directed graph is commonly abbreviated as \\term{DAG}.\n\n    \\thmitem{def:quiver_path/simple} Similarly to \\fullref{def:undirected_multigraph_path/simple}, we say that a directed path is \\term{simple} if it contains to directed cycles.\n\n    \\thmitem{def:quiver_path/undirected} If \\( p = (v, e_1, e_2, \\ldots) \\) is a path in the \\hyperref[def:undirected_multigraph]{undirected multigraph} \\( U(Q) \\),\n    \\begin{equation*}\n      D(p) \\coloneqq (v, e_1, e_2, \\ldots)\n    \\end{equation*}\n    is a sequence of adjacent arcs in \\( Q \\) (with a specified head vertex).\n\n    The head and tail of \\( D(p) \\) are defined as the head and tail of \\( p \\). This definition obviously differs from \\fullref{def:quiver_path}.\n\n    We say that the arc \\( e_k \\) of \\( D(p) \\) is \\term{positively oriented} if the head \\( h_k \\) of the edge \\( e_k \\) in \\( Q \\) equals the head \\( h(e_k) \\) of the arc \\( e_k \\) in \\( D(p) \\). If \\( e_k \\) is not positively oriented, we say that it is \\term{negatively oriented}.\n\n    We conflate \\( p \\) and \\( D(p) \\) where this does not cause confusion.\n\n    Undirected paths are also called \\term{chains} in \\cite[ch. 1, sec. 3.2]{GondranMinoux1984Graphs}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:quiver_path}\n  An example of an infinite \\hyperref[def:quiver_path/directed]{directed path} is the reduced positive integer graph \\eqref{eq:ex:infinite_integer_graphs/positive} regarded as a path of the reduced integer graph \\eqref{eq:ex:infinite_integer_graphs/two_sided}. It is also simple since the degree of \\eqref{eq:ex:infinite_integer_graphs/positive} is \\( 2 \\).\n\n  Now consider again the quiver \\eqref{eq:fig:def:quiver}. The solid lines in \\eqref{fig:ex:def:quiver_path} describe a path.\n  \\begin{equation}\\label{fig:ex:def:quiver_path}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/ex__def__quiver_path.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  \\begin{itemize}\n    \\item This path corresponds to the sequence\n    \\begin{equation*}\n      p = \\parens{ a, \\underbrace{a \\to c}_{e_2}, \\underbrace{c \\to d}_{e_4}, \\underbrace{d \\to f}_{e_6} }.\n    \\end{equation*}\n\n    \\item Its \\hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vector} is\n    \\begin{equation*}\n      \\vect{p}\n      =\n      \\begin{blockarray}{ccccccr}\n        e_1 & e_2 & e_3 & e_4 & e_5 & e_6 & e_7 \\\\\n      \\begin{block}{(ccccccr)}\n        0   & 1   & 0   & 1   & 0   & 1   & 0   \\\\\n      \\end{block}\n      \\end{blockarray}\n      {}^T.\n    \\end{equation*}\n\n    Furthermore, \\( p \\) can be identified from the characteristic vector.\n\n    \\item The \\hyperref[def:quiver_path]{endpoints} are \\( h(p) = h(e_1) = a \\) and \\( t(p) = t(e_7) = f \\).\n\n    \\item It is a \\hyperref[def:undirected_multigraph_path/simple]{simple path} because \\( \\deg(a) = \\deg(f) = 1 \\) and \\( \\deg(c) = \\deg(d) = 2 \\) in the induced subgraph.\n\n    \\item The \\hyperref[def:undirected_multigraph_path/converse]{converse undirected path}\n    \\begin{equation*}\n      p^{-1} = (f, d \\to f, c \\to d, a \\to c),\n    \\end{equation*}\n    is not a directed path because every arc is negatively oriented.\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:quiver_condensation}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver}. We say that the vertex \\( w \\) is \\term{reachable} from \\( v \\) if there exists a \\hyperref[def:quiver_path/directed]{directed path} from \\( v \\) to \\( w \\).\n\n  Define the equivalence relation\n  \\begin{equation*}\n    v \\sim w \\iff v \\T{is reachable from} w \\T{and} w \\T{is reachable from} u.\n  \\end{equation*}\n\n  Now define the binary relation \\( \\widetilde{A} \\) on the \\hyperref[def:equivalence_relation/quotient]{quotient set} \\( \\widetilde{V} \\coloneqq V / {\\sim} \\) as\n  \\begin{equation*}\n    ([u], [v]) \\in \\widetilde{A} \\iff v \\T{is reachable from} w \\T{but not vice versa}.\n  \\end{equation*}\n\n  It is well-defined because if \\( ([v_1], [w_1]) \\in \\widetilde{A} \\), \\( v_2 \\in [v_1] \\) and \\( w_2 \\in [w_1] \\), then by the transitivity of reachability we have that \\( w_2 \\) is reachable from \\( v_2 \\) and thus \\( ([v_2], [w_2]) \\in \\widetilde{A} \\).\n\n  As discussed in \\fullref{def:quiver/simple}, irreflexive relations over sets can be regarded as simple directed graphs. Therefore, the pair \\( \\widetilde{G} \\coloneqq (\\widetilde{V}, \\widetilde{A}) \\) is a directed graph. It is called the \\term{condensation} of the quiver \\( Q \\).\n\n  Compare this definition to \\fullref{def:undirected_multigraph_connectedness/condensation}.\n\\end{definition}\n\n\\begin{example}\\label{ex:def:quiver_condensation}\n  The \\hyperref[def:quiver_condensation]{condensation} of the quiver in \\eqref{eq:fig:def:quiver} is (isomorphic to) the graph itself. If we add the arc \\( f \\to a \\) to \\eqref{eq:fig:def:quiver}, the condensation would be an edgeless quiver with a single vertex.\n\n  We can add new arcs \\( e_8 \\) and \\( e_9 \\) to the quiver in \\eqref{eq:fig:def:quiver} to make the example more interesting:\n  \\begin{equation}\\label{eq:ex:def:quiver_condensation/uncondensed}\n    \\begin{aligned}\n      \\includegraphics[page=1]{output/ex__def__graph_condensation.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  Its condensation is\n  \\begin{equation}\\label{eq:ex:def:quiver_condensation/condensed}\n    \\begin{aligned}\n      \\includegraphics[page=2]{output/ex__def__graph_condensation.pdf}\n    \\end{aligned}\n  \\end{equation}\n\n  These are the \\hyperref[def:quiver_connectedness/strong]{strongly connected components} of \\eqref{eq:ex:def:quiver_condensation/uncondensed}.\n\\end{example}\n\n\\begin{proposition}\\label{thm:graph_condensation_is_acyclic_dag}\n  The \\hyperref[def:quiver_condensation]{condensation} of a quiver is a \\hyperref[def:undirected_multigraph_path]{directed acyclic graph}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\widetilde{G} = (\\widetilde{V}, \\widetilde{E}) \\) be the condensation of the quiver \\( Q = (V, A, h, t) \\). We have already discussed in \\fullref{def:quiver_condensation} that it is a directed graph. It remains to show that it is acyclic.\n\n  Aiming at a contradiction, suppose that there exist cosets \\( [u] \\) and \\( [v] \\) and a path\n  \\begin{equation*}\n    \\parens[\\Big]{ [u] \\to [w_1], \\cdots, [w_n] \\to [v] }\n  \\end{equation*}\n  in \\( \\widetilde{G} \\) that connects them. We can easily prove by induction that \\( v \\) is reachable from \\( u \\), thus contradicting the definition of \\( \\widetilde{A} \\).\n\n  Therefore, \\( \\widetilde{G} \\) is acyclic.\n\\end{proof}\n\n\\begin{definition}\\label{def:quiver_connectedness}\n  Let \\( Q = (V, E, h, t) \\) be a quiver and let \\( \\widetilde{G} = (\\widetilde{V}, \\widetilde{E}) \\) be its condensed directed graph.\n\n  \\begin{thmenum}\n    \\thmitem{def:quiver_connectedness/strong}\\mcite[ch. 1, sec. 3.5]{GondranMinoux1984Graphs} For every coset \\( [v] \\) in \\( \\widetilde{V} \\), the \\hyperref[def:hypergraph/submodel]{subquiver} of \\( Q \\) induced by the vertices \\( [v] \\) is called a \\term{strongly connected component} of \\( Q \\).\n\n    The \\term{strong connectivity number} of \\( Q \\) is the cardinality \\( \\card(\\widetilde{V}) \\).\n\n    If \\( Q \\) has only one strongly connected component, we say that it itself is \\term{strongly connected}.\n\n    \\thmitem{def:quiver_connectedness/weak}\\mcite[ch. 1, sec. 3.3]{GondranMinoux1984Graphs} Similarly, the subquiver \\( Q' \\) of \\( Q \\) is called a \\term{weakly connected component} if is a connected component, in the sense of \\fullref{def:undirected_multigraph_connectedness/components}, of the underlying undirected multigraph \\( U(Q) \\).\n\n    The \\term{weak connectivity number} of \\( Q \\) is the connectivity number of \\( U(Q) \\).\n\n    If \\( Q \\) has only one weakly connected component, we say that it itself is \\term{weakly connected}.\n  \\end{thmenum}\n\n  This definition generalizes symmetric and transitive closures of binary relations not commuting --- see \\fullref{ex:thm:def:relation_closures/symmetric_and_transitive}.\n\n  Compare this definition to \\fullref{def:undirected_multigraph_connectedness}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:quiver_connectedness_via_chains}\n  Let \\( Q \\) be a \\hyperref[def:quiver]{quiver}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:quiver_connectedness_via_chains/strong} \\( Q \\) is \\hyperref[def:quiver_connectedness/strong]{strongly connected} if and only if there exists a \\hyperref[def:quiver_path/directed]{directed path} connecting every pair of vertices.\n\n    \\thmitem{thm:quiver_connectedness_via_chains/weak} \\( Q \\) is \\hyperref[def:quiver_connectedness/weak]{weakly connected} if and only if there exists an \\hyperref[def:quiver_path/undirected]{undirected path} connecting every pair of vertices.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  Trivial.\n\\end{proof}\n\n\\begin{remark}\\label{rem:well_founded_graphs}\n  We can regard any set \\( A \\) in the sense of \\hyperref[def:zfc]{\\logic{ZFC}} as the simple directed graph \\( (A, \\in) \\).\n\n  The \\hyperref[def:zfc/foundation]{axiom of foundation} (via \\fullref{thm:set_membership_is_well_founded}) implies that the relation \\( \\in \\) is well-founded.\n\n  In the terminology if graph theory, this well-foundedness means that, for every vertex \\( v \\), there exists no infinite \\hyperref[def:quiver_path]{path} that ends with \\( v \\).\n\n  This implies that the graph is \\hyperref[def:undirected_multigraph_path]{acyclic}. For finite graphs the converse holds, but an infinite graph this is not so. For example, the chain \\eqref{eq:ex:infinite_integer_graphs/positive} is acyclic but not well-founded.\n\n  Well-founded graphs are important for \\fullref{thm:well_founded_induction}.\n\\end{remark}\n\n\\begin{definition}\\label{def:quiver_free_category}\n  Let \\( Q = (V, A, h, t) \\) be a \\hyperref[def:quiver]{quiver}. We define the \\term{free category} \\( F(Q) \\) generated by \\( Q \\) as follows:\n  \\begin{itemize}\n    \\item The \\hyperref[def:category/objects]{set of objects} \\( \\obj(F(Q)) \\) is the set of vertices \\( V \\).\n\n    \\item The \\hyperref[def:category/morphisms]{set of morphisms} \\( \\cat{F(Q)}(v, w) \\) is the set of all paths from \\( v \\) to \\( w \\).\n\n    \\item The \\hyperref[def:category/composition]{composition of the morphisms} \\( p \\) and \\( q \\) with \\( h(q) = t(p) \\) is the \\hyperref[def:undirected_multigraph_path/concatenation]{concatenation}\n    \\begin{equation*}\n      q \\bincirc p = p \\cdot q.\n    \\end{equation*}\n\n    \\item The \\hyperref[def:category/identity]{identity morphism} on the vertex \\( v \\) is the \\hyperref[def:undirected_multigraph_path/empty]{empty path} at \\( v \\). This is the primary motivation for having a distinct empty path at every vertex.\n  \\end{itemize}\n\n  Since \\( F(Q) \\) is already defined for every quiver \\( Q \\), if we also define how it acts on \\hyperref[eq:def:category_of_small_quivers/homomorphism]{quiver homomorphisms}, this will make \\( F \\) a \\hyperref[def:functor]{functor} from the category \\hyperref[def:category_of_small_quivers]{\\( \\ucat{Quiv} \\)} of \\( \\mscrU \\)-small quivers to the category \\hyperref[def:category_of_small_quivers]{\\( \\ucat{Cat} \\)} of \\( \\mscrU \\)-small categories, for every \\hyperref[def:grothendieck_universe]{Grothendieck universe} \\( \\mscrU \\) containing \\( Q \\).\n\n  For every \\( \\mscrU \\)-small category \\( \\cat{C} \\) and every quiver homomorphism \\( (g_V, g_A): Q \\to U(\\cat{C}) \\), we define the following functor:\n  \\begin{equation}\\label{eq:def:quiver_free_category/functor_from_homomorphism}\n    \\begin{aligned}\n      &G: F(Q) \\to \\cat{C}, \\\\\n      &G(v) \\coloneqq g_V(v) \\\\\n      &G(v, a_1, \\ldots, a_n) \\coloneqq \\begin{cases}\n        \\id_v,                                        &n = 0, \\\\\n        g_A(a_n) \\bincirc G(v, a_1, \\ldots, a_{n-1}), &n > 0,\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation}\n\n  The functor \\( G \\) \\enquote{evaluates} paths in \\( Q \\) inside \\( \\cat{C} \\). Put \\( F(f_V, f_A) \\coloneqq G \\). Parameterized on \\( (f_V, f_A) \\), this defines \\( F \\) is a functor from \\( \\ucat{Quiv} \\) to \\( \\ucat{Cat} \\).\n\n  We will see in \\fullref{ex:def:category_adjunction/quiv_cat} that \\( F \\) is actually left adjoint to the forgetful functor \\( U \\). The new identity loops are an important part of this adjunction.\n\\end{definition}\n", "meta": {"hexsha": "14233c3fa779d47845d22b8d067bb82edcc9e5d1", "size": 26701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/quivers.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/quivers.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/quivers.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.03117506, "max_line_length": 553, "alphanum_fraction": 0.6837571627, "num_tokens": 8240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6125605519931029}}
{"text": "\\chapter{Rosetta Stone}\nBayesian statistics has a lot of terminology floating around, and sometimes\ndifferent communities use different terms for the same concept. This appendix\nlists various common terms that are basically synonymous (they mean the same thing).\nI may even throw in the different terms from time to time, intentionally or\nunintentionally!\n\n\\subsection*{Event, Hypothesis, Proposition, Statement}\nThese are all basically the same thing.\nA proposition is something that can be either true or false, such as ``my age is\ngreater than 35'' or ``the number of Aardvarks in my room is either zero or\none''. These are the things that go in our\nprobability statements: If we write $P(A|B)$, $A$ and $B$ are both propositions,\nthat is, statements that may be true or false. Event is the preferred term in\nclassical statistics.\n\n\n\\subsection*{Sampling Distribution, Probability Model for the Data,\nGenerative Model, Likelihood Function, Likelihood}\nThis is the thing that we\nwrite as $p(x|\\theta)$. Sometimes it is called the sampling distribution or\na generative model because\nyou can sometimes think of the data as having been ``drawn from''\n$p(x|\\theta)$ but using the true value of $\\theta$, which you don't actually\nknow. There is a subtlety here, and that is that the word likelihood can be\nused to mean either $p(x|\\theta)$ before $x$ is known (in which case it is the\nthing you would use to predict possible data) or after $x$ is known. In the latter\ncase $p(x|\\theta)$ is only a function of $\\theta$ because $x$ is fixed at the\nobserved value. The term likelihood function is often used at this point.\n\n\\subsection*{Probability Distribution}\nThe term probability distribution is used to refer to either a probability density\nfunction (in the continuous case) or a probability mass function (in the discrete\ncase). The latter gives the probability of each particular value, whereas the\nformer only gives a probability if you integrate it within some region.\n\n\\subsection*{Marginal Likelihood, Evidence, Prior Predictive Probability, Normalising\nConstant}\nThis is the $p(x)$ or $P(x)$ term in the denominator of Bayes' rule,\nand it is also the total of the {\\tt prior} $\\times$ {\\tt likelihood} column\nof a Bayes' Box. This is the probability of getting the data that you actually got,\nbefore you observed it: hence the terminology ``prior predictive probability''.\nIt is also the thing you use to normalise the posterior distribution (make it sum\nor integrate to 1), hence the term normalising constant. Marginal likelihood makes\nsense because it is a probability of data (like the regular likelihood) but\n``marginalised'' (i.e. not caring about) the value of the parameter(s). It is\nalso called ``evidence'' because it can be used to compare different models, or\nto ``patch together'' two Bayes' Boxes after the fact (see the hypothesis testing\nchapter).\n\n", "meta": {"hexsha": "67d6f6708ea500d9157e57cd4a1acc749cacf849", "size": 2871, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rosetta_stone.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": "rosetta_stone.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": "rosetta_stone.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": 56.2941176471, "max_line_length": 85, "alphanum_fraction": 0.7784743992, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6125605519931027}}
{"text": "% Document type\n\\documentclass[]{amsbook}\n%----------------------------------------------------------\n% Packages\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage{mathtools}\n\\usepackage[pdftex, bookmarks, colorlinks=true]{hyperref}\n\\usepackage{tikz-cd}\n\\usepackage{bbm}\n%----------------------------------------------------------\n% User-defined environments\n\\theoremstyle{plain}\n\\newtheorem{acknowledgement}{Acknowledgement}\n\\newtheorem{algorithm}{Algorithm}[section]\n\\newtheorem{axiom}{Axiom}[section]\n\\newtheorem{case}{Case}[section]\n\\newtheorem{claim}{Claim}[section]\n\\newtheorem{conclusion}{Conclusion}[section]\n\\newtheorem{condition}{Condition}[section]\n\\newtheorem{conjecture}{Conjecture}[section]\n\\newtheorem{corollary}{Corollary}[section]\n\\newtheorem{criterion}{Criterion}\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{example}{Example}[section]\n\\newtheorem{exercise}{Exercise}[section]\n\\newtheorem{lemma}{Lemma}[section]\n\\newtheorem{notation}{Notation}[section]\n\\newtheorem{problem}{Problem}[section]\n\\newtheorem{proposition}{Proposition}\n\\newtheorem{remark}{Remark}[section]\n\\newtheorem{solution}{Solution}[section]\n\\newtheorem{summary}{Summary}[section]\n\\newtheorem{theorem}{Theorem}[section]\n\\numberwithin{equation}{section}\n\n\\theoremstyle{definition}\n\\newtheorem{xca}{Exercise}[section]\n%-----------------------------------------------------------\n% User-defined commands\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\C}{\\mathbb{C}}\n\n\\newcommand{\\dps}{\\displaystyle}\n\\newcommand{\\mb}[1]{\\mathbf{#1}}\n\\newcommand{\\mbb}[1]{\\mathbb{#1}}\n\\newcommand{\\mf}[1]{\\mathfrak{#1}}\n\\newcommand{\\mc}[1]{\\mathcal{#1}}\n\\newcommand{\\opn}[1]{\\operatorname{#1}}\n\\newcommand{\\tb}[1]{\\textbf{#1}}\n\n\\newcommand{\\catname}[1]{\\mathbf{#1}}\n\\newcommand{\\0}{\\mathbf{0}}\n\\newcommand{\\1}{\\mathbf{1}}\n\n\\newcommand{\\la}{\\langle}\n\\newcommand{\\ra}{\\rangle}\n\n\\newcommand{\\q}{\\quad}\n\\newcommand{\\qq}{\\quad \\quad}\n\\newcommand{\\qqq}{\\quad \\quad \\quad}\n\n\\newcommand{\\oldemptyset}{\\emptyset}\n\\renewcommand{\\emptyset}{\\varnothing}\n%-----------------------------------------------------------\n% Math operators\n\\DeclareMathOperator{\\End}{End}\n\\DeclareMathOperator{\\Hom}{Hom}\n\\DeclareMathOperator{\\lcm}{lcm}\n%-----------------------------------------------------------\n\\begin{document}\n\\frontmatter\n\\title[`Algebra: Chapter 0']{Solutions to Exercises from `Algebra: Chapter 0'}\n\n\\begin{abstract}\nSolutions to exercises from the book `Algebra: Chapter 0' by Paolo Aluffi.\n\\end{abstract}\n\n\\maketitle\n\\tableofcontents\n\n\\chapter*{Preface}\n\n\\markboth{PREFACE}{PREFACE} This document contains my attempt at writing\n(hopefully correct!) solutions to exercises from Aluffi's book, while engaging\nin some self-study of modern abstract algebra with the ultimate aim of teaching\nmyself some modern algebraic geometry.\n\\mainmatter\n\n\\include{chapters/set-theory-and-categories}\n\\include{chapters/groups-first-encounter}\n\n\\end{document}\n", "meta": {"hexsha": "ea8692fb0f3c052be3983fa91ccde7c724f3655d", "size": 3029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "vishallama/algebra-chapter0", "max_stars_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-02-05T20:56:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T09:21:00.000Z", "max_issues_repo_path": "main.tex", "max_issues_repo_name": "vishallama/algebra-chapter0", "max_issues_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_issues_repo_licenses": ["MIT"], "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": "vishallama/algebra-chapter0", "max_forks_repo_head_hexsha": "cef5cc84416953797e93b8da3ccf13d436b192be", "max_forks_repo_licenses": ["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.595959596, "max_line_length": 79, "alphanum_fraction": 0.6876857049, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6125351334718951}}
{"text": "\\lab{Algorithms}{ARMA Models}{ARMA Models}\n\\label{lab:arma}\n\\objective{Fit and forecast ARMA models.}\n\nAn $\\text{ARMA}(p,q)$ model is a covariance-stationary discrete stochastic\nprocess $\\{z_t\\}$ that satisfies\n\\begin{align}\n    \\label{eq:arma:def}\n    z_t - \\mu = \\left(\\sum_{i=1}^p \\phi_{i}(z_{t - i} - \\mu)\\right) + a_t +\n    \\left(\\sum_{j=1}^{q} \\theta_{j}a_{t-j} \\right)\n\\end{align}\nwhere $\\mu = E[z_t]$ and $a_t$ are identically Gaussian distributed with\nvariance $\\sigma_a^2$. We note that the assumption that $\\{z_t\\}$ is\ncovariance-stationary is eqivalent to the condition that the roots of the\npolynomial in $B$ \n\\begin{align}\n    \\label{eq:arma:characteristic}\n    \\phi(B) = 1 - \\sum_{i=1}^p\\phi_iB^i \n\\end{align} \nlie without the unit circle.\n\nThe first sum on the right hand side of \\ref{eq:arma:def} is interpreted as an\n``autoregression'' since it is a linear combination of previously observed\nvalues of $z_t$. The second sum is interpreted as a ``moving average'' of the\ncurrent and previous error terms; though formally similar to an average, note\nthat the $\\theta_j$ need not be positive nor sum to one. We say that an\n$\\text{ARMA}(p,q)$ model is an ``autoregressive moving-average model of order\np, q''.\n\n\\section*{Likelihood via Kalman Filter}\n\nIn a general $\\text{ARMA}(p,q)$ model, the likelihood is a function of the\nunobserved error terms $a_t$ and is not trivial to compute. Simple\napproximations can be made, but these may be inaccurate under certain\ncircumstances. Explicit derivations of the likelihood are possible, but\ntedious. However, when the $\\text{ARMA}$ model is placed in state-space, the\nKalman filter affords a straightforward, recursive way to compute the\nlikelihood.\n\nWe demonstrate a state-space representation of an $\\text{ARMA}(p,q)$ model. If\n$r = \\max(p, q+1)$, we write\n\\begin{align}\n    F &= \\begin{bmatrix}\n        \\phi_1 & \\phi_2 & \\cdots & \\phi_{r-1} & \\phi_r\\\\\n        1 & 0 & \\cdots & 0 & 0\\\\\n        0 & 1 & \\cdots & 0 & 0\\\\\n        \\vdots & \\vdots & \\cdots & \\vdots & \\vdots\\\\\n        0 & 0 & \\cdots & 1 & 0\n    \\end{bmatrix}\\\\\n    H &= \\begin{bmatrix}\n        1 & \\theta_1 & \\theta_2 & \\cdots & \\theta_{r-1}\n    \\end{bmatrix}\\\\\n    Q &= \\begin{bmatrix}\n        \\sigma_a^2 & 0 & \\cdots & 0\\\\\n        0 & 0 & \\cdots & 0\\\\\n        \\vdots & \\vdots & \\cdots & \\vdots\\\\\n        0 & 0 & \\cdots & 0\n    \\end{bmatrix}\\\\\n    w_t &\\sim \\text{MVN}(0, Q)\n\\end{align}\nwhere $\\phi_i = \\theta_j = 0$ for $i > p, j > q$. Then the linear stochastic\ndynamical system \n\\begin{align}\n    x_{t+1} &= Fx_t + w_t\\\\\n    z_t &= Hx_t + \\mu\n\\end{align}\ndescribes the same process as the original $\\text{ARMA}$ model.\n\nLet $\\Theta = \\{\\phi_i, \\theta_j, \\mu, \\sigma_a^2\\}$ be the set of parameters\nfor an $\\text{ARMA}(p,q)$ model. Using the chain rule, we can factorize the\nlikelihood as\n\\begin{align}\n    \\label{eq:arma:factorized}\n    p(\\{z_t\\} | \\Theta) = \\prod_{t=1}^{n} p(z_t | z_{t-1}, \\ldots, z_{1},\n    \\Theta)\n\\end{align}\nSince we have assumed that the error terms are Gaussian, each conditional\ndistribution in \\ref{eq:arma:factorized} is also Gaussian, and is completely\ncharacterized by its mean and variance. But these two quantities are easily\nfound via the Kalman filter, namely\n\\begin{align}\n    \\text{mean} & \\quad H\\hat{x}_{t|t-1} + \\mu \\\\\n    \\text{variance} & \\quad HP_{t|t-1}H^T\n\\end{align}\nwhere $\\hat{x}_{t|t-1}, P_{t|t-1}$ are found during the Predict step. Our\nlikelihood becomes\n\\begin{align}\n    \\label{eq:arma:likelihood}\n    p(\\{z_t\\} | \\Theta) = \\prod_{t=1}^{n} N(z_t;\\; H\\hat{x}_{t|t-1} + \\mu,\\;\n    HP_{t|t-1}H^T)\n\\end{align}\nWe begin the recursion by letting\n\\begin{align}\n    \\hat{x}_{1|0} &= \\mathbb{E}(x_1) = 0 \\\\\n    \\text{vec}(P_{1|0}) &= \\mathbb{E}\\left[(x_1 - \\mathbb{E}x_1)(x_1 -\n    \\mathbb{E}x_1)^T\\right] = \\left[I_{r^2} - (F \\otimes F)\\right]^{-1} \\cdot\n    \\text{vec}(Q)\n\\end{align}\nwhere $\\text{vec}$ flattens a matrix and $\\otimes$ is the Kronecker product\n({\\tt numpy.kron}).\n\n\\begin{problem}\n\\label{prob:arma:likelihood}\nWrite a function that computes the log-likelihood of an $\\text{ARMA}(p,q)$\nmodel, given a time series $z_t$. You may reuse your Kalman filter code from\nLab \\ref{lab:kalman}.\n\n\\begin{lstlisting}\ndef arma_likelihood(time_series, phis=array([]), thetas=array([]), mu=0.,\n        sigma=1.):\n    \"\"\"\n    Return the log-likelihood of the ARMA model parameters, given the time\n    series.\n\n    Parameters\n    ----------\n    time_series : ndarray of shape (n,1)\n        The time series in question\n    phis : ndarray of shape (p,)\n        The phi parameters\n    thetas : ndarray of shape (q,)\n        The theta parameters\n    mu : float\n        The parameter mu\n    sigma : float\n        The parameter sigma\n\n    Returns\n    -------\n    log_likelihood : float\n        The log-likelihood of the model\n    \"\"\"\n    pass\n\\end{lstlisting}\n\n\\vspace{3mm} \\noindent\nFor example,\n\\begin{lstlisting}\n>>> arma_likelihood(time_series_a, phis=array([0.9]), mu=17., sigma=0.4)\n-77.6035\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Identification and Fitting}\n\nWhen modeling a data set with an $\\text{ARMA}(p,q)$ model, the order of the\nmodel must be determined as well as the other parameters. The process of\nchoosing $p$ and $q$ is called model identification. Different methods have\nbeen used; for example, Box and Jenkins propose a methodology that involves\nexamining the estimated autocorrelation and partial-autocorrelation functions\nof the data. We will choose $p$ and $q$ that minimize the Akaike information\ncriterion with a correction (AICc), given by\n\\begin{align}\n    2k\\left(1 + \\frac{k+1}{n-k}\\right) - 2 \\ell(\\Theta)\n\\end{align}\nwhere $n$ is the sample size, $k = p + q + 2$ is the number of parameters in\nthe model, and $\\ell(\\Theta)$ is the maximum likelihood for the model class.\n\nTo compute the maximum likelihood for a model class, we need to optimize\n\\ref{eq:arma:likelihood} over the space of parameters $\\Theta$. We can do so\nusing our function from Problem \\ref{prob:arma:likelihood} along with some\noptimization routine, such as {\\tt scipy.optimize.fmin}.\n\n\\begin{problem}\n\\label{prob:arma:mle}\nWrite a function that accepts a time series $\\{z_t\\}$ and returns the\nparameters of the model that minimizes the AICc, given the constraint that $p\n\\leq 3$, $q \\leq 3$.\n\n\\begin{lstlisting}\ndef arma_fit(time_series):\n    \"\"\"\n    Return the ARMA model that minimizes AICc for the given time series,\n    subject to p,q <= 3. \n\n    Parameters\n    ----------\n    time_series : ndarray of shape (n,1)\n        The time series in question\n\n    Returns\n    -------\n    phis : ndarray of shape (p,)\n        The phi parameters\n    thetas : ndarray of shape (q,)\n        The theta parameters\n    mu : float\n        The parameter mu\n    sigma : float\n        The parameter sigma\n    \"\"\"\n    pass\n\\end{lstlisting}\n\n\\vspace{3mm} \\noindent\nFor example,\n\\begin{lstlisting}\n>>> arma_fit(time_series_a)\n(array([ 0.9087]), array([-0.5759]), 17.0652..., 0.3125...)\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:arma:data}\nUse your solution from Problem \\ref{prob:arma:mle} to fit models to the data\nfound in {\\tt time\\_series\\_a.txt}, {\\tt time\\_series\\_b.txt}, {\\tt\ntime\\_series\\_c.txt}. Report the fitted parameters $p, q, \\Theta$.\n\\end{problem}\n\n\\section*{Forecasting}\nThe Kalman filter provides a straightforward way to predict future states, by\ngiving the mean and variance of the conditional distribution of future\nobservations.\n\\begin{align}\n    z_{t + k} | z_{1}, \\cdots, z_{t} \\sim N(z_k;\\; H\\hat{x}_{t+k|t} + \\mu,\\;\n    HP_{t+k|t}H^T)\n\\end{align}\nRecall the relations\n\\begin{align}\n    \\hat{x}_{t+k|t} &= F\\hat{x}_{t+k-1|t}\\\\\n    P_{t+k|t} &= FP_{t+k-1|t}F^T + Q\n\\end{align}\n\n\\begin{problem}\n\\label{prob:arma:forecast}\nForecast each data set ahead 20 intervals using the parameters discovered from\nProblem \\ref{prob:arma:data}, and plot their expected values along with the\noriginal data set. Also plot the expected values plus and minus $\\sigma_{t+k}$,\nand plus and minus $2\\sigma_{t+k}$ to demonstrate credible intervals. \n\n\\begin{lstlisting}\ndef arma_forecast(time_series, phis=array([]), thetas=array([]), mu=0.,\n        sigma=1., future_periods=20):\n    \"\"\"\n    Return forecasts for a time series modeled with the given ARMA model.\n    \n    Parameters\n    ----------\n    time_series : ndarray of shape (n,1)\n        The time series in question\n    phis : ndarray of shape (p,)\n        The phi parameters\n    thetas : ndarray of shape (q,)\n        The theta parameters\n    mu : float\n        The parameter mu\n    sigma : float\n        The parameter sigma\n    future_periods : int\n        The number of future periods to return\n\n    Returns\n    -------\n    evls : ndarray of shape (future_periods,)\n        The expected values of z for times n + 1, ..., n + future_periods\n    sigs : ndarray of shape (future_periods,)\n        The deviations of z for times n + 1, ..., n + future_periods\n    \"\"\"\n    pass\n\\end{lstlisting}\n\n\\vspace{3mm} \\noindent\nFor example,\n\\begin{lstlisting}\n>>> arma_forecast(time_series_a, phis, thetas, mu, sigma, 4)\n(array([ 17.3762,  17.3478,  17.322 ,  17.2986]),\n array([ 0.3125,  0.3294,  0.3427,  0.3533]))\n\\end{lstlisting}\n\\end{problem}\n\n\n\\begin{comment}\n\nThe Box-Jenkins methodology may be too esoteric, in light of straightforward\nalternatives such as the AICc. I have decided to leave this material out.\n\n\\section*{Identification}\n\nIf we have a time series $\\{z_t\\}$ and wish to fit an $ARMA(p,q)$ to it, we\nmust first identify the order of the model, that is, what $p$ and $q$ should\nbe. We discuss a methodology presented by Box and Jenkins that depends on the\nautocorrelations and partial-autocorrelations of the data. Alternative methods\nexist, such as using the Akaike information criterion with a correction (AICc).\n\n\\subsection*{Autocorrelation}\n\nThe autocorrelation between between $z_{t}, z_{t+k}$ is defined as the\nnormalized covariance between the two random variables, verbosely given as\n\\begin{align}\n    \\label{eq:arma:autocorrelation}\n    \\text{cor}[z_{t}, z_{t+k}] = \\frac{E[(z_{t} - E[z_{t}])(z_{t+k} -\n    E[z_{t+k}])]}{\\sqrt{E[(z_{t} - E[z_{t}])^2(z_{t+k} - E[z_{t+k}])^2]}}\n\\end{align}\nSince the $\\{z_t\\}$ is assumed to be covariance-stationary,\n\\ref{eq:arma:autocorrelation} depends only on the lag $k$, not on $t$. This\njustifies the notation\n\\begin{align}\n    \\rho_k = \\text{cor}[z_{t}, z_{t+k}] \\quad \\forall t\n\\end{align}\nWhen $\\rho_k$ is considered a function of $k$, it is called the autocorrelation\nfunction. Since $\\rho_0 = 1, \\rho_{-k} = \\rho_k$, we will be interested in the\ncases when $k > 0$. We can estimate $\\rho_k$ from sample data as\n\\begin{align}\n    \\label{eq:arma:autocorrelation_estimate}\n    \\hat{\\rho}_k = \\frac{\\sum_{t=1}^{N-k}(z_t - \\hat{\\mu})(z_{t+k} -\n    \\hat{\\mu})}{\\sum_{t=1}^{N}(z_t - \\hat{\\mu})^2}\n\\end{align}\nwhere $\\hat{\\mu}$ is the sample mean. This is one of a number of estimates of\nautocorrelation.\n\n\\begin{problem}\n\\label{prob:arma:autocorrelation}\nWrite a function that computes the autocorrelation estimate described in\n\\ref{eq:arma:autocorrelation_estimate}, given a time series and a lag $k$.\nPlot $\\hat{\\rho}_k$ for $1 \\leq k \\leq 20$ for each of the three data sets.\n\\end{problem}\n\n\\subsection*{Partial-Autocorrelation}\n\n\\end{comment}\n", "meta": {"hexsha": "8e4747a1f11631e92c6c0caa63f30aa2907070db", "size": 11230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/TimeSeries/TimeSeries.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": "Algorithms/TimeSeries/TimeSeries.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": "Algorithms/TimeSeries/TimeSeries.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": 34.984423676, "max_line_length": 79, "alphanum_fraction": 0.6727515583, "num_tokens": 3545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6125351256335246}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 3}\n\\subsection{Lecture Notes - Lagrangian Mechanics Part 3}\n\\subsubsection{Review of Variations}\nRecall \\textbf{Hamilton's Principle}, where we consider a trajectory between $t_1$, $t_2$, and variations from that trajectory $\\eta(t)$. The true trajectory taken by the physical system is given by $\\bar{q}(t)$. We parameterize the variations with an $\\alpha$ term, where $q(t) = \\bar{q}(t) + \\alpha\\eta(t)$. $\\bar{q}(t)$ minimizes the action functional $S[q]$ if $S[\\bar{q}] < S[q]$ for any other trajectories $q$. Our functional $S[q]$ is given by:\n\\[S[q] = \\int_{t_1}^{t_2}\nL(q, \\dot{q}, t)dt\\]\nWe found a method to find $\\bar{q}$ by taking the derivative of the action (i.e. a stationary point):\n\\[\\left. \\dod{S[\\bar{q} + \\alpha \\eta]}{\\alpha}\\right|_{\\alpha = 0} = 0\\]\nor alternatively, the statement that the (first order) variation must vanish:\n\\[\\delta S[\\bar{q}] = \\lim_{\\alpha \\rightarrow 0} \\frac{1}{\\alpha}\\left(S[\\bar{q} + \\alpha\\eta] - S[\\bar{q}]\\right) = 0\\]\nWe will explore this more on Monday when we look at constraint forces. \n\n\\subsubsection{Invariance, The Functional Derivative, and Multiple Variables}\n\\begin{enumerate}\n    \\item Form invariance of Euler-Lagrange equations. Going from generalized coordinates $q \\rightarrow \\tilde{q}$, then we have that:\n    \\[\\LL(\\tilde{q}, \\dot{\\tilde{q}}, t) = \\LL(q, \\dot{q}, t)\\]\n    by the definition of the Lagrangian. Alternatively, see that the action is invariant of the choice of general coordinates:\n    \\[\\tilde{S}[\\tilde{q}] = \\int_{t_{1}}^{t_2} \\tilde{\\LL}\\left(\\tilde{q}, \\dot{\\tilde{q}}, t\\right) d t=\\int_{t_{1}}^{t_2} \\mathcal{L}(q, \\dot{q}, t) d t=S[q]\\]\n    \\item One can take a functional derivative and set this to zero. The variation can be written using a functional derivative (indicated by lowercase $\\delta$):\n    \\[\\delta S[q] = \\int \\frac{\\delta S}{\\delta q} \\eta(t) dt\\]\n    What is the definition of the functional derivative? It's very similar to the conventional derivative:\n    \\[\\frac{\\delta S}{\\delta q(t)} = \\lim_{\\alpha = 0} \\frac{S[q + \\alpha \\delta(t)] - S[q]}{\\alpha} = \\dpd{\\LL}{q} - \\dod{}{t}\\dpd{\\LL}{\\dot{q}}\\]\n    Therefore, $\\frac{\\delta S}{\\delta q} = 0$ implies the Euler Lagrange equations. The way you can think about it is like the partial derivative. We are familiar with the total differential of a function (the sum of the partial differentials, see HW1 as an example). Now, imagine we have a function that depends continuously on a function $q$; its like a partial derivative with an index that is continuous (rather than discrete). \n    \\item If we have multiple variables, the generalization is straightforwards; for $n$ variables, the action functional becomes:\n    \\[S = \\int_{t_1}^{t_2}\\LL(q_1, q_2, \\cdots, q_n, \\dot{q}_1, \\dot{q}_2, \\cdots, \\dot{q}_n, t)dt\\]\n    So we would get $n$ Euler-Lagrange equations:\n    \\[\\dpd{\\LL}{q_i} = \\dod{}{t}\\dpd{\\LL}{\\dot{q}_i}\\]\n    Where $\\dpd{\\LL}{q_i}$ is  the generalized force, and $\\dpd{\\LL}{\\dot{q}_i}$ is the generalized momentum. \n\\end{enumerate}\n\n\\subsubsection{Torque, Angular Momentum, and Generalized Momentum Conservation}\nSee derivation in Worksheet three for the relation:\n\\[\\dpd{\\LL}{\\phi} = \\dod{}{t}\\dpd{\\LL}{\\dot{\\phi}}\\]\nWhich corresponds to:\n\\[\\Gamma = \\dod{L}{t}\\]\nSo if there is zero torque, we have conservation of angular momentum. Generally, if $\\LL$ is independent of $q_i$, then the generalized momentum $\\pd{\\LL}{\\dot{q}_i}$ is conserved. We have a conservation law that comes from a certain property in the Lagrangian. We call variables that do not appear in the Lagrangian as a \"cyclic\" or \"ignorable\" variable.\n\\end{document}", "meta": {"hexsha": "53d6182c93246345c7feff7a0df6c54f3cb18ac4", "size": 3694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-3/Lecture-Notes-3.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-3/Lecture-Notes-3.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-3/Lecture-Notes-3.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": 92.35, "max_line_length": 451, "alphanum_fraction": 0.6935571197, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.612535121617302}}
{"text": "\\section{Searching}\n\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$\\max/\\min$ differences (Problem 4.5)}\n  \\begin{enumerate}[(a)]\n\t\\item unsorted; $\\max |x - y|$; $O(n)$\n\t\\item sorted; $\\max |x - y|$; $O(1)$\n\t\\item unsorted; $\\min |x - y|$; $O(n \\log n)$\n\t\\item sorted; $\\min |x - y|$; $O(n)$\n  \\end{enumerate}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Searching in matrix (Problem 4.6)}\n  \\begin{itemize}\n\t\\item $M$: matrix $m \\times n$\n\t\\item row: increasing from left to right\n\t\\item col: increasing from top to down\n\t\\item Is $x \\in M$?\n  \\end{itemize}\n\n  \\pause\n  \\centerline{Divide and conquer.}\n\n  \\pause\n  \\[\n\tT(m,n) = 3T(\\frac{m}{2}, \\frac{n}{2}) + 1 \n  \\]\n\n  % \\pause\n  % \\[\n  %   m = n \\implies T(n) = 3T(\\frac{n}{2}) + 1 \\pause \\implies T(n) = \\Theta(n^{\\log_{2}3})\n  % \\]\n\n  \\pause\n  \\centerline{Always checking the lower left corner.}\n\n  \\pause\n  \\[\n\tT(m, n) = m + n - 1\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Searching in matrix (Problem 4.6)}\n  \\[\n\t\\text{Assume } M: n \\times n \n  \\]\n\n  \\[\n\tW(n) \\le 2n - 1\n  \\]\n\n  \\pause\n  \\vspace{0.30cm}\n  \\centerline{$W(n) \\ge 2n - 1$ by adversary argument!}\n\n  \\pause\n  \\begin{align*}\n\ti + j \\le n - 1 &\\implies x > M_{ij} \\\\\n\ti + j > n - 1 &\\implies x < M_{ij} \\\\\n  \\end{align*}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Local minimum (Problem 4.11)}\n  \\begin{itemize}\n\t\\item Array $A[0 \\ldots n-1]$\n\t\\item Boundary conditions:\n\t  \\begin{align*}\n\t\tA[0] &\\ge A[1] \\\\\n\t\tA[n-2] &\\le A[n-1]\n\t  \\end{align*}\n\t\\item Local minimum $A[i]$:\n\t  \\[\n\t\tA[i-1] \\ge A[i] \\le A[i+1]\n\t  \\]\n\t\\item Goal: Find \\emph{any} local minimum.\n  \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Local minimum (Problem 4.11)}\n  \\begin{enumerate}\n\t\\item Checking each element:\n\t  \\[\n\t\tT(n) = O(n)\n\t  \\]\n\t\\item $\\min A$:\n\t  \\[\n\t\tT(n) = O(n)\n\t  \\]\n\t\\pause\n\t\\item Required:\n\t  \\[\n\t\tT(n) = O(\\log n)\n\t  \\]\n\n\t  \\pause\n\t  \\[\n\t\tT(n) = T(\\frac{n}{2}) + 1\n\t  \\]\n  \\end{enumerate}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Local minimum (Problem 4.11)}\n  2D local minimum:\n  \\begin{itemize}\n\t\\item Matrix $M: n \\times n$\n\t\\item Boundary conditions:\n\t  \\[\n\t\t\\infty\n\t  \\]\n\t\\item Local minimum $A[i,j]$:\n\t  \\begin{align*}\n\t\tA[i,j-1] &\\ge A[i,j] \\le A[i,j+1] \\\\\n\t\tA[i-1,j] &\\ge A[i,j] \\le A[i+1,j]\n\t  \\end{align*}\n\t\\item Goal: Find \\emph{any} local minimum.\n  \\end{itemize}\n\n  \\pause\n  \\[\n\tO(n^2) \\pause \\implies O(n \\log n) \\pause \\implies O(n) \\implies \\textcolor{red}{O(\\log n)}\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{$a_i = i$ (Problem 4.2)}\n  \\begin{itemize}\n\t\\item Sorted integer sequence $\\set{a_1, a_2, \\ldots, a_n}$:\n\t  \\[\n\t\t\\forall i \\neq j: a_i \\neq a_j\n\t  \\]\n\t\\item Goal: \n\t  \\[\n\t\t\\exists? i: a_i = i\n\t  \\]\n  \\end{itemize}\n\n  \\pause\n  \\[\n\tT(n) = O(n)\n  \\]\n\n  \\pause\n  \\[\n\tT(n) = T(\\frac{n}{2}) + 1 = O(\\log n)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Smallest missing positive integer (Problem 4.3)}\n  \\begin{itemize}\n\t\\item Sorted array $A[1 \\ldots n]$:\n\t  \\begin{gather*}\n\t\ta_i \\in \\mathbb{Z}^{+} \\\\\n\t\t\\forall i \\neq j: a_i \\neq a_j\n\t  \\end{gather*}\n\t\\item Goal: Find the smallest missing positive integer.\n  \\end{itemize}\n\n  \\pause\n  \\[\n\tT(n) = O(n)\n  \\]\n\n  \\pause\n  \\[\n\tT(n) = T(\\frac{n}{2}) + 1 = O(\\log n)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing $\\lceil \\sqrt{N} \\rceil$ (Problem 4.12)}\n  \\begin{itemize}\n\t\\item Given an $n$-bit natural number $N$ ($0 \\le N < 2^{n} - 1$)\n\t\\item Goal: Compute $\\lceil \\sqrt{N} \\rceil$ using $O(n)$ additions and shifts.\n  \\end{itemize}\n     \n  \\vspace{0.30cm}\n  \\begin{columns}\n    \\column{0.55\\textwidth}\n\t  \\pause\n\t  \\begin{block}{Elementrary operations:}\n\t    \\begin{itemize}\n\t      \\item $n$-bit + $n$-bit: $O(1)$\n\t      \\item $n$-bit shifted by $1$-bit: $O(1)$\n\t      \\item $\\Rightarrow x^2: O(n)$\n\t    \\end{itemize}\n\t  \\end{block}\n\t\\column{0.45\\textwidth}\n\t  \\pause\n\t  \\begin{enumerate}[<+->]\n\t    \\item Na{\\\"i}ve search: $O(2^{n} \\cdot n)$\n\t    \\item Binary search: $O(n \\cdot n)$\n\t    \\item Binary search in range:\n\t\t  \\[\n\t\t\t2^{\\lfloor \\frac{n-1}{2} \\rfloor} \\le \\lceil \\sqrt{N} \\rceil \\le 2^{\\lceil \\frac{n}{2} \\rceil}\n\t\t  \\]\n\t\t  \\[\n\t\t\t\\lg{(2^{\\lceil \\frac{n}{2} \\rceil} - 2^{\\lfloor \\frac{n-1}{2} \\rfloor})} = O(n)\n\t\t  \\]\n\t\t  \\[ O(n \\cdot n) \\]\n\t  \\end{enumerate}\n  \\end{columns}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing $\\lceil \\sqrt{N} \\rceil$ (Problem 4.12)}\n  \\begin{block}{A Little History:}\n    \\begin{description}\n\t  \\item[$2007$:] Mid-term problem \\\\\n\t\t\\centerline{$O(n)$ required; NO $O(n)$ solutions, however}\n\t  \\item[$\\sim 2013$:] $O(n^2)$\n\t  \\pause\n\t  \\item[$2014$:] $O(n)$\n\t\t\\fignocaption{width = 0.80\\textwidth}{figs/square-root-cs-se.png}\n    \\end{description}\n  \\end{block}\n\n  \\pause\n  \\[\n\tx^2: O(n) \\to O(1)\n  \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing $\\lceil \\sqrt{N} \\rceil$ (Problem 4.12)}\n  Given\n  \\[\n\tM = \\lfloor N/4 \\rfloor\n  \\]\n\n  \\[ \n\tx = \\lceil \\sqrt{M} \\rceil \\textrm{ and } (x, x^2),\n  \\]\n\n  what is\n  \\[ \n    y = \\lceil \\sqrt{N} \\rceil \\textrm{ and } (y, y^2)? \n  \\]\n\n  \\pause\n  \\begin{exampleblock}{An Example:}\n  \\[\n\t\\begin{array}{lll}\n\t  N = 280 & y = \\lceil \\sqrt{280} \\rceil = 17 & y^2 = 289 \\\\ \\pause\n\t  M = \\lfloor 280/4 \\rfloor = 70 & x = \\lceil \\sqrt{70} \\rceil = 9 & x^2 = 81 \\\\ \\pause\n\t  M = \\lfloor 70/4 \\rfloor = 17 & x = \\lceil \\sqrt{17} \\rceil = 5 & x^2 = 25 \\\\\n\t  M = \\lfloor 17/4 \\rfloor = 4 & x = \\lceil \\sqrt{4} \\rceil = 2 & x^2 = 4 \\\\\n\t  M = \\lfloor 4/4 \\rfloor = 1 & x = \\lceil \\sqrt{1} \\rceil = 1 & x^2 = 1\n\t\\end{array}\n  \\]\n  \\end{exampleblock}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing $\\lceil \\sqrt{N} \\rceil$ (Problem 4.12)}\n  \\begin{algorithm}[H]\n    \\caption{Computing $\\lceil \\sqrt{N} \\rceil$.}\n    \\begin{algorithmic}[]\n      \\Procedure{Sqrt-Root}{$N$}\n\t    \\If{$N < 3$}\n\t      \\State \\Return $1 \\Rightarrow (1,1); 2 \\Rightarrow (2,4); 3 \\Rightarrow (2,4)$\n\t    \\EndIf\n\t    \\State $M \\gets \\lfloor N/4 \\rfloor$\n\t    \\State $(x, x^2) \\gets \\textsc{Sqrt-Root}{(M)}$\n\t\t\\State \\Return the $(y, y^2)$ with $y^2 \\sim N$:\n           \\[\n\t\t\t(y, y^2) = \\left\\{ \\begin{array}{ll}\n\t\t\ty = 2x & y^2 = 4x^2 \\\\\n\t\t\ty = 2x + 1 & y^2 = 4x^2 + 4x + 1 \\\\\n\t\t\ty = 2x - 1 & y^2 = 4x^2 - 4x + 1\n\t\t\t\\end{array} \\right.\n\t      \\]\n\t  \\EndProcedure\n    \\end{algorithmic}\n  \\end{algorithm}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Computing $\\lceil \\sqrt{N} \\rceil$}\n  \\[ \\xout{T(n) = T(n/4) + O(1) = \\Theta(\\lg n)} \\]\n\n  \\[ T(n) = T(n - 2) + O(1) = \\Theta(n) \\]\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Space for hashing (Problem 4.4)}\n  \\begin{description}\n\t\\item[Key:] $x$\n\t\\item[Node:] $y$\n\t\\item[Load factor:] $\\alpha$\n  \\end{description}\n\n  \\pause\n  \\begin{itemize}\n\t\\item Closed-address hashing\n\t  \\[\n\t\th_c + \\alpha y h_c\n\t  \\]\n\t\\item Open-address hashing\n\t  \\[\n\t\t\\frac{\\alpha h_c}{\\frac{h_c + \\alpha y h_c }{x}} = \\frac{\\alpha x}{1 + \\alpha y}\n\t  \\]\n  \\end{itemize}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[noframenumbering]\n  \\fignocaption{width = 0.50\\textwidth}{figs/thankyou.jpg}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "9f924b8e7bee76ffa964b9ed8e551de170ece26c", "size": 6972, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2017/algorithm-tutorial-search-selection-20170410/sections/search.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-search-selection-20170410/sections/search.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-search-selection-20170410/sections/search.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.0860927152, "max_line_length": 97, "alphanum_fraction": 0.5243832473, "num_tokens": 2887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.612535121617302}}
{"text": "\\chapter{GPS}\n\nSuppose that the Earth is a spheroid\n\\begin{equation}\n  \\label{eq:spheroid}\n  \\frac{x^2}{a^2} + \\frac{y^2}{a^2} + \\frac{z^2}{b^2} = 1, \\quad a\n  \\geq b > 0,\n\\end{equation}\nwith its centre of symmetry in the origin of the Cartesian coordinate\nsystem and axes overlapping axes of coordinate system.\n\nLet $P$ be a point on the ellipsoid~\\eqref{eq:spheroid}. Define\ngeographical coordinates: latitude and longitude as follows. Latitude\nof $P$ is the angle between the normal to the ellipsoid at the point\n$P$ and the plane $z = 0$ (see figure \\ref{fig:spheroid_coordinates}).\nLongitude of $P$ is the angle between the plane $y = 0$ and the plane\nperpendicular to the plane $z = 0$ passing through the point $P$ and\nthe origin of the coordinate system.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\resizebox{6cm}{!}{\\includegraphics{1.pdf}}\n\\end{center}\n\\caption{Cartesian and geographic coordinates on the spheroid.}\n\\label{fig:spheroid_coordinates}\n\\end{figure}\n\nDenote latitude by $-\\frac{\\pi}{2} \\leq \\varphi \\leq \\frac{\\pi}{2}$,\nlongitude by $-\\pi \\leq \\lambda \\leq \\pi$. The $X$ axis passes through\nthe point $(a, 0, 0)$ with latitude $0^\\circ$ and longitude $0^\\circ$\n($\\varphi = 0, \\lambda = 0$), the $Y$ axis passes through the point\n$(0, a, 0)$ with latitude $0^\\circ$ and longitude $90^\\circ$ east\n($\\varphi = 0, \\lambda = \\frac{\\pi}{2}$) and the $Z$ axis passes\nthrough the north pole $(0, 0, b)$ with latitude $90^\\circ$ north\n($\\varphi = \\frac{\\pi}{2}, -\\pi \\leq \\lambda \\leq \\pi$).\n\n\\section{Conversion of coordinates}\n\nLet $P$ be a point on the ellipsoid~\\eqref{eq:spheroid} with latitude\n$0 < |\\varphi| < \\frac{\\pi}{2}$ and longitude $-\\pi \\leq \\lambda \\leq\n\\pi$. We are looking for its coordinates $(x, y, z)$. As the\n$Z$-coordinate depends only on $\\varphi$, take a point $P'$ with\nlatitude $\\varphi$ and longitude $0$, lying on the plane $y = 0$ (see\nfigure \\ref{fig:plane_y_0}). The line passing through $P'$ and\ninclined to the $x$-axis at the angle $\\varphi$ is a normal to the\nellipse\n\\begin{equation} \\label{eq:ellipseXZ}\n  \\frac{x^2}{a^2} + \\frac{z^2}{b^2} = 1\n\\end{equation}\nat a point $(x_0, z_0)$ and intersects the $x$-axis at the point\n$(x_1, 0)$.\n\n\\begin{figure}[ht]\n\\begin{center}\n\\resizebox{6cm}{!}{\\includegraphics{2.pdf}}\n\\end{center}\n\\caption{Position of the point $P'$ on the plane $y = 0$.}\n\\label{fig:plane_y_0}\n\\end{figure}\n\n\\noindent Hence it follows that\n\\begin{equation} \\label{eq:first_eq_for_z}\n  \\tg \\varphi = \\frac{z_0}{x_0 - x_1}.\n\\end{equation}\nThis normal has the equation\n\\[\nz_0x - (x_0 - x_1)z - z_0x_1 = 0.\n\\]\nOn the other hand, a normal to the ellipse \\eqref{eq:ellipseXZ} at its\npoint $(x_0, z_0)$ has the equation \\cite [pp.~215,~244]\n{bronsztejn-siemiendiajew-musiol-muhlig-2004}\n\\[\na^2z_0x - b^2x_0z - (a^2 - b^2)x_0z_0 = 0.\n\\]\nThese two lines must overlap, so there must be\n\\[\n\\frac{z_0}{a^2z_0} = \\frac{x_0 - x_1}{b^2x_0} = \\frac{z_0x_1}{(a^2 -\n  b^2)x_0z_0}\n\\]\nand\n\\begin{equation} \\label{eq:x1}\n  x_0 - x_1 = \\frac{b^2}{a^2}x_0, \\quad x_1 = \\frac{a^2 -\n    b^2}{a^2}x_0.\n\\end{equation}\nFrom \\eqref{eq:ellipseXZ} we have\n\\begin{equation} \\label{eq:x0_from_XZ}\n  x_0 = \\frac{a}{b}\\sqrt{b^2 - z_0^2}.\n\\end{equation}\nUsing \\eqref{eq:x1} and \\eqref{eq:x0_from_XZ} in\n\\eqref{eq:first_eq_for_z} we obtain\n\\[\nz_0 = p \\frac{\\sin \\varphi}{\\sqrt{1 - e^2\\sin^2 \\varphi}},\n\\]\nwhere $p = b^2 / a$ \\cite [p.~214]\n{bronsztejn-siemiendiajew-musiol-muhlig-2004} and\n\\[\ne = \\frac{\\sqrt{a^2 - b^2}}{a}\n\\]\nis the eccentricity of the ellipse~\\eqref{eq:ellipseXZ} \\cite [p.~214]\n{bronsztejn-siemiendiajew-musiol-muhlig-2004}.\nFrom~\\eqref{eq:x0_from_XZ} we obtain\n\\[\nx_0 = a \\frac{\\cos \\varphi}{\\sqrt{1 - e^2\\sin^2 \\varphi}}.\n\\]\n$X$ and $Y$ coordinates can be calculated from the parametric equation\nof the circle $x^2 + y^2 = x_0^2$ for the angle $\\lambda$: $x = x_0\n\\cos \\lambda$, $y = x_0 \\sin \\lambda$.\n\nThe complete coordinates are\n\\begin{align*}\n  x &= a \\frac{\\cos \\varphi}{\\sqrt{1 - e^2\\sin^2 \\varphi}} \\cos \\lambda \\\\\n  y &= a \\frac{\\cos \\varphi}{\\sqrt{1 - e^2\\sin^2 \\varphi}} \\sin \\lambda \\\\\n  z &= p \\frac{\\sin \\varphi}{\\sqrt{1 - e^2\\sin^2 \\varphi}}\n\\end{align*}\nThese formulas are valid also for $\\varphi = 0$ and $\\varphi = \\pm\n\\frac{\\pi}{2}$.\n\nIf a point lies on the normal with distance $h$ from the surface of\nthe ellipsoid, then the corresponding values of $z_0$ and $x_0$ should\nbe increased by $h \\sin \\varphi$ and $h \\cos \\varphi$, respectively.\nTherefore, if a point is specified by coordinates $(\\varphi, \\lambda,\nh)$, corresponding Cartesian coordinates are\n\\begin{align}\n  \\label{eq:x_coord}\n  x &= \\left( \\frac{a}{\\sqrt{1 - e^2\\sin^2 \\varphi}} + h \\right) \\cos\n  \\varphi \\cos \\lambda \\\\\n  \\label{eq:y_coord}\n  y &= \\left( \\frac{a}{\\sqrt{1 - e^2\\sin^2 \\varphi}} + h \\right) \\cos\n  \\varphi \\sin \\lambda \\\\\n  \\label{eq:z_coord}\n  z &= \\left( \\frac{p}{\\sqrt{1 - e^2\\sin^2 \\varphi}} + h \\right) \\sin\n  \\varphi\n\\end{align}\n\n\\section{Parameters of the spheroid}\n\nWe specify the spheroid of the Earth by two parameters\\footnote{See\n  \\url{https://en.wikipedia.org/wiki/World_Geodetic_System}.}:\nsemi-major axis $a = 6378137.0$ metres and inverse flattening $1 / f =\n298.257223563$, where $f = (a - b) / a$.\n", "meta": {"hexsha": "570062dc336898c03411daa54edf9ecf999bcf55", "size": 5164, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/gps.tex", "max_stars_repo_name": "shgalus/shg", "max_stars_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-05-21T04:14:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-31T17:15:15.000Z", "max_issues_repo_path": "doc/gps.tex", "max_issues_repo_name": "shgalus/shg", "max_issues_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-05-21T05:31:04.000Z", "max_issues_repo_issues_event_max_datetime": "2015-05-21T05:31:04.000Z", "max_forks_repo_path": "doc/gps.tex", "max_forks_repo_name": "shgalus/shg", "max_forks_repo_head_hexsha": "0318d0126cf12c3236183447d130969c468a02fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-05-21T04:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-18T12:35:22.000Z", "avg_line_length": 36.6241134752, "max_line_length": 74, "alphanum_fraction": 0.6719597211, "num_tokens": 1991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6125351095686334}}
{"text": "\\chapter*{\\uppercase{Abbreviations and Notation} \\label{appendix-notation}}\n\n\\section{Abbreviations}\n\n\\begin{description}[leftmargin=!,labelwidth=0.5in,font=\\normalfont]\n\t\\item\n\\end{description}\n\n\n\\section{Mathematical Notation}\n\\begin{description}[leftmargin=!,labelwidth=0.5in,font=\\normalfont]\n\t\\item\n\\end{description}\n\n\n\\subsection{General Notation}\n\n% EDIT BELOW AND REMOVE WHAT YOU DO NOT NEED\n\\begin{description}[leftmargin=!, labelwidth=0.7in]\n  \\item[$x$]             italicized, Roman or Greek letter, denotes scalar values\n  \\item[$\\bs{x}$]        italicized, bold, lowercase Roman or Greek letter, denotes a column vector\n  \\item[$\\bs{X}$]        italicized, bold, uppercase Roman or Greek letter, denotes a matrix\n\t\\item[$\\bs{X}_{ij}$] \t denotes the component of matrix $\\bs{X}$ occupying row $i$ and column $j$\n\n  \\item[$x \\in (a, b)$]  the value $x$ is within the interval such that $a < x < b$\n  \\item[{$x \\in (a, b]$}]  the value $x$ is within the interval such that $a < x \\leq b$\n  \\item[$x \\in [a, b)$]  the value $x$ is within the interval such that $a \\leq x < b$\n  \\item[{$x \\in [a, b]$}]  the value $x$ is within the interval such that $a \\leq x \\leq b$\n  \\item[$1_{A}\\left(x\\right)$] the indicator function,\\[1_{A}\\left(x \\right) = \\begin{cases} 1 & x \\in A \\\\ 0 & x \\notin A \\end{cases}.\\]\n  \\item[$\\bs{1}_n$] an column vector of $n$ $1$s\n  \\item[$\\bs{I}$] the identity matrix\n  \\item[$\\bs{I}_n$] the $n \\times n$ identity matrix\n  \\item[$\\bs{X}^{-1}$] the inverse matrix, i.e., the operator satisfying $\\bs{X}^{-1} \\bs{X} = \\bs{X} \\bs{X}^{-1} = \\bs{I}.$\n  \\item[$\\bs{X}^{\\top{T}}$] transpose, i.e. the operator satisfying $X_{i,j} = X_{j, i} \\; \\forall \\; i,j \\in \\mathbb{N}$\n  \\item[$\\otimes$] Kronecker product\n  \\item[$\\odot$] element-wise multiplication\n\\end{description}\n\n\\subsection{Sets}\n\n\\begin{description}[leftmargin=!, labelwidth=0.8in]\n  \\item[$\\set{x, y, z, \\ldots}$]  the set comprising the elements of $x,$ $y,$ $z,$ $\\ldots$\n  \\item[$\\set{x, y, z} \\backslash x$]  the set comprising the elements of $y$ and $z$\\footnote{In other words, the backslash removes an element (or a subset) from the original set.}\n  \\item[$\\sett{x_i}{i = 1}{n}$]  the set comprising the elements of $x_1, x_2, x_3, \\ldots, x_n$\n  \\item[$\\RR$] set of real numbers\n\t\\item[$\\NN$] set of natural numbers\n  \\item[$\\bs{x} \\in \\mathbb{R}^n$] $\\bs{x}$ is a vector with $n$ elements, all of which are real numbers\n\\end{description}\n\n\\subsection{Statistical Distributions}\n\\begin{description}[leftmargin=!, labelwidth=0.8in]\n  \\item[$\\mathcal{N} \\left( \\mu, \\sigma^2 \\right)$] the uni-variable Gaussian distribution with mean $\\mu$ and variance $\\sigma^2$\n  \\item[$\\mathcal{N} \\left( \\bs{\\mu}, \\bs{\\Sigma} \\right)$] the multi-variable Gaussian distribution with mean vector $\\bs{\\mu}$ and variance-covariance matrix $\\bs{\\Sigma}$\n  \\item[$\\phi(x)$] the standard Gaussian density function\n\\end{description}\n\n\\subsection{Specialized Notation}\nThis notation refers to values defined explicitly in the context of this thesis.\n\n\\begin{itemize}\n\\itembox{$\\M$} a model that takes input parameters to an (observable) state space\n\\itembox{$u$} an observable state space from which data is to be collected\n\\itembox{$\\param$} a (model) parameter into model $\\M$\n\\itembox{$\\obs$} a Parameter-to-Observables (PtO) map, also denoted $\\obs( u\\lam )$ or $\\obs\\lam$, each component of which is a functional  $\\obs_i: u\\lam \\to \\RR$ on the observable state\\footnote{This map represents performing an individual experiment, which may consist of one or more observations (either in space or time). Arranging observational data into a vector defines the map.}\n\\itembox{$\\qoi$} a Quantity of Interest (QoI) map, also denoted $\\qlam$, which acts on observable data to transform the data into a scalar or vector quantity\\footnote{For example, it may be the average of measurements encompassed in $\\obs$. Technically, this map encompasses the following set of compositions: $Q(\\obs(u\\lam))$.}\n\\itembox{$\\data$} data representing an individual output of a (possibly vector-valued) QoI map for a particular parameter $\\param$, i.e. $\\qlam = \\data$\n\\end{itemize}\n\n[TK - add Measure-Theory notation into this section, based on what you have in your newcommands.tex file]\n", "meta": {"hexsha": "13606a15c0063c5e9fdcb2b3216ddf74a223d6e0", "size": 4251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notation.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": "notation.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": "notation.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": 60.7285714286, "max_line_length": 387, "alphanum_fraction": 0.6937191249, "num_tokens": 1347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6124588089884305}}
{"text": "\\section{Queueing Theory}\n\\label{sec:Queueing-Theory}\n\nThe queueing theory is built on the stochastic modeling and analysis, which represents service demands and interarrivals as random variables.\nIt is the theory behind what makes queues appear and how to make them go away.\nIt is the study of queueing behavior in systems and networks.\n\nQueueing theory applies anywhere that queues come up. It is also at the heart of any computer system.\n\nQueueing theory has its origins in research by Agner Krarup Erlang when he created models to describe the Copenhagen telephone exchange.\n\nQueues results from variability in service time and/or interarrival time distribution.\n\nA major reason why computer scientists are so slow to adopt queueing theory is that standard assumptions often do not fit. In some cases they are very far from reality: for example, in the case of high variability and correlations. However there are often ways to work around these assumptions.\n\nThe goals of a queueing theorist is \\textit{predicting} the system performance and \\textit{designing} it to improve performance.\n\nThere are many questions in computer systems design that lend themselves to a queueing-theoretic solution (e.g., power management, priority scheduling, and so on).\nHowever, there are  lots of problems that we can at best only analyze approximately (e.g., mean response time for M/G/k queue). Typically, approximations are very poor when jobs size variability gets high \\cite{gupta2010inapproximability}.\n\n\n\n\n\\subsection{Queue Metrics}\n\\label{sec:Queue-Metrics}\n\nA queue node is described by the following parameters and performance metrics:\n\n\\begin{description}\n\t\\item [Service Order] The scheduling discipline.\n\t\n\t\\item [Average Arrival Rate]  ($\\lambda$) The rate at which jobs arrive to the node.\n\t\n\t\\item [Interarrival Time] ($\\tau$) The time between successive job arrivals.\n\t\n\t\\item [Mean Interarrival Time] ($\\expected{\\tau}=\\frac{1}{\\lambda}$) The average time between successive job arrivals.\n\t\n\t\\item [Service Requirement, Size] ($S$) The time taken by a job to run on server.\n\t\n\t\\item [Average Service Rate] ($\\mu$) The rate at which jobs are served by the server.\n\t\n\t\\item [Mean Service Time] ($\\expected{S}=\\frac{1}{\\mu}$) The average time required to serve a job.\n\t\n\t\\item [Waiting Time, Delay] ($T_{Q}$) The time that the job spends in the queue.\n\t\n\t\\item [Response Time, Turnaround Time] ($T$) The time during which the job is in the node. Thus $T=T_{departure}-T_{arrival}$. Note that $\\expected{T}=\\expected{T_{Q}}+\\expected{S}$.\n\t\n\t\\item [Number of System Jobs] ($N$) The number of jobs in the queue plus the ones being served.\n\t\n\t\\item [Number of Queued Jobs] ($N_{Q}$) The number of jobs in the queue.\n\t\n\t\\item [Utilization] ($\\varrho$) The fraction of time the server is busy, the probability of the server to be busy, the mean number of jobs in that node.\n\t\n\t\\item [Throughput] ($X$) The rate of completions at server.\n\\end{description}\n\n\n\n\n\\subsection{Kendall notation}\nA queue node il classified using the Kendall notation \\cite{kendall1953stochastic}.\n\n\\begin{equation}\nA/S/m/c/N/D\n\\end{equation} \n\nwhere \n\n\\begin{description}\n\t\\item [A] the arrival process, the value indicates the probability distribution of inter-arrival times.\n\t\n\t\\item [S] the service process, the value indicates the probability distribution of service times.\n\t\n\t\\item [A] the number of servers.\n\t\n\t\\item [c] the capacity of the system (that is, the number of servers plus the buffer size).\n\t\n\t\\item [N] the size of the population, that is the total number of jobs.\n\t\n\t\\item [D] the scheduling discipline.\n\\end{description}\n\nThe arrival process \\textit{A} and service process \\textit{S} could be equal to \n\n\\begin{description}\n\t\\item [$M$] Exponential distribution.\n\t\n\t\\item [$D$] Deterministic distribution.\n\t\n\t\\item [$E_{n}$] Erlang distribution of order $n$.\n\t\n\t\\item [$H_{n}$] Hyper-exponential distribution of order $n$.\n\t\n\t\\item [$G$] Generic distribution of independent variables.\n\\end{description}\n\nThe scheduling discipline \\textit{D} could be equal to \n\n\\begin{description}\n\t\\item [$FCFS (FIFO)$] first come, first served.\n\t\n\t\\item [$LCFS (LIFO)$] last come, first served.\n\t\n\t\\item [$RO$] random order.\n\t\n\t\\item [$RR$] round robin.\n\t\n\t\\item [$PS$] processor sharing.\n\t\n\t\\item [$P$] custom priority.\n\\end{description}\n\nWhen the final three parameters are not specified (e.g. M/M/1 queue), it is assumed $K=\\infty$, $N=\\infty$ and $D=FIFO$.\n\n\n\n\n\\subsection{Classification of Queueing Networks}\n\\label{sec:Classification-Queueing-Networks}\n\nQueueing networks can be classified into two categories:\n\n\\begin{description}\n\t\\item [Open Networks] They have external arrivals and departures. In such systems, $X=\\lambda$\n\t\n\t\\item [Closed Networks] They have no external arrivals or departures. In such systems, $X=\\mu$. The number of jobs in the system is fixed to $N$, and it is called \\textit{load} or \\textit{multiprogramming level (MPL)}. $\\expected{T}=\\expected{T_{R}}+\\expected{Z}$. Closed networks can be classified in two categories:\n\t\n\t\\begin{description}\n\t\t\\item [Interactive Networks] There are $N$ \\textit{terminals} which submit jobs to a network of queues, called \\textit{central subsystem}. After submission, a terminal waits for job completion, then sleeps for a think-time $Z$, then can submit again. Thus, a terminal oscillates between a submission-state and a think-state. The goal is to limit the rise of $\\expected{T_{R}}$ with $N$.\n\t\t\n\t\t\\item [Batch Networks] They are interactive networks with no think-time ($Z=0$). The goal is to obtain high throughput.\n\t\\end{description}\t\t\n\t\n\\end{description}\n\n%\\begin{figure}[tp]\n%\\label{fig:Open-Network-Sample}\n%\t\\centering\n%\t\\includegraphics{fig/Open-Network-Sample}\n%\t\\caption{An Open network.}\n%\\end{figure}\n\n%\\begin{figure}[tp]\n%\\label{fig:Interactive-Network-Sample}\n%\t\\centering\n%\t\\includegraphics{fig/Interactive-Network-Sample}\n%\t\\caption{An Interactive network.}\n%\\end{figure}\n\n%\\begin{figure}[tp]\n%\\label{fig:Batch-Network-Sample}\n%\t\\centering\n%\t\\includegraphics{fig/Batch-Network-Sample}\n%\t\t\\caption{A Batch network.}\n%\\end{figure}\n\n\\cite{schroeder2006open} proposed the notion of \\textit{partly-open networks}. Here terminals arrive from outside as in open networks, but make request as in closed ones.\n\n\n\n\n\\subsection{Utilization}\n\\label{sec:Utilization}\n\nThe utilization of a queue node is the fraction of time the node is busy, the probability that it is busy, and the mean number of jobs in that node.\n\n\\begin{theorem}[Utilization Law]\n\\label{thm:Utilization-Law}\n\n\tFor every stable queue node, we have that:\n\t\n\t\\begin{equation}\n\t\\label{eqn:Utilization-Law}\n\t\\varrho = \\frac{\\lambda}{\\mu} = X \\cdot \\mathbf{E}[S]\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tLet us consider the definition of throughput ($X=\\frac{C}{\\tau}$) and utilization ($\\varrho=\\frac{B}{\\tau}$). We have that\n\t\t\n\t\t\\begin{equation*}\n\t\t\tX = \\frac{C}{\\tau} = \\frac{C}{B} \\cdot \\frac{B}{\\tau} = \\frac{C}{B} \\cdot \\varrho\n\t\t\\end{equation*}\n\t\t\n\t\tSince $\\frac{B}{C}=\\expected{S}$ and $\\frac{C}{B}=\\mu$, we have that\n\t\t\n\t\t\\begin{equation*}\n\t\t\tX = \\mu \\cdot \\varrho \\equiv \\frac{\\varrho}{\\expected{S}} \\Rightarrow \\varrho = X \\cdot \\expected{S}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}\n\n\n\n\n\\subsection{Stability}\n\\label{sec:Stability}\n\nThe stability condition guarantees that the queue cannot grow unbounded.\n\n\\begin{theorem}\n\\label{thm:Stability}\n\tA queue node is stable if and only if \\footnote{The condition is necessary, but there are more complex networks (not examined here) where it is not sufficient \\cite{bramson2008stability}.} \n\t\n\t\\begin{equation}\n\t\\label{eqn:Stability}\n\t\\lambda < \\mu\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tLet's prove that if $\\lambda > \\mu$ then the queue would grow to infinity over time.\t\t\n\t\tGiven a time $t$, the number of system jobs $N(t)$, the number of arriving jobs $A(t)$ and the number of departing jobs $D(t)$, we have that\n\t\t\n\t\t\\begin{equation*}\n\t\t\\expected{N(t)}=\\expected{A(t)}-\\expected{D(t)} \\geq t(\\lambda - \\mu)\n\t\t\\end{equation*}\n\t\t\n\t\twhere the inequality holds because the server is not always busy, then the departures at time $t$ are less than $\\mu t$. \n\t\tAt the end, we have that\n\t\t\n\t\t\\begin{equation*}\n\t\t\\lambda > \\mu \\Rightarrow \\lim_{t \\to \\infty} \\expected{N(t)} = \\infty\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}", "meta": {"hexsha": "944c3fdcf194d0b57dfe55a9502ff01fcbf4a887", "size": 8299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/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/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/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": 37.0491071429, "max_line_length": 388, "alphanum_fraction": 0.7318954091, "num_tokens": 2310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6124588051176031}}
{"text": "\\section{Numerical Solution for Burgers' Equation}\n\tLet $\\mathcal{H} = L^2 (0, 1)$. Let's consider an initial value problem for (\\ref{burgers_stochastic}) as follows\n\t\\begin{align}\n\t\\label{burgers_stochastic2}\n\td X(\\xi, t) = \\left[\\alpha \\partial_{\\xi}^2 X(\\xi, t) + \\frac{1}{2} \\partial_\\xi \\left(X^2 (\\xi, t)\\right) \\right] dt + dW_t (\\xi, t), \\hspace{0.2cm} \\xi \\in [0, 1] \n\t\\end{align}\n\tThe boundary condition and its initial condition are respectively \n\t\\begin{align*}\n\t%\\label{IC_burgers_stochastic2}\n\tX(0, t) &= X(1, t) = 0 , \\hspace{0.2cm} t > 0 \\\\\n\tX(\\xi, 0) &= x(\\xi), \\hspace{0.2cm}  x \\in \\mathcal{H},\n\t\\end{align*}\n\twhere $W$ is a cylindrical Wiener process on $\\mathcal{H}$ as was given by \\ref{cylindrical}, associated to a stochastic basis $(\\Omega, \\mathcal{F}, \\mathbb{P}, \\{\\mathcal{F}_t\\}_{t \\geq 0})$, and as usually $\\alpha > 0$ is the viscosity coefficient. \\\\\n\t\n\tUsing the above problem, we will proceed to develop the implementation of the method described in the previous section.\n\t\n\t\\input{burgers_equation/stochastic/numerical_experiments/Implementation}\n\t\\input{burgers_equation/stochastic/numerical_experiments/Initial_Condition}\n\t\\input{burgers_equation/stochastic/numerical_experiments/Numerical_Experiments}\t\n", "meta": {"hexsha": "9c6ab1b7d246730265447a1af811f83f817c04c3", "size": 1242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Numerical_Solution.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/stochastic/numerical_experiments/Numerical_Solution.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/stochastic/numerical_experiments/Numerical_Solution.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": 62.1, "max_line_length": 255, "alphanum_fraction": 0.7133655395, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6124588008586749}}
{"text": "\\section{Approach}\nThe user-based collaborative filtering \\cite{Schafer2007} approach was selected to make movie recommendation for a set of users. This meant that recommendations for an individual user would be based on what similar users have liked that the current user have not yet rated/seen. This is based on the theory that users with similar taste are likely to provide good recommendations to each other. The key here lies in how is similarity between users determined, in this instance the Pearson correlation coefficient measurement \\cite{Wikipedia2017} was selected as the primary method to evaluate similarity, it measures similarity of users by making a linear correlation between what user x and y have rated in terms the score they applied to a set that contains the intersection of movies rated by x and y. The inspiration for this approach was drawn from \\cite{Lead} where this was applied in conjunction with a weighted similarity score that makes sure that users you agree most with are rated higher in terms of movie recommendations.\n\nThis technology was selected based on multiple factors. This included the suggestions made by \\cite{Burke2011} about movie recommendation systems and their domain features including the low risk value of the recommendation, the homogeneous nature of the system and the stability in terms of preference that users have in terms of how much can you rely on previous received information e.g. user's rating history to make future predictions. In terms of technology variation, collaborative filtering provides multiple approaches, e.g. user-based or item based filtering \\cite{Yao}. Both of these have merits, the user-based approach increases in computational cost as the number of users increases. The item based however grows whenever new items are added. In this instance the number of users/items is stable since it is not a live system a choice was made to use the user based approach since the dataset contains 671 users and 9125 movies.\n\n\\section{Required Knowledge}\n\nThe knowledge required for this approach to work include user histories of movie ratings from which user similarity can be based upon. To achieve this a number of public available datasets containing user movie ratings were evaluated. This included the Netflix Prize dataset \\cite{bennett0netflix} , the IMDb academic dataset \\cite{IMDb2017} and the MovieLens \\cite{Harper2015} dataset. From these the MovieLens 100K dataset was chosen as being the most appropriate. The reason for this was that the original Netflix dataset only contained data about when a user rated a movie and not how it was rated. The reason for this was that it was the task for the algorithm to predict the number of reviews and not the actual rating a movie would receive in 2006.  Similar to this the IMDb dataset contained rating of movie's but they weren't tied to any users, meaning that user-based collaborative filtering wasn't feasible. The MovieLens dataset on the other hand doesn't have any of these missing features, meaning that it contained users which had committed at least 20 ratings with a value between 1.0 and 5.0 to different movies. Because of this the MovieLens dataset was selected as the most appropriate to develop this movie recommendation system.\n\nHowever it was discovered later in the process that there has been developed an altered version of the Netflix dataset which provides actual ratings of movies \\cite{Netflix2009}, this was discovered after the MovieLens dataset had been applied.\n\n\\section{Algorithm}\n\tThe pseudo code for the similarity and recommendation functions can be seen in Algorithm \\ref{alg:simpearsons} and \\ref{alg:recommendations}. The similarity function uses Pearson correlation coefficient to determine user similarity on a shared set of movies. The similarity is calculated by basically drawing a line through the rating values of the shared movies. If two users agree on the rating of their shared set of movies the result would be a positive correlation between them, meaning that they are expected to have similar taste. After the similarity has been calculated the recommendation function is run \\ref{alg:recommendations}. This function finds movie recommendations for each user by ranking the unseen movies that similar users have seen. The proposed rating for the unseen movies is proportional to how similar the user who has seen is to the current user, i.e. \\textit{weighted\\_sum[rating.movie\\_id] + = [rating.value * similarity]}. After this has been completed for every user the proposed movies are ranked based on their estimated rating.\n\t\n\tUpon completion the correlation is stored in the user/user \\textit{df\\_similarities} matrix and later persisted in the underlying database for later retrieval when a user requests movie recommendations. See \\cite{Munk2017} for the full implementation.\n\n\t\\begin{algorithm}[H]\n\t\t\\caption{Recommender.sim\\_pearsons()}\n\t\t\\label{alg:simpearsons}\n\t\t\\begin{algorithmic}\n\t\t\t\\STATE $df\\_movies\\_rated[user] \\leftarrow$ Series containing movies rated by user\n\t\t\t\\STATE $df\\_similarities \\leftarrow$ DataFrame consisting of user Id's on the x and y axis\n\t\t\t\n\t\t\t\\FORALL{user\\_x in users}\n\t\t\t\t\\FORALL{user\\_y in users}\n\t\t\t\t\t\\IF{df\\_similarities[user\\_x][user\\_y] is null \\AND user\\_x != user\\_y}\n\t\t\t\t\t\t\\STATE $intersection \\leftarrow$ shared movies between user\\_x and user\\_y\n\t\t\t\t\t\t\\IF{$intersection \\geq 5$}\n\t\t\t\t\t\t\t\\STATE $x\\_ratings \\leftarrow$ list of user\\_x rating values\n\t\t\t\t\t\t\t\\STATE $y\\_ratings \\leftarrow$ list of user\\_y rating values\n\t\t\t\t\t\t\t\\STATE $pearson \\leftarrow personr(x\\_ratings, y\\_ratings)$\n\t\t\t\t\t\t\t\\STATE $df\\_similarities[user\\_x][user\\_y] \\leftarrow pearson$\n\t\t\t\t\t\t\t\\STATE $df\\_similarities[user\\_y][user\\_x] \\leftarrow pearson$\n\t\t\t\t\t\t\\ENDIF\n\t\t\t\t\t\\ENDIF\n\t\t\t\t\\ENDFOR\n\t\t\t\\ENDFOR\n\t\t\t\n\t\t\t\\STATE $Recommender.users\\_ratings\\_similarities \\leftarrow df\\_similarities$\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\n\t\\begin{algorithm}[H]\n\t\t\\caption{Recommender.recommendations() Page 16 \\cite{Lead}}\n\t\t\\label{alg:recommendations}\n\t\t\\begin{algorithmic}\n\t\t\t\\STATE $weighted\\_sum \\leftarrow \\{\\}$\n\t\t\t\\STATE $similarity\\_sum \\leftarrow \\{\\}$\n\t\t\t\\STATE $num\\_rows \\leftarrow length(users)$\n\t\t\t\n\t\t\t\\FORALL{user in users}\n\t\t\t\t\\STATE $df\\_similar\\_users \\leftarrow Recommender.users\\_ratings\\_similarities[user.id]$\n\t\t\t\t\\STATE $df\\_similar\\_users \\leftarrow $ Remove users that aren't similar.\n\t\t\t\t\\STATE $user\\_movies \\leftarrow $ user rated movie ids\n\t\t\t\t\\FORALL{target\\_user\\_id, similarity in df\\_similar\\_users}\n\t\t\t\t\t\\IF{$similarity \\textgreater 0$}\n\t\t\t\t\t\t\\FORALL{rating in users[target\\_user\\_id].ratings}\n\t\t\t\t\t\t\t\\IF{rating.movie\\_id not in user\\_movies}\n\t\t\t\t\t\t\t\t\\STATE $weighted\\_sum.setdefault(rating.movie, 0) $\n\t\t\t\t\t\t\t\t\\STATE $weighted\\_sum[rating.movie\\_id]\\  + =\\ (rating.value * similarity)$\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\\STATE $similarity\\_sum.setdefault(rating.movie\\_id, 0)$\n\t\t\t\t\t\t\t\t\\STATE $similarity\\_sum[rating.movie_id]\\ + =\\ similarity$\n\t\t\t\t\t\t\t\\ENDIF\n\t\t\t\t\t\t\\ENDFOR\n\t\t\t\t\t\\ENDIF\n\t\t\t\t\\ENDFOR\n\t\t\t\n\t\t\t\t\\STATE Rank the ratings, users who agree alot with the current user will have their ratings affect the final score the most\n\t\t\t\t\\STATE $rankings \\leftarrow [(w\\_score / similarity\\_sum[movie\\_id], movie\\_id)$\n\t\t\t\t\\bindent\n\t\t\t\t    \\STATE $for\\ movie\\_id,\\ w\\_score\\ in\\ weighted\\_sum.items()]$  \n\t\t\t\t\\eindent\n\t\t\t\t\\STATE $rankings.sort()$\n\t\t\t\t\\STATE $rankings.reverse()$\n\t\t\t\t\\STATE $Recommender.recoms[user] \\leftarrow rankings$\n\t\t\t\\ENDFOR\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\n\n\\section{Evaluation \\& Reflection}\n\nTo evaluate whether the recommendations made by the correlation filter was actually usable to the users a series of offline tests were conducted. This included randomly splitting the set of user ratings into a training and testing set in of either 60/40 or 80/20 distribution. This was then used to apply the training dataset to the recommendation engine to evaluate whether the engine would be accurately be able to predict the rating contained in the test data Beyond this the amount of minimum shared rated movies were also varied between either above 0 or equal to and above 5. The hypothesis was that by sharing more movie ratings the algorithm would be able to better predict the missing ratings.\n\nTo evaluate the precision of the recommendation predictions the root mean squared error(RMSE) was calculated to determine the accuracy of the predicted ratings. The reason for this was that as described in \\cite{Schafer2007} the RMSE emphasizes large errors and penalizes the performance value by how far each individual prediction is from the true value/rating.\n\nThe results of the testing can be seen in \\ref{table:results}. The results are from running the recommendation test 20 times for each configuration on the MovieLens 100K dataset and extracting the top 100 recommendations. The reason for multiple runs is that because the testing data is a randomly selected sample that by chance could extract a very good set of users. i.e they have rated more movies than the average.\n\nAs Table \\ref{table:results} shows the mean RMSE improves when the number of required shared movies is increased. T-tests at the 1\\% level also shows that there is a significant difference in the results gathered i.e. (p-value = 0,00004) for the 80/20 configurations and (p-value = 4.43e-13) for the 60/40's. However, when looking the percentage between the training/test distributions it indicates no significant difference in the achieved predictions with (p-value = 0.58) between the 60/40 1 or more shared movies vs the 80/20's configuration or (p-value = 0.13) with 60/40 5 or more shared movies vs the 80/20's.\n\n\\begin{table}[H]\n\t\\caption{\\label{table} Testing Results}\n\t\\centering\n\t\\label{table:results}\n\t\\begin{tabular}{c c c c}\n\t\t\\hline\n\t\tTrain \\% & Test \\% & Shared Movies & Mean RMSE  \\\\\n\t\t\\hline\n\t\t60 & 40 & 1 or more &  1,58840 \\\\\n\t\t60 & 40 & 5 or more &  1,23029 \\\\\n\t\t80 & 20 & 1 or more &  1,54424 \\\\\n\t\t80 & 20 & 5 or more &  1,29246 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table} \n\nReflecting on these results it shows that in terms of the configuration parameters for the user-based collaborative filtering approach using the Pearson correlation coefficient similarity function the results supports the proposed hypothesis. I.e that an increase in shared movies has a significant impact on the RMSE with a lower prediction average which means that the prediction ability of the system improves. Whether the recommended movies are actually engaging and interesting to the users is another matter and can't be claimed based on these results.\n\nIn terms of overall drawbacks of the user-based approach, whenever a user adds a new rating that users recommendations has to be recalculated. This could pose a significant query time whenever a user attempts to retrieve recommendations. To mitigate this the current recommendations are pre-calculated when the system is launched, however this does mean that if a user rates a new item it won't be reflected in the recommendations before the system is relaunched. To counter this in general the item-based approach does seem preferable in that the similarity of each item can be precomputed, hence whenever a user commits a new rating the recommendations can be updated subsequently.", "meta": {"hexsha": "11c6e9e9559e88f3707664985b5d86f12da45f1b", "size": 11239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/datawrangling_body_conf.tex", "max_stars_repo_name": "rasmunk/set11521cw2", "max_stars_repo_head_hexsha": "602332583921c700ffeee28cef421d55268ca218", "max_stars_repo_licenses": ["MIT"], "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/datawrangling_body_conf.tex", "max_issues_repo_name": "rasmunk/set11521cw2", "max_issues_repo_head_hexsha": "602332583921c700ffeee28cef421d55268ca218", "max_issues_repo_licenses": ["MIT"], "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/datawrangling_body_conf.tex", "max_forks_repo_name": "rasmunk/set11521cw2", "max_forks_repo_head_hexsha": "602332583921c700ffeee28cef421d55268ca218", "max_forks_repo_licenses": ["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.1727272727, "max_line_length": 1248, "alphanum_fraction": 0.7762256429, "num_tokens": 2621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6124587971818981}}
{"text": "\\chapter{Constant functions}\n\\section{Defined on $\\mdr$}\n\\begin{lemma}\nLet $f:\\mdr \\rightarrow \\mdr$, $f(x) := c$ with $c \\in \\mdr$ be a constant function.\n\nThen $(x_P, f(x_P))$ is the only point on the graph of $f$ with\nminimal distance to $P$.\n\\end{lemma}\n\nThe situation can be seen in Figure~\\ref{fig:constant-min-distance}.\n\\begin{figure}[htp]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            legend pos=north west,\n            legend cell align=left,\n            axis x line=middle,\n            axis y line=middle,\n            grid = major,\n            width=0.8\\linewidth,\n            height=8cm,\n            grid style={dashed, gray!30},\n            xmin=-5, % start the diagram at this x-coordinate\n            xmax= 5, % end   the diagram at this x-coordinate\n            ymin= 0, % start the diagram at this y-coordinate\n            ymax= 3, % end   the diagram at this y-coordinate\n            axis background/.style={fill=white},\n            xlabel=$x$,\n            ylabel=$y$,\n            tick align=outside,\n            minor tick num=-3,\n            enlargelimits=true,\n            tension=0.08]\n          \\addplot[domain=-5:5, thick,samples=50, red] {1};\n          \\addplot[domain=-5:5, thick,samples=50, green] {2};\n          \\addplot[domain=-5:5, thick,samples=50, blue, densely dotted] {3};\n          \\addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};\n          \\addplot[blue, mark = *, nodes near coords=$P_{h,\\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(2, 3)};\n          \\addplot[green, mark = x, nodes near coords=$P_{g,\\text{min}}$,every node near coord/.style={anchor=120}] coordinates {(2, 2)};\n          \\addplot[red, mark = *, nodes near coords=$P_{f,\\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(2, 1)};\n          \\draw[thick, dashed] (axis cs:2,0) -- (axis cs:2,3);\n          \\addlegendentry{$f(x)=1$}\n          \\addlegendentry{$g(x)=2$}\n          \\addlegendentry{$h(x)=3$}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Three constant functions and their points with minimal distance}\n    \\label{fig:constant-min-distance}\n\\end{figure}\n\n\\begin{proof}\nThe point $(x, f(x))$ with minimal distance can be calculated directly:\n\\begin{align}\n    d_{P,f}(x) &= \\sqrt{(x - x_P)^2 + (f(x) - y_P)^2}\\\\\n               &= \\sqrt{(x^2 - 2x_P x + x_P^2) + (c^2 - 2 c y_P + y_P^2)} \\\\\n               &= \\sqrt{x^2 - 2 x_P x + (x_P^2 + c^2 - 2 c y_P + y_P^2)}\\label{eq:constant-function-distance}\\\\\n \\xRightarrow{\\text{Theorem}~\\ref{thm:fermats-theorem}} 0 &\\stackrel{!}{=} (d_{P,f}(x)^2)'\\\\\n              &= 2x - 2x_P\\\\\n  \\Leftrightarrow x &\\stackrel{!}{=} x_P\n\\end{align}\n\nSo $(x_P,f(x_P))$ is the only point with minimal distance to $P$. $\\qed$\n\\end{proof}\n\nThis result means:\n\n\\[S_0(f, P) = \\Set{x_P} \\text{ with } P = (x_P, y_P)\\]\n\\clearpage\n\n\\section{Defined on a closed interval $[a,b] \\subseteq \\mdr$}\n\\begin{theorem}[Solution formula for constant functions]\nLet $f:[a,b] \\rightarrow \\mdr$, $f(x) := c$ with $a,b,c \\in \\mdr$ and\n$a \\leq b$ be a constant function.\n\nThen the point $(x, f(x))$ of $f$ with minimal distance to $P$ is\ngiven by:\n\\[\\underset{x\\in [a,b]}{\\arg \\min d_{P,f}(x)} = \\begin{cases}\n S_0(f,P) &\\text{if } S_0(f,P) \\cap [a,b] \\neq \\emptyset \\\\\n  \\Set{a} &\\text{if } S_0(f,P) \\ni x_P < a\\\\\n  \\Set{b} &\\text{if } S_0(f,P) \\ni x_P > b\n    \\end{cases}\\]\n\\end{theorem}\n\n\\begin{figure}[htp]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            legend pos=north west,\n            legend cell align=left,\n            axis x line=middle,\n            axis y line=middle,\n            grid = major,\n            width=0.8\\linewidth,\n            height=8cm,\n            grid style={dashed, gray!30},\n            xmin=-5, % start the diagram at this x-coordinate\n            xmax= 5, % end   the diagram at this x-coordinate\n            ymin= 0, % start the diagram at this y-coordinate\n            ymax= 3, % end   the diagram at this y-coordinate\n            axis background/.style={fill=white},\n            xlabel=$x$,\n            ylabel=$y$,\n            tick align=outside,\n            minor tick num=-3,\n            enlargelimits=true,\n            tension=0.08]\n          \\addplot[domain=-5:-2, thick,samples=50, red] {1};\n          \\addplot[domain=-1:3, thick,samples=50, green] {1.5};\n          \\addplot[domain=3:5, thick,samples=50, blue, densely dotted] {3};\n          \\addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};\n\n          \\addplot[blue, mark = *, nodes near coords=$P_{h,\\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(3, 3)};\n          \\addplot[green, mark = x, nodes near coords=$P_{g,\\text{min}}$,every node near coord/.style={anchor=120}] coordinates {(2, 1.5)};\n          \\addplot[red, mark = *, nodes near coords=$P_{f,\\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(-2, 1)};\n\n          \\draw[thick, dashed] (axis cs:2,1.5) -- (axis cs:2,2);\n          \\draw[thick, dashed] (axis cs:2,2) -- (axis cs:-2,1);\n          \\draw[thick, dashed] (axis cs:2,2) -- (axis cs:3,3);\n          \\addlegendentry{$f(x)=1, D = [-5,-2]$}\n          \\addlegendentry{$g(x)=1.5, D = [-1,3]$}\n          \\addlegendentry{$h(x)=3, D = [3,5]$}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Three constant functions and their points with minimal distance}\n    \\label{fig:constant-min-distance-closed-intervall}\n\\end{figure}\n\n\\begin{proof}\n\\begin{align}\n    \\underset{x\\in[a,b]}{\\arg \\min d_{P,f}(x)} &= \\underset{x\\in[a,b]}{\\arg \\min d_{P,f}(x)^2}\\\\\n   &=\\underset{x\\in[a,b]}{\\arg \\min} \\big ((x-x_P)^2 + \\overbrace{(y_P^2 - 2 y_P c + c^2)}^{\\text{constant}} \\big )\\\\\n   &=\\underset{x\\in[a,b]}{\\arg \\min} (x-x_P)^2\n\\end{align}\n\nwhich is optimal for $x = x_P$, but if $x_P \\notin [a,b]$, you want\nto make this term as small as possible. It gets as small as possible when\n$x$ is as similar to $x_p$ as possible. This yields directly to the\nsolution formula.$\\qed$\n\\end{proof}\n", "meta": {"hexsha": "4e0f690d1ddd6705636b60da6e360e4897190d8f", "size": 6070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/math-minimal-distance-to-cubic-function/constant-functions.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": "documents/math-minimal-distance-to-cubic-function/constant-functions.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": "documents/math-minimal-distance-to-cubic-function/constant-functions.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": 43.3571428571, "max_line_length": 139, "alphanum_fraction": 0.5741350906, "num_tokens": 1972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.612434598374562}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\n  Luck is the residue of design\n    \\byline{Branch Rickey}\n    \\end{inspiration}\n\n    \\section{Terminology}\n\n    \\begin{problem}\n      Define the \\textbf{residue} of $f$ at the point $z$, which we write $\\Res(f,z)$.\n      \\end{problem}\n      \\begin{solution}\n      The residue of $f:U\\mapsto \\R$ is \n      \\[\n      \\lim_{\\epsilon\\to 0^+} \\frac{1}{2\\pi i}\\int_{\\gamma_\\epsilon} \\frac{f(w)}{w-z} dz\n      \\]\n      Where $\\gamma_\\epsilon:[0, 2\\pi ] \\to \\C$ is defined as $\\gamma(t) = \\epsilon e^{it}$.\n\n      Equivalently, it is the coefficient of the $\\frac{1}{w-z}$ term in the Laurent expansion of $f$ at $z$.\n      \\end{solution}\n      \\section{Numericals}\n\n      \\begin{problem}\n        Evaluate $\\Res(f,z)$ for the function $f(z) = \\displaystyle\\frac{e^z}{z^2-1}$.\n        \\end{problem}\n        \\begin{solution}\n        If $z_0\\neq \\pm 1$, then the function is analytic divided by analytic nonzero, so $\\Res(f,z_0)=0$. We can directly compute the other two cases by multiplying by $z-z_0$ and evaluating at $z_0$:\n        \\begin{gather*}\n        \\Res(f,1) = f(z)(z-1)|_{z=1} = \\frac{e^z}{z+1}|_{z=1} = \\frac{e}{2}\\\\\n        \\Res(f,-1) = f(z)(z+1)|_{z=-1} = \\frac{e^z}{z-1}|_{z=-1} = -\\frac{1}{2e}\n        \\end{gather*}\n        \\end{solution}\n        \\begin{problem}\\label{residues-all-one}\n        Evaluate $\\Res(f,z)$ for the\n          function $f(z) = \\pi \\cot (\\pi z)$.\n          \\end{problem}\n          \\begin{solution}\n          The only points where the residue might be nonzero are where the denominator is zero, that is, where\n          \\[\n              0=\\sin \\pi z = \\frac{e^{i\\pi z}+e^{-i\\pi z}}{2},\n              \\]\n              so points where $z = k$ for $k\\in \\N$.\n\n              Now we can compute the residue at the point $k$ using L'Hopitals rule:\n              \\[\n              \\lim_{z\\to k} \\pi\\frac{(z-k\\pi)\\cos \\pi z}{\\sin \\pi z}\\big|_{z=k} = \\lim_{z\\to k}\\pi \\frac{\\cos (\\pi z) -  (z-k\\pi)\\pi \\sin \\pi z}{\\pi\\cos \\pi z}\\big|_{z=k} = \\frac{\\pi(-1)^k}{\\pi (-1)^k} = 1\n              \\]\n              \\end{solution}\n              \\begin{problem}\\label{residue-coth}Compute $\\Res(f,\\pm bi)$ for the\n                function\n                  \\[\n                      f(z) = \\frac{\\pi \\cot(\\pi z)}{z^2 + b^2}.\n                        \\]\n                        \\end{problem}\n                        \\begin{solution}\n                        For any value of $b$ except for when $bi\\in \\Z$, a simple formula gives the answer:\n                        \\[\n                        Res(f, \\pm bi) = \\lim_{z\\to \\pm bi}\\frac{\\pi \\cot(\\pi z)}{z \\pm bi} =\\frac{\\pi \\cot(\\pm \\pi bi)}{\\pm2bi}\n                        \\]\n                        Otherwise, let $k\\in \\Z = bi$. \n                        we will write out each term as a power series at $k$ and nab the $\\frac{1}{z\\mp bi}$ term.\n\n                        Using a few steps of polynomial long division, we first compute the power series for $\\frac{1}{\\sin z}$ at $\\pm k$ as \n                        \\[\\frac{1}{(z\\mp k)} + \\frac{(z\\mp k)}{6} + O((z\\mp k)^3).\\]\n                        (This formula can be verified by multiplication with the power series for $\\sin (z\\mp k) = (z\\mp k) - \\frac{(z\\mp n)^3}{6} + O(z^5)$, I don't want to latex out polynomial long division.)\n\n                        Next we can compute the power series of $\\frac{1}{z\\pm k}$ at $z\\pm k$. Let $w=z\\mp k$\n                        \\[\n                        \\frac{1}{z\\pm k} = \\frac{1}{w\\pm 2k} = \\frac{\\mp\\frac{1}{2k}}{1-\\frac{w}{\\pm 2k}}= \\mp \\frac{1}{2k}\\sum_{n=0}^\\infty \\frac{w^n}{(\\pm 2k)^n} = \\mp \\frac{1}{2k}\\sum_{n=0}^\\infty \\frac{(z\\mp k)^n}{(\\pm 2k)^n}\n                        \\]\n\n                        Unless $k=0$, in which case the power series of $\\frac{1}{z}$ is $\\frac{1}{z}$.\n\n                        Knowing the series for $\\cos z$, we can write $f$ as a product of power series,\n\n                        \\begin{align*}\n                        \\frac{\\pi\\cot(\\pi (z\\mp k))}{z^2 + b^2} &= \\pi\\cos(\\pi (z\\mp k))\\frac{1}{\\sin(\\pi (z\\mp k))}\\frac{1}{z\\pm k}\\frac{1}{z\\mp k} \\\\\n                        &= \\pi\\left(1 + O((z\\mp k)^2\\right)\\left(\\frac{1}{\\pi(z\\mp k)} - \\frac{\\pi(z\\mp k)}{6} + O((z\\mp k)^3)\\right)\\\\&\\times \\left(\\mp\\frac{1}{2k}\\sum_{n=0}^\\infty \\frac{(z\\mp k)^{n-1}}{(\\pm 2k)^{n}}\\right) \\\\\n                        &= \\pi(1)\\left(\\frac{1}{\\pi(z\\mp k)}\\right)\\left(\\frac{\\mp 1}{2k(z\\mp k)} - \\frac{1}{4k^2}\\right) + O(1)\\\\\n                        &= \\frac{1}{\\pm 2k (z\\mp k)^2} - \\frac{1}{4k^2(z\\mp k)}+ O(1)\n                        \\end{align*}\n                        The residue is the coefficient of $\\frac{1}{z\\mp k}$. Since $bi=k$, it is  $-\\frac{1}{4(bi)^2}=\\frac{1}{4b^2}$.\n\n                        If $k=0$, then we can replace the last term in the big product above with $\\frac{1}{z}$ to get a laurant series of $\\frac{1}{z^2} + O(1)$, and so the residue is 0.\n                        \\end{solution}\n\n\n                        \\begin{problem}\n                          Evaluate the integrals\n                            \\[\n                                \\int_{-\\infty}^\\infty \\frac{\\sin x}{1+x^2} \\, dx \\mbox{ and }\n                                    \\int_{-\\infty}^\\infty \\frac{\\cos x}{1+x^2} \\, dx.\n                                      \\]\n                                      \\end{problem}\n                                      \\begin{solution}\n                                      Since $e^{ix} = \\cos x  + i \\sin x$, we can just integrate\n                                      \\[\n                                      \\int_\\infty^\\infty \\frac{e^{iz}}{1+z^2} dz\n                                      \\]\n                                      and the real part will be the cos integral, the imaginary the sin integral. We can integrate over the following curve:\n\n                                      \\begin{tikzpicture}\n                                      \\draw [<->] (-4, 0) -- (4, 0);\n                                      \\draw [<->] (0, -4) -- (0, 4);\n                                      \\node [below] at (3, 0) {$R$};\n                                      \\node [below] at (1, 0) {$\\gamma_1$};\n                                      \\node [right] at (2, 2.5) {$\\gamma_2$};\n                                      \\draw (0,1) circle[radius=2pt];\n                                      \\node [right] at (0, 1) {$\\Res(\\frac{e^{iz}}{1+z^2}, i)$};\n                                      \\begin{scope}[very thick,decoration={\n                                          markings,\n                                              mark=at position 0.5 with {\\arrow{>}}}\n                                                  ] \n                                                  \\draw[postaction={decorate}] (-3,0) -- (3,0);\n                                                  \\draw[postaction={decorate}] (3, 0) arc [radius=3, start angle=0, end angle=180];\n                                                  \\end{scope}\n                                                  \\end{tikzpicture}\n\n                                                  We can compute the integral over the curve $\\gamma_2$.\n                                                  \\begin{align*}\n                                                  \\int_{\\gamma_2} \\frac{e^{iz}}{1+z^2}dz  = \\int_0^\\pi \\frac{e^{iRcos(\\theta) - Rsin(\\theta)d\\theta}iRe^{i\\theta}}{1+R^2e^{2i\\theta}}d\\theta\\\\\n                                                  \\end{align*}\n                                                  Note that the $e^{iRcos(\\theta) - Rsin(\\theta)}$ term is never more than $1$ in magnitude, so\n                                                  \\begin{align*}\n                                                  \\abs{\\lim_{R\\to\\infty} \\int_{\\gamma_2} \\frac{e^{iz}}{1+z^2}dz} \\leq \\lim_{R\\to\\infty} \\int_0^\\pi \\frac{R}{R^2+1}d\\theta \\leq \\lim_{R\\to\\infty} \\frac{\\pi}{R} = 0\n                                                  \\end{align*}\n\n                                                  By the residue thoerem, the value of the integral around the contour is equal to the value of the residue at $i$, so the value of the integral on the real line is equal to the residue at $i$ times $2\\pi i$.\n\n                                                  \\begin{align*}\n                                                  \\int_\\infty^\\infty \\frac{e^{iz}}{1+z^2} dz &= 2\\pi i \\Res(\\frac{e^{iz}}{1+z^2}, i)\\\\\n                                                  &= 2\\pi i\\lim_{z\\to i} \\frac{e^{iz}(z-i)}{1+z^2} \\\\\n                                                  &= 2\\pi i\\lim_{z\\to i} \\frac{e^{iz}}{z+i} = \\frac{\\pi}{e}\n                                                  \\end{align*}\n\n                                                  Therefore, \n                                                    \\[\n                                                        \\int_{-\\infty}^\\infty \\frac{\\sin x}{1+x^2} \\, dx = 0 \\mbox{ and }\n                                                            \\int_{-\\infty}^\\infty \\frac{\\cos x}{1+x^2} \\, dx =  \\frac{\\pi}{e}\n                                                              \\] \n                                                              \\end{solution}\n                                                              \\begin{problem}\n                                                                For a real number $\\lambda \\in (0,1)$, evaluate\n                                                                  \\[\n                                                                      \\int_{-\\infty}^\\infty \\frac{e^{\\lambda x}}{1 + e^x} \\, dx.\n                                                                        \\]\n                                                                        \\end{problem}\n                                                                        \\begin{solution}\n                                                                        We shall evaluate the integral on the following contour:\\\\\n                                                                        \\scalebox{1.5}{\n                                                                        \\begin{tikzpicture}\n                                                                        \\draw [<->] (-4, 0) -- (4, 0);\n                                                                        \\draw [<->] (0, -1) -- (0, 4);\n                                                                        \\node [below] at (-4, 0) {$-R$};\n                                                                        \\node [below] at (4, 0) {$R$};\n                                                                        \\node [below] at (1, 0) {$\\gamma_1$};\n                                                                        \\node [above] at (-1, 3) {$\\gamma_2$};\n                                                                        \\node [above] at (0, 3) {$2\\pi i$};\n                                                                        \\node [right] at (4, 1.5) {$\\gamma_3$};\n                                                                        \\node [right] at (-4, 1.5) {$\\gamma_4$};\n                                                                        \\draw (0,1.5) circle[radius=2pt];\n                                                                        \\node [right] at (0, 1.5) {$\\Res( \\frac{e^{\\lambda x}}{1 + e^x}, \\pi)$};\n                                                                        \\begin{scope}[very thick,decoration={\n                                                                            markings,\n                                                                                mark=at position 0.5 with {\\arrow{>}}}\n                                                                                    ] \n                                                                                    \\draw[postaction={decorate}] (-4,0) -- (4,0);\n                                                                                    \\draw[postaction={decorate}] (4,0) -- (4,3);\n                                                                                    \\draw[postaction={decorate}] (4,3) -- (-4,3);\n                                                                                    \\draw[postaction={decorate}] (-4,3) -- (-4,0);\n                                                                                    \\end{scope}\n                                                                                    \\end{tikzpicture}\n                                                                                    }\n                                                                                    \\begin{align*}\n                                                                                    \\int_{\\gamma_1}dz +\\int_{\\gamma_2}dz &= \\int_{\\gamma_1}dz -\\int_{-\\gamma_2}dz\\\\\n                                                                                    &= \\int_{-R}^R \\frac{e^{\\lambda x}}{1+e^x} - \\frac{e^{\\lambda (x+2\\pi i)}}{1+e^{x+2\\pi i}} dx\\\\\n                                                                                    &= \\int_{-R}^R \\frac{e^{\\lambda x} - e^{\\lambda x +\\lambda2\\pi i}}{1+e^x}dx\\\\\n                                                                                    &= (1 -e^{\\lambda2\\pi i})\\int_{-R}^R \\frac{e^{\\lambda x}}{1+e^x}dx\\\\\n                                                                                    &= (1 -e^{\\lambda2\\pi i})\\int_{\\gamma_1}dz \n                                                                                    \\end{align*}\n                                                                                    \\begin{align*}\n                                                                                    \\abs{\\int_{\\gamma_3}dz} &= \\abs{\\int_0^{2\\pi i} \\frac{ie^{\\lambda R + \\lambda ti}dt}{1 + e^{R+ti}}}\\\\\n                                                                                    &= \\abs{\\int_0^{2\\pi} \\frac{e^{\\lambda R + \\lambda ti} dt}{1 + e^{R+ti}}}\\\\\n                                                                                    &\\leq \\abs{\\int_0^{2\\pi} \\frac{e^{\\lambda R} dt}{e^{R}}} = 2\\pi e^{R(\\lambda - 1)} \\underset{R\\to\\infty}{\\to} 0\n                                                                                    \\end{align*}\n                                                                                    \\begin{align*}\n                                                                                    \\abs{\\int_{\\gamma_4}dz} &= \\abs{\\int_0^{2\\pi} \\frac{-ie^{-\\lambda R + \\lambda ti}dt}{1 + e^{-R+ti}}}\\\\\n                                                                                    &\\leq 2\\pi \\sup \\abs{\\frac{e^{\\lambda R+\\lambda ti}}{1 + e^{R+ti}}}\\\\\n                                                                                    &\\leq 2\\pi \\abs{\\frac{e^{\\lambda R}}{1 + e^{R}}} \\underset{R\\to -\\infty}{\\to} \\frac{0}{1} = 0\n                                                                                    \\end{align*}\n                                                                                    Now by the residue theorem, \n                                                                                    \\[\n                                                                                    (1-e^{\\lambda 2\\pi i})\\int_{\\gamma_1}dz= \\int_{\\gamma_1+\\gamma_2+\\gamma_3+\\gamma_4} dz  =  2\\pi i \\Res(\\frac{e^{\\lambda x}}{1+e^x}, i\\pi)\n                                                                                    \\]\n\n                                                                                    We can compute the residue at the simple pole \n                                                                                    \\[\n                                                                                     \\Res(\\frac{e^{\\lambda x}}{1+e^x}, i\\pi) = \\lim_{x\\to i\\pi} \\frac{e^{\\lambda x}(x-i\\pi)}{1-e^x}\\big|_{x=i\\pi} = \\frac{\\lambda e^{\\lambda x}(x-i\\pi) + e^{\\lambda x}}{-e^x}|_{x=i\\pi} = e^{i\\pi\\lambda}\n                                                                                     \\]\n\n                                                                                     And now we can use the last two formulas to solve for the desired integral:\n                                                                                     \\[\n                                                                                     \\int_{\\gamma_1}dz = \\frac{2\\pi i e^{i\\pi \\lambda}}{1 - e^{2\\pi i \\lambda}}\n                                                                                     \\]\n                                                                                     \\end{solution}\n                                                                                     \\begin{problem}\n                                                                                       Evaluate the integral $\\displaystyle\\int_{0}^{2\\pi} \\frac{1}{3 + \\sin^2 x} \\, dx$.\n                                                                                       \\end{problem}\n                                                                                       \\begin{solution}\n                                                                                       Rewrite $\\sin x$ as follows:\n                                                                                       \\[\n                                                                                       \\sin x = \\frac{e^{ix} - \\frac{1}{e^{ix}}}{2i}\n                                                                                       \\]\n\n                                                                                       Now let $\\gamma=e^{ix}$ be the positively oriented unit circle.\n                                                                                       \\begin{align*}\n                                                                                       \\int_{0}^{2\\pi} \\frac{dx}{3 + \\sin^2 x} \\, dx &= \n                                                                                       \\int_{0}^{2\\pi} \\frac{dx}{3 + \\left(\\frac{e^{ix} - \\frac{1}{e^{ix}}}{2i}\\right)^2}\\\\\n                                                                                       &= \\int_{0}^{2\\pi} \\frac{ie^{ix}dx}{ie^{ix}\\left(3 - \\left(\\frac{e^{ix} - \\frac{1}{e^{ix}}}{2}\\right)^2\\right)}\\\\\n                                                                                       &= \\int_\\gamma \\frac{dz}{iz\\left(3 - \\left(\\frac{z - \\frac{1}{z}}{2}\\right)^2\\right)}\n                                                                                       \\end{align*}\n\n                                                                                       We can now try to apply the residue theorem. We need to find poles of the function \n                                                                                       $f(z) = \\frac{-i}{z(3 - (\\frac{z - \\frac{1}{z}}{2})^2)}$ in the unit circle.\n                                                                                       $z=0$ is a removable discontinuity since the second factor grows as fast as $\\frac{1}{z^2}$ there, so the only poles are roots of the second factor. We can solve it with the quadratic formula and expand\n                                                                                       \\begin{align*}\n                                                                                       3 - (\\frac{z - \\frac{1}{z}}{2})^2 &= \n                                                                                       \\frac{4}{z^2}\\left(3z^2 - (\\frac{z^2 - 1}{2})^2\\right)\\\\\n                                                                                       &= \\frac{4}{z^2}\\left(  (z-(2-\\sqrt{3}))(z-(2+\\sqrt{3}))(z-(-2-\\sqrt{3}))(z-(-2+\\sqrt{3}))\\right)\n                                                                                       \\end{align*}\n\n                                                                                       The roots in the unit circle can be found with the quadratic formula as $\\pm (2-\\sqrt{3})$.\n                                                                                       \\begin{align*}\n                                                                                       \\Res(f, 2-\\sqrt{3}) &= \n                                                                                       \\frac{-4iz}{(z-(-2+\\sqrt{3}))(z-(2+\\sqrt{3}))(z-(-2-\\sqrt{3}))}\\big|_{z=2-\\sqrt{3}}\\\\\n                                                                                       &= \\frac{-4iz}{2z\\cdot 4\\cdot 2\\sqrt{3}} = \\frac{-i}{4\\sqrt{3}}\n                                                                                       \\end{align*}\n                                                                                       \\begin{align*}\n                                                                                       \\Res(f, 2+\\sqrt{3}) &= \n                                                                                       \\frac{-4iz}{(z-(2-\\sqrt{3}))(z-(2+\\sqrt{3}))(z-(-2-\\sqrt{3}))}\\big|_{z=-2+\\sqrt{3}}\\\\\n                                                                                       &= \\frac{-4iz}{2z\\cdot 4\\cdot 2\\sqrt{3}} = \\frac{-i}{4\\sqrt{3}}\n                                                                                       \\end{align*}\n                                                                                       Now we can finally apply the residue formula to obtain the value of the desired integral:\n                                                                                       \\begin{align*}\n                                                                                       2\\pi i \n                                                                                       \\left(\\frac{-i}{4\\sqrt{3}}+ \\frac{-i}{4\\sqrt{3}}\\right) = \\frac{\\pi}{\\sqrt{3}}\n                                                                                       \\end{align*}\n\n                                                                                       \\end{solution}\n                                                                                       \\begin{problem}\n                                                                                         Evaluate the integral $\\displaystyle \\int_0^\\pi \\log \\sin x \\, dx$.\n                                                                                         \\end{problem}\n                                                                                         \\begin{solution}\n                                                                                         \\begin{align*}\n                                                                                         \\int_0^\\pi \\log \\sin x dx &= \\int_0^\\pi \\log \\abs{\\frac{e^{ix} - e^{-ix}}{2i}} dx\\\\\n                                                                                         &= \\int_0^\\pi \\log \\abs{\\frac{(e^{ix})(e^{ix} - e^{-ix})}{i}} dx - \\int_0^\\pi \\log 2 dx \\\\\n                                                                                         &= \\int_0^\\pi \\log \\abs{1 - e^{2ix}} dx - \\pi \\log 2\n                                                                                         \\int_0^\\pi \\log \\sin x dx &= \\frac{1}{2}\\lim_{r^- \\to 1}\\int_0^{2\\pi} \\log \\abs{1 - re^{ix}} dx - \\pi \\log 2\\\\\n                                                                                         \\end{align*}\n                                                                                         Now we use the fact that for functions $f$ holomorphic on a disk of radius $r$ about the point $z_0$, \n                                                                                         \\[\n                                                                                         f(z_0) = \\frac{1}{2\\pi}\\int_0^{2\\pi} f(z_0+re^{i\\theta})d\\theta\n                                                                                         \\]\n                                                                                         Applying this to $z_0=1, f=\\log$:\n                                                                                         \\begin{align*}\n                                                                                         \\lim_{r^- \\to 1}\\int_0^{2\\pi} \\log (1 - e^{ix}) dx &= \\lim_{r^-\\to 1} \\log 1 = 0\n                                                                                         \\end{align*}\n                                                                                         And we conclude that\n                                                                                         \\[\n                                                                                         \\int_0^\\pi \\log \\sin x \\, dx = -\\pi\\log 2\n                                                                                         \\]\n                                                                                         \\end{solution}\n                                                                                         \\begin{problem}\n                                                                                           Evaluate the integral $\\displaystyle\\int_{-\\infty}^{\\infty} \\frac{1-x}{1-x^7} \\, dx$.\n                                                                                           \\end{problem}\n                                                                                           \\begin{solution}\n                                                                                           Let $f = \\frac{1-x}{1-x^7} = \\frac{1}{1+x+x^2+x^3+x^4+x^5+x^6}$ and $\\zeta$ be the 7th root of unity with the smallest counterclockwise nonzero angle to the positive x axis.\n                                                                                           We will compute the integral on the half circle contour as $R\\to\\infty$.\n\n                                                                                           \\begin{tikzpicture}\n                                                                                           \\draw [<->] (-4, 0) -- (4, 0);\n                                                                                           \\draw [<->] (0, -.2) -- (0, 4);\n                                                                                           \\node [below] at (3, 0) {$R$};\n                                                                                           \\node [below] at (1, 0) {$\\gamma_1$};\n                                                                                           \\node [right] at (2, 2.5) {$\\gamma_2$};\n                                                                                           \\draw (1.247, 1.564) circle[radius=2pt];\n                                                                                           \\draw (-.445, 1.95) circle[radius=2pt];\n                                                                                           \\draw (-1.802, 0.868) circle[radius=2pt];\n                                                                                           \\node [below] at (1.247, 1.564) {$\\Res(f, \\zeta)$};\n                                                                                           \\node [right] at (-.445, 1.95) {$\\Res(f, \\zeta^2)$};\n                                                                                           \\node [above] at (-1.802, 0.868) {$\\Res(f, \\zeta^3)$};\n                                                                                           \\begin{scope}[very thick,decoration={\n                                                                                               markings,\n                                                                                                   mark=at position 0.5 with {\\arrow{>}}}\n                                                                                                       ] \n                                                                                                       \\draw[postaction={decorate}] (-3,0) -- (3,0);\n                                                                                                       \\draw[postaction={decorate}] (3, 0) arc [radius=3, start angle=0, end angle=180];\n                                                                                                       \\end{scope}\n                                                                                                       \\end{tikzpicture}\n\n                                                                                                       The value of the integral on the outer curve $\\gamma_2$ is 0:\n                                                                                                       \\[\n                                                                                                       \\int_{\\gamma_2} \\frac{1-z}{1-z^7} \\leq \\pi R \\sup_{|z|=R} \\frac{\\abs{1-z}}{\\abs{1-z^7}} \\in O(R^{-6}) \n                                                                                                       \\]\n                                                                                                       Using the residue theorem, we can get the value of the integral by multiplying the residues by $2\\pi i$. Unfortunately the residues are nasty to compute, so we will have a nasty expression.\n\n                                                                                                       \\begin{align*}\n                                                                                                           \\Res(f, \\zeta^p) = \\lim_{z\\to \\zeta^p} \\frac{z-\\zeta^p}{\\prod_{k=1}^6 (z-\\zeta^k)} = \\frac{1}{\\prod_{1\\leq k \\leq 6, k\\neq p}^5 (\\zeta^p-\\zeta^k)}\n                                                                                                           \\end{align*}\n                                                                                                           It's easy enough to numerically compute that none of these terms are 0, and consequentally that the computation is indeed valid.\n                                                                                                           \\begin{code}\n                                                                                                           import cmath # using python\n                                                                                                           zeta = complex(0.6234898018587336, 0.7818314824680298)\n                                                                                                           res = [1/reduce(operator.mul, [pow(zeta, p) - pow(zeta,k) for k in range(1, 7) if k != p], 1) for p in range(1, 4)]\n                                                                                                           >> [(-0.12085867654500679+0.02758520424482756j), (-0.09692113342087182-0.2012588073284831j), (0.21777980996587906-0.173673603083655j)]\n                                                                                                           \\end{code}\n                                                                                                           And then we can get the answer by summing the residues and multiplying.\n                                                                                                           \\[\n                                                                                                           \\lim_{R\\to \\infty} \\int_{\\gamma_1} fdz = \\int_{-\\infty}^{\\infty} f dz = 2\\pi i \\sum_{p=1}^3{\\Res(f, \\zeta^p)}\n                                                                                                           \\]\n                                                                                                           \\begin{code}\n                                                                                                           sum(res)*2*cmath.pi * complex(0, 1)\n                                                                                                           >> (2.182446862280324+2.964688223307337e-15j)\n                                                                                                           \\end{code}\n                                                                                                           It's about 2.18.\n                                                                                                           \\end{solution}\n                                                                                                           \\begin{problem}\n                                                                                                             Show that $f(z) = z^5 + 15z - 1$ has five zeros in $B_2(0)$, and one zero in $B_{1/15}(0)$.\n                                                                                                             \\end{problem}\n                                                                                                             \\begin{solution}\n                                                                                                             First we will show that on $B_2(0)$, $\\abs{z^5} > \\abs{15z-1}$. By the triangle inequality, $\\abs{15z-1} \\leq \\abs{15z} + \\abs{1} = 31$, and $\\abs{z^5} = 2^5 = 32$.\n\n                                                                                                             Now we can apply Rouch\\'e's theorem to say that $z^5$ and $z^5+15z-1$ have the same number of zeros in the ball of radius 2 counted with multiplicity, so $f(z)$ must have $5$ zeros in the ball.\n\n                                                                                                             Next consider the ball of radius $\\frac{1}{15}$. The function $15z-(1-10^{-9})$ has exactly one zero in this ball; we hope to apply Rouch\\'e's theorem again by showing that \n                                                                                                             \\[\n                                                                                                             \\abs{15z-1+10^{-9}} \\geq \\abs{z^5 - 10^{-9}}\n                                                                                                             \\]\n                                                                                                             We can just apply the triangle inequality again:\n                                                                                                             \\[\n                                                                                                             \\abs{15z-1+10^{-9}} \\geq 14 + 10^{-9} \\geq \\frac{1}{15}^5 - 10^{-9} \\geq \\abs{z^5 - 10^{-9}}\n                                                                                                             \\]\n                                                                                                             Then we can confirm that there is one zero in the ball of radius $\\frac{1}{15}$.\n\n                                                                                                             \\end{solution}\n                                                                                                             \\begin{problem}\\label{form-at-infinity}\n                                                                                                             Set $w = 1/z$ and compute $f(w) \\, dw$ in terms of $f(z) \\, dz$.\n                                                                                                             \\end{problem}\n                                                                                                             \\begin{solution}\n                                                                                                             If $w=\\frac{1}{z}$, differentiating both sides we get that $dw = \\frac{-dz}{z^2}$. Thus $f(w) dw = -f(\\frac{1}{z})\\frac{dz}{z^2}$\n\n                                                                                                             \\end{solution}\n                                                                                                             \\section{Exploration}\n\n                                                                                                             \\begin{problem}\n                                                                                                               Fix $w \\in \\R$ with $w>0$.  By the intermediate value theorem, the\n                                                                                                                 polynomial $f(z) = z^4 + 4w^3 z - 1$ has a real root in the interval\n                                                                                                                   $(-\\infty,0)$ and another in $(0,1)$, along with two complex roots\n                                                                                                                     $a \\pm bi$.  Use Gauss-Lucas (\\ref{gauss-lucas}) and Rouch\\'e's\n                                                                                                                       (\\ref{rouches-theorem}) theorem to describe a subset of $\\C$\n                                                                                                                         containing $a\\pm bi$.\n                                                                                                                         \\end{problem}\n                                                                                                                         \\begin{solution}\n\n                                                                                                                         We can use Rouch\\'e's theorem to show that the roots lie in the ball of radius $\\max(2w, \\sqrt{2})$. Under these conditions we can prove the inequality $|z^4|>|4w^3z - 1|$, and since $z^4$ has 4 zeros in the ball, so must $f$.\n\n                                                                                                                         To prove the inequality: Suppose that $w>\\sqrt[4]{1/8}$. Then \n                                                                                                                         \\begin{align*}\n                                                                                                                         &8w^4 > 1 \\\\\n                                                                                                                         \\implies &16w^4 > 8w^3 + 1\\\\\n                                                                                                                         \\implies &\\abs{z^4} > \\abs{4zw^3 - 1} \\quad \\text{ if } \\abs{z} = 2w\n                                                                                                                         \\end{align*}\n                                                                                                                         Otherwise, we must have that \n                                                                                                                         \\[w<\\sqrt[4]{1/8}< \\sqrt[3]{\\frac{3}{4\\sqrt{2}}}\\]\n                                                                                                                         which implies that\n                                                                                                                         \\begin{align*}\n                                                                                                                         3 > 4\\sqrt{2}w^3\\\\\n                                                                                                                         &\\implies 4 > 4\\sqrt{2}w^3 - 1\\\\\n                                                                                                                         &\\implies \\abs{z^4} > \\abs{4zw^3 - 1} \\quad \\text{ if } \\abs{z} = \\sqrt{2}\n                                                                                                                         \\end{align*}\n                                                                                                                         In either case, the inequality is satisfied.\n\n                                                                                                                         By Gauss-Lucas, the roots of $f$ contain the convex hull of the roots of $f'(z) = 4z^3+4w^3$, which are cubic roots of $w$. WLOG let $b\\geq 0$. This implies that $b > \\frac{\\sqrt{3}w}{2}$. Combining this with the fact that $a+bi$ is contained in the ball of radius $\\max(2w, \\sqrt{2})$, we get a somewhat restricted set of locations for the roots.\n\n                                                                                                                         We can restrict it a bit more if needed by considering the convex hull further: Let $\\zeta_1 = w(\\frac{\\sqrt{3}}{2}+\\frac{i}{2})$. Since the real roots are all on the line from $-\\max(2w, \\sqrt{2})$ to $1$, $a+bi$ is above the line from 1 to $\\zeta_1$ and the line from $-\\max(2w, \\sqrt{2})$ to $\\zeta_1$. And if $w>1$, then the real part of the roots is greater than $w.$ \n                                                                                                                         \\end{solution}\n                                                                                                                         \\begin{problem}\n                                                                                                                           What is the correct definition of $\\Res(f,\\infty)$?  Generally, we\n                                                                                                                             would shift the viewport by replacing $f$ with the function\n                                                                                                                               $g(z) = f(1/z)$ and then we study $g$ near $z = 0$ in order to\n                                                                                                                                 investigate ``$f$ near $\\infty$.''  Does \\ref{form-at-infinity} help\n                                                                                                                                   here?\n                                                                                                                                   \\end{problem}\n                                                                                                                                   \\begin{solution}\n                                                                                                                                   Le $\\gamma_R$ be the circle of radius $R$ centered at 0.\n                                                                                                                                   The residue of $f$ at $\\infty$ is kinda given by the formula\n                                                                                                                                   \\[\n                                                                                                                                   \\lim_{R \\to \\infty k} \\int_{\\gamma_R} \\frac{f(w)dw}{w}\n                                                                                                                                   \\]\n                                                                                                                                   Except that the part of the circle that is inside is backwards.\n\n                                                                                                                                   We fix this by inverting everything using the subsitution $w=\\frac{1}{z}$ investigated in $\\ref{form-at-infinity}$ to get the formula\n                                                                                                                                   \\[\n                                                                                                                                   \\lim_{R^+\\to 0} \\int_{\\gamma_R} -zg(z)\\frac{dz}{z^2} = \\lim_{R^+\\to 0} \\int_{\\gamma_R} -g(z)\\frac{dz}{z} \n                                                                                                                                   \\]\n                                                                                                                                   Except that since we inverted everything, we are now travelling on $\\gamma$ in the clockwise direction. To fix this we get rid of the negative sign, and see that we are looking for the coefficent of $\\frac{1}{z}$ in the taylor series of $g(z)$, which is nothing but the coefficient of $z$ in the taylor series of $f(z)$.\n                                                                                                                                   \\end{solution}\n                                                                                                                                   \\begin{problem}\\label{rouches-theorem}Suppose $U$ is an open set containing the closed disk $D_r(z_0)$ and\n                                                                                                                                     $f, g : U \\to \\C$ are holomorphic functions satisfying\n                                                                                                                                       \\[\n                                                                                                                                           \\abs{f(z)} > \\abs{g(z)}\n                                                                                                                                             \\]\n                                                                                                                                               for $z \\in \\partial D_r(z_0)$.  Prove \\textbf{Rouch\\'e's theorem}\n                                                                                                                                                 that $f$ and $f+g$ have the same number of zeros, counted with\n                                                                                                                                                   multiplicity, in $B_r(z_0)$.  (This is sometimes called the dog\n                                                                                                                                                     leash theorem---can you see why?)\n                                                                                                                                                     \\end{problem}\n                                                                                                                                                     \\begin{solution}\n                                                                                                                                                     The argument principal tells us that for any holomorphic function $f$, the number of roots of $f$ inside of a positively oriented jordan curve $\\gamma$ is given by\n                                                                                                                                                      $\\frac{1}{2\\pi i}\\int_\\gamma \\frac{f'}{f} dz.$\n\n                                                                                                                                                      In particular, the number of zeros of $f+g = f(1 + \\frac{g}{f})$ is\n                                                                                                                                                      \\begin{align*}\n                                                                                                                                                      \\frac{1}{2\\pi i}\\int_\\gamma \\frac{(f(1 + \\frac{g}{f}))'}{f(1 + \\frac{g}{f})}dx &=\n                                                                                                                                                      \\frac{1}{2\\pi i}\\int_\\gamma \\frac{f'}{f} + \\frac{(1+\\frac{g}{f})'}{1 + \\frac{g}{f}}dx \n                                                                                                                                                      \\end{align*}\n                                                                                                                                                      Thus it suffices to show that the term \n                                                                                                                                                      \\(\n                                                                                                                                                      \\int_\\gamma \\frac{(1+\\frac{g}{f})'}{1 + \\frac{g}{f}}dx\n                                                                                                                                                      \\)\n                                                                                                                                                      vanishes. Since $1+\\frac{g}{f}>0$ on the boundary of $D_r(z_0)$, the function is analytic on the boundary, and since $\\abs{f}>\\abs{g}$, the function $1+\\frac{g}{f}$ is analytic and always positive, so it has no zeros. By the argument principal, the term must evaluate to 0.\n                                                                                                                                                      \\end{solution}\n                                                                                                                                                      \\begin{problem}\n                                                                                                                                                        Use \\ref{rouches-theorem} to give another proof of the Fundamental Theorem of Algebra.\n                                                                                                                                                        \\end{problem}\n                                                                                                                                                        \\begin{solution}\n                                                                                                                                                        Let $p(x) = \\sum_{k=1}^d a_kx^k$ be a degree $d$ polynomial with $a_d\\neq 0$. Then we can choose a circle $B_r(0)$ of sufficently big radius so that the leading term dominates on $\\partial B_r(0)$:\n                                                                                                                                                        \\[\n                                                                                                                                                        \\abs{a_dx^d} \\geq \\abs{\\sum_{k=1}^d a_kx^k}\n                                                                                                                                                        \\]\n                                                                                                                                                        We should also ensure that $r > \\sqrt[d]{a_d}$, to observe that $a_dx^d$ has exactly $d$ roots in the circle corresponding to the scaled $d$th roots of unity. By Rouch\\'e's theorem, this means that $p(x)$ also has exactly $d$ roots in this big circle. And, in fact, in any circle of even larger size, so we can even say that $p(x)$ has exactly $d$ roots in $\\C$.\n                                                                                                                                                        \\end{solution}\n                                                                                                                                                        \\begin{problem}\n                                                                                                                                                          It is important to recognize patterns in how residues equip us to evaluate integrals, so that, when presented with a fresh integration problem, we have some ideas about the best tool for the task.  Develop a tool for evaluating\n                                                                                                                                                            \\[\n                                                                                                                                                                \\int_0^{2\\pi} f(\\cos \\theta,\\sin \\theta) \\, d\\theta\n                                                                                                                                                                  \\]\n                                                                                                                                                                    via residues.  Here $f$ is a rational function, explain how to make\n                                                                                                                                                                      the substitution $z = e^{i\\theta}$ to rewrite\n                                                                                                                                                                        $f(\\cos \\theta,\\sin \\theta)$ in terms of $z$, and\n                                                                                                                                                                          similarly rewrite $d\\theta$ in terms of\n                                                                                                                                                                            $dz$ to reduce the given integral to a certain contour integral.\n                                                                                                                                                                            \\end{problem}\n                                                                                                                                                                            \\begin{solution}\n                                                                                                                                                                            Let $z=e^{i\\theta}$ so that $dz = ie^{i\\theta} d\\theta$. Then $d\\theta = \\frac{dz}{iz}$ and \n                                                                                                                                                                            \\begin{gather*}\n                                                                                                                                                                            \\cos\\theta = \\frac{e^{i\\theta} + e^{-i\\theta}}{2} = \\frac{z+z^{-1}}{2}\\\\\n                                                                                                                                                                            \\sin\\theta = \\frac{e^{i\\theta} - e^{-i\\theta}}{2i} = \\frac{z-z^{-1}}{2i}\n                                                                                                                                                                            \\end{gather*}\n                                                                                                                                                                            So the integral becomes\n                                                                                                                                                                            \\[\n                                                                                                                                                                            \\int_\\gamma f(\\frac{z+z^{-1}}{2},\\frac{z-z^{-1}}{2i})\\frac{dz}{iz}\n                                                                                                                                                                            \\]\n                                                                                                                                                                            Where $\\gamma$ is the image of $e^{i\\theta}$ for $0\\leq \\theta \\leq 2\\pi$, that is, the positively oriented unit circle \n                                                                                                                                                                            \\[\\gamma:[0, 2\\pi] \\to \\C\\qquad \\gamma(\\theta)= e^{i\\theta}.\\]\n\n                                                                                                                                                                            Since $f$ is a rational function, we have a rational function in $z$ so it is meromorphic with finitely many poles $\\{z_k\\}_{k=1}^n$ in the unit circle and the residue theorem can be used to evaluate the integrals:\n                                                                                                                                                                            \\[\n                                                                                                                                                                                \\int_0^{2\\pi} f(\\cos \\theta, \\sin\\theta) d\\theta =  2\\pi i \\sum_{k=1}^n \\Res(f(\\frac{z+z^{-1}}{2},\\frac{z-z^{-1}}{2i}\\frac{1}{iz} ), z_k)\n                                                                                                                                                                                \\]\n                                                                                                                                                                                \\end{solution}\n                                                                                                                                                                                \\begin{problem}\\label{summation-theorem}Sometimes the residue calculus\n                                                                                                                                                                                  permits us to sum series.\n\n                                                                                                                                                                                    Suppose $f$ is meromorphic with poles $z_1,\\ldots,z_N$ with $z_j \\not\\in \\Z$.  Our goal is a formula\n                                                                                                                                                                                      \\[\n                                                                                                                                                                                          \\sum_{n=-\\infty}^{\\infty} f(n) = - \\sum_{j=1}^N \\Res(g, z_j)\n                                                                                                                                                                                            \\]\n                                                                                                                                                                                              where $g(z) = \\pi \\cot(\\pi z) f(z)$.  \\textit{Hint:} Consider a square contour $R$ centered at the origin with side-length $2N+1$.  You may assume that $\\pi \\cot(\\pi z)$ is bounded on $R$ independent of $N$.  You will then need to impose some bound on $f$ on the contour $R$.\n                                                                                                                                                                                              \\end{problem}\n                                                                                                                                                                                              \\begin{solution}\n                                                                                                                                                                                              Let's compute the contour integral $I=\\int_R g(z)dz$ in two different ways. First, using the residue theorem, we have that \n                                                                                                                                                                                              \\begin{equation}\\label{Residue_eq_q}\n                                                                                                                                                                                              \\frac{I}{2\\pi i} = \\sum_{j=1}^N \\Res(g,z_i) + \\sum_{k=-\\infty} ^\\infty \\Res(g, k).\n                                                                                                                                                                                              \\end{equation}\n                                                                                                                                                                                              We can compute the residue of $g$ at $k$\n                                                                                                                                                                                              \\[\n                                                                                                                                                                                              \\Res(\\pi\\cot(\\pi z)f(z), k) = \\lim_{z\\to k} \\pi\\cos(\\pi z)f(z)\\frac{(z-k)}{\\sin(\\pi z)} = \\lim_{z\\to k} \\pi\\cos(\\pi z)f(z)\\frac{(z-k)}{\\sin(\\pi z)} \n                                                                                                                                                                                              \\]\n\n                                                                                                                                                                                              Thus if we can show that $I=0$, we get the desired equality  from \\eqref{Residue_eq_q}.\n                                                                                                                                                                                              \\[\n                                                                                                                                                                                              0 = \\sum_{j=1}^N \\Res(g,z_i) + \\sum_{k=-\\infty} ^\\infty f(k).\n                                                                                                                                                                                              \\]\n\n                                                                                                                                                                                              Second, let's compute $\\int_R g(z)dz$ directly, aiming for it to be 0.\n                                                                                                                                                                                              \\[\n                                                                                                                                                                                              \\lim_{N\\to\\infty} \\int_R g(z) dz \\leq (4(2N+1))\\sup_{z\\in R}(g(z))\n                                                                                                                                                                                              \\]\n                                                                                                                                                                                              Since $\\pi\\cot(\\pi z)$ is bounded, it suffices for the growth rate of $f(z)$ to be asymptotically slowed than that of $8N+4$: $f(|z|) \\in \\omega(|z|)$.\n\n                                                                                                                                                                                              If so, we can conclude that $I=0$, proving the claim.\n                                                                                                                                                                                              \\end{solution}\n                                                                                                                                                                                              \\begin{problem}\n                                                                                                                                                                                                Apply \\ref{residue-coth} and \\ref{summation-theorem} to evaluate\n                                                                                                                                                                                                  \\[\n                                                                                                                                                                                                      \\sum_{n=-\\infty}^\\infty \\frac{1}{n^2 + b^2}.\n                                                                                                                                                                                                        \\]\n                                                                                                                                                                                                        \\end{problem}\n                                                                                                                                                                                                        \\begin{solution}\n                                                                                                                                                                                                        Let $f(n) = \\frac{1}{n^2+b^2}$. We assume $bi \\not \\in \\Z$ so that the sum is finite. Then in the previous problem, $g(n) = \\frac{\\pi\\cot(\\pi z)}{z^2 + b^2}$. By \\ref{residue-coth}, the residue at $\\pm bi$ is $\\frac{\\pi\\cot(\\pm \\pi bi)}{\\pm 2bi}$, so the sum of the residues is $-\\frac{\\pi \\coth{\\pi b}}{b}$ and thus the sum is $\\frac{\\pi \\coth{\\pi b}}{b}$.\n                                                                                                                                                                                                        \\end{solution}\n                                                                                                                                                                                                        \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                                                                                                                        \\begin{problem}\\label{zero-residue-not-enough}Suppose $f : D_r(z_0) \\to \\C$ is holomorphic.  The residue\n                                                                                                                                                                                                          $\\Res(f,z_0)$ vanishes if and only if the singularity $z_0$ is\n                                                                                                                                                                                                            removable.\n                                                                                                                                                                                                            \\end{problem}\n                                                                                                                                                                                                            \\begin{solution}\n                                                                                                                                                                                                            This is true for stupid reasons: if $f$ is holomorphic on a disk surrounding $z_0$, then $f$ has no singularity at $z_0$, so if a singularity exists, it is surely removable. If it is merely meromorphic, a counterexample like $\\frac{1}{z^2}$ suffices, since it has residue $0$ but no removable singularity at $0$.\n\n                                                                                                                                                                                                            However, if the singularity is removable, the residue will vanish, since after removing the singularity, $f$ is holomorphic on a small ball containing $z_0$, so the residue must vanish.\n\n\n                                                                                                                                                                                                            \\end{solution}\n                                                                                                                                                                                                            \\begin{problem}\\label{open-mapping-theorem}If $U \\subset \\C$ is open\n                                                                                                                                                                                                              and $f : U \\to \\C$ is holomorphic, then $f(U)$ is\n                                                                                                                                                                                                                open. % missing nonconstant, can be proved from rouche\n                                                                                                                                                                                                                \\end{problem}\n                                                                                                                                                                                                                \\begin{solution}\n                                                                                                                                                                                                                No, consider $f(z)=0$. If we don't allow $f$ to be a constant, then it is true.\n\n                                                                                                                                                                                                                Choose some arbitrary point $z_0\\in U$ with $f(z_0)=w_0$. Now consider a series of open balls $\\{B_{1/n}(z_0)\\}_{n\\in\\N}$. We can surely find an $n$ where the $n$th ball is contained in $U$ since $U$ is open. Furthermore, by the identity theorem, there is an $n$ where the $n$th ball does not contain any point $z_1$ with $f(z_1)=w_0$ - otherwise, we would have an infinite series of points $\\{z_i\\}$ containing their limit point where $f(z_i)=w$, implying by the identity theorem that $\\forall z\\in U, f(z) = w$. Call the first $n$ satsifying both conditions $N$.\n\n                                                                                                                                                                                                                Let $\\delta = (\\inf_{z\\in B_{1/N}(z_0)}\\abs{f(z)-w_0})/2$, so that for all $z$ in this ball,\n                                                                                                                                                                                                                \\[\n                                                                                                                                                                                                                \\abs{f(z) - w_0 } \\geq 2\\delta.\n                                                                                                                                                                                                                \\]\n                                                                                                                                                                                                                Choose some $w_1\\in \\partial D_\\delta (f(z_0))$, so that \n                                                                                                                                                                                                                \\[\\delta \\geq \\abs{w_0-w_1}.\n                                                                                                                                                                                                                \\]\n\n                                                                                                                                                                                                                To show that $f(U)$ is open, it suffices to show that any such $w_1$ is in the image of $f$, or equivalently that $f(z) - w_1$ has a zero. We know from the last paragraph that $f(z)-w_0$ has exactly one zero in $B_{1/N}(z_0)$, and that \n                                                                                                                                                                                                                \\[\n                                                                                                                                                                                                                \\abs{f(z) - w_0} \\geq \\abs{w_0 - w_1}\n                                                                                                                                                                                                                \\]\n                                                                                                                                                                                                                so by Rouche's theorem, $f(z)-w_0 +w_0-w_1 = f(z) - w_1$ has a zero in $B_{1/N}$. Thus $f(U)$ is open.\n                                                                                                                                                                                                                \\end{solution}\n\n\n                                                                                                                                                                                                                \\end{document}\n", "meta": {"hexsha": "4e2022ea50db0dd69047177ef08f7d6a22996dfd", "size": 76314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol9.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/sol9.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/sol9.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": 136.518783542, "max_line_length": 772, "alphanum_fraction": 0.217142333, "num_tokens": 11232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6124345871356573}}
{"text": "\n\n\\section{CP Violation and Mixing}\n\\label{sect:cpviolation}\n\\index{CP violation}\n\nThis section discusses how CP violation and mixing work\nin the generator. These two topics are closely related, since\na large fraction of CP violating decays occurs via mixing. Exactly what is \nthe best way of introducing these two effects into EvtGen is still not clear; \nthere are different ways of generating CP violating decays depending on what \none is interested in.  For example, one might want to generate a sample of events with \n$B\\rightarrow a_1^+ \\pi^-$, and the $B$'s which tag the flavor of this $B$ \n(e.g., via semileptonic decays) are all $B^0$'s.  On the\nother hand, one might want to generate a sample that has the \ncorrect mixture of $B^0$ and $\\bar B^0$ tags, as determined by the decay \ndynamics.  From the point of view of implementation these two situations are \nfairly different, and at the moment we are still working on choosing \na consistent way of dealing with them.\n\nThis section starts out describing how mixing works, and\nthen proceeds to describe how CP violation is introduced.  Examples\nwill be provided. CP violating decays are\namong the most complicated things this generator does, and \nvarious ways in which one might get the generation of CP\nviolating decays wrong will be pointed out.\n\n\\subsection{Mixing in the $B^0\\bar B^0$ System.}\n\nAs is well know, when $\\Upsilon(4S)$ decays into the $B^0\\bar B^0$ system, \nthe $B$'s are produced in a coherent state.  This implies that  \nwhen one of the $B$'s decays, and its flavor is determined, the other\n$B$ is known to be in a pure state of the opposite flavor.\nThis state then evolves (oscillates) independently, with the oscillation frequency\ngiven by $\\Delta m /2$, ($\\Delta m$ being $m_{2} - m_{1}$, the mass difference between the two $B$ mass \neigenstates).  Assuming $|B_{0}^{\\rm phys}(t = 0)\\rangle = |B^{0}\\rangle$, its time evolution is given by: \n\\begin{equation}\n|B_{\\rm phys}^{0}(t)\\rangle = e^{-\\Gamma t/2}e^{i\\overline{m} t}\\,\\left[ |B^0\\rangle\\,\\cos\\left(\\frac{\\Delta m t}{2}\\right) + i\\frac{q}{p}|\\bar B^0\\rangle\\,\\sin\\left(\\frac{\\Delta m t}{2}\\right)\\right],\n\\end{equation}\nwhere $\\overline{m} \\equiv (m_{1} + m_{2})/2$, $q = e^{i\\phi_{M}}/\\sqrt{2}$, and $p = e^{-i\\phi_{M}}/\\sqrt{2}$ ($\\phi_{M}$ is the mixing angle).  Time $t$ in this formula is the time between the two $B$ decays.\n\nBy projecting $|B_{0}^{\\rm phys}(t)\\rangle$ into a pure $B^0$\nor $\\bar B^0$ state, one can obtain the amplitudes for the $B$ to decay with\na given flavor.  In turn, squaring them gives the probabilities:\n\\begin{eqnarray}\nP(B_{\\rm phys}^{0}\\rightarrow B^0) & = & \\frac{1}{2} e^{-\\Gamma t} (1+\\cos(\\Delta m t))\\\\\nP(B_{\\rm phys}^{0}\\rightarrow \\bar B^0) & = & \\frac{1}{2} e^{-\\Gamma t} (1-\\cos(\\Delta m t))\\\\\n\\end{eqnarray}\n\nIntegrating these over all times, one obtains the total rates:\n\\begin{eqnarray}\nP(B_{\\rm phys}^{0}\\rightarrow B^0)  & = & \\frac{x_{d}^2}{2\\,(1 + x_{d}^{2})}\\\\\nP(B_{\\rm phys}^{0}\\rightarrow \\bar B^0)  & = & \\frac{2 + x_{d}^2}{2\\,(1 + x_{d}^{2})}\\\\\n\\end{eqnarray}\nwhere $x_d \\equiv \\frac{\\Delta m}{\\Gamma}$.\n\nConsidering in a similar way the time evolution of the coherently produced state ($\\Psi(t = 0) = \\frac{1}{\\sqrt{2}}\\,\\left [ |B^{0} \\overline{B}^{0} \\rangle - |\\overline{B}^{0} B^{0} \\rangle \\right ]$ ), one can obtain the ratio:\n\\begin{equation}\n{ N(\\Upsilon(4S)\\rightarrow B^0B^0)+N(\\Upsilon(4S)\\rightarrow\\bar B^0\\bar B^0)\n  \\over N(\\Upsilon(4S)\\rightarrow B^0\\bar B^0)}= \\frac{x_{d}^{2}}{2 + \\,x_{d}^{2}}.\n\\end{equation}\n\nCurrently, mixing is implemented in two decay models: \n$\\tt VSS\\_MIX$ and $\\tt VSS\\_BMIX$.  These models both take the mass\ndifference to be a parameter and use the width assigned in the particle\nproperties table, i.e., from the evt.pdl file in the BaBar environment.\nThese models differ in the number of parameters that\nthe user must supply. The $\\tt VSS\\_MIX$ model requires that the branching\nfractions into mixed and unmixed final states be set by hand, and does not\nrequire that they be consistent with the mass difference and lifetime.\nThe $\\tt VSS_BMIX$ model calculates the branching fractions automatically\nand is therefore safer and easier to use. One can use this model as follows:\n\\begin{verbatim}\nDecay Upsilon(4S)\n0.5  B+       B-        VSS;\n0.5  B0       anti-B0   VSS_BMIX;\nEnddecay\n\\end{verbatim}\nBoth models give identical results when the $\\tt VSS\\_MIX$ branching\nfractions are set correctly.\n\n\n\\subsection{Mixing and Non-zero Lifetime Differences.}\n\n{\\it This section should probably be merged with the previous but \nis currently written separately, mostly due to historical reasons, as\nthis is only needed for $B_s$ mixing, which was added later.}\n\nIn this section $B^0$ and $\\bar B^0$ will generically denote any\nneutral meson flavor eigenstate. These states are not eigenstates\nof the full hamiltonian and hence do not have a definite mass or\nlifetime. The states that are eigenstates of the hamiltonian are\n\\begin{eqnarray}\n|B_L\\rangle & = & p|B^0\\rangle +q|\\bar B^0\\rangle, \\\\\n|B_H\\rangle & = & p|B^0\\rangle -q|\\bar B^0\\rangle.\n\\end{eqnarray}\nThe states $B_L$ and $B_H$ have masses, $m_L$ and $m_H$, and widths, $\\Gamma_L$\nand $\\Gamma_H$, respectively such that \n\\begin{equation}\n|B_{L,H}(t)\\rangle=e^{-(\\Gamma_{L,T}/2+im_{L,T})t}|B_{L,H}\\rangle\n\\end{equation}\nwhere $B_{L,H}(t)$ is the state after evolving the state $B_{L,H}$ for\na time $t$.\n\nThis allows us to evaluate several matrix elements that are useful for\ncalculating the mixing rates\n\\begin{eqnarray}\n\\langle B^0|B^0(t)\\rangle & = & {1\\over 2p}(\\langle B^0|B_L(t)\\rangle\n                                           +\\langle B^0|B_H(t)\\rangle)\\nonumber\\\\\n                          & = & {1\\over 2}(e^{-(\\Gamma_L/2+im_L)t}\n                                          +e^{-(\\Gamma_H/2+im_H)t}),\\\\\n\\langle \\bar B^0|B^0(t)\\rangle & = & {1\\over 2p}(\\langle \\bar B^0|B_L(t)\\rangle\n                                           +\\langle \\bar B^0|B_H(t)\\rangle)\\nonumber\\\\\n                          & = & {q\\over 2p}(e^{-(\\Gamma_L/2+im_L)t}\n                                          -e^{-(\\Gamma_H/2+im_H)t}),\\\\\n\\langle B^0|\\bar B^0(t)\\rangle & = & {1\\over 2q}(\\langle B^0|B_L(t)\\rangle\n                                           -\\langle B^0|B_H(t)\\rangle)\\nonumber\\\\\n                          & = & {p\\over 2q}(e^{-(\\Gamma_L/2+im_L)t}\n                                          -e^{-(\\Gamma_H/2+im_H)t}),\\\\\n\\langle \\bar B^0|\\bar B^0(t)\\rangle & = & {1\\over 2q}(\\langle \\bar B^0|B_L(t)\\rangle\n                                           +\\langle \\bar B^0|B_H(t)\\rangle)\\nonumber\\\\\n                          & = & {1\\over 2}(e^{-(\\Gamma_L/2+im_L)t}\n                                          +e^{-(\\Gamma_H/2+im_H)t}).\n\\end{eqnarray}\n\nNow it is straight forward to calculate the mixing rate. Let $\\chi$ \ndefine the probability that a meson produced, at $t=0$, as a $B^0$ will\ndecay as a $\\bar B^0$. It is now easy to see that \n\\begin{eqnarray}\n\\chi & = &{\\int_0^\\infty |\\langle \\bar B^0|B^0(t)\\rangle|^2dt \\over\n\\int_0^\\infty |\\langle \\bar B^0|B^0(t)\\rangle|^2dt +\n\\int_0^\\infty |\\langle B^0| B^0(t)\\rangle|^2dt }\\nonumber\\\\\n  & = & { x^2+y^2 \\over x^2+y^2+\\vert {p\\over q} \\vert^2(2+x^2-y^2)} \n\\end{eqnarray}\nwhere \n\\begin{equation}\nx\\equiv {\\Delta m \\over \\Gamma},\\qquad y\\equiv {\\Delta\\Gamma\\over \\Gamma}\n\\end{equation}\nand\n\\begin{equation}\n\\Gamma\\equiv {\\Gamma_L+\\Gamma_H \\over 2},\\qquad\n\\Delta\\Gamma \\equiv \\Gamma_H-\\Gamma_L,\\qquad\n\\Delta m \\equiv m_H-m_L.\n\\end{equation}\nSimilarly the probability that that a meson produced, at $t=0$ \nas a $\\bar B^0$ will decay as a $B^0$ is given by\n\\begin{eqnarray}\n\\bar \\chi & = &{\\int_0^\\infty |\\langle B^0|\\bar B^0(t)\\rangle|^2dt \\over\n\\int_0^\\infty |\\langle B^0|\\bar B^0(t)\\rangle|^2dt +\n\\int_0^\\infty |\\langle \\bar B^0| \\bar B^0(t)\\rangle|^2dt }\\nonumber\\\\\n  & = & { x^2+y^2 \\over x^2+y^2+\\vert {q\\over p} \\vert^2(2+x^2-y^2)}.\n\\end{eqnarray}\nIn the limit of $|p/q|=1$ and $y=0$ we have \n\\begin{equation}\nP_{\\pm}(t)=\\chi =\\bar\\chi={x^2\\over 2(1+x^2)}\n\\end{equation}\nas expected.\nThe time distribution, arbitrary normalization, is given by\n\\begin{equation}\ne^{-\\Gamma_L t}(1+e^{\\Delta\\Gamma t}\\pm 2e^{\\Delta\\Gamma t/2}\\cos\\Delta m t)\n\\end{equation}\nThe minus sign corresponds to the case of mixing, and the plus sign\nto the case of no mixing.\n\n\n\\subsection{CP-violation.}\n\nThe ``first generation'' of models which were implemented in EvtGen\nto deal with CP violation did not solve all the problems that are \ninvolved in simulating the physics of the $B\\bar B$ system. To illustrate how \nthese models work, let us consider the following example (the decay \n$B\\rightarrow \\pi^+\\pi^-$):\n\\begin{verbatim}\nAlias MYB B0\n#\nDecay Upsilon(4S)\n0.70   MYB B0      VSS;\n0.30   MYB B0B     VSS;\nEnddecay\n#\nDecay MYB\n1.0   pi+ pi-     SSS_CP alpha dm CP |A| arg(A) |Abar| arg(Abar);\nEnddecay\nEnd\n\\end{verbatim}\n\nThe model used in this example is {\\tt SSS\\_CP}.  Its first argument is {\\tt alpha}, is the\nrelevant CKM angle (in this case it is $\\alpha$); the second argument {\\tt dm} is\nthe mass difference of the two $B$ mass eigenstates; the third\nargument, {\\tt CP}, specifies the CP of the final state, and is either $+1$ or $-1$.\nThe latter argument could in principle be determined from the particle properties, but at \nthe moment EvtGen does not include the C and P quantum numbers in its particle properties\nlist (this should be fixed). The last 4 arguments are the (complex) amplitudes for \n$B^0$ and $\\bar B^0$ to produce the final state.\n\nIn this example the $\\Upsilon(4S)$ decays with unequal\nprobabilities to ``MYB'' and $B^0$  and to ``MYB'' and  $\\bar B^0$. The \n$B^0$ and $\\bar B^0$ simply decay as a $B^0$ and a $\\bar B^0$,\nrespectively, according to the generic decay table.  The interesting\nthing is how ``MYB'' decays.  In the {\\tt SSS\\_CP} model, ``MYB'' will produce a\n$\\pi^+ \\pi^-$ final state, while the other $B$ will provide\na tag of the flavor that is listed in the decay of the $\\Upsilon(4S)$ ($B^0$ in 70\\% \nof the cases, and $\\bar B^0$ in 30\\% of the cases).  Therefore, in this example there will\nbe some number of $B^0$ tags and some number of $\\bar B^0$ tags. \n  \nIf one would like to get a sample of events with only $B^0$ tags, \none could do it in the following way:\n\\begin{verbatim}\nAlias MYB B0\n#\nDecay Upsilon(4S)\n1.00  MYB B0      VSS;\nEnddecay\n#\nDecay MYB\n1.0   pi+ pi-     SSS_CP dm alpha CP |A| arg(A) |Abar| arg(Abar);\nEnddecay\nEnd\n\\end{verbatim}\n\nHere, the only available tag (as specified by the $\\Upsilon(4S)$ branching fraction) is $B^{0}$.\n\nWhen the $\\Upsilon(4S)$ is decayed and the two $B$'s are produced,\nthey are assigned lifetimes which are sampled from a pure exponential\ndistribution, with a mean of the average lifetime specified\nin the particle properties list. (If the decay model is one that\nincludes the effects of mixing, the time distribution is no longer\na pure exponential; see the previous section.  However, as will be\nevident below, it doesn't matter what time distribution is used in\nthe decay of the $\\Upsilon(4S)$.)  Since the lifetime distributions\nof both the $B$ that decays to the CP channel and the tag $B$ are\nno longer exponential, the {\\tt SSS\\_CP} model has to regenerate \nlifetimes of {\\it both} $B$'s. However, the model does not change what\ntag one of the $B$ provides. This is important, because it means that this model\ncannot enforce the right fraction of $B^0$ and $\\bar B^0$ tags.  {\\bf The only way to control this is through the decay table}.\n\nThe {\\tt SSS\\_CP} model handles decays to a pair of scalar particles.\nOf these, the most important one is probably $B \\rightarrow \\pi\\pi$, but the model also \nworks for any other decay with two scalars in the final state, e.g., $K_s\\eta'$.\nOther models which are implemented in a similar way are {\\tt SVS\\_CP} and {\\tt STS\\_CP},\nwhich handle the decays to a scalar and a vector and to a scalar and a \ntensor, respectively. There is also a model for two vectors\nin the final state: it is called {\\tt SVV\\_CP}. One complication with this\nmodel is that there are three partial waves that contribute to the \nrate with different CP. \n\nAll of these models have one feature in common: they generate the $B$ tags with the relative\nfractions specified in the decay table. It seems logical that the next step in expanding \nthe functionality of the generator should be implementing some way to generate the right \nfraction of $B^0$ and $\\bar B^0$ tags according to the amplitudes that are specified for a \nparticular decay channel.  Indeed, this would be a very natural thing to do, because given \nthe amplitudes, the relative fraction of $B^0$ and $\\bar B^0$ tags can be determined.  A new class of models which have been recently put into EvtGen does have this feature.  These new models are particularly important for decays into final states that are not\nCP eigenstates, for example $B\\rightarrow a_1^+\\pi^-$, or decays with direct CP violation (e.g., due to the presence of penguins).\n\nLet us consider in more detail what the problem is.  The time-dependent CP-asymmetry for\nthe decay $B \\rightarrow f$, where $f$ is a CP eigenstate, is defined as:\n\\begin{equation}\nA_f(t) = \\frac{\\Gamma(B^{0}(t) \\rightarrow f) - \\Gamma(\\overline{B}^{0}(t) \\rightarrow f)}{\\Gamma(B^{0}(t) \\rightarrow f) + \\Gamma(\\overline{B}^{0}(t) \\rightarrow f)}\n\\end{equation}\nIf $|A(B^{0} \\rightarrow f)|$ = $|A(\\overline{B}^{0} \\rightarrow f)|$, then the integrated \nasymmetry $\\int_{-\\infty}^{+\\infty}A_f(t)dt = 0$, and the relative fraction of $B^{0}$ ($\\bar B^0$) tags is known (1/2).  However, if $|A(B^{0} \\rightarrow f)| \\neq |A(\\overline{B}^{0} \\rightarrow f)|$ (which can happen, e.g., because of penguin pollution), $\\int_{-\\infty}^{+\\infty}A_f(t)dt \\neq 0$, so the fraction of tags must be somehow determined.\n\n\nOne way to get the correct fraction of tags is to use integrated rates.  For example, for decays into a CP-eigenstate it can be defined as:\n\\begin{equation}\nfr \\equiv \\frac{\\int_{-\\infty}^{\\infty}\\Gamma(\\overline{B}(t)^{0} \\rightarrow f)dt}{\\int_{-\\infty}^{\\infty}\\left[\\Gamma(B^{0}(t) \\rightarrow f) + \\Gamma(\\overline{B}^{0}(t) \\rightarrow f)\\right]dt} \n\\end{equation}\nso that\n\\begin{equation}\nfr = \\frac{|\\overline{A}_{f}|^2 \\left(1 + |\\overline{r}_{f}|^2 + \\frac{(1 - |\\overline{r}_{f}|^2)}{1+x_{d}^2} \\right)}{|\\overline{A}_{f}|^2 \\left(1 + |\\overline{r}_{f}|^2 + \\frac{(1 - |\\overline{r}_{f}|^2)}{1+x_{d}^2} \\right) + |{A}_{f}|^2 \\left(1 + |r_{f}|^2 + \\frac{(1 - |r_{f}|^2)}{1+x_{d}^2} \\right)},\n\\end{equation}\nwhere $x_{d} \\equiv \\frac{\\Delta m}{\\Gamma}$, $r_{f} = e^{2i\\,\\phi_{M}}\\,\\frac{\\overline{A}}{A}$, and $\\overline{r}_{f} = \\frac{1}{r_{f}}$.\n\nTwo functions in the new version of EvtOtherB return this fraction (fractB0CP for decays into a CP eigenstate and fractB0nonCP for decays into non-CP eigenstates).  However, analytical calculations of the integrals can be done only in the simplest cases.  For example, for the $B \\rightarrow \\rho \\pi$ decay one would have to integrate over the Dalitz plot as well as over time to get the total rates, which is very hard to do!  A better solution is to use the so-called acceptance-rejection method, which is effectively equivalent to numerical integration.  This method has been used in the ``second generation'' models which introduce direct CP-violation into EvtGen.\n\n  The new models that are available are: {\\tt SSS\\_CP\\_PNG} for the $B \\rightarrow \\pi^{+} \\pi^{-}$ decay with penguin contributions; {\\tt BTO2PI\\_CP\\_ISO} for the three isospin-related $B\\rightarrow \\pi \\pi$ modes; {\\tt BTOKPI\\_CP\\_ISO} for the four isospin-related $B \\rightarrow K \\pi$ modes; and {\\tt SVS\\_CP\\_ISO} for the five isospin-related generic $scalar \\rightarrow (pseudo)scalar + vector$ modes.  There is another decay model for the latter case, which also returns the correct fraction of $B^0$ ($\\bar B^0$) tags.  It is called {\\tt SVS\\_NONCPEIGEN}.  Here is an example of how this model can be used for the $B \\rightarrow a_1 \\pi$ decay:\n\\begin{verbatim}\nAlias MYB B0\nDecay Upsilon(4S)\n1.000 MYB anti-B0                         VSS;\nEnddecay\nDecay MYB\n1.000 a_1-  pi+          SVS_NONCPEIGEN 1.22 0.51e12 0.0 \n                                                       1.0 0.0 3.0 0.1 \n                                                       3.0 0.1 1.0 0.0;\nEnddecay\nEnd\n\\end{verbatim}\n\nThe first parameter of this model is the corresponding CKM angle (in this case, it is $\\alpha$); the second parameter is $\\Delta m$; the third parameter is the ``flip'' which determines the fraction of ``MYB'' $\\rightarrow f$ to ``MYB'' $\\rightarrow \\overline{f}$ decays, where the state specified in the decay table is considered the ``$f$'' state.  If the flip is set to 0, ``MYB'' always decays into the $f$ state.  The next four parameters are the absolute values and phases for the amplitudes $B^{0} \\rightarrow f$ and $\\bar B^{0} \\rightarrow f$, respectively, and the last four parameters are those for the amplitudes $B^{0} \\rightarrow \\overline{f}$ and $\\overline{B}^{0} \\rightarrow \\overline{f}$.\n\nIt is important not to confuse the ``flip'' parameter with the number of tags.  For example, one would like to generate 10,000 $B\\overline{B}$ events with the flip parameter set to 0.5.  This means that one would get 5,000 ``MYB'' $\\rightarrow f$ decays and 5,000 ``MYB'' $\\rightarrow \\overline{f}$ decays, but within each 5,000 event sample the number of $B^{0}$ and $\\bar B^{0}$ tags is determined by the amplitudes specified in the decay file! \n\nAs before, ``MYB'' in this example decays into a CP-mode, while the other B provides a tag.  However, the model itself generates the correct fraction of $B^{0}$ ($\\bar B^{0}$) tags, which is determined from the last eight parameters (the amplitudes), and is independent of the $\\Upsilon(4S)$ branching fractions.\n\n\n\n\\subsection{Special CP models}\n\n The models described above are meant to be generic models that can\nbe applied to different decays with appropriate arguments. All of the\nabove models are two body decays. There is, however, many other decays\nthat are not two body decays and these can not be treated quite as\nsimply since there will in general be interference between various\nresonances. As an example consider the decay $B\\rightarrow \\pi^+\\pi^-\\pi^0$\nwhich is dominated by the $\\rho(770)$ resonances.\n\n To handle the $B\\rightarrow 3\\pi$ and the $B\\rightarrow 4\\pi$\ndecays two special models have been written. These models are \ncalled {\\tt BTO3PI\\_CP} and {\\tt BTO4PI\\_CP}. The second\nof model {\\tt BTO4PI\\_CP} needs more work interms of understanding the\nconventions of the phases between the resonances that contributes.\n\n\\newpage\n\n\\subsection{Unified implementation of CP-violating and mixing}\n\nThis section describes a {\\it proposal} for how to unify and \nsimplify the simulation of CP-violating decays and mixing in EvtGen, this \nshould allow writing models that works independently of\nhow the neutral $B$ meson is produced, i.e. in a coherent pair in an\n$\\Upsilon(4S)$ decay or incoherently e.g. in a $p\\bar p$ collision.\n\n\\subsubsection{CP violation}\n\nThe decays that we are considering here are \ncommon final states to a neutral $B$ meson and its antiparticle,\ne.g. $B\\to J/\\psi K_S$\nor $B\\to J/\\psi K^*$. At the $\\Upsilon(4S)$ in the absence of\ndirect CP violation these decays can be simplified as we can make the \nassumption that you have an equal number of $B^0$ and $\\bar B^0$\ntags, or equivalent that there is no time integrated asymmetry.\nHowever, we want to write the code such that no assumptions are\nmade about the numbers of $B^0$ and $\\bar B^0$ tags.\nFor $B$ mesons that are produced incoherently we always have to\nconsider the asymmetries in the rates for an initial $B^0$ or\n$\\bar B^0$. \n\nTo allow generating these asymmetries correctly these models\nwill be allowed to modify the flavor of the $B$ meson that is decayed.\nFor the $\\Upsilon(4S)$ this means changing the the flavor of 'the\nother' $B$ meson in the $\\Upsilon(4S)$ decay, the tag $B$. \nFor incoherent produced $B$\nmesons this means that if a specific flavor is given to \nEvtGen it can return a decay of the opposite flavor. If\ne.g. EvtGen is given a $B^{**}+$ to decay and it decays it to\n$B^0\\pi^+$ the decay of the $B^0$ might decide to flip the \nflavor of the decay chain to allow generating the right \ntime integrated asymmetry. This means that after EvtGen is\ndone the code that called EvtGen will get back a $B^{**}-$\nand needs to be prepared to handle this, e.g. by applying CP\nto the decay chain that produced the $B^{**}+$. Also note the\nmeaning of branching fractions in the decay table, for modes\nthat are common to a $B$ and its anti-particle, the $\\bar B$\nthe above implies that the branching fraction listed for the\n$B$ and the $\\bar B$ are the average branching fractions.\n\nPractically, this is implemented in the {\\tt EvtCPUtil}\nclass, which will handle the cases of coherent and incoherently\nproduced $B$ mesons.\n\nHow is this different from the current implementation, V00-09-38?\nNot very much, there are already some models, e.g. the \n{\\tt SVS\\_NONCPEIGEN}\nthat has the full functionality that allows for direct CP violation \nand will generate the right mixture of $B$ and $\\bar B$ tags.\nAll CP models should convert to this more general model. For \napplying this to $B$ mesons that are produced incoherent, i.e.\nwith a definite flavor, we need to modify the {\\tt EvtCPUtil::otherB()}\nmethod to allow the change of the flavor.\n\n\\subsubsection{Mixing}\n\nIn the $\\Upsilon(4S)$ system mixing is handled by the decay of the\n$\\Upsilon(4S)$ meson via models such as {\\tt VSS\\_BMIX}. This \nimplementation seems sufficient at this point. Note that we\nare not considering the case of the $\\Upsilon(5S)$ at this point.\n\nFor incoherently produced neutral $B$ mesons, $B^0$ or $B_s$, we assume that\nthe flavor is tagged and mixing will be generated by adding a \ndecay like $B^0\\to \\bar B^0$ where the mixed particle have \nzero lifetime. Models that simulate CP violation, or in general\nmodels that handle decays common to the $B$ and the $\\bar B$ \ndecay will remove any mixing, this is done in {\\tt EvtCPUtil}. \n(Models that do not make any assumption about\nthe flavor of the $B$ should probably be using a 'neutral $B$' particle\ninstead of a specific flavor, but at BABAR we have not implemented \nthis as it would be very confusing at this point to a lot of\nanalysis code that uses Monte Carlo truth.)\n\nThis means that models that simulates CP-violating decays should not\nneed to turn of mixing, it will practically be ignored. \n\nThe mixing of incoherently produced  $B$ mesons is not done in a \nmodel, this causes some problems as it is hard to control the\nmixing, e.g., turning it of or modifying the parameters. We need to\ninvent a way to control this.\n\n\n", "meta": {"hexsha": "30cafacbd1a8009e695e5ca0f6251e3a85d9f21a", "size": 22692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EvtGen1_06_00/doc/evt_cpviolation.tex", "max_stars_repo_name": "klendathu2k/StarGenerator", "max_stars_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:57:20.000Z", "max_issues_repo_path": "EvtGen1_06_00/doc/evt_cpviolation.tex", "max_issues_repo_name": "klendathu2k/StarGenerator", "max_issues_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EvtGen1_06_00/doc/evt_cpviolation.tex", "max_forks_repo_name": "klendathu2k/StarGenerator", "max_forks_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_forks_repo_licenses": ["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.73, "max_line_length": 705, "alphanum_fraction": 0.6983959105, "num_tokens": 6917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6124345858856297}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage[margin=2.5cm]{geometry}\n\n\n\n\\begin{document}\n\t\\section{Geometry}\n\t\\begin{itemize}\n\t\\item\n\tThe sum of opposite angles in cyclic quadrilateral is $180^\\circ$.\n\t\\item\n\tInscribed angles which subtend to same arc are equal to half of the central angle. \n\t\\item\n\tLimiting case of the above is alternate segment theorem. The angle between tangent and chord is equal to inscribed angle subtending to the same chord.\n\t\\end{itemize}\n\t\n\t\n\t\\begin{enumerate}\n\t\t\\item\n\t\tFind mistake in the \"proof that all triangles are isosceles\".\n\t\t\n\t\t\\item %% LPV 2000 11\n\t\t$PQRS$ is a cyclic quadrilateral in which $\\angle PSR = 90^\\circ$. Points $H$ and $K$ are projections of point $Q$ to lines $PR$ and $PS$ respectively. Prove that line $HK$ intersects segment $SQ$ at its midpoint.\n\t\t\n\t\t\\item %% LPV 2002\n\t\tPoint $P$ is chosen on the circumcircle of triangle $ABC$. Points $K$, $L$ and $M$ are projections of $P$ to lines $AB$, $BC$ and $AC$ respectively. Prove that $K$, $L$ and $M$ lie on the same line.\n  \t\t\n\t\t\\item %% problem solving strategies\n\t\tOne of the cross sections in a rectangular box is a regular hexagon. Prove that the rectangular box is a cube.\n\t\t\n\n\t\\end{enumerate}\n\t\\section{Trigonometry}\n\t\t\\begin{itemize}\n\t\t\t\\item\n\t\t\tSine law:\n\t\t\t$$\\frac{a}{\\sin \\alpha}=\\frac{b}{\\sin \\beta}=\\frac{c}{\\sin \\gamma}=2R $$\n\t\t\t\\item\n\t\t\tCosine law:\n\t\t\t$$ c^2=a^2+b^2-2ab\\cos\\gamma $$\n\t\t\t\\item\n\t\t\tTrigonometric functions of sums:\n\t\t\t$$ \\sin(\\alpha+\\beta)=\\sin\\alpha\\cos\\beta+\\cos\\alpha\\sin\\beta $$\n\t\t\t$$ \\cos(\\alpha+\\beta)=\\cos\\alpha\\cos\\beta-\\sin\\alpha\\sin\\beta $$\n\t\t\\end{itemize}\n\t\t\\begin{enumerate}\n\t\t\t\\item %% Prasolov 1.19\n\t\t\tA straight line passing through vertex $A$ of square $ABCD$ intersects side $CD$ at $E$ and line $BC$ at $F$. Prove that $\\frac{1}{|AE|^2}+\\frac{1}{|AF|^2} =\n\t\t\t\\frac{1}{|AB|^2}$.\n\t\t\t\\item\n\t\t\tAn equilateral triangle is inscribed in a circle. An arbitrary point $P$ is chosen on arc $BC$. Prove that $|MA|=|MB|+|MC|$\n\t\t\t\\item %% Prasolov 1.25\n\t\t\tAngles $\\alpha$ and $\\beta$ of $\\triangle ABC$ are related as $3\\alpha+2\\beta=180^\\circ$. Prove that $a^2+bc=c^2$.\n\t\t\t\\item %% Prasolov 12.49\n\t\t\tProve that for non right angle triangle with circumcircle radius $R$ and area $S$ the following holds\n\t\t\t$$ \\tan\\alpha+\\tan\\beta+\\tan\\gamma=\\tan\\alpha\\tan\\beta\\tan\\gamma=\\frac{4S}{a^2+b^2+c^2-8R^2}$$\n\t\t\\end{enumerate}\n\t\n\t\\newpage\n\t\n\t\\section{Functional equations}\n\t\t\\begin{enumerate}  \n\t\t\t\\item %% LVS 2016\t\t\n\t\t\tFind all functions defined on all real numbers which satisfy for  all $(x,y)$\n\t\t\t$$f(x+y)f(xy)=f(x^2-y^2-1) $$\n\t\t\t\\item %% LVS 2015\n\t\t\tFind all functions defined on all real numbers which satisfy for all $(x,y)$\n\t\t\t$$f(f(x)+f(y))=f(x)+y $$\n\t\t\t\\item %% LVT 2014\n\t\t\tFind all functions defined on all real numbers which satisfy for all $(x,y)$\n\t\t\t$$f(x^2)+f(xy)=f(f(x+y)) $$\n\t\t\t\\item %%  problemsolvingstrategies p277\n\t\t\tFind all polynomial functions that satisfy $P(x+1)=P(x)+2x+1$\n\t\t\t\\item%%  problemsolvingstrategies p277\n\t\t\tFind all solutions to functional equation $f(x+y) + f(x-y) = 2f(x)\\cos y$\n\t\t\t\n\t\t\t\n\t\t\\end{enumerate}\n\t\n\t\\section{Algebra}\n\t\tMean inequalities:\n\t\t$$\\min (a,b,c) \\leq \\frac{3}{\\frac{1}{a}+\\frac{1}{b}+\\frac{1}{c}} \\leq \\sqrt[3]{abc} \\leq \\frac{a+b+c}{3} \\leq \\sqrt{\\frac{a^2+b^2+c^2}{3}} \\leq \\max (a,b,c)$$\n\t\t\\\\\n\t\tCauchy-Schwarz inequality\n\t\t$$(a_1b_1+...+a_nb_n)^2 \\leq (a_1^2+...+a_n^2)(b_1^2+...+b_n^2) $$\n\t\tGeometric series\n\t\t$$ 1+a+a^2+...a^{n-1}=\\frac{a^n-1}{a-1} $$\n\t\t\n\t\t\n\t\t\\begin{enumerate}\n\t\t\\item\n\t\tProve that\n\t\t$$\\frac{x^2+2}{\\sqrt{x^2+1}} \\geq 2 $$\n\t\t\\item\n\t\tProve that\n\t\t$$ a^2+b^2+c^2 \\geq ab+bc+ac $$\n\t\t\\item\n\t\tFind sum\n\t\t$$ \\frac{1}{1 \\times 2} + \\frac{1}{2 \\times 3} +...+ \\frac{1}{(n-1)\\times n} $$\n\t\t\\item\n\t\tProve that\n\t\t$$ 1+2^2+3^2+...+n^2 = \\frac{n(n+1)(2n+1)}{6} $$\n\t\t\\item\n\t\tLet $n \\geq 3$ be an integer, and let $a_2$, $a_3$, ..., $a_n$ be positive real numbers such that $a_2a_3...a_n = 1$. Prove that\n\t\t$$(1 + a_2)^2(1 + a_3)^3...(1 + a_n)^n > n^n$$\t\t\t\n\t\t\\end{enumerate}\n\t\n\t\\newpage\n\t\n\t\\section{Number Theory}\n\tFermat's Little theorem for prime number $p$ and integer $a$\n\t$$ a^p \\equiv a  \\pmod p$$\n\tEuclidian algorithm\n\t$$ \\gcd(a,b)=\\gcd(a-b,b)$$\n\t\\begin{enumerate}\n\t\t\\item\n\t\tProve that $a^4+4b^4$ is not a prime given $a,b$ are positive integers.\n\t\t\\item\n\t\tFind integer solutions $(x,y)$ in terms of prime $p$ for equation\n\t\t$$ \\frac{1}{x}+\\frac{1}{y}=\\frac{1}{p} $$\n\t\t\\item\n\t\tFind all solutions $(x,y,z)$ in integers for\n\t\t$$ x^2 + y^2 + z^2 = 2xyz $$ \n\t\t\\item\n\t\tFind all prime numbers that are the factors of any number in form of\n\t\t$\\underbrace{111...111}_{n}$ for positive integers $n$.\n\t\t\\item\n\t\tPositive integers $a,b$ satisfy\n\t\t$$ a-b = 5b^2-4a^2 > 0$$\n\t\tShow that $a-b$ is a square of an integer.\n\t\\end{enumerate}\n\t\n\t\\section{Combinatorics}\n\t\\begin{enumerate}\n\t\t\\item\n\t\tThere are 6 people in the room. Each pair of people either knows one another or they do not. Prove that there either 3 people among whom nobody knows another or 3 people among whom all people know one another.\n\t\t\\item\n\t\tIs it possible to cover 2018x2018 board with L-shaped pieces (length 3, width 2) without overlapping?\n\t\t\\item\n\t\tIs it possible to find 5 prime numbers, so that sum of each three of those is also a prime?\n\t\t\n\t\t\\item\n\t\tOn the table there are 13 blue chips, 15 red chips and 17 green chips. In each move two chips of different colour are taken from the table and replaced with two chips of the third colour. Is it possible that after some moves there are equal amount of chips of each colour?\n\t\t\n\t\t\\item\n\t\tEach face of a cube is coloured with a different colour. How many distinct colourings are there?\n\t\t \n\t\\end{enumerate}\n\t\n\\end{document}", "meta": {"hexsha": "de0d8d767adeb294cf8cf9090849355068c2117f", "size": 5679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01_intro.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": "01_intro.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": "01_intro.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": 37.3618421053, "max_line_length": 274, "alphanum_fraction": 0.6536362036, "num_tokens": 2110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6124345858856297}}
{"text": "\\section{Trust Flow}\n  We can now define indirect trust from $A$ to $B$.\n  \\subimport{common/definitions/}{indirecttrust.tex}\n  \\noindent Note that $Tr_{A \\rightarrow B} \\geq DTr_{A \\rightarrow B}$. The next result shows $Tr_{A \\rightarrow B}$ is\n  finite.\n  \\subimport{fc17/theorems/}{convergencetheorem.tex}\n  \\subimport{common/proofsketches/}{convergenceproofsketch.tex}\n  Proofs of all theorems can be found in Appendix A\\ifdefined\\proceedings \\ of the full version \\cite{trustisrisk}\\fi.\n\n  In the setting of \\texttt{TransitiveGame(}$\\mathcal{G}$\\texttt{,}$A$\\texttt{,}$B$\\texttt{)} and $j$ being a turn in which\n  the game has converged, we use the notation $Loss_A = Loss_{A, j}$. $Loss_A$ is not the same for repeated executions of this\n  kind of game, since the order in which players are chosen may differ between executions and conservative players can choose\n  which incoming direct trusts they will steal and how much from each.\n\n  Let $G$ be a weighted directed graph. We investigate the maximum flow on it. For an introduction to maximum\n  flows see Introduction to Algorithms, p. 708 \\cite{clrs}. Considering each edge's capacity as its weight, a flow\n  assignment $X = [x_{vw}]_{\\mathcal{V} \\times \\mathcal{V}}$ with source $A$ and sink $B$ is valid when:\n  \\begin{equation}\n  \\label{flow1}\n    \\forall (v, w) \\in \\mathcal{E}, x_{vw} \\leq c_{vw} \\mbox{ and}\n  \\end{equation}\n  \\begin{equation}\n  \\label{flow2}\n    \\forall v \\in \\mathcal{V} \\setminus \\{A,B\\}, \\sum\\limits_{w \\in N^{+}(v)}x_{wv} = \\sum\\limits_{w \\in N^{-}(v)}x_{vw}\n    \\enspace.\n  \\end{equation}\n  The flow value is $\\sum\\limits_{v \\in N^{+}\\left(A\\right)}x_{Av} = \\sum\\limits_{v \\in N^{-}\\left(B\\right)}x_{vB}$. We do not\n  suppose skew symmetry in $X$. There exists an algorithm $MaxFlow\\left(A, B\\right)$ that returns the maximum possible flow\n  from $A$ to $B$.  This algorithm needs full knowledge of the graph and runs in $O\\left(|\\mathcal{V}||\\mathcal{E}|\\right)$\n  time \\cite{maxflownm}. We refer to the flow value of $MaxFlow\\left(A, B\\right)$ as $maxFlow\\left(A, B\\right)$.\n\n  We will now introduce two lemmas that will be used to prove one of the central results of this work, the Trust Flow\n  theorem.\n  \\subimport{fc17/lemmas/}{flowgamelemma.tex}\n  \\subimport{common/proofsketches/}{flowgameproofsketch.tex}\n  \\subimport{fc17/lemmas/}{gameflowlemma.tex}\n  \\subimport{common/proofsketches/}{gameflowproofsketch.tex}\n  \\subimport{common/theorems/}{trustflowtheorem.tex}\n  \\subimport{common/proofs/}{trustflowproof.tex}\n\n  \\noindent Note that the maxFlow is the same in the following two cases: If a player chooses the evil strategy and if that\n  player chooses a variation of the evil strategy where she does not nullify her outgoing direct trust.\n\n  Further justification of trust transitivity through the use of $MaxFlow$ can be found in the sociological work by Karlan et\n  al. \\cite{kmrs} where a direct correspondence of maximum flows and empirical trust is experimentally validated.\n\n  Here we see another important theorem that gives the basis for risk-invariant transactions between different, possibly\n  unknown, parties.\n  \\subimport{common/theorems/}{riskinvtheorem.tex}\n  \\subimport{common/proofs/}{riskinvproof.tex}\n  \\noindent $A$ can reduce her outgoing direct trust in a manner that achieves (\\ref{primetrust}), since\n  $maxFlow\\left(A, B\\right)$ is continuous with respect to $A$'s outgoing direct trusts.\n", "meta": {"hexsha": "6f0132bb3d58ad777f84c0fd5c965fabdf05b449", "size": 3417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fc17/flow.tex", "max_stars_repo_name": "dionyziz/DecentralizedTrust", "max_stars_repo_head_hexsha": "60f65bff00041e7e940491913bd4ca3f11bf22d9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-03-15T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T14:07:45.000Z", "max_issues_repo_path": "fc17/flow.tex", "max_issues_repo_name": "dionyziz/DecentralizedTrust", "max_issues_repo_head_hexsha": "60f65bff00041e7e940491913bd4ca3f11bf22d9", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-03-07T12:25:26.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-31T14:42:20.000Z", "max_forks_repo_path": "fc17/flow.tex", "max_forks_repo_name": "dionyziz/DecentralizedTrust", "max_forks_repo_head_hexsha": "60f65bff00041e7e940491913bd4ca3f11bf22d9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-03-07T10:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-28T06:32:33.000Z", "avg_line_length": 64.4716981132, "max_line_length": 126, "alphanum_fraction": 0.736318408, "num_tokens": 1023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6124345813059762}}
{"text": "\\section{Excision, and the Eilenberg-Steenrod axioms}\nWe have homotopy invariance and the lexseq of a pair. We claimed that $ H_\\ast(X,A)$ ``depends only on $X-A$''. You have to be careful about this. \n\\begin{definition}\nA triple $(X,A,U)$ where $U\\subseteq A\\subseteq X$ is \\emph{excisive} if $\\overline{U}\\subseteq\\mathrm{Int}(A)$. This is a point-set definition. From an excisive triple you can get a pair $(X-U,A-U)\\subseteq (X,A)$, and this is called an excision.\n\\end{definition}\n\\begin{theorem}\nAn excision induces an isomorphism in homology, i.e., $ H_\\ast(X-U,A-U)\\cong H_\\ast(X,A)$. We might prove this on Wednesday.\n\\end{theorem}\nWhat are some consequences? We'll compute $ H_\\ast(S^n)$ and $ H^\\ast(D^n,S^{n-1})$. Here's the result. We'll use the homeomorphisms $D^n\\simeq \\Delta^n$ and $S^{n-1}\\simeq\\partial\\Delta^n$. Let's write $S^0=\\{0,1\\}$, and $\\iota_n:\\Delta^n\\to\\Delta^n$.\n\\begin{theorem}\n\t\\begin{enumerate}\n\t\\item \\begin{equation*}\n\t H_q(S^n)=\\begin{cases}\\Z = \\langle[c^0_\\ast]\\rangle & q=0,n>0\\\\ \\Z\\oplus\\Z = \\langle[c^0_1],[\\partial\\iota_1]\\rangle & q=n=0 \\\\ \\Z = \\langle[\\partial\\iota_{n+1}]\\rangle & q=n>0 \\\\ 0 & \\text{else} \\end{cases}\n\t\\end{equation*}\n\n\t\\item \\begin{equation*}\n\t H_q(D^n,S^{n-1}) = \\begin{cases}\n\t\\Z=\\langle [\\iota_n]\\rangle & q=n\\\\\n\t0 & \\text{else}\n\t\\end{cases}\n\t\\end{equation*}\n\t\\end{enumerate}\n\\end{theorem}\nIf $n=0$, then we say that $S^{-1}=\\emptyset$. What are the generators of these groups?\n\\begin{proof}\nWe'll use the lexseq, homotopy invariance, and excision. We have the lexseq:\n\\begin{equation*}\n\\xymatrix{ & & \\ar[dll]^\\partial\\\\\n H_q(S^{n-1})\\ar[r] & H_q(D^n)\\ar[r] & H_q(D^n,S^{n-1})\\ar[dll]^\\partial\\\\\n H_{1-1}(S^{n-1})\\ar[r] & H_{q-1}(D^n)\\ar[r] & H_{q-1}(D^n,S^{n-1})\\ar[dll]^\\partial\\\\\n & & &}\n\\end{equation*}\nBut we know that $D^n$ is contractible, so $ H_q(D^n)=\\begin{cases}\\Z & q=n\\\\ 0 & \\text{else}\\end{cases}$. This means that $\\partial: H_q(D^n,S^{n-1})\\cong H_{q-1}(S^{n-1})$ for $q>1$, but when $q=1$, we get $0\\to H_1(D^n,S^{n-1})\\xrightarrow{\\partial} H_0(S^{n-1})\\to H_0(D^n) \\to H_0(D^n,S^{n-1})\\to 0$.\n\nLet's think about the case $n>1$. Then $ H_0(S^{n-1})=\\mathbf{Z}=\\langle[c^0_\\ast]\\rangle$, and $ H_0(D^n)=\\Z=\\langle[c^0_\\ast]\\rangle$, so you have an isomorphism, which means that $ H_0(D^n,S^{n-1})=0$ and $ H_1(D^n,S^{n-1})=0$. Now, let's go to the case $n=1$. Then $ H_0(S^0)=\\Z\\oplus\\Z=\\langle [c^0_\\ast],[\\partial\\iota_1]\\rangle$ and $ H_0(D^0)=\\Z$. But $[\\partial\\iota_1]$ goes to zero, and $[c^0_\\ast]$ goes to the generator of $\\Z= H_0(D^0)$. This means that $ H_1(D^1,S^0)$ is generated by $\\langle[\\iota_1]\\rangle\\cong\\Z$ because the map $ H_1(D^n,S^{n-1})\\to H_0(S^{n-1})$ is the boundary map, so $[\\iota_1]\\mapsto [\\partial\\iota_1]$.\n\nExcision will come into play through the following statement.\n\\begin{prop}\nIf $n>1,q>1$, then $ H_q(D^n,S^{n-1})\\to H_q(D^n/S^{n-1},\\ast)\\cong H_q(S^n,\\ast)\\cong H_q(S^n)$, because $D^n/S^{n-1}\\simeq S^n$. The claim is that this collapse map is an isomorphism.\n\\end{prop}\nThis provides the inductive step. Let's assume we've proved the proposition. Then $ H_q(D^n,S^{n-1})\\cong H_{q-1}(S^{n-1})$. The proposition says that $ H_q(S^n)\\cong H_{q-1}(S^{n-1})$. But we also have the boundary map $\\partial: H_{q+1}(D^n,S^{n-1})\\cong H_q(S^n)$, i.e., $ H_{q+1}(D^n,S^{n-1})\\cong H_q(D^n,S^{n-1})$.\n\nNow I want to prove the proposition. \n\\begin{proof}[Proof of proposition]\nWe want to compare $ H_q(D^n,S^{n-1})$ and $ H_q(D^n/S^{n-1},\\ast)$. We'll use excision to do this. We have $D^n=\\{ x\\in\\mathbf{R}^{n+1} | |x|\\leq 1 \\}$. Let $A=\\{ x|1/3\\leq |x|\\leq 1 \\}$ and $U=\\{ x|2/3<|x|\\leq 1 \\}$, and $\\{ x||x|=1 \\} =S^{n-1}\\subseteq U$. We need a preliminary step. $ H_q(D^n,S^{n-1})\\to H_q(D^n,A)$. We claim that this an isomorphism, but this is true because of the lexseq and the 5-lemma. By excision, $ H_q(D^n,A)\\cong H_q(D^n-U,A-U)$. We can collapse the $(n-1)$-sphere, and $(D^n/S^{n-1}-U/S^{n-1},A/S^{n-1}-U/S^{n-1})=(D^n-U,A-U)$ because you're collapsing something from something that's already been collapsed! Now, we claim that $ H_q(D^n/S^{n-1}-U/S^{n-1},A/S^{n-1}-U/S^{n-1})\\cong H_q(D^n/S^{n-1},A/S^{n-1})$, which is true by excision. THE FOLLOWING PART IS MOST DEFINITELY NOT RIGHT\\footnote{My own comment: this proof can be finished by noticing that $A\\simeq S^{n-1}$ via $\\mathbf{v}\\mapsto\\frac{\\mathbf{v}}{||\\mathbf{v}||}$, and that $D^n/S^{n-1}\\simeq S^n$.}. But also, $ H_q(D^n/S^{n-1},\\text{disk})= H_q(D^n/S^{n-1},A/S^{n-1})$. Because the disk is contractible, using the lexseq and the 5-lemma completes the proof of the proposition.\n\\end{proof}\n\\end{proof}\n``This really turns me on, because I love homology.'' Why should you care about homology?\n\\begin{corollary}\nIf $m\\neq n$, then $S^m\\not\\simeq S^n$ because they have different homology groups. \n\\end{corollary}\n\\begin{corollary}\nIf $m\\neq n$, then $\\mathbf{R}^m\\not\\cong \\mathbf{R}^n$, because they're not homeomorphic.\n\\end{corollary}\n\\begin{proof}\nLet $m,n>0$. Assume we have a homeomorphism $f:\\mathbf{R}^m\\to \\mathbf{R}^n$. This restricts to $\\mathbf{R}^m-\\{0\\}\\to \\mathbf{R}^n-\\{0\\}$, but each of these are homotopy equivalent to spheres, but we can't get a homotopy equivalence between two spheres of different dimension by the above corollary.\n\\end{proof}\n\\subsection{Eilenberg-Steenrod axioms}\n\\begin{definition}\nA homology theory (on $\\mathbf{Top}$) is:\n\\begin{itemize}\n\\item a functor $h_n:\\mathbf{Top}_2\\to\\mathbf{Ab}$ for all $n$. We'll write $h_n(X)=h_n(X,\\emptyset)$\n\\item natural transformations $\\partial:h_n(X,A)\\to h_{n-1}(A)$.\n\\end{itemize}\nsuch that:\n\\begin{itemize}\n\\item if $f_0,f_1:(X,A)\\to (Y,B)$ are homotopic, then $f{0,\\ast}\\simeq f_{1,\\ast}:h_n(X,A)\\to h_n(Y,B)$.\n\\item an excision induces isomorphisms.\n\\item a lexseq:\n\\begin{equation*}\n\\cdots\\to h_{q+1}(X,A)\\xrightarrow{\\partial}h_q(A)\\to h_q(X)\\to h_q(X,A)\\xrightarrow{\\partial}\\cdots\n\\end{equation*}\n\\item (the dimension axiom): $h_n(\\ast)$ is nonzero only in dimension zero. This is like the parallel postulate.\n\\end{itemize}\n\\end{definition}\n\\begin{example}\nOrdinary singular homology satisfies these. \n\\end{example}\n\\begin{theorem}[Brouwer fixed-point theorem]\nIf $f:D^n\\to D^n$, then there is some point $x\\in D^n$ such that $f(x)=x$.\n\\end{theorem}\n\\begin{proof}\nSuppose not. Then you can draw a ray from $x$ to $f(x)$ to the boundary $S^{n-1}$, intersecting at a point $g(x)$. Left to you to check that $g$ is continuous. If $x$ was on the boundary, then $x=g(x)$. This is inconsistent by our computation because otherwise the identity on $ H_{n-1}(S^{n-1})$ would be zero, contradiction!\n\\end{proof}\n", "meta": {"hexsha": "1e84b21bbfc5aaf02b751cec94877d691587f5e9", "size": 6587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-10-eilenberg-steenrod.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-10-eilenberg-steenrod.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-10-eilenberg-steenrod.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": 77.4941176471, "max_line_length": 1177, "alphanum_fraction": 0.6609989373, "num_tokens": 2549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.6123492657532373}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\setcounter{section}{-1}\n\n\\begin{document}\n\n\\title{Introduction to Discrete Analysis}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Introduction}\nasdasd\n\n\\newpage\n\n\\section{The discrete Fourier transform}\n\nLet $N$ be a fixed positive integer. Write $\\omega$ for $e^{2\\pi i/N}$, and $\\Z_N$ for $\\Z/n\\Z$. Let $f:\\Z_N \\to \\C$. Given $r \\in \\Z_N$, define $\\hat{f}(r)$ to be\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{N} \\sum_{x \\in \\Z_N} f(x) \\omega^{-rx}\n\\end{aligned}\n\\end{equation*}\nFrom now on we use the notation $\\E_{x \\in \\Z_N}$ for $\\frac{1}{N}\\sum_{x \\in \\Z_N}$, so $\\hat{f}(r) = \\E_x f(x) e^{-\\frac{2\\pi irx}{N}}$.\n\nIf we write $\\omega_r$ for the function $x \\to \\omega^{rx}$, and $\\bra f,g\\ket$ for $\\E_x f(x) \\overline{g(x)}$, then $\\hat{f}(r) = \\bra f,\\omega_r \\ket$. So the discrete fourier transforn is basically expanding the function $f$ in the set of orthonormal basis $\\omega_r$.\n\nLet us write $||f||_p$ for $\\E_x |f(x)|^p)^{1/p}$ (the $L_p$-norm), and call the resulting space $L_p(\\Z_n)$.\n\nImportant convention: we use \\emph{averages} for the 'original functions' in 'physical spaces', and \\emph{sums} for their Fourier transforms in 'frequency space' (referring to $\\E$: $\\bra,\\ket$ is average in the original space but just $\\sum$ in frequency space, i.e. for $\\hat{f},\\hat{g}$ etc.)\n\n\\begin{lemma} (1, Parseval's identity)\\\\\n    If $f,g: \\Z_n \\to \\C$, then $\\bra \\hat{f},\\hat{g}\\ket = \\bra f,g\\ket$.\n    \\begin{proof}\n        \\begin{equation*}\n            \\begin{aligned}\n                \\bra\\hat{f},\\hat{g}\\ket &= \\sum_r \\hat{f}(r) \\overline{\\hat{g}(r)}\\\\\n                &= \\sum_r (\\E_x f(x) \\omega^{-rx}) (\\overline{\\E_y g(y) \\omega^{-ry}})\\\\\n                &= \\E_x \\E_y f(x) \\overline{g(y)} \\sum_r \\omega^{-r(x-y)}\\\\\n                &= \\E_x \\E_y f(x) \\overline{g(y)} n\\delta_{xy}\\\\\n                &= \\bra f,g\\ket\n            \\end{aligned}\n            \\end{equation*}\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (2, Convolution identity)\\\\\n    \\begin{equation*}\n        \\begin{aligned}\n            \\widehat{f*g}(r) = \\hat{f}(r)\\hat{g}(r)\n        \\end{aligned}\n    \\end{equation*}\n    where\n    \\begin{equation*}\n        \\begin{aligned}\n            (f*g)(x) = \\E_{y+z=x}f(y)g(z) = \\E_y f(y)g(x-y)\n        \\end{aligned}\n    \\end{equation*}\n    \\begin{proof}\n        \\begin{equation*}\n            \\begin{aligned}\n                \\widehat{f*g}(r) &= \\E_x f*g(x)\\omega^{-rx}\\\\\n                &=\\E_x \\E_{y+z=x}f(y)g(z)\\omega^{-rx}\\\\\n                &=\\E_x\\E_{y+z=x} f(y)g(z) \\omega^{-ry}\\omega^{-rz}\\\\\n                &=\\E_y\\E_z f(y) \\omega^{-ry} g(z) \\omega^{-rz}\\\\\n                &=\\hat{f}(r) \\hat{g}(r)\n            \\end{aligned}\n        \\end{equation*}\n    \\end{proof}\n\n\\end{lemma}\n\n\\begin{lemma} (3, Inversion formula)\\\\\n    \\begin{equation*}\n        \\begin{aligned}\n            f(x) = \\sum_r \\hat{f}(r) \\omega^{rx}\n        \\end{aligned}\n    \\end{equation*}\n    (note the sign of $\\omega^{rx}$).\n    \\begin{proof}\n        \\begin{equation*}\n            \\begin{aligned}\n                \\sum_r \\hat{f}(r) \\omega^{rx} &= \\sum_r \\E_y f(y) \\omega^{r(x-y)}\\\\\n                &= \\E_y f(y) \\sum_r \\omega^{r(x-y)}\\\\\n                &= \\E_y f(y) n\\delta_{xy}\\\\\n                &=f(x)\n            \\end{aligned}\n        \\end{equation*}\n        This is really just the statement that we get the original vector back when we sum up its components.\n    \\end{proof}\n\\end{lemma}\n\nFurther observations: If $f$ is real-valued, then $\\hat{f}(-r) = \\E_x f(x) \\omega^{rx} = \\overline{\\E_x f(x) \\omega^{-rx}} = \\overline{\\hat{f}(r)}$.\n\nIf $A \\subset \\Z_n$, write $A$ (instead of $1_A,\\chi_A$) for the characteristic function of $A$. Then $\\hat{A}(0) = \\E_x A(x) = \\frac{|A|}{N}$, the \\emph{density} of $A$.\n\nAlso, $||\\hat{A}||^2_2 = \\bra\\hat{A},\\hat{A}\\ket = \\bra A,A\\ket = \\E_x A(x)^2 = \\E_x A(x) = \\frac{|A|}{N}$, again the density.\n\nLet $f:\\Z_n \\to \\C$. Given $\\mu \\in \\Z_n$, define $f_\\mu(x)$ to be $f(\\mu^{-1}x)$ (so we need $(\\mu,N) = 1$). Then\n\\begin{equation*}\n    \\begin{aligned}\n        \\hat{f}_\\mu(r) &= \\E_x f_\\mu (x) \\omega^{-rx}\\\\\n        &= \\E_x f(x/\\mu) \\omega^{-rx}\\\\\n        &=\\E_x f(x) \\omega^{-r\\mu x}\\\\\n        ^= \\hat{f}(\\mu r)\n    \\end{aligned}\n\\end{equation*}\n\n\\subsection{Roth's theorem}\n\\begin{thm} (4)\n    For every $\\delta > 0$, $\\exists N$ s.t. if $A \\subset \\{1,...,N\\}$ is a set of size at least $\\delta N$, then $A$ must contain an arithmetic progression of length 3.\\\\\n    This is also true for 4,5,..., but the proof is much harder -- Szemeredi's theorem.\\\\\n    Basic strategy of proof: show that if $A$ has density $\\delta$ and no AP of length 3 (3AP), then there's a long AP in $P \\subset \\{1,2,...,n\\}$ s.t.\n    \\begin{equation*}\n        \\begin{aligned}\n            |A \\cap P| \\geq (\\delta+c(\\delta)) |p|\n        \\end{aligned}\n    \\end{equation*}\n    where $c(\\delta)$ is some positive number. But then we can continue this argument to expand $A\\cap P$ to infinity (note that $|A\\cap P|$ is an integer, so each time increase by 1 at least).\n\n    The best known relationship between $\\delta$ and the $N$ required is around $\\delta \\sim \\frac{c}{\\log\\log N}$ for some constant $c$.\n\\end{thm}\n\n---Lecture 2---\n\n\\begin{lemma} (5)\\\\\n    Let $N$ be odd, $A,B,C \\subset \\Z_N$ have densties $\\alpha,\\beta,\\gamma$.\\\\\n    If $\\max_{r \\neq 0} |\\hat{A}(r)| \\leq \\frac{\\alpha(\\beta\\gamma)^{1/2}}{2}$ and $\\frac{\\alpha\\beta\\gamma}{2} > \\frac{1}{N}$, then there exists $x,d \\in \\Z_N$ with $d \\neq 0$ s.t. $(x,x+d,x+2d) \\in A \\times B \\times C$.\n    \\begin{proof}\n        \\begin{equation*}\n            \\begin{aligned}\n                \\E_{x,d} A(x) B(x+d) C(x+2d) &= \\E_{x+z=2y} A(x)B(y)C(z)\\\\\n                &=\\E_u (\\E_{x+z=u}A(x)C(z)) \\E_{2y=u} B(y)\\\\\n                &=\\E_u A * C(u) B_2(u)\\\\\n                &=\\bra A*C,B_2\\ket\\\\\n                &=\\bra\\widehat{A*C},\\hat{B}_2\\ket\\\\\n                &=\\bra \\hat{A}\\hat{C},\\hat{B}_2\\ket\\\\\n                &=\\sum_r \\hat{A}(r)\\hat{C}(r)\\hat{B}(-2r)\\\\\n                &=\\alpha\\beta\\gamma + \\sum_{r \\neq 0} \\hat{A}(r)\\hat{C}(r)\\hat{B}(-2r)\n            \\end{aligned}\n        \\end{equation*}\n        Recall here the notation is $B_2(u) = B(u/2)$. now\n        \\begin{equation*}\n            \\begin{aligned}\n                |\\sum_{r\\neq 0} \\hat{A}(r)\\hat{B}(-2r)\\hat{C}(r)| &\\leq \\frac{\\alpha(\\beta\\gamma)^{1/2}}{2}\\sum_{r \\neq 0} |\\hat{B}(-2r)||\\hat{C}(r)|\\\\\n                &\\leq \\frac{\\alpha(\\beta\\gamma)^{1/2}}{2} \\left(\\sum_r |\\hat{B}(-2r)^2\\right)^{1/2}\\left(\\sum_r |\\hat{C}(r)|^2\\right)^{1/2} \\ \\text{By Cauchy-Schwarz}\\\\\n                &=\\frac{\\alpha(\\beta\\gamma)^{1/2}}{2} ||\\hat{B}||_2 ||\\hat{C}||_2\\\\\n                &= \\frac{\\alpha(\\beta\\gamma)^{1/2}}{2} ||B||_2||C||_2\\\\\n                &= \\frac{\\alpha\\beta\\gamma}{2}\n            \\end{aligned}\n        \\end{equation*}\n        The contribution to $\\E_{x,d} A(x)B(x+d)C(x+2d)$ from $d=0$ is at most $\\frac{1}{N}$, so if $\\frac{\\alpha\\beta\\gamma}{2} > \\frac{1}{N}$, we are done.\n    \\end{proof}\n\\end{lemma}\n\nNow let $A$ be a subset of $\\{1,...,N\\}$ with density $\\geq \\delta$ and let $B=C=A \\cap [\\frac{N}{3},\\frac{2N}{3})$. If $B$ has density $<\\frac{\\delta}{5}$ (??), then either $A \\cap [1,\\frac{N}{3}]$ or $A \\cap [\\frac{2N}{3},N]$ has density at least $\\frac{2\\delta}{5}$. In that case we find an AP $P$ of length about $N/3$ such that $|A \\cap P| / |P| \\geq \\frac{6\\delta}{5}$.\\\\\nOtherwise, we find that if $\\max_{r \\neq 0}|\\hat{A}(r)| \\leq \\frac{\\delta}{10}$ and $\\frac{\\delta^3}{50} > \\frac{1}{N}$, then $A \\times B \\times C$ contains a 3AP, so $A$ contains a 3AP.\\\\\nSo if $A$ does not contain a 3AP, then either we find $P$ of length about $N/3$ with $|A\\cap P| / |P| \\geq \\frac{6\\delta}{5}$, or ther exists $r \\neq 0$ s.t. $|\\hat{A}(r)| \\geq \\frac{\\delta}{10}$.\n\n\\begin{defi}\n    If $X$ is a finite set and $f:X \\to \\C$, $Y \\subset X$, write $osc(f|_Y)$ to mean $\\max_{y_1,y_2 \\in Y} |f(y_1)-f(y_2)|$ (I think \\emph{amplitude} is a better word for this).\n\\end{defi}\n\n\\begin{lemma} (6)\\\\\n    Let $r \\in \\Z_n$ and let $\\varepsilon > 0$. Then there is a partition of $\\{1,2,...,N\\}$ into arithmetic progressions $P_i$ of length at least $c(\\varepsilon)\\sqrt{N}$ such that\n    \\begin{equation*}\n        \\begin{aligned}\n            osc(\\omega_r|_{P_i}) \\leq \\varepsilon\n        \\end{aligned}\n    \\end{equation*}\n    for each $i$.\n    \\begin{proof}\n        Let $t = \\lfloor \\sqrt{N}\\rfloor$. Of the numbers $1,\\omega^r,...,\\omega^tr$, there must be two that differ by at most $\\frac{2\\pi}{t}$.\\\\\n        If $|\\omega^{ar}-\\omega^{br}| \\leq \\frac{2\\pi}{t}$ with $a < b$, then $|1-\\omega^{dr}| \\leq \\frac{2\\pi}{t}$ where $d=b-a$. Then $|\\omega^{urd}-\\omega^{vrd}| \\leq |\\omega^{urd}-\\omega^{(u+1)rd}| + ... + |\\omega^{(v-1)rd}-\\omega^{vrd}| \\leq \\frac{2\\pi}{t}(v-u)$.\\\\\n        So if $P$ is a progression with common differnece $d$ and length $l$, then $osc(\\omega_r|_P) \\leq \\frac{2\\pi l}{t}$. So divide up $\\{1,...,N\\}$ into residue classes mod $d$, and partition each residue class into parts of length between $\\frac{\\varepsilon t}{4\\pi}$ and $\\frac{\\varepsilon t}{2\\pi}$ (possible, since $d \\leq t \\leq \\sqrt{N}$).\\\\\n        We are done, with $c(\\varepsilon) = \\frac{\\varepsilon}{16}$ (a casual choice).\n    \\end{proof}\n\\end{lemma}\nNow let us use the information that $r \\neq 0$ and $|\\hat{A}(r)| \\geq \\frac{\\delta^2}{10}$.\\\\\nDefine the \\emph{balanced function} $f$ of $A$ by $f(x) = A(x)=\\frac{|A|}{N}$ for each $x$.\\\\\nNote that $\\hat{f}(0) = 0$ and $\\hat{f}(r) = \\hat{A}(r)$ for all $r \\neq 0$.\n\nNow let $P_1,...,P_m$ be given by Lemma 6 with $\\varepsilon = \\delta^2/20$. Then\n\\begin{equation*}\n    \\begin{aligned}\n        \\frac{\\delta^2}{10} &\\leq |\\hat{f}(r)|\\\\\n        &= \\frac{1}{N} |\\sum_x f(x) \\omega^{-rx}|\\\\\n        &\\leq \\frac{1}{N} \\sum_{i=1}^m |\\sum_{x \\in P_i} f(x) \\omega^{-rx}|\\\\\n        &\\leq \\frac{1}{N} \\sum_{i=1}^N \\left[\\left|\\sum_{x \\in P_i} f(x) \\omega^{-rx_i}\\right| + \\left|\\sum_{x \\in P_i} f(x) (\\omega^{-rx} - \\omega^{-rx_i})\\right|\\right] \\ x_i \\in P_i \\text{ arbitrary}\\\\\n        &\\leq \\frac{1}{N} \\sum_{i=1}^m |\\sum_{x \\in P_i} f(x)| + \\frac{\\delta^2}{20}\n    \\end{aligned}\n\\end{equation*}\nTherefore $\\sum_{i=1}^m \\left|\\sum_{x \\in P_i} f(x)\\right| \\geq \\frac{\\delta^2 N}{20}$.\n\nWe also have $\\sum_{i=1}^m \\sum_{x\\in P_i} f(x) = 0$, so\n\\begin{equation*}\n    \\begin{aligned}\n        \\sum_{i=1}^m \\left(\\left|\\sum_{x \\in P_i} f(x) \\right| + \\sum_{x \\in P_i}f(x) \\right) \\geq \\frac{\\delta^2}{20} \\sum_{i=1}^m |P_i|\n    \\end{aligned}\n\\end{equation*}\nTherefore, \n\\begin{equation*}\n    \\begin{aligned}\n        &|\\sum_{x \\in P_i} f(x)| + \\sum_{x \\in P_i} f(x) \\geq \\frac{\\delta^2}{20} |P_i|\\\\\n        &\\implies \\sum_{x \\in P_i} f(x) \\geq \\frac{\\delta^2}{40}|P_i|\\\\\n        &\\implies |A \\cap P_i| \\geq \\left(\\delta+\\frac{\\delta^2}{40}\\right)|P_i|\n    \\end{aligned}\n\\end{equation*}\n\n---Lecture 3---\n\nNow let $A \\subset \\Z_N$, $|A| \\geq \\delta N$. Then:\\\\\n$\\bullet$ either $A$ contains a 3AP,\\\\\n$\\bullet$ or $N$ is even,\\\\\n$\\bullet$ or $\\exists P \\subset \\{1,...,N\\}$, $|P| \\geq N/3$ s.t. $|A \\cap P| \\geq \\frac{6\\delta}{5} |P|$,\\\\\n$\\bullet$ or $\\exists P \\subset \\{1,...,N\\}$, $|P|\\geq \\frac{\\delta^2}{640}\\sqrt{N}$ (casual) s.t. $|A\\cap P| \\geq (\\delta+\\frac{\\delta^2}{40})|P|$.\n\nNote that the third case is strictly worse than the fourth.\\\\\nWell if the first is true then we're done. Suppose now the seconds hols. Write $N=N_1+N_2$ with $N_1,N_2$ odd, $N_1,N_2 \\approx\\frac{N}{2}$. Then $A$ has density at least $\\delta$ in one of $\\{1,...,N_1\\}$ or $\\{N_1+1,...,N_1+N_2\\}$.\\\\\nIf (4) holds (note (3) $\\implies$ (4)), then we pass to $P$ and start to again. After $\\frac{40}{\\delta}$ iterations, the density at least doubles. Therefore the toatl number of iterations we can have is at most $\\frac{40}{\\delta} + \\frac{40}{2\\delta}+... \\leq \\frac{80}{\\delta}$.\\\\\nIf $\\frac{\\delta^2}{640} \\sqrt{N} \\geq N^{1/3}$ (to account for the above, and also for the possible use of (2)) at each iteration, and $\\frac{\\delta^3}{25} \\geq N^{-1}$ (which follows from the first condition), then after $\\frac{80}{\\delta}$ iterations we have $N \\geq N^{(1/3)^{80/\\delta}}$, so the argument works provided\n\\begin{equation*}\n    \\begin{aligned}\n        N^{(1/3)^{80\\delta}} \\geq \\left(\\frac{640}{\\delta^2}\\right)^6\n    \\end{aligned}\n\\end{equation*}\ntaking logs and simplify a bit, we need\n\\begin{equation*}\n    \\begin{aligned}\n        &-\\frac{80}{\\delta} \\log 3 + \\log \\log N \\geq \\log 6 + \\log (\\log 640 + 2 \\log \\frac{1}{\\delta}))\\\\\n        &\\Leftarrow \\log\\log N \\geq \\frac{160}{\\delta}\\\\\n        &\\Leftarrow \\delta \\geq \\frac{160}{\\log\\log N}\n    \\end{aligned}\n\\end{equation*}\n\n\\subsection{Bogolyubov's method}\nLet $K \\subset \\hat{\\Z}_N$ and let $\\delta > 0$. The \\emph{Bohr set} $B(K,\\delta)$ has two definitions (not exactly equivalent, but quite equivalent):\\\\\n$\\bullet$ (1) $B(K,\\delta) = \\{x \\in \\Z_N: rx \\in [-\\delta N,\\delta N] \\forall r \\in K\\}$ (arc-length definition);\\\\\n$\\bullet$ (2) $B(K,\\delta) = \\{x \\in \\Z_N: |1-\\omega^{rx}| \\leq \\delta \\forall r \\in K\\}$ (chord-length definition).\n\n\\begin{defi}\n    Let $G$ be an abelian group and let $A,B$ be subsets of $G$. Then write $A + B = \\{a+b: a \\in A, b \\in B\\}$ and the obvious definition for $A-B$. We also write $rA = \\{a_1+...+a_r:a_1,...,a_r\\in A\\}$ (note this might be different than what you think this notation should mean).\n\\end{defi}\n\n\\begin{lemma} (7)\\\\\n    Let $A \\subset \\Z_N$ be a set of density $\\alpha$. Then $2A-2A$ contains a Bohr set $B(K,1/4)$ (arc) with $|K| \\leq \\alpha^{-2}$.\n    \\begin{proof}\n        Observe that $x \\in 2A-2A$ iff $A*A*(-A)*(-A)(x) \\neq 0$ (this makes more sense if we write it as $\\E_{a+b-c-d=x} A(a)A(b)A(c)A(d) \\neq 0$, i.e. we are basically just counting the number of ways $x$ can be written as $a+b-c-d$ where $a,b,c,d \\in A$.)\\\\\n        But\n        \\begin{equation*}\n            \\begin{aligned}\n                A*A*(-A)*(-A)(x) &= \\sum_r \\widehat{A*A*(-A)*(-A)}(r) \\omega^{rx} \\text{ inversion formula}\\\\\n                &= \\sum |\\hat{A}(r)|^4 \\omega^{rx}\n            \\end{aligned}\n        \\end{equation*}\n        Let $K = \\{r: |\\hat{A}(r)| \\geq \\alpha^{3/2}\\}$. Then $\\alpha = ||\\hat{A}||_2^2 = \\sum_r |\\hat{A}(r)|^2 \\geq \\alpha^3 |K|$.\\\\\n        So $|K| \\leq \\alpha^{-2}$.\\\\\n        Now suppose that $x \\in B(K,1/4)$. Then\n        \\begin{equation*}\n            \\begin{aligned}\n                \\sum_r |\\hat{A}(r)|^4 \\omega^{rx} &= \\alpha^4 + \\sum_{r \\in K, r \\neq 0} |\\hat{A}(r)|^4 \\omega^{rx} + \\sum_{r \\not\\in K} |\\hat{A}(r)|^4 \\omega^{rx}\n            \\end{aligned}\n        \\end{equation*}\n        The real part of the second term is non-negative since $rx \\in [-N/4,N/4]$ when $r \\in K$.\\\\\n        Also \n        \\begin{equation*}\n            \\begin{aligned}\n                \\left|\\sum_{r \\not\\in K} |\\hat{A}(r)|^4 \\omega^{rx}\\right| &\\leq \\sum_{r \\not\\in K} |\\hat{A}(r)|^4\\\\\n                &< \\alpha^3 \\sum_{r \\not\\in K} |\\hat{A}(r)|^2\\\\\n                &\\leq \\alpha^4\n            \\end{aligned}\n        \\end{equation*}\n        So it follows that the real part of $\\sum_r |\\hat{A}(r)|^4 \\omega^{rx} > 0$, i.e. it is non-zero. So $x \\in 2A - 2A$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (8)\\\\\n    Let $K \\subset \\Z_N$ and let $\\delta > 0$. Then:\\\\\n    (i) $B(K,\\delta)$ (arc) has density at least $\\delta^{|K|}$;\\\\\n    (ii) $B(K,\\delta)$ contains a mod-$N$ artihmetic progression of length at least $\\delta N^{1/|K|}$.\n    \\begin{proof}\n        (i) Let $K = \\{r_1,...,r_k\\}$. Consider the $N$ $k$-tuples $(r_1x,...,r_kx) \\in \\Z_N^k$. If we intersect this set of $k$-tuples with a random 'box' $[t_1,t_1+\\delta N] \\times ... \\times [t_k,t_k+\\delta N]$ (here we are thinking $t_i$ as real numbers), then the expected number of the $k$-tuples in the box is $\\delta^k N$ (since each one has a probability $\\delta^k$).\\\\\n        But if $(r_1x,...,r_kx)$ and $(r_1y,...,r_ky)$ belong to this box, then $x-y \\in B(K,\\delta)$.\\\\\n        (ii) If we take $\\eta > N^{-1/k}$, then by (i) we get that $|B(K,\\eta)| > 1$, therefore at least 2. So $\\exists x \\in B(K,\\eta)$ s.t. $x \\neq 0$. But then $dx\\in B(K,d\\eta)$ for every $d$.\\\\\n        So if $d\\eta \\leq \\delta$ then $dx \\in B(K,\\delta)$. That gives us an AP of length at least $\\frac{\\delta}{\\eta}$. So we get one of length at least $\\delta N^{1/k}$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{defi}\n    Let $A,b$ be subsets of Abelian groups and let $\\phi:A \\to B$. Then $\\phi$ is a \\emph{Freiman homomorphism of order $k$} if \n    \\begin{equation*}\n        \\begin{aligned}\n            a_1+...+a_k=a_{k+1}+...+a_{2k} \\implies \\phi(a_1)+...+\\phi(a_k) = \\phi(a_{k+1})+...+\\phi(a_{2k})\n        \\end{aligned}\n    \\end{equation*}\n    If $k=2$, we call this just a \\emph{Freiman homomorphism}. In that case, the condition is equivalent to $a-b=c-d \\implies \\phi(a)-\\phi(b)=\\phi(c)-\\phi(d)$.\\\\\n    If $\\phi$ has an inverse which is also a F-homomorphism of order $k$, then $\\phi$ is a F-\\emph{isomorphism} of order $k$.\n\\end{defi}\n\n\\begin{lemma} (9)\\\\\n    Assume $0 \\not \\in K$, and $N$ is prime. If $\\delta < 1/4$, then $B(K,\\delta)$ (arc) is Freiman isomorphic to the intersection in $\\R^{|K|}$ of $[-\\delta N, \\delta N]^{|K|}$ with some lattice $\\Lambda$.\n    \\begin{proof}\n        Let $K = \\{r_1,...,r_k\\}$, and let $\\Lambda = N\\Z^k + \\{(r_1 x,...,r_kx):x \\in \\Z\\}$. Write $\\mathbf{r}$ for $(r_1,...,r_k)$. Claim that $B(K,\\delta) \\cong \\Lambda \\cap [-\\delta N, \\delta N]^k$.\\\\\n        Define a map $\\phi:B(K,\\delta) \\to \\Lambda \\cap [-\\delta N, \\delta N]^k$ by sending $x$ to $(\\bra r_1 x\\ket, ...,\\bra r_k x\\ket)$ where $\\bra u\\ket$ means the least-modulus residue $u$ mod $N$.\\\\\n        If $x+y = z+w$, then $\\mathbf{r} x +\\mathbf{r} y = \\mathbf{r}z+\\mathbf{r}w$ in $\\Z_N^k$. But for each $i$, $\\bra r_ix\\ket+\\bra r_iy\\ket-\\bra r_iz\\ket-\\bra r_iw\\ket \\in [-4\\delta N, 4\\delta N]$. Since $\\delta< 1/4$, that implies that $\\bra r_ix\\ket +\\bra r_iy\\ket-\\bra r_iz\\ket-\\bra r_iw\\ket =0$. So $\\bra\\mathbf{r}x\\ket+\\bra\\mathbf{r}y\\ket=\\bra\\mathbf{r}z\\ket+\\bra\\mathbf{r}w\\ket$.\\\\\n        That already implies that $\\phi$ is an injection.\\\\\n        If $\\mathbf{r}x + \\mathbf{a} N \\in [-\\delta N,\\delta N]^k$, then $r_i x \\in [-\\delta N,\\delta N]$ mod $N$ for each $i$. So $x \\in B(K,\\delta)$ and $\\phi(x) = \\mathbf{r}x + \\mathbf{a} N$. So $\\phi$ is a surjection as well.\\\\\n        If $\\mathbf{r}x+\\mathbf{a}N + \\mathbf{r}y+\\mathbf{b}N = \\mathbf{r}z+\\mathbf{c}N+\\mathbf{r}w+\\mathbf{d}N$, then $r_1(x+y) = r_1(z_w)$ mod $N$, so $x+y=z+w$ mod $N$. So the inverse of $\\phi$ is also a Freiman homomorphism.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{lemma} (10)\\\\\n    Let $\\Lambda$ be a lattice and $C$ be a symmetric convex body, both in $\\R^k$. Then $|\\Lambda \\cap C| \\leq 5^k |\\Lambda \\cap \\frac{C}{2}$|.\n    \\begin{proof}\n        let $x_1,...,x_m$ be a maximal subset of $\\Lambda \\cap C$ such that for all $i \\neq j$, $x_j \\not\\in x_i + \\frac{C}{2}$. Then by maximality, the sets $x_i+\\frac{C}{2}$ over(are?) all of $\\Lambda \\cap C$. Also, the sets $x_i+\\frac{C}{4}$ are disjoint subsets of $\\R^k$, and they are all contained in $C+\\frac{C}{4} = \\frac{5}{4} C$. So $m \\leq \\frac{vol(\\frac{5}{4}C)}{vol(\\frac{1}{4}C)} = 5^k$.\n    \\end{proof}\n\\end{lemma}\n\n\\begin{coro} (11)\\\\\n    If $N$ is prime, $0 \\not \\in K$, $|K| = k$, $\\delta < 1/4$, then $|B(K,\\delta)| \\leq 5^k |B(K,\\frac{\\delta}{2})|$.\n\\end{coro}\n\n\\newpage\n\n\\section{Sumsets and their structure}\nIt's to be shown that $|A+A| \\leq K|A|$ $\\implies$ $|rA-sA| \\leq K^{r+s}|A|$ (Ruzsa).\n\n\\begin{lemma} (1, Petridis)\\\\\n    Let $A_0,B$ be finite subsets of an Abelian group such that $|A_0+B| \\leq K_0|A_0|$. Then there exist a non-empty subset $A \\subset A_0$ and $K \\leq K_0$ s.t. $|A+B+C| \\leq K|A+C|$ for every finite subset $C$ of the group.\n    \\begin{proof}\n        Let $A$ minimize the ratio $\\frac{|A+B|}{|A|}$, and let the minimal ratio be $K$.\\\\\n        Claim: this works. We prove this by induction on $C$.\\\\\n        If $C =\\phi$, then the result holds. Now assume it for $C$ and let $x \\not\\in C$. Then $A+(C \\cup \\{x\\}) = (A+C) \\cup [(A+x) \\setminus (A'+x)]$ where $A' = \\{a \\in A:a+x \\in A+C\\}$.\\\\\n        This is a disjoint union, so $|A+(C\\cup \\{x\\})| = |A+C|+|A|-|A'|$, $A+B+(C\\cup\\{x\\}) = (A+B+C) \\cup ((A+B+x)\\setminus (A'+B+x))$, since if $a+x \\in A+C$ then $a+B+x \\subset A+B+C$. So\n        \\begin{equation*}\n            \\begin{aligned}\n                |A+B+(C\\cup\\{x\\})| &\\leq |A+B+C|+|A+B|-|A'+B|\\\\\n                &\\leq K|A+C|+K|A|-K|A'|\n            \\end{aligned}\n        \\end{equation*}\n        by induction and minimality property of $A$.\n    \\end{proof}\n\\end{lemma}\n\n---Lecture 5---\n\n\\begin{coro} (2)\\\\\n    If $A,B$ are finite subsets of an abelian group, and $|A+B| \\leq K^r|A|$, then there exists $A'\\subset A$, $A' \\neq \\phi$ such that $|A'+rB| \\leq K|A'|$ for every positive integer $r$.\n    \\begin{proof}\n        Choose $A'$ as we choose $A$ in lemma 1. Then $|A'+rB| = |A'+B+(r-1)B| \\leq K|A'+(r-1)B|$.\\\\\n        And $|A'+B| \\leq K|A'|$, so we are done by induction.\n    \\end{proof}\n\\end{coro}\n\n\\begin{coro} (3)\\\\\n    If $|A+A| \\leq K|A|$ or $|A-A| \\leq K|A|$, then $|rA| \\leq K^r|A|$.\n    \\begin{proof}\n        Set $B=A$ or $-A$ in corollary 2. (think about this)\n    \\end{proof}\n\\end{coro}\n\n\\begin{lemma} (4, Ruzsa triangle inequality)\\\\\n    Let $A,B,C$ be finite subsets of an abliean group. Then $|A||B-C| \\leq |A-B||A-C|$.\n    \\begin{proof}\n        Define a map $\\phi: A\\times(B-C) \\to (A-B) \\times (A-C)$. Given $(a,x)$ with $a\\in A, x \\in B-C$, choose, \\emph{somehow}, $b(x) \\in B$ and $c(x) \\in C$ s.t. $b(x) - c(x) = x$, and set $\\phi(a,x) = (a-b(x),a-c(x))$. Note that $(a-c(x)) - (a-b(x)) = b(x)-c(x) = x$ (!). And then, having worked out $x$, we know $b(x)$, and $a=a-b(x)+b(x)$, so $a$ is determined too. So $\\phi$ is an injection.\n    \\end{proof}\n\\end{lemma}\n\nThe proof was easy, but why is this called the triangle inequality? We can rewrite it as \n\\begin{equation*}\n    \\begin{aligned}\n        \\frac{|B-C|}{|B|^{1/2}|C|^{1/2}} \\leq \\frac{|A-B|}{|A|^{1/2}|B|^{1/2}} \\cdot \\frac{|A-C|}{|A|^{1/2}|C|^{1/2}}\n    \\end{aligned}\n\\end{equation*}\nSo if we define the \\emph{Ruzsa distance} $d(A,B) = \\frac{|A-B|}{|A|^{1/2}|B|^{1/2}}$, then the inequality says $d(B,C) \\leq d(A,B) d(A,C)$.\n\n\\begin{coro} (5)\\\\\n    If $|A+B| \\leq K|A|$, then $|rB-sB| \\leq K^{r+s}|A|$ for all $r,s$.\n    \\begin{proof}\n        Pick $a'$ as before. Then by corollary 2 with $B$ replaced by $-B$, $|A'-rB| \\leq K^r|A'|$ and $|A'-sB| \\leq K^s|A'|$.\\\\\n        Therefore, by Rusza triangle inequality (lemma 4), $|A'||rB-sB| \\leq K^{r+s}|A'|^2$, so $|rB-sB| \\leq K^{r+s} |A|$.\n    \\end{proof}\n\\end{coro}\n\nOne finally corollary:\n\\begin{coro} (6, Plunnecke's theorem)\\\\\n    If $|A+A| \\leq K|A|$ or $|A-A| \\leq K|A$, then $|rA-sA| \\leq K^{r+s} |A|$.\n    \\begin{proof}\n        Just apply corollary 5 with $B=-A$ or $B=A$.\n    \\end{proof}\n\\end{coro}\n\n\\begin{lemma} (7, Ruzsa's embedding lemma)\\\\\n    Let $A \\subset \\Z$ be finite and suppose that $|kA-kA| \\leq C|A|$. Then there exists a prime $p \\leq 4C|A|$ and a subset $A'\\subset A$ of size at least $|A|/k$ such that $A'$ is Freiman isomorphic of order $k$ to a subset of $\\Z_p$.\n    \\begin{proof}\n        Consider the following composition of maps $\\Z \\xrightarrow{\\text{ reduce mod }q}\\Z_q \\xrightarrow{\\times \\text{ by random non-zero } r} \\Z_q \\xrightarrow{\\text{least non-negative residue}} \\Z \\xrightarrow{\\text{reduce mod }p} \\Z_p$, where $q$ is a prime bigger than $diam A$ and $p$ is a prime $\\in (2C|A|,4C|A|]$ by Bertrand's postulate.\\\\\n        Let $|phi$ be the composition. THe first, second and fourth parts are group homomorphisms, and thus Freiman homomorphisms of all order. Also, the third map is a Freiman homomorphism of order $k$ if you restrict to a subinterval of $[0,q-1]$ of lemgth $\\leq q/k$. To see this, write $\\bra u \\ket$ for least non-negative residue. Then if $I$ has length $\\leq q/k$ (and therefore $<q/k$) and $u_{1},...,u_{2k} \\in I$, then if $i_1+...+u_k-u_{k+1}-...-k_{2k} = 0$, then $\\bra u_1 \\ket + ... + \\bra u_k \\ket - \\bra u_{k+1} \\ket - ... - \\bra u_{2k} \\ket \\equiv 0 \\pmod q$, and also has modulus less than $q$. So it is zero.\\\\\n        By the pigeonhole principle, for any $r$ we can find $I$ of length $\\leq q/k$ such that $A' = \\{a \\in A: ra \\in I\\}$ has size at least $|A| / k$.\\\\\n        Then $\\phi|_{A'}$ is a Freiman homomorphism of order $k$. It's now remain to prove that $\\phi$ is an isomorphism to its image, i.e. we must show that if $a_1+...+a_k-a_{k+1}-...-a_{2k} \\neq 0 (a_i \\in A)$, then\n        $$ \\bra ra_1\\ket + ... + \\bra ra_k\\ket - \\bra ra_{k+1} \\ket - ... - \\bra ra_{2k} \\ket \\not\\equiv 0 \\pmod p$$\n        But if the $a_i$ are chosen sucth that the $ra_i$ all belong to the same interval of length $\\leq q/k$, then \n        $$|\\bra ra_1\\ket + ... + \\bra ra_k\\ket - \\bra ra_{k+1} \\ket - ... - \\bra ra_k\\ket| < q$$\n        and is congruent to $r(a_1+...+a_k-a_{k+1}-...-a_{2k}) \\pmod q$.\\\\\n        So all that can go wrong is if $r(a_1+...+a_k-a_{k+1} - ... - a_{2k}$ is $xp$ for some $x \\neq 0$, with $|x| < q/p$. The number of values to avoid is at most $2q/p$, so for each $a_1+...+a_k-a_{k+1} - ... - a_{2k}$, the probability of going wrong if $r$ is chosen randomly is at most $2/p$. So since $|kA-kA| \\leq C|A|$, the probability of going wrong is at most $\\frac{2}{p} C|A|$. Since $p > 2C|A|$, there exists $r$ s.t. we get an Freiman isomorphism of order $k$.\n    \\end{proof}\n\\end{lemma}\n\n\\end{document}\n", "meta": {"hexsha": "1330d40b45405f60f69153316d9bd0e077302af4", "size": 25321, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IDA.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/IDA.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/IDA.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": 60.721822542, "max_line_length": 627, "alphanum_fraction": 0.559259113, "num_tokens": 9982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6123487948820894}}
{"text": "\\chapter{Summary of Saleena and Paleri}\n\\label{chap:chapter4}\n\nSaleena and Paleri gave an algorithm for \n\\textbf{global value numbering (GVN)}. GVN works by assigning a value \nnumber to variables and expressions. The same value number is \nassigned to those variables and expressions which are provably \nequivalent. A notable difference between Herbrand equivalence and GVN \nis that in Herbrand equivalence we talk about equivalences at a \nparticular program point but in GVN are concerned with equivalence \nbetween expressions at two different program points.\n\nThe data structure used in the algorithm is called \\textbf{value \nexpression} - an expression with value numbers as operands. Two \nexpressions are equivalent if they have same value expression. \nSo, a value expression can be used to represent a set of equivalent \nprogram expressions.\n\n\\section{Notation}\n\\label{sec:Notation}\nInput is a flow graph atmost one assignment statement in each node\nwhich has one of the following forms\n$$x\\; ::=\\; e$$ \n$$e\\; ::=\\; x\\: |\\: c\\: |\\: x\\,op\\,x$$\nThe flow graph also has two additional empty $ENTRY$ and $EXIT$ nodes.\nFor a node $n$, $IN_n$ and $OUT_n$ denotes the input and output \nprogram points of the node.\n\nExpression pool at a program point, is a partition of expressions at \nthat point, in which equivalent expression belongs to the same \npartition. Each class will have a value number which we will consider \nas its first element. For a node $n$, $EIN_n$ and $EOUT_n$ denotes \nthe expression pools at input and output program points of the node.\n\n\\section{Value Expression}\n\\label{sec:ValueExpression}\nThe value expression corresponding to an expression is obtained by \nreplacing actual operands with their corresponding value numbers.\nExample - For the expression-pool $\\{\\{v_1, a, x\\}$, $\\{v_2, b, y \\}\\}$ \nand statement $z ::= x + y$ , the value-expression for $x + y$ will be\n$v_1 + v_2$. Instead of $x + y$, its value-expression is included in \nthe expression-pool, with a new value number ie. the new \nexpression-pool would be \n$\\{\\{v_1, a, x\\},\\{v_2, b, y\\}, \\{v_3, v_1 + v_2, z\\}\\}$.\n\nThe value expression $v_1 + v_2$ represents not just $x + y$ but the\nset of equivalent expressions $\\{a + b, x + b, a + y, x + y\\}$. Its \npresence indicates that an expression from this set is already \ncomputed and this information is enough for detection of redundant \ncomputations. Also, a single binary value expression can represent \nequivalence among any numbre of expressions of any length. Example - \n$v_1 + v_3$ represents, $a + z$, $x + z$, $a + (a + b)$, \n$a + (x + b)$ and so on.\n\n\\section{Algorithm}\n\\label{sec:Algorithm}\nSimilar to Gulwani's algorithm, the algorithm consists of two main \nfunctions - a transfer function for changes in expression pool across \nassignment statements and a confluence function to find the \nexpression pool at points were two branches meet. The algorithm \nstarts with $EOUT_{ENTRY} = \\phi$, and uses transfer and confluence \nfunctions to calculate expression pools at other points. This process \nis repeated till there is any change in the equivalence information.\nFor detailed implementation refer to \\cite{Saleena}.\n", "meta": {"hexsha": "5d4307d82287df3e4f98b5bdc805ba1455d4a933", "size": 3162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Rep_Mid_8/chapter4.tex", "max_stars_repo_name": "himanshu520/HerbrandEquivalence", "max_stars_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_stars_repo_licenses": ["MIT"], "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/Rep_Mid_8/chapter4.tex", "max_issues_repo_name": "himanshu520/HerbrandEquivalence", "max_issues_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_issues_repo_licenses": ["MIT"], "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/Rep_Mid_8/chapter4.tex", "max_forks_repo_name": "himanshu520/HerbrandEquivalence", "max_forks_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_forks_repo_licenses": ["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.6461538462, "max_line_length": 72, "alphanum_fraction": 0.7504743833, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6123487931307586}}
{"text": "\\chapter{Sampling with sufficient statistics}\nThis chapter will go in depth of generating samples from the NHPP given its sufficient statistics. The main focus will be a Gibbs sampler with a Metropolis-Hastings step, and discuss possible modifications.\n\\section{Gibbs sampler}\nThe Gibbs sampler is Markov chain Monte Carlo (MCMC) sampler. A MCMC sampler is a way to sample from a distribution by contructing a Markov chain with spesific equilibrium. From \\cite{casella1992explaining} we have that the Gibbs sampler is used when direct sampling is difficult or cannot be done. This sampler samples from a conditional distribution. This can be done with sufficient statistics.\n\\section{Metropolis-Hastings sampler}\nThis is also a MCMC sampler where direct sampling is difficult. However this is used when the conditional posterior is unknown. Hence this uses a proportional density instead, and has an acceptance rejection step to determine if the new sample is from the desired distribution.\n\\section{Gibbs with Hastings step}\n\\label{sec:gibbsmet}\nA Gibbs sampler with a Metropolis-Hastings step is what we used in this project \\cite{gilks1995adaptive}. Since the values of the sufficient statistics cannot differ from the original data set, the sampler must generate new samples with the same values for the sufficient statistics. Given a sample with $N$ points and number of sufficient statistics, one can draw three arbitrary points and draw a new value for one of the points given the two others. By setting one of the points one can calculate the two others. This is where the Metropolis-Hastings step is used to draw a new value. How to find a new value is shown in section \\ref{sec:draw}. Further when this new value is drawn the two other values must be adjusted to fulfill the sufficient statistics. This should be done serveral times for each sample. The reason for this is to make the samples independent.\n\\subsection{Drawing a new value}\n\\label{sec:draw}\nAssume we have chosen three points ($X_1, X_2, X_3$) from our sample and that we have the same sufficient statistics as in section \\ref{sec:sufstat}. It is these three points that are going to be updated. The idea is to draw a new value for one of them as stated in section \\ref{sec:gibbsmet}. Assume $\\tau = 1$. Hence all values in the samples must be between 0 and 1.  This makes it easier for the uniform distribution. To draw a new value we need to use tranformation of variables from section \\ref{sec:transvar}. The tranformation is\n\\begin{equation*}\n(Z_1, Z_2, Z_3) = (\\sum_{i=1}^{3} X_i, \\prod_{i=1}^{3} X_i, X_3).\n\\end{equation*}\nThis will yield the probability density $f_{Z_1, Z_2, Z_3}(z_1, z_2, z_3)$. However we are interested in $f_{Z_3 | Z_1, Z_2}(z_3 | z_1, z_2)$, where $Z_3=X_3$ is the variable drawn from this distribution. Fortunately from Bayes rule  \\cite{casella2002statistical} the distribution becomes\n\\begin{equation*}\nf_{Z_3 | Z_1, Z_2}(z_3 | z_1, z_2) \\propto f_{Z_1, Z_2, Z_3}(z_1, z_2, z_3).\n\\end{equation*} \nFurther we continue with tranformation of variables. The determinant of the Jacobian matrix then becomes\n\\begin{equation*}\n|J| = X_3 (X_2 - X_1).\n\\end{equation*}\nWe also have the following relations from the tranformation, where we have put $a = Z_1$ and $b = Z_2$\n\\begin{align*}\nX_1 + X_2 + X_3 = a \\\\\nX_1 + X_2 = a - X_3 \\\\\nX_1 \\cdot X_2 \\cdot X_3 = b \\\\\nX_1 \\cdot X_2 = \\frac{b}{X_3}.\n\\end{align*}\nThen $X_1$ and $X_3$ are the roots of\n\\begin{equation*}\nX^2 - (a - X_3) X^2 + \\frac{b}{X_3} = 0,\n\\end{equation*}\nwhich are\n\\begin{equation*}\nX_{(1,2)} = \\frac{(a - X_3) ± \\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}}}{2}.\n\\end{equation*}\nFrom this the jacobian becomes\n\\begin{equation*}\n|J| = X_3\\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}}.\n\\end{equation*}\nFrom paper \\cite{lockhart2007use} the determinant of the inverse jacobian is\n\\begin{equation*}\n|J|^{-1} = \\frac{1}{X_3\\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}}}.\n\\end{equation*}\nSince we have that\n\\begin{equation*}\nf_{X_1, X_2, X_3}(x_1, x_2, x_3) = 1, \\quad 0 \\leq x_i \\leq 1 \\text{ for all }i,\n\\end{equation*}\nthe density to draw new values for $X_3$ becomes\n\\begin{equation*}\n\\Pi \\propto \\frac{1}{X_3\\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}}}.\n\\end{equation*}\nThis is where the Metropolis-Hastings step is used. The requirements for this density are listed below.\n\\begin{align}\n0 \\leq X_3 \\leq \\min(1, a) \\label{eq:req1} \\\\\n(a - X_3)^2 - \\frac{4b}{X_3} \\geq 0 \\label{eq:req2}\\\\ \n(a - X_3) + \\sqrt{(a - X_3)^2 - \\frac{4b}{X_3}} \\leq 1. \\label{eq:req3}\n\\end{align}\nSo when we draw from a proposal density like a uniform distribution we need to make sure that the new $X_3$ fulfills these requirements. If the requirements are not fulfilled then the probability of accepting this new value is zero. If the requirements are fulfilled then the acceptance probability is defined as,\n\\begin{equation}\n\\alpha = \\min\\left(1, \\frac{\\Pi(X_{prop})}{\\Pi(X_{curr})}\\right)\n\\label{eq:alpha}\n\\end{equation}\nAn overview of the algorithm is shown below.\n\\begin{algorithm}\n\\caption{Generate new samples with sufficient statistics}\n\\label{alg:simdata}\n\\begin{algorithmic}\n\\STATE Draw 3 arbitrary indices from $\\{1,2,...,n\\}$\n\\STATE Caclulate sum $a$ and product $b$ of the corresponding $X$'s.\n\\STATE Draw a proposal $X_3$ from $U[0,\\min(a,1)]$.\n\\STATE Check requirements in equations \\ref{eq:req1}, \\ref{eq:req2} and \\ref{eq:req3}.\n\\STATE Calculate $\\alpha$ from equation \\ref{eq:alpha}.\n\\STATE Accept with probability $\\alpha$\n\\STATE Repeat from top desired times to make sample approximately independent.\n\\end{algorithmic}\n\\end{algorithm}\n\\subsection{Possible modifications}\nIn our current version if the sampler generates invalid values for the three new indices in a sample, the algorithm tries over again with three new indices. One possible modification is to not try over again with three new indices, but keep the three indices and draw new random value. However the area for valid values might be small. Hence this modification might not be recommended.\n\\\\\n\\\\\nAnother modification is to use the indices of the entire sample when generating a new sample. This has been done before for related distribution in \\cite{lockhart2007use}. The pros of this method is that you have chance of getting new  values for more of the indices. However the cons is that the values for the sub sums and sub products are sensitive to large and small values when a larger number of indices are used.\n", "meta": {"hexsha": "1d94fa9d68ed2fa27916f908e3862a392e1a31fe", "size": 6406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/samplingsufficient.tex", "max_stars_repo_name": "mariufa/ProsjektOppgave", "max_stars_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_stars_repo_licenses": ["MIT"], "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/samplingsufficient.tex", "max_issues_repo_name": "mariufa/ProsjektOppgave", "max_issues_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_issues_repo_licenses": ["MIT"], "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/samplingsufficient.tex", "max_forks_repo_name": "mariufa/ProsjektOppgave", "max_forks_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_forks_repo_licenses": ["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.3647058824, "max_line_length": 868, "alphanum_fraction": 0.7508585701, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6123487816217555}}
{"text": "%%!TEX TS-program = latex\n\\documentclass[11pt]{article} %DIF > \n\\usepackage{etex}\n\\usepackage[utf8]{inputenc}\n\\input ../AuxFiles/PreambleNotes.tex\n\n\n\\begin{document}\n\\onehalfspace\n\n\\vspace*{\\fill}\n\\begingroup\n\\centering\n\n\\Large {\\scshape Introduction to Statistics}\\\\\n\n(Lectures 11-12: Confidence Sets)\n\n\\endgroup\n\\vspace*{\\fill}\n\n\\newpage\n\n\n\\section{Confidence Sets}\n\n{\\scshape Overview:} \\noindent Lectures 11-12 will focus on the construction of \\emph{confidence sets}. The actions are subsets of the parameter space. Each action is interpreted as a region that (presumably) contains the parameter selected by nature. The loss function we work with is a convex combination of ``volume’’ and ``coverage’’, in a sense we will make precise.\n\nWe first show that Bayes rules for this problem are ``highest posterior density” sets: the collection of parameters with a sufficiently high posterior probability. We then argue that in large samples, highest posterior density sets can be approximated by ``inverting’’ a Wald test. When the parameter of the model is scalar, inverting the Wald test is tantamount to reporting the interval formed by the Maximum Likelihood estimator $\\pm$ $c$ times its estimated “standard error”.\n\nWe then introduce and analyze two popular algorithms for summarizing the uncertainty in parameter estimation: (parametric) bootstrap confidence intervals and Bayesian ``credible’’ intervals. We use these algorithms to construct confidence/credible regions for one of the possibly many coefficients of the Linear Regression model. \n\n\\subsection{Description of the problem} \n\nLet $X$ be a random variable and let $\\{f(x | \\theta)\\}_{\\theta \\in \\Theta}$ be a statistical model. The problem of constructing a confidence set for $\\theta$ starts as follows. In the first stage nature picks an element of the parameter space, which in this section we model explicitly as a subset of $\\mathbb{R}^{k}$. The econometrician cannot observe the parameter selected by nature but observes data. Based on the data, the econometrician has to suggest a ``region’’ of the parameter space that is likely to contain the true parameter selected by nature. \n\nIn principle, the action space for the econometrician based on the description above is the power set of $\\Theta$. A minor technical restriction is that the econometrician can only report regions that are ``measurable’’. This happens because the ``volume’’ of whatever set is reported will be part of the loss function. Let $\\mathcal{C}$ denote the class of regions that the econometrician can report and let $c$ denote an element of $\\mathcal{C}$. \n\nA \\emph{decision rule/algorithm/strategy} for this problem is a mapping\n\\begin{equation*}\nC:X \\rightarrow \\mathcal{C}\n\\end{equation*}\nThese decision rules will be called ``confidence’’ regions.  \n\n\n\\subsection{Loss function}\n\nThe payoff/loss for the econometrician depends on the action taken ($c \\in \\mathcal{C}$) and the true parameter ($\\theta$). The following loss is sometimes used to evaluate confidence sets:\n\\[ \\mathcal{L}_{\\delta}(c, \\theta) = \\delta \\mathbf{1}\\{ \\theta \\notin c \\} + (1-\\delta)\\int_{c} d\\theta, \\]\n\n\\noindent where $\\delta \\in (0,1)$. The first component in the loss function above penalizes the econometrician whenever $\\theta$ does not belong to $c$. The econometrician could avoid the penalty by reporting a ``large’’ region (for example, reporting $\\Theta$).  The second component makes large regions unattractive by taking into account their volume. \n\nThe expected loss (risk) of a confidence region $C$ is given by\n\n\\begin{equation} \\label{equation:TypeI}\n\\mathbb{E}_{f(x|\\theta)} [  \\mathcal{L}_{\\delta}(C(x),\\theta)   ] = \\delta (1-P_{f(x|\\theta)} ( \\theta \\in C(x) ))  + (1-\\delta) \\mathbb{E}_{f(x|\\theta)} [ \\textrm{Vol}(C(x))].\n\\end{equation}\n\n\n\\noindent The term \n\\[ P_{f(x|\\theta)} ( \\theta \\in C(x) ) \\]\nis typically referred to as the \\emph{coverage probability} of $C(\\cdot)$ at $\\theta$. This captures how often the confidence region contains the parameter $\\theta$ when the data is indeed generated by it. The worst coverage probability over the parameter space:\n\n\\[ \\inf_{\\theta \\in \\Theta} P_{f(x|\\theta)} ( \\theta \\in C(x) )  \\]  \n\n\\noindent is called the \\emph{confidence level} of the confidence set $C(x)$. \n\n\\subsection{Minimizing Posterior-Loss}\n\nWe now present a rule that minimizes posterior-loss. Any such rule, by construction, cannot be uniformly improved: there is no other region that has better coverage everywhere and also smaller expected volume. Let $\\pi(\\cdot)$ denote a prior over $\\Theta$ and let $\\pi(\\theta | x)$ denote the posterior. \n\nThe posterior loss of an action $c$ is given by:\n\n\\[ \\delta(1- P_{\\pi(\\theta | x)}( \\theta \\in c  )) + (1-\\delta) \\int_{c} d \\theta.   \\]\n\n\\noindent The term \n\\[ P_{\\pi(\\theta | x)}( \\theta \\in c ) = \\int_{c} \\pi(\\theta | x) d \\theta  \\] \n\\noindent is the posterior probability that $\\theta$ falls in a set $c$. Such probability is usually referred to as the \\emph{credibility} of $c$. Algebra shows that the posterior loss can be written as\n\n\\[ \\delta - \\int_{c}  \\left(  \\delta \\pi(\\theta | x) - (1-\\delta) \\right) d\\theta.  \\]\n\n\\noindent Thus, for each $x$, the posterior loss is minimized by choosing\n\\begin{equation} \\label{equation:HPD}\nC^{\\textrm{Bayes}}_{\\delta}(x) = \\{ \\theta \\in \\Theta \\: | \\: \\pi(\\theta | x) \\geq (1-\\delta)/\\delta  \\}.\n\\end{equation}\nThe region above is called a ``highest posterior density’’ region. As it is name suggests, the region collects the points in the parameter space for which the posterior density is above certain threshold. \n\nIn general, it is hard to give closed form expressions for the highest posterior density region. However, in large samples it is possible to provide (heuristic) approximations for these regions; exploiting the fact that---regardless of the prior---the posterior distribution is approximately distributed as\n\\[  \\mathcal{N}_{k} \\left(  \\widehat{\\theta}_{\\textrm{ML}} \\quad, \\quad \\widehat{I}^{-1} \\right),   \\]\n\\noindent where $\\widehat{I}$ is the observed information. This means that highest posterior density regions will be approximately of the form \n\\begin{eqnarray*}\n\\left \\{ \\theta \\in \\Theta \\: \\Bigg | \\:  \\frac{1}{ (2 \\textrm{det} \\widehat{I}))^{k/2} } \\exp \\left( -\\frac{1}{2} (\\theta - \\widehat{\\theta}_{\\textrm{ML}}) ’\\widehat{I}   (\\theta - \\widehat{\\theta}_{\\textrm{ML}})\\right)  \\geq (1-\\delta)/\\delta \\right \\}, \\\\\n\\end{eqnarray*}\nwhich can be written as \n\\[ \\left \\{ \\theta \\in \\Theta \\: \\Bigg | \\:  (\\widehat{\\theta}_{\\textrm{ML}} - \\theta) ’\\widehat{I}   (\\widehat{\\theta}_{\\textrm{ML}}-\\theta)   \\leq \\widehat{c}_{\\delta} \\right \\}, \n\\]\n\\noindent where $\\widehat{c}_{\\delta}$ is some function that depends on $\\delta$ and $\\widehat{I}$ but not on $\\theta$. Recognize the quadratic form as the Wald statistic for the problem\n\\[ \\mathbf{H}_0: \\theta = \\theta_0, \\textrm{ vs. } \\mathbf{H}_1: \\theta \\neq \\theta_0. \\]\nThus, in large samples, highest-posterior density regions are approximately given by those points in the parameter space in which the Wald statistic is below certain threshold that might depend on the data. \n\nWhen $\\theta$ is scalar, the approximation takes the form\n\\[ \\Big[ \\widehat{\\theta}_{\\textrm{ML}} - \\sqrt{\\frac{\\widehat{c}_{\\delta}}{\\widehat{I}}} \\:, \\: \\widehat{\\theta}_{\\textrm{ML}} + \\sqrt{\\frac{\\widehat{c}_{\\delta}}{\\widehat{I}}} \\Big]  \\]\n\n\n\\noindent {\\scshape Example:} We derive the highest posterior density region for a linear regression model with known variance. We have shown that if the prior density is that of a $\\mathcal{N}_{k}(0, \\sigma^2 (\\mathbb{I}_n/\\lambda))$, the posterior of $\\beta$ is given by\n\\[  \\beta | Y, X \\sim \\mathcal{N}_{k} ( m , V   ),  \\]\nwhere \n\\begin{eqnarray*}\nm  &\\equiv& (X’X + \\lambda \\mathbb{I}_n)^{-1} X’Y, \\\\\nV  & \\equiv & \\sigma^2  (X’X + \\lambda \\mathbb{I}_n)^{-1}.\n\\end{eqnarray*}\n\\noindent The highest-posterior density region is thus \n\\begin{eqnarray*}\nC_{\\delta}(x) &= & \\left \\{ \\beta \\in \\mathbb{R}^{k} \\: \\Big | \\:  \\frac{1}{ (2 \\textrm{det} V))^{k/2} } \\exp \\left( -\\frac{1}{2 } (\\beta - m) ’V^{-1}  (\\beta - m) \\right)  \\geq (1-\\delta)/\\delta \\right \\}, \\\\\n&=&  \\left \\{ \\beta \\in \\mathbb{R}^{k} \\: \\Big | \\:   (\\beta - m) ’V^{-1}  (\\beta - m)  \\leq \\widehat{c}_{\\delta,X,\\sigma^2} \\right \\}.\n\\end{eqnarray*}\n\n\\noindent This is an ellipse centered at the posterior mean. In large samples, \n$$ m \\approx \\widehat{\\beta}_{\\textrm{OLS}}, \\quad V \\approx \\sigma^2 (X’X)^{-1}.$$\nHence, the highest-posterior density region is approximately given by \n\\[ \\left \\{ \\beta \\in \\mathbb{R}^{k} \\: \\Big | \\:  \\frac{1}{\\sigma^2}(\\widehat{\\beta} - \\beta) ’(X’X)  (\\widehat{\\beta} - \\beta)  \\leq \\widehat{c}_{\\delta,X,\\sigma^2} \\right \\}. \\]\n\n\\noindent This is set of all parameter values for which the Wald test for the null $\\beta = \\beta_0$ is low enough. \n\n\\subsection{Confidence Regions and Hypothesis Testing}\nThere is a connection between confidence regions and tests of hypothesis that goes beyond the approximation argument above. Any family of tests of size $\\alpha$ can be ``inverted’’ to construct a confidence region with confidence level of at least $1-\\alpha$. Likewise, any confidence region with confidence level $1-\\alpha$ can be transformed into a statistical test with rate of Type 1 error of at most $\\alpha$. \n\n{\\scshape Inverting a family of tests:} Let $\\{\\phi_{\\theta}\\}_{\\theta \\in \\Theta}$ denote a collection of non-randomized tests. Suppose each element in the collection is a test for the problem\n\\[ \\mathbf{H}_0: \\theta =\\theta_0, \\quad \\mathbf{H}_1: \\theta \\neq \\theta_0. \\]\nSuppose further that each test has size of at most $\\alpha$ in the sense that\n\\[ \\mathbb{P}_{f(x|\\theta)} [\\phi_{\\theta}(x)=1] \\leq \\alpha. \\]\n\n\\noindent The confidence region obtained by ``test inversion’’ is given by\n\n\\[ C  (x) \\equiv \\{ \\theta \\in \\Theta \\: | \\: \\phi_{\\theta}(x)=0\\}. \\]\n\n\\noindent The coverage of such confidence region at $\\theta$ is given by\n\\begin{eqnarray*}\nP_{f(x|\\theta)} [\\theta \\in C(x)] &=& 1-P_{f(x|\\theta)} [\\theta \\notin C(x)]  \\\\\n&=& 1- P_{f(x|\\theta)} [ \\phi_{\\theta}(x) = 1] \\\\\n& \\geq & 1-\\alpha.   \n\\end{eqnarray*}\n\\noindent Therefore, \n\\[\\inf_{\\theta \\in \\Theta} P_{f(x|\\theta)} [\\theta \\in C(x)] \\geq 1-\\alpha,   \\]\n\\noindent which implies that the confidence region formed by test inversion has confidence level, provided each of the tests $\\phi_{\\theta}$ have size of at $\\alpha$. \\\\\n\n{\\scshape Using a confidence region to test a hypothesis:} A confidence region with $C(x)$ confidence level of at least $1-\\alpha$ can be readily used to test a hypothesis of the form\n\\[ \\mathbf{H}_0: \\theta =\\theta_0 \\quad \\textrm{vs.} \\quad \\mathbf{H}_1: \\theta \\neq \\theta_0. \\]\n\nConsider the test $\\phi$ that rejects the null hypothesis above whenever $\\theta \\notin C(x)$. The rate of Type I error of the test is \n\\begin{eqnarray*}\nP_{f(x| \\theta)} [ \\phi(x)=1 ]  &=&  P_{f(x| \\theta)} [\\theta \\notin C(x)] \\\\\n&=&   1-  P_{f(x| \\theta)} [\\theta \\in C(x)]  \\\\\n&\\leq& 1- \\inf_{\\theta \\in \\Theta} P_{f(x| \\theta)} [\\theta \\in C(x)] \\\\\n&\\leq& 1-(1-\\alpha) =\\alpha.\n\\end{eqnarray*}\n\n\n\\subsection{Parametric Bootstrap and Bayesian Credible sets}\n\n\\subsubsection{The Parametric Bootstrap}\n\nSuppose that we have a statistical model $\\{ f(x | \\theta)\\}_{\\theta \\in \\Theta}$ for data $X$.  The estimator $\\widehat{\\theta}_{\\textrm{ML}}$ is a random variable, as it depends on the data. If $\\theta$ were known, we could approximate the distribution of $\\widehat{\\theta}_{\\textrm{ML}}$ by Monte-Carlo methods: generate $I$ independent draws from $x \\sim f(x;\\theta)$, and evaluate $\\widehat{\\theta}_{\\textrm{ML}}$ over the $I$ new data sets that we have generated.  \\\\\n\n\nThe true parameter that generated the data is unknown; hence it is not possible to generate draws from the model $f(x;\\theta)$. However, since there is an estimator for $\\theta$, one could perform the Monte-Carlo approximation exercise described above by using draws from the model:\n\n\\[ f(x | \\widehat{\\theta}_{\\textrm{ML}}).\\]\n\nIf we do this, we will effectively end with $I$ estimators (one for each new data set). Suppose that the sample size is large enough to guarantee that $\\widehat{\\theta}_{\\textrm{ML}}$ is close to the true $\\theta$ (whatever the true value might be) with high probability. If the parametric model $f(x | \\theta)$ varies smoothly with $\\theta$, the c.d.f. based on the $I$ estimators can be shown to be a reasonable approximate for the distribution of $\\widehat{\\theta}_{\\textrm{ML}}$. If the parameter of interest is some function $g(\\theta)$, the procedure above also provides an approximation for $g(\\widehat{\\theta}_{\\textrm{ML}})$, provided $g$ is smooth. \\\\\n\nThe exercise described above is known as the \\underline{parametric bootstrap} and it is a general statistical technique used to estimate the distribution of $\\widehat{\\theta}_{\\textrm{ML}}$ or any function smooth function $g(\\widehat{\\theta}_{\\textrm{ML}})$. \\\\\n\n\\noindent {\\scshape Example:} Consider the linear regression model with unknown variance\n\\[ Y \\sim \\mathcal{N}_n (X\\beta, \\sigma^2 \\mathbb{I}_n). \\]\nThe parameters of the model are $\\beta = (\\beta_1, \\ldots, \\beta_{k})’$ and $\\sigma^2$. Suppose we want to construct a confidence region for the $\\beta_1$. The ML estimators for $\\beta$ and $\\sigma^2$ are\n\\[ \\widehat{\\beta}_{\\textrm{ML}} = (X’X)^{-1}X’Y, \\quad \\widehat{\\sigma}^2_{\\textrm{ML}} = (Y-X \\widehat{\\beta}_{\\textrm{ML}})’ (Y-X \\widehat{\\beta}_{\\textrm{ML}})/n.  \\]\n\n\\noindent The parametric bootstrap algorithm starts by generating $I$ new data sets, independently according to the distribution\n\\[ Y(i)  \\sim \\mathcal{N}_{n}( X \\widehat{\\beta}_{\\textrm{ML}}\\:, \\: \\widehat{\\sigma}^2_{\\textrm{ML}} \\mathbb{I}_n).   \\]\n\\noindent For each of these data sets, we can compute \n\n\\[ \\widehat{\\beta}_{\\textrm{ML}}(i) = (X’X)^{-1}X’Y(i), \\quad \\widehat{\\sigma}^2_{\\textrm{ML}} = (Y(i)-X \\widehat{\\beta}_{\\textrm{ML}}(i))’ (Y(i)-X \\widehat{\\beta}_{\\textrm{ML}}(i))/n,  \\]\n\n\\noindent and collect the first component of $ \\widehat{\\beta}_{\\textrm{ML}}(i)$:\n\n\\[  \\widehat{\\beta}_{\\textrm{ML}}(i)_1 = e_1’ \\widehat{\\beta}_{\\textrm{ML}}(i), \\]\n\n\\noindent where $e_1$ is the first column of the identity matrix of dimension $k$. Let $\\widehat{q}_{\\eta}$ denote the $\\eta$ quantile of $\\{ \\widehat{\\beta}_{\\textrm{ML}}(i)_1\\}_{i=1}^{I}$. The parametric bootstrap confidence interval for $\\beta_1$ (of ``nominal’’ level $1-\\alpha$) for $\\beta_1$ is thus given by\n\\[ C_{\\textrm{Bootstrap}}(Y,X) \\equiv [ \\widehat{q}_{\\alpha/2} \\:, \\: \\widehat{q}_{(1-\\alpha)/2} ]. \\] \n\n\\subsection{Credible Sets based on the quantiles of the posterior}\nThe quantiles of the posterior provide an off-the-shelf algorithm to construct ``credible’’ regions for any real-valued function $g(\\theta)$. Start with the parametric model $\\{f(x|\\theta)\\}$ and let $\\pi(\\theta)$ be a prior. Suppose that we can generate $I$ draws from the posterior distribution $\\pi(\\theta | x)$. Denote these draws $\\{ \\theta(i) \\})_{i=1}^{I}$. For each of these draws we can construct\n\\[ \\Big\\{ g(\\theta(i)) \\Big\\}_{i=1}^{I}. \\]\nLet $\\widehat{p}_{\\eta}$ denote the $\\eta$ quantile of $\\{ g(\\theta(i))\\}_{i=1}^{I}$. The interval with credibility of approximately $1-\\alpha$ is equal to\n\\[ C_{\\textrm{Bayes}} \\equiv [ \\widehat{b}_{\\alpha/2} \\:, \\: \\widehat{b}_{(1-\\alpha)/2} ]. \\] \n\n\\noindent {\\scshape Example:} Let’s go back to the linear regression model with unknown variance. The parameter of interest is still $\\beta_1$. The prior is $\\mathcal{N}_{k}(0, \\sigma^2 (\\mathbb{I}_n/\\lambda))$. The posterior of $\\beta$ (conditional on $\\sigma^2$) is given by\n\\[  \\beta | Y, X, \\sigma^2 \\sim \\mathcal{N}_{k} ( m , V   ),  \\]\nwhere \n\\begin{eqnarray*}\nm  &\\equiv& (X’X + \\lambda \\mathbb{I}_k)^{-1} X’Y, \\\\\nV  & \\equiv & \\sigma^2  (X’X + \\lambda \\mathbb{I}_k)^{-1}.\n\\end{eqnarray*}\nThe posterior distribution for distribution for $\\sigma^2$ is an Inverse-Gamma($a_n$,$b_n$) where\n\\[ a_n = a_0 + n/2, \\quad b_n = b_0 + \\frac{1}{2}( (Y-Xm)’(Y-Xm) + \\lambda m’m ). \\]\n\nWe can generate $I$ draws for $\\sigma^2$ from the Inverse-Gamma posterior. For each draw $\\sigma^2(i)$ we can also take a draw from $\\beta | Y,X, \\sigma^2$, and collect the first element $\\beta(i)_1$. The $\\alpha/2$ and $(1-\\alpha)/2$ quantiles, provide an approximation to the credible set for $\\beta_1$. \n\n\\newpage\n\n\n\\newpage\n\n\n\\bibliographystyle{../AuxFiles/ecta}\n\\bibliography{../AuxFiles/BibMaster}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "5bf77c2307b2370b1c6ed1980947d43b966dd59d", "size": 16404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/Lectures/Lectures11-12.tex", "max_stars_repo_name": "yu45020/Courses-IntroEconometrics-Ph.D", "max_stars_repo_head_hexsha": "84162de869a4c8a7ad93a7e7f3f33e741d4caeb3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-09-10T01:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-13T12:01:36.000Z", "max_issues_repo_path": "docs/Lectures/Lectures11-12.tex", "max_issues_repo_name": "yu45020/Courses-IntroEconometrics-Ph.D", "max_issues_repo_head_hexsha": "84162de869a4c8a7ad93a7e7f3f33e741d4caeb3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-09-07T02:05:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-15T12:46:32.000Z", "max_forks_repo_path": "docs/Lectures/Lectures11-12.tex", "max_forks_repo_name": "yu45020/Courses-IntroEconometrics-Ph.D", "max_forks_repo_head_hexsha": "84162de869a4c8a7ad93a7e7f3f33e741d4caeb3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2018-09-05T03:12:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-13T12:01:38.000Z", "avg_line_length": 73.8918918919, "max_line_length": 661, "alphanum_fraction": 0.6949524506, "num_tokens": 5049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.612348780787875}}
{"text": "\\subsection{Homogeneity}\r\n\\begin{definition}\r\n\tA differential equation is homogeneous if all terms involve the dependent variable or its derivatives.\r\n\\end{definition}\r\n\r\n\\noindent\r\nBelow is a table of homogeneity and equation numbers.\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{c|c}\r\n\t\tHomogeneity & Equation Number \\\\\r\n\t\t\\hline\r\n\t\tHomogeneous &  3, 7, 8 \\\\\r\n\t\tHeterogeneous & 1, 2, 4, 5, 6, 9, 10 \\\\\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\noindent\r\nHomogeneous equations have some nice properties, like always having at least a trivial solution of 0.", "meta": {"hexsha": "8973d42511854a59003f6ad69174da282372c091", "size": 550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/classification/homogeneity.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/homogeneity.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/homogeneity.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": 30.5555555556, "max_line_length": 104, "alphanum_fraction": 0.7218181818, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6123487764513326}}
{"text": "\\section{Introduction}\\label{sec:intro}\n\n\\mypar{Motivation} The longest common subsequence (LCS) problem is the problem of finding the longest (not necessarily contiguous) subsequence that is shared by two input strings. This problem occurs very widely in practice. For example, the two sequences $ABCD$ and $ACBAD$ have the longest common subsequences $ACD$ and $ABD$. The length of the LCS is unique, although multiple subsequences with that length might exist.\n\nLCS algorithms are at the core of comparison tools like ``diff'', which are ubiquitous when working with source code. These comparisons are also used extensively in version control systems. Outside of the software domain, the longest common subsequence problem is extremely important in biology - LCS is the exact solution to DNA nucleotide \\emph{sequence alignment}. However, it is important to note that heuristic methods (BLAST \\cite{altschul_basic_1990}) are often used today, since they allow fast search of very large databases of genetic sequences.\n\nThere exist various specialized LCS algorithms which achieve faster runtime or lower memory usage than general algorithms. One class of specialized algorithms provides improved runtime when both input sequences have significant similarities (edit distance not too large). This is generally the case when comparing two versions of a text document. For this reason algorithms of this class are nearly universally used by tools similar to ``diff''. However such algorithms are generally sequential.\n\nWe adapt the sequential LCS algorithm of Myers \\cite{myers_anond_1986}, which is by far the most commonly used LCS algorithm for similar sequences, for parallel execution on a distributed memory system.\n\n\\mypar{Related work} Bergroth et al. prepared a survey \\cite{bergroth_survey_2000} of various sequential LCS algorithms. They group the algorithms into three categories: ``row-by-row methods'', ``contour methods'' and ``diagonal methods''. The classic dynamic programming algorithm for LCS \\cite{wagner_string--string_1974} is classified as a row-by-row method. Myers' algorithm \\cite{myers_anond_1986} belongs to the class of diagonal methods. Diagonal methods are designed to be efficient when both input sequences are similar. \n\nMost parallel algorithms for the LCS problem are based on row-by-row sequential algorithms. Lu and Lin \\cite{mi_lu_parallel_1994} presented a parallel algorithm of this class, achieving optimal complexity with a shared-memory machine model. Yang et al. \\cite{jiaoyun_efficient_2010} designed a parallel LCS algorithm for GPUs (graphics processing units) by restructuring the classic DP (dynamic programming) table to reduce data dependencies.\\linebreak These algorithms are fundamentally based on row-by-row methods, which are less efficient than diagonal methods for similar input sequences.\n\nAllison and Dix \\cite{allison_bit-string_1986} present a ``bit-parallel'' LCS algorithm (row-by-row method). Assuming a sufficiently small alphabet, their algorithm allows calculating multiple elements of the DP table in parallel, for example by using vector instructions. Their bit-parallel technique can be applied to other algorithms. We do not incorporate it into our algorithm, but do use vectorization within each DP cell.\n\nSince Myers' algorithm \\cite{myers_anond_1986} is an extremely popular LCS algorithm, we attempted to parallelize it. As far as we are aware, there are no published parallel versions of an LCS algorithm from the ``diagonal methods'' class, which Myers' algorithm belongs to. ", "meta": {"hexsha": "7e0ab4851d369825bf468afd7d4da2c560a3dd58", "size": 3554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report_src/sections/01-introduction.tex", "max_stars_repo_name": "tehwalris/mpi-myers-diff", "max_stars_repo_head_hexsha": "9d6dafc9dc16dcf97b4c712dbb8c6dace25eeee5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-09T11:30:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T17:47:49.000Z", "max_issues_repo_path": "report_src/sections/01-introduction.tex", "max_issues_repo_name": "tehwalris/mpi-myers-diff", "max_issues_repo_head_hexsha": "9d6dafc9dc16dcf97b4c712dbb8c6dace25eeee5", "max_issues_repo_licenses": ["MIT"], "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_src/sections/01-introduction.tex", "max_forks_repo_name": "tehwalris/mpi-myers-diff", "max_forks_repo_head_hexsha": "9d6dafc9dc16dcf97b4c712dbb8c6dace25eeee5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 209.0588235294, "max_line_length": 592, "alphanum_fraction": 0.8137310073, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.6123316514314282}}
{"text": "\\section{Numerical Experiment}\n\\label{sec:4}\nIn this section, we apply various methods to solve the LP form of optimal transport \\ref{lp} and the entropic regularization of optimal transport \\ref{equ:kl}. All of the numerical experiments are conducted on an Intel Core i7-6500U Processor with 2 cores and 4 threads.\n\n\\subsection{Datasets of Optimal Transport}\nWe perform the numerical experiments on various datasets, including randomly generated data, DOTmark\\cite{DOTmark}, ellipse example \\cite{multiscale}, Caffarelli's example \\cite{multiscale} and Gaussian mixture model. \n\n\\subsubsection{Randomly generated data}\nIn order to make the feasible set not empty, we first generate a random matrix $R\\in \\mbR^{m\\times n}$, where $R_{i,j}\\sim \\mcN(0,1)\\, i.i.d.$. and then generate $\\mu_i, \\nu_j$ by\n$$\n\\mu_i=\\frac{\\sum_{j=1}^n|R_{i,j}|}{\\sum_{i=1}^m\\sum_{j=1}^n|R_{i,j}|}, \\, \\forall i=1, 2, \\dots m\\\\\n$$\n$$\n\\nu_j=\\frac{\\sum_{i=1}^m|R_{i,j}|}{\\sum_{i=1}^m\\sum_{j=1}^n|R_{i,j}|}, \\, \\forall j=1, 2, \\dots n\\\\\n$$\nIt is easy to verify that $\\sum_{i=1}^m\\mu_i=\\sum_{j=1}^n\\nu_j=1$. We then generate $C_{i,j} \\sim \\mcN(0,1)\\, i.i.d.$. We denote $C_{\\mathrm{min}}=\\min_{i,j}C_{i,j}$ and let $C_{i,j}=C_{i,j}-C_{\\mathrm{min}}$ to ensure $C_{i,j}\\geq 0$. \n\n\\subsubsection{DOTmark}\nDOTmark \\cite{DOTmark} provides $10$ classes of $10$ different images, each of which is available at the different resolutions from $32\\times32$ to $512\\times512$. Suppose we select two images $x$ and $y$ with same resolution $l\\times l$ from one class. The corresponding parameter for the standard form of LP is given in the following way: $m=n=l^2$, $\\mu_i=x_i$, $\\nu_j=y_j$ and $C_{i,j}=\\|x_i-y_j\\|_p$, where $(x_i)_{1\\leq i\\leq m}$ and $(y_j)_{1\\leq j\\leq n}$ form a regular square grid in $\\mbR^2$. In practice, we take $p=2$. In solving this LP, we actually calculate the Wasserstein distance between $x$ and $y$.\n\n\\subsubsection{Ellipse Example}\nThe ellipse example consists of two uniform samples, source and target data set, of size $n$ from the unit circle with normal distributed noise added with zero mean and deviation 0.1. Slightly different from that in the paper \\cite{multiscale}, we construct the source data example by scaling in the x-Axis by 2.0 and in the y-Axis by 0.5. The target data sample is then scaled in the x-Axis by 0.5 and y-Axis by 2.0. The corresponding parameter for the standard form of LP is as follows. $m = n$, $\\mu_i=1, \\nu_i=1(i=1, ..., n)$ and $C_{i, j}=\\|x_i-y_j\\|_2$, which is the Euclidean distance between two points $x_i$ and $y_j$. Figure \\ref{ellipse} gives an example. \n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{final/ellipse1.png}\n\\caption{An Ellipse Example with sample size $n=50$. The darker the line, the greater the $\\pi_{i, j}$.}\n\\label{ellipse}\n\\end{figure}\n\n\\subsubsection{Caffarelli's Example}\nThis example, mentioned in \\cite{multiscale}, consists of two uniform samples on $[-1, 1]^2$ of size $n$. Then any point outside the unit circle are then discarded. The source and target data sample is split along the x-Axis at 0 and shifted by -2 and +2, respectively. Note that the true number of points may be less than $n$. When $n$ is large, about $\\frac{\\pi}{4}n$ points are preserved. For ease of notation, we still assume there are $n$ points. The corresponding parameter for the standard form of LP is as follows. $m = n$, $\\mu_i=1, \\nu_i=1(i=1, ..., n)$ and $C_{i, j}=\\|x_i-y_j\\|_2$, which is the Euclidean distance between two points $x_i$ and $y_j$. Figure \\ref{caff} gives an example.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{final/caff1.png}\n\\caption{An Caffarelli's Example with sample size $n=50$. The darker the line, the greater the $\\pi_{i, j}$.}\n\\label{caff}\n\\end{figure}\n\n\\subsubsection{Gaussian Mixture Model}\nSuppose $p_\\mu$ and $p_\\nu$ are the probability density function of two different Gaussian mixture models and $N$ is the number of discrete points. In this example, $\\mu$ and $\\nu$ are the normalized discrete distribution of Gaussian mixture models, which satisfy\n$$\n\\mu_i=\\frac{p_\\mu(\\frac{i-1}{N-1})}{\\sum_{i=1}^Np_\\mu(\\frac{i-1}{N-1})}, \\quad \\nu_j=\\frac{p_\\nu(\\frac{j-1}{N-1})}{\\sum_{j=1}^Np_\\nu(\\frac{j-1}{N-1})}\n$$\nAnd $C_{i,j}=|i-j|$. \n\n\\subsection{Different methods on Mosek and Gurobi}\n`prim', `dual', `int' represent primal simplex, dual simplex and interior point method respectively. `(M)' means Mosek, `(G)' means Gurobi. For each method, we record the time and the number of iteration it takes and evaluate their performance. We examine the accuracy of the solution $\\pi$ by the value of the objective function ('objval') \n$$\n\\sum_{i=1}^m\\sum_{j=1}^nC_{i,j}\\pi_{i,j}\n$$\nand the violation of the constraints ('vltcst') \n$$\n\\sum_{i=1}^m|\\mu_i - \\sum_{j=1}^{n}\\pi_{i, j}| + \\sum_{j=1}^n|\\nu_j-\\sum_{i=1}^m\\pi_{i, j}|$$\nIn the table, we only give the exact value of `objval' for prim(M). In `objval' of other methods, we give its relative difference to prim(M). Namely, if `objval' for prim(M) is $f_1$ and `objval' for prim(G) is $f_2$, in `objval' of prim(G), we give $\\frac{f_1-f_2}{f_1}$. \n\n\\subsubsection{Randomly generated data}\nFor simplicity, we only consider the case when $m=n$. We take $m=128,256,512,1024$.  \n\n\\input{final/RGD_mg}\n\nFrom Table \\ref{RGD_mg}, we can see on Mosek, dual simplex method and interior point method take much more time than primal simplex does, especially when $m, n$ are large. But on Gurobi, dual simplex method is the fastest method and the time primal simplex method takes is close to the time interior point takes. Interior point method takes much smaller number of iterations than  We can observe that compared to other methods, primal simplex method on Mosek gets the largest value of objective function and the largest value of the violation of constraints. On Mosek, dual simplex methods achieves the lowest value of `vltcst', which partly explains why it takes the longest time. On Gurobi, the solution from all methods satisfies constraints perfectly.\n\n\\subsubsection{DOTmark}\nWe then test the performance of Mosek and Gurobi on DOTmark \\cite{DOTmark}. We number the classes of DOTmark with the order of alphabet in the following way.\n\\begin{table}[!htp]\n\\centering\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\nCauchyDensity&ClassicImages&GRFmoderate&GRFrough&GRFsmooth\\\\\\hline\n1&2&3&4&5\\\\\\hline\nLogGRF&LogitGRF&MicroscopyImages&Shapes&WhiteNoise\\\\\\hline\n6&7&8&9&10\\\\\\hline\n\\end{tabular}\n\\end{table}\n\nWe test on pictures with resolution $32\\times32$. \n\\input{final/DOTmark_mg}\n\nFrom Table \\ref{DOTmark_mg}, we observe that dual simplex method on Mosek takes much longer time than other methods. The cpu-time of primal simplex method on Mosek and primal simplex method and dual simplex method on Gurobi are close. On Mosek and Gurobi, the iteration number vary with different classes of DOTmark. Compared to other methods, primal simplex method on Mosek gets the largest `vltcst' and the largest `vltcst'. On Mosek, dual simplex methods achieves the smallest `vltcst'. On Gurobi , the solution $\\pi$ from all methods satisfies the constraints perfectly.\n\n\\subsubsection{Ellipse Example \\& Caffarelli's Example}\nSimilar to randomly generated data, we only consider the case when $m=n$. We take $m=128,256,512,1024$.  \n\\input{final/ellipse_mg}\n\\input{final/caff_mg}\n\nDifferent from the results on randomly generated data, Table \\ref{ellipse_mg} shows that on Ellipse Example, dual simplex method takes much longer time and more iterations than primal simplex method, no matter on Mosek or on Gurobi. Similar to Ellipse Example, Table \\ref{caff_mg} shows that dual simplex method takes much longer time than the primal simplex method, no matter on Mosek or on Gurobi. The iteration number of primal simplex method and dual simplex method are close. Similarly, compared to other methods, primal simplex method on Mosek gets the largest `vltcst' and the largest `vltcst'. On Mosek, dual simplex methods achieves the smallest `vltcst'. On Gurobi , the solution $\\pi$ from all methods satisfies the constraints perfectly.\n\n\\subsection{First order methods}\n`prim(M)' means primal method of Mosek. `ADMM-p' means ADMM primal method \\ref{alg:ADMM}. `ADMM-d' means ADMM dual method \\ref{alg:ADMM-dual}. `ADMM-s' means another ADMM splitting method for primal problem \\ref{alg:ADMM-split}. BADMM means Bregman ADMM \\ref{alg:BADMM}.\n\\subsubsection{Art of Tuning Parameters}\nThe success of ADMM always lies in an appropriate choice of the coefficient $t$ in the quadratic term of the augmented Lagrangian function. Thanks to the normalization of constraints, i.e., letting $\\sum_{i=1}^m\\mu_i = \\sum_{j=1}^n\\nu_j = 1$, the tuning of parameters is relatively easier. Intuitively, the value of $t$ should be dependent on the problem size, $m$ and $n$, and the objective coefficients $C$. In our implementation, for primal problem, we let $t$ to be proportional to $(m+n)\\bar C$, where $\\bar C$ is the mean of the coefficient matrix $C$ ($\\frac{1}{mn}\\sum_{i, j}C_{i, j}$). For dual problem, we set $t$ to be inversely proportional to $(m+n)\\bar C$. For the Bregman ADMM, we set $t$ to be proportional to $\\bar C$. The detailed proportion will be clear in the following. Empirically, we found that such strategy performs well in our experiments.\n\n\\subsubsection{Randomly Generated Data}\n\\input{final/RGD_fo}\nIn Table \\ref{RGD_fo}, we present the numerical results on random generated data. \nDetailed tuning parameters is listed in Table \\ref{param_rgd_fo}.\n\\begin{table}[h]\n\\centering\n\\caption{Tuned Parameters: Random Generated Data}\n\\label{param_rgd_fo}\n\\begin{tabular}{|c|c|c|}\n\\hline \nSolver & $t$ & Stopping Rule \\\\\n\\hline\nADMM-p & $5(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 5e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-d & $1/(8(m+n)\\bar C)$ & $\\text{`vltcst'}\\leqslant$ 2e-04 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-s & $2(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 1e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nBADMM & $10\\bar C$ & $\\|\\pi-\\tilde\\pi\\|_1\\leqslant$ 1e-06 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nIn this setting, both `ADMM-p' and `ADMM-s' achieves relatively better results. They both satisfy the constraints quite well and achieve lower objective value. `ADMM-p' spends moderate time in all problems because all computation has closed form. `ADMM-s' performs quite well in `objval' and `vltcst', especially when the problem size is larger. However, such accuracy is at the cost of much longer time. In fact, from our observation, much of the time by `ADMM-s' is spent on the projection on the simplex(constraints). There exists more efficient algorithms for projection, but since time is limited, we do not implement them. The projection is quite essential in `ADMM-s' because it imposes $\\pi$ to satisfy constraints, and this may explain why the constraints are easy to satisfy within tolerance.\n\nIt's worth noting that `ADMM-d' has weakness in satisfying constraints. This is because in Section 2.1.2 we regard the ``dual of dual'' as an approximation of initial variables, which is numerically unstable. In our experiments, we found that `ADMM-d' converges faster at the beginning to the optimal value, but then continuously vibrates around optimal value for a long time. `BADMM' appears to perform worse than other three algorithms. The selection of $t$ is inconsistent with other ADMM due to the property of KL divergence. If $t$ is selected to be too big, then the exponential term in \\ref{badmm_pipit_upd} may be so close to 1 that leads to bad precision. Furthermore, in our experiments, we found that when we increase $t$, `BADMM' indeed has slightly better performance in `vltcst' but deteriorates rapidly in `objval'. Our parameter is a balance between the two targets.\n\n\\subsubsection{DOTmark}\nSome detailed tuning parameters is listed in Table \\ref{param_DOTmark_fo}.\n\\begin{table}[htbp]\n\\centering\n\\caption{Tuned Parameters: DOTmark}\n\\label{param_DOTmark_fo}\n\\begin{tabular}{|c|c|c|}\n\\hline \nSolver & $t$ & Stopping Rule \\\\\n\\hline\nADMM-p & $5(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 5e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-d & $1/(8(m+n)\\bar C)$ & $\\text{`vltcst'}\\leqslant$ 2e-04 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-s & $2(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 4e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nBADMM & $10\\bar C$ & $\\|\\pi-\\tilde\\pi\\|_1\\leqslant$ 4e-06 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\input{final/DOTmark_fo}\nTable \\ref{DOTmark_fo} presents the numerical results on DOTmark.\n\nAs to constraints, all methods perform similar to that in the setting of random generated data, since our stopping rule is built on `vltcst' or the norm of difference between $\\pi$ and $\\tilde\\pi$. \n\nAs to objective value, the three traditional ADMM methods are not stable on `objval' and tend to achieve higher value than Mosek. This may be because of the different structure between random generated data and DOTmark. `BADMM' tends to achieve lower objective value. However, the results are not stable and the constraints are not satisfied well.\n\nAs to iteration numbers and time spent, surprisingly, `ADMM-p' and `ADMM-s' need much less iterations than others. This phenomenon implies that we could tighten our stopping rule by decreasing the thresholds. Due to the time limit, further experiments could be conducted in the future.\n\n\\subsubsection{Ellipse Example \\& Caffarelli's Example}\nThe detailed parameters is listed in Table \\ref{param_ellcaff_fo}. \n\\begin{table}[htbp]\n\\centering\n\\caption{Tuning Parameters: Ellipse \\& Caffarelli}\n\\label{param_ellcaff_fo}\n\\begin{tabular}{|c|c|c|}\n\\hline \nSolver & $t$ & Stopping Rule \\\\\n\\hline\nADMM-p & $5(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 5e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-d & $1/(8(m+n)\\bar C)$ & $\\text{`vltcst'}\\leqslant$ 2e-04 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nADMM-s & $2(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 2e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nBADMM & $10\\bar C$ & $\\|\\pi-\\tilde\\pi\\|_1\\leqslant$ 4e-06 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\input{final/ellipse_fo}\n\\input{final/caff_fo}\n\nTable \\ref{ellipse_fo} and \\ref{caff_fo} presents numerical results for Ellipse Example and Caffarelli's Example, respectively.\n\nThe constraints are generally satisfied before we stop iterations. The solution from `BADMM' does not satisfy the constraints very well. However, the optimal value is not within our expectation. The vibration of objective values around optimal values are observed in the three traditional ADMM methods. Among these algorithms, `ADMM-s' performs relatively better on `iter', `objval', and `vltcst', though it takes more time in each iteration. Nevertheless, `objval' of `BADMM' is relatively low.\n\n\\subsection{Algorithms for entropic regularized OT}\n`sinkhorn' represents the Sinkhorn's algorithm with numerical stability and continuation strategy \\ref{alg:sansc}. `ADMM' means the algorithm described in \\ref{alg:ADMM-ER}. Addition to `time', `iter', `objval' and `vltcst', we use `entval' to denote the objective value with extropy regularization term. The values in `objval' are, same as before, compared to `prim(M)'.\n\nThe parameters and stopping criterions of our algorithms are given in Table \\ref{param_er}. In 'sinkhorn', we apply continuation strategy. If the coefficient of the regularized term is $\\epsilon$, we select $10^i\\epsilon(i=4, 3, 2, 1, 0)$ as the sequence and run 4000 iterations in optimizing every subproblem.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{Tuned Parameters: algorithms for entropic regularized OT}\n\\label{param_er}\n\\begin{tabular}{|c|c|c|}\n\\hline \nmethod & $t$ & Stopping Rule \\\\\n\\hline\nADMM & $5(m+n)\\bar C$ & $\\text{`vltcst'}\\leqslant$ 1e-07 or $\\text{`iter'}\\geqslant$ 2e+04 \\\\\\hline\nsinkhorn & / & $\\text{`iter'}\\geqslant$ 2e+04 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\n\\subsubsection{Gaussian Mixture Model: The effect of continuation strategy}\n\nWe consider to test Sinkhorn's algorithm with numerical stability on Gaussian mixture model and test the effect of continuation strategy. We first take $N=128$ as a first exmaple. Figure \\ref{gmm3} gives the probability density function of two Gaussian mixture models.\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=12cm]{final/gmm3.jpg}\n\\caption{The probability distribution function of two Gaussian mixture models $G_1$ and $G_2$. $G_1$ (blue one) has mean $[0.2,0.5]$, variance $[0.05^2, 0.03^2]$ and component proportion $[0.6, 0.4]$; $G_2$ (red one) has mean $[0.6,0.7]$, variance $[0.03^2, 0.05^2]$ and component proportion $[0.3, 0.7]$. }\n\\label{gmm3}\n\\end{figure}\n\nWe then take $\\epsilon=10^{-2},10^{-3},10^{-4},10^{-5}$. If we use the vanilla Sinkhorn's algorithm \\ref{alg:sa} for $\\epsilon=10^{-4},10^{-5}$, $K^{\\epsilon}$ would be a zero matrix. For Sinkhorn's algorithm with numerical stability \\ref{alg:sans}, we take the maximum iteration number to be $10,100,1000,4000$ respectively. For Sinkhorn's algorithm with numerical stability and continuation strategy \\ref{alg:sansc}, we take $\\alpha=0.1$, $\\epsilon_0=\\epsilon\\times 10^5$ and the maximum iteration number to be $2,20,200,800$ respectively. \n\n\\begin{figure}[!htb]\n\\centering\n\\includegraphics[width=12cm]{final/gmm4.jpg}\n\t\\caption{Impact of $\\epsilon$ on the coupling between two gaussian mixture models \\ref{gmm1}. From left to right, $\\epsilon=10^{-2},10^{-3},10^{-4},10^{-5}$. The upper row is without continuation strategy and the lower row is with continuatation strategy. The purple one is the solution to the entropic regularized LP. The green one is the solution to the original LP.}\n\\label{gmm4}\n\\end{figure}\n\nFrom Figure \\ref{gmm4}, we can find that with same iteration number, Sinkhorn's algorithm with numerical stability and continuation strategy converges faster than the one only with numerical stability. This shows that with proper choice of the parameter of continuation, we can achieve acceleration in Sinkhorn's algorithm with continuation strategy.\n\nWe then perform a comprehensive numerical experiment on Gaussian mixture model. Detailed parameters and the stopping criterions are listed in Table \\ref{param_er}. \n\n\\input{final/gmm_er}\nTable \\ref{gmm_er} gives the comprehensive numerical results for Gaussian Mixture Model. The setting is same as Figure \\ref{gmm1}, except that we test examples for different problem sizes, i.e., we let $N=128, 256, 512, 1024$, respectively. We observe that, in most cases, although `sinkhorn' takes much longer time and more iterations than `ADMM', `sinkhorn' outperforms `ADMM' in both `objval' and `vltcst'. \n\n\\subsubsection{Randomly generated data}\nThe parameters and the stopping criterions are listed in Table \\ref{param_er}. Table \\ref{RGD_er} presents numerical results on random generated data. \n\n\\input{final/RGD_er}\n\nWe find that the `objval' and `vltcst' of `sinkhorn' is getting worse with the decrease of $\\epsilon$. This can be explained by the computation complexity of Sinkhorn's algorithm. As shown in Section 3.2, the $\\tau$-approximate solution of the unregularized OT problem takes $O(n^2\\log(n)\\tau^{-3})$ operations where $\\epsilon=\\tau/\\log(n)$. This means that if we decrease the $\\epsilon$ by $0.1$, theoretically we would need $10^3$ times iteration to get a precise solution. Although our improvements of Sinkhorn's algorithm makes it adapt to small $\\epsilon$, but the computation is costly. If we want to use Sinkhorn's algorithm to get an approximation solution of the orignial problem \\ref{lp}, we should pay attention to choose an appropriate $\\epsilon$. \n\nOn the contrary, `ADMM' appears robustness in satisfying constraints within acceptable iteration number. `vltcst' of all test samples are below 1e-06, though it's not comparable to `sinkhorn'. `objval' of ADMM appears to be gradually lower than `prim(M)' when $\\epsilon$ decreases. It's worth noting that in `ADMM' we do not apply continuation strategy. In fact, we observe that with the carefully selected $t$, `ADMM' converges quite fast to the optimal value at the beginning, whatever $\\epsilon$ is, although vibration is unavoidable in the latter steps. Of course, for $\\epsilon$ not large and small or moderate problem sizes, `sinkhorn' performs better than `ADMM'.\n\n\n\\subsubsection{DOTmark}\nDetailed parameters are listed in \\ref{param_er}. (The stopping rule for `ADMM' changes to $\\text{`vltcst'}\\leqslant$ 1e-07 or $\\text{`iter'}\\geqslant$ 2e+04.) Table \\ref{DOTmark_er1} and \\ref{DOTmark_er2} present numerical results on DOTmark.\n\\input{final/DOTmark_er1}\n\\input{final/DOTmark_er2}\n\nSame as before, `objval' and `vltcst' of `sinkhorn' is getting worse with the decrease of $\\epsilon$. All of the results are within 1e-09 in `vltcst', but `objval' deteriorate rapidly when $\\epsilon$ decreases. This can be again explained by the computation complexity of Sinkhorn's algorithm. \n\n'ADMM' can achieve relatively lower objective value on average, and need moderate iterations before `vltcst' arrives at a threshold. The performance is similar to random generated data setting with larger problem sizes. We should note that due to the different problem structures, it seems difficult sometimes for `ADMM' to outperform `prim(M)'.\n\n\\subsubsection{Ellipse Example \\& Caffarelli's Example}\n\\input{final/ellipse_er}\n\\input{final/caff_er}\nTable \\ref{param_er} lists the detailed parameters.Table \\ref{ellipse_er} and Table \\ref{caff_er} present numerical results for Ellipse Example and Caffarelli's Example, respectively. Through our previous experiments, we observe that with the decrease of $\\epsilon$, `ADMM' does not require so much increase of computational complexity as `sinkhorn'. This can be explained by the limit when $\\epsilon\\to0$. When $\\epsilon\\to0$, `ADMM' reduce to ADMM for the primal problem \\ref{lp}. But with $\\epsilon\\to0$, we have shown in Section 3.3.1 that `sinkhorn' will diverge due to the loss of strong convexity. And with the decrease of $\\epsilon$, the strong convexity of problem \\ref{equ:kl} decreases. This also explains why `sinkhorn' requires such enormous iterations to find the optimal solution. In summary, we shall use `sinkhorn' to solve the entropic regularization of OT \\ref{equ:kl} with moderate $\\epsilon$. With large $\\epsilon$, we shall use the original Sinkhorn's algorithm \\ref{alg:sa} because it is faster in computation. `ADMM' seems to be suitable to arbitrary small $\\epsilon$. \n", "meta": {"hexsha": "58a2a137c888b1d40df7de772dc220b1edd6db5f", "size": 22471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/final/numerical_experiment.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/numerical_experiment.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/numerical_experiment.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": 94.8143459916, "max_line_length": 1093, "alphanum_fraction": 0.7490098349, "num_tokens": 6598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.612331649520132}}
{"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 ThreePSF.\n\\end{par} \\vspace{1em}\n\\begin{par}\nThreePSF is an algorithm for estimating the amplitude, phase and offset of the sine waveform according standard IEEE Std 1241-2000';\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;\nt = [0:1/1e4:1-1/1e4];\nDI.y.v = Anom*sin(2*pi*fnom*t + phnom) + Onom;\nDI.Ts.v = 1e-4;\nDI.f.v = fnom;\n\\end{lstlisting}\n\n\n\\subsubsection*{Call algorithm}\n\n\\begin{par}\nUse QWTB to apply algorithm \\lstinline{ThreePSF} to data \\lstinline{DI}.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nCS.verbose = 1;\nDO = qwtb('ThreePSF', DI, CS);\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, phase and offset of sampled waveform.\n\\end{par} \\vspace{1em}\n\\begin{lstlisting}[style=mcode]\nA = DO.A.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\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\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  -8.4377e-09\n\n\npherrppm =\n\n  -9.7700e-09\n\n\nOerrppm =\n\n   8.3267e-10\n\n\\end{lstlisting} \\color{black}\n    \n\n\n%%% \\end{document}\n    \n", "meta": {"hexsha": "76aca5d11fe22cf4a9c5288eb77af0f481202641", "size": 2399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algs_examples_published/doc_ThreePSF.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_ThreePSF.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_ThreePSF.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": 19.192, "max_line_length": 225, "alphanum_fraction": 0.6877865777, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6123316470268072}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program = xelatex\n\\title{Project 5: Solving the FDMs for Two-asset Options}\n\\author{Iydon Liang}\n\\date{\\today}\n\n\\maketitle\\tableofcontents\\clearpage\n\n\\begin{abstract}\n    It's clear that how to solve the FDM for one-asset option, either European, American or Path-dependent types. In this report, we discussed the two-asset options case. And gave three methods to determine the price for a two-asset option.\n\\end{abstract}\n\n\\section{Two-asset Option}\n\\[\n    \\dd S_i(t) = S_i(t)\\alpha_i\\dd t + S_i(t)\\sigma_i\\dd W_i(t)\n\\]\nwhere $\\dd W_i(t)$ $(i=1,\\ldots,n)$ are standard Brownian motion which satisfy\n\\[\n    \\begin{aligned}\n        \\EE(\\dd W_i) &= 0 \\\\\n        \\var(\\dd W_i) &= \\dd t \\\\\n        \\cov(\\dd W_i, \\dd W_j) &= \\delta_{ij} p_{ij} \\dd t.\n    \\end{aligned}\n\\]\n\n\\subsection{Pricing by Monte Carlo Method}\nWe know that price of the two stocks follows a bi-variate log-normal distribution. And we can generate it from a bi-variate normal distribution with $\\mu=0$ and\n\\[\n    \\Sigma = \\begin{pmatrix}\n        1 & \\rho \\\\\n        \\rho & 1\n    \\end{pmatrix}.\n\\]\nThen we can sample $(S_1(T), S_2(T))$ from the distribution, and pricing by Monte Carlo method is possible by so.\n\n\n\n\\section{FDMs for Two-asset Option}\n\\[\n    \\frac{\\partial V}{\\partial t} + rS_1\\frac{\\partial V}{\\partial S_1} + \\frac{1}{2}\\sigma_1^2S_1^2\\frac{\\partial^2 V}{\\partial S_1^2} + rS_2\\frac{\\partial V}{\\partial S_2} + \\frac{1}{2}\\sigma_2^2S_2^2\\frac{\\partial^2 V}{\\partial S_2^2} - rV = 0\n\\]\n\n\\subsection{Approximate the Differential Quotients}\nSuppose $f(i, j, k) = V(S_1=i\\Delta S, S_2=j\\Delta S, t=k\\Delta k)$,\n\\[\n    \\begin{aligned}\n        f_t &\\approx \\frac{f(i, j, k+1) - f(i, j, k)}{\\Delta t} \\\\\n        f_{S_1} &\\approx \\frac{f(i+1, j, k) - f(i-1, j, k)}{2\\Delta t} \\\\\n        f_{S_1S_2} &\\approx \\frac{f(i+1, j, k) - 2f(i, j, k) + f(i-1, j, k)}{\\Delta^2S} \\\\\n        f_{S_2} &\\approx \\frac{f(i, j+1, k) - f(i, j-1, k)}{2\\Delta t} \\\\\n        f_{S_1S_2} &\\approx \\frac{f(i, j+1, k) - 2f(i, j, k) + f(i, j-1, k)}{\\Delta^2S}\n    \\end{aligned}\n\\]\n\n\n\\subsection{Recursion Form}\nSubstitute the approximations in to the BS equation, and put $f(\\cdot, \\cdot, k+1)$ to the left side, put $f(\\cdot, \\cdot, k)$ to the right hand side. Then we get\n\\[\n    \\begin{aligned}\n        f(i, j, k+1) =& \\quad\\alpha_i f(i-1, j, k) \\\\\n        &+ \\beta_i f(i+1, j, k) \\\\\n        &+ \\gamma_j f(i, j-1, k) \\\\\n        &+ \\theta_j f(i, j+1, k) \\\\\n        &+ \\lambda_{1i} f(i, j, k) \\\\\n        &+ \\lambda_{2j} f(i, j, k)\n    \\end{aligned}\n\\]\n\nHere we divide the coefficient of $f(i, j, k)$ into two parts for the convenience of following steps.\n\\[\n    \\begin{aligned}\n        \\alpha_i &= \\frac{1}{2}\\Delta t(ri-\\sigma_1^2i^2) \\\\\n        \\beta_i &= -\\frac{1}{2}\\Delta t(ri+\\sigma_1^2i^2) \\\\\n        \\gamma_j &= \\frac{1}{2}\\Delta t(rj-\\sigma_2^2j^2) \\\\\n        \\theta_j &= -\\frac{1}{2}\\Delta t(ri-\\sigma_2^2j^2) \\\\\n        \\lambda_{1i} &= \\frac{1}{2} + \\Delta t(\\frac{1}{2}r+\\sigma_1^2i^2) \\\\\n        \\lambda_{2j} &= \\frac{1}{2} + \\Delta t(\\frac{1}{2}r+\\sigma_2^2j^2) \\\\\n    \\end{aligned}\n\\]\n\n\n\\subsection{Matrix Form}\nThe relationship can be written as a matrix equation\n\\[\n    AX + XB = C\n\\]\nwhere matrix $C(i, j) = f(i, j, k+1)$, $X(i, j) = f(i, j, k)$\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/2019-12-25-matrix-form.png}\n\\end{figure}\n\n\n\\subsection{Solve the Matrix Equation}\nMatrix equation of the form $AX + XB = C$ is called \\textbf{Sylvester equation}. The equation has a unique solution when the eigenvalues of $A$ and $−B$ are distinct. In \\texttt{MATLAB}, there is a function \\textbf{sylvester(A,B,C)}, which can solve the Sylvester equation.\n", "meta": {"hexsha": "75f3b413e9ef164df77d34709c2b2e4303d09383", "size": 3680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA216/sections/project-5/main.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-5/main.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/project-5/main.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": 37.9381443299, "max_line_length": 273, "alphanum_fraction": 0.6065217391, "num_tokens": 1381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6123316393816227}}
{"text": "\\documentclass[10pt,preprint]{../aastex}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{booktabs}\n\\usepackage{mathrsfs}\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\\usepackage{float}\n\\usepackage{graphicx}\n\\newtheorem{remark}{Remark}\n\\graphicspath{{Figures/}}\n\\newcommand{\\figref}[1]{Figure \\ref{#1}}\n\n\\begin{document}\nThroughout this document, lowercase latin indices ($i,j,$ etc.) run from 1 to 3, lowercase Greek indices ($\\mu,\\nu,$ etc.) run from 0 to 3, and uppercase latin indices ($J$) run from 1 to 5.\n\n\\section{Equations}\nWe are solving the general relativistic hydrodynamics (GRH) equations \\citep{RezzollaRelHyd}:\n\\begin{equation}\\label{Eq:GRH}\n\\pd{\\left(\\sqrt{\\gamma}\\,\\bU\\right)}{t}+\\pd{\\left(\\alpha\\,\\sqrt{\\gamma}\\,\\bF^{i}\\right)}{i}=\\sqrt{\\gamma}\\,\\bS,\n\\end{equation}\nwhere $\\bU$ is the vector of conserved variables, defined as\n\\begin{equation}\n\\bU\\longrightarrow U^{J}=\\begin{pmatrix}D\\\\ S_{j}\\\\ E\\end{pmatrix}=\\begin{pmatrix}\\rho\\,W\\\\ \\rho\\,h\\,W^{2}\\,v_{j}\\\\\\rho\\,h\\,W^{2}-p\\end{pmatrix},\n\\end{equation}\n$\\bF^{i}$ is the vector of fluxes of the conserved variables in the $x^{i}$-direction, defined as\n\\begin{equation}\n\\bF^{i}\\longrightarrow \\left(F^{i}\\right)^{J}=\\begin{pmatrix}D\\left(v^{i}-\\eta^{i}\\right)\\\\ S_{j}\\left(v^{i}-\\eta^{i}\\right)+p\\,\\delta^{i}_{~j}\\\\S^{i}-\\eta^{i}\\,E\\end{pmatrix},\n\\end{equation}\n$\\bS$ is the vector of sources, defined as\n\\begin{equation}\n\\bS\\longrightarrow S^{J}=\\begin{pmatrix}0\\\\\\frac{1}{2}\\,\\alpha\\,P^{ik}\\,\\pd{\\gamma_{ik}}{j}+S_{i}\\,\\pd{\\beta^{i}}{j}-E\\,\\pd{\\alpha}{j}\\\\\\alpha\\,P^{ij}\\,K_{ij}-S^{j}\\,\\pd{\\alpha}{j}\\end{pmatrix},\n\\end{equation}\nwhere $\\rho$ is the mass-density of the fluid, $v^{i}$ are the contravariant components of the fluid three-velocity, and $p$ is the pressure of the fluid. The quantity $h$ is the specific enthalpy of the fluid, defined as\n\\begin{equation}\nh\\equiv1+\\frac{e+p}{\\rho},\n\\end{equation}\nwhere $e$ is the internal energy-density of the fluid. The quantity $W$ is the Lorentz factor of the fluid, defined as\n\\begin{equation}\nW\\equiv\\left(1-\\vv{v}\\cdot\\vv{v}\\right)^{-1/2}.\n\\end{equation}\nThe quantity $\\alpha$ is the lapse function, $\\eta^{i}$ are the ratio of the components shift-vector, $\\beta^{i}$, to the lapse function:\n\\begin{equation}\n\\vv{\\eta}\\longrightarrow\\eta^{i}\\equiv\\alpha^{-1}\\,\\beta^{i},\n\\end{equation}\nand $\\gamma_{ij}$ are the covariant components of the spatial three-metric tensor, i.e. $\\gamma^{ij}\\,\\gamma_{jk}=\\delta^{i}_{~k}$, where $\\delta^{i}_{~k}$ are the usual components of the Kronecker delta tensor. The $P^{ij}$ are the components of the stress-tensor, defined as\n\\begin{equation}\n\\bP\\longrightarrow P^{ij}\\equiv\\rho\\,h\\,W^{2}\\,v^{i}\\,v^{j}+p\\,\\gamma^{ij},\n\\end{equation}\nand the $K_{ij}$ are the components of the extrinsic curvature, defined as\n\\begin{equation}\n\\text{FILL IN HERE}.\n\\end{equation}\n\n\\section{Derivation of Middle Wave-Speed Estimate for General Relativistic HLLC Numerical Flux}\nFor a given Riemann problem we assume that a discontinuity breaks up into four distinct regions (see \\figref{Fig:HLLC_RiemannFan}).\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{HLLC_RiemannFan_MB2005}\n\\caption{HLLC Riemann fan from \\citet{Mignone2005}.}\\label{Fig:HLLC_RiemannFan}\n\\end{figure}\n\n\\subsection{Derivation of Rankine-Hugoniot Jump Conditions}\nThis derivation closely follows \\citet{RezzollaRelHyd}.\n\nWe start the derivation by integrating the one-dimensional version of \\eqref{Eq:GRH} in space from a point $x_{L}$ to a point $x_{R}$, that contains a shock, which we define to be at a time-dependent point $x_{L}<\\lambda\\left(t\\right)<x_{R}$:\n\\begin{equation}\n\\int\\limits_{x_{L}}^{x_{R}}\\pd{\\left(\\sqrt{\\gamma}\\,\\bU\\right)}{t}\\,dx+\\int\\limits_{x_{L}}^{x_{R}}\\pd{\\left(\\alpha\\,\\sqrt{\\gamma}\\,\\bF^{x}\\right)}{x}\\,dx=\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bS\\,dx.\n\\end{equation}\nFirst, we note that in the first integral on the LHS we can pull out the partial derivative with respect to time, which converts it into a total derivative. We also perform an integration-by-parts on the second integral on the LHS, yielding\n\\begin{align}\n\\frac{d}{dt}\\int\\limits_{x_{L}}^{x_{R}}&\\sqrt{\\gamma}\\,\\bU\\,dx+\\left[\\alpha\\,\\sqrt{\\gamma}\\,\\bF^{x}\\right]^{x_{R}}_{x_{L}}=\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bS\\,dx\\\\\n&\\implies\\frac{d}{dt}\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bU\\,dx+\\alpha_{R}\\,\\sqrt{\\gamma_{R}}\\,\\bF_{R}^{x}-\\alpha_{L}\\,\\sqrt{\\gamma_{L}}\\,\\bF_{L}^{x}=\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bS\\,dx,\n\\end{align}\nwhere $\\alpha_{L}=\\alpha\\left(x_{L}\\right)$, etc. The integral over the vector of conserved variables contains the discontinuity, and therefore it's derivative is not well-defined. To overcome this we split the integral into one integral from $x_{L}$ to the location of the shock as approached from below, $s^{-}\\left(t\\right)$, and another integral from the location of the shock as approached from above, $s^{+}\\left(t\\right)$, to $x_{R}$:\n\\begin{equation}\n\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bU\\,dx=\\int\\limits_{x_{L}}^{s^{-}\\left(t\\right)}\\sqrt{\\gamma}\\,\\bU\\,dx+\\int\\limits_{s^{+}\\left(t\\right)}^{x_{R}}\\sqrt{\\gamma}\\,\\bU\\,dx.\n\\end{equation}\nBoth of these integrals are smooth. Next we use the rule for differentiation of an integral depending on a parameter \\citep{RezzollaRelHyd}:\n\\begin{equation}\n\\f{d}{dt}\\int\\limits_{x_{1}\\left(t\\right)}^{x_{2}\\left(t\\right)}Q\\left(x,t\\right)\\,dx=\\int\\limits_{x_{1}\\left(t\\right)}^{x_{2}\\left(t\\right)}\\pd{Q\\left(x,t\\right)}{t}\\,dx+Q\\left(x_{2}\\left(t\\right),t\\right)\\,\\frac{dx_{2}\\left(t\\right)}{dt}-Q\\left(x_{1}\\left(t\\right),t\\right)\\,\\frac{dx_{1}\\left(t\\right)}{dt}.\n\\end{equation}\nThis yields, since $x_{L}$ and $x_{R}$ are constant,\n\\begin{align}\n\\int\\limits_{x_{L}}^{s^{-}\\left(t\\right)}&\\pd{\\left(\\sqrt{\\gamma}\\,\\bU\\right)}{t}\\,dx+\\sqrt{\\gamma\\left(s^{-}\\left(t\\right),t\\right)}\\,\\bU\\left(s^{-}\\left(t\\right),t\\right)\\,\\frac{ds^{-}}{dt}\\\\\n&+\\int\\limits_{s^{+}\\left(t\\right)}^{x_{R}}\\pd{\\left(\\sqrt{\\gamma}\\,\\bU\\right)}{t}\\,dx-\\sqrt{\\gamma\\left(s^{+}\\left(t\\right),t\\right)}\\,\\bU\\left(s^{+}\\left(t\\right),t\\right)\\,\\frac{ds^{+}}{dt}\\\\\n&+\\alpha_{R}\\,\\sqrt{\\gamma_{R}}\\,\\bF_{R}-\\alpha_{L}\\,\\sqrt{\\gamma_{L}}\\,\\bF_{L}=\\int\\limits_{x_{L}}^{x_{R}}\\sqrt{\\gamma}\\,\\bS\\,dx.\n\\end{align}\nWe will now take the limit that $x_{L}\\longrightarrow s^{-}$ and $x_{R}\\longrightarrow s^{+}$. When we do this, we see that the integrals vanish, because the integrands are all smooth in the regions considered. This yields (defining $\\bU_{L}\\equiv\\bU\\left(s^{-}\\left(t\\right),t\\right)$, etc.)\n\\begin{equation}\n\\sqrt{\\gamma_{L}}\\,\\bU_{L}\\,\\frac{ds_{L}}{dt}-\\sqrt{\\gamma_{R}}\\,\\bU_{R}\\,\\frac{ds_{R}}{dt}=\\alpha_{L}\\,\\sqrt{\\gamma_{L}}\\,\\bF_{L}-\\alpha_{R}\\,\\sqrt{\\gamma_{R}}\\,\\bF_{R}.\n\\end{equation}\nNow, we note that $s_{L}=s_{R}$, and that geometry fields are continuous across discontinuities, which means that the metric determinant cancels. This yields, defining the middle wave-speed $\\lambda$ as\n\\begin{equation}\n\\lambda\\equiv\\frac{ds}{dt},\n\\end{equation}\n\\begin{equation}\n\\lambda\\left(\\bU_{L}-\\bU_{R}\\right)=\\alpha\\left(\\bF_{L}-\\bF_{R}\\right).\n\\end{equation}\nThese are the \\textit{Rankine-Hugoniot jump conditions} and they describe how the fluid variables change across a discontinuity. Next we derive an expression for an estimate of the value of the middle wave-speed, $\\lambda$.\n\n\\subsection{Derivation of Estimate of Middle Wave-Speed $\\lambda$}\nNow we apply the jump conditions to the shocked and un-shocked fluid (either the left or the right state):\n\\begin{equation}\n\\lambda^{i}\\left(\\bU^{*}-\\bU\\right)=\\alpha\\left(\\left(\\bF^{*}\\right)^{i}-\\bF^{i}\\right).\n\\end{equation}\nWe will use the shorthand notation:\n\\begin{equation}\n\\bF^{*i}=\\left(\\bF^{*}\\right)^{i}.\n\\end{equation}\nRecalling that the geometry fields are continuous, we assume that the flux in the shocked region can be written as\n\\begin{equation}\n\\bF^{*i}\\longrightarrow\\left(F^{*i}\\right)^{J}=\\begin{pmatrix}D^{*}\\left(\\lambda^{*i}-\\eta^{i}\\right)\\\\ S^{*}_{j}\\left(\\lambda^{*i}-\\eta^{i}\\right)+p^{*}\\,\\delta^{i}_{~j}\\\\S^{*i}-\\eta^{i}\\,E^{*}\\end{pmatrix}.\n\\end{equation}\nApplying the jump conditions to the momentum-density equation we get\n\\begin{align}\n\\lambda^{i}\\left(S_{j}^{*}-S_{j}\\right)&=\\alpha\\left[S^{*}_{j}\\left(\\lambda^{*i}-\\eta^{i}\\right)+p^{*}\\,\\delta^{i}_{~j}-S_{j}\\left(v^{i}-\\eta^{i}\\right)-p\\,\\delta^{i}_{~j}\\right]\\\\\n\\implies S^{*}_{j}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]&=S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}-p\\right)\\delta^{i}_{~j}.\n\\end{align}\nNow we apply the jump conditions to the energy-density equation, which gives\n\\begin{equation}\n\\lambda^{i}\\left(E^{*}-E\\right)=\\alpha\\left[S^{*i}-\\eta^{i}\\,E^{*}-S^{i}+\\eta^{i}\\,E\\right].\n\\end{equation}\nNow, we note that\n\\begin{align}\nS^{i}&=\\left(E+p\\right)v^{i}\\label{Eq:Mom-En}\\\\\nS^{*i}&=\\left(E^{*}+p^{*}\\right)\\lambda^{*i}.\n\\end{align}\nSubstituting this into the energy-density equation gives\n\\begin{align}\n\\lambda^{i}\\left(E^{*}-E\\right)&=\\alpha\\left[\\left(E^{*}+p^{*}\\right)\\lambda^{*i}-\\eta^{i}\\,E^{*}-\\left(E+p\\right)v^{i}+\\eta^{i}\\,E\\right]\\\\\n\\implies E^{*}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]&=E\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}\\,\\lambda^{*i}-p\\,v^{i}\\right).\\label{Eq:En1}\n\\end{align}\nNow we substitute \\eqref{Eq:Mom-En} into the momentum-density equation which yields\n\\begin{align}\n\\left(E^{*}+p^{*}\\right)\\lambda^{*}_{j}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]&=S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}-p\\right)\\delta^{i}_{~j}\\\\\n\\implies E^{*}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]\\lambda^{*}_{j}&=-p^{*}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]\\lambda^{*}_{j}+S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}-p\\right)\\delta^{i}_{~j}.\n\\end{align}\nEquating this with \\eqref{Eq:En1} gives\n\\begin{align}\n&\\left\\{E\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}\\,\\lambda^{*i}-p\\,v^{i}\\right)\\right\\}\\lambda^{*}_{j}\\\\\n&\\hspace{5em}=-p^{*}\\left[\\lambda^{i}-\\alpha\\left(\\lambda^{*i}-\\eta^{i}\\right)\\right]\\lambda^{*}_{j}+S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\left(p^{*}-p\\right)\\delta^{i}_{~j}.\n\\end{align}\nWe see that the term $\\alpha\\,p^{*}\\,\\lambda^{*i}\\,\\lambda^{*}_{j}$ cancels from both sides. We now isolate $p^{*}$ to get\n\\begin{align}\np^{*}&=\\frac{E\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]\\lambda^{*}_{j}-\\alpha\\,p\\,v^{i}\\,\\lambda^{*}_{j}-S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]+\\alpha\\,p\\,\\delta^{i}_{~j}}{\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}}\\\\\n&=\\frac{\\left\\{E\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]-\\alpha\\,p\\,v^{i}\\right\\}\\lambda^{*}_{j}-\\left\\{S_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]-\\alpha\\,p\\,\\delta^{i}_{~j}\\right\\}}{\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}}.\n\\end{align}\nNow we note that\n\\begin{equation}\nE\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]-\\alpha\\,p\\,v^{i}=\\lambda^{i}\\,E-\\alpha\\left[\\left(E+p\\right)v^{i}-\\eta^{i}\\,E\\right]=\\lambda^{i}\\,E-\\alpha\\left(S^{i}-\\eta^{i}\\,E\\right)=\\lambda^{i}\\,E-\\alpha\\,F^{i}_{E},\n\\end{equation}\nand\n\\begin{equation}\nS_{j}\\left[\\lambda^{i}-\\alpha\\left(v^{i}-\\eta^{i}\\right)\\right]-\\alpha\\,p\\,\\delta^{i}_{~j}=\\lambda^{i}\\,S_{j}-\\alpha\\left[S_{j}\\left(v^{i}-\\eta^{i}\\right)+p\\,\\delta^{i}_{~j}\\right]=\\lambda^{i}\\,S_{j}-\\alpha\\,F^{i}_{S_{j}}.\n\\end{equation}\nWith this, we have\n\\begin{equation}\np^{*}=\\frac{\\left(\\lambda^{i}\\,E-\\alpha\\,F^{i}_{E}\\right)\\lambda^{*}_{j}-\\left(\\lambda^{i}\\,S_{j}-\\alpha\\,F^{i}_{S_{j}}\\right)}{\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}}.\n\\end{equation}\nNow, since the pressure is continuous across contact discontinuities we can equate the left and right states, giving\n\\begin{equation}\n\\frac{\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\lambda^{*}_{j}-\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)}{\\alpha\\,\\delta^{i}_{~j}-\\left(-\\lambda^{i}_{L}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}}=\\frac{\\left(\\lambda^{i}_{R}\\,E_{R}-\\alpha\\,F^{i}_{E,R}\\right)\\lambda^{*}_{j}-\\left(\\lambda^{i}_{R}\\,S_{j,R}-\\alpha\\,F^{i}_{S_{j},R}\\right)}{\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}_{R}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}}.\n\\end{equation}\nNow, cross-multiplying and focusing on the LHS:\n\\begin{align}\n&\\left[\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}_{R}+\\alpha\\,\\eta^{i}\\right)\\lambda^{*}_{j}\\right]\\left[\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\lambda^{*}_{j}-\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\right]\\\\\n&=\\left[\\alpha\\,\\delta^{i}_{~j}-\\left(\\lambda^{i}_{R}+\\beta^{i}\\right)\\lambda^{*}_{j}\\right]\\left[\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\lambda^{*}_{j}-\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\right]\\\\\n&=\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\lambda^{*}_{j}-\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\\\\n&\\hspace{3em}-\\left(\\lambda^{i}_{R}+\\beta^{i}\\right)\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\left(\\lambda^{*}_{j}\\right)^{2}+\\left(\\lambda^{i}_{R}+\\beta^{i}\\right)\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\lambda^{*}_{j}\\\\\n&=-\\left(\\lambda^{i}_{R}+\\beta^{i}\\right)\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\left(\\lambda^{*}_{j}\\right)^{2}\\\\\n&\\hspace{3em}+\\left[\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)+\\left(\\lambda^{i}_{R}+\\beta^{i}\\right)\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\right]\\lambda^{*}_{j}\\\\\n&\\hspace{3em}-\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j,L}}\\right).\n\\end{align}\nExpanding out the terms gives\n\\begin{align}\n&\\left[\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\,E_{L}+\\lambda^{i}_{R}\\,\\alpha\\,F^{i}_{E,L}-\\beta^{i}\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)\\right]\\left(\\lambda^{*}_{j}\\right)^{2}\\\\\n&+\\left[\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,E_{L}-\\alpha\\,F^{i}_{E,L}\\right)-\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\,S_{j,L}-\\lambda^{i}_{R}\\,\\alpha\\,F^{i}_{S_{j},L}+\\beta^{i}\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right)\\right]\\lambda^{*}_{j}\\\\\n&-\\alpha\\,\\delta^{i}_{~j}\\left(-\\lambda^{i}_{L}\\,S_{j,L}-\\alpha\\,F^{i}_{S_{j},L}\\right).\n\\end{align}\nFrom symmetry, by letting $L\\leftrightarrow R$ and $\\lambda^{i}_{L}\\leftrightarrow-\\lambda^{i}_{R}$, we can immediately write down the RHS as\n\\begin{align}\n&\\left[\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\,E_{R}-\\lambda^{i}_{L}\\,\\alpha\\,F^{i}_{E,R}-\\beta^{i}\\left(\\lambda^{i}_{R}\\,E_{R}-\\alpha\\,F^{i}_{E,R}\\right)\\right]\\left(\\lambda^{*}_{j}\\right)^{2}\\\\\n&+\\left[\\alpha\\,\\delta^{i}_{~j}\\left(\\lambda^{i}_{R}\\,E_{R}-\\alpha\\,F^{i}_{E,R}\\right)-\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\,S_{j,R}+\\lambda^{i}_{L}\\,\\alpha\\,F^{i}_{S_{j},R}+\\beta^{i}\\left(\\lambda^{i}_{R}\\,S_{j,R}-\\alpha\\,F^{i}_{S_{j},R}\\right)\\right]\\lambda^{*}_{j}\\\\\n&-\\alpha\\,\\delta^{i}_{~j}\\left(\\lambda^{i}_{R}\\,S_{j,R}-\\alpha\\,F^{i}_{S_{j},R}\\right).\n\\end{align}\nNow we subtract the LHS from the RHS, giving\n\\begin{align}\n&\\left[\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\left(E_{R}-E_{L}\\right)-\\left(\\lambda^{i}_{R}\\,\\alpha\\,F^{i}_{E,L}+\\lambda^{i}_{L}\\,\\alpha\\,F^{i}_{E,R}\\right)-\\beta^{i}\\left(\\lambda^{i}_{R}\\,E_{R}+\\lambda^{i}_{L}\\,E_{L}+\\alpha\\,F^{i}_{E,L}-\\alpha\\,F^{i}_{E,R}\\right)\\right]\\left(\\lambda^{*}_{j}\\right)^{2}\\\\\n&+\\left[\\alpha\\,\\delta^{i}_{~j}\\left(\\lambda^{i}_{R}\\,E_{R}+\\lambda^{i}_{L}\\,E_{L}+\\alpha\\,F^{i}_{E,L}-\\alpha\\,F^{i}_{E,R}\\right)-\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\left(S_{j,R}-S_{j,L}\\right)+\\lambda^{i}_{R}\\,\\alpha\\,F^{i}_{S_{j},L}+\\lambda^{i}_{L}\\,\\alpha\\,F^{i}_{S_{j},R}\\right.\\\\\n&\\hspace{3em}\\left.+\\beta^{i}\\left(\\lambda^{i}_{R}\\,S_{j,R}+\\lambda^{i}_{L}\\,S_{j,L}+\\alpha\\,F^{i}_{S_{j},L}-\\alpha\\,F^{i}_{S_{j},R}\\right)\\right]\\\\\n&-\\alpha\\,\\delta^{i}_{~j}\\left(\\lambda^{i}_{R}\\,S_{j,R}+\\lambda^{i}_{L}\\,S_{j,L}+\\alpha\\,F^{i}_{S_{j},L}-\\alpha\\,F^{i}_{S_{j},R}\\right).\n\\end{align}\nBy making use of the HLL conserved variables and fluxes,\n\\begin{align}\n\\left(\\lambda^{i}_{R}+\\lambda^{i}_{L}\\right)\\bU_{HLL}&=\\lambda^{i}_{R}\\,\\bU_{R}+\\lambda^{i}_{L}\\,\\bU_{L}+\\alpha\\,\\bF^{i}_{L}-\\alpha\\,\\bF^{i}_{R}\\\\\n\\left(\\lambda^{i}_{R}+\\lambda^{i}_{L}\\right)\\bF^{i}_{HLL}&=\\lambda^{i}_{R}\\,\\alpha\\,\\bF^{i}_{L}+\\lambda^{i}_{L}\\,\\alpha\\,\\bF_{R}-\\lambda^{i}_{R}\\,\\lambda^{i}_{L}\\left(\\bU_{R}-\\bU_{L}\\right),\n\\end{align}\nwe can simplify the quadratic equation to (assuming that $\\lambda^{i}_{L}\\neq0$ \\textbf{and} $\\lambda^{i}_{R}\\neq0$)\n\\begin{equation}\n\\left(-F^{i}_{E,HLL}-\\beta^{i}\\,E_{HLL}\\right)\\left(\\lambda^{*}_{j}\\right)^{2}+\\left[\\alpha\\,\\delta^{i}_{~j}\\,E_{HLL}+F^{i}_{S_{j},HLL}+\\beta^{i}\\,S_{j,HLL}\\right]\\lambda^{*}_{j}-\\alpha\\,\\delta^{i}_{~j}\\,S_{j,HLL}=0.\n\\end{equation}\nNow we just multiply the equation by $-1$, which gives\n\\begin{equation}\n\\left(F^{i}_{E,HLL}+\\beta^{i}\\,E_{HLL}\\right)\\left(\\lambda^{*}_{j}\\right)^{2}-\\left[\\alpha\\,\\delta^{i}_{~j}\\,E_{HLL}+F^{i}_{S_{j},HLL}+\\beta^{i}\\,S_{j,HLL}\\right]\\lambda^{*}_{j}+\\alpha\\,\\delta^{i}_{~j}\\,S_{j,HLL}=0.\n\\end{equation}\nFinally, we use the metric to raise the index on the contact wave-speed, which gives\n\\begin{equation}\n\\left(\\gamma_{jk}\\right)^{2}\\left(F^{i}_{E,HLL}+\\beta^{i}\\,E_{HLL}\\right)\\left(\\lambda^{*k}\\right)^{2}-\\gamma_{jk}\\left[\\alpha\\,\\delta^{i}_{~j}\\,E_{HLL}+F^{i}_{S_{j},HLL}+\\beta^{i}\\,S_{j,HLL}\\right]\\lambda^{*k}+\\alpha\\,\\delta^{i}_{~j}\\,S_{j,HLL}=0.\n\\end{equation}\n\nWe see that in the special relativistic, Cartesian coordinate limit of $\\alpha\\rightarrow1$, $\\beta^{i}\\rightarrow0^{i}$, and $\\gamma_{ij}=\\delta_{ij}$, we recover the result of \\citet{Mignone2005}.\n\n\\newpage\n\\bibliographystyle{../apj}\n\\bibliography{../../References/references.bib}\n\\end{document}\n", "meta": {"hexsha": "40fe18ba1b98774de5c31c0432654a41b68802c3", "size": 18665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/ContactWaveSpeed_Relativistic/ContactWaveSpeed_Relativistic.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/Euler/ContactWaveSpeed_Relativistic/ContactWaveSpeed_Relativistic.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/Euler/ContactWaveSpeed_Relativistic/ContactWaveSpeed_Relativistic.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": 77.7708333333, "max_line_length": 455, "alphanum_fraction": 0.6391106349, "num_tokens": 7298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6122964446608644}}
{"text": "\\section{Bounded Model Checking,  k-induction, and IC3}~\\label{sec:mck}\n\n\n\n\n\nHighly automated proof techniques are a necessary step for the\nwidespread adoption of formal methods in the software industry.\n One of the more popular techniques used in industry is {\\em Model\n  checking}, where a design is modeled as finite state machine, and\nspecification of some property is formalized in a suitable logic.  The\nmodel checker traverses all of the \nreachable states of the design in order to verify that the property\nholds.  If the property fails, then a sequence of states leading to\nthe failure is produced as a {\\em counterexample.} The main difficulty\nwith this technique is the huge size of usual search spaces. To tackle\nthis, we use logical formula as a concise description for sets of\nstates and the transition relation in the graph of states is decided\nby SMT solvers.  Our work applies\nthe technique of {\\em bounded model checking with satisfiability\n  solving}~\\cite{ClarkeBounded01,ClarkeBounded03} to the problem of\nverifying Copilot monitors.\n\nTo quote Clarke~\\cite{ClarkeBounded01}\n\\begin{quote}\n  In bounded model checking, we construct a Boolean formula that is\n  satisfiable if and only if the underlying state transition system\n  can realize a finite sequence of state transitions that reaches\n  certain states of interest. If such a path segment cannot be found\n  at a given length, $k$, the search is continued for larger $k.$\n\\end{quote} \n\n\n\\paragraph{Background and Definitions} Recall that a state transition system is a triple $(S,I,T),$\nwhere $S$ is a set of states, $I \\subseteq S$ is the set of initial\nstates and $T \\subseteq S \\times S $ is a transition relation over $S.$ A {\\em kripke\n  structure} is a state transition system $(S,I,T,L)$  with a labeling function\n$L: S \\rightarrow  \\mathcal{P}(A)$.  A state $s \n\\in S$ is said to be {\\em k-reachable} if there exists a path from an\ninitial state $i\\in I$ to $s$ of length at most $k.$ A state is said\nto be {\\em reachable} if it is $k$-reachable for some $k\\in \\mathbb{N}.$\nLikewise, a set of states $Q \\subset S$ is said to be reachable if\nthere exists a reachable state in $S.$  Given a transition system, a\nset of states containing all the reachable states of the system is\nsaid to be {\\em invariant.} In the classic procedure for model checking of Linear\nTemporal Logic (LTL) specifications, one computes the product of\nthe kripke structure modeling the system and an transition system that\nrepresents the negation of the specification~\\cite{ClarkeMC}. This product captures\nthe counterexamples of executions violating the property. \n\n\\paragraph{Bounded Model Checking} Bounded model checking was developed to exploit the success of modern\nsatisfiability (SAT) solvers and more recently satisfiability modulo\ntheories (SMT) solvers. Bounded model checking only considers finite\nprefixes of length $k$  of a path that may be a witness acting as a\ncounterexample. In practice, the value of $k$ is systematically\nincreased to look for counterexamples in longer traces.  \n\n  \nSuppose we wish to apply bounded model checking to show that property\n$P$ holds in  the system modeled by the transition\nsystem $(S,I,T,L),$ where $P: S \\rightarrow \\mathbb{B}$ represents\nthe predicate $P$ defined over the states of $S$ such that $P(s)$\nholds in states $s.$\nFormulating this as the following entailment:\n$$ I(s_0) \\tland T(s_0,s_1) \\tland \\cdots \\tland T(s_{k-1},s_k)\n\\models P(s_k)$$\nfor increasing values of $k.$ In the case of $\\tlnot P$ is reachable,\nthe SMT solver will provide an assignment for \n$$I(s_0) \\tland T(s_0,s_1) \\tland T(s_{k-1},s_k) \\tland \\tlnot\nP(s_k)$$\nthat can be used a counterexample. \n\n\\paragraph{$k$-induction}  In proving $P$ manually, a common technique\nis mathematical induction.  Applying classical induction to prove a\nproperty $P$ holds on  for a model one would first show the base case\nby proving that the property is satisfied by the initial state:\n$$I(s_0) \\models P(s_0).$$\nIf the base case holds, then show the inductive step that $P$ holds\nfor some state $n$ and prove it holds for the next state $n+1:$\n$$ T(s_{n},s_{n+1}) \\tland P(s_n) \\models P(s_{n+1}).$$\n\nSheeran~\\etal~\\cite{Sheeran00, EenS03} introduced\n$k-$induction that has the advantage that it is well suited for SAT\nbased bounded model checking.  One begins as with the standard\ninduction, but if one cannot show the property to be true, the\nproperty is strengthened by extending the formula and\nprogressively increasing the length of the reachable states\nconsidered.  To show $P$ holds in the transition system one must first\nshow the base case holds, that is $P$ holds in all states reachable\nfrom an initial state in $k$ steps, and then show the induction step,\nthat if $P$ holds in states $s_0,\\ldots,s_{k-1}$ then it holds in\nstate $s_k.$ The $k$-induction principle is formally expressed in the\nfollowing two entailments:\n\\begin{eqnarray*}\nI(s_0) \\tland T(s_0,s_1) \\tland \\cdots \\tland T(s_{k-1},s_k) &\\models&\nP(s_k) \\\\\nP(s_0) \\tland \\cdots \\tland P(s_{k-1}) \\tland T(s_0,s_1) \\tland \\cdots \\tland T(s_{k-1},s_k) &\\models&\nP(s_k) \n\\end{eqnarray*} \n\nProperty $P$ said to be a $k$-inductive property with respect to\n$(S,I,T)$ if there exists some $k \\in \\mathbb{N}^{0<}$ such that $P$\nsatisfies the $k$-induction principle. As $k$ increases, weaker\ninvariants may be proved. \\jonathantxt{If $P$ is a safety property that doesn't hold, then the first entailment will break for a finite $k$ and a counterexample will be provided.} The trick is to find an invariant that is\ntractable by the SMT solver yet weak enough to satisfy the desired\nproperty.  \n\n\\paragraph{Path Compression}  A major enhancement to the basic\n$k$-induction \nalgorithm eliminates redundant searches via a procedure\nknown as path compression~\\cite{dMRS03} that strengthens the left-hand\nside of the entailments to eliminate paths that contain repeated configurations  (due to\na cycle) or configurations that are equivalent.  \n\n\nIndeed, if $P$ is not invariant, a\ncounterexample exists such that it is cycle-free and only its first state belongs to $I$. More formally, these constraints hold for the path $s_0 \\cdots s_k$ if and only if  $C_k(s_0,\\ldots,s_k)$ hold, where :\n\n$$C_k(s_0,\\ldots,s_k) = \\bigwedge_{i \\neq j} s_i \\neq s_j  \\tland\n\\bigwedge_{i > 0} \\tlnot I(s_i),$$\nand where equality is defined  pointwise over the state vectors.\nWe can now strengthen the left hand side of the induction step\nentailment:\n$$\\bigwedge^{k-1}_{i=0} P(s_i) \\tland \\bigwedge ^{k-1}_{i=0}\nT(s_i,s_{i+1}) \\tland C_k(s_0, \\ldots, s_k) \\models P(s_k). $$\nNow, we can make the algorithm complete for bounded state spaces by\nchecking the entailment \n$$I(s_0) \\tland T(s_0,s_1) \\tland \\cdots \\tland T(s_{k-1}, s_{k})\n \\models \\tlnot C_k(s_0,\\ldots, s_{k-1})$$\nafter the $k$-th bounded model checking iteration.  If this entailment\nholds, and $P$ is $k$-invariant, then $P$ is invariant. \n\n\\paragraph{Structural Abstraction}\nA limiting factor when it comes to applying $k-$induction in practice\nis the computing resources required by the SMT solver. Abstraction is\noften applied to the model the system being analyzed in order to\nreduce the problem space to a more manageable problem.  {\\em\n  Structural abstraction}~\\cite{ bh07structural} is a technique that\nconstructs a abstract model that simulates the concrete one and\naccepts at least the behaviors accepted by the concrete model. The\nabstraction can reduce the size of the problem\nspace and render $k-$induction tractable. This\napproach is  \nrelated to counterexample guided refinement\n(CEGAR)~\\cite{Clarke2003CAR}, where if a counterexample is produced in\nthe analysis of the abstract model that is inconsistent with the\nconcrete model, the abstraction is refined to eliminate the\ncounterexample. The idea is to replace $T$\nby a weaker approximation $T'$ by removing some clauses. Then, \n\\begin{itemize}\n\\item If $P$ is invariant for $T',$ then $P$ is also invariant for $T.$\n\\item Otherwise, we use the counterexample produced by the SMT solver\n  to refine $T'$ by restoring some well-chosen clauses.\n\\end{itemize}  \nIndeed, suppose a counterexample $(v_0,\\ldots, v_k)$ is found for $T'$. Then we can\ncheck whether or not\n%$$\\bigwedge_{i=0}^k  \\bigwedge_{j=1}^n v_{ij} = s_{ij} \\tland I(s_0)\n%\\tland \\bigwedge_{i=0}^{k-1} T(s_i,s_{i+1})$$ \n\n$$ I(v_0)\n\\tland \\bigwedge_{i=0}^{k-1} T(v_i,v_{i+1})$$ \n\n\\jonathan{I simplified the old formula, which I originally made too complex for subtle reasons (optimal use of incremental SMT solvers)}\n\nis satisfiable.  If it is, then the counterexample is valid for $T$.\nOtherwise, the counterexample is spurious. In that case, it is possible to query\nthe SMT solver to obtain an unsatisfiable core of state variables that\ncandidates for refinement.\n\n\n\n\n\n\n\n%\\paragraph{IC3 Algorithm} \n\n%\\jonathan{Concerning this paragraph, I wonder if it's a good thing to give such a brief but formal description. I'm not sure anyone who don't already know the algorithm could understand more than the very basic idea just with this. In my case, it took me several much longer articles to understand the very subtle IC3 algorithm. Maybe we should give up trying to give a formal description, just give the main idea and a reference to a more detailed document in a shorter paragraph. What do you think ? I'm not sure I'm right, I'm really biased on this question.}\n\n%Bounded model checking approaches such as $k$-induction suffer from\n%the drawback of searching for a single strengthening of the invariant\n%to be proved. This monolithic approach often  overwhelms the SAT\n%solver due to its many iterations. \\jonathan{Moreover, we should add that k-induction technique is limited to k-inductive properties.} \n\n\n\n\n%Recall that a property $P$ is inductive if \n%\\jonathan{I don't agree with your notations in this paragraph. Instead of :}\n%$$ P(s_{k-1}) \\tland T(s_{k-1},s_k) \\models P(s_k). $$\n%\\jonathan{I would have written $$ P(s) \\tland T(s, s') \\models P(s'). $$ Indeed, you notation suggests the last equation is about a path and not about a single transition. The use of indexes is misleading I think. What is your opinion about this ? }\n% Otherwise there\n%exists states $s_{k-1}$ and $s_k$ such that  \n$$P(s_{k-1}) \\tland T(s_{k-1},s_k) \\tland \\tlnot P(s_k),$$\n%where $s_{k-1}$ is said to be the {\\em counterexample to\n%  inductiveness} (CTI). The property $P$ is said to be inductive\n%relative to $A$ if and only if\n%$$A(s_{k-1}) \\tland  P(s_{k-1}) \\tland T(s_{k-1},s_k) \\models P(s_k). $$\n%Note that if $P$ is inductive relative to $Q$ and $Q$ is inductive\n%relative to $P,$ then $P \\tland Q$ is inductive.  The idea of using\n%relative inductiveness to prove inductiveness lead to the development\n%of incremental approaches such as that used in the FSIS model\n%checker~\\cite{Bradley06, Bradley2011}.  The basic incremental\n%algorithm used in FSIS is as follows:\n%\\begin{itemize}\n%\\item Try to prove $P$ is inductive.\n%\\item If fails,  if $s$ is CTI, then find an inductive invariant\n % $\\phi_0$ such that $\\phi_0(s)$ does not hold. \n%\\item Continue finding such lemmas $\\phi_0, \\phi_1, \\ldots$ until\n%  there are no more CTIs. \n%\\item As $P$ is inductive to $\\bigwedge_{i} \\phi_i$ it s proven\n%  invariant if it holds for the initial states.\n%\\end{itemize}  \n%Note that each $\\phi_i$ has only to be proven inductive relative to\n%the previously discovered CTIs $\\phi_0, \\phi_1, \\ldots, \\phi_{i-1}$\n%or even inductive to $\\{ \\phi_j \\}_{j<i} \\tland P.$ \n\n\n%As it is difficult to find inductive lemmas, we can limit our search\n%to lemmas that are inductive relative to a formula $R_k$ that\n%over-approximates the set of $k$-reachable states. We then try to\n%propagate these lemmas as $k$ increases, stopping only when reaching a\n%fixed point. The IC3 algorithm~\\cite{Somenzi-FMCAD11,\n%  BradleyCAV12,bradley2012understanding} searches for an\n%over approximation $R$ of the reachable sets such that:\n%\\begin{eqnarray*} \n%I(s_{k-1})  & \\models & R(s_{k-1}) \\\\\n%R(s_{k-1})  \\tland  T(s_{k-1},s_k) &\\models & R(s_k)  \\\\\n%R(s_{k-1})  & \\models & P(s_{k-1})\n%\\end{eqnarray*}\n%where $R$  is constructed as a fixed point of an increasing sequence\n%of $(R_k),$ where each frame $(R_k)$ can be viewed as a conjunction of\n%lemmas. The sequence exhibits the following properties: \n%\\begin{eqnarray*}\n%R_0 & = & \\{ I \\} \\\\\n%R_{i+1} & \\subset & R_i \\\\\n%R_i(s_{k-1}) \\tland  T(s_{k-1},s_k) &\\models & R_{i+1}(s_k)   \\\\\n%P &\\in& R_i \\ \\ \\mbox{for} \\ i > 0. \n%\\end{eqnarray*}\n %If the sequence satisfies these four constraints and admits a fixed\n %point, then $P$ is invariant.   In constructing the sequence, $R_0$\n %is initialized to $\\{ I \\}$ and  $R_1 = P.$  We continue in similar\n %fashion, at  each step, $k,$ is initialized to $P$ then propagate as\n% many lemmas from the previous frame as possible while ensuring that\n %the an error is not reached within one transition step. \n\n%Just as $R$ represents the reachable good states, the IC3 algorithm\n%maintains a set of bad states $B$ such that each state in $B$ leads to\n%an error in one step.  In order to show $B$ is unreachable in $R_k$\n%the predicate $\\tlnot B$ is conjoined to $R_k$ as a lemma.  Although\n%$B$ may not be inductive, it is sufficient to show that it is\n%inductive relative to the previous frame and consequently $B$ is not\n%$k-$reachable.  This can be accomplished by checking the following two\n%entailments:\n%\\begin{eqnarray*}\n%I(s_{i-1}) & \\models & \\tlnot B(s_{i-1}) \\\\ \n%R_{k-1} (s_{i-1}) \\tland \\tlnot  B(s_{i-1}) \\tland T(s_{i-1}, s_i) \n%& \\models & \\tlnot B(s_i).\n%\\end{eqnarray*}\n%If the first entailment fails, then $P$ is not an invariant. If the\n%second fails,  then $B$ is reachable from some state of the previous\n%frame. We generalize this state to a set of states $B',$ consisting of\n%states belonging to the previous frame that lead to $B$ in a single\n%transition.  Next, the algorithm recursively refines $R_{k-1}$ to\n%remove the states in $B'.$ This backward reachability is performed\n%until one of the following conditions are met:\n%\\begin{itemize}\n%\\item The algorithm reaches $R_0 = I$ whence $P$ is not invariant. \n%\\item All the bad states that are recursively generated have been\n % shown to be $k$-unreachable. \n%\\end{itemize} \n\n%Once the strengthening process completes, meaning that no error state\n%is reachable from the last frame, the IC3 algorithm propagates the new\n%lemmas we discovered from each frame to its successor. This is\n%accomplished by verifying the entailment\n\n%$$ R_j(s_{i-1}) \\tland  T(s_{i-1}, s_i)  \\models C(s_i)$$\n%for all $C \\in R_j - R_{j+1},$ where $j$ increases from $0$ to $k.$\n%If all the lemmas of $R_{k-1}$ are successfully propagated to $R_k$,\n%the sequence $(R_j)$ reaches a fixed point and $P$ is proven to be\n%invariant.  Otherwise,  a new frame $R_{k+1}$ is added that is  initialized to $P$\n%and the algorithm continues.  Numerous improvements to the basic\n%algorithm such as {\\em lemma tightening} can be found in the\n%literature that can produce an invariant that is more tractable to\n%modern SMT solvers. \n\n\n\n", "meta": {"hexsha": "36f9e49fc55d60222ed0b9c4ef8e0b2a7f0fbd81", "size": 15048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "co-kind-report/mc-kind.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": "co-kind-report/mc-kind.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": "co-kind-report/mc-kind.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": 51.8896551724, "max_line_length": 563, "alphanum_fraction": 0.7395002658, "num_tokens": 4402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511359371249, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6122964342750604}}
{"text": "\\subsection{Decomposition of T}\n\\SecLabel{t}\n\nThe decomposition of $T$ follows similar path as that of $U$, but with a couple of differences. all permutations $T_i$ are linearly-equivalent, excluding $T_{\\hex{0}}$. The latter function stands out and does not follow any patterns. Furthermore, all $T_i,i \\ne 0$ are related only by linear layer in the input. Let $N_{\\hex{1}},\\ldots,N_{\\hex{f}}\\colon \\field{4} \\to \\field{4}$ be given by\n$$\nN_k(x) \\eqdef T_k^{-1}(x) \\circ T_{\\hex{1}}(x).\n$$\nFor any $k \\ne 0$, $T_k = T_{\\hex{1}} \\circ N_k$ and each of $N_i$ is affine. The look-up table of $N$ is given in \\TabRef{n}.\n\nIn order to obtain linear mapping from affine, we detach the constant xor \\emph{before} the linear map. It could also be detached \\emph{after}, but detaching \\emph{before} allows to merge it with the outer linear layer $L$. Let $\\delta\\colon \\field{4} \\to \\field{4}$ be given by\n$$\n\\delta(k) \\eqdef \\begin{cases}\n    0, &~\\text{if}~k = 0,\\\\\n    N_k^{-1}(0), &~\\text{otherwise}.\n\\end{cases}\n$$\nIt turns out that $\\delta$ is a linear map:\n$$\n\\delta(k_1, k_2, k_3, k_4) = (0, k_1 \\oplus k_3, 0, k_1 \\oplus k_2 \\oplus k_3).\n$$\n\nLet $N'_{\\hex{1}},\\ldots,N'_{\\hex{f}}\\colon \\field{4} \\to \\field{4}$ be given by\n$$\nN'_k(x) = N_k(x \\oplus \\delta(k)).\n$$\nThen all $N'_k$ are linear functions, i.e. $N'_k(0) = 0$ for all $k \\in \\field{4},k\\ne 0$. The codebook of $N'$ is given in \\TabRef{np}.\n\n\\FigTex{n-np.tex}\n\nConsider $N'_{\\hex{2}}$ (other choices are possible, but this one leads to simplest linear layers in the decomposition). It is linear-similar to the same field multiplication chosen in the decomposition of $U$: there exists $\\eta \\in \\linbij{4}$ such that\n$$\nN'_{\\hex{2}} = \\eta \\circ (\\cdot~\\odot X) \\circ \\eta^{-1}.\n$$\nSuch $\\eta$ is given by:\n$$\n\\eta(x_1, x_2, x_3, x_4) \\eqdef (x_1, x_2 \\oplus x_4, x_3 \\oplus x_2, x_4).\n$$\nFurther, all $N'_k$ turn out to be multiplications by a $k$-dependent constant in the finite field. Let $\\varepsilon\\colon \\field{4} \\to \\field{4}$ be given by\n$$\n\\varepsilon(k) \\eqdef \\begin{cases}\n0, & ~\\text{if}~ k = 0,\\\\\n\\eta^{-1} \\circ N'_{k} \\circ \\eta (1), & ~\\text{otherwise}.\n\\end{cases}\n$$\nThen $\\varepsilon$ turns out to be a bijection, and the following holds for $k \\ne 0$:\n$$\n\\eta^{-1} \\circ N'_{k} \\circ \\eta (x) = \\varepsilon(k) \\odot x,\n$$\n$\\varepsilon$ seems to be a complicated permutation without any pattern. Note that when the inverse of $T$ is computed, the field multiplication becomes the field division and thus, the output of $\\varepsilon$ is inverted. Denote the composition of the inversion in the finite field with $\\varepsilon$ by $1/\\varepsilon$ (defining $1/0 = 0$). Surprisingly, it is a linear function. Furthermore, when composed with $\\swaplsb$ which appears here from the decomposition of $U$, it becomes a simple multiplication by a constant in the finite field:\n$$\n1/\\varepsilon \\circ \\swaplsb(k) = k \\odot (X^3 + X^2)\n$$\nfor all $k \\in \\field{4}$.\nIt follows that\n$$\n\\varepsilon(k) = 1/(\\swaplsb(x) \\odot (X^3 + X^2)) = X \\odot (1 / \\swaplsb(k)),\n$$\nwhere $X \\odot (X^3 + X^2) = 1$ in the chosen finite field. The multiplication by constant can be transferred through the main multiplication in $N'$ and merged with $T_{\\hex{1}}$.\n\nWe obtain that, when $k \\ne 0$, $T_k$ can be computed as:\n$$\nT_k(x) = T_{\\hex{1}} \\circ \\eta (\\cdot~\\odot X) \\pround{\n(1/\\swaplsb(k)) \\odot \\eta^{-1} (x \\oplus \\delta(k))\n}.\n$$\nThe addition of $\\delta(k)$, $\\eta^{-1}$ and $\\swaplsb$ can be merged with the outer linear layer $L$. $\\eta$ can be merged with $T_{\\hex{1}}$, and $\\swaplsb$ will cancel out when $T$ is merged with $U$.\n\nLet\n\\begin{align*}\n\\zeta_0 &\\eqdef T_{\\hex{0}} \\circ \\eta,\\\\\n\\zeta_+ &\\eqdef T_{\\hex{1}} \\circ \\eta \\circ (\\odot X).\n\\end{align*}\n\nThen $$\nT_k(x) = \\begin{cases}\n\\zeta_+ \\pround{\n(1/\\swaplsb(k)) \\odot \\eta^{-1} (x \\oplus \\delta(k))\n},&~\\text{if}~k\\ne 0,\\\\\n\\zeta_0\\pround {\n\\eta^{-1} (x \\oplus \\delta(k))\n},&~\\text{if}~k = 0.\n\\end{cases}\n$$\n\nThe final decomposition of $T^{-1}$ and the codebooks of $\\delta, \\eta, \\swaplsb, \\zeta_0, \\zeta_+$ and the field inverse $1/x$ are given are shown in \\FigRef{final-t}. It uses a multiplexer, which chooses its left input branch if the control branch (i.e., $k$) is equal to zero, and its right input branch otherwise.\nThe only differences between $T$ and $T^{-1}$ are using the inverses of $\\zeta_0, \\zeta+$, removing the field inversion, and changing the position of the multiplexer. Note that $\\eta$ is an involution, and the addition of $\\delta(k)$ is involution too. \n\n\\FigTex{final-t.tex}", "meta": {"hexsha": "9dcfeeacf6996eae66a5cf51d9e03d93e6651c91", "size": 4539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strKuz/11t.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/11t.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/11t.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": 51.5795454545, "max_line_length": 544, "alphanum_fraction": 0.6664463538, "num_tokens": 1627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7122321964553656, "lm_q1q2_score": 0.6122801961171999}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{hyperref}\n\\usepackage[pdftex]{graphicx}\n%\\usepackage{physymb}\n%\\usepackage{wrapfig}\n\\usepackage{braket}\n\\usepackage{subcaption}\n\\title{PH 304: Assignment 1}\n\n\\author{Manish Goregaokar (120260006)}\n\\date{January 25, 2015}\n\\begin{document}\n\\maketitle\n\\section*{Problem 1}\n\nThe probability of there not being a single 1 in four rolls is $\\frac56\\times\\frac56\\times\\frac56\\times\\frac56 = \\frac{625}{1296}$ since we restrict each die roll to the space of 2-6 (5 possibilities) out of its actual space of 6.\n\nThe inverse of this, i.e. the probability of there being at least one 1 in four rolls, is  $\\boxed{1 - \\frac{625}{1296} = \\frac{671}{1296} = 0.517747}\\hfill \\text{Ans (i)}$\n\nWhen a pair of dice are rolled 24 times, the probability of never getting a double 1 is $\\left(\\frac{35}{36}\\right)^{24}$ since the (equiprobable) sample space for a single roll has 36 candidates, of which  one is a double-1. Thus the probability of having at least one double 1 is $\\boxed{1-\\left(\\frac{35}{36}\\right)^{24} = 0.491404}\\hfill\\text{Ans (ii)}$\n\\section*{Problem 2}\nLet the probability for a single ameoba to die or have its progeny eventually die out be $d$.\n\n\\begin{align*}\nd & = P(\\text{amoeba dies}) + P(\\text{amoeba lives but descendants die})\\\\\n&= 1-p + p(P(\\text{amoeba or descendants die out})^2)\\\\\n&= 1-p + pd^2\\\\\n\\therefore d &= 1-p + pd^2\\\\\n\\therefore 0 &=pd^2 -d +1-p\\\\\n\\therefore d &= \\frac{1\\pm \\sqrt{1-4p(1-p)}}{2p}\\\\\n &= \\frac{1\\pm \\sqrt{4p^2 - 4p + 1}}{2p}\\\\\n  &= \\frac{1\\pm \\sqrt{(2p - 1)^2}}{2p}\\\\\n  &= \\frac{1\\pm (2p -1)}{2p}\n\\end{align*}\n\nFor $p<\\frac12$, the solution with the $+$ is the only possible one, and thus $d=1$. For $p>\\frac12$, it is the solution with the $-$, and we get the probability of death as $\\frac{1-p}{p}$.\n\nThus, the minimum value of $p$ for there to be a non-zero probability of survival ($d<1$) is $\\boxed{\\frac12}$.\n\nFor $p=3/4$, $d=\\frac13$, so the probability of survival is $1-d = \\boxed{\\frac23}$\n\\section*{Problem 3}\nGiven: $P(\\text{twin}) = 0.02, P(\\text{identical twin}) = 0.002$\n\nWe want $P(\\text{identical}|\\text{twin})$, which by Bayes' theorem is $$\\frac{P(\\text{twin}|\\text{identical})P(\\text{identical})}{P(\\text{twin})}=\\frac{P(\\text{identical})}{P(\\text{twin})}=0.1$$\n\nThus the probability that he was an identical twin is $\\boxed{0.1}\\hfill \\text{Ans.}$\n\n\\section*{Problem 4}\n\nThe distribution is $P(n|N) = {n\\choose N}p^n(1-p)^{N-n}$, and thus the characteristic function is \n\\begin{align*}\\tilde{P}(k) &= \\Braket{e^{-ikn}}\\\\\n&= \\sum_{n=0}^N e^{-ikn}{n\\choose N}p^n(1-p)^{N-n}\\\\\n&= \\sum_{n=0}^N {n\\choose N}\\left(e^{-ik}\\cdot p\\right)^n(1-p)^{N-n}\\\\\n&= (1 - p(e^{-ik}-1))^N\n\\end{align*}\n\n$\\therefore \\boxed{\\tilde{P}(k) = (1 - p(e^{-ik}-1))^N}\\hfill \\text{Ans.}$\n\nCumulant generating function\n\n\\begin{align*}\nQ(k) & = \\ln\\tilde{P}(k)\\\\\n&= \\ln (1 - p(e^{-ik}-1))^N\\\\\n&= N \\ln (1 - p(e^{-ik}-1))\n\\end{align*}\n\n$\\therefore \\boxed{\\ln\\tilde{P}(k) = N\\ln (1 - p(e^{-ik}-1))}\\hfill \\text{Ans.}$\n~\\\\\nIf $-ik = y$, then $Q(k) = \\ln\\tilde{P}(k) = \\sum_n \\frac{y^n}{n!}\\Braket{x^n}_C$. This means that $\\left.Q^{(j)}(k)\\right|_{k=0} = \\Braket{x^j}_C$. Thus the first moment is $Q(0) = 0$, and the second moment is calculated as:\n\n\\begin{align*}\nQ'(0) &= \\left.\\frac{d}{dk}N\\ln (1 - p(e^{-ik}-1))\\right|_{k=0}\\\\\n&= \\left.\\frac{N p e^y}{1-p \\left(e^y-1\\right)}\\right|_{k=0}\\\\\n&= Np\n\\end{align*}\n\nThus the first two cumulants are $\\boxed{0}$ and $\\boxed{Np}\\hfill$ Ans.\n\\section*{Problem 5}\n$$p(x) = \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{(x-\\lambda)^2}{2\\sigma^2}\\right]$$\n\n\\begin{align*}\n\\therefore \\tilde{p}(k) &= \\int_{-\\infty}^{\\infty} e^{-ikx} \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{(x-\\lambda)^2}{2\\sigma^2}\\right] dx\\\\\n&=\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{(x-\\lambda)^2 + 2ikx\\sigma^2}{2\\sigma^2}\\right] dx\\\\\n&=\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{x^2 + \\lambda^2 - 2x\\lambda + 2ikx\\sigma^2}{2\\sigma^2}\\right] dx\\\\\n&=\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{x^2 - 2x(\\lambda - ik\\sigma^2) + \\lambda^2 }{2\\sigma^2}\\right] dx\\\\\n&=\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{x^2 - 2x(\\lambda - ik\\sigma^2) + (\\lambda - ik\\sigma^2)^2 -2\\lambda ik\\sigma^2 +i^2k^2\\sigma^4 }{2\\sigma^2}\\right] dx\\\\\n&=\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{(x -(\\lambda - ik\\sigma^2))^2 -2\\lambda ik\\sigma^2 +i^2k^2\\sigma^4 }{2\\sigma^2}\\right] dx\\\\\n&=e^{-\\lambda ik + \\frac12 i^2k^2\\sigma^2}\\int \\frac1{\\sqrt{2\\pi\\sigma^2}}\\exp\\left[-\\frac{(x -(\\lambda - ik\\sigma^2))^2}{2\\sigma^2}\\right] dx\\\\\n&= e^{-\\lambda ik +\\frac12 i^2k^2\\sigma^2} \\cdot 1\\\\\n&= e^{-\\lambda ik +\\frac12  i^2k^2\\sigma^2}\n\\end{align*}\n\nThus cumulant generating function is just $Q(k) = \\ln \\tilde{p}(k) = -\\lambda ik + \\frac12 i^2k^2\\sigma^2$. If $-ik = y$, $Q(y) = y + \\frac12 y^2\\sigma^2$\n\nThus the cumulants are $\\Braket{x^n}_C = (y + \\frac12 y^2\\sigma^2)^{(n)}$, giving us :\n\n$\\boxed{\\Braket{x}_C = 1}$, $\\boxed{\\Braket{x^2}_C = \\frac12\\sigma^2}$, and for $n>2$, $\\boxed{\\Braket{x^n}_C = 0}$\n\n\\section*{Problem 6}\n\nIf we break T into $n$ intervals of $dt$ each ($dt = T/n$), probability of exactly $M$ of these having an event is (where $\\lambda$ is the proportionality constant such that individual probability is $\\lambda dt$):\n\n$$P(M)_n = {n\\choose M}(\\lambda dt)^M (1-\\lambda dt)^{n-M}$$\n\nAssuming no simultaneous events, we can limit $n$ to infinity:\n\\begin{align*}\n\\lim_{n\\to\\infty} P(M)_n &= \\lim_{n\\to\\infty} {n\\choose M}(\\lambda dt)^M (1-\\lambda dt)^{n-M}\\\\\n&= \\lim_{n\\to\\infty} \\frac{n(n-1)....(n-m+2)(n-m+1)}{M!}\\left(\\lambda \\frac{T}{n}\\right)^M \\left(1-\\lambda \\frac{T}{n}\\right)^{n-M}\\\\\n&= \\lim_{n\\to\\infty} \\frac{n(n-1)....(n-m+2)(n-m+1)}{n^M}\\frac{\\left(\\lambda T\\right)^M}{M!} \\left(1-\\lambda \\frac{T}{n}\\right)^n\\left(1-\\lambda \\frac{T}{n}\\right)^{-M}\\\\\n&=1\\cdot   \\frac{\\left(\\lambda T\\right)^M}{M!} \\cdot  e^{-\\lambda T} \\cdot 1\\\\\n&= \\frac{k^M e^{-k}}{M!}\\qquad\\qquad (k = T\\lambda)\n\\end{align*}\n\n\nThus, the probability distribution, in terms of the proportionality constant $\\lambda$ is:\n\n$\\boxed{P(M) = \\frac{(T\\lambda)^M e^{-T\\lambda}}{M!}}$\n\nThe characteristic function can be calculated as  (rewriting $T\\lambda$ as $\\lambda$)\n\\begin{align*}\n\\tilde{P}(k) &= \\sum_{M=0}^\\infty \\frac{\\lambda^M e^{-\\lambda}}{M!}e^{-ikM}\\\\\n&= e^{-\\lambda}\\sum_{M=0}^\\infty \\frac{e^{(ln\\lambda-ik) M}}{M!}\\\\\n&= \\exp{e^{ln\\lambda-ik}-\\lambda}\n\\end{align*}\n\nThus the cumulant generating function is $e^{ln\\lambda-ik}-\\lambda = \\lambda (e^{y} - 1)$, giving us $\\boxed{\\Braket{x^n}_C = \\lambda}$.\n\\end{document}", "meta": {"hexsha": "90335493e21ca6a16ab64078d301d2ac3c30363b", "size": 6574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course material/PH 304 - Statistical Physics/Assignment 1/assign1.tex", "max_stars_repo_name": "CourseResources/CourseResources", "max_stars_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-28T05:59:31.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-28T05:59:31.000Z", "max_issues_repo_path": "Course material/PH 304 - Statistical Physics/Assignment 1/assign1.tex", "max_issues_repo_name": "CourseResources/CourseResources", "max_issues_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Course material/PH 304 - Statistical Physics/Assignment 1/assign1.tex", "max_forks_repo_name": "CourseResources/CourseResources", "max_forks_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_forks_repo_licenses": ["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.1832061069, "max_line_length": 357, "alphanum_fraction": 0.6282324308, "num_tokens": 2703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.6122801815150942}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb}\n\\usepackage[nodayofweek]{datetime}\n\n% Set size of text area with total parameter\n\\usepackage[a4paper, total={155mm, 255mm}]{geometry}\n\n\\title{Polynomial Root Manipulation}\n\\author{Dyson}\n\\date{\\today}\n\n\\newcommand{\\ab}{\\alpha\\beta}\n\\newcommand{\\bg}{\\beta\\gamma}\n\\newcommand{\\ga}{\\gamma\\alpha}\n\\newcommand{\\ag}{\\alpha\\gamma}\n\n\\newcommand{\\sone}{\\alpha + \\beta + \\gamma}\n\\newcommand{\\stwo}{\\alpha\\beta + \\beta\\gamma + \\gamma\\alpha}\n\\newcommand{\\abg}{\\alpha\\beta\\gamma}\n\n\\newcommand{\\Sone}{\\Sigma_1}\n\\newcommand{\\Stwo}{\\Sigma_2}\n\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{sublemma}{Lemma}[lemma]\n\\newtheorem{conjecture}{Conjecture}\n\n\\begin{document}\n\n\\maketitle\n\n% Set paragraph spacing here to avoid messing with title\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{1em}\n\n\\section{The Question}\n\nChallenge question 2 in the mixed exercise at the end of chapter 4 of the Further Maths Core book says:\n\nThe cubic equation $x^3 + 2x^2 -3x - 5 = 0$ has roots $\\alpha$, $\\beta$, and $\\gamma$. Without solving the equation, find an equation that has roots, $\\alpha + \\beta$, $\\beta + \\gamma$, and $\\gamma + \\alpha$.\n\nThis question is completely different to all the prior questions in the chapter. Most of these questions ask for a linear transformation of roots that can be done with simple substitution, but this question requires a full expansion of triple brackets, lots of algebra, and some very interesting problem solving at the end.\n\n\\section{The Answer}\n\n\\subsection{Establishing Lemmas}\n\nFirstly, we want to establish some lemmas. All of these can be shown by expanding $(x - \\alpha)(x - \\beta)(x - \\gamma)$, but we'll just take them as identities here.\n\nFor a cubic equation $ax^3 + bx^2 + cx + d = 0$, for $x \\in \\mathbb{C}$ and $a, b, c, d \\in \\mathbb{R}$ with roots $\\alpha$, $\\beta$, $\\gamma$:\n\n\\begin{lemma}\n$\\sone \\equiv -\\dfrac{b}{a}$\n\\end{lemma}\n\n\\begin{lemma}\n$\\stwo \\equiv \\dfrac{c}{a}$\n\\end{lemma}\n\n\\begin{lemma}\n$\\abg \\equiv -\\dfrac{d}{a}$\n\\end{lemma}\n\nWe can express these with a more compact notation, $\\sone = \\Sone$, $\\stwo = \\Stwo$, representing the sum of single terms and the sum of pairs respectively.\n\nWe can evaluate these for our original equation and get $\\Sone = -2$, $\\Stwo = -3$, and $\\abg = 5$.\n\n\\subsection{Expanding The New Roots}\n\nWe want roots of $\\alpha + \\beta$, $\\beta + \\gamma$, and $\\gamma + \\alpha$, so we have the expression $(x - \\alpha - \\beta)(x - \\beta - \\gamma)(x - \\gamma - \\alpha)$. This can be expanded as such:\n\\begin{gather*}\n(x - \\alpha - \\beta)(x - \\beta - \\gamma)(x - \\gamma - \\alpha)\\\\[0.5em]\n= (x - \\alpha - \\beta)(x^2 - \\gamma x - \\alpha x - \\beta x + \\bg + \\ab - \\gamma x + \\gamma^2 + \\ag)\\\\[0.5em]\n= (x - \\alpha - \\beta)(x^2 - x\\Sone + \\Stwo - \\gamma x + \\gamma^2)\\\\[0.5em]\n= x^3 - x^2\\Sone + x\\Stwo - \\gamma x^2 + \\gamma^2 x - \\alpha x^2 + \\alpha x\\Sone - \\alpha \\Stwo + \\ag x - \\ag^2 - \\beta x^2 + \\beta x\\Sone - \\beta\\Stwo + \\bg x - \\bg^2\n\\end{gather*}\n\nAfter expanding the expression, we need to reorganise and simplify it.\n\\begin{gather*}\nx^3  - x^2\\Sone + \\alpha x\\Sone + \\beta x\\Sone+ x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\gamma x^2 - \\alpha x^2 - \\beta x^2 + \\gamma^2 x + \\ag x + \\bg x - \\ag^2 - \\bg^2\\\\[0.5em]\n= x^3  - x^2\\Sone + \\alpha x\\Sone + \\beta x\\Sone+ x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - x^2(\\sone) + \\gamma x(\\sone) - \\ag^2 - \\bg^2\\\\[0.5em]\n= x^3  - x^2\\Sone + \\alpha x\\Sone + \\beta x\\Sone + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - x^2\\Sone + \\gamma x\\Sone - \\ag^2 - \\bg^2\\\\[0.5em]\n= x^3 - 2x^2\\Sone + (\\sone)x\\Sone + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\ag^2 - \\bg^2\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\ag^2 - \\bg^2\n\\end{gather*}\n\nIt was at this point that I got stuck for about 15 minutes. If we had a $-\\abg$ term at the end, we could factor it out and do\n\\begin{gather*}\nx^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\ag^2 - \\bg^2 - \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\ag^2 + \\bg^2 + \\abg)\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\gamma(\\ag + \\bg + \\ab))\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\gamma\\Stwo)\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -\\Stwo(\\alpha + \\beta + \\gamma)\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\Sone\\Stwo\n\\end{gather*}\n\nWe can then evaluate this and get a definitive equation to answer the original question. But, how do we get that $- \\abg$ term at the end?\n\nI spent ages just staring at my book, trying to work out what I'd done wrong and where I'd dropped this term. After thoroughly checking and making sure that I'd expanded everything correctly, I decided to just add the term myself.\n\n\\subsection{Adding New Terms}\n\nWe know that adding and subtracting a constant from an expression doesn't change its value. So, for any expression $E$, and any constant $k$, $E + k - k = E$.\n\nSo, we can add the $-\\abg$ term and as long as we also add an extra $+\\abg$ term, the value of the expression won't actually change. And we know the value of $\\abg$ for our original equation, so we can evaluate it after the simplification.\n\nThus,\n\\begin{gather*}\nx^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\ag^2 - \\bg^2\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\alpha\\Stwo - \\beta\\Stwo - \\ag^2 - \\bg^2 - \\abg + \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\ag^2 + \\bg^2 + \\abg) + \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\gamma(\\ag + \\bg + \\ab)) + \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -1(\\alpha\\Stwo + \\beta\\Stwo + \\gamma\\Stwo) + \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo -\\Stwo(\\alpha + \\beta + \\gamma) + \\abg\\\\[0.5em]\n= x^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\Sone\\Stwo + \\abg\n\\end{gather*}\n\nWe can then evaluate this expression with the values for $\\Sone$, $\\Stwo$, and $\\abg$ that we obtained from the coefficients of our original equation.\n\\begin{gather*}\nx^3 - 2x^2\\Sone + x\\Sone^2 + x\\Stwo - \\Sone\\Stwo + \\abg\\\\[0.5em]\n= x^3 + 4x^2 + 4x - 3x - 6 + 5\\\\[0.5em]\n= x^3 + 4x^2 + x - 1\n\\end{gather*}\n\nTherefore, our final equation is $x^3 + 4x^2 + x - 1 = 0$. This is correct, as per the answers in the book.\n\n\\end{document}\n", "meta": {"hexsha": "16d2de47a68e5cf4c57c6c76bceab20d69b06b4d", "size": 6330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Questions/Polynomial_Root_Manipulation.tex", "max_stars_repo_name": "DoctorDalek1963/LaTeX", "max_stars_repo_head_hexsha": "e91a79837bff80f9d361b921acb870a9fcfc3e0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Questions/Polynomial_Root_Manipulation.tex", "max_issues_repo_name": "DoctorDalek1963/LaTeX", "max_issues_repo_head_hexsha": "e91a79837bff80f9d361b921acb870a9fcfc3e0b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Questions/Polynomial_Root_Manipulation.tex", "max_forks_repo_name": "DoctorDalek1963/LaTeX", "max_forks_repo_head_hexsha": "e91a79837bff80f9d361b921acb870a9fcfc3e0b", "max_forks_repo_licenses": ["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.0697674419, "max_line_length": 323, "alphanum_fraction": 0.644549763, "num_tokens": 2435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.6122085048788791}}
{"text": "\\section{Sturm-Liouville Theory}\r\n\\subsection{Review of Second-Order Linear ODEs}\r\nFor a general inhomogeneous ODE $\\mathcal Ly=f(x)$ where\r\n$$\\mathcal Ly=\\alpha(x)\\frac{\\mathrm d^2y}{\\mathrm dx^2}+\\beta(x)\\frac{\\mathrm dy}{\\mathrm dx}+\\gamma(x)y$$\r\nIn general, the homogeneous equation $\\mathcal Ly=0$ has two linearly independent solutions $y_1,y_2$.\r\nThe complementary function $y_c(x)=Ay_1+By_2$ for constants $A,B$ is then the general solution to $\\mathcal Ly=0$ by linearity.\\\\\r\nIf we can find a particular solution (aka particular integral) $y_p$ to $\\mathcal Ly=f$, then $y_p+y_c=y_p+Ay_1+By_2$ for $A,B$ constants is the general solution to $\\mathcal Ly=f$ again by linearity.\r\nTwo pieces of boundary data is then needed to determine the constants $A,B$.\\\\\r\nThere are several types of boundary conditions.\r\nWe sometimes get the Dirichlet condition of specifying the function's value at the endpoints, or the Neumann consitions of specifying the derivative's values at the endpoints.\r\nSometimes these two types of conditions are mixed.\\\\\r\nThe sort of conditions we often consider are homogeneous conditions, i.e. the function vanishes at the endpoints.\r\nThe reason of it is that it allows the superposition of solutions in a linear DE.\r\nWhat if we come across a nonhomogeneous condition?\r\nWe can use the complementary solution to cancel stuff out.\\\\\r\nSometimes, we specify initial data of the function and its derivative as boundary conditions.\\\\\r\nAnother matter of interest is the general eigenvalue problem.\r\nTo solve $\\mathcal Ly=f$ using eigenvalue decompositions like we did previously, we must first solve (subject to boundary conditions) the related eigenvalue problem\r\n$$\\mathcal Ly=\\alpha(x)\\frac{\\mathrm d^2y}{\\mathrm dx^2}+\\beta(x)\\frac{\\mathrm dy}{\\mathrm dx}+\\gamma(x)y=-\\lambda\\rho(x)y$$\r\nwhere $\\rho$ is nonegative.\r\nThis form often occurs after seperation of variables in a PDE.\r\n\\subsection{Self-Adjoint Operators}\r\n\\begin{definition}\r\n    For two functions $f,g:[a,b]\\to\\mathbb C$ we define their inner product to be\r\n    $$\\langle f,g\\rangle=\\int_a^bf^*(x)g(x)\\,\\mathrm dx$$\r\n\\end{definition}\r\nWe can guarantee to rewrite the original eigenvalue problem into the Sturm-Liouville form, i.e. $\\mathcal Ly=\\lambda wy$ where we are able to rewrite $\\mathcal Ly=-(py^\\prime)^\\prime+qy$ and $w$ is a nonnegative wavefunction.\r\n\\footnote{The reason why there is a wavefunction there is just for convenience.}\r\nHow to convert a second order linear ODE to this form?\r\nSimply multiply the diffential equation by an integrating factor $F$ that will be specified later and we can write\r\n$$\\frac{\\mathrm d}{\\mathrm dx}(F\\alpha y^\\prime)-F^\\prime\\alpha y^\\prime-F\\alpha^\\prime y^\\prime+F\\beta y^\\prime+F\\gamma y=-\\lambda F\\rho y$$\r\nSo to eiminate the $y^\\prime$ terms, we set\r\n$$F(x)=\\exp\\left(\\int\\frac{\\beta-\\alpha^\\prime}{\\alpha}\\,\\mathrm dx\\right)$$\r\nwhich reduced the equation to\r\n$$(F\\alpha y^\\prime)^\\prime+F\\gamma y=-\\lambda F\\rho y$$\r\nSetting $p=F\\alpha,q=F\\gamma$ and $w=F\\rho\\ge 0$.\r\n\\begin{example}\r\n    Consider the Hermite equation that appears in quantum mechanics\r\n    $$y^{\\prime\\prime}-2xy^\\prime+2ny=0$$\r\n    Then $\\alpha=1,\\beta=-2x,\\gamma=0,\\lambda\\rho=2n$, so the above procedure translates this to the Sturm-Liouville form\r\n    $$\\mathcal L=(-e^{-x^2}y^\\prime)^\\prime=2ne^{-x^2}y$$\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $\\mathcal L:C\\to C$ be an operator, where $C$ on a class of functions $[a,b]\\to\\mathbb C$ equipped with the inner product we defined previously.\r\n    This operator $\\mathcal L$ is self-adjoint if $\\langle y_1,\\mathcal Ly_2\\rangle=\\langle\\mathcal Ly_1,y_2\\rangle$ for any $y_1,y_2\\in C$.\r\n\\end{definition}\r\nIf we let $\\mathbb L$ be the operator in the Strum-Liouville form, then\r\n\\begin{align*}\r\n    \\langle y_1,\\mathcal Ly_2\\rangle-\\langle\\mathcal Ly_1,y_2\\rangle&=\\int_a^b[-y_1(py_2^\\prime)^\\prime+y_1qy_2+y_2(py_1^\\prime)^\\prime-y_2qy_1]\\,\\mathrm dx\\\\\r\n    &=\\int_a^b[-y_1(py_2^\\prime)^\\prime+y_2(py_1^\\prime)^\\prime]\\,\\mathrm dx\\\\\r\n    &=\\int_a^b[-(y_1(py_2^\\prime)^\\prime+y_1^\\prime py_2^\\prime)+(y_2(py_1^\\prime)^\\prime+y_2^\\prime py_1^\\prime)]\\,\\mathrm dx\\\\\r\n    &=\\int_a^b[-(py_1y_2^\\prime)^\\prime+(py_1^\\prime y_2)^\\prime]\\,\\mathrm dx\\\\\r\n    &=[-py_1y_2^\\prime+py_1^\\prime y_2]_a^b\r\n\\end{align*}\r\nSo for this operator to be self-adjoint, we need some good enough boundary conditions so that enough stuff vanishes.\r\nThis includes homogeneous boundary condition $y(a)=y(b)=0$ or $y^\\prime(a)=y^\\prime(b)=0$ or mixed $y+ky^\\prime=0$ etc..\r\nWe say a Sturm-Liouville problem is regular if the boundary conditions are homogeneous.\r\nPeriodic boundary conditions also work, where we can take $y(a)=y(b)$ and the derivatives are specified (or periodic) at the boundary.\r\nThere can also be singular points of this ODE, where $p(a)=p(b)=0$.\r\nWe can have combinations of above too.\r\n\\subsection{Properties of Self-Adjoint Operators}\r\n\\begin{definition}\r\n    The inner product of $y_1,y_2:[a,b]\\to\\mathbb C$ with respect to weight $w:[a,b]\\to\\mathbb R_{\\ge 0}$ is\r\n    $$\\langle f,g\\rangle_w=\\int_a^bwf^*g\\,\\mathrm dx=\\langle wf,g\\rangle=\\langle f,wg\\rangle$$\r\n\\end{definition}\r\nAnalogous to the finite dimensional case, we have\r\n\\begin{theorem}\\label{self-adjoint}\r\n    For a sufficiently nice self-adjoint operator $\\mathcal L$ on a sufficiently nice space of functions:\\\\\r\n    (a) Eigenvalues of $\\mathcal L$ are real.\\\\\r\n    (b) Eigenfunctions of it with different eigenvalues are orthogonal with respect to the weight $w$.\\\\\r\n    (c) We can take the eigenfunctions as a set of basis for the function space, just like Fourier series.\r\n\\end{theorem}\r\n\\begin{proof}[Proof of (a)]\r\n    1. If $\\mathcal Ly=\\lambda wy$, taking complex conjugate gives $\\mathcal Ly^*=\\lambda^*wy^*$.\r\n    Hence as $\\mathcal L$ is self-adjoint,\r\n    $$0=\\int_a^b(y^*\\mathcal Ly-y\\mathcal Ly^*)\\,\\mathrm dx=(\\lambda-\\lambda^*)\\int_a^bw|y|^2\\,\\mathrm dx$$\r\n    which means $\\lambda=\\lambda^*$, so $\\lambda$ is real.\r\n\\end{proof}\r\nIf $\\lambda$ is non-degenerate (simple), i.e. it has a one-dimensional eigenspace, then $y$ is guaranteed to be real.\r\nEven if it has dimension $2$ (not more because the ODE is second order), we can still find two real functions as basis of the eigenspace.\r\nAlso, by considering $u\\mathcal Lv-v\\mathcal Lu=(-p(uv^\\prime-u^\\prime v))^\\prime$, one can show that a regular Sturm-Liouville problem always has all eigenvalues simple.\r\n\\begin{proof}[Proof of (b)]\r\n    Suppose $\\mathcal Ly_m=\\lambda_mwy_m$ and $\\mathcal Ly_n=\\lambda_nwy_n$, then\r\n    $$0=\\int_a^by_n\\mathcal Ly_m-y_m\\mathcal Ly_n\\,\\mathrm dx=(\\lambda_m-\\lambda_n)\\int_a^bwy_ny_m\\,\\mathrm dx$$\r\n    But $\\lambda_m$ and $\\lambda_n$ are distinct.\r\n    The claim follows.\r\n\\end{proof}\r\nAs an aside, we do not really need the weight function in order to formulate Sturm-Liouville theory, since we can do the transformation $\\tilde{y}=\\sqrt{w}y$ and replace $\\mathcal Ly$ by $(1/\\sqrt{w})\\mathcal L(\\tilde{y}/\\sqrt{w})$.\r\nYet the analytic property is generally simpler if we keep $w$.\\\\\r\nWhat?\r\nHow about (c), you say?\r\nBold of you to assume we'll prove it.\r\nWe are just gonna take it (and several other properties we want it to have) as truth and do stuff with this idea.\r\n\\subsection{Eigenfunction Expansions}\r\nSo basically we just want to find an expansion\r\n$$f=\\sum_{n=1}^\\infty a_ny_n$$\r\nwhere $y_n$ is a set of eigenfunctions of some self-adjoint operator.\r\nTheorem \\ref{self-adjoint}(c) shows that we can do it.\r\nTo find the coefficients $a_n$, we can they use the orthogonality to get\r\n$$\\int_a^bwy_mf\\,\\mathrm dx=\\sum_{n=1}^\\infty a_n\\int_a^bwy_ny_m\\,\\mathrm dx=a_m\\int_a^bwy_n^2\\,\\mathrm dx$$\r\nSo\r\n$$a_n=\\left(\\int_a^bwy_nf\\,\\mathrm dx\\middle)\\right/\\left(\\int_a^bwy_n^2\\,\\mathrm dx\\right)$$\r\nIt's a common practice not to normalise the eigenfunctions as it is not really always clean.\r\nOf course, if we want, we can always write down\r\n$$Y_n=y_n\\left/\\sqrt{\\int_a^bwy_n^2\\,\\mathrm dx}\\right.$$\r\nSo we can get rid of the denominator in $a_n$ and the coefficients will have the expression\r\n$$A_n=\\int_a^bwy_nf\\,\\mathrm dx=a_n\\int_a^bwy_n^2\\,\\mathrm dx$$\r\nbut it isn't that useful and can cause some messiness.\r\n\\begin{example}\r\n    Recall the particular operator already in Sturm-Liouville form $\\mathcal Ly=y^{\\prime\\prime}$, then (with appropriate boundary conditions) we can easily get the eigenvalues $\\lambda_n=(n\\pi/L)^2$ and eigenfunctions being the trigonometrics.\r\n    This just reproduces the Fourier series.\r\n\\end{example}\r\n\\subsection{Completeness and Parseval's Identity}\r\nWe expand\r\n\\begin{align*}\r\n    0&=\\int_a^bw\\left( f(x)-\\sum_{n=1}^\\infty a_ny_n \\right)^2\\,\\mathrm dx\\\\\r\n    &=\\int_a^bw\\left( f^2-2f\\sum_{n=1}^\\infty a_ny_n+\\sum_{n=1}^\\infty a_n^2y_n^2 \\right)\\,\\mathrm dx\\\\\r\n    &=\\int_a^bwf^2\\,\\mathrm dx-\\sum_{n=1}^\\infty a_n^2\\int_a^bwy_n^2\\,\\mathrm dx\r\n\\end{align*}\r\nHence we have\r\n$$\\int_a^bwf^2\\,\\mathrm dx=\\sum_{n=1}^\\infty a_n^2\\int_a^bwy_n^2\\,\\mathrm dx=\\sum_{n=1}^\\infty A_n^2$$\r\nwhich Parseval's identity in this general case.\r\nEasily our previous Parseval's Theorem on Fourier series is a special case.\\\\\r\nIf some of the eigenfunctions are missing from the series, then this gives\r\n$$\\int_a^bwf^2\\,\\mathrm dx\\ge\\sum_{n=1}^\\infty A_n^2$$\r\nThis is known as Bessel's Inequality.\\\\\r\nConsider the partial sums $\\sum_{n\\le N}a_ny_n$, then we shall have $S_N\\to f$ as $N\\to\\infty$ where we would like the style of convergence to be\r\n$$\\epsilon_N=\\int_a^bw[f(x)-S_N(x)]^2\\,\\mathrm dx\\to 0,N\\to\\infty$$\r\nAn interesting question is that, while we know (maybe) the series converges as we want, if we truncate the sequence in some $N$, would the coefficients $\\{a_n\\}_{n\\le N}$ provide the best approxmation (with respect to the error defined in this way) of that particular partial sum, or a different set of partial coefficient will yield a better result?\r\nTo answer this, we evaluate\r\n$$\\frac{\\partial\\epsilon_N}{\\partial a_n}=-2\\int_a^bwy_n\\left( f-\\sum_{k=1}^Na_ky_k \\right)\\,\\mathrm dx=-2\\int_a^bwfy_n-a_nwy_n^2\\,\\mathrm dx$$\r\nwhich is zero when $a_n$ is of the expression we got earlier.\r\nWe can see it is indeed a minimum by observing that\r\n$$\\frac{\\partial^2\\epsilon_N}{\\partial a_n^2}=2\\int_a^bwy_n^2\\,\\mathrm dx\\ge 0$$\r\nThis answers our question.\r\n\\subsection{Legendre's Equation}\r\nTake the usual spherical polar coordinate\r\n$$\\begin{cases}\r\n    x=r\\sin\\theta\\cos\\phi\\\\\r\n    y=r\\sin\\theta\\sin\\phi\\\\\r\n    z=r\\cos\\theta\r\n\\end{cases}$$\r\nwhere Laplace's equation $\\nabla^2 u=0$ translates to\r\n$$\\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left( r^2\\frac{\\partial u}{\\partial r} \\right)+\\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left( \\sin\\theta\\frac{\\partial u}{\\partial\\theta} \\right)+\\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2u}{\\partial\\phi^2}=0$$\r\nSeperation of variables $u=R(r)\\Theta(\\theta)\\Phi(\\phi)$ then gives\r\n$$\\frac{1}{\\sin\\theta}(\\Theta^\\prime\\sin\\theta)^\\prime+\\left( K-\\frac{m^2}{\\sin^2\\theta} \\right)\\Theta=0$$\r\nwhere $K,m$ are constants which essentially makes it an eigenvalue problem.\r\nNow the transformation $x=\\cos\\theta\\in[-1,1]$ and renaming $\\Theta$ as $y$ then gives Legendre's Equation\r\n$$(1-x^2)y^{\\prime\\prime}-2xy^\\prime+\\lambda y=0$$\r\nwhere $\\lambda$ is a constant which is again intepreted as an eigenvalue.\r\nThis is already in Strum-Liouville form by taking $p=1-x^2,q=0,w=1$.\r\nNow $p=1-x^2$ vanishes at the boundary $\\pm 1$, so this equation has to be self-adjoint.\r\nWe assume that $y$ is bounded near the boundary.\\\\\r\nWe now seek a power series solution to the problem.\r\nIf we set\r\n$$y=\\sum_{n=0}^\\infty c_nx^n$$\r\nThen substitution gives\r\n$$(n+2)(n+1)c_{n+2}-n(n-1)c_n-2nc_n+\\lambda c_n=0\\implies c_{n+2}=\\frac{n(n+1)-\\lambda}{(n+1)(n+2)}c_n$$\r\nThe iteration steps by $2$, so we get two linearly independent solutions\r\n\\begin{align*}\r\n    y_{\\text{even}}&=c_0\\left( 1+\\frac{-\\lambda}{2!}x^2+\\frac{(6-\\lambda)(-\\lambda)}{4!}x^4+\\cdots \\right)\\\\\r\n    y_{\\text{odd}}&=c_1\\left( x+\\frac{2-\\lambda}{3!}x^3+\\cdots \\right)\r\n\\end{align*}\r\nNote that $c_{n+2}/c_n\\to 1$, so the both series has radius of convergence $1$ but they diverges at $x=\\pm 1$.\r\nHowever, this is not the end of the world!\r\nThese series may not be infinite.\r\nIf $\\lambda=l(l+1)$ for some $l\\in\\mathbb N$, then one of these two series will terminate and give a polynomial solution.\r\nThese polynomials are called Legendre polynomials $P_l(x)$ which are eigenfunctions of the Legendre equation.\r\nConventionally we normalise $P_l$ by requiring $P_l(1)=1$.\r\nOne can check that this restricts $P_l([-1,1])\\subset [-1,1]$ and $|P_l(-1)|=1$.\r\nBy calculation we have\r\n$$P_0(x)=1,P_1(x)=x,P_2(x)=\\frac{3x^2-1}{2},P_3(x)=\\frac{5x^3-3x}{2},\\ldots$$\r\nWe easily observe that $P_l$ has $l$ roots in $[-1,1]$, also $P_l$ is odd if $l$ is odd, and even when $l$ is even.\r\nBy orthogonality and some calculation,\r\n$$\\forall n\\neq m,\\int_{-1}^1P_nP_m\\,\\mathrm dx=0,\\int_{-1}^1P_n^2\\,\\mathrm dx=\\frac{2}{2n+1}$$\r\nThere are several other ways to characterise Legendre polynomails.\r\nOne can prove that we have\r\n$$P_n(x)=\\frac{1}{2^nn!}\\frac{\\mathrm d^n}{\\mathrm dx^n}(x^2-1)^n,\\sum_{n=0}^\\infty P_n(x)t^n=\\frac{1}{\\sqrt{1-2xt+t^2}}$$\r\nWe also have the recursions\r\n$$l(l+1)P_{l+1}(x)=(2l+1)xP_l(x)-lP_{l-1}(x),(2l+1)P_l(x)=\\frac{\\mathrm d}{\\mathrm dx}(P_{l+1}(x)-P_{l-1}(x))$$\r\nIf we take these $P_l$ as a set of eigenfunctions, then any well-behaved $f$ on $[-1,1]$ can be expressed as\r\n$$f(x)=\\sum_{l=0}^\\infty a_lP_l(x),a_l=\\frac{2l+1}{2}\\int_{-1}^1f(x)P_l(x)\\,\\mathrm dx$$\r\n\\begin{example}\r\n    We can verify that $f(x)=(15x^2-3)/2=P_0(x)+5P_2(x)$.\r\n\\end{example}\r\n\\begin{example}\r\n    The odd equare wave with $f([0,1))=\\{1\\}$ has the expansion\r\n    $$\\sum_{m=1}^\\infty (P_{2m}(0)-P_{2m+2}(0))P_{2m+1}(x)$$\r\n\\end{example}\r\n\\subsection{Inhomogeneous ODEs}\r\nConsider the ODE $\\mathcal Ly=f=wF$ (with homogeneous boundary conditions so that $\\mathcal L$ is self-adjoint) where $w\\ge 0$ is our wavefunction.\r\nGiven eigenfunctions $\\{y_n\\}$ satisfying $\\mathcal Ly_n=\\lambda_nwy_n$ for eigenvalues $\\{\\lambda_n\\}$.\r\nWe now try to find a solution in the form $y=\\sum_nc_ny_n$.\r\nTo do this, we expand $F=\\sum_na_ny_n$ where\r\n$$a_n=\\left( \\int_a^bwFy_n\\,\\mathrm dx\\middle) \\right/\\left( \\int_a^bwy_n^2\\,\\mathrm dx \\right)$$\r\nthen\r\n$$w\\sum_na_ny_n=wF=\\mathcal Ly=\\mathcal L\\sum_nc_ny_n=\\sum_nc_n\\mathcal Ly=w\\sum_nc_n\\lambda_ny_n$$\r\nSo take\r\n$$y=\\sum_n\\frac{a_n}{\\lambda_n}y_n$$\r\ngives a particular solution, assuming everything is well-defined and converges nicely enough.\\\\\r\nAn aside:\r\nThe driving force $F$ sometimes induces a linear response term $\\tilde\\lambda wy$, so the solution is $\\mathcal Ly-\\tilde{\\lambda}wy=f$.\r\nThen our particular solution can be\r\n$$y=\\sum_{\\lambda_n\\neq\\tilde{\\lambda}}\\frac{a_n}{\\lambda_n-\\tilde\\lambda}y_n$$\r\nNow back to theme.\r\nIf we expand the expression of $a_n$, we can get\r\n\\begin{align*}\r\n    y(x)&=\\sum_{n=1}^\\infty\\frac{a_n}{\\lambda_n}y_n(x)\\\\\r\n    &=\\sum_{n=1}^\\infty\\frac{y_n(x)}{\\lambda_nN_n}\\int_a^bw(\\xi)F(\\xi)y_n(\\xi)\\,\\mathrm d\\xi,N_n=\\int_a^bwy_n^2\\,\\mathrm dx\\\\\r\n    &=\\int_a^b\\left( \\sum_{n=1}^\\infty\\frac{y_n(x)y_n(\\xi)}{\\lambda_nN_n} \\right)w(\\xi)F(\\xi)\\,\\mathrm d\\xi\\\\\r\n    &=\\int_a^bG(x,\\xi)f(\\xi)\\,\\mathrm d\\xi,G(x,\\xi)=\\sum_{n=1}^\\infty\\frac{y_n(x)y_n(\\xi)}{\\lambda_nN_n}\r\n\\end{align*}\r\nThis $G(x,\\xi)$ is called the Green's function of this particular eigenvalue problem of that self-adjint operator.\r\nWorth noting that $G$ does not depend on the forcing term $f$.\r\nThe Green's function also induces\r\n$$\\mathcal L^-(\\phi)=\\int_a^bG(x,\\xi)\\phi(\\xi)\\,\\mathrm d\\xi$$\r\nwhich can be taken as kind of an inverse operator to $\\mathcal L$ since $\\mathcal L(\\mathcal L^-(f))=f$.", "meta": {"hexsha": "fd3d938fd70198fb810216ea4d646656f1a4ec79", "size": 15565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/sturm.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": "2/sturm.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": "2/sturm.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": 71.7281105991, "max_line_length": 351, "alphanum_fraction": 0.7048506264, "num_tokens": 5189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.6122084986619898}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Comparing Inverse Problems and Solutions}\\label{sec:compare}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% The Bayesian framework poses a different question and seeks a different answer than the Data-Consistent one.\nThe objective of the Bayesian approach is to determine a single ``true'' parameter that explains all of the observed data \\citep{Smith, Concrete, Complete, Stuart10, Tarantola_book}.\nThe philosophical underpinnings of Bayesian inference is akin to asking the following:\n\n\\begin{center}\n  \\emph{How does one incorporate collected data to shift prior beliefs about specific parameter values?}\n\\end{center}\n\n% The motivations of Bayesian inference are distinct from the Data-Consistent framework, where we seek a pull-back measure: a description of the uncertainty set that explains the variation in the observations under a given description of error.\nHowever, the Data-Consistent approach reflects the goal of constructing a distribution (or probability measure), which is akin to asking:\n\n\\begin{center}\n  \\emph{How does one update initial beliefs in such a way that the modified predictions match the description of uncertainty in observed data?}\n\\end{center}\n\nWe now develop a typical Bayesian inverse problem following the framework described in \\cite{Stuart10, Smith}, in order to make a formal comparison to the Data-Consistent SIP.\n\n\\subsubsection{The Bayesian Inverse Problem}\nLet $d$ denote the ``noisy'' data obtained on $Q(\\paramref)$, which is often represented as\n\\begin{equation*}\n\td = Q(\\paramref) + \\xi,\n\\end{equation*}\nwhere $\\xi$ is a random variable used to model the measurement error that is often assumed to follow a Gaussian distribution.\nThen, the data-likelihood function, often written as a conditional density, $L_\\dspace(\\q \\, |\\, \\param)$, is formed.\nThis describes the differences in relative likelihoods that the data could have been generated from a particular $\\param$.\nIdeally, the largest values of $L_\\dspace(\\q \\, | \\, \\param)$ occur whenever $\\param$ is a close approximation of the true parameter $\\paramref$.\nThe data-likelihood function is distinct from the observed density used in the data-consistent framework.\n\nThe next step in constructing a Bayesian inverse problem is the specification of a prior density denoted by $\\pi_\\text{prior}(\\param)$.\nThe prior describes the different relative likelihoods assumed for the true parameter before data are collected.\nThis is also distinct from the role of the {\\em initial} density used in the data-consistent framework.\n% We choose them to represent the set of feasible parameters, and rely on Monte Carlo sampling for both approaches\\footnote{Priors in Bayesian inference are sometimes chosen for reasons related to Markov-Chain Monte Carlo algorithms in order to ensure their balancing of investigation and exploration, or convergence [TK - cite someone]}.\n\nThe posterior density (i.e., the formal solution to the Bayesian inverse problem) is given by a conditional density, denoted by $\\pi_\\text{post}(\\param\\, | \\, d)$, proportional to the product of the prior and data-likelihood function \\citep{Walpole, Berger, Complete, Smith}.\nIn other words,\n\\begin{equation*}\n\t\\posterior(\\param\\, | \\, \\q) \\propto \\prior(\\param)L_\\dspace(\\q\\, | \\, \\param)\n\\end{equation*}\nThis form of the density follows from Bayes' rule (not from the Disintegration Theorem as with the updated density).\nThe posterior can be interrogated to assess the difference in relative likelihoods of a fixed parameter given the observed data.\nSubsequently, the posterior is often used to produce a ``best'' estimate of the true parameter.\nFor example, the maximum a posteriori (MAP) point is the parameter that maximizes the posterior density.\n\nUnlike the updated density, the posterior is often interrogated indirectly without knowledge of the normalizing constant $C$ required to represent it as a density.\nIn other words, the posterior is a density of the form\n\n\\begin{equation}\\label{eq:sb_post}\n    \\posterior\\lam := \\prior\\lam \\frac{L_\\dspace (\\q | \\param)}{ C },\n\\end{equation}\n\n\\noindent where we emphasize the use of $\\posterior$ to distinguish the \\emph{posterior} from the updated density $\\updated$ in \\eqref{eq:updated-pdf}.\nHere, the denominator $C$ (known as the \\emph{evidence} \\cite{Smith}), ensures the posterior density integrates to one, and is given by\n\\[\nC = \\int_\\pspace \\prior\\lam L_\\dspace(\\q | \\param) \\, d\\param.\n\\]\n\nNote that there are no constraints or requirements that likelihood function be a density.\nIn fact, $L_\\dspace$ need not even be in $L^1(\\pspace)$ since it is actually only the product $\\prior(\\param) L_\\dspace (\\q | \\param)$ that is required to be in $L^1(\\pspace)$ to form a posterior.\nIn other words, $L_\\dspace (\\q | \\param)$ and $\\observed(\\qlam)$ can model completely different things with respect to uncertainty in the data.\nAs stated above, $L_\\dspace (\\q | \\param)$ is used to assess the relative likelihood that a single parameter $\\param\\in\\pspace$ explains all of the observed data, whereas $\\observed(\\qlam)$ describes the relative likelihood of a predicted datum associated with $\\param\\in\\pspace$.\nIn the Bayesian framework, there is a different notion of consistency of solutions, referring to certain asymptotic properties of $\\posterior$ in the limit of infinite data \\citep{Barron, Silverman, starktenorio}.\n\n\n\n%%%%%%%%%\n\n\\subsection{Comparison of Data-Consistent and Bayesian Inversion}\\label{sec:bayesian}\n\nWe summarize the posterior and updated densities side-by-side in Table~\\ref{tab:dens_comparisons} and comment on a few notable aspects not mentioned above.\nObserve for the posterior density that the data-likelihood function appears in both the numerator and denominator.\nIn particular, the data-likelihood function informs the {normalizing constant}, commonly referred to as the evidence term, in the denominator.\nThis is in contrast to the denominator of the updated density, which is given by the predicted density, which is in general not a constant, and can be constructed independently of $\\observed$.\n\n\\begin{table}[htbp]\n\\centering\n\\begin{tabular}{|c|c|}\n\\hline\n & \\\\\n$\\displaystyle \\updated(\\param) = \\initial(\\param) \\frac{\\observed(\\q)}{\\predicted(\\q)}\n$\n&\n$\n\t\\displaystyle \\pi_{\\text{post}}(\\param\\,|\\,\\q) = \\frac{\\prior(\\param)L_\\dspace(\\q \\,|\\,\\param)}{\\int_{\\Lambda} L_\\dspace(\\q \\, |\\, \\param)  \\prior(\\param) \\, d\\pmeas}\n$\n \\\\ & \\\\ \\hline\n\\end{tabular}\n\\caption{Updated density solving the SIP (left) and posterior density solving the Bayesian inverse problem (right).}\n\t\t\\label{tab:dens_comparisons}\n\\end{table}\n\nA practical implication of this difference is that the updated density only alters the structure of the initial density in what we refer to as the ``data-informed'' parameter directions.\nSpecifically, for a fixed $\\q\\in\\dspace$, let $C_\\q := \\set{\\param\\in\\pspace\\, : \\, \\qlam=\\q}$, i.e., $C_\\q$ is a ``contour'' in parameter space.\nThen, for any $\\param\\in C_\\q$, we immediately have $\\updated(\\param)=r(\\q)\\initial(\\param)$ where $r(\\q)$ is a fixed constant of proportionality for all $\\param\\in C_\\q$.\n%Subsequently, using the Disintegration theorem on both the initial and updated densities produces exactly the same family of conditional densities on the contours in parameter space.\nBy contrast, while the posterior does not have to agree with the prior in any direction in parameter space, the prior does impact the structure of the posterior in all directions.\n\nThe previous paragraph is not\\---and should not be interpreted as\\---a criticism of the Bayesian inverse framework.\nIt is simply meant to highlight that the data-consistent and Bayesian frameworks formulate and solve inverse UQ problems from different perspectives and with different (although at times seemingly compatible) assumptions.\nConsequently, the solutions for an inverse problem formulated under either framework may differ significantly.\nAs the example (adopted from \\cite{BJW18a, BJW18b}) below demonstrates, this is true even if we arbitrarily force the inverse problems to appear as similar as possible.\n\n\\FloatBarrier\n", "meta": {"hexsha": "cdc5c052f4b7e6d4537035bccfad5d3ef1fa0ec2", "size": 8319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro/comparison.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": "intro/comparison.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": "intro/comparison.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": 76.3211009174, "max_line_length": 338, "alphanum_fraction": 0.7468445727, "num_tokens": 1908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6121611792217904}}
{"text": "\\newpage\n\\chapter[Cauchy's Integral Formula]{Cauchy's Integral Formula and its Applications}\n\\section{Cauchy's Integral Formula}\nWe have seen so far that if $f:\\mathcal{R} \\to \\C$ is holomorphic on a starlit region $\\mathcal{R}$ then\n\\[\n\\int_{\\mathcal{C}} f = 0\n\\]\nfor any closed contour $\\mathcal{C}$ in $\\mathcal{R}$. What happens when $\\mathcal{R}$ is not starlit?  \n\nIt may happen that while $\\mathcal{R}$ itself is not starlit, the contour $\\mathcal{C}$ is contained in a starlit subregion $\\mathcal{S}$ of $\\mathcal{R}$.\n\n\\begin{figure}[H]\n\\begin{tabular}{ccc}\n\\includegraphics[scale=1]{ch5_notsc3} & \\quad \\includegraphics[scale=1]{ch5_notsc1} \\quad & \\includegraphics[scale=1]{ch5_notsc2}\n\\end{tabular}\n\\caption{The region $\\mathcal{R}$ consists of the complex plane with a disc centred at the origin removed.  This region is not starlit, but there are starlit subregions of $\\mathcal{R}$ containing the contour $\\mathcal{C}$.}\n\\end{figure}\n\nThus if $f$ is holomorphic on $\\mathcal{R}$, then $f$ is also holomorphic on $\\mathcal{S}$ and so Cauchy's Theorem for Starlit Regions (Theorem~\\ref{t:cauchyst}) gives\n\\[\n\\int_{\\mathcal{C}} f=0.\n\\]\n\nIf $\\mathcal{R}$ is not simply connected, then it may not be possible to do this; in particular, when $\\mathcal{C}$ encloses a point $z_0$ at which $f$ is not holomorphic.  For example, suppose $f:\\C \\backslash \\set{0} \\to \\C$ is defined by $f(z) = \\dfrac{1}{z}$, and $\\mathcal{C}$ is the contour shown in Figure~\\ref{f:notsc}.  \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{ch5_notsc}\n\\caption{A contour $\\mathcal{C}$ contained in the non-simply connected region $\\C\\backslash \\set{0}$.}\n\\label{f:notsc}\n\\end{figure}\n\nHere $\\C \\backslash \\set{0}$ is not starlit, and there is no starlit subregion of $\\C \\backslash \\set{0}$ containing $\\mathcal{C}$.  Nonetheless, in certain circumstances, it is at least possible to replace $\\mathcal{C}$ something easier in order to calculate the integral.\n\n\\begin{definition}\nA contour $\\mathcal{C}$, that is not closed, is said to be \\emph{simple} if $\\mathcal{C}$ does not intersect itself.  A \\emph{simple closed contour $\\mathcal{C}$} is one that does not intersect itself except that its start point is the same as its end point.\n\\end{definition}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.3]{ch5_simple_full}\n\\caption{Simple contours.}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.3]{ch5_nonsimple_full}\n\\caption{Non-simple contours.  Note that the closed, non-simple contour on the right has no obvious orientation - it is neither clockwise nor anticlockwise.}\n\\end{figure}\n\n\nFor a simple closed contour $\\mathcal{C}$, when we speak of $\\mathcal{C}$ being clockwise or anticlockwise, we mean relative to the points enclosed by $\\mathcal{C}$.  In other words, a contour $\\mathcal{C}$ is anticlockwise if, as we travel along $\\mathcal{C}$, the region enclosed by $\\mathcal{C}$ always lies to our left.  Again, we shall avoid giving a precise definition, and treat this notion informally.\n\n\n\n\n\nThe following Theorem shows us how in some cases, a potentially complicated contour integral may be reduced to an easier one.\n\\begin{theorem}[Shrinking Contour Theorem/Deformation Theorem]\n\\label{t:sc}\nLet $\\mathcal{R}$ be a simply connected region, $\\mathcal{C}$ an anticlockwise, simple closed contour in $\\mathcal{R}$, $z_0$ a point enclosed by $\\mathcal{C}$ and $g$ a function which is holomorphic on $\\mathcal{R} \\backslash \\set{z_0}$.  Then\n\\[\n\\int_{\\mathcal{C}} g = \\int_{\\mathcal{C}_r} g\n\\]\nwhere $\\mathcal{C}_r$ is an anticlockwise circular contour with centre $z_0$ and radius $r$, which is small enough so that $\\mathcal{C}_r$ is contained in $\\mathcal{R}$.\n\\end{theorem}\n\\begin{center}\n\\includegraphics[scale=0.75]{ch5_scnotstarlit4}\n\\end{center}\n{\\bf Sketch of Proof}\n\nLet us first consider the case where $\\mathcal{R} = \\C$ as shown:\n\\begin{center}\n\\altgraphics[scale=1]{ch5_shrinking_cont_full}{ch5_shrinking_cont}\n\\end{center}\n\\begin{blankbox}\nDraw a straight line through $z_0$ to get two starlit subregions $\\mathcal{R}_1$ and $\\mathcal{R}_2$, with $g$ holomorphic on both $\\mathcal{R}_1$ and $\\mathcal{R}_2$. Join $\\mathcal{C}$ and $\\mathcal{C}_r$ along this straight line to get two new (simple, closed, anticlockwise) contours $\\mathcal{C}_1$ and $\\mathcal{C}_2$ contained in $\\mathcal{R}_1$ and $\\mathcal{R}_2$ respectively.\n\nBy Cauchy's Theorem for Starlit Regions,\n\\[\n\\int_{\\mathcal{C}_1} g = \\int_{\\mathcal{C}_2} g = 0.\n\\]\nMoreover,\n\\[\n0= \\int_{\\mathcal{C}_1} f + \\int_{\\mathcal{C}_2} f = \\int_{\\mathcal{C}} f - \\int_{\\mathcal{C}_r} f,\n\\]\nas the integrals along the straight line segments cancel, leaving us with\n\\begin{itemize}\n\\item an anticlockwise copy of $\\mathcal{C}$, and\n\\item a clockwise copy of $\\mathcal{C}_r$, i.e., the reverse of $\\mathcal{C}_r$.\n\\end{itemize}\nThus\n\\[\n\\int_{\\mathcal{C}} f = \\int_{\\mathcal{C}_r} f.\n\\]\n\\end{blankbox}\n\nFor more general simply connected regions $\\mathcal{R}$, we may need to partition $\\mathcal{R}$ into starlit subregions $\\mathcal{R}_1,\\mathcal{R}_2,\\ldots, \\mathcal{R}_n$, numbered so that $z_0 \\in \\mathcal{R}_n$. By joining points on $\\mathcal{C}$, we get anticlockwise closed contours $\\mathcal{C}^{(1)},\\mathcal{C}^{(2)},\\ldots,\\mathcal{C}^{(n)}$, with $\\mathcal{C}^{(j)}$ contained in $\\mathcal{R}_j$ for each $j$.  Label the regions $\\mathcal{R}_j$ so that $z_0 \\in \\mathcal{R}_n$. \n\n\\begin{center}\n\\altgraphics[scale=0.3]{ch5_deformation1_full}{ch5_deformation2}\n\\end{center}\n\n\\begin{blankbox}\n%\\vspace*{12cm}\nAs before,\n\\[\n\\int_{\\mathcal{C}} g = \\int_{\\mathcal{C}^{(1)}} g + \\int_{\\mathcal{C}^{(2)}} g + \\ldots + \\int_{\\mathcal{C}^{(n)}} g,\n\\]\nas the integrals along the connecting edges cancel in pairs.\n\\begin{comment}\n\\leftimage{\n\\includegraphics[scale=0.3]{ch5_deformation2_full}\n}\n{\nThe edge where $\\mathcal{C}^{(j)}$ and $\\mathcal{C}^{(j+1)}$ intersect is traversed in one direction along $\\mathcal{C}^{(j)}$ and in the opposite direction along $\\mathcal{C}^{(j+1)}$.  Thus when we compute the sum of the integral of $g$ along $\\mathcal{C}^{(j)}$ and along $\\mathcal{C}^{(j+1)}$, the contributions made by this connecting edge cancel.\n}\n\\end{comment}\n\nFor each $j \\neq n$, $g$ is holomorphic on $\\mathcal{R}_j$, and $\\mathcal{C}^{(j)}$ is a closed contour contained in the starlit region $\\mathcal{R}_j$.  Thus by Cauchy's Theorem for Starlit regions, we have\n\\[\n\\int_{\\mathcal{C}^{(j)}} g = 0\\quad \\text{ for } j=1,2,\\ldots,n-1.\n\\]\n\nCombining these two observations it follows that\n\\[\n\\int_{\\mathcal{C}} g = \\int_{\\mathcal{C}^{(n)}} g,\n\\]\nand thus we need to show that\n\\[\n\\int_{\\mathcal{C}^{(n)}}g = \\int_{\\mathcal{C}_r} g.\n\\]\nThe proof of this is almost identical to the case $\\mathcal{R}=\\C$.\n\\end{blankbox}\n\\begin{comment}\n\nWhile $\\mathcal{R}_n$ is starlit, $\\mathcal{R}_n \\backslash \\set{z_0}$ is not.  Thus we split $\\mathcal{R}_n \\backslash \\set{z_0}$ into two starlit subregions, and construct contours $S_1$ and $S_2$ by connecting $\\mathcal{C}^{(n)}$ and $\\mathcal{C}_r$ as shown.\n\\begin{center}\n\\includegraphics[scale=0.25]{ch5_shrinking}\n\\end{center}\n\n\nBy Cauchy's Theorem for Starlit Regions, we again have\n\\[\n\\int_{S_1} g = \\int_{S_2} g = 0.\n\\]\n\nNotice that if we join $S_1$ and $S_2$ we get a contour consisting of\n\\begin{itemize}\n\\item An anticlockwise copy of the circular contour $\\mathcal{C}_r$, \n\\item A clockwise copy of $\\mathcal{C}^{(n)}$, i.e. the reverse of $\\mathcal{C}^{(n)}$, and\n\\item two copies of each of the new edges connecting $\\mathcal{C}^{(n)}$ and $\\mathcal{C}_r$, one in each direction.\n\\end{itemize}\nThus we get\n\\[\n\\int_{S_1} g + \\int_{S_2} g = \\int_{\\mathcal{C}_r} g - \\int_{\\mathcal{C}^{(n)}} g\n\\]\nas the integrals along the new edges connecting $\\mathcal{C}^{(n)}$ and $\\mathcal{C}_r$ cancel, and we are left with $\\mathcal{C}_r$ and the reverse of $\\mathcal{C}^{(n)}$.\n  \nHence\n\\[\n0 = \\int_{S_1} g + \\int_{S_2} g = \\int_{\\mathcal{C}_r} g - \\int_{\\mathcal{C}^{(n)}} g\n\\]\nand so\n\\[\n\\int_{\\mathcal{C}_r} g = \\int_{\\mathcal{C}^{(n)}} g = \\int_{\\mathcal{C}} g.\n\\]\n\\blanksoff\n%\\vspace*{9cm}\n\\end{comment}\n\n\\qed\n\nA very similar argument is used to prove Cauchy's Theorem for Simply Connected Regions.\n\n\\begin{theorem}[Cauchy's Theorem for Simply Connected Regions]\nLet $f$ be a function that is holomorphic in a simply connected region $\\mathcal{R}$, and let $\\mathcal{C}$ be a closed contour in $\\mathcal{R}$. Then\n\\[\n\\int_{\\mathcal{C}} f = 0.\n\\]\n\\end{theorem}\n{\\bf Proof}\nThis is identical to the Proof of Theorem~\\ref{t:sc}, except that now, $f$ is holomorphic on the starlit region $\\mathcal{R}_n$, so that\n\\[\n\\int_{\\mathcal{C}} f = \\int_{\\mathcal{C}_r} f =0.\n\\]\n\\qed\n\n\n%\\vspace*{7cm}\n\n\n\n\n\n\\begin{theorem}[Cauchy's Integral Formula]\n\\label{t:cauchyformula}\nLet $\\mathcal{R}$ be a simply connected region, $\\mathcal{C}$ an anticlockwise simple closed contour in $\\mathcal{R}$, $z_0$ a point enclosed by $\\mathcal{C}$ and $f$ a function that is holomorphic on $\\mathcal{R}$.  Then\n\\[\n\\int_{\\mathcal{C}} \\frac{f(z)}{z-z_0} \\ dz = 2 \\pi i f( z_0).\n\\]\n\\end{theorem}\n\\begin{proof}\nDefine a new function $g$ by the formula\n\\[\ng(z) = \\frac{f(z)}{z-z_0}\n\\]\nso that $g$ is holomorphic on $\\mathcal{R} \\backslash \\set{z_0}$, i.e., where $f$ is holomorphic and $z-z_0 \\neq 0$.  Thus we are trying to show that\n\\[\n\\int_{\\mathcal{C}} g = 2\\pi i f(z_0).\n\\]\nUsing the Shrinking Contour Theorem~\\ref{t:sc}, we may replace $\\mathcal{C}$ with an anticlockwise circular contour $\\mathcal{C}_r$ with centre $z_0$ and radius $r$ to get\n\\[\n\\int_{\\mathcal{C}} g = \\int_{\\mathcal{C}_r} g\n\\]\nwhenever $r>0$ is small enough so that $\\mathcal{C}_r$ is contained in $\\mathcal{R}$.  \n\nIf we define $I$ by\n\\[\nI = \\left(\\int_{\\mathcal{C}_r} \\frac{f(z)}{z-z_0}\\ dz \\right) - 2 \\pi i f(z_0),\n\\]\nthen we want to show that $I=0$.  To do this, we will write $I$ as a single integral along $\\mathcal{C}_r$ and use the Estimation Lemma (together with the fact that our definition of $I$ does not depend on our choice of sufficiently small $r$).\n\nParametrising $\\mathcal{C}_r$ with $\\gamma:[0,2\\pi] \\to \\C$, $\\gamma(t) = z_0 + r \\exp (it)$, we have\n\\[\n\\int_{\\mathcal{C}_r} \\frac{1}{z-z_0}\\ dz = \\int_0^{2\\pi} \\frac{1}{z_0+r\\exp(it)-z_0} \\cdot i r\\exp (it) \\ dt = \\int_0^{2\\pi} i \\ dt = 2 \\pi i\n\\]\n(which we saw in Exercise Sheet 2). Therefore, since $f(z_0)$ is a constant, we get\n\\[\n2\\pi i f(z_0) = \\int_{\\mathcal{C}_r} \\frac{f(z_0)}{z-z_0}\\ dz.\n\\]\nThus\n\\begin{align*}\nI &= \\int_{\\mathcal{C}_r} \\frac{f(z)}{z-z_0}\\ dz - \\int_{\\mathcal{C}_r} \\frac{f(z_0)}{z-z_0}\\ dz \\\\\n& = \\int_{\\mathcal{C}_r} \\frac{f(z)-f(z_0)}{z-z_0}\\ dz.\n\\end{align*}\nTo apply the Estimation Lemma, we need to find an upper bound for\n\\[\n\\abs{ \\frac{f(z)-f(z_0)}{z-z_0} } \\quad \\text{ where } z \\in \\mathcal{C}_r.\n\\]\nSince $\\mathcal{C}_r$ is a circle with centre $z_0$ and radius $r$, it is clear that $\\abs{z-z_0} = r$ for all $z \\in \\mathcal{C}_r$, and thus we look at $\\abs{f(z)-f(z_0)}$.\n\nSince $f$ is holomorphic on $\\mathcal{R}$, it is continuous on $\\mathcal{R}$ and in particular, continuous at $z_0$.  Thus given any $\\epsilon>0$ there exists $\\delta>0$ such that\n\\[\n0 < \\abs{z-z_0} < \\delta \\Rightarrow \\abs{ f(z)-f(z_0) } < \\epsilon.\n\\]\nIn other words, given any $\\epsilon >0$, if we choose $r$ so that $0<r < \\delta$, we have\n\\[\nz \\in \\mathcal{C}_r \\Rightarrow \\abs{z-z_0} = r < \\delta \\Rightarrow \\abs{f(z)-f(z_0)} < \\epsilon.\n\\]\nFor any such $r$ we thus have\n\\[\nz \\in \\mathcal{C}_r \\Rightarrow \\abs{\\frac{f(z)-f(z_0)}{z-z_0}} = \\frac{\\abs{f(z)-f(z_0)}}{\\abs{z-z_0}} < \\frac{\\epsilon}{r}.\n\\]\nBy the Estimation Lemma (using the fact that $\\ell ( \\mathcal{C}_r ) = 2 \\pi r$), we see that\n\\[\n\\abs{\\int_{\\mathcal{C}_r} \\frac{f(z)-f(z_0)}{z-z_0}\\ dz} \\leq \\frac{\\epsilon}{r} 2 \\pi r = 2\\pi \\epsilon.\n\\]\nHowever, since the definition of $I$ does not depend on our choice of (small) $r$, it follows that\n\\[\n\\abs{I} < 2 \\pi \\epsilon\n\\]\nfor all $\\epsilon>0$.  Hence $\\abs{I}=0$ which implies $I=0$, or in other words,\n\\[\n\\int_{\\mathcal{C}} \\frac{f(z)}{z-z_0}\\ dz = 2 \\pi i f(z_0).\n\\]\n\\end{proof}\n\n\\begin{note}\nCauchy's Integral Formula, and its proof, can be easily remembered using the following approximation: if $r$ is small and $z \\in \\mathcal{C}_r$ then $f(z) \\approx f(z_0)$, hence\n\\[\n\\int_{\\mathcal{C}_r} \\frac{f(z)}{z-z_0}\\ dz \\approx \\int_{\\mathcal{C}_r} \\frac{f(z_0)}{z-z_0}\\ dz = f(z_0) \\int_{\\mathcal{C}_r} \\frac{1}{z-z_0}\\ dz = f(z_0) (2\\pi i).\n\\]\n\\end{note}\nSuppose we wish to evaluate the integral $\\int_{\\mathcal{C}} g$ of a continuous function $g$ along some closed contour $\\mathcal{C}$.  If we can find some point $z_0$ enclosed by $\\mathcal{C}$ and a function $f$ holomorphic on $\\mathcal{R}$ with \n\\[\ng(z) = \\frac{f(z)}{z-z_0} \\quad \\text{ for all }z \\in \\mathcal{C}\n\\]\nthen our integral may be evaluated using\n\\[\n\\int_{\\mathcal{C}} g = \\int_{\\mathcal{C}} \\frac{f(z)}{z-z_0}\\ dz =  2\\pi i f(z_0).\n\\]\nIn other words, it is enough to know the value of $f(z_0)$ in order to calculate $\\int_{\\mathcal{C}}g$.\n\\begin{example}\nEvaluate the integral\n\\[\n\\int_{\\mathcal{C}} \\frac{\\Log (z)}{z^2+9}\n\\]\nwhere $\\Log$ is the Principal Logarithm function and $\\mathcal{C}$ is the anticlockwise circle with centre $4i$ and radius $3$.\n\\end{example}\n%\\vspace*{5cm}\n\\begin{solution}\nWe know that $\\Log$ is holomorphic on $\\C_{\\pi}$, and moreover, we have\n\\[\nz^2+9 = (z+3i)(z-3i).\n\\]\nIf we write\n\\[\n\\frac{\\Log (z)}{z^2+9} = \\frac{\\Log (z)}{(z+3i)(z-3i)} = \\frac{f(z)}{z-z_0}\n\\]\nwhere $z_0=3i$ and\n\\[\nf(z) = \\frac{\\Log (z)}{z+3i}\n\\]\nthen $z_0$ is enclosed by $\\mathcal{C}$ and $f$ is holomorphic on $\\C_{\\pi} \\backslash \\set{-3i}$, which is a region containing $\\mathcal{C}$.  However, it is clear that the region $\\C_{\\pi} \\backslash \\set{-3i}$ is not simply connected, so the hypotheses of Cauchy's Integral Formula are not fully satisfied.  We deal with this by replacing $\\C_{\\pi} \\backslash \\set{-3i}$ with a subregion that is simply connected.\n\n\\leftimage{\n\\altgraphics[scale=1]{ch5_cpi5}{ch5_cpi4}\n}{\nIndeed, if we consider the region $\\mathcal{R} = \\set{ z \\in \\C: \\Im (z)>0}$, then we see that\n\\begin{itemize}\n\\item $\\mathcal{R}$ is simply connected,\n\\item $f$ is holomorphic on $\\mathcal{R}$, and\n\\item $\\mathcal{C}$ is a simple, closed anticlockwise contour that is contained in $\\mathcal{R}$ and encloses the point $z_0=3i$.\n\\end{itemize}\n}\n\n\n\n\nTherefore, we can apply Cauchy's Integral Formula, which gives\n\\begin{align*}\n\\int_{\\mathcal{C}} \\frac{\\Log(z)}{z^2+9}\\ dz &= \\int_{\\mathcal{C}} \\frac{f(z)}{z-z_0}\\ dz \\\\\n& = 2 \\pi i f(z_0) \\\\\n& = 2 \\pi i \\left( \\frac{\\Log(3i)}{3i+3i} \\right) \\\\\n& = \\frac{\\pi}{6} \\left( \\log (3) + i \\frac{\\pi}{2} \\right).\n\\end{align*}\n\\end{solution}\n%\\vspace*{5cm}\n\n\n\n%\\vspace*{8cm}\n\n\\begin{theorem}[Cauchy's Integral Formula for Derivatives; proof non examinable]\n\\label{t:cauchyd}\nLet $\\mathcal{R}$ be a simply connected region, $\\mathcal{C}$ a simple, closed anticlockwise contour contained in $\\mathcal{R}$ and $f$ a function that is holomorphic on $\\mathcal{R}$. Then\n\\begin{enumerate}\n\\item $f$ is infinitely differentiable on $\\mathcal{R}$, and\n\\item At every point $z$ in the region enclosed by $\\mathcal{C}$, the $k^{th}$ derivative $f^{(k)}$ of $f$ satisfies\n\\[\nf^{(k)}(z) = \\frac{k!}{2\\pi i} \\int_{\\mathcal{C}} \\frac{f(\\zeta)}{(\\zeta-z)^{k+1}}\\ d \\zeta.\n\\]\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}[Liouville's Theorem]\nLet $f:\\C \\to \\C$ be holomorphic (i.e. $f$ is holomorphic on the entire complex plane) and suppose that $f$ is bounded, i.e., there exists $M>0$ with $\\abs{f(z)}\\leq M$ for all $z \\in \\C$.  Then $f$ is constant.\n\\end{theorem}\n{\\bf Proof: } Exercise Sheet 4.\n\n\\section{Evaluating Real Integrals Using Cauchy's Integral Formula}\nAn important application of Cauchy's Integral Formula (Theorem~\\ref{t:cauchyformula}) is that it allows us to evaluate certain \\emph{real} integrals that would be difficult, if not impossible, to evaluate otherwise.  The following example illustrates the general method for doing so, which we shall develop in the next few sections.\n\\begin{example}\n\\label{e:realint1}\nLet $R>1$, and define a contour $\\cont_R$ by joining the line segment $[-R,R]$ and the upper semicircle $\\mathcal{S}_R$ from $R$ to $-R$ via $iR$.  Use Cauchy's Integral Formula to evaluate\n\\[\n\\int_{\\cont_R} \\frac{1}{1+z^2}\\ dz.\n\\]\n\\begin{center}\n\\includegraphics[scale=1.5]{ch5_cr1}\n\\end{center}\n\\end{example}\n\\begin{solution}\nThe function $f$ is holomorphic on $\\C \\backslash \\set{i,-i}$.  Write\n\\[\n\\frac{1}{1+z^2} = \\frac{1}{(z+i)(z-i)} = \\frac{g(z)}{z-z_0}\n\\]\nwhere\n\\[\ng(z) = \\frac{1}{z+i}\\quad \\text{ and } z_0=i.\n\\]\nThen $g$ is holomorphic on $\\C \\backslash \\set{-i}$ and in particular, on the simply connected region $\\mathcal{R} = \\set{ z \\in \\C: \\Im (z) > - \\frac{1}{2}}$.  Moreover, $\\mathcal{C}_R$ is a closed, simple anticlockwise contour in $\\mathcal{R}$ and $z_0=i$ is a point enclosed by $\\mathcal{C}_R$.\n\\begin{comment}\n\\begin{center}\n\\includegraphics[scale=1]{ch5_cr1}\n\\end{center}\n\\end{comment}\nHence by Cauchy's Integral Formula,\n\\begin{align*}\n\\int_{\\mathcal{C}_R} \\frac{1}{1+z^2}\\ dz &= \\int_{\\mathcal{C}_R} \\frac{g(z)}{z-i}\\ dz \\\\\n&= 2 \\pi i g(i) \\\\\n& = 2\\pi i \\frac{1}{i+i} = \\pi.\n\\end{align*}\n(Note that  this integral does not depend on the value of $R$ once $R>1$).\n\n\\end{solution}\n\n\\begin{example}\nNow, let's use Example~\\ref{e:realint1} to evaluate the real integral\n\\[\n\\int_{-\\infty}^{+\\infty} \\frac{1}{1+x^2}\\ dx.\n\\]\n\\end{example}\n\\begin{solution}\nHaving evaluated the integral using Cauchy's Integral Formula, we now look at the integrals along the two paths $L_R$ and $S_R$;\n\\[\n\\int_{\\mathcal{C}_R} \\frac{1}{z^2+1}\\ dz = \\int_{L_R} \\frac{1}{z^2+1}\\ dz + \\int_{S_R} \\frac{1}{z^2+1}\\ dz.\n\\]\nparametrise $L_R$ with $\\gamma_L:[-R,R] \\to \\C$, $\\gamma(t)=t$, so that $\\gamma'(t)=1$ and\n\\[\n\\int_{L_R} \\frac{1}{1+z^2}\\ dz = \\int_{-R}^R \\frac{1}{1+t^2}\\ dt.\n\\]\nWe have seen already (Example~\\ref{e:estimation}) that\n\\[\n\\lim_{R \\to \\infty} \\int_{S_R} \\frac{1}{1+z^2}\\ dz = 0.\n\\]\nHence\n\\begin{align*}\n\\pi & = \\lim_{R \\to \\infty} \\int_{\\mathcal{C}_R} \\frac{1}{1+z^2}\\ dz \\\\\n& = \\left( \\lim_{R \\to \\infty} \\int_{L_R} \\frac{1}{1+z^2}\\ dz \\right) +  \\left( \\lim_{R \\to \\infty} \\int_{S_R} \\frac{1}{1+z^2}\\ dz \\right)  \\\\\n& = \\lim_{R \\to \\infty} \\int_{-R}^R \\frac{1}{1+t^2}\\ dt + 0 \\\\\n& = \\int_{-\\infty}^{\\infty} \\frac{1}{1+t^2}\\ dt.\n\\end{align*}\nSo we have used contour integration to show that\n\\[\n\\int_{-\\infty}^{\\infty} \\frac{1}{1+x^2}\\ dx = \\pi.\n\\]\n\\end{solution}\n\n\n\\begin{example}\n\\label{e:trig1}\nWe shall evaluate the integral\n\\[\n\\int_{\\Gamma} \\frac{2i}{3z^2-10z+3}\\ dz,\n\\]\nwhere $\\Gamma$ is the anticlockwise unit circle $\\set{z: \\abs{z}=1}$, and use it to evaluate the real integral\n\\[\n\\int_0^{2\\pi} \\frac{1}{5-3\\cos(t)}\\ dt.\n\\]\n\\end{example}\n\\begin{solution}\nIf we factorise the denominator, we can write\n\\[\n\\frac{2i}{3z^2-10z+3} = \\frac{2i}{(3z-1)(z-\\frac{1}{3}}.\n\\]\n\nThe point $z_0=\\frac{1}{3}$ is the only point enclosed by $\\Gamma$ at which this function is not holomorphic.  If we let\n\\[\ng(z) = \\frac{2i}{3(z-3)}\n\\]\nwe have\n\\[\n\\frac{g(z)}{z-\\frac{1}{3}} = \\frac{2i}{(3z-1)(z-3)}\n\\]\nand $g$ is holomorphic on the simply connected region $\\set{z \\in \\C: \\Re (z) < 2}$, which contains $\\mathcal{C}$.  Thus\n\\begin{align*}\n\\int_{\\Gamma} \\frac{2i}{(3z-1)(z-3)}\\ dz & = \\int_{\\Gamma} \\frac{g(z)}{z-\\frac{1}{3}}\\ dz \\\\\n& = 2\\pi i g(\\tfrac{1}{3}) \\\\\n& = 2\\pi i \\left( - \\frac{i}{4} \\right) = \\frac{\\pi}{2}.\n\\end{align*}\n\nFor the second part, we parametrise $\\Gamma$ using $\\gamma:[0,2\\pi]\\to \\C$, $\\gamma(t)=e^{it}$ and use\n\\begin{align*}\n\\int_{\\Gamma} f &= \\int_0^{2\\pi} f ( \\gamma(t) ) \\gamma'(t)\\ dt \\\\\n& = \\int_0^{2\\pi} \\frac{2i}{3e^{2it}-10e^{it}+3}\\cdot i e^{it}\\ dt \\\\\n& = \\int_0^{2\\pi} \\frac{-2}{-10+3(e^{it}-e^{-it})}\\ dt.\n\\end{align*}\nSince $\\cos(t) = \\frac{1}{2}\\brac{e^{it}-e^{-it}}$, it follows that\n\\[\n\\frac{-2}{-10+3(e^{it}+e^{-it})} = \\frac{-2}{-10+6\\cos(t)} = \\frac{1}{5-3\\cos(t)}.\n\\]\nHence\n\\[\n\\int_0^{2\\pi} \\frac{1}{5-3\\cos(t)}\\ dt = \\int_{\\Gamma} \\frac{2i}{3z^2-10z+3} = \\frac{\\pi}{2}.\n\\]\n\\end{solution}\n\n\nWe can generalise the method of Example~\\ref{e:trig1} to evaluate other real trigonometric integrals.\n\\begin{definition}\nA \\emph{Rational Function} $R:U \\to \\R$, where $U \\subseteq \\R^2$, is a function of the form\n\\[\nR(x,y) = \\frac{f(x,y)}{g(x,y)},\n\\]\nwhere $f,g: \\mathbb{R}^2 \\to \\R$ are two polynomials in $x$ and $y$ with real coefficients.\n\\end{definition}\nWe will now describe how to use contour integration to evaluate integrals of the form\n\\[\n\\int_0^{2\\pi} R( \\cos (t), \\sin (t) )\\ dt,\n\\]\nwhere $R$ is a rational function of two real variables. For example, if $R$ is defined by\n$\n\\displaystyle R(x,y) = \\frac{1}{16x^2+25y^2},\n$\nthen we are looking at the integral\n\\[\n\\int_0^{2\\pi} R(\\cos (t) , \\sin (t) )\\ dt = \\int_0^{2\\pi} \\frac{1}{16 \\left( \\cos (t) \\right)^2+25 \\left( \\sin (t) \\right)^2}\\ dt.\n\\]\nNote that $\\cos$ and $\\sin$ are periodic with period $2\\pi$, and that the above integral has limits $0$ and $2\\pi$.\n\n\\begin{example}\n\\label{e:trig2}\nFor any rational function $R$ of two real variables, with $R(\\cos(t),\\sin(t))$ defined for every $t \\in [0,2\\pi]$, we can find a suitable closed contour $\\mathcal{C}$ and complex function $f$ so that\n\\[\n\\int_0^{2\\pi} R ( \\cos(t), \\sin (t) ) = \\int_{\\mathcal{C}} f.\n\\]\n\\begin{blankbox}\nLet $\\mathcal{C}$ be the anticlockwise circle $\\set{z \\in \\C: \\abs{z}=1}$, parametrised using $\\gamma:[0,2\\pi] \\to \\C,\\ \\gamma(t) = \\exp(it)$. Let $f$ denote the complex function we are looking for, so we want\n\\[\n\\int_0^{2\\pi} R ( \\cos(t),\\sin(t) ) \\ dt = \\int_{\\mathcal{C}} f = \\int_0^{2\\pi} f \\left( \\gamma (t) \\right) \\gamma' (t)\\ dt,\n\\]\nor in other words,\n\\begin{equation}\n\\tag{R1}\\label{e:r1}\nf( \\gamma(t) ) = \\frac{1}{\\gamma'(t)} \\cdot R( \\cos(t), \\sin (t) ).\n\\end{equation}\nFor each $z \\in \\mathcal{C}$, $z= \\exp(it)$ for some $t \\in [0,2\\pi]$ and so\n\\begin{align*}\n\\cos(t) & = \\frac{\\exp(it)+\\exp(-it)}{2}  = \\frac{z+z^{-1}}{2} \\\\\n\\sin(t) & = \\frac{\\exp(it)-\\exp(-it)}{2i} =  \\frac{z-z^{-1}}{2i} \\\\\n\\end{align*}\nHence for $z=\\exp (it) \\in \\mathcal{C}$, we have\n\\begin{equation}\n\\tag{R2}\\label{e:r2}\n R ( \\cos (t), \\sin (t) )  = R \\left( \\frac{z+z^{-1}}{2}, \\frac{z-z^{-1}}{2i} \\right), \n \\end{equation}\n(this is not true for all $z$, only for $z$ lying on the contour $\\mathcal{C}$). Moreover, $\\gamma'(t) = i \\exp (it) = iz$; so combining~\\eqref{e:r1} and~\\eqref{e:r2}, we define\n\\[\nf(z) = R \\left( \\frac{z+z^{-1}}{2}, \\frac{z-z^{-1}}{2i} \\right) \\cdot \\frac{1}{iz}.\n\\]\nThen\n\\begin{align*}\n\\int_{\\mathcal{C}} f & = \\int_0^{2\\pi} f( \\gamma(t)) \\gamma'(t) \\\\\n& = \\int_0^{2\\pi} R \\left( \\tfrac{1}{2}(\\exp(it)+\\exp(-it)),\\tfrac{1}{2i}(\\exp(it)-\\exp(-it)) \\right) \\cdot \\frac{1}{i\\exp(it)} \\cdot i\\exp(it)\\ dt \\\\\n&= \\int_0^{2\\pi} R( \\cos (t) , \\sin (t))\\ dt.\n\\end{align*}\n\\end{blankbox}\n\\end{example}\n\\begin{example}\nUse a suitable contour integral to evaluate\n\\[\n\\int_0^{2\\pi} \\frac{1}{2+\\sin \\theta}\\ d \\theta.\n\\]\n\\begin{solution}\nWith $\\mathcal{C}$ the anticlockwise unit circle, we have\n\\begin{align*}\n\\int_0^{2\\pi} \\frac{1}{2+\\sin \\theta}\\ d \\theta & = \\int_{\\mathcal{C}} \\frac{1}{2+\\frac{z-z^{-1}}{2i}} \\cdot \\frac{1}{iz}\\ dz \\\\\n& = \\int_{\\mathcal{C}} \\frac{2}{z^2+4iz-1}\\ dz \\\\\n& = \\int_{\\mathcal{C}} \\frac{2}{(z-(-2+\\sqrt{3})i)(z-(-2-\\sqrt{3})i)}\\ dz.\n\\end{align*}\nBy Cauchy's Integral Formula, this integral has the value\n\\[\n2\\pi i \\cdot \\frac{2}{(-2+\\sqrt{3})i-(-2-\\sqrt{3})i} = \\frac{2\\pi}{\\sqrt{3}}.\n\\]\n\\end{solution}\n\\end{example}\n\n\\begin{example}\nSet up a contour integral that could be used to evaluate\n\\[\n\\int_0^{2\\pi} \\frac{1}{16 \\cos^2 (t) + 25 \\sin^2 (t)}\\ dt.\n\\]\n\\begin{solution}\nHere $R(x,y) = \\dfrac{1}{16x^2+25y^2}$, so the required integral (with $\\mathcal{C}$ the anticlockwise circle $\\set{z \\in \\C : \\abs{z}=1 }$) is\n\\begin{align*}\n\\int_{\\mathcal{C}} R \\left( \\frac{z+z^{-1}}{2}, \\frac{z-z^{-1}}{2i} \\right) \\cdot \\frac{1}{iz}\\ dz & = \\int_{\\mathcal{C}} \\frac{1}{16\\left(\\frac{1}{2}(z+z^{-1})\\right)^2+25\\left(\\frac{1}{2i}(z-z^{-1}) \\right)^2} \\cdot \\frac{1}{iz}\\ dz \\\\\n& = \\int_{\\mathcal{C}} \\frac{1}{4(z+2+z^{-2})-\\frac{25}{4}(z^2-2+z^{-2})} \\cdot \\frac{1}{iz}\\ dz \\\\\n& = \\int_{\\mathcal{C}} \\frac{4i}{9z^4-82z^2+9}\\ dz.\n\\end{align*}\nWe do not yet know how to evaluate this integral, we shall do this in Chapter 6.\n\\end{solution}\n\\end{example}\n\n\n\\section{Series Representations of Holomorphic Functions}\n\\begin{definition}\nA sequence $z_n$ of complex numbers is said to converge to a complex number $z$ if, for all $\\epsilon>0$ there is a natural number $N$ such that $n \\geq N$ implies that $\\abs{z_n-z}<\\epsilon$.\n\nAn infinite series $\\sum_{k=1}^{\\infty} a_k$ is said to converge to a complex number $s$ if the sequence of partial sums $s_n:= \\sum_{k=1}^n a_k$ converges to $s$.  When this occurs we write $\\sum_{k=1}^{\\infty} a_k = s$.\n\\end{definition}\n\nFor a fixed $z_0 \\in \\C$, a \\emph{power series} (centred at $z_0$) is a series of the form $\\displaystyle \\sum_{n=0}^{\\infty} a_n (z-z_0)^n$, where $a_n$ are complex numbers.  As with power series in $\\mathbb{R}$, a complex power series may converge for some values of $z$ and diverge for others.  Note that if $\\mathcal{S}$ denotes the subset\n\\[\n\\mathcal{S} = \\set{ z \\in \\C: \\sum_{n=0}^{\\infty} a_n(z-z_0)^n \\text{ converges } },\n\\]\nthen we get a function $f:\\mathcal{S} \\to \\C$ defined by\n\\[\nf(z) = \\sum_{n=0}^{\\infty} a_n (z-z_0)^n.\n\\]\n\n\n\\begin{theorem}[Taylor's Theorem]\n\\label{t:taylor}\nLet $\\mathcal{R}$ be a region, $f:\\mathcal{R} \\to \\C$ holomorphic and $z_0$ a point in $\\mathcal{R}$.  Then $f$ can be represented by the power series\n\\[\nf(z) = \\sum_{n=0}^{\\infty} \\frac{f^{(n)}(z_0)}{n!} (z-z_0)^n\n\\]\nfor all $z \\in D(z_0;R)$, whenever $R>0$ is small enough so that $D(z_0;R) \\subseteq \\mathcal{R}$.\n\\end{theorem}\n\\begin{center}\n\\includegraphics[scale=1]{ch5_taylordisc_full}\n\\end{center}\nBefore proving Taylor's Theorem, we need the following lemma:\n\\begin{lemma}\n\\label{l:taylor}\nLet $f:\\mathcal{R} \\to \\C$ be a function, $z_0 \\in \\mathcal{R}$ and $R>0$ be such that $D(z_0,R) \\subseteq \\mathcal{R}$.  Then for any $0<r<R$, $z \\in D(z_0,r)$ and $\\zeta \\in \\mathcal{C}_r$ we have\n\\[\n\\frac{f(\\zeta)}{\\zeta-z} = \\left( \\sum_{j=0}^n \\frac{(z-z_0)^jf(\\zeta)}{(\\zeta-z_0)^{j+1}} \\right) + \\frac{(z-z_0)^{n+1} f ( \\zeta)}{(\\zeta-z_0)^{n+1}(\\zeta-z)},\n\\]\nwhere $\\mathcal{C}_r$ is the anticlockwise circular contour with centre $z_0$ and radius $r$.\n\\begin{center}\n\\includegraphics[scale=1]{ch5_taylordisclemma}\n\\end{center}\n\\end{lemma}\n\n\\begin{proof}\nNote that we can write\n\\begin{equation}\n\\label{e:taylor1}\\tag{T1}\n\\frac{1}{\\zeta-z} = \\frac{1}{\\zeta-z_0}\\cdot \\frac{1}{\\brac{1-\\frac{z-z_0}{\\zeta-z_0}}}.\n\\end{equation}\nRearranging the formula for a finite geometric sum,\n\\[\n\\sum_{j=0}^n w^j = \\left( \\frac{1-w^{n+1}}{1-w} \\right),\\quad\\text{gives}\\quad \\frac{1}{1-w} = \\left( \\sum_{j=0}^n w^j \\right) + \\frac{w^{n+1}}{1-w},\n\\]\n\nand so substituting $w = \\dfrac{z-z_0}{\\zeta-z_0}$ we get\n\\begin{align*}\n\\frac{1}{\\brac{1-\\frac{z-z_0}{\\zeta-z_0}}} & = \\left(\\sum_{j=0}^n \\left(\\frac{z-z_0}{\\zeta-z_0}\\right)^j \\right) + \\frac{(z-z_0)^{n+1}}{\\brac{\\zeta-z_0}^{n+1}\\brac{1-\\frac{z-z_0}{\\zeta-z_0}}} \\\\\n& = \\left(\\sum_{j=0}^n \\left(\\frac{z-z_0}{\\zeta-z_0}\\right)^j \\right) + \\frac{\\brac{z-z_0}^{n+1}}{\\brac{\\zeta-z_0}^n \\brac{\\zeta-z}}.\n\\end{align*}\nCombining this with~\\eqref{e:taylor1}, and multiplying both sides by $f(\\zeta)$ we get\n\\[\n\\frac{f(\\zeta)}{\\zeta-z} = \\left( \\sum_{j=0}^n (z-z_0)^j \\frac{f(\\zeta)}{(\\zeta-z_0)^{j+1}} \\right) + \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\n\\]\n\\end{proof}\n\n\\begin{exercise}\nUse the following steps to prove this Theorem (for now, you should assume the result of Lemma~\\ref{l:taylor}).  Fix $r$ with $0<r<R$ and let $\\mathcal{C}_r$ be the anticlockwise circular contour with centre $z_0$ and radius $R$.\n\\begin{enumerate}\n\\item[(i)]  Explain why \n\\[\nf(z) = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}_r} \\frac{f(\\zeta)}{\\zeta-z}\\ d\\zeta\n\\]\nfor all $z \\in D(z_0,r)$.\n\n\\item[(ii)] Use Lemma~\\ref{l:taylor} to show that\n\\[\n2\\pi i f( z) = \\left( \\sum_{j=0}^n (z-z_0)^j  \\int_{\\mathcal{C}_r} \\frac{f(\\zeta)}{(\\zeta-z_0)^{j+1}}\\ d\\zeta \\right) + \\int_{\\mathcal{C}_r} \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta\n\\]\n\n\\item[(iii)] Use Cauchy's Integral Formula for Derivatives to show that\n\\[\nf(z) = f(z_0)+(z-z_0)f'(z_0)+\\frac{(z-z_0)^2f''(z_0)}{2!}+\\ldots+ \\frac{(z-z_0)^n f^{(n)}(z_0)}{n!} + I_n,\n\\]\nwhere $I_n = \\displaystyle \\frac{1}{2\\pi i}\\int_{\\mathcal{C}_r}  \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta.$.\n\\item[(iv)] Show that\n\\begin{itemize}\n\\item $\\abs{\\zeta-z} \\geq r - \\abs{z-z_0}$ for all $\\zeta \\in \\mathcal{C}_r$ and $z \\in D(z_0,r)$, and that\n\\item there exists $K \\geq 0$ with $\\abs{f(\\zeta)} \\leq K$ for all $\\zeta \\in \\mathcal{C}_r$.\n\\end{itemize}\n\\item[(v)] Use part (iv) and the Estimation Lemma to show that\n\\[\n\\abs{I_n} \\leq \\frac{1}{2\\pi} \\cdot \\abs{\\frac{z-z_0}{\\zeta-z_0}}^{n+1} \\cdot \\frac{K}{r-\\abs{z-z_0}}\n\\]\n\\item[(vi) ] Use part (v) to show that $\\abs{I_n} \\to 0$ and $n \\to \\infty$, and explain why this completes the proof.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{proof}[of Taylor's Theorem~\\ref{t:taylor}]\nChoose $r>0$ with $0 < r < R$ and let $\\mathcal{C}_r$ be the anticlockwise circle with centre $z_0$ and radius $r$.  Then by Cauchy's Integral Formula,\n\\[\nf(z) = \\frac{1}{2\\pi i} \\int_{\\mathcal{C}_r} \\frac{f(\\zeta)}{\\zeta-z}\\ d\\zeta\n\\]\nfor all $z$ with $\\abs{z-z_0}<r$.\n\\begin{center}\n\\includegraphics[scale=1]{ch5_taylordiscproof_full}\n\\end{center}\n\nTogether with Lemma~\\ref{l:taylor} we see that\n\\[\n2\\pi i f(z) = \\int_{\\mathcal{C}_r} \\left[ \\left( \\sum_{j=0}^n (z-z_0)^j \\frac{f(\\zeta)}{(\\zeta-z_0)^{j+1}} \\right) + \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}  \\right]\\ d \\zeta. \n\\]\nUsing linearity of contour integrals, we first get\n\\[\n2\\pi i f(z) = \\left( \\sum_{j=0}^n \\int_{\\mathcal{C}_r} (z-z_0)^j \\frac{f(\\zeta)}{(\\zeta-z_0)^{j+1}}\\ d\\zeta \\right) + \\int_{\\mathcal{C}_r} \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta.\n\\]\nand noting that since we are integrating with respect to $\\zeta$, the $(z-z_0)$ terms are constant, this becomes\n\\[\n2\\pi i f( z) = \\left( \\sum_{j=0}^n (z-z_0)^j  \\int_{\\mathcal{C}_r} \\frac{f(\\zeta)}{(\\zeta-z_0)^{j+1}}\\ d\\zeta \\right) + \\int_{\\mathcal{C}_r} \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta\n\\]\n(we leave the last term as it is for now).\n\nUsing Cauchy's Integral Formula For Derivatives (Theorem~\\ref{t:cauchyd}), and dividing both sides by $2\\pi i$, this becomes\n\\[\nf(z) = f(z_0)+(z-z_0)f'(z_0)+\\frac{(z-z_0)^2f''(z_0)}{2!}+\\ldots+ \\frac{(z-z_0)^n f^{(n)}(z_0)}{n!} + I_n,\n\\]\nwhere \n\\[\nI_n = \\frac{1}{2\\pi i}\\int_{\\mathcal{C}_r}  \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta.\n\\]\nTo complete the proof, we must show that $I_n \\to 0$ as $n \\to \\infty$.  We shall use the Estimation Lemma to do this.\n\n\\begin{itemize}\n\\item For $\\zeta \\in \\mathcal{C}_r$, we have $\\abs{\\zeta-z_0}=r$, and since $z$ is enclosed by $\\mathcal{C}_r$, $\\abs{z-z_0}<r$.\n\\item Since $f$ is continuous on $\\mathcal{C}_r$, there is some real number $K \\geq 0$ such that $\\abs{f(\\zeta)} \\leq K$ for all $\\zeta$ in $\\mathcal{C}_r$.  To see this, note that if $\\mathcal{C}_r$ is parametrised by the continuous function $\\gamma:[0,2\\pi] \\to \\C$, $\\gamma (t) = z_0+r e^{it}$, then $t \\mapsto \\abs{f(\\gamma(t))}$ is a continuous, real-valued function on a closed interval, hence is bounded by the Extreme Value Theorem.\n\\item By the backwards triangle inequality,\n\\[\n\\abs{\\zeta-z} = \\abs{\\zeta-z_0+z_0-z} \\geq \\abs{\\abs{\\zeta-z_0}-\\abs{z_0-z}} = r - \\abs{z_0-z},\n\\]\na strictly positive constant since $z$ is fixed and $\\abs{z_0-z}<r$.\n\\end{itemize}\nHence for all $\\zeta \\in \\mathcal{C}_r$ we have\n\\[\n\\abs{\\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}} } = \\abs{\\frac{z-z_0}{\\zeta-z_0}}^{n+1}\\cdot \\frac{\\abs{f(\\zeta)}}{\\abs{\\zeta-z}} \\leq \\abs{\\frac{z-z_0}{\\zeta-z_0}}^{n+1} \\cdot \\frac{K}{r-\\abs{z-z_0}}\n\\]\nThus by the Estimation Lemma,\n\\[\n\\abs{I_n} = \\abs{\\frac{1}{2\\pi i}\\int_{\\mathcal{C}_r}  \\frac{\\brac{z-z_0}^{n+1}f(\\zeta)}{\\brac{\\zeta-z_0}^{n+1} \\brac{\\zeta-z}}\\ d\\zeta} \\leq \\frac{1}{2\\pi} \\cdot \\abs{\\frac{z-z_0}{\\zeta-z_0}}^{n+1} \\cdot \\frac{K}{r-\\abs{z-z_0}},\n\\]\nSince $\\abs{z-z_0}<\\abs{\\zeta-z_0}$, $\\abs{\\dfrac{z-z_0}{\\zeta-z_0}}<1$ and so\n$\\displaystyle \\abs{\\frac{z-z_0}{\\zeta-z_0}}^{n+1} \\to 0 $ as  $n \\to \\infty$.\n\nSince all other terms in the estimate are constant, this shows that $I_n \\to 0$ as $n \\to \\infty$.\n\n\\end{proof}\n\nMany familiar examples of Taylor Series from the real case are also valid for the corresponding complex functions:\n\\begin{center}\n\\includegraphics[scale=0.5]{ch5_taylor_examples}\n\\end{center}\nThese examples can be computed in exactly the same way as the corresponding real series.  In fact, we could say a lot more about complex Taylor Series, but we will not have time to do so in this module. \n\\begin{example}\nThe Taylor Series expansion of a function $f:\\mathcal{R} \\to \\C$ at a point $z_0 \\in \\mathcal{R}$ may not be valid everywhere in the domain of $f$.  For example, let us examine the Taylor series at $z=0$ of the function $f:\\C \\backslash \\set{-i,i} \\to \\C$ defined by\n\\[\nf(z) = \\frac{1}{1+z^2}.\n\\]\n\\end{example} \n\\begin{blankbox}\nThis function is holomorphic on $\\C \\backslash \\set{-i,i}$, and by differentiation we can show that its Taylor series at $z=0$ is\n\\[\n\\sum_{n=0}^{\\infty} (-1)^{n} z^{2n}.\n\\]\nThe largest disc centred at $0$ that is contained in $\\C \\backslash \\set{-i,i}$ is $D(0,1)$, hence this Taylor Series is valid (i.e. converges to $f(z)$) at every point of this disc by Theorem~\\ref{t:taylor}.  However, Theorem~\\ref{t:taylor} tells us nothing about convergence of this series at points of $\\C \\backslash \\set{-i,i}$ that lie outside of this disc (in fact the series diverges at these points).\n\\begin{center}\n\\begin{tabular}{cc}\n\\altgraphics[scale=1]{ch5_taylorexample2_full}{ch5_taylorexample2} & \\altgraphics[scale=1]{ch5_taylorexample3_full}{ch5_taylorexample3}\n\\end{tabular}\n\\end{center}\n\nSimilarly, if we compute the Taylor Series for $f$ at $z=2+i$ (which we won't do, but we know it exists), Theorem~\\ref{t:taylor} tells us that this series converges for all $z$ inside the disc $D(2+i,2)$.\n\\end{blankbox}\n\n\n\n\\begin{remark}\nIt is worth pointing out some of the differences between the real and complex versions of Taylor's Theorem.\n\\begin{enumerate}\n\\item[(i)]  In the complex case, once we know that $f$ is differentiable everywhere on an open set $\\mathcal{R}$ (i.e. holomorphic on $\\mathcal{R}$), we know that $f$ can be represented by a Taylor series.  For real functions it is not enough to know that $f$ is differentiable on an open interval; $f$ must be infinitely differentiable.\n\\item[(ii)] There are examples of real functions that are infinitely differentiable, but whose Taylor series have radius on convergence $0$, e.g., the function $f$ defined by $f(x) = e^{-1/x^2}$ for $x \\neq 0$ and $f(0)=0$.  This cannot happen in the complex case; the radius of convergence is always positive.\n\\end{enumerate}\n\\end{remark}", "meta": {"hexsha": "1648ef2e87d30c2c411167b008611b213140fd97", "size": 34986, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2003/LectureNotes/Chapter_5.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_5.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_5.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": 46.5239361702, "max_line_length": 488, "alphanum_fraction": 0.6529183102, "num_tokens": 13719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.6121611676825378}}
{"text": "\\section{Combinations}\n\n    \\subsection{What are Combinations?}\n     A Combination is a way of selecting objects (permuting) from a group, without the order being important.\n     In essence, it is orderless permutations. Let $ABC$ be a permutation.\n     With permutations we asserted that $ABC$ and $BAC$ are different, as they are ordered differently.\n     In combinations, we assert that $ABC$ and $BAC$ are the same, as they contain the same objects, just in a different order.\n\n    \\subsection{Set Theory}\n    Set Theory involves the creation and manipulation of sets and their properties.\n    A set is a collection of distinct objects in which their order does not matter.\n    The objects in this set are called elements.\n    If a set does not have any elements in it, we refer to it as a \\emph{null set}, which is shown as $\\emptyset$ or $(\\emptyset)$.\n    This null set is a subset of everything.\n    If we want to describe a set containing elements, we must follow the example below.\n    \\begin{equation*}\n        X = \\{a,b,c,d,e,f,\\cdots,y,z\\}\n    \\end{equation*}\n    If we wish to describe the number of elements in the set, we can use $n(X)$, where X represents the set, and n returns the number of elements in that set.\n    In this case $n(X) = 26$, as set X contains all the letters of the alphabet.\n    Sets are referred to differently when compared to other sets, as defined below.\n    \\begin{definition}\n    Special Properties of Sets when Compared to Other Sets\n    \\begin{enumerate}\n        \\item If two sets have no elements in common they are called disjoint sets.\n        \\item If two sets have all elements in common they are equal.\n        \\item If all of elements of A are also in B then A is a subset of B $(A\\subseteq B)$\n    \\end{enumerate}\n    \\end{definition}\n    \n        \\subsubsection{Universal Set and Complement Sets}\n        The set of all elements being considered is called the\\emph{universal set} and is always denoted by $S$.\n        When referring to a set of all elements that are in the universal set, but\\textbf{ not in set A}, we call this the complement of $A$ or $A`$. For example:\n        \\begin{equation*}\n            S = \\{1,2,3,4\\}, A = \\{1,3\\}, A`=\\{2,4\\}\n        \\end{equation*}\n        \n        \\subsubsection{Unions and Intersections}\n        For two sets of A and B, the \\textbf{union} of A and B or $A\\cup B$, is the set of all elements in A or B, not including duplicates.\n        \\begin{equation*}\n            S = \\{1,2,3,4\\}, A = \\{1,3\\}, B =\\{1,2\\}, A\\cup B=\\{1,2,3\\}\n        \\end{equation*}\n        For two sets of A and B the \\textbf{intersection} of A and B, $A\\cap B$, is the set of all the elements that are in both set A and set B.\n        \\begin{equation*}\n            S = \\{1,2,3,4\\}, A = \\{1,3\\}, B =\\{1,2\\}, A\\cap B=\\{1\\}\n        \\end{equation*}\n        If you are ever having trouble remembering the difference between the symbols representing the union and the intersection, remember that a union looks like a cup, and intersection looks like a cap.\n        \n        \\subsubsection{Subsets}\n        Subsets, are sets that are also in another set. To find every possible subset (including null set) we need to use the equation:\n        \\begin{equation*}\n            2^{n(X)}\n        \\end{equation*}\n        In this case, n(X) is the number of elements in Set X. If a question comes up, where we need the number of subsets of a given set with the length $y$, of set $x$, we'd simply use $\\binom{n(x)}{y}$\n        \n    \\subsection{Introduction to Combinations}\n    A combination is a selection of r objects, from n distinct objects \\emph{without regard for order}.\n    The equation for solving combinations is written below.\n    \\begin{equation*}\n        C(n,r) = \\frac{n!}{(n-r)!\\cdot r!}\n    \\end{equation*}\n    This equations finds all combinations by dividing number of objects, by the unused objects $(n-r)!$ and the order of the selected objects.\n    This can be further simplified to:\n    \\begin{equation*}\n        C(n,r) = \\frac{P(n,r)}{r!}\n    \\end{equation*}\n    If order does not matter, the process is called a \\emph{Combination}, whereas when order does matter, it is called a \\emph{Permutation}.\n    On your calculator, the formulae for combinations will be shown as \\textbf{nCr}.\n    If written out by hand, we will use the form:\n    \\begin{equation*}\n        \\binom{n}{r} = \\frac{n!}{(n-r)!\\cdot n!}\n    \\end{equation*}\n    Or simply \\(\\binom{n}{r}\\).\n    \n    \\subsection{Inclusion\\textemdash Exclusion Principle}\n    The Inclusion-exclusion principle is a method of obtaining the number of elements in finite sets.\n    Typically used when asked for the number of combinations of two things, where there is overlap between the two.\\\\\n    Let A represent Set A, and let B represent Set B.\n    \\begin{center}\n        %% Thank you http://tex.stackexchange.com/questions/9681/how-to-draw-venn-diagrams-especially-complements-in-latex\n        \\begin{tikzpicture}[fill=gray]\n            % left hand\n            \\scope\n            \\clip (-2,-2) rectangle (2,2)\n                  (1,0) circle (1);\n            \\fill (0,0) circle (1);\n            \\endscope\n            % right hand\n            \\scope\n            \\clip (-2,-2) rectangle (2,2)\n                  (0,0) circle (1);\n            \\fill (1,0) circle (1);\n            \\endscope\n            % outline\n            \\draw (0,0) circle (1) (0,1)  node [text=black,above] {$A$}\n                  (1,0) circle (1) (1,1)  node [text=black,above] {$B$}\n                  (-2,-2) rectangle (3,2) node [text=black,above] {$H$};\n        \\end{tikzpicture}\n    \\end{center}\n    This diagram perfectly represents the overlap between the two sets.\n    If you caught it earlier, what we're actually finding is $A\\cup B$.\n    The Inclusion\\textemdash Exclusion Principle is merely a way of finding it algebraically.\n    The image above represents the equation below.\n    \\begin{equation*}\n        |A\\cup B| = |A| + |B| - |A\\cap B|\n    \\end{equation*}\n    What happens if we have have three events we need to find the union of though?\n    To do that, we'll follow the same principles, and use the equation below.\n    \\begin{equation*}\n        |A\\cup B\\cup C| = |A| + |B| + |C| - |A\\cap B| - |A\\cap C| - |B\\cap C| + |A\\cap B\\cap C|\n    \\end{equation*}\n    %%TODO: Include a Venn Diagram for this equation above.", "meta": {"hexsha": "38a7ff46307f7e0518a88d35c57cc79070c321e4", "size": 6327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "highschool-projects/MDM4UI/Combinations.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/Combinations.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/Combinations.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": 56.4910714286, "max_line_length": 205, "alphanum_fraction": 0.6396396396, "num_tokens": 1751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6121611661123231}}
{"text": "\\label{appendix:equations}\n\nThis appendix describes the most important equations used in this thesis.\n\n\\section{Neutron flux equations}\n\\label{appendix:equations-n}\n\nEquations \\ref{eq:diffusion} and \\ref{eq:precursors} describe the time dependent behavior of the neutron flux and the concentration of the delayed neutron precursors\nduded\n\\begin{align}\n  % diffusion\n  & \\frac{1}{v_g}\\frac{\\partial}{\\partial t} \\phi_g = \\nabla \\cdot D_g \\nabla \\phi_g - \\Sigma_g^r \\phi_g +\n  \\sum_{g' \\ne g}^G \\Sigma_{g'\\rightarrow g}^s \\phi_{g'} + \\chi_g^p \\sum_{g' = 1}^G (1 - \\beta) \\nu \\Sigma_{g'}^f \\phi_{g'} + \n  \\chi_g^d \\sum_i^I \\lambda_i C_i \\label{eq:diffusion} \\\\\n  % precursors\n  & \\frac{\\partial}{\\partial t} C_i = \\sum_{g'= 1}^G \\beta_i \\nu \\Sigma_{g'}^f \\phi_{g'} - \\lambda_i C_i \\label{eq:precursors}\n  \\intertext{where}\n  & v_g = \\mbox{group $g$ neutron speed } [cm \\cdot s^{-1}] \\notag \\\\\n  & \\phi_g = \\mbox{group $g$ neutron flux } [n \\cdot cm^{-2} \\cdot s^{-1}] \\notag \\\\\n  & t = \\mbox{time } [s] \\notag \\\\\n  & D_g = \\mbox{group $g$ diffusion coefficient } [cm] \\notag \\\\\n  & \\Sigma_g^r = \\mbox{group $g$ macroscopic removal cross-section } [cm^{-1}] \\notag \\\\\n  & \\Sigma_{g'\\rightarrow g}^s = \\mbox{group $g'$ to group $g$ macroscopic scattering cross-section } [cm^{-1}] \\notag \\\\\n  & \\chi_g^p = \\mbox{group $g$ prompt fission spectrum } [-] \\notag\\\\\n  & G = \\mbox{number of discrete energy groups } [-] \\notag \\\\\n  & \\nu = \\mbox{number of neutrons produced per fission } [-] \\notag \\\\\n  & \\Sigma_g^f = \\mbox{group $g$ macroscopic fission cross-section } [cm^{-1}] \\notag \\\\\n  & \\chi_g^d = \\mbox{group $g$ delayed fission spectrum } [-] \\notag \\\\\n  & I = \\mbox{number of delayed neutron precursor groups } [-] \\notag \\\\\n  & \\beta = \\mbox{delayed neutron fraction } [-] \\notag \\\\\n  & \\lambda_i = \\mbox{average decay constant of delayed neutron precursors in precursor group $i$ } [s^{-1}] \\notag \\\\\n  & C_i = \\mbox{concentration of delayed neutron precursors in precursor group $i$ } [cm^{-3}]. \\notag\n\\end{align}\n\nThe following equation relates $\\chi_g^t$ to $\\chi_g^p$ and $\\chi_g^d$ \\cite{hetrick_dynamics_1993}\n\\begin{align}\n  & \\chi_g^t = \\chi_g^p (1 - \\beta) + \\chi_g^d \\sum_i^I \\beta_i  \\label{eq:chit} \\\\\n  \\intertext{where}\n  & \\chi_g^t = \\mbox{group $g$ total fission spectrum } [-]. \\notag\n\\end{align}\n\nThe combination of the steady-state of equations \\ref{eq:diffusion}, \\ref{eq:precursors}, \\ref{eq:chit}, and replacing $\\nu\\Sigma_g^f$ by $\\frac{\\nu\\Sigma_g^f}{k_{eff}}$ yields the eigenvalue equation \\cite{duderstadt_nuclear_1976}\n\\begin{align}\n  \\nabla \\cdot D_g \\nabla \\phi_g - \\Sigma_g^r \\phi_g & + \\sum_{g \\ne g'}^G \\Sigma_{g'\\rightarrow g}^s \\phi_{g'} +\n  \\chi_g^t \\sum_{g' = 1}^G \\frac{1}{k_{eff}}\\nu \\Sigma_{g'}^f \\phi_{g'} = 0 \\label{eq:app-eigenvalue}\n  \\intertext{where}\n  k_{eff} = \\mbox{multiplication factor } [-]. \\notag\n\\end{align}\n\n\\section{Thermal-fluids equations}\n\\label{appendix:equations-th}\n\n% solids\nThe three-dimensional heat conduction equation \\cite{melese_thermal_1984} allows for solving the temperature in the fuel, helium gap, moderator, coolant film, and reflector.\n\\begin{align}\n  & \\rho_i c_{p,i} \\frac{\\partial}{\\partial t} T_i = k_i \\nabla^2 T_i + Q_i \\label{eq:app-solid} \\\\\n  \\intertext{where}\n  & i = \\mbox{f (fuel), g (helium gap), m (moderator), cf (coolant film), r (reflector)} \\notag \\\\\n  & \\rho_i = \\mbox{material $i$ density } [kg \\cdot cm^{-3}] \\notag \\\\\n  & c_{p,i} = \\mbox{material $i$ heat capacity } [J \\cdot kg^{-1} \\cdot K^{-1}] \\notag \\\\\n  & k_i = \\mbox{material $i$ thermal conductivity  } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n  & T_i = \\mbox{material $i$ temperature } [^{\\circ}C] \\notag \\\\\n  & Q_i = \\mbox{material $i$ volumetric heat source } [W \\cdot cm^{-3}]. \\notag\n\\end{align}\n\nEquations \\ref{eq:app-heatsource1} and \\ref{eq:app-heatsource2} define the fuel heat source in the stand-alone and coupled calculations\n\\begin{align}\n  & Q_f = Q_0 \\label{eq:app-heatsource1} \\\\\n  & Q_f = \\sum_{g = 1}^{G} \\epsilon_g^f \\Sigma_g^f \\phi_g \\label{eq:app-heatsource2} \\\\\n  & Q_g = Q_m = Q_{cf} = Q_r = 0 \\label{eq:app-heatsource3}\n  \\intertext{where}\n  & Q_i = \\mbox{material $i$ volumetric heat source } [W \\cdot cm^{-3}] \\notag \\\\\n  & \\epsilon_g^f = \\mbox{energy released per fission } [J] \\notag \\\\\n  & \\Sigma_g^f = \\mbox{group $g$ macroscopic fission cross-section } [cm^{-1}] \\notag \\\\\n  & \\phi_g = \\mbox{group $g$ neutron flux } [n \\cdot cm^{-2} \\cdot s^{-1}]. \\notag\n\\end{align}\n\n% coolant\nThe governing equation of the coolant is the one-dimensional form of the continuity, momentum, and energy conservation equations \\cite{white_viscous_2006}\n\n\\begin{align}\n  & \\frac{\\partial}{\\partial t} \\rho_c + \\nabla \\cdot (\\rho_c u) = 0 \\label{eq:app-continuity} \\\\\n  & \\rho_c \\left(\\frac{\\partial}{\\partial t} u + u\\frac{\\partial}{\\partial z}u \\right) = - \\frac{\\partial}{\\partial z}p - \\tau \\frac{\\varepsilon}{A} - \\rho_c g \\label{eq:app-momentum} \\\\\n  & \\rho_c \\left( \\frac{\\partial}{\\partial t} (c_{p,c} T_c) + u\\frac{\\partial}{\\partial z} (c_{p,c} T_c) \\right) = \\frac{\\partial}{\\partial t} p + u\\frac{\\partial}{\\partial z} p +  q'''_{conv}  \\label{eq:app-tempcool} \\\\\n  & \\tau = \\frac{f}{2} \\rho_c u^2 \\label{eq:app-friction} \\\\\n  & q'''_{conv} = h\\frac{\\varepsilon}{A} (T_i-T_c) \\label{eq:app-convection}\n  \\intertext{where}\n  & \\rho_c = \\mbox{coolant density } [kg \\cdot cm^{-3}] \\notag \\\\\n  & u = \\mbox{coolant velocity } [cm \\cdot s^{-1}] \\notag \\\\\n  & p = \\mbox{coolant pressure } [\\times 10^{-2} Pa] \\notag \\\\\n  & \\tau = \\mbox{shear stress } [\\times 10^{-2} Pa] \\notag \\\\\n  & \\varepsilon = \\mbox{wetted perimeter } [cm] \\notag \\\\\n  & A = \\mbox{cross-sectional area } [cm^2] \\notag \\\\\n  & g = \\mbox{gravity } [m \\cdot s^{-2}] \\notag \\\\\n  & c_{p,c} = \\mbox{coolant specific heat capacity } [J \\cdot kg^{-1} \\cdot K^{-1}] \\notag \\\\\n  & T_c = \\mbox{coolant temperature } [^{\\circ}C] \\notag \\\\\n  & k_c = \\mbox{coolant thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n  & q'''_{conv} = \\mbox{convective heat transfer } [W \\cdot cm^{-3}] \\notag \\\\\n  & f = \\mbox{friction factor } [-] \\notag \\\\\n  & h = \\mbox{heat transfer coefficient } [W \\cdot cm^{-2} \\cdot K^{-1}] \\notag \\\\\n  & T_i = \\mbox{solid temperature } [^{\\circ}C]. \\notag\n\\end{align}\n\nEquation \\ref{eq:app-churchill} \\cite{churchill_friction-factor_1977} determines the friction factor $f$\n\n\\begin{align}\n  & f = 8\\left[ \\left( \\frac{8}{Re} \\right)^{12} + \\frac{1}{(A+B)^{3/2}} \\right]^{1/12} \\notag \\\\\n  & A = \\left\\{ 2.457 \\quad ln \\left( \\frac{1}{\\left(\\frac{7}{Re_{D_h}}\\right)^{0.9}+0.27\\frac{\\varepsilon}{D_h}} \\right) \\right\\}^{16} \\label{eq:app-churchill} \\\\\n  & B = \\left\\{ \\frac{37530}{Re} \\right\\}^{16} \\notag\n  \\intertext{where}\n  & \\varepsilon = \\mbox{surface roughness } [-] \\notag \\\\\n  & Re = \\mbox{Reynolds number } [-] \\notag \\\\\n  & D_h = \\mbox{hydraulic diameter } [cm]. \\notag\n\\end{align}\n\nEquation \\ref{eq:app-film-conduc} calculates the film thermal conductivity $k_f$ \\cite{melese_thermal_1984}\n\n\\begin{align}\n  & Nu = 0.023 Re^{0.8} Pr^{0.4} \\label{eq:app-dittus} \\\\\n  & h = \\frac{Nu \\cdot k_c}{D_h}  \\\\\n  & k_f = h R_{cf} ln(R_{cf}/R_c) \\label{eq:app-film-conduc}\n  \\intertext{where}\n  & Nu = \\mbox{Nusselt number } [-] \\notag \\\\\n  & Pr = \\mbox{Prandtl number } [-] \\notag \\\\\n  & h = \\mbox{heat transfer coefficient } [W \\cdot cm^{-2} \\cdot s^{-1}] \\notag \\\\\n  & D_h = \\mbox{hydraulic diameter } [cm] \\notag \\\\\n  & k_c = \\mbox{coolant thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n  & k_{cf} = \\mbox{coolant film thermal conductivity } [W \\cdot cm^{-1} \\cdot K^{-1}] \\notag \\\\\n  & R_{cf} = \\mbox{coolant film radius } [cm] \\notag \\\\\n  & R_c = \\mbox{coolant channel radius } [cm]. \\notag\n\\end{align}\n\nIn the steady-state limit, equation \\ref{eq:app-continuity} becomes\n\\begin{align}\n  & \\nabla \\cdot (\\rho_c u) = 0\n  \\intertext{wich leads to } \n  & \\rho_c u (z) = \\rho_{c,i} u_i \n  \\intertext{where} \n  & \\rho_{c,i} = \\mbox{inlet coolant density} \\notag \\\\\n  & u_i = \\mbox{inlet coolant velocity.} \\notag\n\\end{align}\n\nIn the steady-state limit, the temperature equations (equations \\ref{eq:app-solid} and \\ref{eq:app-tempcool}) become \\cite{tak_practical_2012}\n\\begin{align}\n  & k_i \\nabla^2 T_i + Q_i = 0 \\\\\n  & \\rho_{c,i} u_i\\frac{\\partial}{\\partial z} (c_{p,c} T_c) = q'''_{conv}.\n\\end{align}\n\n\n\\section{Coolant distribution equation}\n\\label{appendix:equations-fluid}\n\nThe pressure drop in a coolant channel is proportinal to the mass flow squared \n\\begin{align}\n  & \\Delta P = B_i \\dot{m}_i^2 \\label{eq:app-itersolver1}\n  \\intertext{where}\n  & \\Delta P = \\mbox{pressure drop } [Pa] \\notag \\\\\n  & \\dot{m}_i = \\mbox{channel $i$ mass flow rate } [kg \\cdot s^{-1}] \\notag \\\\\n  & B_i = \\mbox{constant specified by the chosen model, value that depends on $\\dot{m}_i$} [kg \\cdot m^{-1}] \\notag\n\\end{align}\nwhich is equivalent to\n\\begin{align}\n  & \\dot{m}_i = \\sqrt{\\frac{\\Delta P}{B_i}}. \\label{eq:app-itersolver2}\n\\end{align}\n\nAssuming constant $\\Delta P$ across all coolant paths, and using equation \\ref{eq:app-itersolver2}, it is possible to calculate the total mass flow rate $\\dot{m}_T$\n\\begin{align}\n  & \\dot{m}_T = \\sum_i \\dot{m}_i = \\sum_i \\sqrt{\\frac{\\Delta P}{B_i}} = \\Delta P \\frac{1}{\\sum_i \\sqrt{B_i}}.\n\\end{align}\n\nFinally, equation \\ref{eq:app-itersolver3} gives $\\Delta P$\n\\begin{align}\n  & \\Delta P = \\frac{\\dot{m}_T}{\\sum_i \\frac{1}{\\sqrt{B_i}}}. \\label{eq:app-itersolver3}\n\\end{align}\n\nThese equations solve $\\dot{m}_i$ using an iterative scheme as $B_i$ depends on $\\dot{m}_i$ \\cite{melese_thermal_1984}\n\\begin{align}\n  & B_i^{(n)} = f(\\dot{m}_i^{(n)}) \\\\\n  & \\Delta P^{(n)} = \\frac{\\dot{m}_T}{\\sum_i \\frac{1}{\\sqrt{B_i^{(n)}}}} \\\\\n  & \\dot{m}_i^{(n+1)} = \\sqrt{\\frac{\\Delta P^{(n)}}{B_i^{(n)}}}.\n\\end{align}", "meta": {"hexsha": "37fa21efba89febceec0ff672f4f72ff34df4824", "size": 9720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixA.tex", "max_stars_repo_name": "robfairh/ms-thesis", "max_stars_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-27T15:39:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T15:39:36.000Z", "max_issues_repo_path": "appendixA.tex", "max_issues_repo_name": "robfairh/ms-thesis", "max_issues_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2020-07-10T18:40:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-02T22:37:02.000Z", "max_forks_repo_path": "appendixA.tex", "max_forks_repo_name": "robfairh/ms-thesis", "max_forks_repo_head_hexsha": "87bc9d4f93d083b08d82c8576b9491f85d0a6457", "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": 53.7016574586, "max_line_length": 231, "alphanum_fraction": 0.6369341564, "num_tokens": 3670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6121611661123231}}
{"text": "\\section{Appendix}\n\n\\subsection{Input-output analysis}\n\\label{app:input_ouput}\n\n\nFor a 2x2 economy, the $\\pmb{A^d}$ matrix is equal to:\n$$ \\pmb{A^d} = \n\\begin{pmatrix} \n\t\\frac{Z11}{P1}  & \\frac{Z12}{P2} \\\\\n\t\\frac{Z21}{P1} & \\frac{Z22}{P2} \n\\end{pmatrix}\n=\n\\begin{pmatrix} \na  & b \\\\\nc & d\n\\end{pmatrix}\n$$\nso:\n$$\\pmb{\\pmb{I} - \\pmb{A^d}} = \n\\begin{pmatrix} \n1 - d  & b \\\\\nc & 1 - a\n\\end{pmatrix}\n$$\n\nWe define $\\Delta$ as $\\Delta = det(\\pmb{I} - \\pmb{A^d})$. Then\n$\\pmb{Q} = (\\pmb{I} - \\pmb{A^d})^{-1}$ is equal to\n$$\\pmb{Q} = \\frac{1}{\\Delta}\n\\begin{pmatrix} \n1 - d  & b \\\\\nc & 1 - a\n\\end{pmatrix}\n$$\n\nTo get a better intuition of the mechanism, we introduce the value added per unit of production: $(va)_i = (VA_i/Pi)$.\nThen, the value added per unit of final demand is equal to:\n$$<va> \\cdot Q =\n\\begin{pmatrix} \nva_1 & 0 \\\\\n0 & va_2\n\\end{pmatrix}\n\\cdot Q \n= \\frac{1}{\\Delta}\n\\begin{pmatrix} \nva_1 \\cdot (1-d) & va_1 \\cdot b \\\\\nva_2 \\cdot c & va_2 \\cdot (1-a)\n\\end{pmatrix}\n$$\n\n$$<va> \\cdot Q \n= \\frac{1}{\\Delta}\n\\begin{pmatrix} \n(1- a-c)\\cdot (1-d) & (1-a-c) \\cdot b \\\\\n(1-b-d) \\cdot c & (1-b-d) \\cdot (1-a)\n\\end{pmatrix}\n$$\n\nwhich simplifies by noting that the sum of the column are equal to 1 :\n$$<va> \\cdot Q \n= \n\\begin{pmatrix} \n1-\\theta_1 & \\theta_2 \\\\\n\\theta_1  & 1-\\theta_2\n\\end{pmatrix}\n$$\n\nwith $\\theta_1 =  \\frac{(1-b-d) \\cdot c}{(1-a)(1-d)-bc}$ and $\\theta_2 = \\frac{(1-a-c) \\cdot b}{(1-a)(1-d)-bc}$. \nThis formula reveals that the Leontief matrix allocates demand between the various sector to generate a value added. For example, an increase of $\\delta$ in the demand adressed to sector S1 would generated a value added in sector S1 equal to $(1-\\theta_1) \\cdot \\delta$, and a value added in sector S2 equal to $\\theta_1 \\cdot \\delta$.\n\nWe can now estimate the number of job per unit of final demand. To that end, we define the vector $e$ of job per unit of value added by :\n$(e_i) = (E_i/VA_i)$, where $E_i$ is the number of jobs in sector i and $VA_i$ the value added in sector i.\nThe number of job per unit of domestic demand - which we call domestic employment content $\\pmb{ce}^d$ - is equal to:\n$$(\\pmb{ce^d})^t =\n\\pmb{e}^t \\cdot <va> \\cdot Q \n= \n\\begin{pmatrix} \ne_1 (1-\\theta_1) + e_2 \\theta_1 ;&\ne_1 \\theta_2  + e_2 (1-\\theta_2)\n\\end{pmatrix}\n$$\n\nThis domestic employment content must now be linked to final demand. \nA shift of $\\delta$ in final demand from S1 to S2 leads to a change in domestic demand equals to:\n$$\\pmb{d^d} =\n\\pmb{<1-\\tau_m>} \\cdot \n\\begin{pmatrix} \n-\\delta  \\\\\n\\delta\n\\end{pmatrix} \n=\n\\begin{pmatrix} \n- (1 - \\tau_1) \\\\\n1 - \\tau_2\n\\end{pmatrix} \\cdot \\delta\n$$\n\n\\subsubsection{Impacts of shifting investment}\nAn increase of one million euros in final demand addressed to S2 leads to an increase in jobs equal to:\n$$(1-\\tau_2) \\cdot \\left( (1-\\theta_2) e_2+ \\theta_2 e_1 \\right)$$.\n\nAn decrease of one million euros in final demand addressed to S1 leads to an increase in jobs equal to:\n$$(1-\\tau_1) \\cdot \\left( (1-\\theta_1) e_1+ \\theta_1 e_2 \\right)$$.\n\nA shift in final demand of one million euros from S1 to S2 leads to an increase in employment if and only if:\n$$(1-\\tau_2) \\cdot \\left( (1-\\theta_2) e_2+ \\theta_2 e_1 \\right) > (1-\\tau_1) \\cdot \\left( (1-\\theta_1) e_1+ \\theta_1 e_2 \\right)$$\n\nIt then useful to note that the right parenthesis in each side is the domestic employment content, a weighted average of direct employment intensity. The above equation can be re-written as:\n$$(1-\\tau_2) \\cdot ce^d_2> (1-\\tau_1) \\cdot ce^d_1 $$\nso a shift in final demand generates jobs if an only if the product of the employment content and the import rate is higher.\nBut the computation of the employment content shows that the domestic employment content is high if demand generates value added in sector with a high number of jobs per value added.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\clearpage\n\n\\subsection{Closed economy}\n\\label{app:closed_economy}\n\n\\subsubsection{Overview of the closed model}\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=7cm]{figures/overview_closed.pdf}\n\t\\caption{Overview of the closed economy model for the S2 sector}\n\t\\label{fig:overview_closed}\n\\end{figure}\n\n\\subsubsection{Index of sets}\n\\begin{itemize}\n\t\\item $u$: S1, S2, CAP, LAB, HOH, INV\n\t\\item $i(u)$: S1, S2. Alias: $j(u)$.\n\t\\item $h(u)$: CAP, LAB.\n\\end{itemize}\n\n\\subsubsection{Index of variables}\n\\begin{itemize}\n\t\n\t\\item $Z_j$: output of the j-th good\n\t\\item $F_{h,j}$: the h-th factor input by the j-th firm\n\t\\item $FF_h$: the h-th factor supply\n\t\\item $Inc$: Household income\n\t\\item $C_i$: household consumption of the i-th good\n\t\\item $p^x_i$: demand price of the i-th good\n\t\\item $p^z_i$ supply price of the i-th good\n\t\\item $p^f_h$ the h-th factor price\n\t\\item $pc$ consumption price index\n\t\\item $S^p$: private savings\t\n\t\\item $U$: unemployment rate\n\t\\item $UU$: utility (Cobb-Douglas)\n\\end{itemize}\n\n\\subsubsection{Index of parameters}\n\\begin{itemize}\n\t\\item $\\alpha_i$: share parameter in utility function\n\t\\item $\\sigma^z$: elasticity in CES production function\n\t\\item $\\rho^z = \\frac{\\sigma^z - 1}{\\sigma^z}$: param. in CES production function\n\t\\item $\\delta_{h,j}$ share parameter in CES production function\n\t\\item $scZ_j$: scale parameter in CES production function  \n\t\\item $\\beta_{h,j}$: share parameter in Cobb-Douglas production function\n\t\\item $b_j$: scale parameter in Cobb-Douglas production function\n\t\\item $a_{h,j}$: Leontief coefficient in production function\n\t\\item $\\gamma$: wage curve elasticity\n\t\\item $U^0$: initial unemployment rate\n\\end{itemize}\n\n\n\n\\subsubsection{Tests}\n\n\\paragraph{Walras' law}\nWalras' law allows to take off one equation. \nIn our numerical application, we remove the market clearing of good for the first sector.\nThen, we check after the run that Walras' law is satisfied.\n\n\\paragraph{Numéraire}\nIn our numerical application, we use the price index of consumption goods as the numéraire. \nWe check that the model is not sensitive to this assumption. We increase the numéraire by 10\\% and rerun the model.\nWith this assumption, we check that all prices have increased by 10\\%, and volumes remain the same.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\clearpage\n\n\\subsection{Simple CGE with two labor skills}\n\\label{app:two_labour_model}\n\n\\subsubsection{Overview of the simple CGE with two labor skills}\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=8cm]{figures/overview_twoLabors.pdf}\n\t\\caption{Overview of the open economy model for the S2 sector}\n\t\\label{fig:overview_twoLabors}\n\\end{figure}\n\n\\subsubsection{Index of sets}\n\\begin{itemize}\n\t\\item $u$: S1, S2, CAP, LAB, HOH, INV\n\t\\item $i(u)$: S1, S2. Alias: $j(u)$\n\t\\item $h(u)$: CAP, LAB\n\t\\item $s$: LABL, LABH \n\\end{itemize}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\\clearpage\n\n\\subsection{Open economy}\n\\label{app:open_economy_model}\n\n\\subsubsection{Overview of the open economy}\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=8cm]{figures/overview_open.pdf}\n\t\\caption{Overview of the open economy model for the S2 sector}\n\t\\label{fig:overview_open}\n\\end{figure}\n\n\\subsubsection{Index of sets}\n\\begin{itemize}\n\t\\item $u$: S1, S2, CAP, LAB, HOH, INV, EXT\n\t\\item $i(u)$: S1, S2\n\t\\item $h(u)$: CAP, LAB\n\\end{itemize}\n\n\\subsubsection{Index of variables}\n\\begin{itemize}\n\t\\item $Z_j$: output of the j-th good\n\t\\item $FF_h$: factor supply\n\t\\item $F_{h,j}$: the h-th factor input by the j-th firm\n\t\\item $Inc$: Household income\n\t\\item $C_i$: household consumption of the i-th good\n\t\\item $E_i$:  exports\n\t\\item $M_i$:  imports\n\t\\item $Q_i$:  Armingtons composite good\n\t\\item $D_i$:  domestic good\n\n\t\\item $pf_h$: the h-th factor price\n\t\\item $p^x_i$: consumption price\n\t\\item $p^z_j$: supply price of the i-th good\n\t\\item $p^q_i$: Armingtons composite good price\n\t\\item $p^e_i$: export price in local currency\n\t\\item $p^m_i$: import price in local currency\n\t\\item $p^d_i$: the i-th domestic good price\n\t\\item $\\epsilon$: exchange rate\n\t\\item $p^c$: price index\n\n\t\\item $S^p$: private savings\n\t\\item $S^f$: foreign savings\n\t\\item $U$: unemployment rate\n\t\\item $UU$: utility (Cobb-Douglas)\n\\end{itemize}\n\n\\subsubsection{Index of parameters}\n\\begin{itemize}\n\t\\item $\\alpha^u_i$: share parameter in utility func.\n\t\\item $\\sigma^z$: elasticity in CES production function\n\t\\item $\\rho^z = \\frac{\\sigma^z - 1}{\\sigma^z}$: param. in CES production function\n\t\\item $\\delta_{h,j}$ share parameter in CES production function\n\t\\item $scZ_j$: scale parameter in CES production function  \n\t\\item $\\sigma^q$: elasticity of Armington substitution\n\t\\item $\\rho^q = \\frac{\\sigma^q-1}{\\sigma^q}$: substitution elasticity parameter for Armington\n\t\\item $\\alpha^m_i$: share par. in Armington func.\n\t\\item $\\alpha^d_i$: share par. in Armington func.\n\t\\item $scq_i$: scale par. in Armington func.\n\t\\item $\\gamma$: wage curve elasticity\n\t\\item $U^0$: initial unemployment rate\n\\end{itemize}\n\n\n\\subsubsection{Results for IO and CGE}\n\\label{subsec:open_economy_results}\n\n\\begin{table}[!ht]\n\t\\centering\n\t\\caption{SAM results in an open economy with our IO model}\n\t\\label{tab:SAM_IO_openEconomy}\n\t\\begin{tabular}{llllllll}\n\t\t\\toprule\n\t\t& S1 & S2 &  HOH & INV & EXT \\\\\n\t\t\\midrule\n\t\tS1 &  &   & 8 & 5 & 3 \\\\\n\t\tS2 &  &    & 12 & 3 & 3 \\\\\n\t\tLAB & 9.60 & 8.53 &   &  &  \\\\\n\t\tCAP & 5.33 & 4.74 &   &  &  \\\\\n\t\tEXT & 1.06 & 4.74 &   &  &  \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\n\\begin{table}[!ht]\n\t\\centering\n\t\\caption{Open economy with fixed exchange rate $\\epsilon$ and endogenous imports}\n\t\\label{tab:SAM_IO_OpenEconomy_noBudget}\n\t\\begin{tabular}{llllll}\n\t\t\\toprule\n\t\t& S1 & S2 & HOH & INV & EXT \\\\\n\t\t\\midrule\n\t\tS1 &  &  & 10.96 & 5.00 & 0.00 \\\\\n\t\tS2 &  &  & 16.44 & 3.00 & 0.00 \\\\\n\t\tLAB & 9.41 & 8.59 &  &  &  \\\\\n\t\tCAP & 5.23 & 4.77 &  &  &  \\\\\n\t\tEXT & 1.33 & 6.08 &  &  &  \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\clearpage\n\n\\subsection{Full model}\n\\label{sec:full_model}\n\n\\subsubsection{Data}\n\\label{app:full_model_data}\n\nAt the 64-sector level of disaggregation, we encounter some issues to calibrate the CGE model:\n\\begin{itemize}\n\t\\item Postal services (CPA\\_H53) have negative capital revenues in 2013. Standard production functions with constant elasticity of substitution cannot account for a negative capital revenue. \n\tSince this sector is not crucial for our analysis of green jobs, we aggregate it with the other transportation service (CPA\\_H50, CPA\\_H51 and CPA\\_H52).\n\t\\item The \"Manufacture of textiles, wearing apparel and leather products\" sector (CPA\\_C13-15) and \"Computer, electronic and optical products\" sector (CPA\\_C26) export more than they produce. To avoid issues with negative values in the calibration of trade within the constant elasticity of transformation (CET) function, we aggregate the textile and leather products with \"Manufacture of wood and of products of wood\" (CPA\\_C16) and computers with electrical equipment (CPA\\_C27)\n\t\\item The \"imputed rent\" sector (CPA\\_L68A) indicates a low but positive remuneration for employees, but no employee. This would lead to an infinite salary. We aggregate this sector with the other real estate services (CPA\\_L68B)\n\\end{itemize}\n\n\n\n\\subsubsection{Overview of the full CGE model}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[width=14cm]{figures/overview_full.pdf}\n\t\\caption{Overview of the fully-fledged model for the S2 sector}\n\t\\label{fig:overview_full}\n\\end{figure}\n\n\\subsubsection{Index of sets}\n\\begin{itemize}\n\t\\item u: SAM entry     /S1*S58, CAP, LAB, IDT, TRF, HOH, GOV,\n\t\\item i(u): goods         /S1*S58/\n\t\\item h(u): factor        /CAP, LAB/\n\t\\item s: labor skill   / highSkill, lowSkill /\n\\end{itemize}\n\n\\subsubsection{Index of variables}\n\\begin{itemize} \n\t\\item $Y_j$: composite factor\n\t\\item $Inc$: household income\n\t\\item $N(s,j)$: worker input by skill\n\t\\item $K_j$: capital factor input by the j-th firm\n\t\\item $L_j$: labor input      \n\t\\item $KK$: capital supply\n\t\\item $NN(s)$: worker supply\n\t\\item $X(i,j)$: intermediate input\n\t\\item $Z_j$: output of the j-th good\n\t\\item $C_i$: household consumption of the i-th good\n\t\\item $G_i$: government consumption\n\t\\item $I_i$: investment\n\t\\item $E_i$: exports\n\t\\item $M_i$: imports\n\t\\item $Q_i$: Armington composite good\n\t\\item $D_i$: domestic good\n\n\t\\item $p^k$: capital factor price\n\t\\item $p^l_j$: labor price\n\t\\item $p^n_s$: workers price\n\t\\item $p^y_j$: composite factor price\n\t\\item $p^z_j$: supply price of the i-th good\n\t\\item $p^q_i$: Armingtons composite good price\n\t\\item $p^e_i$: export price in local currency\n\t\\item $p^m_i$: import price in local currency\n\t\\item $p^d_i$: the i-th domestic good price\n\t\\item $\\epsilon$: exchange rate\n\n\t\\item $S^p$: private saving\n\t\\item $S^g$: government saving\n\t\\item $S^f$: foreign saving\n\t\\item $T^d$: direct tax\n\t\\item $T^z_j$: production tax\n\t\\item $T^p$: private consumption tax\n\t\\item $T^v$: investment tax\n\n\t\\item $KK$: capital supply\n\t\\item $NN_s$: labor supply\n\t\\item $pc$: consumption price\n\n\t\\item $UU$: utility (Cobb-Douglas)\n\\end{itemize}\n\n\\subsubsection{Index of parameters}\n\\begin{itemize}\n\t\\item $\\sigma^Y$: elasticity of substitution in composite factor production\n\t\\item $\\rho^Y = \\frac{\\sigma^Y - 1}{\\sigma^Y}$: substitution elasticity parameter for capital-labor composite\n\t\\item $\\sigma_i$: elasticity of Armington substitution\n\t\\item $\\eta_i = \\frac{\\sigma^z - 1}{\\sigma^z}$: substitution elasticity parameter for Armington\n\t\\item $\\psi_i$: elasticity of transformation\n\t\\item $\\phi_i= \\frac{\\psi^z - 1}{\\psi^z}$: transformation elasticity parameter\n\t\\item $\\alpha_i$: share parameter in utility func.\n\t\\item $\\delta^l_j$: labor share   in CES prod. func.\n\t\\item $\\delta^k_j$: capital share in CES prod. func.\n\t\\item $scY$: scale param.  in CES prod. func.\n\t\\item $\\beta\\_N(s,j)$: share parameter in labor function\n\t\\item $scL_j$: scale parameter in labor function\n\t\\item $ax(i,j)$: intermediate input requirement coeff.\n\t\\item $ay_j$:  composite fact. input req. coeff.\n\t\\item $\\mu_i$:  government consumption share\n\t\\item $\\lambda_i$: investment demand share\n\t\\item $\\delta^m_i$: share par. in Armington func.\n\t\\item $\\delta^d_i$: share par. in Armington func.\n\t\\item $scQ_i$: scale par. in Armington func.\n\t\\item $\\xi^d_i$: share par. in transformation func.\n\t\\item $\\xi^e_i$: share par. in transformation func.\n\t\\item $\\theta_i$: scale par. in transformation func.\n\t\\item $ssg$: average propensity for gov. saving\n\t\\item $\\tau^d$: direct tax rate\n\t\\item $Pop$: population (labor force)\n\t\\item $U^0_s$: initial unemployment\n\t\\item $p^{We}_i$: export price in US dollars\n\t\\item $p^{Wm}_i$: import price in US dollars\n\t\\item $\\tau^z_i$: production tax rate\n\t\\item $\\tau^p$: private consumption tax rate\n\t\\item $\\tau^v$: investment tax\n\t\\item $Pop$: population (labor force)\n\t\\item $\\gamma$: wage curve elasticity\n\\end{itemize}\n\n\n\n\\begin{table}[!ht]\n\t\\centering\n\t\\caption{Comparative equations of IO and CGE models. Identical equations are not repeated to facilitate reading. The main differences with the closed version shown in table \\ref{tab:closedModel} have their equations labeled in bold.}\n\t\\label{tab:fullModel}\n\t\\begin{tabular}{llll}\n\t\t\\toprule\n\t\tNum & Description & Standard CGE  \\\\\n\t\t\\midrule\n\t\teq1 & Production function & $Y_j    = scY_j \\cdot  ( \\delta^k_j \\cdot K_j^{\\rho_Y} + \\delta^l_j \\cdot L_j^{\\rho_Y} )^{1/\\rho_Y}$ \\\\\n\t\teq2 & Capital demand & $ K_j = (scY_j^{\\rho_Y} \\cdot  \\delta^k_j \\cdot  p^y_j / p^k )^{\\sigma_Y} \\cdot  Y_j $ \\\\\n\t\teq3 & Labor demand  & $L_j = (scY_j^{\\rho_Y} \\cdot \\delta^l_j \\cdot  p^y_j / p^l_j )^{\\sigma_Y} \\cdot Y_j $ \\\\\t\n\t\teq4 & Demand of intermediate goods & $X_{i,j}  = ax_{i,j} \\cdot Z_j$ \\\\\n\t\teq5 & Demand of composite factor & $Y_j    = ay_j \\cdot Z_j$ \\\\\n\t\teq6 & Condition of zero profit & $p^z_j   = ay_j \\cdot p^y_j + \\sum_i ax_{i,j} \\cdot p^q_i$ \\\\\n\t\teq7 & Production of labor composite & $L_j    = scL_j \\cdot  \\prod_s N_{s,j}^{\\beta^N_{s,j}}$  \\\\\n\t\teq8 & Demand of labor by skill & $N_{s,j}  = \\beta^N_{s,j} \\cdot p^l_j \\cdot  L_j / p^n_s$ \\\\\n\t\teq9 & Unemployment & $ U_s =  1 - NN_s/Pop_s $\\\\\n\t\teq10 & Labor supply & $\\log( p^n_s / p^c ) = - \\gamma \\cdot  log(\\frac{U_s}{U^0_s}) $  \\\\\n\t\teq11 & Capital supply & $KK = \\overline{KK} $  \\\\\n\t\t\\midrule\n\t\teq12 & Direct tax on household & $T^d = \\tau^d \\cdot Inc $\\\\\n\t\teq13 & Tax on production & $T^z_j = \\tau^z_j \\cdot p^z_j \\cdot Z_j$ \\\\\n\t\teq14 & Tax on household consumption & $T^p = \\tau^p \\cdot \\sum_j  p^q_j \\cdot C_j $ \\\\\n\t\teq15 & Tax on investment & $T^v = \\tau^v \\cdot \\sum_j p^q_j\\cdot I_j $ \\\\\n\t\teq16 & Government consumption & $G_i = \\mu_i ~ ( T^d + \\sum_j T^z_j + T^p + T^v - S^g ) / p^q_i$ \\\\\n\t\t\\midrule\n\t\teq17 & Private savings & $S^p = \\sum_i (1+\\tau^v) \\cdot p^q_i \\cdot I_i - S^g - \\epsilon \\cdot S^f$ \\\\\n\t\teq18 & Government savings & $S^g = ssg \\cdot  (T^d + \\sum_j T^z_j + T^p + T^v)$ \\\\\n\t\t\\midrule\n\t\teq19 & Household income &  $Inc = p^k \\cdot KK + \\sum_s p^n_s \\cdot NN_s $ \\\\\n\t\teq20 & Houshold consumption & $C_i = \\alpha_i \\cdot  (Inc -S^p - T^d) / ((1+\\tau^p) ~ p^q_i) $ \\\\\n\t\t\\midrule\n\t\teq21 & Export demand & $p^e_i = \\epsilon \\cdot pWe_i$ \\\\\n\t\teq22 & Import supply & $p^m_i =\\epsilon \\cdot p^{Wm}_i$ \\\\\n\t\teq23 & Balance of trade & $\\sum_i p^{We}_i \\cdot E_i +S^f = \\sum_i p^{Wm}_i \\cdot M_i$ \\\\\n\t\teq24 & Trade closure & $S^f = \\overline{S^f}$  \\quad OR \\quad $\\epsilon = \\overline{\\epsilon}$  \\\\\n\t\t\\midrule\n\t\teq25 & Armington function & $Q_i = scQ_i \\cdot (\\alpha^m_i M_i^{\\rho_Q} + \\alpha^d_i D_i^{\\rho_Q}  )^{1/\\rho_Q} $ \\\\\n\t\teq26 & Imports demand & $M_i = \\left( scQ_i^{\\rho_Q} \\cdot \\alpha_i^m \\cdot \\frac{p_i^q}{p_i^m} \\right)^{\\sigma_Q} Q_i$ \\\\\n\t\teq27& Domestic demand & $D_i = \\left( scQ_i^{\\rho_Q} \\cdot \\alpha_i^d \\cdot \\frac{p_i^q}{p_i^d} \\right)^{\\sigma_Q} Q_i$ \\\\\n\t\teq28 & CET function & $Z_i  = \\theta_i \\cdot  (\\xi^e_i \\cdot E_i^{\\phi_i} + \\xi^d_i \\cdot D_i^{\\phi_i} )^{(1/\\phi_i)} $  \\\\\n\t\teq29 & Demand of E & $  E_i = (\\theta_i^{\\phi_i} \\cdot \\xi^e_i\\cdot (1+\\tau^z_i) ~ p^z_i/p^e_i)^{(1/(1-\\phi_i))} ~Z_i $ \\\\\n\t\teq30 & Demand of D & $ D_i = (\\theta_i^{\\phi_i} \\cdot \\xi^d_i \\cdot (1+\\tau^z_i) ~ p^z_i/p^d_i)^{(1/(1-\\phi_i))} ~ Z_i $ \\\\\n\t\t\\midrule\n\t\teq31 &  Balance of domestic good & $Q_i = C_i + I_i$ &  \\\\\n\t\teq32 & Balance of labor & $NN_s = \\sum_j N_{s,j}$ &   \\\\\n\t\teq33 & Balance of capital & $KK  = \\sum_j K_j $ &   \\\\\n\t\teq34 & Price equality & $p^c_i = p^z_i$ & \\\\ \n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\clearpage\n\n\\subsubsection{Cobb-Douglas elasticity vs Empirical estimates}\n\n\\begin{table}[!ht]\n\t\\centering\n\t\\caption{Comparing job creation using CES vs Cobb-Douglas \\\\\\hspace{\\textwidth} (for a wage curve elasticity $\\gamma$=0.1, $\\sigma_{Armington}$ =2  and $\\psi_{CET}$=2)}\n\t\\label{tab:CobbDouglasError}\n\t\\begin{tabular}{lcccc}\n\t\t\\toprule\n\t\tTechno & Elasticité  &  Value & Value & Error (\\%) \\\\\n\t    & $\\sigma_{KL}$ &  with CES & with Cobb-Douglas& Cobb-Douglas vs CES \\\\\n\t\t\\midrule \n\t\tSolar & 0.2 &  5858 & 3542 & -40 \\\\\nSolar & 0.3 &5394 & 3542 & -34 \\\\\nSolar & 0.4 & 5003 & 3542 & -29 \\\\\nSolar & 0.5 & 4670 & 3542 & -24 \\\\\nSolar & 0.6 & 4382 & 3542 & -19 \\\\\nWeatherization & 0.2 & 6589 & 4135 & -37 \\\\\nWeatherization & 0.3 & 6097 & 4135 & -32 \\\\\nWeatherization & 0.4 & 5683 & 4135 & -27 \\\\\nWeatherization & 0.5 & 5331 & 4135 & -22 \\\\\nWeatherization & 0.6 & 5026 & 4135 & -18 \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\clearpage\n\n\\subsubsection{Trade}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=4cm]{figures/Armington.pdf}\n\t\\caption{Impact of the Armington elasticity (with CET elasticity equal to two)}\n\t\\label{fig:armington}\n\\end{figure}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=4cm]{figures/CET.pdf}\n\t\\caption{Impact of the CET elasticity (with Armington elasticity equal to two)}\n\t\\label{fig:cet}\n\\end{figure}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[height=4cm]{figures/closure.pdf}\n\t\\caption{Impact of the trade closure rule}\n\t\\label{fig:closure}\n\\end{figure}\n\n\\subsubsection{Full sensitivity analysis}\n\\label{sec:full_sensitivity}\n\n\\begin{table}\n\t\\small\n\t\\centering\n\t\\caption{Full sensitivity analysis for solar }\n\t\\begin{tabular}{cccccccc}\n\t\t\\toprule\n\t\tTechno & $\\gamma$ & $\\sigma_{KL}$ & $\\sigma_{\\text{Armington}}$ & $\\psi_{\\text{CET}}$ & Jobs in CGE &Jobs in IO & Ratio \\\\\n\t\t\\midrule\n\t\tSolar & 0.1 & 0.2 & 1.5 & 1.5 & 6035 & 5010 & 0.83 \\\\\n\t\tSolar & 0.1 & 0.2 & 1.5 & 2 & 5945 & 5010 & 0.84 \\\\\n\t\tSolar & 0.1 & 0.2 & 1.5 & 4 & 5612 & 5010 & 0.89 \\\\\n\t\tSolar & 0.1 & 0.2 & 1.5 & 6 & 5314 & 5010 & 0.94 \\\\\n\t\tSolar & 0.1 & 0.2 & 2 & 1.5 & 5945 & 5010 & 0.84 \\\\\n\t\tSolar & 0.1 & 0.2 & 2 & 2 & 5858 & 5010 & 0.86 \\\\\n\t\tSolar & 0.1 & 0.2 & 2 & 4 & 5534 & 5010 & 0.91 \\\\\n\t\tSolar & 0.1 & 0.2 & 2 & 6 & 5244 & 5010 & 0.96 \\\\\n\t\tSolar & 0.1 & 0.2 & 4 & 1.5 & 5613 & 5010 & 0.89 \\\\\n\t\tSolar & 0.1 & 0.2 & 4 & 2 & 5535 & 5010 & 0.91 \\\\\n\t\tSolar & 0.1 & 0.2 & 4 & 4 & 5245 & 5010 & 0.96 \\\\\n\t\tSolar & 0.1 & 0.2 & 4 & 6 & 4984 & 5010 & 1.01 \\\\\n\t\tSolar & 0.1 & 0.2 & 6 & 1.5 & 5316 & 5010 & 0.94 \\\\\n\t\tSolar & 0.1 & 0.2 & 6 & 2 & 5247 & 5010 & 0.95 \\\\\n\t\tSolar & 0.1 & 0.2 & 6 & 4 & 4985 & 5010 & 1.00 \\\\\n\t\tSolar & 0.1 & 0.2 & 6 & 6 & 4748 & 5010 & 1.06 \\\\\n\t\tSolar & 0.1 & 0.4 & 1.5 & 1.5 & 5130 & 5010 & 0.98 \\\\\n\t\tSolar & 0.1 & 0.4 & 1.5 & 2 & 5066 & 5010 & 0.99 \\\\\n\t\tSolar & 0.1 & 0.4 & 1.5 & 4 & 4823 & 5010 & 1.04 \\\\\n\t\tSolar & 0.1 & 0.4 & 1.5 & 6 & 4603 & 5010 & 1.09 \\\\\n\t\tSolar & 0.1 & 0.4 & 2 & 1.5 & 5066 & 5010 & 0.99 \\\\\n\t\tSolar & 0.1 & 0.4 & 2 & 2 & 5003 & 5010 & 1.00 \\\\\n\t\tSolar & 0.1 & 0.4 & 2 & 4 & 4766 & 5010 & 1.05 \\\\\n\t\tSolar & 0.1 & 0.4 & 2 & 6 & 4551 & 5010 & 1.10 \\\\\n\t\tSolar & 0.1 & 0.4 & 4 & 1.5 & 4824 & 5010 & 1.04 \\\\\n\t\tSolar & 0.1 & 0.4 & 4 & 2 & 4767 & 5010 & 1.05 \\\\\n\t\tSolar & 0.1 & 0.4 & 4 & 4 & 4552 & 5010 & 1.10 \\\\\n\t\tSolar & 0.1 & 0.4 & 4 & 6 & 4355 & 5010 & 1.15 \\\\\n\t\tSolar & 0.1 & 0.4 & 6 & 1.5 & 4605 & 5010 & 1.09 \\\\\n\t\tSolar & 0.1 & 0.4 & 6 & 2 & 4553 & 5010 & 1.10 \\\\\n\t\tSolar & 0.1 & 0.4 & 6 & 4 & 4356 & 5010 & 1.15 \\\\\n\t\tSolar & 0.1 & 0.4 & 6 & 6 & 4175 & 5010 & 1.20 \\\\\n\t\tSolar & 0.1 & 0.6 & 1.5 & 1.5 & 4480 & 5010 & 1.12 \\\\\n\t\tSolar & 0.1 & 0.6 & 1.5 & 2 & 4430 & 5010 & 1.13 \\\\\n\t\tSolar & 0.1 & 0.6 & 1.5 & 4 & 4244 & 5010 & 1.18 \\\\\n\t\tSolar & 0.1 & 0.6 & 1.5 & 6 & 4073 & 5010 & 1.23 \\\\\n\t\tSolar & 0.1 & 0.6 & 2 & 1.5 & 4431 & 5010 & 1.13 \\\\\n\t\tSolar & 0.1 & 0.6 & 2 & 2 & 4382 & 5010 & 1.14 \\\\\n\t\tSolar & 0.1 & 0.6 & 2 & 4 & 4200 & 5010 & 1.19 \\\\\n\t\tSolar & 0.1 & 0.6 & 2 & 6 & 4033 & 5010 & 1.24 \\\\\n\t\tSolar & 0.1 & 0.6 & 4 & 1.5 & 4245 & 5010 & 1.18 \\\\\n\t\tSolar & 0.1 & 0.6 & 4 & 2 & 4201 & 5010 & 1.19 \\\\\n\t\tSolar & 0.1 & 0.6 & 4 & 4 & 4034 & 5010 & 1.24 \\\\\n\t\tSolar & 0.1 & 0.6 & 4 & 6 & 3879 & 5010 & 1.29 \\\\\n\t\tSolar & 0.1 & 0.6 & 6 & 1.5 & 4075 & 5010 & 1.23 \\\\\n\t\tSolar & 0.1 & 0.6 & 6 & 2 & 4035 & 5010 & 1.24 \\\\\n\t\tSolar & 0.1 & 0.6 & 6 & 4 & 3880 & 5010 & 1.29 \\\\\n\t\tSolar & 0.1 & 0.6 & 6 & 6 & 3737 & 5010 & 1.34 \\\\\n\t\t\\bottomrule\n\t\t\\end{tabular}\n\\end{table}\t\n\n\\begin{table}\n\t\\small\n\t\t\\centering\n\t\t\\caption{Full sensitivity analysis for weatherization}\n\t\t\\begin{tabular}{cccccccc}\n\t\t\\toprule\n\t\t\tTechno & $\\gamma$ & $\\sigma_{KL}$ & $\\sigma_{\\text{Armington}}$ & $\\psi_{\\text{CET}}$ & Jobs in CGE &Jobs in IO & Ratio \\\\\n\t\t\\midrule\n\t\tWeatherization & 0.1 & 0.2 & 1.5 & 1.5 & 6782 & 8050 & 1.19 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 1.5 & 2 & 6684 & 8050 & 1.20 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 1.5 & 4 & 6321 & 8050 & 1.27 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 1.5 & 6 & 5997 & 8050 & 1.34 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 2 & 1.5 & 6683 & 8050 & 1.20 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 2 & 2 & 6589 & 8050 & 1.22 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 2 & 4 & 6237 & 8050 & 1.29 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 2 & 6 & 5921 & 8050 & 1.36 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 4 & 1.5 & 6321 & 8050 & 1.27 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 4 & 2 & 6236 & 8050 & 1.29 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 4 & 4 & 5921 & 8050 & 1.36 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 4 & 6 & 5637 & 8050 & 1.43 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 6 & 1.5 & 5998 & 8050 & 1.34 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 6 & 2 & 5922 & 8050 & 1.36 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 6 & 4 & 5638 & 8050 & 1.43 \\\\\n\t\tWeatherization & 0.1 & 0.2 & 6 & 6 & 5380 & 8050 & 1.50 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 1.5 & 1.5 & 5824 & 8050 & 1.38 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 1.5 & 2 & 5753 & 8050 & 1.40 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 1.5 & 4 & 5486 & 8050 & 1.47 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 1.5 & 6 & 5244 & 8050 & 1.54 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 2 & 1.5 & 5753 & 8050 & 1.40 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 2 & 2 & 5683 & 8050 & 1.42 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 2 & 4 & 5423 & 8050 & 1.48 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 2 & 6 & 5187 & 8050 & 1.55 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 4 & 1.5 & 5486 & 8050 & 1.47 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 4 & 2 & 5423 & 8050 & 1.48 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 4 & 4 & 5187 & 8050 & 1.55 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 4 & 6 & 4971 & 8050 & 1.62 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 6 & 1.5 & 5245 & 8050 & 1.53 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 6 & 2 & 5188 & 8050 & 1.55 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 6 & 4 & 4972 & 8050 & 1.62 \\\\\n\t\tWeatherization & 0.1 & 0.4 & 6 & 6 & 4774 & 8050 & 1.69 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 1.5 & 1.5 & 5135 & 8050 & 1.57 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 1.5 & 2 & 5080 & 8050 & 1.58 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 1.5 & 4 & 4873 & 8050 & 1.65 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 1.5 & 6 & 4684 & 8050 & 1.72 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 2 & 1.5 & 5080 & 8050 & 1.58 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 2 & 2 & 5026 & 8050 & 1.60 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 2 & 4 & 4824 & 8050 & 1.67 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 2 & 6 & 4639 & 8050 & 1.74 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 4 & 1.5 & 4873 & 8050 & 1.65 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 4 & 2 & 4824 & 8050 & 1.67 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 4 & 4 & 4639 & 8050 & 1.74 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 4 & 6 & 4468 & 8050 & 1.80 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 6 & 1.5 & 4684 & 8050 & 1.72 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 6 & 2 & 4640 & 8050 & 1.74 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 6 & 4 & 4469 & 8050 & 1.80 \\\\\n\t\tWeatherization & 0.1 & 0.6 & 6 & 6 & 4310 & 8050 & 1.87 \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n", "meta": {"hexsha": "cabba4ea7cf84fe1b629becc27cfba261ab261da", "size": 26151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter4/appendix.tex", "max_stars_repo_name": "QPerrier/Dissertation", "max_stars_repo_head_hexsha": "bf7382137cee951292aa7fb0404b9075d7d2a2eb", "max_stars_repo_licenses": ["MTLL"], "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/appendix.tex", "max_issues_repo_name": "QPerrier/Dissertation", "max_issues_repo_head_hexsha": "bf7382137cee951292aa7fb0404b9075d7d2a2eb", "max_issues_repo_licenses": ["MTLL"], "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/appendix.tex", "max_forks_repo_name": "QPerrier/Dissertation", "max_forks_repo_head_hexsha": "bf7382137cee951292aa7fb0404b9075d7d2a2eb", "max_forks_repo_licenses": ["MTLL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.6828528073, "max_line_length": 481, "alphanum_fraction": 0.6260181255, "num_tokens": 10425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355186, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6121536817309697}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%\n\\section{Discussion}\n\\label{sec:Discussion}\n%%%%%%%%%%%%%%%%%%%%%%\n\nWe have addressed the problem of characterizing the loss surface of neural networks from the perspective\nof gradient descent algorithms. We explored two angles -- topological and geometrical aspects -- that build on top of each other. \n\n\nOn the one hand, we have presented new theoretical results that quantify \nthe amount of uphill climbing that is required in order to progress to lower energy configurations in \nsingle hidden-layer ReLU networks, and proved that this amount converges to zero with overparametrization under mild conditions. On the other hand, we have introduced a dynamic programming algorithm that efficiently approximates geodesics within each level set, providing a tool that not only verifies the connectedness of level sets, but also estimates the geometric regularity of these sets. Thanks to this information, we can quantify how `non-convex' an optimization problem is, and verify that the optimization of quintessential deep learning tasks -- CIFAR-10 and MNIST classification using CNNs, and next word prediction using LSTMs -- behaves in a nearly convex fashion up until they reach high accuracy levels.\n\nThat said, there are some limitations to our framework. In particular, we do not address saddle-point issues that can greatly affect the actual convergence of gradient descent methods. There are also a number of open questions; amongst those, in the near future we shall concentrate on:\n\\begin{itemize}\n\\item \\emph{Extending Theorem \\ref{maintheo} to the multilayer case}. We believe this is within reach, since the main analytic tool we use is that small changes in the parameters result in small changes in the covariance structure of the features. That remains the case in the multilayer case. \n\\item \\emph{Empirical versus Oracle Risk}. A big limitation of our theory is that right now it does not inform us on the differences between optimizing the empirical risk versus the oracle risk. Understanding the impact of generalization error and stochastic gradient in the ability to do small uphill climbs is an open line of research.\n\\item \\emph{Influence of symmetry groups}.  Under appropriate conditions, the presence of discrete symmetry groups does not prevent the loss from being connected, but at the expense of increasing the capacity. An important open question is whether one can improve the asymptotic properties by relaxing connectedness to being connected up to discrete symmetry. \n\\item \\emph{Improving numerics with Hyperplane method}. Our current numerical experiments employ a greedy (albeit faster) algorithm to discover connected components and estimate geodesics. We plan to perform experiments using the less greedy algorithm described in Appendix \\ref{sec:ConstrainedAlg}. \n\\end{itemize}\n \n\n%\\begin{itemize}\n%\\item Future: Generalization Error Question. \n%\n%\\end{itemize}\n", "meta": {"hexsha": "cea5ceb75e514d2f54240c324840c2524c47a353", "size": 2946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writeup/iclr/conclusions.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/conclusions.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/conclusions.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": 105.2142857143, "max_line_length": 719, "alphanum_fraction": 0.7942973523, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6121536779564773}}
{"text": "\n\\section{Flow over a smooth downward step}\n\nThis is a standard textbook energy conservation type problem. Water flows over a flat bedded channel, then through a smooth downward step, and continues over a flat bottomed channel with lower bed elevation.\n\nThe bed is represented with a one dimensional domain over $[0,25]$ m, with topography\n\\begin{equation}\nz(x)= \\left\\{ \\begin{array}{ll}\n 0.2 & ~\\textrm{if}\\quad x \\leq 9 ,,\\\\\n 0.2-0.1(x-9) & ~\\textrm{if}\\quad 9 \\leq x \\leq 11\\,,\\\\\n 0 & ~\\textrm{otherwise}\\,,\\\\\n\\end{array} \\right.\n\\end{equation}\nThe stage is imposed at the downstream boundary, and the discharge is imposed at the upstream boundary.\n\nThe analytical height is found by solving the Bernoulli equation. The simplified Bernoulli equation is the following cubic equation\n\\begin{equation}\nh^3 + \\left(z - \\frac{q^2}{2 g H^2} - H \\right) h^2 + \\frac{q^2}{2 g} = 0\\,,\n\\end{equation}\nwhere $H$ is the upstream height and $q=uh$ is the discharge or $x$-momentum. When the height $h$ has been found, the velocity is computed as $u=q/h$\\,.\n\n\\subsection{Results}\nFor our test we impose a discharge-per-unit-width of 1m$^2$/s, and a downstream stage boundary condition of 1.0m. \n\nRepresentatives of the simulation results are given in the following three figures. The boundary regions are excluded from the plot because the inflow boundary takes some time to adapt to the analytical solution (which is to be expected as we don't enforce the depth or velocity directly there). There should be excellent agreement between the numerical and analytical solutions. \n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{stage_plot.png}\n\\end{center}\n\\caption{Stage results}\n\\end{figure}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{xmom_plot.png}\n\\end{center}\n\\caption{Xmomentum results}\n\\end{figure}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{xvel_plot.png}\n\\end{center}\n\\caption{Xvelocity results}\n\\end{figure}\n\n\n\\endinput\n", "meta": {"hexsha": "94d76ac614bcd92175e91e910b612f9fad7a2fb6", "size": 1992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/subcritical_depth_expansion/results.tex", "max_stars_repo_name": "samcom12/anuga_core", "max_stars_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_stars_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_stars_count": 136, "max_stars_repo_stars_event_min_datetime": "2015-05-07T05:47:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T03:07:40.000Z", "max_issues_repo_path": "validation_tests/analytical_exact/subcritical_depth_expansion/results.tex", "max_issues_repo_name": "samcom12/anuga_core", "max_issues_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_issues_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-05-03T09:27:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T04:22:48.000Z", "max_forks_repo_path": "validation_tests/analytical_exact/subcritical_depth_expansion/results.tex", "max_forks_repo_name": "samcom12/anuga_core", "max_forks_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_forks_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-03-18T07:35:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T07:07:29.000Z", "avg_line_length": 38.3076923077, "max_line_length": 380, "alphanum_fraction": 0.75, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6121536658571924}}
{"text": "% Created 2021-07-14 Wed 11:54\n% Intended LaTeX compiler: pdflatex\n\\documentclass[presentation,aspectratio=169]{beamer}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble}\n\\usepackage{amssymb}\n\\usepackage{pgfplotstable}\n\\DeclareMathOperator{\\shift}{q}\n\\DeclareMathOperator{\\diff}{p}\n\\usetheme{default}\n\\author{Kjartan Halvorsen}\n\\date{\\today}\n\\title{System identification}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={System identification},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.4.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Intro}\n\\label{sec:org2f040f4}\n\\begin{frame}[label={sec:org0fdcf79}]{A complicated process}\n\\begin{columns}\n\\begin{column}{0.6\\columnwidth}\nFrom Wikipedia \"Cyclonic separation\"\n\\end{column}\n\\begin{column}{0.4\\columnwidth}\n\\begin{center}\n\\includegraphics[height=1.0\\textheight]{../../figures/Vertical-cyclone.jpg}\n\\end{center}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\\begin{frame}[label={sec:org5066307}]{System identification}\n\\begin{center}\n  \\begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm, inner sep=10pt}, sumnode/.style={circle, draw, inner sep=2pt},]\n\n    \\node[coordinate] (input) {};\n    \\node[coordinate, right of=input] (copy) {};\n    \\node[coordinate, right of=copy] (midp) {};\n    \\node[block, above of=midp, node distance=10mm] (sys)  {System};\n    \\node[block, below of=midp, node distance=10mm] (mod)  {Model};\n    \\node[sumnode, right of=midp, node distance=26mm] (sum) {\\tiny $\\Sigma$};\n    \\node[coordinate, right of=sum, node distance=22mm] (output) {};\n\n    \\draw[-] (input) -- node[above, pos=0.2] {Measured input} (copy);\n    \\draw[->] (copy) |- node[above] {} (sys);\n    \\draw[->] (copy) |- node[above] {} (mod);\n    \\draw[->] (sys) -| node[left, pos=0.9] {$+$} (sum);\n    \\draw[->] (mod) -| node[left, pos=0.9] {$-$} (sum);\n    \\draw[->] (sum) -- node[above, near end] {Error} (output);\n\n    \\draw[thick, red!70!black, ->] (2.7,-2) -- (3.3,-2) -- (5.3, 0);\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\n\\begin{frame}[label={sec:orgbf66964}]{The Auto-Regressive with eXogenous input (ARX) model}\n\\begin{center}\n\\includegraphics[width=0.7\\linewidth]{../../figures/block-arx}\n\\end{center}\n\\[ A(\\shift) y(k) = B(\\shift)u(k) + e(k+n) \\]\n\nThe error signal \\(e(k)\\) is a zero-mean white noise sequence representing perturbations and modeling errors.\n\\end{frame}\n\n\\begin{frame}[label={sec:org43fbae7}]{First-order ARX model with one delay}\n\\begin{center}\n\\includegraphics[width=0.3\\linewidth]{../../figures/block-arx}\n\\end{center}\n\\[ (\\shift + a_1) y(k) = (b_0 \\shift + b_1) \\shift^{-1}u(k) + e(k+1) \\]\n\\[ y(k+1) +  a_1y(k) = b_0u(k) + b_1u(k-1) + e(k+1) \\]\n\n\\pause\n\nUsing the model to predict the output one step ahead:\n\\begin{align*}\n \\hat{y}(k+1) &= -a_1y(k) + b_0u(k) + b_1u(k-1) =  \\underbrace{\\begin{bmatrix} -y(k) & u(k) & u(k-1) \\end{bmatrix}}_{\\varphi_{k+1}^T} \\underbrace{\\begin{bmatrix} a_1\\\\b_0\\\\b_1\\end{bmatrix}}_{\\theta}\\\\\n &= \\varphi_{k+1}^T\\theta\n \\end{align*}\n\\end{frame}\n\n\n\n\\begin{frame}[label={sec:org82bc73b}]{Parameter estimation - Least squares}\n\\alert{Objective} Given observations \\[\\mathcal{D} = \\{ (u_1,y_1), (u_2, y_2), \\ldots, (u_N, y_N)\\}\\] and model \\(\\mathcal{M}: \\; y(k+1) = -ay(k) + b_0u(k) + b_1u(k-1)  + e(k+1)\\), obtain the parameters \\((a_1,\\,b_0,\\,b_1)\\) which gives the best fit of the model to the data.\n\\end{frame}\n\n\n\n\\begin{frame}[label={sec:orgee9dfe7}]{Parameter estimation - Least squares}\nGiven observations \\[\\mathcal{D} = \\{ (u_1,y_1), (u_2, y_2), \\ldots, (u_N, y_N)\\}\\] and model \\(\\mathcal{M}: \\; y(k+1) = -ay(k) + b_0u(k) + b_1u(k-1)  + e(k+1)\\).\n\n\\begin{enumerate}\n\\item Form the one-step ahead prediction\n\\[ \\hat{y}_{k+1} = -a_1y_k + b_0u_k + b_1u_{k-1} =  \\underbrace{\\begin{bmatrix} -y_k & u_k & u_{k-1} \\end{bmatrix}}_{\\varphi_{k+1}^T} \\underbrace{\\begin{bmatrix} a_1\\\\b_0\\\\b_1\\end{bmatrix}}_{\\theta}\\] and the prediction error\n   \\[ \\epsilon_{k+1} = y_{k+1} - \\hat{y}_{k+1} = y_{k+1} - \\varphi_{k+1}^T\\theta.\\]\n\\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:orgd1a0844}]{Parameter estimation - Least squares}\n\\begin{enumerate}\n\\setcounter{enumi}{1}\n\\item Combine all the observations \\(y_k\\) and predictions \\(\\hat{y}_k\\) on vector form\n\\begin{align*}\n\\epsilon &= \\begin{bmatrix} \\epsilon_3\\\\\\epsilon_4\\\\\\vdots\\\\\\epsilon_N\\end{bmatrix} =  \\begin{bmatrix} y_3\\\\ y_4\\\\\\vdots\\\\y_N \\end{bmatrix} - \\begin{bmatrix} \\hat{y}_3\\\\ \\hat{y}_4\\\\\\vdots\\\\\\hat{y}_N \\end{bmatrix}\n =  \\begin{bmatrix} y_2\\\\ y_3\\\\\\vdots\\\\y_N \\end{bmatrix} - \\begin{bmatrix} \\varphi_2^T\\theta\\\\ \\varphi_3^T\\theta\\\\\\vdots\\\\\\varphi_N^T\\theta \\end{bmatrix}\\\\\n&= y - \\underbrace{\\begin{bmatrix}\\varphi_1^T\\\\\\varphi_2^T\\\\\\vdots\\\\\\varphi_N^T\\end{bmatrix}}_{\\Phi}\\theta = y - \\Phi\\theta \n\\end{align*}\n\\item Solve \\(\\arg\\min \\; J(\\theta) = \\frac{1}{2}\\epsilon^T\\epsilon = \\frac{1}{2}\\sum_{i=3}^N \\epsilon_i(\\theta)^2\\)\n\\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org6ce2d0d}]{The problem with least squares}\n\\begin{columns}\n\\begin{column}{0.4\\columnwidth}\n\\begin{align*}\n \\text{minimize} \\; &\\sum_k g(\\epsilon_k)\\\\\n \\text{where} \\; g(u) &= u^2\n\\end{align*}\n\\end{column}\n\n\\begin{column}{0.6\\columnwidth}\n\\begin{center}\n  \\begin{tikzpicture}\n    \\begin{axis}[\n      width=8cm,\n      height=6cm,\n      ylabel=loss,\n      xlabel=penalty,\n      ]\n      \\addplot[red, thick, no marks, domain=-4:4, samples=201] {x^2};\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\\begin{frame}[label={sec:org49222fc}]{More robust: The Huber loss function}\n\\begin{columns}\n\\begin{column}{0.4\\columnwidth}\nAlso known as \\alert{robust regression}\n\\begin{align*}\n \\text{minimize} \\; &\\sum_k g_{hub}(\\epsilon_k)\\\\\n \\text{where}\\; g_{hub}(u) &= \\begin{cases} u^2 & |u| \\le M\\\\ M(2|u|-M) & |u| > M \\end{cases}\n\\end{align*}\n\\end{column}\n\n\\begin{column}{0.6\\columnwidth}\n\\begin{center}\n  \\begin{tikzpicture}\n    \\begin{axis}[\n      width=8cm,\n      height=6cm,\n      ylabel=penalty,\n      xlabel=residual,\n      ]\n      \\addplot[red, thick, no marks, domain=-4:4, samples=201] {x^2};\n      \\addplot[orange!90!black, ultra thick, no marks, domain=-4:-1, samples=201] {2*abs(x)-1};\n      \\addplot[orange!90!black, thin, no marks, domain=-1:1, samples=201] {x^2};\n      \\addplot[orange!90!black, ultra thick, no marks, domain=1:4, samples=201] {2*abs(x)-1};\n    \\end{axis}\n  \\end{tikzpicture}\n\\end{center}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:org10b0bf3}]{First-order ARX model without delay}\n\\begin{center}\n\\includegraphics[width=0.4\\linewidth]{../../figures/block-arx}\n\\end{center}\n\\[ (\\shift + a_1) y(k) = (b_0 \\shift + b_1) u(k) + e(k+1) \\]\n\n\\alert{Activity}\n\n\\begin{enumerate}\n\\item Determine the one-step ahead predictor \\(\\hat{y}_{k+1}\\) and the prediction error \\(\\epsilon_{k+1}\\).\n\\item Form the system of equations \\(\\Phi\\theta = y\\)\n\\end{enumerate}\n\\end{frame}\n\n\n\\begin{frame}[label={sec:orgc2d06b4}]{The ARX model}\n\\[ A(\\shift) y(k) = B(\\shift)u(k) + e(k+n)\\]\n\n\\alert{Activity} Fill the empty blocks.\n\n\\begin{center}\n  \\begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm, minimum height=12mm}, sumnode/.style={circle, draw, inner sep=2pt}]\n    \n    \\node[coordinate] (input) {};\n    \\node[block, right of=input, node distance=20mm] (plant)  {};\n    \\node[sumnode, right of=plant, node distance=24mm] (sum) {\\tiny $\\Sigma$};\n    \\node[block, above of=sum, node distance=20mm] (dist)  {};\n\n    \\node[coordinate, above of=dist, node distance=12mm] (disturbance) {};\n    \\node[coordinate, right of=sum, node distance=20mm] (output) {};\n\n    \\draw[->] (input) -- node[above, pos=0.3] {$u(k)$} (plant);\n    \\draw[->] (plant) -- node[above] {} (sum);\n    \\draw[->] (sum) -- node[above, near end] {$y(k)$} (output);\n    \\draw[->] (disturbance) -- node[right, pos=0.2] {$e(k)$} (dist);\n    \\draw[->] (dist) -- node[above] {} (sum);\n\n  \\end{tikzpicture}\n\\end{center}\n\\end{frame}\n\\end{document}", "meta": {"hexsha": "e3bdc88a0c53167e62042bad877e4ec7cd20af2f", "size": 8218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "system-identification/slides/lecture-sysid.tex", "max_stars_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_stars_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-07T05:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-22T09:46:13.000Z", "max_issues_repo_path": "system-identification/slides/lecture-sysid.tex", "max_issues_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_issues_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-06-12T20:44:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-12T20:49:00.000Z", "max_forks_repo_path": "system-identification/slides/lecture-sysid.tex", "max_forks_repo_name": "kjartan-at-tec/mr2007-computerized-control", "max_forks_repo_head_hexsha": "16e35f5007f53870eaf344eea1165507505ab4aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-14T03:55:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-14T03:55:27.000Z", "avg_line_length": 35.5757575758, "max_line_length": 275, "alphanum_fraction": 0.654295449, "num_tokens": 3099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6121536639699462}}
{"text": "\\subsection{Formal languages}\\label{subsec:formal_languages}\n\nLanguages are used to define formulas for expressing the \\hyperref[def:zfc]{axioms of set theory}. Here, sets are used to formally define languages. A simple way out of this vicious cycle is via the theory-metatheory relationship discussed in \\fullref{rem:metalogic} and \\fullref{rem:set_definition_recursion}. In short, we define languages within the metatheory using the already available concept of set, and we later define formulas, again in the metatheory, which allows us to subsequently formally define sets via axioms within the object logic.\n\n\\begin{definition}\\label{def:formal_language}\n  Fix a nonempty set \\( \\mscrA \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:formal_language/alphabet} We call \\( \\mscrA \\) an \\term{alphabet}.\n\n    \\thmitem{def:formal_language/symbol} We call each element of \\( \\mscrA \\) a \\term{symbol}.\n\n    \\thmitem{def:formal_language/word} A \\term{string} over \\( \\mscrA \\) is a \\hyperref[def:sequence]{finite sequence} of symbols. If \\( (a, b, c) \\) is a word, for convenience we write it as the string \\( abc \\). This is the reason words are also referred to as \\term{strings}. This notation only makes sense if each symbol of the language is actually represented by one typographic symbol.\n\n    The term \\enquote{string} is common in programming practice. In the context of formal languages, strings are often called \\term{words}. We will avoid the later term since it does not correspond to the everyday use of the term \\enquote{word}.\n\n    \\thmitem{def:formal_language/empty_word} We denote the empty string by \\( \\varepsilon \\).\n\n    \\thmitem{def:formal_language/word_length} The \\term{length} \\( \\len(w) \\) of a word \\( w \\) is the number of elements of the tuple \\( w \\).\n\n    \\thmitem{def:formal_language/concatenation} The \\term{concatenation} of the words \\( v = (v_1, \\ldots, v_n) \\) and \\( w = (w_1, \\ldots, w_m) \\) is the word\n    \\begin{equation*}\n      vw \\coloneqq (v_1, \\ldots, v_n, w_1, \\ldots, w_m).\n    \\end{equation*}\n\n    We abbreviate \\( \\overbrace{w w \\ldots w}^{k \\T{times}} \\) as \\( w^k \\). This is only a notation. We do not distinguish, formally, between the words \\( aaabbaa \\) and \\( a^3 b^2 a^2 \\), nor between \\( a \\varepsilon b \\) and \\( ab \\).\n\n    \\thmitem{def:formal_language/reverse} The \\term{reverse word} of \\( w = (w_1, \\ldots, w_n) \\) is\n    \\begin{equation*}\n      \\op{rev}(w) \\coloneqq (w_n, \\ldots, w_1).\n    \\end{equation*}\n\n    \\thmitem{def:formal_language/prefix} The word \\( p = (p_1, \\ldots, p_m) \\) is a \\term{prefix} of \\( w = (w_1, \\ldots, w_n) \\) if\n    \\begin{equation*}\n      w = (\\underbrace{p_1, \\ldots, p_m}_p, w_{m+1}, \\ldots, w_n).\n    \\end{equation*}\n\n    \\thmitem{def:formal_language/suffix} The word \\( s \\) is a \\term{suffix} of \\( w \\) if \\( \\op{rev}(s) \\) is a prefix of \\( \\op{rev}(w) \\).\n\n    \\thmitem{def:formal_language/subword} The word \\( v \\) is a \\term{subword} of \\( w \\) if there exists a prefix \\( p \\) and a suffix \\( s \\) of \\( v \\) such that\n    \\begin{equation*}\n      w = pvs.\n    \\end{equation*}\n\n    \\thmitem{def:formal_language/kleene_star} The \\term{Kleene star} \\( \\mscrA^* \\) of \\( \\mscrA \\) is the set of all words over \\( \\mscrA \\). If we wish to exclude the empty word, like we often do, we instead write \\( \\mscrA^+ \\) for the set of all non-empty words over \\( \\mscrA \\).\n\n    \\thmitem{def:formal_language/language} A \\term{language} over \\( \\mscrA \\) is any subset of \\( \\mscrA^* \\). Note that in some contexts like \\hyperref[subsec:propositional_logic]{propositional logic} or \\hyperref[subsec:first_order_logic]{first-order logic} the term \\enquote{language} may refer to the alphabet itself (see \\fullref{rem:propositional_language_is_alphabet}).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:kleene_star_is_monoid}\n  For any alphabet \\( \\mscrA \\), the Kleene star \\( \\mscrA^* \\) is a \\hyperref[def:unital_magma/monoid]{monoid} under concatenation.\n\\end{proposition}\n\\begin{proof}\n  Concatenation is clearly associative and the empty word \\( \\varepsilon \\) is a \\hyperref[def:magma_identity]{two-sided identity} under concatenation.\n\\end{proof}\n\n\\begin{definition}\\label{def:formal_grammar}\\mcite[def. 2.2]{Sipser2013}\n  Let \\( V \\) and \\( \\Sigma \\) be disjoint nonempty subsets of some \\hyperref[def:formal_language/alphabet]{alphabet}.\n\n  \\begin{thmenum}\n    \\thmitem{def:formal_grammar/terminals} We call elements of \\( \\Sigma \\) \\term{terminals}. We denote terminals in abstract grammars using lowercase Greek letters, and we denote words using lowercase Latin letters.\n\n    \\thmitem{def:formal_grammar/non_terminals} We call elements of \\( V \\) \\term{non-terminals}. By convention, variables are denoted using capital letters.\n\n    \\thmitem{def:formal_grammar/start} We assume that a special \\term{start symbol} \\( S \\in V \\) is fixed.\n\n    \\thmitem{def:formal_grammar/production_rules} We define a binary \\hyperref[def:relation]{relation} \\( \\to \\) of \\term{production rules} over \\( (V \\cup \\Sigma)^* \\).\n\n    We impose the restriction that no rules of the form \\( \\varepsilon \\to v \\) exist for any word \\( v \\). We do allow, however, production rules of the form \\( v \\to \\varepsilon \\). Such rules are called \\term{\\( \\varepsilon \\)-rules}.\n\n    Rules describe transformations that define how a language is \\enquote{generated} starting from \\( S \\). See \\fullref{def:grammar_derivation} and \\fullref{ex:natural_number_arithmetic_grammar/derivation}.\n\n    \\thmitem{def:formal_grammar/grammar} The quadruple \\( G \\coloneqq (V, S, \\Sigma, \\to) \\) is called a \\term{formal grammar} or simply a \\term{grammar}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:chomsky_hierarchy}\n  We will define the \\term{Chomsky hierarchy} of \\hyperref[def:formal_grammar]{formal grammars}. We can classify a grammar \\( G = (V, S, \\Sigma, \\to) \\) as follows, based on their rules:\n  \\begin{thmenum}\n    \\thmitem{def:chomsky_hierarchy/unrestricted} In general, every production rule has the form \\( v \\to w \\), where both \\( v \\) and \\( w \\) are words consisting of terminal and non-terminals, and \\( v \\) is nonempty.\n\n    When no additional restrictions are imposed on the rules of the grammar, we call it \\term{unrestricted grammar}. The other levels of the hierarchy are subsets of the unrestricted grammars.\n\n    \\thmitem{def:chomsky_hierarchy/non_contracting} The grammar is \\term{non-contracting} if \\( \\len(v) \\leq \\len(w) \\) for every production rule \\( v \\to w \\).\n\n    \\thmitem{def:chomsky_hierarchy/context_sensitive} The grammar is \\term{context-sensitive} if every rule has the form \\( aAb \\to w \\) for some non-terminal \\( A \\), arbitrary words \\( a \\) and \\( b \\), and a nonempty word \\( w \\).\n\n    The requirement for \\( w \\) to be nonempty is set up so that context-sensitive grammars are non-contracting.\n\n    \\thmitem{def:chomsky_hierarchy/context_free} The grammar is \\term{context-free} every rule has the form \\( A \\to w \\) for some non-terminal \\( A \\) and a nonempty word \\( w \\).\n\n    Unlike for context-sensitive languages, \\( w \\) is allowed to be empty. Thus, a context-free grammar is non-contracting, however it may not be context-sensitive if it has \\( \\varepsilon \\)-rules.\n\n    \\thmitem{def:chomsky_hierarchy/regular} Finally, the grammar is \\term{regular} if every rule has one of the forms\n    \\begin{align*}\n      &A \\to \\varepsilon, \\\\\n      &A \\to B \\tau, \\\\\n      &A \\to \\tau B, \\\\\n      &A \\to \\tau,\n    \\end{align*}\n    where \\( A \\) and \\( B \\) are non-terminals and \\( \\tau \\) is a terminal.\n\n    Regular grammars are obviously context-free.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:natural_number_arithmetic_grammar/backus_naur_form}\n  We define a grammar for primary school notation of multiplication and division of \\hyperref[def:set_of_natural_numbers]{natural numbers}. Note that we consider the numbers in \\( \\BbbN \\) only as symbols, without any regard to semantics.\n\n  Let \\( V \\coloneqq \\set{ N, O, M, E } \\) and \\( \\Sigma \\coloneqq \\BbbN \\cup \\set{ \\times, \\div, (, ) } \\). Define the grammar\n  \\begin{equation}\\label{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/simple}\n    \\begin{aligned}\n      N &\\to 0 \\\\\n      N &\\to 1 \\\\\n      \\phantom{N} &\\vdots \\\\\n      N &\\to n \\\\\n      \\phantom{N} &\\vdots \\\\\n      O &\\to \\times \\\\\n      O &\\to \\div \\\\\n      E &\\to N \\\\\n      E &\\to (E O E)\n    \\end{aligned}\n  \\end{equation}\n\n  It is convenient to use the following shorthands:\n  \\begin{equation}\\label{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/shorthand}\n    \\begin{aligned}\n      N &\\to 0 \\mid 1 \\mid 2 \\mid \\ldots \\\\\n      O &\\to \\times \\mid \\div \\\\\n      E &\\to N \\mid (E O E)\n    \\end{aligned}\n  \\end{equation}\n\n  We can choose different non-terminals as the starting symbol. The symbol \\( N \\) corresponds to numbers, \\( O \\) corresponds to operations, and \\( E \\) can be either a number or an expression. We say that \\eqref{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/shorthand} specifies a \\term{grammar schema}. With any starting symbol, the grammar is clearly \\hyperref[def:chomsky_hierarchy]{context-free}.\n\\end{example}\n\n\\begin{remark}\\label{rem:backus_naur_form}\n  The infinitude of possible rules in \\fullref{ex:natural_number_arithmetic_grammar/backus_naur_form} may not bother us formally, but when dealing with software implementations, we must have a finite number of rules. An example of a nontrivial grammar in the wild is the Python grammar that can be found in \\cite{Python39Grammar}. There are also other advantages of introducing a more convenient metasyntax (a syntax for describing language syntax).\n\n  For \\hyperref[def:chomsky_hierarchy/context_free]{context-free grammars}, is often convenient to use the \\term{Backus-Naur form (BNF)}. For \\fullref{ex:natural_number_arithmetic_grammar/backus_naur_form}, the BNF is\n  \\begin{bnf*}\n    \\bnfprod{nonzero digit} {\\bnfts{1} \\bnfor \\bnfts{2} \\bnfor \\bnfts{3} \\bnfor \\bnfts{4} \\bnfor \\bnfts{5} \\bnfor \\bnfts{6} \\bnfor \\bnfts{7} \\bnfor \\bnfts{8} \\bnfor \\bnfts{9}} \\\\\n    \\bnfprod{digit}         {\\bnfts{0} \\bnfor \\bnfpn{nonzero digit}} \\\\\n    \\bnfprod{number}        {\\bnfpn{nonzero digit} \\bnfor \\bnfpn{number} \\bnfsp \\bnfpn{digit}} \\\\\n    \\bnfprod{operation}     {\\bnfts{\\( \\times \\)} \\bnfor \\bnfts{\\( \\div \\)}} \\\\\n    \\bnfprod{expression}    {\\bnfpn{number} \\bnfor \\bnfts{(} \\bnfsp \\bnfpn{number} \\bnfsp \\bnfpn{operation} \\bnfsp \\bnfpn{number} \\bnfsp \\bnfts{)}}.\n  \\end{bnf*}\n\n  The obvious difference is that we explicitly define numbers via their decimal representation, which means that we get a finite amount of rules. Compared to \\eqref{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/simple} some other differences are:\n  \\begin{itemize}\n    \\item Variables are denoted by \\( \\langle \\)words enclosed in angle brackets\\( \\rangle \\), so that we can name variables more descriptively using more than one symbol.\n    \\item Terminals are, by convention, put in \\enquote{quotes}. In human-readable rich text documents like this one, it is sometimes possible to use different fonts, and so instead of using \\enquote{quotes} we specify terminals using an \\texttt{upright typewriter font}.\n    \\item Free-text rules can be specified using a normal font. This is also only used in human-readable rich text documents, however this usage is justified because such rules are only beneficial for human understanding and not for machine parsing.\n    \\item By convention, the symbol \\( \\Coloneqq \\) is used instead of \\( \\to \\) for specifying transition rules.\n    \\item Different rules with the same, source are concatenated as in \\eqref{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/shorthand}.\n    \\item In order to fully describe a context-free grammar, we must only specify its Backus-Naur form and its starting variable.\n  \\end{itemize}\n\\end{remark}\n\n\\begin{definition}\\label{def:grammar_derivation}\n  Fix a \\hyperref[def:formal_grammar]{formal grammar} \\( G = (V, S, \\Sigma, \\to) \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:grammar_derivation/derivation} We define the binary relation \\( \\Rightarrow \\) on the Kleene star \\( (V \\cup \\Sigma)^* \\) by declaring that, for every two \\hyperref[def:formal_language/word]{words} \\( p \\) and \\( s \\) over \\( V \\cup \\Sigma \\) and every production rule \\( v \\to w \\), we have \\( pvw \\Rightarrow pws \\). We also define the relation \\( \\Rightarrow_L \\) as a restriction of \\( \\Rightarrow \\) to the cases where \\( p \\) contains only terminal symbols and \\( \\Rightarrow_R \\) --- if \\( s \\) contains only terminal symbols.\n\n    A \\term{derivation} of the word \\( w_n \\) from \\( w_1 \\) is a \\hyperref[def:quiver_path/directed]{directed path} in the quiver induced by the relation \\( \\Rightarrow \\), i.e.\n    \\begin{equation}\\label{eq:def:grammar_derivation/derivation}\n      w_1\n      \\reloset {u_1 \\to v_1} \\implies\n      w_2\n      \\reloset {u_2 \\to v_2} \\implies\n      \\cdots\n      \\reloset {u_{n-2} \\to v_{n-2}} \\implies\n      w_{n-1}\n      \\reloset {u_{n-1} \\to v_{n-1}} \\implies\n      w_n.\n    \\end{equation}\n\n    A \\term{leftmost derivation} is a derivation performed using \\( \\Rightarrow_L \\) rather than \\( \\Rightarrow \\). \\term{Rightmost derivations} are defined analogously.\n\n    We say that \\( w_n \\) is \\term{derivable} from \\( w_1 \\) if there exists a derivation from \\( w_1 \\) to \\( w_n \\).\n\n    We denote the \\hyperref[def:relation_closures/transitive]{transitive closure} of \\( \\Rightarrow \\) by \\( \\reloset + \\Rightarrow \\) and the \\hyperref[def:relation_closures/reflexive]{reflexive} closure of \\( \\reloset + \\Rightarrow \\) by \\( \\reloset {*} \\Rightarrow \\). Clearly \\( w_1 \\) is derivable from \\( w_n \\) if and only if \\( w_1 \\reloset {*} \\Rightarrow w_n \\).\n\n    The leftmost and rightmost derivations generate the same derivability relation --- the only potential difference is in the order of rule applications in the derivation itself.\n\n    \\thmitem{def:grammar_derivation/unambiguous}\\mcite[def. 2.7]{Sipser2013} We say that the word \\( w \\) can be derived \\term{unambiguously} if it has a unique leftmost derivation.\n\n    Define the set\n    \\begin{equation*}\n      D \\coloneqq \\set{ w \\in (V \\cup \\Sigma)^* \\colon S \\reloset + \\Rightarrow w }\n    \\end{equation*}\n    of all words derivable from the starting symbol \\( S \\).\n\n    If every word in \\( D \\) can be derived unambiguously, we say that the grammar itself is \\term{unambiguous}.\n\n    In an unambiguous grammar, \\fullref{thm:structural_induction_on_unambiguous_grammars} can be used on the \\hyperref[def:quiver/simple]{simple directed graph} \\( (D, \\Rightarrow_L) \\). Indeed, every word in \\( D \\) is derivable from \\( S \\) and every leftmost derivation is unique.\n\n    \\thmitem{def:grammar_derivation/grammar_language} The \\term{language} of the grammar is the set\n    \\begin{equation*}\n      \\mscrL(G) \\coloneqq \\set{ w \\in \\Sigma^* \\colon S \\reloset + \\Rightarrow w }\n    \\end{equation*}\n    of all terminal-only words derivable from the starting symbol \\( S \\).\n\n    We also say that strings in \\( \\mscrL(G) \\) are \\term{generated} by the grammar \\( G \\).\n\n    If a language can be generated by a \\hyperref[def:chomsky_hierarchy/regular]{regular} grammar, we say that the language itself is regular, and similarly for \\hyperref[def:chomsky_hierarchy/context_free]{context-free} and \\hyperref[def:chomsky_hierarchy/context_sensitive]{context-sensitive} grammars.\n\n    For other grammars, for example \\hyperref[def:chomsky_hierarchy/unrestricted]{unrestricted} or \\hyperref[def:chomsky_hierarchy/non_contracting]{non-contracting}, such a terminology is not established.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:natural_number_arithmetic_grammar/derivation}\n  We continue \\fullref{ex:natural_number_arithmetic_grammar/backus_naur_form}. Depending on our choice of starting symbol, we can derive different sets of words.\n\n  For the sake of simplifying our exposition and proof, however, we will assume the simpler grammar described in \\eqref{eq:ex:natural_number_arithmetic_grammar/backus_naur_form/simple}.\n\n  Choose the starting symbol to be \\( E \\). We will show that this grammar is unambiguous.\n\n  \\Cref{fig:ex:natural_number_arithmetic_grammar/derivation/ambiguous} demonstrates that removing the parentheses makes even this simple grammar ambiguous.\n\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=1]{output/ex__natural_number_arithmetic_grammar__derivation.pdf}\n    \\hfill\\hfill\n    \\caption{The unique way to produce the parenthesized arithmetic expression \\( ((6 \\div 2) \\times 3) \\)}\n    \\label{fig:ex:natural_number_arithmetic_grammar/derivation/unambiguous}\n  \\end{figure}\n\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=2]{output/ex__natural_number_arithmetic_grammar__derivation.pdf}\n    \\hfill\\hfill\n    \\caption{Different leftmost derivations of the parenthesis-less arithmetic expression \\( 6 \\div 3 \\times 2 \\)}\n    \\label{fig:ex:natural_number_arithmetic_grammar/derivation/ambiguous}\n  \\end{figure}\n\n  We will show that \\( G \\) is unambiguous. Let \\( w \\) be a word in \\( \\mscrL(G) \\). We explicitly build the leftmost derivation of \\( w \\) using recursion on \\( \\len(w) \\):\n  \\begin{itemize}\n    \\item If \\( \\len(w) = 1 \\), then \\( w = n \\in \\BbbN \\), and the word has been derived as \\( E \\to N \\to n \\).\n\n    \\item Assume that \\( w \\) is unambiguously derived for \\( \\len(w) < m + 2 \\) and let \\( \\len(w) = m + 2 \\), then \\( w \\) is necessarily enclosed in parentheses. Let \\( w = ( \\sigma_1 \\ldots \\sigma_m ) \\) be the symbols of \\( w \\). Because of the parentheses, the only possibility for \\( \\sigma_1 \\ldots \\sigma_m \\) is that it consists of two words in \\( \\mscrL(G) \\) with either a multiplication symbol \\( \\times \\) or a division symbol \\( \\div \\) between them. Let \\( k \\) be the index of the operator symbol, that is, the index such that \\( \\sigma_1 \\ldots \\sigma_{k-1} \\) and \\( \\sigma_{k+1} \\ldots \\sigma_m \\) both belong to \\( \\mscrL(G) \\).\n\n    By the inductive hypothesis, both \\( \\sigma_1 \\ldots \\sigma_{k-1} \\) and \\( \\sigma_{k+1} \\ldots \\sigma_m \\) are unambiguously derived from \\( E \\). Then \\( w \\) is generated by the rule \\( E \\to (E O E) \\), where the operator symbol \\( \\sigma_k \\) determines the terminal of \\( O \\). Therefore, the derivation of \\( w \\) is also unambiguous.\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:ordered_arborescence}\n  An \\term{ordered arborescence} is an \\hyperref[def:arborescence]{arborescence} \\( T = (G, A) \\) with a \\hyperref[def:partially_ordered_set]{partial order} \\( \\leq \\) such that every set of \\hyperref[def:arborescence/ancestry]{siblings} is a \\hyperref[def:partially_ordered_set_chain_and_antichain]{chain}.\n\\end{definition}\n\n\\begin{definition}\\label{def:grammar_syntax_tree}\\mimprovised\n  Fix a \\hyperref[def:chomsky_hierarchy/context_free]{context-free} \\hyperref[def:formal_grammar]{formal grammar} \\( G = (V, S, \\Sigma, \\to) \\).\n\n  For every word \\( w \\) in \\( \\mscrL(G) \\), we will build an \\hyperref[def:ordered_arborescence]{ordered} \\hyperref[def:arborescence/undirected]{rooted tree} whose \\hyperref[def:arborescence/ancestry]{leaves} are the symbols of \\( w \\) and whose root is \\( S \\). We will call this a \\term{syntax tree} for \\( w \\).\n\n  \\begin{figure}\n    \\hfill\n    \\includegraphics[page=1]{output/alg__grammar_syntax_tree.pdf}\n    \\hfill\\hfill\n    \\caption{A grammar tree corresponding to the expression \\( (6 \\div (3 \\times 2)) \\) from \\cref{fig:ex:natural_number_arithmetic_grammar/derivation/unambiguous}}\n    \\label{fig:def:grammar_syntax_tree}\n  \\end{figure}\n\n  Fix a derivation\n  \\begin{equation}\\label{eq:def:grammar_syntax_tree/derivation}\n    S \\Rightarrow w_1 \\Rightarrow \\cdots \\Rightarrow w_{n-1} \\Rightarrow w_n.\n  \\end{equation}\n\n  We use \\hyperref[rem:natural_number_recursion]{natural number recursion} on \\( n \\) to build the tree. Note that, for the purposes of recursion, we allow \\( w_n \\) to contain non-terminals.\n\n  \\begin{itemize}\n    \\item In the trivial case where \\( n = 0 \\), and there is no actual derivation, we build a single-vertex tree with root \\( S \\).\n\n    \\item Suppose that we can build a tree for all derivations of length \\( m - 1 \\) and fix a derivation \\eqref{eq:def:grammar_syntax_tree/derivation} of length \\( n \\).\n\n    First, build a tree \\( T \\) from the derivation\n    \\begin{equation*}\n      S \\Rightarrow w_1 \\Rightarrow \\cdots \\Rightarrow w_{n-2} \\Rightarrow w_{n-1}.\n    \\end{equation*}\n\n    There must exist words \\( p \\), \\( s \\) and \\( v \\) and a non-terminal \\( A \\) such that\n    \\begin{equation*}\n      w_{n-1} = pAs \\Rightarrow pvs = w_n.\n    \\end{equation*}\n\n    There already exists a leaf for \\( A \\) in \\( T \\). For every symbol in \\( v \\), add a new node as a child of this node.\n  \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:unambiguous_grammar_syntax_trees}\n  A \\hyperref[def:chomsky_hierarchy/context_free]{context-free} grammar is \\hyperref[def:chomsky_hierarchy/context_free]{unambiguous} if and only if every word has a unique \\hyperref[def:grammar_syntax_tree]{syntax tree}.\n\\end{proposition}\n\n\\begin{theorem}[Structural induction on unambiguous grammars]\\label{thm:structural_induction_on_unambiguous_grammars}\\mimprovised\n  Unlike for the other induction principles in \\fullref{rem:induction}, we will not formulate this one via logical formulas. This will complicate us unnecessarily. We will instead describe how the principle is used in practice.\n\n  Let \\( G = (V, S, \\Sigma, \\to) \\) be an \\hyperref[def:chomsky_hierarchy/context_free]{unambiguous} \\hyperref[def:chomsky_hierarchy/context_free]{context-free} \\hyperref[def:formal_grammar]{formal grammar}.\n\n  Suppose that we want to prove a statement for every word in \\( \\mscrL(G) \\). It is sufficient to perform the following for every rule \\( A \\to w \\):\n  \\begin{displayquote}\n    Let \\( A_1, \\ldots, A_n \\) be all non-terminals of \\( w \\) and let \\( u_0, \\ldots, u_n \\) be subwords of \\( w \\) such that\n    \\begin{equation*}\n      w = u_0 A_1 u_1 A_2 \\ldots A_n u_n.\n    \\end{equation*}\n\n    Let \\( v_1, \\ldots, v_n \\) be arbitrary words in \\( \\mscrL(G) \\) derivable from \\( A_1, \\ldots, A_n \\), respectively, so that we have the syntax tree\n    \\begin{equation*}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__structural_induction_on_unambiguous_grammars.pdf}\n      \\end{aligned}\n    \\end{equation*}\n\n    Then we must prove the statement for the word\n    \\begin{equation*}\n      u_0 v_1 u_1 \\ldots v_n u_n.\n    \\end{equation*}\n  \\end{displayquote}\n\n  Compare this principle to the more general \\fullref{thm:well_founded_induction}.\n\\end{theorem}\n\\begin{proof}\n  Clearly every word in \\( \\mscrL(G) \\) can be obtained in this way.\n  The role of non-ambiguity is discussed in the proof of \\fullref{thm:well_founded_induction}.\n\\end{proof}\n", "meta": {"hexsha": "97107fdf6ef5454ee61c6670aecba05bf459bd85", "size": 22793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/formal_languages.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/formal_languages.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/formal_languages.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": 69.7033639144, "max_line_length": 649, "alphanum_fraction": 0.7089896021, "num_tokens": 6811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7718434873426303, "lm_q1q2_score": 0.6121536631941388}}
{"text": "\\section{Discrete Armijo Gradient}\n\\lab{sec:DAG}\nThe Discrete Armijo Gradient algorithm can be used to solve\nproblem $\\mathbf P_c$ defined in~\\eqref{sub:Proc} where\n$f(\\cdot)$ is continuously differentiable.\\\\\n\nThe Discrete Armijo Gradient algorithm approximates gradients by finite differences.\nIt can be used for problems where the cost function is evaluated by\ncomputer code that defines a continuously differentiable function but for\nwhich obtaining analytical expressions for the gradients is impractical\nor impossible.\\\\\n\nSince the Discrete Armijo Gradient algorithm is sensitive to discontinuities in\nthe cost function, we recommend not to use this algorithm if the simulation program\ncontains adaptive solvers with loose precision settings, such as\nEnergyPlus~\\cite{Crawley2001:1}.\nOn such functions, the algorithm is likely to fail. \nIn Section~\\ref{sec:AlgSel}, we recommend algorithms that\nare better suited for such situations.\\\\\n\nWe will now present the Discrete Armijo Gradient algorithm and the\nArmijo step-size subprocedure.\n\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{algorithm}\n[Discrete Armijo Gradient 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     & Initial iterate $x_0 \\in \\mathbf X$.\\\\ \n     & $\\alpha, \\beta \\in (0, 1)$, $\\gamma \\in (0, \\infty)$, $k^*, k_0 \\in \\mathbb Z$,\\\\\n     & $l_{max}, \\kappa \\in \\Na$ (for reseting the step-size calculation).\\\\\n     & Termination criteria $\\epsilon_m, \\epsilon_x \\in \\Re_+$, \n     $i_{max} \\in \\Na$.\\\\\n  \\textbf{Step 0}: \n     & Initialize $i=0$ and $m = 0$.\\\\\n  \\textbf{Step 1}:\n     & \\underline{Compute the {\\it search direction} $h_i$.}\\\\\n     & If $\\beta^m < \\epsilon_m$, stop.\\\\\n     & Else, set $\\epsilon = \\beta^{k_0 + m }$ and compute, for $j \\in \\{1, \\ldots, n\\}$,\\\\\n     & $h_i^j = - \\left({f(x_i + \\epsilon \\, e_j ) - f(x_i)}\\right)/{\\epsilon}$.\\\\\n\\textbf{Step 2} : \n     & \\underline{Check descent.} \\\\\n     & Compute $\\Delta(x_i; h_i) = \n     \\left( f(x_i + \\epsilon \\, h_i ) - f(x_i) \\right) / \\epsilon$.\\\\\n     & If $\\Delta(x_i; h_i) < 0$, go to Step 3.\\\\\n     & Else, replace $m$ by $m+1$ and go to Step 1.\\\\\n\\textbf{Step 3} :\n     & \\underline{Line search.}\\\\\n     & Use Algorithm~\\ref{al:ArmijoSubPro} (which requires $k^*, l_{max}$ and $\\kappa$) \n     to compute $k_i$.\\\\\n     & Set \n\\end{tabularx}\n\\vspace{-1ex}\n \\begin{equation}\n   \\hspace{3cm} \\lambda_i = \\argmin_{\\lambda \\in \\{\\beta^{k_i}, \\beta^{k_i-1} \\}  } \n     f(x_i + \\lambda \\, h_i).\n\\end{equation}\n\\vspace{-1ex}\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\textbf{Step 4} :\n     & If $f(x_i + \\lambda_i \\, h_i) - f(x_i) > - \\gamma \\, \\epsilon$, \n     replace $m$ by $m+1$ and go to Step 1.\\\\\n\\textbf{Step 5} :\n     & Set $x_{i+1} = x_i + \\lambda_i \\, h_i$.\\\\\n     & If $\\| \\lambda_i \\, h_i \\| < \\epsilon_x$, stop. Else, replace $i$ by $i+1$ and go to Step 1.\\\\ \n\\hline\n\\end{tabularx}\n}\n~\\\\ \\lab{al:DAG}\n\\end{algorithm}\n\\end{minipage}\n\n\\noindent\n\\begin{minipage}[b]{\\textwidth}\n\\begin{subequations}\n\\begin{algorithm}\n[Armijo Step-Size Subprocedure]\n~\\\\\n{\\em\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\multicolumn{2}{l}{\\hspace{\\textwidth}~} \\\\ \\\\[-8ex]\\\\\n\\hline \\\\[-2ex]\n \\textbf{Data}:\n     & Iteration number $i \\in \\Na$, iterate $x_i \\in \\Re^n$, \n     search direction $h_i \\in \\Re^n$,\\\\ \n     & $k^*, k_{i-1} \\in \\mathbb Z$, $\\alpha, \\beta \\in (0, \\ 1)$, and \n     $\\Delta(x_i;h_i) \\in \\Re$ with $\\Delta(x_i;h_i) < 0$,\\\\\n     & parameter for restart $l_{max}, \\kappa \\in \\Na$.\\\\\n\\textbf{Step 0}:\n     & Initialize $l=0$.\\\\\n     & If $i = 0$, set $k' = k^*$, else set $k' = k_{i-1}$.\\\\\n\\textbf{Step 1}:\n     & Replace $l$ by $l+1$, and test the conditions\n\\end{tabularx}\n\\vspace{-1ex}\n\\begin{eqnarray}\n\\hspace{2cm}     f(x_i + \\beta^{k'} \\, h_i ) - f(x_i) & \\le &\n     \\beta^{k'} \\, \\alpha \\, \\Delta(x_i; h_i), \\label{eq:ArmSteSizPro1} \\\\\n\\hspace{2cm}     f(x_i + \\beta^{k' - 1} \\, h_i ) - f(x_i) & > &\n     \\beta^{k' - 1} \\, \\alpha \\, \\Delta(x_i; h_i).\n\\label{eq:ArmSteSizPro2}\n\\end{eqnarray}\n\\vspace{-1ex}\n\\begin{tabularx}{\\headwidth}{m{2cm}l}\n\\textbf{Step 2}:\n& If $k'$ satisfies \\eqref{eq:ArmSteSizPro1} and \n \\eqref{eq:ArmSteSizPro2}, return $k'$.\\\\\n\\textbf{Step 3}:\n   & If $k'$ satisfies \\eqref{eq:ArmSteSizPro2} \n     but not \\eqref{eq:ArmSteSizPro1},\\\\\n   & \\hspace{1cm} replace $k'$ by $k'+1$.\\\\\n   & else,\\\\\n   & \\hspace{1cm} replace $k'$ by $k'-1$.\\\\\n   & If $l < l_{max}$ or $k_{i-1} \\le  k^* + \\kappa$, go to Step 1. Else, go to Step 4.\\\\\n\\textbf{Step 4}:\n     & Set $\\mathbf K \\triangleq \\{ k \\in \\mathbb Z \\ | \\ k \\ge k^* \\}$,\n     and compute\\\\\n     & $k'\n     \\triangleq \\min_{k \\in \\mathbf K} \\{ k \\ | \\\n     f(x_i + \\beta^k \\, h_i ) - f(x_i) \\le \\beta^k \\, \\alpha \\, \\Delta(x_i; h_i) \\}$.\\\\\n     & Return $k'$.\\\\\n\\hline\n\\end{tabularx}\n}\n\\lab{al:ArmijoSubPro}\n\\end{algorithm}\n\\end{subequations}\n\\end{minipage}\n~\\\\\nNote that in Algorithm~\\ref{al:ArmijoSubPro}, as $\\beta \\to 1$, \nthe number of tries to compute the Armijo step-size is likely to go to infinity.\nUnder appropriate assumptions one can show that $\\alpha = 1/2$ yields \nfastest convergence~\\cite{Pol97:1}.\\\\\n\nThe step-size Algorithm~\\ref{al:ArmijoSubPro} requires often only a small number\nof function evaluations.\nHowever, occasionally, once a very small step-size has occurred,\nAlgorithm~\\ref{al:ArmijoSubPro} can trap the Discrete Armijo Gradient algorithm\ninto using a very small step-size for all subsequent iterations.\nHence, if $k_{i-1} >  k^* + \\kappa$, we reset the step-size by computing Step 4.\\\\\n\nAlgorithm~\\ref{al:DAG} together with the step-size Algorithm~\\ref{al:ArmijoSubPro}\nhave the following convergence properties~\\cite{Pol97:1}.\n\n\\begin{theorem}\nLet $f \\colon \\Re^n \\to \\Re$ be continuously differentiable and bounded below.\n\\begin{enumerate}\n\\item \nIf Algorithm~\\ref{al:DAG} jams at $x_i$, cycling indefinitely in the loop\ndefined by Steps 1-2 or in the loop defined by Steps 1-4,\nthen $\\nabla f(x_i) = 0$.\n\\item\nIf $\\{ x_i \\}_{i=0}^\\infty$ is an infinite sequence constructed by\nAlgorithm~\\ref{al:DAG} and Algorithm~\\ref{al:ArmijoSubPro}\nin solving~\\eqref{sub:Proc},\nthen every accumulation point $\\widehat x$ of $\\{ x_i \\}_{i=0}^\\infty$\nsatisfies $\\nabla f(\\widehat x) = 0$.\n\\end{enumerate}\n\\rbox\n\\end{theorem}\n\n\nNote that $\\epsilon \\, h_i$ has the same units as the cost function,\nand the algorithm evaluates $x_i + \\lambda \\, h_i$ for some $\\lambda \\in \\Re_+$.\nThus, the algorithm is sensitive to the scaling of the problem variables,\na rather undesirable effect.\nTherefore, in the implementation of \nAlgorithm~\\ref{al:DAG} and Algorithm~\\ref{al:ArmijoSubPro},\nwe normalize the cost function values by replacing, for all $x \\in \\Re^n$,\n$f(x)$ by $f(x)/f(x_0)$, where $x_0$ is the initial iterate.\nFurthermore, we set $x_0 = 0$ and evaluate the cost function for the values\n$\\chi^j + x^j \\, s^j$, $j \\in \\{1, \\ldots, n\\}$, where\n$x^j \\in \\Re$ is the $j$-th component of the design parameter computed in\nAlgorithm~\\ref{al:DAG} or Algorithm~\\ref{al:ArmijoSubPro} and\n$\\chi^j \\in \\Re$ and $s^j \\in \\Re$ are the setting of the parameters\n\\texttt{Ini} and \\texttt{Step}, respectively, for\nthe $j$-th design parameter in the optimization command file \n(see page~\\pageref{par:comFil}).\n\nIn view of the sensitivity of the Discrete Armijo Gradient algorithm\nto the scaling of the problem variables and the cost function values,\nthe implementation of penalty and barrier functions may cause\nnumerical problems if the penalty is large compared to the unpenalized\ncost function value.\n\nIf box-constraints for the independent parameters are specified,\nthen the transformations~\\eqref{sub:traBoxCon} are used.\n\n%-------------------------\n\\subsection{Keywords}\nFor the Discrete Armijo Gradient algorithm, the command file (see page~\\pageref{par:comFil}) must only contain continuous parameters.\\\\\n\nTo invoke the algorithm, \nthe \\texttt{Algorithm} section of the GenOpt command file must have the following form:\n\\begin{lstlisting}\nAlgorithm{\n   Main  = DiscreteArmijoGradient;\n   Alpha = Double;     // 0 < Alpha < 1\n   Beta  = Double;     // 0 < Beta  < 1\n   Gamma = Double;     // 0 < Gamma\n   K0    = Integer;\n   KStar = Integer;\n   LMax  = Integer;    // 0 <= LMax\n   Kappa = Integer;    // 0 <= LMax\n   EpsilonM = Double;  // 0 < EpsilonM\n   EpsilonX = Double;  // 0 < EpsilonX\n}\n\\end{lstlisting}\nThe entries are defined as follows:\n\\begin{codedescription}\n\\item [Main]\nThe name of the main algorithm.\n\\item [Alpha]\nThe variable $\\alpha$ used in Step 1 and in Step 4 of Algorithm~\\ref{al:ArmijoSubPro}.\nA typical value is $\\alpha = 1/2$.\n\\item [Beta]\nThe variable $\\beta$ used in approximating\nthe gradient and doing the line search.\nA typical value is $\\beta = 0.8$.\n\\item [Gamma]\nThe variable $\\gamma$ used in Step 4 of Algorithm~\\ref{al:DAG} \nto determine\nwhether the accuracy of the gradient approximation will be increased.\n\\item [K0]\nThe variable $k_0$ that determines the initial accuracy\nof the gradient approximation.\n\\item [KStar]\nThe variable $k^*$ used to initialize the line search.\n\\item [LMax]\nThe variable $l_{max}$ used in Step 3 of Algorithm~\\ref{al:ArmijoSubPro}\nto determine whether the line search needs to be reinitialized.\n\\item [Kappa]\nThe variable $\\kappa$ used in Step 3 of Algorithm~\\ref{al:ArmijoSubPro}\nto determine whether the line search needs to be reinitialized.\n\\item [EpsilonM]\nThe variable $\\epsilon_m$ used in the determination criteria\n$\\beta^m < \\epsilon_m$ in Step 1 of Algorithm~\\ref{al:DAG}.\n\\item [EpsilonX]\nThe variable $\\epsilon_x$ used in the determination criteria\n$\\| \\lambda_i \\, h_i \\| < \\epsilon_x$ in Step 5 of Algorithm~\\ref{al:DAG}.\n\\end{codedescription}\n\n\n% ===============================================\n\n", "meta": {"hexsha": "1ae2dfe03827297fbc7d259c06068e0b9964417a", "size": 9707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/manual/algDisArmGra.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/algDisArmGra.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/algDisArmGra.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": 38.6733067729, "max_line_length": 135, "alphanum_fraction": 0.6657051612, "num_tokens": 3282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6120149766168416}}
{"text": "\\documentclass[11pt]{article}\n\n\\input{preamble}\n\n%\\usepackage{tikz}\n%\\usepackage{tikz-qtree}\n\\usepackage{qtree}\n\\usepackage{xfrac}\n\n\\title{Week 6: Decision Trees and Variational Autoencoders}\n\\author{\\url{http://mlvu.github.io}}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Decision trees}\n\nImagine you do a newspaper round to help you get through these lean times.  On your round, you encounter a number of dogs that either bark or (try to) bite. The dogs are described by the following binary features: \\emph{Heavy}, \\emph{Smelly}, \\emph{Big} and \\emph{Growling}. Consider the following set of examples:\n\n\\begin{center}\n\\begin{tabular}{c  c  c  c  | c }\nHeavy & Smelly &  Big & Growling & Bites \\\\\n\\hline\n\\rc{No}  & \\rc{No} & \\rc{No}  & \\rc{No}  & \\oc{No} \\\\\n\\rc{No}  & \\rc{No} & \\gc{Yes} & \\rc{No}  & \\oc{No} \\\\\n\\gc{Yes} & \\gc{Yes}& \\rc{No}  & \\gc{Yes} & \\oc{No} \\\\\n\\gc{Yes} & \\rc{No} & \\rc{No}  & \\gc{Yes} & \\bc{Yes} \\\\\n\\rc{No}  &\\gc{Yes} & \\gc{Yes} & \\rc{No}  & \\bc{Yes} \\\\\n\\rc{No}  & \\rc{No} & \\gc{Yes} & \\gc{Yes} & \\bc{Yes} \\\\\n\\rc{No}  & \\rc{No} & \\rc{No}  & \\gc{Yes} & \\bc{Yes} \\\\\n\\gc{Yes} &\\gc{Yes} & \\rc{No}  & \\rc{No}  & \\bc{Yes} \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\n\\qu What is the entropy of the target value \\emph{Bites} in the data?\n\\ans{\n\\[H(\\text{Bites})= - \\sfrac{5}{8}\\log_2\\sfrac{5}{8} - \\sfrac{3}{8}\\log_2\\sfrac{3}{8} \\approx 0.9544\\]\n}{}\n\n\\qu Which attribute would the ID3 algorithm choose to use for the root of the tree (without pruning)?\n\\ans{Growling}{}\n\n\\qu What is the information gain of the attribute you chose in the previous question?\n\\ans{approximately 0.0487}{}\n\n\\qu Draw the full decision tree that would be learned for this data using ID3 without pruning.\n\\ans{\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.7\\linewidth]{Tree}\n\\caption{Decision tree}\n\\end{figure}\n}{}\n\n\\qu Suppose three new dogs appear in your round as listed in the table below. Classify them using the tree from the previous question.\n\n\\begin{center}\n\\begin{tabular}{c c c c c | c }\nDog & Heavy & Smelly &  Big & Growling & Bites \\\\\n\\hline\nBuster & \\gc{Yes} & \\gc{Yes} & \\gc{Yes} & \\gc{Yes} & \\ans{\\oc{No}}{?} \\\\\nPluto  & \\rc{No}  & \\gc{Yes} & \\rc{No}  & \\gc{Yes} & \\ans{\\oc{No}}{?} \\\\\nZeus   & \\gc{Yes} & \\gc{Yes} & \\rc{No}  & \\rc{No} & \\ans{\\bc{Yes}}{?} \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\qu Someone proposes a new scheme to prevent overfitting: she suggests to set a pre-defined maximum depth for the decision trees. When the standard algorithm reaches this depth, it terminates. Could this help to prevent overfitting? Why (not)?\n\\ans{\nIt ensures smaller, simpler trees (a smaller model space) and therefore can reduce the risk of overfitting. Overfitting is essentially memorizing too much of your data. Smaller trees can memorize less.\n}{}\n\n\\qu In the maximum depth scheme introduced above, how would you determine a good value for the maximum depth for a given data set?\n\n\\ans{\nThe maximum depth is a \\emph{hyperparameter}. We can choose good values for our hyperparameters by splitting our training data into a validation set and trying different values (either by cross validation or just single runs).}{}\n\n\\qu Why can't we apply L1-regularization to this decision tree learning problem?\n\n\\ans{L1 regularization assumes that your model is described by a real valued vector of parameters (i.e. your model space is continuous.) Decision trees have a \\emph{discrete} model space.}{}\n\n\\section{Variational autoencoders}\n\nThe maximum likelihood principle tells us to optimize the quantity $p(x\\mid \\theta)$ as a function of $\\theta$ (the model parameters).For complex models, this does not usually lead to a closed form solution. Instead, we will rewrite the maximum likelihood objective using the following decomposition.\n\n\\[\n\\ln p(\\x\\mid \\theta) = L(\\rc{q}, \\theta) + KL(\\rc{q}, p) \\\\\n\\]\nwith\n\\begin{align*}\n\\rc{q}(\\z\\mid \\x)\\;&\\text{any distribution on $\\z$} \\\\\nKL(\\rc{q}, p)\\;&\\text{the Kullback-Leibler divergence\\footnotemark}\\\\\n&\\text{between $\\rc{q}(\\z \\mid \\x)$ and $p(\\z \\mid \\x, \\theta)$}\\\\\nL(\\rc{q}, \\theta) &= \\E_\\rc{q} \\ln \\frac{p(\\x, \\z \\mid \\theta) }{\\rc{q}(\\z\\mid \\x)}\n\\end{align*}\n\n\\footnotetext{The KL divergence can be defined using $\\log_2$ or using $\\ln$. The first leads to a value in \\emph{bits}, the second to a value in the slightly more abstract unit of \\emph{nats}. That is, the information distance between the two distributions is the same, but expressed in different units. In the context of the VAE, the natural logarithm $\\ln$ is preferred, mainly because it cancels out neatly against the exponent in the pdf of the normal distribution.\n}\n\nWe will first prove that this equality holds. We start with the right hand side, fill in the components, and derive the left-hand side.\n\n\\qu Fill in the blanks. We have written everything in terms of \\emph{expectations} $\\E$ to simplify the notation. The expectation is over the random variable $\\z$, while $\\x$ has some definite value. Note that $\\E f(\\z) + \\E g(\\z) = \\E\\left [f(\\z) + g(\\z)\\right]$.\n\n\\begin{align*}\nL(\\rc{q}, \\theta) + KL(\\rc{q}, p) &= \\mathbb{E}_\\rc{q} \\ln \\frac{p(\\x, \\z \\mid \\theta) }{\\rc{q}(\\z\\mid \\x)} - \\mathbb{E}_\\rc{q} \\ln \\frac{p(\\z \\mid \\x, \\theta)}{\\rc{q}(\\z\\mid \\x)}\\\\\n&= \\ans{\\E_\\rc{q}  \\ln p(\\x,\\z\\mid \\theta) - \\E_\\rc{q} \\ln \\rc{q}(\\z\\mid \\x) - \\E_\\rc{q} \\ln p(\\z\\mid \\x, \\theta) + \\E_\\rc{q} \\ln \\rc{q}(\\z \\mid \\x)}{\\ldots}\\\\\n&= \\mathbb{E}_\\rc{q} \\ln p(\\x, \\z \\mid \\theta)  - \\mathbb{E}_\\rc{q} \\ln p(\\z \\mid \\x, \\theta) \\\\\n&= \\mathbb{E}_\\rc{q} \\ln \\frac{p(\\x, \\z \\mid \\theta) }{ p(\\z \\mid \\x, \\theta) } = \\ans{\\mathbb{E}_\\rc{q} \\ln \\frac{p(\\z\\mid \\x,  \\theta)p(\\x\\mid \\theta) }{ p(\\z \\mid \\x, \\theta)}}{\\ldots}\\\\\n&= \\mathbb{E}_\\rc{q} \\ln p(\\x \\mid \\theta)  = \\ln p(\\x \\mid \\theta)  \n\\end{align*}\n\nIn EM, we search by alternately (1) optimizing $L(\\rc{q}\\mid \\theta)$ with respect to $\\theta$ and (2) setting $\\rc{q}$ equal to $\\gc{p}$ (so that the KL term becomes zero).\n\n\\qu For the variational autoencoder, we cannot (easily) perform this last step. Why not?\n\\ans{In the variational autoencoder, our model is a neural network that transforms $\\z$ into a distribution on $\\x$. To set the KL divergence term equal to zero, we would have to compute $p(\\z \\mid \\x, \\theta)$: i.e. a probability distribution on $\\z$ that indicates for which $\\z$ our observed $\\x$ is most likely.\n\nWhile sampling techniques exist to approximate this kind of distribution, they are costly and can be very inaccurate.\n}{}\n\n~\\linebreak\nInstead, we \\emph{approximate} $p(\\z \\mid\\x, \\theta)$ with a neural network $\\rc{q_\\bv}(\\z \\mid \\x)$ that produces a distribution on $\\z$ given some $\\x$. We call the neural network computing $p(\\x \\mid \\x, \\theta)$ $\\gc{p_\\bw}(\\x\\mid \\z)$, to make the notation a little more friendly. Here, $\\gc{\\bw}$, stands for all parameters of the \\gc{p} network, and $\\rc{\\bv}$ stands for all parameters of the \\rc{q} network.\\footnotemark \n\n\\footnotetext{We've turned $\\theta$ into $\\gc{\\bw}$ and added parameters $\\rc{\\bv}$ for our approximation $\\rc{q}$ on the conditional distribution on $\\z$. We've also taken the parameters out of the conditional, because we will always talk about the function ``given the parameter''; we will never talk about the probability on the parameters themselves.}\n\nThis gives us an auto-encoder-like structure. An input is mapped to a distribution $\\rc{q_\\bv}(\\z\\mid \\x)$ by the \\rc{encoder}. We sample a single $\\z$ from this distribution and pass it through the \\gc{decoder} $\\gc{p_\\bw}(\\x \\mid \\z)$ to produce a distribution on $\\x$ (see the \\href{https://mlvu.github.io/lectures/51.Deep\\%20Learning2.annotated.pdf}{slides} for diagrams).\n\nTo find a way to train such an architecture, we turn again to our decomposition of the likelihood. In our new notation:\n\\[\n\\ln \\gc{p_\\bw}(\\x) = L(\\rc{\\bv}, \\gc{\\bw}) + KL(\\rc{q}, \\gc{p}) \\p \\\\\n\\]\n\nThe KL divergence term is difficult to compute: it's an expectation, and it contains the function $\\gc{p_\\bw}(\\z \\mid \\x)$ which requires us to invert the \\gc{decoder} neural network (that is, to reason about the inputs given the outputs).\n\nHowever, because the KL divergence is always positive, we know that \n\n\\[\n\\ln \\gc{p_\\bw}(\\x) \\geq L(\\rc{\\bv}, \\gc{\\bw}) \\\\\n\\]\nfor \\emph{any} $\\rc{q_\\bv}$ we choose. This is why $L$ is called the variational \\emph{lower bound}.\\footnotemark~If we choose our parameters $\\gc{\\bw}, \\rc{\\bv}$ to maximize $L$, we are also, indirectly, maximizing $\\ln \\gc{p_\\bw}(\\x)$.\\footnotemark\n\n\\footnotetext{The word \\emph{variational} comes from the fact that one of its arguments, \\rc{q}, is a function (the calculus of functions is called \\emph{variational} calculus). For our purposes, this distinction doesn't matter much, since the function $\\rc{q}$ is defined by a set of parameters $\\rc{\\bv}$, so ultimately we will take the derivative over those parameters, as we are used to.}\n\n\\footnotetext{How close the lower bound $L$ comes to the true value $\\gc{p_\\bw}(\\x)$ depends on how well our encoder network $\\rc{q_\\bv}$ approximates the true conditional distribution on $\\z$: $\\gc{p_\\bw}(\\z \\mid\\x)$. I.e. how small the KL term in the original decomposition is.}\n\nTo do so, we rewrite $L(\\rc{\\bv}, \\gc{\\bw})$ into two separate terms: a KL divergence and an expectation:\n\n\\[\nL(\\rc{\\bv}, \\gc{\\bw}) = - KL(\\rc{q_\\bv}(\\z\\mid\\x), \\gc{p_\\bv}(\\z)) + \\E_\\rc{q_\\bv} \\ln \\gc{p_\\bw}(\\x\\mid \\z)\n\\]\n\n\\qu Show that this equation holds. That is, rewrite the left part into the right. We will assume that all expectations are over $\\rc{q}$.\n\\begin{align*}\n\tL(\\rc{\\bv}, \\gc{\\bw}) &= \\E_\\rc{q} \\ln \\frac{\\gc{p_\\bw}(\\x, \\z)}{\\rc{q_\\bv}(\\z\\mid \\x)} \\\\\n\t&= \\ans{\\E \\ln \\gc{p_\\bw}(\\x, \\z) - \\E \\rc{q_\\bv}(\\z \\mid \\x)}{\\ldots}\\\\\n\t&= \\ans{\\E \\ln \\left[\\gc{p_\\bw}(\\x\\mid \\z)\\gc{p_\\bw}(\\z)\\right] - \\E \\ln \\rc{q_\\bv}(\\z \\mid \\x)}{\\ldots} \\\\\n\t&= \\ans{\\E \\ln \\gc{p_\\bw}(\\x \\mid \\z) + \\E \\ln \\gc{p_\\bw}(\\z) - \\E \\ln \\rc{q_\\bv}(\\z \\mid \\x)}{\\ldots} \\\\\n\t&= \\E \\ln \\gc{p_\\bw}(\\x \\mid \\z) - \\left [ \\E \\ln \\rc{q_\\bv}(\\z \\mid \\x) - \\E \\ln \\gc{p_\\bw}(\\z) \\right ]\\\\\n\t&= \\E \\ln \\gc{p_\\bw} (\\x\\mid \\z) - KL(\\rc{q_\\bv}(\\z\\mid\\x), \\gc{p_\\bw}(\\z)) \n\\end{align*}\n\n\nThus, to optimize our variational autoencoder, we should maximize $L$. In other words, $-L$ is our loss function. The only problem left to solve is that the second term is an expectation (which we cannot compute explicitly). \n\n\\qu How is this solved in practice?\n\n\\ans{We take a single sample from $\\rc{q_\\bv}(\\z\\mid \\x)$ and use $\\ln \\gc{p_\\bw}(\\x\\mid \\z)$ as a (very crude) estimate of the expectation term. \n\nTo let the gradient propagate through the sampling, we add a sample from the standard MVN to the input and transform it to a sample from $\\rc{q_\\bv(\\z\\mid \\x)}$ by multiplying by a matrix $A$ (with $\\Sigma = AA^T$) and adding the mean.}{}\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\n\n\n\n\n", "meta": {"hexsha": "b7620b8c08cfe664f4b1068ac048d67a07a37701", "size": 10750, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week6.tex", "max_stars_repo_name": "mlvu/homework", "max_stars_repo_head_hexsha": "2183b91c2a355279fbe958b1bbc8bd13ea956615", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-02-27T13:25:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-07T07:04:26.000Z", "max_issues_repo_path": "week6.tex", "max_issues_repo_name": "mlvu/homework", "max_issues_repo_head_hexsha": "2183b91c2a355279fbe958b1bbc8bd13ea956615", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week6.tex", "max_forks_repo_name": "mlvu/homework", "max_forks_repo_head_hexsha": "2183b91c2a355279fbe958b1bbc8bd13ea956615", "max_forks_repo_licenses": ["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.75, "max_line_length": 470, "alphanum_fraction": 0.6705116279, "num_tokens": 3591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.705785040214066, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.6119408613242983}}
{"text": "\\chapter{Simulate simple 2D Brownian motion of $\\textbf{\\textit{E.coli}}$} % Main chapter title\n\n\\label{Part1_chapter} % For referencing the chapter elsewhere, use \\ref{Chapter1} \n\n\\section{Symbols}\n\n\\begin{table}[H]\n\\caption{The symbols used in the model of simulating simple 2D Brownian motion of $E.coli$ }\n\\label{tab:part1_symbols}\n\\centering\n\\begin{tabular}{l l}\n\\toprule\n\n\\tabhead{Symbol} & \\tabhead{Definition} \\\\\n\\midrule\n$X(t)$ & Stochastic processes \\\\\n$X_i$ & The direction of movement $X_i = 1,\\ -1$\\\\\n$B(t)$ & Standard Brownian Motion \\\\\n$N(\\mu,\\sigma)$ & Normal distribution with mean $\\mu$ and standard deviation $\\sigma$ \\\\\n% ${\\rm R^{2}_{i}}$ 改成正常体\n$\\Delta x$ & Space interval \\\\\n$\\Delta t$ & Time interval \\\\\n$\\qquad \\sigma  $ & $\\qquad \\sigma = \\Delta x$/$\\sqrt{ \\Delta t}$ \\\\\n$(x,y)$ & Coordinates of $E.coli$ \\\\\n$\\qquad x_t  $ & \\qquad Coordinate in x axis at time t \\\\\n$\\qquad y_t  $ & \\qquad Coordinate in y axis at time t \\\\\n$v$\t\t\t   & The speed of the movement of $E.coli$ \\\\\n\\bottomrule\\\\\n\\end{tabular}\n\\end{table}\n\n\n\\section{Biological background}\n\n$Escherichia \\ coli$ is a Gram-negative, optional anaerobic, rod-shaped, coliform bacterium of the genus Escherichia that is commonly found in the lower intestine of warm-blooded organisms. $E.coli$ are widely used in biological research, cells are typically rod-shaped, and are about 2.0 $\\mu m$ long and 0.25-1.0 $\\mu m$ in diameter, with a cell volume of 0.6-0.7 $\\mu m^3$ . Strains that possess flagella are motile. The flagella have a peritrichous arrangement.It also attaches and effaces to the microvilli of the intestines via an adhesion molecule known as intimin. The thin straight filaments of bacteria called pili, that enable it to attach to specify substrate, and thicker longer helical filaments, called flagella, that enable it to swim.\n\nBrownian motion is the random motion of microscopic particles suspended in a fluid resulting from their collision with the quick atoms or molecules in the liquid or gas. This phenomenon is named after British botanist Robert Brown. In 1827, while looking through a microscope at particles trapped in cavities inside pollen grains in water, Brown noted that the particles moved through the water randomly but failed to explain the mechanisms that caused this movement. He supposed that active molecules were inside those particles thus there was no relationship with the surrounded liquid. \n\nThe Brownian motion is a Gaussian process with time $t$, we can find that, for stochastic processes $\\{X(t),t\\geq0\\}$ :\n\n\\begin{equation*} \n\\begin{aligned} \n\\centering\nX(0) &= 0 \\\\\nX(t) &\\backsim N(0,\\sigma^2t)  \\\\ \nX(t) &= \\Delta x(X_1 + ... + X_{[t/\\Delta t]}) \\\\\n\\sigma^2 &=  \\frac{(\\Delta x)^2}{\\Delta t} \\\\\n\\end{aligned} \n\\end{equation*}\n\n\\newpage\nNormally, we set $\\sigma=1$ and defines this kind of stochastic processes $\\{X(t),t\\geq0\\}$ as \\textbf{Standard Brownian Motion} and they could be denote as $\\{B(t),t\\geq0\\}$, where :\n\n\\begin{equation*} \n\\begin{aligned} \n\\centering\nB(0) &= 0 \\\\\nB(t) &\\backsim N(0,t)  \\\\ \n\\end{aligned} \n\\end{equation*}\n\n\\section{Hypothesis for simulation}\n\nAssuming the $E.coli$ here have no mitosis, so the number of cells maintain constant.\nI use $(x,y)$ to define the location of each cell, assume all the cells start from origin$(0,0)$. They have a random judging for each step in both x and y directions. Set the speed as $50 \\mu m/s$, so for each step,\n\n\n\\begin{equation*} \n\\begin{aligned} \n\\centering\n\\phi_x &\\backsim N(0,1) \\\\\n\\phi_y &\\backsim N(0,1) \\\\\nx_{t+1}  &=  x_{t} + \\phi_x v \\\\ \ny_{t+1}  &=  y_{t} + \\phi_y v \\\\ \n\\end{aligned} \n\\end{equation*}\nThe move on both x and y directions are random and it follows the Brownian motion.\\\\\nSo in theory, for a $E.coli$ population large enough, we have: \\\\\n\\begin{equation*} \n\\begin{aligned} \n\\centering\n\\frac{1}{n} \\sum_{i=1}^{n}x_i(t)   &\\approx 0 \\\\\n\\frac{1}{n} \\sum_{i=1}^{n}y_i(t)   &\\approx 0 \\\\\n\\frac{1}{n} \\sum_{i=1}^{n}x_i(t)^2 &\\approx v^2t  = 250t \\\\\n\\frac{1}{n} \\sum_{i=1}^{n}y_i(t)^2 &\\approx v^2t  = 250t \\\\\n\\end{aligned} \n\\end{equation*}\n%----------------------------------------------------------------------------------------\n%\\newpage\n\\section{Results of simulation}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\linewidth]{Figures/P1_fig1.png}\n\\caption{The simulation of 10000 $E.coli$ cells for simple 2D Brownian motion form (0,0) after 100s}\n\\label{P1_fig1}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\linewidth]{Figures/P1_fig2.png}\n\\caption{The ”mean displacement” and ”mean displacement-square” overtime for simple 2D brownic motion}\n\\label{P1_fig2}\n\\end{figure}\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\linewidth]{Figures/P1_fig3.png}\n\\caption{Single Bacteria Random Walk Trajectory}\n\\label{P1_fig2}\n\\end{figure}\n\n\n%----------------------------------------------------------------------------------------\n\n\n\n\n\n\n\n%----------------------------------------------------------------------------------------\n\n\n\n%----------------------------------------------------------------------------------------\n\n\n\n\n%The \\code{biblatex} package is used to format the bibliography and inserts references such as this one \\parencite{Reference1}. The options used in the \\file{main.tex} file mean that the in-text citations of references are formatted with the author(s) listed with the date of the publication. Multiple references are separated by semicolons (e.g. \\parencite{Reference2, Reference1}) and references with more than three authors only show the first author with \\emph{et al.} indicating there are more authors (e.g. \\parencite{Reference3}). This is done automatically for you. To see how you use references, have a look at the \\file{Chapter1.tex} source file. Many reference managers allow you to simply drag the reference into the document as you type.\n\n", "meta": {"hexsha": "5f997a7c9a1dac4f09b25cb2c3c6d83e28394da2", "size": 5837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/Chapters/Chapter1.tex", "max_stars_repo_name": "c235gsy/Sustech_Systems-Biology", "max_stars_repo_head_hexsha": "bd72b7e7d1238e22901b410b3254a4622d249964", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW3/Chapters/Chapter1.tex", "max_issues_repo_name": "c235gsy/Sustech_Systems-Biology", "max_issues_repo_head_hexsha": "bd72b7e7d1238e22901b410b3254a4622d249964", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW3/Chapters/Chapter1.tex", "max_forks_repo_name": "c235gsy/Sustech_Systems-Biology", "max_forks_repo_head_hexsha": "bd72b7e7d1238e22901b410b3254a4622d249964", "max_forks_repo_licenses": ["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.5597014925, "max_line_length": 751, "alphanum_fraction": 0.6772314545, "num_tokens": 1678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562643, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6119249342360918}}
{"text": "\\section{Cubical diagrams}\n\nIn this lecture we study commuting diagrams of the form\n\\begin{equation*}\n  \\begin{tikzcd}\n    & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n    A' \\arrow[d] & C \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\n    A \\arrow[dr] & X' \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n    & X.\n  \\end{tikzcd}\n\\end{equation*}\nIn these diagrams there are six homotopies witnessing that the faces of the cube commute, as well as a homotopy of homotopies witnessing that the cube as a whole commutes.\n\nOnce the basic definitions of cubes are established, we focus on pullbacks and pushouts that appear in different configurations in these cubical diagrams. For example, if all the vertical maps in a commuting cube are equivalences, then the top square is a pullback square if and only if the bottom square is a pullback square. In \\cref{chap:descent} we will use cubical diagrams in our formulation of the universality and descent theorems for pushouts.\n\nIn our first main theorem of this lecture we show that given a commuting cube in which the bottom square is a pullback square, the top square is a pullback square if and only if the induced square of fibers of the vertical maps is a pullback square. This theorem should be compared to \\cref{cor:pb_fibequiv}, where we showed that a square is a pullback square if and only if it induces equivalences on the fibers of the vertical maps.\n\nIn our second main theorem we use the previous result to derive the 3-by-3 properties for pullbacks and pushouts.\n\n\\subsection{Commuting cubes}\n\\begin{defn}\\label{defn:cube}\nA \\define{commuting cube}\\index{commuting cube|textbf}\n\\begin{equation*}\n\\begin{tikzcd}[column sep=large,row sep=large]\n& C' \\arrow[dl,swap,\"{p'}\"] \\arrow[dr,\"{q'}\"] \\arrow[d,swap,\"{h_C}\" near end] \\\\\nA' \\arrow[d,swap,\"{h_A}\"] & C \\arrow[dl,swap,\"{p}\" very near start] \\arrow[dr,\"{q}\" very near start] & B' \\arrow[dl,crossing over,\"{g'}\" near end] \\arrow[d,\"{h_B}\"] \\\\\nA \\arrow[dr,swap,\"f\"] & X' \\arrow[d,swap,\"{h_X}\" near start] \\arrow[from=ul,crossing over,swap,\"{f'}\" near end] & B \\arrow[dl,\"{g}\"] \\\\\n& X,\n\\end{tikzcd}\n\\end{equation*}\nconsists of types and maps as indicated in the diagram, equipped with\n\\begin{enumerate}\n\\item homotopies\n  \\begin{align*}\n    \\mathsf{top} & : f' \\circ p' \\htpy g' \\circ q' \\\\\n    \\mathsf{back\\usc{}left} & : p \\circ h_C \\htpy h_A \\circ p' \\\\\n    \\mathsf{back\\usc{}right} & : q \\circ h_C \\htpy h_B \\circ q' \\\\\n    \\mathsf{front\\usc{}left} & : f \\circ h_A \\htpy h_X \\circ f' \\\\\n    \\mathsf{front\\usc{}right} & : g \\circ h_B \\htpy h_X \\circ g' \\\\\n    \\mathsf{bottom} & : f \\circ p \\htpy g \\circ q\n  \\end{align*}\n  witnessing that the 6 faces of the cube commute,\n\\item and a homotopy \n  \\begin{align*}\n    % ((((h ·l back-left) ∙h (front-left ·r f')) ∙h (hD ·l top))) ~\n    % ((bottom ·r hA) ∙h ((k ·l back-right) ∙h (front-right ·r g')))\n\\mathsf{coh\\usc{}cube} & : \\ct{(\\ct{(f \\cdot \\mathsf{back\\usc{}left})}{(\\mathsf{front\\usc{}left}\\cdot p')})}{(h_X \\cdot \\mathsf{top})} \\\\\n& \\qquad \\htpy \\ct{(\\mathsf{bottom}\\cdot h_C)}{(\\ct{(g \\cdot \\mathsf{back\\usc{}right})}{(\\mathsf{front\\usc{}right}\\cdot q')})}\n\\end{align*}\nfilling the cube.\n\\end{enumerate}\n\\end{defn}\n\nIn the following lemma we show that if a cube commutes, then so do its rotations and mirror symmetries (that preserve the directions of the arrows).\\footnote{The group acting on commuting cubes of maps is the \\emph{dihedral group} $D_3$ which has order $6$.} This fact is obviously true, but there is some `path algebra' involved that we wish to demonstrate at least once.\n\n\\begin{lem}\n  Consider a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      A' \\arrow[d] & C \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\n      A \\arrow[dr] & X' \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n      & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  Then the cubes\n\n  \\begin{center}\n  \\begin{minipage}{.3\\textwidth}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      C \\arrow[d] & B' \\arrow[dl] \\arrow[dr] & A' \\arrow[dl,crossing over] \\arrow[d] \\\\\n      B \\arrow[dr] & A \\arrow[from=ul,crossing over] \\arrow[d] & X' \\arrow[dl] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  \\end{minipage}\n  \\begin{minipage}{.3\\textwidth}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      B' \\arrow[d] & A' \\arrow[dl] \\arrow[dr] & C \\arrow[dl,crossing over] \\arrow[d] \\\\\n      X' \\arrow[dr] & B \\arrow[from=ul,crossing over] \\arrow[d] & A \\arrow[dl] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  \\end{minipage}\n\n  \\begin{minipage}{.3\\textwidth}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      C \\arrow[d] & A' \\arrow[dl] \\arrow[dr] & B' \\arrow[dl,crossing over] \\arrow[d] \\\\\n      A \\arrow[dr] & B \\arrow[from=ul,crossing over] \\arrow[d] & X' \\arrow[dl] \\\\\n      & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  \\end{minipage}\n  \\begin{minipage}{.3\\textwidth}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      A' \\arrow[d] & B' \\arrow[dl] \\arrow[dr] & C \\arrow[dl,crossing over] \\arrow[d] \\\\\n      X' \\arrow[dr] & A \\arrow[from=ul,crossing over] \\arrow[d] & B \\arrow[dl] \\\\\n      & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  \\end{minipage}\n  \\begin{minipage}{.3\\textwidth}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[d] \\arrow[dr] \\\\\n      B' \\arrow[d] & C \\arrow[dl] \\arrow[dr] & A' \\arrow[dl,crossing over] \\arrow[d] \\\\\n      B \\arrow[dr] & X' \\arrow[from=ul,crossing over] \\arrow[d] & A \\arrow[dl] \\\\\n      & X.\n    \\end{tikzcd}\n  \\end{equation*}\n  \\end{minipage}\n  \\end{center}\n  also commute.\n\\end{lem}\n\n\\begin{proof}\n  We only show that the first cube commutes, which is obtained by a counter-clockwise rotation of the original cube around the axis through $C'$ and $X$. The other cases are similar, and they are formalized in the Agda library for this course.\n\n  First we list the homotopies witnessing that the faces of the cube commute:\n  \\begin{align*}\n    \\mathsf{top}' & \\defeq \\mathsf{back\\usc{}left} \\\\\n    \\mathsf{back\\usc{}left}' & \\defeq \\mathsf{back\\usc{}right}^{-1} \\\\\n    \\mathsf{back\\usc{}right}' & \\defeq \\mathsf{top}^{-1} \\\\\n    \\mathsf{front\\usc{}left}' & \\defeq \\mathsf{bottom}^{-1} \\\\\n    \\mathsf{front\\usc{}right}' & \\defeq \\mathsf{front\\usc{}left}^{-1} \\\\\n    \\mathsf{bottom}' & \\defeq \\mathsf{front\\usc{}right}. \n  \\end{align*}\n  Thus, to show that the cube commutes, we have to show that there is a homotopy of type\n  \\begin{align*}\n    & \\ct{(\\ct{(g \\cdot \\mathsf{back\\usc{}right}^{-1})}{(\\mathsf{bottom}^{-1}\\cdot h_C)})}{(f \\cdot \\mathsf{back\\usc{}left})} \\\\\n    & \\qquad\\qquad \\htpy \\ct{(\\mathsf{front\\usc{}right}\\cdot q')}{(\\ct{(h_X \\cdot \\mathsf{top}^{-1})}{(\\mathsf{front\\usc{}left}^{-1}\\cdot p')})}.\n  \\end{align*}\n  In other words, we need to construct a path\n  \\begin{align*}\n    & \\ct{(\\ct{\\ap{g}{\\mathsf{back\\usc{}right}(c')^{-1}}}{\\mathsf{bottom}(h_C(c'))^{-1}})}{\\ap{f}{\\mathsf{back\\usc{}left}(c')}} \\\\\n    & \\qquad\\qquad \\htpy \\ct{\\mathsf{front\\usc{}right}(q'(c'))}{(\\ct{\\ap{h_X}{\\mathsf{top}(c')^{-1}}}{\\mathsf{front\\usc{}left}(p'(c'))^{-1}})}\n  \\end{align*}\n  for every $c':C'$. Recall that $\\ap{g}{\\mathsf{back\\usc{}right}(c')^{-1}}=\\ap{g}{\\mathsf{back\\usc{}right}(c')}^{-1}$. Using the action on paths of the concatenation function (twice), we see that\n  \\begin{align*}\n    & \\ct{(\\ct{\\ap{g}{\\mathsf{back\\usc{}right}(c')^{-1}}}{\\mathsf{bottom}(h_C(c'))^{-1}})}{\\ap{f}{\\mathsf{back\\usc{}left}(c')}} \\\\\n    & \\qquad\\qquad \\ct{(\\ct{\\ap{g}{\\mathsf{back\\usc{}right}(c')}^{-1}}{\\mathsf{bottom}(h_C(c'))^{-1}})}{\\ap{f}{\\mathsf{back\\usc{}left}(c')}}.\n  \\end{align*}\n  Similarly, we have an identification\n  \\begin{align*}\n    & \\ct{\\mathsf{front\\usc{}right}(q'(c'))}{(\\ct{\\ap{h_X}{\\mathsf{top}(c')}^{-1}}{\\mathsf{front\\usc{}left}(p'(c'))^{-1}})} \\\\\n    & \\qquad\\qquad \\htpy \\ct{\\mathsf{front\\usc{}right}(q'(c'))}{(\\ct{\\ap{h_X}{\\mathsf{top}(c')^{-1}}}{\\mathsf{front\\usc{}left}(p'(c'))^{-1}})}\n  \\end{align*}\n  Therefore it suffices to construct an identification\n  \\begin{align*}\n    & \\ct{(\\ct{\\ap{g}{\\mathsf{back\\usc{}right}(c')}^{-1}}{\\mathsf{bottom}(h_C(c'))^{-1}})}{\\ap{f}{\\mathsf{back\\usc{}left}(c')}} \\\\\n    & \\qquad\\qquad \\htpy \\ct{\\mathsf{front\\usc{}right}(q'(c'))}{(\\ct{\\ap{h_X}{\\mathsf{top}(c')}^{-1}}{\\mathsf{front\\usc{}left}(p'(c'))^{-1}})}\n  \\end{align*}\n  Now we note that our goal is of the form\n  \\begin{equation*}\n    \\ct{(\\ct{\\varepsilon^{-1}}{\\delta^{-1}})}{\\beta}=\\ct{\\zeta}{(\\ct{\\gamma^{-1}}{\\beta^{-1}})}, %%% check greek alphabet\n  \\end{equation*}\n  whereas the assumption that the original cube commutes yields an identification of the form\n  \\begin{equation*}\n    \\ct{(\\ct{\\alpha}{\\beta})}{\\gamma}=\\ct{\\delta}{(\\ct{\\varepsilon}{\\zeta})}\n  \\end{equation*}\n  Indeed, in the case that $\\alpha$, $\\beta$, $\\gamma$, $\\delta$, $\\varepsilon$, and $\\zeta$ are general identifications, we can conclude our goal using path induction on all of them.\n\\end{proof}\n\n\\begin{lem}\nGiven a commuting cube as in \\cref{defn:cube} we obtain a commuting square\n\\begin{equation*}\n\\begin{tikzcd}\n\\fib{f_{1\\check{1}1}}{x} \\arrow[r] \\arrow[d] & \\fib{f_{0\\check{1}1}}{f_{\\check{1}01}(x)} \\arrow[d] \\\\\n\\fib{f_{1\\check{1}0}}{f_{10\\check{1}}(x)} \\arrow[r] & \\fib{f_{0\\check{1}0}}{f_{00\\check{1}}(x)}\n\\end{tikzcd}\n\\end{equation*}\nfor any $x:A_{101}$. \n\\end{lem}\n\n\\begin{lem}\nConsider a commuting cube\n\\begin{equation*}\n\\begin{tikzcd}\n& A_{111} \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\nA_{110} \\arrow[d] & A_{101} \\arrow[dl] \\arrow[dr] & A_{011} \\arrow[dl,crossing over] \\arrow[d] \\\\\nA_{100} \\arrow[dr] & A_{010} \\arrow[d] \\arrow[from=ul,crossing over] & A_{001} \\arrow[dl] \\\\\n& A_{000}.\n\\end{tikzcd}\n\\end{equation*}\nIf the bottom and front right squares are pullback squares, then the back left square is a pullback if and only if the top square is.\n\\end{lem}\n\n\\begin{rmk}\nBy rotating the cube we also obtain:\n\\begin{enumerate}\n\\item If the bottom and front left squares are pullback squares, then the back right square is a pullback if and only if the top square is.\n\\item If the front left and front right squares are pullback, then the back left square is a pullback if and only if the back right square is.\n\\end{enumerate}\nBy combining these statements it also follows that if the front left, front right, and bottom squares are pullback squares, then if any of the remaining three squares are pullback squares, all of them are. Cubes that consist entirely of pullback squares are sometimes called \\define{strongly cartesian}\\index{strongly cartesian cube}.\n\\end{rmk}\n\n\\subsection{Families of pullbacks}\n\n\\begin{lem}\\label{lem:fiberwise-pullback}\nConsider a pullback square\\index{pullback!Sigma-type of pullbacks@{$\\Sigma$-type of pullbacks}}\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*}\n  with $H : f \\circ p \\htpy g \\circ h$. Furthermore, consider type families $P_X$, $P_A$, $P_B$, and $P_C$ over $X$, $A$, $B$, and $C$ respectively, equipped with families of maps\n  \\begin{align*}\n    f' & : \\prd{a:A} P_A(a) \\to P_X(f(a)) \\\\\n    g' & : \\prd{b:B} P_B(b) \\to P_X(g(b)) \\\\\n    p' & : \\prd{c:C} P_C(c) \\to P_A(p(c)) \\\\\n    q' & : \\prd{c:C} P_C(c) \\to P_B(q(c)),\n  \\end{align*}\n  and for each $c:C$ a homotopy $H'_c$ witnessing that the square\n  \\begin{equation}\\label{eq:family-squares-pullback}\n    \\begin{tikzcd}\n      P_C(c) \\arrow[rr,\"{q'_c}\"] \\arrow[d,swap,\"{p'_c}\"] & &[3em] P_B(q(c)) \\arrow[d,\"{g'_{q(c)}}\"] \\\\\n      P_A(p(c)) \\arrow[r,swap,\"{f'_{p(c)}}\"] & P_X(f(p(c))) \\arrow[r,swap,\"{\\tr_{P_X}(H(c))}\"] & P_X(g(q(c)))\n    \\end{tikzcd}\n  \\end{equation}\n  commutes. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item For each $c:C$ the square in \\cref{eq:family-squares-pullback} is a pullback square.\n  \\item The square\n    \\begin{equation}\\label{eq:total-square-pullback}\n      \\begin{tikzcd}[column sep=huge]\n        \\sm{c:C}P_C(c)\n        \\arrow[r,\"{\\total[q]{q'}}\"] \\arrow[d,swap,\"{\\total[p]{p'}}\"] &\n        \\sm{b:B}P_B(b) \\arrow[d,\"{\\total[g]{g'}}\"] \\\\\n        \\sm{a:A}P_A(a) \\arrow[r,swap,\"{\\total[f]{f'}}\"] & \\sm{x:X}P_X(x)\n      \\end{tikzcd}\n    \\end{equation}\n    is a pullback square.\n  \\end{enumerate}\n\\end{lem}\n\n\n\\begin{cor}\nConsider a pullback square\n\\begin{equation*}\n\\begin{tikzcd}\nC \\arrow[r,\"q\"] \\arrow[d,swap,\"p\"] & B \\arrow[d,\"g\"] \\\\\nA \\arrow[r,swap,\"f\"] & X,\n\\end{tikzcd}\n\\end{equation*}\nwith $H:f\\circ p\\htpy g\\circ q$, and let $c_1,c_2:C$. Then the square\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n(c_1=c_2) \\arrow[r,\"\\apfunc{q}\"] \\arrow[d,swap,\"\\apfunc{p}\"] & (q(c_1)=q(c_2)) \\arrow[d,\"\\lam{\\beta}\\ct{H(c_1)}{\\ap{g}{\\beta}}\"] \\\\\n(p(c_1)=p(c_2)) \\arrow[r,swap,\"\\lam{\\alpha}\\ct{\\ap{f}{\\alpha}}{H(c_2)}\"] & f(p(c_1))=g(q(c_2)),\n\\end{tikzcd}\n\\end{equation*}\ncommutes and is a pullback square.\n\\end{cor}\n\n\n\\begin{thm}\n  Consider a commuting cube\n  \\begin{equation*}\n    \\begin{tikzcd}\n      & C' \\arrow[dl] \\arrow[dr] \\arrow[d] \\\\\n      A' \\arrow[d] & C \\arrow[dl] \\arrow[dr] & B' \\arrow[crossing over,dl] \\arrow[d] \\\\\n      A \\arrow[dr] & X' \\arrow[d] \\arrow[from=ul,crossing over] & B \\arrow[dl] \\\\\n      & X\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the bottom square is a pullback square. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The top square is a pullback square.\n  \\item The square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        \\fib{\\gamma}{c} \\arrow[d] \\arrow[r] & \\fib{\\beta}{q(c)} \\arrow[d] \\\\\n        \\fib{\\alpha}{p(c)} \\arrow[r] & \\fib{\\varphi}{f(p(c))}\n      \\end{tikzcd}\n    \\end{equation*}\n    is a pullback square for each $c:C$.\n  \\end{enumerate}\n\\end{thm}\n\n\n\\subsection{The 3-by-3-properties for pullbacks and pushouts}\n\n\\begin{thm}\n  Consider a commuting diagram of the form\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=large,row sep=large]\n      AA \\arrow[r,\"Af\"] \\arrow[d,swap,\"fA\"] \\arrow[dr,phantom,\"\\Rightarrow\" description] & AX \\arrow[d,swap,\"fX\"] & AB \\arrow[l,swap,\"Ag\"] \\arrow[d,\"gB\"] \\arrow[dl,phantom,\"\\Leftarrow\" description] \\\\\n      XA \\arrow[r,\"Xf\"] & XX & XB \\arrow[l,swap,\"Xg\"] \\\\\n      BA \\arrow[u,\"gA\"] \\arrow[r,swap,\"Bf\"] & BX \\arrow[u,\"gX\"] & BB \\arrow[u,swap,\"gB\"] \\arrow[l,\"Bg\"]\n    \\end{tikzcd}\n  \\end{equation*}\n  with homotopies\n  \\begin{align*}\n    ff & : Xf \\circ fA \\htpy Af \\circ fX \\\\\n    fg & : Xg \\circ gB \\htpy Ag \\circ fX \\\\\n    gf & : \n  \\end{align*}\n  filling the (small) squares. Furthermore, consider\n  pullback squares\n  \\begin{equation*}\n    \\begin{tikzcd}\n      AC \\arrow[r] \\arrow[d] & AB \\arrow[d] & XC \\arrow[r] \\arrow[d] & XB \\arrow[d] & BC \\arrow[r] \\arrow[d] & BB \\arrow[d] \\\\\n      AA \\arrow[r] & AX & XA \\arrow[r] & XX & BA \\arrow[r] & BX\n    \\end{tikzcd}\n  \\end{equation*}\n  \\begin{equation*}\n    \\begin{tikzcd}\n      CA \\arrow[r] \\arrow[d] & BA \\arrow[d] & CX \\arrow[r] \\arrow[d] & BX \\arrow[d] & CB \\arrow[r] \\arrow[d] & BB \\arrow[d] \\\\\n      AA \\arrow[r] & XA & AX \\arrow[r] & XX & AB \\arrow[r] & XB.\n    \\end{tikzcd}\n  \\end{equation*}\n  Finally, consider a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      D_3 \\arrow[r] \\arrow[d] & D_2 \\arrow[d] \\\\\n      D_0 \\arrow[r] & D_1.\n    \\end{tikzcd}\n  \\end{equation*}\n  Then the following are equivalent:\n  \\begin{enumerate}\n  \\item This square is a pullback square.\n  \\item The induced square\n    \\begin{equation*}\n      \\begin{tikzcd}\n        D_3 \\arrow[r] \\arrow[d] & C_3 \\arrow[d] \\\\\n        A_3 \\arrow[r] & B_3\n      \\end{tikzcd}\n    \\end{equation*}\n    is a pullback square.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  First we construct an equivalence\n  \\begin{equation*}\n    (A_0\\times_{B_0}C_0)\\times_{(A_1\\times_{B_1}C_1)}(A_2\\times_{B_2} C_2) \\eqvsym (A_0\\times_{A_1}A_2)\\times_{(B_0\\times_{B_1} B_2)} (C_0\\times_{C_1}C_2).\n  \\end{equation*}\n  Now it follows that we have an equivalence\n  \\begin{equation*}\n    \\mathsf{cone}(f_0,g_0)\n  \\end{equation*}\n\\end{proof}\n\n\n\\begin{exercises}\n\\item Some exercises.\n\\end{exercises}\n", "meta": {"hexsha": "c447d9e0d2466081c10135ee22b4933f0b94834e", "size": 16047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/cubical.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/cubical.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/cubical.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": 44.9495798319, "max_line_length": 452, "alphanum_fraction": 0.6267838225, "num_tokens": 5952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6119249160125819}}
{"text": "\\section{More refined sparse grid and improved estimates}\nThis section presents a modified estimate \\cite{bungartz2004sparse} of the approximation property of sparse grids. Recall \n$$\n\\mathcal V_{\\mathbf{k}} = \\mathcal V_{k_1} \\bigotimes  \\mathcal V_{k_2}\\bigotimes\\cdots \\bigotimes  \\mathcal V_{k_d},\n$$\nwhere $\\mathbf{k}=(k_1,k_2,\\cdots,k_d)$ is a multi-index. Let \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}|_\\infty\\le J\\}.\n$$ \n\n\n\n\nRecall $\\mathcal V_{\\mathbf{k}}$ in \\eqref{sparseVk}. Let\n$$\nR_J=\\left\\{\\mathbf{k}: |\\mathbf{k}|_1 - \\frac25 \\log_2\\|2^{\\mathbf{k}}\\|_{l^2}\\le J+d-1- \\frac15 \\log_2 (4^J +4d-4)\\right\\},\n$$\n\\begin{equation}\n  \\label{sparseVJ}\nS_J =\\bigoplus_{\\mathbf{k}\\in R_J} \\mathcal V_{\\mathbf{k}}.  \n\\end{equation}\nThe following the result is analyzed in \\cite{bungartz2004sparse}.\n \\begin{theorem}\\Label{lm:modifySparse1}\nSuppose that  $u\\in W^{2\\mathbf{e}, \\infty}(D_d)$,\n$$\n\\inf_{\\chi\\in S_J} |v-\\chi|_{1, D_d}\\le C h_J \\|u\\|_{2\\mathbf{e},\\infty}.\n$$\nand the dimension of $S_J$ is $\\mathcal{O}(de^dh_J^{-1})$.\n\\end{theorem}\n\\begin{proof}\nFirst, we prove that $S_J$ is a subspace of $S_{J,J+d-1}^d$.\nIf $|\\mathbf{k}|_{1}=J+d-1+i, i  \\in \\mathbb{N}$, we can prove \n$$\n\\|2^{\\mathbf{k}}\\|_{l^2}^2=\\sum_{s=1}^{d} 4^{k_{s}}\\le 4^{J+i}+4 d-4\n$$\n by induction with respect to $d$. \n% It is trivial when $d=1$. For $\\mathbf{k}\\in \\mathbb{R}^d$ and $|\\mathbf{k}|_{1}=J+d-1+i$, there exists $1\\le j\\le d$ such that $k_j\\ge 1$, thus\n%\\begin{equation}\n%\\begin{split}\n%\\sum_{s=1}^{d} 4^{k_{s}} &= \\sum_{s=1, s\\neq i}^{d} 4^{k_{s}} + 4^{k_{j}}\\le 4^{J+i+1-k_j}+4 (d-1)-4 + 4^{k_j}\\le 4^{J+i} + 4d-4.\n%\\end{split}\n%\\end{equation}\nFor subspaces $\\mathcal V_{\\mathbf{k}}$ with $|\\mathbf{k}|_{1}=J+d-1+i, i \\in \\mathbb{N},$ we have\n\\begin{equation}\n\\begin{split}\n|\\mathbf{k}|_{1}-\\frac{1}{5} \\cdot \\log _{2}\\left(\\sum_{s=1}^{d} 4^{k_{s}}\\right) & \\geq J+d-1+i-\\frac{1}{5} \\cdot \\log _{2}\\left(4^{J+i}+4 d-4\\right) \\\\\n& \\geq J+d-1+i-\\frac{1}{5} \\cdot \\log _{2}\\left(4^{i}\\left(4^{J}+4 d-4\\right)\\right) \\\\\n&>J+d-1-\\frac{1}{5} \\cdot \\log _{2}\\left(4^{J}+4 d-4\\right)\n\\end{split}\n\\end{equation}\nTherefore, no $\\mathcal V_{\\mathbf{k}}$ with $|\\mathbf{k}|_{1}>J+d-1$ can belong to $V_J .$ Consequently,  \n\\begin{equation}\nS_J\\subset S_{J,J+d-1}^d,\\qquad \\left|S_J\\right| \\leq\\left|S_{J,J+d-1}^d\\right|.\n\\end{equation}\n\nThen, we prove that  the dimension of $S_J$ is $\\mathcal{O}(h_J^{-1})$. \nNote that $\\left|\\mathcal V_{\\mathbf{k}}\\right| = 2^{|\\mathbf{k}|_{1}-d}$. For any $\\mathbf{k}\\in R_J$ with $|\\mathbf{k}|_{1}=J+d-1-i$, $ \\sum_{j=1}^d 4^{k_j}\\ge {4^J+4d-4\\over 32^i}$. By \\eqref{sparseVJ},\n\\begin{equation}\n\\begin{split}\n\\mbox{dim}S_J&=\\sum_{i=0}^{J-1}  \\sum_{|\\mathbf{k}|_{1}=J+d-1-i, \\sum_{j=1}^d 4^{k_j}\\ge {4^J+4d-4\\over 32^i}} \\mbox{dim}\\mathcal V_{\\mathbf{k}}\n\\\\\n&=2^{J-1} \\cdot \\sum_{i=0}^{J-1} 2^{-i}  \\sum_{|\\mathbf{k}|_{1}=J+d-1-i, \\sum_{j=1}^d 4^{k_j}\\ge {4^J+4d-4\\over 32^i}}1\n\\\\\n& \\leq 2^{J-1} \\cdot \\lim _{J \\rightarrow \\infty} \\sum_{i=0}^{J-1} 2^{-i} \\sum_{|\\mathbf{k}|_{1}=J+d-1-i, \\sum_{j=1}^d 4^{k_j}\\ge {4^J+4d-4\\over 32^i}}1\n\\\\\n&=2^{J-1} d \\lim _{J \\rightarrow \\infty} \\sum_{i=0}^{J-1} 2^{-i}  \\left(\\begin{array}{c}\nd-1+\\lfloor 1.5 i\\rfloor \\\\\nd-1\n\\end{array}\\right).\n\\end{split}\n\\end{equation} \nLet $j=\\lfloor 1.5 i\\rfloor $. Since $\\displaystyle\\sum_{i=0}^{\\infty} x^{i} \\cdot\\left(\\begin{array}{c}k+i \\\\ k\\end{array}\\right)=(1-x)^{-k-1}$ for $k \\in \\mathbb{N}_{0}$ and $0<x<1$,\n\\begin{equation}\n\\begin{split}\n\\mbox{dim}S_J\n& \\leq 2^{J} \\cdot \\frac{d}{2} \\cdot \\sum_{j=0}^{\\infty} 2^{-\\frac{2}{3} j} \\cdot\\left(\\begin{array}{c}\nd-1+j \\\\\nd-1\n\\end{array}\\right) \n\\\\\n&=2^{J} \\cdot \\frac{d}{2} \\cdot\\left(1-2^{-\\frac{2}{3}}\\right)^{-d}\n\\\\\n& \\leq 2^{J} \\cdot \\frac{d}{2} \\cdot \\mathrm{e}^{d}=\\mathcal{O}(h_J^{-1}).\n\\end{split}\n\\end{equation} \nNext we consider the approximation property of $S_J$. Let $\\displaystyle u_J=\\sum_{\\mathbf{k}\\in R_J}u_{\\mathbf{k}}$. Note that \n$$\n\\left|u-u_J\\right|_1 \\leq\\left|u-u_{J,J+d-1}\\right|_1+\\left|u_{J,J+d-1}-u_J\\right|_1.\n$$\nBy $\\left|u-u_{J,J+d-1}\\right|_1=O\\left(h_{J}\\right),$ we can restrict ourselves to $\\left|u_{J,J+d-1}-u_J\\right|_1.$ Note that  for $i \\in \\mathbb{N}_{0},$ \n\\begin{equation}\n\\mathcal V_{\\mathbf{k}}\\subset S_J, \\quad \\mbox{if } |\\mathbf{k}|_{1}=J+d-1-i \\ \\mbox{ and }\\ |\\mathbf{k}|_{\\infty} \\geq J-2.5 i.\n\\end{equation}\nNote that \n$$\n\\left|u_{J,J+d-1}-u_J\\right|_1\\leq \\sum_{\\mathcal V_{\\mathbf k} \\in S_{J,J+d-1}^d \\setminus S_J}\\left|u_{\\mathbf{k}}\\right|_1\n\\leq \\sum_{i=0}^{i^{*}} \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left|u_{\\mathbf{k}}\\right|_1,\n$$\nwhere $i^*$ is the maximum value of $i$ for which the set of indices $\\mathbf{k}$ with $|\\mathbf{k}|_1=n+d-1-i$ with $|\\mathbf{k}|_\\infty<n-2.5i$. \nTherefore, we obtain with \\eqref{sparseuk} that\n\\begin{equation*}\n\\begin{aligned}\n \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left|u_{\\mathbf{k}}\\right|_1\n \\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}}  \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i} 4^{-|\\mathbf{k}|_{1}} \\cdot\\left(\\sum_{j=1}^{d} 4^{k_{j}}\\right)^{1 / 2}.\n \\end{aligned}\n\\end{equation*}\nSince\n$\n\\displaystyle \\sum_{j=1}^{d} 4^{k_{j}}=\\sum_{j=1}^{d} 2^{2k_{j}}\\leq \\left(\\sum_{j=1}^{d} 2^{k_{j}}\\right)^2,\n$\n\\begin{equation*}\n\\begin{aligned}\n \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left|u_{\\mathbf{k}}\\right|_1 \n&\\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} \\cdot 4^{-J-d+1+i}  \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left(\\sum_{j=1}^{d} 2^{k_{j}}\\right)\n\\\\\n&\\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} \\cdot 4^{-J-d+1+i}  \\sum_{j=1}^{J-1-\\lfloor 2.5 i\\rfloor} d \\cdot\\left(\\begin{array}{c}\nJ+d-2-i-j \\\\\nd-2\n\\end{array}\\right) \\cdot 2^{j}\n\\\\\n&=\\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} 4^{-J-d+1+i} \\sum_{k=1}^{J-1-\\lfloor 2.5 i\\rfloor} d\\left(\\begin{array}{c}\nd-2+\\lfloor 1.5 i\\rfloor+k \\\\\nd-2\n\\end{array}\\right) 2^{J-\\lfloor 2.5 i\\rfloor-k}\n\\\\\n&=\\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} 4^{-(d-1)} 2^{-J-\\left\\lfloor\\frac{i}{2}\\right\\rfloor} \\sum_{k=1}^{J-1-\\lfloor 2.5 i\\rfloor}\\left(\\begin{array}{c}\nd-2+\\lfloor 1.5 i\\rfloor+k \\\\\nd-2\n\\end{array}\\right) 2^{-k} .\n\\end{aligned}\n\\end{equation*}\nThus,\n\\begin{equation*}\n\\begin{aligned}\n\\left|u_{J,J+d-1}-u_J\\right|_1\n&\\leq \\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}}  \\cdot 4^{-(d-1)} \\cdot 2^{-J} \\cdot 2 \\cdot 5^{d-1}\\\\\n&=\\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{3^{(d-1) / 2} \\cdot 4^{d-1}} \\cdot\\left(\\frac{5}{2}\\right)^{d-1} \\cdot 2^{-J}\\le Ch_J,\n\\end{aligned}\n\\end{equation*}\nwhich completes the proof.\n\n\n\n%\\begin{equation*}\n%\\begin{aligned}\n%\\left|u_{J,J+d-1}-u_J\\right|_1&\\leq \\sum_{\\mathcal V_{\\mathbf k} \\in S_{J,J+d-1}^d \\setminus S_J}\\left|u_{\\mathbf{k}}\\right|_1\n%\\\\\n%&\\leq \\sum_{i=0}^{i^{*}} \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left|u_{\\mathbf{k}}\\right|_1 \n%\\\\\n%&\\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} \\cdot \\sum_{i=0}^{i^{*}} \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i} 4^{-|\\mathbf{k}|_{1}} \\cdot\\left(\\sum_{j=1}^{d} 4^{k_{j}}\\right)^{1 / 2}\n%\\\\\n%&\\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} \\cdot 4^{-J-d+1} \\cdot \\sum_{i=0}^{i^{*}} 4^{i} \\cdot \\sum_{\\left.|\\mathbf{k}\\right|_{1}=J+d-1-i,\\left.|\\mathbf{k}\\right|_{\\infty}<J-2.5 i}\\left(\\sum_{j=1}^{d} 2^{k_{j}}\\right)\n%\\\\\n%&\\leq \\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} \\cdot 4^{-J-d+1} \\cdot \\sum_{i=0}^{i^{*}} 4^{i} \\cdot \\sum_{j=1}^{J-1-\\lfloor 2.5 i\\rfloor} d \\cdot\\left(\\begin{array}{c}\n%J+d-2-i-j \\\\\n%d-2\n%\\end{array}\\right) \\cdot 2^{j}\n%\\\\\n%&=\\frac{|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} 4^{-J-d+1} \\sum_{i=0}^{i^{*}} 4^{i} \\sum_{k=1}^{J-1-\\lfloor 2.5 i\\rfloor} d\\left(\\begin{array}{c}\n%d-2+\\lfloor 1.5 i\\rfloor+k \\\\\n%d-2\n%\\end{array}\\right) 2^{J-\\lfloor 2.5 i\\rfloor-k}\n%\\\\\n%&=\\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}} 4^{-(d-1)} 2^{-J} \\sum_{i=0}^{i^{*}} 2^{-\\left\\lfloor\\frac{i}{2}\\right\\rfloor} \\sum_{k=1}^{J-1-\\lfloor 2.5 i\\rfloor}\\left(\\begin{array}{c}\n%d-2+\\lfloor 1.5 i\\rfloor+k \\\\\n%d-2\n%\\end{array}\\right) 2^{-k} \n%\\\\\n%&\\leq \\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{2 \\cdot 12^{(d-1) / 2}}  \\cdot 4^{-(d-1)} \\cdot 2^{-J} \\cdot 2 \\cdot 5^{d-1}\\\\\n%&=\\frac{d \\cdot|u|_{2\\mathbf{e},\\infty}}{3^{(d-1) / 2} \\cdot 4^{d-1}} \\cdot\\left(\\frac{5}{2}\\right)^{d-1} \\cdot 2^{-J}\\le Ch_J,\n%\\end{aligned}\n%\\end{equation*}\n\n\\end{proof}\n\n\n\n\n", "meta": {"hexsha": "331cfa91e3e8c4370c31e14fa34ff9dbc142a94c", "size": 8805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/SparseGridModify.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/SparseGridModify.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/SparseGridModify.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": 48.1147540984, "max_line_length": 246, "alphanum_fraction": 0.5876206701, "num_tokens": 4398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6119249118013481}}
{"text": "\\section{Conclusion}\n\\label{sec:conclusion}\n\nThe MinOver algorithm tries to maximize the minimum stability of the dataset.\nIn absence of noise, MinOver yields to a generalization error similar to the Rosenblatt algorithm.\nFor both algorithms the generalization error decreases for a high $\\alpha = P / N$ (i.e. with a higher number of examples $P$) and approaches zero in the limit for $\\alpha \\to \\infty$.\nIn presence of noise, the MinOver algorithm diverges for big datasets, where the likelihood of the data to be non linearly separable is very high.\n\nIn the original formulation, MinOver does not give any advantages over the Rosenblatt algorithm in terms of generalization error, both in absence and presence of noise in the data.\nIn addition, the MinOver algorithm requires more computation power than the Rosenblatt one, since it needs to compute the stability of all examples in the dataset at each epoch.\n", "meta": {"hexsha": "e1dc50617620a1a6e4b3f963e14ca9dfd58ee98c", "size": 914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/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_2/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_2/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": 83.0909090909, "max_line_length": 184, "alphanum_fraction": 0.7997811816, "num_tokens": 199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.611910892145254}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage[intlimits]{amsmath}\n\\usepackage{MnSymbol}\n%\\usepackage{fullpage}\n\\usepackage[top=0.8in, bottom=0.8in, left=0.8in, right=0.8in]{geometry}\n\\usepackage{multicol}\n\\usepackage{wrapfig}\n\n\\newcommand{\\Sp}{\\text{ }}\n\\newcommand{\\Cov}{\\text{Cov}}\n\\newcommand{\\Var}{\\text{Var}}\n\\newcommand{\\Bin}{\\text{Bin}}\n\\newcommand{\\Poi}{\\text{Poi}}\n\\newcommand{\\HypG}{\\text{HypG}}\n\\newcommand{\\Geo}{\\text{Geo}}\n\\newcommand{\\Exp}{\\text{Exp}}\n\\newcommand{\\Norm}{\\text{N}}\n\\newcommand{\\Where}{\\Sp\\text{ where }}\n\n\\setlength{\\columnsep}{0.1pc}\n\n\\title{CS 109 Study Notes}\n\\author{Stephen Koo}\n\n\\begin{document}\n\\maketitle\n\\vspace{-0.3in}\n\\rule{\\linewidth}{0.4pt}\n\n\\section{Fundamentals}\n\\subsection{DeMorgan's Laws}\n\\begin{align*}\n    &\\left( \\bigcup_{i=1}^n E_i \\right)^c = \\bigcap_{i=1}^n E_i^c &\\left( \\bigcap_{i=1}^n E_i \\right)^c = \\bigcup_{i=1}^n E_i^c\n\\end{align*}\n\\subsection{Axioms of Probability}\n\\emph{Axiom 1}: $0 \\leq P(E) \\leq 1$ \\\\\n\\emph{Axiom 2}: $P(S) = 1$ \\\\\n\\emph{Axiom 3}: For any sequence of mutually exclusive events $E_1, E_2, \\ldots$\n\\[\n    P\\left( \\bigcup_{i=1}^{\\infty} E_i \\right) = \\sum_{i=1}^{\\infty} P(E_i)\n\\]\n\\subsection{Inclusion-Exclusion Identity}\n\\[\n    P(E \\cup F) = P(E) + P(F) - P(EF)\n\\]\n\\[\n    P\\left( \\bigcup_{i=1}^{n} E_i \\right) = \\sum_{r=1}^n (-1)^{(r+1)} \\sum_{i_1 < \\ldots < i_r} P(E_{i_1}, E_{i_2}, \\ldots, E_{i_r})\n\\]\n\\subsection{Number of Integer Solutions of Equations}\nThere are $\\binom{n-1}{r-1}$ distinct positive integer-valued vectors $(x_1, x_2, \\ldots, x_r)$ satisfying the equation\n\\begin{align*}\n    &x_1 + x_2 + \\cdots + x_r = n &x_i > 0, i = 1, \\ldots, r\n\\end{align*}\nThere are $\\binom{n+r-1}{r-1}$ distince nonnegative integer-valued vectors $(x_1, x_2, \\ldots, x_r)$ satisfying the equation\n\\[\n    x_1 + x_2 + \\cdots + x_r = n\n\\]\n\n\\section{Conditional Probability}\n\\[\n    P(E|F) = \\frac{P(EF)}{P(F)} \\Leftrightarrow P(EF) = P(E|F)P(F)\n\\]\n\\subsection{Generalized Chain Rule}\n\\[\n    P(E_1 E_2 \\ldots E_n) = P(E_1)P(E_2|E_1)P(E_3|E_1 E_2)\\ldots P(E_n|E_1 E_2 \\ldots E_{n-1})\n\\]\n\\subsection{Bayes' Theorem}\nThe many shapes and forms of Bayes' Theorem...\n\\[\n    P(E) = P(E|F)P(F) + P(E|F^c)P(F^c)\n\\]\n\\[\n    P(F|E) = \\frac{P(EF)}{P(E)} = \\frac{P(E|F)P(F)}{P(E)}\n\\]\n\\[\n    P(F|E) = \\frac{P(E|F)P(F)}{P(E|F)P(F) + P(E|F^c)P(F^c)}\n\\]\n\\emph{Fully General Form}:\\\\\nIf $F_1, F_2, \\ldots, F_n$ comprise a set of mutually exclusive and exhaustive events, then\n\\[\n    P(F_j|E) = \\frac{P(E|F_j)P(F_j)}{\\sum_{i=1}^n P(E|F_i)P(F_i)}\n\\]\n\\emph{That's odd.} \\\\\nThe odds of $H$ given observed evidence $E$:\n\\[\n    \\frac{P(H|E)}{P(H^c|E)} = \\frac{P(H)P(E|H)}{P(H^c)P(E|H^c)}\n\\]\n\n\\section{Independence}\n\\subsection{Definition}\nTwo events are independent if $P(EF) = P(E)P(F)$. Otherwise they are dependent. \\\\\nMore generally, events $E_1, E_2, \\ldots, E_n$ are independent if for every subset $E_{1'}, E_{2'}, \\ldots, E_r$ where $r \\leq n$ it holds that\n\\[\n    P(E_{1'} E_{2'} \\ldots E_r) = P(E_{1'})P(E_{2'})\\cdots P(E_r)\n\\]\n\\subsection{Conditional Independence}\nTwo events $E$ and $F$ are conditional independent given $G$ if \n\\[\n    P(EF|G) = P(E|G)P(F|G)\n\\]\nDependent events can become independent, and vice-versa, by conditioning on additional information.\n\n\\section{Random Distributions}\n\\subsection{Definitions and Properties}\n\\emph{Probability Mass Function}:\n\\[\n    p(a) = P(X=a)\n\\]\n\\emph{Probability Density Function}:\n\\begin{align*}\n    &P(a \\leq X \\leq b) = \\int_{a}^{b} f(x) dx &P(-\\infty < X < \\infty) = \\int_{-\\infty}^{\\infty} f(x) dx = 1\n\\end{align*}\n\\emph{Cumulative Distribution Function}:\n\\[\n    F(a) = F(X \\leq a) \\text{ where } -\\infty < a \\infty\n\\]\n\\begin{align*}\n    &F(a) = \\sum_{\\text{all } x\\leq a} p(x) &F(a) = \\int_{-\\infty}^a f(x) dx\n\\end{align*}\nDensity $f$ is the derivative of CDF $F$: $f(a) = \\frac{d}{da} F(a)$\n\n\\subsection{Joint distributions}\n\\emph{Joint Probability Mass Function}:\n\\[\n    p_{X,Y}(a,b) = P(X=a,Y=b)\n\\]\nMarginal distributions:\n\\begin{align*}\n    &p_X(a) = P(X=a)= \\sum_y p_{X,Y} (a, y) &p_Y(b) = P(Y=b)= \\sum_x p_{X,Y} (x, b)\n\\end{align*}\n\\emph{Joint Cumulative Probability Distribution (CDF)}:\n\\[\n    F_{X,Y}(a,b) = F(a,b) = P(X \\leq a, Y \\leq b) \\text{ where } -\\infty < a,b < \\infty\n\\]\nMarginal distributions:\n\\begin{align*}\n    F_X(a) = P(X \\leq a) = P(X \\leq a, Y < \\infty) = F_{X,Y}(a,\\infty) \\\\\n    F_Y(b) = P(Y \\leq b) = P(X < \\infty, Y \\leq b) = F_{X,Y}(\\infty, b)\n\\end{align*}\n\\emph{Joint Probability Density Function}:\n\\[\n    P(a_1 < X \\leq a_2, b_1 < Y \\leq b_2) = \\int_{a_1}^{a_2} \\int_{b_1}^{b_2} f_{X,Y}(x,y) dy dx\n\\]\n\\begin{align*}\n    &F_{X,Y}(a,b) = \\int_{-\\infty}^a \\int_{-\\infty}^b f_{X,Y}(x,y) dy dx &f_{X,Y}(a,b) = \\frac{\\partial^2}{\\partial a \\partial b} F_{X,Y} (a,b)\n\\end{align*}\nMarginal density functions:\n\\begin{align*}\n    &f_x(a) = \\int_{-\\infty}^{\\infty} f_{X,Y}(a,y)dy \n    &f_y(b) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,b)dx\n\\end{align*}\n\\subsection{Independent Random Variables}\n$n$ random variables $X_1, X_2, \\ldots, X_n$ are called independent if\n\\[\n    P(X_1 = x_1, X_2 = x_2, \\ldots, X_n = x_n) = \\prod_{i=1}^n P(X_i = x_i) \\text{ for all } x_1, x_2, \\ldots, x_n\n\\]\nor analogously for continuous random variables if\n\\[\n    P(X_1 \\leq a_1, X_2 \\leq a_2, \\ldots, X_n \\leq a_n) = \\prod_{i=1}^n P(X_i \\leq a_i) \\text{ for all } a_1, a_2, \\ldots, a_n\n\\]\n\\subsection{Convolution}\nLet $X$ and $Y$ be independent random variables. The convolution of $F_X$ and $F_Y$ is $F_{X+Y}$:\n\\[\n    F_{X+Y}(a) = P(X+Y \\leq a) = \\int_{y=-\\infty}^{\\infty} F_X (a-y)f_Y(y)dy\n\\]\n\\[\n    f_{X+Y}(a) = \\int_{y=-\\infty}^{\\infty} f_X (a-y)f_Y(y)dy\n\\]\nIn discrete case, replace $\\int_{y=-\\infty}^{\\infty}$ with $\\sum_{y}$, and $f(y)$ with $p(y)$.\n\\subsection{Conditional Distributions}\n\\emph{Conditional PMF of $X$ given $Y$}:\n\\[\n    p_{X|Y}(x|y) = P(X=x|Y=y) = \\frac{p_{X,Y}(x,y)}{p_Y(y)}\n\\]\n\\emph{Conditional PDF of $X$ given $Y$}:\n\\[\n    f_{X|Y}(x|y) = \\frac{f_{X,Y}(x,y)}{f_Y(y)}\n\\]\n\\emph{Conditional CDF of $X$ given $Y$}:\n\\begin{align*}\n    F_{X|Y}(a|y) = P(X \\leq a, Y=y) &= \\sum_{x\\leq a} p_{X|Y}(x|y) \\\\\n                                    &=\\int_{-\\infty}^{a} f_{X|Y} (x|y) dx\n\\end{align*}\n$n$ random variables $X_1, X_2, \\ldots, X_n$ are conditionally independent given $Y$ if\n\\[\n    P(X_1 = x_1, X_2 = x_2, \\ldots, X_n = x_n|Y=y) = \\prod_{i=1}^n P(X_i = x_i|Y=y) \\text{ for all } x_1, x_2, \\ldots, x_n, y\n\\]\nor analogously for continuous random variables if\n\\[\n    P(X_1 \\leq a_1, X_2 \\leq a_2, \\ldots, X_n \\leq a_n|Y=y) = \\prod_{i=1}^n P(X_i \\leq a_i|Y=y) \\text{ for all } a_1, a_2, \\ldots, a_n, y\n\\]\nIt is possible to mix continuous and discrete random variables in conditional distributions. For example let $X$ be a continuous random variable and $N$ be a discrete random variable. Then the conditional PDF of $X$ given $N$ and the conditional PMF of $N$ given $X$ are\n\\[\n    f_{X|N}(x|n) = \\frac{p_{N|X}(n|x)f_X(x)}{p_N(n)}\n\\]\n\\[\n    P_{N|X}(n|x) = \\frac{f_{X|N}(x|n)p_N(n)}{f_X(x)}\n\\]\n\n\\section{Expectation}\n\\subsection{Definitions}\nThe expected value for a discrete random variable $X$ is defined as\n\\[\n    E[X] = \\sum_{x: p(x) > 0} x p(x)\n\\]\nFor a continuous random variable $X$, the expected value is\n\\[\n    E[X] = \\int_{-\\infty}^{\\infty} x f(x) dx\n\\]\n\\subsection{Properties}\nIf $I$ is an indicator variable for the event $A$, then\n\\[\n    E[I] = P(A)\n\\]\nLet $g(X)$ be a real-valued function of $X$.\n\\begin{align*}\n    &E[g(X)] = \\sum_{i} g(x_i)p(x_i) &E[g(X)] = \\int_{-\\infty}^{\\infty} g(x) f(x) dx\n\\end{align*}\nLet $g(X,Y)$ be a real-valued function of two random variables.\n\\begin{align*}\n    &E[g(X,Y)] = \\sum_y \\sum_x g(x,y) p_{X,Y}(x,y)  &E[g(X,Y)] = \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} g(x,y) f_{X,Y}(x,y) dx dy\n\\end{align*}\nLinearity:\n\\[\n    E[aX + b]  = aE[X] + b\n\\]\n$N$-th Moment of $X$:\n\\[\n    E[X^n] = \\sum_{x: p(x) > 0} x^n p(x)\n\\]\nExpected Values of Sums:\n\\[\n    E\\left[ \\sum_{i=1}^n X_i \\right] = \\sum_{i=1}^n E[X_i]\n\\]\nBounding Expectation:\\\\\nIf random variable $X \\geq a$ then $E[X] \\geq a$. \\\\\nIf $P(a \\leq X < \\infty) = 1$ then $a \\leq E[X] < \\infty$. \\\\\nIf random variables $X \\geq Y$ then $E[X] \\geq E[Y]$.\n\n\\subsection{Conditional Expectation}\nConditional Expectation of $X$ given $Y=y$:\n\\begin{align*}\n    &E[X|Y=y] = \\sum_x x p_{X|Y}(x|y)   &E[X|Y=y] = \\int_{-\\infty}^{+\\infty} x f_{X|Y} (x|y) dx\n\\end{align*}\nExpectation of conditional sum:\n\\[\n    E\\left[ \\sum_{i=1}^n X_i | Y=y \\right] = \\sum_{i=1}^n E[X_i | Y=y]\n\\]\nExpectation of conditional expectations:\n\\[\n    E[E[X|Y]] = E[X]\n\\]\n\n\n\\section{Variance}\n\\subsection{Definition}\nIf $X$ is a random variable with mean $\\mu$ then the variance of $X$, denoted $\\Var(X)$, is:\n\\[\n    \\Var(X) = E[(X-\\mu)^2] = E[X^2] - (E[X])^2\n\\]\n\\subsection{Properties}\n\\[\n    \\Var(aX + b) = a^2\\Var(X)\n\\]\nIf $X_1, X_2, \\ldots, X_n$ are independent random variables, then\n\\[\n    \\Var\\left( \\sum_{i=1}^n X_i \\right) = \\sum_{i=1}^n \\Var(X_i)\n\\]\n\\subsection{Covariance}\n\\[\n    \\Cov(X,Y) = E[(X-E[X])(Y-E[Y])] = E[XY] - E[X]E[Y]\n\\]\nIf $X$ and $Y$ are independent, $\\Cov(X,Y) = 0$\n\\emph{Properties}:\n\\begin{align*}\n    \\Cov(X,Y) &= \\Cov(Y,X) \\\\\n    \\Cov(X,X) &= \\Var(X) \\\\\n    \\Cov(aX+b, Y) = a\\Cov(X,Y)\n\\end{align*}\nIf $X_1, X_2, \\ldots, X_n$ and $Y_1, Y_2, \\ldots, Y_m$ are random variables, then\n\\[\n    \\Cov\\left( \\sum_{i=1}^n X_i, \\sum_{j=1}^m Y_j \\right) = \\sum_{i=1}^n \\sum_{j=1}^m \\Cov(X_i, X_j)\n\\]\n\\subsection{Correlation}\n\\[\n    \\rho(X,Y) = \\frac{\\Cov(X,Y)}{\\sqrt{\\Var(X)\\Var(Y)}}\n\\]\nNote: $-1 \\leq \\rho(X,Y) \\leq 1$. \\\\\nCorrelation measures linearity between $X$ and $Y$.\\\\\nIf $\\rho(X,Y) = 0$, $X$ and $Y$ are uncorrelated.\n\n\\section{Moment Generating Functions}\n\\subsection{Definition}\nMoment Generating Function (MGF) of a random variable $X$, where $-\\infty < t < \\infty$, is\n\\[\n    M(t) = E[e^{tX}]\n\\]\n\\begin{align*}\n    &\\text{When $X$ is discrete: }      &= \\sum_x e^{tx} p(x) \\\\\n    &\\text{When $X$ is continuous: }    &= \\int_{-\\infty}^{\\infty} e^{tx} f(x) dx\n\\end{align*}\nFor any $n$ random variables $X_1, X_2, \\ldots, X_n$\n\\[\n    M(t_1, t_2, \\ldots, t_n) = E[e^{t_1X_1+t_2X_2+\\cdots+t_nX_n}]\n\\]\nThe individual moment generating function is obtained:\n\\[\n    M_{X_i}(t) = E[e^{tX}] = M(0, \\ldots, 0, t, 0, \\ldots, 0) \\text{ where $t$ at $i$th place}\n\\]\n\\subsection{Properties}\n\\[\n    M^n(t) = \\left( \\frac{d^n}{dt^n} \\right) M(t) = E[X^n e^{nX}]\n\\]\n\\[\n    M^n(0) = E[X^n]\n\\]\n\\[\n    M_X(t) = M_Y(t) \\text{ iff } X \\sim Y\n\\]\n$X_1, X_2, \\ldots, X_n$ independent if and only if:\n\\[\n    M(t_1, t_2, \\ldots, t_n) = M_{X_1}(t_1)M_{X_2}(t_2)\\ldots M_{X_n}(t_n)\n\\]\n\n\\section{Inequalities}\n\\subsection{Boole's Inequality}\nLet $E_1, E_2, \\ldots, E_n$ be events with indicator random variables $X_i$.\n\\[\n    \\sum_{i=1}^n P(E_i) \\geq P\\left( \\bigcup_{i=1}^n E_i \\right)\n\\]\n\\subsection{Markov's Inequality}\n$X$ is a nonnegative random variable.\n\\[\n    P(X \\geq a) \\leq \\frac{E[X]}{a} \\text{ for all } a > 0\n\\]\n\\subsection{Chebyshev's Inequality}\n$X$ is a random variable with $E[X] = \\mu$ and $\\Var(X) = \\sigma^2$.\n\\[\n    P(|X-\\mu| \\geq k) \\leq \\frac{\\sigma^2}{k^2} \\text{ for all } k > 0\n\\]\n\\emph{One-sided inequality}:\n\\[\n    P(X \\geq E[X] + a) \\leq \\frac{\\sigma^2}{\\sigma^2 + a^2} \\text{ for any } a  > 0\n\\]\n\\[\n    P(X \\leq E[X] - a) \\leq \\frac{\\sigma^2}{\\sigma^2 + a^2} \\text{ for any } a  > 0\n\\]\n\\subsection{Chernoff Bound}\n$X$ is a random variable with MGF $M(t)$.\n\\[\n    P(X \\geq a) \\leq e^{-ta} M(t) \\text{ for all } t > 0 \n\\]\n\\[\n    P(X \\leq a) \\leq e^{-ta} M(t) \\text{ for all } t < 0 \n\\]\nIn practice, use the $t$ that minimizes $e^{-ta} M(t)$. \n \n\\subsection{Jensen's Inequality}\nIf $f(x)$ is a convex function ($f''(x) \\geq 0$ for all $x$) then\n\\[\n    E[f(x)] \\geq f(E[X])\n\\]\n\n\\end{document}\n\n", "meta": {"hexsha": "1dc8c6dacfa6dfe228981a2fefa25dfc3a9e513d", "size": 11606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "studysheet.tex", "max_stars_repo_name": "kashizui/Stanford-CS109-Notes", "max_stars_repo_head_hexsha": "e0e0ab8fbc1afbe0711d23b8be4b0c3d4be09cb2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-02-24T23:32:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T14:54:10.000Z", "max_issues_repo_path": "studysheet.tex", "max_issues_repo_name": "kashizui/Stanford-CS109-Notes", "max_issues_repo_head_hexsha": "e0e0ab8fbc1afbe0711d23b8be4b0c3d4be09cb2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "studysheet.tex", "max_forks_repo_name": "kashizui/Stanford-CS109-Notes", "max_forks_repo_head_hexsha": "e0e0ab8fbc1afbe0711d23b8be4b0c3d4be09cb2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-06-06T06:07:22.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-25T19:57:35.000Z", "avg_line_length": 31.7103825137, "max_line_length": 270, "alphanum_fraction": 0.5950370498, "num_tokens": 5017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743735019595, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.6119108889831621}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Geometric Features of Curves}\n        We have previously examined curvature, but curves have other geometric properties which may be of interest, so we wish to look at those and define them mathematically. One of these is the principal normal, which is always perpendicual to the tangent vector. The principal normal describes the rate of change of the tangent vector. Another is osculating planes and circles, where we use planes and circles to approximate curves, rather than linear  line segments.\n        \\begin{definition}{Principal Normal Vector}{}\n                Consider a curve parameterized by \\(\\vec{r}(t)\\) on some interval. There exists a vector \\(\\vec{N}\\) of unit length called the \\emph{principal normal  vector} which is always perpendicular to \\(\\vec{T}\\), and describes the direction in which \\(\\vec{T}\\) is moving.\n\n                In the arc length parameterization, we have\n                \\[\n                \\vec{T}=\\frac{d\\vec{r}}{ds}\n                \\]\n                then if \\(\\kappa\\neq0\\), we define\n                \\[\n                \\vec{N}(s)=\\frac{\\vec{T}'(s)}{|\\vec{T}'(s)|}\n                \\]\n                which is of unit length and points in the direction in which \\(\\vec{T}\\) is curving. There is also an expression for \\(\\vec{N}\\) in terms of an arbitrary parameterization, using that\n                \\[\n                \\frac{d\\vec{T}}{ds}=\\frac{d\\vec{T}}{dt}\\frac{dt}{ds}\n                \\]\n                we have\n                \\[\n                \\vec{N}(t)=\\frac{\\vec{T}'(t)}{|\\vec{T}'(t)|}\n                \\]\n                so the formula is independent of parameterization.\n        \\end{definition}\n        \\begin{theorem}{}{}\n                Prove that \\(\\vec{N}\\perp\\vec{T}\\).\n                \\tcblower\n                Since \\(|\\vec{T}|=1\\), we have \\(\\vec{T}\\cdot\\vec{T}'=0\\), but since \\(\\vec{N}\\) is a scalar multiple of \\(\\vec{T}'\\), it must be that \\(\\vec{N}\\cdot\\vec{T}=0\\) and \\(\\vec{N}\\perp\\vec{T}\\).\n        \\end{theorem}\n        \\begin{definition}{The Osculating Plane}{}\n                Consider a curve described by \\(\\vec{r}(t)\\) on some interval. We define the \\emph{osculating plane} at a point \\(P\\) on the curve as the plane through \\(P\\) which is spanned by \\(\\vec{N}\\) and \\(\\vec{T}\\).\n        \\end{definition}\n        \\begin{definition}{The Osculating Circle}{}\n                Consider a curve described by \\(\\vec{r}(t)\\) on some interval. We define the \\emph{osculating circle} at a point \\(P\\) on the curve to be a circle which lies in the osculating plane, having a radius of \\(\\rho=\\frac{1}{\\kappa}\\), and a centre at \\(P+\\rho\\vec{N}\\).\n        \\end{definition}\n        The osculating circle represents a best circular approximation of the curve at a given point. Note that a circle of radius \\(a\\) has curvature \\(\\kappa=\\frac{1}{a}\\), so the osculating circle has the same curvature as the curve it approximates.\n        \\begin{example}{}{}\n                Consider the circle parameterized by \\(\\vec{r}(t)=a\\cos{t}\\i+a\\sin{t}\\j\\) in \\(\\mathbb{R}^3\\). Find an expression for the osculating  circle.\n                \\tcblower\n                It has previously been found that\n                \\[\n                \\vec{T}(t)=-\\sin{t}\\vec{i}+\\cos{t}\\j\n                \\]\n                and therefore\n                \\[\n                \\vec{T}'(t)=-\\cos{t}\\vec{i}-\\sin{t}\\j\n                \\]\n                but since \\(|\\vec{T}'|=1\\), we have\n                \\[\n                \\vec{N}(t)=\\vec{T}'(t)\n                \\]\n\n                The curvature of this circle is \\(\\kappa=\\frac{1}{a}\\), and therefore the radius of the osculating circle is \\(a\\), identical to that o f the original circle. The centre of the osculating circle is at \\(\\vec{r}-a\\vec{N}=\\vec{0}\\), so the osculating circle is precisely equal to the original circle.\n        \\end{example}\n        \\begin{example}{}{}\n                Consider the helix parameterized by \\(\\vec{r}=a\\cos{t}\\i+a\\sin{t}\\j+bt\\k\\). Find an expression for the osculating circle.\n                \\tcblower\n                We have previously found that\n                \\[\n                \\vec{T}'(t)=\\frac{1}{\\sqrt{a^2+b^2}}\\left(-a\\cos{t}\\i-a\\sin{t}\\j\\right)\n                \\]\n                and\n                \\[\n                |\\vec{T}'(t)|=\\frac{a}{\\sqrt{a^2+b^2}}\n                \\]\n                but this yields\n                \\[\n                \\vec{N}=-\\cos{t}\\i-\\sin{t}\\j\n                \\]\n                which gives the same osculating circle as that of the circle in the previous example, appropriately offset in the z-axis.\n        \\end{example}\n        \\begin{example}{}{}\n                Find an expression for the osculating plane of the helix from the previous example. \n                \\tcblower\n                We require our osculating plane be spanned by \\(\\vec{N}\\) and \\(\\vec{T}\\), so the plane's normal vector must be\n                \\[\n                \\vec{B}=\\vec{T}\\times\\vec{N}\n                \\]\n                where \\(\\vec{B}\\) is known as the \\emph{binormal vector}.\n                An expression describing the plane may then be obtained using the usual method.\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "56803073363b8a9a15877817f08f7b7b35fe8dd0", "size": 5233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_5.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_5.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_5.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": 61.5647058824, "max_line_length": 470, "alphanum_fraction": 0.547869291, "num_tokens": 1378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6119108810866852}}
{"text": "\\subsection{Boolean algebras}\\label{subsec:boolean_algebras}\n\n\\begin{definition}\\label{def:heyting_algebra}\\mcite[10]{BezhanishviliHolliday2019}\n  A \\term{Heyting algebra} is a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice} \\( X \\) with a binary operation \\( \\rightarrow \\) defined as\n  \\begin{equation}\\label{eq:def:heyting_algebra/conditional}\n    (x \\rightarrow y) \\coloneqq \\bigvee\\set{ a \\in X \\given a \\wedge x \\leq y }.\n  \\end{equation}\n\n  In order for the operation to be well-defined, we require that the corresponding join exists for all \\( y \\) and \\( z \\). We call this operation the \\term{conditional} in analogy with the \\hyperref[def:propositional_language/connectives/conditional]{propositional connective}, although this operation is often called \\enquote{implication} because of \\hyperref[def:material_implication]{material implication}.\n\n  Heyting algebras are useful for defining truth values for intuitionistic logic -- see \\fullref{def:propositional_heyting_algebra_semantics} --- and also appear as the \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebra} for propositional intuitionistic theories --- see \\fullref{thm:intuitionistic_lindenbaum_tarski_algebra}.\n\n  \\begin{thmenum}[series=def:heyting_algebra]\n    \\thmitem{def:heyting_algebra/pseudocomplement} For any element \\( x \\), we define its \\term{pseudocomplement} as\n    \\begin{equation}\\label{eq:def:heyting_algebra/pseudocomplement}\n      \\widetilde x\n      \\coloneqq\n      (x \\rightarrow \\bot)\n      =\n      \\bigvee\\set{ a \\in X \\given a \\wedge x = \\bot }.\n    \\end{equation}\n  \\end{thmenum}\n\n  Heyting algebras have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:heyting_algebra]\n    \\thmitem{def:heyting_algebra/theory} We extend the language of the \\hyperref[def:semilattice/theory]{theory of lattices} with the binary infix functional symbol \\( \\rightarrow \\) and the unary functional symbol \\( \\widetilde{\\anon} \\). By adding the axiom \\eqref{eq:def:heyting_algebra/conditional} to the theory of bounded distributive lattices, we obtain the theory of Heyting algebras.\n\n    \\thmitem{def:heyting_algebra/submodel} The Heyting subalgebras are the \\hyperref[def:semilattice/submodel]{bounded sublattices} for which the conditional is well-defined.\n\n    \\thmitem{def:heyting_algebra/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} Heyting algebra is the \\hyperref[def:semilattice/trivial]{one-element bounded lattice}.\n\n    \\thmitem{def:heyting_algebra/homomorphism} \\hyperref[def:first_order_homomorphism]{Homomorphisms} between Heyting algebras are lattice homomorphisms with the additional requirement that homomorphisms preserve conditionals.\n\n    \\thmitem{def:heyting_algebra/category} The \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for Heyting algebras is denoted by \\( \\cat{Heyt} \\). It is a full subcategory of the \\hyperref[def:semilattice/category]{category \\( \\cat{Lat} \\) of lattices}.\n\n    \\thmitem{def:heyting_algebra/opposite} The \\hyperref[def:semilattice/duality]{principle of duality for lattices} does not hold for Heyting algebras.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:topological_space_is_heyting_algebra}\n  Somewhat similar to how the power set of a nonempty set is a Boolean algebra, as shown in \\fullref{thm:boolean_algebra_of_subsets}, the topology \\( \\mscrT \\) of a \\hyperref[def:topological_space]{topological space} \\( (X, \\mscrT) \\) is a Heyting algebra. This is actually used in topological semantics --- see \\fullref{def:propositional_topological_semantics}.\n\n  Indeed,\n  \\begin{itemize}\n    \\item \\hyperref[def:semilattice/join]{Arbitrary joins} are given by \\hyperref[def:basic_set_operations/union]{unions \\( \\bigcap \\)}.\n    \\item \\hyperref[def:semilattice/meet]{Finite meets} are given by \\hyperref[def:basic_set_operations/intersection]{intersections \\( \\bigcup \\)}.\n    \\item The \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top} is the entire domain \\( X \\).\n    \\item The \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom} is the empty set.\n    \\item The \\hyperref[eq:def:heyting_algebra/conditional]{conditional \\( U \\leadsto V \\)} is then\n    \\begin{equation*}\n      \\bigcup\\set[\\Big]{ A \\in T \\given \\underbrace{A \\cap U}_{A \\setminus (X \\setminus U)} \\subseteq V }\n      =\n      \\bigcup\\set[\\Big]{ A \\in T \\given A \\subseteq V \\cup (X \\setminus U) }\n      =\n      \\Int((X \\setminus U) \\cup V),\n    \\end{equation*}\n    which is actually similar to \\fullref{thm:boolean_equivalences/conditional_as_disjunction} despite the fact that arbitrary topologies are not Boolean algebras.\n\n    \\item As a result, the \\hyperref[def:heyting_algebra/pseudocomplement]{pseudocomplement} is\n    \\begin{equation*}\n      \\widetilde U = \\Int(X \\setminus U).\n    \\end{equation*}\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:bounded_lattice_complement}\n  Let \\( X \\) be a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/lattice]{lattice} and fix an element \\( x \\in X \\). A \\term{complement} of \\( x \\) is an element \\( y \\) such that\n  \\begin{align}\n    x \\vee y = \\top \\label{def:bounded_lattice_complement/join}, \\\\\n    x \\wedge y = \\bot \\label{def:bounded_lattice_complement/meet}.\n  \\end{align}\n\n  Due to the commutativity of both \\( \\vee \\) and \\( \\wedge \\), \\( y \\) is a complement of \\( x \\) if and only if \\( x \\) is a complement of \\( y \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:distributive_bounded_lattice_unique_complement}\n  In a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice} \\( X \\), each \\( x \\in X \\) has at most one complement.\n\n  Thus, complementation can be regarded as a \\hyperref[def:partial_function]{partial operation}.\n\\end{proposition}\n\\begin{proof}\n  If \\( y \\) and \\( z \\) are both complements of \\( x \\), then\n  \\begin{balign*}\n    y\n    &\\reloset {\\eqref{eq:thm:binary_lattice_operations/identity/meet}} =\n    y \\wedge \\top\n    = \\\\ &\\reloset {\\eqref{def:bounded_lattice_complement/join}} =\n    y \\wedge (z \\vee x)\n    = \\\\ &\\reloset {\\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join}} =\n    (y \\wedge z) \\vee (y \\wedge x)\n    = \\\\ &\\reloset {\\eqref{def:bounded_lattice_complement/meet}} =\n    y \\wedge z\n    = \\\\ &\\reloset {\\eqref{def:bounded_lattice_complement/meet}} =\n    (x \\wedge z) \\vee (y \\wedge z)\n    = \\\\ &\\reloset {\\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join}} =\n    (x \\vee y) \\wedge z\n    = \\\\ &\\reloset {\\eqref{eq:thm:binary_lattice_operations/identity/meet}} =\n    z.\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:boolean_algebra}\\mcite[48]{Gratzer1978}\n  A \\term{Boolean algebra} is a \\hyperref[def:semilattice/bounded]{bounded} \\hyperref[def:semilattice/distributive_lattice]{distributive lattice} in which every element has a \\hyperref[def:bounded_lattice_complement]{complement}. The complement of each element is unique due to \\fullref{thm:distributive_bounded_lattice_unique_complement}. We define a unary function that gives to every element \\( x \\) its complement \\( \\overline \\anon \\). By definition, this function is an \\hyperref[def:set_with_involution]{involution}.\n\n  \\begin{thmenum}[series=def:boolean_algebra]\n    \\thmitem{def:boolean_algebra/conditional} We also define the binary operation \\term{conditional} (\\( \\rightarrow \\)) via\n    \\begin{equation}\\label{eq:def:boolean_algebra/conditional}\n      (x \\rightarrow y) \\coloneqq (\\overline x \\vee y)\n    \\end{equation}\n    in analogy with \\fullref{thm:boolean_equivalences/conditional_as_disjunction}. This operation highlights that Boolean algebras are a special case of \\hyperref[thm:boolean_algebras_are_heyting_algebras]{Heyting algebras}.\n\n    \\thmitem{def:boolean_algebra/biconditional} It remains to define a binary operation corresponding to the \\hyperref[def:propositional_language/connectives/biconditional]{propositional biconditional}. Inspired by \\fullref{thm:boolean_equivalences/biconditional_via_conditionals}, define\n    \\begin{equation}\\label{eq:def:boolean_algebra/biconditional}\n      (x \\leftrightarrow y) \\coloneqq (x \\rightarrow y) \\wedge (y \\rightarrow x).\n    \\end{equation}\n  \\end{thmenum}\n\n  Boolean algebras have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:boolean_algebra]\n    \\thmitem{def:boolean_algebra/theory} To obtain the theory of Boolean algebras, we replace the unary functional symbol \\( \\widetilde{\\anon} \\) with \\( \\overline \\anon \\) in the language of the \\hyperref[def:heyting_algebra/theory]{theory of Heyting algebras} and then add the axioms \\eqref{def:bounded_lattice_complement/join} and \\eqref{def:bounded_lattice_complement/meet} to the theory. We may also replace \\eqref{eq:def:heyting_algebra/conditional} defining \\( \\rightarrow \\) with the simpler axiom \\eqref{eq:def:boolean_algebra/conditional}.\n\n    \\thmitem{def:boolean_algebra/submodel} The Boolean subalgebras are the \\hyperref[def:semilattice/submodel]{bounded sublattices} which are closed under compementation.\n\n    \\thmitem{def:boolean_algebra/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} Boolean algebra is the \\hyperref[def:semilattice/trivial]{one-element bounded lattice}.\n\n    \\thmitem{def:boolean_algebra/homomorphism} \\hyperref[def:first_order_homomorphism]{Homomorphisms} between Boolean algebras are simply lattice homomorphisms.\n\n    Complements are automatically preserved because for any lattice homomorphism \\( \\varphi \\) between the Boolean algebras \\( X \\) and \\( Y \\),\n    \\begin{equation*}\n      \\varphi(x) \\vee_Y \\varphi(\\overline x) = \\varphi(x \\vee_X \\overline x) = \\varphi(\\top_X) = \\top_Y,\n    \\end{equation*}\n    and similarly for \\( \\wedge \\), hence, due to \\fullref{thm:distributive_bounded_lattice_unique_complement},\n    \\begin{equation*}\n      \\varphi(\\overline x) = \\overline {\\varphi(x)}.\n    \\end{equation*}\n\n    Implications are also automatically preserved because of \\eqref{eq:def:boolean_algebra/conditional}.\n\n    \\thmitem{def:boolean_algebra/category} The \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} for Boolean algebras \\( \\cat{Bool} \\) is a full subcategory the \\hyperref[def:heyting_algebra/category]{category \\( \\cat{Heyt} \\) of Heyting algebras}.\n\n    \\thmitem{def:boolean_algebra/opposite} The \\hyperref[def:semilattice/duality]{principle of duality for lattices} holds for Boolean algebras without interchanging complements.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:boolean_algebras}\n  Examples of \\hyperref[def:boolean_algebra]{Boolean algebras} include:\n\n  \\begin{itemize}\n    \\thmitem{ex:boolean_algebras/lindenbaum_tarski} The \\hyperref[def:lindenbaum_tarski_algebra]{Lindenbaum-Tarski algebras} for classical logic. We prove in \\fullref{thm:intuitionistic_lindenbaum_tarski_algebra} that it is a Boolean algebra.\n    \\thmitem{ex:boolean_algebras/f2} The \\hyperref[thm:finite_fields]{prime field} \\( \\BbbF_2 \\) with suitably defined operations discussed in \\fullref{thm:f2_is_boolean_algebra}.\n    \\thmitem{ex:boolean_algebras/power_set} The power set of any set, usually taken to be a space with additional structure (see \\fullref{thm:boolean_algebra_of_subsets}).\n  \\end{itemize}\n\\end{example}\n\n\\begin{proposition}\\label{thm:binary_boolean_algebra}\n  All two-element \\hyperref[def:boolean_algebra]{Boolean algebras} are isomorphic.\n\\end{proposition}\n\\begin{proof}\n  Follows from the requirement that \\hyperref[def:semilattice/homomorphism]{lattice homomorphisms} preserve constants.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:f2_is_boolean_algebra}\n  For certain purposes, for example \\hyperref[def:zhegalkin_polynomial]{Zhegalkin polynomials}, we may regard the \\hyperref[thm:finite_fields]{prime field} \\( \\BbbF_2 \\) as a Boolean algebra with \\( 1 \\) as the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top} and \\( 0 \\) as the \\hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom element}.\n\\end{corollary}\n\\begin{proof}\n  Follows from \\fullref{thm:binary_boolean_algebra}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:boolean_algebras_are_heyting_algebras}\n  Every \\hyperref[def:boolean_algebra]{Boolean algebra} is a \\hyperref[def:heyting_algebra]{Heyting algebra} with an identification given by \\eqref{eq:def:boolean_algebra/conditional}.\n\\end{proposition}\n\\begin{proof}\n  Fix any \\( x, y \\in X \\) in a Boolean algebra \\( X \\). We will show that \\( x \\rightarrow y \\) as defined in \\eqref{eq:def:boolean_algebra/conditional} satisfies \\eqref{eq:def:heyting_algebra/conditional}.\n\n  Let\n  \\begin{equation*}\n   A \\coloneqq \\set{ a \\in X \\given a \\wedge x \\leq y }\n  \\end{equation*}\n  be the set from \\eqref{eq:def:heyting_algebra/conditional}.\n\n  We will show that \\( \\overline x \\vee y \\) is an \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{upper bound} of \\( A \\).\n\n  Fix some \\( a_0 \\in A \\). By definition of \\( A \\), we have\n  \\begin{equation*}\n   a_0 \\wedge x \\leq y.\n  \\end{equation*}\n\n  But this means that\n  \\begin{equation*}\n   \\underbrace{(a_0 \\wedge x) \\vee \\overline x}_{a_0 \\vee \\overline x} \\leq y \\vee \\overline x.\n  \\end{equation*}\n\n  Since \\( a_0 \\leq a_0 \\vee b \\) for any \\( b \\in X \\), it follows that \\( a_0 \\leq y \\vee \\overline x \\). Therefore, \\( \\overline x \\vee y \\) is indeed an upper bound of \\( A \\).\n\n  Also note that\n  \\begin{equation*}\n   (\\overline x \\vee y) \\wedge x = \\underbrace{(\\overline x \\vee x)}_{\\top} \\wedge (y \\wedge x) = y \\wedge x \\leq y,\n  \\end{equation*}\n  hence \\( \\overline x \\vee y \\in A \\).\n\n  Thus, \\( \\overline x \\vee y \\) is both an upper bound of \\( A \\) and an element of \\( A \\), i.e. it is the least upper bound of \\( A \\). Therefore,\n  \\begin{equation*}\n   \\overline x \\vee y = \\bigvee A.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[De Morgan's laws]\\label{thm:de_morgans_laws}\n  If \\( X \\) is a \\hyperref[def:boolean_algebra]{Boolean algebra}, the following hold for any finite \\hyperref[def:cartesian_product/indexed_family]{family} \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\):\n  \\begin{align}\n    \\overline{\\bigvee_{k \\in \\mscrK} x_k} = \\bigwedge_{k \\in \\mscrK} \\overline{x_k} \\label{eq:thm:de_morgans_laws/complement_of_join} \\\\\n    \\overline{\\bigwedge_{k \\in \\mscrK} x_k} = \\bigvee_{k \\in \\mscrK} \\overline{x_k} \\label{eq:thm:de_morgans_laws/complement_of_meet}\n  \\end{align}\n\n  If \\( X \\) is \\hyperref[def:semilattice/complete]{complete}, \\( \\mscrK \\) may be taken to be any family, not necessarily finite.\n\\end{theorem}\n\\begin{proof}\n  We will only show \\eqref{eq:thm:de_morgans_laws/complement_of_join} since \\eqref{eq:thm:de_morgans_laws/complement_of_meet} is dual.\n\n  In order for \\( \\wedge_{k \\in \\mscrK} \\overline{x_k} \\) to be the complement of \\( \\vee_{k \\in \\mscrK} x_k \\), the conditions \\eqref{def:bounded_lattice_complement/join} and \\eqref{def:bounded_lattice_complement/meet} need to be satisfied.\n\n  From distributivity, we have\n  \\begin{equation*}\n    \\parens*{ \\bigwedge_{k \\in \\mscrK} \\overline{x_k} } \\vee \\parens*{ \\bigvee_{m \\in \\mscrK} x_m }\n    \\reloset {\\eqref{eq:def:semilattice/distributive_lattice/arbitrary/join_over_meet}} =\n    \\bigwedge_{k \\in \\mscrK} \\parens*{ \\overline{x_k} \\vee \\bigvee_{m \\in \\mscrK} x_m }\n    =\n    \\bigwedge_{k \\in \\mscrK} \\parens*{ \\underbrace{\\overline{x_k} \\vee x_k}_{\\top} \\vee \\bigvee_{\\mathclap{m \\in K \\setminus \\set{k}}} x_m }\n    =\n    \\bigwedge_{k \\in \\mscrK} \\top\n    =\n    \\top,\n  \\end{equation*}\n  which proves \\eqref{def:bounded_lattice_complement/join}. The proof of \\eqref{def:bounded_lattice_complement/meet} is analogous.\n\\end{proof}\n", "meta": {"hexsha": "3c9c5b62474e1aeb7e6600bfd5f4fc12118de3ae", "size": 15794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/boolean_algebras.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_algebras.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_algebras.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": 67.2085106383, "max_line_length": 549, "alphanum_fraction": 0.7434468786, "num_tokens": 4954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6119108810866852}}
{"text": "\\documentclass{report}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\begin{document}\n\\section{Perspective of Probability}\n\\subsection{Abstract}\nIn this issue, we will observe multivariate Gaussian distribution from the perspective of probability.\n\\subsection{Prior Knowledge}\n$$\n\\begin{aligned}\nx &\\backsim N(\\mu, \\sigma^2)\\\\\n\\mu &\\in \\mathcal{R}^p, \\sigma \\in \\mathcal{R}^p\\\\\nx_i &\\backsim N(\\mu_i, \\sigma_i)\\\\\np(x_i) &= \\frac{1}{\\sqrt{2\\pi}\\sigma_i} \\exp(-\\frac{(x_i - \\mu_i)^2}{2\\sigma_i^2})\n\\end{aligned}\n$$\n\\subsection{Derivation}\nFirst, let's assume that each $x_i$ is $iid (independent\\ identically\\ distribution)$ as below:\n$$\n\\begin{aligned}\np(x)\n&=\\prod_{i=1}^p p(x_i)\\\\\n&=\\frac{1}{(2\\pi)^{\\frac{p}{2}}\\prod_{i=1}^p \\sigma_i} \\exp(-\\frac{1}{2}\\sum_{i=1}^p (\\frac{(x_i-\\mu_i)^2}{\\sigma_i^2}))\\\\\n&=\\frac{1}{(2\\pi)^{\\frac{p}{2}}|\\Sigma|^{\\frac{1}{2}}} \\exp(-\\frac{1}{2}\n\\left (\n\\begin{matrix}\nx_1-\\mu_1 & x_2-\\mu_2 & ... & x_p - \\mu_p\n\\end{matrix}\n\\right )\n\\left (\n\\begin{matrix}\n\\frac{1}{\\sigma_1^2} & 0 & ... & 0 \\\\\n... & ... & ... & ... \\\\\n0 & ... & 0 & \\frac{1}{\\sigma_p^2}\n\\end{matrix}\n\\right )\n\\left (\n\\begin{matrix}\nx_1-\\mu_1\\\\\n...&\\\\\n...&\\\\\nx_p-\\mu_p\n\\end{matrix}\n\\right ))\\\\\n&=\\frac{1}{(2\\pi)^{\\frac{p}{2}}|\\Sigma|^{\\frac{1}{2}}} \\exp(-\\frac{1}{2}(x-\\mu)^T \\Sigma^{-1}(x-\\mu))\n\\end{aligned}\n\\label{Gau.pdf}\n$$\nThe above is the probability density function of multivariate Gaussian distribution.\\\\\\\\\nWe know that $\\sigma$ is a positive semidefinite matrix, so we can perform singular value decomposition. So we have:\n$$\n\\begin{aligned}\n\\Sigma\n&=UVU^T\\\\\n&=\n\\left ( \\begin{matrix}\nu_1 & ... & u_p\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\n\\lambda_1 & 0 & ... & 0\\\\\n... & 0 & ... & ...\\\\\n0 & ... & ... & \\lambda_p\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\nu_1^T \\\\\n.\\\\\n.\\\\\nu_p^T\n\\end{matrix} \\right )\\\\\n&=\n\\left ( \\begin{matrix}\nu_1\\lambda_1 & ... & u_p \\lambda_p\\\\\n\\end{matrix} \\right )\n\\left ( \\begin{matrix}\nu_1^T\\\\\n.\\\\\n.\\\\\nu_p^T\n\\end{matrix} \\right )\\\\\n&=\\sum_{i=1}^p u_i\\lambda_i u_i^T\n\\end{aligned}\n$$\nthen\n$$\n\\begin{aligned}\n\\Sigma^{-1}\n&=(UVU^T)^{-1}\\\\\n&=(U^T)^{-1}V^{-1}U^{-1}\\\\\n&=UV^{-1}U^T\\\\\n&=\\sum_{i=1}^p u_i \\frac{1}{\\lambda_i} u_i^T\n\\end{aligned}\n$$\nLet's set $\\Delta = (x-\\mu)^T \\Sigma^{-1} (x-\\mu)$\\\\\\\\\nSubstitute the results derived above into:\n$$\n\\begin{aligned}\n\\Delta\n&=(x-\\mu)^T \\Sigma^{-1} (x-\\mu)\\\\\n&=(x-\\mu)^T \\sum_{i=1}^p u_i \\frac{1}{\\lambda_i}u_i^T (x-\\mu)\\\\\n&=\\sum_{i=1}^p(x-\\mu)^T u_i \\frac{1}{\\lambda_i}u_i^T (x-\\mu)\n\\end{aligned}\n$$\nLet's set $y_i=(x-\\mu)^T u_i$\\\\\\\\\nHere, $y_i $ represents the coordinate value of $x$ projected onto the new orthogonal basis $u_i$ after centralization.\\\\\nso:\n$$\n\\Delta=\\sum_{i=1}^p \\frac{y_i^2}{\\lambda_i}\n$$\nNext, let's look at the probability density function of multivariate Gaussian distribution:\n$$\np(x)=\\frac{1}{(2\\pi)^{\\frac{p}{2}}|\\Sigma|^{\\frac{1}{2}}} \\exp(-\\frac{1}{2}(x-\\mu)^T \\Sigma^{-1}(x-\\mu))\n$$\nYou can see that only the exponential part of the formula is related to the variable $x $. The previous factor is to make the probability sum $1 $.\\\\\nTherefore, the probability of Gaussian distribution is directly related to the value of $\\Delta $.\\\\\\\\\nWe assume $p=2$, then:\n$$\n\\frac{y_1^2}{\\lambda_1}+\\frac{y_2^2}{\\lambda_2}=\\Delta\n$$\nWe were surprised to find that this is very similar to the elliptic equation. The value of $\\Delta$ is not fixed, so for different $x$, these sample points form concentric ellipses in the plane. This is one of the properties of Gaussian distribution.\n\\end{document}", "meta": {"hexsha": "d65140ccd0e31c247cb76ffae4d23c8d38b0e83b", "size": 3495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EN-TeX_files/Intro_Math/02_fundamentals-of-math_gaussian-distribution_perspective-of-probability.tex", "max_stars_repo_name": "btobab/Machine-Learning-notes", "max_stars_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2021-08-28T18:47:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T07:36:27.000Z", "max_issues_repo_path": "EN-TeX_files/Intro_Math/02_fundamentals-of-math_gaussian-distribution_perspective-of-probability.tex", "max_issues_repo_name": "btobab/Machine-Learning-notes", "max_issues_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "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": "EN-TeX_files/Intro_Math/02_fundamentals-of-math_gaussian-distribution_perspective-of-probability.tex", "max_forks_repo_name": "btobab/Machine-Learning-notes", "max_forks_repo_head_hexsha": "bc064bd2fe3817444bb8850340ac1177f5fd71c4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-28T18:47:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-28T18:47:22.000Z", "avg_line_length": 29.125, "max_line_length": 250, "alphanum_fraction": 0.6268955651, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.6119108795066117}}
{"text": "\\documentclass{article}\n\\usepackage{tocloft}\n\\include{common_symbols_and_format}\n\\renewcommand{\\cfttoctitlefont}{\\Large\\bfseries}\n\\begin{document}\n\\logo\n\\rulename{True Strength Index} %Argument is name of rule\n\\tblofcontents\n\n\\ruledescription{The True Strength Index (TSI) is a momentum indicator used to identify overbought and oversold signals. It can also be used to indicate trend reversals using bullish and bearish crossover of the signal line and TSI line.}\n\n\\howtotrade\n{The strategy is to identify the oversold and overbought markets and a momentum indicator. \\\\\nBullish Momentum: when the TSI line cross above signal line. \\\\\nBearish Momentum: when signal line cross above TSI line\n}\n\n\n\\ruleparameters\n{Window size for Exponential moving average}{25}{This is the number of time steps over which exponential contributions are sourced.}{$\\lookbacklength$}\n{Window size for Exponential moving average}{13}{This is the number of time steps over which exponential contributions are sourced for smoothed momentum.}{$\\lookbacklength_{s}$}\n{Smoothing Factor}{2}{Smoothing factor represents the weighting applied to the most recent period’s value.}{$S$}\n\\stoptable\n\n\\newpage\n\\section{Equation}\n\\begin{equation}\n    \\Delta p_{\\currenttime} = p_{\\currenttime} - p_{\\currenttime - 1}\n\\end{equation}\n\n\\begin{equation}\n    EMA(\\Delta p_{\\currenttime}, S, \\lookbacklength) = \\Big(\\Delta p_{\\currenttime} * \\Big(\\frac{S}{1 + \\lookbacklength}\\Big)\\Big) + EMA_{\\currenttime-1} * \\Big(1-\\frac{S}{1 + \\lookbacklength}\\Big)\n\\end{equation}\n\n\\begin{equation}\n    EMA(|\\Delta p_{\\currenttime}|, S, \\lookbacklength) = \\Big(|\\Delta p_{\\currenttime}| * \\Big(\\frac{S}{1 + \\lookbacklength}\\Big)\\Big) + EMA_{\\currenttime-1} * \\Big(1-\\frac{S}{1 + \\lookbacklength}\\Big)\n\\end{equation}\n\n\\begin{equation}\n    TSI = 100 \\times \\frac{EMA(EMA(\\Delta p_{\\currenttime}, S, \\lookbacklength), S, \\lookbacklength_{s})}{EMA(EMA(|\\Delta p_{\\currenttime}|, S, \\lookbacklength), S,\\lookbacklength_{s})}\n\\end{equation}\n\\\\\n\nwhere: \\\\\n\n$TSI$ is True Strength Index. \\\\\n\n$EMA$ is exponentially weighted moving average. \\\\\n\n$p_{\\currenttime}$ is current stock value. \\\\\n\n$\\Delta p_{\\currenttime}$ is change in stock value. \\\\\n\n$|\\Delta p_{\\currenttime}|$ is absolute change in stock value. \\\\\n\n$\\lookbacklength$ \\ is look back length. \\\\\n\n$\\lookbacklength_{s}$ is look back length for smoothed momentum. \\\\\n\n$S$ is the smoothing factor.\n\n\\hspace{200mm}\n\\hspace{200mm}\n\\keyterms\n\\furtherlinks\n\\end{document}", "meta": {"hexsha": "192266849768cbbc080a96deec1890dd1421cef5", "size": 2465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/strategies/tex/TrueStrengthIndex.tex", "max_stars_repo_name": "parthgajjar4/infertrade", "max_stars_repo_head_hexsha": "2eebf2286f5cc669759de632970e4f8f8a40f232", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2021-03-25T13:32:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-06T23:03:01.000Z", "max_issues_repo_path": "docs/strategies/tex/TrueStrengthIndex.tex", "max_issues_repo_name": "parthgajjar4/infertrade", "max_issues_repo_head_hexsha": "2eebf2286f5cc669759de632970e4f8f8a40f232", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 137, "max_issues_repo_issues_event_min_datetime": "2021-03-25T10:59:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-28T19:36:30.000Z", "max_forks_repo_path": "docs/strategies/tex/TrueStrengthIndex.tex", "max_forks_repo_name": "parthgajjar4/infertrade", "max_forks_repo_head_hexsha": "2eebf2286f5cc669759de632970e4f8f8a40f232", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2021-03-26T14:26:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T18:21:14.000Z", "avg_line_length": 37.3484848485, "max_line_length": 238, "alphanum_fraction": 0.738336714, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6119108747663913}}
{"text": "\\section{Outlook}\n\n\\begin{frame}{Motivation}\n    \\begin{block}{Verlinde Formula}\n        \\begin{itemize}\n            \\item Let $\\mc{N}$ be the moduli space of stable $\\SL_{2}$-bundles over $\\Sigma_{2}$; it is isomorphic to $\\CC\\PP^{3}$ \\cite{NR1969}.\n            \\item Geometric quantisation $\\mc{Q}(\\mc{N}) := H^{0}(\\mc{N}; \\mc{L}^{\\otimes k})$; its dimension equals the \\textbf{Verlinde formula} \\cite{verlinde1988, JW1992},\n            \\begin{equation*}\n                \\begin{split}\n                    \\dim \\mc{Q}(\\mc{N}) = \\Ver(k) &= \\frac{k^{3}}{6} + k^{2} + \\frac{11k}{6} + 1 \\\\\n                    &= \\frac{(k+1)(k+2)(k+3)}{3!}.\n                \\end{split}\n            \\end{equation*}\n            \\item Named after Dutch physicist Erik Verlinde, who was working on conformal field theories.\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Integration}\n    \\begin{block}{Riemann-Roch-Hirzebruch Theorem}\n        For toric $X$, lattice point count of $\\Delta_{X}$ equals to Euler characteristic,\n        \\vspace*{-12pt}\n        $$ \\chi(X) = \\int_{X} e^{c_{1}( \\mc{O}(k) )}\\cdot \\Td{(TX)}. $$\n        \\vspace*{-12pt}\n    \\end{block}\n    \\begin{block}{Example}\n        For $X = \\CC\\PP^{3}$, have $e^{c_{1}(\\mc{O}(k))} = 1 + kH + \\tfrac{k^{2}}{2}H^{2} + \\tfrac{k^{3}}{6}H^{3}$, and $\\Td{(T\\CC\\PP^{3})} = 1 + 2H + \\tfrac{11}{6}H^{2} + H^{3}$:\n        $$ \\chi(\\CC\\PP^{3}) = \\int_{\\CC\\PP^{3}} \\big( \\tfrac{k^{3}}{6} + k^{2} + \\tfrac{11k}{6} + 1 \\big) \\cdot H^{3} + \\ldots = \\Ver(k). $$\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Our Direction}\n    \\begin{block}{Lattice Points}\n    \\begin{itemize}\n        \\item So $\\Ver(k) = \\chi(\\CC\\PP^{3}) = \\#( k\\cdot \\Delta_{3} \\cap \\ZZ^{3} )$.\n        \\item Anything similar for hypertoric manifolds?\n    \\end{itemize}\n    \\end{block}\n    \\begin{block}{Equivariant Verlinde Formula}\n        \\begin{itemize}\n            \\item Recently, equivariant Verlinde formula for moduli spaces Higgs bundle, $\\mc{M}$, popped up \\cite{GP2017}.\n            \\item $\\dim \\mc{Q} (\\mc{M}) = \\infty$, but $\\mc{M}$ has a $\\CC^{\\ast}$-action.\n            \\item Decompose into $\\CC^{\\ast}$-weight spaces:\n            \\vspace*{-6pt}\n                $$ \\dim \\mc{Q} (\\mc{M}) = \\sum_{n} t^{n} \\cdot \\dim \\mc{Q}_{n}(\\mc{M}), $$\n            \\vspace*{-6pt}\n            but now $\\dim \\mc{Q}_{n}(\\mc{M}) < \\infty$.\n        \\end{itemize}\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{Localisation}\n    \\begin{block}{Fixed-Point Formula}\n        \\vspace*{-12pt}\n        $$ \\sum_{q \\in \\Delta} e^{\\langle q, \\phi \\rangle} = \\sum_{p \\in M^{T}} \\frac{ e^{\\langle p, \\phi \\rangle} }{ \\prod_{k = 1}^{n} (1- e^{\\langle \\alpha_{k}^{p}, \\phi \\rangle}) }, $$\n            with edge vectors $\\alpha_{k}^{p}$, and $\\langle \\alpha_{k}^{p}, \\phi \\rangle \\neq 0$, \\cite{barvinok1993}.\n        \\begin{itemize}\n            \\item Letting $\\phi \\ra 0$ gets the lattice point count (for Delzant $\\Delta$).\n        \\end{itemize}\n    \\end{block}\n    \\begin{block}{Example for $T^{\\ast}\\CC\\PP^{3}$}\n        For $(T^{\\ast}\\CC\\PP^{3})_{\\epsilon-\\text{cut}}$, get\n        $$ \\frac{(\\epsilon + 1)(\\epsilon + 2)(\\epsilon + 3)}{3!} \\cdot \\frac{(k + \\epsilon +1)(k + \\epsilon + 2)(k + \\epsilon + 3)}{3!}. $$\n        Observe that for $\\epsilon = 0$, it becomes $\\Ver(k)$.\n    \\end{block}   \n\\end{frame}\n\n\\begin{frame}{Other Hypertoric Manifolds}\n    \\begin{block}{Non-Convex Core}\n        Want to see what happens for hypertoric manifolds with non-convex cores.\n    \\end{block}\n    \\begin{block}{Example}\n        \\vspace{136pt}\n    \\end{block}      \n\\end{frame}", "meta": {"hexsha": "92c8cba9754b084437ac00e15bb0f5b4963d4d63", "size": 3552, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/summary.tex", "max_stars_repo_name": "bencwbrown/WomenInSTEM-Semester2-2021", "max_stars_repo_head_hexsha": "8222f9ca0696d1f32feb3306f99b9294dd16c75f", "max_stars_repo_licenses": ["MIT"], "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/summary.tex", "max_issues_repo_name": "bencwbrown/WomenInSTEM-Semester2-2021", "max_issues_repo_head_hexsha": "8222f9ca0696d1f32feb3306f99b9294dd16c75f", "max_issues_repo_licenses": ["MIT"], "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/summary.tex", "max_forks_repo_name": "bencwbrown/WomenInSTEM-Semester2-2021", "max_forks_repo_head_hexsha": "8222f9ca0696d1f32feb3306f99b9294dd16c75f", "max_forks_repo_licenses": ["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.36, "max_line_length": 187, "alphanum_fraction": 0.5335022523, "num_tokens": 1298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012104, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6119108716062442}}
{"text": "% Written by Anders Sjoqvist and Ulf Lundstrom, 2009\n% The main sources are: tinyKACTL, Beta and Wikipedia\n% Transcribed to plain TeX by Richard Hladík in 2018.\n{\n% Quick fixes\n\\let\\section\\header\n\\def\\subsection#1{\\header{\\subsectionfont#1}}\n\\def\\subsubsection#1{\\header{\\subsubsectionfont#1}}\n\\chapter{Mathematics (text)}\n\n\\section{Equations}\n\n$$ax^2+bx+c=0 \\Rightarrow x = \\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$$\n\nThe extremum is given by $x = -b/2a$.\n%\n$$\\eqalign{ax+by&=e\\cr cx+dy&=f\\cr}\n\\,\\Rightarrow\\,\n\\eqalign{x&=\\frac{ed-bf}{ad-bc}\\cr y&=\\frac{af-ec}{ad-bc}\\cr}$$\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\nIf $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. $$\nNon-distinct roots $r$ become polynomial factors, e.g. $a_n = (d_1n + d_2)r^n$.\n\n\\section{Trigonometry}\n\n$$\\eqalign{\n\\sin(v+w)&=\\sin v\\cos w+\\cos v\\sin w\\cr\n\\cos(v+w)&=\\cos v\\cos w-\\sin v\\sin w\\cr\n\\tan(v+w)&=\\frac{\\tan v+\\tan w}{1-\\tan v\\tan w}\\cr\n\\sin v+\\sin w&=2\\sin\\frac{v+w}{2}\\cos\\frac{v-w}{2}\\cr\n\\cos v+\\cos w&=2\\cos\\frac{v+w}{2}\\cos\\frac{v-w}{2}\\cr\n(V+W)\\tan(v-w)/2&=(V-W)\\tan(v+w)/2\\cr}$$\nwhere $V, W$ are lengths of sides opposite angles $v, w$.\n$$\\eqalign{a\\cos x+b\\sin x&=r\\cos(x-\\phi)\\cr\na\\sin x+b\\cos x&=r\\sin(x+\\phi)\\cr}$$\nwhere $r=\\sqrt{a^2+b^2}$, $\\phi=\\mathop{\\rm atan2}(b,a)$.\n\n\\section{Geometry}\n\n\\subsection{Triangles}\n\nSide lengths: $a,b,c$\n\nSemiperimeter: $p=\\frac{a+b+c}{2}$\n\nArea: $A=\\sqrt{p(p-a)(p-b)(p-c)}$\n\nCircumradius: $R=\\frac{abc}{4A}$\n\nInradius: $r=\\frac{A}{p}$\n\nLength of median (divides triangle into two equal-area triangles):$$m_a=\\frac{1}{2}\\sqrt{2b^2+2c^2-a^2}$$\n\nLength of bisector (divides angles in two): $s_a=\\sqrt{bc\\left[1-\\left(\\frac{a}{b+c}\\right)^2\\right]}$\n\nLaw of sines: $\\frac{\\sin\\alpha}{a}=\\frac{\\sin\\beta}{b}=\\frac{\\sin\\gamma}{c}=\\frac{1}{2R}$\n\nLaw of cosines: $a^2=b^2+c^2-2bc\\cos\\alpha$\n\nLaw of tangents: $$\\frac{a+b}{a-b}=\\frac{\\tan\\frac{\\alpha+\\beta}{2}}{\\tan\\frac{\\alpha-\\beta}{2}}$$\n\n\\subsection{Quadrilaterals}\n\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{(p-a)(p-b)(p-c)(p-d)}$.\n\n\\subsection{Spherical coordinates}\n\\figure{kactl/math/sphericalCoordinates.pdf}\n\n$$\\eqalign{x &= r\\sin\\theta\\cos\\phi\\cr\ny &= r\\sin\\theta\\sin\\phi\\cr\nz &= r\\cos\\theta\\cr}\\;\\eqalign{\n\tr &= \\sqrt{x^2+y^2+z^2}\\cr\n\\theta &= \\mathop{\\rm acos}\\left(z/\\sqrt{x^2+y^2+z^2}\\right)\\cr\n\\phi &= \\mathop{\\rm atan2}\\left(y,x\\right)\\cr}$$\n\n\\section{Derivatives/Integrals}\n\n$$\\eqalign{\n\\frac{d}{dx}\\arcsin x &= \\frac{1}{\\sqrt{1-x^2}}\\cr\n\\frac{d}{dx}\\arccos x &= -\\frac{1}{\\sqrt{1-x^2}}\\cr\n\\frac{d}{dx}\\tan x &= 1+\\tan^2 x\\cr\n\\frac{d}{dx}\\arctan x &= \\frac{1}{1+x^2}\\cr}\\;\\;\\;\\eqalign{\n\\int\\tan ax &= -\\frac{\\ln|\\cos ax|}{a}\\cr\n\\int x\\sin ax &= \\frac{\\sin ax-ax \\cos ax}{a^2} \\cr\n\\int e^{-x^2} &= \\frac{\\sqrt \\pi}{2} \\text{erf}(x)\\cr\n\\int xe^{ax}dx &= \\frac{e^{ax}}{a^2}(ax-1)\\cr}$$\n\nIntegration by parts:\n$$\\int_a^bf(x)g(x)\\d x = [F(x)g(x)]_a^b-\\int_a^bF(x)g'(x)\\d x$$\n\n\\section{Sums}\n\n$$c^a + c^{a+1} + \\dots + c^{b} = \\frac{c^{b+1} - c^a}{c-1},\\; c \\neq 1$$\n%\n$$\\eqalign{\n\t1 + 2 + 3 + \\dots + n &= \\frac{n(n+1)}{2} \\cr\n\t1^2 + 2^2 + 3^2 + \\dots + n^2 &= \\frac{n(2n+1)(n+1)}{6} \\cr\n\t1^3 + 2^3 + 3^3 + \\dots + n^3 &= \\frac{n^2(n+1)^2}{4} \\cr\n\t1^4 + 2^4 + 3^4 + \\dots + n^4 &= \\frac{n(n+1)(2n+1)(3n^2 + 3n - 1)}{30} \\cr\n}$$\n\n\\section{Series} \n\n$$e^x = 1+x+\\frac{x^2}{2!}+\\frac{x^3}{3!}+\\dots,\\quad(-\\infty<x<\\infty)$$\n$$\\ln(1+x) = x-\\frac{x^2}{2}+\\frac{x^3}{3}-\\frac{x^4}{4}+\\dots,\\quad(-1<x\\leq1)$$\n$$\\sqrt{1+x} = 1+\\frac{x}{2}-\\frac{x^2}{8}+\\frac{2x^3}{32}-\\frac{5x^4}{128}+\\dots,\\quad(-1\\leq x\\leq1)$$\n$$\\sin x = x-\\frac{x^3}{3!}+\\frac{x^5}{5!}-\\frac{x^7}{7!}+\\dots,\\quad(-\\infty<x<\\infty)$$\n$$\\cos x = 1-\\frac{x^2}{2!}+\\frac{x^4}{4!}-\\frac{x^6}{6!}+\\dots,\\quad(-\\infty<x<\\infty)$$\n\n\\section{Probability theory}\n\nLet $X$ be a discrete random variable with probability $p_X(x)$ of assuming the\nvalue $x$. It will then have an expected value (mean)\n$\\mu={\\mathbb E}(X)=\\sum_xxp_X(x)$ and variance\n$\\sigma^2=V(X)={\\mathbb E}(X^2)-({\\mathbb E}(X))^2=\\sum_x(x-{\\mathbb E}(X))^2p_X(x)$\nwhere $\\sigma$ is the standard deviation. If $X$ is instead continuous it will\nhave a probability density function $f_X(x)$ and the sums above will instead be\nintegrals with $p_X(x)$ replaced by $f_X(x)$.\n\nExpectation is linear:\n$${\\mathbb E}(aX+bY) = a{\\mathbb E}(X)+b{\\mathbb E}(Y)$$\nFor independent $X$ and $Y$, $$V(aX+bY) = a^2V(X)+b^2V(Y).$$\n\n\\subsection{Discrete distributions}\n\n\\subsubsection{Binomial distribution}\nThe number of successes in $n$ independent yes/no experiments, each of 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)$ is approximately $\\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 of which 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\n\\subsection{Continuous distributions}\n\n\\subsubsection{Uniform distribution}\nIf the probability density function is constant between $a$ and $b$ and 0 elsewhere it is $\\textrm{U}(a,b),\\quad a<b$.\n$$f(x) = \\cases{{1\\over b-a}& $a<x<b$;\\cr0& otherwise.\\cr}$$\n%\n$$\\mu=\\frac{a+b}{2},\\quad\\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) = \\cases{\\lambda e^{-\\lambda x}&$x\\ge 0$,\\cr 0&otherwise.\\cr}$$\n$$\\mu=\\frac{1}{\\lambda},\\quad\\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 ${\\cal N}(\\mu,\\sigma^2)$, where $\\sigma>0$.\n$$ f(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}} $$\nIf $X_1 \\sim {\\cal N}(\\mu_1,\\sigma_1^2)$ and $X_2 \\sim {\\cal N}(\\mu_2,\\sigma_2^2)$ then\n$$ aX_1 + bX_2 + c \\sim {\\cal 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),\n% TODO: make \\scriptfont\\mathbb work\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.\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% \\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}$ leads 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\n\n\\section{Number-theoretical}\n\n\\subsection{Pythagorean Triples}\n The Pythagorean triples are uniquely generated by\n $$a=k\\cdot (m^{2}-n^{2}),\\ \\,b=k\\cdot (2mn),\\ \\,c=k\\cdot (m^{2}+n^{2}),$$\n with $m > n > 0$, $k > 0$, $m \\bot n$, and either $m$ or $n$ even.\n\n\\subsection{Primes}\n\t$p=962592769$ is such that $2^{21} \\mid p-1$, which may be useful. For hashing\n\tuse 970592641 (31-bit number), 31443539979727 (45-bit), 3006703054056749\n\t(52-bit). There are 78498 primes less than $1\\,000\\,000$.\n\n\tPrimitive roots exist modulo any prime power $p^a$, except for $p = 2, a > 2$, and there are $\\phi(\\phi(p^a))$ many.\n\tFor $p = 2, a > 2$, the group ${\\mathbb Z}_{2^a}^\\times$ is instead isomorphic to ${\\mathbb Z}_2 \\times {\\mathbb Z}_{2^{a-2}}$.\n\n\\subsection{Estimates}\n\t$\\sum_{d|n} d = O(n \\log \\log n)$.\n\n\tThe number of divisors of $n$ is at most around 100 for $n < 5e4$, 500 for $n < 1e7$, 2000 for $n < 1e10$, $200\\,000$ for $n < 1e19$.\n\n\\chapter{Combinatorial (text)}\n\n%\\section{The Twelvefold Way}\n%\t\\import{twelvefoldway.tex}\n\n\\section{Permutations}\n%\\subsection{Factorial}\n%\t\\import{factorial.tex}\n%\t\\kactlimport{intperm.h}\n\n\\subsection{Cycles}\n\tLet the number of $n$-permutations whose cycle lengths all belong to the set $S$ be denoted by $g_S(n)$. Then\n\t$$\\sum_{n=0} ^\\infty g_S(n) \\frac{x^n}{n!} = \\exp\\left(\\sum_{n\\in S} \\frac{x^n} {n} \\right)$$\n\n\\subsection{Involutions}\n\tAn involution is a permutation with maximum cycle length 2, and it is its own inverse.\n\t$$a(n) = a(n-1) + (n-1)a(n-2)$$\n\t$$a(0) = a(1) = 1$$\n\t1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496, 35696, 140152\n\n\\subsection{Stirling numbers of the first kind}\n\t$$s(n,k) = (-1)^{n-k}c(n,k)$$\n\t$c(n,k)$ is the unsigned Stirling numbers of the first kind, and they count the number of permutations on $n$ items with $k$ cycles.\n\t$$s(n,k) = s(n-1,k-1) - (n-1) s(n-1,k)$$\n\t$$s(0,0) = 1, s(n,0) = s(0,n) = 0$$\n\t$$c(n,k) = c(n-1,k-1) + (n-1) c(n-1,k)$$\n\t$$c(0,0) = 1, c(n,0)=c(0,n)=0$$\n\n\\subsection{Eulerian numbers}\n\tNumber of permutations $\\pi \\in S_n$ in which exactly $k$ elements are greater than the previous element. $k$ $j$:s s.t. $\\pi(j)>\\pi(j+1)$, $k+1$ $j$:s s.t. $\\pi(j)\\geq j$, $k$ $j$:s s.t. $\\pi(j)>j$.\n\t$$E(n,k) = (n-k)E(n-1,k-1) + (k+1)E(n-1,k)$$\n\t$$E(n,0) = E(n,n-1) = 1$$\n\t$$E(n,k) = \\sum_{j=0}^k(-1)^j\\binom{n+1}{j}(k+1-j)^n$$\n\n\\subsection{Burnside's lemma}\n\tGiven a group $G$ of symmetries and a set $X$, the number of elements of $X$ \\emph{up to symmetry} equals\n\t $$ {\\frac {1}{|G|}}\\sum _{{g\\in G}}|X^{g}|, $$\n\t where $X^{g}$ are the elements fixed by $g$ ($g.x = x$).\n\n\t If $f(n)$ counts \"configurations\" (of some sort) of length $n$, we can ignore rotational symmetry using $G = \\mathbb Z_n$ to get\n\t $$ g(n) = \\frac 1 n \\sum_{k=0}^{n-1}{f(\\text{gcd}(n, k))} = \\frac 1 n \\sum_{k|n}{f(k)\\phi(n/k)}. $$\n\n\\section{Partitions and subsets}\n\\subsection{Partition function}\n\tPartitions of $n$ with exactly $k$ parts, $p(n,k)$, i.e., writing $n$ as a sum of $k$ positive integers, disregarding the order of the summands.\n\t$$p(n,k) = p(n-1,k-1)+p(n-k,k)$$\n\t$$p(0,0)=p(1,n)=p(n,n)=p(n,n-1)=1$$\n\n\tFor partitions with any number of parts, $p(n)$ obeys\n\t$$ p(0) = 1,\\ p(n) = \\sum_{k \\in \\mathbb Z \\setminus \\{0\\}}{(-1)^{k+1} p(n - k(3k-1) / 2)} $$\n\t$$ p(n) \\sim 0.145 / n \\cdot \\exp(2.56 \\sqrt{n}) $$\n\n%\t\\begin{center}\n%\t\\begin{tabular}{c|c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c@{\\ }c}\n%\t\t$n$    & 0 & 1 & 2 & 3 & 4 & 5 & 6  & 7  & 8  & 9  & 20  & 50  & 100 \\\\ \\hline\n%\t\t$p(n)$ & 1 & 1 & 2 & 3 & 5 & 7 & 11 & 15 & 22 & 30 & 627 & $\\mathtt{\\sim}$2e5 & $\\mathtt{\\sim}$2e8 \\\\\n%\t\\end{tabular}\n%\t\\end{center}\n%\n%\n\\subsection{Stirling numbers of the second kind}\n\tPartitions of $n$ distinct elements into exactly $k$ groups.\n\t$$S(n,k) = S(n-1,k-1) + k S(n-1,k)$$\n\t$$S(n,1) = S(n,n) = 1$$\n\t$$S(n,k) = \\frac{1}{k!}\\sum_{j=0}^k (-1)^{k-j}\\binom{k}{j}j^n$$\n\n\\subsection{Bell numbers}\n\tTotal number of partitions of $n$ distinct elements.\n\t$$B(n) = \\sum_{k=1}^n \\binom{n-1}{k-1}B(n-k) = \\sum_{k=1}^n S(n,k)$$\n\t$$B(0) = B(1) = 1$$\n\tThe first are 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597.\n\tFor a prime $p$\n\t$$B(p^m+n)\\equiv mB(n)+B(n+1) \\pmod{p}$$\n\n\\subsection{Triangles}\n\tGiven rods of length $1,\\ldots,n$,\n\t$$T(n) = \\frac{1}{24} \\cases{n(n-2)(2n-5) & $n$ even\\cr(n-1)(n-3)(2n-1) & $n$ odd}.$$\n\tis the number of distinct triangles (positive are) that can be constructed, i.e., the \\# of 3-subsets of $[n]$ s.t. $x\\leq y\\leq z$ and $z\\neq x+y$.\n\n\\section{General purpose numbers}\n\\subsection{Catalan numbers}\n\t$$C_n=\\frac{1}{n+1}\\binom{2n}{n}= \\binom{2n}{n}-\\binom{2n}{n+1} = \\frac{(2n)!}{(n+1)!n!}$$\n\t$$C_{n+1} = \\frac{2(2n+1)}{n+2}C_n$$\n\t$$C_0=1, C_{n+1}=\\sum C_iC_{n-i}$$\n\tFirst few are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900.\n\t\t\\itemitem{$\\bullet$}\\# of monotonic lattice paths of a $n\\times n$-grid which do not pass above the diagonal.\n\t\t\\itemitem{$\\bullet$}\\# of expressions containing $n$ pairs of parenthesis which are correctly matched.\n\t\t\\itemitem{$\\bullet$}\\# of full binary trees with with $n+1$ leaves (0 or 2 children).\n\t\t\\itemitem{$\\bullet$}\\# of non-isomorphic ordered trees with $n+1$ vertices.\n\t\t\\itemitem{$\\bullet$}\\# of ways a convex polygon with $n+2$ sides can be cut into triangles by connecting vertices with straight lines.\n\t\t\\itemitem{$\\bullet$}\\# of permutations of $[n]$ with no three-term increasing subsequence.\n\n\\subsection{Super Catalan numbers}\n\tThe number of monotonic lattice paths of a $n\\times n$-grid that do not touch the diagonal.\n\t$$S(n) = \\frac{3(2n-3)S(n-1)-(n-3)S(n-2)}{n}$$\n\t$$S(1)=S(2)=1$$\n\t1, 1, 3, 11, 45, 197, 903, 4279, 20793, 103049, 518859\n\n\\subsection{Motzkin numbers}\n\tNumber of ways of drawing any number of nonintersecting chords among $n$ points on a circle. Number of lattice paths from $(0,0)$ to $(n,0)$ never going below the $x$-axis, using only steps NE, E, SE.\n\t$$M(n) = \\frac{3(n-1)M(n-2)+(2n+1)M(n-1)}{n+2}$$\n\t$$M(0) = M(1) = 1$$\n\t1, 1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798, 15511, 41835, 113634\n\n\\subsection{Narayana numbers}\n\tNumber of lattice paths from $(0,0)$ to $(2n,0)$ never going below the $x$-axis, using only steps NE and SE, and with $k$ peaks.\n\t$$N(n,k) = \\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}$$\n\t$$N(n,1) = N(n,n) = 1$$\n\t$$\\sum_{k=1}^n N(n,k) = C_n$$\n\t1, 1, 1, 1, 3, 1, 1, 6, 6, 1, 1, 10, 20, 10, 1, 1, 15, 50\n\n\\subsection{Schr\\\" oder numbers}\n\tNumber of lattice paths from $(0,0)$ to $(n,n)$ using only steps N,NE,E, never going above the diagonal. Number of lattice paths from $(0,0)$ to $(2n,0)$ using only steps NE, SE and double east EE, never going below the $x$-axis. Twice the Super Catalan number, except for the first term.\n\t1, 2, 6, 22, 90, 394, 1806, 8558, 41586, 206098\n\n}\n", "meta": {"hexsha": "673f66ef8ad0bf10347175c6e08437947130a7f3", "size": 15599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "export/chapters/math.tex", "max_stars_repo_name": "trinerdi/trinerdi-icpc", "max_stars_repo_head_hexsha": "c305484f2c4b338d0c59ce2f1e0fc47c5ee9d252", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-10-20T07:36:27.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-03T14:32:36.000Z", "max_issues_repo_path": "export/chapters/math.tex", "max_issues_repo_name": "trinerdi/trinerdi-icpc", "max_issues_repo_head_hexsha": "c305484f2c4b338d0c59ce2f1e0fc47c5ee9d252", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 38, "max_issues_repo_issues_event_min_datetime": "2017-10-22T14:11:37.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-25T13:07:33.000Z", "max_forks_repo_path": "export/chapters/math.tex", "max_forks_repo_name": "trinerdi/trinerdi-icpc", "max_forks_repo_head_hexsha": "c305484f2c4b338d0c59ce2f1e0fc47c5ee9d252", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-16T06:11:58.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-16T06:11:58.000Z", "avg_line_length": 46.2878338279, "max_line_length": 289, "alphanum_fraction": 0.6253606, "num_tokens": 6468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706735, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6119108700281162}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section*{Fri Oct 18 2019}\n\n\\subsection{Covariant differentiation}\n\nWe want to do derivatives, as in: \n%\n\\begin{equation}\n  f(x + \\dd{x} ) = f(x) + \\pdv{f}{x} \\dd{x} \n\\,,\n\\end{equation}\n%\nwhich allow us to ``move around''. In more dimensions,  the rule will be \n%\n\\begin{equation}\n  f(x + \\dd{x} ) - f(x) = \\dd{x^{\\mu }} \\partial_\\mu f\n\\,.\n\\end{equation}\n%\n\nNow, we want to prove that, in Minkowski spacetime, \\(\\partial_\\mu f\\) is a rank (0,1) tensor if \\(f\\) is a function.\n\nUnder a change of variables \\(x^{\\mu } \\rightarrow x^{\\prime \\mu }\\) we have \n%\n\\begin{equation}\n  \\pdv{f(x)}{x^{\\mu }} \\rightarrow \\pdv{f (x')}{x^{\\prime \\mu }} = \\pdv{x^{\\alpha }}{x^{\\prime \\mu }} \\pdv{}{x^{\\alpha }} f(x) \\marginnote{Since \\(x'\\) and \\(x\\) represent the same point, \\(f(x') = f(x)\\).}\n\\,,\n\\end{equation}\n%\nwhich is the transformation law of a covariant vector, or (0,1) tensor.\n\nHowever, for a vector \\(\\dd{x^{\\nu }} \\partial_\\nu A^{\\mu }\\) is \\emph{not} a tensor!\n\nUnder a change of coordinates, \n%\n\\begin{subequations}\n\\begin{align}\n  \\pdv{A^{\\mu}(x)}{x^{\\nu }}  &= \\pdv{}{x^{\\prime \\nu }} A^{\\mu }(x')   \\\\\n  &= \\pdv{x^{\\alpha }}{x^{\\prime \\nu }} \\pdv{}{x^{\\alpha }} \\qty(\\pdv{x^{\\prime \\mu }}{x^{\\beta }} A^{\\beta  }(x))    \\\\\n  &= \\pdv{x^{\\alpha }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\alpha }}{x^{\\beta }} +\n  \\pdv{x^{\\alpha }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\mu }}{x^{\\beta }} \\pdv{A^{\\beta }}{x^{\\alpha }}    \n  \\,,\n\\end{align}\n\\end{subequations}\n%\nand we can see that the second term is the transformation we want, but the first term spoils the transformation. \n\nThis is not an issue in SR: there, the second derivative vanishes:\n%\n\\begin{equation}\n    \\pdv[2]{x^{\\prime \\mu }}{x^{\\alpha }}{x^{\\beta }}\n    = \\pdv{}{x^{\\alpha }} \\Lambda^{\\mu }_{\\beta } = 0 \n\\,,\n\\end{equation}\n%\nsince Lorentz matrices are constant.\n\nSo, we construct a \\emph{Covariant Derivative} which transforms as a tensor under diffeomorphisms.\n\nWe denote it as \\(\\nabla_\\nu A^{\\mu }\\).\nFor any tensor \\(T\\) of arbitrary rank \\((p, q)\\) we request \\(\\nabla_\\nu T\\) to be a tensor of rank \\((p, q+1)\\).\nAlso, we request \\(\\nabla_\\mu \\rightarrow \\partial_\\mu\\) for flat spacetime.\n\nWe define the Christoffel symbols: \n%\n\\begin{equation}\n  \\Gamma_{\\mu \\nu }^{\\alpha } =\n  \\frac{1}{2} g^{\\alpha \\lambda } \\qty(g_{\\lambda \\mu , \\nu }+ g_{\\lambda \\nu , \\mu } - g_{\\mu \\nu , \\lambda })\n\\,,\n\\end{equation}\n%\nwhere we introduced comma notation for partial non-covariant differentiation: the full notation is \n%\n\\begin{align}\n\\partial_{\\mu } x_{A} \\overset{\\text{def}}{=}  x_{A, \\mu } \n\\qquad \\text{and} \\qquad\n\\nabla_{\\mu } x_{A} \\overset{\\text{def}}{=} x_{A;\\mu }\n\\,.\n\\end{align}\n%\n\nThey are symmetric in the two lower indices and they are not tensors. Their transformation law is: \n%\n\\begin{equation}\n  \\Gamma_{\\nu \\kappa }^{\\mu }\\rightarrow\n  \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv{x^{\\beta }}{x^{\\prime \\nu }} \\pdv{x^{\\gamma }}{x^{\\prime \\mu }} \\Gamma^{\\alpha }_{\\beta \\gamma } + \n  \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }}  \n\\,,\n\\end{equation}\n%\nwhich we note is \\emph{not tensorial}!\n\nWe define \n%\n\\begin{equation}\n    \\nabla_{\\nu }V_{\\mu } = \\partial_{\\nu } V_\\mu - \\Gamma_{\\nu \\mu }^{\\alpha } V_{\\alpha }\n\\,,\n\\end{equation}\n%\nand \n%\n\\begin{equation}\n    \\nabla_{\\nu }V^{\\mu} = \\partial_{\\nu } V_\\mu + \\Gamma_{\\nu \\alpha  }^{\\mu  } V^{\\alpha }\n\\,.\n\\end{equation}\n%\n\nHow does it transform? For the covariant derivative, we have:\n%\n\\begin{subequations}\n\\begin{align}\n  \\nabla_{\\nu }' V_{\\kappa }' &= \\pdv{}{x^{\\prime \\nu }} V'_\\kappa - \\Gamma^{\\prime \\mu }_{\\nu \\kappa } V_{\\mu  }'  \\\\\n  &= \\pdv{x^{\\mu }}{x^{\\prime \\nu }} \\partial_{\\mu } \\qty(\\pdv{x^{\\lambda }}{x^{\\prime \\kappa}}V_{\\lambda }) -  \\qty(\\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv{x^{\\beta }}{x^{\\prime \\nu }} \\pdv{x^{\\gamma }}{x^{\\prime \\mu }} \\Gamma^{\\alpha }_{\\beta \\gamma } + \n  \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }} ) \n  \\qty(\\pdv{x^{\\lambda }}{x^{\\prime \\mu }} V_{\\lambda })  \\\\\n  &= \\pdv[2]{x^{\\lambda }}{x^{\\prime \\nu }}{x^{\\prime \\mu }} V_{\\lambda }\n  + \\pdv{x^{\\lambda }}{x^{\\prime \\mu}} \\pdv{V_{\\lambda }}{x^{\\prime \\nu }} - \n  \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\qty(\\pdv{x^{\\beta }}{x^{\\prime \\nu }}\\pdv{x^{\\gamma }}{x^{\\prime \\kappa }} \\Gamma^{\\alpha }_{\\beta \\gamma }  + \\pdv[2]{x^{\\alpha }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }} ) \\pdv{x^{\\lambda }}{x^{\\prime \\mu }} V_{\\lambda }   \\\\\n  &=\\pdv[2]{x^{\\lambda }}{x^{\\prime \\nu }}{x^{\\prime \\mu }} V_{\\lambda }\n  + \\pdv{x^{\\lambda }}{x^{\\prime \\kappa }} \\pdv{x^{\\alpha }}{x^{\\prime \\nu }} \\pdv{V_{\\lambda } }{x^{\\alpha }}\n  - \\qty(\\pdv{x^{\\beta }}{x^{\\prime \\nu }}\\pdv{x^{\\gamma }}{x^{\\prime \\kappa }} \\Gamma^{\\alpha }_{\\beta \\gamma }  + \\pdv[2]{x^{\\alpha }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }} ) \\delta^{\\lambda }_{\\alpha }V_{\\lambda }   \\\\\n  &= \\pdv[2]{x^{\\lambda }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }} V_{\\lambda } \n  + \\pdv{x^{\\lambda }}{x^{\\prime \\kappa }} \\pdv{x^{\\alpha }}{x^{\\prime \\nu }} \\pdv{V_{\\lambda } }{x^{\\alpha }}\n  - \\pdv{x^{\\beta }}{x^{\\prime \\nu }} \\pdv{x^{\\gamma }}{x^{\\prime \\kappa }} \\Gamma^{\\alpha }_{\\beta \\gamma }V_{\\alpha }\n  -\\pdv[2]{x^{\\lambda }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }} V_{\\lambda }   \\\\\n  &= \\pdv{x^{\\lambda }}{x^{\\prime \\kappa }} \\pdv{x^{\\alpha }}{x^{\\prime \\nu }}\n  \\qty(\\pdv{V_{\\lambda }}{x^{\\alpha } } - \\Gamma^{\\sigma }_{\\alpha \\lambda }V_{\\sigma })  \\\\\n  &= \\pdv{x^{\\lambda }}{x^{\\prime \\kappa }} \\pdv{x^{\\alpha }}{x^{\\prime \\nu }}\n  \\nabla_{\\alpha }V_{\\lambda }\n  \\,,\n\\end{align}\n\\end{subequations}\n%\nwhere we used: relabeling of indices, contraction of the Jacobian matrix with its inverse, the chain rule, the product rule, the transformation law of the Christoffel symbols (some steps are wrong... oh well, there's more interesting stuff to do).\n\nThe derivative of a contravariant tensor is a tensor: this can be proven by noticing that \\(\\nabla_\\mu (A^{\\alpha }B_{\\alpha }) = \\partial_\\mu (A^{\\alpha }B_{\\alpha }) = B_{\\alpha } \\nabla_{\\mu }A^{\\alpha } + A^{\\alpha }\\nabla_{\\mu }B_{\\alpha }\\). Otherwise, we can compute away:\n%\n\\begin{subequations}\n\\begin{align}\n  \\nabla_{\\nu }' V^{\\prime \\mu }  &= \\pdv{V^{\\prime \\mu }}{x^{\\prime \\nu }} + \\Gamma^{\\prime \\mu }_{\\nu \\kappa }V^{\\prime \\kappa }  \\\\\n  &= \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{}{x^{\\lambda }} \\qty(\\pdv{x^{\\prime \\mu }}{x^{\\alpha }} V^{\\alpha }) \n  +   \\qty(\\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv{x^{\\beta }}{x^{\\prime \\nu }} \\pdv{x^{\\gamma }}{x^{\\prime \\mu }} \\Gamma^{\\alpha }_{\\beta \\gamma } \n  + \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\prime \\nu }}{x^{\\prime \\kappa }}) \\qty(\\pdv{x^{\\prime \\kappa }}{x^{\\sigma }} V^{\\sigma })  \\\\\n  &= \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\lambda }}{x^{\\alpha }} V^{\\alpha }\n  + \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv{V^{\\alpha }}{x^{\\lambda }}\n  + \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv{x^{\\beta }}{x^{\\prime \\nu }} \\delta^{\\gamma}_{\\sigma } \\Gamma^{\\alpha }_{\\beta \\gamma } V^{\\gamma }+ \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{\\prime \\alpha }}{x^{\\nu }}{x^{\\mu }} \\pdv{x^{\\prime \\kappa }}{x^{\\sigma}} V^{\\sigma }    \\\\\n  &= \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\lambda }}{x^{\\alpha }} V^{\\alpha }\n  + \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\qty(\\pdv{V^{\\alpha }}{x^{\\lambda }} + \\Gamma^{\\alpha }_{\\lambda \\gamma } V^{\\gamma })  \\\\\n  & = \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\nabla_{\\lambda }V^{\\alpha }\n  + \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\lambda }}{x^{\\alpha }}V^{\\alpha }\n  + \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{ \\alpha }}{x^{\\prime \\sigma }}{x^{\\prime \\kappa }} \\pdv{x^{\\prime \\kappa }}{x^{ \\sigma }} V^{\\sigma }  \n  \\,,\n\\end{align}\n\\end{subequations}\n%\nand we would like to see that the two last terms cancel: is \n%\n\\begin{equation}\n    \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\lambda }}{x^{\\alpha }}V^{\\alpha }\n    + \\pdv{x^{\\prime \\mu }}{x^{\\alpha }} \\pdv[2]{x^{ \\alpha }}{x^{\\prime \\sigma }}{x^{\\prime \\kappa }} \\pdv{x^{\\prime \\kappa }}{x^{ \\sigma }} V^{\\sigma }  \\overset{?}{=} 0 \n\\,,\n\\end{equation}\n%\nfor all \\(V^{\\mu }\\)? Let us factor the vector, changing the indices: \n%\n\\begin{equation}\n    \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv[2]{x^{\\prime \\mu }}{x^{\\lambda }}{x^{\\alpha }}\n    + \\pdv{x^{\\prime \\mu }}{x^{\\sigma }} \\pdv[2]{x^{ \\sigma }}{x^{\\prime \\alpha }}{x^{\\prime \\kappa }} \\pdv{x^{\\prime \\kappa }}{x^{ \\alpha }} \\overset{?}{=} 0\n\\,,\n\\end{equation}\n%\nwe can rewrite it as \n%\n\\begin{equation}\n    \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{}{x^{\\alpha }}  \\pdv{x^{\\prime \\mu }}{x^{\\lambda }}\n    + \\pdv{x^{\\prime \\mu }}{x^{\\lambda  }} \n    \\pdv{}{x^{\\prime \\kappa }} \n    \\pdv{x^{ \\lambda }}{x^{\\prime \\nu }}\n    \\pdv{x^{\\prime \\mu }}{x^{ \\alpha }} \\overset{?}{=} 0\n\\,,\n\\end{equation}\n%\nwhich can be recombined into: \n%\n\\begin{equation}\n    \\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{}{x^{\\alpha }}  \\pdv{x^{\\prime \\mu }}{x^{\\lambda }}\n    + \\pdv{x^{\\prime \\mu }}{x^{\\lambda  }} \n    \\pdv{}{x^{\\alpha  }} \n    \\pdv{x^{ \\lambda }}{x^{\\prime \\nu }}\n    \\overset{?}{=} 0\n\\,,\n\\end{equation}\n%\nand becomes \n%\n\\begin{equation}\n  \\pdv{}{x^{\\alpha }} \\qty(\\pdv{x^{\\lambda }}{x^{\\prime \\nu }} \\pdv{x^{\\prime \\mu }}{x^{\\lambda }} ) \n  = \\pdv{}{x^{\\alpha }} \\delta^{\\mu}_{\\nu }\n  = 0\n\\,.\n\\end{equation}\n%\n\nFor any order tensor,  we add a Christoffel symbol for every index, such as in: \n%\n\\begin{equation}\n  \\nabla_{\\mu }V_{\\alpha \\beta }   \n  = \\partial_\\mu V_{\\alpha \\beta } - \\Gamma^{\\lambda}_{\\mu \\alpha }V_{\\lambda \\beta }- \\Gamma^{\\lambda }_{\\mu \\beta }V_{\\alpha \\lambda }\n\\,,\n\\end{equation}\n%\nor \n%\n\\begin{equation}\n    \\nabla_{\\mu }V_{\\alpha}^{\\beta }   \n    = \\partial_\\mu V_{\\alpha}^{\\beta }\n    - \\Gamma^{\\lambda}_{\\mu \\alpha }V_{\\lambda}^{\\beta }\n    + \\Gamma^{\\beta }_{\\mu \\lambda  }V_{\\alpha}^{\\lambda }\n\\,.\n\\end{equation}\n\n\\begin{bluebox}\n  \n\nThe general formula reads: \n%\n\\begin{align}\n\\nabla_{\\pi } T^{\\mu_1 \\dots \\mu_{n}}_{\\nu_1 \\dots \\nu_{p}} =\n\\partial_{\\pi } T^{\\mu_1 \\dots \\mu_{n}}_{\\nu_1 \\dots \\nu_{p}}\n+ \\sum_{i=1}^{n} \\Gamma^{\\mu_{i}}_{\\pi \\sigma }\nT^{\\mu_1 \\dots \\mu_{i-1} \\sigma \\mu_{i+1} \\dots \\mu_{n}}_{\\nu_1 \\dots \\nu_{p}}\n- \\sum _{j=1}^{p} \\Gamma^{\\sigma }_{\\pi \\nu_j}\nT^{\\mu_1 \\dots \\mu_{n}}_{\\nu_1 \\dots \\nu_{i-1} \\sigma \\nu_{i+1} \\dots \\nu_{p}}\n\\,,\n\\end{align}\n%\nwhich can be generalized to tensor \\emph{densities} beyond regular tensors: any tensor tensity \\(\\mathfrak{T}\\) (with any amount of indices, omitted for simplicity) of weight \\(w\\) (that is, which transforms almost like a tensor, with an extra factor of the determinant of the metric raised to the \\(w\\)th power) can be written as \\(\\mathfrak{T} = \\sqrt{-g}^{w} T\\), where \\(g\\) is the determinant of the metric while \\(T\\) is a regular tensor, since as we saw \\(\\sqrt{-g}\\) is a density of weight +1.\n\nThen, we can use this to calculate the covariant derivative of a tensor density: we can express \\(T = \\sqrt{-g}^{-w} \\mathfrak{T}\\), so the rule will be \n%\n\\begin{align}\n\\nabla_{\\mu } \\mathfrak{T} = \\nabla_{\\mu } \\qty(\\sqrt{-g}^{w} \\sqrt{-g}^{-w} \\mathfrak{T})\n= \\sqrt{-g}^{w} \\nabla_{\\mu } \\qty(\\sqrt{-g}^{-w} \\mathfrak{T})\n\\,,\n\\end{align}\n%\nwhere we used the fact that \n%\n\\begin{align}\n\\nabla_{\\mu} \\sqrt{-g} = 0\n\\,,\n\\end{align}\n%\nwhich follows from the fact that the metric is covariantly constant: if we compute it in a LIF, then we get \n%\n\\begin{align}\n\\nabla_{ \\mu} \\qty(\\sqrt{-g})^{w} = \\partial_{\\mu } \\sqrt{-g}^{w}\n- w \\Gamma^{\\alpha }_{\\alpha \\mu} \\sqrt{-g} \n\\,,\n\\end{align}\n%\nwhich is zero:\\footnote{For a derivation of this expression, see \\url{https://yarikraak.nl/tensor_densities.pdf}} there, the coordinate derivatives of the metric are zero, and therefore the Christoffel symbols are also zero. \n\\end{bluebox}\n\n\n\\subsection{Properties of the covariant derivative}\n\n\\begin{itemize}\n    \\item The covariant derivative of a tensor is a tensor;\n    \\item the covariant derivative obeys the Leibniz rule: \\(\\nabla_{\\mu} (AB) = B \\nabla_{\\mu }A + A \\nabla_{\\mu }B\\);\n    \\item the metric is covariantly constant: \\(\\nabla_{\\mu }g_{\\alpha \\beta }=0\\). \n\\end{itemize}\n\nThe fact that the metric is covariantly constant could actually be assumed instead of the explicit expression of the Christoffel symbols in terms of derivatives of the metric. These two are equivalent.\n\nNotice that covariant derivatives do \\emph{not} commute!\n\nWe can check that \\(\\partial_{\\mu} (A^{\\alpha }B_{\\alpha }) = \\nabla_{\\mu } (A^{\\alpha }B_{\\alpha })\\). It is \n%\n\\begin{equation}\n  \\qty(\\partial_{\\mu }A_{\\alpha } - \\Gamma^{\\lambda }_{\\mu \\alpha }A_{\\lambda })B^{\\alpha } \n  + A_{\\alpha }\\qty(\\partial_{\\mu }B^{\\alpha } + \\Gamma_{\\mu \\lambda }^{ \\alpha }B^{\\lambda })\n\\,,\n\\end{equation}\n%\nexpanding and relabeling indices we get the desired cancellation. Now, for parallel transport:\n\n\\subsection{Parallel transport}\n\nTake a curve \\(x^{\\alpha }(\\lambda )\\) and a vector \\(V^{\\mu }\\) defined at a certain point along the curve.\nFor infinitesimal displacement we will have \\(\\dd{V} = \\dd{x} \\cdot \\nabla V\\): in components \\(\\dd{V^{\\mu }} = \\dd{x^{\\alpha }} \\nabla_{\\alpha }V^{\\mu }\\).\n\nParallel transport means that the vector does not change when it is transported: \\(\\nabla_t V^{\\mu }=0\\) where the index \\(t \\) indicates derivation along the curve's tangent vector \\(t^{\\alpha }= \\dv*{x^{\\alpha }}{\\lambda } \\): more explicitly, \\(V^{\\mu }\\) is parallel-transported along the curve parametrized as \\(x^{\\alpha }(\\lambda )\\) if \n%\n\\begin{align}\n\\dv{}{\\lambda } \\qty(V^{\\mu }(x^{\\alpha }(\\lambda )))\n=\n\\dv{x^{\\alpha }}{\\lambda } \\nabla_{\\alpha } V^{\\mu } \n= 0\n\\,.\n\\end{align}\n\n\\end{document}", "meta": {"hexsha": "4d4cf87f8e49976922e9d84c0bfea3c1dd628059", "size": 13776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/general_relativity/18oct.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/general_relativity/18oct.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/general_relativity/18oct.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": 45.1672131148, "max_line_length": 501, "alphanum_fraction": 0.580937863, "num_tokens": 5403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6119108573875277}}
{"text": "\\subsection{Analytical solution}\nWill not work because of how \\eqref{line} is defined. It would have to be the line between the two points that is on the spherical surface.\n\\begin{equation}\n    g(s)=K(f(s))\n\\end{equation}\n\\begin{equation}\n    g'(s) = \\underbrace{K'(f(s))}_{\\text{3$\\times$2 Matrix}}\\cdot\\underbrace{f'(s)}_{\\text{2$\\times$1 Vector}}=\\text{3$\\times$1 Vector}\n\\end{equation}\n\\begin{equation}\n    g'(a,b,s) = K'(f(a,b,s))\\cdot f'(a,b,s)\n\\end{equation}\n\\begin{equation}\n    g'(\\theta_1,\\varphi_1,\\theta_2,\\varphi_2,s)\n\\end{equation}\n\\begin{equation}\n    K'(f(s))=K'\n    \\begin{pmatrix}\n        (1-s)\\cdot\\theta_1 + s\\cdot\\theta_2 \\\\\n        (1-s)\\cdot\\varphi_1 + s\\cdot\\varphi_2\n    \\end{pmatrix}\n\\end{equation}\ngiven:\n\\begin{equation*}\n    A\\dbinom{\\theta_1}{\\varphi_1}, B\\dbinom{\\theta_2}{\\varphi_2}, C\\dbinom{\\theta_3}{\\varphi_3}\n\\end{equation*}\n\\begin{equation}\n    \\cos(\\alpha)=\\frac{\\langle g'(A,B,0), g'(A,C,0)\\rangle}{\\|g'(A,B,0))\\|\\cdot \\|g'(A,C,0)\\|}\n\\end{equation}\n\\begin{equation}\n    \\cos(\\beta)=\\frac{\\langle g'(B,A,0), g'(B,C,0)\\rangle}{\\|g'(B,A,0))\\|\\cdot \\|g'(B,C,0)\\|}\n\\end{equation}\n\\begin{equation}\n    \\cos(\\gamma)=\\frac{\\langle g'(C,A,0), g'(C,B,0)\\rangle}{\\|g'(C,A,0))\\|\\cdot \\|g'(C,B,0)\\|}\n\\end{equation}\n\\begin{lstlisting}[escapechar=@]\n    def f(a, b, s) {\n        res[0] = (1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0]\n        res[1] = (1-s)@$\\cdot$@a[1] + s@$\\cdot$@b[1]\n        return res\n    }\n\\end{lstlisting}\nParameters tp representing $\\theta\\varphi$\n\\begin{lstlisting}[escapechar=@]\n    def k'(tp) {\n        res[0, 0] = cos(tp[0])@$\\cdot$@cos(tp[1])\n        res[1, 0] = cos(tp[0])@$\\cdot$@sin(tp[1])\n        res[2, 0] = -sin(tp[0])\n        res[0, 1] = -sin(tp[0])@$\\cdot$@sin(tp[1])\n        res[1, 1] = sin(tp[0])@$\\cdot$@cos(tp[1])\n        return res\n    }\n\\end{lstlisting}\n\\begin{lstlisting}[escapechar=@]\n    def f'(a, b) {\n        res[0] = b[0] - a[0]\n        res[1] = b[1] - a[1]\n        retrun res\n    }\n\\end{lstlisting}\nUse $f(a, b, s)$ as tp in $k'(tp)$ and multiply resulting matrix with vector $f'(a, b)$. Resulting in an 3$\\times$1 Vector.\n\\begin{equation*}\n    \\begin{pmatrix}\n        a && b \\\\\n        c && d \\\\\n        e && f\n    \\end{pmatrix}\n    \\cdot\n    \\begin{pmatrix}\n        u \\\\\n        v\n    \\end{pmatrix}\n    =\n    \\begin{pmatrix}\n        a\\cdot u + b\\cdot v \\\\\n        c\\cdot u + d\\cdot v \\\\\n        e\\cdot u + f\\cdot v\n    \\end{pmatrix}\n\\end{equation*}\n\\begin{lstlisting}[escapechar=@]\n    def g'(a, b, s) {\n        res[0] = (cos((1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0])@$\\cdot$@\n            cos((1-s)@$\\cdot$@a[1] + s@$\\cdot$@b[1]))@$\\cdot$@(b[0] - a[0]) +\n            (-sin((1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0])@$\\cdot$@\n            sin((1-s)@$\\cdot$@a[1] + s@$\\cdot$@b[1]))@$\\cdot$@(b[1] - a[1])\n        res[1] = (cos((1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0])@$\\cdot$@\n            sin((1-s)@$\\cdot$@a[1] + s@$\\cdot$@b[1]))@$\\cdot$@(b[0] - a[0]) +\n            (sin((1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0]))@$\\cdot$@\n            cos((1-s)@$\\cdot$@a[1] + s@$\\cdot$@b[1]))@$\\cdot$@(b[1] - a[1])\n        res[2] = (-sin((1-s)@$\\cdot$@a[0] + s@$\\cdot$@b[0]))@$\\cdot$@\n            (b[0] - a[0])\n        return res\n    }\n\\end{lstlisting}\nFor $s$ being $0$:\n\\begin{lstlisting}[escapechar=@]\n    def g'(a, b) {\n        res[0] = cos(a[0])@$\\cdot$@cos(a[1])@$\\cdot$@(b[0] - a[0]) -\n            sin(a[0])@$\\cdot$@sin(a[1])@$\\cdot$@(b[1] - a[1])\n        res[1] = cos(a[0])@$\\cdot$@sin(a[1])@$\\cdot$@(b[0] - a[0]) +\n            sin(a[0])@$\\cdot$@cos(a[1])@$\\cdot$@(b[1] - a[1])\n        res[2] = -sin(a[0])@$\\cdot$@(b[0] - a[0])\n        return res\n}\n\\end{lstlisting}", "meta": {"hexsha": "d7927052b89c6ba273239554f0a617d409902756", "size": 3601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/analytical.tex", "max_stars_repo_name": "paddyez/ingress", "max_stars_repo_head_hexsha": "44b4fde664ee562d516de3dd7e49aa2f1e539d79", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-11T11:07:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-11T11:07:14.000Z", "max_issues_repo_path": "tex/analytical.tex", "max_issues_repo_name": "paddyez/ingress", "max_issues_repo_head_hexsha": "44b4fde664ee562d516de3dd7e49aa2f1e539d79", "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": "tex/analytical.tex", "max_forks_repo_name": "paddyez/ingress", "max_forks_repo_head_hexsha": "44b4fde664ee562d516de3dd7e49aa2f1e539d79", "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": 34.625, "max_line_length": 139, "alphanum_fraction": 0.4981949458, "num_tokens": 1554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6118494962789827}}
{"text": "\\section{The Euler-Lagrange Equation}\r\n\\subsection{Derivation of the Equation}\r\nWe now move on to the most important theorem of the course, which gives a necessary condition to extremise a functional in the form\r\n$$F[y]=\\int_\\alpha^\\beta f(x,y,y^\\prime)\\,\\mathrm dx$$\r\nwhere $f$ is given.\r\nIn contexts of geometry and physics, $y$ is most likely to carry the meaning of the trajectory of some point.\\\\\r\nWe first assume that a extremum $y$ exists, then when we apply a small perturbation $y\\mapsto y+\\epsilon\\eta$ with $\\eta(\\alpha)=\\eta(\\beta)=0$ to keep the endpoint fixed.\r\nNow we want to compute $F[y+\\epsilon\\eta]$, but first of all we will need a lemma.\r\n\\begin{lemma}\\label{fund_lemma}\r\n    If $g:[\\alpha,\\beta]\\to\\mathbb R$ is continuous on $[\\alpha,\\beta]$ and\r\n    $$\\int_\\alpha^\\beta g(x)\\eta(x)\\,\\mathrm dx=0$$\r\n    for all $\\eta\\in C([\\alpha,\\beta])$ with $\\eta(\\alpha)=\\eta(\\beta)=0$, then $\\forall x\\in [\\alpha,\\beta],g(x)=0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Assume for sake of contradiction that there exists some $\\bar{x}$ on $(\\alpha,\\beta)$ such that $g(\\bar{x})\\neq 0$.\r\n    WLOG $g(\\bar{x})>0$, then by continuity there is an interval $[x_1,x_2]\\subset[\\alpha,\\beta]$ such that $\\exists c>0,\\forall x\\in [x_1,x_2],g(x)>c$.\r\n    Set\r\n    $$\\eta(x)=\\begin{cases}\r\n        (x-x_1)(x_2-x)\\text{, if $x\\in [x_1,x_2]$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Then\r\n    \\begin{align*}\r\n        \\int_\\alpha^\\beta g(x)\\eta(x)\\,\\mathrm dx\r\n        &=\\int_{x_1}^{x_2}g(x)(x-x_1)(x_2-x)\\,\\mathrm dx\\\\\r\n        &\\ge\\int_{x_1}^{x_2}c(x-x_1)(x_2-x)\\,\\mathrm dx\\\\\r\n        &>0\r\n    \\end{align*}\r\n    Contradiction.\r\n    So $g$ is zero on $(\\alpha,\\beta)$, and it is also zero at $\\alpha,\\beta$ by continuity, hence $g$ is zero on $[\\alpha,\\beta]$.\r\n\\end{proof}\r\nThe $\\eta$ we have used above is called a bump function, which is $C^2$ as one can verify.\r\nOne can also make a $C^k$ bump function by considering\r\n\\footnote{It is also easy to construct a $C^{\\infty}$ bump function.}\r\n$$\\eta(x)=\\begin{cases}\r\n    ((x-x_1)(x_2-x))^{k+1}\\text{, if $x\\in [x_1,x_2]$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\nNow back at $F[y+\\epsilon\\eta]$, then\r\n\\begin{align*}\r\n    F[y+\\epsilon\\eta]&=\\int_\\alpha^\\beta f(x,y+\\epsilon\\eta,y^\\prime+\\epsilon\\eta^\\prime)\\,\\mathrm dz\\\\\r\n    &=F[y]+\\epsilon\\int_\\alpha^\\beta\\left( \\frac{\\partial f}{\\partial y}\\eta+\\frac{\\partial f}{\\partial y^\\prime}\\eta^\\prime \\right)\\,\\mathrm dx+O(\\epsilon^2)\r\n\\end{align*}\r\nWe will analysis the $O(\\epsilon^2)$ remainder later.\r\nFor now, we just observe that for $y$ to be an extremum, the first-order term shall vanish, so we want something like $\\partial F[y+\\epsilon\\eta]/\\partial\\epsilon=0$.\\\\\r\nIntegrate the vanishing first-order coefficient by part,\r\n\\begin{align*}\r\n    0&=\\left.\\frac{\\partial f}{\\partial y^\\prime}\\eta\\right|_\\alpha^\\beta+\\int_\\alpha^\\beta\\left( \\frac{\\partial f}{\\partial y}\\eta-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime}\\eta \\right)\\,\\mathrm dx\\\\\r\n    &=\\int_\\alpha^\\beta\\left( \\frac{\\partial f}{\\partial y}-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime} \\right)\\eta\\,\\mathrm dx\r\n\\end{align*}\r\nBy the preceding lemma, we must have\r\n$$\\frac{\\partial f}{\\partial y}-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime}=0$$\r\nThis is known as the Euler-Lagrange equation, which is the necessary condition for an extremum.\r\nThis equation is first developed in 1745 in a letter from Lagrange to Euler.\r\n\\begin{remark}\r\n    1. The Euler-Lagrange equation is a second-order ODE with initial conditions $y(\\alpha)=y_1,y(\\beta)=y_2$.\\\\\r\n    2. Sometimes the LHS is denoted $\\delta F[y]/\\delta y(x)$ and is called the functional derivative.\r\n    Some author also write $\\epsilon\\eta=\\delta y$, allowing one to write $F[y+\\delta y]=F[y]+\\delta F[y]$ where\r\n    $$\\delta F[y]=\\int_\\alpha^\\beta\\frac{\\delta F[y]}{\\delta y(x)}\\delta y(x)\\,\\mathrm dx$$\r\n    3. Other kinds of boundary conditions (e.g. those on $y^\\prime$) are possible.\\\\\r\n    4. Be careful with derivatives as the notation can be a bit confusing.\r\n    The $x,y,y^\\prime$ are independent variables when we are talking about partial derivatives of $f(x,y,y^\\prime)$.\\\\\r\n    5. For any $h(x,y,y^\\prime)$, a somewhat useful formula is\r\n    $$\\frac{\\mathrm dh(x,y(x),y^\\prime(x))}{\\,\\mathrm dx}=\\frac{\\partial h}{\\partial x}+\\frac{\\partial h}{\\partial y}y^\\prime+\\frac{\\partial h}{\\partial y^\\prime}y^{\\prime\\prime}$$\r\n    For example, for $f(x,y,y^\\prime)=x((y^\\prime)^2-y^2)$, we have $\\mathrm df/\\mathrm dx=(y^\\prime)^2-y^2-2xyy^\\prime+2y^{\\prime\\prime}y^\\prime x$.\r\n\\end{remark}\r\n\\subsection{First Integrals of the Euler-Lagrange Equation}\r\nNow we move on to solve the Euler-Lagrange equations, which is a second order ODE.\r\nIn some special cases, this is a quite easy thing to do.\r\nIn particular, if $f$ does not explicitly depend on some of its variables, then we can simplify the equation to something that is easier to solve.\r\nThese simplifications are often in the form of something being constant.\r\nExpressions like these are called the first integrals of the equations.\r\nNot only are they tools we can use to solve the equation, we can also view them as a conserved quantity of something that is described by a variational problem.\r\nWe will discuss the former in this section.\r\nThe latter will be mentioned later, when we discuss Noether's Theorem.\\\\\r\nAssume that $f$ does not explicitly depend on $y$, then $\\partial f/\\partial y=0$, so the Euler-Lagrange equation can be rewritten as\r\n$$\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime}=0\\implies \\frac{\\partial f}{\\partial y^\\prime}=\\text{const.}$$\r\nwhich is a first order ODE.\r\n\\begin{example}[Geodesics on the Plane]\r\n    Consider the geodesics on the Euclidean plane.\r\n    We know that we want to extremise the functional\r\n    $$F[y]=\\int_\\alpha^\\beta\\sqrt{1+(y^\\prime)^2}\\,\\mathrm dx$$\r\n    In this case, the apparent $f$ does not depend on $y$, hence we can obtain the solution by just solving the first integral\r\n    $$\\frac{y^\\prime}{\\sqrt{1+(y^\\prime)^2}}=\\text{const.}$$\r\n    One can solve this to get $y=mx+c$ for some constants $m,c$, which is our familiar formulation of a straight line, the geodesics of the plane.\r\n\\end{example}\r\n\\begin{example}[Geodesics on a Sphere]\r\n    Consider the two-dimensional unit sphere $S^2$ in $\\mathbb R^3$.\r\n    Use the spherical polar coordinates\r\n    $$x=\\sin\\theta\\sin\\phi,y=\\sin\\theta\\cos\\phi,z=\\cos\\theta,\\theta\\in [0,2\\pi),\\theta\\in[0,\\pi)$$\r\n    The line element on $S^2$ inherited from $\\mathbb R^3$ then gives\r\n    $$\\mathrm ds^2=\\mathrm dx^2+\\mathrm dy^2+\\mathrm dz^2=\\mathrm d\\theta^2+\\sin^2\\theta\\,\\mathrm d\\phi^2$$\r\n    A path restricted on the sphere can then be parameterized in terms of $\\theta,\\phi$.\r\n    Suppose we parameterize the curve by $\\phi(\\theta)$, then the length functional is\r\n    $$F[\\phi]=\\int_{\\theta_1}^{\\theta_2}\\sqrt{1+(\\phi^\\prime)^2\\sin^2\\theta}\\,\\mathrm d\\theta$$\r\n    We observe that the integral inside does not depend on $\\phi$, so we can rewrite the equation to\r\n    $$\\frac{\\phi^\\prime\\sin^2\\theta}{\\sqrt{1+(\\phi^\\prime)^2\\sin^2\\theta}}=\\frac{\\partial f}{\\partial \\phi^\\prime}=\\text{const.}=K$$\r\n    Seperating the variables yields\r\n    $$(\\phi^\\prime)^2=\\frac{K^2}{\\sin^2\\theta(\\sin^2\\theta-K^2)}\\implies\\phi=\\pm\\int\\frac{K\\,\\mathrm d\\theta}{\\sin\\theta\\sqrt{\\sin^2\\theta-K^2}}$$\r\n    which shall produce two solutions, each going one way round.\r\n    To evaluate the integral, we do the substitution $u=\\cot\\theta$ which produces\r\n    $$\\pm\\frac{\\sqrt{1-K^2}}{K}\\cos(\\phi-\\phi_0)=\\cot\\theta$$\r\n    for a constant $\\phi_0$.\r\n    By considering the geometrical meaning of this equation, it then follows that $\\phi(\\theta)$ describes a great circle, i.e. a circle in $\\mathbb R^3$ which exists as the intersection of $S^2$ and a plane that goes through the origin.\r\n\\end{example}\r\nNow, consider for general case of $f(x,y,y^\\prime)$, we have\r\n\\begin{align*}\r\n    \\frac{\\mathrm d}{\\mathrm dx}\\left( f-y^\\prime\\frac{\\partial f}{\\partial y^\\prime} \\right)&=\\frac{\\partial f}{\\partial x}+\\frac{\\partial f}{\\partial y}y^\\prime+\\frac{\\partial f}{\\partial y^\\prime}y^{\\prime\\prime}-y^\\prime\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime}-y^{\\prime\\prime}\\frac{\\partial f}{\\partial y^\\prime}\\\\\r\n    &=y^\\prime\\left( \\frac{\\partial f}{\\partial y}-\\frac{\\mathrm d}{\\mathrm dx}\\frac{\\partial f}{\\partial y^\\prime} \\right)+\\frac{\\partial f}{\\partial x}\r\n    &=\\frac{\\partial f}{\\partial x}\r\n\\end{align*}\r\nIf $y$ satisfies the Euler-Lagrange Equation.\r\nSo if $f$ does not depend explicitly on $x$, then the above indicates that\r\n$$f-y^\\prime\\frac{\\partial f}{\\partial y^\\prime}=\\text{const.}$$\r\n\\begin{example}[The Brachistochrone Problem]\r\n    Consider the functional in the Brachistochrone Problem we defined before, with the initial point assumed to be the origin:\r\n    $$F[y]=\\frac{1}{\\sqrt{2g}}\\int_0^\\beta\\frac{\\sqrt{1+(y^\\prime)^2}}{\\sqrt{-y}}\\,\\mathrm dx$$\r\n    As $f$ in this case does not depend explicitly on $x$, we know that\r\n    $$\\frac{\\sqrt{1+(y^\\prime)^2}}{\\sqrt{-y}}-y^\\prime\\frac{y^\\prime}{\\sqrt{1+(y^\\prime)^2}\\sqrt{-y}}=\\text{const.}=K$$\r\n    So\r\n    $$y^\\prime=\\pm\\frac{\\sqrt{1+K^2y}}{K\\sqrt{-y}}\\implies x=\\pm K\\int\\frac{\\sqrt{-y}}{\\sqrt{1+K^2y}}\\,\\mathrm dy$$\r\n    Set $y=-K^{-2}\\sin^2(\\theta/2)$, so $\\mathrm dy=-K^{-2}\\sin(\\theta/2)\\cos(\\theta/2)$, so\r\n    \\begin{align*}\r\n        x&=\\pm K\\int(-1)\\frac{1}{K^3}\\frac{\\sin^2(\\theta/2)\\cos(\\theta/2)}{\\sqrt{1-\\sin^2(\\theta/2)}}\\,\\mathrm d\\theta\\\\\r\n        &=\\mp\\frac{1}{2K^2}\\int(1-\\cos\\theta)\\,\\mathrm d\\theta\\\\\r\n        &=\\mp\\frac{1}{2K^2}(\\theta-\\sin\\theta)+C\r\n    \\end{align*}\r\n    where $C$ is a constant.\r\n    By our initial condition, $\\theta(0)=0$, so $C=0$.\r\n    Substitute $\\theta$ for both $x,y$ and we get the parameterised equations\r\n    $$\\begin{cases}\r\n        x=(\\theta-\\sin\\theta)/(2K^2)\\\\\r\n        y=-K^{-2}\\sin^2(\\theta/2)\r\n    \\end{cases}$$\r\n    which is the equation of a cycloid, i.e. the path traversed by a fixed point on a wheel which rolls on the $x$-axis.\r\n    Hence, the Brachistochrone is a cycloid.\r\n\\end{example}\r\n\\subsection{Fermat's Principle}\r\nFermat's Principle postulates that light (or sound) travels along paths between two points that are stationary points of the time variation.\r\n\\footnote{In its original form, however, it said that light travels the path that requires the least time, which is not necessarily true in all cases.}\r\nSuppose the light way is described by $y=y(x)$, then the time functional is\r\n$$F[y]=\\int\\frac{\\mathrm dl}{c}=\\int_\\alpha^\\beta\\frac{\\sqrt{1+(y^\\prime)^2}}{c(x,y)}\\,\\mathrm dx$$\r\nwhere $c$ is the speed of light in the medium.\\\\\r\nFirst assume that $c=c(x)$ does not depend on $y$, then $f$ does not explicitly depend on $y$, in which case we have the first integral\r\n$$\\frac{y^\\prime}{\\sqrt{1+(y^\\prime)^2}c(x)}=\\frac{\\partial f}{\\partial y^\\prime}=\\text{const.}$$\r\nSuppose the light ray has an initial incident angle of $\\theta_1$ upwards, then $\\tan\\theta_1=y^\\prime(\\alpha)$.\r\nLet $\\tan\\theta=y^\\prime$ in general, then the above first integral indicates that $\\sin\\theta/c(x)$ is constant.\r\nThis is Snell's Law.\r\nIf $c$ is increasing, then the path is concave and if $c$ is decreasing it is convex.\r\nAlso, if the light goes through a barrier, to the left of which $c$ is constant at $c_F$ and to the right of which $c_S$ with $c_S<c_F$, then the light ray will refract in the way we all expect.", "meta": {"hexsha": "89155b149ec40769c10c652558358401108efe71", "size": 11422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/eleq.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": "2/eleq.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": "2/eleq.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.1466666667, "max_line_length": 344, "alphanum_fraction": 0.6693223604, "num_tokens": 3629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.6118426709411086}}
{"text": "\\documentclass{report}\n\n\\title{explain-math example}\n\\author{Matt Gleich}\n\\date{}\n\n\\makeindex\n\n\\usepackage{explain-math}\n\n\\begin{document}\n    \\maketitle\n\n    \\section{Basic Math Example}\n        \\begin{align*}\n            \\statement{-2(x + 2) = 6}\n            \\explain{Distribute out -2}{\n                \\step{ (-2 \\cdot x) + (-2 \\cdot 2) = 6 }\n                \\step{ -2x - 4 = 6 }\n            }\n            \\explain{Remove -4 from the left}{\n                \\step{ -2x - 4 + 4 = 6 + 4 }\n                \\step{ -2x = 10 }\n            }\n            \\explain{Remove -2 from the left}{\n                \\step{ \\frac{-2x}{-2} = \\frac{10}{-2} }\n                \\step{ \\frac{-2x}{-2} = \\frac{10}{-2} }\n                \\step{ x = -5 }\n            }\n            \\sol{x = -5}\n        \\end{align*}\n\n    \\section{Basic Physics Example}\n        \\begin{align*}\n            \\formula{p = mv}\n            \\variables{\n                \\varu{p}{\\text{?}}{kg $ \\frac{\\text{m}}{\\text{s}} $}\n                \\varu{m}{3.0}{k.g}\n                \\varu{v}{5.0}{m/s East}\n            }\n            \\explain{Plug \\& solve}{p = 3 \\cdot 5}\n            \\sol{p = 15 \\text{ kg} \\cdot \\frac{\\text{m}}{\\text{s}}}\n        \\end{align*}\n\\end{document}\n", "meta": {"hexsha": "3466efb99f9fd4498a999b3953e6ab26fdf9f2c8", "size": 1215, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example.tex", "max_stars_repo_name": "Matt-Gleich/explainmath", "max_stars_repo_head_hexsha": "96111ac6fed2603bdcd93d581e0e686f2e17195e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-06-14T09:51:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T23:34:54.000Z", "max_issues_repo_path": "example.tex", "max_issues_repo_name": "Matt-Gleich/explainmath", "max_issues_repo_head_hexsha": "96111ac6fed2603bdcd93d581e0e686f2e17195e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example.tex", "max_forks_repo_name": "Matt-Gleich/explainmath", "max_forks_repo_head_hexsha": "96111ac6fed2603bdcd93d581e0e686f2e17195e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-11T19:34:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T19:34:24.000Z", "avg_line_length": 27.0, "max_line_length": 68, "alphanum_fraction": 0.4139917695, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.6118426657574226}}
{"text": "\\section{Application: Cryptography}\n\nCryptography is about encoding a message so that it is hard for a\nthird party to read. The original message is called the\n\\textbf{plaintext}%\n\\index{plaintext}%\n\\index{cipher!plaintext} and the encrypted message is called the\n\\textbf{ciphertext}%\n\\index{ciphertext}%\n\\index{cipher!ciphertext}. The process of turning a plaintext into the\ncorresponding ciphertext is called \\textbf{encryption}%\n\\index{encryption}%\n\\index{cipher!encryption}, and the process of turning a ciphertext\ninto the corresponding plaintext is called \\textbf{decryption}%\n\\index{decryption}%\n\\index{cipher!decryption}. An encryption and decryption method is also\ncalled a \\textbf{cipher}%\n\\index{cipher}.  Modern ciphers are designed in such a way that the\ncipher itself is not secret, but the encryption depends on a secret\n\\textbf{key}%\n\\index{key!cryptography}%\n\\index{cipher!key}. A cipher should be designed so that decryption is\neasy for a person who knows the key, but difficult for everybody\nelse. The art of designing ciphers is called \\textbf{cryptography}%\n\\index{cryptography}, and the art of breaking ciphers is called\n\\textbf{cryptanalysis}%\n\\index{cryptanalysis}.\n\nIn order to be able to define ciphers using algebraic operations, we\nstart by encoding strings as sequences of numbers. To that end, we\nassign a number to each letter of the alphabet, as well as the special\nsymbols ``space'', ``comma'', and ``period'', according to the\nfollowing scheme.\n\\begin{center}\n  \\tabcolsep=2.5ex\n  \\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n    \\hline\n    Space & \\qq{A} & \\qq{B} & \\qq{C} & \\qq{D} & \\ldots & \\qq{Z} & Comma & Period \\\\\\hline\n    0 & 1 & 2 & 3 & 4 & \\ldots & 26 & 27 & 28 \\\\\\hline\n  \\end{tabular}\n\\end{center}\nIn practical applications, one would probably use a larger set of\nsymbols and a standard encoding such as ASCII or UTF-8. But the above\n29 symbols will be sufficient for our purposes. It will also come in\nhandy that 29 is prime.\n\n\\begin{example}{Representing strings as sequences of numbers}{string-encoding}\n  Convert the string ``Attack at dawn'' to a sequence of\n  numbers. Convert the sequence of numbers\n  $9,0,12,9,11,5,0,3,15,4,5,19,28$ to a string.\n\\end{example}\n\n\\begin{solution}\n  We have $\\qq{A}=1$, $\\qq{T}=20$, $\\qq{T}=20$, $\\qq{A}=1$, $\\qq{C}=3$,\n  $\\qq{K}=11$, $\\mbox{Space}=0$, and so on. Continuing in this way, the\n  encoding of ``Attack at dawn'' is\n  $1,20,20,1,3,11,0,1,20,0,4,1,23,14$.  Conversely, we have $9=\\qq{I}$,\n  $0=\\mbox{Space}$, $12=\\qq{L}$, $9=\\qq{I}$, $11=\\qq{K}$, $5=\\qq{E}$, and so\n  on. We find that the decoded string is ``I like codes.''\n\\end{solution}\n\nThere are many different ways to define ciphers. Some of the oldest\nknown ciphers date back thousands of years.  An example of such a\n``classic'' cipher is a \\textbf{substitution cipher}%\n\\index{substitution cipher}%\n\\index{cipher!substitution cipher}, where each letter of the alphabet\nis replaced by a different letter, for example $\\qq{A}\\mapsto\\qq{D}$,\n$\\qq{B}\\mapsto\\qq{E}$, and so on. Substitution ciphers have the property\nthat changing one letter of the plaintext always changes exactly one\nletter of the ciphertext. This is not a desirable property, because it\nmakes the cipher easy to break. Therefore, modern ciphers are designed\nto satisfy a property called \\textbf{diffusion}%\n\\index{diffusion}%\n\\index{cipher!diffusion}: changing one letter of the plaintext should\nchange many letters of the ciphertext.\n\nIn a \\textbf{block cipher}%\n\\index{block cipher}%\n\\index{cipher!block cipher}, the plaintext is first divided into\nblocks of equal size, and then each block is encrypted separately. The\n\\textbf{block size}%\n\\index{block size} is the number of plaintext symbols in each\nblock. If the length of the plaintext is not divisible by the block\nsize, we pad the final block with additional spaces. In the context of\na block cipher, the diffusion property means that changing one symbols\nof a plaintext block potentially affects every symbol of the\nciphertext block. The following is an example of a block cipher.\n\n\\begin{definition}{Hill cipher}{hill-cipher}\n  The \\textbf{Hill cipher}%\n  \\index{Hill cipher}%\n  \\index{cipher!Hill cipher} of block size $n$ has as its key an\n  invertible $n\\times n$-matrix $A$ with scalars from $\\Z_{29}$. Each\n  ciphertext block $c_1,\\ldots,c_n$ is computed from the corresponding\n  plaintext block $p_1,\\ldots,p_n$ by matrix multiplication modulo\n  $\\Z_{29}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{c}c_1\\\\\\vdots\\\\c_n\\end{mymatrix}\n    ~=~ A\\begin{mymatrix}{c}p_1\\\\\\vdots\\\\p_n\\end{mymatrix}.\n  \\end{equation*}\n  The matrix $A$ is called the \\textbf{encryption matrix}%\n  \\index{encryption matrix}%\n  \\index{matrix!encryption} of the cipher. It inverse $A^{-1}$ is\n  called the \\textbf{decryption matrix}%\n  \\index{decryption matrix}%\n  \\index{matrix!decryption}.\n\\end{definition}\n\n\\begin{example}{Hill cipher: encryption}{hill-cipher-encryption}\n  Encrypt the message ``Meet me tomorrow'' using the Hill cipher with\n  block size $3$ and encryption matrix\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{ccc}\n      2 & 4 & 1 \\\\\n      3 & 1 & 5 \\\\\n      1 & 3 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We start by converting the message ``Meet me tomorrow'' to a sequence\n  of scalars. We have $\\qq{M}=13$, $\\qq{E}=5$, and so on. The encoded\n  plaintext is $13,5,5,20,0,13,5,0,20,15,13,15,18,18,15,23$. Next, we\n  divide the plaintext into blocks of length 3. Since the length of\n  the plaintext is not a multiple of three, we pad the final block\n  with spaces, i.e., with zeros.\n  \\begin{equation*}\n    \\mbox{Plaintext blocks:}\\quad\n    (13,5,5),\\\n    (20,0,13),\\\n    (5,0,20),\\\n    (15,13,15),\\\n    (18,18,15),\\\n    (23,0,0).\n  \\end{equation*}\n  To compute the ciphertext, we regard each plaintext block as a\n  $3$-dimensional column vector and multiply by the encryption matrix\n  $A$. All calculations are done modulo $29$. For example, for the\n  first block, we have\n  \\begin{equation*}\n    A \\begin{mymatrix}{c} 13 \\\\ 5 \\\\ 5 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{ccc}\n      2 & 4 & 1 \\\\\n      3 & 1 & 5 \\\\\n      1 & 3 & 2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} 13 \\\\ 5 \\\\ 5 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{c} 22 \\\\ 11 \\\\ 9 \\end{mymatrix},\n  \\end{equation*}\n  so the first ciphertext block is $(22,11,9)$. We repeat the same\n  with the remaining plaintext blocks.\n  \\begin{align*}\n    &A \\begin{mymatrix}{c} 20 \\\\ 0 \\\\ 13 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 24 \\\\ 9 \\\\ 17 \\end{mymatrix},\n    \\quad\n    A \\begin{mymatrix}{c} 5 \\\\ 0 \\\\ 20 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 28 \\\\ 16 \\end{mymatrix},\n    \\quad\n    A \\begin{mymatrix}{c} 15 \\\\ 13 \\\\ 15 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 10 \\\\ 17 \\\\ 26 \\end{mymatrix},\n    \\\\\\\\[-2ex]\n    &A \\begin{mymatrix}{c} 18 \\\\ 18 \\\\ 15 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 7 \\\\ 2 \\\\ 15 \\end{mymatrix},\n    \\quad\n    A \\begin{mymatrix}{c} 23 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 17 \\\\ 11 \\\\ 23 \\end{mymatrix}.\n  \\end{align*}\n  Therefore, we have found the following ciphertext blocks:\n  \\begin{equation*}\n    \\mbox{Ciphertext blocks:}\\quad\n    (22,11,9),\\\n    (24,9,17),\\\n    (1,28,16),\\\n    (10,17,26),\\\n    (7,2,15),\\\n    (17,11,23).\n  \\end{equation*}\n  Finally, we can convert the ciphertext to a list of symbols:\n  $\\q{VKIXIQA.PJQZGBOQKW}$.\n\\end{solution}\n\n\\begin{example}{Hill cipher: decryption}{hill-cipher-decryption}\n  Decrypt the message $\\q{RNOLFPHHCIGH DE}$ using the Hill cipher with\n  block size $3$ and encryption matrix\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{ccc}\n      2 & 4 & 1 \\\\\n      3 & 1 & 5 \\\\\n      1 & 3 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The process is analogous to encryption, except that we need to use\n  the decryption matrix $A^{-1}$ instead of $A$. We first calculate\n  $A^{-1}$, keeping in mind that scalars are from the field $\\Z_{29}$.\n  The method is the same as in Example~\\ref{exa:matrix-inverse-z7}; we\n  skip the individual steps in the interest of brevity.\n  \\begin{equation*}\n    \\mat{A\\mid I}\n    ~=~\n    \\begin{mymatrix}{ccc|ccc}\n      2 & 4 & 1  &  1 & 0 & 0 \\\\\n      3 & 1 & 5  &  0 & 1 & 0 \\\\\n      1 & 3 & 2  &  0 & 0 & 1 \\\\\n    \\end{mymatrix}\n    ~\\roweq~\\ldots~\\roweq~\n    \\begin{mymatrix}{ccc|ccc}\n      1 & 0 & 0  &  23 & 20 & 11 \\\\\n      0 & 1 & 0  &   4 & 17 & 28 \\\\\n      0 & 0 & 1  &  26 &  8 & 11 \\\\\n    \\end{mymatrix}\n    ~=~\n    \\mat{I\\mid A^{-1}}.\n  \\end{equation*}\n  Next, we convert the 15 ciphertext symbols $\\q{RNOLFPHHCIGH DE}$ to\n  scalars and divide them into blocks of length 3:\n  \\begin{equation*}\n    \\mbox{Ciphertext blocks:}\\quad\n    (18,14,15),\\\n    (12,6,16),\\\n    (8,8,3),\\\n    (9,7,8),\\\n    (0,4,5).\n  \\end{equation*}\n  Now we decrypt each ciphertext block by a matrix multiplication\n  with $A^{-1}$.\n  \\begin{align*}\n    &A^{-1} \\begin{mymatrix}{c} 18 \\\\ 14 \\\\ 15 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 18 \\\\ 5 \\\\ 20 \\end{mymatrix},\n    \\quad\n    A^{-1} \\begin{mymatrix}{c} 12 \\\\ 6 \\\\ 16 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 21 \\\\ 18 \\\\ 14 \\end{mymatrix},\n    \\quad\n    A^{-1} \\begin{mymatrix}{c} 8 \\\\ 8 \\\\ 3 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 20 \\\\ 15 \\end{mymatrix},\n    \\\\\\\\[-2ex]\n    &A^{-1} \\begin{mymatrix}{c} 9 \\\\ 7 \\\\ 8 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 2 \\\\ 1 \\end{mymatrix},\n    \\quad\n    A^{-1} \\begin{mymatrix}{c} 0 \\\\ 4 \\\\ 5 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 19 \\\\ 5 \\\\ 0 \\end{mymatrix}.\n  \\end{align*}\n  This yields the following plaintext blocks:\n    \\begin{equation*}\n    \\mbox{Plaintext blocks:}\\quad\n    (18,5,20),\\\n    (21,18,14),\\\n    (0,20,15),\\\n    (0,2,1),\\\n    (19,5,0).\n  \\end{equation*}\n  Converting these back to letters, and omitting the trailing space,\n  we find that the plaintext is ``return to base''.\n\\end{solution}\n\nIt is important to note that, despite its good diffusion properties,\nthe Hill cipher is not secure. The cipher has many weaknesses. For\none, because $A\\vect{0}=\\vect{0}$, a block of spaces in the plaintext\nwill always be encrypted as a block of spaces in the ciphertext,\nregardless of the encryption matrix $A$. More importantly, the cipher\nis subject to a so-called \\textbf{known plaintext attack}%\n\\index{known plaintext attack}%\n\\index{cipher!known plaintext attack}.  If an eavesdropper intercepts\nsome ciphertext for which a small amount of the corresponding\nplaintext happens to be known, it is immediately possible to recover\nthe key and therefore decrypt the rest of the ciphertext. Carrying out\nthis attack only requires some basic knowledge of linear algebra. The\nfollowing example illustrates how this is done.\n\n\\begin{example}{Cryptanalysis of the Hill cipher: known plaintext attack}{hill-cipher-cryptanalysis}\n  Eve intercepts the following encrypted message sent by Alice:%\n  \\index{cryptanalysis}\n  \\begin{center}\n    \\q{EFNOR.AHIFNEPL.TSZS,RSKT.ZBBRFVUPFVZLFHNTV}.\n  \\end{center}\n  Eve knows that Alice uses a Hill cipher with block length 3, but she\n  does not know the secret encryption matrix. Eve also knows that\n  Alice begins all of her correspondence with ``My dear\n  love''. Decrypt the message.\n\\end{example}\n\n\\begin{solution}\n  The first three blocks of the ciphertext are $\\q{EFNOR.AHI}$, i.e.,\n  \\begin{equation*}\n    \\mbox{Ciphertext blocks:}\\quad\n    (5,6,14),\\\n    (15,18,28),\\\n    (1,8,9).\n  \\end{equation*}\n  Eve also knows that the first three blocks of the plaintext are\n  $\\q{MY DEAR L}$, i.e.,\n  \\begin{equation*}\n    \\mbox{Plaintext blocks:}\\quad\n    (13,25,0),\\\n    (4,5,1),\\\n    (18,0,12).\n  \\end{equation*}\n  These facts allow Eve to deduce the following information about the\n  unknown decryption matrix $A^{-1}$:\n  \\begin{equation*}\n    A^{-1} \\begin{mymatrix}{c} 5 \\\\ 6 \\\\ 14 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 13 \\\\ 25 \\\\ 0 \\end{mymatrix},\\quad\n    A^{-1} \\begin{mymatrix}{c} 15 \\\\ 18 \\\\ 28 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 4 \\\\ 5 \\\\ 1 \\end{mymatrix},\\quad\n    A^{-1} \\begin{mymatrix}{c} 1 \\\\ 8 \\\\ 9 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 18 \\\\ 0 \\\\ 12 \\end{mymatrix}.\n  \\end{equation*}\n  Since Eve remembers the column method of matrix multiplication, she\n  knows that these three equations can be written as a single equation\n  in matrix form:\n  \\begin{equation*}\n    A^{-1} \\begin{mymatrix}{ccc}\n      5 & 15 & 1 \\\\\n      6 & 18 & 8 \\\\\n      14 & 28 & 9 \\\\\n    \\end{mymatrix}\n    = \\begin{mymatrix}{ccc}\n      13 & 4 & 18 \\\\\n      25 & 5 & 0 \\\\\n      0 & 1 & 12 \\\\\n    \\end{mymatrix}.\\quad\n  \\end{equation*}\n  Note that this equation is of the form $A^{-1}C=P$. (Here, $C$\n  stands for ``ciphertext'' and $P$ for ``plaintext''). Multiplying\n  both sides of the equation by $C^{-1}$ on the right, we get\n  $A^{-1} = PC^{-1}$. Thus, assuming that $C$ is invertible, Eve can\n  easily compute the decryption matrix $A^{-1}$. Eve computes:\n  \\begin{equation*}\n    C^{-1}\n    =\n    \\begin{mymatrix}{ccc}\n      5 & 15 & 1 \\\\\n      6 & 18 & 8 \\\\\n      14 & 28 & 9 \\\\\n    \\end{mymatrix}^{-1}\n    =\n    \\begin{mymatrix}{ccc}\n      19 & 8 & 23 \\\\\n      0 & 5 & 2 \\\\\n      22 & 1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  This allows Eve to compute the decryption matrix:\n  \\begin{equation*}\n    A^{-1}\n    =\n    PC^{-1}\n    =\n    \\begin{mymatrix}{ccc}\n      13 & 4 & 18 \\\\\n      25 & 5 & 0 \\\\\n      0 & 1 & 12 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{ccc}\n      19 & 8 & 23 \\\\\n      0 & 5 & 2 \\\\\n      22 & 1 & 0 \\\\\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{ccc}\n      5  & 26 & 17 \\\\\n      11 & 22 & 5 \\\\\n      3  & 17 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Armed with the decryption matrix $A^{-1}$, Eve can now decrypt\n  Alice's entire message, using the same method as in\n  Example~\\ref{exa:hill-cipher-decryption}. The plaintext is ``My dear\n  love, run away with me at midnight''.\n\\end{solution}\n\nAs the example shows, the Hill cipher is not secure at all. The main\nproblem is that the cipher is {\\em linear}, i.e., each component of a\nciphertext block is a simple linear combination of the components of\nthe plaintext block. This linearity property enables Eve to break the\ncipher by solving a system of linear equations.\n\nFor this reason, all modern block ciphers have a non-linear\ncomponent. Often this takes the form of so-called \\textbf{S-boxes}%\n\\index{S-box}%\n\\index{cipher!S-box}. An S-box is an operation that scrambles the\nsymbols of the alphabet in a non-linear way.  For example, consider\nthe following S-box, which is an operation from $\\Z_{29}$ to\n$\\Z_{29}$:\n\\begin{center}\n  \\tabcolsep=0.4ex\\def\\arraystretch{1.4}\n  \\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\n    \\hline\n    $x$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 \\\\\\hline\n    ~$S(x)$~ & 17 & 9 & 27 & 2 & 20 & 12 & 21 & 26 & 16 & 18 & 4 & 24 & 23 & 7 & 19 & 14 & 28 & 29 & 1 & 15 & 10 & 22 & 6 & 5 & 25 & 11 & 13 & 3 & 8 \\\\\\hline\n  \\end{tabular}\n\\end{center}\nThe inputs of the S-box are shown in the top row, and the\ncorresponding outputs in the bottom row.  For example, this S-box maps\nthe input $7$ to the output $26$. We write $S(7)=26$.\n\n\\begin{definition}{A toy block cipher}{toy-block-cipher}\n  Consider the following block cipher on the alphabet $\\Z_{29}$ with\n  block size $3$. The key consists of $12$ elements $k_1,\\ldots,k_{12}$\n  of $\\Z_{29}$. To encrypt a plaintext block, regard the block as a\n  $3$-dimensional column vector. Then repeat the following steps $3$\n  times. All operations are carried out modulo $29$.\n  \\begin{itemize}\n  \\item Key mixing: add the next three components of the key to the\n    components of the vector.\n  \\item Diffusion: multiply the vector by the fixed $3\\times 3$-matrix\n    $A = \\begin{mymatrix}{ccc}\n      1 & 2 & 3 \\\\\n      3 & 1 & 2 \\\\\n      2 & 3 & 1 \\\\\n    \\end{mymatrix}$.\n  \\item S-box application: apply the S-box to each component of the\n    vector.\n  \\end{itemize}\n  Finally, apply one more key mixing step at the end. The resulting\n  vector is the ciphertext block. The cipher can be visualized as\n  follows:\n  \\begin{equation*}\n    \\begin{tikzpicture}[xscale=1.1,\n      a/.style={fill=red!20},\n      s/.style={fill=yellow!30},\n      k/.style={fill=green!20}]\n      \\draw (0,2) -- (11,2);\n      \\draw (0,1) node[left=2ex]{plaintext} -- (11,1) node[right=2ex]{ciphertext};\n      \\draw (0,0) -- (11,0);\n      \\draw[k] (1,2) +(-0.35,-0.35) rectangle node{$k_1$} +(0.35,0.35);\n      \\draw[k] (1,1) +(-0.35,-0.35) rectangle node{$k_2$} +(0.35,0.35);\n      \\draw[k] (1,0) +(-0.35,-0.35) rectangle node{$k_3$} +(0.35,0.35);\n      \\draw[a] (2,0) +(-0.35,-0.35) rectangle node{$A$} +(0.35,2.35);\n      \\draw[s] (3,2) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (3,1) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (3,0) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[k] (4,2) +(-0.35,-0.35) rectangle node{$k_4$} +(0.35,0.35);\n      \\draw[k] (4,1) +(-0.35,-0.35) rectangle node{$k_5$} +(0.35,0.35);\n      \\draw[k] (4,0) +(-0.35,-0.35) rectangle node{$k_6$} +(0.35,0.35);\n      \\draw[a] (5,0) +(-0.35,-0.35) rectangle node{$A$} +(0.35,2.35);\n      \\draw[s] (6,2) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (6,1) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (6,0) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[k] (7,2) +(-0.35,-0.35) rectangle node{$k_7$} +(0.35,0.35);\n      \\draw[k] (7,1) +(-0.35,-0.35) rectangle node{$k_8$} +(0.35,0.35);\n      \\draw[k] (7,0) +(-0.35,-0.35) rectangle node{$k_9$} +(0.35,0.35);\n      \\draw[a] (8,0) +(-0.35,-0.35) rectangle node{$A$} +(0.35,2.35);\n      \\draw[s] (9,2) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (9,1) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[s] (9,0) +(-0.35,-0.35) rectangle node{$S$} +(0.35,0.35);\n      \\draw[k] (10,2) +(-0.35,-0.35) rectangle node{$k_{10}$} +(0.35,0.35);\n      \\draw[k] (10,1) +(-0.35,-0.35) rectangle node{$k_{11}$} +(0.35,0.35);\n      \\draw[k] (10,0) +(-0.35,-0.35) rectangle node{$k_{12}$} +(0.35,0.35);\n  \\end{tikzpicture}\n\\end{equation*}\n\\end{definition}\n\nNote that the three basic steps (key mixing, diffusion, and S-box\napplication) are repeated several times; each such repetition is\ncalled a \\textbf{round}%\n\\index{cipher!round}%\n\\index{rounds of a cipher} of the block cipher.  The more rounds a\nblock cipher has, the better its diffusion and non-linearity\nproperties. The final round is short: it only consists of a key\nmixing step, with no final diffusion or S-box application. The reason\nis that performing a final diffusion and S-box application would not\nadd anything to the security of the cipher. An attacker could simply\nundo these last two steps, since they do not depend on the key.\n\nThe matrix $A$ is called the \\textbf{diffusion matrix}%\n\\index{diffusion matrix}%\n\\index{matrix!diffusion}%\n\\index{cipher!diffusion matrix} of the cipher. Note that, unlike for\nthe Hill cipher, the matrix $A$ is fixed once and for all and is not\npart of the key. Instead, the key consists of scalars that are added\nto the current block at the beginning of each round.\n\n\\begin{example}{Toy block cipher: encryption}{toy-block-cipher-encryption}\n  Encrypt the message ``I like math'' using the block cipher of\n  Definition~\\ref{def:toy-block-cipher} and the key\n  $1,1,3,3,5,5,7,7,9,9,11,11$.\n\\end{example}\n\n\\begin{solution}\n  We first represent the plaintext as a sequence of blocks, padding\n  the final block with zeros:\n  \\begin{equation*}\n    \\mbox{Plaintext blocks:}\\quad\n    (9,0,12),\\\n    (9,11,5),\\\n    (0,13,1),\\\n    (20,8,0).\n  \\end{equation*}\n  To encrypt the first block, we start with the vector\n  $\\mat{9,0,12}^T$ and apply the following steps:\n\n  \\noindent{\\bf Round 1:}\n  \\begin{itemize}\n  \\item Key mixing: the first three components of the key are\n    $1,1,3$. We add them to the plaintext.\n    \\begin{equation*}\n      \\begin{mymatrix}{c} 9 \\\\ 0 \\\\ 12 \\end{mymatrix}\n      +\n      \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 3 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 10 \\\\ 1 \\\\ 15 \\end{mymatrix}.\n    \\end{equation*}\n  \\item Diffusion: multiply by the matrix $A$.\n    \\begin{equation*}\n      \\begin{mymatrix}{ccc}\n        1 & 2 & 3 \\\\\n        3 & 1 & 2 \\\\\n        2 & 3 & 1 \\\\\n      \\end{mymatrix}\n      \\begin{mymatrix}{c} 10 \\\\ 1 \\\\ 15 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 28 \\\\ 3 \\\\ 9 \\end{mymatrix}.\n    \\end{equation*}\n  \\item S-box application: apply the S-box to each component of the\n    vector.\n    \\begin{equation*}\n      \\begin{mymatrix}{c} S(28) \\\\ S(3) \\\\ S(9) \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 8 \\\\ 2 \\\\ 18 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\noindent{\\bf Round 2:}\n  \\begin{itemize}\n  \\item Key mixing: the next three components of the key are\n    $3,5,5$.\n    \\begin{equation*}\n      \\begin{mymatrix}{c} 8 \\\\ 2 \\\\ 18 \\end{mymatrix}\n      +\n      \\begin{mymatrix}{c} 3 \\\\ 5 \\\\ 5 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 11 \\\\ 7 \\\\ 23 \\end{mymatrix}.\n    \\end{equation*}\n  \\item Diffusion:\n    \\begin{equation*}\n      \\begin{mymatrix}{ccc}\n        1 & 2 & 3 \\\\\n        3 & 1 & 2 \\\\\n        2 & 3 & 1 \\\\\n      \\end{mymatrix}\n      \\begin{mymatrix}{c} 11 \\\\ 7 \\\\ 23 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 7 \\\\ 28 \\\\ 8 \\end{mymatrix}.\n    \\end{equation*}\n  \\item S-box application:\n    \\begin{equation*}\n      \\begin{mymatrix}{c} S(7) \\\\ S(28) \\\\ S(8) \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 26 \\\\ 8 \\\\ 16 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\noindent{\\bf Round 3:}\n  \\begin{itemize}\n  \\item Key mixing: the next three components of the key are\n    $7,7,9$.\n    \\begin{equation*}\n      \\begin{mymatrix}{c} 26 \\\\ 8 \\\\ 16 \\end{mymatrix}\n      +\n      \\begin{mymatrix}{c} 7 \\\\ 7 \\\\ 9 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 4 \\\\ 15 \\\\ 25 \\end{mymatrix}.\n    \\end{equation*}\n  \\item Diffusion:\n    \\begin{equation*}\n      \\begin{mymatrix}{ccc}\n        1 & 2 & 3 \\\\\n        3 & 1 & 2 \\\\\n        2 & 3 & 1 \\\\\n      \\end{mymatrix}\n      \\begin{mymatrix}{c} 4 \\\\ 15 \\\\ 25 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 22 \\\\ 19 \\\\ 20 \\end{mymatrix}.\n    \\end{equation*}\n  \\item S-box application:\n    \\begin{equation*}\n      \\begin{mymatrix}{c} S(22) \\\\ S(19) \\\\ S(20) \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 6 \\\\ 15 \\\\ 10 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n\n  \\noindent{\\bf Round 4 (the final round is abbreviated):}\n  \\begin{itemize}\n  \\item Key mixing: the next three components of the key are\n    $9,11,11$.\n    \\begin{equation*}\n      \\begin{mymatrix}{c} 6 \\\\ 15 \\\\ 10 \\end{mymatrix}\n      +\n      \\begin{mymatrix}{c} 9 \\\\ 11 \\\\ 11 \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{c} 15 \\\\ 26 \\\\ 21 \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n  Therefore, the first ciphertext block is $(15,26,21)$. We repeat the\n  same procedure with the remaining plaintext blocks, and obtain the\n  following ciphertext blocks:\n  \\begin{equation*}\n    \\mbox{Ciphertext blocks:}\\quad\n    (15,26,21),\\\n    (7,24,1),\\\n    (2,16,23),\\\n    (7,20,22).\n  \\end{equation*}\n  The corresponding ciphertext is $\\q{OZUGXABPWGTV}$.\n\\end{solution}\n\nAre ciphers like this actually used in the real world? The answer\nis yes. While the cipher of Definition~\\ref{def:toy-block-cipher} is\ngreatly simplified, it has the same basic structure as modern\nreal-world block ciphers (such as AES, the Advanced Encryption\nStandard). Naturally, these real-world ciphers differ in some details,\nsuch as the alphabet size, the block size, the number of rounds, the\ndesign of the S-boxes, the way the key is computed, and the precise\norder in which the operations are applied. However, their basic\nstructure is very similar to our toy cipher, and indeed, all such\nciphers rely on key mixing, diffusion, and non-linear S-boxes as\ntheir key components.\n\nFor example, AES uses an alphabet size of $256$ instead of $29$ (i.e.,\nit operates on bytes%\n\\index{byte}, rather than elements of $\\Z_{29}$). Although $\\Z_{256}$\nis not a field (because $256$ is not prime), it nevertheless turns out\nthat there exists a field with $256$ elements, and AES uses it for its\nalgebraic operations. Our toy cipher's block size of $3$ is much too\nsmall to achieve effective diffusion; modern real-world ciphers use\nblock sizes between $16$ and $32$ bytes ($128$ to $256$ bits). The\ndesign of the S-boxes is a bit of a black art; at minimum, they must\nbe designed to withstand two common types of cryptanalysis known as\n\\textbf{linear cryptanalysis}%\n\\index{cryptanalysis!linear}%\n\\index{linear cryptanalysis} and \\textbf{differential cryptanalysis}%\n\\index{cryptanalysis!differential}%\n\\index{differential cryptanalysis}.  Among other things, this means\nthat the S-box should be ``as far from linear'' as possible.\n\nA detailed discussion of the design and cryptanalysis of modern block\nciphers is far beyond the scope of this book, but we hope that you\nhave gotten a taste of this fascinating subject, and the role that\nlinear algebra over finite fields plays in it.\n", "meta": {"hexsha": "ef70828726b7e0f72c20c5730534a6baefb5b71d", "size": 25049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Application-Cryptography.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-Application-Cryptography.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-Application-Cryptography.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.8356589147, "max_line_length": 157, "alphanum_fraction": 0.6393468801, "num_tokens": 8816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195327172402, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6117598655510492}}
{"text": "\\section{Classifying spaces: the Grassmann model}\\label{grassmannmodel}\nWe will now shift our focus somewhat and talk about classifying spaces for\nprincipal bundles and for vector bundles. We will do this in two ways: the\nfirst will be via the Grassmann model and the second via simplicial methods.\n\\begin{lemma}\\label{embedding}\n    Over a compact Hausdorff space, any $n$-plane bundle embeds in a trivial\n    bundle.\n\\end{lemma}\n\\begin{proof}\n    Let $\\cU$ be a trivializing open cover of the base $B$; since $B$ is\n    compact, we may assume that $\\cU$ is finite with $k$ elements. There is no\n    issue with numerability, so there is a subordinate partition of unity $\\phi_i$.\n    Consider an $n$-plane bundle $E\\to B$. By trivialization, there is a\n    fiberwise isomorphism $p^{-1}(U_i)\\xrightarrow{f_i}\\RR^n$ where the $U_i\\in\n    \\cU$. A map to a trivial bundle is the same thing as a bundle map in the\n    following diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    E\\ar[r]\\ar[d] & \\RR^N\\ar[d]\\\\\n\t    B\\ar[r] & \\ast\n\t    }\n    \\end{equation*}\n    We therefore define $E\\to (\\RR^n)^k$ via\n    $$e\\mapsto (\\phi_i(p(e))f_i(e))_{i=1,\\cdots,k}.$$\n    This is a fiberwise linear embedding, generally called a ``Gauss map''.\n    Indeed, observe that this map has no kernel on every fiber, so it is an\n    embedding.\n\\end{proof}\nThe trivial bundle has a metric on it, so choosing the orthogonal complement of\nthe embedding of Lemma \\ref{embedding}, we obtain:\n\\begin{corollary}\n    Over a compact Hausdorff space, any $n$-plane bundle has a complement (i.e.\n    a $\\xi^\\perp$ such that $\\xi\\oplus\\xi^\\perp$ is trivial).\n\\end{corollary}\nAnother way to say this is that if $B$ is a compact Hausdorff space with an\n$n$-plane bundle $\\xi$, there is a map $f:X\\to\\Gra_n(\\RR^{kn})$; this is\nexactly the Gauss map. It has the property that taking the pullback\n$f^\\ast\\gamma^n$ of the tautologous bundle over $\\Gra_n(\\RR^{kn})$ gives back\n$\\xi$. \n\nIn general, we do not have control over the number $k$. There is an easy fix to\nthis problem: consider the tautologous bundle $\\gamma^n$ over\n$\\Gra_n(\\RR^\\infty)$, defined as the union of $\\Gra_n(\\RR^m)$ and given the\nlimit topology. This is a CW-complex of finite type (i.e. finitely many cells\nin each dimension). Note that $\\Gra_n(\\RR^m)$ are not the $m$-skeleta of\n$\\Gra_n(\\RR^\\infty)$!\n\nThe space $\\Gra_n(\\RR^\\infty)$ is ``more universal'':\n\\begin{lemma}\\label{universal}\n    Any (numerable) $n$-plane bundle is pulled back from $\\gamma^n\\downarrow\n    \\Gra_n(\\RR^\\infty)$ via the Gauss map.\n\\end{lemma}\nLemma \\ref{universal} is a little bit tricky, since the covering can be wildly\nuncountable; but this is remedied by the following bit of point-set topology.\n\\begin{lemma}\\label{sublemma}\n    Let $\\cU$ be a numerable cover of $X$. Then there's another numerable cover\n    $\\cU^\\prime$ such that:\n    \\begin{enumerate}\n\t\\item the number of open sets in $\\cU^\\prime$ is countable, and\n\t\\item each element of $\\cU^\\prime$ is a disjoint union of elements of\n\t    $\\cU$.\n    \\end{enumerate}\n\\end{lemma}\nIf $\\cU$ is a trivializing cover, then $\\cU^\\prime$ is also a trivializing\ncover.\n\\begin{proof}\n    See \\cite[Proposition 3.5.4]{husemoller}.\n\\end{proof}\nIt is now an exercise to deduce Lemma \\ref{universal}. The main result of this\nsection is the following.\n\\begin{theorem}\n    The map $[X,\\Gra_n(\\RR^\\infty)]\\to \\Vect_n(X)$ defined by $[f]\\mapsto\n    [f^\\ast\\gamma^n]$ is bijective, where $[f]$ is the homotopy class of $f$\n    and $[f^\\ast\\gamma^n]$ is the isomorphism class of the bundle\n    $f^\\ast\\gamma^n$.\n\\end{theorem}\nThis is why $\\Gra_n(\\RR^\\infty)$ is also called the \\emph{classifying space}\nfor $n$-plane bundles. The Grassmannian provides a very explicit geometric\ndescription for the classifying space of $n$-plane bundles. There is a more\nabstract way to produce a classifying space for principal $G$-bundles, which\nwe will describe in the next section; the Grassmannian is the special case when\n$G = \\GL_n(\\RR)$.\n\\begin{proof}\n    We have already shown surjectivity, so it remains to prove injectivity.\n    Suppose $f_0,f_1:X\\to \\Gra_n(\\RR^\\infty)$ such that $f_0^\\ast\\gamma^n$ and\n    $f_1^\\ast\\gamma^n$ are isomorphic over $X$. We need to construct a homotopy\n    $f_0\\simeq f_1$. For ease of notation, let us identify $f_0^\\ast\\gamma^n$\n    and $f_1^\\ast\\gamma_n$ with each other; call it $\\xi:E\\downarrow X$.\n\n    The maps $f_i$ are the same thing as Gauss maps $g_i:E\\to\\RR^\\infty$, i.e.,\n    maps which are fiberwise linear embeddings. The homotopy $f_0\\simeq f_1$ is\n    created by saying that we have a homotopy from $g_0$ to $g_1$ through Gauss\n    maps, i.e., through other fiberwise linear embeddings.\n    \n    In fact, we will prove a much stronger statement: \\emph{any two} Gauss maps\n    $g_0,g_1:E\\to \\RR^\\infty$ are homotopic through Gauss maps. This is very far from\n    true if I didn't have a $\\RR^\\infty$ on the RHS there.\n\n    Let us attempt (and fail!) to construct an affine homotopy between $g_0$\n    and $g_1$. Consider the map $tg_0 + (1-t)g_1$ for $0\\leq t\\leq 1$. In order\n    for these maps to define a homotopy via Gauss maps, we need the following\n    statement to be true: for all $t$, if $tg_0(v) + (1-t)g_1(v) =\n    0\\in\\RR^\\infty$, then $v=0$.  In other words, we need $tg_0+(1-t)g_1$ to be\n    injective. Of course, this is not guaranteed from the injectivity of $g_0$\n    and $g_1$!\n\n    Instead, we will construct a composite of affine homotopies between $g_0$\n    and $g_1$ using the fact that $\\RR^\\infty$ is an infinite-dimensional\n    Euclidean space. Consider the following two linear isometries:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    & \\RR^\\infty = \\langle\n\t    e_0,e_1,\\cdots\\rangle\\ar[dl]^\\alpha_{e_i\\mapsto\n\t    e_{2i}}\\ar[dr]_\\beta^{e_i\\mapsto e_{2i+1}} & \\\\\n\t    \\RR^\\infty & & \\RR^\\infty\n\t    }\n    \\end{equation*}\n    Then, we have four Gauss maps: $g_0$, $\\alpha\\circ g_0$, $\\beta\\circ g_1$,\n    and $g_1$. There are affine homotopies through Gauss maps:\n    $$g_0\\simeq \\alpha \\circ g_0\\simeq \\beta\\circ g_1\\simeq g_1.$$\n    We will only show that there is an affine homotopy through Gauss maps $g_0\n    \\simeq \\alpha \\circ g_0$; the others are left as an exercise. Let $t$ and\n    $v$ be such that $tg_0(v) + (1-t)\\alpha g_0(v) = 0$. Since $g_0$ and\n    $\\alpha g_0$ are Gauss maps, we may suppose that $0<t<1$. Since $\\alpha\n    g_0(v)_i$ has only even coordinates, it follows by definition of the map\n    $\\alpha$ that $g_0(v)$ only had nonzero coordinates only in dimensions\n    congruent to $0$ mod $4$. Repeating this argument proves the desired\n    result.\n\\end{proof}\n", "meta": {"hexsha": "39c334ec96242b7f7cf65b47e16429a8556f316a", "size": 6593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-55-grassmann-model-classifying-spaces.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-55-grassmann-model-classifying-spaces.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-55-grassmann-model-classifying-spaces.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.7153846154, "max_line_length": 85, "alphanum_fraction": 0.6931594115, "num_tokens": 2120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737473266735, "lm_q2_score": 0.8962513786759491, "lm_q1q2_score": 0.6117576620895401}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[legalpaper, portrait, margin=1in]{geometry}\n\n\\title{2016 ISI Calculus Problem}\n\n\\author{Shreenabh Agrawal}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\nLet $f$ be a differentiable function such that $f(f((x))=x \\text { for all } x \\in[0,1]$ Suppose $f(0)=1 .$ Determine the value of $\\int\\limits_{0}^{1}(x-f(x))^{2016} \\: d x$\n\\section{Solution}\n$$f(f(x))=x \\implies\n  f(x)=f^{-1}(x)$$\nThe graph of this is symmetric about $y=x$,\n$$\\therefore f(0) = 1 \\implies f(1) = 0$$\nNow, let us solve the integral (call it (i))\n$${I}=\\int\\limits_{0}^{1}(x-f(x))^{2016}\\:  d x$$\nTaking substitution,\n$$\\begin{aligned}\nf(x) &=t \\\\\nx &=f^{-1}(t)=f(t) \\\\\nd x &=f^{\\prime}(t) \\: d t\n\\end{aligned}$$\nPlugging this in (call this (ii)),\n$$\\begin{aligned}\n\\therefore \\quad I &=\\int\\limits_{1}^{0}(f(t)-t)^{2016} f^{\\prime}(t)\\: d t \\\\\n&=-\\int\\limits_{0}^{1}(t-f(t))^{2016} f^{\\prime}(t) \\:d t\n\\end{aligned}$$\nNow adding (i) and (ii),\n$$2 I=\\int\\limits_{0}^{1}(x-f(x))^{2016}\\left(1-f^{\\prime}(x)\\right) \\: d x$$\nTaking another substitution,\n$$\\begin{aligned}\n(x - f(x)) &= u\\\\\n(1 - f^{\\prime}(x)) \\: dx &= \\: du\n\\end{aligned}\n$$\nFinally,\n$$\\begin{aligned}\n\\therefore \\quad 2 I  & =  \\int\\limits_{-1}^{1}  u^{2016}\\: d u \\\\\n 2 I &=  2 \\cdot\\left[\\frac{u^{2017}}{2017}\\right]_{0}^{1}\n\\end{aligned}$$\nThus, the value of our original integral is:\n$$\\boxed{I = \\frac{1}{2017}}$$\n\\end{document}\n", "meta": {"hexsha": "3c41cc16061312181bec8eb5c845e2d4ff8f97f8", "size": 1495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Creative Math Solving's Problems/2016 ISI Calculus Problem.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/Creative Math Solving's Problems/2016 ISI Calculus Problem.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/Creative Math Solving's Problems/2016 ISI Calculus Problem.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": 28.2075471698, "max_line_length": 174, "alphanum_fraction": 0.6086956522, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.6117544022332617}}
{"text": "\\chapter{Model Selection}\n\\label{chp:subsel}\n\nIn the previous chapters the chosen number of predictors in the models have not been discussed very thoroughly. The p-value was used for selecting the best predictor in Lab 4.6.2 in section \\ref{sec:lab462}. The question though remains how many predictors should be included when creating a model. This chapter discusses three different methods for selecting a subset of the predictors for a model.\n\n\\section{Best Subset Selection}\nBest subset selection is a method for choosing the best possible subset of predictors. In this approach a model is fitted for each possible combination of the predictors.\n\nThe algorithm for best subset selection is explained in Algorithm \\ref{algo:bestsubset}. First the null models are created in step 1. In line 2 it iterates from 1 predictor and up to the number of available predictors. In line 3 all possible models with k predictors are fitted and in line 4 and 5 the best model with k predictors is chosen. When all iterations are done the single best model is chosen.\n\n% Insert the algorithm\n\\begin{algorithm}\n\t\\caption{Best subset selection}\n\t\\label{algo:bestsubset}\n\t\\begin{algorithmic}[1]\n\t\t\\State Let $M_0$ denote null model, containing no predictors. Which means that $M_0$ contains the sample mean for each observation.\n\t\t\\For {each $k$ from $1$ to $length(p)$}\n\t\t\\State Fit all the different models with a combination of k predictors.\n\t\t\\State \\parbox[t]{\\dimexpr\\linewidth-\\algorithmicindent}{Pick the best model with k predictors. Best can be defined as smallest RSS or largest $R^2$}\n\t\t\\State $M_k = best\\_model$\n\t\t\\EndFor\n\t\t\\State Choose a single best models from all the best models in $M_0,...M_k$. The best model is chosen based on $C_p$, $BIC$ or adjusted $R^2$ if the whole data set is used for training the models.\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n\\subsection{Lab 6.5.1 - Best Subset Selection}\nIn this exercise a best subset selection is performed on a data set called \\emph{Hitters}. The data set is used for predicting the salary of baseball players. Before performing best subset selection the data is split into predictors and the response variable.\n\nA function for choosing the best subset is then defined in listing \\ref{lst:best_subset_selection}. In line 3 it iterates through all combinations of the predictors with k number of predictors. A function \\emph{process\\_subset} is called which returns the subset with calculated model, RSS, $R^2$, BIC and $C_p$. In line 4 all the different combinations are appended to the \\emph{models} array. In line 5 the best model is picked based on lowest RSS and then returned.\n\n\\begin{lstlisting}[language=Python, label=lst:best_subset_selection, caption=Function for choosing best subset]\ndef best_subset_selection(k):\n\tmodels = []\n\tfor combo in combinations(X.columns, k):\n\t\tmodels.append(process_subset(combo))\n\treturn models[np.argmin([r['RSS'] for r in models])]\n\\end{lstlisting}\n\nThe function in listing \\ref{lst:process_subset} is called in listing \\ref{lst:best_subset_selection} in line 4. It fits a linear regression model and computes RSS, $R^2$, $C_p$ and BIC for the model.\n\n\\begin{lstlisting}[language=Python, label=lst:process_subset, caption=Function for computing metrics for subset]\ndef process_subset(feature_set):\n\td = len(feature_set)\n\tn = X.shape[0]\n\tmodel = lm.LinearRegression().fit(X[[i for i in feature_set]], Y)\n\tY_hat = model.predict(X[list(feature_set)])\n\t\n\trss = metricsUtil.RSS(Y, Y_hat)  \n\trsquared = metrics.r2_score(Y, Y_hat)\n\tcp = metricsUtil.Cp(rss, d, Y_hat, n)\n\tbic = metricsUtil.Bic(n, rss, d, Y_hat)\n\t\n\treturn {\"model\":model, \"features\": feature_set,\n\t\t\t\"RSS\":rss, \"rsquared\": rsquared, \"bic\": bic, \"cp\":cp }\n\\end{lstlisting}\n\nFor calculating RSS, $R^2$, $C_p$ and BIC a python module called metricsUtil was implemented. The module has defined functions for calculating these values. After these functions are defined the best subset selection is computed. In listing \\ref{lst:best_subset9} a best subset selection is performed for the 19 possible predictors.\n\n\\begin{lstlisting}[language=Python, label=lst:best_subset9, caption=Calculating the best subset from 1 to 19 predictors]\nfor i in xrange(1,20):\n\tsubsets.loc[i] = best_subset_selection(i)\n\\end{lstlisting}\n\nPlotting RSS, $R^2$, $C_p$ and BIC for the best models from 1-19 predictors gives the plotted graphs shown in figure \\ref{fig:best_plottet}. It shows how RSS and $R^2$ respectively monotonically increases and decreases. This is caused by using the same data for both training and testing. When doing this Cp, BIC or adjusted $R^2$ can be used for estimating the optimal amount of predictorss. When calculating BIC and $C_p$ a penalty is added to the calculation. For adjusted $R^2$ the calculation takes into account that only small increases in RSS are often caused by adding a noise variable. Noise variables are added, which consequently leads to a decrease of $R^2$ \\citep[pp. 598]{propandstats} \\citep[pp. 210-213]{ISLR}. \n\n\\myFigure{subset_all_graph.PNG}{Plotted RSS, $R^2$, $C_p$ and BIC for best subset selection from 1-19 predictors}{fig:best_plottet}{1}\n\\FloatBarrier\n\n\nBIC indicates that the best model contains 6 predictors. The best model with 6 predictors include: \\emph{AtBat, Hits, Walks, CRBI, Division} and \\emph{PutOuts}. $C_p$ indicates that the best model contains 10 predictors, this also makes sense as BIC generally places a heavier penalty \\citep[pp. 212]{ISLR}. The best 10 predictors for a model included: \\emph{AtBat, Hits, Walks, CAtBat, CRuns, CRBI, CWalks, PutOuts, Assists} and \\emph{Division}. This also shows how the set of 6 predictors is not just a subset of the 10 predictors. This is because every combination is tried for every number of predictors. A drawback of the algorithm is therefore that it is computationally expensive. The models that must be computed for 19 predictors to find the best amount of predictors is calculated in equation (5.1) to 524,288.\n\n\\begin{equation}\n2^{19} = 524,288\n\\end{equation}\n\nThe following section presents two different algorithms that can be used for selecting predictors with fewer computations than just described for best subset selection.\n\n\\section{Forward and Backward Stepwise Selection}\nForward and backward stepwise selection are two similar algorithms for stepwise selection of a subset. They are both more computationally efficient than the best subset selection.\n\nThe forward stepwise selection algorithm adds predictors to the model one by one. When computing the k+1'th model, the predictors chosen for the k'th model defines the first k predictors and then one new predictor is added. This means that the k'th best model will always be a subset of the k+n'th best model. The predictor that improves most upon the model is always the one added.\n\nBackward stepwise selection works very similar to forward stepwise selection. However, the model instead starts by containing all predictors and at each step a predictor is removed. The predictor that is removed is chosen by which gives the best model. This means that instead of fitting 524,288 models with best subset selection, forward and backward stepwise selection only has to fit 191 models as calculated in equation (5.2). This is a significant difference in models that must be fitted.  This was also obvious when executing the exercises for best subset selection compared to forward and backward stepwise selection.\n\n\\begin{equation}\n1+ \\sum_{k=0}^{18}(19-k) = 191\n\\end{equation}\n\n\\subsection{Lab 6.5.2 - Forward and Backward Stepwise Selection}\nThe exercise for 6.5.3 is very similar to 6.5.2 and a function for forward and backward stepwise selection was implemented and used instead of \\emph{best\\_subset\\_selection} implemented in listing \\ref{lst:best_subset_selection}. The rest of the code could be reused. In listing \\ref{lst:forwardselection} the implemented function for forward stepwise selection is shown. First the remaining predictors to choose from are extracted. \\emph{X.columns} is all the predictors while \\emph{already\\_chosen\\_predictors} is passed as a parameter. It then runs a for loop iterating through all the remaining predictors and adding them to the model. The best model is then selected based on RSS.\n\n\\begin{lstlisting}[language=Python, label=lst:forwardselection, caption=Function for forward stepwise selection]\ndef forward_stepwise_selection(already_chosen_predictors):\n\tremaining_predictors = [p for p in X.columns if p not in\n\t\talready_chosen_predictors]\n\t\t\n\tmodels = []\n\tfor p in remaining_predictors:\n\t\tmodels.append(process_subset(already_chosen_predictors+[p]))\n\treturn models[np.argmin([r['RSS'] for r in models])]\n\\end{lstlisting}\n\nSimilarly a function for backward stepwise selection was implemented. Comparing the models for best subset selection, forward and backward stepwise selection showed that some models were identical while others differed. For example the models with predictors from 1 to 6 for both best subset selection and forward stepwise selection were identical while the model with 7 predictors differed. This is not the case with backward stepwise selection which differs in all these. Actually the best model with 7 predictors differs in all three algorithms. The following 7 predictors were chosen:\n\n\\begin{itemize}\n\\item Forward stepwise: \\emph{CRBI, Hits, PutOuts, Division, AtBat, Walks} and \\emph{CWalks}\n\\item Best subset: \\emph{Hits, Walks, CAtBat, CHits, ChMRun, PutOuts} \\emph{Division}\n\\item Backward stepwise: \\emph{AtBat, Hits, Walks, CRuns, CWalks, PutOuts} and \\emph{Division}\n\\end{itemize}\n\n\\section{Validation Set Approach and Cross-Validation}\nIn the previous exercises $C_p$, AIC, BIC and adjusted $R^2$ was used for picking the right amount of predictors. This was needed because the models were trained on the complete data set and so the test error would provide an underestimate of the true error.\n\nIn this exercise the validation set approach and cross-validation are used. Therefore instead of using $C_p$, AIC, BIC and adjusted $R^2$ the test error can be directly calculated. \n\\subsection{Lab 6.5.3 - Choosing Among Models Using The Validation Set Approach and Cross-Validation}\n\nInitially the validation set approach will be used in combination with best subset selection. This is shown in listing \\ref{lst:validationsetapproach}. First the data is split into a training and testing set. When this is done the best subset selection is run from 1 to 19 predictors. A small modification of the functions were needed so that the training and test sets were used appropriately.\n\n\\begin{lstlisting}[language=Python, label=lst:validationsetapproach, caption=Validation set approach and best subset selection for choosing predictors]\ntrain, test = train_test_split(data, test_size = 0.5)\n\n.......\n\nfor i in xrange(1, 20):\n\tsubsets.loc[i] = best_subset_selection(i, X_train, Y_train,\n\tX_test, Y_test)\n\\end{lstlisting}\n\nThe mean squared error for different numbers of predictors is shown in table \\ref{table:mse_validation}. By using this validation set approach and best subset selection the optimal number of predictors is computed to 9. The optimal number of predictors is based on the model with lowest mean squared error. It is important to note that a different split of train and test data can give a different number of optimal predictors.\n\nThe validation set approach splits the data equally in two parts. This does not leave much data for training and the test error is therefore very likely an overestimate for the model fit on the entire data. Another approach is k-fold cross-validation. In this exercise a 10-fold cross-validation is executed on the data set in combination with best subset selection.\n\nThe implementation of 10-fold cross-validation is shown in listing \\ref{lst:crossvalidation}. First a 10-fold random split of the data is done. Then a for loop iterates through the folds and gives a train and test index for each iteration. These indexes are used to create a training and test set for each fold. For each fold a best subset selection is performed from 1 to 19 predictors. After performing the best subset selection 10 times, one for each fold, then a mean of the MSE is calculated for all the folds.\n\n\\begin{lstlisting}[language=Python, label=lst:crossvalidation, caption=Cross-validation and best subset selection for choosing predictors]\nkf = KFold(n_splits=10, shuffle=True)\nkf.get_n_splits(X)\nj = 0\nmse = np.zeros((kf.n_splits, 19))\nfor train_index, test_index in kf.split(X):\n    X_train = X.iloc[train_index]\n    Y_train = Y.iloc[train_index]\n    X_test = X.iloc[test_index]\n    Y_test = Y.iloc[test_index]\n    for i in xrange(1, 20):\n\t\tsubset = best_subset_selection(i, X_train, Y_train, X_test, Y_test)\n        mse[j,i-1] = subset[\"mse\"]\n    j = j+1  \n\\end{lstlisting}\n\\FloatBarrier\n\nThe results for cross-validation and best subset selection is shown in table \\ref{table:mse_cross}. Using this approach the best model is achieved using a model with 10 predictors. Compared to the best subset selection, this method is even more computationally expensive because it runs the best subset selection one time for each fold.\n\n\\begin{table}\t\n\t\\centering\n\t\\begin{subtable}[t]{2in}\n\t\t\\centering\n\t\t\\begin{tabular}{ p{2.5cm} p{1.5cm}  }\n\t\t\t\\textbf{Predictors} & \\textbf{MSE} \\\\\n\t\t\t\\hline \n\t\t\t\\vspace{0.1px}\n\t\t\t7 & \\vspace{0.1px} 90,133  \\\\\\hline\n\t\t\t\\vspace{0.03em}\n\t\t\t8 & \\vspace{0.03em} 89,914  \\\\\\hline\n\t\t\t\\vspace{0.03em}\n\t\t\t\\textbf{9} & \\vspace{0.03em} \\textbf{89,782}  \\\\\\hline\n\t\t\t\\vspace{0.03em}\n\t\t\t10 &\\vspace{0.03em} 90,015  \\\\\\hline\n\t\t\t\\vspace{0.03em}\n\t\t\t11 & \\vspace{0.03em} 90,192  \\\\\\hline\n\t\t\t\\vspace{0.03em}\n\t\t\t12 & \\vspace{0.03em} 90,363  \\\\\\hline\n\t\t\\end{tabular}\n\t\t\\caption{Validation set approach}\\label{table:mse_validation}\n\t\\end{subtable}\n\t\\quad \n\t\\begin{subtable}[t]{2in}\n\t\t\\centering\n\t\\begin{tabular}{ p{2.5cm} p{1.5cm}  }\n\t\t\\textbf{Predictors} & \\textbf{MSE} \\\\\n\t\t\\hline \n\t\t\\vspace{0.03em}\n\t\t7 & \\vspace{0.03em} 78,360  \\\\\\hline\n\t\t\\vspace{0.03em}\n\t\t8 & \\vspace{0.03em} 77,971  \\\\\\hline\n\t\t\\vspace{0.03em}\n\t\t9 & \\vspace{0.03em} 77,944  \\\\\\hline\n\t\t\\vspace{0.03em}\n\t\t\\textbf{10} & \\vspace{0.03em} \\textbf{77,895} \\\\\\hline\n\t\t\\vspace{0.03em}\n\t\t11 & \\vspace{0.03em} 78,352  \\\\\\hline\n\t\t\\vspace{0.03em}\n\t\t12 & \\vspace{0.03em} 78,795 \\\\\\hline\n\t\\end{tabular}\n\t\t\\caption{Cross-validation}\\label{table:mse_cross}\n\t\\end{subtable}\n\t\\caption{Calculated mean squared error from 7 to 12 predictors.}\\label{table:mse}\n\\end{table}\n\nWhen choosing among the different techniques for subset selection it is often a matter of how much computation power is available.  The best subset selection is a lot more expensive than forward and backward stepwise selection. Combining best subset selection with cross-validation also makes the process even more computationally expensive. If many predictors are available, then best subset selection might simply be too expensive, even for very fast modern computers. If more than 40 predictors are available, then best subset selection is rarely feasible and methods such as forward and backward stepwise selection could be used instead  \\citep[pp. 207]{ISLR}. \n\nAn important aspect of subset selection is that the best model might be more complex than a simpler model performing approximately as good. When choosing subset of predictors complexity vs simplicity should also be included in the final choice of predictors", "meta": {"hexsha": "a45c746ed7908489e2228ecf5f6f0f8c5f9942d0", "size": 15379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/subset_selection.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/subset_selection.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/subset_selection.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": 75.7586206897, "max_line_length": 820, "alphanum_fraction": 0.7737174069, "num_tokens": 3973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208002, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6117544022332615}}
{"text": "\\chapter{\\uppercase{Extensions and Applications of MUD Points and Skewness} \\label{chapter:vector-valued}}\nIn Chapter~\\ref{chapter:geometry}, we introduced the notion of skewness and showed examples of how it impacts the accuracy of approximating SIP solutions with finite sampling.\nHere, we demonstrate how an awareness of skewness allows us to a priori define a QoI that will\\---on average\\---better resolve $\\paramref$ by providing information in mutually distinct directions in $\\pspace$.\nWe begin by revisiting the example in Section \\ref{subsec:pde-example} involving the Poisson problem and uncertain Neumann boundary condition $g$.\nRecall that $\\qoi_\\text{2D}$ is able to better resolve $\\paramref$ (in this case, $\\paramref$ is defined by a finite-dimensional representation of an exact $g$), than $\\qoi_\\text{1D}$.\nThe map $\\qoi_\\text{2D}$ is presented as an alternative option for aggregating the same $100$ measurements and using them to construct a more informative 2D map.\nIn this chapter, we present a more detailed study of the construction of this map, and perform a case-study in designing a problem where the data-constructed QoI map is more informative.\n\n\\input{extensions/mud_vector_map.tex}\n\\FloatBarrier\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\FloatBarrier\n\\input{extensions/mud_pde_geometry.tex}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{extensions/mud_pde_5d.tex}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{extensions/mud_pde_sequence.tex}\n\\FloatBarrier\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\section{Conclusions}\n\nWe have shown that when posing and solving SIPs, we are motivated to choose data-constructed QoI maps which have (a) as many components as possible (up to the dimension of $\\pspace$), and (b) whose components exhibit high-degrees of mutually geometrically distinct information (i.e., low average skewness).\nThere is a dramatic reduction in the sensitivity to the measurement noise when the same hundred measurements are used to construct a map with lower skewness.\nIn the next chapter, we discuss some other considerations for constructing SIPs, including measurement precision and placement.\nWe show how different experimental setups can lead to parameter estimates which exhibit different levels of accuracy and precision.\nWe also introduce a novel method for leveraging the results shown here in a sequential manner to gain possible computational efficiency.\n", "meta": {"hexsha": "2add5af569ccd9452fcb435ef408bcd2aeac6cd4", "size": 2812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter05.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": "chapter05.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": "chapter05.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": 76.0, "max_line_length": 306, "alphanum_fraction": 0.6468705548, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933403143929, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6117543959631181}}
{"text": "\\section{Introduction}\nGiven a graph $G$ and $k$ agents, each of which is associated with an initial vertex and a goal vertex of $G$, \\emph{Multi-Agent Pathfinding (MAPF)} is the problem of finding $k$ conflict-free paths which connect the initial vertex with the goal vertex of each agent.\n\nThere are a number of applications of MAPF, which range from industrial applications, in which the increase in automation may promote the need for dozens---perhaps hundreds---of robots navigating in indoor environments (e.g., warehouses), to aviation, underground mining, and multi-agent videogames \\cite{WangB08}.\n\nSolving MAPF optimally is NP-complete \\cite{YuL13,MaK17}. When viewed as a standard AI search problem, it is straightforward to notice that the branching factor of MAPF is exponential on the number of agents since at each moment in time each agent can perform a number of actions, relatively fixed. It is not surprising, then, that building algorithms that scale reasonably well with the number of agents has been challenging.\n\nFor its most simple version, that is, MAPF over 4-connected grids, a number of approaches have been proposed, but two classes of solvers are the most relevant for the research we report here. A first class, is search-based solvers (e.g., \\nbcite{Standley10}), which use heuristic search as the main component.\nA state-of-the-art search-based solver is Conflict-Based Search (CBS) \\cite{SharonSFS12,FelnerLB00KK18,LiFB0K19}, which uses A* at its core. A second class, is compilation-based solvers; for example which translate MAPF to Satisfiability Testing (SAT) (e.g., \\nbcite{SurynekFSB16}; \\nbcite{BartakZSBS17}; \\nbcite{BartakS19}), and Answer-Set Programming \\cite{ErdemKOS13,GebserOOS18}.\n\nWhen seeking for an optimal solution for MAPF, different objective functions can be considered. Under \\emph{sum-of-costs}, the most popular variant of MAPF, the objective is to minimize the moves agents perform before stopping at the goal. % This is variant is used in state-of-the-art solvers like CBS.\n\nIn this paper, we continue to explore the potential of ASP solvers for MAPF, and propose the first compilation that solves MAPF optimally under the sum-of-costs assumption. A second contribution consists of proposing the first compilation from MAPF to ASP that grows linearly with the number of agents, unlike existing compilations to ASP that are quadratic on the number of agents. In addition, we propose an optimization which uses information drawn from a search algorithm that is run as a preprocessing step to make the encoding more compact.\n\nIn our empirical evaluation, we evaluate our approach on synthetic square grids and warehouse grids with an increasing number of agents. We compare against MDD-SAT~\\cite{SurynekFSB16}, a representative of the state of the art in SAT-based MAPF, and iCBS-h~\\cite{FelnerLB00KK18}, a representative of the state-of-the-art in search-based MAPF. We observe that our approach outperforms both MDD-SAT and iCBS-h when congestion is high. Specifically, our approach has a greater coverage as the number of agents increase. We conclude that Answer-Set Programming is a viable approach to solving MAPF problems.\n", "meta": {"hexsha": "3e7a2a671561c055118ec7bac27eae532e36e4a4", "size": 3187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aaai20/intro.tex", "max_stars_repo_name": "rkoco/lp-mapf", "max_stars_repo_head_hexsha": "8ffa93bd33feb244ac2db7230ea3b9ff2deb7038", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aaai20/intro.tex", "max_issues_repo_name": "rkoco/lp-mapf", "max_issues_repo_head_hexsha": "8ffa93bd33feb244ac2db7230ea3b9ff2deb7038", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aaai20/intro.tex", "max_forks_repo_name": "rkoco/lp-mapf", "max_forks_repo_head_hexsha": "8ffa93bd33feb244ac2db7230ea3b9ff2deb7038", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 199.1875, "max_line_length": 602, "alphanum_fraction": 0.8004392846, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.611754391929116}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\n\\usepackage{url}\n\\usepackage{graphicx}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{dsfont}\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 Facility Location}\n\\normalsize\n\n\n\\section{Problem Statement}\n\nIn this assignment you will design an algorithm to solve a problem faced by distribution companies, {\\em The Facility Location Problem}. A distribution company uses bulk storage facilities to provide goods to many different customers.  The goal of this problem is to determine which facilities will be the most cost effective for serving the customers.  The complexity of the problem comes from the fact that each facility has different costs and storage capabilities.\\footnote{Hint: The facility location problem is closely related to the warehouse location problem discussed in the lectures.} \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 solve the facility location problem.  The problem is mathematically formulated in the following way:  there are $N = 0 \\ldots n-1$ facilities to choose from and $M = n \\ldots n+m-1$ customers that need to be served.  Each facility, ${\\it f} \\in N$ has a setup cost $s_{\\it f}$ and a capacity $cap_{\\it f}$.  Each customer, $c \\in M$, has a demand $d_c$.  Both the facilities and customers are located in a Euclidian space, $\\langle x_i,y_i \\rangle \\; i \\in N \\cup M$.  The cost to deliver goods to a particular customer $c$ from a facility ${\\it f}$ is the Euclidean distance between two locations, ${\\it dist}({\\it f},c)$.\\footnote{${\\it dist}(i,j) = \\sqrt{(x_{i} - x_{j})^2 + (y_{i} - y_{j})^2}$}  Lastly, all customers must be served by exactly 1 facility.  Let $a_f$ be a set variable denoting the customers assigned to facility $f$.  Then the facility location problem is formalized as the following optimization problem:\n$$\n\\begin{array}{ll}\n\\mbox{minimize:} & \\displaystyle \\sum_{f \\in N} \\left( (|a_{\\it f}| > 0) s_{\\it f} + \\sum_{c \\in a_{\\it f}} {\\it dist}({\\it f},c) \\right) \\\\\n\\mbox{subject to:} & \\\\\n     & \\displaystyle \\sum_{c \\in a_{\\it f}}  d_c \\leq cap_{\\it f} \\;\\;\\; ({\\it f} \\in N)\\\\\n     & \\displaystyle \\sum_{{\\it f} \\in N}  (c \\in a_{\\it f}) = 1 \\;\\;\\; (c \\in M) \n\\end{array}\n$$\n\n\\clearpage\n\\section{Data Format Specification}\n\nThe input consists of $|N| + |M| + 1$ lines.  The first line contains two numbers, $|N|$ followed by $|M|$.\nThe first line is followed by $|N|$ lines, where each line encodes the facility's setup cost $s_{\\it f}$, capacity $cap_{\\it f}$, and the location $x_{\\it f}, y_{\\it f}$.  The remaining $|M|$ lines capture the customer information, where each line encodes the customer's demand, $d_c$, and location $x_c, y_c$.\n\n\\vspace{0.2cm}\n\\noindent\nInput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n|N| |M|\ns_0 cap_0 x_0 y_0\ns_1 cap_1 x_1 y_1\n...\ns_|N|-1 cap_|N|-1 x_|N|-1 y_|N|-1\nd_|N| x_|N| y_|N|\nd_|N|+1 x_|N|+1 y_|N|+1\n...\nd_|N|+|M|-1  x_|N|+|M|-1 y_|N|+|M|-1\n\\end{Verbatim}\n%\nThe output has two lines.  The first line contains two values: $obj$ and $opt$.  $obj$ is the cost of the customer to facility assignment (i.e. the objective value) as a real number.  $opt$ should be $1$ if your algorithm proved optimality and $0$ otherwise.  The next line is a list of $|M|$ values in $N$ -- this is the mapping of customers to facilities.\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_|M|-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\\clearpage\n\\paragraph{Examples}\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]\n 3 4 \n 100 100 1065.0 1065.0\n 100 100 1062.0 1062.0 \n 100 500 0.0 0.0 \n 50 1397.0 1397.0\n 50 1398.0 1398.0 \n 75 1399.0 1399.0 \n 75 586.0 586.0\n\\end{Verbatim}\n\n\\vspace{0.2cm}\n\\noindent\nOutput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n2550.013 0\n1 1 0 2\n\\end{Verbatim}\n%\nThis output represents the assignment of customers to facilities, $a_0 = \\{2\\}, a_1 = \\{0,1\\}, a_2 = \\{3\\}$.  That is, customers 0 and 1 are assigned to facility 1, customer 2 is assigned to facility 0, and customers 3 is assigned to facility 2.\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  facility location problem 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%The 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": "bfb979b2cd9ea340c61d60068ecb65f5371746de", "size": 6390, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/facility.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/facility.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/facility.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": 37.5882352941, "max_line_length": 948, "alphanum_fraction": 0.6968701095, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407017, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.6117543837199892}}
{"text": "\\section{Case Study: Rössler System}\n\nThe well known Rössler system is given by the equations\n\\[\n\t\\begin{array}{rcl}\n\t\t\\dot x &=& -y - z \\\\\n\t\t\\dot y &=& x + a \\cdot y \\\\\n\t\t\\dot z &=& b + z \\cdot (x - c) \\\\\n\t\\end{array}\n\\]\nwith parameters $a$, $b$, and $c$. For this example, $a$ and $b$\nare fixed to $0.1$, while we are varying $c$.\n\nThe system has several periodic solutions for each value of $c$ with different\nperiodicities, though only one is stable at a time. We are interested in the origin and\nbranching of those solutions and, thus, drawing a bifurcation diagram using the map\n\\[\n\t\\mathbf y \\mapsto \\{ \\|\\mathbf y(t)\\|  \\ | \\ t \\in [0, 2\\pi), \\ \\mathbf y_1(t) = 0, \\ \\mathbf y'_1(t) > 0 \\} \\ .\n\\]\nHere, $f$ denotes a single periodic solution. Note, that we use only the approximation\ngiven by Galerkin's method.\n\nThe exploration of the bifurcations with the given tools follows roughly these steps:\n\\begin{enumerate}\n\t\\item As a starting point, search for a value of $c$ such that the system has a\n\t\tstable, periodic solution and use the method described in\n\t\t\\autoref{sec:initial} to find it. 4000 iterations in the transient part with step\n\t\tsize of $0.01$, 120 generated intersections with the $(x=0)$-plane and tests for\n\t\tat most $30$ periods were sufficient for all initial solutions of the Rössler\n\t\tsystem. We started at $c=4$ with $64$ samples.\n\t\\item Trace out the branch just by following the newly found solution in both directions\n\t\tusing the predictor-corrector continuation method (\\autoref{sec:cont}). The\n\t\tparameters $\\kappa=0.4$, $\\delta=3.0$, and $\\alpha=10.0$ are a decent choice for\n\t\tthe whole diagram as a good tradeoff between performance and accuracy.\n\t\\item It is possible to detect a pitchfork bifurcation by doubling up the periodicity\n\t\tartificially. Using the described predictor-corrector method, the value\n\t\tof $c$ will eventually converge to the bifurcation point, i.e., a point with a\n\t\tsingular tangent. Since the method is now stuck, reaching the doubly-periodic\n\t\tsolution can be done by solving a slightly perturbed problem for a short time.\n\t\tA short perturbation of strength $0.2$ was enough to reach the doubly-periodic\n\t\tsolution. Also, it might be necessary to increase the sample size due to increased\n\t\tcomplexity in the descending branch.\n\t\\item Remove the perturbation and continue tracing out the bifurcation, i.e. start\n\t\tover in 1 or 2.\n\\end{enumerate}\n\n\\begin{figure}[!ht]\n\t\\centering\n\t\\subfloat[][]{\\includegraphics[width=.4\\textwidth]{img/roessler1a.pdf}}\\quad\n\t\\subfloat[][]{\\includegraphics[width=.4\\textwidth]{img/roessler1b.pdf}}\\\\\n\t\\subfloat[][]{\\includegraphics[width=.4\\textwidth]{img/roessler1c.pdf}}\\quad\n\t\\subfloat[][]{\\includegraphics[width=.4\\textwidth]{img/roessler1d.pdf}}\n\t\\caption{Tracing out the branch of solutions beginning with the solution for\n\t$c=4$ (a). The bifurcation point in $c \\approx 5.376$ is avoided by using a permutation (b),\n\tand the two-periodic solutions can be traced out after removing the inaccurate values\n\tfrom before (c). Eventually, we reach (d), a widely traced out bifurcation diagram.\n\tNote the solutions with periodicity three and descendants, that do not originate in\n\tthe periodicity-one branch.}\n\t\\label{fig:reosslerseq}\n\\end{figure}\n\nSee figure \\ref{fig:reosslerseq} for a visualization of this process, and figures \\ref{fig:roesslerfull}, \\ref{fig:roesslercut} for a depiction of the results.\n\n%\\begin{figure}[!ht]\n\t%\\centering\n\t%\\includegraphics[width=1\\textwidth]{img/roessler2a.pdf}\n\t%\\caption{The bifurcation diagram of the Rössler system for varying $c$. The\n\t\t%even-periodic solutions are colored red, the odd-periodic ones green.}\n%\\end{figure}\n%\n%\n%\\begin{figure}[!ht]\n\t%\\centering\n\t%\\includegraphics[width=1\\textwidth]{img/roessler2b.pdf}\n\t%\\caption{All found solutions for $c=\\dots$ plotted into one diagram.\n\t%Observe how the odd-periodic and even-periodic solutions dodge since they do not\n\t%originate from each other.}\n%\\end{figure}\n\n\\newgeometry{top=0cm}\n\n\\begin{figure}\n\\centering\\makebox[0pt]{\\rotatebox{90}{\\includegraphics{img/roessleroverview.png}}}\n\\caption{An overview of the Rössler bifurcation diagram.}\n\\label{fig:roesslerfull}\n\\end{figure}\n\n\\begin{figure}\n\\centering\\makebox[0pt]{\\rotatebox{0}{\\includegraphics{img/roesslercut20.png}}}\n\\caption{The periodic orbits for $c=20$, together with an underlying trajectory obained through forward intergration (grey) in phase-space. The colors of the periodic solutions match the bifurcation diagram.}\n\\label{fig:roesslercut}\n\\end{figure}\n\n\\restoregeometry\n", "meta": {"hexsha": "97f9dc5dc5f4df978c701e911fcfd84fbfe27af3", "size": 4539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doctheory/roessler.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/roessler.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/roessler.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": 47.7789473684, "max_line_length": 208, "alphanum_fraction": 0.7473011677, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407017, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.611754372227211}}
{"text": "% !TeX root = ./corona_contact_tracing.tex\n% chktex-file 46\n% !TeX spellcheck = en-GB\n% !TeX encoding = utf8\n\n\\subsection{Probabilistic Health Prediction}\n\nWe model partially infected populations as a graph, where each individual (interchangeably called agent) is a node. Edges of this graph model contacts of two agents. We use graph convolution, as explained below, to update our assumptions on the current health state of all individuals.\n\nThe definition of a graph convolution~\\cite{Kipf2017SemiSupervisedCW} for here is\n\n\\begin{equation}\n\t\\label{eq:graph_convolution}\n\th_{v_i}^{(l+1)} = \\sum_{j\\in A(i)} h_{v_j}^{(l)}\n\\end{equation}\n\nwith feature vector $h$ of node $i$ from iteration $(l)$ to $(l+1)$. This formulation is equivalent to the matrix formulation $h^{(l+1)} = A h^{(l)}$ with $A$ as adjacency matrix as shown in \\cref{sec:consistency}. We consider here adjacency matrices without diagonal elements.\n\n\\begin{itemize}\n    \\item Each agent $i$ is modeled by $D$ features $h_{v_i} \\in \\mathbb{R}^D$. Therefore, the feature matrix, $h^{(l)}$, consists of all agents' features at time $(l)$ and is thereby of dimension $N\\times D$ where there are $N$ agents in the population and each agent is described by $D$ features. A three dimensional feature space is used, $D=3$, modeling the three possible health states. The unit vectors of this space are interpreted as following:\n\t\\begin{itemize}\n\t\t\\item $\\vec{e}_0$: susceptible state\n\t\t\\item $\\vec{e}_1$: infected state\n\t\t\\item $\\vec{e}_2$: recovered state\n\t\\end{itemize}\n\tA uniform distribution over these possible states expresses complete uncertainty of the health state of an agent.\n\\end{itemize}\n\nTo accurately model the disease, there is graph contribution and an individual health contribution.\n\n\\subsubsection{Explanation of the graph contribution term}\nThe graph contribution models how infected agents spread the disease through contacts with susceptible agents.\n\n\\begin{equation}\n    h_{v_i, m}^{(l+1)}\n\t=\n\t\\underbrace{\n\t\t\\sum_k \\textcolor{red}{\\frac{\\hat{A}_{v_i, k}^{(l)}}{\\sum_j \\hat{A}_{v_i, j}^{(l)}}} h_{k, m}^{(l)} \\textcolor{blue}{\\delta_{m, e_I}}\n\t}_{\\text{Graph}}\n\\end{equation}\n\n\\begin{itemize}\n    \\item A sum over all agents' features $h_{k,m}^{(l)}$ is weighted by the normalised infection-adjusted graph connections as shown in red.\n    \\item The Kronecker delta, as shown in blue, ensures that only the I feature is added as this is the only one that matters during social contacts between agents.\n    \\item The infection-adjusted adjacency matrix $\\hat{A}$ is constructed from $A$ and $I$ which are the regular continuous adjacency matrix and the infection matrix, respectively. These three quantities are explained in the following:\n    \\begin{itemize}\n        \\item The adjacency matrix $A$ is time dependent, $A^{(l)}$, and inferred from data. In our use case, $A_{ij} = \\frac{1}{dist(v_i, v_j)+\\epsilon}$, hence $A_{ij}$ is large when persons $i$ and $j$ have been in contact. $\\epsilon$ serves as regularization for small distances.\n        \\item The infection matrix is constructed as\n        \\begin{equation}\n            I =\n            \\begin{pmatrix}\n                0     &  0  & 0 \\\\\n                \\beta &  0  & \\alpha \\\\\n                0     &  0  & 0\n            \\end{pmatrix}\n            =\n            (I_{ij})_{i,j}\n        \\end{equation}\n        with $i$ as the index of the host state and $j$ is the index of the contact person state. The states that we consider here are ordered as follows: susceptible, infected, recovered. $\\beta$ denotes the probability of infection  after contact (also known as attack rate). $\\alpha$ models the probability of being reinfected, which we assume to be zero ($\\alpha=0$) based upon current medical \\todo{cite!}research.\n        \\item $\\hat{A}$, with $\\hat{A}_{ij}\\in [0, 1]$, is the adjacency matrix that takes the infection interactions into account and is computed as follows\n        \\begin{equation}\n            \\hat{A}_{ij} = A_{ij}\\cdot \\frac{ h_{v_1}^T I h_{v_2} + h_{v_2}^T I h_{v_1} }{\\beta}.\n        \\end{equation}\n        The weighted scalar product of the health states of agents $i$ and $j$ is used to evaluate whether the edge is relevant for the infection dynamics. Only when an infected person and a susceptible have contact, the edge $A_{ij}$ should be considered, otherwise it should be dropped.\tThe sum in the denominator comes from the fact that both, agent $i$ and $j$, can act as host during a contact. The division by $\\beta$ normalises the factor to one to ensure $\\hat{A}_{ij} \\in [0, 1]$. Since $I$ is not symmetric, $p_a$ is a proper normalization because the sum is in $\\{0, p_a\\}$. Note that the fraction has the desired properties for pure $S$-, $I$- and $R$-persons.\n    \\end{itemize}\n\\end{itemize}\n\n\n\\subsubsection{Temporal}\n% \\item Explanation of the temporal term:\nThe transition of a persons' health state $h_{v_i}^{(l)}$ is determined by the following assumptions:\n\\begin{itemize}\n\t\\item A susceptible person always stays susceptible\n\t\\item An infected person has a probability $\\gamma$, called recovery rate, to recover. The remaining probability $1-\\gamma$ denotes that the person stays sick.\n\t\\item A recovered person could have a probability to be re-infected, but we assume this to be zero. Thus a recovered person always stays recovered.\n\\end{itemize}\nThus the temporal transition matrix $T$ is:\n\\begin{equation}\n\tT = \n\t\\begin{pmatrix}\n\t\t1 &     0    & 0      \\\\\n\t\t0 & 1-\\gamma & \\gamma \\\\\n\t\t0 &     0    & 1      \\\\\n\t\\end{pmatrix}\n\\end{equation}\nThe temporal update rule based on the health status thus becomes:\n\\begin{equation}\n\tH^{(l+1)} = H^{(l)} T\n\\end{equation}\n\n\\subsubsection{Joint Model}\n\nOur main propagation rule is based on the definition of a graph convolution shown in Eq.~\\eqref{eq:graph_convolution} and reads as follows in component notation\n\\begin{equation}\n\th_{v_i, m}^{(l+1)}\n\t=\n\t\\underbrace{\n\t\t\\sum_k \\textcolor{red}{\\frac{\\hat{A}_{v_i, k}^{(l)}}{\\sum_j \\hat{A}_{v_i, j}^{(l)}}} h_{k, m}^{(l)} \\textcolor{blue}{\\delta_{m, e_I}}\n\t}_{\\text{Graph}}\n\t+\n\t\\underbrace{\n\t\t{(h_{v_i}^{(l)}\\cdot T)}_m\n\t}_{\\text{Temporal}}\n\\end{equation}\nwith $m$ being the index of the health state.\n\nThis propagation rule is based on the following aspects:\n\n\\begin{itemize}\n\t\\item The propagation consists of two parts, first the graph contribution and second the temporal contribution. While the former captures the dynamics of infections based on the social contacts between agents, the former ensures that an infected agent heals over time and becomes resistant against the Corona virus.\n\\end{itemize}", "meta": {"hexsha": "0da4d6a82d98bc85bcaef8c486652d9f09cc9282", "size": 6585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/probabilistic_health_prediction.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/probabilistic_health_prediction.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/probabilistic_health_prediction.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": 59.3243243243, "max_line_length": 672, "alphanum_fraction": 0.7053910402, "num_tokens": 1829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.6859494421679929, "lm_q1q2_score": 0.6117372970270564}}
{"text": "\\section{Differentiation}\r\nUntil further notice, we will just study differentiation of a function $f:I\\to\\mathbb R$ where $I$ is an interval.\r\n\\subsection{The Derivative}\r\n\\begin{definition}\r\n    If $a\\in I$ and we have\r\n    $$\\lim_{x\\to a}\\frac{f(x)-f(a)}{x-a}$$\r\n    exists and equals $c\\in\\mathbb R$, we say $f$ is differentiable at $a$ and the derivative is $f^\\prime(a)=c$.\r\n    Moreover, if $f$ is differentiable at all $a\\in I$, we say $f$ is differentiable.\r\n\\end{definition}\r\nGeometrically $f^\\prime(a)$ is the slope of the tangent line of $f$ at $a$.\\\\\r\nAnother (formal) way to put this is to observe that the definition is essentially $\\forall \\epsilon>0,\\exists\\delta>0$,\r\n$$|x-a|<\\delta\\implies\\left|\\frac{f(x)-f(a)}{x-a}-c\\right|<\\epsilon\\implies |f(x)-f(a)-c(x-a)|<\\epsilon|x-a|$$\r\nAnother way we can write is\r\n$$f^\\prime(a)=\\lim_{h\\to 0}\\frac{f(a+h)-f(a)}{h}$$\r\nwhere $h\\in I-a$.\r\n\\begin{example}\r\n    1. The constant function is differentiable everywhere and has zero derivative everywhere.\\\\\r\n    2. The identity function is differentiable everywhere and has derivative $1$.\\\\\r\n    3. $f:(0,\\infty)\\to\\mathbb R$ by $x\\mapsto 1/x$ is differentiable and has derivative $f^\\prime(a)=-a^{-2}$.\\\\\r\n    4. (non-example) The function $x\\mapsto |x|$ is not differentiable at $0$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Suppose $f$ is differentiable at $a$ with derivative $f^\\prime(a)$ iff\r\n    $$f(a+h)=f(a)+f^\\prime(a)h+\\alpha(h)h$$\r\n    where $\\alpha(0)=0$ and $\\alpha$ is continuous at $0$.\r\n\\end{lemma}\r\nNote that given this formula, then $\\alpha(h)$ is completely deterined by $f$ and $f^\\prime(a)$.\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $f$ is differentiable at $a$ implies $f$ is continuous at $a$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    If $f,g:I\\to\\mathbb R$ are differentiable at some $a\\in I$, so are $f+g,fg$ with derivatives $f^\\prime(a)+g^\\prime(a),f^\\prime(a)g(a)+f(a)g^\\prime(a)$ respectively.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{theorem}[Chain Rule]\r\n    Suppose $f:I_1\\to I_2$ is differentiable at $a\\in I_1$ and $g:I_2\\to\\mathbb R$ is differentiable at $f(a)$, then $(g\\circ f)^\\prime(a)=g^\\prime(f(a))f^\\prime(a)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $b=f(a)$, then by our conditions,\r\n    $$f(a+h)=f(a)+f^\\prime(a)h+\\alpha(h)h,g(b+k)=g(b)+g^\\prime(b)k+\\beta(k)k$$\r\n    And $\\alpha(0)=\\beta(0)=0$ and they are both continuous at $0$.\r\n    Take $k=f(a+h)-f(a)=f^\\prime(a)h+\\alpha(h)h$, so\r\n    \\begin{align*}\r\n        (g\\circ f)(a)&=g(b+k)\\\\\r\n        &=g(b)+g^\\prime(b)k+\\beta(k)k\\\\\r\n        &=g(b)+g^\\prime(b)(f^\\prime(a)h+\\alpha(h)h)+\\beta(f^\\prime(a)h+\\alpha(h)h)(f^\\prime(a)h+\\alpha(h)h)\\\\\r\n        &=(g\\circ f)(a)+g^\\prime(f(a))f^\\prime(a)h+\\phi(h)h\r\n    \\end{align*}\r\n    Where $\\phi(h)=g^\\prime(b)\\alpha(h)+\\beta(f^\\prime(a)h+\\alpha(h)h)(f^\\prime(a)+\\alpha(h))$ which is $0$ at $0$ and is continuous at $0$.\r\n    The chain rule follows.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Suppose $f,g:I\\to\\mathbb R$ are differentiable at $a$ and $g(a)\\neq 0$, then $f/g$ is differentiable at $a$ and $(f/g)^\\prime=(f^\\prime g-fg^\\prime)/g^2$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from the chain rule.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    The polynomial $p(x)=a_0+a_1x+\\cdots+a_nx^n$ is differentiable at all $x\\in\\mathbb R$, and if $p,q$ are polynomials, $p/q$ is differentiable at $a$ when $q(a)\\neq 0$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\subsection{Mean Value Theorem}\r\nSuppose we have some $f:I\\to\\mathbb R$.\r\n\\begin{definition}\r\n    We say some $c\\in I$ is a global maximum of $f$ if $\\forall x\\in I,f(x)\\le f(c)$ and a global minimum if $\\forall x\\in I,f(x)\\ge f(c)$.\r\n\\end{definition}\r\nWe know that if $I$ is a closed bounded interval, then $f$ has global maxima and minima.\r\n\\begin{definition}\r\n    Some $c\\in I$ is called a local maximum of $f$ if $\\exists\\epsilon>0,\\forall x\\in (c-\\epsilon,c+\\epsilon)\\cap I,f(x)\\le f(c)$.\r\n    Similarly it is a local minimum if $\\exists\\epsilon>0,\\forall x\\in (c-\\epsilon,c+\\epsilon)\\cap I,f(x)\\ge f(c)$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    $c\\in I$ is called an interior point of $I$ if $\\exists \\epsilon>0,(c-\\epsilon,c+\\epsilon)\\subset I$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Suppose $f:I\\to\\mathbb R$ and $c$ is an interior point of $I$ where $f$ attains local maximum or local minimum at $c$ and $f$ is differentiable at $c$, then $f^\\prime(c)=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suffice to prove the local maximum case.\r\n    Since $c$ is an interior point of $I$, we can choose $\\epsilon'>0,(c-\\epsilon',c+\\epsilon')\\subset I$.\r\n    As $c$ is a local maximum, then there is some $\\epsilon$ such that $0<\\epsilon\\le\\epsilon'$ and that $\\forall x\\in (c-\\epsilon,c+\\epsilon),f(x)\\le f(c)$.\r\n    We can easily find sequences $(x_n^-)\\in (c-\\epsilon,c),(x_n^+)\\in (c,c+\\epsilon)$ both converging to $c$.\r\n    Let $g:(c-\\epsilon,c+\\epsilon)\\setminus\\{c\\}\\to\\mathbb R$ defined by $g(x)=(f(x)-f(c))/(x-c)$, then\r\n    \\begin{align*}\r\n        0&\\le\\lim_{n\\to\\infty}\\frac{f(x_n^-)-f(c)}{x_n^--c}\\\\\r\n        &=\\lim_{x\\to c^-}g(x)=\\lim_{x\\to c}g(x)=\\lim_{x\\to c^+}g(x)\\\\\r\n        &=\\lim_{n\\to\\infty}\\frac{f(x_n^+)-f(c)}{x_n^+-c} \\le 0\r\n    \\end{align*}\r\n    Hence $f^\\prime(c)=\\lim_{x\\to c}g(x)=0$.\r\n\\end{proof}\r\n\\begin{theorem}[Rolle's Theorem]\r\n    Suppose $f:[a,b]\\to\\mathbb R$ is continuous and is differentiable in $(a,b)$ and $f(a)=f(b)=0$, then there is some $c\\in (a,b)$, $f^\\prime(c)=0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It is obvious if $f\\equiv 0$, otherwise WLOG $f$ attains some positive value.\r\n    Then let $c$ be a global maximum of $f$, then $c$ is a local maximum and an interior point of $f$ (since $f$ is zero on endpoints but we have assumed that $f$ attains some positive value), then $c\\in (a,b)$ and we have $f^\\prime(c)=0$ by the preceding proposition.\r\n\\end{proof}\r\n\\begin{theorem}[Mean Value Theorem]\r\n    If $f:[a,b]\\to\\mathbb R$ is continuous on $[a,b]$ and differentiable on $(a,b)$, then there is some $c\\in (a,b)$ with $f^\\prime(c)=(f(b)-f(a))/(b-a)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let\r\n    $$p(x)=\\frac{1}{b-a}((x-a)f(b)-(x-b)f(a))$$\r\n    which although looks dreadful is just a linear polynomial.\r\n    Note that $p(a)=f(a),p(b)=f(b)$, so it is just a line joining the endpoints.\r\n    Then $g(x)=f(x)-p(x)$ is continuous on $[a,b]$ and differentiable on $(a,b)$, so by Rolle's Theorem, there is some $c\\in (a,b)$ sucb that\r\n    $$0=g^\\prime(c)=f^\\prime(c)-\\frac{f(b)-f(a)}{b-a}\\implies f^\\prime(c)=\\frac{f(b)-f(a)}{b-a}$$\r\n    As desired.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Suppose $f:[a,b]\\to\\mathbb R$ is continuous and differentiable in $(a,b)$.\\\\\r\n    1. $f^\\prime\\equiv 0\\iff f$ is constant.\\\\\r\n    2. $f^\\prime\\ge 0\\iff f$ is increasing.\\\\\r\n    3. $f^\\prime>0\\implies f$ is strictly increasing.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Immediate from Mean Value Theorem.\r\n\\end{proof}\r\nNote that the converse of the third statement is false in general.\r\nE.g, $f(x)=x^3$.\\\\\r\nNote that all these depends on the least upper bound property since we used the Mean Value Theorem which depends on Rolle's Theorem which depends on maximum value theorem which depends on Bolzano-Weierstrass Theorem which depends on the Monotone Sequence Theorem which depends on the least-upper-bound property.\r\n\\subsubsection{Inverse Function Theorem}\r\n\\begin{lemma}\r\n    If $f:[a,b]\\to\\mathbb R$ satisfies $f^\\prime(x)>0$ for all $x\\in [a,b]$, then $f:[a,b]\\to[f(a),f(b)]$ is a bijection.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Injectivity is obvious by Mean Value Theorem.\r\n    For surjectivity we can just exploit Intermediate Value Theorem.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $I$ be an interval.\r\n    Suppose $f:I\\to f(I)$ is a continuous bijection, then $f^{-1}:f(I)\\to I$ is also continuous.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Just check definition.\r\n\\end{proof}\r\n\\begin{theorem}[Inverse Function Theorem]\r\n    Suppose $I\\subset R$ is an interval and $f^\\prime(x)>0$ for any $x\\in I$, then the continuous inverse (exists by the preceding lemmas) $f^{-1}:f(I)\\to I$ is differentiable and $(f^{-1})^\\prime(y)=1/f^\\prime(f^{-1}(y))$.\r\n\\end{theorem}\r\n\\begin{example}\r\n    1. $f:x\\mapsto x^n$ on $(0,\\infty)$ satisfies the conditions, so its inverse $f^{-1}:y\\mapsto y^{1/n}$ has $(f^{-1})^\\prime(y)=(1/n)y^{1/n-1}$.\\\\\r\n    2. Consider $\\tan:(-\\pi/2,\\pi/2)\\to\\mathbb R$, it shall be invertible with differentiable inverse $\\tan^{-1}$, then we can calculate, by the formula, that $(\\tan^{-1})(y)=1/(y^2+1)$\r\n\\end{example}\r\n\\begin{proof}[Proof assuming differentiability]\r\n    Assuming $f^{-1}$ is differentiable, then we know that $f(f^{-1}(y))=y$, then by the chain rule, we get $f^\\prime(f^{-1}(y))(f^{-1})^\\prime(y)=1$, rearrange to give the formula.\r\n\\end{proof}\r\n\\begin{proof}[Actual proof]\r\n    Fix $b\\in f(I)$ and let $a=f^{-1}(b)$.\r\n    Suppose $(y_n)$ is a sequence in $f(I)\\setminus \\{b\\}$ with $y_n\\to b$, and let $x_n=f^{-1}(y_n)$.\r\n    We know that $f$ is differentiable hence continuous, so $f^{-1}$ is continuous by the preceding lemma.\r\n    Therefore $x_n=f^{-1}(y_n)\\to f^{-1}(b)=a$.\r\n    Since we know that\r\n    $$\\lim_{x\\to a}\\frac{f(x)-f(a)}{x-a}=f^\\prime(a)$$\r\n    We have\r\n    $$\\frac{f(x_n)-f(a)}{x_n-a}\\to f^\\prime(a)$$\r\n    By hypothesis, $f^\\prime(a)\\neq 0$, so\r\n    $$\\frac{f^{-1}(y_n)-f^{-1}(b)}{y_n-b}=\\frac{x_n-a}{f(x_n)-f(a)}\\to\\frac{1}{f^\\prime(a)}=\\frac{1}{f^\\prime(f^{-1}(b))}$$\r\n    which is true for every sequence $y_n\\to b$, so the theorem is proved.\r\n\\end{proof}\r\n\\subsubsection{L'H\\^opital's Rule}\r\n\\begin{proposition}[L'H\\^opital's Rule]\r\n    Suppose $f,g:I\\to\\mathbb R$ are differentiable with $f(a)=g(a)=0$, and $\\exists r>0, g(x)\\neq 0\\neq g^\\prime(x)$ for $0<|x-a|<r$.\r\n    Then if $\\lim_{x\\to a}f^\\prime(a)/g^\\prime(a)$ exists and equals $k$, then\r\n    $$\\lim_{x\\to a}\\frac{f(x)}{g(x)}=k$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $x\\in I$ and $x>a$.\r\n    Consider $h(t)=f(t)g(x)-f(x)g(t),t\\in [a,x]$.\r\n    Since $f,g$ are differentiable and we have $h(a)=h(a)=0$, so by Rolle's Theorem, there is some $c\\in (a,x)$ with $f^\\prime(c)g(x)-f(x)g^\\prime(c)=h^\\prime(c)=0$.\r\n    Therefore\r\n    $$\\frac{f^\\prime(c)}{g^\\prime(c)}=\\frac{f(x)}{g(x)}$$\r\n    Same for $x<a$.\\\\\r\n    Given $\\epsilon>0$, choose $\\delta>0$ such that\r\n    $$0<|c-a|<\\delta\\implies\\left|\\frac{f^\\prime(c)}{g^\\prime(c)}-k\\right|<\\epsilon$$\r\n    So when $0<|x-a|<\\delta$, one can find $c$ such that $0<|c-a|<|x-a|<\\delta$ and $f^\\prime(c)/g^\\prime(c)=f(x)/g(x)$, which means that\r\n    $$\\left|\\frac{f(x)}{g(x)}-k\\right|=\\left|\\frac{f^\\prime(c)}{g^\\prime(c)}-k\\right|<\\epsilon$$\r\n    which is as we wanted.\r\n\\end{proof}\r\n\\subsection{Higher Derivatives and Taylor Series}\r\n\\begin{definition}\r\n    We say (inductively) that $f:I\\to\\mathbb R$ is $k$ times differentiable with $k^{th}$ derivative $f^{(k)}$ if $f$ is $(k-1)$ times differentiable with differentiable $(k-1)^{th}$ derivative $f^{(k-1)}$ and $f^{(k-1)})^\\prime=f^{(k)}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    A polynomial is $k$ times differentiable for any $k\\in\\mathbb N$.\r\n\\end{example}\r\n\\begin{definition}\r\n    We say $f$ is $C^k$ if $f$ is $k$ times differentiable and $f^{(k)}$ is continuous.\r\n\\end{definition}\r\n\\begin{example}[Non-example]\r\n    Consider\r\n    $$f(x)=\\begin{cases}\r\n        x^2\\sin(1/x)\\text{, for $x\\neq 0$}\\\\\r\n        0\\text{, for $x=0$}\r\n    \\end{cases}$$\r\n    So one can verify that $f$ is differentiable but the derivative, namely,\r\n    $$f^\\prime(x)=\\begin{cases}\r\n        2x\\sin(1/x)-\\cos(1/x)\\text{, for $x\\neq 0$}\\\\\r\n        0\\text{, for $x=0$}\r\n    \\end{cases}$$\r\n    is not continuous at $0$.\r\n\\end{example}\r\nNow, given $f:I\\to\\mathbb R$, we want a degree $k$ polynomial that best approximates $f$.\r\nThe answer depends on the meaning of ``best''.\r\nWe can either calculate the total squared difference (we have not defined it and will not care about it), but on the other hand, the theory of differentiation hints that\r\n$$f(x)=f(a)+f^\\prime(a)(x-a)=P_1(x)$$\r\nis the best linear approximation of $f$ around $a$.\r\nWhy ``around $a$''?\r\nsay for example we want to approximate $\\sin x$ over a large interval, then the best approximation intuitively might be a line with slope very close to $0$, which is obviously not the tangent at, e.g., $0$.\r\nAnd we are only interested in the best approximation close to $a$.\\\\\r\nNow back to our best linear approximation.\r\nThe reason we say it is the ``best'' in the sense that $f(x)-P_1(h)=\\alpha(h)h$ with $\\alpha(0)=0$ and $\\alpha$ is continuous at $0$.\r\nWe can also easily know that such a $P_1$ is unique so as for such an $\\alpha$ to exist by working out their coefficients by substitution and differentiating (with appropriate comments on differentiability, of course).\r\nMore generally, for a sufficiently smooth $f$, we can try to approximate $f(a+h)=P_k(a+h)+h^k\\alpha(h)$ where $\\alpha(0)=0$ and $\\alpha$ is continuous at $0$ and $P_k$ is a polynomial.\r\nUsing the same trick, such an $P_k$ is unique.\r\nIn particular, we obtain $P_k^{(r)}=f^{(r)}$ for any $r\\le k$.\r\n\\begin{lemma}\r\n    If $a,c_0,c_1,\\ldots,c_k\\in\\mathbb R$, then there is a unique degree $k$ polynomial $P$ with $P^{(i)}(a)=c_i$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write out $P(x)=a_0+a_1(x-a)+\\cdots+a_k(x-a)^k$ and differentiating gives $i!a_i=c_i=P^{(i)}(a)$, so the polynomial is uniquely determined.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Given $f:I\\to\\mathbb R$ which is $k$ times differentiable and $a$ is an interior point of $I$, then the $k^{th}$ Taylor polynomial of $f$ centered at $a$ is\r\n    $$P_k(x)=\\sum_{i=0}^k\\frac{f^{(i)}(a)}{i!}(x-a)^i$$\r\n    which is chosen such that $P_k^{(i)}(a)=f^{(i)}(a)$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    $P_k(x)$ is the unique polynomial with degree at most $k$ having the property $P_k^{(i)}(a)=f^{(i)}(a)$ by the preceding lemma.\r\n\\end{remark}\r\n\\begin{theorem}[Taylor's Theorem with Remainder]\r\n    Suppose $f:I\\to\\mathbb R$ is $(k+1)$ times differentiable, and $[a,x]\\subset I$, then\r\n    $$f(x)=\\left(\\sum_{i=0}^k\\frac{f^{(i)}(a)}{i!}(x-a)^i\\right)+\\frac{f^{(k+1)}(c)}{(k+1)!}(x-a)^{k+1}$$\r\n    for some $c\\in (a,x)$.\r\n\\end{theorem}\r\nFor $k=0$, this reduces to the mean value theorem.\r\n\\begin{proof}\r\n    Fix $x>a$ and define\r\n    $$g(t)=f(t)+\\sum_{i=1}^k\\frac{f^{(i)}(t)}{i!}(x-t)^i+\\alpha\\frac{(x-t)^{k+1}}{(k+1)!}$$\r\n    where $\\alpha$ is chosen such that $g(a)=f(x)$ (which exists as a solution to a nondegenerate linear equation).\r\n    Our goal is to find $c\\in (a,x)$ such that $f^{(k+1)}(c)=\\alpha$.\r\n    We have, by definition,\r\n    $$f(x)=g(a)=f(a)+\\sum_{i=1}^k\\frac{f^{(i)}(a)}{i!}(x-a)^i+\\alpha\\frac{(x-a)^{k+1}}{(k+1)!}$$\r\n    Now $f$ is $k+1$ times differentiable so $g$ is differentiable and $g(a)=f(x)=g(x)$, so by Rolle's Theorem, there is some $c\\in (a,x)$ such that $g^\\prime(c)=0$.\r\n    But we have\r\n    $$g^\\prime(t)=f^\\prime(t)+\\sum_{i=1}^k\\left(\\frac{f^{(i+1)}(t)}{i!}(x-t)^i-\\frac{f^{(i)}(t)}{(i-1)!}(x-t)^{i-1}\\right)-\\alpha\\frac{(x-t)^k}{k!}$$\r\n    The first part of this expression is telescoping, so we can simplify it to\r\n    $$g^\\prime(t)=(f^{(k+1)}(t)-\\alpha)\\frac{(x-t)^k}{k!}$$\r\n    Now plugging in $t=c$ shows $f^{(k+1)}(c)=\\alpha$, which completes the proof.\r\n\\end{proof}\r\nIf $f$ is infinitely differentiable, one can then form the Taylor series\r\n$$\\sum_{i=0}^\\infty\\frac{f^{(i)}(a)}{i!}(x-a)^i$$\r\nas the formal limit of the Taylor polynomilas $P_k(x)$, which sometimes does converge and equals $f$.\r\nIf we understand the derivatives of $f$ well-enough and that those derivatives do behave nicely, then it is sometimes possible to use Taylor's Theorem to prove that\r\n$$p(x)=\\lim_{n\\to\\infty}P_n(x)=f(x)$$\r\n\\begin{example}\r\n    Take $f(x)=\\cos x$ (which, albeit hasn't been properly defined, we shall assume standard facts about), then the Taylor series about $0$ is\r\n    $$1-\\frac{x^2}{2!}+\\frac{x^4}{4!}-\\frac{x^6}{6!}+\\cdots=\\sum_{n=0}^\\infty(-1)^n\\frac{x^{2n}}{(2n)!}$$\r\n    The series always converges by the ratio test.\r\n    Must the series converges to $\\cos x$ then?\r\n    The $(2k)^{th}$ partial sum of the series is exactly $P_{2k}(x)$ of $\\cos$ about $0$, then there is $c\\in (0,x)$ with\r\n    $$|f(x)-P_{2k}(x)|=\\left|\\frac{f^{2k+1}(c)}{(2k+1)!}x^{2k+1}\\right|\\le\\frac{|x|^{2k+1}}{(2k+1)!}\\to 0$$\r\n    as $k\\to\\infty$, so the series does converge to $\\cos x$.\r\n\\end{example}\r\n\\begin{definition}\r\n    We say $f:I\\to\\mathbb R$ is $C^\\infty$ (or smooth) if $f$ is $C^k$ for all $k\\in\\mathbb N$.\r\n\\end{definition}\r\nSo for a smooth $f:I\\to\\mathbb R$, one can form the Taylor series (formally)\r\n$$\\sum_{n=0}^\\infty\\frac{f^{(n)}(a)}{n!}(x-a)^n$$\r\nBut even if the series converges for all $x\\in I$, it may not converge to $f(x)$ for $x\\neq a$.\r\nPhilosophically, one cannot fully expect that the behaviour of $f$ near $a$ control its global behaviour.\r\n\\footnote{For complex-valued functions, however, the local behaviour of a nice enough function $f$ can be controlled by its local properties.}\r\nIndeed, for $f_1,f_2:\\mathbb R\\to\\mathbb R$ smooth and $a<b$, it is possible to construct some smooth $f:\\mathbb R\\to\\mathbb R$ such that $f|_{<a}=f_1|_{<a}$ and $f|_{>b}=f_2|_{>b}$.\r\nThis will be proven in example sheet.\r\n\\subsection{Complex Differentiation}\r\n\\begin{definition}\r\n    If $c\\in\\mathbb C,r\\in[0,\\infty)$, we define the open ball of radius $r$ centered at $c$ by $B_r(c)=\\{z\\in\\mathbb C:|z-c|<r\\}$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A subset $\\Omega\\subset\\mathbb C$ is open if $\\forall c\\in\\Omega,\\exists\\epsilon>0,B_\\epsilon(c)\\subset\\Omega$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $\\mathbb C,\\varnothing$ are open.\\\\\r\n    2. Open balls are open.\\\\\r\n    3. (non-example) $\\{z\\in\\mathbb C:|z-a|\\le r\\}$ is not open, but its complement is.\r\n\\end{example}\r\n\\begin{definition}\r\n    Suppose $\\Omega\\in\\mathbb C$ is open and $c\\in\\Omega$.\r\n    For a function $f:\\Omega\\to\\mathbb C$, we say $f$ is complex differentiable at $c$ if\r\n    $$\\lim_{z\\to c}\\frac{f(z)-f(c)}{z-c}$$\r\n    exists.\r\n    In case it does exist, we write it as $f^\\prime(c)$.\r\n\\end{definition}\r\nAll the rules in real differentiation still applies, but we don't really have mean value theorem.\r\nWe can write $f(x+iy)=u(x,y)+iv(x,y)$ where $u,v:\\tilde{\\Omega}\\to\\mathbb R$ where $\\tilde{\\Omega}=\\{(x,y)\\in\\mathbb R^2:x+iy\\in\\Omega\\}$.\r\n\\begin{definition}\r\n    Say $\\tilde{\\Omega}$ is open if $\\Omega$ is.\r\n    Then the partial derivatives of $F:\\tilde{\\Omega}\\to\\mathbb R$ at $(a,b)\\in\\tilde{\\Omega}$ are\r\n    \\begin{align*}\r\n        \\left.\\frac{\\partial F}{\\partial x}\\right|_{(a,b)}&=\\lim_{h\\to 0}\\frac{F(a+h,b)-F(a,b)}{h}\\\\\r\n        \\left.\\frac{\\partial F}{\\partial y}\\right|_{(a,b)}&=\\lim_{h\\to 0}\\frac{F(a,b+h)-F(a,b)}{h}\r\n    \\end{align*}\r\n    Provided that they exist.\r\n\\end{definition}\r\nAlternatively we can define $g_b=F(x,b)$ and so\r\n$$\\left.\\frac{\\partial F}{\\partial x}\\right|_{(a,b)}=g^\\prime_b(a)$$\r\nSimilar for the other component.\r\n\\begin{proposition}\r\n    If $f:\\Omega\\to\\mathbb C$ is complex differentiable at $c=a+ib$ with derivative $f^\\prime(c)=\\alpha+i\\beta$, then the partial derivatives of $u,v$ at $(a,b)$ exist and satisfy\r\n    \\begin{align*}\r\n        \\left.\\frac{\\partial u}{\\partial x}\\right|_{(a,b}&= \\left.\\frac{\\partial v}{\\partial y}\\right|_{(a,b)}=\\alpha\\\\\r\n        -\\left.\\frac{\\partial u}{\\partial y}\\right|_{(a,b}&=\\left.\\frac{\\partial v}{\\partial x}\\right|_{(a,b)}=\\beta\r\n    \\end{align*}\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For any sequence $h_n\\to 0$ in $\\mathbb R\\setminus\\{0\\}$, then it is also a sequence in $\\mathbb C\\setminus\\{0\\}$, so since $f$ is differentiable at $c$,\r\n    \\begin{align*}\r\n        \\alpha+i\\beta&=f^\\prime(c)\\\\\r\n        &=\\lim_{h\\to 0}\\frac{f(c+h)-f(c)}{h}\\\\\r\n        &=\\lim_{n\\to\\infty}\\frac{u(a+h_n,b)-u(a,b)}{h_n}+i\\lim_{n\\to\\infty}\\frac{v(a+h_n,b)-v(a,b)}{h_n}\r\n    \\end{align*}\r\n    So $\\partial u/\\partial x$ and $\\partial v/\\partial x$ exist and are $\\alpha,\\beta$ respectively.\r\n    We can get the other half of the equations by replacing $h_n$ by $ih_n$ and casting exactly the same argument.\r\n\\end{proof}\r\n\\begin{remark}\r\n    If $f:\\Omega\\to\\mathbb C$ is complex differentiable, then (assuming $C^1$ partial derivatives and symmetry of partial derivatives)\r\n    $$\\frac{\\partial^2u}{\\partial x^2}+\\frac{\\partial^2u}{\\partial y^2}=0$$\r\n    which is the Laplace Equation.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Suppose $F:B_r((a,b))\\to\\mathbb R$ has partial derivatives with\r\n    $$\\frac{\\partial F}{\\partial x}=\\frac{\\partial F}{\\partial y}=0$$\r\n    then $F$ is constant.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For $(a',b')\\in B_r((a,b))$, we consider the functions $f_b(x)=F(x,b)$ and $f_a(x)=F(a',x)$ on the reals.\r\n    Then they are differentiable and using mean value theorem on $f_b$ wrt $a,a'$ shows $f(a,b)=f(a',b)$, and using it again on $f_a$ wrt $b,b'$ shows $f(a',b)=f(a',b')$, so $f(a,b)=f(a',b')$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f:B_r(c)\\to\\mathbb C$ has derivative zero, then $f$ is constant.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Complex differentiable functions $f:\\mathbb C\\to\\mathbb C$ behave very nicely.\r\n    Firstly, if $f$ is complex differentiable, so is $f^\\prime$, consequently $f$ is $C^\\infty$.\r\n    Even better, its Taylor series always converges to itself.\r\n    Secondly, if $f$ is bounded then $f$ is constant.\r\n\\end{remark}", "meta": {"hexsha": "c8c1fb8c7d13f8ea747d860d2f1c22d439eaa377", "size": 21326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/diff.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": "4/diff.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": "4/diff.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": 59.4038997214, "max_line_length": 312, "alphanum_fraction": 0.6305448748, "num_tokens": 7541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.6117144903533008}}
{"text": "\\section{Notation}\n\nA Markov decision process (MDP) $\\mdp$ consists of a tuple $(\\mathcal{S}, \\mathcal{A}, P, R, \\gamma, s_0)$, where $\\mathcal{S}$ is the state space, $\\mathcal{A}$ is the action space, $P$ is the transition function mapping $\\mathcal{S} \\times \\mathcal{A}$ to distributions on $\\mathcal{S}$, $R$ is the scalar reward function on $\\mathcal{S} \\times \\mathcal{A}$, $\\gamma$ is the discount factor, and $s_0$ is the starting state.\nNote that a single start state can be converted to a start distribution by letting $P(s_0, \\cdot)$ be independent of the action taken.\n% This work focuses on the episodic setting, where after some number of steps $T$\nAn \\emph{agent} interacts with an MDP by producing a policy $\\pi$ at each timestep and observing the transitions it visits.\n\nThe \\emph{value} of a state $s$ for a policy $\\pi$ is the (discounted) sum of future rewards obtained by running that policy starting from the state $s$:\n\\begin{align}\n    V^{\\pi}(s) = \\E_{\\substack{a_t \\sim \\pi(\\cdot \\mid s_t) \\\\ s_{t+1} \\sim P(s_t, a_t)}} \\sum_{t=0}^\\infty \\gamma^t R(s_t, a_t) ~\\big|~ s_0=s\n\\end{align}\nSimilarly the value of a state-action pair $(s, a)$ is written as\n\\begin{align}\n    Q^{\\pi}(s, a) = \\E_{\\substack{a_t \\sim \\pi(\\cdot \\mid s_t) \\\\ s_{t+1} \\sim P(s_t, a_t)}} \\sum_{t=0}^\\infty \\gamma^t R(s_t, a_t) ~\\big|~ s_0=s, a_0 = a\n\\end{align}\nAny MDP admits a deterministic optimal policy $\\pi^*$ with corresponding value functions $V^*$ and $Q^*$ such that $V^*(s) \\ge V^\\pi(s)$ for all $s$ and $\\pi$ \\citep{sutton2018reinforcement}.\n\n\n\\section{Discounting and Resets}\n\nWhen $\\gamma < 1$ we say that the setting is \\emph{discounted}, and for $\\gamma = 1$ we say that it is \\emph{undiscounted}.\nAn environment may have a time limit $T$ such that after every $T$ steps, the state is reset to $s_0$.\nIn this case we call it \\emph{episodic}.\nTo satisfy the Markov property, episodic environments should include the current timestep $t$ in the state.\n\nFor episodic environments, it is natural to define a policy's quality in terms of the total reward earned (on average) in a single episode, with discounted environments preferring rewards obtained earlier in the episode.\nFor non-episodic environments comparisons between policies are less clear-cut; see Section 2 of \\citet{strehl2008analysis} for a discussion.\n\nCommon practice in deep reinforcement learning is to train agents with discounting and resets, but not include the timestep in the state observations and simply ignore the transition from $s_T$ to $s_0$.\nPolicies are typically evaluated by the total undiscounted reward in an episode, despite the conflict with the training setup.\nIn most cases the rewards are truncated to reflect the limited episode duration \\citep{schulman2017proximal,Fujimoto2018AddressingFA,haarnoja2018soft}.\nSince the agent is unable to tell when an episode will end, this effectively introduces noise into value prediction targets, and this noise varies by state depending on how often the agent has ended an episode on that state.\nIn other cases value targets may be bootstrapped from the state $s_T$ as if the environment were not episodic.\nThis has two issues: (1) it introduces bias by treating an estimate of $V(s_T)$ as the true value, when in some states and environments this estimate may never be updated; and (2) by pretending the environment has no resets, it introduces a mismatch between the training and test objectives.\\endnote{This mismatch is decreased if the divergence between the distributions $P(s_T, \\pi(\\cdot \\mid s_T))$ and $s_0$ is smaller. Like most problems in RL, it also becomes smaller if smaller discount factors are used. However in general there are actions which would provide more short-term reward, and thus perform better toward the end of an episode, than the infinite-horizon optimal actions.}\nHowever, it does not introduce noise.\n\nMore fundamentally, practically all discounted policy gradient algorithms drop the discounting term from the state distribution.\n\\citet{Nota2020IsTP} show that this results in following a direction which is not the gradient of any function, and which is not guaranteed to converge to a good solution with respect to the discounted or undiscounted objectives.\nWhile this is deeply worrying, these methods frequently work well in practice.\nThis may be due to their usage with overparameterized neural network models, which are largely invariant to a reweighting of the data \\citep{byrd2018effect,brandfonbrener2021offlinecontextual}.\n\n% This thesis focuses on the episodic setting.\n% Following common practice in deep reinforcement learning, agents are trained with algorithms which use $\\gamma < 1$, but evaluated according to the total reward earned in an episode.\n\n\n\\section{Defining Sample Complexity}\n\nWe say that a policy $\\pi$ is $\\varepsilon$-optimal if $V^*(s_0) \\le V^\\pi(s_0) + \\varepsilon$.\nDefine $\\bm{\\pi} = A(\\mdp, i)$ to be the policy obtained by running the agent (i.e. algorithm) $A$ in the environment $\\mdp$ for $i$ timesteps, being careful to note that the policy $\\bm{\\pi}$ is itself a random variable due to the randomness in the experience collected in those $i$ steps.\nLet the \\emph{sample complexity} of learning a $\\varepsilon$-optimal policy on $\\mdp$ with $A$ be the expected number of steps (indexed as $i$) such that\n\\begin{align}\n    V^{\\pi_i}(s_0) < V^*(s_0) - \\varepsilon, && \\text{where } \\pi_i = A(\\mdp, i).\n\\end{align}\nThis definition is related to those proposed by \\citet{Fiechter1994EfficientRL} and \\citet{strehl2008analysis} for PAC learning.\nSometimes it is also useful to consider the \"anytime\" performance of an algorithm $A$ on an MDP $\\mdp$.\nAn algorithm $A_1$ would dominate $A_2$ if $\\forall i$, $V^{A_1(\\mdp, i)}(s_0) \\ge V^{A_2(\\mdp, i)}(s_0)$.\n\n\n\n\\section{Online and Deployment Settings} \\label{sec:regret-deployment}\n\nWhile the overall MDP framework is largely shared in the community, several different objectives for a learning agent are commonly studied.\nThe online and offline settings are perhaps the most studied in the theory community, but the \"learn-and-deploy\" setting has the most relevance for present applications of RL.\n\n\n\\paragraph{The online setting.}\n% \\side{talk about sample complexity}\nHere an RL agent learns by continually interacting with the environment with the goal of maximizing the total reward earned across all time.\nThis gives rise to the explore-exploit tradeoff when acting: at each moment, the agent may choose to take an action which is uninformative but leads to greater short-term reward, or one which will yield more information at the cost of lower reward.\nThe objective for this setting is to minimize the rate of accumulation of \\emph{regret}, which measures the difference between the total reward obtained by an optimal policy and the agent:\n\\begin{align}\n    L(A, \\mdp, T) = \\E \\left[ \\sum_{i=1}^T R(s^*_i, a^*_i) - R(s_i, a_i) \\right].\n\\end{align}\nThis setting is appropriate when an agent is being trained \"on the job,\" where mistakes early in learning have just as much deleterious effect as those made later.\nIn this context, sample efficiency controls the total amount of regret the agent will accumulate.\n\n\\paragraph{The learn-and-deploy setting.}\n% \\side{talk about sample complexity}\nThis setting consists of distinct learning and deployment phases.\nIn the learning phase, the agent is not required to perform well and may collect whatever data is most informative.\nIn the deployment phase, the policy is fixed and should be as close to optimal as possible.\nNote that the policy produced at the end of the training procedure need bear no resemblance to those used to collect data.\nFor episodic environments, with a training period consisting of $N$ steps we can write the this objective as\n\\begin{align}\n    L(A, \\mdp, N) = V^*(s_0) - V^{\\pi_N}(s_0), && \\text{where } \\pi_N = A(\\mdp, N)\n\\end{align}\nHistorically this setting has not been much discussed, though it is analagous to the task of best-arm identification in bandits \\citep{Russo2016SimpleBA,Kaufmann2016OnTC}.\nIt is also related to the iterative technique of fitted Q iteration \\citep{Ernst2005TreeBasedBM,Riedmiller2005NeuralFQ}.\n\nCrucially, this setting is the one used in practice in nearly every application of reinforcement learning.\nRL algorithms are not yet safe and reliable enough to allow them to update a policy on the fly, especially with a physical system which may be damaged or cause injury.\nFurthermore, most works studying RL implicitly provide results in this setting by evaluating according to a different policy than the one used for training, for example showing learning curves with a deterministic policy \\citep{Mnih2015HumanlevelCT,Lillicrap2016ContinuousCW,Fujimoto2018AddressingFA,haarnoja2018soft}.\nComparisons of final, large-data performance similarly reflect this setting \\citep{Silver2016MasteringTG,Vinyals2019GrandmasterLI,openai2019dota,OpenAI2019SolvingRC}.\n\nIn this setting, sample efficiency reflects the amount of data the agent needs to collect during training time before it can perform near-optimally at deployment time.\n\n\n\\paragraph{The offline setting.}\n% \\side{talk about sample complexity}\nAlso known as the \\emph{batch} setting, this consists only of pure policy optimization given a fixed dataset of environment interactions collected by an extrinsic behavior policy.\nAfter learning from this data in whatever way it sees fit, an algorithm produces a fixed policy with the objective of earning as much reward as possible.\nThough described as a reinforcement learning setting, it does not include any actual reinforcement as the agent never learns from its own interactions with the environment.\nHowever, this makes the offline RL setting uniquely valuable for isolating how much can be learned from particular data.\nThis setting is also appealing as it would in principle allow an agent to be trained in a risk-free way by using data collected from a safe policy, and for free (in terms of samples) if data from one experiment can be repurposed as training data for another.\\endnote{While there are doubtless some settings where this cross-task data reuse is possible, it has quite clear limits. For a policy to be trained to solve task B using data collected from task A, the policy used for task A would have had to actually also solve task B. It could have been done piecewise rather than in a single good trajectory, but unless the tasks are extremely similar it is vanishingly unlikely. Perhaps a more practical application would be to start with a safe but poor policy for solving a task, then incrementally collect new data, refine the policy using offline RL, validate that the new policy is also safe, and then collect data once more.}\nFor this setting, sample efficiency must be redefined to include the behavior policy under which the data was collected.\nIt then reflects the minimum amount of data collected under that behavior policy required for a particular algorithm to recover the optimal policy.\\endnote{Note that this quantity of data should be expected to be extraordinarily large for most behavior policies.}\n\n% \\side{break into \\textbackslash paragraphs}\n% \\side{write math definitions}\n% \\side{write sample complexity definitions}\n% \\begin{itemize}\n%     \\item The \\emph{online} or \\emph{regret} setting.\n\n%     \\item The \\emph{learn-and-deploy} setting.\n%     \\side{Need a better name for learn-and-deploy}\n%     This setting consists of distinct learning and deployment phases. In the learning phase, the agent is not required to perform well and may collect whatever data is most informative. In the deployment phase, the policy is fixed and should be as close to optimal as possible. This setting schematically breaks down into pure data collection followed by pure policy optimization, though in practice policy optimization is an essential tool during exploration.\n%     \\item The \\emph{offline} or \\emph{batch} setting.\n%     This consists only of pure policy optimization given a fixed dataset of environment interactions collected by an extrinsic behavior policy. After learning from this data in whatever way it sees fit, an algorithm produces a fixed policy with the objective of earning as much reward as possible. Though described as a reinforcement learning setting, it does not include any actual reinforcement as the agent never learns from its own interactions with the environment. However, this makes the offline RL setting uniquely valuable for isolating how much can be learned from particular data.\n% \\end{itemize}\n\n\n% \\side{Do I want a section on simulated versus physical envs?}\n% \\section{Simulated and Physical Environments}\n\n\n\\printendnotes", "meta": {"hexsha": "9f746d297fc8d754de12f66a6daa1d5fe5ab1249", "size": 12676, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/rl-setting.tex", "max_stars_repo_name": "willwhitney/dissertation", "max_stars_repo_head_hexsha": "a9842f84e53ca47ec849488b6cb9acb8a11336ef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-20T20:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-20T20:31:06.000Z", "max_issues_repo_path": "content/rl-setting.tex", "max_issues_repo_name": "willwhitney/doctoral-thesis", "max_issues_repo_head_hexsha": "a9842f84e53ca47ec849488b6cb9acb8a11336ef", "max_issues_repo_licenses": ["MIT"], "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/rl-setting.tex", "max_forks_repo_name": "willwhitney/doctoral-thesis", "max_forks_repo_head_hexsha": "a9842f84e53ca47ec849488b6cb9acb8a11336ef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-25T13:01:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-25T13:01:43.000Z", "avg_line_length": 100.6031746032, "max_line_length": 928, "alphanum_fraction": 0.7808456926, "num_tokens": 3050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6117144867604812}}
{"text": "\\documentclass{article}\n\n\\usepackage{blindtext}\n\\usepackage{multicol}\n\\usepackage{caption}\n\\usepackage{bm}\n\\usepackage{tikz}\n\\usepackage{pgfplots}\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,\n    urlcolor=cyan,\n}\n\\usepackage{geometry}\n\\geometry{\n\ta4paper,\n\tnoheadfoot=true,\n\tleft=1.0in,\n\tright=1.0in,\n\ttop=1.0in,\n\tbottom=1.0in\n}\n\n% url package\n\\usepackage{hyperref}\n\\usepackage{subcaption}\n\n% Titling and Author\n\\title{Latex Tikz Examples, Annotate on Graph}\n\\author{\\href{https://fanwangecon.github.io/}{Fan Wang}\\thanks{https://fanwangecon.github.io, repository: \\href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Annotate Text in Figure}\n\n\\subsection{Slope and Intercept Annotate}\n\nDraw axis below, and a line, middle of page, and annotate the slope of the intercept with arrows. Annotate with box without color.\n\n\\begin{verbatim}\n\\begin{center}\n\\begin{tikzpicture}\n\\draw (0,2) -- (0.25*\\textwidth,2);\n\\draw (0,1) -- (0.5*\\textwidth,1);\n\\end{tikzpicture}\n\\end{center}\n\\end{verbatim}\n\\bigskip\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[->] (-1,0) -- (6,0) node[right] {$N_m$};\n\\draw[->] (0,-1) -- (0,6) node[above] {$N_{m^{\\prime}}$};\n\n% A. Clip area so that line below is only drawn inside finite box\n\\clip (-3,-1) rectangle (6,6);\n\n% B. Draw a line with intercept and slope\n\\draw[line width=0.50mm,domain=-1:6,smooth,variable=\\x, blue] plot ({\\x},{1+\\x*1.25});\n\n% C. Draw Line pointing to Intercept of line\n\\draw[->, line width=0.75mm] (-1.7,2.2) -- (-0.1,1.1);\n\n% D. Draw a transparent text box that wraps text\n\\node[text width=3cm] at (-1.4,3.25) {\\large{$\\bm{\\alpha_i}$ (this is the position of the \\textbf{x-intercept}), wrap text.}};\n\n\\end{tikzpicture}\n\\end{center}\n\n\\subsection{Anote Slope, X intercept and Y intercept}\n\nDraw a line, then point to its slope, x and y intercepts.\n\n\\begin{enumerate}\n  \\item Define the slope and y-intercept: $a_i, b_i$\n  \\item Define and calculate the x-intercept: $c_i = -\\frac{a_i}{b_i}$\n  \\item Define the text that should appear for each element: $a_{desca}$\n  \\item Drawing lines pointing to $a$, $b$ or $c$ points:\n  \\begin{itemize}\n    \\item direction: $d_i \\in \\left\\{NE, SE, SW, NW\\right\\}$\n    \\item rotation: $0 <= e_i <= 90$, which direction points to text\n    \\item dist one: $f_i > 0 $, straight distance from origin\n    \\item dist two: $g_i > 0 $, distance of line\n    \\item point start: $h^o_i, h^o_i$, starting point based on the four pieces of information\n    \\item point end: $h^d_i, h^d_i$, ending point based on the four pieces of information\n  \\end{itemize}\n\\end{enumerate}\n\nSo end up drawing using $a$, $b$ for line, $h^o$ for one point $h*d$ line small segment.\n\n\\begin{verbatim}\n\\end{verbatim}\n\\bigskip\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[->] (-1,0) -- (6,0) node[right] {$N_m$};\n\\draw[->] (0,-1) -- (0,6) node[above] {$N_{m^{\\prime}}$};\n\n% A. Clip area so that line below is only drawn inside finite box\n\\clip (-3,-1) rectangle (6,6);\n\n% B. Draw a line with intercept and slope\n\\draw[line width=0.50mm,domain=-1:6,smooth,variable=\\x, blue] plot ({\\x},{1+\\x*1.25});\n\n% C. Draw Line pointing to Intercept of line\n\\draw[->, line width=0.75mm] (-1.7,2.2) -- (-0.1,1.1);\n\n% D. Draw a transparent text box that wraps text\n\\node[text width=3cm] at (-1.4,3.25) {\\large{$\\bm{\\alpha_i}$ (this is the position of the \\textbf{x-intercept}), wrap text.}};\n\n\\end{tikzpicture}\n\\end{center}\n\n\n\\end{document}\n", "meta": {"hexsha": "163280efad5e45a01e3dace87976dda041a09566", "size": 3479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_other/tikz/annotate/fs_tikz_annotate.tex", "max_stars_repo_name": "guohui-jiang/Tex4Econ", "max_stars_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_other/tikz/annotate/fs_tikz_annotate.tex", "max_issues_repo_name": "guohui-jiang/Tex4Econ", "max_issues_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_other/tikz/annotate/fs_tikz_annotate.tex", "max_forks_repo_name": "guohui-jiang/Tex4Econ", "max_forks_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_forks_repo_licenses": ["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.9916666667, "max_line_length": 164, "alphanum_fraction": 0.6812302386, "num_tokens": 1207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6117144817447254}}
{"text": "\\section{Current Operator in Landau Levels}\n\nNow consider about the current density operator for $N$th Landau level. Since we have already found the extact solution for our time depenedent Hamiltonian and we have identify them as Floquet states with quesi energies. From these solutions we can identify the \\textit{Floquet modes} as given in Eq. \\eqref{3.15} and using quantum numbers we can represent those states as follows\n\\begin{equation} \\label{6.1}\n  \\ket{\\phi_{\\alpha}} = \\ket{\\phi_{n,m}} \\equiv \\ket{n,k_x} \\quad\n  \\text{where} \\quad\n  k_x = m \\frac{2\\pi}{L_x}\n\\end{equation}\nUsing above complete set of eigenstates of Floquet Hamiltonian we can represent the single particle current operator's matrix element as\n\\begin{equation} \\label{6.2}\n  \\qty(\\mb{j})_{nm,n'm'} = \\mel{n,k_x}{\\;\\hat{\\mb{j}}\\;}{n',k'_x}\n\\end{equation}\nwhere particle current operator for this system will be\n\\begin{equation} \\label{6.3}\n  \\hat{\\mb{j}} = \\frac{1}{m} \\qty(\\hat{\\mb{P}} - e\\qty[\\mb{A}_s + \\mb{A}_d(t)]).\n\\end{equation}\nLet's consider the transverse conductivity in $x$ direction and we can identify that $x$ directional current operator as\n\\begin{equation} \\label{6.4}\n  \\hat{j}_x = \\frac{1}{m} \\qty(-i\\hbar\\pdv{x} + eBy).\n\\end{equation}\nNow we can calculate the matrix elements of $x$ directional current operator's matrix in Floquet mode basis as\n\\begin{equation} \\label{6.5}\n  \\qty({j}_x)_{nm,n'm'} = \\mel{n,k_x}{\\;\\hat{j}_x\\;}{n',k'_x} =\n  \\mel{n,k_x}{\\;\\frac{1}{m} \\qty(-i\\hbar\\pdv{x} + eBy)\\;}{n',k'_x}\n\\end{equation}\nand we can evaluate these using Floquet modes derived in Eq.\\eqref{3.15} as follows\n\\begin{equation} \\label{6.6}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\int dx \\int dy \\;\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 - \\zeta(t)\\big)\n    \\exp(-ik_x x) \\\\\n    & \\times\n    \\frac{1}{m} \\qty(-i\\hbar\\pdv{x} + eBy)\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n'}\\big(y - y_0 - \\zeta(t)\\big)\n    \\exp(i k'_x x)\n  \\end{aligned}\n\\end{equation}\nand this can be simplified as\n\\begin{equation} \\label{6.7}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\frac{1}{{mL_x}}\n    \\int dx \\exp(-i(k_x-k'_x) x)\n    \\int dy \\;\n     \\chi_{n}\\big(y - y_0 - \\zeta(t)\\big) \\\\\n    & \\times\n    \\qty(\\hbar k'_x + eBy)\n    \\chi_{n'}\\big(y - y_0 - \\zeta(t)\\big)\n  \\end{aligned}\n\\end{equation}\nand\n\\begin{equation} \\label{6.8}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\int dy \\;\n    \\qty(\\hbar k'_x + eBy)\n     \\chi_{n}\\big(y - y_0 - \\zeta(t)\\big)\n    \\chi_{n'}\\big(y - y_0 - \\zeta(t)\\big).\n  \\end{aligned}\n\\end{equation}\nNow let $y - y_0 - \\zeta(t) = \\bar{y}$ and we will get\n\\begin{equation} \\label{6.9}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\int d\\bar{y} \\;\n    \\qty(\\hbar k'_x + eB\\bar{y} + eBy_0 + eB\\zeta(t))\n     \\chi_{n}(\\bar{y})\n    \\chi_{n'}(\\bar{y}).\n  \\end{aligned}\n\\end{equation}\nusing definition of $y_0$ given in Eq. \\eqref{1.11} this will be modiofied to\n\\begin{equation} \\label{6.10}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\int d\\bar{y} \\;\n    \\qty(\\hbar k'_x + eB\\bar{y} -\\hbar k'_x + eB\\zeta(t))\n     \\chi_{n}(\\bar{y})\n    \\chi_{n'}(\\bar{y})\n  \\end{aligned}\n\\end{equation}\nand using integral indentities of Gauss-Hermite functions\n\\begin{equation} \\label{6.11}\n    \\int d{y} \\;\n    \\chi_{n}({y})\n    \\chi_{n'}({y}) =\n    \\delta_{n',n}\n\\end{equation}\n\\begin{equation} \\label{6.12}\n    \\int dy \\;\n    y\n    \\chi_{n}({y})\n    \\chi_{n'}({y}) =\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n',n-1})\n\\end{equation}\nthis becomes\n\\begin{equation} \\label{6.13}\n  \\begin{aligned}\n    \\qty({j}_x)_{nm,n'm'} & =\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    eB\n    \\qty[\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n',n-1})\n    + \\zeta(t) \\delta_{n',n}\n    ]\n  \\end{aligned}\n\\end{equation}\n\\textcolor{red}{Due to complexity we can only consider the constant contribution and we allows only the one-cycle averaged current flow} and then we can derive the $s=0$ components of the Fourier series as\n\\begin{equation} \\label{6.14}\n  \\begin{aligned}\n    \\qty({j}^x_{s=0})_{nm,n'm'} & =\n    \\frac{1}{T} \\int_0^T dt \\;\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    eB\n    \\qty[\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n',n-1})\n    + \\frac{eE}{m(\\omega_0^2 - \\omega^2)}\\sin(\\omega t) \\delta_{n',n}\n    ]\n  \\end{aligned}\n\\end{equation}\nand this can be evaluate and get\n\\begin{equation} \\label{6.15}\n  \\begin{aligned}\n    \\qty({j}^x_{s=0})_{nm,n'm'} & =\n    \\frac{eB}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n',n-1})\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nFor electric current operator we can introduce the electron's charge and effective mass\n\\begin{equation} \\label{6.16}\n  \\begin{aligned}\n    \\qty({j}^x_{s=0})_{nm,n'm'} & =\n    \\frac{e^2B}{{m_e}}\n    \\delta_{k_x,k'_x}\n    \\qty(\\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1} + \\sqrt{\\frac{n}{2}}\n    \\delta_{n',n-1})\n  \\end{aligned}\n\\end{equation}\n\\hfill$\\blacksquare$\n\n\\noindent\nNext we can consider the transverse conductivity in $y$ direction and we can identify that $y$ directional current operator as\n\\begin{equation} \\label{6.17}\n  \\hat{j}_y = \\frac{1}{m} \\qty(-i\\hbar\\pdv{y} - \\frac{eE}{\\omega}\\cos(\\omega t)).\n\\end{equation}\nNow we can calculate the matrix elements of $y$ directional current operator's matrix in Floquet mode basis as\n\\begin{equation} \\label{6.18}\n  \\qty({j}_y)_{nm,n'm'} = \\mel{n,k_x}{\\;\\hat{j}_y\\;}{n',k'_x} =\n  \\mel{n,k_x}{\\;\\frac{-1}{m} \\qty(i\\hbar\\pdv{y} + \\frac{eE}{\\omega}\\cos(\\omega t))\\;}{n',k'_x}\n\\end{equation}\nand we can evaluate these using Floquet modes derived in Eq.\\eqref{3.15} as follows\n\\begin{equation} \\label{6.19}\n  \\begin{aligned}\n    \\qty({j}_y)_{nm,n'm'} & =\n    \\int dx \\int dy \\;\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n}\\big(y - y_0 - \\zeta(t)\\big)\n    \\exp(-ik_x x) \\\\\n    & \\times\n    \\frac{-1}{m} \\qty(i\\hbar\\pdv{y} + \\frac{eE}{\\omega}\\cos(\\omega t))\n    \\frac{1}{\\sqrt{L_x}} \\chi_{n'}\\big(y - y_0 - \\zeta(t)\\big)\n    \\exp(i k'_x x)\n  \\end{aligned}\n\\end{equation}\nthen introducing new variable\n\\begin{equation} \\label{6.20}\n  y - y_0 - \\zeta(t) = \\bar{y} \\quad \\longrightarrow \\quad dy = d{\\bar{y}}\n\\end{equation}\nand follwing identity [*Ref: Appendix A Hermite fucntions]\n\\begin{equation} \\label{6.21}\n  \\pdv{\\chi_n(y)}{y} = -\\sqrt{\\frac{n+1}{2}} \\chi_{n+1}(y) +\n  \\sqrt{\\frac{n}{2}} \\chi_{n-1}(y)\n\\end{equation}\nabove expression can be simplified as previous case (let $y=\\bar{y}$)\n\\begin{equation} \\label{6.22}\n  \\begin{aligned}\n    \\qty({j}_y)_{nm,n'm'} & =\n    \\frac{-1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\int dy \\;\n     \\chi_{n}(y)\n    \\qty[-i\\hbar \\qty(\n    \\sqrt{\\frac{n'+1}{2}} \\chi_{n'+1}(y) - \\sqrt{\\frac{n'}{2}} \\chi_{n'-1}(y)\n    ) + \\frac{eE}{\\omega}\\cos(\\omega t)\n    \\chi_{n'}(y)].\n  \\end{aligned}\n\\end{equation}\nThen considering Gauss-Hermite integral indentities we can derive that\n\\begin{equation} \\label{6.23}\n  \\begin{aligned}\n    \\qty({j}_y)_{nm,n'm'} & =\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty[i\\hbar \\qty(\n    \\sqrt{\\frac{n'+1}{2}} \\delta_{n,n'+1}\n    - \\sqrt{\\frac{n'}{2}} \\delta_{n,n'-1}\n    ) - \\frac{eE}{\\omega}\\cos(\\omega t) \\delta_{n,n'}]\n  \\end{aligned}\n\\end{equation}\n\\textcolor{red}{Due to complexity we can only consider the constant contribution and we allows only the one-cycle averaged current flow} and then we can derive the $s=0$ components of the Fourier series as\n\\begin{equation} \\label{6.24}\n  \\begin{aligned}\n    \\qty({j}^y_{s=0})_{nm,n'm'} & =\n    \\frac{1}{T} \\int_0^T dt \\;\n    \\frac{1}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty[i\\hbar \\qty(\n    \\sqrt{\\frac{n'+1}{2}} \\delta_{n,n'+1}\n    - \\sqrt{\\frac{n'}{2}} \\delta_{n,n'-1}\n    ) - \\frac{eE}{\\omega}\\cos(\\omega t) \\delta_{n,n'}]\n  \\end{aligned}\n\\end{equation}\nand this can be evaluate and get\n\\begin{equation} \\label{6.25}\n  \\begin{aligned}\n    \\qty({j}^y_{s=0})_{nm,n'm'} & =\n    \\frac{i\\hbar}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty[\n    \\sqrt{\\frac{n'+1}{2}} \\delta_{n,n'+1}\n    - \\sqrt{\\frac{n'}{2}} \\delta_{n,n'-1}\n    ]\n  \\end{aligned}\n\\end{equation}\nand this can be re-write as\n\\begin{equation} \\label{6.26}\n  \\begin{aligned}\n    \\qty({j}^y_{s=0})_{nm,n'm'} & =\n    \\frac{i\\hbar}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty[\n    \\sqrt{\\frac{n}{2}} \\delta_{n',n-1}\n    - \\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1}\n    ]\n  \\end{aligned}\n\\end{equation}\n\n\\noindent\nFor electric current operator we can introduce the electron's charge and effective mass\n\\begin{equation} \\label{6.27}\n  \\begin{aligned}\n    \\qty({j}^y_{s=0})_{nm,n'm'} & =\n    \\frac{ie\\hbar}{{m}}\n    \\delta_{k_x,k'_x}\n    \\qty[\n    \\sqrt{\\frac{n}{2}} \\delta_{n',n-1}\n    - \\sqrt{\\frac{n+1}{2}} \\delta_{n',n+1}\n    ]\n  \\end{aligned}\n\\end{equation}\n\\hfill$\\blacksquare$\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nxx\n", "meta": {"hexsha": "0724eabc38c02d4f2fbd293b181a3f2a6555998f", "size": 8863, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_06.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/sec_06.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/sec_06.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.0440677966, "max_line_length": 380, "alphanum_fraction": 0.5953965926, "num_tokens": 3543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6117144810687368}}
{"text": "\\documentclass[10pt]{article}\n\\usepackage{amsfonts}\n\\usepackage{amssymb, amsmath}\n\\usepackage{eucal}\n\\usepackage{amscd}\n\\usepackage{url}\n\\usepackage{listings}\n\\urlstyle{sf}\n\\pagestyle{plain}\n\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\newcommand{\\N}{\\mathbb{N}}\n\\newcommand{\\Q}{\\mathbb{Q}}\n\\newcommand{\\I}{\\mathbb{I}}\n\\newcommand{\\C}{\\mathbb{C}}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Pee}{\\mathbb{P}}\n\\newcommand{\\EuO}{\\mathcal{O}}\n\\newcommand{\\Qbar}{\\overline{\\mathbb{Q}}}\n\\newcommand{\\code}{\\lstinline}\n\n\\newcommand{\\ljk}[2]{\\left(\\frac{#1}{#2}\\right)}\n\\newcommand{\\modulo}[1]{\\;\\left(\\mbox{mod}\\;#1\\right)}\n\\newcommand{\\fr}{\\mathfrak}\n\n\\def\\notdivides{\\mathrel{\\kern-3pt\\not\\!\\kern4.5pt\\bigm|}}\n\\def\\nmid{\\notdivides}\n\\def\\nsubseteq{\\mathrel{\\kern-3pt\\not\\!\\kern2.5pt\\subseteq}}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{proposition}[theorem]{Proposition}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{property}[theorem]{Property}\n\n\\newenvironment{proof}[1][Proof]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\itshape #1}]}{\\end{trivlist}}\n\\newenvironment{definition}[1][Definition]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\n\\newenvironment{example}[1][Example]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\n\\newenvironment{remark}[1][Remark]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\n\\newenvironment{exercise}[1][Exercise]{\\begin{trivlist}\n\\item[\\hskip \\labelsep {\\bfseries #1}]}{\\end{trivlist}}\n\n\\parindent=0pt\n\\parskip 4pt plus 2pt minus 2pt \n\n\\title{Group Theory}\n\n\\author{William B. Hart}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Introduction to Groups and Subgroups}\n\n\\subsection{Groups and their Basic Properties}\n\n\\subsubsection{Groups}\n\n\\begin{definition}\nA set $G$ with a closed binary operation $\\star : G \\times G \\to G$ is a \\emph{group} if the following rules hold:\n\\begin{enumerate}\n\\item (Associativity) For all $a, b, c \\in G$ we have $(a \\star b) \\star c = a \\star (b \\star c)$.\n\\item (Identity) There exists $e \\in G$ such that for all $g \\in G$ we have $g\\star e = g = e \\star g$.\n\\item (Inverses) For every $g \\in G$ there exists $g' \\in G$ such that $g \\star g' = e = g' \\star g$.\n\\end{enumerate}\nWe sometimes write $(G, \\star)$ to denote the group, in order to emphasise the group operation. In other cases where the operation is clear from the context, we just write $G$.\n\\end{definition}\n\nWe call the element $e$ in the definition above the \\emph{identity} (element) of the group and $g'$ the \\emph{inverse} of $g$.\n\nIn the case that the group operation is addition, we usually write $0$ for the identity element and $-g$ for the inverse of $g$.\n\nWhen the group operation is multiplication, we usually write $1$ for the identity element and $g^{-1}$ for the inverse of $g$.\n\nImplicit in the definition of a group is the closure property:\n\n\\begin{enumerate}\n\\item (Closure) For all $a, b \\in G$ we have $a\\star b \\in G$.\n\\end{enumerate}\n\n\\subsubsection{Basic Results}\n\nTo save on notation we will write $g\\star h$ as $gh$ where this will not cause any confusion.\n\\begin{theorem}\nThe identity element $e$ of a group $G$ is unique.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe inverse of an element $g$ of a group $G$ is unique.\n\\end{theorem}\n\n\\begin{proof}\nClearly $gg'' = e$. The result follows after left multiplication by $g'$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $ab = e$ in a group $G$ then $b = a^{-1}$.\n\\end{theorem}\n\n\\begin{proof}\nThe result follows from $ab = e$ after left multiplication by $a^{-1}$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\\label{idempotent_is_identity}\nSuppose $G$ is a group with identity $e$. If $a \\in G$ is idempotent i.e. $aa = a$, then $a = e$.\n\\end{theorem}\n\n\\begin{proof}\nThe result follows after right multiplication of $a^2 = a$ by $a^{-1}$. $\\square$\n\\end{proof}\n\n\\begin{theorem} \\label{product_inverse}\nSuppose $G$ is a group and $a, b \\in G$. Then $(ab)^{-1} = b^{-1}a^{-1}$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Right Identity and Inverses Suffice for a Group}\n\nIn the definition of a group, it isn't necessary to assume that $e$ is both a left and right identity or that $g'$ is both a left and right inverse of an element $g$. The following theorem shows that a right identity and right inverses suffice in order to have a group.\n\n\\begin{theorem}\nLet $G$ be a set closed under a binary, associative operation. Suppose that:\n\\begin{enumerate}\n\\item (Right identity) There exists $e \\in G$ such that $g\\star e = g$ for all $g \\in G$.\n\\item (Right inverse) For every $g \\in G$ there exists $g' \\in G$ such that $g\\star g' = e$.\n\\end{enumerate}\nThen $e\\star g = g$ and $g'\\star g = e$ and $(G, \\star)$ is a group.\n\\end{theorem}\n\n\\begin{proof}\nAssume $e$ is a right identity and every element $g$ has a right inverse $g'$.\n\nTheorem \\ref{idempotent_is_identity} only relies on right inverses and a right identity, so it holds in the context of the theorem.\n\nIt is easy to check that $g'g$ is idempotent. Thus $g'g = e$, i.e. $g'$ is a left inverse.\n\nThat $eg = g$ follows from $e = gg^{-1}$. $\\square$\n\\end{proof}\n\n\\subsubsection{Cancellation in a Group}\n\n\\begin{theorem}\nLet $G$ be a group and $a, b, c \\in G$. If $ab = ac$ then $b = c$. Similarly if $ac = bc$ then $a = b$.\n\\end{theorem}\n\n\\begin{proof}\nThese follow by left (resp. right) multiplication by $a^{-1}$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Laws of Exponents in a Group}\n\nJust as we do in arithmetic, it is convenient to define integer powers of elements of a group $G$.\n\n\\begin{definition}\nLet $G$ be a group, $g\\in G$ and $n$ a positive integer. We define:\n\n\\begin{align*}\n   g^n &= \\underbrace{g g \\cdots g}_{n \\:\\mathrm{factors}}\\\\\ng^{-n} &= \\underbrace{g^{-1} g^{-1} \\cdots g^{-1}}_{n \\:\\mathrm{factors}}\\\\\n   g^0 &= e\n\\end{align*}\n\\end{definition}\n\nAll of the usual laws of exponents hold.\n\n\\begin{theorem}\nIf $G$ is a group and $g \\in G$ then for all $m, n \\in \\mathbb{Z}$ we have\n$$g^m g^n = g^{m + n}.$$\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $g \\in G$. Then for any $m, n \\in \\mathbb{Z}$ we have\n$$(g^{m})^n = g^{mn}.$$\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\nWhen the group operation is addition, we write $ng$ for the sum of $n$ copies of $g$. Similarly $-ng$ corresponds to the sum of $n$ copies of $-g$. Similar results to the above hold, i.e. $mg + ng = (m + n)g$ and $m(ng) = (mn)g$.\n\n\\subsubsection{The Order of a Group}\n\n\\begin{definition}\nThe cardinality of a group is called its \\emph{order}. We denote the order of a group $G$ by $|G|$.\n\\end{definition}\n\n\\begin{definition}\nIf a group has finite order we say that it is a \\emph{finite group}. Otherwise we say that it is an \\emph{infinite group}.\n\\end{definition}\n\nThe smallest number of elements a group can have is $1$, since a group must contain an identity element.\n\n\\begin{theorem}\nA set $G$ containing just the identity element is a group under any closed binary operation on $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsection{The Order of Elements of a Group}\n\n\\subsubsection{The Order of Elements of a Group}\n\n\\begin{definition}\nLet $G$ be a group and $g \\in G$. If there is a positive integer $n$ such that $g^n = e$, the least such $n$ is called the \\emph{order} of $g$, denoted ord$(g)$. If no such $n$ exists, the element $g$ is said to have \\emph{infinite order}.\n\\end{definition}\n\nIf the group is written additively the order of an element $g$ is the least positive integer $n$ such that $ng = 0$.\n\n\\begin{theorem}\nThe order of an element $g$ in a group $G$ is $1$ iff it is the identity.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Basic Results about the Order Elements in a Group}\n\n\\begin{theorem}\nLet $G$ be a group and $g \\in G$. Then ord$(g) =$ ord$(g^{-1})$.\n\\end{theorem}\n\n\\begin{proof}\nThe result follows easily from $(g^{-1})^n = (g^n)^{-1}$. $\\square$.\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $a, b \\in G$. Then ord$(ab) =$ ord$(ba)$. \n\\end{theorem}\n\n\\begin{proof}\nThe result follows easily from $(ab)^n = a(ba)^{n-1}b$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $g \\in G$ has finite order $n$, then $g^0$, $g^1$, $\\ldots$, $g^{n - 1}$ are all of the distinct powers of $g$.\n\\end{theorem}\n\n\\begin{proof}\nFirst show that all powers $g^a$ are equivalent to one of the given powers. By the division algorithm\n$$a = nq + r$$\nfor some $0 \\leq r < n$. It follows easily that $g^a = g^r.$\n\nTo show they are distinct, suppose to the contrary that $g^i = g^j$ for $0\\leq i < j < n$. Multiplication by $g^{-i}$ contradicts the minimality of $n$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIn a finite group $G$, all elements have finite order.\n\\end{theorem}\n\n\\begin{proof}\nIf $g \\in G$ is of infinite order then it is easy to see that all powers of $g$ are distinct. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups with every Element of Finite Order can be Infinite}\n\n\\begin{theorem}\nThere are infinite groups in which all elements have finite order.\n\\end{theorem}\n\n\\begin{proof}\nConsider an alphabet $L$ of infinitely many distinct letters $\\{g_1, g_2, \\ldots\\}$. Now consider the set $W$ of all finite words (including the empty word) made from these letters in which\n\\begin{enumerate}\n\\item Each letter occurs only once.\n\\item The letters are in alphabetical order, i.e. $g_i$ appears before $g_j$ if $i < j$.\n\\end{enumerate}\n\nDefine a binary operation on $W$ as follows. For $w_1, w_2 \\in W$, form the word that is obtained by taking all the letters that occur in either $w_1$ or $w_2$, but not both, and putting them in alphabetical order.\n\nIt is easy to show that $W$ is a group under this operation and $w^2 = e$ for all $w \\in W$. But $g_1, g_2, \\ldots \\in W$ are infinitely many distinct elements of $W$. $\\square$\n\\end{proof}\n\n\\subsection{Subgroups}\n\n\\subsubsection{Subgroups}\n\n\\begin{definition}\nA subset $H$ of a group $G$ which is a group under the same operation as $G$ when restricted to the elements of $H$ is called a \\emph{subgroup} of $G$. We write $H \\leq G$.\n\\end{definition}\n\n\\begin{theorem}\nIf $e$ is the identity of a group $G$ and $H \\leq G$ then $e$ is also the identity of $H$.\n\\end{theorem}\n\n\\begin{proof}\nThe identity of $H$ is idempotent in $H$ and therefore also in $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $H \\leq G$ and $g^{-1}$ is the inverse of $g$ in $H$ then it is also the inverse of $g$ in $G$.\n\\end{theorem}\n\n\\begin{proof}\nThis follows immediately from the uniqueness of inverses and the previous theorem. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA non-empty subset $H$ of a group $G$ is a subgroup iff it is closed under the group operation of $G$ and $h^{-1} \\in H$ for all $h \\in H$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{corollary} \\label{subgroup}\nA non-empty subset $H$ of a group $G$ is a subgroup iff $ab^{-1} \\in H$ for every pair of elements $a, b \\in H$.\n\\end{corollary}\n\n\\begin{proof}\nLet $H$ satisfy the given conditions. As $H$ is non-empty it contains an element $a$. Therefore by assumption $aa^{-1} = e \\in H$ and $ea^{-1} = a^{-1} \\in H$.\n\nClosure follows by taking $a = g$ and $b = h^{-1}$ for arbitrary $g, h \\in H$. Thus $H$ is a subgroup by the previous theorem.\n\nThe converse is clear. $\\square$\n\\end{proof}\n\n\\subsubsection{The Intersection and Union of two Subgroups}\n\n\\begin{theorem}\nIf $G$ is a group and $H, K \\leq G$ then $H\\cap K$ is a subgroup of $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $H, K \\leq G$ then $H\\cup K$ is a subgroup of $G$ iff $H \\leq K$ or $K \\leq H$.\n\\end{theorem}\n\n\\begin{proof}\nLet $H \\cup K$ be a subgroup of $G$. Suppose $H \\not\\subseteq K$ and $K \\not\\subseteq H$.\n\nThis implies that there exists $h \\in H$ with $h \\notin K$ and $k \\in K$ with $k \\notin H$. We have that $h, k \\in H\\cup K$ and it is easy to see that $hk \\in H$ or $hk \\in K$.\n\nIn the first case, $k = h^{-1}(hk) \\in H$ which is a contradiction. The second case also gives a contradiction. Thus our assumption is false and either $H \\leq K$ or $K \\leq H$.\n\nThe converse is clear. $\\square$\n\\end{proof}\n\n\\subsubsection{The Product of Two Subgroups}\n\n\\begin{definition}\nIf $G$ is a group and $H, K \\leq G$ we define:\n$$HK = \\{hk \\;|\\; h \\in H, K \\in K\\}.$$\n\\end{definition}\n\nNote that $HK$ is just a set at this point. In fact we will show the following.\n\n\\begin{theorem}\\label{HKKH}\nIf $G$ is a group and $H, K \\leq G$ then $HK \\leq G$ iff $HK = KH$.\n\\end{theorem}\n\n\\begin{proof}\nFirst suppose that $HK = KH$. Clearly $HK$ is non-empty as $1 \\in HK$.\n\nSuppose $h_1, h_2 \\in H$ and $k_1, k_2 \\in K$. Then as $HK = KH$ we have that $k_1h_2 = h'k'$ for some $h' \\in H$ and $k' \\in K$. It follows that\n$(h_1k_1)(h_2k_2) = (h_1h')(k'k_2) \\in HK$. Thus $HK$ is closed under the group operation.\n\nThat inverses exist in $HK$ follows from\n$$(hk)^{-1} = k^{-1}h^{-1} \\in KH = HK.$$\nThus $HK$ is a subgroup of $G$ by Theorem \\ref{subgroup}.\n\nConversely, suppose that $HK \\leq G$ and let $hk$ be an arbitrary element of $HK$ for some $h \\in H$ and $k \\in K$.\n\nIt is easy to see that $(hk)^{-1} \\in KH$. But $x \\to x^{-1}$ is a bijection on the elements of $HK$, thus $HK \\subseteq KH$.\n\nThe reverse inclusion is easy to show since $k, h \\in HK$ for all $k \\in K$ and $h \\in H$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Order of the Product of Two Subgroups}\n\n\\begin{theorem}\nIf $G$ is a group and $H, K \\leq G$ both of finite order then:\n$$|HK| = \\frac{|H||K|}{|H\\cap K|}.$$\n\\end{theorem}\n\n\\begin{proof}\nThere are $|H||K|$ not necessarily distinct products $hk$ with $h \\in H$ and $k \\in K$. We claim there are precisely $|H\\cap K|$ ways of writing a given element $hk$ as a product of an element of $H$ by an element of $K$.\n\nFor each $z \\in H\\cap K,$\n$$hk = (hz)(z^{-1}k) \\in HK.$$\n\nThus there are at least $|H\\cap K|$ distinct such ways of writing $hk$.\n\nConversely, note that if $hk = h'k'$ for $h' \\in H$ and $k' \\in K$ then\n$$h^{-1}h' = k(k')^{-1} \\in H\\cap K.$$\n\nWriting $h^{-1}h' = z = k(k')^{-1}$ we have that $h'k' = (hz)(z^{-1}k)$.\n\nTherefore every product $h'k'$ is of this form which settles our claim.\n\nAs $H\\cap K$ is non-empty, $|H\\cap K| \\neq 0$ and the result follows. $\\square$\n\\end{proof}\n\n\\subsubsection{The Subgroup Generated by a Subset}\n\n\\begin{definition}\nLet $G$ be a group and $S \\subseteq G$. The \\emph{subgroup generated} by $S$ is defined to be the intersection of all subgroups of $G$ containing $S$. We denote it $\\langle S \\rangle$. If $S = \\{g_1, g_2, \\ldots, g_n\\}$ we usually write $\\langle g_1, g_2, \\ldots, g_n \\rangle$.\n\\end{definition}\n\nThe subgroup generated by $S$ is the smallest subgroup of $G$ containing $S$ in the sense that it is contained in any subgroup of $G$ containing $S$.\n\nIt is clearly also the smallest subset of $G$ containing $S$ which is closed under taking inverses and closed under the group operation. In fact, we have the following theorem.\n\n\\begin{theorem}\nLet $G$ be a group and $S$ a subset of $G$. Let $S' = \\{s^{-1} \\;|\\; s \\in S\\}$. Then $\\langle S \\rangle$ is the set of all finite products of elements of $S \\cup S'$.\n\\end{theorem}\n\n\\begin{proof}\nLet the given set be denoted $T$. Then $T$ is clearly closed under the group operation. But if $a \\in T$, it has the form $a = s_1s_2\\ldots s_n$ for some $s_i \\in S\\cup S'$. The inverse of $a$ is also clearly in $T$. Thus $T$ is a subgroup of $G$.\n\nBut all of the elements of $G$ are contained in any subgroup of $G$ containing $S$. Thus $T = \\langle S \\rangle$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Commutator Subgroup of a Group}\n\n\\begin{definition}\nLet $G$ be a group and $g, h \\in G$. We define the \\emph{commutator} of $g$ and $h$ to be $[g, h] = g^{-1}h^{-1}gh$. The subgroup of $G$ generated by the commutators of $G$ is called the \\emph{commutator subgroup} of $G$ and is denoted $[G, G]$.\n\\end{definition}\n\nNote that the commutator subgroup may contain elements that are not commutators.\n\n\\begin{theorem}\nIf $G$ is a group and $g, h \\in G$ then $[g, h] = 1$ iff $g$ and $h$ commute.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $g, h \\in G$ then $[g, h] = hg[h, g]$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ is a group then every $h \\in [G, G]$ can be written as a finite product of commutators.\n\\end{corollary}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{theorem}\nA group $G$ is abelian iff it has only one distinct commutator.\n\\end{theorem}\n\n\\begin{proof}\nWe always have $1 = [1, 1]$. Thus if a group contains only one distinct commutator, $[g, h] = 1$ for all $g, h \\in G$ which implies it is abelian. The converse is also clear. $square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $g, h \\in G$ then $[g, h]^{-1} = [h, g]$.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $g, h, s \\in G$ then $[g, h]^s = [g^s, h^s]$ where $g^s = s^{-1}gs$.\n\\end{theorem}\n\n\\begin{proof}\nWe have\n$$[g, h]^s = s^{-1}g^{-1}h^{-1}ghs = s^{-1}g^{-1}ss^{-1}h^{-1}ss^{-1}gss^{-1}hs = [g^s, h^s].$$\n$\\square$\n\\end{proof}\n\n\\subsection{Abelian Groups}\n\n\\subsubsection{Abelian Groups}\n\n\\begin{definition}\nA group $G$ with operation $*$ is said to be \\emph{abelian} if the following rule holds\n\\begin{itemize}\n\\item (Commutativity) $ab = ba$ for all $a, b \\in G$.\n\\end{itemize}\n\\end{definition}\n\nWe often write the group operation in an abelian group as $+$ as the number systems $\\Z$, $\\Q$, $\\R$ and $\\C$ all form abelian groups under $+$.\n\nA familiar example of a group which is not abelian is the group of invertible $n\\times n$ matrices under multiplication. \n\n\\subsubsection{Basic Theorems about Abelian Groups}\n\nWe give some criteria for a group to be abelian.\n\n\\begin{theorem}\nLet $G$ be a group. If $(ab)^2 = a^2b^2$ for all $a, b \\in G$ then $G$ is abelian.\n\\end{theorem}\n\n\\begin{proof}\nIf $(ab)^2 = a^2b^2$, then $a(ba)b = a(ab)b$ from which the result follows by cancellation. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA group $G$ is abelian iff $(ab)^{-1} = a^{-1}b^{-1}$ for all $a, b \\in G$.\n\\end{theorem}\n\n\\begin{proof}\nWe have $(ab)^{-1} = b^{-1}a^{-1}$ by Theorem \\ref{product_inverse}. If $G$ is abelian this implies $(ab)^{-1} = a^{-1}b^{-1}$.\n\nAssuming the latter, the converse follows from $b^{-1}a^{-1} = (ab)^{-1} = a^{-1}b^{-1}$ and the bijection $z \\leftrightarrow z^{-1}$ between elements of $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group in which $a = a^{-1}$ for all $a \\in G$ then $G$ is abelian.\n\\end{theorem}\n\n\\begin{proof}\nSuppose $a = a^{-1}$ for all $a \\in G$. Then $ab = a^{-1}b^{-1} = (ba)^{-1} = ba$ for all $b \\in G$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Order of a Nonabelian Group is at least 6}\n\n\\begin{theorem}\nIf $G$ is a non-abelian group then $|G| \\geq 6$.\n\\end{theorem}\n\n\\begin{proof}\nLet $G$ be a non-abelian group and suppose that $ab \\neq ba$ for distinct $a, b \\in G$.\n\nClearly $a = 1$ and $b = 1$ lead to a contradiction. Thus $a, b, 1$ are distinct.\n\nBy application of cancellation we have that $ab \\neq a$, $ab \\neq b$. If $ab = 1$ then $a$ and $b$ are inverse which contradicts $ab \\neq ba$. \n\nSimilar arguments apply for $ba$ and we have that $1$, $a$, $b$, $ab$, $ba$ are distinct. Suppose that these are the only elements in $G$.\n\nFirstly, note $a^2$ cannot equal $ab$, $ba$ or $a$, by cancellation. We can't have $a^2 = b$ otherwise $ab = ba$. Therefore $a^2 = 1$.\n\nThe element $aba$ cannot equal $a$, $ab$ or $ba$ by cancellation. We also can't have $aba = 1$ since multiplication by $a$ on the left leads to a contradiction. Similarly we can't have $aba = b$.\n\nThus $aba$ is distinct from all five elements in the group and the group must have order at least $6$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Quaternion Group $Q_8$}\n\nWe give an example of a finite non-abelian group.\n\n\\begin{definition}\nThe quaternion group $Q_8$ is the multipicative group containing eight elements $\\{1, -1, i, -i, j, -j, k, -k\\}$ which satisfy the relations $i^2 = j^2 = k^2 = -1$, $(-1)^2 = 1$ and $ijk = -1$.\n\\end{definition}\n\nThe remaining entries in the multiplication table for $Q_8$ can be worked out from the given relations:\n$$jk = -i^2jk = -i(ijk) = i.$$\nand\n$$ij = -ijk^2 = -(ijk)k = k,$$\nand\n$$ki = -kij^2 = -k(ij)j = -k^2j = j.$$\n\nWe also have:\n$$kj = k(ki) = k^2i = -i,$$\nand\n$$ji = j(jk) = j^2k = -k,$$\nand\n$$ik = i(ij) = i^2j = -j.$$\n\nNote that $ij \\neq ji$, $jk \\neq kj$ and $ik \\neq ki$, so $Q_8$ is nonabelian.\n\n\\subsection{Cyclic Groups}\n\n\\subsubsection{Cyclic Groups}\n\n\\begin{definition}\nA group $G$ is said to be \\emph{cyclic} if there exists an element $g \\in G$ such that every element of the group is of the form $g^n$ for some $n \\in \\Z$. We call $g$ a \\emph{generator} of $G$ and write $G = <g>$.\n\\end{definition}\n\nThe identity in a cyclic group is $g^0$ and the inverse of $g^n$ is $g^{-n}$.\n\n\\subsubsection{Basic Results Regarding Cyclic Groups}\n\n\\begin{theorem}\nCyclic groups are abelian.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe order of a finite cyclic group $G = <g>$ is the smallest positive integer $n$ for which $g^n = 1$.\n\\end{theorem}\n\n\\begin{proof}\nLet $n$ be as in the theorem. Clearly $g^a = g^b$ for all $a \\equiv b \\pmod{n}$. Therefore all elements of $G$ lie in $\\{g^i \\;|\\; 0 \\leq i < n\\}$.\n\nIt is easy to see that no two such elements are equal. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe generator of an infinite cyclic group is unique.\n\\end{theorem}\n\n\\begin{proof}\nLet $G = <g>$ be infinite cyclic and suppose that $g^a$ is also a generator for some $1 \\neq a \\in \\Z$.\n\nThen we must have $g = (g^a)^n = g^{an}$ for some $n \\in Z$.\n\nMultiplying by $g^{-1}$ we get $g^{an - 1} = 1$ which contradicts the infinite order of $g$. $\\square$\n\\end{proof}\n\nA generator of a finite cyclic group is not generally unique.\n\n\\begin{theorem}\nLet $G = <g>$ be a cyclic group of order $n$. Then $g^a$ is a generator of $G$ iff $a$ coprime to $n$.\n\\end{theorem}\n\n\\begin{proof}\nIf gcd$(a, n) = d$ then clearly all powers of $g^a$ lie in $\\{1, g^d, g^{2d}, \\ldots, g^{n - d}\\}$. Thus if $d \\neq 1$ then $g^a$ doesn't generate $G$.\n\nConversely, if gcd$(a, n) = 1$ there exist $s, t \\in Z$ such that $as + nt = 1$ by the extended Euclidean algorithm. As $g^n = 1$, this implies that $(g^a)^s = g$. Thus every power of $g$ is also a power of $g^a$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA subgroup $H$ of a cyclic group $G = <g>$ is cyclic and is generated by the smallest positive power of $g$ in $H$.\n\\end{theorem}\n\n\\begin{proof}\nSuppose that $g^a$ is the smallest positive power of $g$ in $H$. Clearly all powers of $g^a$ are in $H$.\n\nNo other power of $g$ is in $H$ by the division algorithm and the minimality of $a$. $\\square$\n\\end{proof}\n\n\\subsection{The Centre and Centralizers}\n\n\\subsubsection{The Centre of a Group}\n\n\\begin{definition}\nThe \\emph{centre} of a group $G$ is defined to be the subset\n$$Z_G = \\{g \\in G \\;|\\; ga = ag \\;\\;\\mbox{for all}\\;\\; a \\in G\\}.$$\n\\end{definition}\n\nIn other words, the centre is the set of all elements that commute with every element of $G$.\n\n\\begin{theorem}\nThe centre of a group $G$ is an abelian subgroup of $G$.\n\\end{theorem}\n\n\\begin{proof}\nClearly the identity of $G$ is in the centre of $G$. Therefore $Z_G$ is not empty.\n\nIf $g \\in Z_G$ and $a \\in G$ then $ga = ag$ for all $a \\in G$. Multiplying by $g^{-1}$ on the left and right we see that $g^{-1} \\in Z_G$.\n\nIt is easy to see that if $g, h \\in Z_G$ then $gh \\in Z_G$ and so $Z_G \\leq G$. It is clear that $Z_G$ is abelian. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA group $G$ is abelian iff $Z_G = G$.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\subsubsection{The Centralizer of a Subset of a Group}\n\n\\begin{definition}\nLet $G$ be a group and $S$ a nonempty subset of $G$. The \\emph{centralizer} of $S$ in $G$ is the set\n$$C_G(S) = \\{g \\in G \\;|\\; gs = sg \\;\\;\\mbox{for all}\\;\\; s \\in S\\}.$$\nWhen $S = \\{g\\}$ we write $C_G(S) = C_G(g)$.\n\\end{definition}\n\nIn other words, the centralizer of $S$ is the set of all elements that commute with $S$. The centralizer of $g \\in G$ is the set of all elements that commute with $g$.\n\n\\begin{theorem}\nLet $S$ be a subset of a group $G$. Then $C_G(S) \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\nNote that $C_G(S)$ need not be abelian. For example, if $G$ is nonabelian, $C_G(1) = G$ which is not abelian.\n\n\\subsubsection{Basic Results Regarding Centralizers}\n\n\\begin{theorem}\nLet $G$ be a group. Then $Z_G = \\bigcap_{g \\in G} C_G(g)$.\n\\end{theorem}\n\n\\begin{proof}\nClearly $Z_G \\subseteq \\bigcap_{g \\in G} C_G(g)$.\n\nFor the reverse inclusion, if $x \\in \\bigcap_{g \\in G} C_G(g)$ then $x$ commutes with every $g \\in G$. Thus $g \\in Z_G$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ is a group and $S \\subseteq G$ then $Z_G \\subseteq C_G(S)$.\n\\end{corollary}\n\n\\begin{proof}\nClearly $C_G(S) = \\bigcap_{s \\in S} C_G(s)$. The result therefore follows from the theorem. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group. Then $C_G(Z_G) = G$.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $S \\subseteq T \\subseteq G$, then $C_G(T) \\leq C_G(S)$.\n\\end{theorem}\n\n\\begin{proof}\nIt suffices to show that $C_G(T) \\subseteq C_G(S)$. But this is clear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. Then $H \\subseteq C_G(H)$ iff $H$ is abelian.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\subsection{Conjugacy}\n\n\\subsubsection{Conjugate elements}\n\n\\begin{definition}\nLet $G$ be a group. Two elements $a, b \\in G$ are said to be \\emph{conjugate} if $a = g^{-1}bg$ for some $g \\in G$.\n\\end{definition}\n\n\\begin{theorem}\nIf $G$ is an abelian group then $a, b \\in G$ are conjugate iff $a = b$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group. If $a, b \\in G$ are conjugate then they have the same order.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group. Conjugacy of elements is an equivalence relation on $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $G$ be a group and $g \\in G$. The class of all elements of $G$ that are conjugate to $g$ is called the \\emph{conjugacy class} of $g$.\n\\end{definition}\n\nClearly conjugacy classes partition $G$.\n\n\\subsubsection{Conjugacy and Centralizers}\n\n\\begin{theorem}\\label{conjugacy}\nLet $G$ be a group. The elements of the conjugacy class of $g$ are in bijection with the left cosets of $C_G(g)$.\n\\end{theorem}\n\n\\begin{proof}\nSuppose that $h$ and $h'$ are in the conjugacy class of $g$, i.e. $h = aga^{-1}$ and $h' = bgb^{-1}$ for some $a, b \\in G$.\n\nWe have that $h = h'$ iff $(b^{-1}a)g(b^{-1}a)^{-1} = g$. But this holds iff $b^{-1}a \\in C_G(g)$.\n\nBut $b^{-1}a \\in C_G(a)$ iff $aC_G(g) = bC_G(g)$.\n\nWriting $[g]$ for the conjugacy class of $g$ and $\\mathcal{C}$ for the set of left cosets of $C_G(g)$, we can define a map $\\phi : [g] \\to \\mathcal{C}$ by $h \\mapsto aC_G(g)$ where $h = aga^{-1}$.\n\nBy what we have just shown, this is a well-defined map and it is clearly a bijection. $\\square$\n\\end{proof}\n\n\\subsection{Cosets and Lagrange's Theorem}\n\n\\subsubsection{Cosets}\n\n\\begin{definition}\nLet $G$ be a group and $H \\leq G$. A \\emph{left coset} is a set of the form\n$$aH = \\{ah \\;|\\; h \\in H\\},$$\nfor some $a \\in G$. Similarly a \\emph{right coset} is a set of the form\n$$Ha = \\{ha \\;|\\; h \\in H\\}.$$\n\\end{definition}\n\nClearly if $G$ is abelian, the left coset $aH$ coincides with the right coset $Ha$ for all $a \\in G$.\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. Two left (right) cosets of $H$ either coincide or are disjoint.\n\\end{theorem}\n\n\\begin{proof}\nIf $g \\in aH$ then clearly $gH \\in aH$. Similarly if $gH = aH$ then $g.1 \\in aH$. A similar argument applies for right cosets. $\\square$\n\\end{proof}\n\n\\begin{theorem}\\label{cosets}\nLet $G$ be a group and $H \\leq G$. If $g \\in aH$ then $aH = gH$. Similarly if $g \\in Ha$ then $Ha = Hg$.\n\\end{theorem}\n\n\\begin{proof}\nClear, as $1 \\in H$. $\\square$\n\\end{proof}\n\nNote that these theorems imply that the cosets of $H$ in $G$ partition $G$.\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. There is a bijection between the left and right cosets of $H$ in $G$.\n\\end{theorem}\n\n\\begin{proof}\nDefine a map $\\phi : gH \\to Hg^{-1}$ from left to right cosets.\n\nThe map $\\phi$ is well-defined, since $gH = g'H$ iff $g \\in g'H$ iff $g = g'h$ for some $h \\in H$ iff $g'^{-1} = hg^{-1}$ iff $Hg^{-1} = Hg'^{-1}$.\n\nThe map is clearly bijective. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe number of cosets of $H$ in $G$, if it is finite, is called the \\emph{index} of $H$ in $G$, written $[G:H]$. Otherwise we say that $H$ has infinite index in $G$ and write $[G:H] = \\infty$.\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. There is a bijection between any two left (right) cosets of $H$ in $G$.\n\\end{theorem}\n\n\\begin{proof}\nDefine the map $\\psi : gH \\to hH$ which sends $a \\mapsto hg^{-1}a$.\n\nAs the map is invertible, it is bijective. A similar argument holds for right cosets. $\\square$\n\\end{proof}\n\n\\begin{corollary} \\label{cosetsize}\nIf $G$ is a finite group and $H \\leq G$ then $|gH| = |hH|$ for all $g, h \\in G$.\n\\end{corollary}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\subsubsection{Lagrange's Theorem}\n\n\\begin{theorem} (Lagrange)\nIf $G$ is a group and $H \\leq G$ then $|H| \\;|\\; |G|$.\n\\end{theorem}\n\n\\begin{proof}\nFollows from Corollary \\ref{cosetsize} and the fact that cosets partition a group. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ is a finite group and $H \\leq G$ then $[G:H] = |G|/|H|$.\n\\end{corollary}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ is a finite group, the order of $g$ must divide $G$.\n\\end{corollary}\n\n\\begin{proof}\nThe subgroup generated by $g$, $\\langle g \\rangle = \\{g^i \\;|\\; i \\in \\Z\\}$ is a subgroup of $G$. We have already shown that if the order of $g$ is $n$, then there are $n$ distinct powers of $g$, which it is easy to see are the elements of $\\langle g \\rangle$.\n\nThe result then follows from Lagrange's theorem. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf a group $G$ has prime order $p$, then it is cyclic.\n\\end{theorem}\n\n\\begin{proof}\nLet $g$ be any element of $G$ other than the identity. The result follows from the fact that the order of $g$ must divide $p$. Thus $\\langle g \\rangle = G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a finite group and $K \\leq H \\leq G$, then\n$$[G:K] = [G:H][H:I].$$\n\\end{theorem}\n\n\\begin{proof}\n$[G:K] = |G|/|K| = (|G|/|H|)(|H|/|K|) = [G:H][G:K]$. $\\square$\n\\end{proof}\n\n\\begin{theorem} \\label{gtoorder}\nIf $G$ is a finite group of order $n$ and $g \\in G$ then $g^n = e$.\n\\end{theorem}\n\n\\begin{proof}\nWe have that the order of $g$ divides $n$. $\\square$\n\\end{proof}\n\n\\begin{theorem} (Euler)\nIf gcd$(a, n) = 1$ then $a^{\\varphi(n)} = 1$.\n\\end{theorem}\n\n\\begin{proof}\nThe function $\\varphi(n)$ counts the number of integers $i$ in $0 \\leq i < n$ such that $gcd(i, n) = 1$.\n\nIt is easy to see that this set of integers is a group under multiplication modulo $n$. Euler's theorem is an application of Theorem \\ref{gtoorder}. $\\square$\n\\end{proof}\n\n\\begin{corollary} (Fermat's Little Theorem)\nIf $p$ is a prime then $a^{p-1} \\equiv 1 \\pmod{p}$ for all $1 \\leq a < p$.\n\\end{corollary}\n\n\\begin{proof}\nThis is Euler's theorem where $n = p$, as $\\varphi(p) = p - 1$. $\\square$\n\\end{proof}\n\n\\subsection{Normal Subgroups and Normalizers}\n\n\\subsubsection{Normal Subgroups}\n\n\\begin{definition}\nLet $G$ be a group. A subgroup $N$ is said to be \\emph{normal} if $gN = Ng$ for all $g \\in G$. We write $N \\mathrel{\\unlhd} G$.\n\\end{definition}\n\n\\begin{theorem}\\label{equivnormal}\nLet $G$ be a group and $N \\leq G$. The following are equivalent:\n\\begin{enumerate}\n\\item $N \\mathrel{\\unlhd} G$\n\\item $g^{-1}ng \\in N$ for all $n \\in N$ and $g \\in G$\n\\item For all $g, h \\in G$, $gh \\in N$ iff $hg \\in N$\n\\item For all $g \\in G$, $g^{-1}Ng \\subseteq N$\n\\item For all $g \\in G$, $g^{-1}Ng = N$\n\\item All left cosets are right cosets and conversely\n\\item For all $x, y, g, h \\in G$, $x \\in gN$ and $y \\in hN$ implies $xy \\in (gh)N$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n(1)$\\iff$ (2) We have that $gN = Ng$ iff for all $n \\in N$, $ng \\in gN$. Multiplication on the left by $g^{-1}$ gives the result.\n\n(1)$\\iff$ (3) We have that $gh \\in N$ iff $h \\in g^{-1}N$. This is equal to $Ng^{-1}$ for all $g \\in G$ iff (1) holds. But $h \\in Ng^{-1}$ iff $hg \\in N$.\n\n(1)$\\iff$ (5) Clear.\n\n(5)$\\implies$ (4) Clear.\n\n(4)$\\implies$ (1) Clearly (4) implies $Ng \\subseteq gN$. But replacing $g$ with $g^{-1}$ in (4) also yields $gN \\subseteq Ng$. Thus we have (1).\n\n(1)$\\iff$ (6) Clear.\n\n(1)$\\implies$ (7) If $x \\in gN$ and $y \\in hN$, then (1) implies $xy \\in gNhN = (gh)NN = (gh)N$.\n\n(7)$\\implies$ (1) Another way of writing (7) is that for $g, h \\in G$ and $n, n' \\in N$, $(gn)(hn') = (gh)n''$ for some $n'' \\in N$. Multiplication on the left by $g^{-1}$ and on the right by the inverse of $n'$ yields a statement equivalent to (1). $\\square$\n\\end{proof}\n\n\\begin{theorem}\nAll subgroups of an abelian group are normal.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group then the trivial subgroup $\\{e\\}$ and $G$ itself are normal subgroups of $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group then $Z_G \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nClearly $g^{-1}zg = z$ for all $z \\in Z_G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $H \\mathrel{\\unlhd} G$ and $H \\leq K \\leq G$ then $H \\mathrel{\\unlhd} K$.\n\\end{theorem}\n\n\\begin{proof}\nWe have that $kH = Hk$ for all $k \\in K \\subseteq G$. $\\square$\n\\end{proof}\n\n\\subsubsection{A Subgroup of Order $2$ is Normal}\n\n\\begin{theorem}\nIf $G$ is a group and $H \\leq G$ with $[G:H] = 2$ then $H \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $H$ and $aH$ be the two distinct left cosets. This implies that $a \\notin H$, which in turn implies that $Ha \\neq H$.\n\nAs the number of left and right cosets is equal, the right cosets must be $H$ and $Ha$. But then it is easy to see every left coset of is a right coset and vice versa and so $H$ is normal in $G$. $\\square$\n\\end{proof}\n\n\\subsubsection{Intersection and Products of Normal Subgroups}\n\n\\begin{theorem}\nIf $G$ is a group and $M, N \\mathrel{\\unlhd} G$ then $M \\cap N \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nWe already know $M \\cap N \\leq G$. \n\nIf $a \\in M \\cap N$ then $g{-1}ag \\in M, N$ for all $g \\in G$. Thus $M \\cap N$ is normal in $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $M \\leq G$ and $N \\mathrel{\\unlhd} G$ then $MN, NM \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\nIf $N \\mathrel{\\unlhd} G$ then $g^{-1}Ng \\in N$ for all $g \\in G$. In particular, this holds for all $g \\in M$ and $Ng = gN$ for all $g \\in M$, i.e. $NM = MN$. Thus by Theorem \\ref{HKKH} $MN, NM \\leq G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $M, N \\mathrel{\\unlhd} G$ then $MN, NM \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nBy the previous theorem $MN, NM \\leq G$.\n\nIf $a = nm \\in NM$ for some $n \\in N$ and $m \\in M$ and $g \\in G$ then $g^{-1}ag = (g^{-1}ng)(g^{-1}mg) \\in NM$. Thus $NM \\mathrel{\\unlhd} G$. A similar argument shows that $MN \\mathrel{\\unlhd} G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $H \\leq G$ and $N \\mathrel{\\unlhd} G$ then $H\\cap N \\mathrel{\\unlhd} H$.\n\\end{theorem}\n\n\\begin{proof}\nLet $x \\in H\\cap N$ and $h \\in H$. Then $h^{-1}xh \\in H$.\n\nWe also have $h^{-1}xh \\in N$ as $x \\in N \\mathrel{\\unlhd} G$.\n\nThus $h^{-1}xh \\in H\\cap N$ for all $h \\in H$ and $x \\in H\\cap N$. Thus $H\\cap N \\mathrel{\\unlhd} H$. $\\square$\n\\end{proof}\n\n\\subsubsection{Congugate subgroups}\n\n\\begin{definition}\nLet $G$ be a group and $H \\leq G$. If $g \\in G$ then $g^{-1}Hg$ is called a \\emph{conjugate} of $H$.\n\\end{definition}\n\n\\begin{theorem}\nIf $G$ is a group with $H \\leq G$ and $g \\in G$ then $g^{-1}Hg \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $K = g^{-1}Hg$. It is easy to show that $1 \\in K$, $g^{-1} \\in K$ for any $g \\in K$ and $ab \\in K$ for any $a, b \\in K$. Thus $K$ is a subgroup of $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $H \\leq G$ then $H$ is in bijection with any conjugate subgroup $g^{-1}Hg$.\n\\end{theorem}\n\n\\begin{proof}\nThe map $h \\mapsto g^{-1}hg$ is invertible and hence a bijection. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $G$ be a group and $H \\leq G$. The intersection, $\\cap_{g \\in G} g^{-1}Hg$, of the conjugates of $H$ in $G$ is called the \\emph{normal core} of $H$ in $G$.\n\\end{definition}\n\n\\begin{theorem}\nThe normal core of a subgroup $H$ of a group $G$ is a normal subgroup of $G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $K = \\cap_{g \\in G} g^{-1}Hg$. Clearly $K$ is a subgroup of $G$ as it is an intersection of subgroups of $G$.\n\nAs $M \\to g^{-1}Mg$ is a bijection of conjugates of $H$ we have that $k \\in K$ implies $g^{-1}kg \\in K$. Thus $K$ is normal in $G$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Normalizer of a Subset}\n\n\\begin{definition}\nLet $G$ be a group and $S \\subseteq G$, then the \\emph{normalizer} of $S$ in $G$ is the set\n$$N_G(S) = \\{g \\in G \\;|\\; g^{-1}Sg = S\\}.$$\nIf $S = \\{s\\}$ we usually write $N_G(s) = N_G(S)$.\n\\end{definition}\n\nNote that $N_G(S)$ need not be a normal subgroup of $G$.\n\n\\begin{theorem}\nIf $G$ is a group and $\\emptyset \\neq S \\subseteq G$ then $N_G(S) \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $S \\subseteq G$ then $Z_G \\in N_G(S)$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Basic Theorems Regarding the Normalizer of a Subset}\n\n\\begin{theorem}\nLet $G$ be a group and $g \\in G$. Then $N_G(g) = C_G(g)$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$, then\n$$C_G(H) \\leq N_G(H) \\leq G.$$\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group, then $N_G(Z_G) = G$.\n\\end{theorem}\n\n\\begin{proof}\nWe have that $G = C_G(Z_G) \\leq N_G(Z_G) = G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. Then $H \\leq N_G(H)$.\n\\end{theorem}\n\n\\begin{proof}\nIt is clear that $H \\subseteq N_G(H)$. As both are groups, the result follows. $\\square$\n\\end{proof}\n\n\\subsubsection{The Commutator Subgroup of a Group is Normal}\n\n\\begin{theorem}\nLet $G$ be a group. Then $[G, G] \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nLetting $g^s = s^{-1}gs$. Recall that any element of $[G, G]$ is a finite product of commutators.\n\nThe result follows from\n\\begin{align*}\n([g_1, h_1][g_2, h_2]\\ldots [g_n, h_n])^s &= [g_1, h_1]^s[g_2, h_2]^s\\ldots [g_n, h_n]^s\\\\\n                                          &= [g_1^s, h_1^s][g_2^s, h_2^s]\\ldots [g_n^s, h_n^s].\n\\end{align*} $\\square$\n\\end{proof}\n\n\\subsubsection{Unique Subgroups of a Given Order}\n\n\\begin{theorem}\nLet $G$ be a group and suppose that $H$ is the only subgroup of $G$ of (finite) order $n$. Then $H$ is a normal subgroup of $G$.\n\\end{theorem}\n\n\\begin{proof}\nAs $H$ is in bijection with all its conjugates $g^{-1}Hg$, all its conjugates also have order $n$ and are thus equal to $H$. Thus $H$ is a normal subgroup of $G$. $\\square$\n\\end{proof}\n\n\\subsection{Quotient Groups}\n\n\\subsubsection{Quotient Groups}\n\n\\begin{theorem}\nLet $G$ be a group and $N \\mathrel{\\unlhd} G$. If $aH = a'N$ and $bN = b'N$ for $a, a', b, b' \\in G$ then $abN = a'b'N$.\n\\end{theorem}\n\n\\begin{proof}\nThis follows immediately from Theorem \\ref{equivnormal} (7) and Theorem \\ref{cosets}. $\\square$\n\\end{proof}\n\nThis allows us to define a well-defined operation on cosets of a normal subgroup.\n\n\\begin{theorem}\nLet $G$ be a group an $N \\mathrel{\\unlhd} G$. The cosets of $N$ form a group under the operation\n$$(aN).(bN) = abN.$$\n\\end{theorem}\n\n\\begin{proof}\nThe identity is the coset $N$. The inverse of $gN$ is $g^{-1}N$ and the associative law clearly holds. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe group of cosets of a normal subgroup $N$ of a group $G$ is called the \\emph{quotient group} of $G$ by $N$, which we denote $G/N$.\n\\end{definition}\n\nNote that we have used left cosets in this definition. As $N$ is normal in $G$ we have $gN = Ng$ for all $g \\in G$. Therefore we can equally well give the definition in terms of right cosets. The quotient group in that case is usually denoted $N\\backslash G$.\n\n\\begin{theorem}\nIf $N \\mathrel{\\unlhd} G$ then\n$$|G/N| = [G:N].$$\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and $N \\mathrel{\\unlhd} G$. Then:\n\\begin{enumerate}\n\\item If $G$ is abelian then so is $G/N$\n\\item If $G$ is finite then so is $G/N$\n\\item If $G$ is cyclic then so is $G/N$\n\\item If $G$ is finitely generated then so is $G/N$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n(1) $(aN)(bN) = abN = baN = (bN)(aN)$.\n\n(2) Clear.\n\n(3) Let $G = \\langle g \\rangle$. The elements of $G/N$ are precisely the elements $g^iN = (gN)^i$ for $i \\in \\mathbb{N}$.\n\n(4) If $G = \\langle g_1, g_2, \\ldots, g_n \\rangle$ then $G/N = \\langle g_1N, g_2N, \\ldots, g_nN \\rangle$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $G/Z_G$ is cyclic then $G$ is abelian.\n\\end{theorem}\n\n\\begin{proof}\nAs $G/Z_G$ is cyclic $G/Z_G = \\langle aZ_G \\rangle$ for some $a \\in G$. Then $g = a^rk_1$ and $h = a^sk_2$ for some $r, s \\in \\Z$ and $k_1, k_2 \\in Z_G$.\n\nThus\n$$gh = a^rk_1a^sk_2 = a^ra^sk_1k_2 = a^sa^rk_1k_2 = a^sk_2a^rk_1 = hg.$$ $\\square$\n\\end{proof}\n\n\\subsubsection{The Abelianisation of a Group}\n\n\\begin{theorem}\nIf $G$ is a group then $G/[G, G]$ is abelian. It is the largest quotient of $G$ which is abelian.\n\\end{theorem}\n\n\\begin{proof}\nThe first part follows from $ab[G, G] = ab[b, a][G, G] = ba[G, G]$.\n\nSuppose that $N$ is a normal subgroup of $G$, but $[g, h] \\notin N$ for some $g, h \\in G$.\n\nClearly $[g, h] \\neq 1$, as $1 \\in N$. Thus $gh \\neq hg$.\n\nBut we also have that $ghN \\neq hgN$, as $g^{-1}h^{-1}gh \\notin N$. Thus $(gN)(hN) \\neq (hN)(gN)$ and $G/N$ is not abelian.\n\nThus if $G/N$ is abelian, $[G, G] \\subseteq N$ which shows the result. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe group $G/[G, G]$ is called the \\emph{abelianisation} of $G$.\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\mathrel{\\unlhd} G$. Then $G/H$ is abelian iff $[G, G] \\leq H$.\n\\end{theorem}\n\n\\begin{proof}\nSuppose $G/H$ is abelian. If $g_1, g_2 \\in G$ then we have $(g_1H)(g_2H) = (g_2H)(g_1H)$. Thus $g_1^{-1}g_2^{-1}g_1g_2 \\in H$. This shows $[G, G] \\in H$. \n\nThe argument can be reverse to show the converse. $\\square$\n\\end{proof}\n\n\\subsubsection{The Correspondence Theorem}\n\n\\begin{theorem}\nIf $G$ is a group and $N \\mathrel{\\unlhd} G$ then there is an order preserving bijection\n$$\\{\\mbox{subgroups of}\\;\\;G\\;\\mbox{containing}\\;N \\} \\leftrightarrow \\{\\mbox{subgroups of}\\;\\;G/N\\}.$$ \n\\end{theorem}\n\n\\begin{proof}\nIf $N \\leq A \\leq G$ then $N \\mathrel{\\unlhd} A$. Thus we can define the map $\\phi : A \\mapsto A/N$. The group Clearly $A/N \\subseteq G/N$. It is easy to show that $A/N \\leq G/N$.\n\nConversely, suppose $H' \\leq G/N$. Let $H = \\{h \\in G \\;|\\; hN \\in H'\\}$. Clearly $N \\subseteq H$. It is also easy to show that $H \\leq G$. We see that $H' = \\phi(H)$ and so $\\phi$ is a surjection.\n\nIf $A/N = B/N$ for $A, B \\leq G$ containing $N$, then $A$ and $B$ consist of precisely the same cosets of $N$ in $G$. Thus $A = B$ and $\\phi$ is injective.\n\nIt is easy to see that $\\phi$ is order preserving. $\\square$\n\\end{proof}\n\n\\begin{definition}\nIf $G$ is a group and $A, B \\leq G$ we write $\\langle A, B \\rangle = \\langle A\\cup B \\rangle$.\n\\end{definition}\n\n\\begin{theorem} \\label{normalcontaining}\nIf $G$ is a group, $A, B \\leq G$ and $N \\mathrel{\\unlhd} G$ then\n\\begin{enumerate}\n\\item If $A \\subseteq B$ for a finite group $A$ then $|B:A| = |B/N:A/N|$\n\\item $\\langle A, B \\rangle/N = \\langle A/N, B/N \\rangle$\n\\item $(A\\cap B)/N = (A/N)\\cap (B/N)$\n\\item $A \\mathrel{\\unlhd} G$ iff $A/N \\mathrel{\\unlhd} G/N$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n(1) Follows from $|B:A| = |B|/|A|$ and $|B/N| = |B|/|N|$.\n\n(2) $\\langle A, B \\rangle/N$ consists of the cosets $gN$ for $g \\in \\langle A\\cup B \\rangle$. But as $(aN)(bN) = abN$ and $(aN)^{-1} = a^{-1}N$ a set of generators of this group is given by $(A/N)\\cup (B/N)$, which gives the result.\n\n(3) Note that $N \\mathrel{\\unlhd} A\\cap B$ and so the result makes sense. It is clear that both groups consist of the cosets $gN$ for $g \\in A\\cap B$.\n\n(4) We have that $A \\mathrel{\\unlhd} G$ iff $g^{-1}ag \\in A$ for all $a \\in A$ and $g \\in G$. But this holds iff $g^{-1}agN \\in A/N$ which is true iff $(g^{-1}N)(aN)(gN) \\in A/N$ for all $gN \\in G/N$, which is precisely the statement of the result. $\\square$\n\\end{proof}\n\n\\subsection{Homomorphisms}\n\n\\subsubsection{Homomorphisms}\n\n\\begin{definition}\nIf $G$ and $H$ are groups a \\emph{homomorphism} from $G$ to $H$ is a map $\\phi : G \\to H$ such that $\\phi(g_1g_2) = \\phi(g_1)\\phi(g_2)$ for all $g_1, g_2 \\in G$.\n\\end{definition}\n\nOf course this is the multiplicative version of the definition. There is a similar definition with addition instead of multiplication in the additive case.\n\n\\begin{theorem}\nIf $\\phi : G \\to H$ is a homomorphism then $\\phi(g^{-1}) = \\phi(g)^{-1}$ and $\\phi(1) = 1$.\n\\end{theorem}\n\n\\begin{proof}\nFrom $\\phi(1) = \\phi(1.1) = \\phi(1)\\phi(1)$ we see that $\\phi(1) = 1$.\n\nFrom $1 = \\phi(1) = \\phi(gg^{-1}) = \\phi(g)\\phi(g^{-1})$ we see that $\\phi(g^{-1}) = \\phi(g)^{-1}$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $H \\leq G$ then the map $\\iota : H \\to G$ which sends $h \\mapsto h$ for all $h \\in H$ is a homomorphism, called the canonical injection.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is a group and $N \\mathrel{\\unlhd} G$ then the map $\\rho : G \\to G/N$ which maps $g \\mapsto gN$ for all $g \\in G$ is a homomorphism, called the canonical projection.\n\\end{theorem}\n\n\\begin{proof}\nWe have that $\\rho(gh) = ghN = (gN)(hN) = \\rho(g)\\rho(h)$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Kernel and Image of a Homomorphism}\n\n\\begin{definition}\nLet $\\phi : G \\to H$ be a homomorphism. The \\emph{kernel} of $\\phi$ is the set\n$$\\mbox{ker}(\\phi) = \\{g \\in G \\;|\\; \\phi(g) = 1\\}.$$\n\\end{definition}\n\n\\begin{theorem}\nIf $\\phi : G \\to H$ is a homomorphism then ker$(\\phi) \\mathrel{\\unlhd} G$. Moreover, if $N \\mathrel{\\unlhd} G$ is any normal subgroup, it is the kernel of some homomorphism from $G$.\n\\end{theorem}\n\n\\begin{proof}\nIt is easy to see that ker$(\\phi)$ is a subgroup of $G$.\n\nTo see that it is normal, let $g \\in G$ and $k \\in \\mbox{ker}(\\phi)$, then $\\phi(g^{-1}kg) = 1$. Thus $g^{-1}kg \\in \\mbox{ker}(\\phi)$.\n\nTo show the second part of the theorem it is enough to note that the kernel of the canonical projection $\\rho : G \\to G/N$ is $N$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nIf $\\phi : G \\to H$ is a homomorphism, the \\emph{image} of $\\phi$ is the set\n$$\\mbox{im}(\\phi) = \\{h \\in H \\;|\\; \\mbox{there exists}\\;\\; g \\in G \\;\\;\\mbox{such that}\\;\\; \\phi(g) = h\\}.$$\n\\end{definition}\n\n\\begin{theorem}\nIf $\\phi : G \\to H$ is a homomorphism then im$(\\phi) \\leq H$.\n\\end{theorem}\n\n\\begin{proof}\nClear.\n\\end{proof}\n\n\\begin{theorem}\nLet $\\phi : G \\to H$ be a surjective homomorphism and let $N$ be a normal subgroup of $G$. Then $\\phi(N) \\mathrel{\\unlhd} H$.\n\\end{theorem}\n\n\\begin{proof}\nLet $h \\in H$ and $n' \\in \\phi(N)$. As $\\phi$ is surjective, we can find $g \\in G$ such that $h = \\phi(g)$. We also have $n' = \\phi(n)$ for some $n \\in N$ by definition.\n\nAs $N \\mathrel{\\unlhd} G$ we have that $g^{-1}ng \\in N$. Thus $h^{-1}n'h = \\phi(g)^{-1}\\phi(n)\\phi(g) \\in \\phi(N)$. As $h$ and $n'$ were arbitrary, this shows that $\\phi(N)$ is normal in $H$. $\\square$\n\\end{proof}\n\n\\subsubsection{Endomorphisms of a Group}\n\n\\begin{definition}\nLet $G$ be a group. An \\emph{endomorphism} of $G$ is a homomorphism $\\phi : G \\to G$. The set of all endomorphisms of $G$ is denoted End$(G)$.\n\\end{definition}\n\n\\begin{theorem}\nIf $G$ is an abelian group under addition, then End$(G)$ has the structure of an additive abelian group.\n\\end{theorem}\n\n\\begin{proof}\nIf $\\phi_1$ and $\\phi_2$ are elements of End$(G)$ we define $(\\phi_1 + \\phi_2)(g) = \\phi_1(g) + \\phi_2(g)$ for all $g \\in G$. If it easy to check that this gives the structure of an abelian group on End$(G)$, with the identity map serving as the identity of End$(G)$. $\\square$\n\\end{proof}\n\nIn fact, the group End$(G)$ can even be given the structure of a ring, where the multiplication in the ring is given by composition of homomorphisms. However, we will not prove this here.\n\n\\subsubsection{Isomorphisms}\n\n\\begin{definition}\nA homomorphism of groups $\\phi : G \\to H$ is said to be an \\emph{isomorphism} if there exists a homomorphism $\\phi^{-1} : H \\to G$ such that $\\phi^{-1}\\circ \\phi =$ id$_G$. We say that $G$ and $H$ are isomorphic, which we denote by $G \\cong H$.\n\\end{definition}\n\n\\begin{theorem}\nA homomorphism $\\phi : G \\to H$ is an isomorphism iff it is a bijection.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\phi^{-1} : H \\to G$ be the inverse map. Clearly it is a homomorphism, which also composes with $\\phi$ to give the identity. $\\square$\n\\end{proof}\n\n\\subsubsection{Automorphisms}\n\n\\begin{definition}\nIf $G$ is a group, an \\emph{automorphism} of $G$ is an isomorphism $\\phi : G \\to G$. We denote the set of automorphisms of $G$ by Aut$(G)$.\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group and $a \\in G$. The map $\\sigma_a : g \\mapsto a^{-1}ga$, called \\emph{conjugation} by $a$ is an automorphism.\n\\end{theorem}\n\n\\begin{proof}\nThe map is clearly a bijection. We have that\n$$\\sigma_a(g_1g_2) = a^{-1}g_1g_2a = (a^{-1}g_1a)(a^{-1}g_2a) = \\sigma_a(g_1)\\sigma_a(g_2).$$\nThus $\\sigma_a$ is a homomorphism. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $G$ be a group. An automorphism of $G$ that is conjugation $\\sigma_a$ for some $a \\in G$ is said to be an \\emph{inner autormorphism} of $G$. We write Inn$(G)$ for the set of inner autormorphisms of $G$.\n\\end{definition}\n\n\\begin{theorem}\nFor a group $G$, the set Aut$(G)$ is a group under composition.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nFor a group $G$, Inn$(G) \\mathrel{\\unlhd}$ Aut$(G)$.\n\\end{theorem}\n\n\\begin{proof}\nConjugation by $1 \\in G$ is an inner automorphism. It is the identity of Aut$(G)$.\n\nIt is clear that $\\sigma_{g^{-1}}$ is the inverse of $\\sigma_g$ in Aut$(G)$ and is an inner automorphism. It is easy to see that $\\sigma_{ab}$ is the composition of $\\sigma_a$ and $\\sigma_b$ and so Inn$(G)$ is a subgroup of Aut$(G)$.\n\nTo show that it is normal, let $\\sigma_g \\in$ Inn$(G)$ and $\\phi \\in$ Aut$(G)$. Then for $h \\in G$:\n\\begin{align*}\n\\phi^{-1}\\cdot\\sigma_g\\cdot\\phi(h) &= \\phi\\circ \\sigma_g \\circ \\phi^{-1}(h)\\\\\n                                   &= \\phi(g^{-1}\\phi^{-1}(h)g)\\\\\n                                   &= \\phi(g^{-1})h\\phi(g)\\\\\n                                   &= \\sigma_{\\phi(g)}(h) \\in \\mbox{Inn}(G)\n\\end{align*} $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group and let $\\phi : G \\to$ Aut$(G)$ be the map $g \\mapsto \\sigma_g$. Then $\\phi$ is a homomorphism. We refer to this as the natural homomorphism from $G$ to Aut$(G)$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $\\phi : G \\to$ Aut$(G)$ be the natural homomorphism. Then ker$(\\phi) = Z_G$.\n\\end{theorem}\n\n\\begin{proof}\n$\\phi(g) =$ id$_G$ iff $g^{-1}ag = a$ for all $a \\in G$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Automorphism Group of a Cyclic Group}\n\n\\begin{theorem}\nThe automorphism group of $\\mathbb{Z}$ is isomorphic to $C_2$.\n\\end{theorem}\n\n\\begin{proof}\nAn automorphism of $\\mathbb{Z}$ must send $1$ to a generator of $\\mathbb{Z}$. As the only generators are $\\pm 1$, the result follows. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $C_n = \\langle g \\rangle$ be a cyclic group of order $n$. The automorphisms of $C_n$ consist of the maps $a \\mapsto a^k$ for $1 \\leq k < n$ with gcd$(k, n) = 1$.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\sigma \\in$ Aut$(C_n)$. Then $\\sigma(g) = g^k$ for some $k$. In order to be an automorphism $g^k$ must generate $C_n$. Thus gcd$(k, n) = 1$.\n\nConsider any element $a = g^r \\in C_n$. Then $\\sigma(a) = \\sigma(g)^r = (g^k)^r = a^k$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nWe have $|\\mbox{Aut}(C_n)| = \\varphi(n)$.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\nNote that Aut$(C_n)$ is an abelian group since $(a^r)^s = (a^s)^r$.\n\n\\subsection{Characteristic Subgroups}\n\n\\subsubsection{Characteristic Subgroups}\n\n\\begin{definition}\nLet $G$ be a group. A subgroup $H \\leq G$ is said to be a \\emph{characteristic subgroup} if $\\phi(H) = H$ for all $\\phi \\in$ Aut$(G)$.\n\\end{definition}\n\n\\begin{theorem}\nA characteristic subgroup $H$ of a group $G$ is normal in $G$.\n\\end{theorem}\n\n\\begin{proof}\n$H$ is preserved under all inner automorphisms, i.e. under conjugation by elements of $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $H$ is a characteristic subgroup of a group $G$ then every $\\phi \\in$ Aut$(G)$ induces an automorphism of $G/H$ which gives a map Aut$(G) \\to$ Aut$(G/H)$.\n\\end{theorem}\n\n\\begin{proof}\nAs $\\phi$ preserves $H$, the induced map $gH \\mapsto \\phi(g)H$ is well defined and an injection. It is clearly a surjection because $\\phi$ is invertible. It is clearly a homomorphism. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $H$ be a subgroup of $G$ of index $n$. If it is the only subgroup of $G$ of index $n$ then it is a characteristic subgroup.\n\\end{theorem}\n\n\\begin{proof}\nAny automorphism $\\phi$ of $G$ must send $H$ to a subgroup $H'$ of $G$. The induced map $H \\to H'$ must be an isomorphism since $\\phi$ is injective.\n\nLet $g_1H, g_2H, \\ldots, g_nH$ be the set of left cosets of $H$ in $G$, for some fixed set of representatives $g_i$.\n\nThe map $\\phi$ sends each coset $g_iH$ to a coset $\\phi(g_i)H'$ of $H'$ in $G$. As every element of $G$ has a unique representation as $g_ih$ for some $i$ and $h \\in H$ and $\\phi$ is an automorphism, the cosets $\\phi(g_i)H'$ must partition $G$.\n\nThus the index of $H'$ in $G$ is $[G:H]$. But $H$ is the only subgroup with this index, thus $H = H'$. $\\square$\n\\end{proof}\n\nLet us write $H$ char $G$ to denote that $H$ is a characteristic subgroup of $G$.\n\n\\begin{theorem}\nIf $K$ char $H$ and $H$ char $G$ then $K$ char $G$.\n\\end{theorem}\n\n\\begin{proof}\nClearly any automorphism of $G$ induces an automorphism of $H$ which in turn induces an automorphism of $K$. $\\square$\n\\end{proof}\n\n\\subsubsection{A Characteristic Subgroup of a Normal Subgroup is Normal}\n\n\\begin{theorem}\nIf $K$ char $H \\mathrel{\\unlhd} G$ then $K \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nAny inner automorphism of $G$ preserves $H$ because it is normal. Thus it induces an automorphism of $H$, which preserves $K$ because it is a characteristic subgroup of $H$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Centre of a Group is a Characteristic Subgroup}\n\n\\begin{theorem}\nLet $G$ be a group. Then $Z_G$ char $G$.\n\\end{theorem}\n\n\\begin{proof}\nAn automorphism $\\phi$ of $G$ maps $Z_G$ isomorphically to a subgroup $Z$ of $G$. But if $z \\in Z_G$ and $g \\in G$ we have $\\phi(z)\\phi(g) = \\phi(g)\\phi(z)$.\n\nBecause $\\phi$ is an automorphism of $G$, this shows that every element of $Z$ commutes with every element of $G$. Thus $Z \\leq Z_G$. By inverting $\\phi$ we see that $Z_G \\leq Z$. $\\square$\n\\end{proof}\n\n\\subsubsection{Subgroups of Cyclic Groups are Characteristic}\n\n\\begin{theorem}\nA subgroup $H$ of a cyclic group $G$ is characteristic.\n\\end{theorem}\n\n\\begin{proof}\nLet $G = \\langle g \\rangle$. Any automorphism $\\phi$ of $G$ sends $g$ to $g^n$ for some integer $n$ such that $\\langle g \\rangle = \\langle g^n \\rangle$.\n\nIf $H \\leq G$ then $H = \\langle g^k \\rangle$ for some integer $k$.\n\nNow $phi(H) = \\langle \\phi(g^k) \\rangle = \\langle g^{nk} \\rangle$.\n\nClearly $\\langle g^{nk} \\rangle \\subseteq \\langle g^k \\rangle$. Therefore it remains to show that $\\langle g^k \\rangle \\subseteq \\langle g^{nk}$.\n\nAs $\\langle g^n \\rangle = G$ there exists an integer $s$ such that $g = g^{ns}$.\n\nThen $g^k = (g^{ns})^k = (g^{nk})^s \\in \\langle g^{nk} \\rangle$.\n\nThus $\\phi(H) = H$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Commutator Subgroup is Characteristic}\n\n\\begin{theorem}\nIf $G$ is a group then $[G, G]$ char $G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $S$ be the set of commutators of $G$. If $[x, y] \\in S$ and $\\phi \\in$ Aut$(G)$ then $\\phi([x, y] = [\\phi(x), \\phi(y)]$.\n\nThis is clearly a bijective map on $S$. As $[G, G]$ is the smallest subgroup of $G$ containing $S$, we have that $\\phi([G, G]) = [G, G]$. $\\square$\n\\end{proof}\n\n\\subsubsection{Subgroups with Elements of Order Dividing $p$}\n\n\\begin{theorem}\nLet $G$ be a group and $N = \\{x \\in G \\;|\\; x^p = 1\\}$ for $p$ a prime. Then $N$ char $G$.\n\\end{theorem}\n\n\\begin{proof}\nAny automorphism of $G$ sends $N$ to an isomorphic subgroup, in which every element must have order $p$ or $1$. In other words, $N$ is sent to an isomorphic subgroup of $N$. $\\square$\n\\end{proof}\n\n\\subsection{The Group Isomorphism Theorems}\n\n\\subsubsection{The First Group Isomorphism Theorem}\n\n\\begin{theorem}\nLet $\\phi : G \\to H$ be a group homomorphism. Then $G/\\mbox{ker}(\\phi) \\cong \\mbox{im}(\\phi)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $K = \\mbox{ker}(\\phi)$. Define $\\psi : G/K \\to \\phi(G)$ by $\\psi(aK) = \\phi(a)$.\n\nThe map $\\psi$ is well defined, for if $aK = bK$ then $a = bk$ for some $k \\in K$ and $\\phi(a) = \\phi(b)\\phi(k) = \\phi(b)$.\n\nIt is easy to see that $\\psi$ is a homomorphism on $G/K$.\n\nWe can check that $\\psi$ is injective, since if $\\phi(a) = \\phi(b)$ then $ab^{-1} \\in K$ and so $aK = bK$.\n\nClearly $\\psi$ is surjective and thus an isomorphism. $\\square$\n\\end{proof}\n\n\\subsubsection{Quotients of quotient groups}\n\n\\begin{theorem}\nLet $H$ and $K$ be normal subgroups of a group $G$ and let $K \\leq H$. Then $(G/K)/(H/K) \\cong G/H$.\n\\end{theorem}\n\n\\begin{proof}\nAs $K \\mathrel{\\unlhd} G$ we have that $K \\mathrel{\\unlhd} H$. As $H \\mathrel{\\unlhd} G$ and both groups contain $K$, we have that $H/K \\mathrel{\\unlhd} G/K$. Thus the theorem makes sense.\n\nWe define the map $\\phi : G/K \\to G/H$ by $\\phi(gK) = gH$. It is easy to check that $\\phi$ is well-defined and a homomorphism.\n\nWe have that ker$(\\phi) = \\{gK \\in G/K \\;|\\; g \\in H\\} = H/K$. Then by the first isomorphism theorem $(G/K)/(H/K) \\cong G/H$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Second Isomorphism Theorem}\n\n\\begin{theorem}\nLet $H, N$ be subgroups of a group $G$ and let $N \\mathrel{\\unlhd} G$. Then\n$$H/(H\\cap N) \\cong HN/N.$$\n\\end{theorem}\n\n\\begin{proof}\nWe have previously shown that $H\\cap N \\mathrel{\\unlhd} H$ and it is easy to see that $N \\mathrel{\\unlhd} HN$, so the theorem makes sens.\n\nDefine a map $\\phi : H \\to HN/N$ by $\\phi(h) = hN$. It is easy to check that this map is a homomorphism.\n\nWe have that ker$(\\phi) = H\\cap N$ and $\\phi$ is surjective. Thus by the first isomorphism theorem the result follows. $\\square$\n\\end{proof}\n\n\\subsubsection{The Third Isomorphism Theorem}\n\n\\begin{theorem}\nLet $G$ be a group and $N$ a normal subgroup. If $K$ is a normal subgroup of $G$ containing $N$ then\n$$(G/N)/(K/N) \\cong G/K.$$\n\\end{theorem}\n\n\\begin{proof}\nWe have already shown in Theorem \\ref{normalcontaining} that $K/N$ is a normal subgroup of $G/N$. Therefore the quotient $(G/N)(K/N)$ makes sense.\n\nDefine a map $\\Phi : G/N \\to G/K$ by $\\Phi : gN \\mapsto gK$ for all $g \\in G$. It is easy to see that this is well-defined as $N \\subseteq K$. It is also easy to see that it is a surjective homomorphism.\n\nThe kernel is precisely the set of cosets $gN$ with $g \\in K$, i.e. $K/N$. \n\nTherefore, the result follows by the first isomorphism theorem. $\\square$\n\\end{proof}\n\n\\subsection{Direct Products of Groups}\n\n\\subsubsection{The Direct Product}\n\n\\begin{theorem}\nLet $G$ and $H$ be groups. Define a binary operation on $G\\times H$ by\n$$(g_1, h_1)\\cdot (g_2, h_2) = (g_1g_2, h_1h_2),$$\nfor $g_1, g_2 in G$ and $h_1, h_2 \\in H$.\nThen $G\\times H$ with this operation is a group.\n\\end{theorem}\n\n\\begin{proof}\nThe operation is clearly closed.\n\nAssociativity follows from associativity of the groups $G$ and $H$. The element $(1_G, 1_H)$ is an identity, and $(g^{-1}, h^{-1})$ is an inverse of $(g, h)$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe group $G\\times H$ under the operation given in the theorem is called the \\emph{(external) direct product} of $G$ and $H$ and is also denoted $G\\times H$.\n\\end{definition}\n\n\\subsubsection{The Order of a Direct Product}\n\n\\begin{theorem}\nLet $G$ and $H$ be groups and let $g \\in G$ have order $m$ and $h \\in H$ have order $n$. Then $(g, h) \\in G\\times H$ has order $lcm(m, n)$.\n\\end{theorem}\n\n\\begin{proof}\nThe order of $(g, h)$ will be the smallest positive integer which is a multiple of $m$ and $n$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ and $H$ be finite groups. Then $|G\\times H| = |G|\\times |H|$.\n\\end{corollary}\n\n\\begin{proof}\nFollows from the order of a cartesian product of finite sets. $\\square$\n\\end{proof}\n\n\\subsubsection{The Direct Product of a Family of Groups}\n\n\\begin{definition}\nLet $\\{G_i : i \\in I\\}$ be a family of groups indexed by a set $I$. The (external) \\emph{direct product} of the family is\n$$\\prod_{i \\in I} G_i = \\{f : I \\to \\cup_{i \\in I} G_i \\;|\\; f(i) \\in G_i \\forall i \\in I\\}.$$\n\\end{definition}\n\nIf $I$ is a two element set, the definition isn't exactly the same as the definition we already gave, but note that $(g, h) = (f(1), f(2))$ for some $f$ from the second definition.\n\nAlso note that if $I$ is a countably infinite set then we can think of the direct product as sequences of elements, one from each group $G_i$, i.e. the elements are of the form $(g_i)_{i \\in \\mathbb{N}}$ where $g_i \\in G_i$.\n\n\\begin{theorem}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The direct product $\\prod_{i \\in I} G_i$ is a group under the operation $(f_1\\cdot f_2)(i) = f_1(i)f_2(i)$.\n\\end{theorem}\n\n\\begin{proof}\nThe definition makes sense because $f_1(i)f_2(i) \\in G_i$ since $G_i$ is a group. It is clear that the direct product is closed under its operation.\n\nIt is easy to check associativity and that $e(i) = 1_{G_i}$ is an identity for the group. The inverse of $f$ is given by $f^{-1}(i) = f(i)^{-1}$ for all $i \\in I$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Canonical Projections of a Direct Product}\n\n\\begin{definition}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The \\emph{canonical projections} of $\\prod_{i \\in I} G_i$ are the maps $\\pi_j : \\prod_{i \\in I} G_i \\to G_j$ given by $\\pi_j : f \\mapsto f(i)$ for all $f \\in \\prod_{i \\in I} G_i$.\n\\end{definition}\n\n\\begin{theorem}\nThe canonical projections $\\pi_j : \\prod_{i \\in I} G_i \\to G_j$ are surjective homomorphisms.\n\\end{theorem}\n\n\\begin{proof}\nIt is easy to see that the $\\pi_j$ are homomorphisms.\n\nIf $g \\in G_j$ and $f(i) = e_{G_i}$ for all $i \\neq j$ and $f(j) = g$ then we see that $\\pi_j(f) = g$, which shows that $\\pi_j$ is surjective. $\\square$\n\\end{proof}\n\n\\subsubsection{The Restricted Direct Product}\n\n\\begin{definition}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The \\emph{restricted direct product} of the $G_i$ is\n$$\\prod'_{i \\in I} G_i = \\{f \\in \\prod_{i \\in I} G_i \\;|\\; f(i) = e_{G_i} \\;\\;\\mbox{for all but finitely many} i\\}.$$\n\\end{definition}\n\n\\begin{theorem}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The restricted direct product $H = \\prod'_{i \\in I} G_i$ is a normal subgroup of the direct product $G = \\prod_{i \\in I} G_i$.\n\\end{theorem}\n\n\\begin{proof}\nIt is easy to check that the restricted direct product is a subgroup of the direct product.\n\nNote that if $g \\in G$ and $h \\in H$ then $(g^{-1}hg)(i) = g^{-1}(i)h(i)g(i)$ for all $i \\in I$.\n\nBut $h(i) = e_{G_i}$ for all but finitely many $i \\in I$. Thus $(g^{-1}hg)(i) = g^{-1}(i)g(i) = e_{G_i}$ for all but finitely many $i$. This means that $g^{-1}hg \\in H$ and $H \\mathrel{\\unlhd} G$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Canonical Injections of the Restricted Direct Product}\n\n\\begin{definition}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The \\emph{canonical injections} of the restricted product are the maps $\\iota_j : G_j \\to \\prod'_{i \\in I} G_i$ given by\n$$(\\iota_j(g))(i) = \\begin{cases}g, & i = j\\\\e_{G_i}, & i \\neq j\\end{cases}.$$\n\\end{definition}\n\n\\begin{theorem}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The canonical injections $\\iota_j : G_j \\to \\prod'_{i\\in I} G_i$ are injective homomorphisms.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $\\{G_i : i \\in I\\}$ be a family of groups. The images $\\iota_j(G_j)$ of the canonical injections of the restricted product are normal subgroups of the product $\\prod_{i\\in G} G_i$.\n\\end{theorem}\n\n\\begin{proof}\nAs $\\iota_j$ is a homomorphism, its image is a subgroup of the product.\n\nLet $G = \\prod_{i \\in I} G_i$ and $H = \\iota_j(G_j)$ be the image of $\\iota_j$. If $h \\in H$ then there exists an $a \\in G_j$ such that $\\iota_j(a) = h$. But this means that $h(j) = a$ and $h(i) = e_{G_i}$ for all $i \\neq j$.\n\nLet $g \\in G$. Then for $i = j$ we have $(g^{-1}hg)(j) = g^{-1}(j)ag(j) \\in G_j$.\n\nIf $i \\neq j$ then $(g^{-1}hg)(i) = g^{-1}(i)g(i) = e_{G_i}$.\n\nThus we see that $g^{-1}hg = \\iota_j(g^{-1}(j)ag(j)) \\in \\iota_j(G_j) = H$. Thus $H \\mathrel{\\unlhd} G$. $\\square$\n\\end{proof}\n\n\\subsubsection{Internal Direct Products}\n\n\\begin{definition}\nLet $G$ be a group and $H, K \\leq G$. The group $G$ is said to be the \\emph{internal direct product} of $H$ and $K$ if\n\\begin{enumerate}\n\\item $G = \\{hk \\;|\\; h \\in H, k \\in K\\}$\n\\item $G\\cap K = \\{1_G\\}$\n\\item $hk = kh$ for all $h \\in H, k \\in K$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group and $H, K \\leq G$. Then $G$ is the internal direct product of $H$ and $K$ iff the following hold:\n\\begin{enumerate}\n\\item $G = \\{hk \\;|\\; h \\in H, k \\in K\\}$\n\\item $G\\cap K = \\{1_G\\}$\n\\item $H, K \\mathrel{\\unlhd} G$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nSuppose $G$ is the direct product of $H$ and $K$. Let $g \\in G$ and $k \\in K$. Then by the first condition above, $g = h'k'$ for some $h' \\in H$, $k' \\in K$.\n\nWe have that $g^{-1}kg = k'^{-1}h'^{-1}kh'k'$ which by the third condition above is equal to $k'^{-1}kk' \\in K$. Thus $K$ is a normal subgroup of $G$. A similar argument holds for $H$.\n\nConversely, suppose that the given conditions hold. Let $h \\in H$ and $k \\in K$. As $K$ is normal in $G$ we have $h^{-1}kh = k'$ for some $k' \\in K$. Similarly $k'^{-1}hk' = h'$ for some $h' \\in H$.\n\nRewriting these, we have $h^{-1}k = k'h^{-1}$ and $k'^{-1}h = h'k'^{-1}$. Multiplying these relations we have that $k'^{-1}k = h'h^{-1}$. But the left side is an element of $K$ and the right side an element of $H$. Thus both equal $1$ by the second condition above.\n\nIn other words, $k' = k$ and $h' = h$, which implies that $hk = kh$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $\\{N_i : i \\in I\\}$ be a family of subgroups of a group $G$. The group $G$ is said to be the internal direct product of the family if:\n\\begin{enumerate}\n\\item $N_i \\mathrel{\\unlhd} G$ for all $i$\n\\item $G = \\langle \\cup_{i\\in I} N_i \\rangle$\n\\item $N_i \\cap \\langle \\cup_{j \\neq i} N_i \\rangle = 1_G$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\nLet $\\{N_i : i \\in I\\}$ be a family of subgroups of a group $G$. Then $G$ is the internal direct product of the family if:\n\\begin{enumerate}\n\\item $N_i \\mathrel{\\unlhd} G$ for all $i \\in I$\n\\item $g_ig_j = g_jg_i$ for all $g_i \\in N_i$ and $g_j \\in N_j$ for $i \\neq j$\n\\item Every $g \\in G$ has a unique expression as a product of elements from distinct $N_i$'s\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nThe proof of the second condition is essentially the same as for the theorem above.\n\nAssume $G$ is the direct product of the $N_i$'s. Let $g \\in G$. As the $N_i$'s generate $G$, we can write $g$ as a product $g_{\\lambda_1}g_{\\lambda_2}\\ldots g_{\\lambda_k}$ where $1 \\neq g_{\\lambda_i} \\in G_{\\lambda_i}$, and the $\\lambda_i$ are distinct. \n\nLet $g = h_{\\mu_1}h_{\\mu_2}\\ldots h_{\\mu_m}$ be another such expression and suppose that $\\mu_1 \\neq \\lambda_i$ for all $i$. Then $h_{\\mu_1} \\in N_{\\mu_1} \\cap \\langle \\cup_{i \\neq \\mu_1} N_i \\rangle$, which is trivial.\n\nThis shows that the third condition holds.\n\nConversely, if the conditions in the theorem hold then clearly the third condition of the definition holds, due to uniqueness of expression as a product. The other conditions follow just as for the proof of the previous theorem. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group that is the internal direct product of subgroups $H_1, H_2, \\ldots, H_n$. Suppose $N \\mathrel{\\unlhd} H_1$, then $N \\mathrel{\\unlhd} G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $g = h_1h_2\\ldots h_n \\in G$ for $h_i \\in H_i$ then for $h \\in H_1$ we have $g^{-1}hg = h_1^{-1}hh_1 \\in H_1$. $\\square$ \n\\end{proof}\n\n\\subsubsection{Equivalence of Internal and External Direct Products}\n\n\\begin{theorem}\nLet $G$ be a group and $H, K \\leq G$. If $G$ is the internal direct product of $H$ and $K$ then $G \\cong H\\times K$.\n\\end{theorem}\n\n\\begin{proof}\nDefine a map $f : H\\times K \\to G$ by $(h, k) = hk$.\n\nBy the commutativity in the internal direct product, the map $f$ is a homomorphism.\n\nTo show it is injective, let $(h_1, k_1), (h_2, k_2) \\in H\\times K$. Suppose that $f(h_1, k_1) = f(h_2, k_2)$, i.e. $h_1k_1 = h_2k_2$. We have that $h_2^{-1}h_1 = k_2k_1^{-1}$. As the intersection of $H$ and $K$ is trivial, we have that $h_1 = h_2$ and $k_1 = k_2$.\n\nSurjectivity of $f$ follows from the fact that $G = \\{hk \\;|\\; h \\in H, k \\in K\\}$. $\\square$\n\\end{proof}\n\nA similar proof shows that internal and external direct products of families of subgroups are isomorphic.\n\n\\subsubsection{The Automorphism Group of a Direct Product}\n\n\\begin{theorem}\nIf $A$ and $B$ are finite groups with coprime orders then Aut$(A\\times B) \\cong$ Aut$(A)\\times$Aut$(B)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\phi : A\\times B \\to A\\times B$ be an automorphism. Composing with the projections onto $A$ and $B$ we get homomorphisms $\\phi_A : A\\times B \\to A$ and $\\phi_B : A\\times B \\to B$.\n\nBy the first isomorphism theorem, the order of ker$(\\phi_A)$ must be $|B|$. As the order of any nontrivial element $a \\in A$ is coprime to $|B|$ we see that no element of $A\\times \\{1\\}$ can be in the kernel of $\\phi_A$.\n\nThis means that $\\phi_A$ induces an automorphism on $A$, and similarly $\\phi_B$ induces an automorphism on $B$.\n\nIt is now clear that there is a homomorphism from Aut$(A\\times B) \\to$ Aut$(A)\\times$ Aut$(B)$. But any pair of automorphisms $\\rho : A \\to A$, $\\sigma : B \\to B$ induces an automorphism of $A\\times B$, and there is a homomorphism Aut$(A)\\times$ Aut$(B) \\to$ Aut$(A\\times B)$, which is thus an isomorphism. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe automorphism group of $C_p\\times C_p$ for a prime $p$ is isomorphic to GL$_2(\\mathbb{Z}/p\\mathbb{Z})$.\n\\end{theorem}\n\n\\begin{proof}\nAn endomorhism of $C_p\\times C_p$ is entirely characterised by where it sends the generators $x$ and $y$ of the summands. Suppose it maps $(x, 1) \\to (x^a, y^b)$ and $(1, y) \\to (x^c, y^d)$, where $a, b, c, d$ can be taken modulo $p$.\n\nThis is an automorphism iff it is invertible, which happens iff $ad - bc = \\pm 1$. Thus an automorphism corresponds to a matrix in GL$_2(\\mathbb{Z}/p\\mathbb{Z})$ and vice versa.\n\nAn easy computation shows that composition of two automorphisms corresponds to matrix multiplication of matrices in GL$_2(\\mathbb{Z}/p\\mathbb{Z})$. $\\square$\n\\end{proof}\n\n\\subsection{The Semidirect Product}\n\n\\subsubsection{The Semidirect Product}\n\n\\begin{definition}\nLet $H$ and $Q$ be groups and let $\\theta : Q \\to$ Aut$(H)$ be a group homomorphism. The semidirect product $H\\rtimes_{\\theta} Q$ is the set $\\{(h, q)\\;|\\; h \\in H, q \\in Q\\}$ with operation $(h_1, q_1)(h_2, q_2) = (h_1\\theta(q_1)h_2, q_1q_2)$.\n\\end{definition}\n\n\\begin{theorem}\nThe semidirect product $H\\rtimes_{\\theta} Q$ is a group.\n\\end{theorem}\n\n\\begin{proof}\nIt is clear that $(1, 1)$ is the identity.\n\nWe have\n$$(h_1, q_1)[(h_2, q_2)(h_3, q_3)] = (h_1\\theta(q_1)[h_2\\theta(q_2)h_3], q_1q_2q_3)] = (h_1\\theta(q_1)h_2\\theta(q_1q_2)h_3).$$\nSimilarly\n$$[(h_1, q_1)(h_2, q_2)](h_3, q_3) = (h_1\\theta(q_1)h_2\\theta(q_1q_2)h_3, q_1q_2q_3).$$\nThus the associative law holds.\n\nFinally, $(\\theta(q^{-1})h^-1, q^{-1})$ is the inverse of $(h, q)$.\n$\\square$\n\\end{proof}\n\n\\begin{theorem}\nGiven groups $H$ and $Q$ and a group homomorphism $\\theta : Q \\to$ Aut$(H)$ there exist canonical injections $H \\to H\\rtimes_{\\theta} Q$ and $Q \\to H\\rtimes_{\\theta} Q$ given by $h \\mapsto (h, 1)$ and $q \\mapsto (1, q)$. These are group homomorphisms.\n\\end{theorem}\n\n\\begin{proof}\nIt is clear that the first is a homomorphism.\n\nFor the second, it follows from $\\theta(q)1 = 1$. $\\square$\n\\end{proof}\n\nWe will identify $H$ with its image under the first injection, so that it is a subgroup of $H\\rtimes_{\\theta} Q$ and similarly we will identify $Q$ with its image under the second injection, so that it is also a subgroup of $H\\rtimes_{\\theta} Q$.\n\n\\begin{theorem}\nLet $H$ and $Q$ be groups and $\\theta : Q \\to$ Aut$(H)$ be a homomorphism. Then\n\\begin{enumerate}\n\\item $H \\mathrel{\\unlhd} H\\rtimes_{\\theta} Q$\n\\item $HQ = H\\rtimes_{\\theta} Q$\n\\item $H\\cap Q = (1, 1) \\in H\\rtimes_{\\theta} Q$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nNote that $(h, q) = (h, 1)(1, q)$. Therefore $HQ = H\\rtimes_{\\theta} Q$.\n\nLet $\\rho : H\\rtimes_{\\theta} Q \\to Q$ be defined by $\\rho(h, q) = q$. This is clearly a homomorphism with kernel $H$. Thus $H$ is a normal subgroup of $H\\rtimes_{\\theta} Q$.\n\nClearly $(1, 1)$ is the only element in (the images of) $H$ and $Q$ (in $H\\rtimes_{\\theta} Q$). $\\square$\n\\end{proof}\n\n\\subsubsection{Internal Semidirect Products}\n\n\\begin{definition}\nIf $G$ is a group with subgroups $H$ and $Q$, we say that $G$ is the \\emph{internal direct product} of $H$ and $Q$ if\n\\begin{enumerate}\n\\item $H \\mathrel{\\unlhd} G$\n\\item $HQ = G$\n\\item $H\\cap Q = 1 \\in G$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{lemma}\nLet $G$ be a group with subgroups $H$ and $Q$. Suppose $G = HQ$ and $H\\cap Q = \\{1\\}$. Then every element $g \\in G$ can be written uniquely in the form $hq$ with $h \\in H$ and $q \\in Q$.\n\\end{lemma}\n\n\\begin{proof}\nSuppose $hq = h'q'$. Then $h'^{-1}h = q'q^{-1} \\in H\\cap Q$. Thus $h = h'$ and $q = q'$. $\\square$\n\\end{proof}\n\nIt is clear that any external semidirect product is an internal semidirect product. But we also have the converse.\n\n\\begin{theorem}\nLet $G$ be a group which is the internal semidirect product of subgroups $H$ and $Q$. Then $G \\cong H\\rtimes_{\\theta} Q$ where $\\theta : Q \\to$ Aut$(H)$ is given by\n$$\\theta(q)(h) = qhq^{-1}.$$\n\\end{theorem}\n\n\\begin{proof}\nBy the lemma, every $g \\in G$ can be written uniquely as $hq$ for $h \\in H$ and $q \\in Q$. Thus the map $\\phi : (h, q) \\mapsto hq$ is a bijection from $H\\rtimes_{\\theta} Q$ to $G$.\n\nIt suffices to show $\\phi$ is a homomorphism:\n\\begin{multline*}\n\\phi((h_1, q_1)(h_2, q_2)) = \\phi((h_1\\theta(q_1)h_2, q_1q_2)) =\\\\\n\\phi(h_1q_1h_2q^{-1}, q_1q_2) = h_1q_1h_2q_2 = \\phi((h_1, q_1))\\phi((h_2, q_2)).\n\\end{multline*} $\\square$\n\\end{proof}\n\nNote that if $G$ is the internal direct product of subgroups $H$ and $Q$ with $Q$ also normal in $G$ then the semidirect product is the direct product.\n\nAlso note that whilst any two direct products of groups $H$ and $Q$ are isomorphic, this is not true of the semidirect product as the semidirect product still depends on the action of $Q$ on $H$.\n\nIn the case of the internal semidirect product, one should not confuse the action of $Q$ on $H$ by conjugation in $G$ with inner automorphisms of $H$ (which would correspond to conjugation by elements of $H$). As $H$ is normal in $G$, the action of $Q$ on $H$ must map $H$ to itself, but this map can be any automorphism of $H$, not just an inner automorphism.\n\n\\subsubsection{Dihedral Groups}\n\n\\begin{definition}\nLet $D_n$ be the group generated by $r$ and $s$ with $r^n = 1$, $s^2 = 1$ and $(sr)^2 = 1$. We call $D_n$ the $n$-th \\emph{dihedral group}.\n\\end{definition}\n\n\\begin{theorem}\nThe dihedral group $D_n$ has $2n$ elements, namely $1, r, \\ldots, r^{n-1}$ and $s, sr, \\ldots sr^{n-1}$.\n\\end{theorem}\n\n\\begin{proof}\nFrom $(sr)^2 = 1$ we have $rs = s^{-1}r^{-1} = sr^{n-1}$. Repeated application of this identity allows us to replace any product of $s$ and $r$ with a product having at most one $s$ on the left. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe dihedral group $D_n$ is isomorphic to the semidirect product $C_n\\times C_2$ where the the non-identity element of $C_2$ acts on $C_n$ by inverting elements, i.e. if $C_n = \\langle r \\rangle$ and $C_2 = \\langle s \\rangle$ then $srs^{-1} = r^{-1}$.\n\\end{theorem}\n\n\\begin{proof}\nNote that we have identified $C_n$ and $C_2$ with subgroups of $D_n$ generated by $r$ and $s$ respectively.\n\nWe have $C_n \\mathrel{\\unlhd} D_n$ as it has index 2.\n\nClearly $C_n\\cap C_2 = 1$ and $C_nC_2 = D_n$.\n\nThe given identity follows from $(sr)^2 = 1$ and $s^2 = 1$. $\\square$\n\\end{proof}\n\n\\subsection{Exact Sequences}\n\n\\subsubsection{Exact Sequences}\n\n\\begin{definition}\nAn exact sequence of groups is a sequence of homomorphisms $f_i$ between groups $G_i$:\n$$G_0 \\overset{f_1}{\\longrightarrow} G_1 \\overset{f_2}{\\longrightarrow} G_{2} \\overset{f_{3}}{\\longrightarrow} \\cdots \\overset{f_n}{\\to} G_n$$\nsuch that im$(f_k) =$ ker$(f_{k+1})$ for every $n$.\n\\end{definition}\n\n\\begin{theorem}\nThe sequence $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B$ is exact at $A$ iff $f$ is an injective homomorphism.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe sequence $A \\overset{f}{\\longrightarrow} B \\longrightarrow 0$ is exact at $B$ iff $f$ is an surjective homomorphism.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nThe sequence $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\longrightarrow 0$ is exact at $B$ iff $f$ is an isomorphism.\n\\end{corollary}\n\n\\subsubsection{Short Exact Sequences}\n\n\\begin{definition}\nA \\emph{short exact sequence} is an exact sequence of the form\n$$0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0.$$\n\\end{definition}\n\n\\begin{theorem}\nIf $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ is a short exact sequence of groups then $C \\cong B/\\mbox{im}(f)$.\n\\end{theorem}\n\n\\begin{proof}\nFollows from the first isomorphism theorem and the definition of exactness at $B$. $\\square$\n\\end{proof}\n\n\\subsubsection{Split Short Exact Sequences}\n\n\\begin{definition}\nA short exact sequence $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ is said to be \\emph{split} if there exists a homomorphism $h : C \\to B$ such that the composition $g\\circ h$ on $C$ is the identity map.\n\\end{definition}\n\n\\begin{theorem}\nLet $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ be a short exact sequence of groups. If there exists a homomorphism $t : B \\to A$ such that $t\\circ f$ is the identity map on $A$ then $B$ is a direct sum of $A$ and $C$.\n\\end{theorem}\n\n\\begin{proof}\nDefine $\\theta : B \\to A\\times C$ by\n$$\\theta(b) = (t(b), g(b)).$$\n\nThis is a homomorphism since $t$ and $g$ are homomorphisms.\n\nWe will show that the kernel of $\\theta$ is trivial, so that it is injective. If $b \\in$ ker$(\\theta)$ then $t(b) = 1$ and $g(b) = 1$. From exactness at $B$ we see that $g(b) = 1$ implies $b = f(a)$ for some $a \\in A$. If $t(b) = 1$ then $1 = t(f(a)) = a$. But this also means $b = f(1) = 1$.\n\nTo show that $\\theta$ is surjective, let $(a, c) \\in A\\times C$. As $g$ is surjective, $c = g(b)$ for some $b \\in B$.\n\nLet $x = t(b)^{-1}a \\in A$. We have $t(bf(x)) = t(b)t(f(x)) = t(b)x = a$. By exactness at $B$ we have that $g(bf(x)) = g(b)g(f(x)) = g(b) = c$. Thus $\\theta(bf(x)) = (a, c)$ and $\\theta$ is surjective. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nLet $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ be a short exact sequence of groups. If there exists a homomorphism $t : B \\to A$ such that $t\\circ f$ is the identity map on $A$ then the sequence is split.\n\\end{corollary}\n\n\\begin{proof}\nDefine $h : C \\to B$ as the composition of the canonical injection of $C$ into $A\\times C$ and the inverse of the map $\\theta$ from the proof of the theorem.\n\nLet $c \\in C$ and $b = h(c) = \\theta^{-1}((1, c))$. Then $g(b) = \\rho_2(\\theta(b))$, by definition of $\\theta$, where $\\rho_2$ is the projection onto the second component. But this is clearly $c$. Thus $h$ splits the sequence. $\\square$\n\\end{proof}\n\nThe converse is not true, but we have the following.\n\n\\begin{theorem}\nLet $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ be a short exact sequence of groups. If the sequence is split then $B \\cong A\\rtimes_{\\theta} C$ for some homomorphism $\\theta : C \\to$ Aut$(A)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $h : C \\to B$ split the sequence. It suffices to show that $B$ is the internal direct product im$(f)\\rtimes_{\\theta}$ im$(h)$.\n\nAs im$(f) =$ ker$(g)$, it is a normal subgroup of $B$.\n\nFirstly, we show that im$(f)$im$(h) = B$. Let $b \\in B$. Then $b = yz$ where $z = h(g(b))$ and $y = bz^{-1}$. We have $g(z) = g(h(g(b))) = g(b)$. Thus $g(y) = g(b)g(z)^{-1} = 1$. Thus $y \\in$ ker$(g) =$ im$(f)$. But $z \\in$ im$(h)$ by construction, and so $b \\in$ im$(f)$im$(h)$.\n\nNow we show that if $x \\in$ im$(f)\\cap$ im$(h)$ then $x = 1$. For if $x = f(a) = h(c)$ for $a \\in A$ and $c \\in C$ then $c = g(h(c)) = g(f(a)) = 1$ due to exactness of the sequence. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nLet $0 \\longrightarrow A \\overset{f}{\\longrightarrow} B \\overset{g}{\\longrightarrow} C \\longrightarrow 0$ be a short exact sequence of groups. If $A$, $B$ and $C$ are abelian and the sequence is split, then $C \\cong A\\times B$.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\section{Free Groups and Presentations}\n\n\\subsection{Free Groups}\n\n\\subsubsection{Free Groups}\n\n\\begin{definition}\nLet $S$ be a set of symbols and let $S^{-1}$ be the set of symbols $s^{-1}$ for each symbol in $S$. Let $T = S\\cup S^{-1}$ and let $W$ be the set of words constructed from symbols in $T$, including the empty word. A word can be \\emph{reduced} by removing any pair of adjacent symbols of the form $ss^{-1}$ or $s^{-1}s$ from the word, for any $s \\in S$. A word is said to be \\emph{reduced} if no such adjacent pairs exist in the word. The \\emph{free group} on $S$ is the set $F(S)$ of reduced words with concatenation followed by reduction as the operation.\n\\end{definition}\n\n\\begin{theorem}\nThe free group $F(S)$ on a set $S$ is a group.\n\\end{theorem}\n\n\\begin{proof}\nThe empty word is the identity, and the operation is clearly associative. The inverse of a word is defined to be the reverse of the word with each symbol $s$ replaced with $s^{-1}$ and vice versa. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nEvery group $G$ is a quotient of a free group.\n\\end{theorem}\n\n\\begin{proof}\nLet $S$ be the underlying set of $G$.\n\nDefine a map $F(S) \\to G$ by sending a reduced word in $F(S)$ to the corresponding product of elements and inverses in $G$.\n\nThis map is clearly well-defined and a surjective homomorphism. The result follows from the first isomorphism theorem. $\\square$\n\\end{proof}\n\n\\subsection{Group Presentations}\n\n\\subsubsection{Group Presentations}\n\n\\begin{definition}\nLet $S$ be a set and $R$ be a set of (reduced) words in $F(S)$. Let $N(R)$ be the smallest normal subgroup of $F(S)$ containing $R$ (the \\emph{normal closure} of $R$), then the group $G = F(S)/N(R)$ is said to have \\emph{presentation} $\\langle S \\;|\\; R \\rangle$.\n\\end{definition}\n\n\\begin{theorem}\nLet $R$ be the kernel of the map $F(S) \\to G$ in the previous theorem. Then $\\langle S \\;|\\; R \\rangle$ is a presentation of $G$.\n\\end{theorem}\n\n\\begin{proof}\nThe kernel is normal and so $N(R) = R$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nA presentation $\\langle S \\;|\\; K \\rangle$ of a group $G$ is said to be finitely generated if $S$ is finite. It is said to be \\emph{finitely related} if $K$ is finite, and a \\emph{finite presentation} if both $S$ and $K$ are finite. The group $G$ is also said to be finitely generated or finitely related or finitely presented, respectively, if it has a presentation with the given properties.\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group. There is a unique homomorphism $\\phi : F(G) \\to G$ which is the identity on elements of $G$.\n\\end{theorem}\n\n\\begin{proof}\nThe definition of $\\phi$ on a word in $F(G)$ is fixed in view of $\\phi$ being a homomorphism and from the fact that $gg^{-1}$ and $g^{-1}g$ are equal to the empty word after reduction, for any $g \\in G$, so that $\\phi(g)\\phi(g^{-1}) = \\phi(g^{-1})\\phi(g) = 1$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nEvery group has a presentation and every finite group has a finite presentation.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Fundamental Theorem of Presentations of a Group}\n\n\\begin{theorem}\nLet $G = \\langle S \\;|\\; R \\rangle$ be a presentation of a group. Let $\\theta : S\\cup S^{-1} \\to H$ be a map to any group $H$ such that $\\theta(s^{-1}) = \\theta(s)^{-1}$ for any $s \\in S$. Suppose that for all relations $r = t_1t_2\\ldots t_k \\in R$ with $t_i \\in S\\cup S^{-1}$ we have $\\theta(t_1)\\theta(t_2)\\ldots \\theta(t_k) = 1$. Then $\\theta$ extends uniquely to a homomorphism $\\theta' : G \\to H$.\n\\end{theorem}\n\n\\begin{proof}\nIf such a homomorphism exists, it is clearly unique.\n\nDefine $\\psi : F(X) \\to H$ by $\\psi(x) = \\phi(x)$ for $x \\in X$ and $x \\in X^{-1}$ and by $\\psi(x_1x_2) = \\phi(x_1)\\phi(x_2)$ for $x_1, x_2 \\in X\\cup X^{-1}$. This is clearly a well-defined homomorphism.\n\nNow $\\psi(r) = 1$ for all $r \\in R$ and so $R \\subseteq$ ker$(\\psi)$.\n\nLet $N =$ ker$(\\psi)$ and $R'$ be the normal closure of $R$ in $F(X)$. Then $N \\mathrel{\\unlhd} F(X)$ and $R' \\leq N$. Thus there is a well-defined homomorphism $\\theta' : F(X)/R' \\to H$. $\\square$\n\\end{proof}\n\n\\subsubsection{Presentation of a Direct Product}\n\n\\begin{theorem}\nLet $G_1 = \\langle X_1 \\;|\\; R_1 \\rangle$ and $G_2 = \\langle X_2 \\;|\\; R_2 \\rangle$ be groups with presentations such that $X_1$ and $X_2$ are disjoint. Then $G_1\\times G_2 = \\langle X_1\\cup X_2 \\;|\\; R_1\\cup R_2\\cup [X_1, X_2] \\rangle$.\n\\end{theorem}\n\n\\begin{proof}\nDefine $\\theta : X_1\\cup X_2 \\to G_1\\times G_2$ by $\\theta(x_1) = (x_1, 1)$ and $\\theta(x_2) = (1, x_2)$ for $x_i \\in X_i$ and extend $\\theta$ to $F(X_1\\cup X_2)$ by multiplicativity.\n\nLet $H = \\langle X_1\\cup X_2 \\;|\\; R_1\\cup R_2\\cup [X_1, X_2] \\rangle$. Let $r = t_1t_2\\ldots t_k$ be a relation in $H$ with $t_i \\in X_1\\cup X_2\\cup X_1^{-1}\\cup X_2^{-1}$.\n\nIf $r \\in R_1$ then $\\theta(r) = (r, 1) = (1, 1)$. Similarly if $r \\in R_2$ then $\\theta(r) = (1, 1)$. Finally, if $r = [x_1, x_2]$ for $x_i \\in X_i$ then\n$$\\theta(r) = \\theta(x_1)^{-1}\\theta(x_2)^{-1}\\theta(x_1)\\theta(x_2) = (x_1, 1)^{-1}(x_2, 1)^{-1}(x_1, 1)(x_2, 1) = (1, 1).$$\n\nTherefore by the Fundamental Theorem of Presentations, $\\theta$ extends to a map $H \\to G_1\\times G_2$. It is clearly surjective.\n\nLet $V = \\langle X_1\\cup X_2 \\;|\\; H \\rangle$.\n\nWe will show that ker$(\\theta) = 1$. Because elements of $X_1$ and $X_2$ commute in $V$, any element of $V$ can be written $v = s_1s_2\\ldots s_mt_1t_2\\ldots t_n$ with $s_i \\in X_1\\cup X_1^{-1}$ and $t_i \\in X_2\\cup X_2^{-1}$. Then $\\theta(v) = (s_1s_2\\ldots s_m, t_1t_2\\ldots t_n)$.\n\nThus if $v \\in$ ker$(\\theta)$ then $s_1s_2\\ldots s_m = 1$ and $t_1t_2\\ldots t_n = 1$. Thus $\\alpha = s_1s_2\\ldots s_m$ is in the normal closure of $R_1$ and $\\beta = t_1t_2\\ldots t_n$ in the normal closure of $R_2$.\n\nThus both $\\alpha$ and $\\beta$ are in the normal closure of $H$. Thus both are $1$ in $V$. Thus $v = 1$. $\\square$\n\\end{proof}\n\n\\section{Permutations}\n\n\\subsection{Permutations}\n\n\\subsubsection{Permutations}\n\n\\begin{definition}\nA \\emph{permutation} on a set $S$ of $n$ elements is a bijection $\\phi : S \\to S$. Such a permutation can be defined by its action on the $i$-th element of $S$, which we can denote\n$$\\left(\\begin{array}{cccc}1 & 2 & \\cdots & n\\\\ \\phi(1) & \\phi(2) & \\cdots & \\phi(n)\\end{array}\\right).$$\n\\end{definition}\n\n\\subsubsection{Cycles}\n\n\\begin{definition}\nA \\emph{cycle} $(a_1, a_2, \\cdots, a_k)$ is a permutation $\\phi$ that maps $a_i \\mapsto a_{i+1}$ for $1 \\leq i < k$ and $a_k \\mapsto a_1$.\n\\end{definition}\n\n\\begin{theorem}\nA permution $\\phi$ on the set $S$ of $n$ elements can be written as a product of disjoint cycles.\n\\end{theorem}\n\n\\begin{proof}\nBegin with $1 \\in S$. Then apply $\\phi$ repeatedly until we reach $1$ again (as $\\phi$ is a bijection and $S$ is finite, this must eventually happen): $1 \\mapsto a_2 \\mapsto \\cdots \\mapsto 1$. This is a cycle.\n\nIf any elements of $S$ did not appear in this cycle, let $b_1$ be the first such element. Apply the same trick to get a cycle beginning with $b_1$. As $\\phi$ is a bijection, the elements of this cycle must be distinct from the elements of the first cycle.\n\nApply the same trick until all elements of $S$ appear in a cycle. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $\\alpha = (a_1, a_2, \\ldots, a_s)$ be a cycle. Let $\\sigma$ be a permutation. Then\n$$\\sigma\\alpha\\sigma^{-1} = (\\sigma(a_1), \\sigma(a_2), \\ldots, \\sigma(a_s)).$$\n\\end{theorem}\n\n\\begin{proof}\nLet $b_i = \\sigma(a_i)$ for $i \\in \\{1, 2, \\ldots, s\\}$.\n\nFor $i \\in \\{1, 2, \\ldots, s-1\\}$ we have\n$$(\\sigma\\alpha\\sigma^{-1})(b_i) = (\\sigma\\alpha)(a_i) = \\sigma(a_{i+1}) = b_{i+1}.$$\n\nWe also have\n$$(\\sigma\\alpha\\sigma^{-1})(b_s) = \\sigma\\alpha(a_s) = \\sigma(a_1) = b_1.$$\n\nAs $\\alpha$ leaves any $x \\not\\in \\{a_1, a_2, \\ldots, a_s\\}$ fixed, we have that $(\\sigma\\alpha\\sigma^{-1})(y) = y$ for all $y \\not\\in \\{b_1, b_2, \\ldots, b_s\\}$. $\\square$\n\\end{proof}\n\n\\subsubsection{Transpositions}\n\n\\begin{definition}\nA \\emph{transposition} is a cycle of length $2$.\n\\end{definition}\n\n\\begin{theorem}\nA cycle is a product of transpositions.\n\\end{theorem}\n\n\\begin{proof}\n$(a_1, a_2, \\ldots, a_s) = (a_s, a_{s-1})(a_s, a_{s - 2})\\cdots(a_s, a_1)$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Symmetric Group}\n\n\\begin{definition}\nThe \\emph{symmetric group} on the set $S$ of $n$ elements is the set of permutations of $S$. We denote it $S_n$.\n\\end{definition}\n\n\\begin{theorem}\nThe set $S_n$ is a group under composition of permutations.\n\\end{theorem}\n\n\\begin{proof}\nThe trivial permutation is the identity. As a permutation is a bijection, it is invertible. Thus inverses exist. Composition is clearly associative. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe symmetric group $S_n$ is generated by transpositions of the form $t_i = (i, i + 1)$.\n\\end{theorem}\n\n\\begin{proof}\nWe have already seen that any permutation can be written as a product of disjoint cycles, and each cycle can be written as a product of transpositions.\n\nBut $(a_i, a_j)$ for $j > i$ can be expressed as $(a_{j-1}, a_j)\\ldots (a_{i+1}, a_{i+2})(a_i, a_{i+1})$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\n$|S_n| = n!$.\n\\end{theorem}\n\n\\begin{proof}\nFollows immediately by counting the number of possible permutation. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nTwo elements of $S_n$ are conjugate iff they have disjoint cycle representations with cycles of the same length.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\alpha = c_1c_2\\ldots c_k$ be a product of disjoint cycles in $S_n$. Let $\\sigma$ be any permutation. Then\n$$\\sigma c_1c_2\\ldots c_k\\sigma^{-1} = (\\sigma c_1\\sigma^{-1})(\\sigma c_2 \\sigma^{-1})\\ldots (\\sigma c_k\\sigma^{-1}).$$\n\nBut by the theorem on conjugation of cycles, this will have the same cycle structure as $\\alpha$.\n\nConversely, let $\\alpha = c_1c_2\\ldots c_k$ and $\\beta = d_1d_2\\ldots d_k$ be permutations with the same cycle structure.\n\nLet $a_1, a_2, \\ldots a_s$ be the elements of the cycles of $\\alpha$ in order (including $1$-cycles), and let $b_1, b_2, \\ldots, b_s$ be the elements of the cycles of $\\beta$ in order (including $1$-cycles). Then the permutation that sends $a_i$ to $b_i$ for all $1 \\leq i \\leq s$ will conjugate $\\alpha$ to $\\beta$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Alternating Group}\n\n\\begin{definition}\nA permutation is even if it is a product of an even number of transpositions.\n\\end{definition}\n\n\\begin{theorem}\nLet $\\epsilon$ be the identity permutation. Then $\\epsilon$ is an even permutation.\n\\end{theorem}\n\n\\begin{proof}\nWe will show that if $\\epsilon$ is a product of $k \\geq 2$ transpositions, then it is the product of $k - 2$ transpositions, which will prove the result, as the identity is not a transposition.\n\nLet $\\epsilon = s_1s_2\\ldots s_k$ and suppose that $s_j = (x, a)$ but $x$ does not appear in $s_{j+1}, s_{j+2}, \\ldots, s_k$.\n\nLet $s_{j-1} = (y, b)$. There are four cases:\n\n(i) If $s_{j-1} = (x, a)$ we are done.\n\n(ii) If $s_{j-1} = (x, b)$ with $b \\neq a$ and $b \\neq x$ then $s_{j-1}s_j = (x, a)(a, b)$.\n\n(iii) If $s_{j-1} = (y, a)$ with $y \\neq x$, $y \\neq a$ then $s_{j-1}s_j = (x, y)(y, a)$.\n\n(iv) If $s_{j-1} = (y, b)$ with $y \\neq x$, $y \\neq a$, $b \\neq x$ and $b\\neq a$ then $s_{j-1}s_j = (x, a)(y, b)$.\n\nIn all cases, we may move the first appearance of $x$ back or cancel a pair of transpositions.\n\nAs $x$ cannot appear just once in the identity, we must always eventually end up in case (i). $\\square$\n\\end{proof}\n\n\\begin{corollary}\nEvery permutation is either odd or even, but not both.\n\\end{corollary}\n\n\\begin{proof}\nIf a permutation were both, the identity could be written as a product of an even permutation and the inverse of an odd permutation, which would be odd. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe \\emph{alternating group} on $n$ elements is the subset of $S_n$ consisting of even permutations. We denote it $A_n$.\n\\end{definition}\n\n\\begin{theorem}\nThe set $A_n$ is a group under composition of permutations.\n\\end{theorem}\n\n\\begin{proof}\nIt is clearly a subgroup of $S_n$ because it is closed under composition and taking of inverses. $\\square$\n\\end{proof}\n\n\\begin{theorem}\n$|A_n| = n!/2$.\n\\end{theorem}\n\n\\begin{proof}\nWe show that half of the elements of $S_n$ are in $A_n$.\n\nLet $\\tau$ be a fixed transposition. Define $f : S_n \\to S_n$ by $f(\\sigma) = \\tau\\sigma$. This is a bijection between the sets of odd and even permutations. Note $f(\\tau\\sigma) = \\tau\\tau\\sigma = \\sigma$, which implies that $f$ is surjective, and it is clearly injective. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe group $A_n$ is generated by its $3$-cycles.\n\\end{theorem}\n\n\\begin{proof}\nWe note:\n\n(i) $(a, b)(c, d) = (a, c, b)(a, c, d)$.\n\n(ii) $(a, b)(b, c) = (a, b, c)$.\n\n(iii) $(a, b)(a, b) = (a, b, c)^2$. $\\square$\n\\end{proof}\n\n\\subsubsection{A Presentation of $S_n$}\n\n\\begin{theorem}\nThe symmetric group $S_n$ has the presentation\n$$\\langle T \\;|\\; t_i^2 = 1, (t_it_{i+1})^3 = 1, (t_it_j)^2 = 1 \\;\\;\\mbox{for}\\;\\; |i - j| > 1 \\rangle,$$\nwhere $T = \\{t_1, t_2, \\ldots, t_{n-1}\\}$.\n\\end{theorem}\n\n\\begin{proof}\nLet the group in the theorem be denoted $G_n$.\n\nWe already know that $S_n$ is generated by transpositions $t_i = (i, i+1)$. It is also easy to check that the given relations hold in $S_n$.\n\nThus there is a surjective group homomorphism $\\phi : G_n \\to S_n$ which maps the symbol $t_i$ to the transposition $t_i$.\n\nAs $S_n$ is finite, it only remains to show that $|G_n| \\leq n!$. We will prove this by induction, the basecase $n = 2$ being clear.\n\nSuppose the result is true for $G_n$ and let $H$ be the subgroup of $G_{n + 1}$ generated by $\\{t_1, t_2, \\ldots, t_n\\}$. By induction $|H| \\leq n!$. We will investigate the cosets of $H$ in $G_{n+1}$.\n\nLet $H_n = H$, $H_{n-1} = t_nH$, $H_{n-2} = t_{n-1}t_nH$, $\\ldots$, $H_0 = t_1t_2\\ldots t_nH$. We will show that these are precisely the cosest of $H$ in $G_{n+1}$ which will prove the result.\n\nTo prove this, it suffices to show that $\\{H_0, H_1, \\ldots, H_n\\}$ is permuted by left multiplication by elements of $G_{n+1}$, since all such cosets include the cosets of $H = H_0$.\n\nAs $G_n$ is generated by $t_1, t_2, \\ldots, t_n$ it is enough to show this for left multiplication by these elements. We will compute $t_iH_j$ for all $1 \\leq i < n$ and $0 \\leq j \\leq n$.\n\nIt's clear that $t_iH_i = H_{i-1}$ and $t_iH_{i-1} = H_i$. Therefore, suppose that $j \\neq i, i - 1$. We will show that $t_iH_j = H_j$ in these cases.\n\nLet us denote $t_kt_{k_1}\\ldots t_{l}$ by $P(k, l)$.\n\nFirstly, if $j \\geq i + 1$ we have\n$$t_iH_j = t_iP(j+1, n)H = P(j+1, n)t_iH = P(j+1, n)H = H_j.$$\n\nIn the case $j \\leq i - 2$ we have\n\\begin{multline*}\ny_iH_j = y_iP(j+1, n)H = P(j+1, i-2)t_it_{i-1}t_iP(i+1, n)H =\\\\\n P(j+1, i-2)t_{i-1}t_it_{i-1}P(i+1, n)H = P(j+1, n)t_{i-1}H = P(j+1, n)H = H_j.\n\\end{multline*}\n$\\square$\n\\end{proof}\n\n\\section{Groups Acting on a Set}\n\n\\subsection{Groups Actions}\n\n\\subsubsection{Group Actions}\n\n\\begin{definition}\nLet $A$ be a set and $G$ a group. A \\emph{left group action} of $G$ on $A$ is a map $G\\times A \\to A$ denoted by $(g, a) \\mapsto ga$ for all $g \\in G$ and $a \\in A$ such that the following hold.\n\\begin{enumerate}\n\\item $g_1(g_2a) = (g_1g_2)a$ for all $g_1, g_2 \\in G$ and $a \\in A$\n\\item $1a = a$ for all $a \\in A$\n\\end{enumerate}\nSimilarly, a \\emph{right group action} is a map $A\\times G \\to A$ such that\n\\begin{enumerate}\n\\item $(ag_1)g_2 = a(g_1g_2)$ for all $g_1, g_2 \\in G$ and $a \\in A$\n\\item $a1 = a$ for all $a \\in A$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group acting on a set $A$ on the left. For each $g \\in G$ we let $\\sigma_g : A \\to A$ be defined by $\\sigma_g(a) = ga$ for all $a \\in A$. Then the following hold.\n\\begin{enumerate}\n\\item Each $\\sigma_g$ is a permutation of $A$, i.e. $\\sigma_g \\in S_A$\n\\item The map $\\varphi : G \\to S_A$ defined by $\\varphi(g) = \\sigma_g$ is a group homomorphism\n\\item If $\\psi : G \\to S_A$ is any homomorphism then the map $G\\times A \\to A$ defined by $(g, a) \\mapsto \\psi(g)a$ is a left group action of $G$ on $A$\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n1. It is easy to see that $\\sigma_g\\circ \\sigma_{g^{-1}}$ is the identity on $A$ and similarly for $\\sigma_{g^{-1}}\\circ \\sigma_g$. Thus $\\sigma_g$ is a bijection and hence a permutation of $A$.\n\n2. It is easy to show that $\\sigma_{g_1g_2} = \\sigma_{g_1}\\circ\\sigma_{g_2}$. Therefore $\\phi(g_1g_2) = \\varphi(g_1)\\circ\\varphi_{g_2}$.\n\n3. Let $g_1, g_2 \\in G$ and $a \\in A$. Then it is easy to check that $g_1(g_2(a)) = \\psi(g_1)(\\psi(g_2)(a))$. Now on account of $\\psi$ being a homomorphism, this is equal to $\\psi(g_1g_2) = (g_1g_2)(a)$. But this is precisely the first requirement for a group representation.\n\nFor $a \\in A$ we have $1a = \\psi(1)(a) = a$. Thus we have a group action of $G$ on $A$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe map $\\varphi : G \\to S_A$ or more generally any homomorphism $\\psi$ as in the theorem is called a \\emph{permutation representation} of $G$ on the set $A$.\n\\end{definition}\n\n\\subsubsection{The Trivial Group Action}\n\n\\begin{theorem}\nLet $G$ be a group and $A$ a set. The map $G\\times A \\to A$ defined by $(g, a) = a$ for all $g \\in G$ and $a \\in A$ is a group action.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe group action of the theorem is called the trivial group action of $G$ on $A$.\n\\end{definition}\n\n\\begin{example}\nLet $\\varphi : G \\to S_A$ be the permutation representation given by $\\varphi(g) = \\;\\;\\mbox{id}_A$. Clearly $\\varphi : G \\to S_A$ is the trivial homomorphism of the group $G$ to the trivial subgroup $\\{\\mbox{id}_A\\}$ of $S_A$.\n\\end{example}\n\n\\subsubsection{Regular Group Actions}\n\nGroups can act on themselves by a left or right regular action.\n\n\\begin{definition}\nLet $G$ be a group. The \\emph{left regular action} of $G$ on itself is the group action defined by $(g, a) \\mapsto ga$ for all $g, a \\in G$, where $ga$ on the right hand side here stands for the group operation. The right regular action of $G$ on itself is defined similarly.\n\\end{definition}\n\n\\begin{theorem}\nThe left and right regular actions of $G$ on itself are left and right group actions, respectively.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{The Action of the Symmetric Group}\n\n\\begin{theorem}\nLet $X$ be a nonempty set and $S_X$ be the symmetric group on $X$. Then the action defined by $(\\sigma, x) = \\sigma(x)$ for $\\sigma \\in S_X$ and $x \\in X$ is a group action.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\nLet $\\varphi : S_X \\to S_X$ be the permutation representation defined by $\\varphi(\\delta) = \\sigma_{\\delta}$ for all $\\delta \\in S_X$ where $\\sigma_\\delta$ is defined by $\\sigma_\\delta(x) = \\delta_x$.\n\nClearly $\\varphi(\\delta) = \\delta$ for all $\\delta \\in S_X$ and so $\\varphi$ is simply the identity homomorphism on $S_X$.\n\n\\subsubsection{The Group Action of Conjugation by a Subgroup}\n\n\\begin{theorem}\nLet $G$ be a group and $H \\leq G$. The map $(h, g) \\mapsto hgh^{-1}$ is a group action of $H$ on $G$. We say that $H$ acts by conjugation on $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Faithful Group Actions}\n\n\\begin{definition}\nLet $A$ be a set and $G$ a group acting on $A$. We say that the action is \\emph{faithful} if the associated representation homomorphism $\\varphi : G \\to S_A$ defined by $\\varphi(g) = \\sigma_g$ where $\\sigma_g(x) = gx$, is injective.\n\\end{definition}\n\n\\begin{theorem}\nLet $A$ be a set and $G$ a group acting on $A$. Then $G$ acts faithfully on $A$ iff for every pair of distinct elements $g_1, g_2 \\in G$ there exists an element $a \\in A$ such that $g_1a \\neq g_2a$.\n\\end{theorem}\n\n\\begin{proof}\nThis just says $\\sigma_{g_1} \\neq \\sigma_{g_2}$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $A$ be a set and $G$ a group acting on $A$. Then $G$ acts faithfully on $A$ iff for every $g \\neq e$ in $G$ there exists $a \\in A$ such that $ga \\neq a$.\n\\end{theorem}\n\n\\begin{proof}\nThis just says that the kernel of $\\varphi$ is trivial. $\\square$\n\\end{proof}\n\n\\subsubsection{Transitive Group Actions}\n\n\\begin{definition}\nLet $A$ be a set and $G$ a group acting on $A$. Then $G$ is said to act \\emph{transitively} on $A$ if for every $a, b \\in A$ there exists $g \\in G$ such that $ga = b$.\n\\end{definition}\n\n\\subsubsection{Regular Group Actions}\n\n\\begin{definition}\nThe action of a group $G$ on a set $A$ is said to be \\emph{regular} if it is faithful and transitive. We say that $A$ is a \\emph{principal homogeneous space} or $G$-torsor.\n\\end{definition}\n\n\\begin{theorem}\nThe action of a group $G$ on itself by left multiplication is regular.\n\\end{theorem}\n\n\\begin{proof}\nIt is clearly transitive and free. $\\square$\n\\end{proof}\n\n\\begin{corollary} (Cayley)\nEvery group $G$ can be embedded in $S_G$.\n\\end{corollary}\n\n\\begin{proof}\nThe associated permutation representation $\\varphi : G \\to S_G$ is injective as the action of a group on itself by left multiplication is faithful. $\\square$\n\\end{proof}\n\n\\subsection{Orbits and Stabilisers}\n\n\\subsubsection{The Orbit and Stabiliser of a Point}\n\n\\begin{definition}\nLet $G$ be a group acting on a nonempty set $A$ and let $a \\in A$. The \\emph{orbit} of $a$ under the action of $G$ is the set\n$$Ga = \\{b \\in A \\;|\\; b = ga \\;\\;\\mbox{for some}\\;\\; g \\in G\\}.$$\n\\end{definition}\n\n\\begin{definition}\nLet $G$ be a group acting on a nonempty set $A$ and let $a \\in A$. The \\emph{stabiliser} of $a$ in $G$ is the set\n$$G_a = \\{g \\in G \\;|\\; ga = a\\}.$$\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group acting on a set $A$. Then $G_a \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\n$G_a$ is clearly closed under the group operation of $G$.\n\nClearly $e \\in G_a$.\n\nIf $g \\in G_a$ then\n$$g^{-1}a = g^{-1}(ga) = (g^{-1}g)a = ea = a.$$\nThus $g^{-1} \\in G_a$ and $G_a$ is a subgroup of $G$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Class Equation for Group Actions}\n\n\\begin{theorem}\nLet $G$ be a group acting on a nonempty set $A$ and let $a \\in A$. Then the orbit $Ga$ is in bijection with the cosets of $G_a$, i.e. $|Ga| = [G:G_a]$.\n\\end{theorem}\n\n\\begin{proof}\nLet $f : G/G_a \\to Ga$ be a map on sets ($G_a$ need not be normal in $G$) defined by $f(gG_a) = ga$.\n\nWe will show for $g_1, g_2 \\in G$ that $g_1G_a = g_2G_a$ iff $g_1a = g_2a$ so that $f$ is well-defined and injective.\n\nClearly we have $g_1a = g_2a$ iff $(g_2^{-1}g_1)a = a$ iff $g_2^{-1}g_1 \\in G_a$ iff $g_1G_a = g_2G_a$.\n\nThe map $f$ is clearly surjective. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group acting on a nonempty set $A$. The set of orbits of the action of $G$ on $A$ partition $A$.\n\\end{theorem}\n\n\\begin{proof}\nIt is clear that two elements $a, b \\in A$ are in the same orbit iff there exists $g \\in G$ such that $a = gb$.\n\nBut this is clearly an equivalence relation. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $G$ be a group acting on a nonempty set $A$. The subset of $A$ \\emph{fixed} by $G$ is the set\n$$A^G = \\{a \\in A \\;|\\; ga = a \\;\\;\\mbox{for all}\\;\\; g \\in G\\}.$$\n\\end{definition}\n\n\\begin{theorem} (Class Equation)\nLet $G$ be a group acting on a finite, nonempty set $A$. Then\n$$|A| = |A^G| + \\sum [G:G_a],$$\nwhere the sum runs over a set of representatives $a$ of the orbits $Ga$ with $|Ga| > 1$.\n\\end{theorem}\n\n\\begin{proof}\nClear from the preceding two theorems. $\\square$\n\\end{proof}\n\nIn particular, note that the size of any orbit divides the order of the group $G$.\n\n\\subsubsection{The Class Equation for Conjugation}\n\n\\begin{theorem}\nLet $G$ be a finite group. Then\n$$|G| = |Z_G| + \\sum [G:C_G(g)],$$\nwhere the sum is over all nontrivial (more than one element) conjugacy classes in $G$.\n\\end{theorem}\n\n\\begin{proof}\nEach element of the centre has trivial conjugacy class and the converse is also true.\n\nThe rest of the sum follows immediately from Theorem \\ref{conjugacy}. $\\square$\n\\end{proof}\n\n\\section{The Sylow Theorems}\n\n\\subsection{$p$-groups}\n\n\\subsubsection{$p$-groups}\n\n\\begin{definition}\nA $p$-group for a prime $p$ is a group in which every element has order a power of $p$.\n\\end{definition}\n\n\\begin{theorem} (Cauchy)\nIf $G$ is a finite group whose order is divisible by a prime $p$ then it has an element of order $p$.\n\\end{theorem}\n\n\\begin{proof}\nWe prove the result first for abelian groups, using induction. If $|G| = p$ then any nontrivial element will do.\n\nLet $a$ be any nontrivial element and let $H = \\langle a \\rangle$. If $p \\;|\\; |H|$ then $a^{|H|/p}$ is of order $p$. If not, then $p$ divides $[G:H]$ and by induction $G/H$ has an element of order $p$. Let that element be $xH$ and let the order of $x$ in $G$ be $m$. As $(xH)^m = H$ we have that $p \\;|\\; m$ and $x^{m/p}$ has order $p$.\n\nWhen $G$ is not abelian, if $p$ divides $|Z_G|$ then by the first part, $Z_G$ contains an element of order $p$ and we are done. If not, as $p \\;|\\; |G|$ we have by the class equation there is some $a \\in G$ such that $[G:C_G(a)]$ is not divisible by $p$. This means that $|C_G(a)|$ is divisible by $p$. As $C_G(a)$ is a proper subgroup it has an element of order $p$ by induction. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $p$ be a prime number. A finite group is a $p$-group iff it has order a power of $p$.\n\\end{theorem}\n\n\\begin{proof}\nIf a group $G$ has order $p^k$, every element of the group must have order dividing $p^k$ and so \n$G$ must be a $p$-group.\n\nIf $G$ does not have order $p^k$ for some $k \\in \\N$ then its order is divisible by some prime $q$ or it is the trivial group. In either case it is not a $p$-group. $\\square$\n\\end{proof}\n\n\\subsubsection{Burnside's theorem for $p$-groups}\n\n\\begin{theorem} (Burnside)\nThe centre $Z_G$ of a nontrivial $p$-group $G$ is nontrivial.\n\\end{theorem}\n\n\\begin{proof}\nIf the centre is trivial, from the class equation, we must have that $[G:C_G(a)]$ is not a power of $p$ for some non-central $a \\in G$. But this means that either $|G|$ is divisible by a prime $q \\neq p$ in which case $G$ is not a $p$-group, or $[G:C_G(a)] = 1$, which means $|C_G| = |G|$. But the latter means that $a$ is central, which is a contradiction. $\\square$\n\\end{proof}\n\n\\begin{theorem} \\label{pgroupsubs}\nIf $G$ is a $p$-group of order $p^k$ it has a normal subgroup of order $p^m$ for all $1 \\leq m \\leq n$.\n\\end{theorem}\n\n\\begin{proof}\nWe proceed by induction. The result is trivial for $k = 0, 1$.\n\nBy the previous theorem, $|Z_G| = p^m$ for some $1 \\leq m \\leq k$. Thus $Z_G$ has an element of order $p$ by Cauchy's theorem. Let $H$ be the subgroup it generates. Note that $H$ is a normal subgroup since it is central. By the induction hypothesis, the result is true for $G/H$.\n\nTherefore by the correspondence theorem $G$ has normal subgroups of order $p^m$ for $2 \\leq m \\leq k$. As $H$ has order $p^1$ the result is proved. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a finite $p$-group and $H$ a proper subgroup of $G$. Then $H$ is a proper subgroup of $N_G(H)$.\n\\end{theorem}\n\n\\begin{proof}\nRecall that $H \\leq N_G(H)$. Suppose to the contrary of the theorem that $H = N_G(H)$ and that $G$ is the smallest group with this property. As $Z_G \\leq N_G(H)$ we have that $Z_G \\leq H$. But $Z_G$ is normal in $H$.\n\nBut $Z_G$ is nontrivial by the theorem above and so $G/Z_G$ furnishes a smaller group where the normalizer of the subgroup $H/Z_G$ is $N/Z_G$ and $N/Z_G = N/Z_G$, which is a contradiction of the minimality of $G$. $\\square$\n\\end{proof}\n\n\\subsubsection{Basic results regarding $p$-groups}\n\n\\begin{theorem}\nLet $G$ be a finite $p$-group. Every nontrivial normal subgroup $N$ of $G$ intersects $Z_G$ nontrivially.\n\\end{theorem}\n\n\\begin{proof}\nAs $N$ is a normal subgroup, it is a union of conjugacy classes. Each conjugacy class has $[G:C_G(a)]$ elements for $a$ in the conjugacy class. But this is a power of $p$ divisible by $p$ unless $a$ is in the centre of $G$.\n\nAs $N$ has order a power of $p$, the number of elements of $N$ in the centre of $G$ must also be divisible by $p$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA group $G$ of order $p^2$ is abelian.\n\\end{theorem}\n\n\\begin{proof}\nIf $G$ is not abelian then $Z_G$ is a proper subgroup of $G$. But it is not trivial by Burnside's theorem and so we must have $|Z_G| = p$.\n\nLet $g \\in G$ but $g \\notin Z_G$. Note that $g \\in C_G(g)$ and $Z_G \\leq C_G(g)$. But this implies $|C_G(g)| = p^2$, which implies $C_G(g) = G$ and thus $C_G(g) = G$ which is a contradiction as this would imply $g \\in Z_G$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe centre of a non-abelian group $G$ of order $p^3$ has order $p$.\n\\end{theorem}\n\n\\begin{proof}\nWe have that $|Z_G| \\in \\{1, p, p^2, p^3\\}$. As $G$ is non-abelian, $|Z_G| \\neq p^3$. As $G$ is a $p$-group $|Z_G| \\neq 1$.\n\nAssume $|Z_G| = p^2$. As $Z_G \\mathrel{\\unlhd} G$ the group $G/Z_G$ has order $p$ and is therefore cyclic. Thus $G$ is abelian.\n\nThe only remaining case is $|Z_G| = p$. $\\square$\n\\end{proof}\n\n\\subsection{Sylow $p$-subgroups and the Sylow Theorems}\n\n\\subsubsection{Sylow $p$-subgroups}\n\n\\begin{definition}\nLet $G$ be a finite group of order $n$ and let $p$ be a prime dividing $n$. A \\emph{Sylow $p$-subgroup of $G$} is a subgroup of order $p^k$ where $p^i \\;|\\; n$ for $1 \\leq i \\leq k$ but not for $i = k + 1$.\n\\end{definition}\n\n\\begin{definition}\nThe set of Sylow $p$-subgroups of a finite group $G$ for which $p \\;|\\; n$ is denoted Syl$_p(G)$. We will denote the number of such groups by $n_p$.\n\\end{definition}\n\n\\subsubsection{Intersection of Sylow Subgroups}\n\n\\begin{theorem}\nLet $G$ be a finite group of order $n$ and let $p$ and $q$ be distinct primes that divide $n$. A Sylow $p$-subgroup $H$ of $G$ and a Sylow $q$-subgroup $K$ of $G$ intersect trivially.\n\\end{theorem}\n\n\\begin{proof}\nThe order of $H$ is a power of $p$ and the order of $K$ is a power of $q$.\n\nBut $H \\cap K$ is a subgroup of both $H$ and $K$, thus it has order dividing a power of $p$ and a power of $q$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Sylow Theorems}\n\n\\begin{theorem} (First Sylow)\nLet $G$ be a finite group of order $n$ and let $p$ be a prime. If $p^k \\;|\\; n$ then $G$ has a subgroup of order $p^k$.\n\\end{theorem}\n\n\\begin{proof}\nFirst we consider the case where $p$ divides the order of $Z_G$. By Cauchy's Theorem, $Z_G$ has an element $a$ of order $p$. As $a \\in Z_G$ the subgroup $\\langle a \\rangle$ is normal in $G$.\n\nBy induction the quotient group $G/\\langle a \\rangle$ has a subgroup $M$ of order $p^{k-1}$. It is easy to see that the preimage of $M$ under the quotient homomorphism is a subgroup of $G$ of order $p^k$.\n\nNow consider the case where $p$ does not divide the order of $Z_G$. From the class equation we see that there is an element $g \\in G$ for which $p$ does not divide $[G:C_G(g)]$. We see that $p^k$ must divide the order of $C_G(g)$ and by induction this must have a subgroup of order $p^k$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $G$ is a finite group of order $n$ and $p$ is a prime for which $p^k \\;|\\; n$ then $G$ has a subgroup of order $p^k$.\n\\end{corollary}\n\n\\begin{proof}\nFollows immediately from the First Sylow Theorem and Theorem \\ref{pgroupsubs}. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nA group $G$ is a $p$-group iff the order of every element of $G$ is a power of $p$.\n\\end{corollary}\n\n\\begin{proof}\nIf $G$ has an element of order divisible by $q$ for some prime $q \\neq p$ then $q$ divides the order of $G$ and it is not a $p$-group.\n\nConversely, if $G$ is not a $p$-group it has order divisible by a prime $q \\neq p$ which means that it has an element of order $q$. $\\square$\n\\end{proof}\n\n\\begin{theorem} (Second Sylow)\nLet $G$ be a finite group, then the number $n_p$ of Sylow $p$-subgroups of $G$ satisfies $n_p \\equiv 1 \\pmod{p}$.\n\\end{theorem}\n\n\\begin{proof}\nLet $P$ be a Sylow $p$-subgroup. Let $g \\in G$ have order a power of $p$ and $gPg^{-1} = P$. We claim $g \\in P$. \n\nConsider the subgroup $R$ of $G$ generated by $P$ and $g$. We have $g \\in N_G(P)$ and so $R \\leq N_G(P)$. Thus $P \\mathrel{\\unlhd} R$.\n\nWe have that $|R| = |R/P||P|$. But $R/P$ is generated by $gP$ which has order a power of $p$. Thus $|R|$ is a power of $p$.\n\nWe note that $G$ acts on Syl$_p(G)$ by conjugation. Let $Q$ be a Sylow $p$-subgroup of $G$ distinct from $P$. Then $Q$ cannot be fixed under conjugation by elements of $P$ because of the claim above.\n\nLet $O$ be the orbit of $Q$ under conjugation by elements of $P$. By the orbit-stabilizer theorem $|O| = [P:P_Q]$ where $P_Q$ is the stabiliser of $Q$ under the action of $P$ by conjugation.\n\nAs $|P|$ is a power of $p$, $|O|$ must be a power of $p$. We cannot have $|O| = 1$ since $Q$ is not fixed by the whole of $P$.\n\nThe set of all Sylow $p$-subgroups is a union of $P$-orbits. The only orbit of order $1$ is $\\{P\\}$. Thus $n_p \\equiv 1 \\pmod{p}$. $\\square$\n\\end{proof}\n\n\\begin{theorem} (Third Sylow)\nAny two Sylow $p$-subgroups of a finite group $G$ are conjugate.\n\\end{theorem}\n\n\\begin{proof}\nLet $P$ be a Sylow $p$-subgroup of $G$. Let $S$ be the set of all $G$-conjugates of $P$. We see that $S$ is invariant under the action of $P$ by conjugation and that $P \\in S$.\n\nAs per the proof of the second Sylow theorem, $|S| \\equiv 1 \\pmod{p}$.\n\nIf $S$ does not cover the whole of $G$, choose $Q$ a Sylow $p$-subgroup of $G$ not in $S$. Let $T$ be the set of $G$-conjugates of $Q$. We also have $|T| \\equiv 1 \\pmod{p}$ by a similar argument to that for $S$ and $P$.\n\nBut $T$ is invariant under the action of $P$ by conjugation and $P \\notin T$. Thus $|T| \\equiv 0 \\pmod{p}$, which is a contradiction. Thus $S$ must cover the whole of $G$. $\\square$\n\\end{proof}\n\n\\begin{theorem} (Fourth Sylow)\nIf $G$ is a finite group of order $n$ and $n = p^km$ for a prime $p$ such that $p$ does not divide $m$ then $n_p$ divides $m$.\n\\end{theorem}\n\n\\begin{proof}\nLet $P$ be a Sylow $p$-subgroup of $G$. The number of conjugates of $P$ is given by $[G:N_G(P)]$ by the orbit-stabiliser theorem.\n\nAs $P \\leq N_G(P)$ we have that $|N_G(P)|$ is divisibly by $p^k$. Thus the number of conjugates of $P$ must divide $m$.\n\nBut there are $n_p$ conjugates of $P$, since all the Sylow $p$-subgroups are conjugate. $\\square$\n\\end{proof}\n\n\\subsubsection{Theorems Regarding Sylow Subgroups}\n\n\\begin{theorem}\nLet $H$ be a $p$-group which is a subgroup of a finite group $G$. Then $H$ is a contained in a Sylow $p$-subgroup of $G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $H$ act on Syl$_p(G)$ by conjugation. The size of the orbit of $P \\in$ Syl$_p(G)$ under this action is $[H:H_P]$ where $H_P$ is the stabiliser of $P$ under the action of $H$. But this is a power of $p$.\n\nAs the size of Syl$_p(G)$ is not a multiple of $p$, there must be an orbit with a single element, $P$ say. Consider the subgroup $HP$ of $G$ generated by $P$ and $H$. We have that $P$ is a normal subgroup of $HP$.\n\nBy the second isomorphism theorem $HP/P \\cong H/(H\\cap P)$. The order of the group on the left is coprime to $p$ because $P$ is a Sylow $p$-subgroup of $G$. The order of the group on the right is a power of $p$ as it divides the order of $H$. \n\nThus both groups are trivial and $H \\subseteq P$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nAn abelian group $G$ is the inner direct product of its Sylow subgroups.\n\\end{theorem}\n\n\\begin{proof}\nThere is a unique Sylow $p$-subgroup for each prime $p$ dividing the order of $G$, as all the Sylow $p$-subgroups are conjugate and $G$ is abelian.\n\nWe can proceed by induction on the number $n$ of primes dividing the order of $G$. Clearly if $n = 1$ the result holds.\n\nLet $P_1, P_2, \\ldots, P_n$ be the Sylow $p$-subgroups of $G$ of order $p_1^{a_1}, \\ldots, p_n^{a_n}$ respectively. We have by induction that $H = P_1P_2\\ldots P_{n-1}$ is the direct product of $P_1, P_2, \\ldots, P_{n-1}$. By induction it has order $m = p_1^{a_1}\\ldots p_{n-1}^{a_{n-1}}$.\n\nWe see that the subgroup of $G$ generated by $H$ and $P_n$ has order divisible by $mp_n^{a_n}$ which is the order of $G$. Thus $HP_n = G$.\n\nWe must have that $H\\cap P_n = \\emptyset$ since every element of $H$ has order dividing $m$ and every element of $P_n$ has order dividing $p_n$.\n\nA similar argument will apply if we replace $P_n$ in the argument by any of the $P_i$. As $G$ is abelian, all the $P_i$ are normal in $G$. Thus $G$ is the direct product of the $P_i$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Frattini Argument}\n\n\\begin{theorem}\nLet $G$ be a finite group, $N \\mathrel{\\unlhd} G$ and $P$ be a Sylow $p$-subgroup of $N$ for some prime $p$. Then\n$$G = NN_G(P).$$ \n\\end{theorem}\n\n\\begin{theorem}\nFor $g \\in G$ we have $gPg^{-1} \\leq gNg^{-1} = N$ because $N \\mathrel{\\unlhd} G$. Thus $gPg^{-1}$ is a Sylow $p$-subgroup of $N$. Thus there exists $n \\in N$ such that $nPn^{-1} = gPg^{-1}$ because Sylow $p$-subgroups are conjugate.\n\nThus $P = (n^{-1}g)P(n^{-1}g)^{-1}$ so that $n^{-1}g \\in N_G(P)$. Note that $g = n(n^{-1}g)$ which establishes the theorem as $g$ was arbitrary.\n\\end{theorem}\n\n\\subsection{Groups of Prescribed Order}\n\n\\subsubsection{Groups of Order $pq$}\n\n\\begin{theorem}\nLet $G$ be a group of order $pq$ where $p < q$ are primes. Then there are two possibilities:\n\\begin{enumerate}\n\\item $G$ is cyclic of order $pq$\n\\item $G$ is non-abelian with generators $a, b$ such that $a^p = b^q = 1$ and $a^{-1}ba = b^r$ for some $r \\not\\equiv 1 \\pmod{q}$, $r^p \\equiv 1 \\pmod{p}$ and $p \\;|\\; q - 1$.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\nLet $n_p, n_q$ be the number of Sylow $p$-subgroups and $q$-subgroups respectively, of $G$.\n\nBy the Sylow theorems, $n_q = 1 + kq$ for some $k \\in \\Z$ and $n_q$ divides $p$. Thus $n_q = 1$. Thus there is one Sylow $q$-subgroup and it is therefore normal in $G$. Denote it by $Q$.\n\nLet $P$ be any $p$-Sylow subgroup. Then $Q\\cap P = 1$ and $QP = G$, so $G$ is a semidirect product of $Q$ and $P$.\n\nWe will determine the action of $P$ on $Q$ by conjugation.\n\nIf $p$ does not divide $q - 1$ then $n_p = 1 + mp$ does not equal $q$ but divides $q$, so it must equal $1$. Then $G$ is a direct product of $Q$ and $P$ and therefore cyclic of order $pq$.\n\nIf $p$ does divide $q - 1$ then Aut$(Q) \\cong C_{q-1}$, which has a unique subgroup $P'$ of order $p$. The map $\\varphi : P \\to$ Aut$(Q)$ must be either trivial, which is the case above, or it must map to the unique subgroup of order $p$.\n\nLet $a$ and $b$ be generators of $P$ and $Q$ respectively. Let the action of $a$ on $Q$ by conjugation be $x \\mapsto x^r$ where $r \\neq 1 \\pmod{q}$. By the above argument we must have $r^p \\equiv 1 \\pmod{p}$.\n\nChoosing a different such $r$ is equivalent to choosing a different generator for $P$ and gives an isomorphic group $G$. Thus there is a unique group $G$ up to isomorphism in this case, and $G$ is clearly non-abelian. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups of Order $p^2q$}\n\n\\begin{theorem}\nLet $G$ be a group of order 12. Then $G$ has one Sylow $3$-subgroup or it is isomorphic to $A_4$ which has one Sylow $2$-subgroup.\n\\end{theorem}\n\n\\begin{proof}\nBy the Sylow theorems, $n_3 \\;|\\; 4$ and $n_3 \\equiv 1 \\pmod{3}$. Thus $n_3 = 1$, in which case we are done, or $n_3 = 4$.\n\nWe will first show that $A_4$ has four Sylow $3$-subgroups.\n\nWe have $|A_4| = 12$. There are eight elements that are $3$-cycles, three elements that are a pair of disjoint transpositions and the identity element.\n\nIt is easy to see there are four Sylow $3$-subgroups, each consisting of the identity and two $3$-cycles.\n\nSimilarly, there is only one Sylow $2$-subgroup consisting of the identity and three pairs of disjoint $2$-cycles.\n\nReturning to the general case, suppose that $G$ has four Sylow $3$-subgroups, i.e. Syl$_3(G) = \\{H_1, H_2, H_3, H_4\\}$. We have $H_i\\cap H_j = 1$ for $i \\neq j$. $G$ acts on Syl$_3(G)$ by conjugation.\n\nWe claim $N_G(H_i) = H_i$. This follows because all Sylow $3$-subgroups are conjugate. Thus there is only one orbit of the action of $G$, from which the theorem follows by the orbit-stabiliser theorem and the fact that $H_i \\leq N_G(H_i)$.\n\nLet $\\varphi : G \\to S_4$ be a permutation representation associated to the action of $G$ on Syl$_3(G)$. We will show the kernel of the map is trivial, i.e. the representation is faithful.\n\nBut if $g \\in$ ker$\\varphi$ it must be in the normaliser of each of the $H_i$ and thus in each of the $H_i$. But we showed this was impossible as the $H_i$ intersect trivially. Thus the permutation representation is injective.\n\nAs $G$ contains eight distinct elements of order $3$ each including the identity and the two other elements of one of the $H_i$, its image in $S_3$ must also have eight such elements. Thus its intersection with $A_4$ must contain these elements. But $A_4$ can't have a subgroup of more than $6$ elements, so the image must in fact be $A_4$.\n\nThus $G$ is isomorphic to $A_4$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group of order $p^2q$ for distinct primes $p$ and $q$. Then $G$ contains a normal Sylow subgroup.\n\\end{theorem}\n\n\\begin{proof}\nIf $p > q$ then $n_p \\equiv 1 \\pmod{p}$ and $n_p \\;|\\; q$. Thus $n_p = 1$ and the Sylow $p$-subgroup is normal in $G$.\n\nIf $q > p$ then $n_q \\equiv 1 \\pmod{q}$ and $n_q \\;|\\; p^2$. If $n_q = 1$ we are done. Thus the only remaining case is $n_q = p^2$ and $n_q \\equiv 1 \\pmod{q}$.\n\nBut then $p^2 = 1 + kq$ for some $k \\in \\mathbb{Z}$. Thus $q \\;|\\; p + 1$. But $q > p$ and so $q = p + 1$. This implies $p = 2$ and $q = 3$ as both $p$ and $q$ are prime.\n\nThus $|G| = 12$. The result follows by the previous theorem. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups of Order $p^2$}\n\n\\begin{theorem}\nLet $G$ be a group of order $p^2$ for some prime $p$. Then either $G$ is cyclic of order $p^2$ or $G \\cong C_p\\oplus C_p$.\n\\end{theorem}\n\n\\begin{proof}\nRecall that a group of order $p^2$ is abelian.\n\nLet $g \\in G$ be an element other than the identity. If the order of $g$ is $p^2$ then $G$ is cyclic.\n\nOtherwise, $g$ has order $p$. Now let $h \\in G$ be a element that is not in $\\langle g \\rangle$. Clearly $\\langle g \\rangle$ and $\\langle g \\rangle$ intersect trivially.\n\nIt's also clear that $g$ and $h$ generate the whole of $G$. And as the group $G$ is abelian, this means that $G = \\langle g \\rangle \\oplus \\langle h \\rangle$. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups of Order $30$}\n\n\\begin{theorem}\nThere are four isomorphism classes of groups $G$ of order $30$, of which one is abelian.\n\\end{theorem}\n\n\\begin{proof}\nWe note that $n_3$ is either $1$ or $10$ and $n_5$ is either $1$ or $6$. However we cannot have both $n_3 = 10$ and $n_5 = 6$. Thus either $n_3 = 1$ or $n_5 = 1$.\n\nTherefore $G$ has a subgroup $P_3$ or $P_5$ of order $3$ or $5$ respectively which is normal in $G$. Thus $H = P_3P_5$ is a subgroup of $G$ of order $15$.\n\nBy the classification of groups of order $pq$ and the fact that $5 \\not\\equiv 1 \\pmod{3}$ we have that $H$ is cyclic.\n\nAs $H$ has index $2$ in $G$ it must be normal. Thus $G \\cong H\\rtimes_{\\theta} Q$ for some homomorphism $\\theta : Q \\to$ Aut$(H)$.\n\nWe have that Aut$(H) \\cong C_4\\times C_2$. Let $p$ be a generator of $C_4$ and $q$ a generator of $C_2$. Then there are only four possible images of the non-identity element of $Q$ under $\\theta$, namely $(1, 1)$, $(p^2, 1)$, $(1, q)$ and $(p^2, q)$. The only one of these that results in an abelian group is the trivial homomorphism. $\\square$\n\\end{proof}\n\n\\section{Simple Groups}\n\n\\subsection{Simple Groups}\n\n\\subsubsection{Simple Groups}\n\n\\begin{definition}\nA group $G$ is said to be \\emph{simple} if $G$ has no proper, nontrivial, normal subgroups.\n\\end{definition}\n\n\\subsubsection{Cyclic Groups of Prime Order are Simple}\n\n\\begin{theorem}\nThe cyclic group $C_p$ with $p$ prime is simple.\n\\end{theorem}\n\n\\begin{proof}\nThere are no subgroups other than the trivial and improper subgroup. $\\square$\n\\end{proof}\n\n\\subsubsection{Finite Abelian Simple Groups}\n\n\\begin{theorem}\nThe only simple abelian groups are the cyclic groups of prime order.\n\\end{theorem}\n\n\\begin{proof}\nA subgroup of an abelian group is always normal. Therefore if $G$ is a simple abelian group it has no nontrivial, proper subgroups.\n\nIf $g \\in G$ then $\\langle g \\rangle$ is a normal subgroup of $G$. Thus $G$ must be cyclic.\n\nBut any infinite cyclic group or finite cyclic group of non-prime order has a proper, normal subgroup other than the trivial group. $\\square$\n\\end{proof}\n\n\\subsection{Simple Alternating Groups}\n\n\\subsubsection{The Group $A_5$ is Simple}\n\n\\begin{theorem}\nIf $G$ is a group of order $60$ and $n_5 > 1$ then $G$ is simple.\n\\end{theorem}\n\n\\begin{proof}\nIf $n_5 > 1$ then by the Sylow theorems, $n_5 = 6$. This accounts for $25$ of the elements of $G$. Let Syl$_5(G) = \\{P_1, P_2, \\ldots, P_6\\}$. We have $P_i\\cap P_j = \\{1\\}$ for all $i \\neq j$.\n\nSuppose that $G$ has a nontrivial, normal proper subgroup. We claim that $|H|$ is not divisible by $5$. If it were, $H$ would have a subgroup of order $5$. It will be one of the Sylow $5$-subgroups of $G$, $P_1$ say.  \n\nBut $H \\mathrel{\\unlhd} G$ and so all the conjugates of $P_1$ must be in $H$. Thus $|H| \\geq 25$.\n\nAs $|H| \\;|\\; |G|$ we must have $|H| = 30$. But we have shown above that all groups of order $30$ have a single Sylow $5$-subgroup.\n\nThus we must in fact have $|H| \\;|\\; 12$.\n\nBut any group $H$ of order $12$ has a normal subgroup $K$ of order $3$ or order $4$. As $H$ is normal in $G$, any conjugate of $K$ in $G$ must be a subgroup of $H$ and since $K$ is the only subgroup of that order, $K$ must be normal in $G$.\n\nSimilarly, if $H$ has order $6$, it contains a normal subgroup of order $3$, and by the same argument as above, this is also normal in $G$.\n\nThus we have shown that if $G$ has a nontrivial, proper normal subgroup, it has a normal subgroup $K$ of order $4$, $3$ or $2$.\n\nThus $G/K$ has order $15$, $20$ or $30$.\n\nIn a group of order $15$, $20$ or $30$ there is a normal Sylow subgroup of order $5$. But the preimage of this group in $G$ is a normal subgroup of order $20$, $15$ or $10$.\n\nBut each of these orders is divisible by $5$, which contradicts what we have proved above. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe group $A_5$ is simple.\n\\end{theorem}\n\n\\begin{proof}\nNote that $|A_5| = 60$.\n\n$A_5$ has one identity element, twenty $3$-cycles, fifteen double $2$-cycles and twenty four $5$-cycles.\n\nThe result then follows from the previous theorem by noting that $n_5 = 6$. $\\square$\n\\end{proof}\n\n\\subsubsection{The Group $A_n$ is Simple for $n \\geq 5$}\n\n\\begin{theorem}\nThe group $A_n$ is simple for $n \\geq 5$.\n\\end{theorem}\n\n\\begin{proof}\nWe will prove the result by induction on $n$, beginning with the fact that $A_5$ is simple by the previous theorem.\n\nSuppose $A_n$ is simple for $5 \\leq n < k$, but also suppose that it is not simple for $n = k$, i.e. there exists $H \\mathrel{\\unlhd} A_k$.\n\nLet $G_i$ be the stabiliser of the $i$-th element of the set $A_k$ is acting on. Each of the $G_i$ are isomorphic to $A_{k-1}$ and therefore simple.\n\nRecall that if $\\sigma = (a_1 a_2 \\ldots a_s)$ is a cycle then $\\alpha\\sigma\\alpha^{-1} = (\\alpha(a_1) \\alpha(a_2) \\ldots \\alpha(a_s))$. Thus it is clear that $\\alpha G_i \\alpha^{-1} = G_{\\alpha_i}$.\n\nWe will show that if $\\sigma \\in H$ and $\\sigma(i) = i$ for some $1 \\leq i \\leq k$ then $\\sigma = 1$.\n\nIf a $\\sigma \\neq 1$ exists in $H$ then $\\sigma \\in H\\cap G_i$. But $H\\cap G_i \\mathrel{\\unlhd} G_i$ since $H$ is a normal subgroup of $A_k$ so any conjugate of it is in $H$, and conjugation by an element of $G_i$ must yield another element of $G_i$.\n\nBut $G_i$ is simple and so $H\\cap G_i$ must be $G_i$ since it is not trivial as $\\sigma \\neq 1$ is an element. Thus $G_i \\leq H$.\n\nBy conjugation we have that $G_{\\alpha(i)} \\leq H$ for each $\\alpha \\in A_k$. Thus $G_i \\leq H$ for all $1 \\leq i \\leq k$.\n\nBut every double transposition fixes some $i$ and is an element of one of the $G_i$. Thus the whole of $A_k$ must be in $H$, i.e. $H = A_k$. But this is a contradiction as we assumed $H$ to be a proper subgroup of $A_k$. Thus $\\sigma = 1$ as claimed.\n\nIn other words, no non-identity elements of $H$ fix an $i$.\n\nBut this implies that there do not exist $\\sigma_1, \\sigma_2 \\in H$ such that $\\sigma_1(i) = \\sigma_2(i)$ for some $1 \\leq i \\leq k$.\n\nWe will now show that no element of $H$ has a cycle decomposition containing a cycle of length $3$ or greater.\n\nSuppose that such a $\\sigma = (a_1 a_2 a_3 \\ldots)$ exists. Let $\\alpha \\in A_k$ fix $a_1$ and $a_2$ but not fix $a_3$.\n\nNow $\\alpha\\sigma\\alpha^{-1} = (a_1 a_2 \\alpha(a_3) \\ldots) \\in H$ as $H$ is normal. But now have that $\\sigma(a_1) = \\alpha\\sigma\\alpha^{-1}(a_1)$. These are distinct permutations because $\\sigma(a_2) \\neq \\alpha\\sigma\\alpha^{-1}(a_2)$. But this contradicts what we have proved above.\n\nThus $H$ consists entirely of elements composed of pairs of pairwise disjoint transpositions.\n\nSuppose that $H$ contains $\\sigma = (a_1 a_2)(a_3 a_4)(a_5 a_6)\\ldots$. Let $\\alpha = (a_1 a_2)(a_3 a_5)$. Then $\\alpha\\sigma\\alpha^{-1} = (a_2 a_1)(a_5 a_4)(a_3 a_6)$. Again we have a contradiction to what we proved above as we have distinct permutations in $H$ that send $a_1$ to the same place.\n\nBut now the only element that can be in $H$ is the identity and $A_k$ must be simple. $\\square$\n\\end{proof}\n\n\\subsubsection{$A_3$ is Simple, $A_4$ is not Simple}\n\n\\begin{theorem}\n$A_3$ is simple.\n\\end{theorem}\n\n\\begin{proof}\n$|A_3| = 3$ and is  cyclic group of order $3$ and is therefore simple. $\\square$\n\\end{proof}\n\n\\begin{theorem}\n$A_4$ is not simple.\n\\end{theorem}\n\n\\begin{proof}\n$|A_4| = 12$ and we have already shown that either $n_2 = 1$. $\\square$\n\\end{proof}\n\n\\section{Subnormal Series}\n\n\\subsection{Composition Series}\n\n\\subsubsection{Composition Series}\n\n\\begin{definition}\nLet $G$ be a group. A \\emph{composition series} for $G$ of length $n$ is a finite chain of subgroups\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G$$\nsatisfying the following:\n\\begin{enumerate}\n\\item $G_i \\mathrel{\\unlhd} G_{i + 1}$\n\\item $G_{i+1}/G_i$ is simple\n\\end{enumerate}\nThe quotients $G_{i+1}/G_i$ are called the \\emph{composition factors} of the series.\n\\end{definition}\n\n\\begin{theorem}\nAny finite group $G$ has a composition series.\n\\end{theorem}\n\n\\begin{proof}\nStart with the group $G_n = G$ and at each step take a maximal, normal, proper subgroup, $G_i$ of $G_{i+1}$, which exists because $G$ is finite.\n\nThe quotient $G_{i+1}/G_i$ is simple by the correspondence theorem and the maximality of $G_i$ in $G_{i+1}$.\n\nThe process must terminate as $G$ is finite. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nFor a finite group $G$, the order of $G$ is the product of the orders of the composition factors of $G$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{The Zassenhaus Butterfly Lemma}\n\n\\begin{theorem}\nLet $G$ be a group and let $H$, $H'$, $K$, $K' \\leq G$ be such that $H' \\mathrel{\\unlhd} H$ and $K' \\mathrel{\\unlhd} K$. Then\n$$H'(H\\cap K') \\mathrel{\\unlhd} H'(H\\cap K) \\;\\;\\mbox{and}\\;\\; K'(K\\cap H') \\mathrel{\\unlhd} K'(H\\cap K).$$\nFurthermore,\n$$\\bigl(H'(H\\cap K)\\bigr)/\\bigl(H'(H\\cap K')\\bigr) \\cong \\bigl(K'(H\\cap K) \\bigr)/\\bigl(K'(K\\cap H')\\bigr).$$\n\\end{theorem}\n\n\\begin{proof}\nFirst note that $H \\cap K \\leq H$.\n\nLet $\\phi : H \\to H/H'$ be the natural projection. Then $(\\phi^{-1}\\circ \\phi)(H\\cap K) = H'(H \\cap K)$, is a group.\n\nNote that $H \\cap K' \\mathrel{\\unlhd} H \\cap K$. Hence\n$$(\\phi^{-1}\\circ \\phi)(H\\cap K') = H'(H\\cap K')$$\nis a normal subgroup of\n$$(\\phi^{-1}\\circ \\phi)(H\\cap K) = H'(H\\cap K).$$\n\nNow, let $\\rho : H'(H\\cap K) \\to \\bigl(H'(H\\cap K)\\bigr)/ \\bigl(H'(H\\cap K')\\bigr)$ be the natural projection.\n\nNote that\n$$(H\\cap K)\\cap \\bigl(H'(H\\cap K')\\bigr) = (H'\\cap K)(H \\cap K').$$\n\nThus by the homomorphism theorems,\n$$\\bigl(H'(H\\cap K)\\bigr)/\\bigl(H'(H\\cap K')\\bigr) \\cong (H\\cap K)/\\bigl((H'\\cap K)(H \\cap K')\\bigr).$$\n\nThe other half of the lemma follows by symmetry. $\\square$\n\\end{proof}\n\n\\subsubsection{The Schreier Refinement Theorem}\n\n\\begin{definition}\nLet $G$ be a group. Any series of groups\n$$1 \\mathrel{\\unlhd} G_1 \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} G_n = G$$\nis called a \\emph{subnormal series}.\nA second subnormal series\n$$1 \\mathrel{\\unlhd} H_1 \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} H_m = G$$\nis said to be a \\emph{refinement} of the first if every $G_i$ appears as a $H_j$ in the same order.\n\\end{definition}\n\n\\begin{theorem} (Schreier)\nAny two subnormal series of a group $G$ have refinements that have isomorphic factor groups, up to reordering.\n\\end{theorem}\n\n\\begin{proof}\nLet\n$$1 = H_0 \\leq H_1 \\leq \\cdots \\leq H_n = G$$\nand\n$$1 = K_0 \\leq K_1 \\leq \\cdots \\leq K_m = G$$\nbe two subnormal series for $G$.\n\nWe refine the series of $H_k$ as follows. For $0 \\leq i \\leq n - 1$ and $0 \\leq j \\leq m$ define\n$$H'_{im + j} = H_i(H_{i+1}\\cap K_j).$$\n\nNote that\n$$H'_{im} = H_i(H_{i+1}\\cap K_0) = H_i.$$\nThus every group that appears in the original series of $H_i$ appears in the new series.\n\nNote that when $m \\;|\\; k$ we have $k = im + m = (i + 1)m$, meaning that there is an ambiguity in this case.\n\nFor the series to be well-defined, we'd require\n$$H_i(H_{i+1}\\cap K_m) = H_{i+1}(H_{i+2}\\cap H_0).$$\n\nBut the the left and right hand sides are both $H_{i+1}$, thus the series is well-defined.\n\nWe will show that this is a subnormal series (except for some possible duplication). Using the representation $k = im + j$ in which $j < m$ we have that\n$$H'_{k+1} = H_i(H_{i+1}\\cap K_{j + 1}).$$\n\nAs $K_j \\mathrel{\\unlhd} K_{j+1}$ we have that\n$$H'_k = H_i(H_{i+1}\\cap K_j) \\mathrel{\\unlhd} H_i(H_{i+1}\\cap H_{j+1}) = H'_{k+1}.$$\n\nNote that it is still possible that $H'_k = H'_{k+1}$ for some $k$. \n\nWe apply a similar construction to create a refinement of the series of $K_k$, by defining for $k = in + j$\n$$K'_k = K_i(K_{i+1}\\cap H_j).$$\n\nNow let $k = um + v$ and $l = vn + u$. We have\n\\begin{align*}\n\\frac{H'_{k+1}}{H'_k} &= \\frac{H_u(H_{u+1}\\cap K_{v+1})}{H_u(H_{u+1}\\cap H_v)}\\\\\n&\\cong \\frac{K_v(K_{v+1}\\cap H_{u+1})}{K_v(K_{v+1}\\cap H_U)}\\\\\n&= \\frac{K'_{l+1}}{K'_l},\n\\end{align*}\nwhere the isomorphism follows from Zassenhaus' lemma.\n\nThus the series have isomorphic factors.\n\nNote that it may still be that some of the factors are redundant because of equal terms in the sequences, as noted above. But we can simply remove these redundant elements. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nLet $G$ be a group with a composition series. Any subnormal series of $G$ can be refined to a composition series.\n\\end{corollary}\n\n\\begin{proof}\nSimply take one of the series to be the composition series, in the theorem and the other to be the given subnormal series. As there are no nontrivial refinements of a composition series, the result follows. $\\square$\n\\end{proof}\n\n\\subsubsection{The Jordan-H\\\"{o}lder Theorem}\n\n\\begin{theorem}\nLet $G$ be a group. The composition factors of any two composition series for $G$ are isomorphic in pairs, though the order of the factors may be different.\n\\end{theorem}\n\n\\begin{proof}\nWe proceed by induction on $|G|$. The theorem is true for $|G| = 2$.\n\nAssume the result is true for all groups of order less than $n$ and suppose $G$ is a group of order $n$.\n\nIf $G$ is simple, the theorem is trivially true. Otherwise, suppose that\n$$1 \\mathrel{\\unlhd} A_r \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} A_1 \\mathrel{\\unlhd} A \\mathrel{\\unlhd} G$$\nand\n$$1 \\mathrel{\\unlhd} B_s \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} B_1 \\mathrel{\\unlhd} B \\mathrel{\\unlhd} G$$\nare two composition series for $G$.\n\nIf $A = B$ then $G/A = G/B$ and by the inductive hypothesis all the other quotients are the same in pairs, up to order, and we are done.\n\nIf $A \\neq B$, consider the group $AB$ of $G$. Now $A$ and $B$ are distinct and maximal in $G$, and thus $AB = G$.\n\nNow let $D = A\\cap B$. By the second isomorphism theorem \n\\begin{equation}\\label{gabd}\nG/A \\cong B/D\\;\\;\\mbox{and}\\;\\;G/B \\cong A/D.\n\\end{equation}\nBut $G/A$ and $G/B$ are simple, thus so are $B/D$ and $A/D$. In other words, $D$ is a maximal normal subgroup of $A$ and $B$.\n\nLet $1 \\mathrel{\\unlhd} D_t \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} D_1 \\mathrel{\\unlhd} D$ be a composition series for $D$.\n\nConsider the quotient groups\n\\begin{equation}\\label{comp1}G/A, A/D, D/D_1, \\ldots, D_t, 1,\\end{equation}\nand\n$$G/A, A/A_1, \\ldots, A_r, 1.$$\nBy the induction hypothesis, the theorem is true for $A$ and so the sequences above are isomorphic in pairs. In particular, $t = r$.\n\nSimilarly, the quotients\n\\begin{equation}\\label{comp2}G/B, B/D, D/D_1, \\ldots, D_t, 1\\end{equation}\nis isomorphic in pairs with\n$$G/B, B/B_1, \\ldots, B_s, 1,$$\nand $s = r$.\n\nBut the sequences \\eqref{comp1} and \\eqref{comp2} are clearly isomorphic in pairs by \\eqref{gabd} and so we are done. $\\square$\n\\end{proof}\n\n\\subsubsection{Dedekind's Modular Law}\n\n\\begin{theorem}\nIf $A, B, C \\leq G$ with $A \\subseteq B$ then\n$$A(B\\cap C) = B\\cap AC.$$\n\\end{theorem}\n\n\\begin{proof}\nFirst note that $A \\subseteq B$ and $B\\cap C \\subseteq B$, thus $A(B\\cap C) \\subseteq B$. Also note that $B\\cap C \\subseteq C$, thus $A(B\\cap C) \\subseteq AC$. Thus we have shown that $A(B\\cap C) \\subseteq B\\cap AC$.\n\nFor the other direction, let $b \\in B\\cap AC$. Then $b = ac$ for some $a \\in A$ and $c \\in C$. But then $c = ba^{-1}$ and so $c \\in B$. Thus $c \\in B\\cap C$. Thus $b = ac \\in A(B\\cap C)$. $\\square$\n\\end{proof}\n\n\\subsubsection{Normal Subgroups of a Group with Composition Series}\n\n\\begin{theorem}\nLet $G$ be a group with composition series and $N \\mathrel{\\unlhd} G$, then $N$ has a composition series.\n\\end{theorem}\n\n\\begin{proof}\nSuppose $G$ has a composition series\n$$1 = G_0 \\mathrel{\\unlhd} G_1 \\mathrel{\\unlhd} \\cdots \\mathrel{\\unlhd} G_n = G.$$\nDefine $N_i = N\\cap G_i$. Then\n$$1 = N_0 \\leq N_1 \\leq \\cdots \\leq N_n = N.$$\n\nLet $x \\in N_i$ and $g \\in N_{i+1}$, then $g^{-1}xg \\in G_i\\cap N = N_i$ by the normality of $G_i$ in $G_{i+1}$. Thus we see that the $N_i$ form a subnormal series.\n\nBut\n\\begin{align*}\nN_i/N_{i+1} &= \\frac{N\\cap G_{i+1}}{N\\cap G_i}\\\\\n&= \\frac{N\\cap G_{i+1}}{(N\\cap G_{i+1})\\cap G_i}\\\\\n&\\cong \\frac{(N\\cap G_{i+1})G_i}{G_i}\n\\end{align*}\nby the second isomorphism theorem.\n\nAs $N \\mathrel{\\unlhd} G$ we have that $N\\cap G_{i+1} \\mathrel{\\unlhd} G_{i+1}$. Thus, as $G_i \\mathrel{\\unlhd} G_{i+1}$ we have that $(N\\cap G_{i+1})G_i \\mathrel{\\unlhd} G_{i+1}$.\n\nTherefore, by the correspondence theorem we have that\n$$\\frac{(N\\cap G_{i+1})G_i}{G_i} \\mathrel{\\unlhd} \\frac{G_{i+1}}{G_i}.$$\n\nBut the latter is simple and so either\n$$\\frac{(N\\cap G_{i+1})G_i}{G_i} = 1 \\;\\;\\mbox{or}\\;\\; \\frac{G_{i+1}}{G_i}.$$\n\nApplying this to the isomorphism we proved above, we have that either $N_i = N_{i+1}$ or $N_{i+1}/N_i$ is simple.\n\nTherefore if we delete any repetitions in the subnormal series of groups $N_i$, we obtain a composition series for $N$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group with composition series and $N \\mathrel{\\unlhd} G$, then $G/N$ has a composition series.\n\\end{theorem}\n\n\\begin{proof}\nAs $N$ is normal in $G$ we have\n$$N = G_0N \\leq G_1N \\leq \\cdots \\leq G_nN = G.$$\n\nThus from the correspondence theorem we have\n$$1 = G_0N/N \\leq G_1N/N \\leq \\cdots \\leq G_nN/N = G/N.$$\n\nFor simplicity, write $Q_i = G_iN/N$. If $x \\in G_i$ and $g \\in G_{i+1}$ we have $g^{-1}xg \\in G_i$, thus\n$$(Ng)^{-1}(Nx)(Ng) \\in G_iN/N = Q_i.$$\nThus $Q_i \\mathrel{\\unlhd} Q_{i+1}$.\n\nFrom $G_i \\leq G_{i+1}$ we have by Dedekind's modular law that\n$$G_iN\\cap G_{i+1} = (G_{i+1}\\cap N)G_i.$$\n\nWe then have\n\\begin{align*}\nQ_{i+1}/Q_i &= \\frac{G_{i+1}}{G_iN/N}\\\\\n&= \\frac{G_{i+1}N}{G_iN}\\\\\n&= \\frac{(G_{i+1}G_i)N}{G_iN}\\\\\n&= \\frac{G_{i+1}}{G_{i+1}\\cap G_iN}\\\\\n&= \\frac{G_{i+1}}{(G_{i+1}\\cap N)G_i}\\\\\n&= \\frac{G_{i+1}/G_i}{(G_{i+1}\\cap N)G_i/G_{i+1}},\n\\end{align*}\nwhere we have used in turn, the third isomorphism theorem, $G_i \\leq G_{i+1}$, the second isomorphism theorem, Dedekind's modular law and the third isomorphism theorem.\n\nAs $G_{i+1}/G_i$ is simple, the final quotient above is either trivial or isomorphic to $G_{i+1}/G_i$. The same then applies to $Q_{i+1}/Q_i$.\n\nUpon deleting repetitions, we obtain a composition series for $G/N$. $\\square$\n\\end{proof}\n\n\\subsubsection{Abelian Groups with Composition Series}\n\n\\begin{theorem}\nLet $G$ be an abelian group. If $G$ has a composition series then $G$ is finite.\n\\end{theorem}\n\n\\begin{proof}\nThe composition factors of $G$ must be simple and abelian, thus cyclic of prime order. As the order of $G$ is the product of the orders of the composition factors, the result follows. $\\square$\n\\end{proof}\n\n\\subsection{Solvable Groups}\n\n\\subsubsection{Solvable Groups}\n\n\\begin{definition}\nA group $G$ is said to be \\emph{solvable} if it has a subnormal series\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G,$$\nsuch that $G_{i+1}/G_i$ is abelian.\n\\end{definition}\n\n\\begin{theorem}\nEvery abelian group is solvable.\n\\end{theorem}\n\n\\begin{proof}\n$1 = G_0 \\leq G_1 = G$ is a composition series such that $G_1/G_0$ is abelian. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nThe group $S_n$ is not solvable for $n \\geq 5$.\n\\end{theorem}\n\n\\begin{proof}\nWe know that $A_n$ is simple for $n \\geq 5$ and so the normal series\n$$1 \\leq A_n \\leq S_n$$\nis a composition series. Its composition factors are $C_2$ and $A_n$, the latter of which is not abelian. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA finite group $G$ is solvable iff it has a composition series with composition factors that are cyclic of prime order.\n\\end{theorem}\n\n\\begin{proof}\nSuppose $G$ is solvable so that it has a subnormal series\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G$$\nwith abelian factors $G_{i+1}/G_i$.\n\nAs it is a finite group it has a composition series. Therefore by the Schreier refinement theorem, the subnormal series can be refined to a composition series. Thus between $G_i$ and $G_{i+1}$ we have a refinement\n$$G_i = H_{i,0} \\leq H_{i,1} \\leq \\cdots \\leq H_{i, m} = G_{i+1},$$\nwith $H_{i, j+1}/H_{i, j}$ simple for all $j$.\n\nBut as $G_i \\mathrel{\\unlhd} G_{i+1}$ we have that $G_i \\mathrel{\\unlhd} H_{i, j+1}$ for all $0 \\leq j < m$. Then $H_{i, j+1}/G_i$ is a subgroup of $G_{i+1}/G_i$ and therefore abelian.\n\nBut now by the second isomorphism theorem, $H_{i, j+1}/H_{i, j}$ is a quotient of $H_{i, j+1}/G_i$ and therefore also abelian. As it is also simple, it must be cyclic of prime order.\n\nConversely, suppose $G$ has a composition series with each composition factor cyclic of prime order. Then this composition series is a subnormal series with each factor abelian and $G$ is solvable. $\\square$\n\\end{proof}\n\n\\subsubsection{Derived Subgroups}\n\n\\begin{definition}\nLet $G$ be a group. We call $[G, G]$ the \\emph{first derived subgroup} of $G$, denoted $G'$ or $G^{(1)}$. The \\emph{$n$-th derived subgroup} of $G$ is the group $[G^{(n-1)}, G^{(n-1)}]$. We denote it $G^{(n)}$.\n\\end{definition}\n\n\\begin{theorem}\nLet $G$ be a group. We have that\n$$G^{(n)} \\leq G^{(n-1)} \\leq \\cdots \\leq G^{(1)} \\leq G.$$\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA group $G$ is solvable if there is a finite integer $n$ such that the $n$-th derived subgroup of $G$ is trivial.\n\\end{theorem}\n\n\\begin{proof}\nLet\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G$$\nbe a subnormal series for $G$ with abelian factor groups.\n\nSince $G_n/G_{n-1}$ is abelian we have that the derived subgroup $G^{(1)} \\leq G_{n-1}$.\n\nBy a similar argument, $G_{n-1}^{(1)} \\leq G_{n-2}$. But we also have $G^{(2)} \\leq G_{n-1}^{(1)}$ because of $G^{(1)} \\leq G_{n-1}$. Thus $G^{(2)} \\leq G_{n-2}$.\n\nContinuing in the same way, we eventually find that $G^{(n)} \\leq 1$.\n\nConversely, if $G^{(1)} = 1$ then we have a chain of subgroups\n$$1 = G^{(n)} \\leq G^{(n-1)} \\leq \\cdots \\leq G^{(1)} \\leq G.$$\n\nBut this is a subnormal series. But $G^{(i-1)}/G^{(i)}$ is abelian iff $[G^{(i-1)}, G^{(i-1)}] \\leq G^{(i)}$. But this is trivially true. $\\square$ \n\\end{proof}\n\n\\subsubsection{Every $p$-group is solvable}\n\n\\begin{theorem}\nIf $G$ is a $p$-group then it is solvable.\n\\end{theorem}\n\n\\begin{proof}\nBegin with the group $G_0 = 1$. As $G$ is a $p$-group, $Z(G)$ is non-trivial by Burnside's theorem. Let $G_1 = Z(G)$. Note that $G_1/G_0$ is abelian since it is isomorphic to $Z(G)$.\n\nNow $Z(G)$ is normal in $G$ and the quotient $G/Z(G)$ is a $p$-group.\n\nAgain by Burnside's theorem, the centre $Z(G/G_1)$ is non-trivial. By the correspondence theorem, there is a subgroup $G_2$ of $G$ containing $G_1$ such that $G_2/G_1$ is isomorphic to $Z(G/G_1)$. Note that this quotient is abelian.\n\nWe continue the same construction until $G/G_{n-1}$ is abelian because the centre of $G/G_{n-1}$ is the whole group. We then set $G_n = G$ and we have constructed a subnormal series for $G$ with abelian cofactors. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups of Order $pq$ are Solvable}\n\n\\begin{theorem}\nIf $G$ is a group of order $pq$ with $p$ and $q$ prime, then $G$ is solvable.\n\\end{theorem}\n\n\\begin{proof}\nIf $p = q$ then $G$ is abelian and we are done. Therefore, assume that $p$ and $q$ are distinct primes with $p > q$.\n\nAs $n_p \\;|\\; q$ we either have $n_p = q$ or $n_p = 1$. But as $n_p \\equiv 1 \\pmod{p}$ the first case is impossible since $p > q$. Thus $n_p = 1$ and the unique Sylow $p$-subgroup $G_1$ is normal in $G$.\n\nWe see that\n$$1 = G_0 \\leq G_1 \\leq G_2 = G$$\nis a subnormal series of $G$ with abelian quotients (cyclic groups of order $p$ and $q$). Thus $G$ is solvable. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups of Order $p^2q$ are Solvable}\n\n\\begin{theorem}\nIf $G$ is a group of order $p^2q$ for primes $p$ and $q$ then $G$ is solvable.\n\\end{theorem}\n\n\\begin{proof}\nIf $p = q$ then $G$ is a $p$-group, which is solvable. So assume $p \\neq q$.\n\nIf $p > q$, then by the same argument as for groups of order $pq$, there is a unique Sylow $p$-subgroup $G_1$ of $G$ which is normal in $G$.\n\nThus we have that\n$$1 = G_0 \\leq G_1 \\leq G_2 = G$$\nis a subnormal series. Note that $|G_1/G_0| = p^2$, and any group of order $p^2$ is abelian. Thus $G$ is solvable.\n\nThe remaining case is when $p < q$. As usual, we have that $n_q$ is $1$, $p$ or $p^2$ by the Sylow theorems. However, $n_q = p$ is not possible as $p < q$.\n\nIf $n_q = 1$ then there is a unique Sylow $q$-subgroup $G_1$ of $G$. Then we have that\n$$1 = G_0 \\leq G_1 \\leq G_2 = G$$\nis a subnormal series, and $|G_2/G_1| = p^2$. Thus all factors are abelian and $G$ is solvable.\n\nIf $n_q = p^2$ then $G$ has $p^2(q - 1) = n - p^2$ elements of order $q$. The remaining $p^2$ elements must lie in a Sylow $p$-subgroup $G_1$ of order $p^2$.\n\nAs $G_1$ is the unique subgroup of order $p^2$, it is normal in $G$. By a similar argument to the above, $G$ is solvable. $\\square$\n\\end{proof}\n\n\\subsubsection{Homomorphic Images of Solvable Groups are Solvable}\n\n\\begin{theorem}\nLet $\\phi : G \\to H$ be a group homomorphism and $G$ a solvable group. Then $\\phi(G)$ is solvable.\n\\end{theorem}\n\n\\begin{proof}\nLet $G$ be solvable and\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G$$\nbe a subnormal series for $G$ in which each factor is abelian.\n\nlet $H_k = \\phi(G_k)$ for all $k$. Then\n$$1 = H_0 \\leq H_1 \\leq \\cdots \\leq H_n = \\phi(G)$$\nis a subnormal series with normal quotients.\n\nLet $f : G_{i+1}/G_i \\to H_{i+1}/H_i$ be defined by $f(gG_i) = \\phi(g)H_i$ for all $g \\in G_{i+1}$. It is easy to see that it is a surjective homomorphism.\n\nAs $G_{i+1}/G_i$ is abelian, so is $f(G_{i+1}/G_i) = H_{i+1}/H_i$, for all $0 \\leq i \\leq n - 1$. Thus $\\phi(G)$ is solvable. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nEvery quotient of a solvable group is solvable.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Every Subgroup of a Solvable Group is Solvable}\n\n\\begin{theorem}\nLet $G$ be a solvable group. Every subgroup $H$ of $G$ is solvable.\n\\end{theorem}\n\n\\begin{proof}\nLet\n$$1 = G_0 \\leq G_1 \\leq \\cdots \\leq G_n = G$$\nbe a subnormal series for $G$ with abelian factors. Let $H_i = H\\cap G_i$. We claim that\n$$1 = H_0 \\leq H_1 \\leq \\cdots \\leq H_n = (G\\cap H) = H$$\nis a normal series of $H$.\n\nFirstly, because $G_i \\mathrel{\\unlhd} G_{i+1}$ we have that $H_i \\mathrel{\\unlhd} H_{i+1}$. For if $x \\in H_i$ and $y \\in H_{i+1}$ then $yxy^{-1} \\in H$ and $yxy^{-1} \\in G_i$ due to $G_i$ being normal in $G_{i+1}$. Thus $yxy^{-1} \\in H\\cap G_i = H_i$.\n\nNow we will show that $H_{i+1}/H_i$ is abelian for all $i$.\n\nNote that\n$$H_i = H\\cap G_i = (H\\cap G_{i+1})\\cap G_i = H_{i+1}\\cap G_i.$$\n\nBy the second isomorhism theorem we therefore have\n$$\\frac{H_{i+1}}{H_i} = \\frac{H_{i+1}}{H_{i+1}\\cap G_i} \\cong \\frac{H_{i+1}G_i}{G_i} \\leq \\frac{G_{i+1}}{G_i}.$$\nThe last relation follows because $H_{i+1}G_i \\leq G_{i+1}$ on account of $G_i$ being normal in $G_{i+1}$.\n\nBut $G_{i+1}/G_i$ is abelian, thus $N_{i+1}/N_i$ is isomorphic to a subgroup of an abelian group. $\\square$\n\\end{proof}\n\n\\subsubsection{Direct Products of Solvable Groups}\n\n\\begin{theorem}\nLet $G$ be a group with $H \\mathrel{\\unlhd} G$. If $H$ and $G/H$ are solvable then so is $G$.\n\\end{theorem}\n\n\\begin{proof}\nLet\n$$1 = K^*_0 \\leq K^*_1 \\leq \\cdots \\leq K^*_n = G/H$$\nbe a subnormal series for $G/H$ with abelian factors.\n\nBy the correspondence theorem, we can construct a partial solvable series of $G$ starting at $H$\n$$H = K_0 \\leq K_1 \\leq \\cdots \\leq K_n = G$$\nwith $K_i \\mathrel{K_{i+1}}$ and $K_{i+1}/K_i$ abelian.\n\nBut $H$ is solvable, and so we can complete the series to a subnormal series for $G$ with abelian factors. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $H$ and $K$ are solvable groups then so is $G = H\\times K$.\n\\end{corollary}\n\n\\begin{proof}\nWe have $H \\mathrel{\\unlhd} G$ and $G/H \\cong K$. $\\square$\n\\end{proof}\n\n\\subsubsection{Groups Without Characteristically Simple Subgroups}\n\n\\begin{definition}\nLet $G$ be a group. A subgroup $N$ is said to be a \\emph{minimal normal subgroup} of $G$ if $N \\neq 1$ and if $K \\mathrel{\\unlhd} G$ with $K \\leq N$ then $K = 1$.\n\\end{definition}\n\n\\begin{definition}\nA group $G$ is said to be \\emph{elementary abelian} if it is an abelian group with every element of order $p$ for a fixed prime $p$.\n\\end{definition}\n\n\\begin{theorem}\nEvery minimal normal subgroup of a finite solvable group $G$ is elementary abelian.\n\\end{theorem}\n\n\\begin{proof}\nLet $N$ be a minimal normal subgroup of $G$ and suppose $H$ is a characteristic subgroup of $V$. Then $H \\mathrel{\\unlhd} G$, which violates the minimality of $N$ unless $H = 1$ or $H = N$.\n\nNow $N' = [N, N]$ is characteristic in $N$ and hence $N' = 1$ or $N' = N$. But $N$ is solvable and so $N' \\neq N$ otherwise the derived series would not terminate in $1$.\n\nThus $N' = 1$ and $N$ is abelian. But any Sylow $p$-subgroup of an abelian group is characteristic. Again by the minimality of $N$, this implies that $N$ is an abelian $p$-group.\n\nBut $\\{x \\in N \\;|\\; x^p = 1\\}$ is a characteristic subgroup of $N$. Thus $N$ is elementary abelian. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nA finite group $G$ whose only characteristic subgroups are $1$ and $G$ is either simple or a direct product of isomorphic simple groups.\n\\end{theorem}\n\n\\begin{proof}\nLet $N_1$ be a minimal normal subgroup of $G$ with minimal order amongst all such groups. \n\nConsider all subgroups of $G$ of the form $N_1\\times N_2\\times \\cdots \\times N_n$ for $N_i \\mathrel{\\unlhd} G$ and $N_i \\cong N_j$ for all $i, j$.\n\nLet $M$ be a subgroup of this form with largest possible order. We will show that $M$ char $G$ so that $M = G$. It is enough to show for any automorphism $\\phi \\in$ Aut$(G)$ that $\\phi(N_i) \\leq M$.\n\nWe firstly show that $\\phi(N_i) \\mathrel{\\unlhd} G$. Let $a \\in G$ and $b = \\phi^{-1}(a)$. Then $a\\phi(N_i)a^{-1} = \\phi(bN_ib^{-1}) \\leq \\phi(N_i)$ due to the normality of $N_i$.\n\nSuppose $\\phi(N_i) \\not\\leq M$. Then $|\\phi(N_i)\\cap M| < |\\phi(N_i)| = |N|$. But $\\phi(N_i)\\cap M \\mathrel{\\unlhd} G$ as we showed above that $\\phi(N_i) \\mathrel{\\unlhd} G$. Thus, by the minimality of $|H|$ we have that $\\phi(H_i)\\cap M = 1$.\n\nBut then $M\\times \\phi(H_i)$ violates the maximality of $M$.\n\nThus $\\phi(N_i) \\leq M$ and so $M$ char $G$ and $M = G$.\n\nNow $N_1$ must be simple. If it has a nontrivial normal subgroup $H$ then $H$ is a normal subgroup of $M = G$. But this contradicts the minimal choice of $N$. $\\square$\n\\end{proof}\n\n\\subsubsection{Hall's Theorem on Solvable Groups of Order $mn$}\n\n\\begin{theorem}\nIf $G$ is a solvable group of order $ab$ with gcd$(a, b) = 1$ then $G$ has a subgroup of order $a$. Any two such subgroups are conjugate.\n\\end{theorem}\n\n\\begin{proof}\nThe proof is by induction on $|G|$. For $|G| = 1$ there is nothing to prove.\n\nWe break into two cases. In the first case, assume $G$ contains a normal subgroup $H$ of order $m'n'$ with $m' \\;|\\; m$ and $n' \\;|\\; n$ and $n' < n$.\n\nIn this case, $G/H$ is solvable and has order $(mn)/(m'n') < mn$ as $n' < n$. Thus by the induction hypothesis, $G/H$ has a subgroup $A/H$ of order $m/m'$. By the correspondence theorem $A$ has order $mn'$. But $A$ is now a solvable group of order $mn' < mn$ and so by the inductive hypothesis, $A$ has a subgroup of order $m$ as required.\n\nWe now show that any two subgroups $A$ and $A'$ of order $m$ are conjugate in this case.\n\nAs $H \\mathrel{\\unlhd} G$ we have that $AH \\leq G$. Moreover, $A, H \\leq AH$ and so $|AH| = m\\nu$ where $n' \\;|\\; \\nu \\;|\\; n$.\n\nBut if we apply the second isomorphism theorem to $A$ and $H$ we see that $|AH| \\;|\\; mm'n'$. Thus $\\nu \\;|\\; n'$. Thus $|AH| = mn'$.\n\nA similar computation shows that $|A'H| = mn'$. Thus both $AH/H$ and $A'H/H$ are subgroups of $G/H$ of order $m/m'$.\n\nAs $|G/H| = (mn)/(m'n') < mn$ we have by induction that $AH/H$ and $A'H/H$ are conjugate.\n\nSuppose for example that $(xH)(AH/H)(xH)^{-1} = (A'H/H)$. Then $xAHx^{-1} = A'H$ since $H$ is normal in $G$ and so left and right cosets of $H$ are in bijection, so that both sides of the equation are unions of cosets of $H$. But this shows that $xAx^{-1} \\leq A'H$.\n\nBut we already have that $A' \\leq A'H$, therefore as both $xAx^{-1}$ and $A'$ have order $a$ and $|A'H| < ab$ we have by induction that $xAx^{-1}$ and $A'$ are conjugate, which completes the induction for this case assuming the second case also holds.\n\nThe first case reduces the to a smaller case whenever $G$ has a proper normal subgroup which is not divisible by $n$. Therefore we may assume without loss of generality that every proper normal subgroup $H$ has order divisible by $n$.\n\nIn the case that $H$ is a minimal normal subgroup we have that $H$ is abelian and every element of $H$ is of order $p$ for some prime $p$. In other words, we can assume without loss of generality that $H$ is a Sylow $p$-subgroup of $G$ for some prime $p$ with order $n = p^k$.\n\nAs $H$ is normal, it is the unique $p$-Sylow subgroup. We then have $|G| = mp^k$ with $p \\not |\\; m$. This constitutes the second case, which we shall now prove.\n\nThe group $G/H$ is a solvable group of order $m$. Thus if $K/H$ is a minimal normal subgroup of $G/H$ then $|K/H| = q^n$ for some prime $q \\neq p$, i.e. $|K| = p^kq^l$. Then if $Q$ is a Sylow $q$-subgroup of $K$ then $K = HQ$.\n\nWe let $N^*$ be the normalizer of $Q$ in $G$ and $N = N^*\\cap K$ which is clearly the normalizer of $Q$ in $K$. We claim that $|N^*| = m$.\n\nBy the Frattini argument $G = KN^*$. But as\n$$G/K = KN^*/K \\cong N^*/(N^*\\cap K) = N^*/N$$\nwe have that $|N^*| = |G||N|/|K|$.\n\nAs $K = HQ$ and $Q \\leq N \\leq K$ we have $K = HN$. Thus $|K| = |H||N|/|H\\cap N|$. Thus\n$$|N^*| = |G||N|/|K| = (|G|/|H|)|H\\cap N| = m|H\\cap N|.$$\n\nIf $H\\cap N = 1$ we have $|N^*| = m$, which would complete the argument. Thus we will prove that $H\\cap N = 1$.\n\nFirst we claim that $H\\cap N \\leq Z_K$.\n\nLet $x \\in H\\cap N$. Let $k = hs \\in K = HQ$ be arbitrary, with $h \\in H, s \\in Q$. We see that $x$ commutes with $h$ because $H$ is abelian.\n\nWe have that $(xsx^{-1})s^{-1} \\in Q$ because $x$ is in the normalizer of $Q$. Also $x(sx^{-1}s^{-1}) \\in H$ as $H$ is normal. Thus $xsx^{-1}x^{-1} \\in Q\\cap H$ which is trivial because the orders of $Q$ and $H$ are coprime. This proves the claim.\n\nNow $Z_K$ is characteristic in $K$ and $K$ is normal in $G$ by the correspondence theorem. Thus $Z_K \\mathrel{\\unlhd} G$.\n\nIf $Z_K$ is not trivial then it contains a minimal subgroup which must also be normal in $G$. But $H$ is the unique minimal normal subgroup of $G$ by definition, so $H \\leq Z_K$.\n\nBut $K = HQ$ and so $Q$ char $K$ since it is a $q$-Sylow subgroup of $K$, all of which are conjugate, and $Q$ is preserved under conjugation by any element of $K$ since $H \\leq Z_K$.\n\nNow $Q$ char $K \\mathrel{\\unlhd} G$, thus $Q \\mathrel{\\unlhd} G$. But as $H$ is the unique minimal normal subgroup of $G$, this implies $H \\leq Q$, which contradicts $H\\cap Q = 1$.\n\nThus we must in fact have $Z_K = 1$ and $N^*$ has the required order.\n\nTo show that all groups of order $m$ are conjugate in this case, let $A$ be any other subgroup of order $m$.\n\nAs $K \\mathrel{\\unlhd} G$ we have that $|AK|$ is divisible by $m$ and by $|K| = p^kq^l = nq^l$. Thus $|AK| = mn = |G|$ and so $AK = G$. Then\n$$G/K = AK/K \\cong A/(A\\cap K),$$\nwhich implies $|A\\cap K| = q^l$, i.e. that $A\\cap K$ is a Sylow $q$-subgroup. It is therefore conjugate to $Q$.\n\nIt is easy to show that conjugate subgroups have conjugate normalizers, and so $N^*$ is conjugate to $N_G(A\\cap K)$. Thus $|N_G(A\\cap K)| = m$.\n\nAs $A\\cap K \\mathrel{\\unlhd} A$ we have that $A \\leq N_G(A\\cap K)$ and so $A = N_G(A\\cap K)$. But this implies that $A$ is conjugate to $N^*$. $\\square$\n\\end{proof}\n\n\\subsection{Central Series and Nilpotent Groups}\n\n\\subsubsection{Lower Central Series}\n\n\\begin{definition}\nLet $G$ be a group. The \\emph{lower central series} of $G$ is the series\n$$G = G_1 \\geq G_2 \\geq \\cdots$$\nwhere $G_{i+1} = [G_i, G]$.\n\\end{definition}\n\nClearly $G_{i+1} \\leq G_i$ for all $i$.\n\n\\begin{theorem}\nLet $G$ be a group with lower central series\n$$G = G_1 \\geq G_2 \\geq \\cdots$$\nthen $G_i$ char $G$ for all $i$.\n\\end{theorem}\n\n\\begin{proof}\nNote that $G_1 = G$ and $G_2 = [G, G]$, both of which are characteristic.\n\nThe proof is completed by induction. If $[x, y] \\in [G_i, G]$ and $\\phi \\in$ Aut$(G)$ then $\\phi([x, y]) = [\\phi(x), \\phi(y)]$. But $\\phi(y) \\in G$ and $\\phi(x) \\in G_i$ by the inductive hypothesis. Thus $\\phi([x, y]) \\in [G_i, G]$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $K \\mathrel{\\unlhd} G$ and $K \\leq H \\leq G$. Then $[H, G]$, the group generated by commutators of the form $h^{-1}g^{-1}hg$ for $h \\in H$ and $g \\in G$, is a subgroup of $K$ iff $H/K \\leq Z(G/K)$.\n\\end{theorem}\n\n\\begin{proof}\nAs $K \\mathrel{\\unlhd} G$ we certainly have $K \\mathrel{\\unlhd} H$. We also have that $(hK)(gK) = (gK)(hK)$ iff $h^{-1}g^{-1}hg \\in K$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a group with lower central series\n$$G = G_1 \\geq G_2 \\geq \\cdots$$\nthen $G_i/G_{i+1} \\leq Z(G/G_{i+1})$.\n\\end{theorem}\n\n\\begin{proof}\nAs $[G_i, G] = G_{i+1}$ and $G_{i+1} \\mathrel{\\unlhd} G$ we can apply the previous theorem which gives that $G_i/G_{i+1} \\leq Z(G/G_{i+1})$. $\\square$ \n\\end{proof}\n\n\\subsubsection{Upper Central Series}\n\n\\begin{definition}\nLet $G$ be a group. The \\emph{higher centers} of $G$ are the groups defined by\n$$Z^0(G) = 1, \\;\\; Z^{i+1}(G)/Z^i(G) = Z(G/Z^i(G)),$$\ni.e. $Z^{i+1}(G)$ is the inverse image of the center in the canonical projection $v_i : G \\to G/Z^i(G)$.\n\\end{definition}\n\nNote that $Z^1(G) = Z(G)$ and $Z_{i+1} \\mathrel{\\unlhd} G$ by the correspondence theorem.\n\n\\begin{definition}\nThe \\emph{upper central series} of the group $G$ is\n$$1 = Z^0(G) \\leq Z^1(G) \\leq Z^2(G) \\leq \\cdots .$$\n\\end{definition}\n\n\\begin{definition}\nLet $G$ be a group. A \\emph{central series} for $G$ is a series\n$$1 = H_n \\leq H_{n-1} \\leq \\cdots \\leq H_0 = G,$$\nwhere $H_i$ is a normal subgroup of $G$ and $H_{i-1}/H_i \\leq Z(G/H_i)$ for all $i$.\n\\end{definition}\n\nNote that a central series terminates and a group need not have a central series.\n\n\\begin{theorem}\nSuppose\n$$1 = H_n \\leq H_{n-1} \\leq \\cdots \\leq H_0 = G,$$\nis a central series for a group $G$ and groups $G_i$ form a lower central series and $Z_i$ an upper central series for $G$. Then\n$$G_{i+1} \\leq H_i \\;\\;\\mbox{and}\\;\\; H_{n-i} \\leq Z_{i+1}.$$\n\\end{theorem}\n\n\\begin{proof}\nWe prove the first inclusion by induction.\n\nNote that $G_1 = H_0 = G$. Now suppose that $G_i \\leq H_{i-1}$ for some $i$. If $x \\in G_i$ and $y \\in G$ then\n$$H_ix \\in G_{i-1}/G_i \\leq Z(G/H_i)$$\nby the assumption and the fact that the $H_i$ form a central series. Thus $H_ix$ and $H_iy$ commute.\n\nThus\n$$H_i[x, y] = (H_ix)^{-1}(H_iy)^{-1}(H_ix)(H_iy) = H_i,$$\nand so $[x, y] \\in H_i$.\n\nThus $$G_{i+1} = [G_i, G] \\leq H_i$$ completing the induction.\n\nWe will also prove the second inclusion by induction.\n\nFirst note that $Z_0 = H_n = 1$. Now suppose that $H_{n-i} \\leq Z_i$ for some $i$. As the $H_i$ form a central series we have\n$$H_{n-i-1}/H_{n-i} \\leq Z(G/H_{n-i}).$$\n\nThus if $x \\in H_{n-i-1}$ and $y \\in G$ we have that $H_{n-i}x$ and $H_{n-i}y$ commute. Thus $[x, y] \\in H_{n-i} \\leq Z_i$. Thus $Z_ix$ commutes with $Z_iy$. Thus $Z_ix \\in Z(G/Z_i) = Z_{i+1}/Z_i$.\n\nBut $x$ was an arbitrary element of $H_{n-i-1}$, thus $H_{n-i-1} \\leq Z_{i+1}$ which completes the induction. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nLet $G$ be a group and $G_i$, $Z_i$ form a lower and upper central series as per the theorem. Then the following are equivalent\n\\begin{enumerate}\n\\item $G_{c+1} = 1$ for some $c$\n\\item $Z_c = G$ for some $c$\n\\item $G$ has a central series.\n\\end{enumerate}\nMoreover if the conditions hold for a group $G$, the value of $c$ is the same in the first two conditions.\n\\end{corollary}\n\n\\begin{proof}\nIf $G$ has a central series of length $n$ of groups $H_i$ as per the theorem then $G_{n+1} \\leq H_n = 1$ and $G = H_0 \\leq Z_n$. Thus $(3)$ implies $(1)$ and $(2)$.\n\nIf $Z_c = G$ then\n$$1 = Z_0 \\leq Z_1 \\leq \\cdots \\leq Z_{c-1} \\leq Z_c = G$$\nis a central series for $G$. Thus $(2)$ implies $(3)$.\n\nIf $G_{c+1} = 1$ then\n$$1 = G_{c+1} \\leq G_c \\leq \\cdots \\leq G_1 = G$$\nis a central series for $G$ by a similar argument to the cases in the theorem. \n\nIt is clear that if the lower central series has $G_{c+1} = 1$ then as it is a central series, the upper central series must have $Z_c = G$. Similarly the other way around, thus the final statement of the theorem holds. $\\square$\n\\end{proof}\n\n\\subsubsection{Nilpotent Groups}\n\n\\begin{definition}\nAny group $G$ which satisfies the equivalent conditions of the corollary in the previous section is said to be a \\emph{nilpotent} group. The number $c$ is called the \\emph{nilpotence} class of $G$.\n\\end{definition}\n\n\\begin{theorem}\nA group $G$ is abelian iff its nilpotence class is $1$.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{Nonabelian Groups of Order $p^3$}\n\n\\begin{theorem}\nLet $G$ be a nonabelian group of order $p^3$ for a prime $p$. Then $|Z(G)| = p$, $G/Z(G) \\cong C_p\\times C_p$ and $Z(G) = [G, G]$.\n\\end{theorem}\n\n\\begin{proof}\nWe have previously shown that $|Z(G)| = p$. Now either $G/Z(G)$ is cyclic of order $p^2$ or isomorphic to $C_p\\times C_p$. As $G$ is abelian if $G/Z(G)$ is cyclic we must have the latter.\n\nAs $G/Z(G)$ is abelian, we must have $[G, G] \\leq Z(G)$. As $G$ is nonabelian, $[G, G]$ is nontrivial and so the result follows. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nA nonabelian group of order $p^3$ for a prime $p$ is nilpotent of class $2$.\n\\end{corollary}\n\n\\begin{proof}\nConsider the sequence $1 \\leq Z(G) \\leq G$. This is the upper central series for $G$ since $Z(G/Z(G)) = G/Z(G)$ by the theorem. Thus the nilpotence class is $2$. $\\square$\n\\end{proof}\n\n\\subsubsection{Every Finite $p$-group is Nilpotent}\n\n\\begin{theorem}\nEvery finite $p$-group is nilpotent.\n\\end{theorem}\n\n\\begin{proof}\nThe centre of a finite $p$-group is nontrivial. But for each higher centre $Z_i$ we have that $G/Z_i$ is a $p$-group and hence its centre is nontrivial. Thus the upper central series for $G$ terminates at $G$. $\\square$\n\\end{proof}\n\n\\subsubsection{Every Nilpotent Group is Solvable}\n\n\\begin{theorem}\nEvery nilpotent group $G$ is solvable.\n\\end{theorem}\n\n\\begin{proof}\nWe previously showed that if $G_i$ are the derived subgroups and $Z_i$ the higher centres of $G$ then $G_i \\leq Z_{c-i}$ where $c$ is the nilpotence class. Thus each of the $G_i$ is abelian and $G$ is solvable. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is nontrivial and nilpotent then $Z(G)$ is nontrivial.\n\\end{theorem}\n\n\\begin{proof}\nIf $Z(G)$ is trivial then there is no upper central series for $G$. $\\square$\n\\end{proof}\n\n\\begin{corollary}\n$S_3$ is solvable but not nilpotent.\n\\end{corollary}\n\n\\begin{proof}\n$S_3$ has trivial centre, thus by the theorem is not nilpotent. However, it is easy to see that it is solvable since $A_3$ is a normal subgroup of index $2$ and order $3$. $\\square$\n\\end{proof}\n\n\\subsubsection{Subgroups, Quotients and Products of Nilpotent Groups are Nilpotent}\n\n\\begin{theorem}\nEvery subgroup $H$ of a nilpotent group $G$ of class $c$ is nilpotent with class at most $c$.\n\\end{theorem}\n\n\\begin{proof}\nBy induction $Z_i(H) \\leq Z_i(G)$ for all $i$. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $G$ is nilpotent of class $c$ and $H \\mathrel{\\unlhd} G$ then $G/H$ is nilpotent of class at most $c$.\n\\end{theorem}\n\n\\begin{proof}\nSuppose that $\\phi: G \\to M$ is a group homomorphism and $H, K \\leq G$. Clearly $\\phi([h, k]) = [\\phi(h), \\phi(k)]$ for all $h \\in H$, $k \\in K$. Thus $\\phi([H, K]) = [\\phi(H), \\phi(K)]$.\n\nSuppose now that $\\phi$ is surjective. As $G_{i+1} = [G, G_i]$ and $M_{i+1} = [M, M_i]$ we have inductively that $M_i \\leq \\phi(G_i)$. Thus if $G$ is nilpotent of class $c$, $M$ has lower central series bounded in length by that of $G$ and the result follows. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $H$ and $K$ are nilpotent, so is $H\\times K$.\n\\end{theorem}\n\n\\begin{proof}\nIt is clear that $[H\\times K, H\\times K] \\leq [H, H]\\times [K, K]$. By induction $(H\\times K)_i \\leq H_i\\times K_i$ for all $i$. Thus if $H$ has nilpotence class $c_1$ and $K$ has nilpotence class $c_2$ then $H\\times K$ is nilpotent with class at most max$\\{c_1, c_2\\}$. $\\square$\n\\end{proof}\n\n\\subsubsection{Nilpotent Groups are the Product of their Sylow Subgroups}\n\n\\begin{theorem} \\label{normalizercond}\nIf $G$ is a nilpotent group and $H < G$ then $H < N_G(H)$.\n\\end{theorem}\n\n\\begin{proof}\nThere must exist an $i$ such that $G_{i+1} \\leq H$ but $G_i \\not\\leq H$.\n\nBut $[G_i, H] \\leq [G_i, G] = G_{i+1} \\leq H$. Thus $G_i \\leq N_G(H)$. \n\nRecall that $H \\leq N_G(H)$ for all $H \\leq G$. But if $H = N_G(H)$ then $G_i \\leq H$, a contradiction. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $P$ be a $p$-Sylow subgroup of a group $G$ and suppose that $N_G(P) \\leq H \\leq G$. Then $N_G(H) = H$.\n\\end{theorem}\n\n\\begin{proof}\nClearly $H \\leq N_G(H)$ so it suffices to show the reverse inclusion.\n\nLet $a \\in N_G(H)$. As $P \\leq N_G(P) \\leq H$ we have\n$$aPa^{-1} \\subseteq aHa^{-1} = H,$$\nsince $a \\in N_G(H)$.\n\nWe therefore have that both $P$ and $aPa^{-1}$ are Sylow subgroups of $H$.\n\nAs all Sylow subgroups are conjugate, there exists $b \\in H$ such that\n$$(b^{-1}a)P(b^{-1}a)^{-1} = P.$$\n\nIn other words, $b^{1}a \\in N_G(P) \\leq H$.\n\nAs $b \\in H$ we must have $a \\in H$ and so $H \\leq N_G(H)$ as required. $\\square$ \n\\end{proof}\n\n\\begin{theorem}\nA group $G$ is nilpotent iff it is the direct product of its Sylow subgroups.\n\\end{theorem}\n\n\\begin{proof}\nAs Sylow subgroups are $p$-groups, they are nilpotent. Thus their direct product is nilpotent.\n\nFor the converse, suppose $G$ is nilpotent and that $H$ is a $p$-Sylow subgroup of $G$.\n\nBy the previous theorem $N_G(N_G(P)) = N_G(P)$.\n\nNow suppose that $N_G(P)$ is a proper subgroup of $G$. Then by Theorem \\ref{normalizercond} we have that $N_G(P)$ is a proper subgroup of $N_G(N_G(P))$. As this would be a contradiction, we must have that $G = N_G(P)$, i.e. $P \\mathrel{\\unlhd} G$.\n\nAs Sylow subgroups intersect trivially and clearly generate $G$, the result follows. $\\square$\n\\end{proof}\n\n\\subsubsection{Maximal Subgroups of Nilpotent Groups are of Prime Index}\n\n\\begin{theorem}\nEvery maximal subgroup $H$ of a nilpotent group $G$ is normal and of prime index in $G$.\n\\end{theorem}\n\n\\begin{proof}\nLet $H$ be maximal in $G$. Then as $H < N_G(H)$ we must have $N_G(H) = G$, i.e. $H \\mathrel{\\unlhd} G$. If the quotient $G/H$ were not of prime order it would have a nontrivial proper subgroup which by the correspondence theorem would contradict the maximality of $H$ in $G$. $\\square$\n\\end{proof}\n\n\\section{Fundamental Theorem of Finitely Generated Abelian Groups}\n\n\\subsection{Finite Abelian $p$-groups}\n\n\\subsubsection{Finite Abelian $p$-groups are a Product of Cyclic Groups}\n\n\\begin{theorem}\nLet $G$ be an abelian group of order $p^n$ for a prime $p$ and let $a \\in G$ have maximal order. Then $G$ can be written $\\langle a \\rangle \\times K$ for some $K \\leq G$.\n\\end{theorem}\n\n\\begin{proof}\nWe proceed by induction on $n$. The result is obvious for $n = 1$.\n\nSuppose $a$ has order $p^m$. For any $x \\in G$ we have $|x| = p^i$ for some $i \\leq m$. Thus for all $x \\in G$ we have $x^{p^m} = 1$.\n\nAssume $G \\neq \\langle a \\rangle$, otherwise the result is trivial.\n\nLet $b \\in G$, $b \\notin \\langle a \\rangle$ be chosen such that $|c| < |b|$ implies $c \\in \\langle a \\rangle$. We will show that $\\langle a \\rangle \\cap \\langle b \\rangle = \\{1\\}$.\n\nAs $|b^p| < |b|$ we have that $b^p \\in \\langle a \\rangle$, i.e. $b^p = a^i$ for some $i$.\n\nClearly $|a^i| \\leq p^{m-1}$. Thus $a^i$ is not a generator of $\\langle a \\rangle$ and so gcd$(p^m, i) \\neq 1$. Thus $i = pj$ for some $j$, i.e. $b^p = a^{pj}$.\n\nConsider $c = a^{-j}b$. Clearly $c \\notin \\langle a \\rangle$ otherwise we would have $b \\in \\langle a \\rangle$. But $c^p = 1$ and so $|c| = p$. Therefore by definition $|b| = p$.\n\nAs $b \\notin \\langle a \\rangle$ we must have $\\langle a \\rangle \\cap \\langle b \\rangle = 1$ as claimed.\n\nReturning to the induction, consider the quotient group $\\bar{G} = G/\\langle b \\rangle$.\n\nLet $\\bar{x}$ denote the coset $x\\langle b \\rangle$.\n\nSuppose that $|\\bar{a}| < |a| = p^m$. This means that $\\bar{a}^{p^{m-1}} = \\bar{1}$, i.e. $a^{p^{m-1}}\\langle b \\rangle = \\langle b \\rangle$. But then $a^{p^{m-1}} \\in \\langle a \\rangle \\cap \\langle b \\rangle = \\{1\\}$, which contradicts $|a| = p^m$.\n\nThus we must have that $|\\bar{a}| = |a| = p^m$ and $bar{a}$ is an element of maximal order in $\\bar{G}$.\n\nAs $|\\bar{G}| = p^{n-1}$ we can apply the induction hypothesis, i.e. $\\bar{G}$ can be written $\\langle \\bar{a} \\rangle\\times \\bar{K}$ for some $\\bar{K} \\leq \\bar{G}$.\n\nLet $K = \\{x \\in G \\;|\\; \\bar{x} \\in \\bar{K}\\}$. Then $K \\leq G$ and $|K| = p|\\bar{K}|$.\n\nLet $x \\in \\langle a \\rangle \\cap K$. Then $\\bar{x} \\in \\langle \\bar{a} \\rangle \\cap \\bar{K} = \\bar{1} = \\langle \\bar{b} \\rangle$. Thus $x \\in \\langle a \\rangle \\cap \\langle b \\rangle = \\{1\\}$.\n\nIt is easy to check that $|\\langle a \\rangle K| = |G|$ and thus $G = \\langle a \\rangle K$.\n\nAs $G$ is abelian, the result follows. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nLet $G$ be a finite abelian $p$-group. Then $G$ is a direct product of cyclic groups of prime power order.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsection{Finitely Generated Abelian Groups}\n\n\\subsubsection{The Fundamental Theorem of Finite Abelian Groups}\n\n\\begin{theorem}\nEvery finite abelian group is a direct product of cyclic groups of prime power order. The product is unique up to reordering.\n\\end{theorem}\n\n\\begin{proof}\nA finite abelian group is a direct product of its Sylow subgroups, and this product is clearly unique.\n\nBy the corollary of the previous section, each of the Sylow subgroups is a product of cyclic groups of prime power order. It remains to prove that each such decomposition of a Sylow $p$-subgroup is unique up to reordering.\n\nTo this end, let $G$ be a group with order $p^k$. We will prove the result by induction on $k$, the base case $k = 1$ being trivial.\n\nSuppose that\n$$G = H_1\\times H_2\\times \\cdots \\times H_m = K_1\\times K_2 \\times \\cdots \\times K_n$$\nis a decomposition of $G$ in two different ways into nontrivial cyclic groups of $p$-power order, with\n$$|H_1| \\geq |H_2| \\geq \\cdots \\geq |H_m|$$\n$$|K_1| \\geq |K_2| \\geq \\cdots \\geq |K_m|$$.\n\nThe set $G^p = \\{x^p \\;|\\; x \\in G\\}$ is a proper subgroup of $G$.\n\nWe have that\n$$G^p = H_1^p\\times \\cdots \\times H_{m'}^p = K_1^p \\times \\cdots \\times K_{n'}^p$$\nwhere $m'$ is the largest integer $i$ such that $|H_i| > p$ and $n'$ is the largest integer $j$ such that $|K_i| > p$.\n\nBy Cauchy's theorem $|G^p| < |G|$. Thus the induction hypothesis applies.\n\nWe have that $|H_i| = p|H_i^p|$ and $|K_i| = p|K_i^p|$. Thus $|H_i| = |K_i|$ for $i \\leq m' = n'$.\n\nAs all the remaining $H_i$ and $K_j$ have order $p$, a simple comparison of orders shows that $m = n$ and we are done. $\\square$\n\\end{proof}\n\n\\subsection{Fundamental Theorem of Finitely Generated Abelian Groups}\n\n\\subsubsection{Finitely Generated Abelian Groups}\n\n\\begin{definition}\nAn abelian group $G$ is finitely generated if there exists a set of \\emph{generators} $g_1, g_2, \\ldots, g_n \\in G$ such that every element of $G$ is a product of powers of the $g_i$ and their inverses.\n\\end{definition}\n\n\\begin{theorem}\nEvery finite group is finitely generated.\n\\end{theorem}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\subsubsection{The Fundamental Theorem}\n\n\\begin{theorem}\nEvery subgroup of $\\mathbb{Z}^n$ is finitely generated (by at most $n$ generators).\n\\end{theorem}\n\n\\begin{proof}\nWe proceed by induction on $n$. For $n = 1$ we know that every subgroup is of the form $k\\mathbb{Z}$ for some $k \\geq 0$. The proof is classical and makes use of the fact that if $a$ and $b$ are in the subgroup then $d = $gcd$(a, b)$ is in the subgroup. As $a$ and $b$ are both in the subgroup generated by $d$, we can replace the generators $a$ and $b$ by the single generator $d$.\n\nIn general, let $H$ be a subgroup of $\\mathbb{Z}^n$ and let $F$ be the set of all $f$ such that $(f, a_2, a_3, \\ldots, a_n) \\in H$. Clearly $F$ is a subgroup of $\\mathbb{Z}$. Let $F$ be $k\\mathbb{Z}$ for some $k \\geq 0$. Now choose any element $(k, a_2, a_3, \\ldots, a_n)$ of $H$.\n\nFor any $(h_1, h_2, \\ldots, h_n) \\in K$ we have\n$$(h_1, h_2, \\ldots, h_n) = s(k, a_2, a_3, \\ldots, a_n) + (0, h_2 - sa_2, h_3 - sa_3, \\ldots, h_n - sa_n).$$\n\nIt is easy to check that the set of all elements $(h_2 - sa_2, h_3 - sa_3, \\ldots, h_n - sa_n)$ is a subgroup of $\\mathbb{Z}^{n-1}$, which is finitely generated with at most $n - 1$ generators, by the inductive hypothesis.\n\nIt is then easy to see that $H$ itself must be finitely generated with at most $n$ generators. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nIf $H$ is a subgroup of $\\mathbb{Z}^n$ then\n$$H \\cong d_1\\mathbb{Z} \\oplus d_2\\mathbb{Z} \\oplus \\cdots \\oplus d_r\\mathbb{Z}$$ \nand\n$$\\mathbb{Z}^n/H \\cong \\mathbb{Z}/d_1\\mathbb{Z} \\oplus \\mathbb{Z}/d_2\\mathbb{Z} \\oplus \\cdots \\oplus \\mathbb{Z}/d_r\\mathbb{Z}\\oplus \\mathbb{Z} \\oplus \\mathbb{Z} \\oplus \\cdots \\oplus \\mathbb{Z},$$\nwhere $1 < d_1 \\;|\\; d_2 \\;|\\; \\ldots \\;|\\; d_r$.\n\\end{theorem}\n\n\\begin{proof}\nThe subgroup $H$ is finitely generated by the previous theorem. Let $h_1, h_2, \\ldots, h_m$ be generators of $H$. Write out the matrix whose rows are given by these generators\n$$A = \\left(\\begin{array}{ccc}h_{1,1} & \\cdots & h_{1,n}\\\\ \\vdots & \\vdots & \\vdots\\\\ h_{m,1} & \\cdots & h_{m, n}\\end{array}\\right).$$\n\nWe reduce $A$ to Smith Normal Form by row and column operations (swap rows or columns, multiply rows or columns by $-1$ or add two rows or columns).\n\nRow operations change the generators of $H$ and column operations change the generators of $\\mathbb{Z}^n$.\n\nThe result is a matrix with zeroes everywhere except on the diagonal, where we have values $d_1, d_2, \\ldots d_r$, followed by zeroes.\n\nIt's easy to see that we can arrange things so that $d_i \\;|\\; d_{i+1}$ via row and column operations and using the extended GCD algorithm.\n\nThe result is that we have found bases for both the groups such that one has the required form in terms of the other. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $G$ be a finitely generated abelian group. Then\n$$G \\cong C_{d_1}\\times C_{d_2}\\times \\cdots \\times C_{d_k}\\times \\mathbb{Z}^r$$\nwhere $1 < d_1 \\;|\\; d_2 \\;|\\; \\ldots \\;|\\; d_k$. The $d_i$ are uniquely determined, as is $r$.\n\\end{theorem}\n\n\\begin{proof}\nLet $g_1, g_2, \\ldots, g_n$ be generators of $G$. Consider the homomorphism $\\mathbb{Z}^n \\to G$ sending $(a_1, a_2, \\ldots, a_n)$ to $a_1g_1 + a_2g_2 + \\cdots + a_ng_n$. Let $K$ be the kernel of the homomorphism. By the first isomorphism theorem $G \\cong \\mathbb{Z}/K$.\n\nNow the result follows by applying the previous theorem. Uniqueness follows as per the theorem for finite abelian groups. $\\square$\n\\end{proof}\n\n\\begin{definition}\nThe value $r$ in the previous theorem is called the \\emph{rank} of the finitely generated group $G$.\n\\end{definition}\n\n\\section{Group Transfer}\n\n\\subsection{The Transfer Map}\n\n\\subsubsection{Complements}\n\n\\begin{definition}\nLet $G$ be a group and $K$ a (not necessarily normal) subgroup of $G$. We say that $Q \\leq G$ is a \\emph{complement} of $K$ in $G$ if $K\\cap Q = 1$ and $KQ = G$.\n\\end{definition}\n\nEven a normal subgroup $K$ of a group $G$ need not have a complement. If it does, it need not be unique. However, we have the following result.\n\n\\begin{theorem}\nLet $K$ be a normal subgroup of a group $G$. Any complements of $K$ in $G$, if they exist, are isomorphic.\n\\end{theorem}\n\n\\begin{proof}\nWe have\n$$G/K = KQ/K \\cong Q/(K\\cap Q) = Q/1 \\cong Q.$$ $\\square$\n\\end{proof}\n\nRecall that $G$ is a direct product of normal subgroups $K$ and $Q$ if $Q$ is a complement of $K$ in $G$.\n\nWe also have that $G = K\\rtimes Q$ if $K \\mathrel{\\unlhd} G$ and $K$ has a complement isomorphic to $Q$.\n\n\\begin{definition}\nLet $K$ be a subgroup of a group $G$, then a (right) transversal of $K$ in $G$ is a subset $T$ of $G$ consisting of one element from each right coset of $K$ in $G$. A left transversal is defined similarly.\n\\end{definition}\n\nIf $G$ is a semidirect product of a normal subgroup $K$ with complement $Q$ then $Q$ is a transversal of $K$ in $G$.\n\n\\subsubsection{The Transfer Map}\n\n\\begin{theorem}\nLet $Q$ be a subgroup of finite index $n$ in a group $G$. Suppose that $\\{l_1, l_2, \\ldots, l_n\\}$ and $\\{h_1, h_2, \\ldots, h_n\\}$ are two left traversals of $Q$ in $G$. For fixed $g \\in G$ and each $i$ there is a unique $\\sigma(i)$ and a unique $x_i \\in Q$ with\n$$gh_i = l_{\\sigma(i)}x_i.$$\nMoreover, $\\sigma$ is a permutation of $\\{1, 2, \\ldots, n\\}$.\n\\end{theorem}\n\n\\begin{proof}\nThe left cosets of $Q$ partition $G$, and so there is a unique left coset $l_jQ$ containing $gh_i$. The first part of the theorem follows if we set $\\sigma(i) = j$.\n\nWe will now show that $\\sigma$ is injective (on a finite set) and therefore a permutation. Assume that $\\sigma(i) = \\sigma(k) = j$. Then $gh_i = l_jx_i$ and $gh_k = l_jx_k$. Then $gh_ix_i^{-1}  gh_kx_k^{-1}$ and so $h_i^{-1}h_k = x_i^{-1}x_k$ and $h_iQ = h_kQ$, i.e. $i = k$. $\\square$\n\\end{proof}\n\n\\begin{definition}\nLet $Q$ be a subgroup of finite index $n$ in a group $G$. The \\emph{transfer} is the map $V : G \\to H/H'$ defined by\n$$V(g) = \\prod_{i=1}^n x_iQ',$$\nwhere $\\{l_1, l_2, \\ldots, l_n\\}$ is some transversal of $Q$ in $G$ and $gl_i = l_jx_i$.\n\\end{definition}\n\n\\begin{theorem}\nLet $Q$ be a subgroup of finite index in a group $G$, then the transfer is a homomorphism. Moreover it does not depend on the choice of transversal in the definition.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\{l_1, l_2, \\ldots, l_n\\}$ and $\\{h_1, h_2, \\ldots, h_n\\}$ be two transversals of $Q$ in $G$. By the previous theorem we have $gl_i = l_{\\sigma(i)}x_i$, $gh_i = h_{\\tau(i)}y_i$ and $h_i = l_{\\alpha(i)}z_i$ for some permutations $\\sigma$, $\\tau$ and $\\alpha$ and some $x_i, y_i, z_i \\in Q$.\n\nCombining these, we have\n$$gh_i = gk_{\\alpha(i)}z_i = l_{\\sigma(\\alpha(i))}x_{\\alpha(i)}z_i.$$\n\nDefine $j$ by $\\alpha(j) = \\sigma(\\alpha(i))$ we have $h_j = l_{\\sigma(\\alpha(i))}z_j$, from which we get\n$$gh_i = h_jz_j^{-1}x_{\\alpha(i)}z_i.$$\n\nBy uniqueness from the previous theorem, and the definition of $j$ we have $j = \\tau(i)$ and\n$y_i = z_j^{-1}x_{\\alpha(i)}z_i = z_{\\alpha^{-1}(\\sigma(\\alpha(i)))}^{-1}x_{\\alpha(i)}z_i.$\n\nWe can ignore order of factors in the abelian group $Q/Q'$. Therefore\n$$\\prod y_iQ' = \\prod z_{\\alpha^{-1}(\\sigma(\\alpha(i)))}^{-1}x_{\\alpha(i)}z_iQ' = \\prod x_{\\alpha(i)}Q',$$\nsince $\\alpha^{-1}\\sigma\\alpha$ is a permutation and so the inverse of each $z_i$ occurs and cancels it.\n\nBecause $\\alpha$ is a permutation we have $\\prod x_{\\alpha(i)}Q' = \\prod x_iQ'$. But this now precisely establishes the independence of the choice of transversal.\n\nNow we will show $V$ is a homomorphism. Let $g, g' \\in G$ and $\\{l_1, l_2, \\ldots, l_n\\}$ be a left transversal of $Q$ in $G$. Then $gl_i = l_{\\sigma(i)}x_i$ and $g'l_i = l_{\\tau(i)}y_i$ for permutations $\\sigma$ and $\\tau$ and some $x_i, y_i \\in Q$. Then\n$$gg'l_i = gl_{\\tau(i)}y_i = l_{\\sigma(\\tau(i))}x_{\\tau(i)}y_i.$$\n\nThus\n\\begin{align*}\nV(gg') = \\prod x_{\\tau(i)}y_iQ' &= \\left(\\prod x_{\\tau(i)}Q'\\right)\\left(\\prod y_{i}Q'\\right)\\\\\n                                &= \\left(\\prod x_{i}Q'\\right)\\left(\\prod y_{i}Q'\\right) = V(g)V(g').\n\\end{align*} $\\square$\n\\end{proof}\n\n\\subsubsection{Normal Complements}\n\n\\begin{theorem}\nLet $Q$ be a subgroup of finite index in a group $G$ and let $\\{l_1, l_2, \\ldots l_n\\}$ be a left transversal of $Q$ in $G$. For each $g \\in G$ there exist $h_1, h_2, \\ldots, h_m \\in G$ and $n_1, n_2, \\ldots, n_m > 0$ depending on $g$ such that \n\\begin{itemize}\n\\item $h_i \\in \\{l_1, l_2, \\ldots, l_n\\}$\n\\item $h_i^{-1}g^{n_i}h_i \\in Q$\n\\item $\\sum n_i = n = [G:Q]$\n\\item $V(g) = \\prod (h_i^{-1}g^{n_i}h_i)Q'$.\n\\end{itemize}\nIn other words, the transfer is a product of conjugages of powers of $g$.\n\\end{theorem}\n\n\\begin{proof}\nWe have that $gl_i = l_{\\sigma(i)}x_i$ for some permutation $\\sigma$ and $x_i \\in Q$. Write $\\sigma$ as a product of disjoint cycles\n$$\\sigma = \\alpha_1\\alpha_2\\ldots \\alpha_m,$$\nwith 1-cycles included (so that the sum of the lengths of the cycles is $n$).\n\nSuppose $\\alpha_i = (j_1, j_2, \\ldots, j_r)$. Then\n$$gl_{j_1} = l_{\\sigma(j_1)}x_{j_1} = l_{j_2}x_{j_1}, \\ldots, gl_{j_r} = l_{j_1}x_{j_r}.$$\n\nNow the following product is contained in $Q$\n$$x_{j_r}\\cdots x_{j_1} = (l_{j_1}^{-1}gl_{j_r})\\cdots (l_{j_2}^{-1}gl_{j_1}) = l_{j_1}^{-1}g^rl_{j_1}.$$\n\nAll of the conclusions follow trivially. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $Q$ be an abelian subgroup of finite index in a group $G$. If $Q \\leq Z(G)$ then $V(g) = g^n$ for all $g\\in G$.\n\\end{theorem}\n\n\\begin{proof}\nAs $Q$ is an abelian subgroup, the map $V$ can be regarded as a homomorphism to $Q$. Furthermore, $Q \\leq Z(G)$ implies that $Q \\mathrel{\\unlhd} G$.\n\nIf $g \\in G$ and $h^{-1}g^rh \\in Q$ then by normality of $Q$ we have\n$$g^r = h(h^{-1}g^rh)h^{-1} \\in Q.$$\n\nBut as $Q \\leq Z(G)$ we now have that $h^{-1}g^rh = g^r$. The result now follows from the previous theorem. $\\square$\n\\end{proof}\n\n\\begin{corollary}\nIf $Q$ is a subgroup of finite index in a group $G$, with $Q \\leq Z(G)$, the map $g \\to g^n$ is a homomorphism.\n\\end{corollary}\n\n\\begin{proof}\nClear. $\\square$\n\\end{proof}\n\n\\begin{theorem}\nLet $Q$ be a $p$-Sylow subgroup of a finite group $G$. If $g, h \\in C_G(Q)$ are conjugate in $G$, they are conjugate in $N_G(Q)$.\n\\end{theorem}\n\n\\begin{proof}\nLet $h = \\alpha^{-1}g\\alpha$ for some $\\alpha \\in G$. Thus $h \\in \\alpha^{-1}C_G(Q)\\alpha = C_G(\\alpha^{-1}Q\\alpha)$.\n\nAs $Q$ and $\\alpha^{-1}Q\\alpha$ are contained in $C_G(h)$, these are both Sylow subgroups of $C_G(h)$.\n\nBy the Sylow theorems, $Q = c^{-1}\\alpha^{-1}Q\\alpha c$ for some $c \\in C_G(h)$. Thus $\\alpha c \\in N_G(Q)$ and $c^{-1}\\alpha^{-1}g\\alpha c = c^{-1}hc = h$, showing that $g$ and $h$ are conjugate in $N_G(Q)$. $\\square$\n\\end{proof}\n\n\\begin{theorem} (Burnside Normal Complement)\nLet $G$ be a finite group and let $Q$ be an abelian Sylow subgroup with $Q \\leq Z(N_G(Q))$. Then $Q$ has a complement $K$ which is normal in $G$.\n\\end{theorem}\n\n\\begin{proof}\nAs $Q$ is abelian, we may identify $Q/Q'$ with $Q$ and regard $V$ as a homomorphism $V: G \\to Q$.\n\nWe have that $V(g) = \\prod h_i^{-1}g^{n_i}h_i$ for some powers $n_i$ and $h_i$ in some transversal of $Q$.\n\nIf $g \\in Q$ then $g^{n_i}$ and $h_i^{-1}g^{n_i}h_i$ are also in $Q$, by the theorems above.\n\nAs $Q$ is abelian, $Q \\leq C_G(Q)$ and so the elements $g^{n_i}$ and $h_i^{-1}g^{n_i}h_i$ are conjugate in $C_G(Q)$. Thus by the previous theorem there is a $c \\in N_G(Q)$ such that $h_i^{-1}g^{n_i}h_i = c^{-1}g^{n_i}c$.\n\nBut if $Q \\leq Z(N_G(C))$ then $c^{-1}g^{n_i}c = g^{n_i}$ and so if $n = [G:Q]$, we have that $V(g) = g^n$ for all $g \\in Q$.\n\nAs $Q$ is a Sylow subgroup, gcd$(n, q) = 1$, where $q = |Q|$. Thus by the extended Euclidean algorithm, there exist $\\alpha, \\beta \\in \\Z$ with $\\alpha n + \\beta q = 1$.\n\nThus for $g \\in Q$ we have $g = g^{\\alpha n}g^{\\beta q} = (g^\\alpha)^n$. Thus $V : G \\to Q$ is surjective.\n\nBy the first isomorphism theorem $G/K \\cong Q$ where $K =$ ker$(V)$. Thus $G = KQ$, $K\\cap Q = 1$ because $|K| = n$ and thus gcd$(|K|, |Q|) = 1$.\n\nThus $K$ is a normal complement of $Q$ as required. $\\square$\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "6d1bd122a06c43430e04a4c73fc79e116fd6d724", "size": 186365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GroupTheory.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": "GroupTheory.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": "GroupTheory.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": 41.8515607456, "max_line_length": 556, "alphanum_fraction": 0.6645990395, "num_tokens": 66430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.6117144788988533}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{geometry} \n\\geometry{margin=1in}\n\\geometry{a4paper} \n\n\n\\usepackage{textcomp}\n\\usepackage{booktabs}\n\\usepackage{array}\n\\usepackage{paralist}\n\\usepackage{verbatim} \n\\usepackage{subfigure}\n\\usepackage{graphicx,caption}\n\\usepackage{placeins}\n\\usepackage{lipsum}\n\\usepackage{xcolor}\n\\usepackage{dcolumn}\n\\usepackage{sectsty}\n\\allsectionsfont{\\sffamily\\mdseries\\upshape}\n\\usepackage{gensymb,amsmath,mathtools,amssymb}\n\\usepackage{flafter}\n%\\usepackage{parskip}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{tocbibind}\n\\usepackage[toc,page]{appendix}\n\\captionsetup{width=\\linewidth}\n\\usepackage{bm}\n\\usepackage{url}\n\\usepackage{empheq}\n\n\\newcommand{\\half}{\\frac{1}{2}}\n\n\n\\graphicspath{{./figs/}}\n\n\n\\title{Passive Flight Solution}\n\\author{Devansh Agrawal}\n%\\date{} \n\n\n\\begin{document}\n\n\\maketitle\n\n\n\\section{Problem statement}\n\nThe dynamics of a rocket flying along the vertical axis (without thrust) can be written as\n\n\\begin{align}\n\\dot{h} &= v\\\\\n\\dot{v} &= -\\frac{D}{m} - g = -\\beta v^2  - g\n\\end{align}\nwhere I have defined a modified ballistic coefficient\n\\begin{equation}\n\\beta = \\frac{1}{2} \\rho \\frac{C_D A}{m}\n\\end{equation}\n\nSince there is no thrusting, the mass is constant, and therefore $\\beta$ is also constant. \n\nFurther we assign the following boundary conditions, \n\n\\begin{align}\nh(0) &= h_0\\\\\nv(0) &= v_0\\\\\nv(t_f) &= 0\n\\end{align}\n\nWe wish to solve these equations, and determine the coasting distance. \n\n\n\\section{Coasting Distance}\n\nUsing Mathematica's DSolve function, we can solve this non-linear coupled ode. Mathematica returns two solutions (which have been simplified here)\\footnote{$\\log$ here refers to the natural logarithm}:\n\nSolution 1 (invalid):\n\\begin{align}\nh(t) &=h_0 + \\frac{\\log \\left(\\cos \\left(\\sqrt{\\beta  g}(t_f-t)\\right)\\right)}{\\beta }-\\frac{\\log \\left(-\\sqrt{\\frac{g}{g+\\beta  v_0^2}}\\right)}{\\beta }\\\\\nv(t) &=\\sqrt{\\frac{g}{\\beta }} \\tan \\left(\\sqrt{\\beta  g}(t_f-t)\\right)\n\\end{align}\n\nand solution 2 (valid):\n\\begin{align}\nh(t) &=h_0 + \\frac{\\log \\left(\\sqrt{1+\\frac{\\beta  v_0^2}{g}} \\cos \\left(\\sqrt{\\beta  g}(t_f-t)\\right)\\right)}{\\beta } \\label{eqn:h}\\\\\nv(t) &= \\sqrt{\\frac{g}{\\beta }} \\tan \\left(\\sqrt{\\beta  g}(t_f-t)\\right) \\label{eqn:v}\n\\end{align}\n\nNotice, that due to the second logarithm in solution 1, it must be invalid\\footnote{or if you think about expanding the log(negative square root()) into negative half log(), the expression turns out to be same as solution 2}, and that the velocity in both solutions are identical. Therefore, solution 2 is the accurate flight path. \n\nImmediately we can see from eqn~\\ref{eqn:h} that the remaining height to go for the rocket is \n\\begin{equation}\n\\boxed{\\Delta h = h(t_f) - h_0 = \\frac{1}{\\beta} \\log \\left(\\sqrt{1+\\frac{\\beta  v_0^2}{g}} \\right)}\n\\end{equation}\n\nIn the limit that drag is insignificant $\\beta \\rightarrow 0$, and the equation correctly approaches the kinematic result, \n\n\\begin{equation}\n\\lim_{\\beta\\rightarrow0} \\Delta h = \\frac{1}{2} \\frac{v_0^2}{ g}\n\\end{equation}\n\nThe figure shows the results plotted. \n\n\n%\\FloatBarrier\n\\begin{figure}[htbp]\n   \\centering\n   \\includegraphics[width=0.8\\linewidth]{coast_regions}\n   \\caption{This figure shows the combination of height to target and current flight speeds that will allow the rocket to coast to the target height. We see little dependence on the dry mass in the range of masses we are interested in. It is extremely important not to overshoot this line. The red lines shows the limiting case where the drag force can be neglected, and is a nice proxy for the case that drag cannot be accurately modelled.}\n   \\label{fig:}\n\\end{figure}\n%FloatBarrier\n\n%\\FloatBarrier\n\\begin{figure}[htbp]\n   \\centering\n   \\includegraphics[width=0.8\\linewidth]{impulsiveCorrection.eps}\n   \\caption{This figure shows the amount of propellant needed if an impulsive manoeuvre is to be used to get the current (h,v) point onto the coasting line (ie moving sideways on the graph). It is computed for a specific case of 20~kg dry mass, and shows that rather small amounts of propellant are needed (note, the propellant mass needed scales basically linearly with dry mass though). Less propellant should be needed for a non-impulsive manoeuvre. Therefore we could design the open loop trajectory aiming for 40~m/s at 300 m remaining, which gives us on the order 4 seconds to recompute and implement the final thrusting.}\n   \\label{fig:}\n\\end{figure}\n\\FloatBarrier\n\n\n\\section{Full Flight Path}\n\nIf we assume $v$ behaves well, we can solve eqn~\\ref{eqn:v} for the final time using $t=0$,  and determine the flight profile:\n\n\\begin{empheq}[box = \\fbox]{align}\nt_f &= \\frac{1}{\\sqrt{\\beta g}} \\arctan{\\left(v_0 \\sqrt{\\frac{\\beta}{g}}\\right)}\\\\\nh(t) &= h_0 + \\frac{1}{\\beta} \\log \\left[\\cos \\left(t \\sqrt{\\beta  g}\\right)+\\sqrt{\\frac{\\beta  v_0^2 }{ g}} \\sin \\left(t \\sqrt{\\beta  g}\\right)\\right]\\\\\nv(t) &= \\sqrt{\\frac{g}{\\beta }} \\tan \\left[\\arctan\\left(v_0\\sqrt{\\frac{\\beta }{g}}\\right) - t \\sqrt{\\beta  g}\\right]\n\\end{empheq}\n\n\nWhile these expressions look complicated, they are in closed form, and therefore are extremely useful!\n\nNote, these derivations ignore the change in drag coefficient with mach number, and the change in air density with altitude. \n\n\n\n\n%\\bibliographystyle{unsrt}\n%\\bibliography{biblio}\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\n\n\n", "meta": {"hexsha": "c03d37ac29f54c28e3ba35ad05867dd667170f57", "size": 5353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PassiveFlight/passive_flight_solution.tex", "max_stars_repo_name": "icl-rocketry/optimalAscent", "max_stars_repo_head_hexsha": "a841745e4097c55fa4996dddc8a7dc45b2059023", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-08-19T01:06:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-06T05:32:08.000Z", "max_issues_repo_path": "PassiveFlight/passive_flight_solution.tex", "max_issues_repo_name": "icl-rocketry/optimalAscent", "max_issues_repo_head_hexsha": "a841745e4097c55fa4996dddc8a7dc45b2059023", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PassiveFlight/passive_flight_solution.tex", "max_forks_repo_name": "icl-rocketry/optimalAscent", "max_forks_repo_head_hexsha": "a841745e4097c55fa4996dddc8a7dc45b2059023", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-06T05:32:10.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T05:32:10.000Z", "avg_line_length": 31.4882352941, "max_line_length": 628, "alphanum_fraction": 0.7257612554, "num_tokens": 1624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702642896702, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6117144645985335}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\marginpar{Monday\\\\ 2020-10-12, \\\\ compiled \\\\ \\today}\n\nWe come back to our noisy dataset \\(x_i = \\mu + n_i\\). \nIf our noise comes from a Gaussian with a \\emph{known}, \\emph{constant} \\(\\sigma \\), then we have \n%\n\\begin{align}\n\\mathscr{L}(x_i | \\mu , \\sigma )\n= \\frac{1}{\\sigma \\sqrt{2 \\pi }} \n\\exp(- \\frac{1}{2} \\frac{(x_i - \\mu )^2}{\\sigma^2})\n\\,.\n\\end{align}\n\nWe also assume that the realizations of the noise are independent. \nSo, the combined likelihood for all the data is given by \n%\n\\begin{align}\n\\mathscr{L}(\\vec{x} | \\mu , \\sigma ) = \\prod_{i=1}^{N} \\mathscr{L}(x_i, \\mu , \\sigma )\n\\,.\n\\end{align}\n\nNow, choosing a prior as we mentioned is difficult in general. Until now we have assumed that our noninformative prior would be constant. \nFor the type of parameter we have now --- \\(\\mu \\) is a \\emph{location} parameter --- works; however we have an issue: a uniform distribution must have a certain range in which it is nonzero, elsewhere it is zero. \nThis range must be finite.\n \nZero cannot be updated: this is a problem.\nWe can, however take a prior that is so wide that it is nonzero in any place the likelihood is measurably nonzero. Practically speaking we only work up to finite precision, so this is not a problem. \n\nWe only case about proportionality: the posterior is proportional to the likelihood, so\n%\n\\begin{align}\nP \\propto \\prod_{i=1}^{N} \\exp(- \\frac{1}{2} \\frac{(x_i - \\mu )^2}{\\sigma^2})\n\\,,\n\\end{align}\n%\ntherefore the log-posterior is \n%\n\\begin{align}\nL = \\log P = - \\frac{1}{2 \\sigma^2} \\sum _{i=1}^{N} (x_i - \\mu ) + \\const\n\\,,\n\\end{align}\n%\nso if we want to find the maximum (log)-posterior: \n%\n\\begin{align}\n\\dv{L}{\\mu }  = \\sum_{i=1}^{N} \\frac{x_i- \\mu }{\\sigma^2}  =0 \n\\,,\n\\end{align}\n%\nmeaning that \n%\n\\begin{align}\nN \\mu = \\sum_{i=1}^{N} x_i \\implies \\hat{\\mu} = \\frac{1}{N} \\sum_{i=1}^{N} x_i\n\\,.\n\\end{align}\n\nWe can also compute the estimate of the error on the estimate: \n%\n\\begin{align}\n\\dv[2]{L}{\\mu } =- \\sum_{i=1}^{N} \\frac{1}{\\sigma^2} = - \\frac{N}{\\sigma^2}\n\\,,\n\\end{align}\n%\ntherefore \n%\n\\begin{align}\n\\sigma_\\mu = \\qty(- \\dv[2]{L}{\\mu })^{-1/2} = \\frac{\\sigma}{\\sqrt{N}}\n\\,.\n\\end{align}\n\nThe great simplification we made here was that we are dealing with only one parameter.\nIn any realistic astrophysics scenario we have at least a dozen. \n\n\\section{Multiparameter estimation}\n\n\\subsection{A two-parameter example}\n\nWe consider a photon counting experiment. \nWe have a diffraction experiment: we can measure light in \\(M\\) frequency channels, labelled by \\(k\\), and at different angles. \n\nOur model (we need one for parameter estimation) is that for each frequency channel \\(k\\) we expect a Gaussian spatial profile centered around \\(x_0 \\) --- for simplicity we assume \\(x_0 \\) is known, and that the standard deviation \\(w\\) is known as well.\nWe are interested in the amplitude \\(A\\) of this Gaussian peak.\n\nAlso, we will have spatially constant noise with amplitude \\(B\\).\nWe need to estimate \\(A\\) and \\(B\\) jointly; \\(B\\) is a \\emph{nuisance parameter} we would ideally integrate over later. \n\nWe expect that the measured data at a frequency channel will look like \n%\n\\begin{align}\nD_k = n_0 \\qty[ A\\exp(- \\frac{(x_k - x_0)^2}{2 w^2} + B)]\n\\,.\n\\end{align}\n\nThe parameter \\(n_0 \\) accounts for the fact that if we measure for longer we see more photons. \n\nPhotons, both noise and signal, are expected to obey Poissonian statistics: \n%\n\\begin{align}\n\\mathbb{P}(N_k | D_k) = \\frac{D_k^{N_k} e^{- D_k}}{N_k!}\n\\,,\n\\end{align}\n%\nwhich is the likelihood: the probability of the data, given our model. \nOur actual likelihood will be given by \\(\\mathscr{L} = \\prod_k \\mathbb{P}(N_k | D_k)\\).\n\nWhat is our prior \\(\\mathbb{P}(A,B | I)\\)? We know that these parameters cannot be negative, so we just take a uniform bivariate prior on \\(A\\geq 0\\),  \\(B \\geq 0\\).\nAs before, this is just meant to say ``uniform over all representable values''. \n\nWe will discuss later that by the nature of \\(A\\) as a scale parameter it would be more reasonable to take \\(\\log A\\) to be uniform.\n\nThe posterior will then be \n%\n\\begin{align}\n\\mathbb{P}(A, B | N_k, I) \\propto\n \\prod_k \\frac{D_k^{N_k} e^{-D_k}}{N_k!}\n\\,.\n\\end{align}\n\nThis then depends on two parameters, and we can maximize it numerically. It is a difficult problem computationally, but not conceptually. \n\nHow can we model this in order to give an error? We can approximate it as a bivariate Gaussian. \n\nIn general, a multivariate Gaussian is given as \n%\n\\begin{align}\n\\mathbb{P}(\\vec{x}) = \\frac{1}{(2 \\pi )^{n/2} \\abs{\\Sigma }^{1/2}}\n\\exp(- \\frac{1}{2} (\\vec{x} - \\vec{\\mu})^{\\top} \\Sigma^{-1} (\\vec{x} - \\vec{\\mu}))\n\\,,\n\\end{align}\n%\nwhere \\(\\Sigma \\) is the \\textbf{covariance matrix} of the two variables. \nOn the diagonal we have the variance of each variable: \\(\\Sigma_{ii} = \\sigma_i^2\\), so \\((\\Sigma^{-1})_{ii} = 1 / \\sigma _i^2\\) as long as the covariance (meaning, the nondiagonal elements) is zero.\n\n\\end{document}\n", "meta": {"hexsha": "e84b4ee8dbf3adda91bfc2e541b97f657ff986fa", "size": 4974, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostatistics_cosmology/oct12.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_third_semester/astrostatistics_cosmology/oct12.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_third_semester/astrostatistics_cosmology/oct12.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": 36.3065693431, "max_line_length": 255, "alphanum_fraction": 0.6801367109, "num_tokens": 1589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6116454580372434}}
{"text": "In this report we have introduced Markov Chain Monte Carlo algorithms, with a particular focus on Langevin Monte Carlo methods. We then tested the performance of the algorithms based on a number of metrics and a broad range of parameters. Our main contribution is extending the work of \\cite{Brosse18tULA} and producing a \\textsc{Python} package ready for use by other researchers to implement their own methods to be tested against the algorithms we have presented here. As well as implementing their own methods, it is also written in a way that allows easy extension to different potentials and distributions. As well as this, we have extended the visualisation library of Rogozhnikov \\cite{rogozhnikov2016hmc} to include LMC methods. This allows students and those newly introduced to the field to get an intuitive look at how these algorithms work, and the differences between them. \n\nWe have shown that taming is a viable method of preventing divergence of Langevin-based algorithms and gives insight into a distribution when Metropolised algorithms are unable to, particularly in ill-conditioned problems. It is interesting to note the efficiency of the \\texttt{LM} algorithm in particular, despite its relative simplicity. It does however suffer from divergence problems as \\texttt{ULA}.\n\nThere is no simple answer as to which algorithm is `best'. Depending on the application, and the prior information given on the distribution, one could make the case for any of the algorithms presented here. If the general shape of the distribution is known and computational power is not a restriction, a simple Random Walk Metropolis algorithm may well be the best option, even in the superlinear case.\n\nIf very little is known about maxima of the distribution, the taming method is the best choice. It is able to quickly find the modes of the distribution without divergence, however once at the mode it often over estimates the width of the potential well.  This has provoked some investigation into `switching' methods, where the chain is initially started using \\texttt{tULA} for a fixed time to find the mode, before switching to the \\texttt{RWM} algorithm to better explore the well. This is the rationale behind the \\texttt{HPH} algorithm in the package, however it has been omitted from the report due to a lack of theoretical justification. It may well turn out to be similar to existing adaptive time stepping methods, or tempering methods.\n\nHigher order methods seem to come at too great a computational cost, especially in very high dimension, although the theory supporting them suggests that more work is to be done on the numerical implementation of such methods.\n\nIf this report has highlighted anything, it is that Metropolisation is not the final word in Langevin Monte Carlo, and other methods of approximating Langevin dynamics should be exploited and explored. Non-asymptotic bounds are of great importance in this area, as it is known that \\texttt{MALA} converges in the limit but this is of little practical use. \n\n\\subsection{Future Work}\\label{subsec:future}\nThere are many possible ways in which the work presented here could be extended, both from a research and personal perspective. First, there is great scope for the improvement of our program. It is possible to add new analytic distributions to sample from, including those with non-smooth potentials as in \\cite{durmus2018efficient}. Another obvious avenue would be to apply all the methods and analysis here to real (large) datasets, when the gradient is not known analytically. This would give the end user a much clearer impression of which algorithm to use in their given case. It would also slow down all gradient based methods as an unbiased estimator for the gradient would have to be calculated at every iteration. It may also be possible to speed up the higher order methods (\\texttt{HOLA,tHOLA,tHOLAc}) by implementing a parallelised version, breaking up the complex iteration into smaller easier to manage sections. This in general is highly non-trivial due to the inherent dependence on the previous step in a Markov chain. Another important consideration is that of burn-in time. For the majority of our tests, we started from a minimiser of the potential well however our code is certainly not limited to this case. Doing so effectively removes any burn-in time as the chains are started in approximate stationarity. When started far away from the mode of a distribution, initial tests suggest taming is a highly preferable method to Metropolised algorithms. They take many more steps towards the mode, while Metropolised algorithms waste lots of time rejecting moves. In practice, this would greatly reduce the burn-in time -- a key feature of an effective MCMC method. \n\nIt is also important that we test the accuracy of our measures. This is difficult, especially in high dimensions as no methods exist for numerically calculating the 2-Wasserstein metric that many of the theoretical bounds use. Furthermore, using kernel density estimation or histograms with few bins introduces an error that is difficult to quantify and reduce. Here we have only qualitative comparisons between metrics. This is a well known problem in numerical optimal transport and inherent in dealing with high dimensional datasets and problems.\n\nMany other methods exist in MCMC that remain to be tested against the tamed algorithms, or incorporated in to our program. These include Hamiltonian Monte Carlo (HMC), manifold MALA (mMALA), underdamped Langevin Monte Carlo and stochastic gradient Langevin dynamics (SGLD) \\cite{betancourt2017conceptual, Girolami2011,cheng2018,pitfalls}. For dealing with stiff problems, specific methods also exist that could be used as benchmarks for taming algorithms \\cite{abdulle2013weak}. In the next section SGLD will be expanded on due to its popularity in machine learning and high dimensional problems. \n\nFor the wider field, it is important that either `user-friendly' bounds on nonasymptotic error are developed in terms of a numerically implementable metric, or that methods are developed to accurately calculate the 2-Wasserstein metric. Even this will not solve the problem of approximating a high dimensional distribution using samples from a distribution; it is simply infeasible to be able to generate enough samples to get a good representation. \n\n", "meta": {"hexsha": "56b6995b7c97750cb1a09afd1e1db2afd9834d9b", "size": 6372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WriteUp/conclusion.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/conclusion.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/conclusion.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": 289.6363636364, "max_line_length": 1685, "alphanum_fraction": 0.816698054, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6116454537771374}}
{"text": "\\subsection{Semimodules}\\label{subsec:semimodules}\n\nSemimodules are generalizations of monoid actions. Notation and terminology-wise, semimodules are somewhat special in that they are very much influenced by linear algebra and analysis, where vector spaces are crucial.\n\n\\begin{definition}\\label{def:endomorphism_semiring}\n  Let \\( X \\) be a monoid or, more generally, an object in a \\hyperref[def:category]{category} that is \\hyperref[def:concrete_category]{concrete} over \\hyperref[def:monoid/category]{\\( \\cat{Mon} \\)}.\n\n  Let \\( \\End(X) \\) be the \\hyperref[def:endomorphism_monoid]{endomorphism monoid} over \\( X \\). These are necessarily monoid endomorphisms, however they may carry additional structure like being \\hyperref[def:group/homomorphism]{group homomorphisms}, \\hyperref[def:semimodule/homomorphism]{semimodule homomorphisms}, \\hyperref[def:semilattice/homomorphism]{(semi)lattice homomorphisms} or their \\hyperref[rem:topological_first_order_structures]{continuous counterparts}.\n\n  Define addition in \\( \\End(X) \\) pointwise as \\( [f + g](x) \\coloneqq f(x) + g(x) \\). Then \\( \\End(X) \\) with pointwise addition and composition is a \\hyperref[def:semiring]{semiring}, which we call the \\term{endomorphism semiring} over \\( X \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:semimodule}\n  Fix a \\hyperref[def:semiring]{semiring} \\( R \\), whose elements we will call \\term{scalars}, and an \\hyperref[rem:additive_magma]{additive} \\hyperref[def:magma/commutative]{commutative} \\hyperref[def:monoid]{monoid} \\( M \\), whose elements we will call \\term{vectors}. See \\fullref{rem:vector_etymology} for a discussion of the term \\enquote{vector}.\n\n  We say that \\( M \\) is a \\term{semimodule} over \\( R \\) if they are compatible in any of the equivalent ways listed below. Analogously to \\hyperref[def:monoid_action]{monoid actions}, if \\( R \\) is not commutative, we distinguish between left and right semimodules. Rather than \\enquote{\\( M \\) is a semimodule over \\( R \\)}, it is often more convenient to say \\enquote{\\( M \\) is an \\( R \\)-semimodule}.\n\n  \\begin{thmenum}[series=def:semimodule]\n    \\thmitem{def:semimodule/action} A left semimodule is a \\hyperref[def:semiring/homomorphism]{homomorphism} from \\( R \\) to the \\hyperref[def:endomorphism_semiring]{endomorphism semiring} \\( \\End(M) \\). A right semimodule is a homomorphism from the \\hyperref[def:semiring/opposite]{dual semiring} \\( R^{-1} \\) to \\( \\End(M) \\).\n\n    This definition is concise and natural, but unfortunately not very useful.\n\n    \\thmitem{def:semimodule/operation} The usual way to define a left semimodule is via a binary operation \\( \\cdot: R \\times M \\to M \\) called \\term{scalar multiplication} that satisfies the following conditions:\n    \\begin{thmenum}\n      \\thmitem{def:semimodule/operation/scalar_multiplication_action} Scalar multiplication is a \\hyperref[def:monoid_action]{monoid action} of the multiplicative monoid \\( (R, \\cdot_R) \\) on \\( M \\). The following conditions correspond to \\eqref{eq:def:monoid_action/family/identity} and \\eqref{eq:def:monoid_action/family/compatibility}:\n      \\begin{align}\n        &1_R \\cdot x = x, \\label{eq:def:semimodule/operation/scalar_multiplication_action/identity} \\\\\n        &(r \\cdot_R s) \\cdot x = r \\cdot (s \\cdot x). \\label{eq:def:semimodule/operation/scalar_multiplication_action/compatibility}\n      \\end{align}\n\n      The second condition can be regarded as a form of associativity.\n\n      \\thmitem{def:semimodule/operation/scalar_addition_distributivity} Scalar addition distributes over scalar multiplication:\n      \\begin{equation}\\label{eq:def:semimodule/operation/scalar_addition_distributivity}\n        (r +_R s) \\cdot x = r \\cdot x + s \\cdot x.\n      \\end{equation}\n\n      \\thmitem{def:semimodule/operation/vector_addition_distributivity} Vector addition distributes over scalar multiplication:\n      \\begin{equation}\\label{eq:def:semimodule/operation/vector_addition_distributivity}\n        r \\cdot (x + y) = r \\cdot x + r \\cdot y.\n      \\end{equation}\n\n      \\thmitem{def:semimodule/operation/absorption} The scalar and vector zeros are compatible:\n      \\begin{equation}\\label{eq:def:semimodule/operation/absorption}\n        0_R \\cdot x = 0_M = r \\cdot 0_M.\n      \\end{equation}\n    \\end{thmenum}\n\n    In practice, we use the same symbol for both scalar and vector addition, and we denote both scalar and vector multiplication via juxtaposition.\n  \\end{thmenum}\n\n  Semimodules have the following metamathematical properties:\n  \\begin{thmenum}[resume=def:semimodule]\n    \\thmitem{def:semimodule/theory} In order to fit the heterogeneous operation \\( \\cdot \\) into the framework of \\hyperref[def:first_order_semantics/satisfiability]{first-order logic models}, we can extend the \\hyperref[def:monoid/theory]{theory of monoids} by adding, for every semiring element \\( r \\), a unary \\hyperref[def:first_order_language/func]{functional symbol} \\( m_r \\). All conditions can then be reformulated via this operation. For example, \\eqref{eq:def:semimodule/operation/scalar_multiplication_action/compatibility} corresponds to the axiom schema\n    \\begin{equation*}\n      m_{rs}(\\xi) = m_r(m_s(\\xi)).\n    \\end{equation*}\n\n    \\thmitem{def:semimodule/homomorphism} A \\hyperref[def:first_order_homomorphism]{first-order homomorphism} between two \\( R \\)-semimodules \\( M \\) and \\( N \\) is a function \\( \\varphi: M \\to N \\) that is a \\hyperref[def:monoid/homomorphism]{monoid homomorphism} and satisfies \\( \\varphi \\bincirc m_r^M = m_r^N \\bincirc \\varphi \\).\n\n    This can be expressed more clearly via the following two conditions, which we call \\term{additivity} and \\term{homogeneity}:\n    \\begin{align}\n      \\varphi(x + y) &= \\varphi(x) + \\varphi(y) \\label{def:semimodule/homomorphism/additive} \\\\\n         \\varphi(rx) &= r \\varphi(x) \\label{def:semimodule/homomorphism/homogeneity}\n    \\end{align}\n\n    Functions satisfying additivity and homogeneity are commonly called \\term{linear}. These are a central object of study in \\hyperref[sec:linear_algebra]{linear algebra} and, to a lesser extent, (linear) \\hyperref[sec:functional_analysis]{functional analysis}.\n\n    \\thmitem{def:semimodule/submodel} The set \\( A \\subseteq M \\) is a \\hyperref[thm:substructure_is_model]{submodel} of \\( M \\) if it is a \\hyperref[def:monoid/submodel]{submonoid} of \\( M \\) that is closed under scalar multiplication, i.e. \\( rM = m_r[M] \\subseteq M \\) for every \\( r \\in R \\). We say that \\( A \\) is an \\( R \\)-\\term{sub-semimodule} of \\( M \\). If \\( M \\) is a module over some semiring extension \\( T \\) of \\( R \\), \\( A \\) may not be a \\( T \\)-sub-semimodule. For this reason, we should only use the term \\enquote{sub-semimodule} of the underlying ring is clear from the context.\n\n    As a consequence of \\fullref{thm:positive_formulas_preserved_under_homomorphism}, the \\hyperref[def:multi_valued_function/image]{image} of an \\( R \\)-semimodule homomorphism \\( \\varphi: M \\to N \\) is an \\( R \\)-sub-semimodule of \\( M \\).\n\n    For an arbitrary set \\( A \\), we denote the \\hyperref[def:first_order_generated_substructure]{generated submodel} by \\( \\linspan{ A } \\) and call it the \\term{linear span} of \\( A \\).\n\n    \\Fullref{rem:span_over_different_semirings} shows how it is important to be unambiguous about over which semiring we take the span of \\( A \\). In case of possible ambiguity, we will use subscripts like \\( \\linspan_R A \\).\n\n    The linear span can be characterized via \\hyperref[rem:linear_combinations]{linear combinations} --- see \\fullref{ex:def:first_order_substructure/vector_space}.\n\n    \\thmitem{def:semimodule/trivial} The \\hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} semimodule is the \\hyperref[def:pointed_set/trivial]{trivial pointed set} \\( \\set{ 0 } \\).\n\n    \\thmitem{def:semimodule/bisemimodule} A \\term{bisemimodule} is a triple \\( (R, A, B) \\), where \\( A \\) is a left \\( R \\)-semimodule, \\( B \\) is a right \\( R \\)-semimodule, and the following associativity condition holds for \\( a \\in A \\), \\( r \\in R \\) and \\( b \\in B \\):\n    \\begin{equation}\\label{eq:def:semimodule/bimodule/associativity}\n      (a \\cdot_A r) \\cdot_B b = a \\cdot_A (r \\cdot_B b).\n    \\end{equation}\n\n    \\thmitem{def:semimodule/category} For a fixed semiring \\( R \\), the \\hyperref[def:category_of_small_first_order_models]{category of \\( \\mscrU \\)-small models} \\( \\ucat{SMod}_R \\) of left semimodules is \\hyperref[def:concrete_category]{concrete} over \\hyperref[def:monoid]{\\( \\ucat{Mon} \\)}.\n\n    Other notations are in use, for example \\( R-\\cat{Mod} \\) in \\cite[158]{Aluffi2009}, that better highlight whether we are considering left or right semimodules. We will prefer \\( \\cat{Mod}_R^{\\opcat} \\) for the category of right modules.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:semimodule/action}{def:semimodule/operation} Fix a semiring homomorphism \\( \\varphi: R \\to \\End(M) \\) and define the operation \\( r \\cdot x \\coloneqq \\varphi(r)(x) \\).\n\n  We will verify that all conditions from \\fullref{def:semimodule/operation} hold for this operation.\n\n  \\begin{itemize}\n    \\item By definition, \\( \\varphi \\) is a monoid action of \\( (R, \\cdot) \\) on \\( (M, \\bincirc) \\).\n\n    \\item Distributivity of scalar addition holds because \\( \\varphi \\) is a \\hyperref[def:magma/homomorphism]{magma homomorphism} from \\( (R, +) \\) to \\( (M, +) \\).\n\n    \\item Distributivity of vector addition holds because, for each \\( r \\), \\( \\varphi(r) \\) is a magma endomorphism of \\( (M, +) \\).\n\n    \\item Since \\( \\varphi \\) is a monoid homomorphism from \\( (R,  +) \\) to \\( (R, \\cdot) \\), it preserves identities and hence\n    \\begin{equation*}\n      0_R \\cdot x = \\varphi(0_R)(x) = [y \\mapsto 0_M](x) = 0_M.\n    \\end{equation*}\n\n    This proves half of \\fullref{def:semimodule/operation/absorption}.\n\n    \\item Since, for each \\( r \\), \\( \\varphi(r) \\) is a monoid endomorphism of \\( (M, +) \\), we have\n    \\begin{equation*}\n      r \\cdot 0_M = \\varphi(r)(0_M) = 0_M.\n    \\end{equation*}\n\n    This proves the other half of \\fullref{def:semimodule/operation/absorption}.\n  \\end{itemize}\n\n  \\ImplicationSubProof{def:semimodule/operation}{def:semimodule/action} Let \\( \\cdot: R \\times M \\to M \\) be an operation satisfying all conditions from \\fullref{def:semimodule/operation}. Define the function \\( \\varphi(r) \\coloneqq (x \\mapsto r \\cdot x) \\). We will show that this is a semiring homomorphism.\n\n  It preserves both identities because\n  \\begin{equation*}\n    \\varphi(0_R) = (x \\mapsto 0) = 0_{\\End(M)}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\varphi(1_R) = (x \\mapsto x) = \\id_M.\n  \\end{equation*}\n\n  We must also show that it preserves both binary operations. Clearly\n  \\begin{equation*}\n    \\varphi(r + s)\n    =\n    (x \\mapsto (r + s) x)\n    \\reloset {\\eqref{eq:def:semiring/right_distributivity}} =\n    (x \\mapsto r x + s x)\n    =\n    (x \\mapsto r x) + (x \\mapsto s x)\n    =\n    \\varphi(r) + \\varphi(s).\n  \\end{equation*}\n\n  For multiplication, we have\n  \\begin{equation*}\n    \\varphi(rs)\n    =\n    (x \\mapsto (rs)x)\n    \\reloset {\\eqref{eq:def:magma/associative}} =\n    (x \\mapsto r(sx))\n    =\n    \\parens[\\Big]{ x \\mapsto \\varphi(r)\\parens[\\Big]{ \\varphi(s)(x) } }\n    =\n    \\varphi(r) \\bincirc \\varphi(s).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:semimodule}\n  \\hyperref[def:semimodule]{Semimodules} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:semimodule/union} The union of a \\hyperref[eq:def:partially_ordered_set/homomorphism/sequence]{monotone sequence}\n    \\begin{equation*}\n      N_1 \\subseteq N_2 \\subseteq \\cdots\n    \\end{equation*}\n    of \\( R \\)-\\hyperref[def:semimodule/submodel]{sub-semimodules} of \\( M \\) is also an \\( R \\)-sub-semimodule of \\( M \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:semimodule/union} Trivial.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:semiring_is_semimodule}\n  Every semiring is a \\hyperref[def:semimodule/bisemimodule]{bisemimodule} over itself with scalar multiplication given by the semiring multiplication.\n\n  This result specializes to \\fullref{thm:semiring_is_algebra}.\n\\end{proposition}\n\\begin{proof}\n  Fix a semiring \\( R \\). We will show that \\( \\cdot \\) satisfied the conditions in \\fullref{def:semimodule/operation}.\n  \\begin{itemize}\n    \\item The identity law \\eqref{eq:def:semimodule/operation/scalar_multiplication_action/identity} holds because \\( 1 \\) is a multiplicative identity of \\( M \\).\n    \\item The associativity-like law \\eqref{eq:def:semimodule/operation/scalar_multiplication_action/compatibility} follows from associativity of multiplication.\n    \\item The two distributivity laws \\eqref{eq:def:semimodule/operation/scalar_addition_distributivity} and \\eqref{eq:def:semimodule/operation/vector_addition_distributivity} follow from left and right distributivity on \\( R \\).\n    \\item The absorption law \\eqref{eq:def:semimodule/operation/absorption} follows from absorption on semirings.\n  \\end{itemize}\n\n  All the above also hold for right semimodules rather than left.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:commutative_monoid_is_semimodule}\n  The categories \\( \\hyperref[def:monoid/category]{\\cat{CMon}} \\) of commutative monoids and \\( \\hyperref[def:semimodule/category]{\\cat{SMod}_\\BbbN} \\) of natural number semimodules are \\hyperref[rem:category_similarity/isomorphism]{isomorphic}.\n\n  More concretely, every commutative monoid \\( M \\) is a left semimodule over \\( \\BbbN \\) with scalar multiplication given by \\hyperref[rem:additive_magma/multiplication]{recursively defined multiplication}\n  \\begin{equation}\\label{eq:thm:commutative_monoid_is_semimodule/operation}\n    \\begin{aligned}\n      &\\cdot: \\BbbN \\times M \\to M \\\\\n      &n \\cdot x \\coloneqq \\begin{cases}\n        0_M,           &n = 0, \\\\\n        n \\cdot x + x, &n > 1.\n      \\end{cases}\n    \\end{aligned}\n  \\end{equation}\n\n  Conversely, in every semimodule over \\( \\BbbN \\), scalar multiplication matches the recursively defined multiplication.\n\n  This result specializes to \\fullref{thm:semiring_is_natural_number_algebra} and \\fullref{thm:abelian_group_is_module}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( M \\) be a commutative monoid. The operation \\( \\cdot: \\BbbN \\times M \\to M \\) defined in \\fullref{thm:semiring_characteristic_homomorphism} satisfies the conditions in \\fullref{def:semimodule/operation} as either a direct consequence of the definition or as a consequence of \\fullref{thm:monoid_distributivity}.\n\n  The homomorphisms are thus also compatible.\n\n  \\NecessitySubProof Let \\( M \\) be a semimodule over \\( \\BbbN \\). We will use induction to show that \\eqref{eq:thm:semiring_is_semimodule/operation} holds.\n  \\begin{itemize}\n    \\item For \\( n = 0 \\), this follows from the absorption law \\eqref{eq:def:semimodule/operation/absorption}.\n    \\item If \\( n \\cdot x = n \\cdot x + x \\), then by scalar distributivity, \\( (n + 1) \\cdot x = n \\cdot x + 1 \\cdot x \\). The multiplicative identity law \\eqref{eq:def:semimodule/operation/scalar_multiplication_action/identity} then shows that \\( 1 \\cdot x = x \\), which concludes our proof.\n  \\end{itemize}\n\n  The homomorphisms are thus also compatible.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:functions_over_semimodule}\n  For a set \\( A \\) and an \\( R \\)-\\hyperref[def:semimodule]{semimodule} \\( N \\), the set \\( \\fun(A, N) \\) of all functions from \\( A \\) to \\( N \\) is itself an \\( R \\)-semimodule with the following operations:\n  \\begin{thmenum}\n    \\thmitem{thm:functions_over_semimodule/addition} Pointwise addition\n    \\begin{equation*}\n      [f + g](x) \\coloneqq f(x) + g(x)\n    \\end{equation*}\n\n    \\thmitem{thm:functions_over_semimodule/scalar_multiplication} Pointwise scalar multiplication\n    \\begin{equation*}\n      [t \\cdot f](x) \\coloneqq t \\cdot f(x)\n    \\end{equation*}\n  \\end{thmenum}\n\n  If \\( A \\) is also an \\( R \\)-algebra, we denote the semimodule of all \\( R \\)-\\hyperref[def:semimodule/homomorphism]{linear maps} by \\( \\hom(A, N) \\).\n\n  This extends to \\fullref{thm:functions_over_algebra}.\n\\end{proposition}\n\\begin{proof}\n  By \\fullref{thm:functions_over_model_form_model}, \\( N \\) is an \\( R \\)-semimodule.\n\\end{proof}\n\n\\begin{definition}\\label{def:function_support}\n  The \\term{support} of a function \\( f: S \\to R \\) from any set \\( S \\) to a semiring \\( R \\) is the set\n  \\begin{equation*}\n    \\supp(f) \\coloneqq \\set{ x \\in S \\given f(x) \\neq 0_R }.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:semimodule_direct_product}\n  The \\term{direct product} of a family of \\( R \\)-\\hyperref[def:semimodule]{semimodules} \\( \\seq{ M_k }_{k \\in \\mscrK} \\) is their \\hyperref[def:monoid_direct_product]{monoid direct product} \\( \\prod_{k \\in \\mscrK} M_k \\) with the additional componentwise scalar product\n  \\begin{equation*}\n    r \\cdot \\seq{ x_k }_{k \\in \\mscrK}\n    \\coloneqq\n    \\seq{ r \\cdot x_k }_{k \\in \\mscrK}.\n  \\end{equation*}\n\n  As in the case of general monoids, the \\term{direct sum} \\( \\bigoplus_{k \\in \\mscrK} M_k \\) is the submonoid of the direct product consisting only of \\hyperref[def:cartesian_product/tuple]{tuples} with \\hyperref[def:set_finiteness]{finite} \\hyperref[def:function_support]{support}. That is, tuples with only finitely many nonzero components.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:semimodule_categorical_limits}\n  We present a refinement to \\fullref{thm:monoid_categorical_limits}.\n\n  \\begin{thmenum}\n    \\thmitem{thm:semimodule_categorical_limits/product} The \\hyperref[def:discrete_category_limits]{categorical product} of the family \\( \\seq{ M_k }_{k \\in \\mscrK} \\) in the category \\hyperref[def:semimodule/category]{\\( \\cat{SMod} \\)} of semimodules is their \\hyperref[def:semimodule_direct_product]{direct product} \\( \\prod_{k \\in \\mscrK} M_k \\).\n\n    \\thmitem{thm:semimodule_categorical_limits/coproduct} The \\hyperref[def:discrete_category_limits]{categorical coproduct} of the family \\( \\seq{ M_k }_{k \\in \\mscrK} \\) in the category \\hyperref[def:semimodule/category]{\\( \\cat{CSMon} \\)} of \\hi{commutative} semimodules is their \\hyperref[def:semimodule_direct_product]{direct sum} \\( \\bigoplus_{k \\in \\mscrK} M_k \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  Simple refinement of \\fullref{thm:monoid_categorical_limits}.\n\\end{proof}\n\n\\begin{definition}\\label{def:free_semimodule}\\mimprovised\n  Fix a \\hyperref[def:semiring]{semiring} \\( R \\). We associate with every set \\( A \\) its \\term{free \\( R \\)-semimodule} \\( R^{\\oplus A} \\) over \\( R \\) defined as the set\n  \\begin{equation*}\n    R^{\\oplus A} \\coloneqq \\bigoplus_{x \\in A} R = \\set{ t: A \\to R \\given t \\T{has finite \\hyperref[def:function_support]{support}} }.\n  \\end{equation*}\n\n  In the case when \\( R \\) is the semiring \\( \\BbbN \\) of natural numbers, \\( \\BbbN^{\\oplus A} \\) is the set of finite \\hyperref[def:weighted_set/multiset]{multisets} over \\( S \\).\n\n  We call \\( A \\) the \\term{basis} of \\( R \\). As with general direct sums, we regard the function \\( t \\) as the indexed family \\( \\seq{ t_x }_{x \\in A} \\), and we call the indexed family a \\term{linear combination} over \\( R \\).\n\n  By \\fullref{thm:functions_over_model_form_model}, \\( R^{\\oplus A} \\) inherits addition and multiplication from \\( R \\) and is actually a semiring. Scalar multiplication can be defined as\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\cdot: R \\times R^{\\oplus A} \\to R^{\\oplus A}, \\\\\n      &r \\cdot \\seq{ t_x }_{x \\in A} \\coloneqq \\seq{ r \\cdot t_x }_{x \\in A}.\n    \\end{aligned}\n  \\end{equation*}\n\n  Finally, define the canonical inclusion.\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\iota_A: A \\to R^{\\oplus A}, \\\\\n      &\\iota_A(x) \\coloneqq \\parens[\\Bigg]\n        {\n          y \\mapsto \\begin{rcases}\n            \\begin{cases}\n              1_R, &y = x \\\\\n              0_R, &y \\neq x\n            \\end{cases}\n          \\end{rcases}\n        }\n    \\end{aligned}\n  \\end{equation*}\n\n  Free right semimodules require trivial adjustments.\n\\end{definition}\n\n\\begin{theorem}[Free semimodule universal property]\\label{thm:free_semimodule_universal_property}\n  Fix a semiring \\( R \\) and a set \\( A \\). The \\hyperref[def:free_semimodule]{free \\( R \\)-semimodule} \\( R^{\\oplus A} \\) over \\( R \\) is the unique up to a unique isomorphism semimodule that satisfies the following \\hyperref[rem:universal_mapping_property]{universal mapping property}:\n  \\begin{displayquote}\n    For every semimodule \\( M \\) over \\( R \\) and every function \\( e: A \\to M \\), there exists a unique \\( R \\)-semimodule homomorphism \\( \\Phi_e: R^{\\oplus A} \\to M \\) such that the following diagram commutes:\n    \\begin{equation}\\label{eq:thm:free_semimodule_universal_property/diagram}\n      \\begin{aligned}\n        \\includegraphics[page=1]{output/thm__free_semimodule_universal_property.pdf}\n      \\end{aligned}\n    \\end{equation}\n  \\end{displayquote}\n\n  Via \\fullref{rem:universal_mapping_property}, \\( A \\mapsto R^{\\oplus A} \\) becomes \\hyperref[def:category_adjunction]{left adjoint} to the \\hyperref[def:concrete_category]{forgetful functor}\n  \\begin{equation*}\n    U: \\cat{SMod}_R \\to \\cat{Set}.\n  \\end{equation*}\n\n  The function \\( e \\) assigns a value from \\( M \\) for each component of a linear combination, while \\( \\Phi_e \\) evaluates the obtained sum. We call \\( \\Phi_e \\) the \\term{linear extension} or \\term{linear combination evaluation map} corresponding to \\( e \\).\n\\end{theorem}\n\\begin{proof}\n  For every function \\( e: A \\to M \\), we want\n  \\begin{equation*}\n    \\Phi_e(\\iota(x)) = e(x).\n  \\end{equation*}\n\n  This suggests the definition\n  \\begin{equation*}\n    \\begin{aligned}\n      &\\Phi_e: R^{\\oplus A} \\to M, \\\\\n      &\\Phi_e(\\seq{ t_x }_{x \\in A}) \\coloneqq \\sum_{x \\in A}^n t_x \\cdot e(x).\n    \\end{aligned}\n  \\end{equation*}\n\n  We discuss well-definedness of infinitary operations in direct sums in \\fullref{rem:binary_operation_syntax_trees/infinite/direct_sum}.\n\\end{proof}\n\n\\begin{remark}\\label{rem:linear_combinations}\n  The \\hyperref[def:free_semimodule]{linear combination} \\( \\sum_{x \\in A} t_x x \\) can instead be written as \\( \\sum_{k=1}^n t_k x_k \\), where \\( x_1, \\ldots, x_n \\) are the values in \\( A \\) for which the scalars \\( t_1, \\ldots, t_n \\) are nonzero (we denote \\( t_{x_k} \\) by \\( t_k \\) for brevity). This is actually the dominating convention, although we sometimes use the former notation and. In vector spaces, we utilize the projection functionals from \\fullref{def:basis_decomposition}.\n\n  This issue is discussed in more generality in \\fullref{rem:binary_operation_syntax_trees/infinite/direct_sum}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:span_via_linear_combinations}\n  For a set \\( A \\) in an \\( R \\)-\\hyperref[def:semimodule]{semimodule} \\( M \\), the \\hyperref[def:semimodule/submodel]{linear span} of \\( A \\), defined as the \\( R \\)-submodule generated by \\( A \\) in the sense of \\fullref{def:first_order_generated_substructure}, equals the set of all \\hyperref[rem:linear_combinations]{linear combinations} over \\( A \\).\n\n  We say that \\( A \\) is a \\term{generating set} of \\( M \\).\n\n  Compare this result to \\fullref{thm:generators_via_polynomials} for algebras.\n\\end{proposition}\n\\begin{proof}\n  \\Cref{fig:thm:span_via_linear_combinations} shows a \\hyperref[def:concrete_syntax_tree]{syntax tree} for a given linear combination, which can be traversed and evaluated to obtain a vector in \\( M \\). Furthermore, it must be a member of \\( \\linspan S \\) since the latter is closed under vector addition and scalar multiplication with members of \\( S \\). Hence, the set \\( L \\) of all linear combinations over \\( S \\) is a subset of \\( \\linspan S \\).\n\n  Generalizing the syntax tree construction from \\cref{fig:thm:span_via_linear_combinations}, we see that \\( L \\) satisfies \\fullref{def:first_order_substructure/inductive}, and is thus a submodule of \\( M \\). Since \\( \\linspan S \\) is the smallest module containing \\( S \\), we have \\( \\linspan S = L \\).\n\n  \\begin{figure}[h]\n    \\hfill\n    \\includegraphics[page=1]{output/thm__span_via_linear_combinations.pdf}\n    \\hfill\\hfill\n    \\caption{A linear combination is simply a \\hyperref[def:multi_valued_function/superposition]{superposition} of scalar multiplication and binary addition.}\n    \\label{fig:thm:span_via_linear_combinations}\n  \\end{figure}\n\\end{proof}\n\n\\begin{remark}\\label{rem:span_over_different_semirings}\n  If \\( M \\) is both an \\( R \\)-semimodule and a \\( T \\)-semimodule, \\fullref{thm:span_via_linear_combinations} highlights a fundamental difference between the generated \\( R \\)-sub-semimodule and the generated \\( T \\)-sub-semimodule.\n\n  For example, the \\( \\BbbN \\)-sub-semimodule generated by \\( 2 \\) is the semiring \\( 2\\BbbN \\) of even natural numbers, while the \\( \\BbbR_{\\geq 0} \\)-sub-semimodule generated by \\( 2 \\) is \\( \\BbbR_{\\geq 0} \\) itself.\n\\end{remark}\n", "meta": {"hexsha": "61ad6adb29427e4d50a0cfc4c0547242bc50e061", "size": 24749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/semimodules.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/semimodules.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/semimodules.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": 65.8218085106, "max_line_length": 601, "alphanum_fraction": 0.708796315, "num_tokens": 7682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6116454495170317}}
{"text": "\\documentclass[a4paper]{article}\n\n\n\\input{../preambles/preamble}\n\\setdefaultlanguage{english}\n%\\setotherlanguages{german,greek}\n\n\\input{../preambles/mathematics}\n\\input{../preambles/physics}\n\n%\\newcommand{\\RomaN}[1]{%\n%  \\textup{\\uppercase\\expandafter{\\romannumeral#1}}%\n%}\n\n\n%\\addbibresource{main.bib}\n\\title{Complex Harmonic Oscillators and How to Squeeze Them}\n\\author{YiFan Wang}\n\n\\newcommand{\\Poibr}[1]{\\sbr{#1}_\\text{P}}\n\\newcommand{\\Combr}[1]{\\sbr{#1}_\\text{-}}\n\n\\newcommand{\\tR}{\\Re}\n\\newcommand{\\tI}{\\Im}\n\\newcommand{\\tS}{\\text{S}}\n\\newcommand{\\tD}{\\text{D}}\n\n\n\\begin{document}\n\\maketitle\n\n%\\begin{abstract}\n%Your abstract.\n%\\end{abstract}\n\n\\tableofcontents\n\n\\section{Single complex oscillator}\n\n\\begin{nameddef}{Classical Hamiltonian in canonical coordinates}\nComplex phase space\n\\begin{equation}\nH = \\frac{1}{2}\\pi^+\\pi^- + \\frac{\\Omega^2}{2}\\phi^+\\phi^-,\n\\end{equation}\nThe corresponding Poisson brackets read\n\\begin{equation}\n\\Poibr{\\rfun{f}{\\eta^C}, \\rfun{g}{\\eta^C}} = \\sum_C \\rbr{\n\\frpa{f}{\\phi^C}\\frpa{g}{\\pi^C} - \\frpa{f}{\\pi^C}\\frpa{g}{\\phi^C}},\n\\end{equation}\nwhere $C \\in \\cbr{+, -}$, $\\eta^+ = \\rbr{\\eta^-}^*$ and $\\eta \\in \\cbr{\\pi, \n\\phi}$, so that\n\\begin{equation}\n\\Poibr{\\phi^{C_1}, \\pi^{C_2}} = \\delta^{C_1 C_2},\\qquad\n\\Poibr{\\phi^{C_1}, \\phi^{C_2}} = \\Poibr{\\pi^{C_1}, \\pi^{C_2}} = 0.\n\\end{equation}\n\nReal phase space\n\\begin{equation}\n\\phi^C = \\frac{1}{\\sqrt{2}}\\rbr{ \\phi_\\tR - C \\ii \\phi_\\tI},\\qquad\n\\pi^C = \\frac{1}{\\sqrt{2}}\\rbr{ \\pi_\\tR + C \\ii \\pi_\\tI}.\n%\\phi^* &= \\frac{1}{\\sqrt{2}}\\rbr{\\phi^\\tR - \\ii \\phi^\\tI},\\qquad\n%\\pi^* &&= \\frac{1}{\\sqrt{2}}\\rbr{\\pi^\\tR + \\ii \\pi^\\tI}.\n\\end{equation}\nInverse transformation\n\\begin{equation}\n\\begin{aligned}\n\\phi_\\tR &= \\frac{1}{\\sqrt{2}}\\rbr{\\phi^+ + \\phi^-},\n&\\phi_\\tI &= \\frac{\\ii}{\\sqrt{2}}\\rbr{\\phi^+ - \\phi^-}, \\\\\n\\pi_\\tR &= \\frac{1}{\\sqrt{2}}\\rbr{\\pi^- + \\pi^+},\n&\\pi_\\tI &= \\frac{\\ii}{\\sqrt{2}}\\rbr{\\pi^- - \\pi^+}. \\\\\n\\end{aligned}\n\\end{equation}\n\nOne can verify\n\\begin{equation}\nH = \\sum_{F} \\frac{1}{2} \\pi_F^2 + \\frac{\\Omega^2}{2} \\phi_F^2,\n\\end{equation}\nwhere $F \\in \\cbr{\\tR, \\tI}$, and\n\\begin{equation}\n\\Poibr{\\rfun{f}{\\eta_F}, \\rfun{g}{\\eta_F}} = \\sum_F\n\\frpa{f}{\\phi_F}\\frpa{g}{\\pi_F} - \\frpa{f}{\\pi_F}\\frpa{g}{\\phi_F},\n\\end{equation}\nso that\n\\begin{equation}\n\\Poibr{\\phi_{F_1}, \\pi_{F_2}} = \\delta_{F_1 F_2},\\qquad\n\\Poibr{\\phi_{F_1}, \\phi_{F_2}} = \\Poibr{\\pi_{F_1}, \\pi_{F_2}} = 0.\n\\end{equation}\nhold as well.\n\\end{nameddef} % Classical Hamiltonian in canonical coordinates\n\n\\begin{nameddef}{Ladder coordinates}\nLadder coordinates (ladder `numbers', later to be quantised) in complex phase\nspace\n\\begin{align}\na_\\phi^C &= \\frac{1}{\\sqrt{2}} \\rbr{\\Omega^{+\\frac{1}{2}}\\phi^{C} - C \\ii\n\\Omega^{-\\frac{1}{2}} \\pi^{-C}}, \\\\\na_\\pi^C &= \\frac{1}{\\sqrt{2}} \\rbr{\\Omega^{+\\frac{1}{2}}\\phi^{-C} - C \\ii\n\\Omega^{-\\frac{1}{2}} \\pi^{C}},\n\\end{align}\nwhere $-- = +$, $-+ = -$.\nPoisson brackets? Inverse transformation\n\\begin{equation}\n\\phi^- = \\frac{\\Omega^{-\\frac{1}{2}}}{\\sqrt{2}}\\rbr{a_\\pi^+ + a_\\phi^-},\\qquad\n\\pi^- = \\frac{\\ii\\Omega^{+\\frac{1}{2}}}{\\sqrt{2}}\\rbr{a_\\phi^+ - a_\\pi^-}.\n\\end{equation}\n\n\nLadder coordinates in real phase space\n\\begin{equation}\na_F^C = \\frac{1}{\\sqrt{2}} \\rbr{\\Omega^{+\\frac{1}{2}}\\phi_F - C \\ii\n\\Omega^{-\\frac{1}{2}} \\pi_F}.\n\\end{equation}\nPoisson brackets? Inverse transformation\n\\begin{equation}\n\\phi_F = \\frac{\\Omega^{-\\frac{1}{2}}}{\\sqrt{2}}\\rbr{a_F^+ + a_F^-},\\qquad\n\\pi_F = \\frac{\\ii\\Omega^{+\\frac{1}{2}}}{\\sqrt{2}}\\rbr{a_F^+ - a_F^-}.\n\\end{equation}\n\n\nOne can check that\n\\begin{equation}\na_\\phi^C = \\frac{1}{\\sqrt{2}}\\rbr{a_\\tR^C - C \\ii a_\\tI^C},\\qquad\na_\\pi^C = \\frac{1}{\\sqrt{2}}\\rbr{a_\\tR^C + C \\ii a_\\tI^C}.\n\\end{equation}\n%Inverse transformation\n%\\begin{equation}\n%a_\\phi^C = \\frac{1}{\\sqrt{2}}\\rbr{a_\\tR^C - C \\ii a_\\tI^C},\\qquad\n%a_\\pi^C = \\frac{1}{\\sqrt{2}}\\rbr{a_\\tR^C + C \\ii a_\\tI^C}.\n%\\end{equation}\n\n\n\\end{nameddef} % Ladder coordinates\n\n\n\n\\begin{nameddef}{Quantisation}\nQuantisation in complex canonical coordinates\n\\begin{equation}\nf \\mapsto \\what{f};\\qquad\n\\Poibr{f,g} \\mapsto \\Combr{\\what{f},\\what{g}} = \\ii \\what{\\Poibr{f,g}}.\n\\end{equation}\nAll classical equations listed above can be immediately quantised, since no \nproduct of non-commuting operators appears.\n\n%Quantum Hamiltonian in canonical coordinates\n%\\begin{align}\n%\\what{H} &= \\frac{1}{2} \\what{\\pi}^ + \\what{\\pi}^- + \n%\\frac{\\Omega^2}{2} \\what{\\phi}^+ \\what{\\phi}^-\n%\\\\\n%&= \\sum_{F} \\frac{1}{2} \\what{\\pi}_F^2 + \\frac{\\Omega^2}{2} \\what{\\phi}_F^2.\n%\\end{align}\n\nCommutators of the ladder operators\n\\begin{align}\n\\Combr{\\what{a}_{\\eta_1}^{-C_1}, \\what{a}_{\\eta_2}^{C_2}} &= \n\\delta_{\\eta_1 \\eta_2} \\delta^{C_1 C_2} \\what{1}; \\\\\n\\Combr{\\what{a}_{F_1}^{-C_1}, \\what{a}_{F_2}^{C_2}}\n&= \\delta_{F_1 F_2} \\delta^{C_1 C_2} \\what{1}. \\\\\n\\end{align}\n\nNumber operators\n\\begin{equation}\n\\what{n}_\\eta \\coloneqq \\what{a}_\\eta^+ \\what{a}_\\eta^-,\\qquad\n\\what{n}_F \\coloneqq \\what{a}_F^+ \\what{a}_F^-.\n\\end{equation}\n\n\nAngular momentum operator\n\\begin{align}\n\\what{L} &\\coloneqq\n\\what{\\phi}_\\tR\\what{\\pi}_\\tI - \\what{\\phi}_\\tI\\what{\\pi}_\\tR \\nonumber \\\\\n&= \\ii\\rbr{\\what{a}_\\tI^+\\what{a}_\\tR^- - \\what{a}_\\tR^+\\what{a}_\\tI^-}\n\\nonumber \\\\\n&= \\ii\\rbr{\\what{\\phi}^-\\what{\\pi}^- - \\what{\\phi}^+\\what{\\pi}^+}\n= \\ii\\rbr{\\what{\\pi}^-\\what{\\phi}^- - \\what{\\pi}^+\\what{\\phi}^+}\n\\nonumber \\\\\n&= \\what{n}_\\pi - \\what{n}_\\phi.\n\\label{eq:angular-momentum}\n\\end{align}\n$\\what{L} = \\what{L}^\\dagger$.\n\n\\begin{align}\n\\what{n}_\\phi &= \\frac{1}{2}\n\\rbr{\\Omega^{+\\frac{1}{2}}\\what{\\phi}^+ - \\ii\\Omega^{-\\frac{1}{2}}\\what{\\pi}^-}\n\\rbr{\\Omega^{+\\frac{1}{2}}\\what{\\phi}^- + \\ii\\Omega^{-\\frac{1}{2}}\\what{\\pi}^+}\n\\nonumber \\\\\n&= \\frac{1}{2} \\rbr{\\Omega^{+1} \\what{\\phi}^+\\what{\\phi}^- + \n\\ii\\rbr{\\what{\\phi}^+\\what{\\pi}^+ - \\what{\\pi}^-\\what{\\phi}^-}\n+ \\Omega^{-1} \\what{\\pi}^-\\what{\\pi}^+} \\nonumber \\\\\n&= \\Omega^{-1}\\what{H} - \\frac{1}{2}\\rbr{1+\\what{L}}.\n\\end{align}\nSubstituting \\eqref{eq:angular-momentum} yields the quantum Hamiltonian\n\\begin{empheq}[box=\\fbox]{equation}\n\\what{H} = \\frac{\\Omega}{2}\\rbr{\\what{n}_\\phi + \\what{n}_\\pi + 1}.\n\\end{empheq} % equation\n%Luckily,\n%\\begin{equation}\n%\\Combr{\\what{L},\\what{H}} = 0\n%\\end{equation}\n%so that\n%\\begin{equation}\n%\\Omega \\Combr{\\what{n},\\what{L}} = \\Combr{\\what{n},\\what{H}} = 0\n%\\end{equation}\n%as well.\n\n\n%\\begin{equation}\n%H = \\frac{1}{2}\\what{\\pi}^+\\what{\\pi}^- + \\frac{\\Omega^2}{2}\\phi^+\\phi^-,\n%\\end{equation}\n\\end{nameddef}\n\n\\begin{nameddef}{Wave function}\nOne may choose the \n\\end{nameddef}\n\n\n\\section{Rotating}\n\n\\section{Cohering}\n\n\\section{Single--mode squeezing}\n\n\\section{Double--mode squeezing}\n\n\\\n\n\n\n\n% Let's print the overall heading of the bibliography first:\n%\\printbibheading\n%\\printbibliography\n\n\\end{document}", "meta": {"hexsha": "1de17142e64c2b659ca15ce2f34ab0a055d36ff4", "size": 6654, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/complex-ho/main.tex", "max_stars_repo_name": "cmp0xff/Notes", "max_stars_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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": "old/complex-ho/main.tex", "max_issues_repo_name": "cmp0xff/Notes", "max_issues_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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": "old/complex-ho/main.tex", "max_forks_repo_name": "cmp0xff/Notes", "max_forks_repo_head_hexsha": "afd712c1e42275bf781a030d6c5f1b7f4c6ec57b", "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": 28.4358974359, "max_line_length": 79, "alphanum_fraction": 0.6211301473, "num_tokens": 2870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6116207567239498}}
{"text": "\n\n\\section{Monte Carlo Methods}\n\n\\subsection{Requirement}\n\n\\begin{itemize}\n\t\\item need episode, so need to terminate\n\t\\item start only when episode ends\n\t\\item do not need model\n\\end{itemize}\n\nNote: Monte Carlo Method is not a online method because it is not step-by-step method.\n\n\\subsection{Prediction}\n\n\\subsubsection{First Visit MC}\n\n\\cindex{Monte Carlo} prediction has \\cindex{first visit} and \\cindex{every visit} methods.\n\n\nThe \\cindex{first visit} Algorithm (\\ref{algo:fvmc}) is an unbiased estimate. \n\n\n\n\\begin{algorithm}\n\t\\caption{First visit MC, estimate $v_\\pi$}\\label{algo:fvmc}\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\forall s \\in \\mathcal{S}, V(s) \\gets random$\n\t\t\\State $\\text{Returns}(s) \\gets []$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State generate an episode $\\pi: S_0, A_0, R_1, S_1, A_1, R_2, \\dots, S_{T-1}, A_{T-1}, R_T$\n\t\t\t\\State $G \\gets 0$\n\t\t\t\\For{$t \\gets T-1, T-2, \\dots, 0$}\n\t\t\t\t\\State $G \\gets \\gamma G + R_{t+1}$\n\t\t\t\t\n\t\t\t\t\\Comment{loop backward to find first appearance}\n\t\t\t\t\\If{$S_t \\notin \\{S_0, S_1, \\dots, S_{t-1}\\}$}\n\t\t\t\t\t\\State $\\text{Returns}(S_t) \\gets \\text{Returns}(S_t) + G$\n\t\t\t\t\t\\State $V(S_t) \\gets \\text{average}(\\text{Returns}(S_t))$\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Explore All State-Action Pair}\n\nIn Monte Carlo control, the policy at $S_t$ need to explore all $q(S_t,A_t)$, which means the MC algorithm needs to cover all $\\langle S_t, A_t \\rangle$ pairs. There are two ways to achieve this:\n\n\\begin{itemize}\n\t\\item exploring start. It might not be possible to enumerate all start.\n\t\\item $\\varepsilon$-soft policy.\n\\end{itemize}\n\n\\subsubsection{Exploring Starts}\n\nIt tries all $\\langle S_t, A_t \\rangle$ pairs as the first action. See Algorithm (\\ref{algo:estart}) for detail.\n\nIf model is not available, $q_\\pi$ is preferred than $V_\\pi$ because it does not need transition probability when calculating optimal policy. \n\n\n\\begin{algorithm}\n\t\\caption{first visit MCES (Exploring Starts), estimate $\\pi_*$}\\label{algo:estart}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\pi(s) \\in \\mathcal{A}(s)$\n\t\t\\State $q(s,a) \\in \\mathbb{R}$\n\t\t\\State $\\text{Returns}(s,a) \\gets []$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$ and $A_0$ so all pairs will appear \\Comment{exploring starts}\n\t\t\t\\State generate episode from $\\langle S_0,A_0 \\rangle$: $\\pi: S_0, A_0, R_1,\\dots, S_{T-1}, A_{T-1}, R_T$\n\t\t\t\\State $G \\gets 0$\n\t\t\t\n\t\t\t\\For{$t \\gets T-1, T-2, \\dots, 0$}\n\t\t\t\t\\State $G \\gets \\gamma G + R_{t+1}$\n\t\t\t\t\n\t\t\t\t\\If{$\\langle S_t, A_t \\rangle \\notin \\{\\langle S_0,A_0 \\rangle,\\langle S_1,A_1 \\rangle, \\dots,\\langle S_{t-1}, A_{t-1} \\rangle \\}$}\n\t\t\t\t\t\\State $\\text{Returns}(S_t, A_t) \\gets \\text{Returns}(S_t, A_t) + G$\n\t\t\t\t\t\\State $q(S_t, A_t) \\gets \\text{average}(\\text{Returns}(S_t, A_t))$\n\t\t\t\t\t\\State $\\pi (S_t) \\gets \\underset{a \\in \\mathcal{A}(S_t)}{\\text{argmax}}\\ q(S_t, a) $\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsubsection{$\\varepsilon$-soft Policy}\n\nIn $\\varepsilon$-soft policy, all $\\langle S_t, A_t \\rangle$ pairs are tried in the middle with non-zero probability:\n\n\\begin{itemize}\n\t\\item \\cindex{$\\varepsilon$-soft} : $\\pi(a|s) >\\displaystyle \\frac{\\varepsilon}{\\mathcal{A}(s)}$.\n\t\\item \\cindex{$\\varepsilon$-greedy} : see Algorithm (\\ref{algo:fvmcsoft}) for detail.\n\\begin{equation*}\n\t\\pi(a|s) = \t\n\t\t\\begin{cases}\n\t\t\t\t\\displaystyle \\frac{\\varepsilon}{\\mathcal{A}(s)} & \\text{, if } a \\text{ is not the greedy choice} \\\\\n\t\t\t\t1 - \\varepsilon + \\displaystyle \\frac{\\varepsilon}{\\mathcal{A}(s)} & \\text{, if } a  \\text{ is the greedy choice}\n\t\t\\end{cases}\n\\end{equation*}\n\\end{itemize}\n\n\n\n\\begin{algorithm}\n\t\\caption{first visit MC control ($\\varepsilon$-greedy), estimate $\\pi_*$}\\label{algo:fvmcsoft}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $\\pi \\gets $ random $\\varepsilon$-greedy policy\n\t\t\\State $q(s,a) \\in \\mathbb{R}$\n\t\t\\State $\\text{Returns}(s,a) \\gets []$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$ and $A_0$ \\Comment{non-exploring start}\n\t\t\t\\State generate episode from $\\langle S_0,A_0 \\rangle$: $\\pi: S_0, A_0, R_1, \\dots, S_{T-1}, A_{T-1}, R_T$\n\t\t\t\\State $G \\gets 0$\n\t\t\t\n\t\t\t\\For{$t \\gets T-1, T-2, \\dots, 0$}\n\t\t\t\t\\State $G \\gets \\gamma G + R_{t+1}$\n\t\t\t\t\n\t\t\t\t\\If{$\\langle S_t, A_t \\rangle \\notin \\{\\langle S_0,A_0 \\rangle,\\langle S_1,A_1 \\rangle, \\dots,\\langle S_{t-1}, A_{t-1} \\rangle \\}$}\n\t\t\t\t\t\\State $\\text{Returns}(S_t, A_t) \\gets \\text{Returns}(S_t, A_t) + G$\n\t\t\t\t\t\\State $q(S_t, A_t) \\gets \\text{average}(\\text{Returns}(S_t, A_t))$\n\t\t\t\t\t\\State $A^* \\gets \\underset{a \\in \\mathcal{A}(S_t)}{\\text{argmax }} q(S_t, a) $\n\t\t\t\t\t\n\t\t\t\t\t\\For{$a \\in \\mathcal{A}(S_t)$}   \\Comment{$\\varepsilon$-greedy}\n\t\t\t\t\t\t\\State \\begin{equation*}\n\t\t\t\t\t\t\t\\pi(a|S_t) \\gets \\begin{cases}\n\t\t\t\t\t\t\t\t\\displaystyle 1 - \\varepsilon + \\frac{\\varepsilon}{\\mathcal{A}(s)} & \\text{,if } a = A^* \\\\\n\t\t\t\t\t\t\t\t\\displaystyle \\frac{\\varepsilon}{\\mathcal{A}(s)} & \\text{,if } a \\neq A^*\n\t\t\t\t\t\t\t\\end{cases} \n\t\t\t\t\t\t\\end{equation*}\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Off-policy prediction via Importance Sampling}\n\n\\subsubsection{Target Policy}\n\n\\begin{description}\n\t\\item[behavior policy] the policy $b$ used to generate behavior\n\t\\item[target policy] the policy $\\pi$ being learned\n\\end{description}\n\nIt has the assumption of \\cindex{coverage}: \n\\begin{equation}\n\t\\pi(a|s) > 0 \\Rightarrow b(a|s) >0\n\\end{equation}\n\n\n\\subsubsection{Importance Sampling}\n\nThe probability of $\\{ A_t, S_{t+1},A_{t+1},\\dots,S_T  \\}$ under policy $\\pi$ is (using Monte Carlo property):\n\\begin{equation}\n\t\\mathbb{P} \\{ A_t, S_{t+1},A_{t+1},\\dots,S_T | S_t, A_{t:T-1} \\sim \\pi \\} = \\prod_{k=t}^{T-1} \\pi(A_k|S_k)p(S_{k+1}|S_k,A_k)\n\\end{equation}\n\nThe \\cindex{importance-sampling ratio} is:\n\\begin{equation}\\label{importancsamplingratio}\n\t\\rho_{t:T-1}^{\\pi / b} = \\frac{\\prod\\limits_{k=t}^{T-1} \\pi(A_k|S_k)p(S_{k+1}|S_k,A_k)}{\\prod\\limits_{k=t}^{T-1} b(A_k|S_k)p(S_{k+1}|S_k,A_k)} = \\prod_{k=t}^{T-1} \\frac{\\pi(A_k|S_k)}{b(A_k|S_k)}\n\\end{equation}\n\nLet $\\mathcal{T}$ denotes the set of all timestamps that $s$ is visited, $T(t)$ is the timestamp that the episode terminate following timestamp $t$, $G_t$ is the return between timestamp $t$ and $T(t)$. There are two different importance sampling:\n\\begin{description}\n\t\\item [ordinary importance sampling] \\begin{equation}\n\t\tV(s) = \\frac{\\sum\\limits_{t \\in \\mathcal{T}} \\rho_{t:T-1}^{\\pi/b} G_t}{|\\mathcal{T}|}\n\t\\end{equation}\n\t\\item [weighted importance sampling] \\begin{equation}\n\t\tV(s) = \\frac{\\sum\\limits_{t \\in \\mathcal{T}} \\rho_{t:T-1}^{\\pi/b} G_t}{\\sum\\limits_{t \\in \\mathcal{T}} \\rho_{t:T-1}^{\\pi/b}}\n\t\\end{equation}\n\\end{description}\n\nFor \\cindex{first visit} method, \\cindex{Ordinary importance sampling} is unbiased, with unlimited variance. So \\cindex{weighted importance sampling} is preferred in practice.\n\nFor \\cindex{every visit} method, both sampling is biased which reduces to near zero when the number of sampling increases.\n\n\nIn practice, \\cindex{every visit} is preferred because it does not need to keep trace of which states have been visited.\n\n\\subsection{Incremental Policy Evaluation}\n\nIncremental implementation need the following background. If we want to estimate \n\\begin{equation}\n\tV_n = \\frac{\\sum\\limits_{k=1}^{n-1} W_k G_k}{\\sum\\limits_{k=1}^{n-1} W_k}, n \\geq 2\n\\end{equation}\n\n$V_n$ could be incrementally updated by:\n\\begin{equation}\n\tV_{n+1} = V_n + \\frac{W_n}{C_n} \\Big( G_n - V_n \\Big), n \\geq 1\n\\end{equation}\n\nwhere \n\\begin{equation*}\n\tC_{n+1} = C_n + W_{n+1}\n\\end{equation*}\n\nAlgorithm (\\ref{algo:opmcp}) implements incremental solution of weighted importance sampling:\n\n\\begin{algorithm}\n\t\\caption{off-policy MC policy evaluation, estimate $q_\\pi$}\\label{algo:opmcp}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $Q(s,a) \\in \\mathbb{R}$\n\t\t\\State $C(s,a) \\in 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State $b \\gets $ any policy with coverage of $\\pi$\n\t\t\t\\State generate episode following $b$: $S_0, A_0,R_1, \\dots, S_{T-1},A_{T-1},R_T$\n\t\t\t\\State $G \\gets 0$\n\t\t\t\\State $W \\gets 1$\n\t\t\t\\For{$t \\gets T-1, T-2, \\dots, 0$}\n\t\t\t\t\\State $G \\gets \\gamma G + R_{t+1}$\n\t\t\t\t\\State $C(S_t,A_t) \\gets C(S_t,A_t) + W$ \n\t\t\t\t\\State $\\displaystyle Q(S_t,A_t) \\gets Q(S_t,A_t) + \\frac{W}{C(S_t,A_t)} \\Big ( G - Q(S_t,A_t) \\Big)$\n\t\t\t\t\\State $\\displaystyle W \\gets W \\frac{\\pi(A_t|S_t)}{b(A_t|S_t)}$\n\t\t\t\t\n\t\t\t\t\\If{$W = 0$} \\Comment{$\\pi(A_t|S_t) = 0$}, $b$ does not cover $\\pi$\n\t\t\t\t\t\\State exit  For loop\n\t\t\t\t\\EndIf\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n\\subsection{Incremental Policy Control}\n\nThe behavior policy $b$ need to be $\\varepsilon$-soft.\n\nAlgorithm (\\ref{algo:opmcpc}) implements incremental control of weighted importance sampling:\n\n\\begin{algorithm}\n\t\\caption{off-policy MC policy control, estimate $q_*$}\\label{algo:opmcpc}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $Q(s,a) \\in \\mathbb{R}$\n\t\t\\State $C(s,a) \\in 0$\n\t\t\\State $\\pi(s) \\gets \\underset{a}{\\text{argmax}} Q(s,a)$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State $b \\gets $ any $\\varepsilon$-soft policy\n\t\t\t\\State generate episode following $b$: $S_0, A_0,R_1, \\dots, S_{T-1},A_{T-1},R_T$\n\t\t\t\\State $G \\gets 0$\n\t\t\t\\State $W \\gets 1$\n\t\t\t\\For{$t \\gets T-1, T-2, \\dots, 0$}\n\t\t\t\t\\State $G \\gets \\gamma G + R_{t+1}$\n\t\t\t\t\\State $C(S_t,A_t) \\gets C(S_t,A_t) + W$ \n\t\t\t\t\\State $\\displaystyle Q(S_t,A_t) \\gets Q(S_t,A_t) + \\frac{W}{C(S_t,A_t)} \\Big( G - Q(S_t,A_t) \\Big)$\n\t\t\t\t\\State $\\pi(S_t) \\gets \\underset{a}{\\text{argmax}}\\  Q(S_t,a)$\n\t\t\t\t\n\t\t\t\t\\If{$A_t \\neq \\pi(S_t)$}\n\t\t\t\t\t\\State exit  For loop\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\displaystyle W \\gets W \\frac{1}{b(A_t|S_t)}$ \\Comment{$\\pi(A_t|S_t) = 1$ because it is greedy}\n\t\t\t\\EndFor\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n", "meta": {"hexsha": "f40499a13b399aae9226db7ec38a8367b57bab45", "size": 9615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.4.mc.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/reinforcement_learning/rl.4.mc.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/reinforcement_learning/rl.4.mc.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": 34.3392857143, "max_line_length": 247, "alphanum_fraction": 0.6498179927, "num_tokens": 3639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6116207567239498}}
{"text": "\\section{Parametric Equations}\\label{sec:Parametric Equations}\nWhen we computed the derivative $dy/dx$ using polar coordinates, we\nused the expressions $x=f(\\theta)\\cos\\theta$ and\n$y=f(\\theta)\\sin\\theta$. These two equations completely specify the\ncurve, though the form $r=f(\\theta)$ is simpler. The expanded form has\nthe virtue that it can easily be generalized to describe a wider range\nof curves than can be specified in rectangular or polar coordinates. \n\nSuppose $f(t)$ and $g(t)$ are functions. Then the equations\n$x=f(t)$ and $y=g(t)$ describe a curve in the plane. In the case of\nthe polar coordinates equations, the variable $t$ is replaced by\n$\\theta$ which has a natural geometric interpretation. In general, $t$\nis simply an arbitrary variable, often called in this case a\n\\dfont{parameter}\\index{parameter}, and this method of specifying a curve is known as \n\\dfont{parametric equations}\\index{parametric equations}\\index{polar coordinates!parametric equations}. One\nimportant interpretation of $t$ is {\\it time}. In this interpretation,\nthe equations $x=f(t)$ and $y=g(t)$ give the position of an object at\ntime $t$.\n\n\\begin{example}{Position of a Path}{positionofapath}\n Describe the path of an object that moves so that its\nposition at time $t$ is given by $x=\\cos t$, $\\ds y=\\cos^2 t$.\n\\end{example}\n\n\\begin{solution}\nWe see immediately that $\\ds y=x^2$, so the path lies on this parabola. The path\nis not the entire parabola, however, since $x=\\cos t$ is always\nbetween $-1$ and $1$. It is now easy to see that the object oscillates\nback and forth on the parabola between the endpoints $(1,1)$ and\n$(-1,1)$, and is at point $(1,1)$ at time $t=0$.\n\\end{solution}\n\nIt is sometimes quite easy to describe a complicated path in\nparametric equations when rectangular and polar coordinate expressions\nare difficult or impossible to devise.\n\n\\begin{example}{Wheel}{wheelexample}\n A wheel of radius 1 rolls along a straight line, say the\n$x$-axis. A point on the rim of the wheel will trace out a curve, called a\ncycloid. Assume the point starts at the origin; find\nparametric equations for the curve.\n\\end{example}\n\n\\begin{solution}\nFigure~\\ref{fig:cycloid} illustrates the generation of the curve. The wheel is shown at its\nstarting point, and again after it has rolled through about 490\ndegrees. We take as our parameter $t$ the angle through which the\nwheel has turned, measured as shown clockwise from the line connecting\nthe center of the wheel to the ground. Since the radius is 1, the\ncenter of the wheel has coordinates $(t,1)$. We seek to write the\ncoordinates of the point on the rim as $(t+\\Delta x,1+\\Delta y)$,\nwhere $\\Delta x$ and $\\Delta y$ are as shown in figure~\\ref{fig:blow\n  up of wheel}. These values are nearly the sine and cosine of the\nangle $t$, from the unit circle definition of sine and\ncosine. However, some care is required because we are measuring $t$\nfrom a nonstandard starting line and in a clockwise direction, as\nopposed to the usual counterclockwise direction. A bit of thought\nreveals that $\\Delta x=-\\sin t$ and $\\Delta y=-\\cos t$. Thus the\nparametric equations for the cycloid are $x=t-\\sin t$, $y=1-\\cos t$.\n\\end{solution}\n\n%\n%\\figure[!ht]\n%\\centerline{\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\sevenpoint\n%\\setcoordinatesystem units <7truemm,7truemm>\n%\\setplotarea x from 0 to 20, y from 0  to 2.2\n%\\axis left shiftedto x=0 /\n%\\axis bottom shiftedto y=0 /\n%\\setquadratic\n%\\textRed\n%\\plot 0.000 0.000 0.001 0.018 0.009 0.070 0.030 0.156 0.069 0.271\n%0.133 0.412 0.226 0.574 0.351 0.751 0.510 0.937 0.704 1.125\n%0.934 1.309 1.197 1.482 1.491 1.637 1.813 1.771 2.157 1.876\n%2.518 1.951 2.891 1.992 3.267 1.998 3.642 1.969 4.007 1.905\n%4.358 1.809 4.687 1.685 4.991 1.536 5.265 1.368 5.506 1.187\n%5.712 1.000 5.883 0.813 6.019 0.632 6.122 0.464 6.195 0.315\n%6.243 0.191 6.269 0.095 6.281 0.031 6.283 0.002 6.284 0.008\n%6.288 0.049 6.304 0.124 6.337 0.229 6.392 0.363 6.475 0.518\n%6.589 0.691 6.736 0.875 6.919 1.063 7.137 1.249 7.389 1.426\n%7.673 1.588 7.986 1.729 8.323 1.844 8.680 1.930 9.049 1.982\n%9.425 2.000 9.801 1.982 10.170 1.930 10.526 1.844 10.863 1.729\n%11.176 1.588 11.461 1.426 11.713 1.249 11.931 1.063 12.113 0.875\n%12.261 0.691 12.375 0.518 12.457 0.363 12.513 0.229 12.545 0.124\n%12.561 0.049 12.566 0.008 12.566 0.002 12.569 0.031 12.580 0.095\n%12.607 0.191 12.654 0.315 12.727 0.464 12.830 0.632 12.966 0.813\n%13.137 1.000 13.343 1.187 13.584 1.368 13.858 1.536 14.162 1.685\n%14.492 1.809 14.842 1.905 15.208 1.969 15.582 1.998 15.959 1.992\n%16.331 1.951 16.692 1.876 17.037 1.771 17.358 1.637 17.652 1.482\n%17.916 1.309 18.145 1.125 18.340 0.937 18.499 0.751 18.623 0.574\n%18.716 0.412 18.780 0.271 18.820 0.156 18.841 0.070 18.848 0.018\n%18.850 0.000 /\n%\\textBlack\n%\\plot 8.500 0.800 8.442 0.799 8.383 0.816 8.329 0.850 8.286 0.900\n%8.258 0.962 8.248 1.033 8.259 1.105 8.291 1.174 8.343 1.233\n%8.412 1.277 8.493 1.299 8.579 1.298 8.664 1.272 8.740 1.221\n%8.800 1.150 8.839 1.061 8.851 0.963 8.835 0.863 8.791 0.769\n%8.720 0.690 8.627 0.632 8.520 0.602 8.406 0.604 8.294 0.638\n%8.195 0.704 8.116 0.797 8.066 0.910 8.049 1.036 8.068 1.164\n%8.124 1.283 /\n%\\multiput {$\\bullet$} at 0 0 7.70 1.602 /\n%\\put {$t$} [bl] <2pt,2pt> at 8.73 1.23\n%\\setlinear\n%\\plot 7.70 1.602 8.5 1 8.5 0 /\n%\\circulararc 360 degrees from 0 0 center at 0 1 \n%\\circulararc 360 degrees from 8.5 0 center at 8.5 1\n%\\endpicture}}\n%\\caption{{A cycloid.} \\label{fig:cycloid}}\n%\\endfigure\n\n\\figure[H]\n\\[\n\\includegraphics[width=4.5in]{images/7-cycloid} \n\\] \n\\caption{{A cycloid.} \\label{fig:cycloid}}\n\\endfigure\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <15truemm,15truemm>\n\\setplotarea x from -1 to 1, y from 0 to 2\n\\multiput {$\\bullet$} at -0.8 1.602 /\n%\\plot 0.000 0.800 -0.058 0.799 -0.117 0.816 -0.171 0.850 -0.214 0.900\n%-0.242 0.962 -0.252 1.033 -0.241 1.105 -0.209 1.174 -0.157 1.233\n%-0.088 1.277 -0.007 1.299 0.079 1.298 0.164 1.272 0.240 1.221\n%0.300 1.150 0.339 1.061 0.351 0.963 0.335 0.863 0.291 0.769\n%0.220 0.690 0.127 0.632 0.020 0.602 -0.094 0.604 -0.206 0.638\n%-0.305 0.704 -0.384 0.797 -0.434 0.910 -0.451 1.036 -0.432 1.164\n%-0.376 1.283 /\n\\putrule from -0.8 1.602 to -0.8 1\n\\putrule from -0.8 1 to 0 1\n\\put {$\\Delta x$} [t] <0pt,-2pt> at -0.4 1\n\\put {$\\Delta y$} [l] <2pt,0pt> at -0.8 1.2\n\\setlinear\n\\plot -0.8 1.602 0 1 0 0 /\n\\circulararc 360 degrees from 0 0 center at 0 1\n\\endpicture}}\n\\caption{{The wheel.} \\label{fig:blow up of wheel}}\n\\endfigure\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Parametric Equations}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n What curve is described by $\\ds x=t^2$, $\\ds y=t^4$? If $t$ is\ninterpreted as time, describe how the object moves on the curve.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n What curve is described by $x=3\\cos t$, $y=3\\sin t$? If $t$ is\ninterpreted as time, describe how the object moves on the curve.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n What curve is described by $x=3\\cos t$, $y=2\\sin t$? If $t$ is\ninterpreted as time, describe how the object moves on the curve.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n What curve is described by $x=3\\sin t$, $y=3\\cos t$? If $t$ is\ninterpreted as time, describe how the object moves on the curve.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Sketch the curve described by $\\ds x=t^3-t$, $\\ds y=t^2$. If $t$ is\ninterpreted as time, describe how the object moves on the curve.\n\\end{ex}\n\n%%%%%%%%%%%\n\\begin{ex}\\label{exer:pseudo cycloid}\n A wheel of radius 1 rolls along a straight line, say the\n$x$-axis. A point $P$ is located halfway between the center of the\nwheel and the rim; assume $P$ starts at the point $(0,1/2)$. As the\nwheel rolls, $P$ traces a curve; find parametric equations for the\ncurve.\n\\begin{sol}\n $\\ds x=t-{\\sin(t)\\over2}$, $\\ds t=1-{\\cos(t)\\over2}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%%\n%\\\\begin{ex}\n% A wheel of radius 1 rolls around the outside of a circle of\n%radius 3. A point $P$ on the rim of the wheel traces out a curve\n%called a \\dfont{hypercycloid}, as indicated in\n%figure~\\ref{fig:hypercycloid and hypocycloid}.  Assuming $P$\n%starts at the point $(3,0)$, find parametric equations for the curve.\n%\\begin{sol}\n% $x=4\\cos t-\\cos(4t)$,\\hfill\\break  $y=4\\sin t-\\sin(4t)$\n%\\end{sol}\n%\\end{ex}\n%\\exrdef{exer:hypercycloid}\n%\n%\\figure\n%\\vbox{\\beginpicture\n%\\normalgraphs\n%\\sevenpoint\n%\\setcoordinatesystem units <7truemm,7truemm>\n%\\setplotarea x from -5 to 5, y from -5  to 5\n%\\axis left shiftedto x=0 /\n%\\axis bottom shiftedto y=0 /\n%\\multiput {$\\bullet$} at 2.81 4.12 3 0 /\n%\\circulararc 360 degrees from 2.81 4.12 center at 2.16 3.366\n%\\circulararc 360 degrees from 0 3 center at 0 0\n%\\circulararc 360 degrees from 5 0 center at 4 0\n%\\textRed\n%\\setquadratic\n%\\plot 3.000 0.000 3.024 0.002 3.092 0.020 3.200 0.065 3.339 0.150\n%3.495 0.285 3.656 0.474 3.807 0.721 3.931 1.022 4.015 1.373\n%4.045 1.763 4.012 2.182 3.908 2.613 3.730 3.041 3.479 3.450\n%3.160 3.824 2.781 4.148 2.353 4.410 1.890 4.602 1.410 4.717\n%0.927 4.755 0.459 4.719 0.021 4.614 -0.375 4.450 -0.717 4.241\n%-1.000 4.000 -1.220 3.743 -1.378 3.487 -1.478 3.245 -1.531 3.030\n%-1.545 2.853 -1.535 2.721 -1.516 2.637 -1.501 2.600 -1.506 2.607\n%-1.542 2.648 -1.620 2.714 -1.746 2.791 -1.924 2.864 -2.152 2.918\n%-2.427 2.939 -2.740 2.914 -3.079 2.832 -3.432 2.685 -3.782 2.471\n%-4.113 2.187 -4.410 1.839 -4.658 1.434 -4.845 0.983 -4.961 0.500\n%-5.000 0.000 -4.961 -0.500 -4.845 -0.983 -4.658 -1.434 -4.410 -1.839\n%-4.113 -2.187 -3.782 -2.471 -3.432 -2.685 -3.079 -2.832 -2.740 -2.914\n%-2.427 -2.939 -2.152 -2.918 -1.924 -2.864 -1.746 -2.791 -1.620 -2.714\n%-1.542 -2.648 -1.506 -2.607 -1.501 -2.600 -1.516 -2.637 -1.535 -2.721\n%-1.545 -2.853 -1.531 -3.030 -1.478 -3.245 -1.378 -3.487 -1.220 -3.743\n%-1.000 -4.000 -0.717 -4.241 -0.375 -4.450 0.021 -4.614 0.459 -4.719\n%0.927 -4.755 1.410 -4.717 1.890 -4.602 2.353 -4.410 2.781 -4.148\n%3.160 -3.824 3.479 -3.450 3.730 -3.041 3.908 -2.613 4.012 -2.182\n%4.045 -1.763 4.015 -1.373 3.931 -1.022 3.807 -0.721 3.656 -0.474\n%3.495 -0.285 3.339 -0.150 3.200 -0.065 3.092 -0.020 3.024 -0.002\n%3.000 0.000 /\n%\\textBlack\n%\\setcoordinatesystem units <7truemm,7truemm> point at -12 0\n%\\setplotarea x from -3.5 to 3.5, y from -3.5  to 3.5\n%\\axis left shiftedto x=0 /\n%\\axis bottom shiftedto y=0 /\n%\\multiput {$\\bullet$} at 3 0 /\n%%\\circulararc 360 degrees from 2.81 4.12 center at 2.16 3.366\n%\\circulararc 360 degrees from 0 3 center at 0 0\n%\\circulararc 360 degrees from 3 0 center at 2 0\n%\\textRed\n%\\setquadratic\n%\\plot 3.000 0.000 2.985 0.000 2.942 0.003 2.870 0.009 2.771 0.021\n%2.645 0.041 2.496 0.070 2.325 0.110 2.134 0.161 1.927 0.225\n%1.706 0.301 1.474 0.390 1.234 0.492 0.989 0.606 0.744 0.731\n%0.500 0.866 0.261 1.010 0.030 1.160 -0.191 1.314 -0.399 1.471\n%-0.592 1.628 -0.769 1.781 -0.928 1.929 -1.067 2.069 -1.187 2.197\n%-1.287 2.312 -1.367 2.410 -1.427 2.490 -1.469 2.549 -1.492 2.586\n%-1.500 2.598 -1.493 2.585 -1.473 2.546 -1.443 2.481 -1.404 2.389\n%-1.358 2.270 -1.309 2.127 -1.258 1.959 -1.207 1.768 -1.158 1.557\n%-1.113 1.327 -1.074 1.081 -1.043 0.823 -1.019 0.554 -1.005 0.279\n%-1.000 0.000 -1.005 -0.279 -1.019 -0.554 -1.043 -0.823 -1.074 -1.081\n%-1.113 -1.327 -1.158 -1.557 -1.207 -1.768 -1.258 -1.959 -1.309 -2.127\n%-1.358 -2.270 -1.404 -2.389 -1.443 -2.481 -1.473 -2.546 -1.493 -2.585\n%-1.500 -2.598 -1.492 -2.586 -1.469 -2.549 -1.427 -2.490 -1.367 -2.410\n%-1.287 -2.312 -1.187 -2.197 -1.067 -2.069 -0.928 -1.929 -0.769 -1.781\n%-0.592 -1.628 -0.399 -1.471 -0.191 -1.314 0.030 -1.160 0.261 -1.010\n%0.500 -0.866 0.744 -0.731 0.989 -0.606 1.234 -0.492 1.474 -0.390\n%1.706 -0.301 1.927 -0.225 2.134 -0.161 2.325 -0.110 2.496 -0.070\n%2.645 -0.041 2.771 -0.021 2.870 -0.009 2.942 -0.003 2.985 -0.000\n%3.000 0.000 /\n%\\textBlack\n%\\endpicture}\n%\\label{fig:hypercycloid and hypocycloid}\n%\\endfigure{A hypercycloid and a hypocycloid.}\n%\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% A wheel of radius 1 rolls around the inside of \n%a circle of radius 3. A point $P$ on the rim of the wheel traces out a\n%curve called a \\dfont{hypocycloid}, as indicated in\n%figure~\\ref{fig:hypercycloid and hypocycloid}. Assuming $P$\n%starts at the point $(3,0)$, find parametric equations for the curve.\n%\\begin{sol}\n% $x=2\\cos t+\\cos(2t)$,\\hfill\\break $y=2\\sin t-\\sin(2t)$\n%\\end{sol}\n%\\end{ex}\n%\\exrdef{exer:hypocycloid}\n%\n%%%%%%%%%%%\n%\\\\begin{ex}\n% An \\dfont{involute\\index{involute}} of a circle is formed\n%as follows: Imagine that a long (that is, infinite) string is wound tightly\n%around a circle, and that you grasp the end of the string and begin to\n%unwind it, keeping the string taut. The end of the string traces out\n%the involute. Find parametric equations for this curve, using a circle\n%of radius 1, and assuming that the string unwinds counter-clockwise\n%and the end of the string is initially at $(1,0)$. \n%Figure~\\ref{fig:involute} shows part of the curve; the\n%dotted lines represent the string at a few different times.\n%\\begin{sol}\n% $x=\\cos t+t\\sin t$,\\hfill\\break  $y=\\sin t-t\\cos t$\n%\\end{sol}\n%\\end{ex}\n%\\exrdef{exer:involute of a circle}\n%\n%\\figure\n%\\vbox{\\beginpicture\n%\\normalgraphs\n%\\sevenpoint\n%\\setcoordinatesystem units <7truemm,7truemm>\n%\\setplotarea x from -5 to 2, y from -4  to 3.5\n%\\axis left shiftedto x=0 /\n%\\axis bottom shiftedto y=0 /\n%\\circulararc 360 degrees from 0 1 center at 0 0\n%\\setquadratic\n%\\textRed\n%\\plot 1.000 0.000 1.002 0.000 1.008 0.001 1.018 0.002 1.031 0.005\n%1.048 0.010 1.069 0.018 1.092 0.028 1.118 0.041 1.147 0.058\n%1.178 0.079 1.211 0.105 1.245 0.135 1.280 0.170 1.315 0.210\n%1.350 0.255 1.385 0.306 1.418 0.362 1.449 0.423 1.478 0.490\n%1.504 0.563 1.527 0.640 1.545 0.723 1.559 0.811 1.568 0.903\n%1.571 1.000 1.568 1.101 1.558 1.205 1.541 1.312 1.516 1.422\n%1.484 1.534 1.443 1.647 1.393 1.761 1.335 1.875 1.268 1.989\n%1.191 2.102 1.105 2.212 1.010 2.320 0.905 2.425 0.791 2.526\n%0.668 2.621 0.536 2.711 0.395 2.794 0.246 2.870 0.088 2.939\n%-0.077 2.998 -0.250 3.048 -0.429 3.088 -0.614 3.117 -0.805 3.135\n%-1.000 3.142 -1.199 3.135 -1.402 3.116 -1.606 3.084 -1.812 3.038\n%-2.019 2.978 -2.225 2.903 -2.430 2.815 -2.632 2.712 -2.831 2.594\n%-3.025 2.462 -3.214 2.316 -3.396 2.155 -3.570 1.981 -3.736 1.793\n%-3.892 1.592 -4.037 1.378 -4.171 1.152 -4.292 0.914 -4.399 0.666\n%-4.492 0.408 -4.570 0.141 -4.631 -0.135 -4.676 -0.417 -4.703 -0.706\n%-4.712 -1.000 -4.703 -1.298 -4.675 -1.598 -4.627 -1.901 -4.559 -2.203\n%-4.472 -2.504 -4.364 -2.803 -4.236 -3.099 -4.088 -3.389 -3.920 -3.672 /\n%%-3.733 -3.948 \n%%-3.526 -4.215 -3.300 -4.471 -3.056 -4.715 -2.794 -4.946\n%%-2.515 -5.163 -2.219 -5.363 -1.908 -5.547 -1.583 -5.713 -1.244 -5.860\n%%-0.893 -5.986 -0.531 -6.091 -0.160 -6.174 0.220 -6.234 0.607 -6.271\n%%1.000 -6.283 /\n%\\textBlack\n%\\setlinear\\setdashes <2pt>\n%\\plot 0.54 0.84 1.38 0.3 /\n%\\plot -0.65 -0.757 -3.68 1.86 /\n%\\plot -0.42 0.91 1.4 1.74 /\n%\\endpicture}\n%\\label{fig:involute}\n%\\endfigure{An involute of a circle.}\n%\n%\\end%%%%%%%%%%\n%\\\\begin{ex}\n%s\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "e2812ccbebab412f43253f9097db3d9a0f0e244f", "size": 14893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-polar-coord-parametric-eq/11-4-parametric-equations.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-4-parametric-equations.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-4-parametric-equations.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.9521126761, "max_line_length": 107, "alphanum_fraction": 0.6738736319, "num_tokens": 6694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.6115551158543979}}
{"text": "\\documentclass[a4paper, 12pt]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage[]{amsfonts}\n\\usepackage[]{graphicx}\n\n\\title{CS231A Course Notes 1: Camera Models}\n\\author{Kenji Hata and Silvio Savarese}\n\\date{}\n\n\\renewcommand\\emph{\\textbf}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\nThe camera is one of the most essential tools in computer vision. It is the mechanism by which we can record the world around us and use its output - photographs - for various applications. Therefore, one question we must ask in introductory computer vision is: how do we model a camera?\n\n\\section{Pinhole cameras}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-1.pdf}\n\\caption{A simple working camera model: the pinhole camera model.}\n\\label{fig:simpleCamera}\n\\end{figure}\nLet's design a simple camera system -- a system that can record an image of an object or scene in the 3D world. This camera system can be designed by placing a barrier with a small aperture between the 3D object and a photographic film or sensor. As Figure~\\ref{fig:simpleCamera} shows, each point on the 3D object emits multiple rays of light outwards. Without a barrier in place, every point on the film will be influenced by light rays emitted from every point on the 3D object. Due to the barrier, only one (or a few) of these rays of light passes through the aperture and hits the film. Therefore, we can establish a one-to-one mapping between points on the 3D object and the film. The result is that the film gets exposed by an ``image\" of the 3D object by means of this mapping. This simple model is known as the \\emph{pinhole camera model}.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-2.pdf}\n\\caption{A formal construction of the pinhole camera model.}\n\\label{fig:pinholeCamera}\n\\end{figure}\nA more formal construction of the pinhole camera is shown in Figure~\\ref{fig:pinholeCamera}. In this construction, the film is commonly called the \\emph{image or retinal plane}. The aperture is referred to as the \\emph{pinhole} $O$ or \\emph{center of the camera}. The distance between the image plane and the pinhole $O$ is the \\emph{focal length} $f$. Sometimes, the retinal plane is placed between $O$ and the 3D object at a distance $f$ from $O$. In this case, it is called the \\emph{virtual image} or \\emph{virtual retinal plane}. Note that the projection of the object in the image plane and the image of the object in the virtual image plane are identical up to a scale (similarity) transformation.\n\nNow, how do we use pinhole cameras? Let $P = \\begin{bmatrix}x & y & z\\end{bmatrix}^T$ be a point on some 3D object visible to the pinhole camera. $P$ will be mapped or \\textbf{projected} onto the image plane $\\Pi'$, resulting in point\\footnote{Throughout the course notes, let the prime superscript (e.g. $P'$) indicate that this point is a projected or complementary point to the non-superscript version. For example, $P'$ is the projected version of $P$.} $P' = \\begin{bmatrix}x' & y'\\end{bmatrix}^T$. Similarly, the pinhole itself can be projected onto the image plane, giving a new point $C'$. \n\nHere, we can define a coordinate system $\\begin{bmatrix}i & j & k\\end{bmatrix}$ centered at the pinhole $O$ such that the axis $k$ is perpendicular to the image plane and points toward it. This coordinate system is often known as the \\emph{camera reference system} or \\emph{camera coordinate system}. The line defined by $C'$ and $O$ is called the \\emph{optical axis} of the camera system.\n\nRecall that point $P'$ is derived from the projection of 3D point $P$ on the image plane $\\Pi'$. Therefore, if we derive the relationship between 3D point $P$ and image plane point $P'$, we can understand how the 3D world imprints itself upon the image taken by a pinhole camera. Notice that triangle $P'C'O$ is similar to the triangle formed by $P$, $O$ and $(0,0,z)$. Therefore, using the law of similar triangles we find that:\n\n\\begin{equation}\n    P' = \\begin{bmatrix}x'&y'\\end{bmatrix}^T = \\begin{bmatrix}f\\frac{x}{z} & f\\frac{y}{z}\\end{bmatrix}^T\n\\end{equation}\n\nNotice that one large assumption we make in this pinhole model is that the aperture is a single point. In most real world scenarios, however, we cannot assume the aperture can be infinitely small. Thus, what is the effect of varying aperture size? \n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-3.pdf}\n\\caption{The effects of aperture size on the image. As the aperture size decreases, the image gets sharper, but darker.}\n\\label{fig:apertureSize}\n\\end{figure}\n\nAs the aperture size increases, the number of light rays that passes through the barrier consequently increases. With more light rays passing through, then each point on the film may be affected by light rays from multiple points in 3D space, blurring the image. Although we may be inclined to try to make the aperture as small as possible, recall that a smaller aperture size causes less light rays to pass through, resulting in crisper but darker images. Therefore, we arrive at the fundamental problem presented by the pinhole formulation: can we develop cameras that take crisp and bright images?\n\n\\section{Cameras and lenses}\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-4.pdf}\n\\caption{A setup of a simple lens model. Notice how the rays of the top point on the tree converge nicely on the film. However, a point at a different distance away from the lens results in rays not converging perfectly on the film.}\n\\label{fig:lens}\n\\end{figure}\n\nIn modern cameras, the above conflict between crispness and brightness is mitigated by using \\emph{lenses}, devices that can focus or disperse light. If we replace the pinhole with a lens that is both properly placed and sized, then it satisfies the following property: all rays of light that are emitted by some point $P$ are refracted by the lens such that they converge to a single point $P'$ in the image plane. Therefore, the problem of the majority of the light rays blocked due to a small aperture is removed (Figure~\\ref{fig:lens}). However, please note that this property does not hold for all 3D points, but only for some specific point $P$. Take another point $Q$ which is closer or further from the image plane than $P$. The corresponding projection into the image will be blurred or out of focus. Thus, lenses have a specific distance for which objects are ``in focus\". This property is also related to a photography and computer graphics concept known as depth of field, which is the effective range at which cameras can take clear photos.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-5.pdf}\n\\caption{Lenses focus light rays parallel to the optical axis into the focal point. Furthermore, this setup illustrates the paraxial refraction model, which helps us find the relationship between points in the image plane and the 3D world in cameras with lenses.}\n\\label{fig:paraxial}\n\\end{figure}\n\nCamera lenses have another interesting property: they focus all light rays traveling parallel to the optical axis to one point known as the \\emph{focal point} (Figure~\\ref{fig:paraxial}). The distance between the focal point and the center of the lens is commonly referred to as the \\emph{focal length} $f$. Furthermore, light rays passing through the center of the lens are not deviated. We thus can arrive at a similar construction to the pinhole model that relates a point $P$ in 3D space with its corresponding point $P'$ in the image plane. \n\n\\begin{equation}\n    P' = \\begin{bmatrix}x'\\\\ y'\\end{bmatrix} = \\begin{bmatrix}z'\\frac{x}{z} \\\\ z'\\frac{y}{z}\\end{bmatrix}\n\\end{equation}\n\nThe derivation for this model is outside the scope of the class. However, please notice that in the pinhole model $z' = f$, while in this lens-based model, $z' = f+z_0$.  Additionally, since this derivation takes advantage of the paraxial or ``thin lens\" assumption\\footnote{For the angle $\\theta$ that incoming light rays make with the optical axis of the lens, the paraxial assumption substitutes $\\theta$ for any place $\\sin(\\theta)$ is used. This approximation of $\\theta$ for $\\sin\\theta$ holds as $\\theta$ approaches 0.}, it is called the \\textbf{paraxial refraction model}.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-6.pdf}\n\\caption{Demonstrating how pincushion and barrel distortions affect images.}\n\\label{fig:distortion}\n\\end{figure}\n\nBecause the paraxial refraction model approximates using the thin lens assumption, a number of aberrations can occur. The most common one is referred to as \\emph{radial distortion}, which causes the image magnification to decrease or increase as a function of the distance to the optical axis. We classify the radial distortion as \\emph{pincushion distortion} when the magnification increases and \\emph{barrel distortion}\\footnote{Barrel distortion typically occurs when one uses fish-eye lenses.} when the magnification decreases. Radial distortion is caused by the fact that different portions of the lens have differing focal lengths.\n\n\\section{Going to digital image space}\nIn this section, we will discuss the details of the parameters we must account for when modeling the projection from 3D space to the digital images we know. All the results derived will use the pinhole model, but they also hold for the paraxial refraction model.\n\nAs discussed earlier, a point $P$ in 3D space can be mapped (or projected) into a 2D point $P'$ in the image plane $\\Pi'$. This $\\mathbb{R}^3 \\rightarrow \\mathbb{R}^2$ mapping is referred to as a \\emph{projective transformation}. This projection of 3D points into the image plane does not directly correspond to what we see in actual digital images for several reasons. First, points in the digital images are, in general, in a different reference system than those in the image plane. Second, digital images are divided into discrete pixels, whereas points in the image plane are continuous. Finally, the physical sensors can introduce non-linearity such as distortion to the mapping. To account for these differences, we will introduce a number of additional transformations that allow us to map any point from the 3D world to pixel coordinates.\n\n\\subsection{The Camera Matrix Model and Homogeneous Coordinates}\n\n\\subsubsection{Introduction to the Camera Matrix Model}\nThe camera matrix model describes a set of important parameters that affect how a world point $P$ is mapped to image coordinates $P'$. As the name suggests, these parameters will be represented in matrix form. First, let's introduce some of those parameters.\n\nThe first parameters, $c_x$ and $c_y$, describe how image plane and digital image coordinates can differ by a translation. Image plane coordinates have their origin $C'$ at the image center where the $k$ axis intersects the image plane. On the other hand, digital image coordinates typically have their origin at the lower-left corner of the image. Thus, 2D points in the image plane and 2D points in the image are offset by a translation vector $\\begin{bmatrix}c_x, c_y\\end{bmatrix}^T$. To accommodate this change of coordinate systems, the mapping now becomes:\n\n\\begin{equation}\n    P' = \\begin{bmatrix}x'\\\\y'\\end{bmatrix} = \\begin{bmatrix}f\\frac{x}{z}+c_x \\\\ f\\frac{y}{z}+c_y\\end{bmatrix}\n\\end{equation}\n\nThe second effect we must account for that the points in digital images are expressed in pixels, while points in image plane are represented in physical measurements (e.g. centimeters). In order to accommodate this change of units, we must introduce two new parameters $k$ and $l$. These parameters, whose units would be something like $\\frac{\\mathrm{pixels}}{\\mathrm{cm}}$, correspond to the change of units in the two axes of the image plane. Note that $k$ and $l$ may be different because the aspect ratio of a pixel is not guaranteed to be one. If $k=l$, we often say that the camera has \\emph{square pixels}. We adjust our previous mapping to be\n\n\\begin{equation}\n    P' = \\begin{bmatrix}x'\\\\y'\\end{bmatrix} = \\begin{bmatrix}fk\\frac{x}{z}+c_x \\\\ fl\\frac{y}{z}+c_y\\end{bmatrix} = \\begin{bmatrix}\\alpha\\frac{x}{z}+c_x \\\\ \\beta\\frac{y}{z}+c_y\\end{bmatrix}\n    \\label{eq:finalImage}\n\\end{equation}\n\nIs there a better way to represent this projection from $P\\rightarrow P'$? If this projection is a linear transformation, then it can be represented as a product of a matrix and the input vector (in this case, it would be $P$. However, from Equation~\\ref{eq:finalImage}, we see that this projection $P\\rightarrow P'$ is not linear, as the operation divides one of the input parameters (namely $z$). Still, representing this projection as a matrix-vector product would be useful for future derivations. Therefore, can we represent our transformation as a matrix-vector product despite its nonlinearity? Homogeneous coordinates are the solution.\n\n\\subsubsection{Homogeneous Coordinates}\n\nOne way to solve this problem is to change the coordinate systems. For example, we introduce a new coordinate, such that any point $P' =(x',y')$ becomes $(x',y',1)$. Similarly, any point $P =(x,y,z)$ becomes $(x,y,z,1)$. This augmented space is referred to as the \\emph{homogeneous coordinate system}. As demonstrated previously, to convert a Euclidean vector $(v_1,...,v_n)$ to homogeneous coordinates, we simply append a 1 in a new dimension to get $(v_1,...,v_n,1)$. Note that the equality between a vector and its homogeneous coordinates only occurs when the final coordinate equals one. Therefore, when converting back from arbitrary homogeneous coordinates $(v_1,  ... , v_n , w)$, we get Euclidean coordinates $(\\frac{v_1}{w},...,\\frac{v_n}{w})$. Using homogeneous coordinates, we can formulate\n\\begin{equation}\n    P_h' = \\begin{bmatrix}\\alpha x + c_xz\\\\\\beta y + c_yz \\\\ z\\end{bmatrix} = \n    \\begin{bmatrix}\n    \\alpha & 0 & c_x & 0\\\\\n    0 & \\beta & c_y & 0 \\\\ \n    0 & 0 & 1 & 0\n    \\end{bmatrix}\n    \\begin{bmatrix}x\\\\y\\\\z\\\\1\\end{bmatrix} =     \\begin{bmatrix}\n    \\alpha & 0 & c_x & 0\\\\\n    0 & \\beta & c_y & 0 \\\\ \n    0 & 0 & 1 & 0\n    \\end{bmatrix} P_h\n    \\label{eq:homogeneous}\n\\end{equation}\n\nFrom this point on, assume that we will work in homogeneous coordinates, unless stated otherwise. We will drop the $h$ index, so any point $P$ or $P'$ can be assumed to be in homogeneous coordinates. As seen from Equation~\\ref{eq:homogeneous}, we can represent the relationship between a point in 3D space and its image coordinates by a matrix vector relationship:\n\\begin{equation}\n    P' = \\begin{bmatrix}x'\\\\y'\\\\ z\\end{bmatrix}=\\begin{bmatrix}\n    \\alpha & 0 & c_x & 0\\\\\n    0 & \\beta & c_y & 0 \\\\ \n    0 & 0 & 1 & 0\n    \\end{bmatrix}\\begin{bmatrix}x\\\\y\\\\z\\\\1\\end{bmatrix}=\n    \\begin{bmatrix}\n    \\alpha & 0 & c_x & 0\\\\\n    0 & \\beta & c_y & 0 \\\\ \n    0 & 0 & 1 & 0\n    \\end{bmatrix}P = MP \n    \\label{eq:canonical}\n    % = K\\begin{bmatrix} I&0\\end{bmatrix}P\n\\end{equation}\nWe can decompose this transformation a bit further into \n\\begin{equation}\nP' = MP = \\begin{bmatrix}\n    \\alpha & 0 & c_x \\\\\n    0 & \\beta & c_y  \\\\ \n    0 & 0 & 1 \n    \\end{bmatrix}\\begin{bmatrix}I & 0\\end{bmatrix}P = K\\begin{bmatrix}I & 0\\end{bmatrix}P\n    \\label{eq:decomposedHomogenousTransform}\n\\end{equation}\n\nThe matrix $K$ is often referred to as the \\emph{camera matrix}. \n\n\\subsubsection{The Complete Camera Matrix Model}\n\nThe camera matrix $K$ contains some of the critical parameters that describes a camera's characteristics and its model, including the $c_x, c_y, k,$ and $l$ parameters as discussed above. Two parameters are currently missing this formulation: \\emph{skewness} and \\emph{distortion}. We often say that an image is skewed when the camera coordinate system is skewed, meaning that the angle between the two axes is slightly larger or smaller than 90 degrees. Most cameras have zero-skew, but some degree of skewness may occur because of sensor manufacturing errors. Deriving the new camera matrix accounting for skewness is outside the scope of this class and we give it to you below:\n\\begin{equation}\nK = \\begin{bmatrix}x'\\\\y'\\\\ z\\end{bmatrix}=\\begin{bmatrix}\n    \\alpha & -\\alpha\\cot\\theta & c_x \\\\\n    0 & \\frac{\\beta}{\\sin\\theta} & c_y  \\\\ \n    0 & 0 & 1 \n    \\end{bmatrix}\n\\end{equation}\nMost methods that we introduce in this class ignore distortion effects, therefore our class camera matrix $K$ has 5 degrees of freedom: 2 for focal length, 2 for offset, and 1 for skewness. These parameters are collectively known as the \\emph{intrinsic parameters}, as they are unique and inherent to a given camera and relate to essential properties of the camera, such as its manufacturing.\n\n\\subsection{Extrinsic Parameters}\n\nSo far, we have described a mapping between a point $P$ in the 3D camera reference system to a point $P'$ in the 2D image plane using the intrinsic parameters of a camera described in matrix form. But what if the information about the 3D world is available in a different coordinate system? Then, we need to include an additional transformation that relates points from the world reference system to the camera reference system. This transformation is captured by a rotation matrix $R$ and translation vector $T$. Therefore, given a point in a world reference system $P_w$, we can compute its camera coordinates as follows:\n\\begin{equation}\nP = \\begin{bmatrix}R&T\\\\0&1\\end{bmatrix} P_w\n\\end{equation}\nSubstituting this in equation (\\ref{eq:decomposedHomogenousTransform}) and simplifying gives\n\\begin{equation}\nP' = K\\begin{bmatrix}R&T\\end{bmatrix}P_w = MP_w\n\\label{eq:cameramatrix}\n\\end{equation}\n\nThese parameters $R$ and $T$ are known as the \\emph{extrinsic parameters} because they are external to and do not depend on the camera.\n\n\\vspace{12pt}\n\nThis completes the mapping from a 3D point $P$ in an arbitrary world reference system to the image plane. To reiterate, we see that the full projection matrix $M$ consists of the two types of parameters introduced above: \\emph{intrinsic} and \\emph{extrinsic} parameters. All parameters contained in the camera matrix $K$ are the intrinsic parameters, which change as the type of camera changes. The extrinsic paramters include the rotation and translation, which do not depend on the camera's build. Overall, we find that the $3\\times4$ projection matrix $M$ has 11 degrees of freedom: 5 from the intrinsic camera matrix, 3 from extrinsic rotation, and 3 from extrinsic translation.\n\n\\section{Camera Calibration}\nTo precisely know the transformation from the real, 3D world into digital images requires prior knowledge of many of the camera's intrinsic parameters. If given an arbitrary camera, we may or may not have access to these parameters. We do, however, have access to the images the camera takes. Therefore, can we find a way to deduce them from images? This problem of estimating the extrinsic and intrinsic camera parameters is known as \\emph{camera calibration}.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/1-7.pdf}\n\\caption{The setup of an example calibration rig.}\n\\label{fig:calibration}\n\\end{figure}\n\nSpecifically, we do this by solving for the intrinsic camera matrix $K$ and the extrinsic parameters $R,T$ from Equation~\\ref{eq:cameramatrix}. We can describe this problem in the context of a calibration rig, such as the one show in Figure~\\ref{fig:calibration}. The rig usually consists of a simple pattern (i.e. checkerboard) with known dimensions. Furthermore, the rig defines our world reference frame with origin $O_w$ and axes $i_w, j_w, k_w$. From the rig's known pattern, we have known points in the world reference frame $P_1,...,P_n$. Finding these points in the image we take from the camera gives corresponding points in the image $p_1,...,p_n$. \n\nWe set up a linear system of equations from $n$ correspondences such that for each correspondence $P_i, p_i$ and camera matrix $M$ whose rows are $m_1, m_2, m_3$:\n\\begin{equation}\np_i = \\begin{bmatrix}u_i\\\\v_i\\end{bmatrix} = MP_i = \\begin{bmatrix}\\frac{m_1 P_i}{m_3P_i}\\\\\\frac{m_2 P_i}{m_3P_i}\\end{bmatrix}\n\\end{equation}\n\nAs we see from the above equation, each correspondence gives us two equations and, consequently, two constraints for solving the unknown parameters contained in $m$. From before, we know that the camera matrix has $11$ unknown parameters. This means that we need at least $6$ correspondences to solve this. However, in the real world, we often use more, as our measurements are often noisy. To explicitly see this, we can derive a pair of equations that relate $u_i$ and $v_i$ with $P_i$. \n\\begin{align*}\nu_i(m_3P_i) - m_1P_i = 0\\\\\nv_i(m_3P_i) - m_2P_i = 0\n\\end{align*}\n\nGiven $n$ of these corresponding points, the entire linear system of equations becomes\n\\begin{align*}\nu_1(m_3P_1) -& m_1P_1 = 0\\\\\nv_1(m_3P_1) -& m_2P_1 = 0\\\\\n&\\vdots\\\\\nu_n(m_3P_n) -& m_1P_n = 0\\\\\nv_n(m_3P_n) -& m_2P_n = 0\\\\\n\\end{align*}\n\nThis can be formatted as a matrix-vector product shown below:\n\\begin{equation}\n\\begin{bmatrix} \nP_1^T & 0^T & -u_1P_1^T \\\\\n0^T & P_1^T & -v_1P_1^T \\\\\n& \\vdots &\\\\\nP_n^T & 0^T & -u_nP_n^T \\\\\n0^T & P_n^T & -v_nP_n^T \n\\end{bmatrix}\n\\begin{bmatrix}\nm_1^T \\\\ m_2^T \\\\m_3^T\n\\end{bmatrix} = \\mathbf{P}m = 0\n\\label{eq:linearsystem}\n\\end{equation}\n\nWhen $2n > 11$, our homogeneous linear system is overdetermined. For such a system $m=0$ is always a trivial solution. Furthemore, even if there were some other $m$ that were a nonzero solution, then $\\forall k\\in \\mathbb{R},km$ is also a solution. Therefore, to constrain our solution, we complete the following minimization:\n\\begin{equation}\n\\begin{aligned}\n    & \\underset{m}{\\text{minimize}}\n    & & \\|\\mathbf{P}m\\|^2 \\\\\n    & \\text{subject to}\n    & & \\|m\\|^2 = 1\n\\end{aligned}\n\\end{equation}\nTo solve this minimization problem, we simply use singular value decomposition. If we let $P = UDV^T$, then the solution to the above minimization is to set $m$ equal to the last column of $V$. The derivation for this solution is outside the scope of this class and you may refer to Section 5.3 of Hartley \\& Zisserman on pages 592-593 for more details.\n\nAfter reformatting the vector $m$ into the matrix $M$, we now want to explicitly solve for the extrinsic and intrinsic parameters. We know our SVD-solved $M$ is known up to scale, which means that the true values of the camera matrix are some scalar multiple of $M$:\n\\begin{equation}\n\\rho M = \\begin{bmatrix}\n\\alpha r_1^T - \\alpha\\cot \\theta r_2^T + c_xr_3^T & \\alpha t_x - \\alpha \\cot \\theta t_y + c_x t_z \\\\\n\\frac{\\beta}{\\sin\\theta}r_2^T + c_yr_3^T & \\frac{\\beta}{\\sin\\theta}t_y + c_yt_z \\\\ r_3^T & t_z\n\\end{bmatrix}\n\\end{equation}\n\nHere, $r_1^T$, $r_2^T$, and $r_3^T$ are the three rows of $R$. Dividing by the scaling parameter gives\n\\[M = \\frac{1}{\\rho}\\begin{bmatrix}\n\\alpha r_1^T - \\alpha\\cot \\theta r_2^T + c_xr_3^T & \\alpha t_x - \\alpha \\cot \\theta t_y + c_x t_z \\\\\n\\frac{\\beta}{\\sin\\theta}r_2^T + c_yr_3^T & \\frac{\\beta}{\\sin\\theta}t_y + c_yt_z \\\\ r_3^T & t_z\n\\end{bmatrix} = \\begin{bmatrix}A & b\\end{bmatrix} =\\begin{bmatrix}\na_1^T \\\\ a_2^T \\\\ a_3^T\n\\end{bmatrix} \\begin{bmatrix}\nb_1\\\\b_2\\\\b_3\n\\end{bmatrix}\n\\]\n\nSolving for the intrinsics gives \n\\begin{equation}\\begin{aligned}\n    \\rho &= \\pm \\frac{1}{\\|a_3\\|}\\\\\n    c_x &= \\rho^2(a_1\\cdot a_3)\\\\\n    c_y &=\\rho^2(a_2\\cdot a_3)\\\\\n    \\theta &= \\cos ^{-1} \\left(-\\frac{(a_1 \\times a_3)\\cdot(a_2\\times a_3)}{\\|a_1\\times a_3\\|\\cdot\\|a_2\\times a_3\\|}\\right)\\\\\n    \\alpha &= \\rho^2 \\|a_1 \\times a_3\\| \\sin \\theta\\\\\n    \\beta &= \\rho^2 \\|a_2 \\times a_3\\| \\sin \\theta\n\\end{aligned}\\end{equation}\n\nThe extrinsics are \n\\begin{equation}\\begin{aligned}\n    r_1 &= \\frac{a_2\\times a_3}{\\|a_2\\times a_3\\|}\\\\\n    r_2 &= r_3\\times r_1\\\\\n    r_3 &= \\rho a_3\\\\\n    T &= \\rho K^{-1} b\n\\end{aligned}\\end{equation}\nWe leave the derivations as a class exercise or you can refer to Section 5.3.1 of the Forsyth \\& Ponce textbook.\n\nWith the calibration procedure complete, we warn against degenerate cases. Not all sets of $n$ correspondences will work. For example, if the points $P_i$ lie on the same plane, then the system will not be able to be solved. These unsolvable configurations of points are known as \\emph{degenerate configurations}. More generally, degenerate configurations have points that lie on the intersection curve of two quadric surfaces. Although this outside the scope of the class, you can find more information in Section 1.3 of the Forsyth \\& Ponce textbook. \n\n\\section{Handling Distortion in Camera Calibration}\nSo far, we have been working with ideal lenses which are free from any distortion. However, as seen before, real lenses can deviate from rectilinear projection, which require more advanced methods. This section provides just a brief introduction to handling distortions. \n\nOften, distortions are radially symmetric because of the physical symmetry of the lens. We model the radial distortion with an isotropic transformation:\n\\begin{equation}\n    QP_i = \\begin{bmatrix}\n    \\frac{1}{\\lambda}&0&0\\\\0 &    \\frac{1}{\\lambda} & 0 \\\\ 0 & 0 &1\\end{bmatrix} M P_i = \\begin{bmatrix}\n    u_i\\\\v_i\\end{bmatrix}\n    = p_i\n\\end{equation}\nIf we try to rewrite this into a system of equations as before, we get \n\n\\begin{align*}\n    u_iq_3P_i  = q_1P_i\\\\\n    v_iq_3P_i  = q_2P_i\n\\end{align*}\n\nThis system, however, is no longer linear, and we require the use of nonlinear optimization techniques, which are covered in Section 22.2 of Forsyth \\& Ponce. We can simplify the nonlinear optimization of the calibration problem if we make certain assumptions. In radial distortion, we note that the ratio between two coordinates $u_i$ and $v_i$ is not affected. We can compute this ratio as\n\\begin{equation}\n    \\frac{u_i}{v_i} = \\frac{\\frac{m_1P_i}{m_3P_i}}{\\frac{m_2P_i}{m_3P_i}} = \\frac{m_1P_i}{m_2P_i}\n\\end{equation}\n\nAssuming that $n$ correspondences are available, we can set up the system of linear equations:\n\\begin{align*}\n    v_1(m_1P_1)-&u_1(m_2P_1) = 0\\\\\n    &\\vdots\\\\\n    v_n(m_1P_n)-&u_n(m_2P_n) = 0\n\\end{align*}\nSimilar to before, this gives a matrix-vector product that we can solve via SVD:\n\\begin{equation}\n    Ln = \\begin{bmatrix}\n    v_1P_1^T & -u_1P_1^T\\\\\n    \\vdots & \\vdots\\\\\n    v_nP_n^T & -u_nP_n^T\\\\ \n    \\end{bmatrix}\n    \\begin{bmatrix}\n    m_1^T\\\\m_2^T\n    \\end{bmatrix}\n\\end{equation}\n\nOnce $m_1$ and $m_2$ are estimated, $m_3$ can be expressed as a nonlinear function of $m_1,m_2,$ and $\\lambda$. This requires to solve a nonlinear optimization problem whose complexity is much simpler than the original one.\n\n\\section{Appendix A: Rigid Transformations}\nThe basic rigid transformations are rotation, translation, and scaling. This appendix will cover them for the 3D case, as they are common type in this class. \n\nRotating a point in 3D space can be represented by rotating around each of the three coordinate axes respectively. When rotating around the coordinate axes, common convention is to rotate in a counter-clockwise direction. One intuitive way to think of rotations is how much we rotate around each degree of freedom, which is often referred to as \\emph{Euler angles}. However, this methodology can result in what is known as \\emph{singularities}, or \\emph{gimbal lock}, in which certain configurations result in a loss of a degree of freedom for the rotation. \n\nOne way to prevent this is to use rotation matrices, which are a more general form of representing rotations. Rotation matrices are square, orthogonal matrices with determinant one. Given a rotation matrix $R$ and a vector $v$, we can compute the resulting vector $v'$ as\n\\[v' = Rv\\]\n\nSince rotation matrices are a very general representation of matrices, we can represent a rotation $\\alpha, \\beta, \\gamma$ around each of the respective axes as follows:\n\\[R_x(\\alpha) = \\begin{bmatrix}1 & 0 & 0\\\\ 0 &\\cos\\alpha &-\\sin\\alpha \\\\ 0 &\\sin\\alpha &\\cos\\alpha \\end{bmatrix}\\]\n\\[R_y(\\beta) = \\begin{bmatrix}\\cos\\beta & 0 & \\sin\\beta \\\\ 0 & 1 & 0 \\\\ -\\sin\\beta & 0 &\\cos\\beta \\end{bmatrix}\\]\n\\[R_z(\\gamma) = \\begin{bmatrix}\\cos \\gamma & -\\sin\\gamma &0 \\\\ \\sin\\gamma &\\cos\\gamma & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}\\]\n\nDue to the convention of matrix multiplication, the rotation achieved by first rotating around the z-axis, then y-axis, then x-axis is given by the matrix product $R_xR_yR_z$.\n\nTranslations, or displacements, are used to describe the movement in a certain direction. In 3D space, we define a translation vector $t$ with 3 values: the displacements in each of the 3 axes, often denoted as $t_x, t_y, t_z$. Thus, given some point $P$ which is translated to some other point $P'$ by $t$, we can write it as:\n\\[ P' = P + t = \\begin{bmatrix}P_x\\\\P_y\\\\P_z\\end{bmatrix} + \\begin{bmatrix}t_x\\\\t_y\\\\t_z\\end{bmatrix}\\]\n\nIn matrix form, translations can be written using homogeneous coordinates. If we construct a translation matrix as\n\\[ T = \\begin{bmatrix}\n1 & 0 & 0 & t_x \\\\0 & 1 & 0 & t_y \\\\0 & 0 & 1 & t_z \\\\ 0 & 0 & 0 & 1\n\\end{bmatrix}\\]\nthen we see that $P'=TP$ is equivalent to $P' = P+t$.\n\n\nIf we want to combine translation with our rotation matrix multiplication, we can again use homogeneous coordinates to our advantage. If we want to rotate a vector $v$ by $R$ and then translate it by $t$, we can write the resulting vector $v'$ as:\n\\[ \\begin{bmatrix}v'\\\\1\\end{bmatrix} = \\begin{bmatrix}\nR & t \\\\ 0 & 1\n\\end{bmatrix}\\begin{bmatrix}\nv \\\\ 1\n\\end{bmatrix}\\]\n\nFinally, if we want to scale the vector in certain directions by some amount $S_x, S_y, S_z$, we can construct a scaling matrix \n\\[S = \\begin{bmatrix}\nS_x & 0 & 0 \\\\ 0 & S_y & 0 \\\\ 0 & 0 & S_z\n\\end{bmatrix}\\]\n\nTherefore, if we want to scale a vector, then rotate, then translate, our final transformation matrix would be:\n\\[T = \\begin{bmatrix}\nRS & t \\\\ 0 & 1\n\\end{bmatrix}\\]\n\nNote that all of these types of transformations would be examples of affine transformations. Recall that projective transformations occur when the final row of $T$ is not $\\begin{bmatrix}\n0 & 0 &0 &1\n\\end{bmatrix}$.\n\n\\section{Appendix B: Different Camera Models}\nWe will now describe a simple model known as the \\emph{weak perspective model}. In the weak perspective model, points are first projected to the reference plane using orthogonal projection and then projected to the image plane using a projective transformation.\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/weak_perspective.png}\n\\caption{The weak perspective model: orthogonal projection onto reference plane}\n\\label{fig:weak_perspective}\n\\end{figure}\n\nAs Figure~\\ref{fig:weak_perspective} shows, given a reference plane $\\Pi$ at a distance $z_o$ from the center of the camera, the points $P,Q,R$ are first projected to the plane $\\Pi$ using an orthogonal projection, generating points $P\\_, Q\\_, R\\_$.  This is a reasonable approximation when deviations in depth from the plane are small compared to the distance of the camera. \n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/weak_perspective2.png}\n\\caption{The weak perspective model: projection onto the image plane}\n\\label{fig:weak_perspective2}\n\\end{figure}\n\nFigure~\\ref{fig:weak_perspective2} illustrates how points $P\\_, Q\\_, R\\_$ are then projected to the image plane using a regular projective transformation to produce the points $p', q', r'$. Notice, however, that because we have approximated the depth of each point to $z_o$ the projection has been reduced to a simple, constant magnification. The magnification is equal to the focal length $f'$ divided by $z_o$, leading to\n\\begin{align*}\nx'=\\frac{f'}{z_0}x\\ \\ \\ \\ \\ \ny'=\\frac{f'}{z_0}y\n\\end{align*}\nThis model also simplifies the projection matrix\n\\[M = \\begin{bmatrix}\nA & b \\\\ 0 & 1\n\\end{bmatrix}\\]\nAs we see, the last row of $M$ is $\\begin{bmatrix}\n0 & 0& 0 &1\n\\end{bmatrix}$ in the weak perspective model, compared to $\\begin{bmatrix}\nv&1\n\\end{bmatrix}$ in the normal camera model. We do not prove this result and leave it to you as an exercise. The simplification is clearly demonstrated when mapping the 3D points to the image plane. \n\\begin{equation}\n    P' = MP = \\begin{bmatrix}\n    m_1 \\\\ m_2 \\\\ m_3\n    \\end{bmatrix}P = \\begin{bmatrix}\n    m_1P \\\\ m_2P \\\\ 1\n    \\end{bmatrix}\n\\end{equation}\nThus, we see that the image plane point ultimately becomes a magnification of the original 3D point, irrespective of depth. The nonlinearity of the projective transformation disappears, making the weak perspective transformation a mere magnifier.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/orthographic.png}\n\\caption{The orthographic projection model}\n\\label{fig:orthographic}\n\\end{figure}\n\n\nFurther simplification leads to the \\emph{orthographic (or affine) projection model}. In this case, the optical center is located at infinity. The projection rays are now perpendicular to the retinal plane. As a result, this model ignores depth altogether.  Therefore,\n\\begin{align*}\n    x' = x\\\\\n    y' = y\n\\end{align*}\nOrthographic projection models are often used for architecture and industrial design.\n\nOverall, weak perspective models result in much simpler math, at the cost of being somewhat imprecise. However, it often yields results that are very accurate when the object is small and distant from the camera. \n\\end{document}\n", "meta": {"hexsha": "7e8e6b433bbe6e07c30c3662e2b8ec306c48900c", "size": 33203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01-camera-models/01-camera-models.tex", "max_stars_repo_name": "zishanqin/cs231a-notes", "max_stars_repo_head_hexsha": "b864cfb7c472573ec1fb7da780748348fc320dab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 287, "max_stars_repo_stars_event_min_datetime": "2017-04-03T00:30:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T03:52:04.000Z", "max_issues_repo_path": "01-camera-models/01-camera-models.tex", "max_issues_repo_name": "zishanqin/cs231a-notes", "max_issues_repo_head_hexsha": "b864cfb7c472573ec1fb7da780748348fc320dab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-06-26T11:23:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-16T09:00:43.000Z", "max_forks_repo_path": "01-camera-models/01-camera-models.tex", "max_forks_repo_name": "zishanqin/cs231a-notes", "max_forks_repo_head_hexsha": "b864cfb7c472573ec1fb7da780748348fc320dab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 112, "max_forks_repo_forks_event_min_datetime": "2017-04-09T10:44:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T09:19:59.000Z", "avg_line_length": 75.9794050343, "max_line_length": 1053, "alphanum_fraction": 0.746287986, "num_tokens": 9376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6113153461612739}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath,amssymb,siunitx,cancel}\n\n\\def\\mhe{m_{\\mathrm{He}}}\n\n\\title{Interstellar Propulsion}\n\\author{Matthias Raives}\n\\date{\\today}\n\\begin{document}\n \n  \\maketitle\n  \n  \\section{Bussard Ramjet}\n    This can be derived multiple ways both relativistic and non-relativistic.  The terminal velocity is large enough that the relativistic derivation is preferred, but the non-relativistic answers are correct to an order-of-magnitude level (within a factor of 3).  Three derivations that I have found are presented here.\n    \n    \\subsection{Relativistic Monentum Conservation}\n      The spacecraft generates thrust from the proton-proton chain:\n      \\begin{equation}\n          6\\mathrm{p} \\rightarrow \\mathrm{He}^{4} + 2\\mathrm{p} + \\nu_{e} + \\Delta E\n      \\end{equation}\n      Since our reactor is perfectly efficient, we'll assume that all the $\\Delta E$ goes into launching the neutrino (which we'll assume is negligible) and helium nucleus out of the spaceship for propulsion, and that we capture the two extra protons produced (so that, in the steady state, we only need to capture 4 protons per reaction).\n      \n      At terminal velocity, the momentum of the ejected helium nuclei is equal to the total momentum of the protons we're collecting.  The momentum of the protons is:\n      \\begin{equation}\n          p_{1} = \\sum p_{p} = 4\\gamma m_{p}v_{T} = \\frac{4m_{p}v_{T}}{\\sqrt{1-\\frac{v_{T}^{2}}{c^{2}}}},\n      \\end{equation}\n      and the momentum of the exhaust can be determined by:\n      \\begin{align}\n          E = \\mhe c^{2} + \\Delta E &= (\\mhe^{2}c^{4} + p_{2}^{2}c^{2})^{1/2}\\\\\n          (\\mhe+\\Delta m)^{2}c^{4} &= \\mhe^{2}c^{4} + p_{2}^{2}c^{2}\\\\\n          \\cancel{\\Delta m^{2}} + \\mhe\\Delta m &= p_{2}^{2}c^{-2}\\\\\n          p_{2} &= c\\sqrt{\\mhe\\Delta m}.\n      \\end{align}\n      The helium nucleus mass is about $\\mhe\\sim 4 m_{p}$, and the energy produced by the proton-proton chain converts to a mass:\n      \\begin{equation}\n          \\Delta m = \\frac{\\Delta E}{c^{2}} \\sim 10^{-2}m_{p}\n      \\end{equation}\n      Setting these momenta equal:\n      \\begin{align}\n          p_{1} &= p_{2}\\\\\n          \\frac{4m_{p}v_{T}}{\\sqrt{1-\\frac{v_{T}^{2}}{c^{2}}}} &= c\\sqrt{\\mhe\\Delta m}\\\\\n          \\frac{\\frac{v_{T}}{c}}{\\sqrt{1-\\frac{v_{T}^{2}}{c^{2}}}} &= \\frac{\\sqrt{\\mhe\\Delta m}}{4m_{p}}\\\\\n          \\frac{v_{T}}{c} &= \\left(\\frac{1}{\\frac{16m_{p}^{2}}{\\mhe\\Delta m}+1}\\right)^{1/2}\\\\\n          \\frac{v_{T}}{c} &= \\left(\\frac{1}{400+1}\\right)^{1/2} \\sim \\frac{1}{20} = 0.05\n      \\end{align}\n    \n    \\subsection{Non-relativistic Momentum Conservation}\n      This method is similar to the first, but it uses the non-relativistic formulas.  We have the total momentum of the protons:\n      \\begin{equation}\n          p_{1} = \\sum p_{p} = 4m_{p}v_{T},\n      \\end{equation}\n      and the exhaust momentum:\n      \\begin{equation}\n          p_{2} = \\sqrt{2\\mhe\\Delta E} = c\\sqrt{2\\mhe\\Delta m}.\n      \\end{equation}\n      Setting these equal:\n      \\begin{align}\n        p_{1} &= p_{2}\\\\\n        4m_{p}v_{T} &= c\\sqrt{2\\mhe\\Delta m}\\\\\n        \\frac{v_{T}}{c} &= \\left(\\frac{\\mhe\\Delta m}{8m_{p}^{2}}\\right)^{1/2}\\\\\n        \\frac{v_{T}}{c} &= \\frac{\\sqrt{2}}{20} \\sim 0.07\n      \\end{align}\n    \n    \\subsection{Non-relativistic Drag}\n      The generalized drag formula is:\n      \\begin{equation}\n          \\frac{1}{2}\\rho v_{T}^{2}A = F\n      \\end{equation}\n      where $A$ is the effective collecting area of our craft.  In this case, $F$ is the thrust generated by our reactor.  We can approximate $F$ by:\n      \\begin{equation}\n          F = \\frac{\\mathrm{d}p}{\\mathrm{d}t} \\sim \\frac{p}{4\\tau} = \\frac{pv_{T}}{4\\lambda}\n      \\end{equation}\n      where $\\tau = \\frac{\\lambda}{v_{T}}$ is the mean time between interactions with ISM protons, and $\\lambda$ is the mean free path of our spaceship in the ISM, given by\n      \\begin{equation}\n          \\lambda = \\frac{m_{p}}{\\rho A}.\n      \\end{equation}\n      Thus, we have:\n      \\begin{equation}\n          \\frac{1}{2}\\rho v_{T}^{2}A = \\frac{p\\rho Av_{T}}{4m_{p}}.\n      \\end{equation}\n      The exhaust momentum $p$ is the same as in the earlier non-relativistic derivation.  Solving for $v_{T}$:\n      \\begin{equation}\n          \\frac{v_{T}}{c} = \\frac{1}{2c}\\frac{p}{m_{p}} = \\left(\\frac{\\mhe\\Delta m}{2m_{p}^{2}}\\right)^{1/2} = \\frac{\\sqrt{2}}{20} \\sim 0.14\n      \\end{equation}\n    \n  \\section{Project Orion}\n    \\subsection{Rocket Equation}\n    Integral to this question is the Rocket Equation:\n    \\begin{equation}\n      \\Delta v = v_{e}\\ln\\left(\\frac{m_{0}}{m_{f}}\\right)\n    \\end{equation}\n    The derivation is as follows.  At time $t=0$, the rocket has mass $m+\\Delta m$ and velocity $v$.  At time $t=\\Delta t$, the rocket has velocity $v+\\Delta v$, mass $m$, and the spent fuel has mass $\\Delta m$ and velocity $v-v_{e}$, where $v_{e}$ is the rest frame ejecta velocity.  By conservation of momentum, then:\n    \\begin{align}\n      (m+\\Delta m)v &= m(v+\\Delta v) + \\Delta m (v-v_{e})\\\\\n      mv + \\Delta m v &= mv + m\\Delta v + \\Delta m v - \\Delta mv_{e}\\\\\n      \\Delta m v_{e} = m\\Delta v\\\\\n      \\Delta v &= v_{e}\\frac{\\Delta m}{m}\n    \\end{align}\n    Integrating this yields:\n    \\begin{equation}\n     \\Delta v = v_{e}\\ln\\left(\\frac{m_{0}}{m_{f}}\\right)\n    \\end{equation}\n    where $m_0$ is the initial mass of the spacecraft (fuel + payload) and $m_f$ is the final mass (just payload).\n    \n    \\subsection{Exhaust Velocity}\n      In the case of pulse propulsion, the ``ejecta velocity'' is actually the velocity of the explosion, when it pushes against your ship.  A nuclear bomb of mass $M$ has yield $E = \\epsilon Mc^{2}$; the ejecta then has velocity:\n      \\begin{equation}\n        v_{e} = \\sqrt{\\frac{2E}{M}} = \\sqrt{2\\epsilon c^{2}}\n      \\end{equation}\n      However, only a fraction $f\\leq \\frac{1}{2}$ of the mass is intercepted, so the effective velocity is\n      \\begin{equation}\n       v_{e} = f\\sqrt{2\\epsilon} c.\n      \\end{equation}\n    \n    \\subsection{Mass Ratio}\n      We can calculate $\\epsilon$ as:\n      \\begin{equation}\n        \\epsilon = \\frac{\\Delta E}{mc^2} \\approx 10^{-3}\n      \\end{equation}\n      Adopting a fiducial $f=\\frac{1}{2}$, we see:\n      \\begin{equation}\n        v_e \\approx 0.02c\n      \\end{equation}\n      and thus\n      \\begin{equation}\n       \\frac{m_{0}}{m_{f}} = \\exp\\left(\\frac{\\Delta v}{v_{e}}\\right) = e^{2.5} \\approx 10.\n      \\end{equation}\n      That is, about 90\\% of the mass of the spacecraft must be fuel (i.e., nukes).  The answer here will vary considerably because of the exponential, however.  Also, modern thermonuclear weapons would increase the efficiency of this design.\n  \n\\end{document}\n", "meta": {"hexsha": "c7af88f9ae6821b5bf245341ebebbd7511a3e400", "size": 6702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Bussard Ramjet/BussardRamjet_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": "Bussard Ramjet/BussardRamjet_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": "Bussard Ramjet/BussardRamjet_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": 50.7727272727, "max_line_length": 339, "alphanum_fraction": 0.609967174, "num_tokens": 2235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6113153445638055}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{subcaption}\n\\usepackage{bm}\n\\graphicspath{{./}}\n\\usepackage[left=1cm,right=1cm,top=1cm,bottom=1cm]{geometry}\n\\begin{document}\n\\title{Rotation Invariance using Second-order Convolutional Neural Networks}\n\n\\section{Introduction}\nWe propose a non-trivial filter filter for a Convolutional Neural Network (CNN) that is invariant to rotations of the input image around the center of the filter. \nIn particular we show how to construct such non-trivial rotationally-invariant filter by using two convolutional neural network layers with a nonlinear ReLu after each convolution.\nOur layer has the following two important properties that cannot both be attained by multiplication by a single filter.\nOne, it is rotationally invariant, and two, it is non-trivial. \nWhat we mean by non-trivial is that our single filter is able to distinguigsh a dumbbell from a donut, even if the donut looks exactly like the surface generated by a rotated dumbbell.\nNo actiong by a single linear filter can have both those properties since linearity implies the second property cannot hold given the first.\nFurthermore, the filter does not need to be trained on rotated views of its input image.\nIn \\cite{chengzhouhan}, Cheng et al. build a neural network that is essentially rotation invariant.\nIn \\cite{jaderberg}, Jaderberg builds a neural network that is invariant to rotations (more generally, to affine transformations of the input).\nHowever, both of those papers require that the network be trained on several transformed input representations in order for the network to learn to be rotationally invariant.\nRelatedly, neither of those networks is guaranteed mathematically to be invariant to rotations of the input image (even for square images rotated a quarter turn, for example).\nWe construct a non-trivial rotationally invariant CNN architecture that does not need to be trained on multiple rotated views on an object.\nOur filter is exactly rotationally invariant for rotations by a quarter turn, and the only reason it is only approximately invariant for other rotations is because of the rectangular nature of image pixels, which we compensate for by using gaussian blurring.\nFor sufficiently high-resolution pixels (or for pixels arranged finely enough along grid lines in polar coordinates) our method is guaranteed to be rotationally invariant to arbitrary precision.\nNa\\\"ively, one might expect that rotationally invariant filters satisfy our goal.\nHowever, as pointed out above, since a single filter is linear in its inputs, any rotationally invariant filter will return the same value for an image and for any weighted average of various rotations of that image.\nWe find this problematic because we would like our rotationally invariant filter to be able to distinguish objects like a donut from a dumbbell, even though if you rotate a dumbbell you get an object that looks like a donut.\nWe show that two layers of rotationally invariant second-order filters have the desired properties.\n\n\\section{Related Work}\nIn \\cite{marcos}, they generate exact rotation invariance over a finite number of rotations by taking the maxpool over a set of rotated filters.\n\n\\section{Defining a rotationally invariant filter}\nNo standard first-order filter is able to accomplish that task because first-order filters are linear in their inputs, so if they are invariant to rotation then they are also necessarily equally triggered by an image of that object and by a weighted average of images of rotations of that object.\n\nWe construct an (approximately) rotationally-symmetric filter as follows. \nWe assume a square filter of side length $2h + 1$. \nThe pixels are defined by $\\mathbf x = (x,y),\\text{ for } x,y\\in [-h,h]$ we define the radius $r$ of a pixel as $r_{\\mathbf{x}} = ||x||_2$. \nWe can therefore construct an approximately rotationally-invariant basis filter by setting the filter value $f_n(\\mathbf{x})$ to be equal to\n$f(\\mathbf{x}) = P(n,\\sigma,r_x)$ \nwhere $n$ is the radius parameter for the desired filter, $\\sigma$ is the standard deviation of the blurring gaussian for the filter, and $P(n, \\sigma, r_x)$ is the gaussian probability density value of the point $r_x$ for the gaussian centered at $n$ with standard deviation $\\sigma$.\n\n\\begin{figure}[h]\n\\centering\n\\begin{subfigure}[t]{.3\\textwidth}\n \\centering\n \\includegraphics[width=1in]{basis}\n \\caption{Our rotationally symmetric basis filter of radius 5 pixels}\n\\end{subfigure}\n\\begin{subfigure}[t]{.3\\textwidth}\n \\centering\n \\includegraphics[width=1in]{rotbasis45}\n \\caption{That basis filter rotated by 45 degrees counterclockwise (using bilinear interpolation to fit rotated pixels)}\n\\end{subfigure}\n\\begin{subfigure}[t]{.3\\textwidth}\n \\centering\n \\includegraphics[width=1in]{diffbasisrot45}\n \\caption{The difference in pixel intensity between the basis filter and the rotated basis filter (hardly discernable)}\n\\end{subfigure}\n\\end{figure}\n\n\\bibliography{traversr}{}\n\\bibliographystyle{plain}\n\\end{document}\n", "meta": {"hexsha": "9fcbd5a7e5ca7a49e19c1ea4805a297c0744cf65", "size": 5086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writeup/traversr.tex", "max_stars_repo_name": "travers-rhodes/ricnn", "max_stars_repo_head_hexsha": "c5a7a15bff78b8f1495223b2bd70c4a1326e469e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writeup/traversr.tex", "max_issues_repo_name": "travers-rhodes/ricnn", "max_issues_repo_head_hexsha": "c5a7a15bff78b8f1495223b2bd70c4a1326e469e", "max_issues_repo_licenses": ["MIT"], "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/traversr.tex", "max_forks_repo_name": "travers-rhodes/ricnn", "max_forks_repo_head_hexsha": "c5a7a15bff78b8f1495223b2bd70c4a1326e469e", "max_forks_repo_licenses": ["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.7941176471, "max_line_length": 296, "alphanum_fraction": 0.799252851, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959543, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6113153432080405}}
{"text": "\\input{permve-ntnu-latex-assignment.tex}\n\n\\title{\n\\normalfont \\normalsize\n\\textsc{Norwegian University of Science and Technology\\\\IT3708 -- Subsymbolic Methods in AI}\n}\n\n\\author{Per Magnus Veierland\\\\permve@stud.ntnu.no}\n\n\\date{\\normalsize\\today}\n\n\\begin{document}\n\n\\fancyfoot[C]{}\n\\maketitle\n\n\\section*{Intelligence Emerging: EA Rank Errata Suggestion}\n\nIn the description of the rank selection in evolutionary algorithms on page 434 in section A.5.2 I've found a small error concerning the derivation in Equation A.6 and A.7.\n\nEquation A.6 shows that Equation~\\ref{eq:a6a} is equal to Equation~\\ref{eq:a6b}.\n\n\\begin{equation}\n\\label{eq:a6a}\n\\sum_{i=1}^{N}\\Bigg[ \\text{min} + (\\text{max} - \\text{min})\\frac{\\textit{rank}(i, g) - 1}{N - 1}\\Bigg]\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:a6b}\nN \\cdot \\text{min} + (\\text{max} - \\text{min}) \\sum_{i=1}^{N}\\frac{i}{N - 1}\n\\end{equation}\n\nHowever these are not equivalent, and Equation~\\ref{eq:a6b} should instead be:\n\n\\begin{equation}\nN \\cdot \\text{min} + (\\text{max} - \\text{min}) \\sum_{i=1}^{N}\\frac{i - 1}{N - 1}\n\\end{equation}\n\nThis results in the following derivation, which differs from the first two steps of Equation A.7:\n\n\\begin{equation}\n\\sum_{i=1}^{N}\\frac{i - 1}{N - 1} =\n\\frac{1}{N - 1}\\sum_{i=1}^{N}(i - 1) =\n\\frac{1}{N - 1}\\sum_{i=1}^{N - 1}i =\n\\frac{1}{N - 1} \\cdot \\frac{(N - 1)N}{2} =\n\\frac{N}{2}\n\\end{equation}\n\n\\end{document}\n\n", "meta": {"hexsha": "a3fae63193c782320e06d2f46c35c94e89bac57c", "size": 1396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "errata/permve-intelligence-emerging-errata-ea-rank/permve-intelligence-emerging-errata-ea-rank.tex", "max_stars_repo_name": "pveierland/permve-ntnu-it3708", "max_stars_repo_head_hexsha": "1066d5c1af5c953dbaf129d7e05ce32f2d4292aa", "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": "errata/permve-intelligence-emerging-errata-ea-rank/permve-intelligence-emerging-errata-ea-rank.tex", "max_issues_repo_name": "pveierland/permve-ntnu-it3708", "max_issues_repo_head_hexsha": "1066d5c1af5c953dbaf129d7e05ce32f2d4292aa", "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": "errata/permve-intelligence-emerging-errata-ea-rank/permve-intelligence-emerging-errata-ea-rank.tex", "max_forks_repo_name": "pveierland/permve-ntnu-it3708", "max_forks_repo_head_hexsha": "1066d5c1af5c953dbaf129d7e05ce32f2d4292aa", "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.3725490196, "max_line_length": 172, "alphanum_fraction": 0.6783667622, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911057, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6113153327744851}}
{"text": "\n% This LaTeX was auto-generated from MATLAB code.\n% To make changes, update the MATLAB code 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\\section*{Author: DAVID LI}\n\n\n\\begin{verbatim}FinalPrep.m --- ELEC 403 Final exam, this matlab file is used to do the\nvarious problems in the ELEC 403 textbook that are related to the final\nexam, of course the focus is on chapter 5 and chapter 7.\\end{verbatim}\n    \n\\subsection*{Contents}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item Prob 5.2 with jacobian f(x) = x\\^{}2+2*y\\^{}2+4*x+4*y\n   \\item Prob 5.2 with Newton\n   \\item Prob 5.4 -- Find a good starting point besides x0 = [1 1]\n   \\item 5.4 Using Newton\n   \\item 5.4 Using Gauss Newton\n   \\item Prob 5.5 -- use a closer point so that it can be done manually\n   \\item Chapter 7, using Prob 5.2 with DFP\n   \\item Chapter 7, using Prob 5.2 with BFGS\n   \\item Examples from the Internet --- Using DFP\n   \\item USING BFGS\n\\end{itemize}\n\n\n\\subsection*{Prob 5.2 with jacobian f(x) = x\\^{}2+2*y\\^{}2+4*x+4*y}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item REMEMBER THAT CHAPTER 5 only has SDM, Newton and Gauss-Newton*\n\\end{itemize}\n\\begin{verbatim}\nsyms x_1 x_2\nf = x_1^2+2*x_2^2+4*x_1+4*x_2;\nlatex(f);\ng=gradient(f);\nlatex(g);\nf1 = x_1+2;\nf2 = sqrt(2)*(x_2+1);\nj=jacobian([f1,f2],[x_1,x_2]);\nh = hessian(f);\n%steep_desc3('func52','grad52',[-1; 1],1e-3);\ngauss_newton('func52','grad52','jacob52',[-1; 1],1e-3);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram gauss_newton.m\n\nF_k =\n\n     3\n\n\ngk =\n\n     2\n     8\n\n\nJk =\n\n    1.0000         0\n         0    1.4142\n\n\nHk =\n\n    2.0000         0\n         0    4.0000\n\n\ndk =\n\n   -1.0000\n   -2.0000\n\n\nak =\n\n    1.0000\n\n\nxk =\n\n   -2.0000\n   -1.0000\n\n\nF_k1 =\n\n    -6\n\n\ngk =\n\n   1.0e-12 *\n\n    0.4450\n   -0.2185\n\n\nJk =\n\n    1.0000         0\n         0    1.4142\n\n\ndk =\n\n   1.0e-12 *\n\n   -0.2225\n    0.0546\n\n\nak =\n\n     1\n\n\nadk =\n\n   1.0e-12 *\n\n   -0.2225\n    0.0546\n\n\ner =\n\n     9\n\n\nxk =\n\n    -2\n    -1\n\n\nF_k1 =\n\n    -6\n\n\ngk =\n\n     0\n     0\n\n\nJk =\n\n    1.0000         0\n         0    1.4142\n\n\ndk =\n\n     0\n     0\n\n\nak =\n\n     1\n\n\nadk =\n\n     0\n     0\n\n\ner =\n\n     0\n\nSolution point:\n\nxs =\n\n    -2\n    -1\n\nObjective function at the solution point:\n\nfs =\n\n    -6\n\nNumber of iterations performed:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Prob 5.2 with Newton}\n\n\\begin{verbatim}\nnewton('func52','grad52','hess52',[0; 0],0.1,1e-3);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram newton.m\n\ngk =\n\n     4\n     4\n\n\nHk =\n\n     2     0\n     0     4\n\n\ndk =\n\n    -2\n    -1\n\nAlpha: 1.000000000 \n\ner =\n\n    2.2361\n\n\ngk =\n\n     0\n     0\n\n\nHk =\n\n     2     0\n     0     4\n\n\nak =\n\n     1\n\nAlpha: 1.000000000 \nSolution point:\n\nxs =\n\n    -2\n    -1\n\nObjective function at the solution point:\n\nfs =\n\n    -6\n\nNumber of iterations performed:\n\nk =\n\n     2\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Prob 5.4 -- Find a good starting point besides x0 = [1 1]}\n\n\\begin{verbatim}\nsyms x_1 x_2\nf = 5*x_1^2-9*x_1*x_2+4.075*x_2^2+x_1;\nlatex(f);\ng = gradient(f);\nlatex(g);\nsteep_desc3('func54','grad54',[-16; -17.9],1e-3);\nh = hessian(f);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram steep_desc3.m\nAlpha: 0.055180698 \n\t xk+1: -16.115879466 \n\t xk+1: -17.795984384 \nf(xk) = -8.148958e+00 \n\nAlpha: 36.073499423 \n\t xk+1: -16.298584133 \n\t xk+1: -17.999528044 \nf(xk) = -8.149995e+00 \nNorm Value: 2.735160e-01\n\nAlpha: 0.055180697 \n\t xk+1: -16.299131033 \n\t xk+1: -17.999037137 \nf(xk) = -8.150000e+00 \nNorm Value: 7.349077e-04\n\nSolution point:\n\nxs =\n\n -16.299131032840879\n -17.999037136909219\n\nObjective function at the solution point:\n\nfs =\n\n  -8.149999976794053\n\nNumber of iterations performed:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{5.4 Using Newton}\n\n\\begin{verbatim}\nh = hessian(f);\nlatex(h)\nnewton('func54','grad54','hess54',[-10; -5],0.1,1e-6);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\nans =\n\n\\left(\\begin{array}{cc} 10 & -9\\\\ -9 & \\frac{163}{20} \\end{array}\\right)\n\n \nProgram newton.m\n\ngk =\n\n  -54.0000\n   49.2500\n\n\nHk =\n\n   10.0000   -9.0000\n   -9.0000    8.1500\n\n\ndk =\n\n   -6.3000\n  -13.0000\n\nAlpha: 0.945675721 \n\ner =\n\n   13.6613\n\n\ngk =\n\n   -2.9335\n    2.6755\n\n\nHk =\n\n   10.0000   -9.0000\n   -9.0000    8.1500\n\n\nak =\n\n     1\n\nAlpha: 1.000000000 \n\ngk =\n\n   1.0e-13 *\n\n    0.5684\n   -0.5684\n\n\nHk =\n\n   10.0000   -9.0000\n   -9.0000    8.1500\n\n\nak =\n\n     1\n\nAlpha: 1.000000000 \nSolution point:\n\nxs =\n\n -16.300000000000054\n -18.000000000000060\n\nObjective function at the solution point:\n\nfs =\n\n  -8.149999999999963\n\nNumber of iterations performed:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{5.4 Using Gauss Newton}\n\n\\begin{verbatim}\nj = jacobian(f,[x_1,x_2]);\ngauss_newton('func54','grad54','jacob54',[-16; -18],1e-3);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram gauss_newton.m\n\nF_k =\n\n   -7.7000\n\n\ngk =\n\n    3.0000\n   -2.7000\n\n\nJk =\n\n    3.0000   -2.7000\n\n\nHk =\n\n   18.0000  -16.2000\n  -16.2000   14.5800\n\n\ndk =\n\n   -0.0920\n    0.0828\n\n\nak =\n\n    1.7993\n\n\nxk =\n\n  -16.1656\n  -17.8511\n\n\nF_k1 =\n\n   -8.1494\n\n\ngk =\n\n    0.0037\n    0.0041\n\n\nJk =\n\n    0.0037    0.0041\n\n\ndk =\n\n  -60.4078\n  -67.1792\n\n\nak =\n\n    0.0022\n\n\nadk =\n\n   -0.1338\n   -0.1488\n\n\ner =\n\n    0.4494\n\n\nxk =\n\n  -16.2994\n  -17.9999\n\n\nF_k1 =\n\n   -8.1500\n\n\ngk =\n\n    0.0049\n   -0.0044\n\n\nJk =\n\n    0.0049   -0.0044\n\n\ndk =\n\n  -56.5957\n   50.8910\n\n\nak =\n\n   1.0000e-05\n\n\nadk =\n\n   1.0e-03 *\n\n   -0.5660\n    0.5089\n\n\ner =\n\n   5.5388e-04\n\nSolution point:\n\nxs =\n\n -16.300007501945657\n -17.999413346528229\n\nObjective function at the solution point:\n\nfs =\n\n  -8.149998557647706\n\nNumber of iterations performed:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Prob 5.5 -- use a closer point so that it can be done manually}\n\n\\begin{par}\nProduce the latex needed for final exam review document\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\nsyms x_1 x_2 x_3\nf = (x_1+5)^2+(x_2+8)^2+(x_3+7)^2+2*x_1^2*x_2^2+4*x_1^2*x_3^2;\nlatex(f)\ng = gradient(f);\nlatex(g)\n\nsteep_desc3('func55','grad55',[0; -8; -7],1e-3)\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim}\nans =\n\n2\\, {x_{1}}^2\\, {x_{2}}^2 + 4\\, {x_{1}}^2\\, {x_{3}}^2 + {\\left(x_{1} + 5\\right)}^2 + {\\left(x_{2} + 8\\right)}^2 + {\\left(x_{3} + 7\\right)}^2\n\n\nans =\n\n\\left(\\begin{array}{c} 4\\, x_{1}\\, {x_{2}}^2 + 8\\, x_{1}\\, {x_{3}}^2 + 2\\, x_{1} + 10\\\\ 4\\, x_{2}\\, {x_{1}}^2 + 2\\, x_{2} + 16\\\\ 8\\, x_{3}\\, {x_{1}}^2 + 2\\, x_{3} + 14 \\end{array}\\right)\n\n \nProgram steep_desc3.m\nAlpha: 0.001538462 \n\t xk+1: -0.015384615 \n\t xk+1: -8.000000000 \n\t xk+1: -7.000000000 \nf(xk) = 2.492308e+01 \n\nAlpha: 0.499585233 \n\t xk+1: -0.015384615 \n\t xk+1: -7.996216159 \n\t xk+1: -6.993378279 \nf(xk) = 2.492302e+01 \nNorm Value: 7.626575e-03\n\nAlpha: 0.001540793 \n\t xk+1: -0.015407926 \n\t xk+1: -7.996216155 \n\t xk+1: -6.993378281 \nf(xk) = 2.492302e+01 \nNorm Value: 2.331078e-05\n\nSolution point:\n\nxs =\n\n  -0.015407926169005\n  -7.996216155022361\n  -6.993378280948492\n\nObjective function at the solution point:\n\nfs =\n\n  24.923018533805848\n\nNumber of iterations performed:\n\nk =\n\n     3\n\n\nans =\n\n   -0.0154\n   -7.9962\n   -6.9934\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Chapter 7, using Prob 5.2 with DFP}\n\n\\begin{itemize}\n\\setlength{\\itemsep}{-1ex}\n   \\item REMEMBER THAT CHAPTER 7 only has DFP and BFGS*\n   \\item DFP\n   \\item BFGS\n\\end{itemize}\n\\begin{verbatim}\ndfp('func52','grad52',[-1; 1],1e-6);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram dfp.m\n------- ITERATION 1 ------\nSTEP 1\n\nxk =\n\n    -1\n     1\n\n\nSk =\n\n     1     0\n     0     1\n\n\ngk =\n\n     2\n     8\n\nSTEP 2\n\ndk =\n\n    -2\n    -8\n\n\nak =\n\n    0.2576\n\n\ndtk =\n\n   -0.5152\n   -2.0606\n\n\nxk_new =\n\n   -1.5152\n   -1.0606\n\nSTEP 3\nNorm of delta is 8.76 and epsi is 1.000000e-06\nSTEP 4\n\ngk_new =\n\n    0.9697\n   -0.2424\n\n\ngmk =\n\n   -1.0303\n   -8.2424\n\n\nsg =\n\n   -1.0303\n   -8.2424\n\n\nsw1 =\n\n    0.2654    1.0615\n    1.0615    4.2461\n\n\nsw2 =\n\n    1.0615    8.4922\n    8.4922   67.9376\n\n\nsw3 =\n\n   68.9991\n\n\nSk =\n\n    0.9998   -0.0625\n   -0.0625    0.2578\n\n\ngk =\n\n    0.9697\n   -0.2424\n\n------- ITERATION 2 ------\nSTEP 2\n\ndk =\n\n   -0.9846\n    0.1231\n\n\nak =\n\n    0.4924\n\n\ndtk =\n\n   -0.4848\n    0.0606\n\nSTEP 3\nNorm of delta is 0.49 and epsi is 1.000000e-06 \nSTEP 4\n\ngk_new =\n\n     0\n     0\n\n\ngmk =\n\n   -0.9697\n    0.2424\n\n\nsg =\n\n   -0.9846\n    0.1231\n\n\nsw1 =\n\n    0.2351   -0.0294\n   -0.0294    0.0037\n\n\nsw2 =\n\n    0.9695   -0.1212\n   -0.1212    0.0151\n\n\nsw3 =\n\n    0.9846\n\n\nSk =\n\n    0.5000   -0.0000\n   -0.0000    0.2500\n\n\ngk =\n\n     0\n     0\n\n------- ITERATION 3 ------\nSTEP 2\n\ndk =\n\n     0\n     0\n\n\nak =\n\n     1\n\n\ndtk =\n\n     0\n     0\n\nSTEP 3\nNorm of delta is 0.00 and epsi is 1.000000e-06 \nsolution point:\n\nxs =\n\n    -2\n    -1\n\nobjective function at the solution point:\n\nfs =\n\n    -6\n\nnumber of iterations at convergence:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Chapter 7, using Prob 5.2 with BFGS}\n\n\\begin{verbatim}\nbfgs('func52','grad52',[-1; 1],1e-6);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram bfgs.m\n------- ITERATION 1 ------\nSTEP 1\n\nxk =\n\n    -1\n     1\n\n\nSk =\n\n     1     0\n     0     1\n\n\ngk =\n\n     2\n     8\n\nSTEP 2\n\ndk =\n\n    -2\n    -8\n\n\nak =\n\n    0.2576\n\n\ndtk =\n\n   -0.5152\n   -2.0606\n\n\nxk_new =\n\n   -1.5152\n   -1.0606\n\nSTEP 3\nNorm of delta is 8.76 and epsi is 1.000000e-06\nSTEP 4\n\ngk_new =\n\n    0.9697\n   -0.2424\n\n\ngmk =\n\n   -1.0303\n   -8.2424\n\n\nD =\n\n   17.5152\n\n\nsg =\n\n   -1.0303\n   -8.2424\n\n\nsw1 =\n\n    0.2654    1.0615\n    1.0615    4.2461\n\n\nsw2 =\n\n    0.5308    2.1230\n    4.2461   16.9844\n\n\nSk =\n\n    1.0142   -0.0643\n   -0.0643    0.2580\n\n\nfk =\n\n   -5.7576\n\n\ngk =\n\n    0.9697\n   -0.2424\n\n------- Iteration 2 ------\nSTEP 2\n\ndk =\n\n   -0.9991\n    0.1249\n\n\nak =\n\n    0.4853\n\n\ndtk =\n\n   -0.4848\n    0.0606\n\nSTEP 3\nNorm of delta is 0.49 and epsi is 1.000000e-06 \nSTEP 4\n\ngk_new =\n\n     0\n     0\n\n\ngmk =\n\n   -0.9697\n    0.2424\n\n\nD =\n\n    0.4848\n\n\nsg =\n\n   -0.9991\n    0.1249\n\n\nsw1 =\n\n    0.2351   -0.0294\n   -0.0294    0.0037\n\n\nsw2 =\n\n    0.4844   -0.0606\n   -0.0606    0.0076\n\n\nSk =\n\n    0.5000    0.0000\n    0.0000    0.2500\n\n\nfk =\n\n    -6\n\n\ngk =\n\n     0\n     0\n\n------- Iteration 3 ------\nSTEP 2\n\ndk =\n\n     0\n     0\n\n\nak =\n\n     1\n\n\ndtk =\n\n     0\n     0\n\nSTEP 3\nNorm of delta is 0.00 and epsi is 1.000000e-06 \nsolution point:\n\nxs =\n\n    -2\n    -1\n\nobjective function at the solution point:\n\nfs =\n\n    -6\n\nnumber of iterations at convergence:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{Examples from the Internet --- Using DFP}\n\n\\begin{par}\n$f(x)=-2*x_1^2-10*x_2^2$\n\\end{par} \\vspace{1em}\n\\begin{verbatim}\ndfp('funcNet1','gradNet1',[1; -1],1e-3);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram dfp.m\n------- ITERATION 1 ------\nSTEP 1\n\nxk =\n\n     1\n    -1\n\n\nSk =\n\n     1     0\n     0     1\n\n\ngk =\n\n     4\n   -20\n\nSTEP 2\n\ndk =\n\n    -4\n    20\n\n\nak =\n\n    0.0577\n\n\ndtk =\n\n   -0.2308\n    1.1538\n\n\nxk_new =\n\n    0.7692\n    0.1538\n\nSTEP 3\nNorm of delta is 10.58 and epsi is 1.000000e-03\nSTEP 4\n\ngk_new =\n\n    3.0769\n    3.0769\n\n\ngmk =\n\n   -0.9231\n   23.0769\n\n\nsg =\n\n   -0.9231\n   23.0769\n\n\nsw1 =\n\n    0.0533   -0.2663\n   -0.2663    1.3314\n\n\nsw2 =\n\n    0.8521  -21.3018\n  -21.3018  532.5444\n\n\nsw3 =\n\n  533.3964\n\n\nSk =\n\n    1.0004    0.0300\n    0.0300    0.0512\n\n\ngk =\n\n    3.0769\n    3.0769\n\n------- ITERATION 2 ------\nSTEP 2\n\ndk =\n\n   -3.1705\n   -0.2499\n\n\nak =\n\n    0.2699\n\n\ndtk =\n\n   -0.8556\n   -0.0674\n\nSTEP 3\nNorm of delta is 1.33 and epsi is 1.000000e-03 \nSTEP 4\n\ngk_new =\n\n   -0.3456\n    1.7281\n\n\ngmk =\n\n   -3.4225\n   -1.3488\n\n\nsg =\n\n   -3.4644\n   -0.1718\n\n\nsw1 =\n\n    0.7321    0.0577\n    0.0577    0.0045\n\n\nsw2 =\n\n   12.0017    0.5951\n    0.5951    0.0295\n\n\nsw3 =\n\n   12.0886\n\n\nSk =\n\n    0.2500   -0.0001\n   -0.0001    0.0503\n\n\ngk =\n\n   -0.3456\n    1.7281\n\n------- ITERATION 3 ------\nSTEP 2\n\ndk =\n\n    0.0866\n   -0.0869\n\n\nak =\n\n    0.9949\n\n\ndtk =\n\n    0.0862\n   -0.0865\n\nSTEP 3\nNorm of delta is 0.12 and epsi is 1.000000e-03 \nSTEP 4\n\ngk_new =\n\n   1.0e-03 *\n\n   -0.9953\n   -0.9953\n\n\ngmk =\n\n    0.3446\n   -1.7291\n\n\nsg =\n\n    0.0864\n   -0.0870\n\n\nsw1 =\n\n    0.0074   -0.0074\n   -0.0074    0.0075\n\n\nsw2 =\n\n    0.0075   -0.0075\n   -0.0075    0.0076\n\n\nsw3 =\n\n    0.1801\n\n\nSk =\n\n    0.2501    0.0000\n    0.0000    0.0500\n\n\ngk =\n\n   1.0e-03 *\n\n   -0.9953\n   -0.9953\n\n------- ITERATION 4 ------\nSTEP 2\n\ndk =\n\n   1.0e-03 *\n\n    0.2489\n    0.0498\n\n\nak =\n\n    0.9997\n\n\ndtk =\n\n   1.0e-03 *\n\n    0.2488\n    0.0498\n\nSTEP 3\nNorm of delta is 0.00 and epsi is 1.000000e-03 \nsolution point:\n\nxs =\n\n   1.0e-10 *\n\n   0.458617078233185\n  -0.458617078910812\n\nobjective function at the solution point:\n\nfs =\n\n     2.523955499581143e-20\n\nnumber of iterations at convergence:\n\nk =\n\n     4\n\n\\end{verbatim} \\color{black}\n    \n\n\\subsection*{USING BFGS}\n\n\\begin{verbatim}\nbfgs('func52','grad52',[-1; 1],1e-6);\n\\end{verbatim}\n\n        \\color{lightgray} \\begin{verbatim} \nProgram bfgs.m\n------- ITERATION 1 ------\nSTEP 1\n\nxk =\n\n    -1\n     1\n\n\nSk =\n\n     1     0\n     0     1\n\n\ngk =\n\n     2\n     8\n\nSTEP 2\n\ndk =\n\n    -2\n    -8\n\n\nak =\n\n    0.2576\n\n\ndtk =\n\n   -0.5152\n   -2.0606\n\n\nxk_new =\n\n   -1.5152\n   -1.0606\n\nSTEP 3\nNorm of delta is 8.76 and epsi is 1.000000e-06\nSTEP 4\n\ngk_new =\n\n    0.9697\n   -0.2424\n\n\ngmk =\n\n   -1.0303\n   -8.2424\n\n\nD =\n\n   17.5152\n\n\nsg =\n\n   -1.0303\n   -8.2424\n\n\nsw1 =\n\n    0.2654    1.0615\n    1.0615    4.2461\n\n\nsw2 =\n\n    0.5308    2.1230\n    4.2461   16.9844\n\n\nSk =\n\n    1.0142   -0.0643\n   -0.0643    0.2580\n\n\nfk =\n\n   -5.7576\n\n\ngk =\n\n    0.9697\n   -0.2424\n\n------- Iteration 2 ------\nSTEP 2\n\ndk =\n\n   -0.9991\n    0.1249\n\n\nak =\n\n    0.4853\n\n\ndtk =\n\n   -0.4848\n    0.0606\n\nSTEP 3\nNorm of delta is 0.49 and epsi is 1.000000e-06 \nSTEP 4\n\ngk_new =\n\n     0\n     0\n\n\ngmk =\n\n   -0.9697\n    0.2424\n\n\nD =\n\n    0.4848\n\n\nsg =\n\n   -0.9991\n    0.1249\n\n\nsw1 =\n\n    0.2351   -0.0294\n   -0.0294    0.0037\n\n\nsw2 =\n\n    0.4844   -0.0606\n   -0.0606    0.0076\n\n\nSk =\n\n    0.5000    0.0000\n    0.0000    0.2500\n\n\nfk =\n\n    -6\n\n\ngk =\n\n     0\n     0\n\n------- Iteration 3 ------\nSTEP 2\n\ndk =\n\n     0\n     0\n\n\nak =\n\n     1\n\n\ndtk =\n\n     0\n     0\n\nSTEP 3\nNorm of delta is 0.00 and epsi is 1.000000e-06 \nsolution point:\n\nxs =\n\n    -2\n    -1\n\nobjective function at the solution point:\n\nfs =\n\n    -6\n\nnumber of iterations at convergence:\n\nk =\n\n     3\n\n\\end{verbatim} \\color{black}\n    \n\n\n\\end{document}\n    \n", "meta": {"hexsha": "4a93c2b8e4a83f79a81f6806349984498c85046b", "size": 14373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ELEC403/ELEC403Final/html/FinalPrep.tex", "max_stars_repo_name": "FriendlyUser/Matlab", "max_stars_repo_head_hexsha": "4615540072e198549370bc8b1f2ce502e94a867e", "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": "ELEC403/ELEC403Final/html/FinalPrep.tex", "max_issues_repo_name": "FriendlyUser/Matlab", "max_issues_repo_head_hexsha": "4615540072e198549370bc8b1f2ce502e94a867e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-10T06:00:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-10T06:00:21.000Z", "max_forks_repo_path": "ELEC403/ELEC403Final/html/FinalPrep.tex", "max_forks_repo_name": "FriendlyUser/Matlab", "max_forks_repo_head_hexsha": "4615540072e198549370bc8b1f2ce502e94a867e", "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": 8.7800855223, "max_line_length": 186, "alphanum_fraction": 0.5373269324, "num_tokens": 6393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.6113057135376856}}
{"text": "\\section{The Real and Complex Number Systems}\n\n\\subsection{Exercise 1}\nIf $rx = q$ or $r+x = q$ for some rational $q$, then substracting $r$ from $q$ or dividing $q$ by $r$ \nyields $x$ rational, which is a contradiction.\n\n\\subsection{Exercise 2}\nWe can first show that $\\sqrt{3}$ is irrational by seeing that $\\frac{a^2}{b^2} = 3 \\implies 3 | a, 3 | b$.\nThen, since $12 = 3 * 2^2$, we have that $\\sqrt{12}$ is irrational as well.\n\n\\subsection{Exercise 4}\nIf $\\alpha > \\beta$ then $\\alpha$ would be an upper bound as well.\n\n\\subsection{Exercise 5}\n$\\forall x \\in A, \\: -x \\leq \\sup{-A}$ and $\\forall \\epsilon \\in \\mathbb{R}, \\: \\exists x \\in A \\: | \\sup{-A} + \\epsilon < -x \\leq \\sup{-A}$. Negating the last inequality gives $\\inf{A} = -\\sup{-A}$.\n\n\\subsection{Exercise 6}\n(a) Follows from $m = \\frac{np}{q}$.\n\n(b) Put $r = \\frac{m}{n}, \\: s = \\frac{p}{q}$. Then $b^r b^s = b^{\\frac{mq}{nq}} b^{\\frac{np}{nq}}$.\nPulling out $\\frac{1}{nq}$ gives the desired result.\n\n(c) $b^r$ is an upper bound since $b > 1$, and if it were not the supremum we could choose \n$t < r$ such that $b^t > b^r$. This is not possible since again, $b > 1$.\n\n(d) Every element in $B(x + y)$ can be expressed as $b^{s + t} = b^s b^t \\: s \\leq x, \\: t \\leq y$.\nIf $\\sup{B(x+y)} = \\alpha < \\sup{B(x)}\\sup{B(y)}$, then $b^s b^t \\leq \\alpha \\implies B(x) \\leq \\alpha b^{-t}\n\\implies B(y) \\leq \\frac{\\alpha}{B(x)} \\implies B(x) B(y) \\leq \\alpha$.\n\n\\subsection{Exercise 7}\n(a) $b^n - 1 = (b - 1) (b^{n-1} + b^{n-2} + ... + 1) \\geq n (b-1)$ since $b > 1$.\n\n(b) Plug $b^{\\frac{1}{n}}$ into (a).\n\n(c) Plug $n > \\frac{b_-1}{t-1}$ into (b).\n\n(d) Using (c) gives that we can choose $n$ such that\n$b^{\\frac{1}{n}} < y \\dot b^{-w} \\implies b^{w + \\frac{1}{n}} < y$.\n\n(e) We can take the reciprocal of (c) and do the same as in (d).\n\n(f) If $b^x > y$ we can apply (e) for a contradiction, if $b^x < y$ we can apply (d)\nfor a contradiction. \n\n(g) Supremum is unique.\n\n\\subsection{Exercise 8}\nSuppose $(0, 1) < (0, 0)$. Then $(0, -1) < (0, 0)$ after multiplying by  $(0, 1)$ twice yields a\ncontradiction. Similarly, assuming the opposite yields $(-1, 0) > (0, 0)$.\n\n\\subsection{Exercise 9}\nDoes exhibit least upper-bound property since you can take $(\\sup{a_i}, \\sup{b_i})$.\n\n\\subsection{Exercise 10}\nException is 0.\n\n\\subsection{Exercise 11}\nTake $w = \\frac{1}{\\abs{z}}z$ and $r = \\abs{z}$ when $\\abs{z} \\neq 0$. \n$w$ and $r$ are not uniquely determined; take $z = 0$ for example.\n\n\\subsection{Exercise 12}\nBy strong induction:\n\\begin{align*}\n        \\abs{z_1 + ... + z_{n+1}} &\\leq \\abs{z_1 + ... + z_n} + \\abs{z_{n+1}} \\\\\n                                  &\\leq \\abs{z_1} + ... + \\abs{z_{n+1}}\n\\end{align*}\n\n\\subsection{Exercise 13}\n\\begin{align*}\n        \\abs{x - y}^2 &= x\\bar{x} - 2\\abs{x}\\abs{y} + y \\bar{y} \\\\\n                      &\\geq (\\abs{x} - \\abs{y})^2\n\\end{align*}\n", "meta": {"hexsha": "03800ab2d6d393d65992235b1bd73c2c748a1e9a", "size": 2836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/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": "Principles_of_Mathematical_Analysis_Rudin/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": "Principles_of_Mathematical_Analysis_Rudin/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": 38.8493150685, "max_line_length": 199, "alphanum_fraction": 0.5782792666, "num_tokens": 1112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.6113057091580165}}
{"text": "\\section{More about $\\Tor$}\nWhere is everybody? Looks like nobody wants to hear about $\\Tor$. You're the select few.\n\nOn Monday I gave ``axioms'' for $\\Tor$, basically by saying that $\\Tor^R_n(M,-):\\mathbf{Mod}_R\\to\\mathbf{Mod}_R$ is like a homology theory. Today I'm going to show a construction of $\\Tor$, and verify the axioms. Or at least the lexseq business. I also tried to show that it's a reasonable idea to study free resolutions, namely:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar@{-->}[rr] & & F_2\\ar[dr]\\ar@{-->}[rr]^d & & F_1\\ar[dr]\\ar@{-->}[rr]^d & & F_0\\ar[dr]\\\\\n& K_2\\ar[ur]\\ar[dr] & & K_1\\ar[ur]\\ar[dr] & & K_0\\ar[ur]\\ar[dr] & & N\\ar[dr]\\\\\n0\\ar[ur] & & 0\\ar[ur] & & 0\\ar[ur] & & 0\\ar[ur] & & 0}\n\\end{equation*}\nWhere $F_{i+1}$ surjects onto $K_i$ and the $F_i$ are free $R$-modules. Splicing these exact sequences gives you a exact sequence in the top row, which is a free resolution of $N$. Of course there are a lot of choices involved, so free resolutions aren't unique. The resolution $F_\\bullet$ does \\emph{not} include $N$, and in the following diagram, the top row isn't exact but $\\cdots\\to F_0\\to N\\to 0$ is exact.\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & F_2\\ar[r] & F_1\\ar[r] & F_0\\ar[r]\\ar[d]^\\epsilon & 0\\\\\n & & & N & }\n\\end{equation*}\nThen, note that:\n\\begin{equation*}\n H_q(F_\\bullet)=\\begin{cases}\nN & q=0\\\\\n0 & q>0\n\\end{cases}\n\\end{equation*}\n\\begin{construction}\nWe construct $\\Tor^R_n(M,N)$ via $ H_n(M\\otimes_R F_\\bullet)$ where $F_\\bullet$ is a free resolution of $N$.\n\\end{construction}\nI have to check that this is well-defined, that it's functorial, and that it satisfies the lexseq. Maybe I should also check what $ H_0(M\\otimes_R F_\\bullet)$ is. I do get $M\\otimes_R F_\\bullet$, because tensoring with $M$ is right exact, i.e., you have an exact sequence $M\\otimes_R F_1\\xrightarrow{p} M\\otimes_R F_0\\to M\\otimes_R N\\to 0$, and the zeroth homology is the cokernel of $p$, which is $M\\otimes_R N$.\n\nThe check that it's well-defined goes like this. I call this the fundamental theorem of homological algebra.\n\\begin{theorem}[Fundamental theorem of homological algebra]\nLet $f:M\\to N$ be an $R$-module homomorphism. Let $\\cdots\\to E_1\\to E_0\\to M\\to 0$ be such that each $E_n$ is free, and $\\cdots\\to F_1\\to F_0\\to N\\to 0$ is exact. The fundamental theorem says that I can lift the map $f:M\\to N$ to a chain map $E_\\bullet\\to F_\\bullet$ (i.e. they commute with the differentials and the augmentations $\\epsilon_N:F_0\\to N$ and $\\epsilon_M:E_0\\to M$), that is unique up to chain homotopy. I.e., they sit in the following commutative diagram:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & E_2\\ar[r]\\ar@{-->}[d]^{f_2} & E_1\\ar[r]\\ar@{-->}[d]^{f_1} & E_0\\ar[r]^{\\epsilon_M}\\ar@{-->}[d]^{f_0} & M\\ar[d]^f\\ar[r] & 0\\\\\n\\cdots\\ar[r] & F_2\\ar[r] & F_1\\ar[r] & F_0\\ar[r]^{\\epsilon_N} & N\\ar[r] & 0}\n\\end{equation*}\n\\end{theorem}\nI'm making a big deal about homological algebra in this course on algebraic topology, because this really is a homotopy-theoretic statement. It's part of the homotopy theory of chain complexes. I just want to mention something.\n\\begin{definition}\nA projective $R$-module $P$ is something such that there's a lift:\n\\begin{equation*}\n\\xymatrix{ & M\\ar@{->>}[d]\\\\\nP\\ar@{-->}[ur]\\ar[r] & N}\n\\end{equation*}\n\\end{definition}\nEvery free module is projective, clearly. Anything that's a direct summand in a projective is also projective. Any projective module is a direct summand of a free module.\n\\begin{example}\nLet $k$ be a field. Then $k\\times k$ acts on $k$ via $(a,b)c=ac$. This is an example of a projective that isn't free.\n\\end{example}\n\\begin{remark}\nThis proof uses only that $E_n$ is projective. But if you have a PID, there's no difference between projective and free.\n\\end{remark}\n\\begin{proof}[Proof of the fundamental theorem of homological algebra]\nLet's try to construct $f_0$. Consider:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & K_0\\ar[r]\\ar@{-->}[d]^{g_0} & E_0\\ar[r]^{\\epsilon_M}\\ar@{-->}[d]^{f_0} & M\\ar[d]^f &\\\\\n0\\ar[r] & L_0=\\ker(\\epsilon_N)\\ar[r] & F_0\\ar@{->>}[r]^{\\epsilon_N} & N\\ar[r] & 0}\n\\end{equation*}\nWe know that $E_0=R\\langle S\\rangle$. What we do is push forward the generators of $E$ via $\\epsilon_M$, push it forward to $f$, and pull it back via $\\epsilon_N$ which makes sense because it's surjective. This gives us $f_0$. You can restrict it to get $g_0$. Now I'm in exactly the same situation.\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & K_1\\ar[r]\\ar@{-->}[d]^{g_1} & E_1\\ar[r]^{\\epsilon_M}\\ar@{-->}[d]^{f_1} & K_0\\ar[d]^{g_0} &\\\\\n0\\ar[r] & L_1\\ar[r] & F_1\\ar[r] & L_0\\ar[r] & 0}\n\\end{equation*}\nAnd $g_1$ exists. Now we need to prove the chain homotopy claim. Suppose I have $f_\\bullet:E_\\bullet\\to F_\\bullet$ and $f^{\\prime}_\\bullet:E_\\bullet\\to F_\\bullet$. Then $f^\\prime_n-f_n$ (which we'll rename $\\ell_n$) is a chain map lifting $0:M\\to N$. Let's rename things, so I have:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar[r] & E_2\\ar[r]\\ar[d]^{\\ell_2} & E_1\\ar[r]\\ar[d]^{\\ell_1} & E_0\\ar[r]^{\\epsilon_M}\\ar[d]^{\\ell_0} & M\\ar[d]^0\\ar[r] & 0\\\\\n\\cdots\\ar[r] & F_2\\ar[r] & F_1\\ar[r] & F_0\\ar[r]^{\\epsilon_N} & N\\ar[r] & 0}\n\\end{equation*}\nWe want that $\\ell_\\bullet\\simeq 0$. That is, we want $h:E_n\\to F_{n+1}$ such that $dh+hd=\\ell$. To begin with, we consider:\n\\begin{equation*}\n\\xymatrix{ & E_0\\ar[d]^{\\ell_0}\\ar@{-->}[dl]^h & \\\\\nF_1\\ar[r]^d & F_0}\n\\end{equation*}\nAt the beginning, we want $dh=0$. Well, we consider:\n\\begin{equation*}\n\\xymatrix{ & & E_0\\ar[d]^{\\ell_0}\\ar[dl]\\ar@{-->}[dll] & \\\\\nF_1\\ar@{->>}[r] & L_0\\ar[r] & F_0}\n\\end{equation*}\nBecause $F_1\\to L_0$ is a surjection, the lift exists, and we have $dh=\\ell_0$. For the next step, we have:\n\\begin{equation*}\n\\xymatrix{ & & E_1\\ar[r]\\ar[d]^{\\ell_1}\\ar@{-->}[dll] & E_0\\ar[d]^{\\ell_0}\\ar[dl]^h & \\\\\nF_2\\ar@{->>}[r] & L_1\\ar[r] & F_1\\ar[r]^d & F_0}\n\\end{equation*}\nSo what do I want to do here? Ultimately what I want is that $dh=\\ell_1-hd$. Well, $d(\\ell_1-hd)=d\\ell_1-dhd=d\\ell_1-\\ell_0d=0$ where the last equality comes because $\\ell$ is a chain map. So now we can use exactness of $E_\\bullet$ to define $h$. Exactly the same process continues.\n\\end{proof}\nThat's it. We're going to use this several times. I'm glad to have mentioned the notion of projectivity, because we'll use it later. Now, apply $M\\otimes_R -$ to that resolution (???). Suppose I have $f:N\\to N^\\prime$, and get a map $f_\\bullet:F_0\\to F^\\prime_\\bullet$. Apply $M\\otimes_R -$ to this, to get a chain map $M\\otimes_R F_\\bullet\\to M\\otimes_R F^\\prime_\\bullet$ to get a map in homology $ H_\\ast(M\\otimes_R F_\\bullet)\\to H_\\ast(M\\otimes_R F^\\prime_\\bullet)$. How independent is this of the lifting that I chose? Suppose I have two chain maps $1\\otimes f_0,f\\otimes f_0^\\prime:M\\otimes_R F_\\bullet\\to M\\otimes_R F^\\prime_\\bullet$. I can certainly form $1\\otimes h:M\\otimes_R F_n\\to M\\otimes_R F^\\prime_{n+1}$. I know that $dh+hd=f-f^\\prime$. When I tensor, I get $1\\otimes(hd+dh)=1\\otimes(f-f^\\prime)$. But I want that $(1\\otimes h)(1\\otimes d)+(1\\otimes d)(1\\otimes h)=1\\otimes f-1\\otimes f^\\prime$. We use a further property of the tensor product:\n\\begin{enumerate}\n\\setcounter{enumi}{7}\n\\item If $f,f^\\prime:N\\to N^\\prime$, then $1\\otimes(f+f^\\prime)=1\\otimes f+1\\otimes f^\\prime:M\\otimes_R N\\to M\\otimes_R N^\\prime$, and $1\\otimes(rf)=r(1\\otimes f)$. And $M\\otimes_R -$ is an $R$-linear functor. \n\\end{enumerate}\nThere's things called derived functors. In more general cases, you can't use chain complexes, but rather you use simplicial resolutions. There's non-additive homological algebra. Anyway, you check that $1\\otimes f$ and $1\\otimes f^\\prime$ are indeed chain homotopic, and so you're done.\n\nI think I've verified that it's well-defined and functorial. What about the lexseq? Now, I start with a sexseq and want to get an lexseq. Suppose I have a sexseq $0\\to A\\to B\\to C\\to 0$. I should first come up with an sexseq of resolutions. Consider:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & A\\ar[r] & B\\ar[r] & C\\ar[r] & 0\\\\\n & F^\\prime_0\\ar[u] & & F^{\\prime\\prime}_0\\ar[u] & \\\\\n & F^\\prime_1\\ar[u] & & F^{\\prime\\prime}_1\\ar[u] & \\\\\n & \\vdots\\ar[u] & & \\vdots\\ar[u] & }\n\\end{equation*}\nI want to get a free resolution in the middle. The only thing that I can think of doing is constructing:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & A\\ar[r]^i & B\\ar[r] & C\\ar[r] & 0\\\\\n0\\ar[r] & F^\\prime_0\\ar[u]^{\\epsilon_A}\\ar[r] & F^\\prime_0\\oplus F^{\\prime\\prime}_0\\ar@{-->}[u]^{\\epsilon_B}\\ar[r] & F^{\\prime\\prime}_0\\ar[u]^{\\epsilon_B}\\ar[r] & 0 \\\\\n & F^\\prime_1\\ar[u] & & F^{\\prime\\prime}_1\\ar[u] & \\\\\n & \\vdots\\ar[u] & & \\vdots\\ar[u] & }\n\\end{equation*}\nIn fact, it's the only choice because you have a free module and the sexseq splits. If I'm going to make this work, this is the only thing I can do. I need the augmentation, though. We can think of $\\epsilon_B$ as a row vector. The first entry obviously has to be $i\\epsilon$. And, well, there's a lift\\footnote{There's some ambiguity here. I have to make a choice. It might seem that the boundary map is made up of the choices, but it \\emph{isn't}! I haven't proved that. It still needs to be proved.} because $F^{\\prime\\prime}_0$ is a free resolution:\n\\begin{equation*}\n\\xymatrix{0\\ar[r] & A\\ar[r]^i & B\\ar[r] & C\\ar[r] & 0\\\\\n0\\ar[r] & F^\\prime_0\\ar[u]^{\\epsilon_A}\\ar[r] & F^\\prime_0\\oplus F^{\\prime\\prime}_0\\ar@{-->}[u]^{\\epsilon_B}\\ar[r] & F^{\\prime\\prime}_0\\ar[u]^{\\epsilon_B}\\ar@{-->}[ul]^{\\overline{\\epsilon}}\\ar[r] & 0 \\\\\n & F^\\prime_1\\ar[u] & & F^{\\prime\\prime}_1\\ar[u] & \\\\\n & \\vdots\\ar[u] & & \\vdots\\ar[u] & }\n\\end{equation*}\nSo that $\\epsilon_B=[i\\epsilon,\\overline{\\epsilon}]$. This is surjective by the Snake lemma. Consider:\n\\begin{equation*}\n\\xymatrix{& 0 & 0 & 0 & \\\\\n0\\ar[r] & A\\ar[r]^i\\ar[u] & B\\ar[r]\\ar[u] & C\\ar[r]\\ar[u] & 0\\\\\n0\\ar[r] & F^\\prime_0\\ar[u]^{\\epsilon_A}\\ar[r] & F^\\prime_0\\oplus F^{\\prime\\prime}_0\\ar@{-->}[u]^{\\epsilon_B}\\ar[r] & F^{\\prime\\prime}_0\\ar[u]^{\\epsilon_B}\\ar@{-->}[ul]^{\\overline{\\epsilon}}\\ar[r] & 0\\\\\n 0\\ar[r] & K^\\prime_0=\\ker\\epsilon_A\\ar[u]\\ar[r] & K_0\\ar[r]\\ar[u] & K^{\\prime\\prime}_0=\\ker\\epsilon_B\\ar[u]\\ar[r] & 0\\\\\n & 0\\ar[u] & 0\\ar[u] & 0\\ar[u] & }\n\\end{equation*}\nThe bottom row is exact by the $3\\times 3$-lemma. It's why I gave it to you for homework! Anyway, I now have a sexseq of free resolutions $0\\to F^\\prime_\\bullet\\to F_\\bullet\\to F^{\\prime\\prime}_\\bullet\\to 0$. Now I want a sexseq $0\\to M\\otimes_R F^\\prime_\\bullet\\to M\\otimes_R F_\\bullet\\to M\\otimes_R F^{\\prime\\prime}_\\bullet\\to 0$, but I don't know this because $M\\otimes_R -$ isn't exact. It's why we got into the business in the whole place. But $0\\to F^\\prime_\\bullet\\to F_\\bullet\\to F^{\\prime\\prime}_\\bullet\\to 0$ is split. And applying any functor gives a splitting of the sexseq, i.e., $M\\otimes_R -$ sends split sexseqs to (split) sexseq. This means that $0\\to M\\otimes_R F^\\prime_\\bullet\\to M\\otimes_R F_\\bullet\\to M\\otimes_R F^{\\prime\\prime}_\\bullet\\to 0$ also splits. Thus we're done proving the lexseq in $\\Tor$.\n\nThe key idea in homological algebra is that free modules are good.\n", "meta": {"hexsha": "fa495d39862ebe0274457090df61ae1ed58179e9", "size": 10964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-22-more-on-tor.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-22-more-on-tor.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-22-more-on-tor.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": 89.868852459, "max_line_length": 959, "alphanum_fraction": 0.674206494, "num_tokens": 4113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6112864528478053}}
{"text": "\\graphicspath{{Chapter2/Figs/}}\n\n\\section{Natural Gradient descent}\n\n%REPRODUCED WITH SOME MODIFCIATIONS FROM:\n%\thttps://wiseodd.github.io/techblog/2018/03/14/natural-gradient/\n%\tHoffman2013\n%\tAmari1998\n\nThe application of standard gradient descent optimisation to functions that depend on probability distributions (as the KL divergence in in variational inference) has an important limitation, as we will show below. \\\\\n\nConsider the gradient descent optimisation of an ELBO $\\Lagr(\\bfX|\\theta)$, where $\\bfX$ are the hidden variables and $\\theta$ the corresponding parameters. From the definition of a gradient:\n\\[\n\\nabla \\Lagr(\\bfX|\\theta) = \\lim_{h\\to0} \\frac{\\Lagr(\\theta + h) - \\Lagr(\\theta)}{\\|h\\|}\n\\]\nwhere $h$ represents an infinitesimally small positive step in the space of $\\theta$.\\\\\n\nTo find the steepest gradient, one would need to search over all possible directions $d$ in an infinitely small distance $h$, and select the $\\hat{d}$ with the largest gradient:\n\\[\n\\nabla \\Lagr(\\bfX|\\theta) = \\lim_{h\\to0} \\frac{1}{\\|h\\|}\\argmax_{d \\, s.t. \\|d\\|=h} \\Lagr(\\theta+d) - \\Lagr(\\theta)\n\\]\nNotice that the neighborhood of $\\theta$ is measured in terms of its Euclidean norm, and the direction of steepest descent is hence dependent on the Euclidean geometry of the $\\theta$ space. This becomes problematic in variational inference. A small step from $\\theta_t$ to $\\theta^{(t+1)}$ does not guarantee a similar small change from $\\Lagr(\\bfX|\\theta^t)$ to $\\Lagr(\\bfX|\\theta^{(t+1)})$. As an example, consider four random variables:\n\\begin{equation}\n\t\\begin{split}\n\t\t\\psi_1 &\\sim \\Ndist{0}{5} \\\\\n\t\t\\psi_2 &\\sim \\Ndist{10}{5}\n\t\\end{split}\n\t\\qquad\n\t\\begin{split}\n\t\t\\psi_3 &\\sim \\Ndist{0}{1} \\\\\n\t\t\\psi_4 &\\sim \\Ndist{10}{1}\n\t\\end{split}\n\\end{equation}\n\nUsing the euclidean metric, the distance between $\\psi_1$ and $\\psi_2$ is the same as the distance between $\\psi_3$ and $\\psi_4$. However, the distance in distribution space (measured for example by the KL divergence) is clearly much larger between $\\psi_1$ and $\\psi_2$ than between $\\psi_3$ and $\\psi_4$ (Figure X).\n\n\\begin{figure}[]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.75\\textwidth]{rnorm.pdf}\n\t\t\\caption{}\n\t\t\\label{fig:XX}\n\t\\end{center}\n\\end{figure}\n\nHence, rather than using the euclidean distance, it is more appropriate to use a KL divergence as a distance metric:\n\\[\n\t\\nabla \\Lagr(\\bfX|\\theta)_{KL} = \\lim_{h\\to0} \\frac{1}{\\|h\\|}\\argmax_{d \\, s.t. KL[p_\\theta||p_{\\theta+d}]=\\|h\\|} \\Lagr(\\theta+d) - \\Lagr(\\theta)\n\\]\nThe direction of steepest ascent measured by the KL divergence is called the natural gradient.\n\nTo find the optimal $\\hat{d}_{KL}$, one needs to solve the following optimisation problem:\n\\[\n\t\\hat{d}_{KL} = \\argmin_{d} \\Lagr(\\theta+d)\n\\]\nwith the constrain $KL[p_\\theta||p_{\\theta+d}]=c$, where $c$ is an arbitrary constant. Introducing Lagrange multipliers $\\lambda$: \\cite{??}:\n\\[\n\t\\Lagr(\\theta+d) + \\lambda(KL[p_\\theta||p_{\\theta+d}] - c)\n\\]\nBefore taking its derivative, we can simplify the equation by approximating the  term $ \\Lagr(\\theta+d)$ with a First-order Taylor series and the term $KL[p_\\theta||p_{\\theta+d}]$ with a second-order Taylor series around $\\theta+d$:\nTO FINMISH\n\\[\nKL[p_\\theta||p_{\\theta+d}]  \\approx \nKL[p_\\theta||p_{\\theta}] + \n%d \\d nabla_{\\theta+d} KL[(\\bfX|\\theta)||(\\bfX|\\theta+d)] | _{\\theta} +\n%\\frac{1}{2} d^T \\d nabla^2_{\\theta+d} KL[(\\bfX|\\theta)||(\\bfX|\\theta+d)] | _{\\theta}d\n\\]\nThe first two terms vanish. The third term corresponds to the negative of the Hessian matrix with respect to $\\theta+d$ (the Fisher Information Matrix $F$), evaluated at $\\theta$. Hence, the term $KL[p_\\theta||p_{\\theta+d}]$ simplifies to $\\frac{1}{2} d^T F d$\n\nThe equation to optimise becomes:\n\\[\n\\Lagr(\\theta) + \\nabla_{\\theta} \\Lagr(\\theta)^T d + \\frac{1}{2} \\lambda d^T F d - \\lambda c\n\\]\n\nFinally, by taking the derivative of Equation X with respect to $d$, setting to zero and solving, we obtain the direction of the steepest natural gradient. It corresponds to the standard (euclidean) gradient pre-multiplied by the inverse of the Fisher Information Matrix:\n\\[\n%\t\\frac{\\partial \\Lagr(\\theta+d)}{\\partial d} + \\lambda\\frac{\\partial(KL[p_\\theta||p_{\\theta+d}]}{\\partial d} = 0\n\\hat{d} \\propto F^{-1} \\nabla_{\\theta} \\Lagr(\\theta)\n\\]\n\n\nFINISH HERE. CHECK IF THE BOTTOM IS MEANINGFUL:::\n\nPlugging this expression into [[EQUATION XX]], we find that the optimal $d$ is:\n\\[\n\\hat{d} = -\\frac{1}{\\lambda} F(\\theta)^{-1} \\nabla_{\\theta} \\Lagr(\\theta)\n\\]\nThe constatn factor can be absorbed into the learning rate. The natural gradient is then defined\n\\[\n\\nabla \\Lagr(\\bfX|\\theta)_{KL} = F(\\theta)^{-1} \\nabla_{\\theta} \\Lagr(\\theta)\n\\]\n\n\n% \\cite{[[GITHUBPAGE]]} shows how, in a simple logistic regression problem, the use of natural gradients lead to improved convergence over standard gradient descent.", "meta": {"hexsha": "06f3d5da5ea29bda538e02cc8b7b6e7b6097ac86", "size": 4808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/old/natural_gradient_descent.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/old/natural_gradient_descent.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/old/natural_gradient_descent.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": 51.6989247312, "max_line_length": 440, "alphanum_fraction": 0.7036189684, "num_tokens": 1528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597971, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6112864472213941}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\subsubsection{At Index}\nThe operation $atIndex$ will return the Value at a\nspecified numeric index within a Collection or\nan empty Collection if there is no value at the specified index.\n\\begin{schema}{AtIndex[Collection, \\nat]}\n  idx? : \\nat\\\\\n  coll? : Collection \\\\\n  atIndex~\\_ : Collection \\cross \\nat \\surj V\n  \\where\n  \\# ~ idx? = 1 \\\\\n  coll! = atIndex(coll?, idx?) = (head ~(~idx? \\extract coll?)) \\iff idx? \\in coll? \\\\\n  coll! = atIndex(coll?, idx?) = \\langle  \\rangle \\iff idx? \\not \\in coll?\n\\end{schema}\nGiven the definition of the $Collection$ and $V$ free types\n\\begin{zed}\n  Collection :== emptyColl ~| ~append \\ldata Collection \\cross Scalar ~\\lor Collection ~\\lor KV \\cross \\nat \\rdata \\\\\n  V ::= Scalar ~| ~Collection ~| ~KV\n\\end{zed}\nThe collection member $coll?_{idx?} : V$ is implied from $append$ accepting the argument of type $Scalar ~\\lor Collection ~\\lor KV \\equiv V$ which means each Collection member is of type $V$. Given that extraction ($~\\_~\\extract~\\_$) returns a Collection,\n\\begin{axdef}\n  \\seq X : Collection\n  \\where\n  \\_~\\extract~\\_ : \\power \\nat_1 \\cross \\seq X \\fun \\seq X\n\\end{axdef}\nin order for $atIndex$ to return the collection member without altering its type,\nthe first member of $atIdx'$ must be returned, not $atIdx'$ itself.\n\\begin{axdef}\n  atIdx' : Collection \\\\\n  coll!, coll?_{idx?} : V \\\\\n  \\where\n  atIdx' = (~idx? \\extract coll?) \\implies \\langle coll?_{idx?} \\rangle \\\\\n  coll! = head(atIdx') = coll?_{idx?}\n\\end{axdef}\nThe $head$ call is made possible by restricting $idx?$ to be a single numeric value.\n\\begin{argue}\n  idx?, idx' : \\nat \\\\\n  \\t1 \\# ~ idx? = 1 @ (~idx? \\extract coll?) = \\langle coll?_{idx?} \\rangle @ \\\\\n  \\t2 (head (~idx? \\extract coll?)) = coll?_{idx?} & expected return given $idx?$ \\\\\n  \\t1 \\# ~ idx' \\geq 2 @ (~idx' \\extract coll?) = \\langle coll?_{idx'_{i}}~..~~coll?_{idx'_{j}} \\rangle @ \\\\\n  \\t2 (head (~idx' \\extract coll?)) = coll?_{idx'_{i}} & unexpected return given $idx'$\n\\end{argue}\nAdditionally, if the provided $idx? \\not \\in coll?$ then an empty Collection will be returned\ngiven that $head$ must be passed a non-empty Collection.\n\\begin{axdef}\n  head : \\seq_1 X \\fun X\n  \\where\n  idx? \\not \\in coll? \\implies (~idx? \\extract coll?) = \\langle  \\rangle ~ \\lnot ~\\seq_1\n\\end{axdef}\nThe properties of $atIndex$ are illustrated in the following examples.\n\\begin{argue}\n  X = \\langle x_{0}, x_{1}, x_{2} \\rangle \\\\\n  \\t1 x_{0} = 0 \\\\\n  \\t1 x_{1} = foo \\\\\n  \\t1 x_{2} = \\langle a, b, c \\rangle \\\\\n  atIndex(X, 0) = 0 & $head~(\\langle~x_{0}~\\rangle)$\\\\\n  atIndex(X, 1) = foo & $head~(\\langle~x_{1}~\\rangle)$\\\\\n  atIndex(X, 2) = \\langle a, b, c \\rangle & $head~(\\langle~x_{2}~\\rangle)$\\\\\n  atIndex(X, 3) = \\langle  \\rangle & $3 \\not \\in X \\implies x_{3} \\not \\in X$\n\\end{argue}\n\\end{document}\n", "meta": {"hexsha": "453e94f08015339aa892a275c4f860f11a19d919", "size": 2840, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/operations/collections/atIndex.tex", "max_stars_repo_name": "yetanalytics/dave", "max_stars_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-08-17T00:38:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T02:32:37.000Z", "max_issues_repo_path": "docs/operations/collections/atIndex.tex", "max_issues_repo_name": "adlnet/dave", "max_issues_repo_head_hexsha": "9339713fac747118e462e4fc7e1ecd54e5d916e3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2018-08-31T18:57:51.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-15T16:40:01.000Z", "max_forks_repo_path": "docs/operations/collections/atIndex.tex", "max_forks_repo_name": "yetanalytics/dave", "max_forks_repo_head_hexsha": "7a71c2017889862b2fb567edc8196b4382d01beb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-09-28T06:48:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-31T16:20:47.000Z", "avg_line_length": 45.0793650794, "max_line_length": 255, "alphanum_fraction": 0.6433098592, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042768, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6112864461127572}}
{"text": "\\SubSecDef{verify}{Verifying Algebraic Security}\n\n\\PropRef{composability} shows that we can compose algebraically secure circuits. Large circuits can be constructed from a set of \\emph{gadgets} - small algebraically secure circuits with some useful semantics. In order to design new gadgets we need to be able to check their algebraic security. The simplest way to get a bound on the absolute correlation is based on the algebraic degree of computed functions: the minimum weight of a \\emph{nonzero} function of $n$ bits of degree $d$ is equal to $2^{n-d}$ (see e.g. \\cite{Carlet}). Therefore, we can think about the following algorithm for checking a circuit $C(x,r_C)$: for any fixed input $x$ compute the ANFs of the functions computed in $C(x,\\cdot)$ (functions of $r_C$) and return the maximum observed degree. The degree does not grow when functions are combined linearly. Therefore, the absolute correlation bound can not grow as well, except when the resulting function is constant in which case the absolute correlation is maximal and the gadget may be insecure. As a result, our method for verifying algebraic security splits into two parts:\n\n\\begin{enumerate}\n    \\item verify that there is no absolute correlation equal to 1 among restrictions of functions from $\\FUNCSD{1}(C)$ except the constant functions and affine functions of $x$;\n    \\item compute the maximum degree among all restrictions of the intermediate functions and compute the corresponding correlation bound.\n\\end{enumerate}\n\nThe second step is straight-forward. We describe an algorithm that solves the first step.\n\nConsider a circuit $C(x,r): \\field{N}\\times\\field{R}\\to\\field{M}$.\nFor all $c \\in \\field{N}$ let $L_c$ be the linear map that returns the restriction $x=c$ of a function $f$ from $\\FUNCSD{1}(C)$ (e.g. if functions are represented as truth table vectors then $L_c$ returns the truth table entries corresponding to the case $x = c$). Note that the domain of $L_c$ is defined to be the subspace $\\FUNCSD{1}(C)$.\n\nWe now give an equivalent condition for the first part of the verification. It serves as a basis for the verification algorithm given in \\AlgRef{verify}.\n\n\\begin{proposition}\nThe circuit $C$ is $\\maxcor$-1-AS for some $\\maxcor < 1$ if and only if for all $c$ the following holds:\n\\begin{equation}\n    \\dim{\\ker{L_c}} = N.\n\\end{equation}\n\\end{proposition}\n\\begin{proof}\nFor any $c \\in \\field{N}$ let $F_c$ be the subspace of $\\FUNCSD{1}(C)$ containing functions that are constant when $x$ is fixed to $c$. Also let $F = \\bigcup_c F_c$.\n$\\maxcor < 1$ requires that any $f\\in \\FUNCSD{1}(C)$ either belongs to $\\XFUNCSD{1}(C)$ or is non-constant for any fixed $x$. It is equivalent to require that $F$ is equal to $\\XFUNCSD{1}(C)$. Note that each $F_c$ includes $\\XFUNCSD{1}(C)$ as a subset. Therefore, $F = \\bigcup_c F_c$ is equal to $\\XFUNCSD{1}(C)$ if and only if for all $c$ $F_c = \\XFUNCSD{1}(C)$. Since these are linear subspaces then we can compare their dimensions.\n\n$\\XFUNCSD{1}(C)$ is spanned by all $x_i$ and the constant-1 function:\n\\eql{prop-algo-dimX}{\n    \\dim{\\XFUNCSD{1}(C)} = N + 1;\n}\n\nThe constant-1 function always belongs to $\\FUNCSD{1}(C)$ and to any of the $F_c$. The subspace of functions that are constant on the restriction can be obtained by adding the constant-1 function to the subspace of functions that are equal to zero on the restriction:\n\\eql{xxx}{\n    F_c &= \\ker{L_c} \\oplus \\pset{\\fzero,\\fone}, \\\\\n    \\EqLabel{prop-algo-dimFc}\n    \\dim{F_c} &= \\dim{\\ker{L_c}} + 1.\n}\n\nBy comparing the dimensions obtained in \\EqRef{prop-algo-dimX},\\EqRef{prop-algo-dimFc} we prove the proposition.\n\\end{proof}\n\n\n\\newcommand\\tbas{\\bas_c}\n\nThe algorithm operates on functions using their truth tables. The truth tables are obtained by evaluating the circuit on all possible inputs and recording the values computed in each node. The set of computed truth tables corresponds to $\\FUNCS(C)$. By removing redundant vectors we can compute a basis $\\bas$ of $\\FUNCSD{1}(C)$ (and also ensure presence of the constant-1 vector). Then, for each $c$ we take the part of each basis vector that corresponds to the fixed $x=c$ (and $r$ taking all possible values). These parts form the subspace $\\Ima{L_c}$. We compute a basis $\\tbas$ of these parts. Finally, we verify that\n\\begin{equation}\n    \\dim{\\ker{L_c}} = \\dim{\\FUNCSD{1}(C)} - \\dim{\\Ima{L_c}} = |\\bas| - |\\tbas| = N.\n\\end{equation}\n\n\\FigTex{algo-verify.tex}\n\nThe algorithm is implemented in SageMath~\\cite{sage} and is publicly available in~\\cite{OurWhiteboxCode}.\n\n\\paragraph{Complexity analysis.}\nThe truth tables have size $2^{N+R}$ bits. Computing the basis of $\\FUNCSD{1}(C)$ takes time $\\OO(min(2^{N+R}, |C|)^\\matexp)$. The same holds for $\\Ima{L_c}$ except that the vectors have size $2^{R}$ and for small $R$ this can be done more efficiently. The total complexity is $\\OO(min(2^{N+R}, |C|)^\\matexp + 2^N min(2^{R}, |C|)^\\matexp)$. Recall that by Proposition~\\ref{wba.prop:nonlinear-gates} we should consider only the nonlinear nodes of the circuit. \n\n\n", "meta": {"hexsha": "b5f3f359b65a61a107eab8021f34143f42e3bbcb", "size": 5029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9wbCounter/34verify.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/9wbCounter/34verify.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/9wbCounter/34verify.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": 86.7068965517, "max_line_length": 1101, "alphanum_fraction": 0.7341419765, "num_tokens": 1407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6112864438122567}}
{"text": "\\section{Network Level Performance Without Retransmission}\n\\label{sec:op_over_infinite_plane}\nThe transmission success probability $p_s(r)$ paves the way to analyze the network packet loss rate $P_{f}$, which is the base to calculate:\\begin{inparaenum}[1)]\n\t\\item the maximum normalized load $L_{\\text{max}}$ under packet loss rate constraint $P_{f}^{\\text{max}}$;\n\t\\item the normalized spatial throughput (per BS) $S = (1-P_{f}) p\\lambda_{m}/ \\lambda_{b}$\n\\end{inparaenum}\nWe first consider two standard ALOHA transmission approaches in unicast mode (best and nearest BS attach) and then analyze the macro diversity case. For macro diversity case, we also consider two cases: selective ratio and maximum ratio combing.\n\\subsection{Nearest BS attach method}\n\\label{sec:nearest_BS_attach_method}\n%A device can attach to the best BS which the received power of packet transmission is the strongest if the channel state info is available during the communication.\nIn this subsection, we assume that the device attaches to the geographically nearest BS then transmits packets. \n%This method is rational when downlink is seldom used for the sake of cost. %TODO: Add this in cover letter.\nTherefore, network packet loss rate $P_{f,n}$ (index $n$ means nearest) is the expectation of $p_s(r)$ with respect to the distance to the nearest base station $r$ . The PDF of $r$ for a PPP, proved in~\\cite{andrews2011tractable}, is as follows:\n\\begin{align}\n\\label{eq:pdf_nearest_distance}\nf\\left( r\\right)  = 2 \\pi \\lambda_b  r \\exp(-\\lambda_b \\pi r^2), r \\in \\left[ 0, +\\infty\\right]. \n\\end{align}\nThus:\n\\begin{align}\n\\label{eq:mean_bx+1_step1}\n&P_{f,n}= \\mathbb{E}_{r}\\left[ 1-p_{s}\\left(r\\right) \\right]  \\nonumber\\\\\n&= 1 -\\int_{0}^{+\\infty} \\mathbb{E}_{\\chi} \\left[ \\exp(-p \\lambda_{m} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  r^2 e^{-\\frac{2}{\\gamma}\\chi}) \\right] 2 \\pi \\lambda_b  r e^{-\\lambda_b \\pi r^2} dr \\nonumber\\\\\n&= 1-\\pi \\lambda_b \\mathbb{E}_{\\chi}\\left[ \\int_{0}^{+\\infty} \\exp(-p \\lambda_{m} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  r^2 e^{-\\frac{2}{\\gamma}\\chi}-\\lambda_b \\pi r^2)\\right] \\!\\!dr^2 \\nonumber\\\\\n&= 1 -\\mathbb{E}_{\\chi}\\left[\\left( A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}} L  e^{-\\frac{2}{\\gamma}\\chi}+1 \\right)^{-1} \\right] \\nonumber\\\\\n%&= 1- \\int_{-\\infty}^{+\\infty} \\frac{1}{ \\frac{p\\lambda_{m}AK}{\\pi \\lambda_{b}}e^t+1}\\frac{\\exp\\left\\lbrace -\\frac{t^2}{2 \\left( \\frac{2}{\\gamma}\\sigma\\right) ^2}\\right\\rbrace }{\\sqrt{2\\pi} \\frac{2}{\\gamma}\\sigma} dt \\nonumber\\\\\n&= 1 - \\int_{-\\infty}^{+\\infty} \\!\\!\\! \\frac{\\gamma}{ 2\\sqrt{2\\pi}\\left( e^t+1\\right)\\sigma} \\exp \\left\\lbrace -\\frac{\\gamma^2}{8 \\sigma^2} \\left(    t-\\ln(A L \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\!\\! \\frac{2\\sigma^2}{\\gamma^2}} )   \\right) ^2 \\right\\rbrace dt.  \n\\end{align}\n%which is actually a logistic-normal integral. According to~\\cite{crooks2009logistic}, this kind of \nIntegral in $(\\ref{eq:mean_bx+1_step1})$ can be accurately approximated by a logistic function~\\cite{crooks2009logistic}. Thus,\n\\begin{align}\n\\label{eq:bs_nst_att_analytical}\nP_{f,n} \n&\\approx 1 - \\frac{1}{1 + \\exp\\left\\lbrace \\left( 1 +\\pi \\sigma^2 / (2\\gamma^2) \\right)^{-1/2} \\ln( A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  L) \\right\\rbrace}  \\nonumber\\\\\n&\\approx 1-\\frac{ 1 }{ 1 + \\left( A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  L\\right) ^{C} }\n\\end{align}\nwhere $A$ is defined in $(\\ref{eq:def_ps_2})$, $L=p\\lambda_{m}/\\lambda_{b}$, $C= \\left( 1 +\\pi \\sigma^2 / (2\\gamma^2) \\right)^{-1/2}$. We conducted a Monte-Carlo simulation and found that the maximum difference between $(\\ref{eq:mean_bx+1_step1})$ and $(\\ref{eq:bs_nst_att_analytical})$ is $2.46\\%$ in normalized load interval $\\left[ 0.021, 0.3\\right] $, which proves the accuracy of the proposed approximation formula $(\\ref{eq:bs_nst_att_analytical})$\\qsong{Remember to put the figure into Annexe part. Here I wan to show that, the difference between approximation formula and exact integral is smaller when normalized load increase }.\n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[width=\\linewidth]{/Users/qsong/Documents/slotted_aloha_related_project/test/comparison_monte_carlo_approximation.eps}\n\t\\caption{Comparison between approximation formula $(\\ref{eq:bs_nst_att_analytical})$ and Monte-Carlo simulation result.}\n\t\\label{fig:comparison_monte_carlo}\n\\end{figure}\n\nFrom $(\\ref{eq:bs_nst_att_analytical})$,  the maximum supported normalized load $L_{\\text{max},n}$ and normalized spatial throughput (index $n$ refers to the nearest BS attach method) is obtained:\n\\begin{align}\n\\label{eq:bs_nst_att_max_load}\nL_{\\text{max},n} &= \\frac{1}{A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}} } \n\\left(  \\frac{P_{f}^{\\text{max}}}{1 - P_{f}^{\\textbf{max}}} \\right) ^{\\frac{1}{C}}, \\\\\n\\label{eq:bs_nst_att_spatial_throughput}\nS_{n} &=  \\frac{L}{1 + \\left( A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  L\\right) ^{C} }.\n\\end{align}\n%We should note that $(\\ref{eq:bs_nst_att_spatial_throughput})$ is obtained by $S = (1-P_{f}) p\\lambda_{m}/ \\lambda_{b}$, where $P_{f}$ is a ... This comment is applied to all spatial throughput in BS attach case.\n\n\\subsection{Best BS attach method}\nIn this subsection, we assume that the device attaches to the BS for which the received power averaged over all fading realizations is the strongest (i.e. the BS that maximizes $r^{-\\gamma}\\exp(\\chi)$). Let $P_{f,b} $ be packet loss rate for this case. As shown in~\\cite[lemma 1]{dhillon2014downlink},  attaching to the best BS in a PPP of intensity $\\lambda_{b}$ with shadowing is equivalent to attaching the nearest one in a transformed PPP of intensity $\\lambda_{b} \\mathbb{E}\\left[ e^{-\\frac{2}{\\gamma}\\chi}\\right] = \\lambda_{b} e^{\\frac{2\\sigma^2}{\\gamma^2}}$ without shadowing. \nTherefore, the link level transmission success probability $p_{s}(r)$ is as follows:\n\\begin{align}\n\t\\label{eq:succ_proba_with_modified_r}\n\tp_{s}(r) = \\exp(-p \\lambda_{m} \\pi A e^{\\frac{2\\sigma^2}{\\gamma^2}} \\theta_{T}^{\\frac{2}{\\gamma}} r^2 )\n\\end{align}\nThe distribution of modified $r$ is thus:\n\\begin{align}\n\t\\label{eq:pdf_modified_r}\n\tf(r) = 2 \\pi \\lambda_b e^{\\frac{2\\sigma^2}{\\gamma^2}}  \\exp( -\\lambda_b  e^{\\frac{2\\sigma^2}{\\gamma^2}} \\pi r^2 ) r \n\\end{align}\nSimilar to the analysis in Sec.~\\ref{sec:nearest_BS_attach_method}, we have:\n\\begin{align}\n\\label{eq:bs_best_att_analytical}\n&P_{f,b}= \\mathbb{E}_{r}\\left[ 1-p_{s}\\left(r\\right) \\right]  \\nonumber\\\\\n&= 1 -\\int_{0}^{+\\infty}  \\exp(-p \\lambda_{m} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  r^2 )  2 \\pi \\lambda_b e^{\\frac{2\\sigma^2}{\\gamma^2}}  \\exp( -\\lambda_b  e^{\\frac{2\\sigma^2}{\\gamma^2}} \\pi r^2 ) r dr \\nonumber\\\\\n&= 1-\\frac{1}{ 1 +  A \\theta_{T}^{\\frac{2}{\\gamma}} L }.\n\\end{align}\nBy inverting $(\\ref{eq:bs_best_att_analytical})$, the maximum supported normalized load $L_{\\text{max}, b}$ (subscript $b$ refers to the best BS attach method) is as follows:\n\\begin{align}\n\tL_{\\text{max},b} &=\\frac{1}{A \\theta_{T}^{\\frac{2}{\\gamma}}  } \n\t\\frac{P_{f}^{\\text{max}}}{1 - P_{f}^{\\textbf{max}}}. \n\\end{align}\nThe normalized spatial throughput $S_{b}$ is as follows:\n\\begin{align}\n\tS_{b} =  \\frac{L}{1 +  A  \\theta_{T}^{\\frac{2}{\\gamma}} L }.\n\\end{align}\n\n\\subsection{Selective Combining like Macro Diversity}\n\\label{sec:sc_macro_diversity}\nSince a transmitted packet is received by all surrounding BS, the transmission of this packet fails if and only if the received SINR at each BS is less than the capture ratio. In other words, if the maximum SINR is still less than the capture ratio, the packet transmission is failed. This is why such a scheme is called selective combining (SC) like macro reception diversity. In this section, we evaluate SC-like macro diversity in one-shot random access case.\n\nStrictly speaking, the cumulative interferences at two different BS are correlated: when a device is transmitting, it generates some non-negligible interference on base stations that are not very far. However, it is still rational to assume that the interferences received by different BS are mutually independent.\n%when received power at each BS exhibits obvious diversity such as in urban area suffered by strong shadowing effect. \nThe reasons are in twofold:\\begin{inparaenum}[1)]\n\t\\item the interference correlation coefficient is shown to be close to $0$ if locations of two BS are different with path-loss model $r^{-\\gamma}$~\\cite[lemma 3.5]{haenggi2009interference}; \n\t\\item Each contribution to the cumulative interference is affected by fading and shadowing, which are i.i.d. random variable for different base stations.\n\\end{inparaenum}\nThus, the packet loss rate $P_{f,m}$ (index $m$ refers to macro reception diversity) is the expectation of the product of failure probabilities to each BS:\n\\begin{align}\n\\label{eq:definition_pfm}\nP_{f,m} &= \\mathbb{E}\\left[  \\prod_{r_i \\in \\Phi_{b}} (1-p_{s}(r_i)) \\right], \\text{with } r_i \\in \\left[0, +\\infty\\right],\n\\end{align} \nwhere $r_i$ is the distance between the device and BS with label $i$. Using Campbell theorem for  $(\\ref{eq:definition_pfm})$:\n\\begin{align}\n\\label{eq:bs_rx_divers_analytical_before_last}\nP_{f,m} &= \\exp\\left\\lbrace -2\\pi \\lambda_{b} \\int_{0}^{+\\infty} p_{s}(r)rdr \\right\\rbrace.\n\\end{align} \nCombining with $(\\ref{eq:def_ps_2})$ and changing integration order, $(\\ref{eq:bs_rx_divers_analytical_before_last})$ can be further simplified:\n\\begin{align}\n\\label{eq:bs_rx_divers_analytical}\nP_{f,m} \n%&= \\exp\\left\\lbrace -\\left[A \\theta_{T}^{\\frac{2}{\\gamma}} L \\right] ^{-1}\\right\\rbrace.\n&= \\exp\\left\\lbrace -\\frac{1}{A \\theta_{T}^{\\frac{2}{\\gamma}} L }\\right\\rbrace.\n\\end{align}\nFrom $(\\ref{eq:bs_rx_divers_analytical})$, we can easily find the maximum load and the throughput:\n\\begin{align}\n\t\\label{eq:bs_rx_divers_max_load}\n\tL_{\\text{max}, m} &= \\frac{1}{A \\theta_{T}^{\\frac{2}{\\gamma}}} \\frac{1}{\\ln(1/P_{f}^{\\text{max}})}, \\\\\n\t\\label{eq:bs_rx_divers_spatial_throughput}\n\tS_{m} &= L \\left(1 -\\exp\\left\\lbrace -\\frac{1}{A \\theta_{T}^{\\frac{2}{\\gamma}} L } \\right\\rbrace \\right). \n\\end{align}\nThe macro diversity gain against the best BS attach mode $G_{\\text{diversity},b}$ is obtained by inverting $(\\ref{eq:bs_best_att_analytical})$ and $(\\ref{eq:bs_rx_divers_analytical})$:\n\\begin{align}\n\t\\label{eq:macro-diversity-gain}\n\tG_{\\text{diversity},b} &= \\left(1-P_{f}^{\\text{max}}\\right)/ \\left( P_{f}^{\\text{max}} \\ln(1/P_{f}^{\\text{max}}) \\right) .\n\\end{align}\nWe deduce that, whatever the ALOHA type, the macro diversity gain against best BS attach\nonly depends on the packet loss rate target.\n\n\\subsection{Maximum Ratio Combining based Macro diversity}\nDue to the fact that a transmitted packet theoretically can be simultaneously received by all BS (ignorance of background noise), linear combining of signals at each BS can be leveraged so that the output SINR is maximized. Such a scheme is called Maximum Ratio Combining (MRC) based macro diversity\nIn this section, the performance of MRC-based macro diversity in case of one-shot random access is evaluated.\n\nConsider a typical device $x_0$ at origin, it has been proved that if the weigh factors involved in MRC context is well designed (see Fig.~\\ref{fig:mrc_macro_diversity_recpetion_illustration}), the output $\\text{SINR}$ $\\Theta$ of best combiner is expressed as \\qs{We need a reference for this...}:\n\\begin{align}\n\\Theta &= \\sum_{y_j \\in \\Phi_{b}}^{} \\theta_{y_j} \\nonumber\\\\\n&= \\sum_{y_j \\in \\Phi_{b}}^{} \\frac{H_{y_j} \\exp(\\chi_{y_j}) r_{y_j}^{-\\gamma}}{I_{y_j}} \\nonumber\\\\\n&= \\sum_{y_j \\in \\Phi_{b}}^{} \\epsilon_{y_j} r_{y_j}^{-\\gamma}\n\\end{align}\nwhere $\\theta_{y_j}$ is the received SINR at BS $y_j$, $H_{y_{j}}$ and $\\exp(\\chi_{y_j})$ are respectively the Rayleigh fading and shadowing component for link between device $x_0$ and BS $y_j$, $I_{y_j}$ refers to cumulative interference suffered at BS $y_j$. For the sake of notation simplicity, let $\\epsilon_{y_j}  = H_{y_j}\\exp(\\chi_{y_j})  / I_{y_j}$. Using similar justification explained in Sec.~\\ref{sec:sc_macro_diversity}, $\\epsilon_{y_j}$ for $j=0,1,2,...$ constitute a series of RV whose element is assumed to be identically independently distributed. \n\nLet $P_{f, \\text{MRC}}$ be the network level packet loss rate in this case. According to capture effect:\n\\begin{align}\n\tP_{f, \\text{MRC}} &= \\mathbb{P} \\left\\lbrace \\Theta < \\theta_{T} \\right\\rbrace \\nonumber \\\\\n\t&= F_{\\Theta} (\\theta_{T}),\n\\end{align}\nwhere $\\theta_{T}$ is the capture ratio, $F_{\\Theta} (\\theta)$ is the CDF of $\\Theta$. It is can be numerically computed from Laplace Transform or Characteristic function of $\\Theta$.\n\nThe Laplace Transform (LT) of $\\Theta$ is by definition as follows\\qsong{To be more restrict, we should explain why we can remove the subscript $y_i$ in the following formula}:\n\\begin{align}\n\\label{eq:lt-sinr-mrc-1}\n\\mathcal{L}_{\\Theta}\\left( s \\right) &= \\mathbb{E}\\left[ e^{-s\\Theta}\\right] \\nonumber\\\\\n&=\\mathbb{E}\\left[ \\exp( -s \\sum_{y_j \\in \\Phi_{b}}^{} \\theta_{y_j} )\\right] \\nonumber\\\\\n&= \\mathbb{E}\\left[ \\prod_{y_j \\in \\Phi_b}^{} \\mathbb{E}_{\\epsilon} \\left[ \\exp( -s \\epsilon r_{y_{j}}^{-\\gamma}) \\right] \\right] \n\\end{align}\nActually, the mathematical operations for interference analysis used in~\\cite{haenggi2009interference} can be reused for $\\eqref{eq:lt-sinr-mrc-1}$. For the sake of clarity, we detail the operations as follows:\n \nApplying Campbell theorem to $\\eqref{eq:lt-sinr-mrc-1}$ and changing the order of integration and expectation operator, we have:\n\\begin{align}\n\\label{eq:lt-sinr-mrc-2}\n\\mathcal{L}_{\\Theta}\\left( s \\right) &= \\exp \\left\\lbrace -\\int_{0}^{+\\infty}    \\mathbb{E}_{\\epsilon}\\left[ 1-\\exp(-s\\epsilon r^{-\\gamma} ) \\right]   2 \\pi \\lambda_{b} r dr \\right\\rbrace \\nonumber\\\\\n&= \\exp \\left\\lbrace -\\mathbb{E}_{\\epsilon}\\left[ \\int_{0}^{+\\infty} \\left(1-\\exp(-s\\epsilon r^{-\\gamma} ) \\right) 2 \\pi \\lambda_{b} r dr  \\right]   \\right\\rbrace \n\\end{align}\n\nLet us focus on the integral $D = \\int_{0}^{+\\infty} \\left(1-\\exp(-s\\epsilon r^{-\\gamma} ) \\right) 2 \\pi \\lambda_{b} r dr $:\n\\begin{align}\n\\label{itg:D}\nD &= \\int_{0}^{+\\infty} \\left(1-\\exp(-s\\epsilon r^{-\\gamma/2} ) \\right) \\pi \\lambda_{b} dr \\nonumber\\\\\n&\\overset{\\mathclap{\\strut\\text{(a)}}} = \\pi \\lambda_{b} \\int_{0}^{+\\infty} \\left(1-\\exp(-x ) \\right) d\\left( -x^{-\\frac{2}{\\gamma}} (s\\epsilon)^{\\frac{2}{\\gamma}}\\right)  \\nonumber\\\\\n&\\overset{\\mathclap{\\strut\\text{(b)}}}= \\pi \\lambda_{b} \\int_{0}^{+\\infty} \\exp(-x ) x^{-\\frac{2}{\\gamma}} (s\\epsilon)^{\\frac{2}{\\gamma}} dx \\nonumber\\\\\n&= \\pi \\lambda_{b}  (s\\epsilon)^{\\frac{2}{\\gamma}}  \\Gamma (1 - \\frac{2}{\\gamma}),\n\\end{align}\nwhere step $(a)$ is obtained with a change of variable $x = s \\epsilon r^{-\\gamma/2}$, step $(b)$ is achieved via integration by parts, $\\Gamma(\\cdot)$ is gamma function.\n\nCombining $\\eqref{eq:lt-sinr-mrc-2}$ and $\\eqref{itg:D}$ , the Laplace Transform of $\\Theta$ is finally simplified as:\n\\begin{align}\n\\label{eq:lt_Theta}\n\\mathcal{L}_{\\Theta}\\left( s \\right) &= \\exp(-\\lambda_{b} \\pi \\mathbb{E}\\left[ \\epsilon ^{\\frac{2}{\\gamma}} \\right]  \\Gamma(1-\\frac{2}{\\gamma}) s^{\\frac{2}{\\gamma}}),\n\\end{align}\nwhere $\\mathbb{E}\\left[ \\epsilon ^{\\frac{2}{\\gamma}} \\right] $ is:\n\\begin{align}\n\\label{eq:epsilon_fractional_moment}\n\\mathbb{E}\\left[ \\epsilon ^{\\frac{2}{\\gamma}} \\right]  &= \\mathbb{E}\\left[ \\left( H \\exp(\\chi)\\right)  ^{\\frac{2}{\\gamma}} \\right] \\mathbb{E}\\left[ I ^{-\\frac{2}{\\gamma}}\\right] \\nonumber\\\\\n&=\\Gamma(1+\\frac{2}{\\gamma}) \\exp( \\frac{2\\sigma^2}{\\gamma^2}) \\mathbb{E}\\left[ I ^{-\\frac{2}{\\gamma}}\\right] \n\\end{align}\n\nSince the Laplace transform of cumulative interference $I$ can be easily obtained and PDF of $I$ is not always exist except $\\gamma=4$, to compute $\\mathbb{E}\\left[ I ^{-\\frac{2}{\\gamma}}\\right]$ (i.e. negative fractional moment calculation problem), one can consider departure from LT. This is a research subject in applied mathematical domain and planned as our future work. The most straightforward way is to rely on Monte-Carlo method.\n\nWith substitution $s = -i \\omega$ in $\\eqref{eq:lt_Theta}$ , the characteristic function (CF) of $\\Theta$ is as follows:\n\\begin{align}\n\\phi_{\\Theta}\\left( \\omega \\right) &= \\exp(-\\lambda_{b} \\pi \\mathbb{E}\\left[ \\epsilon ^{\\frac{2}{\\gamma}} \\right]  \\Gamma(1-\\frac{2}{\\gamma}) \\exp(-i\\pi/\\gamma) \\omega^{\\frac{2}{\\gamma}}),  \n\\end{align}\nwhere $\\omega \\geq 0$, $i$ is imaginary unit.\n\n\\qsong{This paragraph should be simplified. Since in another Chapter, the same numerical technique should have been presented...}As a continuous random variable, the cumulative distribution function $F_{\\Theta}\\left( \\theta \\right)$ of total SINR $\\Theta$ can be directly derived from its characteristic function $\\phi_{\\Theta}\\left(\\omega\\right)$. Applying mathematical techniques used in finance domain~\\cite{hirsa2012computational}, we seek to calculate the Fourier transform of $e^{-\\eta \\theta} F_{\\Theta}\\left( x \\right)$ where term $e^{-\\eta \\theta}$ is a damping function with $\\eta > 0$. \n\\begin{align}\n\\label{eq:intermediate_formula_1}\n\\int_{-\\infty}^{+\\infty} e^{i\\omega \\theta} e^{-\\eta \\theta} F_{\\Theta}\\left( \\theta \\right) dx = \\frac{1}{\\eta - i\\omega} \\phi_{\\Theta}\\left( \\omega +i\\eta \\right) \n\\end{align}\nApplying Fourier inversion for $\\eqref{eq:intermediate_formula_1}$, we obtain the expression for $F_{\\Theta}\\left( \\theta \\right)$ as follows:\n\\begin{align}\n\\label{eq:pr_c_m_case2}\nF_{\\theta}\\left( \\theta \\right)  &= \\frac{e^{\\eta \\theta}}{2\\pi} \\int_{-\\infty}^{+\\infty} e^{-i \\omega \\theta} \\frac{1}{\\eta - i\\omega} \\phi_{Theta}\\left( \\omega +i\\eta\\right) d\\omega  \\nonumber\\\\\n&= \\frac{e^{\\eta \\theta}}{\\pi} \\Re\\left\\lbrace  \\int_{0}^{+\\infty} e^{-i \\omega \\theta} \\frac{1}{\\eta - i\\omega} \\phi_{\\Theta}\\left( \\omega +i\\eta\\right) d\\omega\\right\\rbrace, \n\\end{align}\nThe packet loss rate $P_{f,\\text{MRC}}$ in case of capture ratio $\\theta_{T}$ can be obtained by substituting $\\theta = \\theta_{T}$ in $\\eqref{eq:pr_c_m_case2}$. The latter can be computed using a single numerical integration.\n\n\n%We need to calculate CDF of $\\Theta$ which is the packet loss rate. However, unlike in Sec.XXX, in general case, no closed-form expression. We rely on numerical method to compute packet loss rate wit low complexity. blabla...\n\n\\subsection{A special case, $\\gamma=4$}\nIn this section, we study a special case where path loss component $\\gamma=4$. Proved in ~\\cite[Eq. 3.17]{haenggi2009interference}, the probability density function of cumulative interference $I$, suffered by device at the origin, in a system without shadowing, is as follows:\n\\begin{align}\nf_{I}(x) = \\frac{p\\lambda_{m}}{4} (\\frac{\\pi}{x})^{\\frac{3}{2}} \\exp(-\\frac{\\pi^4 p^2\\lambda_{m}^2}{16x}), x \\geq 0\n\\end{align}\nAlong side with log-normal shadowing effect, the probability density function of cumulative interference $I$ is obtained just by scaling $\\lambda_{m}$ as $ \\lambda_{m} \\exp(\\frac{\\sigma^2}{8})$:\n\\begin{align}\nf_{I}(x) = \\frac{    p\\lambda_{m}   \\exp(\\frac{\\sigma^2}{8})  }{4} (\\frac{\\pi}{x})^{\\frac{3}{2}} \\exp(    -\\frac{    \\pi^4    p^2\\lambda_{m}^2     \\exp^2(\\frac{\\sigma^2}{8})    }{    16x    }    ), x \\geq 0\n\\end{align} \nHence, the negative fractional moment of $I$ can be calculated:\n\\begin{align}\n\\label{eq:gamma=4_fractional_I}\n\\mathbb{E}\\left[ I ^{-\\frac{1}{2}}\\right] &= \\int_{0}^{+\\infty} x^{-\\frac{1}{2}} f_{I}(x) dx \\nonumber\\\\\n&= \\int_{0}^{+\\infty}  \\frac{    p\\lambda_{m}   \\exp(\\frac{\\sigma^2}{8})  }{4}   \\pi^{\\frac{3}{2}}  x^{-2}  \\exp(    -\\frac{    \\pi^4    p^2\\lambda_{m}^2     \\exp^2(\\frac{\\sigma^2}{8})    }{    16x    }    )  dx \\nonumber\\\\\n&= \\frac{4}{    \\pi^{\\frac{5}{2}}  p\\lambda_{m} \\exp(\\frac{\\sigma^2}{8}) }\n\\end{align}\nWith substitution of $\\eqref{eq:gamma=4_fractional_I}$ into $\\eqref{eq:epsilon_fractional_moment}$,\n\\begin{align}\n\\label{eq:negative_fractonal_epsilon_4}\n\\mathbb{E}\\left[ \\epsilon ^{\\frac{1}{2}} \\right] & = 4\\Gamma(\\frac{3}{2})\\pi^{-\\frac{5}{2}} p^{-1}\\lambda_{m}^{-1}\\nonumber\\\\\n&=2\\pi^{-2} p^{-1}\\lambda_{m}^{-1}\n\\end{align}\nFrom $\\eqref{eq:negative_fractonal_epsilon_4}$ and $\\eqref{eq:lt_Theta}$, we have:\n\\begin{align}\n\\mathcal{L}_{\\Theta}\\left( s \\right) &= \\exp(-\\lambda_{b} \\pi 2\\pi^{-2}\\lambda_{m}^{-1} \\Gamma(\\frac{1}{2}) s^{\\frac{1}{2}}) \\nonumber \\\\\n&= \\exp(-2L^{-1}\\pi^{-\\frac{1}{2}}  s^{\\frac{1}{2}}), \n\\end{align}\nwhich is the Laplace Transform of probability density function of $\\Theta$. According to derivative property of Laplace Transform, the cumulative distribution function $F_{\\Theta} (\\theta) $ of ${\\Theta}$ can be obtained by directly inversing $\\frac{1}{s} \\mathcal{L}_{\\Theta}\\left( s \\right)$.\nWhen $\\gamma = 4$, instead of using numerical integration for $\\eqref{eq:pr_c_m_case2}$, we have closed-form CDF of total SINR $\\Theta$:\n\\begin{align}\nP_{f, \\text{MRC}}  = F_{\\Theta} (\\theta_{T}) \n&= \\mathcal{L}^{-1} \\left[ \\frac{1}{s} \\mathcal{L}_{\\Theta}\\left( s \\right) \\right]  \\nonumber\\\\\n&=1 -\\erf \\left( \n\\frac{1}{ L \\sqrt{\\pi \\theta_{T}}}\n\\right),\n\\end{align}\nwhere $\\mathcal{L} \\left[ \\cdot \\right] $ is inverse Laplace Transform operator.\n%We verify that the packet loss rate obtained by $(?)$ and $(?)$ are the same.\n\\qsong{Don't forget to talk about throughput, macro diversity gain as like what we have done in previous section.}\n\n%============================================================================================\n%\\input{Chapter5/bs_rx_divers_mrc.tex}\n%Macro diversity gain against the nearest BS attach method $G_{\\text{diversity}, n}$ is obtained by multiplying $\\exp \\left( \\frac{\\sqrt{2}\\sigma}{\\gamma}\\right)^2$ to $(\\ref{eq:macro-diversity-gain})$.\n% depends on path-loss exponent $\\gamma $, shadowing standard deviation $\\sigma$ and packet loss rate constraint $P_f^{\\text{max}}$, but has nothing to do with capture ratio.\n\n\n%Old expression for P_f1\n%\\begin{align}\n%\\label{eq:bs_nst_att_analytical}\n%P_{f1} &\\approx 1 -\\frac{1}{1 + \\exp\\left\\lbrace \\left( 1 +\\frac{\\pi \\sigma_X^2}{8} \\right)^{-\\frac{1}{2}} \\ln(B) \\right\\rbrace} \\nonumber\\\\\n%&=1-\\frac{1}{1 + \\left(B\\frac{p\\lambda_m}{\\lambda_b} \\right) ^{\\left( 1 +\\frac{\\pi \\sigma^2}{2\\gamma^2} \\right)^{-\\frac{1}{2}}}}, \\\\\n%L_{\\text{max}} &= \\frac{\\left( \\frac{P_{f1}^{\\text{max}}}{1-P_{f1}^{\\text{max}}}\\right)^{\\left( 1 +\\frac{\\pi \\sigma^2}{2\\gamma^2} \\right)^{\\frac{1}{2}}} }{B},\n%\\end{align}\n\n%&= \\int_{-\\infty}^{+\\infty} \\frac{1}{ e^t+1}\\frac{1}{\\sqrt{2\\pi} \\frac{2}{\\gamma}\\sigma} \\exp\\left\\lbrace -\\frac{1}{2} \\frac{(t-\\ln(\\frac{A}{\\pi \\lambda_{b}}))^2}{\\left( \\frac{2}{\\gamma}\\sigma\\right)^2}\\right\\rbrace dt.\n\n%\\begin{align}\n%\\label{eq:mean_bx+1_step1}\n%&P_{f}= \\mathbb{E}_{r}\\left[ 1-p_{s}\\left(r\\right) \\right]  \\nonumber\\\\\n%&= 1-\\int_{0}^{+\\infty} \\mathbb{E}_{G}\\left[ \\exp(-p\\lambda_{m}AK r^2 e^{-\\frac{2}{\\gamma}G})\\right]  2 \\pi \\lambda_b  r e^{-\\lambda_b \\pi r^2} dr \\nonumber\\\\\n%&= 1-\\pi \\lambda_b \\mathbb{E}_{G}\\left[ \\int_{0}^{+\\infty} \\exp(-p\\lambda_{m} A K r^2 e^{-\\frac{2}{\\gamma}G}-\\lambda_b \\pi r^2)\\right] dr^2 \\nonumber\\\\\n%&= 1 -\\mathbb{E}_{G}\\left[ \\frac{1}{\\frac{AKp\\lambda_{m}}{\\pi \\lambda_{b}}e^{-\\frac{2}{\\gamma}G}+1} \\right] \\nonumber\\\\\n%&\\mathbb{E}_{G}\\left[ \\frac{1}{\\frac{p\\lambda_{m}AK}{\\pi \\lambda_{b}}e^{-\\frac{2}{\\gamma}G}+1} \\right]  = \\int_{-\\infty}^{+\\infty} \\frac{1}{ \\frac{p\\lambda_{m}AK}{\\pi \\lambda_{b}}e^t+1}\\frac{\\exp\\left\\lbrace -\\frac{t^2}{2 \\left( \\frac{2}{\\gamma}\\sigma\\right) ^2}\\right\\rbrace }{\\sqrt{2\\pi} \\frac{2}{\\gamma}\\sigma} dt \\nonumber\\\\\n%&= \\int_{-\\infty}^{+\\infty} \\frac{\\gamma}{ 2\\sqrt{2\\pi}\\left( e^t+1\\right)\\sigma}e^{\\left\\lbrace -\\frac{\\gamma^2}{8 \\sigma^2} (t-\\ln\\frac{AKp\\lambda_{m}}{\\pi \\lambda_{b}})^2\\right\\rbrace} dt.\n%\\end{align}\n\n%$\\lim\\limits_{\\frac{p\\lambda_{m}}{\\lambda_{b} } +\\infty} \\frac{p\\lambda_{m}}{\\lambda_{b}}(1-P_{f2}) =\\frac{1}{\\frac{K}{\\pi}\\Gamma(1+\\frac{2}{\\gamma}) \\theta_{T}^{\\frac{2}{\\gamma}}}$\n\n%The normalized spatial throughput $S$ converges to a limit value $ \\left[ K\\Gamma(1+\\frac{2}{\\gamma})\\theta_{T}^{\\frac{2}{\\gamma}} \\right] ^{-1}\\pi$, which depends on SINR threshold and path loss exponent.\n\n%The analysis in Sec.~\\ref{secsec:nst_bs_att} related to normalized spatial throughput still holds for this case.\n\n%With $\\ref{eq:bs_nst_att_max_load}$, we note that normalized spatial throughput $S$ converges to $(AK)^{-1}\\pi$. It is worth indicating that normalized spatial throughput diverges to infinity when normalized load increases. However, this divergence is caused by the approximation in $(\\ref{eq:bs_nst_att_analytical})$.\n\n%Surely, the best BS attach method always outperforms than the nearest BS attach method. However, we still first consider the nearest BS attach method due to three reasons:\\begin{inparaenum}[1)]\n%\\item nearest BS attach is a widely studied method in stochastic geometry field;\n%\\item nearest BS attach is the only choice when the downlink is not available (or seldom used for cost purpose) for some cheap systems;\n%\\end{inparaenum} \n\n\n\n%As discussed before, $(\\ref{eq:bs_nst_att_analytical})$ is applicable for best BS attach method. To obtain a general result for both methods, we redefine $A$ is redefined as follows:\n%\\[ A=\n%\\begin{cases} \n%\\Gamma(1+\\frac{2}{\\gamma}) \\exp \\left( \\frac{\\sqrt{2}\\sigma}{\\gamma}\\right) ^2 \\theta_{T}^{\\frac{2}{\\gamma}} , & \\text{for Nearest BS attach }\\\\\n%\\Gamma(1+\\frac{2}{\\gamma})\\theta_{T}^{\\frac{2}{\\gamma}} ,  & \\parbox[t]{.4\\columnwidth}{for Best BS attach}\n%\\end{cases}\n%\\]\n\n\n\n%\\begin{align}\n%x & \\\\\n%&\\overset{\\mathclap{\\strut\\text{a}}}= foo\\\\\n%& = bar\n%\\end{align}", "meta": {"hexsha": "60217d3d6a48a34b406d2838f6b51d4ab474e791", "size": 25397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter5/bs_rx_divers_op_plane_oneshot.tex", "max_stars_repo_name": "hansomesong/PhD-Thesis", "max_stars_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_stars_repo_licenses": ["MIT"], "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/bs_rx_divers_op_plane_oneshot.tex", "max_issues_repo_name": "hansomesong/PhD-Thesis", "max_issues_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_issues_repo_licenses": ["MIT"], "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/bs_rx_divers_op_plane_oneshot.tex", "max_forks_repo_name": "hansomesong/PhD-Thesis", "max_forks_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_forks_repo_licenses": ["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.3754152824, "max_line_length": 638, "alphanum_fraction": 0.6824428082, "num_tokens": 8859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6112864415117559}}
{"text": "\\chapter{\\label{ch:math}Mathematical preliminaries}\n\nMany methods and applications of natural language processing require\ntopics from mathematics.\nBeing an interdisciplinary field,\nit is often difficult to assume\nthat all students of computational linguistics possess a (fresh) knowledge of\nsome of the mathematical topics and notation.\nThis chapter provides a highly coarse overview\nof some topics in calculus and linear algebra.\nThe discussion here is incomplete and informal.\nThe interested reader should follow\nthe references provided for in-depth treatments of these subjects.\n\nSection~\\ref{sec:linear-intro} introduces some topics from linear algebra.\nWe will mainly introduce vectors, matrices and operations on vectors and matrices.\nAgain, these topics and notation will be important in discussing\nmany of the machine learning methods.\n\n\nIn Section~\\ref{sec:calculus-intro},\nwe will very briefly revisit derivatives and integrals.\nParticularly, derivatives are used for finding maxima or minima of functions,\nwhich is the basis for many of the machine learning methods.\nThe integrals will also come back in our discussion of some of the machine learning methods,\nparticularly in discussion of probabilistic learning and inference.\n\n\\section{\\label{sec:linear-intro}Linear algebra}\n\nIn many NLP methods,\nwe make heavy use of \\term{vectors} and \\emph{matrices},\nwhich are objects studied in \\emph{linear algebra}.\nVectors are used for representing \\term{features} in many machine learning methods.\nOperations on vectors and matrices also have important applications.\nIn this section we will review some of the properties of vectors and matrices,\nand the operations defined on them.\nIf you had a linear algebra course,\nof if you know, for example, matrix multiplication,\nor dot product of vectors, you can safely skip this section.\n\n\\subsection{Vectors}\n\n\\begin{marginfigure}[5ex]\n  \\tikzsetnextfilename{vector-magnitude-direction}\n  \\begin{tikzpicture}\n    \\draw[->,thick] (0,0) -- (1, 1);\n    \\draw[blue,dotted] (-1,-1) -- (2, 2)\n      node[near end, above,font=\\scriptsize,sloped] {direction};\n    \\node[coordinate] (x) at ($(0.5,0)!(0,0)!(1.5,1)$) {};\n    \\node[coordinate] (y) at ($(0.5,0)!(1,1)!(1.5,1)$) {};\n    \\draw[dotted,gray]  (x) -- (0,0);\n    \\draw[dotted,gray]  (y) -- (1,1);\n    \\draw[<->,dotted,blue]  (x) -- (y)\n      node[midway,below,font=\\scriptsize,sloped] {magnitude};\n  \\end{tikzpicture}\n  \\caption{\\label{fig:single-vector-example}A graphical representation of a vector.}\n\\end{marginfigure}\nA vector is a mathematical object with a magnitude and a direction.\nGraphically, we can represent or visualize a (two-dimensional) vector\nas in Figure~\\ref{fig:single-vector-example}.\nMore commonly,\nwe represent vectors by an ordered list of number,\nsuch as $(1, 0, 1)$.\nA vector defined with $n$ real numbers is said to be in the vector space $\\mathbb{R}^{n}$.\nWe often write a vector of $n$ real numbers (vectors in $\\mathbb{R}^{n}$) as\n$\\vect{v} = (v_{1}, v_{2}, \\ldots, v_{n})$.\nNote that the $\\vect{v}$ that stands for the vector is typeset in boldface font.\nIt can alternatively be marked with a arrow over it, like $\\vec{v}$.\nOther notations for vectors of $n$ numbers include\n$\\vect{v} = \\langle v_{1}, v_{2}, \\ldots, v_{n}\\rangle$ or\n$\\vect{v} = \\begin{bmatrix} v_{1}\\\\ \\vdots\\\\ v_{n}\\\\ \\end{bmatrix}$.\n\n\\begin{marginfigure}[5ex]\n  \\tikzsetnextfilename{example-vectors}\n  \\begin{tikzpicture}[scale=0.7]\n    \\draw[<->,thick] (0, -4) -- (0, 4);\n    \\node[anchor=west] at (0, 4) {y};\n    \\draw[<->,thick] (-4, 0) -- (4, 0);\n    \\node[anchor=south] at (4, 0) {x};\n    \\draw[step=1cm,grid] (-4,-4) grid (4,4);\n    \\draw[thick, ->,red] (0,0) -- (1,1);\n    \\node[anchor=west,red] at (1,1) {$(1,1)$};\n    \\draw[thick, ->,blue] (0,0) -- (1,3);\n    \\node[anchor=west,blue] at (1,3) {$(1,3)$};\n    \\draw[thick, ->,green] (0,0) -- (-1,-3);\n    \\node[anchor=east,green] at (-1,-3) {$(-1,-3)$};\n  \\end{tikzpicture}\n  \\caption{\\label{fig:vector-examples}Example vectors in 2-dimensional Euclidean space.}\n\\end{marginfigure}\nGeometrically, we represent vectors as arrows as in Figure~\\ref{fig:vector-examples}.\nThe individual numbers on the notation represent their projection to the respective axis.\nIn the example on the right,\nfor example,\nthe green and blue vectors have the same magnitude,\nbut their direction is opposite of each other.\nIf we take the projections of the vector to the $x$ and $y$ axes,\nthey correspond to real first and the second number in our notation respectively.\n\nMany operations on (real) numbers have analogues forms for vectors,\nand they are used in many branches of science,\nas well as machine learning and natural language processing.\n\n\\newthought{Vector norms} are\na generalization of the magnitude of a vector.\nA \\term{norm} assigns a non-negative \\emph{length} or \\emph{size} to a vector.\nNorms are used often in many machine learning methods,\nand they are related to distance metrics which by themselves are useful in comparing objects represented as (feature) vectors.%\n\\footnote{The norm of a vector is the distance from its tail to its tip.}\nThe most familiar norm is the Euclidean norm,\nwhich is also known as L2 (or L$^{\\text{2}}$) norm.\nL2 norm of a vector $\\vect{v} = (v_{1}, \\ldots, v_{n})$ is\n\n\\[\n  \\norm{\\vect{v}}_{2} = \\sqrt{v_{1}^{2} + \\ldots + v_{n}^{2}}\\;.\n\\]\n\nThe subscript 2\\ in $\\norm{v}_{2}$ communicates that the norm is L2 norm.\nThe L2 norm is often taken to be the default.\nIf the subscript is omitted then we mean the L2 norm.\nAnother interesting norm for our purposes is the L1 norm,\nwhich is related to the so-called taxi-cab, city-block or Manhattan distance.\nIt is defined as\n\n\\[\n  \\norm{\\vect{v}}_{1} = \\lvert{}v_{1}\\rvert + \\ldots + \\lvert{}v_{n}\\rvert\\;.\n\\]\n\n\\begin{marginfigure}[5ex]\n  \\tikzsetnextfilename{regularization-l1-l2}\n  \\begin{tikzpicture}\n    \\draw[step=1cm,grid] (-1,-1) grid (4,4);\n    \\draw[->,thick] (0, -1) -- (0, 4);\n    \\node[anchor=west] at (0, 4) {y};\n    \\draw[->,thick] (-1, 0) -- (4, 0);\n    \\node[anchor=south] at (4, 0) {x};\n    \\node[anchor=west,red] at (3,3) {$(3,3)$};\n    \\draw[very thick,blue] (0,0) -- (3,3);\n    \\draw[very thick,red,dotted] (0.05,0) -- (3,0) -- (3,0.05) -- (3,3);\n    \\draw[very thick,orange,dotted] (0,0) -- (0,2) -- (1,2) -- (1,3) -- (3,3);\n    \\draw[very thick,green,dotted]\n      (0,0) -- (1,0) -- (1,1) -- (2,1) -- (2,2) -- (3, 2) -- (3,3);\n  \\end{tikzpicture}\n  \\caption{\\label{fig:l1-l2}%\n    Visualizations of L2(solid \\textcolor{blue}{blue})\n    and example L1\n    (dotted \\textcolor{green}{green},\n            \\textcolor{orange}{orange}\n        and \\textcolor{red}{red})\n    norms vector $(3,3)$.}\n\\end{marginfigure}\n\nFigure~\\ref{fig:l1-l2} visualizes the L1 and L2 norms\nin two-dimensional Euclidean space.\nNote that both apply to higher dimensional spaces as well.\nSo for our example,\n\\[ \\norm{(3,3)}_{2} = \\sqrt{3^{2} + 3^{2}} = \\sqrt{18} \\approx 4.24\\]\n\\[ \\norm{(3,3)}_{1} = \\lvert{}3\\rvert + \\lvert{}3\\rvert = 6 \\]\\;.\nLike any other vector operation or property,\nvector norms can be generalized to vectors of any dimension.\n\nThe concept of vector norm\ncan also be generalized to any positive integer $p$\nthe L$_{\\text{p}}$ norm for an n-dimensional vector is defined as\n\n\\[\n  \\norm{\\vect{v}}_{p} = \\left(\n          \\sum_{i=1}^{n} \\lvert{}v_{i}\\rvert^{p}\n        \\right)^\\frac{1}{p}\n\\]\n\nIn this course, we will only work with L1 and L2 norms defined above.\n\n\\newthought{Scalar multiplication} is the operation of\nmultiplying a vector with a scalar\n(for our purposes a scalar is a real number).\nGiven a vector $\\vect{v} = (v_{1},\\ldots, v_{n})$,\nits multiplication with scalar $a$ is defined as\n\n\\[\n  a \\vect{v} = (a v_{1}, \\ldots, a v_{2})\n\\]\n\nMultiplying a vector with a positive scalar,\nchanges its magnitude, `scales' it,\nbut does not change its direction.\nMultiplying a vector with a negative scalar\nreverses the direction of the original vector.\n\n\\begin{marginfigure}[-5ex]\n  \\tikzsetnextfilename{scalar-multiplication}\n  \\begin{tikzpicture}[scale=0.7]\n    \\draw[<->,thick] (0, -4) -- (0, 4);\n    \\draw[<->,thick] (-4, 0) -- (4, 0);\n    \\draw[step=1cm,grid] (-4,-4) grid (4,4);\n%          \\draw[->,line width=1mm, blue!40] (0,0) -- (2,4);\n    \\draw[->,very thick, blue!40] (0,0) -- (2,4);\n    \\node[anchor=north west, blue!40] at (2,4) {$2 \\vect{v}$};\n    \\draw[->,thick,red] (0,0) -- (1,2);\n    \\node[anchor=west, red] at (1,2) {$\\vect{v} = (1,2)$};\n    \\draw[->,thick,green] (0,0) -- (-0.5,-1);\n    \\node[anchor=east, green] at (-0.5, -1) {$-0.5 \\vect{v}$};\n  \\end{tikzpicture}\n  \\caption{\\label{fig:scalar-multipl}%\n    Scalar multiplication.\n  }\n\\end{marginfigure}\n\n\\newthought{Vector addition and subtraction}\nare defined on two vectors with the same dimensionality.\nFor $n$-dimensional vectors $\\vect{v} = (v_{1}, \\ldots, v_{n})$\nand $\\vect{w} = (w_{1}, \\ldots, v_{w})$,\n\\[\n  \\vect{v} + \\vect{w} = (v_{1} + w_{1} + \\ldots + v_{n} + w_{n})\n\\]\nThe subtraction is simply addition with a negative vector,\n\\[\n  \\vect{v} - \\vect{w} = \\vect{v} + (-\\vect{w}) = (v_{1} - w_{1} + \\ldots + v_{n} - w_{n})\n\\]\n\n\\begin{marginfigure}\n  \\tikzsetnextfilename{vector-sum}\n  \\begin{tikzpicture}[scale=0.7]\n    \\draw[<->,thick] (0, -4) -- (0, 4);\n    \\draw[<->,thick] (-4, 0) -- (4, 0);\n    \\draw[step=1cm,grid] (-4,-4) grid (4,4);\n    \\draw[->,thick,red] (0,0) -- (1,2);\n    \\node[anchor=east, red] at (1,2) {$\\vect{v}$};\n    \\draw[->,thick,blue] (0,0) -- (2,1);\n%    \\draw[->, dotted,blue] (1,2) -- (3,3);\n    \\draw[->, dotted,red] (2,1) -- (3,3);\n    \\node[anchor=west, blue] at (2,1) {$\\vect{w}$};\n    \\draw[->, thick] (0,0) -- (3,3);\n    \\node[anchor=south] at (3,3) {$\\vect{v + w}$};\n    \\draw[->,thick,purple] (0,0) -- (-2,-1);\n    \\draw[->,purple,dotted] (1,2) -- (-1,1);\n    \\node[anchor=north, purple] at (-2, -1) {$-\\vect{w}$};\n    \\draw[->,thick,black] (0,0) -- (-1,1);\n    \\node[anchor=south,xshift=-0.5em] at (-1, 1) {$\\vect{v}-\\vect{w}$};\n  \\end{tikzpicture}\n  \\caption{\\label{fig:vector-sum}%\n    Vector addition and subtraction.\n  }\n\\end{marginfigure}\n\n\\newthought{Dot product} is a very important quantity that will come up regularly in this course.\nDot product of two vectors,\n$\\vect{v} = (v_{1}, \\ldots, v_{n})$\nand $\\vect{w} = (w_{1}, \\ldots, v_{w})$,\nis a scalar defined as:\n\n\\[\n  \\vect{v}\\cdot\\vect{w} = v_{1} \\times w_{1} + \\ldots + v_{n} \\times w_{n}\n\\]\n\nIt should be emphasized that dot product yields a scalar (real number),\nnot a vector.\nThere are other vector product operations:\n\\emph{outer product} that we will discuss below,\nand \\emph{cross product} defined for vectors in $\\mathbb{R}^{3}$.\nHence, without `dot' the notation $\\vect{v}\\vect{w}$ is ambiguous.\nHowever, it is common to treat $k$-dimensional vectors\nas $k\\times{}1$ matrices for which multiplication is not ambiguous\n(we discuss this notation on page~\\pageref{pageref:vector-matrix-notation}.\n\n\n\\begin{marginfigure}\n  \\tikzsetnextfilename{dot-product}\n  \\begin{tikzpicture}[scale=0.7]\n    \\draw[step=1cm,grid] (-4,-4) grid (4,4);\n    \\draw[<->,thick] (0, -4) -- (0, 4);\n    \\draw[<->,thick] (-4, 0) -- (4, 0);\n    \\coordinate (origin) at (0,0);\n    \\draw[->,thick,red] (0,0) -- (2,2);\n    \\node[anchor=east, red] (v) at (2,2) {$\\vect{v}$};\n    \\draw[->,thick,blue] (0,0) -- (3,1);\n    \\node[anchor=west, blue] (w) at (3,1) {$\\vect{w}$};\n    \\draw[dashed] (2,2) -- (2.4, 0.8);\n    \\draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4pt}]\n      (0,0) -- (2.4, 0.8);\n    \\pic [draw, \"{\\small $\\alpha$}\", angle eccentricity=1.5]\n      {angle = w--origin--v};\n      \\node[anchor=north,rotate=20] at (1.5,-0.1) {$\\norm{v}\\cos\\alpha$};\n  \\end{tikzpicture}\n  \\caption{\\label{fig:dot-product}%\n    Dot product of two vectors.\n  }\n\\end{marginfigure}\nThere is an alternative way to define the dot product,\nwhich also leads to a nice geometric interpretation.\nWe can calculate the dot product as\n\n\\[\n  \\vect{v}\\cdot\\vect{w} = \\norm{\\vect{v}}\\norm{\\vect{w}} \\cos \\alpha\n\\]\nwhere $\\alpha$ is the angle between the two vectors\n(see Figure~\\ref{fig:dot-product}).\nThis also allows us to interpret the dot product geometrically.\nThe dot product of two vectors is proportional to each vector's magnitude,\nand also to the cosine of the angle between them.\nSince the cosine of the angle will be larger for smaller angles,\nthe dot product will be larger for vectors that point to similar directions\n(keeping the magnitudes constant).\nThe dot product of two orthogonal vectors\n(vectors with a \\num{90}\\textdegree{} angle between them)\nis \\num{0}.\nIf the angle is larger tan \\num{90}\\textdegree{},\nthe dot product is negative.\n\n\n\n\\newthought{Cosine similarity} is a similarity measure related to dot product,\nwhich we will often use for measuring similarities between objects of interest,\ne.g., documents.\nFrom above, we can simply write the cosine of the angle between two vectors as,\n\n\\[ \\cos\\alpha = \\frac{\\vect{v}\\vect{w}}{\\norm{\\vect{v}}\\norm{\\vect{w}}} \\]\n\nNote that by dividing the vectors to their Euclidean (L2) norms,\nwe are scaling them to unit vectors pointing in the same direction.\nAs a result, cosine similarity ignores the magnitudes of the vectors.\nThe cosine similarity for vectors that point to the same direction is $1$\n(regardless of their magnitude) and the vectors\nthat point exact opposite directions have a cosine similarity of $-1$.\n\n\\todo[inline]{Cross product (?)}\n\n\\subsection{Matrices}\n\nMatrices are the second type of mathematical objects we often encounter in various NLP methods.\nA matrix is simply a two-dimensional array of numbers,\nwhich is noted as a rectangular placement of scalars.\nA matrix of $n$ rows and $m$ columns is an $n \\times m$ matrix.\nA real-valued $n \\times m$ matrix is said to be in $\\mathbb{R}^{n\\times m}$.\nWe can think about a matrix as a collection of column or row vectors.\nWe denote matrices with boldface capital letters, like \\vect{A}.\nWhile referring to a matrix' elements,\nwe subscript the element first with its row and then its column.\n  \\[ \\vect{A} =\n    \\begin{bmatrix}\n      a_{1,1} & a_{1,2} & a_{1,3} & \\ldots & a_{1,m} \\\\\n      a_{2,1} & a_{2,2} & a_{2,3} & \\ldots & a_{2,m} \\\\\n      \\vdots  & \\vdots  & \\vdots  & \\ddots & \\vdots \\\\\n      a_{n,1} & a_{n,2} & a_{n,3} & \\ldots & a_{n,m} \\\\\n    \\end{bmatrix}\n  \\]\n\nWe will briefly revisit some of the operations on matrices in this section.\n\n\\newthought{Transpose of a matrix} simply replaces its rows by columns.\nTranspose of a matrix $\\vect{A}$ is denoted with $\\vect{A}^{T}$.\n\n\\begin{center}\n  If $\\vect{A} = \\begin{bmatrix} a & b \\\\ c & d \\\\ e & f \\\\ \\end{bmatrix}$,\n  $\\vect{A}^{T} = \\begin{bmatrix} a & c & e\\\\ b & d  & f \\\\ \\end{bmatrix}$.\n\\end{center}\n\n\\newthought{Multiplication by a scalar} is also defined for matrices.\nTo multiply a matrix with a scalar,\neach element of the matrix is multiplied by the scalar.\nFor example,\n\\[\n    2 \\begin{bmatrix} 2 & 1 \\\\ 1 & 4 \\\\ \\end{bmatrix} =\n    \\begin{bmatrix}\n      2\\times{}2 & 2\\times{}1 \\\\\n      2\\times{}1 & 2\\times{}4 \\\\\n    \\end{bmatrix} =\n    \\begin{bmatrix}\n      4 & 2 \\\\\n      2 & 8 \\\\\n    \\end{bmatrix}\n\\]\n\n\\newthought{Matrix addition and subtraction} require two matrices of same dimensions.\nTo obtain sum (difference) of two matrices,\neach element of the second matrix is added to (subtracted from)\nthe corresponding element of the first matrix.\nFor example:\n\n  \\[\n      \\begin{bmatrix}\n        2 & 1 \\\\\n        1 & 4 \\\\\n      \\end{bmatrix} +\n      \\begin{bmatrix}\n        0 & 1 \\\\\n        1 & 0 \\\\\n      \\end{bmatrix} =\n      \\begin{bmatrix}\n        2+0 & 1+1 \\\\\n        1+1 & 4+0 \\\\\n      \\end{bmatrix} =\n      \\begin{bmatrix}\n        2 & 2 \\\\\n        2 & 4 \\\\\n      \\end{bmatrix}\n  \\]\n\n\\newthought{Matrix multiplication} is a slightly complicated operation.\nThe matrix multiplication $\\vect{A}\\times\\vect{B}$ is defined only\nif \\vect{A} has the same number of columns as the number of rows in \\vect{B}.\nMultiplying a $n\\times{}k$ matrix with a $k\\times{}m$ matrix\nresults in a $n\\times{}m$ matrix.\nNote that both $A\\times{}B$ and $B\\times{}A$ is defined only for square matrices (of the same dimensions).\n\nFor an $n\\times{}k$ matrix \\vect{A}\nand a $k\\times{}m$  \\vect{B},\nif $\\vect{A} \\times \\vect{B} = \\vect{C}$,\n$c_{i,j}$, the element of the resulting matrix \\vect{C} on row $i$ and column $j$,\nis calculated as:\n\n\\[\n  c_{ij} = \\sum_{\\ell=0}^{k} a_{i\\ell} b_{\\ell j}\n\\]\n\nFigure~\\ref{fig:matrix-mult} demonstrates the matrix multiplication.\n\n\\begin{figure*}\n  \\tikzsetnextfilename{matrix-multiplication}\n  \\begin{tikzpicture}[ampersand replacement=\\&]\n    \\matrix (A) [matrix of math nodes,\n                 left delimiter  = {[},\n                 right delimiter  = {]}] at (0,0) {%\n      \\textcolor{blue}{a_{11}} \\&\n      \\textcolor{blue}{a_{12}} \\&\n      \\textcolor{blue}{\\ldots} \\&\n      \\textcolor{blue}{a_{1k}} \\\\\n      a_{21} \\&\n      a_{22} \\&\n      \\ldots \\&\n      a_{2k} \\\\\n       \\vdots \\& \\vdots \\& \\ddots \\& \\vdots \\\\\n      a_{n1} \\&\n      a_{n2} \\&\n      \\ldots \\&\n      a_{\\textcolor{red}{nk}} \\\\\n    };\n    \\node[right of=A,anchor=west,xshift=1.5cm] {\\Huge$\\times$};\n    \\matrix (B) [matrix of math nodes,\n                 left delimiter  = {[},\n                 right delimiter  = {]}] at (6,0) {%\n      b_{11} \\&\n     \\textcolor{blue}{b_{12}} \\&\n      \\ldots \\&\n      b_{1m} \\\\\n      b_{21} \\&\n      \\textcolor{blue}{b_{22}} \\&\n      \\ldots \\&\n      b_{2m} \\\\\n      \\vdots \\&\n      \\textcolor{blue}{\\vdots} \\&\n      \\ddots \\&\n      \\vdots \\\\\n      b_{k1} \\&\n      \\textcolor{blue}{b_{k2}} \\&\n      \\ldots \\&\n      b_{\\textcolor{red}{km}} \\\\\n    };\n    \\node[right of=B,anchor=west,xshift=1.5cm] {\\Huge$=$};\n    \\matrix (C) [matrix of math nodes,\n                 left delimiter  = {[},\n                 right delimiter  = {]}] at (12,0) {%\n       c_{11} \\&\n       \\textcolor{blue}{c_{12}} \\&\n       \\ldots \\&\n       c_{1m} \\\\\n       c_{21} \\&\n       c_{22} \\&\n       \\ldots \\&\n       c_{2m} \\\\\n       \\vdots \\&\n       \\vdots \\&\n       \\ddots \\&\n       \\vdots \\\\\n       c_{n1} \\&\n       c_{n2} \\&\n       \\ldots \\&\n       c_{\\textcolor{red}{nm}} \\\\\n    };\n    \\draw[blue]  (A-1-1.south west) rectangle (A-1-4.north east);\n    \\draw[blue]  (B-1-2.north west) rectangle (B-4-2.south east);\n    \\node[below=of C, yshift=5ex,blue]\n        {$c_{12} = a_{11} b_{12} + a_{12} b_{22} + \\ldots a_{1k} b_{k2}$};\n  \\end{tikzpicture}\n  \\caption{Matrix multiplication.\n    The calculation of the resulting matrix \\textcolor{blue}{$c_{12}$} is highlighted.\n  }\\label{fig:matrix-mult}\n\\end{figure*}\n\nNote that the element $c_{ij}$ is the dot product of\n$i^{th}$ row vector of \\vect{A} and $j^{th}$ column vector of \\vect{B}.\nHence, we can view dot-product as matrix multiplication\nof a row vector (on the left) and column vector (on the right).\nDot product of two vectors \\vect{v} and \\vect{w} is often noted as\n$\\vect{v}\\vect{w}^{T}$.%\n\\footnote{It is a common convention to assume that vectors are column vectors\n  unless stated otherwise.}\nTechnically,\nresult of a matrix multiplication of a $1\\times{}k$ vector with a $k\\times{}1$\nvector is a $1\\times{}1$ matrix,\nnot a scalar.\nHowever, this notation is prevalent in machine learning and NLP literature,\nwe will often use this notation during this course.\n\n\\label{pageref:vector-matrix-notation}\nFor example, $\\vect{w} = (2, 2)$ and $\\vect{v} = (2, -2)$,\n\n\\[\n  \\vect{v}\\vect{w}^{T} = \\begin{bmatrix}\n    2 \\\\ -2 \\\\\n  \\end{bmatrix}\n  \\times\n  \\begin{bmatrix}\n    2 & 2 \\\\\n  \\end{bmatrix}\n  = 2\\times{}2 + 2\\times{}-2 = 4 - 4 = 0\n\\]\n\n\\marginnote{What does the result of dot product ($0$) say about the vectors?}\n\n\\newthought{Outer product} of two vectors with the same dimensionality,\ncan also be defined as matrix multiplication.\nThis time we put the column vector to the left and the row vector to the right.\nSo, in the notation used above, outer product of two matrices \\vect{v} and \\vect{w} is\n$\\vect{v}^{T}\\vect{w}$.\nNote that result of outer product of two $k$-dimensional vectors is\na $k\\times{}k$ matrix, not a scalar.\nThe following is an example of outer product of two $3$-dimensional vectors.\n\n\\[\n  \\begin{bmatrix}\n    1 & 2 & 3\\\\\n  \\end{bmatrix}\n  \\times\n  \\begin{bmatrix}\n    6 \\\\ 5  \\\\ 4 \\\\\n  \\end{bmatrix}\n  =\n  \\begin{bmatrix}\n    6  & 5 & 4 \\\\\n    12  & 10 & 8 \\\\\n    18  & 15 & 12 \\\\\n  \\end{bmatrix}\n\\]\n\n\\todo[inline]{Relation to SVD / variance ?}\n\n\\newthought{An identity matrix} is a square matrix\nin which all the elements of the main diagonal are ones,\nand all other elements are zeros.\nThe $n\\times{}n$ identity matrix is denoted by $\\vect{I}_{n}$.\nWhen there is no ambiguity, we omit the subscript, and simply write \\vect{I}.\nMultiplying a matrix with a compatible identity matrix does not change the original matrix.\nFor $n \\times m$ matrix \\vect{A},\n\\[\n  \\vect{I}_{n} \\vect{A} = \\vect{A} \\quad \\vect{A} \\vect{I}_{m} = \\vect{A}\n\\]\n\n\\begin{marginfigure}\n  \\[\n    \\vect{I}_{4} =\n    \\begin{bmatrix}\n      1 & 0 & 0 & 0\\\\\n      0 & 1 & 0 & 0\\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\n    \\end{bmatrix}\n  \\]\n  \\caption{\\label{fig:identity-matrix}$4\\times{}4$ identity matrix.}\n\\end{marginfigure}\n\n\\newthought{Multiplying a vector with a matrix} (linearly) transforms it to another\n(possibly a different dimensional) vector.\nThese linear transformations have many applications,\nand they will also be useful for understanding some of the machine learning concepts.\nHere are a few interesting transformations in 2-dimensional space:\n\n\\begin{itemize}\n  \\item Identity transformation has no effect on the vector to be transformed\n    \\[\n      \\begin{bmatrix}\n        1 & 0 \\\\\n        0 & 1 \\\\\n      \\end{bmatrix}\n      \\times\n      \\begin{bmatrix}\n        1 \\\\\n        2 \\\\\n      \\end{bmatrix}\n      =\n      \\begin{bmatrix}\n        1 \\\\\n        2 \\\\\n      \\end{bmatrix}\n    \\]\n  \\item Stretch along x-axis\n    \\[\n      \\begin{bmatrix}\n        3 & 0 \\\\\n        0 & 1 \\\\\n      \\end{bmatrix}\n      \\times\n      \\begin{bmatrix}\n        1 \\\\\n        2 \\\\\n      \\end{bmatrix}\n      =\n      \\begin{bmatrix}\n        3 \\\\\n        2 \\\\\n      \\end{bmatrix}\n    \\]\n  \\begin{marginfigure}\n    \\tikzsetnextfilename{linear-op-stretch}\n    \\begin{tikzpicture}[scale=0.7]\n      \\draw[step=1cm,grid] (-4,-1) grid (4,4);\n      \\draw[->] (0,-1) -- (0, 4);\n      \\draw[<->] (-4,0) -- (4,0);\n      \\coordinate (v1) at (1,2);\n      \\coordinate (v2) at (3,2);\n      \\draw[blue,thick,->] (0,0) -- (v1);\n      \\node[anchor=south east]  at (v1) {$(1,2)$};\n      \\draw[orange,thick,->] (0,0) -- (v2);\n      \\node[anchor=south west]  at (v2) {$(3,2)$};\n      \\draw[dotted,->,thick] (v1) to[bend left] (v2);\n    \\end{tikzpicture}\n    \\caption{Stretch (three times) along x.}\n  \\end{marginfigure}\n  \\item Multiplying a vector with\n    \\[\n        \\begin{bmatrix}\n          \\cos\\theta & -\\sin\\theta \\\\\n          \\sin\\theta & \\cos\\theta \\\\\n        \\end{bmatrix}\n    \\]\n  rotates it with $\\theta$ degrees (counter-clock wise).\n  For example, for 90-dgrees rotation,\n    \\[\n      \\begin{bmatrix}\n        0 & -1 \\\\\n        1 & 0 \\\\\n      \\end{bmatrix}\n      \\times\n      \\begin{bmatrix}\n        1 \\\\\n        2 \\\\\n      \\end{bmatrix}\n      =\n      \\begin{bmatrix}\n        -2 \\\\\n        1 \\\\\n      \\end{bmatrix}\n    \\]\n  \\begin{marginfigure}\n    \\tikzsetnextfilename{linear-op-rotate}\n    \\begin{tikzpicture}[scale=0.7]\n      \\draw[step=1cm,grid] (-4,-1) grid (4,4);\n      \\draw[->] (0,-1) -- (0, 4);\n      \\draw[<->] (-4,0) -- (4,0);\n      \\coordinate (v1) at (1,2);\n      \\coordinate (v2) at (-2,1);\n      \\draw[blue,thick,->] (0,0) -- (v1);\n      \\node[anchor=south west]  at (v1) {$(1,2)$};\n      \\draw[orange,thick,->] (0,0) -- (v2);\n      \\node[anchor=south east]  at (v2) {$(-2,1)$};\n      \\draw[dotted,->,thick] (v1) to[bend right] (v2);\n    \\end{tikzpicture}\n    \\caption{Rotate 90 degrees.}\n  \\end{marginfigure}\n%  \\item Shear: $\\begin{bmatrix}1 & k \\\\ 0 & 1 \\\\\\end{bmatrix}$\n\\end{itemize}\n\nThese linear operations can be combined (composed)\nfor more complex transformations.\n\n\\newthought{Solving a set of linear linear equations} has been one of\nthe main applications of linear algebra.\nWe will not discuss how to solve a linear equations here\n(since we rarely do this by hand),\nbut we will demonstrate how a set of linear equations are represented using matrices\nand vectors.\nWe will encounter this in various forms during the course.\n\nThe set of equations,\n    \\[\n      \\begin{array}{rcrcr}\n        2x_{1} &+& x_{2}  &=& 6 \\\\\n        x_{1}  &+& 4x_{2} &=& 17 \\\\\n      \\end{array}\n    \\]\n    can be written as:\n    \\[\n      \\underbrace{\\begin{bmatrix} \n        2 & 1 \\\\ \n        1 & 4 \\\\ \n      \\end{bmatrix}}_{\\vect{W}}\n      \\underbrace{\\begin{bmatrix} \n        x_{1} \\\\ \n        x_{2} \\\\ \n      \\end{bmatrix}}_{\\vect{x}} \n      = \n      \\underbrace{\\begin{bmatrix} \n        6 \\\\ \n        17 \\\\ \n      \\end{bmatrix}}_{\\vect{b}}\n    \\]\nwhich allows finding a solution (if one exists)\nusing \\emph{Gaussian elimination}.\n\nFor our purposes,\nimportant part is to realize that\nthis amounts to the matrix/vector operations operations\nwe have been reviewing so far.\n\n\\newthought{Inverse of a matrix} is defined for square matrices. \nInverse of matrix \\vect{W} is denoted by $\\vect{W}^{-1}$.\nMultiplying a matrix with its inverse yields the identity matrix.\n\\[\n  \\vect{W}\\vect{W}^{-1} = \\vect{W}^{-1} \\vect{W} = \\vect{I}\n\\]\n\nNow that we have defined the inverse of a matrix,\nwe can solve the set of linear equations $\\vect{W}\\vect{x} = \\vect{b}$,\nusing the inverse matrix.\n\\[ \n  \\begin{aligned}\n    \\vect{W} \\vect{x} &= \\vect{b} \\\\\n    \\vect{W}^{-1} \\vect{W} \\vect{x} &= \\vect{W}^{-1} \\vect{b} \\\\\n    \\vect{I} \\vect{x} &= \\vect{W}^{-1} \\vect{b} \\\\\n    \\vect{x} &= \\vect{W}^{-1} \\vect{b} \\\\\n  \\end{aligned}\n\\]\n\n\\todo[inline]{note `pseudo inverse' ?}\nCalculating inverse of a matrix involves using a set of operations,\ncalled \\emph{elementary row operations},\non the augmented matrix that contains the original matrix and the identity matrix side by side.\nWe will not cover this here, as we rarely do this by hand.\nInterested readers should check any of the linear algebra sources listed at the end of the chapter.\n\n\\newthought{The determinant of a matrix} is a scalar value\nwith some interesting properties and applications, including\n\\begin{itemize}\n  \\item A matrix is invertible if it has a non-zero determinant\n  \\item A system of linear equations has a unique solution if the coefficient matrix has a non-zero determinant\n\\end{itemize}\n\nWe denote the determinant of a matrix with vertical bars around it,\ndeterminant of \\vect{A} is denoted by $\\lvert\\vect{A}\\rvert$.\nGeometric interpretation of determinant is the (signed) changed in the volume of a unit (hyper)cube caused by the transformation defined by the matrix.\n\nThe determinant of a $2\\times{}2$ matrix can be calculated by the formula:\n\\[\n  \\begin{vmatrix}\n    a & b \\\\\n    c & d \\\\\n  \\end{vmatrix} = a d - b c\n\\]\nThe above formula generalizes to higher dimensional matrices through a recursive definition.\n\\todo{definition, geometric interpretation}\n\n\\newthought{Eigenvalues and eigenvectors} of a matrix also has important applications.\n\nAn \\emph{eigenvector}, \\vect{v}\nand corresponding \\emph{eigenvalue}, $\\lambda$,\nof a matrix $\\vect{A}$ is defined such that\n\\[ \\vect{A} \\vect{v} = \\lambda \\vect{v}\\;. \\] \n\nIn (other) words, multiplying a matrix with its eigen vector\nonly changes its magnitude of the vector\nand does not change its direction.\n\nEigenvalues an eigenvectors have many applications from communication theory to quantum mechanics\nA better known example (and close to home) is Google's PageRank algorithm\nWe will return to them while discussing PCA\nand SVD (and maybe other topics/concepts)\n\n\\todo[inline]{Tensors}\n\n\\section{\\label{sec:calculus-intro}Derivatives and integrals}\n\nDifferentiation and integration are two fundamental concepts in calculus.\nThe reason we review some of the basic calculus here has to do\nwith the fact that these operations are often used\nin probability theory and machine learning.\nIn many machine learning problems,\nlearning is achieved through minimizing the error\nor maximizing an objective (e.g., likelihood).\nA particularly important use of derivatives in machine learning is\nto find maxima or minima of error or objective function.\nThis section will give a refresher on these topics,\nand define some notation that we will use throughout the course. \nYou can safely skip this section,\nif you know how to differentiate polynomial functions\nor what a \\emph{gradient} is.\n\nDerivative of a function indicates the rate of change.\nThe familiar example from physics is that\nthe derivative of the velocity of a moving object is it acceleration.\nFor example,\nthe velocity of a car changes proportional to its acceleration of deceleration.\n\n\\marginnote{\n  \\begin{tcolorbox}[colback=white,colframe=gray,halign=left,width=\\linewidth]\n    A quick refresher on polynomial functions: if $f(x) = x^{n}$,\n    \\[\n      f'(x) = \\frac{df}{dx}  = n x^{n-1}\\;.\n    \\]\n    For example, for\\\\\n      $f(x) = x^{3} + 2 x^{2}$,\n    \\[\n      f'(x) = \\frac{df}{dx} = 3 x^{2} + 4 x\\;.\n    \\]\n  \\end{tcolorbox}\n}\nOne of the common ways of denoting a function's derivative is,\nusing the `prime notation'.\nFor example derivative of the function function $f(x)$ written as $f'(x)$.\nAnother common notation is $\\frac{df}{dx}(x)$ or $\\frac{df}{dx}(x)$.\\todo{double check}\nFor multi-variate functions,\nthis notation makes it clear that the derivative is taken with respect to the variable $x$.\n\nIf defined, derivative of a function is another function.\nA well known example is the polynomials,\nwhose derivatives are lower degree polynomials.\nFor example, if $f(x) = x^{2} - 2 x $ then $f'(x) = 2 x - 2$,\nwhich means that the rate of change of a quadratic function doubles\nas $x$ is increased one unit.\nNote that if a polynomial of degree $n$ is differentiated $n$ times,\nit becomes a constant.\nDerivative of a linear function is a constant value,\nsince a linear function changes with the same rate everywhere.\nOn the other hand, derivative of a constant (function) is $0$,\nsince there is no change.\n\n\\begin{marginfigure}\n  \\tikzsetnextfilename{func-derivative}\n  \\begin{tikzpicture}[scale=0.7]\n    \\draw[step=1cm,grid] (-4,-2) grid (4,4);\n    \\draw[->] (0,-2) -- (0, 4);\n    \\draw[<->] (-4,0) -- (4,0);\n    \\begin{scope}\n      \\clip(-4,-2) rectangle (4,4);\n      \\draw[domain=-2:4,smooth,variable=\\x,blue]\n        plot ({\\x},{\\x*\\x - 2*\\x});\n\n      \\node[blue,xshift=0.2ex] at (1,2) {$f(x) = x^{2} - 2x$};\n\n      \\node[orange,inner sep=0pt,draw,circle,minimum size=2pt]\n        at (1,-1) {};\n      \\node[orange,anchor=north] at (1,-1) {$f'(1) = 0$};\n      \\draw[orange] (-4,-1) -- (4, -1);\n\n      \\begin{scope}\n      \\clip(-4,-0.5) rectangle (4,4);\n        \\node[purple,inner sep=0pt,draw,circle,minimum size=2pt]\n          at (3,3) {};\n        \\node[purple,anchor=south east] at (3,3) {$f'(3) = 4$};\n        \\draw[purple] (4, 7) -- (3,3) -- (2, -1);\n\n        \\node[red,inner sep=0pt,draw,circle,minimum size=2pt]\n          at (-0.5,1.25) {};\n        \\draw[red] (-1.5, 4.25) -- (-0.5,1.25) -- (0.5, -1.75);\n        \\node[red,anchor=north east] at (-0.5,1.25) {$f'(-0.5) = -3$};\n      \\end{scope}\n    \\end{scope}\n  \\end{tikzpicture}\n  \\caption{The function $f(x) = x^{2} - 2x$ and its derivative evaluated at,\n    different $x$ values.\n  }\n\\end{marginfigure}\nWhen evaluated at a particular $x$ value,\nthe derivative of the function will be\nthe slope of the tangent line at that point,\nwhich is indication of the direction and the rate of change.\nNote that in our example above,\nthe derivative of $f(x) = x^{2} - 2x$, $f'(x) = 2 x - 2$,  at $x = 1$ is $0$.\nFor a continuous function the derivative of the function is equal to $0$,\nonly on the maximum and minimum points of the function.\nAnd this is the most important reason for all the earlier\nnotes in this introduction.\nIn many methods we see later on,\nwe will be aiming at maximizing or minimizing functions,\nwhere this will be a handy tool.\nIn general,\nderivative evaluated at a particular point will be $0$ for maxima and minima\nof functions,\nit will be a negative value if the function is decreasing (as $x$ increases),\nand a positive value if the function is increasing with $x$.\n\nSo far,\nwe've considered differentiation of functions of a single variables.\nIn machine learning and NLP,\nwe often deal with functions of many variables.\nOne can also differentiate a function of multiple variables with respect to one of them,\nfor which the dependence between the variables should be considered.\nWe will not review how to take (total) derivatives\nof functions of multiple variables.\nHowever, we will introduce \\term{partial derivatives} briefly here.\nA partial derivative is similar to a total derivative,\nbut we assume that except the variable along which we take the derivative,\nall other variables are constants.\nSo, when you evaluate the partial derivative of a function at a particular point,\nit gives you the rate of change along one of the axes.\n\n\\todo[inline]{note the chain rule and the relation between partial/total derivative?}\nThe partial derivative of a function $f$ with respect variable $x$ is denoted by $\\frac{\\partial f}{\\partial x}$.\nFor example, if $f(x, y) = x^{3} + yx$, \n\\[\n  \\frac{\\partial f}{\\partial x}  = 3 x^{2} + y,\\; \\text{and}\\; \n  \\frac{\\partial f}{\\partial y}  = x .\n\\]\nThe vector formed by all partial derivatives\nof a (scalar) function of $n$-variables is called its \\term{gradient}.\nGradient of a function $f$ is denoted by $\\nabla f$, or $\\vec{\\nabla} f$.\n\\[\n  \\nabla f(x_{1}, \\ldots, x_{n}) = \n        \\left(\\frac{\\partial f}{\\partial x_{1}}, \\ldots,\n              \\frac{\\partial f}{\\partial x_{n}} \\right)\n\\]\nSimilar to derivative of a function of a single variable,\ngradient points to the direction of greatest change,\nand the magnitude of the gradient indicates the steepness of the change.\nAreas where the gradient is \\num{0} are (local) minima, maxima and saddle points.\nAs a result, it is an important tool\nin finding minimum and maximum values of (objective) functions.\n\n\\todo[inline]{Second derivative, picture with a saddle point, Jacobian matrix(?)}\n\n\n\\begin{marginfigure}[-5\\baselineskip]\n  \\tikzsetnextfilename{integration}\n  \\begin{tikzpicture}[x=10mm, y=2mm, scale=0.7]\n    \\draw[step=1cm,grid] (-4,-2) grid (4,30);\n    \\clip(-4,-2) rectangle (4,30);\n    \\draw[->] (0,-2) -- (0, 30);\n    \\draw[<->] (-4,0) -- (4,0);\n\n     \\draw[domain=-4:4,smooth,variable=\\x,blue]\n       plot ({\\x},{3*\\x*\\x});\n      \\fill[blue,opacity=0.2] \n        plot[domain=1:3,smooth,variable=\\x] ({\\x},{3*\\x*\\x}) \n        -- (3,0) -- (1,0) -- cycle;\n%        plot coordinates {(3,27) (3,0) (1,0) (1,3) };\n  \\end{tikzpicture}\n  \\caption{\\label{fig:integral}%\n    Integral of the function $f(x) = 3 x^{2}$ in range $[1, 3]$.\n  }\n\\end{marginfigure}\n\\newthought{Integration} is the inverse of the derivation.\nIn general, the integral of a function in a given range corresponds\nto the (signed) area (or volume) under a function in this range.\nThe notation used for integral of a function $f(x)$ is\n$F(x) = \\int f(x) dx$.\nThis is called an indefinite integral.\nOften we want the integral of a function in an interval $[a,b]$,\nwhich can be calculated by\n\\[\n  \\int_{a}^{b} f(x) dx = F(b) - F(a).\n\\]\n\nFor example, if $f(x) = 3 x^{2}$,\nwe know that $F(x) = x^{3}$ (since the integral is the antiderivative,\nand $F'(x) = f(x) = 3 x^{2}$).\nIf we want to know the area under $f(x)$ within range $[1, 3]$,\nwe simply calculate $F(1) - F(0) = 27 - 1 = 26$.\n\n\\begin{marginfigure}\n  \\tikzsetnextfilename{numeric-integral1}\n  \\begin{tikzpicture}[x=10mm, y=5mm]\n    \\draw[step=1cm,grid] (-0.2,-0.2) grid (4,4);\n    \\clip(-0.2,-0.2) rectangle (4,4);\n    \\draw[->] (0,-0.2) -- (0, 4);\n    \\draw[->] (-0.2,0) -- (4,0);\n\n     \\draw[domain=-4:4,smooth,variable=\\x,blue]\n       plot ({\\x},{0.25*\\x*\\x});\n     \\foreach \\x in {1,...,6}{%\n       \\fill[draw=black,blue,opacity=0.2]\n        (0.5*\\x, 0.25*0.25*\\x*\\x) rectangle ($ (0.5*\\x,0) + (-1*0.5, 0)$);\n     }\n  \\end{tikzpicture}\\\\\n  \\tikzsetnextfilename{numeric-integral2}%\n  \\begin{tikzpicture}[x=10mm, y=5mm]\n    \\draw[step=1cm,grid] (-0.2,-0.2) grid (4,4);\n    \\clip(-0.2,-0.2) rectangle (4,4);\n    \\draw[->] (0,-0.2) -- (0, 4);\n    \\draw[->] (-0.2,0) -- (4,0);\n\n     \\draw[domain=-4:4,smooth,variable=\\x,blue]\n       plot ({\\x},{0.25*\\x*\\x});\n     \\foreach \\x in {1,...,20}{%\n       \\fill[draw=black,blue,opacity=0.2]\n        (3*0.05*\\x, 9*0.0025*0.25*\\x*\\x) rectangle ($ (3*0.05*\\x,0) + (-1*3*0.05, 0)$);\n     }\n  \\end{tikzpicture}\n  \\caption{\\label{fig:ingegral-numeric}%\n    Demonstration of numerical approximation to an integral.\n    Note that as the rectangles get smaller (as in the figure below),\n    sum of their areas gets closer to the area under the curve.\n  }\n\\end{marginfigure}\nOften integrating functions analytically\n(in closed form) is not easy or possible.\nIn these cases, integrals can be computed with numeric approximation.\nOne way to do this is to sum the areas of rectangles\nas demonstrated in Figure~\\ref{fig:ingegral-numeric}.\nAs we decrease the width of the rectangles,\nor equivalently, increase the number of rectangles in a fixed range,\nthe approximation will be more precise.\nThis also hints at interpreting integrals as a infinite sum.\nThis interpretation will often be more useful\nfor the examples we will see (often in probability theory).\n\n\\section*{Summary}\n\nIn this lecture,\nwe reviewed some concepts from linear algebra and calculus.\nThe aim was to\nprovide a refresher for those who studied these topics,\nfamiliarize the reader with the notation that will be used,\nand also give a feeling of the what mathematical concepts will be useful\nfor studying statistical natural language processing.\nThis overview here is necessarily informal and incomplete.\nBelow, a number of potential sources are listed if you need a better introduction to these concepts.\n\nFor linear algebra,\n\\textcite{cherney2013} and \\textcite{beezer2016} are\ntwo textbooks that are freely available online.\nA classic reference textbook for linear algebra is \\textcite{strang2009}.\nFor a more practical/geometric approach,\nsee \\textcite{farin2014} or \\textcite{shifrin2011}.\n\nFor the concepts we reviewed briefly from calculus,\nany textbook introduction to calculus should be sufficient.\nA well-known (also available online) textbook is \\textcite{strang1991}.\nFor more alternatives on open textbooks on mathematics see\n\\url{http://www.openculture.com/free-math-textbooks}.\n", "meta": {"hexsha": "81807ce880e5fede5d479d32c2ffaaa0d86492fd", "size": 38312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math-overview.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": "math-overview.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": "math-overview.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": 36.9094412331, "max_line_length": 151, "alphanum_fraction": 0.6510492796, "num_tokens": 12241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6112864324762073}}
{"text": "\\documentclass{article}\n\n\\usepackage{epsfig}\n\\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{fullpage}\n\\usepackage{commath}\n\\usepackage{amssymb}\n\\usepackage[space]{grffile}\n\\usepackage{float}\n\\usepackage{float}\n\n\\def\\E{\\mathbb{E}}\n\\def\\R{\\mathbb{R}}\n\\def\\bin{\\text{bin}}\n\\def\\bet{\\text{beta}}\n\\def\\Bin{\\text{Binom}}\n\\def\\diag{\\text{diag}}\n\n\\title{Single Sequence HMM in DNA Methylation Problem}\n\\author{Chicheng Zhang}\n\n\\begin{document}\n\\maketitle\n\n\\section{The Model}\n\nIn the problem of DNA methylation, we are given a sequence $\\cbr{x_t = (c_t, \\mu_t)}_{t=1}^l$, where at each time $t$, the coverage is an nonnegative integer $c_t \\in \\cbr{0,1,\\ldots,N}$ and the methylation count is $\\mu_t \\in \\cbr{0,1,\\ldots,c_t}$. We model the data using a hidden Markov model, that is, the underlying dynamics of the hidden states is driven by a Markov chain $\\cbr{h_t}$, where $h_t \\in [m]$. We leave the consideration of context information to the next stage.\n\nThe HMM can be summarized by parameters $(\\pi, T, O)$, where $\\pi \\in \\R^m$ is the initial probability distribution $\\Pr(h_1)$ and $T \\in \\R^{m \\times m}$ is the transition matrix of the Markov chain $\\Pr(h_{t+1} | h_t)$, $O$ is the observation matrix, namely the conditional probability of methylation and coverage, given hidden state $\\Pr(c_t, \\mu_t | h_t)$. To avoid notation clutter, we drop the time indices $t$ if they are the same among all the variables appeared in a formula.\n\nWe assume the $\\mu_t$ given $c_t$ and $h_t$ is drawn from a binomial distribution, and for each hidden state $h \\in [m]$ there is a methylation probability $p_h \\in [0,1]$ associated with it. Formally,\n\\[ \\mu_t | c_t, h_t \\sim \\Bin(c_t, p_{h_t}) \\]\n\n\\section{Algorithm based on Method of Moments}\n\nGiven an observation $(c, \\mu)$, we map it to a $n$-dimensional vector using feature mapping $\\phi$. Generally speaking, different feature mappings have different properties.\n\nFor mapping $\\phi$, we define the corresponding observation matrices as follows:\n\\[ O_{\\phi}^s := \\E[\\phi(c_s,\\mu_s) | h_2] \\]\nfor $s = 1,2,3$, where $h_2$ is the hidden state at time 2. It is worth pointing out that $O_\\phi$ contains information to recover the $p_h$'s, and since\n\\[ O_{\\phi}^3 = O_{\\phi}^2 T, \\qquad O_{\\phi}^1 = O_{\\phi}^2 \\diag(\\pi) T^T \\diag(T\\pi)^{-1}\\]\nif we can recover $O_{\\phi}^s$, $s = 1,2,3$, then we can recover $T$ and $\\pi$ by algebra.\n\nConditional independence of $(c_1, \\mu_1)$, $(c_2, \\mu_2)$, $(c_3, \\mu_3)$ given $h_2$ implies that\n\\[ \\E[\\phi(c_1, \\mu_1) \\otimes \\phi(c_2, \\mu_2) \\otimes \\phi(c_3, \\mu_3)] = \\sum_{i=1}^m w_i (O_{\\phi}^1)_i \\otimes (O_{\\phi}^2)_i \\otimes (O_{\\phi}^3)_i \\]\nwhere $w_i = \\Pr[h_2 = i] = (T\\pi)_i$.\nThis tensor has a low rank structure.\n\nIts empirical version can be computed by summing the outer products of mapped observation over training data; suppose the training data contains triples $\\cbr{((c_{t,1}, \\mu_{t,1}), (c_{t,2}, \\mu_{t,2}), (c_{t,3}, \\mu_{t,3}))}_{t=1}^{l}$, then\n\\[ \\hat{\\E}[\\phi(c_1, \\mu_1) \\otimes \\phi(c_2, \\mu_2) \\otimes \\phi(c_3, \\mu_3)] = \\frac{1}{l} \\sum_{t=1}^l \\phi(c_{t,1}, \\mu_{t,1}) \\otimes \\phi(c_{t,2}, \\mu_{t,2}) \\otimes \\phi(c_{t,3}, \\mu_{t,3}) \\to \\E[\\phi(c_1, \\mu_1) \\otimes \\phi(c_2, \\mu_2) \\otimes \\phi(c_3, \\mu_3)] \\]\n\nTherefore, applying CP-tensor decomposition on the empirical tensor gives an estimate of $O_{\\phi}^s$, $s = 1,2,3$.\n\n\n\\section{Feature Maps}\nSome examples of feature maps are given as follows.\n\n\\paragraph{Binning mapping} Given observation $(c, \\mu)$, $\\phi_{\\bin, n}(c, \\mu)$ is a $n$-dimensional vector, with its entries as follows:\n\\[ (\\phi_{\\bin, n}(c, \\mu))_i = \\begin{cases} I(\\frac{\\mu}{c} \\in (\\frac{i-1}{n}, \\frac{i}{n}]) & c \\neq 0 \\\\ 0 & c = 0 \\end{cases} \\]\nwhere $n$ is a hyperparameter controlling the number of the bins, and the width of the bins is $\\frac{1}{n}$.\n\n\\paragraph{Beta mapping} Given observation $(c, \\mu)$, $\\phi_{\\bet, n}(c, \\mu)$ is a $n$-dimensional vector, with its entries as follows:\n\\[ (\\phi_{\\bet, n}(c, \\mu))_i = \\frac{1}{B(\\mu+1, c-\\mu+1)} (\\frac{i}{n})^\\mu (1-\\frac{i}{n})^{c-\\mu} \\]\n\n\\section{Experiment Results}\n\\subsection{Setting}\nIn this set of experiments, we focus on the methylation data in cell type E1 and chromosome 1.\n\nLet $s$ be the number of base segments merged to a single segment. Specifically, we aggregate every $s$ observations to a single one. Namely, for all integers $k \\geq 0$, we merge obervations $(c_{ks+1}, \\mu_{ks+1})$, $(c_{ks+2}, \\mu_{ks+2})$, \\ldots, $(c_{ks+s}, \\mu_{ks+s})$ to a single $(\\tilde{c}_k, \\tilde{\\mu}_k)$, where\n\\[ \\tilde{c}_k = \\sum_{i=1}^k c_{ks+i}, \\quad \\tilde{\\mu}_k = \\sum_{i=1}^k \\mu_{ks+i}\\]\nNote that the segments merged are non-overlapping.\n\n\nLet $l$ be the length of the input sequence, that is, we draw $l$ 3-consecutive observations with replacement from the (merged) sequence $\\cbr{(c_t, \\mu_t)}_{t=1}^{L}$, forming a new dataset containing triples $\\cbr{((\\tilde{c}_{t,1}, \\tilde{\\mu}_{t,1}), (\\tilde{c}_{t,2}, \\tilde{\\mu}_{t,2}), (\\tilde{c}_{t,3}, \\tilde{\\mu}_{t,3}))}_{t=1}^{l}$.\n\nLet $n$, the dimensionality of the feature mapping, be 30.\n\nLet $m$ be the number of hidden states assumed. For example if $m = 4$, then the estimated matrix $O^2_{\\phi} = \\E[\\phi(x)|h]$ has 4 columns.\n\n%At this point we do not take into account the contexts, and we further assume that the coverage in different segments are non-uniform.\n\nAlthough our ultimate goal is to recover the transition matrix and observation matrix of the hidden Markov model, at the current stage, we recover $\\E[\\phi(x)|h]$ for each value of $h$. Recall that $x = (c, \\mu)$ is the (coverage, methylation) count pair in each segment. In the figures, the x-axis $t$ corresponds to the $i = (tn)^{\\text{th}}$ coordinate of vector $\\phi$. The $y$ axis corresponds to the values of $(\\E[\\phi(x)|h])_i$.\n\n\nThe value of $p_h$ for each $h$ can be straightforwardly extracted from $\\E[\\phi(x)|h]$. The transition matrix can also be computed subsequently. We leave the full recovery of the parameters to the next stage.\n\n\\paragraph{Recovery of $p_h$ from Expected Beta feature mapping}\nRecall that\n\\[ \\int_0^1 \\frac{t t^{m}t^{c-m}}{B(m+1,c-m+1)} dt = \\int_0^1 \\frac{t t^{(m+1)-1}t^{(c-m+1)-1}}{B(m+1,c-m+1)} dt = \\frac{m+1}{c+2} \\]\nTherefore,\n\\[ \\int_0^1 \\E[\\phi(x,t) | h] dt = \\E[\\frac{m+1}{c+2} | h] = \\E[\\frac{cp_h + 1}{c + 2} | h] = \\E[\\frac{c}{c+2}] p_h + \\E[\\frac{1}{c+2}] \\]\nassuming independence between $h$ and $c$.\nLet $a = \\E[\\frac{1}{c+2}]$. Then, $\\int_0^1 \\E[\\phi(x,t) | h] dt = (1 - 2a) p_h + a$.\nHence,\n\\[ p_h = \\frac{\\int_0^1 \\E[\\phi(x,t) | h] dt - a}{1 - 2 a}. \\]\n\n\n%In subsequent results, we show the entire $\\E[\\phi(x)|h]$, as opposed to a single number $p_h \\in [0,1]$. The reason is that we wish to recover more information about the hidden states learned, to get a better understanding of the HMM model.\n\n%-- what features $\\phi$ are you looking at?\n%-- why are you showing the entire $\\phi$ vector and not a single number?\n%We focus on two types of feature mappings $\\phi$, the first one is binning mapping:\n%\\[ \\phi_{\\bin}(x,y) = \\begin{cases} {I(\\frac{\\mu}{c} \\in (y,y+h])} & c \\neq 0 \\\\ 0 & c = 0\\end{cases} \\]\n%where $h$ is the width of the bins.\n\n%The second one is Beta map:\n%\\[ \\phi(x,y) = \\frac{1}{B(\\mu+1, c-\\mu+1)}y^\\mu (1-y)^{c-\\mu} \\]\n%In this mapping there is no explicit notion of ``bin width\", but the value of $c$ can be thought of as a parameter controlling it: if the coverage $c$ is large, then the bin width is small, and vice versa.\n\n%In experiments, since it is impossible to write down $\\E[\\phi(x_1, \\cdot) \\otimes \\phi(x_2, \\cdot) \\otimes \\phi(x_3, \\cdot)]$ and perform tensor decomposition, we use discretization: compute an empirical version of $\\E[\\phi(x_1, y_1) \\otimes \\phi(x_2, y_2) \\otimes \\phi(x_3, y_3)]$, where $y_1, y_2, y_3$ is in $\\cbr{0,h,2h,\\ldots,1}$. By decomposing this tensor we are able to recover $\\E[\\phi(x, y) | h]$, where $y$ is in $\\cbr{0,h,2h,\\ldots,1}$. By mild regularity assumption on the distribution of $x$, this can give a fairly accurate estimate of $\\E[\\phi(x, y) | h]$ where $y$ ranges in the $[0,1]$ interval.\n\n\n\\subsection{Effect of Sample Size $l$}\nWe fix $m = 4$, $s = 1$, and vary the sample size (number of triples collected) $l =$ 1000, 10000, 20000, 40000, 80000, 160000, 320000. The samples are drawn without replacement from the original dataset. Figure~\\ref{fig:varyl} shows the result. Recall that the value of $m$ is the number of hidden states assumed; We observe that the output of the algorithm stablizes when $l \\geq 80000$. \\footnote{For the last few figures, although the colors of the lines in all subfigures are diffent, we observe that they have the same pattern.}\n\n\\begin{figure}[H]\n\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 10000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 10000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 20000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 20000$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 40000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 40000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 80000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 80000$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 160000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 160000$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$l = 320000$}\n    \\end{subfigure}\n    \\\\\n    \\end{tabular}\n\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for varying sample size $l$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varyl}\n\\end{figure}\n\n\n\\subsection{Effect of Specifying the Number of States}\n\nWe fix $l = 320000$, $s = 1$, and vary the number of states $m = 2,3,4,5,6,7,8,9$. Figure~\\ref{fig:varym} shows the columns of $\\E[\\phi(x)|h]$ recovered. The spectral algorithm provides reasonable results when $m \\leq 4$; when $m \\geq 5$, the algorithm started to recover observation columns that has a lot of negative entries.\n\n\n\\begin{figure}[H]\n\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 1_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 1$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 2_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_l/cell = E1_chr = 1_l = 320000_s = 1_m = 5_n = 30_phi = beta_full.pdf}\n        \\caption{$m = 5$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for varying number of states $m$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varym}\n\\end{figure}\n\n\\subsection{Binning Feature vs. Beta Feature}\n\nWe compare the experimental results using two types of feature maps $\\phi_{\\bin, n}$ and $\\phi_{\\bet, n}$. Although the two mappings are substantially different, their respective $\\E[\\phi(x)|h]$ have some similarities. In some sense, the beta mapping is performing a ``soft'' binning which takes into account the number count $c$ in $x$: fixing the value of methylation probability $m/c$, if $c$ is larger, then the beta mapping is closer to a binning mapping with smaller bin size. Figure~\\ref{fig:varyphi} shows the columns of the recovered $\\E[\\phi(x)|h]$ recovered. Generally, $\\phi_{\\bet, n}$ produces smoother observation columns, and the results are stabler than $\\phi_{\\bin, n}$.\n\n%-- double check this one experiment -- typo in file naming?\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n        \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = beta_full.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 30_phi = binning_igz.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 3$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 4$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_phi/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = binning_igz.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 4$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for $m = 3,4$ and two types of feature map $\\phi$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varyphi}\n\\end{figure}\n\n\\subsection{Effect of Number of Segments Combined}\nWe fix $l = 320000$, $m = 4$, and vary the number of merged segments $s = 1,2,3,4,5,6,7,8$. Figure~\\ref{fig:varys} shows the columns of the recovered $\\E[\\phi(x)|h]$. It can be seen that the recovered result is fairly insensitive to the choice of $s$.\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 1$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 2_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 3_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 4_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.45\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/vary_s/cell = E1_chr = 1_l = 320000_s = 5_m = 4_n = 30_phi = beta_full.pdf}\n        \\caption{$s = 5$}\n    \\end{subfigure}\n    \\end{tabular}\n\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for $m = 4$ and beta feature map $\\phi$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varys}\n\\end{figure}\n\n\\section{Experiments with CG methylations}\nIt is previously known that CG sites has different methylation behavior\ncompared to non-CG sites. We conduct experiments by merging the coverages and\nthe methylation counts only in contexts CGA, CGT, CGC, CGG (rows 13 to 16 of\nthe data).\n\n\\subsection{Effect of Number of Hidden States}\nOur first set of experiments is on investigating the effect of $m$, the number of hidden\nstates. We vary $m$ from 1 to 8, and plot the observation matrices in\nFigure~\\ref{fig:varymcg}.\n\nIt can be seen from the figures below that the range of plausible $m$'s are broader:\nunlike the full dataset where the observation columns start to have\nlarge negative entries starting from $m \\geq 4$, the CG subset still produces\npalusible output when $m = 5,6$. In addition, some hidden states recovered\nhas a large methylation probability, which is not observed in the full dataset\n(see e.g. Figure~\\ref{fig:varym}.)\n\n\\begin{figure}[H]\n\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 1_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 1$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 2_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 5_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 5$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 6_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 6$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 7_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 7$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 8_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$m = 8$}\n    \\end{subfigure}\n\n    \\end{tabular}\n\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for varying number of states $m$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varymcg}\n\\end{figure}\n\n\\subsection{Effects of Feature Maps}\nWe next conduct a set of comparisons between the beta feature map and the binning\nfeature map, setting the dimension of feature maps $n = 50$.\nIt can be seen that overall, binning features produce ``rougher''\nobservation columns. As with the range of plausible $m$'s, binning feature performs\nbadly when $m \\geq 5$, while beta feature consistently produces reasonable result\neven if $m = 5,6$. Both approaches output nonsensical observation matrices when\n$m = 7, 8$.\n\nIn addition, algorithm using the binning features cannot capture hidden states that has\nlow methylation probability (for all the hidden states, the conditional\nmethylation frequency histograms skew towards right).\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.4\\textwidth}\n      \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 2_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n      \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 2$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n      \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 2_n = 50_phi = binning_ctxt = 12131415.pdf}\n      \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 2$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 3$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 3_n = 50_phi = binning_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 3$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 4$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 4_n = 50_phi = binning_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 4$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 5_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 5$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 5_n = 50_phi = binning_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 5$}\n    \\end{subfigure}\n    \\end{tabular}\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for $m = 2,3,4,5$ and two types of feature map $\\phi$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varyphicg}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n    \\begin{subfigure}[t]{0.4\\textwidth}\n      \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 6_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n      \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 6$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n      \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 6_n = 50_phi = binning_ctxt = 12131415.pdf}\n      \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 6$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 7_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 7$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 7_n = 50_phi = binning_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 7$}\n    \\end{subfigure}\n    \\\\\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 8_n = 50_phi = beta_full_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bet, n}$ is beta mapping, $m = 8$}\n    \\end{subfigure}\n    &\n    \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/cg/cell = E1_chr = 1_l = 320000_s = 1_m = 8_n = 50_phi = binning_ctxt = 12131415.pdf}\n        \\caption{$\\phi = \\phi_{\\bin, n}$ is binning mapping, $m = 8$}\n    \\end{subfigure}\n    \\end{tabular}\n    \\caption{The observation columns of $\\E[\\phi(x)|h]$recovered, for $m = 6,7,8$ and two types of feature map $\\phi$. The $x$-axis is the value of $t = i/n$, the $y$-axis is the value of $(\\E[\\phi(x)|h])_i$.}\n    \\label{fig:varyphicg2}\n\\end{figure}\n\n\n\\section{Experiments with Posterior Decoding}\n\nWith the observation matrix $\\E[\\phi(x)|h]$, transition matrix $T$, and initial probability $\\pi$ recovered,\nwe apply posterior decoding to the original sequence to get estimates of hidden states in each position (every 100 base pairs).\n\nEmpirically we see the result of posterior decoding is similar to that of Viterbi decoding, therefore we present here only the results\nfor posterior decoding. For illustration purposes, we set the length of our test sequence to 100000; in principle it can be set arbitrarily long.\nWe set the size of our training set to be 320000.\n\nBelow we visualize the recovered hidden states using horizontal bar plots of different colors, each color represents a different outcome\nof hidden state. On the right panel, we plot the corresponding expected feature maps of hidden states, and the colors of feature map\ncurves are consistent with those in the bar plot.\n\nIt can be concluded from the plots that all the sequences we are working with are dominated by a certain hidden states. We observe that the\nobservation matrices recovered in the CG contexts are significantly different from that of CC, CT, CA contexts. In particular, the red hidden\nstate in the results of CC, CT, CA contexts represents one with a low methylation probability, whereas the red hidden state in the result of CG\nrepresents one whose methlation probablity is high.\n\n\\subsection{CC Context}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n  \\end{figure}\n\n\n    \\begin{figure}[H]\n        \\begin{tabular}{cc}\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123l_test = 320000_posterior.pdf}\n            \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n          \\end{subfigure}\n          &\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123_feature_map.pdf}\n            \\caption{Expected Feature map given the hidden states}\n          \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n\\end{figure}\n\n\n\\subsection{CT Context}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |4567l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |4567_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |4567l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |4567_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |4567l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |4567_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n  \\end{figure}\n\n\n    \\begin{figure}[H]\n        \\begin{tabular}{cc}\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |4567l_test = 320000_posterior.pdf}\n            \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n          \\end{subfigure}\n          &\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |4567_feature_map.pdf}\n            \\caption{Expected Feature map given the hidden states}\n          \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |4567l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |4567_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n\\end{figure}\n\n\\subsection{CA Context}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |891011l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |891011_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |891011l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |891011_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |891011l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |891011_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n  \\end{figure}\n\n\n    \\begin{figure}[H]\n        \\begin{tabular}{cc}\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |891011l_test = 320000_posterior.pdf}\n            \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n          \\end{subfigure}\n          &\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |891011_feature_map.pdf}\n            \\caption{Expected Feature map given the hidden states}\n          \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |891011l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |891011_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n\\end{figure}\n\n\\subsection{CG Context}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n  \\end{figure}\n\n\n    \\begin{figure}[H]\n        \\begin{tabular}{cc}\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |12131415l_test = 320000_posterior.pdf}\n            \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n          \\end{subfigure}\n          &\n          \\begin{subfigure}[t]{0.4\\textwidth}\n            \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |12131415_feature_map.pdf}\n            \\caption{Expected Feature map given the hidden states}\n          \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n\\end{figure}\n\n\\subsection{All Contexts}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123456789101112131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123456789101112131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123456789101112131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123456789101112131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123456789101112131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123456789101112131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\n  \\begin{figure}[H]\n      \\begin{tabular}{cc}\n        \\begin{subfigure}[t]{0.4\\textwidth}\n          \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123456789101112131415l_test = 320000_posterior.pdf}\n          \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n        \\end{subfigure}\n        &\n        \\begin{subfigure}[t]{0.4\\textwidth}\n          \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123456789101112131415_feature_map.pdf}\n          \\caption{Expected Feature map given the hidden states}\n        \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123456789101112131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123456789101112131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n    \\end{tabular}\n\\end{figure}\n\n\\section{Merging the Contexts using Conditional Independence}\n\nWe concatenate the feature representations in constexts CC, CA, CT and CG. For each\ncontext, the dimension is 10; hence in total the feature map is of 40 dimensions.\nMoreover, when performing posterior decoding, we assume the the observations are\nconditionally independent, that is, for all $i$, the observation probabililty satisfies\n\\begin{eqnarray*}\n  &&\\Pr[(m_t^{CC}, m_t^{CA}, m_t^{CT}, m_t^{CG}) | c_t^{CC}, c_t^{CA}, c_t^{CT}, c_t^{CG}, h_t = i] \\\\\n  &=&\n  \\Pr[m_t^{CC} | c_t^{CC}, h_t = i] \\Pr[m_t^{CA} | c_t^{CA}, h_t = i] \\Pr[m_t^{CT} | c_t^{CT}, h_t = i] \\Pr[m_t^{CG} | c_t^{CG}, h_t = i]\n\\end{eqnarray*}\n\nFrom the experiments below, we can see that the recovered hidden states are diverse,\nand corresponds to different methylation behaviors in different contexts.\n\n\n\\subsection{Cell type E sequences(E1 and E2)}\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell E, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = E_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\n\\subsection{Cell type V (sequences V8 and V9)}\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell V, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell V, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell V, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell V, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell V, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = V_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\n\\subsection{Cell type P (sequences P13P14 and P15P16)}\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell P, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 2_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell P, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 3_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell P, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 4_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\begin{tabular}{cc}\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell P, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 5_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n      \\\\\n      \\begin{subfigure}[t]{0.4\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415l_test = 320000_posterior.pdf}\n        \\caption{Posterior Decoding for a substring of methylation of cell P, chromosome 1.}\n      \\end{subfigure}\n      &\n      \\begin{subfigure}[t]{0.6\\textwidth}\n        \\includegraphics[width=\\textwidth]{figs/merge_ctxts/cell = P_chr = 1_l = 320000_s = 1_m = 6_n = 40_phi = beta_full_ctxt = |0123|4567|891011|12131415_feature_map.pdf}\n        \\caption{Expected Feature map given the hidden states}\n      \\end{subfigure}\n  \\end{tabular}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "eb44b52c7c97a0a8453d2514315e243498d74b6e", "size": 53535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "kernelbin/expt.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/expt.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/expt.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": 56.5311510032, "max_line_length": 687, "alphanum_fraction": 0.6705706547, "num_tokens": 17846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.6112023819921616}}
{"text": "%!TEX root = modelguide.tex\n\n\\chapter{Supporting classes}\n\nArtiSynth uses a large number of supporting classes, mostly defined in\nthe super package {\\tt maspack}, for handling mathematical and\ngeometric quantities. Those that are referred to in this manual are\nsummarized in this section.\n\n\\section{Vectors and matrices}\n\nAmong the most basic classes are those used to implement vectors and\nmatrices, defined in {\\tt maspack.matrix}. All vector classes implement\nthe interface \\javaclass[maspack.matrix]{Vector} and all matrix\nclasses implement \\javaclass[maspack.matrix]{Matrix}, which provide a\nnumber of standard methods for setting and accessing values and\nreading and writing from I/O streams. \n\nGeneral sized vectors and matrices are implemented by\n\\javaclass[maspack.matrix]{VectorNd} and\n\\javaclass[maspack.matrix]{MatrixNd}. These provide all the usual\nmethods for linear algebra operations such as addition, scaling, and\nmultiplication:\n%\n\\begin{lstlisting}[]\n  VectorNd v1 = new VectorNd (5);        // create a 5 element vector\n  VectorNd v2 = new VectorNd (5); \n  VectorNd vr = new VectorNd (5); \n  MatrixNd M = new MatrixNd (5, 5);      // create a 5 x 5 matrix\n\n  M.setIdentity();                       // M = I\n  M.scale (4);                           // M = 4*M\n\n  v1.set (new double[] {1, 2, 3, 4, 5}); // set values\n  v2.set (new double[] {0, 1, 0, 2, 0});\n  v1.add (v2);                           // v1 += v2\n  M.mul (vr, v1);                        // vr = M*v1\n\n  System.out.println (\"result=\" + vr.toString (\"%8.3f\"));\n\\end{lstlisting}\n%\nAs illustrated in the above example, vectors and matrices both provide\na {\\tt toString()} method that allows their elements to be formated\nusing a C-printf style format string. This is useful for providing\nconcise and uniformly formatted output, particularly for diagnostics.\nThe output from the above example is\n%\n\\begin{verbatim}\n  result=   4.000   12.000   12.000   24.000   20.000\n\\end{verbatim}\n%\nDetailed specifications for the format string are provided in the\ndocumentation for \\javamethod[maspack.util]{NumberFormat.set(String)}.\nIf either no format string, or the string {\\tt \"\\%g\"}, is specified,\n{\\tt toString()} formats all numbers using the full-precision output\nprovided by {\\tt Double.toString(value)}.\n\nFor computational efficiency, a number of fixed-size vectors and\nmatrices are also provided. The most commonly used are those defined\nfor three dimensions, including \\javaclass[maspack.matrix]{Vector3d}\nand \\javaclass[maspack.matrix]{Matrix3d}:\n%\n\\begin{lstlisting}[]\n  Vector3d v1 = new Vector3d (1, 2, 3);\n  Vector3d v2 = new Vector3d (3, 4, 5);\n  Vector3d vr = new Vector3d ();\n  Matrix3d M = new Matrix3d();\n\n  M.set (1, 2, 3,  4, 5, 6,  7, 8, 9);\n\n  M.mul (vr, v1);        // vr = M * v1\n  vr.scaledAdd (2, v2);  // vr += 2*v2;\n  vr.normalize();        // normalize vr\n  System.out.println (\"result=\" + vr.toString (\"%8.3f\"));\n\\end{lstlisting}\n%\n\n\\section{Rotations and transformations}\n\\label{RigidTransform3d:sec}\n\n{\\tt maspack.matrix} contains a number classes that implement rotation\nmatrices, rigid transforms, and affine transforms. \n\nRotations (Section \\ref{Rotations:sec}) are commonly described using a\n\\javaclass[maspack.matrix]{RotationMatrix3d}, which implements a\nrotation matrix and contains numerous methods for setting rotation\nvalues and transforming other quantities. Some of the more commonly\nused methods are:\n%\n\\begin{lstlisting}[]\n   RotationMatrix3d();         // create and set to the identity\n   RotationMatrix3d(u, angle); // create and set using an axis-angle\n\n   setAxisAngle (u, ang);      // set using an axis-angle\n   setRpy (roll, pitch, yaw);  // set using roll-pitch-yaw angles\n   setEuler (phi, theta, psi); // set using Euler angles\n   invert ();                  // invert this rotation\n   mul (R)                     // post multiply this rotation by R\n   mul (R1, R2);               // set this rotation to R1*R2\n   mul (vr, v1);               // vr = R*v1, where R is this rotation\n\\end{lstlisting}\n%\nRotations can also be described by\n\\javaclass[maspack.matrix]{AxisAngle}, which characterizes a rotation\nas a single rotation about a specific axis.\n\nRigid transforms (Section \\ref{RigidTransforms:sec}) are used by\nArtiSynth to describe a rigid body's pose, as well as its relative\nposition and orientation with respect to other bodies and coordinate\nframes.  They are implemented by\n\\javaclass[maspack.matrix]{RigidTransform3d}, which exposes its\nrotational and translational components directly through the fields\n{\\tt R} (a {\\tt RotationMatrix3d}) and {\\tt p} (a {\\tt\nVector3d}). Rotational and translational values can be set and\naccessed directly through these fields.  In addition, {\\tt\nRigidTransform3d} provides numerous methods, some of the more commonly\nused of which include:\n%\n\\begin{lstlisting}[]\n   RigidTransform3d();         // create and set to the identity\n   RigidTransfrom3d(x, y, z);  // create and set translation to x, y, z\n\n   // create and set translation to x, y, z and rotation to roll-pitch-yaw\n   RigidTransfrom3d(x, y, z, roll, pitch, yaw);\n\n   invert ();                  // invert this transform\n   mul (T)                     // post multiply this transform by T\n   mul (T1, T2);               // set this transform to T1*T2\n   mulLeftInverse (T1, T2);    // set this transform to inv(T1)*T2\n\\end{lstlisting}\n%\n\nAffine transforms (Section \\ref{AffineTransforms:sec}) are used by\nArtiSynth to effect scaling and shearing transformations on\ncomponents. They are implemented by\n\\javaclass[maspack.matrix]{AffineTransform3d}.\n\nRigid transformations are actually a specialized form of affine\ntransformation in which the basic transform matrix equals a rotation.\n{\\tt RigidTransform3d} and {\\tt AffineTransform3d} hence both derive\nfrom the same base class\n\\javaclass[maspack.matrix]{AffineTransform3dBase}.\n\n\\section{Points and Vectors}\n\nThe rotations and transforms described above can be used to transform\nboth vectors and points in space.\n\nVectors are most commonly implemented using\n\\javaclass[maspack.matrix]{Vector3d}, while points can be implemented\nusing the subclass \\javaclass[maspack.matrix]{Point3d}.  The only\ndifference between {\\tt Vector3d} and {\\tt Point3d} is that the former\nignores the translational component of rigid and affine transforms;\ni.e., as described in Sections \\ref{RigidTransforms:sec} and\n\\ref{AffineTransforms:sec}, a vector {\\tt v} has\nan implied homogeneous representation of\n%\n\\begin{equation}\n\\v^* \\equiv \\matl \\v \\\\ 0 \\matr,\n\\end{equation}\n%\nwhile the representation for a point {\\tt p} is\n%\n\\begin{equation}\n\\p^* \\equiv \\matl \\p \\\\ 1 \\matr.\n\\end{equation}\n%\n\nBoth classes provide a number of methods for applying rotational and\naffine transforms. Those used for rotations are\n%\n\\begin{lstlisting}[]\n  void transform (R);             // this = R * this\n  void transform (R, v1);         // this = R * v1\n  void inverseTransform (R);      // this = inverse(R) * this\n  void inverseTransform (R, v1);  // this = inverse(R) * v1\n\\end{lstlisting}\n%\nwhere {\\tt R} is a rotation matrix and {\\tt v1} is a vector (or a point\nin the case of {\\tt Point3d}).\n\nThe methods for applying rigid or affine transforms include:\n\\begin{lstlisting}[]\n  void transform (X);             // transforms this by X         \n  void transform (X, v1);         // sets this to v1 transformed by X\n  void inverseTransform (X);      // transforms this by the inverse of X\n  void inverseTransform (X, v1);  // sets this to v1 transformed by inverse of X\n\\end{lstlisting}\nwhere {\\tt X} is a rigid or affine transform.\nAs described above, in the case of {\\tt Vector3d}, these methods\nignore the translational part of the transform and apply only the\nmatrix component ({\\tt R} for a {\\tt RigidTransform3d} and {\\tt A} for\nan {\\tt AffineTransform3d}).\nIn particular, that means that for a {\\tt RigidTransform3d} given by {\\tt X}\nand a {\\tt Vector3d} given by {\\tt v},\nthe method calls\n%\n\\begin{lstlisting}[]\n  v.transform (X.R)\n  v.transform (X)\n\\end{lstlisting}\n%\nproduce the same result.\n\n\\section{Spatial vectors and inertias}\n\\label{SpatialVectors:sec}\n\nThe velocities, forces and inertias associated with 3D coordinate\nframes and rigid bodies are represented using the 6 DOF spatial\nquantities described in Sections \\ref{SpatialVelocitiesAndForces:sec}\nand \\ref{SpatialInertia:sec}. These are implemented by classes in the\npackage {\\tt maspack.spatialmotion}.\n\nSpatial velocities (or twists) are implemented by\n\\javaclass[maspack.spatialmotion]{Twist}, which exposes its\ntranslational and angular velocity components through the publicly\naccessible fields {\\tt v} and {\\tt w}, while spatial forces (or\nwrenches) are implemented by\n\\javaclass[maspack.spatialmotion]{Wrench}, which exposes its\ntranslational force and moment components through the publicly\naccessible fields {\\tt f} and {\\tt m}.\n\nBoth {\\tt Twist} and {\\tt Wrench} contain methods for algebraic\noperations such as addition and scaling. They also contain {\\tt\ntransform()} methods for applying rotational and rigid transforms.\nThe rotation methods simply transform each component by the supplied\nrotation matrix. The rigid transform methods, on the other hand,\nassume that the supplied argument represents a transform between two\nframes fixed within a rigid body, and transform the twist or wrench\naccordingly, using either (\\ref{XvelAB:eqn}) or (\\ref{XforceAB:eqn}).\n\nThe spatial inertia for a rigid body is implemented by\n\\javaclass[maspack.spatialmotion]{SpatialInertia}, which contains a\nnumber of methods for setting its value given various mass, center of\nmass, and inertia values, and querying the values of its components.\nIt also contains methods for scaling and adding, transforming between\ncoordinate systems, inversion, and multiplying by spatial vectors.\n\n\\section{Meshes}\n\\label{Meshes:sec}\n\nArtiSynth makes extensive use of 3D meshes, which are defined in {\\tt\nmaspack.geometry}.  They are used for a variety of purposes, including\nvisualization, collision detection, and computing physical properties\n(such as inertia or stiffness variation within a finite element\nmodel).\n\nA mesh is essentially a collection of vertices\n(i.e., points) that are topologically connected in some way.  All\nmeshes extend the abstract base class\n\\javaclass[maspack.geometry]{MeshBase}, which supports the vertex\ndefinitions, while subclasses provide the topology.\n\nThrough {\\tt MeshBase}, all meshes provide methods for\nadding and accessing vertices. Some of these include:\n%\n\\begin{lstlisting}[]\n  int numVertices();                 // return the number of vertices\n  Vertex3d getVertex (int idx);      // return the idx-th vertex\n  void addVertex (Vertex3d vtx);     // add vertex vtx to the mesh\n  Vertex3d addVertex (Point3d p);    // create and return a vertex at position p\n  void removeVertex (Vertex3d vtx);  // remove vertex vtx for the mesh\n  ArrayList<Vertex3d> getVertices(); // return the list of vertices\n\\end{lstlisting}\n%\nVertices are implemented by \\javaclass[maspack.geometry]{Vertex3d},\nwhich defines the position of the vertex (returned by the method\n\\javamethod*[maspack.geometry.Vertex3d]{getPosition()}), and also\ncontains support for topological connections. In addition, each vertex\nmaintains an index, obtainable via\n\\javamethod*[maspack.geometry.Vertex3d]{getIndex()}, that equals the\nindex of its location within the mesh's vertex list. This makes it\neasy to set up parallel array structures for augmenting mesh vertex\nproperties.\n\nMesh subclasses currently include:\n\n\\begin{description}\n\n\\item[\\protect{\\javaclass[maspack.geometry]{PolygonalMesh}}]\\mbox{}\n\nImplements a 2D surface\nmesh containing faces implemented using half-edges.\n\n\\item[\\protect{\\javaclass[maspack.geometry]{PolylineMesh}}]\\mbox{}\n\nImplements a mesh\nconsisting of connected line-segments (polylines).\n\n\\item[\\protect{\\javaclass[maspack.geometry]{PointMesh}}]\\mbox{}\n\nImplements a point cloud with\nno topological connectivity.\n\n\\end{description}\n\n\\javaclass[maspack.geometry]{PolygonalMesh} is used quite extensively\nand provides a number of methods for implementing faces, including:\n%\n\\begin{lstlisting}[]\n  int numFaces();                 // return the number of faces\n  Face getFace (int idx);         // return the idx-th face\n  Face addFace (int[] vidxs);     // create and add a face using vertex indices\n  void removeFace (Face f);       // remove the face f\n  ArrayList<Face> getFaces();     // return the list of faces\n\\end{lstlisting}\n%\nThe class \\javaclass[maspack.geometry]{Face} implements a face as a\ncounter-clockwise arrangement of vertices linked together by\nhalf-edges (class \\javaclass[maspack.geometry]{HalfEdge}).\n{\\tt Face} also supplies a face's (outward facing) normal\nvia \n\\javamethod[maspack.geometry.Face]{getNormal()}.\n\nSome mesh uses within ArtiSynth, such as collision detection, require a\n{\\it triangular} mesh; i.e., one where all faces have three vertices.\nThe method \\javamethod[maspack.geometry.PolygonalMesh]{isTriangular()}\ncan be used to check for this. Meshes that are not triangular can be\nmade triangular using \n\\javamethod[maspack.geometry.PolygonalMesh]{triangulate()}.\n\n\\subsection{Mesh creation}\n\nIt is possible to create a mesh by direct construction. For example,\nthe following code fragment creates a simple closed tetrahedral\nsurface:\n%\n\\begin{lstlisting}[]\n   // a simple four-faced tetrahedral mesh \n   PolygonalMesh mesh = new PolygonalMesh();\n   mesh.addVertex (0, 0, 0);\n   mesh.addVertex (1, 0, 0);\n   mesh.addVertex (0, 1, 0);\n   mesh.addVertex (0, 0, 1);\n   mesh.addFace (new int[] { 0, 2, 1 });\n   mesh.addFace (new int[] { 0, 3, 2 });\n   mesh.addFace (new int[] { 0, 1, 3 });\n   mesh.addFace (new int[] { 1, 2, 3 });      \n\\end{lstlisting}\n%\n\nHowever, meshes are more commonly created using either one of the\nfactory methods supplied by \\javaclass[maspack.geometry]{MeshFactory},\nor by reading a definition from a file (Section \\ref{MeshFileIO:sec}).\n\nSome of the more commonly used factory methods for creating polyhedral\nmeshes include:\n%\n\\begin{lstlisting}[]\n  MeshFactory.createSphere (radius, nslices, nlevels);\n  MeshFactory.createBox (widthx, widthy, widthz);\n  MeshFactory.createCylinder (radius, height, nslices);\n  MeshFactory.createPrism (double[] xycoords, height);\n  MeshFactory.createTorus (rmajor, rminor, nmajor, nminor);\n\\end{lstlisting}\n%\nEach factory method creates a mesh in some standard coordinate\nframe. After creation, the mesh can be transformed using the\n\\javamethodAlt{maspack.geometry.MeshBase.transform(AffineTransform3dBase)}%\n{transform(X)} method, where {\\tt X} is either a rigid transform (\n\\javaclass[maspack.matrix]{RigidTransform3d}) or a more general affine\ntransform (\\javaclass[maspack.matrix]{AffineTransform3d}).\nFor example, to create a rotated box centered on $(5, 6, 7)$,\none could do:\n%\n\\begin{lstlisting}[]\n  // create a box centered at the origin with widths 10, 20, 30:\n  PolygonalMesh box = MeshFactor.createBox (10, 20, 20);\n\n  // move the origin to 5, 6, 7 and rotate using roll-pitch-yaw\n  // angles 0, 0, 45 degrees:\n  box.transform (\n     new RigidTransform3d (5, 6, 7,  0, 0, Math.toRadians(45)));\n\\end{lstlisting}\n%\nOne can also scale a mesh using\n\\javamethodAlt{maspack.geometry.MeshBase.scale(double)}{scale(s)},\nwhere {\\tt s} is a single scale factor, or\n\\javamethodAlt{maspack.geometry.MeshBase.scale(double,double,double)}%\n{scale(sx,sy,sz)}, where {\\tt sx}, {\\tt sy}, and {\\tt sz} are separate\nscale factors for the x, y and z axes. This provides a useful way to\ncreate an ellipsoid:\n%\n\\begin{lstlisting}[]\n   // start with a unit sphere with 12 slices and 6 levels ...\n  PolygonalMesh ellipsoid = MeshFactor.createSphere (1.0, 12, 6);\n\n  // and then turn it into an ellipsoid by scaling about the axes:\n  ellipsoid.scale (1.0, 2.0, 3.0);\n\\end{lstlisting}\n%\n\\javaclass[maspack.geometry]{MeshFactory} can also be used to create\nnew meshes by performing boolean operations on existing ones:\n%\n\\begin{lstlisting}[]\n  MeshFactory.getIntersection (mesh1, mesh2);\n  MeshFactory.getUnion (mesh1, mesh2);\n  MeshFactory.getSubtraction (mesh1, mesh2);\n\\end{lstlisting}\n%\n\n\\subsection{Setting normals, colors, and textures}\n\nMeshes provide support for adding normal, color, and texture\ninformation, with the exact interpretation of these quantities\ndepending upon the particular mesh subclass. Most commonly this\ninformation is used simply for rendering, but in some cases normal\ninformation might also be used for physical simulation.\n\n\\begin{sideblock}\nFor polygonal meshes, the normal information described here is used\nonly for smooth shading. When flat shading is requested, normals are\ndetermined directly from the faces themselves.\n\\end{sideblock}\n\nNormal information can be set and queried using\nthe following methods:\n%\n\\begin{lstlisting}[]\n  setNormals (\n     List<Vector3d> nrmls, int[] indices);  // set all normals and indices\n\n  ArrayList<Vector3d> getNormals();         // get all normals\n  int[] getNormalIndices();                 // get all normal indices\n  int numNormals();                         // return the number of normals\n  Vector3d getNormal (int idx);             // get the normal at index idx\n\n  setNormal (int idx, Vector3d nrml);       // set the normal at index idx\n  clearNormals();                           // clear all normals and indices\n\\end{lstlisting}\n%\nThe method \\javamethod[maspack.geometry.MeshBase]{setNormals()} takes\ntwo arguments: a set of normal vectors ({\\tt nrmls}), along with a set\nof index values ({\\tt indices}) that map these normals onto the\nvertices of each of the mesh's geometric features. Often, there will\nbe one unique normal per vertex, in which case {\\tt nrmls} will have a\nsize equal to the number of vertices, but this is not always the case,\nas described below.  Features for the different mesh subclasses are:\nfaces for {\\tt PolygonalMesh}, polylines for {\\tt PolylineMesh}, and\nvertices for {\\tt PointMesh}.  If {\\tt indices} is specified as {\\tt\nnull}, then {\\tt normals} is assumed to have a size equal to the\nnumber of vertices, and an appropriate index set is created\nautomatically using\n\\javamethod[maspack.geometry.MeshBase]{createVertexIndices()}\n(described below). Otherwise, {\\tt indices} should have a size of\nequal to the number of features times the number of vertices per\nfeature. For example, consider a {\\tt PolygonalMesh} consisting of two\ntriangles formed from vertex indices (0, 1, 2) and (2, 1, 3),\nrespectively. If normals are specified and there is one unique normal\nper vertex, then the normal indices are likely to be\n%\n\\begin{verbatim}\n   [ 0 1 2  2 1 3 ]\n\\end{verbatim}\n%\nAs mentioned above, sometimes there may be {\\it more} than one normal\nper vertex. This happens in cases when the same vertex uses different\nnormals for different faces. In such situations, the size of the {\\tt\nnrmls} argument will exceed the number of vertices.\n\nThe method {\\tt setNormals()} makes internal copies of the specified\nnormal and index information, and this information can be\nlater read back using \n\\javamethod[maspack.geometry.MeshBase]{getNormals()} \nand\n\\javamethod[maspack.geometry.MeshBase]{getNormalIndices()}.\nThe number of normals can be queried using\n\\javamethod[maspack.geometry.MeshBase]{numNormals()},\nand individual normals can be queried or set using\n\\javamethodAlt{maspack.geometry.MeshBase.getNormal(int)}{getNormal(idx)}\nand\n\\javamethodAlt{maspack.geometry.MeshBase.setNormal(,)}{setNormal(idx,nrml)}.\nAll normals and indices can be explicitly cleared using \n\\javamethod[maspack.geometry.MeshBase]{clearNormals()}.\n\nColor and texture information can be set using analagous methods.\nFor colors, we have\n%\n\\begin{lstlisting}[]\n  setColors (\n     List<float[]> colors, int[] indices);  // set all colors and indices\n\n  ArrayList<float[]> getColors();           // get all colors\n  int[] getColorIndices();                  // get all color indices\n  int numColors();                          // return the number of colors\n  float[] getColor (int idx);               // get the color at index idx\n\n  setColor (int idx, float[] color);        // set the color at index idx\n  setColor (int idx, Color color);          // set the color at index idx\n  setColor (\n     int idx, float r, float g, float b, float a); // set the color at index idx\n  clearColors();                            // clear all colors and indices\n\\end{lstlisting}\n%\nWhen specified as {\\tt float[]}, colors are given as RGB or\nRGBA values, in the range $[0,1]$, with array lengths of 3 and 4,\nrespectively.  The colors returned by\n\\javamethod[maspack.geometry.MeshBase]{getColors()} are always RGBA\nvalues.\n\n%\nWith colors, there may often be {\\it fewer} colors than the number of\nvertices. For instance, we may have only two colors, indexed by 0 and\n1, and want to use these to alternately color the mesh faces. Using\nthe two-triangle example above, the color indices might then look like\nthis:\n%\n\\begin{verbatim}\n   [ 0 0 0 1 1 1 ]\n\\end{verbatim}\n%\n\nFinally, for texture coordinates, we have\n%\n\\begin{lstlisting}[]\n  setTextureCoords (\n     List<Vector3d> coords, int[] indices); // set all texture coords and indices\n\n  ArrayList<Vector3d> getTextureCoords();   // get all texture coords\n  int[] getTextureIndices();                // get all texture indices\n  int numTextureCoords();                   // return the number of texture coords\n  Vector3d getTextureCoords (int idx);      // get texture coords at index idx\n\n  setTextureCoords (int idx, Vector3d coords);// set texture coords at index idx\n  clearTextureCoords();                     // clear all texture coords and indices\n\\end{lstlisting}\n\nWhen specifying indices using \n\\javamethodAlt{maspack.geometry.MeshBase.setNormals(,)}{setNormals},\n\\javamethodAlt{maspack.geometry.MeshBase.setColors(,)}{setColors}, or\n\\javamethodAlt{maspack.geometry.MeshBase.setTextureCoords(,)}{setTextureCoords},\nit is common to use the same index set as that which\nassociates vertices with features. For convenience,\nthis index set can be created automatically using\n%\n\\begin{lstlisting}[]\n   int[] createVertexIndices();\n\\end{lstlisting}\n%\nAlternatively, we may sometimes want to create a index set\nthat assigns the same attribute to each feature vertex. If\nthere is one attribute per feature, the resulting\nindex set is called a {\\it feature index} set, and\ncan be created using\n%\n\\begin{lstlisting}[]\n   int[] createFeatureIndices();\n\\end{lstlisting}\n%\nIf we have a mesh with three triangles and one color per\ntriangle, the resulting feature index set would be\n%\n\\begin{verbatim}\n   [ 0 0 0 1 1 1 2 2 2 ]\n\\end{verbatim}\n%\n\n\\begin{sideblock}\nNote: when a mesh is modified by the {\\it addition} of new features\n(such as faces for \\javaclass[maspack.geometry]{PolygonalMesh}), all\nnormal, color and texture information is cleared by default (with\nnormal information being automatically recomputed on demand if\nautomatic normal creation is enabled; see Section \\ref{AutoNormalCreation:sec}).\nWhen a mesh is modified by the {\\it removal} of\nfeatures, the index sets for normals, colors and textures are adjusted\nto account for the removal.\n\nFor colors, it is possible to request that a mesh explicitly maintain\ncolors for either its vertices or features (Section\n\\ref{vertexAndFeatureColoring:sec}). When this is done, colors will\npersist when vertices or features are added or removed, with default\ncolors being automatically created as necessary.\n\\end{sideblock}\n\nOnce normals, colors, or textures have been set, \none may want to know which of these attributes are\nassociated with the vertices of a specific feature. To know this,\nit is necessary to find that feature's offset into the \nattribute's index set. This offset information can\nbe found using the array returned by\n%\n\\begin{lstlisting}[]\n  int[] getFeatureIndexOffsets()\n\\end{lstlisting}\n%\nFor example, the three normals associated with a triangle at index\n{\\tt ti} can be obtained using\n%\n\\begin{lstlisting}[]\n   int[] indexOffs = mesh.getFeatureIndexOffsets();\n   ArrayList<Vector3d> nrmls = mesh.getNormals();\n   // get the three normals associated with the triangle at index ti:\n   Vector3d n0 = nrmls.get (indexOffs[ti]);\n   Vector3d n1 = nrmls.get (indexOffs[ti]+1);\n   Vector3d n2 = nrmls.get (indexOffs[ti]+2);\n\\end{lstlisting}\n%\nAlternatively, one may use the convenience methods\n%\n\\begin{lstlisting}[]\n   Vector3d getFeatureNormal (int fidx, int k);\n   float[] getFeatureColor (int fidx, int k);\n   Vector3d getFeatureTextureCoords (int fidx, int k);\n\\end{lstlisting}\n%\nwhich return the attribute values for the $k$-th vertex of\nthe feature indexed by {\\tt fidx}.\n\nIn general, the various {\\tt get} methods return references to\ninternal storage information and so should\n{\\bf not} be modified. However, specific values within the lists\nreturned by \n\\javamethod[maspack.geometry.MeshBase]{getNormals()}, \n\\javamethod[maspack.geometry.MeshBase]{getColors()}, or\n\\javamethod[maspack.geometry.MeshBase]{getTextureCoords()}\nmay be modified by the application.  This may be\nnecessary when attribute information changes as the simultion\nproceeds. Alternatively, one may use methods such\nas \n\\javamethodAlt{maspack.geometry.MeshBase.setNormal(,)}{setNormal(idx,nrml)}\n\\javamethodAlt{maspack.geometry.MeshBase.setColor(int,float)}%\n{setColor(idx,color)}, or\n\\javamethodAlt{maspack.geometry.MeshBase.setTextureCoords(int,)}%\n{setTextureCoords(idx,coords)}.\n\nAlso, in some situations, particularly with colors and textures, it\nmay be desirable to {\\it not} have color or texture information\ndefined for certain features. In such cases, the corresponding index\ninformation can be specified as -1, and the {\\tt getNormal()}, {\\tt\ngetColor()} and {\\tt getTexture()} methods will return {\\tt null} for\nthe features in question.\n\n\\subsection{Automatic creation of normals and hard edges}\n\\label{AutoNormalCreation:sec}\n\nFor some mesh subclasses, if normals are not explicitly set, they are\ncomputed automatically whenever {\\tt getNormals()} or {\\tt\ngetNormalIndices()} is called. Whether or not this is true\nfor a particular mesh can be queried by the method\n%\n\\begin{lstlisting}[]\n   boolean hasAutoNormalCreation();\n\\end{lstlisting}\n%\nSetting normals explicitly, using a call to {\\tt\nsetNormals(nrmls,indices)}, will overwrite any existing normal information,\nautomatically computed or otherwise. The method\n%\n\\begin{lstlisting}[]\n   boolean hasExplicitNormals();\n\\end{lstlisting}\n%\nwill return {\\tt true} if normals have been explicitly set, and {\\tt\nfalse} if they have been automatically computed or if there is\ncurrently no normal information. To explicitly remove normals from a\nmesh which has automatic normal generation, one may call {\\tt\nsetNormals()} with the {\\tt nrmls} argument set to {\\tt null}.\n\nMore detailed control over how normals are automatically created may\nbe available for specific mesh subclasses. For example, {\\tt\nPolygonalMesh} allows normals to be created with multiple normals per\nvertex, for vertices that are associated with either open or hard\nedges. This ability can be controlled using the methods\n%\n\\begin{lstlisting}[]\n   boolean getMultipleAutoNormals();\n   setMultipleAutoNormals (boolean enable);\n\\end{lstlisting}\n%\nHaving multiple normals means that even with smooth shading, open or\nhard edges will still appear sharp. To make an edge hard within\na {\\tt PolygonalMesh}, one may use the methods\n%\n\\begin{lstlisting}[]\n   boolean setHardEdge (Vertex3d v0, Vertex3d v1);\n   boolean setHardEdge (int vidx0, int vidx1);\n   boolean hasHardEdge (Vertex3d v0, Vertex3d v1);\n   boolean hasHardEdge (int vidx0, int vidx1);\n   int numHardEdges();\n   int clearHardEdges();\n\\end{lstlisting}\n%\nwhich control the hardness of edges between individual vertices,\nspecified either directly or using their indices.\n\n\\subsection{Vertex and feature coloring}\n\\label{vertexAndFeatureColoring:sec}\n\nThe method \\javamethod[maspack.geometry.MeshBase]{setColors()} makes\nit possible to assign any desired coloring scheme to a mesh. However,\nit does require that the user explicity reset the color information\nwhenever new features are added.\n\nFor convenience, an application can also request that a mesh\nexplicitly maintain colors for either its vertices or features.  These\ncolors will then be maintained when vertices or features are added or\nremoved, with default colors being automatically created as necessary.\n\nVertex-based coloring can be requested with the method\n%\n\\begin{lstlisting}[]\n   setVertexColoringEnabled();\n\\end{lstlisting}\n%\nThis will create a separate (default) color for each of the mesh's\nvertices, and set the color indices to be equal to the vertex indices,\nwhich is equivalent to the call\n%\n\\begin{lstlisting}[]\n   setColors (colors, createVertexIndices());\n\\end{lstlisting}\n%\nwhere {\\tt colors} contains a default color for each\nvertex. However, once vertex coloring is enabled, the color and index\nsets will be updated whenever vertices or features are added or\nremoved. Meanwhile, applications can query or set the colors\nfor any vertex using {\\tt getColor(idx)}, or any of the\nvarious {\\tt setColor} methods.\nWhether or not vertex coloring\nis enabled can be queried using\n%\n\\begin{lstlisting}[]\n   getVertexColoringEnabled();\n\\end{lstlisting}\n%\nOnce vertex coloring is established, the application will typically\nwant to set the colors for all vertices, perhaps using a code fragment\nlike this:\n%\n\\begin{lstlisting}[]\n   mesh.setVertexColoringEnabled();\n   for (int i=0; i<mesh.numVertices(); i++) {\n      ... compute color for the vertex ...\n      mesh.setColor (i, color);\n   }\n\\end{lstlisting}\n%\n\nSimilarly, feature-based coloring can be requested using the method\n%\n\\begin{lstlisting}[]\n   setFeatureColoringEnabled();\n\\end{lstlisting}\n%\nThis will create a separate (default) color for each of the mesh's\nfeatures (faces for \n\\javaclass[maspack.geometry]{PolygonalMesh}, polylines for\n\\javaclass[maspack.geometry]{PolylineMesh}, etc.),\nand set the color indices to equal the feature \nindex set, which is equivalent to the call\n%\n\\begin{lstlisting}[]\n   setColors (colors, createFeatureIndices());\n\\end{lstlisting}\n%\nwhere {\\tt colors} contains a default color for each feature.\nApplications can query or set the colors\nfor any vertex using {\\tt getColor(idx)}, or any of the\nvarious {\\tt setColor} methods. Whether or not feature coloring\nis enabled can be queried using\n%\n\\begin{lstlisting}[]\n   getFeatureColoringEnabled();\n\\end{lstlisting}\n%\n\n\\subsection{Reading and writing mesh files}\n\\label{MeshFileIO:sec}\n\nThe package {\\tt maspack.geometry.io} supplies a number of classes for\nwriting and reading meshes to and from files of different formats.\n\nSome of the supported formats and their associated readers and writers\ninclude:\n\n\\begin{tabular}{|lll|}\n\\hline\nExtension & Format & Reader/writer classes \\\\\n\\hline\n.obj & Alias Wavefront & \\tt WavefrontReader, WavefrontWriter \\\\\n.ply & Polygon file format & \\tt PlyReader, PlyWriter \\\\\n.stl & STereoLithography & \\tt StlReader, StlWriter \\\\\n.gts & GNU triangulated surface & \\tt GtsReader, GtsWriter \\\\\n.off & Object file format & \\tt OffReader, OffWriter \\\\\n\\hline\n\\end{tabular}\n\nThe general usage pattern for these classes is to construct the\ndesired reader or writer with a path to the desired file, and then\ncall {\\tt readMesh()} or {\\tt writeMesh()} as appropriate:\n%\n\\begin{lstlisting}[]\n   // read a mesh from a .obj file:\n   WavefrontReader reader = new WavefrontReader (\"meshes/torus.obj\");\n   PolygonalMesh mesh = null;\n   try {\n      mesh = reader.readMesh();\n   }\n   catch (IOException e) {\n      System.err.println (\"Can't read mesh:\");\n      e.printStackTrace();\n   }\n\\end{lstlisting}\n%\nBoth {\\tt readMesh()} and {\\tt writeMesh()} may throw I/O exceptions,\nwhich must be either caught, as in the example above, or\nthrown out of the calling routine.\n\nFor convenience, one can also use the classes\n\\javaclass[maspack.geometry.io]{GenericMeshReader} or\n\\javaclass[maspack.geometry.io]{GenericMeshWriter}, which internally\ncreate an appropriate reader or writer based on the file\nextension. This enables the writing of code\nthat does not depend on the file format:\n%\n\\begin{lstlisting}[]\n   String fileName;\n   ...\n   PolygonalMesh mesh = null;\n   try {\n      mesh = (PolygonalMesh)GenericMeshReader.readMesh(fileName);\n   }\n   catch (IOException e) {\n      System.err.println (\"Can't read mesh:\");\n      e.printStackTrace();\n   }\n\\end{lstlisting}\n%\nHere, {\\tt fileName} can refer to a mesh of any format supported by\n{\\tt GenericMeshReader}. Note that the mesh returned by {\\tt\nreadMesh()} is explicitly cast to {\\tt PolygonalMesh}.  This is\nbecause {\\tt readMesh()} returns the superclass {\\tt MeshBase}, since\nthe default mesh created for some file formats may be different from\n{\\tt PolygonalMesh}.\n\n\\subsection{Reading and writing normal and texture information}\n\nWhen writing a mesh out to a file, normal and texture information are\nalso written if they have been explicitly set and the file format\nsupports it. In addition, by default, automatically generated normal\ninformation will also be written if it relies on information (such as\nhard edges) that can't be reconstructed from the stored file\ninformation.\n\nWhether or not normal information will be written is returned by the\nmethod\n%\n\\begin{lstlisting}[]\n   boolean getWriteNormals();\n\\end{lstlisting}\n%\nThis will always return {\\tt true} if any of the conditions described\nabove have been met.  So for example, if a {\\tt PolygonalMesh}\ncontains hard edges, and multiple automatic normals are enabled (i.e.,\n{\\tt getMultipleAutoNormals()} returns {\\tt true}), then {\\tt\ngetWriteNormals()} will return {\\tt true}.\n\nDefault normal writing behavior can be overridden within \nthe \\javaclass[maspack.geometry.io]{MeshWriter} classes\nusing the following methods:\n%\n\\begin{lstlisting}[]\n   int getWriteNormals()\n   setWriteNormals (enable)\n\\end{lstlisting}\n%\nwhere {\\tt enable} should be one of the following values:\n\\begin{description}\n\\item[ 0] normals will {\\it never} be written;\n\\item[ 1] normals will {\\it always} be written;\n\\item[-1] normals will written according to the default behavior \ndescribed above.\n\\end{description}\n\nWhen reading a {\\tt PolygonalMesh} from a file, if the file contains\nnormal information with multiple normals per vertex that suggests the\nexistence of hard edges, then the corresponding edges are set to be\nhard within the mesh.\n", "meta": {"hexsha": "08610ce3111bf0c2307e3e22a181c38d5bfd7430", "size": 34330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/modelguide/supportingClasses.tex", "max_stars_repo_name": "gaetanbahl/carapas", "max_stars_repo_head_hexsha": "71c9b9355b740b7312da1a579e4bff5175eb100b", "max_stars_repo_licenses": ["Apache-2.0", "BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-01-12T15:42:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T10:08:17.000Z", "max_issues_repo_path": "doc/modelguide/supportingClasses.tex", "max_issues_repo_name": "gaetanbahl/carapas", "max_issues_repo_head_hexsha": "71c9b9355b740b7312da1a579e4bff5175eb100b", "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/supportingClasses.tex", "max_forks_repo_name": "gaetanbahl/carapas", "max_forks_repo_head_hexsha": "71c9b9355b740b7312da1a579e4bff5175eb100b", "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": 39.055745165, "max_line_length": 83, "alphanum_fraction": 0.7438100786, "num_tokens": 8607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6110590055309941}}
{"text": "\\chapter{Supervised learning methods}\n\nNote the supervised learning methods described in this chapter all require Numerical Python (numpy) to be installed.\n\n\\section{The Logistic Regression Model}\n\\label{sec:LogisticRegression}\n\n\\subsection{Background and Purpose}\n\nLogistic regression is a supervised learning approach that attempts to distinguish $K$ classes from each other using a weighted sum of some predictor variables $x_i$. The logistic regression model is used to calculate the weights $\\beta_i$ of the predictor variables. In Biopython, the logistic regression model is currently implemented for two classes only ($K = 2$); the number of predictor variables has no predefined limit.\n\nAs an example, let's try to predict the operon structure in bacteria. An operon is a set of adjacent genes on the same strand of DNA that  are transcribed into a single mRNA molecule. Translation of the single mRNA molecule then yields the individual proteins. For {\\it Bacillus subtilis}, whose data we will be using, the average number of genes in an operon is about 2.4.\n\nAs a first step in understanding gene regulation in bacteria, we need to know the operon structure. For about 10\\% of the genes in {\\it Bacillus subtilis}, the operon structure is known from experiments. A supervised learning method can be used to predict the operon structure for the remaining 90\\% of the genes.\n\nFor such a supervised learning approach, we need to choose some predictor variables $x_i$ that can be measured easily and are somehow related to the operon structure. One predictor variable might be the distance in base pairs between genes. Adjacent genes belonging to the same operon tend to be separated by a relatively short distance, whereas adjacent genes in different operons tend to have a larger space between them to allow for promoter and terminator sequences. Another predictor variable is based on gene expression measurements. By definition, genes belonging to the same operon have equal gene expression profiles, while genes in different operons are expected to have different expression profiles. In practice, the measured expression profiles of genes in the same operon are not quite identical due to the presence of measurement errors. To assess the similarity in the gene expression profiles, we assume that the measurement errors follow a normal distribution and calculate the corresponding log-likelihood score.\n\nWe now have two predictor variables that we can use to predict if two adjacent genes on the same strand of DNA belong to the same operon:\n\\begin{itemize}\n\\item $x_1$: the number of base pairs between them;\n\\item $x_2$: their similarity in expression profile.\n\\end{itemize}\n\nIn a logistic regression model, we use a weighted sum of these two predictors to calculate a joint score $S$:\n\\begin{equation}\nS = \\beta_0 + \\beta_1 x_1 + \\beta_2 x_2.\n\\end{equation}\nThe logistic regression model gives us appropriate values for the parameters $\\beta_0$, $\\beta_1$, $\\beta_2$ using two sets of example genes:\n\\begin{itemize}\n\\item OP: Adjacent genes, on the same strand of DNA, known to belong to the same operon;\n\\item NOP: Adjacent genes, on the same strand of DNA, known to belong to different operons.\n\\end{itemize}\n\nIn the logistic regression model, the probability of belonging to a class depends on the score via the logistic function. For the two classes OP and NOP, we can write this as\n\\begin{eqnarray}\n\\Pr(\\mathrm{OP}|x_1, x_2) & = & \\frac{\\exp(\\beta_0 + \\beta_1 x_1 + \\beta_2 x_2)}{1+\\exp(\\beta_0 + \\beta_1 x_1 + \\beta_2 x_2)} \\label{eq:OP} \\\\\n\\Pr(\\mathrm{NOP}|x_1, x_2) & = & \\frac{1}{1+\\exp(\\beta_0 + \\beta_1 x_1 + \\beta_2 x_2)} \\label{eq:NOP}\n\\end{eqnarray}\nUsing a set of gene pairs for which it is known whether they belong to the same operon (class OP) or to different operons (class NOP), we can calculate the weights $\\beta_0$, $\\beta_1$, $\\beta_2$ by maximizing the log-likelihood corresponding to the probability functions (\\ref{eq:OP}) and (\\ref{eq:NOP}).\n\n\\subsection{Training the logistic regression model}\n\\label{subsec:LogisticRegressionTraining}\n\n\\begin{table}[h]\n\\begin{center}\n\\caption{Adjacent gene pairs known to belong to the same operon (class OP) or to different operons (class NOP). Intergene distances are negative if the two genes overlap.}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\nGene pair & Intergene distance ($x_1$) & Gene expression score ($x_2$) & Class\\\\\n\\hline\n{\\it cotJA} --- {\\it cotJB} & -53 & -200.78 & OP\\\\\n{\\it yesK} --- {\\it yesL} & 117 & -267.14 & OP\\\\\n{\\it lplA} --- {\\it lplB} & 57 & -163.47 & OP\\\\\n{\\it lplB} --- {\\it lplC} & 16 & -190.30 & OP\\\\\n{\\it lplC} --- {\\it lplD} & 11 & -220.94 & OP\\\\\n{\\it lplD} --- {\\it yetF} & 85 & -193.94 & OP\\\\\n{\\it yfmT} --- {\\it yfmS} & 16 & -182.71 & OP\\\\\n{\\it yfmF} --- {\\it yfmE} & 15 & -180.41 & OP\\\\\n{\\it citS} --- {\\it citT} & -26 & -181.73 & OP\\\\\n{\\it citM} --- {\\it yflN} & 58 & -259.87 & OP\\\\\n{\\it yfiI} --- {\\it yfiJ} & 126 & -414.53 & NOP\\\\\n{\\it lipB} --- {\\it yfiQ} & 191 & -249.57 & NOP\\\\\n{\\it yfiU} --- {\\it yfiV} & 113 & -265.28 & NOP\\\\\n{\\it yfhH} --- {\\it yfhI} & 145 & -312.99 & NOP\\\\\n{\\it cotY} --- {\\it cotX} & 154 & -213.83 & NOP\\\\\n{\\it yjoB} --- {\\it rapA} & 147 & -380.85 & NOP\\\\\n{\\it ptsI} --- {\\it splA} & 93 & -291.13 & NOP \\\\\n\\hline\n\\end{tabular}\n\\label{table:training}\n\\end{center}\n\\end{table}\n\nTable \\ref{table:training} lists some of the {\\it Bacillus subtilis} gene pairs for which the operon structure is known.\nLet's calculate the logistic regression model from these data:\n\n%NOTE - can't use this as a doctest in case NumPy is missing (Jython).\n%Also the ... are missing but that means the user can copy/paste the example.\n\\begin{verbatim}\n>>> from Bio import LogisticRegression\n>>> xs = [[-53, -200.78],\n          [117, -267.14],\n          [57, -163.47],\n          [16, -190.30],\n          [11, -220.94],\n          [85, -193.94],\n          [16, -182.71],\n          [15, -180.41],\n          [-26, -181.73],\n          [58, -259.87],\n          [126, -414.53],\n          [191, -249.57],\n          [113, -265.28],\n          [145, -312.99],\n          [154, -213.83],\n          [147, -380.85],\n          [93, -291.13]]\n>>> ys = [1,\n          1,\n          1,\n          1,\n          1,\n          1,\n          1,\n          1,\n          1,\n          1,\n          0,\n          0,\n          0,\n          0,\n          0,\n          0,\n          0]\n>>> model = LogisticRegression.train(xs, ys)\n\\end{verbatim}\n\nHere, \\verb+xs+ and \\verb+ys+ are the training data: \\verb+xs+ contains the predictor variables for each gene pair, and \\verb+ys+ specifies if the gene pair belongs to the same operon (\\verb+1+, class OP) or different operons (\\verb+0+, class NOP). The resulting logistic regression model is stored in \\verb+model+, which contains the weights $\\beta_0$, $\\beta_1$, and $\\beta_2$:\n\n\\begin{verbatim}\n>>> model.beta\n[8.9830290157144681, -0.035968960444850887, 0.02181395662983519]\n\\end{verbatim}\n\nNote that $\\beta_1$ is negative, as gene pairs with a shorter intergene distance have a higher probability of belonging to the same operon (class OP). On the other hand, $\\beta_2$ is positive, as gene pairs belonging to the same operon typically have a higher similarity score of their gene expression profiles.\nThe parameter $\\beta_0$ is positive due to the higher prevalence of operon gene pairs than non-operon gene pairs in the training data.\n\nThe function \\verb+train+ has two optional arguments: \\verb+update_fn+ and \\verb+typecode+. The \\verb+update_fn+ can be used to specify a callback function, taking as arguments the iteration number and the log-likelihood. With the callback function, we can for example track the progress of the model calculation (which uses a Newton-Raphson iteration to maximize the log-likelihood function of the logistic regression model):\n\n\\begin{verbatim}\n>>> def show_progress(iteration, loglikelihood):\n        print(\"Iteration:\", iteration, \"Log-likelihood function:\", loglikelihood)\n>>>\n>>> model = LogisticRegression.train(xs, ys, update_fn=show_progress)\nIteration: 0 Log-likelihood function: -11.7835020695\nIteration: 1 Log-likelihood function: -7.15886767672\nIteration: 2 Log-likelihood function: -5.76877209868\nIteration: 3 Log-likelihood function: -5.11362294338\nIteration: 4 Log-likelihood function: -4.74870642433\nIteration: 5 Log-likelihood function: -4.50026077146\nIteration: 6 Log-likelihood function: -4.31127773737\nIteration: 7 Log-likelihood function: -4.16015043396\nIteration: 8 Log-likelihood function: -4.03561719785\nIteration: 9 Log-likelihood function: -3.93073282192\nIteration: 10 Log-likelihood function: -3.84087660929\nIteration: 11 Log-likelihood function: -3.76282560605\nIteration: 12 Log-likelihood function: -3.69425027154\nIteration: 13 Log-likelihood function: -3.6334178602\nIteration: 14 Log-likelihood function: -3.57900855837\nIteration: 15 Log-likelihood function: -3.52999671386\nIteration: 16 Log-likelihood function: -3.48557145163\nIteration: 17 Log-likelihood function: -3.44508206139\nIteration: 18 Log-likelihood function: -3.40799948447\nIteration: 19 Log-likelihood function: -3.3738885624\nIteration: 20 Log-likelihood function: -3.3423876581\nIteration: 21 Log-likelihood function: -3.31319343769\nIteration: 22 Log-likelihood function: -3.2860493346\nIteration: 23 Log-likelihood function: -3.2607366863\nIteration: 24 Log-likelihood function: -3.23706784091\nIteration: 25 Log-likelihood function: -3.21488073614\nIteration: 26 Log-likelihood function: -3.19403459259\nIteration: 27 Log-likelihood function: -3.17440646052\nIteration: 28 Log-likelihood function: -3.15588842703\nIteration: 29 Log-likelihood function: -3.13838533947\nIteration: 30 Log-likelihood function: -3.12181293595\nIteration: 31 Log-likelihood function: -3.10609629966\nIteration: 32 Log-likelihood function: -3.09116857282\nIteration: 33 Log-likelihood function: -3.07696988017\nIteration: 34 Log-likelihood function: -3.06344642288\nIteration: 35 Log-likelihood function: -3.05054971191\nIteration: 36 Log-likelihood function: -3.03823591619\nIteration: 37 Log-likelihood function: -3.02646530573\nIteration: 38 Log-likelihood function: -3.01520177394\nIteration: 39 Log-likelihood function: -3.00441242601\nIteration: 40 Log-likelihood function: -2.99406722296\nIteration: 41 Log-likelihood function: -2.98413867259\n\\end{verbatim}\n\nThe iteration stops once the increase in the log-likelihood function is less than 0.01. If no convergence is reached after 500 iterations, the \\verb+train+ function returns with an \\verb+AssertionError+.\n\nThe optional keyword \\verb+typecode+ can almost always be ignored. This keyword allows the user to choose the type of Numeric matrix to use. In particular, to avoid memory problems for very large problems, it may be necessary to use single-precision floats (Float8, Float16, etc.) rather than double, which is used by default.\n\n\\subsection{Using the logistic regression model for classification}\n\nClassification is performed by calling the \\verb+classify+ function. Given a logistic regression model and the values for $x_1$ and $x_2$ (e.g. for a gene pair of unknown operon structure), the \\verb+classify+ function returns \\verb+1+ or \\verb+0+, corresponding to class OP and class NOP, respectively. For example, let's consider the gene pairs {\\it yxcE}, {\\it yxcD} and {\\it yxiB}, {\\it yxiA}:\n\n\\begin{table}[h]\n\\begin{center}\n\\caption{Adjacent gene pairs of unknown operon status.}\n\\begin{tabular}{|c|c|c|}\n\\hline\nGene pair & Intergene distance $x_1$ & Gene expression score $x_2$ \\\\\n\\hline\n{\\it yxcE} --- {\\it yxcD} & 6 & -173.143442352 \\\\\n{\\it yxiB} --- {\\it yxiA} & 309 & -271.005880394 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\nThe logistic regression model classifies {\\it yxcE}, {\\it yxcD} as belonging to the same operon (class OP), while {\\it yxiB}, {\\it yxiA} are predicted to belong to different operons:\n\\begin{verbatim}\n>>> print(\"yxcE, yxcD:\", LogisticRegression.classify(model, [6, -173.143442352]))\nyxcE, yxcD: 1\n>>> print(\"yxiB, yxiA:\", LogisticRegression.classify(model, [309, -271.005880394]))\nyxiB, yxiA: 0\n\\end{verbatim}\n(which, by the way, agrees with the biological literature).\n\nTo find out how confident we can be in these predictions, we can call the \\verb+calculate+ function to obtain the probabilities (equations (\\ref{eq:OP}) and \\ref{eq:NOP}) for class OP and NOP. For {\\it yxcE}, {\\it yxcD} we find\n\\begin{verbatim}\n>>> q, p = LogisticRegression.calculate(model, [6, -173.143442352])\n>>> print(\"class OP: probability =\", p, \"class NOP: probability =\", q)\nclass OP: probability = 0.993242163503 class NOP: probability = 0.00675783649744\n\\end{verbatim}\nand for {\\it yxiB}, {\\it yxiA}\n\\begin{verbatim}\n>>> q, p = LogisticRegression.calculate(model, [309, -271.005880394])\n>>> print(\"class OP: probability =\", p, \"class NOP: probability =\", q)\nclass OP: probability = 0.000321211251817 class NOP: probability = 0.999678788748\n\\end{verbatim}\n\nTo get some idea of the prediction accuracy of the logistic regression model, we can apply it to the training data:\n\\begin{verbatim}\n>>> for i in range(len(ys)):\n        print(\"True:\", ys[i], \"Predicted:\", LogisticRegression.classify(model, xs[i]))\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\n\\end{verbatim}\nshowing that the prediction is correct for all but one of the gene pairs. A more reliable estimate of the prediction accuracy can be found from a leave-one-out analysis, in which the model is recalculated from the training data after removing the gene to be predicted:\n\\begin{verbatim}\n>>> for i in range(len(ys)):\n        model = LogisticRegression.train(xs[:i]+xs[i+1:], ys[:i]+ys[i+1:])\n        print(\"True:\", ys[i], \"Predicted:\", LogisticRegression.classify(model, xs[i]))\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 1\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\n\\end{verbatim}\nThe leave-one-out analysis shows that the prediction of the logistic regression model is incorrect for only two of the gene pairs, which corresponds to a prediction accuracy of 88\\%.\n\n\\subsection{Logistic Regression, Linear Discriminant Analysis, and Support Vector Machines}\n\nThe logistic regression model is similar to linear discriminant analysis. In linear discriminant analysis, the class probabilities also follow equations (\\ref{eq:OP}) and (\\ref{eq:NOP}). However, instead of estimating the coefficients $\\beta$ directly, we first fit a normal distribution to the predictor variables $x$. The coefficients $\\beta$ are then calculated from the means and covariances of the normal distribution. If the distribution of $x$ is indeed normal, then we expect linear discriminant analysis to perform better than the logistic regression model. The logistic regression model, on the other hand, is more robust to deviations from normality.\n\nAnother similar approach is a support vector machine with a linear kernel. Such an SVM also uses a linear combination of the predictors, but estimates the coefficients $\\beta$ from the predictor variables $x$ near the boundary region between the classes. If the logistic regression model (equations (\\ref{eq:OP}) and (\\ref{eq:NOP})) is a good description for $x$ away from the boundary region, we expect the logistic regression model to perform better than an SVM with a linear kernel, as it relies on more data. If not, an SVM with a linear kernel may perform better.\n\nTrevor Hastie, Robert Tibshirani, and Jerome Friedman: {\\it The Elements of Statistical Learning. Data Mining, Inference, and Prediction}. Springer Series in Statistics, 2001. Chapter 4.4.\n\n\\section{$k$-Nearest Neighbors}\n\n\\subsection{Background and purpose}\n\nThe $k$-nearest neighbors method is a supervised learning approach that does not need to fit a model to the data. Instead, data points are classified based on the categories of the $k$ nearest neighbors in the training data set.\n\nIn Biopython, the $k$-nearest neighbors method is available in \\verb+Bio.kNN+. To illustrate the use of the $k$-nearest neighbor method in Biopython, we will use the same operon data set as in section \\ref{sec:LogisticRegression}.\n\n\\subsection{Initializing a $k$-nearest neighbors model}\n\nUsing the data in Table \\ref{table:training}, we create and initialize a $k$-nearest neighbors model as follows:\n\n\\begin{verbatim}\n>>> from Bio import kNN\n>>> k = 3\n>>> model = kNN.train(xs, ys, k)\n\\end{verbatim}\n\nwhere \\verb+xs+ and \\verb+ys+ are the same as in Section \\ref{subsec:LogisticRegressionTraining}. Here, \\verb+k+ is the number of neighbors $k$ that will be considered for the classification. For classification into two classes, choosing an odd number for $k$ lets you avoid tied votes. The function name \\verb+train+ is a bit of a misnomer, since no model training is done: this function simply stores \\verb+xs+, \\verb+ys+, and \\verb+k+ in \\verb+model+.\n\n\\subsection{Using a $k$-nearest neighbors model for classification}\n\nTo classify new data using the $k$-nearest neighbors model, we use the \\verb+classify+ function. This function takes a data point $(x_1,x_2)$ and finds the $k$-nearest neighbors in the training data set \\verb+xs+. The data point $(x_1, x_2)$ is then classified based on which category (\\verb+ys+) occurs most among the $k$ neighbors.\n\nFor the example of the gene pairs {\\it yxcE}, {\\it yxcD} and {\\it yxiB}, {\\it yxiA}, we find:\n\\begin{verbatim}\n>>> x = [6, -173.143442352]\n>>> print(\"yxcE, yxcD:\", kNN.classify(model, x))\nyxcE, yxcD: 1\n>>> x = [309, -271.005880394]\n>>> print(\"yxiB, yxiA:\", kNN.classify(model, x))\nyxiB, yxiA: 0\n\\end{verbatim}\nIn agreement with the logistic regression model, {\\it yxcE}, {\\it yxcD} are classified as belonging to the same operon (class OP), while {\\it yxiB}, {\\it yxiA} are predicted to belong to different operons.\n\nThe \\verb+classify+ function lets us specify both a distance function and a weight function as optional arguments. The distance function affects which $k$ neighbors are chosen as the nearest neighbors, as these are defined as the neighbors with the smallest distance to the query point $(x, y)$. By default, the Euclidean distance is used. Instead, we could for example use the city-block (Manhattan) distance:\n\n\\begin{verbatim}\n>>> def cityblock(x1, x2):\n...    assert len(x1)==2\n...    assert len(x2)==2\n...    distance = abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])\n...    return distance\n...\n>>> x = [6, -173.143442352]\n>>> print(\"yxcE, yxcD:\", kNN.classify(model, x, distance_fn = cityblock))\nyxcE, yxcD: 1\n\\end{verbatim}\n\nThe weight function can be used for weighted voting. For example, we may want to give closer neighbors a higher weight than neighbors that are further away:\n\n\\begin{verbatim}\n>>> def weight(x1, x2):\n...    assert len(x1)==2\n...    assert len(x2)==2\n...    return exp(-abs(x1[0]-x2[0]) - abs(x1[1]-x2[1]))\n...\n>>> x = [6, -173.143442352]\n>>> print(\"yxcE, yxcD:\", kNN.classify(model, x, weight_fn = weight))\nyxcE, yxcD: 1\n\\end{verbatim}\nBy default, all neighbors are given an equal weight.\n\nTo find out how confident we can be in these predictions, we can call the \\verb+calculate+ function, which will calculate the total weight assigned to the classes OP and NOP. For the default weighting scheme, this reduces to the number of neighbors in each category. For {\\it yxcE}, {\\it yxcD}, we find\n\\begin{verbatim}\n>>> x = [6, -173.143442352]\n>>> weight = kNN.calculate(model, x)\n>>> print(\"class OP: weight =\", weight[0], \"class NOP: weight =\", weight[1])\nclass OP: weight = 0.0 class NOP: weight = 3.0\n\\end{verbatim}\nwhich means that all three neighbors of \\verb+x1+, \\verb+x2+ are in the NOP class. As another example, for {\\it yesK}, {\\it yesL} we find\n\n\\begin{verbatim}\n>>> x = [117, -267.14]\n>>> weight = kNN.calculate(model, x)\n>>> print(\"class OP: weight =\", weight[0], \"class NOP: weight =\", weight[1])\nclass OP: weight = 2.0 class NOP: weight = 1.0\n\\end{verbatim}\nwhich means that two neighbors are operon pairs and one neighbor is a non-operon pair.\n\nTo get some idea of the prediction accuracy of the $k$-nearest neighbors approach, we can apply it to the training data:\n\\begin{verbatim}\n>>> for i in range(len(ys)):\n        print(\"True:\", ys[i], \"Predicted:\", kNN.classify(model, xs[i]))\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\n\\end{verbatim}\nshowing that the prediction is correct for all but two of the gene pairs. A more reliable estimate of the prediction accuracy can be found from a leave-one-out analysis, in which the model is recalculated from the training data after removing the gene to be predicted:\n\\begin{verbatim}\n>>> k = 3\n>>> for i in range(len(ys)):\n        model = kNN.train(xs[:i]+xs[i+1:], ys[:i]+ys[i+1:], k)\n        print(\"True:\", ys[i], \"Predicted:\", kNN.classify(model, xs[i]))\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 1\nTrue: 1 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 1\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 0\nTrue: 0 Predicted: 1\n\\end{verbatim}\nThe leave-one-out analysis shows that $k$-nearest neighbors model is correct for 13 out of 17 gene pairs, which corresponds to a prediction accuracy of 76\\%.\n\n\\section{Na\\\"ive Bayes}\n\nThis section will describe the \\verb|Bio.NaiveBayes| module.\n\n\\section{Maximum Entropy}\n\nThis section will describe the \\verb|Bio.MaximumEntropy| module.\n\n\\section{Markov Models}\n\nThis section will describe the \\verb|Bio.MarkovModel| and/or \\verb|Bio.HMM.MarkovModel| modules.\n\n", "meta": {"hexsha": "1415d5b3e8cd42e3b074dfdb5e05d7d71e299f56", "size": 22295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Doc/Tutorial/chapter_learning.tex", "max_stars_repo_name": "amblina/biopython", "max_stars_repo_head_hexsha": "5045a7a3e86d5b32e0eaab941ab35daac86c59f8", "max_stars_repo_licenses": ["PostgreSQL"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-11-21T09:55:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-09T17:39:43.000Z", "max_issues_repo_path": "Doc/Tutorial/chapter_learning.tex", "max_issues_repo_name": "amblina/biopython", "max_issues_repo_head_hexsha": "5045a7a3e86d5b32e0eaab941ab35daac86c59f8", "max_issues_repo_licenses": ["PostgreSQL"], "max_issues_count": 32, "max_issues_repo_issues_event_min_datetime": "2016-11-21T07:38:21.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-16T13:00:03.000Z", "max_forks_repo_path": "Doc/Tutorial/chapter_learning.tex", "max_forks_repo_name": "amblina/biopython", "max_forks_repo_head_hexsha": "5045a7a3e86d5b32e0eaab941ab35daac86c59f8", "max_forks_repo_licenses": ["PostgreSQL"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-11-24T18:57:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:15:25.000Z", "avg_line_length": 53.3373205742, "max_line_length": 1031, "alphanum_fraction": 0.7272034088, "num_tokens": 6478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388040954683, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6110590009720267}}
{"text": "\\documentclass[12pt]{article}\n    \\usepackage{mathtools}\n    \\usepackage{amsfonts}\n\n    \\usepackage{venndiagram}\n    \\usepackage{lastpage}\n    \\usepackage[hidelinks]{hyperref}\n    \\usepackage{color}\n    \\definecolor{darkred}{RGB}{200, 0, 0}\n\n    \\usepackage{fancyhdr}\n    \\pagestyle{fancy}\n    \\fancyhf{}\n    \\fancyhead[LO]{TMA4140: Homework Set 2}\n    \\fancyhead[RO]{Henry S. Sjøen}\n    \\fancyfoot[CO]{\\thepage\\ of \\pageref{LastPage}}\n         \n    \\usepackage{fancyref}\n\n  \\author{Henry S. Sjøen}\n  \\title{%\n  \\textbf{TMA4140 - Homework Set 2}\\\\\n  Basic structures: Sets, Functions, Sequences and Sums\\\\\n    \\color{darkred}{\\textbf{RETTES}}\n  }\n    \\begin{document}\n    \\maketitle \n    \\thispagestyle{empty}\n    % \\pagebreak\n    \\tableofcontents\n      \n    \\pagebreak\n    \\section{Chapter 2.1 - Sets}\n    \\subsection{Exercise 5}\n    Determine whether each of these pairs are equal.\\\\\n        a) $\\{1,3,3,3,5,5,5,5\\},\\{5,3,1\\} \\Rightarrow True$.\\\\\n        b) $\\{\\{1\\}\\},\\{1,\\{1\\}\\} \\Rightarrow False.$\\\\\n        c) $\\emptyset,\\{\\emptyset\\} \\Rightarrow False$\n   \n    \\subsection{Exercise 24}\n    Determine wether each of these sets is the power set of a set, where \\emph{a} and \\emph{b} are distinct elements.\\\\\n        a) $\\emptyset$, is False. $P(\\emptyset)=\\{\\emptyset\\{\\emptyset\\}\\}$\\\\ \n        b) $\\{\\emptyset,\\{a\\}\\}$, is True. $P(\\{a\\})=\\{\\emptyset,\\{a\\}\\}$\\\\\n        c) $\\{\\emptyset, \\{a\\},\\{\\emptyset,a\\}\\}$, is False.\\\\\n        d) $\\{\\emptyset,\\{a\\},\\{b\\},\\{a,b\\}\\}$, is True.\n\n        The powerset of any set $S$ is the set of all subsets of $S$, including the empty set $\\emptyset$ and $S$ itself. \\footnote{Wikipedia, 2018-09-14, 13:54, \\url{https://en.wikipedia.org/wiki/Power_set}}\n        If $a$ and $b$ are distinct elements of a set $A$. $A=\\{a,b\\}$\n        Then the powerset of $A$ is $p(A)=\\{\\emptyset,\\{a\\},\\{b\\},\\{a,b\\}\\}$.\n\n    \\pagebreak\n    \\section{Chapter 2.2 - Set Operations}\n    \\subsection{Exercise 18c}\n    Let A, B and C be sets. Show that:\n    $(A \\cap B) \\subseteq (A \\cup B \\cup C)$\n    \n    % \\begin{equation}\n    %     \\begin{split}\n    %         (A \\cap B) \\subseteq (A \\cup B \\cup C)\n    %     \\end{split}\n    % \\end{equation}\n    \n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}\n            \\fillA\n            \\fillB\n            \\fillC\n        \\end{venndiagram3sets}    \n        \\caption{$(A \\cup B \\cup C)$}\n        \\label{fig:Union}\n    \\end{figure}\n    \n    As illustrated in \\fref{fig:Union} we can se the venndiagram for $(A \\cup B \\cup C)$. Coloring out $(A \\cap B)$, as shown in  \\fref{fig:ACapB}, we can see that $(A \\cap B)$ is a subset of $(A \\cup B \\cup C)$.\n    \n    \\begin{figure}[h]\n        \\centering\n        \\caption{$A \\cap B$}\n        \\begin{venndiagram3sets}\n            % [labelOnlyAB=$A \\cap B$]\n            \\fillACapB\n        \\end{venndiagram3sets}\n        \\label{fig:ACapB}\n    \\end{figure}\n\n        % \\url{http://www3.wolframalpha.com/Calculate/MSP/MSP2891521ibi0a5gd30f95g000037hcb6a7hd034233?MSPStoreType=image/gif&s=44&w=471.&h=279.&cdf=Resizeable}\n\n    \\newpage\n    \\subsection{Exercise 18d}\n    Let A, B and C be sets. Show that:\n    $(A - B) - C \\subseteq A - C$\n\n\n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}\n            \\fillOnlyA\n        \\end{venndiagram3sets}\n        \\caption{$(A - B) - C$}\n        \\label{fig:onlyA}\n    \\end{figure}\n    \n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}\n            \\fillANotC\n        \\end{venndiagram3sets}\n        \\caption{$A - C$}\n        \\label{fig:ANotC}\n    \\end{figure}    \n\n    We can see that $(A - B)-C$ is a subset of $A-C$, see \\fref{fig:onlyA} and \\ref{fig:ANotC}.\n    \n    \\newpage\n    \\subsection{Exercise 46}\n    Show that if A, B, and C are sets, then:\\footnote{This is a special case of the inclusion-exclusion principle, which will be studied in Chapter 8. Also... Wikipedia \\url{https://en.wikipedia.org/wiki/Inclusion-exclusion_principle}}\n    \n    \\begin{equation}\n        |A \\cup B \\cup C| = \n        |A| + |B| + |C| - |A \\cap B| - |A \\cap C| - |B \\cap C| + |A \\cap B \\cap C|\n    \\end{equation}\n\n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}[\n            labelOnlyA=1,labelOnlyB=1,labelOnlyC=1,\n            labelOnlyAB=2,labelOnlyAC=2,labelOnlyBC=2,\n            labelABC=3]\n            \\fillA\n            \\fillB\n            \\fillC\n        \\end{venndiagram3sets}\n        \\caption{$|A|+|B|+|C|$}\n        \\label{fig:u1}\n    \\end{figure}    \n\n    Here we have counted some elements more than once (\\fref{fig:u1}), lets correct that.\n\n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}[\n            labelOnlyA=1,labelOnlyB=1,labelOnlyC=1,\n            labelOnlyAB=1,labelOnlyAC=1,labelOnlyBC=1,\n            labelABC=0]\n            \\fillA\n            \\fillB\n            \\fillC\n        \\end{venndiagram3sets}\n        \\caption{$|A|+|B|+|C|-(|A \\cap B| - |A \\cap C| - |B \\cap C|)$}\n        \\label{fig:u2}\n    \\end{figure}    \n\n    But now, the intersection of A,B and C is not counted. (\\fref{fig:u2}). Lets count the intersection once $|A\\cap B \\cap C|$ as shown in \\fref{fig:u3}.\n\n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}[\n            labelOnlyA=1,labelOnlyB=1,labelOnlyC=1,\n            labelOnlyAB=1,labelOnlyAC=1,labelOnlyBC=1,\n            labelABC=1]\n            \\fillA\n            \\fillB\n            \\fillC\n        \\end{venndiagram3sets}\n        \\caption{$|A|+|B|+|C|-(|A \\cap B| - |A \\cap C| - |B \\cap C|) + |A \\cap B \\cap C|$}\n        \\label{fig:u3}\n    \\end{figure}    \n\n    We have now shown that \n    and we can intuitively see that it's the same as counting all elements inside the union of the three sets: $|A \\cup B \\cup C|$. (\\fref{fig:u4})\n\n    \\begin{figure}[h]\n        \\centering\n        \\begin{venndiagram3sets}\n            \\fillA\n            \\fillB\n            \\fillC\n        \\end{venndiagram3sets}\n        \\caption{Union of the sets A,B and C}\n        \\label{fig:u4}\n    \\end{figure}\n\n    % TODO: Show it with more amazing math.\n\n    \\pagebreak     \n    \\section{Chapter 2.3 - Functions}\n    \\subsection{Exercise 12c}\n    Determine whether each of these functions from $Z$ to $Z$ is one-to-one.\n\n    \\textbf{True.} $f(n) = n^3$, is One-to-One, because it passes both the vertical and horizontal line test.\\footnote{\\url{http://www.mathwords.com/o/one_to_one_function.htm}}\n\n    \\subsection{Exercise 38}\n    % Todo: Look over later\n    Let $f(x) = ax+b$ and $g(x)= cx+d$, where a,b,c, and d are constants. Determine necessary and sufficient conditions on the constants a,b,c, and d so that \n    $f \\cdot g = g \\cdot f$.\n           \n    \\begin{equation}\n        \\begin{split}\n            f \\cdot g = g \\cdot f = a(cx+d)+b=acx+ad+b\\\\\n            g\\cdot f = g(f(x))=c(ax+b)+d=acx+cb+d\\\\\n            f \\cdot g =  g\\cdot f \\Leftrightarrow ad+b = cb+d\n        \\end{split}\n    \\end{equation}\n\n    \\subsection{Exercise 42}\n    % Todo: Look over later\n    Let $f$ be the function from $R$ to $R$ defined by $f(x)=x^2$. Find:\\\\\n    a) $f^{-1}(\\{1\\}) = \\pm 1$\\\\\n    b) $f^{-1}(\\{ x | 0 < x < 1\\}) = \\pm \\{x|-1<x<1 \\wedge x \\neq 0 \\}$\\\\\n    c) $f^{-1}(\\{ x | x > 4\\}) = \\{x|-2>x \\wedge x>2\\}$\n    \n    \\pagebreak     \n    \\section{Chapter 2.4 - Sequences and Summations}\n\n    \\subsection{Exercise 12c}\n    % Todo: Look over later    \n    Show that the sequence {$a_n$} is a solution of the recurrence relation $a_n=-3a_{n-1}+4a_{n-2}$ if $a_n = (-4)^n$\n    \\begin{equation}\n        \\begin{split}\n            a_n =& -3a_{n-1}+4a_{n-2} = (-4)^n\\\\\n            =&-3a_{n-1} + 4a_{n-2}\\\\\n            =& (-4)^{n-1}+4(-4)^{n-2}\\\\\n            =& (-4)^{n-2}[(-3)(-4)+4]\\\\\n            =& (-4)^{n-2}(16)\\\\\n            =& (-4)^{n-2}(-4)^2\\\\\n            =& (-4)^{n}\n        \\end{split}\n    \\end{equation}\n\n    \\subsection{Exercise 33d}\n    Compute the double sum\n    \\begin{equation}\n        \\begin{split}\n            \\sum_{i=0}^{2}\\sum_{j=1}^{3}ij &= (0*1+0*2+0*3)+(1*1+1*2+1*3)+(2*1+2*2+2*3) \\\\\n            &= (0+0+0) + (1+2+3) + (2+4+6)\\\\ \n            &= 0 + 6 + 12\\\\ \n            &= 18 \n        \\end{split}\n    \\end{equation}\n\n    \\pagebreak     \n    \\section{Chapter 2.5 - Cardinality of Sets}\n    \\subsection{TODO: Exercise 16}\n    \\emph{Exercise}: \n    Show that a subset of a countable set is also countable.\\\\\n    \\emph{Answer}:\n    A set is countable if it is finite or is the same size as $\\mathbb{N}$.\n    To show that $A$ is countable, it is sufficient to show that there is an injection\n    from $A$ to $\\mathbb{N}$.\n\n    \\end{document}", "meta": {"hexsha": "d2519098e7a115d9a9cf787363f5065da75b0a87", "size": 8532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "O2/o2.tex", "max_stars_repo_name": "SjoenH/TMA4140-2018", "max_stars_repo_head_hexsha": "9d2973b94f62f2d30328de3db5f496a42f900ebf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "O2/o2.tex", "max_issues_repo_name": "SjoenH/TMA4140-2018", "max_issues_repo_head_hexsha": "9d2973b94f62f2d30328de3db5f496a42f900ebf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-09-16T20:12:23.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-24T09:17:53.000Z", "max_forks_repo_path": "O2/o2.tex", "max_forks_repo_name": "SjoenH/TMA4140-2018", "max_forks_repo_head_hexsha": "9d2973b94f62f2d30328de3db5f496a42f900ebf", "max_forks_repo_licenses": ["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.9920318725, "max_line_length": 235, "alphanum_fraction": 0.5468823254, "num_tokens": 3016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799253, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.6110589961854199}}
{"text": "\n\\chapter{Preliminary Results} \\label{ch-1}\n\n\\section{Minimal Subspace Polynomial and Multipoint Evaluation}\n\nAn algorithm for multipoint evaluation was presented in \\cite{musschost}. Without loss of generality we may suppose $\\rho$ has skew-degree $d$ a perfect square and let $\\delta = \\sqrt{d}$. The target skew polynomial $\\rho$ can be decomposed as $\\rho = \\rho_0 + \\tau^{\\delta} \\rho_1 + \\ldots + \\tau^{\\delta(\\delta - 1)}\\rho_{\\delta-1}$ where each $\\rho_i$ has skew-degree at most $\\delta - 1$. Set $\\rho_i = \\rho_{i,0} + \\rho_{i,1}\\tau + \\ldots + \\rho_{i,\\delta - 1} \\tau^{\\delta-1}$. For each $0 \\leq i \\leq \\delta -1$ and $1 \\leq j \\leq s$ set $v_{i,j} = \\sigma^i(v_j)$, and each $\\rho_i(v_j) = \\sum_{k=0}^{\\delta - 1} \\rho_{i,k}v_{k,j}$. Horner's scheme can then be used to compute $\\rho(v_j) = \\rho_0(v_j) + \\tau^{\\delta}(\\rho_1(v_j) + \\tau^{\\delta}(\\rho_2(v_j) + \\ldots $.\n\n\\begin{algorithm}\n\\caption{Multipoint Evaluation \\cite{musschost}}\n\\label{alg:mpe2}\n\\hspace*{\\algorithmicindent} \\textbf{Input} A skew polynomial $\\rho \\in \\F_{q^n}\\{\\tau \\}$ of degree $d$, and a set of linearly independent evaluation points $\\{ v_1, \\ldots, v_s \\} \\subset \\F_{q^n}$.\\\\\n \\hspace*{\\algorithmicindent} \\textbf{Output} The set $\\{ \\rho(v_1), \\ldots, \\rho(v_s) \\} \\subset  \\F_{q^n}$ \\\\\n \\begin{algorithmic}[1]\n  \\State Compute $\\rho_i = \\rho_{i,0} + \\rho_{i,1}\\tau + \\ldots + \\rho_{i,\\delta - 1} \\tau^{\\delta}$ such that $\\rho = \\rho_0 + \\tau^{\\delta} \\rho_1 + \\ldots + \\tau^{\\delta(\\delta - 1)}\\rho_{\\delta-1}$\n  \\State Compute $v_{i,j} = \\sigma^i(v_j)$ for each $0 \\leq i \\leq \\delta-1$ and $1 \\leq j \\leq s$\n  \\State Compute the $\\delta \\times \\delta$ and $\\delta \\times s$ matrix product:\n  $\n  \\begin{bmatrix}\n  \\rho_{0,0} & \\ldots & \\rho_{0, \\delta - 1} \\\\ \n  \\vdots & & \\vdots \\\\\n  \\rho_{\\delta - 1, 0} & \\ldots & \\rho_{\\delta - 1, \\delta - 1}\n  \\end{bmatrix}\\begin{bmatrix}\n  v_{0,0}  & \\ldots & v_{0,s} \\\\ \\vdots & & \\vdots \\\\\n  v_{\\delta - 1, 0} & \\ldots & v_{\\delta - 1, s}\n  \\end{bmatrix} = \\begin{bmatrix}\n  \\rho_0(v_1) & \\ldots & \\rho_{0}(v_s) \\\\ \n  \\vdots & & \\vdots \\\\\n  \\rho_{\\delta - 1}(v_1) & \\ldots & \\rho_{\\delta - 1}(v_s)\n  \\end{bmatrix}\n  $\n  \n  \\State For $1 \\leq j \\leq s$ compute $\\rho(v_j) = \\rho_0(v_j) + \\tau^{\\delta}(\\rho_1(v_j) + \\tau^{\\delta}(\\rho_2(v_j) + \\ldots $ via Horner's scheme\n \n\\end{algorithmic}\n\n\\end{algorithm}\n\nSteps 1, 2, and 3 take time equal to the cost of $O(d + d^{1/2}s )$ applications of Frobenius powers. The cost of step 3 is either $O(ds^{\\omega - 2})$ field operations in $\\L$ if $s < \\sqrt{d}$, and $O(d^{(\\omega-1)/2}s)$ $\\L$-operations otherwise.  Counting the complexity of modular compositions, the overall bit complexity of the algorithm is either $(ds^{\\omega - 2} n^{\\theta} \\log q)^{1 + o(1)}$ if $s < \\sqrt{d}$, and $(d^{(\\omega-1)/2}sn^{\\theta} \\log q)^{1 + o(1)}$ otherwise.\n\nAlgorithm \\ref{alg:mpe2} may then be leveraged as a subroutine for algorithm \\ref{msp1}; the algebraic runtime of $\\MSP(d)$ satisfies\n\n\\begin{equation*}\n    \\MSPr(d) = 2\\MSPr(d/2) + O(d^{(\\omega + 1)/2}).\n\\end{equation*}\n\nApplying the master theorem, $\\MSPr(d) = \\Theta(d^{(\\omega + 1)/2})$. In terms of bit complexity, we have $ \\MSPr(d) = (d^{(\\omega-1)/2}sn^{\\theta} \\log q)^{1 + o(1)}$.\n\n\\section{Narayanan's Algorithm for Rank-two Drinfeld Modules}\n\nWe propose an amendment to an additional algorithm for finding the characteristic polynomial of a rank-two Drinfeld module based on an approach originally due to Narayanan in \\cite{Narayanan18} and later modified in \\cite{musschost}. Recall that in the rank-two case, the characteristic polynomial of $\\phi$ takes the form $X^2 - aX - b$. Moreover, since $\\tau^{2n} - \\phi_a\\tau^n - \\phi_b = \\id - a(\\phi_x) - b(\\phi_x) = 0$, the polynomial $1 - a - b$ is an annihilator of $\\phi_x$; in fact it is the characteristic polynomial of $\\phi_x = \\Delta_2 \\tau^2 + \\Delta_1 \\tau + \\gamma(x)$ \\cite{GEKELE1991187}. If the minimal polynomial $\\Gamma$ of $\\phi_x$ coincides with the characteristic polynomial,then we can once again resort to a Wiedemann style argument: in this case, it suffices to compute the minimal polynomial $\\Gamma_{\\ell, \\alpha}$ of a sequence $\\{r_i\\} = \\{\\ell(\\phi_x^i(\\alpha)) \\}$ for a uniformly random $\\alpha \\in \\L$ and $\\F_q$-linear map $\\ell: \\L \\to \\F_q$ and argue that with probability greater than $\\frac{1}{2}$ we have $\\Gamma_{\\ell, \\alpha} = \\Gamma$. In his original proposal, Narayanan used the automorphism projection algorithm of Kedlaya and Umans to compute $2n$ terms of the sequence $\\{ r_i \\}$, whereas it is unclear to us whether this approach and its complexity bound extends to the case where $\\phi_x$ is not an automorphism of $\\L$. \n\nInstead, we propose the following alternative approach based on a ``block Wiedemann\" style algorithm \\cite{Coppersmith94}. For some positive integer $\\mu$, pick $\\mu$ many $\\F_q$-linear maps $\\ell_1, \\ldots, \\ell_{\\mu}$ as before and $\\mu$ elements $\\alpha_i \\in \\L$. Construct a sequence of $\\mu \\times \\mu$ matrices $R_{k}$ such that the $(i,j)^{th}$ entry of $R_k$ is $ \\ell_i(\\phi_x^k(\\alpha_j))$. The generating series of this sequence can be expressed as a product of the form $Q^{-1}N$ for  $\\mu \\times \\mu$ matrices matrices $Q,N$ taking coefficients in $\\F_q[x]$ and with the entries of $Q$ having degree at most $\\lceil n/\\mu \\rceil$. Computing $Q$ can be accomplished by first determining $2n/\\mu$ matrices $R_k$ and using the PM basis algorithm given in \\cite{GiJeVi03} in $(\\mu^{\\omega - 1}n\\log q)^{1 + o(1)}$ bit operations. Fix additional constants $\\frak{b}$and set $K = \\lfloor (n/2\\mu)^{\\frak{b}} \\rfloor$, $K' = \\lceil n/2\\mu K \\rceil$. To compute the $R_k$, we turn to the following procedure:\n\n\\begin{enumerate}\n    \\item Compute the $\\F_q$-linear maps $\\ell_{i, \\frak{s}} =  \\phi_x^{\\frak{s}}(\\ell_i)$ for $i \\leq \\mu$ and $\\frak{s} < K$.\n    \\item Compute $\\phi_x^{K}$ and for $j \\leq \\mu$ and $\\frak{t} \\leq K'$ compute $\\alpha_{\\frak{t}, j} = \\phi_x^{\\frak{t}K}(\\alpha_j)$.\n    \\item Let $L$ be the $K\\mu \\times n$ matrix whose rows correspond to the linear map $\\ell_{i, \\frak{s}}$, and $A$ the $n \\times K'\\mu$ matrix whose columns correspond to $\\alpha_{\\frak{t}, j}$. The entries of the matrix product $LA$ are exactly $\\ell_i(\\phi_x^{\\frak{s} + \\frak{t}K}(\\alpha_j))$ for all $i,j \\leq \\mu$, $\\frak{s} < K$, $\\frak{t} < K'$. \n\\end{enumerate}\n\nFor well chosen $\\mu, \\frak{b}$, the procedure outlined above computes all entries of $R_k$ for $k \\leq 2n/\\mu$ in at most $(n^{1.885} \\log q)^{1 + o(1)}$. \n\n%Fix constants, $\\mu$, $\\frak{w}, \\frak{v}$.\n\n\n\n\\section{Minimal Polynomials in Higher Ranks}\n\n\n\\subsection{Schoof-like Algorithms}\n\nOur main results for this section is the following theorem.\n\n\\begin{theorem}\\label{schooflike}\nThere exists a Monte Carlo algorithm such that when $\\gcd(n,r) = 1$ or $r = 3$, then for a generic choice of rank $r$ Drinfeld module $\\phi$ over a degree $n$ extension $\\L$ of  $\\F_q$, the algorithm computes the minimal polynomial of $\\phi$ with bit complexity $r^{(\\omega+3)/2}(n^2 \\log q)^{1 + o(1)}$ and returns a correct result when $q > Cnr^2$, for some constant $C > 2$, with probability greater than $\\frac{1}{2}$.\n\\end{theorem}\n\nRecall the \\textit{minimal polynomial} of $\\phi$ is the unique monic polynomial $\\Gamma = T^{d} - a_{d-1}T^{d-1} - \\ldots - a_1T - a_0 \\in \\F_q[x][T]$ of least degree such that:\n\n\\begin{equation} \\label{charpoly1}\n \\tau^{nd} - \\phi_{a_{d-1}}\\tau^{n(d-1)} - \\ldots - \\phi_{a_1} \\tau^n - \\phi_{a_0} = 0\n\\end{equation}\n\n\nThe goal is to compute each $a_i$ modulo a set of polynomials which can then be used to reconstruct the true coefficients. This can be done over the right-quotient space $\\L\\{\\tau \\}/\\phi_{x-e}$ since $\\phi_{a \\bmod b} \\bmod \\phi_b = \\phi_a \\bmod \\phi_b$ for any $a, b \\in \\F_q[x]$. If $b = x - e$ for $e \\in \\F_q$, then in particular $a(c) = \\phi_a \\bmod \\phi_b$. As in the rank 2 case, when $q \\gg nr$, linear polynomials suffice and equation (\\ref{charpoly1}) becomes\n\n\\begin{equation}\\label{linsys}\n\\tau^{n\\hatr} - a_{\\hatr-1}(e)\\tau^{n(\\hatr-1)} - \\ldots - a_1(e)\\tau^n - a_0(e)  = 0 \\mod \\phi_{x - e}.\n\\end{equation}\n\n$\\L\\{\\tau \\}/\\phi_{x-e}$ is an $r$-dimensional vector space over $\\L$ spanned by the computational basis $\\{1, \\tau, \\ldots, \\tau^{r-1}\\}$, and let $\\hat{\\varphi}$ denote the column vector of $\\varphi \\in \\L\\{\\tau \\}/\\phi_{x-e}$ in the computational basis. Writing (\\ref{linsys}) as a linear system\n\n\\begin{equation}\\label{system1} \\begin{bmatrix} \\hat{\\tau}^{n(\\hatr-1)} & \\ldots & \\hat{\\tau}^{n} \\end{bmatrix} \\begin{bmatrix} a_{\\hatr-1}(e) \\\\ \\vdots \\\\ a_1(e) \\end{bmatrix} = \\begin{bmatrix}  -a_0(e) \\\\ 0 \\\\ \\vdots \\\\ 0  \\end{bmatrix} + \\hat{\\tau}^{n\\hatr}.\n\\end{equation}\n\nLet $ B(\\psi) = \\begin{bmatrix} \\hat{\\tau}^{n(\\hatr-1)} & \\ldots & \\hat{\\tau}^{n} \\end{bmatrix}$ for modulus $\\psi \\in \\L\\{\\tau\\}$. The well-determinedness of the system encoded by $B(\\phi_{x-e})$ can be characterized using the following lemma.\n\n%Let $B_{\\phi}^{n,j} := \\begin{bmatrix} \\tau^{n(j-1)} & \\ldots & \\tau^{n} \\end{bmatrix} \\bmod \\phi_{x-e}$ be the $r \\times (j -1)$ system encoding the coefficients of the $r$-dimensional vector $\\tau^{ni} \\mod \\phi_{x -e}$ in the computational basis. The goal is to show the system given in $(\\ref{system1})$ has a unique solution with high probability when $q \\gg nr$ by applying the Schwartz-Zippel lemma to the polynomial in the coefficients of the Drinfeld module given by $\\det B_{\\phi}^{n,\\hatr}$, where $B_{\\phi}^{n,\\hatr}$ is truncated to the first $\\hatr - 1$ rows, as $\\det B_{\\phi}^{n,\\hatr} \\neq 0$ provides a sufficient condition for solvability.\n\n%Let $ \\Delta_i = \\sum_{j=0}^{n-1}\\alpha_{i,j}x^j$ for $i > 0$ and $ (\\gamma(x) - e) = \\sum_{j=0}^{n-1}\\alpha_{0,j}x^j$. The goal of the next lemma is to bound the degree \n\n\\begin{lemma}\\label{detdeg}\nSuppose $Cn^2r < q$ for a constant $C>2$. Further suppose that there exists at least one skew-polynomial modulus $\\psi$ of skew-degree $r$ such that the system in (\\ref{system1}) is uniquely solvable. Then for choices of Drinfeld coefficients $\\Delta_i$ and evaluation point $e$ except on an asymptotically vanishing set as $q \\to \\infty$, the system given in $(\\ref{system1})$ is well-determined.\n\\end{lemma}\n\n\\begin{proof}\nWe consider general skew-polynomial modulus $\\psi = \\sum_{i=0}^{r} \\Lambda_i \\tau^i$ for equation $(\\ref{system1})$ rather than the special Drinfeld case of $\\Lambda_0 = x - e$. We assume the case $n,d \\geq 3$ we can set $\\mu = n(\\hatr - 1)$, $\\reduc = \\mu - r$, $\\omega = \\mu - n > 0$. We can characterize the linear independence of the set $\\{\\tau^{ni} \\}_{i =1}^{\\hatr} \\bmod \\psi$ as follows: suppose to the contrary that\n\n\\begin{equation}\\label{mult}\n    \\sum_{i=1}^{\\hatr - 1} \\beta_i \\tau^{ni} = P \\psi\n\\end{equation}\n\nwith $P = \\sum_{i= 1}^{\\reduc} p_ix^i \\in \\L\\{\\tau \\}$ and $P \\neq 0 $. The choice of $P$ is constrained by the requirement that the coefficient of $\\tau^{j}$ in the product is 0 if $n$ doesn't divide $j$. The linear system representing the product $P\\psi$ can be encoded as an $ (\\omega + 1) \\times (\\omega - r + 1)$ matrix $M$ over $\\L$\n\n\\begin{equation}\n    \\label{productsystem}\n    \\begin{bmatrix}\n    \\Lambda_{r}^{q^{\\reduc}} & 0 & 0 & \\ldots & 0 & \\ldots & 0 \\\\\n    \\Lambda_{r - 1}^{q^{\\reduc}} & \\Lambda_{r}^{q^{\\reduc - 1}} & 0 & \\ldots & 0 & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    \\Lambda_{0}^{q^{\\reduc}} & \\Lambda_{1}^{q^{\\reduc - 1}} & \\Lambda_{2}^{q^{\\reduc - 2}} & \\ldots & \\Lambda_{r}^{q^{\\reduc - r}} & \\ldots & 0 \\\\\n    0 & \\Lambda_{0}^{q^{\\reduc - 1}} & \\Lambda_{1}^{q^{\\reduc - 2}} & \\ldots & \\Lambda_{r-1}^{q^{\\lambda - r}} & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    0 & 0 & 0 & \\ldots & 0 & \\ldots & \\Lambda_0^{q^{n}}\n    \n    \n    \\end{bmatrix}\n    \\begin{bmatrix}\n    p_{\\reduc} \\\\ p_{\\reduc - 1} \\\\ \\vdots \\\\ p_{n}\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n    \\beta_{\\hatr-1} \\\\ 0 \\\\ \\vdots \\\\ 0 \\\\ \\beta_{1}\n    \\end{bmatrix}\n\\end{equation}\n\nDeleting $\\hatr - 1$ rows corresponding to the free parameters $\\beta_i$ leaves the above as a well determined $ (\\omega - \\hatr + 2) \\times (\\omega - r + 1)$ linear system. \n\n\\begin{equation}\n    \\label{reduced}\n    \\begin{bmatrix}\n    \\Lambda_{r - 1}^{q^{\\reduc}} & \\Lambda_{r}^{q^{\\reduc - 1}} & 0 & \\ldots & 0 & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    \\Lambda_{0}^{q^{\\reduc}} & \\Lambda_{1}^{q^{\\reduc - 1}} & \\Lambda_{2}^{q^{\\reduc - 2}} & \\ldots & \\Lambda_{r}^{q^{\\reduc - r}} & \\ldots & 0 \\\\\n    0 & \\Lambda_{0}^{q^{\\reduc - 1}} & \\Lambda_{1}^{q^{\\reduc - 2}} & \\ldots & \\Lambda_{r-1}^{q^{\\lambda - r}} & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    \n    \n    \\end{bmatrix}\n    \\begin{bmatrix}\n    p_{\\reduc} \\\\ p_{\\reduc - 1} \\\\ \\vdots \\\\ p_{n}\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n    0 \\\\ 0 \\\\ \\vdots \\\\ 0 \\\\ 0\n    \\end{bmatrix}\n\\end{equation}\n\nDeleting an additional $r - \\hatr + 1$ rows, which can be chosen such that the resulting system derived from the modulus $\\psi$ is invertible, and showing that for generic choices of Drinfeld module parameters the determinant of this resulting square matrix is non-zero is sufficient to establish $P = 0$. To that end, we ``vectorize\" equation $(\\ref{productsystem})$: fix an $\\F_q$-basis of $\\L$, under which elements $a \\in \\L$ can be represented by a length $n$ vector $\\hat{a}$ with entries in $\\F_q$ or by their $n\\times n$ multiplication operator $\\overline{a} \\in \\F_q^{n \\times n}$. Moreover, let $\\overline{\\sigma}$ denote the $n\\times n$ matrix of the Frobenius acting on vectors $\\hat{a}$. This allows a rewriting of the truncated system $\\overline{M}$\n\n\\begin{equation}\n    \\label{vectorsystem}\n    \\begin{bmatrix}\n    \\overline{\\sigma}^{\\lambda}\\overline{\\Lambda}_{r - 1} & \\overline{\\sigma}^{\\lambda-1}\\overline{\\Lambda}_{r} & 0 & \\ldots & 0 & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    \\overline{\\sigma}^{\\lambda}\\overline{\\Lambda}_{0} & \\overline{\\sigma}^{\\lambda -1}\\overline{\\Lambda}_{1} & \\overline{\\sigma}^{\\lambda - 2}\\overline{\\Lambda}_{2} & \\ldots & \\overline{\\sigma}^{\\lambda - r}\\overline{\\Lambda}_{r} & \\ldots & 0 \\\\\n    0 & \\overline{\\sigma}^{\\lambda - 1}\\overline{\\Lambda}_{0} & \\overline{\\sigma}^{\\lambda - 2}\\overline{\\Lambda}_{1} & \\ldots & \\overline{\\sigma}^{\\lambda - r}\\overline{\\Lambda}_{r-1} & \\ldots & 0 \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \n    \n    \n    \\end{bmatrix}\n    \\begin{bmatrix}\n    \\hat{p}_{\\reduc} \\\\ \\hat{p}_{\\reduc - 1} \\\\ \\vdots \\\\ \\hat{p}_{n}\n    \\end{bmatrix}\n    = \n    \\begin{bmatrix}\n     \\hat{0} \\\\ \\vdots \\\\ \\hat{0} \n    \\end{bmatrix}\n\\end{equation}\n\nThis system is parametrized by the $\\F_q$-coefficients of $\\Lambda_i = \\sum_{j = 0}^{n-1} \\alpha_{i,j}x^j$. The resulting vectorized system is an  $ n(\\omega - r + 1) \\times n(\\omega - r + 1)$ matrix whose entries are degree 1 polynomials in the variables $\\alpha_{i,j}$; therefore when the determinant is not exactly the zero polynomial in the $\\alpha_{i,j}$, then it has degree $n(\\omega - r + 1) = O(n^2r)$. This can't be the case since the system must be invertible for at least one choice of $\\alpha_{i,j}$ corresponding to the choice of skew-polynomial $\\psi$ for which a solution $z$ to $B(\\psi)z = 0$ is uniquely determined. Applying the Schwartz-Zippel lemma to the determinant:\n\n%Set $\\alpha_i = \\frac{\\Delta_i}{\\Delta_r}$ with coefficients $\\alpha_i := \\sum_{j=0}^{n-1}\\alpha_{i,j}x^j$. Furthermore, let $\\overline{\\alpha_i}$ be the $n\\times n$ matrix of the action of left multiplication by $\\alpha_i$ on $\\L/\\F_q$, and let $\\overline{\\tau}$ denote the matrix representation of the Frobenius. If $\\sum_{i=0}^{r-1}c_i \\tau^i$ is any skew polynomial, the action of left multiplication by $\\tau$ on $\\L[\\tau]/\\phi_{x-e}$ is given by the following matrices:\n\n%\\begin{equation*}\n%M :=  \\begin{bmatrix}\\overline{\\alpha}_{r-1} & I & 0 & \\ldots & 0 \\\\ \\overline{\\alpha}_{r-2} & 0 & I & \\ldots & 0 \\\\ \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\ \\overline{\\alpha}_{0} & 0 & 0 & \\ldots & I \\end{bmatrix} \\hspace{4mm} S := \\begin{bmatrix} \\overline{\\tau} & & \\\\ & \\ddots & \\\\ & & \\overline{\\tau} \\end{bmatrix}\n%\\end{equation*}\n\n%\\begin{equation*}\n%\\begin{bmatrix}\\overline{\\alpha}_{r-1} & I & 0 & \\ldots & 0 \\\\ \\overline{\\alpha}_{r-2} & 0 & I & \\ldots & 0 \\\\ \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\ \\overline{\\alpha}_{0} & 0 & 0 & \\ldots & I \\end{bmatrix} \\begin{bmatrix} \\overline{\\tau} & & \\\\ & \\ddots & \\\\ & & \\overline{\\tau}\\end{bmatrix} \\begin{bmatrix} \\overline{c}_{r-1} \\\\ \\vdots \\\\ \\overline{c}_{0} \\end{bmatrix} = \\begin{bmatrix} \\overline{\\alpha}_{r-1} \\overline{\\tau}(\\overline{c}_{r-1}) + \\overline{\\tau}(\\overline{c}_{r-2}) \\\\ \\overline{\\alpha}_{r-2} \\overline{\\tau} \\overline{c}_{r-1} + \\overline{\\tau} \\overline{c}_{r-3} \\\\ \\vdots \\\\ \\overline{\\alpha}_{0} \\overline{\\tau}(\\overline{c}_{r-1})  \\end{bmatrix}\n%\\end{equation*}\n\n%with each $\\overline{c}_i \\in \\L$ being written as a size $n$ vector over $\\mathbb{F}_q$. Then $\\tau^{in} \\mod \\phi_{x-e}$ is given by \n\n%\\begin{equation*}\n%(MS)^{in-r} \\begin{bmatrix} \\overline{1} \\\\ 0 \\\\ \\vdots \\\\ 0 \\end{bmatrix}.\n%\\end{equation*}\n\n%The entries of this expression have degree $in - r$ in the coefficients $\\alpha_{i,j}$, and the total degree of any term in the square determinant is $2\\sum_{i=1}^{r-1} (in - r) \\leq 2nr^2$.\n\n\\begin{equation*}\n    \\Pr\\Big[\\det \\overline{M} = 0\\Big] \\leq \\frac{n^2r}{q} < \\frac{1}{C}.\n\\end{equation*}\n\n\\end{proof}\n\n%If $\\sqdet B_{\\psi}^{n,r} \\neq 0 $, then for generic choices of base field element $e$ and coefficients of $\\phi_x$, the Schwartz-Zippel lemma implies\n\n% $\\{\\alpha_{i,j}\\}_{1 \\leq i \\leq r-1}^{0 \\leq j \\leq n-1}$, the Schwartz-Zippel lemma implies\n\n\n\nThe remainder of the proof of Theorem 1 is classifying pairs of parameters $n,r$ for which there exists at least one choice of modulus $\\psi \\in \\sring$ that guarantees unique solvability of $B(\\psi)$\n\n\\begin{prop}\\label{coprime}\nSuppose $\\gcd(n,r) = 1$. There exists a Drinfeld module $\\phi_x$ such that $ B(\\phi_x)$ is uniquely solvable.  %e $\\psi = \\tau^n - 1$.\n\\end{prop}\n\\begin{proof}\nLet $\\phi_x = \\tau^r - \\gamma(x)$. For any $e \\neq -\\gamma(x)$, $\\tau^{ni} = (\\gamma(x) + e)^{\\lfloor ni/r \\rfloor} \\tau^{ni \\bmod r} \\bmod \\phi_{x} - e$. Since $\\gcd(n,r) = 1$, the set $\\{ n \\bmod r, 2n \\bmod r, \\ldots, rn \\bmod r\\}$ is a reordering of $\\{0, 1, \\ldots, r-1\\}$ and so the elements $\\tau^{ni}$ form an $\\L$ basis of $\\L\\{ \\tau\\}/\\phi_{x - e}$.\n\\end{proof}\n\n\n\n\\begin{prop}\\label{rank3}\nIf $r = 3$, then for any $n$ there exists a skew-polynomial $\\psi \\in \\L\\{\\tau\\}$ such that $B(\\psi)$ is uniquely solvable.\n\\end{prop}\n\\begin{proof}\nFor a contradiction, let $\\psi$ be any skew polynomial. The notion of an \\textit{Azumaya algebra} and their connection to skew polynomials was previously studied in \\cite{Ikehata1984AzumayaAA} and \\cite{skewfactor}. In particular, we are interested in a distinguished map sending an Azumaya algebra to its center, the \\textit{reduced norm}, which induces a map $\\cN: \\L\\{\\tau\\} \\to \\comm$ while satisfying the following constraints.\n\n\\begin{enumerate}\n    \\item $\\cN(\\psi_1 \\psi_2) = \\cN(\\psi_1) \\cN(\\psi_2)$\n    \\item $\\deg_{\\tau^n} \\cN(\\psi) \\leq n \\deg_{\\tau} \\psi$\n    \\item $\\cN(\\psi) = \\psi^n$ if $\\psi \\in \\L[\\tau^n]$\n    \\item $\\psi$ is irreducible in $\\sring$ if and only if $\\cN(\\psi)$ is irreducible in $\\F_q[\\tau^n]$\n\\end{enumerate}\n\nFor details on the construction of the map and the proof of item (4) we refer to \\cite[Prop. 2.1.17]{skewfactor}. Suppose $\\tau^{2n} - \\lambda \\tau^n = 0$ for some $\\lambda \\in \\F_q$. Then $\\tau^{n} - \\lambda = 0 \\mod \\psi$, and we must have a skew polynomial $D$ such that $\\tau^n - \\lambda = D \\psi$. Taking reduced norms of both sides leads to\n\n\\begin{equation*}\n(\\tau^n - \\lambda)^n = \\cN(D)\\cN(\\psi)\n\\end{equation*}\n\nThe number of irreducible skew-polynomials of any degree was partly characterized in \\cite{odoni_1999}, and in particular they exist for any skew degree. If we choose $\\psi$ to be any degree 3 skew polynomial irreducible in $\\L\\{\\tau \\}$, item (4) implies $\\cN(\\psi)$ is an irreducible central skew-polynomial dividing $(\\tau^n - \\lambda)^n$ and so $\\deg_{\\tau}\\cN(\\psi) = n$. But we must then have $n^2 = \\deg_{\\tau} \\cN(D) + \\deg_{\\tau} \\cN(\\psi) \\leq (n-3)n + n = n^2 - 2n < n^2$, giving a contradiction.\n\n\\end{proof}\n\n\\subsection{Limitations}\n\nOne of the clearest limitations of this approach is the large base field requirement $q > Cn^2 r$. Unlike the case $r = 2$, working with arbitrary degree irreducibles in $\\F_q[x]$ in place of degree 1 polynomials does not appear to repair the issues discussed in lemma (\\ref{detdeg}).\n\nLemma (\\ref{detdeg}) also appears limited to only the parameter cases given in propositions (\\ref{coprime}) and (\\ref{rank3}). As will be seen in the following example, there exist parameter choices for $n, r,$ and Drinfeld module $\\phi_x$ outside these cases where the algorithm will never work.\n\n\\begin{example}\\label{examplefail}\nLet $n = 3$, $r =3$, $\\phi_x = \\tau^3 + x$. For $(\\ref{system1})$ to be uniquely solvable for some $e$, whenever $\\alpha_1 \\tau^3 + \\alpha_2 \\tau^6 = P (\\tau^3 + x - e)$ we must have $P = 0$. However for any $e$ setting $\\alpha_1 = 1$, $\\alpha_2 = x - e $ has the non-zero solution $P = \\tau^3$.  \n\\end{example}\n\nIt is possible to detect failure cases such as those in the preceding example by checking dimensionality of the kernel of the linear system in $(\\ref{reduced})$.  \n\n\n\n\\subsection{Complexity.}\n\nThe algorithm can be summarized with the following routine:\n\n%\\textit{Subroutine 1}\n\\begin{algorithm}[H]\\label{schoof}\n\\caption{Pseudocode for Schoof-like algorithm}\n\\begin{enumerate}\n    \\item Compute $\\tau^{ni} \\mod \\phi_{x-e}$ in the computational basis for $\\lfloor\\frac{r-1}{r}n \\rfloor$ distinct $e \\in \\F_q$ and $1 \\leq i \\leq r$\n    \\item Solve the $r \\times (\\hatr-1)$ system given in (\\ref{system1}) for each choice of $e$. If the system $B(\\phi_{x-e})$ is uniquely solvable, apply a uniformly random projection $\\ell : \\L \\to \\F_q$ to the system and solve the system over $\\F_q$.\n    \\item Interpolate $\\{a_i\\}_{i=1}^{\\hatr-1}$ using the $\\lfloor\\frac{r-1}{r}n \\rfloor$ evaluation points $\\{a_i(e)\\}_{i=1}^{r-1}$ computed in step (2). \n    \\end{enumerate}\n\\end{algorithm}\n\nThe bottleneck of subroutine 1 is step (1). Algorithms for skew-polynomial multiplication can be leveraged to compute the entire collection of $\\tau^{ni} \\mod \\phi_{x - e}$ in $r^{(\\omega+3)/2}(n \\log q)^{1 + o(1)}$ bit operations for a single $e$, with an overall contribution to the algorithm of $r^{(\\omega+3)/2}(n^2 \\log q)^{1 + o(1)}$. Step (2) adds $r^{\\omega}n\\log q$ bit operations, and (3) is of negligible cost. \n\nA generic choice of projection $\\ell$ will preserve unique solvability of $B(\\phi_{x-e})$ with probability at least $1 - \\frac{\\hatr}{q} \\geq 1 - \\frac{1}{Cn^2} $. This holds for $O(n)$ independent choices of projection with probability at least $(1 - \\frac{1}{Cn^2})^n \\to e^{-1/(C)} \\to 1$ for large $n, C$. The remaining probabilistic element is the likelihood of genericity for the choice of Drinfeld module, base field element pair $(\\phi, e)$ for $n$ choices of $e$, which happens with probability $(1 - \\frac{1}{Cn})^{n}$ and which can be made arbitrarily close to 1. This completes the argument for Theorem 1.\n\nWhen working with the prime field case $n = m$ or when $\\gcd(r, s) = 1$, the minimal polynomial is known to have degree $r$ and the routine need only be invoked once. For the general case, including parameter choices not covered by theorem \\ref{schooflike}, we speculate it may be possible to invoke the algorithm for choices of $\\hat{d}$ such that $r = \\hat{d} r'$ with $r' | s$ and invoking probabilistic polynomial testing to verify that the output for a given $\\hat{d}$ is in fact an annihilating polynomial for $\\tau^n$; taking the polynomial corresponding to the least such $\\hat{d}$.\n\n%\\begin{enumerate}\n%    \\item Initialize $r_{upper} \\leftarrow r$, $r_{lower} \\leftarrow 1$.\n%    \\item If $r_{upper} = r_{lower}$, return $r_{upper}$. Otherwise set $\\hatr \\leftarrow \\frac{r_{upper} + r_{lower}}{2}$.\n%    \\item Run Subroutine 1 on the estimate $\\hatr$.\n%    \\item If the system in (\\ref{system1}) is inconsistent, $r_{lower} \\leftarrow \\hatr$ and go to step 2.\n%    \\item If the system in (\\ref{system1}) returns a solution, use polynomial identity testing to determine if $\\tau^{n \\hatr} - \\sum_{i = 0}^{\\hatr - 1} \\phi_{a_i}\\tau^{ni} = 0$. If this equation holds, set $r_{upper} \\leftarrow \\hatr$, otherwise $r_{lower} \\leftarrow \\hatr$. Go to step 2.\n    \n%\\end{enumerate}\n\n\n\n\n\n\\subsection{From Hankel Systems}\nInspired by the Monte Carlo Algorithm given in $\\cite{musschost}$, we will propose an additional algorithm which doesn't depend on the genericity of the chosen Drinfeld module required by the Zippel-Schwartz criteria, and therefore may be usable when the algorithm of theorem \\ref{schooflike} fails, and possesses a similar complexity.\n\\begin{theorem}\\label{hankel}\nLet $\\phi$ be a rank $r$ Drinfeld module over a degree $n$ extension $L/\\F_q$ such that $\\gcd(n, r) = 1$. There is a Monte-Carlo algorithm computing the minimal polynomial of $\\phi_x$ with bit complexity $(r^{3}n^2 \\log q)^{1+o(1)}$ and which returns a correct result with probability greater than $\\frac{1}{2}$ .\n\\end{theorem}\n\nNote that given any algorithm achieving a probability of success greater than $\\frac{1}{2}$, another algorithm that succeeds with probability $\\frac{1}{2} < p < 1$ for any $p$ can be constructed with the same complexity as the original algorithm. We can organize the characteristic equation into a Hankel system.\n\n\\begin{align*}\n\\sum_{i=1}^{r - 1} \\phi_{a_i}\\tau^{ni} = &  \\tau^{nr} - \\phi_{a_0}\n%\\end{equation*}\n%\\begin{equation}\n%\\label{chareq}\n\\\\\n\\sum_{i=1}^{r - 1} \\sum_{j=0}^{n(r-i)/r}a_{i,j}\\phi_{x}^j\\tau^{ni} = & \\tau^{nr} - \\phi_{a_0}\n\\end{align*}\n\nWith $a_{i,j} \\in \\F_q$, and with $a_0$ determined via $(\\ref{norm})$. For integers $u, v > 0$, consider the operator Hankel blocks\n\\begin{align*}\nH_{u,v} = & \\begin{bmatrix}\n\\phi_x^u\\tau^{n} & \\phi_x^u\\tau^{2n} & \\ldots & \\phi_x^u\\tau^{n (r - 1 - \\lfloor(ur/n) \\rfloor)} \\\\\n\\phi_x^u\\tau^{2n} & \\phi_x^u\\tau^{3n} & \\ldots & \\phi_x^u\\tau^{(1 + r - 1 - \\lfloor(ur/n) \\rfloor)n} \\\\ \\vdots & \\vdots & \\ddots & \\vdots \\\\ \\phi_x^u\\tau^{vn} & \\phi_x^u\\tau^{(1+v)n} & \\ldots & \\phi_x^u\\tau^{(v +  r - 1 - \\lfloor(ur/n) \\rfloor) n}\n\\end{bmatrix}\n\\\\\n%\\end{equation*}\n%\\begin{equation*}\n    G_{v} = &\\begin{bmatrix}\n    \\tau^{nr} - \\phi_{a_0} & \\tau^{n(r+1)} - \\phi_{a_0}\\tau^n & \\ldots \\tau^{n(r+v -1)} - \\phi_{a_0}\\tau^{n(v-1)}\n    \\end{bmatrix}^T\n\\end{align*}\n\nDefine\n\\begin{align*}\n%\\begin{equation*}\nH:= & \\begin{bmatrix}\nH_{0,v_1} & H_{1, v_1} & \\ldots & H_{\\lfloor n (r- 1)/r \\rfloor, v_1} \\\\ \\vdots & \\vdots & \\ddots & \\vdots \\\\ H_{0,v_k} & H_{1, v_k} & \\ldots & H_{\\lfloor n (r-1)/r \\rfloor, v_k}\n\\end{bmatrix}\\\\\nG:= & \\begin{bmatrix}\nG_{v_1} \\\\ \\vdots \\\\ G_{v_k}\n\\end{bmatrix}\n%\\end{equation*}\n\\end{align*}\n\nWe then obtain the system\n\n\\begin{equation*}\nH\n\\begin{bmatrix}\na_{1,0} \\\\ a_{2,0} \\\\ \\vdots \\\\ a_{1,1} \\\\ a_{2,1} \\\\ \\vdots \\\\ a_{1, \\lfloor n (r-1)/r \\rfloor}\n\\end{bmatrix} = G\n\\end{equation*}\n\nIn general, non-trivial relations between the linear maps $\\phi_x^i\\tau^{jn}$ acting on $\\L$ ensure that the space of solutions has dimension larger than 0. To eliminate these relations, we lift to an extension $\\K$ over $\\L$. Let $H_{i, j}(\\alpha_{\\ell})$ denote the entry-wise evaluation of $H_{i, j}$ at $\\alpha_{\\ell}$. The goal is to choose a set of evaluation points $\\alpha_1, \\ldots, \\alpha_k \\in K$ such that the over-determined\n\n\\begin{equation*}\n    H(\\alpha_1, \\ldots, \\alpha_k) := \\begin{bmatrix}\nH_{0,v_1}(\\alpha_1) & H_{1, v_1}(\\alpha_1) & \\ldots & H_{\\lfloor n (r-1)/r \\rfloor, v_1}(\\alpha_1) \\\\ \\vdots & \\vdots & \\ddots & \\vdots \\\\ H_{0,v_k}(\\alpha_k) & H_{1, v_k}(\\alpha_k) & \\ldots & H_{\\lfloor n (r-1)/r\\rfloor, v_k}(\\alpha_k)\n\\end{bmatrix}\n\\end{equation*}\n\nhas a well-determined solution. Note that $H$ is an $ (v_1 + \\ldots + v_k) \\times \\bigg( \\sum_{i=1}^{n(r-1)/r} r - 1 - \\lfloor(i r/n) \\rfloor \\bigg)$ system, and that the number of columns is a most $nr$. Let $v_1 = v_2 = \\ldots = v_k = r$, $k = n$, and $[\\K:\\L] = r$. So $[\\K:\\F_q] = nr$, and observe that if the following two conditions are satisfied:\n\n\\begin{enumerate}\n    \\item The linear maps $\\phi_x^{u}\\tau^{ni}$ on $K$ are independent for $1 \\leq i \\leq r-1$ and $0 \\leq u \\leq  \\frac{r-i}{r} n < n$ \n    \\item The set $B = \\{\\alpha_1, \\tau^n(\\alpha_1), \\ldots , \\tau^{n(r - 1)}(\\alpha_1), \\ldots , \\alpha_k, \\tau^n(\\alpha_k), \\ldots , $\n    $\\tau^{n(r - 1)}(\\alpha_k) \\}$ is a basis for $K/\\F_q$\n\\end{enumerate} \n\nThen the equation $H(\\alpha_1, \\ldots, \\alpha_{n})z = G$ must have a unique solution, corresponding to the coefficients of the minimal polynomial of $phi_x$. The following lemma summarizes the core of this argument.\n\n\\begin{lemma}\\label{charindlem}\nLet $F/G$ be a finite field extension with $[F:G] = m$ and fix a basis $\\alpha_1, \\ldots, \\alpha_m$ for $F$ over $G$. Let $\\sigma_1, \\ldots, \\sigma_m$ be independent linear maps over $F$, fixing $G$. Then the following matrix is has no non-trivial solutions\n\n\\begin{equation*}\n \\begin{bmatrix}\n\\sigma_1(\\alpha_1) & \\ldots & \\sigma_m(\\alpha_1) \\\\ \\vdots & & \\vdots \\\\ \\sigma_1(\\alpha_m) & \\ldots & \\sigma_m(\\alpha_m) \n\\end{bmatrix}   \n\\end{equation*}\n\n\n\\end{lemma}\n\\begin{proof}\nSuppose there exist $\\Lambda = \\begin{bmatrix} \\lambda_1 &  \\ldots & \\lambda_m \\end{bmatrix}^T \\in F^m$ with not all $\\lambda_i = 0$ such that\n\n\\begin{equation*}\n \\begin{bmatrix}\n\\sigma_1(\\alpha_1) & \\ldots & \\sigma_m(\\alpha_1) \\\\ \\vdots & & \\vdots \\\\ \\sigma_1(\\alpha_m) & \\ldots & \\sigma_m(\\alpha_m) \\end{bmatrix} \\begin{bmatrix} \\lambda_1 \\\\ \\vdots \\\\ \\lambda_m \\end{bmatrix} = \\begin{bmatrix}\n0 \\\\ \\vdots \\\\ 0\n\\end{bmatrix}\n\\end{equation*}\n\nThen for any row-wise re-scaling with $\\ell_1, \\ldots, \\ell_m \\in G$ we must also have\n\n\\begin{equation*}\n \\begin{bmatrix}\n\\ell_1\\sigma_1(\\alpha_1) & \\ldots & \\ell_1\\sigma_m(\\alpha_1) \\\\ \\vdots & & \\vdots \\\\ \\ell_m\\sigma_1(\\alpha_m) & \\ldots & \\ell_m\\sigma_m(\\alpha_m) \\end{bmatrix} \\begin{bmatrix} \\lambda_1 \\\\ \\vdots \\\\ \\lambda_m \\end{bmatrix} = \\begin{bmatrix}\n0 \\\\ \\vdots \\\\ 0\n\\end{bmatrix}\n\\end{equation*}\n\nWe multiply out the left-hand side and sum the rows to obtain\n\n\\begin{equation}\\label{violation}\n    \\sum_{i=1}^m\\sum_{j=1}^m\\ell_i\\lambda_j\\sigma_j(\\alpha_i) = \\sum_{j=1}^m\\lambda_j\\sigma_j\\bigg(\\sum_{i=1}^m\\ell_i\\alpha_i\\bigg)  = 0\n\\end{equation}\n\nObserve now that (\\ref{violation}) holds for any $\\ell_1, \\ldots, \\ell_m $, violating linear independence.\n\n\\end{proof}\n\nFrom Lemma (\\ref{charindlem}), demonstrating that the system $H(\\alpha_1, \\ldots, \\alpha_{n})z = G$ can be uniquely solved for the coefficients of the minimal polynomial of $\\phi_x$ reduces to establishing the linear independence of $\\phi_x^{u}\\tau^{ni}$ over $\\K$.  If $\\gcd(n,r) = 1$, the degree of the lead term of $\\phi_x^u = C\\tau^{ru} + \\ldots$ has a unique residue modulo $n$ for distinct choices of $u$, and so independence of $\\{ \\phi_x^{u}\\tau^{ni} \\}_{0 \\leq u \\leq n(r-i)/r }^{1 \\leq i < r}$ follows from independence of $id, \\tau, \\tau^2, \\ldots, \\tau^{nr-1}$. The values $\\alpha_1, \\ldots, \\alpha_r$ can be constructed from a normal basis for $K/\\F_q$ by selecting $\\alpha_i = \\alpha^{q^i}$ for $0 \\leq i \\leq r - 1$.\n\n\\subsection{Complexity.} Summarizing the preceding results, we have the following procedure:\n\n\\begin{algorithm}[H]\\label{hankel}\n\\caption{Computing the Minimal Polynomial via a Hankel System }\n\n\\begin{enumerate}\n    \\item Fix a degree $r$ extension $K$ of $L$ and a normal basis for $K$ over $\\F_q$\n    \\item Compute the Hankel Blocks $H_{i,r}(\\alpha_j)$ as well as the right-hand blocks $G_r(\\alpha_j)$\n    \\item Fix a random projection $\\ell: K \\to \\F_q$ and apply it to the entries of $H, G$\n    \\item Solve the resulting $O(nr) \\times nr$ system over $\\F_q$.\n\\end{enumerate}\n\\end{algorithm}\nDetermining a normal basis of size $nr$ of $K/\\F_q$ can be done in sub-quadratic time in the degree of the extension. Constructing the Hankel system above involves computing $\\phi_x^{u}\\tau^{ni}(\\alpha_j)$ for $O(nr^2)$ choices of $0 \\leq u < \\frac{r-1}{r}n, 1 \\leq i \\leq r, 0 \\leq j \\leq r$. The applications of $\\tau$ can be applied for $O(1)$ cost on the normal basis, while applications of $\\phi_x$ take $O(nr \\log q)$ bit operations. The total bit complexity for the entire procedure to compute the block Hankel system is $O(n^2r^3\\log q)$. We may again apply the uniformly selected linear projection $\\ell$ at an additional cost of $O(n^2r^3\\log q)$. Constructing the normal basis and solving the resulting $nr \\times nr$ Hankel system consisting of $n$ block columns and $r$ block rows can be done in at most $O(n^2r^2\\log q)$.\n\n\\subsection{Comparison and Limitations}\n\nUnlike in the Schoof-like case, there is no dependence on the genericity of the choice of Drinfeld module; the algorithm only fails to return a result when a poor choice of projection is made. For cases other than $\\gcd(n,r) = 1$, lemma (\\ref{charindlem}) can be applied by directly by testing the linear independence of characters $\\{ \\phi_x^{u}\\tau^{ni} \\}_{0 \\leq u \\leq n(r-i)/r }^{1 \\leq i < r}$, which can be done probabilistically using polynomial identity testing. \n\n", "meta": {"hexsha": "e29cd034fdad1779d65b0708dc28fa4e1ca3fc72", "size": 33443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MainText/chapter4.tex", "max_stars_repo_name": "DocTrivial/Research-Proposal", "max_stars_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MainText/chapter4.tex", "max_issues_repo_name": "DocTrivial/Research-Proposal", "max_issues_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MainText/chapter4.tex", "max_forks_repo_name": "DocTrivial/Research-Proposal", "max_forks_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.061465721, "max_line_length": 1374, "alphanum_fraction": 0.656280836, "num_tokens": 11821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6110246653086806}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{graphicx}\n\\usepackage{multicol}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\\usepackage{amsthm}\n\\usepackage{geometry}\n\\geometry{a4paper} \n\\usepackage{fancyhdr}\n\\usepackage{xcolor}\n\\begin{document}\n\\author{\\textbf{Elshimaa Ahmed}}\n\\title{\\textbf{Lecture 2}}\n\\date {\\today}\n\\maketitle\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\\section{Predicates}\n\\paragraph{}\npredicates are statements involving variables such that \" $x >3$ \" . These statements are neither tru or false where the value of the variable is not specified.\nThe statement \"$x$ is greater than 3\" involving two parts . the variable part $x$ and the predicate(property) it self \" great than 3\" .its denoted by $P(x)$  once a value is assigned to $x$ the $P(x)$ become a preposition\n\\newline\n\\newline\n\\textbf{For example:}\n\\newline\nlet $P(x)$ denote the statement \"$x > 3$\" what are truth values of $P(4)$ and $P(2)$\n\\newline\n\\newline\n\\textbf{Solution: } we obtain $P(4)$ by setting $x = 4$ in the statement, Hence $P(4)$  is the statement \"$3 > 4$\" which is $True$ . $P(2)$ is the statement \"$ 2 >3$\" which is $False$ \n\\section{Quantifiers}\n\\begin{definition}[\\textbf{Universal Quantifier}]\n    the universal Quantifier of $P(x)$ is the statement \"$P(X)$ is $True$ for all values of $x$ in the domain\". It is denoted by $\\forall x P(x)$\n\\begin{definition}[\\textbf{Esistential Quantifier}]\n    the existential quantifier of $P(x)$ is the preposition \" there exist an element $x$ such that $P(x)$ is $True$\" . It is denoted by $\\exists x P(x)$\n\\end{definition}    \n\\end{definition}\n\n\\begin{tabular}{|c|c|c|}\n    \\hline\n    statement & when true & when false \\\\ \n    \\hline\n    $\\forall x P(x)$ & P(x) is $True$ for all values of $x$ & there is an $x$ for which $P(x)$ is $False$\\\\\n    $\\exists x P(x)$ & there is an $x$ such that $P(x)$ is $True$ & $P(x)$ is $False$ for all $x$ \\\\\n    \\hline\n\\end{tabular}\n\\newline\\newline\n\\textbf{English phrases with quatifiers:}\n\\begin{itemize}\n    \\item \"no one is P(x)\" $\\longleftrightarrow$ $\\forall x \\neg P(x)$ or $\\neg(\\exists x P(x))$\n    \\item \"not every one is P(x)\"$\\longleftrightarrow$ $\\neg(\\forall x P(x))$ or $\\exists x\\neg P(x)$\n    \\item \"exactly one is P(x) \" $\\longleftrightarrow$ $\\exists x (P(x) \\wedge \\forall y (P(y) \\rightarrow x = y)) $ \n    \\item \"all Q(x) is P(x) \" $\\longleftrightarrow$ $ \\forall x (Q(x) \\rightarrow P(x))$\n    \\item \"all Q(x) isnot P(x)\" $\\longleftrightarrow$ $\\forall x (Q(x)\\rightarrow \\neg P(x))$\n    \\item \"some Q(x) are P(x)\" $\\longleftrightarrow$ $\\exists x (Q(x)\\wedge P(x))$\n    \\item \"some Q(x) are not P(x)\" $\\longleftrightarrow$ $\\exists x (Q(x)\\wedge \\neg P(x))$\n\\newline\\newline\n\\end{itemize}\n\n\\noindent\n\\textbf{Nested Quantifiers}\n\\newline\n\\newline\n\\begin{tabular}{|p{2cm}|p{7cm}|p{7cm}|}\n    \\hline\n    statement & when true? &when false? \\\\\n    \\hline\n    $\\forall \\forall y P(x,y)$ & P(x,y) is true for all possible pairs & there is a pair (x,y) such that P(x,y) is false\\\\\n    $\\forall y \\forall x P(x,y)$ & &\\\\\n    \\hline\n    $\\forall x \\exists y P(x,y)$ & for every x there is y (not necessary same for different values of x) such that P(x,y) is true & there is an x such that P(x,y) is false for every y \\\\\n    \\hline\n    $\\exists y \\forall x P(x,y)$ & there is exist a specific (same) y that P(x,y) is true for all x & for every y there is at leasy one  x that P(x,y) fails\\\\\n    \\hline\n    $\\exists x \\exists y P(x,y)$ & therer is a pair (x,y) for which P(x,y) is true & for all pairs (x,y) P(x,y) is False\\\\\n    $\\exists y \\exists x P(x,y) $&&\\\\\n    \\hline \n\\end{tabular}\n\n\n\n\\end{document}", "meta": {"hexsha": "452a67a2e820eb764fc286b94cc870994f3fbaed", "size": 3682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture2/Lecture2.tex", "max_stars_repo_name": "GUC-Notes/discrete-math-", "max_stars_repo_head_hexsha": "f9917c08e9b9706427153a405b03907a26fab2c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-10-14T03:38:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-01T20:13:25.000Z", "max_issues_repo_path": "Lecture2/Lecture2.tex", "max_issues_repo_name": "GUC-Notes/discrete-math-", "max_issues_repo_head_hexsha": "f9917c08e9b9706427153a405b03907a26fab2c7", "max_issues_repo_licenses": ["MIT"], "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/Lecture2.tex", "max_forks_repo_name": "GUC-Notes/discrete-math-", "max_forks_repo_head_hexsha": "f9917c08e9b9706427153a405b03907a26fab2c7", "max_forks_repo_licenses": ["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.3614457831, "max_line_length": 221, "alphanum_fraction": 0.659967409, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.6110246636897166}}
{"text": "\\documentclass[letterpaper,11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[hmargin=1.25in,vmargin=1in]{geometry}\n\\usepackage{booktabs}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{lmodern}\n\\usepackage{microtype}\n\\usepackage{pdflscape}\n\\usepackage{subcaption}\n\n\\title{Coursework 3: STAT 570}\n\\author{Philip Pham}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\begin{enumerate}\n\\item Consider the Poisson-gamma random effects model given by\n  \\begin{align}\n    Y_i \\mid \\mu_i, \\theta_i\n    &\\sim \\operatorname{Poisson}\\left(\\mu_i\\theta_i\\right) \\\\\n    \\theta_i\n    &\\sim \\operatorname{Gamma}\\left(b, b\\right),\n  \\end{align}\n  which leads to a negative binomial marginal model with the variance a\n  quadratic function of the mean. Design a simulation study, along the lines of\n  that which produced Table 2.3 in the book (overdispersed Poisson example) to\n  investigate the efficiency and robustness under\n  \\begin{itemize}\n  \\item a Poisson model;\n  \\item quasi-likelihood with $\\mathbb{E}\\left[Y\\right] = \\mu$ and\n    $\\operatorname{Var}\\left(Y\\right) = \\alpha\\mu$; and\n  \\item sandwich estimation.\n  \\end{itemize}\n\n  Use a log-linear model\n  \\begin{equation}\n    \\log \\mu_i = \\beta_0 + \\beta_1x_i,\n  \\end{equation}\n  with $x_i \\sim_\\mathrm{iid} \\mathcal{N}\\left(0, 1\\right)$ for\n  $i = 1,2,\\ldots,n$, and $\\beta_0 = -2$ and $\\beta_1 = \\log 2$.\n\n  Simulate for:\n  \\begin{itemize}    \n  \\item $b \\in \\left\\{0.2,1,10,1000\\right\\}$.\n  \\item $n \\in \\left\\{10, 20, 50, 100, 250\\right\\}$.\n  \\end{itemize}\n\n  Summarize what your take away message is after carrying out these simulations.\n\n  \\begin{description}\n  \\item[Solution:] Note that\n    \\begin{align}\n      \\mathbb{P}\\left(\n      Y_i = y \\mid \\mu_i\n      \\right)\n      &= \\int_0^\\infty\\mathbb{P}\\left(\n      Y_i = y \\mid \\mu_i, \\theta_i = \\theta\n      \\right)\\mathbb{P}\\left(\n      \\theta_i = \\theta\n      \\mid b\n        \\right)\n        \\,\\mathrm{d}\\theta \\nonumber\\\\\n      &= \\int_0^\\infty\n        \\left(\n        \\frac{\\left(\\mu_i\\theta\\right)^y}{y!}\\exp\\left(-\\mu_i\\theta\\right)\n        \\right)\n        \\left(\n        \\frac{b^b}{\\Gamma(b)}\\theta^{b-1}\n        \\exp\\left(-b\\theta\\right)\n        \\right)        \n        \\,\\mathrm{d}\\theta \\nonumber\\\\\n      &= \\frac{\\mu_i^y b^b}{y!\\Gamma(b)}\n        \\int_0^\\infty\n        \\theta^{b + y - 1}\\exp\\left(-\\theta(b + \\mu_i)\\right)\n        \\,\\mathrm{d}\\theta \\nonumber\\\\\n      &= \\frac{\\Gamma(y + b)}{y!\\Gamma(b)}\n        \\frac{\\mu_i^y b^b}{\\left(\\mu_i + b\\right)^{b + y}}\n        = \\frac{\\Gamma(y + b)}{y!\\Gamma(b)}\n        \\left(\\frac{b}{\\mu_i + b}\\right)^b\n        \\left(\\frac{\\mu_i}{\\mu_i + b}\\right)^y\n        \\nonumber\\\\\n      &\\sim \\operatorname{NegativeBinomial}\\left(\n        b,\n        \\frac{\\mu_i}{\\mu_i + b}\n        \\right).\n        \\label{eqn:p1_negative_binomial}\n    \\end{align}\n\n    By properties of the negative binomial distribution, we have that\n    \\begin{align}\n      \\mathbb{E}\\left[\n      Y_i\n      \\mid x_i\n      \\right]\n      &= \\mu_i = \\exp\\left(\\beta_0 + \\beta_1x_i\\right) \\nonumber\\\\\n      \\operatorname{Var}\\left(Y_i \\mid x_i\\right)\n      &= \\mu_i\\left(\n        1 + \\frac{\\mu_i}{b}\n        \\right).\n      \\label{eqn:p1_y_mean_variance}\n    \\end{align}\n    Thus, variance has a quadratic dependence on the mean, and smaller values of\n    $b$ correspond to more dispersion.\n\n    \\subsection*{Poisson Model}\n\n    In the Poisson model, we assume that\n    $\\operatorname{Var}\\left(Y_i \\mid x_i\\right) = \\mu_i$, e.g.\n    $b \\rightarrow \\infty$, so we neglect the overdispersion parameter.\n\n    In this case, the log-likelihood function is\n    \\begin{equation}\n      l\\left(\\beta\\right) =\n      \\sum_{i=1}^n\\left[\n        y_i\\left(\\beta_0 + \\beta_1x_i\\right) -\n        \\exp\\left(\\beta_0 + \\beta_1x_i\\right) -\n        \\sum_{k=1}^{y_i}\\log k\n      \\right],\n    \\end{equation}\n    which gives us the score function\n    \\begin{equation}\n      S\\left(\\beta\\right) = \\sum_{i=1}^n\\begin{pmatrix}\n        y_i - \\exp\\left(\\beta_0 + \\beta_1x_i\\right) \\\\\n        x_iy_i - x_i\\exp\\left(\\beta_0 + \\beta_1x_i\\right)\n      \\end{pmatrix}.\n      \\label{eqn:p1_score_function}\n    \\end{equation}\n    We can estimate $\\beta$ by solving for\n    $S\\left(\\hat{\\beta}\\right) = \\mathbf{0}$, numerically.\n\n    We can estimate the variance of the estimates from the Fisher information,\n    \\begin{align}\n      \\operatorname{Var}\\left(\n      \\hat{\\beta}\n      \\right)\n      &\\approx\n        I_n\\left(\\hat{\\beta}\\right)^{-1} \\label{eqn:p1_beta_hat_variance}\\\\\n      &= \\left(\n        \\sum_{i=1}^n\\begin{pmatrix}\n          \\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right) &\n          x_i\\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right) \\\\\n          x_i\\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right) &\n          x_i^2\\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right)\n        \\end{pmatrix} \\right)^{-1}  \\nonumber\\\\\n      &= \\frac{1}{\n        \\left(\\sum_{i=1}^n \\hat{\\mu}_i\\right)\\left(\\sum_{i=1}^n x_i^2\\hat{\\mu}_i\\right)\n        - \\left(\\sum_{i=1}^n x_i\\hat{\\mu}_i\\right)^2}\n        \\begin{pmatrix}\n          \\sum_{i=1}^n x_i^2\\hat{\\mu}_i &\n          -\\sum_{i=1}^n x_i\\hat{\\mu}_i \\\\\n          -\\sum_{i=1}^n x_i\\hat{\\mu}_i &\n          \\sum_{i=1}^n \\hat{\\mu}_i\n        \\end{pmatrix}, \\nonumber\n    \\end{align}\n    where $\\hat{\\mu}_i = \\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right)$.\n    \n    \\subsection*{Quasi-likelihood}\n\n    In a quasi-likelihood model, we specify the mean and variance as\n    \\begin{align}\n      \\mathbb{E}\\left[\n      Y_i\n      \\mid x_i\n      \\right]\n      &= \\mu_i = \\exp\\left(\\beta_0 + \\beta_1x_i\\right) \\nonumber\\\\\n      \\operatorname{Var}\\left(Y_i \\mid x_i\\right)\n      &= \\alpha \\mu_i\n      \\label{eqn:p1_y_quasi_mean_variance}\n    \\end{align}\n    From Equation \\ref{eqn:p1_y_mean_variance}, we see that this is not quite\n    correct, still, but it is closer to the real model than the Poisson model.\n\n    Then, by Equation 2.30 of Wakefield's \\emph{Bayesian and Frequentist\n      Regression Methods} our estimating function is\n    \\begin{align}\n      U\\left(\\beta\\right)\n      &= D^\\intercal V^{-1}\\left(y - \\mu\\right)/\\alpha \\nonumber\\\\\n      &= \\sum_{i=1}^n\\begin{pmatrix}\n        \\exp\\left(\\beta_0 + \\beta_1x_i\\right) \\\\\n        x_i\\exp\\left(\\beta_0 + \\beta_1x_i\\right)\n      \\end{pmatrix}\n      \\frac{y_i - \\exp\\left(\\beta_0 + \\beta_1x_i\\right)}{\\alpha\\exp\\left(\\beta_0 + \\beta_1x_i\\right)}\n      \\nonumber\\\\\n      &= \\frac{1}{\\alpha}\\sum_{i=1}^n\\begin{pmatrix}\n        y_i - \\exp\\left(\\beta_0 + \\beta_1x_i\\right) \\\\\n        x_iy_i - x_i\\exp\\left(\\beta_0 + \\beta_1x_i\\right)\n      \\end{pmatrix} = \\frac{1}{\\alpha}S\\left(\\beta\\right)\n      \\label{eqn:p1_quasi_likelihood_score_function}\n    \\end{align}\n    from Equation \\ref{eqn:p1_score_function}. Thus, the maximum\n    quasi-likelihood estimate will be the same as the maximum likelihood\n    estimate from the Poisson model.\n\n    Having solved for $\\hat{\\beta}$, we have\n    \\begin{equation}\n      \\hat{\\mu} = \\exp\\left(\\hat{\\beta}_0 + \\hat{\\beta}_1x_i\\right).\n      \\label{eqn:p1_mu_hat}\n    \\end{equation}\n\n    by Equation 2.31 of Wakefield's \\emph{Bayesian and Frequentist Regression\n      Methods}, we can then compute\n    \\begin{equation}\n      \\hat{\\alpha}_n\n      = \\frac{1}{n-2}\\sum_{i=1}^n \\frac{\\left(y_i - \\hat{\\mu}_i\\right)^2}{\\hat{\\mu}_i}\n      \\label{eqn:p1_alpha_hat}\n    \\end{equation}\n\n    Then, the variance of our estimates is\n    \\begin{align}\n      \\operatorname{Var}\\left(\n      \\hat{\\beta}\n      \\right)\n      &\\approx\n      \\hat{\\alpha}_n\\left(\\hat{D}^\\intercal \\hat{V}^{-1} \\hat{D}\\right)^{-1} \\nonumber\\\\\n      &= \\hat{\\alpha}_n\\left(\\sum_{i=1}^n\n        \\begin{pmatrix}\n          \\hat{\\mu_i} & x_i\\hat{\\mu_i} \\\\\n          x_i\\hat{\\mu_i} & x_i^2\\hat{\\mu_i}.\n        \\end{pmatrix}\\right)^{-1}\n        \\nonumber\\\\\n      &= \\hat{\\alpha}_nI_n\\left(\\hat{\\beta}\\right)^{-1}\n        \\label{eqn:p1_beta_hat_quasi_variance}\n    \\end{align}\n    from Equation \\ref{eqn:p1_beta_hat_variance}.\n\n    \\subsection*{Sandwich Estimation}\n\n    In sandwich estimation, we only need to specify an estimating function\n    $G\\left(\\beta\\right)$. Then, we can apply Equation 2.43 of Wakefield's\n    \\emph{Bayesian and Frequentist Regression Methods} to compute the variance\n    of our estimates:\n    \\begin{align}\n      \\operatorname{Var}\\left(\\hat{\\beta}\\right)\n      &= \\frac{1}{n}\\hat{A}^{-1}\\hat{B}\\left(\\hat{A}^{-1}\\right)^\\intercal \\nonumber\\\\\n      \\hat{A}\n      &= -\\frac{1}{n}\\sum_{i=1}^n\n        \\frac{\\partial}{\\partial\\beta}G\\left(\\hat{\\beta}, X_i, Y_i\\right) \\nonumber\\\\\n      \\hat{B}\n      &= \\frac{1}{n}\\sum_{i=1}^n\n        G\\left(\\hat{\\beta}, X_i, Y_i\\right)G\\left(\\hat{\\beta}, X_i, Y_i\\right)^\\intercal.\n        \\nonumber\n    \\end{align}\n\n    We can reuse the score function from the quasi-likelihood estimate in\n    Equation \\ref{eqn:p1_quasi_likelihood_score_function} without $\\alpha$, so\n    \\begin{equation}\n      G\\left(\\hat{\\beta}, X_i, Y_i\\right)\n      = \\begin{pmatrix}\n        Y_i - \\hat{\\mu}_i \\\\\n        X_i\\left(Y_i - \\hat{\\mu}_i\\right)\n      \\end{pmatrix}\n    \\end{equation}\n    Thus, our estimate for $\\hat{\\beta}$ will remain the same.\n\n    From Equations \\ref{eqn:p1_beta_hat_variance} and\n    \\ref{eqn:p1_beta_hat_quasi_variance}, we have that\n    \\begin{equation}\n      \\hat{A} = \\frac{1}{n}\\hat{D}\\hat{V}^{-1}\\hat{D} = \\frac{1}{n}I_n\\left(\\hat{\\beta}\\right)\n    \\end{equation}\n\n    From Equation \\ref{eqn:p1_quasi_likelihood_score_function}, we have that\n    \\begin{align}\n      \\hat{B}\n      &= \\frac{1}{n}\n        \\hat{D}^\\intercal\\hat{V}^{-1}\\operatorname{diag}\\left(RR^\\intercal\\right)\\hat{V}^{-1}\\hat{D}\n      \\nonumber\\\\\n      &= \\frac{1}{n}\\hat{D}^\\intercal\\begin{pmatrix}\n        \\frac{\\left(y_1 - \\hat{\\mu}_1\\right)^2}{\\hat{\\mu}_1^2} & & \\\\\n        & \\ddots &\\\\\n        & &\\frac{\\left(y_n - \\hat{\\mu}_n\\right)^2}{\\hat{\\mu}_n^2}\n      \\end{pmatrix}\\hat{D} =\n            \\frac{1}{n}\\sum_{i=1}^n \\frac{\\left(y_i - \\hat{\\mu}_i\\right)^2}{\\hat{\\mu}_i^2}\n      \\begin{pmatrix}\n        \\hat{\\mu}_i^2 & x_i\\hat{\\mu}_i^2 \\\\\n        x_i\\hat{\\mu}_i^2 & x_i^2\\hat{\\mu}_i^2\n      \\end{pmatrix} \\nonumber\\\\\n      &= \\frac{1}{n}\\sum_{i=1}^n\\left(y_i-\\hat{\\mu}_i\\right)^2\n        \\begin{pmatrix}\n          1 & x_i\\\\\n          x_i & x_i^2\n        \\end{pmatrix} = \\frac{1}{n}\\sum_{i=1}^n\n                G\\left(\\hat{\\beta},x_i,y_i\\right)G\\left(\\hat{\\beta},x_i,y_i\\right)^\\intercal.\n    \\end{align}\n\n    \\subsection*{Results}\n\n    The results of estimating $\\beta_0$ and $\\beta_1$ under various models for\n    different $b$ and $n$ can be seen in Tables \\ref{tab:p1_results_beta_0} and\n    \\ref{tab:p1_results_beta_1} for $\\beta_0$ and $\\beta_1$, respectively. How\n    often the 95\\% confidence interval contains the true value of $\\beta_j$ was\n    calculated for each simulation.\n\n    When $b \\in \\{10,1000\\}$, there is not much dispersion, and the Poisson\n    model does well for all $n$. At smaller values of $b$, the coverage is not\n    very good.\n\n    The quasi-likelihood model does better than the Poisson model for\n    $n \\geq 50$. For smaller values of $n$, its confidence intervals often fail\n    to cover the true value. The quasi-likelihood model does a poorer job as\n    covering $\\beta_1$, however.\n    \n    For $\\beta_1$, only sandwich estimation produces good confidence intervals\n    for small $b$. However, it needs a lot of samples to do so, typically\n    $n = 250$ or $n = 1000$. When $n$ is smaller it often performs worse than\n    both the Poisson and quasi-likelihood models.\n    \n    Code for the simulations can be found at\n    \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw3/poisson\\_gamma\\_random\\_effects.ipynb}{\\texttt{poisson\\_gamma\\_random\\_effects.ipynb}}.\n  \\end{description}\n\n  \\begin{landscape}\n    \\begin{table}\n      \\tiny\n      \\begin{subtable}{9in}\n        \\input{p1_beta_0.tex}\n        \\caption{95\\% confidence interval converage for $\\beta_0$.}\n        \\label{tab:p1_results_beta_0}\n      \\end{subtable}\n      \n      \\begin{subtable}{9in}\n        \\input{p1_beta_1.tex}\n        \\caption{95\\% confidence interval converage for $\\beta_1$.}\n        \\label{tab:p1_results_beta_1}\n      \\end{subtable}\n\n      \\caption{The results of fitting various models to the data from a\n        Poisson-gamma random effects model. 100,000 simulations were done for\n        each $(\\text{model}, b, n)$ tuple.}\n      \\label{tab:p1_results}  \n    \\end{table}\n  \\end{landscape}\n  \n\n\\item The data in Table \\ref{tab:p2_data} contain data on a typical reliability\n  experiment and give the failure stresses (in GPa) of four samples of carbon\n  fibers of lengths 1, 10, 20 and 50mm.\n\n  \\begin{table}\n    \\tiny\n    \\centering\n    \\input{p2_data.tex}\n    \\caption{Failure stress data for four groups of fibers.}\n    \\label{tab:p2_data}\n  \\end{table}\n\n  \\begin{enumerate}\n  \\item The exponential distribution\n    $Y \\mid \\lambda \\sim_\\mathrm{iid} \\operatorname{Exponential}(\\lambda)$, is a\n    simple model for reliability data:\n    \\begin{equation}\n      p\\left(y \\mid \\lambda \\right) =\n      \\lambda \\exp\\left(-\\lambda y\\right),\n      \\label{eqn:p2_exponential_pdf}\n    \\end{equation}\n    with $\\lambda, y > 0$. The hazard function is the probability of imminent\n    failure and is given by\n    \\begin{equation}\n      h\\left(y\\mid\\lambda\\right) =\n      \\frac{p\\left(y \\mid \\lambda\\right)}{S\\left(y\\mid\\lambda\\right)},\n      \\label{eqn:p2_hazard_definition}\n    \\end{equation}\n    where\n    $S\\left(y\\mid\\lambda\\right) = \\mathbb{P}\\left(Y > y \\mid \\lambda\\right)$ is\n    the probability of failure beyond $y$. Derive the hazard function for the\n    exponential distribution. Suppose we have a sample $y_1,\\ldots,y_n$, of size\n    $n$ from an exponential distribution. Find the form of the MLE of $\\lambda$\n    and the asymptotic variance.\n      \\begin{description}\n      \\item[Solution:] The survival function can be derived with Equation\n        \\ref{eqn:p2_exponential_pdf} as\n        \\begin{align}\n          S\\left(y\\mid\\lambda\\right)\n          &= \\mathbb{P}\\left(Y > y \\mid \\lambda\\right) \\nonumber\\\\\n          &= \\int_y^\\infty \\lambda \\exp\\left(-\\lambda t\\right)\\,\\mathrm{d}t \\nonumber\\\\\n          &= \\left. -\\exp\\left(-\\lambda t\\right) \\right|^\\infty_y \\nonumber \\\\\n          &= \\exp\\left(-\\lambda y\\right).\n            \\label{eqn:p2_survival}\n        \\end{align}\n\n        With Equations \\ref{eqn:p2_hazard_definition} and \\ref{eqn:p2_survival},\n        the hazard function is\n        \\begin{equation}\n          h\\left(y\\mid\\lambda\\right) =\n          \\frac{p\\left(y \\mid \\lambda\\right)}{S\\left(y\\mid\\lambda\\right)}\n          = \\frac{\\lambda \\exp\\left(-\\lambda y\\right)}{\\exp\\left(-\\lambda y\\right)} = \\lambda.\n          \\label{eqn:p2_hazard}\n        \\end{equation}\n      \\end{description}\n\n      Given $y_1,\\ldots,y_n$, the log-likelihood function is\n      \\begin{equation}\n        l\\left(\\lambda\\right) = n\\log\\lambda - \\lambda\\sum_{i=1}^n y_i.\n        \\label{eqn:p2_exponential_log_likelihood}\n      \\end{equation}\n\n      From Equation \\ref{eqn:p2_exponential_log_likelihood}, the score function is\n      \\begin{equation}\n        S\\left(\\lambda\\right) = \\frac{n}{\\lambda} - \\sum_{i=1}^n y_i.\n        \\label{eqn:p2_exponential_score}\n      \\end{equation}\n      Solving $S\\left(\\hat{\\lambda}\\right) = 0$, gives use the MLE,\n      $\\boxed{\\hat{\\lambda} = \\frac{n}{\\sum_{i=1}^n y_i} = \\frac{1}{\\bar{y}}.}$\n\n      The asymptotic variance can be derived from the Fisher information\n      \\begin{equation}\n        I_n\\left(\\hat{\\lambda}\\right)\n        = \\operatorname{Var}\\left(S\\left(\\hat{\\lambda}\\right)\\right)\n        = \\frac{n}{\\hat{\\lambda}^2}.\n      \\end{equation}\n\n      Thus, we have that\n      $\\boxed{\\operatorname{Var}\\left(\\hat{\\lambda}\\right) =\n        \\frac{\\hat{\\lambda}^2}{n}.}$      \n      \n    \\item For each of the four groups in Table \\ref{tab:p2_data}, estimate a\n      separate $\\lambda$, with an associated standard error. Examine the\n      appropriateness of the exponential model via Q-Q plots.\n\n      \\begin{description}\n      \\item[Solution:] The estimates and standard errors for $\\lambda$ are in\n        Table \\ref{tab:p2_exponential_estimates}.\n\n        \\begin{table}\n          \\centering\n          \\input{p2_exponential_estimates.tex}\n          \\caption{Results of fitting an exponential model for each length.}\n          \\label{tab:p2_exponential_estimates}\n        \\end{table}\n\n        From the Q-Q plots in Figure \\ref{fig:p2_qq_exponential}, we see that\n        the exponential model is a very poor fit for the data. The sampled\n        quantiles are very different than the theoretical quantiles. Thus, the\n        model appears to be misspecified.\n\n        \\begin{figure}\n          \\centering\n          \\includegraphics{p2_qq_exponential.pdf}\n          \\caption{Q-Q plots at each length when fitting an exponential model\n            using the MLE.}\n          \\label{fig:p2_qq_exponential}\n        \\end{figure}\n      \\end{description}\n\n      Code for calculations and plots can be found in\n      \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw3/failure\\_stresses.ipynb}{\\texttt{failure\\_stresses.ipynb}}.\n      \n    \\item Consider a quasi-likelihood approach to inference for $\\lambda$ under\n      the model with\n      \\begin{align}\n        \\mathbb{E}\\left[Y \\mid \\lambda \\right]\n        &= \\lambda^{-1} \\nonumber\\\\\n        \\operatorname{Var}\\left(Y \\mid \\lambda\\right)\n        &= \\alpha\\lambda^{-2}\n        \\label{eqn:p2_quasi_likelihood_model}\n      \\end{align}\n      with $\\alpha > 0$. Suggest an estimator for $\\alpha$.  Estimate $\\lambda$,\n      $\\alpha$, and the standard errors, separately for each of the four groups\n      in Table \\ref{tab:p2_data}. What do the results suggest to you about the\n      fit of the exponential model?\n\n      \\begin{description}\n      \\item[Solution:] The quasi-likelihood score is\n        \\begin{align}\n          U\\left(\\lambda\\right)\n          &= D^\\intercal V^{-1}\n            \\left(Y - \\mathbb{E}\\left[Y \\mid \\lambda \\right]\\right)/\\alpha \\nonumber\\\\\n          &= \\begin{pmatrix}\n            -\\lambda^{-2} & \\cdots & -\\lambda^{-2}\n          \\end{pmatrix} \\begin{pmatrix}\n            \\lambda^{2} & & \\\\\n            & \\ddots & \\\\\n            & & \\lambda^{2}\n          \\end{pmatrix} \\begin{pmatrix}\n            \\frac{Y_1 - \\lambda^{-1}}{\\alpha} \\\\\n            \\vdots \\\\\n            \\frac{Y_n - \\lambda^{-1}}{\\alpha}\n          \\end{pmatrix} \\nonumber\\\\\n          &= -\\frac{1}{\\alpha}\\sum_{i=1}^n\\left(Y_i - \\lambda^{-1}\\right)\n            = -\\frac{1}{\\alpha}\\left(\\sum_{i=1}^nY_i - n\\lambda^{-1}\\right).\n            \\label{eqn:p2_quasi_score}\n        \\end{align}\n        \n        Solving Equation \\ref{eqn:p2_quasi_score},\n        $U\\left(\\hat{\\lambda}\\right) = 0$, we get\n        $\\hat{\\lambda} = \\bar{Y}^{-1}$, which is the same as the MLE estimate.\n\n        $\\hat{\\alpha}$ is given by Equation 2.31 of Wakefield's \\emph{Bayesian\n          and Frequentist Regression Methods}:\n        \\begin{equation}\n          \\hat{\\alpha}\n          = \\frac{1}{n - 1}\\sum_{i=1}^n\\frac{\\left(Y_i - \\hat{\\mu}\\right)^2}{V\\left(\\hat{\\mu}\\right)}\n          = \\frac{\\hat{\\lambda}^2}{n - 1}\\sum_{i=1}^n\\left(Y_i - \\hat{\\lambda}^{-1}\\right)^2.\n        \\end{equation}\n\n        We have that\n        \\begin{equation}\n          \\operatorname{Var}\\left(U\\left(\\lambda\\right)\\right)\n          = \\mathbb{E}\\left[- \\frac{\\partial U}{\\partial \\lambda}(\\lambda)\\right]\n          = \\frac{n\\lambda^{-2}}{\\alpha},\n        \\end{equation}\n        we can estimate\n        \\begin{equation}\n          \\operatorname{Var}\\left(\\hat{\\lambda}\\right) =\n          \\operatorname{Var}\\left(U\\left(\\hat{\\lambda}\\right)\\right)^{-1}\n          \\approx \\frac{\\hat{\\alpha}\\hat{\\lambda}^2}{n},\n        \\end{equation}\n        which is the same as the variance for the MLE estimate multiplied by\n        $\\hat{\\alpha}$. The results of fitting the quasi-likelihood model can be\n        seen in Table \\ref{tab:p2_quasi_likelihood_estimates}.\n\n        \\begin{table}\n          \\centering\n          \\input{p2_quasi_likelihood_estimates.tex}\n          \\caption{Results of fitting a quasi-likelihood model for each length.}\n          \\label{tab:p2_quasi_likelihood_estimates}\n        \\end{table}\n\n        From Equation \\ref{eqn:p2_quasi_score}, we see that a quadratic variance\n        function leads to the same score function as Gamma distribution\n        with fixed shape parameter $\\alpha^{-1}$ and rate parameter\n        $\\lambda\\alpha^{-1}$. $\\alpha = 1$ would correspond to the\n        exponential distribution, so it is unsurprising to see that our estimate\n        for $\\lambda$ is the same as the MLE estimate.\n\n        \\begin{figure}\n          \\centering\n          \\includegraphics{p2_qq_quasi_likelihood.pdf}\n          \\caption{Q-Q plots at each length with a Gamma distribution. The shape\n            parameter $\\hat{\\alpha}^{-1}$ and rate parameter\n            $\\hat{\\lambda}\\hat{\\alpha}^{-1}$ were estimated using\n            quasi-likelihood.}\n          \\label{fig:p2_qq_quasi_likelihood}\n        \\end{figure}\n        \n        Standard errors are much smaller than those estimated in Table\n        \\ref{tab:p2_exponential_estimates}. From Figure\n        \\ref{fig:p2_qq_exponential}, we see that the residuals are\n        underdispersed relative to an exponential model, so $\\hat{\\alpha} < 1$,\n        which leads to the smaller standard error estimates.\n\n        Q-Q plots with the theoretical quantiles derived from\n        $\\operatorname{Gamma}\\left(\\hat{\\alpha}^{-1},\n          \\lambda\\hat{\\alpha}^{-1}\\right)$ in Figure\n        \\ref{fig:p2_qq_quasi_likelihood}. The points lie close the $y = x$\n        line. This suggests that the Gamma and quasi-likelihood model are more\n        appropriate. They better capture the variance model compared to the\n        exponential model.\n\n        Code for calculations and plots can be found in\n        \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw3/failure\\_stresses.ipynb}{\\texttt{failure\\_stresses.ipynb}}.\n      \\end{description}\n    \\item Obtain the form of the sandwich estimate for the variance of\n      $\\hat{\\lambda}$. Numerically evaluate sandwich standard errors for the\n      estimate of $\\lambda$ in each of the four groups.\n\n      \\begin{description}\n      \\item[Solution:] We apply Equation 2.43 of Wakefield's \\emph{Bayesian and\n          Frequentist Regression Methods} to compute the variance of our\n        parameter estimate:\n    \\begin{align}\n      \\operatorname{Var}\\left(\\hat{\\lambda}\\right)\n      &= \\frac{1}{n}\\hat{A}^{-1}\\hat{B}\\left(\\hat{A}^{-1}\\right)^\\intercal \\nonumber\\\\\n      \\hat{A}\n      &= -\\frac{1}{n}\\sum_{i=1}^n\n        \\frac{\\partial}{\\partial\\lambda}G\\left(\\hat{\\lambda}, Y_i\\right) \\nonumber\\\\\n      \\hat{B}\n      &= \\frac{1}{n}\\sum_{i=1}^n\n        G\\left(\\hat{\\lambda}, Y_i\\right)G\\left(\\hat{\\lambda}, Y_i\\right)^\\intercal, \\nonumber\n    \\end{align}\n    where we resue the quasi-score from Equation \\ref{eqn:p2_quasi_score} to\n    specify\n    \\begin{equation}\n      G\\left(\\lambda, Y_i\\right) = \\frac{1}{\\lambda} - Y_i\n      \\label{eqn:p2_sandwich_score}\n    \\end{equation}\n    as our estimating function.\n\n    Thus, we'll have that\n    \\begin{align}\n      \\hat{A}\n      &= \\frac{1}{n}I\\left(\\hat{\\lambda}\\right) = \\frac{1}{\\hat{\\lambda}^2} \\nonumber\\\\\n      \\hat{B}\n      &= \\frac{1}{n}\\sum_{i=1}^n\\left(Y_i - \\frac{1}{\\hat{\\lambda}}\\right)^2.\n    \\end{align}\n\n    Thus, our sandwich estimate will be\n    \\begin{equation}\n      \\boxed{\n        \\operatorname{Var}\\left(\\hat{\\lambda}\\right)\n        = \\frac{\\hat{\\lambda}^4}{n^2}\\sum_{i=1}^n\\left(Y_i - \\frac{1}{\\hat{\\lambda}}\\right)^2.\n      }\n      \\label{eqn:p2_sandwich_variance}\n    \\end{equation}\n    The results of applying Equations \\ref{eqn:p2_sandwich_score} and\n    \\ref{eqn:p2_sandwich_variance} can be seen in Table \\ref{tab:p2_sandwich\n      estimates}.   \n    \n    \\begin{table}\n      \\centering \\input{p2_sandwich_estimates.tex}\n      \\caption{Results of fitting a model with sandwich estimation for each\n        length.}\n      \\label{tab:p2_sandwich estimates}\n    \\end{table}\n\n    The estimates for $\\hat{\\lambda}$ are of course the same as in Tables\n    \\ref{tab:p2_exponential_estimates} and\n    \\ref{tab:p2_quasi_likelihood_estimates}, since we reused the same score\n    function. The standard errors are smaller than the exponential model since\n    the data is underdispersed in that model. However, they are quite similar to\n    those in the quasi-likelihood model despite not specifying a variance\n    model. From Figure \\ref{fig:p2_qq_quasi_likelihood}, we have evidence that\n    the quasi-likelihood model fits the data well, so it is unsurprising that an\n    empirical estimate would yield similar results.\n  \\end{description}\n  \n\\item The Weibull distribution is a common model for survival or reliability\n  data:\n  $Y \\mid \\eta,\\alpha \\sim_\\mathrm{iid}\n  \\operatorname{Weibull}\\left(\\eta,\\alpha\\right)$, with $\\eta > 0$, and\n  $\\alpha > 0$. The random variable $Y$ has a Weibull distribution if its\n  density can be written in the form\n  \\begin{equation}\n    p\\left(y \\mid \\eta,\\alpha\\right) = \\eta\\alpha^{-\\eta}y^{\\eta-1}\\exp\\left[\n      -\\left(\\frac{y}{\\alpha}\\right)^\\eta\n    \\right].\n    \\label{eqn:p2_weibull_pdf}\n  \\end{equation}\n  \n  Find the mean, variance and hazard function of a Weibull distribution. For\n  what value of the parameters does the exponential distribution result?\n\n  \\begin{description}\n  \\item[Solution:] The mean can be calculated in terms of the Gamma function\n    \\begin{align}\n      \\mathbb{E}\\left[\n      Y \\mid \\eta,\\alpha\n      \\right] = \\int_0^\\infty y p\\left(y \\mid \\eta,\\alpha\\right)\\,\\mathrm{d}y\n      &= \\eta\\int_0^\\infty \\left(\\frac{y}{\\alpha}\\right)^{\\eta}\n        \\exp\\left[\n        -\\left(\\frac{y}{\\alpha}\\right)^\\eta\n        \\right]\\,\\mathrm{d}y\\nonumber\\\\\n      &= \\alpha\\int_0^\\infty u^{1 + 1/\\eta - 1}\\exp\\left(-u\\right)\\,\\mathrm{d}u \\nonumber\\\\\n      &= \\alpha\\Gamma\\left(1 + 1/\\eta\\right).\n        \\label{eqn:p2_weibull_mean}\n    \\end{align}\n\n    We can calculate the second moment similarly,\n    \\begin{align}\n      \\mathbb{E}\\left[\n      Y^2 \\mid \\eta,\\alpha\n      \\right] = \\int_0^\\infty y^2 p\\left(y \\mid \\eta,\\alpha\\right)\\,\\mathrm{d}y\n      &= \\eta\\int_0^\\infty y\\left(\\frac{y}{\\alpha}\\right)^{\\eta}\n        \\exp\\left[\n        -\\left(\\frac{y}{\\alpha}\\right)^\\eta\n        \\right]\\,\\mathrm{d}y\\nonumber\\\\\n      &= \\alpha^2\\int_0^\\infty u^{2 + 1/\\eta - 1}\\exp\\left(-u\\right)\\,\\mathrm{d}u \\nonumber\\\\\n      &= \\alpha^2\\Gamma\\left(2 + 1/\\eta\\right).\n    \\end{align}\n\n    Thus, we have that\n    \\begin{equation}\n      \\operatorname{Var}\\left(\n        Y \\mid \\eta,\\alpha\n      \\right) = \\alpha^2\\left(\n        \\Gamma\\left(2 + 1/\\eta\\right) - \\left[\\Gamma\\left(1 + 1/\\eta\\right)\\right]^2\n      \\right).\n    \\end{equation}\n\n    The survival function is\n    \\begin{align}\n      S\\left(y \\mid \\eta,\\alpha\\right)\n      &= \\int_y^\\infty p\\left(t \\mid \\eta,\\alpha\\right)\\,\\mathrm{d}t =\n        \\int_{\\left(y/\\alpha\\right)^\\eta}^\\infty\\exp\\left(-u\\right)\\,\\mathrm{d}u \\nonumber\\\\\n      &= \\exp\\left[-\\left(\\frac{y}{\\alpha}\\right)^\\eta\\right].\n        \\label{eqn:p2_weibull_survival}\n    \\end{align}\n\n    Thus, the hazard function simplifies to\n    \\begin{equation}\n      h\\left(y \\mid \\eta,\\alpha\\right) =\n      \\frac{p\\left(y \\mid \\eta,\\alpha\\right)}{S\\left(y \\mid \\eta,\\alpha\\right)} = \n      \\eta\\alpha^{-\\eta}y^{\\eta-1}.\n      \\label{eqn:p2_weibull_hazard}\n    \\end{equation}\n\n    When $\\eta = 1$, this is just the exponential distribution with rate\n    parameter $\\lambda = \\alpha^{-1}$.       \n  \\end{description}\n\\item Is the Weibull distribution with unknown parameters $\\eta$, $\\alpha$ a\n  member of the exponential family? What are the implications for inference?\n  \\begin{description}\n  \\item[Solution:] No, the Weibull distribution with unknown parameters $\\eta$,\n    $\\alpha$ is not a member of the exponential family. Mainly, if take the\n    $\\log$ of the probability density function, we have the term\n    $\\left(\\frac{y}{\\alpha}\\right)^\\eta$. This can not be written in the form\n    $\\theta^\\intercal T(y)$, where $\\theta$ are parameters and $T(y)$ is a\n    transformation of $y$ into a finite-dimensional vector.\n\n    There are implications in inference. The\n    \\href{https://en.wikipedia.org/wiki/Sufficient_statistic#Exponential\\_family}{Pitman-Koopman-Darmois\n      theorem} states that only in exponential families is there a sufficient\n    statistic whose dimension remains bounded as sample size increases. Thus,\n    when inferring the parameters from a sample with maximum likelihood, all the\n    data must be used, which may make the computation intractable for large\n    datasets. Morever, when doing a Bayesian inference, the posterior must be\n    conditioned on all the data rather than a finite set of sufficient\n    statistics, so no conjugate prior will exist.\n\n    In particular, generalized linear models require that the response be\n    generated from a distribution in the exponential family. The special\n    structure of the exponential family make it so the dispersion estimate is an\n    ancillary statistic: its estimation is independent of the estimation of the\n    mean.\n  \\end{description}\n\n\\item For the Weibull model and a random sample of size $n$ obtain: the\n  log-likelihood, the score, and the observed information matrix.\n\n  \\begin{description}\n  \\item[Solution:] The log-likelihood function is\n    \\begin{equation}\n      l\\left(\\eta,\\alpha\\right)\n      = \\sum_{i = 1}^n\\left(\n        \\log\\eta - \\eta\\log\\alpha + \\left(\\eta - 1\\right)\\log y_i\n        - \\exp\\left[\\eta\\left(\\log y_i - \\log\\alpha\\right)\\right]\\right)\n    \\end{equation}\n\n    From which, we have the score function\n    \\begin{equation*}\n      S\\left(\\eta,\\alpha\\right) = \\sum_{i=1}^n\n      \\begin{pmatrix}\n        \\frac{1}{\\eta} - \\log\\alpha + \\log y_i -\n        \\left(\\log y_i - \\log\\alpha\\right)\n        \\exp\\left[\\eta\\left(\\log y_i - \\log\\alpha\\right)\\right]\n        \\\\\n        -\\frac{\\eta}{\\alpha}\n        +\\frac{\\eta}{\\alpha}\\exp\\left[\\eta\\left(\\log y_i - \\log\\alpha\\right)\\right]\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    The observed information for a single observation is\n    \\begin{align*}\n      I_{y_i}\\left(\\eta, \\alpha\\right)\n      &= -\\nabla \\nabla^\\intercal l\\left(\\eta,\\alpha\\right) = \\nabla S\\left(\\eta,\\alpha\\right) \\\\\n      &= \\begin{pmatrix}\n        \\frac{1}{\\eta^2} + \\left(\\log \\frac{y_i}{\\alpha}\\right)^2\n        \\left(\\frac{y_i}{\\alpha}\\right)^\\eta\n        &\n        \\frac{1}{\\alpha} - \\frac{1}{\\alpha}\\left(\\frac{y_i}{\\alpha}\\right)^\\eta -\n        \\frac{\\eta}{\\alpha}\\left(\\log \\frac{y_i}{\\alpha}\\right)\\left(\\frac{y_i}{\\alpha}\\right)^\\eta\n        \\\\\n        \\frac{1}{\\alpha} - \\frac{1}{\\alpha}\\left(\\frac{y_i}{\\alpha}\\right)^\\eta -\n        \\frac{\\eta}{\\alpha}\\left(\\log \\frac{y_i}{\\alpha}\\right)\\left(\\frac{y_i}{\\alpha}\\right)^\\eta\n        &\n        -\\frac{\\eta}{\\alpha^2} + \\frac{\\eta}{\\alpha^2}\\left(\\frac{y_i}{\\alpha}\\right)^\\eta\n        + \\left(\\frac{\\eta}{\\alpha}\\right)^2\\left(\\frac{y_i}{\\alpha}\\right)^\\eta\n      \\end{pmatrix}.\n    \\end{align*}\n\n    The total observed information is then $\\displaystyle\n    I_n\\left(\\eta,\\alpha\\right) = \\sum_{i=1}^nI_{y_i}\\left(\\eta,\\alpha\\right)$.\n  \\end{description}\n  \n\\item Solve the score equations in order to obtain the maximum likelihood\n  estimators (MLEs). You should obtain a single equation that needs to be\n  numerically solved.\n\n  \\begin{description}\n  \\item[Solution:] We want to solve the two equations given by\n    $S\\left(\\hat{\\eta}, \\hat{\\alpha}\\right) = \\mathbf{0}$.\n\n    We can solve for $\\hat{\\alpha}$ in terms of $\\hat{\\eta}$ from the second\n    entry:\n    \\begin{equation}\n      \\hat{\\alpha} = \\left(\\frac{1}{n}\\sum_{i=1}^n y_i^{\\hat{\\eta}}\\right)^{1/\\hat{\\eta}}.\n      \\label{eqn:p2_alpha_hat}\n    \\end{equation}\n\n    Substituting $\\hat{\\alpha}$ with Equation \\ref{eqn:p2_alpha_hat}, we can\n    numerically solve for $\\hat{\\eta}$ in the first entry of the score function.\n  \\end{description}\n\\item Obtain the MLEs and standard errors for the parameters of the Weibull\n  model, for each of the groups in Table \\ref{tab:p2_data}.\n  \\begin{description}\n  \\item[Solution:] The estimates and standard errors can be found in Table\n    \\ref{tab:p2_weibull estimates}. One can see that mean of each estimated\n    distribution $\\hat{\\alpha}\\Gamma\\left(1 + 1/\\hat{\\eta}\\right)$ is quite\n    close to corresponding mean for the exponential distribution\n    $\\hat{\\lambda}^{-1}$.\n\n    \\begin{table}\n      \\centering \\input{p2_weibull_estimates.tex}\n      \\caption{Results of fitting a Weibull model to each length by maximizing\n        likelihood.}\n      \\label{tab:p2_weibull estimates}\n    \\end{table}\n\n    \\begin{figure}\n      \\centering\n      \\includegraphics{p2_qq_weibull.pdf}\n      \\caption{Q-Q plots at each length with a Weibull distribution with\n        parameters in Table \\ref{tab:p2_weibull estimates}.}\n      \\label{fig:p2_qq_weibull}\n    \\end{figure}\n\n    The Q-Q plots in Figure \\ref{fig:p2_qq_weibull} indicate the Weibull\n    distribution fits the data quite well. However, it appears slightly worse\n    than the Gamma distribution: compared to Figure\n    \\ref{fig:p2_qq_quasi_likelihood}, the lower tail is further away from the\n    $y = x$ line. That is, the data are underdispered when fitted to the Weibull\n    distribution.\n\n    Code for calculations and plots can be found in\n    \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw3/failure\\_stresses.ipynb}{\\texttt{failure\\_stresses.ipynb}}.\n  \\end{description}\n\\end{enumerate}\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "497a2a21a65c832fae535d59afbdf71671543f15", "size": 33461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/solutions.tex", "max_stars_repo_name": "ppham27/stat570", "max_stars_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-22T11:05:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T22:46:11.000Z", "max_issues_repo_path": "hw3/solutions.tex", "max_issues_repo_name": "ppham27/stat570", "max_issues_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw3/solutions.tex", "max_forks_repo_name": "ppham27/stat570", "max_forks_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_forks_repo_licenses": ["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.5587878788, "max_line_length": 165, "alphanum_fraction": 0.6275365351, "num_tokens": 10583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.6110246620707529}}
{"text": "%mainfile: ../lecture_notes.tex\n\\chapter{Recursive Least-Squares Adaptive Filters}\n\\label{ch:RLS}\n\\section{Review of the Basics}\n\\subsection{The Matrix Inversion Lemma}\n\\label{sec:woodbury}\nLet $\\vect{X}$, $\\vect{Y}$, $\\vect{X}+\\vect{UYV}$, and $\\vect{Y}^{-1}+\\vect{VX}^{-1}\\vect{U}$ all be non-singular matrices. By equating element $(1,1)$ of the two block matrices in \\eq{eq:block_inv1} and \\eq{eq:block_inv2} and setting\n\\begin{align}\n  \\vect{X} &= \\vect{A}\\\\\n  \\vect{U} &= \\vect{B}\\\\\n  \\vect{V} &= \\vect{C}\\\\\n  \\vect{Y} &= -\\vect{D}^{-1}\\ ,\n\\end{align}\nwe obtain the matrix inversion lemma\n\\bmath\n  (\\vect{X}+\\vect{UYV})^{-1} = \\vect{X}^{-1}-\\vect{X}^{-1}\\vect{U}(\\vect{Y}^{-1}+\\vect{VX}^{-1}\\vect{U})^{-1}\\vect{V}\\vect{X}^{-1}\\ .\n  \\label{eq:woodbury}\n\\emath\nThe matrix inversion lemma is also sometimes called the \\textit{Woodbury matrix identity} or the \\textit{Woodbury's identity}.\n\n\\section{Method of Least-Squares}\nThe adaptive filtering problem is shown in Fig.~\\ref{fig:nonwss_block_diagram2}.\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_diagram2}\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}\nDefine\n\\begin{align}\n  \\vect{w}(n) &= \\bbmtx w_0(n) & w_{1}(n) & \\cdots & w_{M-1}(n)\\ebmtx^T\\\\\n  \\vect{u}(n)&= \\bbmtx u(n) & u(n-1) & \\cdots & u(n-M+1)\\ebmtx^T\\ .\n\\end{align}\nFor $i=1,2,\\ldots,n$ with $n\\geq M$, define\n\\begin{align}\n  \\vect{A}(n) &= \\bbmtx \\vect{u}(1) & \\vect{u}(2) & \\cdots & \\vect{u}(n)\\ebmtx^T\\\\\n  \\vect{d}(n) &= \\bbmtx d(1) & d(2) & \\cdots & d(n)\\ebmtx^T\\\\\n  \\vect{e}(n) &= \\bbmtx e(1) & e(2) & \\cdots & e(n)\\ebmtx^T\\ .\n\\end{align}\nThen\n\\bmath\n  \\vect{e}(n) = \\vect{d}(n)-\\vect{A}(n)\\vect{w}(n)\\quad\\iff\\quad\\vect{d}(n)=\\vect{A}(n)\\vect{w}(n)+\\vect{e}(n)\\ .\n\\emath\nNote that we have made $\\vect{A}(n)$, $\\vect{d}(n)$, and $\\vect{e}(n)$ time-dependent in order to emphasise that we are here concerned with an online algorithm. Therefore, we also formulate the squared error cost function $J_2(\\vect{w}(n))$ in a slightly different way compared to \\eq{eq:cf_squared_error}. Here, we define it as\n\\bmath\n  J_2(\\vect{w}(n)) = \\sum_{i=1}^{n}e^2(i)=\\vect{e}^T(n)\\vect{e}(n)\\ .\n\\emath\n\nIn the method of least-squares, we wish to minimise $J_2(\\vect{w}(n))$ which we can write as\n\\begin{align}\n  J_2(\\vect{w}(n)) &= \\vect{e}^T(n)\\vect{e}(n) = (\\vect{d}(n)-\\vect{A}(n)\\vect{w}(n))^T(\\vect{d}(n)-\\vect{A}(n)\\vect{w}(n))\\notag\\\\\n  &= \\vect{d}^T(n)\\vect{d}(n)+\\vect{w}^T(n)\\vect{A}^T(n)\\vect{A}(n)\\vect{w}(n)-2\\vect{w}^T(n)\\vect{A}^T(n)\\vect{d}(n)\\ .\n\\end{align}\nThe minimiser\n\\bmath\n  \\vect{w}_o(n) = (\\vect{A}^T(n)\\vect{A}(n))^{-1}\\vect{A}^T(n)\\vect{d}(n)\n\\emath\nis referred to as the least-squares solution, and it is the unique solution to the normal equations\n\\bmath\n  \\vect{A}^T(n)\\vect{A}(n)\\vect{w}(n) = \\vect{A}^T(n)\\vect{d}(n)\\ ,\n\\emath\nprovided that $\\vect{A}(n)$ has full rank.\n\n\\subsection{Weighted Least-Squares}\nWhen the statistics of $u(n)$ and/or $d(n)$ is time dependent, the minimisation of the squared error $J_2(\\vect{w}(n))$ may fail to give a good estimate at time $n$ since all data affect the value of $J_2(\\vect{w}(n))$ with the same weight. Ideally, we would like that the new data are assigned a larger weight than the old data. In order to do this, we reformulate $J_2(\\vect{w}(n))$ as a weighted cost function\n\\bmath\n  J_\\beta(\\vect{w}(n)) = \\sum_{i=1}^{n}\\beta(n,i) e^2(i) = \\vect{e}^T(n)\\vect{B}(n) \\vect{e}(n)\n\\emath\nwhere $\\beta(n,i)$ contains the weight pertaining to the $i$'th error at time $n$, and $\\vect{B}(n)$ is a diagonal matrix given by\n\\bmath\n  \\vect{B}(n) = \\diag{\\beta(n,1), \\beta(n,2), \\ldots , \\beta(n,n)}\\ .\n\\emath\nWe use the five step recipe in Sec.~\\ref{ssec:optimisation} to minimise $J_\\beta(\\vect{w}(n))$ w.r.t $\\vect{w}(n)$.\n\\begin{enumerate}\n  \\item Construct the cost function\n  \\begin{align}\n    J_\\beta(\\vect{w}(n)) &= \\vect{e}^T(n)\\vect{B}(n) \\vect{e}(n) = (\\vect{d}(n)-\\vect{A}(n)\\vect{w}(n))^T\\vect{B}(n)(\\vect{d}(n)-\\vect{A}(n)\\vect{w}(n))\\notag\\\\\n    &= \\vect{d}(n)^T\\vect{B}(n)\\vect{d}(n)+\\vect{w}^T(n)\\vect{\\Phi}(n)\\vect{w}(n)-2\\vect{w}^T(n)\\vect{\\varphi}(n)\n  \\end{align}\n  where we have defined $\\vect{\\Phi}(n)$ and $\\vect{\\varphi}(n)$ as\n\\begin{align}\n  \\vect{\\Phi}(n) &= \\vect{A}^T(n)\\vect{B}(n)\\vect{A}(n)\\\\\n  \\vect{\\varphi}(n) &= \\vect{A}^T(n)\\vect{B}(n)\\vect{d}(n)\\ .\n\\end{align}\nWe refer to $\\vect{\\Phi}(n)$ and $\\vect{\\varphi}(n)$ as the correlation matrix and the cross-correlation vector, respectively, since they are scaled and weighted estimates of $\\vect{R}_u$ and $\\vect{r}_{ud}$.\n  \\item Find the gradient\n  \\bmath\n    \\vect{g}(\\vect{w}(n)) = (\\vect{\\Phi}(n)+\\vect{\\Phi}^T(n))\\vect{w}(n)-2\\vect{\\varphi}(n)=2\\vect{\\Phi}(n)\\vect{w}(n)-2\\vect{\\varphi}(n)\n  \\emath\n  \\item Solve $\\vect{g}(\\vect{w}(n))=\\vect{0}$ for $\\vect{w}(n)$\n  \\begin{alignat}{3}\n    &&\\qquad \\vect{g}(\\vect{w}(n)) &= \\mathrlap{2\\vect{\\Phi}(n)\\vect{w}(n)-2\\vect{\\varphi}(n)}\\notag\\\\\n    \\ArrowBetweenLines\n    &&\\qquad \\alignedbox{\\vect{\\Phi}(n)\\vect{w}(n)}{=\\vect{\\varphi}(n)}  &\\qquad &\\text{(Weighted Normal Equations)}\\\\\n    \\ArrowBetweenLines\n    &&\\qquad           \\vect{w}_o(n) &= \\vect{\\Phi}^{-1}(n)\\vect{\\varphi}(n) &\\qquad &\\text{(If }\\vect{\\Phi}(n)\\text{ is invertible)}\n  \\end{alignat}\n  \\item Find the Hessian\n  \\bmath\n    \\vect{H}(\\vect{w}) = 2\\vect{\\Phi}(n)\n  \\emath\n  which is p.d. for all $\\vect{w}(n)$ if $\\vect{A}(n)$ has full rank and $\\beta(n,i)>0$ for all $n\\geq i > 0$.\n  \\item This implies that\n  \\begin{itemize}\n    \\item $J_\\beta(\\vect{w}(n))$ is a convex function, and\n    \\item $\\vect{w}_o(n) = \\vect{\\Phi}^{-1}(n)\\vect{\\varphi}(n)$ is the global minimiser.\n  \\end{itemize}\n\\end{enumerate}\nThe solution $\\vect{w}_o(n)$ is often referred to as the weighted least-squares solution.\n\n\\subsubsection{Estimation of the (Cross-)Correlation}\nComparing the weighted normal equations with the Wiener-Hopf equations, we see that\n\\begin{align}\n  \\hat{\\vect{R}}_u(n) &= c(n,\\beta)\\vect{\\Phi}(n) = c(n,\\beta)\\vect{A}^T(n)\\vect{B}(n)\\vect{A}(n) = c(n,\\beta)\\sum_{i=1}^{n}\\beta(n,i)\\vect{u}(i)\\vect{u}^T(i)\\label{eq:wls_Ru_est}\\\\\n  \\hat{\\vect{r}}_{ud}(n) &= c(n,\\beta)\\vect{\\varphi}(n) = c(n,\\beta)\\vect{A}^T(n)\\vect{B}(n)\\vect{d}(n) = c(n,\\beta)\\sum_{i=1}^{n}\\beta(n,i)\\vect{u}(i)d(i)\\label{eq:wls_rud_est}\n\\end{align}\nare the estimates of the correlation matrix and the cross-correlation vector, respectively. The constant $c(n,\\beta)$ depends on $n$ and the weighting function $\\beta(n,i)$, and it can be selected such that $\\hat{\\vect{R}}_u(n)$ and $\\hat{\\vect{r}}_{ud}(n)$ are unbiased estimates of $\\vect{R}_u(n)$ and $\\vect{r}_{ud}(n)$.\n\n\\subsection{Weight Functions}\nWe consider three simple weight functions.\n\n\\subsubsection{Growing Window Weight Function}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/growing_window}\n  \\caption{The growing window weight function.}\n  \\label{fig:growing_window}\n\\end{figure}\n\\noindent If we select the weight function as\n\\bmath\n  \\beta(n,i) =\n  \\begin{cases}\n    1 & 0 < i \\leq n\\\\\n    0 & \\text{otherwise}\n  \\end{cases}\\ ,\n\\emath\nwe obtain the growing window weight function, and it is sketched in Fig.~\\ref{fig:growing_window}. Selecting the growing window weight function reduces the weighted least-squares problem to the standard least-squares problem. In order to obtain unbiased estimates of $\\vect{R}_u(n)$ and $\\vect{r}_{ud}(n)$ in \\eq{eq:wls_Ru_est} and \\eq{eq:wls_rud_est}, respectively, we have to use\n\\bmath\n  c(n,\\beta) = \\frac{1}{n}\\ .\n\\emath\n\n\\subsubsection{Sliding Window Weight Function}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/sliding_window}\n  \\caption{The sliding window weight function.}\n  \\label{fig:sliding_window}\n\\end{figure}\n\\noindent  If we select the weight function as\n\\bmath\n  \\beta(n,i) =\n  \\begin{cases}\n    1 & n-L < i \\leq n\\\\\n    0 & \\text{otherwise}\n  \\end{cases}\n\\emath\nfor $0 < L \\leq n$, we obtain the sliding window weight function, and it is sketched in Fig.~\\ref{fig:sliding_window}. If we select $L=n$, the sliding window weight function reduces to the growing window weight function. In order to obtain unbiased estimates of $\\vect{R}_u(n)$ and $\\vect{r}_{ud}(n)$ in \\eq{eq:wls_Ru_est} and \\eq{eq:wls_rud_est}, respectively, we have to use\n\\bmath\n  c(n,\\beta) = \\frac{1}{L}\\ .\n\\emath\n\n\\subsubsection{Exponential Weight Function}\n\\begin{figure}[htbp]\n  \\centering\n  \\inputTikZ{figures/exponential_window}\n  \\caption{The exponential weight function.}\n  \\label{fig:exponential_window}\n\\end{figure}\n\\noindent If we select the weight function as\n\\bmath\n  \\beta(n,i) =\n  \\begin{cases}\n    \\lambda^{n-i} & 0 < i \\leq n\\\\\n    0 & \\text{otherwise}\n  \\end{cases}\n\\emath\nfor $0<\\lambda\\leq 1$, we obtain the exponential weight function, and it is sketched in Fig.~\\ref{fig:exponential_window}. The parameter $\\lambda$ is called \\textit{the forgetting factor}. If we select $\\lambda=1$, the exponential weight function reduces to the growing window weight function. In order to obtain unbiased estimates of $\\vect{R}_u(n)$ and $\\vect{r}_{ud}(n)$ in \\eq{eq:wls_Ru_est} and \\eq{eq:wls_rud_est}, respectively, we have to use\n\\bmath\n  c(n,\\beta) = \n  \\begin{cases}\n    \\displaystyle\\frac{1-\\lambda}{1-\\lambda^n} & 0<\\lambda< 1\\\\\n    \\displaystyle\\frac{1}{n} & \\lambda=1\n  \\end{cases}\\ .\n\\emath\n\n\n\\section{The Recursive Least-Squares Algorithm with an Exponential Weight Function}\nIn an online algorithm, we have to solve the weighted normal equations\n\\bmath\n  \\vect{\\Phi}(n)\\vect{w}(n) = \\vect{\\varphi}(n)\n\\emath\nfor $\\vect{w}(n)$ at every time index $n$. However, solving this equation directly as\n\\bmath\n  \\vect{w}(n) = \\vect{\\Phi}^{-1}(n)\\vect{\\varphi}(n)\n\\emath\nyields a high computational complexity of the algorithm for the following two reasons.\n\\begin{enumerate}\n  \\item The matrices $\\vect{A}(n)$ and $\\vect{B}(n)$, and the vector $\\vect{d}(n)$ grows with $n$. Computing $\\vect{\\Phi}(n)$ and $\\vect{\\varphi}(n)$ directly would therefore be infeasible for an online algorithm, unless we use a weight function with a finite duration window.\n  \\item For an $M$-tap FIR filter, it requires in the order of $\\mathcal{O}(M^3)$ operations to solve the normal equations for the filter coefficient vector $\\vect{w}(n)$.\n\\end{enumerate}\nThe recursive least-squares (RLS) algorithm bypasses these two problems. Below, we consider how this is obtained for an exponential weight function, which is the most common weight function.\n\n\\subsubsection{Recursive Computation of $\\vect{\\Phi}(n)$ and $\\vect{\\varphi}(n)$}\nWe may compute the correlation matrix recursively by rewriting it as\n\\begin{align}\n  \\vect{\\Phi}(n) &= \\vect{A}^T(n)\\vect{B}(n)\\vect{A}(n) = \\sum_{i=1}^{n}\\lambda^{n-i}\\vect{u}(i)\\vect{u}^T(i)\\\\\n  &= \\lambda^0 \\vect{u}(n)\\vect{u}^T(n) + \\sum_{i=1}^{n-1}\\lambda^{n-i}\\vect{u}(i)\\vect{u}^T(i) = \\vect{u}(n)\\vect{u}^T(n) + \\lambda\\sum_{i=1}^{n-1}\\lambda^{n-1-i}\\vect{u}(i)\\vect{u}^T(i)\\notag\\\\\n  &= \\vect{u}(n)\\vect{u}^T(n) + \\lambda\\vect{\\Phi}(n-1)\\ .\n  \\label{eq:rls_corr_recurs}\n\\end{align}\nSimilarly, we may compute the cross-correlation vector recursively by rewriting it as\n\\begin{align}\n  \\vect{\\varphi}(n) &= \\vect{A}^T(n)\\vect{B}(n)\\vect{d}(n) = \\sum_{i=1}^{n}\\lambda^{n-i}\\vect{u}(i)d(i)\\\\\n  &= \\lambda^0 \\vect{u}(n)d(n) + \\sum_{i=1}^{n-1}\\lambda^{n-i}\\vect{u}(i)d(i) = \\vect{u}(n)d(n) + \\lambda\\sum_{i=1}^{n-1}\\lambda^{n-1-i}\\vect{u}(i)d(i)\\notag\\\\\n  &= \\vect{u}(n)d(n) + \\lambda\\vect{\\varphi}(n-1)\\ .\n\\end{align}\nThese recursive formulations of the correlation matrix and the cross-correlation vector clearly reduce the computational complexity and are suitable to use in an online algorithm.\n\n\\subsubsection{Inversion of $\\vect{\\Phi}(n)$}\nFor the inversion of the correlation matrix, we use the matrix inversion lemma stated in Sec.~\\ref{sec:woodbury}. Comparing the recursive formulation of the correlation matrix in \\eq{eq:rls_corr_recurs} with the left side of \\eq{eq:woodbury}, we obtain\n\\begin{align}\n  \\vect{X} &= \\lambda\\vect{\\Phi}(n-1)\\\\\n  \\vect{U} &= \\vect{u}(n)\\\\\n  \\vect{V} &= \\vect{u}^T(n)\\\\\n  \\vect{Y} &= 1\\ .\n\\end{align}\nThus, invoking the matrix inversion lemma, we have that\n\\bmath\n  \\vect{\\Phi}^{-1}(n) = \\lambda^{-1}\\vect{\\Phi}^{-1}(n-1)-\\lambda^{-2}\\frac{\\vect{\\Phi}^{-1}(n-1)\\vect{u}(n)\\vect{u}^T(n)\\vect{\\Phi}^{-1}(n-1)}{1+\\lambda^{-1}\\vect{u}^T(n)\\vect{\\Phi}^{-1}(n-1)\\vect{u}(n)}\\ .\n  \\label{eq:rls_inv_phi}\n\\emath\nNote that the computational complexity of the right side of the equation is much lower than that of the left side of the equation when $\\vect{\\Phi}^{-1}(n-1)$ is known. In order to simplify the notation, we define\n\\begin{alignat}{2}\n  \\vect{P}(n) &= \\vect{\\Phi}^{-1}(n)&\\quad&\\text{(inverse correlation matrix)}\\\\\n  \\vect{k}(n) &= \\frac{\\vect{P}(n-1)\\vect{u}(n)}{\\lambda+\\vect{u}^T(n)\\vect{P}(n-1)\\vect{u}(n)}&\\quad&\\text{(gain vector)}\n\\end{alignat}\nwhich leads to that we may write \\eq{eq:rls_inv_phi} as\n\\bmath\n  \\vect{P}(n) = \\lambda^{-1}\\left[\\vect{P}(n-1)-\\vect{k}(n)\\vect{u}^T(n)\\vect{P}(n-1)\\right]\\ .\n\\emath\nBy rearranging the expression for the gain vector, we obtain\n\\begin{align}\n  \\vect{k}(n) &= \\lambda^{-1}\\left[\\vect{P}(n-1)-\\vect{k}(n)\\vect{u}^T(n)\\vect{P}(n-1)\\right] \\vect{u}(n)\\notag\\\\\n  &= \\vect{P}(n)\\vect{u}(n)\\ .\n\\end{align}\n\n\\subsubsection{Recursive computation of $\\vect{w}(n)$}\nWe can now develop the recursive update equation of the filter coefficient vector. We have that\n\\begin{align}\n  \\vect{w}(n) &= \\vect{P}(n)\\vect{\\varphi}(n)\\\\\n  &= \\vect{P}(n)\\left[\\vect{u}(n)d(n) + \\lambda\\vect{\\varphi}(n-1)\\right]=\\lambda\\vect{P}(n)\\vect{P}^{-1}(n-1)\\vect{w}(n-1)+\\vect{k}(n)d(n)\\notag\\\\\n  &= \\left[\\vect{P}(n-1)-\\vect{k}(n)\\vect{u}^T(n)\\vect{P}(n-1)\\right]\\vect{P}^{-1}(n-1)\\vect{w}(n-1)+\\vect{k}(n)d(n)\\notag\\\\\n  &= \\vect{w}(n-1)-\\vect{k}(n)\\vect{u}^T(n)\\vect{w}(n-1)+\\vect{k}(n)d(n)\\notag\\\\\n  &= \\vect{w}(n-1)+\\vect{k}(n)\\xi(n)\n\\end{align}\nwhere we have defined the a priori error as\n\\bmath\n  \\xi(n) = d(n)-\\vect{u}^T(n)\\vect{w}(n-1)\\ .\n\\emath\n\n\\subsubsection{The RLS Algorithm}\nThe RLS algorithm may now be formulated as the following set of equations\n\\begin{align}\n  \\vect{\\pi}(n) &= \\vect{P}(n-1)\\vect{u}(n)\\\\\n  \\vect{k}(n) &= \\frac{\\vect{\\pi}(n)}{\\lambda+\\vect{u}^T(n)\\vect{\\pi}(n)}\\\\\n  \\xi(n) &= d(n)-\\vect{u}^T(n)\\vect{w}(n-1)\\\\\n  \\vect{w}(n) &= \\vect{w}(n-1)+\\vect{k}(n)\\xi(n)\\\\\n  \\vect{P}(n) &= \\lambda^{-1}\\left[\\vect{P}(n-1)-\\vect{k}(n)\\vect{\\pi}^T(n)\\right]\\ .\n\\end{align}\nFor an $M$-tap FIR filter, it requires in the order of $\\mathcal{O}(M^2)$ operations to run one iteration of the RLS algorithm.\n\n\\subsubsection{Initialisation}\nIn order to start the RLS algorithm, we need to select values for the initial inverse correlation matrix $\\vect{P}(0)$, the initial filter coefficient vector $\\vect{w}(0)$, and the input samples $u(n)$ for $n=-M+1,-M+2,\\ldots,1$. Typically, we assume that\n\\begin{align}\n  \\vect{P}(0) &= \\delta^{-1}\\vect{I}\\\\\n  \\vect{w}(0) &= \\vect{0}\\\\\n  u(n) & = 0\\ ,\\quad\\text{for } -M+1<n<1\\ .\n\\end{align}\nThe first assumption implies that we assume that $\\vect{u}(n)$ for $n<1$ is a white random process with covariance matrix $\\delta\\vect{I}$. The value of $\\delta$ should reflect the SNR of the input data with $\\delta$ being small for a high SNR and $\\delta$ being large for a low SNR \\cite[pp.~444--446]{Haykin2001}. This assumption introduces bias into the correlation matrix $\\vect{\\Phi}(n)$. However, this bias decreases to zero for an increasing $n$. An alternative initialisation, which does not introduce bias, is to estimate the correlation matrix and the cross-correlation vector as \\cite[pp.~545--546]{Hayes1996}\n\\begin{align}\n  \\vect{P}(0) &= \\left[\\sum_{i=-M+1}^{0}\\lambda^{-i}\\vect{u}(i)\\vect{u}^T(i)\\right]^{-1}\\\\\n  \\vect{\\varphi}(0) &= \\sum_{i=-M+1}^{0}\\lambda^{-i}\\vect{u}(i)\\vect{d}(i)\n\\end{align}\nprior to starting the RLS algorithm at time $n=1$. The initial value of the filter coefficient vector can be set to $\\vect{w}(0)=\\vect{P}(0)\\vect{\\varphi}(0)$. Note, that this approach requires that we know the input signal from time $n=-2M+2$ and the desired signal from time $n=-M+2$. \n\n\\subsection{Selection of the Forgetting Factor}\nAt time $n$, the memory of the sliding window RLS algorithm is the $L$ newest samples indexed by $n-L+1,\\ldots, n$. For the exponentially weighted RLS algorithm, the memory is controlled by the forgetting factor $\\lambda$. Whereas the interpretation of $L$ is simple, the corresponding interpretation of $\\lambda$ is not that intuitive when we have to investigate the memory of the exponentially weighted RLS algorithm. That is, we would like to interpret the forgetting factor as a sliding window length. We call this window length for the effective window length and denote it by $L_\\textup{eff}$. A simple way of connecting $L_\\textup{eff}$ and $\\lambda$ is by requiring that\n\\bmath\n  \\lim_{n\\to\\infty} \\sum_{i=1}^{n}\\lambda^{n-i} = \\lim_{n\\to\\infty} \\sum_{i=n-L_\\textup{eff}+1}^{n}1\\ .\n\\emath\nThat is, when the RLS algorithm has reached steady-state, the area under the sliding window curve should equal the area under the exponential window curve. This leads to\n  \\bmath\n     \\lim_{n\\to\\infty} \\sum_{i=n-L_\\textup{eff}+1}^{n}1 = L_\\textup{eff}\n  \\emath\n  and\n  \\bmath\n    \\lim_{n\\to\\infty} \\sum_{i=1}^{n}\\lambda^{n-i}=\\lim_{n\\to\\infty} \\sum_{k=0}^{n-1}\\lambda^{k} = \\lim_{n\\to\\infty} \\sum_{k=0}^{n-1}\\lambda^{k} = \\lim_{n\\to\\infty}\\frac{1-\\lambda^n}{1-\\lambda} = \\frac{1}{1-\\lambda}\n  \\emath\n  where the second last equality follows for $\\lambda\\neq 1$ from the geometric series, and the last equality follows if $0<\\lambda<1$. Thus, we have that\n  \\bmath\n    L_\\textup{eff} = \\frac{1}{1-\\lambda}\\ .\n  \\emath\n\n\\subsection{Transient Analysis}\nThe RLS algorithm is stable in the mean and the mean-square if $0<\\lambda\\leq 1$\\ . It may also be shown that the rate of the convergence of the RLS algorithm is typically an order of magnitude faster than the rate of the convergence of the LMS algorithm. Moreover, the rate of the convergence of the RLS algorithm is invariant to the condition number of the correlation matrix $\\vect{R}_u$ of the input signal \\cite[p.~463, ch.~14]{Haykin2001}.\n\n\\subsection{Steady-State Analysis}\nIt can be shown that \\cite[p.~510]{Sayed2003}\n\\begin{alignat}{2}\n  &\\text{EMSE:}&\\quad J_\\textup{ex} &= J_2(\\vect{w}(\\infty))-J_\\textup{min}\\notag\\\\\n  & &\\quad &\\approx J_\\textup{min}\\frac{(1-\\lambda)M}{1+\\lambda-(1-\\lambda)M}\\\\\n  &\\text{Misadjustment:}&\\quad \\mathcal{M} &= \\frac{ J_\\textup{ex}}{J_\\textup{min}} \\approx \\frac{(1-\\lambda)M}{1+\\lambda-(1-\\lambda)M}\\\\\n  &\\text{MSD:} &\\quad E[\\|\\vect{\\Delta}\\vect{w}(\\infty)\\|^2] &\\approx J_\\textup{ex}\\sum_{m=1}^M\\frac{1}{\\lambda_m}\n\\end{alignat}\nwhere $\\lambda_m$ is the $m$'th eigenvalue of the correlation matrix $\\vect{R}_u$ not to be confused with the forgetting factor $\\lambda$. The approximations hold under certain conditions which may be found in \\cite[pp.~508--510]{Sayed2003}.\n\n\\subsection{Computational Cost}\nTable~\\ref{tab:comp_cost_rls} shows the computational cost of the RLS algorithm in terms of the number of multiplications, additions or subtractions, and divisions. From the table, we see that the total number of flops is $5M^2+5M+1$. Thus, the RLS algorithm has a complexity of $\\mathcal{O}(M^2)$. Note, that there exist faster ways of implementing the RLS algorithm \\cite[pp.~247]{Sayed2003}. Some of them even achieve linear complexity \\cite{Slock1991}.\n\\begin{table}[htbp]\n  \\centering\n  \\begin{tabular}{l c c c}\n    \\toprule\n    Term & $\\times$ & $+$ or $-$ & $/$\\\\\n    \\midrule\n    $\\vect{\\pi}(n)=\\vect{P}(n-1)\\vect{u}(n)$ & $M^2$ & $M(M-1)$ &\\\\\n    $\\vect{k}(n) = \\vect{\\pi}(n)/(\\lambda+\\vect{u}^T(n)\\vect{\\pi}(n))$ & $M$ & $M$ & $1$\\\\\n    $\\xi(n)=d(n)-\\vect{u}^T(n)\\vect{w}(n-1)$ & $M$ & $M$ & \\\\\n    $\\vect{w}(n) = \\vect{w}(n-1)+\\vect{k}(n)\\xi(n)$ & $M$ & $M$ & \\\\\n    $\\vect{P}(n) = (\\vect{P}(n-1)-\\vect{k}(n)\\vect{\\pi}^T(n))/\\lambda$ & $M^2$ & $M^2$ & $M^2$ \\\\\n    \\midrule\n    Total & $2M^2+3M$ & $2M^2+2M$ & $M^2+1$\\\\\n    \\bottomrule\n  \\end{tabular}\n  \\caption{Computational cost of the RLS algorithm.}\n  \\label{tab:comp_cost_rls}\n\\end{table}\n", "meta": {"hexsha": "0a32437cf967af13747bc3ed5f5fbd41d8bea8fd", "size": 20348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/lectures/RLS.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/RLS.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/RLS.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": 58.9797101449, "max_line_length": 678, "alphanum_fraction": 0.6594751327, "num_tokens": 7437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6109346795795089}}
{"text": "\\chapter{Poison Processes}\n\\emph{“好想退休哦。”}\n\\newpage\n\n\\section{Poisson Distribution}\n    \\subsection{Poisson Distibution}\n    \\begin{definition}[Poisson Distribution]\n        $X$ has a \\textbf{Poisson distribution} with rate $\\lambda$, denoted by $Poisson(\\lambda)$, if\n        \\[ \\mathbb{P}[X=k] = \\frac{\\lambda^k}{k!}e^{-\\lambda} \\]\n    \\end{definition}\n    \\begin{remark}\n        If we view $\\lambda$ as a constant, then the Poisson distribution can be seen as the limitation of a Binomial distribution $Bermoulli(n, p)$ with $p = \\frac{\\lambda}{n}$, as $n\\to\\infty$.\n    \\end{remark}\n    \\begin{theorem}\n        If $n$ is large, then $Bernoulli(n, \\lambda/n)$ is approximately $Poisson(\\lambda)$.\n    \\end{theorem}\n\n    Suppose we want to compute the number of customers arriving at some restaurant. If we divide the time interval to be sufficiently small s.t. at most one customer arrives at each interval and the probability is uniformly $p$, then the total number of arrivals has a Poisson distribution.\n\n    \\subsection{Expectation and Variance of Poisson Distribution}\n    Let $X$ be a random variable with a Poisson distribution, then\n    \\[ \\mathbb{E}[X] = \\lambda \\]\n    \\[ Var[X] = \\lambda \\]\n\n    \\subsection{Additivity of Poisson Distributions}\n    \\begin{theorem}[Additivity of Poisson Distributions]\n        Let $X_1$, $X_2$ be two independent random variables, $X_1\\sim Poisson(\\lambda_1)$, $X_2\\sim Poisson(\\lambda_2)$, then\n        \\[ X_1 + X_2 \\sim Poisson(\\lambda_1 + \\lambda_2) \\]\n    \\end{theorem}\n    \\begin{proof}\n        \\begin{align*}\n            \\mathbb{P}[X_1=X_2=n] &=\\sum_{m=0}^n \\mathbb{P}[X_1=m, X_2=n-m]\\\\\n            &= \\sum_{m=0}^n\\mathbb{P}[X_1=m]\\cdot\\mathbb{P}[X_2=n-m]\\\\\n            &= \\sum_{m=0}^n\\frac{\\lambda_1^m}{m!}e^{-\\lambda_1}\\cdot\\frac{\\lambda_2^{n-m}}{(n-m)!}e^{-\\lambda_2}\\\\\n            &= \\frac{e^{-(\\lambda_1+\\lambda_2)}}{n!}\\sum_{m=0}^n\\frac{n!}{n!(n-m)!}\\lambda_1^m\\lambda_2^{n-m}\\\\\n            &= \\frac{e^{-(\\lambda_1+\\lambda_2)}}{n!}\\sum_{m=0}^n\\mathrm{C}_m^n \\lambda_1^m \\lambda_2^{n-m}\\\\\n            &= \\frac{(\\lambda_1+\\lambda_2)^n}{n!}e^{-(\\lambda_1+\\lambda_2)}\n        \\end{align*}\n    \\end{proof}\n\n\n\\section{Exponential Distributions}\n\n    \\subsection{Definition of Exponential Distributions}\n    \\begin{definition}[Exponential Distribution]\n        A random variable $X$ is said to have an \\textbf{exponential distribution} with rate $\\lambda$, $X \\sim Exp(\\lambda)$ if\n        \\[ \\forall t \\ge 0 \\quad \\mathbb{P}[X \\le t] = 1 - e^{-\\lambda t} \\]\n    \\end{definition}\n\n    \\subsection{Properties of Exponential Distribution}\n\n        \\subsubsection{Probability Density Function}\n        The exponential distribution $Exp(\\lambda)$ has probability density function\n        \\[ p(x) = \\lambda e^{-\\lambda x} \\]\n\n        \\subsubsection{Expectation}\n        \\[ \\mathbb{E}[X] = \\int_0^{+\\infty} t\\lambda e^{-\\lambda t}\\mathrm{d}t = \\frac{1}{\\lambda} \\]\n\n        \\subsubsection{Variance}\n        \\[ Var[X] = \\mathbb{E}[X^2] - \\mathbb{E}[X] = \\frac{1}{\\lambda^2} \\]\n\n        \\subsubsection{Lack of Memory}\n        \\[ \\mathbb{P}[X>t+s|X>s] = \\mathbb{P}[X \\ge t] \\]\n        \\begin{remark}\n            If we have waited for $s$ units of time, then the probability that we have to wait for $t$ more units is the same as that of we have not waited at all.\\footnote{白~{}等~{}了}\n        \\end{remark}\n\n        \\subsubsection{Exponential Races}\\label{subs:ExponentialRace}\n        Let $X_1 \\sim Exp(\\lambda_1)$, $X_2 \\sim Exp(\\lambda_2)$ be two independent random variables. Let $Y = \\min(X_1, X_2)$, then\n        \\[ Y \\sim Exp(\\lambda_1 + \\lambda_2) \\]\n        \\begin{proof}\n            \\begin{align*}\n                \\mathbb{P}[Y \\ge k] &= \\mathbb{P}[\\min\\{X_1,X_2\\} \\ge k]\\\\\n                &= \\mathbb{P}[X_1 \\ge k, X_2 \\ge k]\\\\\n                &= \\mathbb{P}[X_1 \\ge k]\\cdot \\mathbb{P}[X_2 \\ge k]\\\\\n                &= e^{-(\\lambda_1 + \\lambda_2)k}\n            \\end{align*}\n        \\end{proof}\n\n        If we consider the problem of ``Who finishes first between $X_1$ and $X_2$'', then\n        \\[ \\mathbb{P}[Y=X_1]=\\sum_{s=0}^\\infty \\mathbb{P}[X_1=s,X_2>s] = \\int_0^{+\\infty}p_1(s)\\mathbb{P}[X_2>s]\\mathrm{d}s = \\frac{\\lambda_1}{\\lambda_1 + \\lambda_2} \\]\n        And an exponential race among $n$ random variables is\n        \\[ \\mathbb{P}[Y=X_i] = \\frac{\\lambda_i}{\\sum_j \\lambda_j} \\]\n\n\n\\section{Poisson Processes}\n\n    \\subsection{Definition of Poisson Processes}\n    \\begin{definition}[Poisson Process]\\label{def:PoissonProcess}\n        $\\{N(s)|s \\ge 0\\}$ is a \\textbf{Poisson Process}, if\n        \\begin{enumerate}\n            \\item $N(0)=0$\n            \\item $\\forall t, s \\ge 0 \\quad N(t+s) - N(s) \\sim Poisson(\\lambda t)$\n            \\item $n$ has \\textbf{independent increments}: $\\forall t_0 \\le t_1 \\le \\dots \\le t_n$,\n            \\[ N(t_1)-N(t_0), N(t_2)-N(t_1), \\dots, N(t_n)-N(t_{n-1}) \\]\n            are \\textbf{mutually independent}.\n        \\end{enumerate}\n    \\end{definition}\n\n    \\subsection{Alternative Interpretation of Poisson Process}\n    We can construct a Poisson process as the sum of multiple random variables with Exponential distributions.\n    \\begin{proposition}\\label{prop:AltdefOfPoissonProcess}\n        Let $\\tau_1,\\tau_2,\\dots,\\tau_n$ be independent random variables with exponential distribution $Exp(\\lambda)$. Let $T_n=\\sum_{i=1}^n\\tau_i$, $N(s)=\\max\\{n|T_n \\le s\\}$\n\n        Then $N(s)$ is a Poisson process with rate $\\lambda$.\n    \\end{proposition}\n    \\begin{remark}\n        If we think of $\\tau_i$ as the time interval between the arrival time of customers in a store, then $N(s)$ is the number of customer arrivals before time $s$.\n    \\end{remark}\n\n    To prove Proposition \\ref{prop:AltdefOfPoissonProcess}, we first introduce a theorem.\n\n    \\begin{theorem}\\label{thm:SumOfExpHasGammaDistribution}\n        Let $\\tau_1, \\tau_2, \\dots, \\tau_n$ be independent random variables with Exponential distribution $Exp(\\lambda)$. Let $T_n = \\sum_{i=1}^n\\tau_n$, then $T_n$ has a \\emph{Gamma distribution} $\\Gamma(n, \\lambda)$\n        \\[ f_{T_n}(t) = \\lambda e^{-\\lambda t}\\frac{(\\lambda t)^{n-1}}{(n-1)!} \\quad \\forall t \\ge 0 \\]\n    \\end{theorem}\n    \\begin{proof}\n        Prove by induction on $n$.\n        \\begin{itemize}\n            \\item \\textbf{Base. } $n=1$. $f_{T_1}(t) = \\lambda e^{-\\lambda t}$ obviouly holds.\n            \\item \\textbf{Hypothesis. } Suppose it holds for $n$.\n            \\item \\textbf{Step. }\n            \\begin{align*}\n                f_{T_{n+1}}(t) &= \\int_0^t f_{T_n}(s)\\cdot\\lambda e^{-\\lambda(t-s)}\\mathrm{d}s\\\\\n                &= \\int_0^t \\lambda e^{-\\lambda s}\\frac{(\\lambda s)^{n-1}}{(n-1)!}\\lambda e^{-\\lambda(t-s)}\\mathrm{d}s \\quad \\text{(Plug in the hypothesis)}\\\\\n                &= \\frac{\\lambda^{n+1}}{(n-1)!}e^{-\\lambda t}\\int_0^t s^{n-1}\\mathrm{d}s \\quad \\text{(Move the constants out)}\\\\\n                &= \\frac{\\lambda^{n+1}}{n!}e^{-\\lambda t}t^n\n            \\end{align*}\n            which is exactly $\\Gamma(n+1, \\lambda(n+1))$, so we are done.\n        \\end{itemize}\n    \\end{proof}\n    \\begin{remark}\n        Theorem \\ref{thm:SumOfExpHasGammaDistribution} states that the arrival time of the $n$-th customer has a Gamma distribution.\n    \\end{remark}\n\n    We can now prove Proposition \\ref{prop:AltdefOfPoissonProcess}.\n    \\subsection{Proof of Equivalence of the two definitions}\n        \\begin{proof}\n            To show that the two definitions are equivalent, we need to show that the three requirements in definition \\ref{def:PoissonProcess} can be satisfied by the alternative definition \\ref{prop:AltdefOfPoissonProcess}.\n            \\begin{enumerate}\n                \\item $N(0)=0$ is trivial.\n                \\item We begin proving (2) of definition \\ref{def:PoissonProcess} from the case $s=0$. Notice that $N(t)=n \\Leftrightarrow T_n \\le t \\wedge T_{n+1} > t$, i.e. the $n$-th customer has arrived, but the $(n+1)$-th has not. So we only need to prove the latter has Poisson distribution.\n                \\begin{align*}\n                    \\mathbb{P}[N(t)=n] &= \\mathbb{P}[T_n \\le t, T_{n+1} > t]\\\\\n                    &= \\int_0^t\\mathbb{P}[T_n = s]\\cdot\\mathbb{P}[\\tau_{n+1} > t-s]\\mathrm{d}s \\quad \\text{(Enumerate all possible values of $t$)}\\\\\n                    &= \\int_0^t\\lambda e^{-\\lambda s}\\frac{(\\lambda s)^{n-1}}{(n-1)!}\\cdot e^{-\\lambda(t-s)}\\mathrm{d}s \\quad \\text{(Theorem \\ref{thm:SumOfExpHasGammaDistribution})}\\\\\n                    &= \\frac{\\lambda^n}{(n-1)!}e^{-\\lambda t}\\int_0^t s^{n-1}\\mathrm{d}s \\quad \\text{(Move out the constants)}\\\\\n                    &= \\frac{(t\\lambda)^n}{n!}\\cdot e^{-\\lambda t}\n                \\end{align*}\n                which is exactly the expression of $Poisson(\\lambda t)$, so we are done.\n\n                When $s > 0$, by the lack of memory property, $N(t+s)-N(s)$ must have the same distribution as $N(t) - N(0) = N(t)$. Of course this can also be verified by some moderate calculations.\n                \\item (3) of definitiion \\ref{def:PoissonProcess} can be proved using a similar argument. Notice that the lack-of-memory property and (2) implies that the ``number of arrivals'' after $s$ is independent of the arrivals before $s$. Therefore $N(t_n) - N(t_{n-1})$ is independent of $N(r)$ for all $r < t_{n-1}$. So the result can be proved by induction.\n            \\end{enumerate}\n        \\end{proof}\n\n\n\\section{Thinning}\n    Thinning is associating another random variable with a Poisson Process.\n\n    \\subsection{Thinning}\n        We can associate some i.i.d. random variables $Y_i$ with each arrival. For example, $Y_i$ can be the gender of the $i$-th customer arriving at some restaurant; or if customers arrive in cars, $Y_i$ can be the number of passengers in a car. Let $P_j = \\mathbb{P}[Y_i = j]$. Let $N_j(t)$ be the total number of $i \\le N(t)$ with $Y_i = j$.\n\n        \\begin{theorem}\\label{thm:ThinningOfPoissonProcess}\n            $N_j(t)$ are \\emph{independent} Poisson Processes with rate $\\lambda P_j$.\n        \\end{theorem}\n        \\begin{proof}\n            We will prove the result using the first definition of Poisson Distribution \\ref{def:PoissonProcess}. We only need to consider the simplest cases where $Y_i \\in \\{0,1\\}$.\n            \\begin{align*}\n                \\mathbb{P}[N_0(t) = j, N_1(t) = k] &= e^{-\\lambda t}\\frac{(\\lambda t)^{j+k}}{(j+k)!}\\cdot C^{j+k}_j P_0^j P_1^k \\\\\n                &= e^{-\\lambda t}\\frac{(\\lambda t)^{j+k}}{(j+k)!}\\frac{(j+k)!}{j! \\cdot k!}P_0^j P_1^k\\\\\n                &= e^{-P_0\\lambda t}\\frac{(P_0\\lambda t)^j}{j!} \\cdot e^{-P_1\\lambda t} \\frac{(P_1 \\lambda t)^k}{k!}\n            \\end{align*}\n            This is exactly the product of two Poisson Processes, with rate $P_0\\lambda$ and $P_1\\lambda$ respectively. Therefore we have completed our proof.\n        \\end{proof}\n        \\begin{remark}\n            One tricky fact behind this theorem is that, suppose we are interested in the gender of customers arriving at a restaurant. Assume that the probability that the customer is male or female are equal. If one day 40 males came to the restaurant, this does not give any implication to the number of females coming to the restaurant because they are independent.\n        \\end{remark}\n\n    \\subsection{Examples}\n        \\subsubsection{Finding typos in a book.} Two editors read a 300-page manuscript. Editor $A$ finds $100$ typos, Editor $B$ finds $120$ typos, and $80$ of these typos are the same. Suppose $A$ and $B$ have probability $P_A$ and $P_B$ of discovering a typo, and suppose the typos in the book is a rate $\\lambda$ Poisson Process. How can we estimate $\\lambda$, $P_A$ and $P_B$?\n    \n        We can associate a random variable with each typos appearing in the manuscript.\n        \\begin{enumerate}\n            \\item Neither $A$ or $B$ found it. $(1-P_A)(1-P_B)$\n            \\item Only $A$ found it. $P_A(1-P_B)$\n            \\item Only $B$ found it. $P_B(1-P_A)$\n            \\item Both $A$ and $B$ found it. $P_AP_B$\n        \\end{enumerate}\n        From Theorem \\ref{thm:ThinningOfPoissonProcess}, we know that the four cases follow four independent Poisson Processes. So we can estimate the parameters by solving\n        \\[\n        \\begin{cases}\n            300P_A(1-P_B)\\lambda &= 20\\\\\n            300P_B(1-P_B)\\lambda &= 40\\\\\n            \\lambda P_AP_B &= 80\n        \\end{cases}\n        \\quad \\Longrightarrow \\quad\n        \\begin{cases}\n            P_A &= 2/3\\\\\n            P_B &= 4/5\\\\\n            \\lambda &= 1/2\n        \\end{cases}\n        \\]\n    \n        \\subsubsection{Coupon Collector Once Again.}\n        We revisit the Coupon Collector's problem, but this time we assume the probability of the $j$-th coupon is $P_j$.\n        \\begin{itemize}\n            \\item Let $N_j$ be the number of gachas before we first get a coupon of the $j$-th category.\n            \\item Let $N = \\max_{1 \\le j \\le n}\\{N_j\\}$ is the total number of gachas we need to collect all categories of coupons.\n        \\end{itemize}\n        We want to find $\\mathbb{E}[N]$.\n\n        We re-formulate the problem into the following: suppose we owns a restaurant, and the customers coming to the restaurant is a Poisson Process of rate $\\lambda = 1$. Each customer brings a coupon, let $Y_j$ be the category of the coupon brought by the $j$-th customer. Therefore $N_j(t)$ is a Poisson Process with rate $P_j$. Let $X_j$ be the random variable \\emph{in this Poisson Process setting} denoting the first time to meet a customer with a category $j$ coupon, and we now alternatively consider $X = \\max \\{X_j\\}$.\n\n        We are interested in $\\mathbb{P}[X \\le t]$, i.e. the probability that we have got all categories of coupons before time $t$.\n        \\begin{align*}\n            \\mathbb{P}[X \\le t] &= \\mathbb{P}[X_1 \\le t, X_2 \\le t, \\dots X_n \\le t]\\\\\n            &= \\mathbb{P}[X_1 \\le t] \\cdot \\mathbb{P}[X_2 \\le t] \\cdot \\cdots \\cdot \\mathbb{P}[X_n \\le t]\n        \\end{align*}\n        By the alternative definition of Poisson Process \\ref{prop:AltdefOfPoissonProcess}, $X_j$ has an Exponential Distribution with rate $P_j$. Therefore\n        \\[ \\mathbb{P}[X \\le t] = \\prod_{i=1}^n (1-e^{-P_jt}) \\]\n        \\[ \\mathbb{P}[X > t] = 1 - \\prod_{i=1}^n (1-e^{-P_jt}) \\]\n        \\begin{proposition}\\label{prop:AltComputationOfExpectation}\n            If $X \\ge 0$, then\n            \\[ \\mathbb{E}[X] = \\sum_{t=0}^{\\infty} \\mathbb{P}[X \\ge t] = \\sum_{i=0}^{\\infty}i\\cdot\\mathbb{P}[X=i] \\]\n            \\[ \\mathbb{E}[X] = \\int_0^{\\infty} \\mathbb{P}[X > t]\\mathrm{d}t\\]\n        \\end{proposition}\n        By Proposition \\ref{prop:AltComputationOfExpectation},\n        \\[ \\mathbb{E}[X] = \\int_0^{\\infty} \\mathbb{P}[X > t]\\mathrm{d}t = \\int_0^{\\infty}1 - \\prod_i (1-e^{-P_it})\\mathrm{d}t \\]\n        We have figured out $\\mathbb{E}[X]$, but how is $\\mathbb{E}[X]$ related to $\\mathbb{E}[N]$?\n\n        Notice that $X$ denotes the exact time at which the customer carrying the $N$-th coupon arrives. If $\\tau_i$ denotes the time interval between the arrival of the $(i-1)$-th and the $i$-th customers, then\n        \\[ X = \\sum_{i=1}^N \\tau_i \\]\n        Take expectation on both sides\n        \\[ \\mathbb{E}[X] = \\mathbb{E}\\left[ \\sum_{i=1}^N \\tau_i \\right] = \\mathbb{E}[N]\\cdot\\mathbb{E}[\\tau_1] = \\mathbb{E}[N] \\]\n        Notice that $N$ is a random variable, but we somehow still exchanged the summation and expectation in the second equation, this holds because of Wald's Equation, which will be covered in the future. For now, notice that once $N$ is determined, $\\mathbb{E}[X|N]$ is determined.\n        \\[ \\mathbb{E}[X|N] = N\\mathbb{E}[\\tau_1] = N \\]\n        Take expectations on both sides again\n        \\[ \\mathbb{E}[\\mathbb{E}[X|N]] = \\mathbb{E}[X] = \\mathbb{E}[N] \\]\n        \\begin{remark}\n            The original Coupon Collector's problem is a special case where $P_j$ are uniform. It can be proved\\footnote{“我也不会积，但是我用Mathematica跑了一下他们确实相等” -- Chihao} that the integral equals to the sum of harmonic series.\\footnote{“这个积分我会积” -- Kuan}\\footnote{“不愧是常州数学帝” -- Chihao}\n        \\end{remark}\n\n    \\subsection{Nonhomogeneous Thinning}\n        Now consider another case. Suppose $P_i$ now depends on the arrival time $s$.\n        \\begin{theorem}[Nonhomogeneous Thinning]\n            \\label{thm:NonhomogeneousThinning}\n            Let $Y_1,\\dots,Y_k$ be random variables, and let $p_1,\\dots,p_k$ be nonnegative functions of time $s$ such that for all $s$, $\\sum_{j=1}^k p_j(s)=1$. Assume $\\mathbb{P}[Y_i=j]=p_j(s)$ at $s$. Then $N_i(t)$'s have \\emph{independent} Poisson distribution with mean $\\lambda\\int_0^t P_i(s)\\mathrm{d}s$.\n        \\end{theorem}\n        \\begin{proof}\n            Suppose there are $k$ categories. Suppose until time $t$, each type $i$ have total number $n_i$.\n            \\begin{align*}\n                &\\mathbb{P}[N_1(t)=n_1,\\dots,N_k(t)=n_k]\\\\\n                &=\\mathbb{P}\\left[ N_1(t)=n_1,\\dots,N_k(t)=n_k|N(t)=\\sum_i n_i \\right]\\mathbb{P}\\left[ N(t) = \\sum_i n_i \\right] \\quad \\text{Always holds}\\\\\n                &= \\frac{\\left(\\sum_{i=1}^kn_i\\right)!}{n_1!\\cdots n_k!}p_1^{n_1}\\cdots p_k^{n_k} \\cdot e^{-\\lambda t}\\frac{(\\lambda t)^{\\sum_in_i}}{(\\sum_i n_i)!}\\\\\n                &= \\prod_{i=1}^k e^{-\\lambda t P_i} \\frac{(\\lambda t P_i)^{n_i}}{n_i!}\n            \\end{align*}\n            where\n            \\[ P_i = \\frac{1}{t}\\int_0^t P_i(s)\\mathrm{d}s \\]\n        \\end{proof}\n        \\begin{remark}\n            Actually it is a non-homogeneous Poisson Process with rate\n            \\[ \\lambda(t) = \\lambda\\cdot P_i(t) \\]\n        \\end{remark}\n\n        \\begin{definition}[Nonhomogeneous Poisson Process]\\label{def:NonhomogeneousPoissonProcess}\n            $\\{ N(t) | t \\ge 0 \\}$ is a \\textbf{nonhomogeneous Poisson Process} with rate $\\lambda(s)$ if\n            \\begin{enumerate}\n                \\item $N(0)=0$\n                \\item $N(t)$ has independent increments.\n                \\item $N(t)-N(s)$ has distribution $Poisson\\left(\\int_s^t \\lambda(\\tau)\\mathrm{d}\\tau\\right)$\n            \\end{enumerate}\n        \\end{definition}\n        \\begin{remark}\n            In this case, the time intervals are not exponential distributions, and they are not independent.\n        \\end{remark}\n\n    \\subsection{Applications of Nonhomogeneous Thinning}\n\n        \\subsubsection{M/$G$/$\\infty$ Queue}\n        Consider a queue at some counters in a bank. M stands for a Poisson Process representing the incoming flow of customers. $G$ is a distribution of the time to serve the customers, $G(t) = \\mathbb{P}[ServiceTime \\le t]$. $\\infty$ is the number of counters. Let\n        \\begin{itemize}\n            \\item $X(t)$: the number of customers completed services before time $t$.\n            \\item $Y(t)$: the number of customers being served at time $t$.\n        \\end{itemize}\n\n        Consider the customers arriving before $t$, there are two types\n        \\begin{itemize}\n            \\item Those who have completed their services before $t$. The number is $X(t)$.\n            \\item Those who are being served at $t$. The number is $Y(t)$.\n        \\end{itemize}\n\n        Notice that\n        \\[ p_1(s) = G(t-s) \\quad p_2(s) = 1 - G(t-s) = \\bar{G}(t-s) \\]\n        Therefore\n        \\[ \\mathbb{E}[X(t)] = \\mathbb{E}[N_1(t)] = \\lambda\\int_0^t G(t-s)\\mathrm{d}s = \\lambda\\int_0^t G(s)\\mathrm{d}s \\]\n        \\[ \\mathbb{E}[Y(t)] = \\mathbb{E}[N_2(t)] = \\lambda\\int_0^t \\bar{G}(s)\\mathrm{d}s \\]\n\n        \\subsubsection{Cars in a Tunnel}\n        Consider a tunnel\\footnote{“刚才Kuan提醒我隧道内不能超车” -- Chihao} of length $l$. Suppose we are driving a car, once the car enters the tunnel, its speed cannot change. Assume other NPC cars enter the tunnel with a Poisson distribution of rate $\\lambda$. Suppse the speeds of NPC cars have a distribution $G$, and are also fixed once an NPC car enters the tunnel.\n\n        We want to choose an initial speed $x$ to minimize the time we 超车 or 被超车。\n\n        Let $t_0 = l/x$. If we enter the tunnel at time $s$, then we must exit the tunnel at time $s + t_0$. For an NPC car with speed $X$, the time interval that the NPC car stays in the tunnel is $T=l/X$. Let $F$ be the distribution of $T$.\n\n        \\[ F(t) = \\mathbb{P}[T < t] = \\mathbb{P}[l/X < t] = \\mathbb{P}[X > l/t] = \\bar{G}[l/t] \\]\n\n        Let $t$ denote the time when an NPC car enters the tunnel. We divide NPC cars into $3$ categories:\n        \\begin{enumerate}\n            \\item 超车。$t > s$ and $t + T < s + t_0$\n            \\item 被超车。$t < s$ and $t + T > s + t_0$\n            \\item No thing happens. Omitted.\n        \\end{enumerate}\n        At any given time $t$, let $p$ be the probability of overtaking or being overtaken, we have\n        \\[\n            p(t) =\n            \\begin{cases}\n                \\mathbb{P}[t + T > s + t_0] = \\bar{F}(s+t_0-t) \\quad &(t < s)\\\\\n                \\mathbb{P}[t + T < s + t_0] = \\bar{F}(s+t_0-t) \\quad &(s < t < s+t_0)\\\\\n                0 \\quad &(t > s + t_0)\n            \\end{cases}\n        \\]\n        Notice that only $T$ in the above equation is a random variable.\n        \\begin{align*}\n            \\mathbb{E}[N_{encountered}(s+t_0)] &= \\lambda \\left( \\int_0^s \\bar{F}(s-t_0-t)\\mathrm{d}t + \\int_s^{s+t_0} F(s+t_0-t)\\mathrm{d}t \\right)\\\\\n            &= \\lambda \\left( \\int_{t_0}^{s+t_0} \\bar{F}(t)\\mathrm{d}t + \\int_0^{t_0} F(t)\\mathrm{d}t \\right)\n        \\end{align*}\n        To maximize the expectation, we take the derivative w.r.t. $t_0$.\n        \\[ \\frac{\\mathrm{d}}{\\mathrm{d}t_0} = \\lambda \\left( \\bar{F}(s+t_0) - \\bar{F}(t_0) + F(t_0) \\right) = 0 \\]\n        If the system has been running for a long time, i.e. $s$ is sufficiently large, $\\bar{F}(s+t_0) \\approx 0$, so\n        \\[ F(t_0) = \\bar{F}(t_0) = \\frac{1}{2} \\]\n        and\n        \\[ G\\left(\\frac{l}{t_0}\\right) = \\frac{1}{2} \\]\n        So we choose an initial speed $x$ such that\n        \\[ G(x) = \\frac{1}{2} \\]\n\n        \\subsubsection{HIV Patients}\n        We want to estimate the number of HIV patients, suppose a patient may or may not show symptoms. Assume the number of patients with HIV virus has a Poisson distribution with an unknown rate $\\lambda$. Suppose we know a distribution $G$ representing ``how long a patient with HIV virus shows symptoms''.\n\n        We divide people into 2 types by whether they show symptoms or not. Suppose the patient is infected at time $s$ and we observe if they have shown symptoms at time $t$.\n        \\begin{equation}\\label{eq:NumOfPatientsWithSymptoms} \\mathbb{E}[N_1(t)] = \\lambda \\int_0^t G(t-s)\\mathrm{d}s = \\lambda\\int_0^t G(s)\\mathrm{d}s \\end{equation}\n        \\[ \\mathbb{E}[N_2(t)] = \\lambda \\int_0^t \\hat{G}(t-s)\\mathrm{d}s = \\lambda\\int_0^t \\hat{G}(s)\\mathrm{d}s \\]\n        where $\\lambda$ is unknown.\n\n        However, we do know the number of patients who have already shown symptoms. Therefore we can estimate $\\lambda$ with Eq (\\ref{eq:NumOfPatientsWithSymptoms}), and estimate $\\mathbb{E}[N_2(t)]$ with $\\hat{\\lambda}$.\n\n\\section{Conditioning}\n\n    \\subsection{Conditioning}\n        Let $T_1, T_2, \\dots, T_n$ be the arrival times of a Poisson Process with rate $\\lambda$. Let $U_1, U_2, \\dots, U_n$ be independent uniform random variables on $[0,t]$. Let $V_1, V_2, \\dots, V_n$ be sequence $U_i$ re-arranged in increasing order, then\n        \\begin{theorem}[Conditioning]\\label{thm:ConditioningOfPoissonProcess}\n            If we condition on $N(t)=n$, then the distribution of $T_1, \\dots, T_n$ is the same as the distribution of $V_1, \\dots, V_n$.\n        \\end{theorem}\n        \\begin{sketchproof}~{}\n            \\begin{itemize}\n                \\item The joint distribution of $T_1,\\dots,T_n$ given $N(t)=n$ is $n!/t^n$ (by brutal force calculation).\n                \\item The resulting distribution is uniform over $[0,t]$ because the space has volume $t^n$ and $n!$ possible orderings.\n            \\end{itemize}\n        \\end{sketchproof}\n        \\begin{remark}\n            This property is useful when computing $\\mathbb{P}[N(s)=m|N(t)=n]$\n            \\[ \\mathbb{P}[N(s)=m|N(t)=n] = C^n_m \\left(\\frac{s}{t}\\right)^m\\left(1-\\frac{s}{t}\\right)^{n-m} \\]\n        \\end{remark}\n\n\n\\section{Poisson Approximation}\n    \\subsection{Motivating Example: Max Load}\\label{subs:m-balls-in-n-bins}\n        Consider a m-ball-into-n-bin problem. Suppose we throw balls randomly into several bins, and we want to know how many balls there are in the bin with the most balls.\n\n        If we consider the number of balls in each bin, the number follows a Bernoulli distribution. However, since the number of balls in different bins are not independent, analyzing the problem in this way can be complicated.\n\n        Alternatively, we can analyze the problem by constructing a Poisson Process.\n\n        \\begin{itemize}\n            \\item Let $X_i$ be the number of balls in the $i$-th bin.\n            \\item $X_i \\sim Bernoulli(m, \\frac{1}{n})$.\n            \\item $\\sum_i X_i = m$.\n            \\item We are interested in $X = \\max X_i$.\n        \\end{itemize}\n\n    \\subsection{Poisson Approximation}\n        \\begin{theorem}[Poisson Approximation]\\label{thm:PoissonApproximation}\n            Let $(X_1,\\dots,X_n)$ be a sequence of random variables where each $X_i$ has a Bernoulli distribution, then its distribution is the same as $(Y_1, \\dots, Y_n)$ conditioned on $\\sum_i Y_i = m$, where $Y_i \\sim Poisson(\\lambda)$ are \\emph{independent} Poisson variables with rate $\\lambda$.\n        \\end{theorem}\n        \\begin{proof}\n            Let $a_1, \\dots, a_n \\ge 0$ be $n$ positive integers s.t. $\\sum_i a_i = m$. We calculate $\\mathbb{P}[X_1 = a_1, \\dots, X_n = a_n]$ and $\\mathbb{P}[Y_1 = a_1, \\dots, Y_n = a_n|\\sum_i Y_i=m]$ to show that they are equal to each other.\n\n            Consider throwing $m$ balls into these $n$ bins. There are $n^m$ different kind of throws and $m!$ different permutations of different balls. However, the order of balls in the same bin does not matter, so we shoud divide $m!$ by $a_1!\\cdot \\cdots \\cdot a_n!$.\n            \\begin{align*}\n                \\mathbb{P}[X_1 = a_1, \\dots, X_n = a_n]\n                &= \\frac{1}{n^m} \\cdot \\frac{m!}{a_1! \\dots a_n!}\n            \\end{align*}\n\n            \\begin{align*}\n                \\mathbb{P}[Y_1 = a_1, \\dots, Y_n = a_n | \\sum_iY_i = m]\n                &= \\frac{\\mathbb{P}[Y_1=a_1,\\dots,Y_n=a_n]}{\\mathbb{P}[\\sum_i Y_i = m]}\\\\\n                &= \\frac{\\prod_{i=1}^n \\mathbb{P}[Y_i = a_i]}{\\mathbb{P}[\\sum_i Y_i = m]} \\quad \\text{(Independence of $Y_i$)}\\\\\n                &= \\frac{\\prod_{i=1}^n e^{-\\lambda}\\frac{\\lambda^{a_i}}{a_i!}}{e^{-\\lambda n} \\cdot \\frac{(\\lambda n)^m}{m!}} \\quad \\text{(Denominator is a sum of Poisson)}\\\\\n                &= \\frac{1}{n^m} \\cdot \\frac{m!}{a_1! \\dots a_n!} \\quad \\text{(Mafs)}\n            \\end{align*}\n\n        \\end{proof}\n\n    \\subsection{m-balls-in-n-bins: MaxLoad Revisited}\n        With Theorem \\ref{thm:PoissonApproximation}, we can solve the motivating example in Section \\ref{subs:m-balls-in-n-bins}.\n        \\begin{theorem}\n            Let $m=n$. Let $X = \\max_i X_i$. Then there exist constants $c_1$, $c_2$ such that\n            \\[ \\mathbb{P}\\left[\\frac{c_1\\log n}{\\log\\log n} < X < \\frac{c_2\\log n}{\\log\\log n}\\right] = 1 - O\\left(\\frac{1}{n}\\right) \\]\n        \\end{theorem}\n        \\begin{proof}\n            We first proof the \\emph{upper bound}. Proving the upper bound is equivalent to proving\n            \\[\\mathbb{P}\\left[ X \\ge \\frac{c_2\\log n}{\\log\\log n} \\right] = O\\left(\\frac{1}{n}\\right) \\]\n            \\begin{align*}\n                \\mathbb{P}\\left[ X \\ge \\frac{c_2\\log n}{\\log\\log n} \\right] &= \\mathbb{P}[\\exists i: X_i \\ge k]\\\\\n                &\\le n\\mathbb{P}[X_1 \\ge k] \\quad \\text{(Union Bound)}\\\\\n                &\\le n C^k_n\\left(\\frac{1}{n}\\right)^k\\\\\n                &\\le n\\cdot \\left(\\frac{en}{k}\\right)^k n^{-k} \\quad \\text{(Mafs)}\\\\\n                &= n\\cdot\\left(\\frac{e}{k}\\right)^k\n            \\end{align*}\n            Therefore it is sufficient to show that $n\\cdot e^k / k^k < 1/n^{1+\\epsilon}$ for some $\\epsilon > 0$. Take logarithm on both sides,\n            \\[ (2+\\epsilon)\\log n + k - k\\log k < 0 \\]\n            Hence $k\\log k > 3\\log n$ suffices. Plug in $k = \\frac{c_2\\log n}{\\log\\log n}$.\n            \\begin{align*}\n                k\\log k &= \\frac{c_2\\log n}{\\log\\log n} (\\log\\log n - \\log\\log\\log n + \\log c_2)\\\\\n                &> c_2\\log n\\left(1- \\frac{\\log\\log\\log n}{\\log\\log n}\\right)\\\\\n                &> \\frac{c_2}{2}\\log n\n            \\end{align*}\n            So we can choose $c_2 = 6$.\n            \n            The proof of \\emph{lower bound} requires Theorem \\ref{thm:BadEventBound}. Let $X < \\frac{c_1\\log n}{\\log\\log n}$ be a ``bad event''. This is equivalent to\n            \\[ \\forall i, \\quad X_i < \\frac{c_1\\log n}{\\log\\log n} \\]\n            Denote this bad event by $\\mathcal{B}$, let $f = \\mathbb{I}[\\mathcal{B}|X_1,\\dots,X_n]$ be an indicator of the bad event. By Theorem \\ref{thm:BadEventBound},\n            \\begin{align*}\n                \\mathbb{E}[f] &= \\mathbb{P}[\\mathcal{B}]\\\\\n                &\\le e\\sqrt{n} \\mathbb{E}[\\mathbb{I}[\\mathcal{B}|(Y_1,\\dots,Y_n)]]\\\\\n                &= e\\sqrt{n} \\mathbb{P}[\\forall i \\quad Y_i < \\frac{c_1\\log n}{\\log\\log n}] \\quad \\text{(Independence of $Y_i$)}\\\\\n                &= e\\sqrt{n}\\prod_{i=1}^n \\mathbb{P}[Y_i < RHS]\\\\\n                &= e\\sqrt{n}(1-\\mathbb{P}[Y_i \\ge RHS])^n\\\\\n                &\\le e\\sqrt{n}(1-\\mathbb{P}[Y_i = RHS])^n\\\\\n                &= e\\sqrt{n}\\left(1-\\frac{1}{ek!}\\right)^n\\\\\n                &\\le e\\sqrt{n} e^{-\\frac{n}{ek!}} < \\frac{1}{n} \\quad \\text{(Mafs)}\n            \\end{align*}\n        \\end{proof}\n        \\begin{theorem}\\label{thm:BadEventBound}\n            Let $X_i$ be Bernoulli random variables, and let $Y_i$ be independent Poisson random variables with rate $\\lambda = m/n$. For any function $f$ from $\\mathbb{N}^n$ to $\\mathbb{N}$,\n            \\[ \\mathbb{E}[f(X_1, \\dots, X_n)] \\le e\\sqrt{m}\\cdot\\mathbb{E}[f(Y_1,\\dots,Y_m)] \\]\n        \\end{theorem}\n        \\begin{proof}\n            \\begin{align*}\n                \\mathbb{E}[f(Y_1,\\dots,Y_n)] &= \\sum_{k=0}^{\\infty}\\mathbb{E}[f(Y_1,\\dots,Y_n) | \\sum_i Y_i = k] \\cdot \\mathbb{P}[\\sum_i Y_i = k] \\quad \\text{(Total Probability)}\\\\\n                &\\ge \\mathbb{E}[f(Y_1,\\dots,Y_n)|\\sum Y_i = m]\\cdot \\mathbb{P}[\\sum Y_i = m]\\\\\n                &= \\mathbb{E}[f(X_1,\\dots,X_m)]\\cdot\\mathbb{P}[\\sum Y_i = m] \\quad \\text{(thm \\ref{thm:PoissonApproximation})}\n            \\end{align*}\n            If we let each $Y_i$ has a Poisson distribution of rate $m/n$, by additivity of Poisson variables we have $\\sum Y_i \\sim Poisson(m)$, and then\n            \\begin{align*}\n                \\mathbb{E}[f(Y_1,\\dots,Y_n)] &= \\mathbb{E}[f(X_1,\\dots,X_n)]\\cdot e^{-m}\\frac{m^m}{m!}\\\\\n                &\\ge \\mathbb{E}[f(X_1,\\dots,X_n)]\\cdot\\frac{1}{e\\sqrt{m}}\n            \\end{align*}\n        \\end{proof}\n        \\begin{remark}~{}\n            \\begin{itemize}\n                \\item $f$ is usually chosen to be some indicator function $\\mathbb{I}$ of some ``bad event''. (In order to show that the probability that this ``bad event'' happens is very small.)\n                \\item Choosing $\\lambda = m/n$ is to maximize $\\mathbb{P}[\\sum_i Y_i=m]$.\n            \\end{itemize}\n        \\end{remark}\n", "meta": {"hexsha": "2495c58a5f8a33606ec0b031d0c6933ae5e5b2b8", "size": 30990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Stochastic Processes/PoisonProcess.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/PoisonProcess.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/PoisonProcess.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": 66.5021459227, "max_line_length": 529, "alphanum_fraction": 0.5963536625, "num_tokens": 10165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6109346775443014}}
{"text": "\\newpage\n\\subsection{Goal}\\label{subsec:goal}\n\nThe use of stochastic and metaheuristic algorithms (Simulated Annealing, Differential Evolution, Particle Swarm Optimization) in the tasks of unconstrained nonlinear optimization and the experimental comparison of them with Nelder-Mead and Levenberg-Marquardt algorithms.\n\n\\subsection{Formulation of the problem}\\label{subsec:formulation-of-the-problem}\n\nGenerate the noisy data $(x_k, y_k)$, where $k = 0, \\dots, 1000$, according to the rule:\n\n\\begin{equation*}\ny = \\begin{cases}\n-100 + \\delta_k, & f(x_k) < -100, \\\\\nf(x_k) + \\delta_k & -100 \\leq f(x_k) \\leq 100, \\\\\n100 + \\delta_k & f(x_k) > 100,\n\\end{cases}\n\\end{equation*}\n\n\\begin{equation*}\n    x_k = \\frac{3k}{1000},\n\\end{equation*}\n\n\\begin{equation*}\n    f(x) = \\frac{1}{x^2 - 3x + 2},\n\\end{equation*}\n\nwhere $\\delta_x \\approx N(0, 1)$ are values of a random variable with standard normal distribution.\nApproximate the data by the rational function\n\n\\begin{equation*}\n    F(x, a, b, c, d) = \\frac{ax + b}{x^2 + cx + d},\n\\end{equation*}\n\nby means of least squares through the numerical minimization of the following function:\n\n\\begin{equation*}\n    D(a, b, c, d) = \\sum^{1000}_{k=0}(F(x_k, a, b, c, d) - y_k)^2.\n\\end{equation*}\n\nTo solve the minimization problem, use Nelder-Mead algorithm, Levenberg-Marquardt algorithm and at least two of the methods among Simulated Annealing, Differential Evolution and Particle Swarm Optimization.\nIf necessary, set the initial approximations and other parameters of the methods.\nUse $\\varepsilon = 0.001$ as the precision;\nat most 1000 iterations are allowed.\nVisualize the data and the approximants obtained in a single plot.\nAnalyze and compare the results obtained (in terms of number of iterations, precision, number of function evaluations, etc.).\n\n\\subsection{Brief theoretical part}\\label{subsec:brief-theoretical-part}\n\nOptimization methods are numerical methods for finding optimal (in some sense) values of objective functions, for example, in the framework of mathematical models of certain processes.\n\n\\textit{Stochastic algorithms} are a broad class of algorithms that rely on repeated random sampling to solve an optimization problem.\nThese methods are useful when it is impossible or difficult to apply others.\n\n\\textit{Metaheuristic algorithms} are algorithms inspired by natural phenomena that solve the optimization problem by trial and error.\nMetaheuristic methods do not guarantee that a solution to the optimization problem will be found.\n\n\\paragraph{Nelder-Mead.}\n\nIf the function $f(x)$ is a ravine function, the efficiency of the simplex method in solving problem:\n\\begin{equation*}\n    \\min_{x \\in R^n} f(x) = f(x*) = f*\n\\end{equation*}\nis significantly reduced due to the fact that the regular simplex cannot be \"extended\" along the ravine.\nThe Nelder-Mead method (the deformable polyhedron method) is a development of the simplex method and uses the deformation of the current simplex (not necessarily regular) in the search process.\nThe method uses the following operations on simplexes:\n\n\\begin{itemize}\n    \\item reflection;\n    \\item reduction;\n    \\item compression;\n    \\item stretching.\n\\end{itemize}\n\n\\paragraph{Levenberg-Marquardt algorithm}\n\nThe \\textit{Levenberg-Marquardt algorithm} (\\textit{LMA}) is a popular trust region algorithm that is used to find a minimum of a function (either linear or nonlinear) over a space of parameters.\nEssentially, a trusted region of the objective function is internally modeled with some function such as a quadratic.\nWhen an adequate fit is found, the trust region is expanded.\nAs with many numerical techniques, the Levenberg-Marquardt method can be sensitive to the initial starting parameters.\n\n\\paragraph{Simulated annealing}\n\\textit{Simulated annealing} is a random-search technique which exploits an analogy between the way in  which a metal cools and freezes into a minimum energy crystalline structure (the annealing process) and  the search for a minimum in a more general system;\nit forms the basis of an optimisation technique for combinatorial and other problems.\n\n\\paragraph{Differential evolution}\n\\textit{Differential evolution} is one of the most influential optimization algorithms up-to-date.\nDifferential evolution works through analogous computational steps as used by a standard evolutionary algorithm.\n\n\\subsection{Results}\\label{subsec:results}\n\nIn the case of a \\textit{rational approximation}, significant nonlinearities occur, so the result depends on the initial approximations (Figure~\\ref{ris:plot}).\n\n\\begin{figure}[H]\n    \\center\n    \\includegraphics[width=\\textwidth]{img/plot.png}\n    \\caption{Stochastic and metaheuristic algorithms.}\n    \\label{ris:plot}\n\\end{figure}\n\nFrom the table below (Table,~\\ref{tbl:stohmeta}) it is evident that methods \\textit{Nelder-Mead} and \\textit{Levenberg-Marquardt} require an order of magnitude less number of computations.\nHowever, despite the fact that metaheuristic methods do not guarantee finding the result, they allow you to get a solution of fairly good quality in an acceptable time without knowing the search space.\n\nNote that both metaheuristic methods produced extremely similar results for different numbers of iterations.\n\n\\begin{table}[ht]\n\\caption{Stochastic and metaheuristic algorithms}\n\\begin{tabular}{l|l|c|c|}\n\\cline{2-4}\n                                                         & \\textbf{method}                 & \\multicolumn{1}{l|}{\\textbf{iterations}} & \\multicolumn{1}{l|}{\\textbf{function eval}} \\\\ \\hline\n\\multicolumn{1}{|l|}{\\multirow{4}{*}{\\textbf{rational}}} & \\textit{Nelder-Mead}            & 480                                      & 795                                         \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & \\textit{Levenberg-Marquardt}    & nan                                      & 3                                           \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & \\textit{Simulated Annealing}    & 1000                                     & 9111                                        \\\\ \\cline{2-4}\n\\multicolumn{1}{|l|}{}                                   & \\textit{Differential Evolution} & 149                                      & 9105                                        \\\\ \\hline\n\\end{tabular}\n\\label{tbl:stohmeta}\n\\end{table}\n\n\\paragraph{Levenberg-Marquardt algorithm gives poor results}\n\n\\begin{theorem}\n    \\label{theorem:conv_newton}\n    For doubly continuously differentiable functions (i.e.\\ for $f \\in C^2(D)$) with a non-degenerate matrix $\\nabla^2 f(y^*)$, there exists a $\\varepsilon$-neighborhood of the stationary point $y^*$ of the function $f(y)$ such that for any initial point $y^0$ from this neighborhood, the Newton method will converge superlinearly, and if the Lipschitz condition is met in this neighborhood for Hesse matrices, it will converge quadratically.\n\\end{theorem}\n\nSince the Levenberg-Marquardt algorithm is a hybrid of gradient descent and the Newton method, it therefore has the disadvantages of the Newton method.\nBased on the theorem above [1], we can conclude that if the Hesse matrix is not degenerate, but not sign-positive, then the Newton method can converge to a stationary point that is not a minimum point, but a maximum point or a saddle point.\nAccordingly, a more careful choice of initial approximations is necessary.\n\n\\subsection{Conclusion}\\label{subsec:conclusion}\n\nIn the course of the laboratory work, stochastic and metaheuristic algorithms were implemented and analyzed within the problem of the unconstrained optimization problem.\nThis paper also provides a comparative analysis of stochastic and metaheuristic algorithms.\n\n\\subsection{References}\\label{subsec:references}\n\\begin{enumerate}[label={[\\arabic*]}]\n    \\item С.Ю. Городецкий, Лабораторный практикум по методам локальной оптимизации в программной системе LocOpt, 2007.\n\\end{enumerate}\n\n\\subsection{Appendix}\\label{subsec:appendix}\n\nThe source code is located \\href{https://github.com/vanSultan/anal_dev_algo/tree/lab_04}{here}: \\url{https://github.com/vanSultan/anal_dev_algo/tree/lab_04}.\n", "meta": {"hexsha": "969b254a9bf96e6af179673e619ff4012f34bf58", "size": 8120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab_04/report/lab_04_body.tex", "max_stars_repo_name": "vanSultan/anal_dev_algo", "max_stars_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab_04/report/lab_04_body.tex", "max_issues_repo_name": "vanSultan/anal_dev_algo", "max_issues_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab_04/report/lab_04_body.tex", "max_forks_repo_name": "vanSultan/anal_dev_algo", "max_forks_repo_head_hexsha": "e9d6382103080e6f885b1456cc0a3ce64fbe1863", "max_forks_repo_licenses": ["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.5886524823, "max_line_length": 442, "alphanum_fraction": 0.7235221675, "num_tokens": 2006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6109346706203386}}
{"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 XII Notes}\n\\date{July 2, 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{The Multivariable Chain Rule $-$ 14.5}\n\nIn three dimensions, the formula for the chain rule looks as follows:\n\n$$\\frac{dz}{dt}=\\frac{\\partial f}{\\partial x}\\frac{dx}{dt} + \\frac{\\partial f}{\\partial y}\\frac{dy}{dt}$$\n\nConditions $z=f(x,y); x=x(t), y=y(t)$\\\\\n\n\\textit{Example:}\n\n$$z=x^2y+3xy^4; x=\\sin2t,y=\\cos t$$\n$$\\frac{dz}{dt}=(2xy+3y^4)(2\\cos2t)+(x^2+12xy^3)(-\\sin t)$$\n\nAnother case looks as follows:\n\nIf $z=f(x,y); x=g(s,t), y=h(s,t)$, then:\n\n$$\\frac{\\partial z}{\\partial s}=\\frac{\\partial z}{\\partial x}\\frac{\\partial x}{\\partial s} + \\frac{\\partial z}{\\partial y}\\frac{\\partial y}{\\partial s}$$\n\n$$\\frac{\\partial z}{\\partial t}=\\frac{\\partial z}{\\partial x}\\frac{\\partial x}{\\partial t} + \\frac{\\partial z}{\\partial y}\\frac{\\partial y}{\\partial t}$$\n\nThe general case of the chain rule, where $u$ is a multivariable function of $n$ variables $x_1$, $x_2$,\\dots $x_n$, and each $x$ is a function of $m$ variables $t_1$,\\dots$t_m$, then:\n\n$$\\frac{\\partial u}{\\partial t_i}=\\frac{\\partial u}{\\partial x_1}\\frac{\\partial x_1}{\\partial t_i}+\\frac{\\partial u}{\\partial x_2}\\frac{\\partial x_2}{\\partial t_i}+\\dots+\\frac{\\partial u}{\\partial x_n}\\frac{\\partial x_n}{\\partial t_i}$$\n\n\\subsection{Implicit Differentiation}\n\nIf $\\frac{\\partial f}{\\partial y}\\neq 0$:\n\n$$\\frac{dy}{dx}=-\\frac{\\frac{\\partial f}{\\partial x}}{\\frac{\\partial f}{\\partial y}}$$\n\nIn addition to this:\n\n$$\\frac{\\partial z}{\\partial x}=-\\frac{\\frac{\\partial f}{\\partial x}}{\\frac{\\partial f}{\\partial z}}$$\n\nand\n\n$$\\frac{\\partial z}{\\partial y}=-\\frac{\\frac{\\partial f}{\\partial y}}{\\frac{\\partial f}{\\partial z}}$$\n\n\\section{The Directional Derivative $-$ 14.6}\n\nThe definition of a directional derivative is:\n\n$$ D_{\\hat{u}}=\\lim_{h\\to0} \\frac{f(x_o+ha, y_o + hb)-f(x_o,y_o)}{h} $$\n\nIn more simplified terms:\n\n$$D_{\\hat{u}}=\\frac{\\partial f}{\\partial x} a + \\frac{\\partial f}{\\partial y} b$$\n\n\\subsection{The Gradient Vector}\n\nThe gradient vector is written $\\overrightarrow{\\nabla} f$, and:\n\n$$\\overrightarrow{\\nabla} f = \\frac{\\partial f}{\\partial x}\\hat{\\bold{i}} + \\frac{\\partial f}{\\partial y}\\hat{\\bold{j}}$$\n\nIn the case that $u = f(x,y,z)$:\n\n$$\\overrightarrow{\\nabla} f = \\frac{\\partial f}{\\partial x}\\hat{\\bold{i}} + \\frac{\\partial f}{\\partial y}\\hat{\\bold{j}}+\\frac{\\partial f}{\\partial z}\\hat{\\bold{k}}$$\n\nand\n\n$$D_{\\hat{u}}=\\overrightarrow{\\nabla}f(x,y,z)\\cdot\\hat{u}$$\n\nThe greatest value of the gradient, written as $|\\overrightarrow{\\nabla}f|$, occurs in the same direction for $\\hat{\\bold{u}}$ and $\\overrightarrow{\\nabla}f$\n\n\\end{document}\n", "meta": {"hexsha": "23dd87ab83c283cbce39d6e490bc14e59c0c1dcf", "size": 3969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture12.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/Lecture12.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/Lecture12.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.8016528926, "max_line_length": 236, "alphanum_fraction": 0.6069538927, "num_tokens": 1288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.610934665244836}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amssymb}\n\n\\def\\vec#1{\\mathchoice{\\mbox{\\boldmath$\\displaystyle#1$}}\n\t{\\mbox{\\boldmath$\\textstyle#1$}}\n\t{\\mbox{\\boldmath$\\scriptstyle#1$}}\n\t{\\mbox{\\boldmath$\\scriptscriptstyle#1$}}}\n\\newcommand{\\floor}[1]{\\left\\lfloor #1\\right\\rfloor}\n\\newcommand{\\ceil}[1]{\\left\\lceil #1\\right\\rceil}\n\\newcommand{\\F}{\\mathbb{F}}\n\\newcommand{\\N}{\\mathbb{N}}\n\n\\newcommand{\\Input}{\\textbf{Input:}}\n\\newcommand{\\Output}{\\textbf{Output:}}\n\n\\newcommand{\\field}{\\normalfont\\texttt{gf256}}\n\\newcommand{\\transforms}{\\normalfont\\texttt{transforms}}\n\\newcommand{\\hermite}{\\normalfont\\texttt{hermite}}\n\\newcommand{\\encode}{\\normalfont\\texttt{encode}}\n\n\\newcommand{\\XtoN}{LCHToNewton}\n\\newcommand{\\NtoX}{NewtonToLCH}\n\\newcommand{\\XtoL}{LCHEval}\n\\newcommand{\\LtoX}{LCHInterp}\n\\newcommand{\\lsXtoL}{LowSpaceLCHEval}\n\\newcommand{\\lsLtoX}{LowSpaceLCHInterp}\n\\newcommand{\\XtoM}{LCHToMonomial}\n\\newcommand{\\MtoX}{MonomialToLCH}\n\\newcommand{\\Taylor}{TaylorExpansion}\n\\newcommand{\\InverseTaylor}{InverseTaylorExpansion}\n\n\\makeatletter\n\\newcommand*{\\bdiv}{%\n\t\\nonscript\\mskip-\\medmuskip\\mkern5mu%\n\t\\mathbin{\\operator@font div}\\penalty900\\mkern5mu%\n\t\\nonscript\\mskip-\\medmuskip\n}\n\\makeatother\n\n\\let\\originalleft\\left\n\\let\\originalright\\right\n\\renewcommand{\\left}{\\mathopen{}\\mathclose\\bgroup\\originalleft}\n\\renewcommand{\\right}{\\aftergroup\\egroup\\originalright}\n\n\\newenvironment{inputs}{\\Input\\par\\begin{tabular}{@{}rcl}}{\\end{tabular}}\n\\newenvironment{outputs}{\\Output\\par}{}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1ex plus 0.5ex minus 0ex}\n\n\\begin{document}\n\t\n\\title{\\lowercase{ftoc2}: Fast transforms over characteristic 2}\n\\maketitle\n\n\\section{\\field{}: Implementation of arithmetic in $\\F_{2^8}$}\n\nThe module \\field{} implements field arithmetic for $\\F_{2^8}$. We let\n$\\F_{2^8}=\\F_2(\\alpha)$ for a root $\\alpha$ of $x^8+x^4+x^3+x^2+1$, and\n$\\{\\beta_0,\\dotsc,\\beta_7\\}$ be the basis of the extension obtained by letting\n$\\beta_7=\\alpha^5$ and $\\beta_i=\\beta^2_{i+1}-\\beta_{i+1}$ for\n$i\\in\\{0,\\dotsc,6\\}$. This construction yields a so-called Cantor basis (see\n\\cite[Appendix~A]{gao2010}). Define maps $[{}\\cdot{}]_k:\\N\\rightarrow\\{0,1\\}$\nfor $k\\in\\N$ by\n\\begin{equation*}\n\ti=\\sum_{k\\in\\N}2^k[i]_k\n\t\\quad\\text{for $i\\in\\N$}.\n\\end{equation*}\nThe field $\\F_{2^8}$ is enumerated as $\\{\\omega_0,\\dotsc,\\omega_{255}\\}$, with\n\\begin{equation*}\n\t\\omega_i=\\sum^7_{k=0}[i]_k\\beta_k\n\t\\quad\\text{for $i\\in\\{0,\\dotsc,255\\}$}.\n\\end{equation*}\nThen $\\F_{2^d}=\\{\\omega_0,\\dotsc,\\omega_{2^d-1}\\}$ for $d\\in\\{1,2,4,8\\}$.\n\nAn element $\\omega_i\\in\\F_{2^8}$ is represented by the byte\n$[i]_7[i]_6\\dotsb[i]_0$. Thus, addition of field elements corresponds to\ncomputing the XOR of bytes. Logarithm and exponent tables are used for\nmultiplication. The array $\\texttt{LOG}$ contains logarithms base $\\alpha$:\n$\\texttt{LOG}[i]$ is the byte that corresponds to $\\log_\\alpha\\omega_i$ for\n$i\\in\\{1,\\dotsc,255\\}$, and $\\texttt{LOG}[0]$ is arbitrarily set to zero.\nSimilarly, $\\texttt{EXP}[i]$ corresponds to $\\alpha^i$ for\n$i\\in\\{0,\\dotsc,254\\}$. \n\n\\subsection{Functions}\\\n\n\\texttt{unsigned char mul(unsigned char x, unsigned char y)}\n\n\\begin{inputs}\n\t\\texttt{x} & - & field element, \\\\\n\t\\texttt{y} & - & field element.\n\\end{inputs}\n\n\\begin{outputs}\n\tThe product of the two elements $x,y\\in\\F_{2^8}$ that correspond to the inputs.\n\\end{outputs}\n\n\\section{\\transforms{}: Transforms over $\\F_{2^8}$}\n\nThe module \\transforms{} implements several of the fast transforms proposed\nin~\\cite{gao2010,lin2014,lin2016a,coxon2018b}. Define polynomials\n\\begin{equation*}\n\tN_i\n\t=\n\t\\prod^{i-1}_{j=0}\n\t\\left(x-\\omega_j\\right)\n\t\\quad\\text{and}\\quad\n\tX_i\n\t=\n\t\\prod^7_{k=0}\n\t\\prod^{2^k[i]_k-1}_{j=0}\n\t\\left(x-\\omega_j\\right)\n\\end{equation*}\nfor $i\\in\\{0,\\dotsc,255\\}$. The polynomials $N_i$ are the Newton polynomials\nassociated with the enumeration $\\{\\omega_0,\\dotsc,\\omega_{255}\\}$ of\n$\\F_{2^8}$. The polynomials $X_i$ were introduced by Lin, Chung and Han\n\\cite{lin2014}, and referred to hereafter as the LCH basis polynomials.\n\n\\subsection{Functions}\\\n\n\\texttt{unsigned int log2(unsigned int n)}\n\nCeiling of base two logarithm.\n\n\\begin{inputs}\n\t\\texttt{n} & - & an integer.\n\\end{inputs}\n\n\\begin{outputs}\n\tThe ceiling of $\\log_2 n$.\n\\end{outputs}\n\n\\texttt{void \\NtoX(int l, unsigned char[:]\\ a)}\n\nNewton basis to LCH basis conversion.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat\n\t\\begin{equation}\\label{eqn:newton-lch}\n\t\t\\sum^{\\ell-1}_{i=0}f_iN_i\n\t\t=\\sum^{\\ell-1}_{i=0}h_iX_i.\n\t\\end{equation}\n\\end{outputs}\n\n\\texttt{void \\XtoN(int l, unsigned char[:]\\ a)}\n\nLCH basis to Newton basis conversion.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat \\eqref{eqn:newton-lch} holds.\n\\end{outputs}\n\n\\texttt{void \\LtoX(unsigned char shift, int c, int l, unsigned char[:]\\ a)}\n\nInterpolation on the LCH basis.\n\n\\begin{inputs}\n\t\\texttt{shift} & - & shift parameter,                \\\\\n\t\\texttt{c} & - & number of evaluations provided, \\\\\n\t\\texttt{l} & - & length of the polynomial,       \\\\\n\t\\texttt{a} & - & coefficient array of length $2^{\\ceil{\\log_2\\ell}}$.\n\\end{inputs}\n\n\\begin{outputs}\n\tGiven $\\texttt{shift}=\\lambda\\in\\F_{2^8}$, $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for\n\t$i\\in\\{0,\\dotsc,c-1\\}$, and $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for\n\t$i\\in\\{c,\\dotsc,\\ell-1\\}$, the function terminates with\n\t$\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t\\begin{equation}\\label{eqn:lagrange-lch}\n\t\t\\sum^{\\ell-1}_{i=0}\n\t\th_i\n\t\tX_i\\left(\\omega_j+\\lambda\\right)\n\t\t=\n\t\tf_j\n\t\t\\quad\n\t\t\\text{for $j\\in\\{0,\\dotsc,c-1\\}$}.\n\t\\end{equation}\n\\end{outputs} \n\n\\texttt{void \\XtoL(unsigned char shift, int c, int l, unsigned char[:]\\ a)}\n\nEvaluation on the LCH basis.\n\n\\begin{inputs}\n\t\\texttt{shift} & - & shift parameter,                  \\\\\n\t\\texttt{c} & - & number of evaluations to compute, \\\\\n\t\\texttt{l} & - & length of the polynomial,         \\\\\n\t\\texttt{a} & - & coefficient array of length\n\t$\\max(\\ell,2^{\\ceil{\\log_2c}})$.\n\\end{inputs}\n\n\\begin{outputs}\n\tGiven $\\texttt{shift}=\\lambda\\in\\F_{2^8}$ and $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for\n\t$i\\in\\{0,\\dotsc,\\ell-1\\}$, the function terminates with\n\t$\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t\\eqref{eqn:lagrange-lch} holds.\n\\end{outputs}\n\n\\texttt{void \\lsXtoL(unsigned char shift, int c, int l, unsigned char[:]~a)}\n\nIn-place evaluation on the LCH basis.\n\n\\begin{inputs}\n\t\\texttt{shift} & - & shift parameter,                  \\\\\n\t\\texttt{c}     & - & number of evaluations to compute, \\\\\n\t\\texttt{l}     & - & length of the polynomial,         \\\\\n\t\\texttt{a}     & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tGiven $\\texttt{shift}=\\lambda\\in\\F_{2^8}$, $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for\n\t$i\\in\\{0,\\dotsc,\\ell-1\\}$, and $\\texttt{a}[i]\\in\\F_{2^8}$ for\n\t$i\\in\\{c,\\dotsc,\\ell-1\\}$ (i.e, their value does not matter), the function terminates with\n\t$\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t\\eqref{eqn:lagrange-lch} holds, while $\\texttt{a}[c],\\dotsc,\\texttt{a}[\\ell-1]$\n\tretain their initial values if $c<\\ell$.\n\\end{outputs}\n\n\\texttt{void \\lsLtoX(unsigned char shift, int c, int l, unsigned char[:]~a)}\n\nIn-place interpolation on the LCH basis.\n\n\\begin{inputs}\n\t\\texttt{shift} & - & shift parameter,                \\\\\n\t\\texttt{c}     & - & number of evaluations provided, \\\\\n\t\\texttt{l}     & - & length of the polynomial,       \\\\\n\t\\texttt{a}     & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tGiven $\\texttt{shift}=\\lambda\\in\\F_{2^8}$, $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for\n\t$i\\in\\{0,\\dotsc,c-1\\}$, and $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for\n\t$i\\in\\{c,\\dotsc,\\ell-1\\}$, the function terminates with\n\t$\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t\\eqref{eqn:lagrange-lch} holds, while $\\texttt{a}[c],\\dotsc,\\texttt{a}[\\ell-1]$ \n\tretain their initial values.\n\\end{outputs} \n\n\\texttt{void \\Taylor(int t, int l, unsigned char[:]\\ a)}\n\nGeneralised Taylor expansion at $x^{2^t}-x$.\n\n\\begin{inputs}\n\t\\texttt{t} & - & exponent,                 \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat\n\t\\begin{equation}\\label{eqn:taylor}\n\t\t\\sum^{\\ell-1}_{i=0}f_ix^i\n\t\t=\n\t\t\\sum^{\\ell-1}_{i=0}\n\t\th_i\n\t\tx^{i-2^t\\floor{i/2^t}}\n\t\t\\left(x^{2^t}-x\\right)^{\\floor{i/2^t}}.\n\t\\end{equation}\n\\end{outputs}\n\n\\texttt{void InverseTaylorExpansion(int t, int l, unsigned char[:]\\ a)}\n\nInverse generalised Taylor expansion at $x^{2^t}-x$.\n\n\\begin{inputs}\n\t\\texttt{t} & - & exponent,                 \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat \\eqref{eqn:taylor} holds.\n\\end{outputs}\n\n\\texttt{void \\MtoX(int l, unsigned char[:]\\ a)}\n\nMonomial basis to LCH basis conversion.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat $\\sum^{\\ell-1}_{i=0}f_ix^i=\\sum^{\\ell-1}_{i=0}h_iX_i$.\n\\end{outputs}\n\n\\texttt{void \\XtoM(int l, unsigned char[:]\\ a)}\n\nLCH basis to monomial basis conversion.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat $\\sum^{\\ell-1}_{i=0}h_iX_i=\\sum^{\\ell-1}_{i=0}f_ix^i$.\n\\end{outputs}\n\n\\texttt{void TaylorExpansionHighCoeffs(int t, int c, int l, unsigned char[:]\\\n\ta)}\n\nHigh coefficients of the generalised Taylor expansion at $x^{2^t}-x$.\n\n\\begin{inputs}\n\t\\texttt{t} & - & exponent,                 \\\\\n\t\\texttt{c} & - & cut-off,                  \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for ${i\\in\\{c,\\dotsc,\\ell-1\\}}$,\n\tthen on termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{c,\\dotsc,\\ell-1\\}$\n\tsuch that\n\t\\begin{equation}\\label{eqn:taylor}\n\t\t\\sum^{\\ell-1}_{i=c}f_ix^i\n\t\t=\n\t\t\\sum^{\\ell-1}_{i=0}\n\t\th_i\n\t\tx^{i-2^t\\floor{i/2^t}}\n\t\t\\left(x^{2^t}-x\\right)^{\\floor{i/2^t}},\n\t\\end{equation}\n\tfor some $h_0,\\dots,h_{c-1}\\in\\F_{2^8}$, while\n\t$\\texttt{a}[0],\\dotsc,\\texttt{a}[c-1]$ retain their initial values.\n\\end{outputs}\n\n\\texttt{void \\MtoX HighCoeffs(int c, int l, unsigned char[:]\\ a)}\n\nMonomial basis to LCH basis conversion.\n\n\\begin{inputs}\n\t\\texttt{c} & - & cut-off,                  \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for ${i\\in\\{c,\\dotsc,\\ell-1\\}}$,\n\tthen on termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{c,\\dotsc,\\ell-1\\}$\n\tsuch that\n\t$\\sum^{\\ell-1}_{i=c}f_ix^i=\\sum^{\\ell-1}_{i=0}h_iX_i$ for some\n\t$h_0,\\dots,h_{c-1}\\in\\F_{2^8}$, while $\\texttt{a}[0],\\dotsc,\\texttt{a}[c-1]$\n\tretain their initial values.\n\\end{outputs}\n\n\\section{\\hermite{}: Hermite interpolation and evaluation over $\\F_{2^8}$}\n\nThe module \\hermite{} is an implementation of the Hermite interpolation and\nevaluation algorithms proposed in \\cite{coxon2018}, specialised to $\\F_{2^8}$\nand its subfields. These algorithms reduce instances of the Hermite problems to\ninstances of regular (i.e., without the presence of derivatives) interpolation\nand evaluation problems. We implement these reduction, and use the \\transforms{}\nmodule to solve the problems they admit. The algorithms used in the module are\nmore general than their counterparts in~\\cite{coxon2018}, since they include an\nadditional parameter $\\ell$ that accounts for polynomial length.\n\nFor $i\\in\\N$, let $D^i:\\F_{2^8}[x]\\rightarrow\\F_{2^8}[x]$ be the map that sends\n$f\\in\\F_{2^8}[x]$ to the coefficient of $y^i$ in $f(x+y)\\in\\F_{2^8}[x][y]$,\ncalled the $i$th Hasse derivative on $\\F_{2^8}[x]$.\n\n\\subsection{Functions}\\\n\n\\texttt{void Evaluate(int c, int l, unsigned char[:]\\ a)}\n\nAlgorithm 1.\n\n\\begin{inputs}\n\t\\texttt{c} & - & number of evaluations to compute, \\\\\n\t\\texttt{l} & - & length of the polynomial,         \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f(\\omega_i)\\in\\F_{2^8}$ for\n\t$f=\\sum^{\\ell-1}_{i=0}f_ix^i$ and $i\\in\\{0,\\dotsc,c-1\\}$.\n\\end{outputs}\n\n\\texttt{void Interpolate(int c, int l, unsigned char[:]\\ a)}\n\nAlgorithm 3.\n\n\\begin{inputs}\n\t\\texttt{c} & - & number of evaluations provided, \\\\\n\t\\texttt{l} & - & length of the polynomial,       \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$, and\n\t$\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{c,\\dotsc,\\ell-1\\}$, then on\n\ttermination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t$f=\\sum^{\\ell-1}_{i=0}f_ix^i$ satisfies $f(\\omega_i)=h_i$ for\n\t$i\\in\\{0,\\dotsc,c-1\\}$.\n\\end{outputs}\n\n\\texttt{void PrepareLeft(int d, int n, int c, int l, unsigned char[:]\\ a)}\n\nThe function \\textsf{PrepareLeft} from Algorithm 2.\n\n\\texttt{void PrepareRight(int d, int n, int c, int l, unsigned char[:]\\ a)}\n\nThe function \\textsf{PrepareRight} from Algorithm 4.\n\n\\texttt{void HermiteEvaluate(int d, int n, int c, int l, unsigned char[:]\\ a)}\n\nAlgorithm 2.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,                     \\\\\n\t\\texttt{c} & - & number of evaluations to compute, \\\\\n\t\\texttt{l} & - & length of the polynomial,         \\\\\n\t\\texttt{a} & - & coefficient array of length\n\t$2^{\\lceil\\log_2\\lceil\\ell/2^d\\rceil\\rceil+d}$.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination\n\t$\\texttt{a}[i]=(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})\\in\\F_{2^8}$ for\n\t$f=\\sum^{\\ell-1}_{i=0}f_ix^i$ and $i\\in\\{0,\\dotsc,c-1\\}$.\n\\end{outputs}\n\n\\texttt{void HermiteInterpolate(int d, int n, int c, int l, unsigned char[:]\\\n\ta)}\n\nAlgorithm 4.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,                   \\\\\n\t\\texttt{c} & - & number of evaluations provided, \\\\\n\t\\texttt{l} & - & length of the polynomial,       \\\\\n\t\\texttt{a} & - & coefficient array of length\n\t$2^{\\lceil\\log_2\\lceil\\ell/2^d\\rceil\\rceil+d}$.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$, and\n\t$\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{c,\\dotsc,\\ell-1\\}$, then on\n\ttermination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,c-1\\}$ such that\n\t$f=\\sum^{\\ell-1}_{i=0}f_ix^i$ satisfies\n\t$(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})=h_i$ for $i\\in\\{0,\\dotsc,c-1\\}$.\n\\end{outputs}\n\n\\section{\\encode{}: Systematic encoding of multiplicity codes over $\\F_{2^8}$}\n\nThe module \\encode{} is an implementation of the systematic encoding algorithm\nfor multiplicity codes proposed in \\cite{coxon2017}, specialised to codes over\n$\\F_{2^8}$ and its subfields. To encode, the algorithm solves a multivariate\nHermite interpolation problem, followed by a multivariate Hermite evaluation\nproblem. Both these problems are solved by algorithms that reduce the\nmultivariate problems to instances of the univariate problems. The module\n\\hermite{} is used to solve the univariate problems. The reduction also relies\non the use of a multivariate Newton-like basis. The module \\transforms{} is used to\nperform conversions between this basis and the monomial basis.\n\nThe ring of polynomials over $\\F_q$ in indeterminates $x_1,\\dotsc,x_m$ is\ndenoted by $\\F_q[\\vec{x}]=\\F_q[x_1,\\dotsc,x_m]$. Define\n$\\vec{x}^{\\vec{i}}=x^{i_1}_1\\dotsm x^{i_m}_m$ for\n$\\vec{i}=(i_1,\\dotsc,i_m)\\in\\N^m$. For $\\vec{i}\\in\\N^m$, let\n$D^{\\vec{i}}:\\F_q[\\vec{x}]\\rightarrow\\F_q[\\vec{x}]$ be the map that sends\n$f\\in\\F_q[\\vec{x}]$ to the coefficient of $\\vec{y}^{\\vec{i}}$ in\n$f(\\vec{x}+\\vec{y})\\in\\F_q[\\vec{x}][\\vec{y}]$, called the $\\vec{i}$th Hasse\nderivative on $\\F_q[\\vec{x}]$. Let $\\F_q[\\vec{x}]_\\ell$ denote the space of\npolynomials in $\\F_q[\\vec{x}]$ of total degree less than $\\ell$. The weight of a\nvector $\\vec{i}\\in\\N^m$, denoted $\\left|\\vec{i}\\right|$, is defined to be the\nsum of its entries. Define\n$S_{m,s}=\\{\\vec{s}\\in\\N^m\\mid\\left|\\vec{s}\\right|<s\\}$ for positive $s\\in\\N$.\nThen for $q$ a prime power and positive $m,\\ell,s\\in\\N$ such that $\\ell\\leq sq$,\nthe corresponding multiplicity code is\n\\begin{equation*}\n\t\\mathrm{Mult}(q,m,\\ell,s)\n\t=\n\t\\left\\{\n\t\t\\left(\n\t\t\t\\left(\n\t\t\t\t(D^{\\vec{s}}f)(\\vec{\\omega})\n\t\t\t\\right)_{\\vec{s}\\in S_{m,s}}\n\t\t\\right)_{\\vec{\\omega}\\in\\F^m_q}\n\t\t\\mid\n\t\tf\\in\\F_q[\\vec{x}]_\\ell\n\t\\right\\}.\n\\end{equation*}\n\nThis module is limited to multiplicity codes with $q=2^d$ for some\n$d\\in\\{1,2,4,8\\}$. Consequently, $q$ is assumed to be of this form hereafter. We\nindex the elements of $\\F^m_q$ by vectors in $\\{0,\\dotsc,q-1\\}^m$ by defining\n$\\vec{\\omega}_{\\vec{i}}=(\\omega_{i_1},\\dotsc,\\omega_{i_m})$ for\n$\\vec{i}=(i_1,\\dotsc,i_m)\\in\\{0,\\dotsc,q-1\\}^m$. The class \\texttt{Codeword},\nwhich subclasses NumPy's ndarray, is used to store codewords (i.e., elements) of\na multiplicity code. In particular, a codeword is represented by a\none-dimensional ndarray of length $(qs)^m$. This is roughly $m!$ times the\nlength of the code, so much memory is wasted. If an array represents the\ncodeword corresponding to $f\\in\\F_q[\\vec{x}]$, then the index of\n$(D^{\\vec{s}}f)(\\vec{\\omega}_{\\vec{i}})$ in the array is\n$\\sum^m_{k=1}\\left(i_k+s_kq\\right)(sq)^{k-1}$, where $\\vec{s}=(s_1,\\dotsc,s_m)$\nand $\\vec{i}=(i_1,\\dotsc,i_m)$. If in addition $\\sum^m_{k=1}i_k+s_kq<\\ell$, the\nentry is part of the message of the codeword.\n\nFor $\\vec{s}=(s_1,\\dotsc,s_m)\\in\\N^m$ and\n$\\vec{i}=(i_1,\\dotsc,i_m)\\in\\{0,\\dotsc,q-1\\}^m$, define\n\\begin{equation*}\n\tN_{\\vec{i}+\\vec{s}q}\n\t=N_{i_1}(x_1)\\dotsm N_{i_m}(x_m)\n\t\\left(x^q_1-x_1\\right)^{s_1}\\dotsm\\left(x^q_m-x_m\\right)^{s_m}.\n\\end{equation*}\nThe multivariate Newton basis of $\\F_q[\\vec{x}]$ defined in~\\cite{coxon2017} is then equal to the set of all such polynomials.\n\n\n\\subsection{Functions}\\\n\n\\texttt{void MonomialInterpolate(int d, int l, unsigned char[:]\\ a)}\n\nUnivariate interpolation with respect to the monomial basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,              \\\\\n\t\\texttt{l} & - & length of the polynomial,  \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$ such\n\tthat $f=\\sum^{\\ell-1}_{i=0}f_ix^i$ satisfies\n\t$(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})=h_i$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$.\n\\end{outputs}\n\n\\texttt{void MonomialEvaluate(int d, int l, int s, unsigned char[:]\\ a)}\n\nUnivariate evaluation with respect to the monomial basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,              \\\\\n\t\\texttt{l} & - & length of the polynomial,  \\\\\n\t\\texttt{s} & - & bound on derivative order, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination\n\t$\\texttt{a}[i]=(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})\\in\\F_{2^8}$ for\n\t$f=\\sum^{\\ell-1}_{i=0}f_ix^i$ and $i\\in\\{0,\\dotsc,2^ds-1\\}$.\n\\end{outputs}\n\n\\texttt{void SmallMonomialToNewton(int l, unsigned char[:]\\ a)}\n\nConversion from monomial to Newton basis for $\\ell\\leq 2^8$.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ such that\n\t$\\sum^{\\ell-1}_{i=0}h_iN_i=\\sum^{\\ell-1}_{i=0}f_ix^i$.\n\\end{outputs}\n\n\\texttt{void MonomialToNewton(int d, int l, unsigned char[:]\\ a)}\n\nConversion from monomial to Newton basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,             \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ such that\n\t\\begin{equation}\\label{eqn:gen-newton-monomial}\n\t\t\\sum^{\\ell-1}_{i=0}f_ix^i\n\t\t=\n\t\t\\sum^{\\ell-1}_{i=0}\n\t\th_i\n\t\tN_{i-2^d\\floor{i/2^d}}\n\t\t\\left(x^{2^d}-x\\right)^{\\floor{i/2^d}}.\n\t\\end{equation}\n\\end{outputs}\n\n\\texttt{void SmallNewtonToMononial(int l, unsigned char[:]\\ a)}\n\nConversion from Newton to monomial basis for $\\ell\\leq 2^8$.\n\n\\begin{inputs}\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ such that\n\t$\\sum^{\\ell-1}_{i=0}f_ix^i=\\sum^{\\ell-1}_{i=0}h_iN_i$.\n\\end{outputs}\n\n\\texttt{void NewtonToMonomial(int d, int l, unsigned char[:]\\ a)}\n\nConversion from Newton to monomial basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,             \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ such that\n\t\\eqref{eqn:gen-newton-monomial} holds.\n\\end{outputs}\n\n\\texttt{void NewtonInterpolate(int d, int l, unsigned char[:]\\ a)}\n\nUnivariate interpolation with respect to the Newton basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,             \\\\\n\t\\texttt{l} & - & length of the polynomial, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ such that\n\t\\begin{equation}\\label{eqn:univariate-newton}\n\t\tf\n\t\t=\n\t\t\\sum^{\\ell-1}_{i=0}\n\t\tf_i\n\t\tN_{i-2^d\\floor{i/2^d}}\n\t\t\\left(x^{2^d}-x\\right)^{\\floor{i/2^d}}\n\t\\end{equation}\n\tsatisfies $(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})=h_i$ for\n\t$i\\in\\{0,\\dotsc,\\ell-1\\}$\t\n\\end{outputs}\n\n\\texttt{void NewtonEvaluate(int d, int l, int s, unsigned char[:]\\ a)}\n\nUnivariate evaluation with respect to the Newton basis.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,              \\\\\n\t\\texttt{l} & - & length of the polynomial,  \\\\\n\t\\texttt{s} & - & bound on derivative order, \\\\\n\t\\texttt{a} & - & coefficient array.\n\\end{inputs}\n\n\\begin{outputs}\n\tIf initially $\\texttt{a}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\{0,\\dotsc,\\ell-1\\}$, then\n\ton termination $\\texttt{a}[i]=(D^{i\\bdiv{2^d}}f)(\\omega_{i\\bmod{2^d}})$ for the\n\tpolynomial $f$ defined by \\eqref{eqn:univariate-newton} and\n\t$i\\in\\{0,\\dotsc,2^ds-1\\}$.\n\\end{outputs}\n\n\\texttt{InfoSet(m, l, b)}\n\nGenerator function that yields\n\\begin{equation*}\n\t\\left(\n\ti_1+i_2b+\\dotsb+i_mb^{m-1},\n\ti_1+\\dotsb+i_m\n\t\\right)\n\\end{equation*}\nfor all $(i_1,\\dotsc,i_m)\\in\\N^m$ such that $i_1+\\dotsb+i_m<\\ell$.\n\n\\texttt{RecoverPolynomial(d, m, l, C)}\n\nComputes the polynomial that corresponds to a message.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,                                                 \n\t\\\\\n\t\\texttt{m} & - & number of variables,                                          \n\t\\\\\n\t\\texttt{l} & - & polynomial degree bound,                                      \n\t\\\\\n\t\\texttt{C} & - & a codeword array containing a message, with all other entries\n\tset to zero.\n\\end{inputs}\n\n\\begin{outputs}\n\tLet $b=\\texttt{C.b}$, $I=\\{\\vec{i}\\in\\N^m\\mid\\left|\\vec{i}\\right|<\\ell\\}$, and\n\tdefine $\\pi:\\N^m\\rightarrow\\N$ by\n\t$(i_1,\\dotsc,i_m)\\mapsto\\sum^m_{k=1}i_kb^{k-1}$. Suppose that initially\n\t$\\texttt{C}[i]=h_i\\in\\F_{2^8}$ for $i\\in\\pi(I)$, while all remaining entries of\n\tthe array are zero. Then on termination, $\\texttt{C}[i]=f_i\\in\\F_{2^8}$ for\n\t$i\\in\\pi(I)$ such that the polynomial\n\t\\begin{equation}\\label{eqn:multivariate-newton}\n\t\tf=\\sum_{\\vec{i}\\in I}f_{\\pi(\\vec{i})}N_{\\vec{i}}\n\t\\end{equation}\n\tsatisfies\n\t$(D^{\\vec{i}\\bdiv{2^d}}f)(\\vec{\\omega}_{\\vec{i}\\bmod{2^d}})=h_{\\pi(\\vec{i})}$\n\tfor $\\vec{i}\\in I$, while all remaining entries of the array are zero.\n\\end{outputs}\n\n\\texttt{EvalSet(d, m, l, s, b)}\n\nGenerator function that yields\n\\begin{equation*}\n\t\\left(\n\ti_1+i_2b+\\dotsb+i_mb^{m-1},\n\ti_1+\\dotsb+i_m,\n\t\\floor{i_1/2^d}+\\dotsb+\\floor{i_m/2^d}\n\t\\right)\n\\end{equation*}\nfor all $(i_1,\\dotsc,i_m)\\in\\N^m$ such that $i_1+\\dotsb+i_m<\\ell$ and\n$\\floor{i_1/2^d}+\\dotsb+\\floor{i_m/2^d}<s$.\n\n\\texttt{EncodePolynomial(d, m, l, s, C)}\n\nComputes the codeword that corresponds to a polynomial.\n\n\\begin{inputs}\n\t\\texttt{d} & - & field degree,                                                 \n\t\\\\\n\t\\texttt{m} & - & number of variables,                                          \n\t\\\\\n\t\\texttt{l} & - & polynomial degree bound,                                      \n\t\\\\\n\t\\texttt{s} & - & derivative order bound,                                       \n\t\\\\\n\t\\texttt{C} & - & a codeword array containing the coefficients of a polynomial.\n\\end{inputs}\n\n\\begin{outputs}\n\tLet $b=\\texttt{C.b}$, $I=\\{\\vec{i}\\in\\N^m\\mid\\left|\\vec{i}\\right|<\\ell\\}$,\n\t$C=\\{\\vec{i}+2^d\\vec{s}\\mid\\vec{i}\\in\\{0,\\dots,2^d-1\\}^m,\\vec{s}\\in S_{m,s}\\}$,\n\tand define $\\pi:\\N^m\\rightarrow\\N$ by\n\t$(i_1,\\dotsc,i_m)\\mapsto\\sum^m_{k=1}i_kb^{k-1}$. Suppose that initially\n\t$\\texttt{C}[i]=f_i\\in\\F_{2^8}$ for $i\\in\\pi(I)$, while all remaining entries of\n\tthe array are zero. Then on termination, $\\texttt{C}[i]=h_i\\in\\F_{2^8}$ for\n\t$i\\in\\pi(C)$ such that the polynomial \\eqref{eqn:multivariate-newton} satisfies\n\t$(D^{\\vec{i}\\bdiv{2^d}}f)(\\vec{\\omega}_{\\vec{i}\\bmod{2^d}})=h_{\\pi(\\vec{i})}$\n\tfor $\\vec{i}\\in C$.\n\\end{outputs}\n\n\\texttt{SystematicallyEncode(C)}\n\nSystematic encoding algorithm.\n\n\\begin{inputs}\n\t\\texttt{C} & - & a codeword array containing a message, with all other entries\n\tset to zero.\n\\end{inputs}\n\n\\begin{outputs}\n\tThe array \\texttt{C} equal to systematic encoding of the message.\n\\end{outputs}\n\n\\bibliographystyle{amsplain}\n\n\\begin{thebibliography}{1}\n\t\n\t\\bibitem{coxon2017}\n\tNicholas Coxon, \\emph{Fast systematic encoding of multiplicity codes}, J.\n\tSymbolic\n\tComput. \\textbf{94} (2019), 234--254.\n\t\n\t\\bibitem{coxon2018}\n\tNicholas Coxon, \\emph{Fast {H}ermite interpolation and evaluation over finite\n\t\tfields of characteristic two}, J. Symbolic\n\tComput. \\textbf{98} (2020), 270--283.\n\t\n\t\\bibitem{coxon2018b}\n\tNicholas Coxon, \\emph{Fast transforms over finite fields of characteristic two},\n\tJ. Symbolic\tComput., to appear.\n\t\n\t\\bibitem{gao2010}\n\tShuhong Gao and Todd Mateer, \\emph{Additive fast {F}ourier transforms over\n\t\tfinite fields}, IEEE Trans. Inform. Theory \\textbf{56} (2010), no.~12,\n\t6265--6272.\n\t\n\t\\bibitem{lin2016a}\n\tSian-Jheng Lin, Tareq~Y. Al-Naffouri, Yunghsiang~S. Han, and Wei-Ho Chung,\n\t\\emph{Novel polynomial basis with fast {F}ourier transform and its\n\t\tapplication to {R}eed--{S}olomon erasure codes}, IEEE Trans. Inform. Theory\n\t\\textbf{62} (2016), no.~11, 6284--6299.\n\t\n\t\\bibitem{lin2014}\n\tSian-Jheng Lin, Wei-Ho Chung, and Yunghsiang~S. Han, \\emph{Novel polynomial\n\t\tbasis and its application to {R}eed-{S}olomon erasure codes}, 55th {A}nnual\n\t{IEEE} {S}ymposium on {F}oundations of {C}omputer {S}cience---{FOCS} 2014,\n\tIEEE Computer Soc., Los Alamitos, CA, 2014, pp.~316--325.\n\t\n\\end{thebibliography}\n\t\n\\end{document}\n", "meta": {"hexsha": "27c85c1384519f73713eea49be4747666c902728", "size": 27937, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/doc.tex", "max_stars_repo_name": "ftoc2-dev/ftoc2", "max_stars_repo_head_hexsha": "e66d62a578c0898353e89bb427e241ad7f8e99d3", "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": "docs/doc.tex", "max_issues_repo_name": "ftoc2-dev/ftoc2", "max_issues_repo_head_hexsha": "e66d62a578c0898353e89bb427e241ad7f8e99d3", "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": "docs/doc.tex", "max_forks_repo_name": "ftoc2-dev/ftoc2", "max_forks_repo_head_hexsha": "e66d62a578c0898353e89bb427e241ad7f8e99d3", "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": 34.1946144431, "max_line_length": 126, "alphanum_fraction": 0.6480294949, "num_tokens": 10609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7122321720225279, "lm_q1q2_score": 0.6109300405087493}}
{"text": "\n\\subsection{Nested logit}\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\nIf the error terms are not IID this is more difficult to calculate.\n\nWe divide the \\(J\\) alternatives into nests. Within each of these we assume IID error terms, but allow variation between them.\n\nFor example we could have a nest of public/private transport. We could have a nest of types of product, and within that the firms offering the product.\n\nThe nested logit model does \\(2\\) or more seqential IID logit models. One to select the nest, and the other to select the alternative within the nest.\n\n", "meta": {"hexsha": "46fe0eee7969c9133b8c5f79a41654685ac9d0f6", "size": 647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glmMulti/01-04-nested.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-04-nested.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-04-nested.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": 40.4375, "max_line_length": 151, "alphanum_fraction": 0.7496136012, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6109096684476912}}
{"text": "\\documentclass[a4paper]{article} \n\\input{head}\n\\usepackage{algorithm}\n\\usepackage{verbatim}\n\\usepackage[noend]{algpseudocode}\n\\newcommand{\\algrule}[1][.2pt]{\\par\\vskip.5\\baselineskip\\hrule height #1\\par\\vskip.5\\baselineskip}\n\\newcommand{\\floor}[1]{\\left\\lfloor #1 \\right\\rfloor}\n\\newcommand{\\ceil}[1]{\\left\\lceil #1 \\right\\rceil}\n\n\\begin{document}\n\n%-------------------------------\n%\tTITLE SECTION\n%-------------------------------\n\n\\title{\\textbf{COL351 : Analysis and Design of Algorithm \\\\ Assignment 3 }}\n\\author{Gaurav Jain (2019CS10349) \\& T Abishek (2019CS10407)}\n\\date{}\n\n%-------------------------------\n%\tCONTENTS\n%-------------------------------\n\n\\maketitle\n\n\\section{Convex Hull}\nThe Divide and Conquer algorithm to compute Convex Hull is present below:\n\n{\\centering\n\\begin{minipage}{\\linewidth}\n\\begin{algorithm}[H]\n\\caption{Convex Hull Algorithm}\\label{alg:chull}\n\\begin{algorithmic}[1]\n\\Procedure{ConvexHull}{P = \\{($x_1$,$y_1$),($x_2$,$y_2$)....($x_n$,$y_n$)\\}}\n\\If{n $\\leq$ 5} \n \\State Solve using Brute Force method\n\\EndIf\n\\State Sort P in increasing order according to x coordinate\n\\State Divide P into A and B such that: A contains the left $\\floor{\\frac{n}{2}}$ points and B contains the right $\\ceil{\\frac{n}{2}}$ points.\n\n\\State $Q_1 \\gets$ \\textsc{ConvexHull}(A)\n\\State $Q_2 \\gets$ \\textsc{ConvexHull}(B)\n\n\\State $Q \\gets$ \\textsc{Merge}($Q_1$,$Q_2$)\n\n\\State \\Return $Q$\n\n\\EndProcedure\n\\algrule\n\\Procedure{Merge}{A,B}\n\\State $(x_1,y_1) \\gets$  \\textsc{UpperTangent}(A,B)\n\\State $(x_2,y_2) \\gets$ \\textsc{LowerTangent}(A,B)\n\\State U $\\gets$ \\{\\}\n\\State $u \\gets x_1$\n\\While{$u \\neq x_2$}\n    \\State Add $u$ to U \n    \\State $u \\gets$ next element in A in counter clockwise direction\n\\EndWhile\n\\State $u \\gets y_1$\n\\While{$u \\neq y_2$}\n    \\State Add $u$ to U \n    \\State $u \\gets$ next element in B in clockwise direction\n\\EndWhile\n\n\\State \\Return U\n\\EndProcedure\n\n\\algrule\n\\Procedure{UpperTangent}{A,B}\n\\State a $\\gets$ Rightmost point of A\n\\State b $\\gets$ Leftmost point of B\n\\State T $\\gets$ (a,b)\n\\While{T = ab not a tangent to both A and B}\n    \\While{T not a tangent to A}\n    \\State a $\\gets$ next element in A in counter clockwise direction\n    \\EndWhile\n    \n    \\While{T not a tangent to B}\n    \\State b $\\gets$ next element in B in clockwise direction\n    \\EndWhile\n\\EndWhile\n\n\\State \\Return T\n\\EndProcedure\n\\algrule\n\\Procedure{LowerTangent}{A,B}\n\\State a $\\gets$ Index of rightmost point of A \n\\State b $\\gets$ Index of leftmost point of B\n\\State T $\\gets$ ab\n\\While{T = ab not a tangent to both A and B}\n    \\While{T not a tangent to A}\n    \\State a $\\gets$ next element in A in clockwise direction\n    \\EndWhile\n    \n    \\While{T not a tangent to B}\n    \\State b $\\gets$ next element in B in counter clockwise direction\n    \\EndWhile\n\\EndWhile\n\n\\State \\Return T\n\\EndProcedure\n\n\\end{algorithmic}\n\\end{algorithm}\n\\end{minipage}\n\\par}\n\n\\newpage\n\\textbf{Runtime Analysis:}\\\\\n\nThe time complexity of the divide and conquer algorithm to compute convex hull is calculated using the recurrence relation: T(n) = 2T(n/2)+O(n)+merge operation time complexity. Median is calculated in O(n) using $k^{th}$ smallest element problem discussed in lectures. The brute force method is used for base case when $n\\leq5$ which take $O(n^3)$ time for n points. Thus, there is only a small increase in runtime.\\\\ \nThe time taken in merge operation depends on the time taken to calculate upper tangent and lower tangent of the two convex hulls to be merged and the time taken to merge these two convex hulls and the two tangents which is performed in a while loop iterating over all elements of A and B.\\\\\nThe lower tangent and upper tangent function has same time complexity which is $O(size A)$ for convex hull A. Thus, the time complexity of merge operation is $O(size A)$ + $O(size B)$ + $O(n)$ = $O(n)$.\\\\\n\n\\textbf{Correctness of Algorithm:}\\\\\n\n\\textit{\\underline{Claim 1}} \\\\\nThe line given by the \\textsc{LowerTangent} procedure touches A and B at their lower halves and does not intersect A and B at any other points.\\\\\n\\textit{\\underline{Proof}} \\\\\nThe procedure tends to move both points located on A and B in the same direction and this leads to a line segment which passes through the lowest end of the lower halves of A and B.\\\\\nDue to this movement, line T becomes a direct tangent to the convex hulls A and B. This line also never intersect at any other point of A and B.{\\hfill\\qed}\n\n\\textit{\\underline{Claim 2}} \\\\\nThe polygon formed after the merging step of two convex hulls A and B is a convex hull.\\\\\n\\textit{\\underline{Proof}} Proof by Contradiction \\\\\nSince A and B are convex and they are connected using upper and lower tangents, the merged polygon is also convex in nature. Suppose the polygon formed after merging A and B is not a convex hull. This means that there is at least one extra point in the merged polygon.\\\\\nSo after removing this point, the new polygon is a convex hull and the removed point should lie inside the new polygon. This implies that the removed point was part of a concave edge which is a contradiction as A and B are convex in nature.\nSo the above claim holds.{\\hfill\\qed}\\\\\\\\\nWe can proof the correctness of the algorithm using induction on number of points present in the plane. By dividing the plane into smaller and smaller parts, we reach the base case which is solved using brute force method. Using claim 1 and 2, merging the smaller convex hulls results in the final answer.\n\n\n\\newpage\n\n\\section{Particle Interaction}\n\n\\textbf{Observation}:\\\\\n\nF\\textsubscript{j} $=$ C q\\textsubscript{j} \\bigg( $\\sum\\limits_{i<j}^{}\\frac{q\\textsubscript{i}}{(j-i)\\textsuperscript{2}}$ $-$ $\\sum\\limits_{i>j}^{}\\frac{q\\textsubscript{i}}{(j-i)\\textsuperscript{2}}$ \\bigg)\n\\\\\nF\\textsubscript{j} $=$ C q\\textsubscript{j} c\\textsubscript{j}\n\\\\\\\\\n\nWhere, \\\\\nc\\textsubscript{k} $=$  $\\sum\\limits_{i<j}^{}\\frac{q\\textsubscript{i}}{(j-i)\\textsuperscript{2}}$ $-$ $\\sum\\limits_{i>j}^{}\\frac{q\\textsubscript{i}}{(j-i)\\textsuperscript{2}}$  for all k $\\in$ [1,n] \\hfill(1)   \n\\\\\\\\\n\nConsider the two polynomials, \\\\\nA(x) $=$ q\\textsubscript{1}x + q\\textsubscript{2}x\\textsuperscript{2} + . . . + q\\textsubscript{n}x\\textsuperscript{n}\\\\\n\nB(x) $=$ $ - \\frac{1}{(n-1)\\textsuperscript{2}}x -  . . . - \\frac{1}{4}x\\textsuperscript{n-2} - x\\textsuperscript{n-1} - 0$.$x\\textsuperscript{n} + x\\textsuperscript{n+1} + \\frac{1}{4}x\\textsuperscript{n+2} + . . . +  \\frac{1}{(n-1)\\textsuperscript{2}}x\\textsuperscript{2n-1} $\n\\\\\n\nConsider the product, P(x) = A(x)$*$B(x). \n\\\\Co-efficient of x\\textsuperscript{k} for k in range (n,2n+1) $=$ $\\sum\\limits_{l = 1}^n a\\textsubscript{l}$b\\textsubscript{k-l} \\hfill(2)\\\\\\\\\n\nFrom equation (1) and equation (2), it is observable that coefficient of $x^{n+j}$ in P(x) = $c_j$. So, to obtain $c_j$, we need P(x) which can be calculated using Fast Fourier Transform discussed in the lectures. The time complexity here is $O(nlogn)$.\n\\\\\\\\\nNow, using c\\textsubscript{j} and equation (1), we can obtain F\\textsubscript{j} for all the particles $(j \\in [1,n])$ within $O(nlogn)$ time complexity.\n\\\\\n\n\n{\\centering\n\\begin{minipage}{\\linewidth}\n\\begin{algorithm}[H]\n\\caption{Particle Interaction Algorithm}\\label{pia}\n\\begin{algorithmic}[1]\n\\Procedure{ParticleInteraction}{}\n\\State{$A$ $\\gets$ $[q\\textsubscript{1}, q\\textsubscript{2}, ... , q\\textsubscript{n}]$}\n\\State{$B$ $\\gets$ $[ -$ $\\frac{1}{(n-1)\\textsuperscript{2}}$, - $\\frac{1}{(n-2)\\textsuperscript{2}}$, $-1, 0, 1,$ $\\frac{1}{(n-2)\\textsuperscript{2}}$, $\\frac{1}{(n-1)\\textsuperscript{2}}$]}\n\n\\State{$P \\gets$ MULTIPLY(A, B)}\n\\State{$TotalForce \\gets$ Array of size n}\n\\For{$i \\gets 1$ to $n$}\n    \\State{$TotalForce[i] \\gets$ $C * A[i] * P[n+i]$}\n\\EndFor\n\\EndProcedure\n\\Function{Multiply}{$A, B$}\n    \\State{$dft_A \\gets DFT(A)$}\n    \\State{$dft_B \\gets DFT(B)$}\n    \\State{$dft_P \\gets$ Array of size 2n+1}\n    \\For{$i \\gets 1$ to $len(dft_A)$}\n    \\State{$dft_P[i] \\gets$ $dft_A[i] * dft_B[i]$}\n    \\EndFor\n    \\State{$P \\gets$ $InvDFT(dft_P)$}\n    \\State\\Return{$P$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\\end{minipage}\n\\par}\n\n\\textbf{Runtime Analysis:}\\\\\nThe above algorithm returns $TotalForce$ array which has $j^{th}$ element as the final totalforce acting on $j^{th}$ particle. The \\textsc{Multiply} function invloves calculating DFT for 2 vectors, each has time complexity of O(nlogn) as discussed in the lecture. \\\\\\\\\nNext we have a for loop which has O(n) time complexity. Further, there is InverseDFT which again takes O(2nlog2n). Next, after the \\textsc{Multiply} function we calculate the $TotalForce$ using elements of P and A. This for loop takes O(2n) time complexity. So,\n\\begin{center}\n    T(n) = 2*O(nlogn) + O(n) + O(2nlog2n) + O(2n) = O(nlogn)\n\\end{center}\n\n    %\\begin{algorithm}[H] %\n\n%\\end{algorithm}%\n\\newpage\n\\section{Distance Computation using Matrix Multiplication}\n\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item \\textbf{\nProve that the graph H = (V, E\\textsubscript{H}) can be computed from G in O(n\\textsuperscript{$\\omega$}) time, where $\\omega$ is the exponent of matrix-multiplication.}\n\\\\\\\\\nSolution: Using the property of transitive closure(discussed in lecture notes). Assume A is the adjacency matrix of graph G. Then, (A\\textsuperscript{k})\\textsubscript{ij} $>$ 0 iff there is a walk of length exactly k from i to j. Here edges exist between vertices in H, if there is a walk of length 2 or 1 in graph G. (A\\textsuperscript{2}) gives the adjacency matrix of edges who had walks of length of 2 in G. So, Adjacency matrix of H is given by (A\\textsuperscript{2}) + A. Matrix Addition is O(n\\textsuperscript{2}) and Matrix Multiplication is O(n\\textsuperscript{$\\omega$}). So, overall time complexity is O(n\\textsuperscript{$\\omega$}) if $\\omega > 2$\\\\\n\n\\item \\textbf{\nArgue that for any x, y $\\in$ V , D\\textsubscript{H}(x, y) = $\\ceil{ \\textbf{D\\textsubscript{G}(x, y)/2} }$. }\n\\\\\\\\\nSolution: Assume for some vertice x,y the distance in graph G is k. The Path is (x,$a_1$, $a_2$, $a_3$ ........ $a_(k-1)$, y). As all the vertices who have walk of distance 2 between them get edges in the graph H, x and $a_2$, $a_2$ and $a_4$.... all have edges between them. So the path between x and y becomes (x, $a_2$, $a_4$ ........ $a_(k-2)$, y) if k is even and (x, $a_2$, $a_4$ ........ $a_(k-1)$, y) if k is odd. The distance is k/2 if k is even and k/2 + 1 if k is odd.\n$\\implies $ D\\textsubscript{H}(x, y) = $\\ceil{ \\textbf{D\\textsubscript{G}(x, y)/2} }$\nProved. \n\n\n\\item \\textbf{\nLet A\\textsubscript{G} be adjacency matrix of G, and M $=$ D\\textsubscript{H}$\\star$A\\textsubscript{G}. Prove that for any x, y $\\in$ V, the following holds.\\\\\\\\\n$D\\textsubscript{G}(x, y) = \n \\begin{cases} \n      2D\\textsubscript{H}(x, y) & M(x, y) $ \\geqslant$ degree\\textsubscript{G}(y) · D\\textsubscript{H}(x, y) \\\\\n      2D\\textsubscript{H}(x, y) - 1 & M(x, y) $ \\lneq$ degree\\textsubscript{G}(y) · D\\textsubscript{H}(x, y) \\\\\n   \\end{cases}\n$}\n\\\\\n\\item \\textbf{\nUse (c) to argue that D\\textsubscript{G} is computable from D\\textsubscript{H} in O(n\\textsuperscript{$\\omega$}) time.}\n\\\\\nFrom (c) we have \n$D\\textsubscript{G}(x, y) = \n \\begin{cases} \n      2D\\textsubscript{H}(x, y) & M(x, y) $ \\geqslant$ degree\\textsubscript{G}(y) · D\\textsubscript{H}(x, y) \\\\\n      2D\\textsubscript{H}(x, y) - 1 & M(x, y) $ \\lneq$ degree\\textsubscript{G}(y) · D\\textsubscript{H}(x, y) \\\\\n   \\end{cases}\n$\nwhere  A\\textsubscript{G} is the adjacency matrix of G and M = D\\textsubscript{H}$\\star$A\\textsubscript{G}.\\\\\nAs, $D_G$ is computable using $D_H$ which can be computed in O(n\\textsuperscript{$\\omega$}) time. M can be computed in O(n\\textsuperscript{$\\omega$}) time too. So, the overall time complexity is O(n\\textsuperscript{$\\omega$}).\n\n\\item \\textbf{\nProve that all-pairs-distances in n-vertex unweighted undirected graph can be computed in O(n\\textsuperscript{$\\omega$}log n) time, if $\\omega$ is larger than two.}\n\\\\\n\n{\\centering\n\\begin{minipage}{\\linewidth}\n\\begin{algorithm}[H]\n\\caption{Pair Distance}\\label{pia}\n\\begin{algorithmic}[1]\n\\Procedure{shortestdistance}{$A_G$}\n\n\\State \\If{$A_G$ elements are non-empty}\n\\State \\Return $A_G$\n\\State \\Else\n\\State $A_H$ = ($A_G$\\textsuperscript{2}) + $A_G$\n\\State $D_H$ = SHORTESTDISTANCE($A_H$)\n\\State \\Return dpart($D_H$)\n\\EndIf\n\\EndProcedure\n\n\\end{algorithmic}\n\\end{algorithm}\n\\end{minipage}\n\\par}\n\n\\textbf{Runtime Analysis:}\\\\\nThis is a recursive algorithm, where T(n) = T(n/2) + O(n\\textsuperscript{$\\omega$}), as each time part d is called, the graph's distance halves. This when solved, the time complexity becomes O(n\\textsuperscript{$\\omega$}log n) time\n\n\\textbf{Correctness of Algorithm:}\\\\\nAs, $D_H$ gives $D_G$ using computation done in part D, using that we can say that, if $D_H$ is correct, then $D_G$ calculated will also be correct. In the base case, when the all the vertices are connected, that itself is returned. So, the base case is correct. In the induction step, when until n paths are calculated, the next step would give the correct distance too. Therefor, by induction, proved.\n\n\\end{enumerate}\n\\newpage\n\\section{Hashing}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item The approximate probability can be calculated by:\n\n\\begin{center}\n    $P &= {\\frac{n*n^{n - \\log_2 n}}{n^n}} * {n \\choose \\log_2 n}$ \n\\end{center}\nIn the denominator, we have $n^n$ because, n numbers are being assigned and each number has n possible positions that it can go into.\\\\\nIn the numerator, we have n, as the maximum chain, could be any one of the n positions in the hash table. and $n\\textsuperscript{(n-logn)}$ because $n-logn$ numbers can be assigned to any position and the rest is assigned to the single position. It is also multiplied with n choose ($logn$) because from the n numbers, logn numbers are choosen to be used in the max chain. This final calculation is actually an approximation which is greater than the actual probability, because the expression above actually recounts the same cases multiple times due to the  $n\\textsuperscript{(n-logn)}$ factor. And below, we prove that this bigger approximation is lesser than 1/n and thus the probability is also lesser than 1/n.\n\\begin{center}\n    $P &= {\\frac{n}{n^\\log_2 n}} * {\\frac{n!}{(\\log_2 n)!(n-\\log_2 n)!}}$\n\\end{center}\n\n\\begin{center}\n    $P &= \\frac{n}{(\\log_2 n)!} * {\\frac{n(n-1)(n-2)....(n-\\log_2 n+1)}{n^{\\log_2 n}}}$\n\\end{center}\n\n\\begin{center}\n    $P \\leq \\frac{n}{(\\log_2 n)!}$\n\\end{center}\n\n\\begin{center}\n    Using Sterling Approximation,\n\\end{center}\n    \n\\begin{center}\n    $\\log(k!) = k*log(k) - k$\n\\end{center}    \n\n\\begin{center}\n    So, $\\log(\\log_2 n!) = (\\log_2 n)(\\log (n/e))$\n\\end{center}\n    \n\\begin{center}\n    $ \\frac{\\log(\\log_2 n!)}{\\log n} = \\frac{(\\log_2 n)(\\log (n/e))}{\\log n}$\n\\end{center}\n\n\\begin{center}\n    $ \\frac{\\log(\\log_2 n!)}{\\log n} = \\frac{(\\log (n/e))}{\\log 2}$\n\\end{center}\n\n\\begin{center}\n    For large n, \n\\end{center}\n\n\\begin{center}\n    $\\frac{(\\log (n/e))}{\\log 2} > 2$  \n\\end{center}\n\n\\begin{center}\n    $\\frac{\\log(\\log_2 n!)}{\\log n} > 2$\n\\end{center}\n\n\\begin{center}\n    $\\log(\\log_2 n!) > 2*\\log n$\n\\end{center}\n\n\\begin{center}\n    $\\log(\\log_2 n!/n^2) > 1$\n\\end{center}\n\n\\begin{center}\n    $\\log(\\log_2 n!/n^2) > 1$\n\\end{center}\n\n\\begin{center}\n    So, $\\frac{n}{(\\log_2 n)!} < \\frac{1}{n}$\n\\end{center}\n\\item Prove that for any given r $\\in$ [1,p-1], there exists at least $M/n \\choose n$ subsets of U of size n in which maximum chain length in hash-table corresponding to $H_r(x)$ is $\\Theta(n)$.\\\\\n\\textbf{Solution:}\\\\\nAs x is invertible with rx mod p with the given constraints(given in lecture), rx mod p $\\in$ [0,M-1].\\\\\nTake y = rx mod p, then $H_r(x) = H(y)$. \\\\\nThe aim is to have a set S such that, when hashed using H(y), all the numbers go to the same spot and the maximum-chain length is n, which is $\\Theta(n)$.\\\\\nAssume S = $\\{a_1, a_2..... a_n \\}$, which implies that, $a_1$ mod n = $a_2$ mod n, $a_2$ mod n = $a_3$ mod n ..... \\\\\n$\\implies a_1-a_2$ mod n = 0 ....\\\\\n$\\implies a_1 - a_2 = cn$ where c is an integer.\\\\\n$\\implies a_1 = b + c_1n$ where b (fixed for a specific set) $\\in$ [0,n-1] and $c_1$ $\\in$ [0, $(M-1)/n$] as $a_1$ $\\in$ [0,M]. \\\\ \nAll elements in S can be represented in the above form. And all the elements with above form can be put in a set S which satisfies the set constraints we are looking for.\\\\\nAs, $c_1$ can have M/n unique values, a set S can choose from M/n numbers while forming the set of n numbers.\\\\\n$\\implies$ the possible number of subsets with a fixed b, is {$M/n\\choose n$}, whose maximum length is n $\\in \\Theta(n)$.\\\\\n$\\implies$ there exists atleast {$M/n\\choose n$} subsets that whose maximum chain length is $\\Theta(n)$. {\\hfill\\qed}\n\n\\item The graph plotted is shown below:\n\n\\begin{figure}[H]\n            \\centering\n        \t\\includegraphics[scale=0.65]{plot5.png}\n        \t\\caption{Graph of Maxchain length. \\label{fig:1}}\n        \\end{figure}\n        \n        We see that the H() hashing function gives a linear line whereas the Hr() hashing function's max chain seems to be almost constant. This is because, as we increase k, the numbers in the set whose hashing table position is same increases linearly. Due to this, the max chain length too increases. But in the Hr() hashing function, the rx mod p part, helps \"randomize\" the number before applying the hashing function, thus reducing the max chain length and almost keeping it at a constant level.\n\\end{enumerate}\n\nThe code used to plot is pasted below:\n\\verbatiminput{4c.py}\n\n\n%------------------------------------------------\n\n\\end{document}\n", "meta": {"hexsha": "0283d10d457de4b7ea6fe569f1e08f0586bf24ea", "size": 17480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment-3/A3_sol_LaTeX/main.tex", "max_stars_repo_name": "GauravJain28/ADA-Assignments", "max_stars_repo_head_hexsha": "81783248c2850d8963531c74bbf711f37c34b07f", "max_stars_repo_licenses": ["MIT"], "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-3/A3_sol_LaTeX/main.tex", "max_issues_repo_name": "GauravJain28/ADA-Assignments", "max_issues_repo_head_hexsha": "81783248c2850d8963531c74bbf711f37c34b07f", "max_issues_repo_licenses": ["MIT"], "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-3/A3_sol_LaTeX/main.tex", "max_forks_repo_name": "GauravJain28/ADA-Assignments", "max_forks_repo_head_hexsha": "81783248c2850d8963531c74bbf711f37c34b07f", "max_forks_repo_licenses": ["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.4893617021, "max_line_length": 717, "alphanum_fraction": 0.6811212815, "num_tokens": 5713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484143, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.6109096620750218}}
{"text": "\\subsection{Hash-to-curve Functions}\n\\label{ssec:hash-to-curve}\n\nThe contents of this section should not be considered a full proof\nof security but are for implementation reference.\nFormal treatment of the security proofs for hash-to-curve\nfunctions are handled in referenced works.\n\nWe turn our attention to the hash-to-curve functions\nimplemented in our system.\nThe contents of this section are described hereafter.\nFirst, we review a mechanism often employed to solve this problem.\nThen, we briefly discuss why this solution is not ideal in our setting.\nFinally, we introduce the basis of our implementation and proceed into the\ndefinition of the algorithms used in our system after a brief review of\nsome required mathematical operations.\nAll algorithms may be found at the end of this section.\n\nThe seemingly standard, non-deterministic method to perform a hash-to-curve\noperation in the elliptic curve setting is to use the ``MapToGroup''\nmethod as presented in the original BLS short signature\npaper~\\cite{boneh2001short}.\nIn this method values are hashed into\n$\\F_{p}$ by modular arithmetic with a concatenated counter.\nThis counter starts at a fixed value, and is incremented until\na value is found that creates a valid point on the specified\nelliptic curve.\nWhile this may be sufficient in some instances, we prefer \ndeterministic methods due to the need for bounded\ncomputational overhead.\nIn our system, the need for bounded computational\noverhead arises from a desire to allow an Ethereum smart contract to\nperform the hash-to-curve operations with bounded gas consumption.\nDeterministic methods also have the benefit of minimizing\nside-channel attacks in those\nalgorithms that require such protection.\n\nThe hash-to-curve implementation selected allows the problem space to be\ndivided into independent problems such that their solutions may be composed.\nSpecifically, we first hash to the base field\n(hash map $\\mathfrak{h}:\\braces{0,1}^{*}\\to \\F$)\nand then find a deterministic map from the base field\nto the elliptic curve (function $f:\\F\\to E(\\F)$).\nThis approach allows for a separation of concerns and has become a\nstandard approach to the problem of hashing into an elliptic curve\n~\\cite{icart2009hash,ft2012bnhashtocurve,boneh2019h2cBLS12}.\nAlthough this strategy does offer a simplified view of the problem,\nmapping from the base field to the elliptic curve is nontrivial.\nAdditionally, it is frequently the case that $f$ is not surjective, but\nwe can overcome this limitation to obtain a surjective hash-to-curve algorithm\nunder easily-satisfied\nconditions~\\cite{tibouchi2014elligator,ft2012bnhashtocurve}.\nSpecifically, we use domain-separation in order to obtain independent hash\nfunctions.\nThese independent hash functions allow us overcome a non-surjective\nmapping.\nWe will fully address this concern later in this document.\n\nOur discussion of hashing functions follow\n\\cite{ft2012bnhashtocurve,boneh2019h2cBLS12}.\nWe ask the reader to note that in the remaining work of this section,\nwe view $E(\\F_{p})$ as an additive group unless otherwise specified.\nWe highlight this fact because this is different from the multiplicative\nnotation used previously in this document.\nBefore we define our implementation of the hash-to-curve algorithms employed,\nwe feel a review of the mathematics would benefit the reader.\nThus, we first\nreview the mathematics necessary to perform the hash-to-curve operations.\nAfter this review, we present the algorithm for hashing to $\\G_{1}$\nand then present the algorithm for hashing to $\\G_{2}$.\n\nFor reference, the full \\textsc{HashToG1} algorithm can be\nfound in Alg.~\\ref{alg:hash-to-G1} and the full algorithm for \\textsc{HashToG2}\ncan be found in Alg.~\\ref{alg:hash-to-G2}.\n\n\n\n\\subsubsection{Inverses, Square Roots, and Legendre Symbols\n    in $\\F_{p}$}\n\\label{sssec:finite_math_Fp}\n\nIn this section we review some finite field mathematics that are\nimportant in our hash-to-curve setting.\n\nWe begin by reviewing inversion in $\\F_{p}$.\nFirst, we recall $\\F_{p}^{*} \\equiv \\F_{p}\\setminus\\braces{0}$,\nthe nonzero elements of our finite field.\nFor $a\\in\\F_{p}^{*}$, we have Euler's formula:\n\n\\begin{equation}\n    a^{p-1} = 1 \\mod p.\n\\end{equation}\n\n\\noindent\nThis implies $a^{-1} \\mod p = a^{p-2}$.\nWe acknowledge more efficient methods for computing modular inverses are\npossible, but exponentiation can easily be performed in constant time, which\nis a goal of our implementation. This concludes our discussion of computing\ninverses in $\\F_{p}$.\n\nWe now review the mechanisms for\ncomputing Legendre symbols.\nWe recall that $a\\in\\F_{p}^{*}$ is a \\emph{quadratic residue}\nif there is $x\\in\\F_{p}$ such that $x^{2} = a \\mod p$;\notherwise, $a$ is a called a \\emph{quadratic nonresidue}.\nThis allows us to define the Legendre symbol~\\cite{imc2008}:\n\n\\begin{equation}\n    \\chi_{p}(a) \\equiv \\begin{cases}\n        1 \\quad& \\text{if there $a$ is a quadratic residue modulo $p$.} \\\\\n        -1 \\quad& \\text{if there $a$ is a quadratic nonresidue modulo $p$.} \\\\\n        0 \\quad& \\text{if $p \\mid a$}\n    \\end{cases}\n\\end{equation}\n\n\\noindent\nThe Legendre symbol has a simple formula:\n\n\\begin{equation}\n    \\chi_{p}(a) = a^{\\frac{p-1}{2}}.\n\\end{equation}\n\n\\noindent\nThis formula holds even when $a=0$.\nThis concludes our discussion of computing the Legendre Symbol in $\\F_{p}$.\n\nComputing square roots is more challenging.\nWe now review the mechanism of computing square roots.\nIn our case $p = 3\\mod 4$, so there is a simple\nformula to solve $x^{2} = a$:\n\n\\begin{equation}\n    x = a^{\\frac{p+1}{4}}.\n\\end{equation}\n\n\\noindent\nThis relies on the assumption that $a$ is a quadratic residue,\nso $a^{\\frac{p-1}{2}} = 1$.\nThis concludes our discussion of computing the square roots in $\\F_{p}$.\n\nTaking inverses, Legendre symbols, and square roots\ngives us the necessary tools to hash to $\\G_{1}$.\nThis ends the preliminary work necessary to develop\n\\textsc{HashToG1}.\n\n\n\\subsubsection{Inverses, Square Roots, and Legendre Symbols\n    in $\\F_{p^{2}}$}\n\\label{sssec:finite_math_Fp2}\n\nThe previous section reviewed the mathematics of inverses, square roots, and\nLegendre Symbols in $\\F_{p}$.\nWe must be able to perform the same operations\nin $\\F_{p^{2}}$ if we wish to hash to $\\G_{2}$.\nWhile computing square roots and\ninverses may be familiar to the reader in $\\F_{p}$, the operations require\nspecial handling in $\\F_{p^{2}}$.\nWe review these mechanisms now.\n\nWe first address the problem of computing inverses in $\\F_{p^{2}}$.\nOur discussion and methods follow~\\cite{adj2012sqrtEvenExt},\nand we present their general results applied to our particular case.\nAs mentioned above, the setting of our elliptic curve is $p = 3\\mod 4$.\nThis implies $-1$ is a quadratic nonresidue.\nThus, we have the following isomorphism:\n\n\\begin{equation}\n    \\F_{p^{2}} \\simeq \\F_{p}[i]/\\parens{i^{2}+1}.\n\\end{equation}\n\n\\noindent\nThis is the analogous to constructing the complex numbers $\\C$ from\nthe real numbers $\\R$.\nOur implementation uses this construction. We may use\nthis construction to compute an efficient inversion as follows:\n\n\\begin{equation}\n    \\parens{a_{0} + a_{1}i}^{-1} = \\frac{a_{0}-a_{1}i}{a_{0}^{2}+a_{1}^{2}}.\n\\end{equation}\n\n\\noindent\nThe main computational cost of this operation is the inversion of an element\nin $\\F_{p}$.\nThis concludes our discussion of computing inverses in $\\F_{p^{2}}$.\n\nWe now begin our discussion of computing the Legendre Symbol in $\\F_{p^{2}}$\nIf $a = a_{0} + a_{1}i\\in\\F_{p^{2}}$, then $a$ is a\nquadratic residue in $\\F_{p^{2}}$ if and only if $a_{0}^{2} + a_{1}^{2}$\nis a quadratic residue in $\\F_{p}$.\nThe main computational cost of this operation is the computation of the Legendre\nsymbol of an element in $F_{p}$.\nFrom the above we have the Legendre symbol in $\\F_{p^{2}}$,\nwhich we denote as \\textsc{LegendreFP2} or $\\chi_{p^{2}}(\\cdot)$;\nthis particular algorithm is presented in\nAlg.~\\ref{alg:legendre-fp2}.\nThis concludes our discussion of computing the Legendre Symbol in\n$\\F_{p^{2}}$.\n\nWe will now look at computing square roots in $\\F_{p^{2}}$.\nThe main idea is to find $b\\in\\F_{p^{2}}$ and odd $s$ such\n$b^{2}a^{s} = 1$.\nIn this case, we see\n\n\\begin{align}\n    \\brackets{ba^{\\frac{s+1}{2}}}^{2} &= b^{2}a^{s+1} \\nonumber\\\\\n        &= a.\n\\end{align}\n\n\\noindent\nIf we set\n\n\\begin{align}\n    b &= \\parens{1 + a^{\\frac{p-1}{2}}}^{\\frac{p-1}{2}} \\nonumber\\\\\n    s &= \\frac{p-1}{2},\n\\end{align}\n\n\\noindent\nthen when $b\\ne0$, we have $b^{2}a^{s} = 1$.\nWhen $b=0$, we have $a^{\\frac{p-1}{2}}=-1$.\nIn this case, our square root is $ia^{\\frac{p+1}{4}}$.\nThis procedure is formally presented in~Alg.~\\ref{alg:sqrt-fp2}.\nThe main computational cost of this operation is two exponentiations\nin $\\F_{p^{2}}$.\nThis concludes our discussion of computing square roots in $\\F_{p^{2}}$\nand the preliminary review of those operations\nnecessary to develop \\textsc{HashToG2}.\n\n\n\\subsubsection{Hashing to Base}\n\\label{sssec:hash-to-base}\n\nIn this section we will describe the hash-to-base operation.\nWe begin by discussing the construction of a random oracle into\n$\\F_{p}$ using a single cryptographic hash function with\ndomain separation.\nWe then bound the deviation from uniformity in this operation.\n\nIn the following $H$ is a $256$-bit hash function.\nIn our implementation we use \\textsc{Keccak256}.\nNote this is the \\textsc{Sha3} variant used by Ethereum\nthat differs from the NIST approved \\textsc{Sha3} hash function due to a\ndifference in the handling of padding.\n\nLet $H$ act as a random oracle.\nWe map from $H$ to $\\Z$ by interpreting the output of a\ncryptographic hash function as a big endian unsigned integer.\nThis can be seen in lines 4 and 5 of $\\textsc{HashToBase}$\nas the function named $\\texttt{b2u}$.\nAlthough we may naively map from $\\Z$ to $\\Z_{p}$ by simply taking the\noutput of $H$ modulo $p$, this would be insecure in our setting due to the\nnonuniformity of this operation.\nIn order to ensure the mapping from $\\Z$ to $\\Z_{p}$ is more\nuniformly distributed, domain separation is utilized.\nSpecifically, we use domain separation in order obtain independent hash\nfunctions from $H$ through concatenation of constants with the message being\nhashed.\nThese independent hash functions allow us to create a secure 512-bit random\nnumber from a single cryptographic hash function.\nThe full explanation of this operation is below.\n\nLet $\\textsc{HashToBase}:\\braces{0,1}^{*}\\times\\braces{0,1}^{8}\\times\n\\braces{0,1}^{8}\\to\\F_{p}$ denote our random oracle into the\nunderlying field $\\F_{p}$.\nIn the $\\textsc{HashToBase}$ operation the first component corresponds to the\nunderlying message being hashed, while the last two elements provide the\nnecessary domain separation.\nSee Alg.~\\ref{alg:hash-to-fp} for the full implementation.\n\nDue to the fact $p$ is prime and not a power of 2, there will be some\nnonuniformity in the resulting distribution of \\textsc{HashToBase}.\nWe investigate this nonuniformity now.\n\nFirst, we assume that $H:\\braces{0,1}^{*}\\to\\Z_{N}$\nis a random oracle and $p\\in\\braces{1,2,\\cdots,N-1}$.\nWe want to determine how much $H(m)\\mod p$ deviates from uniformity.\nWe restrict ourselves to the case when $p\\nmid N$.\nLet\n\n\\begin{equation}\n    N = qp + r\n\\end{equation}\n\n\\noindent\nwith $0\\le r< p$ and $q\\ge1$.\nBecause $p\\nmid N$, we have $r\\ge1$.\nLet $X$ be uniformly distributed on $\\Z_{N}$ and set $X_{p} = X \\mod p$.\nFurthermore, we let $U_{p}$ be the uniform distribution modulo $p$.\nThen\n\n\\begin{equation}\n    \\mathcal{P}\\parens{X_{p}\\in\\braces{0,\\cdots,r-1}} = \\frac{q+1}{N}\n\\end{equation}\n\n\\noindent\nand\n\n\\begin{equation}\n    \\mathcal{P}\\parens{X_{p}\\in\\braces{r,\\cdots,p-1}} = \\frac{q}{N}.\n\\end{equation}\n\n\\noindent\nHere, $\\mathcal{P}$ denotes the probability of an event occurring.\nWe now determine the deviation of $X_{p}$ from the uniform\ndistribution $U_{p}$:\n\n\\begin{align}\n    \\Delta\\parens{X_{p},U_{p}} &\\equiv\n        \\sum_{k=0}^{p-1} \\abs{\\mathcal{P}(X_{p}=k) - \\mathcal{P}(U_{p}=k)}\n        \\nonumber\\\\\n    &= \\sum_{u=0}^{r-1} \\abs{\\frac{q+1}{N} - \\frac{1}{p}} +\n        \\sum_{u=r}^{p-1} \\abs{\\frac{q}{N} - \\frac{1}{p}} \\nonumber\\\\\n    &= r\\frac{qp + p - N}{pN} + \\parens{p-r}\\frac{N-qp}{pN}\n        \\nonumber\\\\\n    &\\le \\frac{p}{N}.\n\\end{align}\n\n\\noindent\nFrom this, we see that if $p$ is a $k$-bit prime and\n$N = 2^{k+\\ell}$, then the deviation from uniformity is $\\le2^{-\\ell}$.\n\nIn our case, $p$ is a 254-bit prime and we concatenate the output\nof independent hash functions in order to have a uniformly distributed\n512-bit output.\nFrom the above it may be seen that \\textsc{HashToBase} produces outputs whose\ndeviation from uniformity is less than $2^{-258}$.\nThis deviation is sufficiently small as to not be of concern.\nFurther work is required to more formally prove this assumption, but\nthis work is not included at this time.\n\n\n\\subsubsection{Base to $\\G_{1}$}\n\\label{sssec:base-to-G1}\n\nIn this section we discuss the construction of a hash-to-G1 algorithm.\nWe begin by noting the non-surjective nature for many functions\n$f:\\F_{p}\\to E(\\F_{p})$.\nThen, we cite a known solution to this problem and provide necessary\nmathematics to understand the fundamental operation that\novercomes the problem.\nNext, we discuss the actual implementation.\nLastly, we discuss specific exclusion of three points from the allowable\noutputs of this algorithm for security purposes.\n\nLet us now suppose that we have a hash function\n$\\mathfrak{h}:\\braces{0,1}^{*}\\to\\F_{p}$ and a\ndeterministic map $f:\\F_{p}\\to E(\\F_{p})$.\nAs has been previously stated, in many\nsituations~\\cite{icart2009hash,ft2012bnhashtocurve,boneh2019h2cBLS12}\n$f$ is not surjective.\nThat is, there are points on the elliptic curve $E(\\F_{p})$\n(sometimes a nontrivial fraction) which cannot be reached by $f$.\nEven so, if we use domain separation to construct independent hash functions,\n$\\mathfrak{h}_{1}, \\mathfrak{h}_{2}:\\braces{0,1}^{*}\\to\\F$,\nthen\n\n\\begin{equation}\n    F(\\texttt{m}) = f(\\mathfrak{h}_{1}(\\texttt{m}))\n                    + f(\\mathfrak{h}_{2}(\\texttt{m}))\n\\end{equation}\n\n\\noindent\nis indistinguishable from a random oracle on $E(\\F_{p})$\nunder certain restrictions on $f$.\nSee~\\cite{ft2012bnhashtocurve,tibouchi2014elligator} for details.\n\nWe now turn our attention to determining $f:\\F_{p}\\to E(\\F_{p})$.\nFinding a map $f:\\F_{p}\\to E(\\F_{p})$ is involved.\nOur BN curve has the form\n\n\\begin{align}\n    E:y^{2} &= g(x) \\nonumber\\\\\n            &= x^{3} + b.\n\\end{align}\n\n\\noindent\nFrom~\\cite{ft2012bnhashtocurve}, it possible to show there\nare $x_{1},x_{2},x_{3},y\\in\\F_{p}$ such that\n\n\\begin{equation}\n    g(x_{1})g(x_{2})g(x_{3}) = y^{2}.\n\\end{equation}\n\n\\noindent\nWhen $y\\ne0$, quadratic reciprocity implies that $g(x_{i})$ is square\nfor some $i$; that is, for some $i$ we have\n$(x_{i},\\sqrt{g(x_{i})})\\in E(\\F_{p})$.\nFor uniqueness, we choose the smallest $i$.\nWe will use the construction of~\\cite{ft2012bnhashtocurve}\nto determine such points with some modifications based\non work in~\\cite{boneh2019h2cBLS12}.\nThe exact algorithm can be found in Alg.~\\ref{alg:base-to-G1}.\n\nOne of the main difficulties is determining $i$ in such a way\nas to not leak information; because of this, we do not wish to\nrely upon if statements.\nIn~\\cite{ft2012bnhashtocurve}, they suggested the function\n\n\\begin{equation}\n    \\psi(r_{1},r_{2}) = \\brackets{\\parens{r_{1}-1}r_{2}\\mod3} + 1.\n    \\label{eq:ftAB}\n\\end{equation}\n\n\\noindent\nThis function works under the assumption that modular\narithmetic always returns positive integers.\nThis is not always the case in programming languages;\nin particular, it does not hold in \\textsc{Go} (Golang), the language\nwe use to implement these algorithms.\nTo circumvent this, we use the following function,\nwhich is implemented in Line~\\ref{alg_line:new_coef_func}\nof Alg.~\\ref{alg:base-to-G1}:\n\n\\begin{equation}\n    \\parens{r_{1}-1}\\parens{r_{2}-3}/4 + 1.\n    \\label{eq:newAB}\n\\end{equation}\n\nIn~\\cite{ft2012bnhashtocurve}, the authors encountered an issue when $t=0$.\nTheir solution was to define\n\n\\begin{equation}\n    \\textsc{BaseToG1}(0) = \\parens{\\frac{-1+\\sqrt{-3}}{2}, \\sqrt{1+b}}.\n    \\label{eq:baseToG1zero}\n\\end{equation}\n\n\\noindent\nWahby and Boneh~\\cite{boneh2019h2cBLS12} suggest another\nmethod, which we implement, in order to have a more efficient\nalgorithm.\nThis implementation also affords the benefit of not needing to\nhandle the case of $t=0$ separately.\nThis can be seen in Line~\\ref{alg_line:alpha_def}\nof Alg.~\\ref{alg:base-to-G1} where we define $\\alpha$ as the inverse\nof a value which depends on $t\\in\\F_{p}$.\nWhen $t=0$, we compute $\\alpha = 0$\nbecause we compute inversions via exponentiation.\nThus, the computational convention $0^{-1} = 0 \\mod p$ is established.\nThis leads to the same result as in Eq.~\\eqref{eq:baseToG1zero}\nwithout special handling.\n\nWe have cryptographic insecurity when\n$\\textsc{HashToG1}(\\texttt{m}) = g_{1}^{\\alpha}$ for known $\\alpha$.\nNote we briefly switch back to multiplicative notation at this time.\nIn practice, it is likely this insecurity will only be known when\n$\\alpha\\in\\braces{-1,0,1}$ or is sufficiently close to these values.\nWe assume we may not fix simple proximity to these values, and thus only\nexplicitly address the case of $\\alpha\\in\\braces{-1,0,1}$.\nFor clarity, this notation specifies the hash function outputs of\nthe identity element, the generator, or the generator's\ninverse.\nDue to the concerns around the use of these points, we will not allow these\nindividual cases.\nIn order to enforce this requirement we include a\n\\textsc{SafePointCheck} in \\textsc{HashToG1};\nsee Line~\\ref{alg_line:safe_point_check} in Alg.~\\ref{alg:hash-to-G1}.\nThis function checks the point returned from the hash function for\nequivalence with the identity element OR equivalence of the point's\n$x$ coordinate with $1$.\nIf either of these conditions is true, an error is raised.\nAlthough the probability of a hash mapping to these points is small, this\nerror must be handled appropriately to prevent an attacker from causing\nunexpected errors in a remote system due to specially crafted messages.\n\n\n\\subsubsection{Base to $\\G_{2}$}\n\\label{sssec:base-to-G2}\n\nWe now take up the slightly more challenging possibility\nof computing a hash function to $\\G_{2}$.\nFortunately, we may utilize many of\nthe previously described operations.\nThus, we do not repeat those explanations and only discuss\nthose operations that differ.\nWe would like to remind the reader that the results in\nSec.~\\ref{sssec:finite_math_Fp2} allow\nus to compute Legendre symbols and square roots in $\\F_{p^{2}}$.\n\nUsing the derivation of~\\cite[Section 3]{boneh2019h2cBLS12},\nwe set $u_{0}=1$ as in $\\G_{1}$ to obtain\n\n\\begin{align}\n    x_{1} &= \\frac{\\sqrt{-3}-1}{2} - \\frac{t^{2}\\sqrt{-3}}{t^{2}+g'(1)}\n        \\nonumber\\\\\n    x_{2} &= -1 - x_{2} \\nonumber\\\\\n    x_{3} &= 1 - \\frac{\\parens{t^{2}+g'(1)}^{2}}{3t^{2}},\n\\end{align}\n\n\\noindent\nfor $t\\in\\F_{p^{2}}$.\nHere, we have\n\n\\begin{equation}\n    E':y^{2} = g'(x) = x^{3} + b',\n\\end{equation}\n\n\\noindent\nwhere $b' = b/\\xi = 3/\\parens{i+9}$.\nWith this choice, $-g'(1)$ is a residue in $\\F_{p^{2}}$.\nThis ensures that $t\\in\\{0,\\pm\\sqrt{-g'(1)}\\}$\nimplies $x_{1}$ is a valid point on the curve;\nthus, all inputs result in valid outputs.\nSee Alg.~\\ref{alg:base-to-twist} for the algorithm.\nThus, our hash functions to $\\G_{1}$ and $\\G_{2}$ are\nessentially the same.\n\nAt this point, we have successfully mapped into $E'$;\nhowever, our goal is to map into $\\G_{2}$.\nFrom~\\cite{bnCurves}, we know $\\abs{E'(\\F_{p^{2}})} = q\\parens{2p-q}$.\nThis gives a cofactor $r = 2p-q$ because $p\\nmid q$.\nWe take care of this by clearing the cofactor.\nSee Alg.~\\ref{alg:hash-to-G2} for the full hash algorithm.\n\n\\clearpage\n\n\\input{algs/hash_to_G1.tex}\n\n\\input{algs/gfp2_algs.tex}\n\n\\input{algs/hash_to_G2.tex}\n", "meta": {"hexsha": "48b7c50883dfd55a302b18ce814ff134c8a3c375", "size": 19681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/tcrypt_h2c.tex", "max_stars_repo_name": "chgorman/MadNet-Whitepaper", "max_stars_repo_head_hexsha": "a4cd4946db20713aa0573674c6e1fcc17a76a48a", "max_stars_repo_licenses": ["MIT"], "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_h2c.tex", "max_issues_repo_name": "chgorman/MadNet-Whitepaper", "max_issues_repo_head_hexsha": "a4cd4946db20713aa0573674c6e1fcc17a76a48a", "max_issues_repo_licenses": ["MIT"], "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_h2c.tex", "max_forks_repo_name": "chgorman/MadNet-Whitepaper", "max_forks_repo_head_hexsha": "a4cd4946db20713aa0573674c6e1fcc17a76a48a", "max_forks_repo_licenses": ["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.8480769231, "max_line_length": 80, "alphanum_fraction": 0.7304506885, "num_tokens": 5875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6108470749735531}}
{"text": "\\section{SOLVE Operator}\\ttindex{SOLVE}\nSOLVE is an operator for solving one or more simultaneous algebraic\nequations. It is used with the syntax:\n\\begin{verbatim}\n  SOLVE(EXPRN:algebraic[,VAR:kernel|,VARLIST:list of kernels])\n         :list.\n\\end{verbatim}\n{\\tt EXPRN} is of the form {\\tt <expression>} or\n\\{ {\\tt <expression1>},{\\tt <expression2>}, \\dots \\}.  Each expression is an\nalgebraic equation, or is the difference of the two sides of the equation.\nThe second argument is either a kernel or a list of kernels representing\nthe unknowns in the system.  This argument may be omitted if the number of\ndistinct, non-constant, top-level kernels equals the number of unknowns,\nin which case these kernels are presumed to be the unknowns.\n\nFor one equation, {\\tt SOLVE}\\ttindex{SOLVE} recursively uses\nfactorization and decomposition, together with the known inverses of\n{\\tt LOG}, {\\tt SIN}, {\\tt COS}, {\\tt \\verb|^|}, {\\tt ACOS}, {\\tt ASIN}, and\nlinear, quadratic, cubic, quartic, or binomial factors. Solutions\nof equations built with exponentials or logarithms are often\nexpressed in terms of Lambert's {\\tt W} function.\\index{Lambert's W}\nThis function is (partially) implemented in the special functions package.\n\nLinear equations are solved by the multi-step elimination method due to\nBareiss, unless the switch {\\tt CRAMER}\\ttindex{CRAMER} is on, in which\ncase Cramer's method is used.  The Bareiss method is usually more\nefficient unless the system is large and dense.\n\nNon-linear equations are solved using the Groebner basis package.\n\\index{Groebner} Users should note that this can be quite a\ntime consuming process.\n\n{\\it Examples:}\n\\begin{verbatim}\n            solve(log(sin(x+3))^5 = 8,x);\n            solve(a*log(sin(x+3))^5 - b, sin(x+3));\n            solve({a*x+y=3,y=-2},{x,y});\n\\end{verbatim}\n\n{\\tt SOLVE} returns a list of solutions.  If there is one unknown, each\nsolution is an equation for the unknown.  If a complete solution was\nfound, the unknown will appear by itself on the left-hand side of the\nequation.  On the other hand, if the solve package could not find a\nsolution, the ``solution'' will be an equation for the unknown in terms\nof the operator {\\tt ROOT\\_OF}\\ttindex{ROOT\\_OF}. If there\nare several unknowns, each solution will be a list of equations for the\nunknowns.  For example,\n\\begin{verbatim}\n     solve(x^2=1,x);             -> {X=-1,X=1}\n\n     solve(x^7-x^6+x^2=1,x)\n                            6\n            -> {X=ROOT_OF(X_  + X_ + 1,X_,TAG_1),X=1}\n\n     solve({x+3y=7,y-x=1},{x,y}) -> {{X=1,Y=2}}.\n\\end{verbatim}\nThe TAG argument is used to uniquely identify those particular solutions.\nSolution multiplicities are stored in the global variable {\\tt\nROOT\\_MULTIPLICITIES} rather than the solution list.  The value of this\nvariable is a list of the multiplicities of the solutions for the last\ncall of {\\tt SOLVE}. \\ttindex{SOLVE} For example,\n\\begin{verbatim}\n       solve(x^2=2x-1,x); root_multiplicities;\n\\end{verbatim}\ngives the results\n\\begin{verbatim}\n        {X=1}\n\n        {2}\n\\end{verbatim}\n\nIf you want the multiplicities explicitly displayed, the switch\n{\\tt MULTIPLICITIES}\\ttindex{MULTIPLICITIES} can be turned on. For example\n\\begin{verbatim}\n        on multiplicities; solve(x^2=2x-1,x);\n\\end{verbatim}\nyields the result\n\\begin{verbatim}\n        {X=1,X=1}\n\\end{verbatim}\n\n\\subsection{Handling of Undetermined Solutions}\nWhen {\\tt SOLVE} cannot find a solution to an equation, it normally\nreturns an equation for the relevant indeterminates in terms of the\noperator {\\tt ROOT\\_OF}.\\ttindex{ROOT\\_OF}  For example, the expression\n\\begin{verbatim}\n        solve(cos(x) + log(x),x);\n\\end{verbatim}\nreturns the result\n\\begin{verbatim}\n       {X=ROOT_OF(COS(X_) + LOG(X_),X_,TAG_1)} .\n\\end{verbatim}\n\nAn expression with a top-level {\\tt ROOT\\_OF} operator is implicitly a\nlist with an unknown number of elements (since we don't always know how\nmany solutions an equation has).  If a substitution is made into such an\nexpression, closed form solutions can emerge.  If this occurs, the {\\tt\nROOT\\_OF} construct is replaced by an operator {\\tt ONE\\_OF}.\\ttindex{ONE\\_OF}\nAt this point it is of course possible to transform the result of the\noriginal {\\tt SOLVE} operator expression into a standard {\\tt SOLVE}\nsolution.  To effect this, the operator {\\tt EXPAND\\_CASES}\n\\ttindex{EXPAND\\_CASES} can be used.\n\nThe following example shows the use of these facilities:\n\\extendedmanual{\\newpage}\n\\begin{verbatim}\nsolve(-a*x^3+a*x^2+x^4-x^3-4*x^2+4,x);\n              2     3\n{X=ROOT_OF(A*X_  - X_  + 4*X_ + 4,X_,TAG_2),X=1}\n\nsub(a=-1,ws);\n\n{X=ONE_OF({2,-1,-2},TAG_2),X=1}\n\nexpand_cases ws;\n\n{X=2,X=-1,X=-2,X=1}\n\\end{verbatim}\n\n\\subsection{Solutions of Equations Involving Cubics and Quartics}\n\nSince roots of cubics and quartics can often be very messy, a switch\n{\\tt FULLROOTS}\\ttindex{FULLROOTS} is available, that, when off (the\ndefault), will prevent the production of a result in closed form.  The\n{\\tt ROOT\\_OF} construct will be used in this case instead.\n\nIn constructing the solutions of cubics and quartics, trigonometrical\nforms are used where appropriate.  This option is under the control of a\nswitch {\\tt TRIGFORM},\\ttindex{TRIGFORM} which is normally on.\n\nThe following example illustrates the use of these facilities:\n\\begin{verbatim}\nlet xx = solve(x^3+x+1,x);\n\nxx;\n             3\n{X=ROOT_OF(X_  + X_ + 1,X_)}\n\non fullroots;\n\nxx;\n\n                           - SQRT(31)*I\n                    ATAN(---------------)\n                            3*SQRT(3)\n{X=(I*(SQRT(3)*SIN(-----------------------)\n                              3\n\\end{verbatim}\n\\newpage\n\\begin{verbatim}\n                      - SQRT(31)*I\n               ATAN(---------------)\n                       3*SQRT(3)\n        - COS(-----------------------)))/SQRT(3),\n                         3\n\n                              - SQRT(31)*I\n                       ATAN(---------------)\n                               3*SQRT(3)\n X=( - I*(SQRT(3)*SIN(-----------------------)\n                                 3\n\n                         - SQRT(31)*I\n                  ATAN(---------------)\n                          3*SQRT(3)\n           + COS(-----------------------)))/SQRT(\n                            3\n\n      3),\n\n                  - SQRT(31)*I\n           ATAN(---------------)\n                   3*SQRT(3)\n    2*COS(-----------------------)*I\n                     3\n X=----------------------------------}\n                SQRT(3)\n\noff trigform;\n\nxx;\n                             2/3\n{X=( - (SQRT(31) - 3*SQRT(3))   *SQRT(3)*I\n\n                             2/3    2/3\n     - (SQRT(31) - 3*SQRT(3))    - 2   *SQRT(3)*I\n\n        2/3                           1/3  1/3\n     + 2   )/(2*(SQRT(31) - 3*SQRT(3))   *6\n\n                1/6\n              *3   ),\n\n                          2/3\n X=((SQRT(31) - 3*SQRT(3))   *SQRT(3)*I\n\n                             2/3    2/3\n     - (SQRT(31) - 3*SQRT(3))    + 2   *SQRT(3)*I\n\n        2/3                           1/3  1/3\n     + 2   )/(2*(SQRT(31) - 3*SQRT(3))   *6\n\n                1/6\n              *3   ),\n\n                           2/3    2/3\n     (SQRT(31) - 3*SQRT(3))    - 2\n X=-------------------------------------}\n                          1/3  1/3  1/6\n    (SQRT(31) - 3*SQRT(3))   *6   *3\n\\end{verbatim}\n\n\\subsection{Other Options}\n\nIf {\\tt SOLVESINGULAR}\\ttindex{SOLVESINGULAR} is on (the default setting),\ndegenerate systems such as {\\tt x+y=0}, {\\tt 2x+2y=0} will be solved by\nintroducing appropriate arbitrary constants.\nThe consistent singular equation 0=0 or equations involving functions with\nmultiple inverses may introduce unique new indeterminant kernels\n{\\tt ARBCOMPLEX(j)}, or {\\tt ARBINT(j)}, ($j$=1,2,...),  % {\\tt ARBREAL(j)},\nrepresenting arbitrary complex or integer numbers respectively.  To\nautomatically select the principal branches, do {\\tt off allbranch;} .\n\\ttindex{ALLBRANCH} To avoid the introduction of new indeterminant kernels\ndo {\\tt OFF ARBVARS}\\ttindex{ARBVARS} -- then no equations are generated for the free\nvariables and their original names are used to express the solution forms.\nTo suppress solutions of consistent singular equations do\n{\\tt OFF SOLVESINGULAR}.\n\nTo incorporate additional inverse functions do, for example:\n\\begin{verbatim}\n        put('sinh,'inverse,'asinh);\n        put('asinh,'inverse,'sinh);\n\\end{verbatim}\ntogether with any desired simplification rules such as\n\\begin{verbatim}\n        for all x let sinh(asinh(x))=x, asinh(sinh(x))=x;\n\\end{verbatim}\nFor completeness, functions with non-unique inverses should be treated as\n{\\tt \\verb|^|}, {\\tt SIN}, and {\\tt COS} are in the {\\tt SOLVE}\n\\ttindex{SOLVE} module source.\n\nArguments of {\\tt ASIN} and {\\tt ACOS} are not checked to ensure that the\nabsolute value of the real part does not exceed 1; and arguments of\n{\\tt LOG} are not checked to  ensure that the absolute value of the imaginary\npart does not exceed $\\pi$; but checks (perhaps involving user response\nfor non-numerical arguments) could be introduced using\n{\\tt LET}\\ttindex{LET} statements for these operators.\n\n\\subsection{Parameters and Variable Dependency}\n\nThe proper design of a variable sequence\nsupplied as a second argument to {\\tt SOLVE} is important\nfor the structure of the solution of an equation system.\nAny unknown in the system\nnot in this list is considered totally free. E.g.\\  the call\n\\begin{verbatim}\n    solve({x=2*z,z=2*y},{z});\n\\end{verbatim}\nproduces an empty list as a result because there is no function\n$z=z(x,y)$ which fulfills both equations for arbitrary $x$ and $y$ values.\nIn such a case the share variable {\\tt requirements}\\ttindex{requirements}\ndisplays a set of restrictions for the parameters of the system:\n\\begin{verbatim}\n    requirements;\n\n    {x - 4*y}\n\\end{verbatim}\nThe non-existence of a formal solution is caused by a \ncontradiction which disappears only if the parameters\nof the initial system are set such that all members\nof the requirements list take the value zero.\nFor a linear system the set is complete: a solution\nof the requirements list makes the initial\nsystem solvable. E.g.\\  in the above case a substitution\n$x=4y$ makes the equation set consistent. For a non-linear\nsystem only one inconsistency is detected. If such a system\nhas more than one inconsistency, you must reduce them\none after the other. \n\\footnote{\nThe difference between linear and non--linear\ninconsistent systems is based on the algorithms which\nproduce this information as a side effect when attempting\nto find a formal solution; example:\n$solve(\\{x=a,x=b,y=c,y=d\\},\\{x,y\\}$ gives a set $\\{a-b,c-d\\}$\nwhile $solve(\\{x^2=a,x^2=b,y^2=c,y^2=d\\},\\{x,y\\}$ leads to $\\{a-b\\}$.\n}\nThe  set shows you also the dependency among the parameters: here\none of $x$ and $y$ is free and a formal solution of the system can be\ncomputed by adding it to the variable list of {\\tt solve}. \nThe requirement set is not unique -- there may be other such sets.\n\n\nA system  with parameters may have a formal solution, e.g.\\\n\\begin{verbatim}\n     solve({x=a*z+1,0=b*z-y},{z,x});\n\n        y     a*y + b\n   {{z=---,x=---------}}\n        b        b\n\\end{verbatim}\nwhich is not valid for all possible values of the parameters.\nThe variable {\\tt assumptions}\\ttindex{assumptions} contains then a list of\nrestrictions: the solutions are valid only as long\nas none of these expressions vanishes. Any zero of one of them\nrepresents a special case that is not covered by the\nformal solution. In the above case the value is\n\\extendedmanual{\\newpage}\n\\begin{verbatim}\n    assumptions;\n\n    {b}\n\\end{verbatim}\nwhich excludes formally the case $b=0$; obviously this special \nparameter value makes the system singular. The set of assumptions\nis complete for both, linear and non--linear systems.\n    \n\n{\\tt SOLVE} rearranges the variable sequence\nto reduce the (expected) computing time. This behavior is controlled\nby the switch {\\tt varopt}\\ttindex{varopt}, which is on by default.\nIf it is turned off, the supplied variable sequence is used\nor the system kernel ordering is taken if the variable\nlist is omitted. The effect is demonstrated by an example:\n\\begin{verbatim}\n   s:= {y^3+3x=0,x^2+y^2=1};\n\n   solve(s,{y,x});\n\n                  6       2\n   {{y=root_of(y_  + 9*y_  - 9,y_),\n\n            3\n         - y\n     x=-------}}\n          3\n \n   off varopt; solve(s,{y,x});\n\n                  6       4        2\n   {{x=root_of(x_  - 3*x_  + 12*x_  - 1,x_),\n\n               4      2\n        x*( - x  + 2*x  - 10)\n     y=-----------------------}}\n                  3\n\n\\end{verbatim}\nIn the first case, {\\tt solve} forms the solution as a set of\npairs $(y_i,x(y_i))$ because the degree of $x$ is higher -- \nsuch a rearrangement makes the internal computation of the Gr\\\"obner basis\ngenerally faster. For the second case the explicitly given variable sequence\nis used such that the solution has now the form $(x_i,y(x_i))$.\nControlling the variable sequence is especially important if\nthe system has one or more free variables.\nAs an alternative to turning off {\\tt varopt}, a partial dependency among\nthe variables can be declared using the {\\tt depend}\\index{depend}\nstatement: {\\tt solve} then rearranges the variable sequence but keeps any\nvariable ahead of those on which it depends.\n\\extendedmanual{\\newpage}\n\\begin{verbatim}\n   on varopt;\n   s:={a^3+b,b^2+c}$\n   solve(s,{a,b,c});\n\n                           3       6\n   {{a=arbcomplex(1),b= - a ,c= - a }}\n\n   depend a,c; depend b,c; solve(s,{a,b,c});\n\n   {{c=arbcomplex(2),\n\n                 6\n     a=root_of(a_  + c,a_),\n\n           3\n     b= - a }}\n\\end{verbatim}\nHere {\\tt solve} is forced to put $c$ after $a$ and after $b$, but\nthere is no obstacle to interchanging $a$ and $b$.\n\n", "meta": {"hexsha": "e9543d7154745faa4a29dc891f9aa331b5bc5835", "size": 13682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "atomic_Decomp/Redlog/reduce.doc/solve.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/solve.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/solve.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": 35.9107611549, "max_line_length": 85, "alphanum_fraction": 0.6385762315, "num_tokens": 3798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835534888478, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6107874239778122}}
{"text": "\n\\begin{questions}\n\n\\question{ Modify the code \\texttt{fluidflowFD.m} to solve the equations\n\\begin{align*}\n w_t + \\psi_y w_x - \\psi_xw_y &= Pr \\Delta w + RaPrT_x, \\\\\n T_t + \\psi_y T_x - \\psi_xT_y &= \\Delta T, \\\\\n\\Delta \\psi &= -w,\n\\end{align*}\nwhere $(x,y) \\in (0,1) \\times (0,1)$ and $t>0$. For this exercise, set $Ra = 2 \\times 10^5$ and $Pr = 0.71$ (air).\n\nThe fluid is at rest at $t=0$, with $T = \\psi = w = 0$. The boundary conditions for the stream function is $\\psi_{Gamma} = 0$, which implies that there is no mass transfer through the boundary $\\Gamma$. The value of the vorticity at the walls is expressed as $w_{\\Gamma} = -\\Delta \\psi_{\\Gamma}$ and the temperature at $\\Gamma$ is defined by\n\\begin{align*}\nT(t,x,y) = \\begin{cases}\n2^9\\tanh^4(100t)x^5(x-1)^4,& y =0,~0\\leq x \\leq 1,~t>0, \\\\\n0, & (x,y) \\in \\Gamma,~y\\neq 0,~t>0.\n\\end{cases}\n\\end{align*}\n\n}\n\n\\begin{solution}\n\n\\begin{figure}[H]\n\\center{\\includegraphics[scale=.5]{p4_f1.eps}}\n\\caption{Solution at $ t=1$ second}\n\\end{figure}\n\n\\end{solution}\n\n\\end{questions}\n\n\\subsubsection*{MATLAB}\n\n   \\begin{verbatim}\nfunction HW6P4\n% Parameters\nN = 150;\nRa = 2e5;\nPr = 0.71;\ndt = 1e-5;\n\n\nh = 1/N; % N+1 points in each direction\n[xx,yy] = meshgrid(0:h:1); % 2D gridpoints\n\n% Laplacian with zero BCs\no = ones(N-1,1);\nD2 = (diag(-2*o) + diag(o(1:N-2),-1)+ diag(o(1:N-2),1))/h^2;\n% We need evals and evects to solve Poisson equation\n[eV,eval] = eig(D2); lam = diag(eval);\n\n% Initial condition & pre-allocate memory (start with zeros at t = 0)\nu = 0*xx; v = u; w = u; str = u; T = u;\n\n% boundary condition\n%u(N+1,:) = 1;\nii = 2:N; jj = 2:N;  % index for interior nodes\nwi = zeros(N-1,N-1); % interior values of vorticity\nTi = zeros(N-1,N-1); % interior values of temperature\n\ncount = 0;\nt = 0;\nNplot = round(0.1/dt);\n% main loop\nwhile t<50\n    if mod(count,1000) == 0\n        sprintf('%d -- %f -- %f -- %f -- %f',count,t,norm(str,inf),...\n            norm(w,inf),norm(T,inf));\n    end\n\n   % update temperature at boundary\n   T = BCT(T,xx,t);\n\n    % update vorticity at boundary\n   w = BCw(u,v,w);\n\n   % advance temperature with forward Euler\n   [Trh,Tx] = Trhs(u,v,T);\n   Ti = Ti + dt*Trh;\n   T(ii,jj) = Ti;\n\n   % advance vorticity with forward Euler\n   wi = wi + dt*wrhs(u,v,w,Pr,Ra,Tx);\n   w(ii,jj) = wi;\n\n\n   % compute stream function with conjugate gradient\n   str(2:end-1,2:end-1) = SolvePoisson(wi);\n\n   % update velocity (interior nodes only)\n   u(ii,jj) =  (str(ii+1,jj)-str(ii-1,jj))/(2*h);\n   v(ii,jj) = -(str(ii,jj+1)-str(ii,jj-1))/(2*h);\n\n   t = t+dt;\n   count = count + 1;\n\n   % Plot results every now and then\n   if count == Nplot\n       plotresults(u,v,w,T,str);\n       shg\n       count = 0;\n       disp(t)\n       sprintf('%f -- %f -- %f',norm(T,inf),norm(w,inf),norm(str,inf));\n   end\n\nend\n\n    % Solve Poisson equation (Sylvester equation)\n    function S = SolvePoisson(wi)\n        ff = -eV'*wi*eV;\n        S = ff;\n        for j = 1:N-1\n            S(:,j) = ff(:,j)./(lam(j)+lam);\n        end\n        S = eV*S*eV';\n    end\n\n    % Right-hand side of vorticity equation\n    function wrh = wrhs(u,v,w,Pr,Ra,Tx)\n        wx = (w(ii,jj+1)-w(ii,jj-1))/(2*h);\n        wy = (w(ii+1,jj)-w(ii-1,jj))/(2*h);\n        Lw = (w(ii,jj+1)+w(ii,jj-1)+w(ii+1,jj)+w(ii-1,jj)-4*w(ii,jj))/h^2;\n        wrh = -u(ii,jj).*wx - v(ii,jj).*wy + (Pr)*Lw + Ra*Pr*Tx;\n    end\n\n % Right-hand side of Temperature equation\n    function [Trh,Tx] = Trhs(u,v,T)\n        Tx = (T(ii,jj+1)-T(ii,jj-1))/(2*h);\n        Ty = (T(ii+1,jj)-T(ii-1,jj))/(2*h);\n        LT = (T(ii,jj+1)+T(ii,jj-1)+T(ii+1,jj)+T(ii-1,jj)-4*T(ii,jj))/h^2;\n        Trh = -u(ii,jj).*Tx - v(ii,jj).*Ty + LT;\n    end\n\n   function w = BCw(u,v,w)\n        % three point sided FD formula (second order accurate)\n        w(1,:) = -(-3*u(1,:)+4*u(2,:)-u(3,:))/(2*h);      % = -u_y @ y = 0\n        w(N+1,:) = (-3*u(N+1,:)+4*u(N,:)-u(N-1,:))/(2*h); % = -u_y @ y = 1\n        w(:,1) = (-3*v(:,1)+4*v(:,2)-v(:,3))/(2*h);       % =  v_x @ x = 0\n        w(:,N+1) = -(-3*v(:,N+1)+4*v(:,N)-v(:,N-1))/(2*h);% =  v_x @ x = 1\n    end\n % Enforce boundary condition (Temperature)\n    function T = BCT(T,xx,t)\n        %T0 = @(x,y,t) 2^9 * tanh(100*t)^4 * x.^5 .* (x-1).^4 .* (y==0);\n        %T(1,:) = T0(x(1,:),y(1,:),t);\n        T(1,:) = 2^9*(tanh(100*t))^4*(xx(1,:).^5).*(xx(1,:)-1).^4;\n        %T(N+1,:) = 0;\n        %T(:,1) = 0;\n        %T(:,N+1) = 0;\n    end\n\n    % Plot results\n    function plotresults(u,v,w,T,str)\n       % Use a subset of gridpoints\n       ip = 1:3:N+1;\n       up = u(ip,ip); vp = v(ip,ip);\n       xp = xx(ip,ip); yp = yy(ip,ip);\n\n       % Velocity\n       subplot(2,2,1)\n       quiver(xp,yp,up,vp,10)\n       axis([0 1 0 1]), axis square\n       title('velocity field','fontsize',16)\n\n       % Temperature\n       subplot(2,2,2)\n       contourf(xx,yy,T);\n       H = colorbar; set(H,'fontsize',16)\n       axis square, title('Temperature','fontsize',16)\n\n       % Stream function\n       subplot(2,2,3)\n       mp = max(max(str));\n       mm = min(min(str));\n       contour(xx,yy,str,-logspace(-10,log10(-mm),30),'r'),  hold on\n       contour(xx,yy,str, logspace(-10,log10(mp),20),'k'),   hold off\n       axis square, title('streamlines (logscale)','fontsize',16)\n\n       % Vorticity\n       subplot(2,2,4)\n       logw = log10(abs(w));    logw(abs(w)==0) = nan;\n       contourf(xx,yy,logw,-3:0.5:2),\n       H = colorbar; set(H,'fontsize',16)\n       set(gca,'position',[0.5703 0.1100 0.3347 0.3412])\n       axis square, title('vorticity (log(abs(w))','fontsize',16)\n       drawnow\n\n    end\nend\n\\end{verbatim}", "meta": {"hexsha": "d5c0f0ac34ff9c3de93a7e7e4bfcbeff34008eab", "size": 5503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/texfiles/problem4.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 6/Latex/texfiles/problem4.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 6/Latex/texfiles/problem4.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": 28.9631578947, "max_line_length": 341, "alphanum_fraction": 0.5340723242, "num_tokens": 2111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6107845315981683}}
{"text": "\n\\section{Bound-Preserving Methods Using First-Order DG Scheme}\n\n\\subsection{Cartesian Coordinates}\nThis section closely follows \\citet{Qin2016}.\n\n\\subsubsection{Set of Admissible States}\nWe consider a one-dimensional system of conservation laws:\n\\begin{equation}\n    \\pd{\\,\\bU}{t} + \\pd{\\,\\bF\\left(\\bU\\right)}{x} = \\vect{0},\n\\end{equation}\nwhere $\\bU$ is a vector of conserved variables, defined as:\n\\begin{equation}\\label{Eq:ConservedVariables}\n    \\bU\\longrightarrow\\begin{pmatrix} D\\\\ S\\\\ \\tau\\end{pmatrix}=\\begin{pmatrix} \\rho\\,W\\\\ \\rho\\,h\\,W^{2}\\,v\\\\ \\rho\\,W\\left(h\\,W-1\\right)-p\\end{pmatrix},\n\\end{equation}\nand $\\bF\\left(\\bU\\right)$ are the fluxes of those conserved quantities:\n\\begin{equation}\\label{Eq:FluxVector}\n    \\bF\\left(\\bU\\right)\\longrightarrow\\begin{pmatrix}\\rho\\,W\\,v\\\\ \\rho\\,h\\,W^{2}\\,v^{2}+p\\\\\\rho\\,h\\,W^{2}\\,v-D\\,v\\end{pmatrix}.\n\\end{equation}\n\n\nThe physics leads us to define a set of admissible states, $\\cG_{p}$ (the subscript $p$ stands for primitive), as:\n\\begin{equation}\n    \\cG_{p}\\equiv\\left\\{\\bU\\Big|\\rho>0,\\,p>0,\\,v^{2}<1\\right\\}.\n\\end{equation}\n\nIt is shown in \\citet{Mignone2005} that $\\cG$ is a convex set\\footnote{Convex in the sense that if $\\bU_{1}\\in\\cG$ and $\\bU_{2}\\in\\cG$, then $\\alpha_{1}\\,\\bU_{1}+\\alpha_{2}\\,\\bU_{2}\\in\\cG$, where $\\alpha_{1},\\,\\alpha_{2}\\in\\left[0,1\\right]$ and $\\alpha_{1}+\\alpha_{2}=1$.} and can equivalently be written in terms of the conserved variables as:\n\\begin{equation}\\label{Eq:SetOfAdmissibleStates}\n    \\cG\\equiv\\left\\{\\bU\\Big|D>0,\\,\\tau+D>\\sqrt{D^{2}+S^{2}}\\right\\}.\n\\end{equation}\n\n\\subsubsection{Time-Step Derivation/CFL Condition}\nFor the first-order DG method using forward-Euler time-stepping, we evolve the vector of conserved variables as:\n\\begin{equation}\\label{Eq:1stOrderDG}\n    \\ol{\\bU}^{n+1}_{i}=\\ol{\\bU}^{n}_{i}-\\eta_{i}\\left[\\hat{\\bF}\\left(\\ol{\\bU}^{n}_{i},\\ol{\\bU}^{n}_{i+1}\\right)-\\hat{\\bF}\\left(\\ol{\\bU}^{n}_{i-1},\\ol{\\bU}^{n}_{i}\\right)\\right],\n\\end{equation}\nwhere\n\\begin{equation}\n    \\ol{\\bU}_{i}\\equiv\\f{1}{\\Delta x_{i}}\\int_{x_{\\imh}}^{x_{\\iph}}\\bU_{i}\\,dx,\n\\end{equation}\n$\\eta_{i}\\equiv\\Delta t_{i}/\\Delta x_{i}$, and $\\hat{\\bF}$ is the numerical flux. In this document we use the local Lax-Friedrichs flux, defined as:\n\\begin{equation}\\label{Eq:LLF}\n    \\hat{\\bF}\\left(a,b\\right)=\\f{1}{2}\\left[\\bF\\left(a\\right)+\\bF\\left(b\\right) - \\alpha_{ab}\\left(b-a\\right)\\right],\n\\end{equation}\nwhere $a$ and $b$ represent the state of the fluid in two different elements, $\\alpha_{ab}$ is an estimate for the wave-speed:\n\\begin{equation}\n    \\alpha_{ab}=\\text{max}\\left[\\alpha\\left(a\\right),\\alpha\\left(b\\right)\\right],\n\\end{equation}\nand $\\alpha$ is the largest (in absolute value) eigenvalue of the flux-Jacobian:\n\\begin{equation}\n    \\alpha=\\left|\\left|\\pderiv{\\bF}{\\bU}\\right|\\right|.\n\\end{equation}\nUsing this we define the following variables:\n\\begin{equation}\\label{Eq:EigVals}\n    \\alpha_{\\iph}=\\text{max}\\left[\\alpha\\left(\\ol{\\bU}_{i}\\right),\\alpha\\left(\\ol{\\bU}_{i+1}\\right)\\right],\\hspace{3em} \\alpha_{\\imh}=\\text{max}\\left[\\alpha\\left(\\ol{\\bU}_{i-1}\\right),\\alpha\\left(\\ol{\\bU}_{i}\\right)\\right].\n\\end{equation}\n\nSubstituting \\eqref{Eq:LLF} with \\eqref{Eq:EigVals} into \\eqref{Eq:1stOrderDG}:\n\\begin{align}\n    \\ol{\\bU}^{n+1}_{i}&=\\ol{\\bU}^{n}_{i}-\\f{\\eta_{i}}{2}\\left[\\bF\\left(\\ol{\\bU}^{n}_{i}\\right)+\\bF\\left(\\ol{\\bU}^{n}_{i+1}\\right)-\\alpha_{\\iph}\\left(\\ol{\\bU}^{n}_{i+1}-\\ol{\\bU}^{n}_{i}\\right)\\right.\\nonumber\\\\\n    &\\left.\\hspace{7em}-\\bF\\left(\\ol{\\bU}^{n}_{i}\\right)-\\bF\\left(\\ol{\\bU}^{n}_{i-1}\\right)+\\alpha_{\\imh}\\left(\\ol{\\bU}^{n}_{i}-\\ol{\\bU}^{n}_{i-1}\\right)\\right]\\nonumber\\\\\n    &=\\left[1-\\f{\\eta_{i}}{2}\\left(\\alpha_{\\iph}+\\alpha_{\\imh}\\right)\\right]\\ol{\\bU}^{n}_{i}+\\f{\\eta_{i}}{2}\\,\\alpha_{\\iph}\\left[\\ol{\\bU}^{n}_{i+1}-\\f{1}{\\alpha_{\\iph}}\\bF\\left(\\ol{\\bU}^{n}_{i+1}\\right)\\right]\\nonumber\\\\\n    &\\hspace{15em}+\\f{\\eta_{i}}{2}\\,\\alpha_{\\imh}\\left[\\ol{\\bU}^{n}_{i-1}+\\f{1}{\\alpha_{\\imh}}\\bF\\left(\\ol{\\bU}^{n}_{i-1}\\right)\\right]\\nonumber\\\\\n    &=\\left[1-\\f{\\eta_{i}}{2}\\left(\\alpha_{\\iph}+\\alpha_{\\imh}\\right)\\right]\\ol{\\bU}^{n}_{i}+\\f{\\eta_{i}}{2}\\,\\alpha_{\\iph}\\,\\ol{\\bH}^{-}\\left(\\ol{\\bU}^{n}_{i+1},\\alpha_{\\iph}\\right)+\\f{\\eta_{i}}{2}\\,\\alpha_{\\iph}\\,\\ol{\\bH}^{+}\\left(\\ol{\\bU}^{n}_{i-1},\\alpha_{\\imh}\\right),\\label{Eq:ConvComb}\n\\end{align}\nwhere\n\\begin{equation}\\label{Eq:Hpm}\n    \\ol{\\bH}^{\\pm}\\left(\\ol{\\bU},\\alpha\\right)\\equiv\\ol{\\bU}\\pm\\f{1}{\\alpha}\\,\\bF\\left(\\ol{\\bU}\\right).\n\\end{equation}\n\nThe proof that $\\ol{\\bH}^{\\pm}\\in\\cG$ is given in \\citet{Qin2016}. Therefore, we see that with a restriction on $\\alpha_{i\\pm\\f{1}{2}}$ that \\eqref{Eq:ConvComb} is a convex combination. The restriction is (recalling that $\\eta_{i}=\\Delta t_{i}/\\Delta x_{i}$):\n\\begin{equation}\n    1-\\f{\\eta_{i}}{2}\\left(\\alpha_{\\iph}+\\alpha_{\\imh}\\right)>0\\implies\\f{\\eta_{i}}{2}\\left(\\alpha_{\\iph}+\\alpha_{\\imh}\\right)<1\\implies \\Delta t_{i}<\\f{2\\,\\Delta x_{i}}{\\alpha_{\\iph}+\\alpha_{\\imh}}\\leq\\f{\\Delta x_{i}}{\\text{max}\\left(\\alpha_{i\\pm\\f{1}{2}}\\right)}.\n\\end{equation}\n\nWe want a time-step that is the same for all elements at a given time, so we tighten the restriction to:\n\\begin{equation}\n    \\Delta t<\\text{min}_{i}\\left(\\f{\\Delta x_{i}}{\\text{max}\\left(\\alpha_{i\\pm\\f{1}{2}}\\right)}\\right)=\\f{\\Delta x}{\\text{max}_{i}\\left(\\alpha_{i\\pm\\f{1}{2}}\\right)},\n\\end{equation}\nwhere the equality follows for a uniform mesh, i.e. $\\Delta x_{i}=\\Delta x\\,\\forall i$.\n\n\\newpage\n\n\n\\subsection{Curvilinear Coordinates in 1-D}\nNOTE: We assume a conformally-flat, time-independent spatial three-metric:\n\\begin{equation}\n    \\gamma_{ij}\\left(x^{k},t\\right)\\longrightarrow\\psi^{4}\\left(x^{k}\\right)\\,\\ol{\\gamma_{ii}}\\left(x^{k}\\right),\n\\end{equation}\nwhere $\\psi\\left(x^{k}\\right)$ is the conformal factor and $\\ol{\\gamma}_{ii}$ is the flat-space metric.\n\n\\subsubsection{Set of Admissible States}\nWe again consider a one-dimensional system of conservation laws, but this time with a curvilinear metric:\n\\begin{equation}\\label{Eq:1DCurvilinearConsLaw}\n    \\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}+\\pd{\\left(\\sqrtgm\\,\\bF^{i}\\right)}{i}=\\sqrtgm\\,\\bQ,\\hspace{1em}\\text{(no sum on $i$)},\n\\end{equation}\nwhere $\\bU$ is given by:\n\\begin{equation}\n    \\bU\\longrightarrow\\begin{pmatrix} D\\\\ S_{j}\\\\ \\tau\\end{pmatrix}=\\begin{pmatrix} \\rho\\,W\\\\ \\rho\\,h\\,W^{2}\\,v_{j}\\\\ \\rho\\,W\\left(h\\,W-1\\right)-p\\end{pmatrix}=\\begin{pmatrix} \\rho\\,W\\\\ \\rho\\,h\\,W^{2}\\,\\gamma_{jk}\\,v^{k}\\\\ \\rho\\,W\\left(h\\,W-1\\right)-p\\end{pmatrix},\n\\end{equation}\n$\\bF^{i}\\left(\\bU\\right)$ are the fluxes in the $x^{i}$-direction of those conserved quantities:\n\\begin{equation}\n    \\bF^{i}\\left(\\bU\\right)\\longrightarrow\\begin{pmatrix}D\\,v^{i}\\\\ S^{i}\\,v_{j}+p\\,\\delta^{i}_{~j}\\\\ S^{i}-D\\,v^{i}\\end{pmatrix}=\\begin{pmatrix}\\rho\\,W\\,v^{i}\\\\ \\rho\\,h\\,W^{2}\\,v^{i}\\,v_{j}+p\\,\\delta^{i}_{~j}\\\\\\rho\\,h\\,W^{2}\\,v^{i}-D\\,v^{i}\\end{pmatrix}=\\begin{pmatrix}\\rho\\,W\\,v^{i}\\\\ \\rho\\,h\\,W^{2}\\,\\gamma_{jk}\\,v^{i}\\,v^{k}+p\\,\\delta^{i}_{~j}\\\\\\rho\\,h\\,W^{2}\\,v^{i}-D\\,v^{i}\\end{pmatrix},\n\\end{equation}\nand $\\bQ$ is a source term:\n\\begin{align}\n    \\bQ\\longrightarrow\\begin{pmatrix}0\\\\\\f{1}{2}\\,P^{ik}\\,\\pd{\\,\\gamma_{ik}}{j}\\\\0\\end{pmatrix}&=\\begin{pmatrix}0\\\\ \\f{1}{2}\\left[P^{11}\\,\\pd{\\,\\gamma_{11}}{j}+P^{22}\\,\\pd{\\,\\gamma_{22}}{j}+P^{33}\\,\\pd{\\,\\gamma_{33}}{j}\\right] \\\\0\\end{pmatrix}\\\\\n    &=\\begin{pmatrix}0\\\\ P^{11}\\,h_{1}\\,\\pd{\\,h_{1}}{j}+P^{22}\\,h_{2}\\,\\pd{\\,h_{2}}{j}+P^{33}\\,h_{3}\\,\\pd{\\,h_{3}}{j} \\\\0\\end{pmatrix},\n\\end{align}\nwhere we have used the fact that $\\gamma_{kk}=\\left(h_{k}\\right)^{2}$. The $P^{ik}$ are components of the pressure tensor:\n\\begin{equation}\n    P^{ik}=S^{i}\\,v^{k}+p\\,\\gamma^{ik}=\\gamma^{i\\ell}\\,S_{\\ell}\\,v^{k}+p\\,\\gamma^{ik}=\\gamma^{i\\ell}\\,S_{\\ell}\\,v^{k}+p\\,\\gamma^{i\\ell}\\,\\delta^{k}_{~\\ell}=\\gamma^{i\\ell}\\left(S_{\\ell}\\,v^{k}+p\\,\\delta^{k}_{~\\ell}\\right).\n\\end{equation}\nSince the spatial three-metric is diagonal the only non-zero term is that with $\\ell=i$. We can therefore simplify further:\n\\begin{equation}\n    P^{ik}=\\gamma^{ii}\\left(S_{i}\\,v^{k}+p\\,\\delta^{k}_{~i}\\right)=\\f{1}{\\gamma_{ii}}\\,\\left(S_{i}\\,v^{k}+p\\,\\delta^{k}_{~i}\\right),\\hspace{1em}\\text{(no sum on $i$)}.\n\\end{equation}\nFor the source-term sum we then have:\n\\begin{equation}\\label{Eq:PressureTensorSum}\n    Q_{j}=\\f{1}{2}\\,P^{ik}\\,\\p_{j}\\,\\gamma_{ik}=\\f{1}{2}\\,P^{kk}\\,\\p_{j}\\,\\gamma_{kk}=\\f{1}{2}\\,P^{kk}\\,\\p_{j}\\left(h_{k}\\right)^{2}=P^{kk}\\,h_{k}\\,\\p_{j}\\,h_{k}.\n\\end{equation}\n\nThese definitions lead us to define the same set of admissible states as before, namely:\n\\begin{equation}\n    \\cG_{p}\\equiv\\left\\{\\bU\\Big|\\rho>0,\\,p>0,\\,v^{2}<1\\right\\},\n\\end{equation}\nthe only difference being that $v^{2}$ now involves the metric:\n\\begin{equation}\n    v^{2}=v^{j}\\,v_{j}=\\gamma_{kj}\\,v^{k}\\,v^{j}.\n\\end{equation}\n\nBefore continuing, we show that the introduction of the metric doesn't affect the translation between $\\cG_{p}$ and $\\cG$...\\sd{I've shown this, just need to TeX it up}\n\n\\subsubsection{Time-Step Derivation/CFL Condition}\nWe start by integrating both sides of \\eqref{Eq:1DCurvilinearConsLaw} over $dx^{i}$ and dividing by the volume of the $K^{th}$ element, $\\Delta V_{K}$ (recalling that there is no sum on $i$):\n\\begin{equation}\n    \\f{1}{\\Delta V_{K}}\\int_{x^{i}_{L}}^{x^{i}_{H}}\\pd{\\left(\\sqrtgm\\,\\bU\\right)}{t}dx^{i}+\\f{1}{\\Delta V_{K}}\\int_{x^{i}_{L}}^{x^{i}_{H}}\\pd{\\left(\\sqrtgm\\,\\bF^{i}\\left(\\bU\\right)\\right)}{i}dx^{i}=\\f{1}{\\Delta V_{K}}\\int_{x^{i}_{L}}^{x^{i}_{H}}\\sqrtgm\\,\\bQ\\,dx^{i},\n\\end{equation}\nwhere:\n\\begin{equation}\n    \\Delta V_{K}=\\int_{x^{i}_{L}}^{x^{i}_{H}}dV=\\int_{x^{i}_{L}}^{x^{i}_{H}}\\sqrtgm\\,dx^{i}.\n\\end{equation}\n\nBy defining the cell-average as:\n\\begin{equation}\n    \\bW_{K}\\equiv\\f{1}{\\Delta V_{K}}\\int_{x^{i}_{L}}^{x^{i}_{H}}\\bW\\,dV,\n\\end{equation}\nwe have:\n\\begin{equation}\n    \\f{d\\,\\bU_{K}}{dt}+\\f{1}{\\Delta V_{K}}\\left.\\left(\\sqrtgm\\,\\hat{\\bF}\\left(\\bU\\right)\\right)\\right|^{x^{i}_{H}}_{x^{i}_{L}}=\\bQ_{K}.\n\\end{equation}\nNow, using the common notation of the time step being represented as a superscript $n$:\n\\begin{equation}\n    \\bU^{n+1}_{K}=\\bU^{n}_{K}-\\f{\\Delta t^{n}_{K}}{\\Delta V_{K}}\\left[\\sqrtgm_{H}\\,\\hat{\\bF}^{n}_{H}-\\sqrtgm_{L}\\,\\hat{\\bF}^{n}_{L}\\right]+\\Delta t^{n}_{K}\\,\\bQ^{n}_{K}.\n\\end{equation}\n\nNow we define a parameter a la \\citet{ZS2011b}: $\\ve\\in\\left(0,1\\right)$, such that (NOTE: \\citet{ZS2011b} set $\\ve=1/2$):\n\\begin{equation}\n    \\bU^{n}_{K}=\\ve\\,\\bU^{n}_{K}+\\left(1-\\ve\\right)\\bU^{n}_{K}.\n\\end{equation}\nWe can use the first term to balance out the term in the square brackets and the second term to balance out the source term.\n\nSo, we get:\n\\begin{align}\n    \\bU^{n+1}_{K}&=\\ve\\left\\{\\bU^{n}_{K}-\\f{\\Delta t^{n}_{K}}{\\ve\\,\\Delta V_{K}}\\left[\\sqrtgm_{H}\\,\\hat{\\bF}^{n}_{H}-\\sqrtgm_{L}\\,\\hat{\\bF}^{n}_{L}\\right]\\right\\}+\\left(1-\\ve\\right)\\bU^{n}_{K}+\\Delta t^{n}_{K}\\,\\bQ^{n}_{K}\\\\\n    &=\\ve\\left\\{\\bU^{n}_{K}-\\eta^{n}_{K}\\left[\\sqrtgm_{H}\\,\\hat{\\bF}\\left(\\bU^{n}_{K+1},\\bU^{n}_{K}\\right)-\\sqrtgm_{L}\\,\\hat{\\bF}\\left(\\bU^{n}_{K},\\bU^{n}_{K-1}\\right)\\right]\\right\\}+\\left(1-\\ve\\right)\\bU^{n}_{K}+\\Delta t^{n}_{K}\\,\\bQ^{n}_{K}\\\\\n    &=\\ve\\,\\bH_{K,1}+\\left(1-\\ve\\right)\\bH_{K,2},\n\\end{align}\nwhere\n\\begin{equation}\n    \\bH_{K,1}\\equiv \\bU^{n}_{K}-\\eta^{n}_{K}\\left[\\sqrtgm_{H}\\,\\hat{\\bF}\\left(\\bU^{n}_{K+1},\\bU^{n}_{K}\\right)-\\sqrtgm_{L}\\,\\hat{\\bF}\\left(\\bU^{n}_{K},\\bU^{n}_{K-1}\\right)\\right],\n\\end{equation}\n\\begin{equation}\n    \\bH_{K,2}\\equiv\\bU^{n}_{K}+\\f{\\Delta t^{n}_{K}}{1-\\ve}\\,\\bQ^{n}_{K},\n\\end{equation}\nand\n\\begin{equation}\n    \\eta^{n}_{K}\\equiv\\f{\\Delta t^{n}_{K}}{\\ve\\,\\Delta V_{K}}.\n\\end{equation}\n\nWe proceed by focusing on each term individually, starting with the numerical flux term, $\\bH_{K,1}$.\n\n\\subsubsection{Numerical flux term}\nWe have to show that $\\bH_{K,1}\\in\\cG$. We again we use the Local-Lax-Friedrichs flux, \\eqref{Eq:LLF}, yielding for $\\bH_{K,1}$:\n\\begin{align}\n    \\bU^{n}_{K}-\\f{\\eta^{n}_{K}}{2}\\Big\\{&\\sqrtgm_{H}\\left[\\bF\\left(\\bU^{n}_{K+1}\\right)+\\bF\\left(\\bU^{n}_{K}\\right)-\\alpha^{n}_{H}\\left(\\bU^{n}_{K+1}-\\bU^{n}_{K}\\right)\\right]\\\\\n    &-\\sqrtgm_{L}\\left[\\bF\\left(\\bU^{n}_{K}\\right)+\\bF\\left(\\bU^{n}_{K-1}\\right)-\\alpha^{n}_{L}\\left(\\bU^{n}_{K}-\\bU^{n}_{K-1}\\right)\\right]\\Big\\}\\\\\n    &\\hspace{-10em}=\\left(1-\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}-\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\right)\\bU^{n}_{K}\\\\\n    &\\hspace{-8em}-\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\bF\\left(\\bU^{n}_{K}\\right)+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\bF\\left(\\bU^{n}_{K}\\right)\\\\\n    &\\hspace{-8em}+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\left[\\bU^{n}_{K-1}+\\f{1}{\\alpha^{n}_{L}}\\bF\\left(\\bU^{n}_{K-1}\\right)\\right]+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}\\left[\\bU^{n}_{K+1}-\\f{1}{\\alpha^{n}_{H}}\\bF\\left(\\bU^{n}_{K+1}\\right)\\right].\n\\end{align}\nNow we add and subtract $\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}\\,\\bU^{n}_{K}$ and $\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\,\\bU^{n}_{K}$, yielding:\n\\begin{align}\n    &\\left(1-\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}-\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\right)\\bU^{n}_{K}\\\\\n    &+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}\\left[\\bU^{n}_{K}-\\f{1}{\\alpha^{n}_{H}}\\bF\\left(\\bU^{n}_{K}\\right)\\right]+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\left[\\bU^{n}_{K}+\\f{1}{\\alpha^{n}_{L}}\\bF\\left(\\bU^{n}_{K}\\right)\\right]\\\\\n    &+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\left[\\bU^{n}_{K-1}+\\f{1}{\\alpha^{n}_{L}}\\bF\\left(\\bU^{n}_{K-1}\\right)\\right]+\\f{1}{2}\\,\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}\\left[\\bU^{n}_{K+1}-\\f{1}{\\alpha^{n}_{H}}\\bF\\left(\\bU^{n}_{K+1}\\right)\\right].\n\\end{align}\nAll of the terms in square brackets are similar to the $\\bH_{K}$ quantities in \\citet{Qin2016}, and are therefore in $\\cG$. It can easily be seen that the sum of the coefficients is unity. The final condition is that the coefficient of $\\bU^{n}_{K}>0$, or (recalling that $\\eta^{n}_{K}=\\Delta t_{K}/\\left(\\ve\\,\\Delta V_{K}\\right)$):\n\\begin{align}\n    1&-\\eta^{n}_{K}\\,\\sqrtgm_{H}\\,\\alpha^{n}_{H}-\\eta^{n}_{K}\\,\\sqrtgm_{L}\\,\\alpha^{n}_{L}>0\\implies\\eta^{n}_{K}\\left(\\sqrtgm_{H}\\,\\alpha^{n}_{H}+\\sqrtgm_{L}\\,\\alpha^{n}_{L}\\right)<1\\\\\n    &\\implies\\Delta t^{n}_{K}<\\f{\\ve\\,\\Delta V_{K}}{\\sqrtgm_{H}\\,\\alpha^{n}_{H}+\\sqrtgm_{L}\\,\\alpha^{n}_{L}}\\leq\\f{\\ve\\,\\Delta V_{K}}{2\\,\\text{max}\\left(\\sqrtgm_{K\\pm\\f{1}{2}}\\,\\alpha^{n}_{K\\pm\\f{1}{2}}\\right)}.\n\\end{align}\nAgain we want a time-step that is the same for all elements at a given time, so:\n\\begin{equation}\n    \\Delta t^{n}<\\text{min}_{K}\\left(\\f{\\ve\\,\\Delta V_{K}}{2\\,\\text{max}\\left(\\sqrtgm_{K\\pm\\f{1}{2}}\\,\\alpha^{n}_{K\\pm\\f{1}{2}}\\right)}\\right).\n\\end{equation}\n\nWe close the numerical flux section by writing the explicit form of the time-step for spherical-polar coordinates.\n\n\\subsubsubsection{Time-step for Spherical-Polar Coordinates}\nFor spherical-polar coordinates in 1-D we have that $\\Delta V_{K}=1/3\\left(r_{H}^{3}-r_{L}^{3}\\right)$, and (assuming $\\alpha_{K\\pm\\f{1}{2}}=1\\ \\forall\\ i$) $\\text{max}\\left(\\sqrtgm_{K\\pm\\f{1}{2}}\\,\\alpha_{K\\pm\\f{1}{2}}\\right)=r_{H}^{2}$, so:\n\\begin{align}\n    \\Delta t&<\\text{min}_{i}\\left\\{\\f{\\ve\\,1/3\\left[r_{H}^{3}-r_{L}^{3}\\right]}{2\\,r_{H}^{2}}\\right\\}\\\\\n    &=\\text{min}_{i}\\left\\{\\f{\\ve}{6}\\,r_{H}\\left[1-\\f{r_{L}^{3}}{r_{H}^{3}}\\right]\\right\\}\\\\\n    &=\\text{min}_{i}\\left\\{\\f{\\ve}{6}\\,r_{H}\\left[1-\\left(1-\\f{\\Delta r_{i}}{r_{H}}\\right)^{3}\\right]\\right\\}\\\\\n    &=\\text{min}_{i}\\left\\{\\f{\\ve}{6}\\,r_{H}\\left[1-\\left(1+\\left(\\f{\\Delta r_{i}}{r_{H}}\\right)^{2}-2\\frac{\\Delta r_{i}}{r_{H}}\\right)\\left(1-\\f{\\Delta r_{i}}{r_{H}}\\right)\\right]\\right\\}\\\\\n    &=\\text{min}_{i}\\left\\{\\f{\\ve}{6}\\,r_{H}\\left[\\left(\\f{\\Delta r_{i}}{r_{H}}\\right)^{3}-3\\left(\\f{\\Delta r_{i}}{r_{H}}\\right)^{2}+3\\f{\\Delta r_{i}}{r_{H}}\\right]\\right\\}\\\\\n    &=\\text{min}_{i}\\left\\{\\f{\\ve}{6}\\,\\Delta r_{i}\\left[\\left(\\f{\\Delta r_{i}}{r_{H}}\\right)^{2}-3\\left(\\f{\\Delta r_{i}}{r_{H}}\\right)+3\\right]\\right\\}.\n\\end{align}\nWe know that $\\Delta r_{i}/r_{H}\\in\\left[0,1\\right]$; the minimum value of the quadratic function in this domain is unity. So, we have that for spherical-polar coordinates:\n\\begin{equation}\n    \\Delta t<\\f{\\ve}{6}\\,\\text{min}\\left(\\Delta r_{i}\\right).\n\\end{equation}\n\nNext we handle the source term.\n\n\\subsubsection{Source term}\nFor this section we drop the subscript $K$ and the superscript $n$ (but keep in mind that all quantities are still cell-averages). We have to show that $\\bH_{2}\\in\\cG$, where\n\\begin{equation}\n    \\bH_{2}=\\begin{pmatrix}D\\\\ S_{j}+\\f{\\Delta t}{1-\\ve}\\,Q_{j} \\\\ \\tau\\end{pmatrix},\\hspace{1em}\\left(H_{2}\\right)_{1}>0,\\hspace{1em}\\left(H_{2}\\right)_{5}+\\left(H_{2}\\right)_{1}>\\sqrt{\\left(H_{2}\\right)_{1}\\left(H_{2}\\right)_{1}+\\left(H_{2}\\right)_{j}\\left(H_{2}\\right)^{j}}.\n\\end{equation}\n\nIt is clear that the first requirement for $\\bH_{2}$ is met, i.e. $D>0$. The second requirement is:\n\\begin{align}\n    D+\\tau&>\\sqrt{D^{2}+\\left[S_{j}+\\f{\\Delta t}{1-\\ve}Q_{j}\\right] \\left[S^{j}+\\f{\\Delta t}{1-\\ve}Q^{j}\\right]}\\\\\n    &=\\sqrt{D^{2}+S_{j}\\,S^{j}+\\f{\\Delta t}{1-\\ve}\\left(S_{j}\\,Q^{j}+S^{j}\\,Q_{j}\\right)+\\left(\\f{\\Delta t}{1-\\ve}\\right)^{2}\\,Q_{j}\\,Q^{j}}\n\\end{align}\nNow we square both sides:\n\\begin{align}\n    &D^{2}+\\tau^{2}+2\\,D\\,\\tau>D^{2}+S_{j}\\,S^{j}+\\f{\\Delta t}{1-\\ve}\\left(S_{j}\\,Q^{j}+S^{j}\\,Q_{j}\\right)+\\left(\\f{\\Delta t}{1-\\ve}\\right)^{2}\\,Q_{j}\\,Q^{j}\\\\\n    \\implies&\\tau\\left(\\tau+2\\,D\\right)>\\gamma^{jk}\\,S_{j}\\,S_{k}+\\f{2\\,\\Delta t}{1-\\ve}\\,\\gamma^{jk}\\,S_{j}\\,Q_{k}+\\left(\\f{\\Delta t}{1-\\ve}\\right)^{2}\\,\\gamma^{jk}\\,Q_{j}\\,Q_{k}\\\\\n    \\implies&\\tau\\left(\\tau+2\\,D\\right)>\\f{S_{j}\\,S_{k}}{\\gamma_{jk}}+\\f{2\\,\\Delta t}{1-\\ve}\\,\\f{S_{j}\\,Q_{k}}{\\gamma_{jk}}+\\left(\\f{\\Delta t}{1-\\ve}\\right)^{2}\\,\\f{Q_{j}\\,Q_{k}}{\\gamma_{jk}}\\\\\n    \\implies&a\\left(\\Delta t\\right)^{2}+b\\,\\Delta t+c<0,\n\\end{align}\nwhere:\n\\begin{align}\n    a&=\\f{1}{\\left(1-\\ve\\right)^{2}}\\,\\vv{Q}\\cdot\\vv{Q}=\\f{1}{\\left(1-\\ve\\right)^{2}}\\,\\f{Q_{j}\\,Q_{k}}{\\gamma_{jk}}=\\f{1}{\\left(1-\\ve\\right)^{2}}\\sum\\limits_{k=1}^{3}\\f{\\left(Q_{k}\\right)^{2}}{\\gamma_{kk}}\\\\\n    b&=\\f{2}{1-\\ve}\\,\\vv{S}\\cdot\\vv{Q}=\\f{2}{1-\\ve}\\,\\f{S_{j}\\,Q_{k}}{\\gamma_{jk}}=\\f{2}{1-\\ve}\\sum\\limits_{k=1}^{3}\\f{S_{k}\\,Q_{k}}{\\gamma_{kk}}\\\\\n    c&=-\\tau\\left(\\tau+2\\,D\\right)+\\vv{S}\\cdot\\vv{S}=-\\tau\\left(\\tau+2\\,D\\right)+\\sum\\limits_{k=1}^{3}\\f{\\left(S_{k}\\right)^{2}}{\\gamma_{kk}}.\n\\end{align}\nWe want to make sure that our function has at least one real root, which means we must have that $b^{2}-4\\,a\\,c\\geq0$:\n\\begin{align}\n    b^{2}-4\\,a\\,c&=\\f{4}{\\left(1-\\ve\\right)^{2}}\\left(\\vv{S}\\cdot\\vv{Q}\\right)^{2}-\\f{4}{\\left(1-\\ve\\right)^{2}}\\,\\vv{Q}\\cdot\\vv{Q}\\left[-\\tau\\left(\\tau+2\\,D\\right)+\\vv{S}\\cdot\\vv{S}\\right]\\\\\n    &=\\f{4}{\\left(1-\\ve\\right)^{2}}\\left[\\left(\\vv{S}\\cdot\\vv{Q}\\right)^{2}-\\left(\\vv{Q}\\cdot\\vv{Q}\\right)\\left(\\vv{S}\\cdot\\vv{S}\\right)+\\tau\\left(\\tau+2\\,D\\right)\\vv{Q}\\cdot\\vv{Q}\\right]\\\\\n    &=\\f{4}{\\left(1-\\ve\\right)^{2}}\\left[\\left|\\vv{S}\\right|^{2}\\left|\\vv{Q}\\right|^{2}\\,\\cos^{2}\\theta_{SQ}-\\left|\\vv{Q}\\right|^{2}\\left|\\vv{S}\\right|^{2}+\\tau\\left(\\tau+2\\,D\\right)\\left|\\vv{Q}\\right|^{2}\\right]\\\\\n    &=\\f{4}{\\left(1-\\ve\\right)^{2}}\\left|\\vv{Q}\\right|^{2}\\left[\\tau\\left(\\tau+2\\,D\\right)-\\left|\\vv{S}\\right|^{2}\\left(1-\\cos^{2}\\theta_{SQ}\\right)\\right]\\\\\n    &=\\f{4}{\\left(1-\\ve\\right)^{2}}\\left|\\vv{Q}\\right|^{2}\\left[\\tau\\left(\\tau+2\\,D\\right)-\\left|\\vv{S}\\right|^{2}\\sin^{2}\\theta_{SQ}\\right],\n\\end{align}\nwhere $\\theta_{SQ}$ is the angle between the momentum-density vector and the source-term vector. To guarantee at least one real root we must have that\n\\begin{equation}\n    \\tau\\left(\\tau+2\\,D\\right)\\geq\\left|\\vv{S}\\right|^{2}\\,\\sin^{2}\\theta_{SQ}.\n\\end{equation}\n\n\\newpage\n\\begin{equation}\n    b^{2}-4\\,a\\,c'=\\f{4\\left(S_{1}\\right)^{2}}{\\gamma_{11}}a-4\\,a\\left(S_{1}\\,S^{1}-\\tau^{2}-2\\,D\\,\\tau\\right)=4\\,a\\,\\tau\\left(\\tau+2\\,D\\right).\n\\end{equation}\nSince $\\tau\\geq0$, we must have that $\\tau>-2\\,D$. But, from condition two for $\\bH_{K,2}$ we have that $\\tau>-D$, so this condition is automatically satisfied.\n\nThe solutions to this quadratic equation are:\n\\begin{align}\n    \\Delta t&=\\f{-b}{2\\,a}\\pm\\f{1}{2\\,a}\\sqrt{b^{2}-4\\,a\\,c'}=\\f{-S_{1}}{\\sqrt{\\gamma_{11}}\\,\\sqrt{a}}\\pm\\f{1}{2\\,a}\\sqrt{\\f{4S_{1}^{2}}{\\gamma_{11}}a-4\\,a\\,c'}\\\\\n    &=\\f{-S_{1}}{\\sqrt{\\gamma_{11}}\\,\\sqrt{a}}\\pm\\f{1}{\\sqrt{\\gamma_{11}}\\,\\sqrt{a}}\\sqrt{S_{1}^{2}-c'\\,\\gamma_{11}}=\\f{1}{\\sqrt{\\gamma_{11}}\\,\\sqrt{a}}\\left[-S_{1}\\pm\\sqrt{S_{1}^{2}-c'\\,\\gamma_{11}}\\right]\\\\\n    &=\\f{1}{\\sqrt{\\gamma_{11}}\\,\\sqrt{a}}\\left[-S_{1}\\pm\\sqrt{\\gamma_{11}\\left(\\tau^{2}+2\\,D\\,\\tau\\right)}\\right]\\\\\n    &=\\f{2\\left(1-\\ve\\right)}{P^{kk}\\,\\p_{1}\\,\\gamma_{kk}}\\left[-S_{1}\\pm\\sqrt{\\gamma_{11}\\left(\\tau^{2}+2\\,D\\,\\tau\\right)}\\right]\\\\\n    &=\\f{2\\left(1-\\ve\\right)}{P^{kk}\\,\\p_{1}\\,\\gamma_{kk}}\\left[-S_{1}\\pm\\sqrt{\\gamma_{11}\\,\\tau\\left(\\tau+2\\,D\\right)}\\right].\n\\end{align}\n\nSo, we end up with:\n\\begin{equation}\n    \\Delta t<\\text{min}\\left\\{\\text{min}_{i}\\left(\\f{\\ve\\,\\Delta V_{K}}{2\\,\\text{max}\\left(\\sqrtgm_{i\\pm\\f{1}{2}}\\,\\alpha_{i\\pm\\f{1}{2}}\\right)}\\right),\\text{min}^{n}_{i}\\left(\\f{2\\left(1-\\ve\\right)}{P^{kk}\\,\\p_{1}\\,\\gamma_{kk}}\\left[-S_{1}\\pm\\sqrt{\\gamma_{11}\\,\\tau\\left(\\tau+2\\,D\\right)}\\right]\\right)\\right\\}.\n\\end{equation}\n\n\\subsection{Demanding that $q>0$}\n\nSometimes it happens that the cell-average of $q$, $q_{K}\\equiv q\\left(\\bU_{K}\\right)<0$, so our positivity limiter will fail. To get around this we modify the conserved energy, $\\tau$, to demand that $q=\\ve$, where $0<\\ve\\ll1$. The transformation we make is:\n\\begin{equation}\n   \\tau_{K}\\longrightarrow\\alpha\\,\\tau_{K},\\hspace{1em}\\alpha>1.\n\\end{equation}\nThis modifies the definition of $q_{K}$ from:\n\\begin{equation}\n   q_{K}=\\tau_{K}+D_{K}-\\sqrt{D_{K}^{2}+S_{K}^{2}+\\ve}<0,\n\\end{equation}\nto:\n\\begin{equation}\n   \\ve=\\alpha\\,\\tau_{K}+D_{K}-\\sqrt{D_{K}^{2}+S_{K}^{2}+\\ve}.\n\\end{equation}\nSolving this for $\\alpha$, we get:\n\\begin{equation}\n   \\alpha=\\tau_{K}^{-1}\\left[\\ve-D_{K}+\\sqrt{D_{K}^{2}+S_{K}^{2}+\\ve}\\right].\n\\end{equation}\n", "meta": {"hexsha": "66f3dec705f6e2762a2e5ac810b138df4ca288cc", "size": 21767, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/Euler/SamsTexFiles/BP_Methods_FirstOrder_DGScheme.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/Euler/SamsTexFiles/BP_Methods_FirstOrder_DGScheme.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/Euler/SamsTexFiles/BP_Methods_FirstOrder_DGScheme.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": 72.0761589404, "max_line_length": 393, "alphanum_fraction": 0.6074792117, "num_tokens": 9484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.6859494550081926, "lm_q1q2_score": 0.6106968332153505}}
{"text": "\\chapter{Velocity reconstruction using regression} \n\\label{chap_linearregression} \n\nThis chapter presents regression models to address the problem of estimating high resolution fields from low resolution measurements as defined in section \\ref{sec:probdef1}. It reviews the basic ordinary least squares model, regularized linear regression with the common L2 penalty as well as the L1 penalty, and kernel regression. These models are presented in matrix forms, which are more compact than previous works on turbulence. The problem of selecting model complexity and optimizing model parameters, a fundamental topic in learning theory, are also discussed. \n\nThe models are used to reconstruct high-resolution fields from low-resolution measurements. The DNS database of isotropic turbulence presented in section \\ref{sec:data_isotropic} are used for illustration. Only partial results on selecting the models and optimizing parameters are shown in this chapter. Optimal models will be used in chapter \\ref{chap_comparisons} when comparing performances of all proposed models. \n\n\\section{Regression in turbulence studies}\nRegression is probably the earliest method in statistics for prediction. It aims at learning the relation between input variables and corresponding output targets. The model is learned from training samples where both input and output variables are available. the learned model will be used for prediction in situations where only input variables are given. Nice reviews can be found in \\citet{bishop2006pattern} and \\citet{hastie2009elements}. \n\nLeast squares regression has been applied widely in turbulence studies under the name ``\\textit{linear stochastic estimation}'' (LSE) \\citep{adrian1977role,adrian1979conditional}. It has been further investigated \\citep{guezennec1989stochastic,adrian1992stochastic,ewing1999examination} to estimate conditional eddies from the measurements. Later works introduced various extensions such as multi-time, nonlinear or higher-order LSE \\citep{mokhasi2009predictive,durgesh2010multi,nguyen2010proper,meyer2014provide}, which reconstruct velocity fields from pressure or shear-stress measurements. LSE can be also linked to proper orthogonal decomposition (POD), known also as ``principle component analysis'', to reduce the order of reconstruction problems \\citep{bonnet1994stochastic}. \n\nThe idea of combining LR velocity measurements to obtain HR fields using regression has not been addressed until recently \\citep{melnick2012experimental,tu2013integration}. \\citet{melnick2012experimental} used a POD-LSE model to get fully resolved 3D velocities of a flow over a flat plate by combining 3D smoke intensity and 2D PIV measurements. The POD-LSE model has been developed further by \\citet{tu2013integration} with a multi-time LSE reconstruction model. Kalman filter or Kalman smoother are used as real time estimation or data post-processing respectively. The model is tested using time-resolved PIV measurements of a bluff-body wake at a low $ Re $.\n\nRegression models in previous works remains rather simple, with the use of POD to reduce the order of the model. However, simple linear regression models suffer from certain limitations. The use of POD, acting as a low-pass filter, neglects certain small scales \\textit{a priori}. This work discusses further extensions of simple linear regression based on different regularizations or kernel methods. We aim at maximizing the amount of information that each method can recover, so POD is left aside throughout the thesis. Detailed analysis of reconstruction results such as spectra and errors will assess the performances of regression models as mapping functions between large and small scales. \n\n\\section{Ordinary least squares (OLS)}\nGiven a set of $ \\dimtl $ training samples $ \\left\\lbrace \\left(\\y_t, \\z_t\\right)\\right\\rbrace, t= 1,2,...,\\dimtl $ corresponding to pairs of inputs $ \\y_t \\in \\R^{\\dimsl}$ and outputs $ \\z_t \\in \\R^{\\dimsh}$, regression models estimate $ \\z_t $ as a function of $\\y_t $ via a mapping function $ f $: \n\\begin{equation}\n\tf:  \\y_t \\mapsto  \\myhat{\\z }_t = f(\\y_t) + \\n_t\n\\end{equation}\nwhere $ \\n_t \\sim \\mathscr{N}(0,\\sigma^2_{\\n_t})$ is usually a white Gaussian noise. $ f $ is learned from the $ \\dimtl $ pairs of training samples. This function should minimize the loss $ \\loss(f) $, which measures how far the prediction $ f(\\y) $ and the reference $ \\z $ are different within the training data.\n\nThe ordinary least squares model (OLS) assumes that $ f $ is a empirical linear function of $ \\y_t $. This model is widely used for its simplicity yet efficiency in situations where only a small training set with low signal-to-noise ratio is given. Assuming that $ \\{\\z_t\\} $ and $ \\{\\y_t\\} $ are mean-free and pre-normalized to one-standard deviation, OLS is expressed as:\n\\begin{equation}\n\\myhat{\\z }_t = f(\\y_t) = \\B^{\\mytrans}\\y_t\n\\end{equation}\nwhere  $ \\B $ is the coefficient matrix of size $ \\dimsl \\times \\dimsh $. The $ i- $th column of $ \\B $ tells how to weight each measurement  $ \\y_{t,j} $ to get an estimate of $ \\z_{t,i} $. The unknown $ \\B $ is learned from training data by minimizing the empirical loss:\n\\begin{equation}\n\\loss(\\B) = \\sum^{\\dimtl}_{t=1}{ \\normtwo{\\z_t-\\B^{\\mytrans}\\y_t}\t}\n\\end{equation}\nor rearranged in the matrix form as:\n\\begin{equation}\n\\loss(\\B) = \\normtwo{\\Y\\B-\\Z} = \\left(\\Y\\B-\\Z\\right)^{\\mytrans}\\left(\\Y\\B-\\Z\\right)\n\\label{eq:LSE2}\n\\end{equation}\nwhere $ \\Y^{\\mytrans} \\mydef \\{\\y_t\\} $ of size $ \\dimsl \\times \\dimtl $ and $ \\Z^{\\mytrans} \\mydef \\{\\z_t \\} $ of size $\\dimsh \\times \\dimtl$. $ \\normtwo{.} $ is the Euclidean distance, also called ``\\textit{L2 norm}''. $ \\mydef $ is the notation of ``\\textit{define as}''. The loss $ \\loss(\\B) $ is the square of errors, which is purely data-dependent. The optimization problem is to finds $ \\B $ such that:\n\\begin{equation}\n\\B= \\argmin_B{ \\left\\lbrace \\loss(\\B) \\right\\rbrace} = \\argmin_B{ \\left\\lbrace\\Vert \\Y\\B-\\Z\\Vert^2_2 \\right\\rbrace}\n\\end{equation}\n$ \\argmin{ \\{ . \\}} $ is the argument of the minimum seeking $ \\B $ such that $ \\loss(\\B) $ attains its minimum. The least square error solution of $ \\B $ is by differentiating equation \\ref{eq:LSE2} with respect to $\\B$ and set to zero:\n\\begin{equation}\n\\B= \\pinv { \\Y } \\Z= \\left( \\Y^{\\mytrans}\\Y \\right)^{-1} \\Y^{\\mytrans}\\Z\n\\label{eq:LSE5}\n\\end{equation}\nwhere $ (.)\\pinv{} $ is Moore-Penrose pseudo inverse. Then, the output $ \\z^\\ext  $ of any new input vector $ \\y^\\ext$ out of the training set is estimated as:\n\\begin{equation}\n\\z^\\ext = \\B^{\\mytrans}\\y^\\ext\n\\label{eq:LSE6}\n\\end{equation} \n\n\\section{Regularized linear regression}\n\\label{sec:regularized_linear_regression}\nOLS suffers from critical problems. It requires the inverse of matrix $ \\Y^{\\mytrans}\\Y $ that can be singular or almost singular. The iterative solver can overcome this problem, but may result in a high-variance model with many large coefficients: a small change of $\\y^\\ext$ leads to very different predictions of $\\z^\\ext$. Since learned purely from the training data, it often fits very well the training data but poorly performs otherwise. This phenomena is called \\textit{overfitting} and will be discussed later in this chapter. Regularized least squares are proposed to overcome this problem. The idea is to add a regularization term $ g(\\B) $ on $ \\B $ to the data-dependent error term:\n\\begin{equation}\n\t\\loss(\\B, \\lambda) = \\Vert \\Y\\B-\\Z\\Vert^2_2 +\\lambda g(\\B)\n\t\\label{eq:regularized_linear_regression1}\n\\end{equation}\nwhere the regularization parameter $ \\lambda $ controls the balance between the two terms. Different terms lead to different regression models.\n\n\\subsection{Ridge Regression (RR): L2 penalty}\n\\label{sec:l2_penalty}\nThe most common and simple regularization is L2 penalty, also called ``weight decay'', which leads to the formulation of ridge regression (RR). The regularization term is on the norm of OLS coefficients, i.e. $ g(\\B) = \\Vert \\B \\Vert^2_2$. The loss function becomes:\n\\begin{equation}\n\\loss(\\B, \\lambda) = \\Vert \\Y\\B-\\Z\\Vert^2_2 +\\lambda\\Vert \\B \\Vert^2_2 \n\\label{eq:RR1}\n\\end{equation}\nThe parameter $\\lambda $ controls the balance between the data misfit and regularization term, which is the sum of squares of all coefficients. It controls how far $ \\B $ are shrunk towards zero, the larger $ \\lambda $ the further. Setting the derivative with respect to $ \\B $ to zero, the closed form to estimate $ \\B $ is:\n\\begin{equation}\n\\B=\\left( \\Y ^{\\mytrans}\\Y+\\lambda \\I \\right)^{-1}  \\Y ^{\\mytrans}\\Z \n\\label{eq:RR2}\n\\end{equation}\nThis formula is similar to that of OLS except that some positive value $ \\lambda $ is added to the diagonal elements of $ \\Y^{\\mytrans}\\Y $ to ensure $ \\Y^{\\mytrans}\\Y +\\lambda \\I$ is always invertible.\n\nThe mechanism of RR can be analyzed via the singular value decomposition (SVD) of $ \\Y $: \n\\begin{equation}\n\\Y= \\Umat\\Diag\\Vmat^{\\mytrans}\n\\label{eq:RR3}\n\\end{equation}\nwhere $ \\Umat=(\\mybold{u}_1, \\mybold{u}_2,... ,\\mybold{u}_{\\dimsl}) $ is a $ \\dimtl \\times \\dimsl $ orthogonal matrix, $ \\Diag = diag(d_1, d_2, ... , d_{\\dimsl} )$ is a $ \\dimsl \\times \\dimsl $ diagonal matrix $ (d_1 \\geq d_2 \\geq ... \\geq d_{\\dimsl}) $, and $ \\Vmat^{\\mytrans}=(\\mybold{v}_1^{\\mytrans}, \\mybold{v}_2^{\\mytrans},... ,\\mybold{v}_{\\dimsl}^{\\mytrans}) $ is a $ \\dimsl \\times \\dimsl $ orthogonal matrix. The orthogonality implies that $ \\Umat^{\\mytrans}\\Umat = \\I $ or $ \\Umat^{\\mytrans}=\\Umat^{-1} $, similarly for $ \\Vmat $ and $ \\Vmat^{\\mytrans} $. The formula to estimate RR coefficients becomes:\n\\begin{equation}\n\\B =\\left(\\Y^{\\mytrans} \\Y + \\lambda \\I\\right)^{-1}\\Y^{\\mytrans}\\Z = \\Vmat \\, diag \\left( \\frac{d_j^2}{d_j^2+\\lambda} \\right) \\, \\Umat^{\\mytrans} \\Z\n\\label{eq:RR6}\n\\end{equation}\nRe-estimating training output variables $ \\Z $ as a function of inputs, one obtains:\n\\begin{equation}\n\\myhat{\\Z} = \\Y\\B = \\sum\\limits_{j=1}^{\\dimsl} \\left( \\mybold{u}_j \\frac{d_j^2}{d_j^2 + \\lambda} \\mybold{u}^{\\mytrans}\\right)\\Z\n\\label{eq:RR8}\n\\end{equation}\nThis implies that RR projects $ \\Z $ onto the principal components of $ \\Y^{\\mytrans}\\Y $ with large energy content (large $ d_j $) and shrinks the coefficients of low energy (small $ d_j $). This makes RR close to the \\textit{principal component regression} model discussed in \\citet{jolliffe1982note}, where one decomposes $ \\Y^{\\mytrans}\\Y $ using SVD and then set components with low energy content (small $ d_j $) to zeros in a handy manner. The approach also avoids matrix inversion and plays a role similar to regularization.\n\n\\subsection{LASSO: L1 penalty}\n\\label{sec:l1_penalty}\nThe nature of L2 penalty  is to reduce model variance by shrinking coefficients corresponding to irrelevant events toward zero. However, they are not exactly zero. L1 penalty will precisely force some coefficients to zero. The model is called least absolute selection and shrinkage operator (LASSO) \\citep{tibshirani1996regression} in statistics, or basis pursuit denoising (BPDN) \\citep{chen1998atomic} in signal processing. It is considered as an implicit subset selection step, where irrelevant events are neglected from the reconstruction. This property favors sparsity - output is estimated as a combination of some input variables only- that is beneficial in many applications.\n\n\\begin{algorithm}[t]\n\\caption{Iterative shrinkage-thresholding algorithm (ISTA)}\\label{algo_ISTA}\n\\begin{algorithmic}[1]\n\\State Set k=0 and initialize $ \\B^{(0)} $; \n\\While{not convergence}\n\t\\State $ \\bigtriangledown f(\\B^{(k)}) = \\Y^{\\mytrans}(\\Z-\\Y\\B^{(k)})$ \\Comment{Residual from step k}\n\t\\State $\\B^{(k+1)} \\gets \\prox_{\\lambda \\normone{.}} \\left[ \\B^{(k)} - t^{(k)} \\bigtriangledown f(\\B^{(k)}) \\right] $\n\t\\State k = k + 1 \n\\EndWhile\n\\State \\textbf{return} $\\B^{(k+1)}$\n\\end{algorithmic}\n\\end{algorithm}\n \nThe LASSO cost function is similar to that of RR with a subtle but very important modification:\n\\begin{equation}\nF(\\B)= \\Vert \\Y\\B-\\Z\\Vert^2_2 +\\lambda \\normone{\\B}\n\\label{eq: LASSO1}\n\\end{equation}\nThe data-dependent term is the same as OLS or RR. The different penalty term $ \\lambda \\normone{\\B}$ imposes a constraint on the sum of absolute values of coefficients. This modification leads to sparsity, the key difference between LASSO and RR. It also makes the problem nonlinear and there exits no closed-form solution. Gradient-based methods are usually used to solve this optimization problem. Iterative shrinkage-thresholding algorithms (ISTA) is one of them, where $ \\B $ is solved iteratively by \\textit{soft-thresholding} as in Algorithm \\ref{algo_ISTA} \\citep{daubechies2004iterative}. In the pseudo code, $ prox $- the shrinkage operator- is the element-wise soft-thresholding: \n\\begin{equation}\n\\left(\\prox_{\\lambda \\normone{.}}[\\B]\\right)_i =\n\\begin{cases}\nb_i-\\lambda \\mysign{b_i} & \\text{if } |b_i|>\\lambda,\n\\\\\n0 & \\text{otherwise }\n\\end{cases}\n\\end{equation}\nwhere $ t^{(k)} $ is the gradient step size, $ b_i $ is the $ i- $th coefficient of $ \\B $. The \\textit{sign function} $ \\mysign{b_i} $ is defined as:\n\\begin{equation}\n \\mysign{b_i} =\n\\begin{cases}\n-1 & \\text{if } b_i<0,\n\\\\\n0 & \\text{if } b_i=0,\n\\\\\n1  & \\text{if } b_i>0.\n\\end{cases}\n\\end{equation}\nFaster schemes have been proposed to accelerate the convergence time \\citep{vonesch2008fast,beck2009fast}, but further discussions are outside the scope of this work.\n\nLASSO often outperforms RR and subset selection methods for several reasons. Compared to RR, LASSO takes most of the advantages, including the stability of the solution and the shrinkage feature. These features give a low-variance model compared to subset selection method. Moreover, LASSO favors sparsity, which can be considered as an implicit subset selection \\citep{hastie2005elements, hastie2009unsupervised}. By forcing some of the coefficients to zeros, the irrelevant predictors are suppressed in final estimation.\n\n\\section{Nonlinear regression}\n\\label{sec:nonlinear_regression}\nLinear regression aims at mapping the output as a linear combination of input variables. This implies a real constraint on performances of this family of models. In many cases including turbulence, linear functions are too simple to describe the undergoing phenomenon. Nonlinear regression models are beneficial, and kernel feature mapping is often used.\n\n\\subsection{Feature mapping}\nKernel methods are used to introduce nonlinearity into the model. The idea is to project the original input vector $ \\y  $ onto a fixed feature space:\n\\begin{equation}\n\\y_t \\mymapto \\mybold{\\phi}_t = \\featmap{\\y_t}\n\\end{equation}\nand perform least square regression in this space. $ \\y_t \\in \\R^{\\dimsl}$ is the $ t- $ input vector. The feature vector $ \\mybold{\\phi}_t \\in \\R^{\\Df} $, where $ \\Df \\gg \\dimsl $ is the dimension in feature space. The least square problem becomes: \n\\begin{equation}\n\\B = \\argmin_B{ \\left\\lbrace \\normtwo{ \\Z- \\mathbf{\\Phi}\\B} \\right\\rbrace}\n\\end{equation}\nwhere $ \\mathbf{\\Phi} = \\{\\mybold{\\phi}_t \\} $ ($ t = 1, ..., \\dimtl $), the so-called \\textit{design matrix}, is of size $ \\dimtl \\times \\Df $. Adding L2 regularization term $ \\normtwo{\\B} $ and deriving analogously as RR model, the solution is:\n\\begin{equation}\n\\B=\\left(\\mathbf{\\Phi}^{\\mytrans}\\mathbf{\\Phi} + \\lambda \\I\\right)^{-1}\\mathbf{\\Phi}^{\\mytrans}\\Z\n\\end{equation}\nThen the prediction of a new input variable $ \\y^\\ext $ is:\n\\begin{equation}\n\\z^\\ext=\\B^{\\mytrans} \\featmap{\\y^\\ext}\n\\end{equation} \n\n\\subsection{Kernel ridge regression}\nInvolving nonlinearity via feature mapping significantly increases computational costs. The kernel trick is proposed \\citep{saunders1998ridge} to overcome this problem, resulting in the so-called kernel ridge regression (KRR) model. This trick appears when solving ridge regression using Lagrange dual optimization.\n\n\\subsubsection*{Dual form of ridge regression}\nRR in equation \\ref{eq:RR1} can be re-expressed as a dual Lagrangian optimization problem:\n\\begin{equation}\n\\B=\\argmin_B{ \\left\\lbrace \\sum\\limits_{t=1}^{\\dimtl}\\normtwo{\\mybold{e}_t} + \\lambda \\normtwo{\\B} \\right\\rbrace } \\subjectto \\z_t - \\B^{\\mytrans}\\y_t = \\mybold{e}_t, \\:\\:\\:\\:\\:\\: t = 1, 2, ..., \\dimtl\n\\label{eq:RRdual1}\n\\end{equation}\nwhere $ s.t $ stands for ``\\textit{subject to}''. Introducing Lagrange multipliers $ A[\\dimtl \\times \\dimsh] \\mydef \\{\\mybold{a}_t^{\\mytrans} \\} (t = 1, 2, ..., \\dimtl), \\mybold{a}_t \\in \\R^{\\dimsh}$, the optimization problem \\ref{eq:RRdual1} is equivalent to the problem of finding the saddle point of the function:\n\\begin{equation}\n\\sum\\limits_{t=1}^{\\dimtl}\\normtwo{\\mybold{e}_t} + \\lambda \\normtwo{\\B} + \\sum\\limits_{t=1}^{\\dimtl} \\mybold{a}_t^{\\mytrans}\\left( \\z_t - \\B^{\\mytrans}\\y_t - \\mybold{e}_t\\right)\n\\end{equation}\nThe solution as shown in \\citet{saunders1998ridge} is:\n\\begin{equation}\n\\mathbf{A}  = \\left(\\mathbf{K} + \\lambda \\I\\right)^{-1}\\Z\n\\end{equation}\nwhere $ \\mathbf{K} \\mydef \\Y\\Y^{\\mytrans} $ is the matrix of dot products, $ \\mathbf{K}_{m,n} = \\y _m^{\\mytrans} \\y _n $. The prediction for a new input variables $ \\y^\\ext $ is:\n\\begin{equation}\n\\myhat{\\z }^\\ext = \\left(\\sum\\limits_{t=1}^{\\dimtl}\\mybold{a}_t^{\\mytrans}\\y_t\\right)\\y^\\ext = \\mathbf{A}^{\\mytrans} \\mybold{k}^{\\ext}\n\\end{equation}\nwhere $ \\mybold{k}^{\\ext} \\mydef \\{k_t\\} = \\{ \\y_t^{\\mytrans} \\y^\\ext \\} \\in \\R^{\\dimtl}$.\n \n\\subsubsection*{Kernel trick}\n\n\\begin{table}\n\\centering\n\\begin{tabular}{lc} \\toprule\n\tFunction name  & $ k (\\mybold{u}, \\mybold{v}) $ \\\\ \\midrule\n\tLinear  & $ \\mybold{u}^{\\mytrans} \\mybold{v} $ \\\\ \\midrule\n\tPolynomial  & $ (r + \\mybold{u}^{\\mytrans} \\mybold{v})^d $ for $ r,d \\geq 0 $\\\\ \\midrule\n\tRadial basis function (RBF)  & $ \\myexp{-\\gamma \\normtwo{\\mybold{u} - \\mybold{v}}}$, $ \\gamma > 0 $ \\\\\n\t\\bottomrule\n\\end{tabular}\n\\caption{Common basis functions for kernel methods.}\n\\label{tab_basisfunctions}\n\\end{table}\n\nSolving RR in the dual form offers no improvement of accuracy, speed or stability. However, the beauty of this approach is the presence of only dot products among input variables in the final prediction step. This implies an analogous procedure when working in a nonlinear feature space. The transformation into such a space is unnecessary if the dot products of the transformed variables can be estimated using the kernel: \n\\begin{equation}\nk (\\mybold{u}, \\mybold{v}) = \\featmap{\\mybold{u}}^{\\mytrans} \\featmap{\\mybold{v}}\n\\end{equation}\nThis explicit transformation is computed in time $ \\mathcal{O}(\\dimsl^2) $, where $ \\dimsl $ is the dimension of the input vectors. The \\textit{kernel trick} permits to estimate directly $ k (\\mybold{u}, \\mybold{v}) $ without computing $ \\featmap{\\mybold{u}} $ and $ \\featmap{\\mybold{v}} $, reducing the computational time into $ \\mathcal{O}(\\dimsl) $ only. Not every kernel has this property. Table \\ref{tab_basisfunctions} gathers three common functions.\n\n\\section{A framework to select model and parameters}\nA model is assessed via its generalization performance, i.e. the prediction capability on a new dataset independent from the training set. In all above models, there exists one or more hyper-parameters that are directly linked to model performances. The arising question is how to optimize those parameters using training data only in a systematic manner. This step is the so-called \\textit{parameter optimization}, while the step to test performances of the model on independent data is the so-called \\textit{model assessment}. \n\nIt is worth also mentioning the definition of different datasets: \\textit{training}, \\textit{validation} and \\textit{test} sets. The training set contains data from which a model is learned. The validation set is used to estimate prediction errors, and from which the best model is chosen. This model is the one that gives the most accurate prediction on the validation set. The testing set is finally used to give an estimate of the prediction error of this optimal model. This error is approximately the generalization error on independent datasets.\n\nTo optimize the generalization capability of a model, one needs to understand the idea of \\textit{bias} and \\textit{variance}. Next sections will discuss this topic, with the technique called ``\\textit{cross-validation}'' to find the trade-off between bias and variance using the training data only. \n\n\\subsection{Bias-variance trade-off}\nThe above regression models can be interpreted as seeking a mapping function $ f $: \n\\begin{equation}\n\tf:  \\y  \\mapsto  \\myhat{\\z } = f(\\y ) + \\n\n\\end{equation}\nwhere $ \\n \\sim \\mathscr{N}(0,\\sigma^2_{\\n})$ is assumed to be a white Gaussian noise. The expected prediction error of this model for an input vector $ \\y_\\knot $ is:\n\\begin{equation}\n\\begin{split}\n\\epsilon(\\y_\\knot) & =\\E{\\left(\\z_\\knot - f(\\y_\\knot)\\right)^2} \\\\\n  & = \\underbrace{\\sigma_{\\n}^2}_{\\text{Irreducible Error}} + \\underbrace{\\left(\\E{\\myhat{\\z }_\\knot} - \\z_\\knot\\right)^2}_{\\text{Bias}^2} + \\underbrace{\\E{\\left( \\myhat{\\z }_\\knot -  \\E{\\myhat{\\z }_\\knot} \\right)^2}}_{Variance}\n\\end{split}\n\\end{equation}\nwhere $ \\E{.} $ is the expectation of a variable. The first term comes from the noise, which depends only on the data and is irreducible. The second term is the square bias, showing how far the average of the estimates is different from the true mean. The last term is the expected variance of the estimate around its mean. We can interpret the bias as the average prediction error over different data sets from the true mean, and the variance as how this error is sensitive to a particular choice of data set.\n\nAfter the decomposition, a model is said to be \\textit{underfitting} or \\textit{overfitting} depending on the contribution of each term in the total error. An underfitting model is too simple to capture all details of the underlying phenomenon. This model is high-bias and low-variance: it poorly fits the training data and performs similarly in the testing data. An overfitting model is over-complex: it closely fits the training data, including noises, and gives poor performance on new testing data. This model has low bias and high variance. Ideal models should have both low bias and variance. In practice, a good model must satisfy its \\textit{bias-variance trade-off} when it does not suffer from either the problems of overfitting or underfitting.  \n\n\\begin{figure}\n\\centering\n\t\\includegraphics[width=0.7\\columnwidth]{./images/regression/bias-variance_tradeoff.png}\n\t\\caption{\\label{fig:bias-variance_tradeoff} Typical behavior of prediction error for testing (red) and training (blue) dataset as a function of a hyper-parameter \\citep{hastie2009elements}. Different curves are for various datasets. The solid ones are expected errors (average of all curves). From left to right can be the direction of decreasing regularization or increasing model complexity.}\n\\end{figure}\n\nThe idea of underfitting and overfitting can be visualized in figure \\ref{fig:bias-variance_tradeoff} as modified from \\citet{hastie2009elements}. It shows the prediction errors for training and testing datasets as a function of a parameter. This parameter can be either the model complexity in an increasing order or the regularization parameter $ \\lambda $ in a decreasing order. Models toward the left (low complexity model, or regression with a strong regularization) are underfitting. It does not fit well both the training and testing data. Toward the right, errors on the training set decrease, while those of the testing set decrease and then increase again. Models in the far right are overfitting. They fit well the training set but not the testing set. The desired model is the one such that the error on the testing set is the lowest. At this point, the model reaches its bias-variance trade-off: bias and variance do not necessarily reach their minima, but a compromise ensures the minimal error on testing data.\n\nThe idea of bias-variance trade-off can be further visualized schematically as in figure \\ref{fig:bias-variance} \\citep{hastie2009elements}. The blue-shaded region shows the irreducible error $ \\sigma_{\\n}^2 $ (due to random noise) of the training set, where the truth is at the center and all realizations are within. To fit the model, the non-regularized model space (red curve) contains all possible models, while the magenta one shows the restricted space of regularized models. Model variances are depicted as yellow curves centered at the so-called ``closest fit''. The model bias is the distance of the closest fit and the truth, which can only be reduced as increasing the model complexity or adding more features. Regularized models add estimation bias on top of the model bias but reduce the variance. The benefit of the trade-off is only when the variance is reduced more than the squared estimation bias.\n\n\\begin{figure}\n\\centering\n\t\\includegraphics[width=0.6\\columnwidth]{./images/regression/bias-variance.png}\n\t\\caption{\\label{fig:bias-variance} Schematic view of the behavior of bias and variance \\citep{hastie2009elements}. The blue-shaded, centered at the truth, is the realization space, where maximum distance is the irreducible error. All possible models are bounded by the red/magenta model space curves. Bias is shown by the black lines as the distance to the truth. Best models are shown as black dots, and circled by model variances. }\n\\end{figure}\n\nThe bias-variance trade-off is essentially estimated from the training data. If this set is large enough, it can be virtually divided into training, cross-validation and testing sets. A general advice for the size of these three sets is $ 50 \\% $, $ 25 \\% $ and $ 25 \\% $ respectively \\citep{hastie2009elements}. However, learned models are usually improved when using more data. Cross-validation is another idea to find the trade-off while keeping the whole training data for learning the model. \n\n\\subsection{Cross-validation}\nIn many cases, the training data is limited. Setting aside $ 50 \\% $ the data to quantify the model might lose all the benefits from regularization and nonlinearity compared to OLS. Cross validation (CV) is commonly used to select the model and optimize parameters using all given data. \n\nThe most popular CV technique is \\textit{k-fold} CV. The dataset is randomly split into $ K $ subsets of approximately equal size. For each $ K $-th subset to estimate the prediction error, the model is trained on the remaining $ K-1 $ subsets. This procedure is repeated $ K $ times for all the subset, and the model error for the current setting is the average of its $ K $ estimates. A summary of k-fold CV is presented in algorithm \\ref{algo_kfold}. $ K $ is at most the number of training samples (\\textit{leave one out cross validation}). When $ K $ is high, the selected model tends to have lower bias but higher variance, since many training samples are similar. A much heavier computation is also required, since the training/predicting is repeated $ K $ times. The popular choice of $ K $ is from 5 to 10 \\citep{breiman1992submodel, kohavi1995study}. \n\n\\begin{algorithm}[t]\n\\caption{K-fold cross-validation for set of L parameters $ \\gamma_1, \\gamma_2, ..., \\gamma_L $} \\label{algo_kfold}\n\\begin{algorithmic}[1]\n\t\\State Divide the training samples into k folds randomly\n\t\\For {$ i = 1, 2, ..., L$}\n\t\t\\For {$ j = 1,2,... K $}\n\t\t\t\\State Train the model with $ \\gamma_i $ using all data set except the $ j^{th} $\n\t\t\t\\State Estimate prediction error $ \\epsilon(i,j) $ of the model on the $ j^{th} $ set\n\t\t\\EndFor\n\t\\EndFor\n\t\\State Estimate averaged error $ \\epsilon(i) = \\frac{1}{K}\\sum\\limits_{j=1}^{K}\\epsilon(i,j)$\n\t\\State Return optimal parameter $ \\gamma_m $ where $ \\epsilon(m) = min \\{\\epsilon(i)\\}$.\n\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Regression models for reconstruction of isotropic turbulence}\nWe now apply regression models to reconstruct HR velocity fields from LR measurements. The data from DNS isotropic turbulence discussed in section \\ref{sec:data_isotropic} is used. Streamwise velocities from $ 37 $ data cubes of fully resolved data $ 96^3 $ are used as the reference. In each data cube, only the streamwise velocity component is considered. The training examples are the HR fields (in spanwise-vertical directions) and equivalent LR ones subsampled by a factor of $ \\sqrt{\\dimsh/\\dimsl} = 3 $ in both vertical and spanwise directions. This ratio is equivalent to an energy loss of $ \\Delta \\kappa_s = 1.03 \\% $ (see table \\ref{tab:energyloss_isotropic}). In streamwise direction, the training planes are selected every 4 snapshots, corresponding to an energy loss of $ 1.23 \\% $. This configuration is chosen to mimic other problems investigated later in chapters \\ref{chap_NLM} and \\ref{chap_BayesianFusion}. \n\nRegression models are learned from $ 37 \\times 24 $ pairs of LR ($ \\dimsl = 32 \\times 32 $) and corresponding HR ($\\dimsh = 96 \\times 96 $) fields. The learned models are then used to reconstruct all $ 37 \\times 96 $ HR fields from $ 37 \\times 96 $ measured LR planes. These results are presented latter in chapter \\ref{chap_comparisons} when comparing various methods. Following sections only discuss the optimization of model parameters.\n\n\\subsection{Regularization parameter and shrinkage effect}\nOrdinary least squares model inverses directly $ \\Y^{\\mytrans}\\Y $, which is usually ill-conditioned, leading to high variance models. A slight change of input variables can lead to very different predictions. Regularization is introduced to reduce this effect by imposing different penalty terms on regression coefficients. RR seeks a model with small sum-of-square coefficients, LASSO imposes a penalty of their absolute values (see section \\ref{sec:regularized_linear_regression}). \n\n\\begin{figure}\n\\centering\n\t\\includegraphics[width=0.8\\columnwidth]{./images/regression/RR_LSE_coefficients.png}\n\t\\caption{\\label{fig:RR_LSE_coefficients} Shrinkage effect: coefficients of OLS (left) vs RR (right) models correspond to an input LR measurement at the center of the field. The coefficients, which are rearranged in a 2D field of the size $ 96 \\times 96 $, can be interpreted as the contributions of this input to the reconstruction of all other high-resolution points. The higher the coefficient, the stronger the impact.}\n\\end{figure}\n\nFigure \\ref{fig:RR_LSE_coefficients} shows the weight of the input variable at the center of the field in reconstructing all other HR points by OLS and RR. These are the coefficients $ \\mybold{b}_j \\mydef [b_{j1}, b_{j2}, ..., b_{j\\dimsh}]^{\\mytrans}$ computed in equation \\ref{eq:LSE5} for OLS or equation \\ref{eq:RR2} for RR. Recall that $ \\B $ is of size $ \\dimsl \\times \\dimsh $. The figures are $ \\mybold{b}_j$ of OLS and RR models, where index $ j $ corresponds to the central point. $ \\mybold{b}_j $ is then rearranged to recover the 2D shape of size $ \\sqrt{\\dimsh} \\times \\sqrt{\\dimsh} $ of the 2D velocity fields. In both plots, the weights remain significant in a neighborhood of several pixels. The coefficients drop very quickly when moving away from the center. This is due to the rapid decay of correlation between the central point and its neighbors. The difference between the two methods is that OLS (using direct inversion) gives large coefficients almost everywhere whereas RR shrinks the contributions of irrelevant points to small values.\n\n\\begin{figure}[t]\n\\centering\n\t\\includegraphics[width=0.8\\columnwidth]{./images/regression/RR_coeffs_lambda.eps}\n\t\\includegraphics[width=0.8\\columnwidth]{./images/regression/Lasso_coeffs_lambda.eps}\n\t\\caption{\\label{fig:coeffs_lambda} Shrinkage effects of L2 (top) and L1 (bottom) penalty: coefficients corresponding to eight high-resolution outputs (in eight different colors) as functions of regularization parameters $ \\lambda $. Higher $ \\lambda $ shrink the coefficients toward zeros differently depending on the penalty terms.}\n\\end{figure}\n\nThe different shrinkage behaviors of RR and LASSO are visualized in figure \\ref{fig:coeffs_lambda}. This figure shows the eight different coefficients corresponding to eight HR outputs as a function of the regularization parameter presented in equation \\ref{eq:regularized_linear_regression1}. It confirms the effect of the penalty term, which shrinks coefficients associated with irrelevant inputs to zeros. RR coefficients do not reach exact zeros even for extremely high $ \\lambda $, while LASSO rapidly shrinks some coefficients to exact zeros.\n\n\\subsection{Optimizing regularization parameters and model complexity via ten-fold cross-validation}\t\n\nAll regression models (except OLS) are parametric, i.e. at least one hyper-parameter controls the construction of the model and its performances. With RR, LASSO or KRR, the regularization parameter $ \\lambda $ controls the balance between data misfit and regularization term. KRR model is also a function of the kernel parameter, which is the standard deviation of the distribution when using RBF kernel, or the polynomial order. All hyper-parameters are chosen from the training samples using ten-fold CV (see algorithm \\ref{algo_kfold}). The plot of the error as a function of model parameters is called the ``validation curve'', from which the best model or parameter is selected.\n\nAnother important test is to see whether the training dataset is sufficient or not. This is examined via the so-called ``learning curve''. To estimate this curve, a small subset of data is drawn out randomly from the training set. This set is retained to estimate the error at the last step. For the remaining data, models are optimized using different portions. Trained models are assessed by computing prediction errors on the testing data. The curve of errors as a function of different data size, the ``learning curve'', will tell whether the current training data is sufficiently large to guarantee an accurate learning.\n\n\\begin{figure}\n\\centering\n\t\\includegraphics[height=6.75cm]{./images/regression/RR_validationcurve.eps}\n\t\\hspace{0.3cm}\n\t\\includegraphics[height=6.75cm]{./images/regression/RR_learningcurve.eps}\t\n\t\\caption{\\label{fig:RR_validationcurve} RR validation curve: errors as functions of regularization parameter $ \\lambda $ (left), and learning curve: errors as functions of training data size (right). Red curves are for the prediction, while blue ones are for the training data}\n\\end{figure}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[height=6.75cm]{./images/regression/KRR_validationcurve_lambda.eps}\n\t\\hspace{0.3cm}\n\t\\includegraphics[height=6.75cm]{./images/regression/KRR_validationcurve_gamma.eps}\t\n\t\\caption{\\label{fig:KRR_validationcurve} KRR validation curve (RBF kernel), with parameters are kernel parameter $ \\gamma $ and regulartization parameter $ \\lambda $. Red curves are for the prediction, while blue ones are for the training data}\n\\end{figure}\n\nTo plot validation and learning curves, the average normalized root mean square error (NRMSE) $ \\bar{\\epsilon} $ is used as the prediction error. $ \\bar{\\epsilon} $ represents an overall measure of the reconstruction accuracy. NRMSE is estimated between the reconstructed ($ \\hat{\\z}_t $) and reference ($ \\z_t $) fields\n\\begin{equation}\n\\bar{\\epsilon} = \\left(\\frac{ \\sum\\limits_{t} \\sum\\limits_{j\\in \\varmathbb{J}}(\\hat{\\mybold{z}}_{t,j}-\\mybold{z}_{t,j})^2}{\\sum\\limits_{t} \\sum\\limits_{j\\in \\varmathbb{J}}\\mybold{z}_{t,j}^2}\\right)^{1/2}\n\\label{eq:NRMSE}\n\\end{equation} \n$ \\varmathbb{J} $ is the considered set of points used to estimate the error. In the present case of isotropic turbulence, $ \\varmathbb{J} $ contains all points in each plane.\n\nFigure \\ref{fig:RR_validationcurve} shows the validation and learning curve of RR model on the training set (blue) and validation set (red). The solid lines are the means, while a band of colors show the standard deviations of ten estimates of $ \\bar{\\epsilon} $ from ten folds. The validation curve (left) shows the model behavior for different $ \\lambda $. For the training set, the model fits accurately the data when no or small regularization is imposed. This effect of overfitting is shown on the validation set, where higher errors are obtained. The model has also high variance, i.e. prediction errors vary strongly from one set to the other. The optimal value of $ \\lambda \\approx 100 $ is reached where the validation error is minimum. When a very strong regularization is imposed, errors on both training and validation sets increase, since all coefficients are shrunk toward zero. Errors will grow till their maximum value, which is the variance of the HR data. The learning curve (right) shows the effect of the training data size on the performance of the model (with optimal $ \\lambda $). The figure shows that with larger training data, the prediction error on the validation set decrease sharply while this error on the training set gradually increase. With a good model and sufficiently large training data, these two curves will be very close. The curves also suggest that a larger dataset will lead to a better model in this case. \n\nKRR model parameters are optimized using the same validation curve. Different models come with different kernel parameters (recall table \\ref{tab_basisfunctions}), together with the regularization parameter $ \\lambda $. For RBF kernel, $ \\gamma $ represents the kernel shape. Figure \\ref{fig:KRR_validationcurve} shows that the optimal values of both $ \\lambda $ and $ \\gamma $ are both of the order of $ 10^{-5} $. For polynomial kernel, the polynomial order is to be tuned. The model with higher polynomial order will have lower bias but higher variance. An analogous procedure is used to find the optimal order of the polynomial fit, which is either 2 or 3 in general. \n\n\\section{Concluding remarks}\nIn this chapter, regression models are used to reconstruct high resolution fields of an isotropic turbulence from low resolution measurements. The models seek a mapping function between low and high resolved fields. This function is learned from given training samples and used for prediction when only low-resolution measurements are available. \n\nBoth linear and nonlinear models have been discussed. The ordinary least squares model is the simplest one and is widely used in the literature of turbulence. Since suffering from some critical limitations, notably overfitting and ill-conditioning, various regularization methods have been introduced. Both L2 and L1 penalty have been discussed. While L2 penalty reduces model variance by shrinking coefficients of irrelevant events, L1 forces them to zeros by slightly change the penalty term and offers some potential benefits. Nonlinear regression is another approach to improve OLS. Instead of assuming the underlying phenomenon is linear, it introduces nonlinearity by projecting input vectors to a fixed feature space before performing standard OLS. This nonlinearity helps in improving reconstruction accuracy, since assuming a linear relation between large and small scales of turbulence implies a big constraint on model performances. \n\nWe have presented the procedure to optimize hyper-parameters of regression models. This step is crucial to ensure accurate predictions, since performances of all regression models (except OLS) depend on at least one parameter. The models are learned from the training data, but the performances are assessed on independent data only. Cross-validation is used to seek a compromise, the so-called bias-variance trade-off, from training data only. The dataset is virtually split into many subsets. The models are trained within some subsets, and their prediction generalized errors are estimated using the remaining sets. \n\nThe optimal set of parameters is found using the validation curve and ten-fold cross validation technique. This curve shows the prediction errors on the validation set as a function of model parameters. It gives an idea of the optimal parameter range. Through all the tests, it is shown that the gradient of this curve near its minima is not very sharp, implying that a good estimate of these parameters can be achieved from the training data only. \n\nAll model parameters are investigated. RR model is optimal when its regularization parameter $ \\lambda $ is about $ 100 $. KRR model with RBF kernel is constructed with the optimal values of both $ \\lambda $ and $ \\gamma $ are of the order of $ 10^{-5} $. For polynomial KRR takes 2 or 3 as the optimal order of the kernel.\nAll such models will be used later in chapter \\ref{chap_comparisons} to reconstruct high-resolution fields from low-resolution measurements and compared to other proposed methods.", "meta": {"hexsha": "54e69a011ea05fd8147dcca37e13fc3f14b0e601", "size": 40446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/manuscripts/final_ver1/corps/linearregression.tex", "max_stars_repo_name": "linhvannguyen/PhDworks", "max_stars_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-01T14:41:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T07:08:06.000Z", "max_issues_repo_path": "thesis/manuscripts/final_ver1/corps/linearregression.tex", "max_issues_repo_name": "vanlinhnguyen/PhDworks", "max_issues_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_issues_repo_licenses": ["MIT"], "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/manuscripts/final_ver1/corps/linearregression.tex", "max_forks_repo_name": "vanlinhnguyen/PhDworks", "max_forks_repo_head_hexsha": "9336e5257f5ddc3c899a6fb68b1028c905d13ff9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 121.8253012048, "max_line_length": 1451, "alphanum_fraction": 0.7628937349, "num_tokens": 10454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6106802375782737}}
{"text": "%* glpk04.tex *%\n\n\\chapter{Advanced API Routines}\n\n\\section{Background}\n\\label{basbgd}\n\nUsing vector and matrix notations the LP problem (1.1)---(1.3) (see\nSection \\ref{seclp}, page \\pageref{seclp}) can be stated as follows:\n\n\\noindent\n\\hspace{.5in} minimize (or maximize)\n$$z=c^Tx_S+c_0\\eqno(3.1)$$\n\\hspace{.5in} subject to linear constraints\n$$x_R=Ax_S\\eqno(3.2)$$\n\\hspace{.5in} and bounds of variables\n$$\n\\begin{array}{l@{\\ }c@{\\ }l@{\\ }c@{\\ }l}\nl_R&\\leq&x_R&\\leq&u_R\\\\\nl_S&\\leq&x_S&\\leq&u_S\\\\\n\\end{array}\\eqno(3.3)\n$$\nwhere:\n\n$x_R=(x_1,\\dots,x_m)$ is the vector of auxiliary variables;\n\n$x_S=(x_{m+1},\\dots,x_{m+n})$ is the vector of structural variables;\n\n$z$ is the objective function;\n\n$c=(c_1,\\dots,c_n)$ is the vector of objective coefficients;\n\n$c_0$ is the constant term (``shift'') of the objective function;\n\n$A=(a_{11},\\dots,a_{mn})$ is the constraint matrix;\n\n$l_R=(l_1,\\dots,l_m)$ is the vector of lower bounds of auxiliary\nvariables;\n\n$u_R=(u_1,\\dots,u_m)$ is the vector of upper bounds of auxiliary\nvariables;\n\n$l_S=(l_{m+1},\\dots,l_{m+n})$ is the vector of lower bounds of\nstructural variables;\n\n$u_S=(u_{m+1},\\dots,u_{m+n})$ is the vector of upper bounds of\nstructural variables.\n\nFrom the simplex method's standpoint there is no difference between\nauxiliary and structural variables. This allows combining all these\nvariables into one vector that leads to the following problem\nstatement:\n\n\\noindent\n\\hspace{.5in} minimize (or maximize)\n$$z=(0\\ |\\ c)^Tx+c_0\\eqno(3.4)$$\n\\hspace{.5in} subject to linear constraints\n$$(I\\ |-\\!A)x=0\\eqno(3.5)$$\n\\hspace{.5in} and bounds of variables\n$$l\\leq x\\leq u\\eqno(3.6)$$\nwhere:\n\n$x=(x_R\\ |\\ x_S)$ is the $(m+n)$-vector of (all) variables;\n\n$(0\\ |\\ c)$ is the $(m+n)$-vector of objective\ncoefficients;\\footnote{Subvector 0 corresponds to objective\ncoefficients at auxiliary variables.}\n\n$(I\\ |-\\!A)$ is the {\\it augmented} constraint\n$m\\times(m+n)$-matrix;\\footnote{Note that due to auxiliary variables\nmatrix $(I\\ |-\\!A)$ contains the unity submatrix and therefore has full\nrank. This means, in particular, that the system (3.5) has no linearly\ndependent constraints.}\n\n$l=(l_R\\ |\\ l_S)$ is the $(m+n)$-vector of lower bounds of (all)\nvariables;\n\n$u=(u_R\\ |\\ u_S)$ is the $(m+n)$-vector of upper bounds of (all)\nvariables.\n\nBy definition an {\\it LP basic solution} geometrically is a point in\nthe space of all variables, which is the intersection of hyperplanes\ncorresponding to active constraints\\footnote{A constraint is called\n{\\it active} if at a given point it is satisfied as equality, otherwise\nit is called {\\it inactive}.}. The space of all variables has the\ndimension $m+n$, therefore, to define some basic solution we have to\ndefine $m+n$ active constraints. Note that $m$ constraints (3.5) being\nlinearly independent equalities are always active, so remaining $n$\nactive constraints can be chosen only from bound constraints (3.6).\n\nA variable is called {\\it non-basic}, if its (lower or upper) bound is\nactive, otherwise it is called {\\it basic}. Since, as was said above,\nexactly $n$ bound constraints must be active, in any basic solution\nthere are always $n$ non-basic variables and $m$ basic variables.\n(Note that a free variable also can be non-basic. Although such\nvariable has no bounds, we can think it as the difference between two\nnon-negative variables, which both are non-basic in this case.)\n\nNow consider how to determine numeric values of all variables for a\ngiven basic solution.\n\nLet $\\Pi$ be an appropriate permutation matrix of the order $(m+n)$.\nThen we can write:\n$$\\left(\\begin{array}{@{}c@{}}x_B\\\\x_N\\\\\\end{array}\\right)=\n\\Pi\\left(\\begin{array}{@{}c@{}}x_R\\\\x_S\\\\\\end{array}\\right)=\\Pi x,\n\\eqno(3.7)$$\nwhere $x_B$ is the vector of basic variables, $x_N$ is the vector of\nnon-basic variables, $x=(x_R\\ |\\ x_S)$ is the vector of all variables\nin the original order. In this case the system of linear constraints\n(3.5) can be rewritten as follows:\n$$(I\\ |-\\!A)\\Pi^T\\Pi x=0\\ \\ \\ \\Rightarrow\\ \\ \\ (B\\ |\\ N)\n\\left(\\begin{array}{@{}c@{}}x_B\\\\x_N\\\\\\end{array}\\right)=0,\\eqno(3.8)$$\nwhere\n$$(B\\ |\\ N)=(I\\ |-\\!A)\\Pi^T.\\eqno(3.9)$$\n\n\\newpage\n\nMatrix $B$ is a square non-singular $m\\times m$-matrix, which is\ncomposed from columns of the augmented constraint matrix corresponding\nto basic variables. It is called the {\\it basis matrix} or simply the\n{\\it basis}. Matrix $N$ is a rectangular $m\\times n$-matrix, which is\ncomposed from columns of the augmented constraint matrix corresponding\nto non-basic variables.\n\nFrom (3.8) it follows that:\n$$Bx_B+Nx_N=0,\\eqno(3.10)$$\ntherefore,\n$$x_B=-B^{-1}Nx_N.\\eqno(3.11)$$\nThus, the formula (3.11) shows how to determine numeric values of basic\nvariables $x_B$ assuming that non-basic variables $x_N$ are fixed on\ntheir active bounds.\n\nThe $m\\times n$-matrix\n$$\\Xi=-B^{-1}N,\\eqno(3.12)$$\nwhich appears in (3.11), is called the {\\it simplex\ntableau}.\\footnote{This definition corresponds to the GLPK\nimplementation.} It shows how basic variables depend on non-basic\nvariables:\n$$x_B=\\Xi x_N.\\eqno(3.13)$$\n\nThe system (3.13) is equivalent to the system (3.5) in the sense that\nthey both define the same set of points in the space of (primal)\nvariables, which satisfy to these systems. If, moreover, values of all\nbasic variables satisfy to their bound constraints (3.3), the\ncorresponding basic solution is called {\\it (primal) feasible},\notherwise {\\it (primal) infeasible}. It is understood that any (primal)\nfeasible basic solution satisfy to all constraints (3.2) and (3.3).\n\nThe LP theory says that if LP has optimal solution, it has (at least\none) basic feasible solution, which corresponds to the optimum. And the\nmost natural way to determine whether a given basic solution is optimal\nor not is to use the Karush---Kuhn---Tucker optimality conditions.\n\n\\def\\arraystretch{1.5}\n\nFor the problem statement (3.4)---(3.6) the optimality conditions are\nthe following:\\footnote{These conditions can be appiled to any solution,\nnot only to a basic solution.}\n$$(I\\ |-\\!A)x=0\\eqno(3.14)$$\n$$(I\\ |-\\!A)^T\\pi+\\lambda_l+\\lambda_u=\\nabla z=(0\\ |\\ c)^T\\eqno(3.15)$$\n$$l\\leq x\\leq u\\eqno(3.16)$$\n$$\\lambda_l\\geq 0,\\ \\ \\lambda_u\\leq 0\\ \\ \\mbox{(minimization)}\n\\eqno(3.17)$$\n$$\\lambda_l\\leq 0,\\ \\ \\lambda_u\\geq 0\\ \\ \\mbox{(maximization)}\n\\eqno(3.18)$$\n$$(\\lambda_l)_k(x_k-l_k)=0,\\ \\ (\\lambda_u)_k(x_k-u_k)=0,\\ \\ k=1,2,\\dots,\nm+n\\eqno(3.19)$$\nwhere:\n$\\pi=(\\pi_1,\\pi_2,\\dots,\\pi_m)$ is a $m$-vector of Lagrange\nmultipliers for equality constraints (3.5);\n$\\lambda_l=[(\\lambda_l)_1,(\\lambda_l)_2,\\dots,(\\lambda_l)_n]$ is a\n$n$-vector of Lagrange multipliers for lower bound constraints (3.6);\n$\\lambda_u=[(\\lambda_u)_1,(\\lambda_u)_2,\\dots,(\\lambda_u)_n]$ is a\n$n$-vector of Lagrange multipliers for upper bound constraints (3.6).\n\n\\newpage\n\nCondition (3.14) is the {\\it primal} (original) system of equality\nconstraints (3.5).\n\nCondition (3.15) is the {\\it dual} system of equality constraints.\nIt requires the gradient of the objective function to be a linear\ncombination of normals to the planes defined by constraints of the\noriginal problem.\n\nCondition (3.16) is the primal (original) system of bound constraints\n(3.6).\n\nCondition (3.17) (or (3.18) in case of maximization) is the dual system\nof bound constraints.\n\nCondition (3.19) is the {\\it complementary slackness condition}. It\nrequires, for each original (auxiliary or structural) variable $x_k$,\nthat either its (lower or upper) bound must be active, or zero bound of\nthe corresponding Lagrange multiplier ($(\\lambda_l)_k$ or\n$(\\lambda_u)_k$) must be active.\n\nIn GLPK two multipliers $(\\lambda_l)_k$ and $(\\lambda_u)_k$ for each\nprimal (original) variable $x_k$, $k=1,2,\\dots,\\linebreak m+n$, are\ncombined into one multiplier:\n$$\\lambda_k=(\\lambda_l)_k+(\\lambda_u)_k,\\eqno(3.20)$$\nwhich is called a {\\it dual variable} for $x_k$. This {\\it cannot} lead\nto the ambiguity, because both lower and upper bounds of $x_k$ cannot be\nactive at the same time,\\footnote{If $x_k$ is a fixed variable, we can\nthink it as double-bounded variable $l_k\\leq x_k\\leq u_k$, where\n$l_k=u_k.$} so at least one of $(\\lambda_l)_k$ and $(\\lambda_u)_k$ must\nbe equal to zero, and because these multipliers have different signs,\nthe combined multiplier, which is their sum, uniquely defines each of\nthem.\n\n\\def\\arraystretch{1}\n\nUsing dual variables $\\lambda_k$ the dual system of bound constraints\n(3.17) and (3.18) can be written in the form of so called {\\it ``rule of\nsigns''} as follows:\n\n\\medskip\n\n\\begin{center}\n\\begin{tabular}{|@{\\,}c@{$\\,$}|@{$\\,$}c@{$\\,$}|@{$\\,$}c@{$\\,$}|\n@{$\\,$}c|c@{$\\,$}|@{$\\,$}c@{$\\,$}|@{$\\,$}c@{$\\,$}|}\n\\hline\nOriginal bound&\\multicolumn{3}{c|}{Minimization}&\\multicolumn{3}{c|}\n{Maximization}\\\\\n\\cline{2-7}\nconstraint&$(\\lambda_l)_k$&$(\\lambda_u)_k$&$(\\lambda_l)_k+\n(\\lambda_u)_k$&$(\\lambda_l)_k$&$(\\lambda_u)_k$&$(\\lambda_l)_k+\n(\\lambda_u)_k$\\\\\n\\hline\n$-\\infty<x_k<+\\infty$&$=0$&$=0$&$\\lambda_k=0$&$=0$&$=0$&$\\lambda_k=0$\\\\\n$x_k\\geq l_k$&$\\geq 0$&$=0$&$\\lambda_k\\geq 0$&$\\leq 0$&$=0$&$\\lambda_k\n\\leq0$\\\\\n$x_k\\leq u_k$&$=0$&$\\leq 0$&$\\lambda_k\\leq 0$&$=0$&$\\geq 0$&$\\lambda_k\n\\geq0$\\\\\n$l_k\\leq x_k\\leq u_k$&$\\geq 0$& $\\leq 0$& $-\\infty\\!<\\!\\lambda_k\\!<\n\\!+\\infty$\n&$\\leq 0$& $\\geq 0$& $-\\infty\\!<\\!\\lambda_k\\!<\\!+\\infty$\\\\\n$x_k=l_k=u_k$&$\\geq 0$& $\\leq 0$& $-\\infty\\!<\\!\\lambda_k\\!<\\!+\\infty$&\n$\\leq 0$&\n$\\geq 0$& $-\\infty\\!<\\!\\lambda_k\\!<\\!+\\infty$\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\medskip\n\nMay note that each primal variable $x_k$ has its dual counterpart\n$\\lambda_k$ and vice versa. This allows applying the same partition for\nthe vector of dual variables as (3.7):\n$$\\left(\\begin{array}{@{}c@{}}\\lambda_B\\\\\\lambda_N\\\\\\end{array}\\right)=\n\\Pi\\lambda,\\eqno(3.21)$$\nwhere $\\lambda_B$ is a vector of dual variables for basic variables\n$x_B$, $\\lambda_N$ is a vector of dual variables for non-basic variables\n$x_N$.\n\nBy definition, bounds of basic variables are inactive constraints, so in\nany basic solution $\\lambda_B=0$. Corresponding values of dual variables\n$\\lambda_N$ for non-basic variables $x_N$ can be determined in the\nfollowing way. From the dual system (3.15) we have:\n$$(I\\ |-\\!A)^T\\pi+\\lambda=(0\\ |\\ c)^T,\\eqno(3.22)$$\n\n\\newpage\n\n\\noindent\nso multiplying both sides of (3.22) by matrix $\\Pi$ gives:\n$$\\Pi(I\\ |-\\!A)^T\\pi+\\Pi\\lambda=\\Pi(0\\ |\\ c)^T.\\eqno(3.23)$$\nFrom (3.9) it follows that\n$$\\Pi(I\\ |-\\!A)^T=[(I\\ |-\\!A)\\Pi^T]^T=(B\\ |\\ N)^T.\\eqno(3.24)$$\nFurther, we can apply the partition (3.7) also to the vector of\nobjective coefficients (see (3.4)):\n$$\\left(\\begin{array}{@{}c@{}}c_B\\\\c_N\\\\\\end{array}\\right)=\n\\Pi\\left(\\begin{array}{@{}c@{}}0\\\\c\\\\\\end{array}\\right),\\eqno(3.25)$$\nwhere $c_B$ is a vector of objective coefficients at basic variables,\n$c_N$ is a vector of objective coefficients at non-basic variables.\nNow, substituting (3.24), (3.21), and (3.25) into (3.23), leads to:\n$$(B\\ |\\ N)^T\\pi+(\\lambda_B\\ |\\ \\lambda_N)^T=(c_B\\ |\\ c_N)^T,\n\\eqno(3.26)$$\nand transposing both sides of (3.26) gives the system:\n$$\\left(\\begin{array}{@{}c@{}}B^T\\\\N^T\\\\\\end{array}\\right)\\pi+\n\\left(\\begin{array}{@{}c@{}}\\lambda_B\\\\\\lambda_N\\\\\\end{array}\\right)=\n\\left(\\begin{array}{@{}c@{}}c_B\\\\c_T\\\\\\end{array}\\right),\\eqno(3.27)$$\nwhich can be written as follows:\n$$\\left\\{\n\\begin{array}{@{\\ }r@{\\ }c@{\\ }r@{\\ }c@{\\ }l@{\\ }}\nB^T\\pi&+&\\lambda_B&=&c_B\\\\\nN^T\\pi&+&\\lambda_N&=&c_N\\\\\n\\end{array}\n\\right.\\eqno(3.28)\n$$\nLagrange multipliers $\\pi=(\\pi_i)$ correspond to equality constraints\n(3.5) and therefore can have any sign. This allows resolving the first\nsubsystem of (3.28) as follows:\\footnote{$B^{-T}$ means $(B^T)^{-1}=\n(B^{-1})^T$.}\n$$\\pi=B^{-T}(c_B-\\lambda_B)=-B^{-T}\\lambda_B+B^{-T}c_B,\\eqno(3.29)$$\nand substitution of $\\pi$ from (3.29) into the second subsystem of\n(3.28) gives:\n$$\\lambda_N=-N^T\\pi+c_N=N^TB^{-T}\\lambda_B+(c_N-N^TB^{-T}c_B).\n\\eqno(3.30)$$\nThe latter system can be written in the following final form:\n$$\\lambda_N=-\\Xi^T\\lambda_B+d,\\eqno(3.31)$$\nwhere $\\Xi$ is the simplex tableau (see (3.12)), and\n$$d=c_N-N^TB^{-T}c_B=c_N+\\Xi^Tc_B\\eqno(3.32)$$\nis the vector of so called {\\it reduced costs} of non-basic variables.\n\nAbove it was said that in any basic solution $\\lambda_B=0$, so\n$\\lambda_N=d$ as it follows from (3.31).\n\nThe system (3.31) is equivalent to the system (3.15) in the sense that\nthey both define the same set of points in the space of dual variables\n$\\lambda$, which satisfy to these systems. If, moreover, values of all\ndual variables $\\lambda_N$ (i.e. reduced costs $d$) satisfy to their\nbound constraints (i.e. to the ``rule of signs''; see the table above),\nthe corresponding basic solution is called {\\it dual feasible},\notherwise {\\it dual infeasible}. It is understood that any dual feasible\nsolution satisfy to all constraints (3.15) and (3.17) (or (3.18) in case\nof maximization).\n\nIt can be easily shown that the complementary slackness condition\n(3.19) is always satisfied for {\\it any} basic solution.\\footnote{Until\ndouble-bounded variables appear.} Therefore, a basic\nsolution\\footnote{It is assumed that a complete basic solution has the\nform $(x,\\lambda)$, i.e. it includes primal as well as dual variables.}\nis {\\it optimal} if and only if it is primal and dual feasible, because\nin this case it satifies to all the optimality conditions\n(3.14)---(3.19).\n\n\\def\\arraystretch{1.5}\n\nThe meaning of reduced costs $d=(d_j)$ of non-basic variables can be\nexplained in the following way. From (3.4), (3.7), and (3.25) it follows\nthat:\n$$z=c_B^Tx_B+c_N^Tx_N+c_0.\\eqno(3.33)$$\nSubstituting $x_B$ from (3.11) into (3.33) we can eliminate basic\nvariables and express the objective only through non-basic variables:\n$$\n\\begin{array}{r@{\\ }c@{\\ }l}\nz&=&c_B^T(-B^{-1}Nx_N)+c_N^Tx_N+c_0=\\\\\n&=&(c_N^T-c_B^TB^{-1}N)x_N+c_0=\\\\\n&=&(c_N-N^TB^{-T}c_B)^Tx_N+c_0=\\\\\n&=&d^Tx_N+c_0.\n\\end{array}\\eqno(3.34)\n$$\nFrom (3.34) it is seen that reduced cost $d_j$ shows how the objective\nfunction $z$ depends on non-basic variable $(x_N)_j$ in the neighborhood\nof the current basic solution, i.e. while the current basis remains\nunchanged.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\newpage\n\n\\section{LP basis routines}\n\\label{lpbasis}\n\n\\subsection{glp\\_bf\\_exists --- check if the basis factorization\nexists}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_bf_exists(glp_prob *P);\n\\end{verbatim}\n\n\\returns\n\nIf the basis factorization for the current basis associated with the\nspecified problem object exists and therefore is available for\ncomputations, the routine \\verb|glp_bf_exists| returns non-zero.\nOtherwise the routine returns zero.\n\n\\para{Comments}\n\nLet the problem object have $m$ rows and $n$ columns. In GLPK the\n{\\it basis matrix} $B$ is a square non-singular matrix of the order $m$,\nwhose columns correspond to basic (auxiliary and/or structural)\nvariables. It is defined by the following main\nequality:\\footnote{For more details see Subsection \\ref{basbgd},\npage \\pageref{basbgd}.}\n$$(B\\ |\\ N)=(I\\ |-\\!A)\\Pi^T,$$\nwhere $I$ is the unity matrix of the order $m$, whose columns correspond\nto auxiliary variables; $A$ is the original constraint\n$m\\times n$-matrix, whose columns correspond to structural variables;\n$(I\\ |-\\!A)$ is the augmented constraint $m\\times(m+n)$-matrix, whose\ncolumns correspond to all (auxiliary and structural) variables\nfollowing in the original order; $\\Pi$ is a permutation matrix of the\norder $m+n$; and $N$ is a rectangular $m\\times n$-matrix, whose columns\ncorrespond to non-basic (auxiliary and/or structural) variables.\n\nFor various reasons it may be necessary to solve linear systems with\nmatrix $B$. To provide this possibility the GLPK implementation\nmaintains an invertable form of $B$ (that is, some representation of\n$B^{-1}$) called the {\\it basis factorization}, which is an internal\ncomponent of the problem object. Typically, the basis factorization is\ncomputed by the simplex solver, which keeps it in the problem object\nto be available for other computations.\n\nShould note that any changes in the problem object, which affects the\nbasis matrix (e.g. changing the status of a row or column, changing\na basic column of the constraint matrix, removing an active constraint,\netc.), invalidates the basis factorization. So before calling any API\nroutine, which uses the basis factorization, the application program\nmust make sure (using the routine \\verb|glp_bf_exists|) that the\nfactorization exists and therefore available for computations.\n\n\\newpage\n\n\\subsection{glp\\_factorize --- compute the basis factorization}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_factorize(glp_prob *P);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_factorize| computes the basis factorization for\nthe current basis associated with the specified problem\nobject.\\footnote{The current basis is defined by the current statuses\nof rows (auxiliary variables) and columns (structural variables).}\n\nThe basis factorization is computed from ``scratch'' even if it exists,\nso the application program may use the routine \\verb|glp_bf_exists|,\nand, if the basis factorization already exists, not to call the routine\n\\verb|glp_factorize| to prevent an extra work.\n\nThe routine \\verb|glp_factorize| {\\it does not} compute components of\nthe basic solution (i.e. primal and dual values).\n\n\\returns\n\n\\begin{retlist}\n0 & The basis factorization has been successfully computed.\\\\\n\\verb|GLP_EBADB| & The basis matrix is invalid, because the number of\nbasic (auxiliary and structural) variables is not the same as the number\nof rows in the problem object.\\\\\n\n\\verb|GLP_ESING| & The basis matrix is singular within the working\nprecision.\\\\\n\n\\verb|GLP_ECOND| & The basis matrix is ill-conditioned, i.e. its\ncondition number is too large.\\\\\n\\end{retlist}\n\n\\subsection{glp\\_bf\\_updated --- check if the basis factorization has\nbeen updated}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_bf_updated(glp_prob *P);\n\\end{verbatim}\n\n\\returns\n\nIf the basis factorization has been just computed from ``scratch'', the\nroutine \\verb|glp_bf_updated| returns zero. Otherwise, if the\nfactorization has been updated at least once, the routine returns\nnon-zero.\n\n\\para{Comments}\n\n{\\it Updating} the basis factorization means recomputing it to reflect\nchanges in the basis matrix. For example, on every iteration of the\nsimplex method some column of the current basis matrix is replaced by\na new column that gives a new basis matrix corresponding to the\nadjacent basis. In this case computing the basis factorization for the\nadjacent basis from ``scratch'' (as the routine \\verb|glp_factorize|\ndoes) would be too time-consuming.\n\nOn the other hand, since the basis factorization update is a numeric\ncomputational procedure, applying it many times may lead to\naccumulating round-off errors. Therefore the basis is periodically\nrefactorized (reinverted) from ``scratch'' (with the routine\n\\verb|glp_factorize|) that allows improving its numerical properties.\n\nThe routine \\verb|glp_bf_updated| allows determining if the basis\nfactorization has been updated at least once since it was computed from\n``scratch''.\n\n\\subsection{glp\\_get\\_bfcp --- retrieve basis factorization control\nparameters}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_get_bfcp(glp_prob *P, glp_bfcp *parm);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_get_bfcp| retrieves control parameters, which are\nused on computing and updating the basis factorization associated with\nthe specified problem object.\n\nCurrent values of the control parameters are stored in\na \\verb|glp_bfcp| structure, which the parameter \\verb|parm| points to.\nFor a detailed description of the structure \\verb|glp_bfcp| see\ncomments to the routine \\verb|glp_set_bfcp| in the next subsection.\n\n\\para{Comments}\n\nThe purpose of the routine \\verb|glp_get_bfcp| is two-fold. First, it\nallows the application program obtaining current values of control\nparameters used by internal GLPK routines, which compute and update the\nbasis factorization.\n\nThe second purpose of this routine is to provide proper values for all\nfields of the structure \\verb|glp_bfcp| in the case when the\napplication program needs to change some control parameters.\n\n\\subsection{glp\\_set\\_bfcp --- change basis factorization control\nparameters}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_set_bfcp(glp_prob *P, const glp_bfcp *parm);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_set_bfcp| changes control parameters, which are\nused by internal GLPK routines on computing and updating the basis\nfactorization associated with the specified problem object.\n\nNew values of the control parameters should be passed in a structure\n\\verb|glp_bfcp|, which the parameter \\verb|parm| points to. For a\ndetailed description of the structure \\verb|glp_bfcp| see paragraph\n``Control parameters'' below.\n\nThe parameter \\verb|parm| can be specified as \\verb|NULL|, in which\ncase all control parameters are reset to their default values.\n\n\\para{Comments}\n\nBefore changing some control parameters with the routine\n\\verb|glp_set_bfcp| the application program should retrieve current\nvalues of all control parameters with the routine \\verb|glp_get_bfcp|.\nThis is needed for backward compatibility, because in the future there\nmay appear new members in the structure \\verb|glp_bfcp|.\n\nNote that new values of control parameters come into effect on a next\ncomputation of the basis factorization, not immediately.\n\n\\para{Example}\n\n\\begin{footnotesize}\n\\begin{verbatim}\nglp_prob *lp;\nglp_bfcp parm;\n. . .\n/* retrieve current values of control parameters */\nglp_get_bfcp(lp, &parm);\n/* change the threshold pivoting tolerance */\nparm.piv_tol = 0.05;\n/* set new values of control parameters */\nglp_set_bfcp(lp, &parm);\n. . .\n\\end{verbatim}\n\\end{footnotesize}\n\n\\para{Control parameters}\n\nThis paragraph describes all basis factorization control parameters\ncurrently used in the package. Symbolic names of control parameters are\nnames of corresponding members in the structure \\verb|glp_bfcp|.\n\n\\medskip\n\n{\\tt int type} (default: {\\tt GLP\\_BF\\_LUF + GLP\\_BF\\_FT})\n\nBasis factorization type:\n\n\\verb~GLP_BF_LUF + GLP_BF_FT~ --- $LUF$, Forrest--Tomlin update;\n\n\\verb~GLP_BF_LUF + GLP_BF_BG~ --- $LUF$, Schur complement,\nBartels--Golub update;\n\n\\verb~GLP_BF_LUF + GLP_BF_GR~ --- $LUF$, Schur complement,\nGivens rotation update;\n\n\\verb~GLP_BF_BTF + GLP_BF_BG~ --- $BTF$, Schur complement,\nBartels--Golub update;\n\n\\verb~GLP_BF_BTF + GLP_BF_GR~ --- $BTF$, Schur complement,\nGivens rotation update.\n\nIn case of \\verb|GLP_BF_FT| the update is applied to matrix $U$, while\nin cases of \\verb|GLP_BF_BG| and \\verb|GLP_BF_GR| the update is applied\nto the Schur complement.\n\n%\\medskip\n%\n%{\\tt int lu\\_size} (default: {\\tt 0})\n%\n%The initial size of the Sparse Vector Area, in non-zeros, used on\n%computing $LU$-factorization of the basis matrix for the first time.\n%If this parameter is set to 0, the initial SVA size is determined\n%automatically.\n\n\\medskip\n\n{\\tt double piv\\_tol} (default: {\\tt 0.10})\n\nThreshold pivoting (Markowitz) tolerance, 0 $<$ \\verb|piv_tol| $<$ 1,\nused on computing $LU$-factoriza\\-tion of the basis matrix. Element\n$u_{ij}$ of the active submatrix of factor $U$ fits to be pivot if it\nsatisfies to the stability criterion\n$|u_{ij}| >= {\\tt piv\\_tol}\\cdot\\max|u_{i*}|$, i.e. if it is not very\nsmall in the magnitude among other elements in the same row. Decreasing\nthis parameter may lead to better sparsity at the expense of numerical\naccuracy, and vice versa.\n\n\\medskip\n\n{\\tt int piv\\_lim} (default: {\\tt 4})\n\nThis parameter is used on computing $LU$-factorization of the basis\nmatrix and specifies how many pivot candidates needs to be considered\non choosing a pivot element, \\verb|piv_lim| $\\geq$ 1. If \\verb|piv_lim|\ncandidates have been considered, the pivoting routine prematurely\nterminates the search with the best candidate found.\n\n\\newpage\n\n{\\tt int suhl} (default: {\\tt GLP\\_ON})\n\nThis parameter is used on computing $LU$-factorization of the basis\nmatrix. Being set to {\\tt GLP\\_ON} it enables applying the following\nheuristic proposed by Uwe Suhl: if a column of the active submatrix has\nno eligible pivot candidates, it is no more considered until it becomes\na column singleton. In many cases this allows reducing the time needed\nfor pivot searching. To disable this heuristic the parameter\n\\verb|suhl| should be set to {\\tt GLP\\_OFF}.\n\n\\medskip\n\n{\\tt double eps\\_tol} (default: {\\tt 1e-15})\n\nEpsilon tolerance, \\verb|eps_tol| $\\geq$ 0, used on computing\n$LU$-factorization of the basis matrix. If an element of the active\nsubmatrix of factor $U$ is less than \\verb|eps_tol| in the magnitude,\nit is replaced by exact zero.\n\n%\\medskip\n%\n%{\\tt double max\\_gro} (default: {\\tt 1e+10})\n%\n%Maximal growth of elements of factor $U$, \\verb|max_gro| $\\geq$ 1,\n%allowable on computing $LU$-factorization of the basis matrix. If on\n%some elimination step the ratio $u_{big}/b_{max}$ (where $u_{big}$ is\n%the largest magnitude of elements of factor $U$ appeared in its active\n%submatrix during all the factorization process, $b_{max}$ is the\n%largest magnitude of elements of the basis matrix to be factorized),\n%the basis matrix is considered as ill-conditioned.\n\n\\medskip\n\n{\\tt int nfs\\_max} (default: {\\tt 100})\n\nMaximal number of additional row-like factors (entries of the eta\nfile), \\verb|nfs_max| $\\geq$ 1, which can be added to\n$LU$-factorization of the basis matrix on updating it with the\nForrest--Tomlin technique. This parameter is used only once, before\n$LU$-factorization is computed for the first time, to allocate working\narrays. As a rule, each update adds one new factor (however, some\nupdates may need no addition), so this parameter limits the number of\nupdates between refactorizations.\n\n\\medskip\n\n{\\tt double upd\\_tol} (default: {\\tt 1e-6})\n\nUpdate tolerance, 0 $<$ \\verb|upd_tol| $<$ 1, used on updating\n$LU$-factorization of the basis matrix with the Forrest--Tomlin\ntechnique. If after updating the magnitude of some diagonal element\n$u_{kk}$ of factor $U$ becomes less than\n${\\tt upd\\_tol}\\cdot\\max(|u_{k*}|, |u_{*k}|)$, the factorization is\nconsidered as inaccurate.\n\n\\medskip\n\n{\\tt int nrs\\_max} (default: {\\tt 100})\n\nMaximal number of additional rows and columns, \\verb|nrs_max| $\\geq$ 1,\nwhich can be added to $LU$-factorization of the basis matrix on\nupdating it with the Schur complement technique. This parameter is used\nonly once, before $LU$-factorization is computed for the first time, to\nallocate working arrays. As a rule, each update adds one new row and\ncolumn (however, some updates may need no addition), so this parameter\nlimits the number of updates between refactorizations.\n\n%\\medskip\n%\n%{\\tt int rs\\_size} (default: {\\tt 0})\n%\n%The initial size of the Sparse Vector Area, in non-zeros, used to\n%store non-zero elements of additional rows and columns introduced on\n%updating $LU$-factorization of the basis matrix with the Schur\n%complement technique. If this parameter is set to 0, the initial SVA\n%size is determined automatically.\n\n\\subsection{glp\\_get\\_bhead --- retrieve the basis header information}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_get_bhead(glp_prob *P, int k);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_get_bhead| returns the basis header information\nfor the current basis associated with the specified problem object.\n\n\\returns\n\nIf basic variable $(x_B)_k$, $1\\leq k\\leq m$, is $i$-th auxiliary\nvariable ($1\\leq i\\leq m$), the routine returns $i$. Otherwise, if\n$(x_B)_k$ is $j$-th structural variable ($1\\leq j\\leq n$), the routine\nreturns $m+j$. Here $m$ is the number of rows and $n$ is the number of\ncolumns in the problem object.\n\n\\para{Comments}\n\nSometimes the application program may need to know which original\n(auxiliary and structural) variable correspond to a given basic\nvariable, or, that is the same, which column of the augmented\nconstraint matrix $(I\\ |-\\!A)$ correspond to a given column of the\nbasis matrix $B$.\n\n\\def\\arraystretch{1}\n\nThe correspondence is defined as follows:\\footnote{For more details see\nSubsection \\ref{basbgd}, page \\pageref{basbgd}.}\n$$\\left(\\begin{array}{@{}c@{}}x_B\\\\x_N\\\\\\end{array}\\right)=\n\\Pi\\left(\\begin{array}{@{}c@{}}x_R\\\\x_S\\\\\\end{array}\\right)\n\\ \\ \\Leftrightarrow\n\\ \\ \\left(\\begin{array}{@{}c@{}}x_R\\\\x_S\\\\\\end{array}\\right)=\n\\Pi^T\\left(\\begin{array}{@{}c@{}}x_B\\\\x_N\\\\\\end{array}\\right),$$\nwhere $x_B$ is the vector of basic variables, $x_N$ is the vector of\nnon-basic variables, $x_R$ is the vector of auxiliary variables\nfollowing in their original order,\\footnote{The original order of\nauxiliary and structural variables is defined by the ordinal numbers\nof corresponding rows and columns in the problem object.} $x_S$ is the\nvector of structural variables following in their original order, $\\Pi$\nis a permutation matrix (which is a component of the basis\nfactorization).\n\nThus, if $(x_B)_k=(x_R)_i$ is $i$-th auxiliary variable, the routine\nreturns $i$, and if $(x_B)_k=(x_S)_j$ is $j$-th structural variable,\nthe routine returns $m+j$, where $m$ is the number of rows in the\nproblem object.\n\n\\subsection{glp\\_get\\_row\\_bind --- retrieve row index in the basis\nheader}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_get_row_bind(glp_prob *P, int i);\n\\end{verbatim}\n\n\\returns\n\nThe routine \\verb|glp_get_row_bind| returns the index $k$ of basic\nvariable $(x_B)_k$, $1\\leq k\\leq m$, which is $i$-th auxiliary variable\n(that is, the auxiliary variable corresponding to $i$-th row),\n$1\\leq i\\leq m$, in the current basis associated with the specified\nproblem object, where $m$ is the number of rows. However, if $i$-th\nauxiliary variable is non-basic, the routine returns zero.\n\n\\para{Comments}\n\nThe routine \\verb|glp_get_row_bind| is an inversion of the routine\n\\verb|glp_get_bhead|; that is, if \\linebreak\n\\verb|glp_get_bhead|$(P,k)$ returns $i$,\n\\verb|glp_get_row_bind|$(P,i)$ returns $k$, and vice versa.\n\n\\subsection{glp\\_get\\_col\\_bind --- retrieve column index in the basis\nheader}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_get_col_bind(glp_prob *P, int j);\n\\end{verbatim}\n\n\\returns\n\nThe routine \\verb|glp_get_col_bind| returns the index $k$ of basic\nvariable $(x_B)_k$, $1\\leq k\\leq m$, which is $j$-th structural\nvariable (that is, the structural variable corresponding to $j$-th\ncolumn), $1\\leq j\\leq n$, in the current basis associated with the\nspecified problem object, where $m$ is the number of rows, $n$ is the\nnumber of columns. However, if $j$-th structural variable is non-basic,\nthe routine returns zero.\n\n\\para{Comments}\n\nThe routine \\verb|glp_get_col_bind| is an inversion of the routine\n\\verb|glp_get_bhead|; that is, if \\linebreak\n\\verb|glp_get_bhead|$(P,k)$ returns $m+j$,\n\\verb|glp_get_col_bind|$(P,j)$ returns $k$, and vice versa.\n\n\\subsection{glp\\_ftran --- perform forward transformation}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_ftran(glp_prob *P, double x[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_ftran| performs forward transformation (FTRAN),\ni.e. it solves the system $Bx=b$, where $B$ is the basis matrix\nassociated with the specified problem object, $x$ is the vector of\nunknowns to be computed, $b$ is the vector of right-hand sides.\n\nOn entry to the routine elements of the vector $b$ should be stored in\nlocations \\verb|x[1]|, \\dots, \\verb|x[m]|, where $m$ is the number of\nrows. On exit the routine stores elements of the vector $x$ in the same\nlocations.\n\n\\subsection{glp\\_btran --- perform backward transformation}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_btran(glp_prob *P, double x[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_btran| performs backward transformation (BTRAN),\ni.e. it solves the system $B^Tx=b$, where $B^T$ is a matrix transposed\nto the basis matrix $B$ associated with the specified problem object,\n$x$ is the vector of unknowns to be computed, $b$ is the vector of\nright-hand sides.\n\nOn entry to the routine elements of the vector $b$ should be stored in\nlocations \\verb|x[1]|, \\dots, \\verb|x[m]|, where $m$ is the number of\nrows. On exit the routine stores elements of the vector $x$ in the same\nlocations.\n\n\\subsection{glp\\_warm\\_up --- ``warm up'' LP basis}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_warm_up(glp_prob *P);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_warm_up| ``warms up'' the LP basis for the\nspecified problem object using current statuses assigned to rows and\ncolumns (that is, to auxiliary and structural variables).\n\nThis operation includes computing factorization of the basis matrix\n(if it does not exist), computing primal and dual components of basic\nsolution, and determining the solution status.\n\n\\returns\n\n\\begin{retlist}\n0 & The operation has been successfully performed.\\\\\n\n\\verb|GLP_EBADB| & The basis matrix is invalid, because the number of\nbasic (auxiliary and structural) variables is not the same as the\nnumber of rows in the problem object.\\\\\n\n\\verb|GLP_ESING| & The basis matrix is singular within the working\nprecision.\\\\\n\n\\verb|GLP_ECOND| & The basis matrix is ill-conditioned, i.e. its\ncondition number is too large.\\\\\n\\end{retlist}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\newpage\n\n\\section{Simplex tableau routines}\n\n\\subsection{glp\\_eval\\_tab\\_row --- compute row of the tableau}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_eval_tab_row(glp_prob *P, int k, int ind[], double val[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_eval_tab_row| computes a row of the current\nsimplex tableau (see Subsection 3.1.1, formula (3.12)), which (row)\ncorresponds to some basic variable specified by the parameter $k$ as\nfollows: if $1\\leq k\\leq m$, the basic variable is $k$-th auxiliary\nvariable, and if $m+1\\leq k\\leq m+n$, the basic variable is $(k-m)$-th\nstructural variable, where $m$ is the number of rows and $n$ is the\nnumber of columns in the specified problem object. The basis\nfactorization must exist.\n\nThe computed row shows how the specified basic variable depends on\nnon-basic variables:\n$$x_k=(x_B)_i=\\xi_{i1}(x_N)_1+\\xi_{i2}(x_N)_2+\\dots+\\xi_{in}(x_N)_n,$$\nwhere $\\xi_{i1}$, $\\xi_{i2}$, \\dots, $\\xi_{in}$ are elements of the\nsimplex table row, $(x_N)_1$, $(x_N)_2$, \\dots, $(x_N)_n$ are non-basic\n(auxiliary and structural) variables.\n\nThe routine stores column indices and corresponding numeric values of\nnon-zero elements of the computed row in unordered sparse format in\nlocations \\verb|ind[1]|, \\dots, \\verb|ind[len]| and \\verb|val[1]|,\n\\dots, \\verb|val[len]|, respectively, where $0\\leq{\\tt len}\\leq n$ is\nthe number of non-zero elements in the row returned on exit.\n\nElement indices stored in the array \\verb|ind| have the same sense as\nindex $k$, i.e. indices 1 to $m$ denote auxiliary variables while\nindices $m+1$ to $m+n$ denote structural variables (all these variables\nare obviously non-basic by definition).\n\n\\returns\n\nThe routine \\verb|glp_eval_tab_row| returns \\verb|len|, which is the\nnumber of non-zero elements in the simplex table row stored in the\narrays \\verb|ind| and \\verb|val|.\n\n\\para{Comments}\n\nA row of the simplex table is computed as follows. At first, the\nroutine checks that the specified variable $x_k$ is basic and uses the\npermutation matrix $\\Pi$ (3.7) to determine index $i$ of basic variable\n$(x_B)_i$, which corresponds to $x_k$.\n\nThe row to be computed is $i$-th row of the matrix $\\Xi$ (3.12),\ntherefore:\n$$\\xi_i=e_i^T\\Xi=-e_i^TB^{-1}N=-(B^{-T}e_i)^TN,$$\nwhere $e_i$ is $i$-th unity vector. So the routine performs BTRAN to\nobtain $i$-th row of the inverse $B^{-1}$:\n$$\\varrho_i=B^{-T}e_i,$$\nand then computes elements of the simplex table row as inner products:\n$$\\xi_{ij}=-\\varrho_i^TN_j,\\ \\ j=1,2,\\dots,n,$$\nwhere $N_j$ is $j$-th column of matrix $N$ (3.9), which (column)\ncorresponds to non-basic variable $(x_N)_j$. The permutation matrix\n$\\Pi$ is used again to convert indices $j$ of non-basic columns to\noriginal ordinal numbers of auxiliary and structural variables.\n\n\\subsection{glp\\_eval\\_tab\\_col --- compute column of the tableau}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_eval_tab_col(glp_prob *P, int k, int ind[], double val[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_eval_tab_col| computes a column of the current\nsimplex tableau (see Subsection 3.1.1, formula (3.12)), which (column)\ncorresponds to some non-basic variable specified by the parameter $k$:\nif $1\\leq k\\leq m$, the non-basic variable is $k$-th auxiliary\nvariable, and if $m+1\\leq k\\leq m+n$, the non-basic variable is\n$(k-m)$-th structural variable, where $m$ is the number of rows and $n$\nis the number of columns in the specified problem object. The basis\nfactorization must exist.\n\nThe computed column shows how basic variables depends on the specified\nnon-basic variable $x_k=(x_N)_j$:\n$$\n\\begin{array}{r@{\\ }c@{\\ }l@{\\ }l}\n(x_B)_1&=&\\dots+\\xi_{1j}(x_N)_j&+\\dots\\\\\n(x_B)_2&=&\\dots+\\xi_{2j}(x_N)_j&+\\dots\\\\\n.\\ \\ .&.&.\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\\\\n(x_B)_m&=&\\dots+\\xi_{mj}(x_N)_j&+\\dots\\\\\n\\end{array}\n$$\nwhere $\\xi_{1j}$, $\\xi_{2j}$, \\dots, $\\xi_{mj}$ are elements of the\nsimplex table column, $(x_B)_1$, $(x_B)_2$, \\dots, $(x_B)_m$ are basic\n(auxiliary and structural) variables.\n\nThe routine stores row indices and corresponding numeric values of\nnon-zero elements of the computed column in unordered sparse format in\nlocations \\verb|ind[1]|, \\dots, \\verb|ind[len]| and \\verb|val[1]|,\n\\dots, \\verb|val[len]|, respectively, where $0\\leq{\\tt len}\\leq m$ is\nthe number of non-zero elements in the column returned on exit.\n\nElement indices stored in the array \\verb|ind| have the same sense as\nindex $k$, i.e. indices 1 to $m$ denote auxiliary variables while\nindices $m+1$ to $m+n$ denote structural variables (all these variables\nare obviously basic by definition).\n\n\\returns\n\nThe routine \\verb|glp_eval_tab_col| returns \\verb|len|, which is the\nnumber of non-zero elements in the simplex table column stored in the\narrays \\verb|ind| and \\verb|val|.\n\n\\para{Comments}\n\nA column of the simplex table is computed as follows. At first, the\nroutine checks that the specified variable $x_k$ is non-basic and uses\nthe permutation matrix $\\Pi$ (3.7) to determine index $j$ of non-basic\nvariable $(x_N)_j$, which corresponds to $x_k$.\n\nThe column to be computed is $j$-th column of the matrix $\\Xi$ (3.12),\ntherefore:\n$$\\Xi_j=\\Xi e_j=-B^{-1}Ne_j=-B^{-1}N_j,$$\nwhere $e_j$ is $j$-th unity vector, $N_j$ is $j$-th column of matrix\n$N$ (3.9). So the routine performs FTRAN to transform $N_j$ to the\nsimplex table column $\\Xi_j=(\\xi_{ij})$ and uses the permutation matrix\n$\\Pi$ to convert row indices $i$ to original ordinal numbers of\nauxiliary and structural variables.\n\n\\subsection{glp\\_transform\\_row --- transform explicitly specified row}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_transform_row(glp_prob *P, int len, int ind[], double val[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_transform_row| performs the same operation as the\nroutine \\verb|glp_eval_tab_row| with exception that the row to be\ntransformed is specified explicitly as a sparse vector.\n\nThe explicitly specified row may be thought as a linear form:\n$$x=a_1x_{m+1}+a_2x_{m+2}+\\dots+a_nx_{m+n},$$\nwhere $x$ is an auxiliary variable for this row, $a_j$ are coefficients\nof the linear form, $x_{m+j}$ are structural variables.\n\nOn entry column indices and numerical values of non-zero coefficients\n$a_j$ of the specified row should be placed in locations \\verb|ind[1]|,\n\\dots, \\verb|ind[len]| and \\verb|val[1]|, \\dots, \\verb|val[len]|, where\n\\verb|len| is number of non-zero coefficients.\n\nThis routine uses the system of equality constraints and the current\nbasis in order to express the auxiliary variable $x$ through the current\nnon-basic variables (as if the transformed row were added to the problem\nobject and the auxiliary variable $x$ were basic), i.e. the resultant\nrow has the form:\n$$x=\\xi_1(x_N)_1+\\xi_2(x_N)_2+\\dots+\\xi_n(x_N)_n,$$\nwhere $\\xi_j$ are influence coefficients, $(x_N)_j$ are non-basic\n(auxiliary and structural) variables, $n$ is the number of columns in\nthe problem object.\n\nOn exit the routine stores indices and numerical values of non-zero\ncoefficients $\\xi_j$ of the resultant row in locations \\verb|ind[1]|,\n\\dots, \\verb|ind[len']| and \\verb|val[1]|, \\dots, \\verb|val[len']|,\nwhere $0\\leq{\\tt len'}\\leq n$ is the number of non-zero coefficients in\nthe resultant row returned by the routine. Note that indices of\nnon-basic variables stored in the array \\verb|ind| correspond to\noriginal ordinal numbers of variables: indices 1 to $m$ mean auxiliary\nvariables and indices $m+1$ to $m+n$ mean structural ones.\n\n\\returns\n\nThe routine \\verb|glp_transform_row| returns \\verb|len'|, the number of\nnon-zero coefficients in the resultant row stored in the arrays\n\\verb|ind| and \\verb|val|.\n\n\\newpage\n\n\\subsection{glp\\_transform\\_col --- transform explicitly specified\ncolumn}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_transform_col(glp_prob *P, int len, int ind[], double val[]);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_transform_col| performs the same operation as the\nroutine \\verb|glp_eval_tab_col| with exception that the column to be\ntransformed is specified explicitly as a sparse vector.\n\nThe explicitly specified column may be thought as it were added to\nthe original system of equality constraints:\n$$\n\\begin{array}{l@{\\ }c@{\\ }r@{\\ }c@{\\ }r@{\\ }c@{\\ }r}\nx_1&=&a_{11}x_{m+1}&+\\dots+&a_{1n}x_{m+n}&+&a_1x \\\\\nx_2&=&a_{21}x_{m+1}&+\\dots+&a_{2n}x_{m+n}&+&a_2x \\\\\n\\multicolumn{7}{c}\n{.\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .}\\\\\nx_m&=&a_{m1}x_{m+1}&+\\dots+&a_{mn}x_{m+n}&+&a_mx \\\\\n\\end{array}\n$$\nwhere $x_i$ are auxiliary variables, $x_{m+j}$ are structural variables\n(presented in the problem object), $x$ is a structural variable for the\nexplicitly specified column, $a_i$ are constraint coefficients at $x$.\n\nOn entry row indices and numerical values of non-zero coefficients\n$a_i$ of the specified column should be placed in locations\n\\verb|ind[1]|, \\dots, \\verb|ind[len]| and \\verb|val[1]|, \\dots,\n\\verb|val[len]|, where \\verb|len| is number of non-zero coefficients.\n\nThis routine uses the system of equality constraints and the current\nbasis in order to express the current basic variables through the\nstructural variable $x$ (as if the transformed column were added to the\nproblem object and the variable $x$ were non-basic):\n$$\n\\begin{array}{l@{\\ }c@{\\ }r}\n(x_B)_1&=\\dots+&\\xi_{1}x\\\\\n(x_B)_2&=\\dots+&\\xi_{2}x\\\\\n\\multicolumn{3}{c}{.\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .}\\\\\n(x_B)_m&=\\dots+&\\xi_{m}x\\\\\n\\end{array}\n$$\nwhere $\\xi_i$ are influence coefficients, $x_B$ are basic (auxiliary\nand structural) variables, $m$ is the number of rows in the problem\nobject.\n\nOn exit the routine stores indices and numerical values of non-zero\ncoefficients $\\xi_i$ of the resultant column in locations \\verb|ind[1]|,\n\\dots, \\verb|ind[len']| and \\verb|val[1]|, \\dots, \\verb|val[len']|,\nwhere $0\\leq{\\tt len'}\\leq m$ is the number of non-zero coefficients in\nthe resultant column returned by the routine. Note that indices of basic\nvariables stored in the array \\verb|ind| correspond to original ordinal\nnumbers of variables, i.e. indices 1 to $m$ mean auxiliary variables,\nindices $m+1$ to $m+n$ mean structural ones.\n\n\\returns\n\nThe routine \\verb|glp_transform_col| returns \\verb|len'|, the number of\nnon-zero coefficients in the resultant column stored in the arrays\n\\verb|ind| and \\verb|val|.\n\n\\newpage\n\n\\subsection{glp\\_prim\\_rtest --- perform primal ratio test}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_prim_rtest(glp_prob *P, int len, const int ind[], const double val[],\n                      int dir, double eps);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_prim_rtest| performs the primal ratio test using\nan explicitly specified column of the simplex table.\n\nThe current basic solution associated with the LP problem object must\nbe primal feasible.\n\nThe explicitly specified column of the simplex table shows how the\nbasic variables $x_B$ depend on some non-basic variable $x$ (which is\nnot necessarily presented in the problem object):\n$$\n\\begin{array}{l@{\\ }c@{\\ }r}\n(x_B)_1&=\\dots+&\\xi_{1}x\\\\\n(x_B)_2&=\\dots+&\\xi_{2}x\\\\\n\\multicolumn{3}{c}{.\\ \\ .\\ \\ .\\ \\ .\\ \\ .\\ \\ .}\\\\\n(x_B)_m&=\\dots+&\\xi_{m}x\\\\\n\\end{array}\n$$\n\nThe column is specifed on entry to the routine in sparse format.\nOrdinal numbers of basic variables $(x_B)_i$ should be placed in\nlocations \\verb|ind[1]|, \\dots, \\verb|ind[len]|, where ordinal number\n1 to $m$ denote auxiliary variables, and ordinal numbers $m+1$ to $m+n$\ndenote structural variables. The corresponding non-zero coefficients\n$\\xi_i$ should be placed in locations\n\\verb|val[1]|, \\dots, \\verb|val[len]|. The arrays \\verb|ind| and\n\\verb|val| are not changed by the routine.\n\nThe parameter \\verb|dir| specifies direction in which the variable $x$\nchanges on entering the basis: $+1$ means increasing, $-1$ means\ndecreasing.\n\nThe parameter \\verb|eps| is an absolute tolerance (small positive\nnumber, say, $10^{-9}$) used by the routine to skip $\\xi_i$'s whose\nmagnitude is less than \\verb|eps|.\n\nThe routine determines which basic variable (among those specified in\n\\verb|ind[1]|, \\dots, \\verb|ind[len]|) reaches its (lower or upper)\nbound first before any other basic variables do, and which, therefore,\nshould leave the basis in order to keep primal feasibility.\n\n\\returns\n\nThe routine \\verb|glp_prim_rtest| returns the index, \\verb|piv|, in the\narrays \\verb|ind| and \\verb|val| corresponding to the pivot element\nchosen, $1\\leq$ \\verb|piv| $\\leq$ \\verb|len|. If the adjacent basic\nsolution is primal unbounded, and therefore the choice cannot be made,\nthe routine returns zero.\n\n\\para{Comments}\n\nIf the non-basic variable $x$ is presented in the LP problem object,\nthe input column can be computed with the routine\n\\verb|glp_eval_tab_col|; otherwise, it can be computed with the routine\n\\verb|glp_transform_col|.\n\n\\newpage\n\n\\subsection{glp\\_dual\\_rtest --- perform dual ratio test}\n\n\\synopsis\n\n\\begin{verbatim}\n   int glp_dual_rtest(glp_prob *P, int len, const int ind[], const double val[],\n                      int dir, double eps);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_dual_rtest| performs the dual ratio test using\nan explicitly specified row of the simplex table.\n\nThe current basic solution associated with the LP problem object must\nbe dual feasible.\n\nThe explicitly specified row of the simplex table is a linear form\nthat shows how some basic variable $x$ (which is not necessarily\npresented in the problem object) depends on non-basic variables $x_N$:\n$$x=\\xi_1(x_N)_1+\\xi_2(x_N)_2+\\dots+\\xi_n(x_N)_n.$$\n\nThe row is specified on entry to the routine in sparse format. Ordinal\nnumbers of non-basic variables $(x_N)_j$ should be placed in locations\n\\verb|ind[1]|, \\dots, \\verb|ind[len]|, where ordinal numbers 1 to $m$\ndenote auxiliary variables, and ordinal numbers $m+1$ to $m+n$ denote\nstructural variables. The corresponding non-zero coefficients $\\xi_j$\nshould be placed in locations \\verb|val[1]|, \\dots, \\verb|val[len]|.\nThe arrays \\verb|ind| and \\verb|val| are not changed by the routine.\n\nThe parameter \\verb|dir| specifies direction in which the variable $x$\nchanges on leaving the basis: $+1$ means that $x$ goes on its lower\nbound, so its reduced cost (dual variable) is increasing (minimization)\nor decreasing (maximization); $-1$ means that $x$ goes on its upper\nbound, so its reduced cost is decreasing (minimization) or increasing\n(maximization).\n\nThe parameter \\verb|eps| is an absolute tolerance (small positive\nnumber, say, $10^{-9}$) used by the routine to skip $\\xi_j$'s whose\nmagnitude is less than \\verb|eps|.\n\nThe routine determines which non-basic variable (among those specified\nin \\verb|ind[1]|, \\dots,\\linebreak \\verb|ind[len]|) should enter the\nbasis in order to keep dual feasibility, because its reduced cost\nreaches the (zero) bound first before this occurs for any other\nnon-basic variables.\n\n\\returns\n\nThe routine \\verb|glp_dual_rtest| returns the index, \\verb|piv|, in the\narrays \\verb|ind| and \\verb|val| corresponding to the pivot element\nchosen, $1\\leq$ \\verb|piv| $\\leq$ \\verb|len|. If the adjacent basic\nsolution is dual unbounded, and therefore the choice cannot be made,\nthe routine returns zero.\n\n\\para{Comments}\n\nIf the basic variable $x$ is presented in the LP problem object, the\ninput row can be computed\\linebreak with the routine\n\\verb|glp_eval_tab_row|; otherwise, it can be computed with the routine\n\\linebreak \\verb|glp_transform_row|.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\newpage\n\n\\section{Post-optimal analysis routines}\n\n\\subsection{glp\\_analyze\\_bound --- analyze active bound of non-basic\nvariable}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_analyze_bound(glp_prob *P, int k, double *limit1, int *var1,\n                          double *limit2, int *var2);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_analyze_bound| analyzes the effect of varying the\nactive bound of specified non-basic variable.\n\nThe non-basic variable is specified by the parameter $k$, where\n$1\\leq k\\leq m$ means auxiliary variable of corresponding row, and\n$m+1\\leq k\\leq m+n$ means structural variable (column).\n\nNote that the current basic solution must be optimal, and the basis\nfactorization must exist.\n\nResults of the analysis have the following meaning.\n\n\\verb|value1| is the minimal value of the active bound, at which the\nbasis still remains primal feasible and thus optimal. \\verb|-DBL_MAX|\nmeans that the active bound has no lower limit.\n\n\\verb|var1| is the ordinal number of an auxiliary (1 to $m$) or\nstructural ($m+1$ to $m+n$) basic variable, which reaches its bound\nfirst and thereby limits further decreasing the active bound being\nanalyzed. if \\verb|value1| = \\verb|-DBL_MAX|, \\verb|var1| is set to 0.\n\n\\verb|value2| is the maximal value of the active bound, at which the\nbasis still remains primal feasible and thus optimal. \\verb|+DBL_MAX|\nmeans that the active bound has no upper limit.\n\n\\verb|var2| is the ordinal number of an auxiliary (1 to $m$) or\nstructural ($m+1$ to $m+n$) basic variable, which reaches its bound\nfirst and thereby limits further increasing the active bound being\nanalyzed. if \\verb|value2| = \\verb|+DBL_MAX|, \\verb|var2| is set to 0.\n\nThe parameters \\verb|value1|, \\verb|var1|, \\verb|value2|, \\verb|var2|\ncan be specified as \\verb|NULL|, in which case corresponding information\nis not stored.\n\n\\subsection{glp\\_analyze\\_coef --- analyze objective coefficient at\nbasic variable}\n\n\\synopsis\n\n\\begin{verbatim}\n   void glp_analyze_coef(glp_prob *P, int k,\n                         double *coef1, int *var1, double *value1,\n                         double *coef2, int *var2, double *value2);\n\\end{verbatim}\n\n\\description\n\nThe routine \\verb|glp_analyze_coef| analyzes the effect of varying the\nobjective coefficient at specified basic variable.\n\nThe basic variable is specified by the parameter $k$, where\n$1\\leq k\\leq m$ means auxiliary variable of corresponding row, and\n$m+1\\leq k\\leq m+n$ means structural variable (column).\n\nNote that the current basic solution must be optimal, and the basis\nfactorization must exist.\n\nResults of the analysis have the following meaning.\n\n\\verb|coef1| is the minimal value of the objective coefficient, at\nwhich the basis still remains dual feasible and thus optimal.\n\\verb|-DBL_MAX| means that the objective coefficient has no lower\nlimit.\n\n\\verb|var1| is the ordinal number of an auxiliary (1 to $m$) or\nstructural ($m+1$ to $m+n$) non-basic variable, whose reduced cost\nreaches its zero bound first and thereby limits further decreasing the\nobjective coefficient being analyzed.\nIf \\verb|coef1| = \\verb|-DBL_MAX|, \\verb|var1| is set to 0.\n\n\\verb|value1| is value of the basic variable being analyzed in an\nadjacent basis, which is defined as follows. Let the objective\ncoefficient reach its minimal value (\\verb|coef1|) and continue\ndecreasing. Then the reduced cost of the limiting non-basic variable\n(\\verb|var1|) becomes dual infeasible and the current basis becomes\nnon-optimal that forces the limiting non-basic variable to enter the\nbasis replacing there some basic variable that leaves the basis to keep\nprimal feasibility. Should note that on determining the adjacent basis\ncurrent bounds of the basic variable being analyzed are ignored as if\nit were free (unbounded) variable, so it cannot leave the basis. It may\nhappen that no dual feasible adjacent basis exists, in which case\n\\verb|value1| is set to \\verb|-DBL_MAX| or \\verb|+DBL_MAX|.\n\n\\verb|coef2| is the maximal value of the objective coefficient, at\nwhich the basis still remains dual feasible and thus optimal.\n\\verb|+DBL_MAX| means that the objective coefficient has no upper\nlimit.\n\n\\verb|var2| is the ordinal number of an auxiliary (1 to $m$) or\nstructural ($m+1$ to $m+n$) non-basic variable, whose reduced cost\nreaches its zero bound first and thereby limits further increasing the\nobjective coefficient being analyzed.\nIf \\verb|coef2| = \\verb|+DBL_MAX|, \\verb|var2| is set to 0.\n\n\\verb|value2| is value of the basic variable being analyzed in an\nadjacent basis, which is defined exactly in the same way as\n\\verb|value1| above with exception that now the objective coefficient\nis increasing.\n\nThe parameters \\verb|coef1|, \\verb|var1|, \\verb|value1|, \\verb|coef2|,\n\\verb|var2|, \\verb|value2| can be specified as \\verb|NULL|, in which\ncase corresponding information is not stored.\n\n%* eof *%\n", "meta": {"hexsha": "2367db5738fb51b054c8e6a26837bcc0c14533ce", "size": 53063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sdk/mmitss/src/glpk-4.55/doc/glpk04.tex", "max_stars_repo_name": "OSADP/MMITSS_AZ_FIELD", "max_stars_repo_head_hexsha": "b4c870061c518eddfa0152938ab60abc2a31023f", "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": "sdk/mmitss/src/glpk-4.55/doc/glpk04.tex", "max_issues_repo_name": "OSADP/MMITSS_AZ_FIELD", "max_issues_repo_head_hexsha": "b4c870061c518eddfa0152938ab60abc2a31023f", "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": "sdk/mmitss/src/glpk-4.55/doc/glpk04.tex", "max_forks_repo_name": "OSADP/MMITSS_AZ_FIELD", "max_forks_repo_head_hexsha": "b4c870061c518eddfa0152938ab60abc2a31023f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-04T16:41:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-01T20:32:44.000Z", "avg_line_length": 38.2298270893, "max_line_length": 80, "alphanum_fraction": 0.7319412773, "num_tokens": 15544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.610680235648159}}
{"text": "\\section{Evaluation}\n\\label{sec:evaluation}\n%\nIn this section, we introduce several pairs of coding solutions,\ntranslated to functional programs.\n%\nFor each pair of programs $P_0$ and $P_1$, we identify an inductive\nset of pairs of expressions $I$, and give a map from all pairs of\nexpressions in $I$ to relational invariants that prove the partial\nequivalence of $P_0$ and $P_1$.\n\n\\paragraph{Solutions to Add Digits}\n%\n\\NV{complete}\n\n\\paragraph{Solutions to Climbing Stairs}\n%\n\\begin{figure}[t]\n  \\begin{minipage}{0.48\\linewidth}\n    \\input{code/ClimbStairs0.ml}\n  \\end{minipage}\n  \\begin{minipage}{0.48\\linewidth}\n    \\input{code/ClimbStairs1.ml}    \n  \\end{minipage}\n  %\n  \\caption{\\cc{ClimbStairs0} and \\cc{ClimbStairs1}: two solutions to\n    the Climbing Stairs problem hosted on LeetCode, manually translated\n    to OCaml.\n    %\n    All subexpressions are labeled with indices in comments.\n    %\n  }\n  \\label{fig:climb-stairs}\n\\end{figure}\n%\n\\autoref{fig:climb-stairs} contains the pseudocode for two solutions\nto the Climbing Stairs Problem hosted on the coding platform the\nLeetCode.\n% problem statement:\nThe Climbing Stairs Problem is to take an integer $n$ and return the\nnumber of distinct sequences of steps that can be taken to climb $n$\nsteps, where in each step either one or two steps can be climbed. If\n$n$ is less than or equal to one, then the solution is one.\n%\n\\BH{walk through how the two solutions work}\n\n%\n\\cc{climbStairs0} and \\cc{climbStairs1} have the following proof of\npartial equivalence:\n%\n\\BH{put the pairs of subexpressions in a set}\n%\n\\begin{align*}\n  % pair of main subexpressions:\n  (\\cc{0}, \\cc{0}) \\mapsto & %\n  \\alpha_0^0 = \\alpha_1^0 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair of function bodies:\n  (\\cc{1}, \\cc{1}) \\mapsto & %\n  \\cc{n}_0 = \\cc{n}_1 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair of if guards:\n  (\\cc{2}, \\cc{2}) \\mapsto & %\n  \\cc{n}_0 = \\cc{n}_1 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair of then expressions:\n  (\\cc{3}, \\cc{3}) \\mapsto & \\nu_0 = \\nu_1 \\\\\n  % pair of else expressions:\n  (\\cc{4}, \\cc{4}) \\mapsto & %\n  \\cc{n}_0 = \\cc{n}_1 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair of fixpoint functions:\n  (\\cc{5}, \\cc{5}) \\mapsto & %\n  % inductive relational invariant (indices in step):\n  (\\cc{n}_0 = \\cc{n}_1 \\land %\n  \\alpha_0^0 = \\alpha_1^1 \\land %\n  \\alpha_0^1 = \\alpha_1^1 \\land %\n  \\alpha_0^3 + 1 = \\alpha_1^2 \\implies %\n  \\nu_0 = \\nu_1) \\land \\\\\n  % for establishing final property:\n  & (\\cc{n}_0 = \\cc{n}_1 \\land %\n  \\alpha_0^0 = \\alpha_0^1 + \\alpha_1^1 \\land %\n  \\alpha_0^1 = \\alpha_1^1 \\land %\n  \\alpha_0^3 = \\alpha_1^2 \\implies %\n  \\nu_0 = \\nu_1) \\\\\n  % pair of argument vectors:\n  (\\cc{6}, \\cc{6}) \\mapsto & %\n  \\pi_0(\\nu_0) = \\pi_0(\\nu_1) + \\pi_1(\\nu_1) \\land %\n  \\pi_1(\\nu_0) = \\pi_1(\\nu_1) \\land %\n  \\pi_3(\\nu_0) = \\pi_3(\\nu_3) \\\\\n  % fixpoint body:\n  (\\cc{7}, \\cc{7}) \\mapsto & \n  % inductive relational invariant (indices in step):\n  (\\cc{n}_0 = \\cc{n}_1 \\land %\n  \\cc{sum}_0 = \\cc{count2}_1 \\land %\n  \\cc{prev}_1 = \\cc{count2}_1 \\land %\n  \\cc{i}_3 + 1 = \\cc{i}_1 \\implies %\n  \\nu_0 = \\nu_1) \\land \\\\\n  % for establishing final property:\n  & (\\cc{n}_0 = \\cc{n}_1 \\land %\n  \\cc{sum}_0 = \\cc{count1}_1 + \\cc{count2}_1 \\land %\n  \\cc{prev}_1 = \\cc{count2}_1 \\land %\n  \\cc{i}_3 = \\cc{i}_1 \\implies %\n  \\nu_0 = \\nu_1) \\\\\n  % fixpoint body guards:\n  (\\cc{8}, \\cc{8}) \\mapsto & 0 \\leq \\cc{i}_1 - \\cc{i}_0 \\leq 1 \\implies %\n  \\nu_0 = \\nu_1 \\\\\n  % fixpoint body then expressions:\n  (\\cc{9}, \\cc{9}) \\mapsto & \n  (\\cc{n}_0 = \\cc{n}_1 \\land %\n  \\cc{sum}_0 = \\cc{count2}_1 \\land %\n  \\cc{prev}_0 = \\cc{count2}_1 \\land %\n  \\cc{i}_0 + 1 = \\cc{i}_1 \\implies %\n  \\nu_0 = \\nu_1) \\land \\\\\n  % for establishing final property:\n  & (\\cc{n}_0 = \\cc{n}_1 \\land \\cc{i}_0 \\land %\n  \\cc{sum}_0 = \\cc{count1}_1 + \\cc{count2}_1 \\land %\n  \\cc{prev}_1 = \\cc{count2}_1 \\land %\n  \\cc{i}_0 = \\cc{i}_1 \\implies %\n  \\nu_0 = \\nu_1) \\\\\n  % fixpoint body else expressions:\n  (\\cc{10}, \\cc{10}) \\mapsto & \\cc{sum}_0 = \\cc{count2}_1 \\implies %\n  \\nu_0 = \\nu_1 \\\\\n  % argument steps preserve relative invariants over arguments:\n  % subcase: CS1 is one step ahead of CS0:\n  (\\cc{11}, \\cc{11}) \\mapsto & \n  (\\cc{sum}_0 = \\cc{count2}_1 \\land %\n  \\cc{prev}_1 = \\cc{count2}_1 \\land %\n  \\cc{i}_3 + 1 = \\cc{i}_1 \\implies \\\\\n  & \\pi_0(\\nu_0) = \\pi_1(\\nu_1) \\land %\n  \\pi_1(\\nu_0) = \\pi_0(\\nu_1) \\land %\n  \\pi_3(\\nu_0) = \\pi_2(\\nu_1)) \\land \\\\\n  %\n  & (\\cc{sum}_0 = \\cc{count1}_1 + \\cc{count2}_1 \\land %\n  \\cc{prev}_1 = \\cc{count2}_1 \\land %\n  \\cc{i}_0 = \\cc{i}_1 \\implies \\\\ %\n  & \\pi_0(\\nu_0) = \\pi_0(\\nu_1) + \\pi_1(\\nu_1) \\land %\n  \\pi_1(\\nu_0) = \\pi_1(\\nu_1) \\land %\n  \\pi_3(\\nu_0) = \\pi_2(\\nu_1)) \\\\\n\\end{align*}\n%\n\\BH{define notation for logical variables}\n%\n\\BH{refactor entries to use common invariant meta-variables}\n\n\\BH{walk through relational invariants}\n\n\\NV{Question: Why 9 has n0 equals tp n1 precondition but 10 does not?}\n\n\\paragraph{Solutions to Reverse}\n%\n\\NV{complete}\n\n\\paragraph{Solutions to Trailing Zeroes}\n\\begin{hcode}\ntrailingZeroes0 {- 0 -} n \n = {- 1 -} go0 ((0, n) {- 2 -}) {- 3 -}\n  where\n    go0 {- 4 -} (x, y) {- 5 -}\n      | 5 <= y  {- 6 -}\n      = go0 ((x + (y `div` 5), y `div` 5) {- 9-}) {- 7 -}\n      | otherwise \n      = x {- 8 -}\n\n\ntrailingZeroes1 {- 0 -} n \n = {- 1 -} go1 ((0, n `div` 5) {- 2 -}) {- 3 -}\n  where \n    go1 {- 4 -} (s, n) {- 5 -}\n      | 0 < n   {- 6 -} \n      = go1 ((s + n, n `div` 5) {- 9 -}) {- 7 -}\n      | otherwise \n      = s {- 8 -}\n\\end{hcode}\n\n\n\\newcommand\\rinv[3]{\\ensuremath{(\\cc{#1}, \\cc{#2}) }}\n\\newcommand\\iinv[2]{\\ensuremath{\\mathcal{I}(#1, #2)}}\n\\newcommand\\precondition[2]{\\ensuremath{\\mathcal{P}(#1, #2)}}\n\\newcommand\\postcondition[2]{\\ensuremath{\\mathcal{Q}(#1, #2)}}\n\n$$\n\\text{Invariant: }\\iinv{x_0}{x_1} = x_0^0 = x_1^0 \\land x_0^1 = x_0^1 / 5\n$$\n$$\n\\text{Precondition: }\\precondition{x_0}{x_1} = x_0^0 = x_1^0 \\land x_0^1 = x_0^1 / 5\n$$\n$$\n\\text{Postcondition: }\\postcondition{x_0}{x_1} = x_0 = x_1\n$$\n\n$$\n\\begin{array}{ r c l}\n  % pair of main subexpressions:\n  \\rinv{0}{0} &\\mapsto& \\alpha_0 = \\alpha_1 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair of body \n  \\rinv{1}{1} &\\mapsto& n_0 = n_1 \\implies \\nu_0 = \\nu_1 \\\\\n  % pair on arguments \n  \\rinv{2}{2} &\\mapsto& \\precondition{\\nu_0}{\\nu_1} \\\\\n  % pair of fixpoint functions (like step 5 above):\n  \\rinv{3}{3} &\\mapsto& n_0 = n_1 \\implies \\postcondition{\\nu_0}{\\nu_1} \\\\\n  % pair of fixpoint functions (like step 5 above):\n  \\rinv{4}{4} &\\mapsto& \\precondition{\\alpha_0}{\\alpha_1} \\implies \\postcondition{\\nu_0}{\\nu_1} \\\\\n  \\rinv{5}{5} &\\mapsto& \\precondition{(x_0, y_0)}{(s_1, n_1)} \\implies \\postcondition{\\nu_0}{\\nu_1} \\\\\n  % pair for condition\n  \\rinv{6}{6}  &\\mapsto&  \\precondition{(x_0, y_0)}{(s_1, n_1)} \n                          \\implies 5 \\leq y_0 \\Leftrightarrow 0 < n_1 \n                          \\implies \\postcondition{\\nu_0}{\\nu_1}   \\\\\n  % pair for then\n  \\rinv{7}{7}  &\\mapsto&  \\precondition{(x_0, y_0)}{(s_1, n_1)} \n                          \\implies \\iinv{(x_0, y_0)}{(s_1, n_1)} \n                          \\implies \\postcondition{\\nu_0}{\\nu_1}   \\\\\n  % pair for else\n  \\rinv{8}{8}  &\\mapsto&  \\precondition{(x_0, y_0)}{(s_1, n_1)} \n                          \\implies x_0 = s_1 \n                          \\implies \\postcondition{\\nu_0}{\\nu_1} \\\\\n  % pair for rec call\n  \\rinv{9}{9}  &\\mapsto& \\iinv{(x_0, y_0)}{(s_1, n_1)} \\implies \\iinv{\\nu_0}{\\nu_1}\\\\\n\\end{array}\n$$\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: t\n%%% End: \n", "meta": {"hexsha": "b9d9c4d12b5e00934508bf3dcbac97ec030002fd", "size": 7371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/paper/evaluation.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/paper/evaluation.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/paper/evaluation.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": 33.2027027027, "max_line_length": 102, "alphanum_fraction": 0.5928639262, "num_tokens": 3025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6106802313303835}}
{"text": "\\documentclass{article}\n\\input{../homework-problems}\n\n\\toggletrue{solutions}\n%\\togglefalse{solutions}\n\\toggletrue{answers}\n\\newtheorem{problem}{Problem}\n\n\\newcommand{\\hide}[1]{}\n\n\\renewcommand{\\fcProblemRef}{\\theproblem.\\theenumi}\n\\renewcommand{\\fcSubProblemRef}{\\theenumi.\\theenumii}\n\n\\begin{document}\n\\begin{center}\n\\Large\nMaster Problem Sheet \\\\ Calculus I \\\\ \n\\end{center}\n\n%\\noindent \\textbf{Name:} \\hfill{~}\n%\\begin{tabular}{c|c|c|c|c|c|c|c|c||c}\n%Problem&1 &2&3&4&5&6&7&8& $\\sum$\\\\ \\hline\n%Score&&&&&&&&&\\\\ \\hline\n%Max&20&20&20&20&20&10&20&20&150\n%\\end{tabular}\n\n\n\n\nThis master problem sheet contains all freecalc problems on the topics studied in Calculus I. For a list of contributors/authors of the freecalc project (and in particular, the present problem collection) see file contributors.tex.\n\n\n\\fcLicenseContent\n\n\n\n\\tableofcontents\n\n\\section{Functions, Basic Facts}\\label{secMPSfunctionBasics}\n\\subsection{Understanding function notation}\n\\begin{problem}\n\\input{\\freecalcBaseFolder/modules/precalculus/homework/functions-evaluate-simplify}\n\\end{problem}\n\\subsection{Domains and ranges}\n\\begin{problem}\n\\input{../../modules/precalculus/homework/functions-domains-ranges-1}\n\\end{problem}\n\\subsection{Piecewise Defined Functions}\n\\begin{problem}\n\\input{../../modules/functions-basics/homework/piecewise-linear-formula-from-plot-1}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/functions-basics/homework/piecewise-linear-piecewise-circular-formula-from-plot-1}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/precalculus/homework/piecewise-defined-plot-from-formula}\n\\end{problem}\n\n\\subsection{Function composition}\n\\begin{problem}\n\\input{../../modules/functions-basics/homework/function-composition-domains-and-ranges-1}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/functions-basics/homework/functions-composing-fractional-linear-1}\n\\end{problem}\n\\subsection{Linear Transformations and Graphs of Functions}\n\\begin{problem}\n\\input{../../modules/precalculus/homework/functions-plot-transformations}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/function-graph-linear-transformations/homework/use-known-graph-to-sketch-its-linear-transformation-1}\n\\end{problem}\n\\input{../../modules/function-graph-linear-transformations/homework/use-known-graph-to-sketch-its-linear-transformation-1-solutions}\n\n\n\\section{Trigonometry}\\label{secMPStrigonometry}\n\\subsection{Angle conversion}\n\\begin{problem}\n\\input{../../modules/trigonometry/homework/trigonometry-angle-conversion-degree-to-radian}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/trigonometry/homework/trigonometry-angle-conversion-radian-to-degree}\n\\end{problem}\n\\subsection{Trigonometry identities}\n\\begin{problem}\n\\input{../../modules/trigonometry/homework/trigonometry-identities}\n\\end{problem}\n\n\\subsection{Trigonometry equations}\n\\begin{problem}\n\\input{../../modules/trigonometry/homework/trigonometry-equations}\n\\end{problem}\n\\input{../../modules/trigonometry/homework/trigonometry-equations-solutions}\n\n\\section{Limits and Continuity}\n\\subsection{Limits as $x$ tends to a number}\\label{secMPSlimitsXtendsToNumer}\n\\begin{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-a-common-factor}\n\\end{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-a-common-factor-solutions}\n\\begin{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-a-common-factor2}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-a-direct-substitution}\n\\end{problem}\n\\subsection{Limits involving $\\infty $}\n\\subsubsection{Limits as $x\\to\\pm \\infty$}\\label{secMPSlimitsXtoInfty}\n\\begin{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-infinity-1}\n\\end{problem}\n\\input{../../modules/limits/homework/limit-x-tends-to-infinity-1-solutions}\n\n\\subsubsection{Limits involving vertical asymptote}\\label{secMPSlimitsVerticalAsymptote}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/asymptotes-vertical}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/asymptotes-vertical2}\n\\end{problem}\n\\input{../../modules/curve-sketching/homework/asymptotes-vertical2-solutions}\n\\subsubsection{Find the Horizontal and Vertical Asymptotes}\\label{secMPShorAndVertAsymptotes}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/asymptotes-vertical-horizontal}\n\\end{problem}\n\\input{../../modules/curve-sketching/homework/asymptotes-vertical-horizontal-solutions}\n\n\\subsection{Limits - All Cases - Problem Collection}\n\\begin{problem}\n\\input{../../modules/limits/homework/limit-problem-collection-1}\n\\end{problem}\n\\subsection{Continuity}\n\\subsubsection{Continuity to evaluate limits}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-to-evaluate-limits-1}\n\\end{problem}\n\n\\subsubsection{Conceptual problems} \\label{secMPScontinuityConceptual}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-problems-involving-understanding}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-problems-involving-understanding-2}\n\\end{problem}\n\\subsubsection{Continuity and Piecewise Defined Functions} \\label{secMPScontinuityPiecewise}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-with-piecewise-defined-functions}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-with-piecewise-defined-functions-2}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/continuity/homework/continuity-with-piecewise-defined-functions-3}\n\\end{problem}\n\\subsection{Intermediate Value Theorem}\\label{secMPSintermediateValueTheorem}\n\\begin{problem}\n\\input{../../modules/continuity/homework/IVT-problems}\n\\end{problem}\n\\input{../../modules/continuity/homework/IVT-problems-solutions}\n\\begin{problem}\n\\input{../../modules/continuity/homework/IVT-problems2}\n\\end{problem}\n\\input{../../modules/continuity/homework/IVT-problems2-solutions}\n\\section{Inverse Functions}\\label{secMPSInverseFunctions}\n\n\\subsection{Problems Using Rational Functions Only}\n\\begin{problem}\n\\input{../../modules/inverse-functions/homework/inverse-functions-no-exponents-logarithms-1}\n\\end{problem}\n\\input{../../modules/inverse-functions/homework/inverse-functions-no-exponents-logarithms-1-solutions}\n\n\\begin{problem}\n\\input{../../modules/inverse-functions/homework/inverse-functions4}\n\\end{problem}\n\n\\subsection{Problems Involving Exponents, Logarithms}\n\\begin{problem}\n\\input{../../modules/inverse-functions/homework/inverse-functions1}\n\\end{problem}\n\\input{../../modules/inverse-functions/homework/inverse-functions1-solutions}\n\n\\section{Logarithms and Exponent Basics}\\label{secMPSLogarithmsExponentsBasics}\n\\subsection{Exponents Basics}\n\\begin{problem}\n\\input{../../modules/exponential-functions/homework/exponent-simplify}\n\\end{problem}\n\\input{../../modules/exponential-functions/homework/exponent-simplify-solutions}\n\n\\subsection{Logarithm Basics}\n\\begin{problem}\n\\input{../../modules/logarithms/homework/logarithms-basic-no-properties-1}\n\\end{problem}\n\\input{../../modules/logarithms/homework/logarithms-basic-properties-1-solutions}\n\\begin{problem}\n\\input{../../modules/logarithms/homework/logarithms-combine-1}\n\\end{problem}\n\\input{../../modules/logarithms/homework/logarithms-combine-1-solutions}\n\\begin{problem}\n\\input{../../modules/logarithms/homework/logarithms-basic-properties-1}\n\\end{problem}\n\\input{../../modules/logarithms/homework/logarithms-basic-properties-1-solutions}\n\n\\subsection{Some Problems Involving Logarithms}\n\\begin{problem}\n\\input{../../modules/logarithms/homework/logarithms-equations}\n\\end{problem}\n\\input{../../modules/logarithms/homework/logarithms-equations-solutions}\n\n\\section{Derivatives}\n\\subsection{Derivatives and Function Graphs: basics}\\label{secMPSderivativesFunGraphsBasics}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/match-graph-to-derivative-graph-2}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/match-graph-to-derivative-graph-2-solution}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/match-graph-to-derivative-graph}\n\\end{problem}\n\\subsection{Product and Quotient Rules}\\label{secMPSproductQuotientRules}\n\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-1}\n\\end{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-1-solutions}\n\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-2}\n\\end{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-2-solutions}\n\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-3}\n\\end{problem}\n\\input{../../modules/derivatives/homework/derivatives-product-quotient-rule-3-solutions}\n\n\\subsection{Basic Trigonometric Derivatives}\\label{secMPStrigDerivatives}\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivatives-trig}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivatives-trig-2}\n\\end{problem}\n\\subsection{Natural Exponent Derivatives}\n\\input{../../modules/exponential-functions/homework/exponent-derivative}\n\n\\subsection{The Chain Rule}\\label{secMPSchainRule}\n\n\\begin{problem}\n\\input{../../modules/chain-rule/homework/chain-rule1}\n\\end{problem}\n\\input{../../modules/chain-rule/homework/chain-rule1-solutions}\n\n\\begin{problem}\n\\input{../../modules/chain-rule/homework/chain-rule2}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/chain-rule/homework/chain-rule3}\n\\end{problem}\n\\input{../../modules/chain-rule/homework/chain-rule3-solutions}\n\n\\begin{problem}\n\\input{../../modules/chain-rule/homework/chain-rule4}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/chain-rule/homework/chain-rule5}\n\\end{problem}\n\\subsection{Problem Collection All Techniques}\n\\begin{problem}\n\\input{../../modules/derivatives/homework/derivative-problem-collection-1}\n\\end{problem}\n\\input{../../modules/derivatives/homework/derivative-problem-collection-1-solutions}\n\n\\subsection{Implicit Differentiation}\\label{secMPSImplicitDifferentiation}\n\\begin{problem}\n\\input{../../modules/implicit-differentiation/homework/implicitly-differentiate}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/implicit-differentiation/homework/implicit-tangent}\n\\end{problem}\n\\input{../../modules/implicit-differentiation/homework/implicit-tangent-solutions}\n\n\\subsection{Implicit Differentiation and Inverse Trigonometric Functions}\n\\begin{problem}\n\\input{../../modules/implicit-differentiation/homework/implicit-inverse-trig1}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/implicit-differentiation/homework/implicit-inverse-trig2}\n\\end{problem}\n\n\\subsection{Derivative of non-Constant Exponent with non-Constant Base}\\label{secMPSDerivativeNonConstExponent}\n\\begin{problem}\n\\input{../../modules/logarithms/homework/derivatives-non-const-exponent-2}\n\\end{problem}\n\\input{../../modules/logarithms/homework/derivatives-non-const-exponent-2-solutions}\n\n\\begin{problem}\n\\input{../../modules/logarithms/homework/derivatives-non-const-exponent}\n\\end{problem}\n\n\\subsection{Related Rates}\\label{secMPSrelatedRates}\n\\begin{problem}\n\\input{../../modules/related-rates/homework/related-rates-text-problems-2}\n\\end{problem}\n\\input{../../modules/related-rates/homework/related-rates-text-problems-2-solutions}\n\\begin{problem}\n\\input{../../modules/related-rates/homework/related-rates-text-problems}\n\\end{problem}\n\\input{../../modules/related-rates/homework/related-rates-text-problems-solutions}\n\n\\section{Graphical Behavior of Functions}\n\\subsection{Mean Value Theorem}\\label{secMPS-MVT}\n\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/find-the-mvt-points-1}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/mvt-to-estimate-fmax-fmin-1}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/mvt-show-only-one-root-1}\n\\end{problem}\n\\input{../../modules/maxima-minima/homework/mvt-show-only-one-root-1-solutions}\n\n\\subsection{Maxima, Minima}\\label{secMPSoneVariableMinMax}\n\\subsubsection{Closed Interval method}\\label{secMPSclosedInterval}\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/maxima-minima}\n\\end{problem}\n\n\\begin{problem}\n\\input{../../modules/logarithms/homework/logarithm-physics}\n\\end{problem}\n\n\\subsubsection{Derivative tests}\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/local-maxima-minima-derivative-tests-1}\n\\end{problem}\n\n\\subsubsection{Optimization}\\label{secMPSoptimization}\n\\begin{problem}\n\\input{../../modules/maxima-minima/homework/maxima-minima-text-problems-1}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/optimization/homework/optimization-problem-collection-1}\n\\end{problem}\n\\input{../../modules/optimization/homework/optimization-problem-collection-1-solutions}\n\n\\subsection{Function Graph Sketching}\\label{secMPSfunctionGraphSketching}\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/sketch-graph-with-all-the-details}\n\\end{problem}\n\\input{../../modules/curve-sketching/homework/sketch-graph-with-all-the-details-solutions}\n\n\\begin{problem}\n\\input{../../modules/curve-sketching/homework/sketch-graph-with-all-the-details-2}\n\\end{problem}\n\n\\section{Linearizations and Differentials} \\label{secMPSLinearizationAndDifferentials}\n\\begin{problem}\n\\input{../../modules/differentials/homework/linearization-problems-1}\n\\end{problem}\n\\input{../../modules/differentials/homework/linearization-problems-1-solutions}\n\n\\section{Integration Basics}\n\\subsection{Riemann Sums}\\label{secMPSRiemannSums}\n\\begin{problem}\n\\input{../../modules/integration/homework/riemann-sum-problems-1}\n\\end{problem}\n\\input{../../modules/integration/homework/riemann-sum-problems-1-solutions}\n\n\\subsection{Antiderivatives}\\label{secMPSantiderivatives}\n\\begin{problem}\n\\input{../../modules/antiderivatives/homework/antiderivatives-basic-integrals-1}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/antiderivatives/homework/antiderivatives-basic-integrals-initial-condition-1}\n\\end{problem}\n\\begin{problem}\n\\input{../../modules/antiderivatives/homework/antiderivatives-verify-by-differentiation-1}\n\\end{problem}\n\n\\subsection{Basic Definite Integrals} \\label{secMPSBasicDefiniteIntegrals}\n\\begin{problem}\n\\input{../../modules/integration/homework/basic-definite-integrals-1}\n\\end{problem}\n\\input{../../modules/integration/homework/basic-definite-integrals-1-solutions}\n\\begin{problem}\n\\input{../../modules/integration/homework/basic-definite-integrals-2}\n\\end{problem}\n\\subsection{Fundamental Theorem of Calculus Part I}\\label{secMPSFTCpart1}\n\\begin{problem}\n\\input{../../modules/integration/homework/FTC-part1-problems-1}\n\\end{problem}\n\\input{../../modules/integration/homework/FTC-part1-problems-1-solutions}\n\n\\subsection{Integration with The Substitution Rule}\n\\label{secMPSintegrationSubstitutionRule}\n\\subsubsection{Substitution in Indefinite Integrals}\n\\label{secMPSintegrationSubstitutionRuleIndefinite}\n\\begin{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-1}\n\\end{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-1-solutions}\n\\begin{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-2}\n\\end{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-2-solutions}\n\n\\subsubsection{Substitution in Definite Integrals}\n\\label{secMPSintegrationSubstitutionRuleDefinite}\n\\begin{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-definite-1}\n\\end{problem}\n\\input{../../modules/substitution-rule/homework/substitution-rule-definite-1-solutions}\n\n\\section{First Applications of Integration}\n\\subsection{Area Between Curves}\\label{secMPSareaBetweenCurves}\n\\begin{problem}\n\\input{../../modules/area-between-curves/homework/area-between-curves-problems-1}\n\\end{problem}\n\\input{../../modules/area-between-curves/homework/area-between-curves-problems-1-solutions}\n\\subsection{Volumes of Solids of Revolution}\\label{secMPSvolumesSolidsRevolution}\n\\subsubsection{Problems Geared towards the Washer Method}\\label{secMPSvolumesSolidsRevolutionWashers}\n\\begin{problem}\n\\input{../../modules/volumes/homework/solids-of-revolution-problems-1}\n\\end{problem}\n\\input{../../modules/volumes/homework/solids-of-revolution-problems-1-solutions}\n\n\\subsubsection{Problems Geared towards the Cylindrical Shells Method}\\label{secMPSvolumesSolidsRevolutionShells}\n\\begin{problem}\n\\input{../../modules/volumes/homework/solids-of-revolution-cylindrical-shells-1}\n\\end{problem}\n\\end{document}", "meta": {"hexsha": "877bb9e8fa1199bf0098eabf7c60732ddcebce4a", "size": 16461, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "homework/referenceallproblemsbycourse/calculusimasterproblemsheet.tex", "max_stars_repo_name": "tmilev/freecalc", "max_stars_repo_head_hexsha": "b34b2ad2946fc0b6a9b403d4399a0cf9d23c19dd", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-07-12T11:15:57.000Z", "max_stars_repo_stars_event_max_datetime": "2017-07-12T11:15:57.000Z", "max_issues_repo_path": "homework/referenceallproblemsbycourse/calculusimasterproblemsheet.tex", "max_issues_repo_name": "tmilev/freecalc", "max_issues_repo_head_hexsha": "b34b2ad2946fc0b6a9b403d4399a0cf9d23c19dd", "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": "homework/referenceallproblemsbycourse/calculusimasterproblemsheet.tex", "max_forks_repo_name": "tmilev/freecalc", "max_forks_repo_head_hexsha": "b34b2ad2946fc0b6a9b403d4399a0cf9d23c19dd", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-09-21T13:51:45.000Z", "max_forks_repo_forks_event_max_datetime": "2017-09-21T13:51:45.000Z", "avg_line_length": 37.4113636364, "max_line_length": 231, "alphanum_fraction": 0.7862219792, "num_tokens": 4588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.61068023012656}}
{"text": "\\section{Implementation} \\label{sec:implementation}\n\n\\subsection{Parameters of the Implementation}\n\n\n\\begin{table}[tbh]\n\\begin{center}\n\\begin{tabular}{p{.2 \\textwidth} | p{.6 \\textwidth} | p{.2 \\textwidth}}\\hline\nField & Description & Default value\\\\ \\hline\n$P\\in\\mathbb{Z}$ & Number of populations. & 1 \\\\\n$n\\in\\mathbb{Z}$ & Maximum number of pure strategies per population. & - \\\\\n$S\\in\\mathbb{Z}^{P}$ & Vector of pure strategies in each population, such that $1<S(i)\\leq n$. & ones(G.P, 1) * G.n \\\\\n$m\\in\\mathbb{R}^P$ & Vector with the mass of each population. & ones(G.P, 1) \\\\\n$x0\\in\\mathbb{R}^{P\\times n}$ & Initial state of the society (normalized). & random \\\\\n$f:\\mathbb{R}^{P\\times n} \\rightarrow \\mathbb{R}^{1\\times n}$ or $f:\\mathbb{R}^{P\\times n} \\rightarrow \\mathbb{R}^{P\\times n}$ & Function that returns the fitness the population's strategies. It might return a vector with the fitness of a single population or the fitness of the whole society. & - \\\\ \npop\\_wise & If true, the fitness function $f$ returns the fitness of a single population. Otherwise, $f$ returns the fitness of the whole society. & True \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Parameters of the game.}\n\\label{tab:game}\n\\end{table}\n\n\n\n\\begin{table}[tbh]\n\\begin{center}\n\\begin{tabular}{p{.2 \\textwidth} | p{.6 \\textwidth} | p{.2 \\textwidth}}\\hline\nField & Description & Default value\\\\ \\hline\node & ODE solver for the evolutionary dynamics. & `ode45' \\\\\ndynamics & Evolutionary dynamic. Current version support combinations of {`rd', `maynard\\_rd',  `bnn', `smith',  `logit'}. & `rd' \\\\\ngamma & Defines the weight given to each dynamic when using combined dynamics. &  $\\sum \\gamma(i) = 1$ \\\\\nstep & Simulations are made using the time spam: step:step:time+step. & $0.01$ \\\\\ntol & Defines the error tolerance of the ODE solver, namely, RelTol and AbsTol. If it is not defined, then RelTol and AbsTol can be assigned independently. &  RelTol=AbsTol=$10^{-4}$\\\\\nstop\\_c  & Enables the interruption of the simulations if the norm of the state's change is less than the parameter c\\_error. & False \\\\\nc\\_error &  Convergence error used to stop the simulations. & $10^{-5}$ \\\\\nverb & Allows the display of information, such as the dynamics used and the time spent running the game. & True \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\caption{Parameters of the dynamical implementation.}\n\\label{tab:req_a}\n\\end{table}\n\n\n\n\n\\begin{table}[tbh]\n\\begin{center}\n\\begin{tabular}{p{.2 \\textwidth} | p{.6 \\textwidth} | p{.2 \\textwidth}}\\hline\nField & Description & Default value \\\\ \\hline\n$N\\in\\mathbb{Z}$ & Number of agents & 100 \\\\\n$R\\in\\mathbb{R}$ & Rate of the Poisson clock & 1 \\\\\ntime & Run time of the simulation (number of iterations in the discrete case). & 30 \\\\\nrevision\\_protocol & Revision protocol. The current version support one of the following: `comparison2average', `pairwise\\_comparison', `logit\\_choice', `proportional\\_imitation'. & `proportional\\_imitation' \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\caption{Parameters of the revision protocol.}\n\\label{tab:req_b}\n\\end{table}\n\n\n\n\nThe toolbox uses a structure that contains all the parameters required to run the simulations. The parameters of a population game are defined in Table \\ref{tab:game}. On the other hand, the parameters to run simulations with large or small number of agents are specified in Tables \\ref{tab:req_a} and \\ref{tab:req_b}, respectively.  In this case the behavior of a population with large and small number of agents is simulated using differential equations and revision protocols, respectively. The following is an example to define a game with one population and three strategies per population:\n%\n\\begin{lstlisting}\nG = struct('n', 3, 'f', @fitness1, 'dynamics', {rd},  'ode', 'ode113', 'x0',  [0.2 .7 0.1]', 'time', 60);\n\\end{lstlisting}\n%\n$n$ defines the number of strategies per population, $f$ is a function handler that calculates the fitness of the strategies in each population, and $dynamics$ defines the name of the evolutionary dynamics that we want to use. The simulations are run using the ordinal differential equation (ODE) solver called $ode113$, with initial condition $x0 = [0.2, \\, 0.7, \\, 0.1 ]^\\top$ during $60$ time units.\nNote that the number of populations and the mass of each population are defined by default to one.  The simulation can be started by executing\n%\n\\begin{lstlisting}\n G.run()\n\\end{lstlisting}\n\n\n\n\nOn the other hand, the following structure is used to define a population game with small number of agents per population:\n%\n\\begin{lstlisting}\nG = struct('N', 200, 'n', 3, 'f', @fitness1, 'x0',  [0.2 .7 0.1]', 'ode', 'ode113', 'time', 10000, 'eta', 0.02, 'revision_protocol', @proportional_imitation); \n\\end{lstlisting}\n%\nThe finite population case uses the same parameters than the dynamical implementation, except for the dynamical model. However, it is necessary to define the revision protocol  and the number of agents $N$ per population.\nTable \\ref{tab:req_b} contains the list of parameters required to run the revision protocol. The simulation of the revision protocol can be started by executing\n\\begin{lstlisting}\n G.run_finite()\n\\end{lstlisting}\n\nThe functions \\verb|G.graph()| and \\verb|G.graph_evolution()| can be used to graph the simplex and the state evolution of the society for both cases.\n\n\n\n\\subsection{Example: Rock-Paper-Scissors Game}\n\n\n\n\\begin{figure}[th]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_finite_proportional_imitation.eps}\n\t  \\caption{Small population.}\n\t  \\label{fig:finite1_protocol}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test1_simplex_rd.eps}\n\t  \\caption{Large popultion.}\n\t  \\label{fig:finite1_dynamics}\n  \\end{subfigure}\n  \\caption{Rock-paper-scissors game with a) proportional imitation revision protocol and b) replicator dynamics.}\n  \\label{fig:finite1}\n\\end{figure}\n\n\n\\begin{figure}[th]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_finite_comparison2average.eps}\n\t  \\caption{Small population.}\n\t  \\label{fig:finite2_protocol}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test1_simplex_bnn.eps}\n\t  \\caption{Large popultion.}\n\t  \\label{fig:finite2_dynamics}\n  \\end{subfigure}\n  \\caption{Rock-paper-scissors game with a) comparison to average revision protocol and b) BNN dynamics.}\n  \\label{fig:finite2}\n\\end{figure}\n\n\n\\begin{figure}[tbh]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_finite_pairwise_comparison.eps}\n\t  \\caption{Small population.}\n\t  \\label{fig:finite3_protocol}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test1_simplex_smith.eps}\n\t  \\caption{Large popultion.}\n\t  \\label{fig:finite3_dynamics}\n  \\end{subfigure}\n  \\caption{Rock-paper-scissors game with a) pairwise comparison revision protocol and b) Smith dynamics.}\n  \\label{fig:finite3}\n\\end{figure}\n\n\n\\begin{figure}[tbh]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test_finite_logit_choice.eps}\n\t  \\caption{Small population.}\n\t  \\label{fig:finite4_protocol}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.4\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test1_simplex_logit.eps}\n\t  \\caption{Large popultion.}\n\t  \\label{fig:finite4_dynamics}\n  \\end{subfigure}\n  \\caption{Rock-paper-scissors game with a) logit choice revision protocol and b) Logit dynamics with $\\eta=0.02$.}\n  \\label{fig:finite4}\n\\end{figure}\n\n\n\n\n\nIn this section, we implement rock-paper-scissors game with both revision protocols and evolutionary dynamics presented above, to observe the behavioral differences between a society with small number of agents and its approximation to a dynamical system.\nThe game has only one population with three strategies, denoted $x = [x_1, \\, x_2, \\, x_3]^\\top$. The fitness function is defined as $F(x)=Ax$, where A is equal to \n\\begin{equation}\n  A = \\begin{pmatrix}\n  2  & 1 &  3 \\\\\n  3  & 2 &  1 \\\\\n  1 &  3 &  2\n  \\end{pmatrix}\n\\end{equation}\nNote that we modify the payoff matrix proposed in the literature to ensure positive payoffs.\nFig. \\ref{fig:finite1} to \\ref{fig:finite4} show the evolution of the society with each revision protocol and its approximation to differential equations. We set the initial condition $x_0 = [0.2, \\, 0.7, \\, 0.1 ]^\\top$. The small population cases are made with $200$ agents and $10000$ iterations. The dynamical cases are run during \n30 time units.\n\n\n%The evolution might take place in days, months, years.\n\n\n\n", "meta": {"hexsha": "01ef8552def94571a85c1e02ad2c4a532e1e4861", "size": 8718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/implementation.tex", "max_stars_repo_name": "carlobar/PDToolbox_matlab", "max_stars_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-08-13T09:50:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T09:22:42.000Z", "max_issues_repo_path": "docs/implementation.tex", "max_issues_repo_name": "sjtudh/PDToolbox_matlab", "max_issues_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-07-25T13:04:08.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-03T21:16:17.000Z", "max_forks_repo_path": "docs/implementation.tex", "max_forks_repo_name": "sjtudh/PDToolbox_matlab", "max_forks_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-07-16T00:40:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T10:20:34.000Z", "avg_line_length": 44.9381443299, "max_line_length": 595, "alphanum_fraction": 0.7311309933, "num_tokens": 2526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6106802289227367}}
{"text": "\\chapter{Conclusion}\nThis paper uses the Gibbs sampler with a Metropolis-Hastings step to generate new samples from a NHPP. Test statistics are used to check if the new samples are from the NHPP. The NHPP used has a rate function which is a combination of a log-linear function and a power-law function. By testing the samples for different parameters in the rate function, non of the null hypothesis were rejected. Hence this sampler can be used to generate new samples from a NHPP given a data set.", "meta": {"hexsha": "84929ea6bd073ca98547d614a10b74a59431fe98", "size": 500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Thesis/chapters/concludingremarks.tex", "max_stars_repo_name": "mariufa/ProsjektOppgave", "max_stars_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_stars_repo_licenses": ["MIT"], "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/chapters/concludingremarks.tex", "max_issues_repo_name": "mariufa/ProsjektOppgave", "max_issues_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_issues_repo_licenses": ["MIT"], "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/chapters/concludingremarks.tex", "max_forks_repo_name": "mariufa/ProsjektOppgave", "max_forks_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 250.0, "max_line_length": 479, "alphanum_fraction": 0.806, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.705785040214066, "lm_q1q2_score": 0.6106622041045866}}
{"text": "String matching is determining all the indices in a source string\nwhere a given target string begins; for example, for source string\n\\texttt{ababab} and target \\texttt{aba} the results of string\nmatching would be \\texttt{[0, 2]}. \n\nWe now define a suitable monoid, @SM target@, for the codomain of\na string matching function, where @target@ is the string being looked\nfor.\n%\nAdditionally, we will define a function @toSM :: RString -> SM target@\nwhich does the string matching and is indeed a monoid morphism from\n@RString@ to @SM target@ for a given @target@.\n\n\\subsubsection{String Matching Monoid}\n\nWe define the data type\n@SM target@ to contain a refined string field @input@ and\na list of all the indices in @input@ where the\n@target@ appears.\n%\n\\begin{code}\n  data SM (target :: Symbol) where\n    SM :: input:RString\n       -> indices:[GoodIndex input target]\n       -> SM target\n\\end{code}\n%\nWe use the string type literal~\\footnote{\\texttt{Symbol} is a kind and\ntarget is effectively a singleton type.} to parameterize the monoid\nover the target being matched. This encoding allows the type checker\nto statically ensure that only searches for the same target can be\nmerged together.  The input field is a refined string, and the indices\nfield is a list of good indices.  For simplicity we present lists as\nHaskell's built-in lists, but our implementation uses the reflected\nlist type, @L@, defined in \\S~\\ref{sec:haskell-proofs}.\n\nA @GoodIndex input target@ is a refined type alias for a natural\nnumber @i@ for which @target@ appears at position @i@ of @input@.  As\nan example, the good indices of @\"abcab\"@ on @\"ababcabcab\"@ are\n@[2,5]@.\n%\n\\begin{code}\n  type GoodIndex Input Target\n    = {i:Nat | isGoodIndex Input (fromString Target) i }\n\n  isGoodIndex :: RString -> RString -> Int -> Bool\n  isGoodIndex input target i\n    = (subString i (lenStr target) input  == target)\n    && (i + lenStr target <= lenStr input)\n\n  subString :: Int -> Int -> RString -> RString\n  subString o l = takeStr l . dropStr o\n\\end{code}\n%\n\\ignore{\n\\begin{code}\ngoodSM :: SM \"abcab\"\ngoodSM = SM \"ababcabcab\" [2, 5]\n\nbadSM  :: SM \"abcab\"\nbadSM  = SM \"ababcabcab\" [0, 7]\n\\end{code}\n\\ignore{\n\\NV{Liquid Haskell actually will reject both the above, as the lenStr and subString functions are uninterpreted}\n}\n}\n\n\\subsubsection{Monoid Methods for String Matching}~\\label{subsec:monoid:methods}\nNext, we define the mappend and identity elements for string matching.\n\nThe \\textit{identity element} @mempty@ of @SM t@, for each target @t@, is\ndefined to contain the identity @RString@ (@stringMempty@) and the\nidentity @List@ (@listMempty@).\n\\begin{code}\n  mempty:: forall (t :: Symbol). SM t\n  mempty = SM stringMempty listMempty\n\\end{code}\n%\n\n\\ignore{\nThe associative operator, @(mappend)@,\nappends the two input strings.\nThe appended indices, as depicted in Figure~\\ref{fig:mappend:indices},\nare the concatenations of three list indices:\n\\begin{enumerate}\n\\item The indices @xis@ of the first input, casted to good indices in the new structure,\n\\item the new indices @xyis@ created when concatenating the two strings, and\n\\item the indices @yis@ of the second input, shifted right @lenStr y@ units.\n\\end{enumerate}\n%\n}\n\n\\begin{figure}[t]\n\\centering\n\\captionsetup{justification=centering}\n\\includegraphics[scale=0.5]{text/stringmatcher/makeIndices}\n\\caption{Mappend indices of String Matcher.}\n\\label{fig:mappend:indices}\n\\end{figure}\n%\nThe Haskell definition of @<>@, the monoid operation for @SM t@, is as follows.\n\\begin{code}\n  (mappend)::forall (t::Symbol). KnownSymbol t => SM t -> SM t -> SM t\n  (SM x xis) mappend (SM y yis)\n    = SM (x stringMappend y) (xis' listMappend xyis listMappend yis')\n    where\n      tg   = fromString (symbolVal (Proxy :: Proxy t))\n      xis' = map (castGoodIndexLeft tg x y) xis\n      xyis = makeNewIndices x y tg\n      yis' = map (shiftStringRight tg x y) yis\n\\end{code}\nNote again that capturing target as a type parameter is critical,\notherwise there is no way for the Haskell's type system to specify\nthat both arguments of @(mappend)@ are string matchers on the same target.\n\nThe action of @(<>)@ on the two @input@ fields is straightforward;\nhowever, the action on the two @indices@ is complicated by the need to\nshift indices and the possibility of new matches arising from the\nconcatenation of the two @input@\nfields. Figure~\\ref{fig:mappend:indices} illustrates the three pieces\nof the new @indices@ field which we now explain in more detail.\n\n\\mypara{1. Casting Good Indices}\nIf @xis@ is a list of good indices for the string @x@ and the target\n@tg@, then @xis@ is also a list of good indices for the string\n@x stringMappend y@ and the target @tg@, for each @y@.\n%\nTo prove this property we need to invoke the property\n@subStrAppendRight@ on Refined Strings that establishes\nsubstring preservation on string right appending.\n%\n\\begin{code}\n  assume subStrAppendRight\n      :: sl:RString -> sr:RString -> j:Int\n      -> i:{Int | i + j <= lenStr sl }\n      -> {subString sl i j = subString (sl stringMappend sr) i j}\n\\end{code}\n%\nThe specification of @subStrAppendRight@ ensures that for each\nstring @sl@ and @sr@ and each integer @i@ and @j@ whose sum is within @sl@,\nthe substring from @i@ with length @j@ is identical in @sl@ and in @(sl stringMappend sr)@.\n%\nThe function @castGoodIndexLeft@ applies the above property to an index @i@\nto cast it from a good index on @sl@ to a good index on @(sl stringMappend sr)@\n%\n\\begin{code}\n  castGoodIndexLeft\n    :: tg:RString -> sl:RString -> sr:RString\n    -> i:GoodIndex sl tg\n    -> {v:GoodIndex (sl stringMappend sr) target | v = i}\n\n  castGoodIndexLeft tg sl sr i\n    = cast (subStrAppendRight sl sr (lenStr tg) i) i\n\\end{code}\n%\nWhere @cast p x@ returns @x@, after enforcing the properties of @p@ in the logic\n\\begin{code}\n  cast :: b -> x:a -> {v:a | v = x}\n  cast _ x = x\n\\end{code}\n%\nMoreover, in the logic, each expression @cast p x@\nis reflected as @x@,\nthus allowing random (\\ie non-reflected) Haskell expressions to appear in @p@.\n\n\\mypara{2. Creation of new indices}\nThe concatenation of two input strings @sl@ and @sr@\nmay create new good indices.\n%\nFor instance, concatenation of\n@\"ababcab\"@ with @\"cab\"@\nleads to a new occurence of @\"abcab\"@ at index @5@ which\ndoes not occur in either of the two input strings.\n%\nThese new good indices can appear only at the last @lenStr tg@ positions\nof the left input @sl@.\n%\n@makeNewIndices sl sr tg@ detects all such good new indices.\n%\n\\begin{code}\n  makeNewIndices\n    :: sl:RString -> sr:RString -> tg:RString\n    -> [GoodIndex {sl stringMappend sr} tg]\n    \n  makeNewIndices sl sr tg\n    | lenStr tg < 2 = []\n    | otherwise     = makeIndices (sl stringMappend sr) tg lo hi\n    where\n      lo = maxInt (lenStr sl - (lenStr tg - 1)) 0\n      hi = lenStr sl - 1\n\\end{code}\nIf the length of the @tg@ is less than 2, then no new good indices are created.\n%\nOtherwise,\nthe call on @makeIndices@ returns all the good indices of the input\n@sl stringMappend sr@ for target @tg@\nin the range from @maxInt (lenStr sl-(lenStr tg-1)) 0@ to  @lenStr sl-1@.\n%\n\nGenerally, @makeIndices s tg lo hi@ returns the good indices\nof the input string @s@ for target @tg@ in the range from @lo@ to @hi@.\n%\n\\begin{code}\n  makeIndices :: s:RString -> tg:RString -> lo:Nat\n              -> hi:Int -> [GoodIndex s tg]\n    \n  makeIndices s tg lo hi  \n    | hi < lo             = []\n    | isGoodIndex s tg lo = lo:rest\n    | otherwise           = rest\n    where\n      rest = makeIndices s tg (lo + 1) hi\n\\end{code}\n%Note the similarity to the functional specification of string matching\n%at the beginning of this section.\n\nIt is important to note that\n@makeNewIndices@ does not scan all the input,\ninstead only searching at most @lenStr tg@ positions for new good indices.\n%\nThus, the time complexity to create the new indices is linear\non the size of the target but independent of the size of the input.\n\n\\mypara{3. Shift Good Indices}\nIf @yis@ is a list of good indices on the string @y@ with target @tg@,\nthen we need to shift each element of @yis@ right @lenStr x@ units to\nget a list of good indices for the string @x stringMappend y@.\n\n%\nTo prove this property we need to invoke the property\n@subStrAppendLeft@ on Refined Strings that establishes\nsubstring shifting on string left appending.\n%\n\\begin{code}\n  assume subStrAppendLeft\n    :: sl:RString -> sr:RString\n    -> j:Int -> i:Int\n    -> {subStr sr i j = subStr (sl stringMappend sr) (lenStr sl+i) j}\n\\end{code}\n%\nThe specification of @subStrAppendLeft@ ensures that for each\nstring @sl@ and @sr@ and each integers @i@ and @j@,\nthe substring from @i@ with length @j@ on @sr@\nis equal to the substring from @lenStr sl + i@\nwith length @j@ on @(sl stringMappend sr)@.\n%\nThe function @shiftStringRight@ both shifts the input index @i@ by @lenStr sl@\nand applies the @subStrAppendLeft@ property to it,\ncasting @i@ from a good index on @sr@ to a good index on @(sl stringMappend sr)@\n\nThus, @shiftStringRight@ both appropriately shifts the index\nand casts the shifted index using the above theorem:\n\\begin{code}\n  shiftStringRight\n    :: tg:RString -> sl:RString -> sr:RString\n    -> i:GoodIndex sr tg\n    -> {v:(GoodIndex (sl stringMappend sr) tg) | v = i + lenStr sl}\n    \n  shiftStringRight tg sl sr i\n    = subStrAppendLeft sl sr (lenStr tg) i `cast` i + lenStr sl\n\\end{code}\n\n\\subsubsection{String Matching is a Monoid}\nNext we prove that the monoid methods @mempty@ and @(mappend)@ satisfy\nthe monoid laws.\n%\n\\begin{theorem}[SM is a Monoid]\\label{theorem:stringmatchers}\n(@SM t@, @mempty@, @mappend@)\nis a monoid.\n\\end{theorem}\n%\n\\begin{proof}\nAccording to the Monoid Definition~\\ref{definition:monoid},\nwe prove that string matching is a monoid,\nby providing safe implementations for the monoid law functions.\n%\nFirst, we prove \\textit{left identity}.\n\\begin{code}\n  idLeft :: x:SM t -> {mempty mappend x = xs}\n  \n  idLeft (SM i is)\n    =   (mempty :: SM t) mappend (SM i is)\n    =. (SM stringMempty listMempty) mappend (SM i is)\n    =. SM (stringMempty <+> i) (is1 ++ isNew ++ is2)\n       ? idLeftStr i\n    =. SM i ([] ++ [] ++ is)\n       ? (mapShiftZero tg i is && newIsNullRight i tg)\n    =. SM i is\n       ? idLeftList is\n    ** QED\n    where\n      tg    = fromString (symbolVal (Proxy :: Proxy t))\n      is1   = map (castGoodIndexRight tg i stringMempty) []\n      isNew = makeNewIndices stringMempty i tg\n      is2   = map (shiftStringRight tg stringMempty i) is\n\\end{code}\n\nThe proof proceeds by rewriting, using left identity of the monoid strings and lists,\nand two more lemmata.\n\\begin{itemize}\n\\item Identity of shifting by an empty string.\n\\begin{code}\n  mapShiftZero :: tg:RString -> i:RString\n    -> is:[GoodIndex i target]\n    -> {map (shiftStringRight tg stringMempty i) is = is}\n\\end{code}\nThe lemma is proven by induction on @is@ and\nthe assumption that empty strings have length 0.\n\\item No new indices are created.\n\\begin{code}\n  newIsNullLeft :: s:RString -> t:RString \n                -> {makeNewIndices stringMempty s t = []}\n\\end{code}\nThe proof relies on the fact that @makeIndices@\nis called on the empty range from @0@ to @-1@\nand returns @[]@.\n\\end{itemize}\n\nNext, we prove \\textit{right identity}.\n\\begin{code}\n  idRight :: x:SM t -> {x mappend mempty = x}\n  \n  idRight (SM i is)\n    =  (SM i is) mappend (mempty :: SM t)\n    =. (SM i is) mappend (SM stringMempty listMempty)\n    =. SM (i stringMappend stringMempty) (is1 listMappend isNew listMappend is2)\n       ? idRightStr i\n    =. SM i (is listMappend N listMappend N)\n       ? (mapCastId tg i stringMempty is && newIsNullLeft i tg)\n    =. SM i is\n       ? idRightList is\n    **  QED\n    where\n      tg    = fromString (symbolVal (Proxy :: Proxy t))\n      is1   = map (castGoodIndexRight tg i stringMempty) is\n      isNew = makeNewIndices i stringEmp tg\n      is2   = map (shiftStringRight tg i stringMempty) []\n\\end{code}\nThe proof proceeds by rewriting,\nusing right identity on strings and lists and two more lemmata.\n\\begin{itemize}\n\\item Identity of casting is proven\n\\begin{code}\n  mapCastId \n    :: tg:RString -> x:RString -> y:RString\n    -> is:[GoodIndex x tg] ->\n    -> {map (castGoodIndexRight tg x y) is = is}\n\\end{code}\nWe prove identity of casts by induction on @is@ and\nidentity of casting on a single index.\n\\item No new indices are created.\n\\begin{code}\n  newIsNullLeft :: s:RString -> t:RString\n                -> {makeNewIndices s stringMempty t = listMempty}\n\\end{code}\nThe proof proceeds by case splitting\non the relative length of @s@ and @t@.\nAt each case we prove by induction that all\nthe potential new indices would be out of bounds and thus\nno new good indices would be created.\n\\end{itemize}\n\n- Finally we prove \\textit{associativity}.\nFor space, we only provide a proof sketch.\nThe whole proof is available online~\\cite{implementation}.\n%\nOur goal is to show equality of the left and right associative string matchers.\n%\n\\begin{code}\n  assoc :: x:SM t -> y:SM t -> z:SM t\n        -> {x mappend (y mappend z) = (x mappend y) mappend z}\n\\end{code}\nTo prove equality of the two string matchers we show\nthat the input and indices fields are respectively equal.\n%\nEquality of the input fields follows by associativity of RStrings.\n%\nEquality of the index list proceeds in three steps.\n%\n\\begin{enumerate}\n\\item Using list associativity and distribution of index shifting,\nwe group the indices in the five lists shown in\nFigure~\\ref{fig:mappend:assoc}: the indices of the input @x@, the new\nindices from mappending @x@ to @y@, the indices of the input @y@, the\nnew indices from mappending @x@ to @y@, and the indices of the input\n@z@.\n\\item The representation of each group depends on the order of appending.\nFor example, if @zis1@ (resp. @zis2@) is the group @zis@ when\nright (resp. left) mappend happened first, then we have\n\\begin{code}\n  zis1 = map (shiftStringRight tg xi (yi stringMappend zi))\n             (map (shiftStringRight tg yi zi) zis)\n\n  zis2 = map (shiftStringRight tg (xi stringMappend yi) zi) zis\n\\end{code}\nThat is, in right first, the indices of @z@ are first shifted\nby the length of @yi@ and then by the length of @xi@,\nwhile in the left first case, the indices of @z@ are shifted by the\nlength of @xi stringMappend yi@.\nIn this second step of the proof we prove, using lemmata,\nthe equivalence of the different group representations.\n%\nThe most interesting lemma we use is called @assocNewIndices@ and proves\nequivalence of all the three middle groups together\nby case analysis on the relative lengths of the target @tg@ and the middle string @yi@.\n\\item After proving equivalence of representations,\nwe again use list associativity and distribution of casts to wrap the\nindex groups back in string matchers.\n\\end{enumerate}\n\\begin{figure}\n\\centering\n\\captionsetup{justification=centering}\n\\includegraphics[scale=0.5]{text/stringmatcher/AssociativeIndices}\n\\caption{Associativity of String Matching.}\n\\label{fig:mappend:assoc}\n\\end{figure}\nWe now sketch the three proof steps, while the whole proof\nis available online~\\cite{implementation}.\n\\begin{code}\n  assoc x@(SM xi xis) y@(SM yi yis) z@(SM zi zis)\n    -- Step 1: unwrapping the indices\n    =   x <> (y <> z)\n    =. (SM xi xis) <> ((SM yi yis) <> (SM zi zis))\n                         ...\n    -- via list associativity and distribution of shifts\n    =. SM i (xis1 ++ ((xyis1 ++ yis1 ++ yzis1) ++ zis1))\n    -- Step 2: Equivalence of representations\n    =. SM i (xis2 ++ ((xyis1 ++ yis1 ++ yzis1) ++ zis1))\n       ? castConcat tg xi yi zi xis\n    =. SM i (xis2 ++ ((xyis1 ++ yis1 ++ yzis1) ++ zis2))\n       ? mapLenFusion tg xi yi zi zis\n    =. SM i (xis2 ++ ((xyis2 ++ yis2 ++ yzis2) ++ zis2))\n       ? assocNewIndices y tg xi yi zi yis\n    -- Step 3: Wrapping the indices\n                         ...\n    -- via list associativity and distribution of casts\n    =. (SM xi xis <> SM yi yis) <> SM zi zis\n    =. (x <> y) <> z\n    ** QED\n    where\n      i     = xi stringMappend (yi stringMappend zi)\n\n      yzis1 = map (shiftStringRight tg xi (yi <+> zi)) yzis\n      yzis2 = makeNewIndices (xi <+> yi) zi tg\n      yzis  = makeNewIndices yi zi tg\n      ...\n\\end{code}\n\\cqed\\end{proof}\n", "meta": {"hexsha": "ee9422f0b1d0aefc8139d0c981261806d53de4a2", "size": 16132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/stringmatcher/string-matcher-is-monoid.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/string-matcher-is-monoid.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/string-matcher-is-monoid.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.9287305122, "max_line_length": 112, "alphanum_fraction": 0.697929581, "num_tokens": 4701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6106622003052353}}
{"text": "\\documentclass{subfile}\n\n\\begin{document}\n\t\n\t\\section{SgMO}\\label{sec:sgmo}\n\t\n\t\t\\begin{problem}[Singapore Team Selection Test $2009$, problem $2$]\n\t\t\tIf $a,b,c$ are three positive real numbers such that $ab+bc+ca=1$, prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sqrt[3]{\\dfrac{1}{a}+6b}+\\sqrt[3]{\\dfrac{1}{b}+6c}+\\sqrt[3]{\\dfrac{1}{c}+6a}\n\t\t\t\t\t\t& \\leq\\dfrac{1}{abc}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[Singapore Team Selection Test $2008$, problem $2$]\n\t\t\tLet $x_{1},\\ldots,x_{n}$ be positive real numbers such that $x_{1}\\cdots x_{n}=1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sum_{i=1}^{n}\\dfrac{1}{n-1+x_{i}}\n\t\t\t\t\t\t& \\leq1\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[Singapore Team Selection Test $2007$, problem $2$]\n\t\t\tProve the inequality\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\sum_{i<j}\\dfrac{a_{i}a_{j}}{a_{i}+a_{j}}\n\t\t\t\t\t\t& \\leq \\dfrac{n}{2(a_{1}+\\ldots+a_{n})}\\sum_{i<j}a_{i}a_{j}\n\t\t\t\t\\end{align*}\n\t\t\tfor all positive real numbers $a_{1},\\ldots,a_{n}$.\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[Singapore $2006$, problem $2$]\n\t\t\tLet $n>1$ be an integer and $x_{1},\\ldots,x_{n}$ be real numbers such that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t|x_{1}|+\\ldots+|x_{n}|\n\t\t\t\t\t\t& = 1\\quad\\mbox{and}\\\\\n\t\t\t\t\tx_{1}+\\ldots+x_{n}\n\t\t\t\t\t\t& = 0\n\t\t\t\t\\end{align*}\n\t\t\tProve that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\left|\\dfrac{x_{1}}{1}+\\ldots+\\dfrac{x_{n}}{n}\\right|\n\t\t\t\t\t\t& \\leq \\dfrac{1}{2}\\left(1-\\dfrac{1}{n}\\right)\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\t\t\n\t\t\\begin{problem}[Singapore $2004$, problem $2$]\n\t\t\tLet $a,b,c$ be real numbers such that $ab+bc+ca=1$ and $0<a,b,c<1$. Prove that\n\t\t\t\t\\begin{align*}\n\t\t\t\t\t\\dfrac{a}{1-a^{2}}+\\dfrac{b}{1-b^{2}}+\\dfrac{c}{1-c^{2}}\n\t\t\t\t\t\t& \\geq\\dfrac{3\\sqrt{3}}{2}\n\t\t\t\t\\end{align*}\n\t\t\\end{problem}\n\\end{document}", "meta": {"hexsha": "9023aa669968ad14df8bf121df0fd987788c3518", "size": 1713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sgmo.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": "sgmo.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": "sgmo.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": 31.7222222222, "max_line_length": 96, "alphanum_fraction": 0.5802685347, "num_tokens": 746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6105035434048358}}
{"text": "\\documentclass[10pt,a4paper]{article}%{scrartcl}\n    \\newtheorem{defi}{Definition}[section]\n    \\usepackage[inner=1.0cm,outer=1.0cm,top=0cm,bottom=1cm,includeheadfoot]{geometry}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage[english]{babel}\n    \\usepackage{xcolor}\n    \\usepackage[pdftex]{graphicx}\n    \\usepackage[colorlinks,linkcolor=black,citecolor=black]{hyperref}\n    \\usepackage[numbers]{natbib}\n    \\usepackage{tabularx}\n    \\usepackage{amsmath}\n    \\usepackage{amssymb}\n    \\usepackage{mathtools}\n    \\usepackage{txfonts}\n    \\usepackage{placeins}\n    \\usepackage[skip=0pt]{caption}\n    \\usepackage{multicol}\n\n    \\newlength\\tindent\n    \\setlength{\\tindent}{\\parindent}\n    \\setlength{\\parindent}{0pt}\n    \\renewcommand{\\indent}{\\hspace*{\\tindent}}\n\n\\begin{document}\n\n\n\\section{Col/Row major}\n\\begin{align*}\n\\underbrace{\\bordermatrix{\n\t\ti\\ \\text{\\textbackslash} \\ j\n\t\t& 0 &  1 & 2 & 3      \\cr\n\t\t0 & 0  & 1  & 2  & 3  \\cr\n\t\t1 & 4  & 5  & 6  & 7  \\cr\n\t\t2 & 8  & 9  & 10 & 11 \\cr\n\t\t3 & 12 & 13 & 14 & 15 \\cr\n\t\t4 & 16 & 17 & 18 & 19 \\cr\n}}_{\\textstyle\\begin{array}{c}\\text{row-major order}\n\\end{array}}\n\\qquad\\quad\n\\underbrace{\\bordermatrix{\n\t\ti\\ \\text{\\textbackslash} \\ j\n\t\t& 0 & 1 & 2 & 3     \\cr\n\t\t0 & 0 & 5 & 10 & 15 \\cr\n\t\t1 & 1 & 6 & 11 & 16 \\cr\n\t\t2 & 2 & 7 & 12 & 17 \\cr\n\t\t3 & 3 & 8 & 13 & 18 \\cr\n\t\t4 & 4 & 9 & 14 & 19 \\cr\n}}_{\\textstyle\\begin{array}{c}\\text{column-major order}\n\t\\end{array}}\n\\end{align*}\n\n\\section{Cache aware data storage}\n\\begin{align*}\n\\boldsymbol{C}= &\\boldsymbol{A} \\times  \\boldsymbol{B} \\\\\n= & \\quad\\underbrace{\\bordermatrix{\n\t\ti\\ \\text{\\textbackslash} \\ j\n\t\t& 0 &  1 &  2 &  3 & 4    \\cr\n\t\t  0 &  0 &  1 &  2 & 3  & 4  \\cr\n\t\t  1 &  5 &  6 &  7 & 8  & 9  \\cr\n\t\t  2 & 10 & 11 & 12 & 13 & 14 \\cr\n\t\t  3 & 15 & 16 & 17 & 18 & 19 \\cr\n}}_{\\textstyle\\begin{array}{c}\\text{matrix A row-major}\n\t\\end{array}}\n\\quad \\times\\quad\n\\underbrace{\\bordermatrix{\n\t\ti\\ \\text{\\textbackslash} \\ j\n\t\t& 0 & 1 & 2 & 3     \\cr\n\t\t0 & 0 & 5 & 10 & 15 \\cr\n\t\t1 & 1 & 6 & 11 & 16 \\cr\n\t\t2 & 2 & 7 & 12 & 17 \\cr\n\t\t3 & 3 & 8 & 13 & 18 \\cr\n\t\t4 & 4 & 9 & 14 & 19 \\cr\n}}_{\\textstyle\\begin{array}{c}\\text{matrix B column-major}\n\t\\end{array}}\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "8a475a058a3e7627973c308fff9a0e69ef75a828", "size": 2169, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "img/matrix.tex", "max_stars_repo_name": "rehbergT/dgemm", "max_stars_repo_head_hexsha": "b55e79f86674877f159d604dce27061afb8faadd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-29T13:56:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T06:26:25.000Z", "max_issues_repo_path": "img/matrix.tex", "max_issues_repo_name": "rehbergT/dgemm", "max_issues_repo_head_hexsha": "b55e79f86674877f159d604dce27061afb8faadd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "img/matrix.tex", "max_forks_repo_name": "rehbergT/dgemm", "max_forks_repo_head_hexsha": "b55e79f86674877f159d604dce27061afb8faadd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-08-12T11:51:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T00:30:58.000Z", "avg_line_length": 28.1688311688, "max_line_length": 85, "alphanum_fraction": 0.5855232826, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.757794360334681, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6105035328504893}}
{"text": "\\documentclass{article}\r\n\\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}\r\n\\usepackage{amsmath}\r\n\\usepackage{graphicx}\r\n\\usepackage{listings}\r\n\\usepackage{ulem}\r\n\\usepackage{algorithm}\r\n\\usepackage{algpseudocode}\r\n\\usepackage[colorlinks=true, allcolors=blue]{hyperref}\r\n\r\n\\title{Expectation Maximization for Mixture Model}\r\n\\author{dw}\r\n\r\n\\begin{document}\r\n\\maketitle\r\n\\section{Mixture model}\r\nIn statistics, a mixture model is a probabilistic model for representing the presence of subpopulations within an overall population, without requiring that an observed data set should identify the sub-population to which an individual observation belongs. It is common to think of probability mixture modeling as a missing data problem. One way to understand this is to assume that the data points under consideration have \"membership\" in one of the distributions we are using to model the data. When we start, this membership is unknown, or missing. \\href{https://en.wikipedia.org/wiki/Mixture_model}{[1]}\r\n\r\nAssuming $N$ observation (index $i$) are observed in $K$ distributions(index $K$). The basis model is:\r\n\\begin{equation}\r\n\tp(x_i|\\theta) = \\sum_k \\alpha_k p(x_i| \\theta_k)\r\n\\end{equation}\r\n\r\n\\begin{itemize}\r\n\t\\item $\\theta$ - parameters including $\\theta_k$ and $\\alpha_k$.\r\n\t\\item $\\theta_k$ - parameters of $k$-th distribution.\r\n\t\\item $\\alpha_k$ - weight or prior, equal to $p(z_{ik})$.\r\n\\end{itemize}\r\n\r\n\\textbf{Proof}:\r\nHidden variables $z_{ik}$s indicate which class the $i$-th observation belongs to, value 1 shows in while 0 shows not, and $\\sum_k {z_ik} = 1$, which satisfy categarical distribution.\r\nLikelihood including the hidden variables and observations is:\r\n\r\n\\begin{equation}\r\n\t\\mathcal{L}(\\theta|x_i, z_{ik}) \\propto \\prod_k p(x_i,z_{ik}|\\theta_k)\r\n\\end{equation}\r\n\r\nUsing formula of total probability:\r\n\r\nIt just a trick to promise $z_{ik}=0$ make nonsense in the formula. Using categarical distribution, we have\r\n\r\n\\begin{equation}\r\n\t\\begin{aligned}\r\n\t\t\\mathcal{L}(\\theta|x_i) \\propto \\sum_k p(x_i | z_{ik}, \\theta) p(z_{ik} | \\theta)\r\n\t\t  & = \\sum_k \\prod_k p^{z_{ik}}(x_i,z_{ik}|\\theta_k) p(z_{ik}|\\theta) \\\\\r\n\t\t  & = \\sum_k \\alpha_k p(x_i,z_{ik}|\\theta_k)\r\n\t\\end{aligned}\r\n\\end{equation}\r\n\r\nDon't be confused that:\r\n\\begin{itemize}\r\n\t\\item $p(x_i,z_{ik}|\\theta) = \\{\\alpha_k p(x_i|\\theta_k)\\}^{z_{ik}}$\r\n\t\\item $p(x_i|\\theta,z_{ik}) = p^{z_{ik}}(x_i|\\theta_k)$\r\n\t\\item $p(z_{ik}|\\theta) = \\alpha_k$\r\n\\end{itemize}\r\n\r\n\\section{Expectation Maximization}\r\nHowever, logsum is hard to optimize since all parameters are coupled, using Jensen Inequality we get the lower bound:\r\n\\begin{equation}\r\n\t\\log\\mathcal{L}_{i}(\\theta|x_i) \\propto \\sum_{i} \\log p(x_i|\\theta) \\geq \\sum_{i} \\sum_k q(z_{ik})\\log\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\} = F(q,\\theta)\r\n\\end{equation}\r\n\r\nHere $q(z_{ik})$ is an arbitrary distribution of $z_{ik}$, satisfying $\\sum_k q(z_{ik}) = 1$ only when\r\n\\begin{equation}\r\n\tq(z_{ik}) = \\frac{\\alpha_k p(x_i, z_{ik})}{\\sum_{k'} p(x_i, z_{ik'})}\r\n\\end{equation}\r\nthe equality holds.\r\n\r\n\\textbf{Proof}:\r\nBy Jensen's inequality, for the concave function (such as $\\log$) we have\r\n\\begin{equation}\r\n\tf(\\frac{\\sum_i a_i x_i}{\\sum_i a_i}) \\geq \\frac{\\sum_i a_i f(x_i)}{\\sum_i a_i}\r\n\\end{equation}\r\nWhen $\\sum_i a_i = 1$, it becomes $f(\\sum_i a_i x_i) \\geq \\sum_i a_i f(x_i)$\r\nReplace $a_i$ by $q(z_{ik})$ by $\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\}$, we have\r\n\r\n\\begin{equation}\r\n\t\\begin{aligned}\r\n\t\t\\sum_i \\log p(x_i|\\theta) & = \\sum_i \\log \\sum_k p(x_i, z_{i k}|\\theta)                                 \\\\\r\n\t\t                          & = \\sum_i \\log \\sum_k q(z_{ik}) \\{\\frac{p(x_i, z_{ik}|\\theta)} {q(z_{ik})}\\} \\\\\r\n\t\t                          & \\geq \\sum_i \\sum_k q(z_{ik})\\log\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\}\r\n\t\\end{aligned}\r\n\t\\label{eq: Ineq}\r\n\\end{equation}\r\n\r\nwhen $\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\}$ is nothing to do with $k$ the inequality holds. Notice that\r\n\\begin{equation}\r\n\tp(z_{ik}|x_i,\\theta) = \\frac{p(x_i, z_{ik} |\\theta)}{\\sum_{k'} p(x_i , z_{ik'} | \\theta)} = \\frac{\\alpha_k p(x_i|\\theta_k)} {\\sum_{k'} {\\alpha_{k'} p(x_i|\\theta_{k'})}}\r\n\\end{equation}\r\n\r\ntake $z_{ik}$ as $p(z_{ik}|x_i,\\theta)$ and the $\\sum_{k'} {\\alpha_{k'} p(x_i|\\theta_{k'})}$ is a constant.\r\n\r\n\\section{EM flow chart}\r\n\\begin{itemize}\r\n\t\\item \\textbf{Initial}: Giving an initial guess of $\\theta_{[0]}: \\alpha_{k}^{[0]}, \\theta_{k}^{[0]}$\r\n\t\\item \\textbf{E-step}:\r\n\t      $q^{[\\mathrm{new}]} \\leftarrow \\arg\\max_q F(q,\\theta^{[\\mathrm{old}]})$\r\n\t      \\begin{equation}\r\n\t\t      \\mathcal{L}(\\theta^{[\\mathrm{old}]}|t) \\geq F(q,\\theta^{[\\mathrm{old}]}) = \\sum_i \\sum_k q(z_{ik})\\log\\{\\frac{p(t_{i},z_{ik}|\\theta^{[\\mathrm{old}]})}{q(z_{ik})}\\}\r\n\t      \\end{equation}\r\n\r\n\t      we get\r\n\t      \\begin{equation}\r\n\t\t      q(z_{ik}) = \\frac{\\alpha_k p(x_i|\\theta_k^{[\\mathrm{old}]})} {\\sum_{k'} {\\alpha_{k'} p(x_i|\\theta_{k'}^{[\\mathrm{old}]})}}\r\n\t      \\end{equation}\r\n\r\n\t\\item \\textbf{M-step}:\r\n\t      $\\theta^{[\\mathrm{new}]} \\leftarrow \\arg\\max_{\\theta} F(q^{[\\mathrm{new}]},\\theta)$\\\\\r\n\t      By this way, the parameters in different classes can be optimized individually, Notice that:\r\n\t      \\begin{equation}\r\n\t\t      F(q,\\theta) = \\sum_i \\sum_k q(z_{ik}) \\log{p(x_{i}, z_{ik}|\\theta)} - \\sum_i \\sum_k q(z_{ik}) \\log{q(z_{ik})}\r\n\t      \\end{equation}\r\n\t      Only the former part is dependent on $\\theta$, noted as $Q(q,\\theta)$\r\n\t      \\begin{equation}\r\n\t\t      \\begin{aligned}\r\n\t\t\t      Q(q^{[\\mathrm{new}]},\\theta) & = \\sum_i \\sum_k  q^{[\\mathrm{new}]}(z_{ik})\\log{p(x_i,z_{ik}|\\theta)}               \\\\\r\n\t\t\t                                   & = \\sum_k \\left\\{\\sum_i q^{[\\mathrm{new}]}(z_{ik})\\log{p(x_i,z_{ik}|\\theta)}\\right\\}\r\n\t\t      \\end{aligned}\r\n\t      \\end{equation}\r\n\r\n\t      The optimize target is change to single class.\r\n\t\\item Repeat until converge.\r\n\\end{itemize}\r\n\\textbf{Proof of Convergence:}\r\n1. In E-step, Jensen Inequality promise the convergence. \\\\\r\n2. In M-step, the optimize step promise the convergence. \\\\\r\nHowever, EM is not a global minimizer.\r\n\r\n\\section{Alternative}\r\nE-step define the lower bounds of $\\mathcal{L}(\\theta|t) - \\mathrm{KL}(q(z_{ik})||p(z_{ik}|x_i,\\theta) $ \\\\\r\nDifference between $\\log\\mathcal{L}(\\theta|x) $ and $ F(q,\\theta)$ is the KL-divergence of:\r\nProof:\r\n\\begin{equation}\r\n\t\\begin{aligned}\r\n\t\tL(\\theta) - F(q,\\theta) & = \\sum_i^N \\sum_{k=1}^K \\log\\{{ p(x_i|\\theta)}\\} - \\sum_i^N \\sum_{k=1}^K q(z_{ik})\\log\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\}          \\\\\r\n\t\t                        & = \\sum_i^N \\sum_{k=1}^K q(z_{ik})\\log\\{{ p(x_i|\\theta)}\\} - \\sum_i^N \\sum_{k=1}^K q(z_{ik})\\log\\{\\frac{p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\} \\\\\r\n\t\t                        & = \\sum_i^N \\sum_{k=1}^K q(z_{ik})\\log\\{\\frac{p(x_i|\\theta)/p(x_i,z_{ik}|\\theta)}{q(z_{ik})}\\}                                             \\\\\r\n\t\t                        & = \\sum_i^N \\sum_{k=1}^K q(z_{ik})\\log\\{\\frac{p(z_{ik}|x_i,\\theta)}{q(z_{ik})}\\}                                                           \\\\\r\n\t\t                        & = \\mathrm{KL}(q(z_{ik})||p(z_{ik}|x_i,\\theta))\r\n\t\\end{aligned}\r\n\\end{equation}\r\nThe KL-divergence is always positive and have value 0 only if $q(z_{ik}) = p(z_{ik}|x_i,\\theta)$.\r\n\r\n\\section{Apply: Gaussian mixture model}\r\n\\href{https://biarnes-adrien.medium.com/em-of-gmm-appendix-m-step-full-derivations-4ae95cdd40c9}{Proof}\r\n\\end{document}", "meta": {"hexsha": "aef0c644b7f00321bfbe5da12fa91314b00bcfea", "size": 7396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pdf/EM/main.tex", "max_stars_repo_name": "dw839566105/dw839566105.github.io", "max_stars_repo_head_hexsha": "81892dc7ce9be76d2d85f19b1ad7ba7416f1ec7c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-08-12T13:19:53.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-15T02:52:27.000Z", "max_issues_repo_path": "pdf/EM/main.tex", "max_issues_repo_name": "dw839566105/dw839566105.github.io", "max_issues_repo_head_hexsha": "81892dc7ce9be76d2d85f19b1ad7ba7416f1ec7c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pdf/EM/main.tex", "max_forks_repo_name": "dw839566105/dw839566105.github.io", "max_forks_repo_head_hexsha": "81892dc7ce9be76d2d85f19b1ad7ba7416f1ec7c", "max_forks_repo_licenses": ["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.6575342466, "max_line_length": 608, "alphanum_fraction": 0.6120876149, "num_tokens": 2513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825007, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.610471188838072}}
{"text": "\\section{Quantifiers (Bonevac)}\n\n\\begin{itemize}\n    \\item Aristotle logic gives arguments restricted form. Every sentence is of form $\\{\\text{some,all,no}\\}F\\{\\text{are,not}\\}G$\n    \\item Syllogistic argument has two such setences as premises and one as a conclusion. The meshing of these is specific, limited.\n    \\item \\ti{Sentential logic} takes sentences as basic analytical units, covers broader realm.\n    \\item Sentential logic does not solve problems of syllogistic, e.g. cannot explain why an argument is valid\n    \\item Divergence b/w syllogistic and sentential resolved by Friege and Peirce\n    \\begin{itemize}\n        \\item Introduced determiners (e.g. all, some, no, every, any, etc.)\n        \\item Universal quantifier $\\forall$ and existential quantifier $\\exists$\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{Constants and Quantifiers}\n\nAtomic sentences consist of a main subject/noun phrase and verb phrase. Examples of verb phrases:\n\n\\begin{enumerate}\n    \\item is a man\n    \\item sleeps very soundly\n    \\item kicked the ball into the end zone\n\\end{enumerate}\n\nVerb phrases are terms in syllogistic logic, are \\tb{true or false} of individual objects. E.g. a man can sleep soundly or not.\nObjects of which verb phrase \\tb{satisfy} it, phrase will \\tb{apply} to them.\nThe set of objects which make a verb phrase true are called \\tb{extensions}.\n\nVerb phrases combine with noun phrases to form \\ti{sentences}. Noun phrases specify an object or groups of objects, since verb phrases describe their truth values.\nFollowing examples are complete sentences.\n\n\\begin{itemize}\n    \\item Socrates is a man\n    \\item Mr. Hendley sleeps very soundly\n    \\item Nate have Fred a copy of the letter\n\\end{itemize}\n\nUpper-case alphabet letters w/wout subscripts are \\tb{predicates}. Each predicate has an assigned number.\nPredicate with number $n$ is $n$-ary. Predicate yields a truth value when combined with certain number of objects.\nAssigned value $n$ indicates of how many objects the predicate takes on this truth value.\n\nFor example, man has singulary predicates (true false of a single object). Binary predicates take on two objects. Example is Person 1 respects Person 2, but Person 1 respects makes no sense.\n\nTo structure sentences, take example.\n\n\\begin{example}\n    Something is missing\n\\end{example}\n\nMissing applies to an object.\n\n\\begin{example}\n    Missing(something)\n\\end{example}\n\nWe use lowercase letters to denote constants, capital for predicates as discussed.\nSocrates is a man can be translated to $Ma$ where $a$ is a constant symbolizing Socrates, $M$ means man.\n\n\\begin{example} Translation\\\\\n    (for some $x$)($x$ is missing)\\\\\n    $\\exists x M x$\n\\end{example}\n\n\\section{Quantificational Logic}\n\nMain idea is that we use predicates to describe properties of variables, which we say are \\ti{quantified}.\nSay we define $Lxy$ to be that $x$ likes $y$. $L$ is our predicate, and $x,y$ are variables, of which we can pass any number to an (appropriate) predicate.\n\nIdea of quantifiers\n\\begin{itemize}\n    \\item $\\exists x$: there is some individual $x$ such that\n    \\item $\\forall x$: every individual $x$ such that\n\\end{itemize}\n\n\\subsection{Subtlety with quantifier order}\n\nDifference between\n\\begin{gather*}\n    1.\\;\\exists y\\forall x (Lxy)\\\\\n    2.\\;\\forall x\\exists y(Lxy)\n\\end{gather*}\n\n\\ti{First}: there exists someone who likes all individuals.\\\\\n\\ti{Second}: for every individual, there exists someone who likes them. \n\n\\subsection{Rules and properties}\n\nAn identity predicate exists to test equality of two subjects.\n\n\\begin{definition} (Identity predicate)\n    $$x=y:\\text{$x$ is equal to $y$}$$\n\\end{definition}\n\nWe can obviously tell that identical subjects have the same properties, so\n\n\\begin{definition} (Leibniz' law)\n    $$\\forall x\\forall y(x=y\\then (Px\\leftrightarrow Py))$$\n\\end{definition}\n\nWe can't ``for loop'' over all properties of subjects, so that must be done manually.\n\n\\subsection{Describing quantities}\n\nLet $Px$ mean that $x$ has property $P$. Be aware that we can trivially extend the below equivalences to $n$ subjects.\n\n\\begin{tabular}{l|l}\n    Statement & QL\\\\\n    \\hline\n    \\hline\n    There is exactly one thing that is $P$ & $\\exists x(Px\\land \\forall y(Py\\then x=y))$\\\\\n    There are exactly two things that are $P$ & $\\exists x\\exists y(Px\\land Py\\land x\\neq y\\land \\forall z(Pz\\then (z=x\\lor z=y))$\\\\\n    There are at least two things that are $P$ & $\\exists x\\exists y(Px\\land Py\\land x\\neq y)$\\\\\n    There are less than two things that are $P$ & $\\forall x\\forall y(\\lnot Px\\lor \\lnot Py\\lor x=y)$ (this is not identical to the first)\\\\ \n\\end{tabular}\n\n\\subsection{Interpretations}\n\nTo make interpretations of sentences (i.e. constant values using names) we set $UD=\\{a,b,c\\}$ or whatever,\nthen interpret the predicates with these names $Pa,Pb,Pc$, etc. Here we can cherry pick $a,b,c$ to arbitrarily give truth values to $P$ when interpreted. Useful for informal proofs.\n\n\\subsection{Natural deduction}\n\nBelow is a list of inferences or tautologies for natural deduction.\n\n\\begin{tabular}{l|l|l}\n    Name & Tautology or Inference & Code\\\\\n    \\hline\n    \\hline\n    Quantifier Exchange (occurs both ways) & $\\exists x(\\dots x \\dots)\\leftrightarrow \\forall x \\lnot(\\dots x\\dots)$ & QEx\\\\\n    Universal Instantiation & $\\forall x(\\dots x\\dots)\\therefore \\dots a \\dots$ where $a$ is a new name in proof & UI\\\\\n    Universal Generalization & $\\dots a \\dots\\; \\therefore\\forall x(\\dots x\\dots)$ iff $a$ was declared by UI & UG\\\\\n    Existential Instantiation & $\\exists x(\\dots x\\dots)\\therefore \\dots a\\dots$ where $a$ is any name & EI\\\\\n    Existential Generalization & $\\dots a\\dots \\;\\therefore\\exists x(\\dots x\\dots)$ & EG\\\\\n    Leibniz Law & $\\forall x\\forall y(x=y\\then (Px\\leftrightarrow Py))$ & Leibniz\n\\end{tabular}", "meta": {"hexsha": "cd04216adb40714473e9d31817a9bbd6f0c2ca8a", "size": 5794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "logic/tex/quantificational.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": "logic/tex/quantificational.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": "logic/tex/quantificational.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": 42.9185185185, "max_line_length": 190, "alphanum_fraction": 0.7266137384, "num_tokens": 1581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6104711808812606}}
{"text": "\\newtheorem{theorem}{Theorem}\n\n\\newcommand{\\ff}{f}\n\\newcommand{\\gf}{g}\n\n\\newcommand{\\knl}{k}\n\n\\chapter{Properties of the effective field operator}\n\\chaptermark{Effective field operator}\n\\label{sec:properties-of-field-operators}\n\nIn \\thisref{sec:properties-of-field-operators} we show some properties of the effective field operator that are used in \\cref{sec:energy-cons}.\nIt seems possible that these properties could be proven for a general effective field using only the definition \\cref{eq:62}, but we have not managed to find such a proof.\n\n\\section{Linear Symmetrical operator}\n\\label{sec:linear-symm-field-operators}\n\nAn operator $\\lop$ is linear if\n\\begin{equation}\n  \\lop[\\av + c\\bv] = \\lop[\\av] + c\\lop[\\bv].\n\\end{equation}\nThe vector Laplace, magnetostatic field and magnetocrystalline anisotropy operators are all easily demonstrated to be linear because they involve only linear operations, such as derivatives, integrals and dot products.\n\nAn operator $\\lop$ is symmetrical if\n\\begin{equation}\n  \\ip{\\lop \\av}{\\bv} = \\ip{\\av}{\\lop \\bv},\n\\end{equation}\nfor all functions $\\av, \\bv \\in $ in some function space on the real numbers where $\\ip{\\cdot}{\\cdot}$ is defined.\n\nIn \\thisref{sec:linear-symm-field-operators} we frequently make use of a consequence of the divergence theorem:\n\\begin{equation}\n  \\intd{\\fv(\\xv) \\cdot \\grad \\gf(\\xv)}\n  = \\intb{\\gf(\\xv) \\, (\\fv(\\xv) \\cdot \\nv(\\xv))} - \\intd{\\gf(\\xv) \\, \\div \\fv(\\xv)},\n  \\label{eqn:grad-divergence}\n\\end{equation}\nwhere $\\fv : \\real^d \\rightarrow \\real^d$ and $\\gf : \\real^d \\rightarrow \\real$.\n\nNote that by substituting $\\fv = \\grad \\ff$ into \\cref{eqn:grad-divergence} we can derive\n\\begin{equation}\n  \\begin{aligned}\n    \\intd{(\\lap \\ff) \\gf}\n    &= \\intb{\\gf (\\grad \\ff \\cdot \\nv)} - \\intd{\\grad \\ff \\cdot \\grad \\gf}, \\\\\n    &= \\intb{\\gf \\ddn{\\ff}} - \\intd{\\grad \\ff \\cdot \\grad \\gf}.\n    \\label{eqn:laplace-divergence}\n  \\end{aligned}\n\\end{equation}\n\n\\subsection{Applied field}\n\nThe applied field part of the effective field is in general \\emph{not} linear or symmetrical because it is independent of $\\mv$.\n\n\\subsection{Vector Laplace operator}\n\n\\begin{theorem}\n  If $\\lop$ is a symmetric operator on $v \\in \\ltwo$ then so is its ``vector equivalent'', $\\bar{\\lop}[\\vv] = \\threevec{\\lop v_1}{\\lop v_2}{\\lop v_3}$.\n\\end{theorem}\n\n\\begin{proof}\n  \\begin{equation}\n    \\begin{aligned}\n      \\ip{\\bar{\\lop}\\av}{\\bv} &= \\intd{ \\bar{\\lop} \\av \\cdot \\bv}, \\\\\n      &= \\intd{\\lop[a_1] b_1} + \\intd{\\lop[a_2] b_2} + \\intd{\\lop[a_3] b_3}, \\\\\n      & = \\ip{\\lop[a_1]}{b_1} + \\ip{\\lop[a_2]}{b_2} + \\ip{\\lop[a_3]}{b_3}.\n    \\end{aligned}\n  \\end{equation}\n  So $\\bar{\\lop}$ is symmetrical if and only if $\\lop$ is symmetrical.\n\\end{proof}\n\n\\begin{theorem}[Symmetry of Laplace operator]\n  If $m_i \\in \\ltwo$ and $\\ddn{m_i} = 0$ on all of $\\boundd$ then $\\lap$ is a linear operator on $m_i$.\n\\end{theorem}\n\\begin{proof}\n  Apply equation~\\cref{eqn:laplace-divergence} twice: first with $\\ff = a$, $\\gf = b$, then the other way around.\n  \\begin{equation}\n    \\begin{aligned}\n      \\label{eq:93}\n      \\ip{\\lap a}{b} &= \\intd{\\left(\\lap a \\right) b}, \\\\\n      &= \\intb{b \\ddn{a}} - \\intd{\\grad a \\cdot \\grad b}, \\\\\n      &= \\intb{b \\ddn{a}} + \\intd{a (\\lap b)} - \\intb{a \\ddn{b}}, \\\\\n      &= \\intd{a (\\lap b)}.\n    \\end{aligned}\n  \\end{equation}\n\\end{proof}\n\nFrom these two theorems we see that the vector Laplacian operator $\\lap$ is symmetrical.\nNote that the above does not include the case with surface anisotropy or when the length of $\\mv$ is not constant because in either of these cases we do not necessarily have $\\ddn{\\mv} = 0$.\nThe case with periodic boundary conditions is true by the combination of \\cref{eq:93,eq:95}.\n\n\n\\subsection{Magnetostatic field operator}\n\nFor simplicity we write\n\\begin{equation}\n  \\knl = \\frac{1}{4\\pi \\abs{\\xv - \\xv'}}.\n\\end{equation}\n\n\\begin{theorem}[Symmetry of magnetostatic field operator]\n  If $\\av, \\bv \\in \\ltwo$ and $\\grad \\av, \\grad\\bv \\in \\ltwo$  (\\ie $\\av, \\bv \\in \\sob^1$) then the operator\n  \\begin{equation}\n    \\begin{aligned}\n      \\hmsop [\\av](\\xv) &= - \\grad \\phim[\\av](\\xv), \\\\\n      &= -\\grad \\bigs{\n              -\\intd[\\magd']{ \\knl \\grad' \\cdot \\av(\\xv') }\n              + \\intd[\\boundd']{\\knl \\av(\\xv') \\cdot \\nv(\\xv') }\n            },\n    \\end{aligned}\n  \\end{equation}\n  where primes denote another set of coordinates, is symmetrical.\n  %% Do we also need some properties on k? Is k in ltwo -- yes int(k) something like [1/x]form -inf to inf = 0\n\\end{theorem}\n\n\\begin{proof}\n\n  Essentially we apply identity~\\cref{eqn:grad-divergence}, rearrange the result using the symmetry of the kernel, $\\knl$, and apply the identity again in reverse. We drop the $\\xv$ argument from $\\phim$ where it is obvious.\n\n  Using~\\cref{eqn:grad-divergence} we get\n  \\begin{equation}\n    \\begin{aligned}\n      \\ip{\\hmsop[\\av]}{\\bv} &= -\\intd{\\bv \\cdot \\grad \\phim[\\av] }, \\\\\n      &= - \\intb{\\phim[\\av] (\\bv \\cdot \\nv)} + \\intd{\\phim[\\av] (\\div \\bv) }, \\\\\n      &= \\intb{ \\intd[\\magd']{\\knl (\\nabla' \\cdot \\av(\\xv')) (\\bv(\\xv) \\cdot \\nv(\\xv))}} \\\\\n      &- \\intb{ \\intd[\\boundd']{\\knl (\\av(\\xv') \\cdot \\nv(\\xv')) (\\bv(\\xv) \\cdot \\nv(\\xv))}} \\\\\n      &- \\intd{ \\intd[\\magd']{\\knl (\\nabla' \\cdot \\av(\\xv')) (\\div \\bv(\\xv))}} \\\\\n      &+ \\intd{ \\intd[\\boundd']{\\knl (\\av(\\xv') \\cdot \\nv(\\xv')) (\\div \\bv(\\xv))}}.\n    \\end{aligned}\n  \\end{equation}\n\nChanging the order of the integrals gives (since $\\av$, $\\bv$ and their derivatives are in $\\ltwo$)\n  \\begin{equation}\n    \\begin{aligned}\n      \\ip{\\hmsop[\\av]}{\\bv}\n      &= \\intd[\\magd']{ \\intb{\\knl (\\bv(\\xv) \\cdot \\nv(\\xv))} (\\nabla' \\cdot \\av(\\xv'))} \\\\\n      &- \\intd[\\boundd']{ \\intb{\\knl (\\bv(\\xv) \\cdot \\nv(\\xv))} (\\av(\\xv') \\cdot \\nv(\\xv'))} \\\\\n      &- \\intd[\\magd']{ \\intd{\\knl (\\div \\bv(\\xv))} (\\nabla' \\cdot \\av(\\xv'))} \\\\\n      &+ \\intd[\\boundd']{ \\intd{\\knl (\\div \\bv(\\xv))} (\\av(\\xv') \\cdot \\nv(\\xv'))}.\n    \\end{aligned}\n  \\end{equation}\n\n  Finally we swap $\\xv$ with $\\xv'$ (which we can do because $\\knl$ is symmetrical in its arguments) and collect terms with the same (outer) integral domain\n  \\begin{equation}\n    \\begin{aligned}\n      \\ip{\\hmsop[\\av]}{\\bv} &= \\intd{\\phi[\\bv] (\\div \\av)} - \\intb{\\phi[\\bv] (\\av \\cdot \\nv)}, \\\\\n      & = \\ip{\\hmsop[\\bv]}{\\av}.\n    \\end{aligned}\n  \\end{equation}\n\n\\end{proof}\n\n\n\\subsection{Magnetocrystalline anisotropy}\n\nHere we only examine the case of uniaxial anisotropy as it is the most technologically relevant\n\\begin{equation}\n  \\hca[\\mv] = \\kone (\\mv \\cdot \\ev) \\ev.\n\\end{equation}\n\nWe can easily see that the operator is symmetrical by writing out the definitions\n\\begin{equation}\n  \\begin{aligned}\n    \\ip{\\hca[\\av]}{\\bv} &= \\intd{ \\kone (\\av \\cdot \\ev) (\\ev \\cdot \\bv)}, \\\\\n    &= \\intd{(\\kone(\\bv \\cdot \\ev) \\ev) \\cdot \\av}, \\\\\n    &= \\ip{\\hca[\\bv]}{\\av}.\n  \\end{aligned}\n\\end{equation}\n\n\n\\section{Effective field and energy}\n\\label{sec:energy-field-relation}\n\nA useful relationship between the effective field and the energy is:\n\\begin{equation}\n  \\begin{aligned}\n    \\hop[\\mv] &=  \\lap \\mv + \\hms + \\hca, \\\\\n    -\\frac{1}{2} \\ip{\\mv}{\\hop[\\mv]} &= - \\frac{1}{2} \\intd{\\mv \\cdot\n      \\hop[\\mv]} = \\e,\n  \\end{aligned}\n\\end{equation}\nnote that this does not include the applied field energy.\n\nFor the magnetostatic field this relationship is obvious from the definition of $\\ems$, \\cref{eq:nd-e-ms}.\nFor a uniaxial magnetocrystalline anisotropy effective field the derivation is very simple:\n\\begin{equation}\n  - \\frac{1}{2} \\intd{\\bigb{\\kone (\\mv \\cdot \\ev) \\ev} \\cdot \\mv} =  - \\frac{\\kone}{2}\\intd{(\\mv \\cdot \\ev)^2} = \\eca.\n\\end{equation}\n\nFor the exchange effective field we use \\cref{eq:93} to obtain\n\\begin{equation}\n  -\\frac{1}{2} \\intd{\\mv \\cdot \\lap  \\mv} = -\\frac{1}{2} \\intb{\\mv \\cdot \\ddn{\\mv}} + \\frac{1}{2}  \\intd{\\grad \\mv : \\grad \\mv}.\n\\end{equation}\nThen applying Neumann or periodic boundary conditions on $\\mv$ gives the result\n\\begin{equation}\n  -\\frac{1}{2} \\intd{\\mv \\cdot \\lap \\mv} = \\frac{1}{2} \\intd{(\\grad \\mv)^2} = \\eex.\n\\end{equation}\n% Alternatively, with periodic boundary conditions, the boundary integral is zero due to opposite sides of the boundary having equal $\\mv$ and $\\dmdn$ except for the opposite sign of $\\nv$ (as in \\cref{eq:95}).\n\n\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"./main\"\n%%% End:\n", "meta": {"hexsha": "68040f82e4f3e684ff9856e93f03058bea711ca5", "size": 8264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "h-linear-sym-operator.tex", "max_stars_repo_name": "davidshepherd7/thesis", "max_stars_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-13T10:36:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-28T21:11:27.000Z", "max_issues_repo_path": "h-linear-sym-operator.tex", "max_issues_repo_name": "davidshepherd7/thesis", "max_issues_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "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": "h-linear-sym-operator.tex", "max_forks_repo_name": "davidshepherd7/thesis", "max_forks_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "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.9108910891, "max_line_length": 224, "alphanum_fraction": 0.6326234269, "num_tokens": 2915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.6104711808326919}}
{"text": "\\documentclass[]{report}\n\n\\usepackage{amsmath}\n\\usepackage{bm}\n\\usepackage{graphicx}\n\n\\graphicspath{ {images/} }\n\n\\title{CSCI 567 HW \\# 3}\n\\author{Mohmmad Suhail Ansari \\\\ USC ID: 8518586692\\\\e-mail: mohmmada@usc.edu}\n\n\\begin{document}\n\n\\maketitle\n\n\\paragraph{Sol. 1.1}\n\tGiven, \n\t\\[ E[\\beta] = \\frac{1}{n} \\sum_{i = 1}^{N} {(y_i - x_i^T \\beta)}^2 + \\lambda {\\|\\beta\\|}_2^2\\]\n\n\tWe can write from definition of X\n\t\\[ \\sum^N (y_i - x_i^T \\beta)^2 = {\\| (\\textbf{y} - X \\beta)\\|}^2 = (\\textbf{y} - X \\beta)^T (\\textbf{y} - X \\beta)\\]\n\n\tsubstituting in the first equation\n\n\t\\[ E[\\beta] = \\frac{1}{n} (\\textbf{y} - X \\beta)^T (\\textbf{y} - X \\beta) + \\lambda \\beta^T \\beta \\]\n\n\ttaking partial derivative w.r.t. $\\beta$, we get\n\n\t\\[ \\frac{\\partial{E[\\beta]}}{\\partial{\\beta}} = \\frac{2}{n} [-X^T \\textbf{y} + X^T X \\beta] + 2 \\lambda \\beta = 0\\]\n\t\\[ = -X^T \\textbf{y} + X^T X \\beta + n \\lambda \\beta \\]\n\t\\[ X^T \\textbf{y} = (X^T X + n \\lambda I_D) \\beta \\]\n\t\\[ \\hat{\\beta}_\\lambda = (X^T X + n \\lambda I_D)^{-1} X^T \\textbf{y} \\]\n\n\n\tSince, $\\epsilon$ is normally distributed, we have \n\t\\[ y = \\mathcal{N}(X^T \\beta^*, \\delta^2 I)\\]\n\tand since $\\hat{y} = X^T \\hat{\\beta}_\\lambda$, we have \n\t\\[ \\hat{\\beta}_\\lambda = \\mathcal{N}((X^T X + n \\lambda I_D)^{-1} X^T X^T \\beta^*, (X^T X + n \\lambda I_D)^{-1} X^T \\delta^2 (X^T X + n \\lambda I_D)^{-1} )\\]\n\t\n\n\\paragraph{Sol. 1.2}\n\t\n\tFrom 1.2, let $L = X^T X$, then if we replace it in the $\\hat{\\beta}_\\lambda$, we get \n\t\\[ \\hat{\\beta}_\\lambda = (L + n \\lambda I) X^T y \\]\n\t\\[ = (L(I + n\\lambda L^{-1}))^{-1} L [L^{-1} X^T y] \\]\n\t\\[ = (I + n \\lambda L^{-1})^{-1} L^{-1} L [(X^T X)^{-1} X^T y]\\]\n\tand since, $(X^T X)^{-1} X^T y = \\beta^*$, we get \n\t\\[ \\hat{\\beta}_\\lambda = (I + n\\lambda L^{-1})^{-1} \\beta^* \\]\n\n\tNow,\n\t\\[ E[ x^T \\hat{\\beta}_\\lambda ] - x^T \\beta^* = X^T (I + n\\lambda L^{-1})^{-1} \\beta^* - X^T \\beta^* \\]\n\t\\[ = X^T (I + n\\lambda (X^T X)^{-1})^{-1} - I) \\beta^* \\]\n\n\\paragraph{Sol. 1.3}\n\t\n\tN/A\n\n\\paragraph{Sol. 1.4}\n\t\n\tN/A\n\n\n\\paragraph{Sol. 2.1}\n\tusing Mercer's theorem we can write for any function $f(\\cdot)$\n\t\\[ \\int_{x, x'} k_3 (x, x') f(x) f(x') dx dx' \\]\n\t\\[ = \\int_{x, x'} (a_1 k_1 (x, x') + a_2 k_2 (x, x') ) f(x) f(x') dx dx' \\]\n\t\\[ = \\int_{x, x'} a_1 k_1 (x, x') f(x) f(x') dx dx' + \\int_{x, x'} a_2 k_2 (x, x') f(x) f(x') dx dx' \\]\n\tand since, we know that $k_1 (\\cdot, \\cdot)$ and $k_2 (\\cdot, \\cdot)$ are valid kernel functions, then \n\t\\[ \\int_{x, x'} k_3 (x, x') f(x) f(x') dx dx' \\geq 0 \\]\n\tand hence, $k_3 (\\cdot, \\cdot)$ is a valid kernel function.\n\n\\paragraph{Sol. 2.2}\n\t\n\tFor a feature map $\\phi$ we know that a valid kernel is defined as\n\t\\[ k(x, x') = \\langle \\phi(x), \\phi(x') \\rangle \\]\n\tso we if we use the feature map $\\phi: x \\rightarrow f(x)$, then \n\t\\[ k_4(x, x')  = {\\langle \\phi(x), \\phi(x') \\rangle}_{\\chi^\\phi} \\]\n\t\\[ = f(x) f(x') \\]\n\tbecause $f(x)$ is real valued and hence, $k_4(x, x') = f(x) f(x')$ is a valid kernel.\n\n\t%if $f(\\cdot)$ is a real valued function then using Mercer's theorem we can write\n\t%\\[ \\int_{x, x'}  k_4 (x, x') f(x) f(x') dx dx' \\]\n\t%\\[ = \\int_{x, x'} f(x) f(x') f(x) f(x') dx dx' \\]\n\t%\\[ = \\int_{x, x'} (f(x))^2 (f(x'))^2 dx dx' \\]\n\t%and since $(f(\\cdot))^2 \\geq 0$, therefore\n\t%\\[ \\int_{x, x'}  k_4 (x, x') f(x) f(x') dx dx' \\geq 0 \\]\n\t%and hence, $k_4$ is a valid kernel function.\n\n\\paragraph{Sol. 2.3}\n\tLet, $\\phi_1$ and $\\phi_2$ be feature map of $k_1$ and $k_2$ respectively and let $f_i (x)$ and $g_i (x)$ be $i^{th}$ feature value for \n\t$\\phi_1$ and $\\phi_2$ respectively, then by definition of $k_5$, we can write\n\t\\[ k_5 (x, x') = k_1 (x, x') k_2 (x, x') \\]\n\t\\[ = {\\phi_1 (x)}^T \\phi_1 (x') {\\phi_2 (x)}^T \\phi(x') \\]\n\t\\[ = (\\sum_{i} f_i (x) f_i (x')) (\\sum_{j} g_j (x) g_j (x')) \\]\n\t\\[ = \\sum_i \\sum_j (f_i (x) g_j (x)) (f_j (x') g_j (x'))\\]\n\tso now, we can define a feature map $\\phi_3$ where its $i^{th}$ feature is defined as $h_{i, j}(x) = f_i (x) g_j (x)$. Which gives us\n\t\\[ k_5 (x, x') = {\\phi_3 (x)}^T \\phi_3 (x')\\]\n\tAlso, $k_5$ is symmetric since both $k_1$ and $k_2$ are symmetric, i.e.\n\t\\[ k_5 (x, x') = k_1 (x, x') k_2 (x, x') \\]\n\t\\[ = k_1 (x', x) k_2 (x', x) \\]\n\t\\[ = k_5 (x', x) \\]\n\ttherefore $k_5$ is a valid kernel function.\n\n\\paragraph{Sol. 3.1}\n\tFrom the text, we can write the objective function as \n\t\\[ \\epsilon(w) = \\sum_n (y_i - w^T x_i)^2 + \\lambda {\\| w \\|}_2^2 \\]\n\twe know that\n\t\\begin{align}\n    \tw^T x_i &= \\begin{bmatrix}\n           w_1 \\\\\n           w_2 \\\\\n           \\vdots \\\\\n           w_D\n         \\end{bmatrix} \\begin{bmatrix}x_{i1} x_{i2} \\cdots x_{iD} \\end{bmatrix}\n  \t\\end{align}\n  \t\\[ = \\sum_j^D w_j x_{ij} = \\sum_j^D x_{ij} w_j \\]\n  \t\\[ = x_i^T w \\]\n\n  \tNow, if $\\textbf{y} = [y_1 \\, y_2 \\, y_3 \\cdots \\, y_N]$ and\n  \t\\begin{align}\n    \tX &= \\begin{bmatrix}\n           x_{11} & x_{21} \\cdots x_{N1}\\\\\n           x_{12} & x_{22} \\cdots x_{N2}\\\\\n           x_{13} & x_{23} \\cdots x_{N3}\\\\\n           \\vdots & \\vdots  \\\\\n           x_{1D} & x_{2D} \\cdots x_{ND}\n         \\end{bmatrix}\n  \t\\end{align}\n  \t\n  \twe write\n  \t\\[ \\sum_n (y_i - w^T x_i)^2 = \\| \\textbf{y} - Xw \\|_2^2 \\]\n  \t\n  \tthen we have \n  \t\\[ \\epsilon(w) = \\|\\textbf{y} - Xw\\|_2^2 + \\lambda \\| w\\|_2^2 \\]\n\n\ttaking partial derivative w.r.t $w$, we get \n\t\\[ \\frac{\\partial{\\epsilon(w)}}{\\partial{w}} = 2 X^T (\\textbf{y} - Xw) + 2\\lambda w = 0\\]\n\t%%now, we can write $w^T x_i = x_i^T w$,\n\t%%\\[ = -\\sum_n (y_i x_i) + (\\sum_n x_i^T x_i) w + \\lambda w = 0 \\]\n\t%%we can write $\\sum_n (y_i x_i) = yX = X^T y$ and $\\sum_n x_i^T x_i = X^T X$\n\t%%\\[ = -X^T \\textbf{y} + X^T X w + \\lambda w = 0 \\]\n\t%%\\[ = -X^T \\textbf{y} + (X^T X + \\lambda I_D ) w = 0\\]\n\t\\begin{equation}\n\t\t w^* = {(X^T X + \\lambda I_D)}^{-1} X^T \\textbf{y}\n\t\\end{equation}\n\n\\paragraph{Sol. 3.2}\t\n\twe know\n\t\\[ w^* =  {(X^T X + \\lambda I_D)}^{-1} X^T \\textbf{y} \\]\n\t \n\talso, \n\t\\[ (X^T X + \\lambda I_D) X^T = X^T X X^T + \\lambda X^T = X^T (X X^T + \\lambda I_N)\\] \n\tmultiplying both sides with $(X^T X + \\lambda I_D)^{-1}$ on left and $(X X^T + \\lambda I_N)^{-1} \\textbf{y}$ on right, we get\n\t\\[ X^T (X X^T + \\lambda I_N)^{-1} \\textbf{y} = (X^T X + \\lambda I_D)^{-1} X^T \\textbf{y} \\]\n\n\tusing the above equation in $w^{*}$, we get\n\t\\[ w^{*} = X^T (X X^T + \\lambda I_N)^{-1} \\textbf{y}\\]\n\n\tNow, if we substitute $X$ with $\\mathbf{\\Phi} (x)$ (because dimensions of $XX^T$ and $\\mathbf{\\Phi}(x) {\\mathbf{\\Phi}(x)}^T$ is $N \\times N$)\n\ttherefore we can write \n\t\\[ w^* = \\mathbf{\\Phi}^T {(\\mathbf{\\Phi} \\mathbf{\\Phi}^T + \\lambda I_N)}^{-1} \\textbf{y} \\]\n\t\n\\paragraph{Sol. 3.3}\n\t\\[ \\hat{y} = w^{*T}\\phi(x)\\]\n\t\\[ = {[\\mathbf{\\Phi}^T {(\\mathbf{\\Phi} \\mathbf{\\Phi}^T + \\lambda I_N)}^{-1} \\textbf{y}]}^{T} \\phi(x)\\]\n\t\\[ = y^T {((\\mathbf{\\Phi} \\mathbf{\\Phi}^T + \\lambda I_N)^T)}^{-1} \\mathbf{\\Phi} \\phi(x) \\]\n\t\\[ = y^T {(\\mathbf{\\Phi}^T \\mathbf{\\Phi} + \\lambda I_N)}^{-1} \\mathbf{\\Phi} \\phi(x) \\]\n\t\n\twe also have, \n\t\\begin{align}\n    \t\\mathbf{\\Phi} \\phi(x) &= \\begin{bmatrix}\n           \\phi(x_1)^T \\phi(x) \\\\\n           \\phi(x_2)^T \\phi(x) \\\\\n           \\phi(x_3)^T \\phi(x) \\\\\n           \\vdots  \\\\\n           \\phi(x_N)^T \\phi(x)\n         \\end{bmatrix} = \\kappa(x)\n  \t\\end{align}\n\tsubstituting value of $K$ and $\\kappa(x)$ in $\\hat{y}$, we get \n\t\\[ \\hat{y} = \\textbf{y}^T (K + \\lambda I_N)^{-1} \\kappa(x) \\]\n\n\\paragraph{Sol. 3.4}\n\tThe time complexity for both is $O(N^3)$, but in Ridge Regression there are two instances of matrix multiplication and one inversion, taking\n\t$O(N^3)$ whereas Kernel Ridge Regression only calculate matrix inverse once.\n\n\n\\paragraph{Sol. 4.1}\n\tAs we can see from the graph below the positive examples are \\textbf{not} linearly separable from negative examples.\n\n\\paragraph{Sol. 4.2}\n\tAs observed from values of the transformed feature space a hyper plane in the dimension of $(x_1 x_2)$ feature separates the points, therefore we have\n\t\\[ w = [0 \\quad 0 \\quad 0 \\quad 1]\\]\n\n\\paragraph{Sol. 4.3}\n\tAdding (0.5, 0.5) as a negative example will prevent the positive and negative examples to no longer be linearly separable.\t\n\n\\paragraph{Sol. 4.4}\n\tThis feature transformation corresponds to the the $K(x, x')$ given as \n\t\\[ K(x, x') = 1 + x^2 + {x'}^2 + (x x' )^2\\]\n\n\n\\paragraph{Sol. 5} $\\newline$\n\t\n\t\\textbf{(1)} Since, $C \\rightarrow \\infty$, the penalty for misclassification is really high, i.e. the decision will perfectly divide the points. However, since the points are linearly inseparable the decision boundary is indeterminable (or at least it is not linear). \n\t\\\\\n\n\t\\textbf{(2)}\n\tFor $C \\approx 0$, means the misclassification penalty is small and the decision boundary would mis-classify some points. But a linear can be found (shown in figure below)\n\t\\\\\n\n\t\\textbf{(3)}\n\tThe case with $C \\approx 0$ will perform better than case with $C \\rightarrow \\infty$, since a large value of C will choose a smaller-margin hyperplane compared to small value of C, so small-margin hyperplane might not generalize the vectors enough, i.e. the accuracy for $C \\rightarrow \\infty$ will be high for training data, but it might perform well for test (unseen) data, whereas the $C \\approx 0$ will generalize the vectors enough to perform well for test data.\n\t\\\\\n\n\t\\textbf{(4)}\n\tSince, the data is already linearly inseparable and and for large $C$ there needs to be a decision boundary which should separate points with minimal misclassification so any point in or near the cluster or ``$-$'' points will still lead to same decision boundary (shown below).\n\t\\\\\n\n\t\\textbf{(5)}\n\tA point far from the ``$-$'' cluster will change the decision boundary significantly since the decision boundary should not misclassify (large C) this point ans must include the new point on the correct side of the decision boundary.\n\t\\\\\n\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{Problem-5}\n\t\\end{center}\n\n\\paragraph{Sol. 6}\n\\subparagraph{1.a}\n\tFor sample size of n = 10, we have the following plot\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{fig_10_MSE}\n\t\\end{center}\n\tand the bias and variance are\n\n\t\\begin{center}\n\t\t\\begin{tabular}{c|c|c}\n\t\t\\hline\n\t\t $g(x)$     &   $Var[\\hat{y}]$ &   ${Bias}^2$ \\\\\n\t\t\\hline\n\t\t $g_0 (x)$ &      0           & 0.00835376 \\\\\n\t\t $g_1 (x)$ &      0 \t\t  & 0.0010114999 \\\\\n\t\t $g_2 (x)$ &      0.0129696   & 0.0010114995 \\\\\n\t\t $g_3 (x)$ &      0.0129735   & 0.0010114991 \\\\\n\t\t $g_4 (x)$ &      0.0129809   & 0.0010114983 \\\\\n\t\t $g_5 (x)$ &      0.0129812   & 0.0010114976 \\\\\n\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\n\\subparagraph{1.b}\n\tFor sample size of n = 100, we have the following plot\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{fig_100_MSE}\n\t\\end{center}\n\n\tand the bias and variance are\n\n\t\\begin{center}\n\t\t\\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t $g(x)$     &   $Var[\\hat{y}]$ &   ${Bias}^2$ \\\\\n\t\t\t\\hline\n\t\t\t $g_0 (x)$ &      0           & 0.0100663   \\\\\n\t\t\t $g_1 (x)$ &      0  \t\t  & 0.00020746359 \\\\\n\t\t\t $g_2 (x)$ &      0.0114071   & 0.00020746354 \\\\\n\t\t\t $g_3 (x)$ &      0.011429    & 0.00020746349 \\\\\n\t\t\t $g_4 (x)$ &      0.0114578   & 0.00020746346 \\\\\n\t\t\t $g_5 (x)$ &      0.011458    & 0.00020746345 \\\\\n\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\n\\subparagraph{1.c}\n\tIf we plot the ${Bias}^2$ against $Var[\\hat{y}]$ we see that with increasing complexity, the ${Bias}^2$ decreases and $Var[\\hat{y}]$\n\tincreases.\n\n\tFor Sample Size (n) = 10\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{fig_10_BV}\n\t\\end{center}\n\n\tFor Sample Size (n) = 100\n\t\\begin{center}\n\t\t\\includegraphics[width=\\textwidth]{fig_100_BV}\n\t\\end{center}\n\n\tWe can also observe that with increase in sample size, both ${Bias}^2$ and $Var[\\hat{y}]$ decreases.\n\n\\subparagraph{1.d}\n\tFor each value of $\\lambda$ we get the values for $Bias^2$ and $Var[\\hat{y}]$ as \n\t\\begin{center}\n\t\t\\begin{tabular}{c|c|c}\n\t\t\t\\hline\n\t\t\t           $\\lambda$ &    $Var[\\hat{y}]$ &          $Bias^2$ \\\\\n\t\t\t\\hline\n\t\t\t 0.001 & 1.339555842497451 & 1.335753691359456 \\\\\n\t\t\t 0.003 & 1.339555198601041 & 1.335753691360410 \\\\\n\t\t\t 0.010 & 1.339547874313111 & 1.335753691371258 \\\\\n\t\t\t 0.030 & 1.339483487636583 & 1.335753691466629 \\\\\n\t\t\t 0.1   & 1.338751426233234 & 1.335753692551133 \\\\\n\t\t\t 0.3   & 1.332342280730491 & 1.335753702058702 \\\\\n\t\t\t 1.0   & 1.262651053579910 & 1.335753806797648 \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\n\tWe can see from the plots below that $Var[\\hat{y}$ decreases with increasing $\\lambda$, whereas $Bias^2$ increases with increasing $\\lambda$.\n\n\t\\begin{center}\n\t\t\n\t\t\\includegraphics[width=\\textwidth]{var_lambda}\n\t\t\\[ Var[\\hat{y}] \\]\n\t\\end{center}\n\t\n\t\\begin{center}\n\t\t\n\t\t\\includegraphics[width=\\textwidth]{bias_lambda}\n\t\t\\[ Bias^2 \\]\n\t\\end{center}\n\n\\subparagraph{Use linear SVM in LIBSVM}\n\t\\begin{center}\n\t\t\\begin{tabular}{l|c|c}\n\t\t\t\\hline\n\t\t\t    C     & 3-Fold Cross Validation Accuracy  & Execution Time \\\\\n\t\t\t    \\hline\n\t\t\t    $4^{-6}$     & 55.75\\%     & 0m0.687s      \\\\\n\t\t\t    $4^{-5}$     & 55.75\\%     & 0m0.654s      \\\\\n\t\t\t    $4^{-4}$     & 55.75\\%     & 0m0.666s      \\\\\n\t\t\t    $4^{-3}$     & 71.55\\%     & 0m0.711s      \\\\\n\t\t\t    $4^{-2}$     & 91.55\\%     & 0m0.533s      \\\\\n\t\t\t    $4^{-1}$     & 91.8\\%      & 0m0.338s      \\\\\n\t\t\t    $4^{2}$      & 96.35\\%     & 0m0.204s      \\\\\n\t\t\t    $4^{0}$      & 94.05\\%     & 0m0.239s      \\\\\n\t\t\t    $4^{1}$      & 95.5\\%      & 0m0.206s      \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\tAverage Training Time : 0.4708s\n\n\\newpage\n\n\n\n\\subparagraph{Use Kernel SVM in LIBSVM}\n\n\t\\begin{center}\t\t\t\n\t\tPolynomial Kernel\n\t\t\t\\begin{tabular}{lr|c|c|c}\n\t\t\t\\hline\n\t\t\t C      &   degree & 3-Fold Cross Validation Accuracy   & Execution Time   \\\\\n\t\t\t\\hline\n\t\t\t $4^{-3}$ &        1 & 55.75\\%                             & 0m0.727s         \\\\\n\t\t\t $4^{-3}$ &        2 & 55.75\\%                             & 0m0.697s         \\\\\n\t\t\t $4^{-3}$ &        3 & 55.75\\%                             & 0m0.717s         \\\\\n\t\t\t $4^{-2}$ &        1 & 90.25\\%                             & 0m0.581s         \\\\\n\t\t\t $4^{-2}$ &        2 & 89\\%                                & 0m0.688s         \\\\\n\t\t\t $4^{-2}$ &        3 & 76.7\\%                              & 0m0.801s         \\\\\n\t\t\t $4^{-1}$ &        1 & 91.2\\%                              & 0m0.360s         \\\\\n\t\t\t $4^{-1}$ &        2 & 92.05\\%                             & 0m0.441s         \\\\\n\t\t\t $4^{-1}$ &        3 & 92.05\\%                             & 0m0.513s         \\\\\n\t\t\t $4^{0}$  &        1 & 92.75\\%                             & 0m0.248s         \\\\\n\t\t\t $4^{0}$  &        2 & 93.2\\%                              & 0m0.292s         \\\\\n\t\t\t $4^{0}$  &        3 & 92.7\\%                              & 0m0.366s         \\\\\n\t\t\t $4^{1}$  &        1 & 94.45\\%                             & 0m0.200s         \\\\\n\t\t\t $4^{1}$  &        2 & 94.95\\%                             & 0m0.217s         \\\\\n\t\t\t $4^{1}$  &        3 & 95.2\\%                              & 0m0.233s         \\\\\n\t\t\t $4^{2}$  &        1 & 94.5\\%                              & 0m0.236s         \\\\\n\t\t\t $4^{2}$  &        2 & 95.9\\%                              & 0m0.191s         \\\\\n\t\t\t $4^{2}$  &        3 & 96.15\\%                             & 0m0.193s         \\\\\n\t\t\t $4^{3}$  &        1 & 94.25\\%                             & 0m0.209s         \\\\\n\t\t\t $4^{3}$  &        2 & 96.65\\%                             & 0m0.182s         \\\\\n\t\t\t $4^{3}$  &        3 & 97\\%                                & 0m0.195s         \\\\\n\t\t\t $4^{4}$  &        1 & 94.45\\%                             & 0m0.337s         \\\\\n\t\t\t $4^{4}$  &        2 & 97\\%                                & 0m0.188s         \\\\\n\t\t\t $4^{4}$  &        3 & 97.05\\%                             & 0m0.175s         \\\\\n\t\t\t $4^{5}$  &        1 & 94.15\\%                             & 0m0.544s         \\\\\n\t\t\t $4^{5}$  &        2 & 96.75\\%                             & 0m0.186s         \\\\\n\t\t\t $4^{5}$  &        3 & 96.55\\%                             & 0m0.203s         \\\\\n\t\t\t $4^{6}$  &        1 & 94.2\\%                              & 0m2.278s         \\\\\n\t\t\t $4^{6}$  &        2 & 96.95\\%                             & 0m0.240s         \\\\\n\t\t\t $4^{6}$  &        3 & 96.7\\%                              & 0m0.184s         \\\\\n\t\t\t $4^{7}$  &        1 & 94.2\\%                              & 0m5.259s         \\\\\n\t\t\t $4^{7}$  &        2 & 96.7\\%                              & 0m0.265s         \\\\\n\t\t\t $4^{7}$  &        3 & 96.7\\%                              & 0m0.188s         \\\\\n\t\t\t \\hline\n\t\t\t\\end{tabular}\n\t\t\\end{center}\n\n\t\tAverage Training Time : 0.5555s\n\n\t\t\\newpage\n\t\\begin{center}\t\t\n\t\tRBF Kernel\n\t\t\t\\begin{tabular}{l|l|c|c}\n\t\t\t\\hline\n\t\t\t C      & $\\gamma$   & 3-Fold Cross Validation Accuracy   & Execution Time   \\\\\n\t\t\t\\hline\n\t\t\t $4^{-3}$ & $4^{-7}$   & 55.75\\%                             & 0m0.717s         \\\\\n\t\t\t $4^{-3}$ & $4^{-6}$   & 55.75\\%                             & 0m0.760s         \\\\\n\t\t\t $4^{-3}$ & $4^{-5}$   & 55.75\\%                             & 0m0.773s         \\\\\n\t\t\t $4^{-3}$ & $4^{-4}$   & 55.75\\%                             & 0m0.724s         \\\\\n\t\t\t $4^{-3}$ & $4^{-3}$   & 56\\%                                & 0m0.800s         \\\\\n\t\t\t $4^{-3}$ & $4^{-2}$   & 87.55\\%                             & 0m0.658s         \\\\\n\t\t\t $4^{-3}$ & $4^{-1}$   & 60.6\\%                              & 0m0.704s         \\\\\n\t\t\t $4^{-2}$ & $4^{-7}$   & 55.75\\%                             & 0m0.676s         \\\\\n\t\t\t $4^{-2}$ & $4^{-6}$   & 55.75\\%                             & 0m0.749s         \\\\\n\t\t\t $4^{-2}$ & $4^{-5}$   & 55.75\\%                             & 0m0.883s         \\\\\n\t\t\t $4^{-2}$ & $4^{-4}$   & 64.4\\%                              & 0m0.738s         \\\\\n\t\t\t $4^{-2}$ & $4^{-3}$   & 90.55\\%                             & 0m0.862s         \\\\\n\t\t\t $4^{-2}$ & $4^{-2}$   & 92.2\\%                              & 0m0.415s         \\\\\n\t\t\t $4^{-2}$ & $4^{-1}$   & 92.95\\%                             & 0m0.595s         \\\\\n\t\t\t $4^{-1}$ & $4^{-7}$   & 55.75\\%                             & 0m0.673s         \\\\\n\t\t\t $4^{-1}$ & $4^{-6}$   & 55.75\\%                             & 0m0.739s         \\\\\n\t\t\t $4^{-1}$ & $4^{-5}$   & 66.55\\%                             & 0m0.741s         \\\\\n\t\t\t $4^{-1}$ & $4^{-4}$   & 90.85\\%                             & 0m0.890s         \\\\\n\t\t\t $4^{-1}$ & $4^{-3}$   & 91.35\\%                             & 0m0.370s         \\\\\n\t\t\t $4^{-1}$ & $4^{-2}$   & 93.2\\%                              & 0m0.292s         \\\\\n\t\t\t $4^{-1}$ & $4^{-1}$   & 95.7\\%                              & 0m0.391s         \\\\\n\t\t\t $4^{0}$  & $4^{-7}$   & 55.75\\%                             & 0m0.760s         \\\\\n\t\t\t $4^{0}$  & $4^{-6}$   & 67.8\\%                              & 0m0.697s         \\\\\n\t\t\t $4^{0}$  & $4^{-5}$   & 91.05\\%                             & 0m0.524s         \\\\\n\t\t\t $4^{0}$  & $4^{-4}$   & 91.35\\%                             & 0m0.588s         \\\\\n\t\t\t $4^{0}$  & $4^{-3}$   & 93.55\\%                             & 0m0.229s         \\\\\n\t\t\t $4^{0}$  & $4^{-2}$   & 96.05\\%                             & 0m0.207s         \\\\\n\t\t\t $4^{0}$  & $4^{-1}$   & 97.15\\%                             & 0m0.281s         \\\\\n\t\t\t $4^{1}$  & $4^{-7}$   & 68.05\\%                             & 0m0.836s         \\\\\n\t\t\t $4^{1}$  & $4^{-6}$   & 90.9\\%                              & 0m0.670s         \\\\\n\t\t\t $4^{1}$  & $4^{-5}$   & 91.4\\%                              & 0m0.391s         \\\\\n\t\t\t $4^{1}$  & $4^{-4}$   & 93.3\\%                              & 0m0.300s         \\\\\n\t\t\t $4^{1}$  & $4^{-3}$   & 94.85\\%                             & 0m0.185s         \\\\\n\t\t\t $4^{1}$  & $4^{-2}$   & 96.8\\%                              & 0m0.165s         \\\\\n\t\t\t $4^{1}$  & $4^{-1}$   & 96.95\\%                             & 0m0.263s         \\\\\n\t\t\t $4^{2}$  & $4^{-7}$   & 90.9\\%                              & 0m1.207s         \\\\\n\t\t\t $4^{2}$  & $4^{-6}$   & 91.5\\%                              & 0m0.537s         \\\\\n\t\t\t $4^{2}$  & $4^{-5}$   & 93.35\\%                             & 0m0.237s         \\\\\n\t\t\t $4^{2}$  & $4^{-4}$   & 94.6\\%                              & 0m0.205s         \\\\\n\t\t\t $4^{2}$  & $4^{-3}$   & 96\\%                                & 0m0.182s         \\\\\n\t\t\t $4^{2}$  & $4^{-2}$   & 97.15\\%                             & 0m0.163s         \\\\\n\t\t\t $4^{2}$  & $4^{-1}$   & 96.7\\%                              & 0m0.263s         \\\\\n\t\t\t \\hline\n\t\t\t\\end{tabular}\n\n\t\t\tContinued... \\newline\n\n\t\t\t\\begin{tabular}{l|l|c|c}\n\t\t\t\\hline\n\t\t\t C      & $\\gamma$   & 3-Fold Cross Validation Accuracy   & Execution Time   \\\\\n\t\t\t\\hline\n\t\t\t $4^{3}$  & $4^{-7}$   & 91.5\\%                              & 0m0.429s         \\\\\n\t\t\t $4^{3}$  & $4^{-6}$   & 93.45\\%                             & 0m0.335s         \\\\\n\t\t\t $4^{3}$  & $4^{-5}$   & 94.45\\%                             & 0m0.278s         \\\\\n\t\t\t $4^{3}$  & $4^{-4}$   & 94.65\\%                             & 0m0.194s         \\\\\n\t\t\t $4^{3}$  & $4^{-3}$   & 96.7\\%                              & 0m0.168s         \\\\\n\t\t\t $4^{3}$  & $4^{-2}$   & 97\\%                                & 0m0.167s         \\\\\n\t\t\t $4^{3}$  & $4^{-1}$   & 96.7\\%                              & 0m0.249s         \\\\\n\t\t\t $4^{4}$  & $4^{-7}$   & 93.45\\%                             & 0m0.277s         \\\\\n\t\t\t $4^{4}$  & $4^{-6}$   & 94.45\\%                             & 0m0.266s         \\\\\n\t\t\t $4^{4}$  & $4^{-5}$   & 94.5\\%                              & 0m0.260s         \\\\\n\t\t\t $4^{4}$  & $4^{-4}$   & 95.65\\%                             & 0m0.196s         \\\\\n\t\t\t $4^{4}$  & $4^{-3}$   & 97.3\\%                              & 0m0.174s         \\\\\n\t\t\t $4^{4}$  & $4^{-2}$   & 96.85\\%                             & 0m0.180s         \\\\\n\t\t\t $4^{4}$  & $4^{-1}$   & 96.7\\%                              & 0m0.242s         \\\\\n\t\t\t $4^{5}$  & $4^{-7}$   & 94.45\\%                             & 0m0.236s         \\\\\n\t\t\t $4^{5}$  & $4^{-6}$   & 94.5\\%                              & 0m0.262s         \\\\\n\t\t\t $4^{5}$  & $4^{-5}$   & 94.55\\%                             & 0m0.297s         \\\\\n\t\t\t $4^{5}$  & $4^{-4}$   & 96.7\\%                              & 0m0.232s         \\\\\n\t\t\t $4^{5}$  & $4^{-3}$   & 96.9\\%                              & 0m0.203s         \\\\\n\t\t\t $4^{5}$  & $4^{-2}$   & 96.85\\%                             & 0m0.169s         \\\\\n\t\t\t $4^{5}$  & $4^{-1}$   & 96.7\\%                              & 0m0.249s         \\\\\n\t\t\t $4^{6}$  & $4^{-7}$   & 94.45\\%                             & 0m0.199s         \\\\\n\t\t\t $4^{6}$  & $4^{-6}$   & 94.75\\%                             & 0m0.191s         \\\\\n\t\t\t $4^{6}$  & $4^{-5}$   & 95.65\\%                             & 0m0.434s         \\\\\n\t\t\t $4^{6}$  & $4^{-4}$   & 97.3\\%                              & 0m0.311s         \\\\\n\t\t\t $4^{6}$  & $4^{-3}$   & 97\\%                                & 0m0.225s         \\\\\n\t\t\t $4^{6}$  & $4^{-2}$   & 96.85\\%                             & 0m0.166s         \\\\\n\t\t\t $4^{6}$  & $4^{-1}$   & 96.7\\%                              & 0m0.260s         \\\\\n\t\t\t $4^{7}$  & $4^{-7}$   & 94.6\\%                              & 0m0.264s         \\\\\n\t\t\t $4^{7}$  & $4^{-6}$   & 94.45\\%                             & 0m0.277s         \\\\\n\t\t\t $4^{7}$  & $4^{-5}$   & 96.5\\%                              & 0m0.484s         \\\\\n\t\t\t $4^{7}$  & $4^{-4}$   & 96.85\\%                             & 0m0.422s         \\\\\n\t\t\t $4^{7}$  & $4^{-3}$   & 97\\%                                & 0m0.225s         \\\\\n\t\t\t $4^{7}$  & $4^{-2}$   & 96.85\\%                             & 0m0.156s         \\\\\n\t\t\t $4^{7}$  & $4^{-1}$   & 96.7\\%                              & 0m0.238s         \\\\\n\t\t\t \\hline\n\t\t\t\\end{tabular}\n\n\t\\end{center}\n\n\tAverage Training Time : 0.415s \\newline\n\n\tWe find that the best 3-Fold Cross Validation accuracy we can achieve it using an RBF Kernel with parameters $C = 4^6$ and $\\gamma = 4^{-4}$.\n\tAfter running the libsvm with appropriate parameters we get the classification accuracy = 49.85\\%.\n\n\n\\end{document}", "meta": {"hexsha": "b74db894f1daec688e4315e3c77ac9af0e41ee0f", "size": 23564, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2-6/HW3/hw3.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/HW3/hw3.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/HW3/hw3.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": 47.5080645161, "max_line_length": 469, "alphanum_fraction": 0.4114751316, "num_tokens": 9055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140728, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.610471176975708}}
{"text": "\\section{Rational and Periodic Functions}\r\n\\subsection{Rational Functions}\r\nWe want to study meromorphic functions in the Riemann sphere, which are simply the rational functions.\r\n\\begin{proposition}\r\n    Every meromorphic function $f:\\mathbb C_\\infty\\to\\mathbb C_\\infty$ on the Riemann sphere is a rational function, that is we can write\r\n    $$f(z)=c\\frac{(z-a_1)\\cdots (z-a_m)}{(z-b_1)\\cdots (z-b_n)}$$\r\n    for $c,a_i,b_i\\in\\mathbb C$.\r\n\\end{proposition}\r\nGiven an $f$ in this form, we can assume WLOG that $a_i\\neq b_j$ for all $i,j$.\r\n\\begin{proof}\r\n    The case that $f$ is constant is trivial.\r\n    Replacing $f\\to 1/f$ necessary, then we can assume WLOG that $f(\\infty)\\neq\\infty$.\r\n    Let $b_1,\\ldots,b_{n'}$ be poles of $f$ (there are finitely many as the Riemann sphere is compact).\r\n    Then by assumption $b_i\\neq\\infty$ for all $i$.\r\n    The Laurent series about $b_j$ then has the form\r\n    $$f(z)=\\sum_{l=-k_j}^\\infty c_{j,l}(z-b_j)^l,c_{-k_j,j}\\neq 0$$\r\n    then $k_j$ is the order of the pole.\r\n    Let\r\n    $$Q_j(z)=\\sum_{l=-k_j}^{-1} c_{j,l}(z-b_j)^l$$\r\n    be the principal part of the series and let\r\n    $$g(z)=f(z)-\\sum_{j=1}^{n'}Q_j(z)$$\r\n    Then $g$ is entire and has a removable singularity at $\\infty$, hence it has to be constant, which means $f$ has to be rational.\r\n\\end{proof}\r\n\\begin{remark}\r\n    In th proof, $f(\\infty)\\in\\mathbb C$ means $m\\le n$, and in this case we have $\\deg f=\\sum_jk_j=n$, therefore in general the degree of a rational function is $\\max\\{m,n\\}$.\r\n\\end{remark}", "meta": {"hexsha": "2b4fa27a419778858d850b40313a017cc8348957", "size": 1519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/rational.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": "13/rational.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": "13/rational.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": 58.4230769231, "max_line_length": 177, "alphanum_fraction": 0.6642527979, "num_tokens": 522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568416, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6104202506119594}}
{"text": "\\section{Optimization}\n\n\\subsection{Motivation}\n\n\\begin{frame}\n  \\frametitle{Motivation}\n\n  \\begin{itemize}\n    \\item Optimization is crucial for many solutions in pattern recognition, \\\\\n      pattern analysis, machine learning, artificial intelligence, etc. \\\\[.25cm]\n    \\item Optimization has many faces: \n      \\begin{itemize}\n        \\item discrete optimization,\n        \\item combinatorial optimization,\n        \\item genetic algorithms,\n        \\item gradient descent,\n        \\item unconstrained and constrained optimization,\n        \\item linear programming,\n        \\item convex optimization, etc. \\\\[.25cm]\n      \\end{itemize}\n    \\item There is no lecture on pattern recognition without a \\\\\n      refresher course on optimization techniques. \\\\[.25cm]\n    \\item Each researcher has his own favorite optimization algorithm.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Unconstrained Optimization}\n\n\\begin{frame}\n  \\frametitle{Convexity}\n\n  \\begin{citeblock}{Definition}\n\n    A function $f: \\real^d \\rightarrow \\real$ is \\structure{\\emph{convex}} if the domain $\\mathsf{dom}(f)$ of $f$ is a convex set \\\\\n    and if $\\forall \\vec x, \\vec y \\in \\mathsf{dom}(f)$, and $\\theta$ with $0 \\leq \\theta \\leq 1$, we have\n\n    \\begin{displaymath}\n      f(\\theta \\vec x + (1-\\theta) \\vec y) \\leq \\theta f(\\vec x) + (1-\\theta) f(\\vec y)\n    \\end{displaymath}\n    \\pause\n\n    A function $f: \\real^d \\rightarrow \\real$ is \\structure{\\emph{concave}} if $-f$ is convex.\n\n  \\end{citeblock}\n  \\pause\n  \\vspace{0.5cm}\n\n  \\structure{Geometric interpretation:} \\\\[.25cm]\n\n  The line segment between $(\\vec x, f(\\vec x))$ and $(\\vec y, f(\\vec y))$ lies above the graph of $f$.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unconstrained Optimization}\n \n  Let us assume in the following that we have to compute the minimum \\\\\n  of a convex function\n\n  \\begin{displaymath}\n    f: \\real^d \\rightarrow \\real\n  \\end{displaymath}\n\n  that is twice differentiable. \\\\[.25cm] \\pause\n\n  The unconstrained optimization problem is just the solution of the\\\\\n  minimization problem\n\n  \\begin{displaymath}\n    \\vec x^* = \\argmin_{\\vec x} f(\\vec x)\n  \\end{displaymath}\n\n  where $\\vec x^*$ denotes the optimal point.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unconstrained Optimization \\cont}\n  \n  For this particular family of functions, a necessary and sufficient condition \\\\\n  for the  minumum are the zero-crossings of the function's gradient:\n  \n  \\begin{displaymath}\n    \\nabla f(\\vec x^*) = \\vec 0.\n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Unconstrained Optimization \\cont}\n\n  Most methods follow an \\structure{iterative scheme}:\n\n  \\begin{eqnarray*}\n    \\mbox{initialization} & & \\vec x ^{(0)}\\\\\n    \\mbox{iteration step} & & \\vec x^{(k+1)}= g(\\vec x^{(k)}) \n  \\end{eqnarray*}\n\n  where $g: \\real^d\\rightarrow \\real^d$ is the update function. \\\\[0.5cm] \\pause\n\n  The iterations \\structure{terminate}, if \n  \n  \\begin{displaymath}\n    \\|\\vec x^{(k+1)} - \\vec x^{(k)}\\| < \\epsilon,\n  \\end{displaymath}\n  \n  i.\\,e.\\ no further significant change.\n\\end{frame}\n\n\n\\subsection{Descent Methods}\n\n\\begin{frame}\n\n  \\frametitle{Descent Methods}\n\n  We now consider iteration schemes that produce a sequence of estimates \\\\\n  according to the update function\n%  \n  \\begin{displaymath}\n    \\vec x^{(k+1)} = g(\\vec x^{(k)}) = \\vec x^{(k)} + t^{(k)}\\Delta \\vec x^{(k)} .\n  \\end{displaymath}\n%  \n  where \n%  \n  \\begin{eqnarray*}\n    \\Delta \\vec x^{(k)}\\in \\real ^d: & & \\quad \\mbox{is the \\structure{search direction} in the $k$-th iteration}\\\\\n    t^{(k)}\\in \\real:                & & \\quad \\mbox{denotes the \\structure{step length} in the $k$-th iteration}\n  \\end{eqnarray*}\n  \\pause\n%  \n  and where we expect \n%  \n  \\begin{displaymath}\n    f( \\vec x^{(k+1)} ) < f(\\vec x^{(k)}) ~, \\quad \\mbox{i.\\,e.}~~ \\nabla f(\\vec x^{(k)})^T \\Delta \\vec x^{(k)} < 0\n  \\end{displaymath}\n%  \n  except ~~$ \\vec x^{(k+1)}=\\vec x^{(k)}=\\vec x^*$.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Taylor Approximation}\n \n  For many problems it is always good to know the \\structure{second order Taylor approximation}:\n\n  \\begin{displaymath}\n    f(\\vec x + t\\cdot \\Delta\\vec x) \n    \\approx f(\\vec x) + t\\cdot \\nabla f(\\vec x)^T \\Delta \\vec x +\n      \\frac{1}{2} t^2\\cdot\\Delta \\vec x^T \\nabla^2 f(\\vec x)\\Delta \\vec x\n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Descent Methods \\cont}\n  \n  \\begin{algorithmic}\n    \\STATE \\structure{Input:} function $f$, initial estimate $\\vec x^{(0)}$\n    \\STATE Initialize: $k:=0$\n    \\REPEAT\n      \\STATE Select (or compute) descent direction \n      \\STATE Line search (1-D optimization): $$t^{(k)}= \\argmin_{t \\geq 0}f(\\vec x^{(k)}+t\\cdot \\Delta\\vec x^{(k)})$$\n      \\STATE Update:\n        \\begin{displaymath}\n          \\vec x^{(k+1)} = \\vec x^{(k)} + t^{(k)}\\Delta \\vec x^{(k)} .\n        \\end{displaymath}\n      \\STATE $k:=k+1$\n    \\UNTIL{$\\|\\vec x^{(k)} - \\vec x^{(k-1)}\\| < \\epsilon$}\n    \\STATE \\structure{Output:} $\\vec x^{(k)}$\n  \\end{algorithmic}\n\\end{frame}\n\n\n\\subsection{Backtracking Line Search}\n\n\\begin{frame}\n  \\frametitle{Line Search Methods}\n\n  \\begin{itemize}  \n    \\item Multivariate optimization in its described form requires a \\\\\n      proper line search method.\\\\[.25cm]\n    \\item Exact line search along the straight line $\\{\\vec x + t\\Delta \\vec x ~|~ t \\geq 0\\}$ has to solve\n      \\begin{displaymath}\n        t^* = \\argmin_{t\\geq 0} f(\\vec  x + t\\Delta \\vec x)\n      \\end{displaymath}\n      and is rarely used. \\\\[.25cm]\n    \\item An overview of methods can be found in numerical recipes.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Line Search Methods \\cont}\n  \n  \\structure{Setting $t = 0.25$:}\n  \n  \\begin{center}\n    \\resizebox{.7\\linewidth}{!}{\n        \\input{\\texfigdir/stepsize_example3.pstex_t}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Line Search Methods \\cont}\n  \n  \\structure{Setting $t=1.9$:}\n  \n  \\begin{center}\n    \\resizebox{.7\\linewidth}{!}{\n      \\alt<24->{\n        \\input{\\texfigdir/stepsize_example1_24.pstex_t}\n      }{\\alt<23>{\n        \\input{\\texfigdir/stepsize_example1_23.pstex_t}\n      }{\\alt<22>{\n        \\input{\\texfigdir/stepsize_example1_22.pstex_t}\n      }{\\alt<21>{\n        \\input{\\texfigdir/stepsize_example1_21.pstex_t}\n      }{\\alt<20>{\n        \\input{\\texfigdir/stepsize_example1_20.pstex_t}\n      }{\\alt<19>{\n        \\input{\\texfigdir/stepsize_example1_19.pstex_t}\n      }{\\alt<18>{\n        \\input{\\texfigdir/stepsize_example1_18.pstex_t}\n      }{\\alt<17>{\n        \\input{\\texfigdir/stepsize_example1_17.pstex_t}\n      }{\\alt<16>{\n        \\input{\\texfigdir/stepsize_example1_16.pstex_t}\n      }{\\alt<15>{\n        \\input{\\texfigdir/stepsize_example1_15.pstex_t}\n      }{\\alt<14>{\n        \\input{\\texfigdir/stepsize_example1_14.pstex_t}\n      }{\\alt<13>{\n        \\input{\\texfigdir/stepsize_example1_13.pstex_t}\n      }{\\alt<12>{\n        \\input{\\texfigdir/stepsize_example1_12.pstex_t}\n      }{\\alt<11>{\n        \\input{\\texfigdir/stepsize_example1_11.pstex_t}\n      }{\\alt<10>{\n        \\input{\\texfigdir/stepsize_example1_10.pstex_t}\n      }{\\alt<9>{\n        \\input{\\texfigdir/stepsize_example1_09.pstex_t}\n      }{\\alt<8>{\n        \\input{\\texfigdir/stepsize_example1_08.pstex_t}\n      }{\\alt<7>{\n        \\input{\\texfigdir/stepsize_example1_07.pstex_t}\n      }{\\alt<6>{\n        \\input{\\texfigdir/stepsize_example1_06.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/stepsize_example1_05.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/stepsize_example1_04.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/stepsize_example1_03.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/stepsize_example1_02.pstex_t}\n      }{\n        \\input{\\texfigdir/stepsize_example1_01.pstex_t}\n      }}}}}}}}}}}}}}}}}}}}}}}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Line Search Methods \\cont}\n  \n  \\structure{Setting $t^{(k+1)}= \\frac{1}{2} t^{(k)}$ and starting with $t^{(0)} = 0.5$:}\n  \n  \\begin{center}\n    \\resizebox{.7\\linewidth}{!}{\n        \\input{\\texfigdir/stepsize_example2.pstex_t}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Backtracking Line Search}\n\n  \\begin{center}\n    \\resizebox{.7\\linewidth}{!}{\n      \\alt<6->{\n        \\input{\\texfigdir/armijo6.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/armijo5.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/armijo4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/armijo3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/armijo2.pstex_t}\n      }{\n        \\input{\\texfigdir/armijo1.pstex_t}\n      }}}}}\n    }\n  \\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Backtracking Line Search \\cont}\n\n  The Armijo-Goldstein line search algorithm: \\\\[0.5cm]\n\n  \\begin{algorithmic}\n    \\STATE \\structure{Input:} function $f$, search direction $\\Delta\\vec x$\n    \\STATE Initialize: $t:=1$\n    \\STATE Select: $\\alpha\\in [0,0.5]$ and $\\beta\\in [0,1]$.\n    \\WHILE{$f(\\vec x + t\\Delta \\vec x) > f(\\vec x) +  \\alpha t \\cdot \\nabla f(\\vec x)^T\\Delta\\vec x$}\n      \\STATE $t := \\beta t$\n    \\ENDWHILE\n    \\STATE \\structure{Output:} $t$\n  \\end{algorithmic}\n\\end{frame}\n\n\n\\subsection{Gradient Descent Methods}\n\n\\begin{frame}\n  \\frametitle{Gradient Descent Methods}\n\n  A natural choice of the search direction is the \\structure{negative gradient}:\n  \n  \\begin{displaymath}\n    \\Delta \\vec x^{(k)} = -\\nabla f(\\vec x^{(k)})\n  \\end{displaymath}\n  \\vspace{1cm}\n\n  \\structure{Rule of thumb:}\\\\[.15cm]\n  \n  The negative gradient is the steepest descent direction.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Gradient Descent Methods \\cont}\n\n  \\begin{algorithmic}\n    \\STATE \\structure{Input:} function $f$, initial estimate $\\vec x^{(0)}$\n    \\STATE intialize: $k:=0$\n    \\REPEAT\n      \\STATE Set descent direction: $\\Delta\\vec x^{(k)}=- \\nabla f(\\vec x^{(k)}) $\n      \\STATE Line search (1-D optimization): $$t^{(k)}= \\argmin_{t \\geq 0}f(\\vec x^{(k)}+t\\cdot \\Delta\\vec x^{(k)})$$\n      \\STATE Update:\n        \\begin{displaymath}\n          \\vec x^{(k+1)} = \\vec x^{(k)} + t^{(k)}\\Delta \\vec x^{(k)} .\n        \\end{displaymath}\n      \\STATE $k:= k+1$\n    \\UNTIL{$\\|\\vec x^{(k)} - \\vec x^{(k-1)}\\|_2 < \\epsilon$}\n    \\STATE \\structure{Output:} $\\vec x^{(k)}$\n  \\end{algorithmic}\n\\end{frame}\n\n\\input{nextTime.tex}\n\n\\subsection{Steepest Descent Methods}\n\n\\subsubsection{Algorithm}\n\n\\begin{frame}\n  \\frametitle{Steepest Descent Methods}\n\n  \\structure{(Normalized) steepest descent, what does it mean?} \\\\[.25cm]\n\n  We search for the unit vector that shows the largest decrease \\\\\n  in the linear approximation of $f$:\n  \n  \\begin{displaymath}\n    \\Delta \\vec x = \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ; \\ \\| \\vec u\\|_p = 1\\}\n  \\end{displaymath}   \n  \\pause         \n   \n  \\structure{Conclusions:} \n\n  \\begin{itemize}\n    \\item The steepest descent direction depends on the chosen norm.\n    \\item The negative gradient is not necessarily the best choice for the \\\\\n      search direction.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Steepest Descent Methods \\cont}\n\n  We consider now the first order Taylor approximation of $f(\\vec x +\\vec u)$ \\\\\n  around the selected position $\\vec x$:\n  \n  \\begin{displaymath}\n    f(\\vec x+\\vec u) \\approx f(\\vec x) + \\nabla f(\\vec x)^T \\vec u.\n  \\end{displaymath}\n  \\pause\n  \n  \\begin{itemize}\n    \\item Here $ \\nabla f(\\vec x)^T \\vec u$ is the directional derivative at $\\vec x$ in direction $\\vec u$.\n    \\item The vector $\\vec u$ denotes a descent direction if the inner product \\\\\n      with the gradient vetor is negative, i.\\,e.\n      \\begin{displaymath}\n        \\nabla f(\\vec x)^T \\vec u < 0~.\n      \\end{displaymath}\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Steepest Descent Methods \\cont}\n\n  \\vspace*{-.25cm}\n  \\begin{algorithmic}\n    \\STATE \\structure{Input:} function $f$, initial estimate $\\vec x^{(0)}$, norm $\\|.\\|$\n    \\STATE intialize: $k:=0$\n    \\REPEAT\n      \\STATE Compute highest descent direction: $$ \\Delta \\vec x ^{(k)}= \\argmin_{\\vec u} \\{\\nabla f(\\vec x^{(k)})^T \\vec u ; \\ \\| \\vec u\\| = 1\\}$$    \n      \\STATE Line search (1-D optimization): $$t^{(k)}= \\argmin_{t \\geq 0}f(\\vec x^{(k)}+t\\cdot \\Delta\\vec x^{(k)})$$\n      \\STATE Update:\n        \\begin{displaymath}\n          \\vec x^{(k+1)} = \\vec x^{(k)} + t^{(k)}\\Delta \\vec x^{(k)} .\n        \\end{displaymath}\n      \\STATE $k:=k+1$\n    \\UNTIL{$\\|\\vec x^{(k)} - \\vec x^{(k-1)}\\| < \\epsilon$}\n    \\STATE \\structure{Output:} $\\vec x^{(k)}$\n  \\end{algorithmic}\n\\end{frame}\n\n\n\\subsubsection{$L_2$-norm}\n\n\\begin{frame}\n  \\frametitle{$L_2$-Norm}\n\n  The unit ball for the $L_2$-norm:\n\n  \\begin{figure}\n    \\resizebox{.3\\linewidth}{!}{\n      \\alt<4->{\n        \\input{\\texfigdir/unit_ball_gradient_L2_3.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/unit_ball_gradient_L2_2.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/unit_ball_gradient_L2_1.pstex_t}\n      }{\n        \\input{\\texfigdir/unit_ball_gradient_L2_0.pstex_t}\n      }}}\n    }\n  \\end{figure}\n \n  For the $L_2$-norm the steepest descent direction is the negative gradient:\n  \n  \\begin{displaymath}\n    \\Delta \\vec x \n    = \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ; \\ \\| \\vec u\\|_2 = 1\\}\n    = -\\nabla f(\\vec x)\n  \\end{displaymath}\n\\end{frame}\n\n\n\\subsubsection{$L_1$-norm}\n\n\\begin{frame}\n \\frametitle{$L_1$-Norm}\n \n  The unit ball for the $L_1$-norm: \\\\[.25cm]\n  \n  \\begin{columns}\n  \n    \\column{.5\\linewidth}\n      \\centering\n      \\resizebox{.9\\linewidth}{!}{\n        \\alt<4->{\n          \\input{\\texfigdir/unit_ball_gradient_L1_3.pstex_t}\n        }{\\alt<3>{\n          \\input{\\texfigdir/unit_ball_gradient_L1_2.pstex_t}\n        }{\\alt<2>{\n          \\input{\\texfigdir/unit_ball_gradient_L1_1.pstex_t}\n        }{\n          \\input{\\texfigdir/unit_ball_gradient_L1_0.pstex_t}\n        }}}\n      }\n    \n      \\column{.5\\linewidth}\n        \\centering\n        \\onslide<5->\n        \\resizebox{.9\\linewidth}{!}{\n          \\input{\\texfigdir/unit_ball_gradient_L1_4.pstex_t}\n        }\n  \\end{columns}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{$L_1$-Norm \\cont}\n\n  \\begin{itemize}\n    \\item The steepest descent for the $L_1$-norm selects in each iteration \\\\\n      the component of $\\nabla f(\\vec x)$ with maximum absolute value and then \\\\\n      decreases or increases dependent on the sign of the selected component. \\pause\n    \\item Let $i$ be the index of the gradient component with maximum absolute \\\\\n      value, and let $\\vec e_i\\in\\real^d$ denote the corresponding base vector.\\\\\n      The steepest descent direction is given by:\n      \\begin{eqnarray*}\n        \\Delta \\vec x &=& \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ; \\ \\| \\vec u\\|_1 = 1\\} \\\\\n                      &=& -\\mbox{sgn}\\left(\\frac{\\partial}{\\partial x_i} f(\\vec x)\\right)\\vec e_i\n      \\end{eqnarray*}\n      \\pause\n    \\item \\structure{Note:} Steepest descent using the $L_1$-norm results in the {\\em coordinate descent algorithm}.\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsubsection{$L_\\infty$-norm}\n\n\\begin{frame}\n  \\frametitle{$L_\\infty$-Norm}\n\n  The unit ball for the $L_\\infty$-norm: \\\\[.25cm]\n\n  \\begin{columns}\n  \n    \\column{.5\\linewidth}\n      \\centering\n      \\resizebox{.9\\linewidth}{!}{\n        \\alt<2->{\n          \\input{\\texfigdir/unit_ball_gradient_Linfinity_2.pstex_t}\n        }{\n          \\input{\\texfigdir/unit_ball_gradient_Linfinity_1.pstex_t}\n        }\n      }\n    \n      \\column{.5\\linewidth}\n        \\centering\n        \\onslide<3->\n        \\resizebox{.9\\linewidth}{!}{\n          \\input{\\texfigdir/unit_ball_gradient_Linfinity_3.pstex_t}\n        }\n  \\end{columns}\n\\end{frame}\n\n\n\\subsubsection{Quadratic $L_{\\mat P}$-norm}\n\n\\begin{frame}\n  \\frametitle{$L_{\\mat P}$-Norm}\n  \n  The unit ball for the $L_{\\mat P}$-norm:\n\n  \\begin{figure}\n    \\resizebox{.45\\linewidth}{!}{\n      \\alt<3>{\n        \\input{\\texfigdir/unit_ball_gradient_LP_3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/unit_ball_gradient_LP_2.pstex_t}\n      }{\n        \\input{\\texfigdir/unit_ball_gradient_LP_1.pstex_t}\n      }}\n    }\n  \\end{figure}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{$L_{\\mat P}$-Norm \\cont}\n  \n  The \\structure{steepest descent} for the $L_{\\mat P}$-norm is given by:\n%  \n  \\begin{eqnarray*}\n    \\Delta \\vec x \n      &=& \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ; \\ \\| \\vec u\\|_{\\mat P} = 1\\} \\\\ \\pause\n      &=& \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ;\\  (\\vec u^T{\\mat P}\\vec u)^{\\frac{1}{2}} = 1\\} \\\\ \\pause\n      &=& \\argmin_{\\vec u} \\{\\nabla f(\\vec x)^T \\vec u ;\\ \\| {\\mat P}^{\\frac{1}{2}} \\vec u\\|_2 = 1\\}\n  \\end{eqnarray*}\n  \\pause\n%  \n  As we did in the LDA-transform, we introduce a transform to get \\\\\n  \\structure{spherical data}:\n%\n  \\begin{displaymath}\n    \\vec u' = {\\mat P}^{\\frac{1}{2}} \\vec u\n  \\end{displaymath}\n  \\pause\n%\n  and thus\n%  \n  \\begin{displaymath}\n    f(\\vec u) = f({\\mat P}^{-\\frac{1}{2}}\\vec u') = f'(\\vec u')\n  \\end{displaymath}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{$L_{\\mat P}$-Norm \\cont}\n  \n  Instead of $f(\\vec x)$ we now minimize $f'(\\vec x')$ using the $L_2$-norm and \\\\\n  back-transform the result:\n  \n  \\begin{eqnarray*}\n    \\Delta \\vec x' \n      &=& \\argmin_{\\vec u} \\{\\nabla f'(\\vec x')^T \\vec u' ; \\ \\| \\vec u'\\|_{2} = 1\\} \\\\[.15cm] \\pause\n      &=& -\\nabla f'(\\vec x') \\\\[.15cm] \\pause\n      &=& -\\mat P^{-\\frac{1}{2}}\\nabla f({\\mat P}^{-\\frac{1}{2}}\\vec x') \\\\[.15cm] \\pause\n      &=& - {\\mat P}^{-\\frac{1}{2}}\\nabla f(\\vec x)\n  \\end{eqnarray*}\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{$L_{\\mat P}$-Norm \\cont}\n \n  Now we get for $\\Delta \\vec x$:\n\n  \\begin{eqnarray*}\n    \\Delta \\vec x \n      &=& {\\mat P}^{-\\frac{1}{2}} \\Delta \\vec x' \\\\[.15cm] \\pause\n      &=& {\\mat P}^{-\\frac{1}{2}} \\left( - {\\mat P}^{-\\frac{1}{2}}\\nabla f(\\vec x) \\right) \\\\[.15cm] \\pause\n      &=& - \\mat{P}^{-1} \\nabla f(\\vec x).\n  \\end{eqnarray*}\n  \\pause\n   \n  \\structure{Conclusion:} The steepest descent for the $L_{\\mat P}$-norm is given by\n  \n  \\begin{displaymath}\n     \\Delta \\vec x = -\\mat{P}^{-1} \\nabla f(\\vec x)~.\n  \\end{displaymath}\n\\end{frame}\n\n\n\\subsection{Newton's Method}\n\n\\begin{frame}\n  \\frametitle{Newton's Method}\n\n  \\structure{The idea:}\n  \n  \\begin{itemize}\n    \\item Select a point.\n    \\item Compute the minimum of the second order Taylor approximation.\n  \\end{itemize}\n  \n  \\begin{center}\n    \\resizebox{.7\\linewidth}{!}{\n      \\alt<8->{\n        \\input{\\texfigdir/newton-raphson8.pstex_t}\n      }{\\alt<7>{\n        \\input{\\texfigdir/newton-raphson7.pstex_t}\n      }{\\alt<6>{\n        \\input{\\texfigdir/newton-raphson6.pstex_t}\n      }{\\alt<5>{\n        \\input{\\texfigdir/newton-raphson5.pstex_t}\n      }{\\alt<4>{\n        \\input{\\texfigdir/newton-raphson4.pstex_t}\n      }{\\alt<3>{\n        \\input{\\texfigdir/newton-raphson3.pstex_t}\n      }{\\alt<2>{\n        \\input{\\texfigdir/newton-raphson2.pstex_t}\n      }{\n        \\input{\\texfigdir/newton-raphson1.pstex_t}\n      }}}}}}}\n    }\n  \\end{center}  \n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Newton's Method \\cont}\n \n  Second order Taylor approximation:\n  \\begin{displaymath}\n    f(\\vec x+\\Delta \\vec x) \n    \\approx f(\\vec x) + \\nabla f(\\vec x)^T \\Delta \\vec x + \\frac{1}{2} \\Delta \\vec x^T (\\nabla^2 f(\\vec x))\\Delta \\vec x \n  \\end{displaymath}\n  \\pause\n\n  Now we select $\\Delta \\vec x$ such that \n  \\begin{displaymath}\n    \\nabla\\{  f(\\vec x) + \\nabla f(\\vec x)^T \\Delta \\vec x + \\frac{1}{2}\\Delta \\vec x^T (\\nabla^2 f(\\vec x))\\Delta \\vec x\\} \n    = 0\n  \\end{displaymath}\n  \\pause\n\n  Obviously the gradient is\n  \\begin{displaymath}\n    \\nabla f(\\vec x)+ \\nabla^2 f(\\vec x)\\Delta \\vec x \n    = 0\n  \\end{displaymath}\n  \\pause\n\n  and thus\n  \\begin{displaymath}\n    \\Delta \\vec x \n    = -(\\nabla^2 f(\\vec x))^{-1} \\nabla f(\\vec x)\n  \\end{displaymath} \n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Newton's Method \\cont}\n\n  \\structure{Conclusion:} \\\\[.25cm]\n \n  Newton's method is an $\\vec x$-dependent steepest descent method regarding \\\\\n  the $L_{\\mat P}$-norm, where $\\mat P = \\nabla^2 f(\\vec x)$ is the Hessian.\n\\end{frame}\n\n\n\\begin{frame}\n  \\frametitle{Damped Newton's Method}\n  \n  \\begin{algorithmic}\n    \\STATE \\structure{Input:} function $f$, initial estimate $\\vec x^{(0)}$\n    \\STATE intialize: $k:=0$\n    \\REPEAT\n      \\STATE Compute Newton step:     $$ \\Delta \\vec x^{(k)}= -\\nabla^2 f(\\vec x^{(k)})^{-1} \\nabla f(\\vec x^{(k)}) $$\n      \\STATE Line search (1-D optimization): $$t^{(k)}= \\argmin_{t \\geq 0}f(\\vec x^{(k)}+t\\cdot \\Delta\\vec x^{(k)})$$\n      \\STATE Update:\n        \\begin{displaymath}\n          \\vec x^{(k+1)} = \\vec x^{(k)} + t^{(k)}\\Delta \\vec x^{(k)} .\n        \\end{displaymath}\n    \\STATE $k:=k+1$\n   \\UNTIL{$\\|\\vec x^{(k)} - \\vec x^{(k-1)}\\| < \\epsilon$}\n   \\STATE \\structure{Output:} $\\vec x^{(k)}$\n \\end{algorithmic}\n\\end{frame}\n\n\n\\subsection{Lessons Learned}\n\n\\begin{frame}\n  \\frametitle{Lessons Learned}\n\n  \\begin{itemize}\n    \\item Gradient descent is widely applied. \\\\[.25cm]\n    \\item Gradient descent and coordinate descent are special cases of steepest descent methods. \\\\[.25cm]\n    \\item Steepest descent method depends on the chosen norm.\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  This chapter is basically copied from: \\\\[.25cm]\n \n  \\begin{itemize}\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/}} \\\\[.25cm]\n    \\item Jorge Nocedal, Stephen Wright: \\\\\n      \\structure{Numerical Optimization}, \\\\\n      Springer, New York, 1999.\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 general formulation for an unconstrained optimization problem? \\\\[.5cm]\n    \\item Why do we need a line search in gradient descent approaches? \\\\[.5cm]\n    \\item What is the Armijo-Goldstein line search algorithm? \\\\[.5cm]\n    \\item What are the steepest descent directions if we apply the $L_\\infty$, $L_1$, $L_2$, and $L_{\\mat P}$ norm?\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "80654f236b96bb0b9a1f5f9951cf149a768bce2d", "size": 21903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11_optimization.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": "11_optimization.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": "11_optimization.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.3350582147, "max_line_length": 151, "alphanum_fraction": 0.6085011186, "num_tokens": 7590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952052, "lm_q2_score": 0.8688267677469952, "lm_q1q2_score": 0.6103769190117871}}
{"text": "\\section*{Exercise 2.1}\r\n\\enum{\r\n\\item\r\nSince $\\text{ran} X\\subset\\mathbb{N}$, then\r\n\\spl{\r\nE[X]=\\sum_{x=0}^{\\infty}xP[X=x]=\\sum_{x=0}^{\\infty}\\sum_{y=1}^{x}P[X=x].\r\n}\r\nWe change the order of summation,\r\n\\spl{\r\n    E[X]=\\sum_{x=0}^{\\infty}\\sum_{y=1}^{x}P[X=x]=\\sum_{x=0}^{\\infty}\\sum_{y=x+1}^{\\infty}P[X=y]=\\sum_{x=0}^{\\infty}P[X>x].\r\n}\r\n\r\n\\item \r\nAccording to the result we obtain in 1), we perform the similar calculation to $(X,f_X)$ where $X=1,2,\\hdots,N-r+1$.\r\n\\spl{\r\n    E[X]=\\sum_{x=0}^{N-r}P[X>x].\r\n}\r\nIn fact, $P[X>x]$ is equal to the probability that the first $x$ balls are all black.\r\n\r\n\\spl{\r\n    P[X>x]&=P[\\text{The first x balls are all black}]\\\\\r\n    &=\\frac{N-r}{N}\\frac{N-r-1}{N-1}\\hdots\\frac{N-r-x+1}{N-x+1}\\\\\r\n    &=\\frac{(N-r)!/(N-r-x)!}{N!/(N-x)!}=\\frac{\\binom{N-x}{r}}{\\binom{N}{r}}\\\\\r\n    E[X]&=\\frac{1}{\\binom{N}{r}}\\sum_{x=0}^{r'}\\binom{N-x}{N-r'}=\\frac{1}{\\binom{N}{r}}\\sum_{x=0}^{r'}\\binom{N-r'+x}{N-r'}\\\\\r\n    &=\\frac{\\binom{N+1}{N-r'+1}}{\\binom{N}{r}}=\\frac{\\binom{N+1}{r+1}}{\\binom{N}{r}}=\\frac{N+1}{r+1}.\r\n}\r\n}\r\n\r\n\\section*{Exercise 2.2}\r\nFor $p_0(t)$, when $t=0$ the probability of 0 failure is 1. For $p_x(t)\\quad (x\\geq1)$, when $t=0$ the probability of x failure is 0.\r\nHence, the initial conditions are as the follows.\r\n\\spl{\r\n    p_0(0)&=1\\\\\r\n    p_{x}(0)&=0,\\quad x\\geq1.\r\n}\r\n\r\nSince $p_0'=-\\lambda p_0$, then $p_0(t)=c\\cdot e^{-\\lambda t}$.\r\nAlso we know that $p_0(0)=1$, thus c=1.\r\nHence, $p_0(t)=e^{-\\lambda t}$.\r\n\r\nAssume that $p_x(t)=(\\lambda t)^xe^{-\\lambda t}/x!$ for all $x\\in\\mathbb{N}$.\r\n\r\nFor $x=0$, $p_0(t)=e^{-lambda t}=(\\lambda t)^0e^{-\\lambda t}/0!$, which follows our assumption.\r\n\r\nFor $x=n\\geq0$, we assume the statement is true. When $x=n+1$,\r\n\r\n\\spl{\r\n    &p_{n+1}'+\\lambda p_{n+1}=\\lambda p_n,\\\\\r\n    &(e^{\\lambda t}p_x)'=\\lambda e^{\\lambda t}p_n,\\\\\r\n    &p_{n+1}=\\frac{\\int\\lambda e^{\\lambda t}p_n dt}{e^{\\lambda t}}.\r\n}\r\n\\spl{\r\n    p_{n+1}&=\\frac{\\lambda e^{\\lambda t}p_n dt}{e^{\\lambda t}}=\\frac{\\int\\lambda e^{\\lambda t}(\\lambda t)^ne^{-\\lambda t}/n! dt}{e^{\\lambda t}}\\\\\r\n    &=\\frac{\\lambda^{n+1}/n! \\int t^n dt}{e^{\\lambda t}}=\\lambda^{n+1}/n!/(n+1)(t^{n+1}+C)e^{-\\lambda t}\\\\\r\n    &=(\\frac{(\\lambda t)^{n+1}+(\\lambda)^{n+1}C}{(n+1)!})e^{-\\lambda t}.\r\n}\r\n\r\nTo satisfy that $p_{n+1}(0)=0$, $C$ has to be 0. Thus,\r\n\\spl{\r\n    p_{n+1}(t)=\\frac{(\\lambda t)^{n+1}}{(n+1)!}e^{-\\lambda t}.\r\n}\r\n\r\nTherefore, $p_x(t)=(\\lambda t)^xe^{-\\lambda t}/x!$ for all $x\\in\\mathbb{N}$.\r\n\r\n\\section*{Exercise 2.3}\r\n\\spl{\r\n    f(x)=\\binom{n}{x}p^x(1-p)^{n-x}=\\binom{n}{x}(\\frac{k}{n})^x(1-\\frac{k}{n})^{n-x}=k^x\\frac{\\binom{n}{x}}{n^x}((1-\\frac{1}{n/k})^{n/k})^k(1-\\frac{k}{n})^{-x}\r\n}\r\n\r\nSince\r\n\\spl{\r\n    &\\lim_{n\\to\\infty}\\frac{\\binom{n}{x}}{n^x}=\\lim_{n\\to\\infty}\\frac{n!}{x!(n-x)!n^x}=\\frac{1}{x!},\\\\\r\n    &\\lim_{n\\to\\infty}((1-\\frac{1}{n/k})^{-n/k})^{-k}=e^{-k},\\\\\r\n    &\\lim_{n\\to\\infty}(1-\\frac{k}{n})^{-x}=1.\r\n}\r\n\r\nthen\r\n\\spl{\r\n    \\lim_{n\\to\\infty}f(x)=\\frac{k^x}{x!}e^{-k}.\r\n}\r\n\r\n\\section*{Exercise 2.4}\r\n\\enum{\r\n\\item\r\n\\spl{\r\n    E[V]&=\\int_{0}^{\\infty}(\\frac{2}{\\pi})^{1/2}(m/kT)^{3/2}v^3e^{-\\frac{m}{kT}v^2/2}dv\\\\\r\n    &=(\\frac{2}{\\pi})^{1/2}(m/kT)^{3/2}\\int_{0}^{\\infty}v^3e^{-\\frac{m}{kT}v^2/2}dv\\quad(w=v^2)\\\\\r\n    &=(\\frac{2}{\\pi})^{1/2}(m/kT)^{3/2}\\int_{0}^{\\infty}w^{3/2}e^{-\\frac{m}{kT}w/2}\\frac{1}{2}w^{-1/2}dw\\\\\r\n    &=(\\frac{1}{2\\pi})^{1/2}(m/kT)^{3/2}\\int_{0}^{\\infty}we^{-\\frac{m}{kT}w/2}dw\\\\\r\n    &=(\\frac{m}{2kT\\pi})^{1/2}\\int_{0}^{\\infty}\\frac{m}{kT}we^{-\\frac{m}{kT}w/2}dw\\quad(z=-\\frac{m}{kT}w/2)\\\\\r\n}\r\n\r\n\\spl{\r\n    E[V]=(\\frac{8kT}{m\\pi})^{1/2}\\int_{-\\infty}^{0}ze^zdz=(\\frac{8kT}{m\\pi})^{1/2}.\r\n}\r\n\r\nSince $Var[V]=E[V^2]-E[V]^2$, then\r\n\\spl{\r\n    E[V^2]&=(\\frac{2}{\\pi})^{1/2}(m/kT)^{3/2}\\int_{0}^{\\infty}v^4e^{-\\frac{m}{kT}v^2/2}dv\\\\\r\n    &=-(\\frac{2m}{k\\pi T})^{1/2}\\int_{1}^{0}v^3de^{-\\frac{m}{kT}v^2/2}\\\\\r\n    &=-(\\frac{2m}{k\\pi T})^{1/2}(v^3e^{-\\frac{m}{kT}v^2/2}\\bigg|_0^\\infty-\\int_0^\\infty 3v^2e^{-\\frac{m}{kT}v^2/2}dv)\\\\\r\n    &=3(\\frac{2m}{k\\pi T})^{1/2}\\int_0^\\infty v^2e^{-\\frac{m}{kT}v^2/2}dv\\\\\r\n    &=3(\\frac{2kT}{m\\pi})^{1/2}\\int_0^\\infty e^{-\\frac{m}{kT}v^2/2}dv\\\\\r\n    &=\\frac{3kT}{m}.\r\n}\r\n\r\n\\spl{\r\n    Var[V]=E[V^2]-E[V]^2=\\frac{3kT}{m}-\\frac{8kT}{m\\pi}=\\frac{kT}{m}(3-\\frac{8}{\\pi}).\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    E[E]=E[mV^2/2]=mE[V^2]/2=\\frac{3kT}{2}.\r\n}\r\n\r\n\\item\r\nSince\r\n\\spl{\r\n    E&=\\varphi(v)=\\frac{mv^2}{2},\\\\\r\n    V&=\\varphi^{-1}(\\varepsilon)=(\\frac{2\\varepsilon}{m})^{1/2},\r\n}\r\nthen\r\n\\spl{\r\n    f_E(\\varepsilon)&=f_V(\\varphi^{-1}(\\varepsilon))\\bigg|\\frac{d\\varphi^{-1}(\\varepsilon)}{d\\varepsilon}\\bigg|=(\\frac{1}{2m\\varepsilon})^{1/2}(\\frac{2}{\\pi})^{1/2}(\\frac{m}{kT})^{3/2}\\frac{2\\varepsilon}{m}e^{-\\frac{\\varepsilon}{kT}}\\\\\r\n    &=2(\\frac{\\varepsilon}{\\pi k^3T^3})^{1/2}e^{-\\frac{\\varepsilon}{kT}}. \r\n}\r\n\r\n}\r\n\r\n\\section*{Exercise 2.5}\r\n\\spl{\r\n    \\Gamma(\\frac{2n+1}{2})&=\\int_0^\\infty t^{(2n-1)/2}e^{-t}dt=(t^{(2n-1)/2}e^{-t})\\bigg|_0^\\infty+\\frac{2n-1}{2}\\int_0^\\infty t^{(2n-3)/2}e^{-t}dt\\\\\r\n    &=(\\frac{2n-1}{2})\\Gamma(\\frac{2n-1}{2}).\r\n}\r\n\r\nHence,\r\n\\spl{\r\n    \\Gamma(\\frac{2n+1}{2})=\\frac{(2n-1)(2n-3)\\hdots(1)}{2\\cdot2\\hdots2}\\Gamma(\\frac{1}{2})=\\frac{(2n-1)!!}{2^n}\\Gamma(\\frac{1}{2}).\r\n}\r\n\r\nAlso we obtain\r\n\\spl{\r\n    \\Gamma(\\frac{1}{2})&=\\int_0^\\infty t^{-1/2}e^{-t}dt\\quad(t=w^2)\\\\\r\n    &=\\int_0^\\infty w^{-1}e^{-w^2}2wdw=2\\int_0^\\infty e^{-w^2}dw=\\sqrt{\\pi}\r\n}\r\n\r\nTherefore,\r\n\\spl{\r\n    \\Gamma(\\frac{2n+1}{2})=\\frac{(2n-1)!!}{2^n}\\sqrt{\\pi}.\r\n}\r\n\r\n\\section*{Exercise 2.6}\r\n\\enum{\r\n\\item\r\nDenote that\r\n\\spl{\r\n    Z=\\frac{X-\\mu}{\\sigma}=\\frac{X-6000}{100}\r\n}\r\nso that $Z\\sim N(0,1)$.\r\nThen,\r\n\\spl{\r\n    &P[\\text{A sample strength is less than 6250 kg/cm$^2$}]\\\\\r\n    &=P[X<6250]=P[Z<2.50]=\\Phi(2.50)=0.9938.\r\n}\r\n\r\n\\item\r\n\\spl{\r\n    P[5800\\leq X\\leq 5900]&=P[-2.00\\leq Z\\leq -1.00]\\\\\r\n    &=\\Phi(-1.00)-\\Phi(-2.00)\\\\\r\n    &=0.1587-0.0228\\\\\r\n    &=0.1359.\r\n}\r\n\r\n\\item\r\nAccording to the standard normal distribution table, we know that\r\n\\spl{\r\n    \\Phi(-1.64)=0.0505,\\quad \\Phi(-1.65)=0.0495.\r\n}\r\n\r\nWhen $Z=-1.65$, $X=-1.65\\times100+6000=5835$kg/cm$^2$.\r\n\r\nHence, the strength of 5835 kg/cm$^2$ exceeds 5\\% samples, saying that is exceeded by 95\\% samples.\r\n}\r\n\r\n\\section*{Exercise 2.7}\r\n\\enum{\r\n\\item\r\nThe random variable is a map $X:\\ S\\to \\mathbb{R}$ together with a function $f_X:\\ \\mathbb{R}\\to\\mathbb{R}$. Then, the two properties of a continuous random variable will be showed.\r\n\r\nFor $a<x<b$ where $b>a$, $f(x)=1/(b-a)>0$.\r\nFor other conditions, $f(x)=0>=0$.\r\nHence, $f(x)\\geq0$.\r\n\r\nAlso,\r\n\\spl{\r\n    \\int_{-\\infty}^{\\infty}f(x)dx=\\int_{a}^{b}1/(b-a)dx=(b-a)/(b-a)=1.\r\n}\r\n\r\nHence, this is a density for a continuous random variable.\r\n\r\n\\item\r\nThe graph is as the following.\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=5.5cm]{images/a}\r\n    \\caption{Graph for Exercise 2.7 (2)}\r\n\\end{figure}\r\n\r\n\\item\r\n\\spl{\r\n    P[X<=(a+b)/2]=\\int_{-\\infty}^{(a+b)/2}f(x)dx=\\int_{a}^{(a+b)/2}1/(b-a)dx=(b-a)/2/(b-a)=\\frac{1}{2}.\r\n}\r\n\r\n\\item\r\nSince [c,d] and [e,f] are the subintervals of [a,b], then\r\n\\spl{\r\n    P[c\\leq X\\leq d]&=\\int_{c}^{d}1/(b-a)dx=(d-c)/(b-a).\\\\\r\n    P[e\\leq X\\leq f]&=\\int_{e}^{f}1/(b-a)dx=(f-e)/(b-a).\r\n}\r\n\r\nSince $d-c=f-e$, then $P[c\\leq X\\leq d]=P[e\\leq X\\leq f]$.\r\n\r\n\\item\r\n\\[\r\n    F(x)=\\int_{-\\infty}^{x}f(t)dt=\r\n    \\left\\{\\begin{aligned}\r\n        &0,\\quad x<a\\\\\r\n        &\\frac{x-a}{b-a},\\quad a\\leq x \\leq b\\\\\r\n        &1,\\quad x>b\\\\\r\n    \\end{aligned}\\right.\r\n\\]\r\n\r\n\\item\r\n\\spl{\r\n    E[X]&=\\int_{-\\infty}^{\\infty}xf(x)dx=\\int_{a}^{b}\\frac{x}{b-a}dx\\\\\r\n    &=\\frac{x^2}{2(b-a)}\\bigg|_a^b=\\frac{b^2-a^2}{2(b-a)}=\\frac{a+b}{2}.\r\n}\r\n\\spl{\r\n    E[X^2]&=\\int_{-\\infty}^{\\infty}x^2f(x)dx=\\int_{a}^{b}\\frac{x^2}{b-a}dx\\\\\r\n    &=\\frac{x^3}{3(b-a)}\\bigg|_a^b=\\frac{b^3-a^3}{3(b-a)}=\\frac{a^2+ab+b^2}{3}. \r\n}\r\nHence,\r\n\\spl{\r\n    Var[X]&=E[X^2]-E[X]^2=\\frac{a^2+ab+b^2}{3}-(\\frac{a+b}{2})^2\\\\\r\n    &=\\frac{(b-a)^2}{12}.\r\n}\r\n}", "meta": {"hexsha": "eb9b7f8415c3d8f46db4b6fc2f92a59a92a0844d", "size": 7763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment2/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/Assignment2/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/Assignment2/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": 31.4291497976, "max_line_length": 236, "alphanum_fraction": 0.5201597321, "num_tokens": 3771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346598, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6103769165408857}}
{"text": "%!TEX root = ./writeup.tex\n\n\\newcommand{\\bl}{B_{L,i}(x)}\n\\newcommand{\\br}{B_{R,i}(x)}\n\\newcommand{\\jil}{J_{i,L}}\n\\newcommand{\\jir}{J_{i,R}}\n\\newcommand{\\eddphi}[1]{\\edd_{#1}\\phi_{#1}}\n\\newcommand{\\alphai}[2]{\\frac{#1}{\\Sigma_{t,#2}h_{#2}}}\n\n\\section{Mixed Hybrid Finite Element Method Acceleration}\n\nThe \\gls{mhfem} as applied to Eqs. \\ref{eq:zero} and \\ref{eq:first} uses the following basis functions:\n\t\\begin{subequations}\n\t\\begin{equation} \\label{mhfem:BL}\n\t\t\\bl = \\begin{cases}\n\t\t\t\\frac{x_{i+1/2} - x}{x_{i+1/2} - x_{i-1/2}}, \\ x \\in [x_{i-1/2}, x_{i+1/2}] \\\\ \n\t\t\t0, \\ \\text{otherwise}\n\t\t\\end{cases}\n\t\\end{equation}\n\t\\begin{equation} \\label{mhfem:BR}\n\t\t\\br = \\begin{cases}\n\t\t\t\\frac{x - x_{i-1/2}}{x_{i+1/2} - x_{i-1/2}}, \\ x \\in [x_{i-1/2}, x_{i+1/2}] \\\\ \n\t\t\t0, \\ \\text{otherwise}\n\t\t\\end{cases}. \n\t\\end{equation}\n\t\\end{subequations}\nThe scalar flux is constant within a cell with discontinuous jumps at the cell edges. In other words, \n\t\\begin{equation} \\label{mhfem:flux}\n\t\t\\phi_i(x) = \\begin{cases}\n\t\t\t\\phi_i, \\ x \\in (x_{i-1/2}, x_{i+1/2}) \\\\ \n\t\t\t\\phi_{i\\pm 1/2}, x = x_{i\\pm1/2} \\\\ \n\t\t\t0, \\ \\text{otherwise}\n\t\t\\end{cases} \n\t\\end{equation}\nwith \n\t\\begin{equation} \\label{mhfem:sumphi}\n\t\t\\phi(x) = \\sum_{i=1}^I \\phi_i(x). \n\t\\end{equation}\nThe Eddington factor will be interpolated onto the same grid as the scalar flux so that cell edge and cell center values will be available.  \n\nThe current, $J(x)$, is a piecewise linear function defined by \n\t\\begin{equation} \\label{mhfem:J}\n\t\tJ(x) = \\sum_{i=1}^I \\jil \\bl + \\jir \\br\n\t\\end{equation} \nwhere $\\jil$ and $\\jir$ are the current on the left and right edges of the cell. \n\n\\subsection{Interior}\nOn the interior cells, $i \\in [2, I-1]$, each cell has five unknowns: $\\phi_{i-1/2}$, $\\phi_i$, $\\phi_{i+1/2}$, $\\jil$, and $\\jir$. Since $\\phi_{i+1/2} = \\phi_{(i+1)-1/2}$, only $\\phi_{i}$, $\\phi_{i+1/2}$, $\\jil$, and $\\jir$ must be specified in each cell as the left edge of the cell is specified by the right edge of the previous cell. Thus four equations are needed for each interior cell. \n\nThe first is found by integrating Eq. \\ref{eq:zero} over cell $i$ yielding the balance equation\n\t\\begin{equation} \\label{mhfem:balance}\n\t\t\\jir - \\jil + \\Sigma_{a,i} \\phi_i h_i = Q_i h_i. \n\t\\end{equation}\nEquations for the cell edge current, $\\jil$ and $\\jir$, are found by multiplying Eq. \\ref{eq:first} by $\\bl$ and $\\br$ and integrating over cell $i$. This yields \n\t\\begin{subequations}\n\t\\begin{equation}\n\t\t\\int_{x_{i-1/2}}^{x_{i+1/2}} \\bl \\dderiv{}{x} \\edd(x) \\phi(x) + \\bl \\Sigma_t(x) J(x) \\ud x = 0\n\t\\end{equation}\n\t\\begin{equation}\n\t\t\\int_{x_{i-1/2}}^{x_{i+1/2}} \\br \\dderiv{}{x} \\edd(x) \\phi(x) + \\br \\Sigma_t(x) J(x) \\ud x = 0\n\t\\end{equation}\n\t\\end{subequations}\nIntegrating by parts produces \n\t\\begin{subequations}\n\t\\begin{equation} \\label{mhfem:half1}\n\t\t-\\edd_{i-1/2}\\phi_{i-1/2} + \\edd_i \\phi_i + \\Sigma_{t,i} h_i \\left(\\frac{\\jil}{3}\n\t\t\t+ \\frac{\\jir}{6} \\right) = 0\n\t\\end{equation}\n\t\\begin{equation} \\label{mhfem:half2}\n\t\t\\edd_{i+1/2}\\phi_{i+1/2} - \\edd_i \\phi_i + \\Sigma_{t,i}h_i \\left(\\frac{\\jil}{6} + \\frac{\\jir}{3}\\right) = 0.\n\t\\end{equation}\n\t\\end{subequations}\nEliminating $\\jil$ from Eq. \\ref{mhfem:half1} and $\\jir$ from Eq. \\ref{mhfem:half2}:\n\t\\begin{equation} \\label{mhfem:jir_f}\n\t\t\\jir = \\frac{-2}{\\Sigma_{t,i}h_i} \\left[ \\eddphi{i-1/2} - 3\\eddphi{i} + 2\\eddphi{i+1/2} \\right]\n\t\\end{equation}\n\t\\begin{equation} \\label{mhfem:jil_f}\n\t\t\\jil = \\frac{-2}{\\Sigma_{t,i} h_i} \\left[ -2 \\eddphi{i-1/2} + 3\\eddphi{i} - \\eddphi{i+1/2}\\right]\n\t\\end{equation}\n\nThe equation for $\\phi_{i+1/2}$ is found by enforcing continuity of current such that the current on the right side of cell $i$ is equivalent to the current on the left side of cell $i+1$. In other words,  \n\t\\begin{equation}\n\t\t\\jir = J_{i+1,L}\n\t\\end{equation}\nApplying this condition to Eqs. \\ref{mhfem:jir_f} and \\ref{mhfem:jil_f}:\n\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\t\\alphai{-2}{i} \\eddphi{i-1/2} &+ \\alphai{6}{i} \\eddphi{i} - 4 \\left(\n\t\t\t\\frac{1}{\\Sigma_{t,i}h_i} + \\frac{1}{\\Sigma_{t,i+1}h_{i+1}}\\right)\\eddphi{i+1/2} \\\\\n\t\t&+ \\alphai{6}{i+1}\\eddphi{i+1} - \\alphai{2}{i+1}\\eddphi{i+3/2} = 0. \n\t\t\\end{aligned}\n\t\\end{equation}\n\nThe required four equations can be reduced to two by replacing $\\jir$ and $\\jil$ in Eq. \\ref{mhfem:balance} with Eqs. \\ref{mhfem:jir_f} and \\ref{mhfem:jil_f}. This produces the system of equations for every interior cell $i \\in [2, I-1]$: \n\t\\begin{subequations} \\label{mhfem:intsys}\n\t\t\\begin{equation} \\label{mhfem:intsys1}\n\t\t\t\\phi_i = \\frac{\n\t\t\t\t\\alphai{6}{i}\\eddphi{i-1/2} + \\alphai{6}{i}\\eddphi{i+1/2} + Q_i h_i\n\t\t\t}{\n\t\t\t\t\\Sigma_{a,i}h_i + \\alphai{12}{i}\\edd_i\n\t\t\t}\n\t\t\\end{equation}\n\t\t\\begin{equation} \\label{mhfem:intsys2}\n\t\t\t\\phi_{i+1/2} = \\frac{\n\t\t\t\t\\alphai{-2}{i} \\eddphi{i-1/2} + \\alphai{6}{i} \\eddphi{i} + \\alphai{6}{i+1}\\eddphi{i+1} - \\alphai{2}{i+1}\\eddphi{i+3/2}\n\t\t\t}{4\\left(\n\t\t\t\t\\frac{1}{\\Sigma_{t,i}h_i} + \\frac{1}{\\Sigma_{t,i+1}h_{i+1}}\\right) \\edd_{i+1/2}\n\t\t\t}\n\t\t\\end{equation}\n\t\\end{subequations}\n\n\\subsection{Boundary}\nEquation \\ref{mhfem:intsys} provides $2(I-2)$ equations for the $2I+1$ unknowns. Thus, five boundary equations are required. The values not accounted for in Eq. \\ref{mhfem:intsys} are $\\phi_{1/2}$, $\\phi_{1}$, $\\phi_{3/2}$, $\\phi_{I}$, and $\\phi_{I+1/2}$. \n\nThe Marshak boundary condition is \n\t\\begin{equation}\n\t\t\\phi(x) + 2J(x) = 0. \n\t\\end{equation}\nAt $x = x_{1/2}$:\n\t\\begin{equation}\n\t\t\\phi_{1/2} + 2J_{1,L} = 0\n\t\\end{equation}\nUsing Eq. \\ref{mhfem:jil_f} evaluated at $i=1$, \n\t\\begin{equation}\n\t\t\\phi_{1/2} = \\frac{\n\t\t\t\\frac{6}{\\Sigma_{t,i}h_i} \\eddphi{1} - \\frac{2}{\\Sigma_{t,i}h_i}\\eddphi{3/2}\n\t\t}{\n\t\t\t\\frac{1}{2} + \\frac{4}{\\Sigma_{t,i}h_i}\\edd_{1/2}\n\t\t}\n\t\\end{equation}\nApplying a reflecting boundary on the right edge $J(x_{I+1/2}) = J_{I,R} = 0$:\n\t\\begin{equation} \n\t\t\\phi_{I+1/2} = \\frac{\n\t\t\t-\\eddphi{I-1/2} + 3\\eddphi{I}\n\t\t}{\n\t\t\t2\\edd_{i+1/2}\n\t\t}\n\t\\end{equation}\n$\\phi_1$ and $\\phi_I$ are specified by Eq. \\ref{mhfem:intsys1} with $i=1$ and $i=I$. The remaining unknown, $\\phi_{3/2}$, is found through Eq. \\ref{mhfem:intsys2} with $i=1$. \nThere are now $2I+1$ equations with $2I+1$ unknowns. This system can be solved with the inversion of a banded matrix of bandwidth five. ", "meta": {"hexsha": "745081ee846559a99e40303fbcc1df3cd253ef9f", "size": 6172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/writeup/MHFEM.tex", "max_stars_repo_name": "smsolivier/rh", "max_stars_repo_head_hexsha": "a12da9464328b0fd1af0878a1f55aaf961f47e05", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-30T15:24:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-30T15:24:42.000Z", "max_issues_repo_path": "tex/writeup/MHFEM.tex", "max_issues_repo_name": "smsolivier/rh", "max_issues_repo_head_hexsha": "a12da9464328b0fd1af0878a1f55aaf961f47e05", "max_issues_repo_licenses": ["MIT"], "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/writeup/MHFEM.tex", "max_forks_repo_name": "smsolivier/rh", "max_forks_repo_head_hexsha": "a12da9464328b0fd1af0878a1f55aaf961f47e05", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-22T00:02:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T08:58:46.000Z", "avg_line_length": 44.0857142857, "max_line_length": 393, "alphanum_fraction": 0.6364225535, "num_tokens": 2666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6103769141547596}}
{"text": "\n\n\nThis chapter is an extended version of the recently published paper\n\\citep{MERLINI2019177} which collects results about\nRiordan arrays in the framework of \\textit{matrix functions};  actually,\nthe following methodology applies to any square matrix $m\\times m$ with\n\\textit{exactly one} eigenvalue $\\lambda$ of \\textit{algebraic}\nmultiplicity $m \\in\\mathbb{N}$.  Generalized Lagrange bases are used to\nconstruct Hermite polynomials that interpolate a family of functions;\nmoreover, we show a parallel application of such functions via Jordan\ncanonical forms and case studies are given.\n\n\n\\section{Introduction}\n\n\\label{sec:matrices:functions:introduction}\n\\input{Riordan-matrices-functions/introduction.tex}\n\n\\section{Basic definitions and notations}\n\n\\input{Riordan-matrices-functions/matrix-functions.tex}\n\nNow we apply this framework to the Riordan group.\n\n\\section{Riordan matrices}\n\n\\input{Riordan-matrices-functions/riordan-group.tex}\n\n\\iffalse % \\subsection{A Riordan array characterization of Hermite interpolating polynomials} {{{\n\n\\input{Riordan-matrices-functions/Ra-g-characterization.tex}\n\n\\subsection{A component matrices characterization of Hermite interpolating polynomials}\n\n\\input{Riordan-matrices-functions/Zs-g-characterization.tex}\n\\fi\n% }}}\n\n\\section{Functions and polynomials}\n\nIn this section we instantiate the abstract framework just described to functions\n\\begin{displaymath}\n\\begin{split}\nf(z)&=z^{r},\\,{f(z)=\\frac{1}{z}},\\,{f(z)=\\sqrt{z}},\\,{f(z)=e^{\\alpha z}},\\\\\nf(z)&=log\\,{z},\\,f(z)=sin\\,{z}\\quad\\text{and}\\quad f(z)=cos\\,{z},\n\\end{split}\n\\end{displaymath}\nwhere $r,\\alpha\\in\\mathbb{R}$; in parallel, we construct and show corresponding\nHermite interpolating polynomials in a sequence of theorems, respectively.\nFrom now on, we use $m$ and $\\lambda$ instead of $m_{1}$ and $\\lambda_{1}$ to\nsimplify the notation; moreover, we instantiate $\\lambda=1$ which is the\nnatural eigenvalue for Riordan arrays.\n\nWe start by generalizing the $r$-th power $A^{r}$, usually carried out\nas $\\underbrace{A\\cdots A}_{r\\text{ times}}$, to \\textit{rational} powers\n$r\\in\\mathbb{Q}$.\n\n\\input{Riordan-matrices-functions/function-pow.tex}\n\nInstantiation $r=-1$ in the previous theorem yields a Hermite interpolating\npolynomial for the inverse function which, in the explicit form, reduces to\na binomial transform.\n\n\\input{Riordan-matrices-functions/function-inverse.tex}\n\n\\vfill\n\nInstantiation $r=\\frac{1}{2}$ yields the interpolation of the square root function,\nwe report its derivation for completeness.\n\n\\input{Riordan-matrices-functions/function-sqrt.tex}\n\nMatrix exponentiation is a well studied problem \\citep{MOLERLOAN2003}, here\nwe show another way in the Riordan arrays domain.\n\n\\input{Riordan-matrices-functions/function-exp.tex}\n\nWe show a dual theorem of the previous one concerning the interpolation of the\nlogarithm function.\n\n\\vfill\n\n\\input{Riordan-matrices-functions/function-log.tex}\n\n\n\\begin{remark}\nFor the sake of completeness, a Hermite interpolating polynomial $g$ could\nalso be studied by relaxing the condition $\\lambda=1$ thus considering\n$\\hat{g}(z,\\lambda)$ which subsumes $g(z)=\\hat{g}(z,1)$. Here are one of these\naugmented polynomials interpolating the $log$ function\n\\iffalse\n\\begin{displaymath}\n\\begin{split}\n\\hat{I}_{8}{\\left (z, \\lambda \\right )} &= - \\frac{z^{7}}{\\lambda^{8}} \\\\\n&+ z^{6} \\left(\\frac{1}{\\lambda^{7}} + \\frac{7}{\\lambda^{8}}\\right) \\\\\n&+ z^{5} \\left(- \\frac{1}{\\lambda^{6}} - \\frac{6}{\\lambda^{7}} - \\frac{21}{\\lambda^{8}}\\right) \\\\\n&+ z^{4} \\left(\\frac{1}{\\lambda^{5}} + \\frac{5}{\\lambda^{6}} + \\frac{15}{\\lambda^{7}} + \\frac{35}{\\lambda^{8}}\\right) \\\\\n&+ z^{3} \\left(- \\frac{1}{\\lambda^{4}} - \\frac{4}{\\lambda^{5}} - \\frac{10}{\\lambda^{6}} - \\frac{20}{\\lambda^{7}} - \\frac{35}{\\lambda^{8}}\\right) \\\\\n&+ z^{2} \\left(\\frac{1}{\\lambda^{3}} + \\frac{3}{\\lambda^{4}} + \\frac{6}{\\lambda^{5}} + \\frac{10}{\\lambda^{6}} + \\frac{15}{\\lambda^{7}} + \\frac{21}{\\lambda^{8}}\\right) \\\\\n&+ z \\left(- \\frac{1}{\\lambda^{2}} - \\frac{2}{\\lambda^{3}} - \\frac{3}{\\lambda^{4}} - \\frac{4}{\\lambda^{5}} - \\frac{5}{\\lambda^{6}} - \\frac{6}{\\lambda^{7}} - \\frac{7}{\\lambda^{8}}\\right) \\\\\n&+ \\frac{1}{\\lambda} + \\frac{1}{\\lambda^{2}} + \\frac{1}{\\lambda^{3}} + \\frac{1}{\\lambda^{4}} + \\frac{1}{\\lambda^{5}} + \\frac{1}{\\lambda^{6}} + \\frac{1}{\\lambda^{7}} + \\frac{1}{\\lambda^{8}}\n\\end{split}\n\\end{displaymath}\nand\n\\fi\n\\begin{displaymath}\n\\begin{split}\n\\hat{L}_{8}{\\left (z,\\lambda \\right )} &= \\frac{z^{7}}{7 \\lambda^{7}} \\\\\n&+ z^{6} \\left(- \\frac{1}{6 \\lambda^{6}} - \\frac{1}{\\lambda^{7}}\\right) \\\\\n&+ z^{5} \\left(\\frac{1}{5 \\lambda^{5}} + \\frac{1}{\\lambda^{6}} + \\frac{3}{\\lambda^{7}}\\right) \\\\\n&+ z^{4} \\left(- \\frac{1}{4 \\lambda^{4}} - \\frac{1}{\\lambda^{5}} - \\frac{5}{2 \\lambda^{6}} - \\frac{5}{\\lambda^{7}}\\right) \\\\\n&+ z^{3} \\left(\\frac{1}{3 \\lambda^{3}} + \\frac{1}{\\lambda^{4}} + \\frac{2}{\\lambda^{5}} + \\frac{10}{3 \\lambda^{6}} + \\frac{5}{\\lambda^{7}}\\right) \\\\\n&+ z^{2} \\left(- \\frac{1}{2 \\lambda^{2}} - \\frac{1}{\\lambda^{3}} - \\frac{3}{2 \\lambda^{4}} - \\frac{2}{\\lambda^{5}} - \\frac{5}{2 \\lambda^{6}} - \\frac{3}{\\lambda^{7}}\\right) \\\\\n&+ z \\left(\\frac{1}{\\lambda} + \\frac{1}{\\lambda^{2}} + \\frac{1}{\\lambda^{3}} + \\frac{1}{\\lambda^{4}} + \\frac{1}{\\lambda^{5}} + \\frac{1}{\\lambda^{6}} + \\frac{1}{\\lambda^{7}}\\right) \\\\\n&+ log{\\left (\\lambda \\right )} - \\frac{1}{\\lambda} - \\frac{1}{2 \\lambda^{2}} - \\frac{1}{3 \\lambda^{3}} - \\frac{1}{4 \\lambda^{4}} - \\frac{1}{5 \\lambda^{5}} - \\frac{1}{6 \\lambda^{6}} - \\frac{1}{7 \\lambda^{7}}.\n\\end{split}\n\\end{displaymath}\n\\end{remark}\n\n%Finally, we show two theorem concerning trigonometric functions $sin$ and $cos$, respectively.\n\n\\input{Riordan-matrices-functions/function-sin.tex}\n\n\\input{Riordan-matrices-functions/function-cos.tex}\n\n\\subsection{Case studies}\n\n\n\\input{Riordan-matrices-functions/matricial-Hermite-polys.tex}\n\n\\vfill\n\n\\input{Riordan-matrices-functions/case-study-pascal.tex}\n\n\\input{Riordan-matrices-functions/case-study-catalan.tex}\n\n\\input{Riordan-matrices-functions/case-study-stirling-II.tex}\n\nFinally, we report sine and cosine function applications in Table\n\\ref{table:sin:cos:matrices:functions}; finally, Equation\n\\ref{eq:matrices:functions:sin:cos:identity} shows that the identity\n$sin^{2}\\,z + cos^{2}\\,z=1$ is preserved by the framework of matrices functions\nand even more trigonometric identities can be checked; for example, the\npolynomial\n\\begin{displaymath}\n\\begin{split}\n{SS_{ 8 }}{\\left (z \\right )} &= - \\frac{z^{7}}{5040} cos{\\left (2 \\right )} + z^{6} \\left(- \\frac{1}{720} sin{\\left (2 \\right )} + \\frac{1}{360} cos{\\left (2 \\right )}\\right) \\\\\n    &+ z^{5} \\left(- \\frac{1}{120} cos{\\left (2 \\right )} + \\frac{1}{60} sin{\\left (2 \\right )}\\right) + z^{4} \\left(- \\frac{1}{24} sin{\\left (2 \\right )} - \\frac{1}{36} cos{\\left (2 \\right )}\\right) \\\\\n    &+ z^{3} \\left(- \\frac{1}{9} sin{\\left (2 \\right )} + \\frac{1}{18} cos{\\left (2 \\right )}\\right)  + z^{2} \\left(\\frac{7}{15} cos{\\left (2 \\right )} + \\frac{1}{6} sin{\\left (2 \\right )}\\right) \\\\\n    &+ z \\left(- \\frac{19}{45} cos{\\left (2 \\right )} + \\frac{14}{15} sin{\\left (2 \\right )}\\right) - \\frac{19}{45} sin{\\left (2 \\right )} - \\frac{286}{315} cos{\\left (2 \\right )}\n\\end{split}\n\\end{displaymath}\ninterpolates the function $f(\\theta)=sin(2\\,\\theta)$\nwhich allows us to check the identity $sin(2\\,\\theta)=2\\,sin\\theta\\,cos\\theta$ \nfor a Riordan matrix $\\theta$, formally $SS(\\theta)~=~2\\,S(\\theta)\\,C(\\theta)$.\n\n% a comment about the correct definition of the Lagrange base. {{{\n\\iffalse\nIn the same spirit, many other functions and their relations with already\nstudied ones could be an interesting field of investigation -- we would recall\nthat before starting the lifting process of a scalar function, the user\nhas to pay attention to the correct definition of the generalized Lagrange base\nbecause it all depends on the eigenvalues of the matrix under study.\n\\fi\n% }}}\n\n\n\\begin{table}\n%\\vspace*{-1cm}\n    \\caption[][-1cm]{$sin{\\mathcal{P}_{8}}$,$cos{\\mathcal{P}_{8}}$,$sin{\\mathcal{C}_{8}}$,$cos{\\mathcal{C}_{8}}$,\n$sin{\\mathcal{S}_{8}}$ and $cos{\\mathcal{S}_{8}}$}\n\\input{Riordan-matrices-functions/sines-and-cosines.tex}\n\\label{table:sin:cos:matrices:functions}\n\\end{table}\n\n\n\\section{Jordan canonical form}\n\n\\input{Riordan-matrices-functions/jordan-form.tex}\n\\input{Riordan-matrices-functions/case-study-fibonacci.tex}\n\n\n\\section*{Conclusions}\n\n\\input{Riordan-matrices-functions/conclusions.tex}\n\n\\vfill\n\n\n\n\n\n\n", "meta": {"hexsha": "b89d849b4b619bdfd106aca5e18eeb20982f6b46", "size": 8399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Riordan-matrices-functions/content.tex", "max_stars_repo_name": "massimo-nocentini/PhD-thesis", "max_stars_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Riordan-matrices-functions/content.tex", "max_issues_repo_name": "massimo-nocentini/PhD-thesis", "max_issues_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Riordan-matrices-functions/content.tex", "max_forks_repo_name": "massimo-nocentini/PhD-thesis", "max_forks_repo_head_hexsha": "f30ec2cb9cdf1e93532935448c3438700b9fcbba", "max_forks_repo_licenses": ["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.0717948718, "max_line_length": 208, "alphanum_fraction": 0.6757947375, "num_tokens": 2849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6103184161102693}}
{"text": "\\newpage\n\n\\captionsetup{labelformat=empty}\n\n\\section*{\\texorpdfstring{Appendix D: VOI for conservation auctions\nheuristic solution \\emph{n} =\n3}{Appendix D: VOI for conservation auctions heuristic solution n = 3}}\\label{appendix-d-voi-for-conservation-auctions-heuristic-solution-n-3}\n\\addcontentsline{toc}{section}{Appendix D: VOI for conservation auctions\nheuristic solution \\emph{n} = 3}\n\n\\textbf{Priors}\n\nLet \\(A_1\\), \\(A_2\\), \\(A_3\\) be assets. Each has some value \\(c_1\\),\n\\(c_2\\), and \\(c_3\\) which are uncertain with a joint prior probability\ndistribution,\n\n\\begin{equation}\n\\begin{bmatrix}c_1 \\\\ c_2 \\\\ c_3\\end{bmatrix}\\sim\\mathcal{N}\\left(\\begin{bmatrix}\\mu_1 \\\\ \\mu_2 \\\\ \\mu_3\\end{bmatrix}, \\begin{bmatrix}\\sigma^2_1 & 0 & 0 \\\\ 0 & \\sigma^2_2 & 0\\\\ 0 & 0 & \\sigma^2_3 \\end{bmatrix}\\right)\n(\\#eq:jointprior)\n\\end{equation}\n\nwhere \\(\\mu_1\\), \\(\\mu_2\\), and \\(\\mu_3\\) are means and \\(\\sigma_1\\),\n\\(\\sigma_2\\) and \\(\\sigma_3\\) are the prior standard deviations.\n\n\\textbf{Utilities}\n\nWe assign utilities to each rank order of \\(c_1\\), \\(c_2\\), and \\(c_3\\)\nin combination with each action of purchasing one of \\(A\\), \\(B\\) or\n\\(C\\),\n\n\\begin{equation}\n\\begin{aligned}\nu(A_1, c_1 > c_2 > c_3)&=1\\\\\nu(A_1, c_1 > c_3 > c_2)&=1\\\\\nu(A_1, c_2 > c_1 > c_3)&=0.5\\\\\nu(A_1, c_3 > c_1 > c_2)&=0.5\\\\\nu(A_1, c_2 > c_3 > c_1)&=0\\\\\nu(A_1, c_3 > c_2 > c_1)&=0\\\\\nu(A_2, c_2 > c_1 > c_3)&=1\\\\\n\\mathrm{etc...}&\n\\end{aligned}\n(\\#eq:utilitiesapen2)\n\\end{equation}\n\nsuch that utility is maximised when we purchase the highest ranked\nasset, zero when we purchase the lowest ranked and somewhere inbetween\nwhen we purchase the middle ranked asset.\n\n\\textbf{Ranking probabilties}\n\nWe can express the probability of any assets being in a given rank order\nas the probabililty of two differences being less than zero. Such that,\nfor example,\n\n\\begin{equation}\n\\Pr(c_1 > c_2 > c_3) = \\Pr(c_2 - c_1 < 0,  c_3 - c_2 < 0)\n(\\#eq:probrankapen)\n\\end{equation}\n\nGiven this we define two new variables, \\(z_1\\) and \\(z_2\\) where\n\n\\begin{equation}\n\\begin{aligned}\n  z_1 &= c_2 - c_1,\\\\\n  z_2 &= c_3 - c_2\n\\end{aligned}\n(\\#eq:z12apen)\n\\end{equation}\n\nEven if \\(c_1\\), \\(c_2\\), and \\(c_3\\) are all uncorrelated \\(z_1\\) and\n\\(z_2\\) will not be, where\n\n\\begin{equation}\n\\mathrm{cov}(z_1, z_2)=\\mathrm{cov}(c_1, c_2) - \\mathrm{var}(c_2) - \\mathrm{cov}(c_1, c_3) + \\mathrm{cov}(c_2, c_3)\n(\\#eq:covz)\n\\end{equation}\n\nWhich, when \\(c_1\\), \\(c_2\\), and \\(c_3\\) are all uncorrelated\nsimplifies to\n\n\\begin{equation}\n\\mathrm{cov}(z_1, z_2)=-\\mathrm{var}(c_2)\n(\\#eq:covz2)\n\\end{equation}\n\nTherefore the joint distribution of \\(z_1\\) and \\(z_2\\) is,\n\n\\begin{equation}\n\\begin{bmatrix}z_1\\\\z_2\\end{bmatrix}\n  \\sim\\mathrm{N}\\left(\n  \\begin{bmatrix}\\mu_2-\\mu_1\\\\\\mu_3-\\mu_2\\end{bmatrix},\n  \\begin{bmatrix}\\sigma^2_1+\\sigma^2_2&-\\sigma^2_2\\\\-\\sigma^2_2&\\sigma^2_2+\\sigma^2_3\\end{bmatrix}\\right)\n(\\#eq:jointzapen)\n\\end{equation}\n\nTo obtain \\(\\Pr(c_1 > c_2 > c_3)\\) we evalute the multivariate\ncumulative distribution function of \\(z_1\\) and \\(z_2\\),\n\n\\begin{equation}\n\\Phi(z_1,z_2)\n(\\#eq:phiz)\n\\end{equation}\n\nwithin the limits, \\(-\\infty\\) and 0.\n\n\\textbf{Expected value of perfect information}\n\nTo calculate the prior expected utility of purchasing any asset, we\nweight the utilities for that action (eqn. 2) by the relevant\nprobablities calculated from eqns. 3--9. For instance;\n\n\\begin{equation}\n\\begin{aligned}\n  \\mathrm{E}[u(A_1)] = & 1 \\times \\Pr(c_1 > c_2 > c_3) + 1 \\times \\Pr(c_1 > c_3 > c_2)\\,+ \\\\\n  &0.5 \\times \\Pr(c_2 > c_1 > c_3) + 0.5 \\times \\Pr(c_3 > c_1 > c_2)\\,+ \\\\\n  &0 \\times \\Pr(c_2 > c_3 > c_1) + 0 \\times \\Pr(c_3 > c_2 > c_1)\n\\end{aligned}\n(\\#eq:EuA1apen)\n\\end{equation}\n\nThe expected value of perfect information then is,\n\n\\begin{equation}\n\\mathrm{EVPI}=1-\\max(\\mathrm{E}[u(A_1)],\\mathrm{E}[u(A_2)],\\mathrm{E}[u(A_3)])\n(\\#eq:evpiapen2)\n\\end{equation}\n\n\\textbf{Updating}\n\nNow suppose we can update the priors for \\(c_1\\), \\(c_2\\), and \\(c_3\\)\nby taking \\(M\\) samples from sampling distrubutions with, for\nsimplicity, some fixed variance of 1 and centered on \\(\\mu_1\\),\n\\(\\mu_2\\) and \\(\\mu_3\\) respectively. Further, we can define \\(p_1\\) and\n\\(p_2\\) as the proportion of the \\(M\\) samples allocated to sampling for\n\\(A_1\\) and \\(A_2\\) respectively with \\(1 - p_1 - p_2\\) being allocated\nto \\(A_3\\). We can then use these samples to update the priors for\n\\(c_1\\), \\(c_2\\), and \\(c_3\\) to obtain preposterior estimates,\n\\(c^\\prime_1\\), \\(c^\\prime_2\\), and \\(c^\\prime_3\\), where,\n\n\\begin{equation}\n\\begin{bmatrix}c^\\prime_1 \\\\ c^\\prime_2 \\\\ c^\\prime_3\\end{bmatrix}\\sim\\mathcal{N}\\left(\\begin{bmatrix}\\mu_1 \\\\ \\mu_2 \\\\ \\mu_3\\end{bmatrix}, \\begin{bmatrix}\\frac{\\sigma^2_1}{Mp_1\\sigma^2_1 + 1} & 0 & 0 \\\\ 0 & \\frac{\\sigma^2_2}{Mp_2\\sigma^2_2 + 1} & 0\\\\ 0 & 0 & \\frac{\\sigma^2_3}{M(1 - p_1 - p_2)\\sigma^2_3 + 1} \\end{bmatrix}\\right)\n(\\#eq:jointpost)\n\\end{equation}\n\n\\textbf{Expected value of sample information}\n\nFor any given new rank order, based on the updated preposterior\ndistributions, we can again calculate a probablity by defining new\nvariables (i.e., \\(z^\\prime_1\\) and \\(z^\\prime_2\\)) and evalute their\nmultivariate cumulative distribution as in eqns. 3--9. Therefore we can\nobtain the preposterior expected utilities for each purchase action by\nweighting the preposterior probablites by their respective utilities as\nin eqn. 10. Accordingly the expected vale of sample information is\n\n\\begin{equation}\n\\mathrm{EVSI}=\\max(\\mathrm{E}^\\prime[u(A_1)],\\mathrm{E}^\\prime[u(A_2)],\\mathrm{E}^\\prime[u(A_3)])-\\max(\\mathrm{E}[u(A_1)],\\mathrm{E}[u(A_2)],\\mathrm{E}[u(A_3)])\n(\\#eq:evsiapen2)\n\\end{equation}\n\n\\textbf{Optimisation}\n\nUsing eqns 8-13 we can find the optimal values of \\(p_1\\) and \\(p_2\\)\nfor any given \\(M\\) that will maximise the EVSI. Below we examine a\nnumber of \\_\\_Case studies for different sets of prior distrbutions for\n\\(c_1\\), \\(c_2\\) and \\(c_3\\).\n\n\\textbf{Summary}\n\n\\begin{itemize}\n\\tightlist\n\\item\n  Optimal allocation sensitive to ratios of \\(\\mu\\)'s.\n\\item\n  Optimal allocation sensitive to ratio of \\(\\sigma\\)'s.\n\\item\n  Not always preferential to sample asset with greater uncertainty.\n\\item\n  Solution is symmetrical.\n\\end{itemize}\n\n\\textbf{Case study 1: homogenous prior \\(\\sigma\\)'s and homogenous prior\nmeans}\n\n\\includegraphics{figure/x000_1_1_1-1.png} \\clearpage\n\n\\textbf{Case study 2a: homogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\includegraphics{figure/x110_1_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 2b: homogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\includegraphics{figure/x100_1_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 2c: homogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\includegraphics{figure/x10n1_1_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3a: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_2 = \\sigma_3\\)\n\n\\includegraphics{figure/x100___1_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3b: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_2 = \\sigma_3\\)\n\n\\includegraphics{figure/x1001_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3c: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x110__1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3d: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_2 > \\sigma_3\\)\n\n\\includegraphics{figure/x100__1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3e: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x100_1_1__1c-1.png} \\clearpage\n\n\\textbf{Case study 3f: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_3 > \\sigma_2\\)\n\n\\includegraphics{figure/x110__1_1__1c-1.png} \\clearpage\n\n\\textbf{Case study 3g: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_3 < \\sigma_2\\)\n\n\\includegraphics{figure/x110_1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3h: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x100_1__1___1c-1.png} \\clearpage  \n\n\\textbf{Case study 3i: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_2 < \\sigma_1 < \\sigma_3\\)\n\n\\includegraphics{figure/x100__1_1___1c-1.png} \\clearpage\n\n\\textbf{Case study 3j: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 = \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_2 > \\sigma_3\\)\n\n\\includegraphics{figure/x100___1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3k: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x110_1__1___1c-1.png} \\clearpage\n\n\\textbf{Case study 3l: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_3 < \\sigma_2\\)\n\n\\includegraphics{figure/x110_1___1__1c-1.png} \\clearpage  \n\n\\textbf{Case study 3m: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 = \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_2 > \\sigma_3\\)\n\n\\includegraphics{figure/x110___1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3n: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_2 = \\sigma_3\\)\n\n\\includegraphics{figure/x10n1_1__1__1c-1.png} \\clearpage\n\n\\textbf{Case study 3o: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x10n1__1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3p: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_3 > \\sigma_2\\)\n\n\\includegraphics{figure/x10n1__1_1__1c-1.png} \\clearpage  \n\n\\textbf{Case study 3q: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x10n1_1_1__1c-1.png} \\clearpage\n\n\\textbf{Case study 3r: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_2 = \\sigma_3\\)\n\n\\includegraphics{figure/x10n1__1_1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3s: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 = \\sigma_3 < \\sigma_2\\)\n\n\\includegraphics{figure/x10n1_1__1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3t: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_2 < \\sigma_3\\)\n\n\\includegraphics{figure/x10n1_1__1___1c-1.png} \\clearpage  \n\n\\textbf{Case study 3u: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_2 < \\sigma_1 < \\sigma_3\\)\n\n\\includegraphics{figure/x10n1__1_1___1c-1.png} \\clearpage\n\n\\textbf{Case study 3v: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 < \\sigma_3 < \\sigma_2\\)\n\n\\includegraphics{figure/x10n1_1___1__1c-1.png} \\clearpage\n\n\\textbf{Case study 3w: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_3 > \\sigma_2\\)\n\n\\includegraphics{figure/x10n1__1___1_1c-1.png} \\clearpage\n\n\\textbf{Case study 3x: heterogenous prior \\(\\sigma\\)'s and heterogenous\nprior means}\n\n\\(\\mu_1 > \\mu_2 > \\mu_3\\)\n\n\\(\\sigma_1 > \\sigma_2 > \\sigma_3\\)\n\n\\includegraphics{figure/x10n1___1__1_1c-1.png} \\clearpage\n\n\\captionsetup{labelformat=default}\n", "meta": {"hexsha": "2abaa8a809ea0d6b728b9388d61ad9cb586bd051", "size": 11760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix2.tex", "max_stars_repo_name": "wkmor1/voiConsAuc", "max_stars_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "wkmor1/voiConsAuc", "max_issues_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "wkmor1/voiConsAuc", "max_forks_repo_head_hexsha": "71b466f70188c7faa85de6a1a677700be1a72295", "max_forks_repo_licenses": ["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.7358490566, "max_line_length": 330, "alphanum_fraction": 0.6968537415, "num_tokens": 4582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6103184079101059}}
{"text": "\\section{Lower-degree Artifacts in Feistel Networks}\n\\SecLabel{impmono}\n\nIn previous section it was shown that the HDIM is a very convenient tool for attacking affine encodings. Affine encodings have rather low entropy and thus provably absent monomials of degree $2n-1$ in a Feistel Network provide enough equations to recover the encodings. However, much more equations are needed to recover a Feistel function. A straightforward direction is to consider lower-degree monomials as well, possibly at the cost of attacking fewer rounds. This has an extra benefit of finding more efficient integral distinguishers, since the data complexity of an integral distinguisher is exponential in the degree of the corresponding absent monomial in the ANF. In this section I use the generalization of the HDIM-ANF relation described in \\SecRef{gen-hdim-anf} in order to prove absence of lower degree monomials in Feistel networks. The method is quite similar to the method used for proving type-I distinguishers in \\SecRef{hdim-feistel}. The main idea is to replace the sum variable in the expression to an intermediate state and thus split the structure in two halves.\n\nThe monomials in the ANF of Feistel Networks can be classified by the degree on the left input branch and on the right input branch. Clearly, all monomials in the same class have equivalent possibility of appearing in the ANF, since such monomials can be interchanged by composing Feistel functions with bit permutations.\n\n\\begin{definition}[($(w_l,w_r)$-monomials]\nLet $u_l,u_r \\in \\field{n}$ and let $u \\eqdef (u_l, u_r) \\in \\field{2n}$.\nThe monomial $x^u$ is said to be a $(w_l,w_r)$-monomial if $\\wt(u_l) = w_l$ and $\\wt(u_r) = w_r$. $u$ is then said to be a $(w_l,w_r)$-exponent.\n\\end{definition}\n\n\\begin{theorem}\n\\Label{thm:low-nbij}\nLet $S \\in \\nbij{r}{d}$ and let $f = \\inprod{e_i, S}, n < i \\le 2n,$ be any coordinate of the right output branch of $S$.\nLet $u$ be a $(w_l,w_r)$-exponent. Then $\\coef{u}{f} = 0$ if there exists an integer $r', 0 \\le r' < r$ such that\n$$\n(n - w_l)\\cdot\\maxdegnbij{r'+1}{d} + (n - w_r)\\cdot\\maxdegnbij{r'}{d} + \\maxdegnbij{r-r'}{d} < 2n.\n$$\n\nSimilar result applies for $S \\in \\bij{r}{d}$ by using $\\maxdegbij{r}{d}$.\n\\end{theorem}\n\\begin{proof}\nLet $(a, b) \\in \\field{2n}$ denote the intermediate state of $S$ after $r'$ rounds. Let $(x_l,x_r) \\in \\field{2n}$ be the two input branches of $S$ as functions of $(a,b)$; $(y_l,y_r) \\in \\field{2n}$ be the two output branches of $S$ as functions of $(a,b)$. By Proposition~\\Ref{prop:anf-alternative},\n$$\n\\coef{u}{f} = \\bigoplus_{z \\in \\field{2n}}\n    (\\lnot x_l)^{\\lnot u_l} \n    (\\lnot x_r)^{\\lnot u_r} \n    \\inprod{e_i, y_r},\n$$\nwhere $u_l,u_r \\in \\field{n}$ are the two halves of $u$.\n$(x_l,x_r)$ can be computed using an $r'$-round Feistel Network and $(y_l,y_r)$ can be computed using an $(r-r')$-round Feistel Network. Further note that $\\wt(\\lnot u_l) = n - \\wt(u_l)$ and $\\wt(\\lnot u_r) = n - \\wt(u_r)$. The degree bounds follow:\n\\begin{itemize}\n    \\item $\\deg{(\\lnot x_l)^{\\lnot u_l} } \\le (n - w_l)\\maxdegbij{r'+1}{d}$,\n    \\item $\\deg{(\\lnot x_r)^{\\lnot u_r} } \\le (n - w_r)\\maxdegbij{r'}{d}$,\n    \\item $\\deg{y_r} \\le \\maxdegbij{r - r'}{d}$.\n\\end{itemize}\nThe theorem follows by summing the degree bounds and comparing to the full degree $2n$.\n\\end{proof}\n\nA trick for bijective Feistel functions can be applied similarly to Theorem~\\Ref{thm:bij}.\n\n\\begin{theorem}\n\\Label{thm:low-bij}\nLet $S \\in \\bij{r}{d}$ and let $f = \\inprod{e_i, S}, n < i \\le 2n$ be any coordinate of the right output branch of $S$.\nLet $u$ be a $(w_l,w_r)$-exponent. Then $\\coef{u}{f} = 0$ if there exists an integer $r', 0 \\le r' < r - 3$ such that\n$$\n\\max(d,\\dinv) \\cdot \\proundd{\n    (n - w_l)\\cdot\\maxdegbij{r'}{d} +\n    (n - w_r)\\cdot\\maxdegbij{r'-1}{d} +\n    \\maxdegbij{r-r'-2}{d}\n} < 2n.\n$$\n\\end{theorem}\n\\begin{proof}\nThe variables chosen are $(a,c)$ instead of $(a,b)$ (see \\FigRef{mitmproof}), where $(a,b)$ denotes the intermediate state of $S$ after $r'$ rounds, and $c = f_{r'+1}(b) \\oplus a$. In this case $b$ can be expressed as $f_{r'+1}^{-1}(a \\oplus c)$, and the degree of $b$ as a function of $(a,c)$ is upper bounded by $\\dinv$.\n\nLet $x_l,x_r$ be the two input branches of $S$ as functions of $(a,c)$; $y_l,y_r$ be the two output branches of $S$ as functions of $(a,c)$.\nSimilarly to previous proofs, the following bounds are derived:\n\\begin{itemize}\n    \\item $\\deg{x_l} \\le \\max(d,\\dinv)\\cdot \\maxdegbij{r'}{d}$,\n    \\item $\\deg{x_r} \\le \\max(d,\\dinv)\\cdot \\maxdegbij{r'-1}{d}$,\n    \\item $\\deg{y_l} \\le \\max(d,\\dinv)\\cdot \\maxdegbij{r-r'-1}{d}$, \n    \\item $\\deg{y_r} \\le \\max(d,\\dinv)\\cdot \\maxdegbij{r-r'-2}{d}$.\n\\end{itemize}\nFor Proposition~\\Ref{prop:anf-alternative}, the following bounds are needed:\n\\begin{itemize}\n    \\item $\\deg{(\\lnot x_l)^{\\lnot u_l} } \\le (n - w_l)\\maxdegbij{r'}{d}$,\n    \\item $\\deg{(\\lnot x_r)^{\\lnot u_r} } \\le (n - w_r)\\maxdegbij{r'-1}{d}$,\n    \\item $\\deg{y_r} \\le \\maxdegbij{r - r' - 2}{d}$.\n\\end{itemize}\nThe theorem follows by summing the degree bounds.\n\\end{proof}\n\n\\begin{corollary}\nLet $S \\in \\bij{4}{n-1}$ and let $f = \\inprod{e_i, S}, n < i \\le 2n$ be any coordinate of the right output branch of $S$. Then the following monomials classes are absent in the ANF of $f$ (in total $2^n+n^2+n$ monomials):\n{\n\\enumroman{}\n\\begin{enumerate}\n    \\item $(n-1,n-1)$,\n    \\item $(n-1,n)$,\n    \\item $(n,k)$ for any $0 \\le k \\le n$.\n\\end{enumerate}\n}\n\\end{corollary}\n\\begin{proof}\nSet $r' = 0$ in Theorem~\\Ref{thm:low-bij}. Note that in this extreme case the term $\\dinv \\cdot (n - w_r)\\cdot\\maxdegbij{r'}{d}$ for $r'=0$ can be replaced by $(n - w_r)$, since the right input branch clearly has degree 1 on the chosen variables. For case $(i)$ the condition becomes\n$$ 1 + (n-1) \\pround{\n1\\cdot\\maxdegbij{1}{n-1} +\n\\maxdegbij{1}{n-1}\n} \\le 2n-1 < 2n.$$\nFor case $(ii)$ the condition becomes\n$$ 0 + (n-1) \\pround{\n1\\cdot\\maxdegbij{1}{n-1} + \\maxdegbij{1}{n-1}\n} \\le 2n-2 < 2n.$$\nFor case $(iii)$ the condition becomes\n$$ (n-k) + (n-1) \\pround{\n0 + \\maxdegbij{1}{n-1}\n} \\le 2n-1-k < 2n.$$\n\\end{proof}", "meta": {"hexsha": "ed92f38ef52ab60a141eaaa15b0a8093fc7c12f2", "size": 6084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strFeistel/4impmono.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/4impmono.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/4impmono.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": 60.84, "max_line_length": 1086, "alphanum_fraction": 0.6707758054, "num_tokens": 2182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6103184042955884}}
{"text": "\\chapter{Proofs and Proof Methods}\nWriting proofs deepens your knowledge of the subject at hand. ECS 20 is a proof\nheavy course and prepares you to write extensive proofs in upper division CS\nand Math classes. Almost 60\\% of your exam will be based on proofs and will\ntest your ability to write a flawless proof. Here are three important proof\nmethods that this chapter will cover:\n\n\\begin{itemize}\n    \\item Direct Proof\n    \\item Indirect Proof (Proof by Contraposition)\n    \\item Proof by Contradiction\n    \\item Proof by Cases\n    \\item Constructive and Non-Constructive Proofs\n\\end{itemize}\n\n\\section{Direct Proof}\nThis is the most basic proof method. Here, we will be given a statement of the\nform $ P \\rightarrow Q $ and you will be asked to prove this propositional\nform. Here is how you could prove something directly:\n\n% https://tex.stackexchange.com/questions/108236/enumerate-list-numbers-with-prefix\n% TODO make a macro for steps\n\\begin{enumerate}[label=\\textbf{Step \\arabic*},leftmargin=*]\n    \\item Given $P \\rightarrow Q$, assume P is true.\n    \\item Using $P$, try to use the given information of $P$ to arrive at $Q$.\n\\end{enumerate}\n\nHere is a simple example:\n\n\\begin{theorem}\n    If $a$ is an even integer, then $a^{3} - 6a$ is even.\n\\end{theorem}\n\n\\begin{proof}\n    Let us use a direct proof.\n\n    Assume $a$ is an even integer.\n\n    Then,\n    \\[\n        \\begin{split}\n            \\exists k \\in \\mathbb{Z}, a &= 2k \\\\\n            a^{3} - 6a &= (2k)^{3} - 6(2k) \\\\\n            &= 8k^{3} - 12k \\\\\n            &= 2(4k^{3} - 6k) \\\\\n            &= 2m\\text{, where } m = 4k^{3} - 6k \\\\\n        \\end{split}\n    \\]\n    Thus, $a^3 - 6a$ is even. Therefore, if $a$ is even, then $a^{3} -6a$ is even\n\\end{proof}\n\n\\section{Indirect Proof (Proof by Contraposition)}\nSuppose we are given a statement of the form $P \\rightarrow Q$. Sometimes, a\ndirect proof might be very hard (sometimes impossible) to go about. Therefore\nwe resort to another proof method that simplifies things. In this proof, we\nwill try to show $\\neg Q \\rightarrow \\neg P$ is true. By drawing out a simple\ntruth table you can show that $ P \\rightarrow Q \\Leftrightarrow \\neg Q\n\\rightarrow \\neg P$.\n\nHere is how you can prove something by contraposition:\n\n\\begin{enumerate}[label=\\textbf{Step \\arabic*},leftmargin=*]\n    \\item Given $P \\rightarrow Q$, Assume $\\neg Q$ is true.\n    \\item Using $\\neg Q$, try to arrive at $\\neg P$.\n\\end{enumerate}\n\n\\noindent Here is a simple example:\n\n\\begin{theorem}\n    If $a^{2}$ is even, then $a$ is even\n\\end{theorem}\n\n\\begin{proof}\n    Let us use an indirect proof.\n\n    Assume $a$ is odd (Assume $\\neg Q$).\n\n    Then,\n    \\[\n        \\begin{split}\n            \\exists k \\in \\mathbb{Z}, a &= 2k + 1 \\\\\n            a^{2} &= (2k + 1)^{2} = 4k^2 + 4k + 1 \\\\\n            \\Leftrightarrow a^{2} &= 2(2k^{2} + 2k) + 1 \\\\\n            \\Leftrightarrow &= 2m + 1 \\text{, where } m = 2k^{2} + 2k \\\\\n        \\end{split}\n    \\]\n\n    Therefore, $a^{2}$ is odd.  Thus, we have shown that if $a$ is odd, then\n    $a^{2}$ is odd.\n\n    Therefore by contraposition, If $a^{2}$ is even then, $a$ is even.\n\\end{proof}\n\n\\section{Proof By Contradiction}\nSuppose we are given asked to prove a given statement, Q, a direct proof might\nnot be feasible. Hence we resort to our last proof method to prove statements\nthat might look difficult to prove directly. In this proof method, we assume\n$\\neg Q$ to be true. Suppose you are given a statement of the form $P\n\\rightarrow Q$, then you assume $\\neg (P \\rightarrow Q)$, which is basically $P\n\\wedge \\neg Q$.\n\nHere is a simple example:\n\\begin{theorem}\n    If $(a,b) \\in \\mathbb{Z}^{2}$, then $a^{2} - 4b \\neq 2$\n\\end{theorem}\n\n\\begin{proof}\n    Let us use a proof by contradiction. Assume $P \\wedge \\neg Q$ is true. Then\n    $(a,b) \\in \\mathbb{Z}^{2} \\wedge (a^{2} -4b = 2)$ is true.\n\n    \\[\n        \\begin{split}\n            \\text{If }&a^{2} - 4b = 2\\text{, then} \\\\\n            &a^{2} = 2 + 4b \\\\\n            \\iff &a^{2}\\text{ is even} \\\\\n            \\iff &a\\text{ is even \\footnote{You can prove this by\n            contraposition. However, If you're interested in using a direct\n            proof to show that $a^{2}$ is even $\\rightarrow a$ is even, then\n            you'd have to wait till we reach number theory ;)}} \\\\\n            \\iff &\\exists k \\in \\mathbb{Z}a = 2k \\\\\n            \\iff &(2k)^{2} - 4b = 2 \\\\\n            \\iff &4k^{2} - 4b = 2 \\\\\n            \\iff &2k^{2} - 2b = 1 \\\\\n            \\iff &2 \\times (k^{2} - 2b) = 1 \\\\\n        \\end{split}\n    \\]\n    $\\Leftrightarrow$ An even integer is equal to the odd integer 1, which is a\n    contradiction.\n\n    This contradiction arises due to our incorrect assumption that $\\neg (P\n    \\rightarrow Q)$ was true.\n\n    Therefore, $P \\rightarrow Q$ is true.\n\n    Thus, If $(a,b) \\in \\mathbb{Z}^{2}$, then $a^{2} - 4b \\neq 2$\n\\end{proof}\n\n\\section{Proof by Cases}\nThis is a proof method that is always used when you do not know the constraints\nto a problem. Let us illustrate this with a very simple example:\n\n\\begin{theorem}\n    If $a$ is an integer, then $2a + 1$ is odd.\n\\end{theorem}\n\n\\begin{proof}\n    Here, we do not know if $a$ is an even or odd integer. Thus, we consider\n    both cases and try to prove our hypothesis:\n\n    \\begin{caselist}\n        \\item $a$ is even. \\\\\n            Then, ($\\exists k \\in \\mathbb{Z}$)[$a = 2k$]. \\\\\n            Then, $2a + 1 = 2(2k) + 1$, which is odd!\n        \\item $a$ is odd. \\\\\n            Then, ($\\exists k \\in \\mathbb{Z}$)[$a = 2k + 1$]. \\\\\n            Then, $2a + 1 = 2(2k + 1) + 1$, which is also odd!\n    \\end{caselist}\n\\end{proof}\n\n\\section{Constructive and Non-Constructive Proofs}\n\\subsection{Constructive Proofs}\nConstructive proofs are proof methods in which a specific example is provided.\nThese proofs are generally referred to as \"\\emph{Existence Proofs}\".\n\nLet us take two separate examples to illustrate this proof method.\n\n\\begin{example}\n    Show that there exist two integers a and b such that $a + b$ and $a - b$\n    are both prime numbers.\n    \\begin{proof}\n        We only need to show a single pair $(a,b)$ for which $a + b$ and $a - b$\n        are both prime numbers.\n\n        Let us take $a = 5$ and $b = 2$.\n\n        Then, $a + b = 7$ and $a - b = 3$.\n\n        Both 7 and 3 are prime numbers.\n\n        Thus, we found a particular pair of numbers for which the hypothesis holds.\n    \\end{proof}\n\\end{example}\n\n\\begin{example}\n    Prove or disprove the following:\n    \\begin{center}\n        For all $k \\in \\mathbb{Z}$ greater than 2, $2k + 7$ is a prime number.\n    \\end{center}\n    \\begin{proof}\n        Let us try out a few numbers and see what we get:\n\n        \\begin{trylist}\n            \\item $k = 2$ \\\\\n                Then, $2k + 7 = (2 \\times 2) + 7 = 4 + 7 = 11$ which is a prime\n                number.\n            \\item \\textbf{$k = 3$} \\\\\n                Then, $2k + 7 = (2 \\times 3) + 7 = 6 + 7 = 13$ which is a prime number.\n            \\item $k = 4$ \\\\\n                Then, $2k + 7 = (2 \\times 4) + 7 = 8 + 7 = 15$ \\textbf{which is NOT\n                prime}.\n        \\end{trylist}\n\n        \\noindent Thus, we have found one example which violates the hypothesis.\n\n        \\noindent Thus, the given statement is \\textbf{FALSE}!\n    \\end{proof}\n\\end{example}\n\n\\subsection{Non-Constructive Proofs}\nThis is another kind of an existence proof. In this method, we do not\nexplicitly find a value of 'x' such that $P(x)$ is true. Instead, we show that\nthere must exist some x for which $P(x)$ is true. This might seem like a\nconfusing definition, so let us use this in an example:\n\n\\begin{question}\n    Show that there exists a pair of irrational numbers a and b such that $c =\n    a^{b}$ is rational.\n\\end{question}\n\n\\begin{remark}\n    This is a very famous and interesting problem in the field of proofs and\n    discrete mathematics. Let us look at the solution:\n\\end{remark}\n\n\\begin{proof}\n    We know that $\\sqrt 2$ is irrational. Let us define $c = (\\sqrt 2)^{\\sqrt\n    2}$.\n\n    Additionally, let us define $d = c ^{\\sqrt2}$.\n\n    Then, $d = (\\sqrt 2) ^{\\sqrt 2 \\times \\sqrt 2} = (\\sqrt 2) ^{2} = 2$ which\n    is rational.\n\\end{proof}\n\nNote that we did not explicitly find the values of a and b in the above\nexample. We simply showed that there could exist a pair of irrational numbers\nin which $a^{b}$ could be rational.\n\n\\textbf{\\emph{Trivia: }} Did you know that there is a constructive\nproof for the above mentioned example? It is quite hard to find the right\nexamples for a and b, but it is possible. I haven't included the answers, but\ndo think about it!\n", "meta": {"hexsha": "a2372e02b59e35721ed17b9ba1ea9247ee6fe688", "size": 8535, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ECS 20 Study Guide/Proofs.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/Proofs.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/Proofs.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.1234567901, "max_line_length": 87, "alphanum_fraction": 0.6206209725, "num_tokens": 2626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.610245577188772}}
{"text": "\n\\BoSSSopen{tutorial11-Stokes/StokesEq}\n\\graphicspath{{tutorial11-Stokes/StokesEq.texbatch/}}\n\n\n\\BoSSScmd{\n/// \\label{chap:stokesEquation}\n/// \\section*{What's new?}\n/// \\label{sec:stokesEquation_new}\n/// \\begin{itemize}\n///     \\item {implementation of the incompressible, steady Stokes equation}\n///     \\item advanced: {implementation of the Stokes flow behind a grid as an application}\n/// \\end{itemize}\n///\n///\\section*{Prerequisites}\n///\\label{sec:stokesEquation_prereq}\n///\\begin{itemize}\n/// \\item implementation of numerical fluxes, chapter \\ref{NumFlux} \n/// \\item spatial operator, chapter \\ref{SpatialOperator}\n/// \\item implementation of the gradient operator, chapter \\ref{sec:PoissonAsASystem}\n/// \\item implementation of the SIP operator, chapter \\ref{sec:SIP}\n///\\end{itemize}\n    /// %==========================================\n    /// \\section{Problem statement}\n    /// %==========================================\n/// The Stokes-equation is given as\n/// \\begin{alignat*}{3}\n/// -\\frac{1}{\\reynolds} \\Delta \\vec{u}\n///     & + \\nabla \\psi\n///        & \\ & = \\vec{g}_\\domain\n/// \\\\ \n/// \\operatorname{div} (\\vec{u})\n///     &\n///        & \\ & = 0\n/// \\end{alignat*}\n/// We consider two types of boundary conditions for the Stokes equation,\n/// Dirichlet (on $\\Gamma_D$) and Neumman (on $\\Gamma_N$). Those are defined as\n/// \\begin{alignat*}{3}\n///         \\vec{u} & =\\vec{u}_D \n///         & \\ & \\text{ on } \\Gamma_D\\ \\text{ (Dirichlet)}, \\\\\n///         %\n///         \\left( -\\frac{1}{\\reynolds}\\ \\nabla  \\vec{u} +  \\one_p \\psi \\right) \n///                \\vec{n}_{\\partial \\domain}        & = 0 \n///         & \\ & \\text{ on } \\Gamma_N\\ \\text{ (Neumann) } .\n/// \\end{alignat*}\n/// %==========================================\n/// \\section{Solution within the BoSSS framework}\n/// %==========================================\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nrestart\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\nusing ilPSP.LinSolvers;\\newline \nusing BoSSS.Solution.Tecplot;\\newline \nusing ilPSP.Connectors.Matlab;\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// BoSSScmdSilent BoSSSexeSilent\nusing NUnit.Framework;\n }\n\\BoSSSexeSilent\n\\BoSSScmd{\n/// To implement at which point of the boundary which condition is valid, we\n/// define a global function \nFunc<double[],bool> IsDirichletBndy = null;\\newline \n/// which defines a mapping \n/// \\[\n///    \\vec{x} \\mapsto \\{ \\code{true}, \\code{false} \\},\n/// \\]\n/// where \\code{true} actually indicates a Dirichlet boundary.\n/// Since this function is defined as a global delegate, it can be altered \n/// later on. In the same manner, the function\nFunc<double[],double[]> UDiri = null;\\newline \n/// defines the Dirichlet-value for the velocity at the boundary.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %==========================================\n/// \\subsection{Velocity divergence and pressure gradient}\n/// %==========================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// At first, we implement the velocity divergence, i.e. \n/// the continuity equation. We use the strong form, i.e.\n/// \\[\n///    b(\\vec{u},v) = \n///    \\oint_{\\Gamma \\backslash \\Gamma_D} \n///           \\mean{v} \\jump{\\vec{u}} \\cdot \\vec{n}_\\Gamma \n///    \\dA \n///    -\n///    \\int_{\\domain} \\operatorname{div}(\\vec{u}) v \\dV.\n/// \\]\npublic class Divergence : \\newline \n\\btab \\btab BoSSS.Foundation.IEdgeForm, // edge integrals\\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm     // volume integrals\\newline \n\\{\\newline \n    /// The parameter list for the divergence is empty:\n\\btab public IList<string> ParameterOrdering \\{ \\newline \n\\btab \\btab get \\{ return null; \\} \\newline \n\\btab \\}\\newline \n \\newline \n    /// We have a vector argument variable, \n    /// the velocity $ [ u, v ] = \\vec{u} $\n    /// (our trial function):\n\\btab public IList<String> ArgumentOrdering \\{ \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"u\", \"v\" \\}; \\} \\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags VolTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return TermActivationFlags.AllOn;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags InnerEdgeTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return TermActivationFlags.AllOn; \\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{\\newline \n\\btab    get \\{\\newline \n\\btab \\btab    return TermActivationFlags.AllOn;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n    /// In the volume part, the integrand is $\\operatorname{div}(\\vec{u}) v$:\n\\btab public double VolumeForm(ref CommonParamsVol cpv, \\newline \n\\btab \\btab double[] U, double[,] GradU, \\newline \n\\btab \\btab double V, double[] GradV) \\{\\newline \n\\btab \\btab double Acc = 0;\\newline \n\\btab \\btab for(int d = 0; d < cpv.D; d++) \\{\\newline \n\\btab \\btab \\btab Acc -= GradU[d,d]*V;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\}\\newline \n \\newline \n    /// On interior cell boundaries, we use a \\emph{velocity penalty},\n    /// $\\mean{v} \\jump{\\vec{u}} \\cdot \\vec{n}_\\Gamma$:\n\\btab public double InnerEdgeForm(ref CommonParams inp, \\newline \n\\btab \\btab double[] U\\_IN, double[] U\\_OT, double[,] GradU\\_IN, double[,] GradU\\_OT, \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double Acc = 0;\\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{\\newline \n\\btab \\btab \\btab Acc += 0.5*(V\\_IN + V\\_OT)*(U\\_IN[d] - U\\_OT[d])*inp.Normale[d];\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\}\\newline \n \\newline \n    /// On the domain boundary, we have to distinguish between \n    /// Dirichlet- and Neumann-boundary conditions; the function\n    /// \\code{uDiri} defines which of the two actually applies:\n\\btab public double BoundaryEdgeForm(ref CommonParamsBnd inp, \\newline \n\\btab \\btab double[] U\\_IN, double[,] GradU\\_IN, double V\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double Acc = 0;\\newline \n \\newline \n\\btab \\btab if(!IsDirichletBndy(inp.X)) \\{\\newline \n\\btab \\btab \\btab // On the Neumann boundary, we do not know an outer value for the\\newline \n\\btab \\btab \\btab // velocity, so there is no penalization at all:\\newline \n\\btab \\btab \\btab Acc = 0;    \\newline \n\\btab \\btab \\} else \\{\\newline \n\\btab \\btab \\btab // On the Dirichlet boundary, the outer value for the velocity\\newline \n\\btab \\btab \\btab // is given by the function/delegate 'UDiri':\\newline \n\\btab \\btab \\btab double[] UD = UDiri(inp.X);\\newline \n\\btab \\btab \\btab for(int d = 0; d < inp.D; d++) \\{\\newline \n\\btab \\btab \\btab \\btab Acc += (U\\_IN[d] - UD[d])*inp.Normale[d]*V\\_IN;\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\}\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %==================================\n/// \\subsection{The gradient-operator}\n/// %==================================\n/// We use the variational formulation of the gradient operator, as it is explained in section \\ref{subsec:poissonSystem_gradientOp}.\nclass Gradient\\_d :\\newline \n\\btab \\btab BoSSS.Foundation.IEdgeForm, // edge integrals\\newline \n\\btab \\btab BoSSS.Foundation.IVolumeForm     // volume integrals\\newline \n\\{\\newline \n\\btab public Gradient\\_d(int \\_d) \\{\\newline \n\\btab \\btab this.d = \\_d;\\newline \n\\btab \\}\\newline \n \\newline \n    /// The component index of the gradient:\n\\btab int d;\\newline \n \\newline \n    /// As usual, we do not use parameters:\n\\btab public IList<string> ParameterOrdering \\{ \\newline \n\\btab \\btab get \\{ return null; \\} \\newline \n\\btab \\}\\newline \n \\newline \n    /// We have one argument, the pressure $\\psi$:\n\\btab public IList<String> ArgumentOrdering \\{ \\newline \n\\btab \\btab get \\{ return new string[] \\{ \"psi\" \\}; \\} \\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags VolTerms \\{\\newline \n\\btab \\btab get \\{ return TermActivationFlags.AllOn; \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags InnerEdgeTerms \\{\\newline \n\\btab \\btab get \\{ return (TermActivationFlags.AllOn); \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{\\newline \n\\btab    get \\{ return TermActivationFlags.AllOn; \\}\\newline \n\\btab \\}\\newline \n \\newline \n    /// The volume integrand, for a vector-valued test-function $\\vec{v}$\n    /// would be $-\\operatorname{div}{\\vec{v}} \\psi$. Our test function $v$\n    /// is scalar-valued, so e.g. for $\\code{d} = 0$ we have\n    /// $\\vec{v} = (v,0)$. In this case, our volume integrand reduces as \n    /// $-\\operatorname{div}{\\vec{v}} \\psi = -\\partial_x v \\psi$:\n\\btab public double VolumeForm(ref CommonParamsVol cpv, \\newline \n\\btab \\btab    double[] Psi, double[,] GradPsi, \\newline \n\\btab \\btab    double V, double[] GradV) \\{\\newline \n \\newline \n\\btab \\btab double Acc = 0;\\newline \n\\btab \\btab Acc -= Psi[0]*GradV[d];\\newline \n\\btab \\btab return Acc;\\newline \n\\btab \\}        \\newline \n \\newline \n    /// On interior cell edges, we simply use a central-difference flux.\n    /// Again, we consider a scalar test function, so we have\n    /// $ \\jump{\\psi} \\vec{v} \\cdot \\vec{n} = \\jump{\\psi} v n_d $,\n    /// where $n_d$ is the $d$--th component of $\\vec{n}$:\n\\btab public double InnerEdgeForm(ref CommonParams inp, \\newline \n\\btab \\btab double[] Psi\\_IN, double[] Psi\\_OT, \\newline \n\\btab \\btab double[,] GradPsi\\_IN, double[,] GradPsi\\_OT, \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double Acc = 0;\\newline \n\\btab \\btab Acc += 0.5*(Psi\\_IN[0] + Psi\\_OT[0])*inp.Normale[this.d]*(V\\_IN - V\\_OT);\\newline \n\\btab \\btab return Acc;  \\newline \n\\btab  \\}\\newline \n \\newline \n\\btab public double BoundaryEdgeForm(ref CommonParamsBnd inp, \\newline \n\\btab \\btab double[] Psi\\_IN, double[,] GradPsi\\_IN, double V\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double Acc = 0;\\newline \n\\btab \\btab if(!IsDirichletBndy(inp.X)) \\{\\newline \n\\btab \\btab \\btab // On the Neumann boundary, we want the total stress to be zero,\\newline \n\\btab \\btab \\btab // so there is no contribution from the pressure:\\newline \n\\btab \\btab \\btab Acc = 0;\\newline \n\\btab \\btab \\} else \\{\\newline \n\\btab \\btab \\btab // On the Dirichlet boundary, we do not know an outer value for \\newline \n\\btab \\btab \\btab // the pressure, so we have to take the inner value:\\newline \n\\btab \\btab \\btab Acc += Psi\\_IN[0]*inp.Normale[this.d]*V\\_IN;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return Acc;              \\newline \n\\btab \\}\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %==============================================================\n/// \\subsection{Tests on pressure gradient and velocity divergence}\n/// %==============================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// If our implementation is correct, we created a discretization of \n/// \\[\n///  \\left[ \\begin{array}{cc}\n///     0                 & \\nabla \\\\\n///   -\\operatorname{div} & 0      \\\\\n///  \\end{array} \\right]\n/// \\]\n/// so the matrix should have the form \n/// \\[\n///  \\left[ \\begin{array}{cc}\n///     0     & B      \\\\\n///     B^T   & 0      \\\\\n///  \\end{array} \\right]\n///  =: M,\n/// \\]\n/// i.e. $M$ should be symmetric.\n/// We are testing this using a channel flow configuration:\n/// \\begin{align*}\n///     \\Omega    := & (0,10) \\times (-1,1) , \\\\\n///     \\Gamma_N  := & \\{ (x,y) | \\ x = 10 \\} , \\\\\n///     \\Gamma_D  := & \\partial \\Omega \\setminus \\Gamma_D , \\\\\n///     \\vec{u}_D := & (1 - y^2, 0), \n/// \\end{align*}\n/// using an equidistant grid.\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We create a grid, a DG basis for velocity and pressure \n/// and a variable mapping:\nvar xNodesChannel = GenericBlas.Linspace(0,10,31);// 30 cells in x-direction\\newline \nvar yNodesChannel = GenericBlas.Linspace(-1,1,7); // 6 cells in y-direction\\newline \nvar grdChannel    = Grid2D.Cartesian2DGrid(xNodesChannel,yNodesChannel);\\newline \nvar grdDatChannel = new GridData(grdChannel);\\newline \nvar VelBChannel   = new Basis(grdDatChannel, 2);  // velocity basis\\newline \nvar PsiBChannel   = new Basis(grdDatChannel, 1);  // pressure basis \\newline \nvar varMapChannel = new UnsetteledCoordinateMapping(\\newline \n\\btab \\btab \\btab \\btab \\btab    VelBChannel,VelBChannel,PsiBChannel); // variable mapping\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We specify the boundary conditions as delegates:\nFunc<double[],bool> IsDirichletBndy\\_Channel \\newline \n\\btab \\btab = (X => Math.Abs(X[0] - 10) > 1.0e-10); // its Dirichlet, if x != 10\\newline \nFunc<double[],double[]> UDiri\\_Channel \\newline \n\\btab \\btab = (X => new double[2] \\{ 1.0 - X[1]*X[1], 0\\});\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Let's create the operator which contains only the pressure gradient\n/// and velocity divergence:\nSpatialOperator GradDiv = new SpatialOperator(3,3, // 3 vars. in dom. & codom.\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab    QuadOrderFunc.Linear(), // linear operator\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab    \"u\", \"v\", \"psi\",  // names of domain variables\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab    \"mom\\_x\", \"mom\\_y\", \"conti\"); // names of codom. vars\\newline \nGradDiv.EquationComponents[\"mom\\_x\"].Add(new Gradient\\_d(0)); \\newline \nGradDiv.EquationComponents[\"mom\\_y\"].Add(new Gradient\\_d(1)); \\newline \nGradDiv.EquationComponents[\"conti\"].Add(new Divergence());\\newline \nGradDiv.Commit();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We create the matrix of the \\code{GradDiv}-operator for \n/// the channel configuration. Before that, we have to set values for the \n/// global \\code{IsDirichletBndy} and \\code{UDiri}-variables.\nIsDirichletBndy           = IsDirichletBndy\\_Channel;\\newline \nUDiri                     = UDiri\\_Channel;\\newline \nvar GradDivMatrix\\_Channel = GradDiv.ComputeMatrix(varMapChannel,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   null,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab   varMapChannel);\n }\n\\BoSSSexe\n\\BoSSScmd{\n///Finally, we can test the symmetry of the matrix:\nvar ErrMtx = GradDivMatrix\\_Channel - GradDivMatrix\\_Channel.Transpose();\\newline \nErrMtx.InfNorm();\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// NUnit test (few random tests) BoSSScmdSilent\nAssert.LessOrEqual(ErrMtx.InfNorm(), 1e-12);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %====================================================================\n/// \\subsection{Adding the viscous operator, forming the Stokes operator}\n/// %====================================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We use the SIP-operator from chapter \\ref{sec:SIP} to model the viscous terms:\npublic class Viscous : \\newline \n\\btab \\btab IEdgeForm, // edge integrals\\newline \n\\btab \\btab IVolumeForm     // volume integrals\\newline \n\\{\\newline \n    /// The velocity component:\n\\btab int d;\\newline \n \\newline \n\\btab public Viscous(int \\_d) \\{\\newline \n\\btab \\btab this.d = \\_d;    \\newline \n\\btab \\}\\newline \n \\newline \n    /// We implement Reynolds number and the polynomial degree, \n    /// as well as the cell-wise length scales (required for \n    /// the computation of the penalty factor) as global, static variables.\n\\btab public static double Re;\\newline \n\\btab public static int PolynomialDegree;\\newline \n\\btab public static MultidimensionalArray cj;\\newline \n \\newline \n    /// We do not use parameters:\n\\btab public IList<string> ParameterOrdering \\{ \\newline \n\\btab \\btab get \\{ return new string[0]; \\} \\newline \n\\btab \\}\\newline \n \\newline \n    /// Depending on \\code{d}, the argument variable\n    /// should be either $u$ or $v$:\n\\btab public IList<String> ArgumentOrdering \\{ \\newline \n\\btab \\btab get \\{ \\newline \n\\btab \\btab \\btab switch(d) \\{\\newline \n\\btab \\btab \\btab \\btab case 0  : return new string[] \\{ \"u\" \\}; \\newline \n\\btab \\btab \\btab \\btab case 1  : return new string[] \\{ \"v\" \\}; \\newline \n\\btab \\btab \\btab \\btab default : throw new Exception();\\newline \n\\btab \\btab \\btab \\}\\newline \n\\btab \\btab \\} \\newline \n\\btab \\}\\newline \n \\newline \n    /// The \\code{TermActivationFlags}, as usual:\n\\btab public TermActivationFlags VolTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return TermActivationFlags.GradUxGradV;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags InnerEdgeTerms \\{\\newline \n\\btab \\btab get \\{\\newline \n\\btab \\btab \\btab return (TermActivationFlags.AllOn);\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n\\btab public TermActivationFlags BoundaryEdgeTerms \\{\\newline \n\\btab    get \\{\\newline \n\\btab \\btab    return TermActivationFlags.AllOn;\\newline \n\\btab \\btab \\}\\newline \n\\btab \\}\\newline \n \\newline \n    /// The integrand for the volume integral:\n\\btab public double VolumeForm(ref CommonParamsVol cpv, \\newline \n\\btab \\btab    double[] U, double[,] GradU,\\newline \n\\btab \\btab    double V, double[] GradV) \\{               \\newline \n\\btab \\btab double acc = 0;\\newline \n\\btab \\btab for(int d = 0; d < cpv.D; d++)\\newline \n\\btab \\btab \\btab acc += GradU[0, d] * GradV[d];\\newline \n\\btab \\btab return (1/Re)*acc;\\newline \n\\btab \\}\\newline \n \\newline \n \\newline \n    /// The integrand for the integral on the inner edges:\n\\btab public double InnerEdgeForm(ref CommonParams inp, \\newline \n\\btab \\btab double[] U\\_IN, double[] U\\_OT, double[,] GradU\\_IN, double[,] GradU\\_OT, \\newline \n\\btab \\btab double V\\_IN, double V\\_OT, double[] GradV\\_IN, double[] GradV\\_OT) \\{\\newline \n \\newline \n\\btab \\btab double eta = PenaltyFactor(inp.jCellIn, inp.jCellOut);\\newline \n \\newline \n\\btab \\btab double Acc = 0.0;\\newline \n\\btab \\btab for(int d = 0; d < inp.D; d++) \\{ // loop over vector components \\newline \n\\btab \\btab \\btab // consistency term: -(\\{\\{ \\textbackslash /u \\}\\} [[ v ]])*Normale\\newline \n\\btab \\btab \\btab // index d: spatial direction\\newline \n\\btab \\btab \\btab Acc -= 0.5 * (GradU\\_IN[0, d] + GradU\\_OT[0, d])*(V\\_IN - V\\_OT)\\newline \n\\btab \\btab \\btab \\btab \\btab    * inp.Normale[d];\\newline \n \\newline \n\\btab \\btab \\btab // the symmetry term -(\\{\\{ \\textbackslash /v \\}\\} [[ u ]])*Normale\\newline \n\\btab \\btab \\btab Acc -= 0.5 * (GradV\\_IN[d] + GradV\\_OT[d])*(U\\_IN[0] - U\\_OT[0])\\newline \n\\btab \\btab \\btab \\btab \\btab    * inp.Normale[d];;\\newline \n\\btab \\btab \\}\\newline \n \\newline \n\\btab \\btab // the penalty term eta*[[u]]*[[v]]\\newline \n\\btab \\btab Acc += eta*(U\\_IN[0] - U\\_OT[0])*(V\\_IN - V\\_OT);\\newline \n\\btab \\btab return (1/Re)*Acc;\\newline \n \\newline \n\\btab \\}\\newline \n \\newline \n    /// The integrand on boundary edges, i.e. on $\\partial \\Omega$:\n\\btab public double BoundaryEdgeForm(ref CommonParamsBnd inp, \\newline \n\\btab \\btab double[] U\\_IN, double[,] GradU\\_IN, double V\\_IN, double[] GradV\\_IN) \\{\\newline \n \\newline \n \\newline \n\\btab \\btab double Acc = 0.0;\\newline \n \\newline \n\\btab \\btab if(!IsDirichletBndy(inp.X)) \\{\\newline \n\\btab \\btab \\btab // Neumann boundary conditions, i.e. zero-stress:\\newline \n\\btab \\btab \\btab Acc = 0;\\newline \n\\btab \\btab \\} else \\{\\newline \n\\btab \\btab \\btab // Dirichlet boundary conditions\\newline \n\\btab \\btab \\btab double uBnd = UDiri(inp.X)[d];\\newline \n \\newline \n\\btab \\btab \\btab for(int d = 0; d < inp.D; d++) \\{ // loop over vector components \\newline \n\\btab \\btab \\btab \\btab // consistency term:\\newline \n\\btab \\btab \\btab \\btab Acc -= (GradU\\_IN[0, d])*(V\\_IN) * inp.Normale[d];\\newline \n\\btab \\btab \\btab \\btab // symmetry term:\\newline \n\\btab \\btab \\btab \\btab Acc -= (GradV\\_IN[d])*(U\\_IN[0]- uBnd) * inp.Normale[d];\\newline \n\\btab \\btab \\btab \\}\\newline \n \\newline \n\\btab \\btab \\btab // penalty term\\newline \n\\btab \\btab \\btab double eta = PenaltyFactor(inp.jCellIn, -1);\\newline \n\\btab \\btab \\btab Acc += eta*(U\\_IN[0] - uBnd)*(V\\_IN);\\newline \n\\btab \\btab \\}\\newline \n \\newline \n\\btab \\btab return (1/Re)*Acc;\\newline \n\\btab \\}\\newline \n \\newline \n\\btab double PenaltyFactor(int jCellIn, int jCellOut) \\{\\newline \n\\btab \\btab double PenaltySafety = 2;\\newline \n\\btab \\btab double cj\\_in         = cj[jCellIn];\\newline \n\\btab \\btab double penalty\\_base  = PenaltySafety*PolynomialDegree*PolynomialDegree;\\newline \n\\btab \\btab double eta           = penalty\\_base * cj\\_in;\\newline \n\\btab \\btab if(jCellOut >= 0) \\{\\newline \n\\btab \\btab \\btab double cj\\_out = cj[jCellOut];\\newline \n\\btab \\btab \\btab eta           = Math.Max(eta, penalty\\_base * cj\\_out);\\newline \n\\btab \\btab \\}\\newline \n\\btab \\btab return eta;\\newline \n\\btab \\}\\newline \n\\}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Finally, we are ready to implement the Stokes operator:\nSpatialOperator Stokes = new SpatialOperator(3,3, // 3 vars. in dom. & codom.\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  QuadOrderFunc.Linear(), // linear operator\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  \"u\", \"v\", \"psi\",  // names of domain variables\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab  \"mom\\_x\", \"mom\\_y\", \"conti\"); // names of codom. vars\\newline \nStokes.EquationComponents[\"mom\\_x\"].Add(new Gradient\\_d(0)); \\newline \nStokes.EquationComponents[\"mom\\_x\"].Add(new Viscous(0)); \\newline \nStokes.EquationComponents[\"mom\\_y\"].Add(new Gradient\\_d(1)); \\newline \nStokes.EquationComponents[\"mom\\_y\"].Add(new Viscous(1));\\newline \nStokes.EquationComponents[\"conti\"].Add(new Divergence());\\newline \nStokes.Commit();\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Again, we create the matrix (now, for the Stokes operator) and check its\n/// symmetry; we also have to set the Reynolds number and the polynomial\n/// degree \\emph{before} calling \\code{ComputeMatrix} (since we are doing a\n/// rather dirty trick by using global variables).\nIsDirichletBndy          = IsDirichletBndy\\_Channel;\\newline \nUDiri                    = UDiri\\_Channel;\\newline \nViscous.Re               = 20.0;\\newline \nViscous.PolynomialDegree = VelBChannel.Degree;\\newline \nViscous.cj               = grdDatChannel.Cells.cj;\\newline \nvar StokesMatrix\\_Channel = Stokes.ComputeMatrix(varMapChannel,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab null,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab varMapChannel);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Testing the symmetry:\nvar ErrMtx1 = StokesMatrix\\_Channel - StokesMatrix\\_Channel.Transpose();\\newline \nErrMtx1.InfNorm();\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// NUnit test (few random tests) BoSSScmdSilent\nAssert.LessOrEqual(ErrMtx1.InfNorm(), 1e-12);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We also verify that our Stokes-matrix has full rank, i.e. we show that \n/// matrix size and rank are equal:\n }\n\\BoSSSexe\n\\BoSSScmd{\nStokesMatrix\\_Channel.NoOfRows;\n }\n\\BoSSSexe\n\\BoSSScmd{\nStokesMatrix\\_Channel.rank();\n }\n\\BoSSSexe\n\\BoSSScmdSilent{\n/// NUnit test (few random tests) BoSSScmdSilent\nAssert.AreEqual(StokesMatrix\\_Channel.rank(), StokesMatrix\\_Channel.NoOfRows);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %======================================================\n/// \\subsection{Solving the Stokes equation in the channel}\n/// %======================================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We set the parameters and see whether we actually obtain the correct \n/// solution; the exact solution of our problem is obviously\n/// \\begin{align*}\n///     \\vec{u}_{\\text{ex}} = & (1 - y^2, 0 ), \\\\\n///     \\psi_{\\text{ex}}    = & \\frac{200}{\\text{Re}} - x \\frac{2}{\\text{Re}} \\\\\n/// \\end{align*}\n/// and since it is polynomial we should be able to obtain it \n/// \\emph{exactly} in our velocity-pressure-space of degrees $(2,1)$.\nIsDirichletBndy          = IsDirichletBndy\\_Channel;\\newline \nUDiri                    = UDiri\\_Channel;\\newline \nViscous.Re               = 20.0;\\newline \nViscous.PolynomialDegree = VelBChannel.Degree;\\newline \nvar StokesMatrix\\_Channel = Stokes.ComputeMatrix(varMapChannel,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab null,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab varMapChannel);\\newline \nvar StokesAffine\\_Channel = Stokes.ComputeAffine(varMapChannel,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab null,\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab varMapChannel);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Now, we are ready to solve the stokes equation. \\BoSSS\\ provides us with\n/// a system \n/// \\[\n///   \\code{StokesMatrix\\_Channel} \\cdot (u,v,\\psi) \n///   + \\code{StokesAffine\\_Channel} = 0,\n/// \\]\n/// so we have to multiply \\code{StokesAffine\\_Channel} with $-1$ to get a \n/// right-hand-side.\ndouble[] RHS = StokesAffine\\_Channel.CloneAs();\\newline \nRHS.ScaleV(-1.0);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// In order to store our solution, we have to create DG fields:\nSinglePhaseField u               = new SinglePhaseField(VelBChannel,\"u\");\\newline \nSinglePhaseField v               = new SinglePhaseField(VelBChannel,\"v\");\\newline \nSinglePhaseField psi             = new SinglePhaseField(PsiBChannel,\"psi\");\\newline \nCoordinateVector SolutionChannel = new CoordinateVector(u,v,psi);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// Solve the linear system using a direct method:\nStokesMatrix\\_Channel.Solve\\_Direct(SolutionChannel, RHS);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We export the solution to a Tecplot file:\nTecplot(\"Channel\", 0.0, 3, u, v, psi);\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\emph{TODO}: Use Visit (or any other visualization software)\n/// to inspect the solution!\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %=====================================\n/// \\section{Advanced topics}\n/// %=====================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// %=====================================\n/// \\subsection{Stokes flow behind a grid}\n/// %=====================================\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// We use the following setting:\n/// \\begin{align*}\n///     \\Omega    := & (0,5) \\times (-2,2) \\\\\n///     \\Gamma_N  := & \\{ (x,y) | \\ x = 5 \\} , \\\\\n///     \\Gamma_D  := & \\partial \\Omega \\setminus \\Gamma_D , \\\\\n///     \\vec{u}_D := & (1 - (2 (y - \\operatorname{floor}(y)) - 1)^2, 0), \\\\\n/// \\end{align*}\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// So, the boundary functions are:\nFunc<double[],bool> IsDirichletBndy\\_GridFlow \\newline \n\\btab \\btab = (X => Math.Abs(X[0] - 5) > 1.0e-10); \\newline \nFunc<double[],double[]> UDiri\\_GridFlow \\newline \n\\btab \\btab = (X => new double[2] \\{ 1.0 - (2*(X[1] - Math.Floor(X[1])) - 1).Pow2(),\\newline \n\\btab \\btab \\btab \\btab \\btab \\btab \\btab \\btab 0\\});\n }\n\\BoSSSexe\n\\BoSSScmd{\n/// \\emph{TODO}: the rest is for you! One hint: in $y$-direction, use some \n/// spacing so that you have cell boundaries at (least at) $y = -1, 0, 1$.\n }\n\\BoSSSexe\n", "meta": {"hexsha": "cd20ccc0d232c3fe24293efced6eb992b29aa2ff", "size": 26395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/handbook/tutorial11-Stokes/StokesEq.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/tutorial11-Stokes/StokesEq.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/tutorial11-Stokes/StokesEq.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": 40.4831288344, "max_line_length": 133, "alphanum_fraction": 0.6464481909, "num_tokens": 8319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249076, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6102144009220904}}
{"text": "\\section{Truncations}\n\nTruncation is a universal way of turning an arbitrary type into a $k$-truncated type. We have already seen the propositional truncation of a type $X$ in \\cref{chap:image}, which is the proposition that $X$ is merely inhabited, and the set truncation of $X$ in \\cref{sec:set-truncation}, which is the set of connected components of $X$. The $k$-truncation is a generalization of the propositional truncation and the set truncation to an arbitrary truncation level $k$.\n\nWe construct the truncations by recursion on $k$. The base case $k\\jdeq -2$ is just the operation that sends a type $X$ to the unit type $\\unit$, because up to equivalence there is only one contractible type. For the inductive step, we need to construct the $(k+1)$-truncation assuming that the $k$-truncation of an arbitrary type in a fixed universe $\\UU$ exists. Our construction of the $(k+1)$-truncation is a direct generalization of the construction of the set truncation as a set quotient, where we quotient out the equivalence relation\n\\begin{equation*}\n  (x\\sim y)\\defeq \\trunc{-1}{x=y}.\n\\end{equation*}\nThe idea is simple: if $\\trunc{k+1}{X}$ is to be the universal $(k+1)$-truncated type equipped with a map $\\tproj{k+1}{\\blank}:X\\to \\trunc{k+1}{X}$, then it has to be the case that\n\\begin{equation*}\n  (\\tproj{k+1}{x}=\\tproj{k+1}{x'})\\simeq \\trunc{k}{x=y}.\n\\end{equation*}\nWe prove that this is indeed the case in \\cref{thm:trunc_id}.\n\nThe construction of the $(k+1)$-truncation as a quotient is different than the construction of the $(k+1)$-truncation that appears in \\cite{hottbook} as a higher inductive type. This construction is based on the observation that a type $X$ is $k$-truncated if and only if every map $\\sphere{k+1}\\to X$ is constant. In other words, for every map $f:\\sphere{k+1}\\to X$ into a $k$-type $X$, there is a point $x:X$ and a family of paths $p(t):x=f(t)$. If we think of $f$ as a `wheel' in $X$, then $x$ is the hub at the center of the wheel, and the paths $p(t)$ are the spokes. This leads to defining the $k$-truncation of a type $X$ by the \\emph{hubs-and-spokes method}. In \\cref{sec:hubs-and-spokes} we show that the $k$-truncation of a type is such a higher inductive type.\n\n\\subsection{The universal property of the truncations}\n\n\\begin{defn}\\label{defn:is_truncation}\nLet $X$ be a type. A map $f:X\\to Y$ into an $k$-type $Y$ is said to satisfy the \\define{universal property of the $k$-truncation of $X$} if the precomposition map\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$.\n\\end{defn}\n\n\\begin{rmk}\nA map $f:X\\to Y$ into an $k$-type $Y$ satisfies the universal property of $k$-truncation if of for every $g:X\\to Z$ the type of extensions\n\\begin{equation*}\n\\begin{tikzcd}\nX \\arrow[dr,\"g\"] \\arrow[d,swap,\"f\"] \\\\\nY \\arrow[r,densely dotted] & Z\n\\end{tikzcd}\n\\end{equation*}\nis contractible. Indeed, the type of such extensions is the type\n\\begin{equation*}\n\\sm{h:Y\\to Z} h\\circ f\\htpy g,\n\\end{equation*}\nwhich is equivalent to the fiber of the precomposition map $\\blank\\circ f$ at $g$. \n\\end{rmk}\n\nIn the following proposition we show that if a map $f:X\\to Y$ into a $k$-type $Y$ satisfies the universal property of the $k$-truncation of $X$, then $f$ also satisfies the dependent elimination property.\n\n\\begin{prp}\\label{thm:trunc_dup}\n  Suppose the map $f:X\\to Y$ into an $k$-type $Y$. The following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ satisfies the universal property of $k$-truncation.\n  \\item For any family $P$ of $k$-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. This property is also called the \\define{dependent universal property} of the $k$-truncation.\n%  \\item For any family $P$ of $k$-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%    has a section.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  % The fact that (ii) implies (i) and (iii) is immediate, so we only have to show that both (i) and (iii) imply (ii).\n  The fact that (ii) implies (i) is immediate, so we only have to prove the converse.\n\n  % To prove that (i) implies (ii),\n  Suppose $P$ is a family of $k$-truncated types over $Y$.  \n  Then we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\Big(Y\\to\\sm{y:Y}P(y)\\Big) \\arrow[r,\"\\blank\\circ f\"] \\arrow[d,swap,\"\\proj 1 \\circ\\blank\"] & \\Big(X\\to \\sm{y:Y}P(y)\\Big) \\arrow[d,\"\\proj 1\\circ \\blank\"] \\\\\n      \\Big(Y\\to Y\\Big) \\arrow[r,swap,\"\\blank\\circ f\"] & \\Big(X\\to Y)\n    \\end{tikzcd}\n  \\end{equation*}\n  Since the total space $\\sm{y:Y}P(y)$ is again $k$-truncated by \\cref{ex:istrunc_sigma}, it follows by the universal property of the $k$-truncation that the top map is an equivalence, and by the universal property the bottom map is an equivalence too. It follows from \\cref{cor:pb_equiv} that this square is a pullback square, so it induces equivalences on the fibers by \\cref{cor:pb_fibequiv}. In particular we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\Big(\\prd{y:Y}P(y)\\Big) \\arrow[r] \\arrow[d] & \\Big(\\prd{x:X}P(f(x))\\Big) \\arrow[d] \\\\\n      \\fib{(\\proj 1\\circ \\blank)}{\\idfunc[Y]} \\arrow[r] & \\fib{(\\proj 1 \\circ \\blank)}{f}\n    \\end{tikzcd}\n  \\end{equation*}\n  in which the left and right maps are equivalences by \\cref{ex:pi_sec}, and the bottom map is an equivalence as we have just established. Therefore the top map is an equivalence, so we conclude that $f$ satisfies the dependent universal property.\n%\n%  To see that (iii) implies (ii), consider a family $P$ of $k$-types over $Y$. Our goal is to show that 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*}\n%  is an equivalence. It has a section by assumption, for which we will write $\\varphi$. It therefore remains to show that $\\varphi(h\\circ f)\\htpy h$ for any dependent function $h:\\prd{y:Y}P(y)$. Note that the precomposition function\n%  \\begin{equation*}\n%    \\blank\\circ f : \\Big(\\prd{y:Y}\\varphi(h\\circ f)(y)=h(y)\\Big)\\to\\Big(\\prd{x:X}\\varphi(h\\circ f)(f(x))=h(x)\\Big)\n%  \\end{equation*}\n%  has a section, so it suffices to show that $\\varphi(h\\circ f)\\circ f\\htpy h\\circ f$. This follows again from the assumption that $\\varphi$ is a section of $\\blank\\circ f$.\n\\end{proof}\n\nJust as for pullbacks, pushouts, and the many other types characterized by a universal property, the $k$-truncation of a type is unique once it exists. We prove this in the following proposition and its corollary.\n\n\\begin{prp}\n  Consider a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      \\phantom{Y'} & X \\arrow[dl,swap,\"f\"] \\arrow[dr,\"{f'}\"] \\\\\n      Y \\arrow[rr,swap,\"h\"] & & Y'\n    \\end{tikzcd}\n  \\end{equation*}\n  where $Y$ and $Y'$ are assumed to be $k$-types. If any two of the following three properties hold, so does the third:\n  \\begin{enumerate}\n  \\item The map $f:X\\to Y$ satisfies the universal property of the $k$-truncation of $X$.\n  \\item The map $f':X\\to X'$ satisfies the universal property of the $k$-truncation of $X$.\n  \\item The map $h$ is an equivalence.\n  \\end{enumerate}\n\\end{prp}\n\n\\begin{proof}\n  The claim follows by the 3-for-2 property of equivalences, since we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      Z^{Y'} \\arrow[rr,\"\\blank\\circ h\"] \\arrow[dr,swap,\"{\\blank\\circ f'}\"] & & Z^Y \\arrow[dl,\"\\blank\\circ f\"] \\\\\n      & Z^X & \\phantom{Z^{Y'}}\n    \\end{tikzcd}\n  \\end{equation*}\n  for any $k$-type $Z$.\n\\end{proof}\n\n\\begin{cor}\n  Consider two maps $f:X\\to Y$ and $f':X\\to Y'$ into $k$-types $Y$ and $Y'$, and suppose that both $f$ and $f'$ satisfy the universal property of the $k$-truncation of $X$. Then the type of equivalences $e:Y\\simeq Y'$ equipped with a homotopy witnessing that the triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=tiny]\n      \\phantom{Y'} & X \\arrow[dl,swap,\"f\"] \\arrow[dr,\"{f'}\"] \\\\\n      Y \\arrow[rr,swap,\"e\"] & & Y'\n    \\end{tikzcd}\n  \\end{equation*}\n  commutes is contractible.\n\\end{cor}\n\n\\subsection{The construction of the  \\texorpdfstring{$(k+1)$}{(k+1)}-truncation as a quotient}\n\n\\begin{defn}\n  Consider a universe $\\UU$. We say that $\\UU$ \\define{has $k$-truncations} if for every type $X:\\UU$ there is a map $f:X\\to Y$ into a $k$-type $Y:\\UU$ that satisfies the universal property of the $k$-truncation of $X$.\n\\end{defn}\n\n\\begin{rmk}\n  Note that the universal property of $k$-truncations is formulated with respect to all $k$-types, and not only with respect to the $k$-types in $\\UU$.\n\\end{rmk}\n\nWe will use the following proposition to prove the universal property of the $(k+1)$-truncation. In fact, the converse of the following proposition also holds, and we prove it below in \\cref{thm:is-truncation}.\n\n\\begin{prp}\\label{prp:is-truncation}\n  Consider a map $f:X\\to Y$ into a $(k+1)$-type $Y$. If $f$ is surjective, and its action on paths\n  \\begin{equation*}\n    \\apfunc{f}:(x=x')\\to(f(x)=f(x'))\n  \\end{equation*}\n  satisfies the universal property of the $k$-truncation of $x=x'$, then $f$ satisfies the universal property of the $(k+1)$-truncaton of $X$.\n\\end{prp}\n\n\\begin{proof}\n  Consider a map $g:X\\to Z$ into a $(k+1)$-type $Z$. Our goal is to show that $g$ extends uniquely along $f$ to a map $h:Y\\to Z$. We claim that for any $y:Y$, the type of extensions\n  \\begin{equation*}\n    \\begin{tikzcd}\n      \\fib{f}{y} \\arrow[d] \\arrow[dr,\"g\\circ\\proj 1\"] \\\\\n      \\unit \\arrow[r,densely dotted] & Z\n    \\end{tikzcd}\n  \\end{equation*}\n  is contractible. In other words, on each of the fibers of $f$, the map $g$ is constant in a unique way. Since $f$ is assumed to be surjective, it follows by \\cref{prp:surjective} that it suffices to prove the above extension property for $y\\jdeq f(x)$, for each $x:X$. In other words, we have to show that the type\n  \\begin{equation*}\n    \\sm{z:Z}\\prd{x':X}(f(x)=f(x'))\\to (z=g(x'))\n  \\end{equation*}\n  is contractible for each $x:X$.\n\n  Note that the type $z=g(x')$ is $k$-truncated, and that the map $\\apfunc{f}$ is assumed to satisfy the universal property of the $k$-truncation of $x=x'$. Therefore it is equivalent to show that the type\n  \\begin{equation*}\n    \\sm{z:Z}\\prd{x':X}(x=x')\\to (z=g(x'))\n  \\end{equation*}\n  is contractible. This is immediate by the universal property of the identity type (\\cref{thm:yoneda}), and the fact that $\\sm{z:Z}z=g(x')$ is contractible (\\cref{cor:contr_path}).\n\n  It follows by \\cref{thm:funext_wkfunext} that the product\n  \\begin{equation*}\n    \\prd{y:Y}\\sm{z:Z}\\prd{x:X}(y=f(x))\\to (z=g(x))\n  \\end{equation*}\n  is contractible. Since $\\Pi$ distributes over $\\Sigma$ by \\cref{thm:choice}, we obtain that the type of functions $h:Y\\to Z$ equipped with a homotopy $h\\circ f\\htpy g$ is contractible.\n\\end{proof}\n\nBefore we show that any universe has $k$-truncations for arbitrary $k$, we prove a truncated version of the type theoretic Yoneda lemma under the assumption that $\\UU$ has $k$-truncations for a given $k$. \n\n\\begin{lem}\\label{lem:truncated-yoneda}\n  Suppose $\\UU$ is a universe that has $k$-truncations\n  \\begin{equation*}\n    \\tproj{k}{\\blank}:X\\to\\trunc{k}{X}\n  \\end{equation*}\n  for a given $k\\geq-2$, and consider a family $P$ of types over $X$. We make two claims:\n  \\begin{enumerate}\n  \\item The evaluation function\n    \\begin{equation*}\n      \\Big(\\prd{y:X}\\trunc{k}{x=y}\\to\\trunc{k}{P(y)}\\Big)\\to \\trunc{k}{P(x)}\n    \\end{equation*}\n    given by $h\\mapsto h_x(\\tproj{k}{\\refl{x}})$, is an equivalence.\n  \\item If the total space of $P$ is contractible, then the evaluation function\n    \\begin{equation*}\n      \\Big(\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{P(y)}\\Big)\\to \\trunc{k}{P(x)}\n    \\end{equation*}\n    given by $e\\mapsto e_x(\\tproj{k}{\\refl{x}})$, is an equivalence.\n  \\end{enumerate}\n\\end{lem}\n\n\\begin{proof}\n  The first claim follows immediately by the universal property of the $k$-truncation of $x=y$ and the type theoretical Yoneda lemma (\\cref{thm:yoneda}).\n  \n  To prove the second claim, we first observe that the inclusion of equivalences into all maps induces an embedding that fits in a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\Big(\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{P(y)}\\Big) \\arrow[rr,hook] \\arrow[dr,swap,\"\\ev_{\\tproj{k}{\\refl{x}}}\"] & & \\Big(\\prd{y:X}\\trunc{k}{x=y}\\to\\trunc{k}{P(y)}\\Big) \\arrow[dl,\"\\ev_{\\tproj{k}{\\refl{x}}}\"] \\\\\n      & \\trunc{k}{P(x)}.\n    \\end{tikzcd}\n  \\end{equation*}\n  The evaluation map on the right is an equivalence, and we have to show that if the total space $\\sm{y:X}P(y)$ is contractible, then the evaluation map on the left is an equivalence. We do this by showing that the top map is an equivalence.\n\n  To see this, note that we have a commuting diagram\n    \\begin{equation*}\n    \\begin{tikzcd}\n      \\Big(\\prd{y:X}(x=y)\\simeq P(y)\\Big) \\arrow[d,swap,\"e\\mapsto\\lam{y}\\trunc{k}{e_y}\"] \\arrow[r,hook] & \\Big(\\prd{y:X}(x=y)\\to P(y)\\Big) \\arrow[r,\"\\evrefl\"] \\arrow[d,swap,\"h\\mapsto\\lam{y}\\trunc{k}{h_y}\"] &[2em] P(x) \\arrow[d] \\\\\n      \\Big(\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{P(y)}\\Big) \\arrow[r,hook] & \\Big(\\prd{y:X}\\trunc{k}{x=y}\\to\\trunc{k}{P(y)}\\Big) \\arrow[r,swap,\"\\ev_{\\tproj{k}{\\refl{x}}}\"] & \\trunc{k}{P(x)}\n    \\end{tikzcd}\n  \\end{equation*}\n  In the top row of this diagram we have a concatenation of equivalences: the first map is an equivalence by the fundamental theorem of identity types, and the second map is an equivalence by \\cref{thm:yoneda}. The second map in the bottom row is an equivalence by the first claim of this lemma. Therefore it follows that the vertical map in the middle satisfies the universal property of the $k$-truncation. Since the type at the bottom left is $k$-truncated, we obtain by the universal property of the $k$-truncation a section of the embedding in the bottom row, which proves the claim.\n\\end{proof}\n\n\\begin{thm}\n  Any univalent universe $\\UU$ that is closed under pushouts has $k$-truncations, for every truncation level $k$. We will write\n  \\begin{equation*}\n    \\tproj{k}{\\blank}:X\\to\\trunc{k}{X}\n  \\end{equation*}\n  for the $k$-truncation of $X$.\n\\end{thm}\n\n\\begin{proof}\n  It is easy to see that the terminal projection $X\\to\\unit$ is a $(-2)$-truncation, for any type $X$. Thus, any universe has $(-2)$-truncations.\n\n  We will proceed by induction on $k$. Our inductive hypothesis is that $\\UU$ has $k$-truncations, and our goal is to show that $\\UU$ has $(k+1)$-truncations. The idea of the construction is very similar to the construction of the set quotient by an equivalence relation. Consider the type-valued relation $R_k:X\\to (X\\to \\UU)$ given by\n  \\begin{equation*}\n    R_k(x,x') \\defeq \\trunc{k}{x=x'}.\n  \\end{equation*}\n  Analogous to the definition of set quotients, we define\n  \\begin{equation*}\n    \\trunc{k+1}{X}\\defeq \\im(R_k),\n  \\end{equation*}\n  which comes equipped with a surjective map $q:X\\to\\trunc{k+1}{X}$. Note that the image of $R:X\\to(X\\to\\UU)$ is (essentially) small by \\cref{thm:replacement}. To see that $q:X\\to\\trunc{k+1}{X}$ satisfies the universal property of the $(k+1)$-truncation of $X$, we apply \\cref{prp:is-truncation}. Therefore it remains to show that the action on paths\n  \\begin{equation*}\n    \\apfunc{q}:(x=x')\\to (q(x)=q(x'))\n  \\end{equation*}\n  satisfies the universal property of the $k$-truncation of $x=x'$. Since $q$ is the surjective map in the image factorization of $R_k$, it is equivalent to show that the action on paths\n  \\begin{equation*}\n    \\apfunc{R}:(x=x')\\to (R_k(x)=R_k(x'))\n  \\end{equation*}\n  satisfies the universal property of the $k$-truncation of $x=x'$. Note that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=-2em]\n      \\phantom{\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{x'=y},} & (x=x') \\arrow[dl,swap,\"\\apfunc{R_k}\"] \\arrow[dr] \\\\\n      \\Big(R_k(x)=R_k(x')\\Big) \\arrow[rr,swap,\"\\simeq\"] & & \\Big(\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{x'=y}\\Big),\n    \\end{tikzcd}\n  \\end{equation*}\n  where the bottom map is an equivalence by function extensionality and the univalence axiom. Therefore it suffices to show that the map on the right of this triangle, which is the unique map that sends $\\refl{x}$ to the family of identity equivalences, satisfies the universal property of the $k$-truncation of $x=x'$.\n\n  This map fits in a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=huge]\n      (x=x') \\arrow[d] \\arrow[r,\"\\tproj{k}{\\blank}\"] & \\trunc{k}{x=x'} \\arrow[d,\"\\trunc{k}{\\invfunc}\"] \\\\\n      \\Big(\\prd{y:X}\\trunc{k}{x=y}\\simeq\\trunc{k}{x'=y}\\Big) \\arrow[r,swap,\"\\ev_{\\tproj{k}{\\refl{x}}}\"] & \\trunc{k}{x'=x}.\n    \\end{tikzcd}\n  \\end{equation*}\n  The map on the right is an equivalence because $\\invfunc:(x=x')\\to(x'=x)$ is an equivalence. The bottom map is an equivalence by \\cref{lem:truncated-yoneda}. The top map satisfies the universal property of the $k$-truncation of $x=x'$, hence so does the map on the left, which completes the proof.\n\\end{proof}\n\n\n\\begin{thm}\\label{thm:is-truncation}\n  Consider a map $f:X\\to Y$ into a $(k+1)$-truncated type $Y$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ satisfies the universal property of the $(k+1)$-truncation of $X$.\n  \\item The map $f$ is surjective, and for each $x,x':X$ the map\n    \\begin{equation*}\n      \\apfunc{f} : (x=x')\\to(f(x)=f(x'))\n    \\end{equation*}\n    satisfies the universal property of the $k$-truncation of $x=x'$.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  The fact that (ii) implies (i) was established in \\cref{prp:is-truncation}, so it suffices to show that (i) implies (ii).\n  \n  Suppose first that the map $f$ satisfies the universal property of the $(k+1)$-truncation, and let $x:X$. Recall from \\cref{ex:istrunc_UUtrunc} that the universe of $k$-truncated types is itself $(k+1)$-truncated. Therefore it follows that the map $x'\\mapsto \\trunc{k}{x=x'}$ has a unique extension\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[dr,\"{x'\\mapsto\\trunc{k}{x=x'}}\"] \\arrow[d,swap,\"f\"] \\\\\n      Y \\arrow[r,densely dotted,swap,\"P\"] & \\UU_{\\leq k}.\n    \\end{tikzcd}\n  \\end{equation*}\n  In other words, we obtain a unique family $P$ of $k$-types over $Y$ equipped with equivalences\n  \\begin{equation*}\n    e_{x'}:P(f(x'))\\simeq \\trunc{k}{x=x'}\n  \\end{equation*}\n  indexed by $x':X$. In particular, $P$ comes equipped with a point $p_0:P(f(x))$ such that $e_x(p_0)=\\tproj{k}{\\refl{x}}$. Hence we obtain a family of maps\n  \\begin{equation*}\n    \\prd{y:Y} (f(x)=y)\\to P(y).\n  \\end{equation*}\n  We claim that this is a family of equivalences. By the fundamental theorem of identity types, \\cref{thm:id_fundamental}, it suffices to show that the total space\n  \\begin{equation*}\n    \\sm{y:Y}P(y)\n  \\end{equation*}\n  is contractible. We have $(f(x),p_0)$ at the center of contraction, so we have to construct a contraction\n  \\begin{equation*}\n    \\prd{y:Y}{p:P(y)} (f(x),p_0)=(y,p).\n  \\end{equation*}\n  Now we observe that the type $\\sm{y:Y}P(y)$ is $(k+1)$-truncated, using the fact that any $\\Sigma$-type of a family of $k$-types over a $(k+1)$-type is again $(k+1)$-truncated (\\cref{ex:istrunc_sigma}). It follows that the type $(f(x),p_0)=(y,p)$ is $k$-truncated for each $y:Y$ and each $p:P(y)$. Now we use the dependent universal property of the $k$-truncation of $X$, which was proven in \\cref{thm:trunc_dup}, so it suffices to show that\n  \\begin{equation*}\n    \\prd{x':X}{p:P(f(x'))} (f(x),p_0)=(f(x'),p).\n  \\end{equation*}\n  Since we have an equivalence $e_{x'}:P(f(x'))\\simeq \\trunc{k}{x=x'}$ for each $x':X$, it is equivalent to show that\n  \\begin{equation*}\n    \\prd{x':X}{p:\\trunc{k}{x=x'}}(f(x),p_0)=(f(x'),e_{x'}^{-1}(p)).\n  \\end{equation*}\n  Again, we use that the type of paths $(f(x),p_0)=(f(x'),e_{x'}^{-1}(p))$ is a $k$-type, so we use \\cref{thm:trunc_dup} to conclude that it suffices to show that\n  \\begin{equation*}\n    \\prd{x':X}{p:x=x'}(f(x),p_0)=(f(x'),e_{x'}^{-1}(p)).\n  \\end{equation*}\n  This is immediate by path induction on $p:x=x'$. This proves the claim that the canonical map\n  \\begin{equation*}\n    h_y:(f(x)=y)\\to P(y)\n  \\end{equation*}\n  is an equivalence for each $y:Y$. Now observe that we have a commuting triangle\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=0]\n      \\phantom{\\trunc{k}{x=x'}} & (x=x') \\arrow[dl,swap,\"\\apfunc{f}\"] \\arrow[dr,\"\\tproj{k}{\\blank}\"] & \\phantom{(f(x)=f(x'))} \\\\\n      (f(x)=f(x')) \\arrow[rr,swap,\"h_{f(x')}\"] & & \\trunc{k}{x=x'}\n    \\end{tikzcd}\n  \\end{equation*}\n  for each $x':X$. Therefore it follows that $\\apfunc{f}:(x=x')\\to(f(x)=f(x'))$ satisfies the universal property of the $k$-truncation of $x=x'$.\n\\end{proof}\n\n\\begin{cor}\\label{thm:trunc_id}\nFor any $x,y:X$, there is an equivalence\n\\begin{equation*}\n\\eqv{(\\tproj{k+1}{x}=\\tproj{k+1}{y})}{\\trunc{k}{x=y}}.\n\\end{equation*}\n\\end{cor}\n\n\\subsection{The truncations as recursive higher inductive types}\\label{sec:hubs-and-spokes}\n\nRecall from \\cref{thm:trunc_ap} that a map $f:A\\to B$ is $(k+1)$-truncated if and only if the action on paths\n\\begin{equation*}\n  \\apfunc{f}:(x=y)\\to(f(x)=f(y))\n\\end{equation*}\nis a $k$-truncated map, for each $x,y:A$. Moreover, in \\cref{ex:trunc_diagonal_map} we established that the fibers of the diagonal map $\\delta_f:A\\to A\\times_BA$ are equivalent to the fibers of the maps $\\apfunc{f}$, so it is also the case that $f$ is $(k+1)$-truncated if and only if the diagonal $\\delta_f$ is $k$-truncated.\n\nIn the following theorem, we add yet another equivalent characterization to the truncatedness of a map. We will use this theorem in two ways. First, a simple corollary gives a useful characterization of $k$-truncated types. Second, we will use this theorem to derive an elimination principle of the $(k+1)$-sphere that can be applied to families of $k$-types\n\n\\begin{thm}\n  Consider a map $f:A\\to B$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The map $f$ is $k$-truncated.\n  \\item The commuting square\n    \\begin{equation*}\n      \\begin{tikzcd}[column sep=large]\n        A \\arrow[r,\"f\"] \\arrow[d,swap,\"\\lam{x}\\const_x\"] & B \\arrow[d,\"\\lam{y}\\const_y\"] \\\\\n        A^{\\sphere{k+1}} \\arrow[r,swap,\"f^{\\sphere{k+1}}\"] & B^{\\sphere{k+1}}\n      \\end{tikzcd}\n    \\end{equation*}\n    is a pullback square.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  We prove the claim by induction on $k\\geq-2$. The base case is clear, because the map $A^{\\sphere{-1}}\\to B^{\\sphere{-1}}$ is a map between contractible types, hence an equivalence. Therefore the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n        A \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\n        A^{\\sphere{-1}} \\arrow[r] & B^{\\sphere{-1}}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square if and only if $A\\to B$ is an equivalence.\n\n  For the inductive step, assume that for any map $g:X\\to Y$, the map $g$ is $k$-truncated if and only if the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      X \\arrow[r] \\arrow[d] & Y \\arrow[d] \\\\\n      X^{\\sphere{k+1}} \\arrow[r] & Y^{\\sphere{k+1}}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square, and consider a map $f:A\\to B$. Then $f$ is $(k+1)$-truncated if and only if $\\apfunc{f}:(x=y)\\to(f(x)=f(y))$ is $k$-truncated for each $x,y:A$. By the inductive hypothesis this happens if and only if the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      (x=y) \\arrow[r] \\arrow[d] & (f(x)=f(y)) \\arrow[d] \\\\\n      (x=y)^{\\sphere{k+1}} \\arrow[r] & (f(x)=f(y))^{\\sphere{k+1}}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square, for each $x,y:A$. Now we observe that this is the case if and only if the square on the left in the diagram\n  \\begin{equation*}\n    \\begin{tikzcd}[column sep=small]\n      \\sm{x,y:A}x=y \\arrow[r] \\arrow[d] & \\sm{x,y:A}(f(x)=f(y)) \\arrow[d] \\arrow[r] & \\sm{x,y:B}x=y \\arrow[d] \\\\\n      \\sm{x,y:A}(x=y)^{\\sphere{k+1}} \\arrow[r] & \\sm{x,y:A}(f(x)=f(y))^{\\sphere{k+1}} \\arrow[r] & \\sm{x,y:B}(x=y)^{\\sphere{k+1}}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback square. The square on the right is a pullback square, so the square on the left is a pullback if and only if the outer rectangle is a pullback. By the universal property of $\\sphere{k+2}$ it follows that the outer rectangle is a pullback if and only if the square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[r] \\arrow[d] & B \\arrow[d] \\\\\n      A^{\\sphere{k+2}} \\arrow[r] & B^{\\sphere{k+2}}\n    \\end{tikzcd}\n  \\end{equation*}\n  is a pullback.\n\\end{proof}\n\n\\begin{thm}\\label{thm:truncated}\n  Consider a type $A$. Then the following are equivalent:\n  \\begin{enumerate}\n  \\item The type $A$ is $k$-truncated.\n  \\item The map\n    \\begin{equation*}\n      \\lam{x}\\const_x:A\\to (\\sphere{k+1}\\to A)\n    \\end{equation*}\n    is an equivalence.\n  \\end{enumerate}\n\\end{thm}\n\n\\begin{proof}\n  We prove the claim by induction on $k\\geq-2$. The base case is clear, because the map $A^{\\sphere{-1}}$ is contractible.\n\n  For the inductive step, assume that any type $X$ is $k$-truncated if and only if the map\n  \\begin{equation*}\n    \\lam{x}\\const_x:X\\to (\\sphere{k+1}\\to X)\n  \\end{equation*}\n  is an equivalence.\n  Then $A$ is $(k+1)$-truncated if and only if its identity types $x=y$ are $k$-truncated, for each $x,y:A$. By the inductive hypothesis this happens if and only if\n  \\begin{equation*}\n    (x=y)\\to (\\sphere{k+1}\\to (x=y))\n  \\end{equation*}\n  is a family of equivalences indexed by $x,y:A$. This is a family of equivalences if and only if the induced map on total spaces\n  \\begin{equation*}\n    \\Big(\\sm{x,y:A}x=y\\Big)\\to\\Big(\\sm{x,y:A}(x=y)^{\\sphere{k+1}}\\Big)\n  \\end{equation*}\n  is an equivalence. Note that we have a commuting square\n  \\begin{equation*}\n    \\begin{tikzcd}\n      A \\arrow[r] \\arrow[d] & A^{\\sphere{k+2}} \\arrow[d] \\\\\n      \\Big(\\sm{x,y:A}x=y\\Big) \\arrow[r] & \\Big(\\sm{x,y:A}(x=y)^{\\sphere{k+1}}\\Big)\n    \\end{tikzcd}\n  \\end{equation*}\n  in which both vertical maps are equivalences. Therefore the top map is an equivalence if and only if the bottom map is an equivalence, which completes the proof.\n\\end{proof}\n\n\\begin{proof}\n  Immediate from the fact that $A$ is $k$-truncated if and only if the map $A\\to\\unit$ is $k$-truncated.\n\\end{proof}\n\n\\begin{defn}\n  Consider a type $X$. A \\textbf{$k$-truncation} of $X$ consist of a $k$-type $Y$, and a map $f:X\\to Y$ satisfying the \\textbf{universal property of $k$-truncation}, that for every $k$-type $Z$ the precomposition map\n  \\begin{equation*}\n    \\blank\\circ f: (Y\\to Z)\\to (X\\to Z)\n  \\end{equation*}\n  is an equivalence.\n\\end{defn}\n\nWe define $\\trunc{k}{X}$ by the `hubs-and-spokes' method, as a higher inductive type. The idea is to force any map $\\sphere{k}{X}\\to \\trunc{k}{X}$ to be homotopic to a constant function by including enough points (the hubs) for the values of these constant functions, and enough paths (the spokes) for the homotopies to these constant functions.\n\n\\begin{defn}\n  For any type $X$ we define a type $\\trunc{k}{X}$ as a higher inductive type, with constructors\n  \\begin{align*}\n    \\eta & : X \\to \\trunc{k}{X}. \\\\\n    \\mathsf{hub} & : (\\sphere{k+1}\\to\\trunc{k}{X})\\to\\trunc{k}{X} \\\\\n    \\mathsf{spoke} & : \\prd{f:\\sphere{k+1}\\to\\trunc{k}{X}}\\prd{t:\\sphere{k+1}}f(t)=\\mathsf{hub}(f).\n  \\end{align*}\n\\end{defn}\n\n\\begin{rmk}\n  The induction principle for $\\trunc{k}{X}$ asserts that for any family $P$ of types over $\\trunc{k}{X}$, if we have a dependent function $\\alpha : \\prd{x:X}P(\\eta(x))$ and a dependent function\n  \\begin{equation*}\n    \\beta : \\prd{f:\\sphere{k+1}\\to\\trunc{k}{X}}\\Big(\\prd{t:\\sphere{k+1}}P(f(t))\\Big)\\to P(\\mathsf{hub}(f))\n  \\end{equation*}\n  equipped with an identification\n  \\begin{equation*}\n    \\gamma(f,g,t):\\tr_P(\\mathsf{spoke}(f,t),g(t))=\\beta(f,g),\n  \\end{equation*}\n  for every $f:\\sphere{k+1}\\to\\trunc{k}{X}$, $g:\\prd{t:\\sphere{k+1}}P(f(t))$, and every $t:\\sphere{k+1}$, then we obtain a dependent function\n  \\begin{equation*}\n    h:\\prd{x:\\trunc{k}{X}}P(\\eta(x))\n  \\end{equation*}\n  equipped with an identification $H(x):h(\\eta(x))=\\alpha(x)$ for any $x:X$.\n\\end{rmk}\n\n\\begin{prp}\n  For any type $X$, the type $\\trunc{k}{X}$ is $k$-truncated.\n\\end{prp}\n\n\\begin{proof}\n  By \\cref{thm:truncated} it suffices to show that the map\n  \\begin{equation*}\n    \\delta\\defeq\\lam{x}\\const_x:\\trunc{k}{X}\\to (\\sphere{k+1}\\to\\trunc{k}{X})\n  \\end{equation*}\n  is an equivalence. Note that the inverse of this map is simply the map\n  \\begin{equation*}\n    \\mathsf{hub}: (\\sphere{k+1}\\to\\trunc{k}{X})\\to \\trunc{k}{X},\n  \\end{equation*}\n  which is a section of $\\delta$ by the homotopy $\\mathsf{spoke}$. Therefore it remains to show that\n  \\begin{equation*}\n    \\mathsf{hub}(\\const_x)=x.\n  \\end{equation*}\n  for every $x:\\trunc{k}{X}$. Note that $\\mathsf{spoke}(\\const_x,\\mathsf{hub}(\\const_x))^{-1}$ is such an identification.\n\\end{proof}\n\nRecall that the $(k+1)$-sphere is $k$-connected in the following sense.\n\n\\begin{lem}\\label{lem:sphere-connected}\n  For any family $P$ of $k$-types over $\\sphere{k+1}$, the evaluation map at the base point\n  \\begin{equation*}\n    \\ev_\\ast : \\Big(\\prd{t:\\sphere{k+1}}P(t)\\Big)\\to P(\\ast)\n  \\end{equation*}\n  is an equivalence.\n\\end{lem}\n\n\\begin{thm}\n  For any family $P$ of $k$-types over $\\trunc{k}{X}$, the function\n  \\begin{equation*}\n    \\blank\\circ\\eta:\\Big(\\prd{x:\\trunc{k}{X}}P(x)\\Big)\\to\\Big(\\prd{x:X}P(\\eta(x))\\Big)\n  \\end{equation*}\n  is an equivalence.\n\\end{thm}\n\n\\begin{proof}\n  We first show that for any family $P$ of $k$-types over $\\trunc{k}{X}$, the function\n  \\begin{equation*}\n    \\blank\\circ\\eta:\\Big(\\prd{x:\\trunc{k}{X}}P(x)\\Big)\\to\\Big(\\prd{x:X}P(\\eta(x))\\Big)\n  \\end{equation*}\n  has a section. To see this, we apply the induction principle of $\\trunc{k}{X}$. For any function $\\alpha:\\prd{x:X}P(\\eta(x))$ we need to construct a function $h:\\prd{x:\\trunc{k}{X}}P(x)$ such that $h\\circ\\eta\\htpy\\alpha$, so it suffices to show that the $k$-truncatedness of the types in the family $P$ imply the existence of the terms $\\beta$ and $\\eta$ of the induction principle of $\\trunc{k}{X}$. In other words, we need to show that for every $f:\\sphere{k+1}\\to\\trunc{k}{X}$ and every $g:\\prd{t:\\sphere{k+1}}P(f(t))$ there are\n  \\begin{align*}\n    \\beta(f,g) & : P(\\mathsf{hub}(f)) \\\\\n    \\gamma(f,g) & : \\prd{t:\\sphere{k+1}}\\tr_P(\\mathsf{spoke}(f,t),g(t))=\\beta(f,g).\n  \\end{align*}\n  Since we have already shown that $\\trunc{k}{X}$ is $k$-truncated, it suffices to show the above for $f\\defeq\\const_x$, for any $x:\\trunc{k}{X}$. Now the type of $g$ is just the function type $\\sphere{k+1}\\to P(x)$, so by the truncatedness of $P(x)$ it suffices to construct\n  \\begin{align*}\n    \\beta(\\const_x,\\const_y) & : P(\\mathsf{hub}(\\const_x)) \\\\\n    \\gamma(\\const_x,\\const_y) & : \\prd{t:\\sphere{k+1}}\\tr_P(\\mathsf{spoke}(\\const_x,t),y)=\\beta(\\const_x,\\const_y)\n  \\end{align*}\n  for any $x:X$ and $y:P(x)$. Now we simply define\n  \\begin{equation*}\n    \\beta(\\const_x,\\const_y) \\defeq \\tr_P(\\mathsf{spoke}(\\const_x,\\ast),y).\n  \\end{equation*}\n  Then it remains to construct an identification\n  \\begin{equation*}\n    \\tr_P(\\mathsf{spoke}(\\const_x,t),y)=\\tr_P(\\mathsf{spoke}(\\const_x,\\ast),y)\n  \\end{equation*}\n  for any $t:\\sphere{k+1}$, but this follows at once from \\cref{lem:sphere-connected}, because the identity types of a $k$-truncated type is again $k$-truncated. This completes the proof that the precomposition function\n  \\begin{equation*}\n    \\blank\\circ\\eta:\\Big(\\prd{x:\\trunc{k}{X}}P(x)\\Big)\\to\\Big(\\prd{x:X}P(\\eta(x))\\Big)\n  \\end{equation*}\n  has a section $s$ for every family $P$ of $k$-types over $\\trunc{k}{X}$.\n\n  To show that it is an equivalence, we have to show that $s$ is also a retraction of the precomposition function $\\blank\\circ\\eta$, i.e., we have to show that\n  \\begin{equation*}\n    s(h\\circ\\eta)= h\n  \\end{equation*}\n  for any $h:\\prd{x:\\trunc{k}{X}}P(x)$. By function extensionality, it is equivalent to show that\n  \\begin{equation*}\n    \\prd{x:\\trunc{k}{X}}s(h\\circ\\eta)(x)=h(x).\n  \\end{equation*}\n  Now we observe that the type $s(h\\circ\\eta)(x)=h(x)$ is a $k$-type, and therefore we already know that the function\n  \\begin{equation*}\n    \\blank\\circ\\eta:\\Big(\\prd{x:\\trunc{k}{X}}s(h\\circ\\eta)(x)=h(x)\\Big)\\to \\Big(\\prd{x:X}s(h\\circ\\eta)(\\eta(x))=h(\\eta(x))\\Big)\n  \\end{equation*}\n  has a section. In other words, it suffices to construct a dependent function of type\n  \\begin{equation*}\n    \\prd{x:X}s(h\\circ\\eta)(\\eta(x))=h(\\eta(x)).\n  \\end{equation*}\n  Here we simply use that $s$ is a section $\\blank\\circ\\eta$, and we are done.\n\\end{proof}\n\n\\begin{cor}\\label{cor:k-type-is-reflective-subuniverse}\n  For any type $X$, the map $\\eta:X\\to\\trunc{k}{X}$ satisfies the universal property of $k$-truncation. \n\\end{cor}\n\n\\begin{comment}\n\\subsection{The join extension and connectivity theorems}\n\n\\begin{defn}\\label{defn:local}\nFor a given type $M$, a type $A$ is said to be \\define{$M$-null} if the map\n\\begin{equation*}\n\\lam{a}{m}a : A \\to (M \\to A)  \n\\end{equation*}\nis an equivalence.\n\\end{defn}\n\nIn other words, the type $A$ is $M$-null if each $f:M\\to A$ has a unique extension along the\nmap $M\\to\\unit$, as indicated in the diagram\n\\begin{equation*}\n\\begin{tikzcd}\nM \\arrow[r,\"f\"] \\arrow[d] & A \\\\\n\\unit. \\arrow[ur,densely dotted]\n\\end{tikzcd}\n\\end{equation*}\nNote that being $M$-null in the above sense is a proposition, so that the\ntype of all $M$-null types in $\\UU$ is a subuniverse of $\\UU$. \n\n\\begin{eg}\nBy \\cref{ex:sphere_null}, a type is $\\sphere{n+1}$-null precisely when it is $n$-truncated,\nfor each $n\\geq -2$ (taking the $(-1)$-sphere to be the empty type).\n\\end{eg}\n\nThe notion of $M$-connected type is in a sense dual to the notion of $M$-null types.\n\n\\begin{defn}\nA type $A$ is said to be \\define{$M$-connected} if every $M$-null\ntype is $A$-null. That is, if for every $M$-null type $B$, the map\n\\begin{equation*}\n\\lam{b}{a}{b} : B \\to (A \\to B)\n\\end{equation*}\nis an equivalence. A map is said to be \\define{$M$-connected} if its fibers are $M$-connected.\n\\end{defn}\n\nThus in particular, $M$ itself is $M$-connected, and the unit type $\\unit$ is $M$-connected for every $M$. \n\n\\begin{defn}\nLet $M$ be a type. We say that a type $X$ has the \\define{$M$-extension property}\nwith respect to a map $F:A\\to B$, if the map\n\\begin{equation*}\n\\lam{g}{a} g(F(a)) : (B\\to X)\\to (A\\to X)\n\\end{equation*}\nis $M$-null. In the case $M\\jdeq\\unit$, we say that $X$ is \\define{$F$-local}.\n\\end{defn}\n\n\\begin{lem}\\label{lem:equivalent-extension-problems}\nFor any three types $A$, $A'$ and $B$, the type $B$ is $(\\join{A}{A'})$-null\nif and only if for any any $f:A\\to B$, the type\n\\begin{equation*}\n\\sm{b:B}\\prd{a:A}f(a)=b\n\\end{equation*}\nis $A'$-null.\n\\end{lem}\n\n\\begin{proof}\nTo give $f:A\\to B$ and $(f',H):A'\\to\\sm{b:B}\\prd{a:A}f(a)=b$ is equivalent to giving a map $g:\\join{A}{A'}\\to B$. Concretely, the equivalence is given by substituting in $g:\\join{A}{A'}\\to B$ the constructors of the join, to obtain $\\pairr{g\\circ\\inl,g\\circ\\inr,\\apfunc{g}\\circ\\glue}$. \n\nNow observe that the fiber of precomposing with the unique map $!_{\\join{A}{A'}} : \\join{A}{A'}\\to\\unit$ at $g : \\join{A}{A'}\\to B$, is equivalent to\n\\begin{equation*}\n\\sm{b:B}\\prd{t:\\join{A}{A'}}g(t)=b.\n\\end{equation*}\nSimilarly, the fiber of precomposing with the unique map $!_{A'} : A'\\to\\unit$ at $\\pairr{g\\circ\\inr,\\apfunc{g}\\circ\\glue} : A'\\to\\sm{b:B}\\prd{a:A}f(a)=b$ is equivalent to\n\\begin{equation*}\n\\sm{b:B}{h:\\prd{a:A}g(\\inl(a))=b}\\prd{a':A'}\\pairr{g(\\inr(a')),\\apfunc{g}(\\glue(a,a'))}=\\pairr{b,h}.\n\\end{equation*}\nBy the universal property of the join, these types are equivalent.\n\\end{proof}\n\n\\begin{lem}\\label{lem:join-null}\nSuppose $A$ is an $M$-connected type, and that $B$ is an $(\\join{M}{N})$-null type. Then $B$ is $(\\join{A}{N})$-null.\n\\end{lem}\n\n\\begin{proof}\nLet $B$ be a $(\\join{M}{N})$-null type. Our goal of showing that $B$ is\n$(\\join{A}{N})$-null is equivalent to showing that for any $f:N\\to B$, \nthe type \n\\begin{equation*}\n\\sm{b:B}\\prd{a:A}f(a)=b\n\\end{equation*}\nis $A$-null. \nSince $B$ is assumed to be $(\\join{M}{N})$-null, we know that this type is \n$M$-null. Since $A$ is $M$-connected, this type is also $A$-null.\n\\end{proof}\n\n\\begin{lem}\\label{lem:N-extension-simple}\nLet $A$ be $M$-connected and let $B$ be $(\\join{M}{N})$-null. Then the map\n\\begin{equation*}\n\\lam{b}{a}b:B\\to B^A\n\\end{equation*}\nis $N$-null. \n\\end{lem}\n\n\\begin{proof}\nThe fiber of $\\lam{b}{a}b$ at a function $f:A\\to B$ is equivalent to the type $\\sm{b:B}\\prd{a:A}f(a)=b$. Therefore, it suffices to show that this type is $N$-null. By \\cref{lem:equivalent-extension-problems}, it is equivalent to show that $B$ is $(\\join{A}{N})$-null. This is solved in \\cref{lem:join-null}.\n\\end{proof}\n\n\\begin{thm}[Join extension theorem]\\label{thm:join-extension}\nSuppose $f:X\\to Y$ is $M$-connected, and let $P:Y\\to\\UU$ be a family of\n$(\\join{M}{N})$-null types for some type $N$. Then precomposition by $f$, i.e.\n\\begin{equation*}\n\\lam{s}s\\circ f : \\Big(\\prd{y:Y}P(y)\\Big)\\to\\Big(\\prd{x:X}P(f(x))\\Big),\n\\end{equation*}\nis an $N$-null map.\n\\end{thm}\n\n\\begin{proof}\nLet $g:\\prd{x:X}P(f(x))$. Then we have the equivalences\n\\begin{align*}\n\\hfib{(\\blank\\circ f)}{g} \n& \\eqvsym \\sm{s:\\prd{y:Y}P(y)}\\prd{x:X}s(f(x))=g(x) \\\\\n& \\eqvsym \\sm{s:\\prd{y:Y}P(y)}\\prd{y:Y}{(x,p):\\hfib{f}{y}} s(y)= \\trans{p}{g(x)} \\\\\n& \\eqvsym \\prd{y:Y}\\sm{z:P(y)}\\prd{(x,p):\\hfib{f}{y}} \\trans{p}{g(x)}=z \\\\\n& \\eqvsym \\prd{y:Y}\\hfib{\\lam{z}{(x,p)}z}{\\lam{(x,p)}\\trans{p}{g(x)}}.\n\\end{align*}\nTherefore, it suffices to show for every $y:Y$, that $P(y)$ has the $N$-extension property with respect to the unique map of type $\\hfib{f}{y}\\to\\unit$. This is a special case of \\cref{lem:N-extension-simple}.\n\\end{proof}\n\n\\begin{thm}\\label{thm:simple-join}\nSuppose $X$ is an $M$-connected type and $Y$ is an $N$-connected type. Then $\\join{X}{Y}$ is an $(\\join{M}{N})$-connected type.\n\\end{thm}\n\n\\begin{proof}\nIt suffices to show that any $(\\join{M}{N})$-null type is $(\\join{X}{Y})$-null.\nLet $Z$ be an $(\\join{M}{N})$-null type.\nSince $Z$ is assumed to be $(\\join{M}{N})$-null, it follows by \\cref{lem:join-null} that $Z$ is $(\\join{X}{N})$-null. By symmetry of the join, it also follows that $Z$ is $(\\join{X}{Y})$-null.\n\\end{proof}\n\n\\begin{thm}[Join connectivity theorem]\\label{thm:join-connectivity}\nConsider an $M$-connected map $f:A\\to X$ and an $N$-connected map $g:B\\to X$. Then $\\join{f}{g}$ is $(\\join{M}{N})$-connected.\n\\end{thm}\n\n\\begin{proof}\nThis follows from \\cref{thm:simple-join} and \\cref{defn:join-fiber}.\n\\end{proof}\n\n\\begin{thm}\\label{thm:joinconstruction-connectivity}\nConsider the factorization\n\\begin{equation*}\n\\begin{tikzcd}\nA_n \\arrow[dr,swap,\"f^{\\ast n}\"] \\arrow[r,\"q_n\"] & \\im(f) \\arrow[d] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nof $f^{\\ast n}$ through the image $\\im(f)$. \nThen the map $q_n$ is $(n-2)$-connected, for each $n:\\N$.\n\\end{thm}\n\n\\begin{proof}\nWe first show the assertion that, given a commuting diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[r,\"q\"] \\arrow[dr,swap,\"f\"] & Y \\arrow[d,\"m\"] & A' \\arrow[l,swap,\"{q'}\"] \\arrow[dl,\"{f'}\"] \\\\\n& X\n\\end{tikzcd}\n\\end{equation*}\nin which $m$ is an embedding, then $\\join{f}{f'}=\\join{(m\\circ q)}{(m\\circ q')}=m\\circ (\\join{q}{q'})$.\nIn other words, postcomposition with embeddings distributes over \nthe join operation.\n\nNote that, since $m$ is assumed to be an embedding, we have an equivalence of\ntype $\\eqv{f(a)=f'(a)}{q(a)=q'(a)}$, for every $a:A$. Hence the pullback of\n$f$ and $f'$ is equivalent to the pullback of $q$ along $q'$. Consequently, the\ntwo pushouts\n\\begin{equation*}\n\\begin{tikzcd}\nA\\times_X A' \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & A' \\arrow[d] \\\\\nA \\arrow[r] & \\join[X]{A}{A'}\n\\end{tikzcd}\n\\qquad\\text{and}\\qquad\n\\begin{tikzcd}\nA\\times_Y A' \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & A' \\arrow[d] \\\\\nA \\arrow[r] & \\join[Y]{A}{A'}\n\\end{tikzcd}\n\\end{equation*}\nare equivalent. Hence the claim follows.\n\nAs a corollary, we get that $q_n=q_f^{\\ast n}$. Note that $q_f$ is surjective,\nin the sense that $q_f$ is $\\bool$-connected, where $\\bool$ is the type of booleans%\n\\footnote{Recall that the $\\bool$-null types are precisely the mere propositions.}.\nHence it follows that $q_n$ is $\\bool^{\\ast n}$-connected. \n\nNow recall that the $n$-th join power of $\\bool$ is the $(n-1)$-sphere $\\Sn^{n-1}$, and that\na type is $(\\Sn^{n-1})$-connected if and only if it is $(n-2)$-connected.\n\\end{proof}\n\\end{comment}\n\n\\begin{comment}\n\\subsection{The construction of the $n$-truncation}\\label{sec:truncation}\n\nOur goal in this section is to prove the following theorem. Its proof will take up the entire section.\n\n\\begin{thm}\\label{thm:truncation}\nFor every $k\\geq -2$, there is a $k$-truncation operation\n\\begin{equation*}\n\\trunc{k}{\\blank} : \\UU\\to\\UU\n\\end{equation*}\nequipped with a fiberwise transformation\n\\begin{equation*}\n\\tproj{k}{\\blank}:\\prd{X:\\UU}X\\to\\trunc{k}{X},\n\\end{equation*}\nsuch that for each $X:\\UU$ the type $\\trunc{k}{X}$ is a $k$-type satisfying the (dependent) universal property of $k$-truncation.\n\\end{thm}\n\nWe will define the $k$-truncation operation by induction on $k\\geq-2$,\nwith the trivial operation as the base case. For $k\\geq -2$, suppose we have\na $k$-truncation operation as described in the statement of the theorem.\n\n\\cref{thm:trunc_id} suggests that we can think of the type $\\trunc{k+1}{X}$ is as the quotient of $X$ modulo the\n`$(k+1)$-equivalence relation' given by $\\trunc{k}{a=b}$. \n\n\\begin{defn}\nWe define the reflexive relation $I_k(A) : A \\to (A \\to \\UU)$ by\n\\begin{equation*}\nI_k(A)(a,b) \\defeq \\trunc{k}{a=b},\n\\end{equation*}\nand then we define\n\\begin{align*}\n\\trunc{k+1}{A} & \\defeq \\im(I_k(A)) \\\\\n\\tproj{k+1}{\\blank} & \\defeq q_{I_k(A)},\n\\end{align*}\nwhere $q_{I_k(A)}:A\\to \\im(I_k(A))$ is the map with which the image comes equipped.\n\\end{defn}\n\nNote that the codomain $(A\\to\\UU)$ of $I_k(A)$ is locally small since it is the exponent of\nthe locally small type $\\UU$ by a small type $A$. \nTherefore the image of $I_k(A)$ is essentially small by \\cref{thm:replacement}.\nSince we want the $(k+1)$-truncation to be an operation $\\UU\\to\\UU$, it would be more precise to define $\\trunc{k+1}{A}$ as the (unique) type in $\\UU$ that is equivalent to $\\im(I_k(A))$. Of course, this makes no substantial difference.\n\n\\begin{lem}\\label{lem:modal_contr}\nFor every $a,b:A$, we have an equivalence\n\\begin{equation*}\n\\eqv{(I_k(A)(a)=I_k(A)(b))}{\\trunc{k}{a=b}}.\n\\end{equation*}\n\\end{lem}\n\n\\begin{proof}\nSince $\\im(I_k(A))$ is a subtype of $\\UU^A$, there is for any $b:A$ a `tautological' family $E_b$ of types over $\\im(I_k(A))$, given by\n\\begin{equation*}\nE_b(P) \\defeq P(b).\n\\end{equation*}\nNote that $E_b(I_k(A)(a))\\jdeq \\trunc{k}{a=b}$. Therefore we can prove the claim by showing that the canonical map\n\\begin{equation*}\n\\prd{P:\\im(I_k(A))} (I_k(A)(b)=P)\\to P(b)\n\\end{equation*}\nis a fiberwise equivalence. By \\cref{thm:id_fundamental} it suffices to show that for each $b:A$, the total space\n\\begin{equation*}\n\\sm{P:\\im(I_k(A))}P(b)\n\\end{equation*}\nis contractible. \n\nFor the center of contraction we take the pair\n$\\pairr{I_k(A)(b),\\tproj{k}{\\refl{b}}}$.\nFor the contraction we construct a term of type\n\\begin{equation*}\n\\prd{P:\\im(I_k(A))}{y:P(b)} \\pairr{I_k(A)(b),\\tproj{k}{\\refl{b}}}=\\pairr{P,y}.\n\\end{equation*}\nSince $I_k(A)(b,a)\\jdeq\\trunc{k}{b=a}$, it is equivalent to construct a term of type\n\\begin{equation*}\n\\prd{P:\\im(I_k(A))}{y:P(b)}\\sm{\\alpha:\\prd{a:A} \\eqv{\\trunc{k}{b=a}}{P(a)}} \\alpha_b(\\tproj{k}{\\refl{b}})=y.\n\\end{equation*}\nLet $P:\\im(I_k(A))$ and $y:P(b)$. Then $P(a)$ is $n$-truncated for any $a:A$. Therefore, to construct a map\n$\\alpha(P,y)_a:\\trunc{k}{b=a}\\to P(a)$, it suffices to construct a map of type $(b=a)\\to P(a)$. This may be done by\npath induction, using $y:P(b)$. Since it follows that $\\alpha(P,y)_b(\\tproj{k}{\\refl{b}})=y$, it only remains to show that each $\\alpha(P,y)_a$ is an equivalence.  \n\nNote that the type of those $P:\\im(I_k(A))$ such that for all $y:P(b)$ and all $a:A$ the map $\\alpha(P,y)_a$ is an equivalence, is a subtype of $\\im(I_k(A))$, we may use the universal property of the image of $I_k(A)$: it suffices to lift\n\\begin{equation*}\n\\begin{tikzcd}\n& \\sm{P:\\im(I_k(A))}\\prd{y:P(b)}{a:A}\\isequiv(\\alpha(P,y)_a) \\arrow[d] \\\\\nA \\arrow[ur,densely dotted] \\arrow[r,swap,\"I_k(A)\"] & \\im(I_k(A)).\n\\end{tikzcd}\n\\end{equation*}\nIn other words, it suffices to show that \n\\begin{equation*}\n\\prd{x:A}{y:I_k(A)(x,b)}{a:A}\\isequiv(\\alpha(I_k(A)(x),y)_a).\n\\end{equation*}\nThus, we want to show that for any $y:\\trunc{k}{x=b}$, the map $\\trunc{k}{a=b}\\to\\trunc{k}{x=b}$ constructed above is an equivalence.\nSince the fibers of this map are $n$-truncated, and $\\iscontr(X)$ of an $n$-truncated type $X$ is always $n$-truncated, we may assume that $y$ is of the form $\\tproj{k}{p}$ for $p:x=b$. \nNow it is easy to see that our map of type $\\trunc{k}{b=a}\\to\\trunc{k}{x=a}$ is the unique map which\nextends the path concatenation $\\ct{p}{\\blank}$, as indicated in the diagram\n\\begin{equation*}\n\\begin{tikzcd}[column sep=8em]\n(b=a) \\arrow[r,\"\\ct{p}{\\blank}\"] \\arrow[d] & (x=a) \\arrow[d] \\\\\n\\trunc{k}{b=a} \\arrow[r,densely dotted,swap,\"{\\alpha(I_k(A)(x),y)_a}\"] & \\trunc{k}{x=a}.\n\\end{tikzcd}\n\\end{equation*}\nSince the top map is an equivalence, it follows that the map $\\alpha(I_k(A)(x),y)_a$ is an equivalence.\n\\end{proof}\n\n\\begin{cor}\\label{cor:truncated}\nThe image $\\im(I_k(A))$ is an $(n+1)$-truncated type. \n\\end{cor}\n\n\n\\begin{proof}[Construction]\nWe will show that $\\trunc{n+1}{A}$ is indeed $(n+1)$-truncated in \\cref{cor:truncated} of \\cref{lem:modal_contr} below. Once this fact is established, it remains to verify the dependent universal property of $(n+1)$-truncation.\nBy the join extension theorem \\cref{thm:join-extension} (using $N\\defeq \\emptyt$), it suffices to show that the map $\\tproj{n+1}{\\blank}:A\\to\\trunc{n+1}{A}$ is $\\sphere{n+2}$-connected. Note that $\\tproj{n+1}{\\blank}$ is surjective, so the claim that $\\tproj{n+1}{\\blank}$ is $\\sphere{n+2}$-connected follows from \\cref{lem:ap_connectivity}, where we show that for any surjective map $f:A\\to X$, if the action on paths is $M$-connected for any two points in $A$, then $f$ is $\\susp(M)$-connected. To apply this lemma, we also need to know that $\\tproj{k}{\\blank}:A\\to\\trunc{k}{A}$ is $\\sphere{n+1}$-connected. This is shown in Corollary 7.5.8 of \\cite{hottbook}.\n\\end{proof}\n\n\nBefore we are able to show that for any surjective map $f:A\\to X$, if the action on paths is $M$-connected for any two points in $A$, then $f$ is $\\susp(M)$-connected, we show that a type is $\\susp(M)$-connected precisely when its identity types are $M$-connected.\n\n\\begin{lem}\\label{lem:local_id}\nLet $M$ be a type. Then a type $X$ is $(\\join{\\bool}{M})$-null\nif and only if all of its identity types are $M$-null. \n\\end{lem}\n\n\\begin{proof}\nThe map\n\\begin{equation*}\n\\lam{p}{m}p : (x=y)\\to (M\\to (x=y))\n\\end{equation*}\nis an equivalence if and only if the induced map on total spaces\n\\begin{equation*}\n\\lam{\\pairr{x,y,p}}\\pairr{x,y,\\lam{m}p} : \\Big(\\sm{x,y:X}x=y\\Big)\\to\\Big(\\sm{x,y:X}M\\to (x=y)\\Big)\n\\end{equation*}\nis an equivalence. \nSince the map $\\lam{x}\\pairr{x,x,\\refl{x}}:X\\to\\sm{x,y:X}x=y$ is an equivalence,\nthe above map is an equivalence if and only if the map\n\\begin{equation*}\n\\lam{x}\\pairr{x,x,\\lam{m}\\refl{x}} : X\\to\\Big(\\sm{x,y:X}M\\to (x=y)\\Big)\n\\end{equation*}\nis an equivalence. For every $x:X$, the triple $\\pairr{x,x,\\lam{m}\\refl{x}}$\ninduces a map $\\susp(M)\\to X$. By uniqueness of the universal property,\nit follows that this map is the constant map $\\lam{m}x$.\nThus we see that $\\lam{x}\\pairr{x,x,\\lam{m}\\refl{x}}$ is an equivalence if\nand only if the map\n\\begin{equation*}\n\\lam{x}{m}x : X \\to (\\susp(M)\\to X)\n\\end{equation*}\nis an equivalence. \n\\end{proof}\n\n\\begin{lem}\\label{lem:ap_connectivity}\nSuppose $f:A\\to X$ is a surjective map, with the property that for every\n$a,b:A$, the map\n\\begin{equation*}\n\\mapfunc{f}(a,b):(a=b)\\to (f(a)=f(b))\n\\end{equation*}\nis $M$-connected. Then $f$ is $\\susp(M)$-connected. \n\\end{lem}\n\n\\begin{proof}\nWe have to show that $\\fib{f}{x}$ is $\\susp(M)$-connected for each $x:X$. \nSince this is a mere proposition, and we assume that $f$ is surjective, it\nis equivalent to show that $\\fib{f}{f(a)}$ is $\\susp(M)$-connected for each $a:A$. \nLet $Y$ be a $\\susp(M)$-null type. \nFor every $g:\\fib{f}{f(a)}\\to Y$ be a map we have the point $\\theta(g)\\defeq g(a,\\refl{f(a)})$ in $Y$,\nso we obtain a map\n\\begin{equation*}\n\\theta : (\\fib{f}{f(a)}\\to Y)\\to Y\n\\end{equation*}\nIt is clear that $\\theta(\\lam{\\pairr{b,p}}y)=y$, so it remains to show that\nfor every $g:\\fib{f}{f(a)}\\to Y$ we have $\\lam{\\pairr{b,p}}\\theta(g)=g$.\nThat is, we must show that\n\\begin{equation*}\n\\prd{b:A}{p:f(a)=f(b)} g(a,\\refl{f(a)})=g(b,p).\n\\end{equation*}\nUsing the assumption that $Y$ is $\\susp(M)$-connected, it follows from\n\\cref{lem:local_id} that the type $g(a,\\refl{f(a)})=g(b,p)$ is $M$-connected,\nfor every $b:A$ and $p:f(a)=f(b)$.\nTherefore it follows, since the map $\\mapfunc{f}(a,b):(a=b)\\to(f(a)=f(b))$ is connected, that our goal is equivalent to\n\\begin{equation*}\n\\prd{b:A}{p:a=b} g(a,\\refl{f(a)})=g(b,\\mapfunc{f}(a,b,p)).\n\\end{equation*}\nThis follows by path induction. \n\\end{proof}\n\\end{comment}\n\n\\subsection{Theorems not to forget}\n\n\\begin{thm}\n  Consider a type $X$ and a family $P$ of $(k+n)$-truncated types over $\\trunc{k}{X}$. Then the precomposition map\n  \\begin{equation*}\n    \\blank\\circ\\eta : \\Big(\\prd{y:\\trunc{k}{X}}P(y)\\Big)\\to\\Big(\\prd{x:X}P(\\eta(x))\\Big)\n  \\end{equation*}\n  is $(n-2)$-truncated.\n\\end{thm}\n\n\\begin{exercises}\n\\exercise Consider an equivalence relation $R:A\\to (A\\to\\prop)$. Show that the map $\\tproj{0}{\\blank}\\circ \\inl:A\\to \\trunc{0}{A\\sqcup^{R} A}$ satisfies the universal property of the quotient $A/R$, where $A\\sqcup^{R} A$ is the canonical pushout\n\\begin{equation*}\n\\begin{tikzcd}\n\\sm{x,y:A}R(x,y) \\arrow[r,\"\\pi_2\"] \\arrow[d,swap,\"\\pi_1\"] & A \\arrow[d,\"\\inr\"] \\\\\nA \\arrow[r,swap,\"\\inl\"] & A\\sqcup^{R} A.\n\\end{tikzcd}\n\\end{equation*}\n\\exercise Consider the trivial relation $\\unit\\defeq\\lam{x}{y}\\unit:A\\to (A\\to\\prop)$. Show that the set quotient $A/\\unit$ is a proposition satisfying the universal property of the propositional truncation.\n\\exercise Show that the type of pointed $2$-element sets\n\\begin{equation*}\n\\sm{X:\\UU_{\\bool}}X\n\\end{equation*}\nis contractible.\n\\exercise Define the type $\\mathbb{F}$ of finite sets by\n\\begin{equation*}\n\\mathbb{F}\\defeq \\im(\\fin),\n\\end{equation*}\nwhere $\\fin:\\N\\to\\UU$ is defined in \\cref{defn:fin}. \n\\begin{subexenum}\n\\item Show that $\\eqv{\\mathbb{F}}{\\sm{n:\\N}\\UU_{\\fin(n)}}$. \n\\item Show that $\\mathbb{F}$ is closed under $\\Sigma$ and $\\Pi$. \n\\end{subexenum}\n\\exercise\n\\begin{subexenum}\n\\item A type $Y$ is called \\define{$k$-separated} if for every type $X$ the map\n  \\begin{equation*}\n    (\\trunc{k}{X}\\to Y)\\to(X\\to Y)\n  \\end{equation*}\n  is an embedding. Show that $Y$ is $k$-separated  if and only if it is $(k+1)$-truncated.\n\\item A type $Y$ is called \\define{$n$-fold $k$-separated} if for every type $X$ the map\n  \\begin{equation*}\n    (\\trunc{k}{X}\\to Y)\\to (X\\to Y)\n  \\end{equation*}\n  is $(n-2)$-truncated. Show that $Y$ is $n$-fold $k$-separated if and only if it is $(k+n)$-truncated.\n\\end{subexenum}\n\\exercise Consider a map $f:A\\to B$. Show that the square\n\\begin{equation*}\n  \\begin{tikzcd}[column sep=large]\n    A \\arrow[r,\"f\"] \\arrow[d,swap,\"\\lam{x}\\const_x\"] & B \\arrow[d,\"\\lam{y}\\const_y\"] \\\\\n    A^{\\sphere{k+1}} \\arrow[r,swap,\"f^{\\sphere{k+1}}\"] & B^{\\sphere{k+1}}\n  \\end{tikzcd}\n\\end{equation*}\nis a pullback square if and only if its gap map has a section.\n\\exercise Consider a map $f:X\\to Y$ into a $k$-truncated type $Y$. Show that the following are equivalent:\n\\begin{enumerate}\n\\item For any family $P$ of $k$-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\\item For any family $P$ of $k$-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  has a section.\n\\end{enumerate}\n\\exercise Show that for each type $X$, the map\n\\begin{equation*}\n  \\trunc{k+1}{X}\\to\\UU^X\n\\end{equation*}\ngiven by $y\\mapsto\\lam{x}(y=\\eta'(x))$ is an embedding.\n\\end{exercises}\n", "meta": {"hexsha": "23abfb17a6644af47d83e461a8fefaf1c50e5162", "size": 52088, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/truncation.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/truncation.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/truncation.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.0166503428, "max_line_length": 771, "alphanum_fraction": 0.6641260943, "num_tokens": 18674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6102143865394505}}
{"text": "\\section{Trees}\n\n\\frame{\n{Part 3: Trees}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-4}]\n}\n\n\n\\begin{frame}{Trees and Connectivity}\n\n  {\\larger\n    \\begin{itemize}\n    \\item \\structure{Trees} are connected Graphs with \\alert{no cycles}.\n    \\item Every tree 1-edge connectivity, 1-vertex connectivity.\n    \\item Chromatic Number = 2 (trees can always be bi-colored)\n\n      \\bigskip\n\n    \\item Trees come up all the time:\n      \\begin{columns}\n        \\column{0.5\\textwidth}\n        \\begin{itemize}\n        \\item Family Trees;\n        \\item Search Trees;\n        \\item Game Trees;\n        \\item Parse Trees;\n        \\end{itemize}\n        \\column{0.5\\textwidth}\n        \\begin{itemize}\n        \\item Spanning Trees;\n        \\item Rooted Trees;\n        \\item Ordered Trees;\n        \\item Binary Trees;\n        \\item etc...\n        \\end{itemize}\n      \\end{columns}\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}{Trees and Connectivity}\n\n  {\\larger\n    \\begin{itemize}\n    \\item \\structure{Cut Edge}: An edge is a cut edge if\n      removing it makes two vertices disconnected.\n\n      \\bigskip\n\n    \\item {\\bf Lemma:} An edge is not a cut edge if it is on a\n      cycle.\n\n      \\bigskip\n\n    \\item A tree is a \\structure{connected graph} where\n      \\structure{every edge is a cut edge}\n\n      \\bigskip\n\n    \\item This implies that a tree is a connected graph which\n      is {\\bf\\structure{Edge Minimal}}\n      \\begin{itemize}\n      \\item A tree has the minimum number of edges necessary to\n        connect a set of vertices.\n      \\end{itemize}\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Tree Coloring}\n\n  {\\larger\n    \\begin{itemize}\n    \\item A tree is a graph with a \\structure{unique path}\n      between every pair of vertices.\n\n    \\item As a consequence, $\\chi(\\text{tree}) = 2$\n\n    \\item {\\bf Constructive Demonstration}\n\n      \\begin{columns}\n        \\column{0.7\\textwidth}\n        \\begin{itemize}\n        \\item Pick any node in the tree to be the {\\bf root}, color\n          it ``blue''.\n        \\item Color nodes ``odd'' length from the root as ``red''\n        \\item Color nodes ``even'' length from the root as ``blue''\n        \\item This is the algorithm for 2-coloring on general graphs\n        \\end{itemize}\n        \\column{0.3\\textwidth}\n\n        \\begin{tikzpicture}[scale=.8,auto,swap]\n          %\\tikzset{edge/.style = {->,>=latex'}}\n          \\node[blue vertex] (a) at (1,0) {};\n          \\node[red vertex] (a1) at (0,1) {};\n          \\node[red vertex] (b1) at (1,1) {};\n          \\node[blue vertex] (a2) at (0,2) {};\n          \\node[blue vertex] (b2) at (1,2) {};\n          \\node[blue vertex] (c2) at (2,2) {};\n          \\node[red vertex] (a3) at (0,3) {};\n          \\node[red vertex] (b3) at (1,3) {};\n          \\node[red vertex] (c3) at (2,3) {};\n          \\node[red vertex] (d3) at (3,3) {};\n          \\draw[edge] (a) to (a1);\n          \\draw[edge] (a) to (b1);\n          \\draw[edge] (a1) to (a2);\n          \\draw[edge] (a1) to (b2);\n          \\draw[edge] (b1) to (c2);\n          \\draw[edge] (b2) to (a3);\n          \\draw[edge] (b2) to (b3);\n          \\draw[edge] (b2) to (c3);\n          \\draw[edge] (c2) to (d3);\n\n        \\end{tikzpicture}\n      \\end{columns}\n\n    \\end{itemize}\n\n\n\n  }\n\\end{frame}\n\n\\subsection{Spanning Trees}\n\n\\begin{frame}\n  \\frametitle{Spanning Trees}\n\n  {\\larger\n\n    \\begin{itemize}\n    \\item A \\structure{Spanning Subgraph} of G is a subgraph of\n      $G$ that has all vertices of $G$ (and some of the edges).\n    \\item A \\structure{Spanning Tree} of G is a spanning graph of\n      $G$ that is also a tree.\n    \\end{itemize}\n\n    \\begin{center}\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (0,1) {};\n        \\node[vertex] (a1) at (1,0) {};\n        \\node[vertex] (b1) at (1,1) {};\n        \\node[vertex] (a2) at (2,0) {};\n        \\node[vertex] (b2) at (2,1) {};\n        \\node[vertex] (c2) at (2,2) {};\n        \\node[vertex] (a3) at (3,0) {};\n        \\node[vertex] (b3) at (3,1) {};\n        \\node[vertex] (c3) at (3,2) {};\n        \\node[vertex] (d3) at (2,3) {};\n        \\draw[red edge] (a) to (a1);\n        \\draw[red edge] (a) to (b1);\n        \\draw[red edge] (a1) to (a2);\n        \\draw[red edge] (a1) to (b2);\n        \\draw[red edge] (b1) to (c2);\n        \\draw[red edge] (b2) to (a3);\n        \\draw[red edge] (b2) to (b3);\n        \\draw[red edge] (b2) to (c3);\n        \\draw[edge] (c2) to (d3);\n        \\draw[edge] (a) to (d3);\n        \\draw[edge] (b1) to (d3);\n        \\draw[edge] (a1) to (b1);\n        \\draw[red edge] (b1) to (b2);\n        \\draw[edge] (b2) to (a2);\n        \\draw[edge] (b2) to (c2);\n        \\draw[red edge] (a2) to (a3);\n        \\draw[red edge] (c2) to (c3);\n        \\draw[edge] (a3) to (b3);\n        \\draw[edge] (c3) to (d3);\n        \\draw[edge] (b3) to (c3);\n      \\end{tikzpicture}\n    \\end{center}\n\n    \\begin{itemize}\n    \\item One graph can have multiple spanning trees.\n    \\item Every connected graph has a spanning tree.\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Weighted Spanning Trees}\n\n  {\\larger\n\n    The Spanning Tree problem becomes more interesting when we consider\n    \\structure{weighted edges}.\n\n    \\begin{center}\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (3,5) {};\n        \\node[vertex] (b) at (0,3) {};\n        \\node[vertex] (c) at (3,3) {};\n        \\node[vertex] (d) at (6,3) {};\n        \\node[vertex] (e) at (2,1) {};\n        \\node[vertex] (f) at (4,1) {};\n        \\draw[edge] (a) -- node[weight] {$3$} (b);\n        \\draw[edge] (a) -- node[weight] {$4$} (d);\n        \\draw[edge] (b) -- node[weight] {$4$} (c);\n        \\draw[edge] (c) -- node[weight] {$1$} (d);\n        \\draw[edge] (b) -- node[weight] {$6$} (e);\n        \\draw[edge] (c) -- node[weight] {$9$} (e);\n        \\draw[edge] (c) -- node[weight] {$7$} (f);\n        \\draw[edge] (d) -- node[weight] {$2$} (f);\n        \\draw[edge] (e) -- node[weight] {$1$} (f);\n      \\end{tikzpicture}\n    \\end{center}\n\n    What is the \\structure{minimal cost} structure that\n    allows me to connect everything?\n\n  }\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Minimum Spanning Tree Algorithm}\n\n  {\\larger\n    \\begin{center}\n      \\begin{tikzpicture}[scale=.8,auto,swap]\n        %\\tikzset{edge/.style = {->,>=latex'}}\n        \\node[vertex] (a) at (3,5) {};\n        \\node[vertex] (b) at (0,3) {};\n        \\node[vertex] (c) at (3,3) {};\n        \\node[vertex] (d) at (6,3) {};\n        \\node[vertex] (e) at (2,1) {};\n        \\node[vertex] (f) at (4,1) {};\n        \\draw[black edge] (a) -- node[weight] {$3$} (b);\n        \\draw[edge] (a) -- node[weight] {$4$} (d);\n        \\draw[black edge] (b) -- node[weight] {$4$} (c);\n        \\draw[black edge] (c) -- node[weight] {$1$} (d);\n        \\draw[edge] (b) -- node[weight] {$6$} (e);\n        \\draw[edge] (c) -- node[weight] {$9$} (e);\n        \\draw[edge] (c) -- node[weight] {$7$} (f);\n        \\draw[black edge] (d) -- node[weight] {$2$} (f);\n        \\draw[black edge] (e) -- node[weight] {$1$} (f);\n      \\end{tikzpicture}\n    \\end{center}\n\n    \\begin{enumerate}\n    \\item Start with one arbitrary vertex and add it to the MST.\n    \\item From all edges connected with the MST, select one with minimum weight;\n    \\item Add the edge, and vertex, to the MST;\n    \\item Return to (2)\n    \\end{enumerate}\n  }\n\\end{frame}\n", "meta": {"hexsha": "0dea8bbde314c4132bd7e32a4383b3791e3912d5", "size": 7418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week05/03_Trees.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/03_Trees.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/03_Trees.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": 29.5537848606, "max_line_length": 83, "alphanum_fraction": 0.5295227824, "num_tokens": 2493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6101656920234464}}
{"text": "\\subsection{Centrality}\n  Another important measure is the network centrality. Intuitively, a network that resembles a mesh is preferable over a\n  network with a central hub that acts as an intermediary between all other pairs of nodes. This is because in the latter case\n  Trust Is Risk does not offer any realistic improvement over the existing centralized marketplaces model (e.g. ebay).\n  Nevertheless, the expected indirect trust measure is not always able to distinguish between the two. We thus propose here\n  some different measures to that end.\n  \n  \\subsubsection{Degree Centrality} \\ \\\\\n\n    One possible approach is the degree centrality \\cite{freeman}, that can be broken down as in-degree and out-degree\n    centrality. We first define the node in-degree centrality.\n    \\begin{align*}\n      C^d_{in}\\left(A\\right) = \\sum\\limits_{B \\in \\mathcal{V} \\setminus \\{A\\}}DTr_{B \\rightarrow A}\\footnotemark && \\mbox{\n      (Node in-degree centrality)}\n    \\end{align*}\n    \\footnotetext{Maybe indirect trust is more intuitive here than direct trust.}\n    Let $A^*$ be the player with the maximum centrality: $A^* = \\argmax\\limits_{A \\in \\mathcal{V}}C^d_{in}\\left(A\\right)$. The\n    network in-degree centrality is defined as:\n    \\begin{align*}\n      C^d_{in} = \\sum\\limits_{A \\in \\mathcal{V}}\\left(C^d_{in}\\left(A^*\\right) - C^d_{in}\\left(A\\right)\\right) && \\mbox{\n      (Network in-degree centrality)}\n    \\end{align*}\n    Similarly, for the out-degree centrality we have:\n    \\addtocounter{footnote}{-1}\n    \\begin{align*}\n      C^d_{out}\\left(A\\right) = \\sum\\limits_{B \\in \\mathcal{V} \\setminus \\{A\\}}DTr_{A \\rightarrow B}\\footnotemark && \\mbox{\n      (Node out-degree centrality)}\n    \\end{align*}\n    Let $A^* = \\argmax\\limits_{A \\in \\mathcal{V}}C^d_{out}\\left(A\\right)$. The network out-degree centrality is:\n    \\begin{align*}\n      C^d_{out} = \\sum\\limits_{A \\in \\mathcal{V}}\\left(C^d_{out}\\left(A^*\\right) - C^d_{out}\\left(A\\right)\\right) && \\mbox{\n      (Network out-degree centrality)}\n    \\end{align*}\n\n    A problem of these centrality measures is that their unit is the currency used (i.e. Bitcoin) and thus may not always have\n    an intuitive meaning. We would thus like to have a measure of \\textit{centralization} that has no units and can take\n    values in the interval $\\left[0,1\\right]$, with 0 corresponding to a network of no centralization (all nodes are equal,\n    e.g.  cycle) and 1 to a network with the maximum centralization possible (there is one central vital node for all, e.g.\n    star). A centralization measure that achieves this target is proposed in \\cite{freeman}. Here we use the following\n    modified form. For a graph $\\mathcal{G}$, the in- and out-centralization are defined as:\n    \\begin{align*}\n      Cn^d_{in} &= \\frac{C^d_{in}}{\\max C^d_{in}} && \\mbox{ (in-degree centralization)} \\\\\n      Cn^d_{out} &= \\frac{C^d_{out}}{\\max C^d_{out}} && \\mbox{ (out-degree centralization)} \\enspace,\n    \\end{align*}\n    where $\\max C^d_{in}$ is defined as the maximum in-degree centrality over all networks with the same number of nodes for\n    which the maximum direct\\footnote{Maybe indirect trust is more intuitive here than direct trust.} trust is equal to the\n    maximum \\addtocounter{footnote}{-1}direct\\footnotemark \\ trust of $\\mathcal{G}$; $\\max C^d_{out}$ is defined equivalently.\n\n  \\subsubsection{maxFlow Centrality} \\ \\\\\n\n    An alternative measure of centrality for a player $A \\in \\mathcal{V}$ of a network $\\mathcal{G}$ can be defined as the\n    impact that the removal of $A$ would have on the indirect trust between the rest of the players. More specifically, let\n    $\\mathcal{G}' = \\mathcal{G} \\setminus \\{A\\}$. Then it is:\n    \\begin{align*}\n      C^{mF}\\left(A\\right) = \\sum\\limits_{B,C \\in \\mathcal{V}'}\\left(Tr_{\\mathcal{G}, B \\rightarrow C} - Tr_{\\mathcal{G}', B\n      \\rightarrow C}\\right) && \\mbox{ (Node maxFlow centrality)} \\enspace.\n    \\end{align*}\n    We can now follow the same steps as previously for the relevant network definitions. Let $A^* = \\argmax\\limits_{A \\in\n    \\mathcal{V}}C^{mF}\\left(A\\right)$. Then the network maxFlow centrality is:\n    \\begin{align*}\n      C^{mF} = \\sum\\limits_{A \\in \\mathcal{V}}\\left(C^{mF}\\left(A^*\\right) - C^{mF}\\left(A\\right)\\right) && \\mbox{ (Network\n      maxFlow centrality)}\n    \\end{align*}\n    and the centralization:\n    \\begin{align*}\n      Cn^{mF} = \\frac{C^{mF}}{\\max C^{mF}} && \\mbox{ (Network maxFlow centralization)} \\enspace,\n    \\end{align*}\n    where $\\max C^{mF}$ is the maximum centrality over all networks with the same number of nodes for which the maximum\n    direct\\footnote{Maybe indirect trust is more intuitive here than direct trust.} trust is equal to the maximum\n    \\addtocounter{footnote}{-1} direct\\footnotemark \\ trust of $\\mathcal{G}$.\n", "meta": {"hexsha": "d729bc4d833f712ff12ac1af0e30306e4c9a047c", "size": 4785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/networkhealth/centrality.tex", "max_stars_repo_name": "OrfeasLitos/TrustNet", "max_stars_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-03-15T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T14:07:45.000Z", "max_issues_repo_path": "may31deliverable/networkhealth/centrality.tex", "max_issues_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_issues_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-03-07T12:25:26.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-31T14:42:20.000Z", "max_forks_repo_path": "may31deliverable/networkhealth/centrality.tex", "max_forks_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_forks_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-03-07T10:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-28T06:32:33.000Z", "avg_line_length": 67.3943661972, "max_line_length": 126, "alphanum_fraction": 0.6898641588, "num_tokens": 1443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6101656901189111}}
{"text": "\\chapter{Omitted proofs}\n\\section{Precision bounds for $+,-,\\times$}\\label{sec:proof-precision}\n\nWe first formulate an assumption on the rounding operation $\\round()$. In this section, $M$ and $\\epsilon$ are positive real constants.\n\\begin{assum}\nThe rounding of a value $x$ has a relative error of at most $\\epsilon$. Therefore, if $|x| \\leq M^d$, as we will always assume of a $d$-dimensional value, then\n\\[|\\round(x)-x| \\leq M^d\\epsilon\\]\n\\end{assum}\n\nTo give a solid formalism to our notions of $d$-dimensional values and ``computed in $n$ operations'', we introduce the following recursive definition.\n\\begin{mydef}\\label{def:valid-computation}\nA quadruplets $(x,x',d,n)$ is a \\emph{valid computation} if $|x| \\leq M^d$ and one of these holds:\n\\begin{enumerate}[label={(\\alph*)}]\n\\item $x = x'$, $n=0$;\n\\item $(a,a',d_a,n_a)$ and $(b,b',d_b,n_b)$ are valid computations, $n = n_a+n_b+1$ and either:\n    \\begin{enumerate}[label={(\\roman*)}]\n    \\item $d=d_a=d_b$, $x=a+b$, $x'=\\round(a'+b')$ and $|a'+b'| \\leq M^d$;\n    \\item $d=d_a=d_b$, $x=a-b$, $x'=\\round(a'-b')$ and $|a'-b'| \\leq M^d$;\n    \\item $d=d_a+d_b$, $x=ab$, $x'=\\round(a'b')$ and $|a'b'| \\leq M^d$.\n    \\end{enumerate}\n\\end{enumerate}\n\\end{mydef}\n\nNote that valid computations are strongly limited by the assumptions we place on the magnitude of the results, both theoretical and actual.\n\n{\n    \\newcommand{\\f}[1]{(1+\\epsilon)^{#1}-1}\n    \\newcommand{\\mdfn}[2]{M^{#1}\\left(\\f{#2}\\right)}\n\n    \\begin{thm}\\label{thm:precision}\n    If $(x,x',d,n)$ is a valid computation, then \\[|x'-x| \\leq \\mdfn{d}{n}.\\]\n    \\end{thm}\n\n    We will prove the theorem by induction on the structure of valid computations. We will separate the proof into two lemmas: first addition and subtraction together in Lemma~\\ref{lemma:precision-add}, then multiplication in Lemma~\\ref{lemma:precision-mult}.\n\n    \\begin{lemma}\\label{lemma:fplusf}\n    Let $f(x) = \\f{x}$. If $a,b>0$, then $f(a) + f(b) \\leq f(a+b)$.\n    \\end{lemma}\n    \\begin{proof}\n    Clearly, $f$ is convex. From convexity we find\n    \\begin{align*}\n    f(a) &\\leq \\frac{b}{a+b}\\,f(0) + \\frac{a}{a+b}\\,f(a+b)\\\\\n    f(b) &\\leq \\frac{a}{a+b}\\,f(0) + \\frac{b}{a+b}\\,f(a+b).\\\\\n    \\end{align*}\n    Therefore, $f(a) + f(b) \\leq f(0) + f(a+b) = f(a+b)$.\n    \\end{proof}\n\n    \\begin{lemma}[addition and subtraction]\\label{lemma:precision-add}\n    Let operator $\\ast$ be either $+$ or $-$.\n    If $(a,a',d,n_a)$ and $(b,b',d,n_b)$ are two valid computations for which Theorem~\\ref{thm:precision} holds and $(a\\ast b,\\round(a'\\ast b'),d,n_a+n_b+1)$ is a valid computation, then Theorem~\\ref{thm:precision} holds for it as well.\n    \\end{lemma}\n    \\begin{proof}\n    From the hypotheses know that\n    \\begin{align*}\n    |a'-a| &\\leq \\mdfn{d}{n_a}\\\\\n    |b'-b| &\\leq \\mdfn{d}{n_b}\\\\\n    |a' \\ast b'| &\\leq M^d.\n    \\end{align*}\n    We find\n    \\begin{align*}\n    |\\round(a'&\\ast b') - (a \\ast b)| \\\\\n    &= |(\\round(a'\\ast b') - (a'\\ast b')) + ((a'\\ast b') - (a\\ast b))| \\\\\n    &\\leq |\\round(a'\\ast b') - (a'\\ast b')| + |(a'-a) \\ast (b'-b)| \\\\\n    &\\leq M^d\\epsilon + |a'-a| + |b'-b| \\\\\n    &\\leq M^d\\epsilon + \\mdfn{d}{n_a} + \\mdfn{d}{n_b} \\\\\n    &= M^d\\left[f(1) + f(n_a) + f(n_b)\\right] \\\\\n    &\\leq M^d\\,f(n_a+n_b+1)\\\\\n    &= \\mdfn{d}{n_a+n_b+1}\n    \\end{align*}\n    where the step before last follows from two applications of Lemma~\\ref{lemma:fplusf}.\n    \\end{proof}\n    \n    \\begin{lemma}[multiplication]\\label{lemma:precision-mult}\n    If $(a,a',d_a,n_a)$ and $(b,b',d_b,n_b)$ are two valid computations for which Theorem~\\ref{thm:precision} holds and $(ab,\\round(a'b'),d_a+d_b,n_a+n_b+1)$ is a valid computation, then Theorem~\\ref{thm:precision} holds for it as well.\n    \\end{lemma}\n    \\begin{proof}\n    From the hypotheses we know that\n    \\begin{align*}\n    |a| &\\leq M^d\\\\\n    |b| &\\leq M^d\\\\\n    |a'-a| &\\leq \\mdfn{d_a}{n_a}\\\\\n    |b'-b| &\\leq \\mdfn{d_a}{n_b}\\\\\n    |a'b'| &\\leq M^{d_a+d_b}.\n    \\end{align*}\n    We find\n    \\begin{align*}\n    |\\round(&a'b') - ab)|\\\\\n    =\\ &|(\\round(a'b') - a'b') + (a'b'-ab)|\\\\\n    \\leq\\ &|\\round(a'b') - a'b'| + |(a'-a)b + (b'-b)a + (a'-a)(b'-b)|\\\\\n    \\leq\\ &M^{d_a+d_b}\\epsilon + |a'-a||b| + |b'-b||a| + |a'-a||b'-b|\\\\\n    \\leq\\ &M^{d_a+d_b}\\epsilon + \\mdfn{d_a}{n_a}M^{d_b} + \\mdfn{d_b}{n_b}M^{d_a}\\\\\n    &\\qquad + \\mdfn{d_a}{n_a}\\mdfn{d_b}{n_b}\\\\\n    =\\ &M^{d_a+d_b}\\big[\\epsilon + \\left(\\f{n_a}\\right) + \\left(\\f{n_b}\\right)\\\\\n    &\\qquad + \\left(\\f{n_a}\\right)\\left(\\f{n_b}\\right)\\big]\\\\\n    =\\ &M^{d_a+d_b}\\left[\\epsilon + \\f{n_a+n_b}\\right]\\\\\n    =\\ &M^{d_a+d_b}\\left[f(1) + f(n_a+n_b)\\right]\\\\\n    \\leq\\ &M^{d_a+d_b}\\,f(n_a+n_b+1)\\\\\n    =\\ &\\mdfn{d_a+d_b}{n_a+n_b+1}\n    \\end{align*}\n    where the step before last follows from Lemma~\\ref{lemma:fplusf}.\n    \\end{proof}\n    \n    \\begin{proof}[Proof of Theorem~\\ref{thm:precision}]\n    By induction on the recursive structure of valid computations (see Definition~\\ref{def:valid-computation}). Case (a) is trivial because $|x'-x| = 0$. For case (b), the inductive step for (i) and (ii) follows from Lemma~\\ref{lemma:precision-add} while that of (iii) follows from Lemma~\\ref{lemma:precision-mult}.\n    \\end{proof}\n}\n", "meta": {"hexsha": "a3be42d3d86a1ce6e08cda1df00733d166c02fec", "size": 5123, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/proofs.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/proofs.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/proofs.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": 47.8785046729, "max_line_length": 315, "alphanum_fraction": 0.5908647277, "num_tokens": 1974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6101656818211534}}
{"text": "\n\\chapter{Background}\n\\label{chap:background}\n\nMonte Carlo codes are vital tools in a diverse number of fields. Based\nin simple random number generators, these tools harness the power of\nstatistics to predict and describe a wide variety of behaviors. In\nnuclear engineering, there is a long history of Monte Carlo methods\nused to simulate neutral particle propagation. These methods enjoy a\nwide variety of applications within the field, from fuel cell\ndevelopment to full core analysis. A vital part of the simulation is\nthe propagation and interaction of neutral particles, neutrons. In\nthis chapter we will describe the history and mathematics of these\nneutral particle propagation methods.\n\n\\section{The Monte Carlo Method}\n\\label{sec:monte_carlo}\n\nThe history of Monte Carlo methods begins with nuclear science and\nengineering. Nicholas Metropolis and S. Ulam~\\cite{metropolis1949} at\nLos Alamos National Laboratory developed the method to support the\nManhattan Project. Today, Monte Carlo methods have found diverse\napplications across the hard and social sciences. In nuclear\nengineering, we still use Monte Carlo for its original purpose, the\npropagation of neutral particles. Now, its use has expanded from\nweapons research to assessing the viability and properties of nuclear\nreactors.\n\nWhen used for particle transport, the Monte Carlo method uses a random\nnumber generator to simulate a particle's history. As the simulation\nruns, various parameters are calculated and recorded. This will continue\nfor a finite number of histories, $N$, after which the mean value of\nthe parameters of interest are calculated:\n\\begin{equation*}\n  \\bar{x} = \\frac{1}{N}\\sum_{n=1}^Nx_n\\:,\n\\end{equation*}\nwhere $x_n$ is the value from the $n$-th history\\cite{lewis1993}. The process\nfor sampling will be described in general here, and then extended to\nparticle propagation methods in Sec.~\\ref{sec:propagation}.\n\nAs described by Lewis and Miller~\\cite{lewis1993}, we first must\nconsider a random variable, $x$. We define the probability that $x$\nwill have a value between $a$ and $b$: $P\\{a \\leq x \\leq b\\}$. We\nare interested in the probability that our random variable will have one\nspecific value. Therefore, we define the probability that our variable\nwill fall within a differential distance to a given value $x$ in the\nlimit that the differential distance goes to zero. This is the\n\\gls{pdf}, the probability that $x'$ will be between $x$ and $x +\n\\Delta x$:\n\\begin{equation}\n  \\label{eq:pdf_initial}\n f(x)\\Delta x = \\lim_{\\Delta x \\to 0}  P \\{ x \\leq x' \\leq x + \\Delta x \\}\\:.\n\\end{equation}\nIntegrating the \\gls{pdf} gives the overall probability for the range:\n\\begin{equation}\n\\label{pdf}\n  \\int_a^bf(x)dx = P\\{a \\leq x \\leq b\\}\\:.\n\\end{equation}\nIf we integrate the \\gls{pdf} over the entire range of possible values\nof $x$, it must equal unity; there is a 100\\% chance that its value is\nin the range. Therefore, we must normalize the \\gls{pdf}:\n\\begin{equation*}\n  \\int_{-\\infty}^{\\infty}f(x)dx = 1, \\quad x \\in (-\\infty,\\infty)\\:.\n\\end{equation*}\nWe then may define a \\gls{cdf}:\n\\begin{equation}\n  \\label{eq:cdf}\n  F(x) = P \\{ x' \\leq x\\} = \\int_{-\\infty}^xf(x')dx'\\:.\n\\end{equation}\nIn the limit where $x \\to \\infty$, $F(x) \\to 1$ and as\n$x \\to -\\infty$, $F(x) \\to 0$ from the normalization of the\n\\gls{pdf}. The \\gls{cdf} is uniformly distributed from zero to\nunity~\\cite{lewis1993}, with each value corresponding to a single\nvalue of $x$. We therefore have a means to generate values of $x$\nusing a random number generator uniformly distributed from zero\nunity. To do so, we set:\n\\begin{equation*}\n  F(x) = \\xi\\:,\n\\end{equation*}\nwhere $\\xi \\in [0,1)$ is a random number. For each random number\nsampled, we sample a single value of $x$. This is determined by\ninverting the \\gls{cdf}:\n\\begin{equation}\n  \\label{eq:inverted_cdf}\n  F^{-1}(\\xi) = x\\:.\n\\end{equation}\nWe now have a direct way of using a random number generator to\ngenerate a randomly distributed variable $x$. We will now apply this\nto particle propagation. There are methods available when the\n\\gls{cdf} is not invertible. Each \\gls{cdf} used for particle\npropagation is invertible, so these methods are outside the scope of\ndiscussion.\n% you may want to mention that there are many sampling techniques \n% for when the CDF is not invertible and that those are outside the \n% scope of this discussion.\n\n\\section{Particle Propagation Methods}\n\\label{sec:propagation}\n\nAs a particle moves through a medium, multiple forces and events will\naffect its trajectory. We will consider neutral elementary particles,\nneutrons, so that the effects of gravitational and electromagnetic\nforces are negligible. It is therefore a good assumption that a neutron\nwill travel in a straight line until a physical collision with another\nparticle. Despite the large number of neutrons present in our\nsimulation, we will ignore improbable collisions between neutrons\nthemselves. Neutron collisions with atoms result in an array of\neffects, including absorption and scattering. The relative probability\nof a collision occurring and the resulting type of collision are\ndependent on the atom that the neutron collides with and the energy of the\nneutron. Modeling the propagation of neutrons is accomplished through\na variety of algorithms, some of which we describe in this section.\n\n\\subsection{Ray Tracing}\n\\label{sec:ray_tracing}\n\nThe basic algorithm for simulating particle transport using Monte Carlo is\nray tracing. This method follows a particle from collision to\ncollision, assuming that it travels in a straight, statistically-sampled \npath. Material properties determine the distance between\ncollisions, and therefore material boundaries must be considered explicitly.\n\nParticles propagating through a material have an interaction\nprobability characterized by the material's experimentally-determined\ntotal cross section, a function of position and the incident neutron\nenergy, $\\Sigma_t(\\mathbf{r}, E)$. The probability of an interaction\noccurring in a differential distance $ds$ is related to the\nmacroscopic cross-section:\n\\begin{equation}\n  \\label{eq:macroscopic}\n  \\frac{dP}{ds} = \\Sigma_t(\\mathbf{r}, E)\\:.\n\\end{equation}\nWe assume that each interaction will remove the neutron from the\nincident flux, as it is absorbed or deflected out of the original path\nin position, energy, or both.  The medium therefore attenuates\nan incident mono-energetic neutron flux $\\phi_0$ as a function of\ndistance:\n\\begin{equation}\n  \\label{eq:attenuation}\n  \\phi(s) = \\phi_0 e^{-s\\Sigma_t(\\mathbf{r})}\\:.\n  % I don't think you defined \\phi_{0}\n% It was defined just before the equation, should I make it more\n% explicit? -jsr\n\\end{equation}\nThe probability that a neutron has its first interaction in\ndifferential distance $ds$ after\ntraveling a distance $s$ is found by dividing the flux at that\nposition $\\phi(s)$ by the total flux:\n\\begin{equation}\n  \\label{eq:PDFfunct}\n  f(s)ds = \\frac{\\phi(s)}{\\int_0^\\infty\\phi(s)ds}ds\\:.\n\\end{equation}\nThe basis of Eq.~\\eqref{eq:PDFfunct} is clarified by an example: if\nthe flux after a distance $s$ is half the total flux, then half of the\nneutrons have undergone an interaction.\n\nWe consider the cross-section in a single material region, where we\nassume that the material is homogeneous. In this case, the\ncross-section is no longer a function of position.  Using\nEqs.~\\eqref{eq:attenuation} and \\eqref{eq:PDFfunct}, and assuming that\nthe total cross-section is constant over $\\mathbf{r}$\\cite{lux1991}:\n\\begin{equation}\n  \\label{eq:PDF}\n  f(s)ds = \\Sigma_te^{-s\\Sigma_t}ds\\:.\n\\end{equation}\nThis is the \\gls{pdf} of the distance\ntraveled before the first collision, $s$. As the distance a neutron travels\nincreases, the value of $f(s)$ decreases; it is less probable that a\nneutron will travel further without collision. The \\gls{pdf} gives us the\nprobability at a point $s$ that a neutron undergoes a collision\nexactly there; integrating over the distance $s$ provides us the\nprobability that a neutron undergoes a collision between 0 and $s$. This\nis the \\gls{cdf}:\n\\begin{equation}\n  \\label{eq:cdf}\n  F(s) = \\int_0^s f(s')ds' = 1-e^{-s\\Sigma_t}\\:.\n\\end{equation}\nAs expected, increasing $s$ causes the probability of any interaction,\n$F(s)$, to approach unity. Plots illustrating the behavior of the\n\\gls{pdf} and \\gls{cdf} are shown in Fig.~\\ref{fig:cdf_pdf}.\n\\begin{figure}[hbt]\n  \\centering\n  \\includegraphics[scale=0.75]{images/cdf_pdf}\n  \\caption{Plots of the \\acrshort{cdf} and \\acrshort{pdf} for collision probability per distance travelled $s$.}\n  \\label{fig:cdf_pdf}\n\\end{figure}\n\nAs the \\gls{cdf} ranges from zero to unity, we can sample its value by\na uniformly distributed random variable $\\xi \\in [0,1)$. The distance\n\na function of this sampled random variable:\n\\begin{align*}\n  F(s) = 1 - e^{-s\\Sigma_t} &= \\xi \\:,\\\\\n  \\ln(e^{-s \\Sigma_t}) &= \\ln(1-\\xi)\\:, \\\\\n  -\\Sigma_t s &= \\ln(\\xi) \\:,\\\\\n  s(\\xi) &= \\frac{1}{\\Sigma_t}\\ln(\\xi)\\:.\n\\end{align*}\n\nAfter sampling the path length of the neutron, its position is\nupdated based on its original position and direction. We assumed that\nthe cross-section $\\Sigma_t$ was constant in a material region, so the\nsampled path length is only valid as long as the neutron remains in\nthat region.  If the neutron reaches the boundary between two material\nregions, a new path length must be sampled using the cross-section of\nthe region it is entering. Each time a path length is sampled, the\ndistance to the nearest boundary in the direction of motion is\ndetermined, and the neutron is moved to the boundary and path length\nis resampled if appropriate. This can become computationally expensive\nin complicated geometries and when the probability of crossing\nboundaries with each sample path length is high.\n\n\\section{Woodcock Delta-tracking}\n\\label{sec:delta-tracking}\n\nAs discussed in Section~\\ref{sec:ray_tracing}, the value of $\\Sigma_t$\nat a given position depends on the material at that point. Therefore,\n$\\Sigma_t(\\vec{r})$ is a piece-wise discontinuous function that varies\narbitrarily with position and the geometry of the\nproblem~\\cite{leppanen2013}. Using the ray tracing method, neutrons\nmust stop at boundaries to sample a new path length in a new material\nregion. To avoid the computational inefficiency that arises in\ngeometrically-complicated regions, a rejection sampling technique\nknown as Woodcock delta-tracking was developed~\\cite{woodcock1965}.\n\nWoodcock delta-tracking introduces the concept of the majorant\ncross-section, chosen to be the maximum of all material total\ncross-sections in the region of interest:\n\\begin{equation}\n  \\label{eq:majorant}\n  \\Sigma_\\mathrm{maj} \\equiv \\max_{\\mathbf{r} \\in \\mathbb{V}}\\{\\Sigma_t(\\mathbf{r})\\}\\:,\n\\end{equation}\nwhere $\\mathbb{V}$ is the volume of interest. The majorant concept is shown in a\none-dimensional region in Fig.~\\ref{fig:sigma_maj}.\n\\begin{figure}[hbt]\n  \\centering\n  \\includegraphics[scale=0.75]{images/sigma_maj}\n  \\caption{Total cross-section as a function of position in one\n    dimension. The majorant cross-section is the largest value in the\n    region of interest and determines the probability of a real collision.}\n  \\label{fig:sigma_maj}\n\\end{figure}\n% should y axis be \\Sigma_{t} for clarity? Updated -jsr\n\nThe majorant\ncross-section can also be represented as the summation of the total\ncross-section and a delta cross-section:\n\\begin{equation}\n  \\label{eq:majorant2}\n  \\Sigma_\\mathrm{maj} = \\Sigma_\\delta(\\mathbf{r}) +\n  \\Sigma_t(\\mathbf{r}), \\quad\\forall \\vec{r} \\in \\mathbb{V}\\:.\n\\end{equation}\nFollowing from the definition of $\\Sigma_\\mathrm{maj}$ in\nEq.~\\eqref{eq:majorant}, the function $\\Sigma_\\delta(\\mathbf{r})$ is\nchosen such that $\\Sigma_\\mathrm{maj}$ is constant for the entire\nregion of interest. At the position \\textbf{r} where the maximum value\nof $\\Sigma_t(\\mathbf{r})$ occurs, the delta cross-section is zero.\n\nThe majorant cross-section is constant throughout the entire region of\ninterest, so we can treat it as a single material. Following the same derivation in\nSection~\\ref{sec:ray_tracing}, the \\gls{pdf} of the first collision occurring after\n$s$ in the region of interest using the majorant cross-section is given by:\n\\begin{align}\n f_{\\mathrm{maj}}(s) &= \\Sigma_{\\mathrm{maj}}e^{-\\Sigma_{\\mathrm{maj}}s}\\\\\n& = (\\Sigma_{\\delta}(\\mathbf{r}) + \\Sigma_{t}(\\mathbf{r}))e^{-\\Sigma_{\\mathrm{maj}}s}\\:.\n  \\label{eq:majorantpdf}\n\\end{align}\n\nIn most of the region of interest, the majorant cross-section is not\nthe real cross-section. To accurately preserve physics, we must use a technique called rejection\nsampling to simulate sampling the real $\\Sigma_t(\\vec{r})$ while\nactually sampling using $\\Sigma_\\mathrm{maj}$. \n\n\\subsubsection{Rejection Sampling}\n\\label{sec:rejection_sampling}\nAs described by Lux and\nKoblinger~\\cite{lux1991}, rejection sampling requires a \\gls{pdf} of\ninterest, $f(x)$, and a second \\gls{pdf} $g(x)$ for which:\n\\begin{equation}\n  \\label{eq:Mleq}\n  f(x) \\leq M\\cdot g(x), \\quad \\forall x\\:,\n\\end{equation} where $M \\in \\mathbb{R}$ is a constant.\nSampling from $M\\cdot g(x)$ and accepting these samples with probability:\n\\begin{equation}\n  \\label{eq:preal}\n  P = \\frac{f(x)}{M\\cdot g(x)}\n\\end{equation}\nreplicates sampling directly from $f(x)$. \n\nFor example, consider a\n\\gls{pdf} of interest $f(x) = x^2$ on the interval $x \\in (0,1]$ as shown\nin Fig.~\\ref{fig:circle_square}.\n\\begin{figure}[hbt]\n  \\centering\n  \\includegraphics[scale=0.75]{images/circle}\n  \\caption{Example \\acrshort{pdf} function $f(x) = x^2$.}\n  \\label{fig:circle_square}\n\\end{figure}\nAs described in the previous section, we could sample $f(x)$ using the\n$F(x)$ found by integrating and then inverting. Instead, we can sample from a\ndifferent \\gls{pdf} that is always majorant of $f(x)$, as defined in\nEq.~\\eqref{eq:Mleq}. We can choose $g(x) = M = 1$, as $f(x) \\leq 1$ on\nthe interval of interest. The \\gls{cdf} of $g(x)$ is easy to\ndetermine, because it is a constant value, and is just $G(x) =\nx$. Therefore, we can sample $g(x)$ by simply sampling a random value $\\xi\n\\in (0,1]$ and taking this as the value of $x$. To replicate sampling\nfrom $f(x)$, we then sample another random value $\\xi_2 \\in (0,1]$ and\naccept our value of $x$ using the probability defined in Eq.~\\eqref{eq:preal}:\n\\begin{equation*}\n  \\xi_2 \\leq \\frac{f(x)}{M \\cdot g(x)} = x^2\\:.\n\\end{equation*}\n% may what to mention that M=1 in this case?\n\\begin{minipage}{1.0\\linewidth}\nThe following Matlab script replicates this procedure and generates\nthe histogram shown in Fig.~\\ref{fig:pdf_histogram}.\n\\begin{lstlisting}\na = [];                     % Accepted samples\nfor i = 1:1000\n    x = rand;               % Sample g(x)\n    y = rand;               % Gen random number xi2\n    if y <= x.^2            % If xi2 <= f(x)/g(x)\n        a(end+1) = x;       % Accept sample\n    end\nend\n\\end{lstlisting}\n\\end{minipage}\nAs expected, the procedure has reproduced the desired \\gls{pdf} of\n$f(x) = x^2$. Although this requires sampling two random variables, it\ncan be advantageous if $F(x)$ is difficult or impossible to invert.\n\\begin{figure}[hbtp]\n  \\centering\n  \\includegraphics[scale=0.75]{images/pdf_histogram}\n  \\caption{Histogram of results from sampling and applying the\n    rejection sampling algorithm.}\n  \\label{fig:pdf_histogram}\n\\end{figure}\n\\subsubsection{Application to Delta-tracking}\n\\label{sec:application_to_delta-tracking}\n\nAs we saw in Fig.~\\ref{fig:sigma_maj}, the total cross-section\n$\\Sigma_t$ is a piecewise discontinuous function that depends on the\ngeometry of our problem. Therefore, each region has a different\n\\gls{cdf} for sampling path length, and described in\nSection~\\ref{sec:ray_tracing}. Using rejection sampling, we can sample\nthe real collision \\gls{pdf}, using a different, simpler \\gls{pdf}.\nIn Woodcock delta tracking, the second \\gls{pdf}, $g(x)$, is chosen to\nbe the majorant \\gls{pdf}, Eq.~\\eqref{eq:majorantpdf}. This is\nbeneficial because the majorant cross-section is constant over the\nentire region.\n\nThese functions are both maximized at $x=0$, where the inequality of\nEq.~\\eqref{eq:Mleq} is satisfied by setting $M=1$:\n\\begin{equation}\n  \\label{eq:cseq}\n  \\Sigma_t(\\mathbf{r}) \\leq \\Sigma_\\mathrm{maj}(\\mathbf{r}), \\forall\n  \\mathbf{r} \\in \\mathbb{V} \\:.\n\\end{equation}\nWe sample path length using the constant majorant\ncross-section:\n\\begin{equation}\n  \\label{eq:majorantsample}\n  s_\\mathrm{maj}(\\xi) = -\\frac{1}{\\Sigma_\\mathrm{maj}}\\ln(\\xi)\\:,\n\\end{equation}\nwhich samples the \\gls{pdf} defined in Eq.\\eqref{eq:majorantpdf}.\n% don't need to repeat equation; I think you mean this eqref?\n% Can you clarify this comment? -jsr\nWe can see that this \\gls{pdf} is the sum of two different ones: one\nrepresenting actual collisions based on the real total cross-section\n$\\Sigma_t$ and one representing the non-physical collisions based on\n$\\Sigma_\\delta$. We call these non-physical collisions ``virtual''\ncollisions, and these should be eliminated by our rejection\nsampling. To apply rejection sampling, we therefore pick the \\gls{pdf}\nwe want to sample, $f(x)$, and the \\gls{pdf} we will actually sample,\n$g(x)$, as such:\n\\begin{align*}\n  f(x) &= \\Sigma_t(\\vec{r})e^{-\\Sigma_\\mathrm{maj}s} \\:,\\\\\n  g(x) &= \\Sigma_\\mathrm{maj}e^{-\\Sigma_\\mathrm{maj}s}\\:.\n\\end{align*}\nThe equation $g(x)$ is always majorant to $f(x)$, by the definition of\n$\\Sigma_{\\mathrm{maj}}$, so we set $M=1$. We will therefore accept samples with the\nprobability given in Eq.~\\eqref{eq:preal}:\n\\begin{align}\n  \\label{eq:prealfinal}\n  P_{\\mathrm{real}}(\\vec{r}) &= \\frac{f(x)}{M \\cdot g(x)} =\n      \\frac{\\Sigma_t(\\mathbf{r})e^{-\\Sigma_\\mathrm{maj}s}}{\\Sigma_\\mathrm{maj}e^{-\\Sigma_\\mathrm{maj}s}}\n  = \\frac{\\Sigma_t(\\mathbf{r})}{\\Sigma_\\mathrm{maj}}\\:.\n\\end{align}\n% what's M?\nWe will refer to this as the probability of a ``real'' collision,\n$P_\\mathrm{real}$, to differentiate these physical collisions from the\nnon-physical virtual collisions. It is important to note that the\nprobability is independent of path length $s$, but is dependent on\nposition $\\vec{r}$. At each collision, the material region at the\nneutron position must be determined, but we do not need to explicitly\ntrack boundaries nor calculate their distance each time a path length\nis sampled. The algorithm for delta-tracking is shown in\nFig.~\\ref{fig:dt}.\n\n\\begin{figure}[p]\n  \\centering\n  \\begin{algorithm}[H]\n\\caption{Delta-tracking}\\label{alg:dt}\n\\begin{algorithmic}[1]\n  \\State \\textbf{Sample} path length\n\n  \\State \\textbf{Look up} location to get $\\Sigma_t(\\vec{r})$\n  \\State $P_\\mathrm{real} \\gets\n  \\frac{\\Sigma_t(\\vec{r})}{\\Sigma_\\mathrm{maj}}$\n  \\State \\textbf{Sample} random number $\\xi \\in [0,1)$\n  \\If{$\\xi < P_\\mathrm{real}$} \\Comment{Collision is real}\n  \\State \\textbf{Execute} real collision\n    \\Else \\Comment{Collision is virtual}\n    \\State \\textbf{Execute} virtual collision\n  \\EndIf\n\\end{algorithmic}\n\\end{algorithm}\n\\includegraphics[scale=0.5]{images/dt}\n  \\caption{Delta-tracking algorithm and flow chart.}\n  \\label{fig:dt}\n\\end{figure}\n\nNow, the path length can be sampled across multiple material regions\nof varying $\\Sigma_t$ without explicitly stopping the neutron at a\ngiven boundary. This allows us to avoid determining the distance to\nthe nearest boundary after each path length sampling. Delta-tracking\nis also much more efficient in regions where the geometry is complex\nor material region thicknesses are on the same order as the path\nlength. % I'd add a sentence about why this is important--make us see that this is a thing it is\n% a good idea to choose sometimes; the imbalance in talking about the negative\n% properties leaves me wondering why anyone would choose it.\nThis method can become computationally inefficient in\nregions where the total cross-section is much less than the majorant\ncross-section, leading to oversampling of virtual collisions. This is\nseen in geometries that include localized absorbers, such as control\nrods.\n\n% Another downside is that the \\gls{tle} for\n% flux cannot be used. \n% % Apparently this isn't true. I didn't get the details, but this came up for Kelly at M&C\n% % Check with her to see if she found the reference about it. \n% The \\gls{tle} requires calculating the track-lengths\n% within a particular material cell, and therefore does not work when\n% the neutron path length can cross one or more material\n% boundaries. The \\gls{cfe} can be used in its\n% place, but often results in inferior statistics as not every track\n% length sampled ends in a collision~\\cite{leppanen2013}.\n% % May want to elaborate on all of this, but it'll likely change\n% given previous comment. \n%\n% I commented it out, I'll email Jaakko about his paper, which I use\n% as a reference for it. - JSR\n\n\\section{The Serpent 2 Monte Carlo Code}\n\\label{sec:serpent2}\n\nThe Serpent Monte Carlo code was developed at \\gls{vtt} as a PhD\nthesis project~\\cite{leppanen2007}. A second iteration of the code,\nSerpent 2, is currently under development. Both versions of Serpent use a combination of surface tracking, Woodcock\ndelta-tracking, and rejection sampling for non-uniform density\ndistributions. Serpent 2 selects between surface tracking and\ndelta-tracking by examining the ratio of total cross-section to\nmajorant cross-section~\\cite{leppanen2010}. In regions where many\nvirtual collisions would occur, the code preferentially switches to\nray tracing. This is to avoid the computational inefficiency of\nprocessing virtual collisions that provide no statistics. This\nselection is determined by a constant $c$ and the inequality in\nEq.~\\eqref{eq:s2deltasurface}.\n\\begin{equation}\n  \\label{eq:s2deltasurface}\n  \\frac{\\Sigma_t(\\vec{r})}{\\Sigma_\\mathrm{maj}} > 1 - c\n\\end{equation}\n\nIf this inequality is true, delta-tracking is used, otherwise\nray-tracing (referred to as surface-tracking in Serpent 2) is used. By\ndefault, the value of $c$ is 0.9, as this was determined to produce\nthe best improvement in run time~\\cite{leppanen2010}. We note that\nthis inequality is identical to the value of $P_\\mathrm{real}$. Prior to\nsampling path length, the code tests this ratio for the current\nneutron position and determines if surface tracking or delta-tracking\nshould be used. If delta-tracking is used, the code then determines if\nthe collision is virtual or real. The value of $c$ can be set in the\ninput file using \\verb|set dt|.\n% \\begin{figure}[hbtp]\\centering\n%   \\begin{tikzpicture}[scale=1.5]\n%     \\draw[thick] (0,0) -- (10.0,0);\n%     \\foreach \\x in {0,1,...,10}\n%     {\n%       \\draw (\\x, 0.1) -- (\\x, -0.1);\n%       \\pgfmathsetmacro\\result{\\x * 0.1}\n%       \\node [below] at (\\x, -0.2) {\\small $\\pgfmathprintnumber{\\result}$};\n%     }\n%     \\node [left] at (0,0) {$P_{\\mathrm{real}}$};\n%     \\draw[ thick, <->] (0,0.2) -- (1,0.2);\n%     \\draw[ thick, <->] (1,0.2) -- (10,0.2);\n%     \\node [above] at (0.5, 0.2) {Ray Tracing};\n%     \\node [above] at (5.5, 0.2) {Delta-tracking};\n%   \\end{tikzpicture}\n%   \\caption{Ray-tracing and delta-tracking threshold values in\n%     standard Serpent 2.}\n%   \\label{fig:ray_wdt_normal}\n% \\end{figure}\n% Not sure that this is really illustrating anything.\n\n% \\subsubsection{Nonuniform Density Distributions}\n% \\label{sec:nonuniform}\n\n% Rejection sampling can also be used when the total cross-section is\n% not constant within a material region. As discussed by\n% Lepp\\\"{a}nen~\\cite{leppanen2013}, Serpent 2 conducts a rejection\n% sampling routine similar to Woodcock delta-tracking in these\n% regions. Instead of sampling from a majorant cross-section across\n% multiple materials, a maximum cross-section for the single material\n% region is used. Unlike delta-tracking, this requires stopping the\n% neutron at boundaries and resampling path lengths. This algorithm is\n% not modified by the implementation of \\gls{wdt} and none of the input\n% files used to assess \\gls{wdt} use this feature.\n% Wait, maybe I missed something, but I don't know what's going on this section / paragraph.\n%\n% This is extraneous and outside the scope of this. Not even sure why\n% I put it in here. -JSR\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../masters_report\"\n%%% End:\n", "meta": {"hexsha": "9e165bd32992d1c1731afe6b2669fe25e9f8882a", "size": 24058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/background.tex", "max_stars_repo_name": "jsrehak/jsr_masters", "max_stars_repo_head_hexsha": "1e7861f4ee2016c770847da496c525e0cc5cf17c", "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": "include/background.tex", "max_issues_repo_name": "jsrehak/jsr_masters", "max_issues_repo_head_hexsha": "1e7861f4ee2016c770847da496c525e0cc5cf17c", "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": "include/background.tex", "max_forks_repo_name": "jsrehak/jsr_masters", "max_forks_repo_head_hexsha": "1e7861f4ee2016c770847da496c525e0cc5cf17c", "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.8247619048, "max_line_length": 115, "alphanum_fraction": 0.7434117549, "num_tokens": 6775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303137346444, "lm_q2_score": 0.7718434925908524, "lm_q1q2_score": 0.6101656783518903}}
{"text": "\\documentclass[english]{../thermomemo/thermomemo}\n\n\\usepackage{amsmath, amsthm, amssymb}\n\\usepackage[english]{babel}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{mathtools}\n\\usepackage[utf8]{inputenc}\n\\usepackage{pgf}\n\\usepackage{tikz}\n\\usepackage{url}\n\\usepackage{enumerate}\n\\usepackage[font=small,labelfont=bf]{caption}\n\n\\usepackage{xcolor}\n\\hypersetup{\n  colorlinks,\n  linkcolor={red!50!black},\n  citecolor={blue!50!black},\n  urlcolor={blue!80!black}\n}\n\n% For appendices\n\\usepackage[toc,page]{appendix}\n\n% Package options\n\\usetikzlibrary{arrows,automata,decorations.markings,positioning}\n\n% Other options\n\\setcounter{MaxMatrixCols}{100}\n\n% Macros\n\\newcommand{\\mbf}[0]{\\mathbf}\n\\newcommand*{\\pd}[2]{\\frac{\\partial #1}{\\partial #2}}\n\\newcommand*{\\pdd}[2]{\\frac{\\partial^2 #1}{\\partial #2^2}}\n\\newcommand*{\\pder}[2]{\\left(\\frac{\\partial #1}{\\partial #2}\\right)}\n\\newcommand*{\\pdder}[2]{\\left(\\frac{\\partial^2 #1}{\\partial #2^2}\\right)}\n\\newcommand*{\\pdersub}[3]{\\left(\\frac{\\partial #1}{\\partial #2}\\right)_{#3}}\n\\newcommand*{\\pddersub}[3]{\\left(\\frac{\\partial^2 #1}{\\partial #2^2}\\right)_{#3}}\n\\newcommand*{\\pdcross}[3]{\\left(\\frac{\\partial^2 #1}{\\partial #2 \\partial #3}\\right)}\n\\newcommand*{\\pdcrosssub}[4]{\\left(\\frac{\\partial^2 #1}{\\partial #2 \\partial #3}\\right)_{#4}}\n\\newcommand*{\\hF}[0]{\\hat F}\n\\newcommand*{\\hH}[0]{\\hat H}\n\\newcommand{\\z}{\\zeta}\n\\newcommand{\\lp}{\\left(}\n\\newcommand{\\rp}{\\right)}\n\n\\title{Cubic Plus Association}\n\\author{Ailo Aasen}\n\\date{\\today}\n\\begin{document}\n\\frontmatter\n\\tableofcontents\n\\section{Introduction to CPA}\nCPA is an equation of state which is suitable for modeling associating mixtures, i.e. where hydrogen bonds occur. CPA stands for Cubic Plus Association, which refers to the fact that association is modeled as an additive contribution to the Helmholtz energy of a cubic equation of state. If one uses SRK as the underlying cubic equation of state -- which is the most common choice -- then one in other words has\n\\begin{equation}\n  A^{CPA} = A^{ideal} + A^{SRK} + A^{assoc}.\n\\end{equation}\n\n\\subsection{The association contribution to Helmholtz energy}\nEach associating molecule $i$ is assigned association sites $A_i$, $B_i$, $\\ldots$ For example, water is usually modeled as having four associating sites: each hydrogen atom and each 'free' electron valence pair in oxygen is a site. A site is called bonded if it is involved in a hydrogen bond. The association contribution for a mixture is modeled by\n\\begin{equation}\n  \\frac{A^{assoc}}{RT} = \\sum_{i} n_i \\sum_{A_i} \\lp \\ln X_{A_i} - \\frac{X_{A_i}}{2} + \\frac{1}{2} \\rp\n\\end{equation}\nwhere $X_{A_i}$ is the fraction of molecules \\textit{not} bonded at site $A_i$, and is given by the nonlinear equation\n\\begin{equation}\n  X_{A_i} = \\frac{1}{1+(1/V) \\sum_j n_j \\sum_{B_j} X_{B_j} \\Delta^{A_i B_j}}.\n\\end{equation}\nHere $\\Delta^{A_i B_j}$ is called the bond association strength, and is in CPA given by\n\\begin{equation}\n  \\Delta^{A_i B_j}(T,V,\\mbf n) = g(V,\\mbf n) \\cdot [\\exp(\\epsilon^{A_i B_j}/RT) - 1] b_{ij} \\beta^{A_i B_j},\n\\end{equation}\nwhere the radial distribution function $g$ is given by\\footnote{There are several variants of $g$; this one from simplified CPA (sCPA).}\n\\begin{equation}\n  g(V,\\mbf n) = \\frac{1}{1 - 0.475 B(\\mbf n)/V},\n\\end{equation}\nand $B(\\mbf n) = \\sum_i n_i b_i$. The quantities $b_i$ are the familiar co-volume parameters of the cubic EoS. The strength of the association is modeled using a square-well potential, and the quantities $\\epsilon^{A_i B_j}$ and $\\beta^{A_i B_j}$ represent the well depth and width, respectively.\n\n\\subsection{Mixing rules}\nWhen the CPA EoS is used for mixtures, the conventional mixing rules are applied for cubic part of the equation, namely\n\\begin{align}\n  a &= \\sum_i \\sum_j x_i x_j a_{ij}, \\qquad a_{ij} = \\sqrt{a_i a_j} (1-k_{ij}), \\\\\n  b &= \\sum_i x_i b_i,\n\\end{align}\nwhere $x_i = n_i/n$ is the molfraction of component $i$ in the mixture. Note that even for mixtures containing associating components, the interaction parameters $k_{ij}$ given here are the only adjustable parameters. Several alpha-formulation have been used, although the classic formulation is the most common choice. See also Section \\ref{subsec:fitted parameters}.\n\nThere are two recognized sets of mixing rules for the association parameters: % Only two? Check the papers Voutsas sent you.\n\n\\textbf{CR-1 mixing rules for association parameters}\n\\begin{equation}\n  \\epsilon^{A_i B_j} = \\frac{\\epsilon^{A_i B_i} + \\epsilon^{A_j B_j}}{2}, \\qquad \\beta^{A_i B_j} = \\sqrt{\\beta^{A_i B_i} \\beta^{A_j B_j}}.\n\\end{equation}\n\n\\textbf{Elliot's combining rule for association parameters}\n\nThis combining rule gives directly an expression for $\\Delta^{A_i B_j}$:\n\\begin{equation}\n  \\Delta^{A_i B_j} = \\sqrt{\\Delta^{A_i B_i} \\Delta^{A_j B_j}}.\n\\end{equation}\n\n\\textbf{Mixtures with solvation}\nCPA can be applied to mixtures with one self-associating component and one non-self-asssociating compound, but where there is cross-association -- solvation -- between the two compounds. Examples are the acid-gas mixtures H2O--CO2 and H2O--H2S. Since CO2--H2O is an especially important binary for CCS applications, modeling solvation will be an important task for ThermoPack.\n\nOne approach to modeling cross-interaction between a self-associating component $i$ and a non self-associating component $j$ is to set $\\Delta^{A_i B_j} = s_{ij} \\Delta^{A_i}$, where $s_{ij}$ is a constant determined by fitting the model to experimental data. In general, $s_{ij}$ is temperature-dependent. With this method, no self-association is modeled for the non-self-associating component, thus preserving this qualitative physical aspect. % Reference Austegård, and also Voutsas.\n\nAnother method is discussed by Kontogeorgis \\cite{Kontogeorgis10}, who suggests the so-called modified CR-1 combining rule. The procedure is to use the same expression for $\\Delta^{A_i B_j}$, but with\n\\begin{equation}\n  \\epsilon^{A_i B_j} = \\frac{\\epsilon_{assoc}}{2}, \\qquad \\beta^{A_i B_j} \\ \\text{ (fitted)}.\n\\end{equation}\nAlso for this method, a non-self-associating component has no self-association.\n\nThe third approach is to simply model the solvating component as an associating molecule. This approach sort of disregards the underlying physics, but has been found to give good results. Some experimentation may be needed to figure out the appropriate association scheme. % Reference Voutsas.\n\n\n\\subsection{CPA compared to other SAFT equations}\nAlthough it's not necessary for the remainder, we briefly mention general SAFT equations. CPA is just one in a host of equations of state which model associating components, and that are classified as SAFT equations. SAFT stands for Statistical Associating Fluid Theory, and is -- unlike multiparameter equations of state -- a physically based framework for modeling associating mixtures. Although developed in the late 1980s and early 1990s, there is still much work being published on SAFT.\n\nFortunately, all of the SAFT variants use essentially the same expression for $A^{assoc}$, the difference lying in the bond associating strength $\\Delta^{A_i B_j}$. As an example, we will give the $\\Delta^{A_i B_j}$ as it appears in the model PC-SAFT, namely\n\\begin{equation}\n  \\label{ascStrength}\n  \\Delta^{A_i B_j} = g_{ij} \\cdot [\\exp(\\epsilon^{A_i B_j}/kT) - 1](\\sigma_{ij}^3 \\kappa^{A_i B_j}).\n\\end{equation}\nThe radial distribution function of the hard-sphere fluid is\n\\begin{equation}\n  \\label{gij}\n  g_{ij} = \\frac{1}{1-\\z_3} + \\lp \\frac{d_id_j}{d_i+d_j} \\rp \\frac{3\\z_2}{(1-\\z_3)^2} + \\lp \\frac{d_i d_j}{d_i+d_j} \\rp^2 \\frac{2\\z_2^2}{(1-\\z_3)^2}.\n\\end{equation}\nwhere\n\\begin{equation}\n  \\z_n = \\frac{\\pi}{6} \\rho \\sum_i x_i m_i d_i^n, \\qquad n = 0,1,2,3,\n\\end{equation}\nand\n\\begin{equation}\n  d_i = \\sigma_i \\left[1 - 0.12\\exp \\lp -3\\frac{\\epsilon_i}{kT} \\rp \\right].\n\\end{equation}\nNote, in particular, the in PC-SAFT, the radial distribution function is temperature dependent. Mixing rules for the PC-SAFT parameters:\n\\begin{align}\n  \\sigma_{ij} &= \\frac{1}{2}(\\sigma_i + \\sigma_j) \\\\\n  \\epsilon_{ij} &= \\sqrt{\\epsilon_i \\epsilon_j}(1-k_{ij}).\n\\end{align}\n(Note that $\\epsilon^{A_i B_j}$ and $\\epsilon_{ij}$ are completely different parameters.)\n\nThe biggest strength of PC-SAFT compared to CPA, is that the non-association part is theoretically justified. This advantage becomes especially clear when modeling polymers, which PC-SAFT is tailored to be able to handle. For molecules having a chain-like structure, PC-SAFT indeed outperforms CPA. On the other hand, PC-SAFT has a more complicated non-association part, making it harder to implement (especially in ThermoPack, for which everything is built around cubic equations of state), and also more demanding in terms of computation time. Although only CPA will be implemented at this point, significant portions of the code can be recycled if one at one point in the future decides to implement other SAFT variants.\n% Would be nice with a reference stating that PC-SAFT outperfoms CPA when modeling polymers.\n\n\\subsection{The one-strength association schemes}\nHuang and Radosz (1990) were the first to publish a SAFT variant with extensive parameter lists. They also classified association schemes, which has become the standard for later work on SAFT. Ideally, one should have detailed, independent data from spectroscopy for the associating strength for each site-site interaction. The scheme of Huang and Radosz reduces the number of parameters to be fitted for each interaction $A_i B_i$ to just one. To illustrate this one-strength association scheme, let us consider the water molecule, with two positively polarized hydrogen atoms (sites $A$ and $B$), and two free electron pairs (sites $C$ and $D$). Huang and Radosz classifies water according to the so-called 4C scheme:\n\\begin{align*}\n&\\Delta^{AA} = \\Delta^{AB} = \\Delta^{BB} = \\Delta^{CC} = \\Delta^{CD} = \\Delta^{DD} = 0 \\\\\n&\\Delta^{AC} = \\Delta^{AD} = \\Delta^{BC} = \\Delta^{BD} \\neq 0.\n\\end{align*}\nAlthough this is the most physically appropriate one-strength association scheme for water, various reasons (e.g. limited experimental data, or a desire for reduced complextiy), it is often modeled according to the 3B scheme:\n\\begin{align*}\n&\\Delta^{AA} = \\Delta^{AB} = \\Delta^{BB} = \\Delta^{CC} = 0 \\\\\n&\\Delta^{AC} = \\Delta^{BC} \\neq 0.\n\\end{align*}\nOf course, in the 3B scheme the physical interpretation of the association sites is not so clear, but in the end they are just fitted parameters.\n\nIn the end, the big advantage with the one-strength associating scheme, is that one just have to give the two numbers $\\beta^{A B}$ and $\\epsilon^{A B}$, in addition to the particular one-strength association scheme, to fully describe the association of an associating component. (Of course, the three SRK parameters come in addition to this.)\n\nWhen modeling cross-association, there is only a contribution between the sites having the opposite polarity.\n\n\\section{The $Q$ function and its relation to $F^{\\text{assoc}}$}\nDefine the function\n\\begin{equation}\n  Q(\\mbf n,T,V,\\mathbf{X}) = \\sum_i \\sum_{A_i} n_i \\lp \\ln X_{A_i} - X_{A_i} + 1\\rp - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\Delta^{A_i B_j}.\n\\end{equation}\nHere $\\Delta^{A_i B_j} = \\Delta^{A_i B_j}(T,V,\\mbf n)$ is the bond association strength. If $\\mbf X$ solves the equations\n\\begin{equation}\n  \\pder{Q}{\\mbf X}(T,V,\\mbf n,X) = \\mbf 0, \\quad \\text{i.e.} \\quad   \\frac{1}{X_{A_i}} - 1 - \\frac{1}{V} \\sum_j \\sum_{B_j} n_j X_{B_j} \\Delta^{A_i B_j} = 0 \\quad \\forall \\ X_{A_i}.\n\\end{equation}\nthen the resulting solution $\\mbf X = \\mbf X(T,V,\\mbf n)$ is such that\\footnote{Where $F^{\\text{assoc}}(T,V,\\mbf n) = A^{R}(T,V,\\mbf n)/RT$ and $A^R$ is the association contribution to the residual Helmholtz energy.}\n\\begin{equation}\n  \\label{FQrelationship}\n  F^{\\text{assoc}}(T,V,\\mbf n) = Q(T,V,\\mbf n, \\mbf X(T,V,\\mbf n)).\n\\end{equation}\nWe now clarify the notation used below in the expressions for the derivatives. Given a differential operator $\\partial$, we will in the following use $\\partial Q_{sp}$ to mean $(\\partial Q)(T,V,\\mbf n,\\mbf X(T,V,\\mbf n))$. For example, $\\pder{Q_{sp}}{V} = \\pder{Q}{V}(T,V,\\mbf n,\\mbf X(T,V,\\mbf n))$. Moreover, to avoid subscripting every partial derivative to show which variables are fixed, we agree once and for all that $F^{\\text{assoc}}$ has $(T,V,\\mbf n)$ as independent variables, while $Q$ has $(T,V,\\mbf n,\\mbf X)$ as independent variables. The equality \\eqref{FQrelationship} can also be stated as $F^{\\text{assoc}} = Q|_{\\mbf X = \\mbf X(T,V,\\mbf n)}$.\n\n\\section{First-order derivatives of $F^{\\text{assoc}}$} \\label{first-order derivatives}\nWe find that\n\\begin{align*}\n\\pder{F^{\\text{assoc}}}{V} &= \\pder{Q_{sp}}{V}  + \\sum_i \\sum_{A_i} \\pder{Q_{sp}}{X_{A_i}} \\pder{X_{A_i}}{V} \\\\\n& = \\pder{Q_{sp}}{V},\n\\end{align*}\nsince $\\pder{Q_{sp}}{X_{A_i}} = 0$. Similarly, we have\n$$\n\\pder{F^{\\text{assoc}}}{T} = \\pder{Q_{sp}}{T} \\quad \\text{and} \\quad \\pder{F^{\\text{assoc}}}{n_k} = \\pder{Q_{sp}}{n_k}.\n$$\n\\subsection{Volume derivative}\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{V} &= \\pder{Q_{sp}}{V} \\\\ \\nonumber\n  &= \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{\\Delta^{A_i B_j}}{V} - \\pder{\\Delta^{A_i B_j}}{V} \\right].\n\\end{align}\n\n\\subsection{Temperature derivative}\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{T} &= \\pder{Q_{sp}}{T} \\\\ \\nonumber\n  &= -\\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pder{\\Delta^{A_i B_j}}{T}.\n\\end{align}\n\n\\subsection{Composition derivative}\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{n_k} =& \\pder{Q_{sp}}{n_k} \\nonumber \\\\ \n  =& \\sum_{A_k} \\lp \\ln X_{A_k} - X_{A_k} + 1\\rp - \\frac{1}{V} \\sum_{j} \\sum_{A_k,B_j} n_j X_{A_k} X_{B_j} \\Delta^{A_k B_j} \\label{l1}\\\\\n  &- \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pder{\\Delta^{A_i B_j}}{n_k} \\label{l2}\\\\\n  =& \\sum_{A_k} \\ln X_{A_k} - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pder{\\Delta^{A_i B_j}}{n_k}. \\label{nono}\n\\end{align}\n\n\\section{Second-order derivatives of $F^{\\text{assoc}}$}\nLet the variables $\\z_1,\\z_2$ each equal one of the scalar variables in $(T,V,\\mbf n)$. Recalling that \n$$\n\\pder{F^{assoc}}{\\z_1}(T,V,\\mbf n) = \\pder{Q}{\\z_1}(T,V,\\mbf n,\\mbf X(T,V,\\mbf n)),\n$$\nwe get\n\\begin{align}\n  \\pdcross{F^{\\text{assoc}}}{\\z_2}{\\z_1} =& \\frac{\\partial}{\\partial \\z_2} \\pder{F^{\\text{assoc}}}{\\z_1} \\\\\n  =& \\pdcross{Q_{sp}}{\\z_2}{\\z_1} + \\pdcross{Q_{sp}}{\\z_1}{\\mbf X} \\pder{\\mbf X}{\\z_2}. \\label{stress}\n\\end{align}\nWe once again stress the meaning of our notation: in the first term of \\eqref{stress}, $\\mbf X$ is to be treated as a constant when the cross-derivative is taken. Now, the expression \\eqref{stress} involves the derivative $\\partial \\mbf X/\\partial \\z_2$. To find this derivative, we differentiate the defining relation for $X(T,V,\\mbf n)$, namely $\\pder{Q}{\\mbf X} = \\mbf 0$. Doing this (and taking care to transpose vectors correctly), we get\n\\begin{align}\n \\mbf 0 = \\frac{\\partial}{\\partial \\z_2} \\pder{Q_{sp}}{\\mbf X} = \\pdcross{Q_{sp}}{\\mbf X}{\\z_2} + \\pder{\\mbf X}{\\z_2}^t \\pdder{Q_{sp}}{\\mbf X},\n\\end{align}\nyielding\n\\begin{equation}\n  \\label{Xz2}\n  \\pder{\\mbf X}{\\z_2} = - \\pdder{Q_{sp}}{\\mbf X}^{-1} \\pdcross{Q_{sp}}{\\mbf X}{\\z_2}^t.\n\\end{equation}\nIn conclusion, the formula for the second derivative is obtained by combining \\eqref{stress} and \\eqref{Xz2}:\n\\begin{equation}\n  \\pdcross{F^{\\text{assoc}}}{\\z_2}{\\z_1} = \\pdcross{Q_{sp}}{\\z_2}{\\z_1} -  \\pdcross{Q_{sp}}{\\z_1}{\\mbf X} \\pdder{Q_{sp}}{\\mbf X}^{-1} \\pdcross{Q_{sp}}{\\mbf X}{\\z_2}^t.\n\\end{equation}\nOr, if one prefers summation notation:\n\\begin{equation}\n  \\pdcross{F^{\\text{assoc}}}{\\z_2}{\\z_1} = \\pdcross{Q_{sp}}{\\z_2}{\\z_1} -  \\sum_{i,j} \\sum_{A_i,B_j} \\pdcross{Q_{sp}}{\\z_1}{X_{A_i}} \\lp \\pdder{Q_{sp}}{\\mbf X}^{-1} \\rp_{ij} \\pdcross{Q_{sp}}{X_{B_j}}{\\z_2}.\n\\end{equation}\n\n\\subsection{Formulas for $\\pdcross{Q_{sp}}{\\z_2}{\\z_1}$}\n\n\\begin{align*}\n  \\pdder{Q_{sp}}{T} =  - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdder{\\Delta^{A_i B_j}}{T}.\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{T}{V} = \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{1}{V} \\pder{\\Delta^{A_i B_j}}{T} - \\pdcross{\\Delta^{A_i B_j}}{T}{V} \\right]\n\\end{align*}\n\n\\begin{align*} % DOUBLE-CHECKED\n  \\pdcross{Q_{sp}}{T}{n_k} =& -\\frac{1}{V} \\sum_{j} \\sum_{A_k,B_j} n_j X_{A_k} X_{B_j} \\pder{\\Delta^{A_k B_j}}{T}\\\\\n  &- \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdcross{\\Delta^{A_i B_j}}{T}{n_k}\n\\end{align*}\n\n\\begin{align*}\n  \\pdder{Q_{sp}}{V} = \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ -\\frac{2\\Delta^{A_i B_j}}{V^2} + \\frac{2}{V}  \\pder{\\Delta^{A_i B_j}}{V}  - \\pdder{\\Delta^{A_i B_j}}{V} \\right]\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{V}{n_k} =& \\sum_{j} \\sum_{A_k,B_j} n_j X_{A_k} X_{B_j} \\left[ \\frac{\\Delta^{A_k B_j}}{V^2} - \\frac{1}{V} \\pder{\\Delta^{A_k B_j}}{V}\\right] \\\\\n  &+ \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{1}{V} \\pder{\\Delta^{A_i B_j}}{n_k} - \\pdcross{\\Delta^{A_i B_j}}{V}{n_k} \\right].\n\\end{align*}\n\n\\begin{align*} % DOUBLE-CHECKED\n  \\pdcross{Q_{sp}}{n_l}{n_k} =& - \\frac{1}{V} \\sum_{A_k, B_l} X_{A_k} X_{B_l} \\Delta^{A_k B_l} - \\frac{1}{V} \\sum_{j} \\sum_{A_l, B_j} n_j X_{A_l} X_{B_j} \\pder{\\Delta^{A_l B_j}}{n_k} \\\\\n  &- \\frac{1}{V} \\sum_{j} \\sum_{A_k, B_j} n_j X_{A_k} X_{B_j} \\pder{\\Delta^{A_k B_j}}{n_l} - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdcross{\\Delta^{A_i B_j}}{n_l}{n_k}\n\\end{align*}\nThese derivatives are all found by performing one more differentiation on the first-order derivatives we found in section \\ref{first-order derivatives}. However, when taking an additional derivative of $\\pder{Q_{sp}}{n_k}$, we have to take care to differentiate the expressions on \\eqref{l1} and \\eqref{l2}, and not the simplified expression \\eqref{nono}. This is because the supscript \\textrm{sp} means that $X(T,V,\\mbf n)$ should be substituted in \\textit{after} all the derivatives have been performed.\n\n\\subsection{Formulas for $\\pdcross{Q_{sp}}{X_{A_i}}{\\z_1}$}\nWe have\n\\begin{equation}\n  \\pder{Q}{X_{A_i}} = \\frac{n_i}{X_{A_i}} - n_i  - \\frac{n_i}{V} \\sum_{j} \\sum_{B_j} n_j X_{B_j} \\Delta^{A_i B_j},\n\\end{equation}\nand thus\n\\begin{align*}\n  \\pdcross{Q_{sp}}{T}{X_{A_i}} = -\\frac{n_i}{V} \\sum_{j} \\sum_{B_j} n_j X_{B_j} \\pder{\\Delta^{A_i B_j}}{T}\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{V}{X_{A_i}} = n_i \\sum_{j} \\sum_{B_j} n_j X_{B_j} \\left[ \\frac{1}{V^2} \\Delta^{A_i B_j} - \\frac{1}{V} \\pder{\\Delta^{A_i B_j}}{V} \\right]\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{n_l}{X_{A_i}} = - \\frac{n_i}{V} \\sum_{B_l} X_{B_l} \\Delta^{A_i B_l} - \\frac{1}{V} \\sum_{j} \\sum_{B_j} n_j X_{B_j} n_i \\pder{\\Delta^{A_i B_j}}{n_l}.\n\\end{align*}\n\n\\subsection{Solving for $\\pder{\\mbf X}{V}$ and $\\pdder{Q_{sp}}{V}$ simultaneously}\nThe derivatives $\\pder{\\mbf X}{V}$ and $\\pdder{Q_{sp}}{V}$ are needed in the Newton iteration when solving for volume given pressure, temperature and composition. When both of these are needed, one wants to first solve for $\\pder{\\mbf X}{V}$ from \\eqref{Xz2}, and then use \\eqref{stress} to find $\\pdder{Q_{sp}}{V}$, and therefore a dedicated routine for this has been implemented. To obtain $\\pder{\\mbf X}{V}$, we solve the linear system\n\\begin{equation}\n  \\pdder{Q_{sp}}{\\mbf X} \\pder{\\mbf X}{V} = -\\pdcross{Q_{sp}}{V}{\\mbf X}^t.\n\\end{equation}\nwhere\\footnote{Note that only the diagonal of $\\pdcross{Q}{X_{A_i}}{X_{B_j}}$ is dependent on $\\mbf X$.}\n\\begin{equation}\n  \\pdcross{Q}{X_{A_i}}{X_{B_j}} = -\\frac{n_i}{X_{A_i}^2} \\delta_{A_i B_j} - \\frac{n_i n_j}{V} \\Delta^{A_i B_j}.\n\\end{equation}\nHaving found this derivative, we find $\\pder{P}{V}$ from \\eqref{stress}:\n\\begin{equation}\n    \\pdder{F^{\\text{assoc}}}{V} = \\pdder{Q_{sp}}{V} + \\pdcross{Q_{sp}}{\\mbf X}{V} \\pder{\\mbf X}{V}.\n\\end{equation}\n\n\\section{Derivatives when using the CPA-form of $\\Delta^{A_i B_j}(T,V,\\mbf n)$}\nWe now specialize to a specific functional form of $\\Delta^{A_i B_j}(T,V,\\mbf n)$, namely that used in the CPA-model. It is given by\n\\begin{equation}\n  \\Delta^{A_i B_j}(T,V,\\mbf n) = g(V,\\mbf n) \\cdot [\\exp(\\epsilon^{A_i B_j}/RT) - 1] b_{ij} \\beta^{A_i B_j},\n\\end{equation}\nwhere $\\epsilon^{A_i B_j}$, $b_{ij}$ and $\\beta^{A_i B_j}$ are constants. The first derivatives are thus given by\n\\begin{align}\n  \\pder{\\Delta^{A_i B_j}}{T}   &= -\\frac{\\epsilon^{A_i B_j}}{RT^2} g(V,\\mbf n) \\exp(\\epsilon^{A_i B_j}/RT) b_{ij} \\beta^{A_i B_j} \\\\\n  \\pder{\\Delta^{A_i B_j}}{V}   &= \\pder{g(V,\\mbf n)}{V} \\cdot [\\exp(\\epsilon^{A_i B_j}/RT) - 1] b_{ij} \\beta^{A_i B_j}  = \\pder{\\ln g(V,\\mbf n)}{V} \\Delta^{A_i B_j} \\\\\n  \\pder{\\Delta^{A_i B_j}}{n_k} &= \\pder{g(V,\\mbf n)}{n_k} \\cdot [\\exp(\\epsilon^{A_i B_j}/RT) - 1] b_{ij} \\beta^{A_i B_j} =  \\pder{\\ln g(V,\\mbf n)}{n_k} \\Delta^{A_i B_j}\n\\end{align}\nwhile the second derivatives are given by\n\\begin{align}\n  \\pdder{\\Delta^{A_i B_j}}{T}   &=  g(V,\\mbf n) \\lp 2 + \\frac{\\epsilon^{A_i B_j}}{RT} \\rp b_{ij} \\beta^{A_i B_j} \\frac{\\epsilon^{A_i B_j}}{RT^3} \\exp(\\epsilon^{A_i B_j}/RT) \\\\\n  \\pdcross{\\Delta^{A_i B_j}}{V}{T}   &= -\\frac{\\epsilon^{A_i B_j}}{RT^2} g(V,\\mbf n) \\exp(\\epsilon^{A_i B_j}/RT) b_{ij} \\beta^{A_i B_j} \\pder{g(V,\\mbf n)}{V} \\\\\n  \\pdcross{\\Delta^{A_i B_j}}{n_l}{T}   &= -\\frac{\\epsilon^{A_i B_j}}{RT^2} g(V,\\mbf n) \\exp(\\epsilon^{A_i B_j}/RT) b_{ij} \\beta^{A_i B_j} \\pder{g(V,\\mbf n)}{n_l} \\\\\n  \\pdder{\\Delta^{A_i B_j}}{V}   &= \\pdder{g(V,\\mbf n)}{V}  \\frac{\\Delta^{A_i B_j}}{g(V,\\mbf n)} \\\\\n  \\pdcross{\\Delta^{A_i B_j}}{n_l}{V}  &= \\pdcross{g(V,\\mbf n)}{n_l}{V} \\frac{\\Delta^{A_i B_j}}{g(V,\\mbf n)} \\\\\n  \\pdcross{\\Delta^{A_i B_j}}{n_l}{n_k}  &= \\pdcross{g(V,\\mbf n)}{n_l}{n_k} \\frac{\\Delta^{A_i B_j}}{g(V,\\mbf n)} \n\\end{align}\n\n\\textbf{Derivatives of $g(V,\\mbf n)$}\n\nIn all common variants of CPA, the radial distribution function takes the special functional form $g(V,\\mbf n) = g(\\eta)$, where $\\eta$ is the adimensional number\n$$\n\\eta = B(\\mbf n)/4V = b\\rho/4, \\quad \\text{where} \\quad B(\\mbf n) = nb = \\sum_i n_i b_i.\n$$\nNote that $\\mbf n$ here includes all components, also the non-associating ones. Two common variants for $g(\\eta)$, along with their first and second derivatives, are given by\n\\begin{align*}\n  g(\\eta) = \\frac{1}{1-1.9 \\eta}, \\qquad g'(\\eta) = \\frac{1.9}{(1-1.9\\eta)^2}, \\qquad g''(\\eta) = \\frac{2 \\cdot 1.9^2}{(1-1.9\\eta)^3} \\qquad \\mathbf{(sCPA)} \\\\\n  g(\\eta) = \\frac{1-\\eta/2}{(1- \\eta)^3}, \\qquad g'(\\eta) = \\frac{2.5-\\eta}{(1-\\eta)^4}, \\qquad g''(\\eta) = \\frac{3\\eta-9}{(1-\\eta)^5} \\qquad \\mathbf{(original)}\n\\end{align*}\nIts derivatives with respect to variables $\\zeta_1,\\zeta_2$, each being a member of $(T,\\mbf n)$, are given by\n\\begin{equation}\n  \\pder{g}{\\zeta_1} = g'(\\eta) \\pder{\\eta}{\\zeta_1}, \\qquad \\pdcross{g}{\\zeta_1}{\\zeta_2} = g''(\\eta) \\pder{\\eta}{\\zeta_1} \\pder{\\eta}{\\zeta_2} + g'(\\eta) \\pdcross{\\eta}{\\zeta_1}{\\zeta_2},\n\\end{equation}\nand\n% \\begin{align} % These are correct.\n%   \\pder{g}{V}          =& -\\frac{1}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^2} \\cdot \\frac{0.475 B(\\mbf n) }{V^2} \\\\\n%   \\pder{g}{n_k}        =& \\frac{1}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^2} \\cdot \\frac{0.475}{V} b_k \\\\\n%   \\pdder{g}{V}         =& \\frac{2}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^3} \\cdot \\lp \\frac{0.475 B(\\mbf n) }{V^2} \\rp^2 + \\frac{1}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^2} \\cdot \\frac{2 \\cdot 0.475 B(\\mbf n) }{V^3} \\\\\n%   \\pdcross{g}{n_l}{V}  =& -\\frac{2}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^3} \\cdot \\frac{0.475^2 B(\\mbf n) }{V^3} b_l -\\frac{1}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^2} \\cdot \\frac{0.475}{V^2} b_l \\\\\n%   \\pdcross{g}{n_l}{n_k}=& \\frac{2}{\\lp 1 - 0.475 B(\\mbf n)/V \\rp^3} \\cdot \\lp \\frac{0.475}{V} \\rp^2 b_l b_k,\n% \\end{align}\n%where we used the fact that, $\\pder{B}{n_k} = b_k$, while $\\pdcross{B}{n_l}{n_k} = 0$.\n\\begin{align}\n \\pder{\\eta}{V} = -\\frac{B(\\mbf n)}{4V^2} \\qquad  \\pder{\\eta}{n_k} = \\frac{b_k}{4V},\n\\end{align}\n\\begin{align}\n  \\pdder{\\eta}{V} = \\frac{B(\\mbf n)}{2V^3} \\qquad \\pdcross{\\eta}{n_l}{V}  = -\\frac{b_k}{4V^2} \\qquad  \\pdcross{\\eta}{n_k}{n_l} = 0.\n\\end{align}\n\n\\subsection{Simplified CPA Derivatives}\n\n\\textbf{Simplified first derivatives}\n\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{V} =& \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{\\Delta^{A_i B_j}}{V} - \\pder{\\Delta^{A_i B_j}}{V} \\right] \\\\\n  =& \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\Delta^{A_i B_j} \\left[ \\frac{1}{V} - \\pder{\\ln g}{V} \\right] \\\\\n  =& \\frac{1}{2} \\left[ \\frac{1}{V} - \\pder{\\ln g}{V} \\right] \\sum_i \\sum_{A_i} n_i (1- X_{A_i})\n\\end{align}\n\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{T}  &= -\\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pder{\\Delta^{A_i B_j}}{T}.\n\\end{align}\n\n\\begin{align}\n  \\pder{F^{\\text{assoc}}}{n_k} =& \\sum_{A_k} \\ln X_{A_k} - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pder{\\Delta^{A_i B_j}}{n_k} \\\\\n  =& \\sum_{A_k} \\ln X_{A_k} - \\pder{\\ln g}{n_k} \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\Delta^{A_i B_j} \\\\\n  =& \\sum_{A_k} \\ln X_{A_k} - \\frac{1}{2} \\pder{\\ln g}{n_k} \\sum_{i} \\sum_{A_i} n_i (1-X_{A_i}).\n\\end{align}\n\n\n\\textbf{Simplified formulas for $\\pdcross{Q_{sp}}{X_{A_i}}{\\z_2}$}\n\\begin{align*}\n  \\pdcross{Q_{sp}}{T}{X_{A_i}} =& -\\frac{1}{V} \\sum_{j} \\sum_{B_j} n_i n_j X_{B_j} \\pder{\\Delta^{A_i B_j}}{T} \\\\\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{V}{X_{A_i}} =& \\sum_{j} \\sum_{B_j} n_i n_j X_{B_j} \\left[ \\frac{1}{V^2} \\Delta^{A_i B_j} - \\frac{1}{V} \\pder{\\Delta^{A_i B_j}}{V} \\right] \\\\\n  =& \\left[ \\frac{1}{V}  - \\pder{\\ln g}{V} \\right] \\frac{1}{V} \\sum_{j} \\sum_{B_j} n_i n_j X_{B_j} \\Delta^{A_i B_j} \\\\\n  =& \\left[ \\frac{1}{V}  - \\pder{\\ln g}{V} \\right] \\lp \\frac{1}{X_{A_i}} - 1 \\rp\n\\end{align*}\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{n_l}{X_{A_i}} =& - \\frac{1}{V} \\sum_{B_l} n_i X_{B_l} \\Delta^{A_i B_l} - \\frac{1}{V} \\sum_{j} \\sum_{B_j} n_j X_{B_j} \\left[\\delta_{il} \\Delta^{A_i B_j} + n_i \\pder{\\Delta^{A_i B_j}}{n_l} \\right] \\\\\n  =& - \\frac{1}{V} \\sum_{B_l} n_i X_{B_l} \\Delta^{A_i B_l} - \\left[\\delta_{il} + n_i \\pder{g}{n_l} \\right] \\frac{1}{V} \\sum_{j} \\sum_{B_j} n_j X_{B_j} \\Delta^{A_i B_j} \\\\\n  =& - \\frac{1}{V} \\sum_{B_l} n_i X_{B_l} \\Delta^{A_i B_l} - \\left[\\delta_{il} + n_i \\pder{g}{n_l} \\right] \\lp \\frac{1}{X_{A_i}} - 1 \\rp\n\\end{align*}\n\n%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\\textbf{Simplified formulas for $\\pdcross{Q_{sp}}{\\z_1}{\\z_2}$}\n\n\\begin{align*}\n  \\pdder{Q_{sp}}{T} =  - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdder{\\Delta^{A_i B_j}}{T}.\n\\end{align*}\n\n\n\\begin{align*} % THIS IS THE ONLY ONE WHICH HAS BEEN SIMPLIFIED.\n  \\pdder{Q_{sp}}{V} &= \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ -\\frac{2\\Delta^{A_i B_j}}{V^2} + \\frac{2}{V}  \\pder{\\Delta^{A_i B_j}}{V}  - \\pdder{\\Delta^{A_i B_j}}{V} \\right] \\\\\n  &= \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\Delta^{A_i B_j} \\left[ -\\frac{2}{V^2} + \\frac{2}{V} \\pder{\\ln g(V,\\mbf n)}{V} - \\pdder{g(V,\\mbf n)}{V}  \\frac{1}{g(V,\\mbf n)} \\right] \\\\\n  &= \\frac{1}{2} \\sum_{i} \\sum_{A_i} n_i \\lp \\frac{1}{X_{A_i}}-1 \\rp \\left[ -\\frac{2}{V^2} + \\frac{2}{V} \\pder{\\ln g(V,\\mbf n)}{V} -  \\pdder{g(V,\\mbf n)}{V}  \\frac{1}{g(V,\\mbf n)} \\right]\n\\end{align*}\n\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{T}{V} = \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{1}{V} \\pder{\\Delta^{A_i B_j}}{T} - \\pdcross{\\Delta^{A_i B_j}}{T}{V} \\right]\n\\end{align*}\n\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{T}{n_k} =& \\frac{1}{V} \\sum_{j} \\sum_{A_k,B_j} n_j X_{A_k} X_{B_j} \\pder{\\Delta^{A_k B_j}}{T}\\\\\n  &- \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdcross{\\Delta^{A_i B_j}}{T}{n_k}\n\\end{align*}\n\n\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{V}{n_k} =& \\sum_{j} \\sum_{A_k,B_j} n_j X_{A_k} X_{B_j} \\left[ \\frac{\\Delta^{A_k B_j}}{V^2} - \\frac{1}{V} \\pder{\\Delta^{A_k B_j}}{V}\\right] \\\\\n  &+ \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\left[ \\frac{1}{V^2} \\pder{\\Delta^{A_i B_j}}{n_k} - \\frac{1}{2V} \\pdcross{\\Delta^{A_i B_j}}{V}{n_k} \\right].\n\\end{align*}\n\n\n\\begin{align*}\n  \\pdcross{Q_{sp}}{n_l}{n_k} =& - \\frac{1}{V} \\sum_{A_k, B_l} X_{A_k} X_{B_l} \\Delta^{A_k B_l} - \\frac{1}{V} \\sum_{j} \\sum_{A_i, B_j} n_j X_{A_l} X_{B_j} \\pder{\\Delta^{A_l B_j}}{n_k} \\\\\n  &- \\frac{1}{V} \\sum_{j} \\sum_{A_i, B_j} n_j X_{A_k} X_{B_j} \\pder{\\Delta^{A_k B_j}}{n_l} - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\pdcross{\\Delta^{A_i B_j}}{n_l}{n_k}\n\\end{align*}\n\n\n\\section{Efficient implementation of the association contribution} \\label{effImp}\nWe now describe an efficient implementation of the association contribution, which is outlined in the papers by Michelsen \\cite{Michelsen01} and \\cite{Michelsen06}.\n\nEquation of state models with an association contribution are computationally expensive as they have to solve an internal chemical equilibrium problem. However, using that the association contribution to the Helmholtz energy can be found from a certain minimization procedure, will be used to simplify the calculation of properties like pressure and chemical potentials, together with their derivatives with respect to temperature, volume and composition.\n\n\\subsection{Base equations}\nIn the SAFT and CPA models, the association contribution to the mixture Helmholtz energy is found from\n\\begin{equation}\n  \\label{aAssoc}\n  \\frac{A^{\\text{assoc}}}{RT} = \\sum_i n_i \\sum_{A_i} \\lp \\ln X_{A_i} - \\frac12 X_{A_i} + \\frac12 \\rp.\n\\end{equation}\nHere, $A$ and $B$ index bonding sites on a given molecule, and $X_{A_i}$ denotes the fraction of $A$-sites on molecule $i$ that do NOT form bonds with other active sites. These site fractions are given implicitly by the nonlinear equations\n\\begin{equation}\n  X_{A_i} = \\frac{1}{1 + \\sum_j \\sum_{B_j} x_j X_{B_j} \\Delta^{A_i B_j}},\n\\end{equation}\nwhere $\\Delta^{A_i B_j}$ is the association strength between site $A$ on molecule $i$ and site $B$ on molecule $j$, and depends on $T$, $V$ and $\\mbf n$, but NOT on the fraction of sites that form bonds. Differentiation of \\eqref{aAssoc} yields derived properties (i.e. the contribution from the association term to the derived properties), e.g.\n\\begin{equation}\n  \\frac{P^{\\text{assoc}}}{RT} = -\\frac{\\partial}{\\partial V} \\lp \\frac{A^{\\text{assoc}}}{RT} \\rp = \\sum_i n_i \\sum_{A_i} \\lp \\frac{1}{X_{A_i}}-\\frac{1}{2} \\rp \\frac{\\partial X_{A_i}}{\\partial V}.\n\\end{equation}\nWe will now see, however, that by taking advantage of a certain minimization problem, there is a computationally cheaper expression for the association pressure.\n\nNow, define $Q$ by \n\\begin{equation}\n  Q(\\mbf n,T,V,\\mathbf{X}(\\mbf n, T, V)) = \\sum_i \\sum_{A_i} n_i \\lp \\ln X_{A_i} - X_{A_i} + 1\\rp - \\frac{1}{2V} \\sum_{i,j} \\sum_{A_i, B_j} n_i n_j X_{A_i} X_{B_j} \\Delta^{A_i B_j}.\n\\end{equation}\nThe reason for introducing the $Q$ function, is that the association contribution of SAFT and CPA to the reduced, residual Helmholtz energy, equals the value of $Q$ at a stationary point with respect to the site fractions $\\mbf X$; i.e. at a point where the gradient of $Q$ with respect to the $\\mbf X$-coordinates vanishes. This is shown in Michelsen \\cite{Michelsen01}, in addition to where $Q$ comes from in the first place. The association contribution to pressure is thus found from\n$$\n\\frac{P^{\\text{assoc}}}{RT} = - \\frac{\\partial Q_{sp}}{\\partial V},\n$$\nwhere $Q_{sp}$ is a stationary point with respect to the $\\mbf X$-variables. To find the derivative on the right hand side, we use the chain rule:\n\\begin{align*}\n  \\frac{\\partial Q_{sp}}{\\partial V} = \\pder{Q}{V}_{\\mbf X} + \\sum_i \\sum_{A_i} \\pder{Q}{X_{A_i}}_V \\frac{\\partial X_{A_i}}{\\partial V}\n\\end{align*}\nbut since the derivatives with respect to $X_{A_i}$ are $0$ at the stationary point, we get $P^{\\text{assoc}} = -RT \\pder{Q}{V}_{\\mbf X}$. When this is differentiated out, we get\n\\begin{equation}\n  P^{assoc} = -\\frac{RT}{2V} \\lp 1 - V \\pder{\\ln g}{V} \\rp \\sum_i \\sum_{A_i} n_i (1-X_{A_i}).\n\\end{equation}\n\nAlthough the notation we have used up to now is the traditional one, it is unwieldy to use in what follows. We therefore follow Michelsen \\cite{Michelsen06} and use the following notation\n\\begin{itemize}\n\\item $S$ is the total number of different sites for all molecules\n\\item The totality of association sites on all molecules are indexed sequentially, $k=1,2,\\ldots,S$\n\\item $m_k$ is the total number of moles of molecules that host a given site $k$\n\\item $K_{kl} = K_{lk} = m_l m_k \\Delta^{lk}/V$\n\\end{itemize}\nUsing this notation, we can write\n\\begin{equation}\n  Q(\\mbf X, \\mbf m) = \\sum_{k=1}^S m_k(\\ln X_k - X_k + 1) - \\frac{1}{2} \\sum_{k=1}^S \\sum_{l=1}^S K_{kl} X_k X_l.\n\\end{equation}\nWhen $Q = Q(\\mbf X,\\mbf m)$ is written in this form, its $\\mbf X$-derivatives are given by\n\\begin{equation}\n  \\label{gDef}\n  g_k := \\pder{Q}{X_k} = m_k\\lp \\frac{1}{X_k} - 1 \\rp - \\sum_{l=1}^S K_{kl} X_l,\n\\end{equation}\nwhile its Hessian matrix with respect to $\\mbf X$ is\n\\begin{equation}\n  \\label{hDef}\n  H_{kl} := \\pdcross{Q}{X_k}{X_l} = - \\frac{m_k}{X_k^2} \\delta_{kl} - K_{kl}.\n\\end{equation}\nObserve that, apart from the diagonal, the Hessian matrix is independent of $\\mbf X$. The first step in determining $\\mbf X$ is to compute $\\mbf K$ from the component parameters and the $\\Delta$-function.\n\n\\subsection{Solution procedure for $\\mbf X$}\nAn attractive way to solve for $\\mbf X$ is formulating it as a maximation procedure. More precisely, one utilizes the fact that for a given $T$, $V$ and $\\mbf n$, the correct value of $\\mbf X$ is the value for which $Q$ is maximized. The maximization is unconstrained, the maximum unique, and global convergence can be assured. Michelsen \\cite{Michelsen06} suggests the following quasi-Newton iteration scheme:\n\\begin{equation}\n  \\label{quasiNewtonIteration}\n  \\mbf{\\hat H \\Delta X} + \\mbf g = 0,\n\\end{equation}\nwhere $\\mbf{\\hat H}$ is a modified Hessian matrix with the following properties\n\n\\begin{enumerate}[(i)]\n\\item It is negative definite for all $\\mbf X$\n\\item $\\mbf{\\hat H} \\to \\mbf H$ as $\\mbf X$ approaches the solution\n\\end{enumerate}\nProperty (i) ensures that $\\Delta \\mbf X$ is an ascent \\textit{direction}, because it has a positive projection along the gradient: $\\mbf g^T (-\\mbf{\\hat H}^{-1} \\mbf g) > 0$. However, overstepping is still a possibility, and in that case one can use a linesearch method, or, as we will do, simply bisect the step until an increase in $Q$ is obtained. Property (ii) ensures quadratic convergence.\n\nThe modification is performed as follows: From equations \\eqref{gDef} and \\eqref{hDef}, we see that the diagonal contribution of the hessian can be written as\n$$\n\\frac{m_k}{X_k^2} = \\frac{1}{X_k} \\frac{m_k}{X_k} = \\frac{1}{X_k} \\lp m_k + \\sum_{l=1}^S K_{kl} X_l + g_k \\rp.\n$$\nTo get the modified hessian $\\mbf H$ we simply drop the gradient contribution, giving\n\\begin{equation}\n  \\hat H_{kl} := \\pdcross{Q}{X_k}{X_l} = -\\frac{1}{X_k} \\lp m_k + \\sum_{l=1}^S K_{kl} X_l \\rp \\delta_{kl} - K_{kl}.\n\\end{equation}\nThat $\\hat H$ fulfills property (i) is shown in Michelsen \\cite{Michelsen06}, while property (ii) is obvious since $\\mbf g=0$ at the solution.\n% To show that $\\hat H$ is negative definite one uses the Gershgorin circle theorem, which states that given any eigenvalue $\\lambda \\in \\C$ of an $n \\times n$-matrix $(a_{ij})$, there must exist a $k \\in \\{1,\\ldots,n\\}$ such that $\\lambda$ is contained in the closed disk having center $a_{ii}$ and radius $\\sum_{j \\neq i} |a_{ij}|$.\nIn conclusion, Michelsen \\cite{Michelsen06} suggests the following approach for solving for $\\mbf X$:\n\\begin{enumerate}[(1)]\n\\item Choose an initial estimate of $\\mbf X$.\n\\item Calculate $\\Delta \\mbf X$ from equation \\eqref{quasiNewtonIteration}.\n\\item Set $\\mbf X^{new} = \\max(\\mbf X^{old} + \\Delta \\mbf X, 0.2 \\mbf X^{old})$, denying more than $80 \\%$ reduction in any component.\n\\item Test that $\\mbf X^{new} > 0$, and that the objective function is increased: $Q(\\mbf X^{new}) > Q(\\mbf X^{old})$.\n\\item If (4) is violated, set $\\Delta \\mbf X = \\tfrac{1}{2} \\Delta \\mbf X$ and repeat from step (3).\n\\item Check for convergence. If not converged, set $\\mbf X^{old} = \\mbf X^{new}$ and repeat from step (2).\n\\end{enumerate}\n\nWe have also implemented a back-up procedure if the maximization approach (1)-(6) should fail to converge in a few iterations. The back-up is the method of \\textbf{damped successive substitutions}. This iteration scheme is defined as follows:\n\\begin{equation}\n  \\label{successiveSubs}\n  \\mbf X^{(n+1)} = (1-\\omega) \\mbf f (\\mbf X^{(n)}) + \\omega \\mbf X^{(n)}, \\quad \\text{where} \\quad f_k(\\mbf X^{(n)}) := \\frac{m_k}{m_k + \\sum_{l=1}^S K_{kl} X_l^{(n)}}.\n\\end{equation}\nAlthough the damping parameter $\\omega$ in principle can be tailored to the specific $\\mbf f$, we will follow Michelsen \\cite{Michelsen06} and set $\\omega = 0.2$. With this terminology, the back-up procedure can be described as follows\n\\begin{enumerate}[(1')]\n\\item Set all elements $X_k = 0.2$ as the initial estimate.\n\\item Perform five iterations of successive substitutions with damping factor $\\omega = 0.2$.\n\\item Use the second-order approach above to converge the equations to desired accuracy.\n\\end{enumerate}\n\n\\subsection{Solution procedure for molar volume $v$}\nWhen solving for volume, a twofold nested calculation loop is required. The molar volume $v$ is adjusted in the outer loop, while the association equations must be solved for the matrix $X$ corresponding to the assumed volume in the inner loop. Having found $X$ in the inner loop, we will calculate not only the pressure contribution from the association term $P^{asc} = -RT \\pder{Q}{V}$, but also the two derivatives\n\\begin{equation}\n  \\label{advDeriv}\n  \\pder{\\mbf X}{V} \\quad \\text{and} \\quad \\pder{P^{asc}}{V}.\n\\end{equation}\nThe derivative $\\pder{\\mbf X}{V}$ is found from differentiating $\\mbf g(\\mbf X(V),V) = 0$, which by the chain rule yields\n\\begin{equation}\n  \\mbf H \\pder{\\mbf X}{V} + \\pder{\\mbf g}{V} = 0.\n\\end{equation}\nHere $\\mbf H$ is already found when solving for $\\mbf X$, seeing as $\\bf H = \\bf{\\hat H} - \\mathrm{diag}(\\bf g_k/\\bf X_k)_{k=1}^n$. The derivative $\\pder{P^{asc}}{V}$ is then found from\n\\begin{equation}\n  -\\frac{1}{RT} \\pder{P^{asc}}{V} = \\pdder{Q}{V}_{\\mbf X} + \\pder{\\bf g}{V}^T \\pder{\\bf X}{V}.\n\\end{equation}\nThe derivative of the association pressure is used in the outer loop to solve for volume using a Newton-based method, and the volume derivative of $\\mbf X$, which is obtained as a byproduced in the calculation of $\\pder{P^{asc}}{V}$, is used to create initial estimates (step (1) above) for the inner solution loop for $\\mbf X$. When a correction $\\Delta V$ has been determined from the Newton iteration in the outer loop, we use, as an initial estimate for the inner loop,\n\\begin{equation}\n  \\mbf X^{(n+1)} = \\mbf X^{(n)} + \\Delta V \\pder{\\mbf X}{V}.\n\\end{equation}\nThe tolerance for accepting an inner loop solution in the volume iteration is set fairly loose, and consequently only a single inner-loop iteration is necessary in most cases.\n\n\\textbf{Iterating on the reduced density $\\z$}\n\nMichelsen also offers the following suggestions for a CPA volume solver. First, a robust volume iteration should use the reduced density $\\zeta = b/v$ as the independent variable. Choose, as the equation to be solved to $0$, not $\\zeta \\mapsto P(\\zeta) - P^{spec}$, but as $F(\\z) = (1-\\z)(P(\\zeta) - P^{spec})$. \n\\begin{enumerate}\n\\item Initialization. For the liquid phase, $\\zeta = 0.99$ is to be used as initial estimate. For the vapor phase, use $\\zeta = b/(b+(RT/P))$. The initial limits should be set to $\\z_{min} = 0$, $\\z_{max} = 1$.\n\\item At step $k$, calculate a new value according to Newton's method:\n  \\begin{equation}\n    \\z_{new} = \\z_k - \\frac{(1-\\z_k)(P(\\z_k) - P^{spec})}{P^{spec} - P + (1-\\z_k)\\pder{P}{V}_{T,\\mbf n}V_k/\\zeta_k}.\n  \\end{equation}\n\\item If $\\z_{min} < \\z_{new} < \\z_{max}$, take $\\z_{k+1} = \\z_{new}$. Otherwise, take $\\z_{k+1} = (\\z_{min} + \\z_{new})/2$.\n\\item If $F(\\z_{k+1}) > 0$, set $\\z_{max} = \\z_{new}$; otherwise, set $\\z_{min} = \\z_{new}$.\n\\item Continue until convergence.\n\\end{enumerate}\n\n\\section{Testing the CPA code}\n\\subsection{Mathematical consistency}\nWe have implemented unittests for all the derivatives of all the functions occuring in the CPA implementation. Specifically, we have tested the following analytical derivatives against their numerical counterpart using finite differences:\n\\begin{itemize}\n  \\item \\(g(V,\\mbf n)\\), first and second derivatives;\n  \\item \\(Q(T,V,\\mbf n, \\mbf X)\\), first and second derivatives;\n  \\item \\(\\Delta^{A_i B_j}(T,V,\\mbf n)\\), first and second derivatives;\n  \\item \\(\\mbf X(T,V,\\mbf n)\\), first derivatives;\n  \\item \\(F(T,V,\\mbf n)\\), first and second derivatives;\n  \\item \\(P(T,V,\\mbf n)\\), first and second derivatives;\n  \\item \\(Z(T,V,\\mbf n)\\), first derivatives;\n  \\item \\(S^R(T,P,n)\\), first derivatives;\n  \\item \\(G^R(T,P,n)\\), first derivatives;\n  \\item \\(H^R(T,P,n)\\), first derivatives;\n  \\item \\(\\ln(\\phi)(T,P,n)\\), first derivatives.\n\\end{itemize}\n\n\\subsection{Thermodynamic consistency}\nWe have set up the supertest cpa\\_consistency, which is passed with reasonable tolerances. Thus, all of ThermoPack's implemented thermodynamic identities are fulfilled to a satisfactory accuracy.\n\n\\subsection{Testing physical predictions}\nWe tested what SRK-CPA gave as the liquid density of water at $277$ K, and compared it with SRK and PR.\n\\begin{itemize}\n\\item SRK-CPA: $1019$ $\\mathrm{kg}/\\mathrm{m}^3$.\n\\item SRK: $766$ $\\mathrm{kg}/\\mathrm{m}^3$.\n\\item PR: $859$ $\\mathrm{kg}/\\mathrm{m}^3$.\n\\end{itemize}\nWe thus see that the error of SRK-CPA ($1.9$ \\%) is about one order of magnitude smaller than that of SRK ($23.4$ \\%) and PR ($14.1$ \\%).\n\n\\subsection{Reduction to cubic equation}\nAlthough the CPA code does not handle pure components without association, we can trick the code to do so by assigning it an arbitrary association scheme, but with association parameters $\\epsilon = \\beta = 0$. By assigning $a_0$, $b$ and $c_1$ to be what they are in the SRK equation, SRK-CPA and SRK should be equivalent. We have verified that the two EoS indeed seem to give the same results, by computing the pressure at given $(T,V)$, and solving for the volume at given $(T,P)$.\n\n\\section{Overview of the CPA code}\n\\subsection{Cubic equations of state with fitted parameters} \\label{subsec:fitted parameters}\nThe usual formulation of PR and SRK for pure components is given by\n$$\nP = \\frac{RT}{v-b}-\\frac{a_0 \\alpha(T)}{(v+\\delta_1 b)(v+\\delta_2 b)},\n$$\nwith\n\\begin{equation}\n\\label{eq:a0}\n  a_0 = \\Omega_a \\frac{(RT_c)^2}{P_c}, \\quad b = \\Omega_b \\frac{RT_c}{P_c}, \\quad \\alpha(T) = \\lp 1+c_1(1-\\sqrt{T/T_c}) \\rp^2, \\quad c_1 = m(\\omega).\n\\end{equation}\nThe constants $\\delta_1, \\delta_2, \\Omega_a, \\Omega_b$ and the function $m$ are inherent to the equation of state. The critical temperature $T_c$, critical pressure $P_c$ and acentric factor $\\omega$ are properties of the component, and are needed to capture the peculiarities of the component. The specific forms of $a_0$ and $b$ result from demanding that $dP/dV = d^2P/dV^2 = 0$ at $(T,P) = (T_c,P_c)$, while the function $m$ was devised to fit the vapor pressure data of hydrocarbons.\n\nInstead of using the formulas \\eqref{eq:a0} to compute $a_0$, $b$ and $c_1$, one can also simply fit them (e.g. using liquid volume and vapor pressure data). This is usually necessary when the cubic term is not the only term in the full equation of state (as in e.g. CPA), simply because the formulas \\eqref{eq:a0} were derived under the assumption that the cubic contribution is the \\textit{only} contribution to pressure. Another approach is of course to retain the expressions \\eqref{eq:a0}, and to fit any parameters in the non-cubic terms accordingly. This latter approach does not seem reasonable, seeing as the first approach will always give a fit which is as least as good as the latter, and because the latter approach \\eqref{eq:a0} essentially forces the cubic equation to try to do something it wasn't designed to do (e.g. correlate vapor pressure of self-associating compounds).\n\nKontogeorgis and Folas \\cite{Kontogeorgis10} have compiled fitted parameters for $a_0$, $b$ and $c_1$ for use in the SRK-CPA equation. Their database covers both self-associating and non self-associating components. The parameters for some of the most common components have been recorded in ThermoPack, in the module cpa\\_parameters.\n\nIt should also be mentioned that although the classic alpha formulation $\\alpha(T) = (1+c_1((1-\\sqrt{T/T_c}))^2$ is most common, there is nothing in the way for using other alpha formulations, such as e.g. the well-known variants by Twu or Mathias.\n\n\\subsection{The Helmholtz energy in ThermoPack}\nOne needs to be careful when adding the contributions $F^{cb}$ and $F^{assoc}$ to get the total reduced residual Helmholtz energy $F$. In general we have that the reduced residual Helmholtz energy can be written as $F(T,V,\\mbf n) = k \\cdot \\tilde F(T,1000 V/k,\\mbf n/k)$, where $k$ is a constant, which happens to equal $\\sum_i n_i$. ThermoPack's cbhelm-module gives the derivatives of $\\tilde F$. Thus, to get the cubic contribution $F^{cb}$ to the total reduced residual Helmholtz energy, we need to use the following formulas:\n\\begin{align}\n    F^{cb} &=  k\\cdot\\tilde{F} \\\\\n    F^{cb}_T &=  k\\cdot\\tilde{F}_T \\\\\n    F^{cb}_V &=  1000\\cdot\\tilde{F}_V \\\\\n    F^{cb}_n &=  \\tilde{F}_n \\\\\n    F^{cb}_{TT} &= k \\cdot \\tilde{F}_{TT} \\\\\n    F^{cb}_{TV} &= 1000\\cdot\\tilde{F}_{VT} \\\\\n    F^{cb}_{Tn} &= \\tilde{F}_{nT} \\\\\n    F^{cb}_{VV} &= 1000\\cdot1000\\cdot\\tilde{F}_{VV}/k \\\\\n    F^{cb}_{Vn} &= 1000\\cdot\\tilde{F}_{nV}/k \\\\\n    F^{cb}_{nn}(i,j) &= \\tilde{F}_{nn}/k.\n\\end{align}\n\n\\subsection{New modules, and changes in existing modules}\nBelow we list the routines we have modified in order to implement CPA, ordered by module. This may be helpful if one is working in ThermoPack and sees some CPA-related code one doesn't understand.\n\n\\subsubsection*{cpa}\n\\textit{cpa\\_set\\_scheme\\_and\\_fitted\\_parameters}: This routine has different behavior depending on whether the mixture solvates or not. If it is not solvating, it does the following:\n\nIf the component is not in the CPA database, we use the standard (SRK or PR) values already\n\n If the component is in the CPA database, the parameters in the database are used\n\n\\textit{cpa\\_init}: Allocates memory, retrieves the relevant parameters from the module cpa\\_parameters, and finally uses the parameters together with the inputted mixing rules to initialize the global variables in the cpa-module. Note that cpa\\_init is called after selectEOS in init\\_thermoPack.\n\nThe routines in this module can be separated into two categories: back-end routines and front-end routines. The back-end routines sometimes assume that other routines have been called prior to calling it, a typical example being a routine that takes in X\\_k and (T,V,n), and assumes that \\textit{solve\\_for\\_X\\_k} has been called so that the inputted X\\_k is consistent with (T,V,n). The dependencies of a back-end routine are given before the code for the routine. The front-end routines have no such dependencies.\n\n\\subsubsection*{eoslibinit}\n\\textit{init\\_thermopack}: The cpa model is used if eosstr(1:3)=''CPA''.\\textit{SelectEOS} is called before \\textit{cpa\\_init}, since the global cbeos instance has to be initialized before \\textit{cpa\\_init} is called. Moreover, \\textit{cpa\\_init} is only called for the first component in the cbeos-vector, since we don't want to recalculate the global parameters in cpa.f90 over and over. For the other components, we call \\textit{cpa\\_set\\_scheme\\_and\\_fitted\\_parameters} (which involves some removable overhead since some things are done ncbeos times, but this isn't critical since it is an initialization routine).\n\n\\subsubsection*{cpa\\_parameters}\nA record of pure-component fitted parameters, as well as binary interaction coefficients. Note that the parameters $a_0$, $b$ and $\\omega$ are often replaced by fitted parameters.\n\nAs of now, the module cpa\\_parameters is in the file cpa\\_parameters.f90, but eventually it should probably be moved to tpinputdb.f90, where all other parameters are stored.\n\nWe point out that some common associating components (e.g. ethanol) are not stored in the module compdatadb, and therefore ThermoPack can not be initialized with these components.\n\nThe $c_1$ parameter is used only when ThermoPack is initialized with the classic alpha formulation. The fitted parameters $a_0$ and $b$, if they exist in the database, are per now always used for CPA. However, if one wants to use the ``standard'' (SRK or PR) values for these parameters in terms of critical properties, then one can simply iterate through the global comp-vector, set $a_0$ and $b$ equal to zero, and call the routine \\textit{cbCalcMixtureParams}. Using the fitted parameters if they exist seems like reasonable default behavior.\n\n\\subsubsection*{compdata}\nAdded the three parameters b\\_cpa, a0\\_cpa and c1\\_cpa in the gendata struct (which is the struct holding component data). These are initially set to zero, and then possibly -- depending on the options the user chooses and whether fitted values exist in the database -- updated to their fitted values in cpa\\_parameters.\n\n\\subsubsection*{eosdata}\nAdded the integer parameters cpaSRK and cpaPR, which will be set to eosidx in the global eoscubic-instance cbeos. Also added the integer parameter cbMixClassicCPA, which will be set to mruleidx in cbeos. The reason we need an own CPA-indicator for the classical (van der Waals) mixing rule, is that we need to retrieve the interaction parameters from the CPA\\_parameters database, and not the eosdatadb database where the other interaction parameters are stored.\n\n\\subsubsection*{tpselect}\n\\textit{selectEOS}: Initialize cbeos\\%eosidx to the integer parameter cpaSRK if eosstr='CPA-SRK'. Similarly for CPA-PR. Also cbeos\\%mruleidx is set to cbMixClassicCPA.\n\n\\textit{tpSelectInteractionParameters}: If cbeos\\%mruleidx=cbMixClassicCPA, retrieve interaction parameters from the cpa\\_parameters database if they exist. If not, use the interaction parameters from the usual eosdatadb database.\n\n\\textit{copyFromDB}: Called from \\textit{SelectComp}, this helper function now also sets component\\%b\\_cpa=0.0, component\\%a0\\_cpa=0.0 and component\\%c1\\_cpa=0.0.\n\n\\subsubsection*{tpcbmix}\n\\textit{cbCalcParameters}: cpaSRK and cpaPR are assigned the same alpha, beta, delta and gamma as cbSRK and cbPR, respectively. However, $(\\alpha,\\beta,\\gamma)$ are only used to compute $m(\\omega)=\\alpha + \\beta \\omega - \\gamma \\omega^2$ if $c_1$ isn't fitted (i.e. if it is set to $0.0$ in the global eoscubic-instance cbeos).\n\n\\textit{cbCalcM}: cpaSRK and cpaPR behaves the same way as cbSRK and cbPR, namely that cbeos\\%m1 and cbeos\\%m2 are calculated. The denominator in the attractive part of the cubic EoS is then m1 times m2.\n\n\\textit{cbCalcOmegaZc}: This routine computes many single-component properties, amongst other a0 and b. Therefore we have to stipulate that, in the case of a CPA model, b\\_cpa and a0\\_cpa should be used.\n\n\\textit{cbCalcAmix}: No significant changes; cbMixClassicCPA should behave the same way as cbMixClassic, i.e. call vanderWaalsMix.\n\n\\subsubsection*{cbAlpha}\n\n\\textit{calcAlpha\\_classic\\_CPA}: New routine. Does the same as calcAlpha\\_classic, except that instead of using $m(\\omega)=\\alpha + \\beta \\omega - \\gamma \\omega^2$, it uses the fitted parameter $c_1$ stored in the global comp-vector.\n\n\\textit{cbCalcAlphaTerm}: If cbeos\\%eosidx equals cpaSRK or cpaPR, and if one uses the classical alpha correlation, then we should use the fitted parameter if it has been set, and the usual formulation $\\alpha$-formulation using $m(\\omega)$ if not.\n\n\\subsubsection*{tpsingle}\nThe only changes made were that the following functions also works with CPA: \\textit{TP\\_CalcZfac}, \\textit{TP\\_CalcEnthalpy}, \\textit{TP\\_CalcEntropy}, \\textit{TP\\_CalcFugacity}, \\textit{TP\\_CalcPressure}, \\textit{Gres}.\n\n\\section{Adapting pure component parameters}\nThere does not seem to be any readily available CPA-parameters for $CO_2$ modeled as an associating component. We have therefore fitted the five pure component parameters $a_0,b,c_1,\\epsilon,\\beta$ to PVT-points on $CO_2$'s boiling point curve, using the association scheme 1 (i.e. modeling $CO_2$ as having one association site). The objective function minimized was\n$$\nO(\\Lambda) = \\sum_i \\left[ \\lp \\frac{P_{bub}(T_i^{exp};\\Lambda)-P^{exp}}{P^{exp}}\\rp^2 + \\lp \\frac{v_{liq}(T_i^{exp},P_i;^{exp}\\Lambda)-v_{liq}^{exp}}{v_{liq}^{exp}} \\rp^2 \\right],\n$$\nwhere $\\Lambda = (a_0,b,c_1,\\epsilon,\\beta)$ represents the adjustable parameters. According to \\cite{Kontogeorgis10} one should use PVT data on the boiling point curve ranging from reduced temperatures 0.5 to 0.95. Extending the reduced temperature to values close to one is of minor importance, since association models overpredict the critical temperature.\n\nNote that we have chosen to minimize the squared deviations -- not the squared \\textit{relative} deviations -- since we want to weight more the deviations near the critical point (high pressures).\n\nThe resulting parameters have been stored in the parameter database, \\textit{cpa\\_parameters.f90}.\n\n%\\appendix\n%\\clearpage\n\n\\begin{thebibliography}{11}\n\n\\bibitem{Gross01} Gross J., Sadowski G. Perturbed-Chain SAFT: An Equation of State Based on a Perturbation Theory for Chain Molecules. \\textit{Industrial and Engineering Chemistry Research} \\textbf{2001}, 40, 1244--1260.\n\\bibitem{Kontogeorgis10} Kontogeorgis, Georgis M. and Folas, Georgios K., Thermodynamic Models for Industrial Applications, Wiley 2010\n\\bibitem{Michelsen01} Michelsen M.L., Hendriks E.M. Physical Properties from Association Models. \\textit{Fluid Phase Equilibria} \\textbf{2001}, 180, 165--174.\n\\bibitem{Michelsen06} Michelsen M.L. Robust and Efficient Solution Procedures for Association Models. \\textit{Industrial and Engineering Chemistry Research} \\textbf{2006}, 45, 8449--8453.\n\\bibitem{Muller01} M{\\\"u}ller E.A., Gubbins K.E. Molecular-Based Equations of State for Associating Fluids: A Review of SAFT and Related Approaches. \\textit{Industrial and Engineering Chemistry Research} \\textbf{2001}, 40, 2193--2211.\n\\bibitem{Kontogeorgis10} Kontogeorgis, G.M., Folas, G.K. \\textit{Thermodynamic Models for Industrial Applications}. Wiley 2010.\n\n\\end{thebibliography}\n\n\\end{document}", "meta": {"hexsha": "346fc5076a89dc2992c3ef033d5e03af0e8d7e00", "size": 54518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/memo/CPA/cpa.tex", "max_stars_repo_name": "SINTEF/Thermopack", "max_stars_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-10-14T07:51:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T04:59:23.000Z", "max_issues_repo_path": "doc/memo/CPA/cpa.tex", "max_issues_repo_name": "SINTEF/Thermopack", "max_issues_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2020-10-26T11:43:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:06:30.000Z", "max_forks_repo_path": "doc/memo/CPA/cpa.tex", "max_forks_repo_name": "SINTEF/Thermopack", "max_forks_repo_head_hexsha": "63c0dc82fe6f88dd5612c53a35f7fbf405b4f3f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-10-27T13:04:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T04:59:24.000Z", "avg_line_length": 76.0362622036, "max_line_length": 891, "alphanum_fraction": 0.693037162, "num_tokens": 19020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6101583568907722}}
{"text": "\\chapter{Co-occurrence Networks}\n\\pagenumbering{arabic} \\setcounter{page}{18}\n\nThe microbes do not dwell in isolation; instead, they thrive in colonies and form associations. These associations shape the patterns and structure of their microscopic world, which administers the macroscopic world. For example, the gut microbiome regulates the food choices of an individual. The interaction patterns among these microbes are directed by their evolutionary cycle and inter/intra-species interactions. They can have a positive association like mutualism, commensalism, synergism, or negative associations like competition, parasitism, predation \\cite{weiss_2016_correlation}. To analyse these associative patterns, microbiologists have implemented the concepts of networks science onto these associations. The graphical form of these pairwise associations is called a microbial co-occurrence network. The nodes of the networks denote the microbial species, and the edges of the network describe the statistically significant association. These co-occurrence networks also help determine the critical microbial species or hubs dominating a particular community.\\newline\n\nHowever, drawing adequate ecological conclusions from an entirely mathematical concept is not advisable. Criticisms have been made about co-occurrence networks for predicting non-trophic interactions, which calls for integrating community-level insights. Studies have shown that processes like habitat filtering should be considered while generating the co-occurrence networks to draw ecologically sound conclusions. \\emph{Goberna et al} have compared the effect of habitat filtering, spatial limitation, and biological interactions in governing the community patterns; the study found that habitat filtering and natural interactions are much more predominant than dispersal limitations \\cite{ref10}. This might suggest that associations form independent of their geographical location. They also explained the need to consolidate phylogenetic measure into the downstream analysis to make the networks a close imitation of nature. One might overshadow that the microbes can interact with more than one neighbour, which gives triplet or quadrupole interactions, rather than a pairwise interaction \\cite{berry_2014_deciphering}. This section discusses widely used measures in co-occurrence networks design, such as Pearson correlation, Spearman Correlation and Bray-Curtis similarity measure.\n\n\\section{Pearson's Correlation}\nThe Pearson's Correlation (PC) estimates the magnitude of the linear covariance between two independent variables \\cite{schober_2018_correlation}. The data should be randomly sampled and devoid of outliers showing linear patterns in a scatter-visual test. It assumes that data follows normal distribution the values of a variable are not correlated to themselves \\cite{schober_2018_correlation}. The test works with continuous data points sampled or for a paired observation. In terms of co-occurrence networks, the microbial pair forms an {x,y} set of statements, given that there is no correlation between $x_{i}$ or $x_{n}$/$y_{i}$ or $y_{n}$, where (i = 1). Pearson's correlation calculates three measures, i.e. Coefficient (r), Coefficient of determination ($R^{2}$), and p-value. The r tells the direction and strength to which the x and y are correlated. The r can range between (-1,1), with -1 suggestive of a strong negative correlation and 1 suggestive of a strong positive correlation. The $R^{2}$ explains the variation shared between the x and y, and it can range between (0,1). Lastly, the p-value measures the evidence against the null hypothesis ($H_{0}$) that there is no correlation between x and y. The working formula boils down to dividing the covariance by the product of the standard deviations,\n\n$$r_{xy} = \\frac{\\sum_{i=1}^{n} (X_{i} - \\bar{X}) * (Y_{i} - \\bar{Y})}{\\sqrt{\\sum_{i=1}^{n} (X_{i} - \\bar{X})^{2}} * \\sqrt{\\sum_{i=1}^{n} (Y_{i} - \\bar{Y})^{2}}}$$\n\n\\section{Spearman's Correlation}\nThe Spearman's Correlation (SC) estimates magnitude \\& direction of the monotonic relation among the two ranked variables \\cite{dewinter_2016_comparing}. The SC is implemented on the ordinal data rather than continuous data. It assumes a monotonic association between the variables, i.e. if one is changing, the other remains the same. The SC is well suited for explaining interactions like amensalism. It does not assume the data to be normally distributed and works by ranking the variables first. As the variables are ranked according to their magnitude, they can be implemented on both ordinal and continuous datasets. Pearson's correlation calculates three measures, i.e. Coefficient ($r_{s}$) and p-value. The rs tells the direction and strength to which the x and y are correlated. The $r_{s}$ can range between (-1,1), with -1 suggestive of a perfect negative correlation and 1 suggestive of a perfect positive correlation \\cite{dewinter_2016_comparing}. Lastly, the p-value measures the evidence against the null hypothesis ($H_{0}$) that there is no correlation between x and y. The working formula boils down to dividing the Pearson correlation over the (mean) ranks,\n\n$$r_{s} = 1 - \\frac{6 * \\sum D^{2}}{n^{3} - n}$$\n\n\\section{Bray Curtis Dissimilarity}\nThe Bray Curtis Dissimilarity (BC) quantifies the dissimilarity between the species between two different sites. In terms of microbial ecology, one can say it measures the beta-diversity by comparing the alpha-diversity \\cite{zhang_2019_the}. It falls between 0 to 1, with 0 suggesting that they are identical, and one is suggestive of 100 per cent dissimilar. The BC dissimilarity assumes that both the sampling sites have either the same size or same volume as the BC does not integrate the notion of space \\cite{zhang_2019_the}. The BC can be calculated by dividing the sum of lesser counts of species found in both sites by the sum of the alpha-diversity measure of each site,\n\n$$BC_{ij} = 1 - \\frac{2 * C_{ij}}{S_{i} + S_{j}}$$", "meta": {"hexsha": "ca7473c7185b749b577adf15d0f8f0c0d8712f08", "size": 6006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "literatureReview/tex/ch6.tex", "max_stars_repo_name": "spriyansh/metagenomics-CSG-2021", "max_stars_repo_head_hexsha": "bfa93af6bb8631ee0e19ac6005db72bbf18f0fae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "literatureReview/tex/ch6.tex", "max_issues_repo_name": "spriyansh/metagenomics-CSG-2021", "max_issues_repo_head_hexsha": "bfa93af6bb8631ee0e19ac6005db72bbf18f0fae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "literatureReview/tex/ch6.tex", "max_forks_repo_name": "spriyansh/metagenomics-CSG-2021", "max_forks_repo_head_hexsha": "bfa93af6bb8631ee0e19ac6005db72bbf18f0fae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 286.0, "max_line_length": 1318, "alphanum_fraction": 0.7977022977, "num_tokens": 1338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6101583423863525}}
{"text": "\n\\documentclass[letterpaper, 10 pt, conference]{ieeeconf}  \n\\IEEEoverridecommandlockouts                             \n\\usepackage{graphicx} \n\\usepackage{hyperref}\n\\usepackage{url}\n\n\\overrideIEEEmargins\n\n\\title{\\Huge Target Tracking}\n\\author{Jiyu Tian} \n\n\\begin{document}\n\n\\maketitle\n\\thispagestyle{empty}\n\\pagestyle{empty}\n\n\n\n\n%-------------------------------\n\\section{INTRODUCTION}\nThe Circulant Matrix (CM) tracker is very efficient finding a translated copy of the target template from the previous frame by computing many convolutions in a single shot. This is accomplished by finding the peak response of a filter applied to a region of the current frame that is expected to include the target. This filter changes from frame to frame and it is computed based on the FFT of a larger region which contains the target in the current frame. Efficiency is obtained by applying this filter in the frequency domain. \n\n\n\n%-------------------------------\n\\section{ALGORITHMS DESCRIPTION}\n\n\\subsection{Basic Algorithm}\nThe papers describing the algorithm and the code for this tracker is available at:\n\\url{http://www.robots.ox.ac.uk/~joao/#publications}\nand\n\\url{http://www.robots.ox.ac.uk/~joao/circulant/}.\n\n%-------------------------------\n%-------------------------------\n\\subsection{Detecting Occlusion}\nChecking for occlusion can be fulfilled by including a test that measures the response of the filter against the rest of the search window through the use of the ``Peak to Sidelobe Ratio'' (PSR).\n\n\nThe response of the filter is split into the maximum value and the “sidelobe” consisting of the rest of the pixels in the region, excluding a small window (i.e. $11 \\times 11$) around the peak. Then the PSR is defined as:\n\\begin{equation}\n    \\frac{g_{max} - \\mu}{\\sigma}\n\\end{equation}\nwhere $g_{max}$ is the value of the peak, and $\\mu$, $\\sigma$ are the mean value and the standard deviation of the sidelobe, respectively. A low PSR indicates a poor match and a possible occlusion. If occlusion is detected, the tracker should stop or attempt to hallucinate the target until it can detect it again.\n\n\n\n\n\n%-------------------------------\n%-------------------------------\n\\subsection{Recovery from Occlusion}\nWhen occlusion is detected, the tracker could use the locations of the target in the past to predict where the target is now (even if it is behind some occluding object) and predict where it should be in the next frame. In this way, rather than giving up, the tracker can attempt to find the target in the next frame at this predicted location. The prediction of the location of the target based on previous measurements can be done using one of many possible methods that we will discuss in class. Among them, the Hankel matrix of the target locations or a simple dynamic model such as constant velocity are taken into consideration.\n\n\n\n\n%-------------------------------\n\\section{EXPERIMENTAL RESULTS}\nWe use the \\textit{Occluded Face} dataset for this report. In Fig \\ref{resp}, while the book crosses in front of the human face, noise is introduced to the response values across image. As the book settles for a couple frames, the noise gradually dies down as the tracker \"learns\" what the book looks like.\n\n\n\\begin{figure}[thpb]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{response.png}\n\\caption{Response}\n\\label{resp}\n\\end{figure}\n\n\nBy computing the PSR, we can estimate how certain the tracker is a particular point represents the center of the tracked object. Low ratio indicates that the tracker is less certain of the outcome with weight being spread across a number of possible pixels. This uncertainty could also represent an occlusion. By thresholding the PSR value, we could estimate when the tracked target was occluded.\n\nAs shown in Fig \\ref{psr}, whenever the book crosses over the human face, an occlusion is detected. It is always tricky to determine a proper threshold value for detection.\n\n\n\\begin{figure}[thpb]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{psr.png}\n\\caption{PSR}\n\\label{psr}\n\\end{figure}\n\nFig \\ref{preg} shows our tracking results (OCC) against the original CM tracker and the original MIL tracker. When threshold is larger than $19$, OCC performs better than CM tracker.\n\n\n\\begin{figure}[thpb]\n\\centering\n\\includegraphics[width=0.48\\textwidth]{precisionall.png}\n\\caption{Precision Graph}\n\\label{preg}\n\\end{figure}\n\nSome selections of result figures are shown in Fig \\ref{result}.\n\n\n\\newpage\n\n\n\\begin{figure}[thpb]\n\\centering\n\\includegraphics[width=0.491\\textwidth]{result.png}\n\\caption{Precision Graph}\n\\label{result}\n\\end{figure}\n\n\n\n\n%-------------------------------\n\\section{CONCLUSION}\nIn this project, we improved the CM tracker by implementing an occlusion detection test as well as trying to recover from occlusion. We also explored influence from various parameters, as well as the limitation of the method.\n\n\n\n\n%-------------------------------\n\\section{Acknowledgements}\nThe original Circulant Matrix Tracker from the following paper: \\textit{Henriques, Joao F., et al. \"Exploiting the circulant structure of tracking-by-detection with kernels.\" European conference on computer vision. Springer, Berlin, Heidelberg, 2012.}\n\n\n\\end{document}\n", "meta": {"hexsha": "f75973f5b3e9cafe5ea0b50ccb16d9723c6cf713", "size": 5209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5639-Computer-Vision/Project-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": "EECE5639-Computer-Vision/Project-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": "EECE5639-Computer-Vision/Project-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": 41.672, "max_line_length": 634, "alphanum_fraction": 0.7360337877, "num_tokens": 1192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.8311430562234878, "lm_q1q2_score": 0.6101583375515458}}
{"text": "\\subsubsection{Re-Orthogonalization of LMOs}\\label{reorth}\r\nDuring the course of a long calculation, the LMOs will become increasingly\r\nnon-orthogonal.  Subroutine \\comp{CHECK} ensures that the LMOs remain\r\nnormalized; this is a very rapid calculation.  Ensuring that the LMOs are all\r\northogonal is not so simple.  Re-orthogonalizing the LMOs is a lengthy\r\ncalculation, and is not routinely performed.  However, the option exists to\r\nre-orthogonalize the LMOs, and this can be done either during a \\comp{1SCF}\r\ncalculation (the preferred way), or periodically during a geometry\r\noptimization.\r\n\r\nRe-orthogonalizing consists of taking pairs of LMOs, $\\psi_i$ and $\\psi_j$, and\r\nforming linear combinations such that the overlap ($<\\!\\psi_i|\\psi_j\\!>$) is\r\nzero.  The LMOs involved form the full set, that is, both occupied  plus\r\nvirtual sets are used.\r\n\r\nThe two LMOs can be regarded as unit vectors that are almost at 90$^{\\circ}$ to\r\neach other.  Let the difference from  90$^{\\circ}$ be $\\alpha$.  If the vectors\r\nare each rotated by -$\\frac{1}{2}\\alpha$, then they will become perfectly\r\northogonal. This operation is most conveniently performed using perturbation\r\ntheory. Let:\r\n$$\r\n<\\!\\psi_i|\\psi_i\\!> \\simeq 1 \\simeq <\\!\\psi_j|\\psi_j\\!>\r\n$$\r\nand \r\n$$\r\n|<\\!\\psi_i|\\psi_j\\!>| = S_{ij} \\ll 1,\r\n$$\r\nthen\r\n$$\r\n\\psi_i' = \\psi_i - \\frac{1}{2}S_{ij}\\psi_j\r\n$$\r\nand \r\n$$\r\n\\psi_j' = \\psi_j - \\frac{1}{2}S_{ij}\\psi_i.\r\n$$\r\n\r\nThat the new LMOs are orthogonal can readily be demonstrated:\r\n\\begin{eqnarray}\r\n<\\!\\psi_i'|\\psi_j'\\!> &=&<(\\psi_i - \\frac{1}{2}S_{ij}\\psi_j)|\r\n(\\psi_j - \\frac{1}{2}S_{ij}\\psi_i)\\!> \\nonumber \\\\\r\n &=&<\\psi_i|\\psi_j>-\\frac{1}{2}S_{ij}<\\!\\psi_i|\\psi_i>-\r\n\\frac{1}{2}S_{ij}<\\!\\psi_j|\\psi_j\\!>+\\frac{1}{4}S_{ij}^2<\\!\\psi_j|\\psi_i\\!> \r\n\\nonumber \\\\\r\n&=& S_{ij}-\\frac{1}{2}S_{ij}-\\frac{1}{2}S_{ij} +\\frac{1}{4}S_{ij}^3 \\nonumber \\\\\r\n&=& 0 \\nonumber\r\n\\end{eqnarray}\r\n\r\nThe calculation of the overlaps, $S_{ij}$, is most conveniently done for one\r\nLMO, $\\phi_i$, with all other LMOs.  Because of this, $\\phi_i$ should not be\r\nmodified while the re-orthogonalization is done.  In order to avoid modifying\r\n$\\phi_i$, the rotation is changed so that $\\phi_i$ remains stationary and all\r\nthe rotation is incurred by $\\phi_j$, thus:\r\n$$\r\n\\psi_i' = \\psi_i \r\n$$\r\nand\r\n$$\r\n\\psi_j' = \\psi_j - S_{ij}\\psi_i.\r\n$$\r\n\r\nBefore the re-orthogonalization, the LMOs are almost orthogonal, and the use of\r\nperturbation theory here is fully justified.\r\n", "meta": {"hexsha": "a92a6a0ccb7b4e972fd23b949f82e908c2be3c41", "size": 2446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuals/MOPAC2000_manual/reorth.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/reorth.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/reorth.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": 38.8253968254, "max_line_length": 81, "alphanum_fraction": 0.6860179886, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.6926419894793246, "lm_q1q2_score": 0.6100770490874291}}
{"text": "\\clearpage\n\\subsection{Vector Carry-less Multiply}\n\nThe following instructions support vectorised Carry-less multiply\noperations.\nThese are essential to support the Galois/Counter Mode (GCM) \\cite{nist:gcm}\nblock cipher mode of operation.\nGCM is the only mandatory mode of operation in the TLS 1.3\nciphersuite \\cite[Section 9.1]{tls:1.3}.\n\n\n\\subsubsection{Single-Width Carry-less Multiply}\n\\label{sec:vector:clmul:hilo}\n\n\\begin{cryptoisa}\nvclmul.vv   vrd, vrs1, vrs2 // vrd[i]  = vrs1[i] * vrs2[i] (low SEW-bits)\nvclmul.vs   vrd, vrs1, vrs2 // vrd[i]  = vrs1[0] * vrs2[i] (low SEW-bits)\nvclmulh.vv  vrd, vrs1, vrs2 // vrd[i]  = vrs1[i] * vrs2[i] (hi  SEW-bits)\nvclmulh.vs  vrd, vrs1, vrs2 // vrd[i]  = vrs1[0] * vrs2[i] (hi  SEW-bits)\n\\end{cryptoisa}\n\nThese instructions multiply corresponding \\SEW-bit elements\nto produce a $2*\\SEW$-bit result.\n{\\tt vclmul.*} writes back the low \\SEW bits of the result to the\nelement in \\vrd.\n{\\tt vclmulh.*} writes back the high \\SEW bits of the result to the\nelement in \\vrd.\n\nThe vector-vector ({\\tt *.vv}) instructions multiply corresponding\nelements in each vector.\nThe vector-scalar ({\\tt *.vs}) instructions multiply the zeroth\nelement of \\vrs{1} with the $i'th$ element of \\vrs{2}.\nThe results of each instruction are always written back to the $i'th$\nelement of \\vrd.\n\n\n\\subsubsection{Single-Width Carry-less Multiply with Accumulate}\n\\label{sec:vector:clmul:accumulating}\n\n\\begin{cryptoisa}\nvclmacc.vv  vrd, vrs1, vrs2 // vrd[i] += vrs1[i] * vrs2[i] (low SEW-bits)\nvclmacc.vs  vrd, vrs1, vrs2 // vrd[i] += vrs1[0] * vrs2[i] (low SEW-bits)\nvclmacch.vv vrd, vrs1, vrs2 // vrd[i] += vrs1[i] * vrs2[i] (hi  SEW-bits)\nvclmacch.vs vrd, vrs1, vrs2 // vrd[i] += vrs1[0] * vrs2[i] (hi  SEW-bits)\n\\end{cryptoisa}\n\nThese instructions multiply \\SEW-bit elements\nto produce a $2*\\SEW$-bit intermediate.\n{\\tt vclmul.*} adds the low \\SEW bits of the intermediate to the\n\\SEW-bit element \\vrd, and writes the result back to \\vrd.\n{\\tt vclmulh.*} adds the high \\SEW bits of the intermediate to the\n\\SEW-bit element \\vrd, and writes the result back to \\vrd.\nNote that addition in this context is carry-less, and is simply an {\\tt xor}\noperation.\n\nThe vector-vector ({\\tt *.vv}) instructions operate on corresponding\nelements in each vector.\nThe vector-scalar ({\\tt *.vs}) instructions operate on the zeroth\nelement of \\vrs{1} with the $i'th$ elements of \\vrs{2} and \\vrd.\n\n\n\\subsubsection{Widening Carry-less Multiply}\n\\label{sec:vector:clmul:widening}\n\n\\begin{cryptoisa}\nvwclmul.vv  vrd, vrs1, vrs2 // vrd[i] = vrs1[i] * vrs2[i], LMUL(vrd)=2\nvwclmul.vs  vrd, vrs1, vrs2 // vrd[i] = vrs1[0] * vrs2[i], LMUL(vrd)=2\n\\end{cryptoisa}\n\nThese instructions multiply \\SEW-bit elements\nto produce a $2*\\SEW$-bit result.\nThe $2*\\SEW$-bit result is written back in its entirety to \\vrd,\nwhere \\vrd is treated as a double-width register such that\n$\\LMUL=2$ and $\\EEW(\\vrd)=2*\\SEW$.\n\nThe vector-vector ({\\tt *.vv}) instructions operate on corresponding\nelements in each vector.\nThe vector-scalar ({\\tt *.vs}) instructions operate on the zeroth\nelement of \\vrs{1} with the $i'th$ elements of \\vrs{2} and \\vrd.\n\n\n\\subsubsection{Widening Carry-less Multiply With Accumulate}\n\\label{sec:vector:clmul:widening}\n\n\\begin{cryptoisa}\nvwclmacc.vv vrd, vrs1, vrs2 // vrd[i] += vrs1[i] * vrs2[i], LMUL(vrd)=2\nvwclmacc.vs vrd, vrs1, vrs2 // vrd[i] += vrs1[0] * vrs2[i], LMUL(vrd)=2\n\\end{cryptoisa}\n\nThese instructions multiply \\SEW-bit elements\nto produce a $2*\\SEW$-bit intermediate.\nThe $2*\\SEW$-bit intermediate is added to the $2*\\SEW$-bit element in \\vrd.\nThe result is then written back to \\vrd.\n\\vrd is treated as a double-width register such that\n$\\LMUL=2$ and $\\EEW(\\vrd)=2*\\SEW$.\nNote that addition in this context is carry-less, and is simply an {\\tt xor}\noperation.\n\nThe vector-vector ({\\tt *.vv}) instructions operate on corresponding\nelements in each vector.\nThe vector-scalar ({\\tt *.vs}) instructions operate on the zeroth\nelement of \\vrs{1} with the $i'th$ elements of \\vrs{2} and \\vrd.\n\n", "meta": {"hexsha": "093d6659389596f5d784509efe77be00c4b54f3f", "size": 4007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old-tex/tex/sec-vector-clmul.tex", "max_stars_repo_name": "dingiso/riscv-crypto", "max_stars_repo_head_hexsha": "608f550ea2a791fb091133fe6050321545dfc547", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 199, "max_stars_repo_stars_event_min_datetime": "2020-08-13T15:48:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T13:57:34.000Z", "max_issues_repo_path": "doc/old-tex/tex/sec-vector-clmul.tex", "max_issues_repo_name": "dingiso/riscv-crypto", "max_issues_repo_head_hexsha": "608f550ea2a791fb091133fe6050321545dfc547", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 118, "max_issues_repo_issues_event_min_datetime": "2020-08-13T16:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T20:00:35.000Z", "max_forks_repo_path": "doc/old-tex/tex/sec-vector-clmul.tex", "max_forks_repo_name": "dingiso/riscv-crypto", "max_forks_repo_head_hexsha": "608f550ea2a791fb091133fe6050321545dfc547", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2020-08-28T16:09:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T10:10:58.000Z", "avg_line_length": 38.5288461538, "max_line_length": 76, "alphanum_fraction": 0.7162465685, "num_tokens": 1389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6100770335762126}}
{"text": "\\section{Volume}{}{}\\label{sec:volume}\nNow that we have seen how to compute certain areas by using integration; we will now look into how some\nvolumes may also be computed by evaluating an integral. Generally, the\nvolumes that we can compute this way have cross-sections that are easy\nto describe.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%\\begin{figure}\n%\\centering\n%\\includegraphics[width=0.2\\textwidth]{/figures/figcross1_3D}\n%\\caption{The volume of a general right cylinder}\n%\\label{fig:cross1}\n%\\end{figure}\n\n\t\t\t\n\n\\figure[H]\n%\\texonly\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <0.3truecm,0.3truecm>\n\\setplotarea x from -10 to 10, y from -3 to 20\n\\axis bottom shiftedto y=0 ticks withvalues {$x_i$} / at 7 / /\n\\put {\\hbox{\\epsfxsize9truecm\\epsfbox{images/pyramid_steps.eps}}} at 30 10\n\\put {$y_i\\rightarrow$} [l] <-5pt,-1truept> at -10 6\n\\plot -10 0 0 20 10 0 /\n\\putrule from -10 0 to -10 1\n\\putrule from -10 1 to 10 1\n\\putrule from 10 1 to 10 0\n\\putrule from -9.5 1 to -9.5 2\n\\putrule from -9.5 2 to 9.5 2\n\\putrule from 9.5 2 to 9.5 1\n\\putrule from -9 2 to -9 3\n\\putrule from -9 3 to 9 3\n\\putrule from 9 3 to 9 2\n\\putrule from -8.5 3 to -8.5 4\n\\putrule from -8.5 4 to 8.5 4\n\\putrule from 8.5 4 to 8.5 3\n\\putrule from -8 4 to -8 5\n\\putrule from -8 5 to 8 5\n\\putrule from 8 5 to 8 4\n\\putrule from -7.5 5 to -7.5 6\n\\putrule from -7.5 6 to 7.5 6\n\\putrule from 7.5 6 to 7.5 5\n\\putrule from -7 6 to -7 7\n\\putrule from -7 7 to 7 7\n\\putrule from 7 7 to 7 6\n\\putrule from -6.5 7 to -6.5 8\n\\putrule from -6.5 8 to 6.5 8\n\\putrule from 6.5 8 to 6.5 7\n\\putrule from -6 8 to -6 9\n\\putrule from -6 9 to 6 9\n\\putrule from 6 9 to 6 8\n\\put {$\\vdots$} at 0 13\n\\endpicture}\n%\\caption{\n%Volume of a pyramid approximated by rectangular prisms.\n%(\\expandafter\\url\\expandafter{\\liveurl pyramid.html}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:pyramid}\n%\\htmlfigure{Integration_applications-volume_pyramid.html}\n%\\htmlonly\n\\caption{\\label{fig:pyramid}\nVolume of a pyramid approximated by rectangular prisms.}\n%\\endhtmlonly\n\\endfigure\n\n\\begin{example}{Volume of a Pyramid}{Volume of a Pyramid}\\label{Volume of a Pyramid}\nFind the volume of a pyramid with a square base that is 20 meters tall\nand 20 meters on a side at the base. \n\\end{example}\n\n\\begin{solution}\nAs with most of our applications\nof integration, we begin by asking how we might approximate the\nvolume. Since we can easily compute the volume of a rectangular prism\n(that is, a ``box''), we will use some boxes to approximate the volume of\nthe pyramid, as shown in figure~\\ref{fig:pyramid}: On the left is a\ncross-sectional view, on the right is a 3D view of part of the pyramid\nwith some of the boxes used to approximate the volume.\n\nEach box has volume of the form $\\ds (2x_i)(2x_i)\\Delta y$. Unfortunately,\nthere are two variables here; fortunately, we can write $x$ in terms\nof $y$: From the cross-sectional view we see that a height of 20 is achieved at the midpoint of the base. We will also position the cross-sectional view symmetrically about the $y$-axis. Thus at $x=0$, $y=20$, and we have a slope of $m=-2$. So\n\\begin{align*}\ny&=-2x+b\t\\\\\n20&=-2(0)+b\t\\\\\n20&=b.\n\\end{align*}\n\nTherefore, $y=20-2x$, and in the terms of $x$: $x=10-y/2$ or $\\ds x_i=10-y_i/2$. Then the total volume is\napproximately\n$$\\sum_{i=0}^{n-1} 4(10-y_i/2)^2\\Delta y$$\nand in the limit we get the volume as the value of an integral:\n$$\n  \\int_0^{20} 4(10-y/2)^2\\,dy=\\int_0^{20} (20-y)^2\\,dy=\n  \\left.-{(20-y)^3\\over3}\\right|_0^{20}=\n  -{0^3\\over3}--{20^3\\over3}={8000\\over3}.\n$$\nAs you may know, the volume of a pyramid is \n$(1/3)(\\hbox{height})(\\hbox{area of base})=(1/3)(20)(400)$, which\nagrees with our answer.\n\\end{solution}\n\n\\begin{example}{Volume of an Object}{Volume of an Object}\\label{Volume of an Object}\nThe base of a solid is the region between $\\ds f(x)=x^2-1$ and\n$\\ds g(x)=-x^2+1$, and its cross-sections perpendicular to the $x$-axis \nare equilateral triangles, as indicated in\nFigure~\\xrefn{fig:triangular cross-sections}.\n%\\texonly\nThe solid has been truncated to show a triangular\ncross-section above $x=1/2$.\n%\\endtexonly\nFind the volume of the solid.\n\\end{example}\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1.1 to 1.1, y from -1.1 to 1.1\n\\put {\\hbox{\\epsfxsize6truecm\\epsfbox{images/triangular_solid.eps}}} at 3 0\n\\axis bottom shiftedto y=0 ticks withvalues {$-1\\quad$} {$1$} / at -1 1 / /\n\\axis left shiftedto x=0 ticks withvalues {$-1\\quad$} {$1\\quad$} / at -1 1 / /\n\\plot\n-1.000 0.000 -0.900 -0.190 -0.800 -0.360 -0.700 -0.510 -0.600 -0.640 \n-0.500 -0.750 -0.400 -0.840 -0.300 -0.910 -0.200 -0.960 -0.100 -0.990 \n0.000 -1.000 0.100 -0.990 0.200 -0.960 0.300 -0.910 0.400 -0.840 \n0.500 -0.750 0.600 -0.640 0.700 -0.510 0.800 -0.360 0.900 -0.190 \n1.000 0.000 /\n\\plot\n-1.000 0.000 -0.900 0.190 -0.800 0.360 -0.700 0.510 -0.600 0.640 \n-0.500 0.750 -0.400 0.840 -0.300 0.910 -0.200 0.960 -0.100 0.990 \n0.000 1.000 0.100 0.990 0.200 0.960 0.300 0.910 0.400 0.840 \n0.500 0.750 0.600 0.640 0.700 0.510 0.800 0.360 0.900 0.190 \n1.000 0.000 /\n\\endpicture}}\n%\\begincaption\n%{Solid with equilateral triangles as cross-sections.\n%(\\expandafter\\url\\expandafter{\\liveurl jmol_triangular_x_sections}%\n%AP\\endurl)}\n%%(\\expandafter\\url\\expandafter{\\sageurl solid_with_triangular_x-sections}%\n%%AP\\endurl)}\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:triangular cross-sections}\n%\\htmlfigure{Integration_applications-volume_equilateral_x_sections.html}\n%\\htmlonly\n\\caption\n{Solid with equilateral triangles as cross-sections.\\label{fig:triangular cross-sections}}\n%You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/sage/solid_with_triangular_x-sections/solid_with_triangular_x-sections.sws\">Sage worksheet</a>\n%for this plot and upload it to your own sage account.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\n\\begin{solution}\nA cross-section at a value $\\ds x_i$ on the $x$-axis is a triangle with\nbase $\\ds 2(1-x_i^2)$ and height $\\ds \\sqrt3(1-x_i^2)$, so the area of the\ncross-section is \n$$\n  {1\\over2}(\\hbox{base})(\\hbox{height})=\n  (1-x_i^2)\\sqrt3(1-x_i^2),\n$$\nand the volume of a thin ``slab'' is then\n$$(1-x_i^2)\\sqrt3(1-x_i^2)\\Delta x.$$\nThus the total volume is \n$$\\int_{-1}^1 \\sqrt3(1-x^2)^2\\,dx={16\\over15}\\sqrt3.$$\n\\vskip-10pt\n\\end{solution}\n\nOne easy way to get ``nice'' cross-sections is by rotating a plane\nfigure around a line. For example, in Figure~\\ref{fig:solid of rotation} \nwe see a plane region under a curve and between two\nvertical lines; then the result of rotating this around the $\\ds x$-axis, and\na typical circular cross-section is a circle.\n \n\\figure[H]\n%\\texonly\n\\centerline{\n\\vbox{\\hbox{\\hfill\\raise53pt\\vbox{\n\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <5.5truemm,5.5truemm>\n\\setplotarea x from 0 to 8, y from -4 to 4\n\\axis left /\n\\axis bottom shiftedto y=0 / \n\\putrule from 1 0 to 1 4 \n\\putrule from 6 0 to 6 3\n\\plot 1 4 1.150 3.546 \n1.312 3.125 1.475 2.772 1.638 2.484 1.800 2.255 1.962 2.082 \n2.125 1.961 2.288 1.886 2.450 1.854 2.612 1.859 2.775 1.898 \n2.938 1.967 3.100 2.060 3.262 2.174 3.425 2.303 3.588 2.444 \n3.750 2.593 3.912 2.744 4.075 2.894 4.238 3.037 4.400 3.170 \n4.562 3.289 4.725 3.388 4.888 3.464 5.050 3.511 5.212 3.527 \n5.375 3.505 5.538 3.443 5.700 3.334 5.862 3.176 6.025 2.964 /\n\\endpicture}\n\\quad\\epsfxsize3.8cm\\epsfbox{images/rotated_surface.eps}\n\\quad\\epsfxsize3.8cm\\epsfbox{images/one_disk.eps}\n\\hfill}\\vglue-0pt}}\n\\caption{\\label{fig:solid of rotation} A solid of rotation.}\n\\endfigure\n\nOf course a real ``slice'' of this figure will not have straight\nsides, but we can approximate the volume of the slice by a cylinder or\ndisk with circular top and bottom and straight sides; the volume of\nthis disk will have the form $\\ds \\pi r^2\\Delta x$. As long as we can\nwrite $r$ in terms of $x$ we can compute the volume by an integral.\n\n\\begin{example}{Volume of a Right Circular Cone}{Volume of a Right Circular Cone}\\label{Volume of a Right Circular Cone}\nFind the volume of a right circular cone with base radius 10 and\nheight 20. (A right circular cone is one with a circular base and with\nthe tip of the cone directly over the center of the base.)\n\\end{example}\n\n\\begin{solution}\nWe can view this cone as produced by the rotation of the line\n$y=x/2$ rotated about the $x$-axis, as indicated in\nfigure~\\ref{fig:line to cone}.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <0.25truecm,0.25truecm>\n\\setplotarea x from 0 to 20, y from 0 to 10\n\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$20$} / at 0 20 / /\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/cone.eps}}} at 40 5\n\\plot 0 0 20 10 /\n\\putrule from 20 0 to 20 10\n\\endpicture}}\n\\caption{\\label{fig:line to cone}\nA region that generates a cone; approximating the volume\nby circular disks.}\n%(\\expandafter\\url\\expandafter{\\liveurl cone.html}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:line to cone}\n%\\htmlfigure{Integration_applications-volume_of_cone.html}\n%\\begincaption\n%Approximating the volume of a cone\n%by circular disks.\n%\\endcaption\n\\endfigure\n\nAt a particular point on the $x$-axis, say $\\ds x_i$, the radius of the\nresulting cone is the $y$-coordinate of the corresponding point on the\nline, namely $\\ds y_i=x_i/2$. Thus the total volume is approximately\n$$\\sum_{i=0}^{n-1} \\pi (x_i/2)^2\\,dx$$\nand the exact volume is\n$$\n  \\int_0^{20} \\pi\n  {x^2\\over4}\\,dx={\\pi\\over4}{20^3\\over3}={2000\\pi\\over3}.\n$$ \nNote that we can instead do the calculation with a generic height and\nradius: \n$$\n  \\int_0^{h} \\pi{r^2\\over h^2}x^2\\,dx\n  ={\\pi r^2\\over h^2}{h^3\\over3}={\\pi r^2h\\over3},\n$$ \ngiving us the usual formula for the volume of a cone.\n\\end{solution}\n\n\\begin{example}{Volume of an Object with a Hole}{Volume of an Object with a Hole}\\label{Volume of an Object with a Hole}\nFind the volume of the object generated when the area between\n$\\ds y=x^2$ and $y=x$ is rotated around the $x$-axis. \n\\end{example}\n\n\\begin{solution}\nThis solid has a\n``hole'' in the middle; we can compute the volume by subtracting the\nvolume of the hole from the volume enclosed by the outer surface of\nthe solid. In figure~\\ref{fig:solid with hole} we show the region\nthat is rotated, the resulting solid with the front half cut away,\nthe cone that forms the outer surface, the\nhorn-shaped hole, and a cross-section perpendicular to the $x$-axis.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\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\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n\\axis left shiftedto x=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/cutaway_horn.eps}}} at 3 0\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/outer_cone.eps}}} at 0 -2\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/horn.eps}}} at 2 -2\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/washer_section.eps}}} at 4 -2\n\\plot 0 0 1 1 /\n\\setquadratic\n\\plot\n0.000 0.000 0.100 0.010 0.200 0.040 0.300 0.090 0.400 0.160 \n0.500 0.250 0.600 0.360 0.700 0.490 0.800 0.640 0.900 0.810 \n1.000 1.000 /\n\\endpicture}}\n\\caption{\\label{fig:solid with hole}\nSolid with a hole, showing the outer cone and the shape to\nbe removed to form the hole.}\n%(\\expandafter\\url\\expandafter{\\liveurl solid_with_hole.html}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:solid with hole}\n%\\htmlfigure{Integration_applications-volume_with_hole.html}\n%\\htmlonly\n%\\begincaption\n%Solid with a hole. You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/jmol_solid_of_rotation_with_hole/solid_of_rotation_with_hole.sws\">Sage\n%worksheet</a>\n%for this plot and upload it to your own sage account.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\nWe have already computed the volume of a cone; in this case it is\n$\\pi/3$. At a particular value of $x$, say $\\ds x_i$, the cross-section of\nthe horn is a circle with radius $\\ds x_i^2$, so the volume of the horn is\n$$\\int_0^1 \\pi(x^2)^2\\,dx=\\int_0^1 \\pi x^4\\,dx=\\pi{1\\over 5},$$\nso the desired volume is $\\pi/3-\\pi/5=2\\pi/15$.\n\nAs with the area between curves, there is an alternate approach that\ncomputes the desired volume ``all at once'' by approximating the\nvolume of the actual solid. We can approximate the volume of a slice\nof the solid with a washer-shaped volume, as indicated in\nFigure~\\ref{fig:solid with hole}.\n\nThe volume of such a washer is the area of the face times the\nthickness. The thickness, as usual, is $\\Delta x$, while the area of\nthe face is the area of the outer circle minus the area of the inner\ncircle, say $\\ds \\pi R^2-\\pi r^2$, or $\\pi(\\text{TOP})^2-\\pi(\\text{BOTTOM})^2$. In the present example, at a particular $\\ds x_i$,\nthe radius $R$ (The ``TOP'' function) is $\\ds x_i$ and $r$ (The ``BOTTOM'' function) $\\ds x_i^2$. Hence, the whole volume is\n$$\n  \\int_0^1 \\pi\\left(\\text{TOP}^2-\\text{BOTTOM}^2\\right)\\,dx=\n  \\int_0^1 \\pi x^2-\\pi x^4\\,dx=\n  \\left.\\pi\\left({x^3\\over3}-{x^5\\over5}\\right)\\right|_0^1=\n  \\pi\\left({1\\over3}-{1\\over5}\\right)={2\\pi\\over15}.\n$$\nOf course, what we have done here is exactly the same calculation as\nbefore, except we have in effect recomputed the volume of the outer cone.\n\\end{solution}\n\nSuppose the region between $f(x)=x+1$ and $\\ds g(x)=(x-1)^2$ is rotated around\nthe $y$-axis; see Figure~\\ref{fig:shell method}. It is possible, but\ninconvenient, to compute the  volume of the resulting solid by the\nmethod we have used so far. The problem is that there are two\n``kinds'' of typical rectangles: Those that go from the line to the\nparabola and those that touch the parabola on both ends. To compute\nthe volume using this approach, we need to break the problem into two\nparts and compute two integrals:\n$$\n  \\pi\\int_0^1 (1+\\sqrt{y})^2-(1-\\sqrt{y})^2\\,dy+\n  \\pi\\int_1^4  (1+\\sqrt{y})^2-(y-1)^2\\,dy={8\\over3}\\pi + {65\\over6}\\pi\n  ={27\\over2}\\pi.\n$$\nIf instead we consider a typical vertical rectangle, {but still rotate\naround the $y$-axis,} we get a thin ``shell'' instead of a thin\n``washer''. Note that ``washers'' are related to the area of a circle, $\\pi r^2$, whereas ``shells'' are related to the surface area of a cylinder, $2\\pi rh$. If we add up the volume of such thin shells we will get an\napproximation to the true volume. What is the volume of such a shell?\nConsider the shell at $\\ds x_i$.\nImagine that we cut the shell vertically in one place and ``unroll''\nit into a thin, flat sheet, namely the surface of a cylinder. This sheet will be almost a rectangular\nprism that is $\\Delta x$ thick, $\\ds f(x_i)-g(x_i)$ (TOP$-$BOTTOM) tall, and $\\ds 2\\pi x_i$\nwide. The volume will then be approximately the volume of a rectangular\nprism with these dimensions: $\\ds 2\\pi x_i(f(x_i)-g(x_i))\\Delta x$. If we\nadd these up and take the limit as usual, we get the integral\n$$\n  \\int_0^3 2\\pi x(f(x)-g(x))\\,dx=\n  \\int_0^3 2\\pi x\\left(\\text{TOP}-\\text{BOTTOM}\\right)\\,dx=\n  \\int_0^3 2\\pi x(x+1-(x-1)^2)\\,dx={27\\over2}\\pi.\n$$\nNot only does this accomplish the task with only one integral, the\nintegral is somewhat easier than those in the previous\ncalculation. Things are not always so neat, but it is often the case\nthat one of the two methods will be simpler than the other, so it is\nworth considering both before starting to do calculations.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <1truecm,1truecm>\n\\setplotarea x from 0 to 3.1, y from 0 to 4.1\n\\axis bottom shiftedto y=0 ticks numbered from 0 to 3 by 1 /\n\\axis left shiftedto x=0 ticks numbered from 0 to 4 by 1 /\n\\putrule from 1 2 to 2.4142 2\n\\putrule from 1 1.8 to 2.4142 1.8\n\\putrule from 1 1.8 to 1 2\n\\putrule from 2.4142 1.8 to 2.4142 2\n\\putrule from 0.25 .5625 to 1.75 .5625\n\\putrule from 0.25 .3625 to 1.75 .3625\n\\putrule from 0.25 .3625 to 0.25 .5625\n\\putrule from 1.75 .3625 to 1.75 .5625\n\\plot 0 1 3 4 /\n\\setquadratic\n\\plot\n0.000 1.000 0.150 0.722 0.300 0.490 0.450 0.302 0.600 0.160 \n0.750 0.062 0.900 0.010 1.050 0.002 1.200 0.040 1.350 0.122 \n1.500 0.250 1.650 0.422 1.800 0.640 1.950 0.902 2.100 1.210 \n2.250 1.562 2.400 1.960 2.550 2.402 2.700 2.890 2.850 3.422 \n3.000 4.000 /\n\\setcoordinatesystem units <1truecm,1truecm> point at -5 0\n\\setplotarea x from 0 to 3.1, y from 0 to 4.1\n\\axis bottom shiftedto y=0 ticks numbered from 0 to 3 by 1 /\n\\axis left shiftedto x=0 ticks numbered from 0 to 4 by 1 /\n\\put {\\hbox{\\epsfxsize4cm\\epsfbox{images/shell.eps}}} at 7 2\n\\putrule from 1.5 0.25 to 1.5 2.5\n\\putrule from 1.7 0.25 to 1.7 2.5\n\\putrule from 1.5 0.25 to 1.7 0.25\n\\putrule from 1.5 2.5 to 1.7 2.5\n\\setlinear\n\\plot 0 1 3 4 /\n\\setquadratic\n\\plot\n0.000 1.000 0.150 0.722 0.300 0.490 0.450 0.302 0.600 0.160 \n0.750 0.062 0.900 0.010 1.050 0.002 1.200 0.040 1.350 0.122 \n1.500 0.250 1.650 0.422 1.800 0.640 1.950 0.902 2.100 1.210 \n2.250 1.562 2.400 1.960 2.550 2.402 2.700 2.890 2.850 3.422 \n3.000 4.000 /\n\\endpicture}}\n\\caption{\\label{fig:shell method}\nComputing volumes with ``shells''.}\n%(\\url{http://www.whitman.edu/mathematics/calculus/live/shell.html}%\n%AP\\endurl)}\n%(\\expandafter\\url\\expandafter{\\liveurl shell.html}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:shell method}\n%\\htmlfigure{Integration_applications-volume_shell_method.html}\n%\\htmlonly\n%\\begincaption\n%Computing volumes with ``shells''.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\n\\begin{example}{}{}\\label{}\nSuppose the area under $\\ds y=-x^2+1$ between $x=0$ and $x=1$ is\nrotated around the $x$-axis. Find the volume by both methods.\n\\end{example}\n\n\\begin{solution}\nUsing the disk method we obtain:\n$$\\ds \\int_0^1 \\pi(1-x^2)^2\\,dx={8\\over15}\\pi.$$\nUsing the shell method we obtain:\n$$\\ds \\int_0^1 2\\pi y \\sqrt{1-y}\\,dy={8\\over15}\\pi.$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:volume}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\nVerify that $\\ds\\pi\\int_0^1 (1+\\sqrt{y})^2-(1-\\sqrt{y})^2\\,dy+\n\\pi\\int_1^4  (1+\\sqrt{y})^2-(y-1)^2={8\\over3}\\pi + {65\\over6}\\pi\n={27\\over2}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds\\int_0^3 2\\pi x(x+1-(x-1)^2)\\,dx={27\\over2}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds \\int_0^1 \\pi(1-x^2)^2\\,dx={8\\over15}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds \\int_0^1 2\\pi y \\sqrt{1-y}\\,dy={8\\over15}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nUse integration to find the volume of the solid obtained by revolving \nthe region bounded by $x+y=2$ and the $x$ and $y$ axes around the\n$x$-axis. \n\\begin{sol}\n $8\\pi/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the volume of the solid obtained by revolving \nthe region bounded by $\\ds y=x-x^2$\nand the $x$-axis around the\n$x$-axis. \n\\begin{sol}\n $\\pi/30$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the volume of the solid obtained by revolving \nthe region bounded by $\\ds y=\\sqrt{\\sin x}$ between $x=0$ and\n$x=\\pi/2$, the $y$-axis, and the line\n$y=1$ around the\n$x$-axis. \n\\begin{sol}\n $\\pi(\\pi/2-1)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nLet $S$ be the region of the $xy$-plane bounded above by the curve\n$\\ds x^3y=64$, below by the line $y=1$, on the left by  the line $x=2$, and\non the right by the line $x=4$.  Find\nthe volume of the solid obtained by rotating $S$ around:\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\tthe $x$-axis;\n\t\\item\tthe line $y=1$;\n\t\\item\tthe $y$-axis; and\n\t\\item\tthe line $x=2$.\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$114\\pi/5$\n\t\\item\t$74\\pi/5$\n\t\\item\t$20\\pi$\n\t\\item\t$4\\pi$\n\\end{enumerate}\n\\end{multicols}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The equation $\\ds x^2/9+y^2/4=1$ describes an ellipse.  Find the\nvolume of the solid obtained by rotating the ellipse around the\n$x$-axis and also around the $y$-axis. These solids are\ncalled \\dfont{ellipsoids}; one is vaguely rugby-ball shaped, one is\nsort of flying-saucer shaped, or perhaps squished-beach-ball-shaped.\n\\begin{sol}\n $16\\pi$, $24\\pi$\n\\end{sol}\n\\end{ex}\n\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 0.5\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/rugby.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/ufo.eps}}} at 2 0\n\\endpicture}}\n\\caption{Ellipsoids.\\label{fig:ellipsoids}}\n%(\\url{http://www.whitman.edu/mathematics/calculus/live/ellipsoid.html}%\n%AP\\endurl)}\n%(\\expandafter\\url\\expandafter{\\liveurl ellipsoid.html}%\n%AP\\endurl)}\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:ellipsoids}\n%\\htmlfigure{Integration_applications-ellipsoids.html}\n%\\htmlonly\n%\\begincaption\n%Ellipsoids.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\n\n%%%%%%%%%%\n\\begin{ex}\n Use integration to compute the volume of a sphere of radius\n$r$. You should of course get the well-known formula $\\ds 4\\pi r^3/3$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nA hemispheric bowl of radius $r$ contains water to a depth $h$.  Find\nthe volume of water in the bowl.\n\\begin{sol}\n $\\ds \\pi h^2(3r-h)/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The base of a tetrahedron (a triangular pyramid) of height $h$\nis an equilateral triangle of side $s$.  Its cross-sections\nperpendicular to an altitude are equilateral triangles.  Express its\nvolume $V$ as an integral, and find a formula for $V$ in terms of $h$\nand $s$. Verify that your answer is $(1/3)(\\hbox{area of base})(\\hbox{height})$. \n%% fixme: include picture? see exercise_9.3.13.mw\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nThe base of a solid is the region between $f(x)=\\cos x$ and\n$g(x)=-\\cos x$, $-\\pi/2\\le x\\le\\pi/2$,\nand its cross-sections perpendicular to the $x$-axis \nare squares.\nFind the volume of the solid.\n\\begin{sol}\n $2\\pi$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "1116434e891d4a7e631b9dc9c3c896cfa8fe0a6a", "size": 21707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-3-volume.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": "8-applications-of-integration/8-3-volume.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": "8-applications-of-integration/8-3-volume.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": 34.1305031447, "max_line_length": 243, "alphanum_fraction": 0.7049799604, "num_tokens": 8062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419704455589, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.6100770182350079}}
{"text": "% file: chapters/graph-paths.tex\n\n\\chapter{Paths in Graphs}\t\\label{chapter:graph-paths}\n\n\\section{Single-Source Shortest Paths (SSSP)}\t\\label{section:sssp}\n\n\\input{algs/graph-paths/dijkstra-alg}\n\n\\section{All-Pairs Shortest Paths (APSP)}\t\\label{section:apsp}\n\n\\input{algs/graph-paths/floyd-warshall-alg}\n\n\\section{Eulerian Path and Eulerian Circuit}\t\\label{section:eulerian-path}\n\n\\input{algs/graph-paths/eulerian-circuit-hierholzer}\n", "meta": {"hexsha": "ff85e0dcc1a625c558e73c87e7b5e98848b1eb97", "size": 434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/graph-paths.tex", "max_stars_repo_name": "hengxin/algorithms-pseudocode", "max_stars_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-11-06T08:52:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-27T13:01:13.000Z", "max_issues_repo_path": "chapters/graph-paths.tex", "max_issues_repo_name": "hengxin/algorithms-pseudocode", "max_issues_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_issues_repo_licenses": ["MIT"], "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/graph-paths.tex", "max_forks_repo_name": "hengxin/algorithms-pseudocode", "max_forks_repo_head_hexsha": "5c8265b6368f851337ca9c0dd1476c07b6e29f83", "max_forks_repo_licenses": ["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.125, "max_line_length": 74, "alphanum_fraction": 0.7764976959, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385542, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6100241997112901}}
{"text": "\\chapter{Basic Operations} \\label{chap:operations}\n\nThe basic types have been introduced in the previous chapter, so we move on with the description of the basic BLAS operations.\nAlmost all operations supported by {\\ublas} are available, including element-wise operations on vectors. Thus, consider the  \n\\href{http://www.boost.org/doc/libs/1_52_0/libs/numeric/ublas/doc/operations_overview.htm}{ublas-documentation} as a reference as well.\n\n\\section{Vector-Vector Operations (BLAS Level 1)}\n\n{\\ViennaCL} provides all vector-vector operations defined at level 1 of BLAS. Tab.~\\ref{tab:blas-level-1} shows how these operations can be carried\nout in \\ViennaCL. The function interface is compatible with {\\ublas},\nthus allowing quick code migration for {\\ublas} users.\n\n\n\\TIP{For full details on level 1 functions, refer to the reference documentation\nlocated in \\texttt{doc/doxygen/}}\n\n\n\\begin{table}[tb]\n\\begin{center}\n\\begin{tabular}{l|l|p{6cm}}\nVerbal & Mathematics & ViennaCL\\\\\n\\hline\nswap    & $x \\leftrightarrow y$ & \\lstinline|swap(x,y);| \\\\\nstretch    & $x \\leftarrow \\alpha x$ & \\lstinline|x *= alpha;| \\\\\nassignment & $y \\leftarrow x$ & \\lstinline|y = x;| \\\\\nmultiply add & $y \\leftarrow \\alpha x + y$ & \\lstinline|y += alpha * x;| \\\\\nmultiply subtract & $y \\leftarrow \\alpha x - y$ & \\lstinline|y -= alpha * x;| \\\\\nelementwise product & $y_i \\leftarrow x_i \\cdot z_i$ & \\lstinline|y = element_prod(x,z);| \\\\\nelementwise division & $y_i \\leftarrow x_i \\cdot z_i$ & \\lstinline|y = element_div(x,z);| \\\\\ninner dot product & $\\alpha \\leftarrow x^{\\mathrm{T}} y$ & \\lstinline|inner_prod(x,y);| \\\\\n$L^1$ norm & $\\alpha \\leftarrow \\Vert x \\Vert_1$ & \\lstinline|alpha = norm_1(x);| \\\\\n$L^2$ norm & $\\alpha \\leftarrow \\Vert x \\Vert_2$ & \\lstinline|alpha = norm_2(x);| \\\\\n$L^\\infty$ norm & $\\alpha \\leftarrow \\Vert x \\Vert_\\infty$ & \\lstinline|alpha = norm_inf(x);| \\\\\n$L^\\infty$ norm index& $i \\leftarrow \\max_i \\vert x_i \\vert$ & \\lstinline|i = index_norm_inf(x);| \\\\\nplane rotation & $(x,y) \\leftarrow (\\alpha x + \\beta y, -\\beta x + \\alpha y)$ & \\lstinline|plane_rotation(alpha, beta, x, y);| \\\\\n\\end{tabular}\n\\caption{BLAS level 1 routines mapped to {\\ViennaCL}. Note that the free functions reside in namespace \\texttt{viennacl::linalg}}\n\\label{tab:blas-level-1}\n\\end{center}\n\\end{table}\n \n\\section{Matrix-Vector Operations (BLAS Level 2)}\nThe interface for level 2 BLAS functions in {\\ViennaCL} is similar to that of\n{\\ublas} and shown in Tab.~\\ref{tab:blas-level-2}.\n\n\\TIP{For full details on level 2 functions, refer to the reference documentation\nlocated in \\texttt{doc/doxygen/}}\n\n\n\\begin{table}[tb]\n\\begin{center}\n\\renewcommand{\\arraystretch}{1.2}\n\\begin{tabular}{p{4cm}|l|p{7cm}}\nVerbal & Mathematics & ViennaCL\\\\\n\\hline\nmatrix vector product & $y \\leftarrow A x$ & \\lstinline|y = prod(A, x);| \\\\\nmatrix vector product & $y \\leftarrow A^\\mathrm{T} x$ & \\lstinline|y = prod(trans(A), x);| \\\\\ninplace mv product & $x \\leftarrow A x$ & \\lstinline|x = prod(A, x);| \\\\\ninplace mv product & $x \\leftarrow A^\\mathrm{T} x$ & \\lstinline|x = prod(trans(A), x);| \\\\\n\\hline\nscaled product add & $y \\leftarrow \\alpha A x + \\beta y$ & \\lstinline|y = alpha * prod(A, x) + beta * y| \\\\\nscaled product add & $y \\leftarrow \\alpha A^{\\mathrm T} x + \\beta y$ & \\lstinline|y = alpha * prod(trans(A), x) + beta * y| \\\\\n\\hline\ntri. matrix solve & $y \\leftarrow A^{-1} x$ & \\lstinline|y = solve(A, x, tag);| \\\\\ntri. matrix solve & $y \\leftarrow A^\\mathrm{T^{-1}} x$ & \\lstinline|y = solve(trans(A), x, tag);| \\\\\ninplace solve & $x \\leftarrow A^{-1} x$ & \\lstinline|inplace_solve(A, x, tag);| \\\\\ninplace solve & $x \\leftarrow A^\\mathrm{T^{-1}} x$ & \\lstinline|inplace_solve(trans(A), x, tag);| \\\\\n\\hline\nrank 1 update & $A \\leftarrow \\alpha x y^{\\mathrm T} + A$ & \\lstinline|A += alpha * outer_prod(x,y);| \\\\\nsymm. rank 1 update & $A \\leftarrow \\alpha x x^{\\mathrm T} + A$ & \\lstinline|A += alpha * outer_prod(x,x);| \\\\\nrank 2 update & $A \\leftarrow \\alpha (x y^{\\mathrm T} + y x^{\\mathrm T}) + A$ & \\lstinline|A += alpha * outer_prod(x,y);| \\lstinline|A += alpha * outer_prod(y,x);| \\\\\n\\end{tabular}\n\\caption{BLAS level 2 routines mapped to \\ViennaCL. Note that the free functions reside in namespace \\texttt{viennacl::linalg}. \\lstinline|tag| is one out of \\lstinline|lower_tag|, \\lstinline|unit_lower_tag|, \\lstinline|upper_tag|, and \\lstinline|unit_upper_tag|.}\n\\label{tab:blas-level-2}\n\\end{center}\n\\end{table}\n\n\\section{Matrix-Matrix Operations (BLAS Level 3)}\nFull BLAS level 3 support is since {\\ViennaCL} 1.1.0, cf.~Tab.~\\ref{tab:blas-level-3}. While BLAS\nlevels 1 and 2 are mostly memory-bandwidth-limited, BLAS level 3 is mostly\nlimited by the available computational power of the respective device. Hence,\nmatrix-matrix products regularly show impressive performance gains on mid-\nto high-end GPUs when compared to a single CPU core.\n\nAgain, the {\\ViennaCL} API is identical to that of {\\ublas} and comparisons can\nbe carried out immediately, as is shown in the tutorial located in\n\\texttt{examples/tutorial/blas3.cpp}.\n\nAs for performance, {\\ViennaCL} yields decent performance gains at BLAS level\n3 on mid- to high-end GPUs compared to CPU implementations using a single core\nonly. Nevertheless, one must not expect to obtain the reported peak performance\nof hundreds of GFLOPs for the multiplication of arbitrary matrices. These rates\ncan typically only obtained when tailoring the compute kernel(s) to a\nparticular device and certain matrix dimensions, while {\\ViennaCL} provides\nkernels that represent a good compromise between efficiency and portability\namong a large number of different devices and device types.\n\n\\begin{table}[tb]\n\\begin{center}\n\\renewcommand{\\arraystretch}{1.2}\n\\begin{tabular}{p{4cm}|l|p{7.5cm}}\nVerbal & Mathematics & ViennaCL\\\\\n\\hline\nmatrix-matrix product & $C \\leftarrow A \\times B$ & \\lstinline|C = prod(A, B);| \\\\\nmatrix-matrix product & $C \\leftarrow A \\times B^\\mathrm{T}$ & \\lstinline|C = prod(A, trans(B));| \\\\\nmatrix-matrix product & $C \\leftarrow A^\\mathrm{T} \\times B$ & \\lstinline|C = prod(trans(A), B);| \\\\\nmatrix-matrix product & $C \\leftarrow A^\\mathrm{T} \\times B^\\mathrm{T}$ & \\lstinline|C = prod(trans(A), trans(B));| \\\\\n\\hline\ntri. matrix solve & $C \\leftarrow A^{-1} B$ & \\lstinline|C = solve(A, B, tag);| \\\\\ntri. matrix solve & $C \\leftarrow A^\\mathrm{T^{-1}} B$ & \\lstinline|C = solve(trans(A), B, tag);| \\\\\ntri. matrix solve & $C \\leftarrow A^{-1} B^\\mathrm{T}$ & \\lstinline|C = solve(A, trans(B), tag);| \\\\\ntri. matrix solve & $C \\leftarrow A^\\mathrm{T^{-1}} B^\\mathrm{T}$ & \\lstinline|C = solve(trans(A), trans(B), tag);| \\\\\n%\ninplace solve & $B \\leftarrow A^{-1} B$ & \\lstinline|inplace\\_solve(A, trans(B), tag);| \\\\\ninplace solve & $B \\leftarrow A^\\mathrm{T^{-1}} B$ & \\lstinline|inplace\\_solve(trans(A), x, tag);| \\\\\ninplace solve & $B \\leftarrow A^{-1} B^\\mathrm{T}$ & \\lstinline|inplace\\_solve(A, trans(B), tag);| \\\\\ninplace solve & $B \\leftarrow A^\\mathrm{T^{-1}} B^\\mathrm{T}$ & \\lstinline|inplace\\_solve(trans(A), x, tag);| \\\\\n\\end{tabular}\n\\caption{BLAS level 3 routines mapped to \\ViennaCL. Note that the free functions\nreside in namespace \\texttt{viennacl::linalg}}\n\\label{tab:blas-level-3}\n\\end{center}\n\\end{table}\n\n\\section{Initializer Types}\n\n\\NOTE{Initializer types in {\\ViennaCLversion} can only be used for initializing vectors and matrices, not for computations!}\n\nIn order to initialize vectors, the following initializer types are provided, again similar to {\\ublas}:\n\\begin{center}\n\\begin{tabular}{|l|p{10cm}|}\n \\hline\n \\lstinline|unit_vector<T>(s, i)| & Unit vector of size $s$ with entry $1$ at index $i$, zero elsewhere. \\\\\n \\hline\n \\lstinline|zero_vector<T>(s)| & Vector of size $s$ with all entries being zero. \\\\\n \\hline\n \\lstinline|scalar_vector<T>(s, v)| & Vector of size $s$ with all entries equal to $v$. \\\\\n \\hline\n\\end{tabular}\n\\end{center}\nFor example, to initialize a vector \\lstinline|v1| with all $42$ entries being $42.0$, use\n\\begin{lstlisting}\n viennacl::vector<float> v1 = viennacl::scalar_vector<float>(42, 42.0f);\n\\end{lstlisting}\n\nSimilarly the following initializer types are available for matrices:\n\\begin{center}\n\\begin{tabular}{|l|p{10cm}|}\n \\hline\n \\lstinline|identity_matrix<T>(s, i)| & Identity matrix of dimension $s \\times s$. \\\\\n \\hline\n \\lstinline|zero_matrix<T>(s1, s2)| & Matrix of size $s_1 \\times s_2$ with all entries being zero. \\\\\n \\hline\n \\lstinline|scalar_matrix<T>(s1, s2, v)| & Matrix of size $s_1 \\times s_2$ with all entries equal to $v$. \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n", "meta": {"hexsha": "53870efe11ae4dc82211e3ca26484fef8b9af6b7", "size": 8499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/manual/operations.tex", "max_stars_repo_name": "bollig/viennacl", "max_stars_repo_head_hexsha": "6dac70e558ed42abe63d8c5bfd08465aafeda859", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-21T08:33:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-21T08:33:10.000Z", "max_issues_repo_path": "doc/manual/operations.tex", "max_issues_repo_name": "bollig/viennacl", "max_issues_repo_head_hexsha": "6dac70e558ed42abe63d8c5bfd08465aafeda859", "max_issues_repo_licenses": ["MIT"], "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/manual/operations.tex", "max_forks_repo_name": "bollig/viennacl", "max_forks_repo_head_hexsha": "6dac70e558ed42abe63d8c5bfd08465aafeda859", "max_forks_repo_licenses": ["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.4528301887, "max_line_length": 264, "alphanum_fraction": 0.6970231792, "num_tokens": 2673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6100241963947691}}
{"text": "%!TEX root =  ../main.tex\n\n\\mychapters{Regressions}{regression}{\\chapdir/pics/CMS_higgs-event} \nMany situations in science are about taking actual fuzzy numbers and attempting to\nderive equations from them.    Sometimes these numbers are completely obvious,\npractically screaming what kind of equation they come from.  On the other hand,\nit can be deeply obscure and require enough care to regress from numerical\nto algebraic information.  \n\nBut the consequences can be high.  Later generations may attempt to take your\nequation and extrapolate well beyond the bounds you ever intended.  If you have\nthe wrong model, results can be disastrous, or at least, very upsetting (like the change\nfrom Newtonian to Einsteinian physics).\n\n\\newpage\n\\chapterminitoc\n\n%\t\t\t\t\t\t\t\t\t13 - 1\n\\newpage\n\\invisiblesection{Graphical Patterns}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch13/1301p.pdf}}\n\\newpage\n\\subsection{Increasing/Decreasing}\n\\subsection{Concavity}\n\\subsection{Asymptotes}\n\\subsection{Origin Question}\n\\subsection{Repeating}\n\\subsection{End Behavior}\n\\newpage\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t13 - 2\n\\newpage\n\\invisiblesection{Numerical Patterns}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch13/1302p.pdf}}\n\\newpage\n\\subsection{Add-Add}\n\\subsection{Add-Multiply}\nlogs are multiply add\n\\subsection{Multiply-Multiply}\nroots are divide divide\n\\subsection{Second Difference}\ncubes are add third diff.\n\nperiodic the same data reoccurs at a constant interval\n\\newpage\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t13 - 3\n\\newpage\n\\invisiblesection{Error}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch13/1303p.pdf}}\n\\newpage\n\\subsection{SSres}\n\\subsection{SSdev}\n\\subsection{r vs $r^2$}\n\\newpage\n\\subsection{Exercises}\n\n%\t\t\t\t\t\t\t\t\t13 - 4\n\\newpage\n\\invisiblesection{Linearization}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch13/1304p.pdf}}\n\\newpage\n\\subsection{Who gets the log?}\n\\subsubsection{Lin-Log Graphs}\n\\subsubsection{Log-Log Graphs}\n\\newpage\n\\subsection{Exercises}\n\n\n%\t\t\t\t\t\t\t\t\t13 - 5\n\\newpage\n\\invisiblesection{Differential Equations}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch13/1305p.pdf}}\n\\newpage\n\\subsection{Slope Fields}\n\\subsection{Euler's Method}\n\\subsection{Logistic Curves}\n\\newpage\n\\subsection{Exercises}\n\n\n%\t\t\t\t\t\t\t\t\t13 - 6\n\\newpage\n\\section{Review}\n\\subsection{Chapter Review}\n\\subsection{Chapter Test}", "meta": {"hexsha": "4824c456b52108ca3e7a8efd7c53756a313b9ea7", "size": 2530, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch13/1300.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": "ch13/1300.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": "ch13/1300.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": 27.2043010753, "max_line_length": 88, "alphanum_fraction": 0.7786561265, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744806385543, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6100241904808339}}
{"text": "%Note for this test case:\n%Simple water flow example using ANUGA: Water flowing down a channel.\n%It was called \"steep_slope\" in an old validation test.\n\n\n\\section{Shallow flow down a mild slope with coarsely resolved topography}\nThis case simulates very shallow flow running down a mild slope, with coarsely resolved topography, and a very low discharge. It represents a numerically more challenging idealisation of the rainfall-runoff problem, as compared to the case with higher discharge and resolution. This case has an analytical solution, and in particular, we consider the steady-uniform solution with the values of bed slope and friction slope are the same.   \n\nSuppose that we are given a one dimensional domain. The steady state conditions with a contant water depth everywhere make the shallow water equations to the single identity\n\\begin{equation}\nz_x = - S_f.\n\\end{equation}\nHere $q=uh$ is the momentum or water discharge and $S_f$ is the symbol for the force of bottom friction involving Manning's coefficient $n$. We take \n\\begin{equation}\nS_f = n^2 \\frac{q|q|}{h^{10/3}}.\n\\end{equation}\nIf $q$, $n$, and $z_x$ are given, then the analytical solution is\n\\begin{equation}\nu(x)= \\left[- n^{-2} q^{4/3} z_x\\right]^{3/10},\n\\end{equation}\n\\begin{equation}\nh(x)= \\frac{q}{u}\\,.\n\\end{equation}\n\n\\subsection{Results}\nFor our test, we consider a square dimensional domain with length and width 100. We take $q=1/1000.$, $n=0.03$, and $z_x=-0.1$.\nThe topography is\n\\begin{equation}\nz(x, y)= -0.1 x\\,.\n\\end{equation}\nThe initial condition is $u=v=0$ and\n\\begin{equation}\nw(x,y,0)= -0.1 x + 0.01\\,.\n\\end{equation}\n\n\nSome simulation results are as follows.\nFigures~\\ref{fig:depthdownchan} shows the steady state depth in the downstream direction. There should be a good agreement with the analytical solution in the middle of the domain (the boundaries will not reach steady-uniform flow). \nFigures~\\ref{fig:xvelscrosschan} and~\\ref{fig:yvelscroschan} show the steady state $x$- and $y$-velocities, along a slice in the cross slope direction (near $x=50$). In the middle of the domain the $x$-velocities should agree well with the analytical solution, and the $y$-velocities should be zero. \n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{depth_x.png}\n\\caption{Depth in the downstream direction}\n\\label{fig:depthdownchan}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{xvelocity_x.png}\n\\caption{X velocity in the downstream direction}\n\\label{fig:xveldownchan}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{depth_y.png}\n\\caption{Depth in the downstream direction}\n\\label{fig:depthacrosschan}\n\\end{center}\n\\end{figure}\n \n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{x_velocity.png}\n\\caption{$x$-velocity along the cross-section $x=50$ (i.e. a cross-section with constant bed elevation)}\n\\label{fig:xvelscrosschan}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{y_velocity.png}\n\\caption{$y$-velocity along the cross-section $x=50$ (i.e. a cross-section with constant bed elevation)}\n\\label{fig:yvelscroschan}\n\\end{center}\n\\end{figure}\n\n\n\\endinput\n", "meta": {"hexsha": "3a699e37d1b52cdda151f62224d213d86daf5c69", "size": 3238, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "validation_tests/analytical_exact/rundown_mild_slope_coarse/results.tex", "max_stars_repo_name": "samcom12/anuga_core", "max_stars_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_stars_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_stars_count": 136, "max_stars_repo_stars_event_min_datetime": "2015-05-07T05:47:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T03:07:40.000Z", "max_issues_repo_path": "validation_tests/analytical_exact/rundown_mild_slope_coarse/results.tex", "max_issues_repo_name": "samcom12/anuga_core", "max_issues_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_issues_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-05-03T09:27:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T04:22:48.000Z", "max_forks_repo_path": "validation_tests/analytical_exact/rundown_mild_slope_coarse/results.tex", "max_forks_repo_name": "samcom12/anuga_core", "max_forks_repo_head_hexsha": "f4378114dbf02d666fe6423de45798add5c42806", "max_forks_repo_licenses": ["Python-2.0", "OLDAP-2.7"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-03-18T07:35:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-01T07:07:29.000Z", "avg_line_length": 38.5476190476, "max_line_length": 439, "alphanum_fraction": 0.7578752316, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8175744673038221, "lm_q1q2_score": 0.6100241897617266}}
{"text": "\\section{Scale invariance of balances}\n\\begin{align}\n\\log \\frac{\\prod_{x_j \\in i_L}{(x_j)^{1/|i_L|}}}{\\prod_{x_k \\in i_R}{(x_j)^{1/|i_R|}}} =\n\\log \\frac{\\prod_{p_j \\in i_L}{(\\textcolor{red}{n}p_j)^{1/|i_L|}}}{\\prod_{p_k \\in i_R}{(\\textcolor{red}{n}p_j)^{1/|i_R|}}}=\n\\log \\frac{\\prod_{p_j \\in i_L}{(p_j)^{1/|i_L|}}}{\\prod_{p_k \\in i_R}{(p_j)^{1/|i_R|}}}\n\\end{align}\n$n$  is the true sequencing count, $x_j$ is the true abundances of species $j$ and $p_j$ is the proportion of species $j$. $i_L$ is the set of all species proportions contained in the left sub-tree at internal node $i$, $i_R$ is the set of all species proportions contained in the right sub-tree at the internal node $i$, and, $g(x)$ is the geometric mean of all of the proportions contained in $x$, $|i_R|$ is the number of species contained  $i_R$ and  $|i_L|$ is the number of species contained  $i_L$.  As shown above, the sequencing depth constant gets effectively canceled out.  Thus, log ratios are a natural normalization for sequencing depth, especially if there are no zero abundances present and the samples have sufficient coverage.\n\n%\n\\section{Benchmark of compositional coherence}\n\\textbf{Supplemental Figure 1}\n\nThe simulation consisted of a uniform population of 1000 individuals.  A blooming was simulated across 9 time points, where a single organism eventually grew 100,000x fold.  At each time point, 30 compositions were simulated using multinomial sampling with replacement.  At each time point, a statistical test was performed comparing the sample at that time point to the original time point.  Since we know beforehand that only 1 species is changing, any other tests that don’t involve the first set of proportions that is determined to be significant with p-value $<$ 0.05 is a false positive Figure S1a-b).  In fact, if the bloom of a given species is high enough, all of the other individuals can be detected to change.  In Figure S1e, if 1 species has changed by 100,000x, then all of the pvalues will be less than 10-10, giving a false positive rate close to 100\\%.  The same procedure is performed using balances, any balance that does not contain x1 that is determined to be significant from a t-test is considered a false positive (Figure S1c).  Note that this is highly dependent on the choice of the tree.  In this case, we used a tree where the blooming species x1 was to the far right of the tree (Figure S1f).  In this way, only the balance between x1, and x2 through x1000 should be changing.  But if we were to flip the tree, and place x1 to the far right of the tree, every balance in the tree will contain x1 (Figure S1g).  So as x1 blooms, the number of significant balances will increase (Figure S1d).\n\n\\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=1\\textwidth]{appendix_b/sup_figure1.png}\n        \\caption[A benchmark of statistical tests on compositional data.]{Simulations illustration the occurence of false positives in\n          traditional statistical tests}\n        \\label{figbS1}\n\\end{figure}\nWhile it may be deemed biologically irrelevant, blooms do happen frequently in microbial studies, with individual species sometimes blooming 5 orders of magnitude within a short period of time.  And the 10,000x fold growth of a single species will have the exact same effect as the 1,000x fold growth change of 10 species.  This suggests that there could be many subtle scenarios where we could be misinterpreting biologically relevant signals by testing individual proportions of microbes.\\newpage\n\\textbf{Supplemental Figure 2}\n\n\\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=1\\textwidth]{appendix_b/sup_figure2.png}\n        \\caption[An ecological intrepretation of balances]{A simulation of 4 species, where each species is normally distributed along some environmental gradient.  Each species has a normal distribution with a variance of 3 and a mean of 3, 6, 9 and 12 respectively as shown in Figure S2a.  The resulting balances can be calculated as follows.}\n        \\label{figbS2}\n\\end{figure}\n\\[\nabcd = \\log \\frac{\\sqrt{ab}}{\\sqrt{cd}} \\qquad\nab = \\log \\frac{\\sqrt{a}}{\\sqrt{b}}\ncd = \\log \\frac{\\sqrt{c}}{\\sqrt{d}}\n\\]\nNote, it is not possible to take a logarithm of zero.  A commonly used approach around this problem is to add a pseudocount.  Here we add a pseudocount of 1 after multiplying all of the species probabilities by 10000.  These species abundances are transformed into balances as shown in Figure S2b.  Because of the zero phenomenon, the balances yield something reminiscent to a triangular wave when applied to a pair of unimodal distributions.  Take balance ab for example.  At the far left around -5, neither a or b are present, so both of their abundances are zero.  But since we are adding pseudocounts, the resulting balance is given by log(1/1)=0 . When the gradient value increases to 0, the abundance of a approaches the peak of the distribution, while the abundance of b is still zero, causing the ab balance to increase.  By the time the gradient value is around 4, the abundances of b starts to appear, causing the ab to peak.  When the gradient value is around 8, the abundance of a starts disappearing while the abundance of b starts approaching the maximum peak in Figure S2a.  At a gradient value of 10, the abundance of b also begins to dwindle, and the ab balance spirals towards zero.  This same triangular wave pattern appears in all 3 of these balances, and portions of this also appear in the 88 soils study as shown in Figure S3.\n\nIt is also important to note that a balance of zero also indicates that the abundances between the ratios are equal.  So if a balance is zero, and a pseudocount scheme was used, either the proportions between the numerator and denominator are truly equal, or both the numerator and the denominator are zero.\\newpage\n\\section{Analysis of balances in soils}\n\\textbf{Supplemental Figure 3}\n\n\\begin{figure}[H]\n        \\centering\n        \\includegraphics[width=1\\textwidth]{appendix_b/sup_figure3.png}\n        \\caption[Other balances from the 88 soils study.]{A perspective of different balances in the 88 soils study.}\n        \\label{figbS3}\n\\end{figure}\n\nIf there is truly a unimodal species distribution along pH, we’d expect to see the same sort of triangular wave pattern as shown in Figure 2S.  If this is the case, then the top balance y0 is likely to be resulting from the midsection of the triangular wave between the minimum and the maximum (Figure S3a).  The peaks of the triangular wave are a bit more apparent in the Figure S3b-d.  In Figure S3b, the lower subtree in y1 is probably reaching a maximum in the true abundance around a pH of 7.  In Figure S3c, the upper subtree in y2 is also likely approaching a maximum in the true abundance around a pH of 6.  The same sort pattern could be happening in Figure S3d with the lower subtree in y3.  These glimpses of triangular waves in these graphs suggest that there could be unimodel distributions of OTUs across the pH gradient.\n\nAs daunting as the zeros problem is, the zeros present in data sets such as the 88 soils follow predictable patterns.  Even with a simple pseudo count strategy, we can still extract sensible information about balances of microbes across different pH values.\n", "meta": {"hexsha": "152280d6e41f7c332a2cf400e94eaa62188250b7", "size": 7280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixb.tex", "max_stars_repo_name": "mortonjt/phd-thesis", "max_stars_repo_head_hexsha": "f2b381322236b2591b51e4f9fca5899e0922654c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "appendixb.tex", "max_issues_repo_name": "mortonjt/phd-thesis", "max_issues_repo_head_hexsha": "f2b381322236b2591b51e4f9fca5899e0922654c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "appendixb.tex", "max_forks_repo_name": "mortonjt/phd-thesis", "max_forks_repo_head_hexsha": "f2b381322236b2591b51e4f9fca5899e0922654c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 140.0, "max_line_length": 1520, "alphanum_fraction": 0.7659340659, "num_tokens": 1836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6100220551413734}}
{"text": "\\section{Damage Plasticty Model For Quasi-Brittle Materials}\n\nDamage plasticity model based on \nStrain can be decomposed into elastic and plastic components:\n\\begin{equation}\n\\label{eqn:const1}\n\\boldsymbol{\\epsilon} = \\boldsymbol{\\epsilon}^{el} + \\boldsymbol{\\epsilon}^{pl}\n\\end{equation}\n\nTaking the time derivative gives the decomposition of the strain rate, $\\boldsymbol{\\dot{\\epsilon}}$ :\n\\begin{equation}\n\\label{eqn:const2}\n\\boldsymbol{\\dot{\\epsilon}} = \\boldsymbol{\\dot{\\epsilon}}^{el} + \\boldsymbol{\\dot{\\epsilon}}^{pl}\n\\end{equation}\n\nThe constitutive stress-strain relationship including a scalar damage parameter, $\\mathbf{D}$ can be written as follows:\n\\begin{equation}\n\\label{eqn:const3}\n\\boldsymbol{\\sigma} = (1-\\mathbf{D})\\mathbf{E}:\\boldsymbol{\\epsilon^{el}}\n\\end{equation}\n\nFor simplicity, the damaged elastic stiffness is described as the reduced stiffness due to the damage:\n\\begin{equation}\n\\label{eqn:const4}\n\\mathbf{E^d} = (1-\\mathbf{D})\\mathbf{E}\n\\end{equation}\n\nSubstituting \\ref{eqn:const1} and \\ref{eqn:const4} into \\ref{eqn:const3} results in the following:\n\\begin{equation}\n\\label{eqn:const5}\n\\boldsymbol{\\sigma} = \\mathbf{E^d}:(\\boldsymbol{\\epsilon}-\\boldsymbol{\\epsilon}^{pl})\n\\end{equation}\n\nUsing the \"usual notions of CDM\" (find reference), the effective stress. $\\boldsymbol{\\bar{\\sigma}}$, can be defined as:\n\\begin{equation}\n\\label{eqn:const6}\n\\boldsymbol{\\bar{\\sigma}} = \\mathbf{E}:(\\boldsymbol{\\epsilon}-\\boldsymbol{\\epsilon}^{pl})\n\\end{equation}\n\nSuch that the cauchy stress tensor can be realted to the effective stress tensor as follows:\n\\begin{equation}\n\\label{eqn:const7}\n\\boldsymbol{\\sigma} = (1-\\mathbf{D})\\boldsymbol{\\bar{\\sigma}}\n\\end{equation}\n\nThe nature of the damage evolution is assumed to be a function of the effective stress and the equivalent plastic strain, $\\boldsymbol{\\bar{\\epsilon}^{pl}}$:\n\\begin{equation}\n\\label{eqn:const8}\n\\mathbf{D} = \\mathbf{D}(\\boldsymbol{\\bar{\\sigma}}, \\boldsymbol{\\bar{\\epsilon}^{pl}})\n\\end{equation}\n\nIn this formulation, the brittle nature of rock neccessitates seperate characterization of tensile and compressive damage. In the case where a rock sample fails completely in tension, (i.e. the tensile stiffness becomes effectively 0), the compressive strength remains intacts to a fairly high degree such that two seperate damage variables for tensile damage and compressive damage. As such, the equivalent plastic strain is also considered seperately for tension and compression and is represented as follows:\n\\begin{equation}\n\\label{eqn:const9}\n\\boldsymbol{\\bar{\\epsilon}^{pl}} = \\begin{bmatrix} \n\t\\boldsymbol{\\bar{\\epsilon}_t^{pl}} \\\\ \n\t\\boldsymbol{\\bar{\\epsilon}_c^{pl}} \\end{bmatrix}\n\\end{equation}\n\nThe evolution of the equivalent plastic strains are described by the time derivative of the equivalent plastic strain, which can be considered to be related to the time derivative of the plastic strain through a hardenbing rule, $\\mathbf{h}$ such that:\n\\begin{equation}\n\\label{eqn:const10}\n\\boldsymbol{\\dot{\\bar{\\epsilon}}^{pl}} = \\mathbf{h}(\\boldsymbol{\\bar{\\sigma}},\n\t\\boldsymbol{\\bar{\\epsilon}^{pl}})\\bullet \\boldsymbol{\\dot{\\epsilon}} \n\\end{equation}\n\nThe flow rule can be written in terms of the flow potential function, $G(\\boldsymbol{\\bar{\\sigma}})$, and a plastic mulitplier $\\dot{\\lambda}$:\n\\begin{equation}\n\\label{eqn:const11}\n\\boldsymbol{\\dot{\\epsilon}} = \\dot{\\lambda} \\dfrac{\\partial G(\\boldsymbol{\\bar{\\sigma}})}{\\partial \\boldsymbol{\\bar{\\sigma}}}\n\\end{equation}\n\nNon-associated plasticity  is used, which required the solution of non-symetric equations.\n\n\n\n", "meta": {"hexsha": "32d331cabb8d54d363d4f3181e543a6e2f18bd74", "size": 3566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "section_damagedPlasticityModel.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": "section_damagedPlasticityModel.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": "section_damagedPlasticityModel.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": 46.3116883117, "max_line_length": 511, "alphanum_fraction": 0.7478968031, "num_tokens": 1029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.6099927763392355}}
{"text": "\\subsection{Multiplicative Expression}\n\n\\begin{grammar}\n\\nonterminal{multiplicative-expression}\n    \\produces\n\t\\nonterminal{power-expression} \\\\\n    \\produces\n\t\\nonterminal{multiplicative-expression}\n\t\\lexkeyword{*}\n\t\\nonterminal{power-expression} \\\\\n    \\produces\n\t\\nonterminal{multiplicative-expression}\n\t\\lexkeyword{/}\n\t\\nonterminal{power-expression} \\\\\n\\end{grammar}\n\n\\subsubsection{Eliminating left recursion (in BNF Form)}\n\nEliminating left recursion leads to\n\\begin{grammar}\n\\underbrace{\\nonterminal{multiplicative-expression}}_{=: M}\n    \\produces\n\t\\underbrace{\\nonterminal{power-expression}}_{=: P}\n\t\\underbrace{\\nonterminal{multiplicative-expression'}}_{=:M'}\\\\\n\\nonterminal{multiplicative-expression'}\n    \\produces\n\t\\lexkeyword{*}\n\t\\nonterminal{power-expression} \\nonterminal{multiplicative-expression'}\n\t\\\\\n    \\produces\n\t\\lexkeyword{/}\n\t\\nonterminal{power-expression} \\nonterminal{multiplicative-expression'}\n\t\\\\\n    \\produces\n\\end{grammar}\\\\[-0.5cm]\n\\noindent\n\n\\paragraph{Item automata for M}\n\n\\[\n\\begin{tikzpicture}[\n    every text node part/.style={align=center},\n    initial text =\n]\n    \\node[state,initial]\n\t(S)[rounded rectangle, draw]\n\t{{$[M\\to .PM']$}};\n    \\node[state]\n\t(P)[rounded rectangle, draw,right=of S]\n\t{{$[M\\to P.M']$}};\n    \\node[state,accepting]\n\t(M_)[rounded rectangle, draw,right=of P]\n\t{{$[M\\to PM'.]$}};\n    \\path[->] (S) edge  node [above] {P} (P);\n    \\path[->] (P) edge  node [above] {M'} (M_);\n\\end{tikzpicture}\n\\]\n\n\\paragraph{Item automata for M'}\n\\[\n\\begin{tikzpicture}[\n    every text node part/.style={align=center},\n    initial text =\n]\n    \\node[state,initial,accepting]\n\t(S)[rounded rectangle, draw]\n\t{\n\t    {$[M'\\to .*PM']$}\\\\\n\t    {$[M'\\to ./PM']$}\\\\\n\t    {$[M'\\to .]$}\n\t};\n    \\node[state]\n\t(Mul)[rounded rectangle, draw,right=of S]\n\t{{$[M'\\to *.PM']$}};\n    \\node[state]\n\t(Div)[rounded rectangle, draw,below=of Mul]\n\t{{$[M'\\to /.PM']$}};\n    \\node[state]\n\t(P)[rounded rectangle, draw,right=of Mul]\n\t{\n\t    {$[M'\\to *P.M']$} \\\\\n\t    {$[M'\\to /P.M']$}\n\t};\n    \\node[state,accepting]\n\t(E)[rounded rectangle, draw,right=of P]\n\t{\n\t    {$[M'\\to *PM'.]$} \\\\\n\t    {$[M'\\to /PM'.]$}\n\t};\n    \\path[->] (S) edge  node [above] {\\lexkeyword{*}} (Mul);\n    \\path[->] (S) edge  node [above] {\\lexkeyword{/}} (Div);\n    \\path[->] (Mul) edge  node [above] {P} (P);\n    \\path[->] (Div) edge  node [above] {P} (P);\n    \\path[->] (P) edge  node [above] {M'} (E);\n\\end{tikzpicture}\n\\]\n\n\\subsubsection{Eliminating left recursion (in EBNF Form)}\n\nExpressing the BNF notation in EBNF reveals how the item automata for $M$ and\n$M'$ can be combined in an implementation using a while loop\nchecking if the\ncurrent token is in $\\mathrm{First}(M') = \\{ \\lexkeyword{*}, \\lexkeyword{/}\\}$:\n\\begin{grammar}\n\\underbrace{\\nonterminal{multiplicative-expression}}_{= M}\n    \\produces\n\t\\underbrace{\\nonterminal{power-expression}}_{= P}\n\t\\{\\;\n\t\\underbrace{\n\t    \\nonterminal{multiplicative-op}\n\t    \\nonterminal{power-expression}\n\t    }_{=M'}\n\t\\}\n\t\\\\\n\\nonterminal{multiplicative-op}\n    \\produces\n    \\lexkeyword{*} \\\\\n    \\produces\n    \\lexkeyword{/} \\\\\n\\end{grammar}\\\\[-0.5cm]\n\n", "meta": {"hexsha": "8844e54252384b39ed5040b66ed93d6042fb6e84", "size": 3097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "solutions/c/michael-lehn/doc/mul.tex", "max_stars_repo_name": "michael-lehn/uulm_cb_solutions_practical-1", "max_stars_repo_head_hexsha": "5d32b4a2faf88f58c4a6b0b72490cc76281070ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-12-01T10:45:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-04T17:04:56.000Z", "max_issues_repo_path": "solutions/c/michael-lehn/doc/mul.tex", "max_issues_repo_name": "michael-lehn/uulm_cb_solutions_practical-1", "max_issues_repo_head_hexsha": "5d32b4a2faf88f58c4a6b0b72490cc76281070ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-12-01T13:05:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-04T13:11:18.000Z", "max_forks_repo_path": "solutions/c/michael-lehn/doc/mul.tex", "max_forks_repo_name": "michael-lehn/uulm_cb_solutions_practical-1", "max_forks_repo_head_hexsha": "5d32b4a2faf88f58c4a6b0b72490cc76281070ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-12-01T10:41:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-04T10:45:36.000Z", "avg_line_length": 25.3852459016, "max_line_length": 79, "alphanum_fraction": 0.6328705199, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587586, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.6099927642442958}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{graphicx}\n\\usepackage[export]{adjustbox}\n\\usepackage{amsmath}\n\\usepackage[ruled,vlined]{algorithm2e}\n\n\\title{Machine Learning Overview}\n\\author{Hanchung Lee}\n\\date{February 2020}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Linear Regression}\n\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Linear Regression, in essence, is trying to fit a hyperplane through the data points that minimizes the sum of the distances of all the points to that hyperplane. That hyperplane is then used to predict the location of new data points. In other words, linear regression is a model $\\emph{f} : \\mathbb{R}^{d+1} \\rightarrow \\mathbb{R}$ for a given data pair $(x, y)$ where $x \\in \\mathbb{R}^{d+1}$ and $y \\in \\mathbb{R}$. It is if if the function \\emph{f} is linear, with weights $w$ of the model is the parameters to be learned. Since regression is a mapping to $\\mathbb{R}$, it can be used to estimate a value given a set of inputs $x$.\n    \n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    Regression assumes that the output $y$ is linearly dependent on $x$. However, it will be linear dependent as long as $w$ is linear. It also assumes error term is a normally distributed random variable.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    We model linear regression problem $\\mathbf{y} = \\mathbf{X}\\mathbf{w} + \\mathbf{b}$ using both least squares (LS) or maximum likelihood (ML) solutions:\n    $$\\mathbf{LS}: \\; arg \\min_{w} \\left\\|y - \\mathbf{X}w\\right\\|_{2}^{2}$$\n    $$\\mathbf{ML}: \\; arg \\max_{w} -\\frac{1}{2\\sigma}\\left\\|y - \\mathbf{X}w\\right\\|_{2}^{2}$$\n    Or, alternatively, solving it using vector calculus approach, we solve $\\frac{\\partial}{\\partial{X}}\\left\\|\\mathbf{X}\\mathbf{W} + \\mathbf{b}\\right\\|_{2}^{2} = 0$, and we get\n    $$\\mathbf{X} = (\\mathbf{W}^T\\mathbf{W})^{-1}\\mathbf{W}^T\\mathbf{b}$$\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    Regression can be done using loss functions that spans the $\\mathbb{R}$ space. Mean square error and mean absolute error are the common cost function of choice. We used mean squared error for our formulation.\\\\\n    \\smallbreak\n    Mean squared error (L2 error)  $\\left\\|y - y'\\right\\|_{2}^2 = (y - \\mathbf{X}w)^2$ \\\\ \n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    Linear regression is one of the most fundamental machine learning model. It is easy to implement and train. The trained model is also highly explainable. The modeling framework can be extended by different tricks to make it more robust, such as feature engineering/extension/selection, kernel tricks, and adding regularization.\n    \n    On the flip side, linear regression only model linear relationships between dependent and independent variables (which can be polynomials), which is not enough for more complex relationships. It is also sensitive to anomalies and requires data normalization to prevent that. Also, it requires more samples than the number of parameters as a rule of thumb, which is common across most machine learning models.\n    \n\\end{enumerate}\n\n\\section{Ridge Regression}\n\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Ridge regression is an extension of base regression with an \\verb|L2 norm| regularization term $\\mathbf{\\lambda}\\left\\| \\mathbf{W}\\right\\|_{2}^{2}$ where $\\mathbf{\\lambda}$ is the learning rate that adjusts the regularization of parameters $\\mathbf{W_{i}}$. \\cite{1} The $\\mathbf{\\lambda}$ term is also called the \\emph{shrinkage}. And when $\\mathbf{\\lambda} = 0$, it is just regular linear regression.\n    \n    In other words, we use ridge regression to fix if a linear regressor has high variance to improve the out of the sample fit of the model. We can find the learning rate parameter $\\lambda$ using cross validation.\n    \n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    As with linear regression, Ridge regression assumes that the output $y$ is linearly dependent on $x$. However, it will be linear dependent as long as $w$ is linear. It also assumes error term is a normally distributed random variable.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    From the descriptions above, we can model ridge regression as linear regression problem with a regularization term.\n    $$\\mathbf{y} = \\mathbf{X}\\mathbf{W} + \\mathbf{b} + \\lambda\\left\\|\\mathbf{W}\\right\\|_{2}^{2}$$\n    Thus, the loss function using least squared solution would be:\n    $$\\mathbb{L}_{W_{ridge}} = \\left\\|\\mathbf{y} - (mathbf{X}\\mathbf{W} + \\mathbf{b})\\right\\|_{2}^{2} + \\lambda\\left\\|mathbf{W}\\right\\|_{2}^{2}$$\n    Pulling in the bias term into W and solving it for \\mathbf{W}, we get: \n    $$\\mathbf{W} = (\\lambda\\mathbb{I} + \\mathbf{X}^{T}\\mathbf{X})^{-1}\\mathbf{X}\\mathbf{y},$$\n    where the $\\lambda$ term gets cancelled out as $\\lambda$ goes to $\\infty$.\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    Regression can be done using loss functions that spans the $\\mathbb{R}$ space. Mean square error and mean absolute error are the common cost function of choice. We used mean squared error for our formulation.\\\\\n    \\smallbreak\n    Mean squared error (L2 error)  $\\left\\|y - y'\\right\\|_{2}^2 = (y - \\mathbf{X}w)^2$ \\\\\n    \\smallbreak\n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    Ridge regression extends from Linear regression with a regularization term. Thus it shares similar properties as linear regression: easy to implement, easy to train. The trained model is also highly explainable. The modeling framework can be extended by different tricks to make it more robust, such as feature engineering/extension/selection.\n    \n    On the flip side, it also shares some of the problems with linear regression only model, where it expects linear relationships between dependent and independent variables (which can be polynomials), which is not enough for more complex relationships. It is also sensitive to anomalies and requires data normalization to prevent that. Also, it requires more samples than the number of parameters as a rule of thumb, which is common across most machine learning models.\n    \n\\end{enumerate}\n\n\\section{Lasso Regression}\n\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Lasso regression is an extension of basic regression with an \\verb|L1 norm| regularization term $\\mathbf{\\lambda}\\left\\| \\mathbf{W}\\right\\|_{1}$ where $\\mathbf{\\lambda}$ is the learning rate vector that adjusts the regularization of parameters $\\mathbf{W_{i}}$. \\cite{1} The $\\mathbf{\\lambda}$ term is also called the \\emph{shrinkage}\n    \n    In other words, Lasso is similar to Ridge where both helps adding biases to the model to improve the out of the sample fit of the model.\n    Lasso is especially useful for dealing with sparse data.\n\n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    The same as regression, assuming \\verb|i.i.d.| of sampled data.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    Same as regression except adding an L1 norm term to penalize Weight coefficients of some variables. \n    \n    Cross validation is used to select the regularization hyperparameter $\\mathbf{\\lambda}$.\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    $$\\mathbf{W}^{lasso} = {argmin}_\\mathbf{W}} \\left\\{\\frac{1}{2} \\sum_{i = 1}^{N} (y_i - \\mathbf{W}_0 - \\sum_{j=1}^{P} x_{ij}\\mathbf{W}_{j})^2 + \\mathbf{\\lambda}\\sum_{j=1}^{P}\\left\\|\\mathbf{W}_{i}\\right\\|_{1}\\right\\}$$ \\cite{1}, where the first term within the $argmin$ is the mean squared error and the second term is the Lasso regularization. This can be solved with convex optimization.\n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    The prime difference between Lasso (L1) vs Ridge (L2) regularization of regression is that Lasso has the capability of forcing coefficients to $0$, and in effect, zeros out an feature variable. In essence, Lasso regression is doing feature selection.\n    \n    In a geometric sense, in high dimeisions, L1 norm will have many sharped edges and corners. During convex optimization, if the optimization hits the edges or corners, the coefficient become zero.  ON the other hand, L2 norm is a smooth surface thus it won't hit exactly model\n    \n    \\includegraphics[width=0.5\\textwidth, center]{ridge_vs_lasso.png}\n    \n    Thus, we can say that Lasso Regression yields a \\emph{sparse} model where only a subset of the variables is in play. \n    \n    Ridge is more suited for models with dense features while Lasso is more suited for models with sparse features. Use cross validation to determine the most suitable regularization.\n\\end{enumerate}\n\n\n\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\n\\section{Gradient Boosting}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Gradient boost decision tree models works by training many trees in sequence and ensemble the trees together at the end. When training sequentially, each of the newer trees are trained on the residual error observed by the previous tree. GBDT models tends to fit the training data well, with low bias and high variances. Because of that, it uses a learning rate $\\lambda$ to scale contribution from a new tree. The idea is to take many small steps towards the right direction and ensemble them together result in a better prediction.\n\n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    Decision tree based models makes no assumption about the distribution of the underlying data. In other words, decision trees are non-parametric.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    Gradient boost initializes by building \\verb|depth=1| node. It builds a tree depending on the depth and splits parameters. Then for the following trials it kept on building new trees to minimize the residual errors $(y - \\gamma)$from the previous tree, and scale the contribution with a learning rate $\\lambda$. The whole process is repeated $M$ times and the maximum depth of the individual trees is $J$.\n    \n    A formal definition is as follows \\cite{1}\n    \\bigbreak\n    \\noindent\n    \\hline\n    \\textbf{Algorithm} Gradient Tree Boosting Algorithm\n    \\hline\n    \\begin{enumerate}\n        \\item Initialize $f_o(x) = argmin_{\\gamma} \\sum_{i=1}^{N} L(y_i, \\gamma)$\n        \\item For \\emph{m} = 1 to \\emph{M}:\n            \\begin{enumerate}\n                \n                \\item For \\emph{i} = 1, 2, . . . , \\emph{N} compute the pseudo residual term\n                $r_{im} = -\\left[ \\frac{\\partial L(y_i, f(x_i))}{\\partial f(x_i)}\\right]_{f = f_{m-1}}$\n                \\item For a regresion tree to the target $\\emph{r}_{im}$ given terminal regions $R_{jm}, j = 1, 2, ..., J_m$\n                \\item For $j = 1, 2, ..., J_m$, find the new predicted value $\\gamma$ \\\\\n                $\\gamma_{jm} = argmin_{\\gamma} \\displaystyle\\sum_{x_i \\in R_{jm}} L(y_i, f_{m-1}(x_i) + \\gamma)$\n                \\item Update $f_m(x) = f_{m-1}(x) + \\lambda \\sum_{j=1}^{J_m} \\gamma_{jm} I(x \\in R_{jm})$\n            \\end{enumerate}\n        \\item Output $\\hat f(x) = f_M(x)$\n    \\hline\n    \\end{enumerate}\n\n\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    Given the standard loss function setup, $L(f) = \\sum_{i=1}^{N} L(y_i, f(x_i))$, proper loss function $L(f)$ can be used for different settings. A summary table is as follows \\cite{1}:\n    \\begin{center}\n      \\begin{tabular}{ l | l | l }\n        \\hline\n        Setting & Loss Function & $ \\frac{-\\partial L(y_i, f(x_i))}{\\partial f(x_i)}$ \\\\ \\hline\n        Regression & $\\frac{1}{2}[y_i - f(x_i)]^2$ & $y_i - f(x_i)$ \\\\ \\hline\n        Regression & $\\left\\||y_i - f(x_i)|\\right\\|$ & sign[y_i - f(x_i)] \\\\ \\hline\n        Regression & Huber & y_i - f(x_i) for |y_i - f(x_i)| \\leq \\delta_m \\\\ \n         & & \\delta_m sign[y_i- f(x_i)] for |y_i - f(x_i)| > \\delta_m \\\\ \n         & & where \\delta_m \\eq \\alpha th-quantile \\{|y_i - f(x_i)|\\} \\\\ \\hline\n        Classification & Multinominal Deviance & \\emph{k}th component: $I(y_i \\eq G_k) - p_k(x_i)$ \\\\\n        \\hline\n      \\end{tabular}\n    \\end{center}\n    \n    \\item \\textbf{What are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    Gradient boost is very similar to AdaBoost. The key difference is that for Gradient Boost, it can have a tree size that is larger than a stomp (depth of 1). Because gradient boosting is a boosting model that ensembles sequentially trained models, it is a naturally a low bias model. However, the downside is to a low bias model is the variance can be high and has to be reduced by adding regularization. Also, because the model is trained sequentially, it is compute intensive to train.\n    \n\\end{enumerate}\n\n\n\\section{K-Nearest Neighbors}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    K-Nearest Neighbors can be used for either regression or classification. It finds the K nearest points next to a new input data and determines the value or class by taking the mean value of its K nearest neighbors, or in the case of classification, mode. It captures the point similarity with its neighbours.\n    \n    The smaller the K, smaller training error; the larger the K, the more smooth the decision boundary due to majority voting of neighbors. To find the optimal K, cross validate or grid search.\n\n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    KNN is a non parametric model. The basic assumption is that the data points close to it will have the same class labels for classification, or similar values in terms of regression.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    Given data $(x_1, y_1), (x_2, y_2), ..., (x_i, y_i)$, construct KNN as follows:\n    For a new input $x$:\n    \\begin{enumerate}\n        \\item Return $k$ nearest points closest to $x$, indexed as $x_{i1}, x_{i2}, ..., x_{ij}$.\n        \\item Return the majority vote of $y_{i1}, y_{i2}, ..., y_{ij}$.\n    \\end{enumerate}\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    KNN does not use a loss function to train the model. Instead, it uses distance functions, where the most common distance function is \\verb|L2 norm| $= \\left\\|u - v\\right\\|_2 = (\\sum_{i=1}^{d}(u_i - v_i)^{2})^\\frac{1}{2}$ for dimension $\\mathbb{R}^d$. Or, in a more generalized form,\\\\\n    $$\\left\\|u - v\\right\\|_p = (\\sum_{i=1}^{d}(u_i - v_i)^{p})^\\frac{1}{p}$$\n    \n    Other distances can be used as well, including edit distances (how many edits away to transform from one string to another), or correlation distance (for signal detection).\n    \n    \\item \\textbf{What are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    KNN has an easy to interpret output and it does not make any assumption about the underlying data. Further, it can naturally extend to multi-class classifier and can do well in practice with enough data. For example, KNN can achieve 90\\%+ with MNIST dataset.\n    \n    Om the other hand, it requires data to in or relatively close to memory, thus when the dataset is big is big enough it becomes a big search problem. Also, finding a proper distance function requires some expert knowledge, heuristics, or a grid search.\n\\end{enumerate}\n\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\\bigbreak\n\n\n\\section{K-means Clustering}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    K-means is an unsupervised learning method where it tries to separate data into $K$ clusters by finding the $K$ centroids within the dataset.\n    \n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    K-means is a non-parametric unsupervised learning model. It assumes the clusters separated/calculated has a \"circular\" shape with a centroid each  as it attempts to assign each sample $(x_1, ..., x_n)$ to one of the $K$ clusters $\\{C_1, ..., C_k\\}$\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    To run K-means clustering, we use the following algorithm:\n    \n    \\begin{algorithm}\n        Initialize randomly centeroids $\\mu_1, ..., \\mu_k$\\;\n        \\Repeat{convergence}{\n            assign each point $x_i$ to the cluster with the closet $\\mu_j$;\\\\\n            Calculate the new mean for each cluster as follows:;\\\\\n            $\\mu_j = \\frac{1}{\\|C_j\\|} \\sum_{x_i \\in C_j} x_i$\\\\}\n        \\caption{K-means algorithms}\n        Convergence: means no change in the clusters OR maximum number of iterations reached.\n    \\end{algorithm}\n    \n    To find the optimal $k$ that clusters the data, we can use PG-means algorithm \\cite{5}. Other alternatives are G-means and P-means.\n    \\begin{algorithm}\n        Initialize $k$ to be a small number;\n        \\Repeat{no more cluster center is created.}{\n            Run K-means with those cluster centers, and store the resulting center as C\\\\\n            Assign each point to its nearest cluster\\\\\n            Determine if points in each cluster fit a Gaussian distribution (using Anderson-Darling test).\\\\\n            For each cluster, if the points seem to be normally distributed, keep the cluster center. Otherwise replace it with two cluster centers.}\n        \\caption{PG-means algorithm}\n    \\end{algorithm}\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    There's no cost functions for K-means clustering per se, but the algorithm uses $\\mu_j = \\frac{1}{\\|C_j\\|} \\sum_{x_i \\in C_j} x_i$ to calculate the mean of each centroid.\n    \n    \\item \\textbf{What are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    The biggest benefit for K-means Clustering as a clustering algorithm is that its super easy to implement.\n    \n    However there are many downsides. First, it needs to know $K$, which we can 'solve' using PG-means algorithm\\cite{5}, but there still exists no trivial way to evaluate the model similar to, say, comparing to counting the number of errors in a classification. K-means also suffers from the curse of dimensionality and has no theoretical foundation.\n    \n    There are other methods to cluster non-circular shapes, such as spectral clustering, DBScan, BIRCH, etc that handles other shapes. Alternatively, we can use PCA and TSNE for clustering higher dimensional data.\n\\end{enumerate}\n\n\n\n\\section{Naive Bayes}\n\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Naive Bayes classifier is a probabilistic model based on the Bayes rule. It is Naive because it makes an assumption that inputs are conditionally independent of each output class, which is not realistic. It is also known as \"Idiot's Bayes\"\\cite{1}. Despite that, naive Bayes classifiers often outperform far more sophisticated alternatives. It's a simple and strong method that can be comparable to decision trees and neural networks in certain cases.\n    \n    It is most commonly seen and used in text classification models. \n    \n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    \n    It is Naive because it makes an assumption that inputs are conditionally independent of each output class, which is not realistic. It is also known as \"Idiot's Bayes\"\\cite{1}.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    \\textbf{Learning:} Based on the frequency counts in the dataset:\n    \\begin{enumerate}\n        \\item Estimate all $p(y), \\forall y \\in \\mathbb{Y}$\n        \\item Estimate all $p(x_i|y), \\forall y \\in \\mathbb{Y}, \\forall x_i$\n    \\end{enumerate}\n    \\textbf{Classification:} For a new example, use:\\\\\n    \\begin{align*}\n        y_{new} = argmax_{y \\in \\mathbb{Y}} \\mathbf{\\Pi}_{i} p(x_i|y)    \n    \\end{align*}\n    \n    No model per se or hyperplane, just count the frequencies of various data combinations within the training examples.\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    \"Cost\" function for naive Bayes is not the same as algorithms, where other algorithms try to adjust the model weights with regards to the value that the cost function outputs. Naive Bayes is simply doing \n    \\begin{align*}\n        y_{new} = argmax_{y \\in \\mathbb{Y}} \\mathbf{\\Pi}_{i} p(x_i|y)    \n    \\end{align*}\n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    Naive Bayes is a linear classifier, an variant of Linear Discrimanent Analysis. It is incredibly simple and easy to implement and works wonderfully for text data. It is especially appropriate when the dimension of the feature space is high. The model is light weight and runs very fast for real time inferencing. It is especially useful when inference time budget is small.\n    \n    The naive assumption of feature Independence is a double edged sword. While the assumption made naive Bayes a simple and powerful model, the assumption also prevent it to learn further intricacies of the underlying relationships. One other major disadvantage of naive Bayes is that it does not generalize well to unseen inputs.\n    \n\\end{enumerate}\n\\pagebreak\n\n\\section{Support Vector Machines}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    Support Vector Machines finds the hyperplane that separates the data with the greatest margin. Two key concepts of Support Vector Machine is it uses soft margins instead of max margins to reduce variances and it uses the kernel trick to implicitly increase the feature space to reduce bias. \n    \n    It can be used for both classification and regression problems. It uses a kernel function to compute the inner product of two variables in a higher dimensional space. The data that resides in the soft margin are called support vectors, with distance to the soft margin line $\\epsilon$. Hyperparameter \\textbf{C} is learning rate and is found using cross validation.\n    \n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    Support Vector Machine treats all the data points as equals so it is important to standardize the data. Otherwise it does not make assumptions about the underlying data distribution.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    Support Vector Machine is a convex optimization problem where it \\textbf{Solve:} $\\min_{w, b, \\epsilon}\\frac{1}{2}\\left\\|w\\right\\|_{2}^{2} + C\\sum_{i=1}^{n} \\epsilon_i$ such that $y_i(w^{T} x_i - w_0) \\geq (1 - \\epsilon_i)$ and $\\epsilon_i \\geq 0, \\quad \\forall i$. After derivation, Support Vector Machine function is:\n    $$f(x) = w_o + \\sum \\hat{\\alpha_i}K(x, x_i)$$\n    where $\\hat{\\alpha_i}$ are zero for data not in the support set and $K$ is the Kernel function. The common kernels are polynomial, radio basis kernel (behaves similar to nearest neighbor), and neural network kernel. \\cite{1}\n    \\begin{center}\n      \\begin{tabular}{ l l }\n        \\hline\n        nth-Degree polynomial & $K(x,x') = (1 + (x, x'))^d$ \\\\\n        Radial basis function (RBF) & $K(x, x') = exp(-\\gamma\\left\\|x - x'\\right\\|_{2}^{2}$ \\\\ \n        Neural network & $K(x, x') = tanh(\\kappa_1(x, x') + \\kappa_2)$ \\\\ \n        \\hline\n      \\end{tabular}\n    \\end{center}\n    \n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    Support Vector Machine uses hinge loss, which has the form of loss plus penalty. $L[y, f(x)] = [1 - yf(x)]_{+}$The following compares the negative log likelihood loss to hinge loss. Note that sharp hinge corner, that is when $\\aplha$ are set to zero.\n    \n    \\includegraphics[width=0.3\\textwidth, center]{hinge_loss_han.png}\n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    When classes are nearly separable, SVM does better than logistic regression and LDA. When classes are not, then SVM does similarly well as logistic regression. We can use kernel tricks with LDA and logistic regression as well, but more compute intensive.\n    \n    The downside with SVM is it does not provide a probability estimate, low interpretability, and does not do any feature selection.\n    \n\\end{enumerate}\n\n\n\\section{Neural Networks}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts? What problem does it solve?}\n    \\noindent \n    \\smallbreak\n    According to the Universal Approximator Theorum, neural networks is an universal function approximator that can be used approximate any functions that map $X \\rightarrow Y$. It can be used abstracts away some of the feature engineering steps in classical machine learning tasks. For example, instead of designing image filters, CNN learns the filters itself, or instead of tagging word semantic labels, RNNs learns the relationships between words.\n    \n    The most fundamental neural network layer is a linear layer where $f(\\mathbf{X}) = \\sum_{m=1}^{M} g_m(\\mathbf{W_m}\\intercal\\mathbf{X})$, where the input values go through an affine transformation and scaled by an activation function $g_m$. Activation functions usually tend to scale the outputs to pseudo range bound, such as Sigmoid and Tanh. \n\n    \\item \\textbf{What are the assumptions?}\n    \\noindent \n    \\smallbreak\n    The assumptions are highly dependent on the structure of neural networks. For example, some neural network architectures such as convolution neural networks or recurrent neural nets assumes that the underlying data are \\emph{i.i.d} while some other architectures such as Bayesian neural networks or Graph neural nets could have different assumptions about the relationships between feature spaces.\n    \n    \\item \\textbf{What are the steps of the algorithm?}\n    \\noindent \n    \\smallbreak\n    Neural networks is predominant solved using stochastic gradient descent with an auto differentiation library. First, inputs are feed forward through the network for an output $\\hat y$, and apply the loss function. The algorithm then take the gradients of the loss function and back propagate the network to obtain the differences in parameters between target and output. The parameters are then updated with the differences. One small batch at a time.\n    \\bigbreak\n    \\hline\n    \\noindent\n    \\textbf{Algorithm} Stochastic gradient descent (SGD) update at training iteration k \\cite{2}\n    \\hline\n    \\smallbreak\n    \\textbf{Require:} Learning rate $\\epsilon_k$\n    \n    \\textbf{Require:} Initial parameter $\\theta$\n    \n    \\qquad \\textbf{while} stopping criterion not met \\textbf{do}\n    \n    \\qquad \\qquad Sample a minibatch of \\emph{m} examples from the training set $\\{x^{(1)}, ..., x^{(m)}\\}$ with corresponding targets $y^{(i)}$\n    \n    \\qquad \\qquad Compute gradent estimate: $\\hat g \\leftarrow + \\frac{1}{m}\\nabla_{\\theta}\\sum_{i} L(f(x^{i};\\theta),y_{(i)})$\n    \n    \\qquad \\qquad Apply update: $\\theta \\leftarrow \\theta - \\epsisolon\\hat g$\n    \n    \\qquad \\textbf{end while}\n    \\smallbreak\n    \\hline\n\n    \\item \\textbf{What is the cost function?}\n    \\noindent \n    \\smallbreak\n    Neural networks is an flexible architecture thus different loss functions can be used for different tasks. Typical loss functions includes cross entropy and negative log likelihood for classification and mean absolute error (L1) and mean squared error (L2) for regressions.\n    \n    \\item \\textbf{Whare are the advantages/disadvantages?}\n    \\noindent \n    \\smallbreak\n    Rather than considering neural networks as a kind of model, it is closer to a highly customizable building blocks for machine learning models. Depends on the complexity of the network constructed, it can be capable of learning a large amount of information from data. At the same time it excels in learning implicit relationships. \n    \n    However, it is an black box model that is quite difficult to interpret and usually has to rely on large data sets and large amount of compute power to train. It is also difficult to debug and fine tune.\n    \n\\end{enumerate}\n\n\n\\section{Generative vs Discriminative}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts?}\n    \\noindent \n    \\smallbreak\n    \\textbf{Generative classifiers} learns a model of the join probability $p(x, y)$, of the input $x$ and the label $y$, and make their predictions by using Bayes rules to calculate $p(y|x)$, then pick the most likely label $y$.\\cite{4} In learning joint probability $p(x, y)$ it learns both $p(x|y)$ (likelihood) and $p(y)$ (class prior) and make inference using Bayes rule. Generative models can use the joint probability $p(x, y)$ to generate new data similar to existing data. It also requires not as much data samples to train and easy to implement.\n    \\begin{itemize}\n        \\item[--] Idea: Build a model for what positive examples look like. Build a different model for what negative example look like.\n        \\item[--] To predict a new example, match it with each of the models and see which match is best.\n        \\item[--] Model $p(x|y)$ and $p(y)$\n        \\item[--] Use Bayes rule to obtain $p(y|x) = \\frac{p(x|y)p(y)}{p(x)}$\n        \\item[--] To make a prediction: \\\\\n        \\begin{align*}\n            argmax_{y} p(y|x) &= argmax_{y} \\frac{p(x|y)p(y)}{p(x)} \\\\\n              &\\approx argmax_{y} p(x|y)p(y)  \\\\ \n        \\end{align*}\n        \n    \\end{itemize}\n\n    \\noindent \n    \\smallbreak\n    \\textbf{Discriminative classifiers} models the posterior $p(y|x)$ directly, or learn a direct map from input $x$ to class labels.\\cite{4} Discriminative models generally offers better performance in classification tasks.\n    \\begin{itemize}\n        \\item[--] Idea: model $p(y|x)$, conditional distribution of $y$ given $x$.\n        \\item[--] In discriminative algorithms: find a decision boundary that separates positive from negative examples\n        \\item[--] To predict a new example, check which side of the decision boundary it falls\n        \\item[--] Model $p(y|x)$ directly.\n    \\end{itemize}\n    \n    \\noindent \n    \\smallbreak\n    Here are some examples of generative and discriminative models:\n    \\begin{center}\n      \\begin{tabular}{ l l }\n        \\hline\n        \\textbf{Generative} & \\textbf{Discriminative} \\\\\n        \\hline\n        Naive Bayes & Logistic regression \\\\\n        Hidden Markov model & K-nearest neighbors \\\\ \n        Gaussian mixture model & Support vector machines \\\\\n        Generative adversarial networks & Neural networks \\\\ \n        \\hline\n      \\end{tabular}\n    \\end{center}\n    \n\\end{enumerate}\n\\pagebreak\n\n\\section{Bias-Variance Trade off}\n\\noindent\n\\begin{enumerate}\n    \\item \\textbf{What are the basic concepts?}\n    \\noindent \n    \\smallbreak\n    \n\\end{enumerate}\n\n\n\\begin{thebibliography}{}\n\\bibitem{1}\nHastie, Tibshirani, and Friedman,\n\\emph{The Elements of Statistical Learning}.\n2nd Edition,\n2009.\n\n\\bibitem{2}\nGoodfellow, Bengio, Courville,\n\\emph{Deep Learning},\n2016\n\n\\bibitem{3}\nNasirany, Thomas, Wei, and Yang,\n\\emph{A Comprehensive Guide to Machine Learning},\n2018\n\n\\bibitem{4}\nNg and Jordan,\n\\emph{On Discriminative vs Generative Classifiers: A comparison of logistic regression and naive Bayes}\n2002\n\n\\bibitem{5}\nHamerly and Elkan\n\\emph{PG-means: learning the number of clusters in data}\n2003\n\n\\end{thebibliography}\n\\end{document}\n\n", "meta": {"hexsha": "dad4194956e2b60a52fed86a7d867cd10c0dec74", "size": 32151, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "machine-learning/Han_notes.tex", "max_stars_repo_name": "elliotgunn/ml-cs-practice", "max_stars_repo_head_hexsha": "75515be84c19c286ccc38fae9538c7ffc0dee043", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-02-27T05:29:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-20T18:56:31.000Z", "max_issues_repo_path": "machine-learning/Han_notes.tex", "max_issues_repo_name": "elliotgunn/ml-cs-practice", "max_issues_repo_head_hexsha": "75515be84c19c286ccc38fae9538c7ffc0dee043", "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": "machine-learning/Han_notes.tex", "max_forks_repo_name": "elliotgunn/ml-cs-practice", "max_forks_repo_head_hexsha": "75515be84c19c286ccc38fae9538c7ffc0dee043", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-02-19T17:48:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-09T13:43:31.000Z", "avg_line_length": 57.9297297297, "max_line_length": 640, "alphanum_fraction": 0.7060122547, "num_tokens": 8507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6099621091979026}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\t\t\\chapter{Logarithms}\n\t\\section{Definition}\n\t\\quad In mathematics, the logarithm is the inverse function to exponentiation. That means the logarithm of a given number $x$ is the exponent to which another fixed number, the base $b$, must be raised, to produce that number $x$.\\\\\n\t\n\t\\emph{Consider: }\\\\$$ 2^3 = 8$$\\\\\n\t\n\t3 is the exponent by which 2 must be raised to obtain 8. This statement can also be reversed:\\\\ 3 is the logarithm by which with a base of 2, results in 8. Thus:$$ 3 = \\log_28$$\\\\\n\t\n\t\\emph{In general: }\\\\$$a^b = c \\iff \\log_ac = b ,\\quad a \\in \\mathbb{R^+}$$\\\\\n\t\n\t\n\tFurthermore, it is standard to represent $\\log_{10}(x)$ as $\\log(10) $ and $ \\log_e(x) $ as $ \\ln(x) $\n\t\n\t\n\t\\bigskip\n\t\\bigskip\n\t\\bigskip\n\t\\bigskip\n\t\n\t\\tcbset{\n\t\tenhanced,\n\t\tcolback=red!5!white,\n\t\tboxrule=0.1pt,\n\t\tcolframe=black!75!black,\n\t\tfonttitle=\\bfseries\n\t}\n\t\\begin{center}\n\t\t\\begin{tcolorbox}[center title,hbox,    %%<<---- here\n\t\t\tlifted shadow={1mm}{-2mm}{3mm}{0.1mm}%\n\t\t\t{black!50!white}]\n\t\t\t\\begin{varwidth}{\\textwidth}\n\t\t\t\t\\begin{center}\n\t\t\t\t\t$\t\\log_a1                         = 0                    $ \\\\\n\t\t\t\t\t\\bigskip\n\t\t\t\t\t$\\log_aa                          = 1                    $ \\\\\n\t\t\t\t\t\\bigskip\n\t\t\t\t\t$\t\\log_c(ab)                       \\equiv \\log_ca + log_cb $\\\\\n\t\t\t\t\t\\bigskip\n\t\t\t\t\t$\t\\log_c\\left (\\frac{a}{b}\\right)  \\equiv \\log_ca - log_cb$ \\\\\n\t\t\t\t\t\\bigskip\n\t\t\t\t\t$\tn\\log_ca                         \\equiv \\log_ca^n   $     \n\t\t\t\t\\end{center}\n\t\t\t\\end{varwidth}\n\t\t\\end{tcolorbox} \n\t\\end{center}\n\t\\section{Proofs}\n\t\n\t\n\t\n\t\\paragraph{Proof 1: }$\\log_aa  = 1$\n\t\\begin{center}\n\t\t$\t\\text{Let} \\log_aa = x$\n\t\t$$   a^x      = a $$\n\t\t$$x        =1 $$\n\t\\end{center}\n\t\\paragraph{Proof 2: }$\\log_aa  = 1$\n\t\\begin{center}\n\t\t$\t\\text{Let} \\log_a1 = x$\n\t\t$$   a^x      = 1 $$\n\t\t$$x        = 0$$\n\t\\end{center}\n\t\\paragraph{Proof 3: }$\\log_cab  = \\log_ca + \\log_cb$\n\t\\begin{center}\n\t\t$\t\\text{Let} \\log_ca = x$ ; $\\text{Let} \\log_cb = y$\n\t\t$$\\Rightarrow  c^{x} = a  \\text{ ; } c^{y} = b$$\n\t\t$$\\Rightarrow ab = c $$\n\t\t$$\\Rightarrow\\log_c(ab) = \\log_c(x) + \\log_c(y)$$\n\t\t$$\\therefore\\quad \\log_c(ab) = \\log_c(a) + \\log_c(b)$$\n\t\\end{center}\n\t\\paragraph{Proof 4: }$\\log_c\\frac{a}{b}  = \\log_ca - \\log_cb$\n\t\\begin{center}\n\t\t$\t\\text{Let} \\log_ca = x$ ; $\\text{Let} \\log_cb = y$\n\t\t$$  c^{x} = a  \\text{ ; } c^{y} = b$$\n\t\t$$\\frac{a}{b} = c^x \\times c^{-y} $$\n\t\t$$\\log_c\\frac{a}{b} = \\log_c(x) - \\log_c(y)$$\n\t\\end{center}\n\t\\paragraph{Proof 5: }$\\log_ca^n = n\\log_ca$\n\t\\begin{center}\n\t\t$\t\\text{Let} \\log_ca^n = x$\n\t\t$$ c^x = a^n$$\n\t\t$$c^{\\frac{x}{n}} = a  $$\n\t\t$$\\log_ca = \\frac{x}{n}$$\n\t\t$$x = n\\log_ca $$\n\t\\end{center}\n\\end{document}", "meta": {"hexsha": "444d01c833efc9b8b45ff25fef1930f9a4039612", "size": 2648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Logarithms.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/Logarithms.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/Logarithms.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": 30.4367816092, "max_line_length": 233, "alphanum_fraction": 0.539652568, "num_tokens": 1072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6099621087611563}}
{"text": "\\subsection{Differentials}\\label{sec:differentials}\nVery much related to linear approximations are the {\\em differentials} $dx$ and $dy$, used not to approximate values of $f$, but instead the change (or rise) in the values of $f$.\n\n\\begin{definition}{Differentials dx and dy}{dx}\nLet $y=f(x)$ be a differentiable function. We define a new\n  independent variable $dx$, and a new dependent variable\n  $dy=f'(x)\\,dx$. Notice that $dy$ is a function both of $x$ (since\n  $f'(x)$ is a function of $x$) and of $dx$.  We call both $dx$ and\n  $dy$ \\deffont{differentials}.  \n\\end{definition}\n\nNow fix a point $a$ and let $\\Delta x =x-a$ and $\\Delta y= f(x)-f(a)$.\nIf $x$ is near $a$ then $\\Delta x$ is clearly small. If we set $dx=\\Delta x$ then we obtain\n\\[ dy = f'(a)\\,dx \\approx \\frac{\\Delta y}{\\Delta x}\\Delta x = \\Delta y.\\]\nThus, $dy$ can be used to approximate $\\Delta y$, the actual change in\nthe function $f$ between $a$ and $x$. This is exactly the\napproximation given by the tangent line:\n\\[ dy = f'(a)(x-a) = f'(a)(x-a)+f(a)-f(a)=L(x)-f(a).\\]\nWhile $L(x)$ approximates $f(x)$, $dy$ approximates how $f(x)$ has\nchanged from $f(a)$.\nFigure~\\ref{fig:differentials} illustrates the relationships.\n\n\\figure[!ht]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 4.5, y from 0 to 2.5\n\\axis left /\n\\axis bottom ticks withvalues {$a$} {$x$} / at 1 3 / /\n\\plot 0.500 0.707 0.588 0.766 0.675 0.822 0.762 0.873 0.850 0.922 \n0.938 0.968 1.025 1.012 1.112 1.055 1.200 1.095 1.288 1.135 \n1.375 1.173 1.462 1.209 1.550 1.245 1.638 1.280 1.725 1.313 \n1.812 1.346 1.900 1.378 1.988 1.410 2.075 1.440 2.162 1.471 \n2.250 1.500 2.338 1.529 2.425 1.557 2.512 1.585 2.600 1.612 \n2.688 1.639 2.775 1.666 2.862 1.692 2.950 1.718 3.038 1.743 \n3.125 1.768 3.212 1.792 3.300 1.817 3.388 1.841 3.475 1.864 \n3.562 1.887 3.650 1.910 3.738 1.933 3.825 1.956 3.912 1.978 \n4.000 2.000 /\n\\setlinear\n\\plot 1 1 3 2 3 1 1 1 /\n\\betweenarrows {$dx=\\Delta x$} from 1 0.8 to 3 0.8\n\\betweenarrows {$\\Delta y$} from 3.2 1 to 3.2 1.73\n\\betweenarrows {$dy$} from 3.6 1 to 3.6 2\n\\setdashes <2pt>\n\\putrule from 3 2 to 3.6 2\n\\putrule from 3 1 to 3.6 1\n\\putrule from 3 1.73 to 3.2 1.73\n\\endpicture}}\n\\caption{Differentials.\\label{fig:differentials}}\n\\endfigure\n\nHere is a concrete example.\n\n\\begin{example}{Rise of Natural Logarithm}{rise of natural logarithm}\nApproximate the rise of $f(x)=\\ln x$ from $x=1$ to $x=1.1$, using linear approximation.\n\\end{example}\n\n\\begin{solution}\nNote that $\\ln (1.1)$ is not readily calculated (without a calculator) hence why we wish to use linear approximation to approximate $f(1.1)-f(1)$.\n\nWe fix $a=1$ and as above we have $\\Delta x=x-1$ and $\\Delta y=f(x)-f(1)=\\ln x$, and obtain\n\\[ dy=f'(1)dx\\approx \\frac{\\Delta y}{\\Delta x}\\Delta x=\\Delta y. \\]\nBut $f'(x)=1/x$ and thus $f'(1)=1/1=1$, we obtain in this case\n\\[ dy=dx\\approx\\Delta y. \\]\nFinally for $x=1.1$, we can easily approximate the rise of $f$ as\n\\[ f(1.1)-f(1)=\\Delta y\\approx dy=1.1-1=0.1. \\]\nThe correct value of $\\ln (1.1)=\\ln 1$ is 0.0953\\ldots and thus we were relatively close.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:differentials}}\n\n\\begin{enumialphparenastyle}\n\t\n%%%%%%%%%%\n\\begin{ex} \nLet $\\ds f(x) = x^4$. If $a=1$ and $dx= \\Delta x =1/2$, \nwhat are $\\Delta y$ and $dy$?\n\\begin{sol}\n\t$\\Delta y=65/16$, $dy=2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nLet $\\ds f(x) = \\sqrt{x}$. If $a=1$ and $dx= \\Delta x\n=1/10$, what are $\\Delta y$ and $dy$?\n\\begin{sol}\n\t$\\ds \\Delta y=\\sqrt{11/10}-1$, $dy=0.05$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nLet $f(x) = \\sin (2x)$. If $a=\\pi$ and $dx= \\Delta x\n=\\pi/100$, what are $\\Delta y$ and $dy$?\n\\begin{sol}\n\t$\\ds \\Delta y=\\sin(\\pi/50)$, $dy=\\pi/50$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex} \nUse differentials to estimate the amount of paint needed to\n apply a coat of paint 0.02 cm thick to a sphere with diameter $40$\n meters. (Recall that the volume of a sphere of radius $r$ is $V\n =(4/3)\\pi r^3$. Notice that you are given that $dr=0.02$.)\n\\begin{sol}\n\t$dV=8\\pi/25$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "91d8f86903a7c8e206446d4068165e23d4718f89", "size": 4194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-4-2-differentials.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-2-differentials.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-2-differentials.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.1551724138, "max_line_length": 179, "alphanum_fraction": 0.6473533619, "num_tokens": 1693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6099621073174128}}
{"text": "\\documentclass[a4paper]{article}\n\n\\def\\ntitle{Field Theory}\n\n\\input{header}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Field Extensions}\n\n\\begin{definition}\n  Given a field $F$, there is a unique ring homomorphism $\\phi: \\mathbb{Z} \\rightarrow F, 1 \\mapsto 1$. Let $\\ker \\phi = n\\mathbb{Z}$, then the \\emph{characteristic} of $F$ $\\ch(F) = n$.\n\\end{definition}\n\n\\begin{definition}\n  Fiven a field $F$, the \\emph{prime subfield} of $F$ is the subfield generated by $1_F$.\n\\end{definition}\n\nThe prime subfield of any field is isomorphic to either $\\mathbb{Q}$ or $\\mathbb{F}_p$ for some prime $p$.\n\n\\begin{definition}\n  If $K$ is a field containing a subfield $F$, then $K$ is an extension of $F$, denoted $K/F$.\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{degree of the extension} $K/F$, $[K:F] := \\dim_FK$. The extension is finite if $[K:F]$ is finite, otherwise infinite.\n\\end{definition}\n\n\\begin{proposition}\n  Let $p(x) \\in F[x]$ be irreducible. Then $K:=F[x]/(p(x))\\supseteq F$ and $p$ has a root in $K$.\n\\end{proposition}\n\n\\begin{proposition}\n  Let $p(x) \\in F[x]$ be irreducible of degree $n$, $K:=F[x]/(p(x)),\\: \\theta= x \\mod{p(x)} \\in K$. Then $\\{\\theta^i\\}_{i=0}^{n-1}$ is a basis for $K/F$, so $[K:F]=n$ and $K=\\{\\sum_{i=0}^{n-1} a_i \\theta^i:a_i \\in F\\}$.\n\\end{proposition}\n\n\\begin{proof}\\leavevmode\n  \\begin{itemize}\n  \\item $F[x]$ is a Euclidean domain\n  \\item $p$ is irreducible\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\n  Suppose $K/F$ and $\\alpha,\\beta,\\ldots \\in K$. Then the \\emph{smallest subfield} containing both $F$ and $\\alpha,\\beta,\\ldots$, $F(\\alpha,\\beta,\\ldots)$ is called the field \\emph{generated} by $\\alpha,\\beta,\\ldots$ over $F$.\n\\end{definition}\n\n\\begin{definition}\n  If $K=F(\\alpha)$ then $K$ is a \\emph{simple extension} of $F$ and $\\alpha$ is a \\emph{primitive element} for $K/F$.\n\\end{definition}\n\n\\begin{proposition}\n  Suppose $p(x) \\in F[x]$ is irreducible. Suppose $K/F$ and $\\alpha\\in K$ such that $p(\\alpha)=0$. Then $F(\\alpha) \\cong F[x]/(p(x))$.\n\\end{proposition}\n\n\\begin{proof}\n  Since $p(\\alpha)=0$, we have the following induced homomorphism\n  \\[\n    \\begin{tikzcd}\n      F[x] \\arrow{r}{\\phi} \\arrow{d}[swap]{\\pi} & F(\\alpha)\\\\\n      F[x]/(p(x)) \\arrow[dotted]{ru}[swap]{\\bar\\phi}\n    \\end{tikzcd}\n  \\]\n\n  As $F \\leq \\im(\\bar\\phi) \\leq F(\\alpha)$ and $\\alpha\\in \\im(\\bar\\phi)$, by definition $\\im(\\bar\\phi)=F(\\alpha)$.\n\\end{proof}\n\n\\begin{remark}\n  Roots of an irreducible $p(x)$ are algebraically indistinguishable.\n\\end{remark}\n\n\\begin{theorem}\\label{thm:uniqueness of simple extension}\n  Suppose $\\phi: F\\xrightarrow{\\sim} F',\\: p(x)\\in F[x]$ be irreducible and $p'(x):=\\phi(p(x))$. Suppose $\\alpha,\\beta$ are roots of $p$ and $p'$ respectively. Then $\\sigma: F(\\alpha) \\rightarrow F(\\beta),\\:\\alpha \\mapsto \\beta$ is an isomorphism and\n  \\[\n    \\begin{tikzcd}\n      F \\arrow{r}{\\sim}[swap]{\\phi} \\arrow[hook]{d} & F' \\arrow[hook]{d}\\\\\n      F(\\alpha) \\arrow{r}{\\sim}[swap]{\\sigma} & F'(\\beta)\n    \\end{tikzcd}\n  \\]\n\\end{theorem}\n\n\\begin{proof}\n  $\\phi$ as a map $F[x] \\rightarrow F'[x]$ maps irreducible to irreducible so\n  \\[\n    \\begin{tikzcd}\n      F[x]/(p(x)) \\arrow{r}{\\sim} \\arrow{d} & F'[x]/(p'(x)) \\arrow{d}\\\\\n      F(\\alpha) \\arrow{r} &F(\\beta)\n    \\end{tikzcd}\n  \\]\n\\end{proof}\n\n\\section{Algebraic Extensions}\n\nLet $F$ be a field and $K$ be an extension of $F$.\n\n\\begin{definition}\n  The element $\\alpha\\in K$ is said to be \\emph{algebraic} over $F$ is $\\alpha$ is a root of some nonzero polynomial $f(x)\\in F[x]$. If $\\alpha$ is not algebraic over $F$ then $\\alpha$ is said to be \\emph{transcendental} over $F$. The extension $K/F$ is said to be \\emph{algebraic} if every element of $K$ is algebraic over $F$.\n\\end{definition}\n\n\\begin{proposition}\n  Let $\\alpha$ be algebraic over $F$. Then there is a unique irreducible polynomial $m_{\\alpha,F}(x)\\in F[x]$ which has $\\alpha$ as a root. A polynomial $f(x)\\in F[x]$ has $\\alpha$ as a root iff $m_{\\alpha,F}(x)$ divides $f(x)$ in $F[x]$.\n\\end{proposition}\n\n\\begin{proof}\\leavevmode\n  \\begin{itemize}\n  \\item Let $g(x)\\in F[x]$ be a monic polynomial of minimal degree having $\\alpha$ as a root.\n  \\item $F[x]$ is a Euclidean domain\n  \\end{itemize}\n\\end{proof}\n\n\\begin{definition}\n  The polynomial $m_{\\alpha,F}$ is called the \\emph{minimal polynomial} for $\\alpha$ over $F$. The \\emph{degree} of $m_\\alpha$ is called the \\emph{degree} of $\\alpha$.\n\\end{definition}\n\n\\begin{proposition}\n  Let $\\alpha$ be algebraic over $F$, then\n  \\[\n    F(\\alpha) \\cong F[x]/(m_\\alpha(x))\n  \\]\n  so in particular\n  \\[\n    [F(\\alpha):F] = \\deg m_\\alpha(x) = \\deg \\alpha.\n  \\]\n\\end{proposition}\n\n\\begin{proposition}\n  The element $\\alpha$ is algebraic over $F$ iff the simple extension $F(\\alpha)/F$ is finite.\n\\end{proposition}\n\n\\begin{proof}\n  Use the fact that $\\{\\alpha^i\\}_{i=0}^{\\deg \\alpha}$ is a basis for $F(\\alpha)/F$ when the extension is finite.\n\\end{proof}\n\n\\begin{corollary}\n  A finite extension is algebraic.\n\\end{corollary}\n\n\\begin{eg}[Quadratic Extensions over Fields of Characteristic $\\neq 2$]\n\n  \\texttt{to be filled in}\n\\end{eg}\n\n\\begin{theorem}[Tower Law]\n  Let $F\\subseteq K\\subseteq L$ be fields. Then\n  \\[\n    [L:F] = [L:K][K:F]\n  \\]\n\\end{theorem}\n\n\\begin{definition}\n  An extension $K/F$ is \\emph{finitely generated} if there are elements $\\{\\alpha_i\\}_{i=1}^k$ in $K$ such that $K=F(\\alpha_1,\\ldots,\\alpha_k)$.\n\\end{definition}\n\n\\begin{lemma}\n  $F(\\alpha,\\beta) = (F(\\alpha))(\\beta)$\n\\end{lemma}\n\n\\begin{theorem}\n  The extension $K/F$ is finite iff $K$ is generated by a finite number of algebraic elements over $F$. More precisely,\n  \\[\n    [F(\\alpha_1,\\ldots,\\alpha_k):F] \\leq \\prod_{i=1}^{k} \\deg(\\alpha_i)\n  \\]\n\\end{theorem}\n\n\\begin{corollary}\n  Suppose $\\alpha,\\beta$ are algebraic over $F$. Then $\\alpha\\pm\\beta,\\alpha\\beta,\\alpha/\\beta$ are all algebraic as they are elements of the extenion $F(\\alpha,\\beta)$.\n\\end{corollary}\n\n\\begin{corollary}\n  Let $L/F$ be an arbitrary extension. Then the collection of elements of $L$ that are algebraic over $F$ form a subfield $K$ of $L$.\n\\end{corollary}\n\n\\begin{theorem}[Transitivity of Algebraic Extension]\n  IF $K$ is algebraic over $F$ and $L$ is algebraic over $K$ then $L$ is algebraic over $F$.\n\\end{theorem}\n\n\\begin{proof}\n  Let $\\alpha\\in L$, which is algebraic over $K$ so $\\alpha$ satisfies some polynomial\n  \\[\n    \\sum_{i=0}^{n} a_i \\alpha^i = 0\n  \\]\n\n  with $a_i\\in K$. So\n  \\[\n    [F(\\alpha,a_0,\\ldots,a_n):F] = [F(\\alpha,a_0,\\ldots,a_n):F(a_0,\\ldots,a_n)][F(a_o,\\ldots,a_n):F]\n  \\]\n  which is finite.\n\\end{proof}\n\n\\begin{definition}\n  Let $K_1$ and $K_2$ be two subfields of a field $K$. The \\emph{composite field} of $K_1$ and $K_2$, denoted $K_1K_2$ is the smallest subfield of $K$ containing both $K_1$ and $K_2$.\n\\end{definition}\n\n\\begin{proposition}\\label{prop:composite}\n  Let $K_1$ and $K_2$ be two finite extensions of a field $F$ contained in $K$. Then\n  \\[\n    [K_1K_2:F] \\leq [K_1:F][K_2:F]\n  \\]\n\\end{proposition}\n\n\\section{Classical Straightedge and Compass Constructions}\n\nLet $1$ denote a fixed given unit distance, then any distance is determined by its length $a\\in \\mathbb{R}$. The collection of lengths that can be obtained by compass and straightedge constructions from a unit distance is called the \\emph{constructible} elements of $\\mathbb{R}$.\n\n\\begin{proposition}\n  The collection of constructible elements is a \\emph{subfield} of $\\mathbb{R}$ strictly larger than $\\mathbb{Q}$.\n\\end{proposition}\n\nWe can construct $\\sqrt a$ for any $a > 0$. We can also show, by obtaining the coordinates of lines and circles by solving their equations, that any operation on elements of $F$ produces elements in at most a \\emph{quadratic} extension of $F$. Thus\n\n\\begin{proposition}\n  If the element $\\alpha\\in\\mathbb{R}$ is obtained from a field $F \\subset \\mathbb{R}$ by a series of operations then $[F(\\alpha):F]=2^k$ for some integer $k \\geq 0$.\n\\end{proposition}\n\n\\begin{proposition}\n  Trisecting an angle is impossible since $\\cos 20^{\\circ}$ is not contructible.\n\\end{proposition}\n\n\\begin{proof}\n  Let $\\beta=\\cos20^\\circ$. By triple angle formula we have\n  \\[\n    4\\beta^3 -3\\beta - 1/2 = 0\n  \\]\n  Let $\\alpha=2\\beta$, then $\\alpha$ satisfies the equation\n  \\[\n    \\alpha^3-3\\alpha-1=0\n  \\]\n  which can be shown to have no rational roots by Rational Root Theorem. Thus $[\\mathbb{Q}(\\alpha):\\mathbb{Q}]=3$.\n\\end{proof}\n\n\\begin{remark}\n  The angles $1^\\circ$ and $2^\\circ$ are not constructible as otherwise addition formula show that $20^\\circ$ would be constructible. The regular pentagon gives $72^\\circ$ and the equilateral triangle gives $60^\\circ$ so $3^\\circ$ is constructible.\n\\end{remark}\n\n\\section{Splitting Fields and Algebraic Closures}\n\n\\begin{definition}\n  The extension field $K$ over $F$ is called a \\emph{splitting field} for the polynomial $f(x)\\in F[x]$ if $f(x)$ factors completely into linear factors in $K[x]$ and $f(x)$ does not factor completely into linear factors over any proper subfield of $K$ containing $F$.\n\\end{definition}\n\n\\begin{theorem}\n  For any field $F$, if $f(x)\\in F[x]$ then there exists an extension $K$ of $F$ which is a splitting field for $f(x)$.\n\\end{theorem}\n\n\\begin{proposition}\n  A splitting field of polynomial of degree $n$ over $F$ is of degree at most $n!$ over $F$.\n\\end{proposition}\n\n\\begin{definition}\n  If $K$ is an algebraic extension of $F$ which is the splitting field over $F$ for a collection of polynomials $f(x)\\in F[x]$ then $K$ is called a \\emph{normal} extension of $F$.\n\\end{definition}\n\n\\begin{eg}[Splitting Field of $x^n-1$: Cyclotomic Fields]\n  Consider the splitting field of the polynomial $x^n-1$ over $\\mathbb{Q}$. The roots of the polynomial are called the $n$th \\emph{roots of unity}.\n\n  Since any finite group of the multiplicative group of a field is cyclic, we call a generator of the cyclic group of all $n$th roots of unity a \\emph{primitive} $n$th root of unity, denoted $\\zeta_n$. Given a primitive root $\\zeta_n$, the other primitive roots are then $\\zeta_n^i$ where $1 \\leq i < n$ is an integer relatively prime to $n$. Thus there are $\\varphi(n)$ primitive roots of unity. Over $\\mathbb{C}$ we can see this directly be letting $\\zeta_n:=e^{2\\pi i/n}$.\n\n  The field $\\mathbb{Q}(\\zeta_n)$ is called the \\emph{cyclotomic field of $n$th roots of unity}.\n\n  When $n=p$ is a prime, we have the factorisation\n  \\[\n    x^p-1 = (x-1)(x^{p-1}+\\cdots+x+1)\n  \\]\n  Since $\\zeta_p \\neq 1$ it is a root of the polynomial\n  \\[\n    \\Phi_p(x) = \\frac{x^p-1}{x-1} = (x-1)(x^{p-1}+\\cdots+x+1)\n  \\]\n  which is irreducible. Thus $\\Phi_p$ is the irreducible polynomial of $\\zeta_p$ over $\\mathbb{Q}$ so\n  \\[[\\mathbb{Q}(\\zeta_p):\\mathbb{Q}] = p-1\\]\n\n  See more discussion of in Section \\ref{sec:cyclotomic}.\n\\end{eg}\n\n\\begin{eg}[Splitting Field of $x^p-2$, $p$ is a prime]\n  If $\\alpha$ is a root of the equation $x^p-2$ then $\\zeta\\alpha$ is alos a root where $\\zeta$ is a $p$th root of unity. Denote the positive real $p$th root of $2$ $\\sqrt[p]2$. We can show that the splitting field is exactly $\\mathbb{Q}(\\sqrt[p]2, \\zeta_p)$. The extension field has $\\mathbb{Q}(\\sqrt[p]2)$ and $\\mathbb{Q}(\\zeta_p)$ as subfields so by Proposition \\ref{prop:composite}\n  \\[ [\\mathbb{Q}(\\sqrt[p]2,\\zeta_p):\\mathbb{Q}] = p(p-1) \\]\n\\end{eg}\n\n\\begin{theorem}\n  Let $\\phi: F\\xrightarrow{\\sim} F'$ be an isomorphism of fields. Let $f(x)\\in F[x]$ be a polynomial and $f'(x):=\\phi(f(x))\\in F'[x]$. Let $E$ be a splitting field for $f(x)$ over $F$ and let $E'$ be a splitting field for $f'(x)$ over $F'$. Then the isomorpism $\\phi$ extends to an isomorphism $\\sigma:E\\xrightarrow{\\sim} E'$:\n  \\[\n    \\begin{tikzcd}\n      F \\arrow{r}{\\sim}[swap]{\\phi} \\arrow[hook]{d} & F' \\arrow[hook]{d}\\\\\n      E \\arrow{r}{\\sim}[swap]{\\sigma} & E'\n    \\end{tikzcd}\n  \\]\n\\end{theorem}\n\n\\begin{proof}\n  Induction on the degree $n$ of $f(x)$. The base case where $f(x)$ splits completely in $F[x]$ is easy. Suppose now that $p(x)$ is an irreducible factor of $f(x)$ of degree at least $2$. Let $\\alpha\\in E$ be a root of $p(x)$ and $\\beta\\in E'$ be a root of $p'(x)$. Then by Theorem \\ref{thm:uniqueness of simple extension} we have\n  \\[\n    \\begin{tikzcd}\n      F \\arrow{r}{\\sim}[swap]{\\phi} \\arrow[hook]{d} & F' \\arrow[hook]{d}\\\\\n      F(\\alpha) \\arrow{r}{\\sim}[swap]{\\sigma'} & F(\\beta)\n    \\end{tikzcd}\n  \\]\n\n  Now we have $f(x) = (x-\\alpha)f_1(x)$ over $F(\\alpha)[x]$ where $f_1(x)$ ahs degree $n-1$. Note that the field $E$ is a splitting field for $f_1(x)$ over $F(\\alpha)[x]$: all the roots of $f_1(x)$ are in $E$ and if they were contained in any smaller extension $L$ containing $F(\\alpha)[x]$, then since $F(\\alpha)$ contains $\\alpha$, $L$ would also contain all roots of $f(x)$, which would contradict the minimality of $E$ as the splitting field of $f(x)$ over $F$. Similar for $E'$. Since $f_1(x)$ has degree less than $n$, by induction there exist $\\sigma: E\\xrightarrow{\\sim} E'$ such that\n  \\[\n    \\begin{tikzcd}\n      F \\arrow{r}{\\sim}[swap]{\\phi} \\arrow[hook]{d} & F' \\arrow[hook]{d}\\\\\n      F(\\alpha) \\arrow{r}{\\sim}[swap]{\\sigma'} \\arrow[hook]{d} & F(\\beta) \\arrow[hook]{d}\\\\\n      E \\arrow{r}{\\sim}[swap]{\\sigma} & E'\n    \\end{tikzcd}\n  \\]\n\\end{proof}\n\n\\begin{corollary}[Uniqueness of Splitting Fields]\n  Any two splitting fields for a polynomial $f(x)\\in F[x]$ over a field $F$ are isomorphic.\n\\end{corollary}\n\n\\begin{definition}\n  The field $\\cl F$ is called an \\emph{algebraic closure} of $F$ if $\\cl F$ is algebraic over $F$ and if every polynomial $f(x)\\in F[x]$ splits completely over $\\cl F$.\n\\end{definition}\n\n\\begin{definition}\n  A field $K$ is said to be \\emph{algebraically closed} if every polynomial with coefficients in $K$ has a root in $K$.\n\\end{definition}\n\n$K=\\cl K$ iff $K$ is algebraically closed.\n\n\\begin{proposition}\n  Let $\\cl F$ be an algebraic closure of $F$. Then $\\cl F$ is algebraically closed.\n\\end{proposition}\n\n\\begin{proof}\n  Let $f(x)\\in\\cl F[x]$ and $\\alpha$ be a root of $f(x)$. Then\n  \\[ F \\subseteq \\cl F[x] \\subseteq \\cl F[x] \\]\n  is an algebraic extension by transitivity so $\\alpha\\in\\cl F$.\n\\end{proof}\n\n\\begin{proposition}\n  For any field $F$ there exists an algebraically closed field $K$ containing $F$.\n\\end{proposition}\n\n\\begin{proof}\n  For every nonconstant monic polynomial $f$ with coefficients in $F$, let $x_f$ denote an indeterminate and consider the polynomial ring $F[\\ldots,x_f,\\ldots]$. Consider the ideal $I$ generated by the polynomials $f(x_f)$. Suppose this ideal is not proper, then there is a relation\n  \\[ \\sum_{i=1}^n g_i f_i(x_{f_i}) = 1 \\]\n  where $g_i$ are elements of $F[\\ldots,x_f,\\ldots]$. For $i=1,2,\\ldots,n$ let $x_{f_i}=x_i$ and let $x_{n+1},\\ldots,x_m$ be the remaining variables occurring in the polynomials $g_j$. Then the relation becomes\n  \\[ \\sum_{i=1}^n g_i(x_1,\\ldots,x_m) f_i(x_i) = 1 \\]\n\n  Let $F'$ be a finite extension of $F$ containing a root $\\alpha_i$ of $f_i$. Letting $x_i = \\alpha_i$ and setting $x_{n+1}=\\cdots=x_m=0$. Then the relation above reads $0=1$. Absurd.\n\n  Since $I$ is a proper ideal, by Zorn's Lemma it is contained in a maximal ideal $M$. Then\n  \\[ F \\subseteq K_1:= F[\\ldots,x_f,\\ldots]/M \\]\n  and each polynomial $f$ has a root in $K_1$ by construction. Iterate the process and we obtain a chain of fields\n  \\[ F= K_0 \\subseteq K_1 \\subseteq \\cdots \\]\n  Let\n  \\[ K = \\bigcup_{i\\geq0} K_i \\]\n  which is a field containing $F$ and $K$ is algebraically closed.\n\\end{proof}\n\n\\begin{proposition}\n  Let $K$ be an algebraically closed field and let $F$ be a subfield of $K$. Then the collection of elements $\\cl F$ of $K$ that are algebraic over $F$ is an algebraic closure of $F$. An algebraic closure of $F$ is unique up to isomorphism.\n\\end{proposition}\n\n\\begin{theorem}[Fundamental Theorem of Algebra]\n  $\\mathbb{C}$ is algebraically closed.\n\\end{theorem}\n\n\\begin{corollary}\n  $\\mathbb{C}$ contains an algebraic closure for any of its subfields. In particular, $\\cl{\\mathbb{Q}}$, the collection of complex numbers algebraic over $\\mathbb{Q}$, is an algebraic closure of $\\mathbb{Q}$.\n\\end{corollary}\n\n\\section{Separable Extensions}\n\n\\begin{definition}\n  A polynomial over $F$ is called \\emph{separable} if it has no multiple roots. A polynomial which is not separable is called \\emph{inseparable}.\n\\end{definition}\n\n\\begin{definition}\n  The \\emph{derivative} of the polynomial\n  \\[ f(x)=a_n x^n+a_{n-1}+x^{n-1}+\\cdots + a_1 x + a_0 \\in F[x] \\]\n  is defined to be the polynomial\n  \\[ D_x f(x) := n a_n x^{n-1} + (n-1) a_{n-1} x^{n-2}+\\cdots + 2a_2 x + a_1 \\in F[x] \\]\n\\end{definition}\n\n\\begin{proposition}\n  A polynomial $f(x)$ has a multiple root $\\alpha$ iff $\\alpha$ is also a root of $D_xf(x)$, i.e. both $f(x)$ and $D_xf(x)$ are divisible by the minimal polynomial for $\\alpha$. In particular $f(x)$ is separable iff it is relatively prime to its derivative.\n\\end{proposition}\n\n\\begin{eg}\n  The polynomial $x^{p^n}-x$ over $\\mathbb{F}_p$ has derivative $-1$ so it is separable.\n\\end{eg}\n\n\\begin{eg}\n  The polynomial $x^n-1$ has derivative $nx^{n-1}$. Over any field of characteristic not dividing $n$ this polynomial has the only root $0$, which is not a root of $x^n-1$. Thus $x^n-1$ is separable and there are $n$ distinct $n$th root of unity.\n\\end{eg}\n\n\\begin{corollary}\n  Every irreducible polynomial over a field of characteristic $0$ is separable. A polynomial over such a field is separable iff it is the product of distinct irreducible polynomials.\n\\end{corollary}\n\n\\begin{proof}\n  Suppose $F$ is a field of characteristic $0$ and $p(x)\\in F[x]$ is irreducible of degree $n$. Then $D_xf(x)$ has degree $n-1$ which is coprime to $p(x)$.\n\\end{proof}\n\n\\begin{remark}\n  In characteristic $p$ the derivative of any power of $x^p$ is identically $0$:\n  \\[ D_x(x^{pm}) = pmx^{pm-1} = 0 \\]\n  so it is possible for the degree of the derivative to decrease by more than one. Thus the proof in the corollary may fail.\n\\end{remark}\n\n\\begin{proposition}\\label{prop:frobenius}\n  Let $F$ be a field of characteristic $p$. Then for any $a,b\\in F$,\n  \\begin{align*}\n    (a+b)^p &= a^p+b^p\\\\\n    (ab)^p &= a^p b^p\n  \\end{align*}\n  so the map $a \\mapsto a^p$ is an injective field endomorphism of $F$.\n\\end{proposition}\n\n\\begin{definition}\n  The map in Proposition \\ref{prop:frobenius} is called the \\emph{Frobenius endomorphism} of $F$.\n\\end{definition}\n\n\\begin{corollary}\\label{cor:perfect field}\n  Suppose $\\mathbb{F}$ is a finite field of characteristic $p$. Then every element is a $p$th power in $\\mathbb F$, i.e. $\\mathbb F = \\mathbb F^p$.\n\\end{corollary}\n\n\\begin{proposition}\n  Every irreducible polynomial over a finite field $\\mathbb F$ is separable. A polynomial in $\\mathbb F$ is separable iff it is the product of distinct irreducible polynomials in $\\mathbb F[x]$.\n\\end{proposition}\n\n\\begin{proof}\n  Let $\\mathbb F$ be a finite field and suppose that $p(x)\\in\\mathbb F$ is an irreducible. If $p(x)$ were inseparable then $p(x)=q(x^p)$ for some polynomial $q(x)\\in \\mathbb F$. Let\n  \\[ q(x) = \\sum_{i=0}^m a_i x^i \\]\n  By Corollary \\ref{cor:perfect field}, there exist $b_i\\in \\mathbb F$ such that $a_i= b_i^p$. Then by Proposition \\ref{prop:frobenius}\n  \\begin{align*}\n    p(x)= q(x^p) &= \\sum_{i=0}^m a_i (x^p)^i\\\\\n                 &= \\sum_{i=0}^m b_i^p (x^p)^i\\\\\n                 &= \\sum_{i=0}^m (b_i x^i)^p\\\\\n                 &= (\\sum_{i=0}^m b_i x^i)^p\n  \\end{align*}\n  which show that $p$ is the $p$th power of a polynomial, a contradiction to the irreducibility of $f$.\n\\end{proof}\n\n\\begin{definition}\n  A field $K$ of characteristic $p$ is called \\emph{perfect} if every element of $K$ is a $p$th power in $K$, i.e. $K = K^p$. Any field of characteristic $0$ is also called perfect.\n\\end{definition}\n\n\\begin{eg}[Existence and Uniqueness of Finite Fields]\n  Let $n$ be a positive integer and consider the splitting field of $x^{p^n}-x$ over $\\mathbb F_p$. We have shown that it is separable, thus having $p^n$ roots. For any two roots we can show their sum, product and quotient are also a root by Proposition \\ref{prop:frobenius}. Let $\\mathbb F$ be the \\emph{field} of all such roots, which must be the splitting field. Thus we have $[\\mathbb F:\\mathbb F_p] = n$.\n\n  For the uniqueness, suppose $\\mathbb F$ is any finite field of characteristic $p$. Suppose $[\\mathbb F:\\mathbb F_p] = n$. Since the multiplicative group $\\mathbb F^\\times$ has order $p^n - 1$, we have $\\alpha^{p^n}-\\alpha=0$ for every $\\alpha\\in\\mathbb F$, so by counting argument $\\mathbb F$ is a splitting field of $x^{p^n}-x$. Since splitting fields are unique up to isomorphism, we have proven that \\emph{finite fields of any order $p^n$ exist and are unique up to isomorphism.} We denote the field $\\mathbb F_{p^n}$.\n\\end{eg}\n\n\\begin{proposition}\\label{prop:sep}\n  Let $p(x)$ be an irreducible polynomial over a field $F$ of characteristic $p$. Then there is a unique integer $k \\geq 0$ and a unique irreducible separable polynomial $p_{sep}(x)\\in F[x]$ such that\n  \\[ p(x) = p_{sep}(x^{p^k}) \\].\n\\end{proposition}\n\n\\begin{definition}\n  Use the notation in Proposition \\ref{prop:sep}, the degree of $p_{sep}(x)$ is called the \\emph{separable degree} of $p(x)$, denoted $\\deg_s p(x)$ while $p^k$ is called the \\emph{inseparable degree} of $p(x)$, denoted $\\deg_i p(x)$.\n\\end{definition}\n\nFrom the relation $p(x) = p_{sep}(x^{p^k})$ we have\n\\[ \\deg p(x) = \\deg_s p(x) \\deg_i p(x). \\]\n\n\\begin{definition}\n  The field $K$ is said to be \\emph{separable} (or \\emph{separably algebraic}) over $F$ if every element of $K$ is the root of a separable polynomial over $F$. A field which is not separable is \\emph{inseparable}.\n\\end{definition}\n\n\\begin{corollary}\n  Every finite extension of a perfect field is separable.\n\\end{corollary}\n\n\\section{Cyclotomic Polynomials and Extensions} \\label{sec:cyclotomic}\n\n\\begin{definition}\n  Let $\\mu_n$ denote the \\emph{group of $n$th roots of unity over $\\mathbb Q$}.\n\\end{definition}\n\nIf $d$ is a divisor of $n$ and $\\zeta$ is a $d$th root of unity then $\\zeta$ is also a n $n$th root of unity so\n\\[ \\mu_d \\subseteq \\mu_n \\quad \\text{for all } d|n. \\]\n\nConversely, any element of $\\mu_n$ which is also a $d$th root of unity has order $d$ which divides $|\\mu_n|=n$.\n\n\\begin{definition}\n  The \\emph{$n$th cyclotomic polynomial $\\Phi_n(x)$} is the polynomial whose roots are the primitive $n$th roots of unity:\n  \\[ \\Phi_n(x) := \\prod_{\\text{primitive }\\zeta\\in \\mu_n} (x - \\zeta) = \\prod_{\\substack{1\\leq a <n\\\\ (a,n)=1}} (x-\\zeta_n^a) \\]\n\\end{definition}\n\nSince the roots of $x^n-1$ are precisely the $n$th roots of unity, we have the factorisaton\n\\begin{align*}\n  x^n-1 &= \\prod_{\\zeta \\in \\mu_n} (x-\\zeta)\\\\\n        &= \\prod_{d|n} \\prod_{\\substack{\\zeta \\in \\mu_d\\\\\\zeta\\: \\text{primitive}}} (x - \\zeta) \\quad \\text{group together $\\zeta$ by order $d$}\\\\\n        &= \\prod_{d|n} \\Phi_d(x) \\quad \\text{definition of $\\Phi_n(x)$}\n\\end{align*}\n\nwhich allows us to compute $\\Phi_n(x)$ recursively. Note comparing the degree gives the identity\n\\[ n = \\sum_{d|n} \\varphi(d). \\]\n\n\\begin{lemma}\n  The cyclotomic polynomial $\\Phi_n(x)$ is a monic polynomial in $\\mathbb Z[x]$ of degree $\\varphi(n)$.\n\\end{lemma}\n\n\\begin{proof}\n  It is clear that $\\Phi_n(x)$ is monic and has degree $\\varphi(n)$. To show the coefficients lie in $\\mathbb Z$ we use induction on $n$. The base case is easy. Asumme it is true for all $1 \\leq d < n$. Then $x^n-1 = f(x) \\Phi_n(x)$ where $f(x) = \\prod_{d|n,d\\neq n} \\Phi_d(x)$ is monic and has coefficients in $\\mathbb Z$. Since $f(x)$ divides $x^n - 1$ in $F[x]$ where $F=\\mathbb Q(\\zeta_n)$ and both $f(x)$ and $x^n - 1$ have coefficients in $\\mathbb Q$, $f(x)$ divides $x^n - 1$ in $\\mathbb Q[x]$ by division algorithm (divisibility is independent of the ring). By Gauss' Lemma, $f(x)$ divides $x^n -1 $ in $\\mathbb Z[x]$.\n\\end{proof}\n\n\\begin{theorem}\n  The cyclotomic polynomial $\\Phi_n(x)$ is an irreducible monic polynomial in $\\mathbb Z[x]$ of degree $\\varphi(n)$.\n\\end{theorem}\n\n\\begin{proof}\n  To show that $\\Phi_n(x)$ is irreducible, suppose we have a factorisation in $\\mathbb Z[x]$\n  \\[ \\Phi_n(x) = f(x)g(x), \\]\n  where we take $f(x)$ to be an irreducible factor of $\\Phi_n(x)$. Let $\\zeta$ be a primitive $n$th root of unity for which $f(x)$ is the minimal polynomial. Let $p$ be any prime not dividing $n$. Then $\\zeta^p$ is also a primitive $n$th root of unity. Suppose it is a root of $g(x)$. Then $\\zeta$ is a root of $g(x^p)$ and so\n  \\[ g(x^p) = f(x)h(x), \\: h(x) \\in \\mathbb Z[x] \\]\n\n  Reduce modulo $p$, we obtain\n  \\[ (\\bar g(x))^p = \\bar g(x^p) = \\bar f(x) \\bar g(x) \\quad \\text{in } \\mathbb F_p[x]. \\]\n  Since $\\mathbb F_p[x]$ is a U.F.D., it folows that $\\bar f(x)$ and $\\bar g(x)$ have a factor in common.\n\n  Now reduce $\\Phi_n(x)$ modulo $p$, it follows that $\\bar \\Phi_n(x) \\in \\mathbb F_p[x]$ has a multiple root. But then $x^n-1$ is a multiple of $\\bar \\Phi_n(x)$ so would have a multiple root over $\\mathbb F_p$, which is a contradiction since $p \\nmid n$.\n\n  So it must be the case that $\\zeta^p$ is a root of $f(x)$, for every root $\\zeta$ of $f(x)$. Write every integer $a$ coprime to $n$ as a product of primes $a = p_1p_2\\cdots p_k$, then $\\zeta^{p_1}$ is a root of $f(x)$, $\\zeta^{p_1p_2} = (\\zeta^{p_1})^{p_2}$ is a root of $f(x)$, etc. Then every primitive $n$th root of unity is a root of $f(x)$. So $f(x) = \\Phi_n(x)$.\n\\end{proof}\n\n\\begin{corollary}\n  \\[ [\\mathbb Q(\\zeta_n): \\mathbb Q] = \\varphi(n) \\]\n\\end{corollary}\n\n\\begin{proof}\n  $\\Phi_n(x)$ is the minimal polynomial for any primitive $n$th root of unity $\\zeta_n$.\n\\end{proof}\n\\end{document}", "meta": {"hexsha": "db42a2ebd9cecd1ebdcb055e79a1c0d7d7210d8e", "size": 25404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blurb/df-field_theory.tex", "max_stars_repo_name": "geniusKuang/tripos", "max_stars_repo_head_hexsha": "127e9fccea5732677ef237213d73a98fdb8d0ca0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2018-01-15T05:02:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T15:48:31.000Z", "max_issues_repo_path": "blurb/df-field_theory.tex", "max_issues_repo_name": "b-mehta/tripos", "max_issues_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-11T20:43:21.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T21:29:15.000Z", "max_forks_repo_path": "blurb/df-field_theory.tex", "max_forks_repo_name": "b-mehta/tripos", "max_forks_repo_head_hexsha": "8d3037ede28fed3a3cdb82a88dd3a005bf94b310", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2017-11-08T16:16:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T17:20:19.000Z", "avg_line_length": 47.7518796992, "max_line_length": 626, "alphanum_fraction": 0.6675720359, "num_tokens": 8718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059414036511, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6099621054369231}}
{"text": "\\chapter{B\\'{e}zier Intersection Problems}\\label{chap:bezier-intersection}\n\n\\section{Intersecting B\\'{e}zier Curves}\n\nThe problem of intersecting two B\\'{e}zier curves is a core building\nblock for intersecting two B\\'{e}zier triangles in \\(\\reals^2\\)\nSince a curve is an algebraic variety of dimension one,\nthe intersections will either be a curve segment common to both curves (if\nthey coincide) or a finite set of points (i.e. dimension zero).\nMany algorithms have been described in the literature, both\ngeometric (\\cite{Sederberg1986, Sederberg1990, Kim1998}) and\nalgebraic (\\cite{Manocha:CSD-92-698}).\n\nIn the implementation for this work, the B\\'{e}zier subdivision\nalgorithm is used.\nIn the case of a transversal intersection (i.e. one where the\ntangents to each curve are not parallel and both are non-zero),\nthis algorithm performs very well. However, when curves are tangent,\na large number of (false) candidate intersections are detected and\nconvergence of Newton's method slows once in a neighborhood of an\nactual intersection. Non-transversal intersections\nhave infinite condition number, but transversal intersections with\nvery high condition number can also cause convergence problems.\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/bbox_check.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Bounding box intersection predicate. This is a cheap way to\n    conclude that two curves don't intersect, though it inherently is\n    susceptible to false positives.}\n  \\label{fig:bounding-box-check}\n\\end{figure}\n\nIn the B\\'{e}zier subdivision algorithm, we first check if the\nbounding boxes for the curves are disjoint\n(Figure~\\ref{fig:bounding-box-check}).\nWe use the bounding boxes\nrather than the convex hulls since they are easier to compute and\nthe intersections of boxes are easier to check.\nIf they are disjoint, the pair can be rejected. If not, each curve\n\\(\\mathcal{C} = b\\left(\\left[0, 1\\right]\\right)\\) is split into two halves\nby splitting the unit interval: \\(b\\left(\\left[0, \\frac{1}{2}\\right]\\right)\\)\nand \\(b\\left(\\left[\\frac{1}{2}, 1\\right]\\right)\\)\n(Figure~\\ref{fig:bezier-curve-subdivision}).\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/subdivide_curve.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{B\\'{e}zier curve subdivision.}\n  \\label{fig:bezier-curve-subdivision}\n\\end{figure}\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/subdivision_process.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{B\\'{e}zier subdivision algorithm.}\n  \\label{fig:bezier-subdivision-process}\n\\end{figure}\n\nAs the subdivision continues,\nsome pairs of curve segments may be kept around that won't lead to an\nintersection (Figure~\\ref{fig:bezier-subdivision-process}).\nOnce the curve segments are close to linear within a given tolerance\n(Figure~\\ref{fig:bezier-subdivision-linearized}), the process\nterminates.\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/subdivision_linearized.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Subdividing until linear within tolerance.}\n  \\label{fig:bezier-subdivision-linearized}\n\\end{figure}\n\nOnce both curve segments are linear (to tolerance), the intersection is\napproximated by intersecting the lines connecting the endpoints of each\ncurve segment. This approximation is used as a starting point for Newton's\nmethod, to find a root of \\(F(s, t) = b_0(s) - b_1(t)\\). Since\n\\(b_0(s), b_1(t) \\in \\reals^2\\) we have Jacobian \\(J =\n\\left[ \\begin{array}{c c} b_0'(s) & -b_1'(t) \\end{array}\\right]\\).\nWith these, Newton's method is\n\\begin{equation}\n\\left[ \\begin{array}{c c} s_{n + 1} & t_{n + 1} \\end{array}\\right]^T =\n\\left[ \\begin{array}{c c} s_n & t_n \\end{array}\\right]^T -\nJ_n^{-1} F_n.\n\\end{equation}\nThis also gives an indication why convergence issues occur at non-transveral\nintersections: they are exactly the intersections where the Jacobian is\nsingular.\n\n\\section{Intersecting B\\'{e}zier Triangles}\\label{sec:intersect-bez-tri}\n\nThe chief difficulty in intersecting two surfaces is intersecting their edges,\nwhich are B\\'{e}zier curves.\nThough this is just a part of the overall algorithm, it proved to be the\n\\emph{most difficult} to implement (\\cite{Hermes2017}). So the first part\nof the algorithm is to find all points\nwhere the edges intersect (Figure~\\ref{fig:edge-intersections}).\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/main_figure21.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Edge intersections during B\\'{e}zier triangle intersection.}\n  \\label{fig:edge-intersections}\n\\end{figure}\n\nTo determine the curve segments that bound the curved polygon region(s)\n(see Section~\\ref{subsec:curved-polygons} for more about curved polygons) of\nintersection, we not only need to keep track\nof the coordinates of intersection, we also need to keep note of\n\\emph{which} edges the intersection occurred on and the parameters along\neach curve.\nWith this information, we can classify each point of intersection\naccording to which of the two curves forms the boundary of the\ncurved polygon (Figure~\\ref{fig:intersection-classification}).\nUsing the right-hand rule we can compare the tangent\nvectors on each curve to determine which one is on the interior.\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/main_figure22.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Classified intersections during B\\'{e}zier triangle intersection.}\n  \\label{fig:intersection-classification}\n\\end{figure}\n\nThis classification becomes more difficult when the curves\nare tangent at an intersection, when the intersection occurs at a corner\nof one of the surfaces or when two intersecting edges are coincident\non the same algebraic curve (Figure~\\ref{fig:intersection-difficulties}).\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/main_figure23.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{B\\'{e}zier triangle intersection difficulties.}\n  \\label{fig:intersection-difficulties}\n\\end{figure}\n\nIn the case of tangency, the intersection is non-transversal, hence has\ninfinite condition number. In the case of coincident curves, there are\ninfinitely many intersections (along the segment when the curves\ncoincide) so the subdivision process breaks down.\n\n\\subsection{Example}\n\nConsider two B\\'{e}zier surfaces\n(Figure~\\ref{fig:surface-surface-example})\n\n\\begin{equation}\nb_0(s, t) =\n\\left[ \\begin{array}{c}\n    8 s \\\\ 8 t \\end{array}\\right] \\qquad\nb_1(s, t) =\n\\left[ \\begin{array}{c}\n    2 (6 s + t - 1) \\\\\n    2 (8 s^2 + 8 s t - 8 s + 3 t + 2) \\end{array}\\right]\n\\end{equation}\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/main_figure24.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Surface Intersection Example}\n  \\label{fig:surface-surface-example}\n\\end{figure}\n\nIn the \\emph{first step} we find all intersections of the\nedge curves\n\\begin{multline}\nE_0(r) = \\left[ \\begin{array}{c} 8 r \\\\ 0 \\end{array}\\right],\nE_1(r) = \\left[ \\begin{array}{c} 8 (1 - r) \\\\ 8 r \\end{array}\\right],\nE_2(r) = \\left[ \\begin{array}{c} 0 \\\\ 8 (1 - r) \\end{array}\\right], \\\\\nE_3(r) = \\left[ \\begin{array}{c} 2 (6 r - 1) \\\\ 4 (2 r - 1)^2\n  \\end{array}\\right],\nE_4(r) = \\left[ \\begin{array}{c} 10 (1 - r) \\\\ 2 (3 r + 2) \\end{array}\\right],\nE_5(r) = \\left[ \\begin{array}{c} - 2 r \\\\ 2 (5 - 3 r) \\end{array}\\right].\n\\end{multline}\nWe find three intersections\nand we classify each of them by comparing the tangent vectors\n\\begin{gather}\n  I_1:\n  E_2\\left(\\frac{7}{9}\\right) =\nE_3\\left(\\frac{1}{6}\\right) = \\frac{16}{9}\n\\left[ \\begin{array}{c} 0 \\\\ 1 \\end{array}\\right] \\Longrightarrow\nE_2'\\left(\\frac{7}{9}\\right) \\times\nE_3'\\left(\\frac{1}{6}\\right) = 96 \\\\\nI_2:\nE_0\\left(\\frac{1}{2}\\right) =\nE_3\\left(\\frac{1}{2}\\right) =\n\\left[ \\begin{array}{c} 4 \\\\ 0 \\end{array}\\right] \\Longrightarrow\nE_0'\\left(\\frac{1}{2}\\right) \\times\nE_3'\\left(\\frac{1}{2}\\right) = 0 \\\\\n  I_3:\nE_1\\left(\\frac{1}{8}\\right) =\nE_3\\left(\\frac{3}{4}\\right) =\n\\left[ \\begin{array}{c} 7 \\\\ 1 \\end{array}\\right] \\Longrightarrow\nE_1'\\left(\\frac{1}{8}\\right) \\times\nE_3'\\left(\\frac{3}{4}\\right) = -160.\n\\end{gather}\nFrom here, we construct our curved polygon intersection by drawing\nfrom our list of intersections until none remain.\n\n\\begin{itemize}\n\\itemsep 0em\n\\item First consider \\(I_1\\). Since\n  \\(E_2' \\times\n  E_3' > 0\\)\n  at this point, then we consider the curve\n  \\(E_3\\) to be\n  \\emph{interior}.\n\\item After classification, we move along\n  \\(E_3\\) until we\n  encounter another intersection: \\(I_2\\)\n\\item \\(I_2\\) is a point of tangency since\n  \\(E_0'\\left(\\frac{1}{2}\\right) \\times\n  E_3'\\left(\\frac{1}{2}\\right) = 0\\).\n  Since a tangency has no impact on\n  the underlying intersection geometry, we ignore it and\n  keep moving.\n\\item Continuing to move along\n  \\(E_3\\), we\n  encounter another intersection: \\(I_3\\).\n  Since\n  \\(E_1' \\times\n  E_3' < 0\\)\n  at this point, we consider the curve\n  \\(E_1\\) to be\n  \\emph{interior} at the intersection. Thus we stop moving\n  along \\(E_3\\)\n  and we have our first curved segment:\n  \\(E_3\\left(\\left[\n    \\frac{1}{6}, \\frac{3}{4}\\right]\\right)\\)\n\\item Finding no other intersections on \\(E_1\\)\n  we continue until the end of the edge.\n  Now our (ordered) curved segments are:\n  \\begin{equation}\n  E_3\\left(\\left[\n    \\frac{1}{6}, \\frac{3}{4}\\right]\\right) \\longrightarrow\n  E_1\\left(\\left[\n    \\frac{1}{8}, 1\\right]\\right).\n  \\end{equation}\n\\item Next we stay at the corner and switch to the next curve\n  \\(E_2\\), moving along that curve\n  until we hit the next intersecton \\(I_1\\).\n  Now our (ordered) curved segments are:\n  \\begin{equation}\n  E_3\\left(\\left[\n    \\frac{1}{6}, \\frac{3}{4}\\right]\\right) \\longrightarrow\n  E_1\\left(\\left[\n    \\frac{1}{8}, 1\\right]\\right) \\longrightarrow\n  E_2\\left(\\left[\n    0, \\frac{7}{9}\\right]\\right).\n  \\end{equation}\n  Since we are now back where we started (at \\(I_1\\))\n  the process stops\n\\end{itemize}\nWe represent the boundary of the curved polygon as B\\'{e}zier curves, so\nto complete the process we reparameterize (\\cite[Ch.~5.4]{Farin2001}) each\ncurve onto the relevant interval. For example,\n\\(E_3\\) has control points\n\\(p_0 = \\left[ \\begin{array}{c} -2 \\\\ 4 \\end{array}\\right]\\),\n\\(p_1 = \\left[ \\begin{array}{c} 4 \\\\ -4 \\end{array}\\right]\\),\n\\(p_2 = \\left[ \\begin{array}{c} 10 \\\\ 4 \\end{array}\\right]\\)\nand we reparameterize on \\(\\alpha = \\frac{1}{6}, \\beta = \\frac{3}{4}\\) to\ncontrol points\n\\begin{align}\n  q_0 &= E_3\\left(\\frac{1}{6}\\right) =\n  \\frac{16}{9} \\left[ \\begin{array}{c} 0 \\\\ 1 \\end{array}\\right] \\\\\n  q_1 &= (1 - \\alpha) \\left[(1 - \\beta) p_0 + \\beta p_1\\right] +\n   \\alpha \\left[(1 - \\beta) p_1 + \\beta p_2\\right] = \\frac{1}{6} \\left[\n    \\begin{array}{c} 21 \\\\ -8 \\end{array}\\right] \\\\\n  q_2 &= E_3\\left(\\frac{3}{4}\\right) = \\left[\n    \\begin{array}{c} 7 \\\\ 1 \\end{array}\\right].\n\\end{align}\n\n\\section{B\\'{e}zier Triangle Inverse}\n\nThe problem of determining the parameters \\((s, t)\\) given a point\n\\(\\bm{p} = \\left[\\begin{array}{c c} x & y\\end{array}\\right]^T\\)\nin a B\\'{e}zier triangle can also be solved by using\nsubdivision with a bounding box predicate and then Newton's method\nat the end.\n\n\\begin{figure}\n  \\includegraphics{../images/bezier-intersection/locate_in_triangle.pdf}\n  \\centering\n  \\captionsetup{width=.75\\linewidth}\n  \\caption{Checking for a point \\(\\bm{p}\\) in each of four subregions\n    when subdividing a B\\'{e}zier triangle.}\n  \\label{fig:locate-in-triangle}\n\\end{figure}\n\nFor example, Figure~\\ref{fig:locate-in-triangle} shows\nhow regions of \\(\\utri\\) can be discarded recursively until the\nsuitable region for \\((s, t)\\) has a sufficiently small area. At\nthis point, we can apply Newton's method to the map \\(F(s, t) =\nb(s, t) - \\bm{p}\\). It's very helpful (for Newton's method) that\n\\(F: \\reals^2 \\longrightarrow \\reals^2\\) since the Jacobian will\nalways be invertible\nwhen the B\\'{e}zier triangle is valid. If \\(\\bm{p} \\in \\reals^3\\)\nthen the system would be underdetermined. Similarly, if\n\\(\\bm{p} \\in \\reals^2\\) but \\(b(s)\\) is a B\\'{e}zier curve then the\nsystem would be overdetermined.\n", "meta": {"hexsha": "9346438068e5b78e28307204e079ca535e036c37", "size": 12104, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/bezier-intersection.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/bezier-intersection.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/bezier-intersection.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": 39.2987012987, "max_line_length": 78, "alphanum_fraction": 0.7174487773, "num_tokens": 3801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6099621045634304}}
{"text": "%!TEX root =  ../main.tex\n\n\n\\objective{Connect names of types of equations with graphs.}\n\n\nWe have said that a function is a relation of inputs to outputs, with no more than one output per input.  \nWe have learned that functions can be defined graphically, algebraically, numerical, or verbally.\nA function that is defined by an algebra equation usually has a descriptive name.\nIn this section, we will look at several groupings of various functions, some of which you should\nbe very familiar with, and some of which may be new.\n\n\nYou might be used to seeing a  \\gls{graph} of certain equations, written algebraically with $y$ in terms\nof $x$, like $y=x$.  These have then been graphed on the Cartesian plane, as a continuous curve,\nwith each point corresponding to an ordered pair, $(x,y)$.  Leonhard Euler created much of the notation\nwe use today, including \\emph{function notation}: $y=f(x)$.\n\n\\marginfig[-0in]{\\chapdir/pics/Linear_Function_Graph.png}{Linear functions.\\label{fig:LinearFunction}}\n\\subsubsection{Linear}\nOne of the most obvious things to see is a straight line.  \nHumans create straight lines seemingly more often\nthan anything else.  Hence, lines can feel unnatural or reassuring.  \nWhat are some of the properties of lines?\nHow might two lines be the same?  How might they differ?  \n\n\\marginfig[-0in]{\\chapdir/pics/AndraGrad-4}{A quadratic function is a polynomial of degree two.}\nLines could have the same slope, and therefore never run into each other.  \nThey would only be distinguished by their\nheights.  For convenience, we measure the height of a \\gls{linear} function \nin Analytic Geometry by its starting value, its $y$ when $x$ \nequals zero.  Conversely, these starting locations might be the same and \nslope might be different.  You have learned \\index{linear!intercept form}\nto distinguish these two different variables as $m$ and $b$, as in $y=mx+b$, and we shall see\nthat it is expedient to distinguish them \\textbf{constant} functions, $y=k$.\n\\index{constant!function}\n\n\\subsubsection{Quadratic}\nMany things in our world operate over two dimensions, such as gravity.  \nHence, Newton found that the force\nof two objects upon each other is proportional to the \\emph{square} of their distance.  \nSquares graphed make a\n\\textbf{parabola}, a word that in Greek references the path of a falling or thrown object.  \nAlgebraically, we can see all such shapes\\index{quadratic!standard form}\nhave an equation of the form $y=ax^2+bx+c$, which is called \\gls{quadratic}.  \nYou should already know a great deal about quadratics from previous classes.\n\n\\paragraph{Power}\nAs more dimension interact, the exponent on $x$ can become very \ncomplicated, and even fractional.  We can generalize\\index{power function!standard form}\nfrom $y=x$ to $y=x^2$ and $y=x^3$ to $y=a\\cdot x^b$.  We shall study them in more depth\nin chapter 5.\n\n\\paragraph{Polynomial}\nA sum of power functions with whole number exponents is called a\n\\textbf{polynomial}.  Such equations are among the most well-studied\nareas in mathematics.  A polynomial divided by a polynomial is called\na \\textbf{rational function}.  Both are the subject of chapter 6.\n\\index{polynomial}\\index{rational function}\n\n\\subsubsection{Exponential}\n\\marginfig[-0in]{\\chapdir/pics/2^x_function_graph}{$2^x$ is an  exponential function}\nQuantities that experience the same percentage growth or decay \nyear over year look similar in the algebra: $x$ is in\nthe exponent, and hence such an equation is called an \\gls{exponential} function.  The general form\nis $y=a\\cdot b^x$.  \\index{exponential function!standard form}\nThe ``opposite''\\footnote{There are \\emph{many} things \nwhich could be called `opposite'\nin mathematics, so this is not technical language.  We will define `inverses' of functions in 4.4.} of such a \nfunction is a called a \\gls{logarithm}, and we will follow the TI-8* for now and use the generic equation\n$y=a+b\\ln{x}$.  \\index{logarithmic function}\n\n\\subsubsection{Periodic}\nMany phenomena in nature reoccur the same way at regular intervals.  \nSuch functions are said to be \\textbf{periodic}.\nWe will  study `simple harmonic motion,' which comes from components of motion in circles, in section III,\nTrigonometric Functions.  For now\\footnote{Later, we\nwill factor the ``inside,'' but this first kind is the sort produced by your grapher.}, use the general equation $y=a\\cdot\\sin(bx+c)+d$.\\index{sine function}\n\n\\inlinefig{\\chapdir/pics/Periodic_function_illustration.png}{\\label{fig:periodic}A periodic function is so called because it repeats at a given interval, called the period (P).}\n", "meta": {"hexsha": "e75fc6415f28448cb5b7325d0bf0d0934d7852cc", "size": 4576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch01/0102.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/0102.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/0102.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": 56.4938271605, "max_line_length": 177, "alphanum_fraction": 0.7716346154, "num_tokens": 1173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6099620970414712}}
{"text": "\\input{../../assignment-header}\n\n%========================================================================\n\\title{Direct Collocation via Trapezoid Method}\n\\author{Matthew P. Kelly}\n%========================================================================\n\\begin{document}\n\\maketitle\n\n\\begin{abstract*}\nThis document gives a few examples of how to perform transcription using the\ntrapezoid method for direct collocation.\n\\end{abstract*}\n\n\\section{Boundary Value Problem with Path Objective (simple)}\n\nHere is a general formulation for a continuous-time trajectory optimization problem.\nFor now, let's assume that the duration $T$ is given.\n\n\\begin{align*}\n  & \\text{minimize: } \\qquad J = \\int_0^T \\! g(t,\\, \\bm{x},\\, \\bm{u}) \\, dt \\\\\n  & \\text{subject to: } \\qquad \\bm{0} = \\bm{h}(\\bm{x}(0), \\, \\bm{x}(T)) \\\\\n  & \\text{dynamics: } \\qquad \\dot{\\bm{x}} = \\bm{f}(t,\\, \\bm{x},\\, \\bm{u}) \\\\\n\\end{align*}\n\nPerform direct transcription using the trapezoid method. In other words,\nthe system dynamics and path objective are both approximated\nusing the trapezoid rule for quadrature.\nTo start with, we will us a uniform time grid with $N$ segments:\n\\begin{equation*}\n  h = \\frac{T}{N}  \\quad \\quad \\quad \\quad t_k = k \\cdot h\n\\end{equation*}\n\n\\textbf{Decision Variables: }  $\\displaystyle\n  \\bm{x}_0, \\bm{x}_1, \\dots ,\\bm{x}_N, \\quad \\bm{u}_0, \\bm{u}_1, \\dots, \\bm{u}_N\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{Objective Function: } $\\displaystyle\n  J = \\frac{h}{2} \\cdot \\sum_{k=0}^{N-1} \\Big(\n  g(t_k,\\,  \\bm{x}_k,\\,  \\bm{u}_k)\n  \\, + \\,\n  g(t_{k+1},\\,  \\bm{x}_{k+1},\\,  \\bm{u}_{k+1}) \\Big)\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{Boundary Constraints: } $\\displaystyle\n  \\bm{0} = \\bm{h}(\\bm{x}_0, \\, \\bm{x}_N)\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{System Dynamics Constraints: } \\\\\n\\begin{equation*}\n  \\bm{x}_{k+1} = \\bm{x}_k + \\frac{h}{2} \\cdot\n  \\Big(\n  \\bm{f}(t_k,\\,  \\bm{x}_k,\\,  \\bm{u}_k)\n  \\, + \\,\n  \\bm{f}(t_{k+1},\\,  \\bm{x}_{k+1},\\,  \\bm{u}_{k+1})\n  \\Big)\n  \\quad \\quad \\quad \\quad k \\in 0 \\dots (N-1)\n\\end{equation*}\n\n%=================================================\n\n\n\\section{Boundary Value Problem with Path Objective (Arbitrary Grid)}\n\nHere is a general formulation for a continuous-time trajectory optimization problem.\nNow let's make the boundary times decision variables and use an arbitrary grid.\n\n\\begin{align*}\n  & \\text{minimize: } \\qquad J = \\int_{T_0}^{T_F} \\! g(t,\\, \\bm{x},\\, \\bm{u}) \\, dt \\\\[1em]\n  & \\text{subject to: } \\qquad \\bm{0} = \\bm{h}(T_0, \\, T_F,\\, \\bm{x}(T_0), \\, \\bm{x}(T_F)) \\\\[1em]\n  & \\text{dynamics: } \\qquad \\dot{\\bm{x}} = \\bm{f}(t,\\, \\bm{x},\\, \\bm{u}) \\\\\n\\end{align*}\n\nWe will use an arbitrary grid, which we\nassume is provided either by the user or a mesh refinement algorithm.\nWe then apply a linear mapping to this initial grid such that the\ninitial and final points on the grid match up with\nthe initial and final times that the optimization is using. This allows us to\ncompute the time grid from the\nboundary times ($t_0, t_N$) and the mesh fraction ($\\gamma_0, \\gamma_1, \\dots, \\gamma_N$).\n\n\\begin{equation*}\n  h_k = t_{k+1} - t_k\n  \\quad \\quad \\quad \\quad\n  t_k = \\frac{t_N - t_0}{\\gamma_N - \\gamma_0} \\cdot (\\gamma_k - \\gamma_0) + t_0\n\\end{equation*}\n\n\\textbf{Decision Variables: }  $\\displaystyle\n  t_0, \\, t_N,\\,\n  \\quad\n  \\bm{x}_0,\\, \\bm{x}_1,\\, \\dots, \\,\\bm{x}_N,\\,\n  \\quad\n  \\bm{u}_0,\\, \\bm{u}_1,\\, \\dots,\\, \\bm{u}_N\\,\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{Objective Function: } $\\displaystyle\n  J = \\frac{1}{2} \\cdot \\sum_{k=0}^{N-1}\n  h_k\n  \\Big( g(t_k,\\,  \\bm{x}_k,\\,  \\bm{u}_k)\n  \\, + \\,\n  g(t_{k+1},\\,  \\bm{x}_{k+1},\\,  \\bm{u}_{k+1}) \\Big)\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{Boundary Constraints: } $\\displaystyle\n  \\bm{0} = \\bm{h}(t_0, \\, t_N,\\, \\bm{x}_0, \\, \\bm{x}_N)\n$ \\\\ \\vspace{1em} \\\\\n\n\\textbf{System Dynamics Constraints: } \\\\\n\\begin{equation*}\n  \\bm{x}_{k+1} = \\bm{x}_k + \\frac{h_k}{2} \\cdot\n  \\Big(\n  \\bm{f}(t_k,\\,  \\bm{x}_k,\\,  \\bm{u}_k)\n  \\, + \\,\n  \\bm{f}(t_{k+1},\\,  \\bm{x}_{k+1},\\,  \\bm{u}_{k+1})\n  \\Big)\n  \\quad \\quad \\quad \\quad k \\in 0 \\dots (N-1)\n\\end{equation*}\n\n%=================================================\n\\end{document}\n", "meta": {"hexsha": "d463a0381df695ed008dd426bdf8ca2ca9a5bb1a", "size": 4062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topics/09-direct-collocation/lecture-09-A/trapezoid-direct-collocation.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/09-direct-collocation/lecture-09-A/trapezoid-direct-collocation.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/09-direct-collocation/lecture-09-A/trapezoid-direct-collocation.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": 33.5702479339, "max_line_length": 98, "alphanum_fraction": 0.5733628754, "num_tokens": 1534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6097667747218508}}
{"text": "\\documentclass[11pt,oneside]{article}\t%use\"amsart\"insteadof\"article\"forAMSLaTeXformat\n\\usepackage{geometry}\t\t%Seegeometry.pdftolearnthelayoutoptions.Therearelots.\n\\geometry{letterpaper}\t\t%...ora4paperora5paperor...\n%\\geometry{landscape}\t\t%Activateforforrotatedpagegeometry\n%\\usepackage[parfill]{parskip}\t\t%Activatetobeginparagraphswithanemptylineratherthananindent\n\\usepackage{graphicx}\t\t\t\t%Usepdf,png,jpg,orepsßwithpdflatex;useepsinDVImode\n\t\t\t\t\t\t\t\t%TeXwillautomaticallyconverteps-->pdfinpdflatex\t\t\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\newtheorem{definition}{Definition}\n\\newtheorem{theorem}{Theorem}\n\n\\usepackage[colorlinks]{hyperref}\n\n\\input{macros}\n\n\\title{The \\texttt{smplxn} module\n\\footnote{This document is part of the framework~\\cite{cclar-proj:2013:00}. \\today}\n}\n\\author{Alberto Paoluzzi}\n%\\date{}\t\t\t\t\t\t\t%Activatetodisplayagivendateornodate\n\n\\begin{document}\n\\maketitle\n\\nonstopmode\n\n\\begin{abstract}\nThis module defines a minimal set of functions to generate a dimension-independent grid of simplices.\nThe name of the library was firstly used by our CAD Lab at University of Rome ``La Sapienza'' in years 1987/88 when we started working with dimension-independent simplicial complexes~\\cite{Paoluzzi:1993:DMS:169728.169719}. This one in turn imports some functions from the \\texttt{scipy} package and the geometric library \\texttt{pyplasm}~\\cite{}.\n\\end{abstract}\n\n\\tableofcontents\\newpage\n\n\\section{Introduction}\n\nThe $Simple_X^n$ library, named \\texttt{simplexn} within the Python version of the LARCC framework,\nprovides  combinatorial algorithms for some basic functions of geometric modelling with simplicial complexes. In particular, provides the efficient creation of simplicial complexes generated by simplicial complexes of lower dimension, the production of simplicial grids of any dimension, and the extraction of facets (i.e.~of $(d-1)$-faces) of complexes of $d$-simplices.\n\n\\section{Some simplicial algorithms}\n\nThe main aim of the simplicial functions given in this library is to provide optimal combinatorial algorithms, whose time complexity is linear in the size of the output.\nSuch a goal is achieved by calculating each cell in the output via closed combinatorial formulas, that do not require any searching nor data structure traversal to produce their results.\n\n\\subsection{Linear extrusion of a complex}\n\nHere we discuss an implementation of the linear extrusion of simplicial complexes according to the method discussed in~\\cite{Paoluzzi:1993:DMS:169728.169719} and~\\cite{DBLP:journals/cad/FerruciP91}. In synthesis, for each $d$-simplex in the input complex, we generate combinatorially a $(d+1)$-simplicial \\emph{tube}, i.e.~a chain of $d+1$ simplexes of dimension $d+1$. It can be shown that if the input simplices are a simplicial complex, then the output simplices are a complex too. \n\nIn other words, if the input is a complex, where all $d$-cells either intersect along a common face or are pairwise disjoints, then the output is also a simplicial complex of dimension $d+1$. This method is computationally optimal, since it does not require any search or traversal of data structures. The algorithm~\\cite{DBLP:journals/cad/FerruciP91} just writes the output making a constant number $O(1)$ of operation for each one of its $n$ output $d$-cells, so that the time complexity is $\\Omega(n)$, where $n = d\\,m$, being $m$ the number and $d$ the dimension (and the storage size) of the input cells, represented as lists of indices of vertices.\n\n\\paragraph{Computation}\n\nLet us concentrate on the generation of the simplex chain $\\gamma^{d+1}$ of dimension $d+1$ produced by combinatorial extrusion of a single simplex \n\\[\n\\sigma^d = \\langle v_0, v_1, \\ldots, v_d,   \\rangle .\n\\]\nThen we have, with $|\\gamma^{d+1}| = \\sigma^d \\times I$, and $I=[0,1]$:\n\\[\n\\gamma^{d+1} = \\sum_{k=0}^{d} (-1)^{kd} \\langle v_k, \\ldots v_d, v^*_0, \\ldots  v^*_k \\rangle \n\\]\nwith $v_k\\in \\sigma^d \\times \\{0\\}$ and  $v^*_k\\in \\sigma^d \\times \\{1\\}$, and where the term $(-1)^{kd}$ is used to generate a chain of coherently-oriented extruded simplices.\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\begin{minipage}[c]{0.49\\linewidth}\n\t\t\\caption{Extrusion of (a) a point; (b) a straight line segment; (c) a triangle.}\n\t\\end{minipage} \n   \\begin{minipage}[c]{0.49\\linewidth}\n\t\t\\includegraphics[width=0.8\\linewidth]{images/extrusion}\n\t\\end{minipage} \n   \\label{fig:extrusion}\n\\end{figure}\n\nIn our implementation the combinatorial algorithm above is twofold generalised:\n\\begin{enumerate}\n\\item by applying it to all $d$-simplices of a LAR model of dimension $d$;\n\\item by using instead of the single interval $I=[0,1]$, the possibly unconnected set of 1D intervals generated by the list of integer numbers stored in the \\texttt{pattern} variable\n\\end{enumerate}\n\n\\paragraph{Implementation}\nIn the macro below, \\texttt{larExtrude1} is the function to generate the output model vertices in a multiple extrusion of a LAR model.\n\nFirst we notice that the \\texttt{model} variable contains a pair (\\texttt{V}, \\texttt{FV}), where \\texttt{V} is the array of input vertices, and \\texttt{FV} is the array of $d$-cells (given as lists of vertex indices) providing the  input representation of a LAR cellular complex.\n\nThe \\texttt{pattern} variable is a list of integers, whose absolute values provide the sizes of the ordered set of 1D (in local coords) subintervals specified by the \\texttt{pattern} itself. Such subintervals are assembled in global coordinates, and each one of them is considered either solid or void depending on the sign of the corresponding integer, which may be either positive (solid subinterval) or negative (void subinterval).  \n\nTherefore, a value \\texttt{pattern = [1,1,-1,1]} must be interpreted as the 1D simplicial complex\n\\[\n[0,1] \\cup [1,2] \\cup [3,4]\n\\]\nwith five vertices \\texttt{W = [[0.0], [1.0], [2.0], [3.0], [4.0]]} and three $1$-cells \\texttt{[[0,1], [1,2], [3,4]]}.\n\n\\texttt{V} is the list of input $d$-vertices (each given as a list of $d$ coordinates);\n\\texttt{coords} is a list of absolute translation parameters to be applied to \\texttt{V} in order to generate the output vertices generated by the combinatorial extrusion algorithm.\n\nThe \\texttt{cellGroups} variable is used to select the groups of $(d+1)$-simplices corresponding to solid intervals in the input \\texttt{pattern}, and \\texttt{CAT} provides to flatten their set, by removing a level of square brackets.\n\n%-------------------------------------------------------------------------------\n@d Simplicial model extrusion in accord with a 1D pattern\n@{def larExtrude1(model,pattern):\n    V, FV = model\n    d, m = len(FV[0]), len(pattern)\n    coords = list(cumsum([0]+(AA(ABS)(pattern))))\n    offset, outcells, rangelimit = len(V), [], d*m\n    for cell in FV:\n        @< Append a chain of extruded cells to outcells @>\n    outcells = AA(CAT)(TRANS(outcells))\n    cellGroups = [group for k,group in enumerate(outcells) if pattern[k]>0 ]\n    outVertices = [v+[z] for z in coords for v in V]\n    outModel = outVertices, CAT(cellGroups)\n    return outModel\n@}\n%-------------------------------------------------------------------------------\n\n\\paragraph{Extrusion of single cells}\nFor each cell in \\texttt{FV} a chain of vertices is created, then they are separated into groups of $d+1$ consecutive elements, by shifting one position at a time.\n\n%-------------------------------------------------------------------------------\n@d Append a chain of extruded cells to outcells\n@{@< Create the indices of vertices in the cell \"tube\" @>\n@< Take groups of d+1 elements, by shifting one position @>\t\n@}\n%-------------------------------------------------------------------------------\n\n\\paragraph{Assembling vertex indices in a tube with their shifted images}\nHere the ``long'' chain of vertices is created.\n%-------------------------------------------------------------------------------\n@d Create the indices of vertices in the cell \"tube\"\n@{tube = [v + k*offset for k in range(m+1) for v in cell]\t@}\n%-------------------------------------------------------------------------------\n\n\\paragraph{Selecting and reshaping extruded cells in a tube}\nHere the chain of vertices is spitted into subchains, and such subchains are reshaped into three-dimensional arrays of indices.\n%-------------------------------------------------------------------------------\n@d Take groups of d+1 elements, by shifting one position\n@{cellTube = [tube[k:k+d+1] for k in range(rangelimit)]\noutcells += [reshape(cellTube, newshape=(m,d,d+1)).tolist()]\t@}\n%-------------------------------------------------------------------------------\n\n\n\n\\begin{definition}[Big-Omega order]\nWe say that a function $f(n)$ is \\emph{Big-Omega} order of a function $f(n)$, and write \n$f(n) \\in \\Omega(g(n))$ when a constant $c$ exists, such that:\n\\[\n\\lim_{n\\to\\infty} \\frac{f(n)}{g(n)}=c>0,\\qquad \\mbox{where\\ } 0<c\\leq\\infty.\n\\]\n\\end{definition}\n\n\n\n\\begin{theorem}[Optimality]\nThe combinatorial algorithm for extrusion of simplicial complexes has time complexity $\\Omega(n)$.\n\\end{theorem}\n\\proof{\nOf course, if we denote as $g(n) = nd$ the time needed to write the input of the extrusion algorithm, proportional to the constant length $d$ of cells, and as $f(m) = m(d+1)$ the time needed to write the output, where $m=n(d+1)$, we have\n\\[\n\\lim_{n\\to\\infty} \\frac{f(n)}{g(n)}= \\lim_{n\\to\\infty} \\frac{m(d+1)}{nd}\n= \\lim_{n\\to\\infty} \\frac{[n(d+1)](d+1)}{nd} = \\frac{(d+1)^2}{d} = c > 0\n\\]\n\\qed}\n\n\\subsubsection{Examples of simplicial complex extrusions}\n\n\\paragraph{Example 1}\nIt is interesting to notice that the 2D model extruded in example 1 below and shown in Figure~\\ref{fig:assembly} is locally non-manifold, and that several instance of the pattern in the $z$ direction are obtained by just inserting a void subinterval (negative size) in the \\texttt{pattern} value.\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[width=0.7\\linewidth]{images/assembly} \n   \\caption{A simplicial complex providing a quite complex 3D assembly of tetrahedra.}\n   \\label{fig:assembly}\n\\end{figure}\n\n\\paragraph{Examples 2 and 3}\nThe examples show that the implemented \\texttt{larExtrude1} algorithm is fully multidimensional. \nIt may be worth noting the initial definition of the empty \\texttt{model}, as a pair having the empty list as vertex set and the list \\texttt{[[0]]} as the cell list. Such initial value is used\nto define a predefinite constant \\texttt{VOID}.\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-1a} \n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-1b} \n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-1c} \n   \\caption{1-, 2-, and 3-dimensional simplicial complex generated by repeated extrusion with the same pattern.}\n   \\label{fig:example}\n\\end{figure}\n\n%-------------------------------------------------------------------------------\n@D Examples of simplicial complex extrusions\n@{# example 1\nV = [[0,0],[1,0],[2,0],[0,1],[1,1],[2,1],[0,2],[1,2],[2,2]]\nFV = [[0,1,3],[1,2,4],[2,4,5],[3,4,6],[4,6,7],[5,7,8]]\nmodel = larExtrude1((V,FV),4*[1,2,-3])\nVIEW(EXPLODE(1,1,1.2)(MKPOLS(model)))\n\n# example 2\nmodel = larExtrude1( VOID, 10*[1] )\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(model)))\nmodel = larExtrude1( model, 10*[1] )\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(model)))\nmodel = larExtrude1( model, 10*[1] )\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(model)))\n\n# example 3\nmodel = larExtrude1( VOID, 10*[1,-1] )\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(model)))\nmodel = larExtrude1( model, 10*[1] )\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(model)))\n@}\n%-------------------------------------------------------------------------------\n\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-2a} \n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-2b} \n   \\caption{1- and 2-dimensional simplicial complexes generated by different patterns.}\n   \\label{fig:example}\n\\end{figure}\n\n\n\\subsection{Generation of multidimensional simplicial grids}\n\nThe generation of simplicial grids of any dimension and shape using the \\texttt{larSimplexGrid1}\nis amazingly simple. The input parameter \\texttt{shape} is either a tuple or a list of integers used to specify the \\emph{shape} of the created array, i.e.~both the number of its dimensions (given by \\texttt{len(shape)}) and the \\texttt{size} of each dimension $k$ (given by the \\texttt{shape[k]} element).\nThe implementation starts from the LAR model of the VOID simplicial complex (denoted as \\texttt{VOID}, a predefined constant) and updates the \\texttt{model} variable extruding it iteratively according to the specs given by \\texttt{shape}.\nJust notice that the returned grid \\texttt{model} has vertices with integer coordinates, that can be subsequently scaled and/or translated and/or mapped in any other way, according to the user needs.\n\n%-------------------------------------------------------------------------------\n@d Generation of simplicial grids\n@{def larSimplexGrid1(shape):\n    model = VOID\n    for item in shape:\n        model = larExtrude1(model,item*[1])\n    return model\n@}\n%-------------------------------------------------------------------------------\n\n\n\\paragraph{Examples of simplicial grids} The two examples of simplicial grids generated by the macro below with \\texttt{shape} equal to \\texttt{[3,3]} and \\texttt{[2,3,4]}, respectively, are displayed in Figure~\\ref{fig:simplexn-3}.\n\n\\begin{figure}[htbp] %  figure placement: here, top, bottom, or page\n   \\centering\n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-3a} \n   \\includegraphics[height=0.25\\linewidth,width=0.25\\linewidth]{images/simplexn-3b} \n   \\caption{2- and 3-dimensional simplicial grids.}\n   \\label{fig:simplexn-3}\n\\end{figure}\n\n%-------------------------------------------------------------------------------\n@d Examples of simplicial grids\n@{grid_2d = larSimplexGrid1([3,3])\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(grid_2d)))\n\ngrid_3d = larSimplexGrid1([2,3,4])\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(grid_3d)))\n@}\n%-------------------------------------------------------------------------------\n\n\n\\subsection{Facet extraction from simplices}\n\nA $k$-face of a $d$-simplex is defined as the convex hull of any subset of $k$ vertices.\nA $(d-1)$-face of a $d$-simplex \n\\[\n\\sigma^d = \\langle v_0, v_1, \\ldots, v_d \\rangle\n\\]\n is also called a \\emph{facet}. Each of the $d+1$ facets of $\\sigma^d$, obtained by removing a vertex from $\\sigma^d$, is a $(d-1)$-simplex. A simplex may be oriented in two different ways according to the permutation\nclass of its vertices. The simplex \\emph{orientation} is so changed by either multiplying the simplex by -1, or by executing an odd number of exchanges of its vertices. \n\nThe chain of oriented boundary facets of $\\sigma^d$, usually denoted as $\\partial \\sigma^d$, is generated combinatorially as follows:\n\\[\n\\partial\\, \\sigma^d = \\sum_{k=0}^d (-1)^d \\langle v_0, \\ldots, v_{k-1}, v_{k+1}, \\ldots, v_d \\rangle\n\\]\n\n\\paragraph{Implementation}\n\nThe \\texttt{larSimplexFacets} function, for estraction of non-oriented $(d-1)$-facets of $d$-dimensional simplices, returns a list of $d$-tuples of integers, i.e.~the input LAR representation of the topology of a cellular complex. The final steps are used to remove the duplicated facets, by transforming the sorted facets into a \\emph{set of strings}, so removing the duplicated elements.\n        \n%-------------------------------------------------------------------------------\n@d Facets extraction from a set of simplices\n@{def larSimplexFacets(simplices):\n    out = []\n    d = len(simplices[0])\n    for simplex in simplices:\n        out += AA(sorted)([simplex[0:k]+simplex[k+1:d] for k in range(d)])\n    out = set(AA(tuple)(out))\n    return  sorted(out)\n@}\n%-------------------------------------------------------------------------------\n\n\\paragraph{Examples of facet extraction}\nThe simple generation of the LAR model of a simplicial decomposition of a 3D cube as a \\texttt{larSimplexGrid1} with \\texttt{shape = [1,1,1]} and of its 2D and 1D skeletons is shown here.\n\n%-------------------------------------------------------------------------------\n@d Examples of facet extraction from 3D simplicial cube\n@{V,CV = larSimplexGrid1([1,1,1])\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,CV))))\nSK2 = (V,larSimplexFacets(CV))\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(SK2)))\nSK1 = (V,larSimplexFacets(SK2[1]))\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(SK1)))\n@}\n%-------------------------------------------------------------------------------\n\n\n\n\\subsection{Converting a LAR B-Rep into a set of triangles}\n\nIn this section we show how to convert a LAR boundary representation (B-Rep), i.e.~a LAR model $\\texttt{V,FV}$ made of 2D faces, usually quads but also general polygons, into a LAR model \\texttt{verts,triangles} made by triangles.\n\n\\paragraph{From LAR faces to LAR triangles by vertex sorting}\nFrom every boundary face we generate a new vertex in \\texttt{V}, computed as the centroid of face vertices, and transform each face in a set of triangles, each one given by the face's centroid and by one of the boundary edges. \n\nSince each face is known as a spatially unordered set of vertices, we need to make some more work to extract its edges. First, the face is affinely transformed into the $z=0$ plane, then its (now 2D) vertices are circularly ordered around the origin, so that the original vertex indices are also circularly ordered. Such set of edges provides the indices of vertices to be attached to the centroid index to give the needed triangle indices.\n\n%-------------------------------------------------------------------------------\n@D From LAR faces to LAR triangles\n@{\"\"\" Transformation to triangles by sorting circularly the vertices of faces \"\"\"\ndef quads2tria(model):\n\tV,FV = model\n\tout = []\n\tnverts = len(V)-1\n\tfor face in FV:\n\t\tcentroid = CCOMB([V[v] for v in face])\n\t\tV += [centroid] \n\t\tnverts += 1\n\t\t\n\t\tv1, v2 = DIFF([V[face[0]],centroid]), DIFF([V[face[1]],centroid])\n\t\tv3 = VECTPROD([v1,v2])\n\t\tif ABS(VECTNORM(v3)) < 10**3:\n\t\t\tv1, v2 = DIFF([V[face[0]],centroid]), DIFF([V[face[2]],centroid])\n\t\t\tv3 = VECTPROD([v1,v2])\n\t\ttransf = mat(INV([v1,v2,v3]))\n\t\tverts = [(V[v]*transf).tolist()[0][:-1]  for v in face]\n\n\t\ttcentroid = CCOMB(verts)\n\t\ttverts = [DIFF([v,tcentroid]) for v in verts]\t\n\t\trverts = sorted([[ATAN2(vert),v] for vert,v in zip(tverts,face)])\n\t\tord = [pair[1] for pair in rverts]\n\t\tord = ord + [ord[0]]\n\t\tedges = [[n,ord[k+1]] for k,n in enumerate(ord[:-1])]\n\t\ttriangles = [[nverts] + edge for edge in edges]\n\t\tout += triangles\n\treturn V,out\n@}\n%-------------------------------------------------------------------------------\n\n\n\\subsection{Exporting the $Simple_x^n$ library}\nThe current version of the \\texttt{simplexn} library is exported here. Next versions will take care of the OpenCL acceleration and data partitioning with very-large size simplicial grids and their sets of faces.\n\n%-------------------------------------------------------------------------------\n@O larlib/larlib/simplexn.py \n@{# -*- coding: utf-8 -*-\n\"\"\"Module for facet extraction, extrusion and simplicial grids\"\"\"\nfrom larlib import *\n\nVOID = V0,CV0 = [[]],[[0]]    # the empty simplicial model\n@< Cumulative sum  @>\n@< Simplicial model extrusion in accord with a 1D pattern @>\n@< Generation of simplicial grids @>\n@< Facets extraction from a set of simplices @>\n@< From LAR faces to LAR triangles @>\nif __name__ == \"__main__\":\n\t@< Examples of simplicial complex extrusions @>\n\t@< Examples of simplicial grids @>\n\t@< Examples of facet extraction from 3D simplicial cube @>\n@}\n%-------------------------------------------------------------------------------\n\n\n\\section{Signed (co)boundary matrices of a simplicial complex}\n\\label{simplicial}\n\n\\section{Test examples}\n\n\\subsection{Structured grid}\n\n\\subsubsection{2D example}\n\n\\paragraph{Generate a simplicial decomposition}\nThen we generate and show a 2D decomposition of the unit square $[0,1]^2\\subset\\E^2$ into a $3\\times 3$ grid of simplices (triangles, in this case), using the \\texttt{larSimplexGrid1} function, that returns a pair \\texttt{(V,FV)}, made by the array \\texttt{V} of vertices, and by the array \\texttt{FV} of ``faces by vertex'' indices, that constitute a \\emph{reduced} simplicial LAR of the $[0,1]^2$ domain. The computed \\texttt{FV} array is then dispayed ``exploded'', being $ex,ey,ez$ the explosion parameters in the $x,y,z$ coordinate directions, respectively. Notice that the \\texttt{MKPOLS} pyplasm primitive requires a pair \\texttt{(V,FV)}, that we call a ``model'', as input --- i.e. a pair made by the array \\texttt{V} of vertices, and by a zero-based array of array of indices of vertices. Elsewhere in this document we identified such a data structure as CSR$(M_d)$, for some dimension $d$. Suc notation stands for the Compressed Sparse Row representation of a binary characteristic matrix.\n\n@d Generate a simplicial decomposition ot the $[0,1]^2$ domain\n@{V,FV = larSimplexGrid1([3,3])\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,FV))))\n@}\n\n\\paragraph{Extract the $(d-1)$-faces}\nSince the complex is simplicial, we can directly extract its facets (in this case the 1-faces, i.e. its edges) by invoking the \\texttt{larSimplexFacets} function on the argument \\texttt{FV}, so returning the array \\texttt{EV} of ``edges by vertex'' indices. \n\n%-------------------------------------------------------------------------------\n@d Extract the edges of the 2D decomposition\n@{EV = larSimplexFacets(FV)\nex,ey,ez = 1.5,1.5,1.5\nVIEW(EXPLODE(ex,ey,ez)(MKPOLS((V,EV))))\n@}\n%-------------------------------------------------------------------------------\n\n\\paragraph{Export the executable file}\nWe are finally able to generate and output a complete test file, including the visualization expressions. This file can be executed by the \\texttt{test} target of the \\texttt{make} command.\n\n%-------------------------------------------------------------------------------\n@O test/py/simplexn/test01.py\n@{\"\"\" 2D example \"\"\"\nfrom larlib import *\n\n@<Generate a simplicial decomposition ot the $[0,1]^2$ domain@>\n@<Extract the edges of the 2D decomposition@>\n@}\n%-------------------------------------------------------------------------------\n\n\\subsubsection{3D example}\n\nIn this case we produce a $2\\times 2\\times 2$ grid of tetrahedra. The dimension (3D) of the model to be generated is inferred by the presence of 3 parameters in the parameter list of the \\texttt{larSimplexGrid1} function. \n\n%-------------------------------------------------------------------------------\n@d Generate a simplicial decomposition ot the $[0,1]^3$ domain\n@{V,CV = larSimplexGrid1([2,2,2])\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,CV))))\n@}\n%-------------------------------------------------------------------------------\n\nand repeat two times the facet extraction:\n\n%-------------------------------------------------------------------------------\n@d Extract the faces and edges of the 3D decomposition\n@{\nFV = larSimplexFacets(CV)\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,FV))))\nEV = larSimplexFacets(FV)\nVIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,EV))))\n@}\n%-------------------------------------------------------------------------------\n\nand finally export a new test file:\n\n%-------------------------------------------------------------------------------\n@O test/py/simplexn/test02.py \n@{\"\"\" 3D example \"\"\"\nfrom larlib import *\n\n@<Generate a simplicial decomposition ot the $[0,1]^3$ domain@>\n@<Extract the faces and edges of the 3D decomposition@>\n@}\n%-------------------------------------------------------------------------------\n\n\n\\subsection{Unstructured grid}\n\n\n\\subsubsection{2D example}\n\n\n\\subsubsection{3D example}\n\n\n\\appendix\n\\section{Utilities}\n\n\n%-------------------------------------------------------------------------------\n@d Cumulative sum\n@{\ndef cumsum(iterable):\n    # cumulative addition: list(cumsum(range(4))) => [0, 1, 3, 6]\n    iterable = iter(iterable)\n    s = iterable.next()\n    yield s\n    for c in iterable:\n        s = s + c\n        yield s\n@}\n%-------------------------------------------------------------------------------\n\n\n\\bibliographystyle{amsalpha}\n\\bibliography{simplexn}\n\n\\end{document}\n", "meta": {"hexsha": "5cab34128cfe4584ea3a73c3ec8d70a9d9be5f50", "size": 24435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/simplexn.tex", "max_stars_repo_name": "cvdlab/lar-cc", "max_stars_repo_head_hexsha": "7092965acf7c0c78a5fab4348cf2c2aa01c4b130", "max_stars_repo_licenses": ["MIT", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-09-20T04:48:12.000Z", "max_stars_repo_stars_event_max_datetime": "2016-09-20T04:48:12.000Z", "max_issues_repo_path": "src/tex/simplexn.tex", "max_issues_repo_name": "Ahdhn/lar-cc", "max_issues_repo_head_hexsha": "7092965acf7c0c78a5fab4348cf2c2aa01c4b130", "max_issues_repo_licenses": ["MIT", "Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-02-20T21:57:07.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-21T07:18:11.000Z", "max_forks_repo_path": "src/tex/simplexn.tex", "max_forks_repo_name": "Ahdhn/lar-cc", "max_forks_repo_head_hexsha": "7092965acf7c0c78a5fab4348cf2c2aa01c4b130", "max_forks_repo_licenses": ["MIT", "Unlicense"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2016-11-04T10:47:42.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-10T17:32:50.000Z", "avg_line_length": 50.5900621118, "max_line_length": 999, "alphanum_fraction": 0.649273583, "num_tokens": 6740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7662936537604181, "lm_q1q2_score": 0.6097077526414668}}
{"text": "\\documentclass[../Notes/main.tex]{subfiles}\n\n\\begin{document}\n\\section{Mathematics}\n\\subsection{Useful Data}\n\\begin{tabular}{| l | c | c | c |}\n    \\hline\n    \\(n\\)     & Primes less than \\(n\\) & Maximal Prime Gap & \\(\\max_{0<i<n}(d(i))\\) \\\\\n    \\hline\n    \\num{1e2} & \\num{25}               & \\num{8}           & \\num{12}               \\\\\n    \\num{1e3} & \\num{168}              & \\num{20}          & \\num{32}               \\\\\n    \\num{1e4} & \\num{1229}             & \\num{36}          & \\num{64}               \\\\\n    \\num{1e5} & \\num{9592}             & \\num{72}          & \\num{128}              \\\\\n    \\num{1e6} & \\num{78498}            & \\num{114}         & \\num{240}              \\\\\n    \\num{1e7} & \\num{664579}           & \\num{154}         & \\num{448}              \\\\\n    \\num{1e8} & \\num{5761455}          & \\num{220}         & \\num{768}              \\\\\n    \\num{1e9} & \\num{50487534}         & \\num{282}         & \\num{1344}             \\\\\n    \\hline\n\\end{tabular}\n\n\n\\subsection{Modular Arithmetic}\n\n\\subsubsection{Chinese Remainder Theorem}\n\\lstinputlisting[firstline=2]{CRT/CRT.cpp}\n\n\\subsubsection{Binomial Coefficients mod m}\n\\lstinputlisting[firstline=2]{nCr/nCr.cpp}\n\n\\subsection{Primality Checks}\n\\subsubsection{Miller Rabin}\n\\lstinputlisting[firstline=2]{primalityChecks/millerRabin/millerRabin.cpp}\n\n\\subsubsection{Sieve of Eratosthenes}\n\\lstinputlisting[firstline=2]{primalityChecks/sieveEratosthenes/sieve.cpp}\n\n\\subsubsection{trialDivision}\n\\lstinputlisting[firstline=2]{primalityChecks/trialDivision/trialDivision.cpp}\n\n\\subsection{Others}\n\\subsubsection{Polynomials}\n\\lstinputlisting[firstline=2]{polynomials/polynomials.cpp}\n\n\\subsubsection{Factorial Factorization}\n\\lstinputlisting[firstline=2]{factorialFactorization/factorialFactorization.cpp}\n\n\\end{document}", "meta": {"hexsha": "d3db7e198f4bd9ed62e431727c23c067290cf4fc", "size": 1786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/math.tex", "max_stars_repo_name": "ignaciohermosillacornejo/apuntes_icpc", "max_stars_repo_head_hexsha": "0cf8935931c776f2899c03f79d4dcc6c09b81373", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-08-19T14:25:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-26T06:35:56.000Z", "max_issues_repo_path": "math/math.tex", "max_issues_repo_name": "N9199/apuntes_icpc", "max_issues_repo_head_hexsha": "198571d3d516d09e5418ab51893b400bceb01acd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-04T23:30:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T22:23:49.000Z", "max_forks_repo_path": "math/math.tex", "max_forks_repo_name": "N9199/apuntes_icpc", "max_forks_repo_head_hexsha": "198571d3d516d09e5418ab51893b400bceb01acd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-12-02T22:44:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-17T02:00:22.000Z", "avg_line_length": 38.0, "max_line_length": 86, "alphanum_fraction": 0.5862262038, "num_tokens": 567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6097077460047658}}
{"text": "\\subsection{Overview}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/classifier_comparison}\n  \\caption{Visualization of 1D classifier performance. Red points have observed EM counterparts, while blue do not. We trained the classifier only on the data with solid points, and obtained a decision boundary shown by the dashed line. The open points are the remaining half of the data, which, as you can see, were correctly classified by this decision boundary.}\n  \\label{fig:class}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/mass-distribution}\n  \\caption{Decision boundary from 1D classifier trained on $\\mathcal{M}_c$, overlayed on the 2D mass distribution. Red points have EM counterparts, while blue do not.}\n  \\label{fig:2D}\n\\end{figure*}\n\n\\begin{figure*}[ht]\n  \\includegraphics[width=\\textwidth]{img/classifier-2D.pdf}\n  \\caption{Results of linear SVM classifier, trained on half of the data set, displayed here to perfectly classify the entire data set. Red points represent events with EM counterparts, and blue points represent the events without. The predictions of the classifier are shown as the yellow and blue shaded regions.}\n  \\label{fig:2dclass}\n\\end{figure*}\n\n\n\nLIGO can provide very rapid mass estimates of candidate GW events. Since most of these detections are binary black holes, and EM followup is extremely expensive, very few events are expected to have confirmed EM counterparts.\n\nWe have trained a classifier to determine if an event will have a EM counterpart. In \\S\\ref{sec:classifier-method} we discuss the method used, and in \\S\\ref{sec:classifier-results} we discuss our results.\n\n\n\\subsection{Method}\n\\label{sec:classifier-method}\nWe trained this classifier on the first half of the data, simply taking the mid-way point in $\\mathcal{M}_c$ between the population of events with EM counterparts and without. This is demonstrated in Figure \\ref{fig:class}.\n\nWe took a slightly different approach for the 2D mass distribution, as part of the \\textbf{500\\% extra credit} problem. Here we trained a linear SVM, using \\texttt{sklearn.svm.LinearSVC}, with \\texttt{C=100}, and the masses transformed into log-space. Again, we performed the training on half of the data, and made correct predictions on the full data set. The results are shown in Figure \\ref{fig:2dclass}.\n\n\n\\subsection{Results}\n\\label{sec:classifier-results}\n\nThe classifier correctly separated the two groups with $100\\%$ completeness and zero contamination, even when the training was done using only half of the data set. Of course, this is potentially sensitive to precisely \\emph{which} half of the data set was used, so one can imagine a likely scenario where this failed.\n\nLooking at Figure \\ref{fig:chirp}, you can see that the decision boundary occurs in one of the histogram bins with zero observations. In this sense, it does correlate with structure in the data.\n\nIn Figure \\ref{fig:2D}, we have plotted that same decision boundary over the 2D mass distribution. To do this, we had to derive an expression for $m_2(m_1, \\mathcal{M}_c)$, which we accomplished using \\texttt{Mathematica}. The expression is\n%\n\\begin{equation}\n  m_2(m_1, \\mathcal{M}_c) =\n  \\frac{(2/3)^{1/3} \\mathcal{M}_c^5}{X} +\n  \\frac{X}{2^{1/3} \\cdot 3^{2/3} \\cdot m_1^3},\n%\n  \\label{eq:m2-m1-Mc}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  X \\equiv\n  \\qty[\n    9 m_1^7 \\mathcal{M}_c^5 +\n    \\sqrt{3 m_1^9 \\mathcal{M}_c^{10} \\qty(27 m_1^5 - 4 \\mathcal{M}_c^3)}\n  ]^{1/3}.\n\\end{equation}\n%\nAs you can see from Figure \\ref{fig:2D}, this line corresponds to the division between the events with and without counterparts.\n\nA similar result is obtained using the linear SVM on the 2D mass distribution directly. The result is shown in Figure \\ref{fig:2dclass}.", "meta": {"hexsha": "d21089f22da58dc3817c49ccc5e7a2acd241d15e", "size": 3770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sec_classification.tex", "max_stars_repo_name": "TheCentralLimit/ClassifiedDocument", "max_stars_repo_head_hexsha": "03d160390948ff2499131cbe7518bd49beb6e7dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sec_classification.tex", "max_issues_repo_name": "TheCentralLimit/ClassifiedDocument", "max_issues_repo_head_hexsha": "03d160390948ff2499131cbe7518bd49beb6e7dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sec_classification.tex", "max_forks_repo_name": "TheCentralLimit/ClassifiedDocument", "max_forks_repo_head_hexsha": "03d160390948ff2499131cbe7518bd49beb6e7dd", "max_forks_repo_licenses": ["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.90625, "max_line_length": 407, "alphanum_fraction": 0.7631299735, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631541, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6097077399016377}}
{"text": "\\section{Paper 2}\n\\subsection{\\emph{\"Linear Spectral Clustering Superpixel\"}}\n\\begin{frame}{INTRODUCTION}\n    The introduced technique is called SUPERPIXEL. Widely used in image \n    processing for particular tasks such as image segmentation, image analysis, \n    image classification, target tracking, 3D reconstruction, surface retrieval and \n    object proposal. The purpose of the elaborate story is to reduce the \n    computational complexity through a superpixel system called LSC (Linear Spectral\n    Clustering).\n\\end{frame}\n\n\\begin{frame}{LSC SUPERPIXEL pt1}\n    Goal: optimization (max/min) of two objective functions to create clusters of pixels called superpixels:\n    \\begin{block}{Objective Function 1: Weighted K-Means}\n        $$ F_{km} = \\sum_{k=1}^K\\sum_{p\\in\\pi_k}\\omega(p)= || \\phi(p)-m_k ||^2 $$\n    \\end{block}\n    \\begin{block}{Objective Function 2: Normalized cuts}\n        $$ F_{N_{cuts}} = \\frac{1}{K}\\sum_{k=1}^K\\frac{\\sum_{p\\in\\pi_k}\\sum_{q\\in\\pi_k}W(p,q)}{\\sum_{p\\in\\pi_k}\\sum_{q\\in{V}}W(p,q)} $$\n    \\end{block}\n    Problem: extremely high computational!\n\\end{frame}\n\n\\begin{frame}{LSC SUPERPIXEL pt2}\n    If corollary 1 is satisfied, then  \\emph{weghted K-means clustering} can be used \n    for segmentation and for creation of superpixel regions, instead of the \n    eigen-vector based method.\n    \\begin{block}{\\bfseries{Corollary 1}}\n        Optimizations of the objective functions of the weighted K-means\n        and the normalized cuts are mathematically equivalent if (1) and (2) \n        hold simultaneously. The symbol $ \\cdot $ stands for inner product.\n    \\end{block}\n\n    \\begin{block}{Equation (1)}\n           $$ \\omega(p)\\phi(p) \\cdot \\omega(q)\\phi(q) = W(p,q), \\forall p,q \\in V $$\n    \\end{block}\n\n    \\begin{block}{Equation (2)}\n        $$ \\omega(p) = \\sum_{q \\in V} W(p,q), \\forall p \\in V $$\n    \\end{block}\n\\end{frame}\n\n\\begin{frame}{LSC Algorithm pt1}\n    Problem? $ \\rightarrow $ Find the correct positive similarity function $ W (p,q) $, \n    between two data points \\emph{p} and \\emph{q} to solve equation 1.\n    \\begin{block}{Similarity Function}\n        \\begin{equation}\\small\n            \\begin{split}\n                W(p,q) = C_s^2(\\cos \\frac{\\pi}{2}(x_p-x_q)+\\cos\\frac{\\pi}{2}(y_p-y_q)) \\\\\n                + C_c^2(\\cos \\frac{\\pi}{2}(l_p-l_q)+\\cos\\frac{\\pi}{2}(\\alpha_p-\\alpha_q) \\\\\n                + \\cos\\frac{\\pi}{2}(\\beta_p-\\beta_q)x2.55^2)\n            \\end{split}\n        \\end{equation}\n    \\end{block}\n    \n    \\begin{block}{Mapping Function}\n        \\begin{equation}\\small\n            \\begin{split}\n                \\phi(p) = \\frac{1}{\\omega(p)}[C_c\\cos\\frac{\\pi}{2}l_p, C_c\\sin\\frac{\\pi}{2}l_p, 2.55C_c\\cos\\frac{\\pi}{2}\\alpha_p \\\\\n                x 2.55C_c\\sin\\frac{\\pi}{2}\\alpha_p, 2.55C_c\\cos\\frac{\\pi}{2}\\beta_p, 2.55C_c\\sin\\frac{\\pi}{2}\\alpha_p, \\\\\n                x C_s\\cos\\frac{\\pi}{2}x_p, C_s\\sin\\frac{\\pi}{2}x_p, C_s\\cos\\frac{\\pi}{2}y_p, C_s\\sin\\frac{\\pi}{2}x_p]\n            \\end{split}\n        \\end{equation} \n    \\end{block}\n    \n\\end{frame}\n\n\\begin{frame}{LSC Algorithm pt2}\n    Assuming that equation 1 exists, LSC method takes two parameters as \n    input; The image to be segmented and the preferred K number of \n    superpixels that the algorithm will have to produce. The number K \n    corresponds to the number of centroids and each of these will be useful \n    for grouping the neighbors pixels, in a range of $ \\tau v_x \\ x \\ \\tau v_y $, with $ \\tau>0.5 $, \n    using a distance comparison.\n    \\begin{figure}[h!]\n        \\centering\n        \\includegraphics[width = 0.7 \\linewidth]{paper2/slide1.png}\n        \\centering\n        \\caption{Sample images segmented with K = 1000/500/200 superpixels using LSC.}\n        \\label{fig: metrics}\n    \\end{figure}\n\\end{frame}\n\n\\begin{frame}{COMPARATIVE EXPERIMENTS}\n    \\begin{table}[htbp!]\n        \\centering\n        \\begin{adjustbox}{max width=\\textwidth}\n        \\begin{tabular}{*{9}{|c}|}%%{|c|c|c|c|c|c|c|c|c|}\n            \\hline\n            & EneOpt0 & SEEDS\\footfullcite{0781426509} & ERS\\footfullcite{0781426508} & Lattices & NCuts & SLIC\\footfullcite{0781426514} & Turbo & LSC \\\\\n            \\hline\n            \\bfseries{ADERENCE TO BOUNDARY} & & & & & & & & \\\\\n            \\emph{Under segmentation error} & 0.230 & 0.197 & 0.198 & 0.303 & 0.220 & 0.213 & 0.277 & \\bfseries{0.190}\\\\\n            \\emph{Boundary recall} & 0.765 & 0.918 & 0.920 & 0.811 & 0.789 & 0.837 & 0.739 & \\bfseries{0.926}\\\\\n            \\emph{Achievable segmentation accuracy} & 0.950 & 0.960 & 0.959 & 0.933 & 0.956 & 0.956 & 0.943 & \\bfseries{0.962}\\\\\n            \\hline\n            \\bfseries{SEGMENTATION SPEED} & & & & & & & & \\\\\n            \\emph{Computational complexity} & $ O(N^3/K^2) $ & $ O(N) $ & $ O(N^2 \\lg{N}) $ & $ O(N^{\\frac{3}{2}} \\lg{N}) $ & $ O(N^{\\frac{3}{2}}) $ & $ O(N) $ & $ O(N) $ & $ O(N) $\\\\\n            \\emph{Average time per image} & 3.35s & \\bfseries{0.0935}s & 0.969s & 0.284s & 93.4s & 0.125s & 6.61s & 0.334s\\\\\n            \\hline\n        \\end{tabular}\n        \\end{adjustbox}\n        \\caption{Performance metrics superpixel segmentation algorithms at K=400}\n        \\label{table superpixels}\n    \\end{table}\n    Best performance: low \"Under segmentation Error\" (\\emph{UE}), high \n    \"Boundary Recall\" (\\emph{BR}) and high \"Achievable segmentation accuracy \n    (\\emph{ASA}).\n\\end{frame}\n\n\\begin{frame}{APPLICATIONS: Class segmentation}\n    \\begin{figure}[htbp]\n        \\centering\n        \\includegraphics[width = 1 \\linewidth]{images/paper2/superpixelAlgo.png}\n        \\centering\n        \\caption{Segmentation using different superpixels algorithms. (a) Original Image. (b) QS. (c) ERS. (d) SLIC. (e) LSC. (f)Ground Truth.}\n        \\label{fig: superpixelSegmentation}\n    \\end{figure}\n\n    \\begin{table}[h!]\n        \\centering\n        \\begin{adjustbox}{max width=4cm}\n        \\begin{tabular}{*{5}{|c}|}%%{|c|c|c|c|c|}\n            \\hline\n            & QS & ERS & SLIC & LSC\\\\\n            \\hline\n            bike & 72.2 & 74.2 & 76.3 & \\bfseries{76.9}\\\\\n            cars & 72.2 & 74.7 & 72.5 & \\bfseries{76.8}\\\\\n            person & 66.3 & 66.5 & 66.7 & \\bfseries{67.0}\\\\\n            \\hline\n        \\end{tabular}\n        \\end{adjustbox}\n        \\caption{Accuracy using different superpixels algorithms.}\n        \\label{table accuracy}\n    \\end{table}\n\\end{frame}\n\n\\begin{frame}{APPLICATIONS: Weakly Supervised Semantic Segmentation}\n    \\begin{minipage}{\\linewidth}\n        \\centering\n        \\begin{minipage}{0.45\\linewidth}\n            \\begin{figure}[H]\n                \\includegraphics[width = 0.7 \\linewidth]{images/paper2/semanticSegmentation.png}\n                \\caption{Weakly supervised semantic segmentation. (a) A training image with bounding boxes. (b) Output of soft-max layer of $ FCN_c $. (c) Coarse semantic segmentation result. (d) Superpixels with higher probability of foreground. (e) Fore-/Background segmentation result after iterative optimization. (f) Refined semantic segmentation result.}\n            \\end{figure}\n        \\end{minipage}\n        \\hspace{0.05\\linewidth}\n        \\begin{minipage}{0.45\\linewidth}\n            \\begin{figure}[htbp]\n                \\centering\n                \\includegraphics[width = 1 \\linewidth]{images/paper2/segmentationAlgo.png}\n                \\centering\n                \\caption{Semantic segmentation. (a) Input image. (b) Strong. (c) Bbox-seg. (d) $ Joint_{sp} $ (LSC) }\n            \\end{figure}\n            \\begin{table}[H]\n                \\begin{adjustbox}{max width=4cm}\n                    \\begin{tabular}{*{3}{|c}|}%%{|c|c|c|}\n                        \\hline\n                        Strong\\footnotemark[1]& Bbox-seg\\footnotemark[1] & $ Joint_{sp} $ \\\\\n                        \\hline\n                        62.5 & 60.6 & \\bfseries{64.0} \\\\\n                        \\hline\n                    \\end{tabular}\n                \\end{adjustbox}\n                \\caption{Semantic segmentation accuracy in terms of Mean IOU (\\%)}\n            \\end{table}\n        \\end{minipage}\n    \\end{minipage}\n    \\footnotetext[1]{\\tiny G. Papandreou, L. Chen, K. Murphy, and A. Yuille, “Weakly-and semi-\n    supervised learning of a deep convolutional network for semantic image segmentation,” in Proc. ICCV, pp. 1742–1750, Dec. 2015}\n\\end{frame}\n\n\\begin{frame}{CONCLUSIONS}\n    The LSC algorithm seems to be the best in terms of adherence to the \n    boundary and in the creation of superpixels with increasingly regular \n    shape, but there are still two problems to solve:\n    \\begin{enumerate}\n        \\item The number K of superpixels entered manually\n        \\item New similarity techniques to improve performance\n    \\end{enumerate}\n\\end{frame}", "meta": {"hexsha": "4725dd42ed1dae783d35e94cdda66d253a65d1e3", "size": 8627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/slides_paper2.tex", "max_stars_repo_name": "flavioforenza/Intelligent-Systems-project", "max_stars_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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": "slides/slides_paper2.tex", "max_issues_repo_name": "flavioforenza/Intelligent-Systems-project", "max_issues_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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": "slides/slides_paper2.tex", "max_forks_repo_name": "flavioforenza/Intelligent-Systems-project", "max_forks_repo_head_hexsha": "da2b42677036dc3a8ae6851a550651d442736d98", "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.9277777778, "max_line_length": 360, "alphanum_fraction": 0.6005563927, "num_tokens": 2712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6097077367221739}}
{"text": "% !TeX root = constructions.tex\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Doubling a Cube}\\label{c.cube}\n\n\\section{Messer's doubling of a cube}\\label{s.cube1}\n\nTo double a cube we need to construct  $\\sqrt[3]{2}$. This construction is based on \\cite{newton,hwa}.\n\n\n\\subsection{Dividing a length into thirds}\n\nLang \\cite{lang} shows efficient constructs for rational fractions of the length of the side of a square (piece of paper). Here, we need to divide the side of the square into thirds.\n\nFirst, fold the square in half to locate the point $J=(1,1/2)$. Next, draw the lines $\\overline{AC}$ and $\\overline{BJ}$.\n\\begin{center}\n\\begin{tikzpicture}[scale=.8]\n% Draw square\n\\coordinate (A) at (0,12);\n\\coordinate (B) at (0,0);\n\\coordinate (C) at (12,0);\n\\coordinate (D) at (12,12);\n\n\\fill (A) circle (2pt) node[left]  {$A=(0,1)$};\n\\fill (B) circle (2pt) node[left]  {$B=(0,0)$};\n\\fill (C) circle (2pt) node[right] {$C=(1,0)$};\n\\fill (D) circle (2pt) node[right] {$D=(1,1)$};\n\n\\draw [thick] (A)  -- (B) -- (C) -- (D) -- cycle;\n\n% Divide a side in half\n\n\\coordinate (M)  at (0,6);\n\\coordinate (N) at (12,6);\n\\fill (M) circle (2pt) node[left] {$I=(0,1/2)$};\n\\fill (N) circle (2pt) node[right] {$J=(1,1/2)$};\n\\draw [thick,dashed] (M) -- (N);\n\n\n\\draw [thick,dotted,name path=ac] (A) -- \n   node[near start,above,xshift=24pt] {$y=1-x$} (C);\n\\draw [thick,dotted,name path=be2] (B) -- \n   node[near start,above,xshift=-12pt,yshift=-2pt] {$y=\\disfrac{1}{2}x$} (N);\n\n\\path [name intersections = {of = ac and be2, by = {I}}];\n\\fill (I) circle (2pt) \n   node[below,xshift=-6pt,yshift=-8pt] {$K=$}\n   node[below,xshift=-6pt,yshift=-20pt] {$(2/3,1/3)$};\n\n\\coordinate (E)  at (0,4);\n\\coordinate (F) at (12,4);\n\\fill (E) circle (2pt) node[left] {$E=(0,1/3)$};\n\\fill (F) circle (2pt) node[right] {$F=(1,1/3)$};\n\\draw [thick,dashed] (E) -- (F);\n\n\\coordinate (G)  at (0,8);\n\\coordinate (H) at (12,8);\n\\fill (G) circle (2pt) node[left] {$G=(0,2/3)$};\n\\fill (H) circle (2pt) node[right] {$H=(1,2/3)$};\n\\draw [very thick,dotted] (G) -- (H);\n\\end{tikzpicture}\n\\end{center}\n\nThe coordinates of their point of intersection $K$ are obtained by solving the two equations:\n\\vspace{-2ex}\n\\begin{form}{1.1}\ny&=&1-x\\\\\ny&=&\\disfrac{1}{2}x\\,.\n\\end{form}\nThe result is $x=2/3, y=1/3$.\n\nConstruct the line $\\overline{EF}$ perpendicular to $\\overline{AB}$ through $K$, and construct the reflection $\\overline{GH}$ of $\\overline{BC}$ around $\\overline{EF}$. The side of the square has been divided into thirds.\n\n\\subsection{Building $\\sqrt[3]{2}$}\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.9]\n% Draw and label square\n\\coordinate (A) at (0,12);\n\\coordinate (B) at (0,0);\n\\coordinate (C) at (12,0);\n\\coordinate (D) at (12,12);\n\\fill (A) circle (1.5pt) node[left]  {$A$};\n\\fill (B) circle (1.5pt) node[left]  {$B$};\n\\fill (C) circle (1.5pt) node[right] {$C$};\n\\fill (D) circle (1.5pt) node[right] {$D$};\n\\draw (B) rectangle +(12pt,12pt);\n\\draw[rotate=90] (C) rectangle +(12pt,12pt);\n\\draw [thick] (A)  -- (B) -- (C) -- (D) -- cycle;\n\n% Draw line one-third from botton\n\\coordinate (E)  at (0,4);\n\\coordinate (F) at (12,4);\n\\fill (E) circle (1.5pt) node[left] {$E$};\n\\fill (F) circle (1.5pt) node[right] {$F$};\n\\draw [very thick,dotted,name path=ef] (E) -- (F);\n\n% Draw line two-thirds from bottom\n\\coordinate (G)  at (0,8);\n\\coordinate (H) at (12,8);\n\\fill (G) circle (1.5pt) node[left] {$G$};\n\\fill (H) circle (1.5pt) node[right] {$H$};\n\\draw[rotate=-90] (G) rectangle +(12pt,12pt);\n\\draw [very thick,dotted] (G) -- (H);\n\n% Draw reflections of C and F\n\\coordinate (CP) at (0,5.31);\n\\coordinate (FP) at (2.96,8);\n\\fill (CP) circle (1.5pt)\n  node[left] {$C'$}\n  node[above right,yshift=8pt] {$\\alpha$}\n  node[below right,xshift=-2pt,yshift=-12pt] {$\\alpha'$};\n\\fill (FP) circle (1.5pt)\n  node[above] {$F'$}\n  node[below left,xshift=-8pt] {$\\alpha'$};\n\\draw[rotate=-50] (CP) rectangle +(12pt,12pt);\n\\draw[very thick,dotted] (CP) -- (FP);\n\n% Draw fold and fold arrows\n% Tangent is y = 2.26x - 10.9\n% Crosses x axis at (4.83,0)\n\\coordinate (J) at (4.83,0);\n\\fill (J) circle (1.5pt)\n    node[below] {$J$}\n    node[above left,xshift=-8pt] {$\\alpha$};\n\\draw [very thick,dashed,name path=jd] (J) -- node[very near end,left] {$l$} (10,12);\n\\draw[thick,dotted,bend right=40,->] (C) to ($(CP)+(4pt,0)$);\n\\draw[thick,dotted,bend right=40,->] (F) to ($(FP)+(4pt,4pt)$);\n\n% Draw hypotenuses of right triangles\n\\draw[very thick,dotted] (CP) -- (J);\n\\path (J)  -- (C);\n\n% Labels on BC and hypotenuses\n\\path (CP) -- node[right] {$(a+1)-b$} (J);\n\\path (J)  -- node[below] {$(a+1)-b$} (C);\n\\path (B)  -- node[below] {$b$} (J);\n\\path (C)  -- node[right] {$\\disfrac{a+1}{3}$} (F);\n\\path (CP) -- node[right,xshift=10pt] {$\\disfrac{a+1}{3}$} (FP);\n\n% Labels on AB\n\\draw[<->] ($(A)+(-1,0)$)    --\n  node[fill=white] {$a$} ($(CP)+(-1,0)$);\n\\draw[<->] ($(CP)+(-1,0)$)   --\n  node[fill=white] {$1$} ($(B)+(-1,0)$);\n\\draw[<->] ($(CP)+(-2.5,0)$) --\n  node[fill=white] {$a-\\disfrac{a+1}{3}$} ($(G)+(-2.5,0)$);\n\\draw[<->] ($(A)+(-2.5,0)$) --\n  node[fill=white] {$\\disfrac{a+1}{3}$} ($(G)+(-2.5,0)$);\n\\end{tikzpicture}\n\\end{center}\n\nLabel the side of the square by $a+1$. The construction will show that $a=\\sqrt[3]{2}$.\n\nUsing Axiom~6 place $C$ at $C'$ on $\\overline{AB}$ and $F$ at $F'$ on $\\overline{GH}$.  Denote by $J$ the point intersection of the fold with $\\overline{BC}$ and denote by $b$ the length of $\\overline{BJ}$. The length of $\\overline{JC}$ is $(a+1)-b$.\n\nWhen the fold is performed, the line segment $\\overline{JC}$ is reflected onto the line segment $\\overline{JC'}$ of the same length, and $\\overline{CF}$ is folded onto the line segment $\\overline{C'F'}$ of the same length. A simple computation shows that the length of $\\overline{GC'}$ is:\n\\begin{equation}\na-\\disfrac{a+1}{3}=\\disfrac{2a-1}{3}\\,.\\label{eq.one-third}\n\\end{equation}\nFinally, since $\\angle FCJ$ is a right angle, so is $\\angle F'C'J$.\n\n$\\triangle C'BJ$ is a right triangle so by Pythagoras' theorem:\n\\vspace{-2ex}\n\\begin{form}{1.1}\n1^2 + b^2 &=& ((a+1)-b)^2\\\\\n%&=& a^2+2a+1 - 2(a+1)b + b^2\\\\\na^2+2a - 2(a+1)b&=&0\\\\\nb&=&\\disfrac{a^2+2a}{2(a+1)}\\,.\n\\end{form}\n\n$\\angle GC'F' + \\angle F'C'J + \\angle JC'B = 180^\\circ$ since they form the straight line $\\overline{GB}$. Denote $\\angle GC'F'$ by $\\alpha$.\n\\[\n\\angle JC'B=180^\\circ - \\angle F'C'J - \\angle GC'F'= 180^\\circ - 90^\\circ - \\alpha=90^\\circ -\\alpha\\,,\n\\]\nwhich we denote by $\\alpha'$. The triangles $\\triangle C'BJ$, $\\triangle F'GC'$ are right triangles, so $\\angle C'JB=\\alpha$ and $\\angle C'F'G=\\alpha'$. Therefore, the triangles are similar and using Equation~\\ref{eq.one-third} we have:\n\\[\n\\disfrac{b}{(a+1)-b}=\\disfrac{\\disfrac{2a-1}{3}}{\\disfrac{a+1}{3}}\\,.\n\\]\nSubstituting for $b$:\n\\vspace{-2ex}\n\\begin{form}{1.8}\n\\disfrac{\\disfrac{a^2+2a}{2(a+1)}}{(a+1)-\\disfrac{a^2+2a}{2(a+1)}}&=&\\disfrac{2a-1}{a+1}\\\\\n%\\disfrac{a^2+2a}{(a+1)\\cdot 2(a+1)-(a^2+2a)}&=&\\disfrac{2a-1}{a+1}\\\\\n\\disfrac{a^2+2a}{a^2+2a +2}&=&\\disfrac{2a-1}{a+1}\\,.\n%a^3+3a^2+2a&=&(2a-1)(a^2+2a+2)\\,.\n%&=&2a^3+3a^2+2a-2\\,.\n\\end{form}\n\nSimplifying results in $a^3=2$ and $a=\\sqrt[3]{2}$.\n\n\n\n\\newpage\n\n\\section{Beloch's doubling of a cube}\\label{s.cube2}\n\nMargharita P. Beloch formalized Axiom~6 (Section~\\ref{s.ax6}) and showed that it could be used to solve cubic equations. Here we give her construction for doubling the cube. The solution of cubic equations is discussed in Chapters~\\ref{c.lill}, \\ref{c.beloch}.\n\n\\subsection{The construction}\n\nPlace point $A$ at $(-1,0)$ and point $B$ at $(0,-2)$. Let $p$ be the line with equation $x=1$ and let $q$ be the line with equation $y=2$. Using Axiom~6 construct a fold $l$ that places $A$ at $A'$ on $p$ and $B$ at $B'$ on $q$. Denote the intersection of the fold and the $y$-axis by $Y$ and the intersection of the fold and $x$-axis by $X$.\n\n\\begin{center}\n\\begin{tikzpicture}[scale=1]\n% Draw and label square\n\\coordinate (O) at (0,0);\n\\coordinate (A) at (-2,0);\n\\coordinate (B) at (0,-4);\n\\fill (O) circle (1.5pt)\n  node[below left,xshift=-7pt] {$O$}\n  node[below left,yshift=-12pt] {$(0,0)$};\n\\fill (A) circle (1.5pt)\n  node[above left,xshift=-7pt] {$A$}\n  node[below left,xshift=2pt,yshift=0pt] {$(-1,0)$};\n\\fill (B) circle (1.5pt)\n  node[left,xshift=-12pt] {$B$}\n  node[left,yshift=-12pt] {$(0,-2)$};\n\n%\\draw[thick] (0,-4.5) -- node[near start, left,yshift=-20pt] {$p$} +(0,10);\n%\\draw[thick] (-5,0) -- node[very near start, below,xshift=-16pt] {$q$} +(12,0);\n\\draw[thick] (0,-4.5) --  node[very near end,above left,yshift=12pt] {$y$-\\textsf{axis}} +(0,10);\n\\draw[thick] (-5,0)   -- node[very near start,above left] {$x$-\\textsf{axis}} +(12,0);\n\\draw[very thick] (2,-4.5) -- node[very near start, right,yshift=-10pt] {$p\\!:x=1$} +(0,10);\n\\draw[very thick] (-5,4) -- node[very near start, above,xshift=-16pt] {$q\\!: y=2$} +(12,0);\n\n\\coordinate (AP) at (2,5);\n\\fill (AP) circle (1.5pt) node[above right] {$A'$};\n\\coordinate (BP) at (6.34,4);\n\\fill (BP) circle (1.5pt) node[above right] {$B'$};\n\n% Tangent y = -0.8x + 1.26\n\n% Exchanged X and Y \n\\coordinate (X) at (0,2.52);\n\\coordinate (Y) at (3.15,0);\n\\fill (X) circle (1.5pt) node[right,xshift=4pt,yshift=2pt] {$Y$};\n\\fill (Y) circle (1.5pt) node[above right,xshift=10pt] {$X$};\n\\draw [very thick,dashed] ($(X)!-1.1!(Y)$) -- node[very near end,right,xshift=8pt] {$l$} ($(X)!2!(Y)$);\n\n\\draw [very thick,dotted] (A) -- (AP);\n\\draw [very thick,dotted] (B) -- (BP);\n\n\\draw[thick,dotted,bend left=40,->] (A) to ($(AP)+(-4pt,0)$);\n\\draw[thick,dotted,bend left=40,->] (B) to ($(BP)+(-6pt,-3pt)$);\n\n%\\node[above left] at (0,4) {$(0,2)$};\n%\\node[below left] at (2,0) {$(1,0)$};\n\n\\end{tikzpicture}\n\\end{center}\n\n\\newpage\n\n\\subsection{Proof}\n\nLet us extract a simplified diagram:\n\n\\begin{center}\n\\begin{tikzpicture}[scale=.9]\n\\coordinate (O) at (0,0);\n\\coordinate (A) at (-2,0);\n\\coordinate (B) at (0,-4);\n\\fill (O) circle (1.5pt)\n  node[below left,xshift=-7pt] {$O$};\n\\fill (A) circle (1.5pt)\n  node[above left,xshift=-7pt] {$A$}\n  node[above right,xshift=10pt] {$\\alpha$};\n\\fill (B) circle (1.5pt)\n  node[left,xshift=-12pt] {$B$}\n  node[above right,yshift=12pt] {$\\alpha'$};\n\n\\draw[thick] (0,-4.5) -- +(0,10);\n\\draw[thick] (-3,0)   -- +(8,0);\n\n\\coordinate (AP) at (2,5);\n\\fill (AP) circle (1.5pt) node[above right] {$A'$};\n\\coordinate (BP) at (6.34,4);\n\\fill (BP) circle (1.5pt) node[above right] {$B'$};\n\n% Tangent y = -0.8x + 1.26\n\n% Exchanged X and Y \n\\coordinate (X) at (0,2.52);\n\\coordinate (Y) at (3.15,0);\n\\fill (X) circle (1.5pt)\n  node[right,xshift=4pt,yshift=2pt] {$Y$}\n  node[below right,yshift=-14pt] {$\\alpha$}\n  node[below left,xshift=2pt,yshift=-12pt] {$\\alpha'$};\n\\fill (Y) circle (1.5pt)\n  node[above right,xshift=10pt] {$X$}\n  node[below left,xshift=-13pt,yshift=-2pt] {$\\alpha$}\n  node[above left,xshift=-15pt] {$\\alpha'$};\n\\draw [very thick,dashed] ($(X)!-.4!(Y)$) -- ($(X)!1.2!(Y)$);\n\n\\draw [very thick,dotted] (A) -- (AP);\n\\draw [very thick,dotted] (B) -- (BP);\n\n\\draw (0,0) rectangle +(10pt,10pt);\n\\draw[rotate=-130] (X) rectangle +(10pt,10pt);\n\\draw[rotate=145] (Y) rectangle +(10pt,10pt);\n\n\\end{tikzpicture}\n\\end{center}\n\nThe fold is the perpendicular bisector of $\\overline{AA'}$ and $\\overline{BB'}$. Therefore, $\\angle AYX$ and $\\angle YXB$ are right angles and $\\overline{AA'}$ is parallel to $\\overline{BB'}$. By alternate interior angles $\\angle YAO =\\angle BXO=\\alpha$. If an acute angle in a right triangle is $\\alpha$, the other acute angle must be $90^\\circ - \\alpha$, which we denote $\\alpha'$. The labeling of the angles in all the triangles in the diagram follows immediately.\n\nWe have three similar triangles $\\triangle AOY\\sim \\triangle YOX \\sim \\triangle XOB$. $\\overline{OA}=1$, $\\overline{OB}=2$ are given, so:\n\\vspace{-2ex}\n\\begin{form}{1.4}\n\\disfrac{\\overline{OY}}{\\overline{OA}}=\\disfrac{\\overline{OX}}{\\overline{OY}}=\\disfrac{\\overline{OB}}{\\overline{OX}}\\\\\n\\disfrac{\\overline{OY}}{1}=\\disfrac{\\overline{OX}}{\\overline{OY}}\\\\\n\\overline{OY}^2=\\overline{OX}\\\\\n\\disfrac{\\overline{OY}}{1}=\\disfrac{2}{\\overline{OX}}\\\\\n\\overline{OY}^2=\\overline{OX}=\\disfrac{2}{\\overline{OY}}\\;,\n\\end{form}\nresulting in $\\overline{OY}^3=2$ and $\\overline{OY}=\\sqrt[3]{2}$.\n", "meta": {"hexsha": "ae147124cee605a354c7594680d7a0cd57774306", "size": 12067, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cube.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": "cube.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": "cube.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": 37.9465408805, "max_line_length": 467, "alphanum_fraction": 0.6131598575, "num_tokens": 4779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.6095180502822012}}
{"text": "\\ProvidesFile{mpc.tex}\n\n\\documentclass[a4paper]{article}\n\n\\pagestyle{empty}\n\n\\usepackage{caption}\n\\usepackage{subcaption}\n\n\\usepackage{hyperref}\n\n\\usepackage{float}\n\n\\bibliographystyle{plain}\n\\usepackage[numbers]{natbib}\n\n\\usepackage{times}\n\n\\usepackage{graphicx}\n\\usepackage{url}\n\n\\usepackage{amsmath,amssymb}\n\\usepackage{cases}\n\\usepackage{color}\n\\usepackage{tikz}\n\n\\usepackage{mymath}\n\\usepackage{lipm_notation}\n\n\\usetikzlibrary{snakes}\n\n\\usepackage{a4wide}\n\\renewcommand{\\baselinestretch}{1.5}\n\n\\begin{document}\n\n\\section*{Model of the system}\n\n\\noindent We assume the following discrete-time dynamic system:\n\n\\begin{equation}\n\\begin{split}\n    \\cstate_{k+1} =& \\M{A}_k \\cstate_k + \\M{B}_k \\cjerk_k\\\\\n    \\cop_{k+1} =& \\M{D}_{k} \\cstate_{k+1}\n\\end{split}\n\\end{equation}\n\n\\noindent State and control variables:\n\n\\begin{equation}\n    \\cstate = \n    \\begin{bmatrix}\n        c^{x}\\\\\n        \\dot{c}^{x}\\\\\n        \\ddot{c}^{x}\\\\\n        c^{y}\\\\\n        \\dot{c}^{y}\\\\\n        \\ddot{c}^{y}\\\\\n        c^{\\theta} \\\\ \n        \\dot{c}^{\\theta} \\\\\n        \\ddot{c}^{\\theta} \\\\\n    \\end{bmatrix},\n    \\quad\n    \\V{u} = \\dddot{\\V{c}} = \n    \\begin{bmatrix}\n        \\dddot{c}^{x}\\\\\n        \\dddot{c}^{y}\\\\\n        \\dddot{c}^{\\theta}\\\\\n    \\end{bmatrix}\n\\end{equation}\n\n\\noindent Where $c^{\\theta}$ is the yaw angle of the torso. The state transition and control matrices of the discretized system\nare:\n\n\\begin{equation}\n\\M{A}_k = \n\\begin{bmatrix}\n    \\M{M}_k       & \\M{0}         & \\M{0} \\\\\n    \\M{0}         & \\M{M}_k       & \\M{0} \\\\\n    \\M{0}         & \\M{0}         & \\M{M}_k \\\\\n\\end{bmatrix}\n\\end{equation}\n\\noindent where $\\M{M}_k$ is:\n\\begin{equation}\n\\M{M}_k =\n\\begin{bmatrix}\n    1       & T_k   & T_k^2/2\\\\   \n    0       & 1     & T_k    \\\\   \n    0       & 0     & 1      \\\\   \n\\end{bmatrix}\n\\end{equation}\n\\noindent Control matrix:\n\\begin{equation}\n\\quad\n\\M{B}_k =\n\\begin{bmatrix}\n    T_k^3/6 & 0       & 0       \\\\\n    T_k^2/2 & 0       & 0       \\\\\n    T       & 0       & 0       \\\\\n    0       & T_k^3/6 & 0       \\\\\n    0       & T_k^2/2 & 0       \\\\\n    0       & T       & 0       \\\\\n    0       & 0       & T_k^3/6 \\\\ \n    0       & 0       & T_k^2/2 \\\\\n    0       & 0       & T       \n\\end{bmatrix}\n\\end{equation}\n\n\\noindent Output matrix:\n\\begin{equation}\n\\quad\n\\M{D}_k =\n\\begin{bmatrix}\n    1 & 0 & -\\frac{c_{k}^{z}}{g} & 0 & 0 & 0 & 0 & 0 & 0\\\\\n    0 & 0 & 0 & 1 & 0 & -\\frac{c_{k}^{z}}{g} & 0 & 0 & 0\\\\\n\\end{bmatrix}\n\\end{equation}\n\n\\noindent The state vector does not contain the feet orientations and their derivatives. The reason therefor is that we are interested only in the feet positions and orientations when they are static on the ground.\n\n\\section*{Condensation of the system matrices}\n\n\\noindent We put the system matrices in the condensed form for the whole preview horizon ($N$ intervals):\n\n\\begin{equation}\n\\begin{split}\n    \\cState_{i+1} = \\M{U}_{x} \\cstate_{0} + \\M{U}_{u} \\cJerk_{i}\\\\\n    \\CoP_{i+1} = \\M{O}_{x} \\cstate_{0} + \\M{O}_{u} \\cJerk_{i}\n\\end{split}\n\\end{equation}\n\n\\noindent And corresponding matrices:\n\n\\begin{equation}\n    \\M{U}_{x} =\n        \\begin{bmatrix}\n        \\M{A}_0    \\\\\n        \\M{A}_1 \\M{A}_0  \\\\\n        \\vdots           \\\\\n        \\M{A}_{N-1} \\dots \\M{A}_0 \\\\\n        \\end{bmatrix}\n    \\quad\\quad\n    \\M{U}_{u} =\n        \\begin{bmatrix}\n        \\M{B}_0                             & \\M{0}                                 & \\dots & \\M{0} \\\\\n        \\M{A}_1 \\M{B}_0                     & \\M{B}_1                               & \\dots & \\M{0} \\\\\n        \\vdots                              & \\vdots                                & \\ddots& \\vdots \\\\\n        \\M{A}_{N-1} \\dots \\M{A}_1 \\M{B}_0   & \\M{A}_{N-1} \\dots \\M{A}_2 \\M{B}_1     & \\dots & \\M{B}_{N-1} \\\\\n        \\end{bmatrix}\n\\end{equation}\n\n\\begin{equation}\n    \\M{O}_{x} =\n        \\begin{bmatrix}\n        \\M{D}_1 \\M{A}_0    \\\\\n        \\M{D}_2 \\M{A}_1 \\M{A}_0  \\\\\n        \\vdots           \\\\\n        \\M{D}_{N-1} \\M{A}_{N-2} \\dots \\M{A}_0 \\\\\n        \\end{bmatrix}\n    \\quad\\quad\n    \\M{O}_{u} =\n        \\begin{bmatrix}\n        \\M{D}_1 \\M{B}_0                     & \\M{0}                                 & \\dots & \\M{0} \\\\\n        \\M{D}_2 \\M{A}_1 \\M{B}_0             & \\M{D}_2 \\M{B}_1                       & \\dots & \\M{0} \\\\\n        \\vdots                              & \\vdots                                & \\ddots& \\vdots \\\\\n        \\M{D}_{N-1} \\M{A}_{N-2} \\dots \\M{A}_1 \\M{B}_0   & \\M{D}_{N-1} \\M{A}_{N-2} \\dots \\M{A}_2 \\M{B}_1     & \\dots & \\M{D}_{N-1}\\M{B}_{N-2} \\\\\n        \\end{bmatrix}\n\\end{equation}\n\n\\section*{Constraints}\n\nLet $\\SET{I}$ be the set containing indices of sampling intervals, $\\SET{I}^l_f\n\\subset \\SET{I}$ be the set of indices where orientations of the left foot are\nfixed within $N$ timesteps of a preview, the set $\\SET{I}^r_f$ is defined equivalently for the right foot. Content of the sets $\\SET{I}^l_f$ and $\\SET{I}^r_f$ are defined by the finite state machine at the beginning of\neach preview and are used to build the constraints and selection matrices. For each step there is a defined velocity and duration.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\paragraph{Footstep positions}\nFootstep positions are expressed in the global frame - in general to impose simple bounds as constraints on the variable footstep positions we need to translate and rotate from global to local foot frame.\nIn this case we assume that the constraints on the feet positions have the shape of rectangles. Furthermore, we do not consider the rotation of the constraints.\\\\\n\n\\noindent The footstep position and orientation corresponding to $k$-th ($k = 1,\\dots,N$) sampling interval is denoted as $\\V{f}_k = (f^x_k, f^y_k, f^{\\theta}_k)$.\nWe can map the $M$ footsteps into $N$ sampling intervals of an MPC using the following formula:\n\n\\begin{equation}\n\\begin{split}\n    \\underbrace{\n    \\begin{bmatrix} \n        \\M{f}_1 \\\\ \n        \\vdots \\\\ \n        \\M{f}_N \n    \\end{bmatrix}\n    }_{\\M{F}_{i+1}}\n    & = \n    \\begin{bmatrix}\n        1   &  0   &   \\dots   &   0 \\\\\n        1   &  0   &   \\dots   &   0 \\\\\n        0   &  1   &   \\dots   &   0 \\\\\n        0   &  1   &   \\dots   &   0 \\\\\n        0   &  1   &   \\dots   &   0 \\\\\n        \\vdots  &  \\vdots  &   \\ddots  &   \\vdots \\\\\n        0   &  0   &   \\dots   &   1 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        \\overline{\\M{f}}_0\\\\\n        \\vdots\\\\\n        \\overline{\\M{f}}_M \\\\\n    \\end{bmatrix}\n    =\n    \\underbrace{\n    \\begin{bmatrix}\n        1   \\\\\n        1   \\\\\n        0   \\\\\n        0   \\\\\n        0   \\\\\n        \\vdots  \\\\\n        0   \\\\\n    \\end{bmatrix}}_{\\M{V}_{i+1}}\n    \\overline{\\M{f}_0}\n    +\n    \\underbrace{\n    \\begin{bmatrix}\n        0   &   \\dots   &   0 \\\\\n        0   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        1   &   \\dots   &   0 \\\\\n        \\vdots  &   \\ddots  &   \\vdots \\\\\n        0   &   \\dots   &   1 \\\\\n    \\end{bmatrix}}_{\\overline{\\M{V}}_{i+1}}\n    \\underbrace{\n    \\begin{bmatrix}\n        \\overline{\\M{f}}_1 \\\\\n        \\vdots\\\\\n        \\overline{\\M{f}}_M\\\\\n    \\end{bmatrix}}_{\\overline{\\M{F}}_{i+1}}\n\\end{split}\n\\end{equation}\n\n\\noindent $\\overline{\\M{V}}_{i+1}$ matrix has $N$ rows corresponding to $N$ time intervals and $M$ columns corresponding to $M$ footsteps in the preview horizon. Equation 11\nwill be used in the objective function in order to express footsteps in terms of decision variables $\\overline{\\M{F}}_{i+1}$. Matrices $\\overline{\\M{V}}_{i+1}$, $\\M{V}_{i+1}$ are built before each preview based on the states previewed by the finite state machine.\nStates are previewed according to the time of the preview, sampling time of one interval of the preview and duration of each allowed state. \\\\\n\n\\noindent The difference between two consecutive steps (position of the next step with respect to the previous one) should lie within a rectangle. We therefore constrain the position\nof the next footstep with respect to the previous footstep for all footsteps in the preview. Rotation of this constraint is not taken into account, for example, for three steps in the preview the second step's rotation is not considered when constraining the third step.\nPotentially, it can lead to problems such as self-collisions, however in practice this seems to be of lesser importance especially when violent rotations are prohibited. \\\\\n\n\\noindent We have therefore:\n\n\\begin{equation}\n\\begin{bmatrix}\n    \\ubar{p}^{x}_{k} \\\\\n    \\ubar{p}^{y}_{k}     \n\\end{bmatrix}\n\\le\n\\begin{bmatrix}\n    \\overline{{f}}^{x}_{k+1} - \\overline{{f}}^{x}_{k} \\\\\n    \\overline{{f}}^{y}_{k+1} - \\overline{{f}}^{y}_{k}\n\\end{bmatrix}\n \\le \n\\begin{bmatrix}\n    \\bar{p}^{x}_{k} \\\\\n    \\bar{p}^{y}_{k}     \n\\end{bmatrix}\n, \\quad k = 0 \\dots M-1\n\\end{equation}\n\n\\noindent Where $M$ is the number of steps in the preview.\n\n\\noindent In short:\n\n\\begin{equation}\n\\ubarV{P} \\le \\M{A}_{p}\\V{X} \\le \\barV{P}\n\\end{equation}\n\n\\noindent Where $\\V{X}$ is the decision variables vector.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\paragraph{CoP position}\nBounds on the CoP are expressed in the global frame. Orientations $f^{\\theta}_k$ of the footsteps are disregarded in this constraint. We disregard them because of the geometry of the constraint we assume to avoid\nnonlinearity. Namely, we constrain the CoP to lie within much smaller bounds which do not change with the orientations of the feet. These smaller bounds are represented conceptually as a circle and approximated by a square inscribed therein.\nTherefore, as circle is invariant to the rotation, we can drop the rotation matrix from the CoP constraints but keep the feet rotations among decision variables which will appear in the objective function.\n\n\\begin{equation}\n\\begin{bmatrix}\n    \\underline{z}^{x}_{k} \\\\\n    \\underline{z}^{y}_{k}     \n\\end{bmatrix}\n\\leq\n\\begin{bmatrix}\n    z^{x}_{k} - f^{x}_{k} \\\\\n    z^{y}_{k} - f^{y}_{k}     \n\\end{bmatrix}\n\\leq\n\\begin{bmatrix}\n    \\overline{z}^{x}_{k} \\\\\n    \\overline{z}^{y}_{k}     \n\\end{bmatrix}\n\\quad k = 1 \\dots N\n\\end{equation}\n\n\\noindent In short:\n\n\\begin{equation}\n\\ubarV{Z} \\le \\M{A}_{z}\\V{X} \\le \\barV{Z}\n\\end{equation}\n\n\\section*{Other variables}\n\n\\paragraph{Decision variables}\n\n\\begin{equation}\n    \\quad\n    \\V{X} = \n    \\begin{bmatrix} \n        \\dddot{\\M{C}} \\\\\n        \\overline{\\M{F}}^{x} \\\\\n        \\overline{\\M{F}}^{y} \\\\\n        \\overline{\\M{F}}^{\\theta}\n    \\end{bmatrix}\n    \\quad\n\\end{equation}\n\n\\section*{Objective function}\n\n\\begin{equation}\n\\begin{split}\n    \\MINIMIZE{\\M{X}}  & \\frac{\\beta}{2} \\NORM{\\cVel^{x} - \\cVel^{x}_{ref}}^2 + \\frac{\\beta}{2} \\NORM{\\cVel^{y} - \\cVel^{y}_{ref}}^2 + \\\\\n                        & \\frac{\\gamma}{2}  \\NORM{\\CoP^{x} - \\M{F}^{x}}^2 + \\frac{\\gamma}{2}  \\NORM{\\CoP^{y} - \\M{F}^{y}}^2 +\\\\\n                        & \\frac{\\alpha}{2} \\NORM{\\cJerk^{x}}^2 + \\frac{\\alpha}{2} \\NORM{\\cJerk^{y}}^2 + \\frac{\\gamma}{2} \\NORM{\\M{F}^{\\theta} - \\cPos^{\\theta}}^2 +\\\\\n                        & \\frac{\\beta}{2} \\NORM{\\cVel^{\\theta} - \\cVel^{\\theta}_{ref}}^2 +\\\\\n                        & \\frac{\\alpha}{2} \\NORM{\\cJerk^{\\theta}}^2 \\\\\n    \\SUBJECTTO          & \\ubarV{P} \\le \\M{A}_{p}\\V{X} \\le \\barV{P} \\\\\n                        & \\ubarV{Z} \\le \\M{A}_{z}\\V{X} \\le \\barV{Z}\n\\end{split}\n\\end{equation}\n\n\\section*{Hierarchical least squares problem}\n\\begin{description}\n    \\item[Level 1:]\n        \\begin{equation}\n        \\begin{split}\n            & \\ubarV{Z} \\le \\M{A}_{z}\\V{X} \\le \\barV{Z} \\\\\n            & \\ubarV{P} \\le \\M{A}_{p}\\V{X} \\le \\barV{P}\n        \\end{split}\n        \\end{equation}\n\n    \\item[Level 2:]\n        \\begin{equation}\n        \\begin{split}\n            & \\sqrt{\\frac{\\alpha}{2}} \\cJerk = 0 \\\\\n            & \\sqrt{\\frac{\\beta}{2}} \\M{S}_{vx} \\V{U}_{u} \\cJerk = \\sqrt{\\frac{\\beta}{2}} (\\cVel^{x}_{ref} - \\M{S}_{vx} \\V{U}_{x} \\cstate_{0})\\\\\n            & \\sqrt{\\frac{\\beta}{2}} \\M{S}_{vy} \\V{U}_{u} \\cJerk = \\sqrt{\\frac{\\beta}{2}} (\\cVel^{y}_{ref} - \\M{S}_{vy} \\V{U}_{x} \\cstate_{0})\\\\\n            & \\sqrt{\\frac{\\beta}{2}} \\M{S}_{vt} \\V{U}_{u} \\cJerk = \\sqrt{\\frac{\\beta}{2}} (\\cVel^{\\theta}_{ref} - \\M{S}_{vt} \\V{U}_{x} \\cstate_{0})\\\\\n            & \\sqrt{\\frac{\\gamma}{2}} (\\M{S}_{cx} \\M{D} \\V{U}_{u} \\cJerk - \\overline{\\M{V}} \\overline{\\M{F}}^{x}) = \\sqrt{\\frac{\\gamma}{2}} (\\M{V}\\overline{\\M{f}}^{x}_{0} - \\M{S}_{cx} \\M{D} \\V{U}_{x} \\cstate_{0})\\\\\n            & \\sqrt{\\frac{\\gamma}{2}} (\\M{S}_{cy} \\M{D} \\V{U}_{u} \\cJerk - \\overline{\\M{V}} \\overline{\\M{F}}^{y}) = \\sqrt{\\frac{\\gamma}{2}} (\\M{V}\\overline{\\M{f}}^{y}_{0} - \\M{S}_{cy} \\M{D} \\V{U}_{x} \\cstate_{0})\\\\\n            & \\sqrt{\\frac{\\gamma}{2}} (\\overline{\\M{V}} \\overline{\\M{F}}^{\\theta} - \\M{S}_{t} \\V{U}_{u} \\cJerk) = \\sqrt{\\frac{\\gamma}{2}} (\\M{V}\\overline{\\M{f}}^{\\theta}_{0} - \\M{S}_{t} \\V{U}_{x} \\cstate_{0})\\\\\n        \\end{split}\n        \\end{equation}\n\\end{description}\n\n\\section*{Swing foot trajectory generation}\n\nTrajectory is generated using cubic polynomial of the form\n\\begin{equation}\n    at^3 + bt^2 + ct + d = y_{swing},\n\\end{equation}\nwhere $t$ is time instance; $a,b,c,d$ are coefficients; and $y_{swing}$ is position of the swing\nfoot at time $t$.\n\n\\noindent Derivatives of the cubic polynomial are\n\\begin{equation}\n\\begin{split}\n    & 3at^2 + 2bt + c = \\dot{y}_{swing},\\\\\n    & 6at + 2b = \\ddot{y}_{swing},\\\\\n    & 6a = \\dddot{y}_{swing}.\\\\\n\\end{split}\n\\end{equation}\n\n\\noindent Second derivative (acceleration) will be tracked by the whole-body controller. Hence, the second derivative equation is used to generate \ntrajectory.\n\n\\noindent Knowing initial and final time and position of the motion, coefficients $a$ and $b$ can be expressed as follows\n\\begin{equation}\n\\begin{split}\n    & a = -\\frac{2}{t^{3}_f}(y_{swing,f} - y_{swing,i})\\\\\n    & b = \\frac{3}{t^{2}_f}(y_{swing,f} - y_{swing,i})\\\\\n\\end{split}\n\\end{equation}\n\n\\noindent Accelerations to be tracked can be found then, using\n\\begin{equation}\n\\begin{split}\n    & -\\frac{12}{t^{3}_f}(y_{swing,f} - y_{swing,i})t + \\frac{6}{t^{2}_f}(y_{swing,f} - y_{swing,i}) = \\ddot{y}_{swing}\\\\\n\\end{split}\n\\end{equation}\n\n\\noindent for every swing phase the above polynomial is evaluated at a desired frequency between $[0, T_{support}]$. With initial and final\npositions ($y_{swing, i}$ and $y_{swing, f}$) taken from the planned footsteps. \nDuring transitional double support all accelerations are set to zero. For the $z$ coordinate a fixed\nstep height $h_{step}$ is used to determine the trajectory as follows\n\\begin{equation}\n    y_{swing,f}^z = \n    \\left\\{\n        \\begin{array}{ll}\n            h_{step}    & t \\le \\frac{1}{2}T_{support}, \\\\\n            0           & t > \\frac{1}{2}T_{support}\\\\\n        \\end{array}\n    \\right.\n\\end{equation}\n\n\\noindent Accelerations of the torso ($\\ddot{c}^x$, $\\ddot{c}^y$, $\\ddot{c}^\\theta$) are taken directly from the state vector\n(they are not interpolated using polynomials).\n\n\\end{document}\n \n", "meta": {"hexsha": "8289f4acfab18f9195a941a9d8d236da2d899ab2", "size": 14772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/mpc.tex", "max_stars_repo_name": "jmichalczyk/motion-planning-walking", "max_stars_repo_head_hexsha": "d5e8af515fefa13945c97be9724ff79db0a79439", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-03-07T12:56:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-09T06:45:00.000Z", "max_issues_repo_path": "doc/mpc.tex", "max_issues_repo_name": "jmichalczyk/motion-planning-walking", "max_issues_repo_head_hexsha": "d5e8af515fefa13945c97be9724ff79db0a79439", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-08-31T10:14:06.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T15:11:47.000Z", "max_forks_repo_path": "doc/mpc.tex", "max_forks_repo_name": "jmichalczyk/motion-planning-walking", "max_forks_repo_head_hexsha": "d5e8af515fefa13945c97be9724ff79db0a79439", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-08-28T15:06:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-03T07:17:29.000Z", "avg_line_length": 35.1714285714, "max_line_length": 270, "alphanum_fraction": 0.5573382074, "num_tokens": 5242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.709019146082187, "lm_q1q2_score": 0.609518048107489}}
{"text": "\\section{Gaussian Product Wavefunction}\r\n\\label{sec:ionwf}\r\n\r\nThe Gaussian Product wavefunction implements eq.~\\ref{eq:gauss_prod_wf}\r\n\\begin{equation}\r\n\\Psi(\\vec{R}) = \\prod_{i=1}^N \\exp\\left[ -\\frac{(\\vec{R}_i-\\vec{R}_i^o)^2}{2\\sigma_i^2} \\right]\r\n\\label{eq:gauss_prod_wf},\r\n\\end{equation}\r\nwhere $\\vec{R}_i$ is the position of the $i^{\\text{th}}$ quantum particle and $\\vec{R}_i^o$ is its center. $\\sigma_i$ is the width of the Gaussian orbital around center $i$.\r\n\r\nThis variational wavefunction enhances single-particle density at chosen spatial locations with adjustable strengths. It is useful whenever such localization is physically relevant yet not captured by other parts of the trial wavefunction. For example, in an electron-ion simulation of a solid, the ions are localized around their crystal lattice sites. This single-particle localization is not captured by the ion-ion Jastrow. Therefore the addition of this localization term will improve the wavefunction. The simplest use case of this wavefunction is perhaps the quantum harmonic oscillator (please see the ``tests/models/sho'' folder for examples).\r\n\r\n\\subsubsection{Input Specification}\r\n\r\n\\begin{table}[h]\r\n\\begin{center}\r\n\\begin{tabular}{l c c c l }\r\n\\hline\r\n\\multicolumn{5}{l}{Gaussian Product Wavefunction (ionwf)} \\\\\r\n\\hline\r\n\\bfseries name & \\bfseries datatype & \\bfseries values & \\bfseries defaults  & \\bfseries description \\\\\r\n\\hline\r\nname & text & ionwf & (required) & Unique name for this wavefunction \\\\\r\nwidth & floats & 1.0 -1 & (required) & Widths of Gaussian orbitals.\\\\ \r\nsource & text & ion0 & (required) & Name of classical particle set.\\\\ \r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{table}\r\n\r\n\\FloatBarrier\r\n\r\nAdditional information:\r\n\\begin{itemize}\r\n\\item \\texttt{width} There must be one width provided for each quantum particle. If a negative width is given, then its corresponding Gaussian orbital is removed. Negative width is useful if one wants to use Gaussian wavefunction for a subset of the quantum particles.\r\n\\item \\texttt{source} The Gaussian centers must be specified in the form of a classical particle set. This classical particle set is likely the ion positions ``ion0'', hence the name ``ionwf''. However, one may define arbitrary centers using a different particle set. Please refer to examples in `tests/models/sho'.\r\n\\end{itemize}\r\n\r\n\\subsection{Example Use Case}\r\n\\begin{lstlisting}\r\n  <qmcsystem>\r\n    <simulationcell>\r\n      <parameter name=\"bconds\">\r\n            n n n\r\n      </parameter>\r\n    </simulationcell>\r\n    <particleset name=\"e\">\r\n      <group name=\"u\" size=\"1\">\r\n        <parameter name=\"mass\">5.0</parameter>\r\n        <attrib name=\"position\" datatype=\"posArray\" condition=\"0\">\r\n          0.0001 -0.0001 0.0002\r\n        </attrib>\r\n      </group>\r\n    </particleset>\r\n    <particleset name=\"ion0\" size=\"1\">\r\n      <group name=\"H\">\r\n        <attrib name=\"position\" datatype=\"posArray\" condition=\"0\">\r\n          0 0 0\r\n        </attrib>\r\n      </group>\r\n    </particleset>\r\n    <wavefunction target=\"e\" id=\"psi0\">\r\n      <ionwf name=\"iwf\" source=\"ion0\" width=\"0.8165\"/>\r\n    </wavefunction>\r\n    <hamiltonian name=\"h0\" type=\"generic\" target=\"e\">\r\n      <extpot type=\"HarmonicExt\" mass=\"5.0\" energy=\"0.3\"/>\r\n      <estimator type=\"latticedeviation\" name=\"latdev\" \r\n        target=\"e\"    tgroup=\"u\" \r\n        source=\"ion0\" sgroup=\"H\"/>\r\n    </hamiltonian>\r\n  </qmcsystem>\r\n\\end{lstlisting}\r\n\r\n", "meta": {"hexsha": "139622ecdfd3b652ce661dba4d5c09fca75ca4cc", "size": 3420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/ionwf.tex", "max_stars_repo_name": "bwvdg/qmcpack", "max_stars_repo_head_hexsha": "cd09fc54b36de2579c9802f5e64b7ec15506f3c3", "max_stars_repo_licenses": ["NCSA"], "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/ionwf.tex", "max_issues_repo_name": "bwvdg/qmcpack", "max_issues_repo_head_hexsha": "cd09fc54b36de2579c9802f5e64b7ec15506f3c3", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-10T15:33:28.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-10T15:35:59.000Z", "max_forks_repo_path": "manual/ionwf.tex", "max_forks_repo_name": "bwvdg/qmcpack", "max_forks_repo_head_hexsha": "cd09fc54b36de2579c9802f5e64b7ec15506f3c3", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-23T17:44:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-23T17:44:39.000Z", "avg_line_length": 46.2162162162, "max_line_length": 653, "alphanum_fraction": 0.6912280702, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.6959583187272712, "lm_q1q2_score": 0.6095112422705197}}
{"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 \\textit{initial value problem} (IVP)\n\\begin{align}\n\t\\begin{split}\n\\x'(t) &= f(\\x(t),t),\\quad t_0 \\leq t \\leq t_f \\\\\n\\x(t_0) &= \\x_0, \n\t\\end{split}\n\t\\label{ivp:generic}\n\\end{align}\nwhere $f$ is a suitably continuous function.\nA solution of \\eqref{ivp:generic} is a continuously differentiable, and possibly vector-valued, function $\\x(t) = \\left[x_1(t),\\hdots,x_m(t)\\right]\\trp$, whose derivative $\\x'(t)$ equals $f(\\x(t),t)$ for all $t \\in [t_0,t_f]$, and for which the \\textit{initial value} $\\x(t_0)$ equals $\\x_0$.\n\nUnder the right conditions, namely that $f$ is uniformly Lipschitz continuous in $\\x(t)$ near $\\x_0$ and continuous in $t$ near $t_0$, \\eqref{ivp:generic} is well-known to have a unique solution.\n%[reference Volume 4 here].\nHowever, for many IVPs, it is difficult, if not impossible, to find a closed-form, analytic expression for $\\x(t)$.\nIn these cases, numerical methods can be used to instead \\textit{approximate} $\\x(t)$.\n\nAs an example, consider the initial value problem\n\\begin{align}\n\t\\begin{split}\nx'(t) &= \\sin(x(t)), \\\\\nx(0) &= x_0.\n\t\\end{split}\\label{ivp:example}\n\\end{align}\nThe solution $x(t)$ is defined implicitly by\n\\[t = \\ln \\left|\\frac{\\cos(x_0) + \\cot(x_0)}{\\csc(x(t)) + \\cot(x(t))} \\right|.\\]\nThis equation cannot be solved for $x(t)$, so it is difficult to understand what solutions to \\eqref{ivp:example} look like.\nSince $sin(n\\pi)=0$, there are constant solutions $x_n(t) = n \\pi,$ $n \\in \\mathbb{Z}$.\nUsing a numerical IVP solver, solutions for different values of $x_0$ can be approximated.\nFigure \\ref{ivp:int_curves} shows several of these approximate solutions, along with some of the constant, or \\textit{equilibrium}, solutions.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{example2.pdf}\n\\caption{Several solutions of \\eqref{ivp:example}, using \\li{scipy.integrate.odeint}. }\n\\label{ivp:int_curves}\n\\end{figure}\n\n\n\\section*{Numerical Methods}\nFor the numerical methods that follow, the key idea is to seek an approximation for the values of $\\x(t)$ only on a finite set of values $t_0 < t_1 < \\hdots < t_{n-1} < t_n \\ (= t_f)$.\nIn other words, these methods try to solve for $\\x_1,\\x_2,\\hdots,\\x_n$ such that $\\x_i \\approx \\x(t_i)$.\n\n\\subsection*{Euler's Method}\nFor simplicity, assume that each of the $n$ subintervals $[t_{i-1},t_i]$ has equal length $h = (t_f-t_0)/n$. $h$ is called the \\textit{step size}.\nAssuming $\\x(t)$ is twice-differentiable, for each component function $x_j(t)$ of $\\x(t)$ and for each $i$, Taylor's Theorem says that\n\\begin{align*}\nx_j(t_{i+1}) &= x_j(t_{i}) + h x'_j(t_i) + \\frac{h^2}{2} x''_j(c)\\text{ for some } c \\in [t_i,t_{i+1}].\n\\end{align*}\nThe quantity $\\frac{h^2}{2} x''_j(c)$ is negligible when $h$ is sufficiently small, and thus $x_j(t_{i+1}) \\approx x_j(t_i) + h x'_j(t_i)$.\nTherefore, bringing the component functions of $\\x(t)$ back together gives\n\\begin{align*}\n\\x(t_{i+1}) &\\approx \\x(t_i) + h \\x'(t_i)  ,\\\\\n&\\approx \\x(t_{i}) + h f(\\x(t_i),t_i).\n\\end{align*}\nThis approximation leads to the \\textit{Euler method}: Starting with $\\x_0 = \\x(t_0)$, $\\x_{i+1} = \\x_i +hf(\\x_i,t_i)$ for $i = 0, 1, \\hdots, n-1$.\nEuler's method can be understood as starting with the point at $\\x_0$, then calculating the derivative of $\\x(t)$ at $t_0$ using $f(\\x_0,t_0)$, followed by taking a step in the direction of the derivative scaled by $h$. Set that new point as $\\x_1$ and continue.\n\nIt is important to consider how the choice of step size $h$ affects the accuracy of the approximation. Note that at each step of the algorithm, the \\textit{local truncation error}, which comes from neglecting the $x''_j(c)$ term in the Taylor expansion, is proportional to $h^2$.\nThe error $||\\x(t_i)-\\x_i||$ at the \\textit{ith} step comes from $i = \\frac{t_i-t_0}{h}$ steps, which is proportional to $h^{-1}$, each contributing $h^2$ error.\nThus the \\textit{global truncation error} is proportional to $h$.\nTherefore, the Euler method is called a \\textit{first-order method}, or a $\\mathcal{O}(h)$ method.\nThis means that as $h$ gets small, the approximation of $\\x(t)$ improves in two ways.\nFirst, $\\x(t)$ is approximated at more values of $t$ (more information about the solution), and second, the accuracy of the approximation at any $t_i$ is improved proportional to $h$ (better information about the solution).\n\\begin{comment}\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\\end{comment}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=150mm]{euler.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\\begin{problem} Write a function which implements Euler's method for an IVP of the form \\eqref{ivp:generic}. Test your function on the IVP:\n\\begin{align}\n\t\\begin{split}\n\t\tx' (t)&= x(t) - 2t + 4,\\quad 0 \\leq t \\leq 2, \\\\\n\t\tx(0) &= 0,\n\t\\end{split}\\label{ivp:prob1}\n\\end{align}\nwhere the analytic solution is $x(t) = -2+2t + 2e^t.$\nUse the Euler method to numerically approximate the solution with step sizes $h = 0.2, 0.1$, and $0.05.$ Plot the true solution alongside the three approximations, and compare your results with Figure \\ref{ivp:euler}.\n\\end{problem}\n\n\n\n\\subsection*{Midpoint Method}\n\nThe midpoint method is very similar to Euler's method.\nFor small $h$, use the approximation\n\\begin{align*}\n\\x(t_{i+1}) &\\approx  \\x(t_{i}) + h f(\\x(t_{i})+\\frac{h}{2} f(\\x(t_i),t_i),t_{i}+\\frac{h}{2},).\n\\end{align*}\nIn this approximation, first set $\\hat \\x_i = \\x_i+\\frac{h}{2}f(\\x_i,t_i)$, which is an Euler method step of size $h/2$.\nThen evaluate $f(\\hat \\x_i,t_i+\\frac{h}{2})$, which is a more accurate approximation to the derivative $\\x'(t)$ in the interval $[t_i,t_{i+1}]$.\nFinally, a step is taken in that direction, scaled by $h$.\nIt can be shown that the local truncation error for the midpoint method is $\\mathcal{O}(h^3)$, giving global truncation error of $\\mathcal{O}(h^2)$.\nThis is a significant improvement over the Euler method.\nHowever, it comes at the cost of additional evaluations of $f$ and a handful of extra floating point operations on the side.\nThis tradeoff will be considered later in the lab.\n\n\\subsection*{Runge-Kutta Methods}\nThe Euler method and the midpoint method belong to a family called \\textit{Runge-Kutta methods}.\nThere are many Runge-Kutta methods with varying orders of accuracy.\nMethods of order four or higher are most commonly used.\nA fourth-order Runge-Kutta method (RK4) iterates as follows: \n\\begin{align*}\n\t\\begin{split}\nK_1 &= f(\\x_i,t_i), \\\\\nK_2 &= f(\\x_i + \\frac{h}{2} K_1,t_i + \\frac{h}{2}),\\\\\nK_3 &= f(\\x_i + \\frac{h}{2} K_2,t_i + \\frac{h}{2}),\\\\\nK_4 &= f(\\x_i + h K_3,t_{i+1}),\\\\\n\\x_{i+1} &= \\x_i + \\frac{h}{6}(K_1 + 2K_2 + 2K_3 + K_4).\n\t\\end{split}\n\\end{align*}\n\nRunge-Kutta methods can be understood as a generalization of quadrature methods for approximating integrals, where the integrand is evaluated at specific points, and then the resulting values are combined in a weighted sum.\nFor example, consider a differential equation \n$$x'(t) = f(t)$$\nSince the function $f$ has no $x$ dependence, this is a simple integration problem.\nIn this case, Euler's method corresponds to the left-hand rule, the midpoint method becomes the midpoint rule, and RK4 reduces to Simpson's rule.\n\n\\section*{Advantages of Higher-Order Methods}\nIt can be useful to visualize the order of accuracy of a numerical method.\nA method of order p has relative error of the form\n$$E(h) = Ch^p$$\ntaking the logarithm of both sides yields\n$$log(E(h)) =p \\cdot log(h) + log(C)$$\nTherefore, on a log-log plot against $h$, $E(h)$ is a line with slope $p$ and intercept $log(C)$.\n\n\\begin{problem} Write functions that implement the midpoint and fourth-order Runge-Kutta methods.\nUse the Euler, Midpoint, and RK4 methods to approximate the value of the solution for the IVP \\eqref{ivp:prob1} from Problem 1 for step sizes of $h = 0.2,$ $ 0.1,$ $0.05 $, $0.025,$ and $0.0125.$\n\nPlot the following graphs\n\\begin{itemize}\n\\item The true solution alongside the approximation obtained from each method when $h=0.2$.\n\\item A log-log plot (use \\li{plt.loglog}) of the relative error $|x(2)-x_n|/{|x(2)|}$ as a function of $h$ for each approximation.\n\\end{itemize}\n\nCompare your second plot with Figure \\ref{ivp:relative_error}.\n\\end{problem}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{prob2.pdf}\n\\caption{Loglog plot of the relative error in approximating $x(2)$, using step sizes $h = 0.2,$ $0.1,$ $0.05,$ $0.025,$ and $0.0125$.\nThe 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\nThe Euler, midpoint, and RK4 methods help illustrate the potential trade-off between order of accuracy and computational expense.\nTo increase the order of accuracy, more evaluations of $f$ must be performed at each step.\nIt is possible that this trade-off could make higher-order methods undesirable, as (in theory) one could use a lower-order method with a smaller step size $h$.\nHowever, this is not generally the case.\nAssuming efficiency is measured in terms of the number of $f$-evaluations required to reach a certain threshold of accuracy, higher-order methods turn out to be much more efficient.\nFor example, consider the IVP\n\n\\begin{align}\n\t\\begin{split}\n\t\tx'(t) &= x(t) \\cos(t), \\quad t \\in [0,8],\\\\\n\t\tx(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 applied to \\eqref{ivp:efficiency_problem}. \nThe higher-order RK4 method requires fewer $f$-evaluations to reach the same level of relative error as the lower-order methods.\nAs $h$ becomes small, which corresponds to increasing functional evaluations, each method reaches a point where the relative error $|x(8)-x_n|/{|x(8)|}$ stops improving.\nThis occurs when $h$ is so small that floating point round-off error overwhelms local truncation error. Notice that the higher-order methods are able to reach a better level of relative error before this phenomena occurs.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=\\textwidth]{Efficiency.pdf}\n\\caption{The relative error in computing the solution of \\eqref{ivp:efficiency_problem} at $x = 8$ versus the number of times the right-hand side of \\eqref{ivp:efficiency_problem} must be evaluated.  }\n\\label{ivp:efficiency_figure}\n\\end{figure}\n\n\\begin{comment}\nLet $t^*$ be an approximation of some value $t$.\nThe 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$.\nA 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\nh = 2./best_grid\nX, Y, h, n = initialize_all(a, b, ya, h)\n# Requires an implementation of the euler method\nbest_val = euler(ode_f, X, Y, h, n)[-1]  \n\nsmaller_grids = [10, 20, 40, 80]  # number of subintervals in smaller grids\nh = [2./N for N in smaller_grids]\n\nEuler_sol = [euler(ode_f, initialize_all(a, b, ya, h[i])[0],\n\t\t\tinitialize_all(a, b, ya, h[i])[1], h[i], N+1)[-1]\n\t\t\tfor i, N in enumerate(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\", linewidth=2.)\nplt.show()\n\n\\end{lstlisting}\n\\end{comment}\n\n\\section*{Harmonic Oscillators and Resonance}\nHarmonic oscillators are common in classical mechanics.\nA few examples include the pendulum (with small displacement), spring-mass systems, and the flow of electric current through various types of circuits.\nA harmonic oscillator $y(t)$\\footnote{It is customary to write $y$ instead of $y(t)$ when it is unambiguous that $y$ denotes the dependent variable.} is a solution to 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*}\nHere, $m$ represents the mass on the end of a spring, $\\gamma$ represents the effect of damping on the motion, $k$ is the spring constant, and $f(t)$ is the external force applied.\n\\begin{comment}\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\\end{comment}\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.\n\nTo solve this IVP using a Runge-Kutta method, it must be written in the form\n\\[\\x'(t) = f(\\x(t),t) \\]\nThis can be done by setting $x_1 = y \\ \\text{and} \\ x_2 = y'$. Then we have \\[     \\x'=\n \\left[\\begin{array}{c}x_1 \\\\x_2\\end{array}\\right]'  =  \\left[\\begin{array}{c}x_2 \\\\\\frac{-k}{m}x_1\\end{array}\\right]\\]\nTherefore$$f(\\x(t),t) = \\left[\\begin{array}{c}x_2 \\\\\\frac{-k}{m}x_1\\end{array}\\right]$$\n\n\\begin{problem} Use the RK4 method to solve 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$.\n\nPlot your numerical approximation of $y(t)$.  \nCompare this with the 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}[H]\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} \nA damped free harmonic oscillator $y(t)$ satisfies the IVP\n\\begin{align*}\n\t&{}my'' + \\gamma y' + ky = 0 ,\\\\\n\t&{}y(0) = y_0,\\quad\n\ty'(0) = y'_0.\n\\end{align*}\n\\begin{comment}\nFor fixed values of $m$ and $k$, it is interesting to study the effect of the damping coefficient $\\gamma$.\n\\end{comment}\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$.\n\\end{problem}\n\n\\section*{Forced harmonic oscillators without damping}\nConsider 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 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\nWhen $\\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 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.\nHowever, the fact that the equation predicts large oscillations suggests the spring-mass system could fall apart as a result of the external force. \nThis mechanical resonance has been known to cause failure of bridges, buildings, and airplanes.\n\n\\begin{problem}\nUse the RK4 method to solve 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(t)$: $(\\gamma, \\omega) = (0.5, 1.5),$ $(0.1, 1.1),$ and $(0, 1)$.\nCompare your results with Figure\\ref{ivp:damped_forced_oscillator}.\n\\end{problem}\n\n\n\\begin{figure}[H]\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": "a229989ec7c4beb98da87ffda47cba634e1bcac1", "size": 21216, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume4/IVP/IVP.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/IVP/IVP.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/IVP/IVP.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": 52.776119403, "max_line_length": 292, "alphanum_fraction": 0.7105015083, "num_tokens": 6635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.6095074908308307}}
{"text": "\\chapter{Simulation}\\label{S:RNG}\n\n\\begin{quote}\n``Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.'' --- John von Neumann (1951)\n\\end{quote}\n\n\\section{Physical Random Number Generators}\\label{S:PhysRNG}\nPhysical devices such as the BINGO machine demonstrated in class can be used to produce an integer uniformly at random from a finite set of possibilities.  Such ``ball bouncing machines'' used in the British national lottery as well as the New Zealand LOTTO are complex nonlinear systems that are extremely sensitive to initial conditions (``chaotic'' systems) and are physical approximations of the probability model called a ``well-stirred urn'' or an equi-probable $\\demoivre(1/k,\\ldots,1/k)$ random variable.  \n\nLet us look at the New Zealand LOTTO draws at \\url{http://lotto.nzpages.co.nz/statistics.html} and convince ourselves that all fourty numbers $\\{1,2,\\ldots,39,40\\}$ seem to be drawn uniformly at random.  The British lottery animation at \\url{http://understandinguncertainty.org/node/39} shows how often each of the $49$ numbers came up in the first $1240$ draws.  Are these draws really random?  We will answer these questions in the sequel (see \\url{http://understandinguncertainty.org/node/40} if you can't wait).\n\n\\section{Pseudo-Random Number Generators}\\label{S:RNGIntro}\nOur probability model and the elementary continuous $\\uniform(0,1)$ RV are built from the abstract concept of a random variable over a probability triple.  A direct implementation of these ideas on a computing machine is not possible. In practice, random variables are typically simulated by {\\bf deterministic} methods or algorithms.  Such algorithms generate sequences of numbers \nwhose behavior is virtually indistinguishable from that of truly random \nsequences.  In computational statistics, simulating realisations from a given RV is usually done in two distinct steps.  First, sequences of numbers that imitate  independent and identically distributed (IID) $\\uniform(0,1)$ RVs are generated.  Second, appropriate transformations are made to these imitations of IID $\\uniform(0,1)$ random variates in order to imitate IID random variates from other random variables or other random structures.  These two steps are essentially independent and are studied by two non-overlapping groups of researchers.  The formal term {\\bf pseudo-random number generator} (PRNG) or simply {\\bf random number generator} (RNG) usually\nrefers to some deterministic algorithm used in the first step to produce pseudo-random numbers (PRNs) that imitate IID $\\uniform(0,1)$ random variates.\n\nIn the following chapters, we focus on transforming IID $\\uniform(0,1)$ variates to other non-uniform variates.  In this chapter, we focus on the art of imitating IID $\\uniform(0,1)$ variates using simple deterministic rules.  \n\n\\subsection{Linear Congruential Generators}\\label{S:RNGs}\n\nThe following procedure introduced by D.~H.~Lehmer in 1949 [{\\em Proc.~2nd Symp.~on Large-Scale Digital Calculating Machinery, Harvard Univ.~Press, Cambridge, Mass., 1951, 141--146}] gives the simplest popular PRNG that can be useful in many statistical situations if used wisely.\n\n\\begin{algorithm}[htpb]\n\\caption{Linear Congruential Generator (LCG)}\n\\label{AL:LCG}\n\\begin{algorithmic}[1]\n\\STATE{ {\\it input:} five {\\em suitable} integers:\n\\begin{enumerate}\n\\item $m$, the modulus; $0 < m$\n\\item $a$, the multiplier; $0 \\leq a < m$\n\\item $c$, the increment; $0 \\leq c < m$\n\\item $x_0$, the seed; $0 \\leq x_0 < m$\n\\item $n$, the number of desired pseudo-random numbers\n\\end{enumerate}\n}\n\\STATE {{\\it output:} $(x_0,x_1,\\ldots,x_{n-1})$, the linear congruential sequence of length $n$}\n\\FOR{$i=1$ to $n-1$}\n\\STATE $x_i \\gets (a x_{i-1} + c) \\mod m$\n\\ENDFOR\n\\STATE{{\\it return:}  $(x_1,x_2,\\ldots,x_n)$}\n\\end{algorithmic}\n\\end{algorithm}\n\nIn order to implement LCGs we need to be able to do high precision exact integer arithmetic in {\\sc Matlab}.  We employ the Module {\\tt vpi} to implement variable precision integer arithmetic.  You need to download this module for the next Labwork.\n\n\\begin{labwork}[Generic Linear Congruential Sequence]\\label{LW:GenericLCGS}\nLet us implement Algorithm~\\ref{AL:LCG} in {\\sc Matlab} as follows.\n\\VrbMf[label=LinConGen.m]{scripts/LinConGen.m}\nWe can call it for some arbitrary input arguments as follows:\n\\begin{VrbM}\n>> LinConGen(13,12,11,10,12)\nans =    10     1    10     1    10     1    10     1    10     1    10     1\n>> LinConGen(13,10,9,8,12)\nans =     8    11     2     3     0     9     8    11     2     3     0     9\n\\end{VrbM}\nand observe that the generated sequences are not ``random'' for input values of $(m,a,c,x_0,n)$ equalling $(13,12,11,10,12)$ or $(13,10,9,8,12)$.  Thus, we need to do some work to determine the {\\em suitable} input integers $(m,a,c,x_0,n)$.\n\\end{labwork}\n\n\\begin{labwork}[LCG with period length of $32$]\\label{LW:LinConGenKnuth334T1L5}\nConsider the linear congruential sequence with $(m,a,c,x_0,n)=(256,137,0,123,257)$ with period length of only $32 < m=256$.  We can visualise the sequence as plots in Figure~\\ref{F:LinConGenKnuth334T1L5Plots} after calling the following M-file.\n\\VrbMf[label=LinConGenKnuth334T1L5Plots.m]{scripts/LinConGenKnuth334T1L5Plots.m}\n\\end{labwork}\n\n\\begin{figure}[htbp]\n\\caption{The linear congruential sequence of {\\tt LinConGen(256,137,0,123,257)} with non-maximal period length of $32$ as a line plot over $\\{0,1,\\ldots,256\\}$, scaled over $[0,1]$ by a division by $256$ and a histogram of the $256$ points in $[0,1]$ with $15$ bins.\\label{F:LinConGenKnuth334T1L5Plots}}\n\\centering   \\makebox{\\includegraphics[width=7.0in]{figures/LinConGenKnuth334T1L5Plots}}\n\\end{figure}\n\n\n\\subsubsection*{Choosing the {\\em suitable} magic input $(m,a,c,x_0,n)$}\n\nThe linear congruential  generator is a special case of a {\\em discrete dynamical system}: \n\\[\nx_{i}  = f(x_{i-1}), \\ f: \\{0,1,2,\\ldots,m-1\\} \\to \\{0,1,2,\\ldots,m-1\\} \\ \\text{and} \\ f(x_{i-1})=(a x_{i-1} + c) \\mod m\\enspace .\n\\]  \nSince $f$ maps a the finite set $\\{1,2,\\ldots,m-1\\}$ into itself, such systems are bound to have a repeating cycle of numbers called the {\\bf period}.  In Labwork~\\ref{LW:GenericLCGS}, the generator {\\tt LinConGen(13,12,11,10,12)} has period $(10,1)$ of length $2$, the generator {\\tt LinConGen (13,10,9,8,12)} has period $(8, 11, 2, 3, 0, 9)$ of length $6$ and the generator {\\tt LinConGen(256,137,0,123,257)} has a period of length $32$.  All these generators have a non-maximal period length less than their modulus $m$.  A good generator should have a maximal period of $m$.  Let us try to implement a generator with a maximal period of $m=256$.\n\n\nThe period of a general LCG is at most $m$, and for some choices of $a$ the period can be much less than $m$ as shown in the examples considered earlier.  The LCG will have a full period if and only if:\n\\begin{enumerate}\n\\item $c$ and $m$  are relatively prime,\n\\item  $a-1$ is divisible by all prime factors of $m$,\n\\item  $a-1$ is a multiple of $4$ if  $m$ is a multiple of $4$\n\\end{enumerate}\n\n\\begin{labwork}[LCG with maximal period length of $256$]\nConsider the linear congruential sequence with $(m,a,c,x_0,n)= (256,137,123,13,256)$.  First check that these parameters do indeed satisfy the three condition above and therefore can produce the maximal period length of only $m=256$.  Modify the input parameter to {\\tt LinConGen} and repeat Labwork~\\ref{LW:LinConGenKnuth334T1L5} in order to first produce a sequence of length $257$.  Do you see that the period is of maximal length of $256$ as opposed to the generator of Labwork~\\ref{LW:LinConGenKnuth334T1L5}?  Next produce a Figure to visualise the sequence as done in Figure~\\ref{F:LinConGenKnuth334T1L5Plots}.\n\\end{labwork}\n\nA useful sequence should clearly have a relatively long period, say at least $2^{30}$.  Therefore, the {\\bf modulus $m$ has to be rather large} because the {\\bf period} cannot have more than $m$ elements.  Moreover, the quality of pseudo-random numbers of a LCG is extremely sensitive to the choice of $m$, $a$ and $c$ even if the maximal period is attained.  The next example illustrates this point.\n\n\\begin{labwork}[The infamous {\\tt RANDU}]\\label{LW:RANDU}\n{\\tt RANDU} is an infamous LCG, which has been used since the 1960s.  It is widely considered to be one of the most ill-conceived random number generators designed. Notably, it fails the {\\bf spectral test} badly for dimensions greater than 2.  The following commands help visualise the sequence of first $5001/3$ triplets $(x_i,x_{i+1},x_{i+2})$ seeded from $x_0=1$ (Figure~\\ref{F:RANDU3D5001pts}).  Read {\\tt help reshape} and {\\tt help plot3}. \n\\begin{VrbM}\n>> x=reshape( (LinConGen(2147483648,65539,0,1,5001)./ 2147483648) ,3,[]);\n>> plot3(x(1,:),x(2,:),x(3,:),'.')\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{figure}[htbp]\n\\caption{The LCG called {\\tt RANDU} with $(m,a,c)=(2147483648,65539,0)$ has strong correlation between three consecutive points as: $x_{i+2}=6x_{k+1}-9x_k$.  The two plots are showing $(x_i,x_{i+1},x_{i+2})$ from two different view points.\n.\\label{F:RANDU3D5001pts}}\n\\centering   \\makebox{\\includegraphics[width=7.0in]{figures/RANDU3D5001pts}}\n\\end{figure}\n\n\\begin{labwork}[Fishman20 and Lecuyer21 LCGs]\nThe following two LCGs are recommended in Knuth's Art of Computer Programming, vol.~2, for generating pseudo-random numbers for simple simulation tasks.\n\\begin{VrbM}\n>> LinConGen(2147483647,48271,0,08787458,10) ./ 2147483647\nans =    0.0041    0.5239    0.0755    0.7624    0.6496    0.0769    0.9030    0.4259    0.9948    0.8868\n\n>> LinConGen(2147483399,40692,0,01234567,10) ./ 2147483399\nans =    0.0006    0.3934    0.4117    0.7893    0.3913    0.6942    0.6790    0.3337    0.2192    0.1883\n\\end{VrbM}\n\\end{labwork}\n\nThe number of random numbers $n$ should at most be about $m/1000$ in order to avoid the future sequence from behaving like the past.  Thus, if $m=2^{32}$ then a new generator, with a new suitable set of $(m,a,c,x_0,n)$ should be adopted after the consumption of every few million pseudo-random numbers.\n\nThe LCGs are the least sophisticated type of PRNGs.  They are easier to understand but are not recommended for intensive simulation purposes.  The next section briefly introduces a more sophisticated PRNG we will be using in this course.  Moreover our implementation of LCGs using the variable precision integer package is extremely slow in {\\sc MATLAB} and is only of pedagogical interest. \n\n\\subsection{Generalized Feedback Shift Register  and the``Mersenne Twister'' PRNG} \n\nThe following generator termed {\\tt twister} in {\\sc Matlab} is recommended for use in simulation.  It has extremely long periods, low correlation and passes most statistical tests (the {\\sc diehard} statistical tests).  The {\\tt twister} random number generator of Makoto Matsumoto and Takuji Nishimura is a variant of the twisted generalized feedback shift-register algorithm, and is known as the ``Mersenne Twister'' generator [Makoto Matsumoto and Takuji Nishimura, {\\em Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator}, ACM Transactions on Modeling and Computer\nSimulation, Vol.~8, No.~1 (Jan.~1998), Pages 3--30].  It has a Mersenne prime period of $2^{19937} - 1$ (about $10^{6000}$) and is {\\bf equi-distributed} in $623$ dimensions.  It uses $624$ words of state per generator and is comparable in speed to the other generators.  The recommended default seed is $5489$.  See \\url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html} and \\url{http://en.wikipedia.org/wiki/Mersenne_twister} for details.  \n\nLet us learn to implement the {\\sc Matlab} function that generates PRNs.  In {\\sc Matlab} the function {\\tt rand} produces a deterministic PRN sequence.  First, read {\\tt help rand}.  We can generate PRNs as follows.\n\\begin{labwork}[Calling PRNG in {\\sc Matlab}]\\label{LW:RNGMatlab}\nIn {\\sc Matlab} {\\tt rand} is basic PRNG command.\n\\begin{VrbM}\n>> rand(1,10) % generate a 1 X 10 array of PRNs\nans =\n    0.8147    0.9058    0.1270    0.9134    0.6324    0.0975    0.2785    0.5469    0.9575    0.9649\n>> rand(1,10) % generate another 1 X 10 array of PRNs\nans =\n    0.1576    0.9706    0.9572    0.4854    0.8003    0.1419    0.4218    0.9157    0.7922    0.9595\n>> rand('twister',5489) % reset the PRNG to default state Mersenne Twister with seed=5489\n>> rand(1,10) % reproduce the first array\nans =\n    0.8147    0.9058    0.1270    0.9134    0.6324    0.0975    0.2785    0.5469    0.9575    0.9649\n>> rand(1,10) % reproduce the second array\nans =\n    0.1576    0.9706    0.9572    0.4854    0.8003    0.1419    0.4218    0.9157    0.7922    0.9595\n\\end{VrbM}  \nIn general, you can use any seed value to initiate your PRNG.  You may use the {\\tt clock} command to set the seed:\n\\begin{VrbM}\n>> SeedFromClock=sum(100*clock); % save the seed from clock\n>> rand('twister',SeedFromClock) % initialize the PRNG\n>> rand(1,10)\nans =\n    0.3696    0.3974    0.6428    0.6651    0.6961    0.7311    0.8982    0.6656    0.6991    0.8606\n>> rand(2,10)\nans =\n    0.3432    0.9511    0.3477    0.1007    0.8880    0.0853    0.6067    0.6976    0.4756    0.1523\n    0.5827    0.5685    0.0125    0.1555    0.5551    0.8994    0.2502    0.5955    0.5960    0.5700\n>> rand('twister',SeedFromClock) % initialize the PRNG to same SeedFromClock\n>> rand(1,10)\nans =\n    0.3696    0.3974    0.6428    0.6651    0.6961    0.7311    0.8982    0.6656    0.6991    0.8606\n\\end{VrbM}\n\\end{labwork}\n \n\\begin{figure}[htbp]\n\\caption{Triplet point clouds from the ``Mersenne Twister'' with two different seeds (see Labwork~\\ref{LW:3DPlotsMersenneTwister}).\n.\\label{F:MersenneTwisterTwo3DPtclouds}}\n\\centering   \\makebox{\\includegraphics[width=6.0in]{figures/MersenneTwisterTwo3DPtclouds}}\n\\end{figure}\n\\begin{labwork}[3D plots of triplets generated by the ``Mersenne Twister'']\\label{LW:3DPlotsMersenneTwister}\nTry to find any correlation between triplets generated by the ``Mersenne Twister'' by rotating the 3D plot generated by the following code:\n\\begin{VrbM}\n>> rand('twister',1234)\n>> x=rand(3,2000); % store PRNs in a 3X2000 matrix named x\n>> plot3(x(1,:),x(2,:),x(3,:),'.')\n\\end{VrbM}\nCompare this with the 3D plot of triplets from {\\tt RANDU} of Labwork~\\ref{LW:RANDU}. Which of these two PRNGs do you think is ``more random'' looking? and why? \n\nChange the seed value to the recommended default by the authors and look at the point cloud (in red) relative to the previous point cloud (in blue).  Rotate the plots to visualise from multiple angles.  Are they still random looking?\n\\begin{VrbM}\n>> rand('twister',1234)% same seed as before\n>> x=rand(3,2000); % store PRNs in a 3X2000 matrix named x\n>> rand('twister',5489)% the recommended default seed\n>> y=rand(3,2000);% store PRNs seeded by 5489 in a 3X2000 matrix named y\n>> plot3(x(1,:),x(2,:),x(3,:),'b.') % plot triplets as blue dots\n>> hold on;\n>> plot3(y(1,:),y(2,:),y(3,:),'r.') % plot triplets as red dots\n\\end{VrbM}\n\\end{labwork}\n\n\\section{Simulation of non-$\\uniform(0,1)$ Random Variables}\\label{S:nonUniformRVG}\n\n%\\remove{\nThe $\\uniform(0,1)$ RV of \\hyperref[M:Uniform01]{Model \\ref*{M:Uniform01}} forms the foundation for random variate generation and simulation.  This is appropriately called the fundamental model or experiment, since every other experiment can be obtained from this one.\n\nNext, we simulate or generate samples from other RVs by making the following two assumptions:\n\\begin{enumerate}\n\\item independent samples from the $\\uniform(0,1)$ RV can be generated, and\n\\item real arithmetic can be performed exactly in a computer.\n\\end{enumerate}\nBoth these assumptions are, in fact, not true and require a more careful treatment of the subject.  We may return to these careful treatments later on.\n\n\\subsection{Inversion Sampler for Continuous Random Variables}\\label{S:InvS}\n\\begin{prop}[Inversion sampler]\\label{P:InvS}\nLet $F(x) := \\int_{- \\infty}^{x} f(y) \\,d y : \\Rz \\rightarrow [0,1]$ be a continuous DF with density $f$, and let its inverse $F^{[-1]} : [0,1] \\rightarrow \\Rz $ be:\n\\[\nF^{[-1]}(u) :=  \\inf \\{ x :  F(x) = u \\} \\ .\n\\]\nThen, $F^{[-1]}(U)$ has the distribution function $F$, provided $U$ is a $\\uniform(0,1)$ RV.  Recall $\\inf(A)$ or infimum of a set $A$ of real numbers is the greatest lower bound of every element of $A$.\n\\end{prop}\n\\begin{proof}\nThe ``one-line proof'' of the proposition is due to the following equalities:\n\\[\n\\P(F^{[-1]}(U) \\leq x) = \\P(\\inf \\{ y :  F(y) = U)\\} \\leq x ) = \\P(U \\leq F(x)) = F(x), \\quad for~all~x \\in \\Rz .\n\\]\n\\end{proof}\n\nThis yields the inversion sampler or the inverse (C)DF sampler, where we (i) {\\it generate} $u \\sim \\uniform(0,1)$ and (ii) {\\it return} $x = F^{[-1]}(u)$, as formalised by the following algorithm.\n\n\\begin{algorithm}\n\\caption{Inversion Sampler or Inverse (C)DF Sampler}\n\\label{A:InvS}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n(1) $F^{[-1]}(x)$, inverse of the DF of the target RV $X$,\n(2) the fundamental sampler\n}\n\\STATE {\\it initialise:} set the seed, if any, for the fundamental sampler\n\\STATE {\\it output:} a sample from $X$ distributed according to $F$\n\\STATE {{\\it draw} $u \\sim \\uniform(0,1)$}\n\\STATE {\\it return:} $x = F^{[-1]}(u)$\n\\end{algorithmic}\n\\end{algorithm}\nThis algorithm emphasises the fundamental sampler's availability in an {\\it input} step, and its set-up needs in an {\\it initialise} step.  In the following sections, we will not mention these universal steps; they will be taken for granted.  The direct applicability of \\hyperref[A:InvS]{Algorithm \\ref*{A:InvS}} is limited to univariate densities for which the inverse of the cumulative distribution function is explicitly known.  The next section will consider some examples.\n\n%\\section{Some Simulations of Continuous Random Variables}\\label{S:InvSContinuousRVs}\n%}%end remove\n%\\section{Continuous Random Variables}\n\nRecall the $\\uniform(\\theta_1,\\theta_2)$ RV of \\hyperref[M:Uniformab]{Model \\ref*{M:Uniformab}} with the following PDF, DFand inverse DF. Let us simulate from it using the inversion sampler.\n\n\\begin{figure}[htpb]\n\\caption{A plot of the PDF, DF or CDF and inverse DF of the $\\uniform(-1,1)$ RV $X$.\\label{F:unifpm1}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/Unifpm1pdfcdf}}\n\\end{figure}\n\n\\begin{simulation}[$\\uniform(\\theta_1,\\theta_2)$]\\label{SIM:Uniformab}\nTo simulate from $\\uniform(\\theta_1,\\theta_2)$ RV $X$ using the Inversion Sampler, we first need to find $F^{[-1]}(u)$ by solving for $x$ in terms of $u=F(x;\\theta_1,\\theta_2)$:\n\\[\nu = \\frac{x-\\theta_1}{\\theta_2-\\theta_1} \\quad \\iff  \\quad x = (\\theta_2-\\theta_1)u+\\theta_1 \\quad  \\iff \\quad  F^{[-1]}(u;\\theta_1,\\theta_2) = \\theta_1+(\\theta_2-\\theta_1)u\n\\]\nHere is a simple implementation of the Inversion Sampler for the $\\uniform(\\theta_1,\\theta_2)$ RV in \\Matlab:\n\\begin{VrbM}\n>> rand('twister',786); % initialise the fundamental sampler for Uniform(0,1)\n>> theta1=-1; theta2=1; % declare values for parameters theta1 and theta2\n>> u=rand; % rand is the Fundamental Sampler and u is a sample from it\n>> x=theta1+(theta2 - theta1)*u; % sample from Uniform(-1,1]) RV\n>> disp(x); % display the sample from Uniform[-1,,1] RV\n    0.5134\n\\end{VrbM}\nIt is just as easy to draw $n$ IID samples from $\\uniform(\\theta_1,\\theta_2)$ RV $X$ by transforming $n$ IID samples from the $\\uniform(0,1)$ RV as follows:\n\\begin{VrbM}\n>> rand('twister',786543); % initialise the fundamental sampler\n>> theta1=-83; theta2=1004; % declare values for parameters a and b\n>> u=rand(1,5); % now u is an array of 5 samples from Uniform(0,1)\n>> x=theta1+(theta2 - theta1)*u; % x is an array of 5 samples from Uniform(-83,1004]) RV\n>> disp(x); % display the 5 samples just drawn from Uniform(-83,1004) RV\n  465.3065  111.4994   14.3535  724.8881  254.0168\n\\end{VrbM}\n%Next, we write a \\Matlab function for this sampler which would take the appropriate inputs and return $n$ IID samples from a specified $Uniform(\\theta_1,\\theta_2)$ RV $X$.\n%\\VrbMf[label=UniformabSam.m]{UniformabSam.m}\n\\end{simulation}\n\n%\\remove{\n\\begin{labwork}[Inversion Sampler Demo -- $\\uniform(-5,5)$]\\label{LW:guiInversionSamplerUniform}\nLet us comprehend the inversion sampler by calling the interactive visual cognitive tool built by Jennifer Harlow under a grant from University of Canterbury's Centre for Teaching and Learning (UCTL):\n\\begin{VrbM}\n>> guiInversionSampler\n\\end{VrbM}\nThe M-file {\\tt guiInversionSampler.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiInversionSamplerUniform]{Figure \\ref*{F:guiInversionSamplerUniform}}.  The default target distribution is $\\uniform(-5,5)$.  Now repeatedly push the ``Draw one sample'' button several times and comprehend the simulation process.  You can press ``Draw 100 samples'' to really comprehend the inversion sampler in action after 100 samples are drawn and depicted in the density histogram of the accumulating samples.  \nNext try changing the numbers in the ``Lower bound'' and ``Upper bound'' boxes in order to alter the parameters $\\theta_1$ and $\\theta_2$ of $\\uniform(\\theta_1,\\theta_2)$ RV.  \n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Inversion Sampling from $X \\sim \\uniform(-5,5)$.\\label{F:guiInversionSamplerUniform}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiInversionSamplerUniform}}\n\\end{figure}\n\n%}%end remove\n\nRecall the $\\exponential(\\lambda)$ RV of \\hyperref[M:exponential]{Model \\ref*{M:exponential}}. Let us simulate from it using the inversion sampler.\n\n\\begin{figure}[htpb]\n\\caption{The PDF $f$, DF $F$, and inverse DF $F^{[-1]}$ of the the $\\exponential(\\lambda=1.0)$ RV. \\label{F:ExpfFFInv}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/plotExpfFFInv}}\n\\end{figure}\n\nLet us consider the problem of simulating from an $\\exponential(\\lambda)$ RV with realisations in $\\Rz_+ := [0,\\infty) := \\{x: x \\geq 0, x \\in \\Rz\\}$ to model the waiting time for a bus at a bus stop.\n\\begin{simulation}[$\\exponential(\\lambda)$]\\label{SIM:Exponential}\nFor a given $\\lambda > 0$, an $\\exponential(\\lambda)$ RV has the following PDF $f$, DF $F$ and inverse DF $F^{[-1]}$:\n\\begin{eqnarray}\nf(x; \\lambda) = \\lambda e^{-\\lambda x} \\quad &\nF(x; \\lambda)= 1-e^{-\\lambda x} \\quad &\nF^{[-1]}(u; \\lambda)= \\frac{-1}{\\lambda} \\log_e (1-u)\n\\end{eqnarray}\nWe write the natural logarithm $\\log_e$ as $\\log$ for notational simplicity.  An implementation of the Inversion Sampler for $\\exponential(\\lambda)$ as a function in the M-file:\n\\VrbMf[label=ExpInvCDF.m]{scripts/ExpInvCDF.m}\nWe can simply call the function to draw a sample from, say the $\\exponential(\\lambda=1.0)$ RV by:\n\\begin{VrbM}\n  lambda=1.0;\t\t\t% some value for lambda\n  u=rand;\t\t\t% rand is the Fundamental Sampler\n  ExpInvCDF(u,lambda)\t% sample from Exponential(1) RV via function in ExpInvCDF.m\n\\end{VrbM}\nBecause of the following (recall \\hyperref[Ex:1-UisU]{Example \\ref*{Ex:1-UisU}}):\n\\[\n U \\sim \\uniform(0,1) \\quad \\implies \\quad\n -U \\sim \\uniform(-1,0) \\quad \\implies \\quad\n 1-U \\sim \\uniform(0,1)  \\  ,\n \\]\n we could save a subtraction operation in the above algorithm by replacing {\\tt -(1/lambda) * log(1-u)} by {\\tt -(1/lambda) * log(u)}. \nRecall that the transformation of $U \\sim \\uniform(0,1)$ by $X=-(1/\\lambda) \\log(U)$ is exactly how we defined $X$ as the $\\exponential(\\lambda)$ RV in \\hyperref[M:exponential]{Model \\ref*{M:exponential}}. \nThis is implemented as the following function.\n \\VrbMf[label=ExpInvSam.m]{scripts/ExpInvSam.m}\n\\begin{VrbM}\n>> rand('twister',46678); % initialise the fundamental sampler\n>> Lambda=1.0;  % declare Lambda=1.0\n>> x=ExpInvSam(rand(1,5),Lambda); % pass an array of 5 Uniform(0,1) samles from rand\n>> disp(x); % display the Exponential(1.0) distributed samples\n    0.5945    2.5956    0.9441    1.9015    1.3973\n\\end{VrbM}\n % Get a concrete understanding by implementing this simulation in Lab.\n\\end{simulation}\n\n%\\remove{\n\\begin{labwork}[Inversion Sampler Demo -- $\\exponential(0.5)$]\\label{LW:guiInversionSamplerExponential}\nLet us understand the inversion sampler by calling the interactive visual cognitive tool:\n\\begin{VrbM}\n>> guiInversionSampler\n\\end{VrbM}\nThe M-file {\\tt guiInversionSampler.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiInversionSamplerExponential]{Figure \\ref*{F:guiInversionSamplerExponential}}.  First change the target distribution from the default $\\uniform(-5,5)$ to $\\exponential(0.5)$ from the drop-down menu.  Now push the ``Draw 10 samples'' button and comprehend the simulation process.  Next try changing the ``Rate Parameter'' from $0.5$ to $10.0$ for example  and generate several inversion samples and see the density histogram of the accumulating samples.  You can press ``Draw one sample'' to really comprehend the inversion sampler in action one step at a time.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Inversion Sampling from $X \\sim \\exponential(0.5)$.\\label{F:guiInversionSamplerExponential}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiInversionSamplerExponential}}\n\\end{figure}\nIt is straightforward to do replicate experiments.  Consider the experiment of drawing five  independent samples from the $\\exponential(\\lambda=1.0)$ RV.  Suppose we want to repeat or replicate this experiment seven times and find the sum of the five outcomes in each of these replicates.  Then we may do the following:\n\n\\begin{VrbM}\n>> rand('twister',1973); % initialise the fundamental sampler\n>> % store 7 replications of 5 IID draws from Exponential(1.0) RV in array a\n>> lambda=1.0; a= -1/lambda * log(rand(5,7)); disp(a);\n    0.7267    0.3226    1.2649    0.4786    0.3774    0.0394    1.8210\n    1.2698    0.4401    1.6745    1.4571    0.1786    0.4738    3.3690\n    0.4204    0.1219    2.2182    3.6692    0.9654    0.0093    1.7126\n    2.1427    0.1281    0.8500    1.4065    0.1160    0.1324    0.2635\n    0.6620    1.1729    0.6301    0.6375    0.3793    0.6525    0.8330\n>> %sum up the outcomes of the sequence of 5 draws in each replicate\n>> s=sum(a); disp(s);\n    5.2216    2.1856    6.6378    7.6490    2.0168    1.3073    7.9990\n\\end{VrbM}\n\n\\begin{labwork}[Next seven buses at your bus-stop]\\label{LW:Next7Buses}\nConsider the problem of modelling the arrival of buses at a bus stop.  Suppose that the time between arrivals is an $\\exponential(\\lambda=0.1)$ RV $X$ with a mean inter-arrival time of $1/\\lambda=10$ minutes.  Suppose you go to your bus stop and zero a stop-watch.  Simulate the times of arrival for the next seven buses as indicated by your stop-watch.  Seed the fundamental sampler by your Student ID (eg.~if your ID is {\\tt 11424620} then type {\\tt rand('twister', 11424620);} just before the simulation).  Hand in the code with the arrival times of the next seven buses at your ID-seeded bus stop.\n\\end{labwork}\n\nThe support of the $\\exponential(\\lambda)$ RV is $\\Rz_+ := [0,\\infty)$.  Let us consider a RV built by mirroring the $\\exponential(\\lambda)$ RV about the origin with the entire real line as its support.\n\\begin{model}[$\\laplace(\\lambda)$ or $\\doubleexponential(\\lambda)$ RV]\nIf a RV $X$ is equally likely to be either positive or negative with an exponential density, then the $\\laplace(\\lambda)$ or $\\doubleexponential(\\lambda)$ RV, with the rate parameter $\\lambda>0, \\lambda \\in \\Rz$, may be used to model it.  The density function for the $\\laplace(\\lambda)$ RV given by $f(x; \\lambda)$ is\n\\begin{equation}\\label{E:Laplacepdf}\nf(x; \\lambda) = \\frac{\\lambda}{2} e^{- \\lambda |x|} =\n\\begin{cases}\n \\frac{\\lambda}{2} e^{ \\lambda x} & \\text{if $x < 0$} \\\\\n \\frac{\\lambda}{2} e^{- \\lambda x} & \\text{if $x \\geq 0$} \\\\\n\\end{cases}\n\\enspace .\n\\end{equation}\nLet us define the sign of a real number $x$ by\n\\[\n\\sign(x) =\n\\begin{cases}\n~~1 & \\text{if $x > 0$} \\\\\n~~0 & \\text{if $x = 0$} \\\\\n-1 & \\text{if $x < 0$}  \\ . \\\\\n\\end{cases}\n\\]\nThen, the DF of the $\\laplace(\\lambda)$ RV $X$ is\n\\begin{equation} \\label{E:Laplacecdf}\nF(x; \\lambda) = \\int_{-\\infty}^{x} f(y; \\lambda)\\,dy = \\frac{1}{2}\\left(1+ \\sign(x) \\left(1-e^{- \\lambda |x|}\\right) \\right) \\ ,\n\\end{equation}\nand its inverse DF is\n\\begin{equation}\\label{E:LaplaceInvcdf}\nF^{[-1]}(u;\\lambda) = - \\frac{1}{\\lambda} \\ \\sign\\left(u-\\frac{1}{2}\\right) \\log \\left(1 - 2 \\left|u-\\frac{1}{2} \\right| \\right) \\ , \\ u \\in [0,1]\n\\end{equation}\n\\end{model}\n\n\\paragraph{Mean and Variance of $\\laplace(\\lambda)$ RV $X$:}\nShow that the mean of a $\\laplace(\\lambda)$ RV $X$ is\n\\[\n\\E(X) = \\int_{0}^{\\infty} x f(x;\\lambda)\\,dx\n=   \\int_{0}^{\\infty} x \\frac{\\lambda}{2} e^{- \\lambda |x|}\\,dx\n= 0 \\ ,\n\\]\nand the variance is\n\\[\n\\V(X) = \\left(  \\frac{1}{\\lambda} \\right)^2 + \\left(  \\frac{1}{\\lambda} \\right)^2 = 2 \\left(  \\frac{1}{\\lambda} \\right)^2\\ .\n\\]\nNote that the mean is $0$ due to the symmetry of the density about $0$ and the variance is twice that of the $\\exponential(\\lambda)$ RV.\n\n\\begin{labwork}[Rejection Sampler Demo -- $\\laplace(5)$]\\label{LW:guiInversionSamplerLaplace}\nLet us comprehend the rejection sampler by calling the interactive visual cognitive tool:\n\\begin{VrbM}\n>> guiInversionSampler\n\\end{VrbM}\nThe M-file {\\tt guiInversionSampler.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiInversionSamplerLaplace]{Figure \\ref*{F:guiInversionSamplerLaplace}}.  Using the drop-down menu change from the default target distribution $\\uniform(-5,5)$ to $\\laplace(5)$.  Now repeatedly push the ``Draw one sample'' button several times and comprehend the simulation process.  You can also press ``Draw 1000 samples'' and see the density histogram of the generated samples.  \nNext try changing the numbers in the ``Rate parameter'' box from $5.00$ to $1.00$ in order to alter the parameter $\\lambda$ of $\\laplace(\\lambda)$ RV.  If you are more adventurous then try to alter the number in the ``Location parameter'' box from $0.00$ to some thing else, say $10.00$.  Although our formulation of $\\laplace(\\lambda)$ implicitly had a location parameter of $0.00$, we can easily introduce a location parameter $\\mu$ into the PDF.  With a pencil and paper try to rewrite the PDF in \\eqref{E:Laplacepdf} with an additional location parameter $\\mu$.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Inversion Sampling from $X \\sim \\laplace(5)$.\\label{F:guiInversionSamplerLaplace}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiInversionSamplerLaplace}}\n\\end{figure}\n\n\\begin{simulation}[$\\laplace(\\lambda)$] \\label{SIM:Laplace}\nHere is an implementation of an inversion sampler to draw IID samples from a $\\laplace(\\lambda)$ RV $X$ by transforming IID samples from the $\\uniform(0,1)$ RV $U$:\n\\VrbMf[label=LaplaceInvCDF.m]{scripts/LaplaceInvCDF.m}\nWe can simply call the function to draw a sample from, say the $\\laplace(\\lambda=1.0)$ RV by\n\\begin{VrbM}\n>> lambda=1.0;\t\t% some value for lambda\n>> rand('twister',6567);        % initialize the fundamental sampler\n>> u=rand(1,5);\t\t% draw 5 IID samples from Uniform(0,1) RV\n>> disp(u);\t\t% display the samples in u\n    0.6487    0.9003    0.3481    0.6524    0.8152\n\n>> x=LaplaceInvCDF(u,lambda); % draw 5 samples from Laplace(1) RV using inverse CDF\n>> disp(x);                     % display the samples\n    0.3530    1.6127   -0.3621    0.3637    0.9953\n\\end{VrbM}\n\\end{simulation}\n\n%}%end remove\n\n%\\remove{\n\\begin{labwork}[Inversion Sampler Demo -- $\\cauchy$]\\label{LW:guiInversionSamplerCauchy}\nLet us comprehend the inversion sampler by calling the interactive visual cognitive tool:\n\\begin{VrbM}\n>> guiInversionSampler\n\\end{VrbM}\nThe M-file {\\tt guiInversionSampler.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiInversionSamplerCauchy]{Figure \\ref*{F:guiInversionSamplerCauchy}}.  Using the drop-down menu change from the default target distribution $\\uniform(-5,5)$ to $\\cauchy$ RV of Model~\\ref{M:Cauchy}.  Now repeatedly push the ``Draw one sample'' button several times and comprehend the simulation process.  You can also press ``Draw 10 samples'' several times and see the density histogram of the generated samples.  \nNext try changing the numbers in the ``Scale parameter'' and ``Location Parameter'' boxes from the default values of $1.00$ and  $0.00$, respectively.  Although our formulation of $\\cauchy$ RV is also called {\\em Standard Cauchy} as it implicitly had a location parameter of $0.00$ and scale parameter of $1$.  With a pencil and paper (in conjunction with a wikipedia search if you have to) try to rewrite the PDF in \\eqref{E:StandardCauchypdf} with an additional location parameter $\\mu$ and scale parameter $\\sigma$.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Inversion Sampling from $X \\sim \\cauchy$.\\label{F:guiInversionSamplerCauchy}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/guiInversionSamplerCauchy}}\n\\end{figure}\n\n\\begin{simulation}[$\\cauchy$]\\label{SIM:StdCauchy}\nWe can draw $n$ IID samples from the $\\cauchy$ RV $X$ by transforming $n$ IID samples from $\\uniform(0,1)$ RV $U$ using the inverse DF as follows:\n\\begin{VrbM}\n>> rand('twister',2435567);        % initialise the fundamental sampler\n>> u=rand(1,5);\t\t\t% draw 5 IID samples from Uniform(0,1) RV\n>> disp(u);\t\t\t% display the samples in u\n    0.7176    0.6655    0.9405    0.9198    0.2598\n>> x=tan(pi * u);     % draw 5 samples from Standard cauchy RV using inverse CDF\n>> disp(x);  % display the samples in x\n   -1.2272   -1.7470   -0.1892   -0.2575    1.0634\n\\end{VrbM}\n\\end{simulation}\n\n\n\\subsection{Inversion Sampler for Discrete Random Variables}\\label{S:InvSDiscrete}\nNext, consider the problem of {\\bf sampling from a random variable $X$ with a discontinuous or discrete DF} using the inversion sampler.  We need to define the inverse more carefully here.\n\\begin{prop}[Inversion sampler with compact support]\nLet the support of the RV $X$ be over some real interval $[a,b]$ and let its inverse DF be defined as follows:\n\\[\nF^{[-1]}(u) := \\inf\\{ x \\in [a,b]: F(x) \\geq u, \\ 0 \\leq u \\leq 1 \\} \\ .\n\\]\nIf $U \\sim \\uniform(0,1)$ then $F^{[-1]}(U)$ has the DF $F$, i.e.~$F^{[-1]}(U) \\sim F \\sim X$.\n\\end{prop}\n\\begin{proof}\nThe proof is a consequence of the following equalities:\n\\[\n\\P(F^{[-1]}(U) \\leq x) = \\P(U \\leq F(x)) = F(x) := \\P(X \\leq x)\n\\]\n\\end{proof}\n\n%\\section{Some Simulations of Discrete Random Variables}\\label{S:InvSDiscreteRVs}\n\n\\begin{simulation}[$\\bernoulli(\\theta)$]\\label{SIM:Bernoulli}\nConsider the problem of simulating from a $\\bernoulli(\\theta)$ RV based on an input from  a $\\uniform(0,1)$ RV.  Recall that $\\lfloor x \\rfloor$ (called the `floor of $x$') is the largest integer that is smaller than or equal to $x$, e.g.~$\\lfloor 3.8 \\rfloor = 3$.  Using the floor function, we can simulate a $\\bernoulli(\\theta)$ RV $X$ as follows:\n\\begin{VrbM}\n>>  theta = 0.3;\t\t% set theta = Prob(X=1)\n  % return x  -- floor(y) is the largest integer less than or equal to y\n>> x = floor(rand + theta)\t% rand is the Fundamental Sampler\n>> disp(x) % display the outcome of the simulation\n     0\n>> n=10;  % set the number of IID Bernoulli(theta=0.3) trials you want to simulate\n>> x = floor(rand(1,10)+theta); % vectorize the operation\n>> disp(x) % display the outcomes of the simulation\n     0     0     1     0     0     0     0     0     1     1\n\\end{VrbM}\n\\end{simulation}\nAgain, it is straightforward to do replicate experiments, e.g.~to demonstrate the Central Limit Theorem for a sequence of $n$ IID $\\bernoulli(\\theta)$ trials.\n\\begin{VrbM}\n>> % a demonstration of Central Limit Theorem --\n>> % the sample mean of a sequence of n IID Bernoulli(theta) RVs is Gaussian(theta,theta(1-theta)/n)\n>> theta=0.5; Reps=10000; n=10; hist(sum(floor(rand(n,Reps)+theta))/n)\n>> theta=0.5; Reps=10000; n=100; hist(sum(floor(rand(n,Reps)+theta))/n,20)\n>> theta=0.5; Reps=10000; n=1000; hist(sum(floor(rand(n,Reps)+theta))/n,30)\n\\end{VrbM}\n\nRecall the $\\pointmass(\\theta)$ RV. Formally, we can simulate from it trivially as follows.\n\\begin{simulation}[$\\pointmass(\\theta)$]\\label{SIM:PointMass}\nLet us simulate a sample from the $\\pointmass(\\theta)$ RV $X$.  Since this RV produces the same realisation $\\theta$ we can implement it via the following M-file:\n\n\\VrbMf[label=Sim1PointMass.m]{scripts/Sim1PointMass.m}\nHere is call to the function.\n\\begin{VrbM}\n>> Sim1PointMass(rand(),2)\nans =     2\n>> % % we can use arrayfun to apply Sim1Pointmass to any array of Uniform(0,1) samples\n>> arrayfun(@(u)(Sim1PointMass(u,17)),rand(2,10))\nans =\n    17    17    17    17    17    17    17    17    17    17\n    17    17    17    17    17    17    17    17    17    17\n\\end{VrbM}\nNote that it is not necessary to have input IID samples from $\\uniform(0,1)$ RV via {\\tt rand} in order to draw samples from the $\\pointmass(\\theta)$ RV.  For instance, an input matrix of zeros can do the job:\n\\begin{VrbM}\n>> arrayfun(@(u)(Sim1PointMass(u,17)),zeros(2,8))\nans =\n    17    17    17    17    17    17    17    17\n    17    17    17    17    17    17    17    17\n\\end{VrbM}\n\\end{simulation}\n\nNext we simulate from $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV $X$ of Model~\\ref{M:demoivre} via its inverse DF $$F^{[-1]}: [0,1] \\rightarrow [k] := \\{1,2,\\ldots,k\\} \\ ,$$ given by:\n\\begin{equation}\\label{E:deMoivreInverseDF}\nF^{[-1]}(u;\\theta_1,\\theta_2,\\ldots,\\theta_k) =\n\\begin{cases}\n1 & \\quad \\text{if $0 \\leq u < \\theta_1$}\\\\\n2 & \\quad \\text{if $\\theta_1 \\leq u < \\theta_1+\\theta_2$} \\\\\n3 & \\quad \\text{if $\\theta_1+\\theta_2 \\leq u < \\theta_1+\\theta_2+\\theta_3$} \\\\\n\\vdots & \\\\\nk & \\quad \\text{if $\\theta_1+\\theta_2+\\cdots+\\theta_{k-1} \\leq u < 1$} \\\\\n\\end{cases}\n\\end{equation}\nWhen $k=2$ in the $\\demoivre(\\theta_1,\\theta_2)$ model, we have an RV that is similar to the $\\bernoulli(p=\\theta_1)$ RV.  The DF $F$ and its inverse $F^{[-1]}$ for a specific $\\theta_1=0.3$ are depicted in \\hyperref[F:InvSamk2]{Figure \\ref*{F:InvSamk2}}.\n\n\\begin{figure}[htpb]\n\\caption{The DF $F(x;0.3,0.7)$ of the $\\demoivre(0.3,0.7)$ RV and its inverse $F^{[-1]}(u;0.3,0.7)$. \\label{F:InvSamk2}}\n\\centering   \\makebox{\\includegraphics[width=10cm]{figures/plotInvSamk2R}}\n\\end{figure}\n\nFirst we simulate from an equi-probable special case of the $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV, with $\\theta_1=\\theta_2=\\cdots=\\theta_k=1/k$.\n\\begin{simulation}[$\\demoivre(1/k,1/k,\\ldots,1/k)$]\\label{SIM:deMoivreEqui}\nThe equi-probable $de~Moivre(1/k,1/k,\\ldots,1/k)$ RV $X$ with a discrete uniform distribution over $[k] = \\{1,2,\\ldots k\\}$ can be efficiently sampled using the ceiling function.  Recall that $\\lceil y \\rceil$ is the smallest integer larger than or equal to $y$, eg.~$\\lceil 13.1 \\rceil = 14$.  \\hyperref[A:SimdeMoivreEqui]{Algorithm~\\ref*{A:SimdeMoivreEqui}} produces samples from the $de~Moivre(1/k,1/k,\\ldots,1/k)$ RV $X$.\n\n\\begin{algorithm}[h]\n\\caption{ Inversion Sampler  for $\\demoivre(1/k,1/k,\\ldots,1/k)$ RV}\n\\label{A:SimdeMoivreEqui}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n\\begin{enumerate}\n\\item $k$ in $\\demoivre(1/k,1/k,\\ldots,1/k)$ RV $X$\n\\item $u \\sim \\uniform(0,1)$\n\\end{enumerate}\n}\n\\STATE {\\it output:} a sample from $X$\n\\STATE {{\\it return:} $x \\gets \\lceil k u \\rceil $}\n\\end{algorithmic}\n\\end{algorithm}\n\nThe M-file implementing \\hyperref[A:SimdeMoivreEqui]{Algorithm~\\ref*{A:SimdeMoivreEqui}} is:\n \\VrbMf[label=SimdeMoivreEqui.m]{scripts/SimdeMoivreEqui.m}\nLet us use the function {\\tt SimdeMoivreEqui} to draw five samples from a fair seven-faced cylindrical dice.\n\\begin{VrbM}\n>> k=7; % number of faces of the fair dice\n>> n=5; % number of trials\n>> rand('twister',78657); % initialise the fundamental sampler\n>> u=rand(1,n); % draw n samples from Uniform(0,1)\n>> % inverse transform samples from Uniform(0,1) to samples\n>> % from de Moivre(1/7,1/7,1/7,1/7,1/7,1/7,1/7)\n>> outcomes=SimdeMoivreEqui(u,k); % save the outcomes in an array\n>> disp(outcomes);\n     6     5     5     5     2\n\\end{VrbM}\n\\end{simulation}\n\nNow, let us consider the more general problem of implementing a sampler for an arbitrary but specified $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV.  That is, the values of $\\theta_i$ need not be equal to $1/k$.\n\\begin{simulation}[$\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$]\\label{SIM:deMoivre}\nWe can generate samples from a $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV $X$ when $(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ are specifiable as an input vector via the following algorithm.\n\n\\begin{algorithm}\n\\caption{Inversion Sampler for $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV $X$}\n\\label{A:SimdeMoivre}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n\\begin{enumerate}\n\\item parameter vector $(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ of $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV $X$.\n\\item $u \\sim \\uniform(0,1)$\n\\end{enumerate}\n}\n\\STATE {\\it output:} a sample from $X$\n\\STATE {\\it initialise:}  $F \\gets \\theta_1$, $i \\gets 1$\n\\WHILE{$u > F$}\n\\STATE $i \\gets i+1$\n\\STATE $F \\gets F+\\theta_{i}$\n\\ENDWHILE\n\\STATE {\\it return:} $x \\gets i$\n\\end{algorithmic}\n\\end{algorithm}\n\nThe M-file implementing \\hyperref[A:SimdeMoivre]{Algorithm~\\ref*{A:SimdeMoivre}} is:\n \\VrbMf[label=SimdeMoivreOnce.m]{scripts/SimdeMoivreOnce.m}\nLet us use the function {\\tt deMoivreEqui} to draw five samples from a fair seven-faced dice.\n\\begin{VrbM}\n>> k=7; % number of faces of the fair dice\n>> n=5; % number of trials\n>> rand('twister',78657); % initialise the fundamental sampler\n>> Us=rand(1,n); % draw n samples from Uniform(0,1)\n>> disp(Us);\n    0.8330    0.6819    0.6468    0.6674    0.2577\n>> % inverse transform samples from Uniform(0,1) to samples\n>> % from de Moivre(1/7,1/7,1/7,1/7,1/7,1/7,1/7)\n>> f=[1/7 1/7 1/7 1/7 1/7 1/7 1/7];\n>> disp(f);\n    0.1429    0.1429    0.1429    0.1429    0.1429    0.1429    0.1429\n>> % use funarray to apply function-handled SimdeMoivreOnce to\n>> % each element of array Us and save it in array outcomes2\n>> outcomes2=arrayfun(@(u)(SimdeMoivreOnce(u,f)),Us);\n>> disp(outcomes2);\n     6     5     5     5     2\n>> disp(SimdeMoivreEqui(u,k)); % same result using the previous algorithm\n     6     5     5     5     2\n\\end{VrbM}\nClearly, \\hyperref[A:SimdeMoivre]{Algorithm~\\ref*{A:SimdeMoivre}} may be used to sample from any $\\demoivre(\\theta_1,\\ldots,\\theta_k)$ RV $X$.  We demostrate this by producing five samples from a randomly generated PMF {\\tt f2}.\n\\begin{VrbM}\n>> rand('twister',1777); % initialise the fundamental sampler\n>> f2=rand(1,10); % create an arbitrary array\n>> f2=f2/sum(f2); % normalize to make a probability mass function\n>> disp(f2); % display the weights of our 10-faced die\n    0.0073    0.0188    0.1515    0.1311    0.1760    0.1121    ...\n    0.1718    0.1213    0.0377    0.0723\n>> disp(sum(f2)); % the weights sum to 1\n    1.0000\n>> disp(arrayfun(@(u)(SimdeMoivreOnce(u,f2)),rand(5,5))) % the samples from f2 are\n     4     3     4     7     3\n     6     7     4     5     3\n     5     8     7    10     6\n     2     3     5     7     7\n     6     5     9     5     7\n\\end{VrbM}\n\\end{simulation}\n\nNote that the principal work here is the sequential search, in which the mean number of comparisons until success is:\n\\[\n1 \\theta_1 + 2 \\theta_2 + 3 \\theta_3 + \\ldots + k \\theta_k = \\sum_{i=1}^k{ i \\theta_i}\n\\]\nFor the $\\demoivre(1/k,1/k,\\ldots,1/k)$ RV, the right-hand side of the above expression is:\n\\[\n\\sum_{i=1}^k{ i \\frac{1}{k}} = \\frac{1}{k} \\sum_{i=1}^k{ i} = \\frac{1}{k} \\frac{k(k+1)}{2} = \\frac{k+1}{2} \\ ,\n\\]\nindicating that the average-case efficiency is linear in $k$.  This linear dependence on $k$ is denoted by $O(k)$.  In other words, as the number of faces $k$ increases, one has to work linearly harder to get samples from $\\demoivre(1/k,1/k,\\ldots,1/k)$ RV using \\hyperref[A:SimdeMoivre]{Algorithm \\ref*{A:SimdeMoivre}}.  Using the simpler \\hyperref[A:SimdeMoivreEqui]{Algorithm \\ref*{A:SimdeMoivreEqui}}, which exploits the fact that all values of $\\theta_i$  are equal, we generated samples in constant time, which is denoted by $O(1)$.\n%}%end remove\n\n%\\remove{\n\\begin{simulation}[$\\geometric(\\theta)$]\\label{SIM:Geometric}\nWe can simulate a sample $x$ from a $\\geometric(\\theta)$ RV $X$ using the following simple algorithm:\n\\[\nx \\gets \\lfloor \\log(u) / \\log(1-\\theta) \\rfloor, \\qquad \\text{where, } \\ u \\sim \\uniform(0,1) \\ .\n\\]\nTo verify that the above procedure is valid, note that:\n\\begin{align}\n\\lfloor \\log(U) / \\log(1-\\theta) \\rfloor = x\n& \\iff x \\leq  \\log(U) / \\log(1-\\theta) < x+1 \\notag \\\\\n& \\iff x \\leq  \\log_{1-\\theta}(U) < x+1 \\notag \\\\\n& \\iff (1-\\theta)^x \\geq U > (1-\\theta) ^{x+1} \\notag\n\\end{align}\nThe inequalities are reversed since the base being exponentiated is $1-\\theta \\leq 1$.  The uniform event $(1-\\theta)^x \\geq U > (1-\\theta) ^{x+1}$ happens with the desired probability:\n$$(1-\\theta) ^{x}-(1-\\theta) ^{x+1} = (1-\\theta) ^{x}(1-(1-\\theta)) = \\theta (1-\\theta) ^{x} =: f(x;\\theta), \\quad X \\sim \\geometric(\\theta) \\ .$$\n\nWe implement the sampler to generate samples from $\\geometric(\\theta)$ RV with $\\theta=0.5$, for instance:\n\\begin{VrbM}\n>> theta=0.5; u=rand(); % choose some theta and uniform(0,1) variate\n>> % Simulate from a Geomertic(theta) RV\n>> floor(log (u) / log (1 - theta))\nans =     0\n>> floor(log ( rand(1,10) ) / log (1 - 0.5)) % theta=0.5, 10 samples\nans =     0     0     1     0     2     1     0     0     0     0\n\\end{VrbM}\n\\end{simulation}\n\n\\begin{labwork}[PMF versus relative frequency histogram of simulated $\\geometric(\\theta)$ RV]\\label{LW:RelFreqHistForGeomSims}\nIt is a good idea to make a relative frequency histogram of a simulation algorithm and compare that to the PDF of the discrete RV we are simulating from.  We use the following script to create \\hyperref[F:PlotPdfSimHistGeomthetaHalf]{Figure \\ref*{F:PlotPdfSimHistGeomthetaHalf}}:\n\\VrbMf[label=PlotPdfSimGeometric.m]{scripts/PlotPdfSimGeometric.m}\n\\end{labwork}\n\nLet us simulate from the $\\binomial(n,\\theta)$ RV of Model~\\ref{M:binomial}. %TODO hyperref.\n%\\remove{\n\\begin{labwork}[Binomial coefficient]\\label{LW:BinomialPdf}\nThe \\Matlab function {\\tt BinomialCoefficient} can be used to compute:\n\\[\n\\binom{n}{x} =  \\frac{n !}{x! (n-x)!} = \\frac{n(n-1)(n-2)\\ldots(n-x+1)}{x(x-1)(x-2)\\cdots (2)(1)} = \\frac{\\prod_{i=(n-x+1)}^n i}{\\prod_{i=2}^x} \\ ,\n\\]\nwith the following M-file:\n\\VrbMf[label=BinomialCoefficient.m]{scripts/BinomialCoefficient.m}\nand call {\\tt BinomialCoefficient} in the function {\\tt BinomialPdf} to compute the PDF $f(x;n,\\theta)$ of the $\\binomial(n,\\theta)$ RV $X$ as follows:\n\\VrbMf[label=BinomialPdf.m]{scripts/BinomialPdf.m}\nFor example, we can compute the desired PDF for an array of samples {\\tt x} from $\\binomial(8,0.5)$ RV $X$, as follows:\n\\begin{VrbM}\n>> x=0:1:8\nx =     0     1     2     3     4     5     6     7     8\n>> BinomialPdf(x,8,0.5)\nans =    0.0039    0.0312    0.1094    0.2188    0.2734    0.2188    0.1094    0.0312    0.0039\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{simulation}[$\\binomial(n,\\theta)$ as $\\sum_{i=1}^n \\bernoulli(\\theta)$]\\label{SIM:BinomialFromBernoulliSum}\nSince the $\\binomial(n,\\theta)$ RV $X$ is the sum of $n$ IID $\\bernoulli(\\theta)$ RVs we can also simulate from $X$ by first simulating $n$ IID $\\bernoulli(\\theta)$ RVs and then adding them up as follows:\n\\begin{VrbM}\n>> rand('twister',17678);\n>> theta=0.5; % give some desired theta value, say 0.5\n>> n=5; % give the parameter n for Binomial(n,theta) RV X, say n=5\n>> xis=floor(rand(1,n)+theta) % produce n IID samples from Bernoulli(theta=0.5) RVs X1,X2,...Xn\nxis =     1     1     0     0     0\n>> x=sum(xis) % sum up the xis to get a sample from Binomial(n=5,theta=0.5) RV X\nx =     2\n\\end{VrbM}\nIt is straightforward to produce more than one sample from $X$ by exploiting the column-wise summing property of \\Matlab's {\\tt sum} function when applied to a two-dimensional array:\n\\begin{VrbM}\n>> rand('twister',17);\n>> theta=0.25; % give some desired theta value, say 0.25 this time\n>> n=3; % give the parameter n for Binomial(n,theta) RV X, say n=3 this time\n>> xis10 = floor(rand(n,10)+theta) % produce an n by 10 array of IID samples from Bernoulli(theta=0.25) RVs\nxis10 =\n     0     0     0     0     1     0     0     0     0     0\n     0     1     0     1     1     0     0     0     0     0\n     0     0     0     0     0     0     0     1     0     0\n>> x=sum(xis10) % sum up the array column-wise to get 10 samples from Binomial(n=3,theta=0.25) RV X\nx =     0     1     0     1     2     0     0     1     0     0\n\\end{VrbM}\n\\end{simulation}\n\nIn \\hyperref[SIM:BinomialFromBernoulliSum]{Simulation \\ref*{SIM:BinomialFromBernoulliSum}}, the number of IID $\\bernoulli(\\theta)$ RVs needed to simulate one sample from the $\\binomial(n,\\theta)$ RV is exactly $n$.  Thus, as $n$ increases, the amount of time needed to simulate from $\\binomial(n,\\theta)$ is $O(n)$, i.e.~linear in $n$.  We can simulate more efficiently by exploiting a simple relationship between the $\\geometric(\\theta)$ RV and the $\\binomial(n,\\theta)$ RV.\n\n\nThe $\\binomial(n,\\theta)$ RV $X$ is related to the IID $\\geometric(\\theta)$ RV $Y_1,Y_2,\\ldots$: $X$ is the number of successful $\\bernoulli(\\theta)$ outcomes (outcome is $1$) that occur in a total of $n$ $\\bernoulli(\\theta)$ trials, with the number of trials between consecutive successes distributed according to IID $\\geometric(\\theta)$ RV.\n\\begin{simulation}[$\\binomial(\\theta)$ from IID $\\geometric(\\theta)$ RVs]\\label{SIM:BinomialFromGeoms}\nBy this principle, we can simulate from the $\\binomial(\\theta)$ $X$ by {\\sf Step 1}: generating IID $\\geometric(\\theta)$ RVs $Y_1,Y_2,\\ldots$, {\\sf Step 2}: stopping as soon as $\\sum_{i=1}^k (Y_i+1) > n$ and {\\sf Step 3:} setting $x \\gets k-1$.\n\nWe implement the above algorithm via the following M-file:\n\\VrbMf[label=Sim1BinomByGeoms.m]{scripts/Sim1BinomByGeoms.m}\nHere is a call to simulate $12$ samples from $\\binomial(n=10,\\theta=0.5)$ RV:\n\\begin{VrbM}\n>> theta=0.5; % declare theta\n>> n=10; % say n=10\n>> SampleSize=12;% say you want to simulate 12 samples\n>> rand('twister',10001) % seed the fundamental sampler\n>> Samples=arrayfun(@(T)Sim1BinomByGeoms(n,T),theta*ones(1,SampleSize))\nSamples =     7     5     8     8     4     1     4     8     2     4     6     5\n\\end{VrbM}\n\\hyperref[F:PlotPdfSim10000HistBinomByGeomsn10thetaHalf]{Figure \\ref*{F:PlotPdfSim10000HistBinomByGeomsn10thetaHalf}} depicts a comparison of the PDF of $\\binomial(n=10,\\theta=0.5)$ RV and a relative frequency histogram based on $100,000$ simulations from it.\n\\end{simulation}\n%}% end remove\n\n%\\remove{\nLet us simulate from the $\\poisson(\\lambda)$ RV of Model~\\ref{M:Poisson} as shown in Figure~\\ref{F:PlotPdfSim1000HistPoiss10}. % TODO href\n\n\\begin{simulation}[$\\poisson(\\lambda)$ from IID $\\exponential(\\lambda)$ RVs]\\label{SIM:Poisson}\nBy this principle, we can simulate from the $\\poisson(\\lambda)$ $X$ by {\\sf Step 1}: generating IID $\\exponential(\\lambda)$ RVs $Y_1,Y_2,\\ldots$, {\\sf Step 2}: stopping as soon as $\\sum_{i=1}^k Y_i \\geq 1$ and {\\sf Step 3:} setting $x \\gets k-1$.\n\nWe implement the above algorithm via the following M-file:\n\\VrbMf[label=Sim1Poisson.m]{scripts/Sim1Poisson.m}\nHere is a call to simulate 10 samples from $\\poisson(\\lambda=10.0)$ and $\\poisson(\\lambda=0.1)$ RVs:\n\\begin{VrbM}\n>> arrayfun(@(lambda)Sim1Poisson(lambda),10.0*ones(1,10)) % lambda=10.0\nans =    14     7    10    13    11     3     6     5     8     5\n>> arrayfun(@(lambda)Sim1Poisson(lambda),0.1*ones(1,10)) % lambda=0.1\nans =     2     0     0     0     0     0     0     0     0     0\n\\end{VrbM}\n\\hyperref[F:PlotPdfSim1000HistPoiss10]{Figure \\ref*{F:PlotPdfSim1000HistPoiss10}} depicts a comparison of the PDF of $\\poisson(\\lambda=10)$ RV and a relative frequency histogram based on 1000 simulations from it.\n\\end{simulation}\n\nSimulating from a $\\poisson(\\lambda)$ RV is also a special case of simulating from the following more general RV.\n\\begin{model}[$GD(\\theta_0,\\theta_1,\\ldots)$]\nWe say $X$ is a $\\generaldiscrete(\\theta_0,\\theta_1,\\ldots)$ or $\\GD(\\theta_0,\\theta_1,\\ldots)$ RV over the countable discrete state space $\\Zz_+ := \\{0,1,2,\\ldots\\}$ with parameters $(\\theta_0,\\theta_1,\\ldots)$ if the PMF of $X$ is defined as follows:\n\\[\nf(X=x; \\theta_0,\\theta_1,\\ldots) =\n\\begin{cases}\n0, & if \\quad x \\notin  \\{0,1,2,\\ldots\\} \\\\\n \\theta_0, & if \\quad x=0 \\\\\n \\theta_1, & if \\quad x=1 \\\\\n\\vdots & \\\\\n\\end{cases}\n\\]\n\\hyperref[A:InvSGenDisc]{Algorithm \\ref*{A:InvSGenDisc}} allows us to simulate from any member of the class of non-negative discrete RVs as specified by the probabilities $(\\theta_0,\\theta_1,\\ldots)$.  When an RV $X$ takes  values in another countable set $\\Xz \\neq \\Zz_+$, then we can still use the above algorithm provided we have a one-to-one and onto mapping $D(i)=x: \\Zz_+ \\to \\Xz$ that allows us to think of $\\left(0,1,2,\\ldots\\right)$ as indices of an array $D$ giving $\\Xz = \\left(D(0), D(1), \\ldots \\right)$.\n\\end{model}\n\n\\begin{algorithm}\n\\caption{Inversion Sampler for $GD(\\theta_0,\\theta_1,\\ldots)$ RV $X$}\n\\label{A:InvSGenDisc}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n\\begin{enumerate}\n\\item $\\theta_0$ and $\\{ C(i)  = \\theta_{i}/\\theta_{i-1} \\}$ for any $i \\in \\{1,2,3,\\ldots\\}$.\n\\item $u \\sim \\uniform(0,1)$\n\\end{enumerate}\n}\n\\STATE {\\it output:} a sample from $X$\n\\STATE {\\it initialise:} $p \\gets \\theta_0$, $q \\gets \\theta_0$, $i \\gets 0$\n\\WHILE{$u > q$}\n\\STATE $i \\gets i+1$, $p \\gets p \\ C(i)$, $q \\gets q+p$\n\\ENDWHILE\n\\STATE {\\it return:} $x = i$\n\\end{algorithmic}\n\\end{algorithm}\n\n%\\begin{classwork}\n%What is the algorithm's efficiency when applied to the $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ ?\n%Worst-case and average-case efficiency ?\n%\\vspace{5cm}\n%\\end{classwork}\n\n\n\\begin{simulation}[$\\binomial(n,\\theta)$]\nTo simulate from a $\\binomial(n,\\theta)$ RV $X$, we can use \\hyperref[A:InvSGenDisc]{Algorithm \\ref*{A:InvSGenDisc}} with:\n\\[\n\\theta_0=(1-\\theta)^n, \\qquad C(x+1)=\\frac{\\theta(n-x)}{(1-\\theta)(x+1)}, \\qquad \\text{Mean Efficiency: $O(1+n\\theta)$} \\ .\n\\]\n\\end{simulation}\nSimilarly, with the appropriate $\\theta_0$ and $C(x+1)$, we can also simulate from the $\\geometric(\\theta)$ and $\\poisson(\\lambda)$ RVs.\n\n\\begin{labwork}This is a challenging exercise for the student who is finding the other Labworks too easy. So those who are novice to \\Matlab may skip this Labwork.\n\\begin{enumerate}\n\\item Implement \\hyperref[A:InvSGenDisc]{Algorithm \\ref*{A:InvSGenDisc}} via a function named {\\tt MyGenDiscInvSampler} in {\\tt MATLAB}.  Hand in the {\\tt M-file} named {\\tt MyGenDiscInvSampler.m} giving detailed comments explaining your understanding of each step of the code.  [Hint: $C(i)$ should be implemented as a function (use function handles via {\\tt @}) that can be passed as a parameter to the function {\\tt MyGenDiscInvSampler}].\n\\item Show that your code works for drawing samples from a $\\binomial(n,p)$ RV by doing the following:\n\\begin{enumerate}\n\\item Seed the fundamental sampler by your Student ID (if your ID is {\\tt 11424620} then type {\\tt rand('twister', 11424620);})\n\\item Draw 100 samples from the $\\binomial(n=20,p=0.5)$ RV and report the results in an $2 \\times 2$ table with column headings {\\tt x} and {No. of observations}.  [Hint: the inputs $\\theta_0$ and $C(i)$ for the $\\binomial(n,p)$ RV is given above].\n\\end{enumerate}\n\\item Show that your code works for drawing samples from a $\\geometric(p)$ RV by doing the following:\n\\begin{enumerate}\n\\item Seed the fundamental sampler by your Student ID.\n\\item Set the variable {\\tt Mytheta=rand}.\n\\item Draw 100 samples from the $\\geometric({\\tt Mytheta})$ RV and report the sample mean.  [Note: the inputs $\\theta_0$ and $C(i)$ for the $\\geometric(\\theta)$ RV should be derived and the workings shown].\n\\end{enumerate}\n\\end{enumerate}\n\\end{labwork}\n\n\\subsection{von Neumann Rejection Sampler (RS)}\\label{S:RS}\nRejection sampling [John von Neumann, 1947, in {\\it Stanislaw Ulam 1909-1984}, a special issue of Los Alamos Science, Los Alamos National Lab., 1987, p.~135-136] is a Monte Carlo method to draw independent\nsamples from a target RV $X$ with probability density $f(x)$, where $x \\in \\Xz \\subset \\Rz^k$.  Typically, the target density $f$ is only known up to a constant and therefore the (normalised) density $f$ itself may be unknown and it  is difficult to generate samples directly from $X$.\n\nSuppose we have another density or mass function $g$ for which the following are true:\n\\begin{asparaenum}[(a)]\n\\item\twe can generate random variables from $g$;\n\\item\tthe support of $g$ contains the support of $f$, i.e.~$\\Yz \\supset \\Xz$;\n\\item\ta constant $a > 1$ exists, such that:\n\\begin{equation}\nf(x)\\leq ag(x).\n\\end{equation}\nfor any $x\\in \\Xz$, the support of $X$.  Then $x$ can be generated from Algorithm \\ref*{A:RS}.\n\\end{asparaenum}\n\n\\begin{algorithm}\n\\caption{Rejection Sampler (RS) of von Neumann}\n\\label{A:RS}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n\\begin{itemize}\n\\item[(1)] a target density $f(x)$,\n\\item[(2)] a proposal density $g(x)$ satisfying (a), (b) and (c) above.\n\\end{itemize}\n}\n\\STATE {\\it output:} a sample $x$ from RV $X$ with density $f$\n\n\\REPEAT\n\\STATE Generate $y \\sim g$ and $u \\sim \\uniform(0,1)$\n\\UNTIL{$u \\leq \\frac{f(y)}{a g(y)}$}\n\\STATE {\\it return:} $x \\gets y$\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{prop}[Fundamental Theorem of Simulation]  The von Neumann rejection sampler of Algorithm \\ref*{A:RS} produces a sample $x$ from the random variable $X$ with density $f(x)$.\n\\begin{proof}\nWe shall prove the result for the continuous case. For any real number $t$:\n\n\\begin{eqnarray*}\nF(t) &= \\P(X \\leq t) = \\P\\left(Y \\leq t  \\, | \\, U \\leq\\frac{f(Y)}{ag(Y)} \\right)\n=\\frac{\\P\\left(Y \\leq t, U \\leq\\frac{f(Y)}{ag(Y)} \\right)}{\\P\\left(U \\leq\\frac{f(Y)}{ag(Y)}\\right)}\\\\\n&=\\frac{\\int^t_{-\\infty}\\left(\\int^{f(y)/ag(y)}_0 1 du\\right)g(y)dy}{\\int^{\\infty}_{-\\infty}\\left(\\int^{f(y)/ag(y)}_0 1 du\\right)g(y)dy}\n=\\frac{\\int^t_{-\\infty}\\left(\\frac{f(y)}{ag(y)} \\right)g(y)dy}{\\int^{\\infty}_{-\\infty}\\left(\\frac{f(y)}{ag(y)} \\right)g(y)dy}\\\\\n&=\\int^t_{-\\infty}f(y)dy\n\\end{eqnarray*}\n\\end{proof}\n\\end{prop}\n\n\\begin{labwork}[Rejection Sampler Demo]\\label{LW:guiRejectionsNormal01}\nLet us understand the rejection sampler by calling the interactive visual cognitive tool:\n\\begin{VrbM}\n>> guiRejections\n\\end{VrbM}\nThe M-file {\\tt guiRejections.m} will bring a graphical user interface (GUI) as shown in \\hyperref[F:guiRejectionsNormal01]{Figure \\ref*{F:guiRejectionsNormal01}}.  Try various buttons and see how the output changes with explanations.  Try switching the ``Target distribution'' to ``Mywavy4'' and generate several rejection samples and see the density histogram of the accumulating samples.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Rejection Sampling from $X \\sim \\normal(0,1)$ with PDF $f$ based on proposals from $Y \\sim \\laplace(1)$ with PDF $g$.\\label{F:guiRejectionsNormal01}}\n\\centering   \\makebox{\\includegraphics[width=5.50in]{figures/guiRejectionsNormal01}}\n\\end{figure}\n\n\n%\\subsection{\\exmpl ({\\tt rejection\\_normal\\_laplacian.m})}\n% % Dominic's Demo needs Stats Toolbox\n\\begin{simulation}[Rejection Sampling $\\normal(0,1)$ with $\\laplace(1)$ proposals]\\label{SIM:Normal01FromLaplace}\nSuppose we wish to generate from $X \\sim \\normal(0, 1)$. Consider using the rejection sampler with proposals from $Y \\sim \\laplace(1)$ (using inversion sampler of \\hyperref[SIM:Laplace]{Simulation \\ref*{SIM:Laplace}}). The support of both RVs is $(-\\infty,\\infty)$. Next:\n$$f(x)=\\frac{1}{\\sqrt{2\\pi}}\\exp\\left(-\\frac{x^2}{2}\\right) \\textrm{ and } g(x)=\\frac{1}{2}\\exp(-|x|)$$\nand therefore:\n$$\\frac{f(x)}{g(x)}=\\sqrt{\\frac{2}{\\pi}}\\exp\\left(|x|-\\frac{x^2}{2}\\right)\\leq \\sqrt{\\frac{2}{\\pi}}\\exp\\left(\\frac{1}{2}\\right) = a \\approx 1.3155 \\ .$$\nHence, we can use the rejection method with:\n$$\n\\frac{f(y)}{a g(y)} = \\frac{f(y)}{g(y)} \\frac{1}{a} = \\sqrt{\\frac{2}{\\pi}}\\exp\\left(|y|-\\frac{y^2}{2}\\right) \\frac{1}{\\sqrt{\\frac{2}{\\pi}}\\exp\\left(\\frac{1}{2}\\right)  } = \\exp\\left(|y|-\\frac{y^2}{2} - \\frac{1}{2} \\right)\n$$\n%\\includegraphics\n\nLet us implement a rejection sampler as a function in the M-file {\\tt RejectionNormalLaplace.m} by reusing the function in {\\tt LaplaceInvCDF.m}.\n\\VrbMf[label=RejectionNormalLaplace.m]{scripts/RejectionNormalLaplace.m}\nWe may obtain a large number of samples an plot them as a histogram using the following commands:\n\\begin{VrbM}\n>> % use funarray to convert 1000 zeros into samples from the Normal(0,1)\n>> y=arrayfun(@(x)(RejectionNormalLaplace()),zeros(1,1000));\n>> hist(y,20) % histogram with 20 bins\n\\end{VrbM}\n\\end{simulation}\n\n\\begin{figure}[htpb]\n\\caption{Rejection Sampling from $X \\sim \\normal(0,1)$ with PDF $f$ based on  100 proposals from $Y \\sim \\laplace(1)$ with PDF $g$.\\label{F:RSNormalLaplace}}\n\\centering   \\makebox{\\includegraphics[width=4.50in]{figures/RSNormalLaplace}}\n\\end{figure}\n\n\\begin{classwork}[A note on the proposal's tail in rejection sampling]\nThe condition $f(x)\\leq ag(x)$ is equivalent to $f(x)/g(x)\\leq a$, which says that $f(x)/g(x)$ must be bounded; therefore, $g$ must have higher tails than $f$.\nThe rejection method cannot be used to generate from a Cauchy distribution using a normal distribution, because the latter has lower tails than the former.\n\\end{classwork}\n\n%\\includegraphics\n\nThe next result tells us how many iterations of the algorithm are needed, on average, to get a sample value from a RV with PDF $f$.\n\n\\begin{prop}[Acceptance Probability of RS] The expected number of iterations of the rejection algorithm to get a sample $x$ is the constant $a$.\n\n\\begin{proof}\nFor the continuous case:\n\\begin{displaymath}\n\\P(\\textrm{`accept }y\\textrm{'})=\\P\\left( u\\leq \\frac{f(y)}{ag(y)}\\right)=\\int^{\\infty}_{-\\infty}\\left(\\int^{f(y)/ag(y)}_0du\\right)g(y)dy=\\int^{\\infty}_{-\\infty}\\frac{f(y)}{ag(y)}g(y)dy=\\frac{1}{a}.\n\\end{displaymath}\nAnd the number of proposals before acceptance is the $\\geometric(1/a)$ RV with expectation $\\frac{1}{1/a}=a$.\n\\end{proof}\n\\end{prop}\n\nThe closer $ag(x)$ is to $f(x)$, especially in the tails, the closer $a$ will be to 1, and hence the more efficient the rejection method will be.\n\nThe rejection method can still be used only if the un-normalised form of $f$ or $g$ (or both) is known. In other words, if we use:\n$$f(x)=\\frac{\\tilde{f}(x)}{\\int \\tilde{f}(x)dx} \\textrm{ and } g(x)=\\frac{\\tilde{g}(x)}{\\int \\tilde{g}(x)dx} $$\nwe know only $\\tilde{f} (x)$ and/or $\\tilde{g}(x)$ in closed-form.  Suppose the following are satisfied:\n\\begin{asparaenum}[(a)]\n\\item\twe can generate random variables from $g$;\n\\item\tthe support of $g$ contains the support of $f$, i.e.~$\\Yz \\supset \\Xz$;\n\\item\ta constant $\\tilde{a} > 0$ exists, such that:\n\\begin{equation}\n\\tilde{f}(x)\\leq\\tilde{a}\\tilde{g}(x),\n\\end{equation}\nfor any $x\\in \\Xz$, the support of $X$.  Then $x$ can be generated from Algorithm \\ref*{A:RS2}.\n\\end{asparaenum}\n\n\\begin{algorithm}\n\\caption{Rejection Sampler (RS) of von Neumann -- target shape}\n\\label{A:RS2}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:}\n\\begin{itemize}\n\\item[(1)] shape of a target density $\\tilde{f}(x) = \\left({\\int \\tilde{f}(x)dx}\\right) f(x)$,\n\\item[(2)] a proposal density $g(x)$ satisfying (a), (b) and (c) above.\n\\end{itemize}\n}\n\\STATE {\\it output:} a sample $x$ from RV $X$ with density $f$\n\n\\REPEAT\n\\STATE Generate $y \\sim g$ and $u \\sim \\uniform(0,1)$\n\\UNTIL{$u\\leq\\frac{\\tilde{f}(y)}{\\tilde{a}\\tilde{g}(y)}$}\n\\STATE {\\it return:} $x \\gets y$\n\\end{algorithmic}\n\\end{algorithm}\nNow, the expected number of iterations to get an $x$ is no longer $\\tilde{a}$ but rather the integral ratio: $$ \\left( \\frac{\\int_{\\Xz} \\tilde{f}(x) dx }{\\int_{\\Yz} \\tilde{a} \\tilde{g}(y) dy} \\right)^{-1} \\ .$$\n\n%%The problem is already difficult for the stretched oscillating density for example.\n%\\begin{figure}\n%\\centering   \\makebox[10pt]{\n%\\input{pqfRSMH.tex}\n%}\n%\\caption{The characteristics of three samplers with target $p = p^*/N_p$: (1) Rejection sampler with\n%proposal $q=q^*/N_q$ and the envelope function $f_q$, (2) an independent\n%Metropolis-Hastings sampler (IMHS) driven by an independent base chain $I$\n%with proposal $q_I = q^*_I / N_{q^*_I}$ and (3) a local Metropolis-Hastings sampler (LMHS)\n%driven by a local base chain $L$ with proposal $q_L = q^*_L / N_{q^*_L}$\n%centered at the current state (open square at the bottom). \\label{F:RSMH}}\n%\\end{figure}\n%Rejection Sampling from $Normal(\\mu,\\sigma^2)$ RV $X$ using proposals from $Cauchy(\\nu)$\n%\\begin{model}[Cauchy]\n%A RV $X$ is said to be $Cauchy(\\nu)$ distributed if:\n%\\[\n%f(x;\\nu) = \\frac{\\nu}{\\pi(x^2+\\nu^2)}, \\qquad F(x;\\nu) = \\frac{1}{2} +\\frac{1}{\\pi} \\arctan\\left(\\frac{x}{\\nu}\\right), \\qquad F^{[-1]}(u;\\nu) = \\nu \\tan \\left(\\pi \\left( u- \\frac{1}{2} \\right) \\right)\n%\\]\n%\\end{model}\n%\\begin{labwork}\n%Implement the inversion sampler to draw samples from the $Cauchy(\\nu)$ RV.\n%\\end{labwork}\n\nThe {\\bf Ziggurat Method} [G.~Marsaglia and W.~W.~Tsang, SIAM Journal of Scientific and Statistical Programming, volume 5, 1984] is a rejection sampler that can efficiently draw samples from the $Z \\sim \\normal(0,1)$ RV.  The \\Matlab function {\\tt randn} uses this method to produce samples from $Z$.\\footnote{ {\\tiny See \\url{http://en.wikipedia.org/wiki/Ziggurat\\_algorithm}} for more details.}\n\n\\begin{labwork}[Gaussian Sampling with {\\tt randn}]\\label{LW:randn}\nWe can use \\Matlab function {\\tt randn} that implements the Ziggurat method to draw samples from an RV $Z \\sim \\normal(0,1)$ as follows:\n\\begin{VrbM}\n>> randn('state',67678); % initialise the seed at 67678 and method as Ziggurat -- TYPE help randn\n>> randn % produce 1 sample from Normal(0,1) RV\nans =    1.5587\n>> randn(2,8) % produce an 2 X 8 array of samples from Normal(0,1) RV\nans =\n    1.2558    0.7834    0.6612    0.3247    0.1407    1.0562    0.8034    1.2970\n   -0.5317    0.0417   -0.3454    0.6182   -1.4162    0.4796   -1.5015    0.3718\n\\end{VrbM}\nIf we want to produce samples from $X \\sim \\normal(\\mu,\\sigma^2)$ with some user-specified $\\mu$ and $\\sigma$, then we can use the following relationship between $X$ and $Z \\sim \\normal(0,1)$:\n\\[\nX \\gets \\mu + \\sigma Z, \\qquad Z \\sim \\normal(0,1) \\ .\n\\]\nSuppose we want samples from $X \\sim \\normal(\\mu=\\pi, \\sigma^2=2)$, then we can do the following:\n\\begin{VrbM}\n>> randn('state',679); % initialise the seed at 679 and method as Ziggurat -- TYPE help randn\n>> mu=pi % set the desired mean parameter mu\nmu =    3.1416\n>> sigma=sqrt(2) % set the desired standard deviation parameter sigma\nsigma =    1.4142\n>> mu + sigma * randn(2,8) % produces a 2 X 8 array of samples from Normal(3.1416,1.4.42)\nans =\n    1.3955    1.7107    3.9572    3.2618    6.1652    2.6971    2.4940    4.5928\n    0.8442    4.7617    3.5397    5.0282    1.6139    5.0977    2.0477    2.3286\n\\end{VrbM}\n\\end{labwork}\n\n%%% new content added on 28 Dec 2010: Raaz to integrate and streamline\n%%% this may be used as labwork or exercise, i am calling it labwork for now\n\\begin{labwork}[Sampling from truncated normal distributions] [Christian P. Robert, Simulation of truncated normal variables, Statistics and Computing (1995) 5, 121-125]\nLet $N_+(\\mu,\\tau,\\sigma^2)$ denote the left-truncated normal distribution with truncation point $\\tau$ and density given by\n\n$$f(x|\\mu,\\tau,\\sigma^2)=\\frac{exp(-(x-\\mu)^2/2\\sigma^2)}{\\sqrt{2\\pi}\\sigma[1-\\Phi((\\tau-\\mu)/\\sigma)]}\\BB{1}_{x\\geq\\tau}.$$\n\nWhen $\\tau<\\mu$, the rejection sampler can readily be used to simulate from $N_+(\\mu,\\tau,\\sigma^2)$ by simulating from $\\normal(\\mu,\\sigma^2)$ until a number larger than $\\tau$ is obtained. When $\\tau>\\mu$, however, this can be inefficient and increasingly so as $\\tau$ gets further out into the right tail. In this case, a more efficient approach is to use the rejection sampler with the following translated exponential distribution as the proposal distribution:\n\n$$g(y|\\lambda,\\tau)={\\lambda}exp(-\\lambda(y-\\tau))\\BB{1}_{y\\geq\\tau}.$$\n\n\\begin{enumerate}\n\\item Show that for simulating from $N_+(\\mu=0,\\tau,\\sigma^2=1)$ when $\\tau\\geq0$, the best choice of $\\lambda$ that maximizes the expected acceptance probability for the rejection sampler is given by\n$$\\lambda=\\frac{\\tau+\\sqrt{\\tau^2+4}}{2}$$\n\\item Find the maximum expected acceptance probabilities for the following truncation points, $\\tau=0,0.5,1,1.5,2,2.5$ and 3. What can you conclude about efficiency as $\\tau$ gets further out into the right tail?\n\\item Describe how samples from $N_+(\\mu,\\tau,\\sigma^2)$ can be obtained by simulating from $N_+(\\mu=0,\\tau,\\sigma^2=1)$ and using location-scale transformation.\n\\item A related distribution, denoted by $N_-(\\mu,\\tau,\\sigma^2)$, is the right-truncated normal distribution truncated on the right at $\\tau$. Describe how samples from $N_-(\\mu,\\tau,\\sigma^2)$ can be obtained by simulating from an appropriate left-truncated normal distribution.\n\\item Write a \\Matlab function that provides samples from a truncated normal distribution. The function should have the following inputs: number of samples required, left or right truncation, $\\mu$, $\\sigma^2$ and $\\tau$.\n\\end{enumerate}\n\\end{labwork}\n\n\\input{ExsInSimulation.tex}\n", "meta": {"hexsha": "42158758b81cb5b7a99e60ab193ddd984763051f", "size": 68655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/RandomNumbers.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/RandomNumbers.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/RandomNumbers.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": 63.8057620818, "max_line_length": 669, "alphanum_fraction": 0.6976913553, "num_tokens": 22840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.6095074818369527}}
{"text": "\\documentclass{article}\n\n\\usepackage{lipsum}\n\\usepackage[margin=1.5in]{geometry}\n\\usepackage{titlesec}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\usepackage{mathtools, amssymb, nccmath}\n\\usepackage{bigstrut, changepage, lipsum}\n\n\\newcommand{\\code}{\\texttt}\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\usepackage{siunitx} % Required for alignment\n\n\n% Specify images directory\n\\graphicspath{ {./report-images/} }\n\n% Header and Footer stuff\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\fancyhead{}\n\\fancyfoot{}\n\\fancyfoot[R]{ \\thepage\\ }\n\\renewcommand{\\headrulewidth}{0pt}\n\\renewcommand{\\footrulewidth}{0pt}\n\\newcommand{\\sectionbreak}{\\clearpage}\n\\setlength{\\parindent}{0pt}\n\n%\n\n\\begin{document}\n\n%----------------------------------------------------------------------------------------\n%\tTITLE PAGE\n%----------------------------------------------------------------------------------------\n\n\\begin{titlepage} % Suppresses displaying the page number on the title page and the subsequent page counts as page 1\n\t\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}% Defines a new command for horizontal lines, change thickness here\n\t\n\t\\center % Centre everything on the page\n\t\n\t%------------------------------------------------\n\t%\tHeadings\n\t%------------------------------------------------\n\t\n\t\\textsc{\\Large Data Smoothing}\\\\[0.5cm] % Major heading such as course name\n\t\n\t\\textsc{\\large Exercise 3}\\\\[0.5cm] % Minor heading such as course title\n\t\n\t%------------------------------------------------\n\t%\tTitle\n\t%------------------------------------------------\n\t\n\t\\HRule\\\\[0.6cm]\n\t\n\t{\\huge\\bfseries Data Smoothing Report}\\\\[0.25cm] % Title of your document\n\t\n\t\\HRule\\\\[1.5cm]\n\t\n\t%------------------------------------------------\n\t%\tAuthor(s)\n\t%------------------------------------------------\n\t\n\t\\begin{minipage}{0.4\\textwidth}\n\t\t\\begin{flushleft}\n\t\t\t\\large\n\t\t\t\\textit{Author}\\\\\n\t\t\t\\textsc{Cesare De Cal} % Your name\n\t\t\\end{flushleft}\n\t\\end{minipage}\n\t~\n\t\\begin{minipage}{0.4\\textwidth}\n\t\t\\begin{flushright}\n\t\t\t\\large\n\t\t\t\\textit{Professor}\\\\\n\t\t\t\\textsc{Annie Cuyt}\\\\ % Supervisor's name\n\t\t\t[0.25cm]\n\t\t\t\\textit{Assistant Professor}\\\\\n\t\t\t\\textsc{Ferre Knaepkens} % Supervisor's name\n\n\t\t\\end{flushright}\n\t\\end{minipage}\n\t\t\n\t\\vfill\\vfill\\vfill\n\t\n\t{\\large\\today}\n\t\t\n\t\\vfill\n\t\n\\end{titlepage}\n\n%----------------------------------------------- Introduction ------------------------------------------------------\n\\section{Introduction}\\label{sec:intro}\nThis exercise asks to use the linearly independent basis function:\n$$\\phi_{3,i}(x)=\\binom{3}{i}x^{i}(1-x)^{3-i}\\quad\\quad i = 0, 1, 2, 3$$\nto find the optimal combination\n$$\\phi(x)=\\lambda_0\\phi_{3,0}(x)+\\lambda_1\\phi_{3,1}(x)+\\lambda_2\\phi_{3,2}(x)+\\lambda_3\\phi_{3,3}(x)$$\nthat minimizes the Euclidean norm\n$$\\sqrt{\\sum_{j=0}^{19}{(\\phi(x_j)-y_j)^2}}$$\nfor the 20 data points $(x_j,y_j)$ given in\n\n\\begin{table}[!ht]\n\\large        %% not \"\\fontsize{12}{12}\\selectfont\"\n\\centering    %% not \"\\center{...}\"\n\\begin{tabular}{|c|c|c|}\n\\hline\n$j$ & $x_j$ & $y_j$ \\\\     %% no \"&\" at start of row\n\\hline\n0 & 0.0 & -0.80\\\\\n1 & 0.6 & -0.34\\\\\n2 & 1.5 & 0.59\\\\\n3 & 1.7 & 0.59\\\\\n4 & 1.9 & 0.23\\\\\n5 & 2.1 & 0.10\\\\\n6 & 2.3 & 0.28\\\\\n7 & 2.6 & 1.03\\\\\n8 & 2.8 & 1.50\\\\\n9 & 3.0 & 1.44\\\\\n10 & 3.6 & 0.74\\\\\n11 & 4.7 & -0.82\\\\\n12 & 5.2 & -1.27\\\\\n13 & 5.7 & -0.92\\\\\n14 & 5.8 & -0.92\\\\\n15 & 6.0 & -1.04\\\\\n16 & 6.4 & -0.79\\\\\n17 & 6.9 & -0.06\\\\\n18 & 7.6 & 1.00\\\\\n19 & 8.0 & 0.00\\\\    \n\\hline\n\\end{tabular}\n\\end{table}\n\nThis is an overdetermined system. I'll first find the coefficient matrix $A$ and then use $QR$ decomposition to solve the system. I'll also calculate the $l_2$-norm of the residual, and the condition number of the coefficient matrix. Finally, I'll plot the data points with the graph of the function $\\phi(x)$.\n\n%---------------------------------- Introduction ------------------------------------------------------\n\\section{Tools}\nThe following programming language and libraries have been used in this exercise:\n\\begin{itemize}\n  \\item C\n  \\item GSL (GNU Scientific Library)\n  \\item C Math Library\n  \\item Python (for plotting)\n  \\item SciPy (for plotting)\n\\end{itemize}\nThe following double-precision GSL data types have been used in the exercise:\n\\begin{itemize}\n  \\item \\code{gsl\\_matrix}\n  \\item \\code{gsl\\_vector}\n\\end{itemize}\nThe following GSL methods have been used in the exercise:\n\\begin{itemize}\n  \\item \\code{gsl\\_matrix\\_alloc(size1, size2)}\n  \\item \\code{gsl\\_matrix\\_set(matrix, row, column, value)}\n  \\item \\code{gsl\\_matrix\\_get(matrix, row, column)}\n  \\item \\code{gsl\\_vector\\_alloc(size)}\n  \\item \\code{gsl\\_vector\\_set(vector, index, value)}\n  \\item \\code{gsl\\_vector\\_set\\_zero(vector)}\n  \\item \\code{gsl\\_vector\\_get(vector, index)}\n  \\item \\code{gsl\\_matrix\\_memcpy(destinationMatrix, matrixToCopyFrom)}\n  \\item \\code{gsl\\_linalg\\_SV\\_decomp(A, V, S, workspaceVector)}\n  \\item \\code{gsl\\_vector\\_minmax(vector, minInVector, maxInVector)}\n  \\item \\code{gsl\\_sf\\_fact(number)} to calculate the factorial\n  \\item \\code{gsl\\_sf\\_pow\\_int(base, exponent)}\n  \\item \\code{gsl\\_blas\\_dnrm2(vector)} to calculate the Euclidean norm\n  \\item \\code{gsl\\_matrix\\_free(matrixToDeallocate)}\n  \\item \\code{gsl\\_vector\\_free(vectorToDeallocate)}\n\\end{itemize}\nIn order to decompose the coefficient matrix into its QR decomposition, and then solve the square system $A\\vec{x}=\\vec{b}$, I've used the following methods:\n\\begin{itemize}\n  \\item \\code{gsl\\_linalg\\_QR\\_decomp(matrixQR, vectorTau)}\n  \\item \\code{gsl\\_linalg\\_QR\\_lssolve(matrixQR, vectorTau, vectorB, vectorX, vectorResidual)}\n  \\item \\code{gsl\\_permutation\\_alloc(size)}\n\\end{itemize}\nThe following method from the C Math library was used in this exercise to calculate the absolute value of a number:\n\\begin{itemize}\n  \\item \\code{fabs(x)}\n\\end{itemize}\n  \n\\section{Computation}\nFirst of all, I compute the coefficients A of the linear system by using the linearly independent basis function. For the $(i, j)$ cell in the matrix, I call the basis function by passing the $i$-th element of the $x$ data points, and by using the column $j$ for the $i$ parameter of the basis function. This results in a $20\\times4$ matrix. The following is a representation of A:\n\\begin{adjustwidth}{-2em}{-2em}\n    \\[ \\medmath{\\begin{bmatrix*}[r]\n1.000000000000000\\,e+00 & 0.000000000000000\\,e+00 & 0.000000000000000\\,e+00 & 0.000000000000000\\,e+00 \\bigstrut[t]\\\\\n6.400000000000002\\,e-02 & 2.880000000000000\\,e-01 & 4.320000000000001\\,e-01 & 2.160000000000000\\,e-01 \\\\\n-1.250000000000000\\,e-01 & 1.125000000000000\\,e+00 & -3.375000000000000\\,e+00 & 3.375000000000000\\,e+00 \\\\\n-3.429999999999999\\,e-01 & 2.499000000000000\\,e+00 & -6.068999999999998\\,e+00 & 4.912999999999999\\,e+00 \\\\\n-7.289999999999998\\,e-01 & 4.616999999999998\\,e+00 & -9.747000000000000\\,e+00 & 6.858999999999999\\,e+00 \\\\\n-1.331000000000000\\,e+00 & 7.623000000000002\\,e+00 & -1.455300000000000\\,e+01 & 9.261000000000001\\,e+00 \\\\\n-2.196999999999999\\,e+00 & 1.166100000000000\\,e+01 & -2.063099999999999\\,e+01 & 1.216700000000000\\,e+01 \\\\\n-4.096000000000001\\,e+00 & 1.996800000000001\\,e+01 & -3.244800000000000\\,e+01 & 1.757600000000000\\,e+01 \\\\\n-5.831999999999998\\,e+00 & 2.721599999999999\\,e+01 & -4.233599999999999\\,e+01 & 2.195199999999999\\,e+01 \\\\\n-8.000000000000000\\,e+00 & 3.600000000000000\\,e+01 & -5.400000000000000\\,e+01 & 2.700000000000000\\,e+01 \\\\\n-1.757600000000000\\,e+01 & 7.300800000000001\\,e+01 & -1.010880000000000\\,e+02 & 4.665600000000001\\,e+01 \\\\\n-5.065300000000001\\,e+01 & 1.930290000000000\\,e+02 & -2.451990000000000\\,e+02 & 1.038230000000000\\,e+02 \\\\\n-7.408800000000001\\,e+01 & 2.751840000000000\\,e+02 & -3.407040000000000\\,e+02 & 1.406080000000000\\,e+02 \\\\\n-1.038230000000000\\,e+02 & 3.777390000000001\\,e+02 & -4.581090000000000\\,e+02 & 1.851930000000000\\,e+02 \\\\\n-1.105920000000000\\,e+02 & 4.008960000000000\\,e+02 & -4.844160000000000\\,e+02 & 1.951120000000000\\,e+02 \\\\\n-1.250000000000000\\,e+02 & 4.500000000000000\\,e+02 & -5.400000000000000\\,e+02 & 2.160000000000000\\,e+02 \\\\\n-1.574640000000000\\,e+02 & 5.598720000000002\\,e+02 & -6.635520000000001\\,e+02 & 2.621440000000001\\,e+02 \\\\\n-2.053790000000000\\,e+02 & 7.205670000000001\\,e+02 & -8.426970000000001\\,e+02 & 3.285090000000001\\,e+02 \\\\\n-2.874960000000000\\,e+02 & 9.931679999999998\\,e+02 & -1.143648000000000\\,e+03 & 4.389759999999999\\,e+02 \\\\\n-3.430000000000000\\,e+02 & 1.176000000000000\\,e+03 & -1.344000000000000\\,e+03 & 5.120000000000000\\,e+02 \\bigstrut[b]\n\\end{bmatrix*}} \\]%\n\\end{adjustwidth}\n\n% --------- CONDITION NUMBER ---------\nThen, I calculate the condition number of the coefficient matrix $A$. In GSL there is no direct function that calculates the condition number, but it's possible to use the ratio of the largest singular value of matrix A, $\\sigma_n (A)$, to the smallest $\\sigma_1 (A)$:\n\n$$\\kappa(A) := \\frac{\\sigma_n (A)}{\\sigma_1 (A)}= \\frac{\\norm{A}}{\\norm{A^{-1}}^{-1}}$$\n\nI proceed to factorize $A$ into its singular value decomposition $SVD$ using the \\code{gsl\\_linalg\\_SV\\_decomp} method, and then use $\\code{gsl\\_vector\\_minmax}$ to extract the minimum and maximum singular values out of the vector $S$ that contains the diagonal elements of the singular value matrix. The condition number of the matrix $A$ is equal to $3.741019262503867e+03$.\\\\\n\n% --------- CONDITION NUMBER ---------\n\nThe column vector $\\vec{b}$ is formed by the input $y_j$ values:\n$$\n\\begin{bmatrix} \n-8.000000000000000e-01\\\\\n-3.400000000000000e-01\\\\\n5.900000000000000e-01\\\\\n5.900000000000000e-01\\\\\n2.300000000000000e-01\\\\\n1.000000000000000e-01\\\\\n2.800000000000000e-01\\\\\n1.030000000000000e+00\\\\\n1.500000000000000e+00\\\\\n1.440000000000000e+00\\\\\n7.400000000000000e-01\\\\\n-8.200000000000000e-01\\\\\n-1.270000000000000e+00\\\\\n-9.200000000000000e-01\\\\\n-9.200000000000000e-01\\\\\n-1.040000000000000e+00\\\\\n-7.900000000000000e-01\\\\\n-6.000000000000000e-02\\\\\n1.000000000000000e+00\\\\\n0.000000000000000e+00\\\\\n\\end{bmatrix}\n$$\n\nI proceed in solving the system (finding the $\\lambda$ values that approximate to a solution of the system). I use QR decomposition to solve the system ($\\code{gsl\\_linalg\\_QR\\_decomp}$ and $\\code{gsl\\_linalg\\_QR\\_lssolve}$ GSL methods). The following is the QR decomposition of A:\n\n\\begin{adjustwidth}{-2em}{-2em}\n    \\[ \\medmath{\\begin{bmatrix*}[r]\n-5.607137694902810e+02 & 1.956202843752372e+03 & -2.276212763756861e+03 & 8.833928944999552e+02 \\\\\n1.139370324819986e-04 & -4.671135706796601e+01 & 1.122030535262658e+02 & -6.782418228480103e+01 \\\\\n-2.225332665664034e-04 & 1.460497799957120e-02 & 7.581872706318327e+00 & -8.735870723873337e+00 \\\\\n-6.106312834582108e-04 & 2.762429988027977e-02 & 1.797466673315370e-01 & -2.470454024049311e+00 \\\\\n-1.297814010615264e-03 & 4.400918925292650e-02 & 2.113118885654055e-01 & 1.354991299702775e-01 \\\\\n-2.369534222399064e-03 & 6.326913656703972e-02 & 2.350053228690535e-01 & 9.686987975376644e-02 \\\\\n-3.911244693171105e-03 & 8.491363227214763e-02 & 2.513310790520081e-01 & 6.050043190845661e-02 \\\\\n-7.291970078847909e-03 & 1.207784144212678e-01 & 2.631080548709738e-01 & 1.049772432830278e-02 \\\\\n-1.038251208492211e-02 & 1.462383018205487e-01 & 2.632200917938682e-01 & -1.959354810540480e-02 \\\\\n-1.424212906024982e-02 & 1.723659541841733e-01 & 2.577288314294048e-01 & -4.692208258102275e-02 \\\\\n-3.128995754536886e-02 & 2.498504055563917e-01 & 2.126763547071380e-01 & -1.108942994397425e-01 \\\\\n-9.017582041110428e-02 & 3.520968788593226e-01 & 5.605686650054093e-02 & -1.473630562460556e-01 \\\\\n-1.318963572269736e-01 & 3.635568863958127e-01 & -2.831753402090372e-02 & -1.240982343374392e-01 \\\\\n-1.848325706777897e-01 & 3.424022086740725e-01 & -1.099043818739413e-01 & -7.278910904340619e-02 \\\\\n-1.968831921288935e-01 & 3.335830602668363e-01 & -1.251940955112117e-01 & -5.896438574071358e-02 \\\\\n-2.225332665664034e-01 & 3.108660410390103e-01 & -1.542417580429807e-01 & -2.760834500928011e-02 \\\\\n-2.803278262928973e-01 & 2.434003295032724e-01 & -2.044456433018340e-01 & 5.043304854412397e-02 \\\\\n-3.656292780331310e-01 & 1.127004233192019e-01 & -2.472054281433762e-01 & 1.782091144383195e-01 \\\\\n-5.118193920381977e-01 & -1.705668773785795e-01 & -2.556299463550832e-01 & 4.175378294298211e-01 \\\\\n-6.106312834582110e-01 & -3.921595584433181e-01 & -2.261060282111244e-01 & 5.880648466528077e-01 \\\\\n\\end{bmatrix*}} \\]%\n\\end{adjustwidth}\n\nThe solutions vector is directly given by the $\\code{gsl\\_linalg\\_QR\\_lssolve}$ method.\n\n$$\n\\begin{bmatrix}\n-1.118262027055321e+00\\\\\n-4.515724133992401e-01\\\\\n2.972563550105292e-03\\\\\n2.972882574075207e-01\\\\\n\\end{bmatrix}\n$$\n\nThe residual vector $\\vec{r}$ is also directly given by the $\\code{gsl\\_linalg\\_QR\\_lssolve}$ method.\n$$\n\\begin{bmatrix}\n3.182620270553753e-01\\\\\n-2.038767862631474e-01\\\\\n-3.507925507654632e-02\\\\\n-1.076211346528342e-01\\\\\n-5.104297656943454e-01\\\\\n-6.559970851745927e-01\\\\\n-4.668150300670836e-01\\\\\n3.379120178166642e-01\\\\\n8.680652851344475e-01\\\\\n8.842461476326978e-01\\\\\n4.840349364751467e-01\\\\\n-4.332442092900336e-01\\\\\n-6.426370573997744e-01\\\\\n-1.387527086448619e-01\\\\\n-1.218089886087358e-01\\\\\n-2.242466352247385e-01\\\\\n-1.314405461740510e-02\\\\\n5.037445845512266e-01\\\\\n8.885672158267567e-01\\\\\n-7.311795037780225e-01\\\\\n\\end{bmatrix} \n$$\n\nThe Euclidean norm of the residual vector, which can be easily calculated with $\\code{gsl\\_blas\\_dnrm2(vector)}$, is equal to $2.282876480420795e+00$.\n\\section{Plot}\n\n\\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{graph.png}\n\n\\section{Observations}\nIn this problem I have worked with an overdetermined system of equations which has more equations that unknowns ($m >> n \\rightarrow20 >> 4$). It is not possible to find the exact $\\vec{x}$ vector, but I found a set of $\\lambda$ that satisfies the system as close as possible through $QR$ factorization. \\\\\n\nAt the end of the exercise, I plotted the computed function together with the data points. In order to plot the graph of the $\\phi(x)$ function, I used the $\\lambda$ values contained in $\\vec{x}$ and plugged them into the linear combination. Plus, I created an array of equidistant $x$ values and calculated the function value for each of the values. We can observe that the function gives a general idea of the data points, but overall I don't think it is very accurate.\n\n\\end{document}", "meta": {"hexsha": "8b92b2245957c2f25bb19b622271edeafbdd7148", "size": 14134, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Data Smoothing/CesareDeCal_Exercise3/Report.tex", "max_stars_repo_name": "csr/MATLAB-Scientific-Programming", "max_stars_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Data Smoothing/CesareDeCal_Exercise3/Report.tex", "max_issues_repo_name": "csr/MATLAB-Scientific-Programming", "max_issues_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Data Smoothing/CesareDeCal_Exercise3/Report.tex", "max_forks_repo_name": "csr/MATLAB-Scientific-Programming", "max_forks_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_forks_repo_licenses": ["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.4465408805, "max_line_length": 471, "alphanum_fraction": 0.687844913, "num_tokens": 5360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6095074751138562}}
{"text": "\\documentclass[jou]{apa6}\n\n\\usepackage[american]{babel}\n\n\\usepackage{csquotes}\n\\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}\n\\DeclareLanguageMapping{american}{american-apa}\n\\addbibresource{bibliography.bib}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Discrete Structures\n%% The start of RBS stuff\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Working internal and external links in PDF\n\\usepackage{hyperref}\n% Extra math symbols in LaTeX\n\\usepackage{amsmath}\n\\usepackage{gensymb}\n\\usepackage{amssymb}\n% Enumerations with (a), (b), etc.\n\\usepackage{enumerate}\n\n\\let\\OLDitemize\\itemize\n\\renewcommand\\itemize{\\OLDitemize\\addtolength{\\itemsep}{-6pt}}\n\n\\usepackage{etoolbox}\n\\makeatletter\n\\preto{\\@verbatim}{\\topsep=3pt \\partopsep=3pt }\n\\makeatother\n\n% These sizes redefine APA for A4 paper size\n\\oddsidemargin 0.0in\n\\evensidemargin 0.0in\n\\textwidth 6.27in\n\\headheight 1.0in\n\\topmargin -24pt\n\\headheight 12pt\n\\headsep 12pt\n\\textheight 9.19in\n\n\n\n\\title{Sample Quiz 4}\n\\author{Discrete Structures, Fall 2020}\n\\affiliation{RBS}\n\n\\leftheader{Discrete Sample Quiz 4}\n\n\\abstract{%\n}\n\n%\\keywords{}\n\n\\begin{document}\n\n%\\thispagestyle{empty}\n\n\\twocolumn\n\\section{Worksheet 4: Sets}\n\n\\vspace{10pt}\n{\\bf Question 1.} We define three sets in the universe $U$ of integer numbers\nbetween $1$ and $70$ (inclusive):\n$$\\left\\{ \\begin{array}{rcl}\nK_2 & = & \\{ x \\in U \\,\\mid\\, 2 \\mid x \\},\\\\\nK_5 & = & \\{ x \\in U \\,\\mid\\, 5 \\mid x \\},\\\\\nK_7 & = & \\{ x \\in U \\,\\mid\\, 7 \\mid x \\},\n\\end{array} \\right.$$\n\nFind the size of the following sets.\nHere $|X|$ denotes the number of elements in a finite set\n(BTW, $|X|$ is also the notation for the cardinality of an infinite set).\\\\\n{\\em Note.} It was not intentional, but vertical bar: $\\mid$\nin this exercise happens to be used in three different ways: \nIt is a separator when defining sets $K_2$; it is used to denote\ndivisibility; it also denotes set cardinality.\n\n\\begin{tabular}{ll} \n$\\left| K_2 \\cup K_5 \\right|$ & $\\ldots$ \\\\ \n$\\left| K_2 \\cap K_7 \\right|$ & $\\ldots$ \\\\ \n$\\left| \\overline{K_7} \\right|$ & $\\ldots$ \\\\\n$\\left| \\overline{K_2 \\cap K_5} \\right|$ & $\\ldots$ \\\\\n$\\left| K_2 \\cap K_5 \\cap K_7 \\right|$ & $\\ldots$ \\\\ \n$\\left| K_2 \\cap K_5 \\cap \\overline{K_7} \\right|$ & $\\ldots$ \\\\ \n$\\left| K_2 \\cup K_5 \\cup K_7 \\right|$ & $\\ldots$ \\\\ \n$\\left| \\overline{K_2 \\cup K_5 \\cup K_7} \\right|$ & $\\ldots$ \\\\ \n\\end{tabular}\n\n\n\\vspace{6pt}\n{\\bf Question 2.}\nFind a counterexample to refute the following predicate expression:\\\\\n$(\\exists x \\in U,\\;P(x)) \\wedge (\\exists x\\in U,\\;Q(x)) \\rightarrow$\\\\\n$\\rightarrow \\exists x\\in U,\\;(P(x) \\wedge Q(x))$.\\\\\nHere $P(x)$ is true iff $P$ is a full square (a square of some integer number), \n$Q(x)$ is true iff $x$ is divisible by $5$, and $U$ is the set of all integers \nfrom the interval $[120;130]$.\\\\\n{\\em Note.} The three $x$'s in this formula refer to \nthree unrelated (local) variables. \nIf it looks confusing, you can rewrite it like this:\\\\\n$(\\exists x_1 \\in U,\\;P(x_1)) \\wedge (\\exists x_2\\in U,\\;Q(x_2)) \\rightarrow$\\\\\n$\\rightarrow \\exists x_3\\in U,\\;(P(x_3) \\wedge Q(x_3))$.\n\n\\noindent\n{\\bf (A)} Identify the variables which you need to pick for your counter-example.\\\\\n{\\bf (B)} Pick the values for these variables to make the above statement false.\n\n\n\\vspace{6pt}\n{\\bf Question 3.} Determine the cardinality of the following sets (some finite number? \nequal to $|\\mathbb{N}|$? equal to $|\\mathcal{P}(\\mathbb{N})| = |\\mathbb{R}|$? equal to $|\\mathcal{P}(\\mathbb{R})|$?)\n\\begin{enumerate}[(A)]\n\\item The set of positive real numbers from $(0;1)$ with decimal representation \ncontaining only digits $0$ and $1$? \n\\item The set of positive real numbers from $(0;1)$ with decimal representation \ncontaining only digits $0$ and $1$ (and it is known that the number of $0$s is finite)? \n\\item The set of positive real numbers from $(0;1)$ that are fully periodic decimal fractions with \na period of $2020$ digits? \n\\item The set of positive real numbers from $(0;1)$ that have decimal representation \nwithout any digits \"9\"?\n\\item The set of all irrational $x \\in (0;1)$ such that $x^3$ is rational?\n\\item Ordered pairs of real numbers $x_1,x_2$ such that $x_1,x_2 \\in (0;1)$. \n\\item Finite sequences of real numbers: $x_1,\\ldots,x_n$, and all $x_i \\in (0;1)$? (Here $n$ can \nbe any positive integer)? \n\\item Infinite sequences of real numbers from $(0;1)$: $\\{ x_n \\}$: $x_1,x_2,x_3,\\ldots$.\n\\end{enumerate}\n\n\n\\vspace{6pt}\n{\\bf Question 4.}\nLet ${\\displaystyle f(x) = \\left\\lfloor \\frac{x^3}{3} \\right\\rfloor}$. Find $f(S)$ if $S$ is:\n\\begin{enumerate}[(A)]\n\\item $S = \\{ −2, −1, 0, 1, 2, 3 \\}$.\n\\item $S = \\{0, 1, 2, 3, 4, 5 \\}$.\n\\item $S = \\{1, 5, 7, 11 \\}$.\n\\end{enumerate}\nIs function $f: \\mathbb{Z} \\rightarrow \\mathbb{Z}$ injective? Is it surjective? \nIf it is not, mention counterexamples to show this. \n\n\\vspace{6pt}\n{\\bf Question 5.}\nDetermine, if the given set is a powerset of some other set. If yes, which one?\n\\begin{enumerate}[(A)]\n\\item $\\{\\emptyset,\\; \\{\\emptyset\\},\\; \\{a\\},\\; \\{\\{a\\}\\},\\; \\{\\{\\{a\\}\\}\\},\\; \\{\\emptyset, a\\},\\; \\{\\emptyset, \\{a\\}\\},\\; \\{\\emptyset, \\{\\{a\\}\\}\\},$\\\\\n\\mbox{}$\\;\\{a, \\{a\\}\\},\\; \\{a, \\{\\{a\\}\\}\\},\\; \\{\\{a\\}, \\{\\{a\\}\\}\\},\\; \\{\\emptyset, a, \\{a\\}\\},\\; \\{\\emptyset, a, \\{\\{a\\}\\}\\},$\\\\\n\\mbox{}$\\;\\{\\emptyset, \\{a\\}, \\{\\{a\\}\\}\\},\\; \\{a, \\{a\\}, \\{\\{a\\}\\}\\},\\; \\{\\emptyset, a, \\{a\\}, \\{\\{a\\}\\}\\}\\}$.\n\\item $\\{\\emptyset, \\{a\\}\\}$.\n\\item $\\{\\emptyset, \\{a\\}, \\{\\emptyset, a\\}\\}$.\n\\item $\\{\\emptyset, \\{a\\}, \\{\\emptyset\\}, \\{a, \\emptyset\\}\\}$.\n\\item $\\{\\emptyset, \\{a, \\emptyset\\}\\}$.\n\\end{enumerate}\n\n\\vspace{6pt}\n{\\bf Question 6.}\nGiven two sets $A = \\{ x, y \\}$ and $B = \\{x, \\{x \\}\\}$, check, if statements are true or false:\n\\begin{enumerate}[(A)]\n\\item $x \\subseteq B$.\n\\item $\\emptyset \\in \\mathcal{P}(B)$.\n\\item $\\{x\\} \\subseteq A - B$.\n\\item $|\\mathcal{P}(A)| = 4$.\n\\end{enumerate}\n\n\n\\vspace{6pt}\n{\\bf Question 7.}\nWe define functions $g\\,:\\, A \\rightarrow A$ and $f : A \\rightarrow A$, where $A \\{1, 2, 3, 4\\}$ by \nlisting all argument-value pairs: \n$$g = \\{(1, 4), (2, 1), (3, 1), (4, 2)\\},\\;\\;f = \\{(1, 3), (2, 2), (3, 4), (4, 1)\\}.$$\nFind these functions by listing their argument/value pairs (or establish that they do not exist).\n\\begin{enumerate}[(A)]\n\\item Find $f \\circ g$.\n\\item Find $g \\circ f$.\n\\item Find $g \\circ g$.\n\\item Find $g \\circ (g \\circ g)$.\n\\item Find $f^{-1}$.\n\\item Find $g^{-1}$.\n\\end{enumerate}\n\n\n\\vspace{6pt}\n{\\bf Question 8.} Find these sums:\n\\begin{enumerate}[(A)]\n\\item $1/4 + 1/8 + 1/16 + 1/32 + \\ldots$.\n\\item $2 + 4 + 8 + 16 + 32 + \\ldots + 2^{28}$.\n\\item $2 - 4 + 8 - 16 + 32 - \\ldots - 2^{28}$.\n\\item $1 - 1/2 + 1/4 - 1/8 + 1/16 - \\ldots$.\n\\end{enumerate}\n\n\\vspace{6pt}\n{\\bf Question 9.} Find an appropriate $O(g(n))$ for each function $f(n)$ defined below \n(pick your $g(n)$ to be the slowest growing among the functions such that $f(n)$ is in $O(g(n))$). \n\\begin{enumerate}[(A)]\n\\item $f(n) = 1^2 + 2^2 + \\ldots + n^2$.\n\\item ${\\displaystyle f(n) = \\frac{3n - 8 - 4n^3}{2n - 1}}$. \n\\item ${\\displaystyle f(n) = \\sum\\limits_{k=1}^{n} k^3}$.\n\\item ${\\displaystyle f(n) = \\frac{6n + 4n^5 - 4}{7n^2 - 3}}$. \n\\item ${\\displaystyle f(n) = \\sum\\limits_{k=2}^{n} k\\cdot(k-1)}$.\n\\item ${\\displaystyle f(n) = 3n^2 + 8n + 7}$\n\\end{enumerate}\n\n\\vspace{6pt}\n{\\bf Question 10.}\nFor the given functions, find an optimal $O(g(n))$; find\n$C$ and $n_0$ (from the definition $|f(n)| < C\\cdot |g(n)|$ as long as $n > n_0$). \n\\begin{enumerate}[(A)]\n\\item ${\\displaystyle f(n) = 3n^4 + \\log_2 n^8}$. \n\\item ${\\displaystyle f(n) = \\sum\\limits_{k=1}^{n} (k^3 + k)}$.\n\\item ${\\displaystyle f(n) = (n + 2)\\log_2 (n^2 + 1) + \\log_2 (n^3 + 1)}$.\n\\item ${\\displaystyle f(n) = n^3 + \\sin n^7}$.\n\\end{enumerate}\n\n\n\\vspace{6pt}\n{\\bf Question 11.} This is a Python fragment; variable {\\tt n} can become very large; {\\tt t} is some\nfixed parameter. Denote by $f(n)$ the number of operations depending on the variable {\\tt n}, \nwhere an operation is an addition or a multiplication, or raising to the power 2.\nFind the slowest growing $g(n)$ so that $f(n)$ is in $O(g(n))$. \n\\begin{verbatim}\nsum = 0\nfor i in range(1,n+1):\n    for j in range(1,n+1):\n        sum += (i*t + j*t + 1)**2\n\\end{verbatim}\n\n\\vspace{6pt}\n{\\bf Question 12.} There are two functions $f,g: \\mathbb{R} \\rightarrow \\mathbb{R}$ defined\nfor all real numbers and taking real values.\nFind, which predicate logic expressions describe a statement that is logically\nequivalent to the English sentence ``The function $f(n)$ is in $O(g(n))$''.\\\\\n{\\em Note.} There may be multiple correct answers. \n\n\\begin{enumerate}[(A)]\n\\item $\\forall n \\in \\mathbb{R}\\;\\exists n_0 \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R},$\\\\\n$\\left(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}|g(n)|\\right)$. \n\\item $\\exists n_0 \\in \\mathbb{R}\\;\\forall n \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R},$\\\\\n$(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}|g(n)|)$. \n\\item $\\exists n_0 \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R}\\;\\forall n \\in \\mathbb{R},$\\\\\n$(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}|g(n)|)$. \n\\item $\\exists n_0 \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R}\\;\\forall n \\in \\mathbb{R},$\\\\\n$(n > n_0 \\rightarrow f(n) \\leq C\\cdot{}|g(n)|)$. \n\\item $\\exists n_0 \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R}\\;\\forall n \\in \\mathbb{R},$\\\\\n$(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}g(n))$. \n\\item $\\exists n_0 \\in \\mathbb{R}\\;\\exists C \\in \\mathbb{R}\\;\\forall n \\in \\mathbb{R},$\\\\\n$(n \\geq n_0 \\rightarrow |f(n)| < C\\cdot{}|g(n)|)$. \n\\item $\\exists n_0 \\in \\mathbb{Z}^{+}\\;\\exists C \\in \\mathbb{Z}^{+}\\;\\forall n \\in \\mathbb{R},$\\\\\n$(n > n_0 \\rightarrow |f(n)| \\leq C\\cdot{}|g(n)|)$. \n\\end{enumerate}\n\n\\newpage \n\\subsection{Answers}\n\n\\vspace{6pt}\n{\\bf Question 1.} Answer:\\\\\n\n\\begin{tabular}{ll} \n$\\left| K_2 \\cup K_5 \\right|$ & $42$ \\\\ \n$\\left| K_2 \\cap K_7 \\right|$ & $5$ \\\\ \n$\\left| \\overline{K_7} \\right|$ & $60$ \\\\\n$\\left| \\overline{K_2 \\cap K_5} \\right|$ & $63$ \\\\\n$\\left| K_2 \\cap K_5 \\cap K_7 \\right|$ & $1$ \\\\ \n$\\left| K_2 \\cap K_5 \\cap \\overline{K_7} \\right|$ & $6$ \\\\ \n$\\left| K_2 \\cup K_5 \\cup K_7 \\right|$ & $46$ \\\\ \n$\\left| \\overline{K_2 \\cup K_5 \\cup K_7} \\right|$ & $24$ \\\\ \n\\end{tabular}\n\nTo find $\\left| K_2 \\cup K_5 \\cup K_7 \\right|$ we might use inclusion-exclusion principle: \n$$\\left| K_2 \\cup K_5 \\cup K_7 \\right| = (35 + 14 + 10) - (7 + 5 + 2) + 1 = 46.$$\n\n\n\\vspace{6pt}\n{\\bf Question 2.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 3.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 4.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 5.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 6.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 7.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 8.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 9.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 10.} Answer: TBD\\\\\n\n\\vspace{6pt}\n{\\bf Question 11.} Answer: TBD\\\\\n\n\n\\vspace{6pt}\n{\\bf Question 12.} Answer: TBD\\\\\n\n\n\n\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "da399e08ed1a7c6b8407bd8dfa32ee17b08d13d6", "size": 10779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/site/discrete-spring2020/questionbase/quiz-sample-04.tex", "max_stars_repo_name": "kapsitis/math", "max_stars_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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/site/discrete-spring2020/questionbase/quiz-sample-04.tex", "max_issues_repo_name": "kapsitis/math", "max_issues_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-07-20T03:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T21:50:18.000Z", "max_forks_repo_path": "src/site/discrete-spring2020/questionbase/quiz-sample-04.tex", "max_forks_repo_name": "kapsitis/math", "max_forks_repo_head_hexsha": "f21b172d4a58ec8ba25003626de02bfdda946cdc", "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.3280254777, "max_line_length": 150, "alphanum_fraction": 0.6137860655, "num_tokens": 4208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.6095074737692369}}
{"text": "%!TEX root = ../OGUSAdoc.tex\n\nWe start the \\ogindia section on modeling the household with a description of the demographics of the model. \\citet{Nishiyama:2015} and \\citet{DeBackerEtAl:2017} have recently shown that demographic dynamics are likely the biggest influence on macroeconomic time series, exhibiting more influence than fiscal variables or household preference parameters.\n\nIn this chapter, we characterize the equations and parameters that govern the transition dynamics of the population distribution by age. In \\ogindia, we take the approach of taking mortality rates and fertility rates from outside estimates. But we estimate our immigration rates as residuals using the mortality rates, fertility rates, and at least two consecutive periods of population distribution data. This approach makes sense if one modeling a country in which in one is not confident in the immigration rate data. If the country has good immigration data, then the immigration residual approach we describe below can be skipped.\n\nWe define $\\omega_{s,t}$ as the number of households of age $s$ alive at time $t$. A measure $\\omega_{1,t}$ of households is born in each period $t$ and live for up to $E+S$ periods, with $S\\geq 4$.\\footnote{Theoretically, the model works without loss of generality for $S\\geq 3$. However, because we are calibrating the ages outside of the economy to be one-fourth of $S$ (e.g., ages 21 to 100 in the economy, and ages 1 to 20 outside of the economy), it is convenient for $S$ to be at least 4.} Households are termed ``youth'', and do not participate in market activity during ages $1\\leq s\\leq E$. The households enter the workforce and economy in period $E+1$ and remain in the workforce until they unexpectedly die or live until age $s=E+S$. We model the population with households age $s\\leq E$ outside of the workforce and economy in order most closely match the empirical population dynamics.\n\nThe population of agents of each age in each period $\\omega_{s,t}$ evolves according to the following function,\n\\begin{equation}\\label{EqPopLawofmotion}\n  \\begin{split}\n    \\omega_{1,t+1} &= (1 - \\rho_0)\\sum_{s=1}^{E+S} f_s\\omega_{s,t} + i_1\\omega_{1,t}\\quad\\forall t \\\\\n    \\omega_{s+1,t+1} &= (1 - \\rho_s)\\omega_{s,t} + i_{s+1}\\omega_{s+1,t}\\quad\\forall t\\quad\\text{and}\\quad 1\\leq s \\leq E+S-1\n  \\end{split}\n\\end{equation}\nwhere $f_s\\geq 0$ is an age-specific fertility rate, $i_s$ is an age-specific net immigration rate, $\\rho_s$ is an age-specific mortality hazard rate, and $\\rho_0$ is an infant mortality rate.\\footnote{The parameter $\\rho_s$ is the probability that a household of age $s$ dies before age $s+1$.} The total population in the economy $N_t$ at any period is simply the sum of households in the economy, the population growth rate in any period $t$ from the previous period $t-1$ is $g_{n,t}$, $\\tilde{N}_t$ is the working age population, and $\\tilde{g}_{n,t}$ is the working age population growth rate in any period $t$ from the previous period $t-1$.\n\\begin{equation}\\label{EqPopN}\n  N_t\\equiv\\sum_{s=1}^{E+S} \\omega_{s,t} \\quad\\forall t\n\\end{equation}\n\\begin{equation}\\label{EqPopGrowth}\n  g_{n,t+1} \\equiv \\frac{N_{t+1}}{N_t} - 1 \\quad\\forall t\n\\end{equation}\n\\begin{equation}\\label{EqPopNtil}\n  \\tilde{N}_t\\equiv\\sum_{s=E+1}^{E+S} \\omega_{s,t} \\quad\\forall t\n\\end{equation}\n\\begin{equation}\\label{EqPopGrowthTil}\n  \\tilde{g}_{n,t+1} \\equiv \\frac{\\tilde{N}_{t+1}}{\\tilde{N}_t} - 1 \\quad\\forall t\n\\end{equation}\nWe discuss the approach to estimating fertility rates $f_s$, mortality rates $\\rho_s$, and immigration rates $i_s$ in Sections \\ref{SecDemogFert}, \\ref{SecDemogMort}, and \\ref{SecDemogImm}.\n\n\n\\section{Fertility rates}\\label{SecDemogFert}\n\n  In \\ogindia, we assume that the fertility rates for each age cohort $f_s$ are constant across time. However, this assumption is conceptually straightforward to relax. Our data for U.S. fertility rates by age come from \\citet[Table 3, p. 18]{MartinEtAl:2015} National Vital Statistics Report, which is final fertility rate data for 2013. Figure \\ref{FigFertRates} shows the fertility-rate data and the estimated average fertility rates for $E+S=100$.\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigFertRates}\\textbf{Fertility rates by age ($f_s$) for $E+S=100$}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/fert_rates.png}}}\n  \\end{figure}\n\n  The large blue circles are the 2013 U.S. fertility rate data from \\citet{MartinEtAl:2015}. These are 9 fertility rates $[0.3, 12.3, 47.1, 80.7, 105.5, 98.0, 49.3, 10.4, 0.8]$ that correspond to the midpoint ages of the following age (in years) bins $[10-14, 15-17, 18-19, 20-24, 25-29, 30-34, 35-39, 40-44, 45-49]$. In order to get our cubic spline interpolating function to fit better at the endpoints we added to fertility rates of zero to ages 9 and 10, and we added two fertility rates of zero to ages 55 and 56. The blue line in Figure \\ref{FigFertRates} shows the cubic spline interpolated function of the data.\n\n  The red diamonds in Figure \\ref{FigFertRates} are the average fertility rate in age bins spanning households born at the beginning of period 1 (time = 0) and dying at the end of their 100th year. Let the total number of model years that a household lives be $E+S\\leq 100$. Then the span from the beginning of period 1 (the beginning of year 0) to the end of period 100 (the end of year 99) is divided up into $E+S$ bins of equal length. We calculate the average fertility rate in each of the $E+S$ model-period bins as the average population-weighted fertility rate in that span. The red diamonds in Figure \\ref{FigFertRates} are the average fertility rates displayed at the midpoint in each of the $E+S$ model-period bins.\n\n\n\\section{Mortality rates}\\label{SecDemogMort}\n\n  The mortality rates in our model $\\rho_s$ are a one-period hazard rate and represent the probability of dying within one year, given that an household is alive at the beginning of period $s$. We assume that the mortality rates for each age cohort $\\rho_s$ are constant across time. The infant mortality rate of $\\rho_0=0.00587$ comes from the 2015 U.S. CIA World Factbook. Our data for U.S. mortality rates by age come from the Actuarial Life Tables of the U.S. Social Security Administration \\citep[see][]{SocSec:2015}, from which the most recent mortality rate data is for 2011. Figure \\ref{FigMortRates} shows the mortality rate data and the corresponding model-period mortality rates for $E+S=100$.\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigMortRates}\\textbf{Mortality rates by age ($\\rho_s$) for $E+S=100$}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/mort_rates.png}}}\n  \\end{figure}\n\n  The mortality rates in Figure \\ref{FigMortRates} are a population-weighted average of the male and female mortality rates reported in \\citet{SocSec:2015}. Figure \\ref{FigMortRates} also shows that the data provide mortality rates for ages up to 111-years-old. We truncate the maximum age in years in our model to 100-years old. In addition, we constrain the mortality rate to be 1.0 or 100 percent at the maximum age of 100.\n\n\n\\section{Immigration rates}\\label{SecDemogImm}\n\n  Because of the difficulty in getting accurate immigration rate data by age, we estimate the immigration rates by age in our model $i_s$ as the average residual that reconciles the current-period population distribution with next period's population distribution given fertility rates $f_s$ and mortality rates $\\rho_s$. Solving equations \\eqref{EqPopLawofmotion} for the immigration rate $i_s$ gives the following characterization of the immigration rates in given population levels in any two consecutive periods $\\omega_{s,t}$ and $\\omega_{s,t+1}$ and the fertility rates $f_s$ and mortality rates $\\rho_s$.\n\n  \\begin{equation}\\label{EqPopImmRates}\n    \\begin{split}\n      i_1 &= \\frac{\\omega_{1,t+1} - (1 - \\rho_0)\\sum_{s=1}^{E+S}f_s\\omega_{s,t}}{\\omega_{1,t}}\\quad\\forall t \\\\\n      i_{s+1} &= \\frac{\\omega_{s+1,t+1} - (1 - \\rho_s)\\omega_{s,t}}{\\omega_{s+1,t}}\\qquad\\qquad\\forall t\\quad\\text{and}\\quad 1\\leq s \\leq E+S-1\n    \\end{split}\n  \\end{equation}\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigImmRates}\\textbf{Immigration rates by age ($i_s$), residual, $E+S=100$}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/imm_rates_orig.png}}}\n  \\end{figure}\n\n  We calculate our immigration rates for three different consecutive-year-periods of population distribution data (2010 through 2013). Our four years of population distribution by age data come from \\citet{Census:2015}. The immigration rates $i_s$ that we use in our model are the the residuals described in \\eqref{EqPopImmRates} averaged across the three periods. Figure \\ref{FigImmRates} shows the estimated immigration rates for $E+S=100$ and given the fertility rates from Section \\ref{SecDemogFert} and the mortality rates from Section \\ref{SecDemogMort}.\n\n  At the end of Section \\ref{SecDemogPopSSTP}, we describe a small adjustment that we make to the immigration rates after a certain number of periods in order to make computation of the transition path equilibrium of the model compute more robustly.\n\n\n\\section{Population steady-state and transition path}\\label{SecDemogPopSSTP}\n\n  This model requires information about mortality rates $\\rho_s$ in order to solve for the household's problem each period. It also requires the steady-state stationary population distribution $\\bar{\\omega}_{s}$ and population growth rate $\\bar{g}_n$ as well as the full transition path of the stationary population distribution $\\hat{\\omega}_{s,t}$ and population grow rate $\\tilde{g}_{n,t}$ from the current state to the steady-state. To solve for the steady-state and the transition path of the stationary population distribution, we write the stationary population dynamic equations \\eqref{EqPopLawofmotionStat} and their matrix representation \\eqref{EqPopLOMstatmat}.\n  \\begin{equation}\\label{EqPopLawofmotionStat}\n    \\begin{split}\n      \\hat{\\omega}_{1,t+1} &= \\frac{(1-\\rho_0)\\sum_{s=1}^{E+S} f_s\\hat{\\omega}_{s,t} + i_1\\hat{\\omega}_{1,t}}{1+\\tilde{g}_{n,t+1}}\\quad\\forall t \\\\\n      \\hat{\\omega}_{s+1,t+1} &= \\frac{(1 - \\rho_s)\\hat{\\omega}_{s,t} + i_{s+1}\\hat{\\omega}_{s+1,t}}{1+\\tilde{g}_{n,t+1}}\\qquad\\quad\\:\\forall t\\quad\\text{and}\\quad 1\\leq s \\leq E+S-1\n    \\end{split}\n  \\end{equation}\n  \\begin{equation}\\label{EqPopLOMstatmat}\n    \\begin{split}\n      & \\begin{bmatrix}\n        \\hat{\\omega}_{1,t+1} \\\\ \\hat{\\omega}_{2,t+1} \\\\ \\hat{\\omega}_{2,t+1} \\\\ \\vdots \\\\ \\hat{\\omega}_{E+S-1,t+1} \\\\ \\hat{\\omega}_{E+S,t+1}\n      \\end{bmatrix}= \\frac{1}{1 + g_{n,t+1}} \\times ... \\\\\n      & \\begin{bmatrix}\n        (1-\\rho_0)f_1+i_1 & (1-\\rho_0)f_2 & (1-\\rho_0)f_3 & \\hdots & (1-\\rho_0)f_{E+S-1} & (1-\\rho_0)f_{E+S} \\\\\n        1-\\rho_1 & i_2 & 0 & \\hdots & 0 & 0 \\\\\n        0 & 1-\\rho_2 & i_3 & \\hdots & 0 & 0 \\\\\n        \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n        0 & 0 & 0 & \\hdots & i_{E+S-1} & 0 \\\\\n        0 & 0 & 0 & \\hdots & 1-\\rho_{E+S-1} & i_{E+S}\n      \\end{bmatrix}\n      \\begin{bmatrix}\n        \\hat{\\omega}_{1,t} \\\\ \\hat{\\omega}_{2,t} \\\\ \\hat{\\omega}_{2,t} \\\\ \\vdots \\\\ \\hat{\\omega}_{E+S-1,t} \\\\ \\hat{\\omega}_{E+S,t}\n      \\end{bmatrix}\n    \\end{split}\n  \\end{equation}\n  We can write system \\eqref{EqPopLOMstatmat} more simply in the following way.\n  \\begin{equation}\\label{EqPopLOMstatmat2}\n    \\bm{\\hat{\\omega}}_{t+1} = \\frac{1}{1+g_{n,t+1}}\\bm{\\Omega}\\bm{\\hat{\\omega}}_t \\quad\\forall t\n  \\end{equation}\n  The stationary steady-state population distribution $\\bm{\\bar{\\omega}}$ is the eigenvector $\\bm{\\omega}$ with eigenvalue $(1+\\bar{g}_n)$ of the matrix $\\bm{\\Omega}$ that satisfies the following version of \\eqref{EqPopLOMstatmat2}.\n  \\begin{equation}\\label{EqPopLOMss}\n    (1+\\bar{g}_n)\\bm{\\bar{\\omega}} = \\bm{\\Omega}\\bm{\\bar{\\omega}}\n  \\end{equation}\n\n  \\begin{proposition}\n    If the age $s=1$ immigration rate is $i_1>-(1-\\rho_0)f_1$ and the other immigration rates are strictly positive $i_s>0$ for all $s\\geq 2$ such that all elements of $\\bm{\\Omega}$ are nonnegative, then there exists a unique positive real eigenvector $\\bm{\\bar{\\omega}}$ of the matrix $\\bm{\\Omega}$, and it is a stable equilibrium.\n  \\end{proposition}\n\n  \\begin{proof}\n    First, note that the matrix $\\bm{\\Omega}$ is square and non-negative.  This is enough for a general version of the Perron-Frobenius Theorem to state that a positive real eigenvector exists with a positive real eigenvalue. This is not yet enough for uniqueness. For it to be unique by a version of the Perron-Fobenius Theorem, we need to know that the matrix is irreducible. This can be easily shown. The matrix is of the form\n    $$\\bm{\\Omega} =\n    \\begin{bmatrix}\n      * & *  & * & \\hdots & * & * & *\\\\\n      * & * & 0 & \\hdots & 0 & 0 & 0 \\\\\n      0 & * & * & \\hdots & 0 & 0 & 0 \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\\n      0 & 0 & 0 & \\hdots & *  & * & 0 \\\\\n      0 & 0 & 0 & \\hdots & 0 & * & *\n    \\end{bmatrix}\n    $$\n    Where each * is strictly positive. It is clear to see that taking powers of the matrix causes the sub-diagonal positive elements to be moved down a row and another row of positive entries is added at the top. None of these go to zero since the elements were all non-negative to begin with.\n    $$\\bm{\\Omega}^2 =\n    \\begin{bmatrix}\n      * & *  & * & \\hdots & * & * & *\\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      0 & * & * & \\hdots & 0 & 0 & 0 \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\\n      0 & 0 & 0 & \\hdots & *  & * & 0 \\\\\n      0 & 0 & 0 & \\hdots & 0 & * & *\n    \\end{bmatrix}; ~~~\n    \\bm{\\Omega}^{S+E-1} =\n    \\begin{bmatrix}\n      * & *  & * & \\hdots & * & * & *\\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\\n      * & * & * & \\hdots & *  & * & * \\\\\n      0 & 0 & 0 & \\hdots & 0 & * & *\n    \\end{bmatrix}\n    $$\n    $$\\bm{\\Omega}^{S+E} =\n    \\begin{bmatrix}\n      * & *  & * & \\hdots & * & * & *\\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots \\\\\n      * & * & * & \\hdots & * & * & * \\\\\n      * & * & * & \\hdots & * & * & *\n    \\end{bmatrix}\n    $$\n    Existence of an $m \\in \\mathbb N $ such that $\\left(\\bf\\Omega^m\\right)_{ij} \\neq 0 ~~ ( > 0)$ is one of the definitions of an irreducible (primitive) matrix. It is equivalent to saying that the directed graph associated with the matrix is strongly connected. Now the Perron-Frobenius Theorem for irreducible matrices gives us that the equilibrium vector is unique.\n\n    We also know from that theorem that the eigenvalue associated with the positive real eigenvector will be real and positive. This eigenvalue, $p$, is the Perron eigenvalue and it is the steady state population growth rate of the model. By the PF Theorem for irreducible matrices, $| \\lambda_i | \\leq p$ for all eigenvalues $\\lambda_i$ and there will be exactly $h$ eigenvalues that are equal, where $h$ is the period of the matrix. Since our matrix $\\bf\\Omega$ is aperiodic, the steady state growth rate is the unique largest eigenvalue in magnitude. This implies that almost all initial vectors will converge to this eigenvector under iteration.\n  \\end{proof}\n\n  For a full treatment and proof of the Perron-Frobenius Theorem, see \\citet{Suzumura:1983}. Because the population growth process is exogenous to the model, we calibrate it to annual age data for age years $s=1$ to $s=100$.\n\n  Figure \\ref{FigOrigVsFixSSpop} shows the steady-state population distribution $\\bm{\\bar{\\omega}}$ and the population distribution after 120 periods $\\bm{\\hat{\\omega}}_{120}$. Although the two distributions look very close to each other, they are not exactly the same.\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigOrigVsFixSSpop}\\textbf{Theoretical steady-state population distribution vs. population distribution at period $t=120$}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/OrigVsFixSSpop.png}}}\n  \\end{figure}\n\n  Further, we find that the maximum absolute difference between the population levels $\\hat{\\omega}_{s,t}$ and $\\hat{\\omega}_{s,t+1}$ was $1.3852\\times 10^{-5}$ after 160 periods. That is to say, that after 160 periods, given the estimated mortality, fertility, and immigration rates, the population has not achieved its steady state. For convergence in our solution method over a reasonable time horizon, we want the population to reach a stationary distribution after $T$ periods. To do this, we artificially impose that the population distribution in period $t=120$ is the steady-state. As can be seen from Figure \\ref{FigOrigVsFixSSpop}, this assumption is not very restrictive. Figure \\ref{FigImmRateChg} shows the change in immigration rates that would make the period $t=120$ population distribution equal be the steady-state. The maximum absolute difference between any two corresponding immigration rates in Figure \\ref{FigImmRateChg} is 0.0028.\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigImmRateChg}\\textbf{Original immigration rates vs. adjusted immigration rates to make fixed steady-state population distribution}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/OrigVsAdjImm.png}}}\n  \\end{figure}\n\n  The most recent year of population data come from \\citet{Census:2015} population estimates for both sexes for 2013. We those data and use the population transition matrix \\eqref{EqPopLOMstatmat2} to age it to the current model year of 2015. We then use \\eqref{EqPopLOMstatmat2} to generate the transition path of the population distribution over the time period of the model. Figure \\ref{FigPopDistPath} shows the progression from the 2013 population data to the fixed steady-state at period $t=120$. The time path of the growth rate of the economically active population $\\tilde{g}_{n,t}$ is shown in Figure \\ref{FigGrowthPath}.\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigPopDistPath}\\textbf{Stationary population distribution at periods along transition path}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/PopDistPath.png}}}\n  \\end{figure}\n\n  \\begin{figure}[htbp]\\centering \\captionsetup{width=4.0in}\n    \\caption{\\label{FigGrowthPath}\\textbf{Time path of the population growth rate $\\tilde{g}_{n,t}$}}\n    \\fbox{\\resizebox{4.0in}{3.0in}{\\includegraphics{./images/GrowthPath.png}}}\n  \\end{figure}\n", "meta": {"hexsha": "b8512bbad91d22d14dc94478d4063d9809161870", "size": 18642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/LaTeXsource/Chapters/Chap_Demog.tex", "max_stars_repo_name": "keshavchoudhary87/OG-India", "max_stars_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-17T19:49:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-17T19:49:22.000Z", "max_issues_repo_path": "docs/LaTeXsource/Chapters/Chap_Demog.tex", "max_issues_repo_name": "keshavchoudhary87/OG-India", "max_issues_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2019-08-16T15:40:52.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-16T07:07:15.000Z", "max_forks_repo_path": "docs/LaTeXsource/Chapters/Chap_Demog.tex", "max_forks_repo_name": "keshavchoudhary87/OG-India", "max_forks_repo_head_hexsha": "269ee172b837882c826ee7f99507d93f9643128e", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 44, "max_forks_repo_forks_event_min_datetime": "2019-08-16T15:10:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-08T07:03:26.000Z", "avg_line_length": 96.5906735751, "max_line_length": 954, "alphanum_fraction": 0.7091513786, "num_tokens": 5610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.7154239957834734, "lm_q1q2_score": 0.6095074724246174}}
{"text": "\\documentclass[12pt]{article}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1ex}\n\n\\begin{document}\n\n\\section{Notation}\n\\begin{itemize}\n    \\item $t_n$: date step, $n = 1, \\cdots, N$\n    \\item $m$: item (e.g.\\ contract number), $m = 1, \\cdots, M$\n    \\item $s(m,t_n)$: a series of marks. \n    \\item If $t_{n}$ is a roll date, \n    \\begin{itemize}\n        \\item $s(m,t_{n-1})$ becomes $s(m-1, t_n)$\n        \\item $s(1,t_{n-1})$ rolls off, i.e.\\ disappears\n        \\item $s(M, t_{n})$ appears as a new item\n    \\end{itemize}\n    \\item $q(m,t_n)$: adjusted marks\n    \\item $\\alpha(m, t)$: drift slope calculated for the $m$-th item as of $t$\n    \\item $T(m,t)$: the roll-off (i.e.\\ maturity) date for the $m$-th item as of $t$\n    \\item $\\phi(m,j)$: last drift slope tracked for the $m$-th item over the $j$-th rolling period $[r_j, r_{j+1})$\n    \\item $t' - t$: year-fraction from $t$ to $t'$ calculated using the Act 365 convention. \n\n\\end{itemize}\n\n\\section{Drift Adjustment}\n\n\\subsection{Remarking Criteria}\n\n$t_n$ is a remarked date for the $m$-th item if\n\\begin{itemize}\n    \\item if $t_n$ is not a roll date: \n    \\begin{equation}\n        \\left|\\frac{s(m, t_n) - s(m, t_{n-1})}{s(m, t_{n-1})} \\right| > \\epsilon \n    \\end{equation}\n    \\item if $t_n$ is a roll date:\n    \\begin{equation}\n        \\left|\\frac{s(m, t_n) - s(m + 1, t_{n-1})}{s(m + 1, t_{n-1})} \\right| > \\epsilon \n    \\end{equation}\n\\end{itemize}\nfor some $\\epsilon > 0$. \n\n\n\\subsection{Slope Function}\n\nGiven $\\{s(m,t)\\}_{m}$, the $m$-th slope $\\alpha(m, t)$ is calculated by\n\\begin{eqnarray}\n    \\alpha(1, t) & = & \\frac{s(1,t)}{T(1, t) - t} \\\\\n    \\alpha(m, t) & = & \\frac{s(m,t) - s(m-1,t)}{T(m,t) - T(m-1,t)} \\textrm{ for } m = 2, \\cdots, M\n\\end{eqnarray}\n\n{\\bf Note}: For standardised products like Futures, we may assume $T(m, t) - T(m-1, t) = 90/365$ for simplicity. \n\n{\\bf Motivation}: Consider two marks: $s(m,t)$ and $s(m-1,t)$.\nAfter time is elapsed by $\\Delta := (T(m,t) - T(m-1,t))$, the time-to-roll-off of the first item becomes $(T(m-1,t)-t)$, which is the current time-to-roll-off of the second item. \n\nTherefore, the natural adjustment slope is the one makes\n$$q(m, t + \\Delta) = s(m-1, t)$$\nif no remarks occurs for all future time steps. \n\n\n\n\n\\subsection{Algorithm}\n\nConsider a rolling period $I_j = \\{t_n| t_n \\in [r_j, r_{j+1}]\\}$ where $r_j$ and $r_{j+1}$ are two adjacent rolling dates. Assume that $t_0 \\in I_0$ and $t_N \\in I_J$. \n\nFor each rolling period $j$ starting from $0$ to $J$:\n\\begin{enumerate}\n    \\item Initialisation: Let $t^j$ be the first date in the period, i.e.\\ $t^j := \\max\\{t_0, r_j\\}$ \n    \\begin{itemize}\n        \\item If $j = 0$ or $t^j$ is a remark date, simply set \n        \\begin{itemize}\n            \\item $q(m,t^j) = s(m, t^j)$\n            \\item $\\phi(m, j) = \\alpha(m, t^j)$\n        \\end{itemize}\n        for $m = 1, \\cdots, M$.\n        \\item Otherwise, $j > 0$ and $t^j$ is not a remark date. \n        \n        For $m = 1, \\cdots M-1$, set\n        \\begin{itemize}\n            \\item $\\phi(m, j) = \\phi(m+1, j-1)$, i.e.\\ carry over the slope from the previous period\n            \\item $q(m,t^j) = q(m + 1, p(t^j)) - \\phi(m,j) (t^j - p(t^j))$\n        \\end{itemize}\n        where $p(t)$ is the previous time step in $\\{t_n\\}$. \n\n        For $m = M$, borrowing from $m = M-1$, set\n        \\begin{itemize}\n            \\item $\\phi(M, j) = \\phi(M-1, j)$, i.e. the slope is carried over. \n            \\item $q(M,t^j) = s(M, t^j) + [q(M-1,t^j) - s(M-1,t^j)]$\n        \\end{itemize}\n\n    \\end{itemize}\n\n    \\item For each $t_n$ with $t^j < t_n < r_{j+1}$: \n    \\begin{itemize}\n        \\item If $t_n$ is a remarked date, set\n        \\begin{itemize}\n            \\item $q(m,t_n) = s(m, t_n)$\n            \\item $\\phi(m, j) = \\alpha(m, t_n)$\n        \\end{itemize}\n        for $m = 1, \\cdots, M$\n        \\item Otherwise i.e. not remarked\n\n        \\begin{itemize}\n            \\item $q(m,t_n) = q(m, t_{n-1}) - \\phi(m,j) (t_{n} - t_{n-1})$\n        \n            \\item $\\phi(m, j)$: no update\n        \\end{itemize}\n        for $m = 1, \\cdots, M$\n\n\n            \n    \\end{itemize}\n\\end{enumerate}\n\n\\end{document}$", "meta": {"hexsha": "7e706603a8be8a088c74f4d7c37daa7fc7430a15", "size": 4116, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/remarking_adjustment/remarking_adjustment.tex", "max_stars_repo_name": "xyise/xyise", "max_stars_repo_head_hexsha": "e2bc1c2e824da4fc5cd1d81aaef76a1ad147fb01", "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": "notebook/remarking_adjustment/remarking_adjustment.tex", "max_issues_repo_name": "xyise/xyise", "max_issues_repo_head_hexsha": "e2bc1c2e824da4fc5cd1d81aaef76a1ad147fb01", "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": "notebook/remarking_adjustment/remarking_adjustment.tex", "max_forks_repo_name": "xyise/xyise", "max_forks_repo_head_hexsha": "e2bc1c2e824da4fc5cd1d81aaef76a1ad147fb01", "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.8813559322, "max_line_length": 179, "alphanum_fraction": 0.5466472303, "num_tokens": 1540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6095074672553688}}
{"text": "\\SecDef{expo}{Decomposition based on Finite Field Logarithm}\n\n\\subsection{BelT Block Cipher and its S-Box}\n\nBelT is a block cipher from the Belarusian cryptographic standard~\\cite{BELT}. It uses an 8-bit S-Box $H\\colon \\field{8} \\to \\field{8}$ which is given as a look-up table in the standard. The rationale behind this S-Box is not given in the standard, but instead in a separate rationale document by Agievich~\\etal{}~\\cite{BELTratio}.\n\n\\begin{proposition}[The BelT S-Box Construction, \\cite{BELTratio} (translated)]\nThe look-up tables of the S-Box coordinate functions were chosen as different segments of length 255 of different linear recurrences defined by the irreducible polynomial $p(\\lambda)$:\n$$\np(\\lambda) = \\lambda^8 + \\lambda^6 + \\lambda^5 + \\lambda^2 + 1.\n$$\nAdditionally, a zero element was inserted in a fixed position of each segment.\n\\end{proposition}\n\nAgievich also explains in~\\cite{AA2004,AA2004rus} that such a construction is equivalent to an \\emph{exponential} function in the finite field. \n\n\\newcommand\\fexp[2]{#1^{(#2)}}\n\\newcommand\\pexp[1]{\\mathsf{exp}_{#1}}\n\\newcommand\\plog[1]{\\mathsf{log}_{#1}}\n\n\\begin{definition}\nFor a primitive element $w \\in \\fielde{n}$ let $x \\mapsto \\fexp{w}{x}$ be the map from $\\field{n}$ to itself, obtained by raising $w$ to the power given by the integer represented by $x \\in \\field{n}$, and representing the result as an element of $\\field{n}$, where the polynomial defining the field should be clear from context.\n\nThe exponential mapping can be turned into a permutation of $\\field{n}$ by letting it map 0 to 0. Let $w \\in \\fielde{n}$ be a primitive element. Let $\\pexp{w}$ be a permutation of $\\field{n}$ given by:\n$$\n\\pexp{w}(x) \\eqdef \\mapsto \\begin{cases}\n0, &~\\text{if}~x = 0,\\\\\n\\fexp{w}{x}, &~\\text{otherwise}.\n\\end{cases}\n$$\nLet $\\plog{w}\\colon \\field{n} \\to \\field{n}$ denote the functional inverse of $\\pexp{w}$:\n$$\n\\plog{w} \\eqdef \\pexp{w}^{-1}.\n$$\n\\end{definition}\n\n\\begin{remark}\nIn the S-Box $H$ used in BelT, the zero was inserted at $x = \\hex{0a} \\in \\field{8}$ instead of 0.\n\\end{remark}\n\n\\FigRef{h_lat} shows the Jackson Pollock representations of the column and row frequency tables of the LAT of $H$. In the row frequency table several rows stick out, similarly to the special columns in the column frequency table of the LAT of $\\pi$. This similarity suggests that there might be a relation between $H$ and the inverse of $\\pi$. \n\nSince this chapter is devoted to $\\pi$, for a closer analysis of the S-Box used in BelT, I refer to our paper~\\cite{OurKuz2}.\n\n\\FigTex{h_lat.tex}\n\n\n\\subsection{Exponential Behaviour of $\\pi$}\n\nAn exponential function $x \\mapsto w^x$ has the following property: for all $x,c \\in \\field{8}$\n$$\n\\fexp{w}{x + c} = \\fexp{w}{x} \\fmult \\fexp{w}{c}.\n$$\nThis property can be used to distinguish exponential permutations or functions close to them. However, the integer addition can be partially hidden by a whitening affine layer. Still, a strong property can be observed if the addition is approximated by \\txor{}. Indeed, for a unit vector $e_i$ of $\\field{n}$ and all $x \\in \\field{8}$,\n$$\nx \\oplus e_i =\n\\begin{cases}\nx \\boxplus e_i, & ~\\text{if}~ \\inprod{x, e_i} = 0,\\\\\nx \\boxminus e_i, & ~\\text{if}~ \\inprod{x, e_i} = 1.\n\\end{cases}\n$$\n\nAn advantage of this approximation is that the \\txor{} with $e_i$ after a whitening input linear map $L \\in \\linbij{n}$ maps back to the \\txor{} with $L^{-1}(e_i)$ before the application of $L$. And indeed such behaviour can be observed in $\\pi$! By an exhaustive search over the parameters, the following relations were found in $\\pi$.\n\n\\begin{observation}\nLet $c \\in \\pround{\\hex{12}, \\hex{26}, \\hex{24}, \\hex{30}}$. For any $i \\in \\seg{1}{4}$\n\\begin{equation}\n\\Label{eq:exprel}\n\\Pr_{x \\in \\field{8}} \\psquare{\n    \\begin{aligned}\n    \\pi^{-1}(x \\oplus c_i) = \\pi^{-1}(x) \\fmult X^{2^{i-1}} && ~\\text{or}\\\\\n    \\pi^{-1}(x \\oplus c_i) = \\pi^{-1}(x) \\fdiv X^{2^{i-1}}. &&\n    \\end{aligned}\n} = 240/256,\n\\end{equation}\nwhere multiplication $\\fmult$ and division $\\fdiv$ are performed in the finite field $\\fielde{8} \\simeq \\field{}[X]/(X^8 + X^4 + X^3 + X^2 + 1)$ and $X$ defines a primitive element.\n\\end{observation}\n\n\\newcommand\\taupi{\\plog{X} \\circ \\pi^{-1}}\n\nThis strong property suggests that the output side of $\\pi^{-1}$ is not masked by a random linear layer. Otherwise, the multiplication and the division by $X^{2^i}$ would be masked and not triggered by the constant \\txor{} in the input. Therefore, we assume that the output of $\\pi^{-1}$ is the output of an exponential function composed with some simple layer. The simple layer then can be analyzed separately as $\\taupi$.\n\n\n\\subsection{Decomposing the Arithmetic Layer}\n\nOur hypothesis was that there  is a linear whitening layer mapping all $c_i$ to unit vectors. Equation~\\Ref{eq:exprel} suggests that the unit vectors are consecutive powers of 2. Let $\\alpha \\in \\linbij{8}$ be given by\n$$\n\\alpha \\eqdef \\matb{\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n    0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 \\\\\n    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n}^{-1}.\n$$\nIt is such that for all $i \\in \\pset{1,2,3,4}$, $\\alpha(c_i)$ is the unit vector corresponding to $2^{i-1}$. Preimages of the other four unit vectors were chosen randomly to complete the map. The look-up table of $\\taupi \\circ \\alpha^{-1}$ is given in \\TabRef{taupialpha}. \n\n\\FigTex{taupialpha.tex}\n\nThe rows of \\TabRef{taupialpha} are clearly structured. We observe that each row can be sorted by modifying the linear mapping $\\alpha$ (except the zero value). Indeed, let $\\beta \\in \\linbij{8}$ be given by\n$$\n\\beta \\eqdef \\matb{\n    1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & 1 & 1 & 1 & 0 \\\\\n    1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n    0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 & 0 & 1 & 1 & 0 \\\\\n    1 & 0 & 1 & 0 & 0 & 0 & 1 & 1 \\\\\n    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n}.\n$$\nThen the look-up table of $\\taupi \\circ \\beta^{-1}$ is the same as the look-up table of $\\taupi \\circ \\alpha^{-1}$ with sorted rows.\nIt is shown in \\TabRef{taupibeta}.\n\n\\FigTex{taupibeta.tex}\n\nFurthermore, the rows can be reordered by applying a 4-bit nonlinear mapping to the left branch. Let $q$ be a permutation of $\\field{4}$ given by its lookup table\n$$\n\\lookup{q} \\eqdef (12, 2, 9, 10, 13, 6, 3, 5, 11, 4, 8, 15, 14, 7, 0, 1).\n$$\nLet $q_L$ be a permutation of $\\field{8}$ made by applying $q$ to the left half of the input:\n$$\nq_L(x, y) \\eqdef (q(x), y)).\n$$\nThen the look-up table of $\\taupi \\circ \\beta^{-1} \\circ q_L^{-1}$ has a very simple structure. It is shown in \\TabRef{taupibetaq}. This structure has a simple arithmetic expression. As a result, an algorithmic decomposition of $\\pi^{-1}$ can be deduced. It is given in Algorithm~\\Ref{alg:pinv}.\n\n\\begin{remark}\nIt is also possible to define $q$ such that it moves the row $(17, 34, \\ldots, 255, 0)$ to the end of the table. This change results in similar expressions.\n\\end{remark}\n\n\\FigTex{taupibetaq.tex}\n\n\\begin{algorithm}\n    \\caption{\\Label{alg:pinv}\n        Computing the inverse of $\\pi$: $y = \\pi^{-1}(x)$.\n    }\n    \\begin{algorithmic}[1]\n        \\State{$(l, r) \\gets \\beta(x)$}\n        \\State{$l \\gets q(l)$}\n        \\If{$l = 0$}\n            \\State{$z \\gets 17 \\times ((r + 1) \\mod 16)$} \\Comment{integer arithmetic}\n        \\Else\n            \\State{$z \\gets 17 \\times l + r - 16$} \\Comment{integer arithmetic}\n        \\EndIf\n        \\State{$y \\gets \\plog{X}(z)$}\n        \\State{\\Return{$y$}}\n    \\end{algorithmic}\n\\end{algorithm}\n\n\n\\subsection{Obtaining a Decomposition of $\\pi$}\n\n\\newcommand\\arith{\\widehat{\\pi}}\nLet $\\arith$ be the permutation of $\\field{8}$ given by\n$$\n    \\arith \\eqdef \\plog{X} \\circ \\pi^{-1} \\circ \\beta^{-1} \\circ q_L^{-1}.\n$$\nIt corresponds to the arithmetic part of the decomposition. Observe that it has a TU-decomposition as $\\pi$ has itself (see Section~\\Ref{sec:tu}).\n\n\\begin{observation}\nThere exist permutations of $\\field{4}$ $T_{\\hex{0}},\\ldots,T_{\\hex{f}}$ and $U_{\\hex{0}}, \\ldots, U_{\\hex{f}}$ such that for all $l,r \\in \\field{4}$\n$$\n\\arith(l,r) = U_{T_l(r)}(l), T_l(r).\n$$\n\n\\FigTex{arith-tu.tex}\n\nSuch $T,U$ are given in \\TabRef{arith-tu}. They can also be expressed arithmetically:\n\n\\begin{equation*}\n    T_k(x) = \\begin{cases}\n    x + k, \\mbox{ if } k \\ne 0, \\\\\n    x + k + 1, \\mbox{ otherwise},\n    \\end{cases}\n    U_k(x) = \\begin{cases}\n    ((x - k - 1) \\mod{15}) + k + 1, \\mbox{ if } x \\ne 0, \\\\\n    k, \\mbox{ otherwise}.\n    \\end{cases}\n\\end{equation*}\n\\end{observation}\n\n$T$ and $U$ can be inverted separately. By further using the finite field logarithm and inverses of $\\beta$ and $q_L$, the logarithmic decomposition of $\\pi$ is obtained. The corresponding algorithm is given in Algorithm~\\Ref{alg:forward} and graphical representation is given in \\FigRef{logarithmic}.\n\n\\begin{algorithm}\n    \\caption{Computing the S-Box $y = \\pi(x)$ using the logarithmic decomposition.}\n    \\Label{alg:forward}\n    \\begin{algorithmic}\n        \\State{$(l, r) \\gets \\plog{X}(x)$}\n        \\State{$l \\gets l - r$}\n        \\If{$l = 0$}\n            \\State{$r \\gets r - 1$}\n        \\Else\n            \\State{$l \\gets (l + r - 1) \\mod 15 + 1$}\n        \\EndIf\n        \\State{$r \\gets r - l$}\n        \\State{$l \\gets q^{-1}(l)$}\n        \\State{$y \\gets \\beta^{-1}(l||r)$}\n        \\State{\\Return{$y$}}\n    \\end{algorithmic}\n\\end{algorithm}\n\n\\FigTex{logarithmic}\n", "meta": {"hexsha": "838df3cf6a99b05cdd62a188ac8b47699e7e40c7", "size": 9531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis-source/9strKuz/20expo.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/20expo.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/20expo.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": 46.0434782609, "max_line_length": 423, "alphanum_fraction": 0.642115203, "num_tokens": 3289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6094903345917007}}
{"text": "\\section{Hierarchization on Full Grids (Unidirectional Principle)}\n\\label{sec:42fullGrids}\n\nIf $\\sgset$ is a full grid $\\fgset{\\*l}$\n(see \\cref{sec:21nodalSpaces}),\nthe well-known \\up\ncan be used to apply $\\linop$ to input data $\\vlinin$.\nAs shown in \\cref{fig:unidirectionalPrinciple} for a sparse grid,\nthe idea of the \\up\nis to apply the corresponding one-dimensional operators on the\none-dimensional subgrids (the \\term{poles}) of $\\sgset$,\nwhich is repeated for all dimensions.\nIn this section, we first formulate the \\up for\ngeneral linear operators $\\linop$ and then prove its correctness for\nthe case $\\linop = \\intpmatinv$ of hierarchization.\nThe correctness for arbitrary tensor product operators\nwill follow from \\cref{sec:45spatAdaptiveUP}.\n\n\\begin{figure}\n  \\includegraphics{unidirectionalPrinciple_1}%\n  \\caption[%\n    Unidirectional principle%\n  ]{%\n    Application of a linear operator $\\linop$\n    on two-dimensional sparse grid data with the unidirectional principle.\n    \\emph{Left:}\n    The univariate operator $\\upopuv{1}{\\lisetpole}$ is applied on\n    the input data $\\vlinin$\n    along poles $\\lisetpole$ of the first dimension $x_1$.\n    \\vspace{-0.2em}%\n    \\emph{Center:}\n    The univariate operator $\\upopuv{2}{\\lisetpole}$ is applied on the\n    resulting intermediate data $\\vlinout[(1)]$\n    along poles $\\lisetpole$ of the second dimension $x_2$.\n    \\emph{Right:}\n    Final values $\\vlinout = \\linop[\\vlinin]$ after the application\n    on both dimensions.\n    All grid points of the same color are part of the same pole $\\lisetpole$\n    (equivalence classes of $\\samepole{t}$ in\n    \\cref{alg:unidirectionalPrinciple}).%\n  }%\n  \\label{fig:unidirectionalPrinciple}%\n\\end{figure}\n\n\\paragraph{Unidirectional principle and its correctness}\n\nWe state the \\up in \\cref{alg:unidirectionalPrinciple}.\nThe algorithm is given a permutation $(t_1, \\dotsc, t_d)$ of $(1, \\dotsc, d)$\nthat specifies the order of dimensions in which the \\up should be applied.\nWe denote with $\\upopuv{t_j}{\\lisetpole}$ the one-dimensional version of $\\linop$\napplied in dimension $t_j$ ($j = 1, \\dotsc, d$) on the pole $\\lisetpole$.\nFormally, a pole is an equivalence class of the\n\\term{pole equivalence relation} $\\samepole{t_j}$ on $\\liset$:\n\\begin{equation}\n  \\label{eq:poleEquivalenceRelation}\n  \\*k' \\samepole{t_j} \\*k'' \\iff \\*k'_{-t_j} = \\*k''_{-t_j},\\quad\n  \\*k', \\*k'' \\in \\liset.\n\\end{equation}\nWe prove the correctness of the \\up with the following invariant:\n\n\\begin{algorithm}\n  \\begin{algorithmic}[1]\n    \\Function{$\\vlinout = \\texttt{unidirectionalPrinciple}$}{%\n      $\\vlinin$, $\\liset$, $(t_1, \\dotsc, t_d)$%\n    }\n      \\State{$\\vlinout[(0)] \\gets \\vlinin$}\n      \\For{$j = 1, \\dotsc, d$}\n        \\For{$\\lisetpole \\in \\eqclasses{\\liset}{\\samepole{t_j}}$}\n          \\State{%\n            $(\\linout[(j)]{\\*k})_{\\*k \\in \\lisetpole} \\gets\n            \\upopuv{t_j}{\\lisetpole}\n            \\bracket*{(\\linout[(j-1)]{\\*k})_{\\*k \\in \\lisetpole}}$%\n          }\n          \\Comment{apply univariate operator on pole}%\n          \\label{line:algUnidirectionalPrinciple1}\n        \\EndFor{}\n      \\EndFor{}\n      \\State{$\\vlinout \\gets \\vlinout[(d)]$}\n    \\EndFunction{}\n  \\end{algorithmic}\n  \\caption[%\n    Unidirectional principle%\n  ]{%\n    Application of a tensor product operator $\\linop$ with\n    the unidirectional principle.\n    Inputs are\n    the vector $\\vlinin = (\\linin{\\*k})_{\\*k \\in \\liset}$ of input data,\n    the set $\\liset$ of grid indices, and\n    the permutation $(t_1, \\dotsc, t_d)$ specifying the order in which\n    the one-dimensional operators $\\upopuv{t_j}{\\lisetpole}$ should be applied.\n    The output is the vector $\\vlinout = (\\linout{\\*k})_{\\*k \\in \\liset}$\n    of output data.%\n  }%\n  \\label{alg:unidirectionalPrinciple}%\n\\end{algorithm}\n\n\\begin{proposition}[invariant of unidirectional principle for hierarchization]\n  \\label{prop:invariantUnidirectionalPrinciple}\n  Let $\\linop$ be the hierarchization operator on a full grid,\n  i.e.,\n  $\\linop = \\intpmatinv$,\n  $\\vlinin = (\\fcnval{\\*k})_{\\*k \\in \\liset}$,\n  $\\vlinout = (\\surplus{\\*k})_{\\*k \\in \\liset}$,\n  $\\upopuv{t_j}{\\lisetpole}$ is the univariate interpolation operator\n  $\\intpmatuvinv{t_j}$, and\n  $\\liset = \\{\\*0, \\dotsc, \\*2^\\*l\\}$\n  corresponds to a full grid $\\fgset{\\*l}$ of level $\\*l$.\n  After iteration $j$ of \\cref{alg:unidirectionalPrinciple}\n  ($j = 1, \\dotsc, d$), it holds for $T \\ceq (t_1, \\dotsc, t_j)$\n  \\begin{equation}\n    \\sum_{\\*k_T=\\*0}^{\\*2^{\\*l_T}}\n    \\linout[(j)]{(\\*k_T,\\*k'_{-T})} \\basis{\\*k_T}(\\gp{\\*k'_T})\n    = \\fcnval{\\*k'},\\quad\n    \\*k' = \\*0, \\dotsc, \\*2^\\*l,\n  \\end{equation}\n  where $(\\*k_T,\\*k'_{-T})$ is shorthand for $\\*k''$\n  with $k''_t \\ceq k_t$ if $t \\in T$ and $k''_t \\ceq k'_t$ if $t \\notin T$.\n\\end{proposition}\n\n\\begin{proof}\n  We prove the assertion by induction over $j = 1, \\dotsc, d$.\n  We set $T' \\ceq (t_1, \\dotsc, t_{j-1})$,\n  $T \\ceq (t_1, \\dotsc, t_{j-1}, t_j)$,\n  and we exploit the tensor product structure of the basis\n  to write the \\lhs of the assertion for $j$\n  and arbitrary $\\*k' = \\*0, \\dotsc, \\*2^\\*l$ as\n  \\begin{equation}\n    \\label{eq:proofPropInvariantUnidirectionalPrinciple1}\n    \\sum_{\\*k_T=\\*0}^{\\*2^{\\*l_T}}\n    \\linout[(j)]{(\\*k_T,\\*k'_{-T})} \\basis{\\*k_T}(\\gp{\\*k'_T})\n    = \\sum_{\\*k_{T'}=\\*0}^{\\*2^{\\*l_{T'}}}\n    \\basis{\\*k_{T'}}(\\gp{\\*k'_{T'}})\n    \\sum_{k_{t_j}=0}^{2^{l_{t_j}}}\n    \\linout[(j)]{(\\*k_T,\\*k'_{-T})} \\basis{k_{t_j}}(\\gp{k'_{t_j}}).\n  \\end{equation}\n  If we choose the equivalence class\n  $\\lisetpole \\ceq \\eqclass{(\\*k_T,\\*k'_{-T})}{\\samepole{t_j}}$\n  ($\\*k_T$ arbitrary),\n  then the inner sum over $k_{t_j}$ equals\n  \\begin{equation}\n    \\label{eq:proofPropInvariantUnidirectionalPrinciple2}\n    \\sum_{\\*k'' \\in \\lisetpole}\n    \\linout[(j)]{\\*k''} \\basis{k''_{t_j}}(\\gp{k'_{t_j}})\n    = \\paren*{\n      (\\upopuv{t_j}{\\lisetpole})^{-1}\n      \\bracket*{(\\linout[(j)]{\\*k''})_{\\*k'' \\in \\lisetpole}}\n    }_{k'_{t_j}}\n    = \\linout[(j-1)]{(\\*k_{T'},\\*k'_{-T'})}\n  \\end{equation}\n  by \\cref{line:algUnidirectionalPrinciple1} of\n  \\cref{alg:unidirectionalPrinciple}.\n  We can conclude that the \\lhs\n  \\cref{eq:proofPropInvariantUnidirectionalPrinciple1} equals\n  \\begin{equation}\n    \\sum_{\\*k_{T'}=\\*0}^{\\*2^{\\*l_{T'}}}\n    \\linout[(j-1)]{(\\*k_{T'},\\*k'_{-T'})}\n    \\basis{\\*k_{T'}}(\\gp{\\*k'_{T'}}),\n  \\end{equation}\n  which, by the induction hypothesis, equals $\\fcnval{\\*k'}$ as desired\n  (if $j > 1$).\n  The same reasoning for\n  \\eqref{eq:proofPropInvariantUnidirectionalPrinciple2} can be used\n  to establish the base case for $j = 1$.\n\\end{proof}\n\n\\begin{shortcorollary}[%\n  correctness of unidirectional principle for hierarchization%\n]\n  \\label{cor:algUnidirectionalPrincipleCorrectness}\n  \\Cref{alg:unidirectionalPrinciple}\n  is correct for hierarchization on full grids.\n\\end{shortcorollary}\n\n\\begin{proof}\n  We apply \\cref{prop:invariantUnidirectionalPrinciple} for $j = d$ to obtain\n  $\\sum_{\\*k=\\*0}^{\\*2^\\*l}\n  \\linout[(j)]{\\*k} \\basis{\\*k}(\\gp{\\*k'})\n  = \\fcnval{\\*k'}$\n  for all $\\*k' = \\*0, \\dotsc, \\*2^\\*l$, i.e.,\n  the $\\linout[(j)]{\\*k}$ are the correct interpolation coefficients\n  according to \\eqref{eq:hierarchizationProblem}.\n\\end{proof}\n\n\\paragraph{Complexity}\n\nWe compare the complexity of the \\up for hierarchization with\nthe direct solution of the system \\eqref{eq:hierarchizationSLE} of\nlinear equations.\nIf we assume that $d$ is constant and that\n$\\linop$ and $\\upopuv{t_j}{\\lisetpole}$ apply Gaussian elimination to\nsolve the multivariate and univariate systems, respectively,\nthen directly solving \\eqref{eq:hierarchizationSLE} takes\n$\\landauO{\\ngp^2 (\\ngp + d)}$ time and\n$\\landauO{\\ngp^2}$ memory.\nIn contrast, the \\up only requires\n$\\landauO{\\ngp \\sum_t \\ngp_t^2}$ time%\n\\footnote{%\n  There are $\\ngp/\\ngp_t$ poles in the\n  $t$-th iteration of \\cref{alg:unidirectionalPrinciple}.\n  Each pole requires the solution of an $\\ngp_t \\times \\ngp_t$ linear system,\n  which takes $\\landauO{\\ngp_t^3}$ time.%\n}\nand $\\landauO{\\max\\{N_1^2, \\dotsc, N_d^2, N\\}}$ memory,\nwhere $\\ngp_t$ is the grid size\n$\\setsize{\\{k_t \\mid \\*k \\in \\liset\\}}$ in dimension $t = 1, \\dotsc, d$.\nThe dependency from the univariate grid sizes $\\ngp_t$ instead of $\\ngp$\nmakes the \\up significantly less computationally expensive.\nAs already mentioned,\nthe \\up is even more efficient in the piecewise linear case,\nwhere the univariate interpolation operators can be applied\nin-place.\nHence, it only needs $\\landauO{Nd}$ time and\n$\\landauO{N}$ memory in this case.\n", "meta": {"hexsha": "de97606aceccb4710571f00a9be9674e18e0afc5", "size": 8452, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/42fullGrids.tex", "max_stars_repo_name": "valentjn/thesis-arxiv", "max_stars_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-12T09:28:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:07:17.000Z", "max_issues_repo_path": "tex/document/42fullGrids.tex", "max_issues_repo_name": "valentjn/thesis-arxiv", "max_issues_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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/42fullGrids.tex", "max_forks_repo_name": "valentjn/thesis-arxiv", "max_forks_repo_head_hexsha": "ae30179e67cd6a7813385e140b609546fd65b897", "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.4953271028, "max_line_length": 81, "alphanum_fraction": 0.6579507809, "num_tokens": 2999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6094903277066922}}
{"text": "\\section{Hyperparameters}\n\\label{parameters}\nThis section proposes an equation to evaluate the build-trace trade-off of the PHR algorithm. Two possible solutions for the optimization problem are them presented in the form of grid search and Bayesian optimization. As established in the previous section, PHR depends on the parameters $\\alpha$ and $\\delta$ describing initial cut size and shrink rate. These parameters can be set to adjust the trade-off between build time and trace performance. However, the optimal parameters can differ between scenes and view points, especially when dealing with dynamic scenes and refitted auxiliary trees.\n% TODO: Add figure that shows different optimal parameters and prove thesis\nFrame size also plays a role as higher resolutions profit more from well optimized bounding volume hierarchies while the hit taken by the extended build time is not as significant given the overall higher computational effort. \n\\subsection{Evaluation}\n\\label{evaluation}\nUltimately, the overall frame time including BVH build time and render duration needs to be minimized to unlock the full potential of progressive hierarchical refinement. Stopping the actual execution times is neither efficient nor reliable enough, so an efficient metric that makes the trade-off quantifiable is needed. \n\nA number of metrics have been proposed to estimate the quality of a given bounding volume hierarchy. A well known cost model based on the surface area heuristic, taken from \\cite{meister21survey}, is given by the recurrence equation \n\\[\nc(N) =  \n    \\begin{cases}\n        c_T + \\sum_{N_c}P(N_c|N)c(N_c) &\\quad\\text{if }N\\text{ is interior node,}\\\\\n        c_I|N|&\\quad\\text{otherwise}\\\\\n    \\end{cases}\n\\]\nwhere $C(N)$ is the cost of the subtree with root $N$, $N_c$ is a child of node $N$, $P(N_c|N)$ is the conditional probability of traversing node $N_c$ when $N$ is hit and $|N|$ is the number of primitives in the subtree with root $N$. \n\nConstants $c_T$ and $c_I$ express the average cost of a traversal step and ray-primitive intersection, respectively. Utilizing the micro-benchmarking capabilities of Go revealed that a triangle intersection takes approximately 7 nanoseconds on average, while a traversal step takes around 12 nanoseconds. Consequently, these constants are set to $c_T = 2$ and $c_I = 1$, roughly representing the ratios between those values. \nThe conditional probabilities of traversing a node are expressed using the surface area heuristic\\cite{goldsmith_automatic_1987,macdonald_heuristics_1990}\n\\[\nP(N_c|N)^{SAH} = \\frac{SA(N_c)}{SA(N)}\n\\]\nwhere $SA(N)$ and $SA(N_c)$  are the bounding box surface areas of nodes $N$ and $N_c$, respectively. \n\nEvaluating the build complexity of PHR given a set of parameters and an arbitrary scene is not as trivial, as there is no clear correlation between the parameter values and associated build times.  \n\\begin{figure}\n    \\centering\n    \\subcaptionbox{Build Time}{\\includegraphics[width=0.45\\textwidth]{images/build_time.pdf}}\n    \\hfill\n    \\subcaptionbox{Build Cost}{\\includegraphics[width=0.45\\textwidth]{images/build_cost.pdf}}\n    \\caption{Both the build time and corresponding build cost for the San Miguel scene. This corresponds to a correlation of 0.994.}\n    \\label{fig:build_cost}\n\\end{figure}\nFor scenes with medium to high complexity, the tree size of the resulting BVH could be used as a metric with an average correlation coefficient of around 0.98 between tree size and build time. This correlation does not hold true for simpler scenes though, as trees stop growing once no favorable splits can be found anymore.\nA better metric is the total sum of all cut sizes, as seen in figure \\ref{fig:build_cost}, which can be obtained through a minimal adjustment of the progressive hierarchical refinement algorithm. The surface area heuristic evaluation is the most expensive part of PHR and thus the total number of evaluated nodes directly correlates with the execution duration. Using an atomic counter, the performance penalty is very marginally to non existing. Furthermore, an alternative implementation can be used for the optimization process. The correlation between this number and the BVH construction time averages to 0.99 across all tested scenes.\n\nLet the build cost $b$ be defined as\n\\[\n    b(\\alpha, \\delta) = \\sum_{cut\\in PHR'(\\alpha, \\delta)}|cut|\n\\]\nwhere $b(\\alpha, \\delta)$ is cost of a PHR execution given the parameters $\\alpha$ and $\\delta$, $PHR'(\\alpha, \\delta)$ is a execution of the progressive hierarchical refinement algorithm resulting in a set of all cuts processed and $|cut|$ is the length of given cut.\n\nI propose an equation to evaluate the combined cost of a frame rendered using the PHR algorithm, which also factors in the build-trace trade-off. Given a pair of parameters $\\alpha$ and $\\delta$, this cost is defines as\n\\[\n    e(\\alpha,\\delta) = ||b(\\alpha,\\omega)|| + \\omega^2 ||c(PHR(\\alpha,\\omega))||\n\\]\nwith $||b(\\alpha,\\delta)||$ being the normalized build cost and $||c(PHR(\\alpha,\\omega))||$ the normalized SAH cost of the resulting BVH. The coefficient $\\omega$ functions as a weight determining to what extend trace performance should be favored over build duration. For $\\omega=1$, both trace and build performance are weighed equally, $\\omega>1$ favors higher trace speed and $\\omega<1$ encourages faster build times. These trade-off depends on scene complexity and frame size, so $\\omega$ is defined as:\n\\[\n    \\omega = (\\frac{|prim|}{\\omega_p})^2 * (\\frac{w*h}{\\omega_r})\n\\]\nwhere $|prim|$ is the total number of primitives in the scene and $w$ and $h$ are width and height of the rendered frame, respectively. $\\omega_p$ and $\\omega_r$ are constants depending on the performance of the used path tracer and the targeted frame rate, so they stay constant across all scenes. $\\omega_p$ expresses a number of primitives and $\\omega_r$ a frame size at which the trade-off should be equal, i.e. $\\omega=1$. Once those numbers are exceeded, BVH quality is favored increasingly. \n\nCombining the equation with the previously mentioned metrics and given a search space over the parameters $\\alpha$ and $\\delta$ (e.g. $\\alpha\\in A=[0.4,0.6], \\delta\\in D=[5,10]$) leads to the expression:\n\\[\n    e(\\alpha,\\delta) =\n        \\frac{b(\\alpha, \\delta)}\n        {\\max_{\\alpha\\in A,\\delta\\in D}b(\\alpha, \\delta)}\n        + \\omega^2\n        \\frac{c(PHR(\\alpha, \\delta))}\n        {\\max_{\\alpha\\in A,\\delta\\in D}c(PHR(\\alpha, \\delta))}\n\\]\nwhere $PHR(\\alpha,\\delta)$ is a execution of the PHR algorithm using the parameters $\\alpha$ and $\\delta$ resulting in the root node of a bounding volume hierarchy.\n\\clearpage\n\\subsection{Grid Search}\nThe brute force approach grid search is the obvious first choice to solve this optimization problem. A number of possible values is chosen for each parameter (e.g. $\\alpha\\in\\{0.45,0.5,0.55\\}$ $\\delta\\in\\{5,6,7,8\\}$) and all possible combinations are tested and evaluated. By postponing the evaluation of $e(\\alpha,\\delta)$ until all individual cost evaluations $b(\\alpha, \\delta)$ and $c(PRH(\\alpha,\\delta))$ are available makes their maxima directly accessible, which is another advantage of grid search. \n\nUsually, grid search would be too costly for such a time critical task. In this case however, only two parameters need to be optimized and the search space is relatively small making grid search a potentially viable approach. \n\n\\subsection{Bayesian Optimization}\nA more efficient approach compared to grid search is Bayesian optimization\\cite{pelikan99boa}, which explores the search space by taking previous observations into account. This is done by placing a prior probability distribution over the objective function $e(\\alpha,\\delta)$. First, parameters $\\alpha$ and $\\delta$ are chosen by random in the given search space. Following their evaluation, the prior is updated to form a posterior distribution. Based on this posterior distribution, an acquisition function is constructed to select the next point worth exploring. \n\nIn particular, the Bayesian optimizer\\cite{ou19bo} utilizes a Gaussian process to define the prior/posterior distribution, and expected improvement is used as exploration strategy.\n\nOne issue compared to the aforementioned grid search approach is, that the maximum BVH and build costs are not directly available when evaluating $e(\\alpha,\\delta)$. This is solved by running PHR once with the lowest possible parameters in the search space to obtain the maximum BVH cost and once with the highest possible parameters to obtain the maximum build cost. These numbers correspond to the respective maxima very reliably and there evaluations can also be factored into the prior probability distribution.\n\\cleardoublepage", "meta": {"hexsha": "5492745731b1d736992ccdff6822d33dc861866a", "size": 8722, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/ch04_3-parameters.tex", "max_stars_repo_name": "ChSchmidt99/bachelorthesis", "max_stars_repo_head_hexsha": "4c427317c0334186eea8c587d56d0c176a4b04fb", "max_stars_repo_licenses": ["MIT"], "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/ch04_3-parameters.tex", "max_issues_repo_name": "ChSchmidt99/bachelorthesis", "max_issues_repo_head_hexsha": "4c427317c0334186eea8c587d56d0c176a4b04fb", "max_issues_repo_licenses": ["MIT"], "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/ch04_3-parameters.tex", "max_forks_repo_name": "ChSchmidt99/bachelorthesis", "max_forks_repo_head_hexsha": "4c427317c0334186eea8c587d56d0c176a4b04fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 113.2727272727, "max_line_length": 640, "alphanum_fraction": 0.769777574, "num_tokens": 2016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118068790618, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6094173613561553}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{loctime}\n\\section*{\\hspace*{-1.6cm} loctime}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nTime localization characteristics.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tm,T] = loctime(x)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty loctime} computes the time localization characteristics of\n        signal {\\ty x}. The definition used for the averaged time\n        and the time spreading are the following\\,:\n\\begin{eqnarray*}\nt_m &=& \\frac{1}{E_x}\\ \\int_{-\\infty}^{+\\infty} t\\ |x(t)|^2\\ dt \\\\ T &=&\n2\\ \\sqrt{\\frac{\\pi}{E_x}\\ \\int_{-\\infty}^{+\\infty} (t-t_m)^2\\ |x(t)|^2\\ dt}\n\\end{eqnarray*}\nwhere $E_x$ is the energy of the signal. With this definition (and the one\nused in {\\ty locfreq}), the Heisenberg-Gabor inequality writes $B\\ T\\geq\n1$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n   {\\ty x}   & signal\\\\\n \\hline       {\\ty tm}  & averaged time center\\\\\n        {\\ty T}   & time spreading\\\\\n\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Examples}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nHere is an example of signal which corresponds to the lower bound of the\nHeisenberg-Gabor inequality.\n\\begin{verbatim}\n         z=amgauss(160,80,50); \n         [tm,T]=loctime(z); \n         [fm,B]=locfreq(z);\n         [tm,T,fm,B,T*B]\n         ans = \n               80.0000   50.0000   0.0000   0.0200   1\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nlocfreq.\n\\end{verbatim}\n\\end{minipage}\n\n\n\n\n", "meta": {"hexsha": "2a49097d8e554a525818bef08d0acdc3669154c9", "size": 2013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/loctime.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/loctime.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/loctime.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 22.6179775281, "max_line_length": 75, "alphanum_fraction": 0.6318926975, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.609417358208886}}
{"text": "\\chapter{   Data Analytics}\n% CHAPTER SETTINGS\n\\graphicspath{{./images/data_analytics/}\n\n\\section{Time Series analysis}\n\n\\subsection{Transforms for Time Series Data}\n\n% for code\n% https://machinelearningmastery.com/machine-learning-data-transforms-for-time-series-forecasting/\n\n% Power Transform\n% A power transform removes a shift from a data distribution to make the distribution more-normal (Gaussian).\n\n% On a time series dataset, this can have the effect of removing a change in variance over time.\n\n% ####\n\n% Difference Transform\n\n% A difference transform is a simple way for removing a systematic structure from the time series.\n\n% For example, a trend can be removed by subtracting the previous value from each value in the series. This is called first order differencing. The process can be repeated (e.g. difference the differenced series) to remove second order trends, and so on.\n\n% A seasonal structure can be removed in a similar way by subtracting the observation from the prior season, e.g. 12 time steps ago for monthly data with a yearly seasonal structure.\n\n% ####\n\n% Standardization\n\n% Standardization is a transform for data with a Gaussian distribution.\n\n% It subtracts the mean and divides the result by the standard deviation of the data sample. This has the effect of transforming the data to have mean of zero, or centered, with a standard deviation of 1. This resulting distribution is called a standard Gaussian distribution, or a standard normal, hence the name of the transform.\n\n\n% ####\n\n% Normalization\n\n% ormalization is a rescaling of data from the original range to a new range between 0 and 1.\n\n% As with standardization, this can be implemented using a transform object from the scikit-learn library, specifically the MinMaxScaler class. In addition to normalization, this class can be used to rescale data to any range you wish by specifying the preferred range in the constructor of the object.\n\n\n\n% \\subsection{Considerations for Model Evaluation}\n\n% Considerations for Model Evaluation\n\n% We have mentioned the importance of being able to invert a transform on the predictions of a model in order to calculate a model performance statistic that is directly comparable to other methods.\n\n% Additionally, another concern is the problem of data leakage.\n\n% Three of the above data transforms estimate coefficients from a provided dataset that are then used to transform the data. Specifically:\n\n% Power Transform: lambda parameter.\n% Standardization: mean and standard deviation statistics.\n% Normalization: min and max values.\n% These coefficients must be estimated on the training dataset only.\n\n% Once estimated, the transform can be applied using the coefficients to the training and the test dataset before evaluating your model.\n\n% If the coefficients are estimated using the entire dataset prior to splitting into train and test sets, then there is a small leakage of information from the test set to the training dataset. This can result in estimates of model skill that are optimistically biased.\n\n% As such, you may want to enhance the estimates of the coefficients with domain knowledge, such as expected min/max values for all time in the future.\n\n% Generally, differencing does not suffer the same problems. In most cases, such as one-step forecasting, the lag observations are available to perform the difference calculation. If not, the lag predictions can be used wherever needed as a proxy for the true observations in difference calculations\n\n% \\subsection{Order of Data Transforms}\n\n% a suggested ordering for data transforms is as follows:\n\n% Power Transform.\n% Seasonal Difference.\n% Trend Difference.\n% Standardization.\n% Normalization.\n% Obviously, you would only use the transforms required for your specific dataset.\n\n% Importantly, when the transform operations are inverted, the order of the inverse transform operations must be reversed. Specifically, the inverse operations must be performed in the following order:\n\n% Normalization.\n% Standardization.\n% Trend Difference.\n% Seasonal Difference.\n% Power Transform.\n", "meta": {"hexsha": "901d04af0f3e17c5276518706d56ec4ed5a90b37", "size": 4082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main/chapters/data_analytics.tex", "max_stars_repo_name": "romanroson/veritas", "max_stars_repo_head_hexsha": "148c1aea2369beca96bf8929af260c6634ecbe4c", "max_stars_repo_licenses": ["MIT"], "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/chapters/data_analytics.tex", "max_issues_repo_name": "romanroson/veritas", "max_issues_repo_head_hexsha": "148c1aea2369beca96bf8929af260c6634ecbe4c", "max_issues_repo_licenses": ["MIT"], "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/chapters/data_analytics.tex", "max_forks_repo_name": "romanroson/veritas", "max_forks_repo_head_hexsha": "148c1aea2369beca96bf8929af260c6634ecbe4c", "max_forks_repo_licenses": ["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.9195402299, "max_line_length": 331, "alphanum_fraction": 0.7939735424, "num_tokens": 805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6094173535408247}}
{"text": "\\documentclass[../report/main.tex]{subfiles}\n \n\\begin{document}\n\n% The asterix after \\subsection disables section numbering\n\\subsection*{Problem 1 Part C}\nDetermine the number of refrigerators to be shipped from plants to warehouses, and then warehouses to retailers to minimize the cost.  \\textcolor{blue}{For part C warehouse 2 is limited to just 100 units per week.  Changes to the problem statement or solution relative to Problem 1 Part A are highlighted in blue.}\n\n\\subsection*{Solution}\n\\begin{itemize}\n\t\\item In all 1000 units will travel through the network at a minimum cost of \\textcolor{blue}{\\$18300}.\n\t\\newline\n\t\\item Ship 150 units from plant \\#1 to warehouse \\#1 at a cost of \\$1500.\n\t\\item Ship \\textcolor{blue}{350} units from plant \\#2 to warehouse \\#1 at a cost of \\textcolor{blue}{\\$3850}.\n\t\\item Ship \\textcolor{blue}{100} units from plant \\#2 to warehouse \\#2 at a cost of \\textcolor{blue}{\\$800}.\n\t\\item Ship   \\textcolor{blue}{0} units from plant \\#3 to warehouse \\#2 at a cost of \\textcolor{blue}{\\$   0}.\n\t\\item Ship \\textcolor{blue}{250} units from plant \\#3 to warehouse \\#3 at a cost of \\textcolor{blue}{\\$2250}.\n\t\\item Ship 150 units from plant \\#4 to warehouse \\#3 at a cost of \\$1200.\n\t\\newline\n\t\\item Ship 100 units from warehouse \\#1 to retailer \\#1 at a cost of \\$ 500.\n\t\\item Ship 150 units from warehouse \\#1 to retailer \\#2 at a cost of \\$ 900.\n\t\\item Ship 100 units from warehouse \\#1 to retailer \\#3 at a cost of \\$ 700.\n\t\\item \\textcolor{blue}{Ship 150 units from warehouse \\#1 to retailer \\#4 at a cost of \\$1500}.\n\t\\item Ship  \\textcolor{blue}{50} units from warehouse \\#2 to retailer \\#4 at a cost of \\textcolor{blue}{\\$ 400}.\n\t\\item Ship  \\textcolor{blue}{50} units from warehouse \\#2 to retailer \\#5 at a cost of \\textcolor{blue}{\\$ 500}.\n\t\\item \\textcolor{blue}{Ship 150 units from warehouse \\#3 to retailer \\#5 at a cost of \\$1800.}\n\t\\item Ship 150 units from warehouse \\#3 to retailer \\#6 at a cost of \\$1800.\n\t\\item Ship 100 units from warehouse \\#3 to retailer \\#7 at a cost of \\$ 600.\n\t\\newline\n\t\\item 150 total units will leave plant \\#1 (capacity is 150).\n\t\\item 450 total units will leave plant \\#2 (capacity is 450).\n\t\\item 250 total units will leave plant \\#3 (capacity is 250).\n\t\\item 150 total units will leave plant \\#4 (capacity is 150).\n\t\\newline\n\t\\item \\textcolor{blue}{500} total units will enter warehouse \\#1, \\textcolor{blue}{500} units will leave.\n\t\\item \\textcolor{blue}{100} total units will enter warehouse \\#2, \\textcolor{blue}{100} units will leave.\n\t\\item \\textcolor{blue}{400} total units will enter warehouse \\#3, \\textcolor{blue}{400} units will leave.\n\t\\newline\n\t\\item 100 total units will enter retailer \\#1 (demand is 100).\n\t\\item 150 total units will enter retailer \\#2 (demand is 150).\n\t\\item 100 total units will enter retailer \\#3 (demand is 100).\n\t\\item 200 total units will enter retailer \\#4 (demand is 200).\n\t\\item 200 total units will enter retailer \\#5 (demand is 200).\n\t\\item 150 total units will enter retailer \\#6 (demand is 150).\n\t\\item 100 total units will enter retailer \\#7 (demand is 100).\n\\end{itemize}\n\\subsection*{Linear Program Formulation}\n\\begin{enumerate}[1.]\n\t\\item Overall idea of problem\n\t\\begin{itemize}\n\t\t\\item Refrigerators moving from $n=4$ plants to $q=3$ warehouses to $m=7$ retailers.\n\t\t\\item Not all plants deliver to all warehouses.\n\t\t\\item Not all warehouses deliver to all retailers.\n\t\t\\item Costs of shipping from plants to warehouses vary by pair.\n\t\t\\item Costs of shipping from warehouses to retailers vary by pair.\n\t\t\\item Each plant has a capacity in terms of number of refrigerators it can supply.\n\t\t\\item Each retailer has a capacity in terms of number of refrigerators it demands.\n\t\t\\item\\textcolor{blue}{Warehouse 2 is limited to just 100 units in and out per week.}\t\t\n\t\\end{itemize}\n\t\\item What is the goal?  What are you trying to achieve?\n\t\\begin{itemize}\n\t\t\\item Unchanged from part A.\n\t\\end{itemize}\n\t\\item Identify variables\n\t\\begin{itemize}\n\t\t\\item Unchanged from part A.\n\t\\end{itemize}\n\t\\item Identify constraints\n\t\\begin{itemize}\n\t\t\\item All constraints from part A remain in effect with the addition of two new constraints:\n\t\t\\item\\textcolor{blue}{$np_{12} + np_{22} + np_{32} + np_{42} = 100$}\t\t\n\t\t\\item\\textcolor{blue}{$nw_{23} + nw_{24} + nw_{25} + nw_{26} = 100$}\t\t\n\t\\end{itemize}\n\t\\item Identify inputs and outputs that you can control\n\t\\begin{itemize}\n\t\t\\item Unchanged from part A.\n\t\\end{itemize}\n\t\\item Specify all quantities mathematically\n\t\\begin{itemize}\n\t\t\\item Unchanged from part A.\n\t\\end{itemize}\n\t\\item Check the model for completeness and correctness\n\t\\begin{itemize}\n\t\\item All variables are positive.\n\t\\end{itemize}\n\\end{enumerate}\n\\subsection*{ Matlab Code}\n\\textcolor{blue}{Code minimally changed from part A.  Only changes are 2 additional constraints (16 total equations) in the linear equality matrix and vector.  Identical code from part A is not shown below (to save space).}\n\\lstinputlisting{../problem_one/partC_changes_fromA.m}\n\\end{document}", "meta": {"hexsha": "fa6f6444465bb03ddb8ffc02797bdfac50f7b109", "size": 5010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem_one/partC.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/partC.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/partC.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": 55.6666666667, "max_line_length": 314, "alphanum_fraction": 0.727744511, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6094173502878694}}
{"text": "\\section{Method}\n\nOur work starts with a comprehensive overview of the underlying core concepts. As graph states lie at the heart of measurement-based quantum computing, it is necessary to introduce the terminology and some fundamental results. To make this introduction, we use two different approaches to define graph states. Next, we will introduce the one-way quantum computer, an abstract machine for quantum computing. We use this machine in the following section to discuss various results about measurement-based quantum computing.\n\n\\subsection{Graph States}\n\nWe start by introducing the necessary terminology regarding graphs, which are mathematical objects commonly used in computer science composed of vertices and edges. A graph is defined by a set \\(V\\) of \\(N\\) vertices and a set \\(E\\) of \\(M\\) edges\\cite{clrs}.\n\\begin{gather}\n  V = \\Set{1, 2, \\dots, N} \\\\\n  E \\subseteq [V]^2 \\;\\text{where}\\; \\abs{E\\,} = M\n\\end{gather}\nWe usually represent graphs via diagrams. Such a diagram is given in Figure \\ref{fig:graph_example}. As we do not impose order among the vertices that are connected by an edge, an edge is used only to denote \\emph{connectivity}. Two vertices \\(a, b \\in V\\) are called \\emph{adjacent} if they are connected by an edge. The \\emph{neighbourhood} of a vertex \\(a \\in V\\) is the set of all the vertices \\(a\\) is adjacent to.\n\\begin{equation}\n  N_a = \\Set{\\,b\\in V \\given \\Set{a, b}\\in E\\,}\n\\end{equation}\nGraphs that contain no loops---edges connecting a vertex to itself---or multiple edges between any two of its vertices are called \\emph{simple graphs}\\cite{hein2006}. The main type of graphs we deal with are simple graphs.\n\n\\begin{figure}[h]\n  \\centering\n  \\tikz \\graph [\n    ] {\n      1 -- {2 -- 3, 4};\n      3 -- 4;\n    };\n  \\caption{The diagram of graph \\(G = \\{\\Set{1,2,3,4}\\,,\\, \\{\\Set{1,2}, \\Set{1,4}, \\Set{2,3}, \\) \\(\\Set{1,4}\\}\\} \\) }\\label{fig:graph_example}\n\\end{figure}\n\nSimple graphs can be used to represent some interactions of qubit systems. We call these systems \\emph{graph states}. Formally defining a graph state can be done in two different ways. The first one is by using the system's interaction patterns. \n\nA graph state described by the graph \\(G = \\Set{V, E}\\) is made up of qubits that are labelled by the vertices of \\(G\\). Any two qubits \\(a,b\\in V\\) connected by an edge \\(\\Set{a,b} \\in E\\) interact via an Ising type interaction. We also impose the following conditions apart from the restriction on the qubits' interaction type.\n\\begin{enumerate}\n  \\item Since an edge only denotes connectivity, all two-particle unitaries acting on a vertex must commute.\n  \\begin{equation}\n    [U_{ab}, U_{bc}] = 0 \\quad \\forall a, b, c \\in V\n  \\end{equation}\n  \\item Since edges do not denote a direction, unitaries must be symmetric.\n  \\begin{equation}\n    [U_{ab}, U_{ba}] = 0 \\quad \\forall a, b \\in V\n  \\end{equation}\n  \\item All the particles must interract through the same unitary.\n\\end{enumerate}\nThe general form of an Ising type interaction that satisfies these additional constraints is given by the following unitary, parameterized by the \\emph{interaction strength}.\n\\begin{equation}\n  U_{ab}^I(\\psi_{ab}) = e^{-i \\psi_{ab} \\, \\sigma_z^a \\, \\sigma_z^b}\n\\end{equation}\nThis interraction pattern is useful to us because of the entanglement patterns it produces. Note that such a unitary with parameter \\(\\psi_{ab} = \\pi/4\\) is equivalent to a controlled \\(\\sigma_z\\) gate---denoted by CZ---up to some additional \\(\\pi/4\\)-rotations around the \\(z\\) axis for each qubit.\n\\begin{equation}\n\\begin{aligned}\n  e^{-i\\frac{\\pi}{4}} e^{i\\sigma_z^a\\frac{\\pi}{4}} e^{i\\sigma_z^b\\frac{\\pi}{4}} U^I_{ab}\\p*{\\frac{\\pi}{4}} &= e^{-i\\frac{\\pi}{4}} e^{i\\sigma_z^a\\frac{\\pi}{4}} e^{i\\sigma_z^b\\frac{\\pi}{4}} e^{-i \\frac{\\pi}{4} \\, \\sigma_z^a \\, \\sigma_z^b}\\\\\n  &= e^{-i\\frac{\\pi}{4}}\\\\\n  &= \\begin{bmatrix}\n    1 & 0 & 0 & 0 \\\\\n    0 & 1 & 0 & 0 \\\\\n    0 & 0 & 1 & 0 \\\\\n    0 & 0 & 0 & -1\n  \\end{bmatrix}\n\\end{aligned}\n\\end{equation}\nUsing CZ to construct edges makes sure that a resulting edege\n\\begin{equation}\n  U_{ab}\\ket+^a\\ket+^b = \\frac{1}{\\sqrt2}(\\ket0^a\\ket+^b + \\ket1^a\\ket-^b) \n\\end{equation}\nis maximally entangled. Furhtermore \\(U_{ab}\\)\\/ is Hermitian so it can be used to delete an edge as well.\n\nA graph state \\(\\ket{G}\\) which correspond to the simple graph \\(G=\\p{V, E}\\) is defined to be\n\\begin{equation}\n  \\ket{G} = \\prod_{\\p{a,b} \\, \\in E} U_{ab}\\,\\ket+^V,\n\\end{equation}\nand is prepared via the following procedure\\cite{hein2006}.\n\\begin{enumerate}\n  \\item For each vertex in \\(V\\), prepare the corresponding qubit with the positive \\(\\sigma_x\\) eigenstate \\(\\ket+\\).\n  \\item For each edge \\(\\p{a,b}\\in E\\), apply \\(U_{ab}\\) to the system.\n\\end{enumerate}\n\n\\begin{figure}[bt]\n  \\centering\n  \\subcaptionbox{The diagram of \\(G\\)}[0.85\\linewidth]{\\input{{fig/graph.tikz}}}\n  \\vspace{1em}\n  \n  \\subcaptionbox{Interraction pattern representation of \\(\\ket{G}\\)}[0.43\\linewidth]{%\n    \\begin{align*}\n      \\ket{G} \n      &= U_{24}U_{23}U_{12}\\ket{+}^{\\otimes 4} \\\\\n      &= \\begin{aligned}[t]\n        &\\ket0\\ket0\\ket0\\ket+ -\\ket0\\ket0\\ket1\\ket-\\\\\n        &+\\ket0\\ket1\\ket0\\ket+ -\\ket0\\ket1\\ket1\\ket-\\\\\n        &+\\ket1\\ket0\\ket0\\ket+ +\\ket1\\ket0\\ket1\\ket-\\\\\n        &-\\ket1\\ket1\\ket0\\ket+ +\\ket1\\ket1\\ket1\\ket-\n      \\end{aligned}\n  \\end{align*}}\n  \\hfill\n  \\subcaptionbox{Stabilizer representation of \\(\\ket{G}\\)}[0.43\\linewidth]{%\n  \\begin{gather*}\n    \\sigma_x^1\\sigma_z^2\\\\\n    \\sigma_x^2\\sigma_z^1\\sigma_z^3\\sigma_z^4\\\\\n    \\sigma_x^3\\sigma_z^2\\\\\n    \\sigma_x^4\\sigma_z^2\n  \\end{gather*}}\n\n  \\caption{Representations of the graph state \\(\\ket{G}\\) which correspons to the graph \\(G = \\Set{V, E}\\) where \\(V = \\Set{1,2,3}\\) and \\(E = \\Set{\\Set{1,2}, \\Set{2,3}, \\Set{2,4}}\\)}\\label{fig:graph_state}\n\\end{figure}\n\nAn alternative definition of graph states with a more compact representation uses stabilizer formalism\\cite{caves2014, quant-ph/9705052}. A stabilizer is defined to be a commutative subgroup of the \\(N\\)-qubit Pauli group \\(\\symcal{P}^V\\) over the qubits in \\(V\\) that does not contain \\(-\\id_V\\) or \\(\\pm i\\id_V\\)\\cite{Briegel_2001,pusey2011}. For a given simple graph \\(G=\\p{G, E}\\), the corresponding graph state \\(\\ket{G}\\) is defined as the unique and common eigenvector to the set of independent commuting observables\n\\begin{equation}\n  K_a = \\paulix^a \\pauliz^{N_a} = \\paulix^a \\prod_{b\\in N_a} \\pauliz^{b}\n\\end{equation}\nwith eigenvalues \\(+1\\). These observables, \\(K_a\\), are called \\emph{correlation operators}. The commutative subgroup of \\(\\symcal{P}^V\\) generated by the set \\(\\Set{K_a \\given a \\in V}\\) is called \\emph{the stabilizer of}\\/ \\(\\ket{G}\\). Due to the common eigenvalues of its generators, a stabilizer provides the following set of measurement correlations.\n\\begin{equation}\n  s_x^a\\prod_{b\\in N_a}s_z^b = 1\n\\end{equation}\nIt is also possible to make a measurement on the graph state in a non-generator basis. A general Pauli measurement operator \\(g\\in\\symcal{P}^V\\) can have the following effects on the stabilizer with generators \\(\\langle g_1, g_2,\\dots,g_n\\rangle\\)\\cite{Nielsen2009}.\n\\begin{itemize}\n  \\item \\(g\\) might commute with all the generators of the stabilizer. In this case, either \\(g\\) or \\(-g\\) is a generator and a measurement will leave the state invariant.\n  \\item \\(g\\) might anti-commute with a generator \\(g_1\\). In this case, the observation will yield \\(\\pm1\\) with equal probabilities and the new state will be stabilized by \\(\\langle g, g_2, \\dots, g_n \\rangle\\)\n\\end{itemize}\n\n\\subsection{One-Way Quantum Computer}\n\nQuantum computing literature is no stranger to various abstract machines like quantum Turing machines\\cite{deutsch1985}, quantum finite automata\\cite{SayY14}, or, most notably, quantum circuits. A common trait among these formulations is using unitary transformations to perform calculations. For each of these machines, their program states are traced by quantum state vectors modified only by unitary transformations until the program state is observed. We now define a measurement-based abstract machine, the one-way computer\\cite{russendorf2001}.\n\nA one-way quantum computer has two components:\n\\begin{description}[\n  topsep=0pt,\n  itemsep=-1ex,\n  partopsep=1ex,\n  parsep=1ex,\n  leftmargin=2.5em,\n  labelindent=1.5em,\n  ]\n  \\item[A cluster \\(\\symcal{C}\\)] that is made up of a \\(d\\) dimensional array of qubits. The state of a cluster can be described by a graph state with a regular lattice shape. A 2 dimensional, 2 by 3 cluster can be depicted by the following diagram.\n  \\begin{equation}\n    \\tikz[ baseline={([yshift=-.5ex]current bounding box.center)} ] \\graph [\n      nodes={draw, circle, inner sep=2.5pt, thick},\n      empty nodes,\n      edges = {thick}\n    ] {\n      a -- b -- c;\n      d -- e -- f;\n      a -- d; b -- e; c -- f;\n    };\n  \\end{equation}\n  \\item[A random access measurement device] that is used to govern the program execution. The one-way computer takes a measurement patterns, composed of local measurement directions for each qubit, as its inputs. \n  \\begin{equation}\n    \\symcal{M} = \\Set*{\\,\\vec{r}_a \\given a \\in \\symcal{C}\\,}\n  \\end{equation}  \n  The measurement device then applies these patterns to the cluster.\n\\end{description}\n\nAn essential feature of the one-way quantum computer is its universality. This feature can be proven constructively by providing measurement patterns that implement \\(\\cnot\\) and arbitrary one qubit rotation unitary gates, which are proven to be a universal set of quantum gates\\cite{Deutsch1995}. We now proceed to show that any unitary transformation, \\(U\\), can be simulated via a one-way computer up to a \\emph{by-product} operator \\(U_\\Sigma\\). The one-way computer simulates \n\\begin{equation}\n  U' = U_\\Sigma \\, U\n\\end{equation}\nThese by-product operators result from the randomness inherent to the quantum measurements and are parameterized by the measurement outcomes. Since the measurement outcomes are acquired after each measurement, the one-way computer can apply corrections to its measurement basis adaptively to remove the effects of these operators.\n\nA one-qubit rotation \\(R(\\alpha, \\beta, \\gamma)\\) can be decomposed into the following relation using Euler angles\\cite{daSilva2013}.\n\\begin{equation}\n  R(\\alpha, \\beta, \\gamma) = R_z(\\gamma) R_x(\\beta) R_z(\\alpha)\n\\end{equation}\nTo implement \\(R_z\\) and \\(R_x\\) rotations, the following measurement basis \\(\\symcal{B}(\\varphi) = \\Set*{\\ket{0_\\varphi},\\ket{1_\\varphi} }\\) is used.\n\\begin{equation}\n  \\symcal{B}(\\varphi) = \\Set*{\\frac{\\,\\ket0 + e^{i\\varphi}\\ket1}{2}, \\frac{\\,\\ket0 - e^{i\\varphi}\\ket1}{2} \\,}\n\\end{equation}\nA 2 qubit cluster prepared with an input state \\(\\ket\\psi = a\\ket0 + b\\ket1\\) can be expressed as\n\\begin{align}\n  \\ket{C} &= \\operatorname{CZ} \\ket\\psi\\ket+ \\\\\n  &= \\frac{1}{\\sqrt2}\\left( a \\ket{00} + a \\ket{01} + b \\ket{10} + b\\ket{11}\\right).\n\\end{align}\na measurement of the first qubit of the cluster in \\(\\symcal{B}\\) will project the the second qubit to \\Lfrac{1/2}\\([(a + e^{-i\\varphi}b)\\ket0 + (a - e^{-i\\varphi}b)\\ket1]\\) if the measurement yields 0, and it will project the the second qubit to \\Lfrac{1/2}\\([(a - e^{-i\\varphi}b)\\ket0 + (a + e^{-i\\varphi}b)\\ket1]\\) otherwise. Hence, measuring a qubit on \\(\\symcal{B}(\\varphi)\\) results in the unitary transformation\n\\begin{equation}\n  \\sigma_x^s \\, H P(\\varphi) = \\sigma_x^s \\, J(\\varphi),\n\\end{equation}\nwhere \\(s\\) is the measurement outcome and \\(\\sigma_x^s\\) is the by-product operator. By measuring \\(\\symcal{B}\\) with different angles, it is possible to implement \\(R_z\\) and \\(R_x\\) rotations. Using the relations\n\\begin{gather}\n  R_z(\\varphi) = J(0)J(\\varphi) = H H P(\\varphi) = P(\\varphi) \\\\\n  R_x(\\varphi) = J(\\varphi)J(0) = H P(\\varphi) H = H R_z(\\varphi) H \n\\end{gather}\nit is possible to write \\(R\\) in terms of \\(J\\).\n\\begin{equation}\n  R(\\alpha, \\beta, \\gamma) = J(0)J(\\gamma)J(\\beta)J(\\alpha)\n\\end{equation}\nPerforming four measurements on a 5 qubit linear cluster in basis \\(\\symcal{B}\\) with angles \\(\\theta_1, \\theta_2, \\theta_3\\) and 0 yields the following.\n\\begin{equation}\n  \\sigma_x^{s_4} J(0) \\sigma_x^{s_3} J(\\theta_3) \\sigma_x^{s_2} J(\\theta_2) \\sigma_x^{s_1} J(\\theta_1) \n\\end{equation}\nBy slightly modifying the measurement operators, it is possible to implement \\(R\\) up to a by-product operator. Let the new angles be\n\\begin{equation}\n  \\theta_1' = \\alpha \\quad \\theta'_2 = (-1)^{s_1} \\beta \\quad \\theta_3' = (-1)\\gamma.\n\\end{equation}\nThen these modified measurements with \\(\\theta'_i\\) yield the following operator.\n\\begin{equation}\n  \\underbrace{\\sigma_x^{s_2 + s_4} \\sigma_z^{s_1 + s_3}}_{U_{\\Sigma,R}} \\underbrace{J(0) J(\\gamma) J(\\beta) J(\\alpha)}_{R(\\alpha, \\beta,\\gamma)}\n\\end{equation}\nThis operation can be represented as a diagram as\n\\begin{equation}\n  \\tikz[ baseline={([yshift=-.5ex]current bounding box.center)} ] \\graph [\n    nodes={draw, circle, inner sep=2.5pt, thick},\n    empty nodes,\n    edges = {thick}\n  ] {\n    d[fill=zx_green] -- e[label={$\\scriptscriptstyle \\alpha$}]  -- f[label={$\\scriptscriptstyle \\beta$}] -- g[label={$\\scriptscriptstyle \\gamma$}] -- h;\n  };\n\\end{equation}\nwhere a green vertex ( \\tikz {\\node[draw, circle, inner sep=1.5pt, fill=zx_green, thick] at (0,0) {};} )  representes a measurement in \\(\\sigma_z\\), and an angle labelled vertex denotes a measurement along \\(\\symcal{B}\\). Note that as a special case of this pattern, Hadamard operator can be expressed just by three \\(\\sigma_y\\) measurements.\n\\begin{equation}\n  \\tikz[ baseline={([yshift=-.5ex]current bounding box.center)} ] \\graph [\n    nodes={draw, circle, inner sep=2.5pt, thick},\n    empty nodes,\n    edges = {thick}\n  ] {\n    d[fill=zx_green] -- e[fill=zx_yellow]  -- f[fill=zx_yellow] -- g[fill=zx_yellow] -- h;\n  };\n\\end{equation}\nYellow vertices ( \\tikz {\\node[draw, circle, inner sep=1.5pt, fill=zx_yellow, thick] at (0,0) {};} ) represent measurements along \\(\\sigma_y\\).\n\n\n\nSimulating \\(\\cnot\\) with a one-way computer is also possible. To do this, we implement the following measurement pattern,\n\\begin{equation}\n  \\tikz[ baseline={([yshift=-.5ex]current bounding box.center)} ]\n  \\graph [\n    nodes={draw, circle, inner sep=2.5pt, thick},\n    empty nodes,\n    edges = {thick}\n  ] {\n    d[fill=zx_red, label=left:{Input}] -- e[fill=zx_red] -- f[label=right:{Output}];\n    a[draw=none] --[draw=none]  g[label=right:{Control}] -- e;\n  };\n\\end{equation}\nwhere a red vertex ( \\tikz {\\node[draw, circle, inner sep=1.5pt, fill=zx_red, thick] at (0,0) {};} ) denotes a measurement along \\(\\sigma_x\\). To see how this operation works, consider a graph state with its input qubit initialized to \\(\\ket{\\psi_{i}} = a\\ket0+b\\ket1\\) and control qubit initialized to \\(\\ket{\\psi_c} = c\\ket0+d\\ket1\\).\n\\begin{align}\n  \\ket{G} &= CZ^{\\scriptscriptstyle(24)}CZ^{\\scriptscriptstyle(23)}CZ^{\\scriptscriptstyle(12)}\\ket{\\psi_i} ^{\\scriptscriptstyle(1)}\\ket+^{\\scriptscriptstyle(2)}\\ket+^{\\scriptscriptstyle(3)}\\ket{\\psi_c}^{\\scriptscriptstyle(4)} \\\\\n  &= \\begin{multlined}[t]\n    a\\ket0^{\\scriptscriptstyle(1)} \\left[\\ket0^{\\scriptscriptstyle(2)}\\ket+^{\\scriptscriptstyle(3)}(c\\ket0+d\\ket1)^{\\scriptscriptstyle(4)} + \\ket1^{\\scriptscriptstyle(2)}\\ket-^{\\scriptscriptstyle(3)}(c\\ket0-d\\ket1)^{\\scriptscriptstyle(4)} \\right] \\\\\n    + b\\ket1^{\\scriptscriptstyle(1)}\\left[ \\ket0^{\\scriptscriptstyle(2)}\\ket+^{\\scriptscriptstyle(3)}(c\\ket0+d\\ket1)^{\\scriptscriptstyle(4)} - \\ket1^{\\scriptscriptstyle(2)}\\ket-^{\\scriptscriptstyle(3)}(c\\ket0-d\\ket1)^{\\scriptscriptstyle(4)}\\right]\n  \\end{multlined}\n\\end{align}\nA measurement of the first two qubits will which resulted in \\(s_1=0\\) an \\(s_2=0\\) will yield project the state of qubits into \n\\begin{align}\n  \\ket{G'}^{\\scriptscriptstyle(34)} &= \\bra+^{\\scriptscriptstyle(1)}\\bra+^{\\scriptscriptstyle(2)}\\ket{G}^{\\scriptscriptstyle(1234)}\\\\\n  &= ac\\ket{00}^{\\scriptscriptstyle(34)} + bd\\ket{01}^{\\scriptscriptstyle(34)} + bc{10}^{\\scriptscriptstyle(34)} + ad\\ket{11}^{\\scriptscriptstyle(34)} \\\\\n  &= \\cnot^{\\scriptscriptstyle(43)} \\ket{\\psi_c}^{\\scriptscriptstyle(4)} \\ket{\\psi_i}^{\\scriptscriptstyle(3)}\n\\end{align}\nHence the operation implemented \\(\\cnot\\) on the input and control qubits and wrote the outcome to the output qubit. For different measurement values for \\(s_1\\) or \\(s_2\\), \\(\\cnot\\) is implemented up to the following by-product operator.\n\\begin{equation}\n  U_{\\Sigma, \\cnot} = \\left(\\sigma_x^{\\scriptscriptstyle(3)}\\right)^{s_2} \\left(\\sigma_z^{\\scriptscriptstyle(3)}\\right)^{s_1}\\left(\\sigma_z^{\\scriptscriptstyle(4)}\\right)^{s_1}\n\\end{equation}\n\nAs we have shown, both \\(\\cnot\\) and arbitrary rotation gates can be implemented on a one-way computer. Therefore, it is possible to simulate any computation that is possible on a quantum circuit with a one-way quantum computer by combining these measurement patterns, as described by Figure \\ref{fig:flow}.\n\n\\begin{figure}[htb]\n  \\centering\n  \\includegraphics[\n    width=0.75\\textwidth\n    ]{fig/flow.eps}\n  \\caption{Simulation of a quantum circuit with a one-way computer. Horizontal direction simulates the circuit's time evolution and vertical direction represents the qubit register. \\(\\odot\\) vertices denote a measurement along \\(\\sigma_z\\), a vertical arrow denotes a measurement along \\(\\sigma_x\\) and a tilted arrow denotes a measurement along the \\(xy\\) plane. The image by Raussendorf et. al.\\cite{russendorf2003}} \\label{fig:flow}\n\\end{figure}\n\nAfter introducing a general framework for simulating quantum circuits, we introduce two additional measurement patterns. The first one among these is a measurement by \\(\\sigma_z\\). This measurement effectively deletes a vertex from the cluster without affecting the program logic. A 2 qubit cluster state with an input \\(\\ket{\\psi} = a\\ket0+b\\ket1\\) has the following quantum state.\n\\begin{align}\n  \\ket{G} &= CZ\\ket\\psi\\ket+\\\\\n  &= \\frac{1}{\\sqrt2}(a\\ket{00} + a\\ket{01} + b\\ket{10} - b\\ket{11})\n\\end{align}\nMeasuring the second qubit will yield \\(a\\ket0+b\\ket1\\) if the outcome is 0, and it will yield \\(a\\ket0-b\\ket1\\) if otherwise. So a measurement on \\(\\sigma_z\\) removes the qubit with a side effect operator \\(\\sigma_z^s\\).\n\nThe last measurement pattern is the \\(\\sigma_x\\) measurement, which propagates the information in a linear cluster to the next vertex. The by-product operators are cyclic, with a period of four propagations.\n\\begin{equation}\n  U_\\Sigma =  \\sigma_x^{s_1} \\sigma_z^{s_2}\n\\end{equation}", "meta": {"hexsha": "cd494f3ea7bd5b65ea68b680763cb5681e4b115e", "size": 18378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/final/sections/method.tex", "max_stars_repo_name": "kurabirko/phys400", "max_stars_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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": "documents/final/sections/method.tex", "max_issues_repo_name": "kurabirko/phys400", "max_issues_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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": "documents/final/sections/method.tex", "max_forks_repo_name": "kurabirko/phys400", "max_forks_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "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.5746268657, "max_line_length": 550, "alphanum_fraction": 0.700565894, "num_tokens": 5832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6094173486613915}}
{"text": "\\input{../header_class}\r\n\r\n%---------- start document ---------- %\r\n \\section{lattice -- Lattice}\\linkedzero{lattice}\r\n \\begin{itemize}\r\n \\item {\\bf Classes}\r\n   \\begin{itemize}\r\n   \\item \\linkingone{lattice}{Lattice}\r\n   \\item \\linkingone{lattice}{LatticeElement}\r\n   \\end{itemize}\r\n \\item {\\bf Functions}\r\n   \\begin{itemize}\r\n   \\item \\linkingone{lattice}{LLL}\r\n   \\end{itemize}\r\n \\end{itemize}\r\n%\r\n  \\subsection{Lattice -- lattice}\\linkedone{lattice}{Lattice}\r\n  \\initialize\r\n  \\func{Lattice}{\r\n    \\hiki{basis}{\\linkingone{matrix}{RingSquareMatrix}},\\ \\hiki{quadraticForm}{\\linkingone{matrix}{RingSquareMatrix}}}{\\out{Lattice}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Create Lattice object. \\\\\r\n  \\spacing\r\n  % added document\r\n  \\spacing\r\n  % input, output document\r\n  \\begin{at}\r\n    \\item[basis]\\linkedtwo{lattice}{Lattice}{basis}: The basis of \\param{self} lattice.\r\n    \\item[quadraticForm]\\linkedtwo{lattice}{Lattice}{quadraticForm}: The quadratic form corresponding the inner product.\r\n  \\end{at}\r\n\\C\r\n  \\method\r\n  \\subsubsection{createElement -- create element}\\linkedtwo{lattice}{Lattice}{createElement}\r\n  \\func{createElement}{\\param{self}, \\ \\hiki{compo}{list}}{\\out{\\linkingone{lattice}{LatticeElement}}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Create the element which has coefficients with given \\param{compo}. \\\\\r\n  \\spacing\r\n  % add document\r\n  %\\spacing\r\n  % input, output document\r\n%\r\n  \\subsubsection{bilinearForm -- bilinear form}\\linkedtwo{lattice}{Lattice}{bilinearForm}\r\n  \\func{bilinearForm}{\\param{self}, \\ \\hiki{v\\_1}{\\linkingone{vector}{Vector}}, \\, \\hiki{v\\_2}{\\linkingone{vector}{Vector}} }{\\out{integer}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Return the inner product of $v_1$ and $v_2$ with \\linkingtwo{lattice}{Lattice}{quadraticForm}. \\\\\r\n  \\spacing\r\n  % add document\r\n  %\\spacing\r\n  % input, output document\r\n%\r\n  \\subsubsection{isCyclic -- Check whether cyclic lattice or not}\\linkedtwo{lattice}{Lattice}{isCyclic}\r\n  \\func{isCyclic}{\\param{self}}{\\out{bool}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Check whether \\param{self} lattice is a cyclic lattice or not.\r\n  \\spacing\r\n  % add document\r\n  \\quad \r\n  %\\spacing\r\n  % input, output document\r\n%\r\n  \\subsubsection{isIdeal -- Check whether ideal lattice or not}\\linkedtwo{lattice}{Lattice}{isIdeal}\r\n  \\func{isIdeal}{\\param{self}}{\\out{bool}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Check whether \\param{self} lattice is an ideal lattice or not.\r\n  \\spacing\r\n  % add document\r\n  %\\spacing\r\n  % input, output document\r\n\\C\r\n  \\subsection{LatticeElement -- element of lattice}\\linkedone{lattice}{LatticeElement}\r\n  \\initialize\r\n  \\func{LatticeElement}{\r\n   \\hiki{lattice}{\\linkingone{lattice}{Lattice}},\\\r\n   \\hiki{compo}{list},\\ \r\n  }{\r\n   \\out{LatticeElement}\r\n  }\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Create LatticeElement object. \\\\\r\n  \\spacing\r\n  % added document\r\n  \\quad Elements of lattices are represented as linear combinations of basis.\r\n  The class inherits \\linkingone{matrix}{Matrix}. Then, intances are regarded as $n \\times 1$ matrix whose coefficients consist of \\param{compo}, where $n$ is the dimension of lattice.\\\\\r\n  \\spacing\r\n  % input, output document\r\n  \\quad \\param{lattice} is an instance of Lattice object. \\param{compo} is coeeficients list of basis.\r\n  %\r\n  \\begin{at}\r\n    \\item[lattice]\\linkedtwo{lattice}{LatticeElement}{lattice}: the lattice which includes \\param{self}\r\n  \\end{at}\r\n\\C\r\n  \\method\r\n  \\subsubsection{getLattice -- Find lattice belongs to}\\linkedtwo{lattice}{LatticeElement}{getLattice}\r\n  \\func{getLattice}{\\param{self}}{\\out{\\linkingone{lattice}{Lattice}}}\\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Obtain the Lattice object corresponding to \\param{self}. \\\\\r\n  \\spacing\r\n  % add document\r\n  %\\spacing\r\n  % input, output document\r\n\\C\r\n  \\subsection{LLL(function) -- LLL reduction}\\linkedone{lattice}{LLL}\r\n  \\func{LLL}{\\hiki{M}{\\linkingone{matrix}{RingSquareMatrix}}}{\\out{\\hiki{L}{RingSquareMatrix}}, \\ \\out{\\hiki{T}{RingSquareMatrix}}} \\\\\r\n  \\spacing\r\n  % document of basic document\r\n  \\quad Return LLL-reduced basis for the given basis \\param{M}. \\\\\r\n  \\spacing\r\n  % add document\r\n  % \\spacing\r\n  % input, output document\r\n  \\quad The output \\param{L} is the LLL-reduced basis. \\param{T} is the transportation matrix from the original basis to the LLL-reduced basis.\r\n%\r\n\\begin{ex}\r\n>>> M=mat.Matrix(3,3,[1,0,12,0,1,26,0,0,13]);\r\n>>> lat.LLL(M);\r\n([1, 0, 0]+[0, 1, 0]+[0, 0, 13], [1L, 0L, -12L]+[0L, 1L, -26L]+[0L, 0L, 1L])\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": "1c0d44e362a605dbe0af4c7ba3569830e4549315", "size": 4686, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/lattice.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/ja/lattice.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/ja/lattice.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.0461538462, "max_line_length": 187, "alphanum_fraction": 0.6775501494, "num_tokens": 1431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117898012105, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6094173392195835}}
{"text": "\\subsection{Illustrative Example}\nDespite the differences in the statistical interpretations, we formulate a problem where $\\observed$ and $\\initial$ match the forms of $L_\\dspace$ and $\\prior$.\nHowever, we still observe differences between $\\updated$ and $\\posterior$ due to the use of a normalizing constant $C$ in $\\posterior$ and the use of $\\predicted$ in $\\updated$.\nWe explore the impact of this difference in the denominators of the solutions in the following example.\n\n%%%%%\n\n\n\\begin{ex}\nSuppose $\\pspace = [-1,1]\\subset\\RR$ and $Q(\\param)=\\param^5$ so that $\\dspace = [-1,1]$.\nFor the data-consistent framework, we assume $\\initial\\sim \\mathcal{U}([-1,1])$ and $\\observed\\sim N(0.25,0.1^2)$.\nThe push-forward of initial PDF, the observed PDF, and the updated PDF are shown in Fig.~\\ref{fig:bayes-comparison}.\n\nFor the Bayesian inverse problem, we assume $d\\in \\dspace$ with $d=Q(\\paramref)+\\xi$ where $\\xi\\sim N(0,0.1^2)$.\n%In particular, we assume that $d=0.25$ and follow the process of \\cite{Stuart10} to form the data-likelihood function so that it matches the observed density.\nWe then construct $\\pi_{\\text{post}}(\\param \\, |\\, d)$ for this example assuming a uniform prior (to match the initial density) with an assumed observed value of $d=0.25$ so that the data-likelihood function matches the observed density.\nThe posterior and its push-forward are also shown in Fig.~\\ref{fig:bayes-comparison}.\n\n\n\\begin{figure}[htbp]\n\\centering\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-1.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-pf-1.png}\n \\caption{(Left) The initial/prior PDF $\\initial$ (blue solid curve), updated PDF $\\updated$ (black dashed curve), and posterior PDF $\\pi_\\text{post}$ (green dashed-dotted curve) on $\\Lambda$.\n (Right) The push-forward (PF) of the initial/prior PDF $\\predicted$ (blue solid curve), observed/likelihood PDF (red solid curve), PF of the updated PDF $\\updated$ (black dashed curve), and the PF of the posterior PDF $\\pi_\\text{post}$ (green dashed-dotted curve) for the QoI.}\n \\label{fig:bayes-comparison}\n\\end{figure}\n\n\nWhile the updated and posterior densities in Fig.~\\ref{fig:bayes-comparison} share certain similarities (e.g., they are uni-modal with similar locations of the mode), they are otherwise visibly distinct.\nThe differences between these densities is made more evident by examining their push-forwards.\nThe push-forward of the updated density agrees well with the observed density, which is to be expected.\nHowever, the push-forward of the posterior is bi-modal and does not match the observed density, which we recall is identical to the data-likelihood function in this case.\n%with peaks that appear to align fairly well with the two distinct peaks of the predicted density and observed density.\n%Recall that the observed density and data-likelihood are, in this case, identical.\n%Moreover, with the setup described above, the predicted density can also be interpreted as the push-forward of the prior density.\n%This demonstrates the regularizing impact of the prior on the posterior and how i.\n\n%\n%Hierarchical Bayesian methods \\cite{} extend this typical framework to problems where aleatoric uncertainties are present, but are still fundamentally developed from a  point estimation perspective.\n%Specifically, prior distributions are specified from a parametric family of distributions, such as Gaussian distributions, and the hyper-parameters used to define that family of distributions, such as the means and variances, become a focal point of estimation by the methodology.\n\n\\end{ex}\n\nThe takeaway to the above discussion and example is that each density is solving a {\\em different} inverse problem.\nThe posterior density is intended to provide point estimates of a true parameter value whereas the updated density is intended to quantitatively characterize natural variations in parameter values.\nWe reformulate the previous example to make the role of data collection more central in the follow example.\n\n\\begin{ex}\nFor the (Bayesian) Deterministic Inverse Problem, suppose $Q(\\paramref)=0.25$ and noisy measurement data are drawn from a $N(0.25,0.1^2)$, i.e., we assume that each datum is given by $d=Q(\\paramref)+\\xi$ where $\\xi\\sim N(0,0.1^2)$.\nFor the SIP, we use the sample mean and variance of data to estimate the ``exact'' observed $N(0.25,0.1^2)$ distribution.\nThe observed density and data-likelihood become significantly different from one another as more data are collected.\nThe data-likelihood is in fact given by a product of normal densities.\n\nWe draw $M=5, 10, \\text{ and}, 20$ samples to form estimates of $\\observed$ and the likelihood functions.\nWe show the results in Figure~\\ref{fig:bayes-comparison-convergence}.\n\n\\begin{figure}[htbp]\n\\centering\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-5.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-pf-5.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-10.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-pf-10.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-20.png}\n   \\includegraphics[width=0.49\\linewidth]{figures/bip-vs-sip-pf-20.png}\n \\caption{(Top to Bottom): $S=5, 10, \\text{ and}, 20$ samples are used to solve the SIP and DIP for comparison. (Left) The initial/prior PDF $\\initial$ (blue solid curve), updated PDF $\\updated$ (black dashed curve), and posterior PDF $\\pi_\\text{post}$ (green dashed-dotted curve) on $\\Lambda$.\n (Right) The push-forward (PF) of the initial/prior PDF $\\predicted$ (blue solid curve), observed/likelihood PDF (red solid curve), PF of the updated PDF $\\updated$ (black dashed curve), and the PF of the posterior PDF $\\pi_\\text{post}$ (green dashed-dotted curve) for the QoI.}\n \\label{fig:bayes-comparison-convergence}\n\\end{figure}\n\nFor all values of $M$, the push-forward of the initial remains the same, and the push-forward of the update matches the observed.\nBy contrast, the posterior increases in confidence alongside the predictions it produces.\nThis further illustrates that the DIP and SIP are fundamentally different problems (they are addressing different questions).\nAs more data are incorporated, the goal of the DIP is to reduce epistemic uncertainty; for the SIP, it is to quantify the aleotoric uncertainty.\n\n\\end{ex}\n\n\n%%%%%\n\nIn summary, it is not the goal of Bayesian inference to construct a pullback distribution.\nBayesian inverse problems are fundamentally posed as parameter-identification problems, not distribution estimation problems.\nHowever, one could assume that a posterior on $\\pspace$ can be expressed as a Gaussian distribution, and solve for the most likely mean and standard deviation that characterizes it \\citep{Smith, Tarantola_book}.\nThis defines what is commonly referred to a as a Hierarchical Bayesian Inverse Problem.\n\nMore complex densities can be approximated by mixture models.\nFor example, one can assume that the posterior can be given by a linear combination of four Gaussian distributions, and solve for eight parameter values (four standard deviations and means).\nHowever, the operative word here is \\emph{assume}; in order to capture a density using a Bayesian framework, one needs to impose some sort of explicit structure on the posterior.\nNo such assumption is required in the DCI framework.\nDistributions (or measures) can be solved for directly, regardless of any nonlinear/non-parameteric structure by leveraging the measure-theoretic approaches described in \\cite{BE13} or \\cite{BJW18a}.\n\nIt is important to note that Hierarchical Bayesian inverse problem still casts a distribution-estimation problem in the context of parameter identification.\nAs a complementary line of reasoning, we seek to formulate a parameter identification problem in a DCI framework.\nFor example, the mean of the updated density could be used as an estimator to address the parameter identification problem.\nHowever, collecting more data does not improve confidence if used to estimate $\\observed$ as described above unless we revisit the results with a focus on parameter estimation by considering alternative data-driven ways to construct the QoI (and subsequently $\\observed$).\n\nIn Chapter~\\ref{chapter:mud}, we motivate the use of the maximal updated density point (maximizing the update), as a means of providing a useful point estimate to parameters.\nBefore we proceed, we finish summarizing key results about the stability and numerical convergence of the updated solution \\eqref{eq:updated-pdf} in the next section.\n\n\\FloatBarrier\n", "meta": {"hexsha": "0fa7d8f5d3990dbdfd86eb81f371648d0f09fa90", "size": 8573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro/comparison-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": "intro/comparison-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": "intro/comparison-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": 84.8811881188, "max_line_length": 294, "alphanum_fraction": 0.7798903534, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6094026610094603}}
{"text": "\t\\documentclass{standalone}\n\t\\begin{document}\n\t\\chapter{Partial Fractions}\n\t\\section{Introduction}\n\t\\emph{Consider the expression and suppose it is simplified:}\n\t\n\t\n\t\\begin{alignat*}{2}\n\t\t\\frac{2}{x+1}+\\frac{3}{2x-5} & = \\frac{2(2x-5)+3(x+1)}{(x+1)(2x-5)} \\\\\n\t\t& =\\frac{4x-10+3x+3}{(x+1)(2x-5)}      \\\\\n\t\t& =\\frac{4x-10+3x+3}{(x+1)(2x-5)}      \\\\\n\t\t& =\\frac{7x-7}{(x+1)(2x-5)}            \\\\\n\t\\end{alignat*}\n\t\n\tIn this chapter we reverse the approach above, hence decomposing one fraction to its corresponding partial fractions.\n\t\\newpage\n\t\\section{Types of partial fraction cases}\n\t\\subsection*{\\underline{Type 1: Linear Factors in denominator}}\n\t\\begin{example}\n\t\tDecompose $ \\frac{7x-7}{\\left(x+1\\right)}$ into Partial Fractions\n\t\\end{example}\n\t\\begin{alignat*}{2}\t\n\t\t&            & \\frac{7x-7}{\\left(x+1\\right)} & \\equiv \\frac{A}{\\left(x+1\\right)} + \\frac{B}{\\left(2x-5\\right)} \\\\\n\t\t& \\implies   & 7x-7                          & = A\\left(2x-5\\right)+B\\left(x+1\\right))                         \\\\\t\n\t\t& \\implies   & 7(-1)-7                       & = A(2(-1)-5)\\tag*{$x = -1$}                                     \\\\\n\t\t& \\implies   & -14                           & = -7A                                                           \\\\\\leqnomode\n\t\t& \\implies   & A                             & = 2\\tag{..1}                                                    \\\\\n\t\t& \\implies   & 7\\left(\\frac{5}{2}\\right)-7   & =B\\left(\\left(\\frac{5}{2}\\right)+1\\right)\\tag*{$x=\\frac{5}{2}$} \\\\\n\t\t& \\implies   & \\frac{35}{2} - 7              & = \\frac{7B}{2}                                                  \\\\\n\t\t& \\implies   & B                             & =3\\tag{..2}                                                     \\\\\\\\\n\t\t& \\therefore & \\frac{7x-7}{\\left(x+1\\right)} & = \\frac{2}{\\left(x+1\\right)} + \\frac{3}{\\left(2x-5\\right)}      \n\t\\end{alignat*}\n\t\n\t\n\t\\subsection*{\\underline{Type 2: Irreducible Quadratic Factor in Denominator}}\n\t\\begin{example}\n\t\tDecompose $\\frac{x^2 +1}{(2x+1)(x^2 +3)}$ into its corresponding partial fractions.\n\t\\end{example}\n\t\\begin{alignat*}{2}\n\t\t&            & \\frac{x^2 +1}{(2x+1)(x^2 +3)} & \\equiv \\frac{A}{2x+1}+\\frac{Bx+C}{x^2 +3}       \\\\\n\t\t& \\implies   & x^2 + 1                       & \\equiv A(x^ 2 + 3) + (Bx+C)(2x+1)               \\\\\n\t\t& \\implies   & x^2 + 1                       & \\equiv x^2(A+2B) + x(2B + 2C) + (3A+C)\\tag{*..} \\\\\n\t\t\\intertext{\\quad At this stage, since both equations are identical, we analyse the different coefficients and constants to form a system of equations to solve.}\n\t\t\\intertext{Comparing coefficients of $x^2\\colon$}\n\t\t&            & 1                             & = A+2B\\tag{1..}                                 \\\\\n\t\t\\intertext{Comparing coefficients of $x\\colon$}\n\t\t&            & 0                             & = B+C\\tag{2..}                                  \\\\\n\t\t\\intertext{Comparing constants$\\colon$}\n\t\t&            & C                             & = 1-3A\\tag{3..}                                 \\\\\n\t\t\\intertext{Substituting  3.. in 2..}\n\t\t&            & 0                             & =B+1-3A                                         \\\\\n\t\t& \\implies   & B                             & =3A-1\\tag{4..}                                  \\\\\n\t\t\\intertext{Substituting 4.. in 1..}\n\t\t&            & 1                             & = A + 2(3A-1)                                   \\\\\n\t\t& \\implies   & A                             & = \\frac{-1}{7} \\tag{5..}                        \\\\\n\t\t\\intertext{Substituting 5.. in 1..}\n\t\t&            & 1                             & = \\frac{-1}{7} +2B                              \\\\\n\t\t& \\implies   & -7                            & = 1-14B                                         \\\\\n\t\t& \\implies   & B                             & =\\frac{4}{7}\\tag{6..}                           \\\\\n\t\t\\intertext{Substituting 5.. in 3..}\n\t\t&            & C                             & = 1-3\\left(\\frac{-1}{7}\\right)                  \\\\\n\t\t& \\implies   & C                             & = \\frac{10}{7}                                  \\\\\n\t\t& \\therefore & \\frac{x^2 +1}{(2x+1)(x^2 +3)} & \\equiv \\frac{A}{2x+1}+\\frac{Bx+C}{x^2 +3}       \n\t\\end{alignat*}\n\t\\newpage\n\t\\subsection*{\\underline{Type 3: Repeated factor in the denominator}}\n\t\\begin{example}\n\t\tDecompose $\\frac{x+1}{(x+2)(x-3)^2}$ into its corresponding partial fractions.\n\t\\end{example}\n\t\\begin{alignat*}{2}\n\t\t&            & \\frac{x+1}{(x+2)(x-3)^2} & \\equiv \\frac{A}{x+2} + \\frac{B}{x-3} + \\frac{C}{(x-3)^2}           \\\\\n\t\t& \\implies   & x+1                      & \\equiv A(x-3)^2 + B(x-3)(x+2) + C(x+2)                             \\\\\n\t\t& \\implies   & x+1                      & \\equiv Ax^2 - 6Ax +9A + Bx^2-Bx-6B + Cx+2C)                        \\\\\n\t\t& \\implies   & -2+1                     & =A(-2-3)^2\\tag*{$x=-2$}                                            \\\\\n\t\t& \\implies   & A                        & = \\frac{-1}{25}                                                    \\\\\n\t\t& \\implies   & 3+1                      & =C(3+2)\\tag*{$x=3$}                                                \\\\\n\t\t& \\implies   & C                        & =\\frac{4}{5}                                                       \\\\\n\t\t\\intertext{Comparing coefficients of $x^2\\colon$}\n\t\t& \\implies   & 0                        & = A + B                                                            \\\\\n\t\t& \\implies   & B                        & = \\frac{1}{25}                                                     \\\\\n\t\t& \\therefore & \\frac{x+1}{(x+2)(x-3)^2} & \\equiv \\frac{1}{25(x-3)} + \\frac{4}{5(x-3)^2} - \\frac{-1}{25(x-3)} \\\\\n\t\\end{alignat*}\n\t\n\tThe approach above, is similar to the previous one, with the addition of the fact that each repeated factor has to be listed in order of powers until its own.\n\t\\newpage\n\t\\subsection*{\\underline{Type 4: Improper fraction}}\n\t\\begin{example}\n\t\tDecompose $\\frac{2x^2 -8x +11}{2x-5}$ into its corresponding partial fractions.\n\t\\end{example}\n\tSince the fraction is improper, or top-heavy\\footnotemark[2] it is required to perform a polynomial long division and acquire the proper terms. \\footnotetext[2]{Improper fractions containing a variable are recognized by the order of the exponent when the expression is expanded. i.e $\\frac{x^2}{x+5}$ is regarded as improper}\n\t\\begin{center}\n\t\t\\polylongdiv{2x^2 -8x +11}{2x-5}\n\t\\end{center}\n\t\\begin{alignat*}{2}\n\t\t& \\therefore\\quad & \\frac{2x^2 -8x +11}{2x-5} & \\equiv \tx - \\frac{3}{2} + \\frac{7}{2(2x-5)} \n\t\\end{alignat*}\n\t\\newpage\n\t\\end{document}", "meta": {"hexsha": "03603adecb90f9c4d78a720be1274727dd9b4b6e", "size": 6445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/Partial_Fractions.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/Partial_Fractions.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/Partial_Fractions.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": 65.7653061224, "max_line_length": 326, "alphanum_fraction": 0.4139643134, "num_tokens": 2080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6094026536789525}}
{"text": "Labeling the expensive Paramak model $f(x)$, a surrogate \\textcolor{red}{model is a function}\n$\\hat{f}(x)$ such that $f(x)$ and $\\hat{f}(x)$ minimize a selected dissimilarity\nmetric. In order to be considered \\textit{viable}, $\\hat{f}(x)$ is required to\nachieve \\textcolor{red}{an} expected evaluation time lower than that of~$f(x)$. In this work, we\nconsider \\textcolor{red}{two} methods of producing viable surrogates: (1)~a conventional decoupled\napproach, which evaluates $f(x)$ on a set of \\textcolor{red}{uniformly-random samples} and\ntrains surrogates in a supervised scheme, and (2)~an adaptive approach, which attempts to\ncompensate for localized regression performance \\textcolor{red}{insufficiencies} by interleaving\nmultiple epochs of sampling and training. \\textcolor{red}{Several high-accuracy and deployment-ready surrogate models are developed using the decoupled approach, and their performance characterized numerically, while the adaptive approach is studied as a proof-of-concept.}\n\n\\begin{table}[t]\n\t\\setlength\\tabcolsep{1pt}\n\t\\renewcommand{\\arraystretch}{0.95}\n\t\\caption{\\label{tbl:surrogates}Considered surrogate model families, their\n\t\tselected abbreviations and implementations. $\\mathcal{H}$~denotes the\n\t\tset of hyperparameters, \\textcolor{red}{family-dependent priors that control the\n\t\tlearning process, and are tuned separately. Families with fewer\n\t\thyperparameter represents a smaller surogate domain to explore.}}\n\t\\begin{indented}\n\t\\item[]\n\t\t\\begin{tabular}{lllr}\n\t\t\\toprule\n\t\tSurrogate family & Abbr. & Impl. & $|\\mathcal{H}|$ \\\\\n\t\t\\midrule\n\t\tSupport vector machines~\\cite{fan2008liblinear}\t& SVM & SciKit~\\cite{scikit-learn} & 3 \\\\\n\t\tGradient boosted trees~\\cite{friedman2001greedy,friedman1999stochastic,hastie2009elements}\t& GBT & SciKit & 11 \\\\\n\t\tExtremely randomized trees~\\cite{geurts2006extremely}\t& ERT & SciKit & 7 \\\\\n\t\tAdaBoosted decision trees$^\\text{a}$~\\cite{drucker1997improving}\t& ABT & SciKit & 3 \\\\\n\t\tGaussian process regression~\\cite{williams2006gaussian}\t& GPR & SciKit & 2 \\\\\n\t\t$k$ nearest neighbours\t& KNN & SciKit & 3 \\\\\n\t\tArtificial neural networks\t& ANN & Keras~\\cite{chollet2015keras} & 2 \\\\\n\t\tInverse distance weighing~\\cite{shepard1968two} & IDW & SMT~\\cite{SMT2019} & 1 \\\\\n\t\tRadial basis functions & RBF & SMT & 3 \\\\\n\t\t\\bottomrule\n\t\t\\end{tabular}\\\\%\n\t\t{\\footnotesize $^\\text{a}$Note that ABTs can be viewed as a subclass of GBTs.}\n\t\\end{indented}\n\\end{table}\n\n\\begin{table*}[t]\n\t\\renewcommand{\\arraystretch}{0.95}\n\t\\caption{\\label{tbl:metrics}Metrics recorded in experiments. In\n\tformulations, we work with a training set of size $N_0$ and a test set of\nsize $N$, values $y^{(i)}=f(x^{(i)})$ and $\\hat{y}^{(i)}=\\hat{f}(x^{(i)})$\ndenote images of the $i$th testing sample in Paramak and the surrogate\nrespectively. The mean $\\overline{y}=N^{-1}\\sum_{i=1}^N y^{(i)}$ and $P$ is the\nnumber of input features.}\n\t\\begin{indented}\n\t\\item[]\n\t\t\\begin{tabularx}{\\textwidth}{Xrl}\n\t\t\\toprule\n\t\tRegression performance metrics& Notation\t& Mathematical formulation\\\\\n\t\t\\midrule\n\t\tMean absolute error\t& MAE & $N^{-1}\\sum_{i=1}^N |y^{(i)}-\\hat{y}^{(i)}|$ \\\\\n\t\tStandard deviation of error & $S$\t& $\\text{StdDev}_{i=1}^N\\left\\{ |y^{(i)} -\n\t\t\\hat{y}^{(i)}| \\right\\} $ \\\\\n\t\t\tCoefficient of determination & $R^2$\t& $1-\\sum_{i=1}^N\n\t\t\t\\left(y^{(i)}-\\hat{y}^{(i)} \\right)^2\\left[\\sum_{i=1}^N \\left(\n\t\t\ty^{(i)}-\\overline{y} \\right)^2\\right]^{-1} $ \\\\\n\t\t\tAdjusted $R^2$ & $R^2_\\text{adj.}$\t& $1-(1-R^2)(N-1)(N-P-1)^{-1}$ \\\\\n\t\t\\midrule\n\t\tComputational complexity metrics\t& {}\t& {} \\\\\n\t\t\\midrule\n\t\tMean training time & $\\overline{t}_{\\text{trn.}}$\t& $(\\text{wall training time of\n\t\t$\\hat{f}(x)$})N_0^{-1}$  \\\\\n\t\t\tMean prediction time & $\\overline{t}_{\\text{pred.}}$\t& $(\\text{wall prediction time of\n\t\t\t$\\hat{f}(x)$})N^{-1}$ \\\\\n\t\t\t\tRelative speedup & $\\omega$\t& $(\\text{wall evaluation$^\\text{b}$ time of $f(x)$})\n\t\t\t\t(N\\overline{t}_{\\text{pred.}})^{-1}$ \\\\\n\t\t\\bottomrule\n\t\t\\end{tabularx}\\\\%\n\t\t{\\footnotesize $^\\text{b}$This corresponds to evaluation of Paramak\n\t\t on all points of the test set. In surrogates, the equivalent\n\t\ttime period is referred to as \\textcolor{red}{the} ``prediction time.''}\n\t\\end{indented}\n\\end{table*}\n\nWe selected several state-of-the-art regression algorithms to perform\nsurrogate training on sampled point sets. Listed in~\\Tref{tbl:surrogates}, these\nimplementations define \\textcolor{red}{nine} surrogate families \\textcolor{red}{which are detailed} in~\\Sref{sec:results}.\nWe note that each presented algorithm defines hyperparameters that may influence its\nperformance. Their problem-specific optimal values are searched within the scope\nof this work, in particular in Experiments~1 \\&~2 that are outlined\nin~\\Sref{sec:experiment-methodology}.\n\nTo compare the quality of the produced surrogates, we define a \\textcolor{red}{variety} of metrics listed\nin~\\Tref{tbl:metrics}. For regression performance analysis, we include a\nselection of absolute metrics \\textcolor{red}{(MAE, $S$)} to assess the models' approximation capability\nand set practical bounds on the expected uncertainty of their predictions. In addition, we also track\nrelative measures \\textcolor{red}{($R^2$, $R^2_\\text{adj.}$)} that are better-suited for comparison between this work and others as\nthey are invariant with respect to the selected domain and image space.\nFor analysis of computational complexity, surrogates are assessed in terms of wall\ntime (captured by the Python~3 \\texttt{time} package). This is motivated by common practical \\textcolor{red}{use-cases} of our work, where surrogate models are trained as replacements for\nParamak. All times reported (training, test, evaluation) are\nnormalized by the corresponding dataset size, i.e.~correspond to ``time to\nprocess a single datapoint.''\n\nEven though some surrogates support acceleration by means of \\textcolor{red}{parallelization}, we\nused non-parallelized implementations. The only exception to this \\textcolor{red}{is the ANN family},\nwhich \\textcolor{red}{requires} a considerable amount of processing power for training on\nconventional CPU architectures. Lastly, to prevent undesirable bias by training\nset selection, all reported metrics are obtained via 5-fold cross-validation.\nIn this setting, a sample set is uniformly divided into \\textcolor{red}{five} disjoint folds, each of which\nis used as a test set for models trained on the remaining \\textcolor{red}{four}. Having repeated the\nsame experiment for each division, the overall value of individual metrics is reported in terms of their mean and standard deviation over all folds.\n\n\n\n\\subsection{Decoupled Approach}\\label{sec:experiment-methodology}\n\nExperiments related to the decoupled approach are organized in \\textcolor{red}{four} parts,\nfurther described in this section. In summary, we aim to optimize the hyperparameters of\neach surrogate family separately, \\textcolor{red}{and later compare the best results between\nfamilies.}\n\nThe objective of Experiment~1 is to simplify the regression task for\nsurrogates prone to suboptimal performance in \\textcolor{red}{discrete} spaces.\nTo this end, training points are filtered to a single selected discrete feature\nassignment, and surrogates are trained only on the remaining continuous features.\nThis is repeated several times to explore variances in behavior,\nparticularly in \\textcolor{red}{four} distinct assignments that are obtained by setting blanket and\nfirst wall coolant materials to one\nof:~$\\{\\text{H\\textsubscript{2}O},\\isotope{He}\\}$.\nExperiment~2 conventionally measures surrogate performance on the full feature\nspace without any parameter restrictions. In both experiments, hyperparameter tuning is\nfacilitated by Bayesian optimisation~\\cite{movckus1975bayesian}, where we select the\nhyperparameter configuration that produces the model that maximizes $R^2$. The\nprocess is terminated after 1000~iterations or \\textcolor{red}{two} days, whichever condition is satisfied first.\nThe results of Experiments~1 \\&~2 are depicted\nin Figures~\\ref{fig:exp1-time-vs-reg} \\&~\\ref{fig:exp2-time-vs-reg}\nrespectively, and described in~\\Sref{sec:res-exp12}.\n\nIn Experiment~3, the \\textcolor{red}{twenty} best-performing hyperparameter configurations\n\\textcolor{red}{for} each model family are used to train surrogates on sets of various sizes to\ninvestigate their scaling properties. In particular, we track the metrics\nfrom~\\Tref{tbl:metrics} as functions of training set size (1, 2, 5, 10, 12, 15 and 20 thousands\nof samples) individually \\textcolor{red}{for} each family. This allows their comparison based on\nobserved trends, and estimation of optimal training set sizes.\nThe results of this experiment are shown in~\\Fref{fig:scaling} and discussed\nin~\\Sref{sec:res-exp3}.\n\nFinally, Experiment~4 aims\nto produce surrogates suitable for practical use by retraining selected\nwell-scaling instances on large training sets\\textcolor{red}{.}\nThe results of this process are displayed in~\\Fref{fig:reg-performance} and\nin~\\Tref{tbl:exp4-detailed-results}, and summarized in~\\Sref{sec:res-exp4}.\n\n\n\\subsection{Adaptive Approach}\\label{sec:adaptive}\n\nAdaptive sampling techniques appear frequently in the literature and have been\nspecialized for surrogate modelling, where precision is implicitly limited by the quantity of training samples which are available from the expensive model. Garud's~\\cite{Garud2016} ``Smart Sampling Algorithm'' achieved notable success by incorporating surrogate quality and\ncrowding distance scoring to identify optimal new samples, but was only tested\non a single-parameter domain. We theorized that a nondeterministic sample\ngeneration approach, built around Markov Chain Monte Carlo methods (MCMC), would\nfare better for high-dimensional models by more thoroughly exploring all local\noptima in the feature space. MCMC produces each sample \\textcolor{red}{point} according to a \\textcolor{red}{jump step drawn from a} shared proposal\ndistribution. These sample points will converge to a desired posterior\ndistribution, so long as the acceptance probability meets certain statistical criteria (see~\\cite{Zhou2018} for a review).\n\n\\begin{figure}\n\t\\centering\n\t\\hspace*{-5pt}\\includegraphics[width=1.28\\linewidth]{fig4_qassplan.png}\n\t\\caption{\\label{fig:qassplan}Schematic of QASS algorithm}\n\\end{figure}\n\nMany researchers have embedded surrogate methods into MCMC strategies for\nparameter optimisation~\\cite{Zhang2020,Gong2017}, in particular the ASMO-PODE\nalgorithm~\\cite{Ginting2011} which makes use of MCMC-based adaptive sampling. Our approach draws inspiration from ASMO-PODE, but instead uses MCMC to generate samples\nwhich increase surrogate precision throughout the entire parameter space.\n\nWe designed the Quality-Adaptive Surrogate Sampling algorithm (QASS, \\Fref{fig:qassplan}) to iteratively increment the training/test set with sample\npoints which maximize surrogate error and minimize a crowding distance metric\n(CDM)~\\cite{Solonen2012} in feature space. \\textcolor{red}{Error maximization is desirable for these sample points because it identifies regions of parameter space where the surrogate most needs to be improved.} On each iteration following an initial training of the surrogate on $N$ uniformly random samples, the surrogate was trained and absolute error calculated. MCMC was then performed to sample the error function generated by performing nearest-neighbor interpolation on these test error points. The resultant samples were culled by $50\\%$ according to the CDM, and then the $n$ highest-error candidates were selected for reintegration with the training/test set, beginning another training epoch. Validation was also performed during each iteration on independent, uniformly-random sample sets.\n", "meta": {"hexsha": "9952f24da0f83f977a92cc62a6830a81e34227f7", "size": 11677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/methodology.tex", "max_stars_repo_name": "ukaea-group-project/Documentation", "max_stars_repo_head_hexsha": "fcc642a2969e86c532d03254bb4b162e9f23ee01", "max_stars_repo_licenses": ["MIT"], "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/methodology.tex", "max_issues_repo_name": "ukaea-group-project/Documentation", "max_issues_repo_head_hexsha": "fcc642a2969e86c532d03254bb4b162e9f23ee01", "max_issues_repo_licenses": ["MIT"], "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/methodology.tex", "max_forks_repo_name": "ukaea-group-project/Documentation", "max_forks_repo_head_hexsha": "fcc642a2969e86c532d03254bb4b162e9f23ee01", "max_forks_repo_licenses": ["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.7257142857, "max_line_length": 802, "alphanum_fraction": 0.7693756958, "num_tokens": 3163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6094026524184271}}
{"text": "\\chapter{IMSRG(3) for the pairing Hamiltonian}\\label{app:pairing_hamiltonian_imsrg3}\n\nThe pairing Hamiltonian is given by\n\\begin{equation}\\label{eq:pairing_hamiltonian}\n    H = \\delta \\sum_{p\\sigma} (p - 1) \\crea{p\\sigma} \\annih{p\\sigma}\n    - \\frac{g}{2} \\sum_{p q} \\crea{p+}\\crea{p-} \\annih{q-} \\annih{q+}\\,,\n\\end{equation}\nwhere we have equally-spaced two-fold degenerate levels indexed by the quantum number $p$\nand an attractive (for $g > 0$) pairing interaction.\nCooper first considered this Hamiltonian in 1956~\\cite{Coop56pairing_hamiltonian},\nwhich led to the successful Bardeen-Cooper-Schreifer (BCS) theory of superconductivity~\\cite{Bard57bcs}.\nThe exact eigenvalues of the pairing Hamiltonian were given by Richardson in 1963,\nwhere the solutions are obtained via the solution of the non-linear coupled Richardson equations~\\cite{Rich63pairing_hamiltonian}.\n\nWe focus on a restricted case where $p=1,\\ldots,4$ and $\\delta=1\\mev$,\nand we vary the strength of the pairing interaction $g$.\nWe are interested in the ground state of four fermions,\nfor which our reference state is the state with the two lowest levels completely filled,\n\\begin{equation}\\label{eq:pairing_hamiltonian_reference}\n    \\refgnd = \\crea{2-}\\crea{2+}\\crea{1-}\\crea{1+}\\ket{0}\\,.\n\\end{equation}\nThis system has a couple of useful properties:\nFirst, the number of single-particle states is only eight,\nmaking the IMSRG(3) calculation relatively tractable.\nAdditionally, one can increase the number of levels $p_{\\text{max}}$ easily\nto get a handle on the performance for larger single-particle basis sizes.\nSecond, in addition to the available exact solution,\nthis system is easy to construct and diagonalize in the basis\nof the reference state and its particle-hole excitations,\n\\begin{equation}\n    \\{\\refgnd, \\refhp{ij}{ab}, \\refhp{ijkl}{abcd} \\}\\,,\n\\end{equation}\nwhere the odd number particle-hole excitations do not contribute\nas Eq.~\\eqref{eq:pairing_hamiltonian} only couples pairs.\nThis makes it easy to obtain an exact solution with which to compare the IMSRG(2)\nand IMSRG(3) solutions.\nFinally, after normal ordering the Hamiltonian with respect to our reference state,\nwe find that $\\hnoone$ is diagonal,\nmeaning our reference state is the canonical Hartree-Fock reference state\nwith the Hartree-Fock energy $\\hnozero=E_{\\text{HF}}=2 - g$.\nThis means the IMSRG evolution must only bring in correlation corrections to the energy\nwithout needing to overcome any reference state deficiencies.\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{thesis/doc/images/pairing_ham_imsrg3.pdf}\n    \\caption[\n        The correlation energy $E_{\\text{corr}}$ for the solution of the pairing Hamiltonian\n        obtained via exact diagonalization,\n        IMSRG(2), and IMSRG(3)\n        for $-1 \\le g \\le 1$.\n    ]{\n        The correlation energy $E_{\\text{corr}}$ for the solution of the pairing Hamiltonian\n        obtained via exact diagonalization,\n        IMSRG(2), and IMSRG(3)\n        for $-1 \\le g \\le 1$.\n        Exact diagonalization results obtained using code published with Ref.~\\cite{Liet16lecnotesphysics}.\n    }\\label{fig:pairing_hamiltonian_fig}\n\\end{figure}\n\nThus, we are interested in the correlation energy obtained by the IMSRG(2) and IMSRG(3) solutions,\ndefined as\n\\begin{equation}\n    E_{\\text{corr}} \\equiv E(s \\rightarrow \\infty) - E(s= 0)\\,.\n\\end{equation}\nThis is plotted in Fig.~\\ref{fig:pairing_hamiltonian_fig} for $-1 \\le g \\le 1$.\nWe find generally good agreement between the IMSRG correlation energy\nand the exact correlation energy,\nwith the exception of the region for $0.5 \\le g \\le 1$.\nHere, the IMSRG(3) calculation improves upon the relatively large error in the IMSRG(2)\ncorrelation energy,\nwhich in Ref.~\\cite{Herg16imsrglecnotes}\nwas explained as being due to an overcounting in the fourth-order diagrams in MBPT\nby a factor of 1/2 present in the IMSRG(2) truncation.\nIt seems that this overcounting at fourth-order is lifted in the IMSRG(3).\nWe note here that our results for IMSRG(2) match exactly with those from Ref.~\\cite{Herg16imsrglecnotes}.\n", "meta": {"hexsha": "10271c269ea7539b7b8a40c488d4647a190fc054", "size": 4096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/doc/a03_pairing_hamiltonian_imsrg3.tex", "max_stars_repo_name": "cheshyre/masters-thesis", "max_stars_repo_head_hexsha": "464fb498b0f0225d370358164c8efefe014fa820", "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": "thesis/doc/a03_pairing_hamiltonian_imsrg3.tex", "max_issues_repo_name": "cheshyre/masters-thesis", "max_issues_repo_head_hexsha": "464fb498b0f0225d370358164c8efefe014fa820", "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": "thesis/doc/a03_pairing_hamiltonian_imsrg3.tex", "max_forks_repo_name": "cheshyre/masters-thesis", "max_forks_repo_head_hexsha": "464fb498b0f0225d370358164c8efefe014fa820", "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.1948051948, "max_line_length": 130, "alphanum_fraction": 0.7553710938, "num_tokens": 1164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6094026505858001}}
{"text": "\n\n\n\\section{Antennas}\n\n\\quickimage{Propagation/consts}{.5}\n\nThe electric permittivity is what relates the Electric Displacement Vector (D) and the Electric Field (E). For a deeper meaning one has to look into the constitutive relations as well.\nLikewise, the magnetic permeability relates the Magnetic Induction Field (B) with the Magnetic Field (H).\n\n\\quickimage{Propagation/constitutivas.png}{.5}\n\nThe Electric Polarization and Magnetization vectors show how the material changes when to being subjected to a Electric/Magnetic field. This change can be displacement of charges according due to the application of the Electric field or similar in relation to the magnetic induction field. The higher the permittivity, the most charges move with the application of the field. The higher the permeability, the higher the internal magnetic field.\n\n\n\n\n\\section{Radio Wave Propagation} \n\nIt is absolutely pivotal some nomenclature in order to understand each other.\n\n\\quickimage{Propagation/1.png}{.6}\n\nMainly, everything that is bold is a vector and everything that has a bar on top is a complex amplitude. With these definitions out of the way, we can start:\n\\vspace{.5cm}\n\n\nA wave propagating across the z direction has the following (mathematical) shape:\n\n\\begin{equation}\n    e(z,t) = E_o cos(wt - kz)\n\\end{equation}\n\nWe can only talk about waves when the field disturbance changes in time and propagates in space, thus the dependence with a spatial coordinate and time. Note further that we start off with a very simple wave: is sinusoidal, doesn't have attenuation, only propagates in one direction and only oscillates in one direction.\n\nTo write a (slightly) more general formula for a wave, while taking advantage of the complex notation that assumes already a sinusoidal wave - note that the real part of a exponential is a cossine -, we get:\n\n\\begin{equation}\n    e(z,t) = Re\\{E e^{jwt}\\}, E = E_o e^{-jkz}\n\\end{equation}\n\\begin{equation}\n    e(r,t) = E  cos(wt - \\boldsymbol{k} \\cdot \\boldsymbol{r})\n\\end{equation}\n\n\nSomething important to keep in mind:\n\n\\begin{center}\n    \\bb{In free space, electric and magnetic fields are\n    mutually orthogonal and orthogonal to the\n    propagation direction.}\n\\end{center}\n\n\nNote, however, that this is not true for propagation in matter that is anisotropic or when the waves are contained in a waveguide such like a metallic waveguide where there are TE/TM modes. But we won't consider those cases, at least for now.\n\nAlso, the vector $\\boldsymbol{k}  = k_x \\hat{x} + k_y \\hat{y} + k_z \\hat{z}$ represents the direction of propagation because each of its components will contribute a phase to the oscillation of the wave.\n\nFurther note that the above wave equation is for a plane wave. Fortunately in the far-field all waves are plane waves or can be obtained from them therefore that expression will pop-up fairly often. However, most waves are spherical waves that are no more than plane waves that decay with the radius to the source, therefore the surfaces of equal amplitude are spheres.\n\n\\begin{equation}\n    \\frac{A}{r} e^{j(wt-kr)}\n\\end{equation}\n\nThe more general formula for the complex amplitude is:\n\n\\quickimage{Propagation/3.png}{.6}\n\nThe last part is important because the expression for the free space impedance $Z_0$ comes directly from the Maxwell equations and it is easier to solve them in the frequency domain (with complex amplitudes/phasors).\n\n\\quickimage{Propagation/2.png}{.5}\n\nResulting in the expression below, from where we can prove the previous statement of orthogonality between fields and direction of propagation.\n\n\\quickimage{Propagation/2-5.png}{.5}\n\nThen many expressions come from the Maxwell equations when we consider losses. Because the actual Dispersion Equation is the following:\n\n\\quickimage{Propagation/4.png}{.5}\n\n\n\\bb{Note that the amplitudes of the field for each component} can NOT be a positive number. They can be a complex number in the sense that they will influence the polarization of the field. We'll see that in the next section!\n\nIn summary:\n\\quickimage{Propagation/5.png}{.5}\n\n\n\\subsection{Polarization}\n\n\n\n\n\n\\bb{The polarization is the shape the field oscillation describes while looking at the wave from propagation direction with the wave going away from us}. An easier way of finding if it is rotating to the left or to the right, we can use the right-hand, with the thumb along the propagation. If it is rotating along the way our (right-)hand closes, then it is a right circular polarisation. \n\nThe reference for horizontal polarisation is the earth.\n\n\nThis derivation of \\href{http://kestrel.nmt.edu/~mce/Polarization}{\\ul{The general Elliptic polarization}} shows why plane waves propagating freely can have its polarization described generally by an ellipse. Also shows that certain specific parameters of that ellipse can lead to certain more familiar polarizations, such as linear and circular.\n\n\n\\quickimage{Propagation/pol1.png}{.5}\n%explain this\n\n\\subsection{Reflection}\n\nAll reflections' chapter is according to Snell Laws.\n\nA few bullet points to take away from the first class on reflection are:\n\\begin{itemize}\n    \\item a dry soil behaves as a metal for a very small angle with the ground, typical in very long distances. ``Behaving as a metal'' means that the reflection coefficient will be -1, for either polarisation;\n    \\item Brewster's Angle is of incidence for which the parallel component of the field is passes completely to the other side of the surface. The reflected wave does a $90^{\\circ}$ angle with the refracted wave and only has H field. Note that this only happens for parallel polarisation. In perpendicular is the H field that will be suppressed on reflection. The perpendicular component is never fully absorbed. \n    \\item Horizontal polarisation always has bigger reflection coefficients therefore is worst to use because it will cause more variability on the arrival. Other word for incidences with very short angles with the ground is \"grazing incidences\".\n    \\item Dependences with frequency increase with dielectric conductivity. Else the losses will simply be too small.\n\\end{itemize}\n\nOne thing that needs to be introduced are the Fresnel coefficients:\n\\quickimage{Propagation/6.png}{.5}\n\n\nNote further that the last bullet point mentioned the tangent of the loss angle.\n\n\\begin{equation}\n    \\tan \\delta = \\frac{\\sigma}{\\omega \\epsilon}\n\\end{equation}\n\nNote that if the conductivity is too small, the whole expression will be controlled by that and the frequencies would have to be very small as well to make a difference. Since we don't use those frequencies in Radio Propagation, we may say that only for a sufficiently high conductivity, the frequency dependence increases.\n\n\n\\subsection{Spherical Earth}\n\nSurprise: the Earth is not flat, it's spherical. And this curvature needs to be accounted specially because even the direct ray may be influenced by this curvature.\n\n", "meta": {"hexsha": "9d80386c1354d04e1b76809148afe77f24d14017", "size": 6932, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/RadioPropagation.tex", "max_stars_repo_name": "jmoraispk/TheDocument", "max_stars_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_stars_repo_licenses": ["MIT"], "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/RadioPropagation.tex", "max_issues_repo_name": "jmoraispk/TheDocument", "max_issues_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_issues_repo_licenses": ["MIT"], "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/RadioPropagation.tex", "max_forks_repo_name": "jmoraispk/TheDocument", "max_forks_repo_head_hexsha": "ef14eaaec34cb09a0945ff4647e87ff77eac6890", "max_forks_repo_licenses": ["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.7313432836, "max_line_length": 444, "alphanum_fraction": 0.7823139065, "num_tokens": 1553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6094026450879195}}
{"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% 2D wave propagation subsection of the modeling part\r\n% ***********************************************************************************\r\n\r\n\r\n\\paragraph{Control model}\r\n\r\nWe consider here the simplest model for which a Kalman filter can really bring an added value: a linear, Gaussian and real (i.e. 1D) model:\r\n\\begin{eqnarray}\r\n\\label{kalman-dynamics.eq1}\r\nx_{k+1} &=& A x_k + B u_k + v_k\\\\\r\n\\label{kalman-dynamics.eq2}\r\ny_k &=& C x_k + w_k\r\n\\end{eqnarray}\r\nwhere $X=(x_k)$ is the state of the system (typically a distance to a prescribed value, in whatever unit), $U=(u_k)$ is the control, $Y=(y_k)$ is the measurement. $V=(v_k)$ (resp. $W=(w_k)$) is a Gaussian noise: the $v_k$ (resp. $w_k$)are independent and identically distributed random variables with 0 mean and variance $Q$ (resp. $R$). The initial state $x_0$ is also a centered random variable with variance $\\bar{P}_O$. Note that these notation perfectly adapt to multidimensional systems, with matrices: see any textbook on control to get the matrix equations.\r\n\r\nThis is not specifically needed for Kalman filter, but the usual optimization criteria is quadratic:\r\n\\begin{equation}\\label{kalman-cost.eq1}\r\n\tJ(X,U) = \\frac{1}{N}\\sum_{k=0}^N \\alpha u_k^2 + \\beta x_k^2\r\n\\end{equation}\r\n\r\nThe Equations~(\\ref{kalman-dynamics.eq1})-(\\ref{kalman-dynamics.eq2}) are often written for each time step so the scaling with respect to time has to be careful. In a system with a 100 Hz time step (also refered to as control frequency), typical values are:\r\n\\begin{eqnarray*}\r\nA &=& 1.001\\\\\r\nB &=& .01\\\\\r\nC &=& 1\\\\\r\nQ &=& .001\\\\\r\nR &=& .01\r\n\\end{eqnarray*}\r\nWe have taken $C=1$ because most of the time we try to have a measurement as close to the state as possible and if $C\\neq 1$ it is possible to compensate it. $A>1$ means that the system is unstable: Figure~\\ref{Kalman-free.fig} shows the divergent behavior.\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Kalman-free}       \r\n\t\\caption{The free system dynamics: it shows instability and the system tends to diverge exponentially. The variance $\\sigma_R^2$ (resp. $\\sigma_Q^2$ ) is denoted by $R$ (resp. $Q$) in the system model.}\r\n\t\\label{Kalman-free.fig}\r\n\\end{figure}\r\n\r\n\\paragraph{A naive control}\r\nNow, we would like to stabilize the state of the system as close to zero as possible, and if possible at a reasonable cost. This means we can adjust the weights $\\alpha$ and $\\beta$ in the cost function~(\\ref{kalman-cost.eq1}). Or simpler measure the 2 partial cost functions\r\n\\begin{eqnarray}\r\n\\label{kalman-costX.eq}\r\nJ_1(X) &=& \\frac{1}{N}\\sum_{k=0}^N  x_k^2\\\\\r\n\\label{kalman-costU.eq}\r\nJ_2(U) &=& \\frac{1}{N}\\sum_{k=0}^N u_k^2\r\n\\end{eqnarray}\r\n\r\nNow, we introduce the simplest possible control: a proportional control with gain $K$ defined by:\r\n\\begin{equation}\r\n\\label{kalman-Pcontrol.eq}\r\n\tu_k = -K y_k\r\n\\end{equation}\r\n\r\nSince we have \"unit\" parameters, let's start with a unit gain $K=1$. This indeed stabilizes the system as we see in Figure~\\ref{Kalman-control-Gain1.fig}.\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Kalman-control-Gain1}       \r\n\t\\caption{The same system as in Figure~\\ref{Kalman-free.fig} with the proportional control as defined by Equation~(\\ref{kalman-Pcontrol.eq}) with gain $K=1$. The system is indeed stable with empirical costs $J_1=0.06$ and  $J_2=0.07$.}\r\n\t\\label{Kalman-control-Gain1.fig}\r\n\\end{figure}\r\n\r\nNow, if we try to maximize the precision (at all cost), we can try to compensate the term $A x_k$ in Equation~(\\ref{kalman-dynamics.eq1}) by the term $B u_k = -BK Y_k = -(BKC) x_k -BK w_k$. Since we have no control onto the noise, and since this noise is centered, let's take $A = BKC$, i.e. in our case $K = A/BC = 100.1$. This lead to the result of Figure~\\ref{Kalman-control-Gain100.fig}. What is impressive is not so much the increase in precision, $J_1$ is divided by about 5, that the explosion of the control cost $J_2$, multiplied by about 3,000.\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Kalman-control-Gain100}       \r\n\t\\caption{The same system as in Figure~\\ref{Kalman-control-Gain1.fig} with $K=100.1$ in order to fully compensate $A$. The system is very stable with empirical costs $J_1=0.011$ and  $J_2=209$.}\r\n\t\\label{Kalman-control-Gain100.fig}\r\n\\end{figure}\r\n\r\nIn order to learn more about the trade-off between precision and control cost, one can test intermediary gains, and for $K=10$, we get the Figure~\\ref{Kalman-control-Gain10.fig}. There we have a surprise: the precision is better than with our naively optimal gain $K=100.1$, not to speak of the decrease of the control cost. There are now 2 paths for us: either --- pragmatically --- adjust the gain to get the best control, or --- analytically --- try to understand what was wrong. Indeed, this numerical experiment clearly shows we are missing an important idea. And the idea we are missing is the following: we can have much better estimates of $x_k$ than $y_k$ (even after compensating some multiples in the $C$ coefficient. What we do with the heavy gain $K=100.1$ is simply to add noise. And if we go even further (e.g. $K=200$), the system becomes unstable.\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Kalman-control-Gain10}       \r\n\t\\caption{The same system as in Figure~\\ref{Kalman-control-Gain1.fig} with $K=10$. The empirical costs are $J_1=5.8\\ 10^{-3}$ and  $J_2=1.59$.}\r\n\t\\label{Kalman-control-Gain10.fig}\r\n\\end{figure}\r\n\r\n\\paragraph{The Kalman filter}\r\nNow, we introduce the equations of the Kalman filter, which we know are optimal to estimate $x_k$.\r\n\\begin{eqnarray}\r\n\\label{kalman-filter.eq1}\r\n\\hat{x}_0 &=& 0\\\\\r\n\\label{kalman-filter.eq2}\r\nP_0 &=& \\bar{P}_0\\\\\r\n\\label{kalman-filter.eq3}\r\n\\hat{x}^-_{k+1} &=& A \\hat{x}_k + B u_k\\\\\r\n\\label{kalman-filter.eq4}\r\nP^-_{k+1} &=& A P_k A + Q\\\\\r\n\\label{kalman-filter.eq5}\r\n\\hat{x}_{k+1} &=& \\hat{x}^-_{k+1} + L_{k+1}\\left(y_{k+1}-C\\hat{x}^-_{k+1}\\right)\\\\\r\n\\label{kalman-filter.eq6}\r\nL_{k+1} &=& P^-_{k+1}C\\left(CP^-_{k+1}C+R\\right)^{-1}\\\\\r\n\\label{kalman-filter.eq7}\r\nP_{k+1} &=& \\left(1-L_{k+1}C\\right)P^-_{k+1}\r\n\\end{eqnarray}\r\nThese equations can be found in any textbook on control and are almost true as is for multidimensional states and measures. The most striking here is that the filter works whatever the control.\r\n\r\nThere is not much difference with Equation~(\\ref{kalman-Pcontrol.eq}) in our control model, except that we take the best estimate:\r\n\\begin{equation}\r\n\\label{kalman-Pcontrol.eq2}\r\n\tu_k = -K \\hat{x}_k\r\n\\end{equation}\r\n\r\nThis leads to the result of Figure~\\ref{Kalman-TrueControl-Gain100.fig}. The precision is better than our previous best control (that was obtained for a lower gain) and the control cost is much lower than the control with same gain but based on Equation~(\\ref{kalman-Pcontrol.eq}). Empirically, one sees that this gain is the optimal value in term of precision. As we are curious, we also vary the gain and we get the following results: for $K=10$, $J_1=8\\ 10^{-3}$ and  $J_2=0.53$; for $K=1$, $J_1=0.072$ and  $J_2=0.069$. So we see that for lower gains (and this is much closer to realistic values), the precision is not much improved and the control cost improvement is noticeable mainly for high gains. Again, this certainly means we are missing some concepts. And here what we are missing is the notion of a better feedback control: the proportional control is too simple to be optimal. We could try a PID (Proportional-Integral-Derivative) or other controls (e.g. with pole placement), but in any case we learned that a Kalman filter allow to reduce the noise in the estimation of the state $x_k$.\r\n\r\n\r\n\\begin{figure}[htb]\r\n\t\\centering\r\n\t\\includegraphics[width=10cm]{Kalman-TrueControl-Gain100}       \r\n\t\\caption{The system with a proportional control based on Kalman filter with $K=100.1$. The empirical costs are $J_1=3.77\\ 10^{-3}$ and  $J_2=10.2$.}\r\n\t\\label{Kalman-TrueControl-Gain100.fig}\r\n\\end{figure}\r\n\r\nIn conclusion, note that what we learned practically about estimates, noise reduction and control are very general concepts that can be adapted to many situations, including PDEs. However, it generally requires some know-how to apply these notions.", "meta": {"hexsha": "c932c6398ac98f325636a8fc4da9989343e15949", "size": 8471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "control-kalman.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": "control-kalman.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": "control-kalman.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": 70.5916666667, "max_line_length": 1104, "alphanum_fraction": 0.7088891512, "num_tokens": 2479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396211, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6094026407924028}}
{"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 6}\n\nGive a counter-example to the conjecture that if a directed graph $G$ contains a path from $u$ to $v$, and if $u.d < v.d$ in a depth-first search of $G$, then $v$ is a descendant of $u$ in the depth-first forest produced.\n\n\\subsection*{Solution}\n\nAny directed graph $G$ with a path from $u$ to $v$ through the source vertex $s$ would be considered as counter-example for the proposed statement.\nFigure \\ref{fig61} depicts graph $G$ with source vertex $a$ as one counter-example following required conditions.\n\n\\begin{figure}[H]\\centering\n\\tikzstyle{vertex}=[circle,draw,minimum size=0.7cm]\n  \\begin{tikzpicture}\n    \\node[vertex] (1) {a};\n    \\node[vertex] (2) [below left = 0.5cm and 1.5cm of 1] {b};\n    \\node[vertex] (3) [below right = 0.5cm and 1.5cm of 1] {c};\n    \\path[draw,thick,->]\n\t(1) edge [bend left=30] (2)\n\t(1) edge (3)\n    (2) edge [bend left=30] (1)\n\t;\n    \\path[draw,ultra thick,->]\n    ;\n  \\end{tikzpicture}\n\\caption{Example that if $u.d < v.d$ and $u$ has path to $v$,  graph $G$}\\label{fig61}\n\\end{figure}\n\nStarting from $a$, node $a$ is visited first, and vertices $b$ and $c$ are discovered and placed in queue.\nIn next step, if $b$ is the first node to be visited, the depth-first search algorithm will follow by discovering children of $b$.\nSince $b$ has only one child that is already visited, the depth-first search algorithm continues by visiting vertex $c$.\nIn this case, although there is a path from $b$ to $c$ and $b.d < c.d$, $c$ is not a descendant of $b$.\n", "meta": {"hexsha": "50b2c0d45b3db7beebaabd2b68e33a3e3f9f8ef4", "size": 1868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw05/hw05q06.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/hw05q06.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/hw05q06.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": 49.1578947368, "max_line_length": 221, "alphanum_fraction": 0.6472162741, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.8840392710530071, "lm_q1q2_score": 0.6093732349957492}}
{"text": "\\subsection*{Querying}\n\\paragraph{Optimization:} $\\forall x. T(\\phi)(x) = 0 \\Leftrightarrow x \\text{ satisfies } \\phi$\n\n\\centering\n\\begin{tabular}{ll}\n$\\phi$ & $T(\\phi)$ (non-negative) \\\\\\hline\n$t_1 \\le t_2$ & $\\max(0, t_1-t_2)$ \\\\\n$t_1 \\neq t_2$ & $[t_1 = t_2]$ \\\\\n$t_1 = t_2$ & $T(t_1 \\le t_2 \\land t_2 \\le t_1$ \\\\\n$t_1 < t_2$ & $T(t_1 \\le t_2 \\land t_1 \\neq t_2)$ \\\\\n$\\phi \\lor \\psi$ & $T(\\phi) \\cdot T(\\psi)$ \\\\\n$\\phi \\land \\psi$ & $T(\\phi) + T(\\psi)$\n\\end{tabular}\n\n\\raggedright\n\\paragraph{Box} Box constraints are encoded separately (e.g., w/ L-BFGS-B optimizer)\n\n\\paragraph{Counter-example} Use optimization to find counter-examples to a given property. \n\n\\subsection*{Training with Background Knowledge}\n\\begin{enumerate}\n\\item $\\displaystyle \\argmax_\\theta \\E_{s \\sim D} \\left[ \\forall z. \\phi(z, s, \\theta) \\right]$ (find $\\theta$ s.t. exp. val. of property increases)\n\n\\item $\\displaystyle \\argmin_\\theta \\E_{s \\sim D} \\left[ \\max_z \\lnot \\phi(z, s, \\theta) \\right]$ (find $\\theta$ s.t. max. violation of $\\phi$ is minimized)\n\n\\item $\\displaystyle \\argmin_\\theta \\E_{s \\sim D} \\left[ T(\\phi)(z_\\text{worst}, s, \\theta) \\right]$,\n$\\displaystyle z_\\text{worst} := \\argmin_z T(\\lnot \\phi)(z, s, \\theta)$ (find worst possible violation of $\\phi$, then find $\\theta$ that minimizes its effect)\n\\end{enumerate}\n\nTo solve inner opt. problem efficiently, split into objective and (efficient) projections on convex set (e.g., $L_\\infty$-ball)\n", "meta": {"hexsha": "63a2af4ebee4ffb4a699eb1cf0d6936a642ef270", "size": 1445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "logic.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": "logic.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": "logic.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": 46.6129032258, "max_line_length": 159, "alphanum_fraction": 0.662283737, "num_tokens": 522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6093688764413693}}
{"text": "\\chapter{Linear function}\n\\section{Defined on $\\mdr$}\n\\begin{theorem}[Solution formula for linear functions on $\\mdr$]\n    Let $f: \\mdr \\rightarrow \\mdr $ be a linear function\n    $f(x) := m \\cdot x + t$ with $m \\in \\mdr \\setminus \\Set{0}$ and\n    $t \\in \\mdr$ be a linear function.\n\n    Then there is only one point $(x, f(x))$ on the graph of $f$ with\n    minimal distance to $P = (x_P, y_P)$. This point is given by\n    \\[x = \\frac{m}{m^2+1} \\left ( y_P + \\frac{1}{m} \\cdot x_P - t \\right )\\]\n\\end{theorem}\n\n\\begin{figure}[htp]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            legend pos=north east,\n            legend cell align=left,\n            axis x line=middle,\n            axis y line=middle,\n            grid = major,\n            width=0.8\\linewidth,\n            height=8cm,\n            grid style={dashed, gray!30},\n            xmin= 0, % start the diagram at this x-coordinate\n            xmax= 5, % end   the diagram at this x-coordinate\n            ymin= 0, % start the diagram at this y-coordinate\n            ymax= 3, % end   the diagram at this y-coordinate\n            axis background/.style={fill=white},\n            xlabel=$x$,\n            ylabel=$y$,\n            tick align=outside,\n            minor tick num=-3,\n            enlargelimits=true,\n            tension=0.08]\n          \\addplot[domain=-5:5, thick,samples=50, red] {0.5*x};\n          \\addplot[domain=-5:5, thick,samples=50, blue, dashed] {-2*x+6};\n          \\addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};\n          \\newcommand{\\R}{0.9}\n          \\addplot [domain=0:2*pi,samples=50, dotted]({\\R*cos(deg(x))+2},{\\R*sin(deg(x))+2});\n          \\addplot[blue, nodes near coords=$f_\\bot$,every node near coord/.style={anchor=225}] coordinates {(1.5, 3)};\n          \\addplot[red, nodes near coords=$f$,every node near coord/.style={anchor=225}] coordinates {(0.9, 0.5)};\n          \\addlegendentry{$f(x)=\\frac{1}{2}x$}\n          \\addlegendentry{$f_\\bot(x)=-2x+6$}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption{The shortest distance of $P$ to $f$ can be calculated by using the perpendicular}\n    \\label{fig:linear-min-distance}\n\\end{figure}\n\n\\begin{proof}\n    With Theorem~\\ref{thm:fermats-theorem} you get:\n    \\begin{align}\n        0 &\\stackrel{!}{=} (d_{P,f}(x)^2)'\\\\\n        &= 2(x-x_P) + 2 (f(x) - y_P)f'(x)\\\\\n        \\Leftrightarrow 0 &\\stackrel{!}{=} x - x_P + (f(x) - y_P) f'(x)\\\\\n        &= x- x_P + (mx+t - y_P)\\cdot m\\\\\n        &= x (m+1) + m(t-y_P) - x_P\\\\\n        \\Leftrightarrow x &\\stackrel{!}{=} \\frac{x_p - m(t-y_p)}{m^2+1}\\\\\n        &= \\frac{m}{m^2+1} \\left ( y_P + \\frac{1}{m} \\cdot x_P - t \\right )\\label{eq:solution-linear-r}\n    \\end{align}\n    It is obvious that a minium has to exist, the $x$ from Equation~\\ref{eq:solution-linear-r}\n    has to be this minimum. $\\qed$\n\\end{proof}\n\\clearpage\n\n\\section{Defined on a closed interval $[a,b] \\subseteq \\mdr$}\nLet $f:[a,b] \\rightarrow \\mdr$, $f(x) := m\\cdot x + t$ with $a,b,m,t \\in \\mdr$ and\n$a \\leq b$, $m \\neq 0$  be a linear function.\n\n\\begin{figure}[htp]\n    \\centering\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            legend pos=north east,\n            legend cell align=left,\n            axis x line=middle,\n            axis y line=middle,\n            grid = major,\n            width=0.8\\linewidth,\n            height=8cm,\n            grid style={dashed, gray!30},\n            xmin= 0, % start the diagram at this x-coordinate\n            xmax= 5, % end   the diagram at this x-coordinate\n            ymin= 0, % start the diagram at this y-coordinate\n            ymax= 3, % end   the diagram at this y-coordinate\n            axis background/.style={fill=white},\n            xlabel=$x$,\n            ylabel=$y$,\n            tick align=outside,\n            minor tick num=-3,\n            enlargelimits=true,\n            tension=0.08]\n          \\addplot[domain= 2:3, thick,samples=50, red] {0.5*x};\n          \\addplot[domain=-5:5, thick,samples=50, blue, dashed] {-2*x+6};\n          \\addplot[domain=1:1.5, thick, samples=50, orange] {3*x-3};\n          \\addplot[domain=4:5, thick, samples=50, green] {-x+5};\n          \\addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};\n          \\draw[thick, dashed] (axis cs:2,2) -- (axis cs:1.5,1.5);\n          \\draw[thick, dashed] (axis cs:2,2) -- (axis cs:4,1);\n          \\addlegendentry{$f(x)=\\frac{1}{2}x, D = [2,3]$}\n          \\addlegendentry{$f_\\bot(x)=-2x+6, D=[-5,5]$}\n          \\addlegendentry{$h(x)=3x-3, D=[1,1.5]$}\n          \\addlegendentry{$h(x)=-x+5, D=[4,5]$}\n        \\end{axis}\n    \\end{tikzpicture}\n    \\caption{Different situations when you have linear functions which\n             are defined on a closed intervall}\n    \\label{fig:linear-min-distance-closed-intervall}\n\\end{figure}\n\nThe point with minimum distance can be found by:\n\\[\\underset{x\\in[a,b]}{\\arg \\min d_{P,f}(x)} = \\begin{cases}\n S_1(f, P) &\\text{if } S_1(f, P) \\cap [a,b] \\neq \\emptyset\\\\\n   \\Set{a} &\\text{if } S_1(f, P) \\ni x < a\\\\\n   \\Set{b} &\\text{if } S_1(f, P) \\ni x > b\n    \\end{cases}\\]\n\nIf $S_1(f, P) \\cap [a,b] \\neq \\emptyset$, then $\\underset{x\\in[a,b]}{\\arg \\min d_{P,f}(x)} = S_1(f,P) \\cap [a,b]$,\nbecause $S_1(f,P)$ gives all global minima of $f$. Those are also\nminima for the intervall $[a,b]$. There are not more minima, because\n$S_1$ gives all minima of $P$ to $f$.\n\nIf $S_1(f, P) \\cap [a,b] = \\emptyset$, then it is not that simple.\nBut we can calculate the distance function:\n\n\\begin{align}\n    d_{P,f}(x) &= \\sqrt{(x-x_P)^2 + (f(x) - y_P)^2}\\\\\n    &= \\sqrt{(x^2 - 2x x_P + x_P^2) + (mx + (t-y_P))^2}\\\\\n    &= \\sqrt{(x^2 - 2x x_P + x_P^2) + m^2 x^2 + 2mx(t-y_P) + (t-y_P)^2}\\\\\n    &= \\sqrt{x^2(1+m^2) + x(-2 x_P + 2m(t-y_P)) + (x_P^2 + (t-y_P)^2)}\n\\end{align}\n\nThis function (defined on $\\mdr$) is symmetry to the axis\n\\begin{align}\n    x_S &= - \\frac{-2 x_P + 2m(t-y_P)}{2(1+m^2)}\\\\\n    &= \\frac{x_P - m(t-y_P)}{1+m^2}\\\\\n    &= \\frac{m}{m^2+1} (y_P + \\frac{1}{m} x_P - t)\n\\end{align}\n\n$f$ is on $(-\\infty, x_S]$ strictly monotonically decreasing and\non $[x_S, + \\infty)$ strictly monotonically increasing.\n\nThus we can conclude:\n\\[\\forall x,y \\in \\mdr: x \\leq y < x_S \\Rightarrow d_{P,f}(x_S) < d_{P,f}(y) \\leq d_{P,f}(x)\\]\n\\[\\forall x,y \\in \\mdr: x_S < y \\leq x \\Rightarrow d_{P,f}(x_S) < d_{P,f}(y) \\leq d_{P,f}(x)\\]\n\nWhen $S_1(f, P) \\cap [a,b] = \\emptyset$, then you can have two cases:\n\\begin{itemize}\n    \\item $a \\leq b < x_S$: $b$ has the shortest distance in $[a,b]$\n             on the graph of $f$ to $P$.\n    \\item $x_S < a \\leq b$: $a$ has the shortest distance in $[a,b]$\n             on the graph of $f$ to $P$.\n\\end{itemize}\n", "meta": {"hexsha": "121980a60af029fa05f4f252feaef29d030e5a37", "size": 6696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/math-minimal-distance-to-cubic-function/linear-functions.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": "documents/math-minimal-distance-to-cubic-function/linear-functions.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": "documents/math-minimal-distance-to-cubic-function/linear-functions.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": 43.2, "max_line_length": 122, "alphanum_fraction": 0.5554062127, "num_tokens": 2375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6093448872947405}}
{"text": "\\section{The Kalman Gain}\n\nThe Kalman Gain, $\\boldsymbol{K}$, is the heart of the kalman filter's \\textit{Update} step. It is a matrix that allows uncertainties and covariances to influence the evolution of the state, and it depends on the innovation covariance $\\boldsymbol{S}$.\n\\begin{equation}\n    \\boldsymbol{S} = \\boldsymbol{H} \\cdot \\boldsymbol{P} \\cdot \\boldsymbol{H}^T + \\boldsymbol{R}\n\\end{equation}\n\nThe inverse of this innovation covariance is directly used to compute the Kalman Gain.\n\n\\begin{equation}\n    \\boldsymbol{K} = \\boldsymbol{P} \\cdot \\boldsymbol{H}^T \\cdot \\boldsymbol{S}^{-1}\n\\end{equation}\n\n\\begin{quote}\n    Note: This equation should work, but we noticed the EKF was blowing up to infinity because of weird divergences in the off-diagonal elements of the Kalman Gain. As such, we made a last-minute hack by multiplying this $\\boldsymbol{K}$ component-wise by $\\boldsymbol{H}^T$. This has the effect of forcing all off-diagonals to zero, which is definitely bad but fixed the problems in our time of need. Please do something better than this in the future.\n\\end{quote}\n\nNow that we have $\\boldsymbol{K}$, we can update the state and the covariance, using our innovation and the predictions for $\\boldsymbol{x}$ and $\\boldsymbol{P}$ made in the previous timestep.\n\n\\begin{equation}\n    \\boldsymbol{\\hat{x}}_{k,k} = \\boldsymbol{\\hat{x}}_{k,k-1} + \\boldsymbol{K} \\cdot \\boldsymbol{y}_k\n\\end{equation}\n\n\\begin{equation}\n    \\boldsymbol{P}_{k,k} = (\\boldsymbol{I}_8 - \\boldsymbol{K} \\cdot \\boldsymbol{H}) \\cdot \\boldsymbol{P}_{k,k-1}\n    \\label{eq:cov_update}\n\\end{equation}\nwhere $\\boldsymbol{I}_8$ is the 8x8 identity matrix.\n    \nNote: Equation (\\ref{eq:cov_update}) is a simplified version of the equation which mostly works, but is unstable, and will multiply significant errors which could ruin the whole filter. It works mostly fine, but for reference the more correct equation is included below.\n\\begin{equation}\n    \\boldsymbol{P}_{k,k} = (\\boldsymbol{I}_8 - \\boldsymbol{K} \\cdot \\boldsymbol{H}) \\cdot \\boldsymbol{P}_{k,k-1}\n    \\cdot (\\boldsymbol{I}_8 - \\boldsymbol{K} \\cdot \\boldsymbol{H})^T + \n    \\boldsymbol{K} \\cdot \\boldsymbol{R} \\cdot \\boldsymbol{K}^T\n\\end{equation}\n\n", "meta": {"hexsha": "f573e297245c2355de850b9d80c54c5f48998b17", "size": 2207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/IGVC EKF Derivation/sections/kalmangain.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/kalmangain.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/kalmangain.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": 59.6486486486, "max_line_length": 453, "alphanum_fraction": 0.7313094699, "num_tokens": 652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.609344871552371}}
{"text": "\\documentclass[12pt]{scrartcl}\n\n\\input{preamble}\n\n\\makeatletter\n\\title{Hack 2.0}\\let\\Title\\@title\n\\subtitle{Computer Science I -- Honors\\\\\n{\\small\n\\vskip1cm\nDepartment of Computer Science \\& Engineering \\\\\nUniversity of Nebraska--Lincoln}\n\\vskip-1cm}\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\n\\section*{Problem Statement}\n\nConsider two locations, an origin and a destination, on the globe \nidentified by their latitude and longitude.  The distance between\nthese two locations can be computed using the Spherical Law of \nCosines.  In particular, the distance $d$ is\n $$d = \\arccos{(\\sin(\\varphi_1) \\sin(\\varphi_2) + \\cos(\\varphi_1) \\cos(\\varphi_2) \\cos(\\Delta) )} \\cdot R$$\nwhere\n\\begin{itemize}\n  \\item $\\varphi_1$ is the latitude of location $A$, $\\varphi_2$ is the latitude of location $B$\n  \\item $\\Delta$ is the difference between location $B$'s longitude and location $A$'s longitude\n  \\item $R$ is the (average) radius of the earth, 6,371 kilometers\n\\end{itemize}\n\nWrite a program that \\emph{prompts} the user to enter the latitude \nand longitude of two locations and then computes the distance between them using\nthe above formula.  Note that latitude inputs will be in degrees and in the\nrange $[-90, 90]$ and longitude will be in degrees in the range $[-180, 180]$.\nNegative values correspond to the western and southern hemispheres.  \n\nNote that the formula above assumes that latitude and longitude are \nmeasured in radians $r$, $-\\pi \\leq r \\leq \\pi$.  You can convert from\ndegrees $deg$ to radians $r$ using the formula\n  $$r = \\frac{deg}{180} \\cdot \\pi$$  \n\nYour output should look something like the following.  \n\n\\begin{minted}{text}\nLocation Distance\n========================\nOrigin:      (41.948300, -87.655600)\nDestination: (40.820600, -96.705600)\nAir distance is 764.990931 kms\n\\end{minted}\n\n\n\\section*{Instructions}\n\n\\begin{itemize}\n  \\item You are encouraged to collaborate any number of students \n  before, during, and after your scheduled hack session.  \n  \\item Design at least 3 test cases \\emph{before} you begin\n  designing or implementing your program.  Test cases are \n  input-output pairs that are known to be correct using means\n  other than your program.\n  \\item Include the name(s) of everyone who worked together on\n  this activity in your source file's header.\n  \\item Place your code in a \\mintinline{java}{main()} method in \n    a source file named \\mintinline{text}{AirDistance.java} and \n    turn it in via webhandin.  Make sure that it runs and executes \n    correctly in the webgrader. Each individual\n    student will need to hand in their own copy and will receive their\n    own individual grade.\n  \\item Remember to RTM (Read The Manual) on Java's \n    \\mintinline{java}{Math} class/library to see which method(s) \n    you may find useful and how to use them.\n\\end{itemize}\n  \n\n\n\\end{document}\n", "meta": {"hexsha": "bcbfbbdc54a8a5ca7468b48ec5c9c6e2a4f25926", "size": 2912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "honors/hacks/hack2.0.tex", "max_stars_repo_name": "bobbys131/ComputerScienceI", "max_stars_repo_head_hexsha": "93e22289e966386f208c477ee319837877bbe62a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2018-05-14T20:29:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T10:05:16.000Z", "max_issues_repo_path": "honors/hacks/hack2.0.tex", "max_issues_repo_name": "hrithik125/ComputerScienceI", "max_issues_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-05-11T01:30:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-02T04:34:10.000Z", "max_forks_repo_path": "honors/hacks/hack2.0.tex", "max_forks_repo_name": "hrithik125/ComputerScienceI", "max_forks_repo_head_hexsha": "40be47f15817a50497f6c6f7cdca9ee1db429b00", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 204, "max_forks_repo_forks_event_min_datetime": "2018-10-17T18:35:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T16:51:50.000Z", "avg_line_length": 33.8604651163, "max_line_length": 107, "alphanum_fraction": 0.7307692308, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.6093185086884734}}
{"text": "\\section{Clustering}\n\\label{sec:ctm-clustering}\n\nThe next idea we attempted was using clustering algorithms to group student solutions together. The goal was to put student solutions with similar edit distances, to some subset of reference solutions, in the same cluster.\n\nUnder this mindset, we treated each student as an independent \\textquote{data point} and their edit distance to each reference solution as an independent \\textquote{feature}. Our data thus became an $N \\times M$ matrix with $N$ rows for each student and $M$ columns for each reference solution.\n\nWe made the assumption that full-mark solutions should have very similar features and thus should be very close to each other in the same cluster. Recall that the majority of the historical student solutions in this course had received full marks. Therefore, the majority of each cluster's points should also be very close to each other as well. As a result, we believed each cluster should theoretically be \\textquote{centered} closer to the full-mark solutions than the incorrect solutions; therefore we hypothesized the closer a student solution was to the cluster's center, the higher the probability that the student solution should receive full marks.\n\n%------------------------------------------------------------------------------\n\\subsubsection{Determining Number of Clusters}\n%------------------------------------------------------------------------------\n\nThe K-Means and Gaussian Mixture clustering algorithms require us to specify how many clusters we want to find in our data points (student solutions). There are no straightforward approaches to choosing this value because it depends on the input data and use-case.\n\nIf we choose too few clusters, then we risk putting too many student solutions in the same cluster despite them not being too closely related. If we choose too many clusters, then we risk not getting sufficient data to compute scores. For example, in the extreme case of $N$ clusters, every student would become its own cluster and, according to our original hypothesis of final score being based on closeness to a cluster's center, should receive full marks.\n\nHowever, there are techniques such as the \\textquote{Elbow Method} \\cite{thorndike1953belongs} shown in Figure~\\ref{fig:ctm-num-clusters} that can be used for guidance. For our data, the Elbow Method recommended for us to use 4 clusters.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{elbow}\n\\caption[Using Elbow Method to find Optimal Number of Clusters]{The Elbow Method runs the K-Means clustering algorithm with a range of clusters and computes the sum of squared errors. This sum measures how close the predicted clusters match the data points; the greater the error, the less clusters fit the data. This graph converges to 0 at $N$ clusters where each point is its own cluster and thus has zero error. To find an appropriate number of clusters, we need to visually find an \\textquote{elbow} point on the graph, i.e. where adding an additional cluster will not significantly reduce the error. In this graph, the elbow point is at 4 clusters.}\n\\label{fig:ctm-num-clusters}\n\\end{figure}\n\n%------------------------------------------------------------------------------\n\\subsubsection{Cleaning Up Data}\n%------------------------------------------------------------------------------\n\nAlthough not essential, we chose to perform Principal Component Analysis (PCA) \\cite{wold1987principal} on our data prior to clustering. PCA transforms our set of $M$ features into a smaller set of linearly uncorrelated features or \\textquote{components}. The components are sorted in descending order of variance. In other words, the first few components theoretically capture the majority of the \\textquote{information} in the source data.\n\nThe most obvious advantage of PCA is reducing the runtime of our clustering algorithms because it eliminates features (columns in our data matrix) that represent very little information about our data points. This technique is also useful in visualization as it allows high-dimensional data to be presented in a 2D graph while preserving the majority of the information and relationships between data points.\n\nTo use PCA, we need to specify how many components or features to keep. Similar to the Elbow Method to determine the number of clusters, we can look at the graph of cumulative explained variance shown in Figure~\\ref{fig:ctm-num-components} to estimate an appropriate number of components. For our data, the graph recommended for us to use 6 components.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{explained_variance_ratio}\n\\caption[Explained Variance Ratio]{The explained variance conceptually represents the amount of information in the original data that each component captures. The first component captures almost 80\\% of the original information; the second component captures another 5\\%; and so on. This graph show the cumulative explained variance that each additional component captures. A rule-of-thumb for PCA is to choose the number of components at an \\textquote{elbow point} where adding an additional component will not capture significantly more information. In this graph, the elbow point is at 6 components.}\n\\label{fig:ctm-num-components}\n\\end{figure}\n\n\\input{body/conversion-to-mark/k-means}\n\\input{body/conversion-to-mark/gaussian-mixture}\n\\input{body/conversion-to-mark/hdbscan}\n", "meta": {"hexsha": "8386b3fd9eb2f89919350714421a9a146d0e1482", "size": 5413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/thesis/body/conversion-to-mark/clustering.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/clustering.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/clustering.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": 120.2888888889, "max_line_length": 657, "alphanum_fraction": 0.7607611306, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6093185042666587}}
{"text": "\\section{More inductive types}\n\nAnalogous to the type of natural numbers, many types can be specified as inductive types. In this lecture we introduce some further examples of inductive types: the unit type, the empty type, the booleans, coproducts, dependent pair types, and cartesian products. We also introduce the type of integers.\n\n\\subsection{The idea of general inductive types}\n\nJust like the type of natural numbers, other inductive types are also specified by their \\emph{constructors}, an \\emph{induction principle}, and their \\emph{computation rules}: \n\\begin{enumerate}\n\\item The constructors tell what structure the inductive type comes equipped with. There may any finite number of constructors, even no constructors at all, in the specification of an inductive type. \n\\item The induction principle specifies the data that should be provided in order to construct a section of an arbitrary type family over the inductive type. \n\\item The computation rules assert that the inductively defined section agrees on the constructors with the data that was used to define the section. Thus, there is a computation rule for every constructor.\n\\end{enumerate}\nThe induction principle and computation rules can be generated automatically once the constructors are specified, but it goes beyond the scope of our course to describe general inductive types.\n%For a more general treatment of inductive types, we refer to Chapter 5 of \\cite{hottbook}.\n\n\n\\subsection{The unit type}\nA straightforward example of an inductive type is the \\emph{unit type}, which has just one constructor. \nIts induction principle is analogous to just the base case of induction on the natural numbers.\n\n\\begin{defn}\nWe define the \\define{unit type}\\index{1@{$\\unit$}|see {unit type}}\\index{unit type|textbf} to be a closed type $\\unit$ equipped with a closed term\\index{unit type!star@{$\\ttt$}}\n\\begin{equation*}\n\\ttt:\\unit,\n\\end{equation*}\nsatisfying the induction principle\\index{induction principle!of unit type} that for any type family of types $P(x)$ indexed by $x:\\unit$, there is a term\n\\begin{equation*}\n\\indunit : P(\\ttt)\\to\\prd{x:\\unit}P(x)\n\\end{equation*}\nfor which the computation rule\\index{computation rules!of unit type}\n\\begin{equation*}\n\\indunit(p,\\ttt) \\jdeq p\n\\end{equation*}\nholds. Sometimes we write $\\lam{\\ttt}p$ for $\\indunit(p)$.\n\\end{defn}\n\nThe induction principle can also be used to define ordinary functions out of the unit type. Indeed, given a type $A$ we can first weaken it to obtain the constant family over $\\unit$, with value $A$. Then the induction principle of the unit type provides a function\n\\begin{equation*}\n  \\indunit : A \\to (\\unit\\to A).\n\\end{equation*}\nIn other words, by the induction principle for the unit type we obtain for every $x:A$ a function $\\mathsf{pt}_x\\defeq\\indunit(x):\\unit\\to A$.\n\n\\subsection{The empty type}\nThe empty type is a degenerate example of an inductive type. It does \\emph{not} come equipped with any constructors, and therefore there are also no computation rules. The induction principle merely asserts that any type family has a section. In other words: if we assume the empty type has a term, then we can prove anything.\n\n\\begin{defn}\nWe define the \\define{empty type}\\index{0@{$\\emptyt$}|see {empty type}}\\index{empty type|textbf} to be a type $\\emptyt$ satisfying the induction principle\\index{induction principle!of empty type} that for any family of types $P(x)$ indexed by $x:\\empty$, there is a term\n\\begin{equation*}\n\\indempty : \\prd{x:\\emptyt}P(x).\n\\end{equation*}\n\\end{defn}\n\nThe induction principle for the empty type can also be used to construct a function\n\\begin{equation*}\n  \\emptyt\\to A\n\\end{equation*}\nfor any type $A$. Indeed, to obtain this function one first weakens $A$ to obtain the constant family over $\\emptyt$ with value $A$, and then the induction principle gives the desired function.\n\nThus we see that from the empty type anything follows. Therefore, we we see that anything follows from $A$, if we have a function from $A$ to the empty type. This motivates the following definition.\n\n\\begin{defn}\n  For any type $A$ we define \\define{negation} of $A$ by\n  \\begin{equation*}\n    \\neg A\\defeq A\\to\\emptyt.\n  \\end{equation*}\n\\end{defn}\n\nSince $\\neg A$ is the type of functions from $A$ to $\\emptyt$, a proof of $\\neg A$ is given by assuming that $A$ holds, and then deriving a contradiction. This proof technique is called \\define{proof of negation}. Proofs of negation are not to be confused with \\emph{proofs by contradiction}. In type theory there is no way of obtaining a term of type $A$ from a term of type $(A\\to \\emptyt)\\to\\emptyt$.\n\n\\subsection{The booleans}\n\\begin{defn}\nWe define the \\define{booleans}\\index{booleans|textbf}\\index{2@{$\\bool$}|see {booleans}} to be a type $\\bool$ that comes equipped with\n\\begin{align*}\n\\bfalse & : \\bool \\\\\n\\btrue & : \\bool\n\\end{align*}\nsatisfying the induction principle\\index{induction principle!of booleans} that for any family of types $P(x)$ indexed by $x:\\bool$, there is a term\n\\begin{equation*}\n\\indbool : P(\\bfalse)\\to \\Big(P(\\btrue)\\to \\prd{x:\\bool}P(x)\\Big)\n\\end{equation*}\nfor which the computation rules\\index{computation rules!of booleans}\n\\begin{align*}\n\\indbool(p_0,p_1,\\bfalse) & \\jdeq p_0 \\\\\n\\indbool(p_0,p_1,\\btrue) & \\jdeq p_1\n\\end{align*}\nhold.\n\\end{defn}\n\nJust as in the cases for the unit type and the empty type, the induction principle for the booleans can also be used to construct an ordinary function $\\bool\\to A$, provided that we can construct two terms of type $A$. Indeed, by the induction principle for the booleans there is a function\n\\begin{equation*}\n  \\indbool : A \\to (A\\to A^\\bool)\n\\end{equation*}\nfor any type $A$.\n\n\\begin{eg}\n  Using the induction principle of $\\bool$ we can define all the operations of Boolean algebra. For example, the \\define{boolean negation} operation $\\neg : \\bool \\to \\bool$ is defined by\n  \\begin{align*}\n    \\neg\\btrue & \\defeq \\bfalse & \\neg\\bfalse & \\defeq \\btrue.\n  \\end{align*}\n  The \\define{boolean conjunction} operation $\\blank\\land\\blank : \\bool \\to (\\bool\\to \\bool)$ is defined by\n  \\begin{align*}\n    \\btrue\\land\\btrue & \\defeq \\btrue & \\bfalse\\land\\btrue & \\defeq \\bfalse \\\\\n    \\btrue\\land\\bfalse & \\defeq \\bfalse & \\bfalse\\land\\bfalse & \\defeq \\bfalse.\n  \\end{align*}\n  The \\define{boolean disjunction} operation $\\blank\\lor\\blank : \\bool \\to (\\bool\\to \\bool)$ is defined by\n  \\begin{align*}\n    \\btrue\\lor\\btrue & \\defeq \\btrue & \\bfalse\\lor\\btrue & \\defeq \\btrue \\\\\n    \\btrue\\lor\\bfalse & \\defeq \\btrue & \\bfalse\\lor\\bfalse & \\defeq \\bfalse.\n  \\end{align*}  \n  We leave the definitions of some of the other boolean operations as \\cref{ex:boolean-operation}. Note that the method of defing the boolean operations by the induction principle of $\\bool$ is not that different from defining them by truth tables.\n\n  Boolean logic is important, but it won't be very prominent in this course. The reason is simple: in type theory it is more natural to use the `logic' of types that is provided by the inference rules.\n\\end{eg}\n\n\\subsection{Coproducts and the type of integers}\n\\begin{defn}\nLet $A$ and $B$ be types. We define the \\define{coproduct}\\index{coproduct}\\index{disjoint sum|see {coproduct}} $A+B$\\index{plus ($+$)|see {coproduct}} to be a type that comes equipped with\n\\begin{align*}\n\\inl & : A \\to A+B \\\\\n\\inr & : B \\to A+B\n\\end{align*}\nsatisfying the induction principle\\index{induction principle!of coproduct} that for any family of types $P(x)$ indexed by $x:A+B$, there is a term\n\\begin{equation*}\n\\ind{+} : \\Big(\\prd{x:A}P(\\inl(x))\\Big)\\to\\Big(\\prd{y:B}P(\\inr(y))\\Big)\\to\\prd{z:A+B}P(z)\n\\end{equation*}\nfor which the computation rules\\index{computation rules!of coproduct}\n\\begin{align*}\n\\ind{+}(f,g,\\inl(x)) & \\jdeq f(x) \\\\\n\\inr{+}(f,g,\\inr(y)) & \\jdeq g(y)\n\\end{align*}\nhold. Sometimes we write $[f,g]$ for $\\ind{+}(f,g)$.\n\\end{defn}\n\nThe coproduct of two types is sometimes also called the \\define{disjoint sum}. By the induction principle of coproducts it follows that we have a function\n\\begin{equation*}\n  (A\\to X) \\to \\big((B\\to X) \\to (A+B\\to X)\\big)\n\\end{equation*}\nfor any type $X$. Note that this special case of the induction principle of coproducts is very much like the elimination rule of disjunction in first order logic: if $P$, $P'$, and $Q$ are propositions, then we have\n\\begin{equation*}\n  (P\\to Q)\\to \\big((P'\\to Q)\\to (P\\lor P'\\to Q)\\big).\n\\end{equation*}\nIndeed, we can think of \\emph{propositions as types} and of terms as their constructive proofs. Under this interpretation of type theory the coproduct is indeed the disjunction.\n\nAn important example of a type that can be defined using coproducts is the type $\\Z$ of integers.\n\n\\begin{defn}\n  We define the \\define{integers}\\index{integers|see Z@{$\\Z$}} to be the type $\\Z\\defeq\\nat+(\\unit+\\nat)$. The type of integers comes equipped with inclusion functions of the positive and negative integers\n  \\begin{align*}\n    \\mathsf{in\\usc{}pos} & \\defeq \\inr\\circ\\inr \\\\\n    \\mathsf{in\\usc{}neg} & \\defeq \\inl,\n  \\end{align*}\n  which are both of type $\\N\\to\\Z$, and the constants\n  \\begin{align*}\n    -1_\\Z & \\defeq \\mathsf{in\\usc{}neg}(0)\\\\\n    0_\\Z & \\defeq \\inr(\\inl(\\ttt))\\\\\n    1_\\Z & \\defeq \\mathsf{in\\usc{}pos}(0).\n  \\end{align*}\n\\end{defn}\n\nIn the following lemma we derive an induction principle\\index{induction principle!of Z@{of $\\Z$}} for $\\Z$, which can be used in many familiar constructions on $\\Z$, such as in the definitions of addition and multiplication.\n\n\\begin{lem}\\label{lem:Z_ind}\n  Consider a type family $P$ over $\\Z$. If we are given\n  \\begin{align*}\n    p_{-1} & :P(-1_\\Z) \\\\\n    p_{-S} & : \\prd{n:\\N}P(\\mathsf{in\\usc{}neg}(n))\\to P(\\mathsf{in\\usc{}neg}(\\succN(n)))\\\\\n    p_{0} & : P(0_\\Z) \\\\\n    P_{1} & : P(1_\\Z) \\\\\n    P_{S} & : \\prd{n:\\N}P(\\mathsf{in\\usc{}pos}(n))\\to P(\\mathsf{in\\usc{}pos}(\\succN(n))),\n  \\end{align*}\n  then we can construct a dependent function $f:\\prd{k:\\Z}P(k)$ for which the following judgmental equalities hold:\n  \\begin{align*}\n    f(-1_\\Z) & \\jdeq p_{-1} \\\\\n    f(\\mathsf{in\\usc{}neg}(\\mathsf{succ}_\\N(n))) & \\jdeq p_{-S}(n,f(\\mathsf{in\\usc{}neg}(n))) \\\\\n    f(0_\\Z) & \\jdeq p_{0} \\\\\n    f(1_\\Z) & \\jdeq p_{1} \\\\\n    f(\\mathsf{in\\usc{}pos}(\\mathsf{succ}_\\N(n))) & \\jdeq p_S(n,f(\\mathsf{in\\usc{}pos}(n))).\n  \\end{align*}\n\\end{lem}\n\n\\begin{proof}\n  Since $\\Z$ is the coproduct of $\\N$ and $\\unit+\\N$, it suffices to define\n  \\begin{align*}\n    p_{inl} & : \\prd{n:\\N}P(\\inl(n)) \\\\\n    p_{inr} & : \\prd{t:\\unit+\\N}P(\\inr(t)).\n  \\end{align*}\n  Note that $\\mathsf{in\\usc{}neg}\\jdeq\\inl$ and $-1_\\Z\\jdeq \\mathsf{in\\usc{}neg}(\\zeroN)$. In order to define $p_{inl}$ we use induction on the natural numbers, so it suffices to define\n  \\begin{align*}\n    p_{-1} & : P(-1) \\\\\n    p_{-S} & : \\prd{n:\\N} P(\\mathsf{in\\usc{}neg}(n))\\to P(\\mathsf{in\\usc{}neg}(\\succN(n))).\n  \\end{align*}\n  Similarly, we proceed by coproduct induction, followed by induction on $\\unit$ in the left case and induction on $\\N$ on the right case, in order to define $p_{inr}$. \n\\end{proof}\n\nAs an application we define the successor function on the integers.\n\n\\begin{defn}\nWe define the \\define{successor function}\\index{successor function!on Z@{on $\\Z$}|textbf} on the integers $\\mathsf{succ}_\\Z:\\Z\\to\\Z$ using the induction principle of \\cref{lem:Z_ind}, taking\n\\begin{align*}\n\\mathsf{succ}_\\Z(-1_\\Z) & \\defeq 0_\\N \\\\\n\\mathsf{succ}_\\Z(\\mathsf{in\\usc{}neg}(\\mathsf{succ}_\\N(n))) & \\defeq \\mathsf{in\\usc{}neg}(n) \\\\\n\\mathsf{succ}_\\Z(0_\\Z) & \\defeq 1_\\N \\\\\n\\mathsf{succ}_\\Z(1_\\Z) & \\defeq \\mathsf{in\\usc{}pos}(1_\\N) \\\\\n\\mathsf{succ}_\\Z(\\mathsf{in\\usc{}pos}(\\mathsf{succ}_\\N(n))) & \\defeq \\mathsf{in\\usc{}pos}(\\mathsf{succ}_\\N(\\mathsf{succ}_\\N(n))).\n\\end{align*}\n\\end{defn}\n\n\\subsection{Dependent pair types}\nThe \\emph{dependent pair type}\\index{dependent pair type|see {$\\Sigma$-type}} (or $\\Sigma$-type) can be thought of as a `type indexed' disjoint sum.\nHowever, this intuition for the dependent pair type can be counterproductive once we start to do homotopy theory in type theory.\nIt is better to think of the $\\Sigma$-type as the total space of a family of types depending continuously on a base type, just like one can have a family of spaces depending continuously on a base space (i.e., a fibration).\n\n\\begin{defn}\nLet $A$ be a type in context $\\Gamma$, and let $\\Gamma,x:A\\vdash B(x)~\\mathrm{type}$ be a type family over $A$.\nThe \\define{dependent pair type}\\index{Sigma type@{$\\Sigma$-type}|textbf} is defined to be the inductive type $\\sm{x:A}B(x)$ in context $\\Gamma$ equipped with a \\define{pairing function}\\index{pairing function}\n\\begin{equation*}\n(\\blank,\\blank):\\prd{x:A} \\Big(B(x)\\to \\sm{y:A}B(y)\\Big).\n\\end{equation*}\nThe induction principle\\index{induction principle|of Sigma types@{of $\\Sigma$-types}} for $\\sm{x:A}B(x)$ asserts that for any family of types $P(p)$ indexed by $p:\\sm{x:A}B(x)$, there is a function\n\\begin{equation*}\n\\ind{\\Sigma}:\\Big(\\prd{x:A}{y:B(x)}P(x,y)\\Big)\\to\\Big(\\prd{p:\\sm{x:A}B(x)}P(p)\\Big).\n\\end{equation*}\nsatisfying the computation rule\\index{computation rules!of Sigma types@{of $\\Sigma$-types}}\n\\begin{equation*}\n\\ind{\\Sigma}(f,(x,y))\\jdeq f(x,y).\n\\end{equation*}\nSometimes we write $\\lam{(x,y)}f(x,y)$ for $\\ind{\\Sigma}(\\lam{x}{y}f(x,y))$. \n\\end{defn}\n\n\\begin{defn}\nGiven a type $A$ and a type family $B$ over $A$, the \\define{first projection map}\\index{first projection map|textbf}\\index{projection maps!first projection|textbf}\n\\begin{equation*}\n\\proj 1:\\Big(\\sm{x:A}B(x)\\Big)\\to A\n\\end{equation*}\nis defined by induction as\n\\begin{equation*}\n\\proj 1\\defeq \\lam{(x,y)}x.\n\\end{equation*}\nThe \\define{second projection map}\\index{second projection map|textbf}\\index{projection map!second projection|textbf} is a dependent function\n\\begin{equation*}\n\\proj 2 : \\prd{p:\\sm{x:A}B(x)} B(\\proj 1(p))\n\\end{equation*}\ndefined by induction as\n\\begin{equation*}\n\\proj 2\\defeq \\lam{(x,y)}y.\n\\end{equation*}\nBy the computation rule we have\n\\begin{align*}\n\\proj 1 (x,y) & \\jdeq x \\\\\n\\proj 2 (x,y) & \\jdeq y.\n\\end{align*}\n\\end{defn}\n\n\\subsection{Cartesian products}\nA special case of the $\\Sigma$-type occurs when the $B$ is a type in context $\\Gamma$ weakened by $A$ (i.e., $B$ is not actually depending on $A$). In this case, a term of $\\sm{x:A}B$ is given as a pair consisting of a term of $A$ and a term of $B$. Thus, $\\sm{x:A}B$ is the \\emph{(cartesian) product} $A\\times B$. Since the cartesian product is so common (just like $A\\to B$ is a common special case of the dependent product), we provide its specification along with the induction principle for cartesian products.\n\n\\begin{defn}\nLet $A$ and $B$ be types in context $\\Gamma$. The \\define{(cartesian) product}\\index{cartesian product|textbf}\\index{product!of types|textbf} of $A$ and $B$ is defined as the inductive type $A\\times B$\\index{times ($\\times$)|see {cartesian product}} with constructor\n\\begin{equation*}\n(\\blank,\\blank):A\\to (B\\to A\\times B).\n\\end{equation*}\nThe induction principle\\index{induction principle!of cartesian products} for $A\\times B$ asserts that for any type family $P$ over $A\\times B$, one has\n\\begin{equation*}\n\\ind{\\times} : \\Big(\\prd{x:A}{y:B}P(a,b)\\Big)\\to\\Big(\\prd{p:A\\times B} P(p)\\Big)\n\\end{equation*}\nsatisfying the computation rule\\index{computation rules!of cartesian product} that\n\\begin{align*}\n\\ind{\\times}(f,(x,y)) & \\jdeq f(x,y).\n\\end{align*}\n\\end{defn}\n\nThe projection maps are defined similarly to the projection maps of $\\Sigma$-types. When one thinks of types as propositions\\index{propositions as types!conjunction}, then $A\\times B$ is interpreted as the conjunction of $A$ and $B$.\n\n\\begin{comment}\n\\subsection{Overview of the inductive types}\nThe following table gives an overview of the 'primitive' inductive types that we have introduced so far. Many types of interest can be defined in terms of these inductive types, along with the identity type which we will introduce in \\cref{chap:identity}.\n\\begin{center}\n\\begin{tabular}{llll}\n\\toprule\nname & type & constructors \\\\\n\\midrule\n\\define{natural numbers} & $\\N$ & $\\zeroN:\\N$ \\\\\n& & $\\succN:\\N\\to \\N$ & \\\\\n\\define{empty type} & $\\emptyt$ & {\\color{black!20}(no constructors)}\\\\\n\\define{unit type} & $\\unit$ & $\\ttt:\\unit$ \\\\\n\\define{booleans} & $\\bool$ & $\\bfalse:\\bool$ \\\\\n& & $\\btrue : \\bool$ \\\\\n\\define{coproduct} & $A+B$ & $\\inl : A \\to A+B$ \\\\\n& & $\\inr : B\\to A+B$ & \\\\\n\\define{product} & $A\\times B$ & $(\\blank,\\blank):A\\to (B\\to A\\times B)$ \\\\\n\\define{$\\Sigma$-type} & $\\sm{x:A}B(x)$ & $(\\blank,\\blank):\\prd{y:A} \\big(B(y)\\to \\sm{x:A}B(x)\\big)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\\end{comment}\n\n\\begin{exercises}\n\\item \\label{ex:boolean-operation}Define the following operations of Boolean algebra:\n  \\begin{center}\n    \\begin{tabular}{ll}\n      exclusive disjunction & $p \\oplus q$ \\\\\n      implication & $p \\Rightarrow q$ \\\\\n      if and only if & $p \\Leftrightarrow q$ \\\\\n      Peirce's arrow (neither \\dots{} nor) & $p \\downarrow q$ \\\\\n      Sheffer stroke (not both) & $p\\mid q$.\n    \\end{tabular}\n  \\end{center}\n  Here $p$ and $q$ range over $\\bool$. \n\\item \\label{ex:int_pred}\\index{predecessor function|textbf}Define the predecessor function $\\mathsf{pred}_\\Z:\\Z\\to \\Z$.\n\\item \\label{ex:int_group_ops}\\index{group operations!on Z@{on $\\Z$}}Define group operations\n  \\begin{align*}\n    k,l & \\mapsto k+l \\\\\n    k & \\mapsto -k\n  \\end{align*}\n  on $\\Z$.\n\\item Define multiplication on $\\Z$.\n\\item Construct a function $F:\\Z\\to\\Z$ that extends the Fibonacci sequence to the left\n  \\begin{equation*}\n    \\ldots,5,-3,2,-1,1,0,1,1,2,3,5,8,13,\\ldots\n  \\end{equation*}\n  in the expected way.\n\\item \\label{ex:one_plus_one} Show that $\\unit+\\unit$ satisfies the same induction principle\\index{induction principle!of booleans} as $\\bool$, i.e., define\n  \\begin{align*}\n    t_0 & : \\unit + \\unit \\\\\n    t_1 & : \\unit + \\unit,\n  \\end{align*}\n  and show that for any type family $P$ over $\\unit+\\unit$ there is a function\n  \\begin{align*}\n    \\ind{\\unit+\\unit}:P(t_0)\\to \\Big(P(t_1)\\to \\prd{t:\\unit+\\unit}P(t)\\Big)\n  \\end{align*}\n  satisfying\n  \\begin{align*}\n    \\ind{\\unit+\\unit}(p_0,p_1,t_0) & \\jdeq p_0 \\\\\n    \\ind{\\unit+\\unit}(p_0,p_1,t_1) & \\jdeq p_1.\n  \\end{align*}\n  In other words, \\emph{type theory cannot distinguish between the types $\\bool$ and $\\unit+\\unit$.}\n\\item For any type $A$ we can define the type $\\mathsf{list}_A$ of \\define{lists} elements of $A$ as the inductive type with constructors\n  \\begin{align*}\n    \\mathsf{empty\\usc{}list} & : \\mathsf{list}_A \\\\\n    \\mathsf{append\\usc{}list} & : A \\to (\\mathsf{list}_A \\to \\mathsf{list}_A).\n  \\end{align*}\n  \\begin{subexenum}\n  \\item Write down the induction principle and the computation rules for $\\mathsf{list}_A$.\n  \\item Define a function $\\mathsf{length}:\\mathsf{list}_A\\to\\N$.\n  \\item Define a function $\\mathsf{reverse} : \\mathsf{list}_A \\to \\mathsf{list}_A$ that reverses the order of the elements in any list.\n  \\item Define a function\n    \\begin{equation*}\n      \\mathsf{concat\\usc{}list} : \\mathsf{list}_A \\to (\\mathsf{list}_A \\to \\mathsf{list}_A)\n    \\end{equation*}\n    that concatenates any two lists of elements in $A$.\n  \\item Define a function\n    \\begin{equation*}\n      \\mathsf{sum} : \\mathsf{list}_\\N \\to \\N\n    \\end{equation*}\n    that adds all the elements in a list of natural numbers.\n  \\end{subexenum}\n\\end{exercises}\n", "meta": {"hexsha": "2daf10c938ed484978a73de106a7d889b9742fbe", "size": 19247, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/inductive.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/inductive.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/inductive.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.7625698324, "max_line_length": 515, "alphanum_fraction": 0.6993817218, "num_tokens": 6220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6093184883978277}}
{"text": "\\documentclass{article}\n\n\\begin{document}\n\n\\section{Senstivity Analysis of PETPT (Priestley-Taylor) model}\n\nSensitivity analysis of any theoretical model involves the computation of Sobol indices which measures the variance in the output as a\nresult of the fluctuations in the input parameters. \n%has been performed for the\nThe Priestley-Taylor (PETPT) model is an example of an\nevapotranspiration (EO) model where the daily EO rate of a crop depends on the following independent\nvariables - the maximum (TMAX) and minimum (TMIN) observable temperatures within a\ngiven day, daily solar radiation (SRAD), leaf area index (XHLAI), and soil\nalbedo coefficient (MSALB). For computational purposes, \nthe SALib library in python allows one to perform a\nsensitivity analysis for a given model. In our work, we have implemented three\ndifferent sensitivity methods, namely, Sobol, Fourier Amplitude Sensitivity Test or\nFAST, and finally, Random Balance Design-Fourier Amplitude Sensitivity Test or\nRBD-FAST and compared the first order indices (S$_i$; $i$ is the variable) across the different models.\nOur results indicate that for reasonable approximations of the input parameter\nbounds, S$_i$ values are maximum for TMAX and minimum (zero) for\nXHLAI in all three methods. SRAD followed by MSALB have the most significant\nS$_i$'s after TMAX while the sobol index for TMIN in the PETPT model is\nnegligible. The Sobol method can compute the second order index (S$_{ij}$; for\nthe variables $i$ and $j$) as\nwell. Interestingly, we find that while S$_{XHLAI}$ is vanishingly small,\nthe second order index of XHLAI and TMAX is significantly large. Again,\nS$_{ij}$ for $(i, j)=$ (TMAX, SRAD) is non-negligible. In addition, the runtime for each of\nthe sensitivity analysis methods is computed and compared for different sample\nsizes. It becomes evident that for large sample sizes ($\\sim$ 10$^6$), Sobol is\ntwo orders of magnitude slower than both FAST and RBD-FAST methods. In summary,\nTMAX is the most significant parameter and any significant change in its value will\nhave the maximum effect on the EO rate. Our future goal is to extend our\ndiscussion of sensitivity analysis to the PETASCE model in which the EO rate\ndepends on the\nindependent variables discussed above as well as a new set of input parameters.\n\n\\section{Parameter Estimation}\n\nA necessary question that arises from the previous section is how reliable are\nthe bounds of our input variables that have been used in estimating the Sobol\nindices. While such an\ninformation can be extracted after having parsed through hundreds of documents on\nvarious evapotranspiration models and other experimental data, we would like to\nadopt a more fundamental approach to determine the domain of a high\ndimensional space spanned by our input\nparameters. Given our previous choice of the bounds imposed on the input parameters, it is easy\nto see that there exist a subset of parameter sets which yield similar\nevapotranspiration rates in both PETPT and PETASCE models. However, such an\n{\\it ad-hoc} choice generates only a slice of a larger domain of possible values in\nthe configuration space of our parameters. A more rigorous approach then\nrequires us to minimize the square of the difference between the EO rates of the PETPT and\nPETASCE models which is defined as the Loss. \nTypically, the Loss is a non-convex, non-linear, non-separable function with\nmultiple minima and hence any optimizaiton procedure is non-trivial. \nWe invoke the standard gradient descent algorithm that is ideal for\nconvex optimzation problems and apply it over here. Moreover, the mathematical\nexpression for the EO rates vary based on the domains of the input variables.\nHence, domain constraints need to be imposed while minimizing the Loss.\nThis work is currently  ongoing and we hope to develop a more efficient\nalgorithm that can precisely identify a list of parameter sets that optimize\nthe output in both models. \n\n\n\\end{document}\n", "meta": {"hexsha": "908beab44dbdd669d0fbb4493a63a7f37a796ad3", "size": 3958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/documentation/deliverable_reports/m06_milestone_report/sources/MA-report_model_analysis.tex", "max_stars_repo_name": "rsulli55/automates", "max_stars_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-12-19T16:32:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T07:58:15.000Z", "max_issues_repo_path": "docs/documentation/deliverable_reports/m06_milestone_report/sources/MA-report_model_analysis.tex", "max_issues_repo_name": "rsulli55/automates", "max_issues_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 183, "max_issues_repo_issues_event_min_datetime": "2018-12-20T17:03:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T22:21:42.000Z", "max_forks_repo_path": "docs/documentation/deliverable_reports/m06_milestone_report/sources/MA-report_model_analysis.tex", "max_forks_repo_name": "rsulli55/automates", "max_forks_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-04T22:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T17:34:16.000Z", "avg_line_length": 59.9696969697, "max_line_length": 134, "alphanum_fraction": 0.8041940374, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6092090881339658}}
{"text": "% appendices.tex\n\n\\section{Appendices}\n\n% Not yet ready for prime time; may not include it at any rate because\n% of the \"negative-zero\" problem.\n\n\\subsection*{Higher Order Exponents}\n\nYou can multiply a number times itself as many times as you want. Understanding a little more about exponents (the number of times you multiply a number times itself) will make understanding the language we use to discuss computers quite a bit easier. Just as we mention kilobytes and megabytes as units of storage, there are also less common units of storage that invent new multiplier terms for bits and bytes, because of the ``powers of 2.'' So let's learn about base-2 exponents-- the ``powers of two\".\n\n\\bigskip\n\\newcommand{\\expline}[2]{\n$2^{#1}$ & = & #2 \n}\n\n\\begin{footnotesize}\n\\begin{tabular}{l c l p{3.5in} }\n\n\\multicolumn{3}{c}{\\textbf{Powers of Two}} & \\textbf{Notes} \\\\ \n\\hline\\\\[\\negsep]\n\n\\expline{0}{1}& This one is strange, sort of. But it works! Any number ``to the zeroth power\" is equal to 1. See below for more. \\\\\n\\expline{1}{2} \\\\\n\\expline{2}{4} \\\\\n\\expline{3}{8} \\\\\n\\expline{4}{16} & Since $2^2 = 4$, $2^2 \\times 2^2 = 16 $   \\\\\n\\expline{5}{32} &  This is why you can count to 31 on one hand. \\\\\n\\expline{6}{64} \\\\\n\\expline{7}{128} \\\\\n\\expline{8}{256} & 8-bit computers were the first machines really adopted by consumers. Also, 8 bits makes up one \\emph{byte} of computer memory, so each byte can take on up to 256 values. \\\\ \n\\expline{9}{512} \\\\\n\\expline{10}{1,024} & 1,000 usually gets the prefix \\emph{kilo-}, like a kilogram is 1000 grams. A \\emph{kilobyte} is 1024 bytes.\\\\\n\\expline{16}{65,536} \\\\\n\\expline{20}{1,048,576} & $2^{10}$ bytes is a kilobyte; ($2^{10} \\times 2^{10}$) bytes is a \\emph{megabyte}.\\\\\n\\expline{24}{16,777,216} & Most computer displays can show up to 16 million colors, using red, green, and blue, all in combination. Each piece of the color can have 256 ($2^8$) levels, from zero (black) to 255 (100\\% red, or green, or blue)\\\\\n\\expline{30}{1,073,741,824} & $2^{30}$ bytes is a \\emph{gibibyte}, or a bit more than a \\emph{gigabyte}, which is 1000 megabytes. \\\\\n\\expline{32}{4,294,967,296} \\\\ \n\\expline{40}{1,099,511,627,776} & $2^{40}$ bytes is a \\emph{tebibyte}, or a few percent more than 1000 gigabytes -- a \\emph{terabyte.} \\\\\n\\expline{50}{1,125,899,906,842,624} & $2^{50}$ bytes is \\emph{pebibyte}. A petabyte is so large that one pebibyte is enough to store the DNA of the entire population of the USA\\ldots{}and then clone them, \\emph{twice.} \\\\[\\sep]\n\\hline\n\\end{tabular}\n\n\\end{footnotesize}\n% $10^2 & = & 100 & \\\\\n%$10^3 & = & 1000 & \\\\\n%$10^4 & = & 10000 & \\\\\n\n\\vfill\n\n\\stbox{6.0in}{\\emph{Explanation:} The reason that any number to the zeroth power is equal to one comes from the way we subtract exponents when dividing. You know that 8 divided by 4 equals 2; written another way, $2^3 \\div 2^2 = 2^1$. Notice that the exponents change by subtraction, but the equation is the same! You can \\emph{divide} base-exponent numbers by \\emph{subtracting} the exponents (\\emph{extra-special historical trivia: this is how slide rules work}; see Figure \\ref{fig:sliderule} for a picture). And since any number divided by itself equals one, as in $2^3 \\div 2^3 = 1 $, subtracting the exponents gives $2^0$.}\n\n\n%\\subsection*{Negative Numbers}\n%\n% If we had told the computer that it was using \\emph{signed} numbers, it would count upwards from -32,768, and the first column would be a one, to indicate it was negative, with the rest of them zeros. That is, the format for storing negative numbers subtracts 32,768 from 0 -- the range is still the same (65,536 numbers), but the starting point is different. \n\n\\subsection*{Numbers Below Zero?}\n\nRepresenting \\emph{positive} numbers is easy for a computer: it counts upwards from zero. Representing \\emph{negative} numbers is harder, because \\emph{taking away values by adding them} is a little awkward. To represent a negative, designers use the leading (left-most) bit to declare ``positive'' (zero) or ``negative'' (one). Note that the \\emph{range} of numbers that can be represented does not change -- for a 4-digit binary number, whether counting from zero to 15, or from -8 to 7, the total space used on the number line is still 16 numbers, in order.\n\n\\stbox{6.0in}{\n\\emph{Problem:} If the computer doesn't know it is supposed to use that first number to determine whether a number is negative or not, how does it evaluate the number?\n}\n\n\\subsection*{Complement of a Number}\n\nIn mathematics, the \\emph{complement} of a binary number is ``the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa).\" This number is called the \\emph{ones' complement} of the number.\\footnote{{\\color{webblue}\\href{https://en.wikipedia.org/wiki/Ones\\%27_complement}{Wikipedia page on Ones' Complement.}}}\n\n\nHere's an example:\n\n\\bigskip\n\n\\begin{tabular} {c c c}\n Number &  $+$   &   $-$ \\\\[\\sep]\n \\hline\\\\[\\negsep]\n 0  &  0000 &  1111  \\\\ \n\\grr\n 1  & 0001  & 1110  \\\\\n 2  & 0010  & 1101\\\\\n\\grr\n 3  & 0011  & 1100\\\\\n 4  & 0100  & 1011\\\\\n\\grr\n 5  & 0101  & 1010\\\\\n 6  & 0110  & 1001\\\\\n\\grr\n 7  & 0111  & 1000\\\\\n \\hline\n\n\\end{tabular}\n\n\\subsection*{Subtraction}\n\nSubtraction is similar to addition -- very similar, since the process is ``adding a negative number\". To this point, we haven't seen negative numbers, because numbers below zero are harder to create or see, compared to numbers between zero and 15, or some other positive number. To get a negative number, computer scientists decided to create a pattern for describing negative numbers, that computers can correctly interpret. They decided to use the first bit (1 or 0, just a ``yes'' or ``no'' indicator) of the number as the \\emph{sign bit}: that is, if the first bit, in a ``signed integer\", is 1, then the number is a negative number. So if we have a four bit number, and the first bit is only for the ``is this number negative'' indicator, the number represents numbers in the range $[-7,8]$ -- still 16 values, but counting from $-7$ instead of zero. Also note that if you don't tell the computer the number is signed, it will happily assume the number is \\emph{unsigned} and give you the wrong answer\\footnote{Well, really, it will give you the \\emph{right} answer to a question that is different from the question you thought you were asking!}.\n\nTo subtract, we first create the \\emph{two's complement} of the number we are subtracting (the ``subtrahend\"). We leave the number from which we are subtracting (the ``minuend\") alone.\n\nTwo's complement works like this: you take the \\emph{complement} of the number, and add one. \\emph{Complement} means you swap all the zeroes for ones, and all the ones for zeroes. Put another way, you run each bit through a NOT gate, then add a one to the result, using a set of full adders.\n\nLet's take the two's complement of 7.\n\n\\begin{verbatim}\n       0111      7\n\n       1000           ones' complement of 7\n       0001           add one to get two's complement of 7\n===========   ====\n       1001     -8 + 1 = -7 \n\n\\end{verbatim}\n\nSo here's a simple example of subtraction:\n\n\\begin{verbatim}\n       0110      6\n-      0011      3\n===========   ====\n\n       1100           ones' complement of 3\n       0001           add one to get two's complement\n===========\t   \n       1101           (-8 + 1 + 0 + 4) = -3 ... good. Now we can add:\n\n\n       0110      6\n+      1101     -3\n===========   ====\n       0011      3      (see how the sign bit was converted to positive?)\n                        (the overflowed bit doesn't matter in this case)\n\n\\end{verbatim}\n\n\\newpage\nAnd here's a slightly more interesting one, with 8 bit numbers:\n\n\\begin{verbatim}\n  0000 0110      6\n- 0001 0011     19\n===========   ====\n\n  0001 0011     19\n  \n  1110 1100             ones' complement\n  0000 0001             add one\n===========   ====\n  1110 1101     (-128 + 64 + 32 + 0 + 8 + 4 + 0 + 1) = -19\n\n\n  0000 0110      6\n+ 1110 1101    -19\n===========   ====\n  1111 0011    -13   (-128 + 64 + 32 + 16 + 0 + 0 + 2 + 1) = BOOM! \n  \n\\end{verbatim}\n\nDesigning logic circuits for subtraction using the twos' complement is surprisingly elegant. Let's review what happens to execute a twos' complement subtraction operation:\n\n\\bi\n\\+ Get the ones' complement of the subtrahend (invert each bit with a NOT function)\n\\+ Add 1\n\\+ Add the resulting value to the minuend\n\\ei\n\nBuilding a flexible subtraction logic circuit depends on two features of our existing gates: first, that full adders can accept an incoming ``carry'' bit; and second, that XOR gates can be used as NOT gates by tying one of the inputs to positive voltage. Therefore, the logic circuit works like this:\n\n\\bi\n\\+ Pass each bit of the subtrahend through XOR gates with one of the inputs pulled up to positive voltage level; this takes the ones' complement of the number\n\\+ The result passes into one side of the full adder line we use for adding numbers\n\\+ Set the carry bit on the right-most full adder (i.e. the zero or 1 register) to high -- \\emph{this action adds 1 to the incoming number}\n\\ei\n\nThe result of the line of adders is the answer to the subtraction question.\n \n\\begin{figure}[ht!]\n\\begin{center}\n\n\\input{./include/real_subtraction_circuit.tex}\n\n\\caption{How addition and subtraction gets implemented with logic gates to either subtract {\\color{red}$A$}, a four digit binary number (something like \\texttt{0010}, or ``2\"), from {\\color{blue}$B$} (perhaps \\texttt{1000}, or ``8''), or add the two numbers instead. Each pair of bits goes into a full adder (the trapezoid-shaped symbol). To use subtraction, the M-line is held to a positive voltage, effectively turning the $XOR$ gate into a $NOT$ gate.}\n\\end{center}\n\\end{figure}\n\n\n\\newpage\n\\section*{A Bit More About Capacitors}\n\nThe Leyden jar was one of the first capacitors invented: metal foil was placed inside a glass jar, and wrapped around the outside of a glass jar, but neither foil gets near the top of the jar. The glass barrier between the foil sheets (inside and outside) allows a charge to build up between the foil without allowing the electrical charge to move through the glass. Leyden jars didn't hold much charge, but the concept it demonstrated has not changed.\n\nCapacitors are usually made with two metal plates that are on top of each other (or wrapped around each other), but that do not actually touch. When powered, they allow energy to be stored inside an electrical field. Because the plates need a lot of area to store even a small amount of charge, the plates are usually rolled up into some other shape, such as a cylinder. Sometimes, other shapes of capacitors are used for special purposes. \n\n\\bigskip\n\\stbox{6.0in}{\n\\emph{Experiment:} make a variable capacitor from aluminum foil, paper, and a paper towel tube. The paper should go around the roll only once. Cut the foil one-quarter or one-half inch smaller than the paper on all sides. Tape a small wire to one corner of the foil, if possible using metallic/conductive tape\\footnote{While it is possible to solder to aluminum foil, really there are much better and safer ways to attach a wire to the foil for the purposes of this workshop.}. Tape the foil to the paper. Tape one edge of the paper, foil side down, against the cardboard tube. Make another paper/foil combination. Wrap the paper/foil around the cardboard tube, but tape the paper only to itself, and just loose enough to slide a little. \n\nAnother example, using a coke can, can be found {\\color{webblue}\\href{http://www.tompolk.com/crystalradios/cokecancapacitor.html}{here}}.\n\n\\bigskip\n\nIt is also possible to make a regular capacitor with the paper-foil layers, separated by flat sheets of cardboard. Keep track of the ``up'' and ``down'' sides! Note that it is pretty easy to gang each ``plate'' together and make capacitor with a larger value; tying all the anodes together, and all the cathodes together, makes a larger capacitor.\n}\n\n\n%---------------------------\n\\clearpage\n\\newpage\n\\section*{Why NAND Gates and NOR Gates are ``Universal\"}\n%---------------------------\n\nIt turns out that it is possible to make \\emph{any} gate from NAND gates. The same is true for NOR gates. A very simple example can be seen, where we can create an OR gate from two NOR gates. \n\n\\input{./include/nor-to-or-gate.tex}\n\n\n\\input{./include/3-input-nand.tex}\n\n%---------------------------\n\\newpage\n\\section*{Memory}\n%---------------------------\n\nLogic circuits need to store the numbers they are working with in order to do more than one thing. Central Processing Units (CPUs), Arithmetic Logic Units (ALUs) or Floating-Point Units (FPUs) each work with numbers, and need to fetch them from somewhere and put them somewhere when they are done. The ``somewhere\" is \\emph{memory}. Keeping with the use of binary math and binary logic, a high voltage would be a 1 and a low voltage would be a 0. Through the use of these little stored charges, computers can keep track of many, many pieces of information. No matter what the circuits are doing, everything being stored is composed of some count of zeros and ones. \n\nThere have been \\emph{many} forms of memory through the years, including punched paper cards, and even a wiggly wire! The most common memory that a CPU uses these days is usually called ``dynamic RAM\" (DRAM), and each bit consists of a circuit that is primarily a single capacitor and a single transistor, though it requires supporting circuitry and cannot be read without erasing the memory cell. Computers read eight, sixteen, 32, or 64 bits at a time from a row of memory and pass the information (numbers or instruction codes) from the memory on to be processed by the CPU.\n\nOne type of computer memory, called \\emph{static RAM}, uses at least six transistors per bit. Since  DRAM is simpler (it uses only one transistor and one capacitor per bit), it is also cheaper. Therefore, to store one bit with 6 or more transistors is more expensive. So SRAM is mostly used for very important memory, like the memory very close to the core of the computer processor. Have a look at Figure \\ref{fig:sram}\\footnote{Diagram and supporting information adapted from {\\color{webblue}\\href{https://en.wikipedia.org/wiki/Static_random-access_memory}{Wikipedia}} and {\\color{webblue}\\href{https://www.entner.net/sites/default/files/diss-entner-final-v1.pdf}{Robert Entner's dissertation}}.}, \nwhich is pretty complicated, but if you understand how the two types of transistors are turned on and off, it will make sense. To keep this diagram simple, no resistors are shown. If you look closely at the $Q_1$/$Q_2$ and $Q_3$/$Q_4$ transistors, you can see that they are acting like inverters (that is, each pair makes a NOT gate). When WL (the ``word line\") goes high, $Q_5$ and $Q_6$ open up, allowing access to the single bit stored in $BL$ and the inverse of that bit in $\\overline{BL}$. Whether the word line is active (that is, whether or not you can write to the memory bit), it is possible to read the value of the bit--making SRAM very fast, because the system does not wait on the word line to activate.\n\n\n\\begin{figure}[h!]\n\\begin{center}\n\\input{./include/sramcell.tex}\n\\caption{A static ram cell. The bit line ($BL$) on the right is the value of the bit, and the bit line on the left ($\\low{BL}$) is the complement (NOT) the value of that bit.} % With a bit of careful circuitry, it is possible to write using only one of the bit lines, but it is safer to have two inputs (one positive, and one complement) to ensure the gates both change and lock in the value of the bit.  \n\\label{fig:sram}\n\\end{center}\n\\end{figure}\n\nSRAM uses 6 transistors per bit, making it very expensive compared to dynamic RAM, \nbut each bit of SRAM can stand alone, with no other supporting circuitry except \nfor the word line transistors. So, we use SRAM here because you can see the \ncircuit, and see how it works. As a bonus, you can construct a bit of SRAM with \nopposing NOT gates, making it fairly easy to see what is happening.\n\n\\begin{figure}\n  \\begin{center}\n  \\input{./include/JK-flip-flop.tex}\n  \\caption{A gate-level schematic of one bit of memory, using a JK flip-flop circuit. Note that the two left-most NAND gates have \\emph{three} inputs.}\n  \\end{center}\n\\end{figure}\n\n% JK flip-flop: \n% Flip-flop storage using NOR gates is better than my previous attempt using NOT gates. \n% I had trouble with the word/line controller circuit resistor values for positive \n% clearing and setting of the gate states. \n\nWe are going to implement some RAM using a {\\color{webblue}\\href{https://www.electronics-tutorials.ws/sequential/seq_2.html}{\\emph{flip-flop}}} circuit, made of NAND gates.\nIt uses even more transistors than the SRAM circuit, but it is simpler to create and uses logic gates with which you are already familiar. This ``JK Flip-Flop\" circuit uses\ntwo input NAND gates and also \\emph{three}-input NAND gates. 3-input NAND operates mostly\nthe same way as a regular NAND gate, except that the inputs also include the value of the \nQ and not-Q output (value) lines. \nThese lines are required before the output state (value) of the gate will change. And so is a ``clock\" signal line. By using a signal that turns on or turns off everywhere at once, the computer memory can be more reliable. The clock line ticks on and off like the second hand of a clock, allowing the computer to read or write to the memory without wondering if the values are changing.\nSo, the set- and reset- functions for the memory cell\nonly activate when the clock signal is also high (has positive voltage on the line).\nThis extra feature allows for certainty of reads and writes: it helps\navoid rapid oscillation / instability or lock-ups should a circuit (or a third\ngrader!) try to both set and reset the\nflip-flop at the same time. Furthermore, when powering up a simple SR flip-flop,\nthere is no inherent guarantee of what the value would be (of course, it's\npossible to put a pull-up or pull-down resistor on the signal lines to create\na natural ``base level'' of a set of inputs, though care must be taken to \nnot accidentally create incompatible base conditions (such as accidentally setting\nboth set and reset to high).\n\n\\begin{figure}\n  \\begin{center}\n    \\includegraphics[scale=0.10]{twoflipflops.jpg}\n  \\caption{Two bits of data storage, using JK flip-flop gates.}\n  \\end{center}\n\\end{figure}\n\n\n\n\n\n\n\n\n%---------------------------\n\\clearpage\n\\newpage\n\\section*{Resistor Chart}\n%---------------------------\n\nResistors are marked with colored bands to make it easy to determine what \nresistance value they have, and how close each individual part's value is \nguaranteed to be to that stated value.\n\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\fbox{\n\\includegraphics[scale=0.60]{resistorchart.png}\n}\n\\caption{A resistor value color band chart. The `tolerance' stripe (how close the value is guaranteed to be to the stated value) is on the right side. }\n\\label{fig:resistorchart}\n\\end{center}\n\\end{figure}\n", "meta": {"hexsha": "cb8b04e8bc9e983379d67d7f3eedceae3fabbfa3", "size": 18955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendices.tex", "max_stars_repo_name": "jessehamner/TechMillForKids", "max_stars_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-11-13T21:45:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T09:31:54.000Z", "max_issues_repo_path": "chapters/appendices.tex", "max_issues_repo_name": "jessehamner/TechMillForKids", "max_issues_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-03-10T21:46:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T19:21:58.000Z", "max_forks_repo_path": "chapters/appendices.tex", "max_forks_repo_name": "jessehamner/TechMillForKids", "max_forks_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-11-14T04:40:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-17T05:31:36.000Z", "avg_line_length": 61.3430420712, "max_line_length": 1151, "alphanum_fraction": 0.7231337378, "num_tokens": 5134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585669110203, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.6092090829074474}}
{"text": "\\subsubsection{Quadratic Factors}\r\n\r\nIf a polynomial has complex roots, then it has a quadratic factors.\r\nHere, we'll assume that the quadratic factor isn't repeated. \r\nSo,\r\n\\begin{equation*}\r\n\tQ(x) = R(x)(ax^2+bx+c)\\text{, }b^2-4ac < 0\\text{, and }R(x)\\text{ is not divisible by }ax^2+bx+c\r\n\\end{equation*}\r\nIn this case, we say\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{R(x)(ax^2+bx+c)} = \\left(\\text{Decomposition of }R(x)\\right)+\\frac{A_1x+B_1}{ax^2+bx+c}\r\n\\end{equation*}\r\nand then solve for the constants in the numerator, possibly having to solve a system of equations or using previous results and less convenient values for $x$.\r\n\r\n\\input{./backgroundReview/algebraPreCalc/quadraticFactors_example.tex}", "meta": {"hexsha": "097c6f77a8a440dbcde54aeb87a846ef16f9900a", "size": 702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/backgroundReview/algebraPreCalc/quadraticFactors.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/quadraticFactors.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/quadraticFactors.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.8, "max_line_length": 160, "alphanum_fraction": 0.7165242165, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6092090820816994}}
{"text": "\\subsection{Expressions derived from \\( \\pi \\):}\nOne may easily derive the average number of individuals that are at any given state \nusing \\( pi \\). \nThe average number of individuals in state \\( i \\) can be calculated by multiplying \nthe number of individuals that are present in state \\( i \\) with the probability \nof being at that particular state (i.e \\(\\pi_i (u_i + v_i)\\)). \nUsing this logic it is possible to calculate any performance measures that are related \nto the mean number of individuals in the system.\n\n\nAverage number of people in the system: \n\\begin{equation}\n    L = \\sum_{i=1}^{|\\pi|} \\pi_i (u_i + v_i)\n\\end{equation} \n\nAverage number of people in the service centre: \n\\begin{equation}\n    L_H = \\sum_{i=1}^{|\\pi|} \\pi_i v_i\n\\end{equation}\n\nAverage number of people in the buffer centre:\n\\begin{equation}\n    L_A = \\sum_{i=1}^{|\\pi|} \\pi_i u_i\n\\end{equation}\n\nConsequently getting the performance measures that are related to the duration of \ntime is not as straightforward. \nSuch performance measures are the mean waiting time in the system and the mean time \nblocked in the system. \nUnder the scope of this study three approaches have been considered to calculate these \nperformance measures; a direct approach, a recursive algorithm and consequently a\nclosed-form formula.\n\nThe research question that needs to be answered here is: ``When a class 1/2 \nindividuals enters the system, what is the expected time that they will have to \nwait?''. \nIn order to formulate the answer to that question one needs to consider all possible \nscenarios of what state the system can be in when an individual arrives. \nFurthermore, different formulas arises for class 1 individuals \nand a different one for class 2 individuals.\n\n\\subsection{Mean waiting time} \n\\subsubsection{Recursive formula for mean waiting time of class 1 individuals}\n\\label{sec:recursive-waiting-time-others}\n\nTo calculate the mean waiting time of class 1 individuals one must first identify \nthe set of states \\((u, v)\\) that will imply that a wait will occur. \nFor this particular Markov chain, this points to all states that satisfy \\(v > C\\) \ni.e. all states where the number of individuals in the service centre exceed the \nnumber of servers. \nThe set of such states is defined as \\textit{waiting states} and can be denoted \nas a subset of all the states, where:\n\n\\begin{equation} \\label{eq:waiting_states}\n    S_w = \\{(u, v) \\in S \\; | \\; v > C \\}    \n\\end{equation}\n\nAdditionally, there are certain states in the model where arrivals cannot occur. \nA class 1 individual cannot arrive whenever the model is at any state \n\\((u, N)\\) \nfor all \\(u\\) where \\(N\\) is the system capacity. \nTherefore the set of all such states that an arrival may occur are defined as \n\\textit{accepting states} and are denoted as:\n\n\\begin{equation}\\label{eq:accepting_states_class_1}\n    S_A^{(1)} = \\{(u, v) \\in S \\; | \\; v < N \\}\n\\end{equation}\n\n\n\nMoreover, another element that needs to be considered is the expected waiting time \nin each state \\( c(u,v) \\), otherwise known as sojourn time \\cite{Raghunandanan}. \nIn order to do so a variation of the Markov model has to be considered where when \nthe individual arrives at any of the states of the model no more arrivals can \noccur after that. \n\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{tikzpicture}[-, node distance = 1.4cm, auto]\n\n        \\tikzmath{\n            let \\minsz = 1.8cm;\n        }\n\n        \\node[draw=none, minimum size=\\minsz] (one) {};\n        \\node[state, minimum size=\\minsz, right=of one] (two) {(0,T-1)};\n        \\node[state, minimum size=\\minsz, right=of two] (three) {(0,T)};\n        \\node[state, minimum size=\\minsz, right=of three] (four) {(0,T+1)};\n        \\node[draw=none, minimum size=\\minsz, right=of four] (five) {};\n\n        \\node[state, draw=red, line width=0.5mm, minimum size=\\minsz, \n        below=of three] (three_one) {(1,T)};\n        \\node[state, draw=red, line width=0.5mm, minimum size=\\minsz, \n        below=of three_one] (three_two) {(2,T)};\n        \\node[state, minimum size=\\minsz, below=of four] (four_one) {(1,T+1)};\n        \\node[state, minimum size=\\minsz, below=of four_one] (four_two) {(2,T+1)};\n        \\node[draw=none, minimum size=\\minsz, right=of four_one] (five_one) {};\n        \\node[draw=none, minimum size=\\minsz, right=of four_two] (five_two) {};\n        \\node[draw=none, minimum size=\\minsz, below=of three_two] (three_three) {};\n\n        \\draw[every loop]\n            (two) edge node {\\((T-1) \\mu\\)} (one)\n            (three) edge node {\\(T \\mu\\)} (two)\n            (four) edge node {\\((T+1) \\mu\\)} (three)\n            (five) edge node {\\((T+1) \\mu\\)} (four)\n            (three_one) edge node {\\(T \\mu\\)} (three)\n\n            (four_one) edge node {\\((T+1) \\mu\\)} (three_one)\n            (five_one) edge node {\\((T+1) \\mu\\)} (four_one)\n            (three_two) edge node {\\(T \\mu\\)} (three_one)\n            (three_three) edge node {\\(T \\mu\\)} (three_two)\n            (four_two) edge node {\\((T+1) \\mu\\)} (three_two)\n            (five_two) edge node {\\((T+1) \\mu\\)} (four_two)\n            ;       \n        \n        \\draw[->, red, ultra thick] (three_two) edge node {} (two);\n        \\draw[->, red, ultra thick] (three_one) edge node {} (two);\n    \\end{tikzpicture}\n    \\caption{Markov chain - ignoring any arrivals} \n    \\label{other_patients_trip}\n\\end{figure}\n\nAs illustrated in figure \\ref{other_patients_trip} a class 1 individual, \nwhen in the threshold column, only visits one of the nodes since they are not \naffected by class 2 individuals. \nThus, one may acquire the desired time by calculating the inverse of the sum of \nthe out-flow rate of that state. \nSince we are ignoring arrivals though the only way to exit the state will only be \nvia a service. \nIn essence this notion can be expressed as:\n\n\\begin{equation} \\label{eq:sojourn_others}\n    c^{(1)}(u,v) = \n    \\begin{cases}\n        0, & \\textbf{if } u > 0 \\textbf{ and } v = T \\\\\n        \\frac{1}{\\text{min}(v,C)\\mu}, & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\nNote that whenever any class 1 individual is at a state \\((u,v)\\) where \n\\(u > 0\\) \nand \\(v = T\\) (i.e. all states \\((1,T), (2,T) \\dots, (M,T)\\)) the sojourn time is \nset to \\(0\\). \nThis is done to capture the trip thorough the Markov chain from the perspective \nof class 1 individuals. \nMeaning that they will visit all states of the threshold column but only the one \nin the first row will return a non-zero sojourn time.\n\nNow, using the above equations, and considering all sates that belong in \\(S_w\\) \nthe following recursive formula can be used to get the mean waiting time spent in \neach state in the Markov model. \nFor class 1 individuals, whenever the model is at state \\( (u,v) \\), any \nincoming \nindividual will proceed to arrive at state \\( (u, v+1) \\). \nindividuals will then proceed to visit all other states until they reach one which \nhas less than \\(C\\) servers occupied (i.e. until a server becomes available). \nThe formula goes through all states from right to left recursively and adds the \nsojourn times of all these states together until it reaches a state that is not \nin the set of waiting states. \nThus, the expected waiting time of a class 1 individual when they arrive at \nstate \\( (u,v) \\) can be given by:\n\n\\begin{equation} \\label{eq:waiting-time-at-each-state-other}\n    w^{(1)}(u,v) = \n    \\begin{cases} \n        0, \\hspace{4.85cm} & \\textbf{if } (u,v) \\notin S_w \\\\\n        c^{(1)}(u,v) + w^{(1)}(u-1, v), & \\textbf{if } u > 0 \\textbf{ and } v = T \\\\\n        c^{(1)}(u,v) + w^{(1)}(u, v-1), & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\nFinally, the mean waiting time can be calculated by summing over all expected \nwaiting times of accepting states multiplied by the probability of being at that \nstate and dividing by the probability of being in any accepting state.\n\n\\begin{equation} \\label{eq:recursive-waiting-time-others}\n    W^{(1)} = \\frac{\\sum_{(u,v) \\in S_A^{(1)}} w^{(1)}(u,v) \n    \\pi_{(u,v)}}{\\sum_{(u,v) \\in S_A^{(1)}} \\pi_{(u,v)}}\n\\end{equation}\n\n\n\n\\subsubsection{Recursive formula for mean waiting time of \nclass 2 individuals} \\label{sec:recursive-waiting-time-ambulance}\n\nEquivalently the mean waiting time for class 2 individuals can be calculated \nin a similar manner. \nThe set of waiting states is the same as before but there is a slight modification \nin the set of accepting states.\n\n\\[\n    S_w = \\{(u, v) \\in S \\; | \\; v > C \\}    \n\\]\n\n\\begin{equation}\\label{eq:accepting_states_class_2}\n    S_A^{(2)}=\n    \\begin{cases}\n        \\{(u, v) \\in S \\; | \\; u < M \\} & \\textbf{if } T \\leq N\\\\\n        \\{(u, v) \\in S \\; | \\; v < N \\} & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\nThe set of accepting states is modified in such a way such that a class 2 \nindividual cannot arrive in the model when the model is at any state \\((M, v)\\) \nfor \nall \\(v \\geq T\\) where \\(M\\) is the buffer centre capacity and \\(T\\) is the threshold. \nAn odd situation here is when the threshold is set to a very high number that is \nmore than the actual system capacity. \nIn such cases the set of accepting states is defined in the same way as the \nclass 1 individuals case (\\ref{eq:accepting_states_class_1}). \nThat is because whenever \\(T > N\\) no class 2 individual will ever be blocked in \nthe model \n(since that threshold can never be reached) and thus the last accepting state of \nthe model will be state \\( (0,N-1)\\). \n\nNow just like in the class 1 individuals case the sojourn time is needed. \nFor class 2 individuals whenever individuals are at any row apart from the \nfirst one they automatically get a wait time of \\(0\\) since they are essentially \nblocked.\n\n\\begin{equation} \\label{eq:sojourn_ambulance}\n    c^{(2)}(u,v) = \n    \\begin{cases}\n        0, & \\textbf{if } u > 0 \\\\\n        \\frac{1}{\\text{min}(v,C)\\mu}, & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\nFinally, the recursive formula and the mean waiting time equation are identical \nto the ones described above with the exception that they now use \\(c^{(2)}(u,v)\\) \ninstead of \\(c^{(1)}(u,v)\\).\n\\begin{equation} \\label{eq:waiting-time-at-each-state-ambulance}\n    w^{(2)}(u,v) = \n    \\begin{cases} \n        0, \\hspace{4.85cm} & \\textbf{if } (u,v) \\notin S_w \\\\\n        c^{(2)}(u,v) + w^{(2)}(u-1, v), & \\textbf{if } u > 0 \\textbf{ and } v = T \\\\\n        c^{(2)}(u,v) + w^{(2)}(u, v-1), & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation}\n\n\\begin{equation}\\label{eq:recursive-waiting-time-ambulance}\n    W^{(2)} = \\frac{\\sum_{(u,v) \\in S_A^{(2)}} w^{(2)}(u,v) \\pi_{(u,v)}}\n    {\\sum_{(u,v) \\in S_A^{(2)}} \\pi_{(u,v)}}\n\\end{equation}\n\n\\subsubsection{Mean Waiting Time - Closed-form}\nUpon closer inspection of the recursive formula a more compact formula can arise. \nThe equivalent closed-form formula eliminates the need for recursion and thus makes \nthe computation of waiting times much more efficient. \nJust like in the recursive part there are two formulas; one for \\textit{class 1} \nand one for class 2 individuals. \nThe formulas are given by:\n\n\\begin{equation} \\label{eq:closed_form_waiting_others}\n    W^{(1)} = \\frac{\\sum_{\\substack{(u,v) \\, \\in S_A^{(1)} \\\\ v \\geq C}} \n    \\frac{1}{C \\mu} \\times (v-C+1) \\times \\pi(u,v)}{\\sum_{(u,v) \\, \n    \\in S_A^{(1)}} \\pi(u,v)}\n\\end{equation}\n    \n\\begin{equation}\\label{eq:closed_form_waiting_ambulance}\n    W^{(2)} = \\frac{\\sum_{\\substack{(u,v) \\, \\in S_A^{(2)} \\\\ min(v,T) \\geq C}} \n    \\frac{1}{C \\mu} \\times (\\min(v+1,T)-C) \\times \\pi(u,v)}{\\sum_{(u,v) \\, \n    \\in S_A^{(2)}} \\pi(u,v)}\n\\end{equation}\n\nNote here that the summation, in both equations \\ref{eq:closed_form_waiting_others} \nand \\ref{eq:closed_form_waiting_ambulance}, goes through all states in the set of \naccepting \nstates of either class 1 or class 2 individuals respectively, where a wait \nincurs. \nIn equation \\ref{eq:closed_form_waiting_others} that includes all states \\((u,v)\\) \nin the set of accepting states of class 1 individuals such that \\( v \\geq C\\); i.e. \nwhenever an arrival occurs and the system is at a state where the number of individuals \nin the system is more than or equal to $C$. \nConsequently, for the states that are included in the summation the expression \n\\( v-C+1 \\) indicates the amount of people in service one would have to wait for \nupon arrival at the hospital.\n\nAdditionally, the minimisation function in equation \n\\ref{eq:closed_form_waiting_ambulance} \nensures that when a class 2 individual arrives at any state \nthat is greater than the predetermined threshold, the wait that the individual will \nhave to endure remains the same. \nIn essence, the expression \\(\\min(v+1,T) - C\\) returns the number of people in line \nin front of a particular individual upon arrival.\n\n\n\\subsubsection{Overall Waiting Time}\n\nConsequently, the overall waiting time should can be estimated by a linear combination \nof the waiting times of class 1 and class 2 individuals. \nThe overall waiting time can be then given by the following equation where \\(c_1\\) \nand \\(c_2\\) are the coefficients of each individual's type waiting time:\n\n\\begin{equation}\\label{eq:overall_waiting_time_coeff}\n    W = c_1 W^{(1)} + c_2 W^{(2)}\n\\end{equation}\n\nThe two coefficients represent the proportion of individuals of each type that \ntraversed through the model. \nTheoretically, getting these percentages should be as simple as looking at the arrival \nrates of each type but in practise if the service centre or the buffer centre \nis full, some individuals may be lost to the system. \nThus, one should account for the probability that an individual is lost to the system. \nThis probability can be easily calculated by using the two sets of accepting states \n\\(S_A^{(2)}\\) and \\(S_A^{(1)}\\) defined earlier in equations \n\\ref{eq:accepting_states_class_1} \nand \\ref{eq:accepting_states_class_2}. \nLet us define here the probability, for either class type, that an individual \nis not lost in the system by:\n\n\\begin{equation*}\n    P(L'_1) = \\sum_{(u,v) \\, \\in S_A^{(1)}} \\pi(u,v) \\hspace{2cm}\n    P(L'_2) = \\sum_{(u,v) \\, \\in S_A^{(2)}} \\pi(u,v)\n\\end{equation*}\n\nHaving defined these probabilities one may combine them with the arrival rates of \neach class type in such a way to get the expected proportions of class 1 and \nclass 2 individuals in the model. \nThus, by using these values as the coefficient of equation \n\\ref{eq:overall_waiting_time_coeff} \nthe resultant equation can be used to get the overall waiting time. \nNote here that the equation below gets the overall waiting time for both the recursive \nand the closed-form formula.\n\n\\begin{equation}\\label{eq:overall_waiting_time}\n    W = \\frac{\\lambda_1 P(L'_1)}{\\lambda_2 P(L'_2) + \\lambda_1 P(L'_1)} W^{(1)} + \n    \\frac{\\lambda_2 P(L'_2)}{\\lambda_2 P(L'_2) + \\lambda_1 P(L'_1)} W^{(2)}\n\\end{equation}\n\n\n\n\\subsection{Mean blocking time}\n\n\\subsubsection{Direct approach for mean blocking time}\n\nUnlike the waiting time, the blocking time is only calculated for class 2 individuals.  \nThat is because class 1 individuals cannot be blocked. \nThus, one only needs to consider the pathway of class 2 individuals to get the \nmean blocking time of the system. \nBlocking occurs at states \\((u,v)\\) where \\(u > 0 \\). \nThus, the set of blocking states can be defined as:\n\n\\begin{equation*}\n    S_b = \\{(u,v) \\in S \\; | \\; u > 0\\}\n\\end{equation*}\n \nIn order to not consider individuals that will be lost to the system, the set of \naccepting states needs to be taken into account. As defined in section \n\\ref{sec:recursive-waiting-time-ambulance},\nthe set of accepting states is given by (\\ref{eq:accepting_states_class_2}):\n\n\\begin{equation*}\n    S_A^{(2)}=\n    \\begin{cases}\n        \\{(u, v) \\in S \\; | \\; u < M \\} & \\textbf{if } T \\leq N\\\\\n        \\{(u, v) \\in S \\; | \\; v < N \\} & \\textbf{otherwise}\n    \\end{cases}\n\\end{equation*}\n\nFor the waiting time formula in sections \\ref{sec:recursive-waiting-time-others}\nand \\ref{sec:recursive-waiting-time-ambulance}\nthe mean sojourn time for each state was considered,\nignoring any arrivals. Here, the same approach is used but ignoring only class 2\narrivals. That is because for the waiting time formula, once an individual enters \nthe service centre (i.e. starts waiting) any individual arriving after them will \nnot affect their\npathway. That is not the case for blocking time. When a class 2 individual is \nblocked, \nany class 1 individual that arrives will cause the blocked individual to remain \nblocked for more time. Therefore, class 1 arrivals are considered here:\n\n\\begin{equation}\\label{eq:time_in_state_blocking_time}\n    c(u,v) = \n    \\begin{cases}\n        \\frac{1}{\\min(v,C) \\mu}, & \\text{if } v = C\\\\\n        \\frac{1}{\\min(v,C) \\mu + \\lambda_1}, & \\text{otherwise}\n    \\end{cases}\n\\end{equation}\n \nIn equation \\ref{eq:time_in_state_blocking_time}, both service completions and \nclass 1 arrivals are considered. \nThus, from a blocked individual's perspective whenever the system moves from one \nstate \\((u,v)\\)\nto another state it can either:\n\n\\begin{itemize}\n    \\item be because of a service being completed: we will denote the probability \n    of this happening by \\(p_s(u,v)\\). \n    \\item be because of an arrival of an individual of class 1: denoting such \n    probability by \\(p_o(u,v)\\).\n\\end{itemize}\nThe probabilities are given by:\n\n\\begin{equation*}\n    p_s(u,v) = \\frac{\\min(v,C)\\mu}{\\lambda_1 + \\min(v,C)\\mu}, \\qquad\n    p_o(u,v) = \\frac{\\lambda_1}{\\lambda_1 + \\min(v,C)\\mu}\n\\end{equation*}\n\n\nHaving defined \\(c(u,v)\\) and \\(S_b\\) a formula for the blocking time that is\nexpected to occur at each state can be given by:\n\n\\begin{equation}\\label{eq:blocking-time-at-each-state}\n    b(u,v) = \n    \\begin{cases} \n        0, & \\textbf{if } (u,v) \\notin S_b \\\\\n        c(u,v) + b(u - 1, v), & \\textbf{if } v = N = T\\\\\n        c(u,v) + b(u, v-1), & \\textbf{if } v = N \\neq T \\\\\n        c(u,v) + p_s(u,v) b(u-1, v) + p_o(u,v) b(u, v+1), & \\textbf{if } u > 0 \n        \\textbf{ and } v = T \\\\\n        c(u,v) + p_s(u,v) b(u, v-1) + p_o(u,v) b(u, v+1), & \\textbf{otherwise} \\\\\n    \\end{cases}\n\\end{equation}\n\nUnlike equations (\\ref{eq:waiting-time-at-each-state-other}) and \n(\\ref{eq:waiting-time-at-each-state-ambulance}), equation \n(\\ref{eq:blocking-time-at-each-state}) will not be solved recursively. \nA direct approach will be used to solve this equation here. \nBy enumerating all equations of (\\ref{eq:blocking-time-at-each-state}) for all \nstates \\((u,v)\\) that belong in \\(S_b\\) \na system of linear equations arises where the unknown variables are all the \\(b(u,v)\\)\nterms.\nFor instance, let us consider a Markov model where \\(C=2, T=3, N=6, M=2\\). \nThe Markov model is shown in Figure \\ref{fig:example-algeb-blocking}\nand the equivalent equations are \n(\\ref{eq:first_eq_of_blocking_example})-(\\ref{eq:last_eq_of_blocking_example}).\nThe equations considered here are only the ones that correspond to the blocking \nstates.\n\n\\begin{multicols*}{2}\n    \\begin{figure}[H]\n        \\scalebox{0.50}{\\input{MarkovChain/expressions_from_pi/example_model_2242/main.tex}}\n        \\caption{Example of Markov chain}\n        \\label{fig:example-algeb-blocking}\n    \\end{figure}\n    \\columnbreak\n    \\begin{align}\n        b(1,2) &= c(1,2) + p_o b(1,3) \\label{eq:first_eq_of_blocking_example} \\\\\n        b(1,3) &= c(1,3) + p_s b(1,2) + p_o b(1,4) \\\\\n        b(1,4) &= c(1,4) + b(1,3) \\\\\n        b(2,2) &= c(2,2) + p_s b(1,2) + p_o b(2,3) \\\\\n        b(2,3) &= c(2,3) + p_s b(2,2) + p_o b(1,4) \\\\\n        b(2,4) &= c(2,4) + b(2,3)\\label{eq:last_eq_of_blocking_example}\n    \\end{align}\n\\end{multicols*}\n\nAdditionally, the above equations can be transformed into a linear system of the \nform \\(Zx=y\\) where:\n\n\\begin{equation}\\label{eq:example-algebaric-approach-blocking-time}\n    Z=\n    \\begin{pmatrix}\n        -1 & p_o & 0 & 0 & 0 & 0 \\\\ %(1,2)\n        p_s & -1 & p_o & 0 & 0 & 0 \\\\ %(1,3)\n        0 & 1 & -1 & 0 & 0 & 0 \\\\ %(1,4)\n        p_s & 0 & 0 & -1 & p_o & 0\\\\ %(2,2)\n        0 & 0 & 0 & p_s & -1 & p_o \\\\ %(2,3)\n        0 & 0 & 0 & 0 & 1 & -1 \\\\ %(2,4)\n    \\end{pmatrix},\n    x=\n    \\begin{pmatrix}\n        b(1,2) \\\\\n        b(1,3) \\\\\n        b(1,4) \\\\\n        b(2,2) \\\\\n        b(2,3) \\\\\n        b(2,4) \\\\\n    \\end{pmatrix}, \n    y=\n    \\begin{pmatrix}\n        -c(1,2) \\\\\n        -c(1,3) \\\\\n        -c(1,4) \\\\\n        -c(2,2) \\\\\n        -c(2,3) \\\\\n        -c(2,4) \\\\\n    \\end{pmatrix}\n\\end{equation}\n\nA more generalised form of the equations in \n(\\ref{eq:example-algebaric-approach-blocking-time})\ncan thus be given for any value of \\(C,T,N,M\\) by:\n\n\\begin{align}\n    b(1,T) =& c(1, T) + p_o b(1, T + 1) \\label{eq:first_eq_of_blocking_general}\\\\\n    b(1,T + 1) =& c(1, T + 1) + p_s(1, T) + p_o b(1, T + 1) \\\\\n    b(1,T + 2) =& c(1, T + 2) + p_s(1, T + 1) + p_o b(1, T + 3) \\\\\n    & \\vdots \\nonumber \\\\\n    b(1, N) =& c(1, N) + b(1, N - 1) \\\\\n    b(2, T) =& c(2, T) + p_s b(1, T) + p_o b(2, T + 1) \\\\\n    b(2, T + 1) =& c(2, T + 1) + p_s b(2, T) + p_o b(2, T + 2) \\\\\n    & \\vdots \\nonumber \\\\\n    b(M, T) =& c(M, T) + b(M, T-1) \\label{eq:last_eq_of_blocking_general}\n\\end{align}\n\nThe equivalent matrix form of the linear system of equations \n(\\ref{eq:first_eq_of_blocking_general}) - (\\ref{eq:last_eq_of_blocking_general})\nis given by \\(Zx=y\\), where:\n\\begin{equation}\\label{eq:general-algebaric-approach-blocking-time}\n    \\scalebox{0.9}{\n        \\(\n        Z = \n        \\begin{pmatrix}\n            -1 & p_o & 0 & \\dots & 0 & 0 & 0 & 0 & 0 & \\dots & 0 & 0 \\\\ %(1,T)\n            p_s & -1 & p_o & \\dots & 0 & 0 & 0 & 0 & 0 & \\dots & 0 & 0 \\\\ %(1,T+1)\n            0 & p_s & -1 & \\dots & 0 & 0 & 0 & 0 & 0 & \\dots & 0 & 0 \\\\ %(1,T+2)\n            \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots & \\vdots & \n            \\vdots & \\ddots & \\vdots & \\vdots \\\\ \n            0 & 0 & 0 & \\dots & 1 & -1 & 0 & 0 & 0 & \\dots & 0 & 0 \\\\ %(1,N)\n            p_s & 0 & 0 & \\dots & 0 & 0 & -1 & p_o & 0 & \\dots & 0 & 0 \\\\ %(2,T)\n            0 & 0 & 0 & \\dots & 0 & 0 & p_s & -1 & p_o & \\dots & 0 & 0 \\\\ %(2,T+1)\n            \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots & \\vdots & \n            \\vdots & \\ddots & \\vdots & \\vdots \\\\ \n            0 & 0 & 0 & \\dots & 0 & 0 & 0 & 0 & 0 & \\dots & 1 & -1 \\\\ %(M,T)\n        \\end{pmatrix},\n        x = \n        \\begin{pmatrix}\n            b(1,T) \\\\\n            b(1,T+1) \\\\\n            b(1,T+2) \\\\\n            \\vdots \\\\\n            b(1,N) \\\\\n            b(2,T) \\\\\n            b(2,T+1) \\\\\n            \\vdots \\\\\n            b(M,T) \\\\\n        \\end{pmatrix}, \n        y= \n        \\begin{pmatrix}\n            -c(1,T) \\\\\n            -c(1,T+1) \\\\\n            -c(1,T+2) \\\\\n            \\vdots \\\\\n            -c(1,N) \\\\\n            -c(2,T) \\\\\n            -c(2,T+1) \\\\\n            \\vdots \\\\\n            -c(M,T) \\\\\n        \\end{pmatrix}\n        \\)\n    }\n\\end{equation}\n\nThus, having calculated the mean blocking time for all blocking states \\(b(u,v)\\), \nit only remains to put them together in a formula just like in equations \n\\ref{eq:recursive-waiting-time-others} and \\ref{eq:recursive-waiting-time-ambulance}.\nThe resultant blocking time formula is given by:\n\n\\begin{equation}\\label{eq:algebraic-blocking-time}\n    B = \\frac{\\sum_{(u,v) \\in S_A} \\pi_{(u,v)} \\; b(u,v)}{\\sum_{(u,v) \\in S_A} \n    \\pi_{(u,v)}}\n\\end{equation}\n\n\n\\subsection{Mean proportion of arrivals within time target}\n\nAnother performance measure that needs to be taken into consideration is the \nproportion of individuals whose waiting and service times lie within a specified \ntime target.\nIn order to consider such measure though one would need to obtain the \ndistribution of time in the system for all individuals. The complexity of such \na task lies on the fact that different individuals arrive at different states of\nthe Markov model. Let us first consider the case when an arrival occurs when the\nmodel is at a specific state.\n\n\\subsubsection{Distribution of time at a specific state (with 1 server)}\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.75}{\\input{MarkovChain/expressions_from_pi/example_model_1242/main.tex}}\n    \\caption{Example Markov model \\(C=1, T=2, N=4, M=2\\)}\n    \\label{fig:distribution-of-time-at-specific-state-1-server}\n\\end{figure}\n\nConsider the Markov model of figure \n\\ref{fig:distribution-of-time-at-specific-state-1-server} with one server and a \nthreshold of two individuals. \nLet us now assume that a class 1 individual arrives when the model is at state \n\\((0,3)\\), thus forcing the model to move to state \\((0,4)\\). \nThe distribution of the time needed for the specified individual to exit the \nsystem from state \\((0,4)\\) is given by the sum of exponentially distributed \nrandom variables with the same parameter \\(\\mu\\). \nThe sum of such random variables form the Erlang distribution which is defined \nby the number of random variables that are added and their exponential \nparameter.\nNote here that these random variables represent the individual's pathway from \nthe perspective of the individual. \nThus, \\(X_i\\) represents the random variable of the time that it takes for an\nindividual to move from the \\(i^{\\text{th}}\\) position of the queue to the \n\\((i-1)^{\\text{th}}\\) position (i.e. for someone in front of them to finish \ntheir service) and \\(X_0\\) is the time it takes that individual to move from \nhaving a service to exiting the system.\n\n\n\\begin{align}\n    (0,4) \\Rightarrow \\quad & X_3 \\sim Exp(\\mu) \\nonumber \\\\\n    (0,3) \\Rightarrow \\quad & X_2 \\sim Exp(\\mu) \\nonumber \\\\\n    (0,2) \\Rightarrow \\quad & X_1 \\sim Exp(\\mu) \\nonumber \\\\\n    (0,1) \\Rightarrow \\quad & X_0 \\sim Exp(\\mu) \\nonumber \\\\\n    S = X_3 + X_2 + & X_1 + X_0 = Erlang(4, \\mu)\n\\end{align}\n\nThus, the waiting and service time of an individual in the model of figure \n\\ref{fig:distribution-of-time-at-specific-state-1-server} can be captured by an \nerlang distributed random variable. \nThe general CDF of the erlang distribution \\(Erlang(k, \\mu)\\) is given by:\n\n\\begin{equation} \\label{eq:cdf-erlang}\n    P(S < t) = 1 - \\sum_{i=0}^{k-1} \\frac{1}{i!} e^{-\\mu t} (\\mu t)^i\n\\end{equation}\n\nUnfortunately, the erlang distribution can only be used for the sum of \nidentically distributed random variables from the exponential distribution. \nTherefore, this approach cannot be used when one of the random variables has a \ndifferent parameter than the others. \nIn fact the only case where we can use it is only when the number of servers are\n\\(C=1\\), just like in the explored example, or when an individual arrives and \ngoes straight to service (i.e. when there is no other individual waiting and \nthere is an empty server).\n\n\n\\subsubsection{Distribution of time at a specific state (with multiple servers)}\n\n\\begin{figure}[h]\n    \\centering\n    \\scalebox{0.75}{\\input{MarkovChain/expressions_from_pi/example_model_2242/main.tex}}\n    \\caption{Example Markov model \\(C=2, T=2, N=4, M=2\\)}\n    \\label{fig:distribution-of-time-at-specific-state-2-servers}\n\\end{figure}\n\nFigure \\ref{fig:distribution-of-time-at-specific-state-2-servers} represents the \nsame Markov model as figure \n\\ref{fig:distribution-of-time-at-specific-state-1-server} with the only \nexception that there are 2 servers here. \nBy applying the same logic, assuming that an individual arrives at state \n\\((0,4)\\), the sum of the following random variables arises.\n\n\\begin{align}\n    (0,4) \\Rightarrow \\quad & X_2 \\sim Exp(2\\mu) \\nonumber \\\\\n    (0,3) \\Rightarrow \\quad & X_1 \\sim Exp(2\\mu) \\\\\n    (0,2) \\Rightarrow \\quad & X_0 \\sim Exp(\\mu) \\nonumber\n\\end{align}\n\nSince these exponentially distributed random variables do not share the same \nparameter, an erlang distribution cannot be used. \nIn fact, the problem can now be viewed either as the sum of exponentially \ndistributed random variables with different parameters or as the sum of \nerlang distributed random variables.\nThe sum of erlang distributed random variables is said to follow the \nhypoexponential distribution. \nThe hypoexponential distribution is defined with two vectors of size equal\nto the number of Erlang random variables that are added together\n\\cite{Akkouchi2008}, \\cite{Smaili2013}. \nFor this particular example:\n\n\\begin{align} \\label{eq:multiple-servers-distribution-example}\n    \\begin{rcases}\n        \\begin{rcases}\n            X_2 \\sim Exp(2\\mu) \\\\\n            X_1 \\sim Exp(2\\mu)\n        \\end{rcases}\n        X_1 + X_2 = S_1 \\sim Erlang(2, 2\\mu) \\\\\n        X_0 \\sim Exp(\\mu) \\Rightarrow \\hspace{1cm} X_0 = S_2 \\sim Erlang(1, \\mu)\n    \\end{rcases}\n    S_1 + S_2 = H \\sim Hypo((2,1), (2\\mu, \\mu)) \n\\end{align}\n\nThe random variable \\(H\\) from equation \n\\ref{eq:multiple-servers-distribution-example} follows a hypoexponential \ndistribution with two vector parameters. \nThe CDF of this distribution can be therefore used to get the probability of the \ntime in spent in the system being less than a given target.\nThe CDF of the general hypoexponential distribution \\(Hypo(\\vec{r}, \n\\vec{\\lambda})\\), is given by the following expression, where vector \\(\\vec{r}\\) \ncontains all \\(k\\)-values of the erlang distributions and \\(\\vec{\\lambda}\\) \nis a vector of the distinct parameters \\cite{Favaro2010}.\n\n\\begin{align} \\label{eq:general-cdf-hypoexponential}\n    & P(H < t) = 1 - \\left( \\prod_{j=1}^{\\mid \\vec{r} \\mid} \\lambda_j^{r_j} \\right) \n    \\sum_{k=1}^{\\mid \\vec{r} \\mid} \\sum_{l=1}^{r_k} \\frac{\\Psi_{k,l}(-\\lambda_k)t^{r_k - l} \n    e^{-\\lambda_k t}}\n    {(r_k - l)! (l - 1)!} \\nonumber \\\\ \n    & \\textbf{where} \\qquad \\Psi_{k,l}(t) = - \\frac{\\partial^{l - 1}}\n    {\\partial t ^{l - 1}} \\left( \\prod_{j = 0, j \\neq k}^{\\mid \\vec{r} \\mid} \n    (\\lambda_j + t)^{-r_j} \\right) \\nonumber \\\\\n    & \\textbf{and} \\quad \\qquad \\lambda_0 = 0, r_0 = 1\n\\end{align}\n\n\nThe computation of the derivative makes equation \\ref{eq:general-cdf-hypoexponential}\ncomputationally expensive. \nIn \\cite{Legros2015} an alternative linear version of that CDF is explored via \nmatrix analysis, and is given by the following formula:\n\n\\begin{equation} \\label{eq:linear-general-cdf-hypoexponential}\n    \\begin{split}\n        F(x) = &1 - \\sum_{k=1}^{n} \\sum_{l=0}^{k-1} (-1)^{k-1} \\binom{n}{k} \n            \\binom{k-1}{l} \\sum_{j=1}^{n} \\sum_{s=1}^{j-1} e^{-x \\lambda_s} \n            \\prod_{l=1}^{s-1} \\left( \\frac{\\lambda_l}{\\lambda_l - \\lambda_s} \\right)\n            ^ {k_s} \\\\\n        & \\times \\sum_{s < a_1 < \\dots < a_{l-1} < j} \n            \\left( \\frac{\\lambda_s}{\\lambda_s - \\lambda_{a_1}} \\right) ^ {k_s}\n            \\prod_{m=s+1}^{a_1-1} \\left( \\frac{\\lambda_m}{\\lambda_m - \n            \\lambda_{a_1}}\\right) ^ {k_m}  \n            \\prod_{n=a_1}^{a_2-1} \\left( \\frac{\\lambda_n}{\\lambda_n - \n            \\lambda_{a_2}}\\right) ^ {k_n} \\\\\n        & \\dots \\prod_{r=a_l-1}^{j-1} \\left( \\frac{\\lambda_r}{\\lambda_r - \n            \\lambda_{a_j}}\\right) ^ {k_r}  \n            \\sum_{q=0}^{k_s - 1} \\frac{((\\lambda_s - \\lambda_{a_1})x)^q}{q!}, \\\\\n        & \\text{for } \\geq 0\n    \\end{split}\n\\end{equation}\n\n\n\\subsubsection{Specific CDF of hypoexponential distribution}\nEquations \\ref{eq:general-cdf-hypoexponential} and \n\\ref{eq:linear-general-cdf-hypoexponential} refers to the general CDF of the\nhypoexponential distribution where the size of the vector parameters can be of\nany size \\cite{Favaro2010}.\nIn the Markov chain models described in figures \n\\ref{fig:distribution-of-time-at-specific-state-1-server} and \n\\ref{fig:distribution-of-time-at-specific-state-2-servers} the parameter vectors \nof the hypoexponential distribution are of size two, and in fact, for any \npossible version of the investigated Markov chain model the vectors can only be \nof size two.\nThis is true since for any dimensions of this Markov chain model there will \nalways be at most two distinct exponential parameters; the parameter for \nfinishing a service (\\(\\mu\\)) and the parameter for moving forward in the queue \n(\\(C \\mu\\)). \nFor the special case of \\(C=1\\) the hypoexponential distribution will not be \nused as this is equivalent to an erlang distribution.\nTherefore, by fixing the sizes of \\(\\vec{r}\\) and \\(\\vec{\\lambda}\\) to 2, the \nfollowing specific expression for the CDF of the hypoexponential distribution\narises, where the derivative is removed:\n\n\n\\begin{align} \\label{eq:specific-cdf-hypoexponential}\n    & P(H < t) = 1 - \\left( \\prod_{j=1}^{\\mid \\vec{r} \\mid} \\lambda_j^{r_j} \\right) \n    \\sum_{k=1}^{\\mid \\vec{r} \\mid} \\sum_{l=1}^{r_k} \\frac{\\Psi_{k,l}(-\\lambda_k)t^{r_k - l} \n    e^{-\\lambda_k t}}{(r_k - l)! (l - 1)!} \\nonumber \\\\ \n    & \\textbf{where} \\qquad \\Psi_{k,l}(t) = \n    \\begin{cases} \n        \\frac{(-1)^{l} (l-1)!}{\\lambda_2} \\left[\\frac{1}{t^l} - \\frac{1}\n        {(t + \\lambda_2)^l}\\right] , & k=1 \\\\\n        - \\frac{1}{t (t + \\lambda_1)^{r_1}}, & k=2\n    \\end{cases} \\nonumber \\\\\n    & \\textbf{and} \\quad \\qquad \\lambda_0 = 0, r_0 = 1\n\\end{align}\n\nNote here that the only difference between equation \n\\ref{eq:general-cdf-hypoexponential} and \\ref{eq:specific-cdf-hypoexponential} \nis the \\(\\Psi\\) function. The next section proves why the following expression \nis true:\n\n\\begin{equation} \\label{eq:hypoexponential-expression-to-proof}\n    - \\frac{\\partial^{l - 1}}{\\partial t ^{l - 1}} \n    \\left( \\prod_{j = 0, j \\neq k}^{\\mid \\vec{r} \\mid} (\\lambda_j + t)^{-r_j} \\right) = \n    \\begin{cases} \n        \\frac{(-1)^{l} (l-1)!}{\\lambda_2} \\left[\\frac{1}{t^l} - \\frac{1}\n        {(t + \\lambda_2)^l}\\right] , & k=1 \\\\\n        - \\frac{1}{t (t + \\lambda_1)^{r_1}}, & k=2\n    \\end{cases}\n\\end{equation}\n\n\n\n\\subsubsection{Proof of specific hypoexponential distribution \n\\ref{eq:hypoexponential-expression-to-proof}}\n \nThis section aims to show that there exists a simplified expression of equation \n\\ref{eq:general-cdf-hypoexponential} that is specific to the proposed Markov \nmodel.\nFunction \\(\\Psi\\) is defined using the parameter \\(t\\) and the variables \\(k\\) \nand \\(l\\).\nGiven the Markov model, the range of values that \\(k\\) and \\(l\\) can take can be\nbounded.\nFirst of all, from the range of the double summation in equation \n\\ref{eq:general-cdf-hypoexponential}, it can be seen that \n\\(k = 1, 2, \\dots, \\mid \\vec{r} \\mid\\).\nNow, \\(\\mid \\vec{r} \\mid\\) represents the size of the parameter vectors that, \nfor the Markov model, will always be 2. \nThat is because, for all the exponentially distributed random variables that are\nadded together to form the new distribution, there only two distinct parameters,\nthus forming two erlang distributions. Therefore:\n\n\\begin{equation*}\n    k = 1, 2\n\\end{equation*}\n\nBy observing equation \\ref{eq:general-cdf-hypoexponential} once more, the range\nof values that \\(l\\) takes are \\(l = 1, 2, \\dots, r_k\\), where \\(r_1\\) is \nsubject to the individual's position in the queue and \\(r_2 = 1\\).\nIn essence, the hypoexponential distribution will be used with these bounds:\n\n\\begin{align}\n    k = 1 & \\qquad \\Rightarrow \\qquad l = 1, 2, \\dots, r_1 \\nonumber \\\\\n    k = 2 & \\qquad \\Rightarrow \\qquad l = 1\n\\end{align}\n\nThus the left hand side of equation \\ref{eq:hypoexponential-expression-to-proof} \nneeds only to be defined for these bounds. \nThe specific hypoexponential distribution investigated here is of the form\n\\(Hypo((r_1, 1)(\\lambda_1, \\lambda_2))\\).\nNote the initial conditions \\(\\lambda_0=0, r_0=1\\) defined in equation \n\\ref{eq:general-cdf-hypoexponential} also hold here.\nThus the proof is split into two parts, for \\(k=1\\) and \\(k=2\\).\n\n\n\n\\begin{itemize}\n    \\item \\(k = 2, l = 1\\)\n    \\begin{equation*}\n        \\begin{split}\n            LHS &= - \\frac{\\partial^{1-1}}{\\partial t^{1-1}} \n            \\left( \\prod_{j=0, j \\neq 2}^{2} (\\lambda_j + t)^{-r_j} \\right) \\\\\n            &=-\\left( (\\lambda_0 + t)^{-r_0} \\times (\\lambda_1 + t)^{-r_1} \\right) \\\\\n            &=-\\left( t^{-1} \\times (\\lambda_1 + t)^{-r_1} \\right) \\\\ \n            &= - \\frac{1}{t(t + \\lambda_1)^{r_1}} \\\\\n            & \\hspace{7cm} \\square\n        \\end{split}\n    \\end{equation*}\n    \\item \\(k = 1, l = 1, \\dots, r_1\\)\n    \\begin{equation*}\n        \\begin{split}\n            LHS &= -\\frac{\\partial^{l-1}}{\\partial t^{l-1}} \n            \\left( \\prod_{j=0, j \\neq 1}^{2} (\\lambda_j + t)^{-r_j} \\right) \\\\\n            &= -\\frac{\\partial^{l-1}}{\\partial t^{l-1}}\n            \\left( (\\lambda_o + t)^{-r_0} \\times (\\lambda_2 + t)^{-r_2} \\right) \\\\\n            &= -\\frac{\\partial^{l-1}}{\\partial t^{l-1}}\n            \\left( \\frac{1}{t(t + \\lambda_2)}\\right)\n        \\end{split}\n    \\end{equation*}\n    In essence, it only remains to show that \n    \\(-\\frac{\\partial^{l-1}}{\\partial t^{l-1}} \n    \\left( \\frac{1}{t(t + \\lambda_2)}\\right) = \\frac{(-1)^{l} (l-1)!}{\\lambda_2}\n    \\left[\\frac{1}{t^l} - \\frac{1}{(t + \\lambda_2)^l}\\right]\\).\n    \n    \\textbf{Proof by Induction:}\n    \\begin{enumerate}\n        \\item Base case (\\(l=1\\)):\n        \\begin{equation*}\n            \\begin{split}\n                LHS &= -\\frac{\\partial^{1-1}}{\\partial t^{1-1}} \n                \\left( \\frac{1}{t(t + \\lambda_2)}\\right) = \n                - \\frac{1}{t(t + \\lambda_2)} \\\\\n                RHS &= \\frac{(-1)^{1} (1-1)!}{\\lambda_2}\n                \\left[\\frac{1}{t^1} - \\frac{1}{(t + \\lambda_2)^1}\\right] \\\\\n                &= - \\frac{t + \\lambda_2 - t}{\\lambda_2 t (t + \\lambda_2)} \\\\\n                &= - \\frac{1}{t (t + \\lambda_2)} \\\\\n                LHS &= RHS\n            \\end{split}\n        \\end{equation*}\n        \\item Assume true for \\(l = x\\):\n        \\begin{equation*}\n            -\\frac{\\partial^{x-1}}{\\partial t^{x-1}} \n            \\left( \\frac{1}{t(t + \\lambda_2)}\\right) = \n            \\frac{(-1)^{x} (x-1)!}{\\lambda_2}\n            \\left[\\frac{1}{t^x} - \\frac{1}{(t + \\lambda_2)^x}\\right]\n        \\end{equation*}\n        \\item Prove true for \\(l = x + 1\\): \n        \\(\\Bigg( \\frac{\\partial^x}{\\partial t ^ x} \n        \\left( \\frac{-1}{t (t + \\lambda_2)} \\right) = \n        \\frac{(-1)^{x + 1} (x)!}{\\lambda_2}\n        \\left[\\frac{1}{t^{x+1}}-\\frac{1}{(t + \\lambda_2)^{x+1}}\\right] \\Bigg)\\)\n        \\begin{equation*}\n            \\begin{split}\n                LHS &= \\frac{\\partial}{\\partial t}\n                \\left[ \\frac{\\partial^{x-1}}{\\partial t ^ {x-1}} \n                \\left( \\frac{-1}{t (t + \\lambda_2)} \\right) \\right] \\\\\n                &= \\frac{\\partial}{\\partial t} \\left[\n                    \\frac{(-1)^x (x-1)!}{\\lambda_2} \\left(\n                        \\frac{1}{t^x} - \\frac{1}{(t + \\lambda_2)^x}\n                    \\right)\n                \\right] \\\\\n                &= \\frac{(-1)^x (x-1)!}{\\lambda_2} \\left(\n                    \\frac{(-x)}{t^{x+1}} - \\frac{(-x)}{(t + \\lambda_2)^x}\n                \\right) \\\\\n                &= \\frac{(-1)^x (x-1)! (-x)}{\\lambda_2} \\left(\n                    \\frac{1}{t^{x+1}} - \\frac{1}{(t + \\lambda_2)^x}\n                \\right) \\\\\n                &= \\frac{(-1)^{x+1} (x)!}{\\lambda_2} \\left(\n                    \\frac{1}{t^{x+1}} - \\frac{1}{(t + \\lambda_2)^x}\n                \\right) \\\\\n                & = RHS \\\\\n                & \\hspace{7cm} \\square\n            \\end{split}\n        \\end{equation*}\n    \\end{enumerate}\n\\end{itemize}\n\n\\subsubsection{Proportion within target for class 1 and class 2 individuals}\n\nGiven the two CDFs of the Erlang and Hypoexponential distributions a new \nfunction has to be defined to decide which one to use among the two.\nBased on the state of the model, there can be three scenarios when an individual\narrives.\n\\begin{enumerate}\n    \\item There is a free server and the individual does not have to wait\n    \\begin{equation*}\n        X_{(u,v)} \\sim Erlang(1, \\mu) \n    \\end{equation*}\n    \\item The individual arrives at a queue at the \\(n^{th}\\) position and the \n    model has \\(C > 1\\) servers\n    \\begin{equation*}\n        X_{(u,v)} \\sim Hypo((n, 1), (C \\mu, \\mu)) \n    \\end{equation*}\n    \\item The individual arrives at a queue at the \\(n^{th}\\) position and the \n    model has \\(C = 1\\) servers\n    \\begin{equation*}\n        X_{(u,v)} \\sim Erlang(n + 1, \\mu) \n    \\end{equation*}\n\\end{enumerate}\n\nNote here that for the first case \\(Erlang(1, \\mu)\\) is equivalent to \n\\(Exp(\\mu)\\). \nLet us define \\(X_{(u,v)}^{(1)}\\) the distribution of class 1 individuals and\n\\(X_{(u,v)}^{(2)}\\) the distribution of class 2 individuals, when arriving at \nstate \\((u,v)\\) of the model.\n\n\\begin{equation}\n    X_{(u,v)}^{(1)} \\sim \n    \\begin{cases}\n        \\textbf{Erlang}(v, \\mu), & \\textbf{if } C = 1 \\textbf{ and } v>1 \\\\\n        \\textbf{Hypo}\\left(\\vec{r}=(v - C, 1), \\vec{\\lambda}=(C \\mu, \\mu)\\right), \n            & \\textbf{if } C > 1 \\textbf{ and } v>C \\\\\n        \\textbf{Erlang}(1, \\mu), & \\textbf{if } v \\leq C\n    \\end{cases}\n\\end{equation}\n\n\\begin{equation}\n    X_{(u,v)}^{(2)} \\sim \n    \\begin{cases}\n        \\textbf{Erlang}(\\min(v, T), \\mu), & \\textbf{if } C = 1\n            \\textbf{ and } v, T > 1 \\\\\n        \\textbf{Hypo}\\left(\\vec{r}=(\\min(v, T) - C, 1), \\vec{\\lambda}=(C \\mu, \\mu)\\right), & \n            \\textbf{if } C > 1 \\textbf{ and } v, T  > C \\\\\n        \\textbf{Erlang}(1, \\mu), & \\textbf{if } v \\leq C \\textbf{ or } T \\leq C\n    \\end{cases}\n\\end{equation}\n\n\nEquations \\ref{eq:cdf-erlang} and \\ref{eq:specific-cdf-hypoexponential} can now\nbe used.\nTherefore, the probability that an individual arriving at a specific state is \nwithin a given time target \\(t\\) is given by the following formulas:\n\n\n\\begin{equation}\n    P(X_{(u,v)}^{(1)} < t) = \n    \\begin{cases}\n        1 - \\sum_{i=0}^{v-1} \\frac{1}{i!} e^{-\\mu t} (\\mu t)^i, \n            & \\textbf{if } C = 1 \\textbf{ and } v>1 \\\\\n        & \\\\\n        1 - (\\mu C)^{v-C} \\mu  \n            \\sum_{k=1}^{\\mid \\vec{r} \\mid} \\sum_{l=1}^{r_k}\n            \\frac{\\Psi_{k,l}(-\\lambda_k)t^{r_k - l} \n            e^{-\\lambda_k t}}{(r_k - l)! (l - 1)!},\n            & \\textbf{if } C > 1 \\textbf{ and } v > C \\\\\n        \\textbf{where } \\vec{r}=(v - C, 1) \\textbf{ and } \n            \\vec{\\lambda}=(C \\mu, \\mu) & \\\\\n        & \\\\\n        1 - e^{-\\mu t},  & \\textbf{if } v \\leq C\n    \\end{cases}\n\\end{equation}\n\n\n\\begin{equation}\n    P(X_{(u,v)}^{(2)} < t) = \n    \\begin{cases}\n        1 - \\sum_{i=0}^{\\min(v,T)-1} \\frac{1}{i!} e^{-\\mu t} (\\mu t)^i,  \n            & \\textbf{if } C = 1 \\textbf{ and } v, T > 1 \\\\\n        & \\\\\n        1 - (C \\mu ) ^ {\\min(v,T) - C} \\mu\n            \\sum_{k=1}^{\\mid \\vec{r} \\mid} \\sum_{l=1}^{r_k}\n            \\frac{\\Psi_{k,l}(-\\lambda_k)t^{r_k - l} \n            e^{-\\lambda_k t}}{(r_k - l)! (l - 1)!}, \n            & \\textbf{if } C > 1 \\textbf{ and } v, T  > C \\\\\n        \\textbf{where } \\vec{r}=(\\min(v, T) - C, 1) \\textbf{ and } \n            \\vec{\\lambda}=(C \\mu, \\mu) & \\\\\n        & \\\\\n        1 - e^{-\\mu t}, & \\textbf{if } v \\leq C \\textbf{ or } T \\leq C\n    \\end{cases}\n\\end{equation}\n\n\nIn addition the set of accepting states for class 1 (\\(S_A^{(1)}\\)) and class 2 \n(\\(S_A^{(2)}\\)) individuals defined in  (\\ref{eq:accepting_states_class_1}) and \n(\\ref{eq:accepting_states_class_2}) are also needed here.\nNote here that, \\(S\\) denotes the set of all states of the Markov chain model. \n\n\\begin{align*}\n    S_A^{(1)} &= \\{(u, v) \\in S \\; | \\; v < N \\} \\\\\n    S_A^{(2)} &=\n    \\begin{cases}\n        \\{(u, v) \\in S \\; | \\; u < M \\}, & \\textbf{if } T \\leq N \\\\\n        \\{(u, v) \\in S \\; | \\; v < N \\}, & \\textbf{otherwise}\n    \\end{cases}\n\\end{align*}\n\nHaving defined everything, it only remains to use a formula similar to the ones \nof equations \\ref{eq:recursive-waiting-time-others}, \n\\ref{eq:recursive-waiting-time-ambulance} and \n\\ref{eq:general-algebaric-approach-blocking-time}.\nThe following formula uses the state probability vector \\(\\pi\\) to get the \nweighted average of the probability below target of all states in the Markov\nmodel.\n\n\\begin{equation}\n    P(X^{(1)} < t) = \\frac{\\sum_{(u,v) \\in S_A^{(1)}} P(X_{u,v}^{(1)} < t) \n    \\pi_{u,v} }{\\sum_{(u,v) \\in S_A^{(1)}} \\pi_{u,v}}\n\\end{equation}\n\n\\begin{equation}\n    P(X^{(2)} < t) = \\frac{\\sum_{(u,v) \\in S_A^{(2)}} P(X_{u,v}^{(2)} < t) \n    \\pi_{u,v} }{\\sum_{(u,v) \\in S_A^{(2)}} \\pi_{u,v}}\n\\end{equation}\n\n\n\\subsubsection{Overall proportion within target}\n\nThe overall proportion of individuals for both class 1 and class 2 individuals\nis given by the equivalent formula of equations \n(\\ref{eq:overall_waiting_time_coeff}) and (\\ref{eq:overall_waiting_time}).\nThe following formula uses the probability of lost individuals from both classes\nto get the weighted sum of the two already existing probabilities.\n\n\\begin{equation*}\n    P(L'_1) = \\sum_{(u,v) \\, \\in S_A^{(1)}} \\pi(u,v), \\hspace{1.5cm}\n    P(L'_2) = \\sum_{(u,v) \\, \\in S_A^{(2)}} \\pi(u,v)\n\\end{equation*}\n\n\\begin{equation}\\label{eq:overall_proportion_within_target}\n    P(X < t)= \\frac{\\lambda_1 P(L'_1)}{\\lambda_2 P(L'_2)+\\lambda_1 P(L'_1)} \n    P(X^{(1)} < t) + \\frac{\\lambda_2 P(L'_2)}{\\lambda_2 P(L'_2) + \\lambda_1 \n    P(L'_1)} P(X^{(2)} < t)\n\\end{equation}\n\n\n", "meta": {"hexsha": "78843bfe2bef2c96c6bc22edcbe8d6e5cee34c15", "size": 44375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/main/MarkovChain/expressions_from_pi/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/expressions_from_pi/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/expressions_from_pi/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": 42.6272814601, "max_line_length": 93, "alphanum_fraction": 0.6253521127, "num_tokens": 14409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6091186869249542}}
{"text": "\\documentclass[a4paper, 12pt]{article}\n\n\\usepackage{graphicx}\n\n\\title{P-values behaving badly}\n\\author{Brendon J. Brewer}\n\n\\begin{document}\n\n\\maketitle\n\nCriticising P-values is a favorite pastime among Bayesians. No\n``counterexamples'' repository would be complete without it.\n\n\\section{{\\em Or} implies {\\em more}}\nI learned this example from Alex Etz ({\\tt http://alexanderetz.com/}).\nConsider two propositions, $A$ and $B$, which you are trying to reason about.\nIf you have some judgment about how plausible $A$ is, what would you think\nabout the proposition $A \\vee B$ (read $A$ {\\bf or} $B$), which would be true\nif either one of $A$ or $B$ is true (or both)? \n\nIn probability theory (i.e. Bayesian statistics), the sum rule relates the\nprobability of $A \\vee B$ to the probability of $A$ and the probability of\n$B$ like so:\n\\begin{eqnarray}\nP(A \\vee B | I) &=& P(A | I) + P(B | I) - P(A, B | I)\n\\end{eqnarray}\n\nFrom this, we can show\n\\begin{eqnarray}\nP(A \\vee B | I) &=& P(A | I) + P(B | I) - P(A, B | I)\\\\\n                &=& P(A | I) + P(B | I) - P(A | I)P(B | A, I)\\\\\n                &=& P(A | I)\\left[1 - P(B | A,I)\\right] + P(B | I)\\\\\n                &\\geq& P(B | I). \n\\end{eqnarray}\nTherefore the probability of $(A \\vee B)$ must be greater than or equal to\nthe probability of $B$. As a slogan, ``{\\em or} implies {\\em more}''.\n\nImagine a drug company has an old drug which is known to cure\n75\\% of patients of a disease. They are developing a new drug\nwhich they hope will be even more effective.\nThe effectiveness of the old drug is $\\theta_{\\rm old} = 0.6$ and the\neffectiveness of the new drug is $\\theta_{\\rm new}$, which is unknown.\nConsider three ``coarse-grained''\nhypotheses about the value of $\\theta_{\\rm new}$. The new drug's\neffectiveness could be worse than, equal to, or better than that of the old\ndrug:\n\n\\begin{equation}\n\\begin{array}{lcl}\nH_{\\rm worse}:  &  &\\theta_{\\rm new} < 0.6\\\\\nH_0:            &  &\\theta_{\\rm new} = 0.6\\\\\nH_{\\rm better}: &  &\\theta_{\\rm new} > 0.6\n\\end{array}\n\\end{equation}\n\nThe middle proposition, $H_0$,\nis the ``null hypothesis'' that the new drug and the\nold drug are identical in terms of effectiveness. Classical statistical tests\nare used to quantify the strength of the evidence against $H_0$. In reality,\nit's best to consider the full set of hypotheses about what the value of\n$\\theta_{\\rm new}$ might be, rather than boiling it down to these three\nscenarios. This is related to the idea\nthat ``statistical significance'' and ``practical significance'' are not the\nsame. For example, $\\theta_{\\rm new}$ could be 0.60002, which is\ntechnically ``better'' than the old drug, but not by an amount that's likely\nto matter.\n\nTo measure $\\theta_{\\rm new}$, the company tests the drug on $N=50$ patients\nand counts the number, $x$, who recover. The probability distribution for\n$x$ given $\\theta_{\\rm new}$ (and $N$) is Binomial(50, $\\theta_{\\rm new}$):\n\n\\begin{eqnarray}\np(x | \\theta_{\\rm new}) &=&\n\\left(\\begin{array}{cc}N \\\\ x\\end{array}\\right)\n\\theta_{\\rm new}^x \\left(1 - \\theta_{\\rm new}\\right)^{N - x}.\n\\end{eqnarray}\n\n\\begin{figure}[ht!]\n\\centering\n\\includegraphics[scale=0.5]{drug_example.pdf}\n\\caption{\\label{fig:drug_example}}\n\\end{figure}\n\nSuppose $x=37$ was observed.\n\\begin{eqnarray}\nP(x \\geq 37 | H_0) &=& 0.028\\\\\nP(x \\leq 23 | H_0) &=& 0.031.\n\\end{eqnarray}\n\nThe p-value is supposed to quantify evidence against $H_0$.\n\nCan we interpret it as something like {\\em how strongly we should believe in\n$H_0$?} Something like a posterior probability?\nAnd do we use the one sided p-value or the two sided?\n\n\\begin{eqnarray}\n\\left(H_0 \\vee H_{\\rm better}, \\textnormal{data}\\right) &\\Longrightarrow&\n\\textnormal{p-value} = 0.028\\\\\n\\left(H_{\\rm worse} \\vee H_0 \\vee H_{\\rm better}, \\textnormal{data}\\right) &\\Longrightarrow&\n\\textnormal{p-value} = 0.059.\n\\end{eqnarray}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "a5d8d45a2413b7a81f95bad6884d44815fd58ab1", "size": 3851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/p-values/ms.tex", "max_stars_repo_name": "eggplantbren/Counterexamples", "max_stars_repo_head_hexsha": "25623bcce7667eff6b41e2916a3dec7bd17289c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/p-values/ms.tex", "max_issues_repo_name": "eggplantbren/Counterexamples", "max_issues_repo_head_hexsha": "25623bcce7667eff6b41e2916a3dec7bd17289c8", "max_issues_repo_licenses": ["MIT"], "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/p-values/ms.tex", "max_forks_repo_name": "eggplantbren/Counterexamples", "max_forks_repo_head_hexsha": "25623bcce7667eff6b41e2916a3dec7bd17289c8", "max_forks_repo_licenses": ["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.9906542056, "max_line_length": 92, "alphanum_fraction": 0.6826798234, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.6090755700319109}}
{"text": "% !TEX root = index.tex\n\n\\section{Geometric Meaning of Curvature}\n\n\\subsection{Mean Curvature}\n  The Mean Curvature shows up in physics while studying soap films. At a point on a soap film the difference between the pressure on two sides is proportional to the mean curvature of the surface at that point. This is called the \\textbf{Young-Laplace equation}.\n  \\begin{align*}\n    \\Delta (\\mbox{pressure}) \\propto H\n  \\end{align*}\n  If the soap film does not bound a volume, for example, if it is bounded by a curve then the pressure on both the sides is the same and hence the mean curvature at every point must be 0. Such surfaces are called \\textbf{minimal surfaces}, minimal because these surfaces also have the minimal surface area of all the surfaces bounding the curve. The study of minimal surfaces is a very active area of research in geometry.\n  \\begin{figure}[H]\n    \\centering\n    \\begin{subfigure}[t]{0.495\\textwidth}\n      \\centering\n      \\includegraphics[width=6cm]{Minimal_Surface_1}\n    \\end{subfigure}\n    \\begin{subfigure}[t]{0.495\\textwidth}\n      \\centering\n      \\includegraphics[width=6cm]{Minimal_Surface_2}\n    \\end{subfigure}\n    \\caption{Examples of minimal surfaces. The Mean Curvature at \\emph{every} non-boundary point is 0 and hence at every point the surface looks like the perfect potato chip. Images from \\href{https://en.wikipedia.org/wiki/Minimal_surface}{Wikipedia}.}\n  \\end{figure}\n\n\\subsection{Gaussian Curvature}\n  The Gaussian Curvature is much more subtle and has several interpretations.\n\n  \\begin{definition}\n    For a surface $S$ the \\textbf{geodesic distance} $d_S(p,q)$ between two points $p,q \\in S$ is defined to be the shortest length of the curve on the surface $S$ that connects $p$ to $q$.\n  \\end{definition} For example, on a plane the geodesic distance is simply the Euclidean distance. On a sphere, the geodesic distance between two points is the length of the arc of the great circle connecting them.\n  \\begin{figure}[H]\n    \\centering\n      \\includegraphics[width=3cm]{great_circle}\n    \\caption{The geodesic distance between two points on a sphere is the length of the arc of the great circle connecting them. Image from \\href{https://en.wikipedia.org/wiki/Great-circle_distance}{Wikipedia}.}\n  \\end{figure}\n\n  \\begin{definition}\n    The \\textbf{geodesic ball} of radius $r$ centered at a point $p \\in S$ is the set of points which are at a geodesic distance of at the most $r$ from $p$\n    \\begin{align*}\n      B_r(p) := \\{ x \\in S : d_S(x,p) \\le r\\}\n    \\end{align*}\n  \\end{definition}\nWe'll assume the following theorem without proof.\n  \\begin{thm}\n    The Gaussian curvature of $S$ at $p$ equals\n    \\begin{align*}\n      K &= 3 \\lim \\limits_{r \\rightarrow 0} \\dfrac{2 \\pi r - \\mbox{length of } \\partial B_S(p,r) }{\\pi r^3}\n    \\end{align*}\n  \\end{thm}\n\\begin{cor}\n  \\label{thm:geodesics}\n  The Gaussian curvature can be computed by measuring distances on the surface (without knowing anything about the ambient space).\n\\end{cor}\nThis leads directly to the next theorem.\n\n  \\subsubsection{Theorema Egregium}\n  We can take a sheet of paper and roll into a cylinder without stretching or compressing the sheet.\\footnote{Neglect the \\emph{thickness} of the paper.} Such a map is called an \\textbf{isometry}.\n\n\n\n  \\begin{definition}\n    A smooth map $\\phi: S \\rightarrow S'$ is called an \\textbf{isometry} if\n    \\begin{align*}\n      d_S(p,q) = d_{S'}(\\phi(p),\\phi(q))\n    \\end{align*}for any two points $p,q \\in S$.\n  \\end{definition}\n  \\noindent The map that sends a plane to a cylinder is an example of such an isometry.\n  \\begin{thm}[Theorema Egregium]\n    \\label{thm:theorema}\n    If there exists an isometry $\\phi: S \\rightarrow S'$ between two surfaces then the Gaussian curvature of $S$ at $p \\in S$ equals the Gaussian curvature of $S'$ at $\\phi(p)$.\n  \\end{thm}\n  \\begin{proof}\n    This is a direct consequence of Corollary \\ref{thm:geodesics}. It is possible to measure the Gaussian curvature using only the geodesic distances and geodesic distances are preserved under isometry.\n  \\end{proof}\n  This theorem is interpreted as saying that the Gaussian curvature is \\emph{intrinsic} to a surface.\n\n\n\\subsubsection{Gauss Map}\n\\begin{figure}[H]\n  \\centering\n    \\includegraphics[width=8cm]{Gauss_map}\n  \\caption{The unit normal vector $\\vec n$ defines a map from the surface to the unit sphere $\\vec n : S \\rightarrow S^2$. Image from \\href{https://en.wikipedia.org/wiki/Gauss_map}{Wikipedia}.}\n\\end{figure}\nLet $\\vec n$ denote a continuously varying unit normal vector field on the surface $S$. There are two possibly choices for $\\vec n$, we just pick one. We can think of $\\vec n$ as a map, called the \\textbf{Gauss map} from $S$ to the unit sphere $S^2$. Then,\n\\begin{align*}\n  K &= \\lim \\limits_{r \\rightarrow 0} \\dfrac{\\mbox{area of } \\vec n (B_r(p)) }{\\mbox{area of } B_r(p) }\n\\end{align*}\n\n\\subsubsection{Gauss-Bonnet theorem}\nGaussian curvature has a topological significance as well. If $S$ is a closed surface then\n\\begin{thm}\n  The total Gaussian Curvature\n  \\begin{align*}\n    \\int \\limits_S K \\: dA = 2 \\pi \\chi(S)\n  \\end{align*}\n  where $\\chi(S)$ denotes the Euler characteristic of the surface.\n\\end{thm}\n\n\\subsection{Final Remarks}\nThe methods that we've described only define the various curvatures for \\emph{embedded} surfaces. In general, because the Gaussian curvature can be computed by measuring Geodesic distances it is possible to define the Gaussian curvature (but not the principal and mean curvatures) for manifolds with a metric (also called Riemannian manifold).\n", "meta": {"hexsha": "6cb2d4e49f7e6c89c6be6eac625562388e072e27", "size": 5558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04.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": "04.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": "04.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": 55.58, "max_line_length": 422, "alphanum_fraction": 0.7292191436, "num_tokens": 1549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.6090755455779979}}
{"text": "% MARKER: check positioning of the figures/tables and put float barriers and/or clearpages if needed\n\n\\section{Structural details of the subassembly}\n\\label{hier:details}\n\n\\begin{equation}\n\\label{eq:EBMjoint}\nEBM_{v,j} = \\frac{V_{jh}}{\\frac{1}{jd}-\\frac{l_{b}}{l_{c}l_{b}^{'}}} = \\frac{365(699.5)}{\\frac{1}{0.628}-\\frac{3.4}{3.05*3.17}} = 294.2 kNm (563.8kN \\ Pull)\n\\end{equation}\n", "meta": {"hexsha": "716771f580ca4e41b2da4cb471f47a2eca38dad5", "size": 381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendixA/hierarchy.tex", "max_stars_repo_name": "robgen/latexDicatech", "max_stars_repo_head_hexsha": "7bf884a9052fc7f64d9ff087c2c6027ca15a1963", "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": "appendixA/hierarchy.tex", "max_issues_repo_name": "robgen/latexDicatech", "max_issues_repo_head_hexsha": "7bf884a9052fc7f64d9ff087c2c6027ca15a1963", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-04T11:58:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-04T11:58:30.000Z", "max_forks_repo_path": "appendixA/hierarchy.tex", "max_forks_repo_name": "robgen/latexDicatech", "max_forks_repo_head_hexsha": "7bf884a9052fc7f64d9ff087c2c6027ca15a1963", "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.1, "max_line_length": 156, "alphanum_fraction": 0.6824146982, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6090755407112945}}
{"text": "%%============================\n%% Appendix 4: List of Symbols\n%%============================\n\n\\documentclass[../dissertation.tex]{subfiles}\n\n\\begin{document}\n\n\n%%=====================\n%% Fundamental Notation\n%%=====================\n\\def\\tabletitle{Fundamental Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t$:=$ & defined to be; for example $a := b$ means ``$a$ is defined to be \n\t\t\t$b$''\n\t\t\t& p.\\pageref{sym0:def} \\\\\n\t\t$\\pv$ & Cauchy principle value; given by \n\t\t\t{\n\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\\pv\\int_{\\mathbb R} f(x) \\, \\mathrm{d}x\n\t\t\t\t\t\t:= \\lim_{\\varepsilon \\searrow 0} \\int_{|x|>\\varepsilon} f(x) \\, \\mathrm{d}x\n\t\t\t\t\\end{teqn}\n\t\t\t}\n\t\t\t& p.\\pageref{sym0:pv} \\\\\n\t\t\\textit{a.e.} & abbreviation for almost everywhere & p.\\pageref{sym:ae}\\\\\n\t\t$\\mathbb R$ & the set of all real numbers & p.\\pageref{sym:Reals} \\\\\n\t\t$\\mathbb C$ & the set of all complex numbers & p.\\pageref{sym:Complex} \\\\\n\t\t$\\mathbb Z$ & the set of all integers &  \\\\\n\t\t$\\chi_A$ & characteristic function on a set $A$; given by \n\t\t\t\t{\\begin{teqn}\n\t\t\t\t\t\\chi_A(x) := \n\t\t\t\t\t\t\\begin{cases}\n\t\t\t\t\t\t\t1, & x \\in A \\\\\n\t\t\t\t\t\t\t0, & \\text{otherwise}\n\t\t\t\t\t\t\\end{cases}\n\t\t\t\t\\end{teqn}}\n\t\t\t& p.\\pageref{sym:chi} \\\\\n\t\t$m(\\dotarg)$ & Lebesgue measure on $\\mathbb R$ & p.\\pageref{sym:lebesguemeasure} \\\\\n\t\t$\\mathcal F$, $\\hat{(\\dotarg)}$ & Fourier transform defined as \n\t\t\t\\begin{teqn}\n\t\t\t\t\\hat f(\\xi)\n\t\t\t\t\t\t:= \\(\\mathcal F f\\)(\\xi)\n\t\t\t\t\t\t= \\int_{\\mathbb R} e^{-i x \\xi} f(x) \\, \\mathrm{d}x\n\t\t\t\\end{teqn}\n\t\t\t\t& p.\\pageref{sym:fourier} \\\\[-1\\baselineskip]\n\t\t$\\mathcal F^{-1}$, $\\check{(\\dotarg)}$ & inverse Fourier transform defined \n\t\t\tas\n\t\t\t\\begin{teqn}\n\t\t\t\t\t\\check g(x)\n\t\t\t\t\t\t:= \\(\\mathcal F^{-1}g\\)(x)\n\t\t\t\t\t\t= \\frac{1}{2 \\pi} \\int_{\\mathbb R} e^{i x \\xi} g(\\xi) \\, \\mathrm{d}\\xi\n\t\t\t\\end{teqn}\n\t\t\t& p.\\pageref{sym:fourier} \\\\\n\t\t$\\mathscr S(\\mathbb R)$ & space of all Schwartz class functions on $\\mathbb R$\n\t\t\t& p.\\pageref{sym3:schwartz} \\\\\n\t\t$\\Res_{z=c}f$ & complex residue of a function $f$ at the pole $z = c$\n\t\t\t& p.\\pageref{sym1:res} \\\\\n\t\t$(\\dotarg\\pm i0)$ & implied limit of $(\\dotarg \\pm i \\varepsilon)$ as \n\t\t\t\t$\\varepsilon \\searrow 0$ \n\t\t\t& p.\\pageref{sym:i0} \\\\\n\t\t$f^+$ & lower boundary $f^+(x) := \n\t\t\t\t\\lim_{y\\searrow0} f(x+ i y)$ of a function $f$ analytic on $S_\\delta$,\n\t\t\t\twhere $x, y \\in \\mathbb R$ \n\t\t\t& p.\\pageref{sym:bndries} \\\\\n\t\t$f^-$ & upper boundary $f^-(x) := \\lim_{y\\nearrow0} f(x+ i 2y)$ of a \n\t\t\t\tfunction $f$ analytic on $S_\\delta$, where $x, y \\in \\mathbb R$\n\t\t\t& p.\\pageref{sym:bndries} \\\\\n\t\t$\\lesssim$ & $q \\lesssim s$ means there exists some fixed constant $C$ so \n\t\t\t\tthat $q \\leq C\\,s$; the constant $C$ is commonly referred to as \n\t\t\t\t``the implied constant'' & p.\\pageref{sym:lesssim} \\\\\n\t\t$\\lesssim_k$ & $q \\lesssim s$ means there exists some constant\n\t\t\t\t$C := C(k)$ depending only on the parameter $k$ so that\n\t\t\t\t$q \\leq C \\, s$; the constant $C$ is commonly referred as ``the \n\t\t\t\timplied constant''  \n\t\t\t& p.\\pageref{sym2:lesssimdep} \\\\\n\t\t$\\log_+ t$ & the function given by $\\max\\big\\{ 0, \\, \\log(t) \\big\\}$\n\t\t\t& p.\\pageref{sym:logplus} \\\\\n\t\t$\\inn{x}$ & short-hand notation for $\\big(1 + |x|^2\\big)^{1/2}$\n\t\t\t& p.\\pageref{sym:xbracket} \\\\\n\t\t$L^{p,s}(\\mathbb R)$ & space of measurable functions with \n\t\t\t\\begin{teqn}\n\t\t\t\t\\|f\\|_{L^{p,s}}\n\t\t\t\t\t:= \\left(\\int_{\\mathbb R} \\inn{x}^{sp} |f(x)|^p \\right)^{1/p}\n\t\t\t\t\t< \\infty\n\t\t\t\\end{teqn}\n\t\t\t& p.\\pageref{defn2:Lps} \\\\\n\t\t$\\langle\\dotarg\\rangle L^\\infty(\\mathbb R)$ & space of measurable functions with \n\t\t\t\\[\n\t\t\t\t\\|f\\|_{\\inn{\\dotarg} L^\\infty}\n\t\t\t\t\t:= \\esssup_{x\\in \\mathbb R} \\left| \\inn{x}^{-1} f(x)  \\right|\n\t\t\t\t\t< \\infty\n\t\t\t\\]\n\t\t\t& p.\\pageref{defn2:wLp} \\\\\n\t\t$B_Y(y_0, r)$ & the open ball $\\{ y \\in Y ~:~ \\|y - y_0\\|_Y < r  \\}$ in \n\t\t\tthe metric space $Y$ with radius $r$ centered at $y_0 \\in Y$\n\t\t\t& p.\\pageref{sym:ball} \\\\\n\t\t$Y\\to Z$ & a map from a space $Y$ to a space $Z$\n\t\t\t& p.\\pageref{sym:mapsto} \\\\\n\t\t$Y \\toitself$ & a map from a space $Y$ into itself\n\t\t\t& p.\\pageref{sym:toitself} \\\\\n\t\t$\\|\\dotarg\\|_{Y\\to Z}$ & the induced operator norm for an operator with domain \n\t\t\t$Y$ and co-domain $Z$\n\t\t\t& p.\\pageref{sym:opnorm}\n\\end{indextable}\n\n\n\\newpage\n\n%===================\n% Chapter 1 Notation\n%===================\n\\def\\tabletitle{Chapter 1 Notation}\n% \\def\\tabletitle{Chapter 0 Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t$\\delta$ & depth of stratified fluids\\textemdash{}typically taken \n\t\t\tto be $\\delta=1$ \n\t\t& p.\\pageref{sym:delta} \\\\\n\t$\\mathcal S_\\delta$ & the complex strip\n\t\t\t$\\{z \\in \\mathbb C ~:~ 0 < \\im z < 2\\delta\\}$ \n\t\t& p.\\pageref{sym:Sdelta} \\\\\n\t$f^+$ & lower boundary $f^+(x) := \n\t\t\t\\lim_{y\\searrow0} f(x+ i y)$ of a function $f$ analytic on \n\t\t\t$\\mathcal S_\\delta$,\n\t\t\twhere $x, y \\in \\mathbb R$ \n\t\t& p.\\pageref{sym:bndries} \\\\\n\t$f^-$ & upper boundary $f^-(x) := \\lim_{y\\nearrow0} f(x+ i 2y)$ of a \n\t\t\tfunction $f$ analytic on $\\mathcal S_\\delta$, where $x, y \\in \\mathbb R$\n\t\t& p.\\pageref{sym:bndries} \\\\\n\t$L_\\delta$ & operator on functions analytic in the complex strip \n\t\t$\\mathcal S_\\delta$; given by \n\t\t{\n\t\t\t\\begin{teqn}\n\t\t\t\tL_\\delta (\\Psi) \n\t\t\t\t\t:= \\frac{1}{i} \\frac{\\partial}{\\partial x} \\Psi^+ \n\t\t\t\t\t- \\zeta \\left(\\Psi^+ - \\Psi^-\\right) = u \\Psi^+\n\t\t\t\\end{teqn}\n\t\t}\n\t\t& p.\\pageref{eq0:SpecProb} \\\\\n\t$\\lambda$ & a spectral parameter for the linear spectral problem \n\t\t\t\\eqref{eq0:SpecProb} \n\t\t& p.\\pageref{sym:zeta} \\\\\n\t$\\zeta$ & a spectral parameter for \\eqref{eq0:SpecProb} commonly\n\t\t\tparameterized by $\\lambda$\tas \n\t\t\t$\\displaystyle \\zeta(\\lambda; \\delta) \n\t\t\t\t= \\frac{\\lambda}{1-e^{-2\\delta\\lambda}}$ \n\t\t& p.\\pageref{sym:zeta} \\\\\n\t$\\lambda(\\zeta)$ &  inverse of the map $\\lambda \\to \\zeta(\\lambda)$ \n\t\t& p.\\pageref{sym:lambda} \\\\\n\t$\\inn{x}$ & short-hand notation for $\\big(1 + |x|^2\\big)^{1/2}$\n\t\t& p.\\pageref{sym:xbracket} \\\\\n\t$B_Y(y_0, r)$ & the open ball $\\{ y \\in Y ~:~ \\|y - y_0\\|_Y < r  \\}$ in \n\t\tthe metric space $Y$ with radius $r$ centered at $y_0 \\in Y$\n\t\t& p.\\pageref{sym:ball} \\\\\t\n\t$M_1$, $M_e$, $N_1$, $N_e$ & depending on context, either Jost solutions \n\t\tor analytic extensions of solutions to the integral equations\n\t\t\\eqref{eq0:JostIE}\n\t\t& p.\\pageref{defn0:jost}, p.\\pageref{eq0:JostIE} \\\\\n\t$M_1^+$, $M_e^+$, $N_1^+$, $N_e^+$ & depending on context, either solutions\n\t\tto the integral equations \\eqref{eq0:JostIE} or lower boundary \n\t\tvalues of the Jost solutions\n\t\t& p.\\pageref{eq0:JostIE}, p.\\pageref{defn0:jost} \\\\\n\t$r(\\lambda; \\delta)$ & reflection coefficent; given by\n\t\t{\n\t\t\t\\begin{teqn}\n\t\t\t\tr(\\lambda; \\delta) = \\frac{b(\\lambda; \\delta)}{a(\\lambda; \\delta)},\n\t\t\t\\end{teqn}\n\t\t\twhere\n\t\t\t\\begin{talign}\n\t\t\t\tb(\\lambda)\n\t\t\t\t&:= \n\t\t\t\t\t\\frac{i}{1-2\\delta\\zeta(-\\lambda)} \n\t\t\t\t\t\\int_{\\mathbb R} e^{-i\\lambda x} \n\t\t\t\t\t\tu(x) \\, M_1^+(x; \\lambda,\\delta) \n\t\t\t\t\t\\, \\mathrm{d}x\n\t\t\t\t\t\\\\\n\t\t\ta(\\lambda)\n\t\t\t\t&:=\n\t\t\t\t\t1 \n\t\t\t\t\t+ \\frac{i}{1-2\\delta \\zeta(\\lambda)}\n\t\t\t\t\t\t\\int_{\\mathbb R} \n\t\t\t\t\t\t\tu(x) \\, M_1^+(x; \\lambda,\\delta) \n\t\t\t\t\t\t\\, \\mathrm{d}x\n\t\t\t\\end{talign}\n\t\t} \n\t\t& p.\\pageref{sym0:reflection} \\\\\n\t$\\mathscr D$ & the direct scattering map for the Intermediate Long Wave (ILW) equation; maps\n\t\tILW initial data $u$ to the corresponding reflection coefficient $r$\n\t\t& p.\\pageref{sym0:DSM} \\\\\n\t$G_L$, $G_R$ & formal Green's functions corresponding to the linear spectral problem \n\t\t\\eqref{eq0:SpecProb}\n\t\t& p.\\pageref{eq0:GFL},  p.\\pageref{eq0:GFR}\\\\\n\t$\\alpha(\\lambda; \\delta)$ & residue of $e^{iz\\xi}/p(\\xi)$ at the $\\xi=0$\n\t\tpole; given by \n\t\t\\begin{teqn}\n\t\t\t\\alpha(\\lambda; \\delta)\n\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(\\lambda; \\delta)}\n\t\t\\end{teqn}\n\t\t& p.\\pageref{sym0:residues} \\\\\n\t$\\beta(\\lambda; \\delta)$ & $e^{iz\\lambda}$ times the residue of \n\t\t$e^{iz\\xi}/p(\\xi)$ at the $\\xi=\\lambda$ pole; given by \n\t\t\\begin{teqn}\n\t\t\t\\alpha(\\lambda; \\delta)\n\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(-\\lambda; \\delta)}\n\t\t\\end{teqn}\n\t\t& p.\\pageref{sym0:residues} \\\\\n\t$K^+$ & non-residue term resulting from shifting the integration contours of \n\t\t$G_L^+$ and $G_R^+$\n\t\t& p.\\pageref{sym0:K} \\\\\n\t$T_{\\star, \\lambda, u}$ & bounded operators on \n\t\t$\\inn{\\dotarg}L^\\infty(\\mathbb R)$ given by\n\t\t\\begin{teqn}\n\t\t\tT_{\\star, \\lambda, u} f(x) \n\t\t\t\t:= \\big[ G_\\star^+(\\dotarg; \\lambda) \\big] * (u\\,f)(x),\n\t\t\\end{teqn}\n\t\twhere $\\star = L$ or $R$\n\t\t& p.\\pageref{eq0:Tstar}\n\\end{indextable}\n\n\n\\newpage\n%===================\n% Chapter 2 Notation\n%===================\n\\def\\tabletitle{Chapter 2 Notation}\n% \\def\\tabletitle{Chapter 1 Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t\t$\\mathscr D$ & the direct scattering map for the Intermediate Long Wave (ILW) equation; maps\n\t\t\tILW initial data $u$ to the corresponding reflection coefficient $r$\n\t\t\t& p.\\pageref{sym0:DSM} \\\\\n\t\t$\\star$ & used as a placeholder for both $L$ and $R$; for example, if a \n\t\t\tstatement contains the notation \n\t\t\t``$G_\\star$ ($\\star = L \\text{, or } R$),'' then it is equally \n\t\t\ttrue (or not true) for both $G_L$ and $G_R$\n\t\t\t& p.\\pageref{rmk1:StarNotation} \\\\\n\t\t$f^+$ & lower boundary $f^+(x) := \n\t\t\t\t\\lim_{y\\searrow0} f(x+ i y)$ of a function $f$ analytic on $S_\\delta$,\n\t\t\t\twhere $x, y \\in \\mathbb R$ \n\t\t\t& p.\\pageref{sym:bndries} \\\\\n\t\t$f^-$ & upper boundary $f^-(x) := \\lim_{y\\nearrow0} f(x+ i 2y)$ of a \n\t\t\t\tfunction $f$ analytic on $S_\\delta$, where $x, y \\in \\mathbb R$\n\t\t\t& p.\\pageref{sym:bndries} \\\\\n\t\t$\\delta$ & depth of stratified fluids\\textemdash{}typically taken \n\t\t\t\tto be $\\delta=1$ \n\t\t\t& p.\\pageref{sym:delta} \\\\\n\t\t$\\lambda$ & a spectral parameter for the linear spectral problem \n\t\t\t\t\\eqref{eq0:SpecProb} \n\t\t\t& p.\\pageref{sym:zeta} \\\\\n\t\t$\\zeta$ & a spectral parameter for \\eqref{eq0:SpecProb} commonly\n\t\t\t\tparameterized by $\\lambda$\tas \n\t\t\t\t$\\displaystyle \\zeta(\\lambda; \\delta) \n\t\t\t\t\t= \\frac{\\lambda}{1-e^{-2\\delta\\lambda}}$ \n\t\t\t& p.\\pageref{sym:zeta} \\\\\n\t\t$\\lambda(\\zeta)$ &  inverse of the map $\\lambda \\to \\zeta(\\lambda)$ \n\t\t\t& p.\\pageref{sym:lambda} \\\\\n\t\t$\\zeta^*$ & nonlinear reflection $\\zeta\\big(-\\lambda(\\zeta)\\big)$ \n\t\t\t& p.\\pageref{sym:zetastar} \\\\\n\t\t$G_\\star^+$ & lower boundary value of the Greens' function whose contour\n\t\t\tof integration is $\\Gamma_\\star$; given by \n\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\tG_\\star^+(x; \\lambda, \\delta)\n\t\t\t\t\t\t\t:=\n\t\t\t\t\t\t\t\t\\frac{1}{2\\pi} \n\t\t\t\t\t\t\t\t\\int_{\\Gamma_\\star}\n\t\t\t\t\t\t\t\t\te^{i x \\xi} \\,\n\t\t\t\t\t\t\t\t\t\\frac{1}{p(\\xi; \\lambda, \\delta)}\n\t\t\t\t\t\t\t\t\\, \\mathrm{d}\\xi\n\t\t\t\t\t\\end{teqn}\n\t\t\t& p.\\pageref{sym:GFbndry} \\\\\n\t\t${\\Gamma_L}$ & contour along the real line which bypasses the roots of $p$\n\t\t\t\tfrom below\n\t\t\t& p.\\pageref{sym:Gamma} \\\\\n\t\t${\\Gamma_R}$ & contour along the real line which bypasses the roots of $p$\n\t\t\t\tfrom above\n\t\t\t& p.\\pageref{sym:Gamma} \\\\\n\t\t$p$ & Fourier symbol of the Green's functions; \n\t\t\t\tgiven by\n\t\t\t\t\\[\n\t\t\t\t\tp(\\xi; \\lambda, \\delta)\n\t\t\t\t\t\t= \\xi - \\zeta(\\lambda) \\( 1- e^{-2\\delta \\xi} \\)\n\t\t\t\t\\]\n\t\t\t\tand commonly denoted as $p(\\xi; \\lambda, \\delta)$, \n\t\t\t\t$p(\\xi; \\zeta, \\delta)$, $p(\\xi; \\lambda)$, \n\t\t\t\t$p(\\xi; \\zeta)$, and $p(\\xi)$.\n\t\t\t& p.\\pageref{sym:GFintegrand} \\\\\n\t\t$\\Res_{z=c}f$ & complex residue of a function $f$ at the pole $z = c$\n\t\t\t& p.\\pageref{sym1:res} \\\\\n\t\t$\\alpha(\\lambda; \\delta)$ & residue of $e^{iz\\xi}/p(\\xi)$ at the $\\xi=0$\n\t\t\tpole; given by \n\t\t\t{\\begin{teqn}\n\t\t\t\t\\alpha(\\lambda; \\delta)\n\t\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(\\lambda; \\delta)}\n\t\t\t\\end{teqn}}\n\t\t\t& p.\\pageref{sym:alphabeta} \\\\\n\t\t$\\beta(\\lambda; \\delta)$ & $e^{iz\\lambda}$ times the residue of \n\t\t\t$e^{iz\\xi}/p(\\xi)$ at the $\\xi=\\lambda$ pole; given by \n\t\t\t{\\begin{teqn}\n\t\t\t\t\\beta(\\lambda; \\delta)\n\t\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(-\\lambda; \\delta)}\n\t\t\t\\end{teqn}}\n\t\t\t& p.\\pageref{sym:alphabeta} \\\\\n\t\t$K^+$ & non-residue term resulting from shifting the integration contours of \n\t\t\t$G_L^+$ and $G_R^+$\n\t\t\t& p.\\pageref{sym1:K} \\\\\n\t\t$\\log_+ t$ & the function given by $\\max\\big\\{ 0, \\, \\log(t) \\big\\}$\n\t\t\t& p.\\pageref{sym:logplus} \\\\\n\t\t$\\mathcal R_\\delta$ & the complex strip \n\t\t\t\t$\\{z \\in \\mathbb C ~:~ -\\pi/\\delta \\leq \\im z \\leq \\pi/\\delta \\}$\n\t\t\t\tabout the real line\n\t\t\t\t% about the real axis given by\n\t\t\t\t% \t\\begin{teqn}\n\t\t\t\t% \t\t:= \\{z \\in \\mathbb C ~:~ -\\pi/\\delta \\leq \\im z \\leq \\pi/\\delta \\}\t\n\t\t\t\t% \t\\end{teqn}\n\t\t\t& p.\\pageref{sym1:Rcal} \\\\\n\t\t$\\mathpzc R_\\star$ & sum residues of $e^{iz\\xi}/p(\\xi)$ at the $\\xi=0$ and $\\xi=\\lambda$ \n\t\t\t\tpoles \n\t\t\t& p.\\pageref{sym1:ressum} \\\\\n\t\t$\\delta_c$ & Dirac delta-function centered at $x=c$ \n\t\t\t& p.\\pageref{sym:dirac} \\\\\n\t\t$W_k$ & $k^{th}$ branch ($k \\in \\mathbb Z$) of the complex Lambert $W$ function\n\t\t\t& p.\\pageref{sym1:Wk} \\\\\n\t\t$\\Sigma_{c}$ & the integration contour\n\t\t\t\t$\\mathbb R + i c \\, \\pi$\n\t\t\t& p.\\pageref{sym1:SigRealLine} \\\\\n\t\t$\\Sigma(R,~c)$ & the integration contour $(-R, R) + i c \\,\\pi$,\n\t\t\t\twhere $R > 0$ and $(-R, R):= \\{x \\in \\mathbb R ~:~ -R < x < R\\}$\n\t\t\t& p.\\pageref{sym1:SigR} \\\\\n\t\t$K_\\zeta$ & the integral function given by \n\t\t\t\t{\n\t\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\tK_\\zeta(x) \n\t\t\t\t\t\t\t:= \\int_{\\mathbb R} \n\t\t\t\t\t\t\t\t\\frac{e^{ix \\xi}}{\\xi - \\zeta\\left(1-e^{-2\\xi}\\right)+i\\pi}\n\t\t\t\t\t\t\t\\, \\mathrm{d}\\xi\n\t\t\t\t\t\\end{teqn}\n\t\t\t\t}\n\t\t\t& p.\\pageref{sym1:Kzeta} \\\\\n\t\t$K_q$ & the integral function given by \n\t\t\t\t{\n\t\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\tK_q(x) \n\t\t\t\t\t\t\t:= \\int_{\\mathbb R} \n\t\t\t\t\t\t\t\t\\frac{e^{ix\\xi} \\chi\\left( 2^{-q} x \\xi\\right)}\n\t\t\t\t\t\t\t\t\t{\\xi - \\zeta\\left(1-e^{-2\\xi}\\right)+i\\pi}\n\t\t\t\t\t\t\t\\, \\mathrm{d}\\xi\n\t\t\t\t\t\\end{teqn}\n\t\t\t\t}\n\t\t\t& p.\\pageref{sym1:Kq} \\\\\n\\end{indextable}\n\n\n\n\\newpage\n%===================\n% Chapter 3 Notation\n%===================\n\\def\\tabletitle{Chapter 3 Notation}\n% \\def\\tabletitle{Chapter 2 Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t\t$\\inn{x}$ & short-hand notation for $\\big(1 + |x|^2\\big)^{1/2}$\n\t\t\t& p.\\pageref{sym2:xbracket} \\\\\n\t\t$L^{p,s}(\\mathbb R)$ & space of measurable functions with \n\t\t\t\t\\[\n\t\t\t\t\t\\|f\\|_{L^{p,s}}\n\t\t\t\t\t\t:= \\left(\\int_{\\mathbb R} \\inn{x}^{sp} |f(x)|^p \\right)^{1/p}\n\t\t\t\t\t\t< \\infty\n\t\t\t\t\\]\n\t\t\t& p.\\pageref{defn2:Lps} \\\\\n\t\t$\\langle\\dotarg\\rangle L^\\infty(\\mathbb R)$ & space of measurable functions with \n\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\\|f\\|_{\\inn{\\dotarg} L^\\infty}\n\t\t\t\t\t\t:= \\esssup_{x\\in \\mathbb R} \\left| \\inn{x}^{-1} f(x)  \\right|\n\t\t\t\t\\end{teqn}\n\t\t\t\tfinite\n\t\t\t& p.\\pageref{defn2:wLp} \\\\\n\t\t$L_\\xi^p(\\mathbb R)$ & space of measurable functions which are $L^p$ integrable\n\t\t\t\twith respect to the variable $\\xi$; similar subscript notation\n\t\t\t\tis used for other function spaces\n\t\t\t& p.\\pageref{sym2:Lpxi} \\\\\n\t\t$\\star$ & used as a placeholder for both $L$ and $R$; for example, if a \n\t\t\t\tstatement contains the notation \n\t\t\t\t``$G_\\star$ ($\\star = L \\text{, or } R$),'' then it is equally \n\t\t\t\ttrue (or not true) for both $G_L$ and $G_R$\n\t\t\t& p.\\pageref{rmk1:StarNotation} \\\\\n\t\t$T_{\\star, \\lambda, u}$ & bounded operator on \n\t\t\t\t$\\inn{\\dotarg}L^\\infty(\\mathbb R)$ given by\n\t\t\t\t{\n\t\t\t\t\\begin{teqn}\n\t\t\t\t\tT_{\\star, \\lambda, u} f(x) \n\t\t\t\t\t\t:= \\big[ G_\\star^+(\\dotarg; \\lambda) \\big] * (u\\,f)(x)\n\t\t\t\t\\end{teqn}\n\t\t\t\t}\n\t\t\t\tbased on context, $T_{\\star, \\lambda, u}$ is sometimes denoted \n\t\t\t\tby $T_\\star$, $T_{\\star, \\lambda}$, or $T_\\lambda$\n\t\t\t& p.\\pageref{eqn2:Tdefn} \\\\\n\t\t$X$ & space of potentials $u$ with $\\nm{\\inn{\\dotarg}^{4} u}_{L^2} < \\infty$\n\t\t\t& p.\\pageref{defn2:X} \\\\\n\t\t$\\lesssim_k$ & $q \\lesssim s$ means there exists some constant\n\t\t\t\t$C := C(k)$ depending only on the parameter $k$ so that\n\t\t\t\t$q \\leq C \\, s$; the constant $C$ is commonly referred as ``the \n\t\t\t\timplied constant''  \n\t\t\t& p.\\pageref{sym2:lesssimdep} \\\\\n\t\t$\\chi_\\pm$ & the characteristic functions $\\chi_-:= \\chi_{(-\\infty, 0)}$, \n\t\t\t\t$\\chi_+:= \\chi_{(0, \\infty)}$ on the respective intervals\n\t\t\t\t$(-\\infty, 0)$ and $(0, \\infty)$\n\t\t\t& p.\\pageref{sym2:chipm} \\\\\n\t\t$G$ & as specified in Remark \\ref{rmk2:notation}, $G(x,\\lambda)$ \n\t\t\t\tand $G(\\lambda)$ are occasionally used to as shorthand \n\t\t\t\tnotations for $G_\\star^+(x; \\lambda)$\n\t\t\t& p.\\pageref{rmk2:notation} \\\\\n\t\t$G_h(\\lambda)$ & the difference quotient of $G_\\star^+$ with respect to \n\t\t\t\t$\\lambda$; given by \n\t\t\t\t\\begin{teqn}\n\t\t\t\t\tG_h(\\lambda) := \\frac{G(\\lambda+h) - G(\\lambda)}{h}\n\t\t\t\t\\end{teqn}\n\t\t\t& p.\\pageref{sym2:Gh} \\\\\n\t\t$\\ds\\left(\\frac{1}{p_\\lambda(\\xi)}\\right)_{h}$\n\t\t\t& the difference quotient of $1/p$ with respect to $\\lambda$;\n\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\\left(\\frac{1}{p_\\lambda(\\xi)}\\right)_{h}\n\t\t\t\t\t\t:= \\frac{1}{h}\\,\n\t\t\t\t\t\t\t\\left[\n\t\t\t\t\t\t\t\t\\frac{1}{p(\\xi; \\lambda +h)}\n\t\t\t\t\t\t\t\t-\\frac{1}{p(\\xi; \\lambda)}\n\t\t\t\t\t\t\t\\right]\n\t\t\t\t\\end{teqn}\n\t\t\t& p.\\pageref{sym2:pdiffquot} \\\\\n\t\t$\\Res_{z=c}f$ & complex residue of a function $f$ at the pole $z = c$\n\t\t\t& p.\\pageref{eq2:gzerores}\n\\end{indextable}\n\n\\newpage\n\n\n%===================\n% Chapter 4 Notation\n%===================\n\\def\\tabletitle{Chapter 4 Notation}\n% \\def\\tabletitle{Chapter 3 Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t$\\mathcal S_\\delta$ & the complex strip about the real axis defined by\n\t\t\t$\\mathcal S_1 := \\{z \\in \\mathbb C ~:~ 0 < \\im z < 2 \\}$\n\t\t& p.\\pageref{thm3:main_result} \\\\\n\t$G_\\star$ & analytic continuation of $G_\\star^+$ to the analytic \n\t\t\tstrip $\\mathcal S_1$\n\t\t& p.\\pageref{thm3:main_result} \\\\\n\t$G_\\star^-$ & the upper boundary value of $G_\\star$ defined as a \n\t\t\tdistribution in that\n\t\t\t\\begin{teqn}\n\t\t\t\tG_\\star^- * f = \\lim_{y\\nearrow 2} G_\\star^+(\\dotarg+iy)*f\n\t\t\t\\end{teqn}\n\t\t\tfor $f \\in L^1(\\mathbb R) \\cap L^p(\\mathbb R)$ ($1< p \\leq 2$)\n\t\t& p.\\pageref{eq3:lim} \\\\\n\t$K$ & analytic continuation of $K^+$ to the $\\mathcal S_1$\n\t\t& p.\\pageref{thm3:main_result} \\\\\n\t$\\mathfrak C$ & a portion of $K$ whose limit as $y\\nearrow 2$ is \n\t\t\ta continuous limit operator; given by \n\t\t\t\\begin{teqn}\n\t\t\t\t\\mathfrak C(x,y)\n\t\t\t\t\t:= \\frac{1}{2\\pi} e^{-\\pi|x|} \\, e^{- \\sign(x) \\, i \\pi y }\n\t\t\t\t\t\t\\int_{\\mathbb R} e^{ix \\xi} \\rho\\big(\\xi, y, \\sign(x)\\big) \\, \\mathrm{d}\\xi,\n\t\t\t\\end{teqn}\n\t\t\twhere $x \\in \\mathbb R$ and $y\\in [0, 2]$\n\t\t& p.\\pageref{sym:mathfrakC} \\\\\n\t$\\rho$ & a function given by \n\t\t\t{\n\t\t\t\t\\begin{teqn}\n\t\t\t\t\t\\rho\\big(\\xi, y, c; \\lambda\\big)\n\t\t\t\t\t\t:= \t\n\t\t\t\t\t\t\t\\begin{cases}\n\t\t\t\t\t\t\t\t\\dfrac{e^{-y\\xi}}{p(\\xi; \\lambda) + i \\,c\\, \\pi}, \n\t\t\t\t\t\t\t\t\t& \\xi > 0\\\\\n\t\t\t\t\t\t\t\t\t\\\\\n\t\t\t\t\t\t\t\t\\dfrac{1}{\\zeta(\\lambda)} \n\t\t\t\t\t\t\t\t\\dfrac{\n\t\t\t\t\t\t\t\t\t\\big(\\zeta(\\lambda)- \\xi - c \\, i\\pi \\big)\n\t\t\t\t\t\t\t\t\te^{(2-y)\\xi} \n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t{p(\\xi; \\lambda) + i\\,  c \\, \\pi},\n\t\t\t\t\t\t\t\t\t&\t\\xi < 0.\n\t\t\t\t\t\t\t\\end{cases}\n\t\t\t\t\\end{teqn}\n\t\t\t}\n\t\t& p.\\pageref{eq0:smallR} \\\\\n\t$\\mathpzc R_\\star$ & sum residues of $e^{iz\\xi}/p(\\xi)$ at the \n\t\t\t$\\xi=0$ and $\\xi=\\lambda$ poles \n\t\t& p.\\pageref{eq3:mathpzcR}\\\\\n\t$\\mathcal E_{\\varepsilon}$ & a family of convolution operators\n\t\t\tgiven by\n\t\t\t\\begin{talign}\n\t\t\t\t\t\\left( \\mathcal E_\\varepsilon f \\right)(x)\n\t\t\t\t\t&:=  \\frac{e^{-i \\pi (2-\\varepsilon)}}{2 \\pi i}\n\t\t\t\t\t\t\\int_{-\\infty}^x\n\t\t\t\t\t\t\t\\frac{e^{-\\pi|x-x'|}}{(x-x') - i\\varepsilon} f(x')\n\t\t\t\t\t\t\\, \\mathrm{d}x' \\\\\n\t\t\t\t\t&\\quad + \\frac{e^{i \\pi (2-\\varepsilon)}}{2 \\pi i}\n\t\t\t\t\t\t\\int_x^{\\infty}\n\t\t\t\t\t\t\t\\frac{e^{-\\pi|x-x'|} }{(x-x') - i\\varepsilon} f(x')\n\t\t\t\t\t\t\\, \\mathrm{d}x'\n\t\t\t\\end{talign}\n\t\t& p.\\pageref{sym:almostExpCauchy} \\\\\n\t$E_{\\varepsilon}$ & exponentially weighted Cauchy transform; given by\n\t\t\t\\begin{teqn}\n\t\t\t\tE_{\\varepsilon} f(x)\n\t\t\t\t\t:= \\frac{1}{2\\pi i} \\int_{\\mathbb R}\n\t\t\t\t\t\t\\frac{e^{-\\pi|x-x'|}}{(x-x') - i \\varepsilon} f(x') \\, \\mathrm{d}x'\n\t\t\t\\end{teqn}\n\t\t& p.\\pageref{sym:expCauchy} \\\\\n\t$E$ & exponentially weighted Hilbert Transform;\n\t\t\tgiven by\n\t\t\t\\begin{teqn}\n\t\t\t\tEf(x)\n\t\t\t\t\t:= \\frac{1}{2\\pi i}\n\t\t\t\t\t\t\\pv \\int_{\\mathbb R} \\frac{e^{-\\pi|x-x'|}}{x-x'} f(x') \\, \\mathrm{d}x',\n\t\t\t\\end{teqn}\n\t\t\twhere $\\pv \\int (\\dotarg) \\, \\mathrm{d}\\mu$ denotes a principle value integral.\n\t\t& p.\\pageref{sym:ExpHil} \\\\\n\t$\\mathscr S(\\mathbb R)$ & space of all Schwartz class functions on $\\mathbb R$\n\t\t& p.\\pageref{sym3:schwartz} \\\\\n\t$\\mathpzc E_\\varepsilon, ~\\mathpzc P_\\varepsilon$ & two families of convolution\n\t\t\toperators given by\n\t\t\t\\[\n\t\t\t\t\\mathpzc E_\\varepsilon(y)\n\t\t\t\t\t:= \\frac{1}{2\\pi i} \\frac{y}{y^2 + \\varepsilon^2} e^{-\\pi|y|},\n\t\t\t\t\\quad \\text{and} \\quad\n\t\t\t\t\\mathpzc P_\\varepsilon(y)\n\t\t\t\t\t:= \\frac{1}{\\pi} \\frac{\\varepsilon}{y^2 + \\varepsilon^2} e^{-\\pi|y|}\n\t\t\t\\]\n\t\t& p.\\pageref{sym:badCauchy} \\\\\n\t$E^{(\\varepsilon)}$ &  truncated exponentially weighted Hilbert Transform; given\n\t\t\tby\n\t\t\t\\begin{teqn}\n\t\t\t\tE^{(\\varepsilon)}f(x)\n\t\t\t\t\t:= \\frac{1}{2\\pi i}\n\t\t\t\t\t\t \\int_{|x'|\\geq \\varepsilon} \\frac{e^{-\\pi|x'|}}{x'} f(x-x') \\, \\mathrm{d}x'\n\t\t\t\\end{teqn}\n\t\t\tby definition,\n\t\t\t$(Ef)(x) = \\lim_{\\varepsilon \\searrow 0} E^{(\\varepsilon)}f(x)$\n\t\t& p.\\pageref{sym:truncExpHil} \\\\\n\t$P_\\varepsilon$ & Poisson kernel; given by \n\t\t\t$P_\\varepsilon(y) = \\frac{1}{\\pi}\\frac{\\varepsilon}{y^2+\\varepsilon^2}$\n\t\t& p.\\pageref{sym3:poisson} \\\\\n\t$E^*$ & the maximal operator associated with the Cauchy transform\n\t\t\t$E_{\\varepsilon}$; given by\n\t\t\t\\begin{teqn}\n\t\t\t\tE^*f(x)\n\t\t\t\t\t:= \\( E_{\\varepsilon} \\)^* f(x)\n\t\t\t\t\t:= \\sup_{\\varepsilon>0} \\left\\{\\left|E_{\\varepsilon} f(x)\\right|\\right\\}.\n\t\t\t\\end{teqn}\n\t\t& p.\\pageref{sym:maxCauchyT} \\\\\n\t$M$ & The Hardy-Littlewood maximal operator; given by\n\t\t\t\\begin{teqn}\n\t\t\t\tM f(x)\n\t        \t\t= \\sup_{r > 0}\n\t        \t\t\t\\left\\{\n\t        \t\t\t\t\\frac{1}{B(0, r)} \\int_{B(0, r)} |f(x - x')| \\, \\mathrm{d}x'\n\t\t        \t\t\\right\\}.\n\t\t\t\\end{teqn}\n\t\t& p.\\pageref{sym:hardy} \\\\\n\t$m_E$ & Fourier multiplier for the exponentially weighted Hilbert transform; \n\t\t\tgiven by\n\t\t\t\\begin{teqn}\n\t\t\t\tm_E(\\xi) = \\frac{1}{\\pi} \\arctan(\\xi/\\pi)\n\t\t\t\\end{teqn}\n\t\t& p.\\pageref{sym3:Emult} \\\\\n\t$L^{p,\\infty}$ & weak $L^p$ space; also denoted $weak$-$L^p$ \n\t\t& p.\\pageref{sym:weakLp} \\\\\n\\end{indextable}\n\\newpage\n\n\n%===================\n% Chapter 5 Notation\n%===================\n\\def\\tabletitle{Chapter 5 Notation}\n% \\def\\tabletitle{Chapter 4 Notation}\n\\subsection{\\tabletitle}\n\\begin{indextable}{\\tabletitle}\n\t$M_1$, $M_e$, $N_1$, $N_e$ & depending on context, either Jost solutions \n\t\tor analytic extensions of solutions to the integral equations\n\t\t\\eqref{eq4:JostIE}\n\t\t& p.\\pageref{defn4:jost}, p.\\pageref{eq4:JostIE} \\\\\n\t$X$ & space of potentials $u$ with $\\nm{\\inn{\\dotarg}^{4} u}_{L^2} < \\infty$\n\t\t\t& p.\\pageref{defn2:X} \\\\\n\t$c_0$ & a strictly positive constant chosen in Proposition \\ref{prop4:exist}\n\t\t\tto ensure the existence and uniqueness of Jost solutions for every\n\t\t\tpotential $u \\in X$ with $\\|u\\|_X < c_0$\n\t\t& p.\\pageref{prop4:exist} \\\\\n\t$T_{\\star, \\lambda, u}$ & bounded operator on \n\t\t\t$\\inn{\\dotarg}L^\\infty(\\mathbb R)$ given by\n\t\t\t\\begin{teqn}\n\t\t\t\tT_{\\star, \\lambda, u} f(x) \n\t\t\t\t\t:= \\big[ G_\\star^+(\\dotarg; \\lambda) \\big] * (u\\,f)(x)\n\t\t\t\\end{teqn}\n\t\t\tbased on context, $T_{\\star, \\lambda, u}$ is sometimes denoted \n\t\t\tby $T_\\star$, $T_{\\star, \\lambda}$, or $T_\\lambda$\n\t\t& p.\\pageref{prop4:exist} \\\\\n\t$a$, $b$, $\\breve{a}$, $\\breve{b}$\n\t\t& coefficients for the scattering equations \\eqref{eq3:M1N} and \n\t\t\t\\eqref{eq3:N1M}; given by \n\t\t\t\\begin{talign}\n\t\t\t\ta(\\lambda)\n\t\t\t\t\t&:= 1 + i \\alpha(\\lambda) \\,\n\t\t\t\t\t\t\\int_{\\mathbb R} u(x) \\, M_1^+(x; \\lambda, u) \\, \\mathrm{d}x \\\\\n\t\t\t\tb(\\lambda)\n\t\t\t\t\t&= i \\beta(\\lambda) \\, \n\t\t\t\t\t\t\\int_{\\mathbb R} e^{-ix\\lambda} \\, u(x) \\, M_1^+(x; \\lambda, u) \\, \\mathrm{d}x \\\\\n\t\t\t\t\\breve{a}(\\lambda)\n\t\t\t\t\t&:= 1 + \\alpha(\\lambda)\n\t\t\t\t\t\t\\int_{\\mathbb R} u(x) \\, N_1(x; \\lambda, u) \\, \\mathrm{d}x \\\\\n\t\t\t\t\\breve{b}(\\lambda)\n\t\t\t\t\t&= i \\beta(\\lambda) \n\t\t\t\t\t\t\\int_{\\mathbb R} e^{-ix\\lambda} \\, u(x) \\, N_1(x; \\lambda, u) \\, \\mathrm{d}x\n\t\t\t\\end{talign}\n\t\t& p.\\pageref{prop4:SD} \\\\\n\t$\\alpha(\\lambda; \\delta)$ & residue of $e^{iz\\xi}/p(\\xi)$ at the $\\xi=0$\n\t\t\tpole; given by \n\t\t\t{\\begin{teqn}\n\t\t\t\t\\alpha(\\lambda; \\delta)\n\t\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(\\lambda; \\delta)}\n\t\t\t\\end{teqn}}\n\t\t\t& p.\\pageref{sym:alphabeta} \\\\\n\t$\\beta(\\lambda; \\delta)$ & $e^{iz\\lambda}$ times the residue of \n\t\t\t$e^{iz\\xi}/p(\\xi)$ at the $\\xi=\\lambda$ pole; given by \n\t\t\t{\\begin{teqn}\n\t\t\t\t\\alpha(\\lambda; \\delta)\n\t\t\t\t\t= \\frac{1}{1-2\\delta\\zeta(-\\lambda; \\delta)}\n\t\t\t\\end{teqn}}\n\t\t& p.\\pageref{sym:alphabeta} \\\\\n\t$\\mathscr D$ & direct scattering map for the ILW; given by \n\t\t\t$\\mathscr D: B_X(0, c_0) \\ni u \\mapsto r \\in L_\\lambda^\\infty(\\mathbb R)$\n\t\t& p.\\pageref{sym4:dsm} \\\\\n\t$r$ & reflection coefficient; given by $r(\\lambda) = b(\\lambda) / a(\\lambda)$\n\t\t& p.\\pageref{sym4:dsm}\n\\end{indextable}\n\n\\end{document}", "meta": {"hexsha": "4e716b6f7f5097ccf6a9f9a01a2f7397f550dfd8", "size": 23728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendices/app-Symbols.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": "Appendices/app-Symbols.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": "Appendices/app-Symbols.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": 36.9595015576, "max_line_length": 94, "alphanum_fraction": 0.5707602832, "num_tokens": 9548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.609046895441354}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsthm}\n\\usepackage{amssymb}\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage[margin=0.5in]{geometry}\n\\usepackage{mathrsfs}\n\n\\newtheorem{axiom}{Axiom}[section]\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem*{remark}{Remark}\n\n\\begin{document}\n\\title{Mathematical definitions for everyone... Well, not yet but that is the goal.}\n\\author{Miguel Angel Gomez Barrera}\n\n\\maketitle\n\n\\section{Trigonometry}\n\n\\section{Set}\n\n\\paragraph{Set} In mathematics, a set is a collection of well defined distinct objects, considered as an object in its own right.\n\n\\begin{axiom}[Axiom of Extension] Two sets are equal if and only if they have the same elements.\n\\end{axiom}\n\n\\paragraph{}If $A$ and $B$ are sets and if every element of $A$ is an element of $B$, we say that $A$ is a \\textit{subset} of $B$, or $B$ \\textit{includes} $A$, and we write\n$$A \\subset B$$\nor\n$$B \\supset A$$\n\\begin{axiom}[Axiom of specification]\n\tTo every set $A$ and to every condition $S(x)$ there corresponds a set $B$ whose elements are exactly those elements $x$ of $A$ for which $S(x)$ holds.\n\\end{axiom}\n\n\\paragraph{}For all that has been said so far, we might have been operating ina vacuum. To give discussion some substance, let us officially assume that\n\\begin{center}\n\t\\textit{there exists a set.}\n\\end{center}\n\\paragraph{}The axiom of extension implies that there can only be one set with no elements, the set is called \\textit{the empty set} and is represented by:\n$$\\emptyset.$$\n\\paragraph{}Another Example: $\\{x\\in \\mathbb{N}: x \\neq x\\}$ y $\\{x \\in \\mathbb{N}: \\frac{1}{x} > 1\\}$\n\n\\paragraph{}The empty set is a subset of every set, or, in other words, $\\emptyset \\subset A$ for every $A$. To establish this, we might argue as follows. It is to be proved that every element in $\\emptyset$ belongs to $A$; since there are no elements in $\\emptyset$, the condition is automatically fulfilled. The reasoning is correct but perhaps unsatisfying. Since it is a typical example of a frequent phenomenon, a condition holding in the \"vacuous\" sense, a word of advice to the inexperienced reader might be in order. To prove that something is true about the empty set, prove that it cannot be false. How, for instance, could it be false that $\\emptyset \\subset A$? It could be false only if $\\emptyset$ had an element that did not belong to $A$. Since $\\emptyset$ has no elements at all, this is absurd. Conclusion: $\\emptyset \\subset A$ is not false, and therefore $\\emptyset \\subset A$ for every A.\n\\begin{axiom}[Axiom of pairing]\n\tfor any two sets there exists a set that they both belong to.\n\\end{axiom}\n\\paragraph{Note} In case $S(x)$ is $(x \\in' x)$, or in case $S(x)$ is $(x = x)$, the specified x's do not constitute a set. Despite the maxim about never getting something for nothing, it seems a little harsh to be told that certain sets are not really sets and even their names must never be mentioned. Some approaches to set theory try to soften the blow by making systematic use of such illegal sets but just not calling them sets; the customary word is \"class.\" A precise explanation of what classes really are and how they are used is irrelevant in the present approach. Roughly speaking, a class may be identified with a condition (sentence), or, rather, with the \"extension\" of a condition.\n\n\\begin{axiom}[Axiom of Unions]\n\tFor every collection of sets there exists a set that contains all the elements that belong to at least one set of the given collection.\n\\end{axiom}\n\\paragraph{} Here it is again: for every collection $\\mathscr{C}$ there exists a set $U$ such that $x \\in X$ for some $X \\in \\mathscr{C}$, then $x \\in U$.\n\\paragraph{}the comprehensive set $U$ described above may be too comprehensive; it may contain elements that belong to none of the sets $X$ in collection $\\mathscr{C}$. This is easy to remedy; just apply the axiom of specification to form the set:\n$$\\{x \\in U: x \\in X \\text{ for some } X \\in \\mathscr{C}\\},$$\n\\paragraph{}If we change notation and call the set $U$ again, then\n$$U = \\{x: x \\in X \\text{ for some } X \\in \\mathscr{C}\\},$$\n\\paragraph{}This set $U$ is called \tthe \\textit{union} of collection $\\mathscr{C}$ of sets, note the axiom specification guarantees its uniqueness. the simplest symbol for $U$ that is in use at all is not very popular in mathematics circles; it is\n$$\\bigcup \\mathscr{C},$$\n\\paragraph{}\n\\section{Function}\n(MSC: 03E99)\n\\paragraph{Function} . Is a relation between sets in which one element of the set is related to another element of the second set.\n\n$$f: A \\mapsto B$$\n\nFunctions are composed by three things:\n\n\\begin{itemize}\n    \\item The domain.\n    \\item The codomain or range.\n    \\item The correspondence rule.\n\\end{itemize}\n\n$$f(n):=$$\n\n\\paragraph{Domain}\n\\paragraph{Codomain or Range}\n\n\\begin{theorem}[Taylor Polinomial] Given some function $f$ with derivatives of order $n$ on the point $x=0$. Exists a only one polynomial $P$ on degree less or equal of $n$ which satisfies the $n + 1$ conditions:\n\t$$P(0) = f(0), P'(0)=f'(0), \\dots, P^n = f^{(n)}(0)$$\n, and given by the formula:\n\t$$P(x) = \\sum_{k=0}^{n} \\frac{f^{(k)}(0)}{x!}x^{k}$$\nwhere $x \\neq x_0$.\n\\end{theorem}\n\n\\begin{align*}\nu_{xy} &= u_x u_y\\\\\n\\frac{u_{xy}}{u_x} &= u_y\\\\\n\\frac{\\partial}{\\partial y}\\left(\\ln (u_x)\\right) &= \\frac{\\partial}{\\partial y}\\left(u\\right)\\\\\nc(x) + \\ln(u_x) &= u\\\\\nu_x &= e^{u - c(x)}\\\\\nu_{xy} &= u_y e^{u-c(x)}\n\\end{align*}\nluego,\n$u_{xy} = u_x u_y$ y $u_{xy}= u_y e^{u-c(x)}$\n\n\\end{document}", "meta": {"hexsha": "efe017ab449afb9340b4ca39a8230a49452e1f9f", "size": 5558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "definitions.tex", "max_stars_repo_name": "mangel/mathbook", "max_stars_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "definitions.tex", "max_issues_repo_name": "mangel/mathbook", "max_issues_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "definitions.tex", "max_forks_repo_name": "mangel/mathbook", "max_forks_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_forks_repo_licenses": ["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.0297029703, "max_line_length": 909, "alphanum_fraction": 0.7173443685, "num_tokens": 1643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.800691997339971, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6090468947145633}}
{"text": "\\section{Finiteness Predicates}\\label{finiteness-predicates}\n\\input{figures/finite-classification}\nIn this subsection, we will define and briefly describe each of the five predicates\nin \\Cref{finite-classification}.\nWe will also explain \\emph{why} there are five separate predicates: how can it\nbe the case that so many different things describe ``finiteness''?\nAs we will see, some predicates are too informative (they\ntell us more about the underlying type other than it just being finite), or too\nrestrictive (they don't allow certain finite types to be classified as finite).\nThese diversions won't be dead-ends, however: the final predicate we will land\non as the ``correct'' (or, more accurately, most useful) notion of finiteness\nwill be built out of all of the others.\n\\subsection{Split Enumerability}\\label{split-enumerability}\nWe will start with a simple notion of finiteness, called split enumerability.\nThis predicate is perhaps the first definition of ``finite'' that someone might\ncome up with (it's certainly the most common in dependently-typed programming):\nput simply, a split enumerable type is a type for which all of its elements can\nbe listed.\n\\begin{definition}[Split Enumerable Set]\\label{split-enum-def}\n  To say that some type \\(A\\) is split enumerable is to say that there is a list\n  \\(\\mathit{support} : \\AgdaDatatype{List}\\;A\\) such that any value \\(x : A\\) is in\n  \\(\\mathit{support}\\).\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable/Container.tex]{split-enum-def}\n  We call the first component of this pair the ``support'' list, and the second\n  component the ``cover'' proof.\n  An equivalent version of this predicate was called \\verb+Listable+ in\n  \\citet{firsovDependentlyTypedProgramming2015}.\n\\end{definition}\n\n\nThis predicate is simple and useful, but we will see later on how it is perhaps\na little imprecise.\nBefore we dive in to exploring the predicate itself, though, we will need to\nexplain some of the terms we used in its definition.\n\\paragraph{What is a List?}\nIn this paper we prefer a slightly unusual definition for the type of lists:\n\\twocolcode\n{\\ExecuteMetaDataInline[agda/Container/List.tex]{list-def}}\n{\\ExecuteMetaDataInline[agda/Data/Fin/Base.tex]{fin-def}}\nThis is the definition for a \\emph{container} (\\Cref{container-def}):\neffectively, the above definition says that ``Lists are a datatype whose shape\nis given by the natural numbers, and which can be indexed by numbers smaller\nthan its shape''.\nIf that seems needlessly complex, don't worry: this definition is precisely\nequivalent to the usual inductive one.\n\\ExecuteMetaDataInline[agda/Data/List/Base.tex]{list-def}\nAnd this isn't some kind of hand-waving equivalence, either: since we are\nworking in HoTT, we can (and do) prove that the two types are equal, allowing us\nto use one or the other depending on whichever is more convenient, and\n\\(\\AgdaFunction{subst}\\) in the other representation without loss of generality.\nThat said, defining lists as containers will reveal several interesting\nconnections and proofs about split enumerability and the other predicates, \nso for the remainder of the paper whenever we say \\AgdaDatatype{List} we will\nmean  \\(\\;\\AgdaFunction{⟦}\\Nat,\\AgdaFunction{Fin}\\AgdaFunction{⟧}\\;\\).\n\nWe still must define containers themselves, of course.\nContainers are a well-studied topic in dependent type theory, with a rich\ntheory: we won't dive in to that here.\n\\begin{definition}[Containers]\\label{container-def}\n  A container \\citep{abbottContainersConstructingStrictly2005} is a pair\n  \\(S , P\\) where \\(S\\) is a type, the elements of which are called\n  the \\emph{shapes} of the container, and \\(P\\) is a type family on \\(S\\), where\n  the elements of \\(P(s)\\) are called the \\emph{positions} of a container.\n  We ``interpret'' a container into a functor defined like so:\n  \\ExecuteMetaDataInline[agda/Container.tex]{container-interp}\n\\end{definition}\n\nThe definition of container is a little abstract: it is instructive to think of\nit more concretely for the case of lists.\nThe container representing finite lists is a pair of a natural number \\(n\\)\nrepresenting the length (or ``shape'') of the list, and a function\n\\(\\AgdaDatatype{Fin}\\;n\\to A\\), representing the indexing function into the\nlist.\n\nOne of the nice things about containers is it gives us a generic way to define\n``membership'':\n\\twocolcode\n{\\ExecuteMetaDataInline[agda/Container/Membership.tex]{membership-def}}\n{\\ExecuteMetaDataInline[agda/Snippets/Introduction.tex]{fiber}}\nHere we're using the homotopy-theory notion of a \\AgdaDatatype{fiber} to define\nmembership: a fiber for some function \\(f\\) and some point \\(y\\) in its codomain\nis a value \\(x\\) and a proof that \\(f \\; x \\;\\AgdaDatatype{≡}\\;y\\).\nMembership also makes more sense when described concretely in terms of lists:\n\\(x\\;\\AgdaDatatype{\\ensuremath{\\in}}\\;\\mathit{xs}\\) means ``there is an index\ninto \\(\\mathit{xs}\\) such that the index points at an item equal to \\(x\\)''.\n\\paragraph{Split Surjections}\nNow that we have our terms defined, let's look a little at how split\nenumerability relates to more traditional, classical notions of finiteness.\nIn a classical setting we likely wouldn't mention ``lists'' or the like, and\nwould instead define finiteness based on the existence of some injection or\nsurjection, say a surjection from a finite prefix of the natural numbers.\nIn HoTT, surjections (or, more precisely, \\emph{split} surjections\n\\cite[definition 4.6.1]{hottbook}), are defined like so:\n\n\\twocolcode\n{\\ExecuteMetaDataInline[agda/Function/Surjective/Base.tex]{split-surjective}}\n{\\ExecuteMetaDataInline[agda/Function/Surjective/Base.tex]{split-surjection}}\nAs it turns out, our definition of finiteness here is precisely the same as a\nsurjection-based one, in quite a deep way!\n\\begin{lemma}\\label{split-enum-is-split-surj}%\n  A proof of split enumerability is equivalent to a split surjection from a\n  finite prefix of the natural numbers.\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{is-split-inj-type}\n\\end{lemma}\n\\begin{proof} \\let\\qed\\relax\n   \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{is-split-inj}\n\\end{proof}\n\nIn the above proof syntax the\n\\(\\AgdaDatatype{\\ensuremath{\\equiv \\langle{} \\rangle{} }}\\) connects lines which\nare definitionally equal, i.e. they are ``obviously'' equal from the type\nchecker's perspective.\nClearly, only one line isn't a definitional equality: \n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Data/Sigma/Properties.tex]{reassoc}\n\\end{agdalisting*}\nThis means that we could have in fact written the whole proof as follows:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{split-enum-is-split-surj-short}\n\\end{agdalisting*}\nThe simplicity of this proof, by the way, is why we preferred the\ncontainer-based definition of lists over the traditional one.\n\nIn \\citet{firsovDependentlyTypedProgramming2015}, there is a proof that split\nenumerability and surjections from \\(\\AgdaDatatype{Fin}\\) are propositionally\nequivalent; i.e. a function from each to the other is provided.\nThe fact that the two proofs are precisely equivalent is not proven (and,\nindeed, it is impossible to prove in MLTT).\n\\paragraph{Instances}\n\\begin{marginagdalisting}{Proof of \\(\\AgdaFunction{\\(\\mathcal{E}!\\)\\;\\AgdaDatatype{Bool}}\\)}\\label{bool-is-split-enumerable}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{bool-inst}\n\\end{marginagdalisting}\nTo actually show that a type \\(A\\) is finite amounts to constructing a term of\ntype \\(\\AgdaDatatype{\\ensuremath{\\mathcal{E}!}}\\;A\\).\nFor simple types like \\AgdaDatatype{Bool}, that is simple: it just amounts to\nbasically listing the constructors.\nAs a slightly more complex example, consider the \\(\\AgdaDatatype{Fin}\\) type\nwe've been using.\nRemember that split enumerability is in fact the same as a split surjection from\n\\(\\AgdaDatatype{Fin}\\) (\\Cref{split-enum-is-split-surj}): to show that\n\\(\\AgdaDatatype{Fin}\\) is split enumerable, then, we need only show that it has\na split surjection from itself.\nWe'll prove the following slightly more general statement:\n\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Function/Surjective/Properties.tex]{split-surj-ident}\n\\end{agdalisting*}\n\\paragraph{Decidable Equality}\nOne thing that characterises all split enumerable types is that they are all\n\\emph{discrete}, i.e. they have decidable equality. \n\\begin{agdalisting*}\n  \\begin{multicols}{2} \\null \\vfill\n    \\ExecuteMetaDataInline[agda/Relation/Nullary/Discrete/Base.tex]{discrete-def} \\vfill \\null \\columnbreak\n    \\ExecuteMetaDataInline[agda/Snippets/Dec.tex]{dec-def}\n  \\end{multicols}\n\\end{agdalisting*}\nWe will see later that this has implications for the space of types we're\ndealing with, but for now it simply provides a useful function on split\nenumerable types.\n\\begin{lemma}\\label{split-enum-discrete}\n  Split enumerability implies decidable equality.\n\\end{lemma}\n\\begin{proof}\nTo prove that split enumerability implies decidable equality we'll take a quick\ndetour through injections.\n\\begin{agdalisting*}\n  \\begin{multicols}{2}\n    \\ExecuteMetaDataInline[agda/Function/Injective/Base.tex]{injective} \\columnbreak\n    \\ExecuteMetaDataInline[agda/Function/Injective/Base.tex]{injection}\n  \\end{multicols}\n\\end{agdalisting*}\nThese are useful because we know that any type which injects into a discrete\ntype is itself discrete:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Function/Injective/Properties.tex]{inj-discrete}\n\\end{agdalisting*}\nAnd we can turn a split surjection from \\(A\\) to \\(B\\) into an injection from\n\\(B\\) to \\(A\\):\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Function/Surjective/Properties.tex]{surj-to-inj}\n\\end{agdalisting*}\nYielding a simple proof that any type with a split surjection from a discrete\ntype is itself discrete:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Function/Surjective/Properties.tex]{discrete-surj}\n\\end{agdalisting*}\nSince split enumerability is really just a split surjection from\n\\AgdaDatatype{Fin}, and since we know that \\AgdaDatatype{Fin} is discrete, the\noverall proof resolves quite simply:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{split-is-discrete}\n\\end{agdalisting*}\n\\end{proof}\nThis lemma is also proven in \\citet{firsovDependentlyTypedProgramming2015},\nalthough using a significantly different technique.\n\\subsection{Manifest Bishop Finiteness}\\label{manifest-bishop-finiteness}\nWe mentioned in the introduction that occasionally in constructive mathematics\nproofs will contain ``too much'' information.\nWith split enumerability we can see an instance of this.\nConsider the following proof of the finiteness of bool:\n\\begin{agdalisting}\\label{op-slop}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{bool-slop}\n\\end{agdalisting}\nThere is an extra \\AgdaInductiveConstructor{false} at the end of the support\nlist.\nThere's nothing terribly wrong with that: it is still a valid proof of\nfiniteness, after all, but it does mean that this proof has some extra\ninformation which we didn't necessarily intend to encode.\n\nThere is ``slop'' in the type of split enumerability: there are more distinct\nvalues than there are \\emph{usefully} distinct values.\nTo reconcile this, we will disallow duplicates in the support list.\n\nThis is where manifest Bishop finiteness comes in: this is a definition of\nfiniteness quite similar to split enumerability in other regards, except that it\ndoes not allows for duplicates in the support list.\n\nHow exactly to prohibit duplicates is the next question.\nOne approach might be to change the definition of \\(\\AgdaDatatype{List}\\), or\nintroduce a new type \\(\\AgdaDatatype{NoDupeList}\\), and use it in the predicate\ninstead.\nHowever, this would mean we lose access to the functions we have defined on\nlists, and we have to change the definition of\n\\(\\AgdaFunction{\\ensuremath{\\in}}\\) as well.\n\nThere is a much simpler and more elegant solution: we insist that every\n\\emph{membership proof} must be unique.\nThis would disallow a definition of \\(\\AgdaDatatype{\\ensuremath{\\mathcal{E}!}}\\;\n\\AgdaDatatype{Bool}\\) with\nduplicates, as there are multiple values which inhabit the type\n\\(\\AgdaInductiveConstructor{false}\\;\\AgdaFunction{\\ensuremath{\\in}}\\;\n\\AgdaInductiveConstructor{\\ensuremath{\\left[ \\text{false}, \\text{true},\n      \\text{false} \\right]}}\\).\nIt also allows us to keep most of the split enumerability definition unchanged,\njust adding a condition to the returned membership proof in the cover proof.\n\nTo specify that a value must exist uniquely in HoTT we can use the concept of a\n\\emph{contraction} \\cite[definition 3.11.1]{hottbook}.\n\\begin{agdalisting}\\label{isContr}\n  \\ExecuteMetaDataInline[agda/Snippets/Introduction.tex]{isContr}\n\\end{agdalisting}\nA contraction is a type with the least possible amount of information: it\nrepresents the tautologies.\nAll contractions are isomorphic to \\AgdaDatatype{\\ensuremath{\\top}}.\n\nBy saying that a proof of membership is a contraction, we are saying that it\nmust be \\emph{unique}.\n\\begin{agdalisting}\\label{uniq-memb-def}\n  \\ExecuteMetaDataInline[agda/Container/Membership.tex]{uniq-memb-def}\n\\end{agdalisting}\nNow a proof of \\(x\\;\\AgdaFunction{\\ensuremath{\\in}!}\\;\\mathit{xs}\\) means that\n\\(x\\) is not just in \\(\\mathit{xs}\\), but it appears there \\emph{only once}.\n\nWith this we can define manifest Bishop finiteness:\n\\begin{definition}[Manifest Bishop Finiteness] \\label{bish-def}\n  A type is manifest Bishop finite if there exists a list which contains each\n  value in the type once.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestBishop/Container.tex]{bish-def}\n  \\end{agdalisting*}\n  The only difference between manifest Bishop finiteness and split enumerability\n  is the membership term: here we require unique membership\n  (\\AgdaFunction{\\ensuremath{\\in!}}), rather than simple membership\n  (\\AgdaFunction{\\(\\in\\)}).\n  An equivalent version of this predicate was called \\verb+ListableNoDup+ in\n  \\citet{firsovDependentlyTypedProgramming2015}.\n\\end{definition}\n\nWe use the word ``manifest'' here to distinguish from another common\ninterpretation of Bishop finiteness, which we have called cardinal finiteness in\nthis paper: this version of the proof is ``manifest'' because we have a\nconcrete, non-truncated list of the elements in the proof.\n\n\\paragraph{The Relationship Between Manifest Bishop Finiteness and Split\n  Enumerability}\nWhile manifest Bishop finiteness might seem stronger than split enumerability,\nit turns out this is not the case.\nBoth predicates imply the other.\n\nGoing from manifest Bishop finiteness is relatively straightforward:\nto construct a proof of split enumerability from one of manifest Bishop\nfiniteness, it suffices to convert a proof of \\(x\\;\\AgdaFunction{\\ensuremath{\\in!}}\\;\\mathit{xs}\\) to\none of \\(x\\;\\AgdaFunction{\\ensuremath{\\in}}\\;\\mathit{xs}\\), for all \\(x\\) and \\(\\mathit{xs}\\).\nSince \\AgdaFunction{\\(\\in!\\)} is defined as a contraction of \\AgdaFunction{\\(\\in\\)}, such a conversion\nis simply the \\AgdaField{fst} function.\n\nGoing the other direction takes significantly more work.\n\\begin{lemma}\\label{split-enum-to-manifest-bishop}\n  Any split enumerable set is manifest Bishop finite.\n\\end{lemma}\nThis lemma is proven in \\citet{firsovDependentlyTypedProgramming2015}.\nWe will only sketch the proof here:\nthe ``unique membership'' condition in\n\\(\\AgdaDatatype{\\ensuremath{\\mathcal{B}}}\\) means that we are not permitted\nduplicates in the support list.\nThe first step in the proof, then, is to filter those duplicates out from the\nsupport list of the \\(\\AgdaDatatype{\\ensuremath{\\mathcal{E}!}}\\) proof: we can do this using the decidable\nequality provided by \\(\\AgdaDatatype{\\ensuremath{\\mathcal{E}!}}\\) (\\Cref{split-enum-discrete}).\nFrom there, we need to show that the membership proof carries over\nappropriately.\n\nWe have now proved that every manifestly Bishop finite type is split enumerable,\nand vice versa.\nWhile the types are not \\emph{equivalent} (there are more split enumerable\nproofs than there are manifest Bishop finite proofs), they are of equal power.\n\\paragraph{From Manifest Bishop Finiteness to Equivalence}\nWe have seen that split enumerability was in fact a split-surjection in\ndisguise.\nWe will now see that manifest Bishop finiteness is in fact an \\emph{equivalence}\nin disguise.\nWe define equivalences as contractible maps \\cite[definition 4.4.1]{hottbook}:\n  \\begin{agdalisting}\\label{equiv-def}\n    \\begin{multicols}{2}\n      \\ExecuteMetaDataInline[agda/Snippets/Equivalence.tex]{is-equiv-def} \\columnbreak\n      \\ExecuteMetaDataInline[agda/Snippets/Equivalence.tex]{equiv-def}\n    \\end{multicols}\n  \\end{agdalisting}\n\\begin{lemma}\\label{bishop-equiv}\n  Manifest bishop finiteness is equivalent to an equivalence to a finite prefix\n  of the natural numbers.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestBishop.tex]{bishop-is-equiv-type}\n  \\end{agdalisting*}\n\\end{lemma}\n\\begin{proof} \\let\\qed\\relax \\vspace{-1\\baselineskip}\\phantom{Proof.} \\\\\n  \\begin{minipage}[t]{.83\\textwidth}\\vspace{-1.25\\baselineskip}\n    \\begin{agdalisting*}\n      \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestBishop.tex]{bishop-is-equiv}\n    \\end{agdalisting*}\n  \\end{minipage}\n  \\begin{minipage}[t]{.16\\textwidth}\n\n    Def.~\\ref{bish-def} (\\AgdaDatatype{\\ensuremath{\\mathcal{B}}})     \\\\\n    Eqn.~\\ref{uniq-memb-def} (\\AgdaDatatype{\\ensuremath{\\in!}})       \\\\\n    Eqn.~\\ref{container-membership} (\\AgdaDatatype{\\ensuremath{\\in}}) \\\\\n    Eqn.~\\ref{equiv-def} \\\\\n    Eqn.~\\ref{list-def} ({\\AgdaDatatype{List}})\n    Eqn.~\\ref{container-interp}  \\\\\n    Reassociation \\\\\n    Eqn.~\\ref{equiv-def}\n  \\end{minipage}\n\\end{proof}\n\nThis proof is almost identical to the proof for\n\\Cref{split-enum-is-split-surj}: it reveals that\nenumeration-based finiteness predicates are simply another perspective on\nrelation-based ones.\n\n\\citet{firsovDependentlyTypedProgramming2015} provides a proof of the\nrelated statement; that manifest Bishop finiteness implies an equivalence to a\nprefix of the natural number (and vice versa), but similarly to split\nenumerability they cannot show that the two are equivalent as we have done here.\n\nAs we are working in CuTT, a proof of equivalence between two types gives us the\nability to \\emph{transport} proofs from one type to the other.\nThis is extremely powerful, as we will see.\n\\subsection{Cardinal Finiteness}\\label{cardinal-finiteness}\nWhile we have removed some of the unnecessary information from our finiteness\npredicates, one piece still remains.\nThe two following proofs are both valid proofs of the finiteness of\n\\(\\AgdaDatatype{Bool}\\), and both do not include any duplicates:\n\n\\begin{minipage}{\\textwidth}\n\\begin{multicols}{2}\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{bool-inst}\n  \\end{agdalisting*} \\columnbreak\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/SplitEnumerable.tex]{bool-rev}\n  \\end{agdalisting*}\n\\end{multicols}\n\\end{minipage}\nClearly they're not the same though: the order of their support lists differs.\nEach finiteness predicate so far has contained an \\emph{ordering} of the\nunderlying type.\nFor our purposes, this is too much information: it means that when constructing\nthe ``category of finite sets'' later on, instead of each type having one\ncanonical representative, it will have \\(n!\\), where \\(n\\) is the cardinality of\nthe type\\footnotemark.\n\n\\footnotetext{\n  We actually do get a category (a groupoid, even) from manifest Bishop\n  finiteness \\citep{yorgeyCombinatorialSpeciesLabelled2014}: it's the groupoid of\n  finite sets equipped with a linear order, whose morphisms are order-preserving\n  bijections.\n  We do not explore this particular construction in any detail.\n}\n\nWhat we want is a proof of finiteness that is a proposition.\n\\begin{agdalisting}\\label{isProp}\n  \\ExecuteMetaDataInline[agda/Snippets/Introduction.tex]{isProp}\n\\end{agdalisting}\nThe mere propositions are one homotopy level higher than the contractions\n(\\Cref{isContr}), the types for which all values are equal to some value.\nThey represent the types for which all values are equal, or, the types\nisomorphic to \\agdabot\\;or \\agdatop.\nYou can also define propositions in terms of the contractions: propositions are\nthe types whose paths are contractions.\nSoon (\\Cref{isSet}) we will see the next homotopy level, which are\ndefined in terms of the propositions.\n\nDespite now knowing the precise property we want our finiteness predicate to\nhave, we're not much closer to achieving it.\nTo remedy the problem, we will use the following type:\n\\begin{agdalisting}\\label{prop-trunc}\n  \\ExecuteMetaDataInline[agda/Snippets/PropTrunc.tex]{prop-trunc-def}\n\\end{agdalisting}\nThis is a \\emph{higher inductive type}.\nNormal inductive types have \\emph{point} constructors: constructors which\nconstruct values of the type.\nThe first constructor here (\\AgdaInductiveConstructor{\\ensuremath{\\lvert \\_\n    \\rvert}}), or the constructor \\AgdaInductiveConstructor{true} for\n\\AgdaDatatype{Bool}, are both ``point'' constructors.\n\nWhat makes this type higher inductive is that it also has \\emph{path}\nconstructors: constructors which add new equalities to the type. \nThe \\AgdaInductiveConstructor{squash} constructor here says that all elements of\n\\proptrunc{A}\nare equal, regardless of what \\(A\\) is.\nIn this way it allows us to propositionally truncate types, turning\ninformation-containing proofs into mere propositions.\nPut another way, a proof of type \\proptrunc{A}\nis a proof that some \\(A\\) exists, without revealing \\emph{which} \\(A\\).\n\nTo actually use values of this type we have the following eliminator:\n\\begin{agdalisting}\\label{elim-prop}\n  \\ExecuteMetaDataInline[agda/HITs/PropositionalTruncation/Display.tex]{rec-prop-trunc}\n\\end{agdalisting}\nThis says that we can eliminate into any proposition: interestingly, this allows\nus to define a monad instance for \\AgdaDatatype{\\(\\lVert \\_ \\rVert\\)}, meaning\nwe can use things like do-notation.\n\nWith this, we can define cardinal finiteness:\n\\begin{definition}[Cardinal Finiteness]\n  A type \\(A\\) is cardinally finite if there exists a propositionally truncated\n  proof that \\(A\\) is manifest Bishop finite or equivalent to a finite prefix of\n  the natural numbers.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{cardinal-def}\n  \\end{agdalisting*}\n  This predicate is called Bishop finiteness in \\cite{fruminFiniteSetsHomotopy2018}.\n\\end{definition}\n\\paragraph{Deriving Uniquely-Determined Quantities}\nAt first glance, it might seem that we lose any useful properties we could\nderive from \\(\\AgdaDatatype{\\ensuremath{\\mathcal{B}}}\\).\nLuckily, this is not the case: we will show here how to derive decidable\nequality (\\Cref{cardinal-finite-discrete}) and cardinality\n(\\Cref{card-finite-cardinality}) out from under the\ntruncation.\nThose two lemmas are proven in\n\\citep{yorgeyCombinatorialSpeciesLabelled2014} (Proposition 2.4.9 and 2.4.10,\nrespectively), in much the same way as we have done here.\nOur contribution for this subsection is simply the formalisation.\n\nFirst we'll show that decidable equality carries over from manifest Bishop\nfiniteness.\nBefore we do, note that the fact that we can do this says something interesting\nabout propositional truncation: it has computational, or algorithmic, content.\nThat is in contrast to other ways to ``truncate'' types: \\(\\neg \\neg P\\), for\ninstance, is a way to provide a ``proof'' of \\(P\\) without revealing anything\nabout \\(P\\) in MLTT.\nNo matter how much we prove that a function from \\(P\\) doesn't care about which\n\\(P\\) it got, though, we can never extract any kind of algorithm or computation\nfrom \\(\\neg \\neg P\\).\n\\begin{lemma}\\label{cardinal-finite-discrete}\n  Any cardinal-finite set has decidable equality.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{card-discrete}\n  \\end{agdalisting*}\n\\end{lemma}\n\\begin{proof}\nWe already know that manifest Bishop finiteness implies decidable equality;\nto apply that proof to cardinal finiteness we'll use the\neliminator in \\Cref{elim-prop}.\nOur task, in other words, is to prove the following:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Relation/Nullary/Discrete/Properties.tex]{is-prop-discrete}\n\\end{agdalisting*}\n\nTo show that this type is a proposition we must show that any two given members\nof the type are equal, i.e. we are given two proofs of decidable equality on\n\\(A\\) and we must show that they are equal.\nRemember that \\(\\AgdaFunction{Discrete}\\;A\\) is a function of two arguments\nreturning a \\AgdaDatatype{Dec} of whether those two arguments are equal or not.\n\\todo{ref for wherever this definition was}\nBy function extensionality, to prove that that is a proposition we have to prove\nthat \\(\\AgdaDatatype{Dec}\\;(\\agdaequiv{x}{y})\\) is a proposition.\nThis proof requires that we show that the payload of each of the constructors\n(\\AgdaInductiveConstructor{yes} and \\AgdaInductiveConstructor{no}) are\npropositions.\n\\AgdaInductiveConstructor{no}'s payload is\n\\(\\agdaequiv{x}{y}\\rightarrow\\agdabot\\), which is a\nproposition because \\agdabot\\; is a proposition.\n\n\\AgdaInductiveConstructor{yes} is a little more interesting: its payload is\n\\agdaequiv{x}{y}.\nHow can we prove that the path between \\(x\\) and \\(y\\) is a proposition?\nIt turns out that there is a class of types for which all paths are\npropositions: the \\emph{sets}.\n\\begin{agdalisting}\\label{isSet}\n  \\ExecuteMetaDataInline[agda/Snippets/Introduction.tex]{isSet}\n\\end{agdalisting}\nThis is the next homotopy level up from the propositions (\\Cref{isProp}).\nMore importantly, there is an important theorem relating to sets which\n\\emph{also} relates to decidable equality: Hedberg's theorem\n\\citep{hedbergCoherenceTheoremMartinLof1998}.\nThis tells us that any type with decidable equality is a set.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Relation/Nullary/Discrete/Properties.tex]{discrete-isset}\n\\end{agdalisting*}\nAnd of course we know that \\(A\\) here has decidable equality: we were just given\ntwo proofs of that fact at the beginning of this proof!\n\nThis suffices to prove that decidable equality is itself a proposition, and\ntherefore that we can apply \\Cref{elim-prop} and the proof that bishop\nfiniteness implies decidable equality to cardinal finiteness, proving our goal.\n\\end{proof}\n\nThe next thing we can derive from underneath the truncation in cardinal\nfiniteness is a natural number representing the actual cardinality of the finite\ntype.\nOf course \\Nat isn't a proposition, so the eliminator in\nequation~\\ref{elim-prop} won't work for us here.\nInstead we will use the following:\n\\begin{agdalisting}\\label{elim-prop-coh}\n  \\ExecuteMetaDataInline[agda/HITs/PropositionalTruncation/Display.tex]{rec-prop-trunc-set}\n\\end{agdalisting}\nThis says that we can eliminate into a set as long as the function we use\ndoesn't care about which value it's given: formally, \\(f\\) in this example has\nto be ``coherently constant'' \\citep{krausGeneralUniversalProperty2015}.\n\nWith that, we can move on to the proof:\n\\begin{lemma}\\label{card-finite-cardinality}\n  Given a cardinally finite type, we can derive the type's cardinality, as well\n  as a propositionally truncated proof of equivalence with \\AgdaDatatype{Fin}s of\n  the same cardinality.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{cardinality-is-unique}\n  \\end{agdalisting*}\n\\end{lemma}\n\\begin{proof}\n  The high-level overview of our proof is as follows:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{cardinality-is-unique-impl}\n  \\end{agdalisting*}\n  It is the composition of two operations: first, with\n  \\AgdaFunction{\\ensuremath{\\lVert \\text{map} \\rVert}}, we change the truncated\n  proof of manifest bishop finiteness to a proof of equivalence with fin.\n\n  Then we use the eliminator from \\Cref{elim-prop-coh} with three\n  parameters.\n  The first simply proves that that the output is a set:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{card-isSet}\n  \\end{agdalisting*}\n  The second is the function we apply to the truncated value:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{alg}\n  \\end{agdalisting*}\n  And the third is a proof that that function is itself coherently constant:\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{const-alg}\n  \\end{agdalisting*}\n\n  The tricky part of the proof is \\AgdaFunction{const-alg}: here we need to show\n  that \\AgdaFunction{alg} returns the same value no matter its input.\n  That output is a pair, the first component of which is the cardinality, and\n  the second the truncated equivalence proof.\n  The truncated proofs in the output are trivially equal by the truncation, so\n  our obligation now has been reduced to:\n  \\begin{equation*}\n    \\frac{(n :\\;\\AgdaDatatype{\\ensuremath{\\mathbb{N}}}) \\; \\; \\; (p : \\AgdaDatatype{Fin}\\;n\\;\\AgdaFunction{\\ensuremath{\\simeq}}\\;A) \\; \\; \\;\n      (m :\\;\\AgdaDatatype{\\ensuremath{\\mathbb{N}}}) \\; \\; \\; (q : \\AgdaDatatype{Fin}\\;m\\;\\AgdaFunction{\\ensuremath{\\simeq}}\\;A)\n    }{\n      \\agdaequiv{n}{m}\n    }\n  \\end{equation*}\n  Given univalence we have \\(\\AgdaDatatype{Fin}\\;n \\;\\AgdaFunction{\\ensuremath{\\equiv}}\\; \\AgdaDatatype{Fin}\\;m\\),\n  and the rest of our task is to prove:\n  \\begin{equation*}\n    \\frac{\\agdaequiv{\\AgdaDatatype{Fin}\\;n}{\\AgdaDatatype{Fin}\\;m}}{\\agdaequiv{n}{m}}\n  \\end{equation*}\n\n  This is a well-known puzzle in dependently-typed programming, and one that\n  has a surprisingly tricky and complex proof.\n  We do not include it here, since it has already been explored elsewhere, but\n  it is present in our formalisation.\n\\end{proof}\n\n\\paragraph{Going from Cardinal Finiteness to Manifest Bishop Finiteness}\nWe know of course that we can convert any proof of manifest Bishop finiteness to\na proof of Cardinal finiteness: it's just the truncation function\n\\AgdaInductiveConstructor{\\(\\lvert \\_ \\rvert\\)}.\nIt's the other direction which presents a difficulty:\n\\begin{theorem}\\label{cardinal-to-manifest-bishop}\n  Any cardinal finite type with a total order is Bishop finite.\n\\end{theorem}\n\\begin{proof}\nThe proof for this particular theorem is quite involved in the formalisation, so\nwe only give its sketch here.\n\nOur strategy will be to \\emph{sort} the support list of the proof for Bishop\nfiniteness, and then prove that the sorting function is coherently constant,\nthereby satisfying the eliminator in \\Cref{elim-prop-coh}.\nWe need to show, in other words, that sorting two support lists from proofs of\nmanifest Bishop finiteness on the same type with the same order always returns\nthe same result.\nFor simplicity's sake we will use insertion sort:\n\n\\begin{minipage}{\\linewidth}\n\\begin{multicols}{2}\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{insert}\n  \\end{agdalisting*} \\columnbreak \\vfill \\null \\vfill\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{insertion-sort}\n  \\end{agdalisting*} \\vfill \\null\n\\end{multicols}\n\\end{minipage} \\noindent\nAnd we prove that \\AgdaFunction{sort} produces a list which is sorted, and a\npermutation of its input.\n\\begin{multicols}{2}\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{sort-sorts}\n  \\end{agdalisting*} \\columnbreak\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{sort-perm}\n  \\end{agdalisting*}\n\\end{multicols} \\vspace{-\\baselineskip}\nWe've introduced two new types here: \\AgdaFunction{Sorted} is a predicate\nenforcing that the given list is sorted, and\n\\AgdaFunction{\\(\\leftrightsquigarrow\\)} is a permutation relation between two\nlists.\nWe take the definition of permutations from\n\\citep{danielssonBagEquivalenceProofRelevant2012}: two lists are permutations of\neach other if their membership proofs are all equivalent.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Data/List/Relation/Binary/Permutation.tex]{perm-def}\n\\end{agdalisting*}\nThis definition fits particularly well for two reasons: first, it is defined on\ncontainers generically, which fits well with our finiteness predicates.\nSecondly, it is extremely straightforward to show that the support lists of any\ntwo proofs of manifest Bishop finiteness must be permutations of each other:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{perm-bish}\n\\end{agdalisting*}\n\nAlmost all of the pieces are in place now: we know that the support lists of all\nproofs of \\(\\agdacal{B}\\;A\\) are permutations of each other, and we know that\n\\AgdaFunction{sort} returns a sorted permutation of its input.\nThe final piece of the puzzle is the following:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{sorted-perm-eq}\n\\end{agdalisting*}\nIf two sorted lists are both permutations of each other they must be equal.\nConnecting up all the pieces we get the following:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Data/List/Sort.tex]{perm-invar}\n\\end{agdalisting*}\nBecause we know that all support lists of \\(\\agdacal{B}\\;A\\) are permutations of\neach other this is enough to prove that \\AgdaFunction{sort} is coherently\nconstant, and therefore can eliminate from within a truncation.\nThe second component of the output pair (the cover proof) follows quite\nnaturally from the definition of permutations.\n\\end{proof}\nTo the best of our knowledge, this is the first explicit proof of this theorem.\n\\paragraph{Restrictiveness}\nSo far our explorations into finiteness predicates have pushed us in the\ndirection of ``less informative'': however, as mentioned in the introduction, we\ncan \\emph{also} ask how \\emph{restrictive} certain predicates are.\nSince split enumerability and manifest Bishop finiteness imply each other we\nknow that there can be no type which satisfies one but not the other.\nWe also know that manifest Bishop finiteness implies cardinal finiteness, but we\ndo \\emph{not} have a function in the other direction:\n\\begin{agdalisting}\\label{c-to-b}\n  \\(\\agdacal{C}\\;A\\rightarrow\\agdacal{B}\\;A\\)\n\\end{agdalisting} \\todo{Solve the mystery of the mathcal difference for C and B}\nSo the question arises naturally: is there a cardinally finite type which is\n\\emph{not} manifest Bishop finite?\n\nIt turns out the answer is no!\nThe proof of this fact is relatively short:\n\\begin{agdalisting}\\label{no-gap-card-bishop}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/Cardinal.tex]{no-gap-card-bishop}\n\\end{agdalisting}\nWe can apply the function of type \\(\\agdacal{B}\\;A\\rightarrow\\agdabot\\)\n(i.e. \\(\\AgdaFunction{\\(\\neg\\)}\\;\\agdacal{B}\\;A\\)) to the value of type\n\\(\\AgdaDatatype{\\(\\lVert\\)}\\;\\agdacal{B}\\;A\\;\\AgdaDatatype{\\(\\rVert\\)}\\) (i.e.\n\\(\\agdacal{C}\\;A\\)) using \\Cref{elim-prop}, since \\agdabot\\;is itself a\nproposition.\nThis tells us that manifest bishop finiteness, cardinal finiteness, and split\nenumerability all refer to the same class of types.\n\nInterestingly, while we cannot construct a function with the type in\n\\Cref{c-to-b}, it does exist \\emph{classically}.\nIn fact we can derive it from \\Cref{no-gap-card-bishop} using\nthe classical monad we developed in the introduction, since\n\\Cref{no-gap-card-bishop} is actually equivalent to classical\nimplication.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Snippets/Classical.tex]{classical-impl}\n\\end{agdalisting*}\n\\subsection{Manifest Enumerability}\\label{manifest-enumerability}\nGiven that we have just proven that all of our finiteness predicates apply to\nthe same types, the natural next step is to try find a predicate which applies\nto a different class of types.\nLet's first talk about what this new class of types might look like:\nwhat we're looking for is a type which is in some sense finite, but doesn't\nconform to any of the predicates we've seen so far.\nThe \\emph{circle} (Listing~\\ref{circle-def}) is such a type.\nThe thing that this type has which precludes it from being, say, split\nenumerable, is its \\emph{higher homotopy structure}.\n\n\\begin{marginagdalisting}{The Circle}\\label{circle-def}\n  \\ExecuteMetaDataInline[agda/Snippets/Circle.tex]{circle-def}\n\\end{marginagdalisting}\n\n\nSo far we have seen three levels of homotopy structure: the contractions\n(\\Cref{isContr}), the propositions (\\Cref{isProp}), and the sets\n(\\Cref{isSet}).\nYou may have noticed the pattern that each new level is generated by saying its\npaths are members of the previous level; if we apply that pattern again, we get\nto the next homotopy level: the groupoids.\n\\begin{agdalisting}\n  \\ExecuteMetaDataInline[agda/Snippets/Introduction.tex]{isGroupoid}\n\\end{agdalisting}\nThese types do not necessarily have unique identity proofs: there is more than\none value which can inhabit the type \\agdaequiv{x}{y}.\nThe circle is one of the simplest examples of non-set groupoids: the constructor\n\\AgdaInductiveConstructor{loop} is the extra path in the type which isn't the\nidentity path.\n\nWe now need to recall two facts: first, Hedberg's theorem tells us that every\ndiscrete type is a set.\nSecond, every finiteness predicate we've seen thus far implies decidable\nequality.\nFrom this it's clear that all of the previous predicates are restricted to sets,\nand can't include types like the circle.\n\nBut the type certainly \\emph{seems} finite!\nIt has finitely many points, for instance.\nIn order to explore the ``restrictiveness'' axis in\n\\Cref{finite-classification}, then, we'll need to construct a predicate\nwhich admits the circle.\nManifest enumerability is one such predicate.\n\\begin{definition}[Manifest Enumerability]\n  Manifest enumerability is an enumeration predicate like Bishop finiteness or\n  split enumerability with the only difference being a propositionally truncated\n  membership proof.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestEnumerable/Container.tex]{manifest-enum-def}\n  \\end{agdalisting*}\n\\end{definition}\nThis predicate is novel, to the best of our knowledge.\n\nIt might not be immediately clear why this definition of enumerability allows\nthe circle to conform while the others do not.\nThe crux of the issue was that the cover proofs of the previous definitions\ndidn't just tell us that some element was in the support list, they told us\n\\emph{where} it was in the support list.\nFrom the position we were able to derive decidable equality: that position is\nprecisely what's hidden in manifest enumerability.\n\nAnd indeed this means that the circle is manifestly enumerable.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestEnumerable.tex]{circle-is-manifest-enum}\n\\end{agdalisting*}\nWe use a lemma here, proven in the Cubical Agda library, that\n\\AgdaDatatype{S\\(^1\\)} is \\emph{connected}:\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestEnumerable.tex]{s1-connected}\n\\end{agdalisting*}\n\\paragraph{Surjections}\nWe already saw that split enumerability was the listed form of a split\nsurjection: what we didn't explain was why the word ``split'' was placed before\nsurjection.\nIn the presence of higher homotopies than sets, split surjections are actually\n\\emph{not} a satisfactory definition of surjection.\nAnd we are most certainly in the presence of higher homotopies: just moments ago\nwe were introduced to the circle.\nIn these cases, the following definition of surjections is\npreferred~\\cite[definition 4.6.1]{hottbook}:\n\\begin{agdalisting}\\label{surj-eqn}\n  \\begin{multicols}{2}\n    \\ExecuteMetaDataInline[agda/Function/Surjective/Base.tex]{surjective} \\columnbreak\n    \\ExecuteMetaDataInline[agda/Function/Surjective/Base.tex]{surjection}\n  \\end{multicols}\n\\end{agdalisting}\n\nMuch in the same way that split enumerability were split surjections, our new\npredicate of manifest enumerability corresponds to the proper surjections.\n\\begin{lemma}\n  Manifest enumerability is equivalent to a surjection from a finite prefix of\n  the natural numbers.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/ManifestEnumerable.tex]{manifest-enum-surj}\n  \\end{agdalisting*}\n\\end{lemma}\n\\paragraph{Relation To Split Enumerability}\nIt is trivially easy to construct a proof that any split enumerable type is\nmanifest enumerable: we simply truncate the membership proof.\nGoing the other way is more difficult, as we need to extract the membership\nproof from under a truncation.\nWe do know what we need, however: the key difference between manifest\nenumerability and split enumerability is that the latter implied decidable\nequality.\nSo that's the missing piece we should require in order to go from one to the\nother:\n\\begin{lemma}\\label{manifest-enum-to-split-enum}\n  A manifestly enumerable type with decidable equality is split enumerable.\n\\end{lemma}\n\nNow that we know what extra bit of information we are allowed use in this proof,\nthe path forward becomes a little more clear.\nIn terms of the actual conversion function, the support list will stay the same,\nand only the return type of the cover proof needs to change: from\n\\(\\AgdaDatatype{\\(\\lVert\\)}\\;x\\;\\AgdaFunction{\\(\\in\\)}\\;\\mathit{xs}\\;\\AgdaDatatype{\\(\\rVert\\)}\\)\nto \\(x\\;\\AgdaFunction{\\(\\in\\)}\\;\\mathit{xs}\\).\n\nThat can be accomplished with the help of the following function:\n\\begin{agdalisting}\n  \\ExecuteMetaDataInline[agda/HITs/PropositionalTruncation/Properties.tex]{recompute}\n\\end{agdalisting}\nGiven a decision procedure for some type, and a propositionally truncated value\nof that type, we can construct an element of the type.\n\nIn the case of \\(x\\;\\AgdaFunction{\\(\\in\\)}\\;\\mathit{xs}\\) we can construct a\ndecision procedure for membership of a list, since we already have decidable\nequality on the elements of the list, proving our obligation.\n\\subsection{Kuratowski Finiteness}\\label{kuratowski}\nWe now finally arrive at the most important definition of finiteness: Kuratowski\nfiniteness.\nAs a definition, it is quite different from the predicates we've seen (it\ndoesn't involve lists, for instance), but it plays a much larger role in the\nliterature on finiteness predicates than, say, manifest enumerability.\n\nWe start with the definition of Kuratowski-finite subsets.\n\\begin{agdalisting}\n  \\ExecuteMetaDataInline[agda/Algebra/Construct/Free/Semilattice/Definition.tex]{kuratowski-def}\n\\end{agdalisting}\nThe first two constructors are point constructors, giving ways to create\nvalues of type \\(\\agdacal{K}\\;A\\).\nThey are also recognisable as the two constructors for finite lists, a type\nwhich represents the free monoid.\nThe next two constructors add extra paths to the type: equations that usage of\nthe type must obey.\nThese extra paths turn the free monoid into the free \\emph{commutative}\n(\\AgdaInductiveConstructor{com}) \\emph{idempotent}\n(\\AgdaInductiveConstructor{dup}) monoid.\nThe final constructor truncates the type \\(\\agdacal{K}\\;A\\) to a set.\n\nThe Kuratowski finite subset is a free join semilattice (or, equivalently, a\nfree commutative idempotent monoid).\nMore prosaically, \\(\\agdacal{K}\\) is the abstract data type for finite sets, as\ndefined in the Boom hierarchy \\citep{boomFurtherThoughtsAbstracto1981,\n  bunkenburgBoomHierarchy1994}.\nHowever, rather than just being a specification, \\(\\agdacal{K}\\) is fully usable\nas a data type in its own right, thanks to HITs.\n\nOther definitions of \\(\\agdacal{K}\\) exist (such as the one in\n\\citep{fruminFiniteSetsHomotopy2018}) which make the fact that \\(\\agdacal{K}\\) is\nthe free join semilattice more obvious.\nWe have included such a definition in our formalisation, and proven it\nequivalent to the one above.\n\\begin{agdalisting*}\n  \\ExecuteMetaDataInline[agda/Algebra/Construct/Free/Semilattice/Direct.tex]{direct-def}\n\\end{agdalisting*}\n\nNext, we need a way to say that an entire type is Kuratowski finite.\nFor that, we will need to define membership of \\(\\agdacal{K}\\).\n\\begin{equation*}\n  \\begin{alignedat}{2}\n    x\\;\\AgdaFunction{\\ensuremath{\\in}}& \\; \\AgdaInductiveConstructor{[]}                      &&= \\agdabot \\\\\n    x\\;\\AgdaFunction{\\ensuremath{\\in}}& \\; y \\;\\AgdaInductiveConstructor{\\ensuremath{\\dblcolon}}\\; \\mathit{ys} &&= \\AgdaDatatype{\\ensuremath{\\lVert}}\\;\\agdaequiv{x}{y}\\;\\AgdaDatatype{\\ensuremath{\\uplus}}\\;x\\;\\AgdaFunction{\\ensuremath{\\in}}\\;\\mathit{ys}\\;\\AgdaDatatype{\\ensuremath{\\rVert}}\n  \\end{alignedat}\n\\end{equation*}\nThe \\AgdaInductiveConstructor{com} and \\AgdaInductiveConstructor{dup}\nconstructors are handled by proving that the truncated form of \\AgdaDatatype{\\ensuremath{\\uplus}}\nitself commutative and idempotent.\nThe type of propositions is itself a set, satisfying the \\AgdaInductiveConstructor{trunc}\nconstructor.\nThis gives us enough to define Kuratowski finiteness.\n\\begin{definition}[Kuratowski Finiteness]\n  A type is Kuratowski finite if there exists a Kuratowski-finite subset of that\n  type which contains every element of the type.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Kuratowski.tex]{kuratowski-finite-def}\n  \\end{agdalisting*}\n\\end{definition}\n\nWhile Kuratowski finiteness is something of the standard formal definition of\nfiniteness, it is quite separated from the enumeration-based definitions we have\npresented so far.\nIt's difficult to relate to surjections and equivalences, and requires a\ndifferent style of proof to reason about.\nAs such, we want to get \\emph{away} from Kuratowski finiteness as quickly as\npossible.\nTo do so we use the following lemma:\n\\begin{lemma} \\label{manifest-enum-kuratowski}\n  Kuratowski finiteness is equivalent to truncated manifest enumerability.\n  \\begin{agdalisting*}\n    \\ExecuteMetaDataInline[agda/Cardinality/Finite/Kuratowski.tex]{manifest-enum-kuratowski}\n  \\end{agdalisting*}\n\\end{lemma}\n\\begin{proof}\n  This proof is constructed by providing a pair of functions, to and from each\n  side of the equivalence.\n  This pair implies an equivalence, because both source and target are\n  propositions.\n  This proof, as well as its auxiliary lemmas, are also provided in\n  \\citet{fruminFiniteSetsHomotopy2018}, although there the setting is HoTT\n  rather than CuTT.\n\\end{proof}\nBy relating Kuratowski finiteness---with a full equivalence, no less---to an\nenumerated predicate, we have made it possible to talk about Kuratowski\nfiniteness without interacting with the type at all.\n\nIn the next subsection, we will explore the category of discrete Kuratowski finite\nsets.\nUnder the hood, however, we will really be working with cardinal finite sets.\nWe can do this in a fully rigorous way because\n\\Cref{manifest-enum-kuratowski} allows us to prove the following:\n\\begin{agdalisting}\\label{cardinal-kuratowski}\n  \\ExecuteMetaDataInline[agda/Cardinality/Finite/Kuratowski.tex]{card-iso-kuratowski}\n\\end{agdalisting}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"../paper\"\n%%% End:\n", "meta": {"hexsha": "79e08040a31cabeeab4bd7847938b0be7778910f", "size": 46840, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/finiteness-predicates.tex", "max_stars_repo_name": "oisdk/masters-thesis", "max_stars_repo_head_hexsha": "9c5e8b6f546bee952e92db0b73bfc12592bf3152", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_issues_repo_path": "sections/finiteness-predicates.tex", "max_issues_repo_name": "oisdk/masters-thesis", "max_issues_repo_head_hexsha": "9c5e8b6f546bee952e92db0b73bfc12592bf3152", "max_issues_repo_licenses": ["MIT"], "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/finiteness-predicates.tex", "max_forks_repo_name": "oisdk/masters-thesis", "max_forks_repo_head_hexsha": "9c5e8b6f546bee952e92db0b73bfc12592bf3152", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "avg_line_length": 50.2575107296, "max_line_length": 288, "alphanum_fraction": 0.7794619983, "num_tokens": 12402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6090468939877725}}
{"text": "%\n% 41\n%\n\\chapter{Continuous Functions and Uniform Convergence}\n\n\\Section{3}{1}{The dependence of one complex number on another.}\n\nThe problems with which Analysis is mainly occupied relate to the\ndependence of one complex number on another. If z and are two complex\nnumbers, so connected that, if z is given any one of a certain set of\nvalues, corresponding values of can be determined, e.g. if is the\nsquare of z, or if = 1 when z is real and = for all other values of z,\nthen is said to be a function of z.\n\nThis dependence must not be confused with the most important case of\nit, which will be explained later under the title o analytic\nfunctionality.\n\nIf f is a real function of a real variable z, then the relation\nbetween ( and 2, which may be written\n\ncan be visualised by a curve in a plane, namely the locus of a point\nwhose coordinates referred to rectangular axes in the plane are (s,\n(). No such simple and convenient geometrical method can be found for\nvisualising an equation\n\nconsidered as defining the dependence of one complex number f = | +\ni'7 on another complex number z = x + i)/. A representation strictly\nanalogous to the one already given for real variables would require\nfour-dimensional space, since the number of variables, fj, X, y is\nnow four.\n\nOne suggestion (made by Lie and Weierstrass) is to use a\ndoubly-manifold system of lines in the quadruply-manifold totality of\nlines in three-dimensional space.\n\nAnother suggestion is to represent and;; separately by means of\nsurfaces\n\nA third suggestion, due to Heffter*, is to write\n\nthen draw the surface r = r x, y) - which may be called the\nmodular-surface of the function- and on it to express the values of 6\nby surface-markings. It might be possible to modify this suggestion in\nvarious ways by representing 6 by curves drawn on the surface r=r (.r,\ny).\n\n\\Section{3}{2}{Continuity of functions of real variables.}\n\nThe reader will have a general idea (derived from the graphical\nrepresen- tation of functions of a real variable) as to what is meant\nby continuity.\n\n* Zeitschrift fur Math, tind Phys. xlix. (1899), p. 235.\n\n%\n% 42\n%\n\nWe now have to give a precise definition which shall embody this vague\nidea.\n\nJjetf x) be a function of x defined when a x b.\n\nLet x be such that a x b. If there exists a number I such that,\ncorresponding to an arbitrary positive number e, we can find a\npositive number rj such that\n\n\\ f a:)-l\\ < e,\n\nwhenever \\ x - Xi\\ < rj, x x, and a x b, then I is called the limit\nof /(a;)\n\nIt may happen that we can find a number 1+ (even when I does not\nexist) such that \\ f(x) - l+\\ < € when x- < x < Xi + rj. We call Z+\nthe limit of f(x) when X approaches x- from the right and denote it\nby/(a;i + 0); in a similar manner we define f x - 0) if it exists.\n\nIf f(xi + 0), f xi), f x- - 0) all exist and are equal, we say that\n/(a-) is continuous at x; so that \\ if x) is continuous at x-, then,\ngiven e, we can find 7] such that\n\n\\ f(x) -f(x,) I < e,\n\nwhenever \\ x - Xi\\ < rj and a x h.\n\nIf 1+ and l\\ exist but are unequal, $f(x)$ is said to have an ordinary\ndiscontinuity* at Xi] and if 1+ = /\\ 4=/( i), f ) is said to have a\nremovable discontinuity at x- .\n\nlif x) is a complex function of a real variable, and \\ if x) = g(x) +\ni h (x) where g (x) and h (x) are real, the continuity of $f(x)$ at x\nimplies the continuity of g (x) and of A (x). For when \\ f(x) -f x \\\n< e, then | g (x) -g(xi) \\ < e and I h (x) - h xi)\\ < e; and the\nresult stated is obvious.\n\nExample. From 2*2 examples 1 and 2 deduce that if f(x) and cf) (x) are\ncon- tinuous at Xi, so are f(x) + x), f(x) x x) and, if (.rj) =t= 0,\nf x)/(l) (.*).\n\nThe popular idea of continuity, so far as it relates to a i-eal\nvariable f(x) depending on another real variable x, is somewhat\ndifferent from that just considered, and may perhaps best be expressed\nby the statement \"The function f(x) is said to depend con- tinuously\non X if, as x passes through the set of all values intermediate\nbetween any two adjacent values Xi and X2, f(x) passes through the set\nof all values intermediate between the corresponding values /( j)\nand/(.r2).\"\n\nThe question thus arises, how far this popular definition is\nequivalent to the precise definition given above.\n\nCauchy shewed that if a real function f x), of a real variable TODO,\nsatisfies the precise definition, then it also satisfies what we have\ncalled the popular definition; this result\n\n* If a function is said to have ordinary discontinuities at certain\npoints of an interval it is implied that it is continuous at all other\npoints of the interval.\n\n%\n% 43\n%\n\nvill be proved in 3\"63. But the converse is not true, as was shewn by\nDarboux. This fact may be iUustrated by the following example*.\n\nBetween x= - I and x= +1 (except at x=0), let f(x) = sin -; and\nlet/(0)=0.\n\nIt can then be proved that/ .r) depends continuously on x near .r=0,\nin the sense of the popular definition, but is not continuous at a; =\nin the sense of the precise definition.\n\nExample. If f(x) be defined and be an increasing function in the range\n(a, b), the limits /(.r + 0) exist at all points in the interior of\nthe range.\n\n[If f(x) be an increasing function, a section of rational numbers can\nbe found such that, if a, A be any members of its Z-cla.ss and its\n-clas.s, a<f x + h) for evei-y positive value of h and A ' f x- h) for\nsome po.sitive value of h. The number defined by this section is/(a; +\n0).]\n\n\\Subsection{3}{2}{1}{Simple curves. Continua.}\n\nLet X and y be two real functions of a real variable t which are\ncontinuous for every value of t such that a- t %h. We denote the\ndependence of x and y on t by writing\n\n.' = (0. 3/ = i/(0- a. t%h)\n\nThe functions x (t), y (t) are supposed to be such that they do not\nassume the same pair of values for any two different values of t in\nthe range a < t < b.\n\nThen the set of points with coordinates (x, y) corresponding to these\nvalues of t is called a simple curve. If\n\nX (a) = X h), y (a) = y (b), the simple curve is said to be closed.\n\nExample. The circle x + 7/-= 1 is a simple closed curve; for we may\nwrite t\n\nx=coiit, y = smt. (0 27r)\n\nA two-dimensional continuum is a set of points in a plane possessing\nthe following two properties :\n\n(i) If (x, y) be the Cartesian coordinates of any point of it, a\npositive number 8 (depending on x and y) can be found such that every\npoint whose distance from x, y) is less than S belongs to the set.\n\n(ii) Any two points of the set can be joined by a simple curve\nconsisting entirel '' of points of the set.\n\nExample. The points for which .r-+3/-<l form a continuum. For if P be\nany point inside the unit circle such that OP=r<\\, we may take 8=1-?-;\nand any two points inside the circle may be joined by a straight line\nlying wholly inside the circle.\n\nThe following two theorems | will be assumed in this work; simple\ncases of them appear ob\\ dous from geometrical intuitions and,\ngenerally, theorems of a similar nature will be taken for granted, as\nformal proofs are usually extremely long and difficult.\n\n* Due to Mansion, Mathesis, (2) xix. (1899), pp. 129-131.\n\nt For a proof that the sine and cosine are continuous functions, see\nthe Appendix, § A-41. + Formal proofs will be found in Watson's\nComplex Integration and Cauchy's Theorem. (Cambridge Math. Tracts, No.\n15.)\n\n%\n% 44\n%\n\n(I) A simple closed curve divides the plane into two continua (the '\ninterior ' and the ' exterior '). '\n\n(II) If P be a point on the curve and Q be a point not on the curve,\nthe angle between QP and Ox increases by + 27r or by zero, as P\ndescribes the curve, according as Q is an interior point or an\nexterior point. If the increase is + 27r, P is said to describe the\ncurve ' counterclockwise.'\n\nA continuum formed by the interior of a simple curve is sometimes\ncalled an open two-dimensional region, or briefly an open region, and\nthe curve is called its boundary; such a continuum with its boundary\nis then called a closed two-dimensional region, or briefly a closed\nregion or domain.\n\nA simple curve is sometimes called a closed one-dimensional region; a\nsimple curve with its end-points omitted is then called an open\none-dimensional region.\n\n\\Subsection{3}{2}{2}{Continuous functions of complex variables.}\n\nLety\"( ) be a function of defined at all points of a closed region\n(one- or two-dimensional) in the Argand diagram, and let z be a point\nof the region.\n\nThen f(z) is said to be continuous at z, if given any positive number\ne, we can find a corresponding positive number 77 such that\n\n\\ f z)-f z,)\\ < e, whenever \\ z - Zx\\ < r) and 2- is a point of the\nregion.\n\n3'3. Series of variable terms. Uniformity of convergence.\n\nConsider the series\n\n  1 + a;2 (1+ ieO' (1 + T\n\nThis series converges absolutely \\hardsubsectionref{2}{3}{3}) for all real values of x. If\n8n ( ) be the sum of n terms, then ' >\n\n' \" \">= +\" -(TT ' /\n\nand so lim Sn x) = \\ \\ x'; xrf 0)\n\nbut Sn 0) = 0, and therefore lim Sn (0) = 0.\n\nM-*-00\n\nConsequently, although the series is an absolutely convergent series\nof continuous functions of x, the sum is a discontinuous function of\nx. We naturally enquire the reason of this rather remarkable\nphenomenon, which was investigated in 1841-1848 by Stokes*, Seidelf\nand Weierstrassj, who shewed that it cannot occur except in connexion\nwith another phenomenon, that of non-uniform convergence, which will\nnow be explained.\n\n* Cnmb. Phil. Trans, viii. (1847), pp. 533-583. [Collected Papers, i.\npp. 236-313.] t Mi'mchener Abhandlungen, v. (1848), p. 381. X Ges.\nMath. U'erke, i. pp. 67, 75.\n\n%\n% 45\n%\n\nLet the functions u (z), Wg (z), ... be defined at all points of a\nclosed region of the Argand diagram. Let\n\nSn (z) = U, (z) + M2 (2) + ...+ tin Z). '\n\noc\n\nThe condition that the series 2 Un z) should converge for any\nparticular\n\nn = l\n\nvalue of z is that, given e, a number n should exist such that\n\nI n+p z) - Sn (z)\\ < €\n\nfor all positive values of jo, the value of 7i of course depending on\ne.\n\nLet n have the smallest integer value for which the condition is\nsatisfied. This integer will in general depend on the particular value\nof z which has been selected for consideration. We denote this\ndependence by writing n (z) in place of ?i. Now it mag happen that we\ncan find a number N,\n\nINDEPENDENT OF Z, SUch that\n\nn z)<N \"' '\"\n\nfor all values of z in the region under consideration.\n\nIf this number N exists, the series is said to converge uniformly\nthroughout the region.\n\nIf no such number iV exists, the convergence is said to be\nnon-uniform*.\n\nUniformity of convergence is thus a property depending on a whole set\nof values of z, whereas previously we have considered the convergence\nof a series for various particular values of z, the convergence for\neach value being con- sidered without reference to the other values.\n\nWe define the phrase ' uniformity of convergence near a point z ' to\nmean that there is a definite positive number 8 such that the series\nconverges uniformly in the domain common to the circle \\ z - z \\ \\ h\nand the region in which the series converges.\n\n\\Subsection{3}{3}{1}{On the condition for uniformity of convergence' .}\n\nIf Rn,p z) = Un+i z) + iin+2 (z) + ... + Un+p (z), WO have Seen that\nthe\n\nnecessary and sufficient condition that S Un (z) should converge\nuniformly\n\nin a region is that, given any positive number e, it should be\npossible to choose N INDEPENDENT OF z (but depending on e) such that\n\nI Rn, p(z)\\ < €\n\nfor ALL positive integral values of p.\n\n* The reader who is unacquainted with the concept of uniformity of\nconvergence will find it made much clearer by consultinf; Bromwich,\nIiijinite Series, Ch. vii, where an illuminating account of Osgood's\ngraphical investigation is given.\n\nt This section shews that it is indifferent whether uniformity of\nconvergence is defined by means of the partial remainder Rj p(z) or by\niJ (2). Writers differ in the definition taken as fundamental.\n\n%\n% 46\n%\n\nIf the condition is satisfied, by \\hardsubsectionref{2}{2}{2}, 8n z) tends to a limit, S\nz), say for each value of under consideration; and then, since e is\nindependent of p,\n\nand therefore, when n > iV,\n\nS (2) - Sn (Z) = I lim i v, p 2) - E v. n-N (z), /\n\nand so \\ S(z)-S iz)\\ < 2€.\n\nThus (writing e for e) a necessary condition for uniformity of\nconvergence is that \\ S z) - Sn (z) \\ < e, whenever n>N and N is\nindependent of z; the condition is also sufficient; for if it is\nsatisfied it follows as in \\hardsubsectionref{2}{2}{2} (I) that I R rp z) 1 < 2e, which, by\ndefinition, is the condition for uniformity.\n\nExample 1. Shew that, if x be real, the sum of the series\n\nX X X\n\nTODO\n\nis discontinuous at .r=0 and the series is non-uniformly convergent\nnear ' = 0.\n\nThe sum of the first n terms is easily seen to be 1; so when x - Q\nthe\n\nnx+i\n\nsum is; when a* 4=0, the sum is 1.\n\n1 ' The value of RnXx) = S x)-Sn x) is - -- if x O; so when x is\nsmall, say\n\n:r=one-hundred-milliouth, the remainder after a million terms is - or\nl-TTyTj\n\n100 + 1 the first million terms of the series do not contribute one\nper cent, of the sum. And in\n\ngeneral, to make < e, it is necessary to take\n\n° nx + 1\n\n7i>-(--l\n\nX \\ e\n\nCorresponding to a given e, no number N exists, independent of x, such\nthat n<N for all values of x in any interval including x =; for by\ntaking x sufficiently small we can make n greater than any number N\nwhich is independent of x. There is therefore non- uniform convergence\nnear,r = 0.\n\nExample 2. Discuss the series\n\nx n. n±V)x'''-\\ ]\n\nnZx + n x \\ + 7i- \\ fx y in which x is real.\n\nr.,,, . nx (n- ) X, . X,\n\nThe 7ith term can be written, 5-5 -, -;, . - q, so o (x) = n,\nand\n\nl+n\\ v l + n + \\ y X'' l+x''\n\n  W ] +(,i + 1)2 2\n\n[Note. In this example the sum of the series is not discontinuous at =\n0.] But (taking 6<i, and 4=0), \\ Rn x)\\ < e if e-i(?i + l) \\ x\\ < l-ir\nn+\\ f x; i.e. if ?i+l>| €-i + Ve-2-4 |.T|-l or ?t + l<J e-i-v'e = 3-4\n|:p|- .\n\n%\n% 47\n%\n\nNow it is not the case that the second inequality is satisfied for all\nvalues of n greater than a certain value and for all values of x; and\nthe first inequality gives a value of n(x) which tends to infinity as\nx- 0; so that, corresponding to any interval containing the point =0,\nthere is no number N' independent of x. The series, therefore, is\nnon-uniformly convergent near :i, = 0.\n\nThe reader will observe that n x) is discontinuous at .r = 0; for n\nx)- 'x> as .r- -0, but n(0) = 0.\n\n\\Subsection{3}{3}{2}{Connexion of discontinuity luith non-uniform convergence.}\n\nWe shall now shew that if a semes of continuous functions of z is\nuniformly convergent for all values of z in a given closed domain, the\nsum is a continuous function of z at all points of the domain.\n\nFor let the series be f(z) = it, z) + Wo (2 ) +  . . + Un z)+ ...- Sn\n(z) + Rn z), where Rn (z) is the remainder after n terms.\n\nSince the series is uniformly convergent, given any positive number e,\nwe\n\ncan find a corresponding integer n independent of z, such that | R ( )\n| < e\n\nfor all values of z within the domain.\n\nNow n and e being thus fixed, we can, on account of the continuity of\nSn (2 ), find a positive number rj such that\n\n\\ Sn(z)-S z')\\ < l€,\n\nwhenever \\ z - z' \\ < r . We have then\n\nl/( ) -/V) I = 1 [Sni ) - Sn z')] \\ + lRn(2)- Rn ) \\ < ! Sn z) -\nSn(z') I + I Rniz) \\ + | Rn z') |\n\n' < 6,\n\nwhich is the condition for continuity at z. Example 1. Shew that near\nx = the series\n$$\nTODO\n$$\nwhere i(vP)=a;, (a;) =;p \"~* - :p \"~,\n\nand real values of x are concerned, is discontinuous and non-uniformly\nconvergent.\n\nIn this example it is convenient to take a slightly different form of\nthe test; we shall shew that, given an arbitrarily small number f, it\nis possible to choose values of x, as small as we please, depending on\nn in such a way that | R [x) \\ is not less than e for any value of n,\nno matter how large. The reader will easily see that the existence of\nsuch values of x is inconsistent with the condition for uniformity of\nconvergence. i\\\n\nThe value of S ix) is .r\" \"-i; as n tends to infinity, S x) tends to\n1, 0, or - 1, accord- ing as x is positive, zero, or negative. The\nseries is therefore absolutely convergent for all values of or, and\nhas a discontinuity at .t' = 0.\n\n%\n% 48\n%\n\n1\n\nIn this series R x) = l-x ''-\\ x > 0); however great n may be, by\ntaking* x = e- (2\" - 1) we can cause this remainder to take the value\nl-e' which is not arbitrarily small. The series is therefore\nnon-uniformly convergent near .r = 0.\n\nExample 2. Shew that near z = the series\n\n il H-(l+2) -l l+(l + 2)\"\n\nis non-uniformly convergent and its sum is discontinuous. The nth term\ncan be written\n\nl-(l+3)\" 1-(1+Z)\"-\n\nl + (H-3) H-(l+z) -i' so the sum of the first n terms is, - - . Thus,\nconsidering real values of z greater\n\nthan - 1, it is seen that the sum to infinity is 1, 0, or - 1,\naccording as z is negative, zero,\n\nor positive. There is thus a discontinuity at 2 = 0. This\ndiscontinuity is explained by the\n\nfact that the series is non-uniformly convergent near 2=0; for the\nremainder after n terms\n\nin the series when z is positive is\n\n-2\n\nr+rr+2)\"'\n\nand, however great n may be, by taking z = ~, this can be made\nnumerically greater\n\n2\n\nthan -, which is not arbitrarilv small. The series is therefore\nnon-uniformlv con- 1-1-e'\n\nvergent near 2 = 0.\n\n\\Subsection{3}{3}{3}{The distinction between absolute and uyiiform convergence.}\n\nThe uniform convergence of a series in a domain does not necessitate\nits absolute convergence at any points of the domain, nor conversely.\nThus\n\nthe series S vz r converges absolutely, but (near z = 0) not uniformly\n;\n\n(1 + \")\"\n\nwhile in the case of the series\n\n =i z + n ' the series of moduli is\n\n1\n\n5\", =\n\n =i \\ n + Z'\\ \\ which is divergent, so the series is only\nconditionally convergent; but for all real values of z, the terms of\nthe series are alternately positive and negative and numerically\ndecreasing, so the sum of the series lies between the sum of its first\nn terms and of its first (n -f 1) terms, and so the remainder after n\nterms is numerically less than the nth. term. Thus we only need take a\nfinite number (independent of z) of terms in order to ensure that for\nall real values of z the remainder is less than any assigned number e,\nand so the series is uniformly convergent.\n\nAbsolutely convergent series behave like series with a finite number\nof terms in that we can multiply them together and transpose their\nterms.\n\n* This value of x satisfies the condition i a; | < 5 whenever 2rt - 1\n> log 5~i.\n\n%\n% 49\n%\n\nUniformly convergent series behave like series with a finite number of\nterms in that they are continuous if each term in the series is\ncontinuous and (as we shall see) the series can then be integrated\nterm by term.\n\n\\Subsection{3}{3}{4}{A condition, due to Weierstrass*, for uniform convergence.}\n\nA sufficient, though not necessary, condition for the uniform\nconvergence of a series may be enunciated as follows : -\n\nIf, for all values of z within a domain, the moduli of the terms of a\nseries *S' = Ui (z) + i<2 ( ) + W3 ( ) +    are respectively less\nthan the corresponding terms in a convergent series of positive terms\n\nwhere M is independent of z, then the series S is uniformly convergent\nin this region. This follows from the fact that, the series T being\nconvergent, it is always possible to choose n so that the remainder\nafter the first n terms of T, and therefore the modulus of the\nremainder after the first n terms of *Si, is less than an assigned\npositive number e; and since the value of n thus found is independent\nof z, it follows \\hardsubsectionref{3}{3}{1}) that the series S is uni- formly convergent\n; by § 234, the series S also converges absolutely.\n\nExample. The .scries\n\n1 ., 1,\n\ncos Z +, CO.S- 2+57, CO.S-* Z- ...\n\nis uniformly convergent for all re<il values of r, because the moduli\nof its terms are not greater than the corresi)onding terms of the\nconvergent series\n\nI i whose terms are positive constants.\n\n3 341 . Uniformity of convergence of infinite products t.\n\nA convergent product n 1 + ?< (z) is said to converge uniformly in a\ndomain of values\n\nM=l\n\nof z if, given e, we can tind m independent of z such that\n\nn 1 + (z) - n i+u z) \\ < €\n\nfor all positive integral values of p.\n\nThe only condition for imiformity of convergence which will be used in\nthis work is that the product converges uniformly if | m (s) | < J/\nwhere J/ is independent of 2 and\n\n2 J/ convei-ges.\n\nn = l\n\n* Abhandlungen aus der Funktionenlehre, p. 70. The test given by this\ncondition is usually described (e.g. by Osgood, Annals of Mathematics,\niii. j[1889), p. 130) as the M-test.\n\nt The definition is, effectively, that given by Osgood,\nFunktionentheorie, p. 462. The condition here given for uuiformity of\nconvergence is also established in that work.\n\nW. M. A. 4\n\n%\n% 50\n%\n\nTo prove the validity of the condition we observe that n (l + J/ )\nconverges \\hardsectionref{2}{7}),\n\nM = l\n\nand so we can choose m such that\n\nVl+p VI\n\nn l + M,, - n l + M <€;\n\nn = l )( = 1\n\nand then we have\n\nm+p m I I m p ni+p ~] I\n\nn l+un (.-) - n 1 +t< (s) =1 n 1 + (z) n i +u (z) - 1\n\n11=1 M=l I I n=l \\ \\ n=m+i J I\n\nm r ni+2> ~]\n\n n(i + 14) n i+i/ -i\n\nm=l L n = m+l J\n\nand the choice of ?h is independent of z.\n\n3 \"35. Hardy's tests for uniform convergence*.\n\nThe reader will see, from \\hardsubsectionref{2}{3}{1}, that if, in a given domain.\n\np\n\n2 a z) k where a (2) is\n\nreal and k is finite and independent of and 2, and if / (2) t + i (s)\nand fn )-\n\nuniformly as w - - oo, then 2 a z) f £) converges uniformly. t=i\n\nAlso that if where k is independent of 2 and 2 a (2) converges\nuniformly, then 2 a,j £) w (s) con-\n\nIi = l M = l\n\nverges uniformly. [To prove the latter, observe that m can be found\nsuch that\n$$\nTODO\n$$\nare numerically less than e\\ k; and therefore \\hardsubsubsectionref{2}{3}{0}{1})\n\n2 a (2) M (s) < e <,n+i (2)//(-< e, n=jn+l I\n\nand the choice of e and hi is independent of 2.]\n\n° cos nQ \"\" sin % 2, 2\n\n7t=l '* n = l 'i\n\nExample 1. Shew that, if S>0, the series\n\nconverge uniformly in the range\n\nS (9 27r - S.\n\nObtain the corresponding result for the series\n\n  (-)\"cos?i<9 ' ( - ) sin n6\n\n2i, 2,\n\nn=l n n=\\ n\n\nby writing O + n for .\n\nExample 2. If, when a a,' 6, | co,i (.1;) | < -j and 2 | < + i (.r) -\nco (.r) | <j('2, where\n\n)(=i\n\n 1, k.> are independent of n and .r, and if 2 a is a convergent\nseries independent of x,\n\nn=i\n\nthen 2 a,tC > (:*;) converges uniformly when a .r / . \\addexamplecitation{Hardy.}\n\nn = l\n\n* Proc. London Math. Soc. (2) iv. (1907), pp. 247-265. These results,\nwhich are generalisa- tions of Abel's theorem \\hardsubsectionref{3}{7}{1}, below), though\nwell known, do not appear to have been published before 1907. From\ntheir resemblance to the tests of Dirichlet and Abel for convergence,\nBromwich proposes to call them Dirichlet's and Abel's tests\nrespectively.\n\n%\n% 51\n%\n\n[For we can choose m, independent of .v, such that corollary, we have\n\nm+p I\n\n2 a < e, and then, l)y \\hardsubsubsectionref{2}{3}{0}{1}\n\nn=m+l I\n\nm+p I\n\n2 ttnOin ( ) I < ( 'l + ' '2) f ]\n\nn=m+l I\n\n\\Section{3}{4}{Discussion of a particular double series.}\n\nLet (1)1 and w. be any constants whose ratio is not purely real; and\nlet a be positive.\n\nThe series 2; r-, in which the summation extends over\n\nall positive and negative integral and zero values of in and n, is of\ngreat importance in the theory of Elliptic Functions. At each of the\npoints z = - 2mcoi - 2/10)2 the series does not exist. It can be shewn\nthat the series converges absolutely for all other values of if a > 2,\nand the convergence is uniform for those values of z such that; 2 +\n2niQ)i + 2nco2 8 for all integral values of m and n, where 8 is an\narbitrary positive number.\n\nLet S' denote a summation for all integral values of m and n, the term\nfor which 7n = n = being omitted.\n\nNow, if ni and n are not both zero, and if \\ z + 2m(o + 2nco.2\\ \" 8 >\nfor all integral values of m and n, then we can find a positive number\nC. de- pending on B but not on 2, such that\n\nI 1 !\n\n(z + 2w\\&)i + 2 a)a)''\n\n 2m(Oi + 2710)2)\"\n\nConsequently, by \\hardsubsectionref{3}{3}{4}, the given series is absolutely and uniformly*\nconvergent in the domain considered if\n\n2' 1\n\nI mcoi + no)2 1 \" converges.\n\nTo discuss the convergence of the latter series, let\n\n0), = CTj 4- 1/3,, 0)0 = Qfo + z'/So,\n\nwhere a, a.,, /3i, /Sa are real. Since co../ coi is not real, a /S. -\nou/3i 4= 0. Then the series is\n\n2'\n\n (a,m + aojiy- + /3,m + /SoTi) *\n\nThis converges \\hardsectionref{2}{5} corollary) if the series\n\nS = ' i - -\n\n(m-+n2)\n\nconverges; for the quotient of corresponding terms is\n\nThe reader will easily define uniformity of convergence of double\nseries (see \\hardsectionref{3}{5}).\n\n4-2\n\n%\n% 52\n%\n\nwhere /z = njm. This expression, qua function of a continuous real\nvariable jx, can be proved to have a positive minimum* (not zero)\nsince ofi/3o - ao/3i =|=; and so the quotient is always greater than\na positive number K (independent of/x).\n\nWe have therefore only to study the convergence of the series S. Let\n\nPI 1\n\nV V S'\n\n 'p,q\n\n00 00 1\n\n 4 S S' -, .\n\nm = n=0 (m + 71 )2 *\n\nSeparating Sp g into the terms for which m = n, m > n, and m < n, re-\nspectively, we have\n\npi p m-l 1 q n-1 1\n\nIS. = S - I- s S - + s s .\n\n'% 1 ml\n\nBut S r- <\n\nn=o ni\" + n ) \"- (m ) \"\n\nm°\n\nTherefore IS t -J- + S - + i .\n\nBut these last series are known to be convergent if a - 1 > 1. So the\nseries S is convergent if a > 2. The original series is therefore\nabsolutely and uni- formly convergent, when a > 2, for the specified\nrange of values of z.\n\nExample. Prove that the series\n\n1\n\n2\n\n(mj + 7112 + . . . + my?y\n\nin which the summation extends over all positive and negative integral\nvalues and zero values of mj, m2, ... wi, except the set of\nsimultaneous zero values, is absolutely convergent if fi>ir.\n\\addexamplecitation{Eisenstein, Journal fur Math, xxxv.}\n\n\\Section{3}{5}{The concept of uniformity.}\n\nThere are processes other than that of summing a series in which the\nidea of uniformity is of importance.\n\nLet e be an arbitrary positive number; and let f z, ) be a function of\ntwo variables z and, which, for each point z oi a, closed region,\nsatisfies the inequality \\ f z, ) | < 6 when t, is given any one of a\ncertain set of values which will be denoted by ( z); the particular\nset of values of course depends on the particular value of z under\nconsideration. If a set ( )o can be found such that every member of\nthe set ( )o is a member of all the sets ( j), the function f z, ) is\nsaid to satisfy the inequality uniformly for all points z of\n\n* The reader will find no difficulty in verifying this statement; the\nminimum value in question is given by\n\nK \"' = h W + a + . + r- (a,-/3,r-+(a2 +,3i)=l (ai + /32)2+ (a - iP ]-\n\n%\n% 53\n%\n\nthe region. And if a function (f> z) possesses some property, for\nevery positive value of e, in virtue of the inequality \\ f z, ):<e,(f)\n(z) is then said to possess the property uniformly.\n\nIn addition to the uniformity of convergence of series and products,\nwe shall have to consider uniformity of convergence of integrals and\nalso uniformity of continuity; thus a series is uniformly convergent\nwhen \\ R, z)\\ <e, t( = 0 assuming integer values in- dependent of z\nonly.\n\nFurther, a function f(z) is continuous in a closed region if, given e,\nwe can find a I ositive number r/ such that 1/(2 + 2) -fi ) \\ <\nwhenever\n\n0<\\ C \\ < r and 2 + f is a point of the region.\n\nThe function will be uniformly continuous if we can find a positive\nnumber; inde- pendent of z, such that rjKr and \\ f z + C)~f ) i <\nwhenever\n\n0<UI<'7 and 2 + f is a point of the region, (in this case the set (f)o\nis the set of points whose moduli are less than r)).\n\nWe shall find later \\hardsubsectionref{3}{6}{1}) that continuity involves uniformity of\ncontinuity; this is in marked contradistinction to the fact that\nconvergence does not involve uniformity of convergence.\n\n36. The modified Heine-Borel theorem.\n\nThe following theorem is of great importance in connexion with\nproperties of uniformity; we give a proof for a one-dimensional\nclosed region*.\n\nGiven (i) a straight line CD and (ii) a latv by which, corresponding\nto each point f P of CD, we can determine a closed interval I P) of\nCD, P being an interior point of I (P).\n\nTlien the line CD can be divided into a finite number of closed\nintervals Ji, Jo, ... Jk, such that each interval Jr contains at least\none point not an end point) Pr, such that no point of Jr lies outside\nthe interval I (Pr) associated (by means of the given law) luitli that\npoint Pr§.\n\nA closed interval of the nature just described will be called a\nsuitable interval, and will be said to satisfy condition A).\n\nIf CD satisfies condition A ), what is required is proved. If not,\nbisect CD; if either or both of the intervals into which CD is\ndivided is not- suitable, bisect it or them||.\n\n* A formal proof of the tlieorem for a two-dimensional region will be\nfound in Watson's Complex Integration and Cauchy s Theorem (Camb.\nMath. Tracts, No. 15).\n\nt Examples of such laws associating intervals with points will be\nfound in §§ 3'61, 5'13.\n\nt Except when P is at C or D, when it is an end point.\n\n§ This statement of the Heine-Borel theorem (which is sometimes called\nthe Borel-Lebesgue theorem) is due to Baker, Proc. London Math. Soc.\n(2) i. (1904), p. 24. Hobson, The Theonj of Functions of a Real\nVariable (1907), p. 87, points out that the theorem is practically\ngiven in Goursat's proof of Cauchy's theorem Trans. American Math.\nSoc. i. (1900), j). 14); the ordinary form of the Heine-Borel theorem\nwill be found in the treatise cited.\n\nII A suitable interval is not to be bisected; for one of the parts\ninto which it is divided might not be suitable.\n\n%\n% 54\n%\n\nThis process of bisecting intervals which are not suitable either will\nterminate or it will not. If it does terminate, the theorem is proved,\nfor CD will have been divided into suitable intervals.\n\nSuppose that the process does not terminate; and let an interval,\nwhich can be divided into suitable intervals by the process of\nbisection just described, be said to satisfy condition (B).\n\nThen, by hypothesis, CD does not satisfy condition B); therefore at\nleast one of the bisected portions of CD does not satisfy condition\nB). Take that one which does not (if neither satisfies condition B)\ntake the left-hand one); bisect it and select that bisected part\nwhich does not satisfy condition B). This process of bisection and\nselection gives an unending sequence of intervals 5o, Si, S2, ... such\nthat :\n\n(i) The length of s is 2-\" Ci).\n\n(ii) No point of s,i+i is outside Sn-\n\n(iii) The interval s does not satisfy condition (-4).\n\nLet the distances of the end points of s from G be Xn, yn\\ then Xn <\na? +i < 2 i+i Hn- Therefore, by \\hardsectionref{2}{2}, x and yn have limits; and, by\nthe condition (i) above, these limits are the same, say; let Q be the\npoint whose distance from C is . But, by hypothesis, there is a number\nhq such that every point of CD, whose distance from Q is less than 5q,\nis a point of the associated interval /(Q). Choose n so large that t\nCDk 8q; then Q is an internal point or end point of Sn and the\ndistance of every point of Sn from Q is less than Sq. And therefore\nthe interval 5 satisfies condition (A), which is contrary to condition\n(iii) above. The hypothesis that the process of bisecting intervals\ndoes not terminate therefore involves a contradiction; therefore the\nprocess does terminate and the theorem is proved.\n\nIn the two-dimensional form of the theorem* the interval CD is\nreplaced by a closed two-dimensional region, the interval I P) by a\ncirclet with centre P, and the interval Jj. by a square with sides\nparallel to the axes.\n\n\\Subsection{3}{6}{1}{Uniformity of continuity.}\n\nFrom the theorem just proved, it follows without difficulty that if a\nfunction f(x) of a real variable x is continuous when a x b, then f(x)\nis unifurmly continuous throughout the range a x b.\n\nFor let e be an arbitrary positive number; then, in virtue of the\ncon- tinuity of f x), corresponding to any value of x, we can find a\npositive number S, depending on x, such that\n\n1/( 0 -/( O I < e\n\nfor all values of x' such that \\ x' - x\\ < Sx-\n\n* The reader will see that a proof may be constructed on similar lines\nby drawing a square circumscribing the region and carrying out a\nprocess of dividing squares into four equal squares.\n\nt Or the portion of the circle which lies inside the region.\n\n:J: This result is due to Heine; see Journal fiir Math. lxxi. (1870),\np. 361, and lxxiv. (1872), p. 188.\n\n%\n% 55\n%\n\nThen by § 3\"G we can divide the range (a, b) into a finite number of\nclosed intervals with the property that in each interval there is a\nnumber Xi such\n\nthat \\ fioc') - f xx) \\ < -€, whenever x lies in the interval in which\na;, lies.\n\nLet So be the length of the smallest of these intervals; and let f,\n|' be any two numbers in the closed range (a, 6) such that | - ' | <\no- Then, f ' lie in the same or in adjacent intervals; if they lie\nin adjacent intervals let, be the common end point. Then we can find\nnumbers x, Xo, one in each interval, such that\n\n\\ f )-f .)\\ < \\ e,,/(?o)-/(- 0 < f>\n\n' /(r ) -/( e) \\ < \\ \\, fit) -fu i < 5 6,\n\nso that\n\ni/(i) -/(r) =, /(B -fM] - [fit) -fM]\n\n- /(r)-/( -.) + /( o)-/( .) i\n\n< 6.\n\nIf, ' lie in the same interval, we can prove similarly that\n\ni/( )-/(r)i<2 -\n\nIn either case we have shewn that, for (iny number in the range, we\nhave\n\n\\ f( )-f +0 <e whenever + is in the range and -Bo< < Bq, where So is\nindependent of . The uniformity of the continuity is therefore\nestablished.\n\nCorollary (i). From the two-dimensional form of the theorem of \\hardsectionref{3}{6}\nwe can prove that a function of a complex variable, continuous at all\njwints of a closed region of the Argand diagram, is uniformly\ncontinuous throughout that region.\n\nCorollary (ii). A function f(x) which is continuous throughout the\nrange a x b is bounded in the range; that is to say we can find a\nnumber k independent of x such that \\ f(x) ! <K for all points x in\nthe range.\n\n[Let n be the number of parts into which the range is divided.\n\nLet, i, 2>  In-ij be their end points ] then if x be any point of\nthe rth interval we can find numbers Xi, x-i, ... Xn such that\n\nl/( )-/(- 'i)|<, l/(.i-i)-/'(li)|<i, l/( i)-/(' 2)|<ie, l/(. 2)-/(\n2)|<if,...\n\n \\ f ryi)-f x)\\ < h. Therefore \\ f a)-f x) |< ire, and so\n\nwhich is the required result, since the right-hand side is independent\nof x.\"]\n\nThe corresponding theorem for functions of complex variables is left\nto the reader.\n\n\\Subsection{3}{6}{2}{A real function, of a real variable, continuous\n  in a closed interval, attains its upper bound.}\n\nLet f(x) be a real continuous function of x when a x b. Form a section\nin which the i?-class consists of those numbers r such that r >f x)\n\n%\n% 56\n%\n\nfor all values of x in the range (a, h), and the X-class of all other\nnumbers. This section defines a number a such that f(x) a., but, if h\nbe any positive number, values of x in the range exist such that\nf(x)>a - 8. Then a is called the upper bound oi f x); and the theorem\nstates that a number x' in the range can be found such thai f(x) = a.\n\nFor, no matter how small h may be, we can find values of x for which\n|/( ) - aj\" >'8~; therefore | /(. ) - a| |~ is not bounded in the\nrange; therefore \\hardsubsectionref{3}{6}{1} cor. (ii)) it is not continuous at some point\nor points of the range; but since | f(x) - a | is continuous at all\npoints of the range, its re- ciprocal is continuous at all points of\nthe range \\hardsectionref{3}{2} example) except those points at which f(x) = a',\ntherefore f(x) = a at some point of the range; the theorem is\ntherefore proved.\n\nCorollary (i). The lower bound of a continuous function may be defined\nin a similar manner; and a continuous function attains its lower\nbound.\n\nCorollary (ii). If /( ) be a function of a complex variable continuous\nin a closed region, | f(z) \\ attains its upper bound.\n\n\\Subsection{3}{6}{3}{A real function, of a real variable, continuous\n  in a closed interval, attains all values between its upper and\n  lower bounds.}\n\nLet 31, m be the upper and lower bounds off x); then we can find\nnumbers X, -v, by § 362, such that/( ) = M,f x) = m; let //. be any\nnumber such that m< fjb< M. Given any positive number e, we can (by §\n3-61) divide the range (x, x) into 'A finite number, r, of closed\nintervals such that\n\nl/(.r,'-')-/(*2' ')|<6,\n\nwhere a i\"\"*, iCjC* are any points of the rth interval; take -i**\"',\nx./'' to be the end points of the interval; then there is at least\none of the intervals for which /(*'!<' ') - f,f(x.J ) - /x have\nopposite signs; and since\n\n|[/(,<'-')-/z - /(,\"-))- j|<6,\n\nit follows that j /(aa\"\"') - /ii\\ < e.\n\nSince we can find a number i'''* to satisfy this inequality for all\nvalues of 6, no matter how small, the lower bound of the function \\\nf(x)-fA,\\ is zero; since this is a continuous function of x, it\nfollows from \\hardsubsectionref{3}{6}{2} cor. (i) that/( ) - yLt vanishes for some value of\n. .\n\n\\Subsection{3}{6}{4}{The fluctuation of a function of a real variable*.}\n\nLet/(;) be a real bounded function, defined when a x b. Let\n\na Xi X2 ... : Xn b. Then I /(a) -f(x,) \\ + \\ f(x,) -f(x,) | + ... +\nl/C J -f(b) | is called the fluctuation oi f(x) in the range (a, b)\nfor the set of subdivisions x, X2, ... Xn.\n\nThe terminology of tliis section is partly that of Hobson, The Theory\nof Functions of a Real Variable (1907) and partly that of Young, The\nTheory of Sets of Points (190(5).\n\n%\n% 57\n%\n\nIf the fluctuation have an upper bound FJ*, independent of n, for all\nchoices of iCi, j-o, ... Xn, then f(x) is said to have limited total\nfluctuation in the range (a, h). Fa!' is called the total fluctuation\nin the range.\n\nExample 1. If f(x) be monotonic* in the range (a, b), its total\nfluctnation in the range is|/(a)-/(6)|. '>i\n\nExample 2. A fimction with limited total fluctuation can be expressed\nas the differ- ence of two positive increasing monotonic functions.\n\n[These function.s may be taken to be | Fa' +fix), h Fa'-f x) .]\n\nExample 3. If f(x) have limited total fluctuation in the range a, b),\nthen the limits f x±0) exist at all points in the interior of the\nrange. [See \\hardsectionref{3}{2} example.]\n\nExample 4. li f x\\ g x) have limited total fluctuation in the range\n(a, b) so has f x)g x).\n\n[For \\ f x')g x')-f x)g x)\\ \\ \\ f :>f). \\ g x')-g x)\\ + \\ g ) \\ f\n')-fi. )l and so the total fluctuation of f(x) g x) cannot exceed g .\nFJ'+f. G K where g are the upper bounds of |/( ) |, \\ g (x) \\ .]\n\n- 3'7. Uniformity of convergence of power series. Let the power\n.series\n\nao + tti;-!- ... +an2\"+  '\n\nconverge absolutely when z = Zo.\n\nThen, if\nTODO\n\nBut since S | anZj\" ' converges, it follows, by \\hardsubsectionref{3}{3}{4}, that S ttn \"\nconverges\n\nw = ' 71 =\n\nuniformly with regard to the variable z when \\ z \\ Zq.\n\nHence, by \\hardsubsectionref{3}{3}{2}, a power series is a continuous function of the\nvariable throughout the closed region formed by the interior and\nboundary of any circle concentric with the circle of convergence and\nof smaller radius \\hardsectionref{2}{6}).\n\n\\Subsection{3}{7}{1}{Abel's theorem TODO on continuity up to the\n  circle of convergence.}\n\n00\n\nLet S a,j \" be a po ver series, whose radius of convergence is unity,\nand\n\nM =\n\ncc\n\nlet it be such that S a converges; and let a; 1; then Abel's theorem\n\nTODO\n\nFor, with the notation of \\hardsubsectionref{3}{3}{5}, the function x satisfies the\nconditions\n\n00\n\nlaid on u, x), when 0 a; l; consequently /(a:;) = 2 On \" converges\nuni-\n\nM =\n\n* The function is monotonic if f x)-f x')\\ \\ x-x') is one-signed or\nzero for all pairs of different values of .r and x' .\n\nt Journal fiir Math. i. (1826), pp. 311-339, Theorem iv. Abel's proof\nemploys directlj' the arguments by which the theorems of \\hardsubsectionref{3}{3}{2} and §\n3-35 are proved. In the case when S | a I converges, the theorem is\nobvious from \\hardsectionref{3}{7}.\n\n%\n% 58\n%\n\nformly throughout the range a;: 1; it is therefore, by \\hardsubsectionref{3}{3}{2}, a\ncontinuous function of x throughout the range, and so lim f x)=f l),\nwhich is the\n\na;-*l-0\n\ntheorem stated.\n\n\\Subsection{3}{7}{2}{Abel's theorem* on multiplication of series.}\n\nThis is a modification of the theorem of \\hardsubsectionref{2}{5}{3} for absolutely\nconvergent series.\n\nLet Cn = ttohn + i \\& \\ i + . . . + an 0\n\nThen the convergence of \" an, S bn and 2 c is a sufficient condition\nthat\n\nTODO\n\nFor, let,\n\n (a;)= 2 an B(x)= 2 6na \", C(a.')-= i CnX''. n=0 n=0 M=0\n\nThen the series for A (x), B x), C(x) are absolutely convergent when I\nI < 1, \\hardsectionref{2}{6}); and consequently, by \\hardsubsectionref{2}{5}{3},\n\nA(x)B(x)=C x) when < < 1; therefore, by \\hardsectionref{2}{2} example 2,\n\n  lim A x)] lim B(x) = lim C(x)\\\n\na; .l-0 a;- -l-0 x -l-O\n\nprovided that these three limits exist; but, by \\hardsubsectionref{3}{7}{1}, these three\nlimits are\n\nTODO, and the theorem is proved.\n\nn=0 w = w=0\n\n\\Subsection{3}{7}{3}{Power series which vanish identically.}\n\nIf a convergent poiver seynes vanishes for all values of z such that \\\nz\\ r-, where r > 0, then all the coefficients in the power series\nvanish.\n\nFor, if not, let a be the first coefficient which does not vanish.\n\nThen am + '7/t+i + m+2' \"+ ... vanishes for all values of z (zero\nexcepted) and converges absolutely when \\ z\\ \\ r<r; hence, if s = a\n+i + a,n+2Z + . . ., we have\n\n00\n\nI S I Z, I (ljn-|-7i I T, >j = l\n\nand so we can findf a positive number S r such that, whenever | | S,\n\nI, 2 \\ L I 1 ' I\n\nI ( m+i + ( f\"m+2 +    1 2' '\" I '\n\nand then | a + s | | m | - ! ' ' > i a.m\\, and so a, + s =f when \\ z\n\\ < S.\n\n* Journal filr Math. i. (1826), pp.;:ili-339, Theorem vi. This is\nAbel's original proof. In some text-books a more elaborate proof, by\nthe use of Cesaro's sums \\hardsubsectionref{8}{4}{3}), is given.\n\n%\n% 59\n%\n\nWe have therefore arrived at a contradiction by supposing that some\ncoefficient does not vanish. Therefore all the coefficients vanish.\n\nCorollary 1. \"We may 'equate corresponding coefficients' in two power\nseries whose sums are equal throughout the region 1 |<S, where 8>0.\n\nCorollary 2. We may also equate coefficients in two power series which\nare proved equal only when z is real.\n\nREFERENCES.\n\nT. J. 1'a. Bromwich, Theory of Infinite Series (1908), Ch. vii.\n\nE. Goursat, Cours d'Analyse (Paris, 1910, 1911), Chs. i, xiv.\n\nC J. DE LA Vall e Poussin (Louvain and Paris, 1914), Cours d Analyse\nInfinitesimale, Introduction and Ch. viii.\n\nG. H. Hardy, A course of Pure Mathematics (1914), Ch. v.\n\nVV. F. Osgood, Lehrbiich der Funktionentheorie (Leipzig, 1912), Chs.\nii, iii.\n\nG. N. Watson, Complex Integration and Cauchy's Theorem (Camb. Math.\nTracts, No. 15), (1914), Chs. I, II.\n\nMiscellaneous Examples.\n\n1. Shew that the series\n\n =l(l-2 )(l-2 l)\n\nis equal to,-, -. when 1 2 I < 1 and is equal to,, -, when 1 2 1 >\n1.\n\n  zy z z)-\n\nIs this fact connected with the theory of uniform convergence ?\n\n2. Shew that the series\n\n2sini + 4sinl + ... + 2\"sin + ...\n\nconverges absolutely for all values of z z = excepted), but does not\nconverge uniformly near 2=0.\n\n3. If Un x)=-2 n-\\ f .re-'\"-''' ' + n xe''' '''',\n\nshew that 2 ?< x) does not converge uniformly near x=0.\n\\addexamplecitation{Math. Trip. 1907.}\n\nn = \\\n\n4. Shew that the series -pr j- + -r -... is convergent, but that its\nsquare (formed\n\nby Abel's rule)\n\nT 2+1,73 + 2; U'4' vW -\n\nis divergent.\n\n5. If the convergent series 5=- - - +---+... (r>0) be multiplied by\nitsel,\n\nthe teiTus of the product being arranged as in Abel's result, shew\nthat the resulting series diverges if r | but converges to the sum s \\\ni r>. \\addexamplecitation{Cauchy and Cajori.}\n\n%\n% 60\n%\n\n6. If the two conditionally convergent series\n\n2 - and 2\n\nn=i W =i n'\n\nwhere r and s lie between and 1, be multiplied together, and the\nproduct an-anged as in Abel's result, shew that the necessary and\nsufficient condition for the convergence of the resulting series is r\n+ s >1. \\addexamplecitation{Cajori.}\n\n7. Shew that if the series 1 - 3 + 5 - t +\n\nbe multiplied by itself any number of times, the terms of the product\nbeing arranged as in Abel's result, the resulting series converges.\n\\addexamplecitation{Cajori.}\n\n8. Shew that the qth. power of the series\n\n ! sin d+a sin 2 + ... +a,i sin n6 + ... is convergent whenever 5- (1\n- r)< 1, r being the greatest number satisfying the relation\n\nfor all values of n.\n\n9. Shew that if 6 is not equal to or a multiple of 2n, and if %0) Ui,\nu, ...he a sequence such that u - O steadily, then the series 2i/ cos\nnd + a) is convergent.\n\nShew also that, if the limit of t< is not zero, but ?i is still\nmonotonic, the sum of the\n\nS\n\nseries is oscillatory if - is rational, but that, if - is irrational,\nthe sum may have any value\n\nTT TT\n\nbetween certain bounds whose difference is a cosec 6, where a= lim u -\n\n\\addexamplecitation{Math. Trip., 1896.}\n", "meta": {"hexsha": "ef4c2172d89a2ed1f32fd82b75fedbfe100744b5", "size": 44665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch03.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-ch03.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-ch03.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": 30.9743411928, "max_line_length": 91, "alphanum_fraction": 0.7042203067, "num_tokens": 13387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6090468852989066}}
{"text": "\\lab{Linear Transformations}{Linear Transformations}\n\\objective{Linear transformations are the most basic and essential operators in vector space theory.\nIn this lab we visually explore how linear transformations alter points in $\\mathbb{R}^2$.\nWe then empirically explore the computational cost of applying linear transformations via matrix multiplication.\n}\n\n\\section*{Linear Transformations} % ===========================================\n\nA \\emph{linear transformation} is a mapping between vector spaces that preserves addition and scalar multiplication.\nMore precisely, let $V$ and $W$ be vector spaces over a common field $\\mathbb{F}$.\nA map $L:V\\rightarrow W$ is a linear transformation from $V$ into $W$ if\n\\[L(a\\x_1 + b\\x_2) = aL\\x_1 + bL\\x_2\\] for all vectors $\\x_1,\\ \\x_2 \\in V$ and scalars $a,\\ b \\in \\mathbb{F}$.\n\nEvery linear transformation $L$ from an $m$-dimensional vector space into an $n$-dimensional vector space can be represented by an $m\\times n$ matrix $A$, called the \\emph{matrix representation} of $L$.\nTo apply $L$ to a vector $\\x$, left multiply by its matrix representation.\nThis results in a new vector $\\x^\\prime$, where each component is some linear combination of the elements of $\\x$.\nFor linear transformations from $\\mathbb{R}^2$ to $\\mathbb{R}^2$, this process has the following form.\n%\n\\begin{align*}\nA\\x =\n\\left[\\begin{array}{cc}\na & b \\\\\nc & d \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nx\\\\y\n\\end{array}\\right]\n=\n\\left[\\begin{array}{cc}\nax + by \\\\cx + dy\n\\end{array}\\right]\n=\n\\left[\\begin{array}{cc}\nx^\\prime \\\\y^\\prime\n\\end{array}\\right]\n= \\x^\\prime\n\\end{align*}\n\nLinear transformations can be interpreted geometrically.\nTo demonstrate this, we examine a set of points that collectively form a picture of a horse, stored in the file \\texttt{horse.npy}.\nThe coordinate pairs are organized by column, so the array has two rows: one for $x$-coordinates, and one for $y$-coordinates.\n%\n\\begin{align*}\n\\left[\\begin{array}{cccc}\nx_1 & x_2 & x_3 & \\ldots \\\\\ny_1 & y_2 & y_3 & \\ldots \\\\\n\\end{array}\\right]\n\\end{align*}\n\nUse \\li{np.load()} to extract the array from the \\texttt{.npy} file, then plot the points as individual pixels.\nSee Figure \\ref{fig:linearly-transformed-horses} for the result.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n\n# Load the array from the .npy file.\n>>> data = np.load(\"horse.npy\")\n\n# Plot the x row against the y row with black pixels.\n>>> plt.plot(data[0], data[1], 'k,')\n\n# Set the window limits to [-1, 1] by [-1, 1] and make the window square.\n>>> plt.axis([-1,1,-1,1])\n>>> plt.gca().set_aspect(\"equal\")\n>>> plt.show()\n\\end{lstlisting}\n\n\\subsection*{Types of Linear Transformations} % -------------------------------\n\nLinear transformations from $\\mathbb{R}^2$ into $\\mathbb{R}^2$ can be classified in a few ways.\n\n\\begin{itemize}\n\n\\item \\textbf{Stretch}: %$L(x,y) \\mapsto (ax,by)$.\nStretches or compresses the vector along each axis.\nThe matrix representation is diagonal:\n%\n\\begin{align*}\n\\left[\\begin{array}{rr}\na & 0  \\\\\n0 & b\n\\end{array}\\right]\n\\end{align*}\n%\nIf $a=b$, the transformation is called a \\emph{dilation}.\nThe stretch in Figure \\ref{fig:linearly-transformed-horses} uses $a = \\frac{1}{2}$ and $b = \\frac{6}{5}$ to compress the $x$-axis and stretch the $y$-axis.\n\n\\item \\textbf{Shear}: %$L(x,y) \\mapsto (x + ay, y)$ or $L(x,y) \\mapsto (x, bx + y)$.\nSlants the vector by a scalar factor horizontally or vertically.\nThere are two matrix representations:\n% The corresponding matrix is a Type III elementary matrix.\n%\n\\begin{align*}\n\\text{horizontal shear:\\ }\n\\left[\\begin{array}{cc}\n1 & a\\\\\n0 & 1\n\\end{array}\\right]\n&&\n\\text{vertical shear:\\ }\n\\left[\\begin{array}{cc}\n1 & 0\\\\\nb & 1\n\\end{array}\\right]\n\\end{align*}\n%\nHorizontal shears skew the $x$-coordinate of the vector while vertical shears skew the $y$-coordinate.\nFigure \\ref{fig:linearly-transformed-horses} has a horizontal shear with $a=\\frac{1}{2}$.\n\n\\item \\textbf{Reflection}: Reflects the vector about a line that passes through the origin.\n% Also sometimes called a \\emph{Householder transformation}.\nThe reflection about the line spanned by the vector $\\left[a, b\\right]\\trp$ has the matrix representation\n%\n\\begin{align*}\n\\frac{1}{a^2 + b^2}\n\\left[\\begin{array}{cc}\na^2 - b^2 & 2ab \\\\\n2ab       & b^2 - a^2\n\\end{array}\\right].\n\\end{align*}\n%\nThe reflection in Figure \\ref{fig:linearly-transformed-horses} reflects the image about the $y$-axis ($a=0$, $b=1$).\n\n\\item \\textbf{Rotation}: %$L(x,y) \\mapsto (x\\cos\\theta-y\\sin\\theta,\\ x\\sin\\theta + y\\cos\\theta)$.\nRotates the vector around the origin.\nA counterclockwise rotation of $\\theta$ radians has the following matrix representation:\n%\n\\begin{align*}\n\\left[\\begin{array}{rr}\n\\cos\\theta & -\\sin\\theta\\\\\n\\sin\\theta &  \\cos\\theta\n\\end{array}\\right]\n\\end{align*}\n%\nA negative value of $\\theta$ performs a clockwise rotation.\nChoosing $\\theta = \\frac{\\pi}{2}$ produces the rotation in Figure \\ref{fig:linearly-transformed-horses}.\n\n\\end{itemize}\n\n\\begin{figure}[H] % Generated with horse_drawings() in plots.py.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/OriginalHorse.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/StretchHorse.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/ShearHorse.pdf}\n\\end{subfigure}\n\\\\\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/ReflectionHorse.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/RotationHorse.pdf}\n\\end{subfigure}\n%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/CompositionHorse.pdf}\n\\end{subfigure}\n\\caption{The points stored in \\texttt{horse.npy} under various linear transformations.}\n\\label{fig:linearly-transformed-horses}\n\\end{figure}\n\n\n\\begin{problem} % Implement linear transformations.\nWrite a function for each of the linear transformations listed above.\nEach function should accept an array to transform and the scalars that define the transformation ($a$ and $b$ for stretch, shear, and reflection, and $\\theta$ for rotation).\nConstruct the matrix representation and left multiply it with the input array.\nReturn the transformed array.\n\nTo test your functions, consider writing a separate function that plots two arrays (the original and the transformed) for a side-by-side comparison.\n\\label{prob:implement-linear-transformations}\n\\end{problem}\n\n\\begin{info} % Look ahead to the QR decomposition.\nReflections and rotations are two ways to implement the QR decomposition, an important matrix factorization that will be studied in another lab.\n\\end{info}\n\n\\subsection*{Compositions of Linear Transformations} % ------------------------\n\nLet $V$, $W$, and $Z$ be finite-dimensional vector spaces.\nIf $L:V\\rightarrow W$ and $K:W\\rightarrow Z$ are linear transformations with matrix representations $A$ and $B$, respectively, then the \\emph{composition} $KL:V\\rightarrow Z$ is also a linear transformation, and its matrix representation is the matrix product $BA$.\n\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.\nIn fact, any linear transformation $L:\\mathbb{R}^2 \\rightarrow\\mathbb{R}^2$ is a composition of the four transformations discussed above.\nFigure \\ref{fig:linearly-transformed-horses} displays the composition of all four previous transformations, applied in order (stretch, shear, reflection, then rotation).\n\n\\section*{Affine Transformations} % ===========================================\n\nAll linear transformations map the origin to itself.\nAn \\emph{affine transformation} is a mapping between vector spaces that preserves the relationships between points and lines, but that may not preserve the origin.\nEvery affine transformation $T$ can be represented by a matrix $A$ and a vector $\\b$.\nTo apply $T$ to a vector $x$, we calculate $A\\x + \\b$.\nIf $\\b = \\0$ then the transformation is linear, and if $A = I$ but $\\b\\neq\\0$ then it is called a \\emph{translation}.\n\nFor example, if $T$ is the translation with $\\mathbf{b} = \\left[\\frac{3}{4}, \\frac{1}{2}\\right]\\trp$, then applying $T$ to an image will shift it right by $\\frac{3}{4}$ and up by $\\frac{1}{2}$.\nThis translation is illustrated below.\n\n\\begin{figure}[H] % Generated with translated_horse() in plots.py.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/OriginalHorse.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.32\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/TranslationHorse.pdf}\n\\end{subfigure}\n\\end{figure}\n\nAffine transformations include all compositions of stretches, shears, rotations, reflections, and translations.\nFor example, if $S$ represents a shear and $R$ a rotation, and if $\\b$ is a vector, then $RS\\x + \\b$ shears, then rotates, then translates $\\x$.\n\n\\subsection*{Modeling Motion with Affine Transformations} % -------------------\n\nAffine transformations can be used to model particle motion, such as a planet rotating around the sun.\nLet the sun be the origin, the planet's location at time $t$ be given by the vector $\\p(t)$, and suppose the planet has angular momentum $\\omega$ (a measure of how fast the planet goes around the sun).\nTo find the planet's position at time $t$ given the planet's initial position $\\p(0)$, rotate the vector $\\p(0)$ around the origin by $t\\omega$ radians.\nThus if $R(\\theta)$ is the matrix representation of the linear transformation that rotates a vector around the origin by $\\theta$ radians, then \\[\\p(t) = R(t\\omega)\\p(0).\\]\n\nComposing the rotation with a translation shifts the center of rotation away from the origin, yielding more complicated motion.\n\n\\begin{problem} % Moon orbiting the earth orbiting the sun.\nThe moon orbits the earth while the earth orbits the sun.\nAssuming circular orbits, we can compute the trajectories of both the earth and the moon using only linear and affine transformations.\n\nAssume an orientation where both the earth and moon travel counterclockwise, with the sun at the origin.\nLet $\\p_e(t)$ and $\\p_m(t)$ be the positions of the earth and the moon at time $t$, respectively, and let $\\omega_e$ and $\\omega_m$ be each celestial body's angular momentum.\nFor a particular time $t$, we calculate $\\p_e(t)$ and $\\p_m(t)$ with the following steps:\n\n\\begin{enumerate}\n\\item Compute $\\p_e(t)$ by rotating the initial vector $\\p_e(0)$ counterclockwise about the origin by $t\\omega_e$ radians.\n\\item Calculate the position of the moon relative to the earth at time $t$ by rotating the vector $\\p_m(0) - \\p_e(0)$ counterclockwise about the origin by $t\\omega_m$ radians.\n\\item To compute $\\p_m(t)$, translate the vector resulting from the previous step by $\\p_e(t)$.\n\\end{enumerate}\n\nWrite a function that accepts a final time $T$ and the angular momenta $\\omega_e$ and $\\omega_m$.\nAssuming initial positions $\\p_e(0) = (10,0)$ and $\\p_m(0) = (11,0)$, plot $\\p_e(t)$ and $\\p_m(t)$ over the time interval $t \\in [0, T]$.\n\nThe moon travels around the earth approximately 13 times every year.\nWith $T = \\frac{3\\pi}{2}$, $\\omega_e = 1$, and $\\omega_m = 13$, your plot should resemble the following figure (use \\li{plt.gca().set_aspect(\"equal\")} to fix the aspect ratio).\n\\\\\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/SolarSystem.pdf}\n\\end{figure}\n\n\\label{prob:solar-system-trajectories}\n\\end{problem}\n\n\\section*{Timing Matrix Operations} % =========================================\n\nLinear transformations are easy to perform through simple matrix multiplication.\nHowever, performing matrix multiplication with very large matrices can strain a machine's time and memory constraints.\nFor the remainder of this lab we take an empirical approach in exploring how much time and memory different matrix operations require.\n\n\\subsection*{Timing Code} % ---------------------------------------------------\n\nThe \\li{time} module in the standard library include functions for dealing with time.\nThe module's \\li{time()} function measures the number of seconds from a fixed starting point, called ``the Epoch'' (January 1, 1970 for Unix machines).\n\n\\begin{lstlisting}\n>>> import time\n>>> time.time()\n1466609325.819298\n\\end{lstlisting}\n\nThe \\li{time()} function\\footnote{The \\li{clock()} function is similar to \\li{time()}, but it records more precision on Windows machines.} is useful for measuring how long it takes for code to run: record the time just before and just after the code in question, then subtract the first measurement from the second to get the number of seconds that have passed.\n\n\\begin{lstlisting}\n>>> def time_for_loop(iters):\n...     \"\"\"Time how long it takes to go through 'iters' iterations of nothing.\"\"\"\n...     start = time.time()         # Clock the starting time.\n...     for _ in range(int(iters)):\n...         pass\n...     end = time.time()           # Clock the ending time.\n...     return end - start          # Report the difference.\n...\n>>> time_for_loop(1e5)              # 1e5 = 100000.\n0.007936954498291016\n>>> time_for_loop(1e7)              # 1e7 = 10000000.\n0.8008430004119873\n\\end{lstlisting}\n\nThe standard library's \\li{timeit} module is built specifically to time code and has more sophisticated tools than the \\li{time} module.\nThe \\li{timeit()} function accepts a function handle (the name of the function to run) and the number of times to run it.\nAdditionally, in IPython the quick command \\li{\\%timeit} uses \\li{timeit.timeit()} to quickly time a single line of code.\n\n\\begin{lstlisting}\nIn [1]: import timeit\nIn [2]: def for_loop():\n   ...:     \"\"\"Go through 1e7 iterations of nothing.\"\"\"\n   ...:     for _ in range(int(1e7)):\n   ...:         pass\n\nIn [3]: timeit.timeit(for_loop, number=5) / 5.\nOut[3]: 0.8081045627593995\n\nIn [4]: %timeit for_loop()\n1 loop, best of 3: 801 ms per loop\n\\end{lstlisting}\n\n\\subsection*{Timing an Algorithm} % -------------------------------------------\n\nMost algorithms have at least one input that dictates the size of the problem to be solved.\nFor example, the following functions take in a single integer $n$ and produce a random vector of length $n$ as a list or a random $n\\times n$ matrix as a list of lists.\n\n\\begin{lstlisting}\nfrom random import random\ndef random_vector(n):       # Equivalent to np.random.random(n).tolist()\n    \"\"\"Generate a random vector of length n as a list.\"\"\"\n    return [random() for i in xrange(n)]\n\ndef random_matrix(n):       # Equivalent to np.random.random((n,n)).tolist()\n    \"\"\"Generate a random nxn matrix as a list of lists.\"\"\"\n    return [[random() for j in xrange(n)] for i in xrange(n)]\n\\end{lstlisting}\n\nExecuting \\li{random_vector(n)} calls \\li{random()} $n$ times, so doubling $n$ should about double the amount of time \\li{random_vector(n)} takes to execute.\nBy contrast, executing \\li{random_matrix(n)} calls \\li{random()} $n^2$ times ($n$ times per row with $n$ rows).\nTherefore doubling $n$ will likely more than double the amount of time \\li{random_matrix(n)} takes to execute, especially if $n$ is large.\n\nTo visualize this phenomenon, we time \\li{random_matrix()} for $n = 2^1,\\ 2^2,\\ \\ldots,\\ 2^{12}$ and plot $n$ against the execution time.\nThe result is displayed below on the left.\n\n\\begin{lstlisting}\n>>> domain = 2**np.arange(1,13)\n>>> times = []\n>>> for n in domain:\n...     start = time.time()\n...     random_matrix(n)\n...     times.append(time.time() - start)\n...\n>>> plt.plot(domain, times, 'g.-', linewidth=2, markersize=15)\n>>> plt.xlabel(\"n\", fontsize=14)\n>>> plt.ylabel(\"Seconds\", fontsize=14)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % Generated with timing_demo() in plots.py.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/time_random_matrix1.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/time_random_matrix2.pdf}\n\\end{subfigure}\n\\end{figure}\n\nThe figure on the left shows that the execution time for \\li{random_matrix(n)} increases quadratically in $n$.\nIn fact, the blue dotted line in the figure on the right is the parabola $y = an^2$, which fits nicely over the timed observations. Here $a$ is a small constant, but it is much less significant than the exponent on the $n$.\nTo represent this algorithm's growth, we ignore $a$ altogether and write \\li{random_matrix(n)} $\\sim n^2$.\n% \\footnote{In precise mathematical terms, we might write \\li{random_matrix(n)} $\\in O(n^2)$. See Chapter 1 of Volume II for more details on Big-O notation.}\n\n\\begin{problem} % Time Matrix-Vector and Matrix-Matrix Multiplication.\nLet $A$ be an $m \\times n$ matrix with entries $a_{ij}$, $\\x$ be an $n \\times 1$ vector with entries $x_k$, and $B$ be an $n \\times p$ matrix with entries $b_{ij}$.\n%\n% \\begin{align*}\n% A = \\left[\\begin{array}{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{array}\\right]\n% &&\n% \\x = \\left[\\begin{array}{c}\n% x_1 \\\\ x_2 \\\\ \\vdots \\\\ x_n\n% \\end{array}\\right]\n% &&\n% B = \\left[\\begin{array}{cccc}\n% b_{11} & b_{12} & \\cdots & b_{1p} \\\\\n% b_{21} & b_{22} & \\cdots & b_{2p} \\\\\n% \\vdots & \\vdots & \\ddots & \\vdots \\\\\n% b_{n1} & b_{n2} & \\cdots & b_{np}\n% \\end{array}\\right]\n% \\end{align*}\n\nThe matrix-vector product $A\\x = \\y$ is a new $m \\times 1$ vector and the matrix-matrix product $AB = C$ is a new $m \\times p$ matrix.\nThe entries $y_i$ of $\\y$ and $c_{ij}$ of $C$ are determined by the following formulas:\n%\n\\begin{align*}\ny_i = \\sum_{k=1}^n a_{ik}x_k%,\\qquad i = 1,\\ 2,\\ \\ldots,\\ m.\n&&\nc_{ij} = \\sum_{k=1}^n a_{ik}b_{kj}%,\\quad i = 1,\\, 2,\\, \\ldots,\\ m, \\quad j = 1,\\, 2\\, \\ldots,\\ l.\n\\end{align*}\n\nBelow, we implement these multiplication formulas without using NumPy.\n\n\\begin{lstlisting}\ndef matrix_vector_product(A, x):    # Equivalent to np.dot(A,x).tolist()\n    \"\"\"Compute the matrix-vector product Ax as a list.\"\"\"\n    m, n = len(A), len(x)\n    return [sum([A[i][k] * x[k] for k in range(n)]) for i in range(m)]\n\ndef matrix_matrix_product(A, B):    # Equivalent to np.dot(A,B).tolist()\n    \"\"\"Compute the matrix-matrix product AB as a list of lists.\"\"\"\n    m, n, p = len(A), len(B), len(B[0])\n    return [[sum([A[i][k] * B[k][j] for k in range(n)])\n                                    for j in range(p) ]\n                                    for i in range(m) ]\n\\end{lstlisting}\n\nUse \\li{time.time()}, \\li{timeit.timeit()}, or \\li{\\%timeit} to time each of these functions with increasingly large inputs.\nGenerate the inputs $A$, $\\x$, and $B$ with \\li{random_matrix()} and \\li{random_vector()} (so each input will be $n \\times n$ or $n \\times 1$).\nOnly time the multiplication functions, not the generating functions.\n\nReport your findings in a single figure with two subplots: one with matrix-vector times, and one with matrix-matrix times.\nChoose a domain for $n$ so that your figure accurately describes the growth, but avoid values of $n$ that lead to execution times of more than 1 minute.\nYour figure should resemble the following plots.\n\n\\begin{figure}[H] % Generated with prob1_solution() in plots.py.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/matrixVectorMultiplication.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.474\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/matrixMatrixMultiplication.pdf}\n\\end{subfigure}\n\\end{figure}\n\n\\label{prob:matrix-multiplication-timing}\n\\end{problem}\n\n\\subsection*{Logarithmic Plots} % ---------------------------------------------\n\nThe two plots from Problem \\ref{prob:matrix-multiplication-timing} look similar, but the actual execution times differ greatly.\nTo adequately compare the two, we need to view the results differently.\n\nA \\emph{logarithmic plot} uses a logarithmic scale---with values that increase exponentially, such as $10^1,\\ 10^2,\\ 10^3,\\ \\ldots$---on one or both of its axes.\nThe three kinds of log plots are listed below.\n\n\\begin{itemize}\n\\item \\textbf{log-lin}: the $x$-axis uses a logarithmic scale but the $y$-axis uses a linear scale.\\\\\nUse \\li{plt.semilogx()} instead of \\li{plt.plot()}.\n\\item \\textbf{lin-log}: the $x$-axis is uses a linear scale but the $y$-axis uses a log scale.\\\\\nUse \\li{plt.semilogy()} instead of \\li{plt.plot()}.\n\\item \\textbf{log-log}: both the $x$ and $y$-axis use a logarithmic scale.\\\\\nUse \\li{plt.loglog()} instead of \\li{plt.plot()}.\n\\end{itemize}\n\nSince the domain $n = 2^1,\\ 2^2,\\ \\ldots$ is a logarithmic scale and the execution times increase quadratically, we visualize the results of the previous problem with a log-log plot.\nThe default base for the logarithmic scales on logarithmic plots in Matplotlib is $10$.\nTo change the base to $2$ on each axis, specify the keyword arguments \\li{basex=2} and \\li{basey=2}.\n\nSuppose the domain of $n$ values are stored in \\li{domain} and the corresponding execution times for \\li{matrix_vector_product()} and \\li{matrix_matrix_product()} are stored in \\li{vector_times} and \\li{matrix_times}, respectively.\nThe following code produces Figure \\ref{fig:loglogdemo}.\n\n\\begin{lstlisting}\n>>> plt.subplot(121)        # Plot both curves on a lin-lin plot.\n>>> plt.plot(domain, vector_times, 'b.-', lw=2, ms=15, label=\"Matrix-Vector\")\n>>> plt.plot(domain, matrix_times, 'g.-', lw=2, ms=15, label=\"Matrix-Matrix\")\n>>> plt.legend(loc=\"upper left\")\n\n>>> plot.subplot(122)       # Plot both curves on a base 2 log-log plot.\n>>> plt.loglog(domain, vector_times, 'b.-', basex=2, basey=2, lw=2, ms=15)\n>>> plt.loglog(domain, matrix_times, 'g.-', basex=2, basey=2, lw=2, ms=15)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}[H] % Generated with loglog_demo() in plots.py.\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/loglogDemoBad.pdf}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/loglogDemoGood.pdf}\n\\end{subfigure}\n\\caption{ }\n\\label{fig:loglogdemo}\n\\end{figure}\n\nIn the log-log plot, the slope of the \\li{matrix_matrix_product()} line is about $3$ and the slope of the \\li{matrix_vector_product()} line is about $2$.\nThis reflects the fact that matrix-matrix multiplication (which uses 3 loops) is $\\sim n^3$, while matrix-vector multiplication (which only has 2 loops) is only $\\sim n^2$.\n\n\\begin{problem} % Why NumPy ROCKS.\nNumPy is built specifically for fast numerical computations.\nRepeat the experiment of Problem \\ref{prob:matrix-multiplication-timing}, timing the following operations:\n%\n\\begin{itemize}\n\\item matrix-vector multiplication with \\li{matrix_vector_product()}.\n\\item matrix-matrix multiplication with \\li{matrix_matrix_product()}.\n\\item matrix-vector multiplication with \\li{np.dot()}.\n\\item matrix-matrix multiplication with \\li{np.dot()}.\n\\end{itemize}\n\nCreate a single figure with two subplots: one with all four sets of execution times on a regular linear scale, and one with all four sets of execution times on a log-log scale.\nCompare your results to Figure \\ref{fig:loglogdemo}.\n\\label{prob:numpy-is-awesome}\n\\end{problem}\n\n% TODO: Reword this note. What figure should be included?\n\n\\begin{info} % Note about Caching.\nProblem \\ref{prob:numpy-is-awesome} shows that \\textbf{matrix  operations are significantly faster in NumPy than in plain Python}.\nMatrix-matrix multiplication grows cubically regardless of the implementation; however, with lists the times grows at a rate of $an^3$ while with NumPy the times grow at a rate of $bn^3$, where $a$ is much larger than $b$.\nNumPy is more efficient for several reasons:\n\\begin{enumerate}\n    \\item Iterating through loops is very expensive.\n    Many of NumPy's operations are implemented in C, which are much faster than Python loops.\n    \\item Arrays are designed specifically for matrix operations, while Python lists are general purpose.\n    \\item NumPy takes careful advantage of computer hardware, efficiently using different levels of computer memory.\n\\end{enumerate}\n\nHowever, in Problem \\ref{prob:numpy-is-awesome}, the execution times for matrix multiplication with NumPy seem to increase somewhat inconsistently.\nThis is because the fastest layer of computer memory can only handle so much information before the computer has to begin using a larger, slower layer of memory.\n\n\\begin{comment} % TODO (?): Refine this explanation and plot.\nBelow, we plot execution times for vector-vector addition with NumPy.\nThe large spikes in the plot indicate the times that the array no longer fits in the current level of memory.\n\n\\begin{figure}[H]\n\\includegraphics[width=.5\\textwidth]{figures/cachingDemo.pdf}\n\\end{figure}\n\\end{comment}\n\n\\end{info}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Image Transformation as a Class} % -------------------------------\n\nConsider organizing the functions from Problem \\ref{prob:implement-linear-transformations} into a class.\nThe constructor might accept an array or the name of a file containing an array.\nThis structure would makes it easy to do several linear or affine transformations in sequence.\n\n\\begin{lstlisting}\n>>> horse = ImageTransformer(\"horse.npy\")\n>>> horse.stretch(.5, 1.2)\n>>> horse.shear(.5, 0)\n>>> horse.relect(0, 1)\n>>> horse.rotate(np.pi/2.)\n>>> horse.translate(.75, .5)\n>>> horse.display()\n\\end{lstlisting}\n\n\\subsection*{Animating Parametrizations} % ------------------------------------\n\nThe plot in Problem \\ref{prob:solar-system-trajectories} fails to fully convey the system's evolution over time because time itself is not part of the plot.\nThe following function creates a simple Matplotlib animation for the earth and moon trajectories.\n\n\\begin{lstlisting}\nfrom matplotlib.animation import FuncAnimation\n\ndef solar_system_animation(earth, moon):\n    \"\"\"Animate the moon orbiting the earth and the earth orbiting the sun.\n    Inputs:\n        earth ((2,N) ndarray): The earth's postion with x-coordinates on the\n            first row and y coordinates on the second row.\n        moon ((2,N) ndarray): The moon's postion with x-coordinates on the\n            first row and y coordinates on the second row.\n    \"\"\"\n    fig = plt.figure()                              # Make a figure explicitly.\n    plt.axis([-15,15,-15,15])                       # Set the window limits.\n    plt.gca().set_aspect(\"equal\")                   # Make the window square.\n\n    earth_dot,  = plt.plot([],[], 'bo', ms=10)      # Blue dot for the earth.\n    earth_path, = plt.plot([],[], 'b-')             # Blue line for the earth.\n    moon_dot,   = plt.plot([],[], 'go', ms=5)       # Green dot for the moon.\n    moon_path,  = plt.plot([],[], 'g-')             # Green line for the moon.\n    plt.plot([0],[0],'y*', ms=30)                   # Yellow star for the sun.\n\n    def animate(index):\n        \"\"\"Update the four earth and moon plots.\"\"\"\n        earth_dot.set_data(earth[0,index], earth[1,index])\n        earth_path.set_data(earth[0,:index], earth[1,:index])\n        moon_dot.set_data(moon[0,index], moon[1,index])\n        moon_path.set_data(moon[0,:index], moon[1,:index])\n        return earth_dot, earth_path, moon_dot, moon_path,\n\n    a = FuncAnimation(fig, animate, frames=earth.shape[1], interval=25)\n    plt.show()\n\\end{lstlisting}\n\nSee \\url{http://matplotlib.org/1.5.1/examples/animation/index.html} for other examples of animations in Matplotlib.\n\n\\begin{comment} % TODO: Fix this.\n\\subsection*{Celestial Mechanics} % -------------------------------------------\n\nThe solar system simulation using only linear transformations is not really a physical model.\nA more accurate representation of celestial orbits would use differential equations involving gravitational force to describe the motion.\n\nIn the early 1600s Johannes Kepler discovered that planets travel around the sun in elliptical orbits.\nSimulating an elliptical orbit requires a more complicated physical model because the speed and angular momentum of the celestial body are not constant in time.\nHowever, with only 2 bodies (the earth and the sun), it is still fairly simple to completely describe the system for all time using dynamical systems.\nOnce a third body (the moon) is introduced into the system, however, it becomes incredibly difficult to accurately describe the system.\nThis phenomenon is referred to as the 3-body problem.\n\\end{comment}\n", "meta": {"hexsha": "2c0aa6b348fb0c8bfc0fd3282e406b9b0f2dc174", "size": 28847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1A/LinearTransformations/LinearTransformations.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/LinearTransformations/LinearTransformations.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/LinearTransformations/LinearTransformations.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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.135620915, "max_line_length": 361, "alphanum_fraction": 0.7059312927, "num_tokens": 7744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.8791467801752451, "lm_q1q2_score": 0.6089339692870996}}
{"text": "%%\\documentclass[handout]{beamer}\n%\\documentclass[aspectratio=169,13pt]{beamer}\n\n%\\input{./preamble}\n\n\\subtitle{Linear Systems}\n\\date{}\n\\begin{document}\n\n\\begin{frame}\n  \\titlepage\n\\end{frame}\n\n\\section{Vector and Matrix Norms}\n\n\\begin{frame}{Vector Norms}\n\n\\urcornerlinkdemo{01-error-and-fp}{Vector Norms}\n\n\\begin{itemize}\n\\item {\\bf Properties of vector norms}\n  \\mdcond{ \n    \\begin{align*}\n    ||\\B x|| &\\geq 0 \\\\\n    ||\\B x|| &= 0  \\quad\\Leftrightarrow \\quad\\B x = \\B 0 \\\\\n    ||\\alpha \\B x|| &= |\\alpha|\\cdot ||\\B x|| \\\\\n    ||\\B x + \\B y|| &\\leq ||\\B x|| + ||\\B y||\\quad \\text{(\\coloremph{triangle inequality}) implies continuity}\n    \\end{align*}\n    }\n\\item {\\bf A norm is uniquely defined by its unit sphere:}\n  \\mdcond{\n    Surface defined by space of vectors $\\mathbb{V}\\subset \\mathbb{R}^n$ such that $\\forall \\B x\\in\\mathbb{V}, ||\\B x||=1$\n  }\n\\item {\\bf $p$-norms}\n  \\mdcond{ \n    $||\\B x||_p = \\bigg(\\sum_{i} |x_i|^p\\bigg)^{1/p}$\n    \\begin{itemize}\n    \\sitem $p=1$ gives sum of absolute values of entry (unit sphere is diamond-like)\n    \\sitem $p=\\infty$ gives maximum entry in absolute value (unit sphere is box-like)\n    \\sitem $p=2$ gives Euclidean distance metric (unit sphere is spherical)\n    \\end{itemize}\n  }\n  \n\n\\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}{Inner-Product Spaces}\n\n\\begin{itemize}\n\\item {\\bf Properties of inner-product spaces}:\n%\n%  \\lgcond{ \n    Inner products $\\langle \\B x, \\B y \\rangle$ must satisfy\n    \\begin{align*}\n    \\langle \\B x, \\B x\\rangle  &\\geq 0 \\\\\n    \\langle \\B x, \\B x\\rangle &= 0  \\quad\\Leftrightarrow \\quad\\B x = \\B 0 \\\\\n    \\langle \\B x, \\B y \\rangle & =\\langle \\B y, \\B x \\rangle \\\\\n    \\langle \\B x, \\B y + \\B z \\rangle & =\\langle \\B x, \\B y \\rangle + \\langle \\B x, \\B z \\rangle\\\\\n    \\langle \\alpha \\B x, \\B y \\rangle & =\\alpha \\langle \\B x, \\B y \\rangle \n    \\end{align*}\n%  }\n\n\\item {\\bf Inner-product-based vector norms}\n\n\\lgcond{\nThe $p=2$ vector norm is the Eucledian inner-product norm,\n  $$||\\B x||_2=\\sqrt{\\B x^\\T \\B x}$$\nand due to Cauchy-Schwartz inequality $|\\langle \\B x, \\B y\\rangle|\\leq \\sqrt{\\langle \\B x, \\B x\\rangle\\cdot \\langle \\B y, \\B y\\rangle}$,\n  $$|\\B x^T\\B y| \\leq ||\\B x||_2||\\B y||_2.$$\n  Other inner-products can be expressed as $\\langle \\B x, \\B y \\rangle=\\B x^\\T\\B A\\B y$ where $\\B A$\n  is symmetric positive definite, yielding norms $||\\B x||_{\\B A} = \\sqrt{\\B x^\\T \\B A \\B x}$\n}\n\n\n\\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}{Matrix Norms}\n\n\\urcornerlinkdemo{02-linear-systems}{Matrix norms}\n\n\\begin{itemize}\n\\item {\\bf Properties of matrix norms}:\n  %\\lgcond{ \n    \\begin{align*}\n    ||\\B A|| &\\geq 0 \\\\\n    ||\\B A|| &= 0  \\quad\\Leftrightarrow \\quad\\B A = \\B 0 \\\\\n    ||\\alpha \\B A|| &= |\\alpha|\\cdot ||\\B A|| \\\\\n    ||\\B A + \\B B|| &\\leq ||\\B A|| + ||\\B B||\\quad \\text{(\\coloremph{triangle inequality})}\n    \\end{align*}\n   % }\n\\item {\\bf Frobenius norm}:\n    \\smcond{\n      $$||\\mathbf{A}||_F=\\bigg(\\sum_{i,j} a_{ij}^2\\bigg)^{1/2}$$\n    }\n\\item {\\bf Operator/induced/subordinate matrix norms}:\n\n\\lgcond{\n  For any vector norm $||\\cdot ||$, the induced matrix norm is\n  \\[||\\B A|| = \\max_{\\B x\\neq \\B 0} ||\\B A \\B x||/||\\B x|| = \\max_{||\\B x||=1} ||\\B A \\B x||\\]\n\n}\n\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Induced Matrix Norms}\n\n\\begin{itemize}\n\\item {\\bf Interpreting induced matrix norms}:\n  \\lgcond{\n  A matrix is uniquely defined with respect to a norm by a unit-ball, which is the space of vectors $\\B y = \\B A\\B x$ for all $\\B x$ on the unit-sphere of the norm.\n\n  $$||\\B A||_{p}=\\max_{||\\B x||_p=1} ||\\B A \\B x||_p$$ is the maximum possible $p$-norm\n  \\coloremph{amplification} due to application of $\\B A$ \n%(radius of unit-sphere enclosing unit-ball)\n\n  \n  $$1/||\\B A^{-1}||_{p}=\\min_{||\\B x||_p=1} ||\\B A \\B x||_p$$ is the maximum possible $p$-norm\n  \\coloremph{reduction} due to application of $\\B A$ \n%(radius of unit-sphere enclosed by unit-ball)\n  }\n\\item {\\bf General induced matrix norms}:\n  \\lgcond{\n  $$||\\B A||_{mp}=\\max_{||\\B x||_p=1} ||\\B A \\B x||_m$$\n  typically $m=p$ so we write $||\\B A||_{p}$ and almost always we have $p\\in\\{1,2,\\infty\\}$.\n  (Computing the matrix norm for certain choices of $m\\neq p$ is NP-complete.)\n  }\n\n\n\\end{itemize}\n\\end{frame}\n\n\\section{Matrix Condition Number}\n\n\\begin{frame}{Matrix Condition Number}\n\n\\dblurcornerlinkdemo{02-linear-systems}{Conditioning of 2x2 Matrices}{02-linear-systems}{Condition number visualized}\n\n\\begin{itemize}\n\\item {\\bf Definition}: $\\kappa(\\B A) = ||\\B A|| \\cdot||\\B A^{-1}||$ is the ratio between the shortest/longest distances from the unit-ball center to any point on the surface.\n\\mitem {\\bf Intuitive derivation}:\n\\begin{align*}\n\\kappa(\\B A) &= \\max_{\\text{inputs}} \\quad \\max_{\\text{perturbations in input}}\\left|\\frac{\\text{relative perturbation in output}}{\\text{relative perturbation in input}}\\right| \n\\end{align*}\nsince a matrix is a linear operator, we can decouple its action on\nthe input $\\B x$ and the perturbation $\\B{\\delta x}$ since $\\B A(\\B x +\\B{\\delta x}) = \\B A \\B x + \\B A \\B{\\delta x}$, so\n%&= \\left|\\frac{\\max_{\\text{perturbations in input}}\\text{relative perturbation growth}}{\\max_{\\text{inputs}}\\text{relative input reduction}}\\right| \\\\\n\\begin{align*}\n\\kappa(\\B A) &= \\left|\\frac{\\overbrace{\\max_{\\text{perturbations in input}}\\text{relative perturbation growth}}^{||\\B A||}}{\\underbrace{\\max_{\\text{inputs}} \\text{relative input reduction}}_{1/||\\B A^{-1}||}}\\right| \n\\end{align*}\n\\end{itemize}\n\\end{frame}\n\n\n\n\\begin{frame}{Matrix Conditioning}\n\n\\begin{itemize}\n\\item The matrix condition number $\\kappa(\\B A)$ is the ratio between the max and min distance from the surface to the center of the unit ball transformed by $\\kappa(\\B A)$:\n\\lgcond{\n\\begin{itemize} \n\\item The max distance to center is given by the vector maximizing $\\max_{||\\B x||=1} ||\\B A\\B x||_2$.\n\\sitem The min distance to center is given by the vector minimizing $\\min_{||\\B x||=1} ||\\B A\\B x||_2 = 1/(\\max_{||\\B x||=1} ||\\B A^{-1}\\B x||_2)$.\n\\sitem Thus, we have that $\\kappa(\\B A) = ||\\B A||_2||\\B A^{-1}||_2$\n\\end{itemize}\n}\n\\item The matrix condition number bounds the worst-case amplification of error in a matrix-vector product:\n  \\lgcond{\n  Consider $\\B y + \\B{\\delta y}= \\B A (\\B x + \\B{\\delta x})$, assume $||\\B x||_2=1$\n  \\begin{itemize}\n  \\mitem In the worst case, $||\\B y||_2$ is minimized, that is $||\\B y||_2 = 1/||\\B A^{-1}||_2$\n  \\mitem In the worst case, $||\\B{\\delta y}||_2$ is maximized, that is $||\\B{\\delta y}||_2 = ||\\B A||_2||\\B{\\delta y}||_2$\n  \\mitem So $||\\B{\\delta y}||_2/||\\B{y}||_2$ is at most $\\kappa(\\B A)||\\B{\\delta x}||_2/||\\B{x}||_2$\n  \\end{itemize}\n  }\n\n\\end{itemize}\n\n\\end{frame}\n\n\n\n\\begin{frame}{Norms and Conditioning of Orthogonal Matrices}\n\n\\begin{itemize}\n\\item {\\bf Orthogonal matrices}:\n  \\mdcond{\n  A matrix $\\B Q$ is orthogonal, if its square and its columns are orthonormal,\n  %\\[ \\B Q =\\begin{bmatrix}\\B {q_1} & \\cdots & \\B{q_2}\\end{bmatrix}, \\quad \\langle \\B{q_i},\\B{q_j}\\rangle =\\delta_{i,j} = \\begin{cases} 1 & : i=j \\\\ 0 & :i\\neq j \\end{cases}\\]\n  or equivalently $\\B Q^\\T= \\B Q^{-1}$.\n  }\n\\item {\\bf Norm and condition number of orthogonal matrices}:\n  \\smcond{}\n  \\lgcond{\n  For any $||\\B v||_2=1$,\n  \\begin{align*}\n    ||\\B Q\\B v||_2 &= \\bigg( \\Big\\langle\\B v^\\T \\B Q^\\T,  \\B{Q} \\B v\\Big\\rangle\\bigg)^{1/2}\n                   = \\bigg( \\B v^\\T \\B Q^\\T  \\B{Q} \\B v\\bigg)^{1/2}  =\\bigg( \\B v^\\T \\B v\\bigg)^{1/2} \\\\\n                   &= ||\\B v||_2\n  \\end{align*}\n  Consequently, $||\\B Q||_2=||\\B Q^{-1}||_2 = \\kappa(\\B Q) = 1$.\n\n  \\smallskip\n  $\\B Q \\B v$ expresses $\\B v$ in a coordinate system whose axes\n  are columns of $\\B Q^T$\n  }\n\n\\end{itemize}\n\n\\end{frame}\n\n\\section{Singular Value Decomposition}\n\n\\begin{frame}{Singular Value Decomposition}\n\n\\begin{itemize}\n\\item {\\bf The singular value decomposition (SVD)}:\n\n  \\lgcond{\n    We can express \\coloremph{any} matrix $\\B A$ as\n    $$\\B A = \\B U \\B \\Sigma \\B V^\\T$$\n    where $\\B U$ and $\\B V$ are orthogonal, and $\\B \\Sigma$ is square nonnegative and diagonal,\n    \\[\\B \\Sigma = \\begin{bmatrix} \\sigma_\\text{max} & & \\\\ & \\ddots &\\\\& & \\sigma_\\text{min}\\end{bmatrix}\\]\n    \\coloremph{Any matrix is diagonal when expressed as an operator mapping vectors from a coordinate\n    system given by $\\B V$ to a coordinate system given by $\\B U^\\T$}.\n  }\n  \\lgcond{}\n    \n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Norms and Conditioning via SVD}\n\n\\urcornerlinkinclass{inclass-svdnorm}{Singular Value Decomposition and Norms}\n\n\\begin{itemize}\n\\item {\\bf Norm and condition number in terms of singular values}:\n\n  \\lgcond{\n    When multiplying a vector by matrix $\\B A = \\B U \\B \\Sigma \\B V^\\T$\n    \\begin{itemize}\n    \\mitem Multiplication by $\\B V^\\T$ changes coordinate systems, leaving the norm unchanged\n    \\mitem Multiplication by $\\B U$ changes coordinate systems, leaving the norm unchanged\n    \\end{itemize}\n    \\medskip\n    so, only multiplication by $\\B \\Sigma$ has an effect on the vector norm\n    \\begin{itemize}\n    \\mitem Note that $||\\B \\Sigma||_2=\\sigma_\\text{max}$, $||\\B \\Sigma^{-1}||_2=1/\\sigma_\\text{min}$, so \n    \\[\\kappa(\\B A) =\\kappa(\\B \\Sigma)=\\frac{\\sigma_\\text{max}}{\\sigma_\\text{min}}\\]\n    \\end{itemize}\n  }\n  \\lgcond{}\n\\end{itemize}\n\\end{frame}\n\n\\section{Perturbation Analysis}\n\n\\begin{frame}{Conditioning of Linear Systems}\n\n\\begin{itemize}\n\\item {\\bf Lets now return to formally deriving the conditioning of solving $\\B A \\B x = \\B b$}:\n\n  \\lgcond{\n  Consider a perturbation to the right-hand side (input) $\\B {\\hat{b}} = \\B b + \\B{\\delta b}$\n  \\begin{align*}\n  \\B A \\B{\\hat{x}} &= \\B{\\hat{b}} \\\\\n  \\B A (\\B x  +\\B{\\delta x}) &= \\B{b} + \\B{\\delta b} \\\\\n  \\B A\\B{\\delta x} &= \\B{\\delta b}\n  \\end{align*}\n  we wish to bound the size of the relative perturbation to the output $||\\B{\\delta x}||/||\\B{x}||$ with respect to the size of the relative perturbation the the input $||\\B{\\delta b}||/||\\B{b}||$\n  \\begin{align*}\n  \\B{\\delta x} &= \\B A^{-1}\\B{\\delta b} \\\\\n  \\frac{||\\B{\\delta x}||}{||\\B{x}||} &= \\frac{||\\B A^{-1}\\B{\\delta b}||}{||\\B{x}||} \n  \\leq  \\frac{||\\B A^{-1}||\\cdot ||\\B{\\delta b}||}{||\\B{x}||}\n%  \\frac{||\\B{\\delta b}||}{||\\B{b}||} =  \\frac{||\\B A\\B{\\delta x}||}{||\\B{b}||} \\leq  \\frac{||\\B A||\\cdot ||\\B{\\delta x}||}{||\\B{b}||}\n%  \\frac{||\\B{\\delta b}||}{||\\B{b}||} =  \\frac{||\\B A\\B{\\delta x}||}{||\\B{b}||} \\leq  \\frac{||\\B A||\\cdot ||\\B{\\delta x}||}{||\\B{b}||}\n  \\end{align*}\n  we can use that $||\\B{x}|| \\geq ||\\B{b}||/\\sigma_\\text{max}= ||\\B{b}||/||\\B{A}||$ so\n  \\begin{align*}\n  \\frac{||\\B{\\delta x}||}{||\\B{x}||} \\leq  \\underbrace{||\\B A||\\cdot ||\\B A^{-1}||}_{\\kappa(\\B A)}\\cdot \\frac{||\\B{\\delta b}||}{||\\B{b}||} = \\frac{\\sigma_\\text{max} ||\\B{\\delta b}||}{\\sigma_\\text{min} ||\\B{b}||} \n  \\end{align*}\n  }\n  \\lgcond{}\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Conditioning of Linear Systems II}\n\n\\begin{itemize}\n\\item {\\bf Consider perturbations to the input coefficients $\\B {\\hat{A}} = \\B{A} + \\B{\\delta A}$}:\n\n  \\lgcond{\n  In this case we solve the perturbed system \n  \\begin{align*}\n  \\B{\\hat{A}} \\B{\\hat{x}} &= \\B{b} \\\\\n  \\B A \\B x  +\\B{\\delta \\B A} \\B x &= \\B{b} - \\B{\\hat{A}} \\B{\\delta x} \\\\\n  \\B{\\delta A}\\B x &=  -\\B{\\hat{A}} \\B{\\delta x} \\approx - \\B{A} \\B{\\delta x}\n  \\end{align*}\n  we wish to bound the size of the relative perturbation to the output $||\\B{\\delta x}||/||\\B{x}||$ with respect to the size of the relative perturbation the the input $||\\B{\\delta A}||/||\\B{A}||$\n  \\begin{align*}\n  \\B{\\delta x} &= -\\B A^{-1}\\B{\\delta A}\\B{x} \\\\\n  ||\\B{\\delta x}|| &= ||\\B A^{-1}\\B{\\delta A}\\B{x}|| \\leq ||\\B A^{-1}||\\cdot ||\\B{\\delta A}|| \\cdot ||\\B{x}|| \\\\\n  \\frac{||\\B{\\delta x}||}{||\\B{x}||} &\\leq \\underbrace{||\\B A^{-1}||\\cdot ||\\B {A}||}_{\\kappa(\\B A)} \\cdot \\frac{||\\B{\\delta A}||}{||\\B A||}\n  \\end{align*}\n  }\n  \\lgcond{\n  }\n\\end{itemize}\n\\end{frame}\n\n\\section{Algorithms for Simple Linear Systems}\n\n\\begin{frame}[fragile]{Solving Basic Linear Systems}\n\n\\begin{itemize}\n\\item Solve $\\B D \\B x = \\B b$ if $\\B D$ is diagonal \n\n    \\smcond{$x_i = b_i/d_{ii}$ with total cost $O(n)$}\n\n\\item Solve $\\B Q \\B x = \\B b$ if $\\B Q$ is orthogonal\n\n    \\smcond{$\\B x= \\B Q^\\T \\B b$ with total cost $O(n^2)$}\n\n\\item Given SVD $\\B A = \\B U \\B \\Sigma \\B V^T$, solve $\\B A \\B x = \\B b$\n\n    \\mdcond{\n    \\begin{itemize}\n    \\item Compute $\\B z = \\B U^T\\B b$\n    \\item Solve $\\B \\Sigma \\B y = \\B z$ (diagonal)\n    \\item Compute $\\B x = \\B V \\B x$\n    \\end{itemize}\n    }\n\n\\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}{Solving Triangular Systems}\n\n\\urcornerlinkdemo{02-linear-systems}{Coding back-substitution}\n\n\\begin{itemize}\n\\item {\\bf $\\B L \\B x = \\B b$ if $\\B L$ is lower-triangular is solved by forward substitution:}\n    \\filufil{\n    \\begin{alignat*}{4}\n    l_{11}x_1 &= b_1 && &&x_{1} &&= b_1/l_{11} \\\\\n    l_{21}x_1 + l_{22}x_2 &=b_2 && \\quad\\Rightarrow \\quad&& x_{2} &&= (b_2-l_{21}x_1)/l_{22} \\\\\n    l_{31}x_1 + l_{32}x_2 + l_{33}x_3 &=b_3 && && x_{3} &&= (b_3-l_{31}x_1-l_{32}x_2)/l_{33} \\\\\n          &\\ \\ \\vdots && &&  && \\ \\ \\vdots\n    \\end{alignat*}\n    }{\n    \\begin{alignat*}{4}\n    l_{11}x_1 &= b_1 && &&x_{1} &&= \\quad\\quad\\quad  \\quad\\quad\\quad\\quad\\quad\\quad\\\\\n    l_{21}x_1 + l_{22}x_2 &=b_2 && \\quad\\Rightarrow \\quad&& x_{2} &&= \\hfill \\\\\n    l_{31}x_1 + l_{32}x_2 + l_{33}x_3 &=b_3 && && x_{3} &&= \\hfill  \\\\\n          &\\ \\ \\vdots && &&  && \\ \\ \\vdots\n    \\end{alignat*}\n  }\n\\item {\\bf Algorithm can also be formulated recursively by blocks:}\n   \n  \\lgcond{ \n    \\[\\blomat{l} \\begin{bmatrix} x_1 \\\\ \\B{x_2} \\end{bmatrix} = \\begin{bmatrix} b_1 \\\\ \\B{b_2}\\end{bmatrix}\\]\n    $x_1=b_1/l_{11}$, then solve recursively for $\\B{x_2}$ in $\\B{L_{22}}\\B{x_2} = \\B{b_2}-\\B{l_{21}}x_1$.\n  }\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Solving Triangular Systems}\n\n\\begin{itemize}\n\n\\item {\\bf Existence of solution to $\\B L \\B x =\\B b$:}\n\n    \\mdcond{\n      If some $l_{ii}=0$, the solution may not exist, and $\\B L^{-1}$ does not exist.\n    }\n\\item {\\bf Uniqueness of solution:}\n    \\mdcond{ \n      Even if some $l_{ii}=0$ and $\\B L^{-1}$ does not exist, the system may have a solution.\n      The solution will not be unique since columns of $\\B{L}$ are necessarily linearly dependent if a diagonal element is zero.\n      May want to select solution minimizing norm of $\\B x$.\n    }\n\\item {\\bf Computational complexity of forward/backward substitution:}\n\n  \\mdcond{\n  The recursive algorithm has the cost recurrence,\n  $$T(n)=T(n-1)+n=\\sum_{i=1}^{n} i = n(n+1)/2.$$\n  The total cost is $n^2/2$ multiplications and $n^2/2$ additions to leading order. \n  }\n\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Properties of Triangular Matrices}\n\n\\begin{itemize}\n\\item {\\bf $\\B Z = \\B X \\B Y$ is lower triangular is $\\B X$ and $\\B Y$ are both lower triangular:}\n\n  \\lgcond{\n    \\[\\bomat{z}=\\blomat{x}\\blomat{y}.\\]\n    Clearly, $z_{11}=x_{11}y_{11}$ and $\\B z_{12}=0$, then we proceed by the same argument for the triangular matrix product \n    $\\B{Z}_{22}=\\B{X}_{22}\\B{Y}_{22}$.\n  }\n\n\\item {\\bf $\\B{L^{-1}}$ is lower triangular if it exists:}\n    \n  \\lgcond{\n    We give a constructive proof by providing an algorithm for triangular matrix inversion.\n    We need $\\B{Y}=\\B{X}^{-1}$ so \n    \\[\\blmat{Y}\\blmat{X} = \\begin{bmatrix} \\B I & \\\\ & & \\B I \\end{bmatrix},\\]\n    from which we can deduce\n    \\[\\B{Y}_{11} = \\B{X}_{11}^{-1},\\quad \\B{Y}_{22}=\\B{X}_{22}^{-1},\\quad \\B{Y}_{21} = -\\B{Y}_{22}\\B{X}_{21}\\B{Y}_{11}.\\]\n  }\n\n\n\\end{itemize}\n\\end{frame}\n\n\n\n\\section{Gaussian Elimination}\n\n\\subsection{LU Decomposition}\n\n\\begin{frame}{LU Factorization}\n\n\\begin{itemize}\n\\item {\\bf An \\coloremph{LU factorization} consists of a unit-diagonal lower-triangular \\coloremph{factor} $\\B L$ and upper-triangular factor $\\B U$ such that $\\B  A = \\B L \\B U$:}\n\n\\lgcond{\n\\begin{itemize}\n\\mitem Unit-diagonal implies each $l_{ii}=1$, leaving $n(n-1)/2$ unknowns in $\\B L$ and $n(n+1)/2$ unknowns in $\\B U$, for a total of $n^2$, the same as the size of $\\B A$.\n%\\mitem The latter is done by forward substitution, the former involves an upper-triangular matrix and requires backward substitution\n%\\mitem It suffices to have a forward substitution routine and reversing the ordering of vector elements, \n%      done by taking the product with $\\B P$, $p_{ij} = \\delta(i,n+1-j)$,\n%    \\[\\B L \\B U = \\B L \\B P \\underbrace{\\B P \\B U \\B P}_{\\B{\\tilde L}} \\B P = \\B L \\B P \\B{\\tilde L} \\B P\\]\n\\mitem For rectangular matrices $\\B{A}\\in \\mathbb{R}^{m\\times n}$, one can consider a full LU factorization, \n      with $\\B{L}\\in \\mathbb{R}^{m \\times \\max(m,n)}$ and $\\B{U} \\in \\mathbb{R}^{\\max(m,n) \\times n}$, \n      but it is fully described by a reduced LU factorization, with lower-trapezoidal\n      $\\B{L}\\in \\mathbb{R}^{m \\times \\min(m,n)}$ and upper-trapezoidal $\\B{U} \\in \\mathbb{R}^{\\min(m,n) \\times n}$.\n\\end{itemize}\n}\n\\item {\\bf Given an LU factorization of $\\B A$, we can solve the linear system $\\B A \\B x = \\B b$:} \n\\lgcond{\n    \\begin{itemize} \n    \\sitem using forward substitution $\\B L \\B y = \\B b$\n    \\sitem using backward substitution to solve $\\B U \\B x = \\B y$\n    \\end{itemize}\n\\smallskip\n    Backward substitution is the same as forward substitution with a reversal of the ordering of the elements of the vectors and the ordering of the rows/columns of the matrix.\n}\n\n\\lgcond{}\n\n\\end{itemize}\n\\end{frame}\n\n\\subsection{Naive Algorithm}\n\n\\begin{frame}{Gaussian Elimination Algorithm}\n\n\\urcornerlinkdemo{02-linear-systems}{LU factorization}\n\n\\begin{itemize}\n\\item {\\bf Algorithm for factorization is derived from equations given by $\\B A = \\B L \\B U$:}\n\n\\lgcond{\n%\\[\\bmat{A} = \\blmat{L}\\brmat{U}\\]\n\\[\\begin{bmatrix} a_{11} & \\B{a}_{12} \\\\ \\B{a}_{21} & \\B{A}_{22} \\end{bmatrix}=\n\\begin{bmatrix} 1 &  \\\\ \\B{l}_{21} & \\B{L}_{22} \\end{bmatrix}\n\\begin{bmatrix} u_{11} & \\B{u}_{12} \\\\  & \\B{U}_{22} \\end{bmatrix}\n = \\blmat{L}\\brmat{U}\\]\n\\begin{itemize}\n%\\item Obtain LU factorization of the leading minor \\(\\B{A}_{11}=\\B L_{11}\\B{U}_{11}\\) by recursion\n\\sitem First, observe $\\begin{bmatrix} u_{11} & \\B{u}_{12}\\end{bmatrix} = \\begin{bmatrix}{a}_{11} & \\B{a}_{12}\\end{bmatrix}$\n\\sitem To obtain $\\B{l}_{21}$ compute $\\B{l}_{21} = \\B{a}_{21}/u_{11}$\n%\\item Solve  sets of triangular linear systems can be solved to obtain $\\B L_{21}$ and $\\B{U}_{12}$ from $\\B{A}_{21}=\\B{L}_{21}\\B{U}_{11}$ and $\\B{A}_{12}=\\B{L}_{11}\\B{U}_{12}$\n\\sitem \nObtain $\\B{L}_{22}$ and $\\B{U}_{22}$ by recursively computing LU of the \\coloremph{Schur complement} \\[\\B{S}= \\B{A}_{22}-\\B{l}_{21}\\B{u}_{12}\\] \n\\end{itemize}\n}\n\\item {\\bf The computational complexity of LU is $O(n^3)$:}\n\n\\lgcond{\nComputing $\\B{l}_{21} = \\B{a}_{21}/u_{11}$ requires $O(n)$ operations, finding $\\B S$ requires $2n^2$, so to leading order the complexity of LU is\n$$T(n)=T(n-1)+2n^2=\\sum_{i=1}^n 2i^2 \\approx 2n^3/3$$ \n}\n%\\item {\\bf The $k$th column of $\\B L$ is given by the $k$th \\coloremph{elementary matrix} $\\B{M}_k$:}\n%\n%\\lgcond{\n%\\[\\B{M}_k\\begin{bmatrix} v_1 & \\cdots & v_k & 0 & \\cdots & 0 \\end{bmatrix}^\\T= \\B{v} \\]\n%}\n\n\\end{itemize}\n\\end{frame}\n\n\\subsection{Existence of LU}\n\n\\begin{frame}{Existence of LU Factorization}\n\n\\begin{itemize}\n\\item {\\bf The LU factorization may not exist:}\nConsider matrix $\\begin{bmatrix} 3 & 2 \\\\ 6 & 4 \\\\ 0 & 3\\end{bmatrix}$.\n\n\\lgcond{\n%We can infer what the first row of $\\B L$ and column of $\\B U$ directly from the matrix,\nProceeding with Gaussian elimination we obtain\n\\[\\begin{bmatrix} 3 & 2 \\\\ 6 & 4 \\\\ 0 & 3\\end{bmatrix} =\\begin{bmatrix} 1 & 0 \\\\ 2 & 1 \\\\ 0 & l_{32} \\end{bmatrix} \\begin{bmatrix} 3 & 2 \\\\ 0 & u_{21} \\end{bmatrix}.\\]\nThen we need that $4 = 4+u_{21}$ so $u_{21}=0$, but at the same time $l_{32}u_{21}=3$.\n\nMore generally, if and only if for any partitioning $\\bmat{A}$ the leading minor is singular ($\\det(\\B{A}_{11})=0$), $\\B{A}$ has no LU factorization.\n}\n\n\\item {\\bf Permutation of rows enables us to transform the matrix so the LU factorization does exist:}\n\n\\lgcond{\nGaussian elimination can only fail if dividing by zero. \nAt every recursive step of Gaussian elimination, if the leading entry of the first row is zero, we permute it with a row with an leading nonzero (if $\\B{a}_{21}=\\B 0$, we set $u_{11}=0$ and $\\B{l}_{21}=\\B 0$).\n}\n\n\\end{itemize}\n\\end{frame}\n%\\begin{frame}{Elimination Matrices}\n%\n%\\begin{itemize}\n%\\item {\\bf An elimination matrix $\\B{M}_k$ satisfies the following properties:}\n%\n%\\lgcond{\n%\\begin{itemize}\n%\\item It is a rank-$1$ perturbation of the identity that is unit-diagonal and lower-triangular,\n%\\[ \\B{M}_k = \\B{I} - \\B{m}_k \\B{e}_k^\\T=\\B{I}-\\begin{bmatrix} \\B{\\tilde{m}}_k \\\\ \\B{0}\\end{bmatrix} \\B{e}_k^\\T\\]\n%\\item It reduces a given vector to its first $k$ elements \\[\\B{M}_k\\begin{bmatrix} a_1 \\\\ \\vdots \\\\ a_k \\\\ 0 \\\\ \\vdots\\end{bmatrix}= \\B{a} \\]\n%\\item $\\B{M}_k^{-1}= \\B{I}+\\B{m}_k \\B{e}_k^\\T = 2\\B{I} - \\B{M}_k$\n%\\item $\\B{M}_j\\B{M}_k=(\\B{I} - \\B{m}_j \\B{e}_j^\\T)(\\B{I} - \\B{m}_k \\B{e}_k^\\T)=(\\B{I} - \\begin{bmatrix} \\B{m}_j & \\B{m}_k \\end{bmatrix}\\begin{bmatrix} \\B{e}_j & \\B{e}_k\\end{bmatrix}^\\T)=\\B{M}_j+\\B{M}_k-\\B I$\n%\\end{itemize}\n%}\n%\n%\\lgcond{}\n%\n%\\end{itemize}\n%\\end{frame}\n%\n\n\\subsection{Pivoting}\n\n\\begin{frame}{Gaussian Elimination with Partial Pivoting}\n\n\\urcornerlinkdemo{02-linear-systems}{LU with Partial Pivoting}\n\n\\begin{itemize}\n\\item {\\bf \\coloremph{Partial pivoting} permutes rows to make divisor $u_{ii}$ is maximal at each step:}\n\n\\lgcond{\nBased on our argument above, for any matrix $\\B A$ there exists a permutation matrix $\\B P$ that\ncan permute the rows of $\\B A$ to permit an LU factorization,\n\\[\\B P \\B A = \\B L \\B U. \\]\nPartial pivoting finds such a permutation matrix $\\B P$ one row at a time.\nThe $i$th row is selected to maximize the magnitude of the leading element (over elements in the first column),\nwhich becomes the entry $u_{ii}$.\nThis selection ensures that we are never forced to divide by zero during Gaussian elimination and that the magnitude\nof any element in $\\B L$ is at most $1$.\n}\n\n\\item {\\bf A row permutation corresponds to an application of a \\coloremph{row permutation matrix} $\\B{P}_{jk} = \\B{I} -(\\B{e}_j-\\B{e}_k)(\\B{e}_j-\\B{e}_k)^\\T$:}\n\n\\lgcond{\nIf we permute row $i_j$ .o be the leading ($i$th) row at the $i$th step, the overall permutation matrix is given by\n\\(\\B P^T =\\prod_{i=1}^{n-1} \\B{P}_{ii_j}.\\)\n}\n\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Partial Pivoting Example}\n\n\\begin{itemize}\n\\item Lets consider again the matrix $\\B A = \\begin{bmatrix} 3 & 2 \\\\ 6 & 4 \\\\ 0 & 3\\end{bmatrix}$.\n\n\\lgcond{\n\\begin{itemize}\n\\item The largest magnitude element in the first column is $6$, so we select this as our pivot and perform the first step of LU\n\\[\\underbrace{\\begin{bmatrix} & 1 & \\\\ 1 & & \\\\ & & 1 \\end{bmatrix}}_{\\B P_1} \\begin{bmatrix} 6 & 4 \\\\ 3 & 2 \\\\ 0 & 3\\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 1/2 \\\\ 0 \\end{bmatrix} \\begin{bmatrix} 6 & 4 \\end{bmatrix} + \\begin{bmatrix} 0 & 0  \\\\ 0 & 2 - (1/2)\\cdot 4 \\\\ 0 & 3 - 0\\cdot 4 \\end{bmatrix}\\]\n\\item The Schur complement is $\\begin{bmatrix} 0 & 3 \\end{bmatrix}^T$ and we proceed with pivoted LU, %to obtain its (reduced) LU factorization, we pivot again\n\\[\\underbrace{\\begin{bmatrix} & 1 \\\\ 1 & \\end{bmatrix}}_{\\B P_2} \\begin{bmatrix} 0 \\\\ 3\\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\begin{bmatrix} 3 \\end{bmatrix} \\]\n\\item The overall LU factorization is then given by\n\\(\\B P_1 \\begin{bmatrix} 1 & \\\\ & \\B P_2 \\end{bmatrix} \\B A = \\begin{bmatrix} 1 & \\\\ 0 & 1 \\\\ 1/2 & 0\\end{bmatrix}\\begin{bmatrix} 6 & 4 \\\\ & 3 \\end{bmatrix}\\)\n\\end{itemize}\n}\n\\lgcond{\n}\n\\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}{Complete Pivoting}\n\n\\begin{itemize}\n\\item {\\bf \\coloremph{Complete pivoting} permutes rows and columns to make divisor $u_{ii}$ is maximal at each step:}\n\n\\lgcond{\n\\begin{itemize}\n\\sitem Partial pivoting ensures that the magnitude of the \\coloremph{multipliers} satisfies $|\\B l_{21}|= |\\B a_{21}|/|u_{11}|\\leq \\B 1$\n\\sitem Complete pivoting also gives $||\\B u_{12}||_\\infty\\leq |u_{11}|$ and consequently $|\\B l_{21}|\\cdot ||\\B u_{12}||_\\infty = |\\B a_{21}|\\cdot ||\\B u_{12}||_\\infty/|u_{11}|\\leq |\\B a_{21}|$\n\\sitem Complete pivoting yields a factorization of the form $\\B L \\B U = \\B P \\B A \\B Q$ where $\\B P$ and $\\B Q$ are permutation matrices\n\\end{itemize}\n}\n\n\\item {\\bf Complete pivoting is noticeably more expensive than partial pivoting:}\n\\lgcond{\n\\begin{itemize}\n\\sitem Partial pivoting requires just $O(n)$ comparison operations and a row permutation\n\\sitem Complete pivoting requires $O(n^2)$ comparison operations, which somewhat increases the leading order cost of LU overall\n\\end{itemize}\n}\n\\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Round-off Error in LU}\n\n\\begin{itemize}\n\\item {\\bf Lets consider factorization of $\\begin{bmatrix} \\epsilon & 1 \\\\ 1 & 1 \\end{bmatrix}$ where $\\epsilon<\\epsilon_\\text{mach}$:}\n\n\\lgcond{\n\\begin{itemize}\n\\item Without pivoting we would compute \n$\\B L = \\begin{bmatrix}1  & 0 \\\\ 1/\\epsilon & 1 \\end{bmatrix}$,\n$\\B U = \\begin{bmatrix}\\epsilon  & 1 \\\\ 0 & 1-1/\\epsilon \\end{bmatrix}$\n\\sitem Rounding yields $\\fl(\\B U) = \\begin{bmatrix}\\epsilon  & 1 \\\\ 0 & -1/\\epsilon \\end{bmatrix}$\n\\sitem This leads to $\\B L\\fl(\\B U) = \\begin{bmatrix} \\epsilon & 1 \\\\ 1 & 0 \\end{bmatrix}$, a backward error of $\\begin{bmatrix} 0 & 0 \\\\ 0 & 1 \\end{bmatrix}$\n\\end{itemize}\n}\n\\item {\\bf Permuting the rows of $\\B A$ in partial pivoting gives $\\B P \\B A = \\begin{bmatrix} 1 & 1 \\\\ \\epsilon & 1 \\end{bmatrix} $}\n\\lgcond {\n\\begin{itemize}\n\\item We now compute\n$\\B L = \\begin{bmatrix}1  & 0 \\\\ \\epsilon & 1 \\end{bmatrix}$,\n$\\B U = \\begin{bmatrix}1  & 1 \\\\ 0 & 1-\\epsilon \\end{bmatrix}$, so $\\fl(\\B U)=\\begin{bmatrix}1  & 1 \\\\ 0 & 1 \\end{bmatrix}$\n\\sitem This leads to $\\B L\\fl(\\B U) = \\begin{bmatrix} 1 & 1 \\\\ \\epsilon & 1+\\epsilon \\end{bmatrix}$, a backward error of $\\begin{bmatrix} 0 & 0 \\\\ 0 & \\epsilon \\end{bmatrix}$\n\\end{itemize}\n}\n\n\n\\end{itemize}\n\n\\end{frame}\n\n\\subsection{Error Analysis}\n\n\\begin{frame}{Error Analysis of LU}\n\n\\begin{itemize}\n\n\\item {\\bf The main source of round-off error in LU is in the computation of the Schur complement:}\n\n\\lgcond{\n\\begin{itemize}\n\\sitem Recall that division is well-conditioned, while addition can be ill-conditioned\n\\sitem After $k$ steps of LU, we are working on Schur complement $\\B{A}_{22}-\\B{L}_{21}\\B{U}_{12}$ where $\\B{A}_{22}$ is $(n-k)\\times (n-k)$, $\\B{L}_{21}$ and $\\B{U}_{12}^T$ are $(n-k)\\times k$\n\\sitem Partial pivoting and complete pivoting improve stability by making sure $\\B{L}_{21}\\B{U}_{12}$ is small in norm\n\\end{itemize}\n}\n\n\\item {\\bf When computed in floating point, absolute backward error $\\B{\\delta A}$ in LU (so $\\B{\\hat L}\\B{\\hat U}=\\B{A}+\\B{\\delta A}$) is} $|\\delta a_{ij}| \\leq  \\epsilon_\\text{mach} (|\\B{\\hat L}|\\cdot |\\B{\\hat{U}}|)_{ij}$\n\n\\lgcond{\n%The major source of error is the Schur complement updates.\nFor any $a_{ij}$ with $j\\geq i$ (lower-triangle is similar), we compute \n\\[a_{ij}-\\sum_{k=1}^i\\hat{l}_{ik}\\hat{u}_{kj} = a_{ij} - \\langle \\B{\\hat{l}}_i,\\B{\\hat{u}}_j\\rangle,\\]\nwhich in floating point incurs round-off error at most $\\epsilon_\\text{mach} \\langle|\\B{\\hat{l}}_i|,|\\B{\\hat{u}}_j|\\rangle$.\nUsing this, for complete pivoting, we can show $|\\delta a_{ij}| \\leq \\epsilon_\\text{mach} n^2||\\B A||_\\infty.$\n%For an arbitrary $a_{ij}$, consider the partitioning $\\bmat{A}$ where $\\B{A}_{11}$ is of dimension $\\min(i,j)-1$. \n%After the Schur complement update $\\B{S}= \\fl(\\B{A}_{22}-\\B{\\hat L}_{21}\\B{\\hat U}_{12})$,\n%the entry in $\\B S$ corresponding to $a_{ij}$ (an entry in $\\B{A}_{22}$) will become an entry of $\\B U$ or an entry of $\\B{\\hat L}$ (after a division that can only shrink the error).\n%Thus the $\\B{\\hat L}$ and $\\B{\\hat{U}}$ are factors of a matrix $\\B{A}+\\B{\\delta A}$ where the perturbation is bounded by the error of the inner product necessary to compute any Schur complement entry,\n%so $|\\delta a_{ij}| \\leq \\epsilon_\\text{mach}(|\\B{\\hat{L}}|\\cdot |\\B{\\hat{U}}|)_{ij}$.\n}\n\n\\end{itemize}\n\\end{frame}\n\n\n\\section{Linear System Problem Variants}\n\n\\begin{frame}{Helpful Matrix Properties}\n\n\\begin{itemize}\n\\item {\\bf  Matrix is \\coloremph{diagonally dominant}, so $\\sum_{i\\neq j} |a_{ij}| \\leq |a_{ii}|$:}\n\n\\mdcond{\nPivoting is not required if matrix is strictly diagonally dominant $\\sum_{i\\neq j} |a_{ij}| < |a_{ii}|$.\n}\n\\item {\\bf Matrix is \\coloremph{symmetric positive definite (SPD)}, so $\\forall_{\\B x\\neq 0}, \\B x^T\\B A \\B x>0$:}\n\n\\mdcond{\n$\\B L = \\B U$ and pivoting is not required, \\coloremph{Cholesky} algorithm $\\B A = \\B L \\B L^T$ can be used ($\\B L$ in Cholesky is not unit-diagonal).\n}\n\\item {\\bf Matrix is symmetric but indefinite}:\n\n\\mdcond{\nCompute pivoted \\coloremph{LDL factorization} $\\B P \\B A \\B P^T = \\B L \\B D \\B L^T$ (where $\\B L$ is lower-triangular and unit-diagonal, while $\\B D$ is diagonal)\n}\n\\item {\\bf Matrix is \\coloremph{banded}, $a_{ij}= 0$ if $|i-j|>b$}:\n\n\\mdcond{\nLU without pivoting and Cholesky preserve banded structure and require only $O(nb^2)$ work.\n}\n\\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}{Solving Many Linear Systems}\n\n\\urcornerlinkdemoinclass{02-linear-systems}{Sherman-Morrison}{inclass-sherman-morrison-woodbury}{Sherman-Morrison-Woodbury Formula}\n\n\\begin{itemize}\n\\item {\\bf Suppose we have computed $\\B A = \\B L \\B U$ and want to solve $\\B A \\B X = \\B B$ where $\\B B$ is $n\\times k$ with $k<n$:}\n\n\\mdcond{\nCost is $O(n^2k)$ for solving the $k$ independent linear systems\n}\n\n\\item {\\bf Suppose we have computed $\\B A = \\B L \\B U$ and now want to solve a perturbed system $(\\B A - \\B u \\B v^T)\\B x = \\B b$:}\n\nCan use the \\coloremph{Sherman-Morrison-Woodbury} formula\n\\[(\\B A - \\B u \\B v^T)^{-1} = \\B A^{-1} + \\frac{\\B{A}^{-1}\\B u\\B v^T\\B A^{-1}}{1- \\B v^T \\B{A}^{-1}\\B u}\\] \n\\lgcond{\n\\begin{itemize}\n\\item Consequently we have $\\B A \\B x = \\B b + \\frac{\\B u\\B v^T\\B A^{-1}}{1- \\B v^T \\B{A}^{-1}\\B u}\\B b =\\B b + \\frac{\\B v^T\\B A^{-1}\\B b}{1- \\B v^T \\B{A}^{-1}\\B u}\\B u  $\n\\sitem Need not form $\\B A^{-1}$ or $\\B L^{-1}$ or $\\B U^{-1}$, suffices to use backward/forward substitution to solve $\\B w^T \\B A = \\B v^T$, i.e. solve $\\B U^T \\B L^T \\B w = \\B v$ and then solve\n\\[\\B L \\B U \\B x = \\B b + \\underbrace{\\bigg(\\frac{\\B w^T\\B b}{1- \\B w^T \\B u}\\bigg)}_\\text{scalar}\\B u \\]\n\\end{itemize}\n}\n\\end{itemize}\n\n\\end{frame}\n\n\n%\\end{document}\n", "meta": {"hexsha": "8fb888c94b8202a851bde2785219cdc5a2d61372", "size": 29896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02-body.tex", "max_stars_repo_name": "solomonik/cs450-notes", "max_stars_repo_head_hexsha": "7f4d18705dac5730b7e40e588acf55030c9d823a", "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": "02-body.tex", "max_issues_repo_name": "solomonik/cs450-notes", "max_issues_repo_head_hexsha": "7f4d18705dac5730b7e40e588acf55030c9d823a", "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": "02-body.tex", "max_forks_repo_name": "solomonik/cs450-notes", "max_forks_repo_head_hexsha": "7f4d18705dac5730b7e40e588acf55030c9d823a", "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": 40.2368775236, "max_line_length": 297, "alphanum_fraction": 0.6239296227, "num_tokens": 11238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347362, "lm_q2_score": 0.8791467659263147, "lm_q1q2_score": 0.6089339594176923}}
{"text": "Following \\cite{Hirsch}, the DGMPM discretization of scalar linear advection problems are now written in a finite difference sense.\nThe equations thus obtained are the starting point for von Neumann linear stability analyses.\nFirst, the one-dimensional problem is considered and the equations of the DGMPM space discretization combined with both forward Euler and RK2 explicit time integrations are derived.\nSecond, the two-dimensional equations are written using the DGMPM space discretization along with the explicit forward Euler time integration only.\n\n\\subsection{One-dimensional stability analysis}\n\\label{subsec:scheme_equations}\n\\subsubsection*{Model equation - Space discretization}\nWe consider the scalar linear advection equation for an arbitrary quantity $q=\\rho \\bar{q}$ moving at the constant speed $a \\in \\Rbb^{+*}$ in a homogeneous one-dimensional medium of length $l$:\n\\begin{equation}\n\\drond{\\bar{q}}{t} + \\drond{\\bar{f}}{X} = 0 \n\\end{equation}\nwith specific flux function $\\bar{f} = a\\bar{q}$, leading to the quasi-linear form:\n\\begin{equation}\n\\drond{\\bar{q}}{t} + a\\drond{\\bar{q}}{X} = 0 \\label{eq:scalar_advection}\n\\end{equation}\nEquation \\eqref{eq:scalar_advection} is discretized with the discontinuous Galerkin material point method. Thus, the medium is divided with $N_p$ material points arbitrarily distributed in $E$ two-node elements of constant length $\\Delta X$ (figure~\\ref{fig:1Dmesh}). The grid is such that at least one particle lies in every cell during the computation in order to ensure that there is no hole in the bar. Moreover, periodic boundary conditions are considered to simplify the analysis.\n\\begin{figure}[h!]\n  \\centering\n  \\input{chapter3/pgfFigures/1D_domain}\n  \\caption{One-dimensional mesh made of $E$ elements of constant length $\\Delta X = \\frac{l}{E}$.}\\label{fig:1Dmesh}\n\\end{figure}\n\nSince fields are carried by particles, we seek the scheme equation that gives the solution at a material point for a given time step, with respect to the solutions at other particles at the prior time step. In this section, Latin and Greek symbols are respectively devoted to nodes and material points.\nSince we consider here scalar quantities, the information on nodes and particles can be written as subscripts without ambiguity with vector components.\nIn addition, to make the distinction between fields easier, upper and lower case Latin symbols are used for particle and nodal fields respectively.\nHence, the solution at material point $\\alpha$ and time step $n$ reads $\\bar{Q}^{n}_\\alpha$ whereas that of node $i$ is $\\bar{q}^n_i$.\nThen, the cell containing the particle $\\alpha$ will be denoted by $c(\\alpha)$ so that the nodes interacting with this particle are $2c(\\alpha)-1$ and $2c(\\alpha)$.\nAt last, the linear shape functions defined in element $c(\\alpha)$ are:\n\\begin{equation}\nS_{2c(\\alpha)-1}(X)= \\frac{X^{2c(\\alpha)} - X}{\\Delta X} \\qquad S_{2c(\\alpha)}(X)= \\frac{X -X^{2c(\\alpha)-1}}{\\Delta X} \\qquad X \\in \\[X^{2c(\\alpha)-1},X^{2c(\\alpha)}\\]\n\\end{equation}\nand $S_{i\\alpha}$ or $S_{i,\\alpha}$ correspond to the shape function of node $i$ evaluated at the position of the $\\alpha$th material point.\n\n\\subsubsection*{Scheme equation: Euler time discretization}\nThe method followed in order to write the scheme equation consists in tracing backward the numerical procedure described in section \\ref{sec:DGMPM} in order to get an expression of the form \\eqref{eq:general_scheme} for the material point $\\alpha$:\n\\begin{equation}\n\\bar{Q}^{n+1}_\\alpha = H\\(\\bar{Q}^{n}_\\beta\\) \\qquad  \\beta=1,..,N_p\n\\end{equation} \nQuantities at time $t^{n+1}$ are obtained by interpolating nodal solutions of the discrete equation \\eqref{eq:DGMPM_discrete} in the cell containing the $\\alpha$th particle: \n\\begin{equation}\n\\bar{Q}^{n+1}_\\alpha = S_{2c(\\alpha)-1,\\alpha}\\bar{q}_{2c(\\alpha)-1}^{n+1} + S_{2c(\\alpha),\\alpha}\\bar{q}_{2c(\\alpha)}^{n+1} \\label{eq:updated_MP}\n\\end{equation}\nThe linear scalar advection equation leads to the interface flux function $\\Fc_N =  (aq^*) N $, where\n%With the interface fluxes in the case of the linear scalar advection equation $\\Fc_N =  (aq^*) N $, in which \n$q^*$ is the stationary solution of Riemann's problem at a cell interface and $N=\\pm 1$ the outward unit normal. The discrete form \\eqref{eq:DGMPM_discrete} thus reads for both nodes of cell $c(\\alpha)$:\n\\begin{equation}\n  \\label{eq:nodal_discrete_forms}\n  \\begin{aligned}\n    & \\bar{q}_{2c(\\alpha)-1}^{n+1}= \\bar{q}_{2c(\\alpha)-1}^{n} + \\frac{\\Delta t}{M^L_{2c(\\alpha)-1}}\\( K_{2c(\\alpha)-1,j} a\\bar{q}_{j}^{n}- a\\rho \\bar{q}_{2c(\\alpha)-1}^*N_{2c(\\alpha)-1} \\)\\\\\n    &\\bar{q}_{2c(\\alpha)}^{n+1}= \\bar{q}_{2c(\\alpha)}^{n} + \\frac{\\Delta t}{M^L_{2c(\\alpha)}}\\( K_{2c(\\alpha),j} a\\bar{q}_{j}^{n}- a\\rho \\bar{q}_{2c(\\alpha)}^*N_{2c(\\alpha)} \\)\n  \\end{aligned}\n\\end{equation}\nwhere in a one-dimensional grid, the outward unit vectors are $N_{2c(\\alpha)-1}=-1$ and $N_{2c(\\alpha)}=1$. Discrete equations \\eqref{eq:nodal_discrete_forms} are then simplified by first considering that the mass density is defined in a cell as the ratio of total nodal mass and the element volume:\n%First, the mass density is defined in a cell as the ratio of total nodal mass and the element volume:\n\\begin{equation}\n  \\label{eq:grid_density}\n  \\rho(X) = \\frac{M^L_{2c-1}+M^L_{2c}}{\\Delta X} = \\frac{\\sum_{\\mu=1}^{N_p^c} m_\\mu}{\\Delta X}, \\qquad X \\in [X^{2c-1},X^{2c}]\n\\end{equation}\nwhere $N_p^{c}$ is the number of particles in cell $c$ and $m_\\mu$, the mass carried by the $\\mu$th material point. For homogeneous medium, we further assume that the mass is uniformly distributed between particles so that the previous definition reduces to $\\rho = N_p^{c} m^c/\\Delta X$, with $m^c$ the mass carried by particles lying in $c$. Second, linear shape functions lead to the following the lumped mass matrix and pseudo-stiffness matrices:\n\\begin{align}\n  & M^L_i = \\sum_{\\mu=1}^{N_p} S_{i\\mu} m_\\mu = m^{c(i)} \\sum_{\\mu=1}^{N_p} S_{i\\mu}\\\\\n  & K_{2c(\\alpha)-1,j} = \\sum_{\\mu=1}^{N_p} \\drond{S_{2c(\\alpha)-1,\\mu}}{X} m_\\mu S_{j\\mu} = -m^{c(i)} \\sum_{\\mu=1}^{N_p} \\frac{ S_{j\\mu}}{\\Delta X} \\\\\n  & K_{2c(\\alpha),j} = \\sum_{\\mu=1}^{N_p} \\drond{S_{2c(\\alpha),\\mu}}{X} m_\\mu S_{j\\mu} = m^{c(i)}\\sum_{\\mu=1}^{N_p} \\frac{ S_{j\\mu}}{\\Delta X} \n\\end{align}\nThe discontinuous approximation basis moreover yields a bloc diagonal pseudo-stiffness matrix so that one can write:\n\\begin{equation}\n  \\label{eq:block_diag_K}\n  K_{ij} \\bar{q}_{j}^{n}= K_{i,2c(i)-1} \\bar{q}_{2c(i)-1}^{n}+K_{i,2c(i)} \\bar{q}_{2c(i)}^{n}\n\\end{equation}\nThird, a right-going wave (\\textit{i.e. $a>0$}) leads to a stationary solution of the Riemann problem equal to the state of the upwind node of an interface, that is:\n\\begin{align}\n  & q_{2c(\\alpha)-1}^* = \\rho \\bar{q}^n_{2c(\\alpha)-2}=  N_p^{c(\\alpha)}\\frac{ m^{c(\\alpha)}}{\\Delta X}\\bar{q}^n_{2c(\\alpha)-2} \\\\\n  & q_{2c(\\alpha)}^* = \\rho \\bar{q}^n_{2c(\\alpha)} =  N_p^{c(\\alpha)}\\frac{ m^{c(\\alpha)}}{\\Delta X} \\bar{q}^n_{2c(\\alpha)} \n\\end{align}\nTherefore, gathering all the previous considerations, equations \\eqref{eq:nodal_discrete_forms} read:\n\\begin{equation}\n  \\label{eq:nodal_euler}\n  \\begin{aligned}\n    & \\bar{q}_{2c(\\alpha)-1}^{n+1}= \\bar{q}_{2c(\\alpha)-1}^{n} - \\frac{a\\Delta t}{\\Delta X}\\( \\frac{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}} \\[S_{2c(\\alpha)-1,\\mu}\\bar{q}_{2c(\\alpha)-1}^{n}+ S_{2c(\\alpha),\\mu}\\bar{q}_{2c(\\alpha)}^{n}\\] - N_p^{c( \\alpha)} \\bar{q}^n_{2c(\\alpha)-2}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}}S_{2c(\\alpha)-1,\\mu}}\\)\\\\\n    &\\bar{q}_{2c(\\alpha)}^{n+1}= \\bar{q}_{2c(\\alpha)}^{n} + \\frac{a\\Delta t}{\\Delta X}\\( \\frac{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}} \\[S_{2c(\\alpha)-1,\\mu}\\bar{q}_{2c(\\alpha)-1}^{n}+ S_{2c(\\alpha),\\mu}\\bar{q}_{2c(\\alpha)}^{n}\\]- N_p^{c( \\alpha)} \\bar{q}^n_{2c(\\alpha)}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}} S_{2c(\\alpha),\\mu}} \\)\n  \\end{aligned}\n\\end{equation}\nwhere the volume flux contributions $\\sum_{\\mu=1}^{N_p^{c}} \\[S_{2c-1,\\mu}\\bar{q}_{2c-1}^{n}+ S_{2c,\\mu}\\bar{q}_{2c}^{n}\\]$ are written for simplicity $f_{c}^{n}$, and Courant number $a\\Delta t/\\Delta X$ arises. Introduction of these equations in the updated material point solution \\eqref{eq:updated_MP} leads after some simplifications to:\n\\begin{equation}\n  \\label{eq:euler_before_mapping}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha = S_{2c(\\alpha)-1,\\alpha}q^n_{2c(\\alpha)-1}  &+ S_{2c(\\alpha),\\alpha}\\(1-\\frac{a\\Delta t}{\\Delta X}\\frac{N_p^{c(\\alpha)}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}\\)q^n_{2c(\\alpha)} +N_p^{c(\\alpha)}\\frac{a\\Delta t}{\\Delta X} \\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}q^n_{2c(\\alpha)-2} \\\\\n    & + \\frac{a\\Delta t}{\\Delta X}\\(\\frac{S_{2c(\\alpha),\\alpha}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}-\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}\\)f_{c(\\alpha)}^{n}\n  \\end{split}\n\\end{equation}\n\nThen, the solution at nodes and time step $n$ in equation \\eqref{eq:euler_before_mapping} result from the projection between particles and the grid \\eqref{eq:DGMPM_points2nodes}:\n%In equation \\eqref{eq:euler_before_mapping} the solutions at nodes result from the convection step \\eqref{eq:DGMPM_points2nodes}:\n\\begin{equation}\n\\bar{q}^{n}_{i} = \\frac{\\sum_\\beta S_{i\\beta}m_\\beta \\bar{Q}^n_{\\beta}}{\\sum_\\gamma S_{i\\gamma}m_\\gamma} = \\frac{\\sum_\\beta S_{i\\beta} \\bar{q}^n_{\\beta}}{\\sum_\\beta S_{i\\beta}} \\label{eq:stab_mapping}\n\\end{equation}\nIn particular, volume flux contributions can be written:\n\\begin{equation}\n  f_{c}^{n}=\\sum_{\\mu=1}^{N_p^{c}}\\[S_{2c-1,\\mu}\\frac{\\sum_\\beta S_{2c-1,\\beta}\\bar{q}^n_{\\beta}}{\\sum_\\gamma S_{2c-1,\\gamma}}+ S_{2c,\\mu}\\frac{\\sum_\\beta S_{2c,\\beta} \\bar{q}^n_{\\beta}}{\\sum_\\gamma S_{2c,\\gamma}} \\]=\\sum^{N_p}_{\\beta=1}\\(S_{2c-1,\\beta} +S_{2c,\\beta} \\)\\bar{q}^n_{\\beta} \\label{eq:volume_fluxes_mapped}\n\\end{equation}\nThus, introduction of mappings \\eqref{eq:stab_mapping} and \\eqref{eq:volume_fluxes_mapped} in equation \\eqref{eq:euler_before_mapping} and permutation of sums over $\\beta$ and $i$ lead after some simplifications to the scheme equation:\n\\begin{equation}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha = \\sum_{\\beta=1}^{N_p} \\bar{Q}^{n}_\\beta & \\left\\lbrace \\vphantom{\\frac{S_{2c(\\alpha)-1,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}}S_{2c(\\alpha)-1,\\alpha}\\frac{S_{2c(\\alpha)-1,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}} + S_{2c(\\alpha),\\alpha}\\frac{S_{2c(\\alpha),\\beta}}{\\sum_\\mu S_{2c(\\alpha),\\mu}} \\right. \\\\\n    & -\\frac{a\\Delta t}{\\Delta X}N_p^{c(\\alpha)}\\frac{S_{2c(\\alpha),\\alpha}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}\\frac{S_{2c(\\alpha),\\beta}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}\\\\\n    & + \\frac{a\\Delta t}{\\Delta X}N_p^{c(\\alpha)} \\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}\\frac{S_{2c(\\alpha)-2,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-2,\\mu}} \\\\\n    &\\left.+ \\frac{a\\Delta t}{\\Delta X}\\[\\frac{S_{2c(\\alpha),\\alpha}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}-\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}\\]\\(S_{2c(\\alpha)-1,\\beta} +S_{2c(\\alpha),\\beta}\\) \\right\\rbrace \\label{eq:scheme_euler1}\n  \\end{split}\n\\end{equation}\nNote that the last term of formula \\eqref{eq:scheme_euler1} is non-zero if particles $\\beta$ and $\\alpha$ share the same cell, and in that case the parenthesis is one. Hence, the scheme equation can be rewritten as:\n\\begin{equation}\n  \\label{eq:Euler_scheme}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha = \\sum_{\\beta=1}^{N_p} \\bar{Q}^{n}_\\beta  &\\left\\lbrace\\sum_{i=1}^{2E}S_{i\\beta}\\frac{S_{i\\alpha}}{\\sum_\\mu S_{i\\mu}}  + N_p^{c(\\alpha)}\\frac{a\\Delta t}{\\Delta X} \\[\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\frac{S_{2c(\\alpha)-2,\\beta}}{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}}-\\frac{S_{2c(\\alpha),\\alpha}S_{2c(\\alpha),\\beta}}{\\(\\sum_{\\mu}  S_{2c(\\alpha),\\mu}\\)^2}\\]\\right.\\\\\n    & + \\left.   \\frac{a\\Delta t}{\\Delta X} \\[\\frac{S_{2c(\\beta),\\alpha}}{\\sum_{\\mu}  S_{2c(\\beta),\\mu}}-\\frac{S_{2c(\\beta)-1,\\alpha}}{\\sum_\\mu S_{2c(\\beta)-1,\\mu}}\\] \\vphantom{\\sum_{i=1}^{2E}}\\right\\rbrace\n  \\end{split}\n\\end{equation}\nThe first (\\textit{resp. second}) bracket in equation \\eqref{eq:Euler_scheme} involves shape functions that are non zero if material points $\\beta$ and $\\alpha$ lie in adjacent cells (\\textit{resp. the same cell}).\nHence, the numerical domain of dependence of the DGMPM for the scalar linear advection equation covers two cells regardless of the number of material points.\nIt is worth noticing that in the particular case of one material point lying in every cell, the convective phase \\eqref{eq:stab_mapping} simplifies to: $\\bar{q}^n_i = \\bar{Q}^n_\\alpha$ for $c(i)=c(\\alpha)$. The mapping therefore amounts to a piece-wise constant reconstruction of the field on the background grid that makes the DGMPM equivalent to the \\textit{First Order Upwind (FOU)} method.\nHowever, this no longer holds for other distributions of material points within the computational grid. \n\n\\subsubsection*{Scheme equation: RK2 time discretization}\n\nThe discrete system on the grid resulting from the second-order Runge-Kutta time integration consists of the two-stage procedure \\eqref{eq:DGMPM_discrete_RK2} which, for the one-dimensional scalar linear advection equation, particularizes at node $i$  as:\n\\begin{subequations}\n  \\begin{alignat}{1}\n    \\label{eq:RK2_stage1}& \\bar{q}^{n+1/2}_{i}  =\\bar{q}^{n}_{i} + \\frac{1}{2}\\frac{\\Delta t}{M^L_{i}} a \\( \\sum_{j=1}^{2E} K_{i,j} \\bar{q}^n_{j} - q^{*,n}_{i}N_i \\) \\quad \\text{(no sum on $i$)} \\\\\n    \\label{eq:RK2_stage2}& \\bar{q}^{n+1}_{i}  =\\bar{q}^{n}_{i} + \\frac{\\Delta t}{M^L_{i}} a \\( \\sum_{j=1}^{2E} K_{i,j} \\bar{q}^{n+1/2}_{j} - q^{*,n+1/2}_{i}N_i \\) \\quad \\text{(no sum on $i$)}\n  \\end{alignat}\n\\end{subequations}\nThis procedure can be seen as a recursive use of the Euler scheme \\eqref{eq:nodal_euler} with suitable time step sizes. The first stage \\eqref{eq:RK2_stage1} yields the intermediate nodal fields in cell $c(\\alpha)$:\n\\begin{equation}\n  \\label{eq:discrete_RK2_step1}\n  \\begin{aligned}\n    &\\bar{q}_{2c(\\alpha)-1}^{n+1/2}= \\bar{q}_{2c(\\alpha)-1}^{n} - \\frac{a\\Delta t}{2\\Delta X}\\( \\frac{f_{c(\\alpha)}^{n} - N_p^{c( \\alpha)} \\bar{q}^n_{2c(\\alpha)-2}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}}  S_{2c(\\alpha)-1,\\mu}}\\)\\\\\n    &\\bar{q}_{2c(\\alpha)}^{n+1/2}= \\bar{q}_{2c(\\alpha)}^{n} + \\frac{a\\Delta t}{2\\Delta X}\\( \\frac{f_{c(\\alpha)}^{n}- N_p^{c( \\alpha)}  \\bar{q}^n_{2c(\\alpha)}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}}  S_{2c(\\alpha),\\mu}} \\)\n  \\end{aligned}\n\\end{equation}\nand the second stage \\eqref{eq:RK2_stage2} leads to the expression of nodal quantities at the end of the time step:\n\\begin{equation}\n  \\label{eq:discrete_RK2_step2}\n  \\begin{aligned}\n    &\\bar{q}_{2c(\\alpha)-1}^{n+1}= \\bar{q}_{2c(\\alpha)-1}^{n} - \\frac{a\\Delta t}{\\Delta X}\\( \\frac{\\sum_{\\gamma=1}^{N_p^{c(\\alpha)}}\\[S_{2c(\\alpha)-1,\\gamma}\\bar{q}_{2c(\\alpha)-1}^{n+1/2}+ S_{2c(\\alpha),\\gamma}\\bar{q}_{2c(\\alpha)}^{n+1/2}\\] - N_p^{c( \\alpha)} \\bar{q}^{n+1/2}_{2c(\\alpha)-2}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}}  S_{2c(\\alpha)-1,\\mu}}\\)\\\\\n    &\\bar{q}_{2c(\\alpha)}^{n+1}= \\bar{q}_{2c(\\alpha)}^{n} + \\frac{a\\Delta t}{\\Delta X}\\( \\frac{\\sum_{\\gamma=1}^{N_p^{c(\\alpha)}}\\[S_{2c(\\alpha)-1,\\gamma}\\bar{q}_{2c(\\alpha)-1}^{n+1/2}+ S_{2c(\\alpha),\\gamma}\\bar{q}_{2c(\\alpha)}^{n+1/2}\\]- N_p^{c( \\alpha)}  \\bar{q}^{n+1/2}_{2c(\\alpha)}}{\\sum_{\\mu=1}^{N_p^{c(\\alpha)}}  S_{2c(\\alpha),\\mu}} \\)\n  \\end{aligned}\n\\end{equation}\nThen, introduction of the interpolation from nodes to particles \\eqref{eq:updated_MP} in equations \\eqref{eq:discrete_RK2_step2} leads to the solution at material point $\\alpha$ and time step $n+1$:\n\\begin{equation}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha =  &S_{2c(\\alpha)-1,\\alpha}\\bar{q}_{2c(\\alpha)-1}^{n} - \\(\\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha)-1,\\alpha} - S_{2c(\\alpha),\\alpha}\\frac{\\sum_{\\gamma} S_{2c(\\alpha)-1,\\gamma}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\] \\)\\bar{q}_{2c(\\alpha)-1}^{n+1/2} \\\\ & +S_{2c(\\alpha),\\alpha}\\bar{q}_{2c(\\alpha)}^{n} + \\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha),\\alpha} - S_{2c(\\alpha)-1,\\alpha}\\frac{\\sum_{\\gamma} S_{2c(\\alpha),\\gamma}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}- N_p^{c(\\alpha)}\\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\] \\bar{q}_{2c(\\alpha)}^{n+1/2}\\\\\n    &+N_p^{c(\\alpha)}\\frac{a\\Delta t}{\\Delta X}\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\bar{q}_{2c(\\alpha)-2}^{n+1/2}\n  \\end{split}\n\\end{equation}\nNodal values $q_i^{n+1/2}$ are provided by the first stage of RK2 algorithm and can be substituted in the second stage:\n%Note that the volume fluxes contributions $f_c^{n}$ are used in equations \\eqref{eq:discrete_RK2_step1} and not in \\eqref{eq:discrete_RK2_step2}. Indeed, nodal values $q_i^{n+1/2}$ provided by the first stage of RK2 algorithm are substituted in the second one, it is therefore better to make them appear explicitly. It thus comes:\n\\begin{equation}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha &=  S_{2c(\\alpha)-1,\\alpha}\\bar{q}_{2c(\\alpha)-1}^{n} +S_{2c(\\alpha),\\alpha}\\bar{q}_{2c(\\alpha)}^{n} \\\\\n    -& \\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha)-1,\\alpha} - S_{2c(\\alpha),\\alpha}\\frac{\\sum_{\\mu} S_{2c(\\alpha)-1,\\mu}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\] \\(\\bar{q}_{2c(\\alpha)-1}^{n} - \\frac{a\\Delta t}{2\\Delta X}\\( \\frac{f_{c(\\alpha)}^{n} - N_p^{c( \\alpha)} \\bar{q}^n_{2c(\\alpha)-2}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\)\\) \\\\\n    +& \\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha),\\alpha}\\(1- \\frac{N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\) - S_{2c(\\alpha)-1,\\alpha}\\frac{\\sum_{\\mu} S_{2c(\\alpha),\\mu}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\] \\(\\bar{q}_{2c(\\alpha)}^{n} + \\frac{a\\Delta t}{2\\Delta X}\\( \\frac{f_{c(\\alpha)}^{n}- N_p^{c( \\alpha)}  \\bar{q}^n_{2c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}} \\)\\)\\\\\n    +& N_p^{c(\\alpha)}\\frac{a\\Delta t}{\\Delta X}\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\(\\bar{q}_{2c(\\alpha)-2}^{n} + \\frac{a\\Delta t}{2\\Delta X}\\( \\frac{f_{c(\\alpha)-1}^{n}- N_p^{c( \\alpha)}  \\bar{q}^n_{2c(\\alpha)-2}}{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}} \\)\\) \\label{eq:Mp_before_mapping}\n  \\end{split}\n\\end{equation}\nNote that the solution of the downstream node of the adjacent cell $q^{n+1/2}_{2c(\\alpha)-2}$ results from the second equation of the set \\eqref{eq:discrete_RK2_step1}. Therefore, by rearranging formula \\eqref{eq:Mp_before_mapping} as:\n%Note that the second equation of the set \\eqref{eq:discrete_RK2_step1} is used for $q^{n+1/2}_{2c(\\alpha)-2}$ since it is the downwstream node of the adjacent cell $c(\\alpha)-1$. At last, by rearranging formula \\eqref{eq:Mp_before_mapping} as:\n\\begin{equation}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha =  &\\(S_{2c(\\alpha)-1,\\alpha} -\\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha)-1,\\alpha} - S_{2c(\\alpha),\\alpha}\\frac{\\sum_{\\mu} S_{2c(\\alpha)-1,\\mu}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\]\\)\\bar{q}_{2c(\\alpha)-1}^{n} \\\\\n    +&\\(S_{2c(\\alpha),\\alpha} + \\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha),\\alpha}\\(1-\\frac{N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\) - S_{2c(\\alpha)-1,\\alpha}\\frac{\\sum_{\\mu} S_{2c(\\alpha),\\mu}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\]\\) \\bar{q}_{2c(\\alpha)}^{n} \\\\\n    +&\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2\\(N_p^{c( \\alpha)}\\[\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}} - \\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\] +S_{2c(\\alpha),\\alpha} \\(\\frac{N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\)^2\\)\\bar{q}_{2c(\\alpha)}^{n}\\\\\n    +&N_p^{c( \\alpha)}\\frac{a\\Delta t}{\\Delta X}  \\[ \\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\(1 -   \\frac{a\\Delta t}{2\\Delta X}\\(1+\\frac{N_p^{c( \\alpha)} }{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}} \\)\\)+\\frac{a\\Delta t}{2\\Delta X} \\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\]\\bar{q}^n_{2c(\\alpha)-2}\\\\\n    -&\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2 N_p^{c(\\alpha)}\\frac{S_{2c(\\alpha),\\alpha}}{\\(\\sum_{\\mu}  S_{2c(\\alpha),\\mu}\\)^2} f_{c(\\alpha)}^{n} +\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2N_p^{c(\\alpha)}\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\frac{ f_{c(\\alpha)-1}^{n}}{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}}\n  \\end{split}\n\\end{equation}\nthe use of mapping equations \\eqref{eq:stab_mapping} and \\eqref{eq:volume_fluxes_mapped} allows to write:\n\\begin{equation}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha =  &\\sum_{\\beta} \\bar{Q}_\\beta^n  \\left\\lbrace \\frac{S_{2c(\\alpha)-1,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}}\\(S_{2c(\\alpha)-1,\\alpha} -\\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha)-1,\\alpha} - S_{2c(\\alpha),\\alpha}\\frac{\\sum_{\\gamma} S_{2c(\\alpha)-1,\\gamma}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\]\\)  \\right. \\\\\n    &+\\frac{S_{2c(\\alpha),\\beta}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}\\(S_{2c(\\alpha),\\alpha} + \\frac{a\\Delta t}{\\Delta X}\\[S_{2c(\\alpha),\\alpha}\\(1-\\frac{N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\) - S_{2c(\\alpha)-1,\\alpha}\\frac{\\sum_{\\gamma} S_{2c(\\alpha),\\gamma}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\]\\)  \\\\\n    &+\\frac{S_{2c(\\alpha),\\beta}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2\\(N_p^{c( \\alpha)}\\[\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}} - \\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\] +S_{2c(\\alpha),\\alpha} \\(\\frac{N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\)^2\\)  \\\\\n    &+\\frac{N_p^{c( \\alpha)} S_{2c(\\alpha)-2,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-2,\\mu}}\\frac{a\\Delta t}{\\Delta X} \\[ \\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\(1 -   \\frac{a\\Delta t}{2\\Delta X}\\(1+\\frac{N_p^{c( \\alpha)} }{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}} \\)\\)+\\frac{a\\Delta t}{2\\Delta X} \\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\]\\\\\n    &+\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2 N_p^{c(\\alpha)}\\left.\\( \\frac{\\[S_{2c(\\alpha)-2,\\beta} +S_{2c(\\alpha)-3,\\beta} \\]}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}} S_{2c(\\alpha)-1,\\alpha}-\\frac{\\[S_{2c(\\alpha)-1,\\beta} +S_{2c(\\alpha),\\beta} \\]}{\\(\\sum_{\\mu}  S_{2c(\\alpha),\\mu}\\)^2} S_{2c(\\alpha),\\alpha}\\)  \\right\\rbrace\n  \\end{split}\n\\end{equation}\nOnce the previous formula is simplified, the one-dimensional scheme equation of the DGMPM with the RK2 time discretization can be written:\n\\begin{equation}\n  \\label{eq:RK2_scheme}\n  \\begin{split}\n    \\bar{Q}^{n+1}_\\alpha =  &\\sum_{\\beta} \\bar{Q}_\\beta^n  \\left\\lbrace \\sum_i S_{i\\beta}\\frac{S_{i\\alpha}}{\\sum_\\mu S_{i\\mu}}\n      +\\frac{a\\Delta t}{\\Delta X}\\[\\frac{S_{2c(\\beta),\\alpha}}{\\sum_{\\mu}  S_{2c(\\beta),\\mu}} - \\frac{S_{2c(\\beta)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\beta)-1,\\mu}}\\] \\right.\\\\\n    &+\\frac{a\\Delta t}{\\Delta X}N_p^{c( \\alpha)}\\[\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}}\\frac{S_{2c(\\alpha)-2,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-2,\\mu}}-\\frac{S_{2c(\\alpha),\\alpha}S_{2c(\\alpha),\\beta}}{\\(\\sum_\\mu S_{2c(\\alpha),\\mu}\\)^2}\\] \\\\\n    &+\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2N_p^{c( \\alpha)} \\(\\frac{S_{2c(\\alpha),\\beta}}{\\sum_\\mu S_{2c(\\alpha),\\mu}}-\\frac{S_{2c(\\alpha)-2,\\beta}}{\\sum_\\mu S_{2c(\\alpha)-2,\\mu}}\\)\\[\\frac{S_{2c(\\alpha)-1,\\alpha}}{\\sum_\\mu S_{2c(\\alpha)-1,\\mu}} - \\frac{S_{2c(\\alpha),\\alpha}}{\\sum_{\\mu}  S_{2c(\\alpha),\\mu}}\\]\\\\\n    &+\\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2N_p^{c( \\alpha)}\\frac{S_{2c(\\beta),\\alpha}}{\\(\\sum_{\\mu}  S_{2c(\\alpha),\\mu}\\)^2} \\[N_p^{c( \\alpha)}\\frac{S_{2c(\\alpha),\\beta} }{\\sum_\\mu S_{2c(\\alpha),\\mu}}-1\\]\\\\\n    &+ \\frac{1}{2}\\(\\frac{a\\Delta t}{\\Delta X}\\)^2\\frac{S_{2c(\\beta)+1,\\alpha}N_p^{c(\\alpha)}}{\\sum_{\\mu}  S_{2c(\\alpha)-1,\\mu}\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}} \\left.\\[ 1 - N_p^{c( \\alpha)}\\frac{S_{2c(\\alpha)-2,\\beta} }{\\sum_{\\mu}  S_{2c(\\alpha)-2,\\mu}}\\] \\right\\rbrace\n    \\end{split}\n\\end{equation}\nThe three first terms of the latter scheme equation correspond to that obtained for the Euler algorithm \\eqref{eq:Euler_scheme} while the second order terms are provided by the two-stage time integration. The brackets in those higher-order corrections vanish when only one point is in each cell of the grid, so that the scheme is, as that of the previous section, equivalent to the FOU method.\n\n\\subsubsection*{The von Neumann linear stability analysis}\nThe scheme equations obtained above are written for simplicity:\n\\begin{equation}\n\\bar{Q}^{n+1}_\\alpha = \\sum_{\\beta=1}^{N_p}  D_{\\alpha\\beta} \\bar{Q}^n_{\\beta}\\label{eq:scheme_Dpi}\n\\end{equation}\nMoreover, the computational domain is repeated periodically by mapping it to the domain $[-l,0]$ so that the solution at material point $\\alpha$ and time step $n$ is expanded into a discrete Fourier basis of $2E+1$ harmonics over the domain $X \\in \\[-l,l\\]$:\n\\begin{equation}\n\\bar{Q}^{n}_\\alpha = \\sum_{j=-E}^{E}A_j^n e^{i \\alpha k_j \\Delta X}\n\\end{equation}\nwith $A^n_j$, the magnitude of the $j$th harmonic at time step $n$, $i = \\sqrt{-1}$, and $k_j$ a wave number. Introduction of this expansion in equation \\eqref{eq:scheme_Dpi} yields:\n\\begin{equation}\nA_j^{n+1} e^{i\\alpha k_j \\Delta X} = \\sum_{\\beta=1}^{N_p} A_j^n D_{\\alpha\\beta}e^{i \\beta k_j \\Delta X}\\quad \\forall j=-E,...,E\n\\end{equation}\nThe amplification factor between two time steps at a given point is defined as:\n\\begin{equation}\n\\frac{A_j^{n+1}}{A_j^n} = \\sum_{\\beta=1}^{N_p} e^{i (\\beta -\\alpha)k_j \\Delta X} D_{\\alpha\\beta} \\quad \\forall j=-E,...,E \\label{eq:fourier_expansion}\n\\end{equation}\nA necessary condition to ensure the stability of a numerical scheme is that the amplification factor must be lower than or equal to one in modulus: $\\abs{A^{n+1}/A^n} \\leq 1$. This upper bound prevents an increasing error during the computation. For expression \\eqref{eq:fourier_expansion}, this leads to:\n\\begin{equation}\n \\abs{\\sum_{\\beta=1}^{N_p} e^{i (\\beta -\\alpha)k_j \\Delta X} D_{\\alpha\\beta}} \\leq \\sum_{\\beta=1}^{N_p} \\abs{e^{i (\\beta -\\alpha)k_j \\Delta X} D_{\\alpha\\beta}} = \\sum_{\\beta=1}^{N_p} \\abs{D_{\\alpha\\beta}} \\quad \\forall j=-E,...,E\n\\end{equation}\nwhere the triangle inequality, and the unit modulus of the complex number $e^{i (\\beta -\\alpha)k_j \\Delta X}$ have been used.\nHence, the Courant number must be set so that the following condition is satisfied for all material points:\n\\begin{equation}\n  \\label{eq:stability} \\sum_{\\beta=1}^{N_p} \\abs{D_{\\alpha\\beta}} \\leq 1 \\quad \\forall \\: \\alpha = 1,...,N_p\n\\end{equation}\n% The stability of the scheme is thus ensured by using the lowest CFL number satisfying \\eqref{eq:stability}.\nNote however that the use of the triangle inequality leads to a more severe constraint than the one really holding.\nAs a consequence, the Courant number can be set in practice to higher values than that resulting from the solution of \\eqref{eq:stability}. \n\n%According to scheme equations \\eqref{eq:Euler_scheme} or \\eqref{eq:RK2_scheme}, such a stability condition can be very hard to find analytically for general discretizations. \nAccording to scheme equations \\eqref{eq:Euler_scheme} or \\eqref{eq:RK2_scheme}, the stability condition \\eqref{eq:stability} can be very hard to find analytically for general discretizations. \nNevertheless, though the infinity of possible material point distributions prevents the explicit derivation of a general stability condition, the optimal CFL number satisfying the equality in \\eqref{eq:stability} can be found numerically. Some configurations are studied in table \\ref{tab:CFL_comparison} where the critical Courant number resulting from the two time discretizations studied above are compared. Those results have been obtained by using the same particle distribution in every element of a one-dimensional regular mesh. \n% so that a material point $\\alpha$ must lie between the nodes of the cell it belongs to, that is, $X^I \\in \\[X^{2c-1},X^{2c}\\]$. \nFirst, the DGMPM scheme is stable for all CFL numbers lower than or equal to one when cells contain one particle only regardless of their positions.\nThis property characterizes the FOU method that is retrieved with this discretization. \nThen, when many material points share the same element, several configurations are considered:\n\\begin{itemize}\n\\item[(i)] particles are positioned symmetrically with respect to cell centers and regularly spaced in the mesh.\n  This space discretization is referred to as the natural configuration in the following.\n\\item[(ii)] particles in the natural configuration are all shifted by $u=\\Delta X/10$.\n\\item[(iii)] the same as (ii) with $u$ so that one material point overlaps every left node of the cells.\n\\item[(iv)] the same as (iii) for right nodes.\n\\item[(v)] particles are placed symmetrically with respect to cell centers but not regularly spaced in the mesh. Material points in the left half of cells are shifted by $u_1=-\\Delta X/10$ while those in the right half are shifted by $u_2=\\Delta X/10$.\n\\item[(vi)] the same as (v) with the first and last particles overlapping left and right nodes of cells respectively.\n\\end{itemize}\n\\begin{table}[h]\n  \\centering\n  \\input{chapter3/tabular/CFL_comparison}\n  \\caption{DGMPM critical Courant number values for Euler or RK2 time integration with respect to the number and positions of material points in a one-dimensional grid. Black circles denote material points while white ones represent grid nodes.}\n  \\label{tab:CFL_comparison}\n\\end{table}\n%RK2 results bad when the upwind material point move to the right\n%One can see in table \\ref{tab:CFL_comparison} that the RK2 time discretization generally provides better results in terms of CFL number for the particles distributions considered. However, a uniform translation of material points in the mesh leads to a decrease in the Courant number for both time integrations.\nFirst, table \\ref{tab:CFL_comparison} shows that the natural configuration leads to a better stability bound for the RK2 integrator while the CFL number allowed by using Euler time discretization decreases with increasing numbers of particles per cell.\nSecond, moving every point rightward in the mesh (\\textit{i.e. cases (ii) and (iv)}) causes a drop in the critical Courant number for both RK2 and Euler algorithms. In particular, stability conditions for more than two particles per cell provided by the RK2 are, in those cases, more restrictive than that of the Euler.\nThird, the leftward shift (\\textit{i.e. case (iii)}) leads to an improvement of the stability condition for Euler time integration compared to that in the natural configuration.\nThe CFL number provided by RK2 integration also decreases due to the shift while remaining higher than the Euler.\nAt last, particle distributions conserving the symmetry with respect to cell centers (\\textit{i.e. cases (v) and (vi)}), yield the optimal stability condition for the RK2 integrator while the Euler CFL depends on the spacing between material points.\nMore specifically, the Euler algorithm leads to a vanishing CFL for the case (vi), thus preventing any simulation.\n\n% In table \\ref{tab:CFL_comparison}, we see that in the natural configuration, RK2 integrator leads to the optimal Courant number whereas the one allowed by using Euler discretization depends on the number of material points in cells. Next, those stability conditions become more restrictive when particles are uniformly translated leftward or rightward in the mesh, whit a more significant decrease in CFL number for a translation in the stream direction (\\textit{i.e. cases (ii) and (iv)}). In particular, the RK2 algorithm may yields a lower stability bound than that of Euler approach in situation (iv) with more than two particles per cell.\n% % Furthermore the impact of such a translation is more significant in the stream direction (\\textit{i.e. cases (ii) and (iv)}) in such a way that the decline in CFL number is bigger than for an inverse stream direction (\\textit{i.e. cases (iii)}).\n% In the latter situation, the Euler algorithm provides even better results than in the natural configuration. One the other hand, particles distributions that conserve the symmetry with respect to cells centers lead to the optimal stability condition when using the RK2 time integration while the Euler CFL depends on the spacing between material points. More specifically, Euler algorithm leads to a vanishing CFL for the case (vi), thus preventing any simulation.\nThe distribution of material points, and therefore the resulting quadrature, has an influence on the stability of the scheme. The optimal Courant number can be reached even with the Euler discretization, whereas the classical DGFEM scheme developed in \\cite{Chavent_Salzano} is restricted to condition $\\Delta t / \\Delta X = \\Oc(\\sqrt{\\Delta X})$. This limitation has been addressed by introducing slope limiters in order to remove non-physical oscillations in the vicinity of sharp solutions while providing high-order accuracy in smooth regions \\cite{Chavent_Cockburn}. However, the stability of the method is still bounded by $CFL\\leq 1/2$ and the scheme is first-order accurate. The use of a second-order Runge-Kutta \\cite{DGFEM_CFL} allows second-order accuracy of the scheme, but the stability condition then reduced to $CFL\\leq1/3$. It is worth noting that space–time DGFEM formulations \\cite{ST_DGFEM1,ST_DGFEM2} provided more recently the ability to relax constraints of pure space DGFEM and obtain a critical CFL of 1.\n\n\\subsection{Space convergence analysis of the one-dimensional scheme}\n\\label{sec:convergence}\nWe now propose to focus numerically on convergence properties of DGMPM schemes for linear elasticity problems in homogeneous solids undergoing one-dimensional stress and strain states so that the bar assumption under small strains holds.\nThe following system of one-dimensional linear scalar advection equations is then considered:  \n\\begin{equation}\n  \\label{eq:conv_hyperbolic}\n  \\drond{}{t} \\matrice{v \\\\ \\sigma} -\\drond{}{X}\\matrice{\\frac{1}{\\rho}\\sigma \\\\ Ev} = \\matrice{0 \\\\0}\n\\end{equation}\nin a bar of length $l=1\\:m$, with Young's modulus $E=2\\times10^{11}\\: Pa$, and mass density $\\rho=7800 \\:kg\\cdot m^{-3}$. \nThe bar is assumed to be initially motionless in a free-stress state, that is: $v(X,0)=0 \\:;\\:\\sigma(X,0)=0 \\quad \\forall X \\in [0,l]$, and subject to the following boundary conditions on its left and right ends respectively:\n\\begin{equation}\n  \\label{eq:conv_Bcs}\n    \\begin{aligned}\n    &\\sigma(X=0,t) = \\tilde{\\sigma} \\sin\\(\\frac{0.4\\pi t}{T}\\)\\\\\n    &\\sigma(X=l,t) =0,  \\qquad \\forall t \\in [0,T]\n  \\end{aligned}\n\\end{equation}\nwhere $T=l/c$ is the time taken by waves to travel from one end of the bar to the other at the sound speed $c=\\sqrt{\\frac{E}{\\rho}}$. The combination of the hyperbolic system \\eqref{eq:conv_hyperbolic} and boundary conditions \\eqref{eq:conv_Bcs} yields a Picard problem whose exact solution is \\cite[Ch.2]{Wang}:\n\\begin{equation}\n    \\label{eq:exact_solution_convergence}\n  \\begin{aligned}\n    &\\sigma(X,t)=\\tilde{\\sigma} \\sin\\(\\frac{0.4\\pi (t-X/c)}{T}\\) \\\\\n    & v(X,t)=-\\frac{\\tilde{\\sigma}}{\\rho c}\\sin\\(\\frac{0.4\\pi (t-X/c)}{T}\\), \\quad \\forall \\:X, t \\in \\[0,l\\]\\times\\[0,T\\]\n  \\end{aligned}\n\\end{equation}\nThe continuum system \\eqref{eq:conv_hyperbolic} is discretized with both MPM (the USF formulation is selected to limit the numerical dissipation) and DGMPM by using $2^i$ cells ($i=2,3,...,7$) each containing $N_p=2,3,4,8$ regularly spaced material points so that the regular grid size is $\\Delta X= l/2^i$.\nThe refinement of the mesh operates on both nodes and particles in such a way that the number and position of material points per cell initially selected is held constant.\nConfigurations involving different numbers of particles per element are studied separately and the CFL number can therefore be set once and for all (optimal for DGMPM, and $0.5$ for the MPM).\nNumerical solutions are then compared to the exact one \\eqref{eq:exact_solution_convergence} according to the relative $L^2$ norm of the error, also referred to as the $L^2$ error $\\epsilon$:\n\\begin{subequations}\n  \\begin{alignat}{1}\n    \\label{eq:L2_error_S}\n    & \\epsilon_\\sigma(t) = \\(\\Delta X \\sum_{\\alpha=1}^{N_p}\\frac{(\\sigma_\\alpha - \\sigma_{\\text{exact}}(X_\\alpha,t))^2}{\\sigma_{\\text{exact}}(X_\\alpha,t)^2}\\)^{\\frac{1}{2}} \\\\\n    \\label{eq:L2_error_V}\n    & \\epsilon_v(t) = \\(\\Delta X \\sum_{\\alpha=1}^{N_p}\\frac{(v_\\alpha - v_{\\text{exact}}(X_\\alpha,t))^2}{v_{\\text{exact}}(X_\\alpha,t)^2}\\)^{\\frac{1}{2}}\n  \\end{alignat}\n\\end{subequations}\nThe errors are computed at time $t=0.5 T$ so that no reflection of waves on the right boundary occur and the stress amplitude is set at $\\tilde{\\sigma}=4\\times 10^4\\:Pa$. Figure \\ref{fig:convergence_stress} shows the evolution of the $L^2$ errors $\\epsilon_\\sigma$ with regard to the grid size for the MPM and the DGMPM using Euler and RK2 time discretizations for several numbers of particles per element.\nWe see that, despite the rates of convergence of stress are close to one (obtained by means of non-linear least squares fitting and reported in table \\ref{tab:accuracy}), the DGMPM--Euler and DGMPM--RK2 exhibit lower rates compared to those of the MPM. \n\\begin{figure}[h!]\n  \\centering\n  {\\input{chapter3/pgfFigures/convS_2ppc.tex}\\phantomsubcaption\\label{subfig:convS_2ppc}}\n  {\\input{chapter3/pgfFigures/convS_6ppc.tex}\\phantomsubcaption\\label{subfig:convS_6ppc}}\n  {\\input{chapter3/pgfFigures/convS_10ppc.tex}\\phantomsubcaption\\label{subfig:convS_10ppc}}\n  {\\input{chapter3/pgfFigures/convS_20ppc.tex}\\phantomsubcaption\\label{subfig:convS_20ppc}}\n  \\caption{Evolution of the $L^2$ errors in stress with regard to the number of particles lying in every cell.}\n  \\label{fig:convergence_stress}\n\\end{figure}\n\\begin{table}[h!]\n  \\centering\n  \\input{chapter3/tabular/accuracy}\n  \\caption{Order of accuracy of MPM and DGMPM with regard to the number of particles per cell}\n  \\label{tab:accuracy}\n\\end{table}\nSecond, an increase in the number of particles per cell provides slightly higher convergence rates, according to table \\ref{tab:accuracy}, and shifts DGMPM curves upward as can be seen in figures \\ref{fig:convergence_stress}\\subref{subfig:convS_2ppc} to \\ref{fig:convergence_stress}\\subref{subfig:convS_20ppc}.\nOn the other hand, the MPM error curves do not exhibit this behavior as observed in \\cite{MPM_BSpline1}.\nAt last, for coarse grids (\\textit{i.e.} $\\Delta X= l/2^i$ for $i \\leq 3$) the DGMPM--Euler leads to the lowest error but its smaller rate of convergence makes it quickly less accurate than the two other methods.\nSimilar behavior can be seen for the velocity, whose convergence curves are depicted in figure \\ref{fig:convergence_velocity} for the same discretizations.\nAgain, the DGMPM shows lower rates of convergence than the MPM, and increasing the number of particles per cell leads to more error in DGMPM solutions.\nThe same order of accuracy for velocity and stress resulting from the DGMPM (see table \\ref{tab:accuracy}) was expected since the weak form of system \\eqref{eq:conv_hyperbolic} leads to the same approximation for both fields.\nThe MPM is on the other hand, as FEM, characterized by a higher order of convergence for velocity than stress owing to the use of shape function derivatives for the computation of gradients.\nHence, the MPM rate of convergence in terms of velocity is getting closer to two. \n\nThe loss of accuracy for velocity in DGMPM can be explained by the mapping procedure it uses from nodes to particles since the FLIP mapping has been introduced in order to reach second-order accuracy \\cite{PIC_Nishiguchi}.\nConvergence properties of the MPM using the PIC projection shown in table \\ref{tab:accuracy} and figure \\ref{fig:convergence_velocity} confirm the previous remark.\nIndeed, modifying the way fields are projected from nodes to particles does not affect dramatically the rate of convergence of stress but leads to a significant decrease in velocity accuracy.\n\\begin{figure}[h!]\n  \\centering\n  {\\input{chapter3/pgfFigures/convV_2ppc.tex}\\phantomsubcaption\\label{subfig:convV_2ppc}}\n  {\\input{chapter3/pgfFigures/convV_6ppc.tex}\\phantomsubcaption\\label{subfig:convV_6ppc}}\n  {\\input{chapter3/pgfFigures/convV_10ppc.tex}\\phantomsubcaption\\label{subfig:convV_10ppc}}\n  {\\input{chapter3/pgfFigures/convV_20ppc.tex}\\phantomsubcaption\\label{subfig:convV_20ppc}}\n  \\caption{Evolution of the $L^2$ error in velocity with regard to the number of particles lying in every cell.}\n  \\label{fig:convergence_velocity}\n\\end{figure}\n\nWe now propose to set the Courant number to $0.1$ for the MPM and the DGMPM-Euler in order to compare the accuracy of those first order in time schemes with the same time steps.\n\\begin{figure}[h!]\n  \\centering\n  {\\label{subfig:lowCFL_stress}\\input{chapter3/pgfFigures/convS_2ppclowCFL.tex}}\n  {\\label{subfig:lowCFL_velo}\\input{chapter3/pgfFigures/convV_2ppclowCFL.tex}}\n  \\caption{Evolution of the $L^2$ errors in stress and velocity for two particles per cell. CFL set to 0.1.}\n  \\label{fig:convergence_lowCFL}\n\\end{figure}\n% \\begin{table}[h!]\n%   \\centering\n%   \\input{chapter3/tabular/accuracy_lowCFL}\n%   \\caption{Order of accuracy of MPM and DGMPM for two particles per cell and CFL number set to 0.1.}\n%   \\label{tab:accuracy_low}\n% \\end{table}\nA comparison between the convergence curves obtained for a CFL set to $0.1$ and the previous results (\\textit{i.e. figures \\ref{fig:convergence_stress} and \\ref{fig:convergence_velocity}}) is made in figure \\ref{fig:convergence_lowCFL}.\nThe results first show that the order of accuracy of the DGMPM-Euler is also lower than that of the MPM when the same CFL is used in the methods.\nSecond, as can be seen in figure \\ref{fig:convergence_lowCFL}, the reduction of the time step yields additional error which can be explained by the numerical diffusion introduced in the solutions.\nAs a consequence, the curves resulting from computations performed with a Courant number set to $0.1$ are above those obtained previously.\nHowever, a lower CFL enables an improvement of the rates of convergence of the methods. Indeed, the rates of convergence for both velocity and stress are in that case $0.66$ for the DGMPM-Euler, and $1.00$ for the MPM.\n\nSince the DGMPM aims at capturing non-regular solutions (discontinuities), its first-order of convergence is sufficient. Indeed, the achievable accuracy for such solutions is at most one \\cite[p.149]{Leveque}. \nNevertheless, one might be interested in solving problems that involve smooth solutions so that the need for higher-order accuracy arises.\nAlthough linear shape functions have been employed so far, the method may handle higher-order approximation by using Legendre polynomials or B-Spline functions for instance (higher-order Lagrange polynomials being to be avoided for moving particles \\cite{MPM_BSpline1}).\nFurthermore, DG features enable the local increase in the approximation order in regions where the solution is smooth.\nNote however that the particle-based quadrature rule limits the shape function order one can select since few material points may lead to reduced integration. \nThis issue can however be avoided by means of function reconstruction techniques which build a (\\textit{linear, quadratic etc.}) function on the grid that is based on the values a field takes at particle locations and which can be evaluated everywhere in a cell.\nIn particular, the use of \\textit{moving least squares} \\cite{IMPM} or \\textit{spline interpolation} \\cite{MPM_BSpline1,MPM_BSpline2} within the MPM, enables evaluation of a reconstructed function at Gauss point locations in order to improve the quadrature rule.\nHowever, the introduction of such reconstruction techniques in the DGMPM might lead to a restrictive stability condition as it would make the method closer to DGFEM.\n\n\nFinally, it is worth noticing that only regularly-spaced material points have been considered in the above convergence analysis.\nAn additional means of achieving high-order accuracy can be derived from the following theorem applying to the one-dimensional scalar linear advection equation with $a>0$:\n\\begin{theorem}[Roe \\cite{Toro}]\n  \\label{th:Roe}\n  A numerical scheme of the form:\n  \\begin{equation}\n    \\label{eq:scheme_Roe}\n    Q^{n+1}_\\alpha=\\sum_{\\beta=-\\infty}^{\\infty} D_{\\beta} Q^{n}_{\\alpha+\\beta}\n  \\end{equation}\n  is $p$th order accurate ($p\\geq 0$) in space and time if and only if:\n  \\begin{equation}\n    \\label{eq:Roe_condition}\n    \\sum_\\beta \\beta^k D_{\\beta} = \\(-a\\frac{\\Delta t}{\\Delta X}\\)^k \\quad 0 \\leq k \\leq p\n  \\end{equation}\n\\end{theorem}\nThe complexity of scheme equations \\eqref{eq:Euler_scheme} and \\eqref{eq:RK2_scheme} developed previously, and the lack of such equations for MPM formulations prevent the straightforward calculation of convergence rates.\n% However, one can imagine to build adaption strategies of the set of particles based on theorem \\ref{th:Roe}, so that a given order of accuracy is reached.\nHowever, one can imagine the building of adaptive strategies of the set of particles based on theorem \\ref{th:Roe}, so that a given order of accuracy is reached.\nIf such a distribution of material point exists, the corresponding Courant number can also be computed, thus ensuring both stability and accuracy of the numerical scheme.\n\n\n\\subsection{Two-dimensional stability analysis}\n\\subsubsection*{Model equation -- Space discretization}\nWe now move on to the scalar linear advection equation for an arbitrary quantity $q=\\rho \\bar{q}$ moving at constant speeds $a,b \\in \\Rbb^{+*}$ in the $X$ and $Y$ directions respectively in a homogeneous two-dimensional medium:\n\\begin{equation}\n  \\label{eq:2D_model_equation}\n  \\drond{\\bar{q}}{t} + a\\drond{\\bar{q}}{X} + b\\drond{\\bar{q}}{Y}= 0\n\\end{equation}\nNote that the flux functions are in this case $\\bar{f}^X = a\\bar{q}$ and $\\bar{f}^Y = b\\bar{q}$.\nThe physical domain $[0,l]\\times[0,h]$ is discretized with $N_p$ material points arbitrarily distributed in a Cartesian grid made of $E$ four-node bilinear elements with constant size $\\Delta X \\times \\Delta Y$.\n\\begin{figure}[h!]\n  \\centering\n  \\input{chapter3/pgfFigures/2Dparent}\n  \\caption{Parent and current configurations of a rectangular four-node bilinear element}\n  \\label{fig:2Dparent}\n\\end{figure}\nWith the nodal positions in cell $C$ denoted by $\\vect{X}_i^C=\\matrice{X^C_i \\\\ Y_i^C}$, as depicted in figure \\ref{fig:2Dparent}, the current location $\\vect{X}$ of an arbitrary point in cell $C$ maps to the parent coordinates $(\\xi,\\eta)$ in the domain $\\[-1,1\\]\\times\\[-1,1\\]$ according to:\n\\begin{equation}\n  \\label{eq:parentCoordinates}\n  \\begin{aligned}\n      &\\xi = 2\\frac{X-X^C_1}{\\Delta X} -1 \\quad ; \\quad d\\xi = 2\\frac{dX}{\\Delta X} \\\\\n      &\\eta = 2\\frac{Y-Y^C_1}{\\Delta Y} -1 \\quad ; \\quad d\\eta = 2\\frac{dY}{\\Delta Y} \n  \\end{aligned}\n\\end{equation}\nHorizontal and vertical edges lengths are distinguished here in spite of the Cartesian nature of the grid in order to easily extend the following study to rectilinear grids. Again, there are no empty cells inside the physical domain so that no hole is generated, and periodic boundary conditions are considered to simplify the analysis.\n\n\\subsubsection*{Two-dimensional scheme equation}\nOne can imagine the combination of the DGMPM discretization with a multi-stage time integration, as proposed for one-dimensional problems.\nThe analysis of the DGMPM scheme for two-dimensional problems carried out here however only considers the Euler time discretization.\n%As we shall see, the use of the CTU method (see section \\ref{subsec:interface_fluxes}) introduces second-order corrections in time within the original DCU approach.\nTherefore, the updated solution at material point $\\alpha$ is obtained by interpolation of nodal solutions satisfying equation \\eqref{eq:2D_model_equation}, discretized as:\n\\begin{equation}\n  \\bar{q}_i^{n+1} = \\bar{q}_i^n + \\frac{\\Delta t}{M^L_i} \\(K_{ij}^X a\\bar{q}_j^n + K_{ij}^Y b\\bar{q}_j^n - \\hat{f}_i^{*}\\) \\label{eq:discrete2D}\n\\end{equation}\nso that:\n\\begin{equation}\n  \\label{eq:2D_updatedMP}\n  \\bar{Q}^{n+1}_\\alpha = \\sum_{i=1}^{4E}S_{i\\alpha} \\bar{q}_i^{n+1}\n\\end{equation}\nThe lumped mass matrix in equation \\eqref{eq:discrete2D} has the same expression as in the one-dimensional case that depends on the shape functions of the four-node bilinear element: $M_i^L=\\sum_\\mu m_\\mu S_{i\\mu}$. Making use of parent coordinates \\eqref{eq:parentCoordinates}, the pseudo-stiffness matrices read:\n\\begin{equation}\n  \\begin{aligned}\n    & K_{ij}^X = \\sum_\\beta \\drond{S_{i\\beta}}{X}m_\\beta S_{j\\beta}=\\frac{2}{\\Delta X}\\sum_\\beta\\drond{S_{i\\beta}}{\\xi}m_\\beta S_{j\\beta} \\\\\n    &K_{ij}^Y = \\sum_\\beta\\drond{S_{i\\beta}}{Y}m_\\beta S_{j\\beta}=\\frac{2}{\\Delta Y}\\sum_\\beta\\drond{S_{i\\beta}}{\\eta}m_\\beta S_{j\\beta} \\\\\n  \\end{aligned}\n\\end{equation}\nAs for the one-dimensional case, the homogeneous medium yields the same mass for every particle so that, by writing $\\drond{(\\bullet)}{\\xi}=\\partial_\\xi(\\bullet)$, one gets:\n\\begin{equation}\n  \\label{eq:2Dpseudo_stiffness}\n  \\begin{aligned}\n    & \\frac{K_{ij}^X}{M_i^L}  =  \\frac{2}{\\Delta X} \\frac{\\sum_\\lambda\\partial_\\xi S_{i\\lambda}  S_{j\\lambda}}{\\sum_\\gamma  S_{i\\gamma}} \\\\\n    & \\frac{K_{ij}^Y}{M_i^L} = \\frac{2}{\\Delta Y} \\frac{\\sum_\\lambda\\partial_\\eta S_{i\\lambda} S_{j\\lambda}}{\\sum_\\gamma S_{i\\gamma}}\n  \\end{aligned}\n\\end{equation}\nThe nodal solutions at time $n$ being given by the projection $\\bar{q}^{C,n}_i=\\frac{\\sum_\\beta S_{i\\beta}\\bar{Q}^n_\\beta}{\\sum_\\gamma S_{i\\gamma}}$, volume fluxes of the discrete form can be rewritten as:\n\\begin{equation}\n  \\label{eq:2Dvolume_fluxes}\n  \\begin{aligned}\n    & a\\frac{K_{ij}^X}{M_i^L}\\bar{q}^n_j  = \\sum_\\beta \\bar{Q}^n_\\beta \\frac{2}{\\Delta X} \\frac{a\\sum_\\lambda\\partial_\\xi S_{i\\lambda}  \\sum_j S_{j\\lambda} S_{j\\beta}}{\\sum_\\gamma  S_{i\\gamma}\\sum_\\mu S_{j\\mu}}\\\\\n    & b\\frac{K_{ij}^Y}{M_i^L}\\bar{q}^n_j = \\sum_\\beta \\bar{Q}^n_\\beta\\frac{2}{\\Delta Y}  \\frac{b \\sum_\\lambda\\partial_\\eta S_{i\\lambda}  \\sum_j S_{j\\lambda} S_{j\\beta}}{\\sum_\\gamma  S_{i\\gamma}\\sum_\\mu S_{j\\mu}}\n  \\end{aligned}\n\\end{equation}\nThen, the nodal interface flux $\\hat{f}_i^{*}$ results from the integration of Godunov fluxes along edges connected to the node, according to the weak form \\eqref{eq:DGMPM_semi_discrete}.\nReferring to a quantity defined at an interface by means of superscripts in parentheses, the Godunov flux corresponding to equation \\eqref{eq:2D_model_equation} at interface $(i)$ is:\n\\begin{equation}\n  \\label{eq:2d_Godunov_fluxes}\n  f^{(i)}= c_n q^{(i)}_U = \\underbrace{c_nq^{(i)}_D}_{f_N(q^{(i)}_D)} - \\underbrace{c_n (q^{(i)}_D -q^{(i)}_U)}_{A^{+}_{U/D}} \n\\end{equation}\nwhere $c_n$ is the speed in the normal direction to the interface (\\textit{i.e. b for horizontal and a for vertical edges}). Equation \\eqref{eq:2d_Godunov_fluxes} further involves state vectors $q^{(i)}_U$ and $q^{(i)}_D$ obtained by averaging nodal values connected to interface $(i)$ on upwind and downwind sides respectively, and the right-going fluctuation $A_{U/D}^+$.\nThe CTU is adopted by subtracting from fluxes \\eqref{eq:2d_Godunov_fluxes} transverse corrections based on those fluctuations according to equation \\eqref{eq:transverse_fluctuations}:\n\\begin{equation}\n  \\label{eq:2D_transverse_corrections}\n  B^+A^+_{U/D}=c_t c_n (q^{(i)}_D -q^{(i)}_U)\n\\end{equation}\nwith $c_t$ the speed in the tangent direction to the interface. The final expression of intercell fluxes is hence:\n\\begin{equation}\n  \\label{eq:CTU-fluxes}\n  f^{(i)}= c_n q^{(i)}_U - c_t c_n \\frac{\\Delta t}{2\\Delta X^{(i)}}(q^{(i)}_D -q^{(i)}_U)\n\\end{equation}\n%with $\\Delta X^{(i)}$ the length of edge $(i)$.\n\\begin{figure}[h!]\n  \\centering\n  \\input{chapter3/pgfFigures/2D_domain}\n  \\caption{Two-dimensional patch of cells of constant size $\\Delta X \\times \\Delta Y$.}\\label{fig:2Dmesh}\n\\end{figure}\nFigure \\ref{fig:2Dmesh} shows transverse corrections in the cell $C$ based on fluctuations coming from Bottom ($B$), Left ($L$), Bottom Left ($BL$) neighbor elements. The use of the numbering of interfaces and nodes adopted in figure \\ref{fig:2Dmesh} allows the specialization of equation \\eqref{eq:CTU-fluxes} to intercell fluxes of cell $C$:\n\\begin{align}\n  & f^{(1)} = b \\frac{q_3^{B,n} + q_4^{B,n}}{2} - a b \\frac{\\Delta t}{2\\Delta Y}\\(\\frac{q_1^{B,n}+q_4^{B,n}}{2}-\\frac{q_2^{BL,n}+q_3^{BL,n}}{2}\\) \\\\\n  & f^{(2)} = a \\frac{q_2^{C,n} + q_3^{C,n}}{2} - a b \\frac{\\Delta t}{2\\Delta X}\\(\\frac{q_1^{C,n}+q_2^{C,n}}{2}-\\frac{q_3^{B,n}+q_4^{B,n}}{2}\\) \\\\\n  & f^{(3)} = b \\frac{q_3^{C,n} + q_4^{C,n}}{2} - a b \\frac{\\Delta t}{2\\Delta Y}\\(\\frac{q_1^{C,n}+q_4^{C,n}}{2}-\\frac{q_2^{L,n}+q_3^{L,n}}{2}\\) \\\\\n  & f^{(4)} = a \\frac{q_3^{L,n} + q_4^{L,n}}{2} - a b \\frac{\\Delta t}{2\\Delta X}\\(\\frac{q_1^{L,n}+q_2^{L,n}}{2}-\\frac{q_3^{BL,n}+q_4^{BL,n}}{2}\\)\n\\end{align}\nwhere $q^{C,n}_i= \\rho \\bar{q}^{C,n}_i$ is the value at time step $n$ and node $i$ of cell $C$. Denoting the number of particles in cell $C$ and the mass they carry by $N_p^C$ and $m^C$ respectively, the mass density reads $\\rho = \\frac{N_p^{C} m^C}{\\Delta X \\Delta Y}$. Thus, introduction of the particle fields projection yields the following expressions for interface fluxes:\n\\begin{align}\n  & f^{(1)} = \\sum_{\\beta=1}^{N_p}\\bar{Q}_\\beta^n\\frac{b N^C_p m^C }{2\\Delta X \\Delta Y} \\[  \\(\\frac{S_{3\\beta}^{B} }{\\sum_\\gamma S_{3\\gamma}^{B}} + \\frac{S_{4\\beta}^{B}}{\\sum_\\gamma S_{4\\gamma}^{B}}\\) - a  \\frac{\\Delta t}{2\\Delta Y}\\(\\frac{S_{1\\beta}^{B}}{\\sum_\\gamma S_{1\\gamma}^B} + \\frac{S_{4\\beta}^{B}}{\\sum_\\gamma S_{4\\gamma}^{B} }-\\frac{S_{2\\beta}^{BL}}{\\sum_\\gamma S_{2\\gamma}^{BL}} - \\frac{S_{3\\beta}^{BL}}{\\sum_\\gamma S_{3\\gamma}^{BL}}\\) \\]\\\\\n  & f^{(2)} = \\sum_{\\beta=1}^{N_p} \\bar{Q}_\\beta^n\\frac{a N^C_p m^C }{2\\Delta X \\Delta Y} \\[  \\(\\frac{S_{2\\beta}^{C}}{\\sum_\\gamma S_{2\\gamma}^{C}} + \\frac{S_{3\\beta}^{C}}{\\sum_\\gamma S_{3\\gamma}^{C}} \\)- b \\frac{\\Delta t}{2\\Delta X}\\(\\frac{S_{1\\beta}^{C}}{\\sum_\\gamma S_{1\\gamma}^{C}} + \\frac{S_{2\\beta}^{C}}{\\sum_\\gamma S_{2\\gamma}^{C}}-\\frac{S_{3\\beta}^{B}}{\\sum_\\gamma S_{3\\gamma}^{B}} -\\frac{S_{4\\beta}^{B}}{\\sum_\\gamma S_{4\\gamma}^{B}}\\) \\]\\\\\n  & f^{(3)} =\\sum_{\\beta=1}^{N_p}\\bar{Q}_\\beta^n\\frac{b N^C_p m^C}{2\\Delta X \\Delta Y} \\[  \\(\\frac{S_{3\\beta}^{C}}{\\sum_\\gamma S_{3\\gamma}^{C}} + \\frac{ S_{4\\beta}^{C}}{\\sum_\\gamma S_{4\\gamma}^{C}}\\) - a  \\frac{\\Delta t}{2\\Delta Y}\\(\\frac{S_{1\\beta}^{C}}{\\sum_\\gamma S_{1\\gamma}^{C}} + \\frac{S_{4\\beta}^{C}}{\\sum_\\gamma S_{4\\gamma}^{C}}-\\frac{S_{2\\beta}^{L}}{\\sum_\\gamma S_{2\\gamma}^{L}} - \\frac{S_{3\\beta}^{L}}{\\sum_\\gamma S_{3\\gamma}^{L}}\\) \\]\\\\\n  & f^{(4)} = \\sum_{\\beta=1}^{N_p}\\bar{Q}_\\beta^n\\frac{a N^C_p m^C }{2\\Delta X \\Delta Y}  \\[  \\(\\frac{S_{3\\beta}^{L}}{\\sum_\\gamma S_{3\\gamma}^{L}} + \\frac{ S_{4\\beta}^{L}}{\\sum_\\gamma S_{4\\gamma}^{L}}\\) - b \\frac{\\Delta t}{2\\Delta X}\\(\\frac{S_{1\\beta}^{L}}{\\sum_\\gamma S_{1\\gamma}^{L}} + \\frac{S_{2\\beta}^{L}}{\\sum_\\gamma S_{2\\gamma}^{L}}-\\frac{S_{3\\beta}^{BL}}{\\sum_\\gamma S_{3\\gamma}^{BL}} - \\frac{S_{4\\beta}^{BL}}{\\sum_\\gamma S_{4\\gamma}^{L}}\\)\\]\n\\end{align}\nwritten for simplicity:\n\\begin{equation}\n  \\label{eq:interface_flux_mapped}\n  f^{(i)}=\\sum^{N_p}_\\beta \\bar{Q}_\\beta^n \\frac{c_n N^C_p m^C}{2\\Delta X \\Delta Y}\\[ \\phi_\\beta^{(i)} + \\phi_\\beta^{(i),T} \\]\n\\end{equation}\nIn the last expression, $\\phi^{(i)}$ is devoted to normal contributions while $\\phi^{(i),T}$ stands for transverse corrections at interface $(i)$. Numerical fluxes considered above are based on normal vectors oriented in the direction of the stream (see figure \\ref{fig:2Dmesh}). Nodal interface fluxes on the other hand, as defined in the semi-discrete system:\n%Fluxes contribute to nodes through the boundary integrals of the discrete form:\n\\begin{equation}\n  \\hat{f}_i^{*} = \\int_{\\Gamma} S_i(\\vect{X}) f^*_N  \\: d\\Gamma\n\\end{equation}\nare based on the outgoing flux to an element so that $f^{(1)}$ and $f^{(4)}$ must be counted negatively. The integral for cell $C$ is then:\n\\begin{equation}\n  \\hat{f}_i^{*} =  -\\int_{X^C_1}^{X_2^C} S_i(X,Y^C_{1}) f^{(1)}  dX + \\int_{Y^C_2}^{Y_3^C} S_i(X^C_{2},Y) f^{(2)}  dY +\\int_{X^C_2}^{X_3^C} S_i(X,Y^C_{3}) f^{(3)}  dX -\\int_{Y^C_1}^{Y_4^C} S_i(X^C_{1},Y) f^{(4)}  dY \n\\end{equation}\nwhich can be computed analytically using parent coordinates \\eqref{eq:parentCoordinates}:\n\\begin{subequations}\n  \\begin{alignat}{4}\n    &\\hat{f}_1^{*} = -&\\frac{1}{2}\\[\\Delta X f^{(1)} + \\Delta Y f^{(4)}\\] \\quad;\\quad &\\hat{f}_2^{*} = -&\\frac{1}{2}\\[\\Delta X f^{(1)} - \\Delta Y f^{(2)}\\]\\\\\n    &\\hat{f}_3^{*} =  &\\frac{1}{2}\\[\\Delta X f^{(3)} + \\Delta Y f^{(2)}\\] \\quad;\\quad &\\hat{f}_4^{*} = &\\frac{1}{2}\\[\\Delta X f^{(3)} - \\Delta Y f^{(4)}\\]\n  \\end{alignat}\n\\end{subequations}\nA condensed way of writing those fluxes is adopted by means of the middle point of edge $(j)$ with coordinates $\\vect{X}^{(j)}_{1/2}$, at which the shape functions are:\n\\begin{equation*}\n  S_i(\\vect{X}^{(j)}_{1/2}) =\n  \\left\\lbrace\n  \\begin{aligned}\n    & \\frac{1}{2} \\quad \\text{if node i belongs to edge (j)} \\\\\n    & 0 \\quad \\text{otherwise.}\n  \\end{aligned}\n  \\right.\n\\end{equation*}\nIn addition, components of the outward normal vector to edges $N^{(i)}_X$ and $N^{(i)}_Y$ allow taking into account different signs of intercell fluxes in the Cartesian grid. One thus writes:\n\\begin{equation}\n  \\hat{f}_i^{*}= \\frac{1}{2}\\sum_j^{\\text{edges}} 2S_{i}(\\vect{X}^{(j)}_{1/2})\\(\\Delta Y N^{(j)}_X + \\Delta X N^{(j)}_Y\\) f^{(j)}\n\\end{equation}\nwhich, combined with equation \\eqref{eq:interface_flux_mapped} leads to:\n\\begin{equation}\n  \\hat{f}_i^{*}= \\sum^{N_p}_\\beta \\bar{Q}_\\beta^n \\sum_j^{\\text{edges}} S_{i}(\\vect{X}^{(j)}_{1/2})\\(a\\Delta Y N^{(j)}_X + b\\Delta X N^{(j)}_Y\\)  \\frac{ N^C_p m^C}{2\\Delta X\\Delta Y}\\[ \\phi_\\beta^{(i)} + \\phi_\\beta^{(i),T} \\]\n\\end{equation}\nThese terms are divided by the lumped mass matrix in the discrete form:\n\\begin{equation}\n  \\label{eq:nodal_fluxes}\n  \\frac{\\hat{f}_i^{*}}{M_i^L}=\\sum_\\beta \\frac{\\bar{Q}_\\beta^n}{\\sum_\\mu S_{i\\mu}}   \\sum_{j=1}^{\\text{edges}}\\frac{1}{2} S_{i}(\\vect{X}^{(j)}_{1/2}) N^C_p m^C \\(\\frac{aN^{(j)}_X}{\\Delta X}  + \\frac{bN^{(j)}_Y}{\\Delta Y} \\) \\[\\phi_\\beta^{(j)} + \\phi_\\beta^{(j),T}\\] \n\\end{equation}\n\nAt last, gathering the mapping of updated nodal quantities to the particles \\eqref{eq:2D_updatedMP}, expressions of volume fluxes \\eqref{eq:2Dvolume_fluxes} and intercell fluxes \\eqref{eq:nodal_fluxes}, the updated value at material point $\\alpha$ contained in cell $C$ reads:\n\\begin{equation}\n  \\label{eq:2Dscheme_equation}\n  \\begin{split}\n    \\bar{Q}_\\alpha^{n+1}=  \\sum_{\\beta=1}^{N_p}\\bar{Q}_\\beta^n\\sum_{i=1}^{4E}\\frac{S_{i\\alpha}}{\\sum_\\mu S_{i\\mu}}  \\left\\lbrace \\vphantom{\\sum_{j=1}^{\\text{edges}} } \\right.& S_{i\\beta} +  2  \\sum_{j=1}^{4E} \\frac{ S_{j\\beta}}{\\sum_\\gamma S_{j\\gamma}}\\sum_{\\lambda=1}^{N_p}S_{j\\lambda}\\[ a\\frac{\\Delta t}{\\Delta X}\\partial_\\xi S_{i\\lambda}  + b\\frac{\\Delta t}{\\Delta Y} \\partial_\\eta S_{i\\lambda} \\] \\\\ - & \\frac{1}{2}\\left.\\sum_{k=1}^{\\text{edges}} S_{i}(\\vect{X}^{(k)}_{1/2}) N_p^C \\(a\\frac{\\Delta t}{\\Delta X}N^{(j)}_X  + b\\frac{\\Delta t}{\\Delta Y}N^{(j)}_Y \\)\\[\\phi_\\beta^{(k)} + \\phi_\\beta^{(k),T}\\] \\right\\rbrace\n  \\end{split}\n\\end{equation}\nRecall that transverse contributions $\\phi_\\beta^{(j),T}$ depend on $\\Delta t$, thus providing second-order corrections in the two-dimensional scheme equation \\eqref{eq:2Dscheme_equation}, that can also be rewritten as:\n\\begin{equation}\n  \\label{eq:2Dscheme_D_alphabeta}\n  \\bar{Q}_\\alpha^{n+1}= \\sum_{\\beta=1}^{N_p}\\bar{Q}_\\beta^n D_{\\alpha\\beta}\n\\end{equation}\n\n\\subsubsection*{The von Neumann linear stability analysis}\nAnalogously to the one-dimensional case, the solution at a material point can be expanded into a discrete Fourier basis over the domain $\\[-l,l\\]\\times\\[-h,h\\]$. We consider here a structured distribution of particles made of $N_p=N_p^X\\times N_p^Y$ material points so that one can denote the solution at particles by $\\bar{Q}_{\\alpha\\beta}$, where $\\alpha$ and $\\beta$ are the row and column of material point indices. For one arbitrary Fourier mode, one has \\cite[Ch.20]{Leveque}:\n\\begin{equation}\n\\bar{Q}^{n}_{\\alpha \\beta} = A_{jq}^n e^{i (\\alpha k_j + \\beta k_q)\\Delta X}\n\\end{equation}\nwhere $k_j$ and $k_q$ are wave numbers. Then, the amplification factor reads:\n\\begin{equation}\n\\frac{A_{jq}^{n+1}}{A_{jq}^n} =  \\sum_{\\gamma=1}^{N_p^X}\\sum_{\\mu=1}^{N_p^Y} e^{i ([\\alpha-\\gamma]k_j + [\\beta-\\mu]k_q)\\Delta X}D_{\\alpha\\beta,\\gamma\\mu}\n\\end{equation}\nwith $i=\\sqrt{-1}$. The requirement that the absolute value of the amplification factor is lower than or equal to one leads to the following stability condition:\n\\begin{equation}\n\\abs{\\frac{A_{jq}^{n+1}}{A_{jq}^n}} = \\abs{\\sum_{\\gamma=1}^{N_p^X}\\sum_{\\mu=1}^{N_p^Y} e^{i ([\\alpha-\\gamma]k_j + [\\beta-\\mu]k_q)\\Delta X}D_{\\alpha\\beta,\\gamma\\mu}} \\leq 1 \\Leftrightarrow  \\sum_{\\gamma=1}^{N_p^X}\\sum_{\\mu=1}^{N_p^Y} \\abs{D_{\\alpha\\beta,\\gamma\\mu}} \\leq 1\n\\end{equation}\nor more simply:\n\\begin{equation}\n\\label{eq:2D_stability}\n\\sum_{\\beta=1}^{N_p} \\abs{D_{\\alpha\\beta}} \\leq 1 \\quad \\forall \\alpha=1,...,N_p\n\\end{equation}\n\nAgain, the single particle-per-cell discretization leads to a piece-wise constant reconstruction of the field on the computational grid after the projection from material points to nodes, thus providing the first order upwind method. This method is known to be bounded by the stability requirements \\cite[Ch.20]{Leveque}:\n\\begin{subequations}\n  \\begin{alignat}{2}\n    \\label{eq:2DCFL_DCU}\n    & \\abs{a}\\frac{\\Delta t}{\\Delta X} + \\abs{b} \\frac{\\Delta t}{\\Delta Y} \\leq 1 \\qquad &\\text{for DCU} \\\\\n    \\label{eq:2DCFL_CTU}\n    & \\max \\( \\abs{a} \\frac{\\Delta t}{\\Delta X}  , \\abs{b} \\frac{\\Delta t}{\\Delta Y}\\) \\leq 1 \\qquad &\\text{for CTU}\n  \\end{alignat}\n\\end{subequations}\n\nConfigurations involving more particles in the computational grid cells are then studied numerically by assuming the same material points distribution in every element.\nFurthermore, we consider only regular cells $\\Delta Y = \\Delta X$ and wave speeds satisfying $a\\geq b >0$, so that Courant the number is $a\\Delta t/\\Delta X$.\n%Coefficients $D_{\\alpha \\mu}$ depending on both horizontal and vertical wave speeds, the scheme equation \\eqref{eq:2Dscheme_D_alphabeta} can be written as a function of the CFL number by means of the speed ratio  $a/b$.\nThe scheme equation \\eqref{eq:2Dscheme_D_alphabeta} can then be written as a function of the CFL number by means of the speed ratio  $a/b$.\nHence, the maximal Courant number satisfying the stability condition \\eqref{eq:2D_stability} also depends on the speed ratio.\nEvolutions of the CFL numbers corresponding to several distributions of particles in a two-dimensional grid are gathered in tables \\ref{tab:2DCFL_comparison_2ppc} and \\ref{tab:2DCFL_comparison_4ppc} for the DGMPM scheme using DCU and CTU methods.\nThe first column of these tables shows the positions of material points inside cells for discretizations based on $2$ or $4$ particles per element. \n\n%% 2ppc\nThe space discretization leading to $2$ particles lying in every cell of the mesh is such that within an element, the two material points are both either on the horizontal axis or on the vertical axis of the cell, corresponding respectively to the results reported in the first and second rows of table \\ref{tab:2DCFL_comparison_2ppc}.\nTwo situations are then to be distinguished:\n\\begin{itemize}\n\\item Material points are regularly-spaced within the grid and placed symmetrically two-by-two with respect to cell centers.\n  These distributions are drawn in the first column of table \\ref{tab:2DCFL_comparison_2ppc} by using blue circles to represent particles.\n\\item Material points still satisfy symmetry in cells, but are no longer regularly-spaced in the mesh. In that case, particles are drawn with red crosses.\n\\end{itemize}\n\\begin{table}[h]\n  \\centering\n  \\input{chapter3/tabular/2DCFL_comparison_2ppc}\n  \\caption{Values of critical Courant number $a\\frac{\\Delta t}{\\Delta X}$ for two-dimensional DGMPM scheme using either DCU or CTU with respect to the locations of the $2$ material points lying in every cell as a function of the speed ratio $a/b$.}\n  \\label{tab:2DCFL_comparison_2ppc}\n\\end{table}\nFirst, the results of table \\ref{tab:2DCFL_comparison_2ppc} show that the CFL number exhibits a non-linear dependence on the speed ratio $a/b$ that asymptotically approaches some value which depends on the particle distribution.\nSecond, we see that a reduction of spacing between particles conserving the symmetry between them with respect to cell centers, as for the one-dimensional case, yields an increase in the critical Courant number for both the DCU and CTU approaches. \nThird, whether particles lie on the horizontal axis or the vertical axis of cells has a great influence on the critical Courant number one can expect.\nHence, the configurations of the second row of table \\ref{tab:2DCFL_comparison_2ppc} yield higher CFL numbers for given speed ratios.\nIt then appears that in order to improve the stability of the scheme, one must use a lower number of material points in the direction of the dominating wave speed than in the perpendicular one. For a Cartesian distribution of particles $N_p^X \\times N_p^Y$ this corresponds to $N_p^Y > N_p^X$ if $a>b$, and $N_p^X > N_p^Y$ if $b>a$.\nAt last, it is worth noticing that the improvement brought by the CTU is much less significant than in the case of one single particle-per-cell discretization for which the Courant number can be set to one according to equations \\eqref{eq:2DCFL_DCU} and \\eqref{eq:2DCFL_CTU}.\n\n%% 4ppc\nWe now move on to cases for which grid cells each contain $4$ material points, by considering a square shaped distribution of particles in every element whose centers coincide with cell centroids.\nThis pattern can be contracted or simply translated without change of shape as depicted in the first column of table \\ref{tab:2DCFL_comparison_4ppc}.\nTwo configurations are gathered in each row of the table and are distinguished by using either blue circles or red crosses for material points.\nAgain, we observe that the increase in CFL number enabled by the use of the CTU approach is less important than in the case of one particle-per-cell.\nNext, as for the one-dimensional cases and configurations studied in table \\ref{tab:2DCFL_comparison_2ppc}, we see that the closer particles are from cell centers, the higher the CFL number.\nFinally, it can be seen from the two last rows of table \\ref{tab:2DCFL_comparison_4ppc} that the translation of the square of particles inside elements does not have great influence on the evolution of the Courant number with respect to the speed ratio. \n\\begin{table}[h!]\n  \\centering\n  \\input{chapter3/tabular/2DCFL_comparison_4ppc}\n  \\caption{Values of critical Courant number $a\\frac{\\Delta t}{\\Delta X}$ for two-dimensional DGMPM scheme using either DCU or CTU with respect to the material points distribution as a function of the speed ratio $a/b$.}\n  \\label{tab:2DCFL_comparison_4ppc}\n\\end{table}\n\n\n%Before concluding this chapter, some differences between the stability properties of DGMPM and MPM schemes are emphasized. First, the one and two-dimensional scheme equations written for the DGMPM enable, through the linear von Neumann stability analysis, the computation of \n%The von Neumann linear stability analysis performed in this section provides an explicit (nonlinear) condition \\eqref{eq:stability} that must be satisfied in order to ensure the stability of DGMPM schemes. First, this relation allows to fully exploit the ability of the method to rebuild the grid mesh arbitrarily. Indeed, after such a procedure, the number and positions of material points in grid cells can change and one must be able to adapt properly the CFL number so that the scheme remains stable. An advantage on the original MPM is hence highlighted since no stability condition exists for the method. Second, it has been shown that some DGMPM discretizations provide an improvement of the restrictive CFL number that applies to the DGFEM scheme. In particular, the optimal condition allowing to capture discontinuities ($CFL=1$) can be achieved for several space-time discretizations. This property turns out to be a strength for the DGMPM since it aims at follow waves accurately.\n\n%One can imagine to place material points so that an optimal stability condition is reached by minimizing some functional constrained with the description of material boundaries.\n\n%%% Local Variables: \n%%% mode: latex\n%%% ispell-local-dictionary: \"american\"\n%%% TeX-master: \"../mainManuscript\"\n%%% End:\n", "meta": {"hexsha": "56aeec5b4473851bba30e86d291a18423815f2ac", "size": 67788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/chapter3/numerical_analysis.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/chapter3/numerical_analysis.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/chapter3/numerical_analysis.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": 107.0900473934, "max_line_length": 1028, "alphanum_fraction": 0.7059509058, "num_tokens": 22749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6089085205427427}}
{"text": "%!TEX root = ../main.tex\n\\section{Introduction}\\label{section:introduction}\n\nThe Barab\\'asi-Albert (BA) model is a model for generating scale-free networks with a preferential attachment mechanism \\citep{Barabasi1999}. It has been extensively studied in many fields for its resemblance to real-world networks such as the internet and citation networks. The fat tail is a central characteristic in the model. Every new vertex attaches itself to existing vertices with a probability proportional to its degree, so that vertices with a higher degree are more likely to further increase its degree count, leading to a scale free degree distribution. \n\nThere are two key parts to this model: growth and preferential attachment. The random attachment model is a limiting case of the BA model where it retains growth but does not include preferential attachment. Here we show that the resulting degree distribution in this limit is no longer scale-free but geometric. \n\nRecent works \\citep{Saramaki2004,Cannings2013,J.P.Saramaki2004} have also investigated if preferential attachment can be reproduced without a global knowledge of the entire network, by performing a random walk on th graph. In this project we briefly look at the of such a model and whether it reproduces the power law for preferential attachment. ", "meta": {"hexsha": "cbec59ab0d6e93a3d8adb8e062e9ab84d4f818a1", "size": 1310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/introduction.tex", "max_stars_repo_name": "lingxz/networks", "max_stars_repo_head_hexsha": "c8c38927271ccb6ed31916b0b92eeab4095e3490", "max_stars_repo_licenses": ["MIT"], "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/introduction.tex", "max_issues_repo_name": "lingxz/networks", "max_issues_repo_head_hexsha": "c8c38927271ccb6ed31916b0b92eeab4095e3490", "max_issues_repo_licenses": ["MIT"], "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/introduction.tex", "max_forks_repo_name": "lingxz/networks", "max_forks_repo_head_hexsha": "c8c38927271ccb6ed31916b0b92eeab4095e3490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 163.75, "max_line_length": 569, "alphanum_fraction": 0.8152671756, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673359709795, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6089085182279212}}
{"text": "\\documentclass{memoir}\n\\usepackage{linalg}\n\n% \\begin{figure}[ht]\n%     \\centering\n%     \\incfig{riemmans-theorem}\n%     \\caption{Riemmans theorem}\n%     \\label{fig:riemmans-theorem}\n% \\end{figure}\n\n\\begin{document}\n\\section{Matrix Multiplication}\t\n\\begin{defn}\n\tSuppose $A$ is an $m\\times n$ matrix and $C$ is an $n\\times p$ matrix. Then $AC$ is defined to be the $m\\times p$ matrix whose entries are defined as follows:\n\t\\begin{align*}\n\t\t(AC)_{jk} = \\sum_{r=1}^{n} A_{jr}C_{rk}.\n\t\\end{align*}\n\\end{defn}\t\nMatrix multiplication is not commutative.\n\n\\begin{cor}\n\tIf $T \\in \\mathcal{L}(U,V)$ and $S \\in \\mathcal{L}(V,W)$, then $\\mathcal{M}(ST) = \\mathcal{M}(S)\\mathcal{M}(T)$\n\\end{cor}\nWe denote $A_{j,\\cdot}$ to be the $1\\times n$ matrix consisting of row $j$ of $A$. Likewise, $A_{\\cdot ,k}$ denotes the $m\\times 1$ matrix consisting of column $k$ of $A$.\n\\begin{cor}\n\tSuppose $A$ is an $m\\times n$ matrix and $C$ is an $n\\times p$ matrix. Then\n\t\\begin{align*}\n\t\t(AC)_{jk} = A_{j\\cdot }C_{\\cdot k}\n\t\\end{align*}\n\\end{cor}\n\\begin{cor}\n\tSuppose $A$ is $m\\times n$ matrix and $C$ is $n\\times p$ matrix. Then\n\t\\begin{align*}\n\t\t(AC)_{k} = AC_{k}\n\t\\end{align*}\n\\end{cor}\n\\begin{cor}\n\tSuppose $A$ is $m\\times n$ matrix and $c = \\begin{bmatrix} c_1 \\\\ \\vdots \\\\ c_n \\end{bmatrix} $ is an $n\\times 1$ matrix. Then\n\t\\begin{align*}\n\t\tAc = c_1A_{~1} + \\ldots + c_nA_{~n}.\n\t\\end{align*}\n\\end{cor}\n\n\\section{Invertibility and Isomorphic Vector Spaces}\n\\label{cha:invertibility_and_isomorphic_vector_spaces}\n\n\\subsection{Invertible Linear Maps}\n\\label{sec:invertible_linear_maps}\n\n\\begin{defn}\n\tA linear map $T \\in \\mathcal{L}(V,W)$ is called \\textbf{invertible} if there exists a linear map $S \\in \\mathcal{L}(W,V)$ such that $ST$ equals the identity map on $V$ and $TS$ equals the identity map on $W$. \\\\\n\n\tA linear map that $S$ that satisfies this is called an \\textbf{inverse} of $T$. we denote the inverse by $T^{-1}$.\n\\end{defn}\n\\begin{lemma}\n\tAn invertible linear map has a unique inverse.\n\\end{lemma}\n\\begin{thm}\n\tA linear map is invertible if and only if it is injective and surjective.\n\\end{thm}\n\nWe will not show it here, but one can see that the inverse of a linear map corresponds to the matrix inverse.\n\\subsection{Isomorphic Vector Spaces}\n\\label{sec:isomorphic_vector_spaces}\n\n\\begin{defn}[Isomorphism and Isomorphic]\n\tAn \\textbf{isomorphism between vector spaces} is an invertible linear map. Two vector spaces are called \\textbf{isomorphic} if there is an isomorphism from one vector space onto the other one.\n\\end{defn}\n\\begin{lemma}[Equal dimension implies isomorphic]\n\tTwo finite-dimensional vector spaces over $F$ are isomorphic if and only if they have the same dimension.\n\\end{lemma}\n\\begin{cor}\n\tSuppose $v_1,\\ldots,v_n$ is a basis of $V$ and $w_1,\\ldots,w_m$ is a basis of $W$. Then $\\mathcal{M}$ is an isomorphism between $\\mathcal{L}(V,W)$ and $F^{m,n}$.\n\\end{cor}\n\\begin{cor}[Dimension of Space of Linear Maps]\n\tSuppose $V$ and $W$ are finite-dimensional. Then $\\mathcal{L}(V,W)$ is finite-dimensional and\n\t\\begin{align*}\n\t\t\\textrm{dim}\\mathcal{L}(V,W) = ( \\textrm{dim}V) ( \\textrm{dim}W)\t\n\t\\end{align*}\n\\end{cor}\n\\subsection{Linear Maps Thought of as Matrix Multiplication}\n\\label{sec:linear_maps_thought_of_as_matrix_multiplication}\n\n\\begin{defn}[Matrix of a vector]\n\tSuppose $v \\in V$ and $v_1,\\ldots,v_n$ is a basis of $V$. The \\textbf{matrix of $v$} with respect to this basis is the $n\\times 1$ matrix\n\t\\begin{align*}\n\t\t\\mathcal{M}(v) = \\begin{bmatrix} c_1 \\\\ \\vdots \\\\ c_n \\end{bmatrix} ,\n\t\\end{align*}\n\twhere $c_1,\\ldots,c_n$ are the scalars such that\n\t\\begin{align*}\n\t\tv = c_1v_1 + \\ldots + c_nv_n .\n\t\\end{align*}\n\\end{defn}\n\\begin{cor}\n\tSuppose $T \\in \\mathcal{L}(V,W)$ and $v_1,\\ldots,v_n$ is a basis of $V$, $w_1,\\ldots,w_m$ a basis of $W$. Then the $ k$-th column of $\\mathcal{M}(T)$ equals $\\mathcal{M}(v_k)$.\n\\end{cor}\n\n\\begin{lemma}[Linear maps act like matrix multiplication]\n\tSuppose $T \\in \\mathcal{L}(V,W)$ and $v \\in V$. Suppose $v,w$ are bases of $W$. Then\n\t\\begin{align*}\n\t\t\\mathcal{M}(Tv) = \\mathcal{M}(T) \\mathcal{M}(v) .\n\t\\end{align*}\n\\end{lemma}\n\\subsection{Operators}\n\\label{sec:operators}\n\n\\begin{defn}[Operators]\n\tA linear map from a vector space to itself is called an \\textbf{operator} or \\textbf{endomorphism}. We notate $\\mathcal{L}(V)$ as the set of all operators on $V$.\t\n\\end{defn}\n\\begin{thm}[Injectivity is equivalent to surjectivity in finite dimensions]\n\tSuppose $V$ is finite-dimensional and $T \\in \\mathcal{L}(V)$. Then the following are equivalent:\n\t\\begin{itemize}\n\t\t\\item $T$ is invertible\n\t\t\\item $T$ is injective\n\t\t\\item $T$ is surjective\n\t\\end{itemize}\n\\end{thm}\n\\end{document}\n", "meta": {"hexsha": "c7b0570cd14a3d21ae3bf3fb71a0556095737f91", "size": 4641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear Algebra/Notes/source/10-04-19.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/10-04-19.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/10-04-19.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": 39.0, "max_line_length": 212, "alphanum_fraction": 0.6929541047, "num_tokens": 1659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6089085160658118}}
{"text": "\n\\section{Horodeckis criterion in $C^*$-algebras}\nIn this section, we are going to present the result\nanalogous to the Theorem \\ref{thm:main}, but this time in the C*-algebra setting.\nIt is expected that the previous assumption of injectivity\nwill have to be retained somehow. That leads to the choice of \\emph{nuclear} C*-algebras,\ni.e. algebras whose universal enveloping von Neumann algebras (the second dual spaces) are\ninjective. Not only it allows us to define a tensor product of two C*-algebras\nuniquely, but also facilitates the usage of the previous result.\nNuclear C*-algebras, among others, share also the property of\nlocal reflexivity, which will prove itself indispensable for\nour line of reasoning.\n\nLet $\\mathcal{A}$ and $\\mathcal{B}$ be C*-algebras.\nBy $\\mathcal{A} \\otimes_{max} \\mathcal{B}$\nand $\\mathcal{A} \\otimes_{min} \\mathcal{B}$,\nwe denote respectively the \\emph{maximal} and \\emph{minimal}\nC*-tensor product of $\\mathcal{A}$ and $\\mathcal{B}$.\nIt is known that if at least one of the algebras, say $\\mathcal{A}$,\nis nuclear, then those two tensor norms coincide and\nthe tensor product C*-algebra is in fact uniquely defined.\nFor a nuclear C*-algebra $\\mathcal{A}$, we denote that tensor product\nby $\\mathcal{A} \\bar{\\otimes} \\mathcal{B}$.\nA C*-algebra $\\mathcal{A}$ is by definition \\emph{locally reflexive},\nif for every finite-dimensional operator system $E \\subset \\mathcal{A}^{**}$,\ni.e. a closed self-adjoint subspace containing the identity element,\nthere is a net $(T_{\\lambda})$ of completely positive contractions,\n$T_{\\lambda}: E \\rightarrow \\mathcal{A}$,\nwhich converges to the identity map on $E$ in the weak operator\ntopology. Every nuclear C*-algebra is locally reflexive\n(see Brown and Ozawa\\cite{Brown2008}, 9.3.1-9.3.3).\nThe algebras $\\mathcal{A}$ and $\\mathcal{B}$\ncan be treated as operator spaces in a natural way.\nThus, it is possible to introduce the operator space projective\ntensor norm on the dual operator spaces $\\mathcal{A}^{*}$\nand $\\mathcal{B}^{*}$, and the completion of the algebraic tensor product with\nrespect to that norm will be denoted by\n$\\mathcal{A}^{*} \\hat{\\otimes} \\mathcal{B}^{*}$. Hence, we can introduce a cone of\nseparable states with respect to $\\mathcal{A}$ and $\\mathcal{B}$ in the same way as\nin Section 2. Let  $\\mathcal{S}(\\mathcal{A})$ and $\\mathcal{S}(\\mathcal{B})$\ndenote the state spaces of $\\mathcal{A}$ and $\\mathcal{B}$, respectively.\nWe define a positive cone $C_{\\mathcal{A},\\mathcal{B}}$\nof separable states with respect to $\\mathcal{A}$ and $\\mathcal{B}$ by\n\\begin{equation}\nC_{\\mathcal{A},\\mathcal{B}} =\n\\overline{{\\rm conv}}^{||\\cdot||_{\\wedge}}\n\\left \\{\\omega \\otimes \\varphi: \\, \\,\\omega \\in \\mathcal{S}(\\mathcal{A}),\n\\varphi \\in \\mathcal{S}(\\mathcal{B})\\right \\}.\n\\end{equation}\nIt is clear that a state on $\\mathcal{A} \\bar{\\otimes} \\mathcal{B}$ is separable,\ni.e. $\\tilde{\\phi} \\in C_{\\mathcal{A}, \\mathcal{B}}$,\nif and only if $\\tilde{\\phi}$ is a separable state\non the von Neumann algebra $\\mathcal{A}^{**} \\bar{\\otimes} \\mathcal{B}^{**}$.\n\\begin{theorem}\nLet $\\mathcal{A}$ and $\\mathcal{B}$ be C*-algebras and suppose that\n$\\mathcal{A}$ is nuclear. A state $\\tilde{\\phi} \\in\n(\\mathcal{A} \\bar{\\otimes} \\mathcal{B})^{*}$ is separable\nwith respect to $\\mathcal{A}$ and $\\mathcal{B}$,\nif and only if the functional $\\tilde{\\phi} \\circ ( \\mathbf{1} \\otimes S )$\nis positive for any positive and finite rank map $S: \\mathcal{A} \\rightarrow \\mathcal{B}$.\n\\end{theorem}\n{\\bf Proof.} Let $\\mathfrak{M}=\\mathcal{A}^{**}$ and $\\mathfrak{N}=\\mathcal{B}^{**}$.\nBy the assumption, $\\mathfrak{M}$ is injective. If $\\tilde{\\phi}$ is separable with respect to\n$\\mathcal{A}$ and $\\mathcal{B}$, then it is also separable on\n$\\mathfrak{M} \\bar{\\otimes} \\mathfrak{N}$. For any positive map\n$S: \\mathcal{A} \\rightarrow \\mathcal{B}$, the second dual map\n$S^{**}:\\mathfrak{M} \\rightarrow \\mathfrak{N}$ is positive and normal.\nIt follows from the first part of Theorem \\ref{thm:main} that for any positive\n$z \\in \\mathfrak{M} \\bar{\\otimes} \\mathfrak{M}$,\n$\\langle (\\mathbf{1} \\otimes S^{**})(z), \\tilde{\\phi} \\rangle \\geq 0$.\nTherefore, $\\tilde{\\phi} \\circ (\\mathbf{1} \\otimes S)$ is a\npositive functional on $\\mathcal{A} \\bar{\\otimes} \\mathcal{A}$.\n\nConversely, suppose that $\\tilde{\\phi} \\circ (\\mathbf{1} \\otimes S) \\geq 0$\nfor any positive and finite rank map $S: \\mathcal{A} \\rightarrow \\mathcal{B}$.\nWe are going to show that the state $\\tilde{\\phi}$\nis separable on $\\mathfrak{M} \\bar{\\otimes} \\mathfrak{N}$.\nSuppose on the contrary that $\\tilde{\\phi}$ is not separable on\n$\\mathfrak{M} \\bar{\\otimes} \\mathfrak{N}$.\nBy Theorem \\ref{thm:main}, there is a positive normal and finite rank\nmap $\\tilde{S}: \\mathfrak{M} \\rightarrow \\mathfrak{N}$\nand a positive element $z \\in \\mathfrak{M} \\bar{\\otimes} \\mathfrak{M}$,\nsuch that\n\\begin{equation}\n\\label{eq:Random6347}\n\\langle(\\mathbf{1} \\otimes \\tilde{S})(z), \\tilde{\\phi}\\rangle < 0.\n\\end{equation}\nMoreover, we can choose the element $z$ from the algebraic tensor product\n$\\mathfrak{M} \\otimes \\mathfrak{M}$, i.e. $z = \\sum_{j=1}^{N} x_{j} \\otimes y_{j}$,\neach $x_{j}$ and $y_{j} \\in \\mathfrak{M}$. Let $E \\subset \\mathfrak{M}$ be an\noperator system generated by $\\{ x_{j}, y_{j}\\}_{j=1}^{N}$.\nSince $\\mathcal{A}$ is locally reflexive, there exists\na net $(T_{\\lambda})$ of completely positive contractions\n$T_{\\lambda}: E \\rightarrow \\mathcal{A}$,\nsuch that $T_{\\lambda}$ converges to the identity map\non $E$ in the weak* operator topology, i.e.\nfor any $\\omega \\in \\mathcal{A}^{*}$ and $x \\in E$,\n$ \\langle \\omega, T_{\\lambda}x \\rangle\\stackrel{\\lambda}{\\rightarrow}\n\\langle x, \\omega \\rangle$. Let $a_{\\lambda}$ denote the positive element\nof $\\mathcal{A} \\otimes \\mathcal{A}$,\n$a_{\\lambda} = (T_{\\lambda} \\otimes T_{\\lambda}) (z) =\n\\sum_{j=1}^{N} T_{\\lambda} x_{j} \\otimes T_{\\lambda} y_{j}$, and let\n$i: \\mathcal{A} \\rightarrow \\mathcal{A}^{**}=\\mathfrak{M}$\nbe the canonical embedding. Then,\n$i(a_{\\lambda}) \\stackrel{\\lambda}{\\rightarrow} z$ $\\sigma$-weakly.\nSince $\\mathcal{B}$ is a Banach space, it has a local\nreflexivity property in the following sense (see Ryan\\cite{Ryan2002}, chapter 5.5).\nFor any finite-dimensional subspace $F \\subset \\mathcal{B}^{**}$,\nthere is an operator $P_{F}: F \\rightarrow \\mathcal{B}$\nsuch that for any $y \\in \\mathcal{B}^{**} = \\mathfrak{N}$\nand $\\varphi \\in \\mathcal{B}^{*}$, one has\n\\begin{equation}\n\\label{eq:Random24093}\n\\langle \\varphi, P_{F}y \\rangle =\\langle y, \\varphi \\rangle.\n\\end{equation}\nLet $F = \\tilde{S}(\\mathfrak{M})$.\nIt is obvious from equation \\eqref{eq:Random24093} that $P_{F}$ is positive.\nWe define a positive map $S: \\mathcal{A} \\rightarrow \\mathcal{B}$ by\n$S = P_{F} \\circ \\tilde{S} \\circ i$. Then,\nfor any $A \\in \\mathcal{A}$ and $\\varphi \\in \\mathcal{B}^{*}$, we have\n\\begin{eqnarray}\n\\langle \\varphi, SA \\rangle =\n\\langle \\varphi, P_{F} ( \\tilde{S} \\circ i (A)) \\rangle =\n\\langle  \\tilde{S} \\circ i (A), \\varphi \\rangle \\nonumber\\\\\n=\\langle i(A), \\tilde{S}_{*} \\varphi \\rangle =\n\\langle \\tilde{S}_{*} \\varphi, A \\rangle,\n\\end{eqnarray}\nSuppose now that\n$\\tilde{\\phi} = \\lim \\limits_{n} \\sum_{i=1}^{n}\\omega_{i} \\otimes \\varphi_{i}$,\nwhere each $\\omega_{i} \\in \\mathcal{A}^{*}$,\n$\\varphi_{i} \\in \\mathcal{B}^{*}$.\nThe limit is understood as the one in the projective\noperator norm $|| \\cdot ||_{\\wedge}$, and hence also in the weak and weak* topology on\n$(\\mathcal{A} \\bar{\\otimes} \\mathcal{B})^{*}$. Then, by the assumption,\n$\\langle \\tilde{\\phi},(\\mathbf{1} \\otimes S) (a_{\\lambda}) \\rangle \\geq 0$. Moreover,\n\\begin{eqnarray}\n\\sum \\limits_{i=1}^{n}\\langle \\omega_{i} \\otimes \\varphi_{i},\n(\\mathbf{1} \\otimes S)(a_{\\lambda}) \\rangle =\n\\sum \\limits_{i=1}^{n} \\sum \\limits_{j=1}^{N}\n\\langle \\omega_{i} , T_{\\lambda} x_{j} \\rangle\n\\langle \\tilde{S}_{*} \\varphi_{i}, T_{\\lambda} y_{j}\\rangle \\nonumber\\\\\n\\stackrel{\\lambda}{\\longrightarrow}\\sum \\limits_{i=1}^{n} \\sum \\limits_{j=1}^{N}\n\\langle  x_{j}, \\omega_{i} \\rangle\\langle  y_{j},  \\tilde{S}_{*} \\varphi_{i} \\rangle =\n\\langle (\\mathbf{1} \\otimes \\tilde{S})(z),\n\\sum \\limits_{i=1}^{n} \\omega_{i} \\otimes \\varphi_{i} \\rangle .    \n\\end{eqnarray}\nTaking the limit with respect to $n$,\nsince $(T_{\\lambda})$ is a net of contractions, we get that\n$\\langle (\\mathbf{1} \\otimes \\tilde{S}) (z) ,\n\\tilde{\\phi}\\rangle \\geq 0$, which contradicts \\eqref{eq:Random6347},\nand so $\\tilde{\\phi}$ is separable on\n$\\mathfrak{M} \\bar{\\otimes} \\mathfrak{N}$. $\\Box$ \\\\\nThat essentially generalizes the result of St{\\o}rmer's, who proved a similar theorem under\nadditional conditions. Namely, he used all positive linear maps and assumed that $\\mathcal{B}$\nwas an UHF algebra \\cite{Stormer2009}.\n\n", "meta": {"hexsha": "bab7768fc1557ef6439f11f0cd3433441b3e5d5f", "size": 8626, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chp/Hor_eng.tex", "max_stars_repo_name": "gitmarek/phdthesis", "max_stars_repo_head_hexsha": "ab58eda980448ec2f577e77b555b19be42b59756", "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": "chp/Hor_eng.tex", "max_issues_repo_name": "gitmarek/phdthesis", "max_issues_repo_head_hexsha": "ab58eda980448ec2f577e77b555b19be42b59756", "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": "chp/Hor_eng.tex", "max_forks_repo_name": "gitmarek/phdthesis", "max_forks_repo_head_hexsha": "ab58eda980448ec2f577e77b555b19be42b59756", "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": 54.9426751592, "max_line_length": 94, "alphanum_fraction": 0.6874565268, "num_tokens": 3078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6089085137509912}}
{"text": "\\documentclass[utf8x,hyperref={pdfpagelabels=false}]{beamer}\n\n\\usepackage[utf8x]{inputenc}\n\\usepackage[OT1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{xcolor}\n\\usepackage{amsmath}\n\n\\usetheme{Malmoe}  % Now it's a beamer presentation with the lisa theme!        \n\\usecolortheme{beaver}\n\\setbeamertemplate{footline}[page number]\n\\setbeamertemplate{navigation symbols}{}\n\n\\title{Convolutions for neural networks}\n\n\\author{%\nArnaud Bergeron\n}\n\\date{August 10, 2015}\n\n\\definecolor{termblue}{RGB}{51, 51, 179}\n\\newcommand{\\term}[1]{\\textcolor{termblue}{#1}}\n\n\\begin{document}\n\n\\begin{frame}[plain]\n \\titlepage\n\\end{frame}\n\n\\setcounter{page}{1}\n\n\\section{Convolution}\n\n% Basic operation\n\\begin{frame}\nThe basic convolution operation\n\\begin{overlayarea}{\\textwidth}{5.6cm}\n\\only<1>{\n\\includegraphics[width=\\textwidth]{Conv-single}\n}\n\\only<2->{\n\\begin{displaymath}\nC(i, j) = \\sum^{x = 0}_{m-1} \\sum^{y = 0}_{n-1} A(x + i, y + j) F(x, y)\n\\end{displaymath}\n\\begin{itemize}\n\\item $(m, n)$ is the size of the filter.\n\\end{itemize}\n}\n\\end{overlayarea}\nWhere $A$ is the input channel, $F$ is the filter and $C$ is the output channel.\n\\end{frame}\n\n\\begin{frame}\nThe basic convolution operation with multiple outputs\n\\begin{overlayarea}{\\textwidth}{5.6cm}\n\\only<1>{\n\\includegraphics[width=\\textwidth]{Conv-mout}\n}\n\\only<2->{\n\\begin{displaymath}\nC_{o}(i, j) = \\sum^{x = 0}_{m-1} \\sum^{y = 0}_{n-1} A(x + i, y + j) F_{o}(x, y)\n\\end{displaymath}\n\\begin{itemize}\n\\item $(m, n)$ is the size of the filters.\n\\item $o$ is the output channel.\n\\end{itemize}\n}\n\\end{overlayarea}\nwhere $A$ is the input channel, $F$ are the filters and $C$ are output channels.\n\\end{frame}\n\n\\begin{frame}\nThe basic convolution operation with multiple inputs\n\\begin{overlayarea}{\\textwidth}{5.6cm}\n\\only<1>{\n\\includegraphics[width=\\textwidth]{Conv-min}\n}\n\\only<2->{\n\\begin{displaymath}\nC(i, j) = \\sum^{k=0}_l \\sum^{x = 0}_{m-1} \\sum^{y = 0}_{n-1} A_{k}(x + i, y + j) F_{k}(x, y)\n\\end{displaymath}\n\\begin{itemize}\n\\item $(m, n)$ is the size of the filters.\n\\item $k$ is the input channel.\n\\item $l$ is the number of input channels.\n\\end{itemize}\n}\n\\end{overlayarea}\nwhere $A$ are the input channels, $F$ is the filter bank and $C$ is the output channel.\n\\end{frame}\n\n\\begin{frame}\nThe basic convolution operation with multiple inputs and outputs\n\\begin{overlayarea}{\\textwidth}{5.6cm}\n\\only<1>{\n\\includegraphics[width=\\textwidth]{Conv-basic}\n}\n\\only<2->{\n\\begin{displaymath}\nC_{o}(i, j) = \\sum^{k=0}_{l-1} \\sum^{x = 0}_{m-1} \\sum^{y = 0}_{n-1} A_{k}(x + i, y + j) F_{ko}(x, y)\n\\end{displaymath}\n\\begin{itemize}\n\\item $(m, n)$ is the size of the filters.\n\\item $o$ is the output channel.\n\\item $k$ is the input channel.\n\\item $l$ is the number of input channels.\n\\end{itemize}\n}\n\\end{overlayarea}\nwhere $A$ are the input channels, $F$ are the filter banks and $C$ are the output channels.\n\\end{frame}\n\n\\begin{frame}\nThe basic convolution operation with batches\n\\begin{overlayarea}{\\textwidth}{5.6cm}\n\\only<1>{\n\\includegraphics[width=\\textwidth]{Conv-basic}\n}\n\\only<2->{\n\\begin{displaymath}\nC_{bo}(i, j) = \\sum^{k=0}_{l-1} \\sum^{x = 0}_{m-1} \\sum^{y = 0}_{n-1} A_{bk}(x + i, y + j) F_{ko}(x, y)\n\\end{displaymath}\n\\begin{itemize}\n\\item $(m, n)$ is the size of the filters.\n\\item $o$ is the output channel.\n\\item $k$ is the input channel.\n\\item $l$ is the number of input channels.\n\\item $b$ is the batch.\n\\end{itemize}\n}\n\\end{overlayarea}\nwhere $A$ are the input channels, $F$ are the filter banks and $C$ are the output channels.\n\\end{frame}\n\n% Definitions\n\\begin{frame}\nSome vocabulary:\n\\begin{description}[filter banks]\n\\item[filter] what we call the smaller or \"learned\" 2D matrix in a traditional convolution.\n\\item[channel] what we call input or output 2D matrices in a traditional convolution.  Sometimes called \\term{feature map}.\n\\item[filter bank] group of filters whose convolution output will be summed to form one output channel.  Sometimes called \\term{filter stack}.\n\\end{description}\n\\end{frame}\n\n% Technical considerations\n\\begin{frame}\nMemory layout for images: 'bc01' (a.k.a 'nchw')\n\n\\begin{itemize}\n\\item first dimension is the batch ('b')\n\\item second dimension is the channel ('c')\n\\item last two dimensions are the data ('0', '1')\n\\end{itemize}\n\nMemory layout for filters: 'nc01' ('nchw')\n\n\\begin{itemize}\n\\item first dimension is the output channel ('n')\n\\item second dimension is the input channel ('c')\n\\item last two dimensions are the data ('0', '1')\n\\end{itemize}\n\n\\ \\\\\n\n\\uncover<2->{Some other packages may use different conventions.}\n\\end{frame}\n\n\\section{Pooling}\n\n\\begin{frame}\nBasic pooling operation\n\\includegraphics[width=\\textwidth]{Pool-max}\n\\end{frame}\n\n\\begin{frame}\nMax Pooling\n\\begin{displaymath}\nO_k(i, j) = \\max_{\\substack{0 \\leq x < m \\\\ 0 \\leq y < n}} I_k(x + i, y + j)\n\\end{displaymath}\nAverage Pooling\n\\begin{displaymath}\nO_k(i, j) = \\frac{1}{mn}\\sum^{x = 0}_{m - 1} \\sum^{y = 0}_{n - 1} I_k(x + i, y + j)\n\\end{displaymath}\n\\begin{itemize}\n\\item $k$ is the channel.\n\\item $(m, n)$ is the size of the filters.\n\\end{itemize}\n\\end{frame}\n\n\\end{document}\n", "meta": {"hexsha": "28e305c2a4a24d423a1d4512f1480f621575d184", "size": 5049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conv/conv.tex", "max_stars_repo_name": "aelnouby/summerschool2015", "max_stars_repo_head_hexsha": "c96da4af353fc1b0c1a7e3a08863c6de89072b19", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 437, "max_stars_repo_stars_event_min_datetime": "2015-07-16T22:14:15.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-02T23:47:59.000Z", "max_issues_repo_path": "conv/conv.tex", "max_issues_repo_name": "mila-iqia/summerschool2015", "max_issues_repo_head_hexsha": "c96da4af353fc1b0c1a7e3a08863c6de89072b19", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2015-07-03T00:39:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-27T07:56:40.000Z", "max_forks_repo_path": "conv/conv.tex", "max_forks_repo_name": "mila-udem/summerschool2015", "max_forks_repo_head_hexsha": "c96da4af353fc1b0c1a7e3a08863c6de89072b19", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 201, "max_forks_repo_forks_event_min_datetime": "2015-07-13T17:12:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-09T12:11:07.000Z", "avg_line_length": 26.4345549738, "max_line_length": 142, "alphanum_fraction": 0.6945929887, "num_tokens": 1711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6089085137509912}}
{"text": "\n%%% Template originaly created by Karol Kozioł (mail@karol-koziol.net) and modified for ShareLaTeX use\n\n\\documentclass[a4paper,11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\\usepackage{graphicx}\n\\usepackage[usenames,dvipsnames]{xcolor}\n\n\\usepackage{sansmath}\n\\renewcommand\\familydefault{\\sfdefault}\n\\usepackage{tgheros}\n\n\\usepackage{amsmath,amssymb,amsthm,textcomp}\n\\usepackage{enumerate}\n\\usepackage{multicol}\n\\usepackage{tikz}\n\\usetikzlibrary{graphs,automata,arrows,shapes.misc}\n\n\\usepackage{geometry}\n\\geometry{total={210mm,297mm},\nleft=25mm,right=25mm,%\nbindingoffset=0mm, top=20mm,bottom=20mm}\n\n\n\\linespread{1.3}\n\n\\newcommand{\\linia}{\\rule{\\linewidth}{0.5pt}}\n\n% custom theorems if needed\n\\newtheoremstyle{mytheor}\n    {1ex}{1ex}{\\normalfont}{0pt}{\\scshape}{.}{1ex}\n    {{\\thmname{#1 }}{\\thmnumber{#2}}{\\thmnote{ (#3)}}}\n\n\\theoremstyle{mytheor}\n\\newtheorem{defi}{Definition}\n\n% my own titles\n\\makeatletter\n\\renewcommand{\\maketitle}{\n\\begin{center}\n\\vspace{2ex}\n{\\huge \\textsc{\\@title}}\n\\vspace{1ex}\n\\\\\n\\linia\\\\\n\\@author \\hfill \\@date\n\\vspace{4ex}\n\\end{center}\n}\n\\makeatother\n%%%\n\n% custom footers and headers\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\lhead{}\n\\chead{}\n\\rhead{}\n\\lfoot{Automatic~Verification Assignment \\#5}\n\\cfoot{}\n\\rfoot{Page \\thepage}\n\\renewcommand{\\headrulewidth}{0pt}\n\\renewcommand{\\footrulewidth}{0pt}\n%\n\n% all section titles centered and bolded\n\\usepackage{sectsty}\n\\allsectionsfont{\\bfseries\\large}\n%\n% add section label\n\\renewcommand\\thesection{Problem~\\arabic{section}:}\n\\renewcommand\\thesubsection{(\\alph{subsection})}\n%\n\n%%%----------%%%----------%%%----------%%%----------%%%\n\n\\begin{document}\n\n\\title{Homework Assignment~\\#5}\n\n\\author{R02943142 Hsieh, Chiao}\n\n\\maketitle\n\n\\section{B\\\"uchi Automaton}\nDefine a B\\\"uchi automaton (by drawing its transition diagram) for each of the following temporal properties.\n\n\\subsection{$p$ holds initially (at position 0) and at every third position (3, 6, etc.).}\nAnswer.\n\\smallskip \\\\\nThe automaton for the property is as follow. It rejects infinite words where $\\neg p$ is at one of the positions that are multiple of 3.\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{graph}[circular placement,\n  clockwise=4,\n  nodes={draw, circle},\n  edges={>=latex},\n  radius=1.5cm,\n  phase=180\n  ]{\n   \"$s_0$\"[accepting] <- \"\"[draw=none],\n   \"$s_1$\"[accepting], \n   \"$s_2$\"[accepting],\n   \"$s_3$\",\n   \"$s_0$\"->[edge label={$p$}]\"$s_1$\",\n   \"$s_0$\"->[edge label={$\\neg p$}, swap]\"$s_3$\",\n   \"$s_1$\"->[edge label={$p, \\neg p$}]\"$s_2$\",\n   \"$s_2$\"->[edge label={$p, \\neg p$}]\"$s_0$\",\n   \"$s_3$\"->[edge label={$p, \\neg p$}, loop right]\"$s_3$\"\n};\n\\end{graph}\n\\end{tikzpicture}\n\\end{center}\n\n\\subsection{Whenever $p$ holds, $q$ must hold eventually at a strictly later position.}\nAnswer.\n\\smallskip \\\\\nThe automaton for the property is as follow. Basically, it corresponds to the LTL property, $\\textbf{AG}(p \\rightarrow \\textbf{XF} q))$.\n\\begin{center}\n\\begin{tikzpicture}[font=\\scriptsize]\n\\begin{graph}[circular placement,\n  clockwise=4,\n  nodes={draw, circle},\n  edges={>=latex, inner sep=1pt},\n  radius=2.5cm,\n  phase=180\n  ]{\n   \"$s_0$\"[accepting] <- \"\"[draw=none],\n   \"$s_1$\"[accepting], \n   \"$s_2$\"[accepting],\n   \"$s_3$\",\n   \"$s_0$\"->[edge label={$\\neg{p}q$}, out=120,in=90,looseness=8]\"$s_0$\",\n   \"$s_0$\"->[edge label={$\\neg{p}\\neg{q}$}, bend left]\"$s_1$\",\n   \"$s_0$\"->[edge label={$pq$}, bend left=15]\"$s_2$\",\n   \"$s_0$\"->[edge label={$p\\neg{q}$}, bend left=15]\"$s_3$\",\n   \"$s_1$\"->[edge label={$\\neg{p}q$}, bend left=15, swap]\"$s_0$\",\n   \"$s_1$\"->[edge label={$\\neg{p}\\neg{q}$}, loop above]\"$s_1$\",\n   \"$s_1$\"->[edge label={$p$}, bend left]\"$s_2$\",\n   \"$s_2$\"->[edge label={$\\neg{p}q$}, bend left=15, swap]\"$s_0$\",\n   \"$s_2$\"->[edge label={$pq$}, loop right]\"$s_2$\",\n   \"$s_2$\"->[edge label={$\\neg{q}$}, bend left]\"$s_3$\",\n   \"$s_3$\"->[edge label={$\\neg{p}q$}, bend left]\"$s_0$\",\n   \"$s_3$\"->[edge label={$pq$}, bend left=15]\"$s_2$\",\n   \"$s_3$\"->[edge label={$\\neg{q}$}, loop below]\"$s_3$\"\n};\n\\end{graph}\n\\end{tikzpicture}\n\\end{center}\n\n\\section{LTL to B\\\"uchi Automata Translation}\nApply the simple on-the-fly translation algorithm to construct a generalized B\\\"uchi automaton from the LTL formula $(p \\land q) \\mathcal{U} (p \\lor q)$\nPlease try to illustrate how the algorithm works by showing a few partially constructed automata during the translation.\n\n\\noindent Answer.\n\\smallskip \\\\\nInitially, we begin with the state $s_0$ with the formula $\\phi= (p \\land q) \\mathcal{U} (p \\lor q)$.\nFollowing the GPVW algorithm, $s_0$ is split into two states $s_1, s_2$. \nThen, we first process $s_1$ and put $s_2$ into stack. For $s_1$, the $p\\land q$ in New is processed,\nand two formulae $p$ and $q$ are added to New.\nThe above steps are shown in the following figure.\n\n\\begin{center}\n\\begin{tikzpicture}[\n  every node/.style={draw},\n  every edge/.style={>=latex}\n  ]\n  \\node[cross out] (0) at (0, 0){\n  \\begin{tabular}{l}\n    ID: 0 \\\\\n    IN: init \\\\\n    Old: \\\\\n    New: $\\phi$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (1) at (5,0){\n  \\begin{tabular}{l}\n    ID: 1 \\\\\n    IN: init \\\\\n    Old: $\\phi, p \\land q$\\\\\n    New: $\\phi, p \\land q, p, q$ \\\\\n    Next: $\\phi$\n  \\end{tabular}\n  };\n  \\node (2) at (9,0){\n  \\begin{tabular}{l}\n    ID: 2 \\\\\n    IN: init \\\\\n    Old: $\\phi$\\\\\n    New: $\\phi, p \\lor q$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node[draw=none] (split) at (2.3,0){\\Huge $\\to$};\n\\end{tikzpicture}\n\\end{center}\n\nNext state for $s_1$ is constructed as $s_3$.\n$s_3$ is almost identical to $s_0$;\nthe only difference is that the incoming edge is from $s_1$.\nHence, the state $s_3$ is also split into two states $s_4$ and $s_5$.\n$s_4$ is processed and $s_5$ is pushed into stack.\nAfter comparison, $s_4$ is merged with $s_1$. \nCurrently, $\\{s_2, s_5\\}$ are in the stack.\n\n\\begin{center}\n\\begin{tikzpicture}[\n  every node/.style={draw},\n  every edge/.style={>=latex}\n  ]\n  \\node[cross out] (3) at (0, 0){\n  \\begin{tabular}{l}\n    ID: 3 \\\\\n    IN: 1 \\\\\n    Old: \\\\\n    New: $\\phi$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (1) at (5,0){\n  \\begin{tabular}{l}\n    ID: 1\\textcolor{Gray}{, 4} \\\\\n    IN: init, 1 \\\\\n    Old: $\\phi, p \\land q$\\\\\n    New: $\\phi, p \\land q, p, q$ \\\\\n    Next: $\\phi$\n  \\end{tabular}\n  };\n  \\node (5) at (9,0){\n  \\begin{tabular}{l}\n    ID: 5 \\\\\n    IN: 1 \\\\\n    Old: $\\phi$\\\\\n    New: $\\phi, p \\lor q$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node[draw=none] (split) at (2.3,0){\\Huge $\\to$};\n\\end{tikzpicture}\n\\end{center}\n\nThen, we take the last state $s_5$ in the stack.\nState $s_5$ is split into two states $s_6$ and $s_7$ due to the formula $p \\lor q$.\nFor $s_6$, since there is no formula in Next, it is processed simply by moving formulae from Old to New and adding a Next state $s_8$ with self loop  and without any formula in Old. \nAt this time, $\\{s_2, s_7\\}$ are in the stack.\n$s_7$ is then processed in the same way as $s_6$, and finally only $s_2$ remains in the stack. \n\n\\begin{center}\n\\begin{tikzpicture}[\n  every node/.style={draw},\n  every edge/.style={>=latex}\n  ]\n  \\node[cross out] (5) at (0, 0){\n  \\begin{tabular}{l}\n    ID: 5 \\\\\n    IN: 1 \\\\\n    Old: $\\phi$\\\\\n    New: $\\phi, p \\lor q$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (6) at (5,0){\n  \\begin{tabular}{l}\n    ID: 6 \\\\\n    IN: 1 \\\\\n    Old: $\\phi, p \\lor q$\\\\\n    New: $\\phi, p \\lor q, p$\\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (7) at (8.5,0){\n  \\begin{tabular}{l}\n    ID: 7 \\\\\n    IN: 1 \\\\\n    Old: $\\phi, p \\lor q$\\\\\n    New: $\\phi, p \\lor q, q$\\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (8) at (11.5,0){\n  \\begin{tabular}{l}\n    ID: 8 \\\\\n    IN: 6, 7, 8 \\\\\n    Old: \\\\\n    New: \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node[draw=none] (split) at (2.3,0){\\Huge $\\to$};\n\\end{tikzpicture}\n\\end{center}\n\n\\pagebreak\n\nFor $s_2$, it is split into two states $s_9$ and $ s_{10}$ because of \n$p \\lor q$. \nHowever, after checking, $s_9$ is merged with $s_6$ and $s_10$ is merged with $s_7$. \nTherefore, no additional state is introduced.\n\n\\begin{center}\n\\begin{tikzpicture}[\n  every node/.style={draw},\n  every edge/.style={>=latex}\n  ]\n  \\node[cross out] (2) at (0, 0){\n  \\begin{tabular}{l}\n    ID: 2 \\\\\n    IN: init \\\\\n    Old: $\\phi$\\\\\n    New: $p \\lor q$ \\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (6) at (5,0){\n  \\begin{tabular}{l}\n    ID: 6\\textcolor{Gray}{, 9} \\\\\n    IN: 1, init \\\\\n    Old: $\\phi, p \\lor q$\\\\\n    New: $\\phi, p \\lor q, p$\\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node (7) at (9,0){\n  \\begin{tabular}{l}\n    ID: 7\\textcolor{Gray}{, 10} \\\\\n    IN: 1, init \\\\\n    Old: $\\phi, p \\lor q$\\\\\n    New: $\\phi, p \\lor q, q$\\\\\n    Next:\n  \\end{tabular}\n  };\n  \\node[draw=none] (split) at (2.3,0){\\Huge $\\to$};\n\\end{tikzpicture}\n\\end{center}\n\nNow we discuss about the accepting states. There is only one $\\mathcal{U}$ operator in $\\phi$, so only one set of final state.\nThe set of states with $p \\lor q$ is $\\{s_6, s_7\\}$, and the set without $\\phi$ is $\\{s_8\\}$. \nThus, the set of final states is $\\{s_6, s_7, s_8\\}$.\nWith the help of GOAL, we then convert the labels on states to labels on edges.\nThe final automaton should look like below.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{graph}[circular placement,\n  clockwise=4,\n  nodes={draw, circle},\n  edges={>=latex},\n  radius=2cm,\n  phase=180\n  ]{\n   \"$s_1$\" <- \"\"[draw=none],\n   \"$s_6$\"[accepting],\n   \"$s_8$\"[accepting],\n   \"$s_7$\"[accepting],\n   \"$s_1$\"->[edge label={$pq$},out=120,in=90,looseness=8]\"$s_1$\",\n   \"$s_1$\"->[edge label={$p$}]\"$s_6$\",\n   \"$s_1$\"->[edge label={$q$},swap]\"$s_7$\",\n   \"$s_6$\"->[edge label={$True$}]\"$s_8$\",\n   \"$s_7$\"->[edge label={$True$}, swap]\"$s_8$\",\n   \"$s_8$\"->[edge label={$True$}, loop right]\"$s_8$\"\n};\n\\end{graph}\n\\end{tikzpicture}\n\\end{center}\n\n\\end{document}", "meta": {"hexsha": "111774a9c8d79aa96c83c08e98ea2d289c65c6b1", "size": 9658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Automatic_Verification/R02943142_Automatic_Verification_HW5.tex", "max_stars_repo_name": "hc825b/homeworks", "max_stars_repo_head_hexsha": "21d2d50d7cc0ebb05f08a5ff0bdba16f6a63cccb", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-02T02:05:22.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-02T02:05:22.000Z", "max_issues_repo_path": "Automatic_Verification/R02943142_Automatic_Verification_HW5.tex", "max_issues_repo_name": "hc825b/homeworks", "max_issues_repo_head_hexsha": "21d2d50d7cc0ebb05f08a5ff0bdba16f6a63cccb", "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": "Automatic_Verification/R02943142_Automatic_Verification_HW5.tex", "max_forks_repo_name": "hc825b/homeworks", "max_forks_repo_head_hexsha": "21d2d50d7cc0ebb05f08a5ff0bdba16f6a63cccb", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-22T00:44:03.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-22T00:44:03.000Z", "avg_line_length": 26.1734417344, "max_line_length": 182, "alphanum_fraction": 0.6094429489, "num_tokens": 3647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.6089085080402946}}
{"text": "\\subsection{Group Signatures}\n\\label{ssec:crypto_group_sig}\n\n\\subsubsection{Constructing the Master Public Key}\n\nThe goal of our consensus algorithm is to enable a Byzantine-fault\ntolerant subgroup to cryptographically sign on behalf of the entire\ngroup without requiring every individual group member to sign.\nThis is enabled by signature aggregation in the appropriate way.\n\nWe let $\\mathcal{Q}$ be the collection of qualified\nactors who correctly shared their secrets and\n$\\mathcal{R}\\subseteq\\mathcal{Q}$ such that\n$\\abs{\\mathcal{R}} = t+1$; thus, $\\mathcal{R}$ is a\nByzantine-fault tolerant subgroup.\nAs discussed in~\\cite{gennaro3revisiting,gennaro1999secure,ethdkg},\nin order to ensure that no bad actors gain any information\nabout the master public key and not be able to change\nits underlying probability distribution, we require\n$h_{1}\\in\\G_{1}$ such that $\\dlog_{g_{1}}h_{1}$ is unknown.\nWe also let $h_{2}\\in\\G_{2}$ be a generator.\n\nThe individual shared secrets $s_{i}$ allow us to define the\n\\emph{master secret key} $\\text{msk}$:\n\n\\begin{equation}\n    \\text{msk} = \\sum_{P_{i}\\in\\mathcal{Q}} s_{i}.\n\\end{equation}\n\n\\noindent\nThis gives us the \\emph{master public key} $\\text{mpk}$:\n\n\\begin{align}\n    \\text{mpk} &= h_{2}^{\\text{msk}} \\nonumber\\\\\n        &= \\prod_{P_{i}\\in\\mathcal{Q}} h_{2}^{s_{i}}.\n\\end{align}\n\n\\noindent\nBecause everyone in $\\mathcal{Q}$ correctly shared his secret,\na Byzantine-fault tolerant subgroup $\\mathcal{R}$ can\ncorrectly obtain the secret $s_{i}$ via Lagrange interpolation:\n\n\\begin{align}\n    s_{i} &= \\sum_{P_{j}\\in\\mathcal{R}} s_{i\\to j} R_{j} \\nonumber\\\\\n    R_{j} &= \\prod_{\\substack{P_{k}\\in\\mathcal{R} \\\\ k\\ne j}} \\frac{k}{k-j}.\n    \\label{eq:Rj_coefs}\n\\end{align}\n\n\\noindent\nThis would allow us to recover the secret $s_{i}$ should $P_{i}$\nfail to share $h_{1}^{s_{i}}$ below; however,\nwe take a stricter response and would view failure to share\nas malicious activity leading to stake slashing.\n\nWe now proceed to compute $\\text{mpk}$.\nLet\n\n\\begin{equation}\n    \\pi(h_{1}^{s_{i}}) = \\textsc{DLEQ}(\n        g_{1},g_{1}^{s_{i}},h_{1},h_{1}^{s_{i}},s_{i})\n\\end{equation}\n\n\\noindent\nbe the zk-proof that $h_{1}^{s_{i}}$ is $P_{i}$'s portion\nof the master public key (technically part of $\\text{mpk}^{*}$\nas defined below).\nBecause $C_{i0} = g_{1}^{s_{i}}$ is public knowledge\nand $P_{i}$ correctly shared his secret $s_{i}$, it is possible\nto publicly verify $h_{1}^{s_{i}}$.\nAdditionally, $P_{i}$ will publish $h_{2}^{s_{i}}$ so that\nwe can ensure\n\n\\begin{equation}\n    \\textsc{PairingCheck}(h_{1}^{s_{i}},\\bar{h}_{2},h_{1},h_{2}^{s_{i}})\n        = 1.\n\\end{equation}\n\n\\noindent\nThis will be called by a smart contract.\nThus, failure of $P_{i}$ to publish $h_{1}^{s_{i}}$,\na valid proof $\\pi(h_{1}^{s_{i}})$, and the corresponding\n$h_{2}^{s_{i}}$ amounts to misbehavior which will\nlead to a fine.\n\nThe Ethereum smart contract will store $h_{1}^{s_{i}}$ from\nall participants and broadcast\n$h_{1}^{s_{i}}$, $\\pi(h_{1}^{s_{i}})$, and $h_{2}^{s_{i}}$.\nFrom here, any participant will be able to submit\n\n\\begin{equation}\n    \\text{mpk} = \\prod_{P_{i}\\in\\mathcal{Q}} h_{2}^{s_{i}}\n\\end{equation}\n\n\\noindent\nto the smart contract.\nBecause $\\braces{h_{1}^{s_{i}}}_{i\\in\\mathcal{Q}}$ are stored\nand valid, the contract can construct\n\n\\begin{equation}\n    \\text{mpk}^{*} = \\prod_{P_{i}\\in\\mathcal{Q}} h_{1}^{s_{i}}\n    \\label{eq:mpk_dual}\n\\end{equation}\n\n\\noindent\nand call\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\text{mpk}^{*},\\bar{h}_{2},h_{1},\\text{mpk})\n\\end{equation}\n\n\\noindent\nto ensure $\\text{mpk}$ is valid.\nThe master public key can then be stored publicly and used\nfor group signature verification.\n\n\n\n\\subsubsection{Constructing Group Signatures}\n\nAt this point, we have successfully constructed the master public\nkey $\\text{mpk}$ for $\\mathcal{Q}$ and distributed\nthe master secret key $\\text{msk}$ among the members of $\\mathcal{Q}$.\nWe now turn our attention to constructing group\nsignatures from partial signatures.\n\nEach participant $P_{j}\\in\\mathcal{Q}$ has a portion of the\nmaster secret key; this is portion is called the \\emph{group secret\nkey}:\n\n\\begin{equation}\n    \\gsk_{j} = \\sum_{P_{i}\\in\\mathcal{Q}} s_{i\\to j}.\n\\end{equation}\n\n\\noindent\nThis is possible because we proved that every participant\nin $\\mathcal{Q}$ correctly shared his secret share.\nWe note that that $s_{j\\to j}$ is included in the sum for\n$\\gsk_{j}$ even though the encrypted form was not publicly shared.\nNaturally, there is the corresponding \\emph{group public key}:\n\n\\begin{equation}\n    \\gpk_{j} = h_{2}^{\\gsk_{j}}.\n\\end{equation}\n\n\\noindent\nHere, $\\gpk_{j}$ is $P_{j}$'s portion of the master public key\nand will be broadcast to all users.\nCryptographic proof that $\\gpk_{j}$ is valid will be discussed\nin the next section.\n\nThe threshold property along with the previous definitions give\nus the following result:\n\n\\begin{equation}\n    \\text{msk} = \\sum_{P_{j}\\in\\mathcal{R}} \\gsk_{j}R_{j}.\n\\end{equation}\n\n\\noindent\nThese $R_{j}$ factors only depend on $\\mathcal{R}$.\nIt follows that\n\n\\begin{equation}\n    \\text{mpk} = \\prod_{P_{j}\\in\\mathcal{R}} \\gpk_{j}^{R_{j}}.\n\\end{equation}\n\n\\noindent\nThis will allow partial signatures to be combined into a valid\ngroup signature.\n\nWe now assume that $\\mathcal{Q}$ wants to sign message $M$.\nWe let $H_{2C}(M)\\in\\G_{1}$ be the result of a hash-to-curve algorithm;\nthese will be discussed in Sec.~\\ref{ssec:hash-to-curve}.\nIn this case, participant $P_{j}\\in\\mathcal{R}$ computes the\npartial signature\n\n\\begin{equation}\n    \\sigma_{j} = \\brackets{H_{2C}(M)}^{\\gsk_{j}}.\n\\end{equation}\n\n\\noindent\nFor security, we should confirm\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\sigma_{j},\\bar{h}_{2},H_{2C}(M),\\gpk_{j}) = 1\n\\end{equation}\n\n\\noindent\nto ensure we have a valid signature.\nIf $\\gpk_{j}$ is stored and we can call the hash-to-curve function $H_{2C}$,\nthen the only inputs will be the message $M$\nand signature $\\sigma_{j}$.\n\nIt is easy to compute the group signature from the partial signatures:\n\n\\begin{equation}\n    \\sigma = \\prod_{P_{j}\\in\\mathcal{R}} \\sigma_{j}^{R_{j}}.\n\\end{equation}\n\n\\noindent\nThe $R_{j}$ constants are defined in Eq.~\\eqref{eq:Rj_coefs};\nas mentioned above, the $R_{j}$ depend upon $\\mathcal{R}$\nand can be computed by anyone.\nBecause $\\sigma_{j}\\in\\G_{1}$, signature aggregation could be carried\nout by the EVM if desired; the gas cost would come from calls to\n\\textsc{ECAdd}, \\textsc{ECMul}, and modular exponentiation,\nbut this would be expensive.\nWe now prove this is the signature corresponding to the master public key:\n\n\\begin{align}\n    e(\\sigma, h_{2})\n        &= \\prod_{P_{j}\\in\\mathcal{R}}\n            e\\parens{\\sigma_{j}^{R_{j}},h_{2}}\n            \\nonumber\\\\\n        &= \\prod_{P_{j}\\in\\mathcal{R}}\n            e\\parens{\\brackets{H_{2C}(M)}^{\\text{gsk}_{j}},h_{2}^{R_{j}}}\n            \\nonumber\\\\\n        &= \\prod_{P_{j}\\in\\mathcal{R}} e\\parens{H_{2C}(M),\n                \\brackets{h_{2}^{\\text{gsk}_{j}}}^{R_{j}}} \\nonumber\\\\\n        &= e(H_{2C}(M),\\text{mpk}).\n\\end{align}\n\n\\noindent\nIt follows that\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\sigma,\\bar{h}_{2},H_{2C}(M),\\text{mpk}) = 1.\n\\end{equation}\n\n\\noindent\nThis allows every member of $\\mathcal{R}$ to compute the signature\nfor the entire group while not requiring anyone to share his\nsigning key.\nThis is of utmost importance for security.\n\n\n\n\\subsubsection{Malicious Group Public Key Shares}\n\nWe now look at how to ensure the broadcast value of\n$\\gpk_{j}$ is valid.\n\nAlong with the $P_{j}$'s group public key $\\gpk_{j}\\in\\G_{2}$,\nthere is the corresponding version in $\\G_{1}$:\n\n\\begin{equation}\n    \\gpk_{j}^{*} = g_{1}^{\\gsk_{j}}.\n\\end{equation}\n\n\\noindent\nNote the base is $g_{1}$ and not $h_{1}$ as in the case of $\\text{mpk}^{*}$\nin Eq.~\\eqref{eq:mpk_dual}.\nParticipant $P_{j}$ will publish a signature $\\sigma_{j}$ of a predetermined\nmessage $M$ for security purposes.\nAn initial check will ensure\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\sigma_{j},\\bar{h}_{2},H_{2C}(M),\\gpk_{j}) = 1;\n\\end{equation}\n\n\\noindent\nany validator who provides an invalid signature\nis clearly malicious.\n\nBecause $P_{j}$ correctly shared his secret, $\\gpk_{j}^{*}$\nis public knowledge, as\n\n\\begin{equation}\n    \\gpk_{j}^{*} = \\prod_{P_{i}\\in\\mathcal{Q}}F_{i}(j).\n    \\label{eq:gpkj_star_def}\n\\end{equation}\n\n\\noindent\nThus, it could be reconstructed inside a smart contract.\nFrom there, we will ensure\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\gpk_{j}^{*},\\bar{h}_{2},g_{1},\\gpk_{j}) = 1.\n\\end{equation}\n\n\\noindent\nRequiring submission of $\\gpk_{j}^{*}$ and the associated\nproof could be required at the time of submission.\nThis would be costly, though, and will instead allow\nthe other participants to prove malicious behavior.\nWe would prefer the entire process to be as inexpensive\nas possible should there be no malicious actors.\n\nIt will be expensive to carry out this proof of malicious action.\nThe reason is that in order to compute $\\gpk_{j}^{*}$,\nthe message containing the shared secrets and public coefficients\nfrom every participant will need to be entered into a smart contract\nin order to obtain the right hand side of\nEq.~\\eqref{eq:gpkj_star_def}.\nBecause of this, there is another, cheaper way to prove malicious\nbehavior provided a Byzantine-fault tolerant group\ncorrectly submits $\\gpk_{j}$ with valid signatures $\\sigma_{j}$\nand we discuss this now.\n\nFirst, a participant can go through all possible subgroups\n$\\mathcal{R}\\subseteq\\mathcal{Q}$ searching for a subset\nwhose signatures can be combined to form a valid\ngroup signature.\nOnce a valid subset $\\mathcal{R}$ is found,\nwe can then choose $P_{i}\\in\\mathcal{Q}\\setminus\\mathcal{R}$\nin order to determine if\n$\\braces{P_{i}}\\cup\\parens{\\mathcal{R}\\setminus \\braces{P_{v}}}$\ncan form a valid signature;\nif it does not, then $P_{i}$ is malicious.\nHere $P_{v}\\in\\mathcal{R}$ is a fixed.\nIn this case, two lists of participants would be entered into a smart\ncontract: a list of valid participants followed by a list of\ninvalid participants.\nIt is straightforward to show the list of valid\nparticipants form a valid group signature.\nFrom there, malicious participant's signatures are included \none at a time to show that they form invalid signatures,\ngiving cryptographic proof of malicious behavior.\nNaturally, it would be a malicious action if false participant\nlists were submitted.\n\nWe now look at the costs of both methods.\nThe major costs will be calling the precompiled contracts\n\\textsc{ECAdd}, \\textsc{ECMul}, \\textsc{PairingCheck},\nand \\textsc{ModExp} (modular exponentiation);\nsee Table~\\ref{tab:evm_gas_cost} for the specific gas costs.\nNote that the cost for \\textsc{PairingCheck} comes\nfrom our assumption that we are testing 2 pairings,\nwhile the cost for \\textsc{ModExp} comes from the fact\nthat all of our arguments are 256-bit (32-byte) unsigned integers.\nThese costs come from EIP-198\\footnote{\n    \\url{https://github.com/ethereum/EIPs/blob/master/EIPS/eip-198.md}}\nand EIP-1108\\footnote{\n    \\url{https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1108.md}}.\n\n\\input{tables/evm_cost.tex}\n\nWe begin with the standard method.\nFirst, to compute $\\gpk_{j}^{*}$, we must compute $F_{i}(j)$:\n\n\\begin{equation}\n    F_{i}(j) = C_{i0}C_{i1}^{j}C_{i2}^{j^{2}}\\cdots C_{it}^{j^{t}}.\n\\end{equation}\n\n\\noindent\nThe cost of computing $F_{i}(j)$ is dominated by $t$ calls to \\textsc{ECMul}.\nThis will be done for each element in $\\mathcal{Q}$, so the\nmain computation is $nt$ calls to \\textsc{ECMul} in addition\nto a call to \\textsc{PairingCheck}.\nThus, we see\n\n\\begin{equation}\n    \\text{Cost of Standard Proof} \\sim 113000 + 4000n^{2}.\n\\end{equation}\n\n\\noindent\nFor $n=20$, this corresponds to $1.7$M gas; the gas limit\nis 10M.\n\nWe now look at the cost of the group method.\nWe will ignore the initial cost of ensuring a valid group signature\nfrom $\\mathcal{R}$.\nThe computation consists of forming\n\n\\begin{equation}\n    \\sigma = \\prod_{P_{j}\\in\\mathcal{R}^{*}_{k}} \\sigma_{j}^{R_{j}},\n\\end{equation}\n\n\\noindent\nwhere\n\n\\begin{equation}\n    \\mathcal{R}^{*}_{k} = \\parens{\\mathcal{R}\\setminus P_{v}}\\cup\n        \\braces{P_{k}}\n\\end{equation}\n\n\\noindent\nfor $P_{v}\\in\\mathcal{R}$ fixed and $P_{k}\\in\\mathcal{I}$,\nthe set of participants who incorrectly shared $\\gpk_{j}$.\nFrom there, we would call\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\sigma, \\bar{h}_{2}, H_{2C}(M), \\text{mpk})\n\\end{equation}\n\n\\noindent\nto ensure that this is an invalid signature,\nand the initial check confirming $\\mathcal{R}$ forms a valid\nsignature implies that $P_{k}$ is malicious.\n\nEach group signature $\\sigma$ will require forming $R_{j}$\nand computing $\\sigma_{j}^{R_{j}}$.\nAfter computing $R_{j}$, we require one \\textsc{ECMul} call\nto compute $\\sigma_{j}^{R_{j}}$.\nThe expensive part turns out to be forming $R_{j}$,\nand we focus on its straightforward computation.\nWe recall from Eq.~\\eqref{eq:Rj_coefs} that\n\n\\begin{equation}\n    R_{j} = \\prod_{\\substack{P_{k}\\in\\mathcal{R} \\\\ k\\ne j}} \\frac{k}{k-j}.\n\\end{equation}\n\n\\noindent\nNaively, we would need to compute $t$ finite field inversions,\nwhich corresponds to $t$ \\textsc{ModExp} calls, to compute\n$R_{j}$.\nThis must be performed $t+1$ times to form $\\sigma$;\nwe must also call \\textsc{ECMul} $t+1$ times but this is\nnegligible.\nFinally, we must call\n\n\\begin{equation}\n    \\textsc{PairingCheck}(\\sigma, \\bar{h}_{2}, H_{2C}(M), \\text{mpk});\n\\end{equation}\n\n\\noindent\nthis call must fail for invalid signatures.\nThus, we have\n\n\\begin{equation}\n    \\text{Cost of Naive Group Proof} \\sim 113000 + 5800n^{2}.\n\\end{equation}\n\n\\noindent\nFor $n=20$, this corresponds to $2.4$M gas.\nThis is more expensive than the previous version, but we can\ndo better.\n\nThe main cost comes from the finite field inversions, which require\na call to \\textsc{ModExp}.\nTo fix this, we precompute these inverses and include them\nin the function call.\nAt the beginning of the call, we check to make sure that the submitted\ninverses are valid; if they are valid, we proceed with the\naccusation, and if they are invalid, we stop.\nEverything else is the same as before;\nsee Alg.~\\ref{alg:grpsig_malicious} for the complete description.\nFor each accusation, the main cost is $t+1$ \\textsc{ECMul} calls\nas well as one pairing check.\nNow, these same computations must be included for the initial\ncheck of a valid group signature, but we will ignore that for now.\nThus, we have the cost to prove malicious action for one participant:\n\n\\begin{equation}\n    \\text{Cost of Efficient Group Proof} \\sim 113000 + 4000n.\n\\end{equation}\n\n\\noindent\nFor $n=20$, this corresponds to $200$K gas.\nThis is more efficient than computing $\\gpk_{j}^{*}$ via smart contract.\n\nDue to the costs, validators would always prefer to use the group\nmethod over submitting all of the sent messages.\nEven so, submitting all messages will always work, while in the group\nsetting we require a Byzantine-fault tolerant set of honest\nvalidators.\n\n\\input{algs/gpkj_algs.tex}\n\n", "meta": {"hexsha": "2b1b9a98301dd1b6ce1f44828a3305be44e5e640", "size": 14906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/tcrypt_grpsig.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_grpsig.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_grpsig.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.4749455338, "max_line_length": 77, "alphanum_fraction": 0.7127331276, "num_tokens": 4723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.6654105454764747, "lm_q1q2_score": 0.6087847450627952}}
{"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*{gSat.m} \n\n\\begin{par}\n\\textbf{Summary:} Compute moments of the saturating function $e*(9*\\sin(x(i))+\\sin(3*x(i)))/8$, where $x \\sim\\mathcal N(m,v)$ and $i$ is a (possibly empty) set of $I$ indices. The optional  scaling factor $e$ is a vector of length $I$. Optionally, compute derivatives of the moments.\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}  function [M, S, C, dMdm, dSdm, dCdm, dMdv, dSdv, dCdv] = gSat(m, v, i, e)\\end{verbatim}\n    \\begin{par}\n\\textbf{Input arguments:}\n\\end{par} \\vspace{1em}\n\\begin{verbatim}m     mean vector of Gaussian                                    [ d       ]\nv     covariance matrix                                          [ d  x  d ]\ni     vector of indices of elements to augment                   [ I  x  1 ]\ne     (optional) scale vector; default: 1                        [ I  x  1 ]\\end{verbatim}\n\\begin{par}\n\\textbf{Output arguments:}\n\\end{par} \\vspace{1em}\n\n\\begin{verbatim}M     output means                                                [ I       ]\nV     output covariance matrix                                    [ I  x  I ]\nC     inv(v) times input-output covariance                        [ d  x  I ]\ndMdm  derivatives of M w.r.t m                                    [ I  x  d ]\ndVdm  derivatives of V w.r.t m                                    [I*^2 x  d ]\ndCdm  derivatives of C w.r.t m                                    [d*I x  d ]\ndMdv  derivatives of M w.r.t v                                    [ I  x d^2]\ndVdv  derivatives of V w.r.t v                                    [I^2 x d^2]\ndCdv  derivatives of C w.r.t v                                    [d*I x d^2]\\end{verbatim}\n    \\begin{par}\nCopyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.\n\\end{par} \\vspace{1em}\n\\begin{par}\nLast modified: 2013-03-25\n\\end{par} \\vspace{1em}\n\n\\begin{lstlisting}\nfunction [M, S, C, dMdm, dSdm, dCdm, dMdv, dSdv, dCdv] = gSat(m, v, i, e)\n\\end{lstlisting}\n\n\n\\subsection*{Code} \n\n\n\\begin{lstlisting}\nd = length(m); I = length(i); i = i(:)';\nif nargin < 4; e = ones(1, I); end; e = e(:)';\n\nP = [eye(d); 3*eye(d)];                                        % augment inputs\nma = P*m;    madm = P;\nva = P*v*P'; vadv = kron(P,P); va = (va+va')/2;\n\n% do the actual augmentation with the right parameters\n[M2, S2, C2, Mdma, Sdma, Cdma, Mdva, Sdva, Cdva] ...\n  = gSin(ma, va, [i d+i], [9*e e]/8);\n\nP = [eye(I) eye(I)]; Q = [eye(d) 3*eye(d)];\nM = P*M2;                                                                % mean\nS = P*S2*P'; S = (S+S')/2;                                           % variance\nC = Q*C2*P';                                    % inv(v) times input-output cov\n\nif nargout > 3                                        % derivatives if required\n  dMdm = P*Mdma*madm;         dMdv = P*Mdva*vadv;\n  dSdm = kron(P,P)*Sdma*madm; dSdv = kron(P,P)*Sdva*vadv;\n  dCdm = kron(P,Q)*Cdma*madm; dCdv = kron(P,Q)*Cdva*vadv;\nend\n\\end{lstlisting}\n", "meta": {"hexsha": "3bf62a114caf79c8d0d3f2c0b5c7b06e918dfbaa", "size": 3080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/gSat.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/gSat.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/gSat.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": 41.0666666667, "max_line_length": 283, "alphanum_fraction": 0.4931818182, "num_tokens": 954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6087689990480081}}
{"text": "\\section{Fundamentals of blockchain}\\label{sec:fundamentals}\nIn this section, the key elements of the blockchain that contribute to its properties will be displayed: integrity, immutability, transparency, availability, disintermediation, decentralization.\n\n\\subsection{Cryptography}\\label{sec:criptografia}\nBlockchain relies heavily on encryption to satisfy system and application security requirements. As the word suggests, cryptocurrencies also make heavy use of encryption. Encryption provides a mechanism for safely encoding the rules of system encryption on the system itself. This can prevent tampering and misconceptions and coding in a mathematical protocol the rules for creating new currency units. So, before understanding blockchains correctly, it is necessary to understand the cryptographic foundations they trust \\cite{narayanan2016bitcoin}.\n\nCryptography is a profound academic field of research that uses many advanced mathematical techniques that are notoriously subtle and complicated. In this chapter, cryptographic hashes and digital signatures will be defined, which stand out among the most used resources. For more details, the reader should refer to the book \\cite{narayanan2016bitcoin}.\n\n\\subsubsection{Cryptographic Hashes}\\label{sec:hashesCriptograficos}\nA hash function is a mathematical function with the three properties to be followed \\cite{narayanan2016bitcoin}:\n\n\\begin{itemize}\n\\item  Its input can be any string of any length;\n\\item Produces a fixed size output. To make concrete the discussion in this chapter (e.g., 256 digits);\n\\item It is efficiently computable. Intuitively, this means that it is possible to find out the hash function output within a reasonable time for a given input string. Technically, hashing a n-bit string must have an $O(n)$ runtime.\n\\end{itemize}\n\nThese properties define a general hash function. Cryptographic hash functions (or cryptographic summaries) are unidirectional and hardly allow retrieving the original value $x$ from the hash $h$. For a hash function to be cryptographically secure, it must satisfy the following three properties: (1) collision resistance, (2) hiding, and (3) puzzle friendliness \\cite{greve2018blockchain}.\n\nA collision occurs when two distinct inputs produce the same output. A hash function $H$ is collision-resistant when it is impossible to find two values $x$ and $y$, such that $x \\neq y$ and $H(x) = H(y)$ \\cite{narayanan2016bitcoin}.\n\nThe hidden property states that having the hash function output $y = H (x)$, there is no possible way to find the $x$ input \\cite{greve2018blockchain}.\n\nA hash function $H$ is considered puzzle friendliness if for each possible output value of $n$ bits $y$ if $k$ is chosen from a distribution with high min-entropy, then it is impracticable to find $x$ such that $H (k \\| x) = y$ in time significantly less than $2^n$ \\cite{narayanan2016bitcoin}.\n\n\\subsubsection{Digital Signatures}\\label{sec:assinaturasDigitais}\nA digital signature is supposed to be a digital analog of a handwritten paper signature. Two signature properties are desired, which correspond well to the analogy of the handwritten signature. First, only one person can make their signature, but anyone can verify if it is valid. Secondly, it is desired that the signature be linked to a specific document, so it cannot indicate the agreement or endorsement to a different document \\cite{merkle1989certified}. Moreover, it is not possible to forge a signature in such a way as to reuse it in some other context. That is, signatures must be irrefutable.\n\nTo implement digital signatures, asymmetric key encryption is used. A \\ac{SK} is used for signing the document, and a \\ac{PK} is used to attest the signature's authenticity \\cite{greve2018blockchain}.\n\nA digital signature consists of the following three algorithms \\cite{narayanan2016bitcoin}:\n\n\\begin{itemize}\n\\item $(sk , pk) := generateKeys(keysize)$ – The $generateKeys()$ method receives a key size $(keysize)$ in the input and return a pair of public $(pk)$ and private $(sk)$ keys.\n\\item $sig := sign(sk , msg)$ – The method $sign()$ receives a message $msg$ and a secret key $(sk)$ on entry and returns the signature $sig$ f that message under $sk$.\n\\item $isValid := verify(pk , msg , sig)$ – The method $verify$ receives a public key $(pk)$, a message $msg$, and a signature $(sig)$ as input, and returns a boolean value: $isValid = true$ if $sig$ is a signature valid for $msg$ under $pk$; $isValid = false$, otherwise.\n\\end{itemize}\n\nThe following two properties must be maintained:\n\n\\begin{itemize}\n\\item Authenticity: Signatures can be validated: \\\\ $verify(pk, message, sign(sk, message)) = = true$.\n\\item Signatures are existentially unfalsifiable: signature cannot be forged.\n\\end{itemize}\n\nIt is noted that \\textit{generateKeys()} and \\textit{sign()} can be random algorithms. Generating keys should be randomized because it should be generating different keys for different people. On the other hand, \\textit{verify()} will always be deterministic.\n\n\\begin{figure}[htbp]\n\\begin{center}\n  \\includegraphics[scale=1.0]{images/AliceBob.jpg}\n\\caption{Signatures validated by public/private key \\cite{forging}.}\n\\label{fig:authenticationExample}\n\\end{center}\n\\end{figure}\n\n\\subsection{Consensus}\\label{sec:consenso}\nThe key to blockchain operation is that the network must agree collectively on the ledger's content.  Instead of a central entity maintain control over information (such as a bank, for example), the data is shared among all. This requires the network to maintain the consensus around the information recorded in the blockchain. How this consensus is reached affects the security and economic parameters of the protocol \\cite{kostarev2017review}.\n\nIn this context, consensus emerges as a fundamental problem since it allows distributed participants to coordinate their actions to reach joint decisions, ensuring the consistency of safety and system progress (liveness) despite failures \\cite{greve2018blockchain}. More specifically, in the context of blockchain, consensus enables an agreement on the next block that will be added to the blockchain.\n\nIn the blockchain, reaching consensus between untrusted nodes is a transformation of the problem of \\ac{BG} \\cite{lamport1982byzantine}. In the BG problem, a group of generals who command a portion of the Byzantine army circles the city. The attack would fail if only part of the generals attacked the city. Generals need to communicate to agree on the attack or not. However, there may be traitors in the generals. The traitor could send different decisions to different generals. This is an environment without trust.\n\nReaching consensus in such an environment is a challenge. This is also a challenge for blockchain because its network is distributed, and there is no central node that ensures that ledgers on distributed nodes be all the same. Nodes do not need to trust other nodes. Thus, some protocols are required to ensure that ledgers on different nodes are consistent \\cite{kostarev2017review}. To solve the consensus problem, several algorithms have been proposed, the mainly used are Proof-of-Work, Proof-of-Stake, Delegated Proof-of-Stake, Leased Proof-Of-Stake, Proof of Elapsed Time, Practical Byzantine Fault Tolerance, Simplified Byzantine Fault Tolerance, Delegated Byzantine Fault Tolerance, Directed Acyclic Graphs, Proof-of-Activity, Proof-of-Importance, Proof-of-Capacity, Proof-of-Burn and Proof-of-Weight \\cite{mingxiao2017review}.\n\nA good consensus algorithm means efficiency, security, and convenience. Current standard consensus algorithms still have many shortcomings. New consensus algorithms are created to solve some blockchain-specific problems \\cite{zheng2016blockchain}.\n\n\n\\subsection{Distributed Ledger}\\label{sec:livro}\nA distributed ledger is a data structure distributed by several nodes or computing devices. Each node replicates and saves an identical ledger copy. Each participating node in the network updates independently \\cite{greve2018blockchain}.\n\nThe innovative feature of distributed accounting technology is that any central authority does not maintain the ledger. Updates to The ledger are independently constructed and recorded by each node. The nodes then vote on these updates to ensure that most agree on the conclusion, based on some previous consensus algorithm. Once consensus has been reached, the distributed ledger updates itself, and the latest agreed version is saved on each separate node \\cite{swan2015blockchain}. Thus, the distributed ledger is replicated and immutable. \n\n\\subsubsection{Transactions}\\label{sec:transac}\nThe blockchain is a public digital book that records online transactions. In it, transactions are recorded in a block without the help of third parties, such as a bank or payment processor. The blockchain algorithm automatically graphs and authenticates the transaction, which is immediately visible to all users, minimizing the possibility of fraud. The terms of a transaction do not include any personal or identifying information \\cite{Bankrate2018}.\n\nThe most fundamental definition of a transaction is an atomic event allowed by the underlying protocol from a technical standpoint. A transaction determines a sequence of state operations.  It adds a transfer of an asset or, generally speaking, a smart contract.  In a basic case, the transaction girds a digital signature of the issuer holding the asset and the receiver's address and inputs and outputs for the transaction. Each transaction must contain both Inputs and Outputs, just like in an accounting book. Entries indicate the previous transaction hash related to the current one \\cite{greve2018blockchain}. Validating a Transition involves:\n\n\\begin{enumerate}\n\t\\item signature verification;\n\t\\item confirmation of existing values from hashes of previous referenced transactions;\n\t\\item confirmation that any other transactions did not previously spend the amount.\n\\end{enumerate}\n\nIn this case, it is necessary to search the blockchain between the block from the referenced transaction to the last block of the structure. Each node of the blockchain network independently validates transactions, and this feature contributes to the decentralization of the process \\cite{greve2018blockchain}.\n\n\\subsubsection{Blocks}\\label{sec:blocks}\nBlocks contain a header with the information needed for the current maintenance and its validation. A block consists of the block header and block body, as shown in Figure \\ref{fig:block}. \n\n\\begin{figure}[htbp]\n\\begin{center}\n  \\includegraphics[scale=0.5]{images/blockStructure.png}\n\\caption{Structure of a block. \\cite{zheng2016blockchain}}\n\\label{fig:block}\n\\end{center}\n\\end{figure}\n\nIn particular, the header Pack includes:\n\n\\begin{itemize}\n\\item Block version: indicates which set of block validation rules to follow.\n\\item Parent block hash: A 256-bit hash value that points to the previous block.\n\\item Merkle tree root hash: The hash value of all transactions in the block.\n\\item Timestamp: Current date and time as seconds since 1970-01-01T00:00 UTC.\n\\item  nBits: current hashing target in a compact format.\n\\item Nonce: A 4-byte field, usually starting with 0 and increasing for each hash.\n\\end{itemize}\n\nThe body's block consists of a transaction counter and transaction. The maximum number of transactions a block can hold depends on block size and the size of each transaction. Blockchain uses an asymmetric encryption mechanism to validate transaction authentication. A digital signature based on asymmetric encryption is used in an untrusted environment \\cite{zheng2016blockchain}.\n\nThe validation of a block consists in verifying (i) if its structure is well-formed (ii) its hash is valid (meets the challenge), (iii) its size is within the network accepted limit, (iv) the set of transactions within the block is valid, (v) the first transaction (and only the first) is the coinbase transaction - which incorporates the generation of new cryptocurrencies in the system, besides acting as a reward mechanism. The blocks are validated independently by each node of the blockchain network, and this feature contributes to the process of decentralization \\cite{greve2018blockchain}.\n\nFigure \\ref{fig:blockchain} presents a visual representation of a blockchain \\cite{tian2017supply}.\n\n\\begin{figure}[htbp]\n\\begin{center}\n  \\includegraphics[scale=0.35]{images/blockchain.png}\n\\caption{Blockchain representation \\cite{michael2018blockchain}}\n\\label{fig:blockchain}\n\\end{center}\n\\end{figure}\n", "meta": {"hexsha": "23c70f2698b4e02cf45073575328aa408ab0c107", "size": 12532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2_THEORETICAL_BACKGROUND/sections/4_fundamentalsOfBlockchain.tex", "max_stars_repo_name": "juniorug/Master-thesis", "max_stars_repo_head_hexsha": "c7e7e1da620ea717619c058c170db46cee8e9970", "max_stars_repo_licenses": ["MIT"], "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_THEORETICAL_BACKGROUND/sections/4_fundamentalsOfBlockchain.tex", "max_issues_repo_name": "juniorug/Master-thesis", "max_issues_repo_head_hexsha": "c7e7e1da620ea717619c058c170db46cee8e9970", "max_issues_repo_licenses": ["MIT"], "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_THEORETICAL_BACKGROUND/sections/4_fundamentalsOfBlockchain.tex", "max_forks_repo_name": "juniorug/Master-thesis", "max_forks_repo_head_hexsha": "c7e7e1da620ea717619c058c170db46cee8e9970", "max_forks_repo_licenses": ["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.5702479339, "max_line_length": 835, "alphanum_fraction": 0.8022661985, "num_tokens": 2741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.6087689912439437}}
{"text": "\\chapter{Relativistic Spin-$\\frac{1}{2}$ particles}\n\\section{Spin in non-relativistic QM}\nThe quantum states corresponding to spin-$\\frac{1}{2}$ particles are eigenstates of the spin operator,\n\\begin{equation}\n\\hat{S}_i = \\frac{1}{2}\\sigma_i\n\\end{equation}\nwhere $\\sigma_i$ are the Pauli matrices,\n\\begin{equation}\n\\sigma_x = \\mqty(0 & 1 \\\\ 1 & 0), \\quad\n\\sigma_y = \\mqty(0 & -i \\\\ i & 0), \\quad\n\\sigma_z = \\mqty(1 & 0 \\\\ 0 & -1).\n\\end{equation}\nApplication of $\\hat{S}_z$ on a state of definite spin projection on the z-axis gives\n\\begin{equation}\n\\hat{S}_z \\ket{s, m} = m \\ket{s, m}\n\\end{equation}\nand application of the operator $\\hat{S}^2 = \\sum_i \\hat{S}_i^2$ -- which corresponds to the total spin angular momentum of the state -- gives\n\\begin{equation}\n\\hat{S}^2 \\ket{s, m} = s(s+1) \\ket{s, m}.\n\\end{equation}\n\nThe commutator of any two spin operators is\n\\begin{equation}\n\\left[ \\hat{S}_i, \\hat{S}_j \\right] = i \\epsilon_{ijk} \\hat{S}_k\n\\end{equation}\nand they have the anticommutation relation\n\\begin{equation}\n\\left\\{ \\hat{S}_i, \\hat{S}_j \\right\\} = \\delta_{ij}.\n\\end{equation}\nTherefore, we have that\n\\begin{align}\n\\sigma_i \\sigma_j &= \\frac{[ \\sigma_i, \\sigma_j ] + \\{ \\sigma_i, \\sigma_j \\}}{2}  \\nonumber \\\\\n&= \\delta_{ij} + i\\epsilon_{ijk}\\sigma_k.\n\\end{align}\nSo for any two vectors, $\\vec{a}$ and $\\vec{b}$,\n\\begin{align}\n(\\vec{\\sigma}\\cdot\\vec{a})(\\vec\\sigma\\cdot\\vec{b}) &= \\sigma_i \\, a_i \\, \\sigma_j \\, b_j \\nonumber \\\\\n&= \\sigma_i \\, \\sigma_j \\, (a_i \\, b_j) \\nonumber \\\\\n&= (\\delta_{ij} + i\\epsilon_{ijk}\\sigma_k)(a_i \\, b_j) \\nonumber \\\\\n&= a_i \\, b_i + i \\, \\sigma_k \\, \\epsilon_{kij} \\, a_i \\, b_j \\nonumber \\\\\n&= \\vec{a}\\cdot\\vec{b} + i \\vec{\\sigma}\\cdot(\\vec{a}\\times\\vec{b}).\n\\end{align}\nApplying this result to $\\vec{a} = \\vec{b} = \\vec{p}$, the momentum operator,\n\\begin{align}\n(\\vec{\\sigma}\\cdot\\vec{p})(\\vec{\\sigma}\\cdot\\vec{p}) &= \\vec{p}\\cdot\\vec{p} + i \\vec{\\sigma}\\cdot\\underbrace{(\\vec{p} \\times \\vec{p})}_0 \\nonumber \\\\\n&= \\abs{\\vec{p}}^2. \\label{eq:sigmaDotP2}\n\\end{align}\nThis allows us to express the energy as\n\\begin{equation}\nE = \\frac{(\\vec{\\sigma}\\cdot\\vec{p})(\\vec{\\sigma}\\cdot\\vec{p})}{2m} + V\n\\end{equation}\nwhich leads to the correct energy for a particle with a gyromagnetic ratio if the EM coupling is included.\n\n\\section{The Dirac equation}\nTo avoid the negative energy solutions seen in the treatment of the Klein-Gordon equation, Dirac proposed an equation of motion that is linear in $\\pdv{t}$. Also, there should be distinct solutions for particles with opposite spin.\n\n\\begin{equation}\\boxed{\n\\hat{H}\\psi = \\left( \\vec{\\alpha}\\cdot{\\vec{p}} + \\beta m \\right) \\psi\n}\\end{equation}\nis the Dirac equation. Here, $\\alpha_i$ and $\\beta$ are $4\\times4$ matrices and $\\psi$ therefore a 4-component Dirac spinor.\n\n\\subsection{Constraints on $\\alpha_i$, $\\beta$}\nFor the Dirac equation to describe relativistic particles, it must agree with the relation\n\\begin{equation}\nE^2 = p^2 + 2m.\n\\end{equation}\nExpanding out the operators in the Dirac equation above,\n\\begin{align}\n\\hat{H}^2 &= \\left( \\alpha_i p_i + \\beta m \\right)\\left( \\alpha_j p_j + \\beta m \\right) \\nonumber \\\\\n&= \\alpha_i \\alpha_j p_i p_j + \\left\\{ \\alpha_i, \\beta \\right\\}p_i + \\beta^2 m^2.\n\\end{align}\nSo we see that the matrices $\\alpha_i$ and $\\beta$ have the constraints:\n\\begin{itemize}\n\\item $\\beta^2 = I_4$\n\\item $\\alpha_i \\alpha_j = \\delta_{ij} I_4$\n\\item $\\left\\{ \\alpha_i, \\beta \\right\\} = 0 \\quad \\Rightarrow \\quad \\alpha_i \\beta = - \\beta \\alpha_i$\n\\end{itemize}\nThis final constraint further requires that $\\alpha_i$ and $\\beta$ are all traceless:\n\\begin{align*}\n\\tr(\\alpha_i \\beta) &= -\\tr(\\beta \\alpha_i) \\\\\n\\tr(\\alpha_i \\beta^2) &= -\\tr(\\beta \\alpha_i \\beta) \\\\\n\\tr(\\alpha_i) &= -\\tr(\\beta^2 \\alpha_i) \\quad \\text{by cyclicity of the trace} \\\\\n&= -\\tr(\\alpha_i) = 0.\n\\end{align*}\nMoreover, we require that $\\alpha_i$ and $\\beta$ are Hermitian.\n\nThese constraints still allow for many different representations of the Dirac equation. A commonly used choice is\n\\begin{equation}\n\\alpha_i = \\mqty(\\admat[0]{\\sigma_i, \\sigma_i}), \\quad \\beta = \\mqty(\\dmat[0]{I_2, -I_2}).\n\\end{equation}\n\n\\subsection{Covariant form}\nUsing the Schr{\\\"o}dinger equation, express the Dirac equation in terms of differential operators\n\\begin{equation}\ni \\pdv{\\psi}{t} = -i \\vec{\\alpha}\\cdot\\vec{\\nabla}\\psi + \\beta m \\psi\n\\end{equation}\nand pre-multiply by $\\beta$,\n\\begin{equation}\ni \\beta \\pdv{\\psi}{t} = -i \\beta \\vec{\\alpha}\\cdot\\psi + \\beta^2 m \\psi.\n\\end{equation}\nNow we recognise that $\\beta^2=I_4$ and define the Dirac gamma matrices $\\gamma^0 = \\beta$, $\\gamma^k = \\beta\\alpha^k$. This gives\n\\begin{equation}\\boxed{\n\\left(i \\gamma^\\mu \\partial_\\mu - m \\right)\\psi = 0 \\label{eq:covDirac}\n}.\\end{equation}\nThis is the covariant form of the Dirac equation. Explicitly, the Dirac matrices are\n\\begin{align*}\n\\gamma^0 = \\mqty(\\dmat[0]{I_2,-I_2}), \\quad \\gamma^k = \\mqty(\\admat[0]{\\sigma^k, -\\sigma^k}).\n\\end{align*}\n\n\\subsection{Properties of the $\\gamma$ matrices}\nClearly $\\gamma^0$ is Hermitian,\n\\begin{equation}\n(\\gamma^0)^\\dagger = \\gamma^0\n\\end{equation}\nbut the $\\gamma^k$ are anti-Hermitian,\n\\begin{align}\n(\\gamma^k)^\\dagger &= (\\beta\\alpha^k)^\\dagger \\nonumber \\\\\n&= (\\alpha^k)^\\dagger \\beta^\\dagger \\nonumber \\\\\n&= \\alpha^k \\beta \\nonumber \\\\\n&= -\\beta \\alpha^k \\nonumber \\\\\n&= -\\gamma^k.\n\\end{align}\nAlso we have that\n\\begin{equation}\n(\\gamma^0)^2 = I_4\n\\end{equation}\nand\n\\begin{equation}\n(\\gamma^k)^2 = -I_4.\n\\end{equation}\nFinally, the anticommutator\n\\begin{equation}\n\\left\\{ \\gamma^0, \\, \\gamma^k \\right\\} = 0.\n\\end{equation}\n\nThese properties will prove useful in the following manipulations of the Dirac equation.\n\n\\section{Adjoint Dirac equation}\nTaking the Hermitian conjugate of \\eqref{eq:covDirac} and expanding out the space and time components,\n\\begin{equation}\n-i \\partial_0 {\\psi^\\dagger} \\gamma^0 + i \\partial_k {\\psi^\\dagger} \\gamma^k - m \\psi^\\dagger = 0.\n\\end{equation}\nNow multiply by $-\\gamma^0$ from the right and use $\\gamma^0\\gamma^k = -\\gamma^k\\gamma^0$,\n\\begin{equation}\ni \\partial_0 {\\psi^\\dagger} \\gamma^0 \\gamma^0 + i \\partial_k \\psi^\\dagger \\gamma^0 \\gamma^k + m\\psi^\\dagger \\gamma^0 = 0.\n\\end{equation}\nHere is it natural to identify the adjoint Dirac spinor,\n\\begin{equation}\\boxed{\n\\overline{\\psi} \\equiv \\psi^\\dagger \\gamma^0\n}\\end{equation}\nso the adjoint Dirac equation becomes\n\\begin{equation}\\boxed{\ni\\left(\\partial_\\mu \\overline{\\psi}\\right) \\gamma^\\mu + m \\overline{\\psi} = 0 \\label{eq:adjDirac}\n}\\end{equation}\n\n\\subsection{Conserved current}\nPre-multiply the standard Dirac equation, \\eqref{eq:covDirac}, by the adjoint spinor\n\\begin{equation}\ni \\overline{\\psi} \\gamma^\\mu \\left(\\partial_\\mu \\psi\\right) - m \\overline{\\psi}\\psi = 0\n\\end{equation}\nand post-mulitply the adjoint Dirac equation, \\eqref{eq:adjDirac}, by $\\psi$,\n\\begin{equation}\ni\\left(\\partial_\\mu\\overline{\\psi}\\right)\\gamma^\\mu \\psi + m\\overline{\\psi}\\psi = 0.\n\\end{equation}\nAdding these, we see that\n\\begin{equation}\n\\overline{\\psi} \\gamma^\\mu \\left(\\partial_\\mu \\psi\\right) + \\left(\\partial_\\mu\\overline{\\psi}\\right)\\gamma^\\mu \\psi = \\partial_\\mu\\left( \\overline{\\psi} \\gamma^\\mu \\psi \\right) = 0\n\\end{equation}\nwhere we can identify the 4-current density,\n\\begin{equation}\nj^\\mu = \\overline{\\psi} \\gamma^\\mu \\psi.\n\\end{equation}\nNow the probability density is given by\n\\begin{align*}\nj^0 &= \\overline{\\psi}\\gamma^0\\psi \\\\\n&= \\psi^\\dagger \\gamma^0 \\gamma^0 \\psi \\\\\n&= \\abs{\\psi}^2\n\\end{align*}\nwhich is always positive. Hence the Dirac equation avoids the negative probabilities we saw in the treatment of the Klein-Gordon equation.\n\nAs usual the electromagnetic charge-current density is given by $-e\\overline{\\psi}\\gamma^\\mu\\psi$ for electrons.\n\n\\section{Free particle solutions}\nConsider solutions of the form\n\\begin{equation}\n\\psi = u(p) \\, e^{-ipx}\n\\end{equation}\nwhere $u(p)$ is a 4-component spinor and $p$ and $x$ are understood to be 4-vectors.\n\nSubstituting this into the covariant form of the Dirac equation, \\eqref{eq:covDirac},\n\\begin{align}\n0 &= \\left( i \\gamma^\\mu \\partial_\\mu - m \\right) u(p) \\, e^{-ipx} \\nonumber \\\\\n&= \\left( \\gamma^\\mu p_\\mu - m \\right) u(p) \\, e^{-ipx}.\n\\end{align}\n\nNow define the Feynman slash notation, $\\fsl{p} \\equiv \\gamma^\\mu p_\\mu$. Solutions of the above equation are given by spinors $u(p)$ that satisfy\n\\begin{equation}\n(\\fsl{p} - m) u(p) = 0.\n\\end{equation}\n\nTo find these solutions, it is helpful to return to the original $\\alpha_i, \\beta$ matrices. Do this by expanding out the $\\fsl{p}$ and pre-multiplying by $\\gamma^0$:\n\\begin{align}\n\\gamma^0(\\fsl{p}-m) &= \\gamma^0 \\gamma^0 E - \\gamma^0 \\gamma^k p_k - \\gamma^0 m \\nonumber \\\\\n&= E - \\alpha^k p^k - \\beta m\n\\end{align}\nso we look for solutions of\n\\begin{equation}\n\\left( E - \\alpha^k p_k - \\beta m \\right) u(p) = 0.\n\\end{equation}\n\n\\subsection{Particles at rest}\nFor a particle at rest $p_k=0$ so we have to solve\n\\begin{equation}\n\\left(E - \\beta m \\right) u(p) = 0.\n\\end{equation}\nSolutions exist for\n\\begin{equation}\n\\mdet{\\dmat[0]{(E-m)I_2, -(E+m)I_2}} = 0\n\\end{equation}\nwhich has energy solutions $E = \\pm m$. We have not escaped the negative energy solutions after all! In fact, this leads to four distinct solutions for the spinor\n\\begin{equation}\nu_{1,2} = \\mqty(\\chi_\\pm \\\\ 0) , \\quad u_{3,4} = \\mqty(0 \\\\ \\chi_\\pm) \\quad \\text{where} \\quad \\chi_+ = \\mqty(1 \\\\ 0), \\quad \\chi_- = \\mqty(0 \\\\ 1). \\label{eq:solutionsAtRestDirac}\n\\end{equation}\nIt is simple to see that $u_{1,2}$ are associated with positive energy states and $u_{3,4}$ with negative energy states. Furthermore, the spinors $\\chi_\\pm$ correspond to particles with spin projections $\\pm \\frac{1}{2}$.\n\n\\subsection{Moving particle solutions}\nNow consider the case where $p_k \\neq 0$. This gives the eigenvalue problem\n\\begin{equation}\n\\left[ \\mqty(\\admat[0]{\\vec{\\sigma}, \\vec{\\sigma}}) \\cdot \\vec{p} + \\mqty(\\dmat[0]{I_2, I_2}m) \\right] \\mqty(u_A \\\\ u_B) = E \\mqty(u_A \\\\ u_B)\n\\end{equation}\nor the simultaneous equations\n\\begin{align}\nu_A &= \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E-m} \\, u_B \\\\\nu_B &= \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\, u_A.\n\\end{align}\nThere are still infinitely many solutions but $u_B$ is determined from $u_A$ or vice-versa. To agree with our choices for the spinor at rest, \\eqref{eq:solutionsAtRestDirac}, we choose that for positive energy solutions\n\\begin{equation}\nu_{1,2}(p) = \\mathcal{N} \\mqty(\\chi_\\pm \\\\ \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi_\\pm)\n\\end{equation}\nand for negative energies, $E = -\\abs{E} < 0$,\n\\begin{equation}\nu_{1,2}(p) = \\mathcal{N} \\mqty(-\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{\\abs{E}+m} \\chi_\\pm \\\\ \\chi_\\pm)\n\\end{equation}\n\n\\subsection{Antiparticles}\nSo far we have seen that there are four distinct solutions to the Dirac equation, accounting for each spin and positive and negative energy states. In keeping with the Feynman-Stueckelberg interpretation, we ought to demonstrate that the negative energy solutions of the Dirac equation correspond to the positron.\n\nThe full spinor states for the negative energy solutions are\n\\begin{align}\n\\psi &= u_{3,4}(p) \\, e^{-ipx} \\nonumber \\\\\n&= u_{3,4}(p) \\, \\exp[-i(Et - \\vec{p}\\cdot\\vec{x})] \\nonumber \\\\\n&= u_{3,4}(p) \\, \\exp[i(\\abs{E}t + \\vec{p}\\cdot\\vec{x})]\n\\end{align}\nso again the negative energy solution can be interpreted as a positive energy particle travelling backwards in time and space. Hence, we can write the spinor as\n\\begin{equation}\n\\phi = v_{1,2}(p) e^{-ipx}\n\\end{equation}\nwhere $v_{1,2}(p) = u_{4,3}(-p)$ and this describes a positive energy particle travelling forwards through time. Note that since what we have done is essentially a $CT$ (or equivalently $P$) transformation, the spin states are reversed such that\n\\begin{equation}\nv_1(p) = \\mathcal{N} \\mqty(\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi_- \\\\ \\chi_-)\n\\end{equation}\ncorresponds to a spin \\emph{up} positron, and\n\\begin{equation}\nv_2(p) = \\mathcal{N} \\mqty(\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi_+ \\\\ \\chi_+)\n\\end{equation}\ncorresponds to spin down.\n\n\\section{Orthogonality and normalisation}\nWithout loss of generality, consider electrons travelling along the $z$-axis. Then for a spin-up electron,\n\\begin{equation}\nu_1(p) = \\mathcal{N} \\mqty(1 \\\\ 0 \\\\ \\frac{p}{E+m} \\\\ 0)\n\\end{equation}\nand for spin-down\n\\begin{equation}\nu_2(p) = \\mathcal{N} \\mqty(0 \\\\ 1 \\\\ 0 \\\\ \\frac{-p}{E+m})\n\\end{equation}\n\nConsider two electron wavefunctions, $\\psi_1$, $\\psi_2$, with opposite spin. Their overlap is given by\n\\begin{equation}\n\\int \\psi_1^\\dagger \\psi_2 \\, \\dd[3]{\\vec{x}}.\n\\end{equation}\nNow\n\\begin{equation}\n\\psi_1^\\dagger \\psi_2 = \\mathcal{N}^* \\mathcal{N} \\, \\mqty(1, \\, 0, \\, \\frac{p}{E+m}, \\, 0) \\mqty(0 \\\\ 1 \\\\ 0 \\\\ \\frac{-p}{E+m}) = 0\n\\end{equation}\nand therefore the overlap is zero. This shows that the solutions to the Dirac equation are orthogonal.\n\nThe normalisation condition is given by\n\\begin{equation}\n2E = \\int_V \\psi_1^\\dagger \\psi_1 \\, \\dd[3]{\\vec{x}}.\n\\end{equation}\nFor a spin-up electron travelling along the $z$-axis,\n\\begin{align}\n\\psi_1^\\dagger \\psi_1 &= \\abs{\\mathcal{N}}^2 \\, \\mqty(1, \\, 0, \\, \\frac{p}{E+m}, \\, 0) \\mqty(1 \\\\ 0 \\\\ \\frac{p}{E+m} \\\\ 0) \\nonumber \\\\\n&= \\abs{\\mathcal{N}}^2 \\, \\left( 1+\\frac{p^2}{(E+m)^2} \\right) \\nonumber \\\\\n&= \\abs{\\mathcal{N}}^2 \\, \\left( 1+\\frac{E-m}{E+m} \\right) \\nonumber \\\\\n&= \\abs{\\mathcal{N}}^2 \\, \\frac{2E}{E+m}\n\\end{align}\nTherefore the normalisation condition gives\n\\begin{equation}\n2E = \\mathcal{N}^2 \\, \\frac{2E}{E+m} \\, V\n\\end{equation}\n\\begin{equation}\n\\Rightarrow \\quad \\mathcal{N} = \\sqrt{\\frac{E+m}{V}}\n\\end{equation}\nOften we will use $V=1$ for convenience.\n\n\\section{Helicity}\nWe would like a way to describe the spin of a Dirac particle that is consistent in time. Such a good quantum number must commute with the Dirac Hamiltonian, $\\hat{H}$, which the usual QM operator $\\hat{S}$ does not. To find a suitable operator, it is instructive to expand out the Hamiltonian. According to the Dirac equation,\n\\begin{align}\n\\hat{H} \\mqty(u_A \\\\ u_B) &= \\left( \\vec{\\alpha}\\cdot\\vec{p} + \\beta m \\right) \\mqty(u_A \\\\ u_B) \\nonumber \\\\\n&= \\mqty(m & \\vec{\\sigma}\\cdot\\vec{p} \\\\ \\vec{\\sigma}\\cdot\\vec{p} & -m)\\mqty(u_A \\\\ u_B)\n\\end{align}\nwhere it is to be understood that $m$ stands for $\\smqty(m & 0 \\\\ 0 & m)$. We see from the matrix form of the Dirac Hamiltonian that $\\vec{\\sigma}\\cdot\\vec{p}$ commutes with $\\hat{H}$ and hence there exists a corresponding conserved quantity.\n\n\\subsection{Helicity}\nDefine the helicity operator\n\\begin{equation}\\boxed{\nh \\equiv \\frac{1}{2} \\vec{\\sigma}\\cdot\\hat{\\vec{p}}\n}\\end{equation}\nwhere $\\hat{\\vec{p}} = \\vec{p}/\\abs{\\vec{p}}$. Notice that $\\vec{\\sigma}/2 = \\vec{S}$ so that $h = \\vec{S}\\cdot\\hat{\\vec{p}}$ is nothing but the projection of the particle's spin along its direction of travel.\n\nTo find the spectrum of helicities, we solve the eigenvalue problem for the matrix $\\frac{1}{2} \\vec{\\sigma}\\cdot\\hat{\\vec{p}}$. This is most easily done by writing out the momentum in polar coordinates:\n\\begin{equation}\n\\hat{\\vec{p}} = \\mqty(\\sin\\theta\\cos\\phi \\\\ \\sin\\theta\\sin\\phi \\\\ \\cos\\theta)\n\\end{equation}\nthen\n\\begin{equation}\n\\vec{\\sigma}\\cdot\\hat{\\vec{p}} = \\mqty(\\cos\\theta & \\sin\\theta \\, e^{-i\\phi} \\\\\n\\sin\\theta \\, e^{i\\phi} & -\\cos\\theta).\n\\end{equation}\nThis gives the eigenvalue problem,\n\\begin{equation}\n\\frac{1}{2} \\mqty(\\cos\\theta & \\sin\\theta \\, e^{-i\\phi} \\\\\n\\sin\\theta \\, e^{i\\phi} & -\\cos\\theta) \\mqty(u_A \\\\ u_B) = \\lambda \\mqty(u_A \\\\ u_B)\n\\end{equation}\nwhich has the characteristic equation\n\\begin{equation}\n-\\left( \\cos\\theta - 2\\lambda \\right) \\left( \\cos\\theta + 2\\lambda \\right) - \\sin^2\\theta = 0\n\\end{equation}\nwith solutions\n\\begin{equation}\n\\lambda_\\pm = \\pm\\frac{1}{2}.\n\\end{equation}\n\n\\section{The $\\gamma^5$ matrix}\\label{sec:gammaMatrix}\nDefine the useful $\\gamma^5$ matrix\n\\begin{equation}\n\\gamma^5 = i \\gamma^0 \\gamma^1 \\gamma^2 \\gamma^3.\n\\end{equation}\nIn the Dirac-Pauli representation, it takes the form\n\\begin{equation}\n\\gamma^5 = \\mqty(0 & I_2 \\\\ I_2 & 0)\n\\end{equation}\nwith the properties\n\\begin{align}\n(\\gamma^5)^\\dagger &= \\gamma^5 \\\\\n(\\gamma^5)^2 &= I_4 \\\\\n\\gamma^5 \\gamma^\\mu &= -\\gamma^\\mu \\gamma^5.\n\\end{align}\n\nNow consider the action of $\\gamma^5$ on a solution of the Dirac equation,\n\\begin{equation}\n\\gamma^5 \\mqty(u_A \\\\ u_B) = \\mqty(0 & I_2 \\\\ I_1 & 0) \\mqty(\\chi \\\\ \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi) = \\mqty(\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi \\\\ \\chi).\n\\end{equation}\nFor ultra-relativistic particles $m \\rightarrow 0$ and hence $\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\rightarrow \\vec{\\sigma}\\cdot\\hat{\\vec{p}}$. We also use the fact that $(\\vec{\\sigma}\\cdot\\hat{\\vec{p}})(\\vec{\\sigma}\\cdot\\hat{\\vec{p}}) = I_2$, as shown in \\eqref{eq:sigmaDotP2}.\n\\begin{align}\n\\gamma^5 \\mqty(u_A \\\\ u_B) &= \\mqty(\\left(\\vec{\\sigma}\\cdot\\hat{\\vec{p}}\\right) \\chi \\\\ \\chi) \\nonumber \\\\\n&= \\mqty(\\left(\\vec{\\sigma}\\cdot\\hat{\\vec{p}}\\right) \\chi \\\\ \\left(\\vec{\\sigma}\\cdot\\hat{\\vec{p}}\\right)^2 \\chi) \\nonumber \\\\\n&= \\vec{\\sigma}\\cdot\\hat{\\vec{p}} \\, \\mqty(\\chi \\\\ \\left(\\vec{\\sigma}\\cdot\\hat{\\vec{p}}\\right)\\chi) \\nonumber \\\\\n&= \\vec{\\sigma}\\cdot\\hat{\\vec{p}} \\, \\mqty(u_A \\\\ u_B).\n\\end{align}\nTherefore, in the limit where $m \\rightarrow 0$, the helicity operator becomes $h \\rightarrow {\\gamma^5/2}$.\n\nDefine the chiral projection operators,\n\\begin{equation}\nP_R = \\frac{1}{2}\\left( 1 + \\gamma^5 \\right), \\quad P_L = \\frac{1}{2}\\left( 1 - \\gamma^5 \\right).\n\\end{equation}\nIn the limit where $m \\rightarrow 0$, a helicity eigenstate corresponds to a chiral state -- i.e.~$h=1$ is a right-handed state. For small $m$, a helicity eigenstate will be mostly one chirality plus a small amount of the other.\n\n\\section{Completeness relations}\nThe completeness relations are used extensively in the evaluation of Feynman diagrams.\n\nSum over the spin states,\n\\begin{align}\n\\sum_{s=\\pm} u_s(p) \\, \\overline{u}_s(p) &= \\sum_{s=\\pm} (E+m) \\, \\mqty(\\chi_s \\\\ \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi_s) \\mqty(\\chi_s^\\dagger, \\, -\\frac{\\left(\\vec{\\sigma}\\cdot\\vec{p}\\right)^\\dagger}{E+m} \\chi_s^\\dagger) \\nonumber \\\\\n&= \\sum_{i=\\pm} (E+m) \\, \\mqty(\\chi_s \\chi_s^\\dagger & -\\frac{\\left(\\vec{\\sigma}\\cdot\\vec{p}\\right)^\\dagger}{E+m} \\chi_s \\chi_s^\\dagger \\\\ \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\chi_s \\chi_s^\\dagger & -\\frac{E-m}{E+m} \\chi_s \\chi_s^\\dagger)\n\\end{align}\nwhere for the bottom-right element we have used $(\\vec{\\sigma}\\cdot\\vec{p})^2 = \\abs{p}^2 = E^2 - m^2 = (E-m)(E+m)$.\n\nThe sum over spin states can be easily performed:\n\\begin{equation}\n\\sum_{i=\\pm} \\chi_s \\chi_s^\\dagger = \\mqty(1 \\\\ 0) \\mqty(1,\\, 0) + \\mqty(0 \\\\ 1) \\mqty(0,\\, 1) = \\mqty(\\dmat[0]{1,1}) = I_2\n\\end{equation}\nSo we have that\n\\begin{align}\n\\sum_{i=\\pm} u_s(p) \\, \\overline{u}_s(p) &= (E+m) \\, \\mqty(I_2 & -\\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} \\\\ \\frac{\\vec{\\sigma}\\cdot\\vec{p}}{E+m} & \\frac{m-E}{E+m}) \\nonumber \\\\\n&= \\mqty(E+m & -\\vec{\\sigma}\\cdot\\vec{p} \\\\ \\vec{\\sigma}\\cdot\\vec{p} & m-E) \\label{eq:spinSum}\n\\end{align}\n\nNow consider the matrix given by\n\\begin{align}\n\\fsl{p} + m &= \\gamma^\\mu p_\\mu + m \\\\\n&= \\mqty(E & 0 \\\\ 0 & -E) - \\mqty(0 & \\vec{\\sigma}\\cdot\\vec{p} \\\\ -\\vec{\\sigma}\\cdot\\vec{p} & 0) + \\mqty(\\dmat[0]{m,m}) \\nonumber \\\\\n&= \\mqty(E+m & -\\vec{\\sigma}\\cdot\\vec{p} \\\\ \\vec{\\sigma}\\cdot\\vec{p} & m-E) \\label{eq:pslash+m}\n\\end{align}\n\nComparing \\eqref{eq:spinSum} and \\eqref{eq:pslash+m} gives the completeness relation\n\\begin{equation}\\boxed{\n\\sum_{i=\\pm} u_s(p) \\, \\overline{u}_s(p) = \\fsl{p} + m \\label{eq:completeness}\n}.\\end{equation}\n\nSimilarly for antiparticles,\n\\begin{equation}\n\\sum_{i=\\pm} v_s(p) \\, \\overline{v}_s(p) = \\fsl{p} - m.\n\\end{equation}\n\n\\section{Forms of interaction in Dirac theory}\n\\textbf{Scalar} (even parity): $\\overline{\\psi} \\psi$\n\n\\textbf{Pseudoscalar} (odd parity): $\\overline{\\psi} \\gamma^5 \\psi$\n\n\\textbf{Polar vector} (odd parity): $\\overline{\\psi} \\gamma^\\mu \\psi$. Fermi $\\beta$ decay is described by a polar vector current.\n\n\\textbf{Axial vector} (even parity): $\\overline{\\psi}\\gamma^5 \\gamma^\\mu \\psi$. The weak interaction is a mixture of polar and axial vector interactions.\n\n\\textbf{Tensor}: $\\overline{\\psi}\\sigma^{\\mu\\nu} \\psi$. This type of interaction has not been observed by experiment, although does provide a description of the mechanism behind the anomalous magnetic moment. Spin-2 gravitons would have interactions of this form.\n\n\\section{Trace theorems}\\label{sec:Trace}\nIn scattering problems, we will often see calculations involving the traces of $\\gamma$-matrices. What follows will simplify these calculations with some algebraic results.\n\nWe start with the facts that traces are associative:\n\\begin{equation}\n\\Tr(A+B) \\equiv \\Tr(A) + \\Tr(B)\n\\end{equation}\nand are unchanged by cyclic permutations of the argument:\n\\begin{equation}\n\\Tr(AB \\ldots YZ) \\equiv \\Tr(ZAB \\ldots Y).\n\\end{equation}\n\nAlso the algebra of the $\\gamma$-matrices is defined by their anticommutation relation,\n\\begin{equation}\n\\gamma^\\mu \\gamma^\\nu + \\gamma^\\nu \\gamma^\\mu = 2g^{\\mu\\nu} I_4 \\label{eq:gammaAnticommute}\n\\end{equation}\nwhere the presence of the identity has been made explicit. Taking the trace,\n\\begin{equation}\n\\Tr(\\gamma^\\mu \\gamma^\\nu) + \\Tr(\\gamma^\\nu \\gamma^\\mu) = 2g^{\\mu\\nu} \\Tr(I_4)\n\\end{equation}\nand using the cyclicity of the trace,\n\\begin{equation}\\boxed{\n\\Tr(\\gamma^\\mu \\gamma^\\nu) = 4g^{\\mu\\nu} \\label{eq:trace2}\n}.\\end{equation}\n\nThe trace of any odd number of $\\gamma$-matrices can be shown to be zero by inserting $\\gamma^5 \\gamma^5 = I_4$ into the trace. For example,\n\\begin{align}\n\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho) &= \\Tr(\\gamma^5 \\gamma^5 \\gamma^\\mu \\gamma^\\nu \\gamma^\\rho) \\nonumber \\\\\n&= \\Tr( \\gamma^5 \\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^5) \\nonumber \\\\\n&= -\\Tr(\\gamma^5 \\gamma^5 \\gamma^\\mu \\gamma^\\nu \\gamma^\\rho)\n\\end{align}\nwhere the last line is reached by commuting the last $\\gamma^5$ through three $\\gamma$-matrices, each time introducing a factor $-1$. Hence we have that $\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho) = -\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho)$ which can only be true for\n\\begin{equation}\\boxed{\n\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho) = 0\n}.\\end{equation}\nThis is easily extended to the case for any odd number of $\\gamma$-matrices.\n\nThe trace of four $\\gamma$-matrices can be obtained using \\eqref{eq:gammaAnticommute}:\n\\begin{align}\n\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^\\sigma &= \\left( 2g^{\\mu\\nu} - \\gamma^\\nu \\gamma^\\mu \\right) \\gamma^\\rho \\gamma^\\sigma \\nonumber \\\\\n&= 2g^{\\mu\\nu}\\gamma^\\rho\\gamma^\\sigma - 2g^{\\mu\\rho}\\gamma^\\nu\\gamma^\\sigma + \\gamma^\\nu\\gamma^\\rho\\gamma^\\mu\\gamma^\\sigma \\nonumber \\\\\n&= 2g^{\\mu\\nu}\\gamma^\\rho\\gamma^\\sigma - 2g^{\\mu\\rho}\\gamma^\\nu\\gamma^\\sigma + 2g^{\\mu\\sigma}\\gamma^\\nu\\gamma^\\rho - \\gamma^\\nu\\gamma^\\rho\\gamma^\\sigma\\gamma^\\mu\n\\end{align}\nHence,\n\\begin{equation}\n\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^\\sigma) = g^{\\mu\\nu}\\Tr(\\gamma^\\rho\\gamma^\\sigma) - g^{\\mu\\rho}\\Tr(\\gamma^\\nu\\gamma^\\sigma) + g^{\\mu\\sigma}\\Tr(\\gamma^\\nu \\gamma^\\rho)\n\\end{equation}\nEvaluating the traces with \\eqref{eq:trace2} gives the result\n\\begin{equation}\\boxed{\n\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^\\sigma) = 4g^{\\mu\\nu}g^{\\rho\\sigma} - 4g^{\\mu\\rho}g^{\\nu\\sigma} + 4g^{\\mu\\sigma}g^{\\nu\\rho}\n}\\end{equation}\n\nThe full set of trace theorems is:\n\\begin{itemize}\n\\item $\\Tr(I_4) = 4$;\n\\item the trace of any odd number of $\\gamma$-matrices is zero;\n\\item $\\Tr(\\gamma^\\mu \\gamma^\\nu) = 4g^{\\mu\\nu}$;\n\\item $\\Tr(\\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^\\sigma) = 4g^{\\mu\\nu}g^{\\rho\\sigma} - 4g^{\\mu\\rho}g^{\\nu\\sigma} + 4g^{\\mu\\sigma}g^{\\nu\\rho}$;\n\\item the trace of $\\gamma^5$ multiplied by an odd number of $\\gamma$-matrices is zero;\n\\item $\\Tr(\\gamma^5) = 0$;\n\\item $\\Tr(\\gamma^5 \\gamma^\\mu \\gamma^\\nu) = 0$; and\n\\item $\\Tr(\\gamma^5 \\gamma^\\mu \\gamma^\\nu \\gamma^\\rho \\gamma^\\sigma) = 4i \\varepsilon^{\\mu\\nu\\rho\\sigma}$, where $\\varepsilon^{\\mu\\nu\\rho\\sigma}$ is the antisymmetric tensor under the exchange of any two indices.\n\\end{itemize}\n", "meta": {"hexsha": "1b7e0d7012b6d5db3f222c4db67e4eec6f367fff", "size": 23804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/9_Relativistic_Spin-half_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/9_Relativistic_Spin-half_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/9_Relativistic_Spin-half_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": 48.3821138211, "max_line_length": 326, "alphanum_fraction": 0.676650983, "num_tokens": 8600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6087689787444416}}
{"text": "%!TEX root =  ../main.tex\n\n\\mychapters{Triangles}{triangles}{\\chapdir/pics/Northern_lights_in_Greenland} \n\nAmazingly, the trigonometric functions defined by right-triangles are\nmeaningful on non-right triangles.  The Pythagorean theorem is actually\njust a special case of the Law of Cosines.  Triangles, it seems, are the\nbuilding blocks of the universe.\n\nWhy are triangles so productive?  What is so special about triangles?\nIs there another shape with such descriptive power?\n\n\\newpage\n\\chapterminitoc\n\n\n%\t\t\t\t\t\t\t\t\t11 - 1\n\\newpage\n\\section{Area Formulae}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch11/1101p.pdf}}\n\\subsection{Sine Formulae}\nEvery child with any years under his or her belt in school knows that the area of a triangle is\n$\\frac{1}{2}bh$.  But what if we don't know $h$, the height?  It turns out, other information\nis just as good.\n\nConsider a triangle with side $b$ on the bottom.  For convenience's sake, we will put angle\nA on the left, angle C on the right, and have angle B above.  If we drop an altitude from angle\nC onto side $b$, we have $h$, and have bisected ABC into two right triangles.  We see,\ntherefore, that $\\sin A = \\frac{h}{c}$ and that $\\sin C = \\frac{h}{a}$.  Solving both equations\nfor $h$, we see that $h = c \\cdot \\sin A = a \\cdot \\sin C$.  If we don't know $h$ and we want to\nfind the area, we can substitute in either of these expressions.  This procedure would also have\nworked for the other rotations of triangle ABC.\n\n\\begin{equation}\n\\text{the area of triangle ABC} = \\frac{1}{2} a \\cdot b \\cdot \\sin C = \\frac{1}{2} a \\cdot \\sin B \\cdot c = \\frac{1}{2} \\sin A \\cdot b \\cdot \\sin C\n\\end{equation}\n\n\\subsection{Heron's Formula}\nWhile the proof is very lengthy, the ancient Greek mathematician Hero proved that the area of a \ntriangle is related to itself \\textbf{semi-perimeter}, that is, half the total length around the outside.\nIf we have some triangle with sides $a$, $b$, and $c$, then $s = \\frac{a + b + c}{2}$.  \n\n\\begin{equation}\n\\text{the area of a triangle ABC} = \\sqrt{s(s-a)(s-b)(s-c)}\n\\end{equation}\n\n\\newpage\n\\subsection{Exercises}\nTo be done in Kuta\n\n\n%\t\t\t\t\t\t\t\t\t11 - 2\n%\\newpage\n\\invisiblesection{Law of Cosines}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch11/1102p.pdf}}\n\\newpage\n\\subsection{SSS}\n\\subsection{SAS}\n\\newpage\n\\subsection{Exercises}\nto be done in kuta\n\n%\t\t\t\t\t\t\t\t\t11 - 3\n\\newpage\n\\invisiblesection{Law of Sines}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch11/1103p.pdf}}\n\\newpage\n\\subsection{Imagining the Height}\n\\subsection{SAA}\n\\subsection{ASA}\n\\newpage\n\\subsection{Exercises}\nto be done in kuta\n\n%\t\t\t\t\t\t\t\t\t11 - 4\n\\newpage\n\\invisiblesection{The Ambiguous Case}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch11/1104p.pdf}}\n\\newpage\n\\subsection{SSA}\n\\subsection{Related Rates}\n\\subsection{Exercises}\nto be done in kuta\n\n\n%\t\t\t\t\t\t\t\t\t11 - 5\n\\newpage\n\\invisiblesection{2D Vectors}\n\\subsection{Problems}\n\\noindent\\makebox[\\textwidth]{\\includegraphics[width=\\paperwidth]{ch11/1105p.pdf}}\n\\newpage\n\\subsection{Definition and Magnitude}\nVectors have a length, called their magnitude, written with absolute value bars.\n\\index{Absolute Value!of vectors}\n\\subsection{Vector Components}\n\\subsection{Heading and Bearing}\n\\newpage\n\\subsection{Exercises}\nto be done in kuta\n\n%\t\t\t\t\t\t\t\t\t11 - 6\n\\newpage\n\\section{Review}\n\\subsection{Chapter Review}\n\\subsection{Chapter Test}", "meta": {"hexsha": "f9c248d7521c5644531e129a714c367ab235cc0e", "size": 3491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch11/1100.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": "ch11/1100.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": "ch11/1100.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.3240740741, "max_line_length": 147, "alphanum_fraction": 0.7384703523, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6086981822559628}}
{"text": "\\section{M/M/1 Queues}\n\\label{sec:M-M-1-queues}\n\nA $M/M/1$ is a queue where \n(i) the arrival process is Poissonian with rate $\\lambda$,\n(ii) the service process is Exponential with rate $\\mu$,\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-M-1-queue}\t\n%\t\\centering\n%\t\\includegraphics{fig/M-M-1-Queue}\n%\t\\caption{An M/M/1 queue and its corresponding CTMC.}\n%\\end{figure}\n\t\n\\begin{theorem}[State Probability]\n\\label{thm:M-M-1-probability-state}\t\n\tFor any $M/M/1$, the state probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-1-probability-state}\n\t\\pi_{i} = \\varrho^{i}(1-\\varrho)\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 258-259.\n\t\\end{proof}\n\\end{theorem}\n\n\\begin{theorem}[Mean System Jobs]\n\\label{thm:M-M-1-System-Jobs}\t\n\tFor any $M/M/1$, the expected number of jobs is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-1-System-Jobs}\n\t\\expected{N} = \\frac{\\varrho}{(1-\\varrho)}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\t\\begin{equation*}\n\t\t\\expected{N} = \\sum_{i=0}^{\\infty} i \\pi_{i} = \\frac{\\varrho}{(1-\\varrho)}\n\t\t\\end{equation*}\n\t\\end{proof}\n\\end{theorem}\n\nThe remaining metrics ($\\expected{N_{Q}},\\expected{T},\\expected{T_{Q}}$) could be determined by applying the Little's Law, the basic definitions \n$\\expected{N}=\\expected{N_{Q}}+\\expected{N_{S}}$, \n$\\expected{N_{S}}=\\varrho$, \n$\\expected{T}=\\expected{T_{Q}}+\\expected{T_{S}}$, and\n$\\expected{T_{S}}=\\frac{1}{\\mu}$.\n\nIn particular we obtain:\n\n\\begin{equation}\n\\label{eqn:M-M-1-Queue-Jobs}\n\\expected{N_{Q}} = \\frac{\\varrho^{2}}{(1-\\varrho)}\n\\end{equation}\n\n\\begin{equation}\n\\label{eqn:M-M-1-Delay}\n\\expected{T_{Q}} = \\frac{1}{\\mu} \\cdot \\frac{\\varrho}{(1-\\varrho)}\n\\end{equation}\n\n\\begin{equation}\n\\label{eqn:M-M-1-Response-Time}\n\\expected{T} = \\frac{1}{\\mu - \\lambda}\n\\end{equation}", "meta": {"hexsha": "c9ec2decd84b342b00d0c66c4b56918665568676", "size": 1875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-m-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-m-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-m-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": 27.1739130435, "max_line_length": 145, "alphanum_fraction": 0.6757333333, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.803173801068221, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6086405943914445}}
{"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 XIX 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{Vector Fields $-$ 16.1}\n\nIf the region $D$ lies in $\\mathbb{R}^2$, then the function for the field is as follows:\n\n$$\\bold{\\bar{F}}(x,y)=P(x,y)\\bold{\\hat{i}}+Q(x,y)\\bold{\\hat{j}}$$\n\nIf $D$ lies in $\\mathbb{R}^3$:\n\n$$\\bold{\\bar{F}}(x,y)=P(x,y)\\bold{\\hat{i}}+Q(x,y)\\bold{\\hat{j}}+R(x,y)\\bold{\\hat{k}}$$\n\nThe formula for Newton's law of gravitation is as follows:\n\n$$|\\bold{\\bar{F}}|=\\frac{GmM}{r^2}$$\n\nThis may be transformed into a vector field by using the following steps:\n\n$$|\\bold{\\bar{F}}|=\\frac{GmM}{r^2}$$\n$$|\\bold{\\bar{F}}|=\\frac{GmM}{r^3}\\bold{\\hat{r}}$$\n$$\\bold{\\hat{r}}=\\langle x, y, z\\rangle,\\,r=\\sqrt{x^2+y^2+z^2}$$\n$$|\\bold{\\bar{F}}|=\\frac{GmMx\\bold{\\hat{i}}}{(x^2+y^2+z^2)^{\\frac{3}{2}}}+\\frac{GmMy\\bold{\\hat{j}}}{(x^2+y^2+z^2)^{\\frac{3}{2}}}+\\frac{GmMz\\bold{\\hat{k}}}{(x^2+y^2+z^2)^{\\frac{3}{2}}}$$\n\nCalling back to the gradient, which is written as $\\nabla f(x,y)=\\frac{\\partial f}{\\partial x}\\bold{\\hat{i}} + \\frac{\\partial f}{\\partial y}\\bold{\\hat{j}}$, where $f(x,y)$ is a scalar function. This may be used in conjunction with vector fields.\\\\\n\nAny vector field which has $\\bold{\\bar{F}}=\\nabla f$ is called a conservative vector field. In such a case, $f$ is called a potential function for $\\bold{\\bar{F}}$ \n\n\\textit{In Physics:}\nNewton's formula for gravitation is a conservative vector field.\nIn addition to this, the potential function, $f$, for conservative vector fields was used to find potential electrical and magnetic field, in addition to the aforementioned gravitational field.\n\n\n\\section{Line Integrals $-$ 16.2}\n\nA line integral may be found using the formula:\n\n$$\\int_C f(x,y)\\,ds$$\n\nAs used in an earlier chapter, $ds=\\sqrt{(\\frac{dx}{dt})^2+(\\frac{dy}{dt})^2}$\n\nTherefore, the line integral may be found by using:\n\n$$\\int_C f(x,y)\\,ds=\\int_a^b f(x(t),y(t)) \\sqrt{\\left(\\frac{dx}{dt}\\right)^2+\\left(\\frac{dy}{dt}\\right)^2}\\,dt$$\n\nMuch like any other integral, when applied to a piecewise function, the integral may be broken up:\n\n$$\\int_C f(x,y)\\,ds=\\int_{C_1} f(x,y)\\,ds+\\int_{C_2} f(x,y)\\,ds+\\int_{C_3} f(x,y)\\,ds+\\dots \\int_{C_n} f(x,y)\\,ds+$$\n\n\\end{document}\n", "meta": {"hexsha": "ace6ab0924230398d6325415b948c2a2012770b2", "size": 3532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture Notes/Lecture19.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/Lecture19.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/Lecture19.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": 34.6274509804, "max_line_length": 247, "alphanum_fraction": 0.5985277463, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6086405926063387}}
{"text": "\\documentclass[]{article}\n\\usepackage{amsmath}\n\\usepackage[a4paper]{geometry}\n\\usepackage{graphicx}\n\\usepackage{microtype}\n\\usepackage{siunitx}\n\\usepackage{booktabs}\n\\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}\n\\usepackage{cleveref}\n\\usepackage{caption}\n\\usepackage{subcaption}\n\\usepackage{float}\n\n\\begin{document}\n\n\\title{Regularized Optimization}\n\\author{Dun Wang}\n\\maketitle\n\n\\section{L2 Regularization}\n\nIn PLM, we need to do the L2 form regularized optimization as following:\n\n\\begin{align*}\n  I_{mn}^{*}=\\sum_{m' \\in M_{m}} a_{mnm'}I_{m'n'}\n\\end{align*}\n\n\\begin{align*}\n  \\chi^2_{mn}    = \\sum_{n'\\in{N}_n} \\frac{[I_{mn'} - I^{\\ast}_{mnn'}]^2}{\\sigma^2_{mn'}} \n\t\t+ \\sum_{m'\\in{M}_m} \\frac{a_{mnm'}^2}{\\Sigma^2}\n\\end{align*}\n\\\\\nwhere $\\sum_{m' \\in {M}_m} \\frac{a_{mnm'}^2}{\\Sigma^2}$ is the L2 regularization term and $\\frac{1}{\\Sigma^2}$ is the regularization strength\n\n\n\\section{Linear Algerbra}\nTake derivative to the $\\chi^2$ equation with respect to $a_{mnk}$,  we can get the normal equation with L2 regualrization:\n \n\\begin{align*}\n  0   = \\sum_{n'\\in{N}_n} \\frac{1}{\\sigma^2_{mn'}}[I_{mn'} -  \\sum_{m'\\in{M}_m}a_{mnm'}I_{m'n'}]I_{kn'}\n                 + \\sum_{m'\\in{M}_m} \\frac{a_{mnk}}{\\Sigma^2}\n\\end{align*}\n\\\\\nwhere $k \\in{M}_m$\n\\\\\n\\\\\nConstruct the matrix:\n\\\\\n\\begin{align*}\nA=\n \\begin{pmatrix}\n  I_{1,1} & I_{1,2} & \\cdots & I_{1,m'} \\\\\n  I_{2,1} & I_{2,2} & \\cdots & I_{2,m'} \\\\\n  \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n  I_{n,1} & I_{n,2} & \\cdots & I_{n,m'}\n \\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\nC = \n \\begin{pmatrix}\n  \\sigma^2_{1,1} & 0 & \\cdots & 0 \\\\\n  0 & \\sigma^2_{2,2} & \\cdots & 0 \\\\\n  \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n  0 & 0& \\cdots & \\sigma^2_{n,n}\n \\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\nY = \n \\begin{pmatrix}\n  I_{1,1} & I_{1,2} & \\cdots & I_{1,m}\\\\\n  I_{2,1} & I_{2,2} & \\cdots & I_{2,m} \\\\\n  \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n  I_{n,1}& 0& \\cdots & I_{n,m}\n \\end{pmatrix}\n\\end{align*}\n\n\\begin{align*}\nX=\n \\begin{pmatrix}\n  a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\\n  a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\\n  \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n  a_{m',1} & a_{m',2} & \\cdots & a_{m',n}\n \\end{pmatrix}\n\\end{align*}\n\\\\\nThe equation is equivalent to:\n\\begin{align*}\n(A^TC^{-1}A+\\frac{1}{\\Sigma^2}I)X &= A^TC^{-1}Y\n\\end{align*}\n\\\\\nSolve the linear system above, we can get the regularized optimization parameter set:\n\\begin{align*}\nX &=(A^TC^{-1}A+\\frac{1}{\\Sigma^2}I)^{-1} A^TC^{-1}Y\n\\end{align*}\n\n\n\\end{document}\n", "meta": {"hexsha": "cb01e337b9613fb9597e53423545ff8bf2b63e34", "size": 2487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/notes/notes/regularization.tex", "max_stars_repo_name": "jvc2688/cpm", "max_stars_repo_head_hexsha": "409e9ada39fc6238a63a75fb8474a3af70410347", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-08-13T19:26:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-08-13T19:26:23.000Z", "max_issues_repo_path": "documents/notes/notes/regularization.tex", "max_issues_repo_name": "jvc2688/cpm", "max_issues_repo_head_hexsha": "409e9ada39fc6238a63a75fb8474a3af70410347", "max_issues_repo_licenses": ["MIT"], "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/notes/notes/regularization.tex", "max_forks_repo_name": "jvc2688/cpm", "max_forks_repo_head_hexsha": "409e9ada39fc6238a63a75fb8474a3af70410347", "max_forks_repo_licenses": ["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.6237623762, "max_line_length": 141, "alphanum_fraction": 0.5987133092, "num_tokens": 1081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7401743735019594, "lm_q1q2_score": 0.6085633245842054}}
{"text": "\\subsection{Sensitivity Test}\nBased on the analysis above, we modify the Multi-groups Logistic Model.\n\\begin{equation}\n  \\begin{cases}\n    \\frac{1}{N_x(t)}\\frac{dN_x(t)}{dt} = r_x(t)(1-\\frac{N_x(t)}{{{N'}_x}_{max}} - RGB_x\\frac{N_y(t)}{{{N'}_y}_{max}}) \\\\ \\\\\n    \\frac{1}{N_y(t)}\\frac{dN_y(t)}{dt} = r_y(t)(1-\\frac{N_y(t)}{{{N'}_y}_{max}} - RGB_y\\frac{N_x(t)}{{{N'}_x}_{max}})\n  \\end{cases}\n\\end{equation}\n\\par\nWe take $F_A$ and $F_B$ as examples to analyze the sensitivity of our model when environment fluctuates rapidly. Because they are all drought-tolerant fungi, when rapid fluctuations in the environment have an adverse effect, they will appear as heavy precipitation in a short period of time. We artificially set rapid fluctuations in the environment on the fifth day and draw curve figure of $N_A'(t)$ and $N_B'(t)$ as follows.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=\\textwidth]{figures/A&B_sen.png}\n  \\caption{Curves of $N_A'(t)$ and $N_B'(t)$.}\n\\end{figure}\n\\par\nFrom the above figure, it is found that the fungal population maintained an exponential growth in the first $5$ days. After rapid environmental fluctuations occurred on the $5th$ day, the populations of $F_A$ and $F_B$ both declined significantly. Around the $11th$ day, the population began to increase. After $20$ days, the populations of $F_A$ and $F_B$ both stabilized, at $713$ and $439$, respectively. Compared with the stable fungal population of $F_A$ and $F_B$ without the influence of rapid environmental fluctuations, the values have dropped by $10.4\\%$ and $15.9\\%$, respectively.\n\\par\nTherefore, when rapid environmental fluctuations occur, the \\textbf{advanced Multi-groups Logistic Model} could well reflect the influence of harsh environments on the growth and reproduction of fungi, which shows that the model has \\textbf{good sensitivity}.", "meta": {"hexsha": "2b23fe0369381d89b1dc0c3f832d70d28111afa2", "size": 1850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/2.tex", "max_stars_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_stars_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-07T14:38:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T10:37:34.000Z", "max_issues_repo_path": "5/2.tex", "max_issues_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_issues_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_issues_repo_licenses": ["MIT"], "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/2.tex", "max_forks_repo_name": "syy11cn/2021-mcm-meritorious-article", "max_forks_repo_head_hexsha": "3eaf143f4319fae681d98134bfc7e699833d8273", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 97.3684210526, "max_line_length": 592, "alphanum_fraction": 0.7389189189, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6085633168969136}}
{"text": "\\section*{Introduction}\nOur algorithm is composed by two main stages:\n\\begin{itemize}\n\\item Find a feasible solution.\n\\item Optimize the feasible solution found in the previous stage.\n\\end{itemize}\n\nIn order to improve the diversification of the algorithm and to explore as much as possible the solution space, we run several parallel threads and finally we choose the best of the provided solutions.\n\n\\section*{Feasibile solution search}\nIn our approach, we combine a greedy strategy with a taboo list which stores the ``bad'' couples timeslot, exam.\n\nStarting from a random order of exams, we assign each one to the first timeslot where it does not conflict with any other exam. At the end of this loop, it is highly probable that some exams are not inserted in any timeslot.\n\nHence, we start a loop that continues until all exams are correctly assigned. In this loop we exploit the following algorithm:\n\\begin{enumerate}\n\\item Check if a mutation is needed and mutate consequently.\n\\item For each unassigned exam:\n\\begin{enumerate}\n\\item Search the timeslot with the smallest number of conflicts and where the exam is not taboo.\n\\item Assign the exam to it.\n\\item Remove all the exams in conflict with the added exam and mark the couple timeslot, exam as taboo.\n\\end{enumerate} \n\\item If the number of unassigned exams is lower than the minimum number found so far, update it.\n\\item If the number of conflicts is lower than the minimum number found so far, update it.\n\\end{enumerate}\nThe size of the taboo list is a critical parameter. A large value would store a large number of forbidden couples timeslot, exam making the timeslot choice a difficult operation, while a small value would force a behavior similar to a steepest descent, which conduces to an unfeasible solution. After several attempts, we notice that a good empiric size is 100.\n\nA constant mutation frequency would enforce a strongly modification of an almost feasible solution into a worse one or it may mutate too low frequently. Hence, we adopted for a dynamic approach that changes the control value according to the quality of the current solution.\n\\paragraph*{Mutation}\nFor each taken exam:\n\\begin{enumerate}\n\\item Search the timeslots where the exam does not conflict and where the move is not taboo.\n\\item Move the exam in a random timeslot among the selected ones and mark the couple timeslot, exam as taboo.\n\\end{enumerate}", "meta": {"hexsha": "107c4e15e2244c5a90b195ad2d8e7d6838b18cc3", "size": 2404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/feasible.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": "Report/feasible.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": "Report/feasible.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": 68.6857142857, "max_line_length": 361, "alphanum_fraction": 0.7974209651, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6085633151594981}}
{"text": "\\chapter{Introduction}\n\nI remind some definitions from volume~1~\\cite{volume-1}.\n\nI denote a set definition like $\\setcond{x\\in A}{P(x)}$ instead of customary\n$\\{ x\\in A \\mid P(x) \\}$ (in order to reduce formulas size).\n\nI denote partial order as~$\\sqsubseteq$. I denote lattice operations as\n$\\bigsqcap$, $\\bigsqcup$, $\\sqcap$,~$\\sqcup$.\n\nThe following generalizes monovalued morphisms in category~$\\mathbf{Rel}$.\n\nLet $\\Hom$-sets be complete lattices.\n\\begin{defn}\n\\index{morphism!metamonovalued}A morphism $f$ of a partially ordered\ncategory is \\emph{metamonovalued} when $\\left(\\bigsqcap G\\right)\\circ f=\\bigsqcap_{g\\in G}(g\\circ f)$\nwhenever $G$ is a set of morphisms with a suitable source and destination.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!metainjective}A morphism $f$ of a partially ordered\ncategory is \\emph{metainjective} when $f\\circ\\left(\\bigsqcap G\\right)=\\bigsqcap_{g\\in G}(f\\circ g)$\nwhenever $G$ is a set of morphisms with a suitable source and destination.\\end{defn}\n\\begin{obvious}\nMetamonovaluedness and metainjectivity are dual to each other.\\end{obvious}\n\\begin{defn}\n\\index{morphism!metacomplete}A morphism $f$ of a partially ordered\ncategory is \\emph{metacomplete} when $f\\circ\\left(\\bigsqcup G\\right)=\\bigsqcup_{g\\in G}(f\\circ g)$\nwhenever $G$ is a set of morphisms with a suitable source and destination.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!co-metacomplete}A morphism $f$ of a partially ordered\ncategory is \\emph{co-metacomplete} when $\\left(\\bigsqcup G\\right)\\circ f=\\bigsqcup_{g\\in G}(g\\circ f)$\nwhenever $G$ is a set of morphisms with a suitable source and destination.\n\\end{defn}\nLet now $\\Hom$-sets be meet-semilattices.\n\\begin{defn}\n\\index{morphism!weakly metamonovalued}A morphism $f$ of a partially\nordered category is \\emph{weakly metamonovalued} when $(g\\sqcap h)\\circ f=(g\\circ f)\\sqcap(h\\circ f)$\nwhenever $g$ and $h$ are morphisms with a suitable source and destination.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!weakly metainjective}A morphism $f$ of a partially\nordered category is \\emph{weakly metainjective} when $f\\circ(g\\sqcap h)=(f\\circ g)\\sqcap(f\\circ h)$\nwhenever $g$ and $h$ are morphisms with a suitable source and destination.\n\\end{defn}\nLet now $\\Hom$-sets be join-semilattices.\n\\begin{defn}\n\\index{morphism!weakly metacomplete}A morphism $f$ of a partially\nordered category is \\emph{weakly metacomplete} when $f\\circ(g\\sqcup h)=(f\\circ g)\\sqcup(f\\circ h)$\nwhenever $g$ and $h$ are morphisms with a suitable source and destination.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!weakly co-metacomplete}A morphism $f$ of a partially\nordered category is \\emph{weakly co-metacomplete} when $(g\\sqcup h)\\circ f=(g\\circ f)\\sqcup(h\\circ f)$\nwhenever $g$ and $h$ are morphisms with a suitable source and destination.\\end{defn}\n\\begin{obvious}\n~\n\\begin{enumerate}\n\\item Metamonovalued morphisms are weakly metamonovalued.\n\\item Metainjective morphisms are weakly metainjective.\n\\item Metacomplete morphisms are weakly metacomplete.\n\\item Co-metacomplete morphisms are weakly co-metacomplete.\n\\end{enumerate}\n\\end{obvious}\n\n\\begin{defn}\n\\index{morphism!monovalued}For a partially ordered dagger category\nI will call \\emph{monovalued} morphism such a morphism $f$ that $f\\circ f^{\\dagger}\\sqsubseteq1_{\\Dst f}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!entirely defined}For a partially ordered dagger category\nI will call \\emph{entirely defined} morphism such a morphism $f$\nthat $f^{\\dagger}\\circ f\\sqsupseteq1_{\\Src f}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!injective}For a partially ordered dagger category\nI will call \\emph{injective} morphism such a morphism $f$ that $f^{\\dagger}\\circ f\\sqsubseteq1_{\\Src f}$.\n\\end{defn}\n\n\\begin{defn}\n\\index{morphism!surjective}For a partially ordered dagger category\nI will call \\emph{surjective} morphism such a morphism f that $f\\circ f^{\\dagger}\\sqsupseteq1_{\\Dst f}$.\\end{defn}\n\\begin{rem}\nIt is easy to show that this is a generalization of monovalued, entirely\ndefined, injective, and surjective functions as morphisms of the category\n$\\mathbf{Rel}$.\\end{rem}\n\\begin{obvious}\n``Injective morphism'' is a dual of ``monovalued morphism'' and\n``surjective morphism'' is a dual of ``entirely defined morphism''.\\end{obvious}\n\n", "meta": {"hexsha": "dfef76eb9673096a8a66c8588c107d47d6c06e1f", "size": 4219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-v2intro.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-v2intro.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-v2intro.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "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": 43.4948453608, "max_line_length": 114, "alphanum_fraction": 0.757999526, "num_tokens": 1394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6085633104471444}}
{"text": "\\lab{Discrete Hidden Markov Models}{Discrete Hidden Markov Models}\n\\label{lab:hmm}\n\\objective{Understand how to use discrete Hidden Markov Models.}\n\nGiven a discrete state-space Hidden Markov Model (HMM) with parameters $\\lambda$ and an observation sequence $O$, we would like to answer three questions:\n\\begin{enumerate}\n \\item What is $\\mathbb{P}(O |\\, \\lambda)$? In other words, what is the likelihood that our model generated the observation sequence?\n \\item What is the most likely state sequence to have generated $O$, given $\\lambda$?\n \\item How can we choose the parameters $\\lambda$ that maximize $\\mathbb{P}(O | \\, \\lambda)$?\n\\end{enumerate}\nThe answers to these questions are centered around the \\emph{forward-backward} algorithm for HMMs.\nFor the second question, the approach taken in this lab will be to find the state sequence maximizing the expected number of correct states.\nThe third question is an example of \\emph{unsupervised learning}, since we are attempting to learn (or fit) model parameters using data (the observation sequence $O$) that is devoid\nof human-provided labels (the corresponding state sequence); the algorithm does not rely on human supervision or input.\n\nWe assume throughout this lab that the HMM has a discrete state space of cardinality $N$ and a discrete observation space of cardinality $M$.\nIn this context $\\lambda = \\left( A, B, \\mathbf{\\pi} \\right)$, where $A$ is a $N \\times N$  column-stochastic matrix (the state transition model), $B$ is a $M \\times N$ column-stochastic matrix (the\nstate observation model), and $\\mathbf{\\pi}$ is a stochastic vector of length $N$ (the initial state distribution).\nFurther, $O$ is a vector of length $T$ with values in the set $\\{1,2,\\ldots,M\\}$.\n\n\\begin{warn}\nThe mathematical exposition in the lab assumes the standard 1-based indexing of vectors and matrices.\nBe sure to carefully translate the various formulae into 0-based indexing when implementing these methods for Python coding.\nThis means that, in Python, your array containing the observation sequence $O$ will actually have values\nin the set $\\{0,1,\\ldots,M-1\\}$ so that they may be used to index the matrix $B$ correctly.\n\\end{warn}\n\nThroughout this lab, we will be using the following toy HMM to verify your code.\n\\begin{lstlisting}\n>>> # toy HMM example to be used to check answers\n>>> A = np.array([[.7, .4],[.3, .6]])\n>>> B = np.array([[.1,.7],[.4, .2],[.5, .1]])\n>>> pi = np.array([.6, .4])\n>>> obs = np.array([0, 1, 0, 2])\n\\end{lstlisting}\n\n\\begin{problem}\n\\begin{comment}\nThe following was listed as a problem, but gave the student nothing to do, so we removed the given code.\n\nTo start off your implementation of the HMM, define a class using the following code.\nYou will be adding class methods throughout the remainder of the lab.\n\\begin{lstlisting}\nclass hmm(object):\n    \"\"\"\n    Finite state space hidden markov model.\n    \"\"\"\n    def __init__(self):\n        \"\"\"\n        Initialize model parameters.\n        \"\"\"\n        self.A = None\n        self.B = None\n        self.pi = None\n\\end{lstlisting}\n\\end{comment}\nTo start off your implementation of the HMM, define a class object which you should call ``hmm\".\nThen add the initialization method, in which you should set the \\emph{self} aspects A, B, and pi to be None objects.\nYou will be adding methods throughout the remainder of the lab.\n\\end{problem}\n\n\\subsection*{The Forward Pass}\nOur first task is to efficiently compute $\\log \\mathbb{P}(O | \\lambda)$.\nWe can do this using the \\emph{forward pass} of the forward-backward algorithm.\nWe must take care to compute all values in a numerically stable way; we do this by properly scaling values as necessary.\n\nWe compute a scaled forward probability matrix $\\widehat{\\alpha}$ of dimension $T \\times N$ as follows:\nLet $\\widehat{\\alpha}_{i,:}, B_{i,:}$ denote the $i$-th rows of $\\widehat{\\alpha}$ and $B$, respectively, let $\\odot$ denote the Hadamard (or entry-wise) product of arrays,\nand let $\\langle \\cdot, \\cdot \\rangle$ denote the standard dot product.\n(Note that here, using 0-based indexing and the toy HMM example, $B_{O_3,:}$ would refer to $[.5,.1]$.)\nThen\n\\begin{itemize}\n \\item $c_1 = \\langle \\pi, B_{O_1,:}\\rangle^{-1}$\n \\item $\\widehat{\\alpha}_{1,:} = c_1(\\pi\\odot B_{O_1,:})$\n \\item For $t = 2, \\ldots, T$:\n \\begin{itemize}[]\n     \\item $c_t = \\langle A\\widehat{\\alpha}_{t-1,:}, B_{O_t,:}\\rangle^{-1}$\n\t \\item $\\widehat{\\alpha}_{t,:} = c_t((A\\widehat{\\alpha}_{t-1,:})\\odot B_{O_t,:})$\n \\end{itemize}\n\\end{itemize}\nThe matrix $\\widehat{\\alpha}$ will be of use when fitting parameters, but we can compute the desired log probability using the scaling factors $c_t$ as follows:\n\\[\n\\log \\mathbb{P}(O | \\lambda) = -\\sum_{t=1}^T \\log c_t.\n\\]\n\n\\begin{problem}\nImplement the forward pass by adding the following method to your class:\n\\begin{lstlisting}\ndef _forward(self, obs):\n    \"\"\"\n    Compute the scaled forward probability matrix and scaling factors.\n\n    Parameters\n    ----------\n    obs : ndarray of shape (T,)\n        The observation sequence\n\n    Returns\n    -------\n    alpha : ndarray of shape (T,N)\n        The scaled forward probability matrix\n    c : ndarray of shape (T,)\n        The scaling factors c = [c_1,c_2,...,c_T]\n    \"\"\"\n    pass\n\\end{lstlisting}\nTo verify that your code works, you should get the following output using the toy HMM:\n\\begin{lstlisting}\n>>> h = hmm()\n>>> h.A = A\n>>> h.B = B\n>>> h.pi = pi\n>>> alpha, c = h._forward(obs)\n>>> print -(np.log(c)).sum() # the log prob of observation\n-4.6429135909\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{The Backward Pass}\nThe backward pass of the forward-backward algorithm produces values that can be used to calculate the most likely state sequence corresponding to an observation sequence.\n\nWe compute a scaled backward probability matrix $\\widehat{\\beta}$ of dimension $T \\times N$ as follows:\n\\begin{itemize}\n \\item $\\widehat{\\beta}_{T,i} = c_{T}$ for $i = 1,\\ldots, N$\n \\item $\\widehat{\\beta}_{t,:} = c_{t}A^T(B_{O_{t+1},:}\\odot \\widehat{\\beta}_{t+1,:})$ for $t = T-1, \\ldots, 1$\n\\end{itemize}\n(Above, $A^T$ is the \\emph{transpose} of $A$, not the $T$-th power of $A$.)\n\nIt turns out that\n\\begin{equation*}\n\\mathbb{P}(\\mathbf{x}_{t} = i | O, \\lambda) = \\frac{\\widehat{\\alpha}_{t,i}\\widehat{\\beta}_{t,i}}{\\sum_{j=1}^{N} \\widehat{\\alpha}_{t,j}\\widehat{\\beta}_{t,j}}\n\\end{equation*}\nand so we can easily compute the most likely state at time $t$ by\n\\begin{equation*}\n\\mathbf{x}_{t}^{*} = \\argmax_{i} \\widehat{\\alpha}_{t,i} \\widehat{\\beta}_{t,i}.\n\\end{equation*}\nThis is the solution to the second question posed at the beginning of the lab.\n\n\\begin{problem}\nImplement the backward pass by adding the following method to your class:\n\\begin{lstlisting}\ndef _backward(self, obs, c):\n    \"\"\"\n    Compute the scaled backward probability matrix.\n\n     Parameters\n    ----------\n    obs : ndarray of shape (T,)\n        The observation sequence\n    c : ndarray of shape (T,)\n        The scaling factors from the forward pass\n\n    Returns\n    -------\n    beta : ndarray of shape (T,N)\n        The scaled backward probability matrix\n    \"\"\"\n    pass\n\\end{lstlisting}\nUsing the same toy example as before, your code should produce the following output:\n\\begin{lstlisting}\n>>> beta = h._backward(obs, c)\n>>> print beta\n[[ 3.1361635   2.89939354]\n [ 2.86699344  4.39229044]\n [ 3.898812    2.66760821]\n [ 3.56816483  3.56816483]]\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Computing the $\\delta$ and $\\gamma$ Probabilities}\nHaving implemented both parts of the forward-backward algorithm, we are closing in on the solution to question three, namely that of fitting parameters $\\lambda$ that maximize $\\mathbb{P}(O | \\, \\lambda)$.\nAt this stage, we combine the information accumulated in the forward-backward algorithm to produce a three-dimensional array $\\widehat{\\delta}$\nof shape $(T-1)\\times N \\times N$ whose entries are related to $\\mathbb{P}(\\mathbf{x}_t = i, \\mathbf{x}_{t+1} = j|\\, O, \\lambda)$, as well as\na $T \\times N$ matrix $\\widehat{\\gamma}$ whose entries are related to $\\mathbb{P}(\\mathbf{x}_t=i | \\, O, \\lambda)$.\nThe relevant formulae are\n\\[\n\\widehat{\\delta}_{t,i,j} = \\frac{\\widehat{\\alpha}_{t,i}A_{j,i}B_{O_{t+1},j}\\widehat{\\beta}_{t+1,j}}{\\sum_{k,l}\\widehat{\\alpha}_{t,k}A_{l,k}B_{O_{t+1},l}\\widehat{\\beta}_{t+1,l}}\n\\]\nfor $t = 1, \\ldots, T-1$ and $i,j = 1, \\ldots, N$,\n\\[\n\\widehat{\\gamma}_{t,i} = \\sum_{j=1}^N \\widehat{\\delta}_{t,i,j}\n\\]\nfor $t = 1,\\ldots,T-1$ and $i=1,\\ldots,N$, and finally\n\\[\n\\widehat{\\gamma}_{T,:} = \\frac{\\widehat{\\alpha}_{T,:}\\odot \\widehat{\\beta}_{T,:}}{\\langle\\widehat{\\alpha}_{T,:}, \\widehat{\\beta}_{T,:}\\rangle}.\n\\]\n\n\\begin{problem}\nAdd the following method to your class to compute the $\\delta$ and $\\gamma$ probabilities.\n\\begin{lstlisting}\ndef _delta(self, obs, alpha, beta):\n    \"\"\"\n    Compute the delta probabilities.\n\n    Parameters\n    ----------\n    obs : ndarray of shape (T,)\n        The observation sequence\n    alpha : ndarray of shape (T,N)\n        The scaled forward probability matrix from the forward pass\n    beta : ndarray of shape (T,N)\n        The scaled backward probability matrix from the backward pass\n\n    Returns\n    -------\n    delta : ndarray of shape (T-1,N,N)\n        The delta probability array\n    gamma : ndarray of shape (T,N)\n        The gamma probability array\n    \"\"\"\n    pass\n\\end{lstlisting}\nWhile writing a triply-nested loop may be the simplest way to convert the formula into code,\nit is possible to use array broadcasting to eliminate two of the loops, which will speed up your code.\n\nCheck your code by making sure it produces the following output, using the same toy example as before.\n\\begin{lstlisting}\n>>> delta, gamma = h._delta(obs, alpha, beta)\n>>> print delta\n[[[ 0.14166321  0.0465066 ]\n  [ 0.37776855  0.43406164]]\n\n [[ 0.17015868  0.34927307]\n  [ 0.05871895  0.4218493 ]]\n\n [[ 0.21080834  0.01806929]\n  [ 0.59317106  0.17795132]]]\n>>> print gamma\n[[ 0.18816981  0.81183019]\n [ 0.51943175  0.48056825]\n [ 0.22887763  0.77112237]\n [ 0.8039794   0.1960206 ]]\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Choosing Better Parameters}\nAfter running the forward-backward algorithm and computing the $\\delta$ probabilities, we are now in a position to choose new parameters $\\lambda' = (A', B', \\pi')$\nthat increase the probability of observing our data, i.e.\n\\[\n\\mathbb{P}(O|\\,\\lambda') \\geq \\mathbb{P}(O|\\,\\lambda).\n\\]\nThe update formulas are given by\n\\begin{align*}\nA'_{i,j} &= \\frac{\\sum_{t=1}^{T-1}\\widehat{\\delta}_{t,j,i}}{\\sum_{t=1}^{T-1}\\widehat{\\gamma}_{t,j}}\\\\\nB'_{i,j} &= \\frac{\\sum_{t=1}^{T}\\widehat{\\gamma}_{t,j}1_{\\{O_t=i\\}}}{\\sum_{t=1}^{T}\\widehat{\\gamma}_{t,j}}\\\\\n\\pi' &= \\widehat{\\gamma}_{1,:}\n\\end{align*}\nwhere $1_{\\{O_t=i\\}}$ is one if $O_t=i$ and zero otherwise.\n\\begin{problem}\nImplement the parameter update step by adding the following method to your class:\n\\begin{lstlisting}\ndef _estimate(self, obs, delta, gamma):\n    \"\"\"\n    Estimate better parameter values.\n\n    Parameters\n    ----------\n    obs : ndarray of shape (T,)\n        The observation sequence\n    delta : ndarray of shape (T-1,N,N)\n        The delta probability array\n    gamma : ndarray of shape (T,N)\n        The gamma probability array\n    \"\"\"\n    # update self.A, self.B, self.pi in place\n    pass\n\\end{lstlisting}\nVerify that your code produces the following output on the toy HMM from before:\n\\begin{lstlisting}\nh._estimate(obs, delta)\n>>> print h.A\n[[ 0.55807991  0.49898142]\n [ 0.44192009  0.50101858]]\n>>> print h.B\n[[ 0.23961928  0.70056364]\n [ 0.29844534  0.21268397]\n [ 0.46193538  0.08675238]]\n>>> print h.pi\n[ 0.18816981  0.81183019]\n\\end{lstlisting}\n\\end{problem}\n\n\\subsection*{Fitting the Model}\nWe are now ready to put everything together into a learning algorithm.\nGiven a sequence of observations, a maximum number of iterations $K$, and a convergence tolerance threshold $\\epsilon$, we fit a HMM model using the following procedure:\n\\begin{itemize}\n\\item Randomly initialize parameters $\\lambda = (A, B, \\pi)$\n\\item Compute $\\log \\mathbb{P}(O |\\, \\lambda)$\n\\item For $i=1, 2, \\ldots, K$:\n\\begin{itemize}\n\\item Run forward pass\n\\item Run backward pass\n\\item Compute $\\delta$ probabilities\n\\item Update model parameters\n\\item Compute $\\log \\mathbb{P}(O |\\, \\lambda)$ according to new parameters\n\\item If change in log probabilities is less than $\\epsilon$, break\n\\item Else, continue\n\\end{itemize}\n\\end{itemize}\n\nThe most convenient way to randomly initialize stochastic matrices is to draw from the Dirichlet distribution,\nwhich produces vectors with nonnegative entries that sum to 1.\nThe following Python code initializes $A$, $B$, and $\\pi$ using this technique:\n\\begin{lstlisting}\n>>> # assume N and M are defined\n>>> A = np.random.dirichlet(np.ones(N), size=N).T\n>>> B = np.random.dirichlet(np.ones(M), size=N).T\n>>> pi = np.random.dirichlet(np.ones(N))\n\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{logProbs.pdf}\n\\caption{The log probabilities for a HMM trained on the Declaration of Independence\ndata with 200 iterations. It takes over 100 iterations for the algorithm to work itself out\nof a poor local maximum.}\n\\label{fig:logprobs}\n\\end{figure}\n\n\nThe learning algorithm is essentially an optimization over the parameter space (i.e. the space of tuples of\nstochastic arrays having the proper dimensions) with respect to the objective function $\\mathbb{P}(O |\\, \\lambda)$.\nThe algorithm is guaranteed to increase the objective function at each iteration, so it is sure to converge.\nHowever, the objective function is riddled with local maxima, and so the outcome depends heavily on the randomly\nselected starting values for $A$, $B$, and $\\pi$. Figure \\ref{fig:logprobs} illustrates the issues involved.\nThe log probability stays approximately constant for the first 100\niterations. This indicates that the algorithm is not exploring the parameter space enough, and the parameters\nfound at the 100-th iteration are virtually the same as those found at the first or second iteration. After the first\n100 iterations, however, the algorithm is finally able to explore more of the parameter space and hence make\nbetter progress toward increasing the objective function. The moral of the story is that you may need to train\nthe HMM a few times, using different starting values, and then keep the model that has the highest log likelihood.\n\n\n\\begin{problem}\nImplement the learning algorithm by adding the following method to your class:\n\\begin{lstlisting}\ndef fit(self, obs, A, B, pi, max_iter=100, tol=1e-3):\n    \"\"\"\n    Fit the model parameters to a given observation sequence.\n\n    Parameters\n    ----------\n    obs : ndarray of shape (T,)\n        Observation sequence on which to train the model.\n    A : stochastic ndarray of shape (N,N)\n        Initialization of state transition matrix\n    B : stochastic ndarray of shape (M,N)\n        Initialization of state observation matrix\n    pi : stochastic ndarray of shape (N,)\n        Initialization of initial state distribution\n    max_iter : integer\n        The maximum number of iterations to take\n    tol : float\n        The convergence threshold for change in log-probability\n    \"\"\"\n    # initialize self.A, self.B, self.pi\n    # run the iteration\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nWe now turn to the data found in the file {\\tt declaration.txt}.\nThis file contains the text of the Declaration of Independence.\nWe will use the sequence of characters (after stripping out punctuation and converting everything to lower-case) as our observation sequence.\nIn order to convert the raw text into a useable data structure, we need to read in the file, process the string as necessary, and then map the characters to integer values.\nWe provide sample code below to accomplish this task:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> import string\n\n>>> with open(\"declaration.txt\", 'r') as f: # read in the text\n>>>     dec = f.read(-1).lower() # convert to lower-case\n\n>>> # next, remove punctuation and newline characters\n>>> dec = dec.translate(string.maketrans(\"\",\"\"), string.punctuation+\"\\n\\r\")\n\n>>> # create a list of the unique characters in the text\n>>> char_map = list(set(dec))\n\n>>> # map each character to its index in char_map\n>>> obs = []\n>>> for char in dec:\n>>>     obs.append(char_map.index(char))\n>>> obs = np.array(obs)\n\\end{lstlisting}\n\n\\begin{problem}\nYou are now ready to train a HMM using the Declaration of Independence data.\nUse $N=2$ states and $M=27$ observation values (26 lower case characters and 1 whitespace character),\nand run for 200 iterations with the default value for \\li{tol}.\nGenerally speaking, if you converge to a log probability greater than $-21550$, then you have reached\nan acceptable set of parameters for this dataset.\n\nOnce the learning algorithm converges, analyze the state observation matrix $B$.\nNote which rows correspond to the largest and smallest probability values in each column of $B$,\nand check the corresponding characters.\nThe code below displays typical results for a well-converged HMM:\n\\begin{lstlisting}\n>>> for i in xrange(len(h.B)):\n>>>     print  \"{0}, {1:0.4f}, {2:0.4f}\".format(char_map[i], h.B[i,0], h.B[i,1])\n , 0.0051, 0.3324\na, 0.0000, 0.1247\nc, 0.0460, 0.0000\nb, 0.0237, 0.0000\ne, 0.0000, 0.2245\nd, 0.0630, 0.0000\ng, 0.0325, 0.0000\nf, 0.0450, 0.0000\ni, 0.0000, 0.1174\nh, 0.0806, 0.0070\nk, 0.0031, 0.0005\nj, 0.0040, 0.0000\nm, 0.0360, 0.0000\nl, 0.0569, 0.0001\no, 0.0009, 0.1331\nn, 0.1207, 0.0000\nq, 0.0015, 0.0000\np, 0.0345, 0.0000\ns, 0.1195, 0.0000\nr, 0.1062, 0.0000\nu, 0.0000, 0.0546\nt, 0.1600, 0.0000\nw, 0.0242, 0.0000\nv, 0.0185, 0.0000\ny, 0.0147, 0.0058\nx, 0.0022, 0.0000\nz, 0.0010, 0.0000\n\\end{lstlisting}\nWhat do you notice about the second column of $B$? It seems that the HMM has detected a vowel state and a consonant state, without any prior input from an English speaker.\nInterestingly, the whitespace character is grouped together with the vowels. A HMM can also detect the vowel/consonant distinction in other languages. It appears that\nthis distinction is a statistically significant aspect of much of human language.\n\\end{problem}\n\n\n\n\n", "meta": {"hexsha": "10b66bcbb368a2f01f4fbd5e024d425fbc01dd89", "size": 18061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/HMM/hmm.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/HMM/hmm.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/HMM/hmm.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.2351598174, "max_line_length": 205, "alphanum_fraction": 0.7038369968, "num_tokens": 5215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6085633057347907}}
{"text": "\\documentclass[../main/thesis_msc.tex]{subfiles}\n\n\\begin{document}\n\n\\chapter{Appendix}\n\n\\section{Radio Interferometry Measurement Equation- RIME formalism}\n\nThe calibration techniques used for LOFAR are based on RIME formalism. The explanation closely follows the one given in \\citep{rime}, since the Direction Dependant Effects (DDE) are well explained in it. This section describes the calculation of RIME from the voltages obtained at the antennae.\\\\\n\\noindent Consider a quasi-monochromatic source giving out a signal. This can be represented by a complex vector \\textbf{\\textit{e}} (the ``original signal\"), and be written in the form of a matrix using an orthogonal coordinate system \\textit{xyz}, with `\\textit{z}' along the direction of propagation.\n\\begin{center}\n\\(\n\\textbf{\\textit{e}} = \n  \\begin{pmatrix}\n    e_x \\\\\n    e_y\n  \\end{pmatrix}\n\\)\n\\end{center}\n\\noindent The signal encounters multiple effects on its path towards the antennae. These effects are assumed to affect the signal \\textit{\\textbf{linearly}}. The signal changes to \\textbf{\\textit{e$^\\backprime$}} due to these effects and can be written in the form given in the equation \\ref{eq}.\n\\begin{equation}\n\\textbf{\\textit{e$^{\\backprime}$}} = \\underbrace{\\textbf{\\textit{J}}_n \\textbf{\\textit{J}}_{n-1} ..... \\textbf{\\textit{J}}_1}_{\\textbf{Jones chains}} \\textbf{\\textit{e}} = \\textbf{\\textit{J}} \\textbf{\\textit{e}} \n\\label{eq}\n\\end{equation}\n\\noindent Here, \\textit{\\textbf{J}} is a 2$\\times$2 complex matrix known as Jones matrix. Since there are multiple effects along the path of the signal, the Jones chain is written taking all these effects into account and the final cumulative Jones matrix can be written as \\textit{\\textbf{J}}.\n\\noindent If a and b are two linear dipole feeds, the signal one reaching and gets converted to complex voltages $v_a$ and $v_b$ representing the two polarizations. \n\\begin{equation}\n\\textrm{\n\\(\n\\textbf{\\textit{v}} = \n  \\begin{pmatrix}\n    v_a \\\\\n    v_b\n  \\end{pmatrix}\n\\ = \\textbf{\\textit{J}} \\textbf{\\textit{e}} \\)\n}\n\\label{J}\n\\end{equation}\n\\noindent An interferometer consists of several antennae elements, so let us consider two such spatially separated elements - \\textit{p} and \\textit{q}, giving independent voltage vectors $\\emph{v}_p$ and $\\emph{v}_q$.  Their voltages are correlated to give the visibility matrix V$_{pq}$. Hence, the visibility matrix can be written as:\n\\begin{center}\n\\(\n\\textrm{V}_{pq} = 2\n  \\begin{pmatrix}\n    \\langle v_{pa}v^*_{qa} \\rangle & \\langle v_{pa}v^*_{qb} \\rangle \\\\\n    \\langle v_{pb}v^*_{qa} \\rangle & \\langle v_{pb}v^*_{qb} \\rangle\n  \\end{pmatrix}\n\\)\n\\end{center}\n\\noindent Here, $v^*$ represents the complex conjugate of $v$. V$_{pq}$ can be written as matrix product of $\\emph{v}_p$ and complex conjugate of $\\emph{v}_q$. \\textit{H} represents the conjugate transpose operation.\n\\begin{equation}\n\\textrm{V}_{pq} = 2\\langle v_{p}v^H_{q} \\rangle\n\\label{H}\n\\end{equation}\n \n\\noindent Combining equations \\ref{J} and \\ref{H}, we get:\n\\begin{equation}\n\\textrm{V}_{pq} = 2\\langle \\textbf{\\textit{J}}_{p}(\\textbf{\\textit{ee}}^H) \\textbf{\\textit{J}}_{q} \\rangle\n\\end{equation}\n\\noindent We assume that \\textbf{\\textit{J}}$_{p}$ and \\textbf{\\textit{J}}$_{q}$  are constant over the averaging interval.\n\\begin{equation}\n\\textrm{V}_{pq} = 2\\langle v_{p}v^H_{q} \\rangle = 2\\textbf{\\textit{J}}_p \\begin{pmatrix}\n    \\langle e_{x}e^*_{x} \\rangle & \\langle x_{x}e^*_{y} \\rangle \\\\\n    \\langle e_{y}e^*_{x} \\rangle & \\langle e_{y}e^*_{y} \\rangle\n  \\end{pmatrix} \\textbf{\\textit{J}}^H_q \n\\end{equation}\n\\noindent A relation can be obtained between the source signal and Stokes parameters (I, Q, U, V) as shown in \\citep{RIME1}, and a new matrix called the brightness matrix B is defined.\n\\begin{equation}\n2\\begin{pmatrix}\n    \\langle e_{x}e^*_{x} \\rangle & \\langle x_{x}e^*_{y} \\rangle \\\\\n    \\langle e_{y}e^*_{x} \\rangle & \\langle e_{y}e^*_{y} \\rangle\n  \\end{pmatrix}   = \\underbrace{ \\begin{pmatrix}\n    I + Q & U + iV \\\\\n    U + iV & I - Q\n  \\end{pmatrix} }_{\\textrm{Brightness matrix B}}\n\\end{equation}\n\\noindent The signal undergoes sequential layers of corruption, and the resulting Jones matrix \\textbf{\\textit{J}}$_{p}$  can be written in the form of Jones chain: \\textbf{\\textit{J}}$_{p}$  = (\\textbf{\\textit{J}}$_{pn}$ . \\textbf{\\textit{J}}$_{p(n - 1)}$ .....\\textbf{\\textit{J}}$_{p1}$ ). \n\\noindent The final Jones matrix can be thus written as a cumulative of the following terms:\n\\begin{itemize}\n\\item The \\textbf{phase} term: Phase difference exists between the two antennae due to the path-length difference between the paths from source to \\textit{p} and \\textit{q}. This in turn corrupts the signal. Phase center is the direction in which the antennae are steered towards to minimize the phase difference\\footnote{The net measured visibility is lowered in amplitude due to the presence of this complex term in the Jones matrix, which is variable in terms of both frequency and time. This effect is called ``smearing\".}.  \\\\\nConsidering the conventional coordinate system, with \\textit{z} axis pointed towards the phase center, antenna \\textit{p}'s location can be defined as \\textit{\\textbf{u}}$_p$ = ($u_p, v_p, w_p$). Thus, the phase term in Jones matrix formalism can be written as: \\\\\n\\begin{center}\n$\\textbf{\\textit{K}}_p = e^{i \\kappa_p} = e^{-2i(u_pl + v_pm + w_p(n-1))}$\n\\end{center}\nHere, \\textit{\\textbf{u}} is defined in terms of wavelength. The visibility can hence be written (taking inly the phase term into account)\n\\begin{center}\n$\\textrm{V}_{pq} = \\textbf{\\textit{K}}_p \\textrm{B} \\textbf{\\textit{K}}_q^H$\n\\end{center}\nThe phase term is a scalar matrix, and hence can be moved around in the Jones chain.\n\\item The \\textbf{source-independent antenna} gain term: The interferometer itself also has some corrupting effects, and these can be considered in the Jones chain in the form $\\textbf{\\textit{G}}_p$.Thsi describes the Direction Independent Effects (DIEs) or the uv- Jones term.\n\\item The \\textbf{source-dependent} gain term: This is the remainder of the Jones chain of the form \\textbf{\\textit{E}}$_{sp}$. This represents the Direction Dependent Effects (DDEs) or the sky-Jones term.\n\\end{itemize}\n\\noindent Hence, in total, the Jones chain can be written as:\n\\begin{equation}\n\\textbf{\\textit{J}}_{sp} =  \\textbf{\\textit{G}}_{p} \\textbf{\\textit{E}}_{sp} \\textbf{\\textit{E}}_{sp}\n\\end{equation}\n\\noindent The final visibility matrix can be written\\footnote{This equation is in the ``\\textbf{onion form}\". In this way, the various effects/corruptions are sequentially applied to the signal} as:\n\\begin{equation}\n\\textrm{V}_{pq}=\\textbf{\\textit{G}}_{p} \\left( \\sum\\limits_{s} \\textbf{\\textit{E}}_{sq} \\textbf{\\textit{K}}_{sq} \\textrm{B}_s \\textbf{\\textit{K}}^H_{sq} \\textbf{\\textit{E}}^H_{sq} \\right) \\textbf{\\textit{G}}^H_{q}\n\\end{equation}\nIn LOFAR, this equation is taken over all the sufficiently bright sources in the horizon. However, sky is a continuous brightness distribution B($\\sigma$) with $\\sigma$ being the unit direction vector. Hence, the total visibility for the interferometer should be in the form of an integration, not as a summation of discrete sources. When we write the visibility matrix in terms of the plane projection as described earlier (as opposed to the unit sphere integral, which is not very traceable) it is of the form in the equation \\ref{wterm}, with $ n = \\sqrt{1 - l^2 - m^2}$.\n\\begin{equation}\n\\textrm{V}_{pq}= \\textbf{\\textit{G}}_{p} \\left( \\int\\limits_{l} \\int\\limits_{m} \\frac{1}{n} \\bar{\\textbf{\\textit{E}}}_{p}  (\\textbf{\\textit{l,m}}) \\text{ B } \\bar{\\textbf{\\textit{E}}}^H_{q} (\\textbf{\\textit{l,m}}) e^{-2 \\pi i(u_{pq}l + v_{pq}m + w_{pq}(n-1))} dl dm \\right) \\textbf{\\textit{G}}^H_{q}\n\\label{wterm}\n\\end{equation}\n\\noindent Decomposing $w_{pq} = w_p - w_q$ and writing the non-coplanetary term as per antenna terms, we can substitute $W_p= \\frac{1}{\\sqrt{n}} e ^{-2 \\pi i w_p (n-1)}$ and write $\\textbf{\\textit{E}}_p =  \\bar{\\textbf{\\textit{E}}}_p W_p $. This would give us the visibility matrix in the form of a 2D Fourier Transform  of the apparent sky brightness for the baseline $pq$ (with the term B$_{pq}$ in the place of  $\\textbf{\\textit{E}}_{p}$B$\\textbf{\\textit{E}}_{q}$). \n\\begin{equation}\n\\textrm{V}_{pq} = \\textbf{\\textit{G}}_{p}  \\left( \\int\\limits_{l} \\int\\limits_{m} \\textrm{B}_{pq} e^{-2 \\pi i(u_{pq}l + v_{pq}m)} \\right) \\textbf{\\textit{G}}^H_{q}\n\\end{equation}\n\\noindent This is the general form of the \\textbf{Van Cittert Zernike theorem}. This is the formalism used by the LOFAR calibration software. This equation effectively takes care of the direction dependent effects. Using this fourier relation, and applying the Inverse Fast Fourier Transform (IFFT) algorithm, we can synthesis an image. \n\n\\section{NGC 628- correlation plot}\nThe Figure \\ref{ngc_acd} shows the correlation plot for the thermal region for A, C and D regions, for NGC\\,628. The regions are marked in the Chapter 3 of the thesis in Figure 3.12.\n\n    \\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[scale = 0.65]{13Regions_thermal_region_ACandD.png}\n\t\\caption{Correlation of the flux density value with the spectral index map values, for each pixel. The various regions have different \t\t\tslops of correlation, which is interesting. This plot shows the regions A, C and D.}\n\t\\label{ngc_acd}\n\t\\end{figure}\n\t\n\n\\section{Making of thermal maps}\nTo understand how the thermal map is made, one can refer to \\citet{2017A&A...600A...6M}. In this section I will explain why a simpple H-$\\alpha$ map might not be sufficient if one needs to do an in-depth analysis of thermal emission in the galaxy, and for an accurate determination of the magnetic fields in the galaxy. Classically, the separation of the thermal and non-thermal components has been done by assuming the spectral index of synchrotron emission to be $\\alpha_{\\text{Syn}}$ = $-$1.0. This method overestimates the amount of thermal emission in the spiral arms, as the $\\alpha_{\\text{Syn}}$ in such regions is flatter than the assumed value. The $\\alpha_{\\text{Syn}}$ is also steeper in the inter-arm regions and the outer disk of the galaxy, where a higher amount of synchrotron emission takes place. This leads to an overestimation of the thermal emission in such regions. Another approach is to use 24~$\\mu$m infrared (IR) map to estimate the thermal emission. This method also hasa its own set of caviates viz, IR emission may also come from non-thermal sources such as super massive black holes, and energetic cosmic rays (CRs)may also produce IR, thus overestimating the thermal fractionsw in such regions. In this thesis, the thermal map has been made using an extinction corrected H-$\\alpha$ map. An H-$\\alpha$ map in itself suffers from dust extinction, which would underestimate the amount of thermal emission. In the method where extinction correction is done, the optical depth for the whole galaxy is obtained using high resolution FIR data at 70 and 160~$\\mu$m. Using this, one can determine the amount of extinction, thus producing a very good estimate of the thermal tempelate. This method was developed by \\citet{2007A&A...475..133T}, and is used in the thermal map that I use in my thesis for NGC\\,628. The thermal map for IC\\,342 was based on the separation of the thermal and non- thermal components by assuming a constant spectral index, as the extintion corrected thermal map was not available. My thesis does not require an accurate determination of magnetic fields and cosmir ray propagation. Thus, a superficial understanding of the thermal regions in the galaxy was sufficient.\n\\end{document}\n", "meta": {"hexsha": "694274f00d7dab2edcb69891daefc43dacd7a71f", "size": 11595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix1/appendix1.tex", "max_stars_repo_name": "ayushimandlik/master_thesis", "max_stars_repo_head_hexsha": "eaa75ef217e34c0524ec8ed2acd05b79cbe0d92e", "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": "appendix1/appendix1.tex", "max_issues_repo_name": "ayushimandlik/master_thesis", "max_issues_repo_head_hexsha": "eaa75ef217e34c0524ec8ed2acd05b79cbe0d92e", "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": "appendix1/appendix1.tex", "max_forks_repo_name": "ayushimandlik/master_thesis", "max_forks_repo_head_hexsha": "eaa75ef217e34c0524ec8ed2acd05b79cbe0d92e", "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": 92.76, "max_line_length": 2215, "alphanum_fraction": 0.7340232859, "num_tokens": 3506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387956435734, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.608540161309052}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{Fisher Matrix}\n\n\\marginpar{Tuesday\\\\ 2020-11-24, \\\\ compiled \\\\ \\today}\n\nSuppose we have a data vector \\(\\vec{x}\\), such that each element is distributed according to a Gaussian with mean \\(\\mu \\) and standard deviation \\(\\sigma \\). \nWe could construct an estimator for the mean like \\(\\hat{\\theta} = f(\\vec{x}) = x_3\\). \nThis is unbiased: \\(\\expval{x_3} = \\mu = \\expval{x_i}\\) for any \\(i\\).\n\nHowever, this is not the best estimator we could choose, as its variance is \\(\\sigma^2\\); we could instead use the arithmetic mean, which is also unbiased but has a variance of \\(\\sigma^2 / N\\).\n\nAn \\emph{unbiased} estimator \\(\\theta \\) for \\(\\hat{\\theta}\\) is one such that \\(\\expval{\\hat{\\theta}} = \\theta \\).\n\nGiven a likelihood \\(\\mathscr{L}(\\vec{x} | \\vec{\\theta})\\), the question is: what is the \\textbf{best unbiased estimator} for \\(\\theta \\)?\nIn order to answer this, we need to define the \\textbf{Fisher information matrix}:\n%\n\\begin{align}\nF_{\\alpha \\beta } = \\expval{- \\pdv[2]{\\log \\mathscr{L}}{\\theta_\\alpha}{\\theta _\\beta }}\n\\,.\n\\end{align}\n\nThe average is an ensemble one, over all the possible realizations of the data.\nThis is precisely the Hessian of the log-posterior, computed at the maximum of the posterior, which estimates the precision matrix of the parameters. \nWe have nice theorems for these. \n\n\\begin{theorem}\n    For any unbounded estimator \\(\\hat{\\theta}_\\alpha \\) of \\(\\theta _\\alpha \\), its error is bounded by \n    %\n    \\begin{align}\n    \\sqrt{\\expval{\\hat{\\theta}_\\alpha^2} - \\expval{\\hat{\\theta}_\\alpha }^2} \\geq \\sqrt{F_{\\alpha \\alpha }^{-1}}\n    \\,.\n    \\end{align}\n\\end{theorem}\n\nThis is known as the \\textbf{Cramer-Rao} bound. So, if we can saturate the inequality, then we know we have the best possible estimator. \n\n\\begin{theorem}\n    If there exists a Best Unbiased Estimator, then this is also the Maximum Likelihood estimator. \n\\end{theorem}\n\n\\begin{theorem}\n    The ML estimate is asymptotically the BUE.\n\\end{theorem}\n\nConsider a likelihood \\(P(\\vec{d} | \\theta)\\); then the variance is given by \n%\n\\begin{align}\n\\expval{(\\hat{\\theta} - \\expval{\\hat{\\theta}})^2} = \\int \\dd{\\vec{d}} P(\\vec{d} | \\theta ) (\\theta - \\expval{\\hat{\\theta}})^2 \n\\,.\n\\end{align}\n\nLet us define the product of two functions as \n%\n\\begin{align}\n\\qty(u (\\vec{d}), v (\\vec{d})) = \\int \\dd{\\vec{x}} u (\\vec{x}) v (\\vec{x}) P(\\vec{x} | \\theta )\n\\,.\n\\end{align}\n\nThen, the variance of the estimator \\(\\hat{\\theta} \\) can be expressed by defining \\(v(\\vec{d}) = \\hat{\\theta} - \\expval{\\hat{\\theta}}\\), and then \\(\\var{\\hat{\\theta}} = \\qty(v(\\vec{d}), v(\\vec{d}))\\). \n\nNow we will use the Schwarz inequality, which says that in an inner product space: \n%\n\\begin{align}\n(v, v) \\geq \\frac{(u, v)^2}{(u, u)}\n\\,.\n\\end{align}\n\nWe will apply this, with the aforementioned \\(v\\), and with the so-called \\emph{score function}: \n%\n\\begin{align}\nu(\\vec{d}) = \\pdv{}{\\theta } \\log P(\\vec{d} | \\theta )\n\\,.\n\\end{align}\n%\n\nThen, \n%\n\\begin{align}\n(u, w) &= \\int \\dd{\\vec{x}} u(\\vec{x}) w(\\vec{x}) P(\\vec{x} | \\theta )  \\\\\n&= \\int \\dd{\\vec{x}} \\pdv{}{\\theta } \\log P(\\vec{x} | \\theta ) w(\\vec{x}) P(\\vec{x} | \\theta )  \\\\\n&= \\int \\dd{\\vec{x}} \\frac{1}{P(\\vec{x} | \\theta )} \\pdv{P}{\\theta } w(\\vec{x} ) P(\\vec{x} | \\theta )  \\\\\n&= \\pdv{}{\\theta } \\expval{w}\n\\,.\n\\end{align}\n\nThen, \n%\n\\begin{align}\n(u, v) &= \\int (\\hat{\\theta} - \\expval{\\hat{\\theta}}) \\pdv{\\log P}{\\theta } P(\\vec{x} | \\theta ) \\dd{\\vec{x}} \\\\\n&= \\int \\hat{\\theta} \\pdv{\\log P}{\\theta } P(\\vec{x} | \\theta ) \\dd{\\vec{x}} - \n\\expval{\\hat{\\theta}} \\underbrace{\\int \\pdv{\\log P}{\\theta } P(\\vec{x} | \\theta ) \\dd{\\vec{x}}}_{= \\pdv{}{\\theta } \\int P \\dd{\\vec{x}} = 0}  \\\\\n&= \\int \\hat{\\theta} \\pdv{\\log P}{\\theta } P(\\vec{x} | \\theta ) \\dd{\\vec{x}}  \\\\\n&= \\pdv{}{\\theta } \\expval{\\hat{\\theta}} = 1\n\\,,\n\\end{align}\n%\ntherefore, we can apply Schwarz's inequality so that \n%\n\\begin{align}\n\\var{\\hat{\\theta}} = (v, v) \\geq \\frac{(u, v)^2}{(u, u)} = \\frac{1}{(u, u)}\n= \\qty(\\int \\dd{x} \\qty(\\pdv{}{\\theta } \\log P)^2 P(\\vec{x} | \\theta ))^{-1} = \\expval{\\qty(\\pdv{\\log P}{\\theta })^2}^{-1}\n\\,,\n\\end{align}\n%\nso what we are left to prove is that \n%\n\\begin{align}\n\\expval{\\qty(\\pdv{\\log P}{\\theta })^2} = \\expval{\\pdv[2]{\\log P}{\\theta }}\n\\,.\n\\end{align}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "43b072d4e68986551bb37a46d313c5843fbe068b", "size": 4286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostatistics_cosmology/nov24.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_third_semester/astrostatistics_cosmology/nov24.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_third_semester/astrostatistics_cosmology/nov24.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": 36.6324786325, "max_line_length": 202, "alphanum_fraction": 0.6154923005, "num_tokens": 1515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257127, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6083889084906635}}
{"text": "\\chapter{Nonlinear Ordinary Differential Equations and Iteration}\n\nThe implicit explicit method avoids the direct solution of nonlinear problems. This can be advantageous for some problems, but can also lead to severe time step restrictions in others. Furthermore, the resulting numerical schemes can sometimes have undesirable qualitative properties. For this reason, we need to describe methods that allow us to solve the nonlinear equations generated in fully-implicit numerical schemes. \n\nWe consider an ordinary differential equation \n\\begin{equation}\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}=f(t,y) \n\\end{equation}\nfor $t\\in[t_{0},t^{*}]$, and for which $f(t,y)$ is not necessarily a linear function of $y$. We want to use an implicit numerical method to obtain an approximate solution of this problem -- for example backward Euler's method. If we want to demonstrate the convergence of the numerical scheme, we need to demonstrate convergence of functional iteration which we use to find the solution for the nonlinear equation term in using backward Euler's method. \n\nThe results that follow are primarily taken from Iserles~\\cite{Ise09}, although this material is also often found in calculus texts such as Lax, Burstein and Lax~\\cite{LaxBurLax76}, and Hughes et al.~\\cite{HugEtAl08}. We will let $t_{i}$ denote the time at time step $i$, $y_{i}$ denote the approximate solution at time step $i$ and $h$ denote the time step. We will assume $f$ is Lipschitz continuous, a condition that is weaker than differentiable but stronger than continuous, which we will give a precise definition of.  There are two classical iteration methods:\n\\begin{itemize}\n\\item fixed-point iteration \n\\item Newton's (Newton-Raphson) method.\n\\end{itemize}\nWe will prove convergence of these two methods (a proof of the convergence of the modified Newton-Raphson method is in Iserles~\\cite[p. 130]{Ise09}). We will analyze the specific problem $y'(t)=y^{2}$ with initial data\n$y(0)=1$ and $t\\in[0,0.99]$. \n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Exact Solution to an Example Nonlinear Ordinary Differential Equation}\n\nWe consider\n\\begin{equation}\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}=y^{2}\n\\end{equation}\nwith initial data $y(t=0)=1$ and $t\\in[0,0.99]$.  Whenever the solution $y(t)$ exists, it will be positive all the time, because the initial value is positive and $\\frac{\\mathrm{d}y}{\\mathrm{d}t}$ is positive. \n\nTo integrate this equation explicitly, we use separation of variables to find that\n\\begin{align}\n&{}\\int_{y(0)}^{y(t)}\\frac{1}{\\tilde{y}^{2}}\\mathrm{d}\\tilde{y}=\\int_0^t\\mathrm{d}\\tau\n\\end{align}\nwhich implies \n\\begin{equation}\n-\\frac{1}{y(t)}=t+c\n\\end{equation}\nwhere $c$ is the constant of integration. Using our initial data we get $c=-1$, so\n\\begin{equation}\ny(t)=\\frac{1}{1-t}\n\\end{equation}\nis our exact solution for this problem. We will use this exact solution to compare the numerical solutions obtained by the different iterative methods. Notice that this exact solution becomes infinite as $t\\rightarrow1$. \n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Definitions Required to Prove Convergence}\n\n\\begin{definition}{\\bf The Lipschitz Condition}\nA function $f(x):x\\in D\\subset\\mathbb{R}$ is Lipschitz if $\\left\\Vert f(x_1)-f(x_2)\\right\\Vert \\leq\\lambda\\left\\Vert x_1-x_2\\right\\Vert $ for all $x_1$ and $x_2$ in the domain $D$.\n\\end{definition}\n\nThere are two specific definitions of the Lipschitz condition.\n\n\\begin{definition}{\\bf Locally Lipschitz Condition}\nThe function $f(x)$ is called locally Lipschitz if, for each $z\\in\\mathbb{R}$, there exists an $L>0$ such that $f$ is Lipschitz on the open ball of center $z$ and radius $L$. \n\\end{definition}\n\n\\begin{definition}{\\bf Globally Lipschitz Condition}\nIf $f(x)$ is Lipschitz on all of the space $\\mathbb{R}$ (i.e. The open ball is $\\mathbb{R}$ in above definition), then $f$ is globally Lipschitz.\n\\end{definition}\n\nNote the fundamental difference between the local and global versions of the Lipschitz-condition. Whereas in the local version the Lipschitz ``constant''($\\lambda)$ and the open ball depend on each point $x\\in\\mathbb{R}$ , in the global version the ``constant''($\\lambda)$ is fixed and the open ball is $\\mathbb{R}$. In particular, a globally Lipschitz function is locally Lipschitz continuous, but the converse is not true.\n\n\n%%%%%%%\n% Section\n%%%%%%%\n\\section{Existence and Uniqueness of Solutions to Ordinary Differential Equations}\n\nPeano's theorem states that if $f(x)$ is continuous, then a solution to the ordinary differential equation $x'(t)=f(x)$ with initial condition $x(t_0)=x_0$ exists  at least in some neighbourhood of time $t_0$ -- this solution need not be unique. Picard's theorem states that if $f(x)$ is locally Lipschitz, then the solution for the ordinary differential equation $x'(t)=f(x)$ with initial condition $x(t_0)=x_0$ is unique when it exists. A comprehensive statement of these theorems is in Iserles~\\cite[p. 445]{Ise09}, and there are proofs of these theorems in many books on ordinary differential equations (for example Birkhoff and Rota~\\cite[Chap. 6, pg.\\ 192]{BirRot89}). \n \n%%%%%%%\n%Section\n%%%%%%%\n\\section{Backward Euler}\n\nWe recall that the backward Euler method is given by\n\\begin{equation}\ny^{n+1}=y^{n}+hf(y^{n+1}).\n\\end{equation}\nNote that if $f$ is nonlinear, we need to solve a nonlinear equation in each step advancing the solution (numerical). It is usually hard to solve a nonlinear equation exactly using analytical methods, so we also use numerical methods.  For our example equation, we get\n\\begin{equation}\ny^{n+1}=y^{n}+h\\left(y^{n+1}\\right)^2\n\\end{equation}\nThis example has the advantage that we can find its solutions algebraically, so we can then examine the behavior of numerical schemes.\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Convergence of Functional Iteration}\n\nWe often use functional iteration to solve nonlinear equations. We recall that there are two popular methods: fixed-point iteration and Newton's method.\n\n%subsection\n\\subsection{Convergence of the Fixed-Point Method}\n\nWe want to find a root of $x=f(x).$ We try to use the fixed-point method and to construct a sequence $x_{n+1}=f(x_{n})$ where $n=0,1,2\\ldots$.\n\n\\begin{theorem}\nLet $f(x)$ have a fixed-point $\\tilde{x}=f(\\tilde{x})$, be Lipschitz continuous for $x\\in(a, b)\\subset\\mathbb{R}$ with Lipschitz constant $k<1$ and $f(x)$ be continuous on $[a,b]$. Then the fixed point method $x_{n+1}=f(x_{n})$ converges to the unique fixed-point of $\\tilde{x}=x_{\\infty}=f(x_{\\infty})$ for $x\\in[a,b]$.\n\\end{theorem}\n\n\\begin{proof}\nSince $f(x)$ is Lipschitz continuous, we find that, \n\\begin{equation}\n\\left|x_{n+1}-x_{\\infty}\\right|=\\left|f(x_{n})-f(x_{\\infty})\\right|\\leq k\\left|x_{n}-x_{\\infty}\\right|\n\\end{equation}\nfor $n=1,2\\ldots$. Hence by induction we conclude that \n\\begin{equation}\n\\left|x_{n+1}-x_{\\infty}\\right|\\leq k^{n}\\left|x_{1}-x_{\\infty}\\right|.\n\\end{equation}\nSince $k<1$, $\\lim_{n\\rightarrow\\infty}k^n\\lvert x_1-x_{\\infty}\\rvert=0$, so we obtain a solution $x_{\\infty}=f(x_{\\infty})$, where $x_{\\infty}$ is the fixed point. We can show that the limit is unique by supposing that there are two different limits and reaching a contradiction.\\end{proof}\n\nFor a proof of the existence of the fixed-point under the assumptions used in this theorem, see a book on numerical analysis, such as Bradie~\\cite{Bra06} or Iserles~\\cite{Ise09}.\n\nRegarding our problem, we apply fixed-point iteration, we want to find the root of an equation of the form:\n\\begin{equation}\\label{eq:Fp}\nw=hw^{2}+\\beta=f(w). \n\\end{equation}\nWhen the timestep $h$ is small enough then $f'(w)=2hw\\leq200h<1$. So fixed-point iteration is convergent provided the time-step is small enough. We note that eq.\\ \\eqref{eq:Fp} has two roots, and so the domain of the initial iterate plays an important role in determining which root is choosen.\n\n%subsection\n\\subsection{Convergence of Newton's Method}\n\nWe now consider Newton's method. We want to find a root, $x^*$ of $f(x)$ such that $f(x^*)=0.$ Newton's method is a fixed-point method where the iterates are constructed by\n\\begin{equation}\\label{eq:Newton}\nx_{n+1}=x_{n}-\\frac{f(x_{n})}{f'(x_{n})}\n\\end{equation}\nwhere $n=0,1,2\\ldots$. If the function $f(x)$ is sufficiently well behaved, then Newton's method has a quadratic rate of convergence. \n\n\\begin{theorem}\nSuppose $f(x)$ is twice continuously differentiable and that its second derivative is bounded. Suppose also that there exists $x^*$ for which $f(x^{*})=0$. Suppose $f'(x)\\neq0$ in the interval $\\left[x^{*}-\\left|x^{*}-x_{0}\\right|,x^{*}+\\left|x^{*}-x_{0}\\right|\\right]$, $f''(x)$ is finite in the same interval and $\\left\\lvert x_{0} - x^{*}\\right\\rvert$ is small. Then, Newton's method is of quadratic convergence.\n\\end{theorem}\n\n\\begin{proof}\n\\begin{equation}\nf(x^{*})=f(x_{n})+f'(x_{n})(x^{*}-x_{n})+\\frac{1}{2!}f''(z_{n})(x^{*}-x_{n})^{2}\n\\end{equation}\nby Taylor expansion with Lagrange form remainder. In the above $z_{n}\\in[x_{n},x^{*}]$. Since $f(x^*)=0$, we have \n\\begin{equation}\n0=f(x_{n})+f'(x_{n})(x^{*}-x_{n})+\\frac{1}{2!}f''(z_{n})(x^{*}-x_{n})^{2},\n\\end{equation}\nso \n\\begin{equation}\n\\frac{f(x_{n})}{f'(x_{n})}+(x^{*}-x_{n})=-\\frac{1}{2!}\\frac{f''(z_{n})}{f'(z_{n})}(x^{*}-x_{n})^{2}.\n\\end{equation}\nPlug in the formula for $x_{n+1}$, from eq.\\ \\eqref{eq:Newton}  we have \n\\begin{equation}\nx^{*}-x_{n+1}=-\\frac{1}{2!}\\frac{f''(z_{n})}{f'(z_{n})}(x^{*}-x_{n})^{2}.\n\\end{equation}\nLet\n\\begin{equation}\ne_{n}=\\left|x^{*}-x_{n}\\right|.\n\\end{equation} \nWe have \n\\begin{equation}\ne_{n+1}=\\left|\\frac{1}{2!}\\frac{f''(z_{n})}{f'(z_{n})}\\right|e_{n}^{2}\n\\end{equation}\nand by our assumption, we know there is a constant $c$ such that\n\\begin{equation}\n\\left|\\frac{1}{2!}\\frac{f''(z_{n})}{f'(z_{n})}\\right|<c.\n\\end{equation}\nHence we have $e_{n+1}<me_{n}^{2}$ for some finite constant $m$. So Newton's method is convergent provided $e_0=\\lvert x_0-x^*\\rvert$ is sufficiently small.\n\\end{proof}\n\nRegarding our problem, we consider \n\\begin{equation}\nf(y)=y-hy^{2}-\\beta.\n\\end{equation}\nHence $f'(y)=1-2hy\\neq0$ and $f\"(y)$ is finite, so our problem satisfies all assumptions if we choose our initial data and initial iterates suitably. Hence the Newton iterations will converge and give an approximation to the nonlinear term in backward Euler's method.\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Convergence of the Theta Method}\n\nThe backward Euler, forward Euler and Crank-Nicolson methods are special case of the theta method, so we will first prove the convergence of the theta method to encompass these three methods. The theta method is the following algorithm,\n\\begin{equation}\ny^{n+1}=y^{n}+h[\\theta f(t^{n},y^{n})+(1-\\theta)f(t^{n+1},y^{n+1})]\n\\end{equation}\nwhere\n$n=0,1,\\ldots$ and $\\theta\\in[0,1]$. Notice that for $\\theta=1/2$ we obtain the Crank-Nicolson method or trapezoidal rule.\n\nFirst, substituting the exact solution $y(t)$ and using the Taylor expansion we have\n\\begin{align}\n&{}y(t^{n+1})-y(t^{n})-h[\\theta f(t^{n},y(t^{n}))+(1-\\theta)f(t^{n+1},y(t^{n+1}))]\n\\\\&{}=y(t^{n+1})-y(t^{n})-h[\\theta y'(t^{n})+(1-\\theta)y'(t^{n+1})] \\notag\n\\\\&{} =[y(t^{n})+hy'(t^{n})+\\frac{1}{2}h^{2}y''(t^{n})+\\frac{1}{6}h^{3}y^{\\prime\\prime\\prime}(t^{n})] \\notag\n\\\\&{}\\hspace{2em}-y(t^{n})-h\\{\\theta y'(t^{n})+(1-\\theta)[y'(t^{n})+hy''(t^{n})+\\frac{1}{2}h^{2}y^{\\prime\\prime\\prime}(t^{n})]\\}+\\mathcal{O}(h^{4}) \\notag\n\\\\&{}=\\left(\\theta-\\frac{1}{2}\\right)h^{2}y''(t^{n})+\\left(\\frac{1}{2}\\theta-\\frac{1}{3}\\right)h^{3}y^{\\prime\\prime\\prime}(t^{n})+\\mathcal{O}(h^{4}). \\notag\n\\end{align}\nSubtracting the last expression from \n\\begin{equation}\ny^{n+1}-y^{n}-h[\\theta f(t^{n},y^{n})+(1-\\theta)f(t^{n+1},y^{n+1})]=0,\n\\end{equation}\nwe have that when $h$ is small enough\n\\begin{align}\n&{}e^{n+1,h}\n\\\\&{}=e^{n,h}+\\theta h[f(t^{n},y(t^{n})+e^{n,h})-f(t^{n},y(t^{n}))] \\notag\n\\\\&{}\\hspace{1em}+(1-\\theta)h[f(t^{n+1},y(t^{n+1})+e^{n+1,h})-f(t^{n+1},y(t^{n+1}))] \\notag\n\\\\&{} \\begin{cases}\n-\\frac{1}{12}h^{3}y^{\\prime\\prime\\prime}(t^{n})+\\mathcal{O}(h^{4}), & \\theta=\\frac{1}{2}\\\\\n+(\\theta-\\frac{1}{2})h^{2}y''(t^{n})+\\mathcal{O}(h^{3}), & \\theta\\neq\\frac{1}{2}\n\\end{cases} \\notag\n\\end{align} \nwhere $e^{i}=y^{i}-y(t^{i})$. Using the triangle inequality and by the Lipschitz continuity of $f$, there exist constants $c$ and $\\lambda$ such that \n\\begin{align}\n&{}\\left\\Vert e^{n+1,h}\\right\\Vert\n\\\\&{} \\leq\\left\\Vert e^{n,h}\\right\\Vert +\\theta h\\lambda\\left\\Vert e^{n,h}\\right\\Vert +(1-\\theta)h\\lambda\\left\\Vert e^{n+1,h}\\right\\Vert +\\begin{cases}\nch^{3} & \\theta=\\frac{1}{2}\\\\\nch^{2} & \\theta\\neq\\frac{1}{2}\n\\end{cases}. \\notag\n\\end{align}\nWhen $\\theta=\\frac{1}{2}$, the theta method reduces to the trapezoidal rule. It is possible to show that the Crank-Nicolson method has second order convergence, see for example, Iserles~\\cite{Ise09}. Now let's consider $\\theta\\neq\\frac{1}{2}$, \n\\begin{align}\n&{}\\left\\Vert e^{n+1,h}\\right\\Vert \\leq\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\left\\Vert e^{n,h}\\right\\Vert +\\frac{c}{1-(1-\\theta)h\\lambda}h^{2}. \n\\end{align}\n\nWe claim that \n\\begin{equation}\n\\left\\Vert e^{n,h}\\right\\Vert \\leq\\frac{c}{\\lambda}\\left[\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{n}-1\\right]h\n\\end{equation}\nWe prove this statement by induction.  When $n=0$, $\\left\\Vert e^{n,h}\\right\\Vert =0$, since the initial conditions is exactly calculated. Now suppose this statement is true for $n=k$, where $k\\geq0$ and is a integer. We want to show this statement is true for $n=k+1$. Consider\n\\begin{equation}\n\\left\\Vert e^{k+1,h}\\right\\Vert \\leq\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\left\\Vert e^{k,h}\\right\\Vert +\\frac{c}{1-(1-\\theta)h\\lambda}h^{2},\n\\end{equation}\nthen plug in \n\\begin{equation}\n\\left\\Vert e^{kn,h}\\right\\Vert \\leq\\frac{c}{\\lambda}\\left[\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{k}-1\\right]h.\n\\end{equation}\nWe have\n\\begin{align} \n&{} \\left\\Vert e^{k+1,h}\\right\\Vert \n\\\\&{} \\leq\\frac{c}{\\lambda}\\left[\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{k+1}-\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right]h+\\frac{c}{1-(1-\\theta)h\\lambda}h^{2} \\notag\n\\\\&{}=\\frac{c}{\\lambda}\\left[\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{k+1}-1\\right]h. \\notag\n\\end{align}\nSo our claim is true for all $n$ . Note that \n\\begin{align}\n\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda} &{}=1+\\frac{h\\lambda}{1-(1-\\theta)h\\lambda} \n\\\\&{}\\leq \\exp\\left(\\frac{h\\lambda}{1-(1-\\theta)h\\lambda}\\right) \\notag\n\\end{align}\nby a Taylor expansion of the exponential function. Thus, we have\n\\begin{align}\n\\left\\Vert e^{n,h}\\right\\Vert&{} \\leq\\frac{c}{\\lambda}\\left[\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{n}-1\\right]h\n\\\\&{}\\leq\\frac{c}{\\lambda}\\left(\\frac{1+\\theta h\\lambda}{1-(1-\\theta)h\\lambda}\\right)^{n}h \\notag\n\\\\&{}\\leq\\frac{ch}{\\lambda}\\exp\\left(\\frac{nh\\lambda}{1-(1-\\theta)h\\lambda}\\right). \\notag\n\\end{align}\nBy our condition, $nh\\leq t^{*}.$\nTherefore \n\\begin{equation}\n\\left\\Vert e^{n,h}\\right\\Vert \\leq\\frac{ch}{\\lambda}\\exp\\left(\\frac{t^{*}\\lambda}{1-(1-\\theta)h\\lambda}\\right).\n\\end{equation}\nSo we have $\\lim_{h\\rightarrow0}\\left\\Vert e^{n,h}\\right\\Vert =0$ and $0\\leq nh\\leq t^{*}$. Hence the theta method is convergent\nof order 1 when $\\theta\\neq\\frac{1}{2}.$ \n\nNote that the backward Euler method is a special case of the theta method when $\\theta=0$, so backward Euler's method is convergent of order 1. We arrive at our theorem.\n\n\\begin{theorem}\nBackward Euler's method is convergent of order 1.\n\\end{theorem}\n\n\\begin{remark}\nIf $f$ is globally Lipschitz, then we can apply the above argument with respect to any time interval. If $f$ is only locally Lipschitz, then we need to analyze the situation more carefully. First, by Picard's theorem,  there is a unique solution of this ordinary differential equation for a short amount of time.  Indeed, we just need to know that the Lipschitz constant is finite without necessarily needing to know the exact value.\n\\end{remark}\n\n\\begin{remark} If one did not know of Picard's theorem, one could deduce the existence and uniqueness of solutions to ODEs by using time discretization.\n\\end{remark}\n\nNow we consider $y'=y^{2}$ and $t\\in[0,0.99]$. The exact solution of this problem is $y(t)=\\frac{1}{1-t}$. So $1\\leq y\\leq100$. In our problem, $f=y^{2}$ is clearly analytic and it is locally Lipschitz. It is easy to show $f$ is not globally Lipschitz. If a function $f(x)$ is globally Lipschitz condition then there is a finite constant $\\lambda$ such that \n\\begin{equation}\n\\frac{\\left\\Vert f(x)-f(y)\\right\\Vert }{\\left\\Vert x-y\\right\\Vert }\\leq\\lambda\n\\end{equation}\nfor all $x,y\\in \\mathbb{R}$. In our problem, let $x=0$ and $\\left\\Vert y\\right\\Vert \\rightarrow\\infty,$ it is easy to check \n\\begin{equation}\n\\frac{\\left\\Vert f(x)-f(y)\\right\\Vert }{\\left\\Vert x-y\\right\\Vert }\\rightarrow\\infty.\n\\end{equation}\nWe now discuss how one can find local Lipschitz constants $\\lambda$. When $f$  is differentiable, we often just differentiate $f$ and find the maximum value of its derivative in the domain of interest. In our example, $f$ is simple and we only need to know that the Lipschitz constant is finite. So we use a more rough method to show that the Lipshitz constant is finite,\n\\begin{align}\n&{}\\left\\Vert f(y^{1})-f(y^{2})\\right\\Vert \n=\\left\\Vert y^{1}+y^{2}\\right\\Vert \\left\\Vert y^{1}-y^{2}\\right\\Vert \\leq\\left(\\left\\Vert y^{1}\\right\\Vert +\\left\\Vert y^{2}\\right\\Vert\\right)\\left\\Vert y^{1}-y^{2}\\right\\Vert. \n\\end{align}\nSo it suffices to find the maximal value of $\\left\\Vert y\\right\\Vert$ in this problem. In our problem, $y(t)$ is continuous. Furthermore, $y(t)$ will be positive all the time, because the initial value is positive and $y'$ is positive. A continuous function has finite maximal value in a closed and bounded set. Note that the exact solution of our problem is $y(t)=\\frac{1}{1-t}$ , so $1\\leq y\\leq100$. So we know that the Lipschitz constant in our problem is finite.\n\nFinally, we get the convergence of functional iteration and backward Euler's method of our problem. Thus our numerical scheme for $y'=y^{2}$ with initial data $y(0)=1$ and $t\\in[0,0.99]$ is convergent.\n\n\\begin{corollary}\nBy the theorems for existence and uniqueness of the solution for ordinary differential equations and Theorem 4.1 ,Theorem 4.2 and Theorem 4.3, we arrive at our final goal that the numerical solution generated by backward Euler's method with functional iteration exists and is unique when the time-step, $h0$ approaches zero.\n\\end{corollary}\n \n\\begin{remark} This requires careful choice of initial iterates when doing functional iteration.\n\\end{remark}\n\n\\begin{remark} Typically, the exact solution of an ODE is not known, although it is possible to deduce local Lipschitz continuity. Should the solution become infinite, a numerical method will either not converge or display very large values if the approximate solution closely approximates the exact solution. Some care is required in interpreting such numerical simulations in these cases.\n\\end{remark}\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Example Programs which use Iteration to Solve a Nonlinear Ordinary Differential Equation}\n\nThe following two Matlab programs demonstrate backward Euler's method for the example equation. The first one uses fixed-point iteration to solve for the nonlinear term and the second one uses Newton's method to solve for the nonlinear term. \n\n\\lstinputlisting[style=matlab_style,language=Matlab,label=lst:BEFPiterMatlab,caption={A Matlab program to demonstrate fixed-point iteration.}]{./NonlinearOdeAndIteration/Programs/BackwardEulerFixedPoint.m}\n\n\\lstinputlisting[style=matlab_style,language=Matlab,label=lst:BENewIterMatlab,caption={A Matlab program to demonstrate Newton iteration.}]{./NonlinearOdeAndIteration/Programs/BackwardEulerNewtonIteration.m}\n%%%%%%%\n%  Section\n%%%%%%%\n\\section{Exercises}\n\\begin{enumerate}\n\\item[1)] Run the fixed-point iteration program in Matlab and check that the outcome is reasonable. Now investigate how changing the number of time steps taken to go from a time of 0 to a time of 0.99, and the tolerance for fixed point iterations affects the maximum error. In particular try a range of 1,000-1,000,000 (in powers of 10) for the number of time steps and a tolerance ranging from $10^{-1}-10^{-7}$ (in powers of $10^{-1}$). You should observe that there is an ``ideal\"  combination of subdivisions and tolerance to minimize the error. What are these combinations? Do this whole process again using Newton iteration instead. How have the answers changed?\n\\item[2)] Write a Matlab program to solve $y'=y^2$ with $y(0)=1$ using the Crank-Nicolson method and fixed point iteration. Explain why there are two fixed-points to which the fixed-point iteration can converge. Which of these fixed-points gives the correct approximation to the solution of the differential equation? Comment on how the choice of initial iterate for the fixed-point iteration determines the fixed-point to which the method converges. \n\\item[3)] \n\\begin{enumerate}\n\\item[a)] Show that the differential equation $y'=\\sqrt{\\lvert y\\rvert}$, with $y(0)=0$ is not Lipschitz continuous. \n\\item[b)] Find at least two analytical solutions to this differential equation.\n\\item[c)] Compute a numerical solution to this differential equations using the forward Euler method.\n\\item[d)] Compute a numerical solution to this differential equations using the backward Euler method. Be sure to try different initial guesses for the fixed-point iteration, not just the value at the previous time step; you should be able to calculate the influence of the choice of initial iterate on the selection of solution by the numerical method. Comment on this.\n\\item[e)] Compute a numerical solution to this differential equations using the implicit midpoint rule. Be sure to try different initial guesses for the fixed point iteration, not just the value at the previous time step; you should be able to calculate the influence of the choice of initial iterate on the selection of ``solution'' by the numerical method. Comment on this.\n\\item[f)] Repeat (d) and (e) with Newton iteration.\n\\item[g)] Comment on the applicability of numerical methods for solving differential equations without unique solutions.\n\\end{enumerate}\n\\item[4)] Modify the program for the 1-D Allen-Cahn equation so that it uses the Crank-Nicolson and fixed-point iteration for the nonlinear term. You will need to calculate the nonlinear term in real space, so that your resulting scheme is\n\\begin{equation}\n\\frac{\\hat{u}^{n+1,k+1}-\\hat{u}^n}{\\delta t}=\\frac{\\hat{u}_{xx}^{n+1,k+1}+\\hat{u}^n_{xx}}2 + \\frac{1}{2}\\widehat{\\left[u^{n+1,k}- \\left(u^{n+1,k} \\right)^3\\right]}+\\frac{1}{2}\\widehat{\\left[u^{n}- \\left(u^{n}\\right)^3\\right]},\n\\end{equation}\nwhere $n$ denotes the time step and $k$ denotes the iterate. Stop the iterations once the maximum difference between successive iterates is sufficiently small.\n\\item[5)] Modify the program for the 2-D Allen-Cahn equation so that it uses the Crank-Nicolson method and fixed-point iteration for the nonlinear term. You will need to calculate the nonlinear term in real space.\n\\end{enumerate}\n", "meta": {"hexsha": "40744a146f9ddf9e33193511b9d78fcd771f767f", "size": 23022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NonlinearOdeAndIteration/NonlinearOdeAndIteration.tex", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "NonlinearOdeAndIteration/NonlinearOdeAndIteration.tex", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "NonlinearOdeAndIteration/NonlinearOdeAndIteration.tex", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 69.7636363636, "max_line_length": 675, "alphanum_fraction": 0.7185735384, "num_tokens": 7179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.6083213216865041}}
{"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\\textbf{Disclaimer.} This is the reasoning I used to solve the problem; it\nmay be wrong though. This is intended just as food for thought.\n\n\\section{Regularization With Polynomials}\n\nThis question asks about a hypothesis set based on the Legendre polynomial\n$L_{10}(x)$:\n\n\\begin{equation*}\nL_{10}(x) = \\frac{1}{256}(46189x^{10} - 109395x^8 + 90090x^6 - 30030x^4 + 3465x^2 - 63)\n\\end{equation*}\n\nThe regularization parameter $C$ can be either 0 or 1; when $C=0$, all terms\nin the polynomial with degree $d \\geq Q_o$ are cancelled.\n\n\\subsection{The Answer}\n\nThe correct answer to this question can be found just by proving the first\noption wrong.\n\nThe first option, $\\mathcal{H}(10,0,3) \\cup \\mathcal{H}(10,0,4) = \\mathcal{H}_4$,\nis incorrect because the regularization on both $\\mathcal{H}(10,0,3)$ and\n$\\mathcal{H}(10,0,4)$ ommits the same terms on the polynomial, resulting in\n\n\\begin{equation*}\nL_{10}'(x) = \\frac{1}{256}(3465x^2 - 63),\n\\end{equation*}\n\nso the union $\\mathcal{H}(10,0,3) \\cup \\mathcal{H}(10,0,4)$ cannot possibly be\n$\\mathcal{H}_4$. However, it's plausible that the intersection\n$\\mathcal{H}(10,0,3) \\cap \\mathcal{H}(10,0,4)$ might be $\\mathcal{H}_2$.\n\n\\end{document}\n", "meta": {"hexsha": "78793ecd0c75b8416e00bb7cc78921fc076a9310", "size": 1363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-06/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-06/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-06/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": 29.6304347826, "max_line_length": 87, "alphanum_fraction": 0.7175348496, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.608286986370662}}
{"text": "\\documentclass{amsart}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n%\\usepackage{a4wide}\n%\\usepackage{enumerate}\n\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\Z}{\\mathbb{Z}}\n\\DeclareMathOperator{\\Spa}{Spa}\n\\DeclareMathOperator{\\Spv}{Spv}\n\\DeclareMathOperator{\\pre}{pre}\n\n\\theoremstyle{plain}\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{corollary}[theorem]{Corollary}\n\\newtheorem{proposition}[theorem]{Proposition}\n\\theoremstyle{remark}\n\\newtheorem{remark}[theorem]{Remark}\n\\newtheorem*{remarkn}{Remark}\n\n\\begin{document}\n\n\\title{Projective limits.}\n\\maketitle\n\n\\section{The set-up}\n\nLet $X$ be a type and let $R$ be a preorder on $X$ (that is, a binary relation which is reflexive and transitive). Corresponding to $(X,R)$ is a ``small thin category'' (``small'' means the objects form a set, ``thin'' apparently means that there's at most one morphism between any two objects). We have to make a choice here: let's be covariant (it doesn't matter). So if $x\\ R\\ y$ then there's a morphism from $x$ to $y$.\n\nIf now $i$ is a (covariant) functor from $(X,R)$ to some category $\\mathcal{C}$ then for all $x\\in X$, $A_x:=i(x)$ is an object of $\\mathcal{C}$, and for all $x\\ R\\ y$ we have a morphism $f_{xy}:=i(x\\ R\\ y)$ from $A_x$ to $A_y$. If $\\mathcal{C}$ has all limits, then one can take the (projective) limit of $i$; in the category of commutative rings or types this would be the subring of the product ring $\\prod_{x\\in X}A_x$ consisting of elements $(a_x)_{x\\in X}$ such that $f_{xy}(a_x)=a_y$.\n\n{\\it TODO.} If $\\mathcal{C}$ is the category of topological rings, is the projective limit still the same thing, equipped with subspace topology of the product topology? Surely this is true but I never checked. I will remark that a sheaf of topological rings is not just a presheaf of topological rings such that the underlying presheaf of rings is a sheaf; I believe one needs the ring isomorphism between $\\mathcal{F}(U)$ and the relevant subspace of $\\prod_i\\mathcal{F}(U_i)$ to be a homeomorphism, not just continuous.\n\nNow say $S$ is a sub-preorder of $R$, that is, $S$ is another preorder on $X$ and $x\\ S\\ y\\implies x\\ R\\ y$. This can certainly happen -- for example every equivalence relation is a preorder, so just imagine splitting up $R$'s equivalence classes into smaller ones. As another example one can imagine the usual total order on $\\{1,2,3\\}$ and then a subrelation where $1\\leq 3$ and $2\\leq 3$ but $1$ is no longer at most 2.\n\nThere's a natural functor $(X,S)\\to(X,R)$. So the functor $i:(X,R)\\to\\mathcal{C}$ which sends $x$ to $A_x$ and sends the morphism $x\\ R\\ y$ to $f_{xy}:A_x\\to A_y$, induces a functor $j:(X,S)\\to\\mathcal{C}$ which still sends $x$ to $A_x$ and $x\\ S\\ y$ to $f_{xy}:A_x\\to A_y$. If $\\mathcal{C}$ has all small limits one could ask what the relationship between the limits $A_R$ of $i$ and $A_S$ of $j$ is. First a thought experiment: in the category of types one can see that there is a natural map from $A_R$ to $A_S$; the $j$-limit is a (possibly) bigger subset of the same product. But of course general nonsense gives you a morphism from $A_R$ to $A_S$ in general; as part of the package of the universal object $A_R$ we know that for all $x\\in X$ there's a map from $A_R$ to $A_x$, and these maps commute with all the $f_{xy}$ for $x\\ R\\ y$ and hence for all the $f_{xy}$ with $x\\ S\\ y$; now by the universal property of $A_S$ we get a map from $A_R$ to $A_S$.\n\nIn this note I'll explain a criterion for this map to be an isomorphism in $\\mathcal{C}$.\n\n\\section{The criterion.}\n\nSay the sub-preorder $S$ has the following property: For all $x,y\\in X$, if $x\\ R\\ y$ then there exists $z\\in X$ such that $x\\ S\\ z$, $y\\ S\\ z$ and $z\\ R\\ y$. What does this buy us? Well, $y\\ S\\ z$ implies $y\\ R\\ z$, and then $z\\ R\\ y$ implies that $y$ and $z$ are $R$-isomorphic and hence $f_{yz}$ is an isomorphism in $\\mathcal{C}$. In particular even though it might not be true that $x\\ S\\ y$, it is true that $x\\ S\\ z$ and that $y$ and $z$ are $R$-isomorphic. In particular the morphism $f_{xy}:A_x\\to A_y$ coming from $R$ is isomorphic in $\\mathcal{C}$ to the $S$-morphism $f_{xz}:A_x\\to A_z$.\n\nI claim that if $S$ has this property, then the $i$-limit $A_R$ and the $j$-limit $A_S$ are isomorphic. The fact that $S\\subseteq R$ gives us a map from the $i$-limit to the $j$-limit as we saw above; what we need is a map from the $j$-limit to the $i$-limit. We want to get this map by using the universal property of the $i$-limit; to do this we need to check that the $j$-limit $A_S$ equipped with its maps $\\pi_x:A_S\\to A_x$ satisfies $f_{xy}\\circ\\pi_x=\\pi_y$ for all $x,y$ with $x\\ R\\ y$. What we know (as part of the package of the universal object $A_S$) is that this is true if $x\\ S\\ y$. But now say $x\\ R\\ y$. By our hypothesis on~$S$ we can choose $z$ with $x\\ S\\ z$, $y\\ S\\ z$ and $z\\ R\\ y$; hence $f_{yz}$ is an isomorphism and to prove $f_{xy}\\circ\\pi_x=\\pi_y$ it to prove this after applying $f_{yz}$.\n\nIt thus suffices to prove $f_{yz}f_{xy}\\pi_x=f_{yz}\\pi_y$; but the left hand size is $f_{xz}\\pi_x$ because $i$ is a functor, and hence both sides are $f_z$ because $x\\ S\\ z$ and $y\\ S\\ z$. Hence both sides are equal and by the universal property of $A_R$ we get a map $A_S\\to A_R$. The composite maps in both directions commute with all triangles formed by the maps $A_R\\to A_x$ and $A_S\\to A_x$ so must be the identity map by uniqueness.\n\n\\end{document}\n", "meta": {"hexsha": "91571e60bfcb950560910adcfb85e8adb7690522", "size": 5428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX_docs/cutting_corners.tex", "max_stars_repo_name": "semorrison/lean-perfectoid-spaces", "max_stars_repo_head_hexsha": "bb4311dff45791170bcb1b6a983e2591bee88a19", "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_docs/cutting_corners.tex", "max_issues_repo_name": "semorrison/lean-perfectoid-spaces", "max_issues_repo_head_hexsha": "bb4311dff45791170bcb1b6a983e2591bee88a19", "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_docs/cutting_corners.tex", "max_forks_repo_name": "semorrison/lean-perfectoid-spaces", "max_forks_repo_head_hexsha": "bb4311dff45791170bcb1b6a983e2591bee88a19", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-11T11:57:58.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-11T11:57:58.000Z", "avg_line_length": 108.56, "max_line_length": 961, "alphanum_fraction": 0.7048636699, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6082869700249236}}
{"text": "\\section{Overview of the core language}\n\\subsection{Expressions}\nThere are two kind of expressions for an object in a type:\n\\begin{description}\n\\item[Application:] This is always on the form \\verb|i e1 ... en|,\n  where \\verb|i| is an identifier (a constant or a variable).\n\\item[Abstraction:] This is always on the form \\verb|\\x -> e| where\n  \\verb|x| is a variable.\n\\end{description}\nWe have the following expressions for types:\n\\begin{description}\n\\item[Set:] The type of sets is \\verb|Set|.\n\\item[Functions:] The dependent function type is denoted by  \\verb|(x : E) -> E'|.\n\\item[Elements in a set:] If the object expression \\verb|E| has the\n  type \\verb|Set|, then we use the notation \\verb|E| for the type of\n  elements in \\verb|E|. Hence, we can use applications and\n  abstractions to form type expressions.\n\\end{description}\n\n\\subsection{Declarations}\nA program is a list of declarations, each of which is on one of the\nforms:\n\\begin{description}\n\\item[Typing declaration:] This has the form \\verb|c : E| and it\n  introduces the constant \\verb|c| of the type \\verb|E|.\n\\item[Explicit definition:] This has the form \\verb|c = e| and defines\n  the constant \\verb|c| to be equal to the expression \\verb|e|.\n\\item[Implicit definition:] A declaration of an implicitly defined\n  constant \\verb|f| has the shape\n\\begin{verbatim}\nfun f (x1:t1) ... (xn:tn) : te =\n                 c1 y1 ... ym -> e1 |\n                    ...\n                 ck z1 ... zm -> ek\n\\end{verbatim}\nHere \\verb|c1| \\dots \\verb|ck| are constructors for the data type \\verb|te|.\nThe intuition is that the constant \\verb|f| is defined so that \n\\begin{verbatim}\nf x1 ... xn (c1 y1 ... ym) = e1\n                          ...\nf x1 ... xn (ck z1 ... zl) = ek\n\\end{verbatim}\n\n\\item[Data declaration:] A data type (i.e. an object in \\verb|Set|) is\n  defined by giving the typing of its constructors:\n\\begin{verbatim}\n data D (x1:t1) ... (xn:tn) :tm =\n                c1 : e1| \n                  ... \n                cn : en\n\\end{verbatim}\n\\end{description}", "meta": {"hexsha": "8e67d3d5d0ac34fb6841d89e9e43f8426f368db0", "size": 2022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/core/overview.tex", "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_issues_repo_path": "src/core/overview.tex", "max_issues_repo_name": "masondesu/agda", "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_licenses": ["MIT"], "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/core/overview.tex", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 38.8846153846, "max_line_length": 82, "alphanum_fraction": 0.6538081108, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6082767511961155}}
{"text": "\\problemname{Antimatter Rain}\n\nYou've heard of acid rain but have you heard of antimatter rain?\nAntimatter rain is so potent that when it comes into contact\nwith another object, it immediately disintegrates\nboth itself and the object.\nKayla's job as a SpaceFleet\nResearcher is gathering weather data on exotic planets.\nThis time, their assignment is to monitor the antimatter\nrainfall.\n\nSensors are set up in the planet's atmosphere and are about\nto be rained on with antimatter rain. Oh no! Kayla monitors a\nsingle 2D section. Each sensor is either a single horizontal strip\nor a single point. When one or more antimatter droplet fall\non a single sensor, all of those droplets and the sensor\ndisintegrate simultaneously. That is, they disappear. All other\ndroplets will drop past where the sensor used to be.\n\nKayla sees all the antimatter rain drops the moment before\nthey all start to fall. All droplets fall at exactly the same\nrate.\n\nFor each droplet, Kayla wants to know if and where it\nwill disintegrate. Help them out with this demanding task!\n\n\\begin{center}\n \\includegraphics[width=0.4\\textwidth]{antimatter.pdf}\n\\end{center}\nIllustration of the first sample. The vertical lines connect\nthe drops to the sensor they hit. The drop with no associated vertical\nline will not hit any sensor.\n\n\\section*{Input}\n\nThe first line of input contains two integers $D$ ($1 \\leq D \\leq 100\\,000$),\nwhich is the number of antimatter droplets, and $S$ ($1 \\leq S \\leq 100\\,000$),\nwhich is the number of sensors.\n\nThe next $D$ lines describe the droplets, in order. Each of these lines contains two\nintegers $x$ ($1 \\leq x \\leq 10^9$), which is the $x$-coordinate of the droplet\nand $y$ ($1 \\leq y \\leq 10^9$), which is the $y$-coordinate of the droplet.\n\nThe next $S$ lines describe the sensors. Each line contains three integers\n$x_1$, $x_2$ ($1 \\leq x_1 \\leq x_2 \\leq 10^9$), which is the leftmost and the rightmost\n$x$-coordinate of the sensor, and $y$ ($1 \\leq y \\leq 10^9$), which is the\n$y$-coordinate of the sensor.\n\nIt is guaranteed that no two drops will start in the same location, no drop will\nstart on any sensor, and no two sensors touch (not even at a single point).\n\n\\section*{Output}\nFor each droplet, in order, display a single number indicating the $y$-coordinate that it will disintegrate.\nIf the droplet does not disintegrate, display $0$ instead.\nThese values should appear on separate lines.\n", "meta": {"hexsha": "3b23d94c15ddc80e4ad20bdff19699449f0941c0", "size": 2409, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/antimatterrain/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/antimatterrain/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/antimatterrain/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": 43.0178571429, "max_line_length": 108, "alphanum_fraction": 0.7654628477, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6082767503657921}}
{"text": "\\paragraph{Zonotope} $\\hat{x_j} = a_0^j + \\sum_{i=1}^k a_i^j \\epsilon_i$, $\\epsilon_i \\in [-1, 1]$\n\\paragraph{Symmetry} center is $a_0$, $2 \\cdot a_0 - X$ is $X$ flipped\n\\paragraph{Affine} Zonotope is linear\n\\paragraph{ReLU} Enumerate $\\epsilon_i \\in [-1,1]$ to find $l_x$, $u_x$. \nIf $u_x \\le 0$, $\\hat{y} = 0$. If $l_x \\ge 0$, $\\hat{y} = \\hat{x}$. \nOtherwise, $\\hat{y} = \\lambda \\hat{x} - \\epsilon_\\text{new} \\frac{\\lambda l_x}{2} - \\frac{\\lambda l_x}{2}$, $\\lambda := \\frac{u_x}{u_x-l_x}$", "meta": {"hexsha": "2325defcafb1a234f3ab7af426af2c5b4904f5a5", "size": 491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "zonotope.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": "zonotope.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": "zonotope.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": 81.8333333333, "max_line_length": 140, "alphanum_fraction": 0.6089613035, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.6723317123102956, "lm_q1q2_score": 0.6082252398500979}}
{"text": "%---------------------------Maximum Aspect Frobenius-----------------------------\n\\section{Maximum Aspect Frobenius}\n\nFor quadrilaterals, there is not a unique definition of the aspect Frobenius.\nInstead, we use the aspect Frobenius\ndefined for triangles (see section~\\S\\ref{s:tri-aspect-Frobenius}).\nConsider the four triangles formed by pairs of neighboring quadrilateral edges.\nGiven three counterclockwise, consecutively ordered quadrilateral vertices $i$, $j$, and $k$\ndenote the triangular aspect frobenius $F_{ijk}$.\nTo obtain a single value for the metric, we take the maximum of the four unique triangular aspects\n\\[\n  q = \\max\\left(F_{301}, F_{012}, F_{123}, F_{230}\\right).\n\\]\n\n\\quadmetrictable{maximum 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 square\n{\\cite{pebay:04}}%                          Citation\n{v\\_quad\\_max\\_aspect\\_frobenius}%          Verdict function name\n\n", "meta": {"hexsha": "ef184c401f45eae8b1d00a0f03de7455f773b35f", "size": 1136, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadMaxAspectFrobenius.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/QuadMaxAspectFrobenius.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/QuadMaxAspectFrobenius.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": 47.3333333333, "max_line_length": 98, "alphanum_fraction": 0.5871478873, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8354835493924953, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6082115168533095}}
{"text": "%!TEX root = ../notes.tex\n\\section{April 22, 2022}\n\\subsection{Short Vectors \\emph{continued}}\n\\recall last class we stated Hermite's Theorem:\n\\begin{theorem*}[Hermite's Theorem]\n    Let $L$ be a lattice of dimension $n$. Then $0\\neq v\\in L$ with\n    \\[||\\bvec{v|}|\\leq \\sqrt{n}\\cdot \\det(L)^\\frac{1}{n}\\]\n\\end{theorem*}\n\\begin{proof}\n    Apply Minkowski's Theorem to the cube\n    \\[S = \\left\\{ (x_1, \\dots, x_n) \\Bigm\\vert -\\det(L)^{1/n}\\leq x_i \\leq \\det(L)^{1/n} \\right\\}\\]\n    Minkowski's states that $S$ contains a nonzero lattice vector. By inspection, this lattice vector $\\bvec{v}\\in S$ implies that\n    \\[||\\bvec{v}|| \\leq \\underbrace{\\sqrt{(\\det(L)^{1/n})^2 + \\cdots + (\\det(L)^{1/n})^2}}_{n\\text{ times}} = \\sqrt{n}(\\det(L)^{1/n})\\]\n\\end{proof}\n\n\\begin{theorem*}[Variant of Hermite's Theorem]\n    There is a basis $\\bvec{v}_1, \\dots, \\bvec{v}_n$ with\n    \\[||\\bvec{v}_1||\\cdot||\\bvec{v}_2||\\cdots ||\\bvec{v}_n|| \\leq n^{n/2}\\det(L)\\]\n\\end{theorem*}\n\\begin{definition}[Hadamard Ratio]\n    The \\ul{Hadamard Ratio} is\n    \\[\\mathcal{H} = \\left( \\frac{|\\det(L)|}{||\\bvec{v}_1||\\cdot||\\bvec{v}_2||\\cdots ||\\bvec{v}_n||} \\right)^{1/n}\\]\n\\end{definition}\n\nThe variant of Hermite's Theorem says that there is a basis for which $\\mathcal{H}\\geq \\frac{1}{\\sqrt{n}}$. For any basis, $0 < \\mathcal{H}\\leq 1$. $\\mathcal{H} = 1$ if and only if our basis is orthogonal.\n\nThis ratio makes precise how orthogonal our basis is.\n\nWe can write this in code (\\emph{now enhanced with NumPy!}):\n\\lstinputlisting[]{code/linalg_np.py}\n\nInstead of using a hypercube, we can use a hypersphere. Let\n\\[S = B_R(\\bvec{0}),\\]\na ball with radius $R$ centered at $0$. Minkowski's theorem says $S$ contains a nonzero lattice vector if $\\textsf{Vol}(B_R(\\bvec{0})) \\geq 2^n\\cdot \\det(L)$. Let $\\textsf{Vol}(B_R(\\bvec{0})) = C_n\\cdot R^n$ where $C_n$ is the volume of a unit ball in $n$ dimensions.\n\nThis is also to say that\n\\[R\\geq \\frac{2}{C_n^{1/n}}\\det(L)^{1/n}\\]\nFact from analysis/calculus (Stirling's Formula):\n\\[\\lim_{n\\to\\infty}C_n^{1/n}\\cdot\\sqrt{n} = \\sqrt{2\\pi e}.\\]\nThe key point is\n\\[R\\geq \\frac{2}{C_n^{1/n}}\\det(L)^{1/n} \\approx \\sqrt{\\frac{2}{\\pi e}}\\sqrt{n}(\\det(L))^{1/n}\\]\n\n\\begin{ques*}\n    What is the real truth? Given a random lattice, how long is the shortest vector? What is the actual length (probably)?\n\\end{ques*}\nHow many lattice points \\emph{``should''} a ball of radius $R$ contain? Probably the volume divided by the volume of the fundamental domain:\n\\[\\frac{\\mathsf{Vol}(S)}{\\mathsf{Vol(\\mathcal{F})}} = \\frac{\\mathsf{Vol}(S)}{\\det(L)}.\\]\nSo when \\emph{should} $B_R(\\textbf{0})$ contain nonzero $\\bvec{v}\\in L$? This is probably when $\\mathsf{Vol}(B_R(\\bvec{0})) \\geq \\det(L)$.\n\nIt's around when\n\\[R \\geq \\sqrt{\\frac{1}{2\\pi e}}\\sqrt{n}(\\det(L))^{1/n}\\]\n\n\\begin{definition}[Gaussian Expected Shortest Length]\n    $\\sigma(L) = \\sqrt{\\frac{n}{2\\pi e}}\\cdot (\\det(L))^{1/n}$ is called the \\ul{Gaussian expected shortest length}.\n\\end{definition}\nWe \\emph{expect} $||\\bvec{v}_\\mathsf{shortest}||\\approx\\sigma(L)$. We \\emph{know} $||\\bvec{v}_\\mathsf{shortest}||\\lesssim 2\\cdot \\sigma(L)$\n\n\\subsection{Babai's Algorithm}\n\\emph{Goal:} we want to solve, approximately, the closest vector problem. We have $L\\subseteq\\RR^n$ with basis $\\bvec{v}_1, \\dots, \\bvec{v}_n$. We have some $\\bvec{w}\\in\\RR^n$. We want to find a close lattice vector to $\\bvec{w}$. That is, we want \\[a_1, a_2, \\dots, a_n\\in\\ZZ\\] where $||\\bvec{w} - \\sum a_i\\bvec{v}_i||$ is small.\n\n\\emph{Method:}\n\\begin{enumerate}\n    \\item Write $\\bvec{w} = \\alpha_1\\bvec{v}_1 + \\cdots \\alpha_n\\bvec{v}_n$.\n    \\item Round $\\alpha_i$ to nearest integer $a_i$.\n\\end{enumerate}\n\n\\begin{ques*}\n    When does this work well?\n\\end{ques*}\n\nWe implement this in code:\n\\lstinputlisting[]{code/babai.py}\n", "meta": {"hexsha": "763b81813472c6f08261d3178a67f16d8ab74139", "size": 3753, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-04-22.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-04-22.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-04-22.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": 51.4109589041, "max_line_length": 330, "alphanum_fraction": 0.6514788169, "num_tokens": 1414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6082115029764283}}
{"text": "\\section{Discussion}\\label{sec:discussion}\nIn this section, we will elaborate on the interpretation of some results, reflect on some concepts,\nand connect to the current and future research.\n\nSec.~\\ref{sec:data-encoding} explained the three different encoding methods leveraged in this\nresearch and cited some literature on the effect of encoding on network accuracy. Mathematically\nspeaking, encoding is seen as feature transformation $\\mathcal{T}$, where a character $X$ is\ntransformed to $\\mathcal{T}(X)$ in the new encoding space. Since the lossless encoding is\ninvertible, it is clear for any two functions (networks) and any two encodings (transformations)\nthat\n$\\eta_1\\left(\\mathcal{T}_1(X)\\right) = \\left(\\eta_1\\cdot\\mathcal{T}_1\\cdot\n  \\mathcal{T}_2^{-1}\\right)\\left(\\mathcal{T}_2(X)\\right) =\n\\eta_2\\left(\\mathcal{T}_2(X)\\right)$. This means that if the network $\\eta_1$ is the most accurate\nnetwork for the encoding $\\mathcal{T}_1$, using another encoding $\\mathcal{T}_2$ for the same\nproblem requires designing another network\n$\\eta_2 = \\eta_1\\cdot\\mathcal{T}_1\\cdot \\mathcal{T}_2^{-1}$. However, this network may be of\ncomplicated architecture to be able to ``decode'' a terse or complex pattern $\\mathcal{T}_2(X)$. The\nbehavior of the three encodings BinE, OneE, and TwoE in this paper can be seen in the light of this\ndiscussion. The most terse representation is the BinE ($n=8$) and the most sparse representation is\nthe OneE ($n=181$); and in between comes our TwoE ($n=41$) as a smart design and compromise between\nthe low dimensionality of BinE and the self-decoded nature of the OneE\n(Sec.~\\ref{sec:data-encoding}). This may be a qualitative interpretation to why the accuracy of the\nbest models was always possessed by the TwoE, yet with one exception at the BinE\n(Sec.~\\ref{sec:arabic-results}). However, from Figures~\\ref{fig:ArabicModelsResults} and\n\\ref{english_results}, the rug plots reveal that the populations of accuracy at different\nencodings do interleave and each encoding can perform better than others at some experiments. We\nemphasize that this effect is an artifact to the non exhaustive network configuration parameters and\nexperiments conducted in this research. Had we covered the configuration parameter space then all\nencoding methods would produce the same accuracy, yet at different network architectures, as each\nencoding requires the right network architecture to learn from (or to ``decode'').\n\n\nSec.~\\ref{sec:param-netw-conf} detailed the network configuration parameters for both Arabic\ndatasets (\\{4L, 7L\\} $\\times$ \\{82U, 50U\\} $\\times$ \\{0W, 1W\\} $\\times$ \\{LSTM, BiLSTM\\} = 16\nnetworks) and for English dataset (\\{3L, 4L, 5L, 6L, 7L, 8L\\} $\\times$ \\{30U, 40U, 50U, 6U\\}\n$\\times$ \\{LSTM,\\ BiLSTM,\\ GRU,\\ BiGRU\\} = 96 networks). Each experiment runs almost in one hour (30\nepochs $\\times$ 2 min/epoch) on the mentioned hardware (Sec.~\\ref{sec:model}). The total run time of\nall network configurations on all data representations for both Arabic and English datasets was\n$16\\times 12+96\\times 2 = 384$ hours, i.e., more than two weeks! We are currently working on more\nexhaustive set of experiments to cover a good span of the network configuration parameter space to\nboth confirm the above discussion on encoding and to boost the per-class accuracy on both datasets.\n\n\\bigskip\n\nThe per-class accuracy for both datasets needs investigation; in particular, the interesting trend\nbetween the per-class accuracy and the class size of the Arabic dataset needs more investigation. We\nspeculate that this is a mere correlation that does not imply causation; and the reason for this\ntrend may be attributed to the difficulty of, or the similarity between, the meters having small\nclass size. This difficulty, or similarity, may be what is responsible for the low accuracy\n(Figure~\\ref{fig:footn-both-models}) on a hand, and the lack of interest of poets to compose at\nthese meters, which resulted in their scarcity (Figure~\\ref{fig:footn-footn-class}), on the other\nhand.\n\nDiacritic effect is explained in Sec.~\\ref{sec:results}; experiments with diacritics scored higher\nthan those without diacritics only when small class size were trimmed from the datasets (1T). When\nincluding the whole dataset (0T) the effect of diacritics was not consistent. This interesting\nphenomenon needs more investigation, since the phonetic pattern of any meter is uniquely identified\nby diacritics (Sec.~\\ref{sec:arab-poetry-text}). This may be connected to the observation above of\nthe per-class accuracy.\n\n\nFor more investigation of both phenomena, we are working on a randomized-test-like experiments in\nwhich all classes will be forced to have equal size $n$. We will study how the per-class accuracy or\noverall accuracy, along with their two individual components (precision and recall), behave and how\nthe diacritic effect changes in terms of both $n$ and the number of involved classes $k$, where\n$2 \\leq k \\leq K$, and $K(=16)$ is the total number of meters.\n", "meta": {"hexsha": "ca919ea464f96399dc9e4518c1220c082213c08f", "size": 4991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX/LaTeX-Manuscript-Template/s_Discussion.tex", "max_stars_repo_name": "DrWaleedAYousef/My-Stuff-To-Share", "max_stars_repo_head_hexsha": "d6a4b2a4e5a61fee85318177213b63590928d123", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 45, "max_stars_repo_stars_event_min_datetime": "2017-05-26T07:26:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:24:00.000Z", "max_issues_repo_path": "LaTeX/LaTeX-Manuscript-Template/s_Discussion.tex", "max_issues_repo_name": "DrWaleedAYousef/My-Stuff-To-Share", "max_issues_repo_head_hexsha": "d6a4b2a4e5a61fee85318177213b63590928d123", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-12T17:47:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-01T13:00:08.000Z", "max_forks_repo_path": "LaTeX/LaTeX-Manuscript-Template/s_Discussion.tex", "max_forks_repo_name": "DrWaleedAYousef/My-Stuff-To-Share", "max_forks_repo_head_hexsha": "d6a4b2a4e5a61fee85318177213b63590928d123", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2018-08-16T16:01:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T16:35:57.000Z", "avg_line_length": 74.4925373134, "max_line_length": 100, "alphanum_fraction": 0.7773993188, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6081841477522874}}
{"text": "\\section{Bayesian Preference Learning for Crowds}\\label{sec:model}\n\nWe assume that a pair of items, $a$ and $b$, have utilities\n$f(\\bs x_a)$ and $f(\\bs x_b)$, which represent their value to a user,\nand that $f: \\mathbb{R}^D \\mapsto \\mathbb{R}$ \nis a function of item features, where $\\bs x_a$ and $\\bs x_b$ are vectors \nof length $D$ containing the features of items $a$ and $b$, respectively.\nIf $f(\\bs x_a) > f(\\bs x_b)$, then $a$ is preferred to $b$ (written $a \\succ b$).\nThe outcome of a comparison between $a$ and $b$ is \na pairwise label, $y(a, b)$.\nAssuming that pairwise labels never contain errors,\nthen $y(a, b)=1$ if $a \\succ b$ and $0$ otherwise.\nGiven knowledge of $f$, we can compute the utilities \nof items in a test set given their features, and the outcomes of pairwise comparisons.\n\n\\citet{thurstone1927law} proposed the random utility model,\nwhich relaxes the assumption that pairwise labels, $y(a, b)$,\nare always consistent with the ordering of $f(\\bs x_a)$ and $f(\\bs x_b)$.\nUnder the random utility model, the likelihood $p(y(a,b)=1)$ \nincreases as $f_a - f_b$ increases, i.e.,\nas the utility of item $a$ increases\nrelative to the utility of item $b$.\nThis reflects the greater consistency in a user's choices\nwhen their preferences are stronger,\nwhile accommodating\n%However, since $0 < p(y(a,b)=1) < 1$, the model \n%is uncertain about the value of $y(a,b)$,\nlabelling errors or variations in a user's choices over time.\n%The uncertainty is lower if the values $f_a$ and $f_b$ are further apart, \n%which \n%The random utility model is defined by a likelihood function that\n%maps the utilities to $p(y(a,b))$.\n%or the Thurstone-Mosteller model.\n%\\begin{align}\n%p(y(a, b) | f) & = \\frac{1}{1 + \\exp( f(\\bs x_a) - f(\\bs x_b) ) }\n%\\end{align}\nIn the Thurstone-Mosteller model, % case V model, \nnoise in the observations is explained by a Gaussian-distributed noise term, $\\delta \\sim \\mathcal{N}(0, \\sigma^2)$:\n\\begin{flalign}\n p(y(a, b) | f(\\bs x_a) + \\delta_{a}, f(\\bs x_b) + \\delta_{b} )  \n \\hspace{0.9cm} & = \\begin{cases}\n 1 & \\text{if }f(\\bs x_a) + \\delta_{a} \\geq f(b) + \\delta_{b} \\\\\n 0 & \\text{otherwise,}\n \\end{cases} &\n \\label{eq:thurstone}\n\\end{flalign}\nIntegrating out the unknown values of $\\delta_a$ and $\\delta_b$ gives:\n\\begin{flalign}\n& p( y(a, b) | f(\\bs x_a), f(\\bs x_b) )  & \\label{eq:plphi}\\\\\n& = \\!\\! \\int\\!\\!\\!\\! \\int \\!\\! p( y(a, b) | f(\\bs x_a) + \\delta_{a}, f(\\bs x_b) + \\delta_{b} ) \\mathcal{N}\\left(\\delta_{a}; 0, \\sigma^2\\right)\\mathcal{N}\\left(\\delta_{b}; 0, \\sigma^2\\right) d\\delta_{a} d\\delta_{b} \n%= \\Phi\\left(\\frac{f(\\bs x_a) - f(\\bs x_b)}{\\sqrt{2\\sigma^2}}\\right) \n= \\Phi\\left( z \\right), & \\nonumber\n\\end{flalign}\nwhere $z = \\frac{f(\\bs x_a) - f(\\bs x_b)}{\\sqrt{2\\sigma^2}}$,\nand $\\Phi$ is the cumulative distribution function of the standard normal distribution,\nmeaning that $\\Phi(z)$ is a \nprobit likelihood.\\footnote{Please note that a full list of symbols is provided for reference in Appendix $\\ref{sec:not}$}\nThis likelihood is also used by\n\\citet{chu2005preference} for Gaussian process preference learning (GPPL), but here \nwe simplify the formulation by assuming that $\\sigma^2 = 0.5$,\nwhich leads to $z$ having a denominator of $\\sqrt{2 \\times 0.5}=1$,\nhence $z = f(\\bs x_a) - f(\\bs x_b)$.\nInstead, we model varying degrees of noise in the pairwise labels\nby scaling $f$ itself, as we describe in the next section.\n\nIn practice, $f(\\bs x_a)$ and $f(\\bs x_b)$ must be inferred from\npairwise training labels, $\\bs y$,\nto obtain a posterior distribution over their values.\nIf this posterior is a multivariate Gaussian distribution,\nthen the probit likelihood allows us to analytically marginalise \n$f(\\bs x_a)$ and $f(\\bs x_b)$\nto obtain the probability of a pairwise label:\n\\begin{flalign}\np(y(a,b)| \\bs y) \n= \\Phi(\\hat{z}),& & \\hat{z} = \\frac{\\hat{f}_a - \\hat{f}_b}{\\sqrt{1 + C_{a,a} + C_{b,b} \n- 2C_{a,b}} }, \\label{eq:predict_z} &&\n\\end{flalign}\nwhere $\\hat{f}_a$ and $\\hat{f}_b$ are the means and\n$\\bs C$ is the posterior covariance matrix of the multivariate Gaussian over\n$f(\\bs x_a)$ and $f(\\bs x_b)$.\nUnlike other choices for the likelihood, such as a sigmoid,\nthe probit allows us to compute the posterior over a pairwise label\nwithout further approximation,\n% given this posterior over $f(\\bs x_a)$ and $f(\\bs x_b)$,\n%numerical integration\nhence we assume this pairwise label likelihood for our proposed preference learning model.\n%Obtaining the posterior over $f$ is itself challenging, however, \n%and therefore in Section $\\ref{sec:inf}$ we propose \n%an approximate inference method to address this problem.\n\n\n\\subsection{GPPL for Single User Preference Learning}\n\nWe can model the preferences of a single user by assuming\na Gaussian process prior over the user's utility function, \n%is a function of item features and \n$f \\sim \\mathcal{GP}(0, k_{\\theta}/s)$, where $k_{\\theta}$ is a kernel function with hyperparameters $\\theta$\nand $s$ is an inverse scale parameter.\nThe kernel function takes numerical item features as inputs and determines the covariance between values of $f$ for different items. \nThe choice of kernel function and its hyperparameters controls the shape and smoothness of the function \nacross the feature space and is often treated as a model selection problem.\nKernel functions suitable for a wide range of tasks include the \\emph{squared exponential} \nand the \\emph{Mat\\'ern}~\\citep{rasmussen_gaussian_2006},\nwhich both make minimal assumptions but \nassign higher covariance to items with similar feature values.\nWe use $k_{\\theta}$ to compute a covariance matrix $\\bs K_{\\theta}$,\nbetween a set of $N$ observed items with features $\\bs X = \\{ \\bs x_1, ..., \\bs x_N \\}$.\n\nHere we extend the original definition of GPPL~\\citep{chu2005preference},\nby introducing the inverse scale, $s$,\nwhich is drawn from a gamma prior, \n$s \\sim \\mathcal{G}(\\alpha_0, \\beta_0)$, with shape $\\alpha_0$ and scale $\\beta_0$.\nThe value of $1/s$ determines the variance of $f$,\nand therefore \nthe magnitude of differences between $f(\\bs x_a)$ and $f(\\bs x_b)$ for\nitems $a$ and $b$. This in turn affects the level of certainty\nin the pairwise label likelihood as per Equation \\ref{eq:plphi}.\n\nGiven a set of $P$ pairwise labels, %for a single user, \n$\\bs y=\\{y_1,...,y_P\\}$,\nwhere %the $p$th label, \n$y_p=y(a_p, b_p)$ is the preference label for items $a_p$ and $b_p$, % refers to items $\\{ a_p, b_p \\}$.\nwe can write the joint distribution over all variables as follows:\n\\begin{flalign}\np\\left( \\bs{y}, \\bs f, s | k_{\\theta}, \\bs X, \\alpha_0, \\beta_0 \\right) \n=  \\prod_{p=1}^P p( y_p | \\bs f ) \n\\mathcal{N}(\\bs f; \\bs 0, \\bs K_{\\theta}/s) \\mathcal{G}(s; \\alpha_0, \\beta_0) %\\nonumber \\\\\n%=  \\prod_{p=1}^P \\Phi\\left( z_p \\right) \n%\\mathcal{N}(\\bs f; \\bs 0, \\bs K_{\\theta}/s) \\mathcal{G}(s; \\alpha_0, \\beta_0), &\n\\label{eq:joint_single}\n\\end{flalign}\nwhere \n$\\bs f = \\{f(\\bs {x}_1),...,f(\\bs {x}_N)\\}$\nis a vector containing the utilities of the $N$ items referred to by $\\bs y$,\nand $p( y_p | \\bs f ) = \\Phi\\left( z_p \\right)$ is the pairwise likelihood (Equation \\ref{eq:plphi}). \n%We henceforth refer to this model simply as \\emph{GPPL}.\n\n\\subsection{Crowd Preference Learning} \\label{sec:crowd_model}\n\nTo predict the preferences of individuals in a crowd,\nwe could use an independent GPPL model for each user.\nHowever, by modelling all users jointly, we can\nexploit correlations between their interests\nto improve predictions when preference data is sparse,\nand reduce the memory cost of storing separate models.\nCorrelations between users \ncan arise from common interests over certain subsets of items,\nsuch as in one particular genre in a book recommendation task.\nIdentifying such correlations helps to predict \n preferences from  fewer observations and is the core idea of collaborative filtering~\\citep{resnick1997recommender} and matrix factorisation~\\citep{koren2009matrix}.\n\nAs well as individual preferences, \nwe wish to predict the consensus by aggregating\npreference labels from multiple users. \nIndividual biases of different users may affect consensus predictions,\nparticularly when data for certain items comes from a small subset of users.\nThe consensus could also help\npredict preferences of users with little or no data\n by favouring popular items\nand avoiding generally poor items.\nWe therefore propose \n%address this problem by proposing\n \\emph{crowdGPPL}, which jointly models \nthe preferences of individual users as well as the underlying consensus of the crowd.\nUnlike previous methods for inferring the consensus, \nsuch as \\emph{CrowdBT}~\\citep{chen2013pairwise}, we do not treat differences between users as simply the result of labelling errors, \nbut also account for their subjective biases\ntowards particular items. \n \n% is there a better word than 'label sources' for the different sources of implicit feedback or other types of labeling?\n%In a scenario with multiple users or label sources, \nFor crowdGPPL, \nwe represent utilities in a matrix, $\\bs{F} \\in \\mathbb{R}^{N \\times U}$,\nwith %$N$ rows corresponding to items and \n$U$ columns corresponding to users. \nWithin $\\bs F$, each entry $F_{a,j} = f(\\bs x_a, \\bs u_j)$ is the \nutility for item $n$ for user $j$ with user features $\\bs u_j$.\nWe assume that $\\bs{F} = \\bs{V}^T \\bs{W} + \\bs{t}\\bs{1^T}$\n is the product of two low-rank matrices\nplus a vector of consensus utilities, $\\bs{t} \\in \\mathbb{R}^N$, \nwhere $\\bs{W} \\in \\mathbb{R}^{C \\times U}$ is a latent representation\nof the users,\n$\\bs{V} \\in \\mathbb{R}^{C \\times N}$ is a latent representation of the items,\n $C$ is the number of latent \\emph{components}, i.e., the dimension\nof the latent representations,\nand $\\bs 1$ is a column vector of ones of length $U$. \nThe column $\\bs v_{.,a}$ of $\\bs V$, and the column $\\bs w_{.,j}$ of $\\bs W$,\n are latent vector representations of item $a$ and user $j$,\n respectively.\n%Users with similar values for a certain feature will have similar preferences for \n%the subset of items with corresponding feature values. \nEach row of $\\bs V$, $\\bs v_c=\\{ \nv_c(\\bs{x}_1),...,v_c(\\bs{x}_N)\\}$,  \ncontains evaluations of a latent function, \n$v_c\\sim \\mathcal{GP}(\\bs 0, k_{\\theta} /s^{(v)}_c)$,\nof item features, $\\bs x_a$,\nwhere $k$ is a kernel function, $s^{(v)}_c$ is an inverse function scale,\nand $\\theta$ are kernel hyperparameters.\n%Since our goal is to infer a consensus from a crowd as well as to model individual \n%users' preferences, \nThe consensus utilities, $\\bs t = \\{t(\\bs {x}_1),...,t(\\bs {x}_N)\\}$,\nare values of a consensus utility function over item features,\n$t\\sim \\mathcal{GP}(\\bs 0, k_{\\theta} /s^{(t)})$, which is shared across all users,\nwith inverse scale $s^{(t)}$.\nSimilarly, each row of $\\bs W$, \n$\\bs w_c=\\{w_c(\\bs u_1),...,w_c(\\bs u_U)\\}$,\n contains evaluations of a latent function,\n$w_c \\sim \\mathcal{GP}(\\bs 0, k_{\\eta}/s_c^{(w)})$,\nof user features, $\\bs u_j$, \nwith inverse scale $s_c^{(w)}$\nand kernel hyperparameters $\\eta$.\nTherefore, each utility in $\\bs F$ can be written as\na weighted sum over the latent components:\n\\begin{flalign}\n  f(\\bs x_a, \\bs u_j) = \\sum_{c=1}^C  v_c(\\bs x_a) w_c(\\bs u_j) + t(\\bs x_a),\n  \\label{eq:vw_plus_t}\n\\end{flalign}\nwhere $\\bs u_j$ are the features of user $j$ and $\\bs x_a$ are the features of item $a$.\nEach latent component corresponds to a utility function \nfor certain items, which is shared by a subset of users to differing degrees.\nFor example, in the case of book recommendation,\n$c$ could relate to science fiction novels, \n$v_c$ to a ranking over them,\nand $w_c$ to the degree of agreement of users with that ranking.\n%CrowdGPPL therefore combines latent features of items and\n%users -- represented by the latent components -- with the\n%utilities of the items according to an underlying consensus across users.\n%Given the consensus, $t$,\n%utility for item $a$, $t(\\bs x_a)$,\nThe individual preferences of each user $j$ deviate from a consensus across users, $t$, according\nto $\\sum_{c=1}^C  v_c(\\bs x_a) w_c(\\bs u_j)$. \nThis allows us to subtract the effect of individual biases when inferring the consensus utilities. \nThe consensus can also help \nwhen inferring personal preferences for %new users, \n%new items or \nnew combinations of users and items that are\nvery different to those in the training data by\n accounting for any objective or widespread appeal that an item may have.\n%We provide a Bayesian treatment to matrix factorization by placing Gaussian process priors over the latent functions.\n%differently for each user and item. For example, the observed user feature 'age' may correlate with some latent interests of users, but certain users will deviate from their peer group. \n% what happens if two users have identical features (say, the feature representation\n% has only simple values, such as age in years)? They have 1-1 covariance, but there \n% is variance in the GP at one location, so both can be drawn separately from the prior.\n%It is not necessary to learn a separate scale for $w_c$, since $v_c$ and $w_c$ are multiplied with each other, making a single $s^{(v)}_c$ equivalent to the product of two separate scales. \n%The choice of $C$ can be treated as a hyperparameter, or modeled using a non-parametric prior, such as \n%the Indian Buffet Process, which assumes an infinite number of latent components ~\\citep{ding2010nonparametric}.\n%This section described a Bayesian matrix factorization model, \n%which we will subsequently extend to a preference learning model for crowds of users and label sources. \n% joint distribution\n% notes about problems with inference.\n\nAlthough the model assumes a fixed number of components, $C$,\nthe GP priors over $\\bs w_c$ and $\\bs v_c$ act as \\emph{shrinkage}\nor \\emph{ARD priors} that favour values close to zero~\\citep{mackay1995probable,psorakis2011overlapping}. \nComponents that are not required to explain the data will have posterior\nexpectations and scales $1/s^{(v)}$ and $1/s^{(w)}$ approaching zero.\nTherefore, %due to our choice of prior, \nit is not necessary to optimise the value of $C$ by hand, \nproviding a sufficiently large number is chosen. \n\nEquation \\ref{eq:vw_plus_t} is similar to\n\\emph{cross-task crowdsourcing}~\\citep{mo2013cross}, which \nuses matrix factorisation to model annotator performance in different tasks,\nwhere $\\bs t$ corresponds to the objective difficulty of a task.\nHowever, unlike crowdGPPL, they do not use GPs to model the factors, \nnor apply\nthe approach to preference learning.\nFor preference learning, collabGP~\\citep{houlsby2012collaborative}\nis a related model that \nexcludes the consensus and uses values in $\\bs v_c$ to represent pairs\n rather than individual items, so does not infer item ratings.\nIt also omits scale parameters for the GPs that \nencourage shrinkage when $C$ is larger than required.\n \nWe combine the matrix factorisation method with the preference likelihood of Equation \\ref{eq:plphi}\nto obtain the joint preference model for multiple users, \\emph{crowdGPPL}:\n%represent a consensus between users,\n%if present, while allowing individual users' preferences to deviate from this value through $\\bs V^T \\bs W$. \n%Hence, $\\bs t$ can model the underlying ground truth or consensus in crowdsourcing scenarios, or when using\n%multiple label sources to learn preferences for one individual.\n\\begin{flalign}\n&p\\left( \\bs{y}, \\bs V, \\bs W, \\bs t, s^{(v)}_1 \\!\\!, .., s^{(v)}_C\\!\\!, s^{(w)}_1\\!\\!, .., s^{(w)}_C\\!\\!, s^{(t)} \n| k_{\\theta}, \\bs X, k_{\\eta}, \\bs U, \\alpha_0^{(t)}\\!\\!, \\beta_0^{(t)}\\!\\!,\n\\alpha_0^{(v)}\\!\\!, \\beta_0^{(v)}\\!\\!, \\alpha_0^{(w)}\\!\\!, \\beta_0^{(w)} \\right) \n & \\nonumber \\\\ \n& = \\prod_{p=1}^P \\Phi\\left( z_p \\right) \n\\mathcal{N}(\\bs t; \\bs 0, \\bs K_{\\theta} /s^{(t)})\n\\mathcal{G}({s^{(t)}}; \\alpha_0^{(t)}, \\beta_0^{(t)})\n\\prod_{c=1}^C \\left\\{\n\\mathcal{N}(\\bs v_c; \\bs 0, \\bs K_{\\theta} /s^{(v)}_c)\n\\right.\n & \\nonumber \\\\  \n&\\left.\n\\mathcal{N}(\\bs w_c; \\bs 0, \\bs L_{\\eta}/s^{(w)}_c) \\mathcal{G}(s^{(v)}_c; \\alpha_0^{(v)}, \\beta_0^{(v)})\\mathcal{G}(s^{(w)}_c; \\alpha_0^{(w)}, \\beta_0^{(w)}) \\right\\}, &\n\\label{eq:joint_crowd}\n\\end{flalign}\nwhere \n$z_p = \\bs v_{.,a_p}^T \\bs{w}_{.,u_p} + t_{a_p} - \\bs v_{.,b_p}^T \\bs{w}_{.,u_p} - t_{b_p}$,\nindex $p$ refers to a user and a pair of items, $\\{u_p, a_p, b_p \\}$,\n$\\bs U$ is the set of feature vectors for all users,\n$\\bs K_{\\theta}$ is the prior covariance for the items as in GPPL,\nand $\\bs L_{\\eta}$ is the prior covariance for the users computed\nusing $k_{\\eta}$.\n\n", "meta": {"hexsha": "27ea26e68667e617d90031114be1fa0230e91bea", "size": 16404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/scalable_bayesian_preference_learning_from_crowds/model.tex", "max_stars_repo_name": "UKPLab/tacl2018-preference-convincing", "max_stars_repo_head_hexsha": "65eb1cd3bf76f8068889880e0f80178e790350ce", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-03-01T19:40:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T05:53:47.000Z", "max_issues_repo_path": "documents/scalable_bayesian_preference_learning_from_crowds/model.tex", "max_issues_repo_name": "UKPLab/tacl2018-preference-convincing", "max_issues_repo_head_hexsha": "65eb1cd3bf76f8068889880e0f80178e790350ce", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2020-11-13T17:54:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T23:39:11.000Z", "max_forks_repo_path": "documents/scalable_bayesian_preference_learning_from_crowds/model.tex", "max_forks_repo_name": "UKPLab/tacl2018-preference-convincing", "max_forks_repo_head_hexsha": "65eb1cd3bf76f8068889880e0f80178e790350ce", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-02-06T12:08:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-10T20:40:22.000Z", "avg_line_length": 53.7836065574, "max_line_length": 215, "alphanum_fraction": 0.7176298464, "num_tokens": 4913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127492339907, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6081841477522872}}
{"text": "\\section{Model}\n\n\\begin{definition}\\label{def:mp}\n  A Markov process is a stochastic process $Q_1, Q_2, \\dots$ for which\n  \\begin{equation*}\n    p(Q_t=q_t \\gv Q_1=q_1, Q_2=q_2, \\dots, Q_{t-1}=q_{t-1}) = p(Q_t=q_t \\gv Q_{t-1}=q_{t-1}).\n  \\end{equation*}\n  The possible values of $Q_t$ form a finite set $\\set{Q}$ called the state space.\n\\end{definition}\n\n\\begin{definition}\\label{def:hmm}\n  Let $\\set{A}$ be a non-empty finite set of symbols. Let $Q_1, Q_2, \\dots$ be a Markov process and\n  let $S_1, S_2, \\dots$ be a stochastic process for which\n  \\begin{equation*}\n    p(S_t\\in\\set{A} \\gv Q_1=q_1, Q_2=q_2, \\dots, Q_t=q_t) = p(S_t\\in\\set{A} \\gv Q_t=q_t).\n  \\end{equation*}\n  The pair $(Q_t, S_t)$ is a hidden Markov model (HMM) with alphabet $\\set{A}$.\n\\end{definition}\n\nLet $\\arr{z}=z_1z_2 \\dots z_\\ell$ be a sequence of symbols from alphabet $\\set{A}$ of a given HMM.\\@\nThe marginal likelihood of $\\arr{z}$ is defined by\n\\begin{equation}\\label{eq:hml}\n  \\mathrm{ML}(\\arr{z}) \\eqdef p(S_1=z_1, S_2=z_2, \\dots, S_\\ell=z_\\ell).\n\\end{equation}\n\nThe standard HMM definition is often extended to include states that do not emit symbols. Those\nstates are referred to as silent states and are useful to describe a missing alignment position, for\nexample. This section goes a step further by defining a more general hidden Markov model that\naccounts for states that instead emit sequence of symbols of variable length, including zero-length\nsequences.\n\n\\begin{definition}\n  Let $\\set{A}$ be a non-empty finite set of symbols, $k\\in\\field{N}_0$, and define\n  $\\set{T}=\\bigcup_{i=0}^k\\set{A}^i$.\n  Let $Q_1, Q_2, \\dots$ be a Markov process and let $S_1, S_2, \\dots$ be a stochastic process for\n  which\n  \\begin{equation*}\n    p(S_t\\in\\set{T} \\gv Q_1=q_1, Q_2=q_2, \\dots, Q_t=q_t)\n    = p(S_t\\in\\set{T} \\gv Q_t=q_t).\n  \\end{equation*}\n  The pair $(Q_t, S_t)$ is an invisible Markov model (IMM) with alphabet $\\set{A}$ and\n  limit $k$.\n\\end{definition}\n\nLet $\\arr{z}=z_1z_2 \\dots z_\\ell$ be a sequence of symbols from alphabet $\\set{A}$ of a given IMM.\\@\nThe marginal likelihood of $\\arr{z}$ cannot be written as in \\Cref{eq:hml} since\nwe've lost the the order association between symbols and steps.\nInstead, the marginal likelihood is given by\n\\begin{equation}\\label{eq:ml}\n  \\mathrm{ML}(\\arr{z}) \\eqdef \\sum_{t=1}^{\\infty} p(S_{1..t}=\\arr{z}, S_{t+1}\\neq \\emptyset),\n\\end{equation}\nwhere $S_{1..t}$ denotes the concatenation of the random variables $S_1$, $S_2$, $\\dots$, and $S_t$.\nThe inequality $S_{t+1}\\neq \\emptyset$ is necessary to avoid evaluating the same probability twice.\nThe infinity summation is also needed because of the possibility of existing cycles in the IMM\nformed by states that are able to emmit empty sequences.\n\n\\begin{remark}\n  The notation $p(S_{1..t}=\\arr{z})$ is equal to the summation of the probabilities of every valid\n  association between the random variables $S_1, S_2, \\dots, S_t$ and the subsequences of $\\arr{z}$,\n  including empty subsequences. For example, let $a$ be a sequence composed of a single symbol. We\n  have $p(S_{1..2}=a) = p(S_1=a, S_2=\\emptyset) + p(S_1=\\emptyset, S_2=a)$ by definition, where\n  $\\emptyset$ denotes an empty sequence.\n\\end{remark}\n\n\\subsection{Viterbi}\n\nLet us consider first the Viterbi method applied to HMMs for a given sequence $\\arr{z}$ of length\n$\\ell$.\nLet\n\\begin{equation*}\n  \\viterbi(q_t) \\eqdef \\umax{q_{1..t-1}} \\{ p(S_{1..t}=z_{1..t}, Q_{1..t}=q_{1..t}) \\}\n\\end{equation*}\nbe the so-called Viterbi score. The $\\max$ operator in the previous definition is the maximum across\nall possible associations $Q_1=q_1, Q_2=q_2, \\dots, Q_{t-1}=q_{t-1}$. Viterbi score is therefore the\nmaximum probability among all state paths that ends in $q_t$ and generates the prefix $z_{1..t}$\nfrom sequence $\\arr{z}$. The function domain of $\\viterbi(q_t)$ is such that $t \\in \\{1, 2, \\dots,\n\\ell\\}$ and $q_t \\in \\set{Q}$.\n\nViterbi score can also be defined in a recursive fashion as follows:\n\\begin{equation*}\n\\begin{split}\n  \\viterbi(q_t)\n  &= p(S_t=z_t \\gv Q_t=q_t) \\umax{q_{1..t-1}}\n    \\{ p(Q_t=q_t \\gv Q_{t-1}=q_{t-1}) p(S_{1..t-1}=z_{1..t-1}, Q_{1..t-1}=q_{1..t-1}) \\} \\\\\n  &= p(S_t=z_t \\gv Q_t=q_t) \\umax{q_{t-1}}\n    \\{ p(Q_t=q_t \\gv Q_{t-1}=q_{t-1})\n    \\umax{q_{1..t-2}} \\{ p(S_{1..t}=z_{1..t-1}, Q_{1..t}=q_{1..t-1}) \\} \\} \\\\\n  &= p(S_t=z_t \\gv Q_t=q_t) \\umax{q_{t-1}} \\{ p(Q_t=q_t \\gv Q_{t-1}=q_{t-1})\n    \\viterbi(q_{t-1}) \\},\n\\end{split}\n\\end{equation*}\nfor $t>1$; and\n\\begin{equation*}\n  \\viterbi(q_1) = p(S_1=z_1 \\gv Q_1=q_1) p(Q_1=q_1).\n\\end{equation*}\n\nThe simplicity of the notation $\\viterbi(q_t)$ is no longer enough to define the Viterbi score for\nIMMs as the index $t$ does not unambigously defines a prefix of $\\arr{z}$. We will also make use of\nan additional parameter $F_t\\in \\{0, 1, \\dots, k\\}$: $F_t=f_t$ means that $f_t$ is the length of the\nsequence emitted by $S_t$.\nFor the sake of notation clarity, let us define $z_{i(f_t)..i} \\eqdef\nz_{i-f_t+1..i}$ as the $f_t$-length tail of a sequence $z_{1..i}$. The Viterbi score of an IMM\nregarding a sequence $\\arr{z}$ of length $\\ell$ is defined by\n\\begin{equation}\\label{eq:viterbi}\n  \\viterbi_{i}(q_t,f_t) \\eqdef\n    \\umax{\\substack{q_{1..t-1}\\\\f_{1..t-1}}}\n    \\{\n      p(S_{1..t}=z_{1..i}, Q_{1..t}=q_{1..t} ~;~ F_{1..t}=f_{1..t})\n    \\}.\n\\end{equation}\n\nThe $\\max$ operator in \\Cref{eq:viterbi} is the maximum across all possible associations\n$Q_1=q_1, Q_2=q_2, \\dots, Q_{t-1}=q_{t-1}$ and $F_1=f_1, F_2=f_2, \\dots, F_{t-1}=f_{t-1}$. Viterbi\nscore is therefore the maximum probability among all state paths that ends in $q_t$ emitting\n$z_{i(f_t)..i}$ and generates the prefix $z_{1..i}$ from sequence $\\arr{z}$. The function domain of\n$\\viterbi_{i}(q_t,f_t)$ is such that $t \\in \\{1, 2, \\dots\\}$, $i \\in \\{0, 1, \\dots, \\ell\\}$, $f_t\n\\in \\{0, 1, \\dots, \\min\\{i, k\\}\\}$, and $q_t \\in \\set{Q}$.\n\nViterbi score for IMM can also be defined in a recursive way as follows:\n\\begin{equation*}\n  \\begin{split}\n    \\viterbi_{i}(q_t,f_t)\n    &= p(S_t=z_{i(f_t)..i} \\gv q_t)\n      \\uumax{q_{t-1}}{f_{t-1}}\n      \\{\n        p(q_t \\gv q_{t-1})\n        \\uumax{q_{1..t-2}}{f_{1..t-2}}\n        \\{\n          p(S_{1..t-1}=z_{1..i-f_t}, q_{1..t-1} ~;~ f_{1..t-1})\n        \\}\n      \\}\\\\\n    &= p(S_t=z_{i(f_t)..i} \\gv q_t)\n      \\uumax{q_{t-1}}{f_{t-1}}\n      \\{\n        p(q_t \\gv q_{t-1}) \\viterbi_{i-f_t}(q_{t-1},f_{t-1})\n      \\},\n  \\end{split}\n\\end{equation*}\nfor $t>1$; and\n\\begin{equation*}\n  \\viterbi_{f_1}(q_1,f_1) = p(S_1=z_{1..i} \\gv Q_1=q_1) p(Q_1=q_1).\n\\end{equation*}\n", "meta": {"hexsha": "ecc734a2054c23212553418e6913f08d5874a891", "size": 6493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/model.tex", "max_stars_repo_name": "EBI-Metagenomics/protein-hmm", "max_stars_repo_head_hexsha": "a291a6605459e559ebb912ffc71180094da19378", "max_stars_repo_licenses": ["MIT"], "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/model.tex", "max_issues_repo_name": "EBI-Metagenomics/protein-hmm", "max_issues_repo_head_hexsha": "a291a6605459e559ebb912ffc71180094da19378", "max_issues_repo_licenses": ["MIT"], "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/model.tex", "max_forks_repo_name": "EBI-Metagenomics/protein-hmm", "max_forks_repo_head_hexsha": "a291a6605459e559ebb912ffc71180094da19378", "max_forks_repo_licenses": ["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.4055944056, "max_line_length": 100, "alphanum_fraction": 0.6530109349, "num_tokens": 2523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812554, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6081838222493968}}
{"text": "\\chapter{Pseudo-code for Algorithms}\n\\label{chap:algorithms}\nThis chapter contains pseudo-code for the algorithms described in \\sref{sec:definition_algorithms}. In the following sections, a graph $G$ consists of a set of vertices $V$ and a set of edges $E$. For undirected graphs, each edge is bidirectional, so if $(u, v) \\in E$ then $(v, u) \\in E$. Each vertex has a set of outgoing neighbors $N_\\mathrm{out}(v) = \\{u \\in V | (v, u) \\in E\\}$ and a set of incoming neighbors $N_\\mathrm{in}(v) = \\{u \\in V | (u, v) \\in E\\}$.\n\n\\section{Breadth-First Search (BFS)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$, vertex $\\textit{root}$\n\\Statex \\textbf{output:} array $\\textit{depth}$ storing vertex depths\n\\ForAll{$v \\in V$}\n  \\State $\\textit{depth}[v] \\gets \\infty$\n\\EndFor\n\\State $Q$ $\\gets$  \\textsc{create\\_queue()}\n\\State \\Call{$Q$.push}{$\\textit{root}$}\n\\State $\\textit{depth}[\\textit{root}] \\gets 0$\n\\While{\\Call{$Q$.size}{} > 0}\n  \\State $v \\gets $ \\Call{$Q$.pop\\_front}{ }\n  \\ForAll{$u \\in N_\\mathrm{out}(v)$}\n    \\If{$\\textit{depth}[u] = \\infty$}\n      \\State $\\textit{depth}[u] \\gets \\textit{depth}[v] + 1$\n      \\State \\Call{$Q$.push\\_back}{$u$}\n    \\EndIf\n  \\EndFor\n\\EndWhile\n\\end{algorithmic}\n\\end{algorithm}\n\n\\section{PageRank (PR)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$, integer $\\textit{max\\_iterations}$\n\\Statex \\textbf{output:} array $\\textit{rank}$ storing PageRank values\n\\ForAll{$v \\in V$}\n  \\State $\\textit{rank}[v] \\gets \\frac{1}{|V|}$\n\\EndFor\n\\For{$i=1,\\ldots,\\textit{max\\_iterations}$}\n\\State $\\textit{dangling\\_sum} \\gets 0$\n\\ForAll{$w \\in V$}\n  \\If{$|N_\\mathrm{out}(w)| = 0$}\n    \\State $\\textit{dangling\\_sum} \\gets \\textit{dangling\\_sum} + \\textit{rank}[w]$\n  \\EndIf\n\\EndFor\n\\ForAll{$v \\in V$}\n  \\State $\\textit{new\\_rank}[v] \\gets \\frac{1-d}{|V|} + d \\cdot \\sum_{u \\in N_\\mathrm{in}(v)} \\frac{\\textit{rank}[u]}{|N_\\mathrm{out}(u)|} + \\frac{d}{|V|} \\cdot \\textit{dangling\\_sum} $\n\\EndFor\n\\State $\\textit{rank} \\gets \\textit{new\\_rank}$\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\clearpage\n\n\\section{Weakly Connected Components (WCC)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$\n\\Statex \\textbf{output:} array $\\textit{comp}$ storing component labels\n\\ForAll{$v \\in V$}\n  \\State $\\textit{comp}[v] \\gets v$\n\\EndFor\n\\Repeat\n\\State $\\textit{converged} \\gets \\text{true}$\n\\ForAll{$v \\in V$}\n  \\ForAll{$u \\in N_\\mathrm{in}(v) \\cup N_\\mathrm{out}(v)$}\n    \\If{$\\textit{comp}[v] > \\textit{comp}[u]$}\n      \\State $\\textit{comp}[v] \\gets \\textit{comp}[u]$\n      \\State $\\textit{converged} \\gets \\text{false}$\n     \\EndIf\n  \\EndFor\n\\EndFor\n\\Until{$\\textit{converged}$}\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\\section{Local Clustering Coefficient (LCC)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$\n\\Statex \\textbf{output:} array $\\textit{lcc}$ storing LCC values\n\\ForAll{$v \\in V$}\n   \\State $d \\gets |N_\\mathrm{in}(v) \\cup N_\\mathrm{out}(v)|$\n  \\If {$d \\geq 2$}\n  \\State $t \\gets 0$\n  \\ForAll{$u \\in N_\\mathrm{in}(v) \\cup N_\\mathrm{out}(v)$}\n    \\ForAll{$w \\in N_\\mathrm{in}(v) \\cup N_\\mathrm{out}(v)$}\n     \\If{$(u, w) \\in E$}\n      \\Comment{Check if edge $(u, w)$ exists}\n      \\State $t  \\gets t + 1$\n      \\Comment{Found triangle $v-u-w$}\n     \\EndIf\n    \\EndFor\n  \\EndFor\n    \\State $\\textit{lcc}[v] \\gets \\frac{t}{d(d-1)} $\n  \\Else\n    \\State $\\textit{lcc}[v] \\gets 0$\n    \\Comment{No triangles possible}\n  \\EndIf\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\clearpage\n\n\\section{Community Detection using Label Propagation (CDLP)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$, integer $\\textit{max\\_iterations}$\n\\Statex \\textbf{output:} array $\\textit{labels}$ storing vertex communities\n\\ForAll{$v \\in V$}\n  \\State $\\textit{labels}[v] \\gets v$\n\\EndFor\n\\For{$i=1, \\ldots, \\textit{max\\_iterations}$}\n \\ForAll{$v \\in V$}\n  \\State $C$ $\\gets$ \\textsc{create\\_histogram()}\n\n  \\ForAll{$u \\in N_\\mathrm{in}(v)$}\n    \\State \\Call{$C$.add}{$\\textit{labels}[u]$}\n  \\EndFor\n  \\ForAll{$u \\in N_\\mathrm{out}(v)$}\n    \\State \\Call{$C$.add}{$\\textit{labels}[u]$}\n  \\EndFor\n  \\State $\\textit{freq} \\gets $ \\Call{$C$.get\\_maximum\\_frequency}{ }\n  \\Comment{Find maximum frequency of labels}\n  \\State $\\textit{candidates} \\gets$ \\Call{$C$.get\\_labels\\_for\\_frequency}{$\\textit{freq}$}\n  \\Comment{Find labels with max.\\ frequency}\n  \\State $\\textit{new\\_labels}[v] \\gets$ \\Call{min}{$\\textit{candidates}$}\n  \\Comment{Select smallest label}\n \\EndFor\n \\State $\\textit{labels} \\gets \\textit{new\\_labels}$\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\section{Single-Source Shortest Paths (SSSP)}\n\n\\begin{algorithm}[h!]\n\\begin{algorithmic}[1]\n\\Statex \\textbf{input:} graph $G=(V,E)$, vertex $\\textit{root}$, edge weights $\\textit{weight}$\n\\Statex \\textbf{output:} array $\\textit{dist}$ storing distances\n\\ForAll{$v \\in V$}\n  \\State $\\textit{dist}[v] \\gets \\infty$\n\\EndFor\n\n\\State $H$ $\\gets \\Call{create\\_heap}{ }$\n\\State \\Call{$H$.insert}{root, 0}\n\\State $\\textit{dist}[\\textit{root}] \\gets 0$\n\\While{$\\Call{$H$.size}{} > 0$}\n  \\State $v \\gets$ \\Call{$H$.delete\\_minimum}{ }\n  \\Comment{Find vertex $v$ in $H$ such that $\\textit{dist}[v]$ is minimal}\n  \\ForAll{$w \\in N_\\mathrm{out}(v)$}\n    \\If{$\\textit{dist}[w] > \\textit{dist}[v] + \\textit{weight}[v,w]$}\n      \\State $\\textit{dist}[w] \\gets \\textit{dist}[v] + \\textit{weight}[v,w]$\n      \\State \\Call{$H$.insert}{$w$, $\\textit{dist}[w]$}\n    \\EndIf\n  \\EndFor\n\\EndWhile\n\\end{algorithmic}\n\\end{algorithm}\n", "meta": {"hexsha": "824b8aae0eab302f8494035131668504bb7f5437", "size": 5567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/appendix_algorithms.tex", "max_stars_repo_name": "tudelft-atlarge/graphalytics_docs", "max_stars_repo_head_hexsha": "991dc12df003b5782b768237478f2d44a677dd4f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-25T14:29:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-25T14:29:19.000Z", "max_issues_repo_path": "tex/appendix_algorithms.tex", "max_issues_repo_name": "tudelft-atlarge/graphalytics_docs", "max_issues_repo_head_hexsha": "991dc12df003b5782b768237478f2d44a677dd4f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2017-06-14T18:55:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-03T12:24:11.000Z", "max_forks_repo_path": "tex/appendix_algorithms.tex", "max_forks_repo_name": "tudelft-atlarge/graphalytics_docs", "max_forks_repo_head_hexsha": "991dc12df003b5782b768237478f2d44a677dd4f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-06-14T18:10:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T19:58:13.000Z", "avg_line_length": 33.3353293413, "max_line_length": 463, "alphanum_fraction": 0.6418178552, "num_tokens": 2126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6081838178071599}}
{"text": "% Created 2020-03-11 mié 17:56\n% Intended LaTeX compiler: pdflatex\n\\documentclass[a4paper]{scrartcl}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{textcomp}\n\\usepackage{amssymb}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{khpreamble}\n\\usepackage{pgfplots}\n\\usepackage{pdfpages}\n\\usepackage{circuitikz}\n\\usepgfplotslibrary{groupplots}\n\\usetikzlibrary{positioning}\n\\renewcommand*{\\not}[1]{\\ensuremath{\\bar{#1}}}\n\\renewcommand*{\\not}[1]{\\ensuremath{\\overline{#1}}}\n\\author{Kjartan Halvorsen}\n\\date{2020-03-11}\n\\title{System identification of the tank}\n\\hypersetup{\n pdfauthor={Kjartan Halvorsen},\n pdftitle={System identification of the tank},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.3.6)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Least squares, linear regression}\n\\label{sec:orgbed202b}\n\nConsider observations from experiments below, where you have set some different values of the dependent variable  \\(x\\), run an experiments and observed the result \\(y\\).\n\n  \\begin{center}\n  \\begin{tikzpicture}\n  \\begin{axis}[\n    width = 6cm,\n    height = 4cm,\n    ytick  = data,\n    %    ytick = {0,4,6, 10},\n    %xtick = {0,2, 4, 6, 8, 10, 12},\n    %ymin = 0,\n    %ymax = 10,\n    ylabel = {$y$},\n    xlabel = {$x$},\n    ]\n\n    \\addplot[only marks, blue, domain=1:6, samples=6] { 1 + 3*x -0.4*x*x + 0.4*rand};\n    \n  \\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\nCan you fit a suitable model to the data?\n\n\\subsection{Linear regression}\n\\label{sec:org21b8a5d}\nAssume the model \\(y = a_0x^2 + a_1x + a_2 + \\epsilon\\), where the residual \\(\\epsilon\\) is the part of the observation \\(y\\) that cannot be explained by the model. We want to find the unknown parameters \\(\\theta = \\begin{bmatrix} a_0 & a_1 & a_2\\end{bmatrix}^T\\) of the model given a set of experimental data \\(\\mathcal{D} = \\{ (x_1, y_1),\\, (x_2, y_2),\\, \\ldots, \\, (x_N, y_N) \\}\\).\n\nWe can write the model as \n\\begin{equation}\n\\begin{align} \\epsilon &= y - x^2a_0 - xa_1 - a_2 = y - \\phi_0(x)a_0 - \\phi_1(x)a_1 - \\phi_2(x)a_2 = y - \\underbrace{\\begin{bmatrix}  \\phi_0(x) & \\phi_1(x) & \\phi_2(x) \\end{bmatrix}}_{\\text{regressors}} \\begin{bmatrix} a_0\\\\a_1\\\\a_3\\end{bmatrix}\\\\ &= y - \\phi(x)^T\\theta.\n\\end{align}\n\\end{equation}\nThe model holds for all the observations, which gives\n\\begin{align*}\n  \\epsilon_1 &= y_1 - \\phi(x_1)^T\\theta\\\\\n  \\epsilon_2 &= y_2 - \\phi(x_2)^T\\theta\\\\\n             &\\vdots\\\\\n  \\epsilon_N &= y_n - \\phi(x_N)^T\\theta\\\\\n\\end{align*}\n\nLinear regression, or least-squares fitting, is defined as the optimization problem\n\\begin{equation}\n\\begin{aligned}\n\\text{minimize}\\quad  f(\\theta) &= \\frac{1}{2}\\sum_{i=1}^N \\epsilon_i^2  = \\frac{1}{2} \\sum_{i=1}^N (y_i - \\phi(x_i)^T\\theta)(y_i - \\phi(x_i)^T\\theta) \\\\ &= \\frac{1}{2} \\sum_{i=1}^N \\Big(y_i^2 - 2y_i\\phi(x_i)^T\\theta + (\\phi(x_i)^T\\theta)^2\\Big)\n\\end{aligned}\n\\end{equation}\nThis optimization problem has a closed-form solution found by setting the derivative of \\(f\\) wrt \\(\\theta\\) equal to zero\n\\[ \\frac{d}{d\\theta} f(\\theta) = 0 \\]\n\\[ \\frac{1}{2} \\sum_{i=1}^N \\Big( -2y_i\\phi(x_i)}^T + 2(\\phi(x_i)^T\\theta)\\phi(x_i)^T \\big)\n      = \\sum_{i=1}^N \\Big( -y_i\\phi(x_i)^T + (\\theta^T\\phi(x_i))\\phi(x_i)^T\\big) = 0 \\]\nwhich is equivalent to (by taking the transpose on both sides)\n\\[ \\sum_{i=1}^N \\Big( \\phi(x_i) \\phi(x_i)^T \\theta - \\phi(x_i) y_i\\Big) = 0.\\]\n\\[ \\Big(\\sum_{i=1}^N \\phi(x_i) \\phi(x_i)^T\\Big) \\theta - \\sum_{i=1}^N \\phi(x_i) y_i = 0.\\]\n\\[ \\Big(\\sum_{i=1}^N \\phi(x_i) \\phi(x_i)^T\\Big) \\theta =  \\sum_{i=1}^N \\phi(x_i) y_i .\\]\n\nDefining the matrices and vectors (with some abuse of notation)\n\\begin{align*}\n  x &= \\begin{bmatrix} x_1 & x_2 & \\cdots & x_N \\end{bmatrix}^T\\\\\n  y &= \\begin{bmatrix} y_1 & y_2 & \\cdots & y_N \\end{bmatrix}^T\\\\\n  \\epsilon &= \\begin{bmatrix} \\epsilon_1 & \\epsilon_2 & \\cdots & \\epsilon_N \\end{bmatrix}^T\\\\\n  \\Phi(x) &= \\begin{bmatrix} \\phi(x_1)^T\\\\\\phi(x_2)^T\\\\\\vdots\\\\\\phi(x_N)^T\\end{bmatrix}\\\\\n\\end{align*}\nThe problem can be written \n\\[\n\\text{minimize}\\quad  f(\\theta) = \\frac{1}{2}\\epsilon^T\\epsilon = \\frac{1}{2}(y -\\Phi(x)\\theta)^T(y-\\Phi(x)\\theta)\\]\nwith solution\n\\[ \\theta_{LS} = \\Big( \\Phi(x)^T\\Phi(x) \\Big)^{-1} \\Phi(x)^T y\\]\n\n\\subsection{In practice}\n\\label{sec:org8566269}\nGiven the model \\(y = a_0x^2 + a_1x + a_2 + \\epsilon\\) and the data \\(\\mathcal{D} = \\{ (x_1, y_1),\\, (x_2, y_2),\\, \\ldots, \\, (x_N, y_N) \\}\\), form the vectors and matrices\n\n\\begin{align*}\n\\Phi(x) &= \\begin{bmatrix} x_1^2 & x_1 & 1\\\\x_2^2 & x_2 & 1\\\\\\vdots & \\vdots & \\vdots\\\\x_N^2 & x_N & 1\\end{bmatrix} \\\\\ny &= \\begin{bmatrix}y_1\\\\y_2\\\\\\vdots\\\\y_N\\end{bmatrix}\n\\end{align*}\n\nFind the least-squares solution to \n\\[ \\Phi(x)\\theta = y.\\]\n\nIn matlab\n\\begin{verbatim}\nx = [x1, x2, x3, x4, x5, x6]';\ny = [y1, y2, y3, y4, y5, y6]';\nPhi = [x.^2, x, ones(size(x))];\ntheta = Phi \\ y\n\\end{verbatim}\n\n\\subsection{What about fitting the model \\(y = a_0 x^{a_1}\\)?}\n\\label{sec:orgf11b322}\nTake the logarithm (assuming positive \\(x\\) and \\(y\\))\n\\[ y = \\log a_0 + a_1\\log x\\]\n\n\\section{The tank model}\n\\label{sec:org01022a6}\n\n\\subsection{ODE}\n\\label{sec:orga07be0b}\n\n\\[\\frac{d}{dt} p = \\alpha A \\sqrt{p_s - p} = a (u_v - 5) \\sqrt{p_s - p}\\]\n\n\\subsection{Parameter estimation}\n\\label{sec:org275496d}\nFrom experiments filling the tank with different values for \\(u_v\\) one obtains the following table (assuming u\\textsubscript{s}=1V is p=1bar)\n\\begin{center}\n\\begin{tabular}{rrrrrr}\n\\(p_s\\) & \\(u_v\\) & \\(p\\) & \\(\\Delta p\\) & \\(\\Delta t\\) & \\(\\dot{p}\\)\\\\\n\\hline\n5 & 5.5 & 0 & 0.86 & 1.51 & 0.56953642\\\\\n5 & 6 & 0 & 0.84 & 0.22 & 3.8181818\\\\\n5 & 9 & 0 & 1.16 & 0.238 & 4.8739496\\\\\n\\end{tabular}\n\\end{center}\n\nThe model is \n\\[ \\begin{bmatrix} (u_{v_1} - 5)\\sqrt{p_s - p_1} \\\\\n                      (u_{v_2} - 5)\\sqrt{p_s - p_2} \\\\\n\t\t      \\vdots\\\\\n\t\t      (u_{v_N} - 5)\\sqrt{p_s - p_N} \\end{bmatrix} a = \\begin{bmatrix} \\dot{p}_1\\\\ \\dot{p}_2\\\\\\vdots\\\\ \\dot{p}_N\\end{bmatrix}\n\\]\n\\end{document}", "meta": {"hexsha": "46f5c45fc027a412440ea5410b4cdf1b7401fb76", "size": 6057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/tank-pid/sysid.tex", "max_stars_repo_name": "kjartan-at-tec/mr2015", "max_stars_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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/tank-pid/sysid.tex", "max_issues_repo_name": "kjartan-at-tec/mr2015", "max_issues_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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/tank-pid/sysid.tex", "max_forks_repo_name": "kjartan-at-tec/mr2015", "max_forks_repo_head_hexsha": "1134f3a99ef72e4a17d44edb4d288daad84f3e70", "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.1595092025, "max_line_length": 384, "alphanum_fraction": 0.6376093776, "num_tokens": 2466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6081838159686318}}
{"text": "\\chapter{Search}\n\\label{chp:search}\nMotion planning is about planning the motion of the robot to a certain target. Motion planning is all about finding the optimal or minimum cost path. This is illustrated in figure \\ref{fig:search_mp}. A cost could be how long time it takes to reach a target by a certain path.\n\n\\myFigure{Theory/Search/motion_planning}{Motion Planning.}{fig:search_mp}{0.6}\n\nFigure \\ref{fig:search} illustrates an matrix with a start position 'S' and a goal position 'G'. All the grid cells which are filled out are closed cells. The goal is to find the shortest path to the goal from the start position. One way this can be done is be calculating the g(n) value for each cell. The g(n) value represents how many expansions it took to move to cell n.\n\n\\myFigure{Theory/Search/g_val}{Search.}{fig:search}{0.4}\n\nThis is just one example of a search algorithm. The problem with this algorithm is that with large matrices it become very inefficient. But with the knowledge of g(n) you can make it more efficient. A* is one example of this.  \n\\section{A*}\n\nA* is a search algorithm. It is variant of the search algorithm that is more efficient than expanding every cell or node.\n\n\\myFigure{Theory/Search/a_star}{A*.}{fig:a_star}{0.8}\n\nIn figure \\ref{fig:a_star} a matrix like before is shown on the left, but with other obstacles, and a matrix with the heuristic values. The heuristic value h(n) is calculated by the distance from the node n to the goal.\n\nA* utilizes this information by combining the heuristics cost and the expansion which is called f(n) = g(n) + h(n). This gives an advantage. With the knowledge of the heuristic function the computer can save calculation time because it does not need to search all nodes. This is represented by the green lines in figure \\ref{fig:a_star}.", "meta": {"hexsha": "bade41bf4b235d4bdde57c620aee8be9075dd073", "size": 1807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/Search.tex", "max_stars_repo_name": "Rotvig/AI-Robotics-Project", "max_stars_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_stars_repo_licenses": ["MIT"], "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/Search.tex", "max_issues_repo_name": "Rotvig/AI-Robotics-Project", "max_issues_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_issues_repo_licenses": ["MIT"], "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/Search.tex", "max_forks_repo_name": "Rotvig/AI-Robotics-Project", "max_forks_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_forks_repo_licenses": ["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.35, "max_line_length": 375, "alphanum_fraction": 0.7736579967, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321703143954, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6081838081575043}}
{"text": "\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\newbox\\SlashInput\n\\setbox\\SlashInput=\\hbox{\\tt\\Large\\verb|\\Input|}\n\n\\begin{document}\n\n\\section*{Using {\\copy\\SlashInput}}\n\n% \\vspace{-5pt}\n\nThis simple example shows how {\\tt\\small\\verb|\\Input|} can be used in include other LaTeX sources within\nthe host source. Note the use of nested {\\tt\\small\\verb|\\Input|}'s. The merged file can be inspected by running\n\n\\begin{lstlisting}\n   merge-src.py -i example-10.tex -o merged.tex\n\\end{lstlisting}\n\nfrom the command line. The merged file will be named {\\tt\\small merged.tex}.\n\n\\PySetup{action=verbatim}\n\n% Note: The * in the 1st column is to ensure the python preprocessor does not respond\n%       to any of the \\begin{...} or \\end{...} lines. The \\end{document} line is the\n%       real problem as it terminates the preprocessing.\n%       The * is hidden from LaTeX by way of the listinings option gobble=2.\n\n\\vspace{-5pt}\n\n% ===================================================================\n\\section*{Source of example-10.tex}\n\n\\bgroup\n\\bgcolour{white}\n\\latexstyle\n\\begin{latex}\n*   \\Input{./example-10/limits/limits.tex}\n*   \\Input{./example-10/calculus/calculus.tex}\n\\end{latex}\n\\egroup\n\n\\vspace{10pt}\n\n% ===================================================================\n\\section*{Source of example-10/limits/limits.tex}\n\n\\bgroup\n\\bgcolour{white}\n\\latexstyle\n\\begin{latex}\n*   \\section*{Limits}\n*\n*   \\begin{python}\n\\end{latex}\n\\pythonstyle\n\\begin{python}\n*      from sympy import *\n*      a, n, x, dx = symbols('a n x dx')\n*      ans = limit(sin(4*x)/x,x,0)                  # py (ans.301,ans)\n*      ans = limit(2**x/x,x,oo)                     # py (ans.302,ans)\n*      ans = limit(((x+dx)**2 - x**2)/dx, dx,0)     # py (ans.303,ans)\n*      ans = limit((4*n + 1)/(3*n - 1),n,oo)        # py (ans.304,ans)\n*      ans = limit((1+(a/n))**n,n,oo)               # py (ans.305,ans)\n\\end{python}\n\\latexstyle\n\\begin{latex}\n*   \\end{python}\n*\n*   \\begin{align*}\n*      &\\py*{ans.301}\\\\\n*      &\\py*{ans.302}\\\\\n*      &\\py*{ans.303}\\\\\n*      &\\py*{ans.304}\\\\\n*      &\\py*{ans.305}\n*   \\end{align*}\n\\end{latex}\n\\egroup\n\n\\clearpage\n\n% ===================================================================\n\\section*{Source of example-10/calculus/calculus.tex}\n\\begin{latex}\n*   \\Input{./example-10/calculus/derivs/derivs.tex}\n*   \\Input{./example-10/calculus/integrals/integrals.tex}\n\\end{latex}\n\n% ===================================================================\n\\section*{Source of example-10/calculus/derivs/derivs.tex}\n\n\\bgroup\n\\bgcolour{white}\n\\latexstyle\n\\begin{latex}\n*   \\section*{Differentiation}\n*\n*   \\begin{python}\n\\end{latex}\n\\pythonstyle\n\\begin{python}\n*      ans = diff(x*sin(x),x)                                    # py (ans.501,ans)\n*      ans = diff(x*sin(x),x).subs(x,pi/4)                       # py (ans.502,ans)\n\\end{python}\n\\latexstyle\n\\begin{latex}\n*   \\end{python}\n*\n*   \\begin{align*}\n*      &\\py*{ans.501}\\\\\n*      &\\py*{ans.502}\n*   \\end{align*}\n\\end{latex}\n\\egroup\n\n% ===================================================================\n\\section*{Source of example-10/calculus/integrals/integrals.tex}\n\n\\bgroup\n\\bgcolour{white}\n\\latexstyle\n\\begin{latex}\n*   \\section*{Integration}\n*\n*   \\begin{python}\n\\end{latex}\n\\pythonstyle\n\\begin{python}\n*      a, b, x, y = symbols('a b x y')\n*      ans = integrate(2*sin(x)**2, (x,a,b))                     # py (ans.503,ans)\n*      ans = Integral(2*exp(-x**2), (x,0,oo))                    # py (lhs.504,ans)\n*      ans = ans.doit()                                          # py (ans.504,ans)\n*      ans = Integral(Integral(x**2 + y**2, (y,0,x)), (x,0,1))   # py (lhs.505,ans)\n*      ans = ans.doit()                                          # py (ans.505,ans)\n\\end{python}\n\\latexstyle\n\\begin{latex}\n*   \\end{python}\n*\n*   \\begin{align*}\n*      &\\py*{ans.503}\\\\\n*       \\py{lhs.504}&=\\Py{ans.504}\\\\\n*       \\py{lhs.505}&=\\Py{ans.505}\n*   \\end{align*}\n\\end{latex}\n\\egroup\n\n\\clearpage\n\n\\PySetup{action=show}\n\n\\Input{./example-10/limits/limits.tex}\n\\Input{./example-10/calculus/calculus.tex}\n\n\\end{document}\n", "meta": {"hexsha": "7b14d1898f4aff3be974373da590b04d60e7fdef", "size": 4071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-10.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-10.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-10.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": 26.0961538462, "max_line_length": 111, "alphanum_fraction": 0.5377057234, "num_tokens": 1288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6081837991959895}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\usepackage{graphicx}\n\\usepackage{tabularx}\n\n\\usepackage{enumitem}\n\n\\usepackage[english]{babel}\n\\newtheorem{theorem}{Theorem}\n\n% Geometry \n\\usepackage{geometry}\n\\geometry{letterpaper, left=15mm, top=20mm, right=15mm, bottom=20mm}\n\n% Fancy Header\n\\usepackage{fancyhdr}\n\\renewcommand{\\footrulewidth}{0.4pt}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\chead{MAT 341 - Linear Algebra}\n\\lfoot{CALU Fall 2021}\n\\rfoot{RDK}\n\n% Add vertical spacing to tables\n\\renewcommand{\\arraystretch}{1.4}\n\n% Macros\n\\newcommand{\\definition}[1]{\\underline{\\textbf{#1}}}\n\n\\newenvironment{rcases}\n  {\\left.\\begin{aligned}}\n  {\\end{aligned}\\right\\rbrace}\n\n% Begin Document\n\\begin{document}\n\n\\section*{Chapter 1: Theorems \\& Defintions}\n\n\\vspace{5mm}\n\n\\begin{theorem}[Uniqueness of the Reduced Echelon Form]\n  Each matrix is row equivalent to one and only one reduced echelon matrix.\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\begin{theorem}[Existence and Uniqueness Theorem]\n  A linear system is consistent if and only if the rightmost column of the augmented matrix is \\textit{not} a pivot column; ie, if and only if an echelon form of the augmented matrix has no row of the form $[0 \\cdots 0 b]$ with $b$ nonzero.\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\definition{Spans}: If $v_1, \\ldots, v_p$ are in $\\mathbb{R}^2$ the the set of all linear combinations of $v_1, \\ldots, v_p$ is denoted by \\textbf{Span}$\\{v_1, \\ldots, v_p\\}$ and is called the \\definition{subset of $\\mathbb{R}^2$ spanned by $v_1, \\ldots, v_p$}. That is, \\textbf{Span}$\\{v_1, \\ldots, v_p\\}$ is the collection of all vectors, with scalars $c_1, \\ldots, c_p$, that can be written as\n\\begin{equation*}\n  c_1v_1 + c_2v_2 + \\cdots + c_pv_p\n\\end{equation*}\n\n\\vspace{5mm}\n\n\\definition{Matrix Equation}: If $A$ is an $m \\times n$ matrix, with columns $a_1, \\ldots, a_n$, and if $x$ is in $\\mathbb{R}^n$, then the product of $A \\times x$, by $Ax$ is the linear combination of the columns of $A$ using the corresponding entries in $x$ as weights:\n\\begin{equation*}\n  Ax = \\begin{bmatrix}\n    a_1 & a_2 & \\cdots & a_n\n  \\end{bmatrix}\n  \\begin{bmatrix}\n    x_1 \\\\ x_2 \\\\ \\cdots \\\\ x_n\n  \\end{bmatrix}\n  = x_1a_1 + x_2a_2 + \\cdots + x_na_n\n\\end{equation*}\n\n\\vspace{5mm}\n\n\\begin{theorem}\n  If $A$ is an $m \\times n$ matrix, with columns $a_1, \\ldots, a_n$, and if $b$ is in $\\mathbb{R}^m$, then the matrix equation $Ax = b$ has the same solution set as the vector equation\n  \\begin{equation*}\n    x_1a_1 + x_2a_2 + \\cdots + x_na_n\n  \\end{equation*}\n  which, in turn, has the same solution set as the system of linear equations whose augmented matrix is \n  \\begin{equation*}\n    Ax = \\begin{bmatrix}\n      a_1 & a_2 & \\cdots & a_n & b\n    \\end{bmatrix}\n  \\end{equation*}\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\begin{theorem}\n  Let $A$ be an $m \\times n$ matrix. Then the following statements are logically equivalent. That is, for a particular $A$, either they are all true statements or they are all false.\n  \\begin{enumerate}[label=\\alph*.)]\n    \\item For each $b$ in $\\mathbb{R}^m$, the equation $Ax = b$ has a solution.\n    \\item Each $b$ in $\\mathbb{R}^m$ is a linear combination of the columns of $A$.\n    \\item The columns of $A$ span $\\mathbb{R}^m$.\n    \\item $A$ has a pivot position in every row.\n  \\end{enumerate}\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\begin{theorem}\n  If $A$ is an $m \\times n$ matrix, $u$ and $v$ are vectors in $\\mathbb{R}^n$, and $c$ is a scalar, then \n  \\begin{enumerate}[label=\\alph*.)]\n    \\item $A(u + v) = Au + Av$\n    \\item $A(cu) = c(Au)$\n  \\end{enumerate}\n\\end{theorem}\n\n\\pagebreak\n\n\\definition{Homogeneous Systems}: A system of linear equations is said to be \\textbf{homogeneous} if it can be written in the form $Ax = 0$, where $A$ is an $m \\times n$ matrix and $0$ is the zero vector in $\\mathbb{R}^m$.\n\\begin{itemize}\n  \\item Such a system \\textit{always} has at least one solution, namely the \\textbf{trivial solution}, the zero vector.\n  \\item Such a system has a nontrivial solution if and only if the equation has at least one free variable.\n\\end{itemize}\n\n\\vspace{5mm}\n\n\\definition{Linear Independence}: An indexed set of vectors $\\{v_1, \\ldots, v_p\\}$ in $\\mathbb{R}^n$ is said to be \\textbf{linearly independent} if the vector equation\n\\begin{equation*}\n  x_1v_1 + x_2v_2 + \\cdots + x_pv_p\n\\end{equation*}\nhas only the trivial solution. The set $\\{v_1, \\ldots, v_p\\}$ is said to be \\textbf{linearly dependent} if there exist weights $\\{c_1, \\ldots, c_p\\}$, not all zero, such that\n\\begin{equation*}\n  c_1v_1 + c_2v_2 + \\cdots + c_pv_p = 0\n\\end{equation*}\n\n\\vspace{5mm}\n\n\\begin{theorem}[Characterization of Linearly Dependent Sets]\n  An indexed set $S = \\{v_1, \\ldots, v_p\\}$ of two or more vectors is linearly dependent if and only if at least one of the vectors in $S$ is a linear combination of the others.\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\begin{theorem}\n  If a set contains more vectors than there are entries in each vector, then the set is linearly dependent. That is, any set $\\{v_1, \\ldots, v_p\\}$ in $\\mathbb{R}^n$ is linearly dependent if $p > n$.\n\\end{theorem}\n\n\\vspace{5mm}\n\n\\begin{theorem}\n  If a set $S = \\{v_1, \\ldots, v_p\\}$ in $\\mathbb{R}^n$ contains the zero vector, then the set is linearly dependent.\n\\end{theorem}\n\n\\end{document}", "meta": {"hexsha": "16193a0a5937d4d342dfc839d4e6fa8ac8b8c5fb", "size": 5240, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter 1/Theorems/theorems.tex", "max_stars_repo_name": "Bkrenz/calu-mat341", "max_stars_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_stars_repo_licenses": ["MIT"], "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/Theorems/theorems.tex", "max_issues_repo_name": "Bkrenz/calu-mat341", "max_issues_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_issues_repo_licenses": ["MIT"], "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/Theorems/theorems.tex", "max_forks_repo_name": "Bkrenz/calu-mat341", "max_forks_repo_head_hexsha": "2628f0755dde2e4a933131e23cbe8168444fd77c", "max_forks_repo_licenses": ["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.4054054054, "max_line_length": 396, "alphanum_fraction": 0.6965648855, "num_tokens": 1802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191214879991, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.6081739895294854}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage[utf8]{luainputenc}\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{13 mars, 2015}\n\\maketitle\nlet $\\epsilon>0$ and $f\\in C[0,1]$\nThen there is $N$ such that $||f-B_n(f)||_\\infty<\\epsilon$ for all $n>N$.\n\n$B_n(f)=\\sum\\limits_{k=0}^n{f(\\frac{k}{n}\\binom{n}{k}x^k(1-x)^{n-k}}$\n\n\\begin{enumerate}\n\\item\nsince $[0,1]$ is compact and $f\\in C[0,1]$ f is uniformly continuous on $[0,1]$ so there is $\\delta$ such that $|f(x)-f(y)|<\\frac{\\epsilon}{2}$ when $|x-y|< \\delta$\n\\item\n$f$ is bounded on $[0,1]$ so $|f(x)|\\le M=\\sup\\{|f(x)|\\}$ for all $x\\in [0,1]$\n\\item\nnow for $a\\in [0,1]$, if $|x-a|<\\delta$ then $|f(x)-f(a)|<\\epsilon/2+\\frac{2M}{\\delta^2}(x-a)^2$\n\nif $|x-a|\\epsilon \\delta$ then $|f(x)-f(a)\\le|f(x)|+|f(a)|\\le 2M\\le 2M/\\left(x-a)/\\delta\\right)^2\\le \\frac{2M}{\\delta^2}(x-a)^2+\\frac{\\epsilon}{2}$\n\nso for a fixed $a$, no matter what $x$ we let $|f(x)-f(a)|<\\epsilon/2+\\frac{2M}{\\delta^2}(x-a)^2$.\n\nthis is not a good estimate, but it's an estimate that works no matter what.\n\n\\item\n$B_n(f(x)-f(a)\\cdot 1)=B_n(f(x))-B_n(f(a)\\cdot1)=B_n(f(x))-f(a)B_n(1)=B_n(f(x))-f(a)\\cdot 1$ where $1$ is the function that is one for all $x$ and $f(a)$ is a constant.\n\n\n\\end{enumerate}\n\nso $|B_n(f(x))-f(a)|=|B_n(f(x)-f(a)\\cdot1)|\\le B_n(|f(x)-f(a)\\cdot 1|)\\le B_n(\\epsilon/2+2M/\\delta^2(x-a)^2)=B_n(\\epsilon/2)+2M/\\delta^2B_n((x-a)^2)=\\epsilon/2+2M/\\delta^2[B_n(x^2-2ax+a^2]=\\frac{\\epsilon}{2}+2M/\\delta^2(B_n(x^2)-2aB_n(x)+a^2)=\\frac{\\epsilon}{2}+\\frac{2M}{\\delta^2}((x^2+\\frac{x-x^2}{n})-2a(x)+a^2$\n\nrecall that $B_n(1)=1, B_n(x)=x,$ and $B_n(x^2)=\\frac{x+(n-1)x^2}{n}=x^2+\\frac{x-x^2}{n}$\n\nif $g(x)=x-x^2$ then it's max in $[0,1]$ is $g(\\frac{1}{2})=\\frac{1}{4}$ and so $|(B_n(f))(a)-f(a)\\cdot 1|<\\epsilon/2+2M/\\delta^2$\n\nso $|(B_n(f))(a)-f(a)\\cdot 1|<\\epsilon/2+2M/\\delta^2\\frac{a-a^2}{n}$ so $|(B_n(f))(a)-f(a)\\cdot 1|<\\epsilon/2+2M/\\delta^2(\\frac{1}{4n})$\n\n\\subsubsection*{finish}\nthis inequality does not depend on $a$. $||B_n(f)-f||_\\infty<\\epsilon/2+\\frac{2M}{\\delta^2}\\frac{1}{4n}$. Choos $N$ such that $N\\ge \\frac{M}{\\delta^2\\epsilon}$\n\nso $\\frac{M}{2\\delta^2N}<\\epsilon/2$ and $||B_n(f)-f||_\\infty<\\epsilon/2+\\epsilon/2=\\epsilon$ for any $n>N$ in other words, $\\{B_n(f)\\}$ converges to $f$ uniformly on $[0,1]$\n\n\n\\end{document}\n\n", "meta": {"hexsha": "eb65c2466bc155c8e0897bd4259e7060d8d11802", "size": 2425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ra2/ra2-notes-2015-03-13.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": "ra2/ra2-notes-2015-03-13.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": "ra2/ra2-notes-2015-03-13.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.5438596491, "max_line_length": 314, "alphanum_fraction": 0.6078350515, "num_tokens": 1105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6081595783720118}}
{"text": "\\chapter{Physics Models}\n\\label{ch:models}\n\n\\apsq implements a variety of models to describe the physics of semiconductor detectors.\nThese models are implemented module-independently and can be selected via configuration parameters in the respective models.\nThis chapter serves as central reference for the different models.\n\n\\section{Charge Carrier Mobility}\n\\label{sec:mobility}\n\n\\apsq provides different charge carrier mobility models, the best-suited model depends on the simulated device and other simulation parameters.\nSome models depend on the electric field strength to parametrize the mobility, others on the doping concentration of the device.\nThe charge carrier mobility models are used by all propagation modules and comprise the following models:\n\n\\subsection{Jacoboni-Canali Model}\n\\label{sec:mob:jac}\n\nThe Jacoboni-Canali model~\\cite{jacoboni} is the most widely used parametrization of charge carrier mobility in Silicon as a function of the electric field $E$.\nIt has originally been derived for $\\left<111\\right>$ silicon lattice orientation, but is widely used also for the common $\\left<100\\right>$ orientation.\nThe mobility is parametrized as\n\\begin{equation}\n    \\label{eq:mob:jac}\n    \\mu (E) = \\frac{v_m}{E_c} \\frac{1}{\\left(1 + (E / E_c)^\\beta \\right)^{1 / \\beta}},\n\\end{equation}\nwhere $v_m$, $E_c$, and $\\beta$ are phenomenological parameters, defined for electrons and holes respectively.\nThe temperature dependence of these parameters is taken into account by scaling them with respect to a reference parameter value as\n\\begin{equation}\n    A = A_{ref} \\cdot T^{\\gamma}\n\\end{equation}\nwhere $A_{ref}$ is the reference parameter value, $T$ the temperature in units of \\si{K}, and $\\gamma$ the temperature scaling factor.\n\nThe parameter values implemented in \\apsq are taken from Table~5 of~\\cite{jacoboni} as:\n\\begin{equation*}\n    \\begin{split}\n        v_{m,e} &= \\num{1.53e9} \\cdot T^{-0.87}\\,\\si{cm \\per s}\\\\\n        E_{c,e} &= \\num{1.01} \\cdot T^{1.55}\\,\\si{V \\per cm}\\\\\n        \\beta_e &= \\num{2.57e-2} \\cdot T^{0.66}\n    \\end{split}\n    \\qquad\n    \\begin{split}\n        v_{m,h} &= \\num{1.62e8} \\cdot T^{-0.52}\\,\\si{cm \\per s}\\\\\n        E_{c,h} &= \\num{1.24} \\cdot T^{1.68}\\,\\si{V \\per cm}\\\\\n        \\beta_h &= \\num{0.46} \\cdot T^{0.17}\n    \\end{split}\n\\end{equation*}\nfor electrons and holes, respectively.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"jacoboni\"}.\n\n\\subsection{Canali Model}\n\\label{sec:mob:can}\n\nThe Canali model~\\cite{canali} differs from the Jacoboni-Canali model from equation~\\eqref{eq:mob:jac} only by the value of $v_m$ for electrons.\nThe difference is most likely a typo in the Jacoboni reproduction of the parametrization, so this one can be considered the original parametrization derived from data.\nThe altered value is taken from equation~2a in~\\cite{canali} and amounts to\n\\begin{equation*}\n    v_{m,e} = \\num{1.43e9} \\cdot T^{-0.87}\\,\\si{cm \\per s}\n\\end{equation*}\n\nA comparison with other models exhibits a better accordance of the electron mobility compared to the Jacoboni-Canali parameter value, especially at very high values of the electric field.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"canali\"}.\n\n\\subsection{Hamburg Model}\n\nThe Hamburg model~\\cite{hamburg} presents an empirical parametrization of electron and hole mobility as a function of the electric field $E$ based on measurements of drift velocities in high-ohmic silicon with $\\left<100\\right>$ lattice orientation.\nThe mobility is parametrized as\n\\begin{align}\n    \\label{eq:mob:ham}\n    \\mu_e^{-1}(E) &= 1 / \\mu_{0,e} + E / v_{sat} \\nonumber \\\\\n    \\mu_h^{-1}(E) &= 1 / \\mu_{0,h} &\\quad \\textrm{for} \\quad E < E_0 \\nonumber \\\\\n                  &= 1 / \\mu_{0,h} + b \\cdot (E - E_0) + c \\cdot (E - E_0)^2 &\\quad \\textrm{for} \\quad E \\geq E_0\n\\end{align}\nas taken from equations~3 and~5 of~\\cite{hamburg}.\n\nThe temperature dependence of the model parameters are calculated with respect to their reference values at a temperature of \\SI{300}{K} via equation~6 of~\\cite{hamburg} as\n\\begin{equation}\n    \\label{eq:mob:ham:temp}\n    A_i = A_i(T = \\SI{300}{K}) \\cdot \\left(\\frac{T}{\\SI{300}{K}}\\right)^{\\gamma_i}\n\\end{equation}\nThe hole mobility parameter $c$ is assumed to have no temperature dependence.\n\nThe parameter values implemented in \\apsq are taken from Table~4 of~\\cite{hamburg} as:\n\\begin{equation*}\n    \\begin{split}\n        \\mu_{0,e} &= \\SI{1530}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.42}\\\\\n        v_{sat}   &= \\SI{1.03e7}{cm \\per s} \\cdot (T / \\SI{300}{K})^{-0.226}\\\\\n    \\end{split}\n    \\qquad\n    \\begin{split}\n      \\mu_{0,h} &= \\SI{464}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.20}\\\\\n        b       &= \\SI{9.57e-8}{cm \\per s} \\cdot (T / \\SI{300}{K})^{-0.101}\\\\\n        c       &= \\SI{-3.31e-13}{s \\per V}\\\\\n        E_0     &= \\SI{2640}{V \\per cm} \\cdot (T / \\SI{300}{K})^{0.526}\n    \\end{split}\n\\end{equation*}\nfor electrons and holes, respectively.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"hamburg\"}.\n\n\n\\subsection{Hamburg High-Field Model}\n\nThe Hamburg high-field model~\\cite{hamburg} takes the same form as the Hamburg model provided in equation~\\eqref{eq:mob:ham} but uses a different set of parameter values.\nThe values are taken from Table~3 of~\\cite{hamburg} and are suitable for electric field strengths above \\SI{2.5}{\\kilo V/cm}.\nAgain, no temperature dependence is assumed on hole mobility parameter $c$, while all other parameters are scaled to temperatures different than \\SI{300}{K} using equation~\\eqref{eq:mob:ham:temp}.\n\nThe parameter values implemented in \\apsq are:\n\\begin{equation*}\n    \\begin{split}\n        \\mu_{0,e} &= \\SI{1430}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-1.99}\\\\\n        v_{sat}   &= \\SI{1.05e7}{cm \\per s} \\cdot (T / \\SI{300}{K})^{-0.302}\\\\\n    \\end{split}\n    \\qquad\n    \\begin{split}\n      \\mu_{0,h} &= \\SI{457}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.80}\\\\\n        b       &= \\SI{9.57e-8}{cm \\per s} \\cdot (T / \\SI{300}{K})^{-0.155}\\\\\n        c       &= \\SI{-3.24e-13}{s \\per V}\\\\\n        E_0     &= \\SI{2970}{V \\per cm} \\cdot (T / \\SI{300}{K})^{0.563}\n    \\end{split}\n\\end{equation*}\nfor electrons and holes, respectively.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"hamburg_highfield\"}.\n\n\\subsection{Masetti Model}\n\\label{sec:mob:mas}\n\nThe Masetti mobility model~\\cite{masetti} parametrizes electron and hole mobility as a function of the total doping concentration $D$ of the silicon material.\nThis model requires a doping profile to be loaded for the detector in question, and an error will be returned if the doping profile is missing.\n\nWhile this mobility model requires the \\emph{total doping concentration} $N_D + N_A$ as parameter, the doping profile used throughout \\apsq provides the \\emph{effective doping concentration} $N_D - N_A$ since this also encodes the majority charge carriers via its sign.\nHowever, in the parts of a silicon detector relevant for this simulation, i.e.\\ the sensing volume, the difference between effective and total concentration is expected to be negligible.\nTherefore the doping concentration in this model is taken as the absolute value $N = \\left|N_D - N_A\\right|$.\n\nThe mobility is parametrized as\n\\begin{equation}\n    \\label{eq:mob:mas}\n    \\begin{split}\n        \\mu_e(N) &= \\mu_{0,e} + \\frac{\\mu_{max,e} - \\mu_{0,e}}{1 + (N / C_{r,e})^{\\alpha_e}} - \\frac{\\mu_{1,e}}{(1 + (C_{s,e} / N)^{\\beta_e})}\\\\\n        \\mu_h(N) &= \\mu_{0,h} + \\frac{\\mu_{max,h}}{1 + (N / C_{r,h})^{\\alpha_h}} - \\frac{\\mu_{1,h}}{(1 + (C_{s,h} / N)^{\\beta_h})} + e^{P_c / N}\\\\\n\\end{split}\n\\end{equation}\nas taken from equations~1 (for electrons) and~4 (for holes) of~\\cite{masetti}.\n\nOnly the parameters $\\mu_{max}$ for both electrons and holes are temperature dependent and are scaled according to Equation~\\eqref{eq:mob:ham:temp} with parameters $\\gamma_e = -2.5$ for electrons and $\\gamma_h = -2.2$ for holes.\n\nThe parameter values implemented in \\apsq are taken from Table~I of~\\cite{masetti} as:\n\\begin{equation*}\n    \\begin{split}\n        \\mu_{0,e}   &= \\SI{52.2}{cm^2 \\per V \\per s}\\\\\n        \\mu_{max,e} &= \\SI{1417}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.5}\\\\\n        C_{r,e}     &= \\SI{9.68e16}{\\per \\cubic \\cm}\\\\\n        \\alpha_{e}  &= 0.68\\\\\n        \\mu_{1,e}   &= \\SI{43.4}{cm^2 \\per V \\per s}\\\\\n        C_{s,e}     &= \\SI{3.43e20}{\\per \\cubic \\cm}\\\\\n        \\beta_{e}   &= 2.0\\\\\n    \\end{split}\n    \\qquad\n    \\begin{split}\n        \\mu_{0,h}   &= \\SI{44.9}{cm^2 \\per V \\per s}\\\\\n        \\mu_{max,h} &= \\SI{470.5}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.2}\\\\\n        C_{r,h}     &= \\SI{2.23e17}{\\per \\cubic \\cm}\\\\\n        \\alpha_{h}  &= 0.719\\\\\n        \\mu_{1,h}   &= \\SI{29.0}{cm^2 \\per V \\per s}\\\\\n        C_{s,h}     &= \\SI{6.1e20}{\\per \\cubic \\cm}\\\\\n        \\beta_{h}   &= 2.0\\\\\n        P_{c}       &= \\SI{9.23e16}{\\per \\cubic \\cm}\\\\\n    \\end{split}\n\\end{equation*}\nfor electrons and holes, respectively.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"masetti\"}.\n\n\n\\subsection{Arora Model}\n\nThe Arora mobility model~\\cite{arora} parametrizes electron and hole mobility as a function of the total doping concentration of the silicon material.\nThis model requires a doping profile to be loaded for the detector in question, and an error will be returned if the doping profile is missing.\nThe same caveat to doping concentration information in \\apsq applies as described in the previous section.\n\nThe mobility is parametrized as\n\\begin{equation}\n    \\label{eq:mob:aro}\n    \\begin{split}\n        \\mu_e(N) &= \\mu_{min,e} + \\mu_{0,e} / \\left(1 + (N / N_{ref,e})^{\\alpha}\\right)\\\\\n        \\mu_h(N) &= \\mu_{min,h} + \\mu_{0,h} / \\left(1 + (N / N_{ref,h})^{\\alpha}\\right)\\\\\n    \\end{split}\n\\end{equation}\nas taken from equations~8 (for electrons) and~12 (for holes) of~\\cite{arora}.\n\nThe parameter values are provided at the reference temperature of \\SI{300}{K} and scaled to different temperatures according to Equation~\\eqref{eq:mob:ham:temp}.\nThe values implemented in \\apsq are taken from Table~1 of~\\cite{arora} as:\n\\begin{equation*}\n    \\begin{split}\n        \\mu_{min,e} &= \\SI{88.0}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-0.57}\\\\\n        \\mu_{0,e}   &= \\SI{7.40e8}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.33}\\\\\n        N_{ref,e}   &= \\SI{1.26e17}{\\per \\cubic \\cm} \\cdot (T / \\SI{300}{K})^{2.4}\\\\\n    \\end{split}\n    \\qquad\n    \\begin{split}\n        \\mu_{min,h} &= \\SI{54.3}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-0.57}\\\\\n        \\mu_{0,h}   &= \\SI{1.36e8}{cm^2 \\per V \\per s} \\cdot (T / \\SI{300}{K})^{-2.23}\\\\\n        N_{ref,h}   &= \\SI{2.35e17}{\\per \\cubic \\cm} \\cdot (T / \\SI{300}{K})^{2.4}\\\\\n        \\alpha   &= 0.88 \\cdot (T / \\SI{300}{K})^{-0.146}\n    \\end{split}\n\\end{equation*}\nfor electrons and holes, respectively.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"arora\"}.\n\n\\subsection{Extended Canali Model}\n\nThis model extends the Jacoboni/Canali model described in Section~\\ref{sec:mob:jac} with other doping concentration dependent, low-field models such as the Masetti model described in Section~\\ref{sec:mob:mas}.\nThis technique is for example used in the Synopsys Sentaurus TCAD software.\n\nThe mobility is then parametrized using the two models as:\n\\begin{equation}\n    \\label{eq:mob:mascan}\n    \\mu (E, N) = \\frac{\\mu_{m}(N)}{\\left(1 + \\left(\\mu_{m}(N) \\cdot E / v_{m} \\right)^{\\beta} \\right)^{1 / \\beta}}\n\\end{equation}\nwhere $\\mu_{m}(N)$ is the Masetti mobility from Equation~\\eqref{eq:mob:mas}, and $v_{m}$, $\\beta$ are the respective parameters from the Jacoboni/Canali model presented in Sections~\\ref{sec:mob:jac}~and~\\ref{sec:mob:can}.\n\nThis model can be selected in the configuration file via the parameter \\parameter{mobility_model = \"masetti_canali\"}.\n\n\n\\section{Charge Carrier Lifetime \\& Recombination}\n\\label{sec:recombination}\n\n\\apsq provides the possibility to simulate finite lifetimes of charge carriers as a function of the local doping concentration via non-radiative recombination processes.\nWhile most of these models require the \\emph{total doping concentration} $N_D + N_A$ as parameter, the doping profile used throughout \\apsq provides the \\emph{effective doping concentration} $N_D - N_A$ since this also encodes the majority charge carriers via its sign - an information relevant to some of the models.\nHowever, in the parts of a silicon detector relevant for this simulation, i.e.\\ the sensing volume, the difference between effective and total concentration is expected to be negligible.\nTherefore the two values are treated as equivalent throughout the lifetime models and the doping concentration is taken as the absolute value $N = \\left|N_D - N_A\\right|$.\n\nWhether a charge carrier has recombined with the lattice is calculated for every step of the simulation using the relation\n\\begin{equation}\n    \\label{eq:recomb:prob}\n    p < 1 - e^{- dt / \\tau(N)}\n\\end{equation}\nwhere $p$ is a recombination probability, drawn from a uniform distribution with $[0, 1]$, $dt$ is the last time step of the charge carrier motion and $\\tau$ the lifetime for the local doping concentration calculated by the models described in the following.\nIf Equation~\\eqref{eq:recomb:prob} evaluates to \\emph{false}, the charge carrier still exists, if it evaluates to \\emph{true} it has been recombined with the lattice.\n\nFinite charge carrier lifetime can be simulated by all propagation modules and comprise the following models:\n\n\\subsection{Shockley-Read-Hall Recombination}\n\nThis model describes the finite lifetime based on Shockley-Read-Hall or trap-assisted recombination of charge carriers with the lattice~\\cite{shockley-read,hall}.\nThe lifetime is calculated using the Shockley-Read-Hall relation as given by~\\cite{fossum-lee}:\n\\begin{equation}\n    \\tau(N) = \\frac{\\tau_0}{1 + \\frac{N}{N_{d0}}}\n\\end{equation}\nwhere $\\tau_0$ and $N_{d0}$ are reference lifetime and doping concentration, for electrons and holes respectively.\nThe parameter values implemented in \\apsq are taken from~\\cite{fossum} as:\n\\begin{equation*}\n    \\begin{split}\n        \\tau_{0,e} &= \\SI{1e-5}{s} \\\\\n        N_{d0,e}   &= \\SI{1e16}{\\per \\cubic \\cm} \\\\\n    \\end{split}\n    \\qquad\n    \\begin{split}\n        \\tau_{0,e} &= \\SI{4.0e-4}{s} \\\\\n        N_{d0,e}   &= \\SI{7.1e15}{\\per \\cubic \\cm} \\\\\n    \\end{split}\n\\end{equation*}\n\nThis model can be selected in the configuration file via the parameter \\parameter{recombination_model = \"srh\"}.\n\n\\subsection{Auger Recombination}\n\nThe charge carrier lifetime according to the Auger recombination model is calculated as:\n\\begin{equation}\n    \\tau(N) = \\frac{1}{C_{a} \\cdot N^2}\n\\end{equation}\nwhere $C_{a}$ is the Auger coefficient, taken as $C_{a} = \\SI{3.8e-31}{\\cm^6 \\per \\s}$ from~\\cite{dziewior}.\n\nThis recombination mode applies to minority charge carriers only, majority charge carriers have an infinite life time under this model and Equation~\\eqref{eq:recomb:prob} will always evaluate to \\emph{true}.\n\nThis model can be selected in the configuration file via the parameter \\parameter{recombination_model = \"auger\"}.\n\n\\subsection{Combined SRH/Auger Recombination}\n\nThis model combines the charge carrier recombination from the Shockley-Read-Hall and the Auger model by inversely summing the individual lifetimes calculated by the models via\n\\begin{align}\n    \\label{eq:recom:combined}\n    \\tau^{-1}(N) &= \\tau_{srh}^{-1}(N) + \\tau_{a}^{-1}(N) &\\quad \\textrm{for \\emph{minority} charge carriers} \\nonumber \\\\\n              &= \\tau_{srh}^{-1}(N) &\\quad \\textrm{for \\emph{majority} charge carriers}\n\\end{align}\nwhere $\\tau_{srh}(N)$ is the Shockley-Read-Hall and $\\tau_{a}(N)$ the Auger lifetime.\nThe latter is only taken into account for minority charge carriers.\n\nThis model can be selected in the configuration file via the parameter \\parameter{recombination_model = \"srh_auger\"}.\n", "meta": {"hexsha": "4ad028435bcf9d0d2be37355714c9a58d23064f3", "size": 16066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/usermanual/chapters/models.tex", "max_stars_repo_name": "bencline1/Allpix_GaAs", "max_stars_repo_head_hexsha": "c4922dc9d981aca265e076eb5bfe4cefe51913a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-04T22:31:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-20T11:19:17.000Z", "max_issues_repo_path": "doc/usermanual/chapters/models.tex", "max_issues_repo_name": "bencline1/Allpix_GaAs", "max_issues_repo_head_hexsha": "c4922dc9d981aca265e076eb5bfe4cefe51913a2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2019-04-01T12:25:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-03T12:20:19.000Z", "max_forks_repo_path": "doc/usermanual/chapters/models.tex", "max_forks_repo_name": "bencline1/Allpix_GaAs", "max_forks_repo_head_hexsha": "c4922dc9d981aca265e076eb5bfe4cefe51913a2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2017-08-08T14:57:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-26T17:16:21.000Z", "avg_line_length": 55.0205479452, "max_line_length": 317, "alphanum_fraction": 0.6843644965, "num_tokens": 4981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.7057850402140659, "lm_q1q2_score": 0.6080607822983901}}
{"text": "\\newcommand{\\bY}{\\mathbf{Y}}\r\n\\newcommand{\\NN}{\\mathbb{N}}         \r\n\\newcommand{\\PP}{\\text{PP}}         \r\n%\\nipsfinalcopy % Uncomment for camera-ready version\r\n\r\n% \\subsection{Notation}\r\n% \r\n% Unless otherwise specified, we let lower-case English alphabet characters indicate scalars $x \\in \\Real$. Bold indicates column vectors $\\mb{x} \\in \\Real^p$,\r\n% and upper-case bold indicates matrices, $\\bX \\in \\Real^{p \\times q}$.  Parameters and constants are Greek characters.  Time is $t \\in [0,T]$, \r\n% $i \\in [N]$ indexes the $N$ neurons, where $[N]=\\{1,2,\\ldots,N\\}$. Script denotes sets and pipes denote the cardinality of the set, e.g. $|\\mc{T}|$.  We let $\\equiv$ denote ``is shorthand for''. San serif fonts, e.g., $\\mathsf{H}$, denote functions. \r\n% %\\vspace{-.1in}\r\n% \\subsection{Input}\r\n% %\\vspace{-.1in}\r\n% % \\subsection{Data Model}\r\n% Our data is a time-series of multielectrode recordings $\\bX \\equiv (\\bx_1, \\cdots, \\bx_T)$, and consists of $T$ recordings from $M$ channels. \r\n% The set of recording times lie on regular grid with interval length $\\Delta$, while $\\bx(t) \\equiv \\bx_t\\in \\mathbb{R}^M$ for all $t$. \r\n% This time-series of electrical activity is driven by an unknown number of neurons;  \r\n% we do not wish to bound this number \\emph{a priori}. %, though only a few of the infinite\r\n% =======\r\n% \\subsection{Data Model}\r\n\r\nOur data is a time-series of multielectrode recordings $\\bX \\equiv (\\bx_1, \\cdots, \\bx_T)$, and consists of $T$ recordings from $M$ channels. \r\nAs in usual measurement systems, the recording times lie on regular grid, with interval length $\\Delta$, and $\\bx_t \\in \\mathbb{R}^M$ for all $t$. \r\nUnderlying these observations is a continuous-time electrical signal driven by an unknown number of neurons. %and \r\n%we do not wish to bound this number \\emph{a priori}. %, though only a few of the infinite\r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\n%neurons dominate. These neurons contribute the majority of the activity in any finite interval of time; however, as time passes, the total number of \r\n%observed neurons increases {\\color{red}(Justify?)}. \r\n%Each neuron, has its own `shape' A natural model in such a situation is to\r\nEach neuron generates a continuous-time voltage trace, and  the outputs of all neurons are superimposed and discretely sampled to produce \r\nthe recordings $\\bX$.  At a high level, in \\S \\ref{sec:spike} we model the continuous-time output of each neuron as a\r\nseries of idealized Poisson events smoothed with appropriate kernels, while\r\n\\S \\ref{sec:crm} uses the Gamma process to develop a nonparametric prior for an entire population.\r\n\\S \\ref{sec:disc_time} then describes a discrete-time approximation based on the Bernoulli approximation to the Poisson process. For\r\nconceptual clarity, we restrict ourselves to single channel recordings until \\S \\ref{sec:multi}, where we describe the complete model for multichannel data.\r\n%, and apply this to the observed data.\r\n%Each neuron has its own distribution over waveform shapes. \r\n% \r\n% We describe this in detail, starting first with a model for a single channel recording $\\bx \\equiv (x_1, \\cdots, x_T)\\T$.\r\n% =======\r\n%We start first with the model for the continuous-time output of a single neuron, $x(t)$.\r\n%channel recording $\\bx\\T \\equiv (x_1, \\cdots, x_T)$.\r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\n\r\n%\\vspace{-.1in}\r\n\\subsection{Modeling the continuous-time output of a single neuron} \\label{sec:spike}\r\n%\\vspace{-.1in}\r\nThere is a rich literature characterizing the spiking activity of a single neuron \\citep{gerst08} accounting in detail for factors like non-stationarity, \r\nrefractoriness and spike waveform. We however make a number of simplifying assumptions (some of which we later relax).\r\n%, others we leave for future work). \r\n%Figure \\ref{fig:schematic} \\jovo{@dec - is this fig gonna happen?} provides a schematic depiction of our generative process.\r\nFirst, we model the spiking activity of each neuron as stationary and memoryless, so that its set of spike times are \r\ndistributed as a homogeneous Poisson process ($\\PP$).  %{\\color{red} justify?}\r\n We model the neurons themselves are heterogeneous, with the $i^{th}$ neuron having\r\nan (unknown) firing rate $\\lambda_i$. \r\n% For the $i^{th}$ neuron, the $j^{th}$ spike time is denoted $\\tau_{ij} \\in \\mc{T}_i$\r\nCall the ordered set of spike times of the $i^{th}$ neuron $\\mc{T}_i=(\\tau_{i1}, \\tau_{i2},\\ldots)$; then the time between successive elements of $\\mc{T}_i$ is \r\nexponentially distributed with mean $1/\\lambda_i$. We write this as\r\n$ \\mc{T}_i \\sim \\PP(\\lambda_i)$.\r\n\r\nThe actual electrical output of a neuron is not binary; instead each spiking event is a smooth perturbation in voltage about a\r\nresting state. This perturbation forms the shape of the spike, %and without any loss of generality, we set the resting state to zero. \r\n%{(\\color{red} figure? better biological description? comment on how we preprocess the data to get zero mean?)}. \r\nwith the spike shapes varying across neurons as well as across different spikes of the same neuron. However, each \r\nneuron has its own characteristic distribution over shapes, and we let $\\bth^*_i \\in \\Theta$ parametrize this distribution for neuron $i$.\r\n % having parameter $\\bth^*_i$. \r\nWhenever this neuron emits a \r\nspike, a new shape is drawn independently from the corresponding distribution. %$p_{\\bth_i}$, and \r\nThis waveform is then offset to the time of the spike, and contributes to the voltage trace associated with that spike. \r\n\r\nThe complete recording from\r\nthe neuron is the superposition of all these spike waveforms plus noise.  \r\nRather that treating the noise as white as is common in the literature \\citep{Lewicki}, we allow it to exhibit temporal correlation,\r\nrecognizing that the `noise' is in actual fact background neural activity. \r\nWe model it as a realization of a Gaussian process (GP) \\citep{RasWil2006}, with the covariance kernel $\\mathcal{K}$ of the GP determining\r\nthe temporal structure. We use an exponential kernel, modeling the noise as Markov.  %start by assuming the noise at each observation time is i.i.d.\\ Gaussian.\r\n\r\n% Comment on how this dictionary is obtained now, or in section on inference?)}. \r\nWe model each spike shape as weighted superpositions of a dictionary of $K$ basis functions \r\n$\\mathsf{\\bd}(t) \\equiv (\\mathsf{d}_1(t), \\cdots, \\mathsf{d}_K(t))\\T$. The\r\ndictionary elements are shared across all neurons, and each is a real-valued function of time, i.e., $\\mathsf{d}_k \\in L_2$.\r\n% For the $i^{th}$ neuron, the $j^{th}$ spike time $\\tau_{ij} \\in \\mc{T}_i$, \r\nEach spike time $\\tau_{ij}$ is associated with a random $K$-dimensional weight vector $\\tby_{ij} \\equiv (\\ty_{ij1}, \\ldots \\ty_{ijK})\\T$, and the \r\nshape of this spike at time $t$ is given by the weighted sum $\\sum_{k=1}^K \\ty_{ijk} \\mathsf{d}_k(t-\\tau_{ij})$. We assume $\\tby_{ij} \\sim \\mathsf{N}_K(\\mb{\\mu}^*_i, \\Sigma^*_i)$, indicating a $K$-dimensional \r\nGaussian distribution with mean and covariance given by $(\\mb{\\mu}^*_i, \\Sigma^*_i)$; we let $ \\theta^*_i \\equiv (\\mb{\\mu}^*_i, \\Sigma^*_i) $.   Then, at any time $t$, the output of neuron $i$ is\r\n$\r\n  x_{i}(t) = \\sum_{j=1}^{|\\mc{T}_i|} \\sum_{k=1}^K \\ty_{ijk} \\mathsf{d}_k(t - \\tau_{ij}).\r\n$\r\n\r\n% \r\n% \r\n% \r\n% \\begin{center}\r\n% \\begin{figure}\r\n% % \\includegraphics[width=\\textwidth]{../figs/truefalsepositive}\r\n% \\caption{Schematic of our Generative Model.}\r\n% \\label{fig:schmetic}\r\n% \\end{figure}\r\n% \\end{center}\r\n% \r\n{The total signal received by any electrode  is the superposition of the outputs of all neurons. Assume for the moment there are $N$\r\nneurons, and define $\\mc{T} \\equiv \\cup_{i \\in [N]} \\mc{T}_i$ as\r\nthe (ordered) union of the spike times of all neurons. \r\nLet $\\tau_l \\in \\mc{T}$ indicate the time of the $l^{th}$ overall spike, whereas $\\tau_{ij} \\in \\mc{T}_i$ is the time of the $j^{th}$ spike of neuron $i$.\r\n%To map elements  $\\tau_{ij} \\in \\mc{T}_i$ to elements  $\\tau_l \\in \\mc{T}$,   \r\nThis defines a pair of mappings: $\\nu:[|\\mc{T}|]\\rightarrow [N]$, and $p:[|\\mc{T}|]\\rightarrow \\mc{T}_{\\nu_i}$, with %$(i = \\nu(l))$, , which maps from the $j^{th}$ spikes of neuron $i$ to the $l^{th}$ overall spike.\r\n$\\tau_l = \\tau_{\\nu_l p_l}$. \r\n%\\jovo{i don't think the square brackets around $\\mc{T}$ are correct, we are mapping from the set of spikes, not the number of spikes, right?} \r\nIn words, $\\nu_l \\in N$ is the neuron to which the $l^{th}$ element of $\\mc{T}$ belongs, \r\nwhile $p_l$ indexes this spike in the spike train $\\mc{T}_{\\nu_l}$.\r\n%\\jovo{``position'' is weird to me.  can we say: ``indexes which spike of neuron $\\nu_l$'', or something like that?}.\r\nLet $\\bth_l \\equiv (\\mb{\\mu}_l, \\Sigma_l)$ be the neuron parameter associated with spike $l$, so that $\\bth_l = \\bth^*_{\\nu_l}$. \r\nFinally, define $\\by_l \\equiv (y_{l1}, \\ldots, y_{lK})\\T \\equiv \\tby_{\\nu_j p_j}$ as the weight vector of spike $\\tau_l$. Then, we have that}\r\n% \\begin{subequations}\r\n\\begin{align}\r\n  x(t) &= \\sum_{i \\in [N]} x_{i}(t) =   \\sum_{l \\in |\\mc{T}|} \\sum_{k \\in [K]} y_{lk} \\mathsf{d}_k(t - \\tau_{l}), \\qquad %\\label{eq:spk_sup} \\\\\r\n% \\intertext{where}\r\n  \\text{ where } \\by_{l}  \\sim \\mathsf{N}_K(\\mb{\\mu}_{l}, \\Sigma_{l}). \\label{eq:spk}\r\n\\end{align}\r\n% \\end{subequations}\r\n% \r\nFrom the superposition property of the Poisson process \\citep{kingman93}, the overall spiking activity $\\mc{T}$ is \r\nPoisson with rate $\\Lambda = \\sum_{i \\in [N]} \\lambda_i$. Each event $\\tau_l \\in \\mc{T}$ has a pair of labels, its neuron parameter\r\n$\\bth_l \\equiv (\\mb{\\mu}_l, \\Sigma_l)$, and $\\by_l$, the weight-vector characterizing the spike shape. We view these weight-vectors as the ``marks'' of a \r\nmarked Poisson process $\\mc{T}$.  From the properties of the Poisson process, we have that the marks $\\bth_l$ are drawn i.i.d. from a probability measure\r\n$\\  \\mathsf{G}(\\dd \\bth) = 1/\\Lambda\\sum_{i \\in [N]} \\lambda_i \\delta_{\\bth^*_i}$.\r\n\r\nWith probability one, the neurons have distinct parameters, so that the mark $\\bth_l$ identifies the neuron which produced spike $l$: $\\mathsf{G}(\\bth_l = \\bth^*_i) = \\mathsf{P}(\\nu_l= i) = \\lambda_i/$$\\Lambda$. Given $\\bth_l$, $\\by_l$ is distributed as in\r\nEq.~\\eqref{eq:spk}. The output waveform $x(t)$ is then a linear functional of this marked Poisson process. % (Eq.~\\eqref{eq:spk_sup}). \r\n\r\n%\\vspace{-.1in}\r\n\\subsection{A nonparametric model of population activity}  \\label{sec:crm}\r\n%\\vspace{-.1in}\r\n\r\n%The previous section assumed a known number of neurons $N$; \r\nIn practice, the number of neurons driving the recorded activity is unknown. We do not wish to bound this number \\emph{a priori}, \r\nmoreover we expect this number to increase as we \r\nrecord over longer intervals. This suggests a nonparametric Bayesian approach: allow the \\emph{total} \r\nnumber of underlying neurons to be infinite.\r\nOver any finite interval, only a finite subset of these will be \\emph{active}, and typically, these dominate spiking activity over any interval.\r\nThis elegant and flexible modeling approach allows the data to suggest how many neurons are active, and has already proved \r\nsuccessful in neuroscience applications \\citep{WoodBla2008}.\r\n%where we allow the number of neurons to be infinite.\r\n%this leads to \r\n%While the number of neurons observed over any finite observation interval is finite, this number increases with the observation interval. \r\n%This makes sense in a biological context, in that as we record for longer (e.g., days, weeks, or months even), certain neurons will die or drop-out, and others will appear, simply by virtue of the electrodes moving, for example. \r\n %, moreover the total rate $\\Lambda$ of all neurons must also be finite.\r\n%the total rate $\\Lambda$ must \r\n%also be finite. Moreover, we want this to be dominated by a few $\\lambda_i$: the corresponding neurons contribute the majority of the spiking\r\n%activity in the observation interval. \r\n% A natural framework that captures our  modeling requirements is that of \\emph{completely random measures} (CRMs) \\citep{Kingman:PJM67}.\r\n% CRMs are stochastic processes that form flexible and convenient priors over\r\n% infinite dimensional objects like probability distributions \\citep{JamesLP09}, hazard functions \\citep{Hjo1990}, latent features \\citep{ThiJor2007}. \r\n% These have been well studied in the Bayesian nonparametrics and machine learning communities, and there is a wealth of literature on\r\n% theoretical properties, as well as posterior computation.\r\n% \r\n% Recall that each neuron is characterized by a pair of parameters $(\\lambda_i, \\bth^*_i)$; characterizing the distribution over spike times \r\n% and shapes respectively. With Eq.~\\eqref{eq:mark_distr} in mind, we map the infinite collection of pairs $\\{(\\lambda_i, \\bth^*_i)\\}$ to an atomic measure on $\\Theta$:\r\n% $\\quad \\mathsf{\\Lambda}(\\dd \\bth) = \\sum_{i=1}^{\\infty} \\lambda_i \\delta_{\\bth^*_i}$.\r\n% \r\n% =======\r\nWe use the framework of \\emph{completely random measures} (CRMs) \\citep{Kingman:PJM67} to model our data.\r\n%CRMs are stochastic processes that form flexible and convenient priors over\r\n%infinite dimensional objects like probability distributions \\citep{JamesLP09}, hazard functions \\citep{Hjo1990}, latent features \\citep{ThiJor2007}. \r\nCRMs have been well studied in the Bayesian nonparametrics community, and there is a wealth of literature on\r\ntheoretical properties, as well as posterior computation; see e.g.\\ \\citep{JamesLP09, Hjo1990, ThiJor2007}. \r\n%Recall that each neuron is characterized by a pair of parameters $(\\lambda_i, \\bth^*_i)$; characterizing the distribution over spike times \r\n%and shapes respectively. \r\nRecalling that each neuron is characterized by a pair of parameters $(\\lambda_i, \\bth^*_i)$, %and with the measure $\\mathsf{G}(\\dd \\bth)$ in mind,\r\nwe map the infinite collection of pairs $\\{(\\lambda_i, \\bth^*_i)\\}$ to an random measure $\\Lambda(\\cdot)$ on $\\Theta$:\r\n$\\ \\  \\Lambda(\\dd \\bth) = \\sum_{i=1}^{\\infty} \\lambda_i \\delta_{\\bth^*_i}$.\r\n\r\nFor a CRM, the distribution over measures is induced by distributions\r\nover the infinite sequence of weights, and the infinite sequence of their locations. \r\nThe weights $\\lambda_i$ are the jumps of a \\Levy process \\citep{Sato90}, and their distribution is characterized by a \r\n\\Levy measure $\\rho(\\lambda)$. The locations $\\bth^*_i$ are drawn i.i.d.\\  from a base probability measure $\\mathsf{H}(\\bth^*)$.\r\nAs is typical, we assume these to be independent. % (though this is not necessary). \r\n%{\\color{green} if there's space, I\r\n%can elaborate on the construction of the CRM from its Levy measure, though this is not necessary}\r\n\r\nWe set the \\Levy measure $\\rho(\\lambda) = \\alpha \\lambda^{-1}\\exp(-\\lambda)$,\r\nresulting in a CRM called the Gamma process ($\\Gamma$P) \\citep{applebaum2004}. \r\nThe Gamma process has the convenient property that the \r\ntotal rate $\\Lambda \\equiv {\\Lambda}(\\Theta) = \\sum_{i=1}^{\\infty} \\lambda_i$ is Gamma distributed (and thus conjugate to the Poisson process prior on $\\mc{T}$).\r\n%\\footnote{We abuse notation by using $\\Lambda$ to denote both the measure as well as the total measure of $\\Theta}\r\n%The Gamma distribution has shape parameter $1$ and scale parameter $\\alpha$.  Since this is finite almost surely, so too is $\\mc{T}$. \r\nThe Gamma process is also closely connected with the Dirichlet process \\citep{Ferguson73}, which will prove useful\r\nlater on.\r\n% <<<<<<< HEAD\r\n% Other choices of the \\Levy intensity can be used to capture greater uncertainty in the number of neurons active in any finite interval, or to model\r\n% power-law behavior in the number of spikes emitted by different neurons.\r\n% % \r\n% =======\r\n%Other \\Levy measures can be used to capture greater uncertainty in the number of neurons active in any finite interval, or to model\r\n%power-law behavior in the number of spikes emitted by different neurons.\r\n% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433\r\n% To complete the specification on the Gamma process, we choose a base-measure $\\mathsf{H}(\\bth^*)$.\r\n% %Recalling that $\\bth^* \\equiv (\\mu^*, \\Sigma^*)$ gives the mean and variance of the weight-vector $\\by^*$ of a neuron, \r\n% We set $\\mathsf{H}(\\bth^*)$ \r\n% to the conjugate normal-Wishart distribution with parameters $\\phi$. \r\n% =======\r\nTo complete the specification on the Gamma process, %we choose a base-measure $\\mathsf{H}(\\bth^*)$.\r\n%Recalling that $\\bth^* \\equiv (\\mu^*, \\Sigma^*)$ gives the mean and variance of the weight-vector $\\by^*$ of a neuron, \r\nwe set $\\mathsf{H}_{\\phi}(\\bth^*)$ \r\nto the conjugate normal-Wishart distribution with hyperparameters $\\phi$.\r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\n%Our overall model is then:\r\n%\\begin{subequations}\r\n%\\begin{align}\r\n%  \\mc{T}_i\\ \\  &\\sim \\mathsf{PP}(\\lambda_i) \\quad i \\in \\NN, \\quad &\\text{ where } \\mathsf{\\Lambda}(\\cdot)&=\\sum_{i=1}^{\\infty} \\lambda_i \\delta_{\\theta^*_i} \\sim \\Gamma \\text{P}(\\alpha, \\mathsf{H}(\\cdot| {\\phi})), \\\\ %\\mathcal{NW}(\\mu, \\Sigma)) \\\\ \\\\\r\n%\\vspace{-.8in}\r\n%  x_i(t) &= \\sum_{j = 1}^{|\\mc{T}_i|}  \\sum_{k = 1}^{K} y^*_{ijk} \\mathsf{d}_k(t - \\tau_{ij}), \\quad &\\text{ where }\\by^*_{ij}  &\\sim \\mathsf{N}_K(\\mb{\\mu}^*_i, \\Sigma^*_i) \\quad i,j \\in \\NN, \\\\\r\n%  x(t)   &= \\sum_{i=1}^{\\infty} x_i(t) + \\eps_t, \\quad &\\text{ where at any time $t$, } \\eps_t &\\sim \\mathsf{N}(0,\\Sigma_x) \\text{ independently}\r\n%\\end{align}\r\n%\\end{subequations}\r\n\r\n%Each spike of each neuron is associated with a time $e$ and a weight vector $y$, and one can view the model above as a doubly stochastic Poisson\r\n%process on the product space. \r\n% \r\n%\\jovo{perhaps it is standard, but you sample $\\Lambda$ and then the next line you have $\\lambda_i$, but no explanation for how you from $\\Lambda$ to $\\lambda_i$. i also am confused as to why $\\phi$ is a subscript on $H$, rather than in the $(\\cdot)$}\r\n%Atom $i$ of the CRM corresponds to a neuron with parameters $(\\lambda_i, \\theta^*_i)$. \r\nIt is easy to directly specify the resulting continuous-time model, we provide the equations in the Supplementary Material. \r\nHowever it is more convenient to represent the model using the marked Poisson process of Eq.~\\eqref{eq:spk}. % and \\eqref{eq:spk_shape}. \r\nThere, the overall process $\\mc{T}$ is a rate $\\Lambda$ Poisson process,\r\nand under a Gamma process prior, $\\Lambda$ is Gamma$(\\alpha,1)$ distributed %with shape and scale parameters $\\alpha$ and $1$ respectively \r\n\\citep{Ferguson73}.\r\nThe labels $\\bth_i$ assigning events to neurons are drawn i.i.d. from a normalized Gamma \r\nprocess: % $\\mathsf{G}(\\dd \\bth)$:\r\n%\\vspace{-.2in}\r\n%\\begin{align}\r\n$ \\mathsf{G}(\\dd \\bth) = \\left(1/\\Lambda\\right) \\sum_{l=1}^{\\infty} \\lambda_l$.\r\n%\\end{align}\r\n\r\n$\\mathsf{G}(\\dd \\bth)$ is a random probability measure (RPM) called a \\emph{normalized random measure} \\citep{JamesLP09}. Crucially, a \r\nnormalized Gamma process is the Dirichlet process (DP) \\citep{Ferguson73}, so that \r\nthe spike parameters $\\bth$ are i.i.d.\\ draws with a DP-distributed RPM.\r\nFor spike $l$, the shape vector is drawn from a normal \r\nwith parameters $(\\mb{\\mu}_{l}, \\Sigma_{l})$: these are thus\r\ndraws from a DP mixture (DPM) of Gaussians \\citep{Lo1984}.\r\n\r\n% <<<<<<< HEAD\r\n% The connection with the DP allows us to simplify the representation of our model. In particular, we exploit a remarkable property of the DP that\r\n% allows us to integrate out the infinite-dimensional variable $\\mathsf{G}(\\cdot)$. The resulting marginal distribution over observations follows the so-called\r\n%  Chinese restaurant process ($\\mathsf{CRP}$) \\citep{Pit2002a}. Under this scheme, the $l^{th}$ spike is assigned the same parameter as an earlier spike with probability \r\n% =======\r\n%The connection with the DP allows us to simplify the representation of our model. In particular, \r\nWe can exploit the connection with the DP to %a remarkable property of the DP that allows us to \r\nintegrate out the infinite-dimensional measure $\\mathsf{G}(\\cdot)$ (and thus ${\\Lambda}(\\cdot)$), and assign spikes to neurons via \r\n%. The resulting marginal distribution over observations follows \r\nthe so-called Chinese restaurant process (CRP) \\citep{Pit2002a}. Under this scheme, the $l^{th}$ spike is assigned the same parameter as an earlier spike with probability \r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\nproportional to the number of earlier spikes having that parameter. It is assigned a new parameter (and thus, a new neuron is observed) with probability \r\nproportional to $\\alpha$. Letting $C_t$ be the number of neurons observed until time $t$, and  $\\mc{T}^t_i = \\mc{T}_i \\cap [0,t)$ be the times of spikes \r\nproduced by neuron $i$ before time $t$,\r\nwe then have for spike $l$ at time $t = \\tau_l$: \r\n\\vspace{-.07in}\r\n\\begin{align}\r\n% <<<<<<< HEAD\r\n%   \\mathsf{P}({\\nu_l} = i) & \\propto \r\n% =======\r\n \\bth_l = \\bth^*_{\\nu_l} \\text{, where } \r\n  P({\\nu_l} = i) & \\propto \r\n% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433\r\n  \\begin{cases}\r\n   |\\mc{T}^t_i| \\quad i \\in [C_{t}], \\\\\r\n   \\alpha \\quad\\ i = C_{t} + 1, \r\n  \\end{cases}  \r\n\\label{eq:crp_marg_pr}\r\n\\end{align}\r\n%\\footnote{Strictly speaking, the process we just described is called a P\\'olya urn scheme \\citep{BlaMac1973}; for simplicity, we do not distinguish between this and the \\mathsf{CRP}.}.\r\nThis marginalization property of the DP allows us to integrate out the infinite-dimensional rate vector ${\\Lambda}(\\cdot)$, and sequentially \r\nassign spikes to neurons based on the assignments of earlier spikes.\r\n%is assigned (or equivalently, the parameter $\\bth$ associated with that neuron). These marks are drawn from a probability measure \r\n%$\\mathsf{G}(\\dd \\bth) = \\frac{1}{R} R(\\dd \\bth)$. From the properties of the Gamma process, the probability measure $G$ a Dirichlet process, \r\nThis requires one last property: for the Gamma process, the RPM $\\mathsf{G}(\\cdot)$ is independent of the total mass $\\Lambda$. \r\nConsequently, the clustering of spikes (determined by $\\mathsf{G}(\\cdot)$) is independent of the rate $\\Lambda$ at which they are produced. We then have\r\n the following model:\r\n\\vspace{-.04in}\r\n\\begin{subequations}\r\n\\begin{align}\r\n  \\mc{T} &\\sim \\PP(\\Lambda), \\qquad &\\text{ where } \\Lambda  &\\sim \\mathsf{\\Gamma P}(\\alpha, 1),\r\n   \\\\\r\n  \\by_l &\\sim \\mathsf{N}_K(\\mb{\\mu}_{l}, \\Sigma_{l}), \\qquad &\\text{ where } (\\mb{\\mu}_{l}, \\Sigma_{l})  &\\sim {\\mathsf{CRP}}(\\alpha, \\mathsf{H}_{\\phi}(\\cdot)), \\quad  l \\in [|\\mc{T}|],   \\label{eq:CRP}\\\\\r\n   % (\\mb{\\mu}_{l}, \\Sigma_{l}) &\\equiv \\bth_l,  &\\text{ where } \\bth_l &\\sim \\text{\\mathsf{CRP}}(\\alpha, \\mathsf{H}_{\\phi}(\\cdot)), \\quad l \\in [|\\mc{T}|],   \\label{eq:\\mathsf{CRP}}\\\\\r\n  x(t) &=   \\textstyle{\\sum_{l \\in |\\mc{T}|}} \\sum_{k \\in [K]} y_{lk} \\mathsf{d}_k(t - \\tau_{l}) + \\eps_t  &\\text{ where }  \\eps &\\sim \\text{GP}(0,\\mathcal{K}).  \\label{eq:CRP_mix}  %\\,  l \\in [|\\mc{T}|]. \r\n\\end{align} \\label{eq:marked_pp}\r\n\\end{subequations}\r\n% Unlike most applications which observe the outputs of a $\\mathsf{CRP}$, our observation at any time $t$ is a convolution-like function of the $\\mathsf{CRP}$ outputs of all\r\n% earlier times. Consequently, we cannot directly apply standard techniques for posterior inference. In \\S \\ref{sec:inf}, we develop a novel online \r\n% algorithm for posterior inference; first, we provide a discrete-time approximation to our model.\r\n% =======\r\n%Unlike most applications which observe the outputs of a CRP, our observation at any time $t$ is a convolution-like function of the CRP outputs of all\r\n%earlier times. Consequently, we cannot directly apply standard techniques for posterior inference. In \\S \\ref{sec:inf}, we develop a novel online \r\n%algorithm for posterior inference; first, we provide a discrete-time approximation to our model.\r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\n\r\n%For neuron $i$, the sequence of spike times is distributed as a Poisson process with random rate $\\lambda_i$.\r\n%Each event $\\tau_{ij}$ is associated with a mark or label $y_{ij}$ drawn from a normal distribution (again, with random parameters).\r\n%More broadly, we can view the superposed process $\\mc{T}$ as a rate $\\Lambda$ Poisson process, with each event having a pair of marks, the neuron identity $i$,\r\n%and weight $y$. From the properties of the Gamma process, the pair form a draw from a Dirichlet process.\r\n%Our data is in a form that makes discrete-time modeling more natural, and an approach now is\r\n%one based on the Beta process-binomial process.\r\n\r\n%\\vspace{-.1in}\r\n% =======\r\n\\vspace{-.1in}\r\n% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f\r\n\\subsection{A discrete-time approximation}  \\label{sec:disc_time}\r\n% \\vspace{-.1in}\r\nThe previous subsections modeled the continuous-time voltage output of a neural population. Our data on the other hand consists of recordings\r\nat a discrete set of times. While it is possible to make inferences about the continuous-time process underlying these discrete recordings,\r\nin this paper, %for simplicity, \r\nwe restrict ourselves to the discrete case. %We thus provide a discrete-time approximation to the model above. \r\nThe marked Poisson process characterization of Eq.\\ \\ref{eq:marked_pp} leads to a simple\r\ndiscrete-time approximation of our model.\r\n\r\nRecall first the Bernoulli approximation to the Poisson process: a sample from a Poisson process with rate $\\Lambda$ can be approximated by discretizing\r\ntime at a granularity $\\Delta$, and assigning each bin an event independently with probability $\\Lambda\\Delta$ (the accuracy of the approximation increasing \r\nas $\\Delta$ tends to $0$).\r\n%\r\n%This suggests the following approximation at a time resolution $\\Delta$. Draw the random Poisson process rate $\\Lambda$ drawn from a Gamma$(1,\\alpha)$ \r\n%distribution. Simultaneously, draw a random probability measure\r\n% $G$ from a Dirichlet process. Assign an event to an interval independently with probability $\\Lambda\\Delta$, and to each event, assign a random mark drawn \r\nTo approximate the \\emph{marked} Poisson process $\\mc{T}$, all that is additionally required is to assign marks $\\bth_i$ and $\\by_i$ to each event \r\nin the Bernoulli approximation. Following Eqs.~\\eqref{eq:CRP} and \\eqref{eq:CRP_mix}, the $\\bth_l$'s are distributed according\r\nto a Chinese restaurant process, while each $\\by_l$ is drawn from a normal distribution parametrized by the corresponding $\\bth_l$. We discretize the \r\nelements of dictionary %$\\mathsf{d}_k \\equiv \\{\\mathsf{d}_k(t)\\}_{t \\in (0,T)}$ \r\nas well, %defining a mapping from $L_2$ to $\\Real^L$ \r\nyielding discrete dictionary elements \r\n$\\mt{\\bd}_{k,:}=(\\mt{d}_{k,1}, \\ldots, \\mt{d}_{k,L})\\T$. These form the rows of a ${K \\times L}$ matrix $\\mt{\\bD}$ (we call its columns\r\n$\\mt{\\bd}_{:,h}$). The shape of the $j^{th}$ spike is now a vector of length $L$, and for a weight vector\r\n$\\by$, is given by $\\mt{\\bD} \\by$.\r\n\r\nWe can simplify notation a little for the discrete-time model. \r\nLet $t$ index time-bins (so that for an observation interval of length \r\n$T$, $t \\in [T/\\Delta]$). We use twiddles for variables indexed by bin-position.\r\nThus, $\\mt{\\nu}_t$ and $\\mt{\\theta}_t$ are the neuron and neuron parameter associate with time bin $t$, and $\\mt{\\by}_t$ is its weight-vector. \r\nLet the binary variable $\\mt{z}_t$ indicate whether or not a spike in present in time bin $t$ (recall that \r\n$\\mt{z}_t \\sim \\text{Bernoulli}(\\Lambda \\Delta)$). \r\nIf there is no spike associated with bin $t$, then we ignore the marks $\\mt{\\mu}$ and $\\mt{\\by}$.\r\nThus the output at time $t$, $x_t$ is given by\r\n%\\begin{align}\r\n$\\ x_t = \\sum_{h = 1}^L \\mt{z}_{t-h} \\mathsf{\\bd}_{:,h}^{\\T} \\mt{\\by}_{t-h-1} + \\eps_t$. % \\text{,\\quad where $\\eps_t \\iid \\mathsf{N}(0,\\sigma^2)$.}$ \r\nNote that the noise $\\eps_t$ is now a discrete-time Markov Gaussian process. %In all experiments, we assume this evolves via a discrete-time first order\r\nLet $a$ and $r_t$ be the decay and innovation of the resulting autoregressive (AR) process, so that $\\eps_{t+1} = a \\eps_t + r_t$.\r\n%\\end{align}\r\n% \\vspace{-.1in}\r\n\\subsection{Correlations in time and across electrodes}  \\label{sec:multi}\r\n% \\vspace{-.1in}\r\nSo far, for simplicity, we restricted our model to recordings from a single channel. We now describe the full model we use in experiments with\r\nmultichannel recordings. We let every spike affect the recordings at all channels, with the spike shape varying across channels. \r\nFor spike $l$ in channel $m$, call the weight-vector $\\by^m_l$. All these vectors must be correlated as they correspond to the same spike; we do this \r\nsimply by concatenating the set of vectors into\r\na single $MK$-element vector $\\by_l = (\\by^1_l;\\cdots;\\by^M_l)$, and modeling this as a multivariate normal. In principle, one might expect the associated \r\ncovariance matrix to possess a block structure (corresponding to subvector associated with each channel); however, rather than building this into the model,\r\nwe allow the data to inform us about any such structure.\r\n\r\nWe also relax the requirement that the parameters $\\bth^*$ of each neuron remain constant, and instead allow $\\mb{\\mu}^*$, the mean of the weight-vector\r\ndistribution, to evolve with time (we keep the covariance parameter $\\mb{\\Sigma}^*_i$ fixed, however). \r\nSuch flexibility can capture effects like changing cell characteristics or moving electrodes.\r\nLike the noise term, we model the time-evolution of this quantity as a realization of a Markov Gaussian process; again, in \r\n%A consequence is that the \r\n%means remain marginally Gaussian distributed at any time, on the other hand correlation between means across time is determined by the choice \r\n%of the GP covariance kernel.\r\n%We choose a stationary Markov kernel (where covariance decays exponentially with time); in \r\ndiscrete-time, this corresponds to a simple first-order \r\nAR process. With $\\mb{B} \\in \\mathbb{R}^{K \\times K}$ the transition matrix, and $\\mb{r}_t \\in \\mathbb{R}^K$, \r\nindependent Gaussian {innovations}, we have\r\n  $\\mb{\\mu}^*_{t+1} = \\mathbf{B} \\mb{\\mu}^*_t + \\mathbf{r}_t$.\r\n%The first is the inclusion of measurement noise: {\\color{red} Biology?}. Let $\\eps_t$ be the noise at time $t$, we model this as independent, additive and Gaussian.\r\n%However, rather than modeling the noise as independent across time, we model it as a first-order autoregressive process. This can capture\r\n%effects like the movement of electrodes during the experiment. \r\n% \r\n% \\begin{align}\r\n% \\end{align}\r\nWhere we previously had a DP mixture of Gaussians, we now have a DP mixture of GPs. Each neuron is now associated with a vector-valued function \r\n$\\bth^*(\\cdot)$, rather than a constant. When a spike at time $\\tau_l$ is assigned to neuron $i$, it is assigned a weight-vector $\\by_l$ drawn from a \r\nGaussian with mean $\\mb{\\mu}^*_i(\\tau_l)$. %Following \\citep{wood2009}, a useful extension is to also allow the neuron assignment probabilities to evolve \r\n%(corresponding to a time-varying Gamma process \\citep{RaoTeh2009a}); we leave this for future work. \r\nAlgorithm \\ref{alg:gen_proc} in the Supplementary Material summarizes the full generative mechanism for the full discrete-time model.\r\n% <<<<<<< HEAD\r\n% Our second extension is to generalize our model from a single electrode to the case of multielectrode recordings. \r\n% We allow the shape of any spike to vary across channels: for spike $l$ in channel $m$, call the weight-vector $\\by^m_l$.\r\n% Of course, all these vectors need to be correlated as they correspond to the same spike. We do this simply by concatenating the set of vectors into\r\n% a single $MK$-element vector $\\by_l = (\\by^1_l;\\cdots;\\by^M_l)$, and modeling this as a multivariate normal. In principle, one might expect the associated \r\n% covariance matrix to possess a block structure (corresponding to subvector associated with each channel); however, rather than building this into the model,\r\n% we allow the data to inform us about any such structure.\r\n% Algorithm \\ref{alg:gen_proc} in the supplementary material outlines generative mechanism of the data for the discrete-time model.\r\n% \r\n% \\jovo{what's a semicolon in a sequence?}\r\n% =======\r\n% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433\r\n", "meta": {"hexsha": "f4e0b1bebf445af8da8dd35be723fd2553a747b8", "size": 31966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/model.tex", "max_stars_repo_name": "jovo/online-spike-sorting", "max_stars_repo_head_hexsha": "24b8bac41bff449381c5c60a9d09ac40995035b5", "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": "tex/model.tex", "max_issues_repo_name": "jovo/online-spike-sorting", "max_issues_repo_head_hexsha": "24b8bac41bff449381c5c60a9d09ac40995035b5", "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/model.tex", "max_forks_repo_name": "jovo/online-spike-sorting", "max_forks_repo_head_hexsha": "24b8bac41bff449381c5c60a9d09ac40995035b5", "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.3384223919, "max_line_length": 257, "alphanum_fraction": 0.7180441719, "num_tokens": 9054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6080607766533892}}
{"text": "\\chapter{{\\tt GPart}: Graph Partitioning Object}\n\\label{chapter:GPart:intro}\n\\par\nThe {\\tt GPart} object is used to create a partition of a graph.\nWe use an explicit vertex separator to split a graph (or a\nsubgraph) into the separator and two or more connected components.\nThis process proceeds recursively until the subgraphs are too small\nto split (given by some user-supplied parameter).\n\\par\nAt present, there is one path for splitting a graph (or a subgraph).\n\\begin{itemize}\n\\item\nFind a {\\it domain decomposition} of the graph.\nThe graph's vertices $V$ are partitioned into {\\it domains},\n$\\Omega_1, \\ldots, \\Omega_m$, each a connected component,\nand the interface vertices $\\Phi$.\nThe boundary of a domain $\\Omega_i$ (those vertices not in the domain \nbut adjacent to a vertex in the domain), written\n$\\mbox{adj}(\\Omega_i)$, are a subset of $\\Phi$, the interface\nvertices.\nWe use the term {\\it multisector} for $\\Phi$, for it generalizes\nthe notion of bisector.\n\\par\nWe currently find the domain decomposition by growing domains from\nrandom seed vertices.\nUpper and lower bounds are placed on the weights of the domains.\n\\item\nGiven a domain decomposition of the graph $\\langle \\Phi, \\Omega_1,\n\\ldots, \\Omega_m \\rangle$, we find a {\\it 2-set partition}\n$[S, B, W]$ of the vertices, where $S \\subseteq \\Phi$, \n$\\mbox{Adj}(B) \\subseteq S$ and $\\mbox{Adj}(W) \\subseteq S$.\nNote, it may be the case that $B$ and/or $W$ are not connected\ncomponents.\n\\par\nWe currently find a 2-set partition by forming a {\\it\ndomain-segment} bipartite graph where the segments partition the\ninterface nodes $\\Phi$.\nWe use a block Kernighan-Lin method to find an edge separator of\nthis domain-segment graph.\nSince the ``edges'' are segments, an edge separator of the\ndomain-segment graph is truly a vertex separator of the original\ngraph.\n\\item\nGiven a 2-set decomposition $[S,B,W]$ of the graph, we improve\nthe partition by {\\it smoothing} $S$.\nThe goal is to decrease the size of $S$, or improve the balance\nof the two sets (minimize $\\left| |B| - |W| \\right |$, or both.\nOur present approach is to generate a {\\it wide separator} $Y$\nwhere $S \\subseteq Y$ and try to find a separator \n$\\widehat S \\subseteq Y$ that induces a better partition\n$[{\\widehat S}, {\\widehat B}, {\\widehat W}]$.\n\\par\nTo do this, we form a network and solve a max flow problem.\nThe nodes in $B \\setminus Y$ are condensed into the {\\it source}\nwhile the nodes in $W \\setminus Y$ are condensed into the {\\it sink}.\nThe rest of the network is formed using the structure of the\nsubgraph induced by $Y$.\nGiven a {\\it min-cut} of the network we can identify a separator\n${\\widehat S} \\subseteq Y$ that has minimal weight.\nWe examine two (possibly) different min-cuts and evaluate the\npartitions induced via their minimal weight separators, and accept\na better partition if present.\n\\end{itemize}\nThis process we call {\\tt DDSEP}, which is short for {\\it {\\tt D}omain\n{\\tt D}ecomposition {\\tt SEP}arator},\nexplained in more detail in \n\\cite{ash97-DDSEP} and\n\\cite{ash98-maxflow}.\n\\par\n", "meta": {"hexsha": "cb0c4dc509e22c2a6fe88052e81f935f536042af", "size": 3041, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ccx_prool/SPOOLES.2.2/GPart/doc/intro.tex", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/SPOOLES.2.2/GPart/doc/intro.tex", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/SPOOLES.2.2/GPart/doc/intro.tex", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 43.4428571429, "max_line_length": 70, "alphanum_fraction": 0.7441631042, "num_tokens": 819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6080607615984749}}
{"text": "\\section{$k$-Nearest-Neighbors Algorithm}\n\\label{sec:TheoryKnn}\nThe $k$-Nearest-Neighbors ($k$-NN) algorithm performs a distribution free classification task. It uses a lazy learning approach which means that all the training data is saved. The Algorithm searches that data base for the $k$ closest data points to the point to classify. The distance measurement depends on the application. The class which is most often found in those $k$ nearest neighbors is the one the sample is classified as \\cite[p.~338~f.]{bib:Alzate2007}.\\\\\nThe space of the data points is the PCA-reduced feature space described in section~\\ref{sec:Features}. The distance used in our project is the DTW-distance described in section~\\ref{sec:Distance}. The feature space version of a test sample is calculated and compared to all other feature vectors in the database from section~\\ref{sec:Features}. This comparison table is then sorted by distance using the sorting algorithm built into Python. As output of the $k$-NN classification, the ratio of found neighbors to the total number of neighbors is given for the $k$ nearest neighbors. This can be interpreted as the probability of a point belonging to a class.\n", "meta": {"hexsha": "512b0bb530c516cb86d55ff883bb1f7ac866ac4d", "size": 1191, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/TheoryKnn.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/TheoryKnn.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/TheoryKnn.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": 238.2, "max_line_length": 658, "alphanum_fraction": 0.7951301427, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6080607537576695}}
{"text": "\\section{*Off-policy Methods with Approximation}\n\n\\subsection{Exercise 11.1}\n\\subsubsection*{Q}\nConvert the equation of $n$-step off-policy TD (7.9) to semi-gradient form. Give accompanying definitions of the return for both the episodic and continuing cases.\n\\subsubsection*{A}\nTabular case is \n\\[ \n    V_{t+n}(S_t) = V_{t+n-1} + \\alpha \\rho_{t:t+n-1} [G_{t:t+n} - V_{t+n-1}(S_t)].\n\\]\nThe semi-gradient weight update is\n\\[\n    \\vec{w}_{t+n} = \\vec{w}_{t+n-1} + \\alpha \\rho_{t:t+n-1}[G_{t:t+n} - \\hat{v}(S_t, \\vec{w}_{t+n-1})] \\grad_{\\vec{w}}\\hat{v}(S_t, \\vec{w}_{t+n-1}),\n\\]\nnoting the occurrence of the $n$step TD Error\n\\[\n    \\delta_t^n = G_{t:t+n} - \\hat{v}(S_t, \\vec{w}_{t+n-1}).\n\\]\nWe define the returns in the two cases\n\\begin{description}\n    \\item[episodic] $G_{t:t+n} = \\sum_{i=t}^{t+n-1}\\gamma_{i-t}R_{i+1} + \\gamma^n \\hat{v}(S_{t+n}, \\vec{w}_{t+n-1})$\n    \\item[continuing] $G_{t:t+n} = \\sum_{i=t}^{t+n-1}(R_{i+1} - \\bar{R}_i) + \\hat{v}(S_{t+n}, \\vec{w}_{t+n-1})$\n\\end{description}\nwhere in each case $G_{t:h} = G_t$ if $h \\geq T$.\n    \n\n\\subsection{*Exercise 11.2}\n\\subsubsection*{Q}\nConvert the equations of $n$-step Q$(\\sigma)$ (7.11 and 7.17) to semi-gradient form. Give definitions that cover both the episodic and continuing cases.\n\n\\subsubsection*{A}\nThe update is \n\\[\n    \\vec{w}_{t+n} = \\vec{w}_{t+n-1} + \\alpha [G_{t:t+n} - \\hat{q}(S_t, A_t, \\vec{w}_{t+n-1})] \\grad_{\\vec{w}} \\hat{q}(S_t, A_t, \\vec{w}_{t+n-1}\n\\]\nwith the following definitions of returns targets\\\\\n\n{\\bfseries Episodic}\\\\\n\\[\n    G_{t:h} = 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:h} - \\hat{q}(S_t, A_t, \\vec{w}_{h-1}) \\right] + \\gamma \\bar{V}_{h-1}(S_{t+1})\n\\]\\\\\n\n{\\bfseries Continuing}\\\\\n\\[\n    G_{t:h} = R_{t+1} - \\bar{R}_t + \\left[\\sigma_{t+1}\\rho_{t+1}  + (1-\\sigma_{t+1})\\pi(A_{t+1} \\vert{} S_{t+1})\\right]\\left[G_{t:h} - \\hat{q}(S_t, A_t, \\vec{w}_{h-1}) \\right] + \\bar{V}_{h-1}(S_{t+1})\n\\]\\\\\n\nwhere \n\\[\n    \\bar{V}_i(s) = \\sum_a \\pi(a \\vert{} s) \\hat{q}(s, \\vec{w}_i)\n\\]\nand $G_{h:h} = \\hat{q}_(S_h, A_h, \\vec{w}_{h-1})$ if $h<T$ while if $h=T$ we have $G_{T-1:T} = R_T$ in the episodic case and $G_{T-1:T} = R_T - \\bar{R}_{T-1}$ in the continuing case.\\\\\n\nNote that in each case the value functions are defined with respect to the relevant episodic discounted or continuing average excess return.\n\n\\subsection{Exercise 11.3 (programming)}\n\\subsubsection*{Q}\nApply one-step semi-gradient Q-learning to Baird’s counterexample and show empirically that its weights diverge.\n\n\\subsubsection*{A}\n\\ProgrammingExercise{}\\\\\n\n\\includegraphics[width=\\textwidth]{\\ExerciseOutput/ex_11_3/bairds_counter_example_q_learning.png}\n\n\\subsection{Exercise 11.4}\n\\subsubsection*{Q}\nProve (11.24). Hint: Write the $\\bar{\\mathrm{RE}}$ as an expectation over possible states s of the expectation of the squared error given that $S_t = s$. Then add and subtract the true value of state $s$ from the error (before squaring), grouping the subtracted true value with the return and the added true value with the estimated value. Then, if you expand the square, the most complex term will end up being zero, leaving you with (11.24).\n\n\\subsubsection*{A}\nDefine\n\\[\n    \\overline{\\mathrm{VE}}(\\vec{w}) = \\E{}_{s\\sim\\mu}[v_\\pi(s) - \\hat{v}(s, \\vec{w})]\n\\]\nNow have the return error\n\\begin{align}\n    \\overline{\\mathrm{RE}} &\\doteq \\E{}\\left[ (G_t - \\hat{v}(S_t, \\vec{w}))^2 \\right] \\\\\n    &= \\overline{\\mathrm{VE}}(\\vec{w}) + \\E{}\\left[ (G_t - v_\\pi(S_t))^2 \\right] + 2 \\E{}\\left[ (G_t - v_\\pi(S_t))[v_\\pi(S_t) - \\hat{v}(S_t, \\vec{w})] \\right].\n\\end{align}\nThe final term is\n\\begin{align}\n    \\E{}\\left[ (G_t - v_\\pi(S_t))[v_\\pi(S_t) - \\hat{v}(S_t, \\vec{w})] \\right] &= \\E{}_{s \\sim \\mu}\\left\\{\\E{}\\left[ (G_t - v_\\pi(s))[v_\\pi(s) - \\hat{v}(s, \\vec{w})] \\right]\\vert{} s\\right\\}\\\\\n                  &= 0\n\\end{align}", "meta": {"hexsha": "ba1dd583dac05af11a2727a76171548b56f68faa", "size": 3850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/chapters/chapter11/chapter11_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/chapter11/chapter11_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/chapter11/chapter11_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": 46.3855421687, "max_line_length": 443, "alphanum_fraction": 0.6264935065, "num_tokens": 1516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696748, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6079812532622589}}
{"text": "%!TEX root = ../notes.tex\n\\section{April 6, 2022}\n\\subsection{Lattices and Cryptography}\nThe advantage of lattice based cryptography is that they are quantum resistant.\n\nWe'll use a \\emph{toy example} as a warm-up\\footnote{This isn't even secure classically.}.\n\\begin{example}\n    Suppose we have some $q$ that is public knowledge (any integer).\n\n    Alice will choose reasonably small numbers $f, g$\n    \\begin{align*}\n        0                  & < f < \\sqrt{\\frac{q}{2}} \\\\\n        \\sqrt{\\frac{q}{4}} & < g < \\sqrt{\\frac{q}{2}}\n    \\end{align*}\n    which will constitute her private keys. She'll compute $h = f^{-1}\\cdot g\\pmod{q}$ which will be her public key. We'll assume that $f, g, q$ are all pairwise relatively prime.\n\n    Bob, encrypting message $m$, satisfying $0 < m < \\sqrt{\\frac{q}{4}}$:\n    \\begin{enumerate}\n        \\item Choose random $r$ with $0 < r < \\sqrt{\\frac{q}{2}}$.\n        \\item Compute ciphertext $c = r\\cdot h + m\\pmod{q}$ to send to Alice.\n    \\end{enumerate}\n\n    Alice, to decrypt the message, will do the following:\n    \\begin{enumerate}\n        \\item Calculate $a \\equiv f\\cdot c\\pmod{q}$.\n        \\item Calculate $b \\equiv f^{-1}a\\pmod{g}$.\n    \\end{enumerate}\n    Why does this work?\n    \\begin{align*}\n        a \\equiv f\\cdot c \\equiv f(r\\cdot h + m) & \\equiv f(r\\cdot f^{-1}\\cdot g + m) \\\\\n                                                 & \\equiv r\\cdot g + f\\cdot m\n    \\end{align*}\n    and we rely on the fact that $r\\cdot g + f\\cdot m < q$ since\n    \\[0 < rg + fm < \\sqrt{\\frac{q}{2}}\\sqrt{\\frac{q}{2}} + \\sqrt{\\frac{q}{2}}\\sqrt{\\frac{q}{4}} \\leq q\\]\n    Thus $a\\equiv rg + fm$ (exactly!). Then $b\\equiv f^{-1}a\\equiv f^{-1}(rg + fm)\\pmod{g}\\equiv m\\pmod{g}$. $m < \\sqrt{\\frac{q}{4}} < g$ thus $b = m$ exactly.\n\\end{example}\n\nWe can implement this in code (again):\n\\begin{lstlisting}\nfrom gcd import *\n\nq = 320984712309487123509238471251\n\nwhile True:\n    f = randrange(int(sqrt(q/2)))\n    g = randrange(int(sqrt(q/4))+ 1, int(sqrt(q/2)))\n    if gcd(f, g) == 1 and gcd(f, q) == 1:\n        break\n\nh = (ext_gcd(f, q)[0] * g) % q\n\ndef e(m):\n    r = randrange(sqrt(q/2))\n    c = (r * h + m) % q\n    return c\n\ndef d(c):\n    a = (f * c) % q\n    b = (ext_gcd(f, g)[0] * a) % g\n    return b\n\\end{lstlisting}\n\n\\begin{ques*}\n    What does Eve need to do?\n\\end{ques*}\nEve knows $q, h$ and wants to figure out $f, g$ with $f\\cdot h\\equiv g\\pmod{q}$ and $f, g$ small ($\\mathcal{O}(\\sqrt{q})$).\n\nWe write this as a vector equation:\n\\begin{align*}\n    f\\cdot\n    \\begin{pmatrix}\n        1 \\\\ h\n    \\end{pmatrix} - r\\cdot\n    \\underbrace{\\begin{pmatrix}\n                        0 \\\\ q\n                    \\end{pmatrix}}_{V_1} =\n    \\underbrace{\\begin{pmatrix}\n                        f \\\\ g\n                    \\end{pmatrix}}_{V_2}\n\\end{align*}\nwhere $f, r$ are unknown integers and $\\begin{pmatrix}\n        f \\\\ g\n    \\end{pmatrix}$ is an unknown vector. The known vectors are on the left.\n\nOur goal is to find a \\ul{short vector} in\n\\[\\left\\{ a_1v_a + a_2v_2\\mid a_1, a_2\\in\\ZZ \\right\\}\\]\n\n\\begin{definition}[Lattice]\n    Let $v_1, v_2, \\dots, v_n \\in \\RR^m$ be linearly independent vectors vectors (so $n\\leq m$).\n\n    The \\ul{lattice} generated by $v_1, \\dots, v_n$ is:\n    \\[\\left\\{ a_1v_1 + \\cdots + a_nv_n : a_1, \\dots, a_n\\in\\ZZ \\right\\}\\]\n\\end{definition}\n\n\\begin{remark}\n    There is a fast algorithm to find \\emph{short vectors} in a 2D lattice (which is the one above). Then, Eve can use this to break the above cryptosystem. \\emph{(We will see this later.)}\n\\end{remark}\n\n\\subsection{Subset Sum Cryptosystem}\nThe subset sum problem is as follows: Given $M_1, M_2, \\dots, M_n\\in\\ZZ$: find a subset whose sum is $S$.\n\n\\begin{example}\n    We take $M = \\{2, 3, 5, 8\\}$ and $S = 10$. $S = 2 + 8 = 2 + 3 + 5$. (We note that the subset is not necessarily unique).\n\\end{example}\n\nThe idea is as follows:\n\nAlice chooses $M_1, M_2, \\dots, M_n$. Bob has a message $x_1, x_2, \\dots, x_n$ where each $x_i \\in \\{0, 1\\}$. Bob computes $\\sum x_i M_i$ (that is, Bob's message specifies a subset of $M_i$'s) and sends to Alice.\n\nAlice has to recover which subset Bob sent her. Alice needs to have chosen $M_1, \\dots, M_n$ so that a) the solution to subset-sum is unique, b) it has some secret structure to solve subset sum\\dots\n\n\\emph{Continued next time. }", "meta": {"hexsha": "0c5cb93f1fe89d959074311bd90ba73952868b14", "size": 4277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-04-06.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-04-06.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-04-06.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": 38.1875, "max_line_length": 212, "alphanum_fraction": 0.6006546645, "num_tokens": 1474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6079812373032034}}
{"text": "\\subsection{Two-dimensional ring dataset }\n\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{experiment-2D-torus.pdf}\n  \\vspace{2mm}\n  \\centering\n  \\includegraphics[width=.975\\columnwidth]{figures/colormap.pdf}\n  %\n  \\caption{%\n  %\n  {\\bfseries \\sffamily Two dimensional ring dataset (results)}\n  %\n  Randomized SOM made of $1024$ neurons with a $3$-nearest neighbors induced topology. Model has been trained for $25,000$ epochs on two-dimensional points drawn from a ring distribution on the unit square. \\textbf{A} Map topology in neural space. \\textbf{B} Map topology in data space. \\textbf{C to H} Normalized distance map for six samples. Normalization has been performed for each sample in order to enhance contrast but this prevents comparison between maps.\n  %\n  }\n  \\label{fig:2D-ring:results}\n\\end{figure}\n\n\n% A one-dimensional problem as the one in the previous paragraph does not reveal a lot of information with respec to the organization of the map. Therefore, we proceed with investigating how a two-dimensional map learns two-dimensional representations. First, we train the SOM algorithms (both the Kohonen and VSOM) on $25000$ two-dimensional points drawn from a uniform distribution of an annulus in $[0, 1]\\times[0, 1$]. More precisely, $x_1 = \\frac{1 + r \\cos(k)}{2}$ and $x_2 = \\frac{1 + r\\sin(k)}{2}$, where $k \\sim \\mathcal{U}(0, 2\\pi)$ and $r \\sim \\sqrt{\\mathcal{U}(\\frac{1}{4}, 1)}$. After placing the neurons on the appropriate positions on neural space with respect to the topology provided by a blue noise distribution (only for the VSOM algorithm), we train the maps for $25000$ epochs. Both Kohonen and VSOM algorithms use $1024$ neurons. The results after convergence are shown in Figure~\\ref{fig:annulus}, where the map topology of the annulus is shown in Figure~\\ref{fig:annulus}{\\bfseries \\sffamily A}. The mapping produced by the VSOM learning algorithm is shown in Figure~\\ref{fig:annulus}{\\bfseries \\sffamily B} trained on the annulus data set. As we observe the map covers the input space with higher density within the annulus, where the input data points lie, and a lower density within the hole of annulus. Panels~\\ref{fig:annulus}{\\bfseries \\sffamily C}-{\\bfseries \\sffamily H} display the responses of six neurons (see the red annotated points in panel~\\ref{fig:annulus}{\\bfseries \\sffamily B}) to a stimulus derived from  the discretization of $[0, 1]\\times [0, 1]$. The responses of these neurons are well organized and reflect their receptive fields. \n\n% The distribution of eigenvalues for the two maps (black and blue colors correspond to VSOM and Kohonen maps, respectively) for the current experiment are shown in Figure~\\ref{Fig:distributions}{\\bfseries \\sffamily A}. We observe that there is no significant difference between the two distributions and thus the two algorithms perform equally (see Section~\\ref{sec:gram} for more details about how we obtain the distributions). Also the Wasserstein distance indicates that the two distributions are almost identical. \n\n% Finally, the persistence barcodes and diagrams in Figure~\\ref{Fig:persistence_exp2} indicate that the Kohonen map (middle column in the figure) does not capture so well the $H1$ topological features of the input (first column in the figure),  although it captures the $H1$ properties. This is related to the fact that the  Kohonen map covers with more neurons the hole of the annulus which is not  the case with the VSOM. VSOM retains better than Kohonen the $H1$ topological features and this is reflected in the barcode and diagram (last column) where the blue dots resemble the cluster of blue dots of input's diagram (first column). This indicates that VSOM uses less neurons to cover the hole of the annulus, which can be confirmed by visually inspecting Figure~\\ref{fig:annulus}{\\bfseries \\sffamily B}. The same phenomenon is present in the persistent barcodes where the blue segments appear in input's and VSOM's barcodes but not as strongly as in Kohonen's. \n", "meta": {"hexsha": "6ccfe4b37d7b0d49dab971d98ce08f76fdac969f", "size": 3994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/05-appendix-C.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-C.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-C.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": 159.76, "max_line_length": 1680, "alphanum_fraction": 0.7751627441, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.607981228935016}}
{"text": "We carry around three different 1D radial quantities: $\\etarhoec$\n(edge-centered), $\\etarhocc$ (cell-centered), and $\\divetarho$\n(cell-centered).  These notes discuss when each of these is used, and\nhow they are computed, in both plane-parallel and spherical.\n\n\\section{The Mixing Term, $\\etarho$}\n\nThe base state evolves in response to heating and mixing in the star.\nThe density evolution is governed by\n\\begin{eqnarray}\n\\frac{\\partial \\rho_0}{\\partial t} &=& - \n \\nablab \\cdotb \\left( \\rho_0 w_0 \\er \\right)\n- \\nablab \\cdotb \\left( \\etarho \\er \\right) \\enskip ,\n\\label{eq:rho0upd_new}\n\\end{eqnarray}\nwith\n\\begin{equation}\n\\etarho(r) = \\overline{\\left(\\rhop \\Ubt \\cdot \\er \\right)} = \\frac{1}{A(\\Omega_H)} \n \\int_{\\Omega_H}  (\\rhop \\Ubt \\cdot \\er ) \\; dA \\enskip , \\label{eq:eta}\n\\end{equation}\ndesigned to keep the average value of the full density, $\\rho$, over a\nlayer of constant radius in the star equal to $\\rho_0$.  To complete\nthe update of the base state, we need evolution equations for the\npressure, $p_0$, and velocity, $w_0$.  For spherical geometry, the\nderivation of $w_0$ constraint equation is shown in\nthe multilevel paper, resulting in the following system\n\\begin{eqnarray}\nw_0 &=& \\ow + \\delta w_0 \\\\\n\\frac{1}{r^2} \\frac{\\partial}{\\partial r} \\left (r^2 \\ow \\right ) &=& \\Sbar \\\\\n\\frac{\\partial}{\\partial r} \\left[ \\frac{\\gammabar p_0}{r^2} \\frac{\\partial}{\\partial r} (r^2 \\dw) \\right] &=& - \\frac{g}{r^2} \\frac{\\partial (r^2 \\etarho)}{\\partial r} - \\frac{4 (\\ow + \\dw) \\rho_0 g}{r} \n- 4 \\pi G \\rho_0 \\etarho \\label{eq:dw0constraint}\n\\end{eqnarray}\n\nIn paper~III, we introduced a mixing term, $\\etarho$, to the density\nevolution equation (eq.~[\\ref{eq:rho0upd_new}]), with the objective of\nkeeping the base state density equal to the average of the density\nover a layer.  For a spherical base state, it is best to define the \naverage in terms of spherical coordinates,\n\\begin{equation}\n\\overline{q} = \\frac{1}{4\\pi} \\int_{\\Omega_H} q(r,\\theta,\\phi) \\; d\\Omega\n\\end{equation}\nwhere $\\int_{\\Omega_H} d\\Omega = 4\\pi$ represents the integral over\nthe spherical $\\theta$ and $\\phi$ angles at constant radius.\n\nRecall from Paper III that if initially $\\overline{\\rho'} = 0$,\nthere is no guarantee that $\\overline{\\rho'} = 0$ will hold at later\ntime.  To see this, recall equation (\\ref{eq:Perturbational Density}),\nwritten in a slightly different form:\n\\begin{equation}\n\\frac{\\partial\\rho'}{\\partial t} + \\nabla\\cdot\\left(\\rho'\\Ub\\right) = -\\nabla\\cdot\\left(\\rho_0\\Ubt\\right).\n\\end{equation}\nWe integrate this over a spherical shell of thickness $2h$ at radius $r_0$, i.e.,\n$\\Omega_H \\times (r_0-h, r_0+h)$, and normalize by the integration\nvolume, which is $\\sim 4\\pi r_0^2  2h$ for small $h$, to obtain:\n\\begin{eqnarray}\n\\frac{1}{4\\pi r_0^2 2h}\\int_{r_0-h}^{r_0+h}r^2 dr\\int_{\\Omega_H}\\left[\\frac{\\partial\\rho'}{\\partial t} + \\nabla\\cdot\\left(\\rho'\\Ub\\right)\\right]d\\Omega \n&=& - \\frac{1}{4\\pi r_0^2 2h}\\int_{r_0-h}^{r_0+h}r^2 dr\\int_{\\Omega_H}\\nabla\\cdot\\left(\\rho_0\\Ubt\\right)d\\Omega \\nonumber \\\\\n&=& \\left. -\\frac{1}{4\\pi r_0^2 2h}\\int_{\\Omega_H}\\left[\\rho_0\\left(\\Ubt\\cdot\\eb_r\\right)\\right]r^2 d\\Omega\\right|_{r_0-h}^{r_0+h} \\nonumber \\\\\n&=& 0,\n\\end{eqnarray} \nwhere we have used the divergence theorem in spherical coordinates to transform\nthe volume integral on the right hand side into an area integral over $\\Omega_H$.  \nWe see that the right hand side disappears since \n$\\int_{\\Omega_H}\\rho_0(\\Ubt\\cdot\\eb_r)d\\Omega=0$,  which follows from the definition \nof $\\Ubt$.  Now, expanding the remaining terms and taking the limit as \n$h\\rightarrow 0,$ we can write\n\\begin{eqnarray} \n0 &=& \\lim_{h\\rightarrow 0} \\frac{1}{4\\pi r_0^2 2h} \\int_{r_0-h}^{r_0+h} r^2  dr \\int_{\\Omega_H} \\left[\\frac{\\partial \\rho'}{\\partial t} + \\nabla\\cdot(\\rho'\\Ub)\\right] d\\Omega \\nonumber \\\\\n&=& \\frac{\\partial}{\\partial t} \\left( \\lim_{h\\rightarrow 0} \\frac{1}{4\\pi r_0^2} \\frac{1}{2h} \\int_{r_0-h}^{r_0+h} r^2  dr \\int_{\\Omega_H}  \\rho' d\\Omega \\right) + \\lim_{h\\rightarrow 0} \\left[\\frac{1}{4\\pi r_0^2  2h} \\int_{r_0-h}^{r_0+h} r^2  dr \\int_{\\Omega_H}  \\nabla \\cdot ( \\rho' \\Ub )  d\\Omega\\right] \\nonumber \\\\\n&=& \\frac{\\partial}{\\partial t} \\left(\\frac{1}{4\\pi} \\int_{\\Omega_H}  \\rho'  d\\Omega \\right) + \\lim_{h\\rightarrow 0} \\left\\{\\left.\\frac{1}{r_0^2 2h}\\left[\\frac{1}{4\\pi}\\int_{\\Omega_H} \\rho' (\\Ub \\cdot \\eb_r)  d\\Omega  \\right]  r^2 \\right |_{r_0-h}^{r_0+h} \\right\\} \\nonumber  \\\\\n&=&  \\frac{\\partial}{\\partial t} \\overline{\\rho'} + \\lim_{h\\rightarrow 0} \\left\\{ \\left .  \\frac{1}{r_0^2  2h} \\left[ \\overline{\\rho' (\\Ub \\cdot \\eb_r)} \\right]  r^2  \\right |_{r_0-h}^{r_0+h} \\right\\} \\nonumber  \\\\\n&=&  \\frac{\\partial}{\\partial t} \\overline{\\rho'} + \\lim_{h\\rightarrow 0} \\frac{1}{r_0^2 2h} \\int_{r_0-h}^{r_0+h} \\nabla \\cdot \\left[\\overline{\\rho' (\\Ub \\cdot \\eb_r)} \\eb_r \\right]  r^2  dr \\nonumber \\\\\n&=&  \\frac{\\partial}{\\partial t} \\overline{\\rho'} + \\nabla \\cdot \\left[ \\overline{\\rho' (\\Ub \\cdot \\eb_r)} \\eb_r \\right]\n\\end{eqnarray} \nagain using the divergence theorem, extracting the time derivative from the spatial integral,\nand switching the order of operations as appropriate.\n\nIn short, \n\\begin{equation}\n\\frac{\\partial}{\\partial t} \\overline{\\rho'} = - \\nabla\\cdot\\left[\\overline{\\rho'\\left(\\Ub\\cdot\\eb_r\\right)}\\eb_r\\right] = -\\nabla\\cdot\\left(\\etarho\\eb_r\\right), \\label{eq:rhopbar}\n\\end{equation} \nand thus, $\\etarho = \\overline{\\left(\\rho'\\Ub\\cdot\\eb_r\\right)}$.\n\nWe need both $\\etarho$ alone and its divergence for the\nvarious terms in the construction of $w_0$ and the correction to\n$\\rho_0$.  The quantity $\\etarho$ is edge-centered on our grid, and\nfor Cartesian geometries, we constructed it by averaging the\nappropriate fluxes through the grid boundaries.  For a spherical base\nstate, this does not work, since the spherical shells do not line up\nwith the Cartesian grid boundaries.\n\nTherefore, we take a different approach.  We compute $\\etarho$ by\nconstructing the quantity $\\rhop \\Ubt \\cdot \\er$ in each cell, and then\nuse our average routine to construct a 1-d, cell-centered\n$\\eta_{\\rho,r}$ (this is essentially numerically solving the integral\nin Eq.~[\\ref{eq:eta}]).  The edge-centered values of $\\etarho$,\n$\\eta_{\\rho,r+1/2}$ are then constructed by simple\naveraging: \\MarginPar{should we be doing a volume-weighted average?}\n\\begin{equation}\n\\eta_{\\rho,r+1/2} = \\frac{\\eta_{\\rho,r} + \\eta_{\\rho,r+1}}{2} \\enskip .\n\\end{equation}\n\nInstead of differencing $\\eta_{\\rho,r+1/2}$ to construct the \ndivergence, we instead use equation~(\\ref{eq:rhopbar}) directly, by writing:\n\\begin{equation}\n\\left [ \\nabla \\cdot (\\etarho \\er ) \\right ]^{n+1/2}\n= - \\frac{\\overline{\\rhop^{n+1}} - \\overline{\\rhop^n}}{\\Delta t}\n= - \\frac{\\overline{\\rhop^{n+1}}}{\\Delta t} \\enskip ,\n\\end{equation}\nwhere we have made use of the fact that $\\overline{\\rhop^n} = 0$ by construction.\n\n\n%-----------------------------------------------------------------------------\n% flow chart\n%-----------------------------------------------------------------------------\n\\section{$\\eta$ Flow Chart}\n\\begin{enumerate}\n\\item Enter {\\tt advance\\_timestep} with $[\\etarhoec, \\etarhocc]^{n-\\myhalf}$.\n\\item Call {\\tt make\\_w0}.  The spherical version uses uses $\\etarho^{{\\rm ec},n-\\myhalf}$ and $\\etarho^{{\\rm cc},n-\\myhalf}$.\n\\item Call {\\tt density\\_advance}.  The plane-parallel version computes $\\etarho^{{\\rm flux},n+\\myhalf,*}$.\n\\item Call {\\tt make\\_etarho} to compute $[\\etarhoec, \\etarhocc]^{n+\\myhalf,*}$.  The plane-parallel version uses $\\etarho^{{\\rm flux},n+\\myhalf,*}$.\n\\item Call {\\tt make\\_psi}.  The plane-parallel version uses $\\etarho^{{\\rm cc},n+\\myhalf,*}$.\n\\item Call {\\tt make\\_w0}.  The spherical version uses uses $\\etarho^{{\\rm ec},n+\\myhalf,*}$ and $\\etarho^{{\\rm cc},n+\\myhalf,*}$.\n\\item Call {\\tt density\\_advance}.  The plane-parallel version computes $\\etarho^{{\\rm flux},n+\\myhalf}$.\n\\item Call {\\tt make\\_etarho} to compute $[\\etarhoec, \\etarhocc]^{n+\\myhalf}$.  The plane-parallel version uses $\\etarho^{{\\rm flux},n+\\myhalf}$.\n\\item Call {\\tt make\\_psi}.  The plane-parallel version uses $\\etarho^{{\\rm cc},n+\\myhalf}$.\n\\end{enumerate}\n\n%-----------------------------------------------------------------------------\n% computing\n%-----------------------------------------------------------------------------\n\\section{Computing $\\etarhoec$ and $\\etarhocc$}\nThis is done in {\\tt make\\_eta.f90}.\n\n\\subsection{Plane-Parallel}\nWe first compute a radial edge-centered multifab, $\\etarho^{\\rm flux}$, using\n\\begin{equation}\n\\eta_{\\rho,\\ib+\\myhalf\\eb_r}^{\\rm flux} = \\left[\\left(\\Ubt_{\\ib+\\myhalf\\eb_r}^{n+\\myhalf}\\cdot\\eb_r\\right) + w_{0,r+\\myhalf}^{n+\\myhalf}\\right] \\rho_{\\ib+\\myhalf\\eb_r}^{n+\\myhalf} - w_{0,r+\\myhalf}^{n+\\myhalf}\\rho_{0,r+\\myhalf}^{n+\\myhalf, {\\rm pred}}\n\\end{equation}\n$\\etarhoec$ is the edge-centered ``average'' value of $\\eta_{\\rho}^{\\rm flux}$,\n\\begin{equation}\n\\eta_{\\rho,r+\\myhalf}^{\\rm ec} = \\overline{\\eta_{\\rho,\\ib+\\myhalf\\eb_r}^{\\rm flux}}\n\\end{equation}\n$\\etarhocc$ is a cell-centered average of $\\etarhoec$,\n\\begin{equation}\n\\eta_{\\rho,r}^{\\rm cc} = \\frac{\\eta_{\\rho,r+\\myhalf}^{\\rm ec} + \\eta_{\\rho,r-\\myhalf}^{\\rm ec}}{2}.\n\\end{equation}\n\n\\subsection{Spherical}\\label{Sec:eta Spherical}\nFirst, construct $\\eta_{\\rho}^{\\rm cart} =\n[\\rho'(\\Ubt\\cdot\\eb_r)]^{n+\\myhalf}$ using:\n\\begin{equation}\n\\left[\\frac{\\rho^n+\\rho^{n+1}}{2}-\\left(\\frac{\\rho_0^n+\\rho_0^{n+1}}{2}\\right)^{\\rm cart}\\right] \\sum_d\\left(\\frac{\\Ubt_{\\ib+\\myhalf\\eb_d}^{n+\\myhalf}\\cdot\\eb_d+\\Ubt_{\\ib-\\myhalf\\eb_d}^{n+\\myhalf}\\cdot\\eb_d}{2}\\right)n_d.\n\\end{equation}\nThen, $\\etarhocc$ is the cell-centered average of $\\eta_{\\rho}^{\\rm cart}$,\n\\begin{equation}\n\\etarhocc = \\overline{\\eta_{\\rho}^{\\rm cart}}.\n\\end{equation}\nOn interior faces, $\\etarhoec$ is the average of $\\etarhocc$,\n\\begin{equation}\n\\eta_{\\rho,r-\\myhalf}^{\\rm ec} = \\frac{\\eta_{\\rho,r-1}^{\\rm cc} + \\eta_{\\rho,r}^{\\rm cc}}{2}.\n\\end{equation}\nAt the upper and lower boundaries, we use\n\\begin{eqnarray}\n\\eta_{\\rho,-\\myhalf}^{\\rm ec} &=& 0, \\\\\n\\eta_{\\rho,{\\rm nr}-\\myhalf}^{\\rm ec} &=& \\eta_{\\rho,{\\rm nr}-1}^{\\rm cc}.\n\\end{eqnarray}\n\n%-----------------------------------------------------------------------------\n% etarho_ec\n%-----------------------------------------------------------------------------\n\\section{Using $\\etarhoec$}\n\\subsection{Plane-Parallel}\nNOT USED.\n\n\\subsection{Spherical}\nIn {\\tt make\\_w0}, $\\etarhoec$ is used in the construction of the RHS\nfor the $\\delta w_0$ equation.\n\n%-----------------------------------------------------------------------------\n% etarho_cc\n%-----------------------------------------------------------------------------\n\\section{Using $\\etarhocc$}\n\\subsection{Plane-Parallel}\nIn {\\tt make\\_psi}, $\\psi = \\etarhocc g$.\n\n\\subsection{Spherical}\nIn {\\tt make\\_w0}, $\\etarhocc$ is used in the construction of the RHS\nfor the $\\delta w_0$ equation.\n\n", "meta": {"hexsha": "8bbfcfdb68e4a4482a4b14ddde445c7c27631b94", "size": 10776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Docs/eta_notes/eta.tex", "max_stars_repo_name": "sailoridy/MAESTRO", "max_stars_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-05-15T15:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-09T08:13:32.000Z", "max_issues_repo_path": "Docs/eta_notes/eta.tex", "max_issues_repo_name": "sailoridy/MAESTRO", "max_issues_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2017-06-14T23:05:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-28T16:40:42.000Z", "max_forks_repo_path": "Docs/eta_notes/eta.tex", "max_forks_repo_name": "sailoridy/MAESTRO", "max_forks_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2017-06-14T14:52:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-04T07:16:09.000Z", "avg_line_length": 56.4188481675, "max_line_length": 319, "alphanum_fraction": 0.6416109874, "num_tokens": 3779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.661922862511608, "lm_q1q2_score": 0.6079630752396401}}
{"text": "\\chapter{Derivation of spreading coefficient limit of declining infection}\\label{chap:principles}\n\nIn this document I try to develop a model that would help me to understand the\nessential figures and numbers that we should be monitored and measured in order to \ndistinguish the effective and ineffective measures in limiting the spread of\nthe COVID19 virus.\n\nI start the derivation from the measured reproduction number $R0$. We know that\nthe nature of the growth of the infection is exponential which inherently\nmeans the disease is spread by infected persons infecting the uninfected ones\nover certain period of time. Later on in Chapter \\ref{sect:discrete_time} I add a more detailed discrete time\nsystem model to reveal the effects of the feedback delays. That model is still\nunder construction, and I need to fit the system parameter presented in the\nfollowing to that model.\nWith COVID19 there is lots of statistics about number of\ninfected persons, daily new cases, deaths and recoveries. Based on these\nstatistics we may derive the estimate of the contamination time during which\nthe infected patient spreads the disease in such a manner that the daily\nproportional growth equals the monitored reproduction number.\n\nUnder assumption that infected persons spread the disease with constant\nfraction of cases per day, the newly infected persons tomorrow can be\nexpressed as\n\\begin{align}\n    y\\left(n\\right)&=K y\\left(n-1\\right)\\\\\n    K&= \\frac{y\\left(n\\right)}{y\\left(n-1\\right)}=\n    \\frac{y\\left(n\\right)-y\\left(n-1\\right)}{y\\left(n-1\\right)}+1\n\\end{align}\nwhere $y\\left(n\\right)$ is the number of infected persons on day $n$. Without\nlimiting measures $K$ is assumed here to be relatively constant. \n\nWe may express $K$ as\n\\begin{align}\n    K&= 1+S\\\\\n    S &= \\frac{y\\left(n\\right)-y\\left(n-1\\right)}{y\\left(n-1\\right)},\n\\end{align}\nwhere $S$ is spreading coefficient, the \\emph{ ratio of of daily increase of\n    cases  to\nactive cases }. It should be noted that any estimation error that is in fixed\nproportion to actually confirmed cases is canceled in calculation of $S$. Thus\nwe can state that any measure that gives us proportionally relatively stable\ninformation will provide us accurate information about $S$.\n\nAs shown before, $K_l$ and $S$ can be measured. So can be the reproduction\nnumber $R_0$, which for the COVID19 have been estimated to be $R_0=2.06 \\ldots\n2.52$~\\cite{Zhang_S2020}.\nThese two expansion mechanisms are related, ans they should match at least in early phases of\nepidemic, when deaths, recoveries, countermeasures, and developing immunity do not hinder the\nspreading. The relation can be expressed as \n\\begin{align}\n    K^{T_c}&= 1+R_0\\\\\n    T_c&=\\frac{\\ln\\left(1+R_0\\right)}{\\ln\\left(K\\right)},\n\\end{align}\nwhere $T_c$ is the contamination time, i.e.\\ the effective time during which the patients\nspread the disease. It can be thought as a time before patient get's so\nvisibly sick that he will be isolated/quarantined from the community and thus\ndoes not spread the disease. This time is specific to disease and we may\nassume here it is relatively constant.\n\nWe may now denote the spreading coefficient, measured as the ratio of increase\nto the active cases, in the beginning of the epidemic as $S_0$. Thus\n\\begin{align}\n    T_c&=\\frac{\\ln\\left(1+R_0\\right)}{\\ln\\left(1+S_0\\right)}\n\\end{align}\nFor present COVID19, $S_0$ seems to be, with reasonable number of cases,\nbetween 0.3 and 0.2, thus we may use $S_0=0.25$ in our example\ncalculations. We may now preform an example calculation for contamination\nperiod \n\\begin{align}\n    S_0&=0.25\\\\\n    R_0&=2.5\\\\\n    T_c&=\\frac{\\ln\\left(1+R_0\\right)}{\\ln\\left(1+S_0\\right)}=5.6.\n\\end{align}\nThus the estimate of the contamination time is 5.6 days, and we assume that to\nremain constant.\n\nUnder ongoing epidemic, public authorities and private persons perform\nmeasures to reduce $S$ in order to hinder the spread of the disease. However,\nas $S$ and $R_0$ are connected, we may try to calculate \\emph{how low we should\nreduce $S$ in order to stop the epidemic under assumption that $T_T$ does not\nchange}. Stopping the epidemic means $R_0< 1$. We may now calculate the limit\n$S_l$ that should result in declining numbers of active patients.\n\\begin{align}\n    {\\left(1+S_l\\right)}^{T_c}&<2\\\\\n    S_l&<2^{\\frac{\\ln\\left(1+S_0\\right)}{\\ln\\left(1+R_0\\right)}}-1.\n\\end{align}\nWith the given values for current COVID19 outbreak $S_l<0.13$. \n\nIn Table~\\ref{tab:variants} the obtained values under various assumptions are\npresented.\n\\begin{table}[h!]\n  \\begin{center}\n      \\caption{Spreading coefficient limit value under various assumptions on\n      reproduction number $R_0$ and initial spreading coefficient $S_0$}\\label{tab:variants}\n   \\begin{tabular}{c|c|c|c} % <-- Alignments: 1st column left, 2nd middle and 3rd right, with vertical lines in between\n        \\textbf{$R_0$} & \\textbf{$S_0$} & \\textbf{$T_c$} & \\textbf{$S_l$}\\\\\n      \\hline\n      2 &0.25&4.9&0.15 \\\\\n      2 &0.3&4.2&0.18\\\\\n      2 &0.4&3.7&0.21\\\\\n      2.5&0.25&5.6&0.13\\\\\n      2.5&0.3&4.8&0.16\\\\\n      2.5&0.4&4.2&0.18\\\\\n      3 &0.25&6.2&0.11\\\\\n      3 &0.3&5.3&0.14\\\\\n      3 &0.4&4.6&0.18\\\\\n    \\end{tabular}\n  \\end{center}\n\\end{table}\nThese values reveal that with given parameter spread there is no\n\\emph{practical} difference in contamination time, it lies between 3.7 to 6.2\ndays. This means practically two days difference, easily masked by individual\nvariation and real life uncertainties. \nFurthermore we may quite\ncertainly say there is no chance of epidemic to stop with spreading factors\nlarger than 0.2. Assuming 0.15 might be wishful thinking but may work, and 0.1 should be\nquite safe. \n\nAs the global data for the cases have been collected and made generally\navailable it is possible to evaluate the theory by comparing it to\nexisting data. That comparison well be presented in Chapter~\\ref{chap:observations}.\n\n\\section{Parameter estimation with measured data}\nOn March 23 friend of mine,  Teemu Lehtimäki suggested that the measured\nrelative growth e.g.\\ in Sweden and the trend of measured cases do not support\nthe $R_0$ parameter value 2.x, but that the correct number could be higher. The\narising is, what is the most reliable way to estimate $T_t$ in the beginning\nof the epidemic, when the behaviour of the individuals is not affected by the\ncounter measures, but when the cases are relatively scarce. I think one\npossible \nmethod is LMS curve fitting based on measured relative growth and difference\nof cases $y\\left(n\\right)-y\\left(n-x\\right)$. \n\n\\chapter{Discrete time infection system model}\\label{sect:discrete_time}\nIn order to gain more insight on input-output relation (i.e the\ntransfer function),,stability and critical parameters to be identified, I\ndeveloped s simple discrete-time system model.\n\nFig \\ref{fig:infection_system} depicts a discrete time infection system model\nin Z-domain. $X(Z)$ are \n    the infectious patients entering the community with spreading factor $S$.\n$X_q(Z)$ are the infectious patients entering the system through\nquarantine. They are known to be infectious, but they are isolated.\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth]{Figures/Infection_system.eps}\n    \\caption{Discrete time Infection system in Z-domain.}\\label{fig:infection_system}\n\\end{figure}\n\nFig \\ref{fig:infection_feedback_system} presents the infection feedback\neventually causing the exponential growth. Every infectious patient $X$ will\ninitiate an infection chain over $T_c$ days, adding $S$ new infections. \n\\begin{figure}\n    \\centering\n    \\includegraphics[width=\\textwidth]{Figures/Contamination_feedback_system.eps}\n    \\caption{Infection feedback system $W(Z)$}\\label{fig:infection_feedback_system}\n\\end{figure}\n\nDue to the feedback through $W(Z)$, the system will eventually have positive\nfeedback causing exponential type of growth. The parameters characterizing the\nsystem behaviour are listed in Table~\\ref{table:system parameters}.\n\\begin{table}\n    \\centering\n    \\caption{Infection system parameters}\\label{table:system parameters}\n    \\begin{tabular}{l|p{10cm}}\n        \\textbf{Parameter} & \\textbf{Description} \\\\\n        \\hline\n        $S$ & Spreading factor.\\\\\n        $T_i$ & Incubation period. It is assumed that the patient is not\n        infectious during this time. \\\\\n        $T_c$ & Contamination period. Patient spreads the disease during this\n        time until is isolated from the population because of sickness or\n        treatment.\\\\\n        $T_m$ & Monitoring delay. The time from the patient becoming\n        infectious to registration of the case.\\\\\n        $r_d$ & Death rate. The share of the registered patients dying.\\\\\n        $T_d$ & Delay of death. Time from registration to death.\\\\\n        $T_r$ & Recovery time.\n    \\end{tabular}\n    \\label{tab:system_parameters}\n\\end{table}\n\n\\subsection{Considerations on the feedback model}\nIn the beginning of the  April I had already several bothersome days of\nthinking the accuracy of the  feedback model. There seemed to be a\ndiscrepancy between the exponential growth model I describe in the beginning\nof this chapter, and the $R_0$-based exponential model. As per now, (April 2), I\nthink I have developed an explanation that helps to get the modeling forward.\n\nThe parameters $s_k$ define define the feedback system $W(Z)$ In simplest case,\n$s_0=R_0$, and the other feedback coefficients are zero. This will provide\nthe growth due to feedback on a single day with the delay of $T_i$. To use\nrelative growth as a measure in this kind of a system, we should estimate the\n$T_i$ accurately, and use the past values $y\\left(n-T_i\\right)$ in calculation\nof relative growth. Currently I use $y\\left(n-1\\right)$ in calculation of the\nrelative growth, and it does not take into account the incubation period at\nall. Adding the delay would increase the relative growth values on by the\naverage gain of over incubation period, (which should be $R$). \n\nSo, the\nquestion remains why my model seems to work, even though it is timing wise\nincorrect. My current thoughts are the following and subject to change. The\nway I originally thought the exponential growth process is, that \\emph{a\n    patient infects persons as geometric series so that total number of persons over the\ncontamination person is increased by reproduction number $R$}. This is technically incorrect.\nHowever, it can be modeled as $s_k$  values in Fig.~\\ref{fig:infection_feedback_system}\n\\begin{align}\n    s_k&=s\\left(1+s\\right)^k, \\quad k=\\left[0,T_c-1\\right].\n\\end{align}\nThis is the  sum of the growth after $T_c$, which compensates the lack of $T_i$.\nActually, as  \n\\begin{align}\n    s_{T_c}&=\\left(1+s\\right)^{T_c}-1=R,\n\\end{align}\nthe model works exactly as the incubation period were $T_c$. So the timing\nerror in the relative growth estimate is the difference of the contamination\nperiod $T_c$, and incubation period $T_i$. Most likely this is not zero, but\nthe question is, is that difference typically smaller than the estimation\nerror of the incubation period? If it is, it is, using this model provides\nbetter estimate than the discrete time model with estimated\nincubation period. One can also think, that the incubation period \\emph{is}\nthe period over which the patient is infectious but not sick enough to isolate\nhimself. At the end of the incubation period, the patient has infected $R$\npatients. This effectively means $T_c=T_i$, which would mean that the model is\naccurate, and measuring the relative growth would reflect quite accurately the\ncharacteristics of the system. It also distributes the exponential growth\nover the $T_c$ with exponential emphasis on the last days. More considerations\nare required to determine if this is accurate enough.\n\nThe remaining delay is the measurement delay\n$T_m$, which is not related to the disease, but the system measuring it. This\ndoes not affect the relative growth number, only delays the result by $T_m$-\nIt should also be noted, that we may measure the contamination period by\nmonitoring the relative growth at the point where the increase of the number\nof active cases stops. \n\nTherefore following observations about the nature of the\nsystem can be made.\n\\begin{itemize}\n    \\item System is not linear time invariant, but can be considered piecewise\n        linear over\n        the coherence time on $S$, i.e. during the periods $S$ is not altered,\n        and linear time invariant, if $S$ is considered constant.\n    \\item As the fraction of recovered and dead patiences increases, the $S$\n        is decreased. This phenomenon is not included in this model,\n        indicating infinite population.\n    \\item Timing relation of the signal and $S$ in the feedback path indicates\n        that the effect of changes in policies affecting $S$ are immediate to\n        the spreading of the disease, and visible in the statistics after the\n        measurement delay $T_m$.\n\\end{itemize}\n\n", "meta": {"hexsha": "201fe295113404082e7ad0d1697c1b6d101f19ac", "size": 12903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "derivation.tex", "max_stars_repo_name": "mkosunen/Covid19-Study", "max_stars_repo_head_hexsha": "6126038aa27bf73414cd2f7d3ef60b7fe9aeb72f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "derivation.tex", "max_issues_repo_name": "mkosunen/Covid19-Study", "max_issues_repo_head_hexsha": "6126038aa27bf73414cd2f7d3ef60b7fe9aeb72f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "derivation.tex", "max_forks_repo_name": "mkosunen/Covid19-Study", "max_forks_repo_head_hexsha": "6126038aa27bf73414cd2f7d3ef60b7fe9aeb72f", "max_forks_repo_licenses": ["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.0, "max_line_length": 119, "alphanum_fraction": 0.7537006898, "num_tokens": 3385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6078894965018277}}
{"text": "\\documentclass[10pt, letterpapr]{article}\n\\usepackage[utf8]{inputenc} % document encoding\n\\usepackage{graphicx}\n\\usepackage{comment} % allow comment blocks to be added\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\n\\subsection*{Multiphase flow through porous media}\n\n\\subsubsection*{Liquid phase}\n\nFlux through a porous medium is defined as:\n\n\\[\n\tf_l=-K\\frac{d\\psi}{dz}\n\\]\n\n\\noindent where $f_l$ is liquid flux density [kg\\,m$^{-2}$\\,s$^{-1}$], $\\psi$ is the matric potential [J\\,kg$^{-1}$] $\\left(\\text{note: }\\psi=gh\\right)$, and $K$ is the hydraulic conductivity [kg\\,s\\,m$^{-3}$].\\footnote{note: $K_{kg\\cdot\\,s\\cdot\\,m^{-3}}=\\frac{\\rho_l}{g}K_{m\\cdot\\,s^{-1}}$}\n\nWhen combined with the mass conservation equation, the result yields the transient vertical (1D) Richards (1931) equation: \n\n% pg.166 Bittelli etal (2015); potential is being represented in the energy per unit mass form (J/kg) rather than the per unit volume form (J/m3=Pa) to avoid temperature dependence on liquid volume (see pg.98).\n\n\\[\n\t\\rho_l\\frac{\\partial\\theta}{\\partial t}=\\frac{\\partial}{\\partial z}\\left[K(\\psi)\\left(\\frac{\\partial\\psi}{\\partial z}+g\\right)\\right],\n\\]\n\n\\noindent which is often expressed in its so-called $\\psi$--based form:\n\n\\[\n\t\\rho_lC(\\psi)\\frac{\\partial\\psi}{\\partial t}=\\frac{\\partial}{\\partial z}\\left[K(\\psi)\\left(\\frac{\\partial\\psi}{\\partial z}+g\\right)\\right],\n\\]\n\n\\noindent where $\\rho_l$ is the density of the liquid [kg\\,m$^{-3}$], $g$ is the acceleration to to gravity ($\\approx9.80665$\\,m\\,s$^{-2}$ or J\\,kg$^{-1}$\\,m$^{-1}$). The capacity [kg\\,J] term is solved using the Campbell (1974) model: % pg121\n\n\\[\n\tC(\\psi)=\\frac{d\\theta}{d\\psi}=\\frac{-\\theta}{b\\psi}\n\\]\n\n\\noindent and conductivity:\n\n\\[\n\tK(\\psi)=\n\t\\begin{cases}\n\t\tK_s\\left(\\frac{\\psi_e}{\\psi}\\right)^{2+3/b}  \\qquad &\\text{if $\\psi_m\\leq\\psi_e$} \\\\\n\t\tK_s  &\\text{otherwise}\n\t\\end{cases}\n\\]\n\n\\noindent where $K_s$ is the saturated conductivity [kg\\,s\\,m$^{-3}$], $b$ is a shape parameter and $\\psi_e$ is the air-entry potential [J kg$^{-1}$]. Furthermore, water content ($\\theta$) [m$^3$ m$^{-3}$] and $\\psi$ are assumed related by the power-law relationship:\n\n\\[\n\t\\theta(\\psi)=\n\t\\begin{cases}\n\t\t\\theta_s\\left(\\frac{\\psi}{\\psi_e}\\right)^{-1/b}  \\qquad &\\text{if $\\psi_m\\leq\\psi_e$} \\\\\n\t\t\\theta_s  &\\text{otherwise}\n\t\\end{cases}\n\\]\n\n\\noindent or conversely,\n\n\\[\n\t\\psi(\\theta)=\n\t\\begin{cases}\n\t\t\\psi_e\\left(\\frac{\\theta}{\\theta_s}\\right)^{-b}  \\qquad &\\text{if $\\theta\\leq\\theta_s$} \\\\\n\t\t\\psi_e  &\\text{otherwise}\n\t\\end{cases}\n\\]\n\n\\noindent where $\\theta_s$ is the water content at saturation. The water balance for cell $i$ can be solved using the its finite-difference form: % linear method\n\\[\n\t\\frac{\\rho_l\\left(\\theta_i^{j+1}-\\theta_i^j\\right)\\left(z_{i+1}-z_{i-1}\\right)}{2\\Delta t}=\\frac{\\overline{K}_i\\left(\\psi_{i+1}-\\psi_i\\right)}{z_{i+1}-z_i}-\\frac{\\overline{K}_{i-1}\\left(\\psi_i-\\psi_{i-1}\\right)}{z_i-z_{i-1}}+u_i\n\\]\n\n\\noindent or in its $\\psi$-based form:\n\\[\n\t\\frac{\\rho_lC_i\\left(\\psi_i^{j+1}-\\psi_i^j\\right)\\left(z_{i+1}-z_{i-1}\\right)}{2\\Delta t}=\\frac{\\overline{K}_i\\left(\\psi_{i+1}-\\psi_i\\right)}{z_{i+1}-z_i}-\\frac{\\overline{K}_{i-1}\\left(\\psi_i-\\psi_{i-1}\\right)}{z_i-z_{i-1}}+u_i\n\\]\n\nThe source term $u_i$ could include extraction by roots, evaporation, etc. In most cases, for vertical simulations, the source term represents gravitational flux, where:\n\\[\n\tu_i=g\\left(\\overline{K}_{i-1}-\\overline{K}_i\\right).\n\\]\n\n% The solution to the above equation is done implicitly, by solving a system equations. Transforming the above to:\n% \\begin{align*}\n\t% \\varrho(i) &=\\rho_lC_i\\frac{\\left(z_{i+1}-z_{i-1}\\right)}{2\\Delta t} \\\\\n\t% k(i) &=\\frac{K_i}{z_{i+1}-z_i} \\\\\n\t% c(i) &= a(i+1) = k(i) \\\\\n\t% b(i) &= k(i-1)+k(i)+\\varrho(i) \\\\\n\t% d(i) &= \\varrho(i)\\psi_i^j+u(i)\n% \\end{align*}\n\n% \\noindent the finite-difference scheme for $4$ layers is put in matrix form:\n% \\[\n\t% \\begin{bmatrix}\n\t\t% b(1) & c(1) & 0 & 0 \\\\\n\t\t% a(2) & b(2) & c(2) & 0 \\\\\n\t\t% 0 & a(3) & b(3) & c(3) \\\\\n\t\t% 0 & 0 & a(4) & b(4)\n\t% \\end{bmatrix}\n\t% \\begin{bmatrix}\n\t\t% \\psi^{j+1}(1) \\\\\n\t\t% \\psi^{j+1}(2) \\\\\n\t\t% \\psi^{j+1}(3) \\\\\n\t\t% \\psi^{j+1}(4)\n\t% \\end{bmatrix}\n\t% =\n\t% \\begin{bmatrix}\n\t\t% d(1) \\\\\n\t\t% d(2) \\\\\n\t\t% d(3) \\\\\n\t\t% d(4)\n\t% \\end{bmatrix}\n% \\]\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection*{Vapour phase within the soil matrix}\n\nVapour flux density [kg\\,m$^{-2}$\\,s$^{-1}$] (i.e., molecular diffusion flux of water vapour in the air) is defined using Fick's Law: %pg.70 Novak\n\\[\n\tf_v=-\\rho_a D(\\theta) \\frac{dq}{dz},\n\\]\n\n\\noindent where $\\rho_a$ is the density of air, [kg m$^{-3}$], $D(\\theta)$ is the effective coefficient of turbulent diffusion of water vapour in pore-space air [m$^2$\\,s$^{-1}$], often given the form attributed to Penman (1940):\n\\[\n\tD(\\theta)=D_a\\eta\\left(\\theta_s-\\theta\\right),\n\\]\n\n\\noindent where $D_a$ is coefficient of molecular diffusion of water vapour in air $\\approx2.12\\times10^{-5}$ m$^2$\\,s$^{-1}$, and $\\eta$ is a dimensionless coefficient characterizing the turbulent diffusion in porous media, $\\eta\\approx0.66$ (Penman, 1940). Note that the term $\\left(\\theta_s-\\theta\\right)$ is included correct for the volume of gas-filled porosity, where vapour flux is occurring. $q$ is the specific humidity (moisture content) of air [kg\\,kg$^{-1}$]:\n\\[\n\tq=\\frac{\\varepsilon e}{P}=wq^*(T,P),\n\\]\n\n\\noindent where $e$ and $P$ are the vapour and total pressures, respectively [kg\\,m$^{-1}$\\,s$^{-2}$], $\\varepsilon$ is the ratio of the molecular weight of water to the molecular weight of air ($\\approx 0.622$), $w$ is the relative humidity [--], and $q^*$ is the saturated specific humidity determined using the August-Roche-Magnus-Tetens relationship:\n\\[\n\tq^*(T,P)=\\frac{0.38}{P}\\exp\\left(\\frac{17.625T}{T+243.04}\\right),\n\\]\n\n\\noindent where $P$ is in [kPa] and $T$ is in [$^\\circ$C].\n\nWithin a porous medium, assuming isobaric (i.e., $P_\\text{pores}\\approx P_a$) and isothermal (constant temperature) conditions, the specific humidity gradient can be related to pore-space relative humidity ($w_p$) and soil temperature ($T_s$) by:\n\\[\n\t\\frac{dq}{dz}=q^*(T_s,P)\\frac{dw_p}{dz}.\n\\]\n\nBy further assuming that the liquid and vapour phases are in equilibrium (i.e., have equal potential and the partial pressure of water has reached its vapour pressure, $e$), according to the ideal gas law, pore-space relative humidity can be determined from liquid potential by (Philip, 1957):\n\\[ %eq:wp\n\tw_p=\\frac{e}{e^*(T_s)}=\\frac{q}{q^*(T_s,P)}=\\exp{\\frac{\\omega_w\\psi}{RT_s}},\n\\]\n\n\\noindent where the gas constant $R=8.3143$ J mol$^{-1}$ K$^{-1}$, the molecular mass of water $\\omega_w=0.01802$ kg mol$^{-1}$, and $e^*$ is the saturated vapour pressure at the temperature of the soil surface $T_s$ [K]. Next, using the chain rule,\n\\[\n\t\\frac{dw_p}{dz}=\\frac{dw_p}{d\\psi}\\frac{d\\psi}{dz}=w_p\\frac{\\omega_w}{RT_s}\\frac{d\\psi}{dz},\n\\]\n\n\\noindent Combining the above equations, results in:\n\\[\n\tf_v=-K_v\\frac{d\\psi}{dz},\n\\]\n\n\\noindent where\n\\[\n\tK_v=\\frac{\\omega_w\\eta\\rho_aD_aq}{RT_s}\\left(\\theta_s-\\theta\\right),\n\\]\n\nBy combining the flux of water vapour, the Richards equation can be re-stated as (Nov\\'ak, 2012): % pg.71 \n\\[\n\t\\rho_l\\frac{\\partial\\theta}{\\partial t}=\\frac{\\partial}{\\partial z}\\left[K(\\psi)\\left(\\frac{\\partial\\psi}{\\partial z}+g\\right)+\\rho_a D(\\theta)\\frac{\\partial q}{\\partial z}\\right],\n\\]\n\n\\noindent and further:\n\n\\[\n\t\\rho_l\\frac{\\partial\\theta}{\\partial t}=\\frac{\\partial}{\\partial z}\\left[\\left[K(\\psi)+K_v(\\theta,q)\\right]\\frac{\\partial\\psi}{\\partial z}+gK(\\psi)\\right].\n\\]\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection*{Atmospheric exchange}\n\nAt the soil surface--atmosphere interface, the flux density to the atmosphere remains (Nov\\'ak, 2012):\n\\[\n\tf_v=\\rho_a D \\frac{dq}{dz}\n\\]\n\nAssuming that vertical fluxes do not change in the vicinity of the evaporating soil surface, integrating the above equation from the soil surface ($z_s$) and some effective height above the surface ($z_a$) yields: %pg.45 in Novak\n\n\\[\n\t-\\int\\limits_{q_s}^{q_a}dq = \\frac{f_v}{\\rho_a}\\int\\limits_{z_s}^{z_a}\\frac{dz}{D(z)},\n\\]\n\n\\noindent re-arranging:\n\n\\[\n\tf_v=\\frac{1}{\\int_{z_s}^{z_a}\\frac{dz}{D(z)}}\\rho_a(q_s-q_a).\n\\]\n\n\\noindent Next, by defining a water vapour turbulent transport coefficient ($k_v$) [m\\,s$^{-1}$]:\n\n\\[\n\tk_v=\\frac{1}{\\int_{z_s}^{z_a}\\frac{dz}{D(z)}},\n\\]\n\n\\noindent vapour flux density to the atmosphere from the gas-filled pores can be written as:\n\\begin{align*}\n\tf_{v,g} &=\\rho_ak_v(q_s-q_a) \\\\\n\t&=\\rho_ak_v\\left[q_s-w_aq^*(T_a,P_a)\\right],\n\\end{align*}\n\n\\noindent and\n\\[\n\tf_{v,l}=\\rho_ak_v(q^*(T_s,P_a)-q_a),\n\\]\n\n\\noindent where $w_a$ is the atmospheric relative humidity, $T_a$ is air temperature [K], and $P_a$ is air pressure [Pa\\,=\\,kg\\,m$^{-1}$\\,s$^{-2}$]. (Note that for water, the units for flux density [kg\\,m$^{-2}$\\,s$^{-1}$] is equivalent to [mm\\,s$^{-1}$].) The water vapour turbulent transport coefficient can be related to wind speed ($u(z)$) [m\\,s$^{-1}$] using boundary-layer theory: % simplified from pg.49 Novak\n\\[\n\tk_v\\approx\\frac{\\kappa^2u(z)}{\\left[\\ln\\left(\\frac{z}{z_0}\\right)+\\frac{\\beta}{L_*}z\\right]^2} \\approx\\frac{\\kappa^2u(z)}{\\ln\\left(\\frac{z-d_e}{z_0}\\right)^2},\n\\]\n\n\\noindent where $\\kappa$ is the von-K\\'arm\\'an constant ($\\approx0.4$), $z_0$ is the roughness length [m], $\\beta$ and $L_*$ are the Monin-Obukhov (1954) coefficient of atmospheric stability and characteristic length, respectively, and $d_e$ is the so-called zero-plane displacement height [m]. Alternatively, the Penman (1948)/Penman-Monteith (1965) relationship to aerodynamic resistance ($r_a$), soil surface resistance ($r_s$) and canopy resistance ($r_c$) [s\\,m$^{-1}$] can be used, where:\n\\[\n\tk_v=\\frac{1}{r_a+r_s+r_c}.\n\\]\n\nLastly, the effective mass flux evaporating from the soil surface must account for the portion of the soil surface area exposed to gas-filled pores and the area of direct liquid exposure:\n\\begin{align*}\n\tf_e &=\\left(\\theta_s-\\theta\\right)f_{v,g}+\\theta f_{v,l}. \\\\\n\t\t&=\\rho_ak_v\\left[\\theta_s(q_s-q_a)+\\theta(q^*_s-q_s)\\right]\n\\end{align*}\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection*{Numerical solution to the Richards equation}\n\nOne solution to the 1D Richards equation is the cell-centered finite volume solution scheme following Bittelli et.al.\\,(2015). The cell-centered finite-volume form to the above equations gives the mass-balance at node $i$ as:\n\\[\n\t\\rho_lV_i\\frac{\\partial\\theta_i}{\\partial t}=\\sum_{j=1}^{n}F_{ij}+u_i \\qquad\\forall i\\neq j,\n\\]\n\n\\noindent where $V_i$ is the finite volume of cell/node $i$, and the inter-nodal mass flux [kg\\,s$^{-1}$]:\n\\[\n\tF_{ij}=-A_{ij}\\overline{K}_i\\frac{h_i-h_j}{L_{ij}},\n\\]\n\n\\noindent and $h_i=\\psi_i+gz$ is the total hydrostatic potential [J\\,kg$^{-1}$]. In the 1D vertical, The water balance in cell $i$ (i.e., implicit Euler method---evaluating at the end of the time step) is: %pg.63\n\\[\n\t\\frac{\\rho_lV_i\\overline{C}_i}{\\Delta t}\\left(h_i^{k+1}-h_i^k\\right)=F_i\\left(h_i^{k+1}-h_{i+i}^{k+1}\\right)-F_{i-1}\\left(h_{i-1}^{k+1}-h_i^{k+1}\\right)+u_i,\n\\]\n\n\\noindent where\n\\[\n\tF_i=-A_i\\frac{\\overline{K}_i}{z_{i+1}-z_i}.\n\\]\n\\noindent and\n\\[\n\t\\overline{C}_i=\\frac{d\\theta}{dh}\\approx\\frac{\\theta_i^{k+1}-\\theta_i^k}{h_i^{k+1}-h_i^k}.\n\\]\n\nThe solution to the above equation is done implicitly, by solving a system equations, expanding the above and letting:\n\\begin{align*}\n\t\\varrho(i) &=\\frac{\\rho_l V_i\\overline{C}_i}{\\Delta t} \\\\\n\tf(i) &=\\frac{A_i\\overline{K}_i}{z_{i+1}-z_i} \\\\\n\tc(i) &= a(i+1) = -f(i) \\\\\n\tb(i) &= f(i-1)+f(i)+\\varrho(i) \\\\\n\td(i) &= \\varrho(i)h_i^k+u_i\n\\end{align*}\n\n\\noindent the finite-volume scheme for $4$ layers is put in matrix form:\n\\[\n\t\\begin{bmatrix}\n\t\tb(1) & c(1) & 0 & 0 \\\\\n\t\ta(2) & b(2) & c(2) & 0 \\\\\n\t\t0 & a(3) & b(3) & c(3) \\\\\n\t\t0 & 0 & a(4) & b(4)\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\th^{k+1}(1) \\\\\n\t\th^{k+1}(2) \\\\\n\t\th^{k+1}(3) \\\\\n\t\th^{k+1}(4)\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t\td(1) \\\\\n\t\td(2) \\\\\n\t\td(3) \\\\\n\t\td(4)\n\t\\end{bmatrix}\n\\]\n\n\\noindent which is a tri-diagonal matrix that is solved using the Thomas algorithm.\n\n\n\\subsubsection*{Newton-Raphson transformation}\n\nA finite-difference solution to the 1D Richards equation is solved using the Newton-Raphson solution scheme following Bittelli et.al.\\,(2015). The water balance in cell $i$ is:\n\n\\begin{multline*}\n\tF_i=\\frac{\\overline{K}_i\\left(\\psi_{i+1}-\\psi_i\\right)}{z_{i+1}-z_i}-\\frac{\\overline{K}_{i-1}\\left(\\psi_i-\\psi_{i-1}\\right)}{z_i-z_{i-1}} \\\\\n\t\t-g\\left(\\overline{K}_i-\\overline{K}_{i-1}\\right)-\\frac{\\rho_l}{2\\Delta t}\\left(\\theta_i^{k+1}-\\theta_i^k\\right)\\left(z_{i+1}-z_{i-1}\\right),\n\\end{multline*}\n\n\\noindent where $F$ is the mass balance residual and $\\overline{K}$ is the mean elemental hydraulic conductivity. Applying integral transform methods (Bittelli et.al., 2015), $\\overline{K}$ is defined by: %eq.8.53 pg.178\n\\[\n\t\\overline{K}_i=\\frac{K_{i+1}\\psi_{i+1}-K_i\\psi_i}{\\left(1+3/b\\right)\\left(\\psi_{i+1}-\\psi_i\\right)}.\n\\]\n\n\\noindent The solution to the above equation is then considered a minimization problem, whereby Newton-Raphson:\n\n\\[\n\t\\frac{\\partial F}{\\partial\\psi}\\cdot \\left(\\psi^{k+1}-\\psi^k\\right)=-F\\rightarrow 0 \\\\\n\\]\n\n\\noindent or in a matrix-form for a $3$--layer profile is:\n\n\\[\n\t\\begin{bmatrix}\n\t\t\\frac{\\partial F_1}{\\partial\\psi_1} & \\frac{\\partial F_1}{\\partial\\psi_2} & \\frac{\\partial F_1}{\\partial\\psi_3} \\\\\n\t\t\\frac{\\partial F_2}{\\partial\\psi_1} & \\frac{\\partial F_2}{\\partial\\psi_2} & \\frac{\\partial F_2}{\\partial\\psi_3} \\\\\n\t\t\\frac{\\partial F_3}{\\partial\\psi_1} & \\frac{\\partial F_3}{\\partial\\psi_2} & \\frac{\\partial F_3}{\\partial\\psi_3}\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\t\\psi_1^{k+1}-\\psi_1^k \\\\\n\t\t\\psi_2^{k+1}-\\psi_2^k \\\\\n\t\t\\psi_3^{k+1}-\\psi_3^k\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t\t-F_1 \\\\\n\t\t-F_2 \\\\\n\t\t-F_3 \\\\\n\t\\end{bmatrix}\t\n\\]\n\n\\noindent where $k$ indicates the $k^{th}$ iteration of the minimization attempt. The mass-balance function $F$ is solved by:\n\n\\[\n\tF_i=f_i-f_{i-1}+u_i-u_{i-1}-\\frac{\\rho_l}{2\\Delta t}\\left(\\theta_i^{k+1}-\\theta_i^k\\right)\\left(z_{i+1}-z_{i-1}\\right),\n\\]\n\n\\noindent where\n\\[\n\tf_i=-\\frac{\\overline{K}_i\\left(\\psi_{i+1}-\\psi_i\\right)}{z_{i+1}-z_i} = -\\frac{K_{i+1}\\psi_{i+1}-K_i\\psi_i}{\\left(1+3/b\\right)\\left(z_{i+1}-z_i\\right)}\t\n\\]\n\n\\noindent and letting\n\\begin{align*}\n\tu_i &=-gK_i \\\\\n\t\\varrho_i &=-\\rho_l\\theta_i\\frac{z_{i+1}-z_{i-1}}{2\\Delta t},\n\\end{align*}\n\n\\noindent then substituting yields:\n\\begin{multline*}\n\tF_i=\\frac{K_i\\psi_i-K_{i-1}\\psi_{i-1}}{\\left(1+3/b\\right)\\left(z_i-z_{i-1}\\right)}\n\t-\\frac{K_{i+1}\\psi_{i+1}-K_i\\psi_i}{\\left(1+3/b\\right)\\left(z_{i+1}-z_i\\right)} \\\\\n\t-g\\left(K_i-K_{i-1}\\right)-\n\t\\frac{\\rho_l}{2\\Delta t}\\left(\\theta_i^{k+1}-\\theta_i^k\\right)\\left(z_{i+1}-z_{i-1}\\right).\n\\end{multline*}\n\n\\noindent Differentiating $F_i$ with respect to $\\psi_i$, $\\psi_{i-1}$ and $\\psi_{i+1}$ yields:\n\n\\begin{align*}\n\tf'_i &=\\frac{\\partial f_i}{\\partial\\psi_i}=\\frac{K_i}{z_{i+1}-z_i} \\\\\n\tu'_i &=\\frac{\\partial u_i}{\\partial\\psi_i}=\\frac{gK_i}{\\psi_i}(2+3/b) \\\\\n\t\\varrho'_i &=\\frac{\\partial \\varrho_i}{\\partial\\psi_i}=\\rho_l\\frac{\\theta_i}{b\\psi_i}\\frac{z_{i+1}-z_{i-1}}{2\\Delta t}\n\\end{align*}\n\n\\noindent and thus % pg.180-181\n\\begin{align*}\n\t\\frac{\\partial F_i}{\\partial\\psi_i} &=\\frac{K_i}{z_{i+1}-z_i}+\\frac{K_{i-1}}{z_i-z_{i-1}}+u'_i+\\varrho'_i \\\\\n\t\\frac{\\partial F_i}{\\partial\\psi_{i-1}} &=\\frac{-K_{i-1}}{z_i-z_{i-1}}-u'_{i-1} \\\\\n\t\\frac{\\partial F_i}{\\partial\\psi_{i+1}} &=\\frac{-K_i}{z_{i+1}-z_i}\n\\end{align*}\n\n\\noindent Solving the Newton-Raphson system of equations is then accomplished like the linear methods described above.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsubsection*{Boundary conditions}\n\nBoundary conditions for the top of the vertical profile can either be a constant flux (e.g., evaporation) or constant potential:\n\n\\begin{itemize}\n\t\\item For constant flux, the source is added to $F_1$; \n\t\\item For a constant potential, $\\psi_1^{j+1}$ is known and is set at the start of the time step (since the Newton-Raphson method computes changes in $\\psi$ to bring $F$ to zero, $F_1$ and $\\frac{\\partial F_1}{\\partial\\psi_i}$ are set to zero before solving; therefore the value of $\\psi_1$ will remain constant throughout the time step. For infiltration, set $\\psi_1=\\psi_e$.\n\\end{itemize}\n\nAt the bottom of the profile, either a constant potential (i.e., water table) or a free drainage condition can be specified using a ghost below the profile that never becomes part of the solution. Free drainage is set by:\n\\begin{align*}\n\t\\psi_{n+1} &=\\psi_n \\\\\n\t\\theta_{n+1} &=\\theta_n \\\\\n\tK_{n+1} &=K_n\n\\end{align*}\n\n\\noindent after each outer iteration, where $n$ is the number of finite difference cells being solved.\n\n\\newpage\n\\subsection*{References}\n\nBittelli, M., Campbell, G.S., and Tomei, F., 2015. Soil Physics with Python. Oxford University Press.\n\nCampbell, G.S., 1974. A simple method for determining unsaturated conductivity from moisture retention data. Soil Science, 117: 311--387.\n\nMonteith, J.L.,1965. Evaporation and environment. Symposia of the Society for Experimental Biology 19: 205–-224.\n\nNov\\'ak, V., 2012. Evapotranspiration in the Soil-Plant-Atmosphere System. Springer. 253pp.\n\nPenman, H.L., 1940. Gas and vapour movements in the soil: I. The diffusion of vapours through porous solids. Journal of Agricultural Science 30(3): 437--462.\n\nPenman, H.L., 1948. Natural evaporation from open water, bare soil and grass. Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences 193(1032): 120--145.\n\nPhilip, J.R., 1957. Evaporation, and moisture and heat fields in the soil. Journal of Meteorology 14: 354--366.\n\nRichards, L.A., 1931. Capillary conduction of liquids through porous media. Physics 1: 318--333.\n\n\n\n\\end{document}", "meta": {"hexsha": "ba33f0e84a79acc168dff74c0fdf12ae482ddea1", "size": 18251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "profile/theory.tex", "max_stars_repo_name": "maseology/goHydro", "max_stars_repo_head_hexsha": "f018407b1e1d569475a635467415a55aa3a12eec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-08T11:07:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-08T11:07:19.000Z", "max_issues_repo_path": "profile/theory.tex", "max_issues_repo_name": "maseology/goHydro", "max_issues_repo_head_hexsha": "f018407b1e1d569475a635467415a55aa3a12eec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "profile/theory.tex", "max_forks_repo_name": "maseology/goHydro", "max_forks_repo_head_hexsha": "f018407b1e1d569475a635467415a55aa3a12eec", "max_forks_repo_licenses": ["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.8600917431, "max_line_length": 494, "alphanum_fraction": 0.6398005589, "num_tokens": 6378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6078894872734149}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{tensor}\n\\author{Andreas Forster}\n\\numberwithin{equation}{section}\n\\renewcommand{\\vec}[1]{\\ensuremath{\\mathbf{#1}}}\n\\newcommand{\\vecs}[1]{\\ensuremath{\\boldsymbol{#1}}}\n\\renewcommand{\\deg}{\\ensuremath{^\\circ}}\n\\newcommand{\\norm}[1]{\\ensuremath{\\left|\\left|#1\\right|\\right|}}\n\\newcommand{\\Exp}{\\mathrm{Exp}}\n\n\\renewcommand{\\arraystretch}{1.5}\n%\\setcounter{secnumdepth}{0}\n\n\\begin{document}\n\\section{Free Line Parametrization}\nA coordinate frame $L_i$ is defined with origin $\\tensor[_W]{\\vec{p}}{_L}$ on the line and with minimum distance $d_{L}$ to the frame origin. The $x$ axis is aligned with the line and the $z$ axis points away from the origin. The parametrization is as follows:\n\\begin{equation}\n\\vec{l} = \\left[q_{WL}^T \\quad d_L\\right].\n\\end{equation}\nThe line anchor $\\tensor[_W]{\\vec{p}}{_L}$ can be calculated in the following way:\n\\begin{equation}\n\\tensor[_W]{\\vec{p}}{_L} = q_{WL}\\times\\begin{bmatrix}\n0\\\\0\\\\d_L\\end{bmatrix}\n\\end{equation}\nAnd the line direction $\\tensor[_W]{\\vec{x}}{_L}$:\n\\begin{equation}\n\\tensor[_W]{\\vec{x}}{_L} = q_{WL}\\times\\begin{bmatrix}1\\\\0\\\\0 \\end{bmatrix}\n\\end{equation}\n%\n\\section{Measurement}\nLet $\\vec{f}_1$ and $\\vec{f}_2$ be the bearing vectors through the two endpoints of the detected line segment. $\\tilde{\\vec{n}} = \\frac{\\vec{f}_1\\times\\vec{f}_2}{\\norm{\\vec{f}_1\\times\\vec{f}_2}}$ is the normalized normal vector of the plane spanned by the two bearing vectors and defines our measurement.\n%\n\\section{Error formulation}\nGiven: Measurement $\\tilde{\\vec{n}}$ and line $\\vec{l} = [q_{WL}^T\\quad d_L]$.\n\\subsection{Parallel constraint}\nThe direction of the line is parallel to the plane defined with $\\tilde{\\vec{n}}$:\n\\begin{equation}\n\\varepsilon_1 = \\tensor[_C]{\\tilde{\\vec{n}}}{^T}C_{CB}\\hat{C}_{BW}\\tensor[_W]{\\vec{x}}{_L}.\n\\end{equation}\n$\\varepsilon_1$ is related to the angle $\\delta\\phi$ between plane and the line $\\vec{l}$ in the following way:\n\\begin{equation}\n\\varepsilon_1 = \\sin \\delta\\phi.\n\\end{equation}\n\\subsection{Distance constraint}\nThe anchor point should be part of the measured plane. We define the second error term $\\varepsilon_2$ as the sine of the angle between the bearing vectors through the anchor point and the projection of that point on the measured plane.  \n\\begin{align}\n\\varepsilon_2 &= \\frac{\\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} \\hat{C}_{BW} \\left(\\tensor[_W]{\\hat{\\vec{p}}}{_C} - \\tensor[_W]{\\vec{p}}{_L}\\right)}{\\norm{\\tensor[_W]{\\hat{\\vec{p}}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\\\\\n\\tensor[_W]{\\hat{\\vec{p}}}{_C} &= -\\left(\\tensor[_W]{\\hat{\\vec{t}}}{_{CB}}+\\tensor[_W]{\\hat{\\vec{t}}}{_{BW}}\\right)\\\\ \n&=-\\left(\\hat{C}_{WB} C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \n\\hat{C}_{WB} \\tensor[_B]{\\hat{\\vec{t}}}{_{BW}}\\right)\\\\\n&=-\\hat{C}_{WB} \\left(C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \n\\tensor[_B]{\\hat{\\vec{t}}}{_{BW}}\\right)\n\\end{align}\n\\section{Jacobian w.r.t to $T_{BW}$}\n\\begin{align}\nC_{BW} &\\leftarrow C_{BW}\\Exp(\\vecs{\\delta\\phi})\\\\\n\\tensor[_B]{\\vec{t}}{_{BW}} &\\leftarrow \\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW}\\vecs{\\delta t}\n\\end{align}\n\\subsection{$\\vecs{\\varepsilon_1}$}\n\\begin{align}\n\\varepsilon_1 &= \\tensor[_C]{\\tilde{\\vec{n}}}{^T}C_{CB} C_{BW}\\Exp(\\vecs{\\delta\\phi}) \\tensor[_W]{\\vec{x}}{_L}\\\\\n&\\approx \\tensor[_C]{\\tilde{\\vec{n}}}{^T}C_{CB} C_{BW}\\tensor[_W]{\\vec{x}}{_L} - \\tensor[_C]{\\tilde{\\vec{n}}}{^T}C_{CB} C_{BW} \\tensor[_W]{\\vec{x}}{_L^\\wedge}\\vecs{\\delta\\phi}\n\\end{align}\n\\begin{align}\n\\frac{\\partial \\varepsilon_1}{\\partial\\vecs{\\delta\\phi}} &= -\\tensor[_C]{\\tilde{\\vec{n}}}{^T}C_{CB} C_{BW}\\tensor[_W]{\\vec{x}}{_L^\\wedge}\\\\\n\\frac{\\partial \\varepsilon_1}{\\partial\\vecs{\\delta t}} &= \\begin{bmatrix} 0&0&0 \\end{bmatrix}\n\\end{align}\n\\subsection{$\\vecs{\\varepsilon_2}$}\n%\n%\nLet:\n\\begin{equation}\n\\vec{v} = \\frac{\\tensor[_W]{\\hat{\\vec{p}}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}{\\norm{\\tensor[_W]{\\hat{\\vec{p}}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\end{equation}\nThen:\n\\begin{align}\n\\varepsilon_2 &= \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW} \\Exp(\\vecs{\\delta\\phi}) \\vec{v}\\\\\n&\\approx \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW} \\vec{v} - \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW} \\vec{v}^\\wedge \\vecs{\\delta\\phi}\n\\end{align}\n\\begin{align}\n\\frac{\\partial\\varepsilon_2}{\\partial\\vecs{\\delta\\phi}} &= \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\frac{\\partial \\vec{v}}{\\partial\\vecs{\\delta\\phi}} - \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\vec{v}^\\wedge\\\\\n\\frac{\\partial\\varepsilon_2}{\\partial\\vecs{\\delta t}} &= \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\frac{\\partial\\vec{v}}{\\partial \\vecs{\\delta t}}\n\\end{align}\n\\begin{align}\n\\frac{\\partial\\vec{v}}{\\partial\\vecs{\\delta\\phi}} &= \\frac{\\partial \\vec{v}}{\\partial\\tensor[_W]{\\vec{p}}{_C}} \\frac{\\partial \\tensor[_W]{\\vec{p}}{_{C}}}{\\partial \\vecs{\\delta\\phi}}\\\\\n\\frac{\\partial\\vec{v}}{\\partial\\vecs{\\delta t}} &= \\frac{\\partial \\vec{v}}{\\partial\\tensor[_W]{\\vec{p}}{_C}} \\frac{\\partial \\tensor[_W]{\\vec{p}}{_C}}{\\partial \\vecs{\\delta t}} \n\\end{align}\nSome derivatives:\n\\begin{align}\n\\frac{d\\norm{\\vec{w}}}{d\\vec{w}} &= \\frac{1}{\\norm{\\vec{w}}}\\vec{w}^T\\\\\n\\frac{d\\frac{1}{\\norm{\\vec{w}}}}{d\\vec{w}} &= -\\frac{1}{\\norm{\\vec{w}}^3}\\vec{w}^T\\\\\n\\frac{d\\frac{\\vec{w}}{\\norm{\\vec{w}}}}{d\\vec{w}} &= \\frac{1}{\\norm{\\vec{w}}}I - \\frac{1}{\\norm{\\vec{w}}^3}\\vec{w}\\vec{w}^T\\notag\\\\\n&= \\frac{1}{\\norm{\\vec{w}}}\\left(I - \\frac{\\vec{w}}{\\norm{\\vec{w}}}\\left(\\frac{\\vec{w}}{\\norm{\\vec{w}}}\\right)^T\\right)\n\\end{align}\nIt follows:\n\\begin{align}\n\\frac{\\partial \\vec{v}}{\\partial\\tensor[_W]{\\vec{p}}{_C}} &= \n%\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}I\n%-\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}^3} (\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L})(\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L})^T\\notag\\\\\n%&=\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n%\\left( \n%I - \\frac{(\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L})(\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L})^T}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}^2}\n%\\right)\\\\\n%&=\n\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\end{align}\n\\subsubsection{Derivative of camera position w.r.t to $T_{BW}$}\n\\begin{align}\n\\tensor[_W]{\\vec{p}}{_C} &= -\\Exp(-\\vecs{\\delta\\phi}) C_{WB} \\left( C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \\left(\\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW} \\vecs{\\delta t}\\right)\\right)\\\\\n&\\approx -\\left[C_{WB} \\left( C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \\left(\\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW} \\vecs{\\delta t}\\right)\\right)\\right.\\\\\n&\\left.\\qquad-\\vecs{\\delta\\phi}^\\wedge C_{WB} \\left( C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \\left(\\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW} \\vecs{\\delta t}\\right)\\right)\\right]\\\\\n&\\approx -C_{WB} \\left( C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \\left(\\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW} \\vecs{\\delta t}\\right)\\right)\\\\\n&\\qquad+\\vecs{\\delta\\phi}^\\wedge C_{WB} \\left( C_{BC} \\tensor[_C]{\\vec{t}}{_{CB}} + \\left(\\tensor[_B]{\\vec{t}}{_{BW}} + C_{BW} \\vecs{\\delta t}\\right)\\right)\\\\\n%\n&\\approx -(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}} + \\vecs{\\delta t})\n+ \\vecs{\\delta\\phi}^\\wedge\\left(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}} + \\vecs{\\delta t}\\right)\\\\\n&\\approx -(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}} + \\vecs{\\delta t})\n- \\left(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}} + \\vecs{\\delta t}\\right)^\\wedge\\vecs{\\delta\\phi}\\\\\n%\n%&\\approx-\\left(\\tensor[_W]{\\vec{t}}{_{CB}}+\\tensor[_W]{\\vec{t}}{_{CB}^\\wedge}\\vecs{\\delta\\phi}\\right) - \\left(\\tensor[_W]{\\vec{t}}{_{BW}} + \\vecs{\\delta t} + \\tensor[_W]{\\vec{t}}{_{BW}^\\wedge}\\vecs{\\delta\\phi} +\\vecs{\\delta t}^\\wedge\\vecs{\\delta\\phi}\\right)\n\\end{align}\n\\begin{align}\n\\frac{\\partial\\tensor[_W]{\\vec{p}}{_C}}{\\partial\\vecs{\\delta\\phi}} &= -(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}})^\\wedge\\\\\n\\frac{\\partial\\tensor[_W]{\\vec{p}}{_C}}{\\partial\\vecs{\\delta t}} &= -I\n\\end{align}\n\\subsubsection{Full jacobian}\n\\begin{align}\n\\frac{\\partial\\varepsilon_2}{\\partial\\vecs{\\delta\\phi}} &= \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\frac{\\partial \\vec{v}}{\\partial\\vecs{\\delta\\phi}} - \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\vec{v}^\\wedge\\\\\n&= \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\frac{\\partial \\vec{v}}{\\partial\\tensor[_W]{\\vec{p}}{_C}} \n\\frac{\\partial \\tensor[_W]{\\vec{p}}{_{C}}}{\\partial \\vecs{\\delta\\phi}}\n - \\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\vec{v}^\\wedge\\\\\n&= \\tensor[_W]{\\tilde{\\vec{n}}}{^T}\n\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\frac{\\partial \\tensor[_W]{\\vec{p}}{_{C}}}{\\partial \\vecs{\\delta\\phi}}\n - \\tensor[_W]{\\tilde{\\vec{n}}}{^T} \\vec{v}^\\wedge\\\\\n &= \\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\\tensor[_W]{\\tilde{\\vec{n}}}{^T}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\left(-(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}})^\\wedge\\right)\n - \\tensor[_W]{\\tilde{\\vec{n}}}{^T} \\vec{v}^\\wedge\\\\\n &=\\frac{-1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\\tensor[_W]{\\tilde{\\vec{n}}}{^T}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\left(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}}\\right)^\\wedge\n - \\tensor[_W]{\\tilde{\\vec{n}}}{^T} \\vec{v}^\\wedge\\\\\n&=-\\tensor[_W]{\\tilde{\\vec{n}}}{^T}\\left(\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\left(\\tensor[_W]{\\vec{t}}{_{CB}} + \\tensor[_W]{\\vec{t}}{_{BW}}\\right)^\\wedge + \\vec{v}^\\wedge\\right)\n\\end{align}\n\\begin{align}\n\\frac{\\partial\\varepsilon_2}{\\partial\\vecs{\\delta t}} &= \n\\tensor[_C]{\\tilde{\\vec{n}}}{^T} C_{CB} C_{BW}\\frac{\\partial\\vec{v}}{\\partial \\vecs{\\delta t}}\\\\\n&= \n\\tensor[_W]{\\tilde{\\vec{n}}}{^T} \n\\frac{\\partial \\vec{v}}{\\partial\\tensor[_W]{\\vec{p}}{_C}}\n\\frac{\\partial \\tensor[_W]{\\vec{p}}{_C}}{\\partial \\vecs{\\delta t}}\\\\\n&=\n\\tensor[_W]{\\tilde{\\vec{n}}}{^T} \n\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\frac{\\partial \\tensor[_W]{\\vec{p}}{_C}}{\\partial \\vecs{\\delta t}}\\\\\n&=\n\\frac{1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\tensor[_W]{\\tilde{\\vec{n}}}{^T}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n(-I)\\\\\n&=\\frac{-1}{\\norm{\\tensor[_W]{\\vec{p}}{_C} - \\tensor[_W]{\\vec{p}}{_L}}}\n\\tensor[_W]{\\tilde{\\vec{n}}}{^T}\n\\left(\nI - \\vec{v}\\vec{v}^T\n\\right)\n\\end{align}\n\n\\nocite{*}\n\\bibliographystyle{IEEEtran}\n\\bibliography{bibliography_lines}\n\n\\end{document}", "meta": {"hexsha": "dfed8a38c9f9d150475f3997f2a6f36c4b71ee03", "size": 10589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ze_geometry/doc/line_parametrization.tex", "max_stars_repo_name": "rockenbf/ze_oss", "max_stars_repo_head_hexsha": "ee04158e2d51acb07a267196f618e9afbc3ffd83", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2016-09-27T07:41:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-03T20:44:28.000Z", "max_issues_repo_path": "ze_geometry/doc/line_parametrization.tex", "max_issues_repo_name": "rockenbf/ze_oss", "max_issues_repo_head_hexsha": "ee04158e2d51acb07a267196f618e9afbc3ffd83", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-18T15:53:06.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-21T03:10:06.000Z", "max_forks_repo_path": "ze_geometry/doc/line_parametrization.tex", "max_forks_repo_name": "rockenbf/ze_oss", "max_forks_repo_head_hexsha": "ee04158e2d51acb07a267196f618e9afbc3ffd83", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-11-05T07:51:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T02:26:08.000Z", "avg_line_length": 53.7512690355, "max_line_length": 304, "alphanum_fraction": 0.6119558032, "num_tokens": 4516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7025300636233415, "lm_q1q2_score": 0.6078459395472787}}
{"text": "% !TEX root = ./main.tex\n\\section{General diffusion equation}\n\nOur introduction to diffusion theory begins with the derivation of the partial\ndifferential equation that defines the time evolution of the allele frequency\nprobability distribution $P(x, t)$. The approach we will consider here is a\ndiscretization of the otherwise continuous probability density function.\nFigure~\\ref{fig01:diffusion_basics}(B) depicts the idea behind this\ndiscretization where we divide the distributions into bins of some width $\\Delta\nx$. Since $P(x, t)$ is a \\textit{probability density function}, i.e., a\nprobability function for continuous random variables, evaluating this density\nfor any particular value of the allele frequency returns zero. Only intervals of\nthe form $P(x - \\delta x \\leq x \\leq x + \\delta x)$ have meaningful\nprobabilities. This is because $P(x, t)$ has units of inverse $x$ (in our case,\ninverse allele frequency), but probability has no dimensions. So by computing\nthe interval via an integration of the form\n\\begin{equation}\n    P(x - \\delta x \\leq x \\leq x + \\delta x) =\n    \\int_{x - \\delta x}^{x + \\delta x} dx \\; P(x, t),\n\\end{equation}\nwe multiply the density $P(x, t)$ (units of inverse allele frequency) with the\ninfinitesimal width $dx$ (units of allele frequency), recovering a dimensionless\nquantity. Our discretization of this distribution then takes the form\n\\begin{equation}\n    p(x, t) \\equiv P(x - \\frac{\\Delta x}{2} \\leq x \\leq x + \\frac{\\Delta x}{2}) \n    \\approx \\overbrace{P(x, t)}^{\\text{height}} \n    \\overbrace{\\Delta x}^{\\text{width}},\n\\label{eq:mass_vs_density}\n\\end{equation}\nwhere we define $p(x, t)$ to be a \\textit{probability mass function}, i.e., a\nprobability function for discrete random variables. What we are doing is\napproximating the integral as a rectangle of height $P(x, t)$ and a width $dx$.\nThe smaller $dx$ the more accurate our approximation gets.\n\nBefore jumping into the modeling of each of the individual evolutionary forces,\nwe will begin our analysis with an abstract transition probability that captures\nthe effect of all forces all together. This will allow us to gain intuition on\nhow to implement each of the particular forces in the following section. Let us\ndefine a probability transition rate $\\phi(x \\mid x')$. The way to think about\nthis function is that, by taking into account all evolutionary forces involved,\n$\\phi(x \\mid x')$ tells us what is the probability of transition from an allele\nfrequency $x'$ to a frequency $x$ per unit time. Given that $\\phi(x \\mid x')$ is\na rate (units of inverse time), we need to multiply is by a small window of time\n$\\Delta t$ in order to obtain a transition probability. For example, if we want\nto compute what is the probability of transitioning from an allele frequency $x$\nto an allele frequency $x + \\Delta x$ in a small time window $\\Delta t$, we must\ncompute\n\\begin{equation}\n    P_{\\text{transition}}(x \\rightarrow x + \\Delta x; \\Delta t) = \n    \\phi(x + \\Delta x \\mid x) \\Delta t.\n\\end{equation}\nWith this in hand let's focus our attention to a particular frequency value $x$.\nFigure~\\ref{fig01:diffusion_basics}(C) shows the checks and balances we need to\nconsider for this allele frequency. What the schematic shows is that in a small\ntime window $\\Delta t$ the ``amount of probability'' at $x$ can change due to\nthe outflow of probability mass from $x$ to the two contiguous bins $x + \\Delta\nx$ and $x - \\Delta x$, and due to the inflow from those same two bins. We are\nassuming that $\\Delta t$ is sufficiently small such that we only need to\nconsider transitions from the nearest neighbors. Writing down this check and\nbalance equation we obtain\n\\begin{equation}\n\\begin{split}\n    p(x, t + \\Delta t) &= p(x, t)\n    + \\overbrace{p(x - \\Delta x, t) \\phi(x \\mid x - \\Delta x)\\Delta t}\n    ^{\\text{inflow from the left}}\n    + \\overbrace{p(x + \\Delta x, t) \\phi(x \\mid x + \\Delta x)\\Delta t}\n    ^{\\text{inflow from the right}}\\\\\n    &- \\overbrace{p(x, t) \\phi(x - \\Delta x \\mid x) \\Delta t}\n    ^{\\text{outflow to the left}}\n    - \\overbrace{p(x, t) \\phi(x + \\Delta x \\mid x) \\Delta t}\n    ^{\\text{outflow to the right}}.\n\\end{split}\n\\label{eq:inflow_outflow_diffusion}\n\\end{equation}\nTo make further progress, we need to rewrite the transition probability in terms\nof the jump size $r \\equiv x - x'$. In other words, instead of defining the\nfunciton with the initial and final position, we define the function with the\ninitial position and the size of the displacement. This is\n\\begin{equation}\n    \\phi(x \\mid x') = \\phi(x'; r).\n\\end{equation}\nUsing this allows us to rewrite \\ref{eq:inflow_outflow_diffusion} as\n\\begin{equation}\n\\begin{split}\n    p(x, t + \\Delta t) = &p(x, t)\n    + p(x - \\Delta x, t) \\phi(x - \\Delta x; \\Delta x)\\Delta t\n    + p(x + \\Delta x, t) \\phi(x + \\Delta x; -\\Delta x)\\Delta t\\\\\n    &- p(x, t) \\phi(x; -\\Delta x) \\Delta t\n    - p(x, t) \\phi(x; \\Delta x) \\Delta t.\n\\end{split}\n\\label{eq:jump_diffusion}\n\\end{equation}\nThis equation needs a few rearrangements. First we send the first term on the\nright hand side to the left, and divide both sides by $\\Delta t$. This results\nin\n\\begin{equation}\n\\begin{split}\n    \\frac{p(x, t + \\Delta t) - p(x, t)}{\\Delta t} &=\n    p(x - \\Delta x, t) \\phi(x - \\Delta x; -\\Delta x)\n    + p(x + \\Delta x, t) \\phi(x + \\Delta x; \\Delta x)\\\\\n    &- p(x, t) \\phi(x; -\\Delta x) \n    - p(x, t) \\phi(x; \\Delta x).\n\\end{split}\n\\end{equation}\nTaking the limit $\\Delta t \\rightarrow 0$ allows us to rewrite\n\\begin{equation}\n\\begin{split}\n    \\frac{d p(x, t)}{dt} &=\n    p(x - \\Delta x, t) \\phi(x - \\Delta x; -\\Delta x)\n    + p(x + \\Delta x, t) \\phi(x + \\Delta x; \\Delta x)\\\\\n    &- p(x, t) \\phi(x; -\\Delta x) \n    - p(x, t) \\phi(x; \\Delta x).\n\\end{split}\n\\label{eq:master_eq_jump}\n\\end{equation}\nThis equation that describes the time evolution of the probability mass function\nis usually called a master equation. As written right now,\nEq.~\\ref{eq:master_eq_jump} depends on the unknown function $\\phi(x; r)$ that\ninvolves the influence of all evolutionary forces. The next manipulation of the\nequation involves a Taylor expansion of the terms in Eq.~\\ref{eq:master_eq_jump}\ninvolving $x \\pm \\Delta x$ around $x$. As written right now we cannot Taylor\nexpand $p(x, t)$ since a probability mass function can only evaluated for the\n\\textit{discrete} values the random variable can take. It is at this point that\nwe use Eq.~\\ref{eq:mass_vs_density} to convert back to the probability density\nfunction. Substituting this in Eq.~\\ref{eq:master_eq_jump} doesn't have any\neffect given that the extra $\\Delta x$ term that comes along with converting\nfrom a mass to a density cancels from both sides, resulting in\n\\begin{equation}\n\\begin{split}\n    \\frac{d P(x, t)}{dt} &=\n    P(x - \\Delta x, t) \\phi(x - \\Delta x; -\\Delta x)\n    + P(x + \\Delta x, t) \\phi(x + \\Delta x; \\Delta x)\\\\\n    &- P(x, t) \\phi(x; -\\Delta x) \n    - P(x, t) \\phi(x; \\Delta x).\n\\end{split}\n\\label{eq:master_eq_density}\n\\end{equation}\nNow we can properly Taylor expand the terms involving $x \\pm \\Delta x$. This \nexpansion takes the form\n\\begin{equation}\n\\begin{split}\n    P(x \\pm \\Delta x, t) \\phi(x \\pm \\Delta x; \\mp \\Delta x) &\\approx\n    P(x, t)\\phi(x; \\mp \\Delta x)\\\\\n    &+ \\frac{d}{dx}\n    \\left[ P(x, t) \\phi(x; \\mp \\Delta x)  \\right] (\\pm \\Delta x)\\\\\n    &+ \\frac{1}{2} \\frac{d^2}{d x^2}\n    \\left[ P(x, t) \\phi(x; \\mp \\Delta x)  \\right] (\\pm \\Delta x)^2.\\\\\n\\end{split}\n\\label{eq:taylor_expand_jump}\n\\end{equation}\nSubstituting Eq.~\\ref{eq:taylor_expand_jump} into Eq.~\\ref{eq:master_eq_density}\nresults in\n\\begin{equation}\n\\begin{split}\n    \\frac{\\partial P(x, t)}{\\partial t} &=\n    P(x, t)\\phi(x; - \\Delta x)\\\\\n    &+ \\frac{\\partial}{\\partial x}\n    \\left[ P(x, t) \\phi(x; - \\Delta x)  \\right] (\\Delta x)\\\\\n    &+ \\frac{1}{2} \\frac{\\partial^2}{\\partial x^2}\n    \\left[ P(x, t) \\phi(x; - \\Delta x) \\right]   (\\Delta x)^2\\\\\n    &+ P(x, t) \\phi(x; \\Delta x)\\\\\n    &+ \\frac{\\partial}{\\partial x}\n    \\left[ P(x, t) \\phi(x; \\Delta x)  \\right] (- \\Delta x)\\\\\n    &+ \\frac{1}{2} \\frac{\\partial ^2}{\\partial x^2}\n    \\left[ P(x, t) \\phi(x; \\Delta x)  \\right] (- \\Delta x)^2\\\\\n    &- P(x, t) \\phi(x; -\\Delta x) \n    - P(x, t) \\phi(x; \\Delta x).\n\\end{split}\n\\end{equation}\nThis equation might look quite messy, but it can be enormously simplified by\ncancelling terms and using the fact that derivatives are linear operators. Doing\nso results in\n\\begin{equation}\n    \\frac{\\partial P(x, t)}{\\partial t} =\n    \\frac{\\partial}{\\partial x}\n    \\left[ P(x, t) \n    \\left(\\phi(x; - \\Delta x) - \\phi(x; \\Delta x) \\right) (\\Delta x) \n    \\right]\n    + \\frac{1}{2} \\frac{\\partial^2}{\\partial x^2}\n    \\left[ P(x, t)\n    \\left(\\phi(x; - \\Delta x) - \\phi(x; \\Delta x)\\right) (\\Delta x)^2 \\right].\n\\label{eq:PDE_diffusion}\n\\end{equation}\n\nLet's look at the terms involving the transition probability. The first term on\nthe right hand side of the equation involves a term $\\left(\\phi(x; - \\Delta x) -\n\\phi(x; \\Delta x) \\right) (\\Delta x)$. This is nothing else than the mean\ndisplacement. The way to see this is as follows: recall that in our discrete\napproach for sufficiently small $\\Delta t$ we only really have to consider the\nthree contiguous bins $x$ and $x \\pm \\Delta x$. To be consistent with the\nnotation in the population genetics literature, let us define $M(x)\\Delta t$ as\nthe mean change in allele frequency during a small time window $\\Delta t$. This\nis analogous to the definition of $\\phi(x \\mid x')$ in which only the product of\n$\\phi(x \\mid x')\\Delta t$ satisfies the dimensionless nature of probabilities.\nIn other words, we can think of $M(x)$ as the mean rate with which the allele\nfrequency changes. The mean change in allele frequency is then computed as\n\\begin{equation}\nM(x)\\Delta t = \\left\\langle \\Delta x \\mid x \\right\\rangle_{\\Delta x}\\Delta t,\n\\end{equation}\nwhere $\\langle \\cdot \\rangle_{\\Delta x}$ means to take the average over possible\njumps in allele frequency. What this equation says is that $M(x)\\Delta t$\nrepresents the expected shift in allele frequency on a small time window $\\Delta\nt$ given that the current allele frequency is $x$. Computing this average\ndisplacement for our discrete case has only three options: a jump of size\n$\\Delta x$, a jump of size $- \\Delta x$ and no jump. The average jump is then\ngiven by.\n\\begin{equation}\n    M(x)\\Delta t = \n    \\overbrace{(-\\Delta x) \\phi(x, - \\Delta x)\\Delta t}\n    ^{\\text{jump from $x$ to $x - \\Delta x$}}\n    + \\overbrace{(\\Delta x) \\phi(x, + \\Delta x)\\Delta t}\n    ^{\\text{jump from $x$ to $x _ \\Delta x$}}\n    + \\overbrace{(0) (1 - \\phi(x, + \\Delta x) - \\phi(x, - \\Delta x)\\Delta t}\n    ^{\\text{no jump}}\n\\label{eq:Mx}\n\\end{equation}\nFrom this we can easily see that\n\\begin{equation}\n    M(x) = \\left(\\phi(x; + \\Delta x) - \\phi(x; - \\Delta x) \\right) (\\Delta x).\n\\end{equation}\nNotice this the change in the order in the terms compared with the first term in\nEq.~\\ref{eq:PDE_diffusion}. This change of order will be carried as a minus sign\nin our final result. In the same way let us define $V(x)\\Delta t$ as the\nvariance in displacement during a small time window. This is written as\n\\begin{equation}\n    V(x)\\Delta t = \\left[\\langle (\\Delta x)^2 \\mid x \\rangle_{\\Delta x}\n    - \\left(\\langle \\Delta x \\mid x \\rangle_{\\Delta x}\\right)^2\\right]\\Delta t.\n\\end{equation}\nAs we showed in Eq.~\\ref{eq:Mx}, the mean displacement scales with $\\Delta x$.\nThis means that the second term on the right hand side of\nEq.~\\ref{eq:variance_displacement} scales with $(\\Delta x)^2$, which for very\nsmall $\\Delta x$ we will consider as negligible. With this simplification, the\nvariance in displacement during a small time window $\\Delta t$ is then simply\ngiven by\n\\begin{equation}\n    V(x)\\Delta t = \\langle (\\Delta x)^2 \\mid x \\rangle_{\\Delta x} \\Delta t.\n\\label{eq:variance_displacement}\n\\end{equation}\nThis can be computed again considering the three possible jumps as\n\\begin{equation}\n    V(x)\\Delta t = \n    \\overbrace{(\\Delta x)^2 \\phi(x; \\Delta x)\\Delta t}\n    ^{\\text{jump from $x$ to $x + \\Delta x$}}\n    + \\overbrace{(-\\Delta x)^2 \\phi(x; \\Delta x)\\Delta t}\n    ^{\\text{jump from $x$ to $x - \\Delta x$}}\n    + \\overbrace{(0)^2 (1 - \\phi(x, + \\Delta x) - \\phi(x, - \\Delta x)\\Delta t)\n    \\Delta t}\n    ^{\\text{no jump}}.\n\\end{equation}\nFrom this we can see that \n\\begin{equation}\n    V(x) = \\left(\\phi(x; + \\Delta x) - \\phi(x; - \\Delta x)\\right) (\\Delta x)^2.\n\\label{eq:Vx}\n\\end{equation}\nSubstituting Eqs.~\\ref{eq:Mx}~and~\\ref{eq:Vx} into Eq.~\\ref{eq:PDE_diffusion} \nresults in the diffusion-advection equation for allele frequency we were after\n\\begin{equation}\n    \\frac{\\partial P(x, t)}{\\partial t} = \n    - \\frac{\\partial}{\\partial x}\\left[ P(x, t) M(x) \\right]\n    + \\frac{1}{2}\\frac{\\partial^2}{\\partial x^2}\\left[ P(x, t) V(x) \\right].\n\\end{equation}\nThe reason for writing this general Fokker-Planck equation in terms of the mean\ndisplacement rate $M(x)$ and the variance in the displacement rate $V(x)$ is\nthat the evolutionary are assigned to each of these functions. As we will see in\nthe next section, selection and mutation, being deterministic evolutionary\nforces belong to the advection term, and therefore they define $M(x)$, while\ngenetic drift, a stochastic force, defines the term $V(x)$.", "meta": {"hexsha": "83c04303a92032cb3480af4c2db8178494bb6ec0", "size": 13218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/spread_the_butter/section_02_general_fokker_planck.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/spread_the_butter/section_02_general_fokker_planck.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/spread_the_butter/section_02_general_fokker_planck.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": 49.5056179775, "max_line_length": 80, "alphanum_fraction": 0.6832349826, "num_tokens": 4107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7025300698514777, "lm_q1q2_score": 0.6078459327285354}}
{"text": "\\section*{Exercise 26.2-9}\r\nWe are given two flows, $f$ and $f'$ and compute the augmented flow $f\\uparrow f'$.\r\n\r\n\\textbf{Does the augmented flow satisfy the flow conservation property?}\r\n\\\\\r\nYes!\r\n\\\\\r\n\\\\\r\nFor any vertice $u\\in V - \\left\\{s,t\\right\\}$, one of the following cases apply:\r\n\\\\\r\n\\textit{Neither $f$ nor $f'$ includes $u$.}\r\n\\\\\r\nThere is no flow, so $f(u,v)=f(v,u)$, where $v\\in V$.\r\n\\\\\r\n\\\\\r\n\\textit{$f$ and/or $f'$ includes $u$.}\r\n\\\\\r\nIt is given, that $f$ and $f'$ are ordinary flows, so the flow conservation property must hold for each of these; all flow into a vertice will also flow out. Regardless of whether $u$ is included in one or two flows, all flow into $u$ will also come out.\r\n\\\\\r\n\\\\\r\n\\textbf{Does the augmented flow satisfy the capacity constraint?}\r\n\\\\\r\nNo!\r\n\\\\\r\n\\\\\r\nConsider the following case:\r\n\\\\\r\nThe edge $(u,v)$ has capacity $c(u,v)=2$. The edge $(u,v)$ is part of both flows $f$ and $f'$, where $f(u,v)=2$ and $f'(u,v)=2$.\r\n\\\\\r\nHence, $f(u,v)+f'(u,v)=2+2=4>c(u,v)$.", "meta": {"hexsha": "d8ec046086326135266b36ea56b244060cef52dd", "size": 1002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/26.2-9.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": "Uge1/26.2-9.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": "Uge1/26.2-9.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": 33.4, "max_line_length": 255, "alphanum_fraction": 0.6317365269, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.607845924392564}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{November 5, 2014}\n\\maketitle\n\\section*{4.2 2a,8,9}\n\\subsection*{9}\nshow that the remainder when $f(x)$ is divided by $(x-a)^2$ is $f'(a)(x-a)+f(a)$\n\n$f(x)=(x-a)^2q(x)+r(x)$ and $\\deg r<2$ $r(x)=\\alpha x+\\beta$.\n$f(a)=r(a)=\\alpha a+\\beta$.\n$f'(x)=2(x-a)q(x)+(x-a)^2q'(x)+\\alpha$\n$f'(a)=\\alpha$\n\n$f(a)=f'(a)a+\\beta\\to\\beta=f(a)-af'(a)$.o\n\n$r(x)=f'(a)x+f(a)-af'(a)=f'(a)(x-a)+f(a)$\n\\section*{proposition}\nlet$I\\subseteq K[x]$ such that\n\\begin{enumerate}\n\\item\n$I$ contains a non-zero polynomial\n\\item\n$f(x),g(x)\\in I\\Rightarrow f(x)+g(x)\\in I$\n\\item\n$f(x)\\in I, g(x)\\in K[x]\\Rightarrow f(x)g(x)\\in I$\n\\end{enumerate}\nthis is the ideal of $K[x]$\nlet $d(x)\\in I$ of minimal degree. then $I=\\{a(x)f(x):f(x)\\in K[x]\\}$\n\n\\subsubsection*{proof}\nlet $h(x)\\in I$ write $h(x)=d(x)q(x)+r(x)$ with $r(x)=0$ or $\\deg r>\\deg d$\n\nthen $r(x)=h(x)+d(x)[-q(x)]\\in I$ by 2 above. by choice of $d(x)$ we have $r(x)=0$ and so $h(x)\\in I$\n\n\n\\section*{def}\n$f(x),g(x)\\in K[x]$ where $K$ is a field. a monic polynomial $a(x)\\in K[x]$ is called gcd of $f(x),g(x)$ if\n\\begin{enumerate}\n\\item\n$a(x)|f(x)$ and $a(x)|g(x)$\n\\item\nif $t(x)|f(x)$ and $t(x)|g(x)$ then $t(x)|a(x)$\n\\end{enumerate}\n\nmonic means that the leading coefficient is 1\n\n\n\\section*{thm}\nif we have $f(x),g(x)$ non-zero, then $\\exists\\gcd(f(x),g(x))$ and $\\gcd(f(x),g(x))$ can be expressed in the form $\\alpha(x)f(x)+\\beta(x)g(x)$.\n\\subsubsection*{proof}\n\nlet ideal $I=\\{\\alpha(x)f(x)+\\beta(x)g(x)\\}$. Check that $I$ satisfies all conditions of earlier proposition.\n\nlet $d(x)\\in I$ of minimal degree and without loss of generality assume $d(x)$ is monic. we can do this because multiplying by a constant is multiplying by a polynomial, so it's still in $I$.\n\nclaim $d(x)$ is a $\\gcd$ of $f(x),g(x)$\n\n$I=\\{d(x)h(x):h(x)\\in K[x]\\}$ in particular $d(x)f(x)$ and $d(x)g(x)$ are both in $I$. now if $t(x)|f(x)$ and $t(x)|g(x)$. $\\exists\\alpha(x),\\beta(x)$ such that $d(x)=\\alpha(x)f(x)+\\beta(x)g(x)$. then $t(x)|d(x)$. \n\n\\section*{thm}\nthe gcd is unique. lets assume that $d_1(x)$ and $d_2(x)$ are gcd of $f(x)$ and $g(x)$. $d_2(x)|f(x)$ and $d_2(x)|g(x)$. $d_1$ is gcd so $d_1|d_2$ and $d_1(x)|f(x)$ and $d_1(x)|g(x)$ so because $d_2$ is gcd then $d_2|d_1$. we said our gcd was monic.\n\n$d_1(x)=d_2(x)\\alpha_1(x)$ and $d_2(x)=d_1(x)\\alpha_2(x)$. now $d_1(x)\\alpha_1(x)\\alpha_2(x)\\to d_2=d_1(x)\\alpha_1(x)\\alpha_2(x)$\n\n\\section*{thm}\nif $p(x)|f(x)g(x)$ and $\\gcd(p(x),f(x))=1$ then $p(x)|g(x)$.\n\n\\section*{def}\n$f(x)\\in K[x]$. we say that $f(x)$ is irreducible over the field $K$ if $f(x)$ cannot be factored into a product of two polynomials of degree lower than $\\deg f(x)$.\n\\subsection*{example}\n$x^2+1$ is irreducible over $\\mathbb{R}$\n\\subsection*{example}\n$x^2+1\\in \\mathbb{C}[x]$ is reducible (not irreducible) over $\\mathbb{C}$\n\n\\section*{prop}\n$f(x)\\in K[x]$, $\\deg f(x)$ is $2$ or $3$ and $f(x)$ has no roots in $K$. then $f(x)$ is irreducible.\n\n\\subsubsection*{proof}\nwe choose $\\deg 2,3$ because at least one of the factors is $\\deg 1$\n\nwe assume the factors exist. then $f(x)=(\\alpha x+\\beta)h(x)$ and $f(-\\beta\\alpha^{-1})=0$ and it has a root.\n\n\\section*{thm}\nevery non-zero polynomial in  $K[x]$ can be written uniquely as a product of irreducible polynomials.\n\nproof is inductive argument\n\n\\section*{def}\n$f(x)\\in K[x], c\\in K$ we say that $c$ is a root of multiplicity $m$ of $f(x)$ if $(x-c)^m$ divides $f(x)$ and $(x-c)^{m+1}\\not| f(x)$\n\n\\section*{prop}\n$f(x)\\in \\mathbb{R}[x]$, $\\deg f(x)\\ge 1$ then $f(x)$ has no repeatable factors iff the $gcd$ of $f(x)$ and $f'(x)$ is one\n\\end{document}\n\n\n", "meta": {"hexsha": "150b6f6ff35eb399d0624f9fd13bd258b10eca42", "size": 3780, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "abstract algebra/abstract-notes-2014-11-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": "abstract algebra/abstract-notes-2014-11-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": "abstract algebra/abstract-notes-2014-11-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": 35.6603773585, "max_line_length": 249, "alphanum_fraction": 0.619047619, "num_tokens": 1498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6077588419676578}}
{"text": "\\section{Updates 12/16/2019}%\n\\label{sec:updates2019_12_16}\nAll of the following results were trained using Horovod on COOLEY for\n$1\\times10^5$ training steps ($2\\times$  previous training length).\n%\n\nAs a measure of how well the trained sampler performs, we can introduce the\n\\emph{tunneling rate} ($\\gamma$), as\n%\n\\begin{equation}\n  \\gamma = \\frac{1}{M}\\sum_{m=1}^{M} |\\mathcal{Q}^{(m+1)} - \\mathcal{Q}^{(m)}|\n\\end{equation}\n%\nwhere $\\mathcal{Q} \\in \\mathbb{Z}$ is the topological charge, and $M$ denotes\nthe number of accept/reject steps the sampler was ran for.\n%\nThis tells us the amount by which we can expect the topological charge to\nchange per step, and is a useful metric for measuring how well the sampler is\nable to explore different topological sectors.\n%\n", "meta": {"hexsha": "bef45a4f9252b16bb9d1e30fbbdd1a4de35a70a1", "size": 769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/updates/updates_2019_12_16.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/updates/updates_2019_12_16.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/updates/updates_2019_12_16.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": 36.619047619, "max_line_length": 78, "alphanum_fraction": 0.7347204161, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6077588404032124}}
{"text": "\\section{A plethora of products}\n\\begin{remark}\nPlease note that these notes might be absolute bullshit, because I came back today from my flight at 8 am.\n\\end{remark}\nRecall that we have the Kronecker pairing $\\langle ,\\rangle: H^p(X)\\otimes H_p(X)\\to R$, which obviously isn't natural because $ H^p$ is contravariant while homology isn't.\n\nConsider the following. Given $f:X\\to Y$, and $b\\in H^p(Y)$ and $x\\in H_p(X)$, how does $\\langle f^\\ast b,x\\rangle$ relate to $\\langle b,f_\\ast x\\rangle$?\n\\begin{claim}\n$$\\langle f^\\ast b,x\\rangle=\\langle b,f_\\ast x\\rangle$$\n\\end{claim}\n\\begin{proof}\nEasy! I find it useful to write out diagrams of where things are. We're gonna work on the chain model.\n\\begin{equation*}\n\t\\xymatrix{\n\t\\Hom(S_p(X),R)\\otimes S_p(X)\\ar[r]^{\\langle,\\rangle} & R\\\\\n\t\\Hom(S_p(Y),R)\\otimes S_p(X)\\ar[r]^{1\\otimes f_\\ast}\\ar[u]^{f^\\ast\\otimes 1} & \\Hom(S_p(Y),R)\\otimes S_p(Y)\\ar[u]^{\\langle,\\rangle}\n\t}\n\\end{equation*}\nThe top line is what gives the Kronecker pairing. Note that $f^\\ast$ means contravariant and $f_\\ast$ means covariant. This diagram commuting \\emph{is} the statement we want to prove. Let's see. Suppose $[\\beta]=b$ and $[\\xi]=x$. Then from the bottom left, going to the right and then the top is $\\beta\\otimes\\xi\\mapsto\\beta\\otimes f_\\ast(\\xi)\\mapsto\\beta(f_\\ast\\xi)$. The other way is $\\beta\\otimes\\xi\\mapsto f^\\ast(\\beta)\\otimes\\xi=(\\beta\\circ f)\\otimes\\xi\\mapsto(\\beta\\circ f)(\\xi)$. This is exactly $\\beta(f_\\ast\\xi)$, because, oh, that's just how composition works.\n\\end{proof}\nThere's another product around. We called this $\\mu$ I think, where $\\mu:H(C_\\bullet)\\otimes H(D_\\bullet)\\to H(C_\\bullet\\otimes D_\\bullet)$ given by $[c]\\otimes [d]\\mapsto[c\\otimes d]$. I'm secretly using this in the above proof.\n\nWe also have the cross product(s!) $\\times: H_p(X)\\otimes H_q(Y)\\to H_{p+q}(X\\times Y)$ and $\\times: H^p(X)\\otimes H^q(Y)\\to H^{p+q}(X\\times Y)$. You should think of this as fishy because both maps are in the same direction -- but this is OK because we're using different things to make these constructions. Still, they're related:\n\\begin{theorem}\nLet $a\\in H^p(X),b\\in H^p(Y),x\\in H_p(X), y\\in H_q(Y)$. Then:\n\\begin{equation*}\n\\langle a\\times b,x\\times y\\rangle=(-1)^{|x|\\cdot |b|}\\langle a,x\\rangle\\langle b,y\\rangle\n\\end{equation*}\n\\end{theorem}\nThis isn't just idle -- although idle things are a great thing to do!\n\\begin{proof}\nSay $[\\alpha]=a,[\\beta]=b,[\\xi]=x,[\\eta]=y$. Then recall that $\\langle a\\times b,x\\times y\\rangle$ comes from $(\\alpha\\times\\beta)(\\sigma)=(-1)^{pq}\\alpha(\\sigma_1\\circ\\alpha_p)\\beta(\\sigma_2\\circ\\omega_q)$ where $\\sigma:\\Delta^{p+q}\\to X\\times Y$. There's two uses of the symbol $\\alpha$, and there'll be a third one in a minute, but they'll all have subscripts, so I hope you'll forgive me.\n\nRecall also the ($(p,q)$th component of the) Alexander-Whitney map $\\alpha_{X,Y}:S_{p+q}(X\\times Y)\\to S_p(X)\\otimes S_q(Y)$. We have a big diagram:\n\\begin{equation*}\n\\xymatrix{\n\tS_p(X)\\otimes S_q(Y)\\ar[r]^{\\times}\\ar[dr]^{1\\sim} & S_{p+q}(X\\times Y)\\ar[d]^{\\alpha_{X,Y}}\\ar[dr]^{\\alpha\\times\\beta} & \\\\\n\t& S_p(X)\\otimes S_p(Y)\\ar[r]_{\\alpha\\cdot\\beta} & R\n}\n\\end{equation*}\nWhere $\\alpha\\cdot\\beta:(\\xi\\otimes\\eta)\\mapsto(-1)^{pq}\\alpha(\\xi)\\cdot\\beta(\\xi)$. Now, the diagonal arrow $S_p(X)\\otimes S_q(Y)\\to S_p(X)\\otimes S_p(Y)$ is unique up to chain homotopy, and is homotopic to the identity -- this is what the method of acyclic models tells me. (See the statement of the Eilenberg-Zilber theorem above.)\n\nThus we find that $\\alpha_{X,Y}(\\xi\\times\\eta)=\\xi\\otimes\\eta+(dh+hd)(\\xi\\otimes\\eta)$ for some chain homotopy $h$. I think we're really down now, because $\\xi$ and $\\eta$ are both cycles, and hence $d$ will kill them (wait it seems like it only kills $\\eta$???). So $\\alpha_{X,Y}(\\xi\\times\\eta)=\\xi\\otimes\\eta$. Now, $\\alpha\\cdot\\beta$ is a cocycle (check!). When I apply $\\alpha$ it kills the $dh$ factor (what???), therefore $(\\alpha\\cdot\\beta)\\alpha_{X,Y}(\\xi\\times \\eta)=(\\alpha\\cdot\\beta)(\\xi\\otimes\\eta)$.\n\\end{proof}\nAll because of the magic of acyclic models.\n\nLet's now try to prove a K\\\"unneth theorem for $ H^\\ast$. Let $R=k$ be a field (eg $\\FF_p,\\QQ$) that's our coefficient. Then we have $ H_\\ast(X)\\otimes_k H_\\ast(Y)\\cong H_\\ast(X\\times Y)$. Also, this map $ H^p(X)\\otimes H_p(X)\\to k$ has an adjoint $ H^p(X)\\to \\Hom_k( H_p(X),k)=: H_p(X)^\\vee$, which is an isomorphism because $\\Ext$ vanishes over a field.\n\\begin{theorem}\nLet $k$ be a field. Assume that $ H_p(X)$ is finite-dimensional for all $p$. Then $ H^\\ast(X)\\otimes H^\\ast(Y)\\cong H^\\ast(X\\times Y)$.\n\\end{theorem}\n\\begin{proof}\nWe have:\n\\begin{equation*}\n\\xymatrix{\n\t H^\\ast(X)\\otimes H^\\ast(Y)\\ar[r]^{\\times}\\ar[d]^\\cong & H^\\ast(X\\times Y)\\ar[d]^\\cong\\\\\n\t H_\\ast(X)\\otimes H_\\ast(Y)^\\vee\\ar[d]^{\\zeta} & H_\\ast(X\\times Y)^\\vee\\ar[dl]^\\cong\\\\\n\t\\left( H_\\ast(X)\\otimes H_\\ast(Y)\\right)^\\vee\n}\n\\end{equation*}\nWhere $\\zeta:\\alpha\\otimes\\beta\\mapsto(x\\otimes y\\mapsto \\pm\\alpha(x)\\beta(y))$. The theorem we proved above implies that this diagram commutes.\n\nIn general, I might have two (graded) vector spaces $U,V$, and consider $U^\\vee\\otimes V^\\vee\\to(U\\otimes V)^\\vee$ by the above formula. Well, $(U\\otimes V)^\\vee=\\Hom_k(U\\otimes V,k)=\\Hom_k(U,V^\\vee)$. Thus I get a map $U^\\vee\\otimes V^\\vee\\to\\Hom_k(U,V^\\vee)$. This map is an isomorphism when $U$ or $V$ is finite dimensional. I also have $\\widehat{\\alpha}:U^\\vee\\otimes W\\to \\Hom(U,W)$ via $\\alpha\\otimes w\\mapsto(w\\mapsto\\alpha(u)w)$. And that's the map we have in mind. The image of $\\widehat{\\alpha}$ consists of finite rank homomorphisms because a general tensor is a finite sum. This is therefore an isomorphism if $U$ or $W$ is finite dimensional. \n\nThis shows that the map $\\zeta$ above is an isomorphism if $ H_\\ast(X)$ or $ H_\\ast(Y)$ is finite-dimensional. We're done by commutativity.\n\\end{proof}\nWe saw before that $\\times$ is an algebra map! So this is an isomorphism of algebras.\n\nThere are more products around. There is a map $ H^p(Y)\\otimes H^q(X,A)\\to H^{p+q}(Y\\times X,Y\\times A)$. Constructing this is on your homework. You can see how this comes about. This comes from the map on the chain level, and it comes from looking at the cochains, and you're going to get a map (???). Anyway. Suppose $Y=X$. Then I get $\\cup: H^\\ast(X)\\otimes H^\\ast(X,A)\\to H^\\ast(X\\times X,X\\times A)\\xrightarrow{\\Delta^\\ast} H^\\ast(X,A)$ where $\\Delta:(X,A)\\to (X\\times X,X\\times A)$. This ``relative cup product'' makes $ H^\\ast(X,A)$ into a graded module over $ H^\\ast(X)$. This is \\emph{not} a ring -- it doesn't have a unit, for example -- but it is a module. Also the lexseq is a sequence of $ H^\\ast(X)$-modules. I'm just making statements here.\n\nI want to introduce you to \\emph{one more} product, which we'll talk more about, and forms the foundation of Poincar\\'{e} duality. This is the cap product. What can I do with $S^p(X)\\otimes S^n(X)$? Well, I get big map:\n\\begin{equation*}\nS^p(X)\\otimes S_n(X)\\xrightarrow{1\\times (\\alpha_{X,X}\\circ \\Delta_\\ast)} S^p(X)\\otimes S_p(X)\\otimes S_{n-p}(X)\\xrightarrow{\\langle -,-\\rangle\\otimes 1}S_{n-p}(X)\n\\end{equation*}\nThis composite participates in a chain map. This induces a map in homology $\\cap: H^p(X)\\otimes H_n(X)\\to H_{n-p}(X)$ that comes from $\\mu$. This is a pretty interesting map.\n\\begin{lemma}\n$(\\alpha\\cup\\beta)\\cap x=\\alpha\\cap(\\beta\\cap x)$ and $1\\cap x=x$.\n\\end{lemma}\n\\begin{proof}\nEasy to check from the definition.\n\\end{proof}\nThis makes $ H_\\ast(X)$ into a module over $ H^\\ast(X)$. These are not hard things to check. There's a lot of structure, and the fact that $ H^\\ast(X)$ forms an algebra is a good thing. Notice how the dimensions work. People made a mistake before, and they should have indexed cohomology with negative numbers, so that $\\cap: H^p(X)\\otimes H_n(X)\\to H_{n-p}(X)$ makes sense. A cochain complex with positive grading is the same as a chain complex with negative grading.\n\nThere's also slant products (two of them!). Maybe we won't talk about them. We will check a few things about cap products, and then we'll go into Poincar\\'{e} duality. We can prove nice theorems then.\n", "meta": {"hexsha": "048fa25b4f38265f054162a49633980b71753e72", "size": 8095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-31-plethora-of-products.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-31-plethora-of-products.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-31-plethora-of-products.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": 96.369047619, "max_line_length": 755, "alphanum_fraction": 0.6938851143, "num_tokens": 2728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799253, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.607758826104091}}
{"text": "\\chapter{Idealized rates and instruments}\n\\label{chap:instuments}\n\n\\added[comment={Added}]{In this chapter we review idealized versions of interest rates and derivatives of interest rates. By idealized, we mean that the instruments are simplied for analytical purposes. For example, there is no lag between trade and spot date or expiry and delivery date. Neither we do not use funding rate that is separate form the market rates. The treatment is standard and is based mainly on} \\textcite[pp. 1--22]{brigo2007interest} unless otherwise noted.\n\nIn the following, we assume that $0 < t < T$ are points of time and $\\dayc(t,T) \\in [ 0, \\infty )$ is the day count convention between the points $t$ and $T$. We explicitly assume that $\\dayc(t,T) \\approx T-t$ when $t \\approx T$.\n\n\\section{Fundamental rates and instruments}\n\n\\subsection{Short-rate, idealized bank account and stochastic discount factor}\n\nWhen making calculations with idealized bank account, it is customary to assume that the day count-convention $\\dayc(t,T) = T-t$ as this will simplify the notation. An idealized bank account is an instrument with the value\n\\begin{align}\n\\Bank(t) = \\exp \\left( \\int\\limits_0^t r(s) \\dx s \\right)\n\\end{align}\nwhere $r(t)$ is the short-rate rate. The short-rate $r(t)$ may be non-deterministic but we assume that it is smooth enough so that the integral can be defined in some useful sense. We note that $\\Bank(0)=1$. If $\\delta > 0$ is very small and $r(t)$ is a smooth function, then \n\\begin{align}\n\\int\\limits_t^{t+\\delta} r(s) \\dx s \\approx r(t) \\delta\n\\end{align}\nand we see that the first-order expansion of exponential function yields\n\\begin{align}\n\\Bank(t+\\delta) \\approx \\Bank(t) ( 1+r(t) \\delta ) .\n\\end{align}\nThus the short-rate can be seen as continuous interest rate intensity. Short-rate is purely theoretical construction which can be used to price financial instruments. \n\nNow we may define a stochastic discount factor $\\DF(t,T)$ from time $t$ to $T$ as\n\\begin{align}\n\\DF(t,T) = \\frac{\\Bank(t)}{\\Bank(T)} = \\exp \\left( - \\int\\limits_t^T r(s) \\dx s \\right) .\n\\end{align}\nIf $r(t)$ is a random variable, then $\\Bank(t)$ and $\\DF(t,T)$ are stochastic too.\n\n\n\n\\subsection{Zero-coupon bond}\n\nA promise to pay one unit of currency at time $T$ is called a $T$-bond. We shall assume that there is no credit risk for these bonds. We further assume that the market is liquid and bond may be freely bought and sold at the same price, furthermore short selling is allowed without limits or extra fees. The price of this bond at time $t$ is denoted by $\\Bond(t,T)$ and so $\\Bond(t,T) > 0$ and $\\Bond(T,T) = 1$.  \n\nAs $\\DF(0,t)$ is guaranteed to pay one unit of currency at the time $t$, we see that in this case $\\DF(0,t) = \\Bond(0,t)$. We note that if the short-rate $r(t)$ is deterministic, then\n\\begin{align}\n\\DF(0,t) = \\frac{1}{\\Bank(t)}\n\\end{align}\nis deterministic too.  We see that if short-rate $r(t)$ is deterministic, then $\\DF(t,T) = \\Bond(t,T)$ for all $0 \\leq t \\leq T$. But this does not hold if $r(t)$ is truly stochastic.\n\n\\subsection{Simple spot $\\Rflt(t,T)$ and $k$-times compounded simple spot rate}\n\nThe simple spot rate $\\Rflt(t,T)$ is defined by\n\t\\begin{align}\n\t\t\\Rflt(t,T) = \\frac{1 - \\Bond(t,T)}{\\dayc(t,T)\\Bond(t,T)} ,\n\t\\end{align}\nwhich is equivalent to \n\t\\begin{align}\n\t\t\\label{discountandrate}\n\t\t1 + \\dayc(t,T) \\Rflt(t,T) = \\frac{1}{\\Bond(t,T)} .\n\t\\end{align}\n\t\nFor $k \\geq 1$, the $k$-times compounded interest rate from $t$ to $T$ is\n\\begin{align}\n\\Rflt^k(t,T) = \\frac{k}{\\Bond(t,T)^{\\frac{1}{k \\dayc(t,T)}}} - k,\n\\end{align}\nwhich is equivalent to \n\\begin{align}\n\\Bond(t,T) \\left( 1 + \\frac{\\Rflt^k(t,T)}{k} \\right)^{k \\dayc(t,T)} = 1 .\n\\end{align}\nAs\n\\begin{align}\n(1 + \\frac{x}{k})^k \\longrightarrow \\e^x\n\\end{align}\nwhen $k \\longrightarrow \\infty$, then\n\\begin{align}\n\\left( 1 + \\frac{L^k(t,T)}{k} \\right)^{k\\dayc(t,T)} \\longrightarrow \\e^{\\dayc(t,T)r(t,T)} ,\n\\end{align}\nwhere $\\Rflt^k(t,T) \\longrightarrow r(t,T)$ when $k \\longrightarrow \\infty$. \n\n\\subsection{Forward rate agreement}\n\nA forward rate agreement (FRA) is a contract that pays\n\\begin{align}\n\\dayc_K(t,T) K - \\dayc(t,T) \\Rflt(t,T)\n\\end{align}\nat the time $T$. Here we assume that the contact is made at the present time $0$ and $0 < t < T$, but this assumption is made just to keep the notation simplier. Here $K$ is an interest rate that is fixed at time $0$, $\\dayc_K$ is the day count convention for the this fixed rate and $\\Rflt(t,T)$ is the spot rate from time $t$ to $T$ (which might not be know at the present). The price of a FRA at the time $s \\leq t$ is denoted by $\\FRA(s,t,T,K)$. Now\n\\begin{align}\n\\FRA(t,t,T,K) = \\Bond(t,T) \\left( \\dayc_K(t,T) K - \\dayc(t,T) \\Rflt(t,T) \\right) .\n\\end{align}\n\nIn order to price a FRA at different times, we consider a portfolio of one long $T$-bond and $x$ short $t$-bonds. The value of this portfolio at the present is $V(0) = \\Bond(0,T) - x \\Bond(0,t)$ and we note that the portfolio has zero value if\n\\begin{align}\n\\label{FRAzeroprice}\nx = \\frac{\\Bond(0,T)}{\\Bond(0,t)}.\n\\end{align}\n\nAt the time $t$, the portfolio has value\n\\begin{align}\nV(t) &= \\Bond(t,T) - x \\\\\n&= \\Bond(t,T) \\left( 1 - \\frac{x}{\\Bond(t,T)} \\right)\n\\end{align}\nwhere $\\Bond(t,T)$ is known and\n\\begin{align}\n1 + \\dayc(t,T) \\Rflt(t,T) = \\frac{1}{\\Bond(t,T)} = y(t,T).\n\\end{align}\t\nWe define $K^*(x) = x^{-1}$. Thus\n\\begin{align}\n1 - \\frac{x}{\\Bond(t,T)} &= x \\left( \\frac{1}{x} - \\frac{1}{\\Bond(t,T)} \\right) \\\\\n&= x \\left( K^*(x) -  y(t,T)  \\right) \n\\end{align}\nand this implies that\n\\begin{align}\n\\label{forwardpricelemmaquation}\nV(t) &= x \\Bond(t,T) \\left( K^*(x) - y(t,T) \\right) .\n\\end{align}\nWithout arbitrage\n\\begin{align}\n\\label{forwardpricelemmaquation1}\nV(T) &= x \\left( K^*(x) - y(t,T) \\right) \\\\\n&= x \\left( K^*(x) - 1 - \\dayc(t,T) \\Rflt(t,T) \\right)\n\\end{align}\nWe note that at the time $0$, $K^*(x)$ is a known yield but $y(t,T)$ is an unknown yield if $\\Bond(t,T)$ is not deterministic. Now if\n\\begin{align}\nK &= \\frac{1}{\\dayc_K(t,T)} \\left( K^*(x) - 1 \\right) \\\\\n&= \\frac{1}{\\dayc_K(t,T)} \\left( \\frac{1}{x} - 1 \\right)\n\\end{align}\nthe given portfolio can be used to replicate the cash flows of the FRA and\n\\begin{align}\nx \\FRA(s,t,T,K) = V(s) .\n\\end{align}\nIf\n\\begin{align}\nx &= \\frac{\\Bond(0,T)}{p(0,t)}\n\\end{align}\nthen $V(0) = 0$ and\n\\begin{align}\nK &= \\frac{1}{\\dayc_K(t,T)} \\left( \\frac{\\Bond(0,t)}{\\Bond(0,T)} - 1 \\right) \\\\\n&= \\frac{\\dayc(t,T)}{\\dayc_K(t,T)}  \\Rflt(t,T) .\n\\end{align}\nWe see that the forward rate and the rate that defines FRA with zero present value are essentially the same. Thus we define that the forward rate at the time $t$ from time $T$ to $S$ is\n\\begin{align}\n\t\\Rflt(t,T,S) &= \\frac{1}{\\dayc(T,S)} \\left( \\frac{\\Bond(t,T)}{\\Bond(t,S)} - 1 \\right) .\n\\end{align}\nSince $\\dayc(T,S) \\approx S-T$ when $T \\approx S$, we have that \n\t\\begin{align}\n\t\t\\Rflt(t,T,S) &= \\frac{1}{\\dayc(T,S)} \\left( \\frac{\\Bond(t,T)}{\\Bond(t,S)} - 1 \\right) \\\\\n\t\t\t\t   &\\approx \\frac{1}{\\Bond(t,T)} \\frac{\\Bond(t,T) - \\Bond(T,S)}{S-T}\n\t\\end{align}\nand therefore\n\t\\begin{align}\n\t\t\\Rflt(t,T,S) & \\longrightarrow - \\frac{1}{\\Bond(t,T)} \\frac{ \\partial \\Bond(t,T) }{ \\partial t} \\\\\n\t\t\t&= - \\frac{\\partial \\log \\Bond(t,T)}{\\partial T}\n\t\\end{align}\nwhen $S \\rightarrow T^+$ under the assumption that the zero curve $\\Bond(t,T)$ is differentiable. We now define that the instantaneous forward rate at the time $t$ is\n\t\\begin{align}\n\t\t\\Forwardrate(t,T) = - \\frac{\\partial \\log \\Bond(t,T)}{\\partial T}.\n\t\\end{align}\nNow since $\\Bond(t,t) = 1$,\n\t\\begin{align}\n\t\t- \\int_t^T f(t,s) \\dx s &= \\int_t^T \\partial \\log \\Bond(t,s) \\dx s \\\\\n\t\t\t&=  \\log \\Bond(t,T) - \\log \\Bond(t,t) \\\\ &= \\log \\Bond(t,T)\n\t\\end{align}\t\nmeaning that\n\t\\begin{align}\n\t\t\\Bond(t,T) = \\exp \\left( - \\int\\limits_t^T \\Forwardrate (t,s) \\dx s \\right) .\n\t\\end{align}\n\t\n\\section{Interest rate instruments}\t\t\n\n\\subsection{Fixed leg and floating leg}\n\nA leg with tenor $t_0 < t_1 < t_2 < \\ldots < t_n = T$ and coupons $c_1, c_2, \\ldots, c_n$ is an instruments that pays $c_i$ at the time $t_i$ for all $1 \\leq i \\leq n$. The coupons may be functions of some variables. Thus a is a portfolio of $n$ zero-coupon bonds with maturities coinciding with tenor. It has has present value of\n  \\begin{align}\n    \\sum_{i=1}^n c_i \\Bond (t, t_i) \\1_{ \\{ t \\geq t_i \\} } \n  \\end{align}\nat the time $t$. \n\nA floating leg with a unit principal has coupons defined by $c_i = \\dayc_1(t_{i-1}, t_i) \\Rflt(t_{i-1}, t_i)$, where $\\Rflt$ is a reference rate for a floating. It has a present value of\n\\begin{align}\nPV_{\\text{float}}(t) &= \\sum_{i=1}^n \\Bond (t,t_i) \\dayc_1(t_{i-1}, t_i) \\Rflt(t_{i-1}, t_i) \\\\ \n\t&= \\sum_{i=1}^n \\Bond (t,t_i) \\left( \\frac{1}{\\Bond(t_{i-1},t_i)} -1 \\right) \\\\\n\t&= \\sum_{i=1}^n \\Bond (t,t_{i-1}) \\Bond (t_{i-1},t_i) \\left( \\frac{1}{\\Bond(t_{i-1},t_i)} -1 \\right) \\\\\n\t&= \\sum_{i=1}^n \\left( \\Bond (t,t_{i-1}) - \\Bond (t,t_{i-1})\\Bond (t_{i-1},t_i) \\right) \\\\\n\t&= \\sum_{i=1}^n \\left( \\Bond (t,t_{i-1}) - \\Bond (t,t_i) \\right) \\\\\n\t&= \\Bond (t,t_{0}) - \\Bond (t,t_n)\n\\end{align}\nand especially $PV_{\\text{float}}(t_0) = 1 - \\Bond (t,t_n)$.\n\nIf the coupons are $c_i = K \\dayc_0(t_{i-1}, t_i)$ for a fixed rate $K$, then we call it as a fixed leg with a unit principal. It has a present value\n  \t\\begin{align}\n\t\tPV_{\\text{fixed}}(t) &= K \\sum_{i=1}^n  \\dayc_0(t_{i-1}, t_i) \\Bond (t,t_i) .\n\t\\end{align}\n\t\n\\subsection{Coupon bearing bond}\n\nA coupon bearing bond with floating coupons and a unit principal is combination of a floating leg and payment of one currency unit coinciding with the last tenor date. Thus it has present value of\n\\begin{align}\nPV_{\\text{floating bond}}(t) = \\Bond (t,t_{0})\n\\end{align}\nand especially $PV_{\\text{floating bond}}(t_0) = 1$.\n\nSimilarly a coupon bearing bond with fixed coupons and a unit principal is combination of a fixed leg and payment of one currency unit coinciding with the last tenor date. It has a present value of\n\t\\begin{align}\n\t\tPV_{\\text{fixed bond}}(t) &= \\Bond (t,t_n) + K \\sum_{i=1}^n  \\dayc_0(t_{i-1}, t_i) \\Bond (t,t_i) \\\\\n\t\t&= \\Bond (t,t_n) + PV_{\\text{fixed}}(t) .\n\t\\end{align}\n\t\t\n\\subsection{Vanilla interest rate swap}\n\nA vanilla payer interest rate swap (IRS) is a contract defined by paying a fixed leg and receiving a floating leg. A vanilla receiver interest rate swap (IRS) is a contract defined by paying a floating leg and receiving a fixed leg. The legs may have different amount of coupons. Also the coupons dates and day count conventions may not coincide. If $K$ is the common rate for the fixed leg and both legs have the same notional value, then a payer IRS has the present value of\n  \t\\begin{align}\n\t\t \\sum_{i=1}^m \\Bond (t,t'_i) \\dayc_1(t'_{i-1}, t'_i) \\Rflt(t'_{i-1}, t'_i) - K \\sum_{i=1}^n \\Bond (t,t_i) \\dayc_0(t_{i-1}, t_i)\n\t\\end{align}\nwhere $t'_0 < t'_1 < t'_2 < \\ldots < t'_m$ are the coupon times for the floating leg. A par swap is a swap with present value of zero and the fixed rate for a par swap is \n  \t\\begin{align}\n\t\tK = \\frac{ \\sum\\limits_{i=1}^m \\Bond (t,t'_i) \\dayc_1(t'_{i-1}, t'_i) \\Rflt(t'_{i-1}, t'_i) }{ \\sum\\limits_{i=1}^n \\Bond (t,t_i) \\dayc_0(t_{i-1}, t_i) }\n\t\\end{align}\nIt is easy to see that if the both legs have same underlying notional principal and coupon dates are the same, then the swap is just a collection of forward rate agreements with a fixed strike price. A vanilla payer IRS let the payer to hedge interest rate risk by converting a liability with floating rate payments into fixed payments.\n\n\\subsection{Overnight indexed swap}\n\nAt the end of a banking day, banks and other financial institutions may face surplus or shortage of funds. They may lend the excess or borrow the shortfall on overnight market. Overnight lending rate is often regarded as a proxy for risk-free rate. In Euro area, European Central Bank calculates Eonia, which is a weighted average of all overnight unsecured lending transactions in the interbank market.\n\nOvernight indexed swap (OIS) is a swap where a compounded reference overnight lending rate is exchanged to a fixed rate.\n\n\\subsection{Call and put option and call-put parity}\n\nA European call (put) option gives the buyer the right but not an obligation to buy (sell) a designated underlying instrument from the option seller with a fixed price at expiry date. Thus a call option on $T$-bond with strike price $K$ and maturity $S < T$ has the final value\n\t\\begin{align}\n\t\t\\ZBC(S,S,T,K) = \\left( \\Bond(S,T) - K \\right)^+\n\t\\end{align}\nand the corresponding put option has the final value\n\t\\begin{align}\n\t\t\\ZBP(S,S,T,K) = \\left( K - \\Bond(S,T) \\right)^+ .\n\t\\end{align}\n\t\nA portfolio of long one call and short one put option on a same $T$-bond with identical strike price $K$ and maturity $S$ has final value of\n\t\\begin{align}\n\t\t\\left( \\Bond(S,T) - K \\right)^+ - \\left( K - \\Bond(S,T) \\right)^+ = \\Bond(S,T) - K.\n\t\\end{align}\nTherefore, without any arbitrage, we have the so called call-put--parity\n\t\\begin{align}\n\t\t\\ZBC(t,S,T,K) - \\ZBP(t,S,T,K) = \\Bond(t,T) - \\Bond(t,S) K\n\t\\end{align}\nholds for all $t \\leq S$.\n\n\t\n\\subsection{Caplet, cap, floorlet and floor}\n\nIn order to keep notation simplier, we assume that the present is $0$ and $0 < t < T$. A caplet is an interest rate derivative in which the buyer receives\n\t\\begin{align}\n\t\t\\left( \\Rflt(t,T) - K \\right)^+\n\t\\end{align}\nat the time $T$, where $\\Rflt(t,T)$ is some reference rate and $K$ is the fixed strike price. The fixing is done at when the contract is made. \n\nSuppose that a firm must pay a floating rate $L$. By buying a cap with strike $K$ against $L$, the firm is paying\n\t\\begin{align}\n\t\tL - \\left( L - K \\right)^+  = \\min (L,K)\n\t\\end{align}\nmeaning that the highest rate will pay will be the strike rate $K$. Thus caps may be used to hedge interest rate risk.\n\nNow\n\t\\begin{align}\n\t\t\\Rflt(t,T) - K &= \\frac{1}{\\dayc(t,T)} \\left( 1+\\dayc(t,T)\\Rflt(t,T) - K^* \\right) \\\\\n\t\t\t&= \\frac{1}{\\dayc(t,T)} \\left( \\frac{1}{p(t,T)} - K^* \\right)\n\t\\end{align}\nwhere $K^* = 1+ \\dayc(t,T)K$. Thus the value of a caplet at the time $t$ is\n\t\\begin{align}\n\t\tp(t,T) \\left( \\Rflt(t,T) - K \\right)^+ &= \\frac{p(t,T)}{\\dayc(t,T)} \\left( \\frac{1}{p(t,T)} - K^* \\right)^+ \\\\\n\t\t\t&= \\frac{1}{\\dayc(t,T)} \\left( 1 - p(t,T) K^* \\right)^+ \\\\\n\t\t\t&= \\frac{K^*}{\\dayc(t,T)} \\left( \\frac{1}{K^*} - p(t,T) \\right)^+ .\n\t\\end{align}\nBut this is the price of $\\frac{K^*}{\\dayc(t,T)}$ put options on a $T$-bond with strike price $\\frac{1}{K^*}$ at the time of strike $t$. Thus we can price a caplet as a put option on a bond. As the price of a cap contains optionality, we must model the interest rates in order to price it.\n\nA cap is a linear collection of caplets with the same strike price.\n\nA floorlet is an derivate with the payment\n\t\\begin{align}\n\\dayc(t,T) \\left( K - \\Rflt(t,T) \\right)^+\n\\end{align}\nat the time $T$, where $\\Rflt(t,T)$ is some reference rate with day-count convention $\\dayc(t,T)$ and $K$ is the fixed strike price. Similarly a floor is a linear collection of floorlets with the same strike price. We can price a floorlet is the price of $\\frac{K^*}{\\dayc(t,T)}$ call options on a $T$-bond with strike price $\\frac{1}{K^*}$ at the time of strike $t$.\n\n\\subsection{Swaption}\n\nA swaption is an interest rate derivative that allows the owner the right but not an obligation to enter into an IRS. A payer swaption gives the owner the right to enter a payer swap (a swap paying a fixed rate while receiving floating rate). A receiver swaption gives the owner the option to initiate a receiver swaption (a swap paying a floating rate while receiving a fixed rate).\n\nA European payer swaption is equivalent to a European put option on a coupon bearing bond. The underlying swap have the value of\n  \t\\begin{align}\n\t\t\\Swap(S) = PV_{\\text{float}}(S) - PV_{\\text{fixed}}(S) .\n\t\\end{align}\nat the time of the strike $S$. Thus\n\t\\begin{align}\n\t\t\\Swaption(S) &= \\left( PV_{\\text{float}}(S) - PV_{\\text{fixed}}(S) \\right)^+ \\\\\n\t\t\t&= \\left( 1 - \\Bond (t,t_n) - PV_{\\text{fixed}}(S) \\right)^+ \\\\\n\t\t\t&= \\left( 1 - PV_{\\text{fixed bond}}(S) \\right)^+ .\n\t\\end{align}\nWe see that a swaption is a european put option on a fixed rate coupon bond. The coupon rate is the fixed rate of the underlying swap and strike price is the principal of the bond and the underlying swap. \n\nIn some cases we may price a swaption as a portfolio of options on zero-coupon bond. This trick was introduced in \\cite{jamshidian1989anexactbondoptionformula}. We now denote the price of a zero coupon bond as a function of a short rate $\\Bond(t,T,r)$. We consider a put option with maturity $S$ and strike price $K$ on a bond with coupond $c_i$ occuring at times $t_i$, $i=1,2, \\ldots, n$. Let $r^*$ be the rate with the property\n\t\\begin{align}\n\t\tK &= \\sum_{i=1}^n c_i \\Bond(S, t_i, r^*)  .\n\t\\end{align}\nNow the put option has a value \n\t\\begin{align}\n\t\t\\left( K - \\sum_{i=1}^n c_i \\Bond(S,t_i) \\right)^+ &= \\left( \\sum_{i=1}^n c_i \\left( \\Bond(S, t_i, r^*) - \\Bond(S,t_i,r(S)) \\right) \\right)^+ .\n\t\\end{align}\nIf we assume that the bond prices are uniformly decreasing function on the initial short rate, then the options will be exercised if and only if $r^* < r(S)$ and now\n\t\\begin{align}\n\t\t\\Bond(S, t_i, r^*) > \\Bond(S,t_i,r(S)) .\n\t\\end{align}\nfor all $i$ Otherwise all $\\Bond(S, t_i, r^*) \\leq \\Bond(S,t_i,r(S))$ for all $i$. Thus the put option has value\n\t\\begin{align}\n\t\t\\sum_{i=1}^n c_i \\left( \\Bond(S, t_i, r^*) - \\Bond(S,t_i,r(S)) \\right)^+\n\t\\end{align}\nwhich is a portfolio of put options with maturities $S$ on a zero coupon bonds with strike prices of $\\Bond(S, t_i, r^*)$. The assumption behind this trick assumes in essence that the prices of the zero coupon bonds moves in unison. This is satisfied by one-factor models but the assumption does not hold for multi-factor models.\n\nSimilarly, a European receiver swaption is equivalent to a European call option on a coupon bearing bond. Under the same assumption, we may disassemble a receiver swaption as a portfolio of call options on zero coupon bonds.\n\n\\iffalse\n\n\\subsection{Eurodollar futures}\n\nEurodollar futures is a contract that will swap\n\t\\begin{align}\n\t\t1- \\Rflt(T,S)\n\t\\end{align}\nwith\n\t\\begin{align}\n\t\t1 - \\FUT(t,T,S)\n\t\\end{align}\nat the time $T$, where $t < T < S$ and the futures rate $\\FUT(t,T,S)$ is set so that entering futures contract at the time $t$ costs nothing. Futures contracts are resettled continuously, meaning that for a small time horizon $\\delta > 0$, the owner of a futures contract will have a cash flow of\n\t\\begin{align}\n\t\t\\FUT(s,T,S) - \\FUT(s+\\delta,T,S) .\n\t\\end{align}\nIn practice, resettlement is done daily. As $\\FUT(T,T,S) = \\Rflt (T,S)$, the holder of a futures contract has experienced undiscounted net cash flow of\n\t\\begin{align}\n\t\t\\sum\\limits_{t \\leq s < T} \\left( \\FUT(s,T,S) - \\FUT(s+\\delta,T,S) \\right) = \\FUT(t,T,S) - \\Rflt (T,S) ,\n\t\\end{align}\nbut we note this number contains undiscounted cash flows from different point of times. If interest rates raises, the futures contract will lose value. On the other hand, falling interest rates will make contract more valuable. Assuming that the rates of different tenor move in unison, the refinancing cost of settling a move of $n>0$ basis points is higher than the benefits of reinvesting gains from a movement of $-n$ basis points.\n\n\\fi\n\n\\section{Defaultable instruments and credit default swaps}\n\n\\subsection{Defaultable $T$-bond}\n\nA defaultable $T$-bond with no recovery (NR) is an instrument that pays\n\t\\begin{align}\n\t\t\\DBond(T,T) = \\begin{cases} 1, & T < \\default \\\\ 0, & T \\geq \\default \\end{cases}\n\t\\end{align}\nat the time $T$, where $\\default$ is the time of a default of the underlying. The price of a defaultable $T$-bond at the time $t < T$ is denoted by $\\DBond(t,T)$.\n\nA defaultable $T$-bond with recovery of treasury (RT) has the same final payout is a defaultable $T$-bond with no recovery but in addition it pays $\\delta \\Bond(\\default, T)$ if $\\default \\leq T$, where $0 < \\delta < 1$. Thus it was a terminal value of\n\t\\begin{align}\n\t\t\\DBond(T,T) = \\1_{ \\{ \\default > T \\} } + \\delta \\1_{ \\{ \\default \\leq T \\} } .\n\t\\end{align}\n\nA defaultable $T$-bond with recovery of face value (RFV) has the same final payout is a defaultable $T$-bond with no recovery but in addition it pays $\\delta$ at the default if $\\default \\leq T$, where $0 < \\delta < 1$. Thus it was a terminal value of\n\t\\begin{align}\n\t\t\\DBond(T,T) = \\1_{ \\{ \\default > T \\} } + \\delta \\1_{ \\{ \\default \\leq T \\} } \\Bond(\\default,T) .\n\t\\end{align}\n\t\nA defaultable $T$-bond with recovery of market value (RMV) has the same final payout is a defaultable $T$-bond with no recovery but in addition it pays $\\delta\\DBond(\\default,T)$ at the default if $\\default \\leq T$, where $0 < \\delta < 1$. Thus it was a terminal value of\n\\begin{align}\n\\DBond(T,T) = \\1_{ \\{ \\default > T \\} } + \\delta \\1_{ \\{ \\default \\leq T \\} } \\Bond(\\default,T) .\n\\end{align}\n\n\\subsection{Credit default swap}\n\nA credit default swap (CDS) is an instrument where the seller of the contract will compensate the buyer if the reference instrument or entity has a credit event such as a default. In exchange, the buyer will make periodic payments to the seller until the end of the contract or the default event. The buyer of CDS will be hedged against the credit risk of the reference entity. Originally physical settlement was used. If the credit event occurs before the maturity of the CDS, then the seller is obligated to buy the underlying reference debt for face value. Since the notional value of credit default swaps may be greater than the underlying debt, physical settlement is a cumbersome process and cash settlements are held instead. In order to determine the value of a contract after the default, a credit event auction is held to determine the recovery value $\\Rec$ (\\cite{ISDAbigbang}, \\cite{BISquarterlyreview2010}).\n\nSuppose that the CDS will offer protection from $S$ to $T$ and $\\default$ is the time of the credit event. The protection seller has agreed to pay the buyer $\\LGD = 1 - \\Rec$ at the time $\\default$ if $S \\leq \\default \\leq T$. The protection leg of CDS has a value of\n\t\\begin{align}\n\t\t\\Protection(t) = \\Bond(t, \\default) \\LGD \\1_{ \\{ S \\leq \\default \\leq T \\} }\n\t\\end{align}\nat the time $t$. Let $S = t_0 < t_1 < t_2 < \\ldots <t_n = T$. The premium leg will pay a coupon rate $C$ at the times $t_1 < t_2 < \\ldots < t_n$ if the credit event has not occurred. If the credit event happes, then the buyer will pay the accrued premium rate at the time of the default. The premium leg has a value of\n\t\\begin{align}\n\t\t\\Premium(t, C) =\\sum_{i=1}^n \\Bond(t, t_i) \\dayc(t_{i-1},t_i) C \\1_{ \\{ \\default > t_i \\} } + \\Bond(t, \\default) \\dayc(t,\\default) C \\1_{ \\{ t_s \\leq \\default \\leq t_{s+1} \\} }\n\t\\end{align}\nwhere $t_s$ is the last date from $t_0 < t_1 < \\ldots < t_n$ before the credit event (if it occurs).\n\nStandardized CDS contracts have quarterly coupon payments and rates are usually set to be either $25$, $100$, $500$ or $1000$ basis points. So when traded the buyer will pay \n\t\\begin{align}\n\t\t\\Premium(0, C) - \\Protection(0) .\n\t\\end{align}\nEarlier the coupon rate $C$ was set so that $\\Premium(0, C) = \\Protection(0)$ and no money was exchanged at the trade.\n\n\n\n\n", "meta": {"hexsha": "a42e1856258b3a978e3806000685ce5ba2a576d1", "size": 23057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "instruments.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": "instruments.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": "instruments.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": 59.8883116883, "max_line_length": 920, "alphanum_fraction": 0.6819620939, "num_tokens": 7532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581510799252, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6077588229246357}}
{"text": "\\section{Hierarchical Models}\n\n\\begin{frame}{Structure of HM - Setup}\n  \\Large{\n  \\emphcol{Hierarchical Data:}\\pause\n  \\begin{itemize}\n    \\item[] \\emphcol{Individual Level:} $(y_i, x_i)$ for $i = 1,\\mydots,n$\\pause\n    \\item[] \\emphcol{Group Level:} $u_j$ for $j = 1,\\mydots,J$\n  \\end{itemize}\\pause\n  \\emphcol{Example:}\n  \\begin{itemize}\n    \\item[] \\emphcol{Test Outcome:} $y_i$\n    \\item[] \\emphcol{Parental Income:} $x_i$\n    \\item[] \\emphcol{Num. of Teachers:} $u_j$\n  \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}{Structure of HM}\n\\begin{figure}\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[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    (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\\end{figure}\n\\end{frame}\n\n\\begin{frame}{The Prior Revisited}\n  \\Large{\n    \\emphcol{Before:}\n    \\begin{itemize}\n        \\item[] \\emphcol{Model:} $p(\\text{data} \\mid \\theta)$\n        \\item[] \\emphcol{Prior:} $p(\\theta)$\n      \\end{itemize}\\pause\n    \\emphcol{Now:}\n    \\begin{itemize}\n      \\item[] \\emphcol{Model:} $p(\\text{data} \\mid \\theta, \\phi) = p(\\text{data} \\mid \\theta)$\n      \\item[] \\emphcol{Prior:} $p(\\theta \\mid \\phi)$\n      \\item[] \\emphcol{Hyperprior:} $p(\\phi)$\n    \\end{itemize}\n  }\n\\end{frame}\n\n\\begin{frame}{The Posterior Revisited}\n  \\Large{\n    \\emphcol{Posterior:}\n    \\begin{align*}\n    \\action<+->{p(\\theta, \\phi \\mid \\text{data}) &\\propto p(\\text{data} \\mid \\theta) p(\\theta, \\phi)\\\\}\n    \\action<+->{&\\propto p(\\text{data} \\mid \\theta) p(\\theta \\mid \\phi) p(\\phi)\\\\}\n    \\action<+->{p(\\phi \\mid \\text{data}) &\\propto \\int p(\\theta, \\phi \\mid \\text{data}) \\mathrm{d} \\theta}\n    \\end{align*}\n  }\n\\end{frame}\n\n\\begin{frame}{Varying Slopes, Varying Intercepts}\n  \\Large{\n    \\begin{itemize}\n      \\item[] \\emphcol{Setup:} Individual $i$ in group $j$\\pause\n      \\item[] \\emphcol{Individual Level:} $y_i = \\alpha_{j[i]} + \\beta_{j[i]} x_i + \\epsilon_i$\\pause\n      \\item[] \\emphcol{Group Level:} $\\sqmat{\\alpha_j\\\\\\beta_j} = \\gamma_0 + \\gamma u_j + \\eta_j$\\pause\n      \\item[] \\emphcol{Priors on:} $\\gamma_0, \\gamma, \\epsilon_i, \\eta_j$\\pause\n    \\end{itemize}\n  }\n\\end{frame}\n", "meta": {"hexsha": "278cb3d7dbeab58715ed751cea41dcff74680bf4", "size": 3029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/part2.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": "presentation/part2.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": "presentation/part2.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": 34.0337078652, "max_line_length": 106, "alphanum_fraction": 0.6087817762, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6077520529190168}}
{"text": "\\documentclass[11pt]{article}\n\n\\usepackage{graphicx}\n\\usepackage{courier}\n\\usepackage{underscore}\n\\setlength\\parindent{0pt}\n\n\\title{Laconic Operation Documentation}\n\\author{Adam Yedidia}\n\n\\begin{document}\n    \n\\maketitle\n\nThis document enumerates all the primitive operations in Laconic. It is recommended that users start by reading \\texttt{laconic_quick_start.pdf} to get a sense for how Laconic works. \\\\\n\nRemember that operations can be combined into complex expressions (i.e. \\texttt{(a+b)*c}) but that full parenthesization is required! Also, recall that \\texttt{int}s are signed integers with no maximum or minimum value, \\texttt{list}s are Python-style lists of \\texttt{int}s, and \\texttt{list2}s are Python-style lists of \\texttt{list}s. \n\n\\section{Integer Operations}\n\nAssume in the operations below that \\texttt{x} and \\texttt{y} are variables of type \\texttt{int} with values $x$ and $y$, respectively. \\\\\n\nAll the operations below yield values of type \\texttt{int}.\n\n\\subsection{Addition}\n\nThe expression \\texttt{x+y} yields the value $x+y$.\n\n\\subsection{Subtraction}\n\nThe expression \\texttt{x-y} yields the value $x-y$.\n\n\\subsection{Multiplication}\n\nThe expression \\texttt{x*y} yields the value $xy$.\n\n\\subsection{Integer Division}\n\nThe expression \\texttt{x/y} yields the value $s(xy)\\left\\lfloor|\\frac{x}{y}|\\right\\rfloor$, where $s()$ is the sign function. In plain English, integer division in Laconic rounds numbers to the lowest-magnitude adjacent number. This means that \\texttt{3/2} would yield the value 1, and \\texttt{(0-3)/2} would yield the value $-1$. \\\\\n\nIf \\texttt{y} is 0, Laconic will throw a runtime error if interpreted, and the compiled TMD or Turing machine will enter an infinite loop.\n\n\\subsection{Negation}\n\nThe expression \\texttt{{\\raise.17ex\\hbox{$\\scriptstyle\\sim$}}x} yields the value $-x$. Note the strange negation operator.\n\n\\subsection{Equality}\n\nThe expression \\texttt{x==y} yields the value 1 if $x=y$, and the value 0 otherwise.\n\n\\subsection{Inequality}\n\nThe expression \\texttt{x!=y} yields the value 1 if $x\\not=y$, and the value 0 otherwise.\n\n\\subsection{Greater Than}\n\nThe expression \\texttt{x>y} yields the value 1 if $x>y$, and the value 0 otherwise.\n\n\\subsection{Less Than}\n\nThe expression \\texttt{x<y} yields the value 1 if $x<y$, and the value 0 otherwise.\n\n\\subsection{Greater or Equal}\n\nThe expression \\texttt{x>=y} yields the value 1 if $x\\ge y$, and the value 0 otherwise.\n\n\\subsection{Less Than or Equal}\n\nThe expression \\texttt{x<=y} yields the value 1 if $x\\le y$, and the value 0 otherwise.\n\n\\subsection{And}\n\nThe expression \\texttt{x\\&y} yields the value 1 if $x>0$ and $y>0$, and the value 0 otherwise. Note that negative values of $x$ and $y$ are interpreted as ``false'' values for the purposes of ``boolean'' operations.\n\n\\subsection{Or}\n\nThe expression \\texttt{x|y} yields the value 1 if $x>0$ or $y>0$, and the value 0 otherwise.\n\n\\subsection{Not}\n\nThe expression \\texttt{!x} yields the value 1 if $x\\le 0$, and the value 0 otherwise.\n\n\\section{List and List2 Operations}\n\nAssume in the operations below that \\texttt{x} is a variable of type \\texttt{int}, \\texttt{l} is a variable of type \\texttt{list}, and that \\texttt{L} is a variable of type \\texttt{list2}. Assume that these variables have values of $x$, $l$, and $L$, respectively.\n\n\\subsection{Indexing}\n\nThe expression \\texttt{l@x} yields the \\texttt{int} value of the $x^{\\textrm{th}}$ element of $l$, assuming 0-indexing. If $x\\le |l|$, a runtime error is thrown in both the interpreted and compiled versions of the code.\\\\\n\nThe expression \\texttt{L@*x} yields the \\texttt{list} value of the $x^{\\textrm{th}}$ element of $L$, assuming 0-indexing. If $x\\le |L|$, a runtime error is thrown in both the interpreted and compiled versions of the code. \\\\\n\nIn general, \\texttt{list2} operations use the same symbol as the corresponding \\texttt{list} operations, but with a \\texttt{*} at the end.\n\n\\subsection{Appending}\n\nThe expression \\texttt{l\\char`\\^x} yields the \\texttt{list} value of $l||[x]$, where $||$ denotes the concatenation operation. \\\\\n\nThe expression \\texttt{L\\char`\\^*l} yields the \\texttt{list2} value of $L||[l]$, where $||$ denotes the concatenation operation.\n\n\\subsection{Length} \n\nThe expression \\texttt{\\#l} yields the \\texttt{int} value of $|l|$. \\\\\n\nThe expression \\texttt{\\#*L} yields the \\texttt{int} value of $|L|$. \n\n\\subsection{Concatenation}\n\nIn the expressions below, the variables \\texttt{l1}, \\texttt{l2}, \\texttt{L1}, and \\texttt{L2} have types \\texttt{list}, \\texttt{list}, \\texttt{list2}, and \\texttt{list2}, with values of $l_1$, $l_2$, $L_1$, and $L_2$, respectively. \\\\\n\nThe expression \\texttt{l1||l2} yields the \\texttt{list} value of $l_1||l_2$, where $||$ denotes the concatenation operation. \\\\\n\nThe expression \\texttt{L1||*L2} yields the \\texttt{list2} value of $L_1||L_2$, where $||$ denotes the concatenation operation.\n\n\\subsection{Explicit Description}\n\nTo explicitly enumerate a \\texttt{list}, put the elements of the \\texttt{list} between brackets and separated by commas. For example, \\texttt{[x, 1, y]} would yield the \\texttt{list} value $[x, 1, y]$. \\\\\n\nTo explicitly enumerate a \\texttt{list2}, put the elements of the \\texttt{list2} between colons and separated by commas. For example, \\texttt{:[x, 1, y], l1, []:} would yield the \\texttt{list2} value $[[x, 1, y], l_1, []]$.\n\n\\end{document}\n", "meta": {"hexsha": "77a2dc77ed74708211e205284421e0e92c05e5e3", "size": 5375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/docs/laconic_ops.tex", "max_stars_repo_name": "ricsonc/parsimony", "max_stars_repo_head_hexsha": "37cbead5421f546b2f687c1a916fc50ad21f417d", "max_stars_repo_licenses": ["MIT"], "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/laconic_ops.tex", "max_issues_repo_name": "ricsonc/parsimony", "max_issues_repo_head_hexsha": "37cbead5421f546b2f687c1a916fc50ad21f417d", "max_issues_repo_licenses": ["MIT"], "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/laconic_ops.tex", "max_forks_repo_name": "ricsonc/parsimony", "max_forks_repo_head_hexsha": "37cbead5421f546b2f687c1a916fc50ad21f417d", "max_forks_repo_licenses": ["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.0573770492, "max_line_length": 338, "alphanum_fraction": 0.7294883721, "num_tokens": 1608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6077520529190167}}
{"text": "\\subsection{Relations}\\label{subsec:relations}\n\n\\begin{definition}\\label{def:cartesian_product}\\mcite[def. 1.23]{OpenLogicFull}\n  We are now in a vicious cycle where we need binary Cartesian products in order to define arbitrary Cartesian products. We will do this as quickly as possible, without introducing relations and functions. The latter two will be discussed in detail in \\fullref{subsec:relations} and \\fullref{subsec:functions}, respectively.\n\n  \\begin{thmenum}\n    \\thmitem{def:cartesian_product/kuratowski_pair} The \\term{Kuratowski pair} or simply \\term{ordered pair} \\( \\braket{ x, y } \\) of the sets \\( x \\) and \\( y \\) is defined as\n    \\begin{equation*}\n      \\braket{ x, y } \\coloneqq \\set{ \\set{ x }, \\set{ x, y } }.\n    \\end{equation*}\n\n    This is a simple and widespread definition that encodes the order of \\( x \\) and \\( y \\), unlike the set \\( \\set{ x, y } \\) for example.\n\n    We will later use the notation \\( (x, y) \\), but until \\fullref{rem:kuratowski_pairs_and_tuples}, we want to distinguish between Kuratowski pairs and \\( 2 \\)-tuples.\n\n    We will use the following \\hyperref[rem:predicate_formula]{predicate formula} in \\( \\ref{eq:def:function/predicate}[\\rho, \\tau, \\sigma] \\):\n    \\begin{equation*}\\taglabel[\\op{IsPair}]{eq:def:cartesian_product/kuratowski_pair_predicate}\n      \\ref{eq:def:cartesian_product/kuratowski_pair_predicate}[\\rho, \\tau, \\sigma] \\coloneqq \\qforall \\xi \\parens[\\Bigg]{ \\xi \\in \\rho \\leftrightarrow \\parens[\\Big]{ \\parens[\\Big]{ \\qforall {\\eta \\in \\xi} \\eta \\doteq \\tau } \\vee \\parens[\\Big]{ \\qforall {\\eta \\in \\xi} (\\eta \\doteq \\tau \\vee \\eta \\doteq \\sigma) } } }\n    \\end{equation*}\n\n    \\thmitem{def:cartesian_product/indexed_family} A set \\( i \\) of Kuratowski pairs is called an \\term{indexed family} if whenever \\( \\braket{ k, A } \\in i \\) and \\( \\braket{ k, B } \\in i \\), we have \\( A = B \\). It is conventional to denote this unique set corresponding to \\( k \\) as \\( A_k \\) without an explicit reference to \\( i \\).\n\n    The \\term{index set} of the family is\n    \\begin{equation*}\n      \\mscrK \\coloneqq \\set{ k \\given \\qexists A \\braket{ k, A } \\in i }.\n    \\end{equation*}\n\n    The family itself is then denoted as\n    \\begin{equation*}\n      \\seq{ A_k }_{k \\in \\mscrK}.\n    \\end{equation*}\n\n    If \\( A_k \\in \\mscrA \\) for every \\( k \\in \\mscrK \\), we sometimes write\n    \\begin{equation*}\n      \\seq{ A_k }_{k \\in \\mscrK} \\subseteq \\mscrA,\n    \\end{equation*}\n    although the latter is an embedding rather than set inclusion.\n\n    \\thmitem{def:cartesian_product/tuple} A \\term{tuple} from the indexed family \\( \\seq{ A_k }_{k \\in \\mscrK} \\) is another indexed family \\( \\seq{ x_k }_{k \\in \\mscrK} \\) with the same index set satisfying the condition that for every \\( k \\in \\mscrK \\), the value \\( x_k \\) belongs to \\( A_k \\).\n\n    We will see later that this is precisely a \\hyperref[def:choice_function]{choice function}.\n\n    \\thmitem{def:cartesian_product/product} The \\term{Cartesian product} of an indexed family \\( \\seq{ A_k }_{k \\in \\mscrK} \\) is the set of all tuples from this family. We denote the Cartesian product by\n    \\begin{equation*}\n      \\prod_{k \\in \\mscrK} A_k.\n    \\end{equation*}\n\n    With the availability of \\hyperref[def:function]{functions} in \\fullref{subsec:functions}, we can define the Cartesian product as the set\n    \\begin{equation*}\n      \\prod_{k \\in \\mscrK} A_k = \\set{ f: A \\to \\bigcup_{k \\in \\mscrK} A_k \\given \\qforall {k \\in \\mscrK} k \\in A_k }.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:sequence}\n  Families indexed by \\( \\omega \\) are called \\term{infinite sequences} or simply \\term{sequences}. We will use several notations, depending on the context.\n  \\begin{itemize}\n    \\item \\( \\seq{ A_k }_{k \\in \\BbbN} \\), which is the conventional notation for indexed families.\n    \\item \\( \\seq{ A_k }_{k=0}^\\infty \\), which easily extends to cases such as \\( \\seq{ A_k }_{k=m}^n \\) when the index set is \\( \\set{ m, \\ldots, n } \\).\n    \\item \\( (A_0, A_1, \\ldots) \\), which is used when explicitly enumerating members of the sequence.\n  \\end{itemize}\n\n  It is conventional to write a family \\( \\seq{ A_k }_{k \\in n} \\) indexed by a natural number \\( n \\) using the notation \\( (A_1, \\cdots, A_n) \\), with or without the outer parentheses. Families indexed by natural numbers are called \\term{finite sequences}.\n\n  For \\( n = 2 \\), finite sequences are called \\term{pairs}, for \\( n = 3 \\) --- \\term{triples} and for \\( n = 4 \\) --- \\term{quadruples}.\n\n  We say that \\( A_{k_1}, A_{k_2}, \\ldots \\) is a \\term{subsequence} of \\( A_1, A_2, \\ldots \\) if \\( k_1 < k_2 < \\ldots \\), i.e. if the sequence of indices is monotone in the sense of \\eqref{eq:def:partially_ordered_set/homomorphism/sequence}.\n\\end{definition}\n\n\\begin{remark}\\label{rem:kuratowski_pairs_and_tuples}\n  Note that the tuple \\( (A, B) \\)\n  \\begin{equation*}\n    (A, B) = \\set[\\Bigg]{ \\set[\\Big]{ \\set{ 0 }, \\set{ 0, A } }, \\set[\\Big]{ \\set{ 1 }, \\set{ 1, B } } }\n  \\end{equation*}\n  is formally different from the \\hyperref[def:cartesian_product/kuratowski_pair]{Kuratowski pair}\n  \\begin{equation*}\n    \\braket{ A, B } = \\set[\\Big]{ \\set{ A }, \\set{ A, B } }.\n  \\end{equation*}\n\n  This is one reason we hurried to define general Cartesian products --- we wanted to avoid working with tuples defined in terms of Kuratowski pairs. We even introduced a special notation for them, just so we can avoid any confusion. Nevertheless, it is conventional to conflate Kuratowski pairs with \\( \\set{ 0, 1 } \\)-indexed tuples.\n\n  We also conflate the tuples \\( (A, (B, C)) \\), \\( ((A, B), C) \\) and \\( (A, B, C) \\).\n\\end{remark}\n\n\\begin{definition}\\label{def:relation}\n  Let \\( A_1, \\ldots, A_n \\) be a \\hyperref[def:sequence]{finite sequence} of sets and let\n  \\begin{equation*}\n    R \\subseteq A_1 \\times \\cdots \\times A_n\n  \\end{equation*}\n  be a subset of their \\hyperref[def:cartesian_product/product]{Cartesian product}.\n\n  The sequence \\( (R, A_1, \\ldots, A_n) \\) is called an \\( n \\)-ary \\term{relation}. We say that the tuple \\( (x_1, \\ldots, x_n) \\in A_1 \\times \\cdots \\times A_n \\) is related with respect to \\( R \\) if \\( (x_1, \\ldots, x_n) \\in R \\).\n\n  Relations are the semantical counterpart to \\hyperref[def:first_order_structure/interpretation/predicate]{first-order predicates} and are equivalent to Boolean-valued functions, as discussed in \\fullref{rem:boolean_valued_functions_and_predicates}.\n\n  We generalize only the following notions from \\hyperref[def:binary_relation]{binary relations}:\n  \\begin{thmenum}[series=def:relation]\n    \\thmitem{def:relation/graph} The set \\( R \\) of tuples is called the \\term{graph} of the relation. In case the sequence \\( A_1, \\ldots, A_n \\) is clear from the context, we can identify the relation \\( (R, A_1, \\ldots, A_n) \\) with its graph \\( R \\). We occasionally use the notation \\( \\gph(R) \\) for explicitly denoting the graph.\n\n    \\thmitem{def:relation/signature} The \\term{signature} of the relation is the sequence \\( (A_1, \\ldots, A_n) \\). Obviously this definition only makes sense if we know what the signature is, either from the context or from the definition of the relation as the sequence \\( (R, A_1, \\ldots, A_n) \\) rather than only via its graph \\( R \\).\n\n    As a matter of fact, it is common to ignore the signature when defining relations --- see e.g. \\cite[7]{Kelley1955} or \\cite[def. 2.1]{OpenLogicFull}. If we do identify a relation only with its graph, however some notions like \\hyperref[def:multi_valued_function/range]{ranges} and \\hyperref[def:multi_valued_function/image]{images} coincide despite being different and other notions like \\hyperref[def:function_invertibility/surjective]{function surjectivity} make no sense.\n\n    Furthermore, two relations whose graphs are equal may have different signatures, which further highlights how important it is to distinguish between a relation and its graph.\n\n    \\thmitem{def:relation/arity} For some small values of \\( n \\), \\( n \\)-ary relations have established names:\n    \\begin{itemize}\n      \\item \\term{Nullary} if \\( n = 0 \\).\n      \\item \\term{Unary} if \\( n = 1 \\).\n      \\item \\term{Binary} if \\( n = 2 \\).\n      \\item \\term{Ternary} if \\( n = 3 \\).\n    \\end{itemize}\n\n    This is not to be confused with \\hyperref[def:multi_valued_function/arity]{function arity} --- functions are always binary relations.\n\n    \\thmitem{def:relation/single_set} If all \\( A_k \\) for \\( k = 1, \\ldots, n \\) are equal to the set \\( A \\), we say that \\( R \\subseteq A^n \\) is a relation \\hi{on \\( A \\)}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{definition}\\label{def:binary_relation}\n  An important special case of \\hyperref[def:relation]{relations} are \\term{binary relations}. Given two sets \\( A \\) and \\( B \\), a binary relation between them is a triple \\( (R, A, B) \\).\n\n  In addition to the terminology for \\fullref{def:relation}, we also introduce the following terms:\n  \\begin{thmenum}[series=def:binary_relation]\n    \\thmitem{def:binary_relation/empty} The relation is \\term{empty} if its graph is the empty set, i.e. if no two elements are related.\n\n    It is important to highlight that the graphs of all empty relations are equal, but two empty relations are only equal if their signatures are.\n\n    \\thmitem{def:binary_relation/converse} The \\term{converse relation} of \\( R \\) is\n    \\begin{equation*}\n      R^{-1} \\coloneqq \\set{ (y, x) \\given (x, y) \\in R }.\n    \\end{equation*}\n\n    \\thmitem{def:binary_relation/restriction} If \\( A = B \\), the \\term{restriction} of \\( R \\) to \\( X \\subseteq A \\) is the binary relation \\( (R\\restr_{X}, X, X) \\) is\n    \\begin{equation*}\n      R\\restr_{X} \\coloneqq R \\cap (X \\times X) = \\set{ (x, y) \\in R \\given x \\in X \\T{and} y \\in X }.\n    \\end{equation*}\n\n    We say that \\( R \\) is an \\term{extension} of \\( R\\restr_{X} \\).\n\n    \\thmitem{def:binary_relation/diagonal} A special relation is the \\term{diagonal relation} on a set \\( A \\):\n    \\begin{equation*}\n      \\increment_A \\coloneqq \\set{ (x, x) \\given x \\in A }.\n    \\end{equation*}\n\n    \\thmitem{def:binary_relation/composition} Given two binary relations \\( R \\subseteq A \\times B \\) and \\( T \\subseteq B \\times C \\), we define their composition as\n    \\begin{equation*}\n      T \\bincirc R \\coloneqq \\set*{ (x, z) \\in A \\times C \\given* \\qexists {y \\in B} \\parens[\\Big]{ (x, y) \\in R \\T{and} (y, z) \\in T } }.\n    \\end{equation*}\n  \\end{thmenum}\n\n  Whenever \\( A = B \\) and \\( R \\) is simply a binary relation over \\( A \\), the following are commonly used conditions that are often as axioms to some theory:\n  \\begin{thmenum}[resume=def:binary_relation]\n    \\thmitem{def:binary_relation/reflexive} \\( R \\) is \\term{reflexive} if \\( \\Delta_A \\subseteq R \\), i.e. if every element of \\( A \\) is related with itself.\n\n    The following formula is used as an axiom for \\hyperref[def:partially_ordered_set/nonstrict]{nonstrict partial orders} and \\hyperref[def:entourage]{entourages}:\n    \\begin{equation}\\label{eq:def:binary_relation/reflexive}\n      \\qforall \\xi (\\xi \\mathbin{R} \\xi).\n    \\end{equation}\n\n    Note that we use \\fullref{rem:first_order_formula_conventions/infix} notation in the latter case. Using either infix or prefix notation is actually a necessity since we do not actually have a concept of an ordered tuple in general (not set-based) first-order theories --- see \\fullref{rem:first_order_formula_conventions/infix}.\n\n    \\thmitem{def:binary_relation/irreflexive} \\( R \\) is \\term{irreflexive} if \\( \\Delta_A \\cap R = \\varnothing \\), i.e. if no element of \\( A \\) is related with itself.\n\n    The following formula is used as an axiom for \\hyperref[def:partially_ordered_set/strict]{strict partial orders}:\n    \\begin{equation}\\label{eq:def:binary_relation/irreflexive}\n      \\neg \\qexists \\xi (\\xi \\mathbin{R} \\xi).\n    \\end{equation}\n\n    \\thmitem{def:binary_relation/symmetric} \\( R \\) is \\term{symmetric} if \\( R = R^{-1} \\).\n\n    The following formula is used as an axiom for \\hyperref[def:equivalence_relation]{equivalence relations}, \\hyperref[def:undirected_multigraph]{undirected graphs} and \\hyperref[def:entourage]{entourages}:\n    \\begin{equation}\\label{eq:def:binary_relation/symmetric}\n      \\xi \\mathbin{R} \\eta \\rightarrow \\eta \\mathbin{R} \\xi.\n    \\end{equation}\n\n    \\thmitem{def:binary_relation/antisymmetric} \\( R \\) is \\term{antisymmetric} if \\( R \\cap R^{-1} = \\Delta_X \\).\n\n    The following formula is used as an axiom for \\hyperref[def:partially_ordered_set]{partial orders}:\n    \\begin{equation}\\label{eq:def:binary_relation/antisymmetric}\n      (\\xi \\mathbin{R} \\eta \\wedge \\eta \\mathbin{R} \\xi) \\rightarrow \\xi \\doteq \\eta.\n    \\end{equation}\n\n    \\thmitem{def:binary_relation/transitive} \\( R \\) is \\term{transitive} if \\( R = R \\bincirc R \\).\n\n    The following formula is used as an axiom for \\hyperref[def:partially_ordered_set]{preorders}:\n    \\begin{equation}\\label{eq:def:binary_relation/transitive}\n      (\\xi \\mathbin{R} \\eta \\wedge \\eta \\mathbin{R} \\zeta) \\rightarrow \\xi \\mathbin{R} \\zeta.\n    \\end{equation}\n\n    \\thmitem{def:binary_relation/total} \\( R \\) is \\term{total} if any two member of \\( A \\) are related.\n\n    The following formula is used as an axiom for \\hyperref[def:totally_ordered_set]{nonstrict total orders}:\n    \\begin{equation}\\label{eq:def:binary_relation/total}\n      \\qforall \\xi \\qforall \\eta (\\xi \\mathbin{R} \\eta \\vee \\eta \\mathbin{R} \\xi).\n    \\end{equation}\n\n    Total relations are also called \\term{connected} because of \\fullref{thm:order_category_isomorphism/totally_ordered}.\n\n    \\thmitem{def:binary_relation/trichotomic} \\( R \\) is \\term{trichotomic} if every two elements of \\( A \\) are either related or equal.\n\n    The following formula is used as an axiom for \\hyperref[def:totally_ordered_set]{strict total orders}:\n    \\begin{equation}\\label{eq:def:binary_relation/trichotomic}\n      \\qforall \\xi \\qforall \\eta (\\xi \\mathbin{R} \\eta \\vee \\eta \\mathbin{R} \\xi \\vee \\eta = \\xi).\n    \\end{equation}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:def:binary_relation}\n  \\hyperref[def:binary_relation]{Binary relations} are used in vastly different contexts:\n  \\begin{itemize}\n    \\item \\hyperref[def:function]{Functions} are special binary relations.\n    \\item \\hyperref[sec:order_theory]{Orders} are also special binary relations.\n    \\item \\hyperref[def:quiver/simple]{Directed graphs} are commonly defined as binary relations.\n    \\item \\hyperref[def:entourage]{Entourages} are binary relations in \\hyperref[def:uniform_space]{uniform spaces}.\n    \\item Relations are equivalent to Boolean-valued functions as shown in \\fullref{rem:boolean_valued_functions_and_predicates}, and are often used for defining semantics of predicate symbols in \\hyperref[subsec:first_order_logic]{first-order logic}.\n  \\end{itemize}\n\\end{example}\n\n\\begin{definition}\\label{def:equivalence_relation}\n  A binary relation on the set \\( A \\) that is \\hyperref[def:binary_relation/reflexive]{reflexive}, \\hyperref[def:binary_relation/symmetric]{symmetric} and \\hyperref[def:binary_relation/transitive]{transitive} is called an \\term{equivalence relation}. In other words, an equivalence relation is a symmetric \\hyperref[def:preordered_set]{preorder}.\n\n  We often denote equivalence relations via the symbol \\( \\sim \\).\n\n  \\begin{thmenum}\n    \\thmitem{def:equivalence_relation/coset} The \\term{equivalence class} of \\( x \\in A \\), also called its \\term{coset}, is the set\n    \\begin{equation*}\n      [x] \\coloneqq \\set{ y \\in A \\given x \\sim y }\n    \\end{equation*}\n    of all elements of \\( A \\) that are related to \\( x \\).\n\n    \\thmitem{def:equivalence_relation/quotient} The \\term{quotient set} of \\( A \\) by \\( \\sim \\) is the set\n    \\begin{equation*}\n      A / {\\sim} \\ \\coloneqq \\set{ [x] \\given x \\in A }.\n    \\end{equation*}\n\n     If we have an easy way to choose a representative from each coset, then \\( A / {\\sim} \\) may be regarded as a subset of \\( A \\). In general, this is not a subset relation by only an \\hyperref[def:first_order_homomorphism_invertibility/embedding]{embedding}.\n\n    \\thmitem{def:equivalence_relation/projection} Using forward references to \\fullref{subsec:functions}, we define the \\term{canonical projection} as the function\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\pi: A \\to A / {\\sim}  \\\\\n        &\\pi(x) \\coloneqq [x].\n      \\end{aligned}\n    \\end{equation*}\n\n    If we have a fixed \\hyperref[def:choice_function]{choice function} \\( c: A / {\\sim} \\to A \\), we also define the canonical embedding\n    \\begin{equation*}\n      \\begin{aligned}\n        &\\iota: A / {\\sim} \\to A \\\\\n        &\\iota([x]) \\coloneqq c(x).\n      \\end{aligned}\n    \\end{equation*}\n\n    We sometimes have an obvious choice function, for example in \\fullref{thm:representatives_in_univariate_polynomial_quotient_set}. In this case, the canonical projection may be regarded as a function from \\( A \\) to the subset \\( c(A / {\\sim}) \\) of \\( A \\). Otherwise, the function \\( \\pi \\) can be regarded as a \\hyperref[def:multi_valued_function]{multi-valued function} from \\( A \\) to \\( A \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:congruence_modulo_relation}\n  If \\( x \\sim y \\) for some \\hyperref[def:equivalence_relation]{equivalence relation}, we say that they are \\term{congruent modulo} \\( \\sim \\). This concept specializes to congruence modulo normal subgroups defined in \\fullref{def:congruence_modulo_normal_subgroup}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:equality_is_smallest_equivalence_relation}\n  The equality \\hyperref[def:binary_relation]{relation} \\( = \\) is the intersection of all equivalence relations.\n\\end{proposition}\n\\begin{proof}\n  It is equivalent to the \\hyperref[def:binary_relation/diagonal]{diagonal relation} \\( \\Delta_X \\). It is the smallest reflexive (resp. symmetric and transitive) relation on \\( A \\), i.e. the intersection of all reflexive (resp. symmetric and transitive) relations.\n\\end{proof}\n\n\\begin{definition}\\label{def:set_partition}\n  Let \\( A \\) be a set. A \\term{cover} of \\( A \\) is a \\hyperref[rem:family_of_sets]{family} \\( \\mscrA \\subseteq \\pow(A) \\) of nonempty subsets of \\( A \\) such that \\( A = \\bigcup \\mscrA \\). We sometimes use the term more loosely and say that an arbitrary family of sets \\( \\mscrA \\) is a cover of \\( A \\) if \\( A \\subseteq \\bigcup \\mscrA \\). The two definitions are identical if we intersect each set in \\( \\mscrA \\) with \\( A \\) and exclude the empty sets.\n\n  A \\term{partition} of \\( A \\) is a pairwise \\hyperref[def:subset]{disjoint} cover. In other words, the cover \\( \\mscrA \\) is a partition if and only if each element of \\( A \\) belong to exactly one set in \\( \\mscrA \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:equivalence_partition}\n  Fix a set \\( A \\). Let \\( {\\sim} \\) be a binary relation of \\( A \\). The following are equivalent:\n  \\begin{thmenum}\n    \\thmitem{thm:equivalence_partition/equivalence} \\( {\\sim} \\) is an \\hyperref[def:equivalence_relation]{equivalence relation}.\n\n    \\thmitem{thm:equivalence_partition/partition} There exists a \\hyperref[def:set_partition]{partition} \\( \\mscrA \\) of \\( A \\) such that \\( x \\sim y \\) if and only if they belong to the same set in the partition \\( \\mscrA \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\ImplicationSubProof{thm:equivalence_partition/equivalence}{thm:equivalence_partition/partition} Let \\( {\\sim} \\) be an equivalence relation on \\( A \\). The quotient set \\( A / {\\sim} \\) is a partition. Indeed:\n  \\begin{itemize}\n    \\item Every element \\( x \\in A \\) belongs exactly one equivalence class \\( [x] \\) by definition.\n\n    \\item The equivalence classes are disjoint. Indeed, assume the contrary. Then there exist \\( x \\) and \\( y \\) such that \\( [x] \\cap [y] \\neq \\varnothing \\) and yet \\( x \\not\\sim y \\).\n\n    Let \\( z \\in [x] \\cap [y] \\). Then \\( z \\sim x \\) and \\( z \\sim y \\), thus from transitivity of \\( {\\sim} \\) we have \\( x \\sim z \\sim y \\) and hence \\( x \\sim y \\), which contradicts our assumption that \\( x \\not\\sim y \\).\n\n    Hence, either \\( [x] = [x] \\) or \\( [x] \\cap [y] = \\varnothing \\). That is, different equivalence classes are disjoint.\n  \\end{itemize}\n\n  \\ImplicationSubProof{thm:equivalence_partition/partition}{thm:equivalence_partition/equivalence} Let \\( \\mscrA \\) be a partition of \\( A \\) such that \\( x \\sim y \\) if and only if they both belong to the same set in \\( \\mscrA \\).\n\n  Given \\( x \\in A \\), denote by \\( A_x \\) the set in \\( \\mscrA \\) which contains \\( x \\). The family \\( \\seq{ A_x }_{x \\in A} \\) is well-defined since \\( \\mscrA \\) is a partition, which means that \\( x \\) belongs to exactly one set in \\( \\mscrA \\).\n\n  \\SubProofOf*[def:binary_relation/reflexive]{reflexivity} Clearly \\( A_x = A_x \\), hence \\( x \\sim x \\).\n\n  \\SubProofOf*[def:binary_relation/symmetric]{symmetry} If \\( x \\sim y \\), then \\( A_x = A_y \\), which implies \\( A_y = A_x \\) and thus \\( x \\sim y \\).\n\n  \\SubProofOf*[def:binary_relation/transitive]{transitivity} If \\( x \\sim y \\) and \\( y \\in z \\), then \\( A_x = A_y = A_z \\) and thus \\( x \\sim z \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:relation_closures}\n  Let \\( R \\subseteq A^2 \\) be a binary relation on the set \\( A \\). We define several \\hyperref[def:closure_operator]{closure operators}:\n  \\begin{thmenum}\n    \\thmitem{def:relation_closures/reflexive} The \\term{reflexive closure} of \\( R \\) is\n    \\begin{equation*}\n      \\cl^R(R) \\coloneqq R \\cup \\Delta_X.\n    \\end{equation*}\n\n    \\thmitem{def:relation_closures/symmetric} The \\term{symmetric closure} of \\( R \\) is\n    \\begin{equation*}\n      \\cl^S(R) \\coloneqq R \\cup R^{-1}.\n    \\end{equation*}\n\n    \\thmitem{def:relation_closures/transitive} The \\term{transitive closure} \\( \\cl^T(R) \\) of \\( R \\) is\n    \\begin{equation*}\n      \\cl^T(R) \\coloneqq \\bigcup \\set{ R^k \\given k = 1, 2, \\ldots },\n    \\end{equation*}\n    where \\( R^k \\) is iterated \\hyperref[def:binary_relation/composition]{composition} of \\( R \\).\n\n    Note that this is very different from the transitive closure of a set defined in \\fullref{def:transitive_closure_of_a_set}.\n\n    A \\term{transitive reduction} of \\( R \\) is a \\hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{minimal} relation \\( Q \\subseteq R \\) such that \\( \\cl^T(Q) = \\cl^T(R) \\). If there exists a smallest such relation, it is the unique transitive reduction, and we denote it by \\( \\red^T(R) \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:relation_closures}\n  \\hyperref[def:relation_closures]{Binary relation closures} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:relation_closures/reflexive_relation} The symmetric and transitive closures of a reflexive relation are symmetric.\n    \\thmitem{thm:def:relation_closures/symmetric_relation} The reflexive and transitive closures of a symmetric relation are symmetric.\n    \\thmitem{thm:def:relation_closures/transitive_relation} The reflexive closure of a transitive relation is transitive. The symmetric closure of a transitive relation may not be transitive --- see \\fullref{ex:thm:def:relation_closures/symmetric_and_transitive}.\n\n    \\thmitem{thm:def:relation_closures/reflexive_and_symmetric} The reflexive and symmetric closures commute:\n    \\begin{equation}\\label{eq:thm:def:relation_closures/reflexive_and_symmetric}\n      \\cl^S \\cl^R(R) = \\cl^R \\cl^S(R).\n    \\end{equation}\n\n    \\thmitem{thm:def:relation_closures/reflexive_and_transitive} The transitive and reflexive closures commute:\n    \\begin{equation}\\label{eq:thm:def:relation_closures/reflexive_and_transitive}\n      \\cl^R \\cl^T(R) = \\cl^T \\cl^R(R).\n    \\end{equation}\n\n    \\thmitem{thm:def:relation_closures/symmetric_and_transitive} For the transitive and symmetric closures of \\( R \\) we have\n    \\begin{equation}\\label{eq:thm:def:relation_closures/symmetric_and_transitive}\n      \\cl^S \\cl^T(R) \\subseteq \\cl^T \\cl^S(R).\n    \\end{equation}\n\n    The converse holds if \\( R \\) is symmetric but not in general --- see \\fullref{ex:thm:def:relation_closures/symmetric_and_transitive}.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:relation_closures/reflexive_relation} Trivial.\n  \\SubProofOf{thm:def:relation_closures/symmetric_relation} Trivial.\n  \\SubProofOf{thm:def:relation_closures/transitive_relation} Trivial.\n  \\SubProofOf{thm:def:relation_closures/reflexive_and_symmetric} Trivial.\n  \\SubProofOf{thm:def:relation_closures/reflexive_and_transitive} The reflexive closure only adds pairs of the form \\( (x, x) \\). Thus, if \\( (x, y) \\in \\cl^T(\\cl^R(R)) \\) for \\( x \\neq y \\), then \\( (x, y) \\in \\cl^T(R) \\subseteq \\cl^R(\\cl^T(R)) \\).\n\n  Conversely, if \\( (x, y) \\in \\cl^R(\\cl^T(R)) \\) for \\( x \\neq y \\), then \\( (x, y) \\in \\cl^T(R) \\subseteq \\cl^R(\\cl^T(R)) \\).\n\n  \\SubProofOf{thm:def:relation_closures/symmetric_and_transitive} If \\( (x, y) \\in \\cl^S(\\cl^T(R)) \\), then we have the following possibilities:\n  \\begin{itemize}\n    \\item If \\( (x, y) \\in R \\), obviously \\( (x, y) \\in \\cl^T(\\cl^S(R)) \\).\n    \\item If \\( (x, y) \\in \\cl^T(R) \\setminus R \\), then there exists some natural number \\( k > 1 \\) such that \\( (x, y) \\in R^k \\).\n\n    Since \\( R^k \\subseteq [\\cl^S(R)]^k \\), as can be shown by induction, we have \\( (x, y) \\in [\\cl^S(R)]^k \\). We thus conclude that \\( (x, y) \\in \\cl^T(\\cl^S(R)) \\).\n\n    \\item Finally, if \\( (x, y) \\not\\in \\cl^T(R) \\), then \\( (y, x) \\in \\cl^T(R) \\). As in the previous step, we can show that \\( (y, x) \\in \\cl^T(\\cl^S(R))) \\). The latter set is symmetric, hence \\( (x, y) \\in \\cl^T(\\cl^S(R)) \\).\n  \\end{itemize}\n\n  Since \\( (x, y) \\) was arbitrary, we conclude that \\eqref{eq:thm:def:relation_closures/symmetric_and_transitive} holds.\n\n  Furthermore, if \\( R \\) is symmetric, then\n  \\begin{equation*}\n    \\cl^T \\cl^S(R)\n    =\n    \\cl^T(R)\n    \\reloset {\\ref{thm:def:relation_closures/reflexive_relation}} =\n    \\cl^S \\cl^T(R).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{example}\\label{ex:thm:def:relation_closures/symmetric_and_transitive}\n  We will show that symmetric and transitive closures of relations do not commute. This is also a consequence of the difference between \\hyperref[def:quiver_connectedness/weak]{weak} and \\hyperref[def:quiver_connectedness/strong]{strong} connectedness of quivers.\n\n  Consider the set \\( A = \\set{ a, b, c } \\) and the relation \\( R = \\set{ (a, b), (c, b) } \\).\n\n  It should be noted that \\( R \\) is \\hyperref[def:binary_relation/transitive]{transitive}. Thus,\n  \\begin{equation*}\n    \\cl^S(\\cl^T(R)) = \\cl^S(R) = R \\cup \\set{ (b, a), (b, c) }.\n  \\end{equation*}\n\n  The latter set is not transitive because \\( (a, b) \\) and \\( (b, a) \\) both belong to \\( \\cl^S(R) \\) and neither \\( (a, a) \\) nor \\( (b, b) \\) do not.\n\n  This shows that the converse of \\eqref{eq:thm:def:relation_closures/symmetric_and_transitive} does not hold in general.\n\\end{example}\n\n\\begin{proposition}\\label{thm:equivalence_closure}\n  The \\hyperref[def:relation_closures/reflexive]{reflexive}, \\hyperref[def:relation_closures/symmetric]{symmetric} and \\hyperref[def:relation_closures/transitive]{transitive} closure \\( \\cl^T \\cl^S \\cl^R (R) \\) of any relation \\( R \\) is an \\hyperref[def:equivalence_relation]{equivalence relation}.\n\n  This holds for any permutation of the closures as long as \\( \\cl^T \\) is applied \\hi{after} \\( \\cl^S \\). This latter restriction is due to \\fullref{thm:def:relation_closures/symmetric_and_transitive}.\n\\end{proposition}\n\\begin{proof}\n  Let \\( R \\subseteq A \\times B \\) be an arbitrary relation. By \\fullref{thm:def:relation_closures/reflexive_relation}, \\( \\cl^S \\cl^R (R) \\) is reflexive. It is also symmetric as the symmetric closure of \\( \\cl^R(R) \\).\n\n  Then the transitive closure \\( \\cl^T \\cl^S \\cl^R (R) \\) is also symmetric and reflexive by \\fullref{thm:def:relation_closures/reflexive_relation} and \\fullref{thm:def:relation_closures/symmetric_relation}.\n\n  Therefore, \\( \\cl^T \\cl^S \\cl^R (R) \\) is an equivalence relation.\n\\end{proof}\n", "meta": {"hexsha": "d932fe63c11c332589b4c343756bca4335f769e6", "size": 27891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/relations.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/relations.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/relations.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": 67.2072289157, "max_line_length": 479, "alphanum_fraction": 0.6892545983, "num_tokens": 8685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.6077520486860285}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{Backpropagation and Higher-order Gradients}\n\\author{Kazuki Yoshiyama}\n\\date{July 2020}\n\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\usepackage{mathtools}\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\begin{document}\n\n\\maketitle\n\n\\abstract{This is the mathematical notes for computing the first-order gradients of functions and higher-order gradients in terms of mathematical view.}\n\n\\section{Introduction}\n\\label{sec:intro}\n\nThis is the mathematical notes for computing the first-order gradients of functions and higher-order gradients. We can universally support the $n$-th order gradients, i.e., the infinite order gradients by definition of the first-order gradients and construction of the implementation of a computational graph. Note that the latter is out-of-scope in this technical notes. \\\\\n\nThe first-order gradients of many functions can be computed by the combination of other functions, and also there sometimes exists a periodic pattern among $n$-th order gradients of a function (e.g., $sin$ and $cos$ functions). Thus, we do not need to consider really messy derivation for $n$-th order gradients for almost all functions.\\\\\n\nThe function inputs are generally denoted by $x$, $w$ for trainable parameters, and $y$ for outputs. The first-order gradient operator is denoted by $d$, or $\\frac{\\partial L}{\\partial \\cdot}$ where $L$ is the objective in an optimization problem and $\\cdot$ is of the w.r.t.. The $n$-th gradient operator is denoted by $d_n := \\frac{\\partial L_n}{\\partial \\cdot}$. We generally use the gradient operator up to $d_2$ mainly because of the periodicity. In case of the first-order gradients, we generally omit the suffix for simpler notations.\\\\\n\n\nFrom the following section, a section shows a group of function, and subsection is for a specific function.\n\n\\section{Neural Network Layer}\n\\label{sec:Neural Network Layer}\n\n\\subsection{Affine (Linear)}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = Wx + b\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx &&= W^T dy \\label{eq:data_grad} \\\\\n  dW &&= dy x^T \\label{eq:filter_grad}\\\\\n  db &&= dy.\n\\end{eqnarray}\n\nIf we take a gradient further in case of the backward pass,\n\n\\begin{eqnarray}\n  d_2 x &&= (d_2d_1 W)^T d_1y \\\\\n  d_2 W &&= d_1y (d_2d_1 x)^T \\\\\n  d_2d_1 y &&= W (d_2d_1 x) + (d_2d_1 W) x + d_2d_1b.\n\\end{eqnarray}\n\nInterestingly, the first equation is same as \\eqref{eq:data_grad} as a function, the second equation is same as \\eqref{eq:filter_grad} also as a function, and finally the third equation is same as the forward pass definition of the affine, all are same as a function but with the different inputs. Thus, we can reuse the existing implementation, and also there are a cycle among the n-th order gradients.\\\\\n\nThis interesting pattern can also be seen in other functions, we sometimes note that in each function.\n\n\\subsection{Convolution}\n\nThe convolution is the same operation as affine's but within a receptive field. Thus, we can apply the same argument of the affine for the backward and higher-order gradients.\n\n% \\subsection{FusedConvolution}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   y = ReLU(Add(BatchNorm(x), z)).\n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   dx0 &&= dReLU(dy) \\\\\n%   dx_1 &&= dx0 \\\\\n%   dz &&= dx0 \\\\\n%   dx &&= dBatchNorm(dx_1).\n% \\end{eqnarray}\n\n\\subsection{DepthwiseConvolution}\n\nThe depthwise convolution is the same operation of the convolution in the forward and backward except that the convolution does not happens over the feature dimension. Thus, we can apply the same argument of the affine for the backward and higher-order gradients.\n\n\\subsection{Deconvolution}\nThe deconvolution is the opposite operation of the convolution in the forward and backward pass. Thus, we can apply the same argument of the affine for the backward and higher-order gradients. The only exception is the padding case. For some padding patterns, we can not use the directly opposite operations.\n\n\\subsection{DepthwiseDeconvolution}\n\nThe depthwise convolution is the same operation of the deconvolution in the forward and backward except that the convolution does not happens over the feature dimension. Thus, we can apply the same argument of the affine for the backward and higher-order gradients.\n\n\\subsection{RNN}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.\n\\end{eqnarray}\n\nThis is a composite function of affines and non-linearity. Thus, we can reuse those functions.\n\n\\subsection{LSTM}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n\nThis is a composite function of affines and non-linearity. Thus, we can reuse those functions.\n\n\\subsection{GRU}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n\nThis is a composite function of affines and non-linearity. Thus, we can reuse those functions.\n\n\n\\section{Pooling}\n\n\\subsection{MaxPooling}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i_1, i_2} = \\max_{k_1, k_2 \\in K} (x_{i_1 + k_1, i_2 + k_2}).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{i_1 + k_1, i_2 + k_2} &&= dy_{i_1, i_2}, \\\\\n  k_1, k_2 &&= \\arg \\max_{k_1, k_2 \\in K} (x_{i_1 + k_1, i_2 + k_2}).\n\\end{eqnarray}\n\nThe second order gradient is the maxpooling of $d_2d_1 x_{i_1 + k_1, i_2 + k_2}$ again. Thus, we have a periodic relationship the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\n\n\n\\subsection{AveragePooling}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i_1, i_2} = \\frac{1}{K_1 K_2} \\sum_{k1} \\sum_{k2} x_{i_1 + k_1, i_2 + k_2}    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{i_1 + k_1, i_2 + k_2} = dy_{i_1, i_2} \\times \\frac{1}{K_1K_2}.\n\\end{eqnarray}\n\nNote that the backward of the average pooling is simply the broadcast in the receptive field and multiplication.\n\nThe second order gradient is the average pooling of $d_2d_1 x_{i_1 + k_1, i_2 + k_2}$ again. Thus, we have a periodic relationship of the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\n\n\n\\subsection{GlobalAveragePooling}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i_1, i_2} = \\frac{1}{K_1 K_2} \\sum_{k1} \\sum_{k2} x_{i_1 + k_1, i_2 + k_2}    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{i_1 + k_1, i_2 + k_2} = dy_{i_1, i_2} \\times \\frac{1}{K_1K_2}.\n\\end{eqnarray}\n\nNote that the backward of the global average pooling is simply the broadcast in the receptive field (over input feature map) and multiplication.\nThe second order gradient is the global average pooling of $d_2d_1 x_{i_1 + k_1, i_2 + k_2}$ again. Thus, we have a periodic relationship the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\n\n\\subsection{SumPooling}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i_1, i_2} = \\sum_{k1} \\sum_{k2} x_{i_1 + k_1, i_2 + k_2}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{i_1 + k_1, i_2 + k_2} = d y_{i_1, i_2}.\n\\end{eqnarray}\n\nNote that the backward of the sum pooling is simply the broadcast in the receptive field.\n\nThe second order gradient is the sum pooling of $d_2d_1 x_{i_1 + k_1, i_2 + k_2}$ again. Thus, we have a periodic relationship the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\n\n\n\\subsection{Unpooling}\nUnpooling is the broadcast in the receptive field. \\\\ \\\\\n%\nForward pass:\n\n\\begin{eqnarray}\n  y_{k_1 i_1 + j_1, k_2 i_2 + j_2} = x_{i_1, i_2}\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{i_1, i_2} = \\sum_{k1} \\sum_{k2} dy_{k_1 i_1 + j_1, k_2 i_2 + j_2}\n\\end{eqnarray}\n\nThe second order gradient is the unpooling of $d_2d_1 x_{i_1, i_2}$ again. Thus, we have a periodic relationship the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\n\n\\subsection{Embed}\nEmbed is the affine function but with a fixed look-up indices. \\\\ \\\\\n%\n\\begin{eqnarray}\n  y = Wx.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dW = dy x^T.\n\\end{eqnarray}\n%\nIf we take a gradient further in case of the backward pass,\n\n\\begin{eqnarray}\n  d_2d_1 y = (d_2d_1 W) x.\n\\end{eqnarray}\n\n\n\\section{Activation Function}\n\\label{sec:Neural Network Activation Functions}\n\n\\subsection{Sigmoid}\n\nForward pass:\n\n\\begin{eqnarray}\n  \\sigma(x) = \\frac{1}{1 + \\exp(-x)}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\times \\sigma(x) (1 - \\sigma(x)).\n\\end{eqnarray}\n\n\n\\subsection{Swish}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i &&= \\frac{x_i}{1 + \\exp(-x_i)} \\\\\n      &&= x_i \\sigma(x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\times \\sigma(x_i) (1 + x_i (1 - \\sigma(x_i))).\n\\end{eqnarray}\n\n\\subsection{Tanh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\tanh (x_i).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i (1 - \\tanh^2(x_i)).\n\\end{eqnarray}\n\n\n\\subsection{ReLU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\max (0, x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\begin{cases}\n     1 & (x > 0) \\\\\n     0 & ({\\rm otherwise})\n  \\end{cases}.\n\\end{eqnarray}\n\n\n\\subsection{LeakyReLU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\alpha * \\min(0, x_i) + \\max (0, x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\begin{cases}\n     1      & (x > 0) \\\\\n     \\alpha & ({\\rm otherwise})\n  \\end{cases}. \n\\end{eqnarray}\n\n\n\\subsection{Softmax}\n\nForward pass:\n\n\\begin{eqnarray}\n  \\sigma(x_i) = \\frac{\\exp(x_i)}{\\sum_j \\exp(x_j)}\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_j &&= \\sum_i dy_i \\sigma(x_i) (\\delta_{ij} - \\sigma(x_j)) \\\\\n       &&= dy_j \\sigma(x_j) - \\sigma(x_j) \\sum_i dy_i \\sigma(x_i).\n\\end{eqnarray}\n\n\n\\subsection{LogSoftmax}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\log \\frac{\\exp(x_i)}{\\sum_j \\exp(x_j)}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_j &&= \\sum_i dy_i (\\delta_{ij} - \\sigma(x_j)) \\\\\n       &&= dy_j  - \\sigma(x_j) \\sum_i dy_i.\n\\end{eqnarray}\n\n\n\\subsection{ELU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i= \\left\\{\n  \\begin{array}{ll}\n    x_i & (x > 0)\\\\\n    \\alpha (\\exp(x_i) - 1) & (x \\leq 0)\n  \\end{array} \\right..\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i= dy_i \\left\\{\n  \\begin{array}{ll}\n    1 & (x > 0)\\\\\n    \\alpha \\exp(x_i) & (x \\leq 0)\n  \\end{array} \\right.. \n\\end{eqnarray}\n\n\n\\subsection{SELU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i= \\lambda \\left\\{\n  \\begin{array}{ll}\n    x_i & (x > 0)\\\\\n    \\alpha (\\exp(x_i) - 1) & (x \\leq 0)\n  \\end{array} \\right..\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i= dy_i \\lambda \\left\\{\n  \\begin{array}{ll}\n    1 & (x > 0)\\\\\n    \\alpha \\exp(x_i) & (x \\leq 0)\n  \\end{array} \\right.. \n\\end{eqnarray}\n\n\n\\subsection{CReLU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = [\\max(0, x), \\max(0, -x)].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = \n  dy_0 \\left\\{\n  \\begin{array}{ll}\n    1 & (x > 0)\\\\\n    0 & (x \\leq 0)\n  \\end{array} \\right. \n  - \n  dy_1 \\left\\{\n  \\begin{array}{ll}\n    1 & (-x > 0)\\\\\n    0 & (-x \\leq 0)\n  \\end{array} \\right.,\n\\end{eqnarray}\n%\nwhere $dy_0$ and $dy_1$ are corresponding parts by the concatenation.\n\n\n\\subsection{CELU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i= [elu(x_i), elu(-x_i)].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = \n  dy_0 \\left\\{\n  \\begin{array}{ll}\n    1 & (x > 0)\\\\\n    \\alpha \\exp(x_i) & (x \\leq 0)\n  \\end{array} \\right. \n  - \n  dy_1 \\left\\{\n  \\begin{array}{ll}\n    1 & (-x > 0)\\\\\n    \\alpha \\exp(-x_i) & (-x \\leq 0)\n  \\end{array} \\right.,\n\\end{eqnarray}\n%\nwhere $dy_0$ and $dy_1$ are corresponding parts by the concatenation.\n\n\\subsection{PReLU}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\max(0, x_i) + w_i \\min(0, x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    1   & (x > 0)\\\\\n    w_i & (x \\leq 0)\n  \\end{array} \\right., \\\\\n  w_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    0   & (x > 0)\\\\\n    x_i & (x \\leq 0)\n  \\end{array} \\right.\n\\end{eqnarray}\n%\nTake care that we have to take the summation over the other dimensions other than $i$.\n%\nIn case of the shared $w$,\n\n\\begin{eqnarray}\n  dx_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    1   & (x > 0)\\\\\n    w_i & (x \\leq 0)\n  \\end{array} \\right., \\\\\n  w &&= \\sum_ i dy_i \\left\\{\n  \\begin{array}{ll}\n    0   & (x > 0)\\\\\n    x_i & (x \\leq 0)\n  \\end{array} \\right.\n\\end{eqnarray}\n%\nTake care that we also have to take the summation over the other dimensions other than $i$.\n\n\\subsection{GELU}\n\nForward pass:\n\n\\begin{eqnarray}\n  GELU(x) &&= x P(X \\leq  x) = x \\Phi (x)  \\\\\n   && \\approx 0.5x \\times (1 + \\tanh \\left( \\sqrt{\\frac{2}{\\pi}}(x + 0.044715 x^3) \\right))\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx &&= dy \\left( 0.5u + 0.5x (1 - \\tanh^2(v))\\sqrt{2/\\pi} (1 + 0.134145 x^2) \\right) \\\\\n  u &&= 1 + \\tanh (v) \\\\\n  v &&= \\sqrt{2/\\pi} (x + 0.044715 x^3).\n\\end{eqnarray}\n\n\n\\subsection{ReLU6}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\min(\\max(0,x), 6).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\begin{cases}\n     0 & (x >= 6) \\\\\n     1 & ({\\rm otherwise}) \\\\\n     0 & (x <= 0)\n  \\end{cases}.\n\\end{eqnarray}\n\n\\subsection{HardSigmoid}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\begin{cases}\n     1 & (x >= 2.5) \\\\\n     0.2 x + 0.5 & ({\\rm otherwise}) \\\\\n     0 & (x <= -2.5)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\begin{cases}\n     0 & (x > 2.5) \\\\\n     0.2 & ({\\rm otherwise}) \\\\\n     0 & (x < -2.5)\n  \\end{cases}. \n\\end{eqnarray}\n\n\n\\subsection{HardTanh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = x \\begin{cases}\n     1 & (x > 1) \\\\\n     x & ({\\rm otherwise}) \\\\\n     -1 & (x < -1)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\begin{cases}\n     0 & (x >= 1) \\\\\n     1 & ({\\rm otherwise}) \\\\\n     0 & (x <= -1)\n  \\end{cases}.\n\\end{eqnarray}\n\n\n\\subsection{LogSigmoid}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i &&= \\log(1 / (1 + \\exp(-x_i)))  \\\\\n      &&= \\log(\\sigma(x_i)).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i (1 - \\sigma(x_i)). \n\\end{eqnarray}\n\n\\subsection{SoftPlus}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\log(1+\\exp(x_i)).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{\\exp(x_i)}{1 + \\exp(x_i)}.\n\\end{eqnarray}\n\n\\subsection{SoftSign}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = x/(1+|x|).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\frac{1}{(1 + |x)|)^2}.\n\\end{eqnarray}\n\n\n\\subsection{TanhShrink}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = x - \\tanh(x).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\left(1 - (1 - \\tanh^2(x))\\right).\n\\end{eqnarray}\n\n\\subsection{Sinc}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\begin{cases}\n     \\frac{\\sin(x)}{x} & (x \\neq 0) \\\\\n     1 & ({\\rm otherwise})\n  \\end{cases}. \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\begin{cases}\n     \\frac{\\cos(x)  - sinc(x)}{x} & (x \\neq 0) \\\\\n     0 & ({\\rm otherwise})\n  \\end{cases}. \\end{eqnarray}\n\n\n\\section{Normalization}\n\\label{sec:Normalization}\n\n\\subsection{BatchNormalization}\n\nForward pass (Training):\n\n\\begin{eqnarray}\n  \\mu &&= \\frac{1}{M} \\sum x_i \\\\\n  \\sigma^2 &&= \\frac{1}{M} \\left(\\sum x_i - \\mu\\right)^2 \\\\\n  \\hat{x}_i &&= \\frac{x_i - \\mu}{\\sqrt{\\sigma^2 + \\epsilon}} \\\\\n  y_i &&= \\hat{x}_i \\gamma + \\beta.\n\\end{eqnarray}\n%\nForward pass (Test):\n\n\\begin{eqnarray}\n  y_i = \\gamma \\frac{x_i - \\mu_r}{\\sqrt{\\sigma_r^2 + \\epsilon}} + \\beta\n\\end{eqnarray}\n%\nBackward pass (Training):\n\n\\begin{eqnarray}\n  d\\hat{x}_i &&= dy_i \\cdot \\gamma, \\\\\n  d\\sigma^2 &&= \\sum_{i=1}^m d\\hat{x}_i \\cdot (x_i - \\mu) \\cdot \\frac{-1}{2}(\\sigma^2 + \\epsilon)^{-3/2}, \\\\\n  d\\mu &&= \\frac{-1}{\\sqrt{\\sigma^2 + \\epsilon}} \\sum_{i=1}^{m} d\\hat{x}_i, \\\\\n  dx_i &&= d\\hat{x}_i \\frac{1}{\\sqrt{\\sigma^2 + \\epsilon}} + d\\sigma^2 \\frac{2(x_i - \\mu)}{m} + d\\mu \\cdot \\frac{1}{m}, \\\\\n  d\\gamma &&= \\sum_{i=1}^{m} dy_i \\cdot \\hat{x}_i, \\\\\n  d\\beta &&= \\sum_{i=1}^{m} dy_i.\n\\end{eqnarray}\n\nNote \\href{https://arxiv.org/abs/1502.03167}{the original batch normalization paper} includes the redundant term in the gradient w.r.t. the mean input. It is explicitly excluded in the above gradient derivation.\\\\\\\\\n%\nBackward pass (Test):\n\n\\begin{eqnarray}\n  dx_i &&= dy_i \\frac{\\gamma}{\\sqrt{\\sigma_r^2 + \\epsilon}} \\\\\n  d\\gamma &&= \\sum_i dy_i \\frac{x_i - \\mu_r}{\\sqrt{\\sigma_r^2 + \\epsilon}} \\\\\n  d\\beta &&= \\sum_i dy_i.\n\\end{eqnarray}\n\n\\subsection{SyncBatchNormalization}\n\nFormulation is same as the batch normalization, but the running mean/variance are computed over multiple devices.\n\n\\subsection{WeightNormalization}\n\nForward pass (for one filter):\n\n\\begin{eqnarray}\n  && \\hat{v} = g \\odot v \\odot s^{-1/2}, \\\\\n  && s = \\sum_i v_i^2 + \\epsilon \\\\\n  && g \\in \\mathbb{R}, v \\in \\mathbb{R}^D\n\\end{eqnarray}\n%\nBackward pass (for one filter):\n\n\\begin{eqnarray}\n  dv_j &&= d\\hat{v}_j \\odot g \\odot s^{-1/2} - \\left( \\sum_i d\\hat{v}_i v_i \\right) \\odot g \\odot s^{-3/2} \\odot v_j, \\\\\n  dg &&= \\sum_{i} d\\hat{v}_i v_i \\odot s^{-1/2}.\n\\end{eqnarray}\n\n\\subsection{Norm}\n\nForward pass:\n\n\\begin{eqnarray}\n    y = \\|x\\|_p = \\left( \\sum_i |x_i|^p \\right)^{\\frac{1}{p}}\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n    dx_i = dy \\times \\left( \\sum_i |x_i|^p \\right)^{\\frac{1}{p} - 1} \\times\n    \\begin{cases}\n     |x_i|^{p-1} & (x_i >= 0) \\\\\n     -|x_i|^{p-1} & ({\\rm otherwise})\n  \\end{cases}. \n\\end{eqnarray}\n\n\\subsection{NormNormalize}\n\nForward pass:\n\n\\begin{eqnarray}\n    y &&= x_i \\times \\left( \\sum_i |x_i|^p \\right)^{-\\frac{1}{p}} \\\\\n      &&= \\frac{x_i}{\\|x\\|_p}\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n    dx_i = dy \\times \\left( \\sum_i |x_i|^p \\right)^{-\\frac{1}{p}} + dy \\times \\left( \\sum_i |x_i|^p \\right)^{-\\frac{1}{p} - 1} \\times\n    \\begin{cases}\n     x_i^2 & (x_i >= 0) \\\\\n     -x_i^2 & ({\\rm otherwise})\n  \\end{cases}. \n\\end{eqnarray}\n\n\\section{Reduction}\n\\label{sec:Reduction}\n\n\\subsection{Sum}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\sum_{i} x_i.\n\\end{eqnarray}\n%\nBackward pass (broadcast):\n\n\\begin{eqnarray}\n  dx_i = dy.\n\\end{eqnarray}\n\n\n\\subsection{Mean}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\sum_{i}^{N} x_i / N.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy / N.\n\\end{eqnarray}\n\n\n\\subsection{Max}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\max_{i} x_i.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy \\begin{cases}\n     1 & (i = \\arg\\max_i (x_i) \\\\\n     0 & ({\\rm otherwise})\n  \\end{cases}.\n\\end{eqnarray}\n\n\n\\subsection{Min}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\min_{i} x_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy \\begin{cases}\n     1 & (i = \\arg\\min_i (x_i) \\\\\n     0 & ({\\rm otherwise})\n  \\end{cases}. \n\\end{eqnarray}\n\n\n\\subsection{Prod}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\Pi_{i} x_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy \\Pi_{j \\neq i} x_j.\n\\end{eqnarray}\n\n\\subsection{Cumsum}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\sum_{j < i} x_j.\n\\end{eqnarray}\n%\nBackward pass (reverse cumsum):\n\n\\begin{eqnarray}\n  dx_k = \\sum_{i > k} dy_i.\n\\end{eqnarray}\n\n\\subsection{Cumprod}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\Pi_{j < i} x_j\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_k = \\sum_{i > k} (dy_i \\Pi_{j < i, j \\neq k} x_j).\n\\end{eqnarray}\n\n\n\\section{Arithmetic}\n\\label{sec:Arithmetic}\n\n\\subsection{Add2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x^{(0)}_i + x^{(1)}_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i, \\\\\n  dx^{(1)}_i = dy_i.\n\\end{eqnarray}\n\n\n\\subsection{AddN}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x^{(0)}_i + . . . + x^{(n-1)}_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n   dx^{(m)}_i = dy_i\n\\end{eqnarray}\n\n\\subsection{Sub2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x^{(0)}_i - x^{(1)}_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i, \\\\\n  dx^{(1)}_i = -dy_i. \n\\end{eqnarray}\n\n\n\\subsection{Mul2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x^{(0)}_i x^{(1)}_i.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\times x^{(1)}_i, \\\\\n  dx^{(1)}_i = dy_i \\times x^{(0)}_i.  \n\\end{eqnarray}\n\n\n\\subsection{MulN}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x^{(0)}_i . . . x^{(n-1)}_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(m)}_i = dy_i \\Pi_{n \\neq m} x^{(n)}_i.\n\\end{eqnarray}\n\n\n\\subsection{Div2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\frac{x^{(0)}_i} {x^{(1)}_i}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i &&= dy_i x^{(1)}_i, \\\\\n  dx^{(1)}_i &&= - dy_i \\frac{x^{(0)}_i}{(x^{(1)}_i) ^2}.\n\\end{eqnarray}\n\n\n\\subsection{Pow2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = {(x^{(0)}_i)} ^ {x^{(1)}_i}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i &&= dy_i \\times x^{(1)}_i \\times {(x^{(0)}_i)} ^ {x^{(1)}_i -1}, \\\\\n  dx^{(1)}_i &&= dy_i \\times {(x^{(0)}_i)} ^ {x^{(1)}_i} \\times  \\log{x^{(0)}_i}.\n\\end{eqnarray}\n\n\n\\subsection{AddScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x_i + v.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i.\n\\end{eqnarray}\n\n\n\\subsection{MulScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = v x_i.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i v.\n\\end{eqnarray}\n\n\n\\subsection{PowScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = (x_i) ^ v.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\times v \\times (x_i) ^ {v - 1}.\n\\end{eqnarray}\n\n\n\\subsection{RSubScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = v - x_i.    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = - dy_i \n\\end{eqnarray}\n\n\n\\subsection{RDivScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\frac{v}{x_i}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = - dy_i \\frac{v}{x_i^2}.\n\\end{eqnarray}\n\n\n\\subsection{RPowScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = v ^ {x_i}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\times v ^ {x_i} \\times \\log{v}.\n\\end{eqnarray}\n\n\\section{Logical}\n\\label{sec:Logical}\n\n\\subsection{Sign}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\begin{cases}\n    1  & (x > 0) \\\\\n    -1 & (x < 0) \\\\\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass (Zero sub-gradient):\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n%\nBackward pass (Straight-Through-Estimator):\n\n\\begin{eqnarray}\n  dx = dy. \n\\end{eqnarray}\n\n\\subsection{Minimum2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\min(x^{(0)}_i, x^{(1)}_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\begin{cases}\n    1  & (x^{(0)}_i < x^{(1)}_i) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\\\\\n  dx^{(1)}_i = dy_i \\begin{cases}\n    1  & (x^{(1)}_i < x^{(0)}_i) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\n\\end{eqnarray}\n\n\\subsection{Maximum2}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\max(x^{(0)}_i, x^{(1)}_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\begin{cases}\n    1  & (x^{(0)}_i > x^{(1)}_i) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\\\\\n  dx^{(1)}_i = dy_i \\begin{cases}\n    1  & (x^{(1)}_i > x^{(0)}_i) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\n\\end{eqnarray}\n\n\n\\subsection{MinimumScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\min(x_i, v).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\begin{cases}\n    1  & (x^{(0)}_i < v) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\\\\ \n\\end{eqnarray}\n\n\\subsection{MaximumScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\max (x_i, v).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\begin{cases}\n    1  & (x^{(0)}_i > v) \\\\\n    0 & ({\\rm otherwise})\n  \\end{cases}\\\\ \n\\end{eqnarray}\n\n\n\\subsection{LogicalAnd}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1 & (x^{(0)}_i \\neq 0 \\;\\&\\; x^{(1)}_i \\neq 0) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{LogicalOr}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    0 & (x^{(0)}_i = 0 \\;\\&\\; x^{(1)}_i = 0) \\\\\n    1 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\\subsection{LogicalXor}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1 & (x^{(0)}_i = 0 \\;\\&\\; x^{(1)}_i = 0) \\\\\n    1 & (x^{(0)}_i \\neq 0 \\;\\&\\; x^{(1)}_i \\neq 0) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{Equal}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1 & (x^{(0)}_i = x^{(1)}_i) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{NotEqual}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    0 & (x^{(0)}_i = x^{(1)}_i) \\\\\n    1 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{GreaterEqual}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1  & (x^{(0)}_i \\geq x^{(1)}_i) \\\\\n    0 & (x^{(0)}_i < x^{(1)}_i)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\\subsection{Greater}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1  & (x^{(0)}_i > x^{(1)}_i) \\\\\n    0 & (x^{(0)}_i \\leq x^{(1)}_i)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{LessEqual}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1  & (x^{(0)}_i \\leq x^{(1)}_i) \\\\\n    0 & (x^{(0)}_i > x^{(1)}_i)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{Less}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x^{(0)}_i,x^{(1)}_i) = \\begin{cases}\n    1  & (x^{(0)}_i < x^{(1)}_i) \\\\\n    0 & (x^{(0)}_i \\geq x^{(1)}_i)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{LogicalAndScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1 & (x_i \\neq 0 \\;\\&\\; v \\neq 0) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{LogicalOrScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    0 & (x_i = 0 \\;\\&\\; v = 0) \\\\\n    1 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{LogicalXorScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1 & (x_i = 0 \\;\\&\\; v = 0) \\\\\n    1 & (x_i \\neq 0 \\;\\&\\; v \\neq 0) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{EqualScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1 & (x_i = v) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{NotEqualScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    0 & (x_i = v) \\\\\n    1 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{GreaterEqualScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1  & (x_i \\geq v \\\\\n    0 & (x_i < v\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{GreaterScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1  & (x_i > v \\\\\n    0 & (x_i \\leq v\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{LessEqualScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1  & (x_i \\leq v) \\\\\n    0 & (x_i > v)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{LessScalar}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i,v) = \\begin{cases}\n    1  & (x_i < v) \\\\\n    0 & (x_i \\geq v)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.\n\\end{eqnarray}\n\n\\subsection{LogicalNot}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x_i) = \\begin{cases}\n    1 & (x_i = 0) \\\\\n    0 & {\\rm otherwise}\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)}_i = 0.\n\\end{eqnarray}\n\n\\subsection{Where}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\begin{cases}\n    x_{true}  & (cond) \\\\\n    x_{false} & (not \\ cond)\n  \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{true} = dy \\begin{cases}\n    1  & (cond) \\\\\n    0 & (not\\ cond)\n  \\end{cases}, \\\\\n  dx_{false} = dy \\begin{cases}\n    0 & (cond) \\\\\n    1 & (not\\ cond)\n  \\end{cases}.\n\\end{eqnarray}\n\n\n\\section{Math}\n\\label{sec:Math}\n\n\\subsection{Constant}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = const.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)} = 0.\n\\end{eqnarray}\n\n\\subsection{Arange}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = arange(start, stop, step)\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(\\cdot)} = 0.\n\\end{eqnarray}\n\n\\subsection{Abs}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = |x_i|    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\begin{cases}\n    1 & (x \\geq 0) \\\\\n    -1 & ({\\rm otherwise})\n  \\end{cases}.\n\\end{eqnarray}\n\n\n\\subsection{Exp}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\exp(x_i).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\exp(x_i).  \n\\end{eqnarray}\n\n\n\\subsection{Log}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\ln(x_i).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{x_i}.\n\\end{eqnarray}\n\n\n\\subsection{Identity}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = x\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy.\n\\end{eqnarray}\n\n\n\\subsection{BatchMatmul}\n\nForward pass:\n\n\\begin{eqnarray}\n  R = P Q.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dP = dR \\ Q^T, \\\\\n  dQ = P^T \\ dR.\n\\end{eqnarray}\n%\nThis is the case where no transpose occurs. If there is a transpose operation, we have to consider the order of the matrix multiplication and the transpose of the operand matrices.\n\nSimilar to the affine in the case of $n$-th order gradients, there is also periodic pattern. Thus, we can reuse the forward pass of the batch matmul for computing $n$-th order gradients.\n\n\\subsection{Round}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = round(x_i).    \n\\end{eqnarray}\n%\nBackward pass (Zero sub-gradient):\n\n\\begin{eqnarray}\n  dx_i = 0.\n\\end{eqnarray}\n%\nBackward pass (Straight-Through-Estimator):\n\n\\begin{eqnarray}\n  dx_i = dy_i. \n\\end{eqnarray}\n\n\n\\subsection{Ceil}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = ceil(x_i).  \n\\end{eqnarray}\n%\nBackward pass (Zero sub-gradient):\n\n\\begin{eqnarray}\n  dx_i = 0.\n\\end{eqnarray}\n%\nBackward pass (Straight-Through-Estimator):\n\n\\begin{eqnarray}\n  dx_i = dy_i. \n\\end{eqnarray}\n\n\\subsection{Floor}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = floor(x_i).\n\\end{eqnarray}\n%\nBackward pass (Zero sub-gradient):\n\n\\begin{eqnarray}\n  dx_i = 0.\n\\end{eqnarray}\n%\nBackward pass (Straight-Through-Estimator):\n\n\\begin{eqnarray}\n  dx_i = dy_i. \n\\end{eqnarray}\n\n\\subsection{Sin}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\sin (x_i).    \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\cos(x_i).\n\\end{eqnarray}\n\n\n\\subsection{Cos}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\cos (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = -dy_i \\sin(x_i).\n\\end{eqnarray}\n\n\n\\subsection{Tan}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\tan (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{\\cos(x_i)^2}. \n\\end{eqnarray}\n\n\n\\subsection{Sinh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\sinh (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\cosh(x_i).\n\\end{eqnarray}\n\n\n\\subsection{Cosh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\cosh (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\sinh(x_i).\n\\end{eqnarray}\n\n\n\\subsection{ASin}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = asin (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{\\sqrt{1 - x^2}}.\n\\end{eqnarray}\n\n\n\\subsection{ACos}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = acos (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{-1}{\\sqrt{1 - x^2}}.\n\\end{eqnarray}\n\n\n\\subsection{ATan}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = atan (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{1 + x^2}.\n\\end{eqnarray}\n\n\n\\subsection{ATan2}\n\nForward pass:\n\n\\begin{eqnarray}\n  z = atan2(y, x) = 2 \\times arctan(\\frac{y}{\\sqrt{x^2 + y^2} + x})\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dy = dz \\frac{x}{x^2 + y^2}, \\\\\n  dx = dz \\frac{-y}{x^2 + y^2}\n\\end{eqnarray}\n\n\n\\subsection{ASinh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = asinh (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{\\sqrt{x^2 + 1}}.\n\\end{eqnarray}\n\n\n\\subsection{ACosh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = acosh (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{\\sqrt{x^2 - 1}}.\n\\end{eqnarray}\n\n\\subsection{ATanh}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = atanh (x_i).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dy_i \\frac{1}{1 - x^2}.\n\\end{eqnarray}\n\n\n\\section{Array Manipulation}\n\\label{sec:Array Manipulation}\n\nThe backward of array manipulations is simply that the in-coming gradients go back to the location where the data comes from in the forward pass. Sometimes, there are the opposite relationship like the backward pass of the concatenation is the forward pass of the split.\n\n\\subsection{Concatenate}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = [x_1, \\ldots, x_n].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  [dx_1, \\ldots, dx_n] = dy.\n\\end{eqnarray}\n\n\n\\subsection{Split}\n\nForward pass:\n\n\\begin{eqnarray}\n  [y_1, \\ldots, y_n] = x.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = [dy_1, \\ldots, dy_n].\n\\end{eqnarray}\n\n\n\\subsection{Stack}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = [x_1, \\ldots, x_n].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  [dx_1, \\ldots, dx_n] = dy.\n\\end{eqnarray}\n\n\n\\subsection{Slice}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = x[start_1:stop_1:step_1, ..., start_n:stop_n:step_n]\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx[start_1:stop_1:step_1, ..., start_n:stop_n:step_n] = dy.\n\\end{eqnarray}\n\n\n\\subsection{Pad}\n\nForward pass (constant):\n\n\\begin{eqnarray}\n  v(x) = \\begin{cases}\n    c & (x < 0) \\\\\n    u(x) & ({\\rm otherwise}) \\\\\n    c & (x > W - 1)\n    \\end{cases}.\n\\end{eqnarray}\n%\nBackward pass (constant):\n\n\\begin{eqnarray}\n  du(x) = dv(x) \\begin{cases}\n    0 & (x < 0) \\\\\n    1 & ({\\rm otherwise}) \\\\\n    0 & (x > W - 1)\n    \\end{cases}.\n\\end{eqnarray}\n\n\n\\subsection{Transpose}\n\nForward pass:\n\n\\begin{eqnarray}\n  y[i_1\\ldots i_N] = x[T(i_1), \\ldots T(i_N)].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx[T(i_1), \\ldots T(i_N)] = dy[i_1, \\ldots i_N].\n\\end{eqnarray}\n\n\n\\subsection{Broadcast}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = x.\n\\end{eqnarray}\n%\nBackward pass (sum):\n\n\\begin{eqnarray}\n  dx = \\sum_i dy_i.\n\\end{eqnarray}\n\n\n\\subsection{Tile}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = [x_1, \\ldots, x_n, x_{n+1}, \\ldots, x_{2n}, \\ldots, x_{K \\times (n-1) + 1}, \\ldots, x_{K \\times n}]\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = \\sum_{j, mod(j, n) = i} dy_j.\n\\end{eqnarray}\n\n\n\\subsection{OneHot}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n\n\n\\subsection{Flip}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n\n\n\\subsection{Shift}\n\nForward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  TODO.  \n\\end{eqnarray}\n\n\n\\subsection{Sort}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = sort(x)\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy[index\\ of\\ sort(x)].\n\\end{eqnarray}\n\n\\subsection{Reshape}\n\nForward pass:\\\\\n\nShape of an NdArray changes and strides consequently. \\\\ \\\\\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dy_i = dx_i, \n\\end{eqnarray}\n\nShape of an NdArray changes and strides consequently. \n\n\n\\subsection{MatrixDiag}\n\nForward pass:\n\n\\begin{eqnarray}\n  \\begin{bmatrix}\n    y_1 & & \\\\\n    & \\ddots & \\\\\n    & & y_n \n  \\end{bmatrix}\n  = [x_1, \\ldots, x_n].\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  [dx_1, \\ldots, dx_n] = \n  \\begin{bmatrix}\n    dy_1 & & \\\\\n    & \\ddots & \\\\\n    & & dy_n \n  \\end{bmatrix} \n\\end{eqnarray}\n\n\n\\subsection{MatrixDiagPart}\n\nForward pass:\n\n\\begin{eqnarray}\n  [y_1, \\ldots, y_n] = \n  \\begin{bmatrix}\n    x_1 & & \\\\\n    & \\ddots & \\\\\n    & & x_n \n  \\end{bmatrix}\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  \\begin{bmatrix}\n    dx_1 & & \\\\\n    & \\ddots & \\\\\n    & & dx_n \n  \\end{bmatrix}\n  = [dy_1, \\ldots, dy_n].\n\\end{eqnarray}\n\n\n\\subsection{BatchInv}\n\nForward pass:\n\n\\begin{eqnarray}\n  Y = X^{-1}.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dX = -(X^{-1})^T dY (X^{-1})^T\n\\end{eqnarray}\n\n\n\\subsection{BatchDet}\n\nForward pass:\n\n\\begin{eqnarray}\n  Y = det(X).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dX = dY \\odot det(X) \\odot (X^{-1})^T.\n\\end{eqnarray}\n\n\\subsection{BatchLogdet}\n\nForward pass:\n\n\\begin{eqnarray}\n  Y = \\log(|\\det(X)|).\n\\end{eqnarray}\n%\nBackward pass:\n\nComposite backward of $BatchDet \\rightarrow Abs \\rightarrow Log$.\n\n\\subsection{GatherNd}\n\nForward pass:\n\n\\begin{eqnarray}\n  U = GatherNd(O, I).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dO = ScatterNd(dU, I).\n\\end{eqnarray}\n\n\n\\subsection{ScatterNd}\n\nForward pass:\n\n\\begin{eqnarray}\n  O = ScatterNd(U, I).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dU = GatherNd(dO, I).\n\\end{eqnarray}\n\n\n\\section{Signal Processing}\n\\label{sec:Signal Processing}\n\n\\subsection{Linear interpolate}\n\nNotation of the linear interpolation function s slightly different from the others. Given the real-number query points $x, y$ on the 2D-spatial feature $u$, the interpolation coefficients are computed as\n\n\\begin{eqnarray}\n  p_1 &=& x - \\floor*{x}\\\\\n  p_0 &=& 1 - p_1 \\\\\n  q_1 &=& y - \\floor*{y}\\\\\n  q_0 &=& 1 - q_1.\n\\end{eqnarray}\n%\nWhere-to-look, or where-to-fetch on the grid feature $u$ are denoted as\n\\begin{eqnarray}\n  x_0 &=& \\floor*{x} \\\\\n  x_1 &=& 1 - x_0 \\\\\n  y_0 &=& \\floor*{y} \\\\\n  y_1 &=& 1 - y_0.\n\\end{eqnarray}\n%\nSee \\href{https://en.wikipedia.org/wiki/Bilinear_interpolation}{the bilinear interpolation} for visual understanding. Then,  \\\\ \\\\\n%\nForward pass:\n\n\\begin{eqnarray}\n  v &=& p_0 * q_0* u(x_0, y_0) \\\\\n  &+& p_0 * q_1 * u(x_0, y_1) \\\\\n  &+& p_1 * q_0 * u(x_1, y_0) \\\\\n  &+& p_1 * q_1 * u(x_1, y_1) .\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  du(x_0, y_0) &=& dv * p_0 * q_0 \\\\\n  du(x_0, y_1) &=& dv * p_0 * q_1 \\\\\n  du(x_1, y_0) &=& dv * p_1 * q_0 \\\\\n  du(x_1, y_1) &=& dv * p_1 * q_1.\n\\end{eqnarray}\n\nThe second order gradient is the interpolation of $d_2d_1 u(\\cdot, \\cdot)$ again. Thus, we have a periodic relationship for the gradient operators: $d_0(\\cdot) = d_2(\\cdot), d_1(\\cdot) = d_3(\\cdot), \\ldots$.\\\\\n\nThis 2D linear interpolation can be generalized to the N-d case.\n\n\\begin{equation}\n  v = \\sum_{i_1, i_2, i_n \\in \\{0, 1\\}} p_{i_1}\\dots p_{i_n} u(x_{i_1}, \\ldots x_{i_n}).\n\\end{equation}\n\n\\subsection{FFT}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = W_{FFT}x =: FFT(x).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = IFFT(dy).\n\\end{eqnarray}\n%\nTake care of the normalization coefficient. In the normalized FFT, the backward does not need to deal with the normalized coefficient. In the unnormailzed FFT, the backward needs to address the normalization coefficient.\n\n\\subsection{IFFT}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = W_{IFFT}x =: IFFT(x).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = FFT(dy).\n\\end{eqnarray}\n%\nTake care of the normalization coefficient. In the normalized FFT, the backward does not need to deal with the normalized coefficient. In the unnormailzed FFT, the backward needs to address the normalization coefficient.\n\n\\section{Stochasticity}\n\\label{sec:Stochasticity}\n\n\\subsection{Dropout}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\left\\{\n  \\begin{array}{ll}\n    \\frac{x}{1 - p} & (u > p) \\\\\n    0 & ({\\rm {\\rm otherwise}})\n  \\end{array} \\right.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy \\left\\{\n  \\begin{array}{ll}\n    \\frac{1}{1 - p} & (u > p) \\\\\n    0 & ({\\rm {\\rm otherwise}})\n  \\end{array} \\right.\n\\end{eqnarray}\n\n\n\\subsection{TopKData}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = TopKData(x).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy[TopKDataIndex]\n\\end{eqnarray}\n\n\n\\subsection{TopKGrad}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = TopKGrad(x).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy[TopKGradIndex].\n\\end{eqnarray}\n\n\n% \\subsection{Rand}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{Randint}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{Randn}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandBinomial}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandBeta}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandGamma}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandomChoice}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandomCrop}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandomFlip}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandomShift}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n% \\subsection{RandomErase}\n\n% Forward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n% %\n% Backward pass:\n\n% \\begin{eqnarray}\n%   TODO.  \n% \\end{eqnarray}\n\n\n\\section{Loss Functions}\n\\label{sec:Loss Functions}\n\n\\subsection{SigmoidCrossEntropy}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = - \\left(x^{(1)}_i \\ln \\left(\\sigma \\left(x^{(0)}_i \\right)\\right) + \\\n  \\left(1 - x^{(1)}_i\\right) \\ln \\left(1 - \\sigma \\left(x^{(0)}_i \\\n  \\right)\\right)\\right)\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i (\\sigma_i - x^{(1)}_i)\n\\end{eqnarray}\n\n\n\\subsection{BinaryCrossEntropy}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = - \\left(x^{(1)}_i * \\ln \\left(x^{(0)}_i\\right) + \\left(1 - \\\n  x^{(1)}_i\\right) * \\ln \\left(1 - x^{(0)}_i\\right)\\right).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i = dy_i \\frac{x^{(0)}_i - x^{(1)}_i}{x^{(0}_i (1 - x^{(0)}_i)}\n\\end{eqnarray}\n\n\n\\subsection{SoftmaxCrossEntropy}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i} &&= -\\ln \\sum_i t_i \\sigma(x_i)\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{j} &&= dy (\\sigma(x_j) - t_j).\n\\end{eqnarray}\n%\nwhere the $\\sigma(x)$ is the softmax.\n\n\\subsection{CategoricalCrossEntropy}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_{i} &&= -\\ln \\sum_i t_i x_i\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_{j} && = -dy \\frac{t_j}{x_j}.\n\\end{eqnarray}\n\n\n\\subsection{SquaredError}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = \\left(x^{(0)}_i - x^{(1)}_i\\right)^2.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i &&= dy_i \\times 2 \\times \\left(x^{(0)}_i - x^{(1)}_i\\right) \\\\\n  dx^{(1)}_i &&= -dy_i \\times 2 \\times \\left(x^{(0)}_i - x^{(1)}_i\\right).\n\\end{eqnarray}\n\n\n\\subsection{AbsoluteError}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i = | x^{(0)}_i - x^{(1)}_i |.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i= \\left\\{\n  \\begin{array}{ll}\n   dy_i  & (x^{(0)}_i > x^{(1)}) \\\\\n   -dy_i & ({\\rm otherwise})\n  \\end{array} \\right. \\\\\n  dx^{(1)}_i= \\left\\{\n  \\begin{array}{ll}\n   -dy_i  & (x^{(0)}_i > x^{(1)}) \\\\\n   dy_i & ({\\rm otherwise})\n  \\end{array} \\right.\n\\end{eqnarray}\n\n\n\\subsection{HuberLoss}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i= \\left\\{\n  \\begin{array}{ll}\n    (x^{(0)}_i - x^{(1)}_i)^2 & (|x^{(0)}_i - x^{(1)}_i| < \\delta) \\\\\n    \\delta (2 |x^{(0)}_i - x^{(1)}_i| - \\delta) & ({\\rm otherwise})\n  \\end{array} \\right.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    2 (x^{(0)}_i - x^{(1)}_i) & (|x^{(0)}_i - x^{(1)}_i| < \\delta) \\\\\n    2 \\delta & (|x^{(0)}_i - x^{(1)}_i| \\geq \\delta \\ and \\ x^{(0)}_i \\geq x^{(1)}_i) \\\\\n    -2 \\delta & (|x^{(0)}_i - x^{(1)}_i| \\geq \\delta \\ and \\ x^{(0)}_i < x^{(1)}_i)\n  \\end{array} \\right. \\\\\n  dx^{(1)}_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    - 2 (x^{(0)}_i - x^{(1)}_i) & (|x^{(0)}_i - x^{(1)}_i| < \\delta) \\\\\n    - 2 \\delta & (|x^{(0)}_i - x^{(1)}_i| \\geq \\delta \\ and \\ x^{(0)}_i \\geq x^{(1)}_i) \\\\\n    2 \\delta & (|x^{(0)}_i - x^{(1)}_i| \\geq \\delta \\ and \\ x^{(0)}_i < x^{(1)}_i)  \\end{array} \\right. \n\\end{eqnarray}\n\n\n\\subsection{EpsilonInsensitiveLoss}\n\nForward pass:\n\n\\begin{eqnarray}\n  y_i= \\left\\{\n  \\begin{array}{ll}\n    | x^{(0)}_i - x^{(1)}_i | - \\epsilon & (| x^{(0)}_i - x^{(1)}_i | > \\epsilon) \\\\\n    0 & ({\\rm otherwise})\n  \\end{array} \\right.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx^{(0)}_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    1  & ( | x^{(0)}_i - x^{(1)}_i | > \\epsilon \\ and \\ x^{(0)}_i >= x^{(1)}_i) \\\\\n    -1  & ( | x^{(0)}_i - x^{(1)}_i | > \\epsilon \\ and \\ x^{(0)}_i < x^{(1)}_i) \\\\\n    0 & {\\rm otherwise}\n  \\end{array} \\right. \\\\\n  dx^{(1)}_i &&= dy_i \\left\\{\n  \\begin{array}{ll}\n    -1  & ( | x^{(0)}_i - x^{(1)}_i | > \\epsilon \\ and \\ x^{(1)}_i >= x^{(0)}_i) \\\\\n    1  & ( | x^{(0)}_i - x^{(1)}_i | > \\epsilon \\ and \\ x^{(1)}_i < x^{(0)}_i) \\\\\n    0 & {\\rm otherwise}\n  \\end{array} \\right.\n\\end{eqnarray}\n\n\n\\subsection{KLMultinomial}\n\nForward pass:\n\n\\begin{eqnarray}\n  D = \\sum_i p_i \\log \\left( \\frac{p_i}{q_i} \\right).\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dp_i &&= dD \\left( \\log(\\frac{p_i}{q_i}) + 1 \\right), \\\\\n  dq_i &&= dD \\frac{-p_i}{q_i}.\n\\end{eqnarray}\n\n\n\\section{Quantization Neural Network Layers}\n\\label{sec:Quantization Neural Network Layers}\n\nQuantization layers mainly relies on Straight-Through-Estimator (STE) where we use the proxy of a quantized function for deriving the backward pass of the quantized function to simulate smooth gradients. In this sence, the proxy should be closer to the quantized function and smooth one, but we can replace the gradient of a quantized function with much simplier one like $1$, meaning just pass the in-coming gradients. This sounds a bit cheating, but STE works fine in practice.\n\n\\subsection{BinarySigmoid}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = \\begin{cases}\n    1 & (x > 0) \\\\\n    0 & ({\\rm {\\rm otherwise}})\\end{cases},\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = 0.5 * dy.\n\\end{eqnarray}\n\n\n\\subsection{BinaryTanh}\n\nForward pass:\n\n\\begin{eqnarray}\n  f(x) = \\begin{cases}\n    1 & (x > 0) \\\\\n    -1 & ({\\rm {\\rm otherwise}})\n  \\end{cases},\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  f(x) = \\begin{cases}\n    1 & (x > 0) \\\\\n    -1 & ({\\rm {\\rm otherwise}})\n  \\end{cases},\n\\end{eqnarray}\n\n\n\\subsection{Prune}\n\nForward pass:\n\n\\begin{eqnarray}\n  q_i = \\left \\{\n  \\begin{array}{ll}\n    0   & abs(x_i) < threshold \\\\\n    x_i & {\\rm otherwise}\n  \\end{array}\n  \\right.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx_i = dq_i.\n\\end{eqnarray}\n\n\n\\subsection{QuantizeLinear}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = saturate(round(x / s) + z).    \n\\end{eqnarray}\n\nThe {\\it saturate} is, for example in case of int8, $clip(x, -128, 127)$. The {\\it round} depends on implementation, but {\\it round-to-even} or {\\it round-away-from-zero} are often used. Zero-point $z$ is sometimes omitted for computational efficiency.\\\\ \\\\\n%\nBackward pass:\n  \n\\begin{eqnarray}\n  dx &&= \\left\\{\n  \\begin{array}{ll}\n    dy / s & (saturate(round(x / s)) \\\\\n    0 & (otherwise).\n  \\end{array} \\right.\n\\end{eqnarray}\n\n\\subsection{DequantizeLinear}\n\nForward pass:\n\n\\begin{eqnarray}\n  y = (x - z) * s.\n\\end{eqnarray}\n%\nBackward pass:\n\n\\begin{eqnarray}\n  dx = dy * s\n\\end{eqnarray}\n\n\n% \\input{references}\n\\end{document}\n\n\n\\bibliographystyle{plain}\n\\bibliography{references}\n\\end{document}\n", "meta": {"hexsha": "8573be7a64eadd2e1f936f24bea11cc601850071", "size": 48513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "kzky/Backpropagation-and-Higher-order-Gradients", "max_stars_repo_head_hexsha": "29b4dcf67252eba586c94e1b978cd88bdd0cbf94", "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": "main.tex", "max_issues_repo_name": "kzky/Backpropagation-and-Higher-order-Gradients", "max_issues_repo_head_hexsha": "29b4dcf67252eba586c94e1b978cd88bdd0cbf94", "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": "main.tex", "max_forks_repo_name": "kzky/Backpropagation-and-Higher-order-Gradients", "max_forks_repo_head_hexsha": "29b4dcf67252eba586c94e1b978cd88bdd0cbf94", "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": 17.3446549875, "max_line_length": 543, "alphanum_fraction": 0.6269247418, "num_tokens": 18734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6077520468123523}}
{"text": "\\documentclass[letterpaper, 10pt]{article}\n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb,scrextend}\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\usepackage{silence}\n\\WarningFilter{latex}{You have requested package}\n\\input{ltx/pkg/preamble}\n\n\n\n\n\n\\begin{document}\n\n\\lhead{MAT224 Linear Algebra II}\n\\chead{Eigenvalues, Eigenvectors and Diagonalizability}\n\\rhead{Week 09 I}\n\n\\title{Linear Algebra II \\\\ \\Large{MAT224}}\n\\author{Lennart Döppenschmitt}\n% \\maketitle\n% \\tableofcontents\n\n\\section*{Eigenvalues and Eigenvectors Pt II}%\n\\textbf{Textbook:} Section 4.1\n\n\\lb\n\\textbf{Proposition (4.1.5)}\n\\lb\nA nonzero vector $\\vec v ∈ V$ is an eigenvector of $T$ with eigenvalue $λ$ if and only if\n\\[ \\vec v ∈ \\ker(T - λ \\cdot \\tx{id}_V) \\]\n\\begin{proof}\n    \n\\end{proof}\n\\vspace{200pt}\n\\lb\n\\textbf{Discussion}\n\\lb\nFor a transformation $T ∈ \\cal L(V)$ which of these statements are equivalent to \n\\emph{$λ$ is an eigenvalue of $T$}?\n\\begin{enumerate}\n    \\item $T(\\vec v) = λ \\vec v$ for some $\\vec v ∈ V$\n    \\item $\\ker(T - λ \\tx{id}_V) \\neq \\cb{0}$\n    \\item $T - λ \\tx{id}_V$ is not an isomorphism\n\\end{enumerate}\n\n\n\n\n\\vspace{30pt}\n\\lb\n\\q{\\textbf{Question}}\n\\lb\n\\q{So for which $λ ∈ \\R$ can we expect to find eigenvectors?}\n\n\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Proposition (4.1.9)}\n\\lb\n$λ ∈ \\R$ is an eigenvalue of $T ∈ \\cal L(V)$ if and only if\n\\[ \\det{T - λ \\cdot \\tx{id}_V} = 0 \\]\n\\ble{That is, there are eigenvectors $\\vec v ∈ V$ with eigenvalue $λ$.}\n\\begin{proof}\n\\end{proof}\n\n\n\n\n\\vspace{200pt}\n\\lb\n\\textbf{Proposition (4.1.6)}\n\\lb\nFor a given eigenvalue $λ$ of  $T ∈ \\cal L(V)$ the set of all eigenvectors\n\\[ E_λ = \\cb{\\vec v ∈ V ~ \\vert ~ T(\\vec v) = λ  \\vec v } \\]\ntogether with with the zero vector $\\vec 0$\nis a subspace of $V$ called the \\emph{$λ$-eigenspace} of $T$.\n\\begin{proof}\n\\end{proof}\n\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Example (4.1.1)}\n\\lb\nLet's have another look at example (4.1.1) from the book.\nLet $\\map{\\R^2}[T_A]{\\R^2}$ be the linear transformation represented by the matrix\n\\[ \\begin{pmatrix} 2 & 1 \\\\ 1 & 2 \\end{pmatrix} \\]\nCompute its eigenvalues and the corresponding eigenspaces with the theory introduced above.\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Definition}\n\\lb\nLet $A$ be an $n \\times n$ matrix. The polynomial $c_A(λ) = \\det{A - λ I_n}$ is called the\n\\emph{characteristic polynomial} of A.\n\n\\vspace{30pt}\n\\lb\nFollowing this definition and proposition 4.1.9, we can say that eigenvalues of a matrix $A$\nwill be the roots of its characteristic polynomial.\n\n\n\n\\vspace{170pt}\n\\lb\n\\textbf{Proposition (4.1.12)}\n\\lb\nSimilar matrices have equal characteristic polynomial\n\\begin{proof}\n\\end{proof}\n\n\n\n\n\n\n\\vspace{200pt}\n\\lb\n\\textbf{Corollary}\n\\lb\nThe characteristic polynomial for a transformation $T ∈ \\cal (L)$ as\n\\[ c_T(λ) =  \\det{[T]_α^α - λI_n} \\]\ndoes not depend on the choice of basis.\n\n\n\n\n\n\n\n\\newpage\n\\lb\n\\textbf{True or False}\n\\begin{enumerate}\n    \\item[$\\square$]\n    $T ∈ \\mathcal{L}(V)$ is an isomorphism if and only if $0$ is not an eigenvalue.\n    \\item[$\\square$]\n    Every transformation has at least one eigenvalue.\n    \\item[$\\square$]\n    There are infinitely many eigenvectors to every eigenvalue of a transformation.\n    \\item[$\\square$]\n    There is at least one eigenvector to every eigenvalue of a transformation.\n    \\item[$\\square$]\n    An $n \\times n$ matrix can have at most $n$ distinct eigenvalues.\n\\end{enumerate}\n\n\\vspace{100pt}\n\\lb\n\\textbf{Discussion}\n\\lb\nSuppose the transformation $T ∈ \\mathcal{L}(V)$ is represented by the matrix\n\\[ \\begin{pmatrix}\n    2 & 1 & 0 \\\\\n    0 & 2 & 0 \\\\\n    2 & 3 & 1\n\\end{pmatrix}\n\\]\nwith respect to some basis $α$.\n\\begin{enumerate}\n    \\item Find the characteristic polynomial $c_T(λ)$.\n    \\item Find all eigenvalues of $T$.\n    \\item Find a basis for each eigenspace of $T$.\n\\end{enumerate}\n\n\n\n\\newpage\n\\section*{Diagonalizability}%\n\\textbf{Textbook:} Section 4.2\n\n\\lb\n\\textbf{Definition (4.2.1)}\n\\lb\nA linear transformation $ T ∈ \\mathcal{L}(V)$ on a finite dimensional vector space $V$ is\nsaid to be \\emph{diagonalizable} if there exists a basis of $V$\nconsisting entirely of eigenvectors of $T$.\n\n\\lb\n\\ble{Why does this definition makes sense?}\nTry to find the matrix $[T]_α^α$ in a basis of eigenvectors $α = \\cb{\\vec{α} _1, \\ldots, \\vec{α}_n}$\n\n\n\\vspace{200pt}\n\\lb\n\\textbf{Goal}\n\\lb\nFind a condition to determine whether a transformation is diagonalizable or not.\n\n\\lb\n\\textbf{Definition}\n\\lb\nLet $λ$ be an eigenvalue of a linear transformation $T$ on $V$.\n\\begin{enumerate}\n    \\item The \\emph{algebraic multiplicity} $m_λ$ of $λ$ is the degree with which \n        $c_T$ vanishes at $λ$.\n    \\item The \\emph{geometric multiplicity} of $λ$ is the dimension of the eigenspace $E_λ(T)$\n\\end{enumerate}\n\n\n\n\\newpage\n\\lb\n\\textbf{Proposition (4.2.4)}\n\\lb\nLet $\\vec v_1, \\ldots \\vec v_k$ be eigenvectors to distinct eigenvalues $λ_i$ of a linear transformation $\\map{V}[T]{V}$,\nthen $ \\cb{\\vec v_1, \\ldots, \\vec v_n}$ is linearly independent in $V$.\n\\begin{proof}\n\\end{proof}\n\n\n\n\n\\newpage\n\\lb\n\\textbf{Corollary (4.2.5)}\n\\lb\nLet $T$ be a linear transformation on $V$ with distinct eigenvectors $λ_1, \\ldots, λ_k$ and for\neach eigenvalue $λ_j$ consider a linearly independent family of eigenvectors\n\\[ \\cb{\\vec v_1^j, \\ldots, \\vec v_{n_j}^j} \\]\nin $E_{λ_j}$.\nThen the union of all these families of eigenvectors \n\\[ S = \\cb{\\vec v_1^j, \\ldots, \\vec v_{n_1}^j} \\cup \\ldots\n\\cup \\cb{\\vec v_1^k, \\ldots, \\vec v_{n_k}^k} \\]\nis linearly independent in $V$.\n\\begin{proof}\n\\end{proof}\n\n\n\\vspace{300pt}\n\\lb\n\\textbf{Discussion}\n\\lb\nWhat is the intersection of eigenspaces to distinct eigenvalues?\n\n\n\\newpage\n\\lb\n\\textbf{Proposition (4.2.6)}\n\\lb\nFor every linear transformation $T$ on a finite dimensional vector space $V$ the geometric \nmultiplicity is bounded by $1$ and the algebraic multiplicity.\n\\[ 1 \\leq \\dim{E_λ}(T) \\leq m_λ \\]\n\\begin{proof}\n\\end{proof}\n\n\\vspace{200pt}\n\\lb\n\\textbf{Theorem (4.2.7)}\n\\lb\nFor a linear transformation $T$ on a finite dimensional vector space $V$\nwith distinct eigenvalues $λ_1, \\ldots, λ_k$.\nThen $T$ is diagonalizable if and only if\n\\begin{enumerate}\n    \\item $m_{λ_1} + \\cdots + m_{λ_k} = \\dim{V}$\n    \\item for each $i$, $\\dim{E_{λ_i}} = m_{λ_i}$\n\\end{enumerate}\n\\textbf{Remark:} The first condition can be dropped if we assume that all roots of $c_T(λ)$ has\nare real valued. We will see a discussion later.\n\\begin{proof}\n\\end{proof}\n\n\n\\newpage\n\\lb\n\\textbf{Example (4.2.3)}\n\\lb\nDiagonalize, if possible the transformation $T$ on $\\R^3$ given by the matrix\n\\[ A = \\begin{pmatrix}\n    2 & 2 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 1 & 2\n\\end{pmatrix}\n\\]\n\n\n\n\n\\vspace{300pt}\n\\lb\n\\textbf{Discussion}\n\\lb\nCan you argue with the transformation given by\n\\[ B = \\begin{pmatrix}\n    0 & -1 & 0 \\\\\n    1 & 0 & 0 \\\\\n    0 & 0 & 0\n\\end{pmatrix}\n\\]\nwhy the condition $m_{λ_1} + \\cdots + m_{λ_k} = \\dim{V}$ is important in the above theorem?\n\n\n\n\\newpage\n\\lb\n\\textbf{Remarks}\n\\lb\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "0ea696c09dde10acf4fddedf017a375f3453b93a", "size": 6889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week09.1.tex", "max_stars_repo_name": "Researchnix/mat224", "max_stars_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-03T21:56:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-30T03:26:18.000Z", "max_issues_repo_path": "week09.1.tex", "max_issues_repo_name": "Researchnix/mat224", "max_issues_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week09.1.tex", "max_forks_repo_name": "Researchnix/mat224", "max_forks_repo_head_hexsha": "05a6bd843d87f5877c457cefef28d2a976df4973", "max_forks_repo_licenses": ["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.5956112853, "max_line_length": 121, "alphanum_fraction": 0.6797793584, "num_tokens": 2434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6077520430649997}}
{"text": "\n\n\n% \\graphicspath{{Chap2/plots/}}\nThe transition matrix, or T-matrix, relates the multipole coefficients of the scattered field of an object to the multipole coefficients of the field incident on the object. The method was pioneered by Waterman \\cite{waterman1965matrix}.  A T-matrix can represent the scattering solution of a single object or a collection of objects, \\cite{chew1995waves}. Deriving or computing the elements of a T-matrix is its own subject, but simple objects admit analytic solutions. This chapter gives the basic definition of the T-matrix and instructions for rotation. Then equations and routines for the T-matrix elements of dielectric and metal spheres are provided. Derivations and routines are then provided to convert between a T-matrix and an S-matrix. Finally, we give expressions for different radar cross sections in terms of the T-matrix and evaluate these for spheres.\n\n\n\\section{Definition}\n\nThe incident field is expanded in regular spherical wave functions around the object, and the scattered field is expanded in radiating wave functions. The harmonic sums are written in matrix notation as\n\\begin{eqnarray}\n\\bb{E}_{inc}(\\br) &=& \\onebytwo{\\textit{Rg}\\bb{M}^t(k,\\br)}{\\textit{Rg}\\bb{N}^t(k,\\br)}\\twobyone{\\bb{a}}{\\bb{b}} \\\\\n\\bb{E}_{sca}(\\br) &=& \\onebytwo{\\bb{M}^t(k,\\br)}{\\bb{N}^t(k,\\br)}\\twobyone{\\bb{c}}{\\bb{d} \\label{tmatrixesca} } \n\\end{eqnarray}\n\nThe expression for the incident field is valid everywhere, while the scattered field is only valid outside the smallest radius that encloses the object or collection of objects. In other words, a T-matrix does not model the scattering solution within an object region.  Next, define the sub-matrices that relate the expansion coefficients between the $\\bb{M}$ and $\\bb{N}$ harmonics as  \n\\begin{equation}\n\\twobyone{\\bb{c}}{\\bb{d}} = \\twobytwo{\\overline{\\bb{T}}^{MM}}{\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{NM}}{\\overline{\\bb{T}}^{NN}} \\twobyone{\\bb{a}}{\\bb{b} \\label{Tmatrixdef} }\n\\end{equation}\n\n\nAn object and its T-matrix can be rotated using the rotation matrix for spherical harmonics. Given an object T-matrix, the T-matrix of the object rotated by ZXZ Euler angles $(\\alpha,\\beta,\\gamma)$ is\n\\eq{\\twobytwo{\\overline{\\bb{T}}^{'MM}}{\\overline{\\bb{T}}^{'MN} }{\\overline{\\bb{T}}^{'NM}}{\\overline{\\bb{T}}^{'NN}} = \n\\twobytwo{\\bb{D}^*}{0}{0}{\\bb{D}^*}\n\\twobytwo{\\overline{\\bb{T}}^{MM}}{\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{NM}}{\\overline{\\bb{T}}^{NN}} \n\\twobytwo{\\bb{D}}{0}{0}{\\bb{D}} }\n\n\\noindent where $\\bb{D}$ describes the inverse rotation and $\\overline{\\bb{T}}'$ is the T-matrix of the rotated object as seen from the fixed frame. The field first viewed from the frame of the rotated object, then the T-matrix is applied in its natural frame, last the perspective is rotated back to the fixed frame (an inverse rotation in the opposite direction, i.e., a forward rotation, $\\bb{D}^*$.)\n\n\n\n%The rule of thumb for the number of unique $(l,m)$ harmonics needed to represent the scattered field of an object with the multipole expansion is $O(kd)$, where $k$ is the background wavenumber, and $d$ is the largest dimension of the object. Alternately, $d$ can be thought of as the diameter of the smallest sphere enclosing the object.  The total number harmonics up to $L$ all $m$ is \n%\n%\\eq{N = \\sum_{l=1}^{L} \\sum_{m=-l}^l 1 = L^2 + 2L}\n%\n%Then solving the quadratic for $L$ we get, roughly, \n%\n%\\eq{L \\approx 2 \\sqrt{kd  + 1} - 1}\n\n%which is rounded up.  \n\n\\clearpage\n\\newpage\n\\section{Object T-matrix}\n\nThis section derives the T-matrix for several simple objects.\n\n\\subsection{Dielectric Sphere}\n\\label{sec:tmatrixsphere}\nLet a sphere of radius $a$ be centered at the origin with outer and inner regions having wavenumbers $k_1$ and $k_2$, respectively.  The incident, scattered, and total electric fields are expanded in terms of vector spherical wave functions. The regular form of the wave functions is used for the incident everywhere and the total field inside the sphere, while the singular form is used for the scattered field outside of the sphere. \n\\begin{eqnarray}\n\\bb{E}_{inc}(\\br) &=& \\onebytwo{\\textit{Rg}\\bb{M}^t(k_1,\\br)}{\\textit{Rg}\\bb{N}^t(k_1,\\br)}\\twobyone{\\bb{a}}{\\bb{b}}, \\quad \\forall \\ \\br \\\\\n\\bb{E}_{sca}(\\br) &=& \\onebytwo{\\bb{M}^t(k_1,\\br)}{\\bb{N}^t(k_1,\\br)}\\twobyone{\\bb{c}}{\\bb{d}}, \\quad \\br \\ge a \\\\\n\\bb{E}_{tot}(\\br) &=& \\onebytwo{\\textit{Rg}\\bb{M}^t(k_2,\\br)}{\\textit{Rg}\\bb{N}^t(k_2,\\br)}\\twobyone{\\bb{e}}{\\bb{f}}, \\quad \\br \\le a\n\\end{eqnarray}\n\n\\vspace{-2mm}\nThe magnetic fields are found by taking the curl of each expression (i.e., Faraday's law) and applying the curl relations for vector spherical wave functions. For example, the scattered magnetic field is \n\\begin{equation}\n\\bb{H}_{sca}(\\br) = \\frac{k}{i\\omega\\mu}\\onebytwo{\\bb{N}^t(k,\\br)}{\\bb{M}^t(k,\\br)}\\twobyone{\\bb{c}}{\\bb{d}}\n\\end{equation}\n\nBoundary conditions require that the tangential electric and magnetic fields at $r=a$ must be equal\n\\begin{eqnarray}\n\\hat{\\br}\\times\\bb{E}_{tot} &=& \\hat{\\br}\\times\\bb{E}_{inc} + \\hat{\\br}\\times\\bb{E}_{sca} \\label{rcrossescat} \\\\\n\\hat{\\br}\\times\\bb{H}_{tot} &=& \\hat{\\br}\\times\\bb{H}_{inc} + \\hat{\\br}\\times\\bb{H}_{sca} \\label{rcrosshscat}\n\\end{eqnarray}\n\nWe want to express the total and scattered field coefficients in terms of the incident field coefficients. We outline the steps and state the result. Left dot \\eqref{rcrossescat} and \\eqref{rcrosshscat} by $\\hat{\\bb{M}}(k_1,\\br)$ and by $\\hat{\\bb{N}}(k_1,\\br)$, respectively, where the caret, $\\hat{}$, means the angular harmonics are conjugated.  Apply the vector identity that exchanges dot and cross product, evaluate at $r=a$, and integrate over the unit sphere. Orthogonality will pick out the $l$ harmonics. Solve the resulting system of equations, and after some simplifications, including use of the Wronskian, we get the following relations between the coefficients.\n\\begin{equation}\nc_{lm} = -a_{lm}\\dfrac{\\mu_2 j_l(k_2a)\\left[k_1aj_l(k_1a)\\right]' - \\mu_1 j_l(k_1a) \\left[k_2aj_l(k_2a)\\right]'}{\\mu_2 j_l(k_2a) [k_1ah_l^{(1)}(k_1a)]' - \\mu_1 h_l^{(1)}(k_1a)\\left[k_2aj_l(k_2a)\\right]'} \\label{clmalm}\n\\end{equation}\n\n\\begin{equation}\nd_{lm} = -b_{lm}\\dfrac{\\epsilon_2 j_l(k_2a)\\left[k_1aj_l(k_1a)\\right]' - \\epsilon_1 j_l(k_1a) \\left[k_2aj_l(k_2a)\\right]'}{\\epsilon_2 j_l(k_2a) [k_1ah_l^{(1)}(k_1a)]' - \\epsilon_1 h_l^{(1)}(k_1a)\\left[k_2aj_l(k_2a)\\right]'} \\label{dlmblm}\n\\end{equation}\n\n\\begin{equation}\ne_{lm} = a_{lm}\\dfrac{i\\mu_1}{k_1a}\\dfrac{1}{ \\mu_2 j_l(k_2a) [k_1ah_l^{(1)}(k_1a)]' - \\mu_1 h_l^{(1)}(k_1a)\\left[k_2aj_l(k_2a)\\right]' } \\label{elmalm}\n\\end{equation}\n\n\\begin{equation}\nf_{lm} = b_{lm}\\dfrac{i\\epsilon_2}{k_2a}\\dfrac{1}{\\epsilon_2 j_l(k_2a) [k_1ah_l^{(1)}(k_1a)]' - \\epsilon_1 h_l^{(1)}(k_1a)\\left[k_2aj_l(k_2a)\\right]' } \\label{flmblm}\n\\end{equation}\n\n\\noindent where $a$ is the radius, $k_1$ is the wavenumber outside the sphere, $k_2$ is the wavenumber inside the sphere, either given by \n\\eq{k = \\omega\\sqrt{\\mu\\epsilon} = \\dfrac{\\omega}{c} \\sqrt{\\mu_r \\epsilon_{rc}}}\n\\eq{\\epsilon_{rc} = \\epsilon_r + i\\dfrac{\\sigma}{\\omega\\epsilon_o}}\n\n\\noindent where $\\omega$ is the natural frequency, $c$ is the speed of light in vacuum, $\\mu$ is the magnetic permeability, $\\mu_r$ is the relative permeability, $\\epsilon$ is the dielectric permittivity, $\\epsilon_{rc}$ is the relative complex permittivity, $\\epsilon_r$ is the real part of the relative permittivity, $\\sigma$ is the conductivity, and $\\epsilon_{o}$ is the permittivity of free space.  The Bessel derivatives apply to the argument $x = ka$ as\n\\begin{equation}\n[ x z_l(x)]' = z_l(x) + x z_l'(x) \n\\end{equation}\n\nEquations \\eqref{clmalm} and \\eqref{dlmblm} give the scattered field coefficients, while \\eqref{elmalm} and \\eqref{flmblm} give the coefficients for the total field inside the sphere. Dividing \\eqref{clmalm} and \\eqref{dlmblm} by $a_{lm}$ and $b_{lm}$, respectively, gives the T-matrix elements for the dielectric sphere. \n\\begin{eqnarray}\nT^{MM}_{lmlm}  &=& \\dfrac{c_{lm}}{a_{lm}} \\label{tmmsphere} \\\\\nT^{NN}_{lmlm} &=&  \\dfrac{d_{lm}}{b_{lm}}  \\label{tnnsphere}\\\\\nT_{lmlm}^{MN} &=& 0 \\\\\nT_{lmlm}^{NM} &=& 0 \n\\end{eqnarray}\n\nThis T-matrix is diagonal, so there is no mode-mixing, and the elements are only a function the degree $l$, which are copied for all $m$ at that degree. \n\nThe routine \\texttt{tmatrixDielectricSphere} gives the T-matrix elements of a dielectric sphere up to maximum degree $L$ all $m$. It takes as input the maximum degree harmonic $L$, sphere radius, and wavenumbers and inside and outside the sphere. The permeabilities are optional, but if nonzero, must also be included in the wavenumbers.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/tmatrixDielectricSphere.m}\n}\n\n\n\n\\subsection{PEC Sphere}\n\nThe T-matrix for a perfect electrical conductor (PEC) sphere is found by taking $\\epsilon_2 \\rightarrow \\infty$ and/or $\\mu_2 \\rightarrow 0$ in \\eqref{tmmsphere} and \\eqref{tnnsphere}.  The result is\n\\begin{eqnarray}\nT_{lmlm}^{MM} &=& -\\dfrac{j_l(ka)}{h_l^{(1)}(ka)} \\\\\nT_{lmlm}^{NN} &=& -\\dfrac{[k a j_l(ka)]'}{[k a h_l^{(1)}(ka)]'} \\\\\nT_{lmlm}^{MN} &=& 0 \\\\\nT_{lmlm}^{NM} &=& 0 \n\\end{eqnarray}\n\n\\noindent where $k$ is the background wavenumber.  The negative sign is the 180 degree phase flip familiar from 1D scattering from a PEC boundary. \n\nThe routine \\texttt{tmatrixPECSphere} gives the T-matrix elements of a PEC sphere up to maximum degree $L$ all $\\pm m$.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/tmatrixPECSphere.m}\n}\n\n%\\subsection{Multilayered Dielectric Sphere}\n%\\subsection{PEC Cylinder}\n%\\subsection{Dielectric Cylinder}\n%\\section{Multilayered Dielectric Sphere with PEC Core}\n\n\\clearpage\n\\newpage\n\\section{Extended Boundary Condition Method}\n\nThe extended boundary condition method (EBCM) is a technique to compute the T-matrix of a bounded, homogenous object that has an arbitrary or irregular surface. For example, this has been used to determine the T-matrix of short cylinders in \\cite{duan2015experimental}.  While analytically generic, the EBCM is usually not accurate for highly elongated objects or objects with large concavities. We outline the derivation, comment on the computation, and provide a routine to compute the solution.\n\n\\paragraph{Formulation}\nThe EBCM makes use of the extinction theorem to express fields both inside and outside the object in terms of an integral over the surface of the object, \\cite{chew1995waves}. The geometry is shown in Figure \\ref{geoebcm}. The extended boundaries are two virtual surfaces, $S_1$ and $S_2$, that are contained in the volumes, $V_1$ and $V_2$, respectively, but do not intersect the actual surface, $S$. $S_1$ and $S_2$ are used to decide the form of the addition theorem for the dyadic Green's function. The fields tangent to $S$ are expanded in terms of vector spherical wave functions, after which the incoming and outgoing field coefficients can be related and the T-matrix found.  \n\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=2.2in]{Tmatrix/Figures/ebcm} \n   \\caption{Geometry for the Extended Boundary Condition Method.}\n   \\label{geoebcm}\n\\end{figure}\n\nThe surface integral equations used for the EBCM are \\cite{chew1995waves,duan2015experimental}, \n\\begin{align}\n\\bb{E}_{inc}(\\br) &= -\\int_S dS'\\left( i \\omega \\mu_1 \\G{1} \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') + \\left[\\nabla\\times \\G{1} \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right), \\quad \\br \\in V_2  \\label{ebcmSIEV2}\\\\\n0 &= -\\int_S dS'\\left( i \\omega \\mu_2 \\G{2} \\cdot \\hat{n}' \\times \\bb{H}_2(\\br') + \\left[\\nabla\\times \\G{2} \\right] \\cdot \\hat{n}' \\times \\bb{E}_2(\\br') \\right), \\quad \\br \\in V_1  \\label{ebcmSIEV1}\n\\end{align}\n\n\\noindent where $\\hat{n}'$ is the outward pointing surface normal (the leading minus sign is missing in \\cite{chew1995waves}, and \\eqref{dyadicGreenscurlprime} has been applied to the curl). The dyadic Green's functions are evaluated at the wavenumbers $k_1$ and $k_2$ of the outer and inner regions, respectively.  Note, each equation is only valid when the observation point, $\\br$, is in the region of the opposite wavenumber. \n\nThe addition theorem for the dyadic Green's function, \\eqref{dyadicgreensaddition}, is used to expand $\\G{1}$ and $\\G{2}$ on the virtual surfaces, $S_2$ and $S_1$, respectively, according the rule that the regular form of the wave functions are used for the smaller of $\\br$ or $\\br'$.  Therefore,\n\\ea{\\G{1} &=& ik_1\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}, \\quad \\br \\in S_2  \\label{ebcmg1} \\\\\n\\G{2} &=& ik_2\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\M{k_2,\\br}\\textit{Rg}\\Mhat{k_2,\\br'} +\\N{k_2,\\br} \\textit{Rg}\\Nhat{k_2,\\br'}, \\quad \\br \\in S_1 \\label{ebcmg2} }\n\n%To accommodate the outer product, we apply the following curl relation \n %\\eq{\\nabla' \\times \\G{ } = -\\nabla \\times \\G{ } }\n \n\\noindent where $\\hat{\\ }$ means conjugate of the angular function. The dyad is formed by the outer product of the components of the wave functions, where the left vector is unprimed and the right vector is primed. The vector spherical wave functions are fully normalized. The curl in \\eqref{ebcmSIEV2} and \\eqref{ebcmSIEV1} must be applied to the first vector of the outer product in \\eqref{ebcmg1} and \\eqref{ebcmg2}, \\cite{tai1997general}, which is the reason for using the unprimed curl. The tangential fields of region 2, $\\hat{n}'\\times\\bb{E}_2(\\br')$ and $\\hat{n}'\\times\\bb{H}_2(\\br')$, are expanded as (in matrix notation) \n\\vspace{-2mm}\n\\ea{\\hat{n}'\\times \\bb{E}_2(\\br') &=& \\onebytwo{\\hat{n}'\\times\\textit{Rg}\\bb{M}^t(k_2,\\br')}{\\hat{n}'\\times\\textit{Rg}\\bb{N}^t(k_2,\\br')}\\twobyone{\\boldsymbol{\\alpha}^M}{\\boldsymbol{\\alpha}^N} \\label{ebcmE2} \\\\\ni\\omega \\mu_2 \\hat{n}'\\times \\bb{H}_2(\\br') &=& \\onebytwo{\\hat{n}'\\times \\nabla' \\times \\textit{Rg}\\bb{M}^t(k_2,\\br')}{\\hat{n}'\\times\\nabla' \\times \\textit{Rg}\\bb{N}^t(k_2,\\br')}\\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N}\\label{ebcmH2} \n}\n\n\\underline{Step 1}: The first step of EBCM is to derive the relationship between the expansion coefficients $\\boldsymbol{\\alpha}$ and $\\boldsymbol{\\beta}$ subject to the constraint of \\eqref{ebcmSIEV1}. This starts by substituting \\eqref{ebcmg2} into \\eqref{ebcmSIEV1}. The curl relations for the vector wave functions, \\eqref{vswfcurlM} and \\eqref{vswfcurlN}, are applied to the primed wave functions to convert the curl of the wave function into the opposite wave function times the wavenumber. The result is rearranged and expressed as an expansion of unprimed wave functions so that \\eqref{ebcmSIEV1} becomes\n\\ea{0 &=&  \\sum_{l=1}^{\\infty}\\sum_{m=-l}^l e_{lm} \\M{k_2,\\br} +f_{lm} \\N{k_2,\\br}  \\label{ebcmg2expand}  \\\\\ne_{lm} &=& -ik_2\\int_{S_1} dS' \\left[ i \\omega \\mu_2\\textit{Rg}\\Mhat{k_2,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_2(\\br')   + k_2 \\textit{Rg}\\Nhat{k_2,\\br'} \\cdot \\hat{n}' \\times \\bb{E}_2(\\br')   \\right]  \\label{ebcmclm} \\\\\nf_{lm} &=&  -ik_2\\int_{S_1} dS'\\left[ i \\omega \\mu_2 \\textit{Rg}\\Nhat{k_2,\\br'}  \\cdot \\hat{n}' \\times \\bb{H}_2(\\br')  + k_2\\textit{Rg}\\Mhat{k_2,\\br'} \\cdot \\hat{n}' \\times \\bb{E}_2(\\br') \\right] \\label{ebcmdlm}  }\n\n%\\ea{0 &=&  -ik_2\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\int_S dS'\\left( i \\omega \\mu_2 \\left[ \\M{k_2,\\br}\\textit{Rg}\\Mhat{k_2,\\br'} +\\N{k_2,\\br} \\textit{Rg}\\Nhat{k_2,\\br'} \\right] \\cdot \\hat{n}' \\times \\bb{H}_2(\\br') - \\right.\\nonumber \\\\\n%\\ & \\ &\\left. \\left[\\nabla'\\times \\left[  \\M{k_2,\\br}\\textit{Rg}\\Mhat{k_2,\\br'} +\\N{k_2,\\br} \\textit{Rg}\\Nhat{k_2,\\br'}\\right] \\right] \\cdot \\hat{n}' \\times \\bb{E}_2(\\br') \\right)  }\n%\\ea{0 &=&  -ik_2\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\int_S dS'\\left( \\M{k_2,\\br}\\left[ i \\omega \\mu_2\\textit{Rg}\\Mhat{k_2,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_2(\\br')   +\\nabla'\\times\\textit{Rg}\\Mhat{k_2,\\br'} \\cdot \\hat{n}' \\times \\bb{E}_2(\\br')   \\right] \\right.\\nonumber\\\\\n%\\ &\\ & \\left. +\\N{k_2,\\br} \\left[ i \\omega \\mu_2 \\textit{Rg}\\Nhat{k_2,\\br'}  \\cdot \\hat{n}' \\times \\bb{H}_2(\\br')  + \\nabla'\\times\\textit{Rg}\\Nhat{k_2,\\br'} \\cdot \\hat{n}' \\times \\bb{E}_2(\\br') \\right] \\right)  }\n\nBecause \\eqref{ebcmg2expand} is zero for all points $\\br \\in V_1$, including points at infinity, and because the wave functions are independent, $e_{lm}$ and $f_{lm}$ have to be equal to zero for all $(l,m)$. Applying the curl relations again to \\eqref{ebcmH2}, then substituting \\eqref{ebcmE2} and \\eqref{ebcmH2} into both \\eqref{ebcmclm} and \\eqref{ebcmdlm}, and using a different summation index, we get\n\\vspace{-3mm}\n\\ea{e_{lm} &=& -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p \\int_{S_1} dS' \\left[ \n\\textit{Rg}\\Mhat{k_2,\\br'}\\cdot \n\\left(\\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\beta^M_{pq} + \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\beta^N_{pq} \\right) \\right. \\nonumber \\\\\n\\ & \\ & \\left. + \n\\textit{Rg}\\Nhat{k_2,\\br'} \\cdot \n\\left(\\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\alpha^M_{pq} + \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\alpha^N_{pq} \\right)\n   \\right]   \\\\\nf_{lm} &=&  -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p\\int_{S_1} dS'\\left[  \n\\textit{Rg}\\Nhat{k_2,\\br'}  \\cdot \n\\left(\\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\beta^M_{pq} + \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\beta^N_{pq}\\right) \\right. \\nonumber \\\\\n\\ & \\ & \\left. + \n\\textit{Rg}\\Mhat{k_2,\\br'} \n\\left(\\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br') \\alpha^M_{pq}+ \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\alpha^N_{pq} \\right)\n\\right]  }\n\nUsing the vector identity $\\bb{a} \\cdot (\\bb{b} \\times \\bb{c}) = \\bb{b} \\cdot (\\bb{c} \\times \\bb{a})$, and the fact that cross products of similar wave function are equal to zero, these simplify to  \n\\ea{e_{lm} &=& -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p \\int_{S_1} dS' \\hat{n}' \\cdot \\left[ \n \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Mhat{k_2,\\br'}  \\beta^M_{pq}  + \n \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Nhat{k_2,\\br'}    \\alpha^M_{pq}    \n   \\right] \\nonumber  \\\\\n \\ & \\ &\\label{ebcmelm2} \\\\\nf_{lm} &=&  -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p\\int_{S_1} dS'\\hat{n}' \\cdot\\left[  \n   \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Nhat{k_2,\\br'}    \\beta^N_{pq}   + \n  \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Mhat{k_2,\\br'}\\alpha^N_{pq}  \n\\right] \\nonumber \\label{ebcmflm2} \\\\}\n\n\n%these can be rearranged as  \n%\\ea{c_{lm} &=& -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p \\int_{S_1} dS' \\hat{n}' \\cdot \\left[ \n% \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Mhat{k_2,\\br'}  \\beta^M_{pq} +  \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Mhat{k_2,\\br'} \\beta^N_{pq}  \\right. \\nonumber \\\\\n%\\ & \\ & \\left. - \n% \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Nhat{k_2,\\br'}    \\alpha^M_{pq} -  \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times \\textit{Rg}\\Nhat{k_2,\\br'}   \\alpha^N_{pq} \n%   \\right]   \\\\\n%d_{lm} &=&  -ik_2^2 \\sum_{p=1}^{\\infty}\\sum_{q=-p}^p\\int_{S_1} dS'\\hat{n}' \\cdot\\left[  \n% \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Nhat{k_2,\\br'}    \\beta^M_{pq} +  \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Nhat{k_2,\\br'}    \\beta^N_{pq}  \\right. \\nonumber \\\\\n%\\ & \\ & \\left. - \n%  \\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Mhat{k_2,\\br'} \\alpha^M_{pq}- \\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\\times\\textit{Rg}\\Mhat{k_2,\\br'}\\alpha^N_{pq}  \n%\\right]  }\n\n\\vspace{-3mm}\nNext, choose $S_1$ to be a sphere so that $\\hat{n}' = \\hat{r}$. From the cross-product  relations for the vector spherical wave functions over a sphere \\eqref{MNrorth1}-\\eqref{MNrorth3}, the integrals will be non-zero only when $(l,m) = (p,q)$. The Bessel function products that remain are identical between the two indicies, so these can be factored from the difference. Finally, because $ \\bb{M}_{lm}\\times\\hat{\\bb{N}}_{lm} = -\\hat{\\bb{N}}_{lm}\\times \\bb{M}_{lm}$, and $ \\bb{N}_{lm}\\times\\hat{\\bb{M}}_{lm} = -\\hat{\\bb{M}}_{lm}\\times \\bb{N}_{lm}$, and using the fact that $e_{lm} = 0$ and $f_{lm}=0$, we have the constraint\n%\\vspace{-5mm}\n\\ea{0 &=&    \\beta^M_{pq}  - \\alpha^M_{pq}  \\\\\n0 &=&   \\beta^N_{pq}  -  \\alpha^N_{pq}  }\n\n\n%, \\eqref{vswfcurlM} and \\eqref{vswfcurlN}, and rearranging, we get\n%\\ea{0 &=&  -ik_2\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\int_S dS'\\left( i \\omega \\mu_2 \\left[ \\M{k_2,\\br}\\textit{Rg}\\Mhat{k_2,\\br'} +\\N{k_2,\\br} \\textit{Rg}\\Nhat{k_2,\\br'} \\right] \\cdot \\hat{n}' \\times \\bb{H}_2(\\br') - \\right.\\nonumber \\\\\n%\\ & \\ &\\left. k_2 \\left[\\left[  \\M{k_2,\\br}\\textit{Rg}\\Nhat{k_2,\\br'} +\\N{k_2,\\br} \\textit{Rg}\\Mhat{k_2,\\br'}\\right] \\right] \\cdot \\hat{n}' \\times \\bb{E}_2(\\br') \\right), \\quad \\br \\in V_1  }\n\n%Using \\eqref{ebcmg2} in \\eqref{ebcmSIEV1}, then substituting \\eqref{ebcmE2} and \\eqref{ebcmH2}, and following the steps in \\cite{chew1995waves}, it can be shown that $\\boldsymbol{\\alpha}^M = \\boldsymbol{\\beta}^M$ and $\\boldsymbol{\\alpha}^N = \\boldsymbol{\\beta}^N$. \n\n\\noindent or $\\boldsymbol{\\alpha}^M = \\boldsymbol{\\beta}^M$ and $\\boldsymbol{\\alpha}^N = \\boldsymbol{\\beta}^N$ for all harmonics.  \n\n%In \\cite{chew1995waves,duan2015experimental}, the same coefficient relations do not have a minus sign, but this sign comes from the fact that the cross products of the pairs of wave functions in \\eqref{ebcmelm2} and \\eqref{ebcmflm2} are reversed. \n\n\\underline{Step 2}: The second step of the EBCM is to use \\eqref{ebcmSIEV2} to derive a relationship between expansion coefficients of the incident and tangential fields. This starts by expanding the incident field as regular waves in region 2 using the wavenumber of region 1\n\\eq{\\bb{E}_{inc}(\\br) = \\onebytwo{\\textit{Rg}\\bb{M}^t(k_1,\\br)}{\\textit{Rg}\\bb{N}^t(k_1,\\br)}\\twobyone{\\bb{a}}{\\bb{b}}, \\quad \\br \\in V_2 \\label{ebcmeinc2}}\n \nSubstituting \\eqref{ebcmeinc2} and \\eqref{ebcmg1} into \\eqref{ebcmSIEV2}, applying the curl, and matching like harmonics of the unprimed wave functions, the incident field expansion coefficients are written in terms of the tangential fields as\n\\ea{a_{lm} &=& -ik_1 \\int_S dS'\\left( i \\omega \\mu_1  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') +   k_1\\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) \\label{ebcmalm1} \\\\\nb_{lm} &=& -ik_1\\int_S dS'\\left( i \\omega \\mu_1   \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') +    k_1\\Mhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) \\label{ebcmblm1}}\n\nBecause the tangential fields of region 1 and region 2 must be equal on $S$, then $\\hat{n}'\\times \\bb{E}_1(\\br')$ and $\\hat{n}'\\times \\bb{H}_1(\\br')$ can be expanded using \\eqref{ebcmE2} and \\eqref{ebcmH2}, respectively. The tangential fields of region 1 are then\n\\ea{\\hat{n}'\\times \\bb{E}_1(\\br') &=&\\onebytwo{\\hat{n}'\\times\\textit{Rg}\\bb{M}^t(k_2,\\br')}{\\hat{n}'\\times\\textit{Rg}\\bb{N}^t(k_2,\\br')}\\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N} \\label{ebcmE2b} \\\\\n \\hat{n}'\\times \\bb{H}_1(\\br') &=& \\dfrac{k_2}{i\\omega \\mu_2} \\onebytwo{\\hat{n}'\\times  \\textit{Rg}\\bb{N}^t(k_2,\\br')}{\\hat{n}'\\times  \\textit{Rg}\\bb{M}^t(k_2,\\br')}\\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N} \\label{ebcmH2b} \n}\n%In addition, the incident field coefficients become\n%\\ea{a_{lm} &=& -ik_1 \\int_S dS'\\left( i \\omega \\mu_1  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  k_1 \\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) \\label{ebcmalm2} \\\\\n%b_{lm} &=& -ik_1\\int_S dS'\\left( i \\omega \\mu_1   \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') - k_1 \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right)  \\label{ebcmblm2} }\n\n\\noindent where we have used $\\boldsymbol{\\alpha} =\\boldsymbol{\\beta}$ as well as the curl relations. Next, substitute \\eqref{ebcmE2b} and \\eqref{ebcmH2b} into both \\eqref{ebcmalm1} and \\eqref{ebcmblm1}. This is done with a separate summation index. Collecting terms, we can write the result in matrix notation as\n\\ea{\\twobyone{\\bb{a}}{\\bb{b}} &=&    -i \\twobytwo{\\overline{\\bb{Q}}^{MM}}{\\overline{\\bb{Q}}^{MN}}{\\overline{\\bb{Q}}^{NM}}{\\overline{\\bb{Q}}^{NN}} \\cdot \\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N} = -i \\overline{\\bb{Q}} \\cdot\\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N} \\label{abQ}  } \n\n\\noindent where\n\\eq{\\left[\\overline{\\bb{Q}}^{MM}\\right]_{lm,pq} = k_1^2 \\int_S dS' \\left( \\left(\\dfrac{\\mu_1 k_2}{\\mu_2 k_1}\\right)  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br') +  \\Nhat{k_1,\\br'}  \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br') \\right) \\label{ebcmQ1} }\n\\eq{\\left[\\overline{\\bb{Q}}^{MN}\\right]_{lm,pq} = k_1^2 \\int_S dS' \\left(  \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right) \\Mhat{k_1,\\br'}   \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br') +    \\Nhat{k_1,\\br'}  \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br') \\right) \\label{ebcmQ2}}\n\\eq{\\left[\\overline{\\bb{Q}}^{NM}\\right]_{lm,pq} =k_1^2\\int_S dS' \\left(  \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right)  \\Nhat{k_1,\\br'}\\cdot \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br') +   \\Mhat{k_1,\\br'}   \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br') \\right) \\label{ebcmQ3}}\n\\eq{\\left[\\overline{\\bb{Q}}^{NN}\\right]_{lm,pq} =k_1^2\\int_S dS' \\left( \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right)    \\Nhat{k_1,\\br'}\\cdot \\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br') +  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br') \\right) \\label{ebcmQ4} }\n\n%\\eq{\\left[\\bb{Q}^{MM}\\right]_{lm,pq} = k_1 \\int_S dS'\\left( i \\omega \\mu_1  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  k_1 \\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{MN}\\right]_{lm,pq} = k_1 \\int_S dS'\\left( i \\omega \\mu_1  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  k_1 \\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{NM}\\right]_{lm,pq} =k_1\\int_S dS'\\left( i \\omega \\mu_1   \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') - k_1 \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{NN}\\right]_{lm,pq} =k_1\\int_S dS'\\left( i \\omega \\mu_1   \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') - k_1 \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n\n\n%\n%\\eq{\\left[\\bb{Q}^{MM}\\right]_{lm,pq} = k_1^2 \\int_S dS' \\left( \\left(\\dfrac{\\mu_1 k_2}{\\mu_2 k_1}\\right)  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  \\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{MN}\\right]_{lm,pq} = k_1^2 \\int_S dS' \\left(  \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right) \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -    \\Nhat{k_1,\\br'}  \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{NM}\\right]_{lm,pq} =k_1^2\\int_S dS' \\left(  \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right)  \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -   \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\eq{\\left[\\bb{Q}^{NN}\\right]_{lm,pq} =k_1^2\\int_S dS' \\left( \\left(\\dfrac{\\mu_1k_2}{\\mu_2 k_1}\\right)    \\Nhat{k_1,\\br'}\\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  \\Mhat{k_1,\\br'}   \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n\n%\\hat{n}'\\times\\textit{Rg}\\bb{M}_{pq}(k_2,\\br')\n%\\hat{n}'\\times\\textit{Rg}\\bb{N}_{pq}(k_2,\\br')\n\n\\underline{Step 3}: The third step is to relate scattered field coefficients to the incident field coefficients. For this, the surface integral equation for the scattered field in region 1 is given by, \\cite{chew1995waves},\n\\eq{\\bb{E}_{sca}(\\br) = \\int_S dS'\\left( i \\omega \\mu_1 \\G{1} \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') + \\left[\\nabla \\times \\G{1} \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right), \\quad \\br \\in V_1  \\label{ebcmSIEV3}}\n\nIn the extinction theorem, the surface integral equations for each Green's function come in pairs, and \\eqref{ebcmSIEV3} is the second of the pair for $\\G{1}$.  The scattered field is expanded with radiating waves in region 1 as\n\\eq{\\bb{E}_{sca}(\\br) = \\onebytwo{\\bb{M}^t(k_1,\\br)}{ \\bb{N}^t(k_1,\\br)}\\twobyone{\\bb{c}}{\\bb{d}}, \\quad \\br \\in V_1 \\label{ebcmesca1}}\n\nUsing the form of the dyadic Green's function in \\eqref{ebcmg2}, but evaluated with $k_1$, and then repeating the procedure of Step 2, it can be shown that \n\\ea{\\twobyone{\\bb{c}}{\\bb{d}} &=&   i\\textit{Rg}\\overline{\\bb{Q}} \\cdot\\twobyone{\\boldsymbol{\\beta}^M}{\\boldsymbol{\\beta}^N} \\label{abQ2}}\n\n\\noindent where $\\textit{Rg}\\overline{\\bb{Q}}$ means use the regular form of the vector wave functions with $(l,m)$ index that are contributed by the addition theorem. \n\n\\underline{Step 4}: Finally, solving \\eqref{abQ} for $\\boldsymbol{\\beta}$, substituting the result into \\eqref{abQ2}, and applying the definition of the T-matrix, \\eqref{Tmatrixdef}, we get  \n\\eq{\\overline{\\bb{T}} = -\\textit{Rg}\\overline{\\bb{Q}}\\cdot \\overline{\\bb{Q}}^{-1} \\label{tmatrixqq} }\n\n\nThe T-matrix is independent of the wave function normalization. Our derivation uses fully normalized wave functions. The derivation in \\cite{duan2015experimental} used partially normalized wave functions where a factor of $1/l(l+1)$ appears in the Green's function addition theorem and therefore in the expressions for the $\\overline{\\bb{Q}}$ matrices. However, a factor of $1/\\sqrt{l(l+1)}$ can be distributed to each wave function to make them fully normalized. %Therefore, \\eqref{ebcmQ1}-\\eqref{ebcmQ4} are equivalent to the same expressions in \\cite{duan2015experimental}. \n\nWe can rederive the T-matrix of the dielectric sphere in Section \\ref{sec:tmatrixsphere} to validate \\eqref{ebcmQ1}-\\eqref{ebcmQ4}. From \\eqref{MNrorth1}-\\eqref{MNrorth3}, the cross products of wave functions in \\eqref{ebcmQ1}-\\eqref{ebcmQ4}, when integrated over the surface of the sphere, will be zero if the pair of wave functions are the same type, and will be nonzero for dissimilar pairs. From orthogonality, only like-harmonics survive the integration. These mean that $\\overline{\\bb{Q}}^{MM}$ and $\\overline{\\bb{Q}}^{NN}$ will be diagonal and $\\overline{\\bb{Q}}^{MN} = \\overline{\\bb{Q}}^{NM} = 0$. From \\eqref{MNrorth3}, what remains are combinations of products of spherical Bessel functions, spherical Hankel functions, and their modified derivatives. The fact that the cross products in \\eqref{ebcmQ1} or \\eqref{ebcmQ4} are flipped yields a minus sign so that we get a difference between products of Bessel functions. Finally, $\\textit{Rg}\\overline{\\bb{Q}}$ will put regular-type Bessel functions in the numerator of the T-matrix diagonal, while the inverse, $\\overline{\\bb{Q}}^{-1}$, will put mixed Bessel-Hankel products in the denominator. This is precisely the result in \\eqref{clmalm} and \\eqref{dlmblm}.  \n\n\\paragraph{Computation}\nNotes on the computation:\n\\begin{itemize}\n  \\setlength{\\itemsep}{1pt}\n  \\setlength{\\parskip}{0pt}\n  \\setlength{\\parsep}{0pt}\n\\item The surface integrals in \\eqref{ebcmQ1}-\\eqref{ebcmQ4} have to be discretized. Each surface point will have its own differential surface area and surface normal unit vector. \n\\item The infinite sums of the expansions have to be truncated. The maximum degree harmonic, $L$, must be large enough to keep the solution accurate. However, the amplitude of the T-matrix elements decay beyond a certain maximum harmonic based on the object size and wavelength. In practice, the computation can be performed multiple times with finer surface discretization and more harmonics until the T-matrix coverages to a stable value.  \n\\item $\\overline{\\bb{Q}}$ is a square matrix. This facilitates the matrix inverse and yields a square T-matrix. \n\\item Direct inversion of $\\overline{\\bb{Q}}^{-1}$ is not recommended. Use matrix decomposition or indirect inversion.\n\\item Both $\\textit{Rg}\\overline{\\bb{Q}}$ and $ \\overline{\\bb{Q}}$ need to be stored in order to compute the matrix inverse and matrix multiplication. They also have to be stored separately because they contain different mixtures of radial Bessel functions. \n\\item There are only four unique wave function cross products in \\eqref{ebcmQ1}-\\eqref{ebcmQ4}.\n\\item The constant $k_1^2$ in \\eqref{ebcmQ1}-\\eqref{ebcmQ4} can be ignored because it will cancel in \\eqref{tmatrixqq}.\n\\item Because $ \\overline{\\bb{Q}}$ must be stored, and because our wave function routines, \\texttt{BC} and \\texttt{MN}, return all harmonics for a given set of points, it is advantageous to compute $\\textit{Rg}\\overline{\\bb{Q}}$ and $\\overline{\\bb{Q}}$ as a running sum over the surface discretization. This is likely slower than building and manipulating temporary 3D arrays spanning the two harmonics indices and all surface points. However, trading storage for computation time allows the surface discretization to be made arbitrarily small for a fixed number of harmonics.\n\\item The wave functions are separable in spherical coordinates, the radial functions only differ in wavenumber, and the angular functions only differ by conjugation. It is advantageous to deconstruct, and then rebuild, the wave functions combinations inline.\n\\item The four submatrices, \\eqref{ebcmQ1}-\\eqref{ebcmQ4}, can be thought of as being formed by the outer product between the harmonic indices $(l,m)$ and $(p,q)$, where $(l,m)$ are along rows and $(p,q)$ are along columns. For any surface point, we only need to compute two sets of 1D arrays that contain harmonics up to a maximum degree $L$ and then construct the outer product.\n\n%\\item  The wave functions are separable in spherical coordinates, therefore the vector spherical harmonics that make up the wave functions only need to be computed once. Likewise for the Bessel functions. Combinations of cross products are then needed to build $\\textit{Rg}\\overline{\\bb{Q}}$ and $\\overline{\\bb{Q}}$. \n\\item The vector identity $\\bb{a} \\cdot (\\bb{b} \\times \\bb{c}) = \\bb{b} \\cdot (\\bb{c} \\times \\bb{a})$ can be used in \\eqref{ebcmQ1}-\\eqref{ebcmQ4} to bring the surface normal outside the parentheses and write the matrix elements as cross products of wave functions. In doing so, the vector products can be computed once and then applied to all harmonics as simple scale factors.\n\\item Finally, we use the following shorthand and derive simplifications for wave function cross product combinations. This assumes that the computation loops over surface points and constructs the four submatrices as outer products of harmonics per surface point. Let the $\\bb{M}$ and $\\bb{N}$ wave functions, Section \\ref{sec:vecsphwave}, be written in the shorthand\n\\ea{\\bb{M}_j &=& c_j  \\bb{C}_j \\\\\n\\bb{N}_j &=& p_j  \\bb{P}_j + b_j  \\bb{B}_j }\n\\noindent where $c_j = c(k_j r)$, $p_j= p(k_j r)$, and $b_j= b(k_j r)$ are the regular or irregular radial Bessel functions associated with each vector spherical harmonic function. The index $j = [1, 2]$ keeps track of the wavenumber of the Bessel functions, $k_1$ or $k_2$, as well as the family of index: $(l,m)$ or $(p,q)$. From Section \\ref{sec:vecsphharm}, we can write the vector spherical harmonics in the shorthand\n\\ea{\\bb{P}_j &=& W_j \\hat{r} \\\\\n\\bb{B}_j &=& V_j\\hat{\\theta} + U_j\\hat{\\phi} \\\\\n\\bb{C}_j &=& U_j\\hat{\\theta} - V_j\\hat{\\phi} }\n\\noindent where $U$, $V$, $W$ are the unique spherical functions that make up the vector spherical harmonics.  Next, we need the following cross products\n\\ea{\\bb{C}_1 \\times \\bb{C}_2 &=& \\hat{r}(V_1U_2 - U_1 V_2) \\\\\n\\bb{B}_1 \\times \\bb{B}_2 &=& \\hat{r}(V_1U_2 - U_1 V_2) \\\\\n\\bb{C}_1 \\times \\bb{B}_2 &=& \\hat{r}(U_1U_2 + V_1V_2) \\\\\n\\bb{C}_1 \\times \\bb{P}_2 &=& - (V_1\\hat{\\theta} + U_1\\hat{\\phi})W_2 \\\\\n\\bb{B}_1 \\times \\bb{P}_2 &=& (U_1\\hat{\\theta} - V_1\\hat{\\phi})W_2 \\\\\n%\\bb{B}_1 \\times \\bb{P}_2 &=& W_2(U_1\\hat{\\theta} - V_1\\hat{\\phi}) = W_2 \\bb{C}_1 \\\\\n\\bb{P}_1 \\times \\bb{P}_2 &=& 0 }\n\nAssume that every cross product in \\eqref{ebcmQ1}-\\eqref{ebcmQ4} is converted to a form, for example, $\\bb{M}_1 \\cdot (\\hat{n} \\times \\bb{N}_2) = - \\hat{n} \\cdot (\\bb{M}_1  \\times \\bb{N}_2)$. The minus sign can be ignored because it is common to all terms and will cancel in \\eqref{tmatrixqq}. The wave function cross products are then:\n\\begin{align}\n\\bb{M}_1 \\times \\bb{M}_2 &= (c_1 \\bb{C_1})\\times (c_2 \\bb{C_2}) \\\\\n\\ &= \\hat{r} c_1c_2 (V_1U_2- U_1V_2) \\label{crossexample} \\\\\n\\bb{N}_1 \\times \\bb{N}_2 &= (p_1\\bb{P}_1 + b_1 \\bb{B}_1)\\times (p_2\\bb{P}_2 + b_2 \\bb{B}_2) \\\\\n\\ &= \\hat{r} b_1b_2(V_1U_2 - U_1V_2) + \\hat{\\theta} (b_1U_1p_2W_2 - p_1W_1b_2U_2)  + \\hat{\\phi}(p_1W_1b_2V_2 - b_1V_1p_2W_2) \\\\\n\\bb{M}_1 \\times \\bb{N}_2 &= (c_1 \\bb{C}_1) \\times (p_2 \\bb{P}_2 + b_2 \\bb{B}_2) \\\\\n\\ &= \\hat{r} c_1b_2 (U_1 U_2 + V_1 V_2) - \\hat{\\theta} c_1 V_1 p_2 W_2 - \\hat{\\phi} c_1U_1 p_2 W_2 \\\\\n\\bb{N}_1 \\times \\bb{M}_2  &=  (p_1 \\bb{P}_1 + b_1 \\bb{B}_1)\\times (c_2 \\bb{C}_2)  \\\\\n\\ &= -\\hat{r} b_1 c_2 (U_1 U_2 + V_1 V_2) + \\hat{\\theta}p_1 W_1 c_2 V_2 + \\hat{\\phi} p_1 W_1 c_2U_2  \n\\end{align}\n\n%\\begin{align}\n%\\bb{M}_1 \\times \\bb{M}_2 &= (c_1 \\bb{C_1})\\times (c_2 \\bb{C_2}) \\\\\n%\\ &= \\hat{r} c_1c_2 (V_1U_2- U_1V_2) \\label{crossexample} \\\\\n%\\bb{N}_1 \\times \\bb{N}_2 &= (p_1\\bb{P}_1 + b_1 \\bb{B}_1)\\times (p_2\\bb{P}_2 + b_2 \\bb{B}_2) \\\\\n%%\\ &=& -p_1W_1b_2\\bb{C}_2 + p_2W_2 b_1\\bb{C}_1 + b_1b_2 \\bb{B}_1 \\times \\bb{B}_2 \\\\\n%\\ &= \\hat{r} b_1b_2(V_1U_2 - U_1V_2) + \\hat{\\theta} (b_1U_1p_2W_2 - p_1W_1b_2U_2)  + \\hat{\\phi}(p_1W_1b_2V_2 - b_1V_1p_2W_2) \\\\\n%\\bb{M}_1 \\times \\bb{N}_2 &= (c_1 \\bb{C}_1) \\times (p_2 \\bb{P}_2 + b_2 \\bb{B}_2) \\\\\n%%\\ &=& c_1p_2 \\bb{C}_1 \\times \\bb{P}_2 + c_1b_2 \\bb{C}_1 \\times \\bb{B}_2 \\\\\n%\\ &= \\hat{r} c_1b_2 (U_1 U_2 + V_1 V_2) - \\hat{\\theta} c_1 V_1 p_2 W_2 - \\hat{\\phi} c_1U_1 p_2 W_2 \\\\\n%\\bb{N}_1 \\times \\bb{M}_2  &=  (p_1 \\bb{P}_1 + b_1 \\bb{B}_1)\\times (c_2 \\bb{C}_2)  \\\\\n%%\\ &=& c_1p_2 \\bb{C}_1 \\times \\bb{P}_2 + c_1b_2 \\bb{C}_1 \\times \\bb{B}_2 \\\\\n%\\ &= -\\hat{r} b_1 c_2 (U_1 U_2 + V_1 V_2) + \\hat{\\theta}p_1 W_1 c_2 V_2 + \\hat{\\phi} p_1 W_1 c_2U_2  \n%\\end{align}\n\n\nThe dot product between $\\hat{n}$ and any unit vector that results from the cross products reduces to a scale factor. Radial and angular functions with like index must to be multiplied together. The product between functions of index 1 and 2 are computed as an outer product over harmonics. The first wave function always has $\\hat{\\ }$, and the Bessel functions of the second wave function are always regular. The vector spherical harmonics between index 1 and 2 only differ by conjugation. \n\nFor example, in \\eqref{crossexample}, for a single point of the surface discretization, we will a) compute the column vector $f_1 = c_1U_1$ over $(l,m)$, b) multiply this by any scale factors including the dot product with $\\hat{n}$, c) compute the column vector over $(p,q)$ as $f_2 = c_2 U_2 = c_2 U_1^*$, where $^*$ means conjugate, d) take the outer product $f_1 \\cdot f_2^t$, where $^t$ is transpose, then e) add the resulting matrix to the running sum of $\\overline{\\bb{Q}}$. This is done for all the combinations of wave functions needed in \\eqref{ebcmQ1}-\\eqref{ebcmQ4}. \n\\end{itemize}\n\n\\vspace{-5mm}\n\n\\begin{figure}[H] \n   \\centering\n   \\subfigure{\\includegraphics[width=5in]{Tmatrix/Figures/ebcmsphere}} \\\\\n   \\subfigure{\\includegraphics[width=2.9in]{Tmatrix/Figures/ebcmTmm}}\n   \\subfigure{\\includegraphics[width=2.9in]{Tmatrix/Figures/ebcmTnn}}\n   \\caption{Top: Surface discretization of a dielectric sphere for the EBCM. Sphere has a radius of 1$\\lambda$ and a relative permittivity of 2 in a background of free-space. The facet vertices are distributed in a disco ball arraignment. A total of 2192 surface facets are determined from the convex hull of a 3D Delaunay triangularization. Surface normal vectors are shown at the centroid of each facet. The facet centroids are the integration points, $\\br'$. Facet area is determined from the cross product of two triangle edge vectors. Bottom: Real and imaginary parts of the diagonal $T^{MM}$ and $T^{NN}$ T-matrices computed with \\texttt{ebcm} and compared to the T-matrices computed analytically with \\texttt{tmatrixDielectricSphere}. Small differences are apparent. The EBCM result improves with finer surface discretization. }\n   \\label{ebcmcompare}\n\\end{figure}\n\n\n\\clearpage\n\\paragraph{Routine}\n\nThe routine \\texttt{ebcm} returns the four block T-matrices computed using the EBCM, \\eqref{tmatrixqq}. The T-matrices are square and have harmonics up to maximum degree $L$ all $\\pm m$ linearly indexed. The routine takes as input the wavenumbers, $k_1$ and $k_2$, in the outer and inner regions, respectively, the maximum degree harmonic, $L$, and user-provided surface discretization. The surface discretization needs the Cartesian coordinates of surface points, $\\br'$, the differential area at each point, $dS'$, and the Cartesian components of the outward surface unit normal vector, $\\hat{n}'$, at each point. The arrays describing the surface can be any size, but must be the same size. The permeabilities, $\\mu_1$ and $\\mu_2$, are optional, and default to 1, and when needed, they can be relative or absolute, but must also be included in $k_1$ and $k_2$. The matrices $\\textit{Rg}\\overline{\\bb{Q}}$ and $\\overline{\\bb{Q}}$ are computed as running sums over surface points in order to limit the total size of temporary arrays. The matrix inverse, $\\overline{\\bb{Q}}^{-1}$, is computed with Matlab's right matrix divide, \\texttt{'/'}.  Two helper functions, \\texttt{ebcmbessel} and \\texttt{ebcmprod}, are used to organize the code and compute combinations of spherical Bessel and angular functions. The results match the analytic expressions derived for the T-matrix of a dielectric sphere, shown in Figure \\ref{ebcmcompare}. \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/ebcm.m}\n}\n\n\n%\\ea{\\bb{E}_{inc}(\\br) &=& \\sum_{l=1}^{\\infty}\\sum_{m=-l}^l a_{lm} \\textit{Rg}\\M{k_1,\\br}  + b_{lm}\\textit{Rg}\\N{k_1,\\br} \\nonumber \\\\\n%\\ & =& -\\int_S dS'\\left( i \\omega \\mu_1 \\left(ik_1\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right) \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -\\right. \\nonumber \\\\\n%\\ &=& \\left. \\left[\\nabla'\\times \\left(ik_1\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right)  \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\ea{a_{lm} &=& -ik_1 \\int_S dS'\\left( i \\omega \\mu_1 \\left(\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right) \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -\\right. \\nonumber \\\\\n%\\ & & \\left. \\left[\\nabla'\\times \\left(\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right)  \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\n%\\ea{b_{lm} &=& -ik_1\\int_S dS'\\left( i \\omega \\mu_1 \\left(\\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right) \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -\\right. \\nonumber \\\\\n%\\ & & \\left. \\left[\\nabla'\\times \\left( \\sum_{l=1}^{\\infty}\\sum_{m=-l}^l \\textit{Rg}\\M{k_1,\\br}\\Mhat{k_1,\\br'} + \\textit{Rg}\\N{k_1,\\br}\\Nhat{k_1,\\br'}\\right)  \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\n%\\ea{a_{lm} &=& -ik_1 \\int_S dS'\\left( i \\omega \\mu_1 \\left(  \\Mhat{k_1,\\br'}  \\right) \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') -  \\left[\\nabla'\\times \\left( \\Mhat{k_1,\\br'}  \\right)  \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n%\n%\\ea{b_{lm} &=& -ik_1\\int_S dS'\\left( i \\omega \\mu_1 \\left(   \\Nhat{k_1,\\br'}\\right) \\cdot \\hat{n}' \\times \\bb{H}_1(\\br') - \\left[\\nabla'\\times \\left( \\Nhat{k_1,\\br'}\\right)  \\right] \\cdot \\hat{n}' \\times \\bb{E}_1(\\br') \\right) }\n\n\\clearpage\n\\newpage\n\n\\section{T-matrix to S-matrix Transformation}\n\\label{secTtoS}\n\nHere we derive the relationship between the T-matrix and S-matrix. Start with the expression for the scattered field, \\eqref{tmatrixesca}, then write out the sums and expand the vector wave functions in their far-field approximations, \\eqref{farfieldM} and \\eqref{farfieldN}, \n\\eq{\\lim_{kr \\rightarrow \\infty} \\bb{E}_s(\\hat{k}_s) = \\dfrac{e^{ikr}}{kr}  \\sum_{l=1}^{\\infty}\\sum_{m=-l}^l i^{-l-1} c_{lm} \\bb{C}_{lm}(\\theta_s,\\phi_s) +  i^{-l}   d_{lm}  \\bb{B}_{lm}(\\theta_s,\\phi_s) }\n\nSubstituting the definition of the T-matrix\n\\ea{ \\bb{E}_s(\\hat{k}_s) &=& \\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\sum_{l'm'} i^{-l-1} \\bb{C}_{lm}(\\theta_s,\\phi_s)\\left(T^{MM}_{lm,l'm'} a_{l'm'} + T^{MN}_{lm,l'm'} b_{l'm'}  \\right)   \\nonumber \\\\\n\\ & \\ & + i^{-l}   \\bb{B}_{lm}(\\theta_s,\\phi_s)\\left(T^{NM}_{lm,l'm'} a_{l'm'} + T^{NN}_{lm,l'm'} b_{l'm'}  \\right)  }\n\nThe coefficients $a_{lm}$ and $b_{lm}$ are chosen as the expansion coefficients for the vector plane waves, \\eqref{almplaneE} and \\eqref{blmplaneE}, giving \n\\ea{\\bb{E}_s(\\hat{k}_s) &=& 4\\pi\\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\sum_{l'm'} i^{-l-1} \\bb{C}_{lm}(\\theta_s,\\phi_s)\\left(T^{MM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  - T^{MN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\bb{E}_i   \\nonumber \\\\\n\\ & \\ &  + i^{-l}   \\bb{B}_{lm}(\\theta_s,\\phi_s)\\left(T^{NM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  - T^{NN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\bb{E}_i  \\label{scattmatrix1}  }\n\n\\noindent where $(\\theta_i,\\phi_i)$ are the spherical angles of the incident field direction, and $\\bb{E}_i$ is the polarized incident electric field.  At this point, the sum can be computed directly and dotted with the polarization unit vectors as needed.  This is written more clearly in matrix notation over the $\\theta$, $\\phi$ components of the fields as\n\\ea{\\twobyone{E_{s,\\theta}(\\hat{k}_s)}{E_{s,\\phi}(\\hat{k}_s)} &=& 4\\pi\\dfrac{e^{ikr}}{kr} \\twobytwo{\\bb{C}_{\\theta}^t(\\theta_s,\\phi_s)}{\\bb{B}_{\\theta}^t(\\theta_s,\\phi_s)}{\\bb{C}_{\\phi}^t(\\theta_s,\\phi_s)}{\\bb{B}_{\\phi}^t(\\theta_s,\\phi_s)}\n\\twobytwo{\\overline{\\bb{L}}_1}{0}{0}{\\overline{\\bb{L}}_2} \n\\tbt{\\overline{\\bb{T}}^{MM}}{\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{NM}}{\\overline{\\bb{T}}^{NN}}  \\nonumber \\\\\n\\ & \\ & \\twobytwo{\\overline{\\bb{L}}_2^{-1}}{0}{0}{-\\overline{\\bb{L}}_1^{-1}} \\twobytwo{\\bb{C}_{\\theta}^*(\\theta_i,\\phi_i) }{\\bb{C}_{\\phi}^*(\\theta_i,\\phi_i) }{\\bb{B}_{\\theta}^*(\\theta_i,\\phi_i) } {\\bb{B}_{\\phi}^*(\\theta_i,\\phi_i) } \\twobyone{E_{i,\\theta}(\\hat{k}_i)}{E_{i,\\phi}(\\hat{k}_i)} \\label{scattmatrix} }\n\nThe vector spherical harmonics are column vectors over harmonics $(l,m)$ (where $^t$ is transpose and $^*$ is simple conjugate). The coefficient matrices $\\bb{L}$ are diagonal with elements\n\\ea{\\left[ \\overline{\\bb{L}}_1\\right]_{ll} &=& i^{-l-1}  \\\\\n\\left[ \\overline{\\bb{L}}_2\\right]_{ll} &=& i^{-l} }\n\n\n%4\\pi i^l  \\bb{C}^*_{lm}(\\theta_k,\\phi_k)  \\cdot  \\bb{E} \n%-4\\pi i^{l+1}  \\bb{B}^*_{lm}(\\theta_k,\\phi_k) \\cdot  \\bb{E} \n\nChoosing the orthonormal basis formed by the spherical unit vectors $\\hat{k} = \\hat{r}$, $\\hat{\\theta}$, and $\\hat{\\phi}$, the scattered field can be written \n\\eq{\\bb{E}_s = \\left( \\hat{\\theta}_s E_{\\theta,s} + \\hat{\\phi}_s E_{\\phi,s} \\right) \\dfrac{e^{ikr}}{r}}\nFrom which we have the S-matrix \n\n\\begin{equation}\n\\twobyone{E_{s,\\theta}(\\hat{k}_s)}{E_{s,\\phi}(\\hat{k}_s)} = \n\\twobytwo\n{S_{\\theta\\theta}(\\hat{k}_s,\\hat{k}_i) }\n{S_{\\theta\\phi}(\\hat{k}_s,\\hat{k}_i) }\n{S_{\\phi\\theta}(\\hat{k}_s,\\hat{k}_i) }\n{S_{\\phi\\phi}(\\hat{k}_s,\\hat{k}_i) }   \n\\twobyone{E_{i,\\theta}(\\hat{k}_i)}{E_{i,\\phi}(\\hat{k}_i)} \n\\end{equation}\n\n\n%Here, $\\hat{\\theta}$, and $\\hat{\\phi}$ are the same as the $\\hat{h}$ and $\\hat{v}$ polarizations in the 'wave-oriented' or 'forward scattering alignment' (FSA) polarization convention \\cite{ulaby2014microwave}, relative to the z-axis. \n\n%We essentially derived the relation between the T-matrix and the S-matrix in \\eqref{scattmatrix} by writing the scattered field using the far-field vector wave functions and coefficients for the vector incident plane waves. \n\nFurther vectorizing \\eqref{scattmatrix} over incident and scattered directions, the T-matrix to S-matrix transformation can be written in block matrices, where the block vector spherical harmonics have harmonic indices along rows and wave vector directions along columns. The component S-matrix blocks are\n\\eq{\\twobytwo\n{\\overline{\\bb{S}}_{\\theta\\theta} }\n{\\overline{\\bb{S}}_{\\theta\\phi}}\n{\\overline{\\bb{S}}_{\\phi\\theta} }\n{\\overline{\\bb{S}}_{\\phi\\phi} }   \n=\n\\dfrac{4\\pi}{k} \\twobytwo{\\overline{\\bb{C}}_{\\theta}}{\\overline{\\bb{B}}_{\\theta}}{\\overline{\\bb{C}}_{\\phi}}{\\overline{\\bb{B}}_{\\phi}}\\twobytwo{\\overline{\\bb{L}}_1}{0}{0}{\\overline{\\bb{L}}_2} \\tbt{\\overline{\\bb{T}}^{MM}}{\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{NM}}{\\overline{\\bb{T}}^{NN}}  \\twobytwo{\\overline{\\bb{L}}_2^{-1}}{0}{0}{-\\overline{\\bb{L}}_1^{-1}} \\twobytwo{\\overline{\\bb{C}}_{\\theta}^*}{\\overline{\\bb{C}}_{\\phi}^*}{\\overline{\\bb{B}}_{\\theta}^* } {\\overline{\\bb{B}}_{\\phi}^*} \\label{TtoSBC}} \n\n\\noindent where here $^*$ is conjugate transpose. The S-matrix block matrices have scattered field directions along rows, and incident field directions along columns. Recall that the left vector spherical harmonics are evaluated at scattered directions, and the right ones are evaluated at incident directions. This can be used to compute the S-matrix at arbitrary combinations of incident and scattered directions. Also the vector spherical harmonics are fully normalized.  See Section \\ref{fastTtoS} for an exact computation of this using spherical harmonic transforms when the S-matrix can be sampled on the nodes of Gaussian quadrature. \n\nThe routine \\texttt{compute\\char`_S\\char`_from\\char`_T}, computes the four spherical vector components of the S-matrix given the four components of the T-matrix. The block T-matrices are $N \\times N$ with harmonics up to degree $L$ all $m$ linearly indexed. The routine takes the incident and scattered directions, which can be different sizes between them. The size of the output S-matrix block matrices is the size of an array that is the concatenation of the scattered and incident direction array in that order. The fully normalized vector spherical harmonics are used. The matrix multiplication is fast, but the routine can run out of memory quickly for large $L$ and large number of wave directions. The routine gives identical results to the ones in Section \\ref{fastTtoS} based on Gaussian quadrature.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/compute_S_from_T.m}\n}\n\n\n\\section{S-matrix to T-matrix Transformation}\n\\label{secStoT}\n\nThe S-matrix to T-matrix transformation requires integrating the S-matrix components and vector spherical harmonics over the unit spheres of incident and scattered directions. Let the diagonal matrix $\\overline{\\bb{W}}$ hold the weights of the discretized surface integral over the sphere, where the integral is applied over the sphere of wave vector directions. From orthogonality of the fully normalized vector spherical harmonics, we have the identity\n\\eq{ \\twobytwo{\\overline{\\bb{C}}_{\\theta}^*}{\\overline{\\bb{C}}_{\\phi}^*}{\\overline{\\bb{B}}_{\\theta}^* } {\\overline{\\bb{B}}_{\\phi}^*} \n\\twobytwo{\\overline{\\bb{W}}}{0}{0}{\\overline{\\bb{W}}} \n\\twobytwo{\\overline{\\bb{C}}_{\\theta}}{\\overline{\\bb{B}}_{\\theta}}{\\overline{\\bb{C}}_{\\phi}}{\\overline{\\bb{B}}_{\\phi}} \n= \\twobytwo{\\overline{\\bb{I}}}{0}{0}{\\overline{\\bb{I}}} } \n\nThis identity assumes that the weights are chosen so that the integral is computed exactly. Using this, \\eqref{TtoSBC} can be manipulated to give\n\n\\eq{\\tbt{\\overline{\\bb{T}}^{MM}}{\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{NM}}{\\overline{\\bb{T}}^{NN}}  \n=\n\\dfrac{k}{4\\pi} \n\\twobytwo{\\overline{\\bb{L}}_1^{-1}}{0}{0}{\\overline{\\bb{L}}_2^{-1}} \n\\twobytwo{\\overline{\\bb{C}}_{\\theta}^*}{\\overline{\\bb{C}}_{\\phi}^*}{\\overline{\\bb{B}}_{\\theta}^* } {\\overline{\\bb{B}}_{\\phi}^*} \n\\twobytwo{\\overline{\\bb{W}}}{0}{0}{\\overline{\\bb{W}}} \n\\twobytwo\n{\\overline{\\bb{S}}_{\\theta\\theta} }\n{\\overline{\\bb{S}}_{\\theta\\phi}}\n{\\overline{\\bb{S}}_{\\phi\\theta} }\n{\\overline{\\bb{S}}_{\\phi\\phi} }   \n\\twobytwo{\\overline{\\bb{W}}}{0}{0}{\\overline{\\bb{W}}} \n\\twobytwo{\\overline{\\bb{C}}_{\\theta}}{\\overline{\\bb{B}}_{\\theta}}{\\overline{\\bb{C}}_{\\phi}}{\\overline{\\bb{B}}_{\\phi}} \n\\twobytwo{\\overline{\\bb{L}}_2}{0}{0}{-\\overline{\\bb{L}}_1} \\label{StoTBC}}\n\nThis expression transforms the S-matrix to the T-matrix under the condition that the S-matrix is fully sampled and can be accurately integrated with $\\overline{\\bb{W}}$. See Section \\ref{fastStoT} for a fast routine that computes this integral exactly when the S-matrix is sampled at the nodes of Gaussian quadrature. \n\n\\section{Far-field T-matrix}\n\nIn \\eqref{TtoSBC} the inner three matrices of the T-matrix to S-matrix transformation convert between vector spherical harmonic expansions on either side of the T-matrix. From this, it is possible to define a far-field T-matrix that transforms between incoming and outgoing far-field plane-wave patterns that are expressed in vector spherical harmonics.\n\nLet an incoming far-field pattern of a field and its vector spherical harmonic expansion be defined\n\\begin{eqnarray}\n\\bb{F}(\\theta,\\phi) &=& F_{\\theta}(\\theta,\\phi) \\hat\\theta + F_{\\phi}(\\theta,\\phi) \\hat\\phi \\\\\n\\ & = & \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm} \\bb{B}_{lm}(\\theta,\\phi) + c_{lm} \\bb{C}_{lm}(\\theta,\\phi)\n\\end{eqnarray}\n\n\\noindent and let an outgoing far-field pattern due to a scatterer and its vector spherical harmonic expansion be\n\\begin{eqnarray}\n\\bb{F}'(\\theta,\\phi) &=& F_{\\theta}'(\\theta,\\phi) \\hat\\theta + F_{\\phi}'(\\theta,\\phi) \\hat\\phi \\\\\n\\ & = & \\sum_{l=1}^{L} \\sum_{m = -l}^{l} b_{lm}' \\bb{B}_{lm}(\\theta,\\phi) + c_{lm}' \\bb{C}_{lm}(\\theta,\\phi)\n\\end{eqnarray}\n\nBoth field expansions are band limited with the same number of harmonics. Define the far-field T-matrix to transform the vector spherical harmonic coefficients of the incoming field to those of the outgoing field:\n\\begin{equation}\n\\twobyone{\\bb{b}'}{\\bb{c}'} = \\twobytwo{\\overline{\\bb{T}}^{BB}}{\\overline{\\bb{T}}^{BC}}{\\overline{\\bb{T}}^{CB}}{\\overline{\\bb{T}}^{CC}}\\twobyone{\\bb{b}}{\\bb{c}} \\label{TBC}\n\\end{equation}\n\nUsing \\eqref{TtoSBC}, this is related to the full T-matrix as\n\\eq{\n\\twobytwo{\\overline{\\bb{T}}^{BB}}{\\overline{\\bb{T}}^{BC}}{\\overline{\\bb{T}}^{CB}}{\\overline{\\bb{T}}^{CC}}= \\dfrac{4\\pi}{k} \\twobytwo{\\overline{\\bb{L}}_2}{0}{0}{\\overline{\\bb{L}}_1} \\tbt{\\overline{\\bb{T}}^{NN}}{\\overline{\\bb{T}}^{NM}}  {\\overline{\\bb{T}}^{MN} }{\\overline{\\bb{T}}^{MM}}\\twobytwo{-\\overline{\\bb{L}}_1^{-1}}{0}{0} {\\overline{\\bb{L}}_2^{-1}}\\label{ffTmatrix}} \n\nThe reverse is accomplished by simple inversion.\n\nThe routines  \\texttt{convert\\char`_T\\char`_to\\char`_Tfar} and  \\texttt{convert\\char`_Tfar\\char`_to\\char`_T} will transform T-matrix to a far-field T-matrix and visa versa. They take as input the four $N \\times N$ block matrices, where $N = L^2 + 2L$ and maximum harmonic degree $L$ all $m$ linearly indexed.   \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/convert_T_to_Tfar.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/convert_Tfar_to_T.m}\n}\n\n\n\\clearpage\n\\newpage\n\\section{Radar Cross Section from T-matrix}\n\nThe bistatic radar cross section is defined \n\\eq{\\sigma_{pq}(\\hat{k}_s,\\hat{k}_i) = \\lim_{r \\rightarrow \\infty} 4\\pi r^2 \\dfrac{\\left\\vert \\hat{p} \\cdot \\bb{E}_s \\right\\vert^2}{\\left\\vert \\hat{q} \\cdot \\bb{E}_i \\right\\vert^2} \\label{rcs1} }\n\nThis is used with \\eqref{scattmatrix1} to compute the radar cross section given an object T-matrix. In short, the process removes the scale factors $E_o e^{ikr}/r$ from \\eqref{scattmatrix1} and can then be evaluated given incident/scattered directions and polarizations.  Because $\\sigma_{pq} = 4\\pi \\vert S_{pq}\\vert^2$, \\eqref{rcsfromSpq}, the routine \\texttt{compute\\char`_S\\char`_from\\char`_T}, Section \\ref{secTtoS}, can be used to compute the S-matrix for $\\hat{p} = \\hat{\\theta}$ and $\\hat{q} = \\hat{\\phi}$. This can then be converted to any radar cross section polarization combination using \\eqref{projectedsmatrix}. \n\n\\subsection{Backscatter Radar Cross Section from T-matrix}\n\nIn the backscatter direction $\\theta_s = \\pi-\\theta_i$ and $\\phi_s = \\pi+\\phi_i$.  Alternatively, $\\theta_i = \\pi - \\theta_s$ and $\\phi_i = \\pi + \\phi_s$.  For a T-matrix, it is a little easier to think of backscatter as pointing from the object frame to the source, i.e., in terms of the scattered direction, Figure \\ref{brcstmatrixfig}. Therefore, using the second relations in \\eqref{scattmatrix1} with the parity relations, \\eqref{Blmparity} and \\eqref{Clmparity}, we have\n\\begin{align}\n\\bb{E}_s(\\hat{k}_s) &= 4\\pi\\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\sum_{l'm'} i^{-l-1} \\bb{C}_{lm}(\\theta_s,\\phi_s)\\left(T^{MM}_{lm,l'm'} i^{l'} (-1)^{l'} \\bb{C}^*_{l'm'}(\\theta_s,\\phi_s)  - T^{MN}_{lm,l'm'} i^{l'+1} (-1)^{l'+1} \\bb{B}^*_{l'm'}(\\theta_s,\\phi_s)  \\right)\\cdot  \\bb{E}_i   \\nonumber \\\\\n\\ &   + i^{-l}  \\bb{B}_{lm}(\\theta_s,\\phi_s)\\left(T^{NM}_{lm,l'm'} i^{l'} (-1)^{l'} \\bb{C}^*_{l'm'}(\\theta_s,\\phi_s)  - T^{NN}_{lm,l'm'} i^{l'+1} (-1)^{l'+1} \\bb{B}^*_{l'm'}(\\theta_s,\\phi_s)  \\right)\\cdot  \\bb{E}_i    \\end{align}\n\nNote the vector components of $\\bb{B}$ and $\\bb{C}$ are for the scattered direction $(\\theta_s,\\phi_s)$. Next let both the incident and scattered polarizations be written in terms of the spherical unit vectors of the scattered direction, with two separate angles, $\\beta_i$ and $\\beta_s$, \n\\ea{\\hat{\\beta}_i &=& \\cos\\beta_i \\hat{\\theta}_s + \\sin\\beta_i \\hat{\\phi}_s \\\\\n\\hat{\\beta}_s &=& \\cos\\beta_s \\hat{\\theta}_s + \\sin\\beta_s \\hat{\\phi}_s }\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=3in]{Tmatrix/Figures/brcstmatrix} \n   \\caption{Geometry the BRCS from a T-matrix.}\n   \\label{brcstmatrixfig}\n\\end{figure}\n\n\n\nUsing these in \\eqref{rcs1} the backscatter radar cross section written in terms of scattered polarizations is\n\\begin{align}\n\\sigma_{\\beta_s,\\beta_i} &= \\dfrac{(4\\pi)^3}{k^2}\\left\\vert \\sum_{lm}\\sum_{l'm'} (-i)^{l+1} \\left( \\hat{\\beta}_s\\cdot \\bb{C}_{lm}(\\theta_s,\\phi_s) \\right)\\left(T^{MM}_{lm,l'm'} (-i)^{l'} \\bb{C}^*_{l'm'}(\\theta_s,\\phi_s)  - T^{MN}_{lm,l'm'} (-i)^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_s,\\phi_s)  \\right)\\cdot \\hat{\\beta}_i  \\right. \\nonumber \\\\\n\\ &  \\left. + (-i)^{l}  \\left(  \\hat{\\beta}_s\\cdot\\bb{B}_{lm}(\\theta_s,\\phi_s)\\right)\\left(T^{NM}_{lm,l'm'} (-i)^{l'} \\bb{C}^*_{l'm'}(\\theta_s,\\phi_s)  - T^{NN}_{lm,l'm'} (-i)^{l'+1} \\bb{B}^*_{l'm'}(\\theta_s,\\phi_s)  \\right)\\cdot   \\hat{\\beta}_i   \\right\\vert^2 \\label{tmatrixbrcs2} \n\\end{align}\n\n\nThe routine \\texttt{brcs\\_from\\_Tmatrix} computes the backscatter radar cross section using \\eqref{tmatrixbrcs2}. It takes as input the four block T-matrices sized $N \\times N$ with harmonics up to degree $L$ all $m$ linearly indexed. The routine takes the scattered directions $(\\theta_s,\\phi_s)$ measured in the frame of the object, which can be any size. There are two modes: 1) if a single combination of polarization angles $\\beta_i$ and $\\beta_s$ is provided, then there is one output BRCS, 2) if the four $\\hat{\\theta}$ and $\\hat{\\phi}$ orthogonal BCRS vector combinations are requested, then the polarization angles are not needed. The outputs are the size of the angle arrays. The results match the analytical results for PED and dielectric spheres (see next sections).\n\n{\\scriptsize\n\\VerbatimInput{\\code/Tmatrix/brcs_from_Tmatrix.m}\n}\n\n\n\n%\n%Next we can ask what are the polarization and orientation averaged backscatter radar cross sections for co- and cross-polarizations.  These are given by \n%\\ea{\\left< \\sigma_{co} \\right> &=&  \\dfrac{1}{2\\pi} \\int_0^{2\\pi}\\left(  \\dfrac{1}{4\\pi} \\int \\sigma_{\\beta,\\beta}(\\hat{k}_i) d\\Omega_i \\right) d\\beta \\\\\n%\\left< \\sigma_{cross} \\right> &=&  \\dfrac{1}{2\\pi} \\int_0^{2\\pi}\\left(  \\dfrac{1}{4\\pi} \\int \\sigma_{\\beta+\\pi/2,\\beta}(\\hat{k}_i) d\\Omega_i \\right) d\\beta }\n\n%It appears quite complicated to continue analytically from \\eqref{tmatrixbrcs1} and no simple reduction has been found yet. \n\n\n\n\n\n%In the backscatter direction $\\theta_s = \\pi-\\theta_i$ and $\\phi_s = \\pi+\\phi_i$.  Using these in \\eqref{scattmatrix1} together with the parity relations for these vector spherical harmonics, \\eqref{Blmparity} and \\eqref{Clmparity}, we have\n%\\ea{\\bb{E}_s(\\hat{k}_s) &=& 4\\pi\\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\sum_{l'm'} i^{-l-1} (-1)^{l}\\bb{C}_{lm}(\\theta_i,\\phi_i)\\left(T^{MM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{MN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\bb{E}_i   \\nonumber \\\\\n%\\ & \\ &  + i^{-l}   (-1)^{l+1} \\bb{B}_{lm}(\\theta_i,\\phi_i)\\left(T^{NM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{NN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\bb{E}_i    }\n%\n%The vector components in the place of the scattered direction are now identical to those in the incident direction. Let the incident and scattered polarizations be written in terms of the spherical unit vectors relative to the incident direction, with two separate angles, $\\beta_i$ and $\\beta_s$, \n%\\ea{\\hat{\\beta}_i &=& \\cos\\beta_i \\hat{\\theta} + \\sin\\beta_i \\hat{\\phi} \\\\\n%\\hat{\\beta}_s &=& \\cos\\beta_s \\hat{\\theta} + \\sin\\beta_s \\hat{\\phi} }\n%\n%The backscatter cross section given in terms of polarizations measured from the view of the incident direction is\n%\\ea{\\sigma_{\\beta_s,\\beta_i} &=& \\dfrac{(4\\pi)^3}{k^2}\\left\\vert \\sum_{lm}\\sum_{l'm'} i^{-l-1} (-1)^{l}\\hat{\\beta}_s\\cdot \\bb{C}_{lm}(\\theta_i,\\phi_i)\\left(T^{MM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{MN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot \\hat{\\beta}_i  \\right. \\nonumber \\\\\n%\\ & \\ &  \\left. + i^{-l}   (-1)^{l+1} \\hat{\\beta}_s\\cdot\\bb{B}_{lm}(\\theta_i,\\phi_i)\\left(T^{NM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{NN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot   \\hat{\\beta}_i   \\right\\vert^2 }\n\n\n\n\n\n\n\\clearpage\n\\newpage\n\\subsection{Backscatter Radar Cross Section of a Sphere}\n\n%\\noindent where $\\bb{E}_s$ is the far-field scattered field, $\\bb{E}_i $ are plane waves incident on the target, and $\\hat{p}$ and $\\hat{q}$ are polarization unit vectors. \n\nFor a sphere, the radar backscatter is independent of the incident direction, and \\eqref{scattmatrix1} can be simplified analytically.  Let the incident direction be in the $+\\hat{z}$ direction, $(\\theta_i,\\phi_i) = (0,0)$, and the scattered direction be $-\\hat{z}$ with $(\\theta_i,\\phi_i) = (\\pi,0)$.  Let the incident and scattered electric field have both $\\hat{x}$ and $\\hat{y}$ components   \n\\eq{\\bb{E}_i = E_x \\hat{x} + E_y \\hat{y}}\n\n%\\ea{\\bb{E}_s(\\br) &=& 4\\pi\\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\sum_{l'm'} \\nonumber \\\\\n%\\ & \\ & i^{-l-1} \\bb{C}_{lm}(\\pi,0)\\left(T^{MM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(0,0)  + T^{MN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(0,0)  \\right)\\cdot  \\bb{E}_i   + \\nonumber \\\\\n%\\ & \\ &  i^{-l}   \\bb{B}_{lm}(\\pi,0)\\left(T^{NM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(0,0)  + T^{NN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(0,0)  \\right)\\cdot  \\bb{E}_i  \\nonumber \\\\ }\n\n\nFor a PEC or dielectric sphere, the T-matrix is diagonal with zero cross terms so that \\eqref{scattmatrix} reduces to one sum as \n\\ea{\\bb{E}_s(\\pi,0) &=& -4\\pi i\\dfrac{e^{ikr}}{kr}   \\sum_{lm}\\bb{C}_{lm}(\\pi,0)T^{MM}_{lm} \\bb{C}^*_{lm}(0,0) \\cdot  \\bb{E}_i   -  \\bb{B}_{lm}(\\pi,0)T^{NN}_{lm}  \\bb{B}^*_{lm}(0,0) \\cdot  \\bb{E}_i  }\n\n%\\ea{\\bb{E}_s(\\br) &=& 4\\pi\\dfrac{e^{ikr}}{kr}  \\sum_{lm}\\nonumber \\\\\n%\\ & \\ & i^{-l-1} \\bb{C}_{lm}(\\pi,0)\\left(T^{MM}_{lm} i^{l}  \\bb{C}^*_{lm}(0,0) \\right)\\cdot  \\bb{E}_i   + \\nonumber \\\\\n%\\ & \\ &  i^{-l}   \\bb{B}_{lm}(\\pi,0)\\left( T^{NN}_{lm} i^{l+1}  \\bb{B}^*_{lm}(0,0)  \\right)\\cdot  \\bb{E}_i  \\nonumber \\\\ }\nUsing \\eqref{clmzplus}, \\eqref{blmzplus}, \\eqref{clmzminus}, \\eqref{blmzminus}, this reduces to\n\\ea{\\bb{E}_s(\\pi,0) &=& \\dfrac{-i}{2} \\dfrac{e^{ikr}}{kr}  \\sum_{l} (-1)^l (2l+1) \\left[ \\hat{x} (T^{MM}_{l} - T^{NN}_{l}) E_x - \\hat{y} (T^{MM}_{l} - T^{NN}_{l}) E_y\\right]\\label{esbacksphere} }\n\nThis shows that the scattered field in the backscatter direction of a sphere is polarization independent with no cross-pol. Substituting \\eqref{esbacksphere} into \\eqref{rcs1} and choosing either polarization, the polarization amplitude will cancel. The backscatter radar cross section of a sphere where only the diagonal elements of the T-matrix are non-zero\n\\eq{\\sigma = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} (-1)^l (2l+1) \\left(T^{MM}_{l} - T^{NN}_{l}\\right) \\right\\vert^2 \\label{rcssphere}}\n\n\\subsection{Backscatter RCS of a PEC Sphere}\n\nSubstituting the T-matrix for a PEC sphere into \\eqref{rcssphere}, the backscatter RCS of a PEC sphere is\n\\eq{\\sigma_{PEC} = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} (-1)^l (2l+1) \\left(\\dfrac{j_l(ka)}{h_l^{(1)}(ka)}  - \\dfrac{[k a j_l(ka)]'}{[k a h_l^{(1)}(ka)]'}\\right) \\right\\vert^2 \\label{sigmapec}}\n\n\n%\n%Using the Wronskian\n%\\eq{j_l(x) {h'}_l^{(1)}(x) - h_l^{(1)}(x) j_l'(x) = \\dfrac{i}{x^2} }\n%\n%\\eq{\\sigma_{PEC} = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} \\dfrac{(-1)^l (2l+1) }{ ka h_l^{(1)}(ka) [k a h_l^{(1)}(ka)]'} \\right\\vert^2 }\n%\n%Next, we write this in terms of logarithmic derivative of the Bessel functions.  Let $\\chi$ be the Riccati-Bessel function or Riccati-Hankel function.  The logarithmic derivative is \n%\n%\\eq{\\phi_n(x) = x j_n(x)}\n%\\eq{\\zeta_n(x) = xh_n^{(1)}(x)}\n%\n%\\eq{A_n = \\dfrac{1}{x j_n(x)}\\dd{x j_n(x)}{x}  }\n%\\eq{B_n = \\dfrac{1}{xh_n^{(1)}(x)}\\dd{xh_n^{(1)}(x)}{x}}\n%\n%\\eq{\\chi_l(x) = xz_l(x)}\n%\\eq{C_l = \\dfrac{1}{\\chi_l}\\dd{\\chi_l}{x} }\n%\n%These have the single term recurrence \n%\n%\\eq{\\rho_l = \\dfrac{\\chi_l}{\\chi_{l+1}}}\n%\\eq{\\dfrac{1}{\\rho_l} = \\dfrac{2l+1}{x} - \\rho_{l-1}}\n%\\eq{C_l = -\\dfrac{l}{x} + \\dfrac{1}{\\dfrac{l}{x} - C_{l-1}}}\n%\n%Using the fact that\n%\\ea{j_0(x) &=& \\dfrac{\\sin x}{x} \\\\\n%j_1(x) &=& -\\dfrac{\\cos x}{x} + \\dfrac{\\sin x}{x^2} \\\\\n%h_0^{(1)}(x) &=& \\dfrac{e^{i x}}{ix} \\\\\n%h_1^{(1)}(x) &=& -\\left(1 + \\dfrac{i}{x}\\right) \\dfrac{e^{i x}}{x} }\n%\n%\\eq{\\psi_0 = \\dfrac{e^{ix}}{i}}\n%\\eq{\\rho_0 = \\dfrac{x}{1 - ix}}\n%\\eq{C_0 = 1 + i - \\dfrac{1}{x}}\n%\n%\n%\n%\n%\\eq{\\sigma_{PEC} = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} \\dfrac{(-1)^l (2l+1) }{\\chi_l^2 C_l  } \\right\\vert^2 }\n\n\n%\n%\n%\\eq{z'_l(x) = z_{l-1}(x) - \\dfrac{l}{x}z_{l}(x) }\n%this becomes\n%\\eq{\\sigma_{PEC} = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} \\dfrac{(-1)^l (2l+1) }{ x h_l^{(1)}(x)\\left((1-l)h_l^{(1)}(x) + x h_{l-1}^{(1)}(x)\\right) } \\right\\vert^2 }\n%\n%$x = ka$.  The Hankel function can be computed recursively as \n%\\eq{z_l(x) = \\dfrac{2(l-1)}{x} z_{l-1}(x) - z_{l-2}(x)}\n%\n%with initial conditions\n%\\ea{h_0^{(1)}(x) &=& \\dfrac{e^{i x}}{ix} \\\\\n%h_1^{(1)}(x) &=& -\\left(1 + \\dfrac{i}{x}\\right) \\dfrac{e^{i x}}{x} }\n\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=3.5in]{Tmatrix/Figures/brcspecsphere} \n   \\caption{RCS of PEC sphere, normalized by cross-section area.  The maximum occurs at $ka \\approx 1.03$, with a value of about 3.65 (linear).}\n\\end{figure}\n\n\nThe routine \\texttt{brcs\\_pec\\_sphere} is a workable routine to compute \\eqref{sigmapec}. The sum is truncated when incremental change is less than machine precision. The standard and better way to compute this is to use logarithmic derivatives of the Bessel functions, but that is a separate topic.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/brcs_pec_sphere.m}\n}\n\n\\subsection{Backscatter RCS of a Dielectric Sphere}\n\nUsing the T-matirx for the dielectric sphere in \\eqref{rcssphere}, the backscatter RCS of a non-magnetic dielectric sphere is \n\\eq{\\sigma = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} (-1)^l (2l+1) \\left(\\dfrac{j_2 j_1'  -  j_1j_2'}{ h_1 j_2' -  j_2 h_1'} - \\dfrac{ x_2^2 j_2 j_1' -  x_1^2 j_1 j_2' }{ x_1^2 h_1 j_2' - x_2^2  j_2 h_1' } \\right) \\right\\vert^2 \\label{sigmaer}}\n\nwhich uses the shorthand: \n\\ea{x_1 &=& k_1 a \\\\\nx_2 &=& k_2 a \\\\\nj_1 &=& j_l(k_1a) \\\\\nj_1' &=& [k_1 a j_l(k_1a)]' \\\\\nj_2 &=& j_l(k_2a) \\\\\nj_2' &=& [k_2 a j_l(k_2a)]' \\\\\nh_1 &=& h_l^{(1)}(k_1a) \\\\\nh_1' &=& [k_1 a h_l^{(1)}(k_1a)]' \n}\n\n\\noindent where $k_1$ is the wavenumber outside the sphere, and $k_2$ is wavenumber inside the sphere.  Making use of the Wronskian $j_l(x) {h'}_l^{(1)}(x) - h_l^{(1)}(x) j_l'(x) = i/x^2$, it can be shown that $h_1' j_1 - h_1 j_1'  = i/x_1$.  Then the backscatter can also be written \n\\eq{\\sigma = \\dfrac{\\pi}{k^2} \\left\\vert \\sum_{l=1}^{\\infty} (-1)^l (2l+1) \\left(\\dfrac{j_2 j_2' ( x_2^2 - x_1^2) }{x_1 \\left(h_1 j_2' - j_2 h_1' \\right)\\left(x_1^2 h_1 j_2' - x_2^2  j_2 h_1' \\right)}\\right) \\right\\vert^2 }\n\n\\clearpage\n\\begin{figure}[h] \n   \\centering\n   \\subfigure{\\includegraphics[width=3.2in]{Tmatrix/Figures/brcsdielectricsphere}  \\label{brcsdiesph} } \n   \\subfigure{\\includegraphics[width=3.1in]{Tmatrix/Figures/brcsdielectricspheregrid}   \\label{brcsdiesphall}}\n   \\caption{Backscatter RCS of dielectric sphere, normalized by cross-section area, in free-space. Left: $\\epsilon_r = 2.5$. Right: $\\epsilon_r =$1 to 5, and $a/\\lambda_o$ = 0 to 2.}\n \\end{figure}\n \n \n%\\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3.5in]{Tmatrix/Figures/brcsdielectricsphere} \n%   \\caption{Backscatter RCS of dielectric sphere, normalized by cross-section area, in free-space.  $\\epsilon_r = 2.5$.}\n%   \\label{brcsdiesph}\n%\\end{figure}\n%\n%\\begin{figure}[h] \n%   \\centering\n%   \\includegraphics[width=3.5in]{Tmatrix/Figures/brcsdielectricspheregrid} \n%   \\caption{Backscatter RCS of lossless dielectric sphere, normalized by cross-section area, in free-space.}\n%      \\label{brcsdiesphall}\n%\\end{figure}\n\nThe routine \\texttt{brcs\\_dielectric\\_sphere} is a workable routine for the computation of \\eqref{sigmaer}.  Assuming a background of vacuum, Figure \\ref{brcsdiesph} shows the backscatter RCS for a sphere with $\\epsilon_r = 2.5$ as a function of sphere radius. Figure \\ref{brcsdiesphall} shows the same as a function of $k_o a$ and $\\epsilon_r$. \n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/brcs_dielectric_sphere.m}\n}\n\n\\clearpage\n\\section{Scattering Cross Section from T-matrix}\n\nThe scattering cross section is equal to the scattered power integrated over the sphere for a unit amplitude incident electric field and specific incident direction. From \\cite{tsang1985theory}, the scattering cross section is written in terms of the S-matrix as \n\\eq{\\sigma_{s\\beta}(\\hat{k}_i) = \\int_S \\left( \\vert S_{p \\beta}(\\hat{k}_s,\\hat{k}_i) \\vert^2 + \\vert S_{q \\beta}(\\hat{k}_s,\\hat{k}_i) \\vert^2 \\right) d\\Omega_s  }\n\n\\noindent where $\\beta$ is the incident polarization and $p$ and $q$ are any two orthogonal scattered polarizations. Taking the magnitude squared of \\eqref{scattmatrix1} without the terms $E_o e^{ikr}/r $, integrating this over the scattered field directions, and applying orthonormality of the vector spherical harmonics, one gets, similar to \\cite{tsang1985theory},\n\n\\ea{\\sigma_{s\\beta}(\\hat{k}_i) &=& \\dfrac{16\\pi^2}{k^2} \\sum_{lm} \\left\\{ \\left\\vert \\sum_{l'm'} \\left(T^{MM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{MN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\hat{\\beta} \\right\\vert^2 \\right. \\nonumber \\\\\n\\ & \\ &  +\\left. \\left\\vert \\sum_{l'm'} \\left(T^{NM}_{lm,l'm'} i^{l'}  \\bb{C}^*_{l'm'}(\\theta_i,\\phi_i)  + T^{NN}_{lm,l'm'} i^{l'+1}  \\bb{B}^*_{l'm'}(\\theta_i,\\phi_i)  \\right)\\cdot  \\hat{\\beta} \\right\\vert^2 \\right\\}  \\label{tmatrixscatcrosssection} }\n\nThe routine \\texttt{compute\\char`_scs\\char`_from\\char`_tmatrix} computes the scattering cross section of an object from its T-matrix. It takes as input the four $N \\times N$ bock T-matrices where $N = L^2 + 2L$, for harmonics up to maximum degree $L$ all $m$.  The incident angles can be any size. The incident polarization is defined relative to the spherical unit vectors $\\hat{\\beta} = \\cos \\beta \\hat{\\theta} + \\sin\\beta \\hat{\\phi}$.  Recall $\\hat{v} =\\hat{\\theta}$ and $\\hat{h} =\\hat{\\phi}$. Values $\\beta = [0,\\pi/2]$ correspond to $v, h$ respectively. The array of $\\beta$ can be any size. The scattering cross section is returned on an array with dimensions that are the concatenation of the sizes of the incident direction array and polarization angle array.  \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/compute_scs_from_tmatrix.m}\n}\n\n% From \\cite{tsang2000scattering}, if the scattered electric field is written in terms of the far field pattern as \n%\\eq{\\bb{E}_s = \\left( \\hat{v}_s E_{vs\n%} + \\hat{h}_s E_{hs} \\right) \\dfrac{e^{ikr}}{r}}\n%with \n%\\eq{\\twobyone{E_{vs}}{E_{hs}} = \\twobytwo{S_{vv}}{S_{vh}}{S_{hv}}{S_{hh}} \\twobyone{E_{vi}}{E_{hi}}}\n%\n%then the scattering cross section for polarization $p = v,h$ and fixed incident direction is \n%\\eq{\\sigma_{sp}(\\hat{k}_i) = \\int_S \\left( \\vert S_{vp}(\\hat{k}_s,\\hat{k}_i) \\vert^2 + \\vert S_{hp}(\\hat{k}_s,\\hat{k}_i) \\vert^2 \\right) d\\Omega_s  }\n\n%\n%\\eq{\\bb{E}_s = \\hat{e}_s E_o f(\\hat{k}_s,\\hat{k}_i) \\dfrac{e^{ikr}}{r}}\n%\n%then the scattering cross section is \n%\\eq{\\sigma_s = \\int \\left\\vert f(\\hat{k}_s,\\hat{k}_i) \\right\\vert^2 d\\Omega_s} \n%\n\n\n\\subsection{Scattering Cross Section of a Sphere}\n\nFor the scattering cross section of a sphere, from symmetry, we only need to consider one incident polarization and an arbitrary incident direction. Assume that the incident plane wave propagates in the $z$ direction:\n\\eq{\\bb{E}_i = E_o \\hat{x}  \\label{Eincxz}}\n\nThe T-matrix of the sphere is diagonal with zero cross terms, which means \\eqref{tmatrixscatcrosssection} simplifies to\n\\ea{\\sigma_{s} &=& \\dfrac{16\\pi^2}{k^2} \\sum_{lm} \\left\\{ \\left\\vert  T^{MM}_{lmlm}   \\bb{C}^*_{lm}(0,0) \\cdot  \\hat{x} \\right\\vert^2 + \\left\\vert T^{NN}_{lmlm}  \\bb{B}^*_{lm}(0,0)  \\cdot  \\hat{x} \\right\\vert^2 \\right\\}  }\n\nFrom \\eqref{clmzplus}, \\eqref{blmzplus}, and \\eqref{Eincxz}, the vector spherical harmonics for $z$ propagation wave have only $m=\\pm1$ harmonics and the dot product with $\\hat{x}$ is\n\\eq{\\bb{C}^*_{l,\\pm 1}(0,0) \\cdot  \\hat{x}=  \\dfrac{i}{2} \\sqrt{\\dfrac{2l+1}{4\\pi}} }\n\\eq{\\bb{B}^*_{l,\\pm 1}(0,0) \\cdot  \\hat{x} = \\pm  \\dfrac{1}{2} \\sqrt{\\dfrac{2l+1}{4\\pi}} }\n\nSubstituting these we get \n%\\ea{\\sigma_{sx}(\\hat{k}_i) &=& \\dfrac{16\\pi^2}{k^2} \\sum_{lm} \\left\\{ \\left\\vert  T^{MM}_{lmlm}   \\bb{C}^*_{lm}(0,0) \\cdot  \\hat{x} \\right\\vert^2 + \\left\\vert T^{NN}_{lmlm}  \\bb{B}^*_{lm}(0,0)  \\cdot  \\hat{x} \\right\\vert^2 \\right\\}  }\n\n% scattered field is \n%\\ea{\\bb{E}_s(\\hat{k}_s) &=& 4\\pi\\dfrac{e^{ikr}}{kr} i  \\sum_{lm}-\\bb{C}_{lm}(\\theta_s,\\phi_s)T^{MM}_{lm} \\bb{C}^*_{lm}(0,0) \\cdot  \\bb{E}_i   +  \\bb{B}_{lm}(\\theta_s,\\phi_s)T^{NN}_{lm}  \\bb{B}^*_{lm}(0,0) \\cdot  \\bb{E}_i  \\nonumber \\\\ }\n%\n%Using \\eqref{clmzplus}, \\eqref{blmzplus}, and \\eqref{Eincxz}\n%\n%\\eq{\\bb{C}^*_{l,\\pm 1}(0,0) \\cdot  \\bb{E}_i = E_o \\dfrac{i}{2} \\sqrt{\\dfrac{2(l+1)}{4\\pi}} }\n%\\eq{\\bb{B}^*_{l,\\pm 1}(0,0) \\cdot  \\bb{E}_i = \\pm E_o \\dfrac{1}{2} \\sqrt{\\dfrac{2(l+1)}{4\\pi}} }\n%\n%\\ea{\\bb{E}_s(\\hat{k}_s) &=& E_o 4\\pi\\dfrac{e^{ikr}}{2kr} \\sum_{l,m=\\pm1} \\sqrt{\\dfrac{2(l+1)}{4\\pi}} \\left( \\bb{C}_{lm}(\\theta_s,\\phi_s)T^{MM}_{lm}    \\pm i \\bb{B}_{lm}(\\theta_s,\\phi_s)T^{NN}_{lm}  \\right) \\nonumber \\\\ }\n%%\\ea{\\bb{E}_s(\\br) &=& E_o 4\\pi\\dfrac{e^{ikr}}{2kr} \\sum_{l} \\sqrt{\\dfrac{2(l+1)}{4\\pi}} \\left( (\\bb{C}_{l,1}(\\theta,\\phi) + \\bb{C}_{l,-1}(\\theta,\\phi)) T^{MM}_{l}    + i \\left( \\bb{B}_{l,1}(\\theta,\\phi) + \\bb{B}_{l,-1}(\\theta,\\phi)\\right) T^{NN}_{l}  \\right) \\nonumber \\\\ }\n%\n%Dropping $E_o$ and $e^{ikr}/r$, integrating the magnitude squared of the scattered field over the sphere, \n%\n%\\ea{\\sigma_{sca} &=& \\left(\\dfrac{4\\pi}{2k}\\right)^2  \\int \\left\\vert \\sum_{l} \\sqrt{\\dfrac{2(l+1)}{4\\pi}} \\left( (\\bb{C}_{l,1}(\\theta_s,\\phi_s) + \\bb{C}_{l,-1}(\\theta_s,\\phi_s)) T^{MM}_{l}   \\right.\\right. \\nonumber \\\\\n%\\ & \\ & \\left.\\left. + i \\left( \\bb{B}_{l,1}(\\theta_s,\\phi_s) + \\bb{B}_{l,-1}(\\theta_s,\\phi_s)\\right) T^{NN}_{l}  \\right) \\right\\vert^2 d\\Omega_s }\n%\n%Expanding the magnitude squared as two conjugate independent sums, then after applying orthogonality of the vector spherical harmonics each term becomes independent.  \n\n\\eq{\\sigma_{s} = \\dfrac{2\\pi}{k^2}  \\sum_{l=1}^{\\infty}(2l+1) \\left(\\left\\vert T^{MM}_{l} \\right\\vert^2 + \\left\\vert T^{NN}_{l} \\right\\vert^2  \\right) \\label{spheresca}  }\n\nA factor of two comes from summing the $m=\\pm1$ terms. \n\n\\subsection{Scattering Cross Section of a PEC Sphere}\n\nThe scattering cross section of a PEC sphere is given by substituting the T-matrix for a PEC sphere into \\eqref{spheresca}\n\\eq{\\sigma_{s,PEC} = \\dfrac{2\\pi}{k^2}  \\sum_{l=1}^{\\infty}(2l+1) \\left(\\left\\vert \\dfrac{j_l(ka)}{h_l^{(1)}(ka)}  \\right\\vert^2 + \\left\\vert \\dfrac{[k a j_l(ka)]'}{[k a h_l^{(1)}(ka)]'} \\right\\vert^2  \\right) \\label{scspecsphere}}\n\n\\noindent where the sphere has radius $a$ in a background with wavenumber $k$.\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{Tmatrix/Figures/scspecsphere} \n   \\caption{Scattering cross section of a PEC sphere, normalized by cross-section area, in free-space.}\n   \\label{scspecsph}\n\\end{figure}\n\n\n\n\nThe routine \\texttt{scs\\char`_pec\\char`_sphere} is a workable routine to compute \\eqref{scspecsphere}. The sum is truncated when incremental change is less than machine precision. \n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/scs_pec_sphere.m}\n}\n\\clearpage\n\\subsection{Scattering Cross Section of a Dielectric Sphere}\n\nThe scattering cross section of a dielectric sphere is given by substituting the T-matrix for a dielectric sphere into \\eqref{spheresca}. This gives identical results to \\cite{tsang2000scattering} Figure 1.6.3 and also matches outputs from Ulaby and Long 2014 Code Module 8.12.\n\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=3.5in]{Tmatrix/Figures/scsdielectricspheregrid} \n   \\caption{Scattering cross section of lossless dielectric sphere, normalized by cross-section area, in free-space.}\n      \\label{scsdiesphall}\n\\end{figure}\n\n\nThe routine \\texttt{scs\\char`_dielectric\\char`_sphere} computes the scattering cross section of a dielectric sphere given the inner and outer wavenumbers $k_1$, $k_2$, and sphere radius $a$.  \n\n{\\scriptsize\n\\VerbatimInput{\\code/Tmatrix/scs_dielectric_sphere.m}\n}\n\n%\n%\\subsection{Rayleigh Limit}\n%\n%Classical Rayleigh scattering comes by taking the small argument limit of \\eqref{spheresca}.  Keeping only the $l=1$ term, assuming nonmagnetic.  Using the facts that \n%\n%\\ea{j_n(x) & \\approx & \\dfrac{x^n}{1 \\cdot 3 \\cdot 5 \\cdots(2n+1)} \\\\\n%h_n^{(1)}(x) & \\approx &  \\dfrac{x^n}{1 \\cdot 3 \\cdot 5 \\cdots(2n+1)} -i \\dfrac{1 \\cdot 3 \\cdot 5 \\cdots(2n-1)}{x^{n+1}} }\n%\n%Then it can be shown that \n%\\ea{ \\lim_{x \\rightarrow 0} j_1(x) & \\approx & \\dfrac{x}{3}\\\\\n% \\lim_{x \\rightarrow 0} (x j_1(x))' & \\approx &  \\dfrac{2x}{3} \\\\\n% \\lim_{x \\rightarrow 0} h_1^{(1)}(x) &  \\approx & \\dfrac{x}{3} -i x^{-2}  \\\\\n% \\lim_{x \\rightarrow 0} (x h_1^{(1)}(x) )' & \\approx &  i x^{-2} + \\dfrac{2x}{3} }\n%\n%Using \n%\\ea{x_1 &=& k_1 a \\\\\n%x_2 &=& k_2 a}\n%\n%and substituting the limits\n%\\ea{T_{lmlm}^{MM} &=& \\dfrac{ \\dfrac{x_2}{3} \\dfrac{2x_1}{3} -   \\dfrac{x_1}{3}\\dfrac{2x_2}{3}}{  \\left(\\dfrac{x_1}{3} -i x_1^{-2}\\right) \\dfrac{2x_2}{3} -   \\dfrac{x_2}{3} \\left( i x_1^{-2} + \\dfrac{2x_1}{3} \\right) } \\\\\n%T_{lmlm}^{NN} &=& \\dfrac{x_2^2 \\dfrac{x_2}{3} \\dfrac{2x_1}{3} -   x_1^2\\dfrac{x_1}{3} \\dfrac{2x_2}{3} }{  x_1^2 \\left(\\dfrac{x_1}{3} -i x_1^{-2} \\right) \\dfrac{2x_2}{3} -  x_2^2  \\dfrac{x_2}{3}\\left( i x_1^{-2} + \\dfrac{2x_1}{3} \\right) } } \n%\n%\n%\\ea{T_{lmlm}^{MM} &=& \\dfrac{  j_l(x_2) [x_1 j_l(x_1)]' -   j_l(x_1)[x_2 j_l(x_2)]'}{  h_l^{(1)}(x_1) [x_2 j_l(x_2)]' -   j_l(x_2) [x_1 h_l^{(1)}(x_1)]'}  \\\\\n%T_{lmlm}^{NN} &=& \\dfrac{x_2^2 j_l(x_2) [x_1 j_l(x_1)]' -   x_1^2j_l(x_1) [x_2 j_l(x_2)]' }{  x_1^2 h_l^{(1)}(x_1) [x_2j_l(x_2)]' -  x_2^2  j_l(x_2)[x_1 h_l^{(1)}(x_1)]'} } \n%\n%\n%\\subsection{Scattering Efficiency of a Dielectric Sphere}\n%\n%In general, the scattering efficiency is defined as the scattering cross section divided by the geometric cross section. For a sphere of radius $a$ this is\n%\n%\\eq{Q_{sca} = \\dfrac{\\sigma_{sca}}{\\pi a^2} }\n%\n%This is a measure of the amount of power scattered compared to the power intercepted. For a sphere in the Mei regime, this value is around 2 and can be as high as 4.  This is means that the scattering cross section for large spheres near resonances is greater than the geometric cross section.  \n%\n%This is given by the simple routine \\texttt{scatEfficiencyDieletricSphere}.\n%\n%{\\footnotesize\n%\\VerbatimInput{\\code/Tmatrix/scatEfficiencyDieletricSphere.m}\n%}\n\n\\clearpage\n\n\\subsection{Polarization and Orientation Averaged Scattering Cross Section using T-matrix}\n\nWe can compute the polarization and orientation averaged scattering cross section directly from the elements of the T-matrix using \\eqref{polorientavescs} and \\eqref{tmatrixscatcrosssection}:\n\\ea{\\left< \\sigma \\right> &=&  \\dfrac{1}{2\\pi} \\int_0^{2\\pi}\\left(  \\dfrac{1}{4\\pi} \\int \\sigma_{s\\beta}(\\hat{k}_i) d\\Omega_i \\right) d\\beta }\n\nLet the incident polarization vector be $\\hat{\\beta} = \\cos \\beta \\hat{\\theta} + \\sin\\beta \\hat{\\phi}$, then, for example, the first magnitude squared term in \\eqref{tmatrixscatcrosssection} looks like\n\\ea{I_{lm}(\\theta_i,\\phi_i,\\beta) &=& \\left\\vert \\sum_{l'm'}  T^{MM}_{lm,l'm'} i^{l'}  \\left(C^*_{\\theta,l'm'}(\\theta_i,\\phi_i) \\cos\\beta + C^*_{\\phi,l'm'}(\\theta_i,\\phi_i) \\sin\\beta \\right) \\right. \\nonumber \\\\\n\\ & \\  & +\\left. T^{MN}_{lm,l'm'} i^{l'+1} \\left(B^*_{\\theta,l'm'}(\\theta_i,\\phi_i) \\cos\\beta + B^*_{\\phi,l'm'}(\\theta_i,\\phi_i) \\sin\\beta \\right)  \\right\\vert^2 }\n\nAfter expanding the magnitude squared with a second sum, it is clear that cross terms having $\\cos\\beta\\sin\\beta$ will not survive the $\\beta$ integral and can be ignored. From orthogonality of the vector spherical harmonics the cross terms of the vector spherical harmonics will not survive the integration over incident directions. The only terms that matter are of the form $C^*_{\\theta,l'm'}(\\theta_i,\\phi_i)C_{\\theta,l''m''}(\\theta_i,\\phi_i) \\cos^2\\beta + C^*_{\\phi,l'm'}(\\theta_i,\\phi_i)C_{\\phi,l''m''}(\\theta_i,\\phi_i) \\sin^2\\beta $. The trick is to first compute the $\\beta$ integral, so that $\\cos^2\\beta$ and $\\sin^2\\beta$ become $\\pi$ which is factored out, after which $1/2$ remains from the $\\beta$ integral normalization. The dot products of the vector spherical harmonics then integrate to 1 and collapse one sum. Only the $1/4\\pi$ remains from the normalization of the integral over incident directions. The end result is a double sum over the magnitude squared of all elements of the T-matrix:\n\\eq{\\left< \\sigma \\right> =   \\dfrac{2\\pi}{k^2} \\sum_{lm}\\sum_{l'm'} \\left\\vert T^{MM}_{lm,l'm'} \\right\\vert^2 + \\left\\vert T^{MN}_{lm,l'm'} \\right\\vert^2  + \\left\\vert T^{NM}_{lm,l'm'} \\right\\vert^2  + \\left\\vert T^{NN}_{lm,l'm'} \\right\\vert^2  \\label{tmatrixpolorientave}}\n\nEquation \\eqref{tmatrixpolorientave} is basically the square of the Frobenius norm of the entire T-matrix, scaled by a constant that depends on wavelength. This expression is amazingly elegant and comes from the fact that each T-matrix element contains scattering information for all spherical directions and polarizations at once. This can be checked against the scattering cross section of the sphere, which is independent of incident polarization and direction, and therefore $\\left< \\sigma \\right> = \\sigma_s$: the T-matrix elements of the sphere are diagonal (eliminates one sum) with no cross terms and depends only on $l$, so that each sum over $m$ contributes $2l+1$ terms, which gives \\eqref{spheresca}.  \n\nThe routine \\texttt{compute\\char`_avescs\\char`_from\\char`_tmatrix}  computes the polarization and orientation average scattering cross section from a T-matrix. It takes as input the four $N \\times N$ block T-matrices where $N = L^2 + 2L$, for harmonics up to maximum degree $L$ all $\\pm m$ and returns \\eqref{tmatrixpolorientave}. This is easy enough to compute.\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Tmatrix/compute_avescs_from_tmatrix.m}\n}\n\n\n", "meta": {"hexsha": "b45eea8841de8ce73fe446001a0fb40749c70082", "size": 82890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Tmatrix/Tmatrix.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/Tmatrix/Tmatrix.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/Tmatrix/Tmatrix.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": 87.7142857143, "max_line_length": 1433, "alphanum_fraction": 0.6754614549, "num_tokens": 31312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6077520407056878}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\n\\setcounter{chapter}{5}\n\n\\chapter{Stacks I}\n\nWe recall that for a category $C$ and a subset $W \\subset C_1$ of morphisms in $C$, a localization of $C$ along $W$ is a category $W^{-1}C$ with a functor $l: C \\to W^{-1}C$ such that for all other categories $D$, the functor\n\n\\[\nl^*: \\underline{Hom}(W^{-1}C, D),  \\underline{Hom}(C, D)\n\\]\n\nis full and faithful, and the essential image consists of functors $C \\to D$ sending $W$ to isomorphisms in $D$. If a localization exists it's unique up to isomorphism.\n\n\n\\section{Homotopy theory of groupoids}\n\nWe consider the case where $C = Gpd$, the category of groupoids (i.e. objects are groupoids and morphisms are functors of groupoids). We take $W$ the subset of equivalence of groupoids (i.e. the functors that are equivalences of category) and we we consider the category $W^{-1}Gpd$.\n\n\\begin{defn}\n    The homotopy category of groupoids is the localization $W^{-1}Gpd$. We also write $Ho(Gpd)$. The set of morphisms in $Ho(Gpd)$ between objects $A$ and $B$ is denoted $[A, B]$.\n\\end{defn}\n\nWe now denote [Gpd] the category where objects are groupoids, and for groupoids $A$ and $B$, the sect of morphisms between $A$ and $B$ in $[Gpd[$ is by definition the set of isomorphism classes of functors from $A$ to $B$. There's a natural projection $p: Gpd \\to [Gpd]$, which is the identity on objects and the canonical projection on morphism sets. Exercise: write down compositions in $[Gpd]$\n\n\n\\begin{thm}\n    The natural project\n    \\[\n        p: Gpd \\to [Gpd]\n    \\]\n    is a localization of $Gpd$ along $W$. It follows that $p$ induces a natural equivalence\n\n    \\[\n        Ho(Gpd) \\simeq [Gpd]\n    \\]\n\n\\end{thm}\n\n\\begin{proof}\n...\n\\end{proof}\n\n\\begin{cor}\n    The natural functor\n    \\[\n        j: Set \\to Gpd \\to Ho(Gpd)\n    \\]\n    sending a set to the corresponding discrete groupoid, is full and faithful, and has a left adjoint:\n    \\[\n        \\pi_0: Ho(Gpd) \\to Set\n    \\]\n\\end{cor}\n\n\\begin{proof}\n...\n\\end{proof}\n\nExercise: Let $G$ and $H$ be groups. We write $BG$ (resp. $BH$) the groupoids with a single object and $G$ (and $H$) group of automorphisms of the object. Describe the set $[BG, BH]$ of morphisms in the category Ho(Gpd).\n\n\\section{Homotopy theory of diagrams of groupoids}\n\nLet $I$ be a category, and consider $\\underline{Hom}(I, Gpd)$ the category of functors from $I$ to $Gpd$ (also called the category of $I$-diagrams in $Gpd$). Take $F, G: I \\to Gpd$ two $I$-diagrams. A morphism\n\\[\n    f: F \\to G\n\\]\nis a equivalence if on each object $i\\in I$, the induced morphism\n\n\\[\nf_i: F(i) \\to G(i)\n\\]\nis an equivalence of groupoids. This defines the class $W_I$ of weak equivalences in $\\underline{Hom}(I, Gpd)$.\n\\begin{defn}\n    The homotopy category of $I$-diagrams of groupoids is $W_I^{-1}\\underline{Hom}(I, Gpd)$. Also denoted $Ho(\\underline{Hom}(I, Gpd))$. The set of morphisms in $W_I^{-1}\\underline{Hom}(I, Gpd)$ from $F$ to $G$ is denoted $[F, G]$.\n\\end{defn}\n\nTo generalization of theorem 1.2. to the case of digrams of groupoids, we need to introduce the notion of weak morphisms between objects in $\\underline{Hom}(I, Gpd)$. For this, we denote, for $F \\in \\underline{Hom}(I, Gpd)$, and for morphisms $u: i \\to j$ in $I$, $u_*^F: F(i) \\to F(j)$ the functor induced by $u$. Note by definition, $(u^f \\circ v^f)_* = u_*^F \\circ v_*^f$ and $id_*^F = id$.\n\n\\begin{thm}\n    The natural functor\n    \\[\n        \\underline{Hom}(I, Gpd) \\to [\\underline{Hom}(I, Gpd)]\n    \\]\n    induces an equivalence\n    \\[\n        Ho(\\underline{Hom}(I, Gpd) \\simeq [\\underline{Hom}(I, Gpd)]\n    \\]\n\n\\end{thm}\n\n\n\n\\section{Homotopy limits}\n\\section{Homotopy categories of prestacks and stacks}\n\n\\end{document}", "meta": {"hexsha": "245709d981ec85bdb98ae16975c2983c746c7d1a", "size": 3714, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/lecture5.tex", "max_stars_repo_name": "jakebian/OTIM-toen-mastercourse", "max_stars_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_stars_repo_licenses": ["MIT"], "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/lecture5.tex", "max_issues_repo_name": "jakebian/OTIM-toen-mastercourse", "max_issues_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_issues_repo_licenses": ["MIT"], "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/lecture5.tex", "max_forks_repo_name": "jakebian/OTIM-toen-mastercourse", "max_forks_repo_head_hexsha": "61d89ade9f4c08966d671277c13ace3614636ac2", "max_forks_repo_licenses": ["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.8979591837, "max_line_length": 396, "alphanum_fraction": 0.6677436726, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6077520364726994}}
{"text": "\\chapter{Fake rate of pulse detection}\n\\label{ch:rate}\n\nIn \\autoref{ch:snr} we measured the signal to noise ratio after filtering. The\npoint of using the SNR is expressing the signal height relative to the width of\nthe noise distribution, because the threshold required to reject noise with a\ngiven probability is proportional to that scale. So it is convenient to express\nthe threshold relative to the same scale. When setting a threshold on the\nfiltered amplitude, as done in data acquisition to reduce the noise rate, an\nSNR well above such a rescaled threshold will ensure that a good efficiency for\nsignal is retained.\n\nThis chapter deals with the calculation of the noise rate resulting from random\nfluctuations of the noise above the threshold.\n\nEven assuming the noise to be Gaussian, the probability that a random\nfluctuation gets above the threshold is not given simply by computing the\nsurvival function (i.e., the integral to $+\\infty$) of the Gaussian\ndistribution at the threshold.\n\nMore precisely, the probability that any given sample is above the threshold is\ngiven by such integral. What we need, however, is the \\emph{rate} of threshold\n\\emph{crossings}. The noise is not white, but even if it was, after applying\nthe filter, which combines linearly many input samples for each output sample,\nthe waveform is autocorrelated at least up to the length of the filter.\nIntuitively, if a smooth function crosses a threshold, it takes some time to go\ndown before it can cross the threshold again.\n\nWe will present the method used to compute the threshold crossing rate of the\nnoise, or fake rate, for a running average filter, and check that the\ncalculated rates are consistent with the results obtained in data.\n\nThe choice of the running average filter is due to the fact that this was the\nfilter implemented as part of the first prototype firmware for the FPGA of the\ndigitizer board. This constitutes the first processing stage in the DarkSide\nDAQ chain, and the reduction of the noise is a key goal of that processing.\nHowever, the method we present can be applied to any linear filter of choice,\nand allows to extrapolate efficiently to very low rates.\n\n\\section{Model}\n\nWe expect the noise to be Gaussian. Even if it were not prior to any\nprocessing, when filtering many samples are linearly combined, and the sum of\nrandom variables tends to have a Gaussian distribution independently of the\ninitial one. So Gaussianity is a reasonable assumption in our study.\n\n\\subsection{From the continuous case}\n\nWe have a discrete sequence of samples. The continuous equivalent is a Gaussian\nprocess. We can expect the discrete case to be equivalent to the continuous\ncase if the autocorrelation time is larger enough than the sampling step, which\nshould hold from the consideration above.\n\nAlso, even though the values are initially discrete too, after filtering the\npossible non integer values between two consecutive integers are at least the\nlength of the filter (think about an average). So we take the formula for the\ncontinuous case and adapt it.\n\nThe mean number of threshold upcrossings $r$ in the interval $(0,1)$ by a\nzero-mean stationary and appropriately smooth Gaussian process is given by\n\\cite[81]{rasmussen2006}\n%\n\\begin{align}\n    r &= \\sqrt{-\\frac{k''(0)}{2\\pi}} \\operatorname{gauss}(u;0,\\sigma) = \\\\\n      &= \\frac 1 {2\\pi} \\frac {\\sqrt{-k''(0)}} \\sigma\n         \\exp \\left( -\\frac12 (u/\\sigma)^2 \\right),\n\\end{align}\n%\nwhere $u$ is the threshold, $\\sigma$ the noise standard deviation (the RMS),\n$\\operatorname{gauss}(x;\\mu,\\sigma)$ a Gaussian probability density on $x$ with\nmean $\\mu$ and standard deviation $\\sigma$, and $k$ the autocovariance\nfunction, i.e., $k(x) = \\operatorname{Cov}[f(t), f(t+x)]$ for any $t$ (for\nexample, $k(0) = \\sigma^2$), where $f(t)$ is the continuous waveform.\n\nWe have to map the second derivative of the autocovariance function to a\ndiscrete equivalent. We first do a manipulation in the continuous realm. Since\nthe covariance operator is an integral, it commutes with derivation:\n%\n\\begin{align}\n    k''(x)\n    &= \\frac{\\partial^2}{\\partial x^2} \\operatorname{Cov}[f(t), f(t+x)] = \\\\\n    &= \\operatorname{Cov}[f(t), f''(t+x)],\n\\end{align}\n%\nthus $k''(0) = \\operatorname{Cov}[f(t), f''(t)]$. We estimate the second\nderivative with a finite difference:\n%\n\\begin{align}\n    f(t \\pm \\Delta t)\n    &= f(t) \\pm f'(t) \\Delta t + \\frac12 f''(t) \\Delta t^2 + O(\\Delta t^3)\n    \\rightarrow \\\\\n    \\rightarrow f''(t) \\Delta t^2 &=\n    f(t + \\Delta t) + f(t - \\Delta t) - 2 f(t) + O(\\Delta t^3).\n\\end{align}\n%\nChoosing $\\Delta t = 1/f_s$, where $f_s$ is the sampling frequency, and calling\n$y_i = f(t_0 + i\\Delta t)$ the samples, we have:\n\\begin{align}\n    k''(0) &\\mapsto f_s^2 k_2, \\\\\n    k_2 &\\equiv \\operatorname{Cov}[y_i, y_{i+1}+y_{i-1}-2y_i], \\label{eq:k2} \\\\\n    r &= f_s \\frac 1 {2\\pi} \\frac {\\sqrt{-k_2}} \\sigma\n         \\exp \\left( -\\frac12 (u/\\sigma)^2 \\right).\n    \\label{eq:rcont}\n\\end{align}\n%\nDiscretizing directly $k''(0)$ yields the same result.\n\nThe covariance in \\autoref{eq:k2} can be estimated with the sample\ncovariance on a filtered waveform array~$\\mathbf y$.\n\n\\subsection{Direct discrete derivation}\n\nSince the formula we derived is approximate, as a cross check we derive another\napproximate one following a different path.\n\nA threshold crossing happens when a sample is below the threshold and the next\none is above: $y_i \\leq u$, $y_{i+1} > u$. Fix $i=0$ and let $p(y_0,y_1)$ be the\njoint distribution of the two samples. The probability of crossing at any given\npoint then is\n%\n\\begin{equation}\n    P =\n    \\int_{-\\infty}^u \\mathrm d y_0\\,\n    \\int_u^\\infty \\mathrm d y_1\\,\n    p(y_0, y_1).\n    \\label{eq:crossingprob}\n\\end{equation}\n\nIn general we can not obtain the crossing rate just by multiplying $P$ by the\nsampling frequency because of correlations. However in practice we are\ninterested in low crossing rates, less than~\\SI{10}{cps}, to be compared to the\nfilter length $\\SI{2}{\\micro s} = 1/(\\SI{500}{kHz})$. If the typical time\nbetween crossings is much longer than the autocorrelation time, then we can\nignore correlations. Thus the crossing rate is $r = f_s P$.\n\nThe integrand in \\autoref{eq:crossingprob} is a bivariate Gaussian\ndistribution, which explicitly is\n%\n\\begin{equation}\n    p(y_0,y_1) =\n    \\frac 1 {2\\pi \\sqrt{\\sigma^4 - c^2}}\n    \\exp \\left(\n    \\frac 1 2\n    \\begin{pmatrix}\n        y_0 & y_1\n    \\end{pmatrix}\n    \\begin{pmatrix}\n        \\sigma^2 & c \\\\\n        c & \\sigma^2\n    \\end{pmatrix}^{-1}\n    \\begin{pmatrix}\n        y_0 \\\\ y_1\n    \\end{pmatrix}\n    \\right),\n\\end{equation}\n%\nwhere $c = \\operatorname{Cov}[y_0, y_1]$.\n\nWe do not know how to the integral analytically, so we break down the joint\ndistribution as $p(y_0,y_1) = p(y_1|y_0) p(y_0)$ and discretize the integral\nover~$y_0$:\n%\n\\begin{align}\n    p(y_0) &= \\operatorname{gauss}(y_0; 0, \\sigma), \\\\\n    p(y_1|y_0) &= \\frac {p(y_0, y_1)} {p(y_0)}\n    = \\operatorname{gauss} \\left(\n        y_1; \\frac c {\\sigma^2} y_0, \\sqrt{\\sigma^2 - \\frac {c^2} {\\sigma^2}}\n    \\right), \\\\\n    P &\\approx\n    \\sum_{k=0}^{N-1} \\Delta u\\, p(y_0(k,u,\\Delta u))\n    \\int_u^\\infty \\mathrm d y_1\\, p(y_1|y_0(k,u,\\Delta u)), \\label{eq:rdisc} \\\\\n    y_0(k,u,\\Delta u) &\\equiv u - k \\Delta u.\n\\end{align}\n\nThe integral on $y_1$ can be computed using the error function. $\\Delta u$\nshould be chosen small compared to $\\sigma$, while $N$ large relative to\n$\\sigma / \\Delta u$.\n\nIn \\autoref{fig:crossingprob} we compare formula~\\eqref{eq:rcont} (with $f_s\n= 1$) with $P$ and with the Gaussian survival function. To make the comparison\nwe have to use a $k_2$ that matches $c$:\n%\n\\begin{align}\n    k_2 &= \\operatorname{Cov}[y_i, y_{i+1}+y_{i-1}-2y_i] = \\notag \\\\\n    &= \\operatorname{Cov}[y_i,y_{i+1}]\n    + \\operatorname{Cov}[y_i,y_{i-1}]\n    - 2 \\operatorname{Cov}[y_i,y_i] = \\notag \\\\\n    &= 2 (c - \\sigma^2). \\label{eq:c2k2}\n\\end{align}\n%\nWe use $\\sigma=1$, $c = \\SI{99}\\%$, $\\Delta u = 1/100$, $N=500$ (we decreased\n$\\Delta u$ until convergence). We see that our derivation and the formula\nfor Gaussian processes agree very well, while differing visibly from the\nsurvival function. We will henceforth use the continuous formula for its\nsimplicity.\n\n\\begin{figure}\n    \n    \\widecenter{\\includempl{figcrossingprob}}\n\n    \\figcaption{crossingprob}{The threshold upcrossing rate expressed as\n    per-sample crossing probability (i.e., the rate if the sampling frequency\n    is~1) for an autocorrelated Gaussian waveform, estimated using three\n    formulae: 1) the probability for a single sample to be higher than the\n    threshold, 2) a formula for continuous processes (\\autoref{eq:rcont}),\n    3) an approximation of the discrete case (\\autoref{eq:rdisc}).}\n    \n\\end{figure}\n\n\\subsection{Dead time}\n\nOne part of the data acquisition system (DAQ) for which the study of threshold\ncrossings is particularly relevant are the digitizers. Due to limited logic\nresources in the installed FPGAs, a digitizer can not do complicated\nprocessing. Instead, a simple filter is applied, and the filtered waveform is\ncompared to the threshold. Whenever the threshold is crossed, a fixed slice of\nwaveform is sent to the front end processing (FEP) for further analysis\n(identify multiple signals, locate them precisely, use a better filter, etc.).\nA threshold crossing that happens too close in time to a previous crossing will\nbe ignored.\n\nThis means that we have a dead time $T$. We model it as a non-restartable dead\ntime, i.e., a crossing that happens within $T$ of a previous one is ignored\nonly if the latter has not been ignored itself.\n\nAssuming that the crossings are a Poisson process, the formula to correct a\nrate $R$ for the effect of the dead time is \\cite[120]{knoll2010}:\n%\n\\begin{equation}\n    R \\mapsto \\frac R {1 + RT}. \\label{eq:deadrate}\n\\end{equation}\n\nWe note that the crossings of a Gaussian process are not in general a Poisson\nprocess. We just need one counterexample to show this. Consider the process\nwith autocovariance function $k(x)=\\cos(x)$. This is positive definite because\nit is a linear combination of external products: $\\cos(x-y) = \\cos x \\cos y +\n\\sin x \\sin y$. Since $\\cos$ is orthogonal to $\\sin$, they are the\neigenfunctions, so a realization of the process is a random linear combination\nof harmonic functions, which means that it is a shifted cosine, so the\ncrossings are exactly periodic.\n\nHowever, in practice we expect that there will just be a ``repulsion'' or\n``attraction'' of crossings within the scale of the autocorrelation time, so\nfor low crossing rate the formula should work.\n\n\\section{Application to real electrical noise data}\n\nWe want to test formula~\\eqref{eq:rcont} on actual electrical noise.\n\n\\subsection{Data}\n\nWe will use the Proto0 run 886, collected when operating the SiPMs below their\nbreakdown voltage, see \\autoref{sec:dataproto0}. Tiles 53, 57 and 59 (used in\nProto0) will be also studied with LNGS data, while for Tile~15 just LNGS data\nare available. The LNGS data files are:\n%\n\\begin{verbatim}\nFBK/NUV/MB2-LF-3x/NUV-LF_3x_53/nuvhd_lf_3x_tile53_77K_64V_6VoV_1.wav\nFBK/NUV/MB2-LF-3x/NUV-LF_3x_53/nuvhd_lf_3x_tile53_77K_66V_7VoV_1.wav\nFBK/NUV/MB2-LF-3x/NUV-LF_3x_57/nuvhd_lf_3x_tile57_77K_64V_6VoV_1.wav\nFBK/NUV/MB2-LF-3x/NUV-LF_3x_59/nuvhd_lf_3x_tile59_77K_64V_6VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_55V_0VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_59V_2VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_63V_4VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_67V_6VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_71V_8VoV_1.wav\nLFOUNDRY/pre-production-test/TILE_15/LF_TILE15_77K_73V_9VoV_1.wav\n\\end{verbatim}\n\nThe Proto0 data consists purely of noise, so no preprocessing is required. For\nthe LNGS data we take the pre-trigger part of the events, and ignore events\nwhere any pre-trigger sample is less than~750 (860 for Tile~15).\n\nWe plot the time-value histogram of the data for Tile 53 in Proto0 and LNGS\n(\\autoref{fig:hist2dtile53}), for Tile 15 at maximum overvoltage, and for\nTiles 57 and 59 (\\autoref{fig:hist2dtile155759}).\n\n\\subsection{Filter}\n\nWe filter using a \\SI1{\\micro s} moving average with \\SI1{\\micro s} of baseline\nand \\SI1{\\micro s} of dead time, without delay between the baseline and the\nsignal averages. In \\autoref{fig:sqfilt} we show an example filtered\nwaveform and the filter shape.\n\n\\begin{figure}\n\n    \\widecenter{\\includempl{figsqfilt}}\n\n    \\figcaption{sqfilt}{A filtered waveform. The computation is split into a\n    moving average $m$ (dotted line) and its finite difference $y$ (solid black\n    line). The right plot shows the overall filter shape. (We use an event with\n    a signal just to see how the filter behaves, the analysis is done on noise\n    only.)}\n\n\\end{figure}\n\nAlthough we know from \\autoref{ch:snr} and~\\ref{ch:timeres} that this is\nnot the optimal filter by SNR neither by temporal resolution, this is a simple\nfilter that would be suitable for implementation in the digitizer's FPGA.\n\nSince on LNGS data the events are short compared to the filter length\n(\\SI9{\\micro s} vs.\\ \\SI2{\\micro s}), we need to take into account boundary\neffects. The output length of the filtered waveform is $(\\text{initial length})\n- \\SI2{\\micro s} + \\SI1{sample}$; to compute the rate we have to divide by this\nquantity instead of the initial waveform length.\n\nThe dead time does not play nicely with borders, because a hypothetical unseen\ncrossing within \\SI1{\\micro s} before the event start could kill a crossing in\nthe event. Moreover, at low thresholds, the first crossing will happen\nalmost immediately, and again immediately after the dead time ends, thus the\nnumber of crossings per event is quantized.\n\nA complete solution to these problems would be to avoid counting the crossings\nwhich happen within \\SI1{\\micro s} after the event start (although they are\ndetected and do project a dead time on the following ones), and in the\nremaining region further select a subregion which is \\SI1{\\micro s} shorter but\nhas a uniformly random starting position.\n\nHowever we are mostly interested in the low-rate regime, in which the dead time\nboundary effects are negligible, so we keep the whole filtered region.\n\n\\subsection{Algorithm}\n\nThe simplest way to count the threshold crossings as a function of the\nthreshold is to repeat the calculation varying the threshold. The computational\ncomplexity is $O(nN)$ where $n$ is the number of thresholds and $N$ the number\nof samples.\n\nTo produce a smooth curve (large $n$) we use instead a reverse histogram. We\nchoose an evenly spaced range of thresholds. For each pair of consecutive\nsamples, if the second sample is higher than the first, we determine the\nsubrange of thresholds that falls between the samples, and increment their\ncounts. To apply the dead time, we keep a per-threshold last occurence time.\n\nSince the range of thresholds is evenly spaced, the subrange can be found\narithmetically, so the complexity is just $O(N)$, i.e., it does not depend on\nthe number of thresholds.\n\n\\subsection{Results}\n\\label{sec:rateconcl}\n\nIn \\autoref{fig:fakerate1} we compare the measured threshold crossings with\nthe continuous-derived formula~\\eqref{eq:rcont} for a single Tile over the\nentire threshold range. The coefficients $\\sigma$ and $k_2$ for the formula are\ncomputed on each filtered event and then averaged. Finally, the dead time is\naccounted for with~\\eqref{eq:deadrate}. For the data, the conversion from count\nto rate is done dividing by the length of the filtered waveform (so \\SI2{\\micro\ns} less than the initial length per event).\n\nA discrete agreement can be observed at low and high rates, less so in the\nintermediate region. The agreement at high rate is probably improved by\nsaturation due to dead time, since the maximum rate allowed by dead time is\n$1/(\\SI1{\\micro s}) = \\SI1{Mcps}$. Although it cannot be fully appreciated from\n\\autoref{fig:fakerate1} due to the logarithmic scale, even where the theory and\ndata lines are closer they still differ by a factor~1.3, while the Poisson\nerror is approx.~\\SI3\\% since the count is~1000.\n\n\\begin{figure}\n    \n    \\widecenter{\\includempl{figfakerate1}}\n\n    \\figcaption{fakerate1}{Measured and predicted (with \\autoref{eq:rcont})\n    fake rate for Tile~31 in Proto0 with a noise-only acquisition. The right\n    scale shows the actual count of threshold crossings for the data, with a\n    gray band marking one crossing.}\n    \n\\end{figure}\n\nIn \\autoref{fig:fakerate} we show the same comparison together for all\ndatasets, divided in three groups (Tile~15 LNGS data, LNGS other Tiles, Proto0\ndata). The parameters for the formula, and the rates at threshold~$4\\,\\sigma$,\nare listed in \\autoref{tab:fakerate}.\n\nFor comparison, in \\autoref{fig:fakerate} we also show the rate predicted by\n\\cite[98]{savarese2018}, which provides the following formula:\n%\n\\begin{align}\n    r &= \\frac{R_0}2 \\exp\\left(-\\frac12 (u/\\sigma)^2\\right), \\\\\n    R_0 &= \\frac 2{\\sqrt 3} f_u, \\quad f_u = \\SI{40}{MHz}.\n\\end{align}\n%\nWe see that it overestimates the true rate about by a factor of~5-10. Note,\nhowever, that the formula was derived without taking into account filtering, so\nthe overestimation is expected.\n\nIn the second group above some threshold the measured rate stops decreasing and\nremains constant at approximately 10 counts. This is probably due to real\npulses which our very simple preprocessing can not filter away, most likely\n\\SI1{PE} dark noise or random pulses from light leaks.\n\nIn \\autoref{fig:fakerate} we highlight the measured rates for Tile~53 because\nthey are evident outliers. The rate remains higher than the theory predicts and\nthan the other Tiles as the threshold increases. This is visible in Proto0, and\nin LNGS at \\SI6{VoV}, but not at \\SI7{VoV}. Analogously, from\n\\autoref{tab:fakerate} we see that the quantity $f_s \\sqrt{-k_2}/(2\\pi\\sigma)$\nthat multiplies the exponential in~\\eqref{eq:rcont} is different from the\nothers for Tile~53, in the same cases as the data, but with the opposite trend.\nThis variation seems to depend only on an increase in $\\sigma$ and not on $k_2$.\n\nComparing the 2D histograms for Tile~53 (\\autoref{fig:hist2dtile53}) to the\nothers (\\autoref{fig:hist2dtile155759}) there is no apparent difference. Three\npossible explanations come to mind: 1)~a violation of Gaussianity, 2)~stray\npulses, 3)~low frequency electrical noise.\n\n\\marginpar{Looking at the spectrum it is evident that there's a very low\nfrequency component ($<\\SI{10}{kHZ} = 1/(\\SI{100}{\\micro s})$) absent in other\nTiles. Maybe they are sudden changes of baseline? I should look at events where\ncrossings with high threshold happen. Try to do the spectrum with windowing to\nsee if it's a boundary problem.}\n\nRegarding Gaussianity, we checked the distribution of the samples before\nfiltering and it agrees very well with a Gaussian. If they are stray pulses,\nthey do not have the same height, otherwise they would show up as a flat rate\ncurve. It could be oscillating noise with a frequency of\napprox.~$1/(\\SI2{\\micro s}) = \\SI{500}{kHz}$, since our filter would be very\ngood at picking that up, or sudden variations of the baseline.\n\nWe note that this behavior arises for the same Tile in different setups,\nshowing up both as an increased noise RMS and an higher threshold crossing\nrate. We also note that the Proto0 data were collected after the LNGS data. As\nfor the absence of this behavior in the LNGS data collected at \\SI{7}{VoV}, we\ncannot formulate hypotheses as we do not know in what order the LNGS data at\n\\SI{6}{VoV} and \\SI{7}{VoV} were collected, i.e., whether the tile was damaged\nduring the testing procedure.\n\nWe did not investigate further the discrepancy for Tile~53, since for all\nthe other Tiles the agreement between our model and data is consistent and\nsatisfactory.\n\nWe now want to estimate the minimum amount of data required for the procedure.\nFrom \\autoref{tab:fakerate} we see that the relative error on $k_2$ times the\nsquare root of the time, $C \\equiv\n\\operatorname{Std}[\\bar{k_2}]\\sqrt{T}/|k_2|$, is approximately \\SI8{ns^{1/2}}\nin all cases. The error should be proportional to $T^{-1/2}$, so to have an\n\\SI1\\% error we need $T_{\\SI1\\%} = (100 C)^2 = \\SI{0.7}{ms}$.\n\nWe conclude this chapter by summarizing all the steps we took to compute the\nfake rate:\n%\n\\begin{enumerate}\n    \n    \\item Acquire at least \\SI1{ms} of noise data.\n    \n    \\item Filter the data (including baseline subtraction) producing a\n    filtered waveform $\\mathbf y$.\n    \n    \\item Compute the standard deviation $\\sigma$ and $k_2 =\n    \\operatorname{Cov}[y_i, y_{i+1} + y_{i-1} - 2y_i]$.\n    \n    \\item Compute the fake rate for threshold $u$ using $r =\n    f_s\\sqrt{-k_2/(2\\pi)}\\operatorname{gauss}(u;0,\\sigma)$ where $f_s$ is the\n    sampling frequency.\n    \n\\end{enumerate}\n%\nAlternatively, if one has a noise spectrum available but not the noise\nwaveform, it is possible to obtain the autocovariance by computing the discrete\nFourier transform of the power spectrum \\cite[84]{ferrante2015} and then\nnormalizing it to be $\\sigma^2$ in 0. Then $k_2$ is obtained by the covariance\nat lag 1 $c$ with \\eqref{eq:c2k2}. If the spectrum was obtained from the\ndiscrete Fourier transform of a noise waveform, $c$ is the first coefficient\nafter the central one in the autocovariance.\n\nThe model was satisfactory in 24 of the 25 Tiles we considered. The uncertainty\nin the low rate regime is \\SI{\\pm50}\\% and the result is an overestimate with\nprobability \\SI{90}\\%. These statements are educated guesses based on\n\\autoref{tab:fakerate}.\n\n\\begin{table}\n    \n    \\widecenter{%\n    \\begin{tabular}{\n        c\n        S[table-format=2]\n        S[table-format=>1]\n        S[table-format=3]\n        S[table-format=2.1]\n        S[table-format=+1.4]\n        S[table-format=2.3]\n        S[table-format=1.1]\n        *2S[table-format=1.2]\n    }\n        \\toprule\n        \\multicolumn3c{Data}\n        &\n        &\n        &\n        &\n        &\n        & \\multicolumn2c{Rate @ $4\\,\\sigma$} \\\\\n        \\cmidrule(r){1-3} \\cmidrule(l){9-10}\n        \n        Setup\n        & {Tile}\n        & {Overvoltage}\n        & {$T$}\n        & {$\\sigma$}\n        & {$k_2$}\n        & {$\\operatorname{Std}[\\bar{k_2}]\\sqrt T$}\n        & {$f_s \\sqrt{-k_2}/(2\\pi\\sigma)$}\n        & {Theory}\n        & {Data} \\\\\n        \n        &\n        & {[\\si{V}]}\n        & {[\\si{ms}]}\n        & {[\\si{u}]}\n        & {[\\si{u^2}]}\n        & {[\\si{u^2 ns^{1/2}}]}\n        & {[\\si{Mcps}]}\n        & {[\\si{kcps}]}\n        & {[\\si{kcps}]} \\\\\n        \\midrule\n        \n  LNGS & 15 &  0 & 138 &  1.6 & -0.0017 & 0.012 & 4.2 &  1.4 &  1.1 \\\\\n  LNGS & 15 &  2 & 138 &  1.5 & -0.0017 & 0.012 & 4.3 &  1.4 &  1.2 \\\\\n  LNGS & 15 &  4 & 138 &  1.5 & -0.0017 & 0.012 & 4.3 &  1.4 &  1.3 \\\\\n  LNGS & 15 &  6 & 138 &  1.5 & -0.0017 & 0.012 & 4.4 &  1.5 &  1.1 \\\\\n  LNGS & 15 &  8 & 138 &  1.5 & -0.0017 & 0.012 & 4.5 &  1.5 &  1.4 \\\\\n  LNGS & 15 &  9 & 138 &  1.4 & -0.0017 & 0.012 & 4.6 &  1.5 &  1.3 \\\\  \\midrule\n  LNGS & 53 &  6 &  69 &  3.8 & -0.0044 & 0.030 & 2.7 & 0.92 &  2.6 \\\\\n  LNGS & 53 &  7 &  69 &  2.1 & -0.0043 & 0.029 & 5.0 &  1.7 &  1.0 \\\\\n  LNGS & 57 &  6 &  68 &  2.2 & -0.0043 & 0.031 & 4.8 &  1.6 &  1.2 \\\\\n  LNGS & 59 &  6 &  69 &  2.2 & -0.0040 & 0.028 & 4.6 &  1.5 &  1.0 \\\\  \\midrule\nProto0 & 29 & <0 & 499 &  8.3 &   -0.86 &   10. & 2.2 & 0.74 & 0.77 \\\\\nProto0 & 30 & <0 & 499 &  6.9 &   -0.75 &   6.0 & 2.5 & 0.84 & 0.67 \\\\\nProto0 & 31 & <0 & 499 &  7.7 &   -0.82 &   7.0 & 2.3 & 0.78 & 0.60 \\\\\nProto0 & 32 & <0 & 499 &  7.0 &   -0.76 &   6.6 & 2.5 & 0.83 & 0.67 \\\\\nProto0 & 34 & <0 & 499 &  6.5 &   -0.78 &   6.2 & 2.7 & 0.90 & 0.62 \\\\\nProto0 & 36 & <0 & 499 &  7.7 &   -0.84 &   7.1 & 2.4 & 0.79 & 0.63 \\\\\nProto0 & 37 & <0 & 499 &  6.5 &   -0.69 &   5.4 & 2.5 & 0.85 & 0.67 \\\\\nProto0 & 38 & <0 & 499 &  7.7 &   -0.84 &   7.1 & 2.4 & 0.80 & 0.59 \\\\\nProto0 & 39 & <0 & 499 &  7.6 &   -0.91 &   7.5 & 2.5 & 0.84 & 0.68 \\\\\nProto0 & 41 & <0 & 499 &  7.5 &   -0.87 &   7.1 & 2.5 & 0.83 & 0.71 \\\\\nProto0 & 42 & <0 & 499 &  7.0 &   -0.82 &   6.8 & 2.6 & 0.87 & 0.63 \\\\\nProto0 & 52 & <0 & 499 &  7.8 &   -0.82 &   6.5 & 2.3 & 0.77 & 0.61 \\\\\nProto0 & 53 & <0 & 499 & 10.1 &   -0.90 &   8.0 & 1.9 & 0.63 &  2.3 \\\\\nProto0 & 54 & <0 & 499 &  8.0 &   -0.89 &   7.4 & 2.4 & 0.79 & 0.59 \\\\\nProto0 & 55 & <0 & 499 &  8.0 &   -0.85 &   7.1 & 2.3 & 0.77 & 0.63 \\\\\nProto0 & 57 & <0 & 499 &  7.8 &   -0.88 &   7.4 & 2.4 & 0.80 & 0.69 \\\\\nProto0 & 58 & <0 & 499 &  7.6 &   -0.82 &   6.4 & 2.4 & 0.79 & 0.65 \\\\\nProto0 & 59 & <0 & 499 &  7.6 &   -0.79 &   6.6 & 2.3 & 0.77 & 0.55 \\\\\nProto0 & 60 & <0 & 499 &  7.5 &   -0.77 &   6.3 & 2.3 & 0.78 & 0.61 \\\\\nProto0 & 61 & <0 & 499 &  8.0 &   -0.89 &   7.4 & 2.4 & 0.79 & 0.60 \\\\\nProto0 & 62 & <0 & 499 &  7.6 &   -0.80 &   6.6 & 2.3 & 0.78 & 0.62 \\\\\nProto0 & 63 & <0 & 499 &  8.1 &   -0.86 &   7.1 & 2.3 & 0.76 & 0.61 \\\\\nProto0 & 64 & <0 & 499 &  7.9 &   -0.81 &   6.9 & 2.3 & 0.76 & 0.66 \\\\\nProto0 & 65 & <0 & 499 &  7.5 &   -0.80 &   6.4 & 2.4 & 0.80 & 0.62 \\\\\nProto0 & 66 & <0 & 499 &  8.2 &   -0.91 &   7.5 & 2.3 & 0.77 & 0.61 \\\\\n        \n        \\bottomrule\n    \\end{tabular}}\n    \n    \\tabcaption{fakerate}{The coefficients measured on the filtered waveforms\n    needed to evaluate the formula for the threshold upcrossing rate. $T$ is\n    the total duration, $\\sigma$ the standard deviation, $k_2$ the covariance\n    of the waveform with its second derivative (\\autoref{eq:k2}),\n    $\\operatorname{Std}[\\bar{k_2}]$ the uncertainty on the value of $k_2$\n    determined as the standard deviation of the sample mean of $k_2$ values\n    across events. The unit ``\\si{u}'' is the ADC digit.}\n    \n\\end{table}\n\n\\begin{figure}\n    \n    \\widecenter{\\includempl{figfakerate}}\n    \n    \\figcaption{fakerate}{The threshold upcrossing rate both counting directly\n    the crossings on data and computing it with formula~\\eqref{eq:rcont}. The\n    gray band marks the rate corresponding to a single crossing counted in the\n    data. The thick gray curve is the rate predicted by\n    \\cite[98]{savarese2018}.}\n    \n\\end{figure}\n\n\\begin{figure}\n    \n    \\widecenter{\\includempl{fighist2dtile53-0}}\n\n    \\widecenter{\\includempl{fighist2dtile53-1}}\n\n    \\widecenter{\\includempl{fighist2dtile53-2}}\n    \n    \\figcaption{hist2dtile53}{Time-value histograms of Tile 53 noise in Proto0\n    with a baseline acquisition, and in LNGS pre-trigger at overvoltage \\SI6V\n    and \\SI7V.}\n    \n\\end{figure}\n\n\\begin{figure}\n    \n    \\widecenter{\\includempl{fighist2dtile155759-0}}\n\n    \\widecenter{\\includempl{fighist2dtile155759-1}}\n\n    \\widecenter{\\includempl{fighist2dtile155759-2}}\n\n    \\figcaption{hist2dtile155759}{Time-value histograms of Tiles 15, 57 and 59\n    noise in LNGS data.}\n    \n\\end{figure}\n", "meta": {"hexsha": "c2c25e6d6d9b49dabd4f60c20f8e3420bc675412", "size": 26703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rate.tex", "max_stars_repo_name": "Gattocrucco/thesis", "max_stars_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-15T07:16:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T07:16:46.000Z", "max_issues_repo_path": "rate.tex", "max_issues_repo_name": "Gattocrucco/thesis", "max_issues_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "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": "rate.tex", "max_forks_repo_name": "Gattocrucco/thesis", "max_forks_repo_head_hexsha": "0b8672b7dc6a4ec54c5c76ecfbb83edcf34729f7", "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.3571428571, "max_line_length": 80, "alphanum_fraction": 0.6952402352, "num_tokens": 8531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6076767164776908}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrri}\n\\section*{\\hspace*{-1.6cm} tfrri}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nRihaczek time-frequency distribution.\n\\end{minipage}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrri(x)\n[tfr,t,f] = tfrri(x,t)\n[tfr,t,f] = tfrri(x,t,N)\n[tfr,t,f] = tfrri(x,t,N,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrri} computes the Rihaczek distribution of a discrete-time\n        signal {\\ty x}, or the cross Rihaczek representation between two\n        signals. Its expression is \n\\[R_x(t,\\nu)=x(t)\\ X^*(\\nu)\\ e^{-j2\\pi \\nu t}.\\]\n \n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & signal if auto-Ri, or {\\ty [x1,x2]} if cross-Ri ({\\ty\n\t\t\tNx=length(x)}) \\\\\n        {\\ty t}     & time instant(s)           & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins  & {\\ty Nx}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                          & {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation\\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrri} applies {\\ty tfrqview} on\n the real part of the distribution, which is equal to the Margenau-Hill\n distribution.\n\\end{minipage}\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4); tfrri(sig);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] A. Rihaczek ``Signal Energy Distribution in Time and Frequency'', IEEE\nTans. on Info. Theory, Vol. 14, No. 3, pp. 369-374, 1968.\n\\end{minipage}\n", "meta": {"hexsha": "49cfb7836f17ae4d5241f43a8f6815577cd9ba45", "size": 2245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrri.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrri.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrri.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 27.3780487805, "max_line_length": 75, "alphanum_fraction": 0.6213808463, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672089305841, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6076767105409766}}
{"text": "\\documentclass[11pt]{article}\n\n\\newcommand{\\REDUCE}{REDUCE}\n\\newcommand{\\RLISP}{RLISP}\n% \\usepackage{reduce}\n\n\\title{\\texttt{TRIGSIMP} \\\\\nA \\REDUCE{} Package for the Simplification and Factorization of\nTrigonometric and Hyperbolic Expressions}\n\n\\author{Wolfram Koepf \\\\\n\tAndreas Bernig \\\\\n\tHerbert Melenk \\\\\n\tZIB Berlin \\\\\n\t~ \\\\\n\tRevised by Francis Wright \\\\\n\tQMW London \\\\\n\tE-mail: \\texttt{F.J.Wright@Maths.QMW.ac.uk}}\n\n\\date{17 January 1999}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\n\nThe \\REDUCE{} package TRIGSIMP is a useful tool for all kinds of\nproblems related to trigonometric and hyperbolic simplification and\nfactorization.  There are three operators included in TRIGSIMP:\ntrigsimp, trigfactorize and triggcd.  The first is for simplifying\ntrigonometric or hyperbolic expressions and has many options, the\nsecond is for factorizing them and the third is for finding the\ngreatest common divisor of two trigonometric or hyperbolic\npolynomials.  This package is automatically loaded when one of these\noperators is used.\n\n\n\\section{Simplifying trigonometric expressions}\n\nAs there is no normal form for trigonometric and hyperbolic\nexpressions, the same function can convert in many different\ndirections, e.g.\\ $\\sin(2x) \\leftrightarrow 2\\sin(x)\\cos(x)$.  The\nuser has the possibility to give several parameters to the operator\n\\texttt{trigsimp} in order to influence the transformations.  It is\npossible to decide whether or not a rational expression involving\ntrigonometric and hyperbolic functions vanishes.\n\nTo simplify an expression \\texttt{f}, one uses\n\\texttt{trigsimp(f[,options])}.  For example:\n\\begin{verbatim}\ntrigsimp(sin(x)^2+cos(x)^2);\n\n1\n\\end{verbatim}\nThe possible options (where $^*$ denotes the default) are:\n\\begin{enumerate}\n\\item \\texttt{sin}$^*$ or \\texttt{cos};\n\\item \\texttt{sinh}$^*$ or \\texttt{cosh};\n\\item \\texttt{expand}$^*$, \\texttt{combine} or \\texttt{compact};\n\\item \\texttt{hyp}, \\texttt{trig} or \\texttt{expon};\n\\item \\texttt{keepalltrig};\n\\item \\texttt{tan} and/or \\texttt{tanh};\n\\item target arguments of the form \\textit{variable} /\n\\textit{positive integer}.\n\\end{enumerate}\nFrom each of the first four groups one can use at most one option,\notherwise an error message will occur.  Options can be given in any\norder.\n\nThe first group fixes the preference used while transforming a\ntrigonometric expression:\n\\begin{verbatim}\ntrigsimp(sin(x)^2);\n\n      2\nsin(x)\n\ntrigsimp(sin(x)^2, cos);\n\n         2\n - cos(x)  + 1\n\\end{verbatim}\nThe second group is the equivalent for the hyperbolic functions.\n\nThe third group determines the type of transformation.  With the\ndefault, \\texttt{expand}, an expression is transformed to use only\nsimple variables as arguments:\n\\begin{verbatim}\ntrigsimp(sin(2x+y));\n\n                                 2\n2*cos(x)*cos(y)*sin(x) - 2*sin(x) *sin(y) + sin(y)\n\\end{verbatim}\nWith \\texttt{combine}, products of trigonometric functions are\ntransformed to trig\\-onometric functions involving sums of variables:\n\\begin{verbatim}\ntrigsimp(sin(x)*cos(y), combine);\n\n sin(x - y) + sin(x + y)\n-------------------------\n            2\n\\end{verbatim}\nWith \\texttt{compact}, the \\REDUCE{} operator \\texttt{compact}\n\\cite{hearns} is applied to \\texttt{f}.  This often leads to a simple\nform, but in contrast to \\texttt{expand} one does not get a normal\nform. For example:\n\\begin{verbatim}\ntrigsimp((1-sin(x)^2)^20*(1-cos(x)^2)^20, compact);\n\n      40       40\ncos(x)  *sin(x)\n\\end{verbatim}\n\nWith an option from the fourth group, the input expression is\ntransformed to trigonometric, hyperbolic or exponential form\nrespectively:\n\\begin{verbatim}\ntrigsimp(sin(x), hyp);\n\n - sinh(i*x)*i\n\ntrigsimp(sinh(x), expon);\n\n  2*x\n e    - 1\n----------\n      x\n   2*e\n\ntrigsimp(e^x, trig);\n\ncos(i*x) - sin(i*x)*i\n\\end{verbatim}\n\nUsually, \\texttt{tan}, \\texttt{cot}, \\texttt{sec}, \\texttt{csc} are\nexpressed in terms of \\texttt{sin} and \\texttt{cos}.  It can sometimes\nbe useful to avoid this, which is handled by the option\n\\texttt{keepalltrig}:\n\\begin{verbatim}\ntrigsimp(tan(x+y), keepalltrig);\n\n  - (tan(x) + tan(y))\n----------------------\n  tan(x)*tan(y) - 1\n\\end{verbatim}\nAlternatively, the options \\texttt{tan} and/or \\texttt{tanh} can be\ngiven to convert the output to the specified form as far as possible:\n\\begin{verbatim}\ntrigsimp(tan(x+y), tan);\n\n  - (tan(x) + tan(y))\n----------------------\n  tan(x)*tan(y) - 1\n\\end{verbatim}\nBy default, the other functions used will be \\texttt{cos} and/or\n\\texttt{cosh}, unless the other desired functions are also specified\nin which case this choice will be respected.\n\nThe final possibility is to specify additional target arguments for\nthe trigonometric or hyperbolic functions, each of which should have\nthe form of a variable divided by a positive integer.  These\nadditional arguments are treated as if they had occurred within the\nexpression to be simplified, and their denominators are used in\ndetermining the overall denominator to use for each variable in the\nsimplified form:\n\\begin{verbatim}\ntrigsimp(csc x - cot x + csc y - cot y, x/2, y/2, tan);\n\n     x          y\ntan(---) + tan(---)\n     2          2\n\\end{verbatim}\n\nIt is possible to use the options of different groups simultaneously:\n\\begin{verbatim}\ntrigsimp(sin(x)^4, cos, combine);\n\n cos(4*x) - 4*cos(2*x) + 3\n---------------------------\n             8\n\\end{verbatim}\n\nSometimes, it is necessary to handle an expression in separate steps:\n\\begin{verbatim}\ntrigsimp((sinh(x)+cosh(x))^n+(cosh(x)-sinh(x))^n, expon);\n\n  1   n    n*x\n(----)  + e\n   x\n  e\n\ntrigsimp(ws, hyp);\n\n2*cosh(n*x)\n\ntrigsimp((cosh(a*n)*sinh(a)*sinh(p)+cosh(a)*sinh(a*n)*sinh(p)+\n    sinh(a - p)*sinh(a*n))/sinh(a));\n\ncosh(a*n)*sinh(p) + cosh(p)*sinh(a*n)\n\ntrigsimp(ws, combine);\n\nsinh(a*n + p)\n\\end{verbatim}\n\nThe \\texttt{trigsimp} operator can be applied to equations, lists and\nmatrices (and compositions thereof) as well as scalar expressions, and\nautomatically maps itself recursively over such non-scalar data\nstructures:\n\\begin{verbatim}\ntrigsimp( { sin(2x) = cos(2x) } );\n\n                            2\n{2*cos(x)*sin(x)= - 2*sin(x)  + 1}\n\\end{verbatim}\n\n\n\\section{Factorizing trigonometric expressions}\n\nWith \\texttt{trigfactorize(p,x)} one can factorize the trigonometric\nor hyperbolic polynomial \\texttt{p} in terms of trigonometric\nfunctions of the argument \\texttt{x}.  The output has the same format\nas that from the standard \\REDUCE{} operator \\texttt{factorize}.  For\nexample:\n\\begin{verbatim}\ntrigfactorize(sin(x), x/2);\n\n             x            x\n{{2,1},{sin(---),1},{cos(---),1}}\n             2            2\n\\end{verbatim}\nIf the polynomial is not coordinated or balanced \\cite{art}, the\noutput will equal the input.  In this case, changing the value for\n\\texttt{x} can help to find a factorization, e.g.\n\\begin{verbatim}\ntrigfactorize(1+cos(x), x);\n\n{{cos(x) + 1,1}}\n\ntrigfactorize(1+cos(x), x/2);\n\n             x\n{{2,1},{cos(---),2}}\n             2\n\\end{verbatim}\nThe polynomial can consist of both trigonometric and hyperbolic functions:\n\\begin{verbatim}\ntrigfactorize(sin(2x)*sinh(2x), x);\n\n{{4,1}, {sinh(x),1}, {cosh(x),1}, {sin(x),1}, {cos(x),1}}\n\\end{verbatim}\n\nThe \\texttt{trigfactorize} operator respects the standard \\REDUCE{}\n\\texttt{factorize} switch \\texttt{nopowers} -- see the \\REDUCE{}\nmanual for details.  Turning it on gives the behaviour that was\nstandard before \\REDUCE~3.7:\n\\begin{verbatim}\non nopowers;\n\ntrigfactorize(1+cos(x), x/2);\n\n        x        x\n{2,cos(---),cos(---)}\n        2        2\n\\end{verbatim}\n\n\n\\section{GCDs of trigonometric expressions}\n\nThe operator \\texttt{triggcd} is essentially an application of the\nalgorithm behind \\texttt{trigfactorize}.  With its help the user can\nfind the greatest common divisor of two trigonometric or hyperbolic\npolynomials.  It uses the method described in \\cite{art}.  The syntax\nis \\texttt{triggcd(p,q,x)}, where \\texttt{p} and \\texttt{q} are the\ntrigonometric polynomials and \\texttt{x} is the argument to use.  For\nexample:\n\\begin{verbatim}\ntriggcd(sin(x), 1+cos(x), x/2);\n\n     x\ncos(---)\n     2\n\ntriggcd(sin(x), 1+cos(x), x);\n\n1\n\\end{verbatim}\nThe polynomials $p$ and $q$ can consist of both trigonometric and\nhyperbolic functions:\n\\begin{verbatim}\ntriggcd(sin(2x)*sinh(2x), (1-cos(2x))*(1+cosh(2x)), x);\n\ncosh(x)*sin(x)\n\\end{verbatim}\n\n\n\\section{Further Examples}\n\nWith the help of this package the user can create identities:\n\\begin{verbatim}\ntrigsimp(tan(x)*tan(y));\n\n sin(x)*sin(y)\n---------------\n cos(x)*cos(y)\n\ntrigsimp(ws, combine);\n\\end{verbatim}\n\n{\\samepage\\begin{verbatim}\n cos(x - y) - cos(x + y)\n-------------------------\n cos(x - y) + cos(x + y)\n\\end{verbatim}}\n\n\\begin{verbatim}\ntrigsimp((sin(x-a)+sin(x+a))/(cos(x-a)+cos(x+a)));\n\n sin(x)\n--------\n cos(x)\n\ntrigsimp(cosh(n*acosh(x))-cos(n*acos(x)), trig);\n\n0\n\ntrigsimp(sec(a-b), keepalltrig);\n\n  csc(a)*csc(b)*sec(a)*sec(b)\n-------------------------------\n csc(a)*csc(b) + sec(a)*sec(b)\n\ntrigsimp(tan(a+b), keepalltrig);\n\n  - (tan(a) + tan(b))\n----------------------\n  tan(a)*tan(b) - 1\n\ntrigsimp(ws, keepalltrig, combine);\n\ntan(a + b)\n\\end{verbatim}\n\nSome difficult expressions can be simplified:\n\\begin{verbatim}\ndf(sqrt(1+cos(x)), x, 4);\n\n            5           4            3       2            3\n( - 4*cos(x)  - 4*cos(x)  - 20*cos(x) *sin(x)  + 12*cos(x)\n\n             2       2            2                   4\n  - 24*cos(x) *sin(x)  + 20*cos(x)  - 15*cos(x)*sin(x)\n\n                    2                       4            2\n  + 12*cos(x)*sin(x)  + 8*cos(x) - 15*sin(x)  + 16*sin(x) )/\n\n(16*sqrt(cos(x) + 1)\n\n         4           3           2\n *(cos(x)  + 4*cos(x)  + 6*cos(x)  + 4*cos(x) + 1))\n\non rationalize;\ntrigsimp(ws);\n\n sqrt(cos(x) + 1)\n------------------\n        16\n\noff rationalize;\nload_package taylor;\n\ntaylor(sin(x+a)*cos(x+b), x, 0, 4);\n\ncos(b)*sin(a) + (cos(a)*cos(b) - sin(a)*sin(b))*x\n\n                                    2\n - (cos(a)*sin(b) + cos(b)*sin(a))*x\n\n    2*( - cos(a)*cos(b) + sin(a)*sin(b))   3\n + --------------------------------------*x\n                     3\n\n    cos(a)*sin(b) + cos(b)*sin(a)   4      5\n + -------------------------------*x  + O(x )\n                  3\n\ntrigsimp(ws, combine);\n\n sin(a - b) + sin(a + b)                               2\n------------------------- + cos(a + b)*x - sin(a + b)*x\n            2\n\n    2*cos(a + b)   3    sin(a + b)   4      5\n - --------------*x  + ------------*x  + O(x )\n         3                  3\n\\end{verbatim}\n\nCertain integrals whose evaluation was not possible in \\REDUCE{}\n(without preprocessing) are now computable:\n\\begin{verbatim}\nint(trigsimp(sin(x+y)*cos(x-y)*tan(x)), x);\n\n       2\n(cos(x) *x - cos(x)*sin(x) - 2*cos(y)*log(cos(x))*sin(y)\n\n          2\n  + sin(x) *x)/2\n\nint(trigsimp(sin(x+y)*cos(x-y)/tan(x)), x);\n\n                                   x  2\n(cos(x)*sin(x) - 2*cos(y)*log(tan(---)  + 1)*sin(y)\n                                   2\n\n                      x\n  + 2*cos(y)*log(tan(---))*sin(y) + x)/2\n                      2\n\\end{verbatim}\nWithout the package, the integration fails, and in the second case one\ndoes not receive an answer for many hours.\n\n\\begin{verbatim}\ntrigfactorize(sin(2x)*cos(y)^2, y/2);\n\n{{2*cos(x)*sin(x),1},\n\n       y          y\n {cos(---) - sin(---),2},\n       2          2\n\n       y          y\n {cos(---) + sin(---),2}}\n       2          2\n\\end{verbatim}\n\\begin{verbatim}\ntrigfactorize(sin(y)^4-x^2, y);\n\n        2               2\n{{sin(y)  + x,1},{sin(y)  - x,1}}\n\ntrigfactorize(sin(x)*sinh(x), x/2);\n\n{{4,1},\n\n        x\n {sinh(---),1},\n        2\n\n        x\n {cosh(---),1},\n        2\n\n       x\n {sin(---),1},\n       2\n\n       x\n {cos(---),1}}\n       2\n\ntriggcd(-5+cos(2x)-6sin(x), -7+cos(2x)-8sin(x), x/2);\n\n       x        x\n2*cos(---)*sin(---) + 1\n       2        2\n\ntriggcd(1-2cosh(x)+cosh(2x), 1+2cosh(x)+cosh(2x), x/2);\n\n        x  2\n2*sinh(---)  + 1\n        2\n\\end{verbatim}\n\n\\begin{thebibliography}{99}\n\n\\bibitem{art}\nRoach, Kelly: Difficulties with Trigonometrics. Notes of a talk.\n\n\\bibitem{hearns}\nHearn, A.C.: COMPACT User Manual.\n\n\\end{thebibliography}\n\\end{document}\n", "meta": {"hexsha": "b5f8c252053c205e51bcae86f52c0bd53250edd6", "size": 12020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packages/trigsimp/trigsimp.tex", "max_stars_repo_name": "arthurcnorman/general", "max_stars_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": "packages/trigsimp/trigsimp.tex", "max_issues_repo_name": "arthurcnorman/general", "max_issues_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": "packages/trigsimp/trigsimp.tex", "max_forks_repo_name": "arthurcnorman/general", "max_forks_repo_head_hexsha": "5e8fef0cc7999fa8ab75d8fdf79ad5488047282b", "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": 24.8347107438, "max_line_length": 74, "alphanum_fraction": 0.6143094842, "num_tokens": 3790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672043084051, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6076767025739437}}
{"text": "\\section{Multigrid Methods } %Jonathan / b-j8522 / Jul 20\n\n\n\\subsection{Dual spaces}\n{\\bf Definition:} Given a vector space $V$, the dual space \n$$V^\\prime = \\{\\varphi: V \\to \\mathbb{R}: \\varphi\\textrm{ is a linear map}\\}$$\nHere $V^\\prime$ itself is  also a vector space. It's easy to verify $(\\varphi_1+\\varphi_2): V\\to \\mathbb{R}$. (Because $(\\varphi_1+\\varphi_2)(v)=\\varphi_1(v)+\\varphi_2(v)$). \n\nLet $v_1,\\ldots,v_n \\in V$ be a basis, define functions $\\varphi_i: V\\to\\mathbb{R}$ by \n\\begin{equation}\n\\varphi_i (v_j) = \\delta_{ij} := \\left\\{\n\t\\begin{array}{cc}\n\t1, & i=j \\\\\n\t0, & i\\ne j\n\t\\end{array} \\right.\n\\end{equation}\n\nExercise: show that $\\varphi_1, \\ldots, \\varphi_n$ is a basis of $V^\\prime$.\n\nLet's give some properties of the dual space here.\nSuppose $f: V \\to W$ is a linear map. Let $W^\\prime$ be the dual space of $W$, defined by\n\\begin{equation}\nW^\\prime = \\{ \\psi: W\\to \\mathbb{R},\\ \\textrm{s.t.}\\ W\\ \\textrm{is linear} \\}.\n\\end{equation}  \nSo $\\psi \\circ f: V\\to \\mathbb{R}$ is linear, which means $\\psi \\circ f \\in V^\\prime$.\nComposition with $f$ gives a map from $W^\\prime$ to $V^\\prime$. %, called $f^\\top$\n\nFurthermore, suppose $W\\subset V$ is a subspace, a $\\varphi \\in V^\\prime$ is a function from $V$ to $\\mathbb{R}$, and is also a function from $W$ to $\\mathbb{R}$.  \n\n\n\\subsection{Multigrid methods}\nConsider to solving a linear system as follows\n\\begin{equation}\\label{eq:linearsys}\nA u = \\varphi\n\\end{equation}\nwhere $\\varphi\\in V^{\\prime}$, we are looking for $u\\in V$, and  $A: V\\to V^{\\prime}$ is a linear map. Here $V^{\\prime}$ is the dual space of $V$. \n\nNow, we consider a method to solving the linear system \\eqref{eq:linearsys}. Notice that $V$ is a very high dimensional, so the system is very difficult to solve. So we consider if we can approximate this equation by some lower dimensional system.\n\nConsider a subspace $W\\subset V$, then we can consider the system \n\\begin{equation}\\label{eq:sublinearsys}\nAw = \\psi\n\\end{equation}\nwhere $w\\in W$ and $\\psi$ equals to $\\varphi$ restricted to $W$. Basically, there is a restriction/projection operation $V^\\prime \\to W^\\prime$.%Usually the restriction is natural, so we use same notation here.\nNow, we can choose some subspace $W$, and solve system \\eqref{eq:sublinearsys} to get the approximation of the solution.\n\n\\subsubsection{Abstract Algorithm}\nConsider a sequence of subspaces $W_1, W_2, \\ldots, W_n \\subset V$. \n\\begin{itemize}\n\\item Pick $v_0\\in V$, consider residual equation \n\\begin{equation}\nAv = r_0 = \\varphi - A v_0\n\\end{equation}\n\\item Restrict $Av=r_0 $ to $W_1$. \n\\item Solve it on $W_1$ and add the solution to $v_0$ to get $v_1$.\n\\end{itemize}\n\n\\subsubsection{Example}\nWe give an 1-d example here. Consider a 1-D problem.\n\\begin{equation}\n\\begin{split}\n -\\frac{\\textrm{d}^2}{\\textrm{d} x^2} u &= f  \\label{eq:1dProb}\\\\\n u(0)&=u(1)=0\n\\end{split}\n\\end{equation}\nHere we try to find a function defined on $[0,1]$. The function values of endpoints are $0$, and the second derivative is given. \n\nThe First thing we need to do is to formulate $A: V\\to V^\\prime$. \nChoose a smooth function $g(x)$.\nIntegrate both sides of \\eqref{eq:1dProb} against $g$ (view both sides in dual space).\n\\begin{equation}\\label{eq:1dProbInt}\n\\begin{split}\n   &\\int_0^1 \\left( -\\frac{\\textrm{d}^2}{\\textrm{d} x^2} u(x) \\right) \\cdot g(x) \\textrm{d}x = \\int_0^1 f(x)  g(x) \\textrm{d}x \n \\end{split}\n\\end{equation}\nUsing integration by part, the left hand side of \\eqref{eq:1dProbInt} equals\n\\begin{equation}\n\\begin{split}\n \\int_0^1 \\left( \\frac{\\textrm{d}}{\\textrm{d} x} u \\right) \\left( \\frac{\\textrm{d}}{\\textrm{d} x} g \\right) \\textrm{d}x \n\\end{split}\n\\end{equation}\nIt gives \n\\begin{equation}\n \\int_0^1 \\left( \\frac{\\textrm{d}}{\\textrm{d} x} u \\right) \\left( \\frac{\\textrm{d}}{\\textrm{d} x} g \\right) \\textrm{d}x = \\int_0^1 f g \\textrm{d}x  \\quad \\forall g\n\\end{equation}\nBut the above still can not be solve, because it is infinite dimensional. \nSo we apply the restriction mentioned before from it to a finite dimensional subspace. \n\n\\subsubsection{Restrict to a finite dimensional subspace}\n\nDivide $[0,1]$ to $n$ pieces, $0=x_0<x_1<\\ldots<x_n=1$.\nLet $$V = \\left\\{\\ \\textrm{Piecewise linear functions which are linear on}\\ (x_i,x_{i+1}]\\ \\right\\}.$$ And this is the simplest finite element space.\nWe need to restrict $u$ and $g$ to space $V$.\n\nNow we need bases of vector spaces $V$ and $V^\\prime$ which are dual. Let's talk first about the basis in $V^\\prime$. A good choice of the basis for the dual space $V^\\prime$, functions from $V$ to real numbers. Consider functions in $V$. We have $n+1$ different grid points, and the function is uniquely determined by its values at all these grid points. Take a particular point $x_i$, and evaluating in $x_i$.\n\\begin{equation}\n\\begin{split}\n\\varphi_{i} (v) = v(x_i)\\quad \\textrm{and}\\quad\n\\varphi_{i} \\in V^\\prime\n\\end{split}\n\\end{equation}\nSo evaluation at one of these grid points is a dual vector. And particular because the function is uniquely determined by values on these grid points, this actually is the dual basis.d\nNow we obtain the dual basis. That $\\{ \\varphi_1, \\varphi_2, \\ldots, \\varphi_n\\}$ is a basis of $V^\\prime$.\nThen consider functions in $V$ with the property that $v\\in V$ such that \n\\begin{equation}\n\\varphi_i (v_j) = \\left\\{\n\t\\begin{array}{cc}\n\t1, & i=j \\\\\n\t0, & i\\ne j\n\t\\end{array} \\right.\n\\end{equation}\nSo we get the `hat' function $v_i$ that is a piecewise linear function. and $v_i$ equals one on the grid $x_i$ and zero on the others. Then we have $\\{ v_1, v_2, \\ldots, v_n \\}$ is the dual basis of $V$.\nIn order to turn \\eqref{eq:1dProbInt} into an equation like \\eqref{eq:1dProb}. We want to represent $u$ and $g$as a simple linear combination of $\\{ v_1, v_2, \\ldots, v_n \\}$:\n\\begin{equation}\nu = \\sum_{i=1}^n a_i v_i\n\\end{equation}\nAnd the right hand side of \\eqref{eq:1dProbInt} should be a dual vector and equal to \n\\begin{equation}\n\\sum_{i=1}^n b_i \\varphi_i, \n\\end{equation}\nthat is\n\\begin{equation}\nb_i = \\int_0^1 f v_i {\\rm d}x.\n\\end{equation}\nAnd we also need to figure out what $\\int_0^1 \\left( \\frac{\\textrm{d}}{\\textrm{d} x} v_i \\right) \\left( \\frac{\\textrm{d}}{\\textrm{d} x} v_j \\right) \\textrm{d}x$ is. Notice that $v_i$ is the `hat' function. Then, it gives \n\\begin{equation}\n\\left(\n\t\\begin{array}{ccccc}\n\t\\frac{2}{h} & -\\frac{1}{h} & 0 &\\cdots &0\\\\\n\t-\\frac{1}{h} & \\frac{2}{h} & 0 &\\cdots &0 \\\\ \n\t\\vdots & \\ddots  & \\ddots & \\ddots &\\vdots \\\\\n\t0 & 0 & \\cdots &-\\frac{1}{h} & \\frac{2}{h} \n\t\\end{array} \\right)\n\\left(\n\t\\begin{array}{c}\n\ta_1\\\\ a_2 \\\\\n\t\\vdots \\\\ a_n\n\t\\end{array} \\right)\n=\n\\left(\n\t\\begin{array}{c}\n\tb_1\\\\ b_2 \\\\\n\t\\vdots \\\\ b_n\n\t\\end{array} \\right)\n\\end{equation}\nwhere $h = \\frac{1}{n}$ is the length of each segmentation. \nSo far, we take the integral equation \\eqref{eq:1dProbInt} in the infinite dimensional vector space, and restrict it to a finite dimensional vector space. This is what people do to solve differential equations. \n\nNow consider the multigrid method. We start with the equation in the finite dimensional subspace $V$, then we restrict it to a coarse space (a smaller subspace of $V$). \n\nIn this particular problem, let $W\\subset V$ be the subspace of functions which are linear in $[x_{2n}, x_{2n+2}]$. Notice that we get coarse grids $0=w_0 <w_1< \\ldots <w_{\\frac{n}{2}}$. As before, we can construct two bases, like $\\{\\varphi_i\\}$ and $\\{v_i\\}$. A basis of $W^\\prime$\n\\begin{equation}\n\\{ \\psi_1^\\prime, \\psi_2^\\prime, \\ldots, \\psi_{\\frac{n}{2}}^\\prime\\}\n\\end{equation}\nand and the dual basis of $W$  \n\\begin{equation}\n\\{ w_1^\\prime, w_2^\\prime, \\ldots, w_{\\frac{n}{2}}^\\prime\\}.\n\\end{equation}\nAnd $w_i$ is also a `hat' function which is piecewise linear and equal to one at grid $x_{2i}$ and zero at the others $x_{2j}$ with $j=0,1,\\ldots,i-1,i+1,\\ldots, \\frac{n}{2}$. \nNow, we want to do the same restriction, as we done before, from $V$ to $W$.\nConsider the right hand side \n\\begin{equation}\n\\sum_{i=1}^{n} b_i \\varphi_i \\in V^\\prime\n\\end{equation}\nSo \n\\begin{equation} \n\\sum_{i=1}^{n} b_i \\varphi_i (w_j) = \\frac{1}{2} b_{2j-1} + b_{2j} +\\frac{1}{2} b_{2j+1}\n\\end{equation}\nThen we get\n\\begin{equation}\n\\left(\n\t\\begin{array}{c}\n\tb_1\\\\ b_2 \\\\ b_3 \\\\b_4 \\\\ \n\t\\vdots \\\\ b_{n-1} \\\\b_n\n\t\\end{array} \\right) \n\\to\n\\left(\n\t\\begin{array}{c}\n\t- \\\\\n\tb^\\prime_1\\\\\n\t- \\\\\n\t b_2^\\prime \\\\\n\t\\vdots \\\\- \\\\ b^\\prime_n\n\t\\end{array} \\right) \n\\end{equation}\nAnd the value of $b_i^\\prime = \\frac{1}{2} b_{2i-1} + b_{2i} + \\frac{1}{2} b_{2i+1}$. That how we get the right hand side of a small system from a large system. Notice this can be regard as the convolution with stride two. And the other thing is please to figure out, given a linear combination of the basis $\\{w_1,\\ldots, w_{\\frac{n}{2}}\\}$, how to get the coefficients of this linear combination w.r.t. the basis $\\{v_1,\\ldots, v_{\\frac{n}{2}}\\}$. That is the map from the small subspace $W$ to the large space $V$.\n", "meta": {"hexsha": "86213050ad43f54de4ecafd1648b2ba78e6b8087", "size": 8881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/497Proj_mg.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/497Proj_mg.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/497Proj_mg.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.4919786096, "max_line_length": 517, "alphanum_fraction": 0.681679991, "num_tokens": 3227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527631, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.6076766960525286}}
{"text": "%%==============================================\n%% Section 3.01: Analytic Extension to the Strip\n%%==============================================\n\n\\documentclass[../dissertation.tex]{subfiles}\n\n\n\\begin{document}\n\\section{Analytic Extension to the Strip}\\label{sec3:Analyticity}\n\n%%\n%% The following was taken directly (with a modification of the notation) \n%% from from Prof. Perry's section of the kpw1.tex file\n%% \n% We wish to show that $M_1^+$ is the lower boundary value of a function analytic in the \n% strip $\\{ z \\in \\CC ~:~ 0 < \\im z < 2\\}$ which satisfies the spectral problem \n% \\eqref{eq0:SpecProb}. For the moment we fix $\\lambda$ and supress the $\\lambda$ dependence of \n% $M_1$ and $G_L$ for brevity. As a candidate for the analytic continuation we consider the \n% function ($z=x+iy$)\n% \\begin{equation}\n% \t\\label{eq2:ILW.M.ac}\n% \tM_1(z) = 1 + \\int_{-\\infty}^\\infty G_L(x-x'+iy) u(x') M_1(x') \\, \\mathrm{d}x'.\n% \\end{equation}\n% for $0<y<2$. \nA natural candidate for the analytic extension of $G_\\star$ to the open strip \n$\\mathcal S_1 = \\{ z \\in \\mathbb C ~:~ 0 < \\im z < 2\\}$ is\n\\begin{equation}\n\t\\label{eq3:ILW.GFz}\n\tG_\\star(x+iy) \n\t\t:= \\frac{1}{2\\pi} \n\t\t\t\\int_{\\Gamma_\\star} e^{ix\\xi} \n\t\t\t\t\\frac{e^{-y\\xi}}{\\xi - \\zeta\\left(1-e^{-2\\xi}\\right)} \n\t\t\t\\, \\mathrm{d}\\xi,\n\t\t\\qquad (\\star = L \\text{, or } R)\n\\end{equation}\nwhich is a convergent integral for $0<y<2$ owing to the new factor $e^{-y\\xi}$. \nA straightforward argument with the dominated convergence theorem shows that \n$G_\\star(z)$ is continuous on the open strip $\\mathcal S_1$. It then follows from \nMorera's theorem and \\eqref{eq3:ILW.GFz} that $G_\\star(z)$ is analytic in $z$.\n\nNext we consider convolution of $G_\\star(\\dotarg+iy)$ with $L^1$ functions. Since the integral \n\\eqref{eq3:ILW.GFz} is absolutely convergent for $y$ in compact subintervals of $(0,2)$, it \nfollows that for any $f \\in L^1(\\RR)$, $G_\\star(\\dotarg+iy)* f$  obeys the uniform\nin $\\lambda$ bound \n\\[\n\t\\left\\|G_\\star(\\dotarg+iy; \\lambda)* f\\right\\|_{\\inn{\\dotarg}L^\\infty} \n\t\t\\lesssim_{\\, y} \\left\\|f\\right\\|_{L^1}\n\\] \nwhere the implied constant has the same uniformity. Another application of Morera's \ntheorem shows that, for any $f \\in C_0^\\infty(\\RR)$, the convolution $G_\\star(\\dotarg+iy)*f$ \ndefines an analytic function of $z$ in $\\mathcal S_1$. Finally let \n$f \\in L^1(\\mathbb R) \\cap L^p(\\mathbb R)$ for some \n$p \\in (1,2]$, and let $\\{ f_n \\}_{n \\in \\NN}$ be a sequence from $C_0^\\infty(\\mathbb R)$ \nconverging to $f$ in $L^1 \\cap L^p$. Then $\\left(G_\\star(\\dotarg+iy)*f_n\\right)(x)$ converges \nuniformly to $\\left(G_\\star(\\dotarg+iy)*f\\right)(x)$ on compact subsets of $\\mathcal S_1$, \nso $G_\\star(\\dotarg+iy)*f$ is also analytic in $\\mathcal S_1$. \n% This shows that $M(z)$ as defined by \\eqref{eq2:ILW.M.ac} defines an \n% analytic function on $S$. \n\nIt remains to show that $G_\\star$ as a convolution operator has an upper boundary \nvalue $G_\\star^-$ and to obtain an effective formula for $G_\\star^-$. Using the \n``boxcar'' contour in Figure \\ref{fig1:GammaContour} again we can compute\n\\begin{subequations}\n\t\\label{eq3:ILW.GFz.rep}\n\t\\begin{align}\n\t\t\\label{eq3:ILW.GLz.rep}\n\t\tG_L(x+ iy; \\lambda)\n\t\t\t&= \n\t\t\t\tK(x+iy; \\lambda) \n\t\t\t\t+ i \\big[\n\t\t\t\t\t\t\\alpha(\\lambda) + \\beta(\\lambda) e^{i\\lambda x}e^{-\\lambda y} \n\t\t\t\t\t\\big] \\chi_L(x) \\\\\n\t\t\t&= \n\t\t\t\tK(x+iy; \\lambda) + \\mathpzc R_L(x+iy; \\lambda) \n\t\t\t\t\\nonumber \\\\\n\t\tG_R(x+ iy; \\lambda)\n\t\t\t&= \n\t\t\t\tK(x+iy; \\lambda) \n\t\t\t\t- i \\big[\n\t\t\t\t\t\t\\alpha(\\lambda) + \\beta(\\lambda) e^{i\\lambda x}e^{-\\lambda y} \n\t\t\t\t\t\\big] \\chi_R(x) \\\\\n\t\t\t&= \n\t\t\t\tK(x+iy; \\lambda) - \\mathpzc R_R(x+iy; \\lambda) \n\t\t\t\t\\nonumber\n\t% G_L(x+iy; \\lambda) =\n\t% \t\\begin{cases}\n\t% \t\t-K(x+iy; \\lambda),\t\t\t\t\t\t\t\t\n\t% \t\t\t&\tx<0 \\\\\n\t% \t\ti \\left(\n\t% \t\t\t\\alpha(\\lambda) + \\beta(\\lambda) e^{i\\lam x}e^{-y\\lam} \n\t% \t\t\\right)\n\t% \t\t- K(x+iy; \\lambda), \n\t% \t\t\t& x>0\t\\\\\n\t% \t\\end{cases}\n\\end{align}\n\\end{subequations}\nHere\n\\begin{equation}\n\t\\label{eq3:ILW.K.z}\n\tK(x + iy; \\lambda) \n\t\t\t\t:= \\frac{e^{-\\pi|x|} \\exp\\big(- i \\pi y \\sign(x)  \\big)}{2\\pi} \n\t\t\t\t\t\\int_{\\mathbb R} e^{i x \\xi} \n\t\t\t\t\t\t\\frac{e^{-y\\xi}}{p(\\xi; \\lambda) + i \\pi \\sign(x)}\n\t\t\t\t\t\\, \\mathrm{d}\\xi\n\\end{equation}\nis defined by a convergent integral for $y \\in (0,2)$, so that $K(x+iy)$ is actually \na bounded continuous function. We can now study boundary values for the convolution of \n$G_L(\\dotarg+iy)$ with a function on the line as $y \\nearrow 2$.  Note that\n\\[\n\tK(x + iy; \\lambda)\n\t\t= \\frac{1}{2 \\pi} \\int\\limits_{\\Sigma_{\\sign(x)}} \\frac{e^{i(x + iy) \\xi}}{p(\\xi)} \\, \\mathrm{d}\\xi,\n\\]\nwhere $\\Sigma_{\\sign(x)}$ is the contour defined at the beginning of Subsection \\ref{sec1:AsympK},\nas \n\\[\n\ti(x + iy)\\big(\\xi + i \\pi \\sign(x) \\big)\n\t\t= \\big( i x \\xi - y \\xi\\big) \n\t\t\t+ \\big( -\\pi x \\sign(x) - i \\pi y \\sign(x) \\big).\n\\]\n\n%%\n%% End verbatum stealing from Prof. Perry's notes. \n%% Begin partial thievery of Prof. Perry's notes.\nIn our analysis of this limit, we first claim that for any $f \\in L^1 \\cap L^p$ \n($1 < p \\leq 2$), we can rewrite the convolutions $G_\\star*f$ as \n\\begin{subequations}\n\t\\label{eq3:ILW.(GFz*f)}\n\t\\begin{align}\n\t\t\\label{eq3:ILW.(GLz*f)}\n\t\t\\big(G_L(\\dotarg + iy)*f\\big)(x) \n\t\t\t&= i\\alpha(\\lambda) \\int_{-\\infty}^x f(x') \\, \\mathrm{d}x' \\\\\n\t\t    &\\quad + i\\beta(\\lambda) \\, e^{i\\lam x}e^{-\\lam y} \n\t\t    \t\t\\int_{-\\infty}^x e^{-i\\lam x'} f(x')\\, \\mathrm{d}x' \n\t\t    \t\\nonumber \\\\\n\t\t    &\\quad +\\int_{\\mathbb R} \\mathfrak C(x-x',y) f(x') \\, \\mathrm{d}x' \n\t\t\t\t\\nonumber \\\\\n\t\t\t&\\quad + \\frac{e^{-i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_{-\\infty}^x e^{-\\pi|x-x'|} \\frac{1}{(x-x') - i(2-y)} f(x') \\, \\mathrm{d}x'\n\t\t\t\t\\nonumber  \\\\\n\t\t\t&\\quad + \\frac{e^{i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_x^{\\infty} e^{-\\pi|x-x'|} \\frac{1}{(x-x') - i(2-y)} f(x') \\, \\mathrm{d}x'\n\t\t\t\t\\nonumber \\\\[0.5\\baselineskip]\n\t\t\\label{eq3:ILW.(GLz*f)}\n\t\t\\big(G_R(\\dotarg + iy)*f\\big)(x) \n\t\t\t&= i\\alpha(\\lambda) \\int_{-\\infty}^x f(x') \\, \\mathrm{d}x' \\\\\n\t\t    &\\quad + i\\beta(\\lambda) \\, e^{i\\lam x}e^{-\\lam y} \n\t\t    \t\t\\int_{-\\infty}^x e^{-i\\lam x'} f(x')\\, \\mathrm{d}x' \n\t\t    \t\\nonumber \\\\\n\t\t    &\\quad +\\int_{\\mathbb R} \\mathfrak C(x-x',y) f(x') \\, \\mathrm{d}x' \n\t\t\t\t\\nonumber \\\\\n\t\t\t&\\quad + \\frac{e^{-i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_{-\\infty}^x e^{-\\pi|x-x'|} \\frac{1}{(x-x') - i(2-y)} f(x') \\, \\mathrm{d}x'\n\t\t\t\t\\nonumber  \\\\\n\t\t\t&\\quad + \\frac{e^{i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_x^{\\infty} e^{-\\pi|x-x'|} \\frac{1}{(x-x') - i(2-y)} f(x') \\, \\mathrm{d}x'\n\t\t\t\t\\nonumber\n\t\\end{align}\n\\end{subequations}\nwhere $\\mathfrak C$ is as defined in equations \\eqref{eq3:GFcont} and \\eqref{eq0:smallR} above.\nIndeed, one can see directly from \\eqref{eq3:ILW.GFz.rep} \n\\begin{align*}\n\t\\big(G_L(\\dotarg + iy)*f\\big)(x) \n\t\t&= \\big(K(\\dotarg + iy) * f\\big)(x) + \\mathpzc R_L(\\dotarg + iy) * f \\\\\n\t\\big(G_R(\\dotarg + iy)*f\\big)(x) \n\t\t&= \\big(K(\\dotarg + iy) * f\\big)(x) + \\mathpzc R_R(\\dotarg + iy) * f.\n\\end{align*}\nFurther, since \n\\begin{align*}\n\t\\big(K(\\dotarg + iy) * f\\big)(x)\n\t\t&= \n\t\t\t\\frac{e^{-i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_{-\\infty}^x \n\t\t\t\t\t\\left(\n\t\t\t\t\t\te^{-\\pi |x - x'|} \n\t\t\t\t\t\t\\int_{\\mathbb R}\n\t\t\t\t\t\t\te^{ix\\xi} \\frac{e^{-y\\xi}}{p(\\xi;\\lambda) + i\\pi}\n\t\t\t\t\t\t\\, \\mathrm{d}\\xi\n\t\t\t\t\t\\right)\n\t\t\t\tf(x')\n\t\t\t\t\\, \\mathrm{d}x' \\\\\n\t\t&\\quad+\n\t\t\t\\frac{e^{i \\pi y}}{2 \\pi i} \n\t\t\t\t\\int_x^{\\infty}\n\t\t\t\t\t\\left(\n\t\t\t\t\t\te^{-\\pi |x - x'|} \n\t\t\t\t\t\t\\int_{\\mathbb R}\n\t\t\t\t\t\t\te^{ix\\xi} \\frac{e^{-y\\xi}}{p(\\xi;\\lambda) - i\\pi}\n\t\t\t\t\t\t\\, \\mathrm{d}\\xi\n\t\t\t\t\t\\right)\n\t\t\t\tf(x')\n\t\t\t\t\\, \\mathrm{d}x' \\\\\n\\end{align*}\nthe identity\n\\begin{align}\\label{eq3:RanId}\n\t\\frac{e^{-y \\xi}}{p(\\xi , \\lambda) \\pm i \\pi} \n\t\t= \\frac{1}{\\zeta(\\lambda)} e^{(2-y)\\xi} \\chi_{\\mathbb R^-}(\\xi) \n\t\t\t+ \\rho \\big(\\xi, y, \\pm 1; \\lambda\\big),\n\\end{align}\nwhere $\\chi_{\\mathbb R^-}$ denotes the characteristic function of $(-\\infty, 0)$, along with the\nFourier identity\n\\[\n\t\\int_{\\mathbb R} \n\t\te^{i x \\xi} \\frac{1}{\\zeta(\\lambda)} e^{(2-y)\\xi} \\chi_{\\mathbb R^-}(\\xi)\n\t\\, \\mathrm{d}\\xi\n\t= \n\t\t\\frac{1}{ix + (2-y)}\n\\]\nimply equations \\eqref{eq3:ILW.(GFz*f)} hold. \n\n\nTo verify identity \\eqref{eq3:RanId} note that \n\\begin{align*}\n\t\\zeta \n\t\t&= \\big(-\\zeta + \\zeta \\, e^{-2\\xi} + \\zeta) e^{2\\xi} \\\\\n\t\t&= \n\t\t\t\\big[\n\t\t\t\t\\xi - \\zeta\\big(1-e^{-2\\xi}\\big) \n\t\t\t\t\\pm i \\pi - \\xi \\mp i \\pi \n\t\t\t\\big]\n\t\t\te^{2\\xi},\n\\end{align*}\nwhich implies \n\\begin{align*}\n\t&\\frac{1}{\\zeta} e^{(2-y)\\xi} \n\t\t\t+ \\frac{1}{\\zeta}\n\t\t\t\t\\frac{\n\t\t\t\t\t\\big(\\zeta - \\xi \\mp i\\pi\\big)e^{(2-y)\\xi}\n\t\t\t\t}\n\t\t\t\t{\\xi-\\zeta(1-e^{2\\xi}) \\pm i \\pi}  \\\\\n\t&\\qquad= \n\t\t\\frac{1}{\\zeta} \n\t\t\\Big\\{\n\t\t\t\\big[\n\t\t\t\t\\xi - \\zeta\\big(1-e^{-2\\xi}\\big) \n\t\t\t\t\\pm i \\pi - \\xi \\mp i \\pi \n\t\t\t\\big]\n\t\t\te^{2\\xi}\n\t\t\\Big\\}\n\t\t\\frac{e^{-y\\xi}}{p(\\xi; \\lambda) \\pm i \\pi} \\\\\n\t&\\qquad= \\frac{e^{-y\\xi}}{p(\\xi; \\lambda) \\pm i \\pi},\n\\end{align*}\nas claimed.\n\n\nBy introducing the notation\\label{sym:almostExpCauchy}\n\\begin{align*}\n\t\\left( \\mathcal E_\\varepsilon f \\right)(x) \n\t\t&:=  \\frac{e^{-i \\pi (2-\\varepsilon)}}{2 \\pi i} \n\t\t\t\\int_{-\\infty}^x \n\t\t\t\t\\frac{e^{-\\pi|x-x'|}}{(x-x') - i\\varepsilon} f(x') \n\t\t\t\\, \\mathrm{d}x' \\\\\n\t\t&\\quad + \\frac{e^{i \\pi (2-\\varepsilon)}}{2 \\pi i} \n\t\t\t\\int_x^{\\infty} \n\t\t\t\t\\frac{e^{-\\pi|x-x'|} }{(x-x') - i\\varepsilon} f(x') \n\t\t\t\\, \\mathrm{d}x',\n\\end{align*}\nequation \\eqref{eq3:ILW.(GFz*f)} can be rewritten more simply as \n\\begin{subequations}\n\t\\label{eq3:ILW.(Gz*f).simp}\n\t\\begin{align}\n\t\t\\label{eq3:ILW.(GLz*f).simp}\n\t\t\\big(G_L(\\dotarg + iy)*f\\big)(x) \n\t\t\t&= \\big[\\mathfrak C(\\dotarg, y) + \\mathpzc R_L(\\dotarg+iy)\\big] * f(x) \n\t\t\t\t+ \\mathcal E_{(2-y)} f(x)\n\t\t\t\\\\\n\t\t\\label{eq3:ILW.(GRz*f).simp}\n\t\t\\big(G_R(\\dotarg + iy)*f\\big)(x) \n\t\t\t&= \\big[\\mathfrak C(\\dotarg, y) - \\mathpzc R_R(\\dotarg+iy) \\big] * f(x) \n\t\t\t\t+ \\mathcal E_{(2-y)} f(x)\n\t\\end{align}\n\\end{subequations}\nSince the integrands of the residue terms\n\\begin{align*}\n\t\\mathpzc R_L(\\dotarg+iy)*f(x)\n\t\t&= i\\alpha \\int_{-\\infty}^x f(x') \\, \\mathrm{d}x' \n\t\t       + i\\beta(\\lambda) \\, e^{\\lambda(ix - y)}\n\t\t    \t\t\\int_{-\\infty}^x e^{-i\\lam x'} f(x')\\, \\mathrm{d}x' \\\\\n\t\\mathpzc R_R(\\dotarg+iy)*f(x)\n\t\t&=  i\\alpha \\int_{-\\infty}^x f(x') \\, \\mathrm{d}x' \n\t\t       + i\\beta(\\lambda) \\, e^{\\lambda(ix - y)}\n\t\t    \t\t\\int_x^{\\infty} e^{-i\\lam x'} f(x')\\, \\mathrm{d}x' \n\\end{align*}\nin \\eqref{eq3:ILW.(Gz*f).simp} do not involve $y$, they are certainly well behaved \nunder the limit $y \\nearrow 2$. Further, the purpose of decomposing the convolution\noperator $G_L$ as shown in \\eqref{eq3:ILW.(Gz*f).simp} is to isolate the singularity that \nresults under the limit $y \\nearrow 2$. Indeed, a cursory inspection of the\nconvolution operator $\\mathfrak C$ leads one to believe that it is well behaved under \nthis limit, which \nis something we discuss further in Section \\ref{sec3:ContPart}.\n\nThe $\\mathcal E_{(2-y)} f(x)$ terms in \\eqref{eq3:ILW.(Gz*f).simp} captures the singular \nportion of $K$ under the $y\\nearrow 2$ limit. Understanding the behavior of these terms \nunder this limit involves much more delicate analysis and is the subject of Sections \n\\ref{sec3:CauchyTrans} and \\ref{sec3:BndE}. \n\n\\begin{rmk}\n\tThat $\\mathpzc R_\\star$ grows linearly for $\\lambda = 0$ is the single reason\n\twhy we can only guarantee the limit \\eqref{eq3:lim} converges as an $L^p$ limit \n\tfor functions with sufficient decay (\\textit{i.e.} $L^{p,1}$) and not for all\n\t$L^p$ functions when $\\lambda = 0$.\n\\end{rmk}\n\n\\end{document}", "meta": {"hexsha": "95c0133193422e56747bf4664c9c30cbc1422090", "size": 11142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter3-xContin/3.1-Analyticity.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": "Chapter3-xContin/3.1-Analyticity.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": "Chapter3-xContin/3.1-Analyticity.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": 36.7722772277, "max_line_length": 102, "alphanum_fraction": 0.5793394364, "num_tokens": 4643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6076142600755875}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 3.2 Riemann tensor from commutation of $\\nabla$}\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   \\nabla{#}::Derivative.\n   \\partial{#}::PartialDerivative.\n\n   \\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2});\n\n   # rules for the first two covariant derivs of V^a\n\n   deriv1 := \\nabla_{a}{V^{b}} -> \\partial_{a}{V^{b}}\n                                + \\Gamma^{b}_{d a} V^{d}.          # cdb (ex-0302.101,deriv1)\n\n   deriv2 := \\nabla_{a}{\\nabla_{b}{V^{c}}} -> \\partial_{a}{\\nabla_{b}{V^{c}}}\n                                            + \\Gamma^{c}_{d a} \\nabla_{b}{V^{d}}\n                                            - \\Gamma^{d}_{b a} \\nabla_{d}{V^{c}}.\n                                                                   # cdb (ex-0302.102,deriv2)\n\n   Vabc :=   \\nabla_{c}{\\nabla_{b}{V^{a}}}\n           - \\nabla_{b}{\\nabla_{c}{V^{a}}}.                        # cdb (ex-0302.103, Vabc)\n\n   substitute (Vabc,deriv2)                                        # cdb (ex-0302.104, Vabc)\n   substitute (Vabc,deriv1)                                        # cdb (ex-0302.105, Vabc)\n\n   distribute     (Vabc)                                           # cdb (ex-0302.106, Vabc)\n   product_rule   (Vabc)                                           # cdb (ex-0302.107, Vabc)\n\n   sort_product   (Vabc)                                           # cdb (ex-0302.108, Vabc)\n   rename_dummies (Vabc)                                           # cdb (ex-0302.109, Vabc)\n   canonicalise   (Vabc)                                           # cdb (ex-0302.110, Vabc)\n   factor_out     (Vabc,$V^{a?}$)                                  # cdb (ex-0302.111, Vabc)\n\\end{cadabra}\n\n\\begin{dgroup*}[spread={3pt}]\n   \\Dmath*{\\cdb{ex-0302.103} = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.104}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.105}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.106}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.107}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.108}\n                             = \\Cdb*[\\hskip2.0cm\\hfill]{ex-0302.109}\n                             = \\Cdb*{ex-0302.110}\n                             = \\Cdb*{ex-0302.111}\n                             = - R^{a}{}_{dbc} V^d}\n\\end{dgroup*}\n\nThis result agrees with Misner, Thorne and Wheeler. pg. 266.\n\\end{document}\n", "meta": {"hexsha": "7fc0d86bc3de0730c361c7ea05ba2dde58314931", "size": 2627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0302.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-0302.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-0302.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": 45.2931034483, "max_line_length": 94, "alphanum_fraction": 0.4130186525, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6075952066225022}}
{"text": "\n\\subsection{Loops, multiple edges and simple graphs}\n\n\\subsubsection{Loops}\n\nA loop is an edge where both the vertices are the same.\n\n\\subsubsection{Multiple edges}\n\nIf there are two edges with the same pair of indices, there are multiple edges.\n\n\\subsubsection{Simple graphs}\n\nNo loops or multiple edges.\n\n", "meta": {"hexsha": "77e167349931b208cbca01d7f563983f46974164", "size": 308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/graph/01-04-simple.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/graph/01-04-simple.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/graph/01-04-simple.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.25, "max_line_length": 79, "alphanum_fraction": 0.7792207792, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6075952039278345}}
{"text": "\\section{Bonus lectures}\r\nWe have $n$ bins $1,2,\\ldots,n$ and $n$ indistinguishable balls.\r\nFor every ball, we pick a bin uniformly randomly and place it independently of other balls.\r\nLet $X_i$ be the number of balls in bin $i$.\r\nDefine the maximum load to be $M_n=\\max_{i\\le n}X_i$.\r\nNow for every $i$, $X_i\\sim\\operatorname{Bin}(n,1/n)$.\r\nWe first want to find heuristically the value of $\\mathbb P(M_n\\ge x)$.\r\nNote that we have $\\mathbb P(M_n\\ge x)\\le n\\mathbb P(X_1\\ge x)$.\r\nThis is quite strict but works in this case.\r\nNow for large $n$, we approximate $X_1$ by $\\operatorname{Pois}(1)$, so we can estimate (by something proved in example sheet) by $\\mathbb P(\\operatorname{Pois}(\\lambda)\\ge x)\\le\\exp(-x\\log(x/\\lambda)-\\lambda+x)$, so\r\n$$\\mathbb P(M_n\\ge x)\\le n\\mathbb P(X_1\\ge x)\\approx n\\mathbb P(\\operatorname{Pois}(1)\\ge x)\\le \\exp(-x\\log(x)-1+x)$$\r\nSo for $\\mathbb P(M_n\\ge x)\\to 0$, we need $x=(1+\\epsilon)\\log n/\\log\\log n$.\r\n\\begin{theorem}\r\n    We have\r\n    $$\\frac{M_n}{\\log n/\\log\\log n}\\xrightarrow{\\mathbb P}1$$\r\n    as $n\\to\\infty$.\r\n\\end{theorem}\r\nLet $N\\sim\\operatorname{Pois}(\\lambda)$ and let $X=\\sum_{k=1}^N\\xi_k$ where $\\xi_k\\sim\\operatorname{Bern}(p)$, then $X\\sim\\operatorname{Pois}(\\lambda p)$ and $N-X\\sim\\operatorname{Pois}(\\lambda(1-p))$ and $X,N-X$ are independent, so\r\n$$\\mathbb P(X=x,N-X=y)=e^{-\\lambda}\\frac{\\lambda^{x+y}}{(x+y)!}\\binom{x+y}{x}p^x(1-p)^y$$\r\nWe cast a method called Poissonization.\r\n\\begin{proof}\r\n    Suppose we throw $\\operatorname{Pois}(n(1+\\epsilon))$ balls instead and let $Y_i$ be the load of bin $i$, then $Y_i\\sim\\operatorname{Pois}(1+\\epsilon)$ are i.i.d..\r\n    Set $\\tilde{M}_n=\\max_{i\\le n}Y_i$, then\r\n    \\begin{align*}\r\n        \\mathbb P(M_n\\ge x)&\\le\\mathbb P(\\tilde{M}_n\\ge x,\\operatorname{Pois}(n(1+\\epsilon))\\ge n)+\\mathbb P(\\operatorname{Pois}(n(1+\\epsilon))<n)\\\\\r\n        &\\le\\mathbb P(\\tilde{M}_n\\ge x)+\\mathbb P(\\operatorname{Pois}(n(1+\\epsilon))<n)\\\\\r\n        &\\le\\mathbb P(\\tilde{M}_n\\ge x)+\\exp(n\\log (1+\\epsilon)-\\epsilon n)\\\\\r\n        &\\le\\mathbb P(\\tilde{M}_n\\ge x)+\\exp\\left( -\\frac{n\\epsilon^2}{10} \\right)\r\n    \\end{align*}\r\n    for $\\epsilon\\in(0,1)$.\r\n    Hence\r\n    $$\\mathbb P\\left(M_n\\ge(1+\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)\\le\\mathbb P\\left(\\tilde{M}_n\\ge(1+\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)+\\exp\\left( -\\frac{n\\epsilon^2}{10} \\right)$$\r\n    Note that $\\exp(-n\\epsilon^2/10)\\to 0$ as $n\\to\\infty$.\r\n    Now\r\n    $$P\\left(\\tilde{M}_n\\ge(1+\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)\\le n\\mathbb P\\left( Y_1\\ge (1+\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)$$\r\n    which is bounded by\r\n    $$n\\exp\\left( -(1+\\epsilon)\\frac{\\log n}{\\log\\log n}\\log\\left( \\frac{\\log n}{\\log\\log n} \\right)-(1+\\epsilon)+(1+\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)$$\r\n    which is at most\r\n    $$n\\exp\\left( -(1+\\epsilon)\\log n+10\\frac{\\log n\\log\\log\\log n}{\\log\\log n} \\right)\\to 0$$\r\n    as $n\\to\\infty$, hence\r\n    $$\\lim_{n\\to\\infty}\\mathbb P\\left(M_n\\ge(1+\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)\\to 0$$\r\n    which establishes the upper bound.\\\\\r\n    For the lower bound, we need to show that for all $\\epsilon\\in(0,1)$, we have\r\n    $$\\lim_{n\\to\\infty}\\mathbb P\\left( M_n\\le(1-\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)\\to 0$$\r\n    Note first that $\\mathbb P(\\operatorname{Pois}(n(1-\\epsilon))>n)\\le e^{-n\\epsilon^2/10}$, so\r\n    $$\\mathbb P\\left( M_n\\le(1-\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)\\le e^{-n\\epsilon^2/10}+\\mathbb P\\left( \\tilde{M}_n\\le(1-\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)$$\r\n    where $\\tilde{M}_n=\\max_{i\\le n}\\tilde{Y}_i$ with $\\tilde{Y}_i$ are i.i.d. $\\operatorname{Pois}(1-\\epsilon)$.\r\n    So\r\n    $$P\\left( \\tilde{M}_n\\le(1-\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)=P\\left( \\tilde{Y}_1\\le(1-\\epsilon)\\frac{\\log n}{\\log\\log n} \\right)^n$$\r\n    Now we have\r\n    $$P\\left( \\tilde{Y}_1\\ge(1-\\epsilon)\\frac{\\log n}{\\log\\log n}\\right)\\ge e^{-(1-\\epsilon)}\\frac{(1-\\epsilon)^M}{M!},M=(1-\\epsilon)\\frac{\\log n}{\\log\\log n}$$\r\n    Hence\r\n    \\begin{align*}\r\n        \\mathbb P(\\tilde{M}_n<M)\\le\\left( 1-e^{-(1-\\epsilon)}\\frac{(1-\\epsilon)^M}{M!} \\right)^n\\\\\r\n        \\le\\exp\\left(-ne^{-(1-\\epsilon)}\\frac{(1-\\epsilon)^M}{M!}\\right)\r\n    \\end{align*}\r\n    Now $M!\\le M(M/e)^M$ for large enough $M$, so we (finally!) get $\\mathbb P(\\tilde{M}_n<M)=o(1)$, whcih establishes the result.\r\n\\end{proof}\r\nThrow $n$ balls into $n$ bins.\r\nEvery time, we pick $d\\ge 2$ bins at random and place the ball in the least loaded bin.\r\n\\begin{theorem}\r\n    After all balls have been placed, the maximum load is\r\n    $$\\frac{\\log\\log n}{\\log d}+O(1)$$\r\n    with probability $1-o(1)$.\r\n\\end{theorem}\r\nWe will use the Chernoff inequality for binomials, i.e.\r\n$$\\mathbb P(\\operatorname{Bin}(n,p)\\ge 2np)\\le e^{-np/3}$$\r\nThe height of the ball is the number of balls already placed in the bin it is placed $+1$.\r\nLet $\\nu_i$ be the number of bins with load $\\ge i$ and $\\mu_i$ is the number of bins with height $\\ge i$, then $\\nu_i\\le \\mu_i$.\r\nThe idea is that we want to define a sequence $\\beta_i$ such that $\\nu_i\\le\\beta_i$ with high probability for all $i\\le i^\\star$ where $i^\\star$ is to be determined and we will show that $i^\\star=\\log\\log n/\\log d$.\r\nThen at this time, $\\beta_{i^\\star}$ will have order $n$ and we can finish the proof easily from there.\r\nSuppose we condition on $\\nu_i\\le\\beta_i$, then the probability that a ball has height at least $i+1$ is bounded by $(\\beta_i/n)^d$ since all of the $d$ choices have to come from bins with load $\\ge i$, so\r\n$$\\mathbb P(\\nu_{i+1}>k)\\le\\mathbb P(\\operatorname{Bin}(n,(\\beta_i/n)^d))$$\r\n\\begin{lemma}\r\n    Let $X_1,\\ldots$ be a sequence of random variables and let $Y_i$ be a function of $X_1,\\ldots,X_i$ that takes values in $\\{0,1\\}$.\r\n    If $\\mathbb P(Y_i=1|X_1,\\ldots,X_{i-1})\\le p$, then\r\n    $$\\mathbb P\\left( \\sum_{i=1}^nY_i>k \\right)\\le\\mathbb P(\\operatorname{Bin}(n,p)>k)$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Each $Y_i$ is upper bounded by $\\operatorname{Bern}(p)$.\r\n    And for the sum we use induction.\r\n\\end{proof}\r\n\\begin{proof}[Proof of the Theorem]\r\n    Let $\\nu_i(t)$ be the number of bins with load $\\ge i$ at time $t$ (after the $t^{th}$ ball is placed).\r\n    Let $\\mu_i(t)$ be the number of balls with height $\\ge i$ at time $t$.\r\n    Write $\\nu_i(n)=\\nu_i$ and $\\mu_i(n)=\\mu_i$, so $\\nu_i(t)\\le\\mu_i(t)$ for any $i,t$.\r\n    Now we want to find a sequence $\\beta_i$ with $\\nu_i\\le\\beta_i$ for $i< i^\\star$ with high probability.\r\n    Let $\\beta_4=n/4$ and $\\beta_{i+1}=2n(\\beta_i/n)^d$.\r\n    Define $E_i=\\{\\nu_i\\le\\beta_i\\}$, so $\\mathbb P(E_4)=1$.\r\n    Now we want to show that for all $4\\le i<i^\\star$ where $i^\\star$ is to be determined, we have $\\mathbb P(E_{i=1}^c)\\le\\mathbb P(E_i^c)+1/n^2$.\r\n    Define a sequence of binomial variables $Y_t=1_{h(t)\\ge i+1,\\nu_{i-1}\\le\\beta_i}$.\r\n    Let $\\omega_j$ be bins selected by the $j^{th}$ ball.\r\n    Now\r\n    $$\\mathbb P(Y_t=1|\\omega_1,\\ldots,\\omega_{t-1})\\le\\left( \\frac{\\beta_i}{n} \\right)^d=p_i$$\r\n    So by the preceding lemma, for any $k$,\r\n    $$\\mathbb P\\left( \\sum_{t=1}^nY_t>k \\right)\\le\\mathbb P(\\operatorname{Bin}(n,p)>k)$$\r\n    So\r\n    $$\\mathbb P(E_{i+1}^c|E_i)=\\mathbb P(\\nu_{i+1}\\ge\\beta_{i+1}|E_i)\\le\\mathbb P(\\mu_{i+1}>\\beta_{i+1}|E_i)$$\r\n    Conditioned on $E_i$, $Y_t=1_{h(t)\\ge i+1}$, so $\\sum_{t=1}^nY_t=\\mu_{i+1}$, so\r\n    \\begin{align*}\r\n        \\mathbb P(\\mu_{i+1}>\\beta_{i+1}|E_i)&=\\mathbb P\\left( \\sum_{t=1}^nY_t>\\beta_{i+1}\\middle|E_i \\right)\\\\\r\n        &=\\frac{1}{\\mathbb P(E_i)}\\mathbb P\\left( \\sum_{t=1}^nY_t>\\beta_{i+1},E_i \\right)\\\\\r\n        &\\le\\frac{1}{\\mathbb P(E_i)}\\mathbb P\\left( \\sum_{t=1}^nY_t>\\beta_{i+1}\\right)\\\\\r\n        &\\le\\frac{1}{\\mathbb P(E_i)}\\mathbb P(\\operatorname{Bin}(n,p_i)>\\beta_{i+1})\\\\\r\n        &\\le\\frac{e^{-np_i/3}}{\\mathbb P(E_i)}\r\n    \\end{align*}\r\n    Note that for any $i$ with $np_i\\ge 6\\log n$ we have\r\n    $$\\mathbb P(E_{i+1}^c|E_i)\\le\\frac{1}{n^2\\mathbb P(E_i)}\\implies\\mathbb P(E_{i+1}^c)\\le\\frac{1}{n^2}+\\mathbb P(E_i^c)$$\r\n    Let $i^\\star$ be the first $i$ such that $np_i<6\\log n$.\r\n    Now we claim that\r\n    $$i^\\star=\\log\\log n/\\log d+O(1)$$\r\n    It suffices to show by induction that\r\n    $$\\beta_{i+4}=\\frac{n}{2^{2d^i}-\\sum_{j=0}^{i-1}d^j}$$\r\n    Once we know that, we get $\\beta_{i+4}\\le n/2^{d^i}$, so $\\mathbb P(E_{i^\\star}^c)\\le i^\\star/n^2$, so $\\beta_{i^\\star+i}=2np_{i^\\star}\\le 2n(6\\log n/n)=12\\log n$\r\n    Now\r\n    \r\n    \\begin{align*}\r\n        \\mathbb P(\\nu_{i^\\star+1}>18\\log n|E_{i^\\star})&\\le\\mathbb P(\\nu_{i^\\star+1}>18\\log n|E_{i^\\star})\\\\\r\n        &\\le\\frac{\\mathbb P(\\operatorname{Bin}(n,6\\log n/n^2)>18\\log n)}{\\mathbb P(E_{i^\\star})}\\\\\r\n        &\\le e^{-2\\log n}/\\mathbb P(E_{i^\\star})\\\\\r\n        &=\\frac{1}{n^2\\mathbb P(E_{i^\\star})}\r\n    \\end{align*}\r\n    So\r\n    $$\\mathbb P(\\nu_{i^\\star+1}\\ge 18\\log n)\\le\\frac{1}{n^2}+\\mathbb P(E_{i^\\star}^c)\\le\\frac{i^\\star+1}{n^2}$$\r\n    Now $\\{\\nu_{i^\\star+1}\\ge 1\\}\\subset\\{\\mu_{i^\\star+1}\\ge 1\\}\\subset\\{\\mu_{i^\\star+2}\\ge 2\\}$.\r\n    \\begin{align*}\r\n        \\mathbb P(\\mu_{i^\\star+1}\\ge 2|\\nu_{i^\\star+1}<18\\log n)&\\le\\mathbb P(\\operatorname{Bin}(n,(8\\log n/n)^d)\\ge 2)/\\mathbb P(\\nu_{i^\\star+1}<18\\log n)\\\\\r\n        &\\le\\binom{n}{2}\\left( \\frac{18\\log n}{n} \\right)^{2d}+\\frac{i^\\star+1}{n^2}\\\\\r\n        &\\le\\frac{n^2}{n^{2d}}(18\\log n)^{2d}+\\frac{i^\\star+1}{n^2}\\\\\r\n        &=o(1/n)\r\n    \\end{align*}\r\n    and this shows what we wanted.\r\n\\end{proof}", "meta": {"hexsha": "8721c87bb310f2c62832dc04ae699b0b7b2a5d22", "size": 9311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16/bonus.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": "16/bonus.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": "16/bonus.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": 70.007518797, "max_line_length": 233, "alphanum_fraction": 0.6069165503, "num_tokens": 3769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6075952000158714}}
{"text": "\\subsection{Variation of Parameters}\r\n\\noindent\r\nAlthough the method of undetermined coefficients is useful and relatively quick because it is algebra-based, it cannot solve many equations, even simple-looking second order equations, like\r\n\\begin{equation*}\r\n\ty'' + y = \\csc{x}\r\n\\end{equation*}\r\nThe method also requires guessing, meaning for very complicated forms of $b(x)$, things can get very messy.\\\\\r\n\r\n\\noindent\r\nInstead, we'll look at a more rigorous, calculus-based, approach developed by Lagrange called \"variation of parameters\". We'll first see how to apply the method to 2nd order linear ODEs with constant coefficients, like forced vibrations, and then we'll extend with method to order $n$.\r\n\r\n\\input{./higherOrder/nonHomeg/variationParameters_secondOrder.tex}\r\n\\input{./higherOrder/nonHomeg/variationParameters_higherOrder.tex}", "meta": {"hexsha": "50ca12e47e9d4e6d31341c2a6765786f6425531e", "size": 843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters.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/nonHomeg/variationParameters.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/nonHomeg/variationParameters.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": 64.8461538462, "max_line_length": 286, "alphanum_fraction": 0.7864768683, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6075951934092405}}
{"text": "\\chapter{Product of funcoids over a filter}\n\nThe following definition is inspired by the usual definition of Tychonoff\nproduct of topological spaces.\n\n\\begin{defn}\n  Let $f$ be an indexed family of funcoids. Let $\\mathcal{F}$ be a filter on\n  $\\dom f$.\n  \\[ a \\mathrel{\\left[ \\prod^{[\\mathcal{F}]} f \\right]} b \\Leftrightarrow\n     \\exists N \\in \\mathcal{F} \\forall i \\in N : \\Pr^{\\mathsf{RLD}}_i a\n     \\suprel{f_i} \\Pr^{\\mathsf{RLD}}_i b \\]\n  for atomic reloids $a$ and $b$.\n\\end{defn}\n\n\\begin{rem}\n  We are especially interested in the special case when $\\mathcal{F}$ is the\n  cofinite filter. In this case $a \\mathrel{\\left[ \\prod^{[\\mathcal{F}]} f\n  \\right]} b$ is defined by the condition that $\\Pr^{\\mathsf{RLD}}_i a\n  \\suprel{f_i} \\Pr^{\\mathsf{RLD}}_i $ for an infinite number of\n  indexes $i$.\n\\end{rem}\n\n\\begin{obvious}\n$a \\mathrel{\\left[ \\prod^{\\suprel{ \\top^{\\mathscr{F} (\\dom f)} }} f\n\\right]} b \\Leftrightarrow a \\mathrel{\\left[ \\prod^{(A)} f \\right]} b$.\n\\end{obvious}\n\n\\begin{prop}\n  $\\neg \\left( \\mathcal{X} \\suprel{f} \\mathcal{Y} \\right)$ implies $\\neg\n  \\left( X \\suprel{f} Y \\right)$ for some $X \\in \\up \\mathcal{X}$, $Y\n  \\in \\up \\mathcal{Y}$.\n\\end{prop}\n\n\\begin{proof}\n  Suppose $\\neg \\left( \\mathcal{X} \\suprel{f} \\mathcal{Y} \\right)$. Then\n  $\\mathcal{Y} \\asymp \\supfun{f} \\mathcal{X}$. Thus by separability of\n  core for filters $Y \\asymp \\supfun{f} \\mathcal{X}$ for some $Y \\in\n  \\up \\mathcal{Y}$, that is $\\neg \\left( \\mathcal{X} \\suprel{f} Y\n  \\right)$. Apply this result twice.\n\\end{proof}\n\n\\begin{lem}\n  ~  \n  \\[ \\forall X \\in \\prod_{i \\in D} \\up a_i, Y \\in \\prod_{i \\in D}\n     \\up b_i \\exists x \\in \\prod_{i \\in D} \\mathrm{atoms} \\uparrow X_i,\n     y \\in \\prod_{i \\in D} \\mathrm{atoms} \\uparrow Y_i \\exists N \\in\n     \\mathcal{F} \\forall j \\in N : x_j \\mathrel{[f_j]} y_j \\]\n  implies $\\exists N \\in \\mathcal{F} \\forall i \\in N : a_i \\suprel{f_i}\n  b_i$.\n\\end{lem}\n\n\\begin{proof}\n  Suppose for the contrary $\\neg \\left( a_i \\suprel{f_i} b_i \\right)$ for\n  all $i \\in N$ where $N \\in \\mathcal{F}$ (i.e. for an infinite number of\n  indexes if $\\mathcal{F}$ is the cofinite filter). Then (lemma above) there\n  are $X_i \\in \\up a_i$ and $Y_i \\in \\up b_i$ such that $\\neg\n  \\left( X_i \\mathrel{[f_j]^{\\ast}} Y_i \\right)$ for $i \\in N$. Thus $\\neg\n  \\left( x_i \\suprel{f_i} y_i \\right)$ for $i \\in N$, contrary to the\n  condition.\n\\end{proof}\n\n\\begin{prop}\n  The funcoid $\\prod^{[\\mathcal{F}]} f$ exists.\n\\end{prop}\n\n\\begin{proof}\n  We need to prove that\n  \\[ \\forall X \\in \\up a, Y \\in \\up b \\exists x \\in \\atoms\n     \\uparrow^{\\mathsf{RLD}} X, y \\in \\atoms\n     \\uparrow^{\\mathsf{RLD}} Y : x \\mathrel{\\left[ \\prod^{(A 2)} f\n     \\right]} y \\]\n  implies $a \\mathrel{\\left[ \\prod^{[\\mathcal{F}]} f \\right]} b$.\n  \n  Equivalently transforming it: \\fxwarning{More detailed proof.}\n  \n  $\\forall X \\in \\up a, Y \\in \\up b \\exists x \\in \\atoms\n  \\uparrow^{\\mathsf{RLD}} X, y \\in \\atoms\n  \\uparrow^{\\mathsf{RLD}} Y \\\\  \n  \\exists N \\in \\mathcal{F} \\forall i \\in N : \\Pr^{\\mathsf{RLD}}_i x\n  \\suprel{f_i} \\Pr^{\\mathsf{RLD}}_i y$; \\\\\n  $\\forall X \\in \\up a, Y \\in \\up b \\exists x \\in \\prod_{i \\in\n  \\dom f} \\atoms \\uparrow^{\\mathsf{RLD}} X_i, y \\in\n  \\prod_{i \\in \\dom f} \\atoms \\uparrow^{\\mathsf{RLD}} Y_i \\\\  \n  \\exists N \\in \\mathcal{F} \\forall i \\in N : x_i \\suprel{f_i} y_i$;\n\n  \\[ \\forall X \\in \\prod_{i \\in D} \\up a_i, Y \\in \\prod_{i \\in D}\n     \\up b_i \\exists x \\in \\prod_{i \\in D} \\mathrm{atoms} \\uparrow X_i,\n     y \\in \\prod_{i \\in D} \\mathrm{atoms} \\uparrow Y_i \\exists N \\in\n     \\mathcal{F} \\forall j \\in N : x_j \\mathrel{[f_j]} y_j \\]\n  where $D = \\dom f$.\n  \n  Thus by the lemma $\\exists N \\in \\mathcal{F} \\forall i \\in N : a_i\n  \\suprel{f_i} b_i$, that is $a \\suprel{\\prod^{[\\mathcal{F}]} f} b$.\n\\end{proof}\n\n\\fxnote{TODO: when $\\Pr_j \\prod^{[\\mathcal{F}]}_{i\\in D} a_i = a_j$?}\n\n\\section{More on product of reloids}\n\n\\fxwarning{Move this to a more appropriate place.}\n\n\\begin{defn}\n  $\\prod^{(Y)}_{i \\in \\dom f} f = \\prod^{(A)}_{i \\in \\dom f}\n  \\tofcd f$ for an indexed family~$f$ of reloids.\n\\end{defn}\n\n\\begin{prop}\n  \\[ a \\mathrel{\\left[ \\prod^{(Y)}_{i \\in \\dom f} f \\right]} b\n  \\Leftrightarrow \\forall i \\in \\dom f : f_i \\nasymp\n  \\Pr^{\\mathsf{RLD}}_i a \\times^{\\mathsf{RLD}}\n  \\Pr^{\\mathsf{RLD}}_i b. \\]\n\\end{prop}\n\n\\begin{proof}\n  $f_i \\nasymp \\Pr^{\\mathsf{RLD}}_i a \\times^{\\mathsf{FCD}} \\Pr^{\\mathsf{RLD}}_i b\n  \\Leftrightarrow \\tofcd f_i \\sqsupseteq\n  \\Pr^{\\mathsf{RLD}}_i a \\times^{\\mathsf{FCD}} \\Pr^{\\mathsf{RLD}}_i b \\Leftrightarrow\n  a \\mathrel{[\\tofcd f_i]} b$.\n\\end{proof}\n\n\\begin{example}\n  The funcoid $p$ described by the formula (for atomic reloids $a$ and $b$)\n  \\[ a \\mathrel{\\mathrel{p}} b \\Leftrightarrow \\forall i \\in \\dom f : f_i\n     \\sqsupseteq \\Pr^{\\mathsf{RLD}}_i a \\times^{\\mathsf{RLD}}\n     \\Pr^{\\mathsf{RLD}}_i b \\]\n  does not exist (in general), even if we restrict to $2$-indexed families\n  only.\n\\end{example}\n\n\\begin{proof}\n  For the case if $f = \\llbracket v , w \\rrbracket$ is a $2$-indexed family of\n  reloids, the formula which we need to disprove takes the form:\n  \\[ a \\mathrel{\\mathrel{p}} b \\Leftrightarrow v \\sqsupseteq \\dom a\n     \\times^{\\mathsf{RLD}} \\dom b \\wedge w \\sqsupseteq \\im\n     a \\times^{\\mathsf{RLD}} \\im b. \\]\n  Take $v = w = 1^{\\mathbf{Rel}}$ on an infinite set. Suppose for the\n  contrary $p$ exists and is a funcoid. Then\n  \\[ \\forall X \\in \\up a, Y \\in \\up b \\exists x \\in \\atoms\n     \\uparrow X, y \\in \\atoms \\uparrow Y : x \\mathrel{\\mathrel{p}} y \\Rightarrow\n     a \\mathrel{\\mathrel{p}} b. \\]\n  For a counter-example take $a = b$ to be a nontrivial ultrafilter. Then for\n  every $X \\in \\up a$, $Y \\in \\up b$ take $x = y$ to be singletons\n  on $X \\cap Y$. We have $x \\mathrel{\\mathrel{p}} y$, but not $a \\mathrel{\\mathrel{p}} b$.\n\\end{proof}", "meta": {"hexsha": "87a2d8aaa43ab6814de408a3479f1b7a15b3b992", "size": 5745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-prod-new.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-prod-new.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-prod-new.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "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.8958333333, "max_line_length": 90, "alphanum_fraction": 0.6205395997, "num_tokens": 2344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7217432182679957, "lm_q1q2_score": 0.6075819575961231}}
{"text": "\n%----------------------------------------------------------------------------------------\n% Quantum Mechanic's Toolbox\n%----------------------------------------------------------------------------------------\n\n\n\\chapter*{Quantum Mechanic's Toolbox}\nThis is a collection of the tools in our toolbox.\n\n%tool1\n\\ref{tool:decom} This tool is used to write a state vector in terms of a set of orthonormal basis vectors.\n\\[\n\\ket{A} = \\sum_j \\alpha_j \\ket{j},\n\\]\nwhere $\\alpha_j$ are complex numbers.\n\n%tool2\n\\ref{tool:orthog} This tool is used to collapse a sum using the inner product of two orthonormal state vectors.\n\\[\n\\avg{k|A} = \\bra{k} \\left( \\sum_j \\alpha_j \\ket{j} \\right)= \\alpha_k.\n\\]\n\n%tool3\n\\ref{tool:span} This tool is used to insert a complete set of basis vectors and project a state vector onto that basis.\n\\[\n\\sum_j \\ket{j}\\bra{j} = \\onehat \\qquad \\int_{-\\infty}^{\\infty} \\ket{\\lambda}\\bra{\\lambda} = \\onehat. \n\\]\n\n%tool4\n\\ref{tool:prob} This tool is used to calculate the probability of measuring a particular outcome of a quantum state.\n\\[\nP(\\rmt{measuring } \\ket{\\lambda}) = \\abs{\\avg{\\lambda|\\Psi}}^2 = P(a,b) = \\int\\displaylimits_a^b\\psi^{*}(x)\\psi^{}(x)dx.\n\\]\n\n%tool5\n\\ref{tool:avg} This tool is used to find the average measurement value of an operator for an input state.\n\\[\n\\avg{\\hat{L}} = \\bra{\\Psi_\\rmt{in}}\\hat{L}\\ket{\\Psi_\\rmt{in}} =  \\sum_j P(\\lambda_j)\\lambda_j = \\Tr \\oprod{\\Psi}{\\Psi}\\hat{L}.\n\\]\n\n%tool6\n\\ref{tool:eigen} This tool is used to evaluate the operation of a linear operator on one of its eigenvectors. It returns the eigenvalue and the eigenvector.\n\\[\n\\hat{L}\\ket{\\lambda} = \\lambda\\ket{\\lambda}.\n\\]\n\n%tool7\n\\ref{tool:sch} This tool is used to find the time evolution of a quantum state.\n\\[\n\\I \\hbar \\frac {d}{dt}\\ket{\\Psi} = \\hat{H}\\ket{\\Psi}\n\\]\n%tool8\n\\ref{tool:commutator} This tool is used to find the commutation relationship between two operators.\n\\[\n\\com{\\hat{A},\\hat{B}}=\\hat{A}\\hat{B} - \\hat{B}\\hat{A}\n\\]\n\n%tool9\n\\ref{tool:meunc} This tool is used to find the uncertainty in the measurement associated with an operator.\n\\[\n\\Delta L= \\left[\\avg{\\hat{L}^2} - \\avg{\\hat{L}}^2\\right]^{1/2}.\n\\]\n\n%tool10\n\\ref{tool:genuncert} This tool is used to find the uncertainty relationship between two operators.\n\\[\n\\Delta A \\Delta B \\geq \\frac{1}{2} \\abs{\\bra{\\Psi}\\com{\\hat{A},\\hat{B}}\\ket{\\Psi}}.\n\\]\n\n%tool11\n\\ref{tool:wavefunction} This tool is used to determine the continuous wavefunction in a particular basis.\n\\[\n\\psi(\\lambda) = \\avg{\\lambda|\\Psi}\\quad \\psi(x) = \\avg{x|\\Psi}\\quad \\phi(p_x) = \\avg{p_x|\\Psi} \\quad \\psi(\\vec{r}) \\equiv \\avg{\\vec{r}|\\Psi} \\quad \\phi(\\vec{p}) \\equiv \\avg{\\vec{p}|\\Psi}.\n\\]\n\n%tool12 - Fourier Transforms\n\\ref{tool:FTtool} This tool is used to transform a wavefunction back and forth from the position to the momentum bases.\n\\[\n\\begin{split}\n\\phi(p_x)= &  \\frac{1}{\\sqrt{2\\pi\\hbar}}\\int\\displaylimits_{-\\infty}^{\\infty}\\E{-\\I \\frac{p_x}{\\hbar} x} \\psi(x) dx\\\\\n\\psi(x) = &  \\frac{1}{\\sqrt{2\\pi\\hbar}}\\int\\displaylimits_{-\\infty}^{\\infty}\\E{\\I \\frac{p_x}{\\hbar} x} \\phi(p_x) dp_x.\n\\end{split}\n\\begin{split}\n\\displaystyle \\phi(\\vec{p})& = \\frac{1}{(2\\pi\\hbar)^{3/2}}\\int \\psi(\\vec{r})\\E{-\\I\\vec{p}\\cdot \\vec{r}/\\hbar}d^{3}r.\\\\\n\\displaystyle \\psi(\\vec{r}) &= \\frac{1}{(2\\pi\\hbar)^{3/2}}\\int \\phi(\\vec{p})\\E{\\I\\vec{p}\\cdot \\vec{r}/\\hbar}d^{3}p.\n\\end{split}\n\\]\n\n%tool13 - TDSWE\n\n\\ref{tool:TDSWE} This tool is used to find the time evolution of a quantum wavefunction in the position basis in a position-dependent potential.\n\\[\n\\I\\hbar \\frac{\\partial \\psi(\\vec{r},t)}{\\partial t} =-\\frac{\\hbar^2}{2m}\\vec{\\nabla}^2\\psi(\\vec{r},t) + V(\\vec{r}) \\psi(\\vec{r},t).\n\\]\n\n%tool14 - TISWE\n\\ref{tool:TISWE} This tool is used to find the energy eigenvalues for a the time-independent Schr\\\"{o}dinger equation in the position basis.\n\\[\n-\\frac{\\hbar^2}{2m}\\vec{\\nabla}^2\\psi_E(\\vec{r}) + V(\\vec{r}) \\psi_E(\\vec{r})= E \\psi_E(\\vec{r})\n\\]\n\nPath Integral\n\\[\nC_{1,2} =\\int\\displaylimits_{-\\infty}^{\\infty}\\bra{x_2} \\E{-\\I \\frac{\\hat{H}}{\\hbar} \\Delta t/2}\\ket{x}\\bra{x}\\E{-\\I \\frac{\\hat{H}}{\\hbar} \\Delta t/2}\\ket{x_1}dx.\n\\]\n\nFirst-order time-independent perturbation model\n\\[\nE_n^1 = \\bra{\\psi_n^0}\\hat{H}'\\ket{\\psi_n^0}\n\\]\n\nTime-dependent perturbation model\n\\[\n\\begin{split}\n\\dot{c}_a =& -\\frac{\\I}{\\hbar} c_b H'_{ab} \\E{-\\I\\omega_0 t} \\\\\n\\dot{c}_b =&  -\\frac{\\I}{\\hbar} c_a H'_{ba} \\E{\\I\\omega_0 t}\n\\end{split}\n\\]\n\nNumber Operators\n\\[\n\\begin{split}\n\\Ap = & \\left(\\sqrt{\\frac{m \\omega_0}{2\\hbar}}\\hat{X}+ \\frac{\\hat{P}_x }{\\I\\sqrt{2m\\hbar\\omega_0}}\\right)\\\\\n\\Am = & \\left(\\sqrt{\\frac{m \\omega_0}{2\\hbar}}\\hat{X}- \\frac{\\hat{P}_x }{\\I\\sqrt{2m\\hbar\\omega_0}}\\right)\\\\\n\\Ap\\ket{n} = & \\sqrt{n+1}\\ket{n+1}\\\\\n\\Am\\ket{n} = & \\sqrt{n}\\ket{n-1}\\\\\n\\hat{N}\\ket{n} = & \\Ap\\Am\\ket{n} = n\\ket{n},\\; n=0,1,2,\\ldots\n\\end{split}\n\\]\n\nAngular Momentum Operator\n\\[\n\\vec{L} = \\vec{r}\\times\\vec{p} \\rightarrow \\begin{aligned}\nL_x = & yp_z - zp_y\\\\\nL_y = & zp_x - xp_z\\\\\nL_z = & xp_y - yp_x\\\\\n\\end{aligned}\n\\]\n\nGeneralized Angular Momentum\n\\[\n\\begin{split}\n\\com{\\Jh_1,\\Jh_2} =& \\I\\hbar\\Jh_3\\\\\n\\com{\\Jh_2,\\Jh_3} =& \\I\\hbar\\Jh_1\\\\\n\\com{\\Jh_3,\\Jh_1} =& \\I\\hbar\\Jh_2\\\\\n\\Jh^2 = &\\Jh_1^2 + \\Jh_2^2 +\\Jh_3^2\\\\\n\\com{\\Jh^2,\\Jh_1} = & \\com{\\Jh^2,\\Jh_2} = \\com{\\Jh^2,\\Jh_3} = 0\n\\end{split}\n\\]\n\n\\[\n\\begin{split}\n\\Jh^2\\ket{jm_j} = & j(j+1)\\hbar^2\\ket{jm_j}\\\\\n\\Jh_3\\ket{jm_j} = & m_j\\hbar \\ket{jm_j} \\\\\nj =& 0,\\frac{1}{2},1,\\frac{3}{2},\\ldots \\\\ \nm_j =& -j,-j+1,-j+2,\\ldots,j-2,j-1,j\\; \\rmt{ and}\\\\\n\\Jpm\\ket{jm_j} = &\\hbar \\sqrt{j(j+1) - m_j(m_j\\pm1)} \\ket{j(m_j\\pm1)}.\n\\end{split}\n\\]\n\nSpherical Harmonics in Position Basis\n\\[\n\\Ylm(\\theta,\\phi)=\\sqrt{\\frac{(2l+1)(l-m_l)!}{4\\pi(l+m_l)!}} P_l^{m_l}(\\cos\\theta) \\E{\\I m_l\\phi}\n\\]\n\nNormalized Radial Coulomb Wavefunction\n\\[\nR_{nl}(r) = \\sqrt{\\left(\\frac{2}{n a_0}\\right)^3\\frac{(n-l-1)!}{2n\\left[(n+l)!\\right]^3}}\\E{-\\frac{r}{na_0}}\\left(\\frac{2r}{na_0}\\right)^l L_{n-l-1}^{2l+1}\\left(\\frac{2r}{na_0}\\right).\n\\]\n\n%---------------------------------\n% Useful items\n%---------------------------------\n\\subsection{Matrix Representations}\nThis is a table of the matrix representations for common states and operators.\n\\bas\n\\ket{u},\\ket{V} \\Meq & \\vket{1}{0} & \\ket{d},\\ket{H} \\Meq & \\vket{0}{1} \\nonumber\\\\\n\\ket{r},\\ket{D_R} \\Meq & \\frac{1}{\\stwo}\\vket{1}{1} & \\ket{\\ell},\\ket{D_L} \\Meq & \\frac{1}{\\stwo}\\vket{1}{-1} \\nonumber\\\\\n\\ket{i},\\ket{C_R} \\Meq & \\frac{1}{\\stwo}\\vket{1}{\\I} & \\ket{o},\\ket{C_L} \\Meq & \\frac{1}{\\stwo}\\vket{1}{-\\I} \\nonumber\\\\\n\\hat{\\sigma}_1 \\Meq &\\sxmatrix  & \\hat{S}_x \\Meq& \\frac{\\hbar}{2}\\sxmatrix \\nonumber\\\\\n\\hat{\\sigma}_2 \\Meq &\\symatrix  & \\hat{S}_y \\Meq& \\frac{\\hbar}{2}\\symatrix \\nonumber\\\\\n\\hat{\\sigma}_3 \\Meq &\\szmatrix  & \\hat{S}_z \\Meq& \\frac{\\hbar}{2}\\szmatrix \\nonumber\n\\eas\n\n\n\n\n\n%sagemathcloud={\"latex_command\":\"\"}\n", "meta": {"hexsha": "595a63e892251d2c4d4cab3d2912c41aedbb185e", "size": 6710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/toolbox.tex", "max_stars_repo_name": "madsenmj/book-quantum-mechanics", "max_stars_repo_head_hexsha": "364bd956f89122fb535582f8e4529c63ed069cec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-09-04T06:10:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-25T07:54:53.000Z", "max_issues_repo_path": "src/toolbox.tex", "max_issues_repo_name": "madsenmj/book-quantum-mechanics", "max_issues_repo_head_hexsha": "364bd956f89122fb535582f8e4529c63ed069cec", "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/toolbox.tex", "max_forks_repo_name": "madsenmj/book-quantum-mechanics", "max_forks_repo_head_hexsha": "364bd956f89122fb535582f8e4529c63ed069cec", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-04T07:58:46.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-19T20:42:53.000Z", "avg_line_length": 35.3157894737, "max_line_length": 187, "alphanum_fraction": 0.6119225037, "num_tokens": 2737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832332, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6075819439652725}}
{"text": "\\chapter{Probability Model}\\label{S:ProbModel}\n\n\\section{Experiments}\\label{S:Experiments}\n\nIdeas about chance events and random behaviour arose out of thousands of\nyears of game playing, long before any attempt was made to use\nmathematical reasoning about them. Board and dice games were well known\nin Egyptian times, and Augustus Caesar gambled with dice. Calculations\nof odds for gamblers were put on a proper theoretical basis by Fermat\nand Pascal in the early 17th century.\n\n\\begin{definition}\nAn {\\bf experiment} is an activity or procedure that produces distinct, well-defined possibilities called {\\bf outcomes}.  \nThe set  of all outcomes   is called the {\\bf sample space}, and is denoted by $\\Omega$.\n\nThe subsets of $\\Omega$ are called {\\bf events}.  \nA single outcome, $\\omega$, when seen as a subset of $\\Omega$, as in\n$\\{\\omega\\}$, is called a  {\\bf simple event}.\n\nEvents, $E_1,\\, E_2\\, \\dots \\, E_n$,  that cannot occur at the same time are called {\\bf mutually exclusive} events, or {\\bf pair-wise disjoint} events.  This means that $E_i\n\\cap E_j = \\emptyset $ where $i\\not=j$.\n\\end{definition}\n\n\n\n\\begin{example}\nSome standard examples of experiments are the following:\n\n\\bit\n\n\\item $\\Omega=\\{ {\\textsf{Defective, Non-defective}} \\}$ if our\n  experiment is to inspect a light bulb.\n\nThere are only two outcomes here, so   $\\Omega = \\{ \\omega_1, \\omega_2\\}$\nwhere $\\omega_1= {\\textsf{Defective}}$ and  $\\omega_2 =\n{\\textsf{Non-defective}}$.\n\n\n\\item $\\Omega=\\{ {\\textsf{Heads, Tails}} \\}$ if our experiment is to\n  note the outcome of a coin toss.\n\n\nThis time, $\\Omega=\\{ \\omega_1, \\omega_2\\}$ where $\\omega_1= {\\textsf{Heads}}$ and  $\\omega_2 = {\\textsf{Tails}}$.\n\n\n\\item If our experiment is to roll a die  then there are six outcomes corresponding to\n  the number that shows on the top. For this experiment,\n  $\\Omega = \\{\\mathsf{1,2,3,4,5,6}\\}$.\n\n\nSome examples of events are the set of odd numbered outcomes\n$A=\\{\\mathsf{1,3,5}\\}$, and  the set of\neven numbered outcomes $B=\\{\\mathsf{2,4,6}\\}$.\n\n\nThe simple events  of $\\Omega$ are $\\{\\sf{1}\\}, \\{\\sf{2}\\}, \\{\\sf{3}\\}, \\{\\sf{4}\\}, \\{\\sf{5}\\}$, and $\\{\\sf{6}\\}$.\n\n\\eit\n\\end{example}\n\n\nThe outcome of a random experiment is uncertain until it is performed and observed.  \nNote that sample spaces need to reflect the problem in hand.  \nThe example below is to convince you that an experiment's sample space is merely a collection of distinct elements called outcomes and these outcomes have to be {\\em discernible in some well-specified sense} to the experimenter!\n\n\n\\begin{example}\n\\label{Eg:SensoryDiscerningExperiments} \nConsider a generic\n  die-tossing experiment by a human experimenter. Here \\newline $\\Omega=\n  \\{\\omega_1,\\omega_2,\\omega_3,\\ldots,\\omega_6\\}$, but the\n  experiment might correspond to rolling a die whose faces are:\n\\begin{enumerate}\n\\item sprayed with six different scents (nose!), or\n\\item studded with six distinctly flavoured candies (tongue!), or\n\\item contoured with six distinct bumps and pits (touch!), or\n\\item acoustically discernible at six different frequencies (ears!), or\n\\item painted with six different colours (eyes!), or\n\\item marked with six different numbers $\\mathsf{1,2,3,4,5,6}$ (eyes!), or , \\ldots\n\\end{enumerate}\nThese six experiments are  equivalent as far as probability goes.\n\\end{example}\n\n\n\\begin{definition}\n{A {\\bf trial} is a single performance of an experiment and it\n  results in an outcome.}\n\\end{definition}\n\n\n\n\\begin{example}\nSome standard examples of a trial are:\n\n\\bit\n\n\\item A roll of a die.\n\n\\item A toss of a coin.\n\n\\item A release of a chaotic double pendulum.\n\n\\eit\n\\end{example}\n\nAn experimenter often performs more than one trial.  Repeated trials of an experiment forms the basis of science and engineering as the experimenter learns about the phenomenon by repeatedly performing the same mother experiment with possibly different outcomes.  This repetition of trials in fact provides the very motivation for the definition of probability.\n\n\\begin{definition}{An {\\bf ${\\mathbf n}$-product experiment} is obtained by\n    repeatedly performing $n$ trials of some experiment. \n    %This experiment is often called the mother experiment.% Raaz substituted to avoid the ambiguous reference to 'This'\n    The experiment that is repeated is called the ``mother'' experiment.}\n\\end{definition}\n\n\n\n\\begin{example}[Toss a coin $n$ times]\\label{EX:T3X}\nSuppose our experiment entails tossing a coin $n$ times and recording ${\\tt H}$ for Heads and ${\\tt T}$ for Tails.  When $n=3$, one possible outcome of this experiment is ${\\tt HHT}$, ie.~a Head followed by another Head and then a Tail.  Seven other outcomes are possible.  \n%Below, we refer to this experiment by the symbol $\\EE{E}_{\\theta}^{3}$.  More generally, we refer to the experiment of tossing a coin $n$ times as $\\EE{E}_{\\theta}^{n}$ and sometimes refer to $\\EE{E}_{\\theta}^{1}$ by $\\EE{E}_{\\theta}$ for simplicity.  The reason for the $\\theta$ subscrip will become apparent as we develop the theory.\n\\end{example}\n\n\nThe sample space for ``toss a coin three times\" experiment %$\\EE{E}_{\\theta}^{3}$ %\\hyperref[EX:T3X]{Experiment \\ref*{EX:T3X}} of tossing a coin 3 times \nis:\n\\[\n\\Omega = \\{ {\\tt H}, {\\tt T} \\}^3 =  \\{ {\\tt HHH}, {\\tt HHT}, {\\tt HTH}, {\\tt HTT}, {\\tt THH}, {\\tt THT}, {\\tt TTH}, {\\tt TTT}  \\} \\ ,\n\\]\nwith a particular sample point or outcome $\\omega = {\\tt HTH}$, and another distinct outcome $\\omega' = {\\tt HHH}$.  An event, say $A$, that `at least two Heads occur' is the following subset of $\\Omega$:\n\\[\nA = \\{ {\\tt HHH}, {\\tt HHT}, {\\tt HTH}, {\\tt THH} \\} \\ .\n\\]\nAnother event, say $B$, that `no Heads occur' is:\n\\[\nB = \\{{\\tt TTT}\\}\n\\]\nNote that the event $B$ is also an outcome or sample point.  Another interesting event is the empty set $\\emptyset  \\subset \\Omega$.  The event that `nothing in the sample space occurs' is $\\emptyset$.\n\n\\begin{classwork}[A thrice-bifurcating tree of outcomes]\nCan you think of a graphical way to enumerate the outcomes of the Experiment~\\ref{EX:T3X}%$\\EE{E}_{\\theta}^{3}$\n?  Draw a diagram of this under the caption of \\hyperref[F:T3X]{Figure~\\ref*{F:T3X}}, using the caption as a hint (in other words, draw your own \\hyperref[F:T3X]{Figure~\\ref*{F:T3X}}).\n\\begin{figure}[htpb]\n\\caption{A binary tree whose leaves are all possible outcomes.\\label{F:T3X}}\n\\vspace{4cm}\n\\end{figure}\n\\end{classwork}\n\n\\remove{\nIn \\hyperref[LW:T3X]{Labwork~\\ref*{LW:T3X}} we implement \\hyperref[AL:T3X]{Algorithm~\\ref*{AL:T3X}} to  print all the outcomes.  The algorithm uses {\\bf for loops} to reach the leaves (outcomes of $\\EE{E}_{\\theta}^{3}$) of the binary tree.\n\\begin{algorithm}[htpb]\n\\caption{List $\\Omega$ for ``Toss a Coin Three Times\" experiment $\\EE{E}_{\\theta}^{3}$}\n\\label{AL:T3X}\n\\begin{algorithmic}[1]\n\\STATE {\\it input:} nothing\n\n\\STATE {\\it output:} print/list all outcomes of $\\EE{E}_{\\theta}^{3}$ \n\n\\STATE {\\it initialize:} ${\\bf SampleSpace1Toss} = \\{ {\\tt H}, {\\tt T} \\}$  \\COMMENT{{\\tiny ${\\bf SampleSpace1Toss}[1]={\\tt H}$ and ${\\bf SampleSpace1Toss}[2]={\\tt T}$}}\n\\FOR{$i=1$ to $2$} \n\\FOR{$j=1$ to $2$}\n\\FOR{$k=1$ to $2$}\n\\STATE {\n Print ${\\bf SampleSpace1Toss}[i]$ ${\\bf SampleSpace1Toss}[j]$ ${\\bf SampleSpace1Toss}[k]$ \\\\\nPrint `` , \"  \\COMMENT{{\\tiny print a comma character to delimit outcomes}}\n}\n\\ENDFOR\n\\ENDFOR\n\\ENDFOR\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{labwork}[Three for loops for the thrice-bifurcating tree]\\label{LW:T3X}\nLet's write a {\\sc Matlab} code in a script file named {\\tt OutcomesOf3Tosses.m} that implements \\hyperref[AL:T3X]{Algorithm~\\ref*{AL:T3X}} to print all the outcomes of $\\EE{E}_{\\theta}^{3}$.  You need to go to the File menu and create a new file named {\\tt OutcomesOf3Tosses.m} Run it in the command window.\n\\begin{VrbM}\n>> type OutcomesOf3Tosses.m\n\nSampleSpace1Toss='HT';\t% declare a string vector or character array\n% SampleSpace1Toss is the name of the char array\nSampleSpace1Toss(1);\t\t% access the first element 'H' this way\nSampleSpace1Toss(2);\t\t% access the second element 'T' this way\n% Now let's write the routine for listing the sample space of 'toss 3 times'\nw=' ';\t\t% declare w to be the character ' '\nfor i = 1:1:2\t\t% for loop for variable i = start:increment:end\n  for j = 1:1:2\t\t% for loop for variable j\n    for k = 1:1:2\t% for loop for variable j\n     % next we concatenate using strcat -- strcat('A','B','C','D') concatenates the 4 char arrays\n     x = strcat(SampleSpace1Toss(i),SampleSpace1Toss(j),SampleSpace1Toss(k),' , '); % ' ,' delimited outcome\n     w = strcat(w,x); % recursively store the outcomes in a new array w\n    end\n  end\nend\nw\t\t% print w at the end of the three for loops\n>> lab1work4\n>> SampleSpace1Toss(1)\nans = H\n>> SampleSpace1Toss(2)\nans = T\n>> w\nw = HHH ,HHT ,HTH ,HTT ,THH ,THT ,TTH ,TTT ,\n\\end{VrbM}\n\\end{labwork}\n}\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\n\\section{Probability}\\label{S:Probability}\nThe  mathematical model for probability or the probability model is an axiomatic system that may be motivated by the intuitive idea of `long-term relative frequency'.  If the axioms and definitions are intuitively motivated, the probability model simply follows from the application of logic to these axioms and definitions.  No attempt to define probability in the real world is made. However, the application of probability models to real-world problems through statistical experiments has a fruitful track record.  In fact, you are here for exactly this reason.\n\n\\begin{idea}[The long-term relative frequency (LTRF) idea]\nSuppose we are interested in the fairness of a coin, i.e.~if landing Heads has the same ``probability\" as landing Tails.  We can toss it $n$ times and call \n$N({\\tt H},n)$ the fraction of times we observed Heads out of $n$ tosses.\nSuppose that after conducting the tossing experiment $1000$ times, we rarely observed Heads, e.g.~$9$ out of the $1000$ tosses, then $N({\\tt H},1000)=9/1000=0.009$.  Suppose we continued the number of tosses to a million and found that this number approached closer to $0.1$, or, more generally, $N({\\tt H},n) \\to 0.1$ as $n \\to \\infty$.  We might, at least intuitively, think that the coin is unfair and has a lower ``probability'' of $0.1$ of landing Heads.  We might think that it is fair had we observed $N({\\tt H},n) \\to 0.5$ as $n \\to \\infty$.  Other crucial assumptions that we have made here are:\n\\begin{enumerate}\n\\item {\\bf Something Happens}: Each time we toss a coin, we are certain to observe Heads {\\bf or} Tails, denoted by ${\\tt H} \\cup {\\tt T}$.  The probability that ``something happens'' is $1$.  More formally:\n\\[\nN({\\tt H} \\cup {\\tt T},n)= \\frac{n}{n} = 1.\n\\]\nThis is an intuitively reasonable assumption that simply says that one of the possible outcomes is certain to occur, provided the coin is not so thick that it can land on or even roll along its circumference.\n\n\\item {\\bf Addition Rule}: Heads and Tails are mutually exclusive events in any given toss of a coin, i.e.~they cannot occur simultaneously.  The intersection of mutually exclusive events is the empty set and is denoted by ${\\tt H} \\cap {\\tt T} = \\emptyset$. The event ${\\tt H} \\cup {\\tt T}$, namely that the event that ``coin lands Heads {\\bf or} coin lands Tails\" satisfies:\n\\[\nN({\\tt H} \\cup {\\tt T},n)= N({\\tt H},n) + N({\\tt T},n) .\n\\]\n\\item The coin-tossing experiment is repeatedly performed in an {\\bf independent} manner, i.e.~the outcome of any individual coin-toss does not affect that of another.  This is an intuitively reasonable assumption since the coin has no memory and the coin is tossed identically each time.\n\\end{enumerate}\n\\end{idea}\n\nWe will use the LTRF idea more generally to motivate a mathematical model of probability called probability model.  Suppose $A$ is an event associated with some experiment $\\EE{E}$, so that $A$ either does or does not occur when the experiment is performed.  We want the probability that event $A$ occurs in a specific performance of $\\EE{E}$, denoted by $\\P(A)$, to intuitively mean the following:  if one were to perform a super-experiment $\\EE{E}^{\\infty}$ by independently repeating the experiment $\\EE{E}$ and recording $N(A,n)$, the fraction of times $A$ occurs in the first $n$ performances of $\\EE{E}$ within the super-experiment $\\EE{E}^{\\infty}$. Then the LTRF idea suggests:\n\\begin{equation}\\label{E:NofAn}\nN(A,n) :=  \\frac{\\text{Number of times $A$ occurs}}{n=\\text{Number of performances of $\\EE{E}$}} \\to \\P(A), \\ as \\quad  n \\to \\infty\n\\end{equation}\n\nNow, we are finally ready to define probability.\n\\begin{definition}[Probability]\\label{D:Prob}\nLet $\\EE{E}$ be an experiment with sample space $\\Omega$.  Let $\\C{F}$ denote a suitable collection of events in $\\Omega$ that satisfy the following conditions:\n\\begin{enumerate}\n\\item It (the collection) contains the sample space:\n$\\boxed{\n\\Omega \\in \\C{F} }$.\n\\item It is closed under complementation:\n$\\boxed{\nA \\in \\C{F} \\quad \\implies \\quad A^c \\in \\C{F} }$.\n\\item It is closed under countable unions:\n$\\boxed{\nA_1, A_2, \\ldots \\in \\C{F} \\quad \\implies \\quad \\bigcup_{i} {A_i} := A_1 \\cup A_2 \\cup \\cdots \\in \\C{F} }$.\n\\end{enumerate}\nFormally, this collection of events is called a {\\bf sigma field} or a {\\bf sigma algebra}.  Our experiment $\\EE{E}$ has a sample space $\\Omega$ and a collection of events $\\C{F}$ that satisfy the three condition. \n\nGiven a double, e.g. $(\\Omega, \\C{F})$, {\\bf probability} is just a function $\\P$ which assigns each event $A \\in \\C{F}$ a number $\\P(A)$ in the real interval $[0,1]$, i.e.~$\\boxed{\\P : \\C{F} \\to [0,1] }$, such that:\n\\begin{enumerate}\n\\item The `Something Happens' axiom holds, i.e.~$\\boxed{\\P(\\Omega) = 1}$. \n\\item The `Addition Rule' axiom holds, i.e.~for events $A$ and $B$:\n$$\n\\boxed{\nA \\cap B = \\emptyset \\quad \\implies \\quad \\P(A \\cup B) = \\P(A) + \\P(B)\n} \\ .\n$$\n\\end{enumerate}\n\\end{definition}\n\\subsection{Consequences of our Definition of Probability}\\label{S:ConseqDefProb}\nIt is important to realize that we accept the `addition rule' as an axiom in our mathematical definition of probability (or our probability model) and we do {\\bf not} prove this rule.  However, the facts which are stated ({\\scriptsize with proofs}) below, are logical consequences of our definition of probability:\n\\begin{enumerate}\n\\item For any event $A$, $\\boxed{\\P(A^c) = 1 - \\P(A)}$.\n{\\scriptsize\n\\begin{proof}\nOne line proof.\n\\[\n\\overbrace{\\P(A) + \\P(A^c)}^{LHS} \\underbrace{=}_{+~\\text{rule}~\\because A \\cap A^c = \\emptyset} \\P(A \\cup A^c) \\underbrace{=}_{A \\cup A^c = \\Omega} \\P(\\Omega) \\underbrace{=}_{\\because~\\P(\\Omega) = 1} \\overbrace{1}^{RHS} \\quad \\underbrace{\\Longrightarrow}_{LHS-\\P(A)~\\&~RHS-\\P(A)} \\quad \\P(A^c) = 1-\\P(A)\n\\]\n\\end{proof}\n}\n\\begin{itemize}\n\\item If $A = \\Omega$ then $A^c = \\Omega^c = \\emptyset$ and \n$\\boxed{\\P(\\emptyset) = 1-\\P(\\Omega) = 1-1 = 0}$.\n\\end{itemize}\n\n\\item For any two events $A$ and $B$, we have the {\\bf inclusion-exclusion principle}:\n\\[\n\\boxed{\n\\P(A \\cup B) = \\P(A) + \\P(B) - \\P(A \\cap B)\n}.\n\\]\n{\\scriptsize\n\\begin{proof}\nSince: \n\\begin{eqnarray}\n\\quad A = (A \\setminus B) \\cup (A \\cap B) & \\quad \\text{and} \\quad & (A \\setminus B) \\cap (A \\cap B) = \\emptyset, \\notag \\\\\n\\quad A \\cup B = (A \\setminus B) \\cup B & \\quad \\text{and} \\quad & (A \\setminus B) \\cap B = \\emptyset \\notag\n\\end{eqnarray}\nthe addition rule implies that:\n\\begin{eqnarray}\n\\P(A) &=& \\P(A \\setminus B) + \\P(A \\cap B) \\notag \\\\\n\\P(A \\cup B) &=& \\P(A \\setminus B) + \\P(B) \\notag\n\\end{eqnarray}\nSubstituting the first equality above into the second, we get:\n\\[\n\\P(A \\cup B) = \\P(A \\setminus B) + \\P(B) = \\P(A) - \\P(A \\cap B) + \\P(B)\n\\]\n\\end{proof}\n}\n\\item From inclusion-exclusion principle we get {\\bf Boole's inequality}: for any two events $A, B$\n\\[\n\\P(A \\cup B) \\leq \\P(A) + \\P(B)\n\\]\n\\item The inclusion-exclusion principle extends similarly to any three events $A_1,A_2,A_3$ as follows:\n\\[\n\\P(A_1 \\cup A_2 \\cup A_3) = \\P(A_1) + \\P(A_2) + \\P(A_3) - \\P(A_1 \\cap A_2) - \\P(A_1 \\cap A_3) - \\P(A_2 \\cap A_3) + \\P(A_1 \\cap A_2 \\cap A_3)\n\\]\nand generalises to any $n$ events $A_1,A_2,\\ldots,A_n$ as folows:\n\\[\n\\P \\left( \\bigcup_{i=1}^n A_i \\right) = \\sum_{i=1}^n \\P(A_i) - \\sum_{i<j} \\P(A_i \\cap A_j) + \\sum_{i<j<k} \\P(A_i \\cap A_j \\cap A_k) + \\cdots + (-1)^{n-1} \\sum_{i< \\cdots <n} \\P \\left( \\bigcap_{i=1}^n A_i \\right)\n\\]\n\n{\\scriptsize\n\\begin{proof} See the counting argument in \\url{https://en.wikipedia.org/wiki/Inclusion\\%E2\\%80\\%93exclusion_principle} if you are curious.\n\\end{proof}\n}  \n\\item Once again by the inclusion-exclusion principle, the Boole's inequality generalises to any $n$ events $A_1,A_2,\\ldots,A_n$ as folows:\n\\[\n\\P \\left( \\bigcup_{i=1}^n A_i \\right) \\leq \\sum_{i=1}^n \\P(A_i)\n\\]\n\\item For a sequence of mutually disjoint events $A_1, A_2, A_3, \\ldots, A_n$: \n\\[\n\\boxed{\nA_i \\cap A_j = \\emptyset \\quad \\text{for any $i \\neq j$} \\quad \\implies \\quad \\P(A_1 \\cup A_2 \\cup \\cdots \\cup A_n) = \\P(A_1)+\\P(A_2)+ \\cdots + \\P(A_n)} .\n\\]\n{\\scriptsize\n\\begin{proof}\nIf $A_1, A_2, A_3$ are mutually disjoint events, then $A_1 \\cup A_2$ is disjoint from $A_3$.  Thus, two applications of the addition rule for disjoint events yields:\n\\[\n\\P(A_1 \\cup A_2 \\cup A_3) = \\P((A_1 \\cup A_2) \\cup A_3) \\underbrace{=}_{+~\\text{rule}} \\P(A_1 \\cup A_2) + \\P(A_3) \\underbrace{=}_{+~\\text{rule}}  \\P(A_1) + \\P(A_2) + \\P(A_3)\n\\]\nThe $n$-event case follows by mathematical induction.\n\\end{proof}\n}\n\\end{enumerate}\n\nWe have formally defined the {\\bf probability model} specified by the {\\bf probability triple} $(\\Omega, \\C{F},\\P)$ that can be used to model an {\\bf experiment} $\\EE{E}$.\n\n\\begin{example}[First Ball out of NZ Lotto]\\label{Eg:NZLottoModel}\nLet us observe the number on {\\em the first ball that pops out in a New Zealand Lotto trial}.  \nThere are forty balls labelled $1$ through $40$ for this experiment and so the sample space is \\[\\Omega\\;=\\;\\{\\mathsf{1,2,3,\\dots,39,40}\\}\\,.\\]  \nBecause the balls are vigorously whirled around inside the Lotto machine, modelled as a well-stirrred urn, before the first one pops out, \nwe can model each ball to pop out first with the same probability. \nSo, we assign each outcome $\\omega \\in \\Omega$ the same probability of $\\frac{1}{40}$, i.e., our probability model for this experiment is:\n\\[\n\\P(\\omega) = \\frac{1}{40}, \\ \\text{for each \\ } \\omega \\in \\Omega = \\{\\mathsf{1,2,3,\\ldots,39,40}\\} \\enspace .\n\\]\nNote: We sometimes abuse notation and write $\\P(\\omega)$ instead of the\nmore accurate but cumbersome $\\P(\\{\\omega\\})$ when writing down\nprobabilities of simple events. \n\nCrucially, by $\\omega=\\mathsf{17}$ for example, we mean all the detailed dynamics inside the Lotto machine that lead to the event that the ball labelled by the number $\\mathsf{17}$ ends up popping out. \nSo, $\\Omega$ here is indeed a more complicated set although it only leads to $40$ possible outcomes.\n\nFigure~\\ref{F:LottoDraws}~(a) shows the frequency of the first ball number in 1114 NZ Lotto draws.  \nFigure~\\ref{F:LottoDraws}~(b) shows the relative frequency, i.e., the frequency divided by $1114$, the number of draws.  \nFigure~\\ref{F:LottoDraws}~(b) also shows the equal probabilities under our model.\n\n\\begin{figure}[htbp]\n\\centering\n\\subfigure[{\\scriptsize Frequency of first ball.}]{\n\\includegraphics[width=7.5cm,height=4cm]{figures/mylotto_freq}}\n\\quad\n\\subfigure[{\\scriptsize Relative frequency and probability of first ball.}]{\n\\includegraphics[width=7.5cm,height=4cm]{figures/mylotto_freq_relative}}\n\\caption{First ball number in 1114 NZ Lotto draws from 1987 to 2008.\\label{F:LottoDraws}}\n\\end{figure}\n\\end{example}\n\n\nNext, let us take a detour into how one might interpret it in the real world.  The following is an adaptation from Williams D, {\\it Weighing the Odds: A Course in Probability and Statistics}, Cambridge University Press, 2001, which henceforth is abbreviated as WD2001.\n\\begin{center}\n\\begin{tabular}{l l}\n{\\bf Probability Model} & {\\bf Real-world Interpretation} \\\\\nSample space $\\Omega$ & Set of all outcomes of an experiment \\\\\nSample point $\\omega$ & Possible outcome of an experiment \\\\ \n(No counterpart) & Actual outcome $\\omega^{\\star}$ of an experiment\\\\\nEvent A, a (suitable) subset of $\\Omega$ & The real-world event corresponding to A \\\\\n & occurs if and only if $\\omega^{\\star} \\in A$\\\\\n$\\P(A)$, a number between $0$ and $1$         & Probability that $A$ will occur for an \\\\\n & experiment yet to be performed \\\\\n\\\\\n% \\end{tabular}\n% \\end{center}\n% \\begin{center}\n% \\begin{tabular}{l l}\n{\\bf Events in Probability Model} & {\\bf Real-world Interpretation} \\\\\nSample space $\\Omega$ & The certain even `something happens' \\\\\nThe $\\emptyset$ of $\\Omega$ & The impossible event `nothing happens' \\\\ \nThe intersection $A \\cap B$ & `Both $A$ and $B$ occur'\\\\\n$A_1 \\cap A_2 \\cap \\cdots \\cap A_n $ & `All of the events $A_1, A_2, \\ldots, A_n$ occur simultaneously'\\\\\nThe union $A \\cup B$ & `At least one of $A$ and $B$ occurs'\\\\\n$A_1 \\cup A_2 \\cup \\cdots \\cup A_n$ & `At least one of the events $A_1, A_2, \\ldots, A_n$ occurs'\\\\\n$A^c$, the complement of $A$ & `$A$ does not occur'\\\\\n$A \\setminus B$ & `$A$ occurs, but $B$ does not occur'\\\\\n$A \\subset B$ & `If $A$ occurs, then $B$ must occur'\n\\end{tabular}\n\\end{center}\n\n\n{In the probability model of Example~\\ref{Eg:NZLottoModel}, show that for any event $E \\subset \\Omega$, \\[\\P(E)\\; =\\;\n\\frac{1}{40} \\;\\times \\;\\text{number of elements in $E$} \\enspace . \\]\n}\n{\\label{Eg:NZLottoExp}}\n{\nLet $E = \\{\\omega_1,\\omega_2,\\ldots,\\omega_k\\}$ be an event with $k$ outcomes (simple events).  \nThen by the addition rule for mutually exclusive events we get:\n%\\begin{multiline}\n$$\\P(E)\\;=\\;\\P\\left( \\{\\omega_1,\\omega_2,\\ldots,\\omega_k\\} \\right)\n= \\P\\left(\\bigcup^{k}_{i=1} \\{ \\omega_i \\}\\right)\\;=\\;\\sum^{k}_{i=1}\\P\\left(\\{\\omega_i\\}\\right)\\;=\\;\\sum^{k}_{i=1}\\frac{1}{40}\\;=\\;\\frac{k}{40} \\enspace .$$\n\n%\\end{multiline}\n}\n\n\\subsection{Sigma Algebras of Typical Experiments$^*$}\n\n\\begin{example}[`Toss a fair coin once']\nConsider the `Toss a fair coin once' experiment.  What is its sample space $\\Omega$ and a reasonable collection of events $\\C{F}$ that underpin this experiment?  \n\\[\n\\Omega = \\{  {\\tt H}, {\\tt T} \\}, \\qquad \\C{F} = \\{ {\\tt H}, {\\tt T},\\Omega, \\emptyset \\} \\ ,\n\\]\nA function that will satisfy the definition of probability for this collection of events $\\C{F}$ and assign $\\P({\\tt H}) = \\frac{1}{2}$ is summarized below.  First check that the above $\\C{F}$ is a sigma-algebra.  Draw a picture for $\\P$ with arrows that map elements in the domain $\\C{F}$ given above to elements in its range. \n\\begin{center}\n\\begin{tabular*}{3.5in}{@{\\extracolsep{\\fill}}r c l} \\hline\nEvent $A \\in \\C{F}$ & $\\P : \\C{F} \\to [0,1]$ & $\\P(A) \\in [0,1]$ \\\\ \\hline\n$\\Omega=\\{ {\\tt H}, {\\tt T} \\} \\, \\bullet$ & $ \\ \\longrightarrow \\ $ & $1$ \\\\ \n${\\tt T} \\, \\bullet$ & $ \\ \\longrightarrow \\ $ & $1-\\frac{1}{2}$ \\\\ \n${\\tt H}  \\, \\bullet$ & $ \\ \\longrightarrow \\ $ & $\\frac{1}{2}$ \\\\ \n$\\emptyset \\, \\bullet$ & $ \\ \\longrightarrow \\ $ & $0$ \\\\ \\hline\n\\end{tabular*}\n\\end{center}\n\\end{example}\n\n\\begin{classwork}[The trivial sigma algebra]\nNote that $\\C{F}' = \\{ \\Omega, \\emptyset\\}$ is also a sigma algebra of the sample space $\\Omega= \\{  {\\tt H}, {\\tt T} \\}$.  Can you think of a probability for the collection $\\C{F}'$?\n\\begin{center}\n\\begin{tabular*}{3.5in}{@{\\extracolsep{\\fill}}r c l} \\hline\nEvent $A \\in \\C{F}'$ & $\\P : \\C{F}' \\to [0,1]$ & $\\P(A) \\in [0,1]$ \\\\ \\hline\n$\\Omega=\\{ {\\tt H}, {\\tt T} \\} \\, \\bullet$ & $ \\ \\longrightarrow \\ $ &\\\\ \n$\\emptyset \\, \\bullet$ & $ \\ \\longrightarrow \\ $ & \\\\ \\hline\n\\end{tabular*}\n\\end{center}\n{\\scriptsize\nThus, $\\C{F}$ and $\\C{F}'$ are two distinct sigma algebras over our $\\Omega=\\{ {\\tt H}, {\\tt T} \\}$.  Moreover, $\\C{F}' \\subset \\C{F}$ and is called a sub sigma algebra.  Try to show that $\\{\\Omega,\\emptyset\\}$ is the smallest possible sigma algebra over all possible sigma algebras over any given sample space $\\Omega$ (think of intersecting an arbitrary family of sigma algebras)?\n}\n\\end{classwork}\n \nGenerally one encounters four types of sigma algebras (you will understand the last two types after taking more advanced courses in mathematics, so it is fine to understand the ideas intuitively for now!) and they are:\n\\be\n\\item\nWhen the sample space $\\Omega=\\{\\omega_1,\\omega_2,\\ldots,\\omega_k\\}$ is a finite set with $k$ outcomes and $\\P(\\omega_i)$, the probability for each outcome $\\omega_i \\in \\Omega$ is known, then one typically takes the sigma-algebra $\\C{F}$ to be the set of all subsets of $\\Omega$ called the {\\bf power set} and denoted by $2^{\\Omega}$.  \nThe probability of each event $A \\in 2^{\\Omega}$ can be obtained by adding the probabilities of the outcomes in $A$, i.e., $\\P(A)=\\sum_{\\omega_i \\in A} \\P(\\omega_i)$.  \nClearly, $2^{\\Omega}$ is indeed a sigma-algebra and it contains $2^{\\#\\Omega}$ events in it.  \n\n\\item\nWhen the sample space $\\Omega=\\{\\omega_1,\\omega_2,\\ldots\\}$ is a countable set then one typically takes the sigma-algebra $\\C{F}$ to be the set of all subsets of $\\Omega$.  Note that this is very similar to the case with finite $\\Omega$ except now $\\C{F}=2^{\\Omega}$ could have uncountably many events in it.\n\n%%TODO make an example of a continuous space experiment, say Darth Mole's light saber for R^1 and destination of a random ride in Doctor Who's TARDIS space-time R^d \n\\item\nIf $\\Omega = \\Rz^d$ for finite $d \\in \\{1,2,3,\\ldots\\}$ then the {\\bf Borel sigma-algebra} is the smallest sigma-algebra containing \nall {\\bf half-spaces}, i.e., sets of the form \n$$\\{x=(x_1,x_2,\\ldots,x_d) \\in \\Rz^d: x_1 \\leq c_1, x_2 \\leq c_2, \\ldots, x_d \\leq c_d\\}, \\quad \\text{ for any } c=(c_1,c_2,\\ldots,c_d)\\in\\Rz^d \\enspace ,\n$$\nWhen $d=1$ the half-spaces are the half-lines $\\{(-\\infty,c]: c \\in \\Rz\\}$ and when $d=2$ the half-spaces are the south-west quadrants $\\{(-\\infty,c_1]\\times(-\\infty,c_2] : (c_1,c_2) \\in \\Rz^2\\}$, etc.  \n(Equivalently, the Borel sigma-algebra is the smallest sigma-algebra containing all open sets in $\\Rz^d$). \n\n\\item\nGiven a finite set $\\Sz=\\{s_1,s_2,\\ldots,s_k\\}$, let $\\Omega$ be the sequence space $\\Sz^{\\infty}:=\\Sz \\times \\Sz \\times \\Sz \\times\\cdots$, i.e., the set of sequences of infinite length that are made up of elements from $\\Sz$.  \nA set of the form\n\\[\nA_1 \\times A_2 \\times \\cdots \\times A_n \\times \\Sz \\times \\Sz \\times \\cdots, \\quad A_k \\subset \\Sz \\text{ for all } k \\in \\{1,2,\\ldots,n\\} \\enspace ,\n\\]\nis called a {\\bf cylinder set}.  \nThe set of events in $\\Sz^{\\infty}$ is the smallest sigma-algebra containing the cylinder sets. \n\n\\begin{itemize}\n\\item {\\bf A most primitive sigma-algebra for probability theory:} \nFor example if $\\Sz=\\{0,1\\}$, then $\\Omega = \\{0,1\\}^{\\infty}$ is the set of all infinite sequences made of $0$'s and $1$'s. \nTo take advantage of arithmetic and analysis, $\\Omega$ can be seen as the binary representation of all real numbers in the unit interval $[0,1]$.  \nWe can take advantage of combinatorics and algebra if we further represent the dyadic partition of $[0,1]$ by a binary tree (as drawn in lectures). \nThen, a cylinder set such as $1 \\times 1 \\times 0 \\times \\{0,1\\} \\times \\{0,1\\} \\times \\cdots$, an event here, can be interpreted as the finite binary sequence $(1,1,0)$ --- corresponding to the third leaf of a finite binary tree with four leaves obtained by splitting the right-most leaf twice. This cylindrical event $(1,1,0)$ contains all real numbers in the interval $[\\frac{3}{4},\\frac{7}{8}] \\subset [0,1] =: \\Omega$.\\end{itemize}\n\n\\ee\n\n\\begin{Exercise}[title={Intuiting a most primitive sigma-algebra -- this is optional},label={underMPSA}]\nTry to carefully recollect and understand the most primitive sigma-algebra in the last item above as it was explained in lectures.\n%\\ExePart\n%\\Question\n%\\subQuestion Show that...\n%\\subQuestion In this question...\n%\\subsubQuestion Show that...\n%\\subsubQuestion Conclude...\n%\\subQuestion Conclude.\n%\\Question Show that if $b > 1$...\n%\\ExePart\n%\\Question What happens to if $b=1$?\n\\end{Exercise}\n\\begin{Answer}\nThis is an optional exercise. You will understand this as you progress through your mathematics programme. \nThe explanation in the said item was (or will be explained in person again) in the lectures. \nThis exercise was created to answer natural questions that were asked by students who wanted to know.\n\\end{Answer}\n\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\\input{ExsInProbability.tex}\n\n\\section{Conditional Probability}\\label{S:CondProb}\n\nConditional probabilities arise when we have partial information about\nthe result of an  experiment which restricts the sample space to a range\nof outcomes.  For example, if there has been a lot of recent seismic activity\nin Christchurch, then the probability that an already damaged building will\ncollapse tomorrow is clearly higher than if there had been no recent seismic activity.\n\nConditional probabilities are  often\nexpressed in English by phrases such as:\\cen{ ``If $A$ happens, what is the probability that\n$B$ happens?''} or \\cen{``What is the probability that  $A$ happens if\n$B$ happens?''} or \\cen{``  What is the probability that  $A$ occurs given that $B$ occurs?''}\n\nNext, we define conditional probability and the notion of independence of events.  We use the LTRF idea to motivate the definition.\n\\begin{idea}[LTRF intuition for conditional probability]\nLet $A$ and $B$ be any two events associated with our experiment $\\EE{E}$ with $\\P(A) \\neq 0$.  The `conditional probability that $B$ occurs given that $A$ occurs' denoted by $\\P(B|A)$ is again intuitively underpinned by the super-experiment $\\EE{E}^{\\infty}$ which is the `independent' repitition of our original experiment $\\EE{E}$ `infinitely' often.  The LTRF idea is that $\\P(B|A)$ is the long-term proportion of those experiments on which $A$ occurs that $B$ also occurs.\n \nRecall that $N(A,n)$ as defined in \\eqref{E:NofAn} is the fraction of times $A$ occurs out of $n$ independent repetitions of our experiment $\\EE{E}$ (ie.~the experiment $\\EE{E}^{n}$).  If $A \\cap B$ is the event that `$A$ and $B$ occur simultaneously', then we intuitively want\n\\[\n\\P(B|A) \\quad \\lq\\lq \\rightarrow \" \\quad \\frac{N(A \\cap B,n)}{N(A,n)} = \\frac{N(A \\cap B,n)/n}{N(A,n)/n} =  \\frac{\\P(A \\cap B)}{\\P(A)}\n\\]\nas our $\\EE{E}^{n} \\rightarrow \\EE{E}^{\\infty}$.  So, we {\\bf define} conditional probability as we want.\n \\end{idea}\n \\begin{definition}[Conditional Probability]\\label{D:CondProb}\nSuppose we are given an experiment $\\EE{E}$ with a triple $(\\Omega, \\C{F}, \\P)$.  Let $A$ and $B$ be events, ie.~$A,B \\in \\C{F}$, such that $\\P(A) \\neq 0$.  Then, we define the {\\bf conditional probability} of $B$ given $A$ by,\n \\begin{equation}\\label{E:CPD}\n \\P(B|A) := \\frac{\\P(A \\cap B)}{\\P(A)} \\ .\n \\end{equation}\nNote that $A$ serves as the new reduced sample space so that conditional probabilities given $A$ \\emph{are} indeed  probabilities.\nThus, for a {\\bf fixed} event $A \\in \\C{F}$ with $\\P(A)>0$ and {\\bf any} event $B \\in \\C{F}$, the conditional  probability $\\P(B | A)$ is a probability as in \\hyperref[D:Prob]{Definition \\ref*{D:Prob}}, ie.~a function:\n \\[\n \\P(B | A) : \\C{F} \\rightarrow [0,1]\n \\]\n that assigns to each $B \\in \\C{F}$ a number in the interval $[0,1]$, such that, the axioms of probability are satisfied:\n\\begin{itemize}\n\\item[]{Axiom~(1): For any event $B$, $0\\leq P(B|A)\\leq 1$.}\n\\item[]{Axiom~(2): $\\P(\\Omega | A) = 1$ \\qquad Meaning `Something Happens given the event A happens'}\n\\item[]{Axiom~(3): The `Addition Rule' axiom holds, ie.~for events $B_1, B_2 \\in \\C{F}$,\n \\[\n B_1 \\cap B_2 = \\emptyset \\quad \\text{implies} \\quad \\P(B_1 \\cup B_2 | A) = \\P(B_1 | A) + \\P(B_2 |  A)  \\ .\n \\]}\n\\item[]{Axiom~(4): For mutually exclusive events, $B_1,B_2, \\ldots$,\n\\[\n\\P(B_1 \\cup B_2 \\cup \\cdots | A) = \\P(B_1|A)+\\P(B_2|A)+\\cdots \\enspace .\n\\]}\n\\end{itemize} \n\\end{definition}\n\nFrom the definition of conditional probability we get the following properties or rules:\n\\begin{itemize}\n\\item[]{{\\bf Complementation rule:} $\\P(B | A)\\, = \\,1 - \\P(B^c | A)$ .}\n\\item[]{{\\bf Addition rule for two arbitrary events $B_1$ and $B_2$:} \\[{\\P(B_1 \\cup B_2 | A) \\;= \\;\\P(B_1 | A) + \\P(B_2 | A) - \\P(B_1\\cap B_2|A)}\\,.\\]}\n\\item[]{Solving for $P(A\\cap B)$ with  these definitions of conditional probability\ngives another rule:\n\\begin{framed}\n{\\bf Multiplication rule for two likely events:} \n\nIf $A$ and $B$ are events, and if\n  $\\P(A)\\neq 0$ and  $\\P(B)\\neq 0$, then\n\\[\\P(A\\cap B)\\;=\\;\\P(A)\\P(B|A)\\;=\\;\\P(B)\\P(A|B)\\,. \\]\n\\end{framed}\n}\n\\end{itemize}\n\n%%%%%%%\n\n\\begin{example}[Wasserman03, p.~11]\\label{EX:Wasserman03p11}\n A medical test for a disease $D$ has outcomes $+$ and $-$.  the probabilities are:\n\\begin{center}\n \\begin{tabular}{l | c | c}\n \\hline\n & Have Disease ($D$) & Don't have disease ($D^c$)  \\\\ \\hline\nTest positive ($+$) & 0.009 & 0.099 \\\\\n Test negative ($-$) & 0.001 & 0.891\\\\ \\hline\n \\end{tabular}\n \\end{center}\n Using the definition of conditional probability, we can compute the conditional probability that you test positive given that you have the disease:\n \\[\n \\P(+ | D) = \\frac{\\P(+ \\cap D)}{\\P(D)} = \\frac{0.009}{0.009+0.001}=0.9 \\ ,\n \\]\n and the conditional probability that you test negative given that you don't have the disease:\n \\[\n \\P(- | D^c) = \\frac{\\P(- \\cap D^c)}{\\P(D^c)} = \\frac{0.891}{0.099+0.891} \\approxeq 0.9 \\ .\n \\]\n Thus, the test is quite accurate since sick people test positive 90\\% of the time and healthy people test negative 90\\% of the time.\n \nNow, suppose you go for a test and and test positive.  What is the probability that you have the disease ?\n \\[\n \\P(D|+) = \\frac{\\P(D \\cap +)}{\\P(+)} = \\frac{0.009}{0.009+0.099} \\approxeq 0.08\n \\]\nMost people who are not used to the definition of conditional probability would intuitively associate a number much bigger than $0.08$ for the answer.  Interpret conditional probability in terms of the meaning of the numbers that appear in the numerator and denominator of the above calculations.\n\\end{example}\n \n\\subsection{Bayes' Theorem}\\label{S:BayesTheorem}\n Next we look at one of the most elegant applications of the definition of conditional probability along with the addition rule for a partition of $\\Omega$ called \\emph{Bayes' Theorem}. \nWe will present a two event case first called \\emph{Bayes' Rule} and then present the more general case of the Theorem.\n\nThis is useful because many problems involve reversing the order of conditional\nprobabilities. Suppose we want to investigate  some phenomenon $A$  and\nhave an observation $B$ that is evidence about $A$: for example, $A$ may\nbe breast cancer and $B$  may be a positive mammogram. Then  Bayes'\nTheorem tells us how we should update our probability of $A$, given the\nnew evidence $B$.\n\nOr, put more simply, Bayes' Rule is useful when you know $P(B | A)$ but\nwant $P(A | B )$!\n\n\\begin{framed}\n\\begin{prop}[Bayes' Rule]\\label{P:BayesRule}\n\\begin{equation}\nP(A|B)\\;=\\;\\frac{P(A)P(B|A)}{P(B)} \\enspace .\n\\end{equation}\n\\end{prop}\n\\end{framed}\n\\begin{proof}\nFrom the  definition of conditional probability and the multiplication rule for two likely events $A$ and $B$ we get:\n$$\nP(A|B)\\;=\\;\\frac{P(A \\cap B)}{P(B)} \\; = \\;\\frac{P(B \\cap A)}{P(B)}\\;= \\; \\frac{P(B|A)P(A)}{P(B)}\\;  =\\; \\frac{P(A)P(B|A)}{P(B)} \\enspace .\n$$\n\\end{proof}\n\n\\begin{example}[Mammogram]\\label{EXmammogram}\nApproximately 1\\% of women aged 40--50 have breast cancer. \nA woman with breast cancer has a 90\\% chance of a positive test from a mammogram, while a woman without breast cancer has a 10\\% chance of a false positive result from the test. \nWhat is the probability that a woman indeed has breast cancer given that she just had a positive test?\\\\[3pt]\nSolution:\\\\[3pt]\n{Let $A=$``the woman has breast cancer'', and $B=$``a positive\ntest.''\n\n\\medskip\n\n We want  $P(A|B)$ but what we are given is $P(B|A)= 0.9$.\n\\medskip\n\nBy the definition of conditional probability,\n$$P(A|B)\\;=\\;P(A\\cap B)/P(B)$$\n\nTo evaluate the numerator we use the multiplication rule\n$$P(A\\cap B)\\;=\\;P(A)P(B|A)\\;=\\;0.01\\times 0.9\\;=\\;0.009$$\n\nSimilarly,\n$$P(A^c\\cap B)\\;=\\;P(A^c)P(B|A^c)\\;=\\;0.99 \\times 0.1\\;=\\;0.099$$\n\nNow $P(B)\\,=\\,P(A\\cap B)+P(A^c\\cap B)$ so\n\n$$P(A|B)\\;=\\;\\frac{P(A\\cap B)}{P(B)}\\;=\\;\\frac{0.009}{0.009+0.099}\\;=\\;\\frac{9}{108}$$\nor a little less than 9\\%. This situation comes about because it is much easier to have a false positive for a healthy woman, which has probability $0.099$, than to find a woman with breast cancer having a positive test, which has probability $0.009$.\n\n\\medskip\n\nThis answer is somewhat surprising. Indeed when ninety-five physicians were asked this question their average answer was 75\\%. The two statisticians who carried out this survey indicated that physicians were better able to see the answer when the data was presented in frequency format. 10 out of 1000 women have breast cancer. Of these 9 will have a positive mammogram. However of the remaining 990 women without breast cancer 99 will have a positive reaction, and again we arrive the answer $9/(9+99)$.\n\n\\bigskip\n\n\\emph{Alternative solution using a tree diagram:}\n\n\\begin{center}\n\\begin{picture}(100,140)(75,30)\\drawline(0,90)(75,120)(125,140)\n\\drawline(75,120)(125,100)\\drawline(0,90)(75,60)(125,40)\n\\drawline(75,60)(125,80)\n\\put(60,120){$A$}\\put(60,50){$A^c$}\n\\put(130,140){$\\mathsf{B}$ \\;\\;$P(A\\cap B)=0.009$}\\put(130,100){$\\mathsf{B^c}$ \\;\\;$0.001$}\n\\put(130,80){$\\mathsf{B}$ \\;\\; $P(A^c\\cap B)=0.099$}\\put(130,40){$\\mathsf{B^c}$ \\;\\;$ 0.891$}\n\\put(95,140){$0.9$}\\put(95,95){$0.1$}\n\\put(95,75){$0.1$}\\put(95,35){$0.9$}\n\\put(30,110){$0.01$}\\put(30,60){$0.99$}\n\\put(20,160){\\text{\\small Breast Cancer}}\n\\put(100,160){\\text{\\small Positive Test}}\n\\end{picture}\n\\end{center}\n\nSo the probability that a woman has breast cancer given that\nshe has just had a positive test is  $$P(A|B)\\;=\\;\\frac{P(A\\cap B)}{P(B)}\\;=\\;\\frac{0.009}{0.009+0.099}\\;=\\;\\frac{9}{108}$$\n\n\\emph{$^*$In the exam, there won't be any need for electronic calculators and you may leave the answer in either of the last two numerical forms for full credit, provided you show the steps in your reasoning.}\n}\n\\end{example}\n\nBefore we see the more general form of Bayes' Rule, let us make a simple observation called the \\emph {total probaility theorem}.\n\n\\begin{framed}\n\\begin{prop}[Total probability theorem]\\label{Thm:TotalProb}\nSuppose $A_1 \\cup A_2 \\ldots \\cup A_k$ is a sequence of events with positive probability that partition the sample space, that is, $A_1\\cup A_2 \\cdots \\cup A_k=\\Omega$ and  $A_i \\cap A_j = \\emptyset$ for any $i \\neq j$, then for some arbitrary event $B$.\n\\begin{equation}\\label{E:TotalProb}\nP(B) \\;= \\;\\sum_{h=1}^k P(B \\cap A_h) \\;= \\;\\sum_{h=1}^k P(B|A_h)P(A_h)\n\\end{equation}\n\\end{prop}\n\\end{framed}\n\\begin{proof}\nThe first equality is due to the addition rule for mutually exclusive events, \\[B \\cap A_1, B \\cap A_2, \\ldots, B \\cap A_k\\] and the second equality is due to the multiplication rule for two likely events.\n\\end{proof}\nReference to the Venn digram (you should draw below as done in lectures) will help you understand this idea for the four event case.\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/totProbThmVennDiagram.eps}\n\\caption{Reference to the Venn digram will help you understand this idea behind the proof of the total probability theorem in Proposition~\\ref{Thm:TotalProb} for the four event case.}\n\\end{center}\n\\end{figure}\n\n\\begin{example}[Urn with red and black balls]\\label{EX:urnRedBlackBalls} \nA well-mixed urn contains five\n{\\sf red} and ten {\\sf black} balls. We draw two balls from the urn\nwithout replacement. What is the probability that the second ball drawn\nis {\\sf red}?\n\nThis is easy to see if we draw a probability tree diagram.  \nThe first split in the tree is based on the outcome of the first draw and the second on the outcome of the last draw.  \nThe outcome of the first draw dictates the probabilities for the second one since we are sampling without replacement.  \nWe multiply the probabilities on the edges to get probabilities of the four endpoints, and then sum the ones that correspond to {\\sf red} in the second draw, that is\n\\[\nP(\\text{second ball is red}) \\;=\\; 4/42+10/42\\;=\\;1/3 \\enspace .\n\\]\n\n\\begin{center}\n\\begin{picture}(100,140)(75,30)\n\\drawline(0,90)(75,120)(125,140)\n\\drawline(75,120)(125,100)\n\\drawline(0,90)(75,60)(125,40)\n\\drawline(75,60)(125,80)\n\\put(55,125){{\\sf red}}\\put(55,45){{\\sf black}}\n\\put(130,140){$\\mathsf{(red, red)}$ 4/42}\\put(130,100){$\\mathsf{(red, black)}$ 10/42}\n\\put(130,80){$\\mathsf{(black, red)}$ 10/42}\\put(130,40){$\\mathsf{(black, black)}$ 18/42}\n\\put(95,140){4/14}\\put(95,115){10/14}\n\\put(95,80){5/14}\\put(95,55){9/14}\n\\put(30,110){1/3}\\put(30,80){2/3}\n\\end{picture}\n\\end{center}\n\nAlternatively,  use the total probability theorem to break\nthe problem  down into manageable pieces.  \nLet\n  $R_1=\\{\\mathsf{(red,red),(red,black)}\\}$ and\n  $R_2=\\{\\mathsf{(red,red),(black,red)}\\}$ be the events corresponding\n  to a {\\sf red} ball in the $1$st and $2$nd draws, respectively, and\n  let $B_1=\\{\\mathsf{(black,red),(black,black)}\\}$ be the event of a\n  {\\sf black} ball on the first draw.\n\nNow $R_1$ and $B_1$ partition $\\Omega$ so we can  write:\n\\begin{eqnarray*}\nP(R_2)\n&=& \\P(R_2\\cap R_1) + \\P(R_2\\cap B_1)\\\\[6pt]\n&=& \\P\\;(R_2| R_1)\\P(R_1) + \\P(R_2|B_1)\\P(B_1)\\\\[6pt]\n&=& (4/14)(1/3)\\,+\\,(5/14)(2/3) =  1/3 \\enspace .\n\\end{eqnarray*}\n\\end{example}\n\n\\begin{framed}\n\\begin{prop}[Bayes' Theorem, 1763]\n Suppose the events $A_1,A_2,\\ldots,A_k \\in \\C{F}$, with $\\P(A_h)>0$ for each $h \\in \\{1,2,\\ldots,k\\}$, partition the sample space $\\Omega$, ie.~they are mutually exclusive (disjoint) and exhaustive events with positive probability: \n \\[\n A_i \\cap A_j = \\emptyset, \\ \\text{for any distinct $i,j \\in \\{1,2,\\ldots,k\\}$}, \\qquad \\bigcup_{h=1}^k A_h = \\Omega, \\qquad \\P(A_h) > 0\n \\]\n Thus, precisely one of the $A_h$'s will occur on any performance of our experiment $\\EE{E}$.  \n \n Let $B \\in \\C{F}$ be some event with $\\P(B) > 0$, then \n \\begin{equation}\\label{E:BayesThm}\n \\P(A_h|B) = \\frac{\\P(B|A_h) \\P(A_h)}{\\sum_{h=1}^k \\P(B|A_h) \\P(A_h)}\n \\end{equation}\n \\end{prop}\n\\end{framed}\n {\\scriptsize\n \\begin{proof}\n We apply elementary set theory, the definition of conditional probability $k+2$ times and the addition rule once:\n \\begin{eqnarray}\n \\P(A_h | B) &=& \\frac{\\P(A_h \\cap B)}{\\P(B)} = \\frac{\\P( B \\cap A_h)}{\\P(B)} = \n \\frac{\\P( B | A_h) \\P(A_h)}{\\P(B)}  \\notag \\\\\n &=& \\frac{\\P( B | A_h) \\P(A_h)}{\\P \\left( \\bigcup_{h=1}^k (B \\cap A_h) \\right)} =\n \\frac{\\P( B | A_h) \\P(A_h)}{\\sum_{h=1}^k \\P \\left( B \\cap A_h \\right)} \\notag \\\\\n &=& \\frac{\\P( B | A_h) \\P(A_h)}{\\sum_{h=1}^k \\P(B | A_h) \\P(A_h)} \\notag\n \\end{eqnarray}\nThe operations done to the denominator in the proof above is merely the total probability theorem:\n\\begin{equation*}\n\\P( B) = \\sum_{h=1}^k \\P(B | A_h) \\P(A_h)\n\\end{equation*}\n \\end{proof}\n}\n\nWe call $\\P(A_h)$ the {\\bf prior probability of} $A_h$, i.e., before observing $B$ or \\emph{a priori}, and $\\P(A_h|B)$ the {\\bf posterior probability of} $A_h$, i.e., after observing $B$ or \\emph{a posteriori}. \n\nThis theorem is at the heart of solving Bayesian \\emph{Decision Problems} which fall into several sub-problems called \\emph{inference}, \\emph{learning} and \\emph{control} problems.\nLet's see one of the simplest such \\emph{learning problems} called \\emph{prediction}, more specifically \\emph{classification}, where we need to choose between finitely many possible choices based on past information next.\n\n\\begin{example}[Wasserman2003~p.12]\\label{Wasserman2003p12}\nSuppose Larry divides his email into three categories: $A_1 = \\text{``spam''}$, $A_2 =\\text{ ``low priority''}$, and $A_3 = \\text{ ``high priority''}$.  From previous experience, he finds that $\\P(A_1) = 0.7$, $\\P(A_2) = 0.2$ and $\\P(A_3)=0.1$.  Note that $\\P(A_1 \\cup A_2 \\cup A_3) = \\P(\\Omega) = 0.7+0.2+0.1 = 1$.  Let $B$ be the event that the email contains the word ``free.''  From previous experience, $\\P(B|A_1) = 0.9$, $\\P(B|A_2) = 0.01$ and $\\P(B|A_3)=0.01$.  Note that $\\P(B|A_1) + \\P(B|A_2) + \\P(B|A_3) = 0.9+0.01+0.01 \\neq 1$.  Now, suppose Larry receives an email with the word ``free.''  What is the probability that it is ``spam,'' ``low priority,''  and ``high priority'' ?\n%{\\color{Gray}{\n\nSolution:\\\\[4pt]\n{\\scriptsize{\n\\[\n\\begin{array}{l l l l l}\n\\P(A_1 | B) \n&= \\frac{\\P(B|A_1)\\P(A_1)}{\\P(B|A_1)\\P(A_1)+\\P(B|A_2)\\P(A_2)+\\P(B|A_3)\\P(A_3)} \n&= \\frac{0.9 \\times 0.7}{(0.9 \\times 0.7)+ (0.01 \\times 0.2) + (0.01 \\times 0.1)}\n&= \\frac{0.63}{0.633}\n&\\approxeq 0.995 \\\\\n\\\\\n\\P(A_2 | B) \n&= \\frac{\\P(B|A_2)\\P(A_2)}{\\P(B|A_1)\\P(A_1)+\\P(B|A_2)\\P(A_2)+\\P(B|A_3)\\P(A_3)} \n&= \\frac{0.01 \\times 0.2}{(0.9 \\times 0.7)+ (0.01 \\times 0.2) + (0.01 \\times 0.1)}\n&= \\frac{0.002}{0.633}\n&\\approxeq 0.003 \\\\\n\\\\\n\\P(A_3 | B) \n&= \\frac{\\P(B|A_3)\\P(A_3)}{\\P(B|A_1)\\P(A_1)+\\P(B|A_2)\\P(A_2)+\\P(B|A_3)\\P(A_3)} \n&= \\frac{0.01 \\times 0.1}{(0.9 \\times 0.7)+ (0.01 \\times 0.2) + (0.01 \\times 0.1)}\n&= \\frac{0.001}{0.633}\n&\\approxeq 0.002 \\\\\n\\end{array}\n\\]\nNote that $\\P(A_1|B) + \\P(A_2|B)+\\P(A_3|B) = 0.995+0.003+0.002=1$.\n}}\n%}}\n\nThis is essentially the idea behind \\emph{Bayes classifiers}, that are used to solve such \\emph{prediction} problems across different problem domains in \\emph{statistical machine learning}, where solutions are given from computer programs.\n\\end{example}\n\n\\subsection{Independence and Dependence}\\label{S:IndepDep}\n\nIn general, $P(A | B)$ and $P(A)$ are different, but sometimes the\noccurrence of $B$ makes no difference, and gives no new information about the\nchances of $A$ occurring.  This is the idea behind independence. Events\nlike ``having blue eyes'' and ``having blond hair'' are\nassociated due to common genetic ancestry, but  events like ``my neighbour wins Lotto'' and ``I win Lotto'' are not due to the Lotto machine being chaotically whirled around before ejection (as modelled by a well-stirred urn).\n\n\\begin{definition}[Independence of two events]\\label{D:IndOf2Events}\n Any two events $A$ and $B$ are said to be {\\bf independent} if and only if\n \\begin{equation}\\label{E:PofAB=PAPB}\n \\P(A \\cap B) = \\P(A) \\P(B) \\ .\n \\end{equation}\n \\end{definition}\n Let us make sense of this definition in terms of our previous definitions.  When $\\P(A)=0$ or $\\P(B)=0$, both sides of the above equality are $0$.  If $\\P(A) \\neq 0$, then rearranging the above equation we get:\n \\[\n \\frac{\\P(A \\cap B)}{\\P(A)} = \\P(B) \\ .\n \\]\n But, the LHS is $\\P(B|A)$ by \\hyperref[E:CPD]{definition \\ref*{E:CPD}}, and thus for independent events $A$ and $B$, we get:\n \\[\n \\P(B|A) = \\P(B) \\ .\n \\]\nThis says that information about the occurrence of $A$ does not affect the occurrence of $B$.  If $\\P(B) \\neq 0$, then an analogous argument:\n{\\scriptsize\n\\[\n\\P(A \\cap B) = \\P(A) \\P(B) \\iff \\P(B \\cap A) = \\P(A) \\P(B) \\iff \\frac{\\P(B \\cap A)}{\\P(B)} = \\P(A) \\iff  \\P(A|B) = \\P(A) \\ ,\n\\]\n}\nsays that information about the occurrence of $B$ does not affect the occurrence of $A$.  Therefore, the probability of their joint occurence $\\P(A \\cap B)$ is simply the product of their individual probabilities $\\P(A) \\P(B)$.\n\n\\begin{definition}[Independence of a sequence of events]\\label{D:IndOfSeqOfEvents}\nWe say that a finite or infinite sequence of events $A_1,A_2,\\ldots$ are independent if whenever $i_1,i_2,\\ldots,i_k$ are distinct elements from the set of indices $\\Nz$, such that $A_{i_1},A_{i_2},\\ldots,A_{i_k}$ are defined (elements of $\\C{F}$), then\n\\[\n\\P(A_{i_1} \\cap A_{i_2} \\ldots \\cap A_{i_k})  =  \\P(A_{i_1} ) \\P(A_{i_2})  \\cdots \\P(A_{i_k}) \n\\]\n\\end{definition}\n\n\\begin{example}[Some Standard Examples]\\label{EX:SStsExs}\nA sequence of events in a sequence of independent trials is independent.\n\\be\n\n\\item[(a)] Suppose you toss a fair coin twice such that the first toss is independent of the second.  Then,\n$$\n\\P(\\mathsf{Heads} \\text{ on the first toss} \\cap \\mathsf{Tails} \\text{ on the second toss} ) = \\P(\\mathsf{H}) \\P(\\mathsf{T}) = \\frac{1}{2} \\times \\frac{1}{2}= \\frac{1}{4} \\enspace .\n$$\n\n\\item[(b)] Suppose you independently toss a fair die three times.  Let $E_i$ be the event that the outcome is an even number on the $i$-th trial.  The probability of getting an even number in all three trials is:\n\\begin{eqnarray*}\n\\P(E_1 \\cap E_2 \\cap E_3)\n&=& \\P(E_1) \\P(E_2) \\P(E_3)\\\\\n&=& \\left(\\P(\\{\\mathsf{2,4,6}\\})\\right)^3\\\\\n&=& \\left(\\P(\\{\\mathsf{2}\\} \\cup \\{\\mathsf{4}\\} \\cup \\{\\mathsf{6}\\}) \\right)^3 \\\\\n&=& \\left(\\P(\\{\\mathsf{2}\\}) + \\P(\\{\\mathsf{4}\\}) + \\P(\\{\\mathsf{6}\\})\\right)^3\\\\\n&=& \\left(\\frac{1}{6} + \\frac{1}{6} + \\frac{1}{6} \\right)^3 \n= \\left(\\frac{1}{2} \\right)^3\n= \\frac{1}{8} \\enspace .\n\\end{eqnarray*}\n%This is an obvious answer but there is a lot of maths going on here!\n\n\\item[(c)]Suppose you toss a fair coin independently $m$ times.  Then each of the $2^m$ possible outcomes in the sample space $\\Omega$ has equal probability of $\\frac{1}{2^m}$ due to independence.\n\\ee\n\\end{example}\n\n\\begin{example}[dependence and independence]\\label{EX:depAndindep} \nSuppose we toss two fair dice.  \nLet $A$ denote the event that the sum of the dice is six and $B$ denote the event that the first die equals four.  The sample space encoding the thirty six ordered pairs of outcomes for the two dice is $\\Omega = \\{ (1,1), (1,2), \\ldots, (1,6), (2,1), \\ldots, (2,6), \\ldots, (5,6), (6,6)\\}$ and due to independence $\\P(\\omega)=1/36$ for each $\\omega\\in\\Omega$.  \nThen \n\\[\n\\P(A \\cap B)  = \\P (\\{(4,2)\\}) = \\frac{1}{36} \\enspace ,\n\\]\nbut\n\\begin{eqnarray*}\n\\P(A)\\P(B) \n&=& \\P (\\{(1,5),(2,4),(3,3),(4,2),(5,1)\\}) \\P( \\{ (4,1),(4,2),(4,3),(4,4),(4,5),(4,6) \\}) \\\\\n&=& \\frac{5}{36}\\times \\frac{6}{36} = \\frac{5}{36}\\times\\frac{1}{6} = \\frac{5}{216} \\enspace ,\n\\end{eqnarray*}\nand therefore $A$ and $B$ are not independent.  \nThe reason for the events $A$ and $B$ being dependent is clear because the chance of getting a total of six depends on the outcome of the first die (not being six).\n\nNow, let $C$ be the event that the sum of the two dice equals seven.  \nThen\n\\[\n\\P(C \\cap B)  = \\P (\\{(4,3)\\}) = \\frac{1}{36} \\enspace ,\n\\]\nwhile\n\\begin{eqnarray*}\n\\P(C \\cap B)  \n&=& \\P (\\{(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)\\}) \\P( \\{ (4,1),(4,2),(4,3),(4,4),(4,5),(4,6) \\})\\\\\n&=& \\frac{6}{36}\\times\\frac{6}{36}= \\frac{1}{36} \\enspace ,\n\\end{eqnarray*}\nand therefore $C$ and $B$ are independent events.  Once again this is clear because the chance of getting a total of seven does not depend any more on the outcome of the first die (it is allowed to be any one of the six possible outcomes). \n\\end{example}\n\n\n\\begin{example}[Pairwise independent events that are not jointly independent]\\label{EX:2indButNotMutind}\nLet a ball be drawn from an well-stirred urn containing four balls labelled 1,2,3,4.  \nConsider the events $A = \\{1,2\\}$, $B=\\{1,3\\}$ and $C=\\{1,4\\}$.  \nThen,\n\\begin{eqnarray*}\n\\P(A \\cap B) &=& \\P(A)\\P(B) = \\frac{2}{4}\\times\\frac{2}{4} = \\frac{1}{4},\\\\\n\\P(A \\cap C) &=& \\P(A)\\P(C) = \\frac{2}{4}\\times\\frac{2}{4} = \\frac{1}{4},\\\\\n\\P(B \\cap C) &=& \\P(B)\\P(C) = \\frac{2}{4}\\times\\frac{2}{4} = \\frac{1}{4},\n\\end{eqnarray*}\nbut,\n\\[\n\\frac{1}{4} = \\P(\\{1\\}) = \\P (A \\cap B \\cap C) \\neq \\P(A)\\P(B)\\P(C) = \\frac{2}{4}\\times\\frac{2}{4}\\times\\frac{2}{4}=\\frac{1}{8} \\enspace .\n\\]\nTherefore, inspite of being pairwise independent, the events $A$, $B$ and $C$ are not jointly independent.\n\\end{example}\n\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 axioms and rules of probability.\n\\end{framed}\n\n\\input{ExsInConditionalProbability.tex}\n", "meta": {"hexsha": "37d5512387cf27b333f2be43a91487961000e069", "size": 52217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ProbabilityModel.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/ProbabilityModel.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/ProbabilityModel.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": 53.3916155419, "max_line_length": 689, "alphanum_fraction": 0.6784380566, "num_tokens": 17550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.8688267677469951, "lm_q1q2_score": 0.6075309584812775}}
{"text": "\\documentclass{memoir}\n\\usepackage{notestemplate}\n\n% \\begin{figure}[ht]\n%     \\centering\n%     \\incfig{riemmans-theorem}\n%     \\caption{Riemmans theorem}\n%     \\label{fig:riemmans-theorem}\n% \\end{figure}\n\n\\begin{document}\n\n\\section{Groups of Symmetries}\n\\label{sec:groups_of_symmetries}\n\nWhile the abstract definition of groups seems very natural, the construction of groups actually originated as a way to capture certain notions of physical systems. One important natural group arises from symmetries of geometric objects.\\\\\n\nLet \\(n \\in \\Z_+\\) be a positive integer with \\(n\\geq 3\\), and denote by \\(D_{2n}\\) the set of symmetries of a regular \\(n\\)-gon (the \\textbf{dihedral group}). We consider a symmetry to be any rigid motion that maintains the same locations of nodes of the \\(n\\)-gon (but the ordering of the nodes might differ).\\\\\n\nWe can uniquely describe a symmetry \\(s\\) by defining the permutation \\(\\sigma \\) on \\(\\left\\{ 1,2,\\ldots,n \\right\\} \\) that permutes the nodes. Notice, however, that not every permutation is allowed-- rotations do not change the relative ordering of the nodes, and reflections merely reverse the ordering of the nodes. In short, instead of the \\(n!\\) possible permutations, we are actually restricting ourselves to \\(2n\\) permutations-- the \\(n\\) permutations obtained by cycling the list, and the \\(n\\) permutations obtained by reversing each of those permutations.\\\\\n\nWe can make \\(D_{2n}\\) into a group by defining the oberation \\(st\\) for \\(s,t \\in D_{2n}\\), which is the symmetry obtained by first applying the transformations of \\(t\\), and then the transformations of \\(s\\). This is associative because it is the composition of functions; the identity is given by the identity permutation (fixing all vertices in place), and the inverse symmetry is the transformations that undoes the symmetries.\\\\\n\nIn fact, for any \\(n\\)-gon, all symmetries can be described as an element of \\(D_{2n}\\), and hence we will show some properties of \\(D_{2n}\\) that will allow us to utilize it better as group. We denote by \\(r\\) the transformation given by the rotation clockwise about the origin by \\(\\sfrac{2\\pi }{n}\\) radians, and \\(s\\) to be the reflection about the line of symmetry from the first index through the origin. Then \\(D_{2n}\\) has the following properties:\n\\begin{itemize}\n\t\\item \\(1,r,r^2,\\ldots,r^{n-1}\\) are all distinct, \\(r^{n}=1\\) and so \\(\\left| r \\right| =n\\)\n\t\\item \\(\\left| s \\right| =2\\) \n\t\\item \\(s \\neq r^{i}\\) for any \\(i\\) \n\t\\item \\(sr^{i}\\neq sr^{j}\\) for all \\(i\\neq j\\), \\(i,j<n\\)\n\\end{itemize}\nThese properties allow us to explicitly view the symmetry group by\n\\begin{align*}\n\tD_{2n}= \\left\\{1,r,r^2,\\ldots,r^{n-1}, s,sr, s r^2,\\ldots,s r^{n-1} \\right\\} \n\\end{align*}\nFurthermore, we have that \\(rs = s r ^{-1}\\), and \\(r^{i}s = s r^{-i}\\). These properties allow us to combine elements and simplify quickly, and hence are good to be familiar with.\n\n\\begin{exmp}\n\tConsider \\(n=12\\), and hence \\(D_{24}\\). To compose the symmetries given by \\((sr^{9})\\) and \\((s r^{6})\\), we get\n\t\\begin{align*}\n\t\t(s r^{9}) (s r^{6}) = s (r^{9}s)r^{6} = s(s r^{-9})r^{6} = s^{2}(r^{-3}) = r^{-3} = r^{9}\n\t\\end{align*}\n\\end{exmp}\n\n\\section{Groups of Permutations}\n\\label{sec:permutation_groups}\n\nWhen considering the construction of the dihedral group, one might be curious what occurs if one allows all permutations of nodes within the set. This in fact results in a group as well-- the permutaton group.\n\n\\begin{defn}[Permutation Group]\n\tLet \\(\\Omega \\) be a nonempty set and let \\(S_\\Omega \\) denote the set of all bijections from \\(\\Omega \\) to itself. \\(S_\\Omega \\) is a group under the operation of composition, and is referred to as the \\textbf{symmetric group on the set \\(\\Omega \\)}.\\\\\n\n\tIf \\(\\Omega  = \\left\\{ 1,2,3,\\ldots,n \\right\\} \\), the \\textbf{symmetric group of degree \\(n\\)} is denoted \\(S_n\\).\n\\end{defn}\n\nOne learns in combinatorics that the number of permutations of a set of size \\(n\\) is \\(n!\\), and so \\(\\left| S_n \\right| = n!\\).\\\\\n\nNow we will describe a clever notation that can be used to write elements \\(\\sigma \\) of \\(S_n\\) referred to as cycle decomposition.\n\n\\begin{defn}[Cycle Decomposition]\n\tA \\textbf{cycle} is a string of integers representing the elements of \\(S_n\\) which cyclically permutes these integers (and fixes all other integers). For example, the cycle \\((a_1a_2\\ldots a_m)\\) sends \\(a_1\\) to \\(a_2\\), \\(a_2\\) to \\(a_3\\), and so on, finally sending \\(a_m\\) to \\(a_1\\). Every element \\(\\sigma \\in S_n\\) can be described by following the rearrangement of integers until a cycle forms-- and then looking for the cycles in the remaining numbers. Thus, we can write a permutation in the form\n\t\\begin{align*}\n\t\t(a_1a_2\\ldots a_{m_1}) (a_{m_1+1}a_{m_1+2}\\ldots a_{m_2})\\ldots(a_{m_{k-1}+1}a_{m_{k-1}+2}\\ldots a_{m_k})\n\t\\end{align*}\n\twhich represents \\(k\\) different cycles that \\(\\sigma \\) partitions \\(\\Omega \\) into.\\\\\n\nThis allows us to quickly see how \\(\\sigma \\) acts on elements in \\(S_n\\). To calculate \\(\\sigma (x)\\), find \\(x\\) in the list, and if there is an integer to the right of it, then \\(\\sigma (x)\\) equals that integer. Otherwise, it is the end of the cycle and hence \\(\\sigma (x)\\) is the first element in the list.\\\\\n\nThe product of all the cycles is called the \\textbf{cycle decomposition} of \\(\\sigma \\).\n\\end{defn}\nThe \\textbf{length} of a given cycle is the number of integers that appears in it. A cycle of length \\(t\\) is called a \\(t\\)-cycle. Finally, two cycles are called \\textbf{disjoint} if they have no numbers in common (in a symmetric group, all cycles are disjoint).\\\\\n\nThis also makes it simple to find inverses, as the cycle decomposition of \\(\\sigma ^{-1}\\) is obtained by reversing the order of elements within each cycle. To compute compositions, first follow the cycle given in the first permutation, then the cycle in the second permutation.\\\\\n\nAs one works with more examples, they will quickly see that \\(S_n\\) is non-abelian for all \\(n\\geq 3\\). But of course, disjoint cycles commute, and so one can rearrange the cycles in any product of disjoint cycles without changing the permutation.\\\\\n\nExercise caution-- one will see that a permutation can be written via many different decompositions of cycles. However, there is only one unique decomposition into \\textit{disjoint} cycles.\n\n\\begin{cor}\nWith the combinatorial construction of a permutation, we say a permutation is even or odd based on the number of inversions. With this definition, we say that a permutation is even if and only if the permutation is the product of an even number of transpositions.\n\\end{cor}\nThus we can check if a permutation is even or odd by counting the number of even cycles. An odd cycle does not change parity, but an even cycle will. Thus, if a permutation has an even number of even cycles, it is even (parity of one). If instead the number of even cycles is odd, then it is an odd permutation (parity of negative one).\\\\\n\n\\begin{defn}[Permutation Groups]\n\tPermutation groups are subgroups of \\(S_n\\).\n\\end{defn}\nFor example, the dihedral group is merely one of many permutation groups.\\\\\n\nLet \\(A_n\\) denote the set of even permutations. This is clearly a subgroup of \\(S_n\\). \n\n\\begin{prop}\n\\begin{align*}\n\t\\left| S_n : A_n \\right| =2.\n\\end{align*}\n\\end{prop}\n\n\\begin{proof}\nObserve that there is a bijection from the even permutations to the odd permutations by simply transposing the first two elements.\n\\end{proof}\n\nWe will discuss the alternating group \\(A_n\\) momentarily.\n\n\\begin{hw}\nThe order of an element \\(g \\in S_n\\) is the LCM of the lengths of disjoint cycles.\n\\end{hw}\n\n\\end{document}\n", "meta": {"hexsha": "d5dcd04d58f9939f1935d330208bd0da782f551b", "size": 7625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Abstract Algebra - Introductory/Algebra I/Notes/source/2020-04-08-PermGroup.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": "Abstract Algebra - Introductory/Algebra I/Notes/source/2020-04-08-PermGroup.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": "Abstract Algebra - Introductory/Algebra I/Notes/source/2020-04-08-PermGroup.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": 71.261682243, "max_line_length": 569, "alphanum_fraction": 0.7180327869, "num_tokens": 2160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.885631484383387, "lm_q1q2_score": 0.607498434050881}}
{"text": "\\subsection{Strategy results}\n\\label{sec:results_strategy}\n\nTable \\ref{table:financial_metrics} shows the results of the benchmark and the\nstrategy under test. We can see that the estimate on the Sharpe Ratio is bigger\nfor benchmark than the strategy under test. Later, evaluation of the\nProbabilistic Sharpe Ratio will be used to analyze the confidence on the Sharpe\nRatio estimation for different reference values. Sortino ratio is bigger for the\nstrategy under test which is aligned with the win loss ratio observation. There\nare no considerable differences in other indexes with the exception of the\nvolatility which has a rough difference of two magnitude orders.\n\nTwo indices were not computed for the benchmark strategy: correlation to\nunderlying (because it would be equal to 1) and the return on execution cost.\nThe latter will just add noise because only two trades will be executed: one at\nthe start of the time series and one at the end. Finally, because of the low\nobserved correlation value we can state that both strategies are doing quite\ndifferent things.\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{| c | c | c |} \n    \\hline\n    \\multicolumn{3}{|c|}{Financial metrics} \\\\\n    \\hline\n    Metric & Buy and hold & Strategy under test \\\\\n    \\hline\n    Sharpe ratio & 2.2156 & 1.2289 \\\\\n    \\hline\n    Sortino ratio & 2.9138 & 5.7169 \\\\\n    \\hline\n    Win loss ratio & 1.1171 & 8.0973 \\\\\n    \\hline\n    Win rate & 0.5637 & 0.5833 \\\\\n    \\hline\n    Average return & 0.0073 & 0.0065 \\\\\n    \\hline \n    Volatility & 1.2062 & 0.0352 \\\\\n    \\hline\n    Correlation to underlying &  - & 0.0454 \\\\\n    \\hline\n    Return on execution costs & - & 21.2264 \\\\\n    \\hline\n  \\end{tabular}\n  \\caption{Financial metrics benchmark.}\n  \\label{table:financial_metrics}\n\\end{table}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{results/images/log_odds_ratio_psr.png}\n    \\caption{Odds ratio for the Probabilistic Sharpe Ratio of the buy and hold strategy and the strategy under test.}\n    \\label{fig:prob_sharpe_ratio}\n\\end{figure}\n\nBecause the Probabilistic Sharpe Ratio is compared against a sequence of target\nSharpe Ratios (0.01 increments between 0. and 1.), it is better shown in terms\nlog-odds ratio of the PSR values in figure \\ref{fig:prob_sharpe_ratio}. It is observed\nthat for both strategies the odds quickly drop to quite low values below Sharpe\nRatios above 0.1. This is explained by analyzing the Probabilistic Sharpe Ratio\nequation (\\ref{eqn:prob_sharpe_ratio}). The denominator of the test statistic,\ni.e. the standard error, is simply great because of the extremely large kurtosis\nand skewness coefficients that both strategies exhibit. See table \\ref{table:return_moments}\nand remember that the normal distribution has a skewness of 0 and a kurtosis\nof 3. Together with the table, figures\n\\ref{fig:b_h_return_distribution} and \\ref{fig:st_return_distribution} display\nhistograms for the return distributions.\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabular}{| c | c | c |} \n    \\hline\n    \\multicolumn{3}{|c|}{Moments of returns} \\\\\n    \\hline\n    Metric & Buy and hold & Strategy under test \\\\\n    \\hline\n    Mean of returns & 0.0073 & 0.0065 \\\\\n    \\hline\n    Variance of returns & 0.0039 & 3.4018 . $10^{-6}$ \\\\\n    \\hline\n    Skewness of returns & 0.2973 & 19.1115 \\\\\n    \\hline\n    Kurtosis of returns & 11.9335 & 450.5218 \\\\\n    \\hline\n  \\end{tabular}\n  \\caption{Moments of the returns for both strategies}\n  \\label{table:return_moments}\n\\end{table}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1.1\\textwidth]{results/images/hist_returns_btc.png}\n    \\caption{Buy and hold return distribution.}\n    \\label{fig:b_h_return_distribution}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1.1\\textwidth]{results/images/hist_returns_st.png}\n    \\caption{Strategy under test return distribution.}\n    \\label{fig:st_return_distribution}\n\\end{figure}\n", "meta": {"hexsha": "d3bc84ae2a8a5e4a791751ed605d64213ee1500d", "size": 3935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/results/financial_results.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/results/financial_results.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/results/financial_results.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": 38.2038834951, "max_line_length": 117, "alphanum_fraction": 0.7311308767, "num_tokens": 1116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540518, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.607472039573701}}
{"text": "% Every Latex document starts with a documentclass command\n\\documentclass[a4paper, 11pt]{article}\n\n% Load some packages\n\\usepackage{graphicx} % This allows you to put figures in\n\\usepackage{natbib}   % This allows for relatively pain-free reference lists\n\\usepackage[left=3cm,top=3cm,right=3cm]{geometry} % The way I like the margins\n\\usepackage{dsfont}\n\\usepackage{amsmath}\n\n\n% This helps with figure placement\n\\renewcommand{\\topfraction}{0.85}\n\\renewcommand{\\textfraction}{0.1}\n\n% Set values so you can have a title\n\\title{New Paper}\n\\author{Me}\n\\date{\\today}\n\n\n\n% Document starts here\n\\begin{document}\n\n%% Actually put the title in\n%\\maketitle\n\n%\\abstract{This is the abstract}\n\n% Need this after the abstract\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{8pt}\n\n\\section{Bright Sky Example}\nThis problem actually gave me headaches during my PhD until\nI thought harder about priors and realised why it was happening.\nConsider an $N \\times N$ image of a patch of sky. Without any noise,\nwe'd observe the `true' image, defined by the flux $f$ in each pixel:\n\\begin{align}\n\\textnormal{true image} &= \\left\\{f_{ij}\\right\\}\n\\end{align}\nThe true total flux of the patch of sky is\n\\begin{align}\nF &= \\sum_{i=1}^N \\sum_{i=1}^N f_{ij}.\n\\end{align}\n\nHowever, due to noise, we observe a perturbed version of the\nflux in each pixel. i.e. our data is noisy fluxes $D_{ij}$,\nsuch that\n\\begin{align}\np(D_{ij} | f_{ij}) &\\sim \\textnormal{Normal}\\left(f_{ij}, \\sigma^2\\right)\n\\end{align}\nAssuming $\\sigma$ is known, the likelihood\nwe'd need to infer the $f$s from the $D$s\nis therefore\n\\begin{align}\np\\left(\\{D_{ij}\\} | \\{f_{ij}\\}\\right)\n&\\propto \\exp\n\\left[\n  -\\frac{1}{2\\sigma^2}\\sum_{i=1}^N\\sum_{j=1}^N\n                  \\left(D_{ij} - f_{ij}\\right)^2\n\\right].\n\\end{align}\n\nWith this likelihood, we can infer the $f$s\n(the de-noised image) from the $D$s (the noisy data).\nWe know fluxes are non-negative, so $f_{ij} \\geq 0$.\n\nWith an implicit uniform prior on the $f$s,\ntry MCMC sampling and using the chain of $f$s to\nget a posterior for $F$. You should notice something\n``wrong'' with it, caused by the uniform prior.\n\n\n\n\\bibliographystyle{plainnat}\n\\bibliography{references}{}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "f9a0198d5cf902524d62c54ddb0c4aa802cd9c53", "size": 2189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/bright_sky.tex", "max_stars_repo_name": "dhuppenkothen/mcmcfail", "max_stars_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_stars_repo_licenses": ["MIT"], "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/bright_sky.tex", "max_issues_repo_name": "dhuppenkothen/mcmcfail", "max_issues_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_issues_repo_licenses": ["MIT"], "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/bright_sky.tex", "max_forks_repo_name": "dhuppenkothen/mcmcfail", "max_forks_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_forks_repo_licenses": ["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.3734939759, "max_line_length": 78, "alphanum_fraction": 0.7167656464, "num_tokens": 681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6074720376217396}}
{"text": "\\section{Order theory}\\label{sec:order_theory}\n\n\\term{Orders} are special \\hyperref[def:binary_relation]{binary relations} which, surprisingly, are used to compare elements in a \\hyperref[def:set]{set}. Order theory studies pairs \\( X = (X, \\leq) \\), where \\( X \\) is a set and \\( \\leq \\) is a \\hyperref[def:preordered_set]{preorder}.\n\nWe denote orders using symbols rather than letters because it is customary to write orders using \\hyperref[rem:first_order_formula_conventions/infix]{infix notation}, e.g. \\( a \\leq b \\) rather than \\( (a, b) \\in {\\leq} \\).\n\n\\begin{figure}[h]\n  \\caption{Hierarchy of ordered sets}\\label{fig:ordered_sets_hierarchy}\n  \\smallskip\n  \\hfill\n  \\begin{forest}\n    [\n      {\\hyperref[def:preordered_set]{Preordered sets}}\n        [{\\hyperref[def:directed_set]{Directed sets}}]\n        [\n          {\\hyperref[def:partially_ordered_set]{Partially ordered sets}}\n            [\n              {\\hyperref[def:totally_ordered_set]{Totally ordered set}}\n              [{\\hyperref[def:well_ordered_set]{Well-ordered set}}]\n            ]\n            [\n              {\\hyperref[def:semilattice]{Semilattices}}\n                [\n                  {\\hyperref[def:semilattice/lattice]{Lattices}}\n                    [\n                      {\\hyperref[def:heyting_algebra]{Heyting algebras}}\n                      [{\\hyperref[def:boolean_algebra]{Boolean algebras}}]\n                    ]\n                ]\n            ]\n        ]\n        [{\\hyperref[def:equivalence_relation]{Equivalence partition}}]\n      ]\n  \\end{forest}\n  \\hfill\\hfill\n\\end{figure}\n\n\\Fullref{subsec:well_ordered_sets} is focused on set theory, and hence we have included it in \\fullref{sec:set_theory} rather than here.\n\nGeneral (semi)lattices also admit algebraic definitions, however these algebraic descriptions have some drawbacks:\n\\begin{itemize}\n  \\item There is no general way to extend algebraic operations from finitary to infinitary. This can sometimes be circumvented if the order happens to carry more information about the partially ordered set than the algebraic operations --- see \\fullref{thm:binary_lattice_operations/new_lattice}.\n\n  \\item We often implicitly rely on the order structure, for example in \\hyperref[def:heyting_algebra]{the definition for Heyting algebras}.\n\\end{itemize}\n", "meta": {"hexsha": "8f154eece20b3645f8fec45e419a58d0e3a8895f", "size": 2290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/order_theory.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/order_theory.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/order_theory.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.7826086957, "max_line_length": 296, "alphanum_fraction": 0.6711790393, "num_tokens": 579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631541, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6074720364567663}}
{"text": "\\chapter{Other things}\n\n\n\n% \\section{Don’t use inline for long formulas}\n% \n% The change in \\cref{breaking inline math} tends to lead to problems with long formulas or equations, as the surrounding text has to be arranged in a way that they are contained in a single line.\n% This is a feature of \\cref{breaking inline math}:\n% If formulas and equations are too long then they should be put into display mode, not inline mode!\n% Compare the following two examples:\n% \\begin{LTXexample}[pos = b]\n%   Suppose that you have already written a bunch of text.\n%   Now you start talking about the inequality $\\lcm([L_1 : K],[L_2 : K]) \\leq [L_1 L_2 : K] \\leq [L_1 : K] [L_2 : K]$,\n%   which is a bit long.\n%   The surrounding text doesn’t really help when you want to focus on the formula.\n% \\end{LTXexample}\n% \\begin{LTXexample}[pos = b]\n%   Suppose that you have already written a bunch of text.\n%   Now you start talking about the inequality\n%   \\[\n%           \\lcm([L_1 : K],[L_2 : K])\n%     \\leq  [L_1 L_2 : K]\n%     \\leq  [L_1 : K] [L_2 : K]\n%   \\]\n%   which is a bit long.\n%   Now the surrounding text doesn’t matter when you want to focus on the formula.\n% \\end{LTXexample}\n\n\n\n\n\n% \\section{Put important things in display mode}\n% \n% Putting mathematical content in display mode distinguishes it from the surrounding text.\n% This can be used to emphasize its importance.\n% It therefore makes sense to put certain contents into display mode even though it’s short and can reasonable fit into inline mode.\n% \n% \\begin{LTXexample}[pos = b]\n%   If $I$ is an ideal in a commutative ring $R$ and $M$ is an $R$-module then\n%   \\[\n%     (R/I) \\otimes_R M\n%     \\cong\n%     M / IM \\,.\n%   \\]\n%   This will turn out to be a rather useful identity.\n% \\end{LTXexample}\n\n\n", "meta": {"hexsha": "69cacf034afae6c0016ba288f12173f3cc57b607", "size": 1758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/others.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/others.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/others.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": 35.16, "max_line_length": 196, "alphanum_fraction": 0.6814562002, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837581726991, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6074720309076339}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 4}\n\\subsection{Lecture Notes - Lagrangian Mechanics Part 4}\n\\subsubsection{Proof of Lagrange Equations for Holonomic Systems}\nWe consider a holonomic system with $f(\\v{r}_i, t) = 0$ constraints. Consider a true path $\\v{r}^*(t)$, and a general path with variation of $\\v{r}(t) = \\v{r}^*(t) + \\alpha\\delta\\v{r}(t)$ Note that $\\v{r}$ is not necessarily generalized coordinate. $\\v{r}(t)$ and $\\v{r}^*(t)$ are on a surface to which the particle is constrained; this implies that the variation is also constrained. Now, we study the action:\n\\[S[\\v{r}^* + \\alpha\\delta\\v{r}] = \\int_{t_1}^{t_2} \\LL[\\v{r}^* + \\alpha\\delta\\v{r}, \\dot{\\v{r}}^* + \\alpha\\delta\\dot{\\v{r}}, t]dt\\]\nNow, we do a Taylor expansion around the true path:\n\\begin{align*}\n    S[\\v{r}^* + \\alpha\\delta\\v{r}] &= \\int_{t_1}^{t_2} dt\\left(\\LL(\\v{r}^*, \\dot{\\v{r}}^*, t) + \\alpha\\delta\\v{r}\\dpd{\\LL}{\\v{r}} + \\alpha\\delta\\dot{\\v{r}}\\dpd{\\LL}{\\dot{\\v{r}}} + \\delta(\\alpha^2) \\right) \\quad \\text{First term is unperturbed action, so we can write as:}\n    \\\\ &= S[\\v{r}^*, \\dot{\\v{r}}^*, t] + \\alpha\\int_{t_1}^{t_2}dt\\dpd{\\LL}{\\v{r}}\\delta\\v{r} + \\alpha\\int_{t_1}^{t_2}dt\\dpd{\\LL}{\\dot{\\v{r}}}\\dod{}{}t + \\delta(\\alpha^2)\\quad\\text{Integrating by parts, we have:}\n    \\\\&= S[\\v{r}^*, \\dot{\\v{r}}^*, t] + \\alpha\\int_{t_1}^{t_2}dt\\dpd{\\LL}{\\v{r}}\\delta\\v{r} + \\left. \\dpd{\\LL}{\\dot{\\v{r}}}\\delta\\v{r}\\right|_{t_1}^{t_2} - \\int_{t_1}^{t_2}dt\\left(\\dod{}{t}\\dpd{\\LL}{\\dot{\\v{r}}}\\right)\\delta\\v{r}\\quad\\text{Boundary term is zero, so:}\n    \\\\&= S[\\v{r}^*, \\dot{\\v{r}}^*, t] + \\alpha\\int_{t_1}^{t_2}dt\\left(\\dpd{\\LL}{\\v{r}} - \\dod{}{t}\\dpd{\\LL}{\\dot{\\v{r}}}\\right)\\delta\\v{r} + \\delta(\\alpha^2)\n\\end{align*}\nThis is a first order variation (as we can tell from the fact that we expanded around $\\alpha$ to first order). This is given by:\n\\[\\delta S = \\lim_{\\alpha \\rightarrow 0}\\frac{1}{\\alpha}\\left(S[\\v{r}^* + \\alpha\\delta\\v{r}] -S[\\v{r}^*]\\right) = \\int_{t_1}^{t_2}dt\\left(\\dpd{\\LL}{\\v{r}} - \\dod{}{t}\\dpd{\\LL}{\\dot{\\v{r}}}\\right)\\delta\\v{r}\\]\nWe have that the first term $\\dpd{\\LL}{\\v{r}} = -\\grad{U}$ are conservative forces. Now considering the kinetic energy as $T = \\frac{m}{2}\\dot{\\v{r}}^2$, then the second term is $\\dod{}{t}\\dpd{\\LL}{\\dot{\\v{r}}} = m\\ddot{\\v{r}} = \\v{F}_{tot} = \\v{F}_{constraint} + \\v{F}_{conservative}$. The contribution to the action integral for the constraint forces are given by $-\\int_{t_1}^{t_2}\\delta\\v{r}\\cdot\\v{F}_{constaint} = 0$ as the constraint force is perpendicular to any direction for which we can actually very the path! Hence, the first order variation is given by:\n\\[\\delta S = -\\int_{t_1}^{t_2}\\delta\\v{r}\\cdot\\left(m\\ddot{\\v{r}} + \\grad{U}\\right)dt\\]\nIf the particle follows Newton's laws of motion, then $m\\ddot{\\v{r}} + \\grad{U} = 0$ and hence the first order variation is $\\delta S = 0$! The beauty of this formulation is the constraint forces do not contribute. Here, $\\delta\\v{r}$ must be consistent with the constraint. So for the generalized coordinate, any variation works, and $\\delta S[q] = 0$.\n\n\\end{document}", "meta": {"hexsha": "3cbcffb7dac74b12f51f288478701bde073f2b24", "size": 3105, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-4/Lecture-Notes-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/Lecture-Notes-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/Lecture-Notes-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": 141.1363636364, "max_line_length": 567, "alphanum_fraction": 0.6344605475, "num_tokens": 1229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911057, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6074720247760148}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% fphw Assignment\n% LaTeX Template\n% Version 1.0 (27/04/2019)\n%\n% This template originates from:\n% https://www.LaTeXTemplates.com\n%\n% Authors:\n% Class by Felipe Portales-Oliva (f.portales.oliva@gmail.com) with template \n% content and modifications by Vel (vel@LaTeXTemplates.com)\n%\n% Template (this file) License:\n% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%----------------------------------------------------------------------------------------\n%    PACKAGES AND OTHER DOCUMENT CONFIGURATIONS\n%----------------------------------------------------------------------------------------\n\n\\documentclass[\n    12pt, % Default font size, values between 10pt-12pt are allowed\n    %letterpaper, % Uncomment for US letter paper size\n    %spanish, % Uncomment for Spanish\n]{fphw}\n\n% Template-specific packages\n\\usepackage[utf8]{inputenc} % Required for inputting international characters\n\\usepackage[T1]{fontenc} % Output font encoding for international characters\n\\usepackage{fontspec,unicode-math} % Required for using utf8 characters in math mode\n\\usepackage{parskip}  % To add extra space between paragraphs\n% \\usepackage{mathpazo} % Use the Palatino font\n\\usepackage{graphicx} % Required for including images\n\\usepackage{booktabs} % Better horizontal rules in tables\n\\usepackage{hyperref} % For links (both internal and external)\n% \\usepackage{listings} % Required for insertion of code\n\\usepackage{enumerate}% To modify the enumerate environment\n\\usepackage{cleveref} % Better \\ref command -> \\cref\n\\usepackage{import}   % This 4 packages and the command allow importing pdf\n\\usepackage{xifthen}  % figures generated with inkscape\n\\usepackage{pdfpages} % Source: https://castel.dev/post/lecture-notes-2/\n\\usepackage{mathtools}\n\\usepackage{wrapfig}\n\\usepackage{cancel}\n\\usepackage{transparent}\n\\newcommand{\\incfig}[1]{%\n    \\def\\svgwidth{0.95\\columnwidth}\n    \\small\n        \\import{./images/}{#1.pdf_tex}\n}\n\n\\setlength{\\parindent}{15pt}\n\\setlength{\\headheight}{22.66pt}\n\n%----------------------------------------------------------------------------------------\n%    ASSIGNMENT INFORMATION\n%----------------------------------------------------------------------------------------\n\n\\title{Task 6 \\\\ Surface Gradient} % Assignment title\n\n\\author{Emilio Domínguez Sánchez} % Student name\n\n\\date{November 14th, 2020} % Due date\n\n\\institute{University of Murcia \\\\ Faculty of Mathematics} % Institute or school name\n\n\\class{Geometría de Superficies} % Course or class name\n\n\\professor{Dr. Pascual Lucas Saorin} % Professor or teacher in charge of the assignment\n\n%----------------------------------------------------------------------------------------\n%    Definitions\n%----------------------------------------------------------------------------------------\n\n\\usepackage{physics}\n\\newcommand{\\R}{\\mathbb{R}}\n\\newcommand{\\inner}[2]{\\left\\langle #1, \\; #2 \\right\\rangle}\n\\newcommand{\\tf}{\\tilde{f}}\n\\DeclareMathOperator{\\Ima}{Im}\n\\DeclareMathOperator{\\proj}{proj}\n\n\\begin{document}\n\n\\maketitle % Output the assignment title, created automatically using the information in the custom commands above\n\n%----------------------------------------------------------------------------------------\n%    ASSIGNMENT CONTENT\n%----------------------------------------------------------------------------------------\n\n\\section*{Problem}\n\n\\begin{problem}\n\n    The \\emph{gradient} of a differentiable function $f : S \\to \\R$ is the function\n$\\grad{f} : S \\to \\R^3$ that assigns each point $p \\in S$ the vector\n$\\grad{f}(p) \\in T_p \\subset \\R^3$ such that\n\n\\begin{equation*}\n    \\braket{\\grad{f}(p)}{v} = \\dd{f}_p(v)\n\\end{equation*}\n\n\\noindent\nfor each $v \\in T_pS$.\nThe gradient is a good example of a field of tangent vectors over $S$.\n\n    Prove that\n\n\\begin{enumerate}\n    \\item If $E$, $F$, and $G$ are the coefficients of the first fundamental form\n    for a parametrization $X : U \\subset \\R^2 \\to S$, then\n\n    \\begin{equation*}\n        \\grad{f} = \\frac{\\tf_uG - \\tf_vF}{EG-F^2}X_u + \\frac{\\tf_vE - \\tf_uF}{EG-F^2}X_v\n    \\end{equation*}\n\n    inside $X(U)$.\n    Where $\\tf = f \\circ X$ is the local representative of $f$ by $X$.\n\n    And in particular, if $S = \\R^2$ then the definition matches the usual definition\n    of gradient for functions defined over $\\R^2$.\n\n    \\item The gradient for a surface points in the direction (in the tangent space)\n    of greatest slope.\n\n    \\begin{equation*}\n        \\max\\qty{\\frac{\\dd{f}_p(v)}{\\norm{v}}}_{v \\in T_pS} =\n        \\max\\qty{\\dd{f}_p\\qty(\\frac{v}{\\norm{v}})}_{v \\in T_pS} =\n        \\dd{f}_p\\qty(\\frac{\\grad{f}(p)}{\\norm{\\grad{f}(p)}}).\n    \\end{equation*}\n\n    \\item If $\\grad{f} ≠ 0$ for every point of a contour line $C = f^{-1}(a)$,\n    then $C$ is a regular curve over $S$ and $\\grad{f}$ is orthogonal to $C$ in $C$.\n\n    \\begin{equation*}\n        0 \\notin \\grad{f}(C) \\implies\n        \\begin{dcases}\n            \\text{$C$ is a curve} \\\\\n            \\grad{f} \\perp C.\n        \\end{dcases}\n    \\end{equation*}\n\\end{enumerate}\n\n\\end{problem}\n\n%----------------------------------------------------------------------------------------\n\n\\subsection*{Answer}\n\n    \\textit{Riesz Theorem} states that for any linear functional $F$\nover a finite dimensional\\footnotemark Hilbert space (like $T_pS$),\nthere exists a vector $v$ such that $F = \\braket{v}{\\cdot}$.\nThis theorem justifies the definition of the gradient.\nThat the gradient points in the direction of greatest slope is a consequence of\n\\textit{Cauchy-Schwarz} inequality.\n%\n\\begin{equation*}\n    \\abs{\\braket{\\grad{f}(p)}{\\frac{v}{\\norm{v}}}} ≤ \\norm{\\grad{f}(p)}.\n\\end{equation*}\n%\nWhich is an equality when\n$\\braket{\\grad{f}(p)}{\\frac{\\grad{f}(p)}{\\norm{\\grad{f}(p)}}} = \\norm{\\grad{f}(p)} ≥ 0$.\nTherefore,\n%\n\\begin{equation*}\n    \\max\\qty{\\frac{\\dd{f}_p(v)}{\\norm{v}}}_{v \\in T_pS} =\n    \\frac{\\dd{f}_p(\\grad{f}(p))}{\\norm{\\grad{f}(p)}}.\n\\end{equation*}\n\n\\footnotetext{Actually, the theorem can also be proved\nfor infinite dimensional Hilbert spaces\nif the linear functional is continuous.}\n\n    Next we will find the expression of $f$ in the basis $\\qty{X_u, X_v}$.\n%\n\\begin{equation*}\n    \\grad{f} = c_uX_u + c_vX_v.\n\\end{equation*}\n%\nGiven that we have an expression for the dot product of $\\grad{f}$,\nour mind could be asking us to write\n$c_u = \\braket{\\grad{f}}{X_u}$ and $c_v = \\braket{\\grad{f}}{X_v}$.\nAnd although that is not true because $X_u$ and $X_v$ are not necesarilly ortonormal,\nwe can still deduce the values of $c_u$ and $c_v$ using those products,\nbecause\n%\n\\begin{alignat*}{2}\n    \\braket{\\grad{f}}{X_u} &=\n    \\braket{c_uX_u + c_vX_v}{X_u} &=\n    c_u\\braket{X_u}{X_u} + c_v\\braket{X_v}{X_u} &=\n    Ec_u + Fc_v \\qq{and} \\\\\n    \\braket{\\grad{f}}{X_v} &=\n    \\braket{c_uX_u + c_vX_v}{X_v} &=\n    c_u\\braket{X_u}{X_v} + c_v\\braket{X_v}{X_v} &=\n    Fc_u + Gc_v.\n\\end{alignat*}\n%\nWhich, using the differentail equal\n%\n\\begin{equation*}\n    \\begin{aligned}\n        \\braket{\\grad{f}}{X_u} &=\n        \\dd{f}(X_u) &= \\\\\n        \\braket{\\grad{f}}{X_v} &=\n        \\dd{f}(X_v) &=\n    \\end{aligned}\n    \\qq{(by definition of the differential)\\footnote{}}\n    \\begin{aligned}\n        = &\\tf_u &\\qq{and} \\\\\n        = &\\tf_v.\n    \\end{aligned}\n\\end{equation*}\n\n\\footnotetext{Or, reproducing the definitions, if so you prefer:\n$\\dd{f}(X_u) = \\dd{f} \\circ \\dd{X}(1, 0) = \\dd{\\tf}(1, 0) = \\tf_u$.}\n\n     Matching both expressions we get the system\n%\n\\begin{align*}\n    \\begin{dcases}\n        c_uE + c_vF = \\tf_u \\\\\n        c_uF + c_vG = \\tf_v\n    \\end{dcases}\n    \\implies\n    \\begin{dcases}\n        c_u(EG - F^2) = \\tf_uG - \\tf_vF \\\\\n        c_v(F^2 - GE) = \\tf_uF - \\tf_vE \\\\\n    \\end{dcases},\n    & \\qq{which,} \\\\\n    \\qq{if $EG-F^2 ≠ 0$, implies that} &\n    \\begin{dcases}\n        c_u = \\frac{\\tf_uG - \\tf_vF}{EG-F^2}X_u \\\\\n        c_v = \\frac{\\tf_vE - \\tf_uF}{EG-F^2}X_v &.\n    \\end{dcases}\n\\end{align*}\n%\nBut $EG-F^2$ cannot be zero, ultimately because $\\qty{X_u, X_v}$ is a basis of $T_pS$\nwhich in turn is because $\\dd{X}$ is inyective.\n\n    When the basis is taken to be orthogonal the expression is greatly simplified.\n%\n\\begin{equation*}\n    \\grad{f} =\n    \\frac{\\tf_uG - \\tf_vF}{EG-F^2}X_u + \\frac{\\tf_vE - \\tf_uF}{EG-F^2}X_v =\n    (F = 0) =\n    \\tf_u\\frac{X_u}{E} + \\tf_v\\frac{X_v}{G}.\n\\end{equation*}\n%\nAnd in particular, when $S = \\R^2$ and $X$ is taken to be the identity so that\n$X_u = \\mqty(1 & 0)$ and $X_v = \\mqty(0 & 1)$,\n$E = G = 1$, and the equation can be written as\n%\n\\begin{multline*}\n    \\grad{f} =\n    \\tf_u\\mqty(1 & 0) + \\tf_v\\mqty(0 & 1) =\n    \\mqty(\\tf_u & \\tf_v) = \\\\\n%\n    \\begin{multlined}\n\\text{\\Big(Where $\\tf_u = \\dd(f\\circ X)\\mqty(1 & 0) = \\dd{f}\\mqty(1 & 0) = \\pdv{f}{u}$} \\\\\n\\text{using the standard definition of differential.\\Big)}\n    \\end{multlined} \\\\\n%\n    \\mqty(\\pdv{f}{u} & \\pdv{f}{v}) =\n    \\grad{f},\n\\end{multline*}\n%\nwhere the last symbol is the traditional interpretation of the gradient.\n\n    Lastly, if $\\grad{f} ≠ 0$ for every point of a contour line $C = f^{-1}(a)$,\n$C$ should be a regular curve.\nThere is a similar result over $\\R^2$ that proves it using the implicit function theorem.\nBut, as usual when developing the theory about surfaces,\nwe do not have it defined or proved for surfaces.\nLuckily, the solution is, as usual, bringing the problem to $\\R^2$\nmaking use of $X$.\n\n    Fix $p \\in C$. We would like to start by proving that\n$\\grad{f}(p) ≠ 0 \\iff \\grad{\\tf}(X^{-1}(p)) ≠ 0$.\nSuch an intuitive statement would be hard to prove playing with the\n(clearly not-)inspiring expression we have derived for $\\grad{f}(p)$.\nInstead, it is easier to prove that $\\grad{f}(p) = 0 \\iff \\grad{\\tf}(X^{-1}(p)) = 0$.\n%\n\\begin{multline*}\n    \\grad{f}(p) = 0 \\iff\n    \\dd{f}(p) = 0 \\iff\n    \\qty(\\dd{X} biyective) \\iff \\\\\n    \\dd{f}(p)\\circ\\dd{X}(X^{-1}(p)) =\n        \\dd(f\\circ X)(X^{-1}(p)) = \\dd{\\tf}(X^{-1}(p)) = 0 \\iff \\\\\n    \\grad{\\tf}(X^{-1}(p)) = 0.\n\\end{multline*}\n\n    Now we will move the problem to $U$.\nDefine $\\tilde{C} = X^{-1}(C\\cap \\Ima{X})$.\nFrom here onwards, we write $q = X^{-1}(p)$ for simplicity.\nClearly, $q$ is in $\\tilde{C}$.\nBecause $\\grad{\\tf}(q) ≠ 0$, either $\\pdv{\\tf}{u}\\,(q) ≠ 0$ or $\\pdv{\\tf}{v}\\,(q) ≠ 0$.\nWithout loss of generality, assume it is $\\pdv{\\tf}{v}\\,(q)$.\nThen there exists a neighborhood $N$ of $q$ ($\\in \\R^2$) and\na differentiable function $v : (I := \\proj_{\\R}(N)) \\to N$ such that\n$\\qty{\\mqty(u & v(u))}_{u \\in I} = \\tilde{C} \\cap N$.\nThat means that locally, $\\tilde{C} = \\tilde{α}(I)$ where $\\tilde{α}(t) = \\mqty(t & v(t))$.\nAnd we can return our conclusion to $C$ writing\n%\n\\begin{equation*}\n    C \\cap \\qty(\\Ima X \\cap X(N)) =\n    \\qty(C \\cap \\Ima X) \\cap X(N) =\n    X(\\tilde{C} \\cap N) =\n    X(\\tilde{α}(I)).\n\\end{equation*}\n%\nNote that $X(N)$ is a neighborhood of $p$ because $X$ is an homeomorphism (thus it is open).\nHence, we have proved that there exists a neighborhood, $\\Ima X \\cap X(N)$, of $p$\non which $C$ is $X(α(I))$,\nfor $N$, $I$ and $α$ all dependent on $X$ and $p$.\nAnd in order to complete the argument,\nwe emphasize that $\\tilde{α} = \\qty[t \\mapsto \\mqty(t & v(t))]$ is clearly\ndifferentiable, regular\\footnotemark and inyective,\nand so would be $α(t) := X(\\tilde{α}(t))$,\ncompleting the argument that $C$ is a regular curve in $S$.\n\n\\footnotetext{Indeed, $\\dv{\\tilde{α}}{t} = \\mqty(1 & \\dv{v}{t}) ≠ 0$.\nAlso, the inyectivity is key to prove that $\\tilde{α}$ is an homeomorphism.}\n\n    In the previous conditions, $f(α(t)) = a$ is a constant function from $\\R$ to $\\R$.\n%\n\\begin{equation*}\n    0 = \\dd{(f \\circ α)}(t) = \\dd{f}(α(t))(\\dd{α}(t)) = \\braket{\\grad{f}(α(t))}{\\dd{α}(t)}\n    \\implies\n    \\grad{f}(p) \\perp T_pC.\n\\end{equation*}\n%\nWhere we have used the chain rule for functions defined between manifolds,\nthe definition of gradient and\nthe fact that the image of $\\dd{α}(t)$ generates $T_{α(t)}C$.\n\n%----------------------------------------------------------------------------------------\n\n\\end{document}\n", "meta": {"hexsha": "f27f25d0b099bf8d71cce6fa43b9aef14f9d19b1", "size": 11946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "surface-gradient.tex", "max_stars_repo_name": "useredsa/exercises-surfaces-geometry", "max_stars_repo_head_hexsha": "19b17a0a4c729e3a99f51ea285ae1539352c742b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-25T03:04:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-25T03:04:15.000Z", "max_issues_repo_path": "surface-gradient.tex", "max_issues_repo_name": "useredsa/introductory-exercises-of-differential-geometry", "max_issues_repo_head_hexsha": "19b17a0a4c729e3a99f51ea285ae1539352c742b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "surface-gradient.tex", "max_forks_repo_name": "useredsa/introductory-exercises-of-differential-geometry", "max_forks_repo_head_hexsha": "19b17a0a4c729e3a99f51ea285ae1539352c742b", "max_forks_repo_licenses": ["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.2389380531, "max_line_length": 114, "alphanum_fraction": 0.5873095597, "num_tokens": 3913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.607165818233023}}
{"text": "% Question  ##################################################################################################################\n\\section{Question 2}\\label{ssec:pt1q2}\n\\textbf{Modern or mean-variance portfolio theory (MPT) is a major cornerstone of financial theory. Based\non this theoretical breakthrough the Nobel Prize in Economics was awarded to its inventor, Harry\nMarkowitz, in 1990. Using the data from Question 1, we need to investigate the right allocation\nacross a portfolio made up of 3 investments, S\\&P500, FTSE 100 and Gold (SPDR). }\n\n% END Question  ##############################################################################################################\n\n% Question (i) ###############################################################################################################\n\n\\subsection{Q2 (i)}\\label{sssec:pt1q2i}\n\\textbf{In question 1, you identified the individual expected return and volatility of the 3 investments\nseparately. Calculate the expected return and volatility of the portfolio, considering equal weight for the 3 investments. }\n\n\\noindent\nCode for this question can be found in the notebook in section 'Question 2 (i)'. Before calculating both measurements for the portfolio, it was noted that there is some discrepancy between the dates of the assets. The dates of S\\&P500 and Gold were not matching with the dates for the FTSE100 index. To solve this dates were aligned to capture more accurate measurements. \n\n\\noindent\nTo calculate the annualized return and volatility for the portfolio a new function called ‘ann\\_ret\\_vol’ was created in the ‘fintech’ library as shown in Fig.~\\ref{fig:annretport}. This was later called from the notebook cell. As shown, this function takes three parameters. For first parameter a new pandas dataframe with the log returns for each asset was created (each column has the log returns for each asset). After doing so an equal weight was set as a numpy array and passed as a parameter. In this task it was assumed that a year has 250 days. \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .55]{imgs/annvolret.png}\n  \\caption{Function to measure expected returns and volatility for portfolio.}\n  \\label{fig:annretport}\n\\end{figure}\n\n\\noindent\nTo calculate the expected return for the portfolio the weighted sum of the mean return for each asset was taken and multiplied by the number of days (to annualize) as shown in Eq.~\\ref{eq:portret}.  \n\n\\begin{equation} \\label{eq:portret}\n   E(r) = \\Sigma w_i k_i\n\\end{equation}\n\n\\noindent\nOn the other hand, calculating portfolio risk is a bit more complicated than taking the sum of the weighted volatility of each asset. To calculate the volatility of the portfolio, first we need to find the covariance between the asset's returns, since the risk of an asset may be correlated with another asset. Eq.~\\ref{eq:portvol} shows how to calculate volatility for a portfolio with two assets but this can be easily extended to three assets when writing it in code as shown in Fig.~\\ref{fig:annretport}. The final measurements for the portfolio are shown in Fig.~\\ref{fig:portretvolresults}. \n\n\\begin{equation} \\label{eq:portvol}\n   \\sigma = \\sqrt{(w_1^2 \\sigma_1^2) + (w_2^2 \\sigma_2^2) + 2 (w_1) (w_2) (Corr(R_1, R_2) \\sigma_1 \\sigma_2)}     \n\\end{equation}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/portretvolresults.png}\n  \\caption{Results for portfolio volatility and returns.}\n  \\label{fig:portretvolresults}\n\\end{figure}\n\n% END Question (i) ###########################################################################################################\n\n% Question (ii) ##############################################################################################################\n\n\\subsection{Q2 (ii)}\\label{sssec:pt1q2ii}\n\n\\textbf{Investigate different portfolio expected return and volatility by simulating different random\nweights of your investments (2000 simulations). Assume that all weights have to be $>0$ and that the\nsum of all weights should be equal to 1. Create a plot showing the expected return (y-axis) and volatility (x-axis) for different/random portfolio weights.}\n\n\\noindent\nThe code for this simulation can be found in 'Question 2 (ii)' in the notebook and a function called 'annretvol\\_port\\_rand' was created in the 'fintech' library to simulate different weights for a portfolio as shown in Fig.~\\ref{fig:portsimulationcode}. The plot shown in Fig.~\\ref{fig:portsimulation} shows the expected return (y-axis) and the volatility (x-axis) for these simulations. \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/port_sim_code.png}\n  \\caption{Function to generate portfolio returns and volatility using random weights.}\n  \\label{fig:portsimulationcode}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/port_simulation.png}\n  \\caption{Portfolio returns and volatility using random weights (2000 Simulations).}\n  \\label{fig:portsimulation}\n\\end{figure}\n\n% END Question (ii) ##########################################################################################################\n\n% Question (iii) #############################################################################################################\n\n\\subsection{Q2 (iii)}\\label{sssec:pt1q2iii}\n\\textbf{Using an optimisation library (e.g. using solver in excel or an optimisation library in python),\nidentify the two portfolios that will return (a) the highest Sharpe ratio and (b) the lowest Value at \nRisk. For the Sharpe ratio, assume that the risk free rate is zero. Using the plot in question (ii), indicate the position of these two portfolios.}\n\n\\noindent\n\\textbf{In your answers explain the method/steps used.}\n\n\\noindent\nThe code for this question is shown in 'Question 2 (iii)' and as an optimization library a third party library called 'scipy.optimize' \\cite{python:scipy} was utilised for this process. For the highest Sharpe ratio a function called 'max\\_sharperatio\\_port' was created in the 'fintech' library as shown in Fig.~\\ref{fig:maxsharperatio}. \n\n\\noindent\nIn this function the third party library described, is used to minimize the negative Sharpe ratio which gives us the portfolio with the highest Sharpe ratio. The function which is being minimized is shown in Fig.~\\ref{fig:negsharperatio}. After the function finds the minimum, the values described in the code comments in Fig.~\\ref{fig:maxsharperatio} are returned. The final output for the highest Sharpe Ratio is shown in Fig.~\\ref{fig:maxsharperatioresults}. \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/maxsharpefunc.png}\n  \\caption{Function used to find the maximum Sharpe Ratio for a portfolio.}\n  \\label{fig:maxsharperatio}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/negsharperatio.png}\n  \\caption{The function being minimized to find the maximum Sharpe Ratio.}\n  \\label{fig:negsharperatio}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/maxsharperatioresults.png}\n  \\caption{The results for the portfolio with the max Sharpe Ratio.}\n  \\label{fig:maxsharperatioresults}\n\\end{figure}\n\n\\noindent\nFor the other measurement, which is the lowest VaR(99\\%) for the portfolio, another function was created called ‘min\\_var\\_port’ in the ‘fintech’ library as shown in Fig.~\\ref{fig:minvarport}. The same optimization library used to get the previous measurement was utilised.   \n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/minvarport.png}\n  \\caption{Function used to get the minimum VaR for a portfolio.}\n  \\label{fig:minvarport}\n\\end{figure}\n\n\\noindent\nSimilarly, to the previous function a value/function is being minimized to get the desired output. The function being minimized is the computed VaR using the covariance variance approach. This function is shown in Fig.~\\ref{fig:minimizeminvarport}. After the function finds the minimum, the values described in the code comments in Fig.~\\ref{fig:minvarport} are returned. The final output for the lowest VaR(99\\%) is shown in Fig.~\\ref{fig:minvarresults}.\n\n\\noindent \nFinally these measurements were plotted on the same plot used in (ii) where the red star indicates the portfolio with the maximum Sharpe Ratio and the green star indicates the portfolio with the lowest VaR(99\\%). This plot is shown in Fig.~\\ref{fig:portsimbest}.\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/varminimize.png}\n  \\caption{The function being minimized to find the lowest VaR.}\n  \\label{fig:minimizeminvarport}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/minvarresults.png}\n  \\caption{The results for the portfolio with the lowest VaR.}\n  \\label{fig:minvarresults}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .65]{imgs/port_simulation_best.png}\n  \\caption{The portfolio with the Highest Sharpe Ratio (Red Star) and with the lowest VaR(99\\%) (Green Start) on the plot used in (ii).}\n  \\label{fig:portsimbest}\n\\end{figure}\n\n% END Question (iii) #########################################################################################################", "meta": {"hexsha": "3968e332226aa70de3a4040ba473f556bdcb6c1d", "size": 9143, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/LaTeX/sections/1_part/2_question.tex", "max_stars_repo_name": "achmand/ari5122_assignment", "max_stars_repo_head_hexsha": "0322dfc77303bf77ca5acbacee4efc659765ab42", "max_stars_repo_licenses": ["MIT"], "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/LaTeX/sections/1_part/2_question.tex", "max_issues_repo_name": "achmand/ari5122_assignment", "max_issues_repo_head_hexsha": "0322dfc77303bf77ca5acbacee4efc659765ab42", "max_issues_repo_licenses": ["MIT"], "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/LaTeX/sections/1_part/2_question.tex", "max_forks_repo_name": "achmand/ari5122_assignment", "max_forks_repo_head_hexsha": "0322dfc77303bf77ca5acbacee4efc659765ab42", "max_forks_repo_licenses": ["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.7581699346, "max_line_length": 597, "alphanum_fraction": 0.6979109701, "num_tokens": 2222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056040203136, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.6071383553842506}}
{"text": "\\chapter{Differential forms}\nIn this chapter, all vector spaces are finite-dimensional\nreal inner product spaces.\nWe first start by (non-rigorously) drawing pictures\nof all the things that we will define in this chapter.\nThen we re-do everything again in its proper algebraic context.\n\n\\section{Pictures of differential forms}\nBefore defining a differential form,\nwe first draw some pictures.\nThe key thing to keep in mind is\n\\begin{moral}\n\t``The definition of a differential form is:\n\tsomething you can integrate.'' \\\\ --- Joe Harris\n\\end{moral}\n\nWe'll assume that all functions are \\vocab{smooth},\ni.e.\\ infinitely differentiable.\n\nLet $U \\subseteq V$ be an open set of a vector space $V$.\nSuppose that we have a function $f : U \\to \\RR$, i.e.\\\nwe assign a value to every point of $U$.\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tdot(\"$3$\", (-2,1), red);\n\t\tdot(\"$\\sqrt2$\", (-1,-1), red);\n\t\tdot(\"$-1$\", (2,2), red);\n\t\tdot(\"$0$\", (-3,-3), red);\n\t\\end{asy}\n\\end{center}\n\\begin{definition}\n\tA \\vocab{$0$-form} $f$ on $U$ is just a smooth function $f : U \\to \\RR$.\n\\end{definition}\nThus, if we specify a finite set $S$ of points in $U$\nwe can ``integrate'' over $S$ by just adding up the values\nof the points:\n\\[ 0 + \\sqrt 2 + 3 + (-1) = 2 + \\sqrt2. \\]\nSo, \\textbf{a $0$-form $f$ lets us integrate over $0$-dimensional ``cells''}.\n\nBut this is quite boring, because as we know we like\nto integrate over things like curves, not single points.\nSo, by analogy, we want a $1$-form to let us integrate\nover $1$-dimensional cells: i.e.\\ over curves.\nWhat information would we need to do that?\nTo answer this, let's draw a picture of a curve $c$,\nwhich can be thought of as a function $c : [0,1] \\to U$.\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tpair a = (-2,-2);\n\t\tpair b = (3,0);\n\t\tpair p = (0,1);\n\t\tpair q = (2,0);\n\t\tlabel(\"$c$\", q, dir(45), heavygreen);\n\t\tdot(a, heavygreen);\n\t\tdot(b, heavygreen);\n\t\tdraw(a..p..q..b, heavygreen);\n\t\tdot(\"$p$\", p, dir(90), blue);\n\t\tpair v = p+1.5*dir(-10);\n\t\tlabel(\"$v$\", v, dir(50), blue);\n\t\tdraw(p--v, blue, EndArrow);\n\t\\end{asy}\n\\end{center}\nWe might think that we could get away\nwith just specifying a number on every point of $U$\n(i.e.\\ a $0$-form $f$), and then somehow ``add up''\nall the values of $f$ along the curve.\nWe'll use this idea in a moment, but we can in fact do something more general.\nNotice how when we walk along a smooth curve, at every point $p$\nwe also have some extra information: a \\emph{tangent vector} $v$.\nSo, we can define a $1$-form $\\alpha$ as follows.\nA $0$-form just took a point and gave a real number,\nbut \\textbf{a $1$-form will take both a point \\emph{and} a tangent\nvector at that point, and spit out a real number.}\nSo a $1$-form $\\alpha$ is a smooth function on pairs $(p,v)$,\nwhere $v$ is a tangent vector at $p$, to $\\RR$.  Hence\n\\[ \\alpha : U \\times V \\to \\RR. \\]\n\nActually, for any point $p$, we will require that $\\alpha(p,-)$\nis a linear function in terms of the vectors:\ni.e.\\ we want for example that $\\alpha(p,2v) = 2\\alpha(p,v)$.\nSo it is more customary to think of $\\alpha$ as:\n\\begin{definition}\n\tA \\vocab{$1$-form} $\\alpha$ is a smooth function\n\t\\[ \\alpha : U \\to V^\\vee. \\]\n\\end{definition}\nLike with $Df$, we'll use $\\alpha_p$ instead of $\\alpha(p)$.\nSo, at every point $p$, $\\alpha_p$ is some linear functional\nthat eats tangent vectors at $p$, and spits out a real number.\nThus, we think of $\\alpha_p$ as an element of $V^\\vee$;\n\\[ \\alpha_p \\in V^\\vee. \\]\n\nNext, we draw pictures of $2$-forms.\nThis should, for example, let us integrate over a blob\n(a so-called $2$-cell) of the form\n\\[ c : [0,1] \\times [0,1] \\to U \\]\ni.e.\\ for example, a square in $U$.\nIn the previous example with $1$-forms,\nwe looked at tangent vectors to the curve $c$.\nThis time, at points we will look at \\emph{pairs} of tangent vectors\nin $U$: in the same sense that lots of tangent vectors\napproximate the entire curve, lots of tiny squares\nwill approximate the big square in $U$.\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tfilldraw( (-2,-2)--(-2,2)--(2,2)--(2,-2)--cycle, \n\t\t\topacity(0.4) + orange, red);\n\t\tlabel(\"$c$\", (2,2), dir(45), red);\n\t\tfor (real t = -1; t < 2; t += 1) {\n\t\t\tdraw( (-2,t)--(2,t), red );\n\t\t\tdraw( (t,-2)--(t,2), red );\n\t\t}\n\t\tpair p = (-1, -1);\n\t\tdot(\"$p$\", p, dir(225), blue);\n\t\tpair v = p + dir(90);\n\t\tpair w = p + dir(0);\n\t\tdraw(p--v, blue, EndArrow);\n\t\tdraw(p--w, blue, EndArrow);\n\t\tlabel(\"$v$\", v, dir(135), blue);\n\t\tlabel(\"$w$\", w, dir(-45), blue);\n\t\\end{asy}\n\\end{center}\nSo what should a $2$-form $\\beta$ be?\nAs before, it should start by taking a point $p \\in U$,\nso $\\beta_p$ is now a linear functional:\nbut this time, it should be a linear map on two vectors $v$ and $w$.\nHere $v$ and $w$ are not tangent so much as their span cuts out\na small parallelogram. So, the right thing to do is in fact consider\n\\[ \\beta_p \\in V^\\vee \\wedge V^\\vee. \\]\nThat is, to use the wedge product to get a handle on\nthe idea that $v$ and $w$ span a parallelogram.\nAnother valid choice would have been $(V \\wedge V)^\\vee$;\nin fact, the two are isomorphic, but it will be more convenient\nto write it in the former.\n\n\\section{Pictures of exterior derivatives}\nNext question:\n\\begin{moral}\n\tHow can we build a $1$-form from a $0$-form?\n\\end{moral}\nLet $f$ be a $0$-form on $U$; thus, we have a function $f : U \\to \\RR$.\nThen in fact there is a very natural $1$-form on $U$ arising\nfrom $f$, appropriately called $df$.\nNamely, given a point $p$ and a tangent vector $v$,\nthe differential form $(df)_p$ returns the \\emph{change in $f$ along $v$}.\nIn other words, it's just the total derivative $(Df)_p(v)$.\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tdot(\"$3$\", (-2,1), red);\n\t\tdot(\"$\\sqrt2$\", (-1,-1), red);\n\t\tdot(\"$-1$\", (2,2), red);\n\t\tdot(\"$0$\", (-3,-3), red);\n\t\tdraw((-1,-1)--(0,1), blue, EndArrow);\n\t\tlabel(\"$\\sqrt2 + \\varepsilon$\", (0,1), dir(90), blue);\n\t\tlabel(\"$v$\", (-0.5, 0), dir(0), blue);\n\t\\end{asy}\n\\end{center}\nThus, $df$ measures ``the change in $f$''.\n\nNow, even if I haven't defined integration yet,\ngiven a curve $c$ from a point $a$ to $b$, what do you think\n\\[ \\int_c df \\]\nshould be equal to?\nRemember that $df$ is the $1$-form that measures\n``infinitesimal change in $f$''.\nSo if we add up all the change in $f$ along a path from $a$ to $b$,\nthen the answer we get should just be\n\\[ \\int_c df = f(b) - f(a). \\]\nThis is the first case of something we call Stokes' theorem.\n\nGeneralizing, how should we get from a $1$-form to a $2$-form?\nAt each point $p$, the $2$-form $\\beta$ gives a $\\beta_p$\nwhich takes in a ``parallelogram'' and returns a real number.\nNow suppose we have a $1$-form $\\alpha$.\nThen along each of the edges of a parallelogram,\nwith an appropriate sign convention the $1$-form $\\alpha$ gives\nus a real number.\nSo, given a $1$-form $\\alpha$, we define $d\\alpha$\nto be the $2$-form that takes in a parallelogram\nspanned by $v$ and $w$,\nand returns \\textbf{the measure of $\\alpha$ along the boundary}.\n\nNow, what happens if you integrate $df$ along the entire square $c$?\nThe right picture is that, if we think of each little square\nas making up the big square, then the adjacent boundaries cancel out,\nand all we are left is the main boundary.\nThis is again just a case of the so-called Stokes' theorem.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tfilldraw( (-2,-2)--(-2,2)--(2,2)--(2,-2)--cycle, \n\t\t\topacity(0.4) + orange, red);\n\t\tlabel(\"$c$\", (2,2), dir(45), red);\n\t\tfor (real t = -1; t < 2; t += 1) {\n\t\t\tdraw( (-2,t)--(2,t), red );\n\t\t\tdraw( (t,-2)--(t,2), red );\n\t\t}\n\t\tpair p = (-1, -1);\n\t\tdot(\"$p$\", p, dir(225), blue);\n\t\tpair v = p + dir(90);\n\t\tpair w = p + dir(0);\n\t\tpair x = w + v - p;\n\t\tdraw(p--w, blue, EndArrow);\n\t\tdraw(w--x, blue, EndArrow);\n\t\tdraw(x--v, blue, EndArrow);\n\t\tdraw(v--p, blue, EndArrow);\n\t\\end{asy}\n\t\\hspace{4em}\n\t\\begin{minipage}[t]{6.2cm}\n\t\t\\includegraphics[width=6cm]{media/stokes-patch.png}\n\t\t\\\\ \\scriptsize Image from \\cite{img:stokes}\n\t\\end{minipage}\n\\end{center}\n\n\n\\section{Differential forms}\n\\prototype{Algebraically,\n\tsomething that looks like $f \\ee_1^\\vee \\wedge \\ee_2^\\vee + \\dots$,\n\tand geometrically, see the previous section.}\n\nLet's now get a handle on what $dx$ means.\nFix a real vector space $V$ of dimension $n$,\nand let $\\ee_1$, \\dots, $\\ee_n$ be a standard basis.\nLet $U$ be an open set.\n\n\\begin{definition}\n\tWe define a \\vocab{differential $k$-form} $\\alpha$ on $U$\n\tto be a smooth (infinitely differentiable) map\n\t$\\alpha : U \\to \\Lambda^k(V^\\vee)$.\n\t(Here $\\Lambda^k(V^\\vee)$ is the wedge product.)\n\\end{definition}\n\nLike with $Df$, we'll use $\\alpha_p$ instead of $\\alpha(p)$.\n\n\\begin{example}\n\t[$k$-forms for $k=0,1$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\item A $0$-form is just a function $U \\to \\RR$.\n\t\t\\item A $1$-form is a function $U \\to V^\\vee$.\n\t\tFor example,\n\t\tthe total derivative $Df$ of a function $V \\to \\RR$ is a $1$-form.\n\t\t\\item Let $V = \\RR^3$ with standard basis $\\ee_1$, $\\ee_2$, $\\ee_3$.\n\t\tThen a typical $2$-form is given by\n\t\t\\[\n\t\t\t\\alpha_p\n\t\t\t=\n\t\t\tf(p) \\cdot \\ee_1^\\vee \\wedge \\ee_2^\\vee\n\t\t\t+ g(p) \\cdot \\ee_1^\\vee \\wedge \\ee_3^\\vee\n\t\t\t+ h(p) \\cdot \\ee_2^\\vee \\wedge \\ee_3^\\vee\n\t\t\t\\in \\Lambda^2(V)\n\t\t\\]\n\t\twhere $f,g,h : V \\to \\RR$ are smooth functions.\n\t\\end{enumerate}\n\\end{example}\n\nNow, by the projection principle (\\Cref{thm:project_principle}) we only have to specify\na function on each of $\\binom nk$ basis elements of $\\Lambda^k(V^\\vee)$.\nSo, take any basis $\\{e_i\\}$ of $V$, and \ntake the usual basis for $\\Lambda^k(V^\\vee)$ of elements\n\\[ e_{i_1}^\\vee \\wedge e_{i_2}^\\vee \\wedge \\dots \\wedge e_{i_k}^\\vee. \\]\nThus, a general $k$-form takes the shape\n\\[ \\alpha_p = \\sum_{1 \\le i_1 < \\dots < i_k \\le n} \n\tf_{i_1, \\dots, i_k}(p) \\cdot\n\te_{i_1}^\\vee \\wedge e_{i_2}^\\vee \\wedge \\dots \\wedge e_{i_k}^\\vee. \\]\nSince this is a huge nuisance to write, we will abbreviate this to just\n\\[ \\alpha = \\sum_I f_I \\cdot de_I \\]\nwhere we understand the sum runs over $I = (i_1, \\dots, i_k)$,\nand $de_I$ represents $e_{i_1}^\\vee \\wedge \\dots \\wedge e_{i_k}^\\vee$.\n\nNow that we have an element $\\Lambda^k(V^\\vee)$, what can it do?\nWell, first let me get the definition on the table, then tell you what it's doing.\n\\begin{definition}\n\tFor linear functions $\\xi_1, \\dots, \\xi_k \\in V^\\vee$\n\tand vectors $v_1, \\dots, v_k \\in V$, set\n\t\\[\n\t\t(\\xi_1 \\wedge \\dots \\wedge \\xi_k)(v_1, \\dots, v_k)\n\t\t\\defeq\n\t\t\\det\n\t\t\\begin{bmatrix}\n\t\t\t\\xi_1(v_1) & \\dots & \\xi_1(v_k) \\\\\n\t\t\t\\vdots & \\ddots & \\vdots \\\\\n\t\t\t\\xi_k(v_1) & \\dots & \\xi_k(v_k)\n\t\t\\end{bmatrix}.\n\t\\]\n\tYou can check that this is well-defined\n\tunder e.g. $v \\wedge w = -w \\wedge v$ and so on.\n\\end{definition}\n\n\\begin{example}\n\t[Evaluation of a differential form]\n\tSet $V = \\RR^3$.\n\tSuppose that at some point $p$, the $2$-form $\\alpha$ returns\n\t\\[ \\alpha_p = 2 \\ee_1^\\vee \\wedge \\ee_2^\\vee + \\ee_1^\\vee \\wedge \\ee_3^\\vee. \\]\n\tLet $v_1 = 3\\ee_1 + \\ee_2 + 4\\ee_3$ and $v_2 = 8\\ee_1 + 9\\ee_2 + 5\\ee_3$.\n\tThen\n\t\\[\n\t\t\\alpha_p(v_1, v_2)\n\t\t=\n\t\t2\\det \\begin{bmatrix}\n\t\t\t3 & 8 \\\\ 1 & 9 \\end{bmatrix}\n\t\t+\n\t\t\\det \\begin{bmatrix}\n\t\t\t3 & 8 \\\\ 4 & 5 \\end{bmatrix}\n\t\t= 21.\n\t\\]\n\\end{example}\n\nWhat does this definition mean?\nOne way to say it is that\n\\begin{moral}\n\tIf I walk to a point $p \\in U$,\n\ta $k$-form $\\alpha$ will take in $k$ vectors $v_1, \\dots, v_k$\n\tand spit out a number, which is to be interpreted as a (signed) volume.\n\\end{moral}\n\nPicture:\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$U$\");\n\t\tpair p = (-2,-2);\n\t\tdot(\"$p$\", p, dir(225), red);\n\t\tpair p1 = p + 1.4*dir(120);\n\t\tpair p2 = p + 1.7*dir(10);\n\t\tdraw(p--p1, red, EndArrow);\n\t\tdraw(p--p2, red, EndArrow);\n\t\tlabel(\"$v_1$\", p1, dir(p1-p), red);\n\t\tlabel(\"$v_2$\", p2, dir(p2-p), red);\n\t\tlabel(\"$\\alpha_p(v_1, v_2) \\in \\mathbb R$\", p+dir(45)*3);\n\t\\end{asy}\n\\end{center}\n\nIn other words, at every point $p$, we get a function $\\alpha_p$.\nThen I can feed in $k$ vectors to $\\alpha_p$ and get a number,\nwhich I interpret as a signed volume of the parallelpiped spanned by the $\\{v_i\\}$'s\nin some way (e.g.\\ the flux of a force field).\nThat's why $\\alpha_p$ as a ``function'' is contrived to lie in the wedge product:\nthis ensures that the notion of ``volume'' makes sense, so that for example,\nthe equality $\\alpha_p(v_1, v_2) = -\\alpha_p(v_2, v_1)$ holds.\n\nThis is what makes differential forms so fit for integration.\n\n\n\\section{Exterior derivatives}\n\\prototype{Possibly $dx_1 = \\ee_1^\\vee$.}\nWe now define the exterior derivative $df$ that we gave\npictures of at the beginning of the section.\nIt turns out that the exterior derivative is easy to compute\ngiven explicit coordinates to work with.\n\nFirst, given a function $f : U \\to \\RR$,\nwe define\n\\[ df \\defeq Df = \\sum_i \\frac{\\partial f_i}{\\partial e_i} e_i^\\vee \\]\nIn particular, suppose $V = \\RR^n$ and $f(x_1, \\dots, x_n) = x_1$\n(i.e.\\ $f = \\ee_1^\\vee$). Then:\n\\begin{ques}\n\tShow that for any $p \\in U$, \\[ \\left( d(\\ee_1^\\vee) \\right)_p = \\ee_1^\\vee. \\]\n\\end{ques}\n\n\\begin{abuse}\n\tUnfortunately, someone somewhere decided\n\tit would be a good idea to use ``$x_1$'' to denote $\\ee_1^\\vee$\n\t(because \\emph{obviously}\\footnote{Sarcasm.} $x_1$ means\n\t``the function that takes $(x_1, \\dots, x_n) \\in \\RR^n$ to $x_1$'')\n\tand then decided that \\[ dx_1 \\defeq \\ee_1^\\vee. \\]\n\tThis notation is so entrenched that I have no choice\n\tbut to grudgingly accept it.\n\tNote that it's not even right,\n\tsince technically it's $(dx_1)_p = \\ee_1^\\vee$; $dx_1$ is a $1$-form.\n\t\\label{abuse:dx}\n\\end{abuse}\n\\begin{remark}\n\tThis is the reason why we use the notation $\\frac{df}{dx}$ in calculus now:\n\tgiven, say, $f : \\RR \\to \\RR$ by $f(x) = x^2$, it is indeed true that\n\t\\[ df = 2x \\cdot \\ee_1^\\vee = 2x \\cdot dx \\]\n\tand so by (more) abuse of notation we write $df/dx = 2x$.\n\\end{remark}\n\nMore generally, we can define the \\vocab{exterior derivative}\nin terms of our basis $e_1$, \\dots, $e_n$ as follows:\nif $\\alpha = \\sum_I f_I de_I$ then we set\n\\[ d\\alpha \\defeq \\sum_I df_I \\wedge de_I\n\t= \\sum_I \\sum_j \\fpartial{f_I}{e_j} de_j \\wedge de_I. \\]\nThis doesn't depend on the choice of basis.\n\n\\begin{example}[Computing some exterior derivatives]\n\tLet $V = \\RR^3$ with standard basis $\\ee_1$, $\\ee_2$, $\\ee_3$.\n\tLet $f(x,y,z) = x^4 + y^3 + 2xz$.\n\tThen we compute\n\t\\[ df = Df = (4x^3+2z) \\; dx + 3y^2 \\; dy + 2x \\; dz. \\]\n\tNext, we can evaluate $d(df)$ as prescribed: it is\n\t\\begin{align*}\n\t\td^2f &= (12x^2 \\; dx + 2 dz) \\wedge dx + (6y \\; dy) \\wedge dy\n\t\t+ 2(dx \\wedge dz) \\\\\n\t\t&= 12x^2 (dx \\wedge dx) + 2(dz \\wedge dx) + 6y (dy \\wedge dy) + 2(dx \\wedge dz) \\\\\n\t\t&= 2(dz \\wedge dx) + 2(dx \\wedge dz) \\\\\n\t\t&= 0.\n\t\\end{align*}\n\tSo surprisingly, $d^2f$ is the zero map.\n\tHere, we have exploited \\Cref{abuse:dx} for the first time,\n\tin writing $dx$, $dy$, $dz$.\n\\end{example}\nAnd in fact, this is always true in general:\n\\begin{theorem}[Exterior derivative vanishes]\n\t\\label{thm:dd_zero}\n\tLet $\\alpha$ be any $k$-form.\n\tThen $d^2(\\alpha) = 0$.\n\tEven more succinctly, \\[ d^2 = 0. \\]\n\\end{theorem}\nThe proof is left as \\Cref{prob:dd_zero}.\n\\begin{exercise}\n\tCompare the statement $d^2 = 0$ to the geometric\n\tpicture of a $2$-form given at the beginning of this chapter.\n\tWhy does this intuitively make sense?\n\\end{exercise}\n\nHere are some other properties of $d$:\n\\begin{itemize}\n\t\\ii As we just saw, $d^2 = 0$.\n\t\\ii For a $k$-form $\\alpha$ and $\\ell$-form $\\beta$, one can show that\n\t\\[ d(\\alpha \\wedge \\beta) = d\\alpha \\wedge \\beta + (-1)^k (\\alpha \\wedge d\\beta). \\]\n\t\\ii If $f \\colon U \\to \\RR$ is smooth, then $df = Df$.\n\\end{itemize}\nIn fact, one can show that $df$ as defined above is\nthe \\emph{unique} map sending $k$-forms to $(k+1)$-forms\nwith these properties.\nSo, one way to define $df$ is to take as axioms\nthe bulleted properties above\nand then declare $d$ to be the unique solution to this functional equation.\nIn any case, this tells us that our definition of $d$\ndoes not depend on the basis chosen.\n\nRecall that $df$ measures the change in boundary.\nIn that sense, $d^2 = 0$ is saying something like\n``the boundary of the boundary is empty''.\nWe'll make this precise when we see Stokes' theorem in the next chapter.\n\n\\section{Closed and exact forms}\nLet $\\alpha$ be a $k$-form.\n\\begin{definition}\n\tWe say $\\alpha$ is \\vocab{closed} if $d\\alpha = 0$.\n\\end{definition}\n\\begin{definition}\n\tWe say $\\alpha$ is \\vocab{exact} if for some $(k-1)$-form $\\beta$,\n\t$d\\beta = \\alpha$.  If $k = 0$, $\\alpha$ is exact only when $\\alpha = 0$.\n\\end{definition}\n\\begin{ques}\n\tShow that exact forms are closed.\n\\end{ques}\n\nA natural question arises: are there closed forms\nwhich are not exact?\nSurprisingly, the answer to this question is tied to topology.\nHere is one important example.\n\n\\begin{example}\n\t[The angle form]\n\t\\label{ex:angle_form}\n\tLet $U = \\RR^2 \\setminus \\{0\\}$,\n\tand let $\\theta(p)$ be the angle formed by the $x$-axis\n\tand the line from the origin to $p$.\n\n\tThe $1$-form $\\alpha : U \\to (\\RR^2)^\\vee$ defined by\n\t\\[ \\alpha = \\frac{-y \\; dx + x \\; dy}{x^2+y^2} \\]\n\tis called the \\vocab{angle form}:\n\tgiven $p \\in U$ it measures the change in angle $\\theta(p)$\n\talong a tangent vector.\n\tSo intuitively, ``$\\alpha = d\\theta$''.\n\tIndeed, one can check directly that the angle form is closed.\n\n\tHowever, $\\alpha$ is not exact: there is no global smooth\n\tfunction $\\theta : U \\to \\RR$ having $\\alpha$ as a derivative.\n\tThis reflects the fact that one can actually perform\n\ta full $2\\pi$ rotation around the origin, i.e.\\ $\\theta$\n\tonly makes sense mod $2\\pi$.\n\tThus existence of the angle form $\\alpha$ reflects\n\tthe possibility of ``winding'' around the origin.\n\\end{example}\n\nSo the key idea is that the failure of a closed form to be exact\ncorresponds quite well with ``holes'' in the space:\nthe same information that homotopy and homology groups are trying to capture.\nTo draw another analogy, in complex analysis Cauchy-Goursat\nonly works when $U$ is simply connected.\nThe ``hole'' in $U$ is being detected by the existence of a form $\\alpha$.\nThe so-called de Rham cohomology will make this relation explicit.\n\n\\section\\problemhead\n\\begin{problem}\n\tShow directly that the angle form\n\t\\[ \\alpha = \\frac{-y \\; dx + x \\; dy}{x^2+y^2} \\]\n\tis closed.\n\\end{problem}\n  \n\\begin{problem}\n\t\\label{prob:dd_zero}\n\tEstablish \\Cref{thm:dd_zero}, which states that $d^2 = 0$.\n\t\\begin{hint}\n\t\tThis is just a summation.\n\t\tYou will need the fact that mixed partials are symmetric.\n\t\\end{hint}\n\\end{problem}\n", "meta": {"hexsha": "5feee29bcfdad160193e958eeb741992142178f0", "size": 18225, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/diffgeo/forms.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/diffgeo/forms.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/diffgeo/forms.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.9467455621, "max_line_length": 87, "alphanum_fraction": 0.6558024691, "num_tokens": 6415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6071193943493761}}
{"text": "\\chapter{Introduction to Proof with HOL}\\label{proof}\n\n\\newcommand\\tacticline{\\hline \\hline}\n\\newenvironment{proofenumerate}{\\begin{enumerate}}{\\end{enumerate}}\n% proofenumerate is distinguished from a normal enumeration so that\n% h e v e a can spot these special cases and treat them better.\n\n\n\\paragraph{Preliminaries} This chapter discusses the nature of proof\nin \\HOL{} in more detail.  The previous chapter has provided a broad\noverview of how proof is done in \\HOL{}, while here the emphasis is on\nattaining a more thorough grounding in the material.  As before, we\nare using \\texttt{<holdir>/bin/hol}.\n\n\\setcounter{sessioncount}{0}\n\nFor a logician, one definition of a formal proof is that it is a\nsequence, each of whose elements is either an {\\it axiom\\/} or follows\nfrom earlier members of the sequence by a {\\it rule of inference\\/}.\nA theorem is the last element of a proof.\n\nTheorems are represented in \\HOL{} by values of an abstract type\n{\\small\\verb|thm|}.  The only way to create theorems is by generating\nsuch a proof.  In \\HOL, following \\LCF, this consists in applying\n\\ML{} functions representing {\\it rules of inference\\/} to axioms or\npreviously generated theorems.  The sequence of such applications\ndirectly corresponds to a logician's proof.\n\nThere are five axioms of the \\HOL{} logic and eight primitive\ninference rules. The axioms are bound to ML names. For example, the Law of\nExcluded Middle is bound to the \\ML{} name {\\small\\verb|BOOL_CASES_AX|}:\n\n\\begin{session}\n\\begin{verbatim}\n- BOOL_CASES_AX;\n> val it = |- !t. (t = T) \\/ (t = F) : thm\n\\end{verbatim}\n\\end{session}\n\nTheorems are printed with a preceding turnstile {\\small\\verb+|-+} as\nillustrated above; the symbol `{\\small\\verb|!|}' is the universal\nquantifier `$\\forall$'.  Rules of inference are \\ML{} functions that\nreturn values of type {\\small\\verb|thm|}.  An example of a rule of\ninference is {\\it specialization\\/} (or $\\forall$-elimination).  In\nstandard `natural deduction' notation this is:\n\n\\[ \\Gamma\\turn \\uquant{x}t\\over \\Gamma\\turn t[t'/x]\\]\n\n\\begin{itemize}\n\\item $t[t'/x]$ denotes the result of substituting $t'$ for free\noccurrences of $x$ in $t$, with the restriction that no free variables in $t'$\nbecome bound after substitution.\n\\end{itemize}\n\n\\noindent This rule is represented in \\ML\\\nby a function\n{\\small\\verb|SPEC|},\\footnote{{\\tt SPEC} is not a\nprimitive rule of inference in the HOL logic, but is a derived rule. Derived rules\nare described in Section~\\ref{forward}.}\nwhich takes as arguments a term\n{\\small\\verb|``|}$a${\\small\\verb|``|} and a theorem\n{\\small\\verb%|- !%}$x${\\small\\verb|.|}$t[x]$ and returns the theorem\n{\\small\\verb%|- %}$t[a]$, the result of substituting $a$ for $x$ in $t[x]$.\n\n\\begin{session}\n\\begin{verbatim}\n- val Th1 = BOOL_CASES_AX;\n> val Th1 = |- !t. (t = T) \\/ (t = F) : thm\n\n- val Th2 = SPEC ``1 = 2`` Th1;\n> val Th2 = |- ((1 = 2) = T) \\/ ((1 = 2) = F) : thm\n\\end{verbatim}\n\\end{session}\n\nThis session consists of a proof of two steps: using an axiom and\napplying the rule \\ml{SPEC}; it interactively performs the following proof:\n\n\n\\begin{proofenumerate}\n\\item $ \\turn \\uquant{t} t=\\top\\ \\disj\\  t=\\bot$ \\hfill\n[Axiom \\ml{BOOL\\_CASES\\_AX}]\n\\item $ \\turn (1{=}2)=\\top\\ \\disj\\ (1{=}2)=\\bot$\\hfill [Specializing line 1 to `$1{=}2$']\n\\end{proofenumerate}\n\nIf the argument to an \\ML{} function representing a rule of inference\nis of the wrong kind, or violates a condition of the rule, then the\napplication fails.  For example, $\\ml{SPEC}\\ t\\ th$ will fail if $th$\nis not of the form $\\ml{|-\\ !}x\\ml{.}\\cdots$ or if it is of this form\nbut the type of $t$ is not the same as the type of $x$, or if the free\nvariable restriction is not met.  When one of the standard\n\\ml{HOL\\_ERR} exceptions is raised, more information about the failure\ncan often be gained by using the \\ml{Raise} function.\n\n\\begin{session}\n\\begin{verbatim}\n- SPEC ``1=2`` Th2;\n! Uncaught exception:\n! HOL_ERR <poly>\n\n- SPEC ``1 = 2`` Th2 handle e => Raise e;\n\nException raised at Thm.SPEC:\n\n! Uncaught exception:\n! HOL_ERR <poly>\n\\end{verbatim}\n\\end{session}\nHowever, as this session illustrates, the failure token does not\nalways indicate the exact reason for failure. The failure conditions\nfor rules of inference are given in \\REFERENCE.\n\nA proof in the \\HOL{} system is constructed by repeatedly applying\ninference rules to axioms or to previously proved theorems.  Since\nproofs may consist of millions of steps, it is necessary to provide\ntools to make proof construction easier for the user.  The proof\ngenerating tools in the \\HOL{} system are just those of \\LCF, and are\ndescribed later.\n\nThe general form of a theorem is $t_1,\\ldots,t_n\\ $\\ml{|-}$\\ t$, where\n$t_1$, $\\ldots$ , $t_n$ are boolean terms called the {\\it assumptions}\nand $t$ is a boolean term called the {\\it conclusion\\/}.  Such a\ntheorem asserts that if its assumptions are true then so is its\nconclusion.  Its truth conditions are thus the same as those for the\nsingle term\n$(t_1${\\small\\verb|/\\|}$\\ldots${\\small\\verb|/\\|}$t_n$)\\ml{==>}$t$.\nTheorems with no assumptions are printed out in the form \\ml{|-}$\\ t$.\n\nThe five axioms and eight primitive inference rules of the \\HOL{} logic\nare described in detail in the document \\DESCRIPTION.  Every value of\ntype \\ml{thm} in the \\HOL{} system can be obtained by repeatedly\napplying primitive inference rules to axioms.  When the \\HOL{} system\nis built, the eight primitive rules of inference are defined and the\nfive axioms are bound to their \\ML{} names, all other predefined\ntheorems are proved using rules of inference as the system is\nmade.\\footnote{This is a slight over-simplification.} This is one of\nthe reasons why building \\ml{hol} takes so long.\n\nIn the rest of this chapter, the process of {\\it forward proof\\/},\nwhich has just been sketched, is described in more detail.  In\nChapter~\\ref{tactics} {\\it goal directed proof\\/} is described,\nincluding the important notions of {\\it tactics\\/} and {\\it\n  tacticals\\/}, due to Robin Milner.\n\n\\section{Forward proof}\n\\label{forward}\n\nThree of the primitive inference rules of the \\HOL{} logic are\n\\ml{ASSUME} (assumption introduction), \\ml{DISCH} (discharging or\nassumption elimination) and \\ml{MP} (Modus Ponens).  These rules will\nbe used to illustrate forward proof and the writing of derived rules.\n\nThe inference rule \\ml{ASSUME} generates theorems of the form \\ml{$t$\n  |- $t$}. Note, however, that the \\ML{} printer prints each\nassumption as a dot (but this default can be changed; see below).  The\nfunction \\ml{dest\\_thm} decomposes a theorem into a pair consisting of\nlist of assumptions and the conclusion.\n\n\\begin{session}\n\\begin{verbatim}\n- val Th3 = ASSUME ``t1==>t2``;;\n> val Th3 =  [.] |- t1 ==> t2 : thm\n\n- dest_thm Th3;\n> val it = ([``t1 ==> t2``], ``t1 ==> t2``) : term list * term\n\\end{verbatim}\n\\end{session}\n\nA sort of dual to \\ml{ASSUME} is the primitive inference rule\n\\ml{DISCH} (discharging, assumption elimination) which infers from\na theorem of the form $\\cdots t_1\\cdots\\ml{\\ |-\\ }t_2$ the new theorem\n$\\cdots\\ \\cdots\\ \\ml{|-}\\ t_1\\ml{==>}t_2$. \\ml{DISCH} takes as arguments\nthe term to be discharged (\\ie\\ $t_1$) and the theorem from whose\nassumptions it is to be discharged and returns the result of the discharging.\nThe following session illustrates this:\n\n\\begin{session}\n\\begin{verbatim}\n- val Th4 = DISCH ``t1==>t2`` Th3;\n> val Th4 = |- (t1 ==> t2) ==> t1 ==> t2 : thm\n\\end{verbatim}\n\\end{session}\nNote that the term being discharged need not be in the assumptions; in\nthis case they will be unchanged.\n\n\\begin{session}\\begin{verbatim}\n- DISCH ``1=2`` Th3;\n> val it =  [.] |- (1 = 2) ==> t1 ==> t2 : thm\n\n- dest_thm it;\n> val it = ([``t1 ==> t2``], ``(1 = 2) ==> t1 ==> t2``) : term list * term\n\\end{verbatim}\\end{session}\n\n    In \\HOL\\, the rule \\ml{MP} of Modus Ponens is specified in\n    conventional notation by:\n\\[\n\\Gamma_1 \\turn t_1 \\imp t_2 \\qquad\\qquad \\Gamma_2\\turn t_1\\over\n\\Gamma_1 \\cup \\Gamma_2 \\turn t_2\n\\]\nThe \\ML{} function \\ml{MP} takes argument theorems of the form\n\\ml{$\\cdots\\ $|-$\\ t_1$\\ ==>\\ $t_2$} and \\ml{$\\cdots\\ $|-$\\ t_1$} and\nreturns \\ml{$\\cdots\\ $|-$\\ t_2$}. The next session illustrates the use\nof \\ml{MP} and also a common error, namely not supplying the \\HOL\\\nlogic type checker with enough information.\n\n\\begin{session}\\begin{verbatim}\n- val Th5 = ASSUME ``t1``;\n<<HOL message: inventing new type variable names: 'a.>>\n! Uncaught exception:\n! HOL_ERR <poly>\n- val Th5 = ASSUME ``t1`` handle e => Raise e;\n<<HOL message: inventing new type variable names: 'a.>>\n\nException raised at Thm.ASSUME:\nnot a proposition\n! Uncaught exception:\n! HOL_ERR <poly>\n\n- val Th5 = ASSUME ``t1:bool``;\n> val Th5 =  [.] |- t1 : thm\n\n- val Th6 = MP Th3 Th5;\n> val Th6 =  [..] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n    The hypotheses of \\ml{Th6} can be inspected with the \\ML{} function\n    \\ml{hyp}, which returns the list of assumptions of a theorem (the\n    conclusion is returned by \\ml{concl}).\n\n\\begin{session}\\begin{verbatim}\n- hyp Th6;\n> val it = [``t1 ==> t2``, ``t1``] : term list\n\\end{verbatim}\\end{session}\n\n    \\HOL{} can be made to print out hypotheses of theorems explicitly\n    by setting the global flag \\ml{show\\_assums} to true.\n\n\\begin{session}\\begin{verbatim}\n- show_assums := true;\n> val it = () : unit\n\n- Th5;\n> val it =  [t1] |- t1 : thm\n\n- Th6;\n> val it =  [t1 ==> t2, t1] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n\n\\noindent Discharging \\ml{Th6} twice establishes the theorem\n\\ml{|-\\ t1 ==> (t1==>t2) ==> t2}.\n\n\\begin{session}\\begin{verbatim}\n- val Th7 = DISCH ``t1==>t2`` Th6;\n> val Th7 = [t1] |- (t1 ==> t2) ==> t2 : thm\n\n- val Th8 = DISCH ``t1:bool`` Th7;\n> val Th8 = |- t1 ==> (t1 ==> t2) ==> t2 : thm\n\\end{verbatim}\\end{session}\n\n    The sequence of theorems: \\ml{Th3}, \\ml{Th5}, \\ml{Th6}, \\ml{Th7},\n    \\ml{Th8} constitutes a proof in \\HOL{} of the theorem \\ml{|-\\ t1\n      ==> (t1 ==> t2) ==> t2}. In standard logical notation this proof\n    could be written:\n\n\\begin{proofenumerate}\n\\item $ t_1\\imp t_2\\turn t_1\\imp t_2$ \\hfill\n[Assumption introduction]\n\\item $ t_1\\turn t_1$ \\hfill\n[Assumption introduction]\n\\item $ t_1\\imp t_2,\\ t_1 \\turn t_2 $ \\hfill\n[Modus Ponens applied to lines 1 and 2]\n\\item $ t_1 \\turn (t_1\\imp t_2)\\imp t_2$ \\hfill\n[Discharging the first assumption of line 3]\n\\item $ \\turn t_1 \\imp (t_1 \\imp t_2) \\imp t_2$ \\hfill\n[Discharging the only assumption of line 4]\n\\end{proofenumerate}\n\n\\subsection{Derived rules}\n\n\nA {\\it proof from hypothesis $th_1, \\ldots, th_n$} is a sequence each\nof whose elements is either an axiom, or one of the hypotheses $th_i$,\nor follows from earlier elements by a rule of inference.\n\nFor example, a proof of $\\Gamma,\\ t'\\turn t$ from the hypothesis\n$\\Gamma\\turn t$ is:\n\n\n\\begin{proofenumerate}\n\\item $ t'\\turn t'$ \\hfill [Assumption introduction]\n\\item $ \\Gamma\\turn t$ \\hfill [Hypothesis]\n\\item $ \\Gamma\\turn t'\\imp t$ \\hfill [Discharge $t'$ from line 2]\n\\item $ \\Gamma,\\ t'\\turn t$ \\hfill [Modus Ponens applied to lines 3 and 1]\n\\end{proofenumerate}\n\n\\noindent This proof works for any hypothesis of the form $\\Gamma\\turn t$\nand any boolean term $t'$ and shows that the result of adding an\narbitrary hypothesis to a theorem is another theorem (because the four\nlines above can be added to any proof of $\\Gamma\\turn t$ to get a\nproof of $\\Gamma,\\ t'\\turn t$).\\footnote{This property of the logic is\n  called {\\it monotonicity}.} For example, the next session uses this\nproof to add the hypothesis \\ml{``t3``} to \\ml{Th6}.\n\n\\begin{session}\\begin{verbatim}\n- val Th9 = ASSUME ``t3:bool``;\n> val Th9 = [t3] |- t3 : thm\n\n- val Th10 = DISCH ``t3:bool`` Th6;\n> val Th10 = [t1 ==> t2, t1] |- t3 ==> t2 : thm\n\n- val Th11 = MP Th10 Th9;\n> val Th11 = [t1 ==> t2, t1, t3] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n\n    A {\\it derived rule\\/} is an \\ML{} procedure that generates a proof\n    from given hypotheses each time it is invoked. The hypotheses are\n    the arguments of the rule.  To illustrate this, a rule, called\n    \\ml{ADD\\_ASSUM}, will now be defined as an \\ML{} procedure that\n    carries out the proof above. In standard notation this would be\n    described by:\n\n\\[ \\Gamma\\turn t\\over \\Gamma,\\ t'\\turn t \\]\n\n\\noindent The \\ML{} definition is:\n\n\\begin{session}\\begin{verbatim}\n- fun ADD_ASSUM t th = let\n    val th9 = ASSUME t\n    val th10 = DISCH t th\n  in\n    MP th10 th9\n  end;\n> val ADD_ASSUM = fn : term -> thm -> thm\n\n- ADD_ASSUM ``t3:bool`` Th6;\n> val it =  [t1, t1 ==> t2, t3] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n\\noindent The body of \\ml{ADD\\_ASSUM} has been coded  to mirror  the proof done\nin session~10 above, so as to show how an interactive proof can be\ngeneralized into a procedure.  But \\ml{ADD\\_ASSUM} can be written much\nmore concisely as:\n\n\\begin{session}\\begin{verbatim}\n- fun ADD_ASSUM t th = MP (DISCH t th) (ASSUME t);\n> val ADD_ASSUM = fn : term -> thm -> thm\n\n- ADD_ASSUM ``t3:bool`` Th6;\nval it = [t1 ==> t2, t1, t3] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n\n    Another example of a derived inference rule is \\ml{UNDISCH}; this\n    moves the antecedent of an implication to the assumptions.\n\n\\[ \\Gamma\\turn t_1\\imp t_2 \\over\\Gamma,\\ t_1\\turn t_2 \\]\n\n\\noindent An \\ML{} derived rule that implements this is:\n\n\n\\begin{session}\\begin{verbatim}\n- fun UNDISCH th = MP th (ASSUME(#1(dest_imp(concl th))));\n> val UNDISCH = fn : thm -> thm\n\n- Th10;\n> val it =  [t1 ==> t2, t1] |- t3 ==> t2 : thm\n\n- UNDISCH Th10;\n> val it =  [t1, t1 ==> t2, t3] |- t2 : thm\n\\end{verbatim}\\end{session}\n\n\\noindent Each time \\ml{UNDISCH\\ $\\Gamma\\turn t_1\\imp t_2$} is executed,\nthe following proof is performed:\n\n\\begin{proofenumerate}\n\\item $ t_1\\turn t_1$ \\hfill [Assumption introduction]\n\\item $ \\Gamma\\turn t_1\\imp t_2$ \\hfill [Hypothesis]\n\\item $ \\Gamma,\\ t_1\\turn t_2$ \\hfill [Modus Ponens applied to lines 2 and 1]\n\\end{proofenumerate}\n\nThe rules \\ml{ADD\\_ASSUM} and \\ml{UNDISCH} are the first derived rules\ndefined when the \\HOL{} system is built. For a description of the main\nrules see the section on derived rules in \\DESCRIPTION.\n\n\\subsection{Rewriting}\n\nAn important derived rule is \\ml{REWRITE\\_RULE}.  This takes a list of\nconjunctions of equations, \\ie\\ a list of theorems of the form:\n\n\\[ \\Gamma\\turn (u_1 = v_1) \\conj (u_2 = v_2) \\conj \\ldots\\ \\conj (u_n  = v_n)\\]\n\n\\noindent  and a theorem\n$\\Delta\\turn t$ and repeatedly replaces instances of $u_i$ in $t$ by\nthe corresponding instance of $v_i$ until no further change occurs.\nThe result is a theorem $\\Gamma\\cup\\Delta\\turn t'$ where $t'$ is the\nresult of rewriting $t$ in this way.  The session below illustrates\nthe use of \\ml{REWRITE\\_RULE}.  In it the list of equations is the\nvalue \\ml{rewrite\\_list} containing the pre-proved theorems\n\\ml{ADD\\_CLAUSES} and \\ml{MULT\\_CLAUSES}.  These theorems are from the\ntheory \\ml{arithmetic}, so we must use a fully qualified name with the\nname of the theory as the first component to refer to them.\n(Alternatively, we could, as in the Euclid example of\nchapter~\\ref{chap:euclid}, use \\ml{open} to bring declare all of the\nvalues in the theory at the top level.)\n\n\\begin{session}\\begin{verbatim}\n- val rewrite_list = [arithmeticTheory.ADD_CLAUSES,\n                      arithmeticTheory.MULT_CLAUSES];\n> val rewrite_list =\n    [ []\n     |- (0 + m = m) /\\ (m + 0 = m) /\\ (SUC m + n = SUC (m + n)) /\\\n        (m + SUC n = SUC (m + n)),\n      []\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)]\n    : Thm.thm list\n\\end{verbatim}\\end{session}\n\n\\begin{session}\\begin{verbatim}\n- REWRITE_RULE rewrite_list (ASSUME ``(m+0)<(1*n)+(SUC 0)``);\n> val it =  [m + 0 < 1 * n + SUC 0] |- m < SUC n : thm\n\\end{verbatim}\\end{session}\n\n\\noindent\nThis can then be rewritten using another pre-proved theorem\n\\ml{LESS\\_THM}, this one from the theory \\ml{prim\\_rec}:\n\n\\begin{session}\\begin{verbatim}\n- REWRITE_RULE [prim_recTheory.LESS_THM] it;\n> val it =  [m + 0 < 1 * n + SUC 0] |- (m = n) \\/ m < n : thm\n\\end{verbatim}\\end{session}\n\n    \\ml{REWRITE\\_RULE} is not a primitive in \\HOL, but is a derived\n    rule. It is inherited from Cambridge \\LCF\\ and was implemented by\n    Larry Paulson (see his paper \\cite{lcp_rewrite} for details). In\n    addition to the supplied equations, \\ml{REWRITE\\_RULE} has some\n    built in standard simplifications:\n\n\\begin{session}\\begin{verbatim}\n- REWRITE_RULE [] (ASSUME ``(T /\\ x) \\/ F ==> F``);\n> val it = [T /\\ x \\/ F ==> F] |- ~x : thm\n\\end{verbatim}\\end{session}\n\n    There are elaborate facilities in \\HOL{} for producing customized\n    rewriting tools which scan through terms in user programmed\n    orders; \\ml{REWRITE\\_RULE} is the tip of an iceberg, see\n    \\DESCRIPTION\\ for more details.\n\n\\section{Goal Oriented Proof: Tactics and Tacticals}\n\\label{backward}\\label{tactics}\n\nThe style of forward proof described in the previous chapter is\nunnatural and too `low level' for many applications. An important\nadvance in proof generating methodology was made by Robin Milner in\nthe early 1970s when he invented the notion of {\\it tactics\\/}. A\ntactic is a function that does two things.\n\\begin{myenumerate}\n\\item Splits a `goal' into `subgoals'.\n\\item Keeps track of the reason why solving the subgoals will solve the goal.\n\\end{myenumerate}\n\n\\noindent Consider, for example, the  rule of $\\wedge$-introduction\\footnote{In\n  higher order logic this is a derived rule; in first order logic it\n  is usually primitive.  In HOL the rule is called {\\tt CONJ} and its\n  derivation is given in \\DESCRIPTION.}  shown below:\n\n\\[ \\Gamma_1\\turn\nt_1\\qquad\\qquad\\qquad\\Gamma_2\\turn t_2\\over \\Gamma_1\\cup\\Gamma_2 \\turn t_1\\conj\nt_2 \\]\n\n\n\\noindent In \\HOL,  $\\wedge$-introduction is  represented by  the \\ML{} function\n\\ml{CONJ}:\n\n\\[\\ml{CONJ}\\ (\\Gamma_1\\turn t_1)\\ (\\Gamma_2\\turn t_2) \\ \\ \\leadsto\\\n\\ (\\Gamma_1\\cup\\Gamma_2\\turn  t_1\\conj  t_2)\\]\n\n\\noindent  This  is   illustrated  in  the\nfollowing new session (note that the session number has been reset to\n{\\small\\sl 1}:\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\\begin{verbatim}\n- show_assums := true;\nval it = () : unit\n\n- val Th1 = ASSUME ``A:bool`` and Th2 = ASSUME ``B:bool``;\n> val Th1 =  [A] |- A : thm\n  val Th2 =  [B] |- B : thm\n\n- val Th3 = CONJ Th1 Th2;\n> val Th3 =  [A, B] |- A /\\ B : thm\n\\end{verbatim}\\end{session}\n\n    Suppose the goal is to prove $A\\conj B$, then this rule says that\n    it is sufficient to prove the two subgoals $A$ and $B$, because\n    from $\\turn A$ and $\\turn B$ the theorem $\\turn A\\conj B$ can be\n    deduced. Thus:\n\n\\begin{myenumerate}\n\\item To prove $\\turn A \\conj B$ it is sufficient to\n      prove $\\turn A$ and $\\turn B$.\n\\item The justification for the reduction of the\ngoal  $\\turn A \\conj B$  to the two  subgoals  $\\turn A$\nand $\\turn B$ is the rule of $\\wedge$-introduction.\n\\end{myenumerate}\n\nA {\\it goal\\/} in \\HOL{} is a pair \\ml{([$t_1$;\\ldots;$t_n$],$t$)} of\n\\ML{} type {\\small\\verb|term list * term|}. An {\\it achievement\\/} of\nsuch a goal is a theorem \\ml{$t_1$,$\\ldots$,$t_n$\\ |-\\ $t$}.  A tactic\nis an \\ML{} function that when applied to a goal generates subgoals\ntogether with a {\\it justification function\\/} or {\\it validation\\/},\nwhich will be an \\ML{} derived inference rule, that can be used to\ninfer an achievement of the original goal from achievements of the\nsubgoals.\n\nIf $T$ is a tactic (\\ie\\ an \\ML{} function of type \\ml{goal -> (goal\n  list * (thm list -> thm))}) and $g$ is a goal, then applying $T$ to\n$g$ (\\ie\\ evaluating the \\ML{} expression $T\\ g$) will result in an\nobject which is a pair whose first component is a list of goals and\nwhose second component is a justification function, \\ie\\ a value with\n\\ML{} type {\\small\\verb|thm list -> thm|}.\n\nAn example tactic is \\ml{CONJ\\_TAC} which implements (i) and (ii)\nabove.  For example, consider the utterly trivial goal of showing\n{\\small\\verb|T /\\ T|}, where \\ml{T} is a constant that stands for\n$true$:\n\n\\begin{session}\\begin{verbatim}\n- val goal1 =([]:term list, ``T /\\ T``);\n> val goal1 = ([], ``T /\\ T``) : term list * term\n\n- CONJ_TAC goal1;\n> val it =\n    ([([], ``T``), ([], ``T``)], fn)\n    : (term list * term) list * (thm list -> thm)\n\n- val (goal_list,just_fn) = it;\n> val goal_list =\n    [([], ``T``), ([], ``T``)]\n    : (term list * term) list\n  val just_fn = fn : thm list -> thm\n\\end{verbatim}\\end{session}\n\n\\noindent \\ml{CONJ\\_TAC} has produced a goal  list consisting  of two identical\nsubgoals of just showing \\ml{([],\"T\")}.  Now, there is a preproved\ntheorem in \\HOL, called \\ml{TRUTH}, that achieves this goal:\n\n\\begin{session}\\begin{verbatim}\n- TRUTH;\n> val it = [] |- T : thm\n\\end{verbatim}\\end{session}\n\n\\noindent Applying the justification function \\ml{just\\_fn} to a list\nof theorems achieving the goals in \\ml{goal\\_list} results\nin a theorem achieving the original goal:\n\n\\begin{session}\\begin{verbatim}\n- just_fn [TRUTH,TRUTH];\n> val it =  [] |- T /\\ T : thm\n\\end{verbatim}\\end{session}\n\n    Although this example is trivial, it does illustrate the essential\n    idea of tactics.  Note that tactics are not special\n    theorem-proving primitives; they are just \\ML{} functions.  For\n    example, the definition of \\ml{CONJ\\_TAC} is simply:\n\n\\begin{hol}\\begin{verbatim}\n   fun CONJ_TAC (asl,w) = let\n     val (l,r) = dest_conj w\n   in\n     ([(asl,l), (asl,r)], fn [th1,th2] => CONJ th1 th2)\n   end\n\\end{verbatim}\\end{hol}\n\n\\noindent The \\ML{} function \\ml{dest\\_conj} splits a conjunction into its\ntwo conjuncts: If \\ml{(asl,``$t_1$}{\\small\\verb|/\\|}\\ml{$t_2$``)} is a\ngoal, then \\ml{CONJ\\_TAC} splits it into the list of two subgoals\n\\ml{(asl,$t_1$)} and \\ml{(asl,$t_2$)}. The justification function,\n{\\small\\verb|fn [th1,th2] => CONJ th1 th2|} takes a list\n\\ml{[$th_1$,$th_2$]} of theorems and applies the rule \\ml{CONJ} to\n$th_1$ and $th_2$.\n\nTo summarize: if $T$ is a tactic and $g$ is a goal, then applying $T$\nto $g$ will result in a pair whose first component is a list of goals\nand whose second component is a justification function, with \\ML{} type\n{\\small\\verb|thm list -> thm|}.\n\nSuppose\n$T\\ g${\\small\\verb| = ([|}$g_1${\\small\\verb|,|}$\\ldots${\\small\\verb|,|}$g_n${\\small\\verb|],|}$p${\\small\\verb|)|}.\nThe idea is that $g_1$ , $\\ldots$ , $g_n$ are subgoals and $p$ is a\n`justification' of the reduction of goal $g$ to subgoals $g_1$ ,\n$\\ldots$ , $g_n$.  Suppose further that the subgoals $g_1$ , $\\ldots$\n, $g_n$ have been solved.  This would mean that theorems $th_1$ ,\n$\\ldots$ , $th_n$ had been proved such that each $th_i$ ($1\\leq i\\leq\nn$) `achieves' the goal $g_i$.  The justification $p$ (produced by\napplying $T$ to $g$) is an \\ML{} function which when applied to the\nlist\n{\\small\\verb|[|}$th_1${\\small\\verb|,|}$\\ldots${\\small\\verb|,|}$th_n${\\small\\verb|]|}\nreturns a theorem, $th$, which `achieves' the original goal $g$.  Thus\n$p$ is a function for converting a solution of the subgoals to a\nsolution of the original goal. If $p$ does this successfully, then the\ntactic $T$ is called {\\it valid\\/}.  Invalid tactics cannot result in\nthe proof of invalid theorems; the worst they can do is result in\ninsolvable goals or unintended theorems being proved.  If $T$ were\ninvalid and were used to reduce goal $g$ to subgoals $g_1$ , $\\ldots$\n, $g_n$, then effort might be spent proving theorems $th_1$ , $\\ldots$\n, $th_n$ to achieve the subgoals $g_1$ , $\\ldots$ , $g_n$, only to\nfind out after the work is done that this is a blind alley because\n$p${\\small\\verb|[|}$th_1${\\small\\verb|,|}$\\ldots${\\small\\verb|,|}$th_n${\\small\\verb|]|}\ndoesn't achieve $g$ (\\ie\\ it fails, or else it achieves some other\ngoal).\n\nA theorem {\\it achieves\\/} a goal if the assumptions of the theorem are\nincluded in the assumptions of the goal {\\it and\\/} if the conclusion of the\ntheorems is equal (up to the renaming of bound variables) to the conclusion of\nthe goal. More precisely, a theorem\n\\begin{center}\n$t_1$, $\\dots$, $t_m${\\small\\verb% |- %}$t$\n\\end{center}\n\n\\noindent  achieves a goal\n\\begin{center}\n{\\small\\verb|([|}$u_1${\\small\\verb|,|}$\\ldots${\\small\\verb|,|}$u_n${\\small\\verb|],|}$u${\\small\\verb|)|}\n\\end{center}\n\n\\noindent if and only if $\\{t_1,\\ldots,t_m\\}$\nis a subset of $\\{u_1,\\ldots,u_n\\}$ and $t$ is equal to $u$ (up to\nrenaming of bound variables).  For example, the goal\n{\\small\\verb|([``x=y``, ``y=z``, ``z=w``], ``x=z``)|} is achieved by\nthe theorem {\\small\\verb+[x=y, y=z] |- x=z+} (the assumption\n{\\small\\verb|``z=w``|} is not needed).\n\nA tactic {\\it solves\\/} a goal if it reduces the goal\nto the empty list\nof subgoals. Thus $T$ solves $g$ if\n$T\\ g${\\small\\verb| = ([],|}$p${\\small\\verb|)|}.\nIf this is the case and if $T$ is valid, then $p${\\small\\verb|[]|}\nwill evaluate to a theorem achieving $g$.\nThus if $T$ solves $g$ then the \\ML{} expression\n{\\small\\verb|snd(|}$T\\ g${\\small\\verb|)[]|} evaluates to\na theorem achieving $g$.\n\nTactics are specified using the following notation:\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n$goal$ \\\\ \\tacticline\n$goal_1\\ \\ \\ goal_2 \\ \\ \\ \\cdots\\ \\ \\ goal_n$ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent For example, a tactic called {\\small\\verb|CONJ_TAC|} is described by\n\n\\newcommand\\ttbs{\\texttt{\\symbol{\"5C}}}\n\\newcommand\\ttland{\\texttt{/\\ttbs}}\n\n\\begin{center}\n\\begin{tabular}{lr} \\\\\n\\multicolumn{2}{c}{$t_1$ \\ttland{} $t_2$} \\\\ \\tacticline\n$t_1$ & $t_2$ \\\\\n\\end{tabular}\n\\end{center}\n\n\n\n\\noindent Thus {\\small\\verb|CONJ_TAC|} reduces a goal of the form\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,``|}$t_1${\\small\\verb|/\\|}$t_2${\\small\\verb|``)|}\nto subgoals\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,``|}$t_1${\\small\\verb|``)|} and {\\small\\verb|(|}$\\Gamma${\\small\\verb|,``|}$t_2${\\small\\verb|``)|}.\nThe fact that the assumptions of the top-level goal\nare propagated unchanged to the two subgoals is indicated by the absence\nof assumptions in the notation.\n\nAnother example is {\\small\\verb|numLib.INDUCT_TAC|}, the tactic for\ndoing mathematical induction on the natural numbers:\n\n\\begin{center}\n\\begin{tabular}{lr} \\\\\n\\multicolumn{2}{c}{\\texttt{!}$n$\\texttt{.}$t[n]$} \\\\ \\tacticline\n$t[\\texttt{0}]$ & $\\quad\\{t[n]\\}\\ t[\\texttt{SUC}\\;n]$\n\\end{tabular}\n\\end{center}\n\n{\\small\\verb|INDUCT_TAC|} reduces a goal\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,``!|}$n${\\small\\verb|.|}$t[n]${\\small\\verb|``)|} to a basis subgoal\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,``|}$t[${\\small\\verb|0|}$]${\\small\\verb|``)|}\nand an induction step subgoal\n{\\small\\verb|(|}$\\Gamma\\cup\\{${\\small\\verb|``|}$t[n]${\\small\\verb|``|}$\\}${\\small\\verb|,``|}$t[${\\small\\verb|SUC |}$n]${\\small\\verb|``)|}.\nThe extra induction assumption {\\small\\verb|``|}$t[n]${\\small\\verb|``|}\nis indicated in the tactic notation with set brackets.\n\n\\begin{session}\\begin{verbatim}\n- numLib.INDUCT_TAC([], ``!m n. m+n = n+m``);\n> val it =\n    ([([], ``!n. 0 + n = n + 0``),\n      ([``!n. m + n = n + m``], ``!n. SUC m + n = n + SUC m``)], fn)\n    : (term list * term) list * (thm list -> thm)\n\\end{verbatim}\\end{session}\n\n\\noindent The first subgoal is the basis case and the second subgoal is\nthe step case.\n\nTactics generally fail (in the \\ML{} sense, \\ie\\ raise an exception) if\nthey are applied to inappropriate goals. For example,\n{\\small\\verb|CONJ_TAC|} will fail if it is applied to a goal whose\nconclusion is not a conjunction. Some tactics never fail, for example\n{\\small\\verb|ALL_TAC|}\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n$t$ \\\\ \\tacticline\n$t$\n\\end{tabular}\n\\end{center}\n\n\\noindent is the `identity tactic'; it reduces a goal\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,|}$t${\\small\\verb|)|} to the\nsingle subgoal\n{\\small\\verb|(|}$\\Gamma${\\small\\verb|,|}$t${\\small\\verb|)|}---\\ie\\ it\nhas no effect. {\\small\\verb|ALL_TAC|} is useful for writing complex\ntactics using tacticals.\n\n\n\\subsection{Using tactics to prove theorems}\n\\label{using-tactics}\n\nSuppose goal $g$ is to be solved. If $g$ is simple it might be\npossible to immediately think up a tactic, $T$ say, which reduces it\nto the empty list of subgoals. If this is the case then executing:\n\n$\\ ${\\small\\verb| val (|}$gl${\\small\\verb|,|}$p${\\small\\verb|) = |}$T\\ g$\n\n\\noindent will bind $p$ to a function which when applied to the empty list\nof theorems yields a theorem $th$ achieving $g$.  (The declaration\nabove will also bind $gl$ to the empty list of goals.) Thus a theorem\nachieving $g$ can be computed by executing:\n\n$\\ ${\\small\\verb| val |}$th${\\small\\verb| = |}$p${\\small\\verb|[]|}\n\n\\noindent This will be illustrated using \\ml{REWRITE\\_TAC} which takes a list\nof equations (empty in the example that follows) and tries to prove a goal\nby rewriting with these equations together with\n\\ml{basic\\_rewrites}:\n\n\\begin{session}\\begin{verbatim}\n- val goal2 = ([]:term list, ``T /\\ x ==> x \\/ (y /\\ F)``);\n> val goal2 = ([], ``T /\\ x ==> x \\/ y /\\ F``) : (term list * term)\n\n- REWRITE_TAC [] goal2;\n> val it = ([], fn) : (term list * term) list * (thm list -> thm)\n\n- #2 it [];\n> val it =  [] |- T /\\ x ==> x \\/ y /\\ F : thm\n\\end{verbatim}\\end{session}\n\n\\noindent Proved theorems are usually stored in the current theory\nso that they can be used in subsequent sessions.\n\nThe built-in function\n \\ml{store\\_thm} of\n\\ML{} type {\\small\\verb|(string * term * tactic) -> thm|} facilitates the use\nof tactics:\n{\\small\\verb|store_thm(\"foo\",|}$t${\\small\\verb|,|}$T${\\small\\verb|)|} proves\nthe goal   {\\small\\verb|([],|}$t${\\small\\verb|)|}   (\\ie\\  the   goal  with  no\nassumptions and  conclusion  $t$)  using  tactic  $T$  and  saves the resulting\ntheorem with name {\\small\\verb|foo|} on the current theory.\n\nIf the theorem is not to be saved, the function \\ml{prove} of type\n{\\small\\verb|(term * tactic) -> thm|} can be used.  Evaluating\n{\\small\\verb|prove(|}$t${\\small\\verb|,|}$T${\\small\\verb|)|} proves   the   goal\n{\\small\\verb|([],|}$t${\\small\\verb|)|} using $T$ and returns the result without\nsaving it.  In both cases  the evaluation  fails if  $T$ does  not solve the\ngoal {\\small\\verb|([],|}$t${\\small\\verb|)|}.\n\nWhen conducting a proof that involves many subgoals and tactics, it is\nnecessary to keep track of all the justification functions and compose\nthem in the correct order.  While this is feasible even in large\nproofs, it is tedious.  \\HOL{} provides a package for building and\ntraversing the tree of subgoals, stacking the justification functions\nand applying them properly; this package was originally implemented\nfor \\LCF\\ by Larry Paulson.\n\nThe subgoal package implements a simple framework for interactive\nproof. A proof tree is created and traversed top-down.  The current\ngoal can be expanded into subgoals using a tactic; the subgoals are\npushed onto a goal stack and the justification function onto a proof\nstack.  Subgoals can be considered in any order.  If the tactic solves\na subgoal (\\ie\\ returns an empty subgoal list), then the package\nproceeds to the next subgoal in the tree.\n\nThe function \\ml{set\\_goal} of type \\ml{goal -> proofs}\\footnote{The\n  \\ml{proofs} type stores multiple proof attempts (multiple trees) at\n  once.} initializes the subgoal package with a new goal. Usually\ntop-level goals have no assumptions; the function \\ml{g} is useful in\nthis case.\n\nTo illustrate the subgoal package the trivial theorem $\\vdash\n\\uquant{m}m+0=m$ will be proved from the definition of addition (we\nfirst \\ml{open} the theory of arithmetic to bring ML bindings for its\ntheorems to the top level):\n\n\\begin{session}\\begin{verbatim}\n- open arithmeticTheory;\n> ...\n- ADD;\n> val it = |- (!n. 0 + n = n) /\\ (!m n. (SUC m) + n = SUC(m + n)) : thm\n\\end{verbatim}\\end{session}\n\n\\noindent Notice that \\ml{ADD} specifies\n$0+m=m$ but not $m+0=m$. Of course, $\\uquant{m\\ n}m+n = n+m$ is true,\nbut the first step of the proof is to show $\\uquant{m}m+0=m$ from the\ndefinition of addition.  Notice that the function \\ml{g} does not take\na term as an argument, but rather a \\emph{quotation}, with only one\nset of back-quotes.\n\n\\begin{session}\\begin{verbatim}\n- g `!m. m+0=m`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !m. m + 0 = m\n\\end{verbatim}\\end{session}\n\n\\noindent This sets up the goal. Next the goal is split into a basis and step case\nwith \\ml{Induct}. To do this the function \\ml{e} (or,\nequivalently, \\ml{expand}) is used. This applies a tactic to the top\ngoal on the stack, then pushes the resulting subgoals onto the goal\nstack, then prints the resulting subgoals. If there are no subgoals,\nthe justification function is applied to the theorems solving the\nsubgoals that have been proved and the resulting theorems are printed.\n\n\\begin{session}\\begin{verbatim}\n- e Induct;\nOK..\n2 subgoals:\n> val it =\n    SUC m + 0 = SUC m\n    ------------------------------------\n      m + 0 = m\n\n    0 + 0 = 0\n\\end{verbatim}\\end{session}\n\n\\noindent The top of the goal stack is printed last. The basis case\nis an instance of the definition of addition, so is solved by\nrewriting with \\ml{ADD}.\n\n\\begin{session}\\begin{verbatim}\n- e(REWRITE_TAC[ADD]);\nOK..\n\nGoal proved.\n [] |- 0 + 0 = 0\n\nRemaining subgoals:\n> val it =\n    SUC m + 0 = SUC m\n    ------------------------------------\n      m + 0 = m\n\\end{verbatim}\\end{session}\n\n\\noindent The basis is solved and the goal\nstack popped so that its top is now the step case, namely showing that\n{\\small\\verb|(SUC m) + 0 = SUC m|} under the assumption\n{\\small\\verb|m + 0 = m|}. This goal can be solved by rewriting first with the\ndefinition of addition:\n\n\\begin{session}\\begin{verbatim}\n- e(REWRITE_TAC[ADD]);\nOK..\n1 subgoal:\n> val it =\n    SUC (m + 0) = SUC m\n    ------------------------------------\n      m + 0 = m\n\\end{verbatim}\\label{session:rewrite-add}\\end{session}\n\n\\noindent and then with the assumption \\ml{m+0=m}. The tactic\n\\ml{ASM\\_REWRITE\\_TAC} is used to rewrite with the assumptions of a\ngoal. It is just like \\ml{REWRITE\\_TAC} except that it adds the\nassumptions to the list of equations used for rewriting. For the\nexample here no equations besides the assumptions are needed, so\n\\ml{ASM\\_REWRITE\\_TAC} is given the empty list of equations.\n\n\\begin{session}\\begin{verbatim}\n- e(ASM_REWRITE_TAC[]);\nOK..\n\nGoal proved.\n [m + 0 = m] |- SUC (m + 0) = SUC m\n\nGoal proved.\n [m + 0 = m] |- SUC m + 0 = SUC m\n> val it =\n    Initial goal proved.\n     [] |- !m. m + 0 = m\n    : GoalstackPure.goalstack\n\\end{verbatim}\\label{session:asm-rewrite-add}\\end{session}\n\n\\noindent The top goal is solved, hence the preceding goal (the step case)\nis solved too, and since the basis is already solved, the main goal is\nsolved.\n\nThe theorem achieving the goal can be extracted from the subgoal package with\n\\ml{top\\_thm}:\n\n\\begin{session}\\begin{verbatim}\n- top_thm();\nval it = [] |- !m. m + 0 = m : thm\n\\end{verbatim}\\end{session}\n\n    The proof just done can be `optimized'. For example, instead of\n    first rewriting with \\ml{ADD} (box \\ref{session:rewrite-add}) and\n    then with the assumptions (box \\ref{session:asm-rewrite-add}), a\n    single rewriting with \\ml{ADD} and the assumptions would suffice.\n    To illustrate, the last two steps of the proof will be `undone'\n    using the function \\ml{backup} (also, \\ml{b}) which restores the\n    previous state of the goal and theorem stacks.\n\n\\begin{session}\\begin{verbatim}\n- b();\n> val it =\n    SUC (m + 0) = SUC m\n    ------------------------------------\n      m + 0 = m\n\n- b();\n> val it =\n    SUC m + 0 = SUC m\n    ------------------------------------\n      m + 0 = m\n\n\\end{verbatim}\\end{session}\n\n\\noindent The proof can now be completed in one step instead of two:\n\n\\begin{session}\\begin{verbatim}\n- e(ASM_REWRITE_TAC[ADD]);\nOK..\n\nGoal proved.\n [m + 0 = m] |- SUC m + 0 = SUC m\n> val it =\n    Initial goal proved.\n     [] |- !m. m + 0 = m\n    : GoalstackPure.goalstack\n\\end{verbatim}\\end{session}\n\n\n    The order in which goals are attacked can be adjusted using\n    \\ml{rotate\\ }$n$ (alternatively,~\\ml{r}) which rotates the goal\n    stack by $n$. For example:\n\n\\begin{session}\\begin{verbatim}\n- b(); b();\n> ...\n\n> val it =\n    SUC m + 0 = SUC m\n    ------------------------------------\n      m + 0 = m\n\n    0 + 0 = 0\n\n- r 1;\n> val it =\n    0 + 0 = 0\n\n\n    SUC m + 0 = SUC m\n    ------------------------------------\n      m + 0 = m\n\\end{verbatim}\\end{session}\n\n\\noindent The top goal is now the step case not the basis case, so expanding\nwith a tactic will apply the tactic to the step case.\n\n\\begin{session}\\begin{verbatim}\n- e(ASM_REWRITE_TAC[ADD]);\nOK..\n\nGoal proved.\n [m + 0 = m] |- SUC m + 0 = SUC m\n\nRemaining subgoals:\n> val it =\n    0 + 0 = 0\n\\end{verbatim}\\end{session}\n\n    It is possible to do the whole proof in one step, but this\n    requires a compound tactic built using the {\\it\n      tactical\\/}\\footnote{This word was invented by Robin Milner:\n      `tactical' is to `tactic` as `functional' is to `function'.}\n    \\ml{THENL}.  Tacticals are higher order operations for combining\n    tactics.\n\n\\subsection{Tacticals}\n\\label{tacticals}\n\nA {\\it tactical\\/} is an \\ML{} function that takes one or more tactics\nas arguments, possibly with other arguments as well, and returns a\ntactic as its result.  The various parameters passed to tacticals are\nreflected in the various \\ML{} types that the built-in tacticals have.\nSome important tacticals in the \\HOL{} system are listed below.\n\n\\subsubsection{\\tt THENL : tactic -> tactic list -> tactic}\n\nIf tactic $T$ produces $n$ subgoals and $T_1$, $\\ldots$ , $T_n$ are\ntactics then $T${\\small\\verb| THENL|}\n{\\small\\verb|[|}$T_1${\\small\\verb|;|}$\\ldots${\\small\\verb|;|}$T_n${\\small\\verb|]|}\nis a tactic which first applies $T$ and then applies $T_i$ to the\n$i$th subgoal produced by $T$.  The tactical {\\small\\verb|THENL|} is\nuseful if one wants to do different things to different subgoals.\n\n\\ml{THENL} can be illustrated by doing the proof of $\\vdash \\uquant{m}m+0=m$ in\none step.\n\n\\setcounter{sessioncount}{0}\n\\begin{session}\\begin{verbatim}\n- g `!m. m + 0 = m`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !m. m + 0 = m\n\n- e(INDUCT_TAC THENL [REWRITE_TAC[ADD], ASM_REWRITE_TAC[ADD]]);\nOK..\n> val it =\n    Initial goal proved.\n     [] |- !m. m + 0 = m\n\\end{verbatim}\\end{session}\n\n\\noindent The compound tactic\n{\\small\\verb|INDUCT_TAC THENL [REWRITE_TAC[ADD];ASM_REWRITE_TAC[ADD]]|}\nfirst applies \\ml{INDUCT\\_TAC} and then applies\n\\ml{REWRITE\\_TAC[ADD]} to the first subgoal (the basis) and\n\\ml{ASM\\_REWRITE\\_TAC[ADD]} to the second subgoal (the step).\n\nThe tactical {\\small\\verb|THENL|} is useful for doing different things\nto different subgoals. The tactical \\ml{THEN} can be used to apply the\nsame tactic to all subgoals.\n\n\\subsubsection{\\tt THEN : tactic -> tactic -> tactic}\\label{THEN}\n\nThe tactical {\\small\\verb|THEN|} is an \\ML{} infix. If $T_1$ and $T_2$\nare tactics, then the \\ML{} expression $T_1${\\small\\verb| THEN |}$T_2$\nevaluates to a tactic which first applies $T_1$ and then applies $T_2$\nto all the subgoals produced by $T_1$.\n\nIn fact, \\ml{ASM\\_REWRITE\\_TAC[ADD]} will solve the basis as well as\nthe step case of the induction for $\\uquant{m}m+0=m$, so there is an\neven simpler one-step proof than the one above:\n\\setcounter{sessioncount}{0}\n\\begin{session}\\begin{verbatim}\n- g `!m. m+0 = m`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !m. m + 0 = m\n\n- e(INDUCT_TAC THEN ASM_REWRITE_TAC[ADD]);\nOK..\n> val it =\n    Initial goal proved.\n     [] |- !m. m + 0 = m\n\\end{verbatim}\\end{session}\n\n\\noindent This is typical: it is common to use a single tactic for several\ngoals. Here, for example, are the first four consequences of the\ndefinition \\ml{ADD} of addition that are pre-proved when the built-in\ntheory \\ml{arithmetic} \\HOL{} is made.\n\n\\begin{hol}\\begin{verbatim}\n   val ADD_0 = prove (\n     ``!m. m + 0 = m``,\n     INDUCT_TAC THEN ASM_REWRITE_TAC[ADD]);\n\\end{verbatim}\\end{hol}\n\n\\begin{hol}\\begin{verbatim}\n   val ADD_SUC = prove (\n     ``!m n. SUC(m + n) = m + SUC n``,\n     INDUCT_TAC THEN ASM_REWRITE_TAC[ADD]);\n\\end{verbatim}\\end{hol}\n\n\\begin{hol}\\begin{verbatim}\n   val ADD_CLAUSES = prove (\n     ``(0 + m = m)              /\\\n       (m + 0 = m)              /\\\n       (SUC m + n = SUC(m + n)) /\\\n       (m + SUC n = SUC(m + n))``,\n     REWRITE_TAC[ADD, ADD_0, ADD_SUC]);\n\\end{verbatim}\\end{hol}\n\n\\begin{hol}\\begin{verbatim}\n   val ADD_COMM = prove (\n     ``!m n. m + n = n + m``,\n     INDUCT_TAC THEN ASM_REWRITE_TAC[ADD_0, ADD, ADD_SUC]);\n\\end{verbatim}\\end{hol}\n\n\n\\noindent These proofs are performed when the \\HOL{} system is made and the\ntheorems are saved in the theory \\ml{arithmetic}. The complete list of\nproofs for this built-in theory can be found in the file\n\\ml{src/num/arithmeticScript.sml}.\n\n\n\\subsubsection{\\tt ORELSE : tactic -> tactic -> tactic}\\label{ORELSE}\n\nThe tactical {\\small\\verb|ORELSE|} is an \\ML{} infix. If $T_1$ and\n$T_2$ are tactics,\n%\\index{tacticals!for alternation}\nthen $T_1${\\small\\verb| ORELSE |}$T_2$ evaluates to a tactic which\napplies $T_1$ unless that fails; if it fails, it applies $T_2$.\n\\ml{ORELSE} is defined in \\ML{} as a curried infix by\\footnote{This is\n  a minor simplification.}\n\n\\begin{hol}\n   {\\small\\verb|(|}$T_1${\\small\\verb| ORELSE |}$T_2${\\small\\verb|)|} $g$\n   {\\small\\verb|=|}  $T_1\\; g$ {\\small\\verb|handle _ =>|} $T_2\\; g$\n\\end{hol}\n%\\index{alternation!of tactics|)}\n\n\\subsubsection{\\tt REPEAT : tactic -> tactic}\n\nIf $T$ is a tactic then {\\small\\verb|REPEAT |}$T$ is a tactic which\nrepeatedly applies $T$ until it fails. This can be illustrated in\nconjunction with \\ml{GEN\\_TAC}, which is specified by:\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n{\\small\\verb|!|}$x${\\small\\verb|.|}$t[x]$\n\\\\ \\tacticline\n$t[x']$\n\\\\\n\\end{tabular}\n\\end{center}\n\n\\begin{itemize}\n\\item Where $x'$ is a variant of $x$\nnot free in the goal or the assumptions.\n\\end{itemize}\n\n\\noindent \\ml{GEN\\_TAC} strips off one quantifier;\n\\ml{REPEAT\\ GEN\\_TAC} strips off all quantifiers:\n\n\\begin{session}\\begin{verbatim}\n- g `!x y z. x+(y+z) = (x+y)+z`;\n> val it =\n    Proof manager status: 1 proof.\n    1. Incomplete:\n         Initial goal:\n         !x y z. x + (y + z) = x + y + z\n\n- e GEN_TAC;\nOK..\n1 subgoal:\n> val it =\n    !y z. x + (y + z) = x + y + z\n\n- e(REPEAT GEN_TAC);\nOK..\n1 subgoal:\n> val it =\n    x + (y + z) = x + y + z\n\\end{verbatim}\\end{session}\n\n\\subsection{Some tactics built into HOL}\n\nThis section contains a summary of some of the tactics built into the\n\\HOL{} system (including those already discussed).  The tactics given\nhere are those that are used in the parity checking example.\n\nBefore beginning, note that the \\ML{} type {\\small\\verb|thm_tactic|}\nabbreviates {\\small\\verb|thm->tactic|}, and the type\n{\\small\\verb|conv|}\\footnote{The type {\\small{\\tt conv}} comes from\n  Larry Paulson's theory of conversions \\cite{lcp_rewrite}.}\nabbreviates {\\small\\verb|term->thm|}.\n\n\\subsubsection{\\tt REWRITE\\_TAC : thm list -> tactic}\n\\label{rewrite}\n\n\\begin{itemize}\n\\item{\\bf Summary:} {\\small\\verb|REWRITE_TAC[|}$th_1${\\small\\verb|,|}$\\ldots${\\small\\verb|,|}$th_n${\\small\\verb|]|}\nsimplifies the goal by rewriting\nit with the explicitly given theorems $th_1$, $\\ldots$ , $th_n$,\nand various built-in rewriting rules.\n\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n$\\{t_1, \\ldots , t_m\\}t$\n\\\\ \\tacticline\n$\\{t_1, \\ldots , t_m\\}t'$\n\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent where $t'$ is obtained from $t$ by rewriting with\n\\begin{enumerate}\n\\item  $th_1$, $\\ldots$ , $th_n$ and\n\\item  the standard rewrites held in the \\ML{} variable {\\small\\verb|basic_rewrites|}.\n\\end{enumerate}\n\n\\item{\\bf Uses:} Simplifying goals using previously proved theorems.\n\n\\item{\\bf Other rewriting tactics}:\n\\begin{enumerate}\n\\item {\\small\\verb|ASM_REWRITE_TAC|} adds the assumptions of the goal\n  to the list of theorems used for rewriting.\n\\item {\\small\\verb|PURE_REWRITE_TAC|} uses neither the assumptions nor\n  the built-in rewrites.\n\\item {\\small\\verb|bossLib.RW_TAC|} of type \\ml{simpLib.simpset -> thm\n    list -> tactic}.  A \\ml{simpset} is a special collection of\n  rewriting theorems and other theorem-proving functionality.  Values\n  defined by \\HOL{} include \\ml{bossLib.base\\_ss}, which has basic\n  knowledge of the boolean connectives, \\ml{bossLib.arith\\_ss} which\n  ``knows'' all about arithmetic, and \\ml{HOLSimps.hol\\_ss}, which\n  includes theorems appropriate for lists, pairs, and arithmetic.\n  Additional theorems for rewriting can be added using the second\n  argument of \\ml{RW\\_TAC}.\n\\end{enumerate}\n\\end{itemize}\n\n\n\\subsubsection{\\tt CONJ\\_TAC : tactic}\\label{CONJTAC}\n\n\\begin{itemize}\n\n\\item{\\bf Summary:} Splits a\ngoal {\\small\\verb|``|}$t_1${\\small\\verb|/\\|}$t_2${\\small\\verb|``|} into two subgoals {\\small\\verb|``|}$t_1${\\small\\verb|``|}\nand {\\small\\verb|``|}$t_2${\\small\\verb|``|}.\n\n\\begin{center}\n\\begin{tabular}{lr} \\\\\n\\multicolumn{2}{c}{$t_1$ \\ttland{} $t_2$} \\\\ \\tacticline\n$t_1$ & $t_2$ \\\\\n\\end{tabular}\n\\end{center}\n\n\\item{\\bf Uses:} Solving conjunctive goals.\n{\\small\\verb|CONJ_TAC|} is invoked by {\\small\\verb|STRIP_TAC|} (see below).\n\n\\end{itemize}\n\n\n\n\\subsubsection{\\tt EQ\\_TAC : tactic}\\label{EQTAC}\n\n\n\\begin{itemize}\n\n\\item{\\bf Summary:}\n{\\small\\verb|EQ_TAC|}\nsplits an equational goal into two implications (the `if-case' and\nthe `only-if' case):\n\n\\begin{center}\n\n\n\n\\begin{tabular}{lr} \\\\\n\\multicolumn{2}{c}{$u\\; \\ml{=}\\; v$} \\\\ \\tacticline\n$u\\; \\ml{==>}\\; v$ & $\\quad v\\; \\ml{==>}\\; u$ \\\\\n\\end{tabular}\n\\end{center}\n\n\\item{\\bf Use:} Proving logical equivalences, \\ie\\ goals of the form\n``$u$\\ml{=}$v$'' where $u$ and $v$ are boolean terms.\n\n\\end{itemize}\n\n\n\n\n\\subsubsection{\\tt DISCH\\_TAC : tactic}\\label{DISCHTAC}\n\n\\begin{itemize}\n\n\\item{\\bf Summary:} Moves the antecedent\nof an implicative goal into the assumptions.\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n$u${\\small\\verb| ==> |}$v$\n\\\\ \\tacticline\n$\\{u\\}v$\n\\\\\n\\end{tabular}\n\\end{center}\n\n\n\\item{\\bf Uses:} Solving goals of the form\n{\\small\\verb|``|}$u${\\small\\verb| ==> |}$v${\\small\\verb|``|} by assuming {\\small\\verb|``|}$u${\\small\\verb|``|} and then solving\n{\\small\\verb|``|}$v${\\small\\verb|``|}.\n{\\small\\verb|STRIP_TAC|} (see below) will invoke {\\small\\verb|DISCH_TAC|} on implicative goals.\n\\end{itemize}\n\n\\subsubsection{\\tt GEN\\_TAC : tactic}\n\n\\begin{itemize}\n\n\\item{\\bf  Summary:} Strips off one universal quantifier.\n\n\n\\begin{center}\n\\begin{tabular}{c} \\\\\n{\\small\\verb|!|}$x${\\small\\verb|.|}$t[x]$\n\\\\ \\tacticline\n$t[x']$\n\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Where $x'$ is a variant of $x$\nnot free in the goal or the assumptions.\n\n\\item{\\bf   Uses:} Solving universally quantified goals.\n{\\small\\verb|REPEAT GEN_TAC|} strips off all\nuniversal quantifiers and is often the first thing one does in a proof.\n{\\small\\verb|STRIP_TAC|} (see below) applies {\\small\\verb|GEN_TAC|} to universally quantified goals.\n\\end{itemize}\n\n\n\\subsubsection{\\tt PROVE\\_TAC : thm list -> tactic}\n\n\\begin{itemize}\n\\item {\\bf Summary:} Used to do first order reasoning, solving the\n  goal completely if successful, failing otherwise.  Using the\n  provided theorems and the assumptions of the goal,\n  {\\small\\verb|PROVE_TAC|} does a search for possible proofs of the\n  goal.  Eventually fails if the search fails to find a proof shorter\n  than a reasonable depth.\n\\item {\\bf Uses:} To finish a goal off when it is clear that it is a\n  consequence of the assumptions and the provided theorems.\n\\end{itemize}\n\n\n\\subsubsection{\\tt STRIP\\_TAC : tactic}\n\n\\begin{itemize}\n\n\\item{\\bf Summary:} Breaks a goal apart.  {\\small\\verb|STRIP_TAC|}\n  removes one outer connective from the goal, using\n  {\\small\\verb|CONJ_TAC|}, {\\small\\verb|DISCH_TAC|},\n  {\\small\\verb|GEN_TAC|}, \\etc\\ If the goal is\n$t_1${\\small\\verb|/\\|}$\\cdots${\\small\\verb|/\\|}$t_n${\\small\\verb| ==> |}$t$\nthen {\\small\\verb|STRIP_TAC|} makes each $t_i$ into a separate assumption.\n\n\\item{\\bf Uses:} Useful for splitting a goal up into manageable pieces.\nOften the best thing to do first is {\\small\\verb|REPEAT STRIP_TAC|}.\n\\end{itemize}\n\n\\subsubsection{\\tt SUBST\\_TAC : thm list -> tactic}\n\n\\begin{itemize}\n\n\\item{\\bf Summary:}\n  {\\small\\verb+SUBST_TAC[|-+}$u_1${\\small\\verb|=|}$v_1${\\small\\verb|,|}$\\ldots${\\small\\verb+,|-+}$u_n${\\small\\verb|=|}$v_n${\\small\\verb|]|}\n  converts a goal $t[u_1,\\ldots ,u_n]$ to the subgoal form\n  $t[v_1,\\ldots ,v_n]$.\n\n\\item{\\bf Uses:} To make replacements for terms in situations in which\n  {\\small\\verb|REWRITE_TAC|} is too general or would loop.\n\\end{itemize}\n\n\n\\subsubsection{\\tt ACCEPT\\_TAC : thm -> tactic}\\label{ACCEPTTAC}\n\n\n\\begin{itemize}\n\n\\item{\\bf Summary:} {\\small\\verb|ACCEPT_TAC |}$th$\nis a tactic that solves any goal that is\nachieved by $th$.\n\n\\item{\\bf Use:} Incorporating forward proofs, or theorems already\n  proved, into goal directed proofs.  For example, one might reduce a\n  goal $g$ to subgoals $g_1$, $\\dots$, $g_n$ using a tactic $T$ and\n  then prove theorems $th_1$ , $\\dots$, $th_n$ respectively achieving\n  these goals by forward proof. The tactic\n\n\\[\\ml{  T THENL[ACCEPT\\_TAC }th_1\\ml{,}\\ldots\\ml{,ACCEPT\\_TAC }th_n\\ml{]}\n\\]\n\nwould then solve $g$, where \\ml{THENL}\n%\\index{THENL@\\ml{THENL}}\nis the tactical that applies the respective elements of the tactic\nlist to the subgoals produced by \\ml{T}.\n\n\\end{itemize}\n\n\n\n\\subsubsection{\\tt ALL\\_TAC : tactic}\n\n\\begin{itemize}\n\\item{\\bf Summary:} Identity tactic for the tactical {\\small\\verb%THEN%}\n(see \\DESCRIPTION).\n\n\\item{\\bf Uses:}\n\\begin{enumerate}\n\\item Writing tacticals (see description of {\\small\\verb|REPEAT|}\nin \\DESCRIPTION).\n\\item With {\\small\\verb%THENL%}; for example, if tactic $T$ produces two subgoals\nand we want to apply $T_1$\nto the first one but to do nothing to the second, then\nthe tactic to use is $T${\\small\\verb% THENL[%}$T_1${\\small\\verb|;ALL_TAC]|}.\n\\end{enumerate}\n\\end{itemize}\n\n\\subsubsection{\\tt NO\\_TAC : tactic}\n\n\\begin{itemize}\n\\item{\\bf Summary:} Tactic that always fails.\n\n\\item{\\bf Uses:} Writing tacticals.\n\\end{itemize}\n", "meta": {"hexsha": "90e6e45360ff80c794fe060e157821bc0fc3b105", "size": 49483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Tutorial/proof.tex", "max_stars_repo_name": "LiLiming/HOL", "max_stars_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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/proof.tex", "max_issues_repo_name": "LiLiming/HOL", "max_issues_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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/proof.tex", "max_forks_repo_name": "LiLiming/HOL", "max_forks_repo_head_hexsha": "8de43bf3176993a37fb2f917fe978964c9d0591c", "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.7492977528, "max_line_length": 139, "alphanum_fraction": 0.6771820625, "num_tokens": 15979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.6071193904132303}}
{"text": "\\chapter{Isomorphism Theorems and Series}\r\n\\section {Isomorphism Theorems:} \r\n{\\bf Isomorphism Theorem:} (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\\begin{quote}\r\n\\emph{Proof of 1:}  Let $N= ker(\\phi)$ and define $\\psi(Nx)= \\phi(x)$.  $\\psi$ is \r\nwell defined since $Nx=Ny \\rightarrow y=nx$ and $\\phi(y)= \\phi(nx)= \\phi(n) \\phi(x)= \\phi(x)$\r\nand is a homomorphism since $\\phi$ is.\r\nIf $\\psi(Nx)=\\psi(Ny)$ then $\\phi(xy^{-1}) \\in N$ so $Nx=Ny$ and $\\psi$ is 1-1.  The image\r\nof $\\psi$ is $Im(\\phi)$. So $\\psi$ is an isomorphism.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of 2:}  Define $\\psi(Kx)= Hx$.  $\\psi$ is well defined and is a homomorphism.\r\n$ker(\\psi)= Kh, h \\in H$ so $(G/K)/(H/K) \\cong G/H$ by the previous result.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of 3:}  Define $\\psi(Nh)= (H \\cap N) h$.  $\\psi$ is well defined and is a homomorphism.\r\n$ker(\\psi)=  \\{ h \\in H: h \\in H \\cap N \\}$ so $HN/N \\cong H/(H \\cap N)$ by (1).\r\n\\end{quote}\r\n{\\bf Definition 1:}\r\nA \\emph{derived series} is a sequence $G^{[0]}=G$, $G^{[i+1]}= [G^{[i]}, G^{[i]}]$.  \r\n$G$ is \\emph{solvable} iff\r\nderived series terminates at ${1}$.  \r\n\\\\\r\n\\\\\r\n{\\bf Definition 2:} The sequence of homomorphisms $A \\rightarrow_{\\alpha} B \\rightarrow_{\\beta} C$ is\r\n\\emph{exact} if $im(\\alpha )= ker( \\beta)$.  The sequence\r\n$1 \\rightarrow N \\rightarrow_{id} G \\rightarrow_{\\varphi} H \\rightarrow_{\\epsilon} 1 $ is a \r\n\\emph{short exact sequence} if the map $id$ is inclusion and $\\epsilon$ is the trivial homomorphism and\r\neach subsequence is exact; in this case, \r\n$G/N \\approx H$ by the above.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 3:}\r\nA \\emph{subnormal series} is a sequence of groups $G_i$ such that\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$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 4:}\r\nA \\emph{normal series} is a subnormal series where $G \\rhd G_i, \\forall i$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition 5:}\r\nA \\emph{chief series} is a normal series with no repeated terms and no normal subgroup properly\r\nlying between two series elements.  \r\n\\\\\r\n\\\\\r\n{\\bf Definition 6:}\r\nA \\emph{composition series} is a subnormal series \r\nterminating at $1$ in which $G_i/G_{i-1}$ is simple.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 1:} If $K \\lhd H <G$ and $N \\lhd G$ then $NK \\lhd NH$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $a, b \\in N, h \\in H, k \\in K$.\r\n$[ak,bh]= \r\nk^{-1} a^{-1}h^{-1}b^{-1} ak bh= \r\nk^{-1} a^{-1} (h^{-1}b^{-1} a h) \r\n(h^{-1}kh) (h^{-1} bh) \\in K N N K N = NK$.  So $[NK,NH] \\subseteq NK$ and $NK \\lhd NH$.\r\n\\end{quote}\r\n{\\bf Lemma 2:}\r\n$A(A^* \\cap B) \\cap A^* \\cap B^*= B(B^* \\cap A) \\cap A^* \\cap B^*$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIt suffices to show\r\n$A(A^* \\cap B) \\cap B^*= B(B^* \\cap A) \\cap A^*$.\r\nSuppose $x=at \\in A(A^* \\cap B) \\cap B^* , a \\in A, t \\in (A^* \\cap B) \\subseteq B^*$.\r\n$x= t (t^{-1}at) \\in BA \\cap B^*$; since $x \\in B^*, t^{-1} x \\in B^*$\r\nand $t^{-1} a t \\in B^* \\cap A$. Thus \r\n$A(A^* \\cap B) \\cap B^* \\subseteq B(B^* \\cap A) \\cap A^*$.\r\nSymmetrically, $A(A^* \\cap B) \\cap B^* \\supseteq B(B^* \\cap A) \\cap A^*$.\r\n\\end{quote}\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\n\\begin{quote}\r\n\\emph{Proof:}  \r\nApply lemma 1 with $N=A$, $K=A^* \\cap B$, $H= A^* \\cap B^*$, $G=A^*$ to get\r\n$A(A^* \\cap B) \\lhd A(A^* \\cap B^*)$.  Symmetrically,\r\n$B(B^* \\cap A) \\lhd B(A^* \\cap B^*)$.  \r\nSet $K_1= A(A^* \\cap B)$ and $K_2= B(B^* \\cap A)$.  Let \r\n$t_1 \\in {\\frac {A(A^{*} \\cap B^{*})} {A(A^{*} \\cap B) }}, \r\nt_2 \\in {\\frac {B(A^{*} \\cap B^{*})} {B(B^{*} \\cap A) }}$, $t_1=ayK_1, t_2=bzK_2$ where\r\n$a \\in A, b \\in B, y, z \\in (A^* \\cap B^*)$.\r\n$ay= y (y^{-1}ay)= ya'$ so $t_1= yK_1$.  Similarly, $t_2= zK_2$.\r\nDefine $h:\r\n{\\frac {A(A^{*} \\cap B^{*})} {A(A^{*} \\cap B) }} \\rightarrow\r\n{\\frac {B(B^{*} \\cap A^{*})} {B(B^{*} \\cap A) }}$ by $h(yK_1)= y K_2$.  The map is\r\nwell defined since $yK_1=zK_1$ iff $z^{-1}y \\in A(A^* \\cap B^*) \\cap A^* \\cap B^*$\r\niff\r\n$z^{-1}y \\in B(A^* \\cap B^*) \\cap A^* \\cap B^*$ by lemma 2.\r\n\\end{quote}\r\n{\\bf Theorem 1:}\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\\begin{quote}\r\n\\emph{Proof:} $1 \\rightarrow 2 \\rightarrow 3$ is trivial.  \r\nSuppose $S: 1=G_r \\lhd G_{r-1} \\lhd \\ldots \\lhd G_1 \\lhd G_0=G$ has abelian factors.\r\nClaim: $G^{(j)} \\le G_j$.  Note that $G' \\subseteq G_1$ since $G/G_1$ is abelian.  \r\nThe claim follows\r\nfrom by an easy induction.\r\n\\end{quote}\r\n{\\bf Definition:} Two normal series, \r\n$G_0 \\geq G_1 \\geq G_2 \\geq \\ldots \\geq G_n$ and\r\n$H_0 \\geq H_1 \\geq H_2 \\geq \\ldots \\geq H_m$, are \\emph{equivalent} if $m = n$ and\r\n$G_i/G_{i+1} \\cong H_{\\pi(i)}/H_{\\pi(i)+1}$ for some permutation, $\\pi$.\r\n\\\\\r\n\\\\\r\n{\\bf Schreier's Theorem:} Two normal series for $G$ have equivalent refinements.\r\nTwo compositions series for $G$ are equivalent.\r\n\\begin{quote}\r\n\\emph{Proof:}  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\\end{quote}\r\n{\\bf Jordan-Holder Theorem:} If $G$ has a composition series, $S$,  then any\r\nsubnormal series $S^*$ can be refined to a composition series and any two composition series\r\nare equivalent.\r\n\\begin{quote}\r\n\\emph{Proof:} $S$ and $S^*$ have equivalent refinements by Schreier.  Remove any repetitions to\r\nproduce new equivalent refinements.  Since a composition series does not have proper refinements,\r\nthe series are equivalent.\r\n\\end{quote}\r\n{\\bf Butterfly Lemma:} If $U, V  \\subseteq G$, $u \\lhd U$, and $v \\lhd V$ then\r\n$u(U \\cap v) \\lhd u(U \\cap V)$,\r\n$(u \\cap V)v \\lhd (U \\cap V)v$ and \r\n$u(U \\cap V)/u(U \\cap v) \\cong (U \\cap V)v/(u \\cap V)v$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $H= (U \\cap V)$ [resp. $(U \\cap V)v$] and $N= u(U \\cap v)$ [resp. $(u \\cap V)v$].\r\nWe show $N \\lhd HN$.\r\nLet $x= a_1 b_1 \\in HN$ and $y = a_2 b_2 \\in N$, $a_1, a_2 \\in u, b_1 \\in (U \\cap V), b_2 \\in (U \\cap v)$.\r\n$x^{-1} y x = b_1^{-1} a_1^{-1} a_2 b_2 a_1 b_1 = b_1^{-1} a_1^{-1} a_2 b_1 b_1^{-1} b_2 b_1 b_1^{-1} a_1 b_1 =$\r\n$a_3 b_3 a_4 b_3^{-1} a_1 b_3 = a_3 b_3 a_4 $, $a_3, a_4 \\in u, b_3 \\in (U \\cap v)$.  So $x^{-1} y x =\r\n= a_3 b_3 a_4 b_3^{-1} b_3$.  Thus $x^{-1} y x \\in u(U \\cap v)$ and $N \\lhd H$.\r\n$HN =(U \\cap V)u(U \\cap v) = u(U \\cap V)$.  $u(U \\cap V)/u(U \\cap v) = HN/N \\cong H/(H \\cap N) = (U \\cap V)/(U \\cap V \\cap u(U \\cap v)$.\r\nNow we show, $U \\cap V \\cap u(U \\cap v) = (U \\cap v) (V \\cap u)$.  Let $a_1 b_1 \\in u(U \\cap v), a_1 \\in u, b_1 \\in (U \\cap v)$.\r\nIf $a_1 b_1 \\in V$, $a_1 \\in V$ (since $b_1 \\in v \\subseteq V$), thus $a_1 \\in (u \\cap V)$ and $a_1 b_2 \\in (u \\cap V) (U \\cap v)$.\r\nWe've shown, $u(U \\cap V)/u(U \\cap v) \\cong (U \\cap V)/(u \\cap V)(U \\cap v)$.  A symmetric aargument shows\r\n$(U \\cap V)v/(u \\cap V)v \\cong (U \\cap V)/(u \\cap V)(U \\cap v)$.  So $u(U \\cap V)/u(U \\cap v) \\cong (U \\cap V)v/(u \\cap V)v$,\r\nwhich is what we wanted.\r\n\\end{quote}\r\n{\\bf Another proof of Schrier:} Let \r\n$1 \\lhd G_r \\lhd \\ldots \\lhd G_1 = G$ and\r\n$1 \\lhd H_s \\lhd \\ldots \\lhd H_1 = H$ be normal towers, they have equivalent refinements.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nPut $G_{ij} = G_{i+1}(H_j \\cap G_i)$ and $H_{ji} = H_{j+1}(G_i \\cap H_j)$.  Use the butterfly to show\r\n$G_{ij}/G_{i,j+1} \\cong H_{ji}/H_{j, i+1}$.\r\n\\end{quote}\r\n\\section {Indecomposible Groups and Krull Schmidt}\r\n{\\bf Definition 7:}\r\n$\\phi$ is a \\emph{normal endomorphism} iff\r\n$\\phi(a^{-1}xa)=\r\na^{-1} \\phi(x)a$, $\\forall x,a \\in G$.\r\nA group, $G$, is \\emph{indecomposible}, if $G \\ne 1$, and if $G = H \\times K$ then either\r\n$H = 1$ or $K = 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma 1:} \r\nIf $\\phi$ and $\\psi$ are normal endomorphisms of a group $G$ then so is their composition\r\nand so is $\\phi^{-1}$..\r\nIf $\\phi$ is a normal endomorphism of $G$ and if $H \\lhd G$ then $\\phi(H) \\lhd G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Routine.\r\n\\end{quote}\r\n{\\bf Lemma 2:}  Let $G = H_1 \\times \\ldots \\times H_m$ have projections $\\pi_i : G \\rightarrow H_i$\r\nand inclusions $\\lambda_j : H_i \\rightarrow G$ then the sum of any $k$ distinct $\\lambda_i \\pi_i$\r\nis a normal endomorphism of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Routine.\r\n\\end{quote}\r\n{\\bf Lemma 3:} \r\nIf $H \\lhd G$ and both $H$ and $G/H$ have both chain conditions then $G$ has both chain conditions.\r\nIf $G= H \\times K$ and $G$ has both chain conditions then so do $H$ and $K$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf \r\n$G_1 \\ge G_2 \\ge \\ldots$ is a chain of normal subgroups of $G$ then\r\n$H \\cap G_1 \\ge H \\cap G_2 \\ge \\ldots$ \r\nis a chain of normal subgroups of $H$ and\r\n$HG_1 /H \\ge HG_2 /H \\ge \\ldots$ \r\nis a chain of normal subgroups of $G/H$.  \r\n$\\exists t,s: H \\cap G_t= H \\cap G_{t+1} = \\ldots$\r\n$HG_s /H= HG_{t+1} /H = \\ldots$; let $l= max(t,s)$.  $G_l=G_{l+1} = \\ldots$ so\r\n$G$ has ACC.  A similar argument holds for DCC.\\\\\r\n\\\\\r\nIf $G = H \\times K$ then every normal subgroup of $H$ is a normal subgroup of $G$ and\r\nevery chain of normal subgroups  of $H$ is a chain of normal subgroups of $G$.\r\n\\end{quote}\r\n{\\bf Theorem 2:} \r\nIf $G$ satisfies ACC or DCC then $G$ is the direct product of indecomposable groups.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nCall $G$ ``good'' if it satisfies the conclusion of the theorem.  If $G$ is indecomposible,\r\n$G$ is good and if $A$ and $B$ are good so is $A \\times B$.  So if $G= U \\times V$ is bad\r\neither $U$ is bad or $V$ is bad.  Supposed $G$ is bad.  Define $H_0=G$ and by induction,\r\n$\\exists H_1 , H_2 , \\ldots , H_n$ with $H_i$ a bad proper factor of $H_{i+1}$.\r\nso, $G=H_0 > H_1 > \\ldots$.  If $G$ has DCC, this must terminate at a bad indecomposible group\r\nwhich is a contradiction.\r\n\\end{quote}\r\n{\\bf Lemma 3:} \r\nIf $G$ satisfies ACC (resp. DCC) on normal subgroups \r\nand $f$ is a normal endomorphism\r\nof $G$, then $f$ is an injection iff $f$ is an surjection.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose $\\phi$ is an injection and $g \\in \\phi(G)$.   We prove by induction\r\nthat $\\phi^n(g) \\notin \\phi^{n+1}(G)$.   If not, $\\exists h \\in  G: \\phi^n(g)= \\phi^{n+1}(h)$ \r\nso $\\phi(\\phi^{n-1}(g)) = \\phi(\\phi^{n}(h))$.  Since\r\n$\\phi$ is injective, $\\phi^{n-1}(g)= \\phi^n(h)$ which contradicts the inductive hypothesis.\r\nThus $\\exists$ a chain $G > \\phi(G) > \\phi^2(G) > \\ldots$.  $\\phi$ is normal so\r\n$\\phi^n$ is normal and by a previous lemma $\\phi^n(G) \\lhd G, \\forall n$.  This violates\r\nthe DCC condition.\r\n\\\\\r\n\\\\\r\nNow assume $\\phi$ is surjective.  Define $K_n= ker(\\phi^n(G))$ with each $K_n \\lhd G$.\r\n$1 = K_0 \\le K_1 \\le \\ldots $.  This chain stops because of ACC.  Let $t$ be the smallest integer\r\nsuch that $K_t= K_{t+1} = \\ldots$.  We claim $t=0$.  If $t \\ge 1$ then $\\exists x \\in K_t$ with\r\n$x \\notin K_{t-1}$ so \r\n$\\phi^{t}(x) \\ne 1$ but $\\phi^{t+1}(x)=1$.\r\nSince $\\phi$ is a surjection, $\\exists g \\in G$ with $x= \\phi(g)$.  Hence\r\n$1 = \\phi^{t}(x) = \\phi^{t+1}(g)$ so $g \\in K_{t+1}= K_t$ and thus\r\n$a= \\phi(g)= \\phi^{t-1}(g) ( \\phi(g))= \\phi^{t-1}(g)$ which is a contradiction so $\\phi$\r\nis injective.\r\n\\end{quote}\r\n{\\bf Definition 8:} An endomorphism $\\phi$ of $G$ is nilpotent if $\\exists k>0: \\phi^j=0$;\r\nnote $0: g \\mapsto 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Fitting Lemma:}\r\nLet $G$ satisfy both chain conditions.  If $\\phi$ is a\r\nnormal endomorphism of $G$ with $\\phi(H)=H$ and $\\phi(K)=K$ then\r\n$G= H \\times K$ and\r\n$\\phi_{|K}$ is nilpotent and $\\phi_{|H}$ is surjective.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $K_n= ker(\\phi^n(G))$ and $H_n= im(\\phi^n(G))$.\r\n$G \\ge H_1 \\ge \\ldots $ and \r\n$1 \\le K_1 \\ge \\ldots $.  Suppose $H_i$ stops at $t$ and $K_i$ stops at $s$, $l= max(r,s)$.\r\nLet $x \\in H \\cap K$.  Since $x \\in H, \\exists g \\in G$ with $x= \\phi^l(g)$.\r\n$\\phi^l(x)=1$ so $\\phi^{2l}(g)=1$ and $g \\in K_{2l}= K_l$.  $x \\in \\phi^l(g)=1$ and\r\nso $H \\cap K=1$.\r\nIf $g \\in G$ then $\\phi^l(g) \\in H_l = H_{2l}$ so\r\n$\\exists y \\in G: \\phi^l(g)= \\phi^{2l}(y)= 1$ and\r\n$\\phi^l(g \\phi^l(y^{-1}))=1$ so\r\n$g \\phi^l(y^{-1}) \\in K_{l}=K_{2l}$ so $g=(g \\phi^l(y^{-1}))\\phi^l(y) \\in KH$ and $G= K \\times H$.\r\nNow, $\\phi(H)=\\phi(H_l)= \\phi(\\phi^l(G))= \\phi^{l+1}(G)= H_{l+1}=H_j=H$ so\r\n$\\phi$ is surjective.  Finally, if $x \\in K$ then $\\phi^l(x) \\in K \\cap H=1$ and so\r\n$\\phi_{|K}$ is nilpotent.\r\n\\end{quote}\r\n{\\bf Theorem 3:}\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\\begin{quote}\r\n\\emph{Proof:}  \r\nBy Fitting Lemma, $G= K \\times H$ with $\\phi_{|K}$ and $\\phi_{|H}$ surjective.\r\nSince $G$ is indecomposible, then either $G=H$ or $G=K$.  In the first case,\r\n$\\phi$ is nilpotent.  In the second case, $\\phi$ is surjective and so by the previous Lemma,\r\n$\\phi$ is an automorphism.\r\n\\end{quote}\r\n{\\bf Lemma:} Let $G$ be an indecomposible group with both chain conditions and\r\nsuppose $\\phi, \\psi$ are two normal, nilpotent endomorphisms of $G$.  If $\\phi+\\psi$ is\r\nan endomorphism of $G$ then it is nilpotent.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy the previous result, \r\n$\\phi+\\psi$ is either an automorphism or nilpotent.\r\nIf it is an automorphism, there is an inverse, $\\gamma$, normal.\r\nFor each $x \\in G$, $x= (\\phi+\\psi) \\gamma(x))= \\phi(\\gamma(x)) + (\\psi(\\gamma(x))$. \r\nIf $\\lambda= \\phi \\gamma$  and $\\mu= \\psi \\lambda$,\r\n$1_G= \\lambda+\\mu$.  In particular,\r\n$x= \\lambda(x) \\mu(x)$ and so $\\lambda+\\mu= \\mu+\\lambda \\rightarrow \\lambda \\mu = \\mu \\lambda$.\r\n$End(G)$ is generated by $\\mu, \\lambda$ and \r\n$(\\lambda + \\mu)^m = \\sum {m \\choose i} \\phi^i \\psi^{m-i}$.  Since both\r\n$\\phi$ and $\\psi$ are nilpotent so are $\\lambda$ and $\\mu$ and they are not automorphisms.\r\nSo, $\\exists r, s: \\lambda^r=\\mu^s=0$.  If $m=r+s-1$ then either\r\n$i \\ge r$ or $m-i \\ge s$ so $1_G^m =0$ and $G=1$.\r\n\\end{quote}\r\n{\\bf Corollary:}  Let $G$ be an indecomposible group having both chain conditions.\r\nIf $ \\varphi_1, \\ldots, \\varphi_n $\r\nis a set of normal, nilpotent endomorphisms of $G$ such that every sum of distinct\r\n$\\varphi$'s is an endomorphism, then\r\n$ \\varphi_1 + \\ldots + \\varphi_n $ is nilpotent.\r\n\\begin{quote}\r\n\\emph{Proof:}  By induction on $n$.\r\n\\end{quote}\r\n{\\bf Krull-Schmidt Theorem:}  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$. \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $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\\end{quote}\r\n\\section {Inner Automorphisms}\r\n{\\bf Definitions 9:} $G$ is \\emph{complete} if it is centerless and every automorphism is inner\r\nin which case $G \\cong Aut(G)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 4:} $S_n$ is complete if $n \\ne 2,3$.\r\n\\begin{quote}\r\n\\emph{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\n\\end{quote}\r\n{\\bf Theorem 5:}\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 $ \\langle K^l, Aut(K) \\rangle $, $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\\begin{quote}\r\n\\emph{Proof:}\r\nSee, Scott.\r\n\\end{quote}\r\n", "meta": {"hexsha": "0fcb53a36e8bd9dd704a48fdaf2dd4b283e654ad", "size": 17895, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtIsomorphism.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/gtIsomorphism.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/gtIsomorphism.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": 48.6277173913, "max_line_length": 137, "alphanum_fraction": 0.6050293378, "num_tokens": 7308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.607119388698674}}
{"text": "\n\n\\subsection{Applications to combinatorial sums}\n\n\\citeauthor{sprugnoli:1991}, in \\cite{sprugnoli:1991}, shows how the\n\\emph{Riordan group} and its elements \\emph{Riordan arrays} provide an elegant\nmethodology to solve combinatorial sums. This method is quite different from\nones proposed in \\cite{egorychev:1990}, \\cite{wilf:zeilberger:1990} and\n\\cite{wilf:1989}, since it offer a \\emph{constructive} proof for a sum identity\n$\\sum_{k}f_{k}=v$: \\marginpar{not only a $certification$ for $\\sum_{k}f_{k}=v$}\nin addition to be a \\emph{certification} for the identity, it shows how to find\nsuch value $v$. \n\nThe following result is another way to state\n\\autoref{thm:riordan:group:fundamental:theorem} and it allows us to show in the\nproof an interesting trick about coefficient extractor $[t^{n}]$. \n\n\\begin{theorem}\n    Let $\\mathcal{M}=(d(t),h(t))$ be a Riordan matrix and $\\vect{\\omega}$ \n    be a \\emph{given} sequence $\\lbrace\\omega_{i}\\rbrace_{i\\in\\mathbb{N}}$. Choose\n    a row index $n\\in\\mathbb{N}$, then:\n    \\begin{displaymath}\n        \\sum_{k=0}^{n}{m_{nk}\\,\\omega_{k}}=[t^{n}]d(t)\\Omega(h(t))\n    \\end{displaymath}\n    where function $\\Omega$ is a \\ac{gf} of sequence $\\vect{\\omega}$.\n    \\label{thm:sprugnoli:riordan:combinatorial:sums}\n\\end{theorem}\n\n\\begin{proof}\n    By relation among Riordan array $\\mathcal{M}$ and matrix \n    $\\lbrace m_{nk}\\rbrace_{n,k\\in\\mathbb{N}}$:\n    \\begin{displaymath}\n        \\sum_{k=0}^{n}{m_{nk}\\omega_{k}}\n            =\\sum_{k=0}^{n}{[t^{n}]m_{k}(t)\\,\\omega_{k}}\n            =d(t)\\sum_{k=0}^{n}{[t^{n}]h(t)^{k}\\,\\omega_{k}}\n    \\end{displaymath}\n    since summing $n+1$ coefficients extracted from $n+1$\n    \\marginpar{a trick on $[t^{n}]$ within a sum: moving it from inside to outside}\n    convolutions of function $h$ with itself, is the same as\n    do $n+1$ convolutions of function $h$ with itself, sum them\n    and, lately, do \\emph{one} coefficient extraction. Therefore:\n    \\begin{displaymath}\n        =[t^{n}]d(t)\\sum_{k=0}^{n}{\\omega_{k}\\,h(t)^{k}}\n        =[t^{n}]d(t)\\Omega(h(t))\n    \\end{displaymath}\n    as required.\n\\end{proof}\n\nFor the sake of clarity, we would like to apply previous result to\nPascal array $\\mathcal{P}$ in order to find diagonal sums. Define\na new array $\\hat{\\mathcal{P}}$ as:\n\\begin{equation}\n    \\hat{\\mathcal{P}}=\\left(\\frac{1}{1-t},\\frac{t^{2}}{1-t}\\right)\n    \\label{eq:pascal:array:for:diagonals}\n\\end{equation}\nin order to have coefficients lying on diagonals in \\autoref{eq:pascal:array:derived:for:example}\nto lie on rows. The following is the matrix denoted by $\\hat{\\mathcal{P}}$:\n\\marginpar{an example: computing diagonal sums of array $\\mathcal{P}$}\n\\begin{displaymath} \n    \\left[\n    \\begin{array}{rrrrr}\n    1 &  &  &  &   \\\\\n    1 &  &  &  &   \\\\\n    1 & 1 &  &  &   \\\\\n    1 & 2 &  &  &   \\\\\n    1 & 3 & 1 &  &   \\\\\n    1 & 4 & 3 &  &   \\\\\n    1 & 5 & 6 & 1 &   \\\\\n    1 & 6 & 10 & 4 &  \\\\\n    1 & 7 & 15 & 10 & 1 \\\\\n    1 & 8 & 21 & 20 & 5 \n    \\end{array}\n    \\right] \n\\end{displaymath}\nwhere $d_{nk}\\in\\mathcal{P} \\rightarrow d_{n-k,k}\\in\\hat{\\mathcal{P}}$, \ntherefore array $\\hat{\\mathcal{P}}$ is defined over matrix \n$\\left\\lbrace{{n-k}\\choose{k}}\\right\\rbrace_{n,k\\in\\mathbb{N}}$.\nConsider sequence $\\vect{1}=\\lbrace1\\rbrace_{n\\in\\mathbb{N}}$, \n\\autoref{thm:sprugnoli:riordan:combinatorial:sums} allows us to write the sum\nof coefficients lying on row $n$ as:\n\\marginpar{sum of the $n$-th $\\mathcal{P}$'s diagonal yield the $n$-th Fibonacci number}\n\\begin{displaymath}\n    \\sum_{k=0}^{n}{{{n-k}\\choose{k}}}=[t^{n}]\n        \\frac{d_{\\hat{\\mathcal{P}}}(t)}{1-h_{\\hat{\\mathcal{P}}}(t)}\n        =[t^{n}]\\frac{1}{1-t-t^{2}}\n        =F_{n}\n\\end{displaymath}\nwhere $F_{n}$ is the $n$-th \\emph{Fibonacci number}.\n\\\\\\\\\nThe following result is very interesting because it allows us to solve\nmore combinatorial sum using both a Riordan array $\\mathcal{M}$\nand its inverse $\\mathcal{M}^{-1}$.\n\n\\begin{theorem}\n    Let $\\mathcal{M}=(d(t),h(t))$ be a Riordan array and $\\vect{\\omega}$ \n    be a sequence $\\lbrace\\omega_{i}\\rbrace_{i\\in\\mathbb{N}}$ with an \\emph{unknown} \n    \\ac{gf} $\\Omega$. Choose a row index $n\\in\\mathbb{N}$, if $\\vect{\\theta}$ is a  \n    sequence $\\lbrace\\theta_{i}\\rbrace_{i\\in\\mathbb{N}}$ with a \\emph{given} \\ac{gf} $\\Theta$, \n    then:\n    \\begin{displaymath}\n        \\sum_{k=0}^{n}{\\tilde{m}_{nk}\\,\\theta_{k}}=\\omega_{n}\n        \\quad\\rightarrow\\quad \n        \\sum_{k=0}^{n}{m_{nk}\\,\\omega_{k}}=\\theta_{n}\n    \\end{displaymath}\n    where $\\tilde{m}_{nk}\\in\\mathcal{M}^{-1}$. Moreover, \n    $\\Omega(t)=\\frac{1}{d(\\hat{h}(t))}\\,\\Theta(\\hat{h}(t))$,\n    where function $\\hat{h}$ is the compositional inverse of \n    function $h$.\n    \\label{thm:sprugnoli:sequences:inversion:by:combinatorial:sums}\n\\end{theorem}\n\n\\begin{proof}\n    By \\autoref{thm:sprugnoli:riordan:combinatorial:sums} we can rewrite:\n    \\begin{displaymath}\n        \\sum_{k=0}^{n}{\\tilde{m}_{nk}\\,\\theta_{k}}\n            = [t^{n}]\\frac{1}{d(\\hat{h}(t))}\\,\\Theta(\\hat{h}(t)) \n            = [t^{n}]\\Omega(t) = \\omega_{n}\n    \\end{displaymath}\n    which sets unknown function $\\Omega$, namely the \\ac{gf} for \n    sequence $\\vect{\\omega}$, such that $\\Omega(t)=\\frac{1}{d(\\hat{h}(t))}\\,\\Theta(\\hat{h}(t))$. \n    Then:\n    \\begin{displaymath}\n        \\sum_{k=0}^{n}{m_{nk}\\,\\omega_{k}}\n            = [u^{n}]d(u)\\Omega(h(u))\n            = [u^{n}]\\Theta(u)\n            = \\theta_{n}\n    \\end{displaymath}\n    as required.\n\\end{proof}\n\nWhy is \\autoref{thm:sprugnoli:sequences:inversion:by:combinatorial:sums} important?\n\\marginpar{another way to find \\ac{gf} for a row in a Riordan array}\nAssume that you have a Riordan array $\\mathcal{M}=(d(t),h(t))$ over a matrix of coefficients\n$\\lbrace m_{nk}\\rbrace_{n,k\\in\\mathbb{N}}$. You are interested to find the\n\\ac{gf} $\\Omega$ of a row $r\\in\\mathbb{N}$ over the sequence:\n\\begin{displaymath}\n    \\vect{\\omega} \n        =(w_{0},w_{1},w_{2},\\ldots,w_{r},0,\\ldots)\n        =(m_{r0},m_{r1},m_{r2},\\ldots,m_{rr},0,\\ldots)\n\\end{displaymath}\nwhen you know the \\ac{gf} $\\Theta$ over a sequence $\\vect{\\theta}$ such that:\n\\begin{displaymath}\n    \\sum_{k=0}^{n}{m_{nk}\\,\\omega_{k}}\n        =\\sum_{k=0}^{n}{m_{nk}\\,m_{rk}}\n        =\\theta_{n}\n\\end{displaymath}\napplying \\autoref{thm:sprugnoli:sequences:inversion:by:combinatorial:sums},\nit is necessary to find $\\mathcal{M}^{-1}$ and compute function $\\Omega$ as:\n\\begin{displaymath}\n    \\Omega(t)=\\frac{1}{d(\\hat{h}(t))}\\,\\Theta(\\hat{h}(t))\n\\end{displaymath}\nsuch function $\\Omega$ is the desired one, namely the \\ac{gf} over\nsequence $\\vect{\\omega}$, itself over coefficients lying on row $r$, as required.\n", "meta": {"hexsha": "e6edfb730a6fc7c95fb910ff73a6e162d4d255aa", "size": 6573, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classicthesis/Chapters/back-to-the-basics/sprugnoli.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/back-to-the-basics/sprugnoli.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/back-to-the-basics/sprugnoli.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": 42.6818181818, "max_line_length": 97, "alphanum_fraction": 0.6251331203, "num_tokens": 2391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6071193818404486}}
{"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 \\#3 \\end{Large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\n\\begin{document}\n\n\\maketitle\n%%---------------------------------------------------------------\n%% Problem 1\n%%---------------------------------------------------------------\n\\section{Problem 3.1}\n\\large{\\textbf{Solution:}}\\\\\n(a) The maximum likelihood estimates for $\\bm{\\mu}$ and $\\bm{\\Sigma}$ are given by:\n\\begin{equation*}\n\\hat{\\bm{\\mu}} = \\frac{1}{N} \\sum^N_{i=1} \\bm{x}_i\n\\end{equation*}\n\\begin{equation*}\n\\hat{\\bm{\\Sigma}} = \\frac{1}{N} \\sum^N_{i=1} (\\bm{x}_i - \\hat{\\bm{\\mu}}) (\\bm{x}_i - \\hat{\\bm{\\mu}})'\n\\end{equation*}\nWith MATLAB the maximum likelihood estimates for mean and covariances are:\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\mu_1}} = \\begin{bmatrix}\n 0.7969\\\\\n 0.4314\\\\ \n -1.4372\n\\end{bmatrix} &  \\hat{\\bm{\\mu_2}} = \\begin{bmatrix}\n 1.5947\\\\ \n 4.1320\\\\ \n -3.6648\n\\end{bmatrix} & \\hat{\\bm{\\mu_3}} = \\begin{bmatrix}\n 0.2426\\\\ \n -0.0509\\\\\n -0.0850\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_1 = \\begin{bmatrix}\n    2.8273  &  0.0296 &  -0.0082 \\\\\n    0.0296  &  4.9341  & -0.0832 \\\\\n   -0.0082  & -0.0832   & 1.9925\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_2  = \\begin{bmatrix}\n    1.0344  &  0.0419  &  0.0434 \\\\\n    0.0419  &  3.8840  &  1.0384 \\\\\n    0.0434  &  1.0384  &  5.9750\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_2  = \\begin{bmatrix}\n    9.7968  & -0.0261  &  0.1294\\\\\n   -0.0261  &  9.1673  &  0.0610\\\\\n    0.1294  &  0.0610  & 10.2171\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\vfill\n\\clearpage\n\n\\noindent(b) (c) As shown in Figure 1, the minimum error rate achieves at $\\alpha=0.12$. The classifier goes from under-fitting to over-fitting as $\\alpha$ goes from 1 to 0. The classifier does not perform well as $\\alpha$ approaches 1, i.e, the individual covariances ``shrink'' toward a common one, since the model is getting further from the truth. \\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{1bc.png}\n\\caption{Training\\ and\\ testing\\ error\\ versus $\\alpha$ from\\ 0\\ to\\ 1}\n\\end{figure}\n\n\\noindent(d) With MATLAB the maximum likelihood estimates for mean and covariances are:\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\mu_1}} = \\begin{bmatrix}\n  -0.0110 \\\\ \n  0.0054 \\\\ \n  0.0144 \\\\ \n\\end{bmatrix} &  \\hat{\\bm{\\mu_2}} = \\begin{bmatrix}\n 0.9931 \\\\\n 4.9504 \\\\\n -2.9815\n\\end{bmatrix} & \\hat{\\bm{\\mu_3}} = \\begin{bmatrix}\n 0.0254 \\\\\n 0.0571 \\\\\n -0.0778\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_1 = \\begin{bmatrix}\n    3.1963  & -0.7264  &  0.4860 \\\\\n   -0.7264  &  2.7638  &  2.7435 \\\\\n    0.4860  &  2.7435  &  3.7038\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_2  = \\begin{bmatrix}\n    1.0692  & -0.5619  &  0.1870  \\\\\n   -0.5619  &  3.1287  & -0.5232  \\\\\n    0.1870  & -0.5232  &  0.9506\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\n\\begin{equation*}\n\\begin{aligned}\n\\centering {\\begin{matrix}\n\\hat{\\bm{\\Sigma}}_2  = \\begin{bmatrix}\n    9.3002  & -5.2652  &  5.2015 \\\\\n   -5.2652  & 10.2951  & -5.0706 \\\\\n    5.2015  & -5.0706  & 12.1647\n\\end{bmatrix}\n\\end{matrix}}\n\\end{aligned}\n\\end{equation*}\n\n\\vfill\n\\clearpage\n\\noindent\\\\(e) (f) In this case, the training dataset is large enough for the model to learn the correct parameters. As we can see in Figure 2, the training error tracks the testing error. $\\alpha \\approx 0$ yields the best performance since the error rates reach minimum at $\\alpha \\approx 0$, where the estimated variance matrices are closest to the true ones. With shrinkage we could choose from numerous parameters for the variance matrix with best performance.\\\\\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{1ef.png}\n\\caption{Training\\ and\\ testing\\ error\\ versus $\\alpha$ from\\ 0\\ to\\ 1}\n\\end{figure}\n\\text{ }\\\\\n%%---------------------------------------------------------------\n%% Problem 2\n%%---------------------------------------------------------------\n\\section{Problem 3.2}\n\\large{\\textbf{Solution:}}\\\\\n(a) As described in the text, the basic version of the K-means algorithm is:\\\\\n\\\\\n\\textbf{K-means clustering Algorithm}\\\\\n1 Begin initialize $n,\\ c,\\ \\bm{\\mu}_1,\\ \\bm{\\mu}_2,...,\\ \\bm{\\mu}_c$\\\\\n2 Do classify $n$ samples according to nearest $\\bm{\\mu}_i$\\\\\n3 Recompute $\\bm{\\mu}_i$\\\\\n4 Until no change in $\\bm{\\mu}_i$\\\\\n5 Return $\\bm{\\mu}_1,\\ \\bm{\\mu}_2,...,\\ \\bm{\\mu}_c$\\\\\n6 End\\\\\n\\vfill\n\\clearpage\n\n(b) See Figure 3.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds1.png}\n\\caption{Result of clustering with k-means on dataset1.mat}\n\\end{figure}\n\n\\noindent(c) See Figure 4. Since k-means clustering is based on the assumption that all clusters have equal identity covariance matrices, it cannot classify the mixture ellipse dataset to their original shapes.\n\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds2.png}\n\\caption{Result of clustering with k-means on dataset2.mat}\n\\end{figure}\n\n\\vfill\n\\clearpage\n\\noindent(d) See Figure 5.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds3.png}\n\\caption{Result of clustering with k-means on dataset3.mat}\n\\end{figure}\n\n\\noindent(e) See Figure 6.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds4.png}\n\\caption{Result of clustering with k-means on dataset4.mat}\n\\end{figure}\n\n\\vfill\n\\clearpage\n(f) Knee occurs around $K = 4$\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds5.png}\n\\caption{MSE of dataset5.mat with k-means}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{ds52.png}\n\\caption{Result of clustering with k-means on dataset5.mat}\n\\end{figure}\n\n\n\n\n\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "3b674f7de883b93fd441f5649d390fdbb04e8c29", "size": 6528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-3/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-3/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-3/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": 26.0079681275, "max_line_length": 467, "alphanum_fraction": 0.6499693627, "num_tokens": 2357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6071193727606334}}
{"text": "\\chapter{The ALU}\r\n\r\n\\section{Design}\r\nFor a computer to be capable of effective operation, it needs the ability to perform\r\n actual processing of data. \r\nIt has long been known that the ability to compare two items and act upon the result is sufficient for effective computation \r\n---Turing Machines are based around this concept.\r\nIt would therefore have been possible to build a basic  comparison unit, and rely\r\non software  to derive mathematical and logical operations.\r\nThis would have been unreasonably  inefficient.\r\nAll realistic computers   have hardware dedicated to evaluation of these functions.\r\nThese Arithmetic and Logic Units ({\\bf ALU}) normally perform at least integer addition, subtraction and the standard boolean functions of two variables.\r\nMore powerful units are capable of high speed multiplication, or even manipulate\r\nfloating point numbers.\r\n\r\n\r\nAt the start of the project I was offered the possibility of using a \r\nsingle chip 64-bit floating point ALU from AMD (AM29C327) \\cite{amd:uprogramming,amd:29c300}.\r\nThis would have produced impressive performance figures, but I \r\ndecided that it would have been unworkable, since it was \r\ndesigned for a triple data bus and needed 31 bits of control \r\ninformation every cycle. A single bus system would have  been unable to use this \r\ndevice effectively. \r\n\r\nInstead I designed a very simple ALU, since this made \r\nformal specification  possible. The unit was  \r\nbuilt from eight bit sliced TTL ICs, each of which  operates on four bits.\r\n When connected together via a two level \r\n carry lookahead generator, they  perform   operations on 32-bit words.\r\n\r\nThis \r\nis sufficient for many purposes, except that the ability to shift \r\na word  right was needed in iterative multiplication and division algorithms.\r\n\r\n The result of the ALU had to be stored until  re-used in later instructions.\r\nThe state of this result, \r\nwhether zero or  negative  needed to obtained in a form\r\n which could be passed to the Skip register.\r\n Arithmetic overflow and carry flags were also desirable,\r\n   detecting results too large to be represented in 32 bits.\r\n \r\n\\section{Implementation}\r\n\r\nThe design of the ALU is shown in figure~\\ref{figure:alu}.\r\n\r\nAn Accumulator stores the output of the ALU between operations.\r\nThis can be read as a memory location.\r\nThe contents of the Accumulator are also used as one of the inputs to the ALU,\r\nso only one other argument needs to be supplied per operation.\r\nThis accumulator is built out of four SSRS, so can be read directly by the host.\r\n\r\nA number of bit sliced ALUs were available with built in accumulator registers. \r\nFor example,\r\nthe AMD AM2901 (\\cite{amd:logic}) or the TTL 74F681 ALU bit slices,\r\n would have provided enhanced performance with less components and wiring.\r\nUsing these would have prevented the host examining the Accumulator directly.\r\nInstead I used 74F381 ALU/function generators in my design.\r\nThese  only perform basic operations ---addition, subtraction, and, or, exclusive or, preset and clear. \r\nThree control signals  are used to select a function.\r\n\r\n\r\nBetween the outputs of the ALU ICs and the Accumulator is a bank of five PALS.\r\nNormally these pass the result straight through, each PAL checking if the bits passed though it are all zero or not.\r\nThey can also be instructed to shift the result ---including the carry flag--- one bit to the right; \r\nthis shifting is controlled by a  one bit signal.\r\nThis post shifting  allows a normal operation to be combined with a shift, to make unusual functions such as `subtract and divide by two'.\r\n\r\nThe results of the five \r\nzero tests along with other signals are fed to another PAL, which \r\nproduces values for a Condition Code register ({\\bf CC}),  constructed from a Shadow Serial Register. \r\nThe PAL generates a zero flag  when all five slices of the result are zero.\r\n\r\n\\begin{figure}\r\n\\vspace{20cm}\r\n\\caption{The ALU}\r\n\\label{figure:alu}\r\n\\end{figure}\r\n\r\n\\subsubsection{Overflow}\r\n\r\nAn arithmetic overflow is where  a signed number's sign changes due to too large an addition, subtraction or shift.\r\n\r\nMy design of an ALU does not detect signed overflow, despite the original intent to do so.\r\nI had originally\r\nacquired equations  from my CS3 notes to detect  overflows using a PAL.\r\nWhile specifying the system  I realised\r\nthese equations  only detected overflow on signed addition. \r\nTo detect overflow in a multi-function ALU, one must compare the carry between\r\nbit 30 and bit 31 of the result with the most significant bit, an overflow occuring if the two differ.\r\nThis can not be done with the 74F381 bit-sliced devices, as this carry is internal.\r\nI have discovered that AMD make a special most-significant-slice version of this bit-sliced ALU which does detect overflows internally. \r\nThe result of this check would however become confused if shifting was performed after the operation, so would not always be reliable.\r\n\r\n Note that even if the ALU did produce an overflow flag, the software would still have to check it after every operation. A number of\r\nimplementations of languages do not do this because of the overhead this entails; \r\nAPM Pascal and Standard ML are two such  implementations.\r\n\r\n\\subsubsection{Memory Interface}\r\n\r\nSeventeen addresses are allocated to the ALU, as shown in table~\\ref{table:memory}.\r\nOne of these addresses returns the current value of the Accumulator whenever it is read.\r\nThe remaining sixteen addresses all apply a different function between the accumulator and the word moved to the selected address.\r\nThis is accomplished by wiring  address bus lines directly to the ALU  and the PALS.\r\n\r\nIt is not be possible to directly load the \r\naccumulator, but a two instruction sequence  clears it and then adds a \r\nnumber to the now empty accumulator.\r\n\r\nCondition code flag manipulation is  supported:\r\nreading any of the sixteen function addresses returns one of the condition code flags in the least significant bit. \r\nThese results can be passed directly to the Skip register for conditional branching.\r\nBefore performing a subtraction the carry flag has to be set to true, while\r\nfor other operations the flag has to be cleared.\r\nAn address is provided to enable this; when it is written to, the least significant bit is passed to the carry flag.\r\n", "meta": {"hexsha": "744818e808bf95878a9b9ae7ff00d691b3f23823", "size": 6296, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/urisc/alu.tex", "max_stars_repo_name": "steveloughran/formality", "max_stars_repo_head_hexsha": "adb784eff346bfd9ac13db9589fbf233a41e7f16", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2015-02-03T22:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-11T08:00:28.000Z", "max_issues_repo_path": "papers/urisc/alu.tex", "max_issues_repo_name": "steveloughran/formality", "max_issues_repo_head_hexsha": "adb784eff346bfd9ac13db9589fbf233a41e7f16", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-06-29T15:52:11.000Z", "max_issues_repo_issues_event_max_datetime": "2015-06-30T18:38:04.000Z", "max_forks_repo_path": "papers/urisc/alu.tex", "max_forks_repo_name": "steveloughran/formality", "max_forks_repo_head_hexsha": "adb784eff346bfd9ac13db9589fbf233a41e7f16", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-05-08T14:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T08:00:30.000Z", "avg_line_length": 54.747826087, "max_line_length": 154, "alphanum_fraction": 0.7814485388, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6071174301586086}}
{"text": "% corrected VD 81\n\n\\subsubsection{Recurrent Neural Network}~\\\\\n\n%introduction\n\nRecurrent Neural Networks (RNNs) are a particular architecture of ANNs which can\nprocess sequential data $S = x_{1},\\dots,x_{n}$. In traditional ANN the input\nand output data are assumed to be independent. However, for sequential data,\nthis is usually not the case. For example, the prediction of the next word in a\nsentence is dependent on the words that appeared before. As opposed to MLP, RNN\nfeeds back their outputs back to their network and thus gain an overview of past\ninputs. To explain how RNNs are implemented, we have to introduce the notion of\ncomputational graphs. A computational graph is a formal structure representing a\nset of computations. We obtain a chain of events by unfolding a recurrent\ncomputation into a computational graph with a repetitive structure. \\\\\n\nConsider a recurrent system,\n\\begin{equation}\n  s_{t} = f(s_{t-1};\\theta)\n\\end{equation}\nwith $s$ being the state of the system. The graph can be unfolded considering\nthe time step $t = 3$, we have,\n\\begin{equation}\n  \\begin{split}\n    s_{3} & = f(s_{2};\\theta) \\\\\n          & = f(f(s_{1};\\theta);\\theta)\n  \\end{split}\n  \\label{recurrentsystem}\n\\end{equation}\nThis expression can be illustrated by a directed acyclic computational graph, as\nshown in Figure~\\ref{dag}\\\\\n\\input{sections/scientific/fr2/DAG.tex}\n\nNow we consider the recurrent system accepting an external signal $\\bm{x}_{t}$,\n\\begin{equation}\n  s^{t} = f(s^{t-1},\\bm{x}_{t};\\theta)\n  \\label{eqaccepting}\n\\end{equation}\nwhere the state $s$ is containing information about the past sequence $S$. The\nhidden units can be described with equation~\\ref{eqaccepting} using $\\bm{h}$ to\ndenote the state,\n\\begin{equation}\n  \\bm{h}_{t} = f(\\bm{h}_{t-1},\\bm{x}_{t};\\theta)\n\\end{equation}\nrepresented in Figure~\\ref{unfoldrnnaccepting}.\\\\\n\\input{sections/scientific/fr2/unfoldrnnaccepting.tex}\n\n%math\n\nWith graph unfolding, we can now present some common examples of an RNN. Here are\nsome important designs of RNNs:\\\\\n\n\\begin{itemize}\n  \\item RNNs which take a single input and produce an output at every time step\n    $t$. This is called a one-to-many RNN.\\\\\n  \\item RNNs which read an entire data sequence and produce a data sequence.\n    This is called a many-to-many RNN.\\\\\n  \\item RNNs which are connected recurrently between hidden units, read an\n    entire data sequence $S$ and produce only one single output. This is called\n    a many-to-one RNN.\\\\\n\\end{itemize}\n\n\\input{sections/scientific/fr2/noutputrnn.tex}\n\nWe pick the RNN represented in Figure~\\ref{noutputrnn} to develop forward\npropagation equations. This RNN takes in a data sequence $S$ and outputs for\nevery time step $t$ an output. In this figure, we didn't include an\nactivation function for the hidden units $h$. However, for the equations, we\nassume the activation function $\\mathcal{H}$ to be the hyperbolic tangent.\\\\\n\nLet $h_{0}$ be the initial state. For every time step from $t = 1$ to $t =\nn$, we apply the following equations:\n\\begin{align}\n  \\bm{a}_{t} & = \\bm{b} + \\bm{Wh}_{t-1} + \\bm{Ux}_{t} \\\\\n  \\bm{h}_{t} & = \\tanh(\\bm{a}_{t}) \\\\\n  \\bm{o}_{t} & = \\bm c + \\bm{Vh}_{t} \\\\\n  \\bm{\\hat y}_{t} & = softmax(\\bm o_{t})\n\\end{align}\nwhere $\\bm b$ and $\\bm c$ are the bias vectors and $\\bm U$, $\\bm V$ and $\\bm W$ are\nthe weight matrices.\\\\\n\n%problem\n\n\\textbf{The Challenge of Long-Term Dependencies.} The challenge of learning\nlong-term dependencies is that gradients, propagated through a very deep RNN,\ncan vanish or explode. Gradients can vanish when the gradients are converging to\n$0$ and therefore the weights won't be updated while learning. Exploding\ngradients happen if the gradients are too large and the loss function will never\nreach the optimized minimum. As a solution to the challenges of RNNs, effective\nsequence models used in practice are called gated RNNs. These include the long\nshort-term memory (LSTM) and the gated recurrent unit (GRU) based RNNs. Gated\nRNNs are based on the idea of creating paths through time that have gradients\nthat neither vanish nor explode.\\cite{doi:10.1162/neco.1997.9.8.1735}~\\\\\n", "meta": {"hexsha": "3559bb7fc6264d88d687e4aa912170cba9834e96", "size": 4120, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/scientific/fr2/recurrent.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/recurrent.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/recurrent.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": 43.3684210526, "max_line_length": 83, "alphanum_fraction": 0.7376213592, "num_tokens": 1168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6071174209198731}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 15}\n\\subsection{Lecture Notes - Rotating Frame Clickers}\nWhich of the following motion leads to fictituous forces?\n\\begin{enumerate}[1.]\n    \\item The frame moves at a constant velocity with respect to an inertial reference frame.\n    \\item The frame rotates at a constant angular velocity with respect to an inertial reference frame.\n    \\item The frame moves at a constant acceleration with respect to an inertial reference frame.\n    \\item The frame rotates at a constant angular acceleration with respect to an inertial reference frame.\n\\end{enumerate}\n\\begin{s}\nThree of these frames have fictituous forces (1 does not, its inertial). 2. We saw last day, 3/4 lead to fictituous forces as we will see today!\n\\end{s}\n\\noindent The coriolis and centrifugal \"forces\" are\n$$\n\\begin{array}{l}\n\\mathbf{F}_{\\text {coriolis }}=-2 \\mathrm{~m} \\boldsymbol{\\Omega} \\times \\mathbf{v} \\\\\n\\mathbf{F}_{\\text {centifitigal }}=-\\mathrm{m} \\boldsymbol{\\Omega} \\times(\\boldsymbol{\\Omega} \\times \\mathbf{r})\n\\end{array}\n$$\nWhich force is more important in the limit of slow velocity (in the rotating frame)?\n\\begin{s}\nIn the limit of slow velocity, the centrifugal force (independent of velocity) dominates (the Coriolois force is linear in velocity).\n\\end{s}\nA disk drive typically rotates at $3600$rpm, or $360$ radians per second. For a dust particle at radius $r = 5$cm, how fast must the particle be moving (in the rotating frame) for the Coriolis and the centrifugal forces to have approximately equal magnitude?\n\\begin{s}\nEquating the two expressions and solving for $\\abs{\\v{v}}$, we find that $\\abs{\\v{v}} = 900$cm/s.\n\\end{s}\n\\noindent A hockey 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. In the \\textbf{inertial} frame, which way does the path of the puck bend?\n\\begin{center}\n    \\includegraphics[scale=0.3]{Lecture-15/w15-img3.png}\n\\end{center}\n\\begin{s}\nThe path of the puck does not bend in the inertial frame; it retains a straight trajectory (there is no force acting on it!)\n\\end{s}\n\\noindent In the rotating frame, which way does the path of the puck bend?\n\\begin{s}\nApplying the RHR, we see that the path curves to the right when viewed from above (towards positive $x$).\n\\end{s}\n\\end{document}", "meta": {"hexsha": "537cfbaeca6ae61163a1c361a2f7a5b893aca1d5", "size": 2488, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-15/Lecture-Notes-15.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-15/Lecture-Notes-15.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-15/Lecture-Notes-15.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": 59.2380952381, "max_line_length": 346, "alphanum_fraction": 0.7548231511, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6069052711459644}}
{"text": "\\section{Network Level Performance with Retransmission mechanism}\n\\label{sec:op_over_infinite_plane_with_retransmission}\nIn this section, we extend the network level performance analysis by taking into account retransmission mechanism. Let $N_{\\text{max}}$ be the maximum allowed number of transmissions. We consider a conventional retransmission mechanism: in case of no reception of acknowledge from BS, a packet is retransmitted after a random interval until its delivery to BS or the reach of maximum allowed trials. For macro diversity, the retransmission mechanism may be different depends whether the BS is designed to acknowledge the received packet. For LPWAN such as LoRaWAN, the employed retransmission mechanism is completely the same as that use in slotted ALOHA cellular systems. For Sigfox, devices always transmit one packet $N_{\\text{max}}$ times no matter whether previous packet transmission is successful.\n\nIn case of retransmission, $p\\lambda_{m}$ is the fresh space-time arrival packet intensity and $L = p\\lambda_{m}/\\lambda_{b}$ is referred to as the fresh normalized load. We assume that each retransmission takes place at random over long intervals following the collisions that give rise to them, therefore, the aggregate uplink packets stream still follows a Poisson Point Process with aggregate time-space intensity $\\lambda_{\\text{agg}}$. Let $G = p\\lambda_{\\text{agg}}/\\lambda_{b}$ be the aggregated normalized load. \n\nAccording to Poisson's splitting property~\\cite{meyn2012markov}, the aggregate packet arrival process can be divided into $N_{max}$ mutually independent Poisson arrivals processes. Let $p_{f}$ be the failure probability of one transmission and $P_{f}$ be the network level packet loss rate after $N_{max}$ transmissions, namely $P_{f} =  p_f^{N_{max}} $. The relationship between aggregated normalized load $G$ and fresh normalized load $L$, depends whether the BS acknowledges the received packet, is as follows:\n\\begin{equation}\n\\label{eq:relationship_intensity_fresh_agg}\n\tG=\n\t\\begin{cases}\n\t\\frac{ 1-P_f }{1-P_f^{1/N_{\\text{max}}}} L, & \\text{ACK available} \\\\\n\tN_{\\textbf{max}} L , & \\text{otherwise}\n\t\\end{cases}\n\\end{equation}\n\\subsection{Best BS attach}\nConsider a typical device, at the origin, whose modified distance to the best BS is denoted by $r'$. The distribution of $r'$ is given by $(\\ref{eq:pdf_modified_r})$. From $\\eqref{eq:succ_proba_with_modified_r}$, its packet loss rate $p_{f, b}(r')$ with respect to $r'$ and $\\lambda_{\\text{agg}}$ is:\n\\begin{align}\n\t\\label{eq: fail_proba_with_modified_r_retrans}\n\tp_{f, b}(r') &= \\left[ 1 - exp(-p \\lambda_{\\text{agg}} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  {r'} ^ 2)\\right] ^{N_{\\text{max}}}, \\nonumber \\\\\n\t&= \\left[ 1 - exp(-B {r'} ^ 2)\\right] ^{N_{\\text{max}}},\n\\end{align} \nwhere $B = p \\lambda_{\\text{agg}} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}} $.\n\nThe network-level packet loss rate $P_{f,b}$ is obtained by averaging over the infinite plane:\n\\begin{align}\n\t\\label{eq:bs_best_att_analytical_retransmission}\n\tP_{f,b} &= \\mathbb{E}_{r}\\left[ p_{f, b}(r') \\right]  \\nonumber\\\\\n\t&= \\int_{0}^{+\\infty}  \\left[ 1- \\exp(-B {r'}^2 ) \\right] ^{N} 2 \\pi \\lambda_b e^{\\frac{2\\sigma^2}{\\gamma^2}}  \\exp( -\\lambda_b  e^{\\frac{2\\sigma^2}{\\gamma^2}} \\pi {r'}^2 ) r' dr' \\nonumber\\\\\n\t&\\overset{\\mathclap{\\strut\\text{(a)}}} =   \\sum_{i=0}^{N}\\left[ \\binom{N}{i} (-1)^i \\int_{0}^{+\\infty}  \\exp(-i B {r'}^2) 2 \\pi \\lambda_b e^{\\frac{2\\sigma^2}{\\gamma^2}}  \\exp( -\\lambda_b  e^{\\frac{2\\sigma^2}{\\gamma^2}} \\pi {r'}^2 ) r' dr' \\right]  \\nonumber\\\\\n\t&=   \\sum_{i=0}^{N}\\left[ \\binom{N}{i} (-1)^i \\frac{1}{iB + \\lambda_b  e^{\\frac{2\\sigma^2}{\\gamma^2}} \\pi }  \\pi \\lambda_b e^{\\frac{2\\sigma^2}{\\gamma^2}} \\right]  \\nonumber\\\\\t\n\t&=   \\sum_{i=0}^{N}\\left[ \\binom{N}{i} (-1)^i \\frac{1}{i A \\theta_{T}^{\\frac{2}{\\gamma}} G + 1 } \\right], \n\\end{align}\nwhere step $(a)$ is obtained by using binomial theorem and changing the order of summation and integration.\n\nWith a given $L$, network level packet loss level along side with other performance metrics, can be obtained by fixed point iteration method base on $\\eqref{eq:relationship_intensity_fresh_agg}$ and $\\eqref{eq:bs_best_att_analytical_retransmission}$.\n\\subsection{Selective Combining based Macro Diversity}\nLet $P_{f, m}$ and $p_{f, m}$ respectively be the network packet loss rate and one transmission failure probability. Similar to $\\eqref{eq: fail_proba_with_modified_r_retrans}$,  $p_{f, m}$ is allows:\n\\begin{align}\n\\label{eq: fail_proba_with_modified_r_retrans_macro_diversity}\np_{f, m}(r')\n&= \\left[ 1 - exp(-B {r'} ^ 2)\\right] ^{N_{\\text{max}}},\n\\end{align} \nwhere $B = p \\lambda_{\\text{agg}} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}} $.\nWith macro reception diversity, one packet is failed if and only if none of BS has decoded it after $N_{\\text{max}}$ trials. Using similar justification in Sec~$\\ref{sec:sc_macro_diversity}$, we have:\n\\begin{align}\n\\label{eq:definition_pfm_retransmission}\nP_{f,m} &= \\mathbb{E}\\left[  \\prod_{r_i \\in \\Phi_{b}} (1-p_{s}(r_i))^{N_{\\text{max}}} \\right], \\nonumber\\\\\n& = \\mathbb{E}\\left[  \\prod_{r_i \\in \\Phi_{b}} ( 1 - \\exp(-p \\lambda_{m} \\pi A e^{\\frac{2\\sigma^2}{\\gamma^2}} \\theta_{T}^{\\frac{2}{\\gamma}} r^2 ) )^{N_{\\text{max}}} \\right], \\text{with } r_i \\in \\left[0, +\\infty\\right].\n\\end{align} \nwhere $r_i$ is the modified distance between the device and BS with label $i$. By using Campbell theorem:\n\\begin{align}\n\\label{eq:bs_rx_divers_retransmission_analytical_before_last}\nP_{f,m} &= \\exp\\left\\lbrace -2\\pi \\lambda_{b} e^{\\frac{2\\sigma^2}{\\gamma^2}}\\int_{0}^{+\\infty} \\left[  1 - \\left( 1-\\exp(-Br^2) \\right) ^{N_{\\text{max}}} \\right]  rdr \\right\\rbrace.\n\\end{align}\nApplying binomial theorem to $\\eqref{eq:bs_rx_divers_retransmission_analytical_before_last}$:\n\\begin{align}\n\t\\label{eq:plr_bs_div_retransmission}\n\tP_{f,m} &= \\exp\\left\\lbrace -2\\pi \\lambda_{b} e^{\\frac{2\\sigma^2}{\\gamma^2}}\\int_{0}^{+\\infty} \\left[ -\\sum_{i=1}^{N_{\\text{max}}} \\binom{N}{i} (-1)^i \\exp(-iBr^2) \\right] rdr \\right\\rbrace \\nonumber\\\\\n\t&= \\exp\\left\\lbrace 2\\pi \\lambda_{b} e^{\\frac{2\\sigma^2}{\\gamma^2}} \\sum_{i=1}^{N_{\\text{max}}} \\int_{0}^{+\\infty} \\binom{N}{i} (-1)^i \\exp(-iBr^2) rdr \\right\\rbrace \\nonumber\\\\\n\t&= \\exp(\\sum_{i=1}^{N_{\\text{max}}} \\binom{N}{i} (-1)^{i} \\frac{1 }{i A \\theta^{2\\sigma^2/\\gamma^2} G })\n\\end{align}\nSimilarly, the combination of $\\eqref{eq:relationship_intensity_fresh_agg}$ and $\\eqref{eq:plr_bs_div_retransmission}$ allows to using fixed point iteration method to calculate the network level packet loss level with a given $L$.", "meta": {"hexsha": "a68b501c0ed1f615d80d7911c45681acc6988d08", "size": 6629, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter5/bs_rx_divers_op_plane_retransmission.tex", "max_stars_repo_name": "hansomesong/PhD-Thesis", "max_stars_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_stars_repo_licenses": ["MIT"], "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/bs_rx_divers_op_plane_retransmission.tex", "max_issues_repo_name": "hansomesong/PhD-Thesis", "max_issues_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_issues_repo_licenses": ["MIT"], "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/bs_rx_divers_op_plane_retransmission.tex", "max_forks_repo_name": "hansomesong/PhD-Thesis", "max_forks_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_forks_repo_licenses": ["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.2222222222, "max_line_length": 804, "alphanum_fraction": 0.7017649721, "num_tokens": 2247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6069052600683423}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\\title{Probability: Quiz 2}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\\section{Problem 1}\t\n\tIndicate True of False for each statment.\n\t\\subsection{Part A}\n\t$X$ and $Y$ are independent random variables. $X$ is uniformly distributed on $[-2,2]$. $Y$ is uniformly distributed on $[-1,5]$. If $Z=X+Y$, then $f_Z(3) = 1/6$.\n\t\\\\\\\\\n\t\\textbf{True}.\\\\\n\tThis PDF of the sum of two random variables is found through convolution, where $f_Z(z) = \\int_{-\\infty}^{\\infty}f_X(x)f_Y(z-x)~dx$.\\\\\\\\\n\t$f_Z(3) = \\int_{-\\infty}^{\\infty}f_X(x)f_Y(3-x)~dx$\\\\\n\t$f_X(x)$ in non-zero only for $x\\in[-2,2]$. $f_Y(y)$ is only non-zero for $y\\in [-1,5]$, thus $f_Y(3-x)$ is only non-zero for $x\\in [-2,4]$. The limits of integration is the union of these two sets: $[-2,2]$.\\\\\n\t$f_Z(3) = \\int_{-2}^{2}f_X(x)f_Y(3-x)~dx = \\left(\\frac{1}{6}\\right)\\left(\\frac{1}{4}\\right)\\left(2+2\\right) = \\frac{1}{6}$\\\\\n\t\\subsection{Part B}\n\tIf $X$ is a Gaussian random variable with mean $0$ and variance $1$, then the density function of of $Z=|X|$ is equal to $2f_X(x),z\\geq0$.\\\\\n\t\\\\\n\t\\textbf{True}. Since $X$ is symmetric about $0$, $Z=|X|$ means the probability of $-x$ adds to the probability of $x$, causing the $f_Z(z) = 2f_X(z)$ where $z\\geq0$.\\\\\n\t\\subsection{Part C}\n\tThe sum of a random number ($N$) of independent Gaussian random variables with zero mean and unit variance results in a Gaussian random variable, regardless of the distribution of $N$.\\\\\n\t\\\\\n\t\\textbf{False}\\\\\n\tFor $Y = X_1 + X_2 + \\dots + X_N$, the transform of $Y$ can be found as such.\\\\\n\t$M_Y(s) = M_N(s)|_{e^s = M_X(s)}$. Let $N$ be Gaussian.\\\\\n\t\\\\\n\t$M_N(s) = e^{s^2/2}$ and since $X$ is Gaussian, $M_X(s) = e^{s^2/2}$.\\\\\n\t\\\\\n\tThus, $M_Y(s) = \\sqrt{(e^s)^s}|_{e^s=M_X(s)} = \\sqrt{(e^{s^2/2})^s}$, which is clearly not Gaussian.\\\\\n\t\\subsection{Part D}\n\tIf $X$ and $Y$ are independent random variables, both exponentially distributed with parameters $\\lambda_1$ and $\\lambda_2$ respectively, then the random variable $Z = \\min\\{X,Y\\}$ is also exponentially distributed.\\\\\n\t\\\\\n\t\\textbf{True}\\\\\n\tThe CDF $F_Z(z) = P(Z\\leq z) = P(\\min\\{X,Y\\}\\leq z)$ is not immediately evident, but $1-F_Z(z)$ is.\\\\\n\t\\[\n\t\t1-F_Z(z) = P(Z > z) = P(\\min\\{X,Y\\} > z)\n\t\\]\n\t\\[\n\t\t= P(X>z, Y>z) = P(X>z)~P(Y>z)\n\t\\]\n\t\\[\n\t\t= \\left(1-F_X(z)\\right)\\left(1-F_Y(z)\\right) = \\left(1-1+e^{-\\lambda_1z}\\right)\\left(1-1+e^{-\\lambda_2z}\\right)\n\t\\]\n\t\\[\n\t\t1-F_Z(z) = e^{-(\\lambda_1 + \\lambda_2)z}\n\t\\]\n\t\\[\n\t\tf_Z(z) = (\\lambda_1+\\lambda_2)e^{-(\\lambda_1 + \\lambda_2)z}\n\t\\]\\\\\n\t\\subsection{Part E}\n\tLet the transform associated with random variable $X$ be $M_X(s) = \\left(\\frac{e^s}{1-s}\\right)^{15}$. $\\textbf{E}[X]$ is equal to 30.\\\\\n\t\\\\\n\t\\textbf{True}\\\\\n\t\\[\n\t\t\\textbf{E}[X] = \\frac{d}{ds}M_X(s)|_{s=0} = 15\\left(\\frac{e^s}{1-s}\\right)^{14}\\frac{(1-s)e^s + e^s}{(1-s)^2}|_{s=0}\n\t\\]\n\t\\[\n\t\t\\textbf{E}[X] = 15\\left(\\frac{1}{1-0}\\right)^{14}\\frac{(1)(1)+1}{(1-0)^2} = 15~(2) = 30\n\t\\]\\\\\n\t\\subsection{Part F}\n\t$X$ and $Y$ are independent random variables. $Y$ is normal with mean 0 and variance 1, $X$ is uniform on $[0,1]$. $Z=X+Y$. The conditional density of $Z$ given $X$, $f_{Z|X}(z|x)$ is normal with mean $x$ and variance 1.\\\\\n\t\\\\\n\t\\textbf{True}\\\\\n\t$Z$ given some $x$ is the normal random variable $Y$ plus $x$, $Z|x = Y + x$. Thus, $\\textbf{E}[Z|X] = \\textbf{E}[Y] + x$ and $\\text{Var}(Z|X) = \\text{Var}(Y)$.\\\\\n\t\\subsection{Part G}\n\tVar($Z$)=2.\\\\\n\t\\\\\n\t\\textbf{False}\\\\\n\tSince $X$ and $Y$ are independent, Var($X+Y$)=Var($X$)+Var($Y$)\\\\So, Var($Z$) = $\\frac{1}{12} + 1 \\neq 2$.\\\\\n\t\\subsection{Part H}\n\t$\\textbf{E}[X|Z=-1]=-1$\\\\\n\t\\\\\n\t\\textbf{False}\\\\\n\t$X$ is bounded by $[0,1]$, so it cannot take the value of -1.\\\\\n\t\\subsection{Part I}\n\tCov($X$,$Z$) = Var($X$)\\\\\n\t\\\\\n\t\\textbf{True}\\\\\n\t\\[\n\t\t\\text{Cov}(X,Z) = \\textbf{E}[XZ] - \\textbf{E}[X]\\textbf{E}[Z]\n\t\\]\n\t\\[\n\t\t= \\textbf{E}[X(X+Y)] - \\textbf{E}[X]\\textbf{E}[X+Y]\n\t\\]\n\t\\[\n\t\t= \\textbf{E}[X^2] + \\textbf{E}[XY] - \\textbf{E}[X]^2 - \\textbf{E}[X]\\textbf{E}[Y]\n\t\\]\n\t\\[\n\t\t= \\textbf{E}[X^2] - \\textbf{E}[X]^2 + \\textbf{E}[XY] - \\textbf{E}[X]\\textbf{E}[Y]\n\t\\]\n\t\\[\n\t\t= \\text{Var}(X) + \\text{Cov}(X,Y)\n\t\\]\n\tAnd since $X$ and $Y$ are independent, Cov($X$,$Y$)=0, thus Cov($X$,$Z$) = Var($X$)\\\\\n\t\\subsection{Part J}\n\t$Z = \\textbf{E}[X|Z] + \\textbf{E}[Y|Z]$\\\\\n\t\\\\\n\t\\textbf{True}\\\\\n\t$\\textbf{E}[Z|Z] = \\textbf{E}[X+Y|Z]$ and since conditional expectation is linear, $\\textbf{E}[Z|Z] = Z = \\textbf{E}[X|Z] + \\textbf{E}[Y|Z]$\n\t\\pagebreak\n\t\\section{Problem 2}\n\t\\subsection{Part A}\n\tFind the least squares estimate of $Y$ given $X=x$, for all possible values of $x$.\\\\\n\t\\\\\n\t\\[\n\t\\mathbf{E}[Y|X] = \n\t\\begin{cases}\n\t\\frac{1}{2} & 0 \\leq X < 1\\\\\n\tX-\\frac{1}{2} & 1 \\leq X \\leq 2\n\t\\end{cases}\n\t\\]\n\t\\\\\n\t\\subsection{Part B}\n\tLet $g(x)$ be the estimate from Part A. Find $\\mathbf{E}[g(X)]$ and Var$(g(X))$.\\\\\n\t\\\\\n\t\\[\n\t\\mathbf{E}[g(X)] = \\int_{0}^{2}g(x)f_X(x)~dx = \n\t\\frac{1}{2}\\left(\n\t\\int_{0}^{1}\\frac{1}{2}~dx + \\int_{1}^{2}x-\\frac{1}{2}~dx\n\t\\right)\n\t\\]\n\t\\[\n\t\\mathbf{E}[g(X)] = \\frac{1}{2}\\left(\n\t\\frac{1}{2} + 1 - 0\n\t\\right) = \\frac{3}{4}\n\t\\]\n\t\\[\n\t\\mathbf{E}[g(X)^2] = \\int_{0}^{2} g(x)^2f_X(x)~dx=\n\t\\frac{1}{2}\\left(\n\t\\frac{1}{4} + \\int_{1}^{2}(x-\\frac{1}{2})^2~dx\n\t\\right) = \\frac{1}{2}(\\frac{1}{4}+\\frac{13}{12}) = \\frac{2}{3}\n\t\\]\n\t\\[\n\t\\text{Var}(g(X)) = \\mathbf{E}[g(X)^2] - \\mathbf{E}[g(X)]^2 = \\frac{2}{3} - \\frac{9}{16} = \\frac{5}{48} \\approx 0.1042\n\t\\]\n\t\\subsection{Part C}\n\tFind the mean squared error $\\mathbf{E}[(Y-g(X))^2]$. Is it the same as $\\mathbf{E}[\\text{var}(Y|X)]$?\\\\\n\t\\\\\n\tSince $g(X)=\\mathbf{E}[Y|X]$,\n\t\\[\n\t\\mathbf{E}[(Y-g(X))^2] = \\mathbf{E}[(Y-\\mathbf{E}[Y|X])^2]=\n\t\\mathbf{E}[\\mathbf{E}[(Y-\\mathbf{E}[Y|X])^2|X]]\n\t\\]\n\t\\[\n\t= \\mathbf{E}[\\mathbf{E}[(Y|X-\\mathbf{E}[Y|X])^2]]=\n\t\\mathbf{E}[\\text{Var}(Y|X)]\n\t\\]\n\tSince $Y$ is uniform for all $X$, $\\text{Var}(Y|X) = \\frac{1}{12}(Y_1+1-Y_1)^2 = \\frac{1}{12}$, $0\\leq X\\leq2$\\\\\n\t$\\mathbf{E}[\\text{Var}(Y|X)] = \\frac{1}{2}\\int_{0}^{2} \\frac{1}{12}~dx = \\frac{1}{12}$\n\t\\pagebreak\n\t\\section{Problem 3}\n\tEach year, an editor is sent a random number of books for review. The number of books received can be modeled as a Poisson random variable \\textit{N} with mean $\\mu$. Each book contains a random number of typos, modeled by a Poisson random variable with mean $\\lambda$. Let $B_i$ denote the number of typos in book $i$. Assume all random variables are independent. The editor finds typos with probability $p$, independent of all other findings, and other random variables.\n\t\n\tThere are two different payment options:\n\t\n\t\\textbf{Option 1.} \\$1 for each typo found\n\t\n\t\\textbf{Option 2.} \\$1 for each book where at least 1 typo is found\n\t\n\tLet $X_i$ be the amount of money the editor receives for book $i$ and $T$ the total amount of money the editor receives in a year.\n\t\\subsection{Part A}\n\tThe the PMF of $X_i$ under option 1.\\\\\n\t\\\\\n\tThe PMF of $X_i$ under option 1 is the PMF of the number of typos in book $i$. For each typo is book $i$, the editor has a $p$ probability of catching it. Thus, the PMF is a binomial distribution with the number of trials the random variable of $B_i$.\\\\\n\t\\[\n\t\\mathbf{P}(X_i=x|B_i=b) = \\binom{b}{x}p^x(1-p)^{b-x}\n\t\\]\n\tSince $X_i$ and $B_i$ are independent,\n\t\\[\n\t\\mathbf{P}(X_i=x) = \\sum_{b=x}^{\\infty}\\mathbf{P}(X_i=x|B_i=b)\\mathbf{P}(B_i=b)\n\t\\]\n\t\\[\n\t\\mathbf{P}(X_i=x) = \\sum_{b=x}^{\\infty}\\binom{b}{x}p^x(1-p)^{b-x} \\frac{\\lambda e^{-\\lambda}}{b!}\n\t\\]\n\t\\[\n\t\\mathbf{P}(X_i=x) = \n\t\\frac{(p\\lambda)^x}{x!}e^{-\\lambda}\\sum_{b=0}^{\\infty}\n\t\\frac{(\\lambda(1-p))^b}{b!} = \\frac{(p\\lambda)^x}{x!}e^{-p\\lambda}\n\t\\]\n\tThis is a Poisson PMF with mean $p\\lambda$.\n\t\\\\\n\t\\subsection{Part B}\n\tFind $M_T(s)$ under option 1.\\\\\n\t\\\\\n\t$T = X_1 + X_2 + \\dots X_N$. Thus, $M_T(s) = M_N(s)|_{e^s=M_X(s)}$\n\t\\[\n\tM_N(s) = e^{\\mu(e^s-1)} \\qquad M_X(s) = e^{p\\lambda(e^s-1)}\n\t\\]\n\t\\[\n\tM_T(s) = e^{\\mu\\left(e^{p\\lambda(e^s-1)}-1\\right)}\n\t\\]\n\t\\\\\n\t\\subsection{Part C}\n\tFind \\textbf{P}$(T=2)$ under option 2.\\\\\n\t\\\\\n\tSince $T$ is a discrete random variable, we can find probabilities through differentiation of $M_T(s)$ as  such:\n\t\\[\n\t\\mathbf{P}(T=t) = \\frac{1}{t!}\\frac{d^t}{d(e^s)^t}M(s)|_{e^s=0}\n\t\\]\n\t\\[\n\t\\mathbf{P}(T=2) = \\frac{1}{2}\\frac{d^2}{d(e^s)^2}M_T(s)|_{e^s=0}\n\t\\]\n\t\\[\n\t= \\left[\\frac{\\mu p\\lambda}{2}\\exp\\{\\mu e^{p\\lambda(e^s-1)-\\mu+p\\lambda e^s - p\\lambda}\\left(\\mu p\\lambda e^{p\\lambda(e^s-1)}+p\\lambda\\right)\n\t\\right]|_{e^s=0}\n\t\\]\n\t\\[\n\t\\mathbf{P}(T=2) = \\frac{1}{2}\\mu(p\\lambda)^2 e^{-p\\lambda}e^{\\mu(e^{-p\\lambda -1})}\\left(\\mu e^{-p\\lambda}+1\\right)\n\t\\]\n\t\\\\\n\t\\subsection{Part D}\n\tFind $\\mathbf{E}[T]$.\\\\\n\t\\\\\n\t\\[\n\t\\mathbf{E}[T] = \\frac{d}{ds}M_T(s)|_{s=0} = e^{\\mu\\left(e^{p\\lambda(e^s-1)}-1\\right)}\\mu e^{p\\lambda(e^s-1)}p\\lambda e^s|_(s=0)\n\t\\]\n\t\\[\n\t\\mathbf{E}[T] = \\mu p\\lambda\n\t\\]\n\t\\\\\n\t\\subsection{Part E}\n\tFind Var($T$).\\\\\n\t\\\\\n\t\\[\n\t\\text{Var}(T) = \\mathbf{E}[T^2]-\\mathbf{E}[T]^2\n\t\\]\n\t\\[\n\t\\mathbf{E}[T^2] = \\frac{d^2}{ds^2}M_T(s)|_{s=0}\n\t= (\\mu p\\lambda)^2 + \\mu(p\\lambda)^2 + \\mu p\\lambda\n\t\\]\n\t\\[\n\t\\text{Var}(T) = (\\mu p\\lambda)^2 + \\mu(p\\lambda)^2 + \\mu p\\lambda - (\\mu p\\lambda)^2 = \\mu p\\lambda(p\\lambda + 1)\n\t\\]\n\t\\\\\n\t\\subsection{Part F}\n\tFind the PMF of $X_i$ under option 2.\\\\\n\t\\\\\n\tUnder option 2, $X_i = 1$ if at least 1 typo is found in book $i$, and 0 otherwise (Binomial distribution). From Part A, we see that the  number of found typos is book $i$ is a Poisson random variable with mean $p \\lambda$. Thus, the probability that $X_i=0$ is $e^{-p \\lambda}$. The full PMF is:\n\t\\[\n\tX_i = \n\t\\begin{cases}\n\t\te^{-p\\lambda} & x=0\\\\\n\t\t1-e^{-p\\lambda} &x=1\\\\\n\t\t0 & \\text{otherwise}\n\t\\end{cases}\n\t\\]\n\t\\\\\n\t\\subsection{Part G}\n\tFind $\\mathbf{E}[T]$ under option 2.\\\\\n\t\\\\\n\tEach book viewed by the editor, there is a $\\rho$ probability that he or she will get a dollar for the book. There are $N$ number of attempts ate getting dollars. Thus, $T$ has a binomial distribution with the number of trials being a Poisson random variable. Following a similar procedure as Part A:\n\t\\[\n\t\t\\mathbf{P}(T=t) = \\sum_{n=t}^{N}\\binom{n}{t}\\rho^t(1-\\rho)^{n-t}\\frac{\\mu^n}{n!}e^{-\\mu} = \\frac{(\\mu\\rho)^t}{t!}e^{-\\mu\\rho}\n\t\\]\n\tThis is a Poisson distribution with mean $\\mu\\rho$. From Part G, we saw that the probability $\\rho$ of receiving a dollar for book $i$ is $1-e^{-p\\lambda}$. Therefore, we have:\n\t\\[\n\t\\mathbf{E}[T] = \\mu\\rho = \\mu(1-e^{-p\\lambda})\n\t\\] \n\t\\\\\n\t\\subsection{Part H}\n\tWhich option should the editor choose?\\\\\n\t\\\\\n\tWe will answer this by finding the option with the highest expected value for $T$. Under option 1, $\\mathbf{E}[T] = \\mu p\\lambda$. Under option 2, $\\mathbf{E}[T] = \\mu(1-e^{-p\\lambda})$.\n\t\n\tBoth $\\mu$ and $\\lambda$ are out of the editor's control. But $p$ is determined by the editor's skill in spotting typos. As $p$ increases towards 1, the expected yearly payout under option 1 grows linearly towards $\\mu\\lambda$. Whereas under option 2 it is bounded above by $\\mu(1-e^{-\\lambda})$. Note that $1-e^{-\\lambda}$ grows sub-linearly, so $\\mu\\lambda$ will always be greater than $\\mu(1-e^{-\\lambda})$.\n\t\n\tTherefore, option 1 will result in the highest expected value of $T$. \n\\end{document}", "meta": {"hexsha": "aa2e3a48d86425a7f1c3d897370714b19b4176ae", "size": 10988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/Quiz2/quiz2.tex", "max_stars_repo_name": "markditsworth/psa", "max_stars_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Exams/Quiz2/quiz2.tex", "max_issues_repo_name": "markditsworth/psa", "max_issues_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exams/Quiz2/quiz2.tex", "max_forks_repo_name": "markditsworth/psa", "max_forks_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_forks_repo_licenses": ["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.2490842491, "max_line_length": 473, "alphanum_fraction": 0.5948307244, "num_tokens": 4728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.606864015635844}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n%\n%     This file is included from the file   Segmentation.tex\n% \n%     Section tag and label are placed in this top file.\n%\n%\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\\itkpiccaption[Zero Set Concept]{Concept of zero set in a level set.\\label{fig:LevelSetZeroSet}}\n\\parpic(9cm,6cm)[r]{\\includegraphics[width=8cm]{LevelSetZeroSet.eps}}\n\nThe paradigm of the level set is that it is a numerical method for tracking\nthe evolution of contours and surfaces. Instead of manipulating the contour\ndirectly, the contour is embedded as the zero level set of a higher\ndimensional function called the level-set function, $\\psi(\\bf{X},t)$. The\nlevel-set function is then evolved under the control of a differential\nequation.  At any time, the evolving contour can be obtained by extracting\nthe zero level-set $\\Gamma(\\bf(X),t) =\n\\{\\psi(\\bf{X},t) = 0\\}$ from the output.  The main advantages of using level\nsets is that arbitrarily complex shapes can be modeled and topological\nchanges such as merging and splitting are handled implicitly. \n\nLevel sets can be used for image segmentation by using image-based features\nsuch as mean intensity, gradient and edges in the governing differential\nequation.  In a typical approach, a contour is initialized by a user and is\nthen evolved until it fits the form of an object in the image.\nMany different implementations and variants of this basic concept have been\npublished in the literature. An overview of the field has been made by\nSethian \\cite{Sethian1996}.\n\nThe following sections introduce practical examples of some\nof the level set segmentation methods available in ITK.  The remainder of this\nsection describes features common to all of these filters except the\n\\doxygen{itk}{FastMarchingImageFilter}, which is derived from a different code\nframework.  Understanding these features will aid in using the filters\nmore effectively.\n\nEach filter makes use of a generic level-set equation to compute the update to\nthe solution $\\psi$ of the partial differential equation.\n\n\\begin{equation}\n\\label{eqn:LevelSetEquation}\n\\frac{d}{dt}\\psi = -\\alpha \\mathbf{A}(\\mathbf{x})\\cdot\\nabla\\psi - \\beta\n  P(\\mathbf{x})\\mid\\nabla\\psi\\mid + \n\\gamma Z(\\mathbf{x})\\kappa\\mid\\nabla\\psi\\mid\n\\end{equation}\n \nwhere $\\mathbf{A}$ is an advection term, $P$ is a propagation (expansion) term,\nand $Z$ is a spatial modifier term for the mean curvature $\\kappa$.  The scalar\nconstants $\\alpha$, $\\beta$, and $\\gamma$ weight the relative influence of\neach of the terms on the movement of the interface.  A segmentation filter may\nuse all of these terms in its calculations, or it may omit one or more terms.\nIf a term is left out of the equation, then setting the corresponding scalar\nconstant weighting will have no effect.\n\nAll of the level-set based segmentation filters \\emph{must} operate with\nfloating point precision to produce valid results.  The third, optional\ntemplate parameter is the \\emph{numerical type} used for calculations and as\nthe output image pixel type.  The numerical type is \\code{float} by default,\nbut can be changed to \\code{double} for extra precision.  A user-defined,\nsigned floating point type that defines all of the necessary arithmetic\noperators and has sufficient precision is also a valid choice.  You should\nnot use types such as \\code{int} or \\code{unsigned char} for the numerical\nparameter.  If the input image pixel types do not match the numerical type,\nthose inputs will be cast to an image of appropriate type when the filter is\nexecuted.\n\nMost filters require two images as input, an initial model $\\psi(\\bf{X},\nt=0)$, and a \\emph{feature image}, which is either the image you wish to\nsegment or some preprocessed version.  You must specify the isovalue that\nrepresents the surface $\\Gamma$ in your initial model. The single image\noutput of each filter is the function $\\psi$ at the final time step.  It is\nimportant to note that the contour representing the surface $\\Gamma$ is the\nzero level-set of the output image, and not the isovalue you specified for\nthe initial model.  To represent $\\Gamma$ using the original isovalue, simply\nadd that value back to the output.\n\nThe solution $\\Gamma$ is calculated to subpixel precision.  The best discrete\napproximation of the surface is therefore the set of grid positions closest to\nthe zero-crossings in the image, as shown in\nFigure~\\ref{fig:LevelSetSegmentationFigure1}.  The\n\\doxygen{itk}{ZeroCrossingImageFilter} operates by finding exactly those grid \npositions and can be used to extract the surface. \n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.4\\textwidth]{LevelSetSegmentationFigure1.eps}\n\\itkcaption[Grid position of the embedded level-set surface.]{The implicit level\nset surface $\\Gamma$ is the black line superimposed over the image grid.  The location\nof the surface is interpolated by the image pixel values.  The grid pixels\nclosest to the implicit surface are shown in gray. }\n\\protect\\label{fig:LevelSetSegmentationFigure1}\n\\end{figure}\n\nThere are two important considerations when analyzing the processing time for\nany particular level-set segmentation task: the surface area of the evolving\ninterface and the total distance that the surface must travel.  Because the\nlevel-set equations are usually solved only at pixels near the surface (fast\nmarching methods are an exception), the time taken at each iteration depends on\nthe number of points on the surface.  This means that as the surface grows, the\nsolver will slow down proportionally.  Because the surface must evolve slowly\nto prevent numerical instabilities in the solution, the distance the surface\nmust travel in the image dictates the total number of iterations required.\n\nSome level-set techniques are relatively insensitive to initial conditions\nand are therefore suitable for region-growing segmentation. Other techniques,\nsuch as the \\doxygen{itk}{LaplacianSegmentationLevelSetImageFilter}, can easily\nbecome ``stuck'' on image features close to their initialization and should\nbe used only when a reasonable prior segmentation is available as the\ninitialization.  For best efficiency, your initial model of the surface\nshould be the best guess possible for the solution. \n\n\n\\subsection{Fast Marching Segmentation}\n\\label{sec:FastMarchingImageFilter}\n\n\\ifitkFullVersion\n\\input{FastMarchingImageFilter.tex}\n\\fi\n\n\n%% \\subsection{Shape Detection Segmentation}\n%% \\label{sec:ShapeDetectionLevelSetFilter}\n\n%% \\ifitkFullVersion\n%% \\input{ShapeDetectionLevelSetFilter.tex}\n%% \\fi\n\n\n%% \\subsection{Geodesic Active Contours Segmentation}\n%% \\label{sec:GeodesicActiveContourImageFilter}\n\n%% \\ifitkFullVersion\n%% \\input{GeodesicActiveContourImageFilter.tex}\n%% \\fi\n\n\n%% \\subsection{Threshold Level Set Segmentation}\n%% \\label{sec:ThresholdSegmentationLevelSetImageFilter}\n%% \\ifitkFullVersion\n%% \\input{ThresholdSegmentationLevelSetImageFilter.tex}\n%% \\fi\n\n\n%% \\subsection{Canny-Edge Level Set Segmentation}\n%% \\label{sec:CannySegmentationLevelSetImageFilter}\n%% \\ifitkFullVersion\n%% \\input{CannySegmentationLevelSetImageFilter.tex}\n%% \\fi\n\n\n%% \\subsection{Laplacian Level Set Segmentation}\n%% \\label{sec:LaplacianSegmentationLevelSetImageFilter}\n%% \\ifitkFullVersion\n%% \\input{LaplacianSegmentationLevelSetImageFilter.tex}\n%% \\fi\n\n%% \\subsection{Geodesic Active Contours Segmentation With Shape Guidance}\n%% \\label{sec:GeodesicActiveContourShapePriorLevelSetImageFilter}\n%% \\ifitkFullVersion\n%% \\input{GeodesicActiveContourShapePriorLevelSetImageFilter.tex}\n%% \\fi\n\n\n", "meta": {"hexsha": "83d9c418ef92e9b6455d0453ca8db165370d3e7e", "size": 7566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/SoftwareGuide/Latex/LevelSetsSegmentation.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/LevelSetsSegmentation.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/LevelSetsSegmentation.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": "2015-10-08T12:04:06.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-19T08:00:47.000Z", "avg_line_length": 44.2456140351, "max_line_length": 96, "alphanum_fraction": 0.7772931536, "num_tokens": 1804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118222, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6068640109366487}}
{"text": "\\chapter{Kinematics}\\label{CrossSectionApp}\n\nConsider the process \n\\bel{csProcess}\nf_1(\\pa, \\ra), f_2(\\pb, \\rb) \\rightarrow f'_1(\\ppa, \\rpa), f'_2(\\ppb, \\rpb),\n\\ee\nwhere\n$f_{1, 2}$, $f'_{1, 2}$ are some fermions,\n$\\pa$, $\\ra$, $\\pb$, $\\rb$ denote the momenta and\nspin polarization states of the incoming particles\nand the \"prime\" versions are used for the outgoing ones. The particle momenta\nsatisfy the on-shell conditions, \n\\be\n\\pa^2 = \\ma^2, \\quad  \\pb^2 = \\mb^2,\n\\quad\n\\ppa^2 = \\mpa^2, \\quad  \\ppb^2 = \\mpb^2,\n\\ee\n\n\\P\nThe amplitude is given by \nthe $S$-matrix element that has the following general structure, \n\\beml{csSis}\nS(f_1, f_2 \\rightarrow f'_1, f'_2)\n& = &\n-i (2\\pi)^{4}\n\\left(\\frac{\\ma\\mb\\mpa\\mpb}{\\Ea\\Eb\\Epa\\Epb}\\right)^{\\frac{1}{2}}\n\\delta(\\ppa + \\ppb - \\pa - \\pb)\n\n\\nel &&{}\\times \n M(\\pa, \\ra, \\pb, \\rb, \\ppa, \\rpa, \\ppb, \\rpb).\n\\ee\n\nHere $M$ is some smooth Lorentz-invariant function of momenta and spins\n(Feynman amplitude) and $E$ is defined through \n\\be\n    E^2 = \\absp^2 + m^2.\n\\ee\n\nThe Dirac delta-function in \\rf{csSis} reflects the 4-momentum conservation \nin the process \\rf{csProcess},\n\\bel{cs-conservation-law}\n\\pa + \\pb \\; = \\; \\ppa +\\ppb,\n\\ee\n\n\n\\P\nThe center-of-mass unpolarized differential cross section is according\nto~\\cite{SMTextBook} given by\n\\bel{cs-cross1}\n\\left({d\\sigma \\over d\\Omega}\\right)_{\\rm c.m.}\n\\; = \\;{1 \\over 4 \\pi^2 (\\Ea + \\Eb)^2}{\\abspp\\over \\absp}\n\\ma\\mb\\mpa\\mpb \\, X(\\pa, \\pb, \\ppa, \\ppb),\n\\ee\n\nwith\n\\bel{cs1}\nX(\\pa, \\pb, \\ppa, \\ppb) \\; = \\; {1 \\over 4}\\sum_\\ra\\sum_\\rb\\sum_\\rpa\\sum_\\rpb\n   M^\\dagger(\\ra, \\rb, \\rpa, \\rpb) M(\\ra, \\rb, \\rpa, \\rpb),\n\\ee\n\nwhere $E$, $E'$, $\\vecp$ and $\\vecpp$ are \nthe energies and 3-momenta of the \nincoming and outgoing particles in the center-of-mass frame,\n\n\\be\n\\pa|_{\\rm c.m} = (\\Ea, \\vecp), \n\\quad \n\\pb|_{\\rm c.m}  = (\\Eb, -\\vecp),\n\\quad \n\\ppa|_{\\rm c.m} = (\\Epa, \\vecpp),\n\\quad \n\\ppb|_{\\rm c.m} = (\\Epb, -\\vecpp).\n\\ee\n\nTo rewrite the cross section in an explicitly Lorentz-invariant form \nI express it through the total momentum squared $s$ and two other \nkinematic invariants $t$ and $u$,\n\\be\ns = (\\pa + \\pb)^2 =  (\\ppa + \\ppb)^2,\n\\ee\n\\be\nt = (\\ppa - \\pa)^2 =  (\\pb - \\ppb)^2,\n\\ee\n\\be\nu = (\\ppb - \\pa)^2 =  (\\pb - \\ppa)^2.\n\\ee\n\nThese Lorentz scalars are related by the identity\n\\bem\ns + t + u & = & (\\pa + \\pb)^2 + (\\ppa - \\pa)^2 + (\\ppb - \\pa)^2\n\\nel\n& = & \\ma^2 + \\mb^2 + \\mpa^2 + \\ma^2 + \\mpb^2 + \\ma^2 \n\\nel\n&&{}  + 2(\\pa \\cdot \\pb) - 2(\\pa \\cdot \\ppa) - 2(\\pa \\cdot \\ppb)\n\\nel\n& = & 3\\ma^2 + \\mb^2 + \\mpa^2 + \\mpb^2 \n  + 2\\pa \\cdot(\\pb - \\ppa -  \\ppb)\n\\nel\n& = & 3\\ma^2 + \\mb^2 + \\mpa^2 + \\mpb^2 \n  - 2(\\pa \\cdot \\pa)\n\\ee\nor\n\\bel{sum-s-t-u}\ns + t + u = \\ma^2 + \\mb^2 + \\mpa^2 + \\mpb^2 .\n\\ee\n\n\nIn the c.m. frame $s$ may be written as\n\\be\ns = (\\Ea + \\Eb)^2 - (\\vecp - \\vecp)^2 = (\\Ea + \\Eb)^2\n.\n\\ee\n\nTo get an expression for the c.m. momentum $\\absp$ I proceed\nas following,\n\\be\n(\\pa \\cdot \\pb) = (\\pa \\cdot \\pb)|_{\\rm c.m} = \\Ea\\Eb + \\absp^2 \n= \\sqrt{\\ma^2 + \\absp^2}\\sqrt{\\mb^2 + \\absp^2}\n    + \\absp^2\n    .\n\\ee\n\nSquaring, I find\n\\bem\n(\\ma^2 + \\abs{\\vec{p}}^2)(\\mb^2 + \\absp^2) \n & = &\n[(\\pa \\cdot \\pb) - \\absp^2]^2, \n\\nel\n\\absp^2(\\ma^2 + \\mb^2) + \\ma^2\\mb^2 \n& = & \n(\\pa \\cdot \\pb)^2 - 2(\\pa \\cdot \\pb)\\absp^2,\n\\nel\n(\\pa \\cdot \\pb)^2 - \\ma^2\\mb^2 \n&=& \\absp^2[\\ma^2 + \\mb^2 + 2 (\\pa \\cdot \\pb)] \n,\n\\ee\nor\n\\be\n(\\pa \\cdot \\pb)^2 - \\ma^2\\mb^2 \\;=\\; \\absp^2(\\pa + \\pb)^2 \\;=\\; s\\absp^2 \n.\n\\ee\n\nThus\n\\be\n\\absp^2 \n={1 \\over s}[(\\pa \\cdot \\pb)^2 - \\ma^2\\mb^2]\n={1 \\over 4s}\\{[2(\\pa \\cdot \\pb)]^2 - [2\\ma\\mb]^2\\}.\n\\ee\n\nFurthermore,\n\n\\bem\n\\lefteqn{\n[2(\\pa \\cdot \\pb)]^2 - [2\\ma\\mb]^2 \\; = \\; (s - \\ma^2 - \\mb^2)^2 - [2\\ma\\mb]^2\n}\n\\nel\n&=& (s - \\ma^2 - \\mb^2 - 2\\ma\\mb)(s - \\ma^2 - \\mb^2 + 2\\ma\\mb)\n\\nel\n&=& [s - (\\ma + \\mb)^2][s - (\\ma - \\mb)^2]\n.\n\\ee\n\nSo\n\\bel{cs-abs-p-squared}\n\\absp^2   =\n{1 \\over 4s} [s - (\\ma + \\mb)^2][s - (\\ma - \\mb)^2]\n.\n\\ee\n\nIn the same way I find \n\\bel{cs-abs-pp-squared}\n\\abspp^2  = \n{1 \\over 4s} [s - (\\mpa + \\mpb)^2][s - (\\mpa - \\mpb)^2],\n\\ee\nand thus\n\\bel{cs-pp-over-p}\n{\\abspp\\over \\absp} \n= \\sqrt{[s - (\\mpa + \\mpb)^2][s - (\\mpa - \\mpb)^2] \\over \n        [s - (\\ma + \\mb)^2][s - (\\ma - \\mb)^2]}\n.\n\\ee\n\n\\P\n\nTo be Lorentz-invariant, the quantity $X$ can depend on the particle momenta \nonly through scalar products of different $p$. With\n\\beml{cs-t-explicit}\nt    & = & (\\ppa - \\pa)^2 = \\mpa^2 + \\ma^2 - 2(\\ppa \\cdot \\pa)\n\\nel & = & (\\pb - \\ppb)^2 = \\mb^2 + \\mpb^2 - 2(\\pb \\cdot \\ppb)\n,\n\\ee\n\n\\beml{cs-u-explicit}\nu    & = & (\\ppb - \\pa)^2 = \\mpb^2 + \\ma^2 - 2(\\ppb \\cdot \\pa)\n\\nel & = & (\\pb - \\ppa)^2 = \\mb^2 + \\mpa^2 - 2(\\pb \\cdot \\ppa)\n,\n\\ee\n\nall such products are given by\n\\begin{eqnarray}\\label{cs-scalar-products-1}\n(\\pa \\cdot \\pb) & = &{1 \\over 2} (s - \\ma^2 - \\mb^2),\n\\\\\n(\\ppa \\cdot \\ppb) & = & {1 \\over 2} (s - \\mpa^2 - \\mpb^2),\n\\\\\n(\\ppa \\cdot \\pa) & = & {1 \\over 2} (\\mpa^2 + \\ma^2 - t),\n\\\\\n(\\ppb \\cdot \\pa) & =& {1 \\over 2} (\\mpb^2 + \\ma^2 - u)\n\\nel &=& \n{1 \\over 2} [\\mpb^2 + \\ma^2 - (\\mpa^2 + \\ma^2 + \\mpb^2 + \\mb^2 - s - t)]\n\\nel &=& \n{1 \\over 2} (s + t - \\mpa^2 - \\mb^2),\n\\\\\n(\\ppa \\cdot \\pb) &=& {1 \\over 2} (\\mpa^2 + \\mb^2 - u)\n= {1 \\over 2} (s + t - \\mpb^2 - \\ma^2) ,\n\\\\\n(\\ppb \\cdot \\pb) \n&=& {1 \\over 2} (\\mpb^2 + \\mb^2 - t)\n= {1 \\over 2} (s + u - \\mpa^2 - \\ma^2)\n.\n\\label{cs-scalar-products-2}\n\\end{eqnarray}\n\nThus $X(\\pa,\\pb,\\ppa,\\ppb)$ may be viewed as a function of $s$ and $t$,\n\\bel{cs-X-of-s-t}\nX = X(s, t).\n\\ee\n\n\\P\nThe variable $t$ can be expressed via the center-of-mass frame \nscattering angle $\\theta$ defined by \n$\\vecpa\\cdot\\vecppa = \\vecp\\cdot\\vecpp = \\absp\\abspp\\cos\\theta$,\n\n\\be\n(\\ppa \\cdot \\pa) = (\\ppa \\cdot \\pa)|_{\\rm c.m} = \\Epa\\Ea -  \\vecpa\\cdot\\vecppa\n= \\Epa\\Ea -  \\absp\\abspp\\cos\\theta\n.\n\\ee\nThus\n\\be\n{1 \\over 2} (\\ma^2 + \\mpa^2 - t) \n  = \\Epa\\Ea -  \\absp\\abspp\\cos\\theta,\n\\ee\nand\n\\bel{cs-t-of-theta}\nt =   2\\absp\\abspp\\cos\\theta - t_0,\n\\ee\nwhere I defined\n\\bel{cs-tmp-t0-is}\nt_0 = 2\\Epa\\Ea  - (\\ma^2 + \\mpa^2)\n.\n\\ee\n\nTo calculate $2\\Epa\\Ea$ in~\\rf{cs-tmp-t0-is} I use~\\rf{cs-abs-p-squared} \nand~\\rf{cs-abs-pp-squared}  to express\n$\\Ea$ and $\\Epa$,\n\\bem\n\\Ea^2 & = & \\absp^2 + \\ma^2 = \n{1 \\over 4s} [s - (\\ma + \\mb)^2][s - (\\ma - \\mb)^2]  + \\ma^2,\n\\nel\n4s\\Ea^2 &=& s^2 + s [4\\ma^2 - (\\ma + \\mb)^2 - (\\ma - \\mb)^2]\n+ (\\ma^2 - \\mb^2)^2 \n\\nel\n& = & s^2 + 2 s (\\ma^2 -\\mb^2) + (\\ma^2 - \\mb^2)^2 \n= (s + \\ma^2 -\\mb^2)^2\n.\n\\ee\nSo\n\\be\n\\Ea^2 = {1 \\over 4s}(s + \\ma^2 -\\mb^2)^2, \n\\ee\nand similarly \n\\be\n\\Epa^2 = {1 \\over 4s}(s + \\mpa^2 -\\mpb^2)^2.\n\\ee\n\nTaking the square roots I find\n\\be\n2\\Epa\\Ea = {1 \\over 2s}(s + \\mpa^2 -\\mpb^2)(s + \\ma^2 -\\mb^2).\n\\ee\n\nIt gives \n\\beml{cs-t0-is}\nt_0 & = &  {1 \\over 2s}(s + \\mpa^2 -\\mpb^2)(s + \\ma^2 -\\mb^2) - \\ma^2 - \\mpa^2\n\\nel\n&=& {1 \\over 2s}\n\\{s^2 + s[-2(\\ma^2 + \\mpa^2) + (\\ma^2 - \\mb^2) + (\\mpa^2 -\\mpb^2)]\n\\nel && \\qquad{}\n   + (\\mpa^2 -\\mpb^2)(\\ma^2 -\\mb^2)\\}\n\\nel &=&\n{1 \\over 2s}[s^2 - s(\\ma^2 + \\mpa^2 + \\mb^2 + \\mpb^2) \n   + (\\mpa^2 -\\mpb^2)(\\ma^2 -\\mb^2)].\n\\nel\n\\ee\n\nNow I may write for the c.m. differential cross-section~\\rf{cs-cross1}\n\\bel{cs-cross2}\n\\left({d\\sigma \\over d\\Omega}\\right)_{\\rm c.m.}\n\\; = \\; {d\\sigma(s, t(\\theta)) \\over d\\Omega}\n\\; = \\;{1 \\over 4 \\pi^2 s}{\\abspp\\over \\absp}\n\\ma\\mb\\mpa\\mpb \\, X(s, t).\n\\ee\n\nThen for the total cross-section for the process \\rf{csProcess}, defined by\n\\be\n\\sigma_T(s) = \n\\int {d\\sigma \\over d\\Omega} d\\Omega\n= \\int {d\\sigma \\over d\\Omega} \\sin\\theta d\\theta d\\phi\n,\n\\ee\n\nI have \n\\bel{cs-cross3}\n\\sigma_T(s) = \n\\int {d\\sigma(s, t(\\theta)) \\over d\\Omega} \\sin\\theta d\\theta d\\phi\n = 2\\pi \\int_{-1}^1 {d\\sigma(s, t(\\theta)) \\over d\\Omega} d(\\cos\\theta) .\n\\ee\n\nFrom~\\rf{cs-t-of-theta} I find\n\\be\nd(\\cos\\theta) = {dt \\over 2\\absp\\abspp}\n.\n\\ee\n\nThus\n\\bem\n\\sigma_T(s)  \n& = & {\\pi \\over \\absp\\abspp} \\int_{t_-}^{t_+} \n\\left({d\\sigma \\over d\\Omega}\\right)_{\\rm c.m.} dt\n\\nel\n& = &\n{\\ma\\mb\\mpa\\mpb \\over 4 \\pi^2 s}{\\abspp\\over \\absp}\n{\\pi \\over \\absp\\abspp} \\int_{t_-}^{t_+} X(s, t) dt ,\n\\nel\n& = &{\\ma\\mb\\mpa\\mpb \\over 4 \\pi s \\absp^2}\n \\int_{t_-}^{t_+} X(s, t) \\, dt\n ,\n\\ee\nwhere $t_{\\pm}$ are given by\n\\be\nt_{\\pm} = t\\left|_{\\cos\\theta = \\pm 1}\\right. = \\pm 2\\absp\\abspp - t_0\n.\n\\ee\n\n\\P\nIn the case when \n\\bel{cs-ultra-approximation}\n\\mpa = \\mpb = m' \\gg \\ma = \\mb = m, \\quad s \\ge 4m'^2 \\gg m^2\n\\ee\n\nthe kinematic relations of this appendix can be simplified. \nTo write the formulas\nin a compact form I introduce the dimension-less quantity $\\rho$, \n\\bel{csRhoIs}\n\\rho = {m'^2 \\over s},\n\\quad \\rho \\le {1 \\over 4}.\n\\ee\n\nWith this notation I have according \nto~\\rf{cs-abs-p-squared}--\\rf{cs-pp-over-p} \n\\be\n\\absp^2 = \n{s \\over 4} - m^2 \\approx {s \\over 4}, \n\\qquad\n\\abspp^2 = {s \\over 4}(1 - 4\\rho),\n\\ee\n\\be\n{\\abspp \\over \\absp} \n\\approx \\sqrt{1 - 4\\rho}, \n\\qquad\n\\abspp \\absp = {\\abspp \\over \\absp} \\absp^2 = \n{s \\over 4}\\sqrt{1 - 4\\rho}\n.\n\\ee\n\nSo under this approximation $t_\\pm$ becomes\n\\bel{cs-tmp-t-pm-approximation}\nt_{\\pm} \\approx \\pm {s \\over 2}\\sqrt{1 - 4\\rho} - t_0\n\\approx \\pm{s \\over 2}\\sqrt{1 - 4\\rho} - {1 \\over 2}(s - 2m'^2) \n= {s \\over 2} (2\\rho - 1 \\pm \\sqrt{1 - 4\\rho}).\n\\ee\n\nThe scalar products in~\\rf{cs-scalar-products-1}--\\rf{cs-scalar-products-2}\nnow read\n\\be\n(\\pa \\cdot \\pb) \\approx {s \\over 2},\n\\qquad \n(\\ppa \\cdot \\ppb) = {s \\over 2}(1 - 2\\rho),\n\\ee\n\n\\beml{csKinApproximation}\n(\\ppa \\cdot \\pa) = (\\ppb \\cdot \\pb) & \\approx & {m'^2 - t \\over 2},\n\\nel\n(\\ppb \\cdot \\pa) = (\\ppa \\cdot \\pb) & \\approx & {m'^2 - u \\over 2} \n\\approx {s + t - m'^2 \\over 2},\n\\ee\n\nand the cross sections~\\rf{cs-cross2}and~\\rf{cs-cross3} are given by\n\n\\bel{cs-tmp-dif-approximation}\n\\left({d\\sigma \\over d\\Omega}\\right)_{\\mbox{c.m.}}\n\\approx \n{m^2 m'^2  \\over 4\\pi^2 s} \\sqrt{1 - 4\\rho}\\, X(s, t)\n,\n\\ee\n\n\\bel{cs-tmp-total-approximation}\n\\sigma_T(s)  \n\\approx {m^2 m'^2 \\over \\pi s^2} \\int_{t_-}^{t_+} X(s, t) \\, dt \n.\n\\ee\n\n\\P\nI next present several useful results and find typical integrals \nthat occur during calculations \nof the total cross section under the approximation~\\rf{cs-ultra-approximation}:\n\n\\bem\n\\lefteqn{\n(\\qpb \\cdot \\qa) (\\qpa \\cdot \\qb) + (\\qpb \\cdot \\qb) (\\qpa \\cdot \\qa)\n}\n\\nel\n& \\equiv &\n{1 \\over \\ma\\mb\\mpa\\mpb}\n[(\\ppb \\cdot \\pa) (\\ppa \\cdot \\pb) + (\\ppb \\cdot \\pb) (\\ppa \\cdot \\pa)]\n\\nel\n& = & {1 \\over m^2m'^2}\n[(\\ppb \\cdot \\pa)^2 + (\\ppa \\cdot \\pa)^2]\n\\approx {1 \\over 4m^2m'^2}[(s + t - m'^2)^2 + (m'^2 - t)^2]\n\\nel & = &\n{1 \\over 4m^2m'^2}[(m'^2 - t)^2 -2s(m'^2 - t) + s^2 + (m'^2 - t)^2],\n\\ee\nor\n\\bel{cs-4q-sum}\n(\\qpb \\cdot \\qa) (\\qpa \\cdot \\qb) + (\\qpb \\cdot \\qb) (\\qpa \\cdot \\qa)\n\\approx {2(m'^2 - t)^2 + s(s + 2t - 2m'^2) \\over 4m^2m'^2}\n.\n\\ee\n\nThrough similar steps I have\n\\beml{cs-4q-sub}\n\\lefteqn{\n(\\qpb \\cdot \\qa) (\\qpa \\cdot \\qb) - (\\qpb \\cdot \\qb) (\\qpa \\cdot \\qa)\n}\n\\nel\n& \\equiv &\n{1 \\over \\ma\\mb\\mpa\\mpb}\n[(\\ppb \\cdot \\pa) (\\ppa \\cdot \\pb) - (\\ppb \\cdot \\pb) (\\ppa \\cdot \\pa)]\n\\nel\n& \\approx & {1 \\over 4m^2m'^2}[(s + t - m'^2)^2 - (m'^2 - t)^2],\n\\nel\n& \\approx & {s \\over 4m^2m'^2}(s + 2t - 2m'^2)\n.\n\\ee\n\nThe direct consequences of~\\rf{cs-tmp-t-pm-approximation} are\n\\beml{cs-t-pm-pm}\nt_+ - t_- & \\approx & s\\sqrt{1 - 4\\rho}, \n\\nel\nt_+ + t_- & \\approx & s(2\\rho - 1),\n\\nel\nt_+ t_- & \\approx &\n{s^2 \\over 4} (2\\rho - 1 + \\sqrt{1 - 4\\rho})(2\\rho - 1 - \\sqrt{1 - 4\\rho})\n\\nel \n&=& {s^2 \\over 4} [(2\\rho - 1)^2 - (1 - 4\\rho)]\n= s^2\\rho^2\n.\n\\ee\n\nThus from the definition of $\\rho$~\\rf{csRhoIs}\n\\bel{cs-t-pm-mul}\nt_+ t_- \\approx  m'^4\n.\n\\ee\n\n\\P\nIn the following integrals I assume that \n$x$ and $z$ are complex numbers and $r$ is real.\n\n\\beml{cs-int-1}\n\\int_{t_-}^{t_+} (2m'^2 - 2t - s) dt\n& = & (t_+ - t_-)(2m'^2 - s) - (t_+^2 - t_-^2)\n\\nel \n& = &\n(t_+ - t_-)(2m'^2 - s -t_+ - t_-)\n\\nel\n& = & (t_+ - t_-)[s(2\\rho - 1) -t_+ - t_-]\n\\nel\n& \\approx & 0,\n\\ee\nwhere~\\rf{cs-t-pm-pm} was used. Next\n\n\\bem\n\\int_{t_-}^{t_+} (m'^2 - t)^2 dt \n&=&\\int_{t_-}^{t_+} (m'^4 - 2 m'^2t + t^2) dt \n\\nel \n& = & \nm'^4(t_+ - t_-) - m'^2(t_+^2 - t_-^2) + {1 \\over 3}(t_+^3 - t_-^3)\n\\nel \n& = & \n(t_+ - t_-)\\{m'^4 - m'^2(t_+ + t_-) + {1 \\over 3}[(t_+ + t_-)^2 - t_+t_-]\\}.\n\\ee\n\nAt this point, according to~\\rf{cs-t-pm-pm}--\\rf{cs-t-pm-mul} I can\nwrite the approximation\n\\beml{cs-int-2}\n\\int_{t_-}^{t_+} (m'^2 - t)^2 dt\n& \\approx & \ns\\sqrt{1 - 4\\rho}\\{m'^4 - m'^2(2m'^2 - s) \n   + {1 \\over 3}[(2m'^2 - s)^2 - m'^4]\\}\n\\nel \n& = & \ns\\sqrt{1 - 4\\rho}\\,[m'^4(1 - 2 + 1) + m'^2s(1 -4/3) + s^2/3]\n\\nel \n& = & \ns\\sqrt{1 - 4\\rho}[s^2/3 - m'^2s/3]\n\\nel \n& = & {s^3 \\over 3} (1 - \\rho)\\sqrt{1 - 4\\rho}\\,\n.\n\\ee\n\nI shall also need the integral \n\\be\n\\int_{t_-}^{t_+} \\Re\\left({z \\over t - x}\\right) dt\n\\ee\nfor value of $x$ such that no pole is encountered,\n\n\\bel{csIntTmp3}\n\\int_{t_-}^{t_+} \\Re\\left({z \\over t - x}\\right) dt \n\\;=\\; \\int_{t_- - x}^{t_+ - x} \\Re\\left({z \\over t}\\right) dt \n\\;=\\;  \\Re\\left(z\\ln{t_+ - x \\over t_- - x}\\right)\n.\n\\ee\n\nTo simplify the last expression I use,\n\\begin{eqnarray}\n\\Re(z_1 z_2) &=& \\Re(z_1)\\Re(z_2) - \\Im(z_1)\\Im(z_2), \n\\\\\n\\label{cs-Im-z1-z2}\n\\Im(z_1 z_2) &=& \\Re(z_1)\\Im(z_2) + \\Im(z_1)\\Re(z_2), \n\\\\\n\\Re(\\ln z_3) &=& \\ln\\abs{z_3}, \n\\\\\n\\Im(\\ln z_3) &=& \\arctg{\\Im(z_3) \\over \\Re(z_3)} \n%+ \\left\\{\\matrix{0, & \\Re(z) \\ge 0 \\cr \\pi, & \\Re(z) < 0}\\right.\n,\n\\end{eqnarray}\nthat are valid for any complex $z_1$,$z_2$ and $z_3 \\ne 0$. Thus\n\n\\bem\n\\Re\\left[z \\ln {t_+ - x \\over t_- - x}\\right] \n&=&\n\\Re(z)\\Re\\left[ \\ln {t_+ - x \\over t_- - x}\\right] \n- \\Im(z)\\Im\\left[ \\ln {t_+ - x \\over t_- - x}\\right] \n\\nel\n&=&\n\\Re(z)\\ln\\abs{t_+ - x \\over t_- - x}\n- \\Im(z)\\Im\\left[ \\ln {t_+ - x \\over t_- - x}\\right],\n\\ee\n\nwhere\n\\bem\n\\lefteqn{\n\\Im\\left[ \\ln {t_+ - x \\over t_- - x}\\right]\n= \\Im\\left[ \\ln {(t_+ - x)(t_- - x^*) \\over \\abs{t_- - x}^2}\\right]\n= \\Im\\left[ \\ln (t_+t_- + \\abs{x}^2 - x t_- - x^*t_+)\\right]\n}\n&& \\fillEqn\n\\nel\n&=& \\arctg{\\Im(m'^4 + \\abs{x}^2 - x t_- - x^*t_+) \n         \\over \\Re(m'^4 + \\abs{x}^2 - x t_- - x^*t_+)}\n= \\arctg{\\Im(x)(t_+ - t_-) \n         \\over m'^4 + \\abs{x}^2 - \\Re(x)(t_- + t_+)}\n,         \n\\ee\n\nor\n\\bel{cs-tmp-im-log}\n\\phi(x) \\equiv \\Im\\left[ \\ln {t_+ - x \\over t_- - x}\\right]\n= \n\\arctg{s\\sqrt{1 - 4\\rho}\\,\\Im(x)\n         \\over m'^4 + \\abs{x}^2 - s(2\\rho - 1)\\Re(x)}\n.\n\\ee\n\nIt gives for~\\rf{csIntTmp3}, \n\\bel{cs-int-3}\n\\int_{t_-}^{t_+} \\Re\\left({z \\over t - x}\\right) dt \n\\; \\approx \\;\n\\Re(z)\\ln\\abs{t_+ - x \\over t_- - x}\n- \\Im(z) \\phi(x).\n\\ee\n\nNext I consider the integral (where again no pole is encountered)\n\n\\bem\n\\lefteqn{\n\\int_{t_-}^{t_+} {(t - r)^2 \\over t - x} dt \n\\; = \\; \n\\int_{t_- - x}^{t_+ - x} {(t + x - r)^2 \\over t} dt \n= \n\\int_{t_- - x}^{t_+ - x} \n\\left[{(x - r)^2 \\over t} + 2(x - r) + t \\right] dt \n}\n&& \\fillEqn\n\\nel\n& = &\n(x - r)^2 \\ln{t_+ - x \\over t_- - x}\n+ 2(x - r)(t_+ - t_-) + {1 \\over 2}[(t_+ - x)^2 - (t_- - x)^2]\n.\n\\ee\n\nBut\n\\be\n(t_+ - x)^2 - (t_- - x)^2 = (t_+ - x + t_- - x)(t_+ - t_-)\n= [s(2\\rho - 1) - 2x](t_+ - t_-),\n\\ee\n\nso\n\\beml{cs-tmp-int1}\n\\int_{t_-}^{t_+} {(t - r)^2 \\over t - x} dt \n& = &\n(x - r)^2 \\ln{t_+ - x \\over t_- - x}\n+ (t_+ - t_-)[2(x - r) + {s \\over 2}(2\\rho - 1) - x]\n\\nel\n& = &\n(x - r)^2 \\ln{t_+ - x \\over t_- - x}\n+ s\\sqrt{1 - 4\\rho}(x - 2r + s\\rho - s/2)\n.\n\\ee\n\nI use~\\rf{cs-tmp-int1} to calculate the following two integrals.\nFirst I consider\n\n\\bem\n\\lefteqn{\n\\int_{t_-}^{t_+} \\Re\\left(z{(t - r)^2 \\over t - x}\\right) dt \n}\n\\nel\n& \\approx &\n\\Re\\left[z(x - r)^2 \\ln{t_+ - x \\over t_- - x}\\right]\n+ s\\sqrt{1 - 4\\rho}\\Re[z(x  - 2r + s\\rho - s / 2)]\n\\nel\n& = &\n\\Re\\left[z(x - r)^2 \\ln{t_+ - x \\over t_- - x}\\right]\n+ s\\sqrt{1 - 4\\rho}\\Re[zx  - z(2r - s\\rho + s / 2)]\n\\nel\n& = &\n\\Re[z(x - r)^2] \\Re\\left[\\ln{t_+ - x \\over t_- - x}\\right]\n-\\Im[z(x - r)^2] \\Im\\left[\\ln{t_+ - x \\over t_- - x}\\right]\n\\nel\n&& {}\n+ s\\sqrt{1 - 4\\rho}\\{\\Re(zx) - \\Re(z)[2r + s(1 - 2\\rho)/2]\\}\n,\n\\ee\n\nor\n\\beml{cs-int-4}\n\\int_{t_-}^{t_+} \\Re\\left(z{(t - r)^2 \\over t - x}\\right) dt \n& \\approx &\n\\Re[z(x - r)^2] \\ln\\abs{t_+ - x \\over t_- - x}\n-\\Im[z(x - r)^2] \\phi(x)\n\\nel\n&&{}\n+ s\\sqrt{1 - 4\\rho}\\{\\Re(zx) - \\Re(z)[2r + s(1 - 2\\rho)/2]\\}\n.\n\\nel\n\\ee\n\n\\P\nIn the following calculations I use \n\\be\n{1 \\over \\abs{t - x}^2} \n= {1 \\over x - x^*} \\left({1 \\over t - x} - {1 \\over t - x^*} \\right)\n= {1 \\over 2i\\Im(x)} \\left({1 \\over t - x} - {1 \\over t - x^*} \\right)\n,\n\\ee\nwhere it is supposed that $\\Im(x) \\ne 0$. \nThus ($r$ is real)\n\n\\bem\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt \n& \\equiv &\n\\Re\\left\\{\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt \n\\right\\}\n\\nel\n& = &\n\\Re\\left\\{\n{1 \\over 2i\\Im(x)}\n\\int_{t_-}^{t_+} \\left[{(t - r)^2 \\over t - x}\n                       - {(t - r)^2 \\over t - x^*}\\right] dt \n\\right\\}\n\\nel\n& = &\n{1 \\over 2\\Im(x)}\n\\Im\\left\\{\n\\int_{t_-}^{t_+} \\left[{(t - r)^2 \\over t - x}\n                       - {(t - r)^2 \\over t - x^*}\\right] dt \n\\right\\}\n,\n\\ee\n\nwhere I have used the fact that $r$ is real. So\n\n\\beml{cs-int-6}\n\\lefteqn{\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt \n}\n\\nel\n& = &\n{1 \\over 2\\Im(x)}\n\\Im\\left[(x - r)^2 \\ln {t_+ - x \\over t_- - x}\n+ s\\sqrt{1 - 4\\rho}(x - 2r + m'^2 - s / 2)\n\\right]\n\\nel&& {}\n-{1 \\over 2\\Im(x)}\n\\Im\\left[\n(x^* - r)^2 \\ln {t_+ - x^* \\over t_- - x^*}\n+ s\\sqrt{1 - 4\\rho}(x^* - 2r + m'^2 - s / 2)\n\\right]\n\\nel\n& = &\n{1 \\over 2\\Im(x)}\n\\Im\\left[\n(x - r)^2 \\ln {t_+ - x \\over t_- - x} \n- (x^* - r)^2 \\ln {t_+ - x^* \\over t_- - x^*}\n+ s\\sqrt{1 - 4\\rho}(x - x^*)\n\\right]\n\\nel\n\\ee\n\nI simplify the last expression with the help of the identity\n\\be\n\\Im(z - z^*) = \\Im[2i\\Im(z)] = 2\\Im(z).\n\\ee\n\nAccording to~\\rf{cs-Im-z1-z2} I find for the integral~\\rf{cs-int-6}\n\\bem\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt \n& = &\n{1 \\over \\Im(x)}\n\\Im\\left[(x - r)^2 \\ln {t_+ - x \\over t_- - x} + sx\\sqrt{1 - 4\\rho} \\right]\n\\nel\n& = &\n{1 \\over \\Im(x)}\n\\Re[(x - r)^2] \\Im\\left[\\ln{t_+ - x \\over t_- - x}\\right] \n\\nel&&{}\n+{1 \\over \\Im(x)}\n\\Im[(x - r)^2] \\Re\\left[\\ln {t_+ - x \\over t_- - x}\\right] \n+ s\\sqrt{1 - 4\\rho}\n\\,\n.\n\\ee\n\nBy taking into account that\n\\be\n\\Re[(x - r)^2] = [\\Re(x - r)]^2 - [\\Im(x - r)]^2 = [\\Re(x) - r]^2 - \\Im(x)^2,\n\\ee\n\\bel{csReImForSub}\n\\Im[(x - r)^2] = 2\\Im(x - r)\\Re(x - r) = 2\\Im(x)[\\Re(x) - r]\n,\n\\ee\n\nI finally find\n\\beml{cs-int-65}\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt\n&\\approx&\n{[\\Re(x) - r]^2 - \\Im(x)^2 \\over \\Im(x)} \\phi(x)\n+ 2[\\Re(x) - r]\\ln\\abs{t_+ - x \\over t_- - x}\n\\nel\n&&{}\n+ s\\sqrt{1 - 4\\rho}\\, .\n\\ee\n\nWhen $\\Im(x) = 0$, i.e when $x$ is real, I may use,\n\\be\n\\lim_{\\varepsilon \\rightarrow 0} \n\\left({1 \\over \\varepsilon} \\arctg a\\varepsilon\\right)\n= a\n\\ee\nto calculate the first term in~\\rf{cs-int-65},\n\\bem\n{ \\phi(x)\\over \\Im(x)} &=& \n{ 1 \\over \\Im(x)} \n\\arctg{s\\sqrt{1 - 4\\rho}\\Im(x) \\over m'^4 + \\abs{x}^2 - s(2\\rho - 1)\\Re(x)}\n\\nel&\\rightarrow &\n{s\\sqrt{1 - 4\\rho}\\over m'^4 + \\abs{x}^2 - s(2\\rho - 1)\\Re(x)}\n.\n\\ee\n\nThus for real $x$ equation~\\rf{cs-int-65} becomes\n\\beml{cs-int-7}\n\\int_{t_-}^{t_+} {(t - r)^2 \\over (t - x)^2} dt\n&\\approx&\n{s\\sqrt{1 - 4\\rho}[x - r]^2 \\over m_\\chi^4 + x^2 - sx(2\\rho - 1)}\n+ 2(x - r)\\ln\\abs{t_+ - x \\over t_- - x}\n+ s\\sqrt{1 - 4\\rho}\\,\n.\n\\nel\n\\ee\n\n\\P\nFor reference purposes I collect here several key formulas.\nFor the process~\\rf{csProcess} when the particle masses satisfy\n\\bel{csUltraApproximation}\n\\mpa = \\mpb = m' \\gg \\ma = \\mb = m, \\quad s \\ge 4m'^2 \\gg m^2,\n\\ee\n\nthe c.m. differential  and total cross sections are given by\n\\bel{csDifApproximation}\n\\left({d\\sigma \\over d\\Omega}\\right)_{\\rm c.m.}\n\\approx \n{m^2 m'^2  \\over 4\\pi^2 s} \\sqrt{1 - 4\\rho}\\, X(s, t)\n,\n\\ee\n\n\\bel{csTotalApproximation}\n\\sigma_T(s)  \n\\approx {m^2 m'^2 \\over \\pi s^2} \\int_{t_-}^{t_+} X(s, t) \\, dt \n,\n\\ee\n\nwhere\n\n\n\\begin{eqnarray}\n\\label{cs-s}\ns & = & (\\pa + \\pb)^2 = (\\ppa + \\ppb)^2 ,\n\\\\\n\\label{cs-t-is}\nt &=& (\\ppa - \\pa)^2 = (\\pb - \\ppb)^2 ,\n\\\\\n\\label{cs-t-pm-approximation}\nt_\\pm & \\approx & {s \\over 2} (2\\rho - 1 \\pm \\sqrt{1 - 4\\rho})\n,\n\\\\\n\\label{cs-rho}\n\\rho &=& {m'^2 \\over s} \\; \\le \\; {1 \\over 4},\n\\end{eqnarray}\n\nand $X$ is the spin sum over initial and final particle spin states,\n\\bel{cs-X-is}\nX(s, t) \\equiv \nX(\\pa, \\pb, \\ppa, \\ppb) \n=  {1 \\over 4}\\sum_{\\ra, \\rb, \\rpa, \\rpb = +, -}\n   M^\\dagger(\\ra, \\rb, \\rpa, \\rpb) M(\\ra, \\rb, \\rpa, \\rpb)\n.   \n\\ee\n\n\\P\nUnder the approximation~\\rf{csUltraApproximation} the following relations hold,\n\\beml{cs-q-scalar-products}\n(\\qpb \\cdot \\qa) (\\qpa \\cdot \\qb) + (\\qpb \\cdot \\qb) (\\qpa \\cdot \\qa)\n& \\approx &\n{2(m'^2 - t)^2 + s(s + 2t - 2m'^2) \\over 4m^2m'^2}\n,\n\\nel\n(\\qpb \\cdot \\qa) (\\qpa \\cdot \\qb) - (\\qpb \\cdot \\qb) (\\qpa \\cdot \\qa)\n& \\approx & {s \\over 4m^2m'^2}(s + 2t - 2m'^2)\n,\n\\ee\n\n\\beml{cs-t-expressions}\nt_+ - t_- & \\approx & s\\sqrt{1 - 4\\rho}, \n\\nel\nt_+ + t_- & \\approx & s(2\\rho - 1),\n\\nel\nt_+ t_- & \\approx & m'^4\n.\n\\ee\n\n\\P\nOne may also find the integrals,\n\n\\bel{csInt1}\n\\int_{t_-}^{t_+} (2m'^2 - 2t - s) dt \n\\; \\approx \\; \n0\n,\n\\ee\n\n\\bel{csInt2}\n\\int_{t_-}^{t_+} (m'^2 - t)^2 dt \n\\; \\approx \\;\n{s^3 \\over 3} (1 - \\rho)\\sqrt{1 - 4\\rho} \\,\n,\n\\ee\n\n\\bel{csInt3}\n\\int_{t_-}^{t_+} \\Re\\left({z \\over t - x}\\right) dt\n\\; \\approx \\;\n\\Re(z)\\ln\\abs{t_+ - x \\over t_- - x}\n- \\Im(z) \\phi(x),\n\\ee\n\nwhere $z$ is an arbitrary complex number, \n$x$ is a complex number such that no pole is encountered in~\\rf{csInt3}\nand\n\\bel{csImLog}\n\\phi(x) \\; = \\;\n\\arctg{s\\sqrt{1 - 4\\rho}\\,\\Im(x)\n         \\over m'^4 + \\abs{x}^2 - s(2\\rho - 1)\\Re(x)}\n.\n\\ee\n\nFurthermore\n\\beml{csInt4}\n\\int_{t_-}^{t_+} \\Re\\left(z{(t - r)^2 \\over t - x}\\right) dt \n& \\approx &\n\\Re[z(x - r)^2] \\ln\\abs{t_+ - x \\over t_- - x}\n-\\Im[z(x - r)^2] \\phi(x)\n\\nel\n&&{}\n+ s\\sqrt{1 - 4\\rho}\\{\\Re(zx) - \\Re(z)[2r + s(1 - 2\\rho)/2]\\}\n,\n\\nel\n\\ee\n\n\\beml{csInt65}\n\\int_{t_-}^{t_+} {(t - r)^2 \\over \\abs{t - x}^2} dt\n&\\approx&\n{[\\Re(x) - r]^2 - \\Im(x)^2 \\over \\Im(x)} \\phi(x)\n+ 2[\\Re(x) - r]\\ln\\abs{t_+ - x \\over t_- - x}\n\\nel\n&&{}\n+ s\\sqrt{1 - 4\\rho}\\, \n.\n\\ee\n\nFor a real $x$ the integral~\\rf{csInt65} reads\n\\beml{csInt7}\n\\int_{t_-}^{t_+} {(t - r)^2 \\over (t - x)^2} dt\n&\\approx&\n{s\\sqrt{1 - 4\\rho}[x - r]^2 \\over m_\\chi^4 + x^2 - sx(2\\rho - 1)}\n+ 2(x - r)\\ln\\abs{t_+ - x \\over t_- - x}\n+ s\\sqrt{1 - 4\\rho}\\,\n.\n\\nel\n\\ee\n\n", "meta": {"hexsha": "6f24915b78502825071b8d5d5a5ac7c94ddf417e", "size": 21587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writes/bergen_master_thesis/body/Kinematics.tex", "max_stars_repo_name": "ibukanov/ahome", "max_stars_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/bergen_master_thesis/body/Kinematics.tex", "max_issues_repo_name": "ibukanov/ahome", "max_issues_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/bergen_master_thesis/body/Kinematics.tex", "max_forks_repo_name": "ibukanov/ahome", "max_forks_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": 22.9404888417, "max_line_length": 79, "alphanum_fraction": 0.5253624867, "num_tokens": 10647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6067882048638052}}
{"text": "\\chapter{Conventions and useful relations}\n\\label{Conventions}\n\n\\begin{itemize}\n\n\\item \n$A^\\dag$, $A^T$, $A^*$ denote respectively\nthe hermitian conjugation, matrix transposition and complex conjugation of $A$.\nFor a scalar quantity $a$, $a^T = a$ and $a^\\dag = a^*$.\n\n\\item \nLower-case Greek letters are used for Lorentz indices\nand two-component spinor indices. In most cases the letters\n$\\mu$, $\\nu$, $\\rho$, $\\sigma$ are Lorentz indices, whereas \n$\\alpha$ and $\\beta$ are two-component spinor indices. Lower-case Roman letters\nare used to index four-component spinors. The index $r$ is often used \nto denote \"+\" or \"-\" polarization states. \n\n\\item \nThe Cartesian metric tensor $\\eta_{\\mu\\nu}$ is given by\n\\bel{convCartesianMetric}\n\\eta_{\\mu\\nu} = \\left\\{ \\matrix{1  & \\mbox{if} \\quad \\mu = \\nu = 0 \\cr\n                                -1 & \\mbox{if} \\quad \\mu = \\nu \\ne 0 \\cr\n                                0  & \\mbox{otherwise} } \\right. .\n\\ee\n\n\\item\n$g_{\\mu\\nu}$ stands for an arbitrary symmetric matrix with signature -2, i.e.\nthe difference between the number of positive and negative eigenvalues of \n$g_{\\mu\\nu}$ should be -2.\n\n\\P\nThese requirements mean\nthat one can find a non-singular real matrix $L$ such that \n\n\\bel{gamma-metric-transformation}\n\\eta_{\\mu\\nu} = L_{\\mu}{}^\\rho L_{\\nu}{}^\\sigma g_{\\rho\\sigma}\n\\quad \\mbox{or} \\quad \ng_{\\rho\\sigma} = (L^{-1})_\\rho{}^\\mu (L^{-1})_\\sigma{}^\\nu \\eta^{\\mu\\nu}\n.\n\\ee  \n\nAnother useful form of~\\rf{gamma-metric-transformation} is\n\\bel{gamma-metric-transformation2}\n\\eta^{\\mu\\nu} = (L^{-1})_\\rho{}^\\mu (L^{-1})_\\sigma{}^\\nu g^{\\rho\\sigma}\n\\quad \\mbox{or} \\quad \ng^{\\rho\\sigma}= L_{\\mu}{}^\\rho L_{\\nu}{}^\\sigma\\eta^{\\mu\\nu}\n.\n\\ee\n\nIn most cases $g$ is used to denote the determinant of $g_{\\mu\\nu}$, \n\\be\ng = \\det g < 0.\n\\ee\n\n\\item \nI use $p$ mostly for particle 4-momenta such that \n\\be\np^2  \\equiv p_\\mu p^\\mu = g_{\\mu\\nu}p^\\mu p^\\mu = m^2 > 0\n\\ee\nwith some\nmass $m$. I also use $q$ to denote the normalized momenta, \n\\bel{convQPRelation}\nq \\equiv p/m, \\quad q^2 = 1.  \n\\ee  \n\n\\item \n$(a \\cdot b)$ and $\\slsh{a}$ represent \nthe index-less notations for scalar products, \n\\be\n(a \\cdot b) \\equiv a_\\mu b^\\mu, \\quad \\slsh{a} = a_\\mu \\gu\\mu.\n\\ee\n\n\\item \n$A_{(\\mu_1 \\dots \\mu_k)}$ and $A_{[\\mu_1 \\dots \\mu_k]}$ \ndenote the symmetric and antisymmetric parts of $A_{\\mu_1 \\dots \\mu_k}$,\n\n\\beml{convention-symmetry-anti-symmetry}\nA_{(\\mu_1 \\dots \\mu_k)} & = &\n\\frac{1}{k!}\\sum_{\\sigma}\nA_{\\mu_{\\sigma(1)} \\dots \\mu_{\\sigma(k)}},\n\n\\nel\nA_{[\\mu_1 \\dots \\mu_k]} & = &\n\\frac{1}{k!}\\sum_{\\sigma}\n\\sign(\\sigma) A_{\\mu_{\\sigma(1)} \\dots \\mu_{\\sigma(k)}},\n\\ee\n\nwhere the sum is taken over the permutation group of the set \n$\\{ 1, \\dots, k \\}$, $\\sigma(n)$ gives the result of\nthe permutation $\\sigma$ for the number $n$ and \n$\\sign(\\sigma)$ is $1$\nif $\\sigma$ forms an even permutation of $\\{ 1, \\dots, k \\}$\n and $-1$ otherwise. (A permutation \nis even if it is obtained by an even number of simple permutations \nand the simple permutation is the exchange\nof two neighboring indices.)\n\n\\P \nIt is easy to check that\n\\beml{contractionWithSymAnti}\n&\nA_{(\\mu_1 \\dots \\mu_k)}B^{(\\mu_1 \\dots \\mu_k)} = \nA_{\\mu_1 \\dots \\mu_k}B^{(\\mu_1 \\dots \\mu_k)} = \nA_{(\\mu_1 \\dots \\mu_k)}B^{\\mu_1 \\dots \\mu_k} ,\n\n\\nel &\nA_{[\\mu_1 \\dots \\mu_k]}B^{[\\mu_1 \\dots \\mu_k]} = \nA_{\\mu_1 \\dots \\mu_k}B^{[\\mu_1 \\dots \\mu_k]} = \nA_{[\\mu_1 \\dots \\mu_k]}B^{\\mu_1 \\dots \\mu_k} ,\n\n\\nel &\nA_{[\\mu_1 \\dots \\mu_k]}B^{(\\mu_1 \\dots \\mu_k)} = 0 .\n\n\\ee\n\n\\item\n\n$\\varepsilon^{\\mu\\nu\\rho\\sigma}$ is the fully\nantisymmetric 4-dimensional tensor defined by\n\n\\bel{convEpsilonUpIs}\n\\varepsilon^{\\mu\\nu\\rho\\sigma} = \\varepsilon^{[\\mu\\nu\\rho\\sigma]} = \n   \\frac{1}{\\sqrt{-g}} e^{\\mu\\nu\\rho\\sigma},\n\\quad\ne^{\\mu\\nu\\rho\\sigma} = e^{[\\mu\\nu\\rho\\sigma]}, \n\\quad \ne^{0123} = 1,\n\\ee\n\nThe pseudo-tensor $e^{\\mu\\nu\\rho\\sigma}$ satisfies for any $A^\\mu{}_\\nu$\n\\bel{convDetIs}\nA^\\mu{}_{\\mu'}A^\\nu{}_{\\nu'}A^\\rho{}_{\\rho'}A^\\sigma{}_{\\sigma'}\n                        e^{\\mu'\\nu'\\rho'\\sigma'} \n= \\det(A) \\, e^{\\mu\\nu\\rho\\sigma}\n\\ee\n\nBy the definition $e_{\\mu\\nu\\rho\\sigma} = e^{\\mu\\nu\\rho\\sigma}$ and \nfor the covariant version of $\\varepsilon^{\\mu\\nu\\rho\\sigma}$ \none can find\n\n\\beml{convEpsilonDownIs}\n\\varepsilon_{\\mu\\nu\\rho\\sigma} \n& = & g_{\\mu\\mu'}g_{\\nu\\nu'}g_{\\sigma\\sigma'}g_{\\rho\\rho'}\n        \\varepsilon^{\\mu'\\nu'\\sigma'\\rho'} \n\n\\nel \n&  = & \\frac{1}{\\sqrt{-g}} g_{\\mu\\mu'}g_{\\nu\\nu'}g_{\\sigma\\sigma'}g_{\\rho\\rho'}\n                        e^{\\mu'\\nu'\\sigma'\\rho'}   \n= \\frac{1}{\\sqrt{-g}} g e_{\\mu\\nu\\rho\\sigma},\n\\nel\n\\varepsilon_{\\mu\\nu\\rho\\sigma} & = & -\\sqrt{-g} \\, e_{\\mu\\nu\\rho\\sigma}\n\\ee\n\n\\P\nIn the case when $g_{\\mu\\nu}$ equals the Cartesian \nmetric~\\rf{convCartesianMetric}\n, $g = -1$ and $\\varepsilon^{\\mu\\nu\\rho\\sigma}$ is given by\n\\be\n\\varepsilon^{\\mu\\nu\\rho\\sigma} = e^{\\mu\\nu\\rho\\sigma},\n\\quad\n\\varepsilon^{0123} = 1,\n\\quad\n\\varepsilon_{0123} = -e_{0123} = -e^{0123} = -1.\n\\ee\n\n\n\\end{itemize}\n", "meta": {"hexsha": "f574d44662227abd497c9e99226feaecb1ccb477", "size": 4896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writes/bergen_master_thesis/body/Conventions.tex", "max_stars_repo_name": "ibukanov/ahome", "max_stars_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/bergen_master_thesis/body/Conventions.tex", "max_issues_repo_name": "ibukanov/ahome", "max_issues_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": "writes/bergen_master_thesis/body/Conventions.tex", "max_forks_repo_name": "ibukanov/ahome", "max_forks_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "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": 28.9704142012, "max_line_length": 79, "alphanum_fraction": 0.6235702614, "num_tokens": 1887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6067881998104745}}
{"text": "%\n% IAT 267: Introduction to Technological Systems - A Course Overview\n% Section: Electricity and Circuit Design\n%\n% Author: Jeffrey Leung\n%\n\\section{Electricity and Circuit Design}\n\t\\label{sec:electricity-and-circuit-design}\n\\subsection{Electricity}\n\t\\label{subsec:electricity-and-circuit-design:electricity}\n\\begin{easylist}\n\n\t& \\emph{Voltage:} Relative level of electrical energy between any two given points in a circuit\n\t\t&& Denoted by \\si{\\volt}\n\t\t&& SI unit: Volts (\\si{\\volt})\n\t\t&& Totals 0 over the entire circuit\n\t\t\t&&& Power sources add to the voltage; components subtract from the voltage\n\t& \\emph{Current:} Amount of electrical energy passing through any given point in a circuit\n\t\t&& Denoted by I\n\t\t&& SI unit: Amperes/amps (\\si{\\ampere})\n\t\t&& Constant throughout the circuit\n\t\t&& Follows the path of least resistance\n\n\t& \\emph{Resistance:} Amount of difficulty in moving an electric current through a given component\n\t\t&& Denoted by R\n\t\t&& SI unit: Ohms (\\si{\\ohm})\n\t\t&& Inherent property of a material\n\t\t&& \\emph{Conductor:} Material which has a low resistance\n\t\t&& \\emph{Insulator:} Material which has a high resistance\n\t\t&& Calculating resistance:\n\t\t\t&&& \\hyperref[subsec:electricity-and-circuit-design:circuits]{Series circuit}: Add the individual resistances\n\n\t\t\t&&&& Formula:\n\n\t\t\t\\begin{displaymath}\n\t\t\t\tR_{T}\n\t\t\t\t= \\sum_{i=0}^{n} R_{i}\n\t\t\t\\end{displaymath}\n\n\t\t\t&&&& E.g. For the circuit in figure~\\ref{fig:series-circuit-total-resistance-example},\n\n\t\t\t\\begin{figure}[!htb]\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\tto [battery] (0, 3)\n\t\t\t\t\t\tto [R, l=R1 (820\\ \\si{\\ohm})] (3, 3)\n\t\t\t\t\t\tto [R, l=R2 (1200\\ \\si{\\ohm})] (3, 0)\n\t\t\t\t\t\tto [R, l=R3 (150\\ \\si{\\ohm})] (0, 0);\n\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\end{center}\n\t\t\t\t\t\\caption{Series circuit with resistors 820 \\si{\\ohm}, 1200 \\si{\\ohm}, 150 \\si{\\ohm}}\n\t\t\t\t\t\\label{fig:series-circuit-total-resistance-example}\n\t\t\t\\end{figure}\n\n\t\t\tThe total resistance is:\n\t\t\t\\Deactivate\n\t\t\t\\begin{IEEEeqnarray}{ r C l }\n\t\t\t\tR_{T}\n\t\t\t\t& = & \\sum_{i=0}^{n} R_{i} \\\\\n\t\t\t\t& = & R_{1} + R_{2} + R_{3} \\\\\n\t\t\t\t& = & 820\\ \\si{\\ohm} + 1200\\ \\si{\\ohm} + 150\\ \\si{\\ohm} \\\\\n\t\t\t\t& = & 2170\\ \\si{\\ohm}\n\t\t\t\\end{IEEEeqnarray}\n\t\t\t\\Activate\n\n\t\t\t&&& \\hyperref[subsec:electricity-and-circuit-design:circuits]{Parallel circuit}: Find the current of each individual path (see \\emph{Ohm's Law} below) (voltage is constant throughout the circuit), and divide the voltage by the sum of the resulting currents\n\n\t\t\t\t&&&& Formula:\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tR_{T}\n\t\t\t\t\t= \\frac{V}{\\sum^{n}_{i=0} \\frac{V}{R_{i}}}\n\t\t\t\t\t= \\frac{1}{\\sum^{n}_{i=0} \\frac{1}{R_{i}}}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\t&&&& E.g. For the circuit in figure~\\ref{fig:parallel-circuit-total-resistance-example-1},\n\n\t\t\t\t\\begin{figure}[!htb]\n\t\t\t\t\t\\begin{center}\n\t\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\t\tto [battery, l=60\\ \\si{\\volt}] (0,3)\n\t\t\t\t\t\t\tto [short] (9,3)\n\t\t\t\t\t\t\tto [R, l_=R3 (20 \\si{\\ohm})] (9,0)\n\t\t\t\t\t\t\tto [short] (0,0);\n\n\t\t\t\t\t\t\t\\draw (6,3)\n\t\t\t\t\t\t\tto [R, l_=R2 (12 \\si{\\ohm})] (6,0);\n\n\t\t\t\t\t\t\t\\draw (3,3)\n\t\t\t\t\t\t\tto [R, l_=R1 (6 \\si{\\ohm})] (3,0);\n\t\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\t\\end{center}\n\t\t\t\t\t\\caption{Parallel circuit with resistors 6 \\si{\\ohm}, 12 \\si{\\ohm}, 20 \\si{\\ohm}}\n\t\t\t\t\t\\label{fig:parallel-circuit-total-resistance-example-1}\n\t\t\t\t\\end{figure}\n\n\t\t\t\tThe currents are:\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tI_{1}\n\t\t\t\t\t= \\frac{V_{1}}{R_{1}}\n\t\t\t\t\t= \\frac{60\\ \\si{\\volt}}{6\\ \\si{\\ohm}}\n\t\t\t\t\t= 10\\ \\si{\\ampere}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tI_{2}\n\t\t\t\t\t= \\frac{V_{2}}{R_{2}}\n\t\t\t\t\t= \\frac{60\\ \\si{\\volt}}{12\\ \\si{\\ohm}}\n\t\t\t\t\t= 5\\ \\si{\\ampere}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tI_{3}\n\t\t\t\t\t= \\frac{V_{3}}{R_{3}}\n\t\t\t\t\t= \\frac{60\\ \\si{\\volt}}{20\\ \\si{\\ohm}}\n\t\t\t\t\t= 3\\ \\si{\\ampere}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tI_{T}\n\t\t\t\t\t= \\sum_{i=0}^{n} I_{i}\n\t\t\t\t\t= I_{1} + I_{2} + I_{3}\n\t\t\t\t\t= 10\\ \\si{\\ampere} + 5\\ \\si{\\ampere} + 3\\ \\si{\\ampere}\n\t\t\t\t\t= 18\\ \\si{\\ampere}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\tTherefore, the total resistance is:\n\n\t\t\t\t\\begin{displaymath}\n\t\t\t\t\tR_{T}\n\t\t\t\t\t= \\frac{\\si{\\volt}_{T}}{I_{T}}\n\t\t\t\t\t= \\frac{60\\ \\si{\\volt}}{18\\ \\si{\\ampere}}\n\t\t\t\t\t= 3.\\overline{3}\\ \\si{\\ohm}\n\t\t\t\t\\end{displaymath}\n\n\t\t\t\t&&&& E.g. For the circuit in figure~\\ref{fig:parallel-circuit-total-resistance-example-2},\n\n\t\t\t\t\\begin{figure}[!htb]\n\t\t\t\t\t\\begin{center}\n\t\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\t\tto [battery, l=60\\ \\si{\\volt}] (0,3)\n\t\t\t\t\t\t\tto [short] (9,3)\n\t\t\t\t\t\t\tto [R, l_=R3 (10 \\si{\\ohm})] (9,0)\n\t\t\t\t\t\t\tto [short] (0,0);\n\n\t\t\t\t\t\t\t\\draw (6,3)\n\t\t\t\t\t\t\tto [R, l_=R2 (15 \\si{\\ohm})] (6,0);\n\n\t\t\t\t\t\t\t\\draw (3,3)\n\t\t\t\t\t\t\tto [R, l_=R1 (5 \\si{\\ohm})] (3,0);\n\t\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\t\\end{center}\n\t\t\t\t\t\\caption{Parallel circuit with resistors 5 \\si{\\ohm}, 15 \\si{\\ohm}, 10 \\si{\\ohm}}\n\t\t\t\t\t\\label{fig:parallel-circuit-total-resistance-example-2}\n\t\t\t\t\\end{figure}\n\n\t\t\t\tThe total resistance is:\n\n\t\t\t\t\\Deactivate\n\t\t\t\t\\begin{IEEEeqnarray}{ r C l }\n\t\t\t\t\tR_{T}\n\t\t\t\t\t& = & \\frac{1}{ \\sum_{i=0}^{n} \\frac{1}{R_{i}} } \\\\\n\t\t\t\t\t& = & \\frac{1}{ \\frac{1}{R_{1}} + \\frac{1}{R_{2}} + \\frac{1}{R_{3}} } \\\\\n\t\t\t\t\t& = & \\frac{1}{ \\frac{1}{5} + \\frac{1}{15} + \\frac{1}{10} } \\\\\n\t\t\t\t\t& = & \\frac{1}{ \\frac{6}{30} + \\frac{2}{30} + \\frac{3}{30} } \\\\\n\t\t\t\t\t& = & \\frac{1}{ \\frac{11}{30} } \\\\\n\t\t\t\t\t& = & \\frac{30}{11}\\ \\si{\\ohm}\n\t\t\t\t\\end{IEEEeqnarray}\n\t\t\t\t\\Activate\n\n\t& \\emph{Ohm's Law:} Formula relating voltage, current, and resistance\n\t\t&& Formula:\n\n\t\t\\begin{displaymath}\n\t\t\tV = I \\cdot R\n\t\t\\end{displaymath}\n\n\t\t\\medskip\n\n\t\t\\begin{center}\n\t\t\t\\Deactivate\n\t\t\t\\begin{tabular}{ l r @{ = } l }\n\t\t\t\twhere\n\t\t\t\t& $V$ & Voltage \\\\\n\t\t\t\t& $I$ & Current \\\\\n\t\t\t\t& $R$ & Resistance\n\t\t\t\\end{tabular}\n\t\t\t\\Activate\n\t\t\\end{center}\n\n\t\t&& \\emph{Short-circuit:} Insufficient resistance which creates too much current (as voltage is constant), damaging the circuit\n\n\t\\bigskip\n\n\t& \\emph{Power:} Rate at which electrical energy is transferred\n\t\t&& Denoted by P\n\t\t&& SI unit: Watt (\\si{\\watt})\n\t\t&& Formula:\n\n\t\t\\begin{displaymath}\n\t\t\tP = V \\cdot I\n\t\t\\end{displaymath}\n\n\t\t\\begin{center}\n\t\t\t\\Deactivate\n\t\t\t\\begin{tabular}{ l r @{ = } l }\n\t\t\t\twhere\n\t\t\t\t& $P$ & Power \\\\\n\t\t\t\t& $V$ & Voltage \\\\\n\t\t\t\t& $I$ & Current\n\t\t\t\\end{tabular}\n\t\t\t\\Activate\n\t\t\\end{center}\n\n\t& Electron flow:\n\t\t&& From greater electrical energy to lesser electrical energy\n\t\t&& From the negative terminal to the positive terminal\n\n\\end{easylist}\n\\subsection{Types of Electricity}\n\t\\label{subsec:electricity-and-circuit-design:types-of-electricity}\n\\begin{easylist}\n\n\t& \\emph{Piezoelectricity:} Electrical potential created from pressure energy exerted upon a polarized crystal\n\t\t&& Discovered in 1880s by the Curies\n\t\t&& Explanation:\n\t\t\t&&& Piezoelectric crystals are permanently electrically polarized, aligning the dipoles and attracting excess surface charge to electrically neutralize the crystal\n\t\t\t&&& Applying force to the piezoelectric crystal disrupts the orientation of electric dipoles which creates temporary excess charge\n\t\t&& E.g. Quartz is compressed to create a consistent electrical signal in a watch\n\t\t&& For applications, see \\hyperref[sec:sensors]{Sensors} and \\hyperref[sec:actuators]{Actuators}\n\n\\end{easylist}\n\\subsection{Circuits}\n\t\\label{subsec:electricity-and-circuit-design:circuits}\n\\subsubsection{Introduction}\n\t\\label{subsubsec:electricity-and-circuit-design:circuits:introduction}\n\\begin{easylist}\n\n\t& \\emph{Circuit:} Loop of electronic components with a power source and a load\n\n\t& Input pins not grounded or connected to power may exhibit variable capacitance (electrical energy)\n\t\t&& Example of proper grounding: See figure~\\ref{fig:example-input-pin-grounding}\n\n\t\t\\begin{figure}[!htb]\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0, 6)\n\t\t\t\t\tto [closing switch] (0, 4)\n\t\t\t\t\tto [R, l_=10k\\ \\si{\\ohm}] (0, 2)\n\t\t\t\t\tto (0, 2) node[ground]{};\n\n\t\t\t\t\t\\draw (0, 4)\n\t\t\t\t\tto [short, l=Input\\ pin] (2, 4);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\t\t\t\t\\caption{Example of Input Pin Grounding}\n\t\t\t\t\\label{fig:example-input-pin-grounding}\n\t\t\\end{figure}\n\n\t& \\emph{Schematic:} Visual representation of a system using standardized symbols\n\n\\end{easylist}\n\\subsubsection{Components}\n\t\\label{subsubsec:electricity-and-circuit-design:circuits:components}\n\\begin{easylist}\n\n\t& \\emph{Power source:} Provider of electrical energy\n\t\t&& Denoted by:\n\n\t\t\t&&& Voltage source (American):\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [american voltage source] (2,0);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\n\t\t\t&&& Battery:\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [battery] (2,0);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\n\t\t\t\t&&&& Longer line is the positive terminal; shorter line is the negative terminal\n\n\t\t&& E.g. Battery, wall plug\n\n\t& \\emph{Electrical load:} Component which consumes electrical energy\n\t\t&& E.g. Light bulb\n\n\t& \\emph{Resistor:} Electrical component which limits the current in a circuit\n\t\t&& Denoted by:\n\t\t\\begin{center}\n\t\t\t\\begin{circuitikz}\n\t\t\t\t\\draw (0,0)\n\t\t\t\tto [R] (2,0);\n\t\t\t\\end{circuitikz}\n\t\t\\end{center}\n\n\t\t&& \\emph{Potentiometer:} Resistor which has adjustable/variable resistance\n\t\t\t&&& Denoted by:\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [pR] (2,0);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\t\t\t&&& Connections:\n\t\t\t\t&&&& Side prong to positive\n\t\t\t\t&&&& Middle prong to output\n\t\t\t\t&&&& (Other) side prong to ground\n\t\t\t\t&&&& Turning the knob moves the middle prong along a resistor, closer/farther to the side prong, forcing the current to move through greater resistance\n\n\t& \\emph{Polarization:} Characteristic of an electrical component which only operates when the current flows in a specific direction\n\t\t&& Anode (longer prong) is connected to the positive terminal\n\t\t&& Cathode (shorter prong) is connected to the negative terminal\n\n\t\t\\medskip\n\n\t\t&& \\emph{Diode:} Electrical component which limits the flow of electricity to only one direction\n\t\t\t&&& Denoted by:\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [Do] (2,0);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\n\t\t\t&&& \\emph{Light Emitting Diode (LED):} Diode which emits light when current flows through with the correct voltage\n\t\t\t\t&&&& Denoted by:\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\tto [D*] (2,0);\n\t\t\t\t\t\\end{circuitikz}\n\n\t\t\t\t\t\\medskip\n\t\t\t\t\tor\n\t\t\t\t\t\\medskip\n\n\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\tto [leDo] (2,0);\n\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\end{center}\n\n\n\t& \\emph{Capacitor:} Electrical component which stores then releases electrical energy in intervals\n\t\t&& May be polarized\n\t\t&& Denoted by:\n\n\t\t\t&&& Unpolarized:\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\tto [capacitor] (2,0);\n\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\end{center}\n\n\t\t\t&&& Polarized:\n\t\t\t\t\\begin{center}\n\t\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\t\tto [polar capacitor] (2,0);\n\t\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\end{center}\n\n\n\t& \\emph{Switch:} Electrical component which controls a break in a circuit and therefore electrical energy flow\n\t\t&& Denoted by:\n\t\t\\begin{center}\n\t\t\t\\begin{circuitikz}\n\t\t\t\t\\draw (0,0)\n\t\t\t\tto [closing switch] (2,0);\n\t\t\t\\end{circuitikz}\n\t\t\\end{center}\n\n\t\t&& Closing a switch completes the circuit; opening a switch breaks the circuit\n\n\t& \\emph{(Solderless) Breadboard:} Base on which circuits can be built\n\t\t&& Useful for prototyping or designing a circuit\n\t\t&& Components should not be added or removed while the circuit is live to avoid short circuits or shocks\n\n\t& \\emph{Microcontroller:} Small computer with a processor, memory, and programmable inputs/outputs\n\n\t& \\emph{Analog-to-digital converter}: Device which converts an analog voltage to a digital value\n\n\\end{easylist}\n\\subsubsection{Types of Circuits}\n\t\\label{subsubsec:electricity-and-circuit-design:circuits:types-of-circuits}\n\\begin{easylist}\n\n\t& \\emph{Serial circuit:} Circuit in which all components are connected in-line\n\t\t&& I.e. Only one path exists from the positive terminal to the negative terminal for the electrons to flow through\n\t\t&& E.g. See figure~\\ref{fig:series-circuit-example}.\n\n\t\t\\begin{figure}[!htb]\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [battery] (0,2)\n\t\t\t\t\tto [lamp] (4,2)\n\t\t\t\t\tto [short] (4,0)\n\t\t\t\t\tto [lamp] (0,0);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\caption{Example of a series circuit}\n\t\t\t\t\\label{fig:series-circuit-example}\n\t\t\t\\end{center}\n\t\t\\end{figure}\n\n\t\t&& To find the total resistance, see \\hyperref[subsec:electricity-and-circuit-design:electricity]{Calculating resistance}\n\n\t& \\emph{Parallel circuit:} Circuit in which not all components are placed in-line with each other\n\t\t&& I.e. Multiple paths exist from the positive terminal to the negative terminal for the electrons to flow through\n\t\t&& E.g. See figure~\\ref{fig:parallel-circuit-example}.\n\n\t\t\\begin{figure}[!htb]\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0,0)\n\t\t\t\t\tto [battery] (0,2)\n\t\t\t\t\tto [short] (4,2)\n\t\t\t\t\tto [lamp] (4,0)\n\t\t\t\t\tto [short] (0,0);\n\n\t\t\t\t\t\\draw (2,0)\n\t\t\t\t\tto [lamp] (2,2);\n\t\t\t\t\\end{circuitikz}\n\t\t\t\t\\caption{Example of a parallel circuit}\n\t\t\t\t\\label{fig:parallel-circuit-example}\n\t\t\t\\end{center}\n\t\t\\end{figure}\n\n\t\t&& To find the total resistance, see \\hyperref[subsec:electricity-and-circuit-design:electricity]{Calculating resistance}\n\n\t& \\emph{Voltage divider:} Portion of a circuit which connects to the ground, using a variable resisitance from a sensor to manipulate the voltage outputted to a component\n\t\t&& For an example schematic, see figure~\\ref{fig:example-voltage-divider}\n\n\t\t\\begin{figure}[!htb]\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{circuitikz}\n\t\t\t\t\t\\draw (0, 6)\n\t\t\t\t\tto [short, l^=$V_{in}$] (2, 6)\n\t\t\t\t\tto [R, l_=$R_{1}$] (2, 4)\n\t\t\t\t\tto [short, l^=$V_{out}$] (4, 4);\n\n\t\t\t\t\t\\draw (2, 4)\n\t\t\t\t\tto [R, l_=$R_{2}$] (2, 2)\n\t\t\t\t\tto (2, 2) node[ground]{};\n\t\t\t\t\\end{circuitikz}\n\t\t\t\\end{center}\n\t\t\t\t\\caption{Example of a Voltage Divider}\n\t\t\t\t\\label{fig:example-voltage-divider}\n\t\t\\end{figure}\n\n\t\t&& Formula for output voltage:\n\n\t\t\\begin{displaymath}\n\t\t\tV_{out} = \\frac{R_{2}}{R_{1} + R_{2}} \\cdot V_{in}\n\t\t\\end{displaymath}\n\n\t\t\t&&& Explanation:\n\n\t\t\t\\Deactivate\n\t\t\t\\begin{IEEEeqnarray}{ r C l }\n\t\t\t\tV_{in}\n\t\t\t\t& = & I \\cdot R \\\\\n\t\t\t\t& = & I \\cdot (R_{1} + R_{2}) \\rule[-1.5em]{0pt}{1em} \\\\\n\t\t\t\tI\n\t\t\t\t& = & \\frac{V_{in}}{R_{1} + R_{2}} \\rule[-1.5em]{0pt}{1em} \\\\\n\t\t\t\tV_{out}\n\t\t\t\t& = & I \\cdot R \\\\\n\t\t\t\t& = & I \\cdot R_{2} \\\\\n\t\t\t\t& = & \\frac{V_{in}}{R_{1} + R_{2}} \\cdot R_{2} \\\\\n\t\t\t\t& = & \\frac{R_{2}}{R_{1} + R_{2}} \\cdot V_{in}\n\t\t\t\\end{IEEEeqnarray}\n\t\t\t\\Activate\n\n\t\t\tReminders: \\\\\n\t\t\tVoltage is the potential difference between a component in the circuit and the ground. \\\\\n\t\t\tCurrent ($I$) is constant throughout the circuit.\n\n\\end{easylist}\n\\clearpage\n", "meta": {"hexsha": "e73d7b2efe2fd2ab4b563bf3101015868d6775c2", "size": 14546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "iat-267-introduction-to-technological-systems/tex/electricity-and-circuit-design.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": "iat-267-introduction-to-technological-systems/tex/electricity-and-circuit-design.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": "iat-267-introduction-to-technological-systems/tex/electricity-and-circuit-design.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": 29.6252545825, "max_line_length": 259, "alphanum_fraction": 0.6292451533, "num_tokens": 5121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6067598905109082}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{amsmath} \n\\usepackage{amsthm}\n\\usepackage{amsfonts}\n\\usepackage{graphicx}\n\n\\graphicspath{ {images/} }\n\n\\newtheorem{theorem}{Theorem}\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}\n\\theoremstyle{definition}\n\\newtheorem{example}{Example}\n\n\\begin{document}\n\n\\title{Spherical Harmonics: Approximating Functions With Orthogonal Bases}\n\\author{Justin Meiners}\n\n\\maketitle\n\n\\section{Introduction}\n\nIn this paper I will explain how to use sets of simple functions as a basis for approximating more complicated functions. This is similar to trigonometric fourier series but more general. Along the way I will explain how the theory applies to functions on the unit sphere called spherical harmonics. At the end I will apply this theory to a problem in computer graphics.\n\n\\section{Inner Products}\n\nIn analysis we generalized the notion of distance by definining a metric, which as an operator with certain properties that ensure it acts like a \"distance function\". For example, it would not make sense to talk about negative distances, so a metric must always be positive.\n\nWe can similarly generalize the idea of a dot product by definining an inner product in terms of its essential properties.\n\n\\begin{definition}\n    An \\textbf{inner product} is binary operation with the following properties:\n\n    Let $x, y, z\\in V$ and $a\\in R$\n\n    \\begin{enumerate}\n        \\item Positive definite: $\\langle x, x\\rangle=0$ when $x=0$ otherwise $\\langle x, x \\rangle>0$\n        \\item Symmetric: $\\langle x, y \\rangle=\\langle y, x \\rangle$.\n        \\item Linear: $\\langle ax, y \\rangle= a\\langle x, y \\rangle$.\n        \\item Distributive: $\\langle x, y + z \\rangle = \\langle x, y \\rangle + \\langle x, z \\rangle$\n    \\end{enumerate}\n\\end{definition}\n\n\\begin{example}\n    Since we wanted to generalize dot product, we expect the euclidean dot product to satisfy these properties.\n\n    $$\\langle x, y \\rangle =\\sum_{i=1}^{n} x_{i}y_{i}$$\n\\end{example}\n\n\\begin{example} \n    The topic of this paper is approximating functions. What might an inner product of functions look like? We can think of it as a continuous dot product. The dot product is the sum of multiples of each vector component. Given two functions $f(x), g(x)$ we can similarly add up multiples of their values at every point. This is of course an integral.\n\n    $$\\langle f(x), g(x) \\rangle = \\int_{a}^{b} f(x)g(y) dx$$\n    This is an inner product of integrable functions on the interval $[a, b]$.\n\\end{example}\n\n\\begin{example}\n    Later we will be approximating functions on the unit sphere. This requires a more exotic inner product which is a spherical integral.\n\n    $$\\langle f(\\theta, \\phi), g(\\theta, \\phi) \\rangle=\\int_{0}^{2\\pi}\\int_{0}^{\\pi}f(\\theta, \\phi)g(\\theta, \\phi)\\sin\\phi\\ \\partial\\phi \\partial\\theta$$\n\n\\end{example}\n\n\n\\subsection{Inner Product Spaces}\n\nThe presence of an inner product gives us more structure than a plain vector space. \n\n\\begin{definition}\n    An \\textbf{inner product space} is a vector space with an inner product operation.\n\\end{definition}\n\n\n\\section{Orthogonal Systems}\n\nAs we know from euclidean geometry that vectors $x, y$ are said to be orthogonal when $\\langle x, y \\rangle$=0. This term also applies to any inner product space.\n\n\\begin{example}\n    What does this look like for functions? An example of two orthogonal functions is $\\cos(\\pi x)$ and $\\cos(2\\pi x)$. The image on the right highlights the inner product which makes it easier to see what is happening.\n\n    \\begin{figure}[h]\n        \\includegraphics[scale=0.3]{ortho}\n        \\includegraphics[scale=0.3]{ortho-int}\n        \\centering\n    \\end{figure}\n\\end{example}\n\n\n\\begin{definition}\n    A set $\\{u_{1}, u_{2}, \\ldots, u_{n} \\}$ is called an \\textbf{orthogonal system} iff for each $i,j\\in \\{ 1 \\ldots n \\}$  $\\langle u_{i}, u_{j} \\rangle=0$ whenever $i\\neq j$.\n\n\\end{definition}\nInformally it is a set of vectors in which each vector is orthogonal to every other vector in the set.\n\n\\subsection{Linear Independance}\n\n\\begin{theorem}\n    The vectors in an orthogonal system are linearly independant\n\\end{theorem}\n\n\\begin{proof}\n    Suppose $c_{1}u_{1}+c_{2}u_{2}+\\ldots+c_{n}u_{n}=0$\n\n    Let $i\\in \\{ 1...n \\}$. Then:\n    \\begin{equation}\n        \\begin{split}\n            &\\langle u_{i}, c_{1}u_{1} + c_{2}u_{2} + \\ldots + c_{n}u_{n} \\rangle \\\\ \n            &= \\langle u_{i}, c_{1}u_{1} \\rangle + \\langle u_{i}, c_{2}u_{2} \\rangle + \\ldots + \\langle u_{i}, c_{i}u_{i} \\rangle + \\ldots + \\langle u_{i}, c_{n}u_{n} \\rangle \\\\\n            &= c_{1}\\langle u_{i}, u_{1} \\rangle + c_{2}\\langle u_{i}, u_{2} \\rangle + \\ldots + c_{i}\\langle u_{i}, u_{i} \\rangle + \\ldots + c_{n}\\langle u_{i}, u_{n} \\rangle \\\\\n            &= c_{i}\\langle u_{i}, u_{i} \\rangle=0 \n        \\end{split}\n    \\end{equation}\n\n    Since $\\langle u_{i}, u_{i} \\rangle \\neq 0$ then $c_{i}=0$.\n    Therefore the set is linearly independant.\n\\end{proof}\n\n\\subsection{Completeness}\n\nLinear independance leads us to think about forming a basis for our vector space. Specifically to approximate functions, we want to create a basis for our space of functions. We now know we can create a linearly indepedant set from orthogonal vectors, for a finite set this guarentee's the vectors span, but not for an infinite space.\n\n\\begin{definition}\n    An orthogonal system $S$ is said to be \\textbf{complete} iff the smallest space containing $S$ is the whole inner product space $R$.\n\\end{definition}\n\nCompleteness is always relative to the space. Clearly an orthogonal system is always complete in some space (the span of the vectors).\n\n\\begin{definition}\n    An orthogonal system which is complete is called an \\textbf{orthogonal basis}.\n\\end{definition}\n\n\\begin{example}\n    The standard basis vectors are an orthgonal basis for $\\mathbb{R}^{n}$ under the dot product.\n    \\begin{equation}\n        \\begin{split}\n            e_{1}&=( 1, 0, \\ldots, 0 ) \\\\\n            e_{2}&=( 0, 1, \\ldots, 0 ) \\\\\n            \\ldots \\\\\n            e_{n}&=( 0, 0, \\ldots, 1 ) \n        \\end{split}\n    \\end{equation}\n\\end{example}\n\n\\begin{example}\n    The powers of x are an orthogonal basis for the space of real polynomials.\n     $$S=\\{ 1, x, x^{2}, x^{3}, \\ldots, x^{n}, \\ldots \\}$$\n\\end{example}\n\n\\begin{example}\n    Laplace's equation states\n    $$\\nabla\\cdot\\nabla f=0$$.\n\n    Although the derivation is significant\\cite{laplace-equation} 3D spherical coordinates this can be written as:\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    The \\textbf{spherical harmonics} are functions which satisfy this equation. They form an orthogonal basis for the space of integrable functions on the unit sphere, using the spherical inner product introduced earlier.\n\n    $$Y_{\\ell}^{m}(\\theta, \\phi)=\\sqrt{\\frac{(2\\ell +1)(\\ell-m)!}{4\\pi(\\ell+m)!}}P_{\\ell}^{m}(\\cos\\phi)e^{im\\theta}$$\n\n    Where $P_{\\ell}^{m}$ are the associated legendre polynomials.\n\\end{example}\n\n\\section{Bessel's Inequality}\n\nWe will now explore Bessel's inequality which will tell us when an orthogonal system is complete. In this section we will refer to the norm of a vector. We will not explore the definition or properties of vector spac enorms here. For our usage the norm is defined by the following:\n\n\\begin{definition}\n    $||x||=\\sqrt{\\langle x, x \\rangle}$\n\\end{definition}\n\n\\begin{definition}\n    Let $U=\\{u_{1}, u_{2}, \\ldots \\}$ be an orthogonal system and $x\\in R$ where $R$ is an inner product space. Define the coordinates $c_{i}$ with respect to $U$ as $c_{i}=\\langle u_{i}, x \\rangle$.\n\\end{definition}\n\n\\begin{theorem}\n    Let $U=\\{u_{1}, u_{2}, \\ldots \\}$ be an orthonormal system and $x\\in R$. Then: \n    $$||x - \\sum_{i=1}^{\\infty} a_{i}u_{i}||$$\n    Is minimized when $a_{i}=c_{i}$, the coordinates with respect to $U$.\n\\end{theorem}\n\nIn other words linear combinations of the vectors in the orthogonal system get closest to the function when they are scaled by the coordintaes.\n\n\\begin{proof}\n    \\begin{equation}\n    \\begin{split}\n        ||x - \\sum_{i=1}^{\\infty} a_{i}u_{i}||^{2}&=\\langle x - \\sum_{i=1}^{\\infty} a_{i}u_{i}, x - \\sum_{i=1}^{\\infty} a_{i}u_{i} \\rangle \\\\\n        &= \\langle x, x \\rangle - 2\\langle x, \\sum_{i=1}^{\\infty} a_{i}u_{i} \\rangle + \\langle \\sum_{i=1}^{\\infty} a_{i}u_{i}, \\sum_{i=1}^{\\infty} a_{i}u_{i} \\rangle \\\\\n        &= ||x||^{2} - 2\\sum_{i=1}^{\\infty} a_{i}c_{i} + \\sum_{i=1}^{\\infty} a_{i}^{2}||u_{i}||^{2} \\\\\n        &= ||x||^{2} - 2\\sum_{i=1}^{\\infty} a_{i}c_{i} + \\sum_{i=1}^{\\infty} a_{i}^{2} + \\sum_{i=1}^{\\infty} (c_{i}^{2} - c_{i}^{2}) \\\\\n        &= ||x||^{2} + (\\sum_{i=1}^{\\infty} a_{i}^{2} - 2\\sum_{i=1}^{\\infty} a_{i}c_{i} + \\sum_{i=1}^{\\infty} c_{i}^{2}) - \\sum_{i=1}^{\\infty} c_{i}^{2} \\\\\n        &= ||x||^{2} + \\sum_{i=1}^{\\infty} (a_{i} - c_{i})^{2} - \\sum_{i=1}^{\\infty} c_{i}^{2} \n    \\end{split}\n    \\end{equation}\n   \n    This is smallest when the middle term drops out which is when $a_{i} = c_{i}$.\n\\end{proof}\n\n\\begin{theorem}\n    Bessel's Inequality\n    $$\\sum_{i=1}^{\\infty}c_{i}^{2} \\leq ||x||^{2}$$\n\\end{theorem}\n\n\\begin{proof}\n    \\begin{equation}\n    \\begin{split}\n        \\langle x - \\sum_{i=1}^{\\infty} a_{i}u_{i}, x - \\sum_{i=1}^{\\infty} a_{i}u_{i} \\rangle &\\geq 0 \\\\\n        ||x||^{2} + \\sum_{i=1}^{\\infty} (a_{i} - c_{i})^{2} - \\sum_{i=1}^{\\infty} c_{i}^{2} &\\geq 0 \\\\\n        ||x||^{2} - \\sum_{i=1}^{\\infty} c_{i}^{2} &\\geq 0 \\\\\n        ||x||^{2} &\\geq \\sum_{i=1}^{\\infty} c_{i}^{2}\n    \\end{split}\n    \\end{equation} \n\\end{proof}\n\n\n\\begin{theorem}\n    An orthogonal system is complete iff Bessel's Inequality is always equal.\n\\end{theorem}\n\n\\begin{proof}\n    We want to show that any vector $x$ in $V$ is equal to linear combinations of the basis elements. In other words the basis spans $V$.\n    \\begin{equation}\n    \\begin{split}\n        ||x - \\sum_{i=1}^{\\infty} c_{i}u_{i}||^{2}&=||x||^{2} + \\sum_{i=1}^{\\infty} (c_{i} - c_{i})^{2} - \\sum_{i=1}^{\\infty} c_{i}^{2} = 0 \\\\\n        x=\\sum_{i=1}^{\\infty} c_{i}u_{i} \\\\\n    \\end{split}\n    \\end{equation}\n\\end{proof}\n\nSo to prove that an orthogonal system is complete we only need to verify that Bessel's inequality is an equality.\n\n\\section{Application}\nIn computer graphics, each object in the scene must be lit directly from each light source (radiance), as well as by light which is bounced from the surronding scene (irradiance). Since light is incoming from all directions, this effect can be modeled as function on a sphere $f(\\theta, \\phi)$. The normal vectors on the surface of the model are used to evaluate the function to calculate the color value at each point on the surface.\n\n\\begin{figure}[h]\n    \\includegraphics[scale=0.35]{sphere-function}\n    \\centering\n\\end{figure}\n\nUnfortunatly, storing this incoming light function, over the entire sphere is not trivial. A common techniques is to place light probes around the scene. At each probe a set of 6 images is rendered (up, down, left, right, forward, back). Nearby objects then  a cubemap (a set of 6 images in a cube) is rendered of the sorrounding scene and then evalatuted. This provides high quality lighting but requires a significant amount of memory to store each of these images.\n\n\\begin{figure}[h]\n    \\includegraphics[scale=0.30]{cubemap}\n    \\includegraphics[scale=0.35]{cube-function}\n    \\centering\n\\end{figure}\n\nWith the theory we have just developed we can do better by approximating the lighting function using the orthgonal basis of the spherical harmonics. For very reflective materials, such as metal, an image is necessary to capture high frequency detail, but most materials need a lower frequency signal. For common materials we need only the first 9 spherical harmonics to get a good approximation. \\cite{sh-lighting}\n\n\\subsection*{Preprocess Step}\n\\begin{enumerate}\n    \\item At each probe in the scene render 6 images of the surrounding enviornment to create a cubemap. We will denote each color channel of the cubemap by the function $g_{\\alpha}(\\theta, \\phi)$ where $\\alpha\\in \\{R, G, B \\}$.\n    \\item For each $\\alpha$ calculate the 9 coeffecients $s_{\\ell}^{m}$ using the inner product.\n        $$s_{\\ell}^{m}=\\langle Y_{\\ell}^{m}(\\theta, \\phi), g_{\\alpha}(\\theta, \\phi) \\rangle=\n        \\int_{0}^{2\\pi}\\int_{0}^{\\pi} Y_{\\ell}^{m}(\\theta, \\phi) g_{\\alpha}(\\theta, \\phi) \\sin\\phi\\ \\partial\\phi \\partial\\theta$$\n        For $0\\leq\\ell\\leq2$ and $-\\ell\\leq m \\leq\\ell$.\n\\end{enumerate}\n\n\\subsection*{Rendering Step}\n\\begin{enumerate}\n    \\item Find the closest probe to this model and get its 9 coeffecients.\n    \\item For each pixel or vertex\n        \\begin{enumerate}\n            \\item Calculate the approximate lighting value using the coeffecients and the spherical harmonic functions.\n                $$x_{\\alpha}=\\sum_{\\ell=0}^{2} \\sum_{m=-\\ell}^{\\ell} s_{\\ell}^{m}Y_{\\ell}^{m}(\\theta, \\phi)$$ \n\n        \\end{enumerate}\n\\end{enumerate}\n\nAdditional details can be found in Ramamoorthi \\cite{sh-lighting} and Green \\cite{sh-gritty}.\n\n\\subsection*{Results}\n\nThe following images were captured from my implementation of this method. The original cubemap is shown on the left, with the spherical harmonic approximation on the right.\n\n\\begin{figure}[h]\n    \\includegraphics[scale=0.25]{vase2}\n    \\includegraphics[scale=0.25]{vase2-sh}\n    \\centering\n\\end{figure}\n\n\\begin{figure}[h]\n    \\includegraphics[scale=0.25]{vase1}\n    \\includegraphics[scale=0.25]{vase1-sh}\n    \\centering\n\\end{figure}\n\n\\pagebreak\n\n\\begin{thebibliography}{999}\n\n\\bibitem{intro-analysis}\n  A.N Kolmogorov \\& S.V. Fomin,\n  \\emph{Introductory Real Analysis}.\n  Dover Books,\n\\bibitem{laplace-equation}\n    Justin Meiners,\n   \\emph{Deriving Laplace's Equation in Spherical Coordinates}\n\\bibitem{sh-lighting}\n    Ravi Ramamoorthi \\& Pat Hanrahan,\n    \\emph{An Efficient Representation for Irradiance Enviornment Maps}\n\\bibitem{sh-gritty}\n    Robin Green\n    \\emph{Spherical Harmonic Lighting: The Gritty Details},\n    Sony Computer Entertainment America\n\\bibitem{cubemap}\n    Cubemap images were taken from: http://www.humus.name/\n\n\\end{thebibliography}\n\n\\end{document}\n", "meta": {"hexsha": "3cbaf3bf80421e40360f8f63bb7a22fdf879cf23", "size": 14273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/functions.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/functions.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/functions.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": 45.167721519, "max_line_length": 467, "alphanum_fraction": 0.6749807329, "num_tokens": 4489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6067598851048219}}
{"text": "\\input{Setup.tex}\n\\begin{document}\n\n\\mainmatter\n\nMFRs \\today \\\\\nMsc Thesis - Dynamics of adaptive neuronal networks. \\\\\nSimon Aertssen (s181603), \\today \\\\ \n\n\\section{Writing out the whole system}\nThe network dynamics are described as follows:\n\\begin{align}\n\\frac{d \\theta_i}{d t} &= (1 - \\cos\\theta_i) + (1 + \\cos\\theta_i)\\cdot\\left(\\eta_i + I_i \\right) \\qquad \\theta_i \\in \\T^N \\nonumber \\\\\nI_{i} &= \\frac{\\kappa}{\\langle k\\rangle} \\sum_{j=1}^{N} A_{i j} P_{n}\\left(\\theta_{j}\\right) \\label{eq:FullThetaNeuronNetwork} \\\\\nP_{n}\\left(\\theta_{j}\\right) &= a_n (1 - \\cos\\theta_j) \\nonumber\n\\end{align}\n\nWe observe synchronisation through the order parameter\n\\begin{align}\nZ(t) = \\frac{1}{N} \\sum_{j=1}^N e^{\\ic\\theta_j}  \\qquad Z(t) \\in \\C \\label{eq:orderparameter}\n\\end{align}\n\nFor a fixed degree network it has been proven that the order parameter follows:\n\\begin{align}\n\\dot{Z}(t)= -\\ic \\frac{(Z-1)^2}{2}+\\frac{(Z+1)^2}{2} \\cdot \\left(-\\Delta+ \\ic\\eta_{0}\n+ \\ic \\kappa \\cdot \\left(1+\\frac{Z^{2} + \\overline{Z}^{2} }{6} - \\frac{4}{3} \\Re(Z)\\right)\\right) \\label{eq:MeanField}\n\\end{align}\n    \nFor an arbitrary network the order parameter follows a trajectory per degree. When we assemble the whole expression for the Ott-Antonsen manifold as found in \\cite{OttAntonsen2017} with $H_2(\\k,t)$ as in \\cite{Martens2020}, we obtain the following:\n\\begin{align}\n\\frac{\\partial z(\\k, t)}{\\partial t} &= -\\ic \\frac{(z(\\k, t)-1)^{2}}{2} + \\frac{(z(\\k, t)+1)^{2}}{2} \\cdot I(\\k, t) \\qquad z(\\k,t) \\in \\C^{M_\\k} \\nonumber \\\\\n%I(\\k) &= -\\Delta(\\k) + \\ic \\eta_{0}(\\k) + i d_{n} \\kappa \\cdot H_n(\\k,t) \\label{eq:OttAntonsenSystemFull} \\\\\n%H_n(\\k,t) &= \\frac{a_n}{\\kmean} \\sum_{\\kacc} P\\left(\\kacc\\right) a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left[A_{0}+\\sum_{p=1}^{n} A_{p}\\left(z\\left(\\kacc, t\\right)^{p} + \\overline{z}\\left(\\kacc, t\\right)^{p}\\right)\\right] \nI(\\k, t) &= -\\Delta(\\k) + \\ic \\eta_{0}(\\k) + i \\kappa \\cdot H_2(\\k,t) \\label{eq:OttAntonsenSystemFull} \\\\\nH_2(\\k,t) &= \\frac{1}{\\kmean} \\sum_{\\kacc} P\\left(\\kacc\\right) a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left( 1 + \\frac{z(\\kacc, t)^2 + \\overline{z}(\\kacc, t)^2}{6} - \\frac{4}{3} \\Re(z(\\kacc, t)) \\right) \\nonumber\n\\end{align}\n\n$\\k$ represents a two-dimensional vector of the in- an out degree as $\\k = ( \\kin, \\kout)$ and has unique entries as it forms the support of the vector of degrees of \\eqref{eq:FullThetaNeuronNetwork} as $\\degree(\\theta_i)$. So $z(\\k,t)$ is really a vector in the complex plane that represents the mean-field dynamics on any node with degree $\\k$, so we could also index as $z(t)_{\\k}$. $\\kacc$ represents $\\k$ when $\\k$ is already in use.\\\\\n\nWe can then find the mean field dynamics through\n\\begin{align}\n\\overline{Z}(t) &= \\frac{1}{N} \\sum_{\\k} P(\\k) z(\\k, t) \\qquad \\overline{Z}(t) \\in \\C \\label{eq:OttAntonsenMeanField}\n\\end{align}\n\nIt is important to notice that in \\eqref{eq:OttAntonsenSystemFull} and \\eqref{eq:OttAntonsenMeanField} we actually compute an inner vector product, which is non-commutative for complex numbers:\n\\begin{align}\na \\cdot b = \\overline{b \\cdot a} \\qquad a, b \\in \\C^r\n\\end{align}\nThis is the result of the \\textsl{Conjugate} or \\textsl{Hermitian} symmetry of the inner product. This is especially important in the \\matlab implementation.\n\n\n\\section{Initial conditions}\nAs the systems in \\cref{eq:FullThetaNeuronNetwork,eq:orderparameter,eq:MeanField,eq:OttAntonsenSystemFull,eq:OttAntonsenMeanField} describe the same dynamics for fully connected networks, it is important to be able to transform initial conditions between systems. When transforming from $\\theta_i(t) \\rightarrow z(\\k,t) \\rightarrow Z(t)$ we go from $\\T^N \\rightarrow \\C^{M_\\k}$ to $\\C^{M_\\k} \\rightarrow \\C$. If we have the same initial conditions, then all systems will predict the same behaviour. We will only map everything to $\\C$.\\\\\nThe following maps can be used to transform the initial conditions, but as they do not give any qualitative information on the dynamics or distributions of the variables, they are not valid for transforming between dynamics. We discard $t=0$ for clarity. \\\\\nMapping operations onto the order parameter in the complex plane is straightforward:\n\\begin{align*}\n\\theta_i \\xrightarrow{\\hspace*{8mm}} Z &= \\frac{1}{N} \\sum_{j=1}^N e^{\\ic\\theta_j} \\\\\nz(\\k) \\longrightarrow Z &= \\frac{1}{N} \\sum_{\\k} P(\\k) z(\\k, t)\n\\end{align*}\n\nTaking the inverse maps, we can make use of the fact that the average of a set of identical values is the value itself. For $z(\\k)$ we have a weighed average which we need to undo, making sure that the whole sums up to $N$.\n\\begin{align*}\nZ \\xrightarrow{\\hspace*{9mm}} \\theta_{i} &= -\\ic \\cdot \\log \\left( Z \\right) \\\\\nZ \\longrightarrow z(\\k) &= \\overline{\\frac{Z \\cdot n(\\k)}{P(\\k)}}\n\\end{align*}\n\nThen, transferring between $\\theta_i$ and $z(\\k)$, we need to filter $\\theta_i$ per degree:\n\\begin{align*}\nz(\\k) \\longrightarrow \\theta_i &= -\\ic \\cdot \\log \\left( \\frac{z(\\k)\\cdot P(\\k)}{n(\\k)} \\right) \\qquad \\text{ if } \\degree(\\theta_i) = \\k \\\\\n\\theta_i \\longrightarrow z(\\k) &= \\sum_{\\k} e^{\\ic \\vartheta_{\\k}} \\qquad \\qquad \\vartheta_{\\k} = \\sum_{i = 1}^{n(\\k)} \\theta_i \\in \n\\left\\{ \\theta_i \\vert \\degree(\\theta_i) = \\k, \\forall i \\leq N \\right\\}\n\\end{align*}\n%Or also $\\sum_i^N A_{ij} = k^{\\rm in} \\cup \\sum_j^N A_{ij} = \\kout$. \n\nWe can see how $\\lim_{N \\rightarrow +\\infty} n(\\k) = P(\\k)$, which makes these maps exact for any network size. \n    \n%\\newpage\n%\\section{Phase space}\n%\\subsection{Fixed degree networks}\n%In the phase space, we can clearly distinguish three macroscopic states for the mean field:\n%\\begin{figure}[H]\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRPSR.png}\n%  \\caption{PSR state}\\label{fig:MFRPSR}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRPSS.png}\n%  \\caption{PSS state}\\label{fig:MFRPSS}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}%\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRCPW.png}\n%  \\caption{CPW state}\\label{fig:MFRCPW}\n%\\endminipage\n%\\end{figure}\n%For different networks this can look a little different.\n%\n%\\subsection{Random networks}\n%\\begin{figure}[H]\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSR_random.png}\n%  \\caption{PSR state}\\label{fig:MFRPSR}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSS_random.png}\n%  \\caption{PSS state}\\label{fig:MFRPSS}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}%\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARCPW_random.png}\n%  \\caption{CPW state}\\label{fig:MFRCPW}\n%\\endminipage\n%\\end{figure}\n%\n%\\subsection{Scale Free networks}\n%\\begin{figure}[H]\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSR_scalefree.png}\n%  \\caption{PSR state}\\label{fig:MFRPSR}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSS_scalefree.png}\n%  \\caption{PSS state}\\label{fig:MFRPSS}\n%\\endminipage\\hfill\n%\\minipage{0.32\\textwidth}%\n%  \\includegraphics[width=\\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARCPW_scalefree.png}\n%  \\caption{CPW state}\\label{fig:MFRCPW}\n%\\endminipage\n%\\end{figure}\n%\n%\n%\\section{Differences between theory and practice}\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/InspectMeanFieldFullyConnected.pdf}\n%  \\caption{Mean field descriptions of fully connected networks.}\\label{fig:InspectMeanFieldFullyConnected}\n%\\end{figure}\n%\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/InspectMeanFieldFixedDegree.pdf}\n%  \\caption{Mean field descriptions of fixed degree networks.}\\label{fig:InspectMeanFieldFixedDegree}\n%\\end{figure}\n%\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/InspectMeanFieldRandom.pdf}\n%  \\caption{Mean field descriptions of random networks.}\\label{fig:InspectMeanFieldRandom}\n%\\end{figure}\n%\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/InspectMeanFieldScaleFree.pdf}\n%  \\caption{Mean field descriptions of scale-free networks.}\\label{fig:InspectMeanFieldScaleFree}\n%\\end{figure}\n%\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/testScaleFree.png}\n%  \\caption{The scale-free networks seem to converge to different limit cycles.}\\label{fig:testScaleFree}\n%\\end{figure}\n%\n%\\begin{figure}[H]\n%  \\includegraphics[width=\\linewidth]{../Figures/InspectMeanFieldLogNorm.pdf}\n%  \\caption{Mean field descriptions of log-normal networks.}\\label{fig:InspectMeanFieldLogNorm}\n%\\end{figure}\n\n\n\n\\section{Fixpoint iteration}\nIn \\cite{OttAntonsen2017} a fixpoint iteration is suggested to find attractive fixpoints of the system \\eqref{eq:OttAntonsenSystemFull}. If we set $\\frac{\\partial z(\\k, t)}{\\partial t} = 0$ we can solve the following system:\n\\begin{align}\n\\ic \\frac{(z(\\k, t)-1)^{2}}{2} &= \\frac{(z(\\k, t)+1)^{2}}{2} \\cdot I(\\k) \\nonumber \\\\\n\\ic \\left(\\frac{z(\\k, t)-1}{z(\\k, t)+1}\\right)^2 &= I(\\k) \\nonumber \\\\\n\\frac{z(\\k, t)-1}{z(\\k, t)+1} &\\equiv b(\\k,t) \\nonumber \\\\\nz(\\k, t) - 1 &= b(\\k,t) z(\\k, t) + b(\\k,t)  \\nonumber \\\\\nz(\\k, t) \\cdot (1 - b(\\k,t)) &= b(\\k,t)  + 1\\nonumber\n\\end{align}\n\nWe can then obtain the stable equilibria from:\n\\begin{align}\n\\ic b(\\k,t)^2 = I(\\k) \\hspace{10mm} z(\\k, t)_{\\pm} = \\frac{1 \\pm b(\\k,t)}{1 \\mp b(\\k,t)} \\label{eq:fixedpointiterations} \n\\end{align}\nwhere the signs are chosen so that $\\vert z(\\k, t) \\vert \\leq 1$. This works.\n\n\n\\section{A Newton-Raphson iteration for all fixpoints}\n\\subsection{Theory behind the method}\nThe fixpoint iteration only gives us the stable equilibria of the system \\eqref{eq:OttAntonsenSystemFull}. We can obtain all equilibria and the Jacobian from a Newton-Raphson iteration. We define the equilibria $\\boldsymbol{x^\\ast} \\in \\R^n$ of a multivariate function $\\boldsymbol{f}(\\boldsymbol{x}) : \\R^n \\rightarrow \\R^n$ with $\\boldsymbol{f}(\\boldsymbol{x}) = \\boldsymbol{0}$. Expanding $\\boldsymbol{f}$ as a Taylor series, we obtain:\n\\begin{align}\nf_i(\\boldsymbol{x} + \\delta \\boldsymbol{x}) =f_{i}(\\boldsymbol{x}) + \\sum_{j=1}^{n} \\frac{\\partial f_{i}(\\boldsymbol{x})}{\\partial x_{j}} \\delta x_{j}+O\\left(\\delta \\boldsymbol{x}^{2}\\right) \\approx f_{i}(\\boldsymbol{x})+\\sum_{j=1}^{n} \\frac{\\partial f_{i}(\\boldsymbol{x})}{\\partial x_{j}} \\delta x_{j}, \\qquad (i=1, \\cdots, n)\n\\end{align}\n\nWe can also write this in vector notation, by setting $\\boldsymbol{J}(\\boldsymbol{x}) = \\nabla \\boldsymbol{f}(\\boldsymbol{x}) = \\frac{d}{d\\boldsymbol{x}} \\boldsymbol{f}(\\boldsymbol{x}) \\in \\R^{n \\times n}$ \n\\begin{align}\n\\boldsymbol{f}(\\boldsymbol{x}+\\delta \\boldsymbol{x}) &\\approx\\left[\\begin{array}{c}f_{1}(\\boldsymbol{x}) \\\\ \\vdots \\\\ f_{N}(\\boldsymbol{x})\\end{array}\\right] \n+ \\left[\\begin{array}{ccc}\\frac{\\partial f_{1}}{\\partial x_{1}} & \\cdots & \\frac{\\partial f_{1}}{\\partial x_{N}} \\\\ \\vdots & \\ddots & \\vdots \\\\ \\frac{\\partial f_{N}}{\\partial x_{1}} & \\cdots & \\frac{\\partial f_{N}}{\\partial x_{N}}\\end{array}\\right]\n\\left[\\begin{array}{c}\\delta x_{1} \\\\ \\vdots \\\\ \\delta x_{N}\\end{array}\\right] \n=\\boldsymbol{f}(\\boldsymbol{x})+\\boldsymbol{J}(\\boldsymbol{x}) \\delta \\boldsymbol{x} \n\\end{align}\n\nBy assuming $\\boldsymbol{f}(\\boldsymbol{x}+\\delta \\boldsymbol{x}) = 0$ we can find that $\\delta \\boldsymbol{x} = -\\boldsymbol{J}^{-1}( \\boldsymbol{x}) \\boldsymbol{f}(\\boldsymbol{x})$ so that $\\boldsymbol{x} + \\delta \\boldsymbol{x} =  \\boldsymbol{x} - \\boldsymbol{J}^{-1} (\\boldsymbol{x}) \\boldsymbol{f}(\\boldsymbol{x})$. This expression converges to $\\boldsymbol{x^\\ast}$. When the equations are nonlinear, the equations converge to the real root as $\\boldsymbol{x}_k =  \\boldsymbol{x}_k - \\boldsymbol{J}^{-1} ( \\boldsymbol{x}_k)\\boldsymbol{f}(\\boldsymbol{x}_k)$. \\\\\n\nFor \\eqref{eq:OttAntonsenSystemFull}, we can compute the Jacobian for the diagonal and off-diagonal elements separately. But as $z(\\k,t)$ is a complex function, first we need to understand what the derivative of a complex function is. \n\n\n\\subsection{Derivatives of complex functions}\nFor $z = x + \\ic y \\in \\C$ and $x,y \\in R$ the conjugate is defined as $\\overline{z} = x - \\ic y$. That means that we can write the real and imaginary parts as:\n\\begin{align*}\nx = \\frac{z + \\overline{z}}{2} \\text{  and   }   y = -\\ic \\frac{z - \\overline{z}}{2}\n\\end{align*}\nUsing the chain rule, we can write the partial derivative with respect to $z$ in function of $x$ and $y$ as $x$ and $y$ are functionally independent and find the first Wirtinger operator:\n\\begin{align*}\n\\frac{\\partial}{\\partial z} =\\frac{\\partial x}{\\partial z} \\frac{\\partial}{\\partial x}+\\frac{\\partial \\bar{y}}{\\partial z} \\frac{\\partial}{\\partial \\overline{y}} \n\\longrightarrow \\frac{\\partial x}{\\partial z} = \\frac{1}{2} \\text{   and   } \\frac{\\partial y}{\\partial z} =  - \\frac{\\ic}{2} \n\\longrightarrow \\frac{\\partial}{\\partial z} = \\frac{1}{2}\\left(\\frac{\\partial}{\\partial x} - \\ic \\frac{\\partial}{\\partial y}\\right)\n\\end{align*}\nWe note the following properties:\n\\begin{align*}\n\\frac{\\partial}{\\partial z} z = 1 \\hspace{10mm} \\frac{\\partial}{\\partial z}\\overline{z} = \\frac{1}{2}\\left(1 - \\ic^2 \\right) = 0\n\\end{align*}\nInteresting for is the result of the following: \n\\begin{align*}\n\\overline{z}^2 &= (x - \\ic y)^2 = x^2 - y^2 - \\ic 2xy \\\\\n\\frac{\\partial}{\\partial z} \\overline{z}^2 &=  \\frac{1}{2}\\cdot(2x -\\ic 2y - \\ic\\cdot(-2y -\\ic 2x)) = x -\\ic y + \\ic y -\\ic x = 0\n\\end{align*}\n\n\n\n\\subsection{Derivatives of the complex mean field equations}\nWe can now compute derivatives of the complex functions $z(\\k,t)$. We will set $z(\\k, t) = z_{\\k}$ and rewrite system \\eqref{eq:OttAntonsenSystemFull} to help the reader:\n\\begin{align}\n\\frac{\\partial z_{\\k}}{\\partial t} &= -\\ic \\frac{(z_{\\k}-1)^{2}}{2} + \\frac{(z_{\\k}+1)^{2}}{2} \\cdot I_{\\k} \\qquad z_{\\k} \\in \\C^{M_\\k} \\nonumber \\\\\n%I(\\k) &= -\\Delta(\\k) + \\ic \\eta_{0}(\\k) + i d_{n} \\kappa \\cdot H_n(\\k,t) \\label{eq:OttAntonsenSystemFull} \\\\\n%H_n(\\k,t) &= \\frac{a_n}{\\kmean} \\sum_{\\kacc} P\\left(\\kacc\\right) a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left[A_{0}+\\sum_{p=1}^{n} A_{p}\\left(z\\left(\\kacc, t\\right)^{p} + \\overline{z}\\left(\\kacc, t\\right)^{p}\\right)\\right] \nI_{\\k} &= -\\Delta_{\\k} + \\ic \\eta_{0_{\\k}} + i \\kappa \\cdot H_{2_{\\k}} \\label{eq:OttAntonsenSystemFull_k} \\\\\nH_{2_{\\k}} &= \\frac{1}{\\kmean} \\sum_{\\kacc} P_{\\k} a_{\\kacc \\k} \\cdot \\left( 1 + \\frac{z_{\\kacc}^2 + \\overline{z}_{\\kacc}^2}{6} - \\frac{4}{3} \\Re(z_{\\kacc}) \\right) \\nonumber\n\\end{align}\n\nThe diagonal elements are found as:\n\\begin{equation}\n\\begin{aligned}[b]\n\\frac{\\partial}{\\partial z_{\\k}}\\left(\\frac{\\partial z_{\\k}}{\\partial t} \\right) &= - \\ic(z_{\\k} - 1) + (z_{\\k} + 1) \\cdot I_{\\k} +  \\frac{(z_{\\k}+1)^{2}}{2} \\cdot \\frac{\\partial I(z_{\\k})}{\\partial z_{\\k}} \\\\\n\\frac{\\partial I_{\\k}}{\\partial z_{\\k}} &= \\ic \\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial z_{\\k}} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial z_{\\k}} &= \\frac{1}{\\kmean} P_{\\k} a_{\\k \\k} \\cdot \\left(\\frac{2 z_{\\k}}{6} - \\frac{4}{3} \\cdot \\frac{1}{2} \\right) = \\frac{1}{\\kmean} P_{\\k} a_{\\k \\k} \\cdot\\frac{z_{\\k} - 2}{3}\n\\end{aligned}\n\\label{eq:OttAntonsenSystemJacobianDiagonal}\n\\end{equation}\n\nThe off-diagonal elements are found as\n\\begin{equation}\n\\begin{aligned}[b]\n\\frac{\\partial}{\\partial z_{\\kacc}}\\left(\\frac{\\partial z_{\\k}}{\\partial t} \\right) &= \\frac{(z_{\\k} + 1)^{2}}{2} \\cdot \\frac{\\partial I_{\\k}}{\\partial z_{\\kacc}} \\\\\n\\frac{\\partial I_{\\k}}{\\partial z_{\\kacc}} &= \\ic \\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial z_{\\kacc}} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial z_{\\kacc}} &= \\frac{1}{\\kmean} P_{\\kacc} a_{\\kacc \\k} \\cdot \\frac{z_{\\kacc} - 2}{3}\n\\end{aligned}\n\\label{eq:OttAntonsenSystemJacobianOffDiagonal}\n\\end{equation}\n\n\n\\subsection{First results}\nI cannot seem to converge close enough.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.75\\textwidth]{../Figures/ProblemsWithNewtonRaphson.png}\n\\end{figure}\n\nThe reason that this method does not work is because the field $H_2(\\k,t)$ is non-holomorphic. We can verify this with the Cauchy-Riemann equations:\n\\begin{align*}\nz(\\k,t) &= x(\\k,t) + \\ic \\cdot y(\\k,t)\\\\\nf\\left( z(\\k,t) \\right) &= u\\left(x(\\k, t), y(\\k, t) \\right) + \\ic v\\left(x(\\k, t), y(\\k, t) \\right)\\\\\n&= \\frac{1}{\\kmean} \\sum_{\\kacc} P\\left(\\kacc\\right) a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left( 1 + \\frac{z(\\kacc, t)^2 + \\overline{z}(\\kacc, t)^2}{6} - \\frac{4}{3} \\Re(z(\\kacc, t)) \\right)\\\\\n&= \\frac{1}{\\kmean} \\sum_{\\kacc} P\\left(\\kacc\\right) a\\left(\\kacc \\rightarrow \\k\\right) \\cdot \\left( 1 + \\frac{x(\\kacc, t)^2}{3} - \\frac{4}{3} x(\\kacc, t) \\right)\n\\end{align*}\nThis leaves us with only $u$ defined as a real-valued function, so that the Cauchy-Riemann equations do not hold: the function is non-holomorphic. \n \n\\subsection{Mapping onto $\\R^2$}\n$\\bar{z}_{\\k}$ and $\\Re(z_{\\k})$ are non-holomorphic. Try again by separating the real and imaginary part: \\\\\n$z(\\k,t) = x(\\k,t) + \\ic y(\\k,t)$.\n\\begin{align*}\n\\dot{x_{\\k}} \n&=f_{\\k} \\left(x_{\\k}, y_{\\k}, \\eta_{0}, \\Delta, \\kappa \\right) \\\\ \n&=(x_{\\k}-1) y_{\\k}-\\frac{(x_{\\k}+1)^{2}-y_{\\k}^{2}}{2} \\Delta-(x_{\\k}+1) \\cdot y_{\\k} \\cdot \\left[\\eta_{0}+ \\kappa \\cdot H_{2_{\\k}}\\right] \\\\ \n\\dot{y_{\\k}} &= g_{\\k} \\left(x_{\\k}, y_{\\k}, \\eta_{0}, \\Delta, \\kappa \\right) \\\\ \n&=-\\frac{(x_{\\k}-1)^{2}-y_{\\k}^{2}}{2}-(x_{\\k}+1) y_{\\k} \\Delta+\\frac{(x_{\\k}+1)^{2}-y_{\\k}^{2}}{2} \\cdot \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] \n\\end{align*}\n\nThe Jacobian can then be found from taking the derivatives?\n\\begin{align*}\n\\frac{\\partial f_{\\k}}{\\partial x_{\\k}} &= y_{\\k}-(x_{\\k}+1) \\cdot \\Delta-y_{\\k} \\cdot \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] - (x_{\\k}+1) \\cdot y_{\\k} \\cdot \\left(\\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}}\\right)\\\\\n\\frac{\\partial f_{\\k}}{\\partial y_{\\k}} &= (x_{\\k}-1)+y_{\\k} \\cdot \\Delta-(x_{\\k}+1) \\cdot \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] \\\\\n\\frac{\\partial g_{\\k}}{\\partial x_{\\k}} &= -(x_{\\k} - 1) - y_{\\k} \\cdot \\Delta + (x_{\\k} + 1) \\cdot \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] + \\left( \\frac{(x_{\\k} + 1)^2 - y_{\\k}^2}{2} \\right) \\cdot \\left(\\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}}\\right) \\\\\n\\frac{\\partial g_{\\k}}{\\partial y_{\\k}} &= y_{\\k} - (x_{\\k} + 1)\\cdot \\Delta - y_{\\k} \\cdot \\left[\\eta_{0} + \\kappa \\cdot H_{2_{\\k}} \\right] \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\k}} &= \\frac{1}{\\langle k\\rangle} P_{\\k} a_{\\k \\k} \\cdot(x_{\\k}-2) \\cdot \\frac{2}{3} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial y_{\\k}} &= 0 \n\\end{align*}\n\nAnd the off-diagonal elements:\n\\begin{align*}\n\\frac{\\partial f_{\\k}}{\\partial x_{\\kacc}} &= - (x_{\\k}+1) \\cdot y_{\\k} \\cdot \\left(\\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}}\\right)\\\\\n\\frac{\\partial f_{\\k}}{\\partial y_{\\kacc}} &= 0 \\\\\n\\frac{\\partial g_{\\k}}{\\partial x_{\\kacc}} &= \\left( \\frac{(x_{\\k} + 1)^2 - y_{\\k}^2}{2} \\right) \\cdot \\left(\\kappa \\cdot \\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}}\\right) \\\\\n\\frac{\\partial g_{\\k}}{\\partial y_{\\kacc}} &= 0\\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial x_{\\kacc}} &= \\frac{1}{\\langle k\\rangle} P_{\\kacc} a_{\\kacc \\k} \\cdot(x_{\\kacc}-2) \\cdot \\frac{2}{3} \\\\\n\\frac{\\partial H_{2_{\\k}}}{\\partial y_{\\kacc}} &= 0\n\\end{align*}\n\nWhat dimensions does the Jacobian have now? $2 n \\times 2 n$.\n\n \n\n\n\\subsection{From the order parameter}\nWhat if we take the Jacobian straight from the OA order parameter? If $z(\\k,t) = x(\\k,t) + \\ic y(\\k,t)$:\n\\begin{align}\n\\overline{Z}(t) &= \\frac{1}{N} \\sum_{\\k} P(\\k) \\cdot \\left( x(\\k,t) + \\ic y(\\k,t) \\right) = \\frac{1}{N} \\sum_{\\k} P(\\k) x(\\k,t) + \\ic \\frac{1}{N} \\sum_{\\k} P(\\k) y(\\k,t)  \n\\end{align}\n\n\n\n\\bibliographystyle{utphys}\n\\small{\\bibliography{references}}\n\n\\label{LastPage}~\n\n\\end{document}\n", "meta": {"hexsha": "661b37ee52e8cc726393e364118d57249632e98f", "size": 19923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/Notes/MFRs.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/Notes/MFRs.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/Notes/MFRs.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": 62.259375, "max_line_length": 566, "alphanum_fraction": 0.6612457963, "num_tokens": 7545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6067378170169261}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\\usepackage[margin=0.5in]{geometry}\n\\usepackage[utf8]{inputenc}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{corollary}{Corollary}[theorem]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{definition}{Definition}[section]\n\n\\begin{document}\n\\paragraph{}Things to study:\n\\begin{itemize}\n    \\item Point.\n    \\item Distance between points.\n    \\item Line.\n    \\item Plane.\n    \\item \n\\end{itemize}\n\\section{Linear algebra}\n\\begin{definition}{(Dot).}\nis an abstract idea to represent a place on a nth dimension.\n\\end{definition}\n\\paragraph{} On one dimension we can say that a dot is an $x \\in S$ on which $S$ is a set. Similarly on the two and three dimension we have:\n$$(x,y) \\in S^{2},$$\n$$(x,y,z) \\in S^{3},$$\nIn general we will be working from now on with the real numbers: $\\mathbb{R}^n$, where $n$ is the dimension.\n\\subsection{Operations}\n\\begin{definition}{Addition (+)}\nGiven two points $P_1$ and $P_2$, we say that the addition of these two points will be equal to some other point. And it is represented as:\n$$P_1 + P_2 = P_3,$$\nalso a more general on nth dimension sum will be:\n$$(x_1, y_1, z_1, \\dots, m_1) + (x_2, y_2, z_2, \\dots, m_2) = (x_1 + x_2, y_1 + y_2, z_1 + z_2, \\dots, m_1 + m_2)$$\n\\end{definition}\n\\begin{definition}{Dot Product ($\\cdot$)}\nGiven two points $P_1$ and $P_2$, we say that the addition of these two points will be equal to some scalar k. Then\n$$P_1 = (x_1, y_1, z_1, \\dots, m_1), P_2 = (x_2, y_2, z_2, \\dots, m_2)$$\n\\begin{align*}\n    P_1 \\cdot P_2 &= P_3\\\\\n    (x_1, y_1, z_1, \\dots, m_1) \\cdot (x_2, y_2, z_2, \\dots, m_2) &=  x_1 x_2 + y_1 y_2 + z_1 z_2 + \\dots + m_1 m_2\n\\end{align*}\n\\end{definition}\n\\begin{definition}{Scalar product}\nThe scalar product is...\n\\end{definition}\n\\end{document}\n", "meta": {"hexsha": "48ce505bb758e7ae736342f269793118abb73b86", "size": 1867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LinearAlgebraFun.tex", "max_stars_repo_name": "mangel/mathbook", "max_stars_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LinearAlgebraFun.tex", "max_issues_repo_name": "mangel/mathbook", "max_issues_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LinearAlgebraFun.tex", "max_forks_repo_name": "mangel/mathbook", "max_forks_repo_head_hexsha": "9b857d3e469339c90164b00aee12c2682cd253cf", "max_forks_repo_licenses": ["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.9038461538, "max_line_length": 140, "alphanum_fraction": 0.6920192823, "num_tokens": 681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6067378119417512}}
{"text": "%\n% 150\n%\n\\chapter{Asymptotic Expansions and Summable Series}\n\n\\Section{Simple example of an asymptotic expansion.}\n\nConsider the function $f(x) = \\int_{x}^{\\infty} t^{-1} e^{x-t}\n\\dmeasure t$, where $x$ is real and positive, and the path of\nintegration is the real axis.\n\nBy repeated integrations by parts, we obtain\n$$\nf(x) = \\frac{1}{x} - \\frac{1}{x^{2}} + \\frac{2!}{x^{3}} - \\cdots +\n\\frac{ (-)^{n-1} (n-1)!}{x^{n}} + (-)^{n} n! \\int_{x}^{\\infty}\n\\frac{e^{x-t} \\dmeasure t}{t^{n+1}}.\n$$\n\nIn connexion with the function $f(x)$, we therefore consider the\nexpression\n$$\nu_{n-1} = \\frac{ (-)^{n-1} (n-1)!}{x^{n}},\n$$\nand we shall write\n$$\n\\sum_{m=0}^{n} u_{m} = \\frac{1}{x} - \\frac{1}{x^{2}} +\n\\frac{2!}{x^{3}} - \\cdots + \\frac{ (-)^{n} n!}{x^{n+1}} = S_{n}(x).\n$$\nThen we have $\\absval{u_{m}/u_{m-1}} = mx^{-1} \\rightarrow \\infty$.\n\\emph{The series $\\sum u_{m}$ is therefore divergent for all values of\n$x$}. In spite of this, however, the series can be used for the\ncalculation of $f(x)$; this can be seen in the following way.\n\nTake any fixed value for the number $n$, and calculate the value of\n$S_{n}$. We have\n$$\nf(x) - S_{n}(x) = (-)^{n+1} (n+1)! \\int_{x}^{\\infty} \\frac{e^{x-t}\n\\dmeasure t}{t^{n+2}},\n$$\nand therefore, since $e^{x-t} \\leq 1$,\n$$\n\\absval{ f(x) - S_{n}(x) } = (n+1)! \\int_{x}^{\\infty} \\frac{e^{x-t}\n\\dmeasure t}{t^{n+2}} < (n+1)! \\int_{x}^{\\infty} \\frac{\\dmeasure\nt}{t^{n+2}} = \\frac{n!}{x^{n+1}}.\n$$\nFor values of $x$ which are sufficiently large, the right-hand member\nof this equation is very small. Thus, if we take $x \\geq 2n$, we have\n$$\n\\absval{ f(x) - S_{n}(x)} < \\frac{1}{2^{n+1} n^{2}},\n$$\nwhich for large values of $n$ is very small. It follows therefore that\n\\emph{the value of the function $f(x)$ can he calculated with great\naccuracy for large values of $x$, by taking the sum of a suitable\nnumber of terms of the series $\\sum u_{m}$}.\n\nTaking even fairly small values of $x$ and $n$\n$$\nS_{5}(10) = 0.09152, \\quad 0 < f(10) - S_{5}(10) < 0.00012.\n$$\n%\n% 151\n%\n\nThe series is on this account said to be an asymptotic expansion of\nthe function $f(x)$. The precise definition of an asymptotic expansion\nwill now be given.\n\n\\Section{Definition of an asymptotic expansion.} A divergent series\n$$\nA_{0} + \\frac{A_{1}}{z} + \\frac{a_{2}}{z^{2}} + \\cdots +\n\\frac{A_{n}}{z^{n}} + \\cdots,\n$$\nin which the sum of the first $(n + 1)$ terms is $S_{n}$, is said to\nbe an \\emph{asymptotic expansion} of a function $f(z)$ for a given\nrange of values of $\\arg$, if the expression $R_{n}(z) = z^{n}[f(z) -\nS_{n}(z)]$ satisfies the condition\n$$\n\\lim_{ \\absval{z} \\rightarrow \\infty } R_{n}(z) = 0 \\quad (\\textrm{$n$\nfixed}),\n$$\neven though\n$$\n\\lim_{n \\rightarrow \\infty} \\absval{R_{n}(z)} = \\infty \\quad\n(\\textrm{$z$ fixed}).\n$$\nWhen this is the case, we can make\n$$\n\\absval{ z^{n} [f(z) - S_{n}(z)] } < \\eps,\n$$\nwhere $\\eps$ is arbitrarily small, by taking $\\absval{z}$ sufficiently\nlarge.\n\nWe denote the fact that the series is the asymptotic expansion of\n$f(z)$ by writing\n$$\nf(z) \\sim \\sum_{n=0}^{\\infty} A_{n} z^{-n}.\n$$\n\nThe definition which has just been given is due to\n\\Poincare\\footnote{TODO}. Special asymptotic expansions had, however,\nbeen discovered and used in the eighteenth century by Stirling,\nMaclaurin and Euler. Asymptotic expansions are of great importance in\nthe theory of Linear Differential Equations, and in Dynamical\nAstronomy; some applications will be given in subsequent chapters of\nthe present work.\n\nThe example discussed in \\hardsectionref{8}{1} clearly satisfies the\ndefinition just given: for, when $x$ is positive, $\\absval{x^{n} [f(x)\n- S_{n}(x)]} < n! x^{-1} \\rightarrow 0$ as $x \\rightarrow \\infty$.\n\n%\\begin{Remark} For the sake of simplicity, in this chapter we shall\nfor the most part consider asymptotic expansions only in connexion\nwith real positive values of the argument. The theory for complex\nvalues of the argument may be discussed by an extension of the\nanalysis.\n\n\\Subsection{Another example of an asymptotic expansion.} As a second\nexample, consider the function $f(x)$, represented by the series\n$$\nf(x) = \\sum_{k=1}^{\\infty} \\frac{c^{k}}{x+k},\n$$\nwhere $x > 0$ and $0 < c < 1$.\n\n%\n% 152\n%\n\nThe ratio of the $k$th term of this series to the $(k- l)$th is less\nthan $c$, and consequently the series converges for all positive\nvalues of $x$. We shall confine our attention to positive values of\n$x$. We have, when $x > k$,\n$$\n\\frac{1}{x+k} = \\frac{1}{x} - \\frac{k}{x^{2}} + \\frac{k^{2}}{x^{3}} -\n\\frac{k^{3}}{x^{4}} + \\frac{k^{4}}{x^{5}} - \\cdots.\n$$\n\nIf, therefore, it were allowable\\footnote{It is not allowable, since\n$k>x$ for all terms of the series after some definite term.} to expand\neach fraction $\\frac{1}{x+k}$ in this way, and to rearrange the series\nfor $f(x)$ in descending powers of $x$, we should obtain the formal\nseries\n$$\n\\frac{A_{1}}{x} + \\frac{A_{2}}{x^{2}} + \\cdots + \\frac{A_{n}}{x^{n}} +\n\\cdots,\n$$\nwhere\n$$\nA_{n} = (-)^{n-1} \\sum_{k=1}^{\\infty} k^{n-1} c^{k}.\n$$\nBut this procedure is not legitimate, and in fact $\\sum_{n=1}^{\\infty}\nA_{n} x^{-n}$ diverges. We can, however, shew that it is an asymptotic\nexpansion of $f(x)$.\n\nFor let\n$$\nS_{n}(x) = \\frac{A_{1}}{x} + \\frac{A_{2}}{x^{2}} + \\cdots +\n\\frac{A_{n}}{x^{n}} %TODO: verify correct subscript; book is\ninconsistent\n$$\n\nThen S\\{x)= i ('- -4 + lf + ... + izyi)\n\nk = l\\ \\ xj J x + k'\n\nso that TODO\n\nNow TODO converges for any given value of n and is equal to C, say;\nand hence fc=i\n\nTODO\n\nConsequently TODO\n\nExample. If TODO, where x is positive and the path of integration is\nthe\n\nJ X\n\nreal axis, prove that\n\nTODO\n\n[In fact, it was shewn by Stokes in 1857 that\n\nTODO\n\nthe upper or lower sign is to be taken according as TODO. ]\n%\\end{Remark}\n\\Section{Multiplication of asymptotic expansions.}\n\nWe shall now shew that two asymptotic expansions, valid for a common\nrange of values of arg', can be multiplied together in the same way\nas ordinary series, the result being a new asymptotic expansion.\n\nTODO\n\nFor let TODO\n\n%\n% 153\n%\nand let Sn\\{z) and Tn\\{z) be the sums of their first (n + 1) terms; so\nthat, n being fixed,\n\nf(z) - Sn (Z) = (Z-X <t> (Z) - Tn \\{z) = (z).\n\nThen, if C = om + iB,n-i + . . . + mo. it is obvious that*\n\nSJz)Tn\\{z)= i C,nZ--+0(z-).\n\nBut f\\{z) Cf> (Z) = \\{Sn (Z) + (Z-)] [Tn \\{z) + (-»)\\}\n\n= Sn \\{Z) Tn (Z) + (Z-)\n\nTO =\n\nThis result being true for any fixed value of n, we see that\n\nTODO\n\n\\Subsection{Integration of asymptotic expansions.}\n\nWe shall now shew that it is permissible to integrate an asymptotic\nexpansion term by term, the resulting series being the asymptotic\nexpansion of the integral of the function represented by the original\nseries.\n\nFor let TODO and let TODO.\n\nTODO\n\nThen, given any positive number e, we can find Xq such that TODO when\nx>Xo,\n\nand therefore\n\nTODO\n\nBut TODO and therefore TODO.\n\nOn the other hand, it is not in general permissible t to\ndiflFerentiate an asymptotic expansion; this may be seen by\nconsidering TODO.\n\n\\Subsection{Uniqueness of an asymptotic expansion.}\n\nA question naturally suggests itself, as to whether a given series can\nbe\n\n* See \\hardsubsectionref{2}{1}{1}; we use o (2~\") to denote any function i/- (z) such that\n3\" i/- (2) -»- as | 2, -*- x . t For a theorem concerning\ndifferentiation of asymptotic expansions representing analytic\nfunctions, see Kitt, Bull. American Math. Soc. xxiv. (1918), pp.\n225-227.\n\n%\n% 154\n%\n\nthe asymptotic expansion of several distinct functions. The answer to\nthis is in the affirmative. To shew this, we first observe that there\nare functions L \\{x) which are represented asymptotically by a series\nall of whose terms are zero, i.e. functions such that lim xL \\{x) =\nfor every fixed value of n. The\n\nTODO\n\nfunction e~ is such a function when x is positive. The asymptotic\nexpansion* of a function J\\{x) is therefore also the asymptotic\nexpansion of\n\nJ\\{x) + L(x).\n\nOn the other hand, a function cannot be represented by more than one\ndistinct asymptotic expansion over the whole of a given range of\nvalues of z; for, if\n\nTODO\n\nthen TODO\n\nwhich can only be if TODO,\n\nImportant examples of asymptotic expansions will be discussed later,\nin connexion with the Gamma-function (Chapter xii) and Bessel\nfunctions (Chapter xvii).\n\n\\Section{Methods of 'summing' series.}\n\nWe have seen that it is possible to obtain a development of the form\n\nf(x)= i A,,x~'\" + R,,\\{x),\n\nm =\n\n00\n\nwhere Rn(x)- co as ?i- > oo, and the series S) A.,nX~ does not\nconverge.\n\nm =\n\nWe now consider what meaning, if any, can be attached to the ' sum '\nof a non- convergent series. That is to say, given the numbers ao,\na, a, ..., we wish to formulate definite rules by which we can\nobtain from them a\n\nTODO\n\nnumber 8 such that S = 'S, an if 2 a converges, and such that aS'\nexists\n\nTODO\n\nwhen this series does not converge.\n\n\\Subsection{Borel's method of summation.} We have seen \\hardsubsectionref{7}{8}{1}) that\n\n00 /\"»\n\n2 anz\"\" = e-(f) (tz) dt,\n\nn=0 J\n\nwhere (tz) = X \", the equation certainly being true inside; the\ncircle\n\n00\n\nof convergence of S az'. If the integral exists at points z\noutside this circle, we define the ' Borel sum ' of S a,i2\" to mean\nthe integral.\n\n* It has been shewn that when the coefficients in the expansion\nsatisfy certain inequaUties, there is only one analytic function with\nthat asymptotic expansion. See PJiil. Trans. 213, a, (1911), pp.\n279-313.\n\nt Borel, Leo)is stir les Series Diveryentes (1901), pp. 97-115.\n\n%\n% 155\n%\n\nThus, whenever R(z)< I, the ' Bore] sum ' of the series S 2'' is\n\n»=o\n\n1 e-*e''dt = \\{l-z)-\\\n\nJ\n\nIf the ' Borel sum ' exists we say that the series is ' summable (B).'\n\n\\Subsection{Elder's* method of summation.} A method, practically due\nto Euler, is suggested by the theorem of \\hardsectionref{3}{7}l;\n\n00 00\n\nthe ' sum ' of S a,i may be defined as lim S ctn' when this limit\nexists.\n\nn=0 2:-1-0 n=0\n\nThus the ' sum ' of the series 1 - 1 + 1 - 1 + ... would be lim (1 - X\n+ cc- - ...) = lim (1 + x)~ = i.\n\n\\Subsection{Cesdro's-f method of summation.}\n\nLet Sn = «! + ao + . . . + «n; then if S = lim - (s, + Sj +    +\nn) exists, we say that S Un is 'summable (C'l),' and that its sum\n(CI) is S. It is necessary to establish the 'condition of\nconsistency;!:,' namely that S= 2 a when this series is convergent.\n\n00 n\n\nTo obtain the required result, let TODO, then we have\n\nm = l m = l\n\nto prove that TODO.\n\nGiven e, we can choose n such that\n\nso TODO\n\nThen, if i > n, we have\n\nn+p\n\n% a,\n\nm=n-rl\n\n< e for all values of p, and\n\nTODO\n\nSince TODO is a positive decreasing sequence, it follows from Abel's\ninequality \\hardsubsubsectionref{2}{3}{0}{1}) that\n\nTODO\n\nTherefore\n\nTODO\n\n* Instit. Cale. Diff. (1755). See Borel, loc. cit. Introduction, t\nBulletin des Sciences Math. (2), xiv. (1890), p. 114. + See the end of \\hardsectionref{8}{4}.\n\n%\n% 156\n%\nMaking v-x, we see that, if S be any one of the limit points (§\n2'21) of S, then\n\nn I\n\nS - % a,  e. Therefore, since | s - 5,1 ! < e, we have\n\nThis inequality being true for every positive value of e we infer, as\nin\\hardsubsectionref{2}{2}{1}, that S =s; that is to say S has the unique limit s;\nthis is the theorem which had to be proved.\n\nExample 1. Frame a definition of 'uuiforui .summability (Cl) of a\nseries of variable terms.'\n\nExample 2. TODO\n\n\\Subsubsection{TODO:Cesdrds general method of summation.}\n\nA series TODO is said to be 'summable (Cr)' if TODO exists, where\n\nIt follows from \\hardsubsectionref{8}{4}{3} example 2 that the 'condition of consistency'\nis satisfied; in fact it can be proved* that if a series is summable\n(C/) it is also summable \\{Cr) when r>r'; the condition of consistency\nis the particular case of this result when r = 0.\n\n\\Subsection{The method of summation of Rieszi.}\n\nA more extended method of ' summing ' a series than the preceding is\nby means of\n\nhm 2 ( 1 - - cin,\n\nin which X,i is any real function of n which tends to infinity with n.\nA series for which this limit exists is said to be 'summable \\{Rr)\nwith sum-function X.'\n\n\\Section{Hardy's convergence theorem.}\n\ns summable ( a,i=0(l/?i),\n\nLet S an he a series tuhick is summable \\{G 1). Then if\n\nw=l\n\nthe series TODO converges.\n\nn=\\\n\n* Bromwich, Infinite Series, § 122. t Comptes Rendus, cxlix. (1910),\npp. 18-21.\n\nX Proc. London Math. Sac. (2), viii. (1910), pp. 302-304. For the\nproof here given, we are indebted to Mr Littlewood.\n\nLet Sn = a I + a. +. + cin; then since S Un is summable \\{G 1), we\nhave\n\n%\n% 157\n%\n\nM = l\n\nSi + So+ ... + Sn = n[s + (l)j,\n\nwhere s is the sum ((71) of X «».\n\nLet TODO and let\n\nSm-s = t,a, \\{m = l, 2, ... n),\n\nti + to+ ... +tn = (Tn\n\nWith this notation, it is sufficient to shew that, if j a | < Kn~,\nwhere K is independent of n, and if On = n.o (1), then tn -> sis n ->\ncc .\n\nSuppose first that a, a, ... are real. Then, if tn does not tend\nto zero, there is some positive number h such that there are an\nunlimited number of the numbers t,i which satisfy either (i) t > h\nor (ii) tn < -h. We shall shew that either of these hypotheses implies\na contradiction. Take the former*, and choose n so that tn > h.\n\nThen, when r = 0, 1,2,\n\n< K/n.\n\nNow plot the points P,. whose coordinates are (r, tn+r) in a Cartesian\ndiagram. Since tnr+i-tn+r = an+r+i, the slope of the line PrPr+i is\nless than = arc tan (K/n).\n\nTherefore the points Pq, Pj, P.,, ... lie above the line y = h - xtan\n6. Let Pk be the last uf the points P, Pj, ... which lie on the left\nof a;'= hcot 6, so that TODO.\n\nDraw rectangles as shewn in the figure. The area of these rectangles\nexceeds the area of the triangle bounded by y = h - x tan 6 and the\naxes; that is to say\n\nTODO\n\n* The reader will see that the latter hypothesis involves a\ncontradiction by using arguments of a precisely similar character to\nthose which will be employed in dealing with the former hypothesis.\n\n%\n% 158\n%\n\nBut I (Tn+k - 0\"7i-i ! < I 0'7i+A; ! + I n-i \\\n\n= (n + k).o\\{l) + \\{n-l).o(l) = n.o\\{l), since k  hnK~, and h, K\nare independent of n.\n\nTherefore, for a set of values of n tending to infinity,\n\nh-K~n <n.o\\{l), which is impossible since h'-K~ is )iot o (1)\nas /i-> x .\n\nThis is the contradiction obtained on the hypothesis that lim tn> h >\n0; therefore Urn tn  0. Similarly, by taking the corresponding case\nin which tn - h, we arrive at the result lim tn  0. Therefore\nsince lim tn > lim tn,\n\nwe have lim t = lim tn = 0,\n\nand so tn - > 0.\n\nThat is to say Sn -> s, and so 2 a,i is convergent and its sum is s.\n\nIf an be complex, we consider R (a) and / (a) separately, and find\n\nTODO\n\nthat S R\\{an) and S /(c/) converge by the theorem just proved, and so\nTODO\n\nThe reader will see in Chapter ix that this result is of great\nimportance in the modern theory of Fourier series.\n\nCorollary. If TODO be a function of TODO such that TODO\n\nthroughout a domain of values of TODO, and if TODO, where K is\nindependent of |,\n\n2 a () converges uniformly throughoxit the domain. n=i\n\nFor, retaining the notation of the preceding section, if n() does\nnot tend to zero uniformly, we can find a positive number h\nindependent of n and | such that an infinite sequence of values of n\ncan be found for which t (») > A or i () <-h for some point\nTODO of the domain*; the value of  depends on the value of n under\nconsideration.\n\nWe then find, as in the original theorem,\n\nTODO\n\nfor a set of values of n tending to infinity. The contradiction\nimplied in the inequality shews that h does not exist, and so\nrt(|)-9-0 uniformly.\n\n* It is assumed that « () is real; the extension to complex\nvariables cau be made as in the former theorem. If no such number h\nexisted, < (|) would tend to zero uniformly.\n\nt It is essential to observe that the constants involved iu the\ninequality do not depend on |,j. For if, say, K depended on TODO\nwould really be a function of n and might be o (1) qua function of n,\nand the inequality would not imply a contradiction.\n\n%\n% 159\n%\n\nREFERENCES.\n\nH. PoiNCAR, Acta Mathematica, viii. (1886), pp. 295-344.\n\nE. BoREL, Lecons sur les Series Divergentes (Paris, 1901).\n\nT. J. Pa. Bromwich, Theory of Infinite Series (1908), Ch. xi.\n\nE. W. Barnes, Phil. Trans, of the Royal Society, 206, a (1906), pp.\n249-297.\n\nG. H. Hardy and J. E. Littlewood, Proc. London Math. Soc. (2), xi.\n(1913), pp. 1-16*.\n\nG. N. Watson, Phil. Trans, of the Royal Society, 213, a (1911), pp.\n279-313.\n\nS. Chapman +, Proc. London Math. Soc. (2), ix. (1911), pp. 369-409.\n\nMiscellaneous Examples.\n\n/\" e~ 1 2 ! 4 !\n\n:; :idt~ - ~ + - - ...\n\nwhen X is real and positive.\n\n2. Discuss the representation of the function\n\nf(x)=\\{'' <\\{t)e-dt\n\n(where x is supposed real and positive, and is a function subject to\ncertain general con- ditions) by means of the series\n\nTODO\n\nShew that in certain cases (e.g. ((;) = e'\") the series is\nabsolutely convergent, and represents TODO for large positive values\nof $x$ but that in certain other cases the series is the asymptotic\nexpansion of $f(x)$.\n\n3. Shew that\n\nfor large positive values of z.\n\nTODO\n\n(Legendre, Exerdces de Calc. Int. (1811), p. 340.) 4. Shew that if,\nwhen x>0,\n\nTODO\n\nShew also that/(.r) can be expanded into an absolutely convergent\nseries of the form\n\nTODO \\addexamplecitation{\\Schlomilch.}\n\n' ' A.=i(+l)(.r-i-2)...( + -\\}\n\n5. Shew that if the series 1+0 + 0-1+04-1 + + 0-1 + ..., in which two\nzeros precede each -1 and one zero precedes each +1, be 'summed' by\nCeskro's method, its sum is f. \\addexamplecitation{Euler, Borel.}\n\n6. Shew that the series 1-21 + 4! - ... cannot be summed by Borel's\nmethod, but the series l+0-2! + + 4! + ... can be so summed.\n\n* This paper contains many references to recent developments of the\nsubject. t A bibliography of the literature of summable series will be\nfound on p. 372 of this memoir.", "meta": {"hexsha": "99681a747823178e8b251e8207f3dbb58a7d300c", "size": 17578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch08.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-ch08.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-ch08.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.7549467275, "max_line_length": 93, "alphanum_fraction": 0.67874616, "num_tokens": 5711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370111, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.6067378078904923}}
{"text": "\\documentclass[serif,xcolor=pdftex,dvipsnames,table,hyperref={bookmarks=false,breaklinks}]{beamer}\r\n\r\n\\input{../config.tex}\r\n\r\n\\settitlecard{6}{NumPy 2}\r\n\r\n\\begin{document}\r\n\\lstset{style=custompython}\r\n\r\n\\maketitlepage\r\n%\r\n% \\section{Announcements}\r\n% \\subsection{Foo}\r\n%\r\n% \\begin{frame}[t]{Announcements}\r\n% \t\\begin{itemize}\r\n% \t\t\\item Assignment 2 is due tonight at 11:55pm.\r\n% \t\t\\item Quiz 3 will be posted tonight and due next Tuesday.\r\n% \t\t\\item Assignment 3 will go out tomorrow and will be due next Thursday.\r\n% \t\\end{itemize}\r\n% \\end{frame}\r\n\r\n\\section{Shape Manipulation and Broadcasting}\r\n\\subsection{Foo}\r\n\r\n\\begin{frame}[t,fragile]{Shape Manipulation}\r\n\t% reshape, resize, ravel, flat, T, -1 for auto reshaping\r\n\tNumPy provides various functions for changing the shape/size of an array. The most basic is \\verb|reshape| which returns an array with a new shape.\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(9)\r\n\t\t>>> A\r\n\t\tarray([0, 1, 2, 3, 4, 5, 6, 7, 8])\r\n\t\t>>> A.reshape((3,3))\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5],\r\n\t\t       [6, 7, 8]])\r\n\t\t\t   \r\n\t\t>>> A.shape = (3,3)\r\n\t\t>>> A\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5],\r\n\t\t       [6, 7, 8]])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Shape Manipulation}\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide7}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Shape Manipulation}\r\n\t% reshape, resize, ravel, flat, T, -1 for auto reshaping\r\n\tPython allows you to specify a \\textbf{single} unknown dimension using $-1$.\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(6)\r\n\t\t>>> A.\r\n\t\t>>> A.reshape((2,-1))\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5]])\r\n\t\t>>> A.reshape((-1,2))\r\n\t\tarray([[0, 1],\r\n\t\t       [2, 3],\r\n\t\t       [4, 5]])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n% \\begin{frame}[t,fragile]{Shape Manipulation}\r\n% \t% reshape, resize, ravel, flat, T, -1 for auto reshaping\r\n% \tPython allows you to specify a \\textbf{single} unknown dimension using $-1$.\r\n% \t\\pause\r\n% \t\\begin{lstlisting}\r\n% \t\t>>> A = np.arange(6)\r\n% \t\t>>> A.reshape((2,-1))\r\n% \t\tarray([[0, 1, 2],\r\n% \t\t       [3, 4, 5]])\r\n% \t\t>>> A.reshape((-1,2))\r\n% \t\tarray([[0, 1],\r\n% \t\t       [2, 3],\r\n% \t\t       [4, 5]])\r\n% \t\\end{lstlisting}\r\n% \\end{frame}\r\n\r\n% \\begin{frame}[t]{Shape Manipulation}\r\n% \t% resize\r\n% \\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Shape Manipulation}\r\n\t% reshape, resize, ravel, flat, T, -1 for auto reshaping\r\n\tOther useful functions return specific shapes:\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A.ravel()\r\n\t\tarray([0, 1, 2, 3, 4, 5])\r\n\r\n\t\t>>> A.transpose() # Also use a.T\r\n\t\tarray([[0, 3],\r\n\t\t       [1, 4],\r\n\t\t       [2, 5]])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Fancy Indexing}\r\n\t% Indexing with arrays of bools\r\n  \tNumPy arrays can be indexed with arrays of booleans. This is sometimes called \\emph{masking}.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(10)\r\n\t\t>>> B = (A%2) == 0\r\n\t\t>>> A[B] # Select all even numbers\r\n\t\tarray([0, 2, 4, 6, 8])\r\n\t\t\r\n\t\t>>> A = np.array([[0,-1],[2,3],[-3,2]])\r\n\t\t>>> A\r\n\t\tarray([[ 0, -1],\r\n\t\t       [ 2,  3],\r\n\t\t       [-3,  2]])\r\n\t\t>>> B = A.sum(1) < 0\r\n\t\t>>> A[B,:] # Select all rows whose sum is < 0\r\n\t\tarray([[ 0, -1],\r\n\t\t       [-3,  2]])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Fancy Indexing}\r\n\t% Indexing with arrays of ints\r\n\t% Q: what happens to element assignment when index list contains duplicates?\r\n  \tArrays can also be indexed using other \\textbf{integer} arrays.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = 2*np.arange(10)\r\n\t\t>>> B = np.array([1,4,5,7])\r\n\t\t>>> A[B]\r\n\t\tarray([ 2,  8, 10, 14])\r\n\t\t\r\n\t\t>>> A = np.arange(6).reshape((2,3))\r\n\t\t>>> A\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5]])\r\n\t\t>>> B = np.array([0,0,1])\r\n\t\t>>> C = np.array([1,2,2])\r\n\t\t>>> A[B,C] # One array for each dimension\r\n\t\tarray([1, 2, 5])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n% \\begin{frame}[t]{Interactive Demo}\r\n% \\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Broadcasting}\r\n\tIn most cases, when the shapes of two arrays do not match, NumPy will not let you perform elementwise operation between them.\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(6).reshape((2,3))\r\n\t\t>>> A\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5]])\r\n\t\t>>> B = np.arange(5)\r\n\t\t>>> A * B\r\n\t\tTraceback (most recent call last):\r\n\t\t  File \"<stdin>\", line 1, in <module>\r\n\t\tValueError: operands could not be broadcast together with shapes (2,3) (5,)\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Broadcasting}\r\n\tIn some special cases, NumPy will replicate one or more of the inputs so that it can perform the desired operation. This is called \\textbf{broadcasting}.\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(6).reshape((2,3))\r\n\t\t>>> A\r\n\t\tarray([[0, 1, 2],\r\n\t\t       [3, 4, 5]])\r\n\t\t>>> B = np.arange(3)\r\n\t\t>>> A * B # B is copied for each row of A\r\n\t\tarray([[ 0,  1,  4],\r\n\t\t       [ 0,  4, 10]])\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide08}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide09}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide10}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide11}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide12}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t]{Broadcasting}\r\n\t% Broadcasting 2d\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide13}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Interactive Demo}\r\n\t\\centering\r\n\t\\Huge{Interactive Demo}\r\n\t\\normalsize\r\n\t\\begin{enumerate}\r\n\t\t\\item How do you set all of the negative elements in an array to zero?\r\n\t\t\\item Recall that you can set an entire slice of an array by using indexed assignment. What happens when assign to a slice indexed by an array and there are duplicates in the \\textbf{index} array?\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item For example: \\verb|a[np.array([1,1,2])] = np.array([1,2,3])|\r\n\t\t\\end{itemize}\r\n\t\t\\item Use broadcasting to calculate the outer product of two one dimensional arrays (i.e. $A\\otimes B = AB^T$).\r\n\t\\end{enumerate}\r\n\\end{frame}\r\n\r\n% \\begin{frame}[t,fragile]{Interactive Demo}\r\n% \t\\centering\r\n% \t\\Huge{Interactive Demo}\r\n% \t\\normalsize\r\n% \t\\begin{enumerate}[<+->]\r\n% \t\t\\item How do you set all of the negative elements in an array to zero?\r\n% \t\t\\begin{itemize}[<+->]\r\n% \t\t\t\\item \\verb|A[A < 0] = 0|\r\n% \t\t\\end{itemize}\r\n% \t\t\\item Recall that you can set an entire slice of an array by using indexed assignment. What happens when assign to a slice indexed by an array and there are duplicates in the \\textbf{index} array?\r\n% \t\t\\begin{itemize}\r\n% \t\t\t\\item It will use that last index\r\n% \t\t\\end{itemize}\r\n% \t\t\\item Use broadcasting to calculate the outer product of two one dimensional arrays (i.e. $A\\otimes B = AB^T$).\r\n% \t\\end{enumerate}\r\n% \\end{frame}\r\n\t\r\n\r\n% \\begin{frame}[t]{Broadcasting}\r\n% \tExample: Broadcasting to calculate an outer product, $\\mathbf{a}\\mathbf{b}^T$.\r\n% \t\\pause\r\n% \t\\begin{lstlisting}\r\n% \t\t>>> a = np.array([1,2,3])\r\n% \t\t>>> b = np.array([4,5,6])\r\n% \t\t>>> a.reshape((3,1)) * b.reshape((1,3))\r\n% \t\tarray([[ 4,  5,  6],\r\n% \t\t       [ 8, 10, 12],\r\n% \t\t       [12, 15, 18]])\r\n% \t\\end{lstlisting}\r\n% \\end{frame}\r\n\r\n\r\n\\section{Miscellaneous NumPy}\r\n\\subsection{Foo}\r\n\r\n\\begin{frame}[t,fragile]{Reductions}\r\n\t% sum, cumprod, cumsum\r\n\tReductions compute aggregate statistics on the array. For example:\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(6).reshape((3,2))\r\n\t\t>>> A.sum()\r\n\t\t15\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Reductions}\r\n\t% sum, cumprod, cumsum\r\n\tMost reductions take an argument \\verb|axis| which allow you to specify the dimension along which the aggregation takes place.\r\n\t\r\n\t\\pause\r\n\t% picture\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide14}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Reductions}\r\n\t% sum, cumprod, cumsum\r\n\tMost reductions take an argument \\verb|axis| which allow you to specify the dimension along which the aggregation takes place.\r\n\t\r\n\t% picture\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide15}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Reductions}\r\n\t% sum, cumprod, cumsum\r\n\tMost reductions take an argument \\verb|axis| which allow you to specify the dimension along which the aggregation takes place.\r\n\t\r\n\t% picture\r\n\t\\centering\r\n\t\\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide16}.png}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Reductions}\r\n\t% sum, cumprod, cumsum\r\n\tOther common reductions are:\r\n\t\r\n\t\\pause\t\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.arange(6).reshape((3,2))\r\n\t\t>>> A.prod(axis=0)\r\n\t\tarray([ 0,  6, 20])\r\n\t\t>>> A.max(axis=1) # Also min\r\n\t\tarray([1, 3, 5])\r\n\t\t>>> A.argmax(axis=1) # Also argmin\r\n\t\tarray([1, 1, 1])\r\n\t\t>>> A.mean(axis=1)\r\n\t\tarray([ 0.5,  2.5,  4.5])\r\n\t\t>>> A.std(axis=-1) # -1 corresponds to the last dimension\r\n\t\tarray([ 0.5,  0.5,  0.5])\r\n\t\t>>> np.median(A,axis=1) # Not a member function\r\n\t\tarray([ 0.5,  2.5,  4.5])\r\n\t\\end{lstlisting}\r\n\t% picture\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Stacking}\r\n\t% hstack, vstack, column_stack, concatenate\r\n\tNumPy provides a number of functions for combining arrays.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.ones((3,4))\r\n\t\t>>> B = np.ones((3,4))\r\n\t\t>>> np.vstack((A,B)).shape # first dimension\r\n\t\t(6, 4)\r\n\t\t>>> np.hstack((A,B)).shape # second dimension\r\n\t\t(3, 8)\r\n\t\t>>> np.stack((A,B)).shape # new dimension\r\n\t\t(2, 3, 4)\r\n\t\t>>> np.concatenate((A,B),axis=0).shape # any dimension\r\n\t\t(6, 4)\r\n\t\t>>> np.concatenate((A,B),axis=1).shape # any dimension\r\n\t\t(3, 8)\r\n\t\\end{lstlisting}\r\n\t\\pause\r\n\tAnalogues to each of these functions exist for splitting arrays.\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Copy}\r\n\tBecause the contents of an array are mutable, we often need to copy the contents of an array to avoid overwriting the original.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.ones((3,4))\r\n\t\t>>> B = A\r\n\t\t>>> B is A\r\n\t\tTrue\r\n\t\t>>> B = A.copy() # Create a new copy of 'A' in memory\r\n\t\t>>> B is A\r\n\t\tFalse\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Basic Linear Algebra}\r\n\t% cross, dot, outer, svd, vdot, inv, trace\r\n\tNumPy implements many of the standard linear algebra functions:\r\n\t\r\n\t\\begin{itemize}[<+->]\r\n\t\t\\item \\verb|np.dot(A,B)|: $A^T B$\r\n\t\t\\item \\verb|np.outer(A,B)|: $A B^T$\r\n\t\t\\item \\verb|np.trace(A)|: $tr(A)$\r\n\t\t\\item \\verb|np.inv(A)|: $A^{-1}$\r\n\t\t\\item \\verb|np.svd(A)|: Singular value decomposition.\r\n\t\t\\item And many more...\r\n\t\\end{itemize}\r\n\t\t\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{File I/O}\r\n\tNumPy has two main sets of File I/O functions. \\verb|load| and \\verb|save| read and write .npy files.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> np.save(\"my_array.npy\",my_array)\r\n\t\t>>> my_array = np.load(\"my_array.npy\")\r\n\t\\end{lstlisting}\r\n\t\r\n\t\\pause\r\n\t\\verb|loadtxt| and \\verb|savetxt| read and write text files. The \\verb|delimiter| argument specifies what character will be used to separate entries and defaults to tab.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> np.savetxt(\"my_array.csv\",my_array,delimiter=',')\r\n\t\t>>> my_array = np.loadtxt(\"my_array.npy\",delimiter=',')\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{'Object' Arrays}\r\n\tIn general arrays store only a single type, however, you can create mixed type arrays by setting the data type to \\verb|object|. In python, everything an \\verb|object| so these arrays can store anything.\r\n\t\r\n\t\\pause\r\n\t\\begin{lstlisting}\r\n\t\t>>> A = np.array([1,2.0,\"string\"],dtype=object)\r\n\t\t>>> A + A\r\n\t\tarray([2, 4.0, 'stringstring'], dtype=object)\r\n\t\t>>> A / 3\r\n\t\tTraceback (most recent call last):\r\n\t\t  File \"<stdin>\", line 1, in <module>\r\n\t\tTypeError: unsupported operand type(s) for /: 'str' and 'int'\r\n\t\\end{lstlisting}\r\n\\end{frame}\r\n\r\n\\begin{frame}[t,fragile]{Interactive Demo}\r\n\t\\centering\r\n\t\\Huge{Interactive Demo}\r\n\t\\normalsize\r\n\t\\begin{enumerate}\r\n\t\t\\item What is the difference between the reductions \\verb|sum| and \\verb|cumsum|?\r\n\t\t\\item \\verb|view()| can be used in a similar way as copy, but has a slightly different effect. Try to figure out what view does.\r\n\t\\end{enumerate}\r\n\\end{frame}\r\n%\r\n%\r\n% \\section{Pandas}\r\n% \\subsection{Foo}\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "11430e981564c86d151c00522a07a3113956c63b", "size": 12494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/Lecture06/lecture.tex", "max_stars_repo_name": "royadams/intro_to_numerical_computing_with_python", "max_stars_repo_head_hexsha": "f31706f691b8a22ad8db19cdb950a0cb1df047f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-18T05:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T05:36:19.000Z", "max_issues_repo_path": "src/Lecture06/lecture.tex", "max_issues_repo_name": "royadams/intro_to_numerical_computing_with_python", "max_issues_repo_head_hexsha": "f31706f691b8a22ad8db19cdb950a0cb1df047f4", "max_issues_repo_licenses": ["MIT"], "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/Lecture06/lecture.tex", "max_forks_repo_name": "royadams/intro_to_numerical_computing_with_python", "max_forks_repo_head_hexsha": "f31706f691b8a22ad8db19cdb950a0cb1df047f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-09T20:22:57.000Z", "avg_line_length": 28.7880184332, "max_line_length": 205, "alphanum_fraction": 0.6239795102, "num_tokens": 4282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.6067378066216986}}
{"text": "\\input{structure.tex}\n\\graphicspath{{10_fig/}}\n\\title{第十章\\ 复杂性}\n\n\\begin{document}\n\n\\maketitle\n\nThere are great complexities in the science of complexity, since our world contains all kinds of complexities. In this part, we take a glance of the complexity world by a few examples.\n\n\\textbox{Complexities in simple functions}{\n    Do you understand a complex function $f(z)=z^2+C$? \n    Do you understand a real function $g(x)=R(x-x^2)$?\n    If you think you do, take a look at the following images:\n\n    \\marginnote{\\cg{0.382}{BPlt}}\n    \\cg{1.0}{MBPlt}\n\n    The 4 figures in the left are results of iteratively apply $f(z)$ (at various zoom levels) and the figure in the right is the result of iteratively apply $g(x)$. Did you realize the complexities contained in these functions?\n\n    In these figures, there is a hidden number $4.669201609\\cdots$. Can you find it out?\n}\n\n\\marginnote{\\cg{0.37}{Britain-fractal-coastline-combined}\nImage from Wikipedia, CC BY-SA 3.0}\n\\textbox{How to measure the length of a coastline?}{\n    Let's measure the coastline of Britain by a straight and rigid ruler. \n\n    The length is indicated by the first image to the left.\n\n    Let's use a shorter ruler to do the measurement again. Oh, I got a result longer than before. Even shorter ruler? Even longer results. Thanks to the fact that the world is made of atoms, which gives us a short distance cutoff. Otherwise, with infinitely short rulers, I would have measured the coastline of Britain with infinite length!\n\n    The Britain has a coastline with infinite length classically? Are you serious?\n}\n\n\\textbox{Four dimensional human beings}{\n    From scientific fictions, you may have heard of beings living in 4 dimensional space (excluding time). They are said to appear and disappear suddenly in our view as 3 dimensional beings.\n\n    Do you admire them? What if I tell you that we are actually 4 dimensional beings? Can you imagine in which sense this may be real?\n}\n\n \n\\section{Iteration: from Population of Rabbits to Chaos}\n\n\\textbox{The logistic map $R(x-x^2)$ as generations of rabbits}{\n    Let's consider models about the population of rabbits on an island after generations of self-reproduction. \n    \n    In the simplest model, the rabbits has a constant self-reproduction rate $R$, i.e. after a generation, the number of rabbits becomes $n_{k+1} = R n_k$. The number of rabbits then increase or decrease exponentially by $n_1 = R n_0, ~ n_2 = R^2 n_0, $ etc.\n\n    This model is too simple. It did not take into account that if there are too many rabbits, the lack of resource on the island will course massive death of the rabbits and thus the population would decrease. To take this into account in a simple toy model, we let\n    \\begin{align}\n        n_{k+1} = R (n_k - \\frac{n_k^2}{S} )~,\n    \\end{align}\n    where $S$ is a constant. Now the iteration equation appears to have two parameters $R$ and $S$. An equation with two parameters introduce additional complexity to study. However, without lose of generality, one can redefine $x_k \\equiv n_k/S$. Then the iteration equation for $x_k$ is\n    \\begin{align}\n        x_{k+1} = R (x_k - x_k^2)~.\n    \\end{align}\n    This stands for iteratively apply a function $g(x) = R(x-x^2)$, and calculate $g(g(g(\\ldots g(x_0)\\ldots )))$ with an initial value $x_0$. This function is known as the logistic map.\n}\n\n\\marginnote{\\cg{0.37}{logisticXk} Plots of $x_k$ for different values of $R$. The black solid curve is for $x_0=0.2$ and the red dashed curve is for $x_0 = 0.205$. The difference is minor for small $R$ but is huge for the chaotic case, indicating a sensitive initial condition dependence.}\n\\textbox{Behavior of $R(x-x^2)$ with different values of $R$}{\n    How do iterations of $x_{n+1}=R(x_n-x_n^2)$ behave at large $n$ for different $R$? One can easily write a computer program to test that. And the result for $n\\rightarrow \\infty$ is as follows:\n    \\begin{itemize}\n        \\item For $0<R<1$: $x_\\infty =0$. Because the birth rate is too low to compensate the death.\n        \\item For $1<R<3$: $x_\\infty = (R-1)/R$. This value is known as an attractor since it can be obtained from any $0<x_0<1$. To get it, assuming there is a stationary limit, and solve the equation $x_\\infty = R( x_\\infty - x_\\infty^2 )$.\n        \\item For $3<R<3.44949$: there is no unique limit $x_\\infty$. Instead, at large $k$, $x_k$ oscillates with two possible values. This can be understood as: for one generation, there are too many rabbits thus many died. The next year, there are more resources and then can support more rabbits.\n        \\item For $3.44949 < R < 3.54409$: $x_k$ oscillates with 4 possible values. This is hard to understand, but can be tested easily numerically. Further, for $3.54409 < R < 3.56407$: $x_k$ oscillates with 8 possible values; For $3.56407<R<3.56876$: $x_k$ oscillates with 16 possible values; ... When one increases $R$ a bit, the period doubles. \n        \\item For $R>3.56995$, one can no longer find oscillatory behavior. The behavior of $x_k$ at large $k$ looks random, and is exponentially sensitive to small variation in initial condition $x_0$. This behavior is known as \\emph{chaos}.\n    \\end{itemize}\n}\n\n\\textbox{The Bifurcation Plot}{\n    The plot of the logistic map is best known in the form of the below bifurcation plot. Here one clearly note the doubling of periods and eventually the emergence of chaos as $R$ increases.\n    \\marginnote{If you zoom in the bifurcation plot, you will find some self-similarities in its substructures.}\n    \\cg{0.8}{BPltFramed}\n}\n\n\\needspace{0.2\\textwidth}\n\\mtextbox{The Mandelbrot Set}{\n    For the complex function $f(z)=z^2+C$, the Mondelbrot set is a plot about how fast the sequence $f(0), f(f(0)), \\cdots$ diverges or converge. The complexities in this iteration in the complex plane of $C$ is plotted at the beginning of this part. Along the real axis, the plot has self-similarity and the period is determined by the Feigenbaum constant. The relation to the logistic map is plotted in the below figure.\n    % Image: Wikipedia released to the public domain\n    \\cg{0.7}{Verhulst-Mandelbrot-Bifurcation-Wikipedia-public-domain}\n    To study the Mandelbrot set in more details, you will find that at different parts of the Mandelbrot set, iterations converge to different number of points. This is very similar to the logistic map. Also note the self similarities in the Mandelbrot set. We will come back to self similarities later. \n    \\mnewline\n    You can find on the site \\href{https://sites.google.com/site/logicedges/}{logicedges} the zoom of the above connection and more videos about complexity.\n}\n% 恒纪元\n\\textbox{The orderly era: period doubling and the Feigenbaum constant}{\n    From the above observations, we note that the oscillation has $2^n$ possible values for a range of $R$: $R_n < R < R_{n+1}$. At large $n$:\n    \\begin{align}\n        \\delta \\equiv \\lim_{n\\rightarrow \\infty} \\frac{R_{n+1}-R_n}{R_{n+2}-R_{n+1}} = 4.669201609\\cdots ~.\n    \\end{align}\n    This number $\\delta$ is known as the Feigenbaum constant. Interestingly, the Feigenbaum constant is not only the ratio for rabbit birth rate, but rather it is a universal constant of nature. The periodicity of a broad class of non-linear behaviors has the same limiting behavior. \n}\n\n% 乱纪元\n\\textbox{The chaotic era: the classical loss of determinism}{\n    In the framework of classical mechanics, Laplace proposed that if a smart demon knows the initial position and velocity of all particles in the universe, the demon can predict the future. It is known as the Laplace's demon.\n\n    Now we know that determinism is (at least apparently) lost in quantum mechanics. Thus, Laplace's proposal does not work. However, even in the framework of classical mechanics, due to chaos, Laplace's proposal does not practically work either. This is because a tiny small error in the knowledge of the initial condition will be amplified exponentially fast in a chaotic system. As a result, it is exponentially hard to predict the future even in the classical sense.\n\n    \\tcblower\n\n    In the 1890s, Poincare studied the 3-body problem and noted that the solutions are exponentially sensitive to initial conditions. This is the starting point of the study of chaos. But for decades, his work was largely forgotten.\n\n    In 1961, Lorenz tried to use 12 nonlinear PDEs to model the change of weather. One day, he wanted to re-run a previous simulation from the middle using data printouts. However, he found that his previous calculation is not reproducible. He struggled and eventually found the reason: the result is exponentially sensitive to the initial condition. This re-discovery is the modern start for chaos study and is later known as the ``butterfly effect'': ``Hurricane formed because a butterfly flapped her wings several weeks earlier''.\n}\n\n\\section{Fractals: Dimensions Reloaded}\n\nTo understand how coastlines would have infinite classical length, let us consider a toy model, known as the Koch's snowflake. \n\n\\marginnote{\\cg{0.35}{koch_edit}}\n\\textbox{Koch's snowflake}{\n    Starting from a straight line, shrink it by $1/3$ and fold it 4 times, as the figure to the right. Do it \\emph{infinitely many times}. Then you get the Koch's snowflake. We observe a few features of the Koch's snowflake:\n    \\titem{\n        \\item The snowflake is self-similar. Take a part and zoom in, you find the same image as the original whole image. This non-trivial self-similarity is known as a fractal structure. Though coastlines do not have exact fractal structure, they have fractal-like structures that the part ``looks like'' the whole after zooming in. You can try to see this feature yourself by zooming in Google Map.\n        \\item What's the length of lines in the snowflake? Let's take the initial straight line to have length $L$. Then the first iteration of shinking-folding procedure gives a length $(4/3)L$, the second iteration gives $(4/3)^2L$, ... and the $n$-th iteration gives $(4/3)^nL$. As $n \\rightarrow \\infty $, the length diverges. Thus, the Koch's snowflake fits an line with infinite length into a finite width (and height).\n        \\item Due to the folding (roughness), the snowflake appears to have a bit of ``thickness'' if you look from far away. Thus, the snowflake appears in some sense like a two-dimensional object instead of a one-dimensional line. However, if you look infinitely close, the snowflake looks one dimensional again. What's the dimension of the slowflake?\n    }\n}\nTo study the dimension of the Koch's snowflake, let us generalize our definition of spatial dimensions.\n\\textbox{The dimension of the snowflake: Hausdorff dimension}{\n    How to formally define spatial dimensions? There are many ways. Among which one is by the scaling behavior of objects. Take a square for example, it has trivial self-similarity. Cut its length of edges by $1/2$, you get 4 self-similar squares.\n    \n    \\mtextbox{Sierpinski triangle}{\n        As another example of fractals, the below image is the Sierpinski triangle.\n        \\cg{0.8}{sierpinski}\n        When you cut edges by 1/2, you get 3 self-similar pieces. Thus $D_H = \\log 3 / \\log 2$.    \n    }\n    \\cg{0.5}{square-similar}\n    In general, if you cut its length of edges in $1/M$ intervals, and you get $N$ self-similar squares. What's the relation between $M$ and $N$? Of course, $N = M^2$, and thus\n    \\begin{align}\n        \\frac{\\log N}{\\log M} = 2~.\n    \\end{align}\n    Recall that the square is a two-dimensional object. Is this $2$ appearing at the right hand side a coincidence? You can try a 3-dimensional box, or higher dimensional objects. Soon you can be convinced that it's not a coincidence. And in general you have:\n    \\begin{align}\n        D_H \\equiv \\mbox{(dimension)} = \\frac{\\log \\mbox{(number of self-similar pieces)}}{\\log \\mbox{(number of subdivision of edges)}}~.\n    \\end{align}\n    Space dimension defined in this way is known as the Hausdorff dimension.\n    \\tcblower\n    What's the Hausdorff dimension for Koch's snowflake? Cutting the length by 1/3 and we get 4 self-similar pieces. Thus $D_H = \\log 4 / \\log 3 \\simeq 1.26$. It's an object somewhere between dimension 1 and 2. This is a mathematical way of the above argument that roughness turns into line width.\n\n    You can find a list of beautiful fractals and their Hausdorff dimensions \\href{https://en.wikipedia.org/wiki/List_of_fractals_by_Hausdorff_dimension}{on Wikipedia}.\n}\n\n\\marginnote{\\cg{0.2}{boxDim}}\n\\textbox{Coastlines and other fractal-like objects}{\n    For coastlines, there is no precise self-similarity but at best statistical self-similarity. Nevertheless, one can still count the fractal dimension by scaling properties: Draw grid lines on the map. Count how many boxes cross the coastline. And study how the number of boxes scales when we shrink the intervals between grid lines. One finds that the UK coastline has a box counting dimension of 1.25. The dimension of coastlines of Norway, Australia and South Africa are 1.52, 1.13 and 1.05, respectively. The smaller dimension, the smoother the coastlines.\n    \\tcblower\n    \\twocol{0.7}{0.1}{0.18}{Fractal-like structures are abundant in nature. For example, the fractal dimension of cauliflowers is measured to be about 2.8. This is intuitive since a cauliflower is a 3-dimensional object and has holes in it arising from fractal structures.}{\\cg{1}{cauliflowers}}\n}\n\n\\textbox{The Kleiber's Law: Metabolic rate for organisms}{\n    Let's change topic to a bit of biology. Guess what's the relation between metabolic rate and mass for organisms? Are they linearly proportional?\n\n    \\cg{0.7}{metabolic1}\n\n    \\marginnote{\\cg{0.35}{WBE} Image from West, Brown, Enquist, Science 276, 122 (1997). See also their paper on Science 284, 1677 (1999).}\n\n    Here is a plot by Hemmingsen on Reports of the Steno Memorial Hospital (1960). Interestingly, the metabolic rate scale as $M^{3/4}$. This strange power is known as the Kleiber's law. The factor 3 in $3/4$ is intuitive -- this is how mass scales with length. However, where does the factor of 4 come from? Researchers further found that the heart rate and growth rate scales as $-1/4$, and the blood circulation time and life span scales as $1/4$ of animal mass, respectively. Again, the mysterious factor of $4$ arises.\n    \\tcblower\n    In the 1990s, West, Brown and Enquist noted that fractal-like structure (such as blood vessels) is more efficient in deliver materials in the body of animals. The fractal-like structure in 3-dimension corresponds to 4 dimensions if no fractal-like structure is used. Thus, in the fractal sense, we effectively live in 4 spatial dimensions!\n}\n\n\\section{Epilogue: Summary and What's Next}\n\n\\textbox{Further reading about the content}{\n    \\titem{\n        \\item There is an excellent online course \\href{https://www.complexityexplorer.org/courses}{``Introduction to Complexity''} by Melanie Mitchell. She also has a book \\href{https://www.amazon.com/Complexity-Guided-Tour-Melanie-Mitchell/dp/0199798109}{Complexity: A Guided Tour}.\n        \\item For more formal textbooks, see, for example, \\href{https://www.amazon.com/Fractal-Geometry-Mathematical-Foundations-Applications/dp/0470848626/ref=pd_cp_b_3}{Fractal Geometry: Mathematical Foundations and Applications} by Falconer.\n        \\item Many models here can be simulated in a modeling language \\href{https://ccl.northwestern.edu/netlogo/}{``NetLogo''}. The model source code is simple and fun to read thanks to the language features provided by NetLogo.\n    }\n}\n\n\\textbox{What's next?}{\n    You may like to learn about information, emergent behaviors, networks, genetic algorithms and cellular automata in the world of complexity from the suggested further readings.\n\n    Complexity is an interdisciplinary science. You may find your next steps in how to route computer networks, how to recommend goods to customers, how brain works in life science, how birds fly in groups, how to reach a person using your social connections, how to plan the expansion of a city, how to design a algorithm for a robot, how to make more precise weather forecast, and even how a black hole absorbs matter.\n}\n\n\n\n\\printindex\n\n\\end{document}\n", "meta": {"hexsha": "ee64c52e3b7d773b01227c1bc6febb814e4220f9", "size": 16198, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10_complexity.tex", "max_stars_repo_name": "LLLgoyour/Handout", "max_stars_repo_head_hexsha": "7f44dbf8a00cdd93a191b7e63ea576a7465045af", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-11-20T18:57:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T04:35:23.000Z", "max_issues_repo_path": "10_complexity.tex", "max_issues_repo_name": "LLLgoyour/Handout", "max_issues_repo_head_hexsha": "7f44dbf8a00cdd93a191b7e63ea576a7465045af", "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": "10_complexity.tex", "max_forks_repo_name": "LLLgoyour/Handout", "max_forks_repo_head_hexsha": "7f44dbf8a00cdd93a191b7e63ea576a7465045af", "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": 86.1595744681, "max_line_length": 562, "alphanum_fraction": 0.7458945549, "num_tokens": 4165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6067378017914008}}
{"text": "\\vsssub\n\\subsubsection{~$S_{mud}$: Dissipation by viscous mud (Ng)} \\label{sec:BT9}\n\\vsssub\n\n\\opthead{BT9}{NRL/SWAN}{M. Orzech and E. Rogers}\n\n\\noindent\nTo activate viscous mud effects with the Ng routines, the user specifies\n{\\code BT9} in the switch parameter file. The Ng method computes $k_i$ as:\n\\begin{equation}\\label{eq:dmud3}\n  k_i \\approx {D_{mud}} \\equiv \\frac{\\delta_m({B_r'}+{B_i'}){k_1}^2}{sinh2{k_1}{d}+2{k_1}{d}},\n\\end{equation}\nHere, ${\\delta_m}$ is the Stokes boundary layer thickness for mud, ${d}$ is\nwater depth, and ${k_1}$ is leading order term of the real part of the\nmud-modified wave number $k_{mud}$, respectively, in a Taylor expansion about\nthe mud-water interface, and ${D_{mud}}$ is the leading order term in the full\nexpansion of $k_i$. $B'$ is a complex coefficient affecting the depth profile\nof the velocities.  For additional details, see \\para\\ref{sec:BT8} and\n\\cite{art:Ng00}.\n", "meta": {"hexsha": "251e9b7af3093060fc5e320da19cf5bae32e7704", "size": 914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WW3/manual/eqs/BT9.tex", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "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": "WW3/manual/eqs/BT9.tex", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-31T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:17:45.000Z", "max_forks_repo_path": "WW3/manual/eqs/BT9.tex", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-01T09:29:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-01T09:29:46.000Z", "avg_line_length": 45.7, "max_line_length": 94, "alphanum_fraction": 0.7242888403, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.679178692681616, "lm_q1q2_score": 0.6067167145641835}}
{"text": "%---------------------------Diagonal---------------------------\n\\section{Diagonal}\n\nThis metric is the ratio of the minimum diagonal length to the maximum diagonal length:\n\\[\nq = \\frac{D_{\\min}}{ D_{\\max}}.\n\\]\nNote that if $D_{\\max} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{diagonal}%\n{$1$}%                                        Dimension\n{$[0.65,1]$}%                                 Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[1,DBL\\_MAX]$}%                             Full range\n{$1$}%                                        Cube\n{--}%                                         Citation\n{v\\_hex\\_diagonal}%                           Verdict function name\n", "meta": {"hexsha": "f79338ac5f8ae3669420e42d056796df5acda1b0", "size": 706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexDiagonal.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/HexDiagonal.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/HexDiagonal.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.2222222222, "max_line_length": 87, "alphanum_fraction": 0.3852691218, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6066564761444545}}
{"text": "\\chapter{Humanoid Posture Generation on non-Euclidean Manifolds}\n\n\\section{abstract}\nWe present a reformulation of the posture generation problem that encompasses non-Euclidean manifolds. \nSuch a formulation allows a more elegant mathematical description of the constraints, which we exemplify through some scenarios in the simulation results section.\nIn our previous work, the posture generation problem is formulated as a non-linear optimization program with constraints expressed only through Euclidean manifolds; we solve the latter problem using on-the-shelf solvers.\nInstead, we decided to implement a new SQP solver that is most suited to non-Euclidean manifolds structural objects.\nBy doing so, we have a better mastering in the way to tune and specialize our SQP solver for robotic problems.\n\n\n\\section{Introduction}\n\\label{sec:Intro}\nComputing robot configurations to meet the requirements of a given set of tasks, within a viable state, is a recurrent problem whose complexity grows with that of the robot. In this paper, we are interested in the following generalized inverse kinematics problem: we search a configuration for which the robot fulfills tasks under constraints of joint limits, auto-collision and non-desired collision avoidance, balance, torque limits, etc. We coined it posture generation. Such a problem is encountered in both planning and control. In both cases, computation time and robustness are critical issues.\n\nWe have already proposed various implementations of the humanoid posture generation problem. All of our implementations formulate the problem as a non-linear optimization program to address multi-contact planning. In~\\cite{escande:ras:2013}, the multi-contact planner explores the contact space using thousands of HRP-2 humanoid posture generator (PG) queries; we used the FSQP solver~\\cite{cfsqp:manual}. In~\\cite{bouyarmane:ar:2012}, the PG is extended to handle various humanoid robots and multiple agents, the solver used is IPOPT~\\cite{wachter:mp:2006}. In~\\cite{vaillant:humanoids:2014} the PG is extended to various contact models and used to generate multiple related postures at once. The latter work and the DRC participation revealed that re-planning on the fly is necessary and having a robust PG is crucial in many situations. Other works also make use of PG, e.g. in~\\cite{hauser:humanoids:2005}\\cite{Aristidou2009}.\n\nPosture generation has been formulated as a problem over a Euclidean space. Robots variable may however be more naturally expressed over non-Euclidean manifolds. The archetypes for this are the rotation part of the root body for a humanoid robot, and ball joints, whose variables live in $SO(3)$. Some typical tasks are also naturally formulated on different manifolds. For example for making contact with any object that can be mapped on a sphere, the contact point position for this object can be parametrized in $S2$. Human shoulder can be elegantly parametrized on $S2\\times\\mathbb{R}$, as proposed in~\\cite{Baerlocher}.\n\n\\begin{figure}[!tb]\n\\centering\n  \\centering\n  \\setlength\\fboxsep{0pt}\n  \\setlength\\fboxrule{1pt}\n  \\fbox{\\includegraphics[width=.95\\linewidth]{papers/Humanoids2015/figure/hrp4CubeOnSphere.png}}\n\\caption{HRP-4 carrying a 2-kg cube. Left: feet on a sphere, objective function is to maintain the cube at a given position. Right: right foot free to move on the floor, objective is to put the cube as far as possible in a given direction}\n\\label{fig:hrp4_cube}\n\\end{figure}\n\nFormulating the problem over $\\mathbb{R}^n$ leads either to discontinuities that can prevent the convergence of the optimization solver, or to cumbersome writing to specify that the variable is actually living on a manifold (see~\\cite{bouyarmane:humanoids:2012}).\n\nIn this paper, we propose a new optimization solver able to work on generic smooth manifolds. We take inspiration from the approach used for unconstrained optimization on manifold~\\cite{absil:book:2008} and adapt it to constrained optimization. To the best of our knowledge, constrained optimization on manifold has drawn few research for now. This is likely due to the fact that in most problems the only constraint is to be on the manifold. We are only aware of the work of Schulman~\\emph{et al.}~\\cite{Schulman2014}, where the authors explain the adaptation of their solver to work on $SE(3)$. This adaptation is however not valid for general manifolds without more care about hessian computation.\n\nThe second contribution of this paper is a Posture Generation framework developed to ease the writing of functions, so that the user can focus on the problem formulation without having to care about the tedious bookkeeping inherent to optimization problems of this size.\n\nA background motivation for this work is to have our own optimization solver, instead of a black box. We will now be able to specialize the solver specifically to robotic problems, by leveraging modeling properties and approximations, for a gain in time and robustness. We also look forward to using this solver for problems with a varying number of constraints along the iterations (such as when complex collision constraints are considered).\n\nThe rest of the paper is organized in a classical way: we start with a bit of math to describe the foundations; then we introduce the PG~\\emph{per se}, the problem formulation followed with illustration of successful generations. \n\n\\newcommand{\\reduce}[2]{\\hspace{-#2pt} #1 \\hspace{-#2pt}}\n\n\\section{Optimization on Manifolds}\n\\label{sec:1}\nIn this section, we describe a Sequential Quadratic Programming (SQP) approach~\\cite{nocedal:book:2006} to solve the following non-linear constrained optimization program\n\n\\begin{align}\n\\label{eq:optim_problem}\n  \\minimize_{x \\in \\mathcal{M}} & \\quad f(x)\\\\\n  \\text{subject to}&\n  \\begin{array}{rcl}\n    {l} \\leq & \\reduce{c(x)}{8}& \\leq {u} \\nonumber\n  \\end{array}\n\\end{align}\n\nwhere $\\mathcal{M}$ is a $n$-dimensional smooth manifold and $c$ is a $m$-dimensional real-valued function.\n\n\\subsection{Representation problem}\nWhen $\\mathcal{M} = \\mathbb{R}^n$, the problem~(\\ref{eq:optim_problem}) is solved iteratively, starting from an initial guess $x_0$ and performing successive steps $x_{i+1} = x_i + {\\bf p_i}$ where ${\\bf p_i}$ is the increment found at the $i$-th iteration, until convergence is achieved. The strategy to compute ${\\bf p_i}$ depends on the solver.\n\nThis classical scheme cannot be readily applied to optimization over non-Euclidean manifolds. First of all, only (a subset of) the real numbers can be stored in computers. To manipulate elements of $\\mathcal{M}$ we need to choose a way to represent them in memory. This boils down to choosing a representation space $\\mathbb{E} = \\mathbb{R}^r$ (with $r \\geq n$) and a map\n\\begin{equation}\n  \\psi\\ :\\ \n  \\begin{array}{ccc}\n    x & \\reduce{\\mapsto}{6} & \\mathbf{x} \\\\\n    \\mathcal{M} & \\reduce{\\rightarrow}{6} & \\mathbb{E}\n  \\end{array} \\nonumber\n\\end{equation}\nIn the following, we identify $\\mathcal{M}$ with the set $\\psi(\\mathcal{M}) \\subseteq \\mathbb{E}$.\n\nWith this representation, it is tempting to simply transform problem~(\\ref{eq:optim_problem}) as an optimization over $\\mathbb{R}^r$ with objective $f \\circ \\psi^{-1}$ and constraint $c \\circ \\psi^{-1}$, and solve it with a usual solver. But depending on the representation choice, one of the two following problems arises:\\\\\n(i) $r=n$, then it is not possible in the general non-Euclidean case to find $\\psi$ without derivative discontinuities. This can lead to critical convergence problems, \\\\\n(ii) $r>n$, then most elements of $\\mathbb{E}$ do not represent an element of $\\mathcal{M}$ %($\\psi(\\mathcal{M})$ is a measure-zero subset of $\\mathbb{E}$) \nand $\\psi$ cannot be surjective. Constraints need to be added to force the solution on $\\mathcal{M}$. As a result, the problem has more variables and constraints w.r.t (i). Moreover, the additional constraints are unlikely to be met along the iteration process (even if $x_i$ is an element of $\\mathcal{M}$, $x_i+{\\bf p_i}$ is likely not, as nothing enforces it). This means that in order to evaluate $f \\circ \\psi^{-1}$ and $c \\circ \\psi^{-1}$ at a given $x_i$, one has to project it on $\\psi(\\mathcal{M})$ first, effectively computing $f \\circ \\psi^{-1} \\circ \\pi$ and $c \\circ \\psi^{-1} \\circ \\pi$, where $\\pi$ is the projection. The composition by $\\pi$ is an additional burden in programming (see e.g. in~\\cite{bouyarmane:humanoids:2012a}).\n\nAs a simple example, the set of 3D-rotations $SO(3)$ is a manifold of dimension $3$. The following (classical) choices can be made\n\\begin{itemize}\n  \\item Rotation matrix ${\\bf R} \\in \\mathbb{R}^{3\\times 3} \\approx \\mathbb{R}^9$, additional constraints: $\\{{\\bf R}^t{\\bf R} = I\\ ,\\ \\det({\\bf R})=1\\}$, projection by orthogonalization,\n  \\item Quaternion ${\\bf q} \\in \\mathbb{R}^4$, additional constraints: $\\{ \\left\\|{\\bf q}\\right\\|=1\\}$, projection $\\pi({\\bf x}) = {\\bf x}/\\left\\|{\\bf x}\\right\\|$,\n  \\item Euler angles ($\\mathbb{E} = \\mathbb{R}^3$), singularities when reaching gimbal lock.\n\\end{itemize}\n\n\n\\subsection{Local parametrization}\nBy definition, there is always, at a point $x$ of a smooth $n$-dimensional manifold $\\mathcal{M}$, a smooth map $\\varphi_x$ between an open set of $T_x\\mathcal{M}$, the tangent space to $\\mathcal{M}$ at $x$, and a neighborhood of $x$, with $\\varphi_x(0) = x$. $T_x\\mathcal{M}$ can be identified with $\\mathbb{R}^n$. This gives us a local parametrization for $\\mathcal{M}$. The driving idea of the optimization on manifolds is to change the parametrization at each iteration. Applying this idea, we can reformulate Problem~(\\ref{eq:optim_problem}) around $x_i$ as\n\\begin{align}\n\\label{eq:local_problem}\n\\minimize_{{\\bf z} \\in T_{x_i}\\mathcal{M}} & \\quad f \\circ \\varphi_{x_i}({\\bf z}) \\\\\n  \\text{subject to}&\n  \\begin{array}{rcl}\n    {l} \\leq & \\reduce{c \\circ \\varphi_{x_i}({\\bf z})}{8}& \\leq {b} \\nonumber\n  \\end{array}\n\\end{align} \nThis is an optimization problem on $\\mathbb{R}^n$. If we perform one iteration of a classical solver starting from ${\\bf z_0} = 0$, we get an iterate ${\\bf z_1}$, which corresponds to the iterate $x_{i+1} = \\varphi_{x_i}({\\bf z_1})$. We can then reformulate Problem~(\\ref{eq:optim_problem}) around $x_{i+1}$, perform a new iteration and repeat the process until convergence.\n\n\\begin{figure}[!htb]\n\t\\centering\n  \\includegraphics[width=.9\\linewidth]{papers/Humanoids2015/figure/manifold.pdf}\n    \\caption{There are many possible choices for $\\varphi_{x}$ but not all yield a curve $\\varphi_{x}(t{\\bf z})$ which is going in the same direction as ${\\bf z}$: $\\varphi_{1}$ and $\\varphi_{2}$ are correct choices, $\\varphi_{3}$ is not.}\n\t\\label{fig:phimap}\n\\end{figure}\n\n\nHowever, convergence cannot be achieved without care on the choice of $\\varphi_{x_i}$: it must be such that for any ${\\bf z}$, the curve $t \\mapsto \\varphi_{x_i}(tz)$ is tangent to ${\\bf z}$, see Fig.~\\ref{fig:phimap}, so that the update $x_{i+1} = \\varphi_{x_i}({\\bf z_1})$ is made in the direction given by ${\\bf z_1}$.\n\nThe exponential map is a good theoretical candidate, but it is often impractical or expensive to compute. Depending on the manifold, cheaper maps can be chosen.\n\nWith the iterative formulation approach described above, we do not have any parametrization issue, do not need additional constraints, and have the minimum number of optimization parameters. But we still need a map $\\psi$ and real space $\\mathbb{E}$ to represent the $x_i$ and keep track of them in a global way. The ${\\bf x_i}$ are guaranteed to be on $\\mathcal{M}$ so we can choose a representation with $r>n$ where $\\psi$ is singularity-free without any drawback.\nAlso, the programmer can write the function $f' = f \\circ \\psi^{-1}$ as if it was a function from $\\mathbb{E}$ to $\\mathbb{R}$ without the need to project on $\\psi(\\mathcal{M})$ first (same goes for $c' = c \\circ \\psi^{-1}$).\nFor example if $\\mathcal{M} = SO(3)$ and $\\mathbb{E} = \\mathbb{R}^{3\\times 3}$, ${\\bf x_i}$ is automatically a rotation matrix and can be used directly as such when writing the function.\n\n\\subsection{Local SQP on manifolds}\nWe choose to adopt an SQP approach to solve our problem. We first define the Lagrangian function\n\\begin{equation}\n  \\mathcal{L}_x ({\\bf z}, \\lambda) = f\\circ \\varphi_x({\\bf z}) - \\lambda^T c \\circ \\varphi_x({\\bf z})\n\\end{equation}\nwith $\\lambda \\in \\mathbb{R}^m$ the vector of Lagrange multipliers, and note $H_k$ the Hessian matrix $\\nabla_{zz}^2 \\mathcal{L}_{x_k}$. Taking ${\\bf z_0} = 0$, the first SQP step for Problem~(\\ref{eq:local_problem}) is computed by solving the following quadratic program\n\n\\begin{align}\n\t\\label{eq:SQPStep}\n  \\minimize_{\\bf z \\in \\mathbb{R}^n } & \\quad \\frac{\\partial f\\circ \\varphi_{x_k}}{\\partial {\\bf z}}(0)^T {\\bf z } + \\frac{1}{2} {\\bf z }^T H_k{\\bf z }\\\\\n  \\text{subject to}&\n  \\begin{array}{lr}\n    \\text{l} \\leq c\\circ \\varphi_{x_k}(0) + \\frac{\\partial c\\circ \\varphi_{x_k}}{\\partial {\\bf z}}(0) {\\bf z }\\leq \\text{u}\\\\\n  \\end{array} \\nonumber\n\\end{align}\n\nThe basic SQP approach adapted to manifolds can be summarized as follows\n\\begin{enumerate}\n\t\\item set $k=0$ and $x_k$ to the initial value\n  \\item compute ${\\bf z}$ from Problem~(\\ref{eq:SQPStep}) for current $x_k$\n  \\item set $x_k = \\varphi_{x_k}({\\bf z})$\n\t\\item if convergence is not yet achieved go-to step 2\n\\end{enumerate}\n\nComputations of function values and derivatives are based on the fact that $f \\circ \\varphi = f' \\circ \\psi \\circ \\varphi$ (and same for $c$), and\n\\begin{align}\n  f'\\ :\\ \n  \\begin{array}{ccc}\n    \\mathbb{E} & \\reduce{\\rightarrow}{6} & \\mathbb{R}\n  \\end{array} \\nonumber \\\\\n\t\\psi \\circ \\varphi\\ :\\ \n  \\begin{array}{ccc}\n    \\mathbb{R}^n & \\reduce{\\rightarrow}{6} & \\mathbb{E}\n  \\end{array} \\nonumber\n\\end{align}\nare representable functions. The gradient of $f \\circ \\varphi$ is \n\\begin{align}\n  \\frac{\\partial f\\circ\\varphi_x}{\\partial {\\bf z}}=\n  \\frac{\\partial f'}{\\partial y}(\\psi\\circ\\varphi_x)\\times\n  \\frac{\\partial (\\psi\\circ\\varphi_x)}{\\partial {\\bf z}}\n\\end{align}\n\n\\subsection{Practical implementation}\nThe above SQP algorithm works locally, \\emph{i.e.} when starting close enough to the solution. In practice, various possible refinements are made to ensure convergence from any starting point. We detail hereafter our choices.\n\nMaps $\\varphi_{x_i}$ are only valid locally, and we need to account for this: a step ${\\bf z}$ found by Problem~(\\ref{eq:SQPStep}) should not be outside the validity region of the map. We could enforce this by adding a constraint ${\\bf z}_{\\text{map}}^- \\leq {\\bf z} \\leq {\\bf z}_{\\text{map}}^+$ in~(\\ref{eq:SQPStep}). This leads naturally to trust region methods that we therefore favor over line-search approaches.\n\nTo know if a step ${\\bf z}$ is acceptable or not, one usually uses a penalty-based merit function. In our early tests, the update of the penalty parameters proved to be difficult with our types of problems. We now use a filter instead.\n\nOur algorithm is an adaptation of Fletcher's filter SQP~\\cite{Fletcher:mathprog:2000} to the case of manifolds: we use an adaptive trust-region that is intersected with the validity region of $\\varphi_{x_i}$, and a new iterate $x_{i+1} = \\varphi_{x_i}({\\bf z})$ is accepted if either the cost function or the sum of constraint violations is made better than for any previous iterates.\n\nAside from the manifold adaptation, our main departure from Fletcher is in the Hessian computation where we used an approximation, since the exact one is too expensive to compute in our problems. After testing several possibilities, we settled for a self-scaling damped BFGS update~\\cite{nocedal:mp:1993,nocedal:book:2006}, adapted to the manifold framework. More precisely, given the Hessian approximation $H_k$ at iteration $k$, we compute the approximation $H_{k+1}$ as follows\n\\begin{align}\n\t&s_k = \\mathcal{T}_z(z), \\quad y_k = \\nabla_z \\mathcal{L}_{x_{k+1}}(0,\\lambda_{k+1}) - \\mathcal{T}_z(\\mathcal{L}_{x_{k}}(0,\\lambda_{k})) \\nonumber\\\\\n\t&\\theta_k = \\left\\{\\begin{array}{ll} \n\t\t1 & \\mbox{if} \\; s_k^T y_k \\geq 0.2 s_k^T \\tilde{H}_k s_k \\\\\n\t\t\\frac{0.8 s_k^T \\tilde{H}_k s_k}{s_k^T \\tilde{H}_k s_k - s_k^T y_k} & \\mbox{otherwise}\n\t\\end{array}\\right. \\nonumber \\\\\n\t&r_k = \\theta_k y_k + \\left(1-\\theta_k\\right) \\tilde{H}_k s_k \\quad \\mbox{(damped update)} \\nonumber \\\\\n\t&\\tau_k = \\min\\left(1, \\frac{s_k^T r_k}{s_k^T \\tilde{H}_k s_k} \\right) \\quad \\mbox{(self-scaling)} \\nonumber \\\\\n\t&H_{k+1} = \\tau_k \\left(\\tilde{H}_k - \\frac{\\tilde{H}_k s_k s_k^T \\tilde{H}_k}{s_k^T \\tilde{H}_k s_k} \\right) + \\frac{r_k r_k^T}{s_k^T r_k} \\nonumber\n\\end{align}\nwhere $\\mathcal{T}_{\\bf z}$ is a vector transport along ${\\bf z}$ (see~\\cite{absil:book:2008}) and $\\tilde{H}_k$ is such that for ${\\bf u} \\in T_{x_{k+1}} \\mathcal{M}$, $\\tilde{H}_k {\\bf u} = \\mathcal{T}_{\\bf z}\\left(H_k \\mathcal{T}_{\\bf z}^{-1}({\\bf u}) \\right)$.\n\nDespite Powell's update, $H_{k}$ might not be positive definite (but still symmetric). We regularize it as follows: we first perform a Bunch-Kaufman factorization $P_k H_k P_k^T= L_k B_k L_k^T$ where $P_k$ is a permutation matrix, $L_k$ is unit lower triangular and $B_k$ is block diagonal with blocks of size $1 \\times 1$ or $2\\times 2$ (obtaining $B_k$ as a diagonal matrix is not numerically stable for Cholesky-like decomposition of indefinite matrices), see~\\cite{golub:book:1996}. \nThe eigenvalue decomposition $B_k = Q_k D_k Q_k^T$ is immediate and cheap to compute. From the diagonal matrix $D_k$ we form $D'_k$ such that $d'_{ii} = \\max\\left(d_{ii},\\mu_{\\min}\\right)$ where $\\mu_{\\min}>0$ is user-defined (we typically set it to $0.1$). \nDefining $L'_k = L_k Q_k (D'_k)^{1/2}$, we get a regularized matrix $H'_k = P_k^T L_k L_k^T P_k$. In our case, we use {\\tt LSSOL}~\\cite{gill:techrep:1986} for solving the QP~(\\ref{eq:SQPStep}), which directly accepts the factorized form $(P_k, L'_k)$. This avoids an internal Cholesky factorization so that our regularization does not add too much time to the overall process of building and solving the QP.\n\nThe code for $\\psi\\circ\\varphi$, its gradient and the vector transport needs only to be implemented once for each elementary manifold (it is then trivial to get those functions for Cartesian products of manifolds). The composition with $f'$ and $c'$ is done automatically. The expression of those functions is adapted from~\\cite{boumal:jmlr:2014}.\n\n\\section{Posture Generation, variables and architecture}\n\\label{sec:2}\n\nWriting a posture generation problem can easily become cumbersome without the appropriate tools. \nCommon pitfalls are for example writing the derivative of a function, managing how the Jacobian matrices of the already implemented functions are modified when a variable is added to the problem, adding a new type of constraint, or correctly writing a function on a sub-manifold of the problem manifold. \nA fair amount of bookkeeping is always necessary, which should not be the charge of the user writing the constraints.\nIn our PG, we propose an architecture automating most of the problematic tasks, so that the user can focus on the mathematical formulation of the problem.\n%\\begin{itemize}\n  %\\item A system of geometrical and mathematical expression trees that automatically computes the mathematical expressions behind geometric relations\n  %\\item An automatic mapping between the submanifold of each function and the global manifold of the problem\n  %\\item A problem generator that aggregates all the informations from the abovementionned items to generate a problem that can be passed to the solver\n%\\end{itemize}\n\n\\subsection{Geometric expressions}\n\nMost constraints are geometric.\nIn order to simplify the writing of functions, we use a dedicated system of expression graph encapsulated in a set of geometric objects.\nThe main idea is to separate the purely mathematical logic from the geometric one. As an example if $P_r$ and $V_r$ are a point and a vector attached to the camera of the robot, and $P_e$ is a fixed point in the environment, the constraint $(P_e - P_r).V_r = 0$ can be used to have the robot look at $P_e$. With our system, the user creates only those objects and write the code {\\tt (Pe-Pr).dot(Vr)} to get the value needed. The geometric layer takes care that all the quantities are expressed in the correct frame, the mathematical layer performs the corresponding operations. If $q$ is a variable object, {\\tt (Pe-Pr).dot(Vr).diff(q)} returns automatically the differential of the expression w.r.t. $q$. This makes the writing of the constraints very easy.\n\nAt the mathematical level, we consider 5 types of expressions which can be either variables or constants:\n\\begin{itemize}\n  \\item Scalar, a 1-dimensional element of $\\mathbb{R}$\n  \\item Coordinates, a 3-dimensional element of $\\mathbb{R}^3$\n  \\item Rotation, a $3\\times3$ matrix representing a 3D rotation\n  \\item Transformation, a $4\\times4$ matrix representation of a 3D isometry\n  \\item Array, a dynamic size array\n\\end{itemize}\nThe meaningful unary (inverse, opposite, norm...) and binary (multiplication, addition, subtraction, dot product...) operations (with their derivatives by chain rule) are implemented.\nWe also have a Function class for more complicated expressions, for example expressing $q \\mapsto T_i(q)$ where $T_i$ is the transformation between the reference frame of the robot and the frame of its $i$-th body \\footnote{The kinematics of rigid body systems is handled by the RBDyn library (\\url{https://github.com/jorisv/RBDyn})}. \nThe combinations of those elementary operations defines a computation graph.%, just like in many symbolic calculation frameworks.\n\nThe geometric layer consists of physical or geometric objects, named features, which exist independently of their mathematical expression in a given reference frame. We have so far 4 objects:\n\\begin{itemize}\n  \\item A Frame, defined by a Transformation expression and a reference frame. \n  \\item A Point and a Vector, defined by a Coordinates expression and a reference frame. \n  \\item A Wrench, defined by a pair of Coordinates expressions and a reference frame.\n\\end{itemize}\nWe have a special World Frame object to serve as starting reference frame. \n\nFor each feature, one can get its expression in a given frame.\nBasic operations are defined between those features (when applicable). For example, the subtraction between two Points gives a Vector. The geometric logic resides in the change of frame and those operations.\n\n%Based on that expression system, the robot can simply be represented as a function that keeps track and updates the transformations of the frames of all its bodies, with respect to an Array expression on entry, the articular parameters.\n%For a given articular parameter array, the user can query the frame of any body on the robot, and by composition, the user can query any feature defined on a frame of the robot, as well as its derivatives.\n%This tools allows for a very simplified writting of robotics constraints as a combination of operations on geometric features, without worrying about the vectors and matrix beneath and without having to write the derivatives.\n\n\\subsection{Automatic mapping}\n\nThe manifold $\\mathcal{M}$, on which the optimization takes place, is a Cartesian product of several sub-manifolds. Same goes for their representation spaces:\n\\begin{equation}\n  \\begin{split}\n    \\mathcal{M} = \\mathcal{M}_1\\times\\mathcal{M}_2\\times\\mathcal{M}_3\\times\\hdots\\\\\n    \\mathbb{E} = \\mathbb{E}_1\\times\\mathbb{E}_2\\times\\mathbb{E}_3\\times\\hdots\n  \\end{split}\n\\end{equation}\nFrom the solver's viewpoint, the entry space of each function is the complete manifold.\nBut for the developer, writing a function on the complete $\\mathbb{E}$ is cumbersome because (i) of the need to manage indexes, and (ii) when the function is implemented, the complete $\\mathbb{E}$ may not be known.\nA user-written function $f$ is usually defined on a subset of $\\mathbb{E}$, say $\\mathbb{E}_I=\\mathbb{E}_i\\times\\mathbb{E}_j\\times\\mathbb{E}_k\\hdots$, that is minimalist for that function, and should not account for unrelated manifolds. One does not want to think about the values of the forces when writing a geometric constraint for example.\nOur automatic mapping tool %keeps track of all the necessary mappings for each function added and upon the instantiation of the problem, \ngenerates the correct projection functions $\\pi_I$ such that the developer can write a function $f$ on $\\mathbb{E}_I$ while the solver receives it as a function $f \\circ \\pi_I$ on $\\mathbb{E}$. This idea is illustrated by the example in Fig.~\\ref{fig:auto_map}\n%\\begin{equation}\n  %\\begin{split}\n  %\\pi_I:\\mathbb{E}\\to\\mathbb{E}_I\\\\\n  %f:\\mathbb{E}_I\\to\\mathbb{R}\\\\\n  %f\\circ\\pi_I:\\mathbb{E}\\to\\mathbb{R}\n  %\\end{split}\n%\\end{equation}\n\n\\begin{figure}[!htb]\n\\centering\n  \\centering\n  \\setlength\\fboxsep{0pt}\n  \\includegraphics[width=.7\\linewidth]{papers/Humanoids2015/figure/auto_mapping_text.pdf}\n\\caption{automatic variable mapping}\n\\label{fig:auto_map}\n\\end{figure}\n\n\\subsection{Problem Generator}\n\nThe problem generator is the tool constructing the optimization problem.\nIt registers all the variables and the functions related to a given problem.\nEach function is likely to bring additional variables with it.\nFor each contact contributing to the balance, a variable on $\\mathbb{R}^3$ representing the contact force is added to the problem.\nThe associated wrench is added to the stability constraints.\nOnce the registration is complete, the complete manifold of the problem is generated and uses the information of the Automatic mapping to ``plug\" each function with the correct sub-manifold.\nSubsequently, the optimization problem can be generated and passed to the solver.\nThe communication between the solver and the generated problem is made through the RobOptim framework\\footnote{\\url{http://www.roboptim.net/}}.% ~\\cite{moulard:jsme:2013, moulard:jrsj:2014}.\n\n\\section{Problem formulations}\n\\label{sec:3}\nLet $q=[q_F^T; q_r^T]\\in\\mathbb{R}^3\\times SO(3)\\times \\mathcal{M}_r$ be the combination of the free-flyer of the robot $q_F\\in \\mathbb{R}^3 \\times SO(3)$ and the articular parameters $q_r\\in\\mathcal{M}_r$.\nLet $\\mathcal{W}_i(p)=\\{f_i,m_i(p)\\}$ be the wrench (force+moment) applied by the environment onto the robot at contact $i$ and expressed on point $p$.\nA frame $F$ is composed of a reference point and an orthonormal basis of 3 vectors $F = \\{O, (x, y, z)\\}$.\n\nHere is a list of constraints that we consider in our problem (implementation of other ones is on-going):\n\\begin{itemize}\n\\item Joint limits ${q^-} \\leq q_r \\leq {q^+}$:\\\\\nThese cannot be directly translated on manifolds other than $\\mathbb{R}^n$. For example, spherical joints can be parametrized on $S2 \\times \\mathbb{R}$, then the $S2$ part can be limited by a cone, and the $\\mathbb{R}$ part can have real bounds. \n\\item The contact constraint consists in identifying the features of two frames $F_1$ and $F_2$. For example, for a planar contact, we get the set of equation~\\ref{eq:planar_contact}.\n\n\\begin{equation}\n  \\begin{split}\n    (O_2-O_1).z_1 = 0\\\\\n    z_2.z_1 \\leq 0 \\\\\n    z_2.x_1 = 0 \\\\\n    z_2.y_1 = 0\n  \\end{split}\n  \\label{eq:planar_contact}\n\\end{equation}\n\nNote that on $F_2$ only the point $O_2$ and the vector $z_2$ are necessary.\nOther types of contacts can be created that way, by equalizing other features, as explained in \\cite{escande:ras:2013}.\n\n\\item The stability constraint ensures that the Euler-Newton equation~(\\ref{eq:NewtonWrench}) is balanced for the set of external wrenches applied to the robot (gravity $\\mathcal{W}_G$ and contact forces $\\mathcal{W}_i$).\n  \\begin{equation}\n    \\sum_{i}{\\mathcal{W}_i(p)} + {\\mathcal{W}_G(p)} = 0\n    \\label{eq:NewtonWrench}\n  \\end{equation}\n  For each contact that bears forces (\"stability\" contact), a wrench applied on the robot at the contact point is added to the problem.\n  That wrench is parametrized on a subset of $\\mathbb{R}^6$ depending on the type of contact.\n  For punctual contacts, the moment part is null on the application point.\n  Only a parametrization of the force part on $\\mathbb{R}^3$ is needed.\n  We model planar contacts as a combination of punctual forces applied at each vertex of the contact polygon.\n  In the case of interaction forces between 2 robots, only one wrench is created and it is used as is in the stability equation of one robot and its opposite is used for the stability of the second robot.\n\n\\item The friction cone constraint limits the tangential part of every forces to avoid slippage. We write it as~\\ref{eq:friction} (with $\\mu$ the friction coefficient)\n\\begin{equation}\n  \\begin{split}\n    \\mu^2f_z^2-f_x^2-f_y^2 \\geq 0 \\\\\n    f_z \\geq 0\n  \\end{split}\n  \\label{eq:friction}\n\\end{equation}\n\\end{itemize}\n\nThe frame in which the constraints are written matters critically.\nMost often, the frame's configuration depends on a part of the optimization variables, that must be accounted for in computing the constraints' Jacobian.\nOur framework computes such dependencies automatically.\n\nOur current PG (i.e. coding state) does not include yet collisions and auto-collisions, nor torque limits. Their implementation is on-going and is simply the matter of coding time.\nAnother important part is its cost function.\nWe only mention the cost function that have specificities when dealing with manifolds, the distance to a reference posture $q_0$.\nOn a robot that has all its articulations parametrized on $\\mathbb{R}$ the distance can be expressed simply with the Euclidean norm $d = \\norm{q_j-q_0}^2$.\nSince we work on non-Euclidean manifolds, the logarithm function on the manifold must be used. It gives the distance vector between two points in the tangent space, the norm of this vector can be used as a distance.\nSo we get $d = \\norm{\\text{log}_{q_0}(q_r)}^2$.\n\n\n%FROM HERE IT IS OLD TEXT\n\n%There can be several kinds of contact between a surface of the robot and its environment(which could contain other robots).\n%We denote $\\mathcal{S}_R$ and $\\mathcal{S}_E$ the two surfaces belonging to two bodies $\\mathcal{B}_R$, $\\mathcal{B}_E$ that are to be put in contact.\n%We equip those surfaces with a frame $\\mathcal{F} = \\{O, (x, y, z)\\}$, with $O$ a point of contact on the surface, and $z$ a vector normal to the surface at $O$.\n%The transformation that leads from the reference frame of a body $\\mathcal{B}$ to the reference frame of a surface $\\mathcal{S}$ is denoted $^\\mathcal{S}H_\\mathcal{B}$.\n%Note that those two surfaces do not need to be plane, a curved continous surface would suit as well.\n%For a contact to be geometricaly satisfied, the planes defined by $\\{O, (x, y)\\}$ on both surfaces must be coplanar with normals of opposite directions.\n%This can be assured by satisfying the following set of equation:\n\n%\\begin{align}\n  %\\begin{split}\n  %(O_R-O_E) . z_E = 0 \\\\\n  %z_R . x_E = 0 \\\\\n  %z_R . y_E = 0 \\\\\n  %z_R . z_E \\leq 0\n  %\\end{split}\n  %\\label{eq:floating contact}\n%\\end{align}\n\n%If any(either or both) of the two surfaces in contact is non-plane, finding the exact location of the contact point on the surface is necessary, because then, the normal to the contact is not known in advance.\n%In that situation, we propose to paramaterize the contact frame on the surface on a 1 or 2-dimentional manifold.\n%\\begin{equation}\n  %\\mathcal{F}(u_S\\in \\mathcal{M}_S) = \\{O(u_S), (x(u_S), y(u_S), z(u_S)\\}\n%\\end{equation}\n%Which, depending on the shape, could be $\\mathbb{R}^2$ or $S2$.\n%In that case, an additional set of variables $u_S\\in \\mathcal{M}_S$ is added to the optimization problem as well as the constraint set \\ref{eq:floating contact} depending on it.\n\n%The floating contact constraint can be extended to fix the contact to a given position and orientation by adding to it the following set of equation that locks the degrees of freedom of rotation around the normal and translation in the tangent plane of the contact:\n\n%\\begin{align}\n  %\\begin{split}\n  %(O_R-O_E) . x_E = 0 \\\\\n  %(O_R-O_E) . y_E = 0 \\\\\n  %y_R . x_E = 0 \\\\\n  %x_R . y_E = 0\n  %\\end{split}\n  %\\label{eq:fix planar contact}\n%\\end{align}\n\n%Those two sets of equations \\ref{eq:floating contact} and \\ref{eq:fix planar contact} can easily be recombined to generate other types of constraints(e.g. fixing only the translation, or only the rotations...).\n\n%For any scenario to be realistic, the robot must satisfy its stability constraint. Given a set of wrenches applied on the robot $\\{\\mathcal{W}_0, \\mathcal{W}_1...,\\mathcal{W}_{n_w}\\}$.\n%The sum of all those wrenches applied on a singular point must be zero.\n%For each punctual contact that needs to bear forces, a new wrench is created, that wrench is parametrized by a set of two vectors describing its force $f = (f_x, f_y, f_z)^T \\in \\mathbb{R}^3$ and moment $m = (m_x, m_y, m_z)^T \\in \\mathbb{R}^3$ at the contact point.\n%We denode $\\mathcal{W}_G$ the wrench generated by the weight of the robot: $\\mathcal{W}_G(CoM) = \\{(0, 0, -mg)^T, (0, 0, 0)^T\\}$. For any chosen reduction point $p$, the stability constraint writes as follows:\n\n%\\begin{equation}\n  %\\sum_{i=0}^{n_w}{\\mathcal{W}_i(p)} + {\\mathcal{W}_G(p)} = 0\n  %\\label{eq:NewtonWrench}\n%\\end{equation}\n\n%Equation \\ref{eq:NewtonWrench} can be rewritten with only vectors as:\n\n%\\begin{equation}\n  %\\begin{split}\n  %\\sum_{i=0}^{n_w}{f_i} - m g = 0 \\\\\n  %\\sum_{i=0}^{n_w}{m_i(p)} + {m_G(p)} = 0\n  %\\end{split}\n  %\\label{eq:NewtonForceMoment}\n%\\end{equation}\n\n%A usual choice of reduction point for those equations is the center of mass of the robot. In which case the moment part of the gravity wrench is null.\n%In the case of surfacic contact between two plane surfaces, the contact polygon is determined and a punctual force with zero moment is added on each vertex.\n%The forces generated on each point need to satisfy the Coulomb friction cone equations which writes as follows for a friction coefficient $c$:\n\n%\\begin{equation}\n  %\\begin{split}\n    %c^2 f_z^2 - f_x^2 - f_y^2 \\geq 0 \\\\\n    %f_z \\geq 0\n  %\\end{split}\n  %\\label{eq:FrictionCone}\n%\\end{equation}\n\n%It is not straightforward to devise a friction limit in terms of moment.\n%Which is why, in the current study, we considere that the punctual contacts are perfect and do not generate moment on their application point.\n%This translates in fixing the moment variables of the wrench to zero while the force variables still exist.\n%In the case of planar contacts, of course, the moment part cannot be ignored.\n%But, given a planar polygon in which the contact happens, the wrench generated by this contact can be modeled as a set of punctual forces, one on each vertex of the polygon. Which respect the same friction cone equations \\ref{eq:FrictionCone} and are taken into account in \\ref{eq:NewtonWrench}.\n\n\\section{Simulation Results}\n\\label{sec:4}\nHere, we present several posture generation problems resolution that leverage the specific capabilities of our software.\n\n\\begin{figure*}\n\\centering\n  \\centering\n  \\setlength\\fboxsep{0pt}\n  \\setlength\\fboxrule{1pt}\n  \\fbox{\\includegraphics[width=\\textwidth]{papers/Humanoids2015/figure/4directionsStrokesWithCoM.png}}\n  %\\fbox{\\includegraphics[width=.95\\linewidth]{papers/Humanoids2015/figure/contact_plan_sphere_4_directions.png}}}\n  \\caption{HRP2-Kai leaning on sphere with right wrist to point the left gripper as far as possible in 4 cardinal directions. Top row: semi-predefined contact; Bottom row: free contact with parametrized wrist. Projection of the CoM on the ground (green dots)}\n\\label{fig:contact_plan_sphere}\n\\end{figure*}\n\n\\subsection{Application to plan-sphere contact}\nWhen we consider a planar contact, having a frame $F_{S}$ fixed in reference to $F_{B}$ is sufficient because the equations describing that contact are invariant w.r.t. the point's location.\nBut for different contact topologies, the location of the contact point in the body's frame $F_{B}$ matters.\nWe propose to parametrize the location and normal of the contact point with an additional variable.\n\nWe consider the contact between a body's flat surface $S_B$ of normal $n_B$, with the surface of a sphere $S_s$ of center $c_s$, radius $r_s$, and let $p_s$ and $n_s$ be a point and its normal to $S_S$.\nThe most general way to express such a constraint is to ensure that $p_s$ is on $S_B$ and that $n_s$ and $n_B$ are opposite.\nThis means creating a variable $v_{S2}$ on the manifold $S2$ and map $p_S$ and $n_S$ on it.\nIn our framework, this constraint is expressed exactly as the contact between 2 planar surfaces, once the mappings of $p_s(v_{S2})$ and $n_s(v_{S2})$ are done.\nIn a framework that does not handle manifolds (as we do), it would require to setup a specific constraint, ensuring that the distance between $c_s$ and $S_B$ is equal to $r_S$.\n\nIn Fig.~\\ref{fig:contact_plan_sphere} we show the results obtained by solving a problem where the HRP2-Kai robot has to keep its feet in contact with the ground at fixed positions, touch a sphere with a side of its right wrist and point as far as possible in a given direction $d$ with its left hand, under balance constraints.\nThe top row of Fig.~\\ref{fig:contact_plan_sphere} shows the results for this problem with several different $d$.\n%It shows that our optimization algorithm finds an optimal contact point on the sphere to reach its goal as best as possible while satisfying the given constraints.\nIn every situation, the projection of the CoM is outside the polygon of support, meaning that such postures would not be reached without leaning on the sphere.\n\n\\subsection{Contact with parametrized wrist}\n\n\\begin{figure}[!htb]\n\\centering\n  \\centering\n  \\setlength\\fboxsep{0pt}\n  \\setlength\\fboxrule{1pt}\n  \\fbox{\\includegraphics[width=.95\\linewidth]{papers/Humanoids2015/figure/param_wrist_detail.pdf}}\n\t%\\fbox{\\includegraphics[width=.95\\linewidth]{papers/Humanoids2015/figure/param_wrist_detail.png}}\n\\caption{Parametrization of the wrist of HRP2-Kai}\n\\label{fig:param_wrist_detail}\n\\end{figure}\n\nBeing able to choose the location of the contact point on the sphere is interesting, but a limitation of this formulation is that the contact point on the wrist of the robot is restricted to one single user-defined face.\nInstead, we describe the shape of the wrist body as a parametric function and let the contact point on the wrist as well as its counterpart on the sphere, result from the optimization process.\nThe section of HRP2-Kai's wrist is a square with rounded edges.\nWe parametrize this shape as shown in Fig.~\\ref{fig:param_wrist_detail}:\nwe consider the angular coordinate $\\theta$ of the point on the section. It is added as a variable to the problem.\nThe shape of a quarter of section $[0;\\pi/2]$ is a succession of a vertical line, a quarter of circle and a horizontal line.\nThis pattern is repeated for the 3 other quarters.\nThe equations are given in Fig.~\\ref{fig:param_wrist_detail}.\nIn our framework, we define the function describing the shape of the wrist, create a frame parametrized by that function and then define the contact between that frame and the point and normal on the sphere.\nThis formulation not only is very easy to implement, but most importantly, allows for richer posture generations.\nThe optimization algorithm chooses the contact point on the sphere as well as the contact point on the wrist, which leads to a wider accessibility range, and a better satisfaction of the cost function.\nThe bottom row of Fig.~\\ref{fig:contact_plan_sphere} displays the results of this simulation for the robot pointing in 4 directions.\nNotice that on the 2nd and the 4th (pointing forward and to the left) images, the results for the 2 types of models are nearly identical.\nWhereas in the 1st and 3rd images, different faces of the wrist have been chosen(On the 1st, the wrist is rotated by $180^{\\circ}$, and $90^{\\circ}$) on the 3rd).\nIn these 4 cases, the contact with parametrized wrist gives a better cost of the objective function.\nThis observation scales:\nwe solved this problem for 5000 random pointing directions, and in average, the contact with parametrized wrist allows to reach 5mm further.\nThe success rate of the solver is $98.5\\%$ in the parametrized wrist case against $99.9\\%$ when the face is fixed. The numbers of iterations are similar.\n\n%Also, that kind of formulation makes it easier for the user to generate satisfactory postures, as he does not need to specify the plan contact surface anymore.\nThis method is certainly scalable, and can be used for any kind of humanoid robot and environment.\nYet, it requires to have a parametric equation of the surface.\nWe plan to implement a method to generate a parametrized surface point and its normal directly from the 3D mesh of an object.\nThe accompanying video shows the optimization process for the problem with parametrized wrist. Notice on the video that the contact point on the wrist changes sides all along the iterations.\n\n\\subsection{Contact with an object parametrized on $S2$}\n\nIn this simulation case, we want the HRP-4 robot (anther model) to carry a cube with its two hands.\nThe most general way to do it is to select a face of the cube for each contact, and enforce the contact between that face and the hand's surface.\nWe propose to approximate the cube with a superellipsoid and to parametrize the resulting shape on $S2$.\nThe implicit equation of a superellipsoid is $S(x,y,z) = 0$, with\n\\begin{equation}\n  S(x,y,z) = \\left( \\left|\\frac{x}{A}\\right|^r + \\left|\\frac{y}{B}\\right|^r\\right)^\\frac{t}{r} + \\left|\\frac{z}{C}\\right|^t - 1\n  \\label{eq:super_ellipsoid}\n\\end{equation}\n\nA point in $S2$ is represented by a vector $v=(x,y,z)$ in $\\mathbb{E} = \\mathbb{R}^3$. To a given unit vector $v$ we associate a point $\\alpha v$ on the surface of the superellipsoid by solving $S(\\alpha v) = 0$ for $\\alpha$. At this point, the normal is given by $\\dfrac{\\nabla S(\\alpha v)}{\\left\\|\\nabla S(\\alpha v)\\right\\|}$ which simplifies into $\\dfrac{\\nabla S(v)}{\\left\\|\\nabla S(v)\\right\\|}$.\n%It returns the intersection between any unit vector and the surface of the super ellipsoid.\n%Also we generate a similar function that returns the normal of the intersection point.\nGiven this parametrization, we write a contact constraint between the frame of the hand of the robot and the point and normal on the surface of the superellipsoid.\n\nIn Fig.~\\ref{fig:hrp4_cube} we present some results for a posture generation problem with manipulation: On the left side, the feet are free to move on a sphere, and, on the right side, the left foot position is fixed and the right foot is free to move on the ground. The hands must be in contact with the cube. The cube is free to move (parametrized by $\\mathbb{R}^3 \\times SO(3)$) and has it own set of Euler-Newton equations, which must be fulfilled.\nOn the accompanying video, one can observe how the contact points on the cube evolve along with the optimization.\n%For each contact with the cube, a variable on $S2$ is added to the problem to parametrize the contact point.\n%Each hand is in contact with a point and normal on the cube.\n\n%\\begin{figure}\n%\\centering\n  %\\centering\n  %\\setlength\\fboxsep{0pt}\n  %\\setlength\\fboxrule{1pt}\n  %\\fbox{\\includegraphics[width=.99\\linewidth]{papers/Humanoids2015/figure/hrp4CubeOnSphere.png}}\n%\\caption{HRP4 carrying 2kg a cube. Left: the objective function is to maintain the cube at a given position. Right: it is to put the cube as far as possible in a given direction}\n%\\label{fig:hrp4_cube}\n%\\end{figure}\n\n\\subsection{Posture Generation with a human model}\n\n\\begin{figure}\n\\centering\n  \\centering\n  \\setlength\\fboxsep{0pt}\n  \\setlength\\fboxrule{1pt}\n  \\fbox{\\includegraphics[width=.7\\linewidth]{papers/Humanoids2015/figure/cropped_human.png}}\n\\caption{Posture generation for a human avatar}\n\\label{fig:pg_human}\n\\end{figure}\n\nThe geometric model of a human is much more complex than the one of a humanoid robot in terms of topology.\nEven with the simplest models, the shoulders, wrists, ankles, or hips need to be described as spherical joints, and therefore be parameterized on $SO(3)$.\nWe showcase that our solver is able to handle such complex models as a human avatar in Fig.~\\ref{fig:pg_human}.\nOur human model has spherical joints on its wrists, shoulders, torso, hips and ankles.\nWith the addition to the free-flyer, the manifold that contains the articular space of that human model is:\n$\\mathcal{M}_H = SO(3)\\times\\mathbb{R}^3\\times \\left(SO(3)\\right)^9\\times\\mathbb{R}^4$.\nWe fixed the neck's joints as well as the fingers to avoid unnecessary variables.\nIn this simulation, we require the human to stand on an inclined slope while leaning on the left side's wall.\nSince we have not yet implemented the boundary limits on spherical joints, the model could reach non desired configurations.\nThat issue limits for the time being the number of scenarios that we can solve.\nBut the use of a cost function on the posture of type $d = \\norm{\\text{log}_{q_0}(q_j)}^2$, attracting the avatar to a basic standing posture, allowed us to have acceptable results.\n\n\\section{Discussion and conclusion}\n\\label{sec:Conclusion}\nWriting the posture generation problem as a non-linear optimization problem on non-Euclidean manifolds proves to be an elegant approach in terms of code structuring and user interface, in addition to mathematical readability. This work is still on-going and only preliminary results of the current state of the implementation are shown. We illustrate some posture generation problems with the HRP2-Kai and the HRP-4 humanoid robots; the results are very promising indeed. Our future (on-going) work is focused on the following streams:\n\\begin{itemize}\n\\item complement other functionalities as ready-to-use templates (e.g. constraints on task forces, collision avoidance, etc.);\n\\item specialize the solver to humanoid PG problems and benchmark various numerical approaches (e.g. for the choice of the Hessian approximation, the trust region, tuning some parameters, etc.) and exploiting, if any, robotic model properties;\n\\item improve convergence, numerical robustness and computation time of the PG. Currently, the resolution of any of the presented problems takes a few seconds on a laptop with Intel Core i7-3840QM CPU @ 2.80GHz. We aim at reducing it to a tenth of a second.\n\\end{itemize} \nOnce the code is more stable and finalized, we plan to make it open-source.\n", "meta": {"hexsha": "ab76e306d88c2b844bb3f1bd5e2505f82470b8e2", "size": 46194, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "papers/Humanoids2015/Humanoids2015.tex", "max_stars_repo_name": "stanislas-brossette/phd-thesis", "max_stars_repo_head_hexsha": "7f4d2d46dfdd1f59ac29770585e8cee6dc4f2668", "max_stars_repo_licenses": ["MIT"], "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/Humanoids2015/Humanoids2015.tex", "max_issues_repo_name": "stanislas-brossette/phd-thesis", "max_issues_repo_head_hexsha": "7f4d2d46dfdd1f59ac29770585e8cee6dc4f2668", "max_issues_repo_licenses": ["MIT"], "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/Humanoids2015/Humanoids2015.tex", "max_forks_repo_name": "stanislas-brossette/phd-thesis", "max_forks_repo_head_hexsha": "7f4d2d46dfdd1f59ac29770585e8cee6dc4f2668", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 85.5444444444, "max_line_length": 930, "alphanum_fraction": 0.7548382907, "num_tokens": 12555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6066434009158947}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{fullpage}\n\\begin{document}\n\\begin{center}\n\\Large\\textbf{Long Term Time Series Generation Conditioned on Sequential Short-Term Forecasts} \\\\\n\\large{Kyle Perline}\n\\end{center}\n\n\n\nThis code implements the Long Term Generation algorithm.  This algorithm was developed in Kyle Perline's Ph.D. thesis at Cornell University, and this work is currently under submission to IEEE Transactions on Sustainable Energy.\n\nThe Long Term Generation algorithm generates long term time series conditioned on sequential short-term historical forecasts. The application is to generating wind power scenarios conditioned on sequential short-term historical wind power forecasts.\n\n\\section{Technical Definitions and Objective}\n\nLet the time index be $t$.  Let $R_t$ be a (univariate) response random variable. Let $F_t=(F_t^1,...,F_t^{\\Delta})$ be a $\\Delta$-dimensional random vector of forecasts, where $F_t^i$ predicts the response variable $R_{t+i}$, for each $i=1,...,\\Delta$. (The predictor variables $F_t$ can be more general than the described forecasts; e.g. they can be probabilistic forecasts instead of point forecasts, or they do not even need to be forecasts at all.) Over time steps $T_1,...,T_2$ there is some joint probability density function $P$ of the $R_t$ and $F_t$, denoted\n\n$$ P(F_{T_1},R_{T_1},F_{T_1+1},R_{T_1+1},...,F_{T_2},R_{T_2}). $$\n\n\\noindent Let $r_t$ and $f_t$ be historical samples of the random variables $R_t$ and $F_t$, respectively.\n\nSuppose that historical forecasts $f_{T_1},...,f_{T_2}$ are obtained.  Then the conditional distribution of the response variables conditioned on the forecasts is\n\n$$ P(R_{T_1},...,R_{T_2} | f_{T_1},...,f_{T_2}). $$\n\nThe Long Term Generation algorithm creates an estimate $\\hat{P}$ of this conditional distribution, i.e.\n\n$$ \\hat{P}(R_{T_1},...,R_{T_2} | f_{T_1},...,f_{T_2}) =_d P(R_{T_1},...,R_{T_2} | f_{T_1},...,f_{T_2}). $$\n\n\n\\noindent This Long Term Generation algorithm has three main steps:\n\n\\begin{enumerate}\n\\item For each time step $t=T_1,...,T_2$ estimate the \\textbf{marginal distribution} $P(R_t|f_{T_1},...,f_{T_2})$.\n\nThis is accomplished by:\n\\begin{enumerate}\n\\item Create a predictor random variable $X_{t,u}=h_{t,u}(F_{T_1+u},...,F_{T_2+u})$; let $x_{t,u}$ be the historical sample.\n\\item For some positive integer, draw historical samples \n$$D_t = \\{ (x_{t,u},r_t) \\}_{-N\\leq u \\leq N}.$$\nThis definition assumes that $P$ is \\textit{slowly time varying}.\n\\item Use a numerical method to construct the estimate $\\hat{P}(R_t|X_{t,0})$ based on $D_t$.  The two numerical methods that have been implemented are \\textit{Kernel Density Estimation} and \\textit{Quantile Regression}.\n\\end{enumerate}\nFor example, if $X_{t,u}=F_{t-1+u}^1$, then the predictor variable is the previous time step's one time step ahead forecast.  Then in step (b) the data set at time $t$ is\n$$ D_t = \\{ (f_{t-1+u}^1,r_{t+u}) \\}_{-N \\leq u \\leq N}. $$\n\\noindent In step (c) the slowly time varying assumption means that each data point in $D_t$ is drawn from the same distribution $P(R_t|F_{t-1}^1)$.  We therefore construct the estimate $\\hat{P}(R_t|F_{t-1}^1)$.\n\n\\item Construct the \\textbf{joint distribution} $\\hat{P}(R_{T_1},...,R_{T_2}|X_{T_1,0},...,X_{T_2,0})$ based on the marginal distributions.  A Gaussian copula approach is used, where each of the marginal distributions are transformed into a standard normal distribution.  The joint distribution is then uniquely specified by the covariance matrix.  There are multiple methods for estimating or constructing this covariance matrix.\n\\item Draw scenarios from $\\hat{P}(R_{T_1},...,R_{T_2}|X_{T_1,0},...,X_{T_2,0})$.\n\\end{enumerate}\n\n\\section{Long Term Generation code}\nThere are three main sections of code.\n\n\\begin{enumerate}\n\\item Marginal Distributions:  Both Kernel Density Estimation (KDE) and Quantile Regression (QR) have been implemented.  Run \\texttt{KDEdemo} for an example of KDE usage.\n\\item Joint Distribution: The Gaussian copula method has been implemented, with various approaches for estimating the covariance matrix.\n\\item Getting Data: Various methods were implemented for automatically obtaining the data set $D_t$ in step 1b.\n\\end{enumerate}\n\nWind scenarios can be generated using the Long Term Generation algorithm by calling \\texttt{RUN\\_GEN\\_SCENARIOS.LTG()}.\n\n\\end{document}", "meta": {"hexsha": "04f10c40f4dc0cba17c336b15df1762f855d093c", "size": 4444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Readme.tex", "max_stars_repo_name": "kyleperline/LTG", "max_stars_repo_head_hexsha": "ec3b9e55aeb2611c04453a8bf5e236ef26462806", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Readme.tex", "max_issues_repo_name": "kyleperline/LTG", "max_issues_repo_head_hexsha": "ec3b9e55aeb2611c04453a8bf5e236ef26462806", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Readme.tex", "max_forks_repo_name": "kyleperline/LTG", "max_forks_repo_head_hexsha": "ec3b9e55aeb2611c04453a8bf5e236ef26462806", "max_forks_repo_licenses": ["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.3529411765, "max_line_length": 568, "alphanum_fraction": 0.7414491449, "num_tokens": 1284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6066398584101445}}
{"text": "\\documentclass{article}\n\n\\usepackage{style/preamble}\n\\usepackage{style/mytikz}\n\\usepackage{parskip}\n\n\\newcounter{dip}\n\n\\begin{document}\n  \\title{Problem Set 4 - Points at $\\infty$}\n  \\date{}\n  \\maketitle\n\n\n\n\n\n\n\n\\begin{mdframed}\n  Corrected Theorem 4.1 from PSet 02:\n  \\begin{theorem}\n    Let $f$ be a non-constant holomorphic function defined near $z_0 \\in \\bbc$.\n    Suppose the Taylor series of $f$ near $z_0$ has the form\n    \\begin{align*}\n      f(z) - f(z_0) = a_k (z - z_0)^k + a_{k+1} (z - z_0)^{k+1} + a_{k+2} (z - z_0)^{k+2} + \\dots\n    \\end{align*}\n    with $a_k \\neq 0$.\n    Then there exists biholomorphic functions $\\psi(z)$, $\\phi(z)$ (with appropriate domains) such that\n    \\begin{align*}\n      \\psi \\circ f \\circ \\phi (z) = z^k\n    \\end{align*}\n  \\end{theorem}\n\\end{mdframed}\n\n\n\n\\section{Complex projective space}\n\nProjectivization provides a technique for compactifying non-compact surfaces.\nHowever, as we will see tomorrow, this technique sometimes creates singularities so should be used with caution.\n\n\\begin{definition}\n  The \\emph{complex projective space} of dimension $n$ is the set\n  \\begin{align*}\n    \\bbp^n := \\set{(z_0, z_1, \\dots, z_n)  \\mid  z_i \\in \\bbc \\mbox{ and not all $z_i$ are zero}}/\\sim\n  \\end{align*}\n  where the equivalence $\\sim$ is defined as\n  \\begin{align*}\n    (z_0, z_1, \\dots, z_n) \\sim (\\lambda z_0, \\lambda z_1, \\dots,\\lambda z_n) \\mbox{ for } \\lambda \\neq 0 \\in \\bbc\n  \\end{align*}\n  The elements of $\\bbp^n$ are written as $[z_0: z_1 : \\dots : z_n]$ and the $z_i$'s are called \\emph{homogeneous coordinates}.\n\\end{definition}\n\n\\begin{qbox}\n  Convince yourself that $\\bbp^n$ is the space of complex lines passing through the origin in $\\bbc^{n+1}$. (Such spaces are called Grassmannians.)\n\\end{qbox}\n\nThere is a natural embedding of $\\bbc^n$ in $\\bbp^{n}$ given by\n\\begin{align*}\n  (z_0, z_1, \\dots, z_{n-1}) \\longmapsto [z_0 : z_1 : \\dots : z_{n-1} : 1]\n\\end{align*}\nIt is easy to see that this map is injective. So we can think of $\\bbc^n$ as a subset of $\\bbp^n$.\nAny element in $\\bbp^n$ of the form $[z_0 : z_1 : \\dots : z_{n-1} : z_n]$ with $z_n \\neq 1$ is in the image of the above embedding, hence\n\\begin{align*}\n  \\bbp^n \\setminus \\bbc^n\n  &= \\set{ [z_0 : z_1 : \\dots : z_{n-1} : 0] \\mid z_i \\in \\bbc} \\\\\n  &\\cong \\bbp^{n-1}\n\\end{align*}\nWe think of the points in $\\bbp^n \\setminus \\bbc^n$ as the ``points at $\\infty$''.\nSo $\\bbp^n$ has ``$\\bbp^{n-1}$ many'' points at $\\infty$.\n\nWe are mainly interested in the space $\\bbp^2$.\nWe will use the notation\n\\begin{align*}\n  \\bbp^2 = \\set{ [z : w : t] }.\n\\end{align*}\nThe points at $\\infty$ are then the points with $t = 0$ i.e. $\\set{[z:w:0]}$.\n\n\n\n\n\n\n\n\n\n\n\\section{Homogenization}\nLet $p(z,w)$ be a polynomial in two variables with complex coefficients.\nAnd let\n\\begin{align*}\n  S_p = \\set{(z,w) \\mid  p(z,w) = 0} \\subseteq \\bbc^2\n\\end{align*}\n\\begin{definition}\n  A polynomial is \\emph{homogeneous} if every monomial term in it has the same total degree.\n\\end{definition}\n\\emph{Homogenization} turns $p$ into a homogeneous polynomial $\\conj{p}(z,w,t)$ in three variables, where we add powers of $t$ as needed to make each term of the same degree.\n\\begin{ex}\n  If $p(z,w) = z^2 - w^3 - w$ then $\\conj{p}(z,w,t) = z^2t - w^3 - wt^2$.\n  If $p(z,w) = z^2 - w^2 - w$ then $\\conj{p}(z,w,t) = z^2 - w^2 - wt$.\n\\end{ex}\n\n\\begin{qbox}\n  Let $\\conj{p}(z,w,t)$ is a homogeneous polynomial.\n  Prove that $(a,b,c)$ is a root of $\\conj{p}$ if and only if $(\\lambda a , \\lambda b, \\lambda c)$ is a root of $\\conj{p}$ for $\\lambda \\neq 0 \\in \\bbc$.\n\\end{qbox}\n\nHence, we can ask for solutions of the homogeneous polynomial  $p(z,w,t)$  in the projective space $\\bbp^2$.\n\nIf $S_p$ is the set $\\set{(z,w) \\mid  p(z,w) = 0} \\subseteq \\bbc^2$ then denote\n\\begin{align*}\n  \\conj{S_p} := \\set{[z:w:t] \\mid  p(z,w,t) = 0} \\subseteq \\bbp^2.\n\\end{align*}\n\\begin{definition}\n  $\\conj{S_p}$ is called the \\emph{projectivization} of $S_p$.\n\\end{definition}\n\nThere is a natural embedding $S_p \\rightarrow \\conj{S_p}$ which sends a solution $(z,w)$ of $p$ to the solution $[z:w:1]$ of $\\conj{p}$.\nThe points in $\\conj{S_p} \\setminus S_p$ are called the points at $\\infty$.\n\n\n% \\begin{qbox}\n%   Describe the spaces $\\bbc^1 = \\set{[1:t]}$ and $\\bbc^2 = \\set{[1:w:t]}$ as solutions of certain polynomial equations.\n%   Show that projectivizations of $\\bbc^1$ and $\\bbc^2$ are precisely $\\bbp^1$ and $\\bbp^2$ respectively.\n%   \\begin{align*}\n%     \\conj{\\bbc^1} = \\bbp^1 \\qquad \\conj{\\bbc^2} = \\bbp^2\n%   \\end{align*}\n% \\end{qbox}\n\nFor any homogeneous polynomial $\\conj{p}$ the space $\\conj{S_p}$ is compact. The proof of this is essentially the fact that closed subsets of compact sets are compact and zero sets of polynomials are closed. But because of the points at $\\infty$ the argument is a bit more intricate, we won't go over the details.\n\n\n\\begin{qbox}\n  Let $q(w)$ be a complex polynomial and let $p(z,w) = z^2 - q(w)$.\n  Find the number of points at $\\infty$ for $\\conj{S_p}$ for the following polynomials\n    \\begin{enumerate}\n      \\item $q(w) = w + b$, where $b \\in \\bbc$.\n      \\item $q(w) = w^2 + bw + c$, where $b,c \\in \\bbc$.\n      \\item $q(w) = w^n + a_{n-1} w^{n-1}+ \\dots a_1 w + a_0$, where $a_i \\in \\bbc$ and $n \\ge 3$.\n    \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}\n  Let $p(z,w)$ be an arbitrary polynomial with homogenization $\\conj{p}(z,w,t)$.\n  What can you say about the number of points at $\\infty$ for $\\conj{S_p}$?\n  Can you interpret this result in terms of limits $\\lim_{z \\rightarrow \\infty} z/w$?\n\\end{qbox}\n\n\\textbf{Fact:} when $q(w)$ is a non-constant polynomial of degree $\\le 3$ with distinct roots and $p(z,w) = z^2 - q(w)$ the space $\\conj{S_p}$ is a Riemann surface and the projection map\n\\begin{align*}\n    \\pi: \\conj{S_p} &\\longrightarrow \\bbp^1 \\\\\n    [z:w:1] &\\longmapsto w \\\\\n    [z:w:0]  &\\longmapsto \\infty\n\\end{align*}\nis a complex differentiable map.\n\n\\begin{qbox}\n  Using the Riemann--Hurwitz formula for the projection $\\pi$, find the genus of the curves $\\conj{S_p}$ when $p(z,w) = z^2 - q(w)$ and $q$ is a non-constant polynomial of degree $\\le 3$ with distinct roots.\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Fermat's conjecture for function fields}\n\n\\begin{theorem}\n  The are no non-constant complex coefficient polynomial solutions to the equation\n  \\begin{align*}\n    (x(t))^d + (y(t))^d  = (z(t))^d\n  \\end{align*}\n  if $d > 2$, with $\\mathrm{gcd}(x(t), y(t), z(t)) = 1$.\n\\end{theorem}\n\n\\begin{proof}\n  Consider the polynomial $p(z,w) = z^d + w^d - 1$ with homogenization $p(z,w,t) = z^d + w^d - t^d$.\n  $\\conj{S_p}$ has exactly $d$ points at $\\infty$ given by $z^d + w^d = 0$, namely\n  \\begin{align*}\n    [\\zeta_1:1:0]\\:, \\: [\\zeta_2:1:0]\\:, \\dots,\\: [\\zeta_d:1:0] \\mbox{ where } \\zeta^d_i = -1\n  \\end{align*}\n  One can show that the projection map\n  \\begin{align*}\n      \\pi: \\conj{S_p} &\\longrightarrow \\bbp^1 \\\\\n      [z:w:1] &\\longmapsto w \\\\\n      [z:w:0]  &\\longmapsto \\infty\n  \\end{align*}\n  is a complex differentiable map, and hence a ramified covering.\n\n  Consider a point $w \\in \\bbc$. The points in $\\pi^{-1}(w)$ are the elements $[z:w:1]$\n  such that $z^d = 1 - w^d$.\n  Hence,\n  \\begin{enumerate}\n    \\item $\\pi^{-1}(w)$ has size $d$ if $ 1 - w^d \\neq 0$,\n    \\item $\\pi^{-1}(w)$ has size $1$ if $ w^d = 0$,\n    \\item $\\pi^{-1}(\\infty)$ has size $d$.\n  \\end{enumerate}\n\n  This tells us that there are $d$ branch points given by the $d^{th}$ roots of unity, call them $\\tau_1, \\dots, \\tau_d$, and the fiber over each branch point is single element $[0:\\tau_i:1]$.\n\n  Plugging this in the Riemann--Hurwitz formula we get\n  \\begin{align*}\n    \\chi(\\conj{S_p})\n    &= d \\cdot \\chi(\\bbp^1) - \\sum_{d} (d - 1) \\\\\n    &= 3d - d^2\n  \\end{align*}\n\n  Hence if $d > 2$, $\\chi(\\conj{S_p}) < 2$ and hence genus of $\\conj{S_p} > 0$.\n  Hence if $d > 2$, there are no non-constant complex differentiable maps\n  \\begin{align*}\n    \\bbp^1 \\longrightarrow \\conj{S_p}\n  \\end{align*}\n\n  But a solution $(x(s),y(s),z(s))$ to the equation $x^d + y^d = z^d$ defines a complex differentiable map\n  \\begin{align*}\n    \\bbp^1 &\\longrightarrow \\conj{S_p} \\\\\n    s &\\longmapsto [x(s) : y(s) : z(s)]\n  \\end{align*}\n  extended to $\\infty$ by taking the limit. This map would be non-constant if $\\mathrm{gcd}(x,y,z) = 1$. But no such map exists.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "a026aa7acb92b9aae27f6e922f9f3ea97767b276", "size": 8278, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PSet04.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": "PSet04.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": "PSet04.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": 35.9913043478, "max_line_length": 313, "alphanum_fraction": 0.6325199324, "num_tokens": 3037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.6066398508767182}}
{"text": "% Copyright 2017 Markus J. Pflaum, licensed under CC BY-NC-ND 4.0\n% main author: \n%   Markus J. Pflaum\n%\n\\section{Orthogonal decomposition and the Riesz representation theorem}\n  \n\\para \nOne of the issues with infinite-dimensional analysis is that a closed subspace of an infinite dimensional Banach space might not have a \nclosed complement. Fortunately, the situation in Hilbert space theory is not so grim because \nevery closed subspace of a Hilbert space admits an orthogonal complement. This is one of the four \ncrucial properties  which distinguish Hilbert spaces from Banach spaces and which are stated in the following. \n\nIn this section $\\hilbertH$ will always denote a Hilbert space over the field $\\fldK=\\R$ or $\\fldK=\\C$. \nThe symbol $\\langle \\cdot , \\cdot\\rangle$ will stand for the inner product of $\\hilbertH$. \n\n\\begin{theorem}[Best approximation theorem] \n   Every closed convex nonempty subset $C$ of a Hilbert space \n   $\\hilbertH$ has a unique element of minimal norm.\n\\end{theorem}\n\\begin{proof}\nLet $d = \\inf\\{ \\|v\\| \\mid v \\in C \\}$ which is a non-negative real number. We claim there exists a unique \n$v_0 \\in C$ with $\\|v_0\\| =d$. \nFor uniqueness, consider two vectors $v_0, v_1$ satisfying the desired property, and let $v = \\frac{1}{2}(v_0 + v_1)$ \nbe their midpoint. Then\n\\begin{equation*}\n  \\|v\\| = \\frac{1}{2}\\|v_0 + v_1\\| \\leq \\frac{1}{2}(\\|v_0\\| + \\|v_1\\|) = d\n\\end{equation*}\nBy minimality of $d$ this entails $\\|v\\| =d$. By the parallelogram identity\n\\begin{equation*}\n    \\left\\|\\frac{1}{2} (v_0 + v_1)\\right\\|^2 + \\left\\|\\frac{1}{2}(v_0 - v_1) \\right\\|^2  = \n    2\\left\\|\\frac{v_0}{2}\\right\\|^2 + 2\\left\\|\\frac{v_1}{2}\\right\\|^2 = d^2 \\ ,\n\\end{equation*}\nhence\n\\[\n\\left\\| \\frac{1}{2} (v_0 - v_1) \\right\\|^2 \\leq d^2 - \\|v\\|^2 = 0 \\ ,\n\\]\nproving $v_0 = v_1$. \n\nFor the proof of existence observe that by definition of $d$ there exists a sequence $(v_n)_{n \\in \\mathbb{N}} \\subset C$ such \nthat $\\lim_{n \\to \\infty}\\|v_n \\| = d$. By convexity\n\\[\n   \\frac{1}{2}(v_n + v_m) \\in C\n\\]\nfor all $n,m \\in \\mathbb{N}$, hence $\\frac{1}{4}\\|v_n + v_m \\|^2 \\geq d^2$. The parallelogram equality entails\n\\[\n0 \\leq \\| v_n - v_m \\|^2 = 2\\|v_n \\|^2 + 2\\|v_m \\|^2 - \\| v_n + v_m \\|^2 \\leq 2\\|v_n \\|^2 + 2\\|v_m \\|^2 - 4d^2 \\ .\n\\]\nSince $\\lim_{n \\to \\infty}\\|v_n \\| = d$ there exists for given $\\varepsilon >0$ an $N\\in \\N$ such that \n$ \\|v_n \\|^2 -d^2 \\leq \\frac 14 \\varepsilon^2 $ for all $n \\geq N$. Hence, for $n,m \\geq N$\n\\[\n  0 \\leq \\| v_n - v_m \\| \\leq \\varepsilon \\ ,\n\\] \nand $(v_n)_{n \\in \\N}$ is a Cauchy-sequence, so convergent by completeness of $\\hilbertH$. Put $v_0:= \\lim_{n \\to \\infty}v_n$. \nThen $v_0 \\in C$ since $C$ is closed and $\\|v_0 \\|=\\lim_{n \\to \\infty}\\|v_n \\| = d$. The existence claim follows \nand the proof is finished.\n\\end{proof}\n\n\\begin{thmanddef}[Orthogonal decomposition theorem] \n\\label{thm:orthogonal-decomposition-theorem}\nLet $\\vectorspV \\subset \\hilbertH$ be a closed subspace of the Hilbert space $\\hilbertH$. Then the \n\\emph{orthogonal complement}\n\\[\n  \\vectorspV^\\bot = \\big\\{ w \\in \\hilbertH \\bigmid \\langle v,w \\rangle = 0 \\text{ for each } v \\in \\vectorspV \\big\\}\n\\]\nis a closed subspace of $\\hilbertH$ and $\\hilbertH = \\vectorspV \\oplus \\vectorspV^\\bot$. \nThe map $\\proj_\\vectorspV : \\hilbertH \\to \\vectorspV$ which maps $w \\in \\hilbertH$ to the unique $w_1\\in \\vectorspV$ \nsuch that $w - w_1 \\in   \\vectorspV^\\bot$ is called the \\emph{orthogonal projection} onto $\\vectorspV$.\nIt satisfies $\\left\\| w-  \\proj_\\vectorspV (w)\\right\\| = d(w,\\vectorspV) := \\inf \\big\\{ \\| v-w \\| \\bigmid v\\in \\vectorspV \\big\\}$ that is $\\proj_\\vectorspV (w)$ is the unique element of $\\vectorspV$ having shortest distance from $w$.  \n\\end{thmanddef}\n\\begin{proof}\nFor $v \\in \\hilbertH$ define $v^\\flat :\\hilbertH \\to \\R$ by $v^\\flat (w) = \\langle w,v \\rangle$. Recall that this map is \ncontinuous and linear. Hence the kernel $(v^\\flat)^{-1}(0)$ is a closed linear subspace of $\\hilbertH$ and \n\\[\n  \\vectorspV^{\\bot} = \\bigcap_{v \\in \\vectorspV} (v^\\flat)^{-1}(0)\n\\]\nis a closed linear subspace. To show $\\vectorspV \\cap \\vectorspV^\\bot = \\{0\\}$, consider \n$v \\in \\vectorspV \\cap \\vectorspV^\\bot$. Then $\\|v \\|^2 = \\langle v,v \\rangle = 0$. \nNow, given some $w \\in \\hilbertH$, it can be written as $w = w_1 + w_2$ with \n$w_1 \\in \\vectorspV$ and $w_2 \\in \\vectorspV^\\bot$. To see this put $C = w - \\vectorspV$. Then $C$ is closed and convex. \nBy the best approximation theorem there exists a unique element $w_2 \\in C$ of minimal norm. Let  $w_1$\nbe the unique element of $\\vectorspV$ such that $w_2 = w -w_1$. It remains to show $w_2 \\in \\vectorspV^\\bot$. \nSince $w_2$ has minimal norm among the elements of $w-\\vectorspV$ the following inequality holds for all \nvectors $v \\in \\vectorspV$:\n\\[\n\\|w_2 \\|^2 \\leq \\| w_2 + v \\|^2 = \\|w_2 \\|^2 + 2\\, \\Re\\langle w_2,v\\rangle + \\| v \\|^2 \\ . \n\\]\nHence\n\\[\n0 \\leq 2\\, \\Re\\langle w_2,v\\rangle + \\| v \\|^2 \\quad \\text{for all  } v \\in \\vectorspV  \\ .\n\\]\nNow assume that $\\|v\\|=1$ and choose $\\varphi \\in \\R$ such that $e^{i\\varphi}\\langle w_2, v \\rangle \\in \\R$.\nSetting $v' = e^{-i\\varphi}v$, one obtains for all $\\lambda \\in \\R$ by the last inequality\n\\[\n  0 \\leq 2 \\langle w_2,\\lambda v'\\rangle + \\| \\lambda v' \\|^2 = \n  2\\lambda\\langle w_2, x'\\rangle + \\lambda^2\\ .\n\\]\nFor $\\lambda = -\\langle w_2, v' \\rangle$ this entails  the estimate\n\\[ \n   \\| \\langle w_2, v' \\rangle \\|^2 = \n   - \\left( - 2\\|\\langle w_2,v \\rangle \\|^2 + \\| \\langle w_2, v' \\rangle \\|^2 \\right) = - \\left(  2\\lambda\\langle w_2, x'\\rangle + \\lambda^2 \\right) \\leq 0 \\ .\n\\]\nHence $\\langle w_2, v \\rangle = 0$ for all unit vectors $v \\in \\vectorspV$, therefore $w_2 \\in \\vectorspV^\\bot$.\n\nThe remainder of the claim is now a consequence of the construction of $w_1$ from the given $w$ and the \nobservation that $\\proj_\\vectorspV (w) = w_1$. \n\\end{proof}\n\n\\begin{corollary}\n  For every closed subspace $\\vectorspV \\subset \\hilbertH$ of a Hilbert space $\\hilbertH$ the relation\n  \\[\n     V = (V^\\perp)^\\perp \n  \\]\n  holds true. \n\\end{corollary}\n\n\\begin{proof}\n  One has $V \\subset  (V^\\perp)^\\perp $ by definition of the orthogonal complement. \n  Since \\[ \\hilbertH = V \\oplus  V^\\perp =  (V^\\perp)^\\perp \\oplus V^\\perp \\] \n  by the preceding theorem, the claim follows.\n\\end{proof}\n\n\\begin{theorem}[Riesz representation theorem for Hilbert spaces]\n  Let $\\hilbertH$ be a Hilbert space and $\\hilbertH'$ its topological dual. Then the \\emph{musical map} \n  \\[ {}^\\flat: \\hilbertH \\to \\hilbertH',\\quad \n     v \\mapsto v^\\flat = \\left( \\hilbertH \\ni w \\mapsto \\langle w,v\\rangle \\in \\fldK\\right) \\]\n  is an isometric isomorphism which is linear in the real case and conjugate-linear in the complex case. \n\\end{theorem}\n\n\\begin{proof}\n  Obviously, ${}^\\flat$ is linear if the ground field $\\fldK$ equals $\\R$ and conjugate-linear if $\\fldK=\\C$.\n  Now observe that for all $v \\in \\hilbertH$ by the Cauchy--Schwarz inequality \n  \\[\n    \\| v^\\flat \\| = \\sup\\big\\{ |\\langle w,v \\rangle | \\bigmid w \\in \\hilbertH \\: \\& \\: \\|w\\| =1 \\big\\} = \n    \\| v \\| \\ ,\n  \\]\n  hence ${}^\\flat$ is an isometry, so in particular injective. \n  It remains to show surjectivity. So assume that $\\alpha : \\hilbertH \\to \\fldK$ is a nontrivial \n  continuous linear form. \n  Let $\\vectorspV$ be its kernel. Then  $\\vectorspV$ is a closed linear subspace of $\\hilbertH$.\n  Since $\\alpha$ is nontrivial, the orthogonal complement $\\vectorspV^\\bot$ is nontrivial, too. Hence \n  $\\vectorspV^\\bot \\cong \\hilbertH/\\vectorspV$ is isomorphic to $\\image \\alpha = \\fldK$ \n  and there exists a  vector $v \\in \\vectorspV^\\bot \\setminus \\{ 0 \\} $ such that \n  $\\alpha (v) = 1$. Since $v$ spans $ \\vectorspV^\\bot$ there exists   for every $w\\in \\hilbertH$ a\n  unique $\\lambda_w  \\in \\fldK$ such that $w = \\proj_V (w) + \\lambda_w v$. Then compute \n  \\[\n    \\alpha (w) = \\alpha (\\lambda_w v ) = \\lambda_w  \\quad \\text{and} \\quad \n    \\left( \\frac{v}{\\|v\\|^2}\\right)^\\flat (w) = \n    \\frac{1}{\\|v\\|^2} \\langle w, v \\rangle =  \\frac{ \\lambda_w}{\\|v\\|^2} \\langle v , v \\rangle \n    = \\lambda_w \\ .\n  \\]\n  This entails $\\alpha = \\left( \\frac{v}{\\|v\\|^2}\\right)^\\flat$, and ${}^\\flat$ is surjective.\n\\end{proof}\n\n\\begin{remark}\n  Sometimes, and we will follow that convention, the inverse of the musical isomorphism \n  ${}^\\flat: \\hilbertH \\to \\hilbertH'$ is denoted ${}^\\sharp: \\hilbertH' \\to \\hilbertH$. \n\\end{remark}\n\n\\begin{corollary}\n  Every Hilbert space $\\hilbertH$ is \\emph{reflexive} that is the canonical map\n  \\[ H \\to H'' , \\: v \\mapsto \\left( H' \\ni \\lambda \\mapsto \\lambda(v) \\in \\fldK \\right) \\]\n  is an isometric isomorphism. \n\\end{corollary}\n\n\\begin{proof}\n  By the Riesz Representation Theorem, the dual $\\hilbertH'$ is a Hilbert space \n  with inner product  \n  \\[\n    \\langle\\!\\langle \\cdot, \\cdot  \\rangle\\!\\rangle : \\hilbertH' \\times \\hilbertH' \\to \\fldK, \\:  \n    (\\lambda,\\mu)   \\mapsto \\langle\\!\\langle \\lambda, \\mu \\rangle\\!\\rangle = \\inprod{\\mu^\\sharp,\\lambda^\\sharp} \\ .\n  \\] \n  Hence, by applying the Riesz Representation Theorem twice, \n  the map ${}^\\flat \\circ {}^\\flat : \\hilbertH \\to  \\hilbertH''$ is an isometric linear isomorphism. \n  Now compute for $v\\in \\hilbertH$ and $\\lambda \\in \\hilbertH'$\n  \\[\n     (v^\\flat)^\\flat (\\mu) = \\langle\\!\\langle \\lambda, v^\\flat \\rangle\\!\\rangle =\n     \\inprod{v, \\lambda^\\sharp} = \\lambda (v) \\ . \n  \\]\n  Hence ${}^\\flat \\circ {}^\\flat$ coincides with the canonical map above and the claim\n  follows. \n\\end{proof}\n\n\\begin{corollary}\n\\label{thm:correspondence-bounded-sesquilinear-forms-bounded-operators}\n  Let $b:\\hilbertH \\times \\hilbertH\\to \\fldK$ be a bounded sesquilinear form on a Hilbert space $\\hilbertH$. Then there exists\n  unique bounded linear map $A : \\hilbertH \\to \\hilbertH$ such that\n  \\[\n      b(v,w)  = \\inprod{Av,w} \\quad \\text{for all } v,w\\in \\hilbertH \\ .\n  \\]\n  Moreover, the operator norm $\\| A \\|$ coincides with $\\| b\\|$. \n\\end{corollary}\n\\begin{proof}\n  First let us show uniqueness. So let $A,B  : \\hilbertH \\to \\hilbertH$ be bounded and linear so that\n  \\[\n          b(v,w)  = \\inprod{Av,w} = \\inprod{Bv,w}  \\quad \\text{for all } v,w\\in \\hilbertH \\ .\n  \\]\n  Then $ \\|(A-B)v \\|^2 = \\inprod{Av-Bv,(A-B)v} = b(v,(A-B)v) - b(v,(A-B)v)=  0$ for all $v\\in \\hilbertH$ \n  which entails equality of $A$ and $B$. \n\n  To prove existence observe that for every $v\\in \\hilbertH$ the map $\\hilbertH \\to \\fldK$, $w \\mapsto \\overline{b(v,w)}$\n  is bounded an linear, so by the Riesz representation theorem there exists for every $v$ an element $Av \\in \\hilbertH$ \n  such that $\\inprod{w,Av} =  \\overline{b(v,w)}$ for all $w\\in \\hilbertH$. \n  Let us show that the map $A$ is linear. \n  For $v_1,v_2\\in \\hilbertH$ check that\n  \\begin{equation*}\n    \\begin{split}\n      \\inprod{w,A(v_1+v_2)} & =  \\overline{b(v_1+v_2,w)} = \\overline{b(v_1,w)}+ \\overline{b(v_2,w)} = \\\\\n      & = \\inprod{w,Av_1}  +\\inprod{w,Av_2} =  \\inprod{w,Av_1+Av_2} \\quad \\text{for all } w\\in \\hilbertH \\ . \n    \\end{split}\n  \\end{equation*}\n  But that implies $A(v_1+v_2) = Av_1+Av_2$. Given $r\\in \\fldK$ and $v\\in\\hilbertH$ one verifies\n  \\[\n    \\inprod{w,A(rv)} =  \\overline{b(rv,w)} = \\overline{rb(v,w)} = \\overline{r} \\, \\overline{b(v,w)}\n    =  \\overline{r}  \\inprod{w,Av} =  \\inprod{w,rAv} \\quad \\text{for all } w\\in \\hilbertH \\ . \n  \\]\n  Hence $A(rv) = r Av$ and linearity of $A$ is proved. \n  \n  For the operator norm compute\n  \\begin{equation*}\n    \\begin{split}\n    \\| A \\| & = \\sup \\big\\{ \\left|\\inprod{Av,w} \\right| \\bigmid v,w \\in \\hilbertH \\: \\& \\: \\|v\\| = \\|w\\| =1 \\big\\} = \\\\\n    & = \\sup \\big\\{ \\left| b(v,w) \\right| \\bigmid v,w \\in \\hilbertH \\: \\& \\: \\|v\\| = \\|w\\| =1 \\big\\} = \\| b\\| \\ .\n   \\end{split}\n  \\end{equation*}\n\\end{proof}\n\n\\para\nLast in this section we will examine the \\emph{Hilbert direct sum} or just \\emph{Hilbert sum} of a family\n$(\\hilbertH_i)_{i\\in I}$ of Hilbert spaces. It is defined by\n\\begin{equation*}\n  \\begin{split}\n   \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i & = \\left\\{ (v_i)_{i\\in I} \\in \\prod_{i\\in I}\\hilbertH_i\n   \\Bigmid \\left( \\|v_i\\|^2 \\right)_{i\\in I} \\text{ is summable} \\right\\} = \\\\\n   & = \\left\\{ (v_i)_{i\\in I} \\in \\prod_{i\\in I}\\hilbertH_i\n   \\Bigmid \\exists C \\geq 0 \\, \\forall J \\in \\mathscr{F} (I): \\: \\sum_{i\\in J} \\|v_i\\|^2 \\leq C \\right\\} \\ ,\n  \\end{split}\n\\end{equation*}\nwhere, as usual, $\\mathscr{F} (I)\\subset \\powerset{I}$ denotes the set of all finite subsets of $I$.\n\n\\begin{proposition}\n  Let $(\\hilbertH_i)_{i\\in I}$ be a family of Hilbert spaces. Then the Hilbert direct sum\n  $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ is a Hilbert space with inner product  given by\n  \\[\n    \\inprod{-,-} : \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i \\times\n    \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i \\to \\fldK, \\quad\n    \\left( (v_i)_{i\\in I} ,  (w_i)_{i\\in I} \\right) \\mapsto \\sum_{i\\in I} \\inprod{v_i,w_i} \\ .\n  \\]\n\\end{proposition}\n\n\\begin{proof}\n  We show first that $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ is a subvector space of\n  the direct product $\\prod_{i\\in I} \\hilbertH_i$.  \n  Let $z\\in \\fldK$ and $(v_i)_{i\\in I}, (w_i)_{i\\in I}\\in \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$.\n  Choose $C,D \\geq 0$ such that\n  \\[\n    \\sum_{i\\in J} \\|v_i\\|^2 \\leq C \\quad\\text{and}\\quad\n    \\sum_{i\\in J} \\|w_i\\|^2 \\leq D \\quad\\text{for all} J \\in \\mathscr{I} \\ .\n  \\]\n  Then\n  \\begin{equation}\n    \\label{eq:estimate-finite-sum-square-norms-multiple}\n    \\sum_{i\\in J} \\|z v_i\\|^2 = |z| \\, \\sum_{i\\in J} \\| v_i\\|^2\\leq |z| \\, C \\quad\n    \\text{for all } J\\in \\mathscr{I} \\ ,\n  \\end{equation}\n  so $(zv_i)_{i\\in I} \\in \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$. \n  Moreover, by Minkowski's inequality for finite sums,\n  \\begin{equation}\n    \\label{eq:estimate-finite-sum-square-norms-sum}\n    \\sum_{i\\in J} \\|v_i + w_i\\|^2 \\leq\n    \\left( \\sqrt{\\sum_{i\\in J} \\|v_i\\|^2} +  \\sqrt{\\sum_{i\\in J} \\| w_i\\|^2} \\right)^2\n    \\leq \\left( \\sqrt{C} + \\sqrt{D} \\right)^2 \\quad\\text{for all } J\\in \\mathscr{I} \\ .\n  \\end{equation}\n  Hence the family $\\left( \\| v_i + w_i\\|^2 \\right)_{i\\in I}$ is summable and\n  $\\left( v_i + w_i \\right)_{i\\in I} \\in \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$. \n  \n  Next observe that the map\n  \\[\n    \\big\\| - \\big\\| : \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i \\to \\fldK,\n    \\: (v_i)_{i\\in I} \\mapsto \\big\\| (v_i)_{i\\in I}  \\big\\| = \\sqrt{\\sum_{i\\in I} \\| v_i\\|^2} \n  \\]\n  is well-defined by definition of the Hilbert direct sum. It is even a norm\n  by \\eqref{eq:estimate-finite-sum-square-norms-multiple} and\n  \\eqref{eq:estimate-finite-sum-square-norms-sum}. \n    \n  Now we need to show that the inner product on $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$\n  is well-defined which means that the family $\\left( \\inprod{v_i,w_i} \\right)_{i\\in I}$ is summable\n  for all $(v_i)_{i\\in I} ,  (w_i)_{i\\in I} \\in \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$.\n  To this end let $J\\subset I$ be a finite subset. Then, by the triangle inequality, \n  the Cauchy--Schwarz inequality on the Hilbert spaces $\\hilbertH_i$ and the\n  Cauchy--Schwarz inequality for finite sums,\n  \\[\n    \\left| \\sum_{i\\in J} \\inprod{v_i,w_i} \\right| \\leq\n    \\sum_{i\\in J} \\left| \\inprod{v_i,w_i} \\right| \\leq\n    \\sum_{i\\in J} \\| v_i\\| \\, \\| w_i\\| \\leq\n    \\sqrt{\\sum_{i\\in J} \\| v_i\\|^2} \\cdot \\sqrt{\\sum_{i\\in J} \\| w_i\\|^2}\n    \\leq \\big\\| (v_i)_{i\\in I}  \\big\\| \\, \\big\\| (w_i)_{i\\in I}  \\big\\| \\ .\n  \\]\n  Hence the family $\\left( \\inprod{v_i,w_i} \\right)_{i\\in I}$ is absolutely summable, so in particular\n  summable, and the inner product is well-defined.\n\n  By definition and since all the inner products on the Hilbert spaces $\\hilbertH_i$ are conjugate\n  symmetric and positive definite, the map $\\inprod{-,-} $ on\n  $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ has to be conjugate symmetric and positive definite\n  as well. It remains to show linearity in the first argument.\n  Denote for  $(v_i)_{i\\in I}, (w_i)_{i\\in I} \\in \\prod_{i\\in I} \\hilbertH_i$\n  and $J\\in \\mathscr{F} (I)$ by $\\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}_J$ the finite sum\n  $\\sum_{i\\in J} \\inprod{v_i,w_i}$. Observe that the net\n  $\\big( \\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}_J \\big)_{J\\in \\mathscr{F}(I)}$ converges to\n  $\\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}$ in case both $(v_i)_{i\\in I}$ and $(w_i)_{i\\in I}$\n  are in $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$. Now let $z\\in \\fldK$ and \n  $(v_i)_{i\\in I}, (v_i^\\prime)_{i\\in I},  (w_i)_{i\\in I} \\in \\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$.\n  Then \n  \\begin{equation*}\n    \\begin{split}\n      \\inprod{(v_i)_{i\\in I} + (v_i^\\prime)_{i\\in I},(w_i)_{i\\in I}}_J & =\n      \\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}_J + \\inprod{(v_i^\\prime)_{i\\in I},(w_i)_{i\\in I}}_J\n      \\quad\\text{and}\\\\\n      \\inprod{z (v_i)_{i\\in I},(w_i)_{i\\in I}}_J & = z \\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}_J \\ .\n    \\end{split}\n  \\end{equation*}\n  By convergence of all the nets $\\big( \\inprod{(v_i)_{i\\in I} ,(w_i)_{i\\in I}}_J \\big)_{J\\in \\mathscr{F}(I)}$,\n  linearity in the first argument follows.\n\n  By construction, the norm associated to the inner product $\\inprod{-,-} $ on\n  $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ coincides with the above defined norm $\\big\\|-\\big\\|$.\n  It remains to show that $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ equipped with the norm\n  $\\big\\|-\\big\\|$ is complete. To this end observe that for every finite $J\\subset I$ the map\n  \\[\n    \\big\\| - \\big\\|_J : \\prod_{i\\in I} \\hilbertH_i \\to \\R_{\\geq 0}, \\:\n    (v_i)_{i\\in I} \\mapsto \\sqrt{\\inprod{(v_i)_{i\\in I},(v_i)_{i\\in I}}_J}\n    = \\sqrt{\\sum_{i\\in J} \\| v_i \\|^2}\n  \\]\n  is a seminorm and that $(v_i)_{i\\in I} \\in \\prod_{i\\in I} \\hilbertH_i$ lies in\n  the Hilbert direct sum $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$ if and only if the\n  family $\\left(\\big\\| (v_i)_{i\\in I}  \\big\\|_J\\right)_{J\\in \\mathscr{F}(I)}$ is bounded. \n  Now let $\\left((v_i^n)_{i\\in I} \\right)_{n\\in \\N}$ be a Cauchy sequence.\n  Let $\\varepsilon >0$ and choose $N_\\varepsilon \\in \\N$ such that \n  \\begin{equation}\n    \\label{eq:cauchy-criterion-sequence-hilbert-direct-sum}\n    \\big\\| (v_i^m)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\| < \\varepsilon \\quad\n    \\text{for all } n,m\\geq N_\\varepsilon \\ .\n  \\end{equation}\n  Hence\n  \\begin{equation}\n    \\label{eq:cauchy-criterion-sequence-finite-cutoff}\n    \\big\\| (v_i^m)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\|_J <    \\varepsilon \\quad\n    \\text{for all } J\\in \\mathscr{F}(I) \\text{ and }  n,m\\geq N_\\varepsilon \\ . \n  \\end{equation}\n  Taking $J =\\{ j\\}$ for $j\\in I$ this implies that the sequence\n  $ (v_j^n)_{n\\in \\N}$ is a Cauchy sequence in the Hilbert space $\\hilbertH_j$. \n  Let $v_j \\in \\hilbertH_j$ be its limit. The family $(v_i)_{i\\in I}$ then is\n  an element of $\\widehat{\\bigoplus\\limits_{i\\in I}} \\hilbertH_i$. To verify this\n  put $N=N_1$ and observe that by \\eqref{eq:cauchy-criterion-sequence-finite-cutoff}\n  for all finite $J\\subset I$\n  \\begin{equation*}\n    \\begin{split}\n    \\big\\| (v_i)_{i\\in I} \\big\\|_J & \\leq\n    \\big\\| (v_i^N)_{i\\in I} \\big\\|_J + \\big\\| (v_i)_{i\\in I} - (v_i^N)_{i\\in I} \\big\\|_J = \\\\\n    & = \\big\\| (v_i^N)_{i\\in I} \\big\\|_J + \\lim_{m\\to \\infty} \\big\\| (v_i^m)_{i\\in I} - (v_i^N)_{i\\in I} \\big\\|_J\n    \\leq \\big\\| (v_i^N)_{i\\in I} \\big\\| + 1.\n    \\end{split}\n  \\end{equation*}\n    \n  Hence the family $\\left(\\big\\| (v_i)_{i\\in I} \\big\\|_J\\right)_{J\\in \\mathscr{F}(I)}$\n  is bounded and $(v_i)_{i\\in I}$ lies in the Hilbert direct sum of the spaces $\\hilbertH_i$, $i\\in I$. \n  Moreover, \\eqref{eq:cauchy-criterion-sequence-finite-cutoff} entails that\n  \\[\n    \\big\\| (v_i)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\|_J =\n    \\lim_{m\\to \\infty} \\big\\| (v_i^m)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\|_J \\leq \\varepsilon \\quad\n    \\text{for all } J\\in \\mathscr{F}(I) \\text{ and }  n\\geq N_\\varepsilon \\ . \n  \\] \n  Since $\\big\\| (v_i)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\|$ is the limit of the\n  net $\\left(\\big\\| (v_i)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\|_J\\right)_{J\\in\\mathscr{F}(I)}$,\n  the estimate \n  \\[\n    \\big\\| (v_i)_{i\\in I} - (v_i^n)_{i\\in I} \\big\\| \\leq \\varepsilon \\quad\n    \\text{for all }  n\\geq N_\\varepsilon \n  \\]\n  follows and the sequence $\\left((v_i^n)_{i\\in I} \\right)_{n\\in \\N}$ convergence to\n  $(v_i)_{i\\in I}$. This finishes the proof.    \n\\end{proof}", "meta": {"hexsha": "bba9b7ac0a03a3b68091a11400182dd48e22a943", "size": 20133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/orthogonal-decomposition-riesz-representation-theorem.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/orthogonal-decomposition-riesz-representation-theorem.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/orthogonal-decomposition-riesz-representation-theorem.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": 52.842519685, "max_line_length": 235, "alphanum_fraction": 0.6298117519, "num_tokens": 8042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6066398493700328}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\n\\section{Complex Measures}\n\nWe can generalize finite (real and positive) measures with the following.\n\n\\begin{definition}\nLet $(X, \\m{A})$ be a measurable space. A complex measure is a set function $\\mu: \\m{A} \\to \\C$ such that for every partition $\\{A_{i}\\}_{i\\in \\N}$ of $A$\n\\begin{align}\n\t\\mu(A) = \\sum_{i=1}^{\\infty}\\mu(A_{i}) \\label{eq: convergence of complex measure}\n\\end{align}\n\\end{definition}\nThe convergence of the series in \\eqref{eq: convergence of complex measure} is now required whereas for positive and real measures, the series could either converge or diverge to $\\infty$ (possibly $-\\infty$ for real measures). This in turn ensures that $\\mu(\\emptyset)=0$.\nFor any partition $\\sigma: \\N \\to \\N$ the union of the partition is unchanged so \\eqref{eq: convergence of complex measure} implies\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty}\\mu(A_{i}) = \\mu\\left(\\bigcup_{i=1}^{\\infty}A_{i})\\right) = \\mu\\left(\\bigcup_{i=1}^{\\infty}A_{\\sigma(i)})\\right) = \\sum_{i=1}^{\\infty}\\mu(A_{\\sigma(i)}).\n\\end{align*}\nWe express this by saying that the series in \\eqref{eq: convergence of complex measure} is unconditionally convergent. It is well known that an absolutely convergent series is conditionally convergent, and we will later prove (in \\cref{prop: unconditionally implies absolutely}) that in fact a series is unconditionally convergent if and only if it is absolutely convergent, so \\eqref{eq: convergence of complex measure} is absolutely convergent.\n\n\\begin{definition}\nFor a complex measure $\\mu: \\m{A} \\to \\C$ we associate a new set function $|\\mu|$ given by\n\\begin{align*}\n\t|\\mu|(A) := \\sup\\left\\{ \\sum_{i=1}^{\\infty} |\\mu(A_{i}) | : \\{A_{i}\\}_{i\\in \\N} \\text{ partition of } A \\right\\}, A \\in \\m{A}\n\\end{align*}\nThe measure $|\\mu|$ is called the \\textbf{total variation} (measure) of $\\mu$. The term total variation of $\\mu$ is often used to denote the number $|\\mu|(X)$.\n\\end{definition}\n\n\\begin{theorem}\nThe total variation measure $|\\mu|$ of a complex measure $\\mu$ is a positive measure.\n\\end{theorem}\n\\begin{proof}\nClearly $|\\mu|(\\emptyset)=0$ and $|\\mu|(A) \\le |\\mu|(B)$ whenever $A\\subseteq B$.\n\nLet $\\{A_{i}\\}_{i\\in \\N}$ be a partition of $A\\in \\m{A}$, $\\varepsilon>0$ be given, and for each $i\\in \\N$ choose a partition $\\{B_{ij}\\}_{j \\in \\N}$ of $A_{i}$ such that\n\\begin{align*}\n\t|\\mu|(A_{i}) - \\frac{\\varepsilon}{2^{i}} < \\sum_{j=1}^{\\infty} | \\mu(B_{ij}) |.\n\\end{align*}\nThen $\\{B_{ij}\\}_{i,j\\in \\N}$ is a partition of $A$, and we get\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty} |\\mu|(A_{i}) - \\varepsilon \\le \\sum_{i=1}^{\\infty}\\sum_{j=1}^{\\infty} | \\mu(B_{ij}) | \\le |\\mu|(A),\n\\end{align*}\nand since $\\varepsilon$ was arbitrary, $\\sum_{i=1}^{\\infty} |\\mu|(A_{i}) \\le |\\mu|(A)$.\n\nFor the other inequality let $\\{B_{i}\\}_{i\\in \\N}$ be an arbitrary partition of $A$. For fixed $i$, $\\{B_{i} \\cap A_{j}\\}_{j\\in \\N}$ is a partition of $B_{i}$, and for fixed $j$, $\\{B_{i} \\cap A_{j}\\}_{i\\in \\N}$ is a partition of $A_{j}$. Hence\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty}|\\mu(B_{i})| &= \\sum_{i=1}^{\\infty} \\left| \\sum_{j=1}^{\\infty} \\mu(B_{i} \\cap A_{j}) \\right|\\\\\n\t&\\le \\sum_{i=1}^{\\infty} \\sum_{j=1}^{\\infty} | \\mu(B_{i} \\cap A_{j}) | \\\\\n\t&= \\sum_{j=1}^{\\infty} \\sum_{i=1}^{\\infty} | \\mu(B_{i} \\cap A_{j}) |\\\\\n\t&\\le \\sum_{j=1}^{\\infty} |\\mu(A_{j})|\n\\end{align*}\ntaking the supremum over all partitions $\\{B_{i}\\}_{i\\in \\N}$ of $A$ we get\n\\begin{align*}\n\t|\\mu|(A) \\le \\sum_{j=1}^{\\infty} |\\mu(A_{j})|\n\\end{align*}\nhence equality holds.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%   Pi-inequality  %%%%%%%%%%%%%%%%\n\n\\begin{lemma} \\label{lem: weird pi inequality}\nIf $z_{1}, \\dots, z_{N} \\in \\C$, then there is a subset $S$ of $\\{1, \\dots, N\\}$ for which\n\\begin{align}\n\t\\left| \\sum_{k\\in S} z_{k} \\right| \\ge \\frac{1}{\\pi} \\sum_{k=1}^{\\infty} |z_{k}|. \\label{eq: weird pi inequality}\n\\end{align}\n\\end{lemma}\n\\begin{proof}\nWrite $z_{k}=|z_{k}|e^{i\\alpha_{k}}$. For $-\\pi \\le \\theta \\le \\pi$ let $S(\\theta)$ be the set of all $k\\in \\{1, \\dots, N\\}$ for which $\\cos(\\alpha_{k} - \\theta) > 0$. Then\n\\begin{align*}\n\t\\left| \\sum_{k\\in S(\\theta)} z_{k} \\right| &= \\left| e^{-i\\theta} \\sum_{k\\in S(\\theta)} z_{k} \\right| \\ge \\mathfrak{R} \\left( \\sum_{k\\in S(\\theta)} e^{-i\\theta} z_{k} \\right) = \\sum_{k\\in S(\\theta)} |z_{k}|\\cos(\\alpha_{k} - \\theta) \\\\\n\t&= \\sum_{k=1}^{N} |z_{k}| \\cos^{+}(\\alpha_{k}- \\theta).\n\\end{align*}\nIf $S(\\theta)$ is empty, then the empty sum is 0 by definition.\n\nThe function $\\varphi(\\theta):=\\sum_{k=1}^{N} |z_{k}| \\cos^{+}(\\alpha_{k}- \\theta)$ is continuous on $[-\\pi, \\pi]$, and attains its maximum at a point $\\theta=\\theta_{0}$. Let $S=S(\\theta_{0})$. Then\n\\begin{align*}\n\t\\left| \\sum_{k\\in S} z_{k} \\right| \\ge \\max_{\\theta\\in [-\\pi, \\pi]} \\varphi(\\theta) \\ge \\frac{1}{2\\pi} \\int_{-\\pi}^{\\pi} \\varphi(\\theta)d\\theta = \\sum_{k=1}^{N} |z_{k}| \\frac{1}{2\\pi} \\int_{-\\pi}^{\\pi} \\cos^{+}(\\alpha_{k}-\\theta)d\\theta,\n\\end{align*}\nbut\n\\begin{align*}\n\t\\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi} \\cos^{+}(\\alpha_{k}-\\theta)d\\theta = \\frac{1}{2\\pi}\\int_{-\\pi}^{\\pi} \\cos^{+}(\\theta)d\\theta=\\frac{1}{2\\pi}\\int_{\\frac{-\\pi}{2}}^{\\frac{\\pi}{2}} \\cos(\\theta)d\\theta = \\frac{1}{2}\n\\end{align*}\nso \\eqref{eq: weird pi inequality} holds.\n\\end{proof}\n\nWe can now prove that an unconditionally convergent series is absolutely convergent. We prove an apparently stronger statement.\n\n\\begin{proposition}\\label{prop: unconditionally implies absolutely}\nLet $\\{z_{i}\\}_{i\\in \\N}$ be a sequence of complex numbers such that $\\sum_{i=1}^{\\infty}z_{\\sigma(i)}$ is convergent for all permutations $\\sigma:\\N \\to \\N$ with sum $s_{\\sigma}\\in \\C$. Then $\\sum_{i=1}^{\\infty}|z_{i}|<\\infty$ and $s_{\\sigma}$ is independent of $\\sigma$.\n\\end{proposition}\n\\begin{proof}\nAssume that $\\sum_{i=1}^{\\infty}|z_{i}|=\\infty$, we will then show that there exists a permutation, $\\sigma$, such that $\\sum_{i=1}^{\\infty}|z_{\\sigma(i)}|=\\infty$, which is a contradiction with the assumption. For this, choose an $N_{1}\\in \\N$ such that\n\\begin{align*}\n\t\\sum_{i=1}^{N_{1}}|z_{i}| > \\pi.\n\\end{align*}\nUsing \\Cref{lem: weird pi inequality} there exists a subset $S_{1}\\subseteq \\{1, \\dots, N_{1}\\}$ such that\n\\begin{align*}\n\t\\left|\\sum_{i\\in S_{1}}z_{i}\\right| \\ge \\sum_{i=1}^{N_{1}}|z_{i}| > 1.\n\\end{align*}\nSince $\\sum_{i=N_{1}+1}^{\\infty}|z_{i}|=\\infty$ we choose $N_{2}>N_{1}$ such that $\\sum_{i=N_{1}+1}^{N_{2}}|z_{n}|>\\pi$ and by \\Cref{lem: weird pi inequality} there exists a subset $S_{2}\\subseteq \\{N_{1}+1, \\dots, N_{2}\\}$ such that\n\\begin{align*}\n\t\\left|\\sum_{i\\in S_{2}} z_{i} \\right| > 1.\n\\end{align*}\nRepeating this construction, we get a sequence $S_{1}, S_{2}, \\dots $ of pairwise disjoint and finite subsets of $\\N$ such that\n\\begin{align}\n\t\\left| \\sum_{i\\in S_{n}}z_{i}\\right| > 1, \\quad \\text{for all } n. \\label{eq: all greater than one}\n\\end{align}\nIf $\\N\\setminus \\bigcup_{i=1}^{\\infty}S_{i}=\\{n_{1}, n_{2}, \\dots \\}$ with $n_{i}<n_{j}$ when $i<j$, we define a bijection $\\sigma:\\N \\to \\N$ by arranging $\\N$ in the following way: $S_{1},n_{1}, S_{2},n_{2}, \\dots$, with the elements in $S_{n}$ ordered in the usual fashion. If on the other hand $\\N\\setminus \\bigcup_{i=1}^{\\infty}S_{i}=\\{n_{1}, n_{2}, \\dots, n_{k} \\}$ (i.e. finite) we arrange $\\N$ by the following: $S_{1},n_{1}, \\dots, S_{k},n_{k},S_{k+1},n_{k+1}, \\dots$.\n\nNow $\\sigma$ is a permutation for which $\\sum_{i\\in \\N} z_{\\sigma(i)}$ doesn't converge, because if it did converge, there would exist an $N\\in \\N$ such that\n\\begin{align*}\n\t\\forall n\\ge N, \\; \\forall p\\in \\N: \\left| \\sum_{i=n+1}^{n+p} z_{\\sigma(i)} \\right| \\le \\frac{1}{2},\n\\end{align*}\nbut this contradicts \\eqref{eq: all greater than one}, and we are done.\n\\end{proof}\n\n\nThe following theorem shows that every complex measure is bounded. This property is often expressed by saying that $\\mu$ is of bounded variation.\n\n\\begin{theorem}\\label{thm: total variation is finite}\nIf $\\mu$ is a complex measure on $X$, then $|\\mu|(X)<\\infty$.\n\\end{theorem}\n\\begin{proof}\nFirst suppose that some set $A\\in \\m{A}$ has $|\\mu|(A)=\\infty$. Put $t=\\pi(1+|\\mu(A)|)$. Since $|\\mu|(A)>t$, there is a partition $\\{A_{i}\\}_{i\\in \\N}$ such that\n\\begin{align*}\n\t\\sum_{i=1}^{N}|\\mu(A_{i})| > t\n\\end{align*}\nfor some $N\\in \\N$. We now use \\Cref{lem: weird pi inequality} with $z_{i}=\\mu(A_{i})$ to obtain a subset $S$ of $\\{1, \\dots, N\\}$, such that with $B=\\bigcup_{k\\in S}A_{k}$, we get\n\\begin{align*}\n\t|\\mu(B)| = \\left| \\sum_{k\\in S} \\mu(A_{k}) \\right| \\ge \\frac{1}{\\pi} \\sum_{i=1}^{N}|\\mu(A_{i})| > \\frac{t}{\\pi} > 1.\n\\end{align*}\nWith $C=A\\setminus B$ it follows that\n\\begin{align*}\n\t|\\mu(C)|=|\\mu(A)-\\mu(B)| \\ge |\\mu(B)| - |\\mu(A)| > \\frac{t}{\\pi} - |\\mu(A)| = 1\n\\end{align*}\nThus $A$ can be split up into two disjoint sets $B$ and $C$ with $|\\mu(B)|, |\\mu(C)|>1$. Since $|\\mu|$ is a measure, one of $|\\mu|(B)$ or $|\\mu|(C)$ must be $\\infty$.\n\nSo assume for contradiction that $|\\mu|(X)=\\infty$. We then split $X$ into two disjoint sets $B_{1}$, $C_{1}$ as above with $|\\mu|(B_{1})>1$, $|\\mu|(C_{1})=\\infty$, and split $C_{1}$ into two disjoint sets $B_{2}$, $C_{2}$ as above with $|\\mu|(B_{2})>1$, $|\\mu|(C_{2})=\\infty$. We continue this way and get a countable infinite disjoint family $\\{B_{i}\\}_{i\\in \\N}$ with $|\\mu|(B_{i})>1$ for each $i\\in \\N$. Since $\\mu$ is countably additive\n\\begin{align*}\n\t\\mu\\left( \\bigcup_{i=1}^{\\infty} B_{i} \\right) = \\sum_{i=1}^{\\infty} \\mu(B_{i}).\n\\end{align*}\nBut this series cannot converge, since $\\mu(B_{i})$ does not go towards $0$ as $i\\to \\infty$ so this contradiction shows that $|\\mu|(X)<\\infty$.\n\\end{proof}\n\n\\begin{theorem}\nLet $\\mu$ be a complex measure. Then $|\\mu|$ is the smallest positive measure $\\nu$ satisfying\n\\begin{align*}\n\t|\\mu(A)| \\le \\nu(A), \\quad \\forall A\\in \\m{A}.\n\\end{align*}\n\\end{theorem}\n\\begin{proof}\nClearly $\\mu(A)| \\le |\\mu|(A)$ for all $A\\in \\m{A}$ since $A=A\\cup\\emptyset \\cup \\emptyset \\cup \\dots$ is a partition of $A$.\n\nLet $\\nu$ be a positive measure on $(X, \\m{A})$ satisfying\n\\begin{align}\n\t|\\mu(A)|\\le \\nu(A), \\quad \\forall A\\in \\m{A}. \\label{eq: piajsf}\n\\end{align}\nThe claim is that $|\\mu|(A)\\le \\nu(A)$ for all $A\\in \\m{A}$, and it is enough to prove that\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty}|\\mu(A_{i})| \\le \\nu(A)\n\\end{align*}\nfor every partition $\\{A_{i}\\}_{i\\in \\N}$ of $A$. But this is obvious since the left hand side of \\eqref{eq: piajsf} is majorized by\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty}\\nu(A_{i})=\\nu(A).\n\\end{align*}\n\\end{proof}\n\n\\begin{corollary}\\label{cor: stupid corollary}\nLet $\\mu$ be a complex measure and $A\\in \\m{A}$. Then\n\\begin{align*}\n\t|\\mu|(A)&=\\sup\\left\\{ \\sum_{i=1}^{\\infty} |\\mu(A_{i}) | n\\in \\N, \\{A_{1}, \\dots, A_{n}\\} \\text{ partition of } A \\right\\} \\\\\n\t&=\\sup\\left\\{ \\sum_{i=1}^{\\infty} |\\mu(A_{i}) | n\\in \\N A_{1}, \\dots, A_{n} \\text{ pairwise disjoint subsets of } A \\right\\}\n\\end{align*}\n\\end{corollary}\n\\begin{proof}\nThe idea is, for some countable partition, to construct a finite partition, and a finite family of disjoint sets, which still satisfy the property.\n\nFor $\\varepsilon>0$ there exists a countable partition $\\{A_{i}\\}_{i\\in I}$ of $A$ such that\n\\begin{align*}\n\t\\sum_{i=1}^{\\infty} |\\mu(A_{i})| > |\\mu|(A)-\\frac{\\varepsilon}{2}.\n\\end{align*}\nThe series on the left is convergent since it is by definition less than $|\\mu|(A)$ which we proved was finite. So there exists an $N\\in \\N$ such that\n\\begin{align*}\n\t\\sum_{N+1}^{\\infty} |\\mu(A_{i})| < \\frac{\\varepsilon}{2}.\n\\end{align*}\nThen $A_{1}, \\dots, A_{N}$ are pairwise disjoint subsets of $A$ which satisfy\n\\begin{align*}\n\t\\sum_{i=1}^{N}|\\mu(A_{i})| = \\sum_{i=1}^{\\infty}|\\mu(A_{i})| - \\sum_{i=N+1}^{\\infty}|\\mu(A_{i})| > |\\mu(A_{i})|-\\frac{\\varepsilon}{2}-\\frac{\\varepsilon}{2},\n\\end{align*}\nand with $\\tilde{A}=\\bigcup_{i=N+1}^{\\infty}A_{i}$ we see that $\\{A_{1}, \\dots, A_{N}, \\tilde{A}\\}$ is a finite partition of $A$ with\n\\begin{align*}\n\t\\sum_{i=1}^{N}|\\mu(A_{i})| + |\\mu(\\tilde{A})| > |\\mu|(A)-\\varepsilon.\n\\end{align*}\n\\end{proof}\n\n%%%%%%%%%%%%%%%%   Discussion of the complex measures as a banach space  %%%%%%%%%%%%%%%%\n\nWe denote the set of complex measures on $(X, \\m{A})$ by $M(X, \\m{A})$.\nFor two measures $\\mu, \\nu \\in M(X, \\m{A})$ we define\n\\begin{align*}\n\t(\\mu + \\nu)(A)&:=\\mu(A)+\\nu(A) \\\\\n\t(z\\mu)(A)&:=z\\mu(A)\n\\end{align*}\nfor all $A\\in \\m{A}$, $z\\in \\C$. With these operations, $M(X, \\m{A})$ is a vector space over $\\C$. If we furthermore define\n\\begin{align*}\n\t\\Vert \\mu \\Vert := |\\mu|(X)\n\\end{align*}\nthen $\\m{M}(X, \\m{A})$ becomes a normed linear space.\n\nA complex measure is a bounded function on $(X, \\m{A})$, so $M(X, \\m{A})$ can be seen as a subspace of $B(\\m{A}, \\C)$, the space of bounded functions on $\\m{A}$, which is a Banach space with the uniform norm. We want to prove that $M(X, \\m{A})$ with the total variation norm is a Banach space as a subspace of $B(\\m{A}, \\C)$ equipped with the uniform norm. So first we have to prove that the uniform norm and the total variation norm are equivalent\n\n\\begin{lemma}\nFor $\\mu \\in M(X, \\m{A})$\n\\begin{align*}\n\t\\sup_{A\\in \\m{A}} |\\mu(A)| \\le \\vert \\mu \\Vert \\le \\pi \\sup_{A\\in \\m{A}} |\\mu(A)|\n\\end{align*}\n\\end{lemma}\n\\begin{proof}\nThe first inequality follows from $|\\mu(A)| \\le |\\mu|(A)\\le |\\mu|(X) \\le \\norm{\\mu}$.\n\nLet $A_{1},\\dots,A_{n}\\in \\m{A}$ be pairwise disjoint. By \\Cref{lem: weird pi inequality} there exists a subset $S\\subseteq \\{1,\\dots, n\\}$ such that\n\\begin{align*}\n\t\\sum_{i=1}^{n}|\\mu(A_{i}| \\le \\pi \\left| \\sum_{i\\in S}|\\mu(A_{i}) \\right| = \\pi \\left| \\mu(\\bigcup_{i\\in S} A_{i}) \\right| \\le \\pi \\sup_{A\\in \\m{A}} |\\mu(A)|\n\\end{align*}\nAnd \\cref{cor: stupid corollary} tells us that\n\\begin{align*}\n\t|\\mu|(X)\\le \\pi \\sup_{A\\in \\m{A}} |\\mu(A)|\n\\end{align*}\ncompleting the proof.\n\\end{proof}\n\n%%%%%%%%%%%%%%%%   complex measures form a banach space  %%%%%%%%%%%%%%%%\n\n\\begin{theorem}\n$M(X, \\m{A})$ is a Banach space under the total variation norm.\n\\end{theorem}\n\\begin{proof}\nLet $\\{\\mu_{n}\\}_{n\\in \\N}$ be a sequence of complex measures converging uniformly (since we are in the uniform norm-topology) to a function $\\mu\\in B(\\m{A},\\C)$. We will show that in fact $\\mu\\in M(X, \\m{A})$.\n\nIf $A_{i}, \\dots, A_{m}$ are pairwise disjoint sets from $\\m{A}$, then\n\\begin{align*}\n\t\\mu\\left( \\bigcup_{i=1}^{m} A_{i} \\right)=\\lim_{n\\to \\infty}\\mu_{n}\\left( \\bigcup_{i=1}^{m} A_{i} \\right)=\\lim_{n\\to \\infty} \\left( \\sum_{i=1}^{m} \\mu_{n}(A_{i}) \\right)=\\sum_{i=1}^{m}\\mu(A_{i}),\n\\end{align*}\nhence $\\mu$ is finitely additive. To show that $\\mu$ is countably additive, let $\\{A_{i}\\}_{i\\in \\N}$ be a sequence of pairwise disjoint sets from $\\m{A}$. Given $\\varepsilon>0$ there exists $n_{0}\\in \\N$ such that\n\\begin{align*}\n\t|\\mu(B) - \\mu_{n_{0}}(B)| \\le \\frac{\\varepsilon}{2} \\quad \\text{for all } B\\in \\m{A}.\n\\end{align*}\nSince $\\mu$ was finitely additive, we obtain\n\\begin{align*}\n\t&\\left| \\mu\\left( \\bigcup_{i=1}^{\\infty}A_{i} \\right) - \\sum_{i=1}^{m}\\mu(A_{i}) \\right| = \\left|\\mu\\left( \\bigcup_{i=m+1}^{\\infty}A_{i} \\right) \\right| \\\\\n\t&\\le \\left| \\mu\\left( \\bigcup_{i=m+1}^{\\infty} A_{i} \\right) - \\mu_{n_{0}}\\left( \\bigcup_{i=m+1}^{\\infty} A_{i} \\right) \\right| + \\left| \\mu_{n_{0}}\\left( \\bigcup_{i=m+1}^{\\infty} A_{i} \\right) \\right| \\\\\n\t&\\le \\frac{\\varepsilon}{2} + |\\mu_{n_{0}}|\\left( \\bigcup_{i=m+1}^{\\infty} A_{i} \\right)\n\\end{align*}\nSince $|\\mu_{n_{0}}|$ is a finite positive measure, the last term in the above tends to zero as $m\\to \\infty$. This shows that\n\\begin{align*}\n\t\\left| \\mu\\left( \\bigcup_{i=1}^{\\infty}A_{i} \\right) - \\sum_{i=1}^{m}\\mu(A_{i}) \\right| \\le \\varepsilon\n\\end{align*}\nfor $m$ large enough such that $|\\mu_{n_{0}}|\\left( \\bigcup_{i=m+1}^{\\infty} A_{i} \\right)\\le \\frac{\\varepsilon}{2}$. This shows that $\\mu$ is a complex measure.\n\\end{proof}\n\n\n\\begin{example}\\label{ex: example to prove}\n(a) Let $\\{z_{n}\\}_{n\\in \\N}\\subseteq \\C$ be such that $\\sum_{1}^{\\infty}|z_{n}|<\\infty$. We then define a complex measure on the $\\sigma$-algebra of the power set of $\\N$ by setting $\\mu(\\{n\\}):=z_{n}$, $n\\in \\N$, such that\n\\begin{align*}\n\t\\mu(A)=\\sum_{n\\in A}z_{n}, \\quad A\\subseteq \\N.\n\\end{align*}\nClearly\n\\begin{align*}\n\t|\\mu|(A)=\\sum_{n\\in A}|z_{n}|.\n\\end{align*}\n\n(b)\nIt is easy to see, that if $\\mu_{1}, \\mu_{2}$ are positive measures where one of them is finite, then $\\mu_{1}-\\mu_{2}$ defines a real measure. Furthermore, if $\\lambda_{1}, \\lambda_{2}$ are finite real measures, it is also quite easy to see that $\\lambda_{1}+i\\lambda_{2}$ defines a complex measure. So, let $(X, \\m{A}, \\mu)$ be a measure space with a positive measure $\\mu$ and let $f:X\\to \\C$ be a $\\mu$-integrable function. Then\n\\begin{align*}\n\t\\sigma(A):=\\int_{A}fd\\mu, \\quad A\\in A\n\\end{align*}\nis a complex measure since\n\\begin{align*}\n\t\\int_{A}fd\\mu=\\int_{A}\\mathfrak{R}(f)^{+}d\\mu-\\int_{A}\\mathfrak{R}(f)^{-}d\\mu+i\\int_{A}\\mathfrak{I}(f)^{+}d\\mu-i\\int_{A}\\mathfrak{I}(f)^{-}d\\mu\n\\end{align*}\nand each of the four integrals define a finite positive measure.\nwe will later prove (\\cref{thm: later proof}) that\n\\begin{align*}\n\t|\\sigma|(A)=\\int_{A}|f|d\\mu.\n\\end{align*}\n\\end{example}\n\n\n\\begin{definition}\\label{def: positive and negative variations}\nConsider a finite real measure $\\mu$ on some measurable space $(X, \\m{A})$, define $|\\mu|$ as before, and define\n\\begin{align*}\n\t\\mu^{+}=\\frac{1}{2}(|\\mu|+\\mu), \\qquad \\mu^{-}=\\frac{1}{2}(|\\mu|-\\mu).\n\\end{align*}\nThen both $\\mu^{+}, \\mu^{-}$ are positive measures on $\\m{A}$, and they are bounded by \\cref{thm: total variation is finite}. Furthermore\n\\begin{align*}\n\t\\mu=\\mu^{+}-\\mu^{-}, \\qquad |\\mu|=\\mu^{+}+\\mu^{-}.\n\\end{align*}\nThe measures $\\mu^{+}$ and $\\mu^{-}$ are called the positive and negative variations of $\\mu$, respectively. This representation of $\\mu$ as a difference of the two positive measures $\\mu^{+}$ and $\\mu^{-}$ is known as the \\textbf{Jordan decomposition } of $\\mu$. This representation has a certain minimum property among all representations of $\\mu$ as a defference of two positive measures. This fact will be shown in \\cref{cor: Jordan decomp}.\n\\end{definition}\n\n\n%%%%%%%%%%%%%%%%   ABSOLUTE CONTINUITY  %%%%%%%%%%%%%%%%\n\\subsection{Absolute Continuity}\n\nLet $\\mu$ be a positive measure on a measurable space $(X, \\m{A})$, and let $\\nu$ be an arbitrary measure (i.e. positive, real or complex) on the same space. We say that $\\nu$ is \\textbf{absolutely continuous} with respect to $\\mu$, and write\n\\begin{align*}\n\t\\nu \\ll \\mu\n\\end{align*}\nif\n\\begin{align*}\n\t\\forall A\\in \\m{A}: \\mu(A) = 0 \\Rightarrow \\nu(A) = 0.\n\\end{align*}\nIf there is a set $B\\in \\m{A}$ for which $\\nu(A)=\\nu(A\\cap B)$ for every $B\\in \\m{A}$, we say that $\\nu$ is \\textbf{concentrated} on $B$. We see that $\\nu$ is concentrated on $B$ if and only if $\\nu(A)=0$ for all $A\\in \\m{A}$ for which $A\\cap B=\\emptyset$.\n\nSuppose $\\nu_{1}, \\nu_{2}$ are arbitrary measures on $\\m{A}$, and suppose there exists a pair of disjoint sets $A, B$ such that $\\nu_{1}$ is concentrated on $A$, and $\\nu_{2}$ is concentrated on $B$. Then we say that $\\nu_{1}$ and $\\nu_{2}$ are \\textbf{mutually singular}, and write\n\\begin{align*}\n\t\\nu_{1} \\perp \\nu_{2}.\n\\end{align*}\n\nWhat follows are some elementary properties of these concept.\n\n\\begin{proposition}\\label{prop: abs cont properties}\nSuppose $\\nu, \\nu_{1}$ and $\\nu_{2}$ are arbitrary measures on a measurable space $(X, \\m{A})$, and $\\mu$ is a positive measure. Then\n\\begin{enumerate}\n\\item If $\\nu$ is concentrated on $A$, then so is $|\\nu|$.\n\\item If $\\nu_{1} \\perp \\nu_{2}$ then $|\\nu_{1}| \\perp |\\nu_{2}|$.\n\\item If $\\nu_{1} \\perp \\nu$ and $\\nu_{2} \\perp \\nu$ then $\\nu_{1} + \\nu_{2} \\perp \\nu$.\n\\item If $\\nu_{1} \\ll \\mu$ and $\\nu_{2} \\ll \\mu$ then $\\nu_{1} + \\nu_{2} \\ll \\mu$.\n\\item If $\\nu \\ll \\mu$, then $|\\nu|\\ll \\mu$.\n\\item If $\\nu_{1}\\ll \\mu$ and $\\nu_{2} \\perp \\mu$ then $\\nu_{1} \\perp \\nu_{2}$.\n\\item If $\\nu \\ll \\mu$ and $\\nu \\perp \\mu$, then $\\nu \\equiv 0$.\n\\end{enumerate}\n\\end{proposition}\n\\begin{proof}\n\\begin{enumerate}\n\\item If $B\\cap A=\\emptyset$ and $\\{B_{i}\\}$ is any partition of $B$, then $\\nu(B_{i})=0$ for all $i$, hence $|\\nu|(B)=0$.\n\\item Immediate consequence of $1.$\n\\item There are disjoint sets $A_{1},B_{1}$ such that $\\nu_{1}$ is concentrated on $A_{1}$ and $\\nu$ is concentrated on $B_{1}$, and there are disjoint sets $A_{2},B_{2}$ such that $\\nu_{2}$ is concentrated on $A_{2}$ and $\\nu$ is concentrated on $B_{2}$. But then $\\mu_{1}+\\mu_{2}$ is concentrated on $A:=A_{1} \\cup A_{2}$, and $\\nu$ is concentrated on $B:=B_{1} \\cap B_{2}$, and $A\\cap B= \\emptyset$.\n\\item Trivial by the definition.\n\\item Suppose $\\mu(A)=0$ and $\\{A_{i}\\}$ is a partition of $A$, then $\\mu(A_{i})=0$ for all $i$ and since $\\nu\\ll \\mu$ also $\\nu(A_{i})=0$ for all $i$, this implies that $\\sum|\\nu(A_{i})|=0$ which in turn implies that $|\\nu|(A)=0$.\n\\item There are disjoint sets $A, B$ such that $\\mu$ is concentrated on $A$, and $\\nu_{1}$ is concentrated on $B$. Since $\\nu_{1} \\ll \\mu$, there is a set $C\\subseteq A$ such that $\\nu_{1}$ is concentrated on $B$. But $C\\cap B=\\emptyset$ so $\\nu_{1}, \\nu_{2}$ are mutually singular.\n\\item by $6.$, the assumption of $7.$ implies that $\\nu \\perp \\nu$ which clearly forces $\\nu \\equiv 0$.\n\\end{enumerate}\n\\end{proof}\n\nThe following theorem explains why the word ``continuity'' is used in the relation $\\ll$.\n\n\\begin{theorem}\\label{thm: why it is called absolutely continuous}\nLet $\\mu$ be a positive measure and $\\nu$ a complex measure, both on the measurable space $(X, \\m{A})$. Then the following are equivalent\n\\begin{enumerate}\n\\item $\\nu \\ll \\mu$.\n\\item $\\forall \\varepsilon>0, \\exists \\delta > 0, \\forall A\\in \\m{A} : \\mu(A)<\\delta \\Rightarrow |\\nu(A)|<\\varepsilon$.\n\\end{enumerate}\n\\end{theorem}\n\\begin{proof}\nAssume (2) holds and that $\\mu(A)=0$ for some $A\\in \\m{A}$. Then $|\\nu(A)|<\\varepsilon$ for all $\\varepsilon > 0$, hence $\\nu(A) = 0$.\n\nNow assume that (2) does not hold. Then there is an $\\varepsilon > 0$ and sets $A_{n}\\in \\m{A}$, $n=1, 2, \\dots$ such that\n\\begin{align*}\n\t\\mu(A_{n})<2^{-n}, \\quad \\text{while} \\quad |\\nu(A_{n})| \\ge \\varepsilon.\n\\end{align*}\nLetting\n\\begin{align*}\n\tB_{n}=\\bigcup_{i=n}^{\\infty}A_{i}, \\quad B=\\cap_{n=1}^{\\infty}B_{n}\n\\end{align*}\n(i.e. $B=\\lim\\sup A_{i}$) we get\n\\begin{align*}\n\t\\mu(B_{n})=\\sum_{i=n}^{\\infty}\\mu(A_{i}) < 2^{-n+1}.\n\\end{align*}\nSince $B_{1} \\supseteq B_{2} \\supseteq \\dots$ we obtain $\\mu(B)=0$, and\n\\begin{align*}\n\t|\\nu|(B)=\\lim_{n\\to \\infty} |\\nu|(B_{n})\\ge \\lim_{n\\to \\infty} |\\nu|(A_{n}) \\ge \\lim_{n\\to \\infty} |\\nu(A_{n})| \\ge \\varepsilon.\n\\end{align*}\nOn the other hand, if (1) was true, then, for every measurable subset $E\\subseteq B$, we would have $\\nu(E)=0$, and therefore $|\\nu|(E)=0$, which is a contradiction.\n\\end{proof}\n\n\n\\begin{lemma}\\label{lem: function w}\nIf $\\mu$ is a positive $\\sigma$-finite measure on a measurable space $(X, \\m{A})$, then there is a function $w\\in L^{1}(\\mu)$ such that $0<w(x)<1$, for every $x\\in X$.\n\\end{lemma}\n\\begin{proof}\nAs $\\mu$ is $\\sigma$-finite, there is a countable partition $\\{A_{n}\\}_{n\\in \\N}$ of $X$, such that $\\mu(A_{n})<\\infty$. Put $w_{n}(x)=0$ if $x\\in X\\setminus A_{n}$ and put\n\\begin{align*}\n\tw_{n}(x)=2^{-n}\\min\\{1, \\mu(A_{n})^{-1}\\}\n\\end{align*}\nif $x\\in A_{n}$. Then $w:=\\sum_{i=1}^{\\infty}w_{n}$ has the required property. Indeed $w(x)>0$ since $X$ was the union of the sets $A_{n}$. Also $w(x)<1$ since the $A_{n}$ are disjoint, and $w\\in L^{1}(\\mu)$ since\n\\begin{align*}\n\t\\int w(x)dx = \\sum_{i=1}^{\\infty} \\min\\left\\{\\frac{\\mu(A_{n})}{2^{n}}, \\frac{1}{2^{n}}\\right\\} \\le 1.\n\\end{align*}\n\\end{proof}\n\nThe point of the Lemma is that $\\mu$ can be replaced by a finite measure $\\tilde{\\mu}$ (i.e. $d\\tilde{\\mu}=wd\\mu$), such that $\\mu$ and $\\tilde{\\mu}$ share their null-sets.\n\nWe are now coming to the principal theorem on absolute continuity, and perhaps the most important in measure theory.\n\n\\begin{theorem}[Lebesgue-Radon-Nikodym]\nLet $\\mu$ be a positive $\\sigma$-finite measure on a measurable space $(X,\\m{A})$, and let $\\nu$ be a complex measure on $\\m{A}$. Then\n\\begin{itemize}\n\\item[(a)] there is a unique pair of complex measures $\\nu_{a}$ and $\\nu_{s}$ on $\\m{A}$ such that\n\\begin{align}\n\t\\nu=\\nu_{a}+\\nu_{s}, \\qquad \\nu_{a}\\ll \\mu, \\quad \\nu_{s} \\perp \\mu. \\label{eq: lebesgue decomposition}\n\\end{align}\nIf $\\nu$ is positive or finite, then so are $\\nu_{a}$ and $\\nu_{s}$. Furthermore\n\\item[(b)] there is a unique $h\\in L^{1}(\\mu)$ such that\n\\begin{align}\n\t\\nu_{a}(A)=\\int_{A}h d\\mu \\label{eq: radon-nikodym}\n\\end{align}\nfor every set $A\\in \\m{A}$.\n\\end{itemize}\nEspecially, if $\\nu\\ll \\mu$, i.e. $\\nu_{s}\\equiv 0$, then $\\nu$ is of the form \\eqref{eq: radon-nikodym}. Stated this way, the theorem is often just called the Radon-Nikodym theorem.\n\\end{theorem}\n\\begin{proof}\nFirst we assume that $\\nu$ is a positive bounded measure on $\\m{A}$. Find $w$ associated to $\\mu$ as in \\Cref{lem: function w}. Then $d\\varphi=d\\nu+wd\\mu$ is a positive bounded measure $\\varphi$ on $\\m{A}$ ,and by the definition of the sum of two measures we have\n\\begin{align*}\n\t\\int_{X}fd\\varphi = \\int_{X}fd\\nu + \\int_{X}fwd\\mu\n\\end{align*}\nfor $f=\\ind{A}$, $A\\in \\m{A}$, hence for simple $f$, hence for any non-negative measurable $f$.\n\nIf $f\\in L^{2}(\\varphi)$, the Schwarz inequality gives\n\\begin{align*}\n\t\\left|\\int_{X}fd\\nu \\right| \\le \\int_{X} |f|d\\nu \\le \\int_{X}|f|d\\varphi \\le \\left[ \\int_{X}|f|^{2}d\\varphi \\right]^{1/2} [\\varphi(X)]^{1/2}.\n\\end{align*}\nSo since $\\varphi(X)<\\infty$, we see that\n\\begin{align*}\n\tf\\mapsto \\int_{X}fd\\nu\n\\end{align*}\nis a bounded linear functional of $L^{2}(\\varphi)$. Note that $L^{2}(\\varphi)$ is a Hilbert space and since every bounded linear functional on a Hilbert space $H$ is, by the Riesz representation theorem, given by an inner product with an element of $H$ there exists a $g\\in L^{2}(\\varphi)$ such that\n\\begin{align}\n\t\\int_{X}fd\\nu=\\int_{X}fgd\\varphi \\label{eq: functional as inner product}\n\\end{align}\nfor every $f\\in L^{2}(\\varphi)$.\n\nWe see that $g$ is defined uniquely as an element of $L^{2}(\\varphi)$, though it is only $\\varphi$-a.e. unique as a point function on $X$.\n\nApply \\eqref{eq: functional as inner product} to $f=\\ind{A}$ for any $A\\in \\m{A}$, with $\\varphi(A)>0$. Then \\eqref{eq: functional as inner product} becomes\n\\begin{align*}\n\t\\nu(A)=\\int_{A}gd\\varphi\n\\end{align*}\nand since $0\\le \\nu \\le \\varphi$ we obtain\n\\begin{align*}\n\t0\\le \\frac{1}{\\varphi(A)}\\int_{A}gd\\varphi=\\frac{\\nu(A)}{\\varphi(A)}\\le 1\n\\end{align*}\nHence by \\cref{thm: average lies in S}, $g(x)\\in [0,1]$ for $\\varphi$-a.e $x\\in X$.\nTherefore we may assume that $0\\le g(x) \\le 1$ for every $x\\in X$, without affecting \\eqref{eq: functional as inner product}, and thus write \\eqref{eq: functional as inner product} as\n\\begin{align}\n\t\\int_{X}(1-g)fd\\nu=\\int_{X}fgwd\\mu. \\label{eq: rewriting}\n\\end{align}\n\nLet\n\\begin{align*}\n\tA:=\\{x:0\\le g(x) \\le 1\\}, \\quad S:=\\{x: g(x)=1 \\}\n\\end{align*}\n\nand define positive bounded measures $\\nu_{a}$ and $\\nu_{s}$ by\n\\begin{align*}\n\t\\nu_{a}(B)=\\nu(A\\cap B), \\qquad \\nu_{s}(B)=\\nu(S\\cap B), \\qquad \\forall B\\in \\m{A}\n\\end{align*}\nsuch that $\\nu=\\nu_{a}+\\nu_{s}$.\nIf $f=\\ind{S}$ in \\eqref{eq: rewriting}, the left side becomes $0$, and the right side becomes $\\int_{S}wd\\mu$. So since $w(x)>0$ for all $x\\in X$, we see that $\\mu(S)=0$, and thus $\\nu_{s} \\perp \\mu$.\n\nSince $g$ is bounded, we can replace $f$ in \\eqref{eq: rewriting} by\n\\begin{align*}\n\tf=\\ind{B}(1+g+g^{2}+\\dots+g^{n})\n\\end{align*}\nfor $n=1,2, \\dots$ and $B\\in \\m{A}$. Writing \\eqref{eq: rewriting} we get\n\\begin{align}\n\t\\int_{B}(1-g^{n+1})d\\nu = \\int_{B}g\\left(\\sum_{i=0}^{n}g^{i}\\right)wd\\mu. \\label{eq: hadf}\n\\end{align}\nBy definition $g(x)=1$ on $S$, so $1-g^{n+1}(x)=0$ on $S$. Furthermore $g^{n+1}(x)\\to 0$ monotonically at every point $x\\in A$. With this, the left side of \\eqref{eq: hadf} converges to $\\nu(A\\cap B)=\\nu_{a}(B)$ as $n\\to \\infty$.\n\nThe integrand $\\sum_{1}^{n+1}g$ increase monotonically to a nonnegative measurable limit $h$, and the monotone convergence theorem gives us that the right hand side of \\eqref{eq: hadf} converges to $\\int_{B}hd\\mu$ as $n\\to \\infty$.\n\nWe have thus shown, that \\eqref{eq: radon-nikodym} holds for every $B\\in \\m{A}$. Taking $B=X$, we see that $h\\in L^{1}(\\mu)$, since $\\nu_{a}(X)<\\infty$. Furthermore since \\eqref{eq: radon-nikodym} holds in this setting, we see that $\\nu_{a}\\ll \\mu$ and the proof is complete under the restricted assumptions.\n\nIf $\\nu$ is a complex measure on $\\m{A}$, then $\\nu=\\nu_{1}+i\\nu_{2}$, for two real measures, $\\nu_{1}, \\nu_{2}$, and we can apply the first part of the proof to the positive and negative variations of $\\nu_{1}$ and $\\nu_{2}$. %%%% refer to positive and negative variations.\n\\end{proof}\n\n\n\nThe pair $\\nu_{a}, \\nu_{s}$ is called the \\textbf{Lebesgue decomposition} of $\\nu$ relative to $\\mu$. The pair is unique, as is easily seen, for if $\\nu_{a}',\\nu_{s}'$ is another pair which satisfies \\eqref{eq: lebesgue decomposition}, then\n\\begin{align}\n\t\\nu_{a}'-\\nu_{a}=\\nu_{a}-\\nu_{s}', \\label{eq: unique decomposition}\n\\end{align}\nbut then $\\nu_{a}'-\\nu_{a}\\ll \\mu$ and $\\nu_{s}-\\nu_{s}'\\perp \\mu$, hence from \\cref{prop: abs cont properties}(c), (d) and (g) we see that both sides of \\eqref{eq: unique decomposition} are equal to 0.\n\nThe function $h$ which occurs in \\eqref{eq: radon-nikodym} is called the \\textbf{Radon-Nikodym derivative} of $\\nu_{a}$ with respect to $\\mu$. This we denote by $d\\nu_{a}=hd\\mu$ or perhaps even $h=d\\nu_{a}/ d\\mu$. The above proof is due to von Neumann.\n\n\n%%%%%%%%%%%%%%%%   Consequences of the Lebesgue-Radon-Nikodym theorem  %%%%%%%%%%%%%%%%\n\\subsection{Consequences of the Lebesgue-Radon-Nikodym Theorem}\n\nWe recall that for a complex number $z\\in C$ there is a $\\theta\\in [0,2\\pi)$ such that $z=|z|\\cdot e^{i\\theta}$. We show a similar result for complex measures.\n\n\\begin{theorem}\\label{thm: polar representation}\nLet $\\mu$ be a complex measure on a measurable space $(X, \\m{A})$. Then there exists a measurable function $h$ such that $|h(x)|=1$ for all $x\\in X$ and such that\n\\begin{align}\n\td\\mu=hd|\\mu|. \\label{eq: polar representation}\n\\end{align}\nThis is sometimes referred to as the \\textbf{polar representation} of $\\mu$.\n\\end{theorem}\n\\begin{proof}\nObviously $\\mu \\ll |\\mu|$, so the Radon-Nikodym theorem guarantees the existence of some $h\\in L^{1}(|\\mu|)$ that satisfies \\eqref{eq: polar representation}. We have to show that $|h(x)|=1$ for all $x\\in X$.\n\nLet $A_{r}:=\\{|h(x)|<r\\}$ for some positive $r\\in \\R$, and let $\\{B_{i}\\}$ be a partition of $A_{r}$. Then\n\\begin{align*}\n\t\\sum_{i}|\\mu(B_{i})|=\\sum_{i}\\left| \\int_{B_{i}}hd|\\mu| \\right| \\le \\sum_{i} r|\\mu|(B_{i})=r|\\mu|(A_{r})\n\\end{align*}\nHence $|\\mu|(A_{r})\\le r|\\mu|(A_{r})$. If $r<1$ this forces $|\\mu|(A_{r})=0$, i.e. $\\{|h(x)|<1\\}$ is a $|\\mu|$-null set, hence $|h|\\ge 1$ $|\\mu|$ almost everywhere.\n\nConversely, if $|\\mu|(A)>0$, \\eqref{eq: polar representation} gives\n\\begin{align*}\n\t\\left| \\frac{1}{|\\mu|(A)} \\int_{A}hd|\\mu| \\right|=\\frac{|\\mu(A)|}{|\\mu|(A)}\\le 1\n\\end{align*}\nApplying \\cref{thm: average lies in S} with $S=\\overline{B(0,1)}$ we see that $|h|\\le 1$.\n\nFor $B:=\\{|h(x)|\\neq 1\\}$ we have shown that $|\\mu|(B)=0$, so redefining $h$ such that $h(x)=1$ on $B$ (This does not change \\eqref{eq: polar representation}) we obtain a function that satisfies the desired properties.\n\\end{proof}\n\nWe can now prove the claim in \\cref{ex: example to prove}(b)\n\\begin{theorem}\\label{thm: later proof}\nLet $\\mu$ be a positive measure on a measurable space $(X, \\m{A})$, and $f\\in L^{1}(\\mu)$, then we saw that\n\\begin{align*}\n\t\\sigma(A):=\\int_{A}fd\\mu, \\quad A\\in \\m{A},\n\\end{align*}\nis a complex measure. The total variation is given by\n\\begin{align*}\n\t|\\sigma|(A)=\\int_{A}|f|d\\mu, \\quad A\\in \\m{A}.\n\\end{align*}\n\\end{theorem}\n\\begin{proof}\nBy \\cref{thm: polar representation} there is a function $h$ with $|h|=1$ such that $d\\sigma=hd|\\sigma|$. By assumption $d\\sigma=fd\\mu$ so $hd|\\sigma|=fd\\mu$. Thus $d|\\sigma|=\\overline{h}fd\\mu$ and since $|\\sigma|\\ge 0$ and $\\mu\\ge 0$, it follows that $\\overline{h}f\\ge 0$ $\\mu$ almost everywhere, so that $\\overline{h}g=|g|$ $\\mu$ almost everywhere.\n\\end{proof}\n\\text{ }\\\\\nWe now prove a result about the positive and negative variations of a real measure $\\mu$ from \\cref{def: positive and negative variations}. This result shows that the positive and negative variations are mutually singular, such that all negative mass is concentrated on one set (called $N$) and all positive mass is concentrated on another set (called $P$).\n\n\\begin{theorem}\nLet $\\mu$ be a real measure on a measurable space $(X, \\m{A})$. Then there exist sets $P,N\\in \\m{A}$ such that $P\\cap N=\\emptyset$ and $P\\cup N = X$ and such that the positive and negative variations of $\\mu$ satisfy\n\\begin{align*}\n\t\\mu^{+}(A)=\\mu(P\\cap A), \\quad \\mu^{-}(A)=-\\mu(N\\cap A), \\qquad A\\in \\m{A}.\n\\end{align*}\nThe pair $(P,N)$ is called the \\textbf{Hahn decomposition} of $X$ induced by $\\mu$.\n\\end{theorem}\n\\begin{proof}\nBy \\cref{thm: polar representation} there exists a function $h$ with $|h|=1$ such that $d\\mu=hd|\\mu|$. Since $\\mu$ is real, so is $h$, $\\mu$-almost everywhere, and therefore everywhere by redefining $h$ to be $\\pm1$ on the null set where it is not real.\nHence $h(x)=\\pm 1$. Put\n\\begin{align*}\n\tP:=\\{h(x)=1\\}, \\qquad N:=\\{h(x)=-1\\}.\n\\end{align*}\nBy definition $\\mu^{+}=\\frac{1}{2}(|\\mu|+\\mu)$, and since\n\\begin{align*}\n\t\\frac{1}{2}(1+h)=\\begin{cases}\n\th \\quad \\text{on } P \\\\\n\t0 \\quad \\text{on } N\n\t\\end{cases}\n\\end{align*}\nWe have for any $A\\in \\m{A}$, that\n\\begin{align*}\n\t\\mu^{+}(A)=\\frac{1}{2}\\left( \\int_{A}1d|\\mu|+\\int_{A}hd|\\mu| \\right)=\\frac{1}{2}\\int_{A}(1+h)d|\\mu|=\\int_{P\\cap A}hd|\\mu|=\\mu(P\\cap A).\n\\end{align*}\nSince $\\mu(A)=\\mu(P\\cap A)+\\mu(N\\cap A)$ and since $\\mu=\\mu^{+}-\\mu^{-}$ the rest of the argument follows from the first.\n\\end{proof}\n\\text{ } \\\\\nWe can now show the minimum property of the Jordan decomposition discussed in \\cref{def: positive and negative variations}.\n\n\\begin{corollary}\\label{cor: Jordan decomp}\nIf $\\mu=\\nu_{1}-\\nu_{2}$, where $\\nu_{1},\\nu_{2}$ are positive measures, then $\\nu_{1}\\ge \\mu^{+}$ and $\\nu_{2}\\ge \\mu^{-}$.\n\\end{corollary}\n\\begin{proof}\nSince $\\mu\\le \\nu_{1}$ we get\n\\begin{align*}\n\t\\mu^{+}(A)=\\mu(P\\cap A)\\le \\nu_{1}(P\\cap A)\\le \\nu_{1}(A),\n\\end{align*}\nand the rest follows.\n\\end{proof}\n\n\n\n%%%%%%%%%%%%%%%%   Bounded linear functionals on L^{p}  %%%%%%%%%%%%%%%%\n\\subsection{Bounded Linear Functionals on $L^{p}$}\nLet $\\mu$ be a positive measure, suppose $1\\le p \\le \\infty$, and let $q$ be the exponent conjugate to $p$, i.e. $\\frac{1}{p}+\\frac{1}{q}=1$. Hölder's inequality shows that if $g\\in L^{q}(\\mu)$ and if $T_{g}$ is given by\n\\begin{align*}\n\tT_{g}(f)=\\int_{X}fgd\\mu,\n\\end{align*}\nthen $T_{g}$ is a bounded linear functional on $L^{p}(\\mu)$ with norm at most $\\norm[q]{g}$. But do all bounded linear functionals on $L^{p}(\\mu)$ have this form, and is this form unique? Essentially we are asking whether $L^{p}(\\mu)^{*}=L^{q}(\\mu)$ (isometric isomorphism). We shall now attempt to answer this question.\n\nFor $p=\\infty$ the answer is negative: \n\nLet $f$ be any extreme point in the closed unit ball of $L^{1}([0,1], m)$ where $m$ is the Lebesgue measure. Let $F:[0,1] \\to [0,1]$ be defined by $F(t)=\\int_{[0,t]}|f(x)|dm(x)$, then $F$ is continuous, since for all $t_{0},t_{1}\\in [0,1]$ (assume without loss of generality that $t_{0}<t_{1}$) we have\n\\begin{align*}\n\t|F(t_{0})-F(t_{1})|=\\left| \\int_{t_{1}}^{t_{0}}|f(x)|dm(x) \\right| \\le \\norm[1]{f}|t_{0}-t_{1}|.\n\\end{align*}\nWith this, we also see that $\\norm{F}\\le\\norm[1]{f}<\\infty$. Since $F$ is continuous there exists a $c\\in [0,1]$ such that $F(c)=\\frac{1}{2}\\norm[1]{f}$.\nPut $g_{1}=2f|_{[0,c]}$ and $g_{2}=2f|_{[c,1]}$, thus $g_{1},g_{2}$ both lie in the closed unit ball of $L^{1}([0,1],m)$. But $g_{1}\\neq f \\neq g_{2}$ and $f=\\frac{1}{2}(g_{1}+g_{2})$ which is in contradiction with the assumption that $f$ was in the closed unit ball. Hence the closed unit ball of $L^{1}([0,1], m)$ has no extreme points.\n\nNow if $L^{1}([0,1],m)$ was the dual of a Banach space, its closed unit ball would, by the Krein-Milman theorem, have extreme points, therefore from what we have just shown, $L^{1}([0,1], m)$ is not a dual space of a Banach space.\n\nHowever for $1<p<\\infty$ the answer is affirmative. It is also true for $p=1$ if we assume that the measure in question is $\\sigma$-finite, so we shall confine ourselves to this case.\n\n\\begin{theorem}\\label{thm: p dual of q}\nSuppose $1\\le p < \\infty$, $\\mu$ is a $\\sigma$-finite positive measure on $X$ and $T$ is a bounded linear functional on $L^{p}(\\mu)$. Then there is a unique $g\\in L^{q}(\\mu)$ where $\\frac{1}{p}+\\frac{1}{q}=1$ such that\n\\begin{align}\n\tTf=\\int_{X}fgd\\mu, \\quad f\\in L^{p}(\\mu). \\label{eq: related T and g}\n\\end{align}\nMoreover, if $T$ and $g$ are related as in \\eqref{eq: related T and g}, then\n\\begin{align}\n\t\\norm{T}=\\norm[q]{g}. \\label{eq: equality of norms}\n\\end{align}\nIn other words, $L^{q}(\\mu)=L^{p}(\\mu)^{*}$ (isometric isomorphism).\n\\end{theorem}\n\\begin{proof}\nIf $g,g'$ satisfy \\eqref{eq: related T and g} then for any $A\\in \\m{A}$ with $\\mu(A)<\\infty$ we have \n\\begin{align*}\n\t\\int_{A}g-g'd\\mu=\\int_{A}\\ind{A}gd\\mu-\\int_{A}\\ind{A}g'd\\mu=T(\\ind{A})-T(\\ind{A})=0\n\\end{align*}\nand the $\\sigma$-finiteness of $\\mu$ implies therefore that $g=g'$ $\\mu$ almost everywhere, proving the uniqueness of $g$.\n\nIf \\eqref{eq: related T and g} holds, then Hölder's inequality implies\n\\begin{align*}\n\t\\norm{T}\\le \\norm[q]{g}.\n\\end{align*}\nSo it remains to prove that $g$ exists and that $\\norm{T}\\ge \\norm[q]{g}$. If $\\norm{T}=0$, then \\eqref{eq: related T and g} and \\eqref{eq: equality of norms} holds with $g\\equiv 0$. So we can assume $\\norm{T}>0$.\n\nWe first consider the case when $\\mu(X)<\\infty$. For any $A\\in \\m{A}$ define\n\\begin{align*}\n\t\\nu(A)=T(\\ind{A}).\n\\end{align*}\nNow $T$ is linear, and $\\ind{A\\cup B}=\\ind{A}+\\ind{B}$ if $A\\cap B=\\emptyset$, so $\\nu$ is additive. To show countable additivity, let $\\{A_{i}\\}$ be a countable partition of $A$, let $B_{k}=\\bigcup_{1}^{k}A_{i}$, and observe that\n\\begin{align*}\n\t\\norm[p]{\\ind{A} -  \\ind{B_{k}} }=(\\int_{X}(\\ind{A} -  \\ind{B_{k}})^{p} d\\mu)^{1/p}=\\mu(A-B_{k})^{1/p}\\to 0, \\qquad k\\to \\infty\n\\end{align*}\nHere, the assumption that $p<\\infty$ is used. Since $T$ is continuous we have $\\nu(B_{k})\\to \\nu(A)$, so $\\nu$ is a complex measure. It is clear that $\\nu(A)=0$ whenever $\\mu(A)=0$ since then $\\norm[p]{\\ind{A}}=0$. Hence $\\nu \\ll \\mu$ and the Radon-Nikodym theorem ensures the existence of a function $g\\in L^{1}(\\mu)$  such that for every $A\\in \\m{A}$\n\\begin{align}\n\tT(\\ind{A})=\\int_{A}gd\\mu=\\int_{X}\\ind{A}gd\\mu. \\label{eq: kfa}\n\\end{align}\nBy linearity of $T$ it follows that \n\\begin{align}\n\tTf=\\int_{X}fgd\\mu \\label{eq: T works for all f}\n\\end{align}\nfor every simple measurable function $f$, and so also for every $f\\in L^{\\infty}(\\mu)$ since every such function $f$ is the uniform limit of simple functions $f_{i}$. Note that the uniform convergence of $f_{i}$ to $f$ implies $\\norm[p]{f_{i}-f}\\to 0$ hence $Tf_{i}\\to Tf$ as $i\\to \\infty$.\n\nTo conclude that $g\\in L^{q}(\\mu)$ and that \\eqref{eq: equality of norms} holds, it is best to split the argument into two cases.\n\n1: If $p=1$, \\eqref{eq: kfa} shows that\n\\begin{align*}\n\t\\left| \\int_{A}gd\\mu\\right| \\le \\norm{T}\\cdot \\norm[1]{\\ind{A}}=\\norm{T}\\cdot\\mu(A)\n\\end{align*}\nfor every $A\\in \\m{A}$. By \\cref{thm: average lies in S} $|g(x)|\\le \\norm{T}$ $\\mu$-almost everywhere, hence $\\norm[\\infty]{g}\\le \\norm{T}$.\n\n2: If $1<p<\\infty$ there is a measurable function $x\\mapsto \\alpha(x)$, such that $|\\alpha|=1$ and $\\alpha g=|g|$. Let $A_{n}:=\\{|g(x)|\\le n\\}$ and define $f:=\\ind{A_{n}}|g|^{q-1}\\alpha$. Then $|f|^{p}=|g|^{q}$ on $A_{n}$, $f\\in L^{\\infty}(\\mu)$ and \\eqref{eq: T works for all f} gives us that\n\\begin{align*}\n\t\\int_{A_{n}}|g|^{q}d\\mu=\\int_{X}fgd\\mu=Tf\\le \\norm{T}\\left[ \\int_{A_{n}}|g|^{q}d\\mu \\right]^{1/p},\n\\end{align*}\nhence\n\\begin{align*}\n\t\\int_{X}\\ind{A_{n}}|g|^{q}d\\mu \\le \\norm{T}^{q}, \\qquad n=1,2, \\dots\n\\end{align*}\nWe now apply the monotone convergence theorem to this and obtain $\\norm[q]{g}\\le \\norm{T}$ as wanted. So \\eqref{eq: equality of norms} holds and $g\\in L^{q}(\\mu)$.\n\nIt follows that both sides of \\eqref{eq: T works for all f} are continuous functions on $L^{p}(\\mu)$, they coincide on the dense subset $L^{\\infty}(\\mu)$ of $L^{p}(\\mu)$ so they coincide on all of $L^{p}(\\mu)$ which completes the proof for the case when $\\mu(X)<\\infty$.\n\nIf $\\mu(X)=\\infty$ but $\\mu$ is $\\sigma$-finite choose $w\\in L^{1}(\\mu)$ from \\Cref{lem: function w}. Then $d\\tilde{\\mu}=wd\\mu$ defines a finite measure on $\\m{A}$ and\n\\begin{align*}\n\tF\\mapsto w^{1/p}F\n\\end{align*}\nis a linear isometry of $L^{p}(\\tilde{\\mu})$ onto $L^{p}(\\mu)$, since $w(x)>0$ for all $x\\in X$, as is easily checked.\n\nHence\n\\begin{align*}\n\tS(F)=T(w^{1/p}F)\n\\end{align*}\ndefines a bounded linear functional $S$ on $L^{p}(\\tilde{\\mu})$ with $\\norm{S}=\\norm{T}$.\nThe first part of this proof shows now that there exists a function $G\\in L^{q}(\\tilde{\\mu})$ satisfying\n\\begin{align*}\n\tS(F)=\\int_{X}FGd\\tilde{\\mu}, \\qquad F\\in L^{p}(\\tilde{\\mu})\n\\end{align*}\nLetting $g=w^{1/q}G$ (or if $p=1$, $g=G$), we see that\n\\begin{align*}\n\t\\int_{X}|g|^{q}d\\mu=\\int_{X}|G|d\\tilde{\\mu}=\\norm{S}^{q}=\\norm{T}^{q}\n\\end{align*} \nif $p>1$, whereas $\\norm[\\infty]{g}=\\norm[\\infty]{G}=\\norm{S}=\\norm{T}$ if $p=1$. Thus \\eqref{eq: equality of norms} holds, and since $Gd\\tilde{\\mu}=w^{1/p}gd\\mu$, we at last see\n\\begin{align*}\n\tT(f)=S(w^{-1/p}f)=\\int_{X}w^{-1/p}fGd\\tilde{\\mu}=\\int_{X}fgd\\mu\n\\end{align*}\nfor every $f\\in L^{p}(\\mu)$ as wanted.\n\\end{proof}\n\nThe special case $p=q=2$ is a general fact about Hilbert spaces (recall that $L^{2}(\\mu)$ is a Hilbert space), i.e. any bounded linear functional $T:L^{2}(\\mu)\\to \\C$ is given as the scalar product with an $L^{2}$-function $\\overline{g}$:\n\\begin{align*}\n\tTf=\\int fg d\\mu=\\langle f,\\overline{g} \\rangle\n\\end{align*}\nThis is a consequence of the Riesz Representation theorem.\n\n%%%%%%%%%%%%%%%%  Riesz?Markov?Kakutani representation theorem   %%%%%%%%%%%%%%%%\n\\subsection{The Riesz-Markov Theorem}\nLet $X$ be a locally compact Hausdorff space. \\cref{thm: Riesz-Markov-Kakutani representation theorem} characterizes the \\textbf{positive} linear functionals on $C_{c}(X)$. We are now able to characterize the \\textbf{bounded} linear functionals $T$ on $C_{c}(X)$. Now $C_{c}(X)$ is a dense subspace of $C_{0}(X)$ relative to the supremum norm, so every such $T$ has a unique extension to a bounded linear functional on $C_{0}(X)$ (see theorem 13.3 in \\cite{Musat17}). Hence we can just as well assume we are dealing with the Banach space $C_{0}(X)$.\n\nIf $\\mu$ is a complex Morel measure, \\cref{thm: polar representation} ensures the existence of a complex Borel measurable function $h$ with $|h|=1$ such that $d\\mu=hd|\\mu|$. It is therefore reasonable to define integration with respect to a complex measure $\\mu$ by the formula\n\\begin{align*}\n\t\\int fd\\mu=\\int fhd|\\mu|.\n\\end{align*}\nand we get $\\int \\ind[A] d\\mu=\\mu(A)$. Thus\n\\begin{align*}\n\t\\int_{X}\\ind{A} d(\\mu+\\nu)=(\\mu+\\nu)(A)=\\mu(A)+\\nu(A)=\\int_{X}\\ind{A}d\\mu+\\int_{X} \\ind{A} d\\nu\n\\end{align*}\nwhen $\\mu$ and $\\nu$ are complex measures on $\\m{A}$ and $A\\in \\m{A}$. This leads to the addition formula\n\\begin{align*}\n\t\\int_{X} fd(\\mu+\\nu)=\\int_{X}fd\\mu+\\int_{X}fd\\nu\n\\end{align*}\nwhich is valid for every bounded measurable $f$.\n\nWe will call a complex Borel measure, $\\mu$ on $X$ regular, if $|\\mu|$ is regular in the sense of \\cref{def: regular}. If $\\mu$ is a complex Borel measure on $X$, it is clear that the mapping\n\\begin{align*}\n\tf\\mapsto \\int_{X}fd\\mu\n\\end{align*}\nis a bounded linear functional on $C_{0}(X)$, with norm no larger that $|\\mu|(X)$.\nIt is the content of the Riesz-Markov theorem, that every such bounded linear functional on $C_{0}(X)$ arise in this way.\n\n\n\\begin{theorem}[Riesz-Markov]\\label{thm: Riesz-markov}\nLet $X$ be a locally compact Hausdorff space. For any bounded linear functional $T$ on $C_{0}(X)$ there is a unique regular complex Borel measure $\\mu$ on $X$ such that\n\\begin{align}\n\tTf=\\int_{X}fd\\mu \\label{eq: rep of lin func}\n\\end{align}\nfor every $f\\in C_{0}(X)$. Furthermore\n\\begin{align}\n\t\\norm{T}=|\\mu|(X) \\label{eq: jadfhsadf}\n\\end{align}\n\\end{theorem}\n\\begin{proof}\nFirst, if $T=0$, \\eqref{eq: rep of lin func} is satisfied by $\\mu=0$, so assume $T\\neq 0$.\nTo show uniqueness, assume $\\nu, \\lambda$ are regular complex Borel measures on $X$ satisfying \\eqref{eq: rep of lin func}. It is easy to see that $\\mu:=\\lambda-\\nu$ is also regular. Now since they both satisfy \\eqref{eq: rep of lin func}, we have $\\int_{X}fd\\mu=0$ for all $f\\in C_{0}(X)$, and we have to prove that $\\mu=0$. By \\cref{thm: polar representation} there exists a Borel measurable function $h\\in L^{1}(|\\mu|)$ with $|h|=1$, such that $d\\mu=hd|\\mu|$. For any sequence $\\{f_{n}\\}$ in $C_{0}(X)$ we can then write\n\\begin{align*}\n\t|\\mu|(X)=\\int_{X}(\\overline{h}-f_{n})hd|\\mu|\\le \\int_{X}|\\overline{h}-f_{n}|d|\\mu|,\n\\end{align*}\nand since $C_{c}(X)$ is dense in $L^{1}(|\\mu|)$ (see Theorem 3.14 in \\cite{Rudin87}), $\\{f_{n}\\}$ can be chosen so that the last expression tends to $0$ as $n\\to \\infty$. Thus $|\\mu|(X)=0$, thus $\\mu=0$, which settles the uniqueness.\n\nNow given a bounded linear functional $T$ on $C_{0}(X)$, we can without loss of generality assume that $\\norm{T}=1$. Our aim will be to construct a \\textbf{positive} linear functional $S$ on $C_{c}(X)$ such that\n\\begin{align}\n\t|Tf| \\le S(|f|)\\le \\norm{f}, \\qquad f\\in C_{c}(X), \\label{eq: ineq of lin funcs}\n\\end{align}\nwhere $\\norm{f}$ denotes the supremum norm. Once we have this $S$, we can associate with is a positive Borel measure $\\nu$ as in \\cref{thm: Riesz-Markov-Kakutani representation theorem}. The conclusion of \\cref{thm: Riesz-Markov-Kakutani representation theorem} is that $\\nu$ is regular if $\\nu(X)<\\infty$. Since\n\\begin{align*}\n\t\\nu(X)=\\sup\\{ Sf: 0 \\le f \\le 1,  f\\in C_{c}(X) \\}\n\\end{align*}\nand since $|Sf| \\le 1$ if $\\norm{f} \\le 1$, we see that actually $\\nu(X)\\le 1$.\n\nFrom \\eqref{eq: ineq of lin funcs} we can further deduce that\n\\begin{align*}\n\t|Tf| \\le S(|f|) = \\int_{X} |f| d\\nu = \\norm[1]{f}, \\qquad f\\in C_{c}(X)\n\\end{align*}\nwhere the last norm refers to the space $L^{1}(\\nu)$. Thus $T$ is a linear functional on $C_{c}(X)$ of norm at most $1$ with respect to the $L^{1}(\\nu)$-norm on $C_{c}(X)$. By Hahn-Banach there is a norm-preserving extension of $T$ to a linear functional on $L^{1}(\\nu)$ and therefore \\cref{thm: p dual of q} (the case $p=1$) gives a Borel measurable function $g\\in L^{\\infty}(\\nu)$ with $|g| \\le 1$ such that\n\\begin{align}\n\tTf=\\int_{X}fgd\\nu, \\qquad f\\in C_{c}(X) \\label{eq: idno}\n\\end{align}\nEach side of \\eqref{eq: idno} is a continuous functional on $C_{0}(X)$ and $C_{c}(X)$ is dense in $C_{0}(X)$, hence \\eqref{eq: idno} holds for all $f\\in C_{0}(X)$ and so \\eqref{eq: rep of lin func} holds with $d\\mu=g d\\nu$.\n\nSince $\\norm{T}=1$, \\eqref{eq: idno} shows that\n\\begin{align*}\n\t\\int_{X} |g| d\\nu \\ge \\sup\\{ |Tf| : f\\in C_{0}(X), \\norm{f} \\le 1 \\} = 1.\n\\end{align*}\nBut since $\\nu(X) \\le 1$ and $|g| \\le 1$ this forces $\\nu(X)=1$ and $|g|=1$ $\\nu$-almost everywhere. Thus $d|\\mu| = |g| d\\nu = d\\nu$, by \\cref{thm: later proof} and\n\\begin{align*}\n\t|\\mu| (X) = \\nu(X) = 1 = \\norm{T}\n\\end{align*}\nwhich proves \\eqref{eq: jadfhsadf}.\n\nThus all we have to do, is find a positive linear functional $S$ that satisfies \\eqref{eq: ineq of lin funcs}.\n\nFirst assume that $f\\in C_{c}^{+}(X)$ (the class of all non-negative real members of $C_{c}(X)$), and define\n\\begin{align*}\n\tSf=\\sup\\{ |Th| : h\\in C_{c}(X), |h| \\le f \\}.\n\\end{align*}\nThen $Sf \\ge 0$, $S$ satisfies \\eqref{eq: ineq of lin funcs}, $0 \\le f_{1} \\le f_{2}$ implies $Sf_{1} \\le Sf_{2}$, and $S(cf)=cSf$ if $c$ is a positive constant. We have to show that\n\\begin{align}\n\tS(f+g)=Sf+Sg, \\qquad f,g\\in C_{c}^{+}(X) \\label{eq: linearity}\n\\end{align}\nand then we have to extend $S$ to a linear functional on $C_{c}(X)$.\n\nLet $f,g\\in C_{c}^{+}(X)$. For $\\varepsilon > 0$ there exists $h_{1},h_{2}\\in C_{c}(X)$ such that $|h_{1}|\\le f$, $|h_{2}|\\le g$, and\n\\begin{align*}\n\tSf \\le |Th_{1}| + \\varepsilon, \\qquad Sg \\le |Tg| + \\varepsilon.\n\\end{align*}\nNow there are complex numbers $\\alpha_{i}\\in \\C$, with $|\\alpha_{i}|=1$ such that $\\alpha_{1}T(h_{i})=|T(h_{i})|$ for $i=1,2$.\nThen\n\\begin{align*}\n\tSf+Sg &\\le |T(h_{1})| + |T(h_{2})| + 2\\varepsilon \\\\\n\t&= T(\\alpha_{1}h_{1} + \\alpha_{2}h_{2}) + 2\\varepsilon \\\\\n\t&\\le S(|h_{1}| + |h_{2}|) + 2\\varepsilon \\\\\n\t&\\le S(f+g) + 2\\varepsilon\n\\end{align*}\nhence the inequality $\\ge$ holds in \\eqref{eq: linearity}.\n\nNext, let $h\\in C_{c}(X)$ be such that $|h| \\le f + g$, let $V:=\\{ x: f(x) + g(x) > 0 \\}$, and define\n\\begin{align*}\n\th_{1}(x)&:= \\frac{f(x)h(x)}{f(x)+g(x)}, \\qquad h_{2}(x):=\\frac{g(x)h(x)}{f(x)+g(x)}, \\quad x\\in V \\\\\n\th_{1}&=h_{2}:=0, \\qquad x\\not\\in V.\n\\end{align*}\nIt is clear that $h_{1}$ is continuous at all points of $V$. If $x_{0}\\not\\in V$ then $h(x_{0})=0$, so since $h$ is continuous and $|h_{1}(x)| \\le |h(x)|$ for all $x\\in X$, it follows that $x_{0}$ is a point of continuity of $h_{1}$. Thus $h_{1}\\in C_{c}(X)$ and the same argument applies to $h_{2}$.\nSince $h_{1}+h_{2}=h$ and $|h_{1}| \\le f$, $|h_{2}| \\le g$, we have\n\\begin{align*}\n\t|Th| = |T(h_{1}) + T(h_{2})| \\le |T(h_{1})| + |T(h_{2})| \\le Sf + Sg.\n\\end{align*}\nHence $S(f+g) \\le Sf + Sg$ and we have shown equality in \\eqref{eq: linearity}.\n\nIf $f$ is now a real function $f\\in C_{c}(X)$, define $2f^{+}=|f|+f$. Then $f^{+}\\in C_{c}^{+}(X)$, and if we define $f^{-}$ similarly, then $f^{-}\\in C_{c}^{+}(X)$ and since $f=f^{+}-f^{-}$, it is natural to define\n\\begin{align*}\n\tSf=Sf^{+} - Sf^{-}, \\qquad f\\in C_{c}(X), f \\text{ real}\n\\end{align*}\nand\n\\begin{align*}\n\tS(u+iv)=Su+ iSv.\n\\end{align*}\nSimple algebraic manipulations now show that our extended functional $S$ is linear on $C_{c}(X)$. This completes the proof.\n\\end{proof}\n\n\\end{document}\n\n\n\n\n\n\n", "meta": {"hexsha": "cd5ee096be97aa170b8c05ef03576c2cfb972a49", "size": 49615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/VectorMeasures/Sections/ComplexMeasures.tex", "max_stars_repo_name": "TheTextbook/MeasureTheory", "max_stars_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_stars_repo_licenses": ["MIT"], "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/VectorMeasures/Sections/ComplexMeasures.tex", "max_issues_repo_name": "TheTextbook/MeasureTheory", "max_issues_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_issues_repo_licenses": ["MIT"], "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/VectorMeasures/Sections/ComplexMeasures.tex", "max_forks_repo_name": "TheTextbook/MeasureTheory", "max_forks_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_forks_repo_licenses": ["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.2855407047, "max_line_length": 549, "alphanum_fraction": 0.6356343848, "num_tokens": 19091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.6066398403299207}}
{"text": "\\chapter{Alternative representations of binary relations}\n\n\\begin{thm}\nLet $A$ and~$B$ be fixed sets. The diagram at the figure~\\ref{rels-dia} is\na commutative diagram (in category $\\mathbf{Set}$), every arrow in\nthis diagram is an isomorphism. Every cycle in this diagram is an\nidentity. All ``parallel'' arrows are mutually inverse.\n\nFor a Galois connection~$f$ I denote $f_0$ the lower adjoint and $f_1$ the upper adjoint.\nFor simplicity, in the diagram I equate $\\subsets A$ and $\\mathscr{T}A$.\n\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=1cm, column sep=-1.0cm]\n& \\begin{tabular}{c}binary relations\\\\ between $A$ and $B$\\end{tabular}\n\\arrow[rd, shift left, \"\\Psi_1^{-1}\"]\n\\arrow[ld, shift left, \"\\Psi_2\"] \\\\\n\\begin{tabular}{c}pointfree funcoids\\\\ between\\\\ $\\subsets A$ and $\\subsets B$\\end{tabular}\n\\arrow[ru, shift left, \"\\Psi_2^{-1}\"]\n\\arrow[rr, shift left, \"\\Psi_3\"]\n\\arrow[rd, shift left, \"\\Psi_4\"]\n& & \\begin{tabular}{c}antitone Galois\\\\ connections\\\\ between\\\\ $\\subsets A$ and $\\subsets B$\\end{tabular}\n\\arrow[lu, shift left, \"\\Psi_1\"]\n\\arrow[ll, shift left, \"\\Psi_3^{-1}\"]\n\\arrow[ld, leftrightarrow, \"\\Psi_5=\\Psi_5^{-1}\"]\n\\\\\n& \\begin{tabular}{c}Galois connections\\\\ between $\\subsets A$ and $\\subsets B$\\end{tabular}\n\\arrow[lu, shift left, \"\\Psi_4^{-1}\"]\n\\end{tikzcd}\n\n\\begin{flushleft}\n\\begin{description}\n\\item[$\\Psi_1$] $f\\mapsto\\setcond{(x,y)}{y\\in f_0\\{x\\}}=\\setcond{(x,y)}{x\\in f_1\\{y\\}}$\n\\item[$\\Psi_1^{-1}$] $r\\mapsto\\left(X\\mapsto\\setcond{y\\in B}{\\forall x\\in X:x\\mathrel{r}y}, Y\\mapsto\\setcond{x\\in A}{\\forall y\\in Y:x\\mathrel{r}y}\\right)$\n\\item[$\\Psi_2$] $r\\mapsto(\\subsets A,\\subsets B,\\rsupfun{r},\\rsupfun{r^{-1}})$\n\\item[$\\Psi_2^{-1}$] $f\\mapsto\\setcond{(x,y)}{\\{x\\}\\suprel{f}\\{y\\}}$\n\\item[$\\Psi_3$] $f\\mapsto\\left(X\\mapsto\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x,Y\\mapsto\\bigsqcap_{y\\in\\mathscr{T} Y\\setminus\\{\\bot\\}}\\supfun{f^{-1}}y\\right)=\n  \\left(X\\mapsto\\bigsqcap_{x\\in X}\\supfun{f}\\{x\\},Y\\mapsto\\bigsqcap_{y\\in Y}\\supfun{f^{-1}}\\{y\\}\\right)$\n\\item[$\\Psi_3^{-1}$] $f\\mapsto\\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x,Y\\mapsto\\bigsqcup_{y\\in\\mathscr{T}Y\\setminus\\{\\bot\\}}f_1 y\\right)=\n  \\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in X}f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\{y\\}\\right)$\n\\item[$\\Psi_4$] $f\\mapsto\\left(X\\mapsto\\lnot\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x,Y\\mapsto\\bigsqcap_{y\\in\\mathscr{T} Y\\setminus\\{\\bot\\}}\\supfun{f^{-1}}\\lnot y\\right)=\n  \\left(X\\mapsto\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot\\supfun{f}x,Y\\mapsto\\bigsqcap_{y\\in\\mathscr{T} Y\\setminus\\{\\bot\\}}\\supfun{f^{-1}}\\lnot y\\right)=\n  \\left(X\\mapsto\\lnot \\bigsqcap_{x\\in X}\\supfun{f}\\{x\\},Y\\mapsto\\bigsqcap_{y\\in Y}\\supfun{f^{-1}}\\lnot \\{y\\}\\right)=\n  \\left(X\\mapsto\\bigsqcup_{x\\in X}\\lnot\\supfun{f}\\{x\\},Y\\mapsto\\bigsqcap_{y\\in Y}\\supfun{f^{-1}}\\lnot \\{y\\}\\right)$\n\\item[$\\Psi_4^{-1}$] $f\\mapsto\\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot f_0 x,Y\\mapsto\\bigsqcup_{y\\in\\mathscr{T}Y\\setminus\\{\\bot\\}}f_1\\lnot y\\right)=\n  \\left(\\subsets A,\\subsets B,X\\mapsto\\lnot\\bigsqcap_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x,Y\\mapsto\\bigsqcup_{y\\in\\mathscr{T}Y\\setminus\\{\\bot\\}}f_1\\lnot y\\right)=\n  \\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in X}\\lnot f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\lnot\\{y\\}\\right)=\n  \\left(\\subsets A,\\subsets B,X\\mapsto\\lnot\\bigsqcap_{x\\in X}f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\lnot\\{y\\}\\right)$\n\\item[$\\Psi_5=\\Psi_5^{-1}$] $f\\mapsto(\\mathord{\\lnot}\\circ f_0,f_1\\circ\\mathord{\\lnot})$\n\\end{description}\n\\end{flushleft}\n\n\\caption{\\label{rels-dia}}\n\\end{figure}\n\\end{thm}\n\n\\begin{proof}\nFirst, note that despite we use the notation~$\\Psi_i^{-1}$, it is not yet proved that~$\\Psi_i^{-1}$ is the inverse of~$\\Psi_i$. We will prove it below.\n\nNow prove a list of claims. First concentrate on the upper ``triangle'' of the diagram (the lower one will be considered later).\n\n\\begin{claim}\n$\\setcond{(x,y)}{y\\in f_0\\{x\\}}=\\setcond{(x,y)}{x\\in f_1\\{y\\}}$ when $f$ is an antitone Galois connection between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\n$y\\in f_0\\{x\\}\\Leftrightarrow\\{y\\}\\sqsubseteq f_0\\{x\\}\\Leftrightarrow\\{x\\}\\sqsubseteq f_1\\{y\\}\\Leftrightarrow x\\in f_1\\{y\\}$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\scriptstyle \\left(X\\mapsto\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x,Y\\mapsto\\bigsqcap_{y\\in\\mathscr{T} Y\\setminus\\{\\bot\\}}\\supfun{f^{-1}}y\\right)=\n\\left(X\\mapsto\\bigsqcap_{x\\in X}\\supfun{f}\\{x\\},Y\\mapsto\\bigsqcap_{y\\in Y}\\supfun{f^{-1}}\\{y\\}\\right)$\nwhen $f$ is a pointfree funcoid between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\nIt is enough to prove $\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x = \\bigsqcap_{x\\in X}\\supfun{f}\\{x\\}$ (the rest follows from symmetry).\n$\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x \\sqsubseteq \\bigsqcap_{x\\in X}\\supfun{f}\\{x\\}$ because\n$\\mathscr{T} X\\setminus\\{\\bot\\}\\supseteq\\setcond{\\{x\\}}{x\\in X}$.\n$\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x \\sqsupseteq \\bigsqcap_{x\\in X}\\supfun{f}\\{x\\}$ because\nif $x\\in\\mathscr{T} X\\setminus\\{\\bot\\}$ then we can take $x'\\in x$ that is $\\{x'\\}\\subseteq x$ and thus\n$\\supfun{f}x \\sqsupseteq \\supfun{f}\\{x'\\}$, so\n$\\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}x \\sqsupseteq \\bigsqcap_{x\\in\\mathscr{T} X\\setminus\\{\\bot\\}}\\supfun{f}\\{x'\\} \\sqsupseteq\n\\bigsqcap_{x\\in X}\\supfun{f}\\{x\\}$.\n\\end{claimproof}\n\n\\begin{flushleft}\n\\begin{claim}\n$\\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x,Y\\mapsto\\bigsqcup_{y\\in\\mathscr{T}Y\\setminus\\{\\bot\\}}f_1 y\\right) =\n\\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in X}f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\{y\\}\\right)$\nwhen $f$ is an antitone Galois connection between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\end{flushleft}\n\\begin{claimproof}\nIt is enough to prove $\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x=\\bigsqcup_{x\\in X}f_0\\{x\\}$ (the rest follows from symmetry).\nWe have $\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x\\sqsupseteq\\bigsqcup_{x\\in X}f_0\\{x\\}$ because $\\{x\\}\\in\\mathscr{T}X\\setminus\\{\\bot\\}$.\nLet $x\\in\\mathscr{T}X\\setminus\\{\\bot\\}$. Take $x'\\in X$. We have $f_0 x\\sqsubseteq f_0\\{x'\\}$ and thus\n$f_0 x\\sqsubseteq \\bigsqcup_{x\\in X}f_0\\{x\\}$. So $\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}f_0 x\\sqsubseteq\\bigsqcup_{x\\in X}f_0\\{x\\}$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_3^{-1} = \\Psi_2\\circ\\Psi_1$.\n\\end{claim}\n\\begin{claimproof}\n$\\Psi_2\\Psi_1 f = \\left(\\subsets A,\\subsets B,X\\mapsto\\setcond{y}{\\exists x\\in X:(x,y)\\in\\Psi_1 f},Y\\mapsto\\setcond{x}{\\exists y\\in Y:(x,y)\\in\\Psi_1 f}\\right) =\n\\left(\\subsets A,\\subsets B,X\\mapsto\\setcond{y}{\\exists x\\in X:y\\in f_0\\{x\\}},Y\\mapsto\\setcond{x}{\\exists y\\in Y:x\\in f_1\\{y\\}}\\right) =\n\\left(\\subsets A,\\subsets B,X\\mapsto\\bigsqcup_{x\\in X}f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\{y\\}\\right) =\n\\Psi_3^{-1} f$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_3 = \\Psi_1^{-1}\\circ\\Psi_2^{-1}$.\n\\end{claim}\n\\begin{claimproof}\n$\\Psi_1^{-1}\\Psi_2^{-1} f = \n\\left(X\\mapsto\\setcond{y\\in B}{\\forall x\\in X:\\{x\\}\\suprel{f}\\{y\\}}, Y\\mapsto\\setcond{x\\in A}{\\forall y\\in Y:\\{x\\}\\suprel{f}\\{y\\}}\\right) =\n\\left(X\\mapsto\\setcond{y\\in B}{\\forall x\\in X:y\\in\\supfun{f}\\{x\\}}, Y\\mapsto\\setcond{x\\in A}{\\forall y\\in Y:x\\in\\supfun{f^{-1}}\\{y\\}}\\right) =\n\\left(X\\mapsto\\bigsqcap_{x\\in X}\\supfun{f}\\{x\\},Y\\mapsto\\bigsqcap_{y\\in Y}\\supfun{f^{-1}}\\{y\\}\\right) = \\Psi_3 f$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_1$ maps antitone Galois connections between~$\\subsets A$ and~$\\subsets B$ into binary relations between~$A$ and~$B$.\n\\end{claim}\n\\begin{claimproof}\nObvious.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_1^{-1}$ maps binary relations between~$A$ and~$B$ into antitone Galois connections between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\nWe need to prove $Y\\subseteq\\setcond{y\\in B}{\\forall x\\in X:x\\mathrel{r}y}\\Leftrightarrow X\\subseteq\\setcond{x\\in A}{\\forall y\\in Y:x\\mathrel{r}y}$.\nAfter we equivalently rewrite it:\n\\[\\forall y\\in Y \\forall x\\in X:x\\mathrel{r}y\\Leftrightarrow\\forall x\\in X\\forall y\\in Y:x\\mathrel{r}y\\]\nit becomes obvious.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_2$ maps binary relations between~$A$ and~$B$ into pointfree funcoids between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\nWe need to prove that $f=(\\subsets A,\\subsets B,\\supfun{f},\\supfun{f^{-1}})$ is a pointfree funcoids that is $Y\\nasymp\\supfun{f}X\\Leftrightarrow X\\nasymp\\supfun{f^{-1}}Y$. Really, for every\n$X\\in\\mathscr{T}A$, $Y\\in\\mathscr{T}B$ \n\\begin{multline*}\nY\\nasymp\\supfun fX\\Leftrightarrow Y\\nasymp\\rsupfun rX\\Leftrightarrow Y\\nasymp\\supfun rX\\Leftrightarrow\\\\\nX\\nasymp\\supfun{r^{-1}}Y\\Leftrightarrow X\\nasymp\\rsupfun{r^{-1}}Y\\Leftrightarrow X\\nasymp\\supfun{f^{-1}}Y.\n\\end{multline*}\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_2^{-1}$ maps pointfree funcoids between~$\\subsets A$ and~$\\subsets B$ into binary relations between~$A$ and~$B$.\n\\end{claim}\n\\begin{claimproof}\nSuppose $f\\in\\mathsf{pFCD}(\\mathscr{T}A,\\mathscr{T}B)$ and prove\nthat the relation defined by the formula~$\\Psi_2^{-1}$ exists.\nTo prove it, it's enough to show that $y\\in\\supfun f\\{x\\}\\Leftrightarrow x\\in\\supfun{f^{-1}}\\{y\\}$.\nReally, \n\\[\ny\\in\\supfun f\\{x\\}\\Leftrightarrow\\{y\\}\\nasymp\\supfun f\\{x\\}\\Leftrightarrow\\{x\\}\\nasymp\\supfun{f^{-1}}\\{y\\}\\Leftrightarrow x\\in\\supfun{f^{-1}}\\{y\\}.\n\\]\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_3$ maps pointfree funcoids between~$\\subsets A$ and~$\\subsets B$ into antitone Galois connections between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\nBecause $\\Psi_3 = \\Psi_1^{-1}\\circ\\Psi_2^{-1}$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_3^{-1}$ maps antitone Galois connections between~$\\subsets A$ and~$\\subsets B$ into pointfree funcoids between~$\\subsets A$ and~$\\subsets B$.\n\\end{claim}\n\\begin{claimproof}\nBecause $\\Psi_3^{-1} = \\Psi_2\\circ\\Psi_1$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_2$ and $\\Psi_2^{-1}$ are mutually inverse.\n\\end{claim}\n\\begin{claimproof}\nLet $r_{0}\\in\\subsets(A\\times B)$ and $f\\in\\mathsf{pFCD}(\\mathscr{T}A,\\mathscr{T}B)$\ncorresponds to~$r_{0}$ by the formula~$\\Psi_2$; let $r_{1}\\in\\subsets(A\\times B)$\ncorresponds to~$f$ by the formula~$\\Psi_2^{-1}$. Then $r_{0}=r_{1}$\nbecause \n\\[\n(x,y)\\in r_{0}\\Leftrightarrow y\\in\\rsupfun{r_{0}}\\{x\\}\\Leftrightarrow y\\in\\supfun f\\{x\\}\\Leftrightarrow(x,y)\\in r_{1}.\n\\]\n\nLet now $f_{0}\\in\\mathsf{pFCD}(\\mathscr{T}A,\\mathscr{T}B)$ and $r\\in\\subsets(A\\times B)$\ncorresponds to~$f_{0}$ by the formula~$\\Psi_2^{-1}$; let $f_{1}\\in\\mathsf{pFCD}(\\mathscr{T}A,\\mathscr{T}B)$\ncorresponds to~$r$ by the formula~$\\Psi_2$. Then $(x,y)\\in r\\Leftrightarrow y\\in\\supfun{f_{0}}\\{x\\}$\nand $\\supfun{f_{1}}=\\rsupfun r$; thus \n\\[\ny\\in\\supfun{f_{1}}\\{x\\}\\Leftrightarrow y\\in\\rsupfun r\\{x\\}\\Leftrightarrow(x,y)\\in r\\Leftrightarrow y\\in\\supfun{f_{0}}\\{x\\}.\n\\]\nSo $\\supfun{f_{0}}=\\supfun{f_{1}}$. Similarly $\\supfun{f_{0}^{-1}}=\\supfun{f_{1}^{-1}}$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_1$ and $\\Psi_1^{-1}$ are mutually inverse.\n\\end{claim}\n\\begin{claimproof}\nLet $r_0\\in\\subsets(A\\times B)$ and $f\\in\\mathscr{T}A\\otimes\\mathscr{T}B$\ncorresponds to~$r_{0}$ by the formula~$\\Psi_1^{-1}$; let $r_{1}\\in\\subsets(A\\times B)$\ncorresponds to~$f$ by the formula~$\\Psi_1$. Then $r_{0}=r_{1}$ because\n\\[\n(x,y)\\in r_1 \\Leftrightarrow y\\in f_0\\{x\\} \\Leftrightarrow y\\in\\setcond{y\\in B}{x\\mathrel{r_0}y} \\Leftrightarrow x\\mathrel{r_0}y.\n\\]\n\nLet now $f_{0}\\in\\mathscr{T}A\\otimes\\mathscr{T}B$ and $r\\in\\subsets(A\\times B)$\ncorresponds to~$f_{0}$ by the formula~$\\Psi_1$; let $f_{1}\\in\\mathscr{T}A\\otimes\\mathscr{T}B$\ncorresponds to~$r$ by the formula~$\\Psi_1^{-1}$. Then $f_0=f_1$ because\n\\begin{multline*}\nf_{10} X = \\setcond{y\\in B}{\\forall x\\in X:x\\mathrel{r}y} = \\setcond{y\\in B}{\\forall x\\in X:y\\in f_{00}\\{x\\}} = \\\\\n\\bigsqcap_{x\\in X}f_{00}\\{x\\} = \\text{(obvious~\\ref{polar-flip})} = f_{00}X.\n\\end{multline*}\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_3$ and $\\Psi_3^{-1}$ are mutually inverse.\n\\end{claim}\n\\begin{claimproof}\nBecause $\\Psi_3^{-1} = \\Psi_2\\circ\\Psi_1$ and $\\Psi_3 = \\Psi_1^{-1}\\circ\\Psi_2^{-1}$\nand that $\\Psi_2^{-1}$ is the inverse of $\\Psi_2$ and $\\Psi_3^{-1}$ is the inverse of $\\Psi_3$ were proved above.\n\\end{claimproof}\n\nNow switch to the lower ``triangle'':\n\n\\begin{flushleft}\n\\begin{claim}\n$\\left(X\\mapsto\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot f_0 x,Y\\mapsto\\bigsqcup_{y\\in\\mathscr{T}Y\\setminus\\{\\bot\\}}f_1\\lnot y\\right)=\\left(X\\mapsto\\bigsqcup_{x\\in X}\\lnot f_0\\{x\\},Y\\mapsto\\bigsqcup_{y\\in Y}f_1\\lnot\\{y\\}\\right)$.\n\\end{claim}\n\\end{flushleft}\n\\begin{claimproof}\nIt is enough to prove $\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot f_0 x = \\bigsqcup_{x\\in X}\\lnot f_0\\{x\\}$ for a Galois connection~$f$\n(the rest follows from symmetry).\n\n$\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot f_0 x \\sqsupseteq \\bigsqcup_{x\\in X}\\lnot f_0\\{x\\}$ because $\\{x\\}\\in\\mathscr{T}X\\setminus\\{\\bot\\}$.\nIf $x\\in\\mathscr{T}X\\setminus\\{\\bot\\}$ then there exists $x'\\in\\{x\\}$ and thus $\\lnot f_0\\{x'\\}\\sqsupseteq \\lnot f_0 x$. Thus\n$\\lnot f_0 x \\sqsubseteq \\bigsqcup_{x\\in X} \\lnot f_0 \\{x\\}$ and so\n$\\bigsqcup_{x\\in\\mathscr{T}X\\setminus\\{\\bot\\}}\\lnot f_0 x \\sqsubseteq \\bigsqcup_{x\\in X}\\lnot f_0\\{x\\}$.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_5$ is self-inverse.\n\\end{claim}\n\\begin{claimproof}\nObvious.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_4 = \\Psi_5\\circ\\Psi_3$.\n\\end{claim}\n\\begin{claimproof}\nEasily follows from symmetry.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_4^{-1} = \\Psi_3^{-1}\\circ\\Psi_5^{-1}$.\n\\end{claim}\n\\begin{claimproof}\nEasily follows from symmetry.\n\\end{claimproof}\n\n\\begin{claim}\n$\\Psi_4$ and $\\Psi_4^{-1}$ are mutually inverse.\n\\end{claim}\n\\begin{claimproof}\nFrom two above claims and the fact that\n$\\Psi_3^{-1}$ is the inverse of $\\Psi_3$ and $\\Psi_5^{-1}$ is the inverse of $\\Psi_5$ proved above.\n\\end{claimproof}\n\nNote that now we have proved that $\\Psi_i$ and $\\Psi_i^{-1}$ are mutually inverse for all $i=1,2,3,4,5$.\n\n\\begin{claim}\nFor every path of the diagram on figure~\\ref{rels-dia2} started with the circled node, the corresponding morphism is with which the node is labeled.\n\\begin{figure}[ht]\n\\begin{tikzcd}[row sep=1cm, column sep=0.5cm]\n& \\circled{1}\n\\arrow[rd, shift left, \"\\Psi_1^{-1}\"]\n\\arrow[ld, shift left, \"\\Psi_2\"] \\\\\n\\Psi_2\n\\arrow[ru, shift left, \"\\Psi_2^{-1}\"]\n\\arrow[rr, shift left, \"\\Psi_3\"]\n\\arrow[rd, shift left, \"\\Psi_4\"]\n& & \\Psi_1^{-1}\n\\arrow[lu, shift left, \"\\Psi_1\"]\n\\arrow[ll, shift left, \"\\Psi_3^{-1}\"]\n\\arrow[ld, leftrightarrow, \"\\Psi_5=\\Psi_5^{-1}\"]\n\\\\\n& \\Psi_5\\circ\\Psi_1^{-1}\n\\arrow[lu, shift left, \"\\Psi_4^{-1}\"]\n\\end{tikzcd}\n\\caption{\\label{rels-dia2}}\n\\end{figure}\n\\end{claim}\n\\begin{claimproof}\nTake into account that $\\Psi_3^{-1} = \\Psi_2\\circ\\Psi_1$, $\\Psi_4 = \\Psi_5\\circ\\Psi_3$\nand thus also $\\Psi_4\\circ\\Psi_2 = \\Psi_5\\circ\\Psi_1^{-1}$.\nNow prove it by induction on path length.\n\\end{claimproof}\n\n\\begin{claim}\nEvery cycle in the diagram at figure~\\ref{rels-dia} is identity.\n\\end{claim}\n\\begin{claimproof}\nFor cycles starting at the top node it follows from the previous claim.\nFor arbitrary cycles it follows from theorem~\\ref{rehash-isos}.\n\\end{claimproof}\n\n\\begin{claim}\nThe diagram at figure~\\ref{rels-dia} is commutative.\n\\end{claim}\n\\begin{claimproof}\nFrom the previous claim.\n\\end{claimproof}\n\n\\end{proof}\n\n\\begin{prop}\nWe equate the set of binary relations between~$A$ and~$B$ with $\\mathbf{Rld}(A,B)$.\n$\\Psi_2$ and~$\\Psi_2^{-1}$ from the diagram at figure~\\ref{rels-dia} preserve composition and identities (that are functors\nbetween categories $\\mathbf{Rel}$ and $(A,B)\\mapsto\\mathsf{pFCD}(\\mathscr{T}A,\\mathscr{T}B)$) and also reversal ($f\\mapsto f^{-1}$).\n\\end{prop}\n\n\\begin{proof}\nLet $\\supfun f=\\rsupfun p$ and $\\supfun g=\\rsupfun q$. Then $\\supfun{g\\circ f}=\\supfun g\\circ\\supfun f=\\rsupfun q\\circ\\rsupfun p=\\rsupfun{q\\circ p}$.\nLikewise $\\supfun{(g\\circ f)^{-1}}=\\rsupfun{(q\\circ p)^{-1}}$. So\n$\\Phi_2$ preserves composition.\n\nLet $p=1_{\\mathbf{Rel}}^{A}$ for some set~$A$. Then $\\supfun f=\\rsupfun p=\\rsupfun{1_{\\mathbf{Rel}}^{A}}=\\id_{\\subsets A}$\nand likewise $\\supfun{f^{-1}}=\\id_{\\subsets A}$, that is $f$ is\nan identity pointfree funcoid. So $\\Phi_2$ preserves identities.\n\nThat $\\Phi_2^{-1}$ preserves composition and identities follows from the fact that it is an isomorphism.\n\nThat is preserves reversal follows from the formula $\\supfun{f^{-1}}=\\rsupfun{p^{-1}}$.\n\\end{proof}\n\n\\begin{prop}\nThe bijections $\\Psi_2$ and~$\\Psi_2^{-1}$ from the diagram at figure~\\ref{rels-dia} preserves monovaluedness\nand injectivity.\\end{prop}\n\\begin{proof}\nBecause it is a functor which preserves reversal.\\end{proof}\n\\begin{prop}\nThe bijections $\\Psi_2$ and~$\\Psi_2^{-1}$ from the diagram at figure~\\ref{rels-dia} preserves domain\nan image.\\end{prop}\n\\begin{proof}\n$\\im f=\\supfun f\\top=\\rsupfun p\\top=\\im p$, likewise for domain.\\end{proof}\n\\begin{prop}\nThe bijections $\\Psi_2$ and~$\\Psi_2^{-1}$ from the diagram at figure~\\ref{rels-dia} maps cartesian\nproducts to corresponding funcoidal products.\\end{prop}\n\\begin{proof}\n$\\supfun{A\\times^{\\mathsf{FCD}}B}X=\\begin{cases}\nB & \\text{if }X\\nasymp A\\\\\n\\bot & \\text{if }X\\asymp A\n\\end{cases}=\\rsupfun{A\\times B}X$. Likewise $\\supfun{(A\\times^{\\mathsf{FCD}}B)^{-1}}Y=\\rsupfun{(A\\times B)^{-1}}Y$.\\end{proof}\n\nLet $\\Phi$ map a pointfree funcoid whose first component is~$c$ into the Galois connection whose lower adjoint is~$c$.\nThen $\\Phi$ is an isomorphism (theorem~\\ref{bfunc-is-adj}) and\n$\\Phi^{-1}$ maps a Galois connection whose lower adjoint is~$c$ into the pointfree funcoid whose first component is~$c$.\n\nInformally speaking, $\\Phi$ replaces a relation~$r$ with its complement relations~$\\lnot r$. Formally:\n\n\\begin{prop}\n~\n\\begin{enumerate}\n\\item For every path~$P$ in the diagram at figure~\\ref{rels-dia} from binary relations between $A$ and $B$\nto pointfree funcoids between $\\subsets A$ and $\\subsets B$\nand every path~$Q$ in the diagram at figure~\\ref{rels-dia} from\nGalois connections between $\\subsets A$ and $\\subsets B$\nto binary relations between $A$ and $B$,\nwe have $Q\\Phi P r = \\lnot r$.\n\n\\item For every path~$Q$ in the diagram at figure~\\ref{rels-dia} from binary relations between $A$ and $B$\nto pointfree funcoids between $\\subsets A$ and $\\subsets B$\nand every path~$P$ in the diagram at figure~\\ref{rels-dia}\nfrom Galois connections between $\\subsets A$ and $\\subsets B$\nto binary relations between $A$ and $B$,\nwe have $P\\Phi^{-1} Q r = \\lnot r$.\n\\end{enumerate}\n\\end{prop}\n\n\\begin{proof}\nWe will prove only the second ($P\\circ \\Phi^{-1}\\circ Q = \\lnot$), because the first ($Q\\circ\\Phi\\circ P= \\lnot$)\ncan be obtained from it by inverting the morphisms (and variable replacement).\n\nBecause the diagram is commutative, it is enough to prove it for some fixed~$P$ and~$Q$.\nFor example, we will prove $\\Psi_2^{-1} \\Phi^{-1} \\Psi_4 \\Psi_2 r = \\neg r$.\n\n$\\Psi_4 \\Psi_2 r = \\left( X \\mapsto \\neg \\bigsqcap_{x \\in X} \\rsupfun{r}\n\\{ x \\} , Y \\mapsto \\bigsqcap_{y \\in Y} \\rsupfun{r} \\neg \\{ y \\} \\right)$.\n\n$\\Phi^{-1} \\Psi_4 \\Psi_2 r$ is pointfree funcoid $f$ with $\\supfun{f}\n= X \\mapsto \\neg \\bigsqcap_{x \\in X} \\rsupfun{r} \\{ x \\}$.\n\n$\\Psi_2^{-1} \\Phi^{-1} \\Psi_4 \\Psi_2 r$ is the relation consisting of $(x ,\ny)$ such that $\\{ x \\} \\suprel{f} \\{ y \\}$ what is equivalent to: $\\{ y \\}\n\\nasymp \\supfun{f} \\{ x \\}$; $\\{ y \\} \\nasymp \\neg \\rsupfun{r} \\{ x \\}$; $\\{ y \\} \\nsqsubseteq \\rsupfun{r} \\{ x \\}$; $y \\notin \\rsupfun{r} \\{ x \\}$.\n\nSo $\\Psi_2^{-1} \\Phi^{-1} \\Psi_4 \\Psi_2 r = \\neg r$.\n\\end{proof}\n\n\\begin{prop}\n$\\Phi$ and $\\Phi^{-1}$ preserve composition.\n\\end{prop}\n\n\\begin{proof}\nBy definitions of compositions and the fact that both pointfree funcoids and Galois connections are determined by the first component.\n\\end{proof}\n", "meta": {"hexsha": "d9e1b701349f04f488351f33ee8e5dfa17bbb848", "size": 19657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap-alt-bin.tex", "max_stars_repo_name": "vporton/algebraic-general-topology", "max_stars_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-06-26T00:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T04:56:16.000Z", "max_issues_repo_path": "chap-alt-bin.tex", "max_issues_repo_name": "vporton/algebraic-general-topology", "max_issues_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-12-30T07:16:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T02:05:02.000Z", "max_forks_repo_path": "chap-alt-bin.tex", "max_forks_repo_name": "vporton/algebraic-general-topology", "max_forks_repo_head_hexsha": "d1d02a6515a6dabbc5d30b0c00a3e6a9878b36b1", "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": 48.1789215686, "max_line_length": 238, "alphanum_fraction": 0.6820471079, "num_tokens": 8084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544824, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.606639829385172}}
{"text": "\\section{Theory}\n\\subsection{Analysis of Stage 1 \\ref{sec:stage1}} \nThis section focuses on assessing the quality of the basis given\nby Proto-Algorithm \\ref{alg:proto-algorithm}. More precisely, we want to prove rigorous bounds on the\napproximation error\n\\begin{equation}\\label{eq:range-error}\n\\|\\mtx{A}-\\mtx{Q}\\mtx{Q}^\\adj\\mtx{A}\\|\n\\end{equation}\nwhere $\\|\\cdot\\|$ denotes either the operator norm or Frobenius norm.\n\nWe will split the argument into two parts \\footnote{The authors\nargue that this bipartite proof\nis common in the literature of randomized linear algebra}:\n\\begin{enumerate}\n  \\item Provide a generic error bound that depends on the interaction\n  between the test matrix $\\mtx{\\Omega}$ and the right and left\n  singular values of $\\mtx{A}$. \\footnote{Note that we do not deal\n  with randomness yet.} \n  \\item Estimate the error using the distribution of the random matrix.\n  We provide both expectation and probability tail bounds for the error.\n\\end{enumerate}\n\n\\subsubsection{(1) Error bounds via Linear Algebra}\nAs we aim to compute a rank-$k$ approximation of $\\mtx{A}$, we appropiately\npartition the exact SVD as\n\\begin{equation}\n\\label{eq:part}\n\\begin{array}{@{}c@{}r@{}c@{}c@{}c@{}c@{}c}\n        && k & n - k && n & \\\\\n    \\mtx{A} = \\mtx{U} &\\left. \\begin{array}{c} \\\\ \\\\ \\end{array} \\!\\!\\! \\right[ &\n    \\begin{array}{c} \\mtx{\\Sigma}_1 \\\\ \\phantom{\\mtx{\\Sigma}_2} \\end{array} &\n    \\begin{array}{c} \\phantom{\\mtx{\\Sigma}_1} \\\\ \\mtx{\\Sigma}_2 \\end{array} &\n    \\left] \\!\\!\\! \\begin{array}{c} \\\\ \\\\ \\end{array} \\right. &\n    \\left[\\begin{array}{c} \\mtx{V}_{1}^{\\adj} \\\\ \\mtx{V}_{2}^{\\adj}\\end{array}\\right]\\,\n    & \\begin{array}{c} k \\\\ n - k \\\\ \\end{array}\n\\end{array}\n\\end{equation}\n\nNow, let $\\mtx{\\Omega}_i=\\mtx{V}_i\\mtx{\\Omega}$ for $i=1,2$. Express\n$\\mtx{Y}=\\mtx{A}\\mtx{\\Omega}$ as\n\\begin{equation*} \\label{eqn:X-struct}\n    \\begin{array}{@{}c@{}c@{}c}\n    & \\ell & \\\\\n    \\mtx{Y} = \\mtx{A}\\mtx{\\Omega} =\n        \\mtx{U} \\left. \\begin{array}{@{}c} \\\\ \\\\ \\end{array} \\right[ &\n    \\begin{array}{c} \\mtx{\\Sigma}_1 \\mtx{\\Omega}_1 \\\\\n    \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2 \\end{array} &\n    \\left] \\begin{array}{c} k \\\\ n - k \\end{array} \\right.\n    \\end{array}\n\\end{equation*}\nwhere $\\mtx{\\Sigma}_1\\mtx{\\Omega}_1$ controls most of the action of $\\mtx{Y}$,\nand $\\mtx{\\Sigma}_2\\mtx{\\Omega}_2$ is a small perturbation.\n\nThe Proto-Algorithm \\ref{alg:proto-algorithm}\n computes an orthogonal basis $\\mtx{Q}$ of $\\Ima(\\mtx{Y})$. In other\nwords, we can express the orthogonal projection to $\\Ima(\\mtx{Y})$ as\n$\\mtx{P}_{\\mtx{Y}} = \\mtx{P}_{\\Ima(\\mtx{Y})} = \\mtx{Q}\\mtx{Q}^\\adj$\n\\footnote{We simplify the notation of the orthogonal projectoin to\n$\\mtx{P}_{\\mtx{Y}}$}.\nThe following Theorem \\ref{thm:main-error-bd} bounds the squared\nerror provides a deterministic error bound to the squared error.\n\\begin{theorem}[Deterministic error bound] \\label{thm:main-error-bd} %\\\\\nWe have that\n\\begin{equation}\n\\label{eq:main-error-bd}\n\\triplenorm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A} }^2\n    \\leq \\triplenorm{\\mtx{\\Sigma}_2}^2 + \n    \\smtriplenorm{\\mtx{\\Sigma}_2\\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv}^2,\n\\end{equation}\nwhere $\\triplenorm{\\cdot}$ denotes either the spectral norm or the\nFrobenius norm.\n\\end{theorem}\n\n\\begin{remark} \\rm\n Note that $\\mtx{\\Sigma}_1$ does not appear in the error bound.\n\\end{remark}\n\\begin{remark} \\rm\nThe first term is a deterministic\nclean error term; we want to compute a rank-$k$\napproximation so the error can not be smaller than this term.\nThe second term is a random term that depends on the interaction of\nthe right singular values of $\\mtx{A}$ amplified by $\\mtx{\\Sigma}_2$.\n\\end{remark}\n\nWe would also like to be able to analyze the power scheme described in \n\\ref{alg:randomized-power-iteration},\ni.e, \n$\\mtx{B}=(\\mtx{A}\\mtx{A}^\\adj)\\mtx{A}=\\mtx{U}\\mtx{\\Sigma}^{2q+1}\\mtx{V}^\\adj$.\nThe rationale behind the power scheme was that the random approximation\nof the $k$-dimensional gross action of $\\mtx{A}$ can be improved if we amplify\n$\\mtx{\\Sigma}_1 - \\mtx{\\Sigma}_2$ by power iteration. This can be easily\nverified by the following Theorem \\ref{thm:power-method}.\n\\begin{theorem}[Power scheme] \\label{thm:power-method}\n%Let $m$, $n$, and $\\ell$ be positive integers such that $\\ell < n \\leq m$.\nLet $\\mtx{A}$ be an $m\\times n$ matrix, and let $\\mtx{\\Omega}$ be an $n\\times \\ell$\nmatrix. Fix a nonnegative integer $q$, form $\\mtx{B} = {(\\mtx{A}\\mtx{A}^\\adj)}^q \\mtx{A}$,\nand compute the sample matrix $\\mtx{Z} = \\mtx{B\\Omega}$.  Then\n$$\n\\norm{ (\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{A} }\n    \\leq \\norm{ (\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{B} }^{1/(2q+1)}.\n$$\n\\end{theorem}\n\\begin{remark} \\rm\nLet's consider the operator norm, i.e, $\\|\\mtx{\\Sigma}_1\\|=\\sigma_{k+1}$.\nThen $$\n\\norm{ (\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{A} }\n    \\leq \\norm{ (\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{B} }^{1/(2q+1)}\n    \\leq \\left( 1 + \\smnorm{}{\\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv}^2 \\right)^{1/(4q+2)}\n        \\sigma_{k+1} $$\nso the power scheme shrinks the suboptimality exponentially fast.\n\\end{remark}\n\nFinally, we can ask what are the consequences of truncating the SVD\nof $\\mtx{P}_{\\mtx{Z}}\\mtx{A}$, i.e, compute its best rank-$k$ approximation.\n\\begin{theorem}[Analysis of Truncated SVD] \\label{thm:truncation}\nLet $\\mtx{A}$ be an $m \\times n$ matrix with singular values $\\sigma_1 \\geq \\sigma_2 \\geq \\sigma_3 \\geq \\dots$,\nand let $\\mtx{Z}$ be an $m \\times \\ell$ matrix, where $\\ell \\geq k$.\nSuppose that $\\widehat{\\mtx{A}}_{(k)}$ is a best rank-$k$ approximation of $\\mtx{P}_{\\mtx{Z}} \\mtx{A}$ with respect to the spectral norm.  Then\n$$\n\\smnorm{}{ \\mtx{A} - \\widehat{\\mtx{A}}_{(k)} }\n  \\leq \\sigma_{k+1} + \\norm{(\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{A}}.\n$$\n\\end{theorem}\n\\begin{remark} \\rm\nThe result of Theorem \\ref{thm:truncation} is quite pessimistic, and\nin practice we observe that truncating the SVD is not that damaging in\nthe randomized setting.\n\\end{remark}\n\n\\subsubsection{(2) Bounds on the gaussian setting} \nFirst we start by providing a bunch of results on gaussian matrices\nthat will be key to prove the bounds on expectation and probability tails.\n%% TECHNICAL BACKGROUND\n\\begin{proposition}[Expected norm of a scaled Gaussian matrix] \n\\label{prop:scaled-gauss}\nFix matrices $\\mtx{S}, \\mtx{T}$, and draw a standard Gaussian matrix $\\mtx{G}$.  Then\n\\begin{gather}\n\\left( \\Expect \\fnormsq{ \\mtx{SGT} } \\right)^{1/2}\n    = \\fnorm{\\mtx{S}} \\fnorm{\\mtx{T}}\n    \\quad\\text{and}\\quad\n\\Expect \\norm{ \\mtx{SGT} }\n    \\leq \\norm{\\mtx{S}} \\fnorm{\\mtx{T}} + \\fnorm{\\mtx{S}} \\norm{\\mtx{T}}.\n    \\label{eqn:avg-specnorm}\n\\end{gather}\n\\end{proposition}\n%\n\\begin{proposition}[Expected norm of a pseudo-inverted Gaussian matrix] \n\\label{prop:gauss-inv-expect}\nDraw a $k \\times (k + p)$ standard Gaussian matrix $\\mtx{G}$ with $k \\geq 2$ and $p \\geq 2$.  Then\n\\begin{gather}\n\\left( \\Expect \\fnormsq{ \\mtx{G}^\\psinv } \\right)^{1/2} = \\sqrt{\\frac{k}{p-1}}\n  \\quad\\text{and}\\quad\n\\Expect \\norm{ \\mtx{G}^\\psinv } \\leq \\frac{\\econst\\sqrt{k+p}}{p}\n    \\label{eqn:avg-inv-specnorm}.\n\\end{gather}\n\\end{proposition}\n% \n\\begin{proposition}[Concentration for functions of a Gaussian matrix] \n\n\\label{prop:gauss-tail}\nSuppose that $h$ is a Lipschitz function on matrices:\n$$\n\\abs{ h(\\mtx{X}) - h(\\mtx{Y}) } \\leq L \\fnorm{ \\mtx{X} - \\mtx{Y} }\n\\quad\\text{for all $\\mtx{X}, \\mtx{Y}$.}\n$$\nDraw a standard Gaussian matrix $\\mtx{G}$.  Then\n$$\n\\Prob{ h(\\mtx{G}) \\geq \\Expect h(\\mtx{G}) + Lt } \\leq \\econst^{-t^2/2}.\n$$\n\\end{proposition}\nNow, we are ready to state and proof the main theorems in expectations,\nand afterwards we will confirm that the error does not oscillate too\nmuch around the mean by proving the corresponing bounds on the tails of the\ndistribution.\n\n\\begin{theorem}[Average error] \\label{thm:avg-frob-error-gauss}\nThe expected approximation error can be bounded as follows\n\\begin{enumerate}\n  \\item\n$$\n\\Expect \\fnorm{(\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}}\n    \\leq \\sigma_{k+1}\\sqrt{\\left( 1 + \\frac{k}{p-1} \\right)r(\\mtx{\\Sigma_2})}\n$$\n\\item \n$$\n\\Expect \\norm{(\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}}\n    \\leq  \\sigma_{k+1}\\left(1 + \\sqrt{\\frac{k}{p-1}}\n    +  \\frac{\\econst\\sqrt{k+p}}{p}\\sqrt{r(\\mtx{\\Sigma_2})}\\right)\n$$\n \\end{enumerate}\n\\end{theorem}\nOne interesting quantity is worth examining is\n$\\norm{(\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}}/\\sigma_{k+1}$ to check\nthe factor that tells how far the\napproximation is from the optimal rank-$k$ approximation \\ref{eq:fixed-rank}.\nWe observe that the suboptimality term increases\nessentially as $~\\sim\\sqrt{k/p}$ and has a term corresponding to the \nnumerical rank \\ref{eq:num-rank} of the singular values corresponding\nto the perturbation.\n\\footnote{The original statement of Theorem \\ref{thm:avg-frob-error-gauss}\nfrom \\cite{halko2011finding} does not explicitly write $r(\\mtx{\\Sigma_2})$.\nHowever, given that we introduced the concept of numerical rank \n\\ref{eq:num-rank} and its interpretation, I found interesting to highlight its\nappearance in the theorem.}\nWe will go through the proof for the sake of illustration.\n\\begin{proof}\nH{\\\"o}lder's inequality and Theorem \\ref{thm:main-error-bd} give \n$$\n\\Expect \\fnorm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}}\n    \\leq \\left( \\Expect \\fnormsq{(\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}} \\right)^{1/2}\n    \\leq \\left( \\smnorm{\\rm F}{\\mtx{\\Sigma}_2}^2 + \\Expect \\smnorm{\\rm F}{ \\mtx{\\Sigma}_2\n                \\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv }^2 \\right)^{1/2}.\n$$\nThen, we condition on $\\mtx{\\Omega}_1$ and use Proposition~\\ref{prop:scaled-gauss}\nand first part of Proposition~\\ref{prop:gauss-inv-expect}\n$$\n\\Expect \\smnorm{\\rm F}{ \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv }^2\n    = \\Expect \\left( \\Expect \\left[ \\smnorm{\\rm F}{ \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2\n\\mtx{\\Omega}_1^\\psinv }^2 \\ \\big\\vert \\ \\mtx{\\Omega}_1 \\right] \\right)\n    = \\Expect \\left( \\fnormsq{\\mtx{\\Sigma}_2} \\smnorm{\\rm F}{\\mtx{\\Omega}_1^\\psinv}^2 \\right)\n    = \\fnormsq{\\mtx{\\Sigma}_2} \\cdot \\Expect \\smnorm{\\rm F}{\\mtx{\\Omega}_1^\\psinv}^2\n    = \\frac{k}{p-1} \\cdot \\fnormsq{\\mtx{\\Sigma}_2},\n$$\nPutting everything together\n$$\n\\Expect \\fnorm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A}}\n    \\leq \\left(1 + \\frac{k}{p-1}\\right)^{1/2} \\fnorm{ \\mtx{\\Sigma}_2 }.\n$$\nand the first part if proved. \\\\\nThe bound on the operator norm is very similar, Theorem~\\ref{thm:main-error-bd}\nimplies that\n$$\n\\Expect \\norm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A} }\n    \\leq \\Expect \\left( \\normsq{\\mtx{\\Sigma}_2}\n        + \\smnorm{}{\\mtx{\\Sigma}_2 \\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv }^2 \\right)^{1/2}\n    \\leq \\norm{\\mtx{\\Sigma}_2} + \\Expect \\smnorm{}{ \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2 \\mtx{\\Omega}_1^\\psinv }.\n$$\nConditioning again on $\\mtx{\\Omega}_1$, we can bound the expectation w.r.t\n $\\mtx{\\Omega}_2$\n$$\n\\Expect \\smnorm{}{ \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2\n\\mtx{\\Omega}_1^\\psinv }\n    \\leq \\Expect \\left( \\norm{\\mtx{\\Sigma}_2} \\smnorm{\\rm F}{\\mtx{\\Omega}_1^\\psinv}\n        + \\fnorm{\\mtx{\\Sigma}_2} \\smnorm{}{\\mtx{\\Omega}_1^\\psinv} \\right)\n    \\leq \\norm{\\mtx{\\Sigma}_2} \\left( \\Expect \\smnorm{\\rm F}{\\mtx{\\Omega}_1^\\psinv}^2 \\right)^{1/2}\n        + \\fnorm{\\mtx{\\Sigma}_2} \\cdot \\Expect \\smnorm{}{\\mtx{\\Omega}_1^\\psinv}.\n$$\nFinally applying Proposition~\\ref{prop:gauss-inv-expect}, we get to the final\nresult\n$$\n\\Expect \\smnorm{}{ \\mtx{\\Sigma}_2 \\mtx{\\Omega}_2\n\\mtx{\\Omega}_1^\\psinv }\n    \\leq \\sqrt{\\frac{k}{p-1}} \\norm{\\mtx{\\Sigma}_2}\n    + \\frac{\\econst\\sqrt{k+p}}{p} \\fnorm{\\mtx{\\Sigma}_2}.\n$$\n\\end{proof}\n\nFinally, we will state the bounds on the tails that prove that the \npreviously expectation bounds are representative of the random behavior.\n\n\\begin{theorem}[Deviation bounds for the Frobenius error] \\label{thm:tail-frob-error-gauss}\nFrame the hypotheses of Theorem~\\ref{thm:avg-frob-error-gauss}.\nAssume further that $p \\geq 4$.  For all $u, t \\geq 1$,\n$$\n\\fnorm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A} }\n    \\leq \\left( 1 + t \\cdot \\sqrt{12k/p} \\right)\n    \\left( \\sum\\nolimits_{j > k} \\sigma_j^2 \\right)^{1/2}\n    + ut \\cdot \\frac{\\econst\\sqrt{k+p}}{p+1} \\cdot \\sigma_{k+1},\n$$\nwith failure probability at most $5 t^{-p} + 2 \\econst^{-u^2/2}$.\n\\end{theorem}\n\n\\begin{theorem}[Deviation bounds for the spectral error] \\label{thm:tail-spec-error-gauss}\nFrame the hypotheses of Theorem~\\ref{thm:avg-frob-error-gauss}, and assume further that $p \\geq 4$.  Then\n$$\n\\norm{ (\\Id - \\mtx{P}_{\\mtx{Y}}) \\mtx{A} }\n    \\leq \\left( 1 + 8 \\sqrt{(k + p) \\cdot p \\log p} \\right) \\sigma_{k+1}\n        + 3 \\sqrt{k+p} \\left( \\sum\\nolimits_{j > k} \\sigma_j^2 \\right)^{1/2},\n$$\nwith failure probability at most $6 p^{-p}$.\n\\end{theorem}\nSimilar bounds can also be proven for the power scheme \n\\cite{halko2011finding} that give a high probability guarantee for \nthe bound \\ref{thm:power-method}.\n\nFinally, let's analyze the error bounds on the \nthe Power Scheme \\ref{alg:randomized-power-iteration} that are directly\nderived from Theorem \\ref{thm:power-method} using H{\\\"o}lder's inequality\nand the bound $\\smnorm{\\rm F}{\\Sigma_2^{2q+1}}\\leq\\left(\\sqrt{ \\min\\{m,n\\} - k }\\right)\\sigma_{k+1}^{1/(2q+1)}$.\n\n\\begin{corollary}[Average spectral error for the power scheme]\n\\label{cor:power-method-spec-gauss}\nFrame the hypotheses of Theorem~\\ref{thm:avg-frob-error-gauss}.\nDefine $\\mtx{B} = {(\\mtx{A}\\mtx{A}^\\adj)}^{q} \\mtx{A}$ for a\nnonnegative integer $q$, and construct the sample matrix $\\mtx{Z} =\n\\mtx{B\\Omega}$.  Then\n$$\n\\Expect \\norm{(\\Id - \\mtx{P}_{\\mtx{Z}}) \\mtx{A}}\n    \\leq \\left[ 1 + \\sqrt{\\frac{k}{p-1}}\n    + \\frac{\\econst\\sqrt{k+p}}{p} \\cdot \\sqrt{ \\min\\{m,n\\} - k } \\right]^{1/(2q+1)}\n    \\sigma_{k+1}.\n$$\n\\end{corollary}\n\nFrom Corollary \\ref{cor:power-method-spec-gauss} we observe how as we increase\n$q$, the power scheme drives the extra factor in the error to one\nexponentially fast.\n\\newpage", "meta": {"hexsha": "a688cd986fe080279cde63ee699d75ca52481420", "size": 13612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/theory.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/theory.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/theory.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": 44.1948051948, "max_line_length": 143, "alphanum_fraction": 0.6619894211, "num_tokens": 4841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.6065585597788687}}
{"text": "\\section{Generalized Additive Models}\nWe extend additive models to generalized additive models in a similar\nway to the extension of linear models to generalized linear models.\n\nSay $Y$ has conditional distribution from an exponential family and the\nconditional mean of\nthe response $E(Y|X_1,\\dots,X_p) = \\mu(X_1,\\dots,X_p)$ is related to\nan additive  model through some link functions\n\\[\ng\\{\\mu_i\\} = \\eta_i = \\alpha + \\sum_{j=1}^p f_j(x_{ij}) \n\\]\nwith $\\mu_i$ the conditional expectation of $Y_i$ given\n$x_{i1},\\dots,x_{ip}$. This motivates the use of the IRLS procedure used\nfor GLMs but  incorporating the backfitting algorithms used for\nestimation in Additive Models. \n\nAs seen for GLM the estimation technique is again motivated by the\napproximation:\n\\[\ng(y_i) \\approx g(\\mu_i) + (y_i - \\mu_i) \\frac{\\partial \\eta_i}{\\partial\n  \\mu_i}\n\\]\nThis motivates a weighted regression setting of the form\n\\[\nz_i = \\alpha + \\sum_{j=1}^p f_j(x_{ij}) + \\varepsilon_i, \\, i=1,\\dots,n\n\\]\nwith the $\\varepsilon$s, the working residuals,  independent with\n$\\E(\\varepsilon_i) =0$ and \n\\[\n\\var(\\varepsilon_i) = w_i^{-1} = \\left( \\frac{\\partial \\eta_i}{\\partial\n    \\mu_i} \\right)^2 V_i\n\\]\nwhere $V_i$ is the variance of $Y_i$.\n\nThe procedure for estimating the function $f_j$s is called the {\\it\n  local scoring procedure}:\n\\begin{enumerate}\n\\item Initialize: Find initial values for our estimate:\n  \\[ \n  \\alpha^{(0)}=g\\left(\\sum_{i=1}^n y_i/n\\right); f^{(0)}_1 =\n  \\dots,f^{(0)}_p = 0 \n  \\]\n\\item Update: \n  \\begin{itemize}\n  \\item Construct an adjusted dependent variable\n    \\[\n    z_i = \\eta_i^{(0)} + (y_i - \\mu_i^{(0)})  \n    \\left( \\frac{\\partial \\eta_i}{\\partial \\mu_i} \\right)_0\n    \\]\n    with $\\eta_i^{(0)} = \\alpha^{(0)} + \\sum_{j=1}^p f^{(0)}_j(x_{ij})$ and $\\mu_i^{(0)} =\n    g^{-1}(\\eta_i^{(0)})$\n    \n  \\item  Construct weights:\n    \\[\n    w_i =  \\left( \\frac{\\partial \\mu_i}{\\partial \\eta_i} \\right)^2_0\n    (V_i^{(0)})^{-1} \n    \\]\n    \n  \\item  Fit a weighted additive model to $z_i$, to obtain estimated\n    functions $f_j^{(1)}$, additive predictor $\\eta^{(1)}$ and fitted\n    values $\\mu^{(1)}_i$.  \n\n    Keep in mind what a fit is.... $\\hat{\\f}$.\n  \\item  Compute the convergence criteria\n    \\[\n    \\Delta(\\eta^{(1)},\\eta^{(0)}) = \\frac{\\sum_{j=1}^p || f_j^{(1)} -\n    f_j^{(0)} ||} {\\sum_{j=1}^p ||f^{(0)}_j||}\n    \\]\n  \\item  A natural candidate for $||f||$ is $||\\mathbf{f}||$, the\n    length of the vector of evaluations of $f$ at the $n$ sample points.\n  \\end{itemize}\n\\item Repeat previous step replacing $\\eta^{(0)}$ by $\\eta^{(1)}$ until\n  $\\Delta(\\eta^{(1)},\\eta^{(0)})$ is below some small threshold.\n\\end{enumerate}\n\n\n\\subsection{Penalized Likelihood}\nHow do we justify the local scoring algorithm? One way is to minimize\na penalized likelihood criterion.\n\nGiven a generalized additive model let \n\\[\n\\eta_i = \\alpha + \\sum_{j=1}^p f_j(x_{ij})\n\\]\nand consider the \nlikelihood $l(f_1,\\dots,f_p)$ as a function $\\be =\n(\\eta_1,\\dots,\\eta_p)'$. \n\nConsider the following optimization problem: Over p-tuples of\nfunctions $f_1,\\dots,f_p$ with continuous first and second derivatives and\nintegrable second derivatives find one that minimizes\n\\[\npl(f_1,\\dots,f_p) = l(\\be;\\by) - \\frac{1}{2}\\sum_{j=1}^p \\lambda_j\n\\int \\{f_j''(x)\\}^2 \\, dx\n\\]\nwhere $\\lambda_j \\geq 0, j=1,\\dots,p$ are smoothing parameters.\n\nAgain we can show that \nthe solution is an additive cubic spline with knots at the unique\nvalues of the covariates.  \n\n\nIn order to find the $\\f$s that maximize this penalized likelihood\nwe need some optimization algorithm. We will show that the\nNewton-Raphson algorithm is equivalent to the local-scoring\nprocedure. \n\n\n\nAs before we can write the criterion as:\n\\[\npl(\\f_1,\\dots,\\f_p) = l(\\be,\\by) - \\frac{1}{2} \\sum_{j=1}^p\n\\lambda_j \\f_j'\\mathbf{K}_j \\f_j.\n\\]\n\nIn order to use Newton-Raphson we\nlet $\\mathbf{u} = \\partial l / \\partial{\\be}$ and $\\mathbf{A} = -\n\\partial^2 l/ \\partial \\be^2$. The first step is then taking\nderivatives and solving the \nscore equations:\n\\[\n\\left(\n\\begin{array}{cccc}\n\\mathbf{A} + \\lambda_1 \\mathbf{K}_1&\\mathbf{A}&\\dots&\\mathbf{A}\\\\\n\\mathbf{A}&\\mathbf{A} + \\lambda_2 \\mathbf{K}_2&\\dots&\\mathbf{A}\\\\\n\\vdots&\\vdots&\\ddots&\\vdots\\\\\n\\mathbf{A}&\\mathbf{A}&\\dots&\\mathbf{A}+\\lambda_p \\mathbf{K}_p\n\\end{array}\n\\right)\n\\left(\n\\begin{array}{c}\n\\f_1^1 - \\f_1^0\\\\\n\\f_2^1 - \\f_2^0\\\\\n\\vdots\\\\\n\\f_p^1 - \\f_p^0\n\\end{array}\n\\right)\n=\n\\left(\n\\begin{array}{c}\n\\mathbf{u} - \\lambda_1 \\mathbf{K}_1 \\f_1^0\\\\\n\\mathbf{u} - \\lambda_1 \\mathbf{K}_1 \\f_2^0\\\\\n\\vdots\\\\\n\\mathbf{u} - \\lambda_1 \\mathbf{K}_1 \\f_p^0\n\\end{array}\n\\right)\n\\]\nwhere both $\\mathbf{A}$ and $\\mathbf{u}$ are evaluated at $\\be^0$. In\nthe exponential family with canonical family, the entries in the above\nmatrices are of simple form, for example the matrix $\\mathbf{A}$ is\ndiagonal with diagonal elements $a_{ii} = (\\partial \\mu_i / \\partial\n\\eta_i)^2 V_i^{-1}$.\n\nTo simplify this further, we let $\\bz = \\be^0 + \\mathbf{A}^{-1}\n\\mathbf{u}$, and $\\bS_j = (\\mathbf{A} + \\lambda_j \\mathbf{K}_j)^{-1}\n\\mathbf{A}$, a weighted cubic smoothing-spline operator. Then we can\nwrite\n\\[\n\\left(\n\\begin{array}{cccc}\n\\mathbf{I}&\\mathbf{S}_1&\\dots&\\mathbf{S}_1\\\\\n\\mathbf{S}_2&\\mathbf{I}&\\dots&\\mathbf{S}_2\\\\\n\\vdots&\\vdots&\\ddots&\\vdots\\\\\n\\mathbf{S}_p&\\mathbf{S}_p&\\dots&\\mathbf{I}\n\\end{array}\n\\right)\n\\left(\n\\begin{array}{c}\n\\f_1^1\\\\\n\\f_2^1\\\\\n\\vdots\\\\\n\\f_p^1\n\\end{array}\n\\right)\n=\n\\left(\n\\begin{array}{c}\n\\mathbf{S}_1 \\mathbf{z}\\\\\n\\mathbf{S}_2 \\mathbf{z}\\\\\n\\vdots\\\\\n\\mathbf{S}_p \\mathbf{z}\n\\end{array}\n\\right)\n\\]\n\nFinally we may write this as\n\\[\n\\left(\n\\begin{array}{c}\n\\mathbf{f}_1^1\\\\\n\\mathbf{f}_2^1\\\\\n\\vdots\\\\\n\\mathbf{f}_p^1\n\\end{array}\n\\right)\n=\n\\left(\n\\begin{array}{cccc}\n\\mathbf{S}_1(\\bz - \\sum_{j\\neq 1} \\f^1_j)\\\\\n\\mathbf{S}_2(\\bz - \\sum_{j\\neq 2} \\f^1_j)\\\\\n\\vdots\\\\\n\\mathbf{S}_p(\\bz - \\sum_{j\\neq p} \\f^1_j)\\\\\n\\end{array}\n\\right)\n\\]\n\nThus the Newton-Raphson updates are an additive model fit; in fact\nthey solve a weighted and penalized quadratic criterion which is the\nlocal approximation to the penalized log-likelihood. \n\nNote: any linear smoother can be viewed as the solution to\nsome penalized likelihood. So we can set-up to penalized likelihood\ncriterion so that the solution is what we want it to be.\n\nThis algorithm converges with any linear smoother.\n\n\\subsection{Inference}\n\\subsubsection{Deviance}\nThe deviance or likelihood-ratio statistic, for a fitted model\n$\\hat{\\bg{\\mu}}$ is defined by \n\\[\nD(\\by;\\hat{\\bg{\\mu}}) = 2\\{l(\\bg{\\mu}_{max}; \\by) - l(\\hat{\\bg{\\mu}})\\}\n\\]\nwhere $\\bg{\\mu}_{max}$ is the parameter value that maximizes\n$l(\\hat{\\bg{\\mu}})$ over all $\\bg{\\mu}$ (the saturated model). We\nsometimes unambiguously use $\\hat{\\bg{\\eta}}$ as the argument of the\ndeviance rather than $\\hat{\\bg{\\mu}}$. \n\nRemember for GLM if we have two linear models defined by $\\eta_1$\nnested within $\\eta_2$, then under appropriate regularity conditions,\nand assuming $\\eta_1$ is correct, $D(\\hat{\\eta}_2;\\hat{\\eta}_1) =\nD(y;\\hat{\\eta}_1) - D(y;\\hat{\\eta}_2)$ has asymptotic $\\chi^2$\ndistribution with degrees of freedom equal to the difference in\ndegrees of freedom of the two models. This result is used extensively\nin the analysis of deviance tables etc...\n\nFor non-parametric we can still compute deviance and it still makes\nsense to compare the deviance obtained for different models. However,\nthe asymptotic approximations are undeveloped. \n\nH\\&T present heuristic arguments for  the non-parametric case.\n\n\\subsubsection{Standard errors}\nEach step of the local scoring algorithm consists of a backfitting\nloop applied to the adjusted dependent variables $\\bz$ with weights\n$\\bA$ given by the estimated information matrix. If $\\bR$ is the\nweighted additive fit operator, then at convergence\n\\[\n\\hat{\\bg{\\eta}} = \\bR(\\hat{\\bg{\\eta}} + \\bA^{-1}\\hat{\\bg{\\mu}})\n\\]\n\\[\n= \\bR \\bz,\n\\]\nwhere $\\hat{\\bu} = \\partial l / \\partial \\hat{\\bg{\\eta}}$. The\nidea is to approximate $\\bz$ by an asymptotically equivalent quantity\n$\\bz_0$. We will not be precise and write $\\approx$ meaning\nasymptotically equivalent.\n\nExpanding $\\hat{\\bu}$ to first order about the true\n$\\bg{\\eta}_0$, we get $\\bz \\approx \\bz_0 + \\bA_0^{-1}\\bu_0$, which has\nmean $\\bg{\\eta}_0$ and variance $\\bA_0^{-1} \\phi \\approx \\bA\n\\phi$. \n\nRemember for additive models we had the fitted predictor\n$\\hat{\\bg{\\eta}} = \\bR\\by$ where $\\by$ has covariance\n$\\sigma^2\\bI$. Here $\\hat{\\bg{\\eta}} = \\bR\\bz$, and $\\bz$ has\nasymptotic covariance $\\bA_0^{-1}$. $\\bR$ is not a linear operator due\nto its dependence on $\\hat{\\mu}$ and thus $\\by$ through the weights,\nso we need to use its asymptotic version $\\bR_0$ as well. We therefore\nhave\n\\[\n\\cov(\\hat{\\bg{\\eta}}) \\approx \\bR_0 \\bA_0^{-1} \\bR_0 ' \\phi \\approx\n\\bR \\bA^{-1} \\bR' \\phi\n\\]\nSimilarly \n\\[\n\\cov(\\hat{\\f}_j) \\approx \\bR_j \\bA^{-1} \\bR_j' \\phi\n\\]\nwhere $\\bR_j$ is the matrix that produces $\\hat{\\f}_j$ from $z$.\n\nUnder some regularity conditions we can further show that\n$\\hat{\\bg{\\nu}}$ is asymptotically normal, and this permits us to\nconstruct confidence intervals.\n\n\\subsection{Degrees of freedom}\nPreviously we described how we defined the degrees of freedom of the\nresiduals as the expected value of the residual sum of squares. The\nanalogous quantity in generalized models is the deviance. We therefore\nuse the expected value of the deviance to define the {\\it relative\ndegrees of freedom}.\n\nWe don't know the exact or asymptotic distribution of the deviance so\nwe need some approximation that will permit us to get an approximate\nexpected value. \n\nUsing a second order Taylor approximation we have that\n\\[\n\\E[D(\\by;\\hat{\\bg{\\mu}})] \\approx \\E[(\\by - \\hat{\\bg{\\mu}})'\\bA^{-1} (\\by -\n\\hat{\\bg{\\mu}})]\n\\]\nwith $\\bA$ the Hessian matrix defined above. We now write this in terms of the\n``linear terms''.\n\\[\n \\E[(\\by - \\hat{\\bg{\\mu}})'\\bA (\\by - \\hat{\\bg{\\mu}})] \\approx (\\bz -\n \\hat{\\bg{\\eta}})'\\bA (\\bz - \\hat{\\bg{\\eta}})\n\\]\nand we can show that this implies that if the model is unbiased\n\\[\n\\E(D) = df \\phi\n\\]\nwith \n\\[\ndf = n - \\tr(2\\bR - \\bR'\\bA\\bR\\bA^{-1})\n\\]\n\nThis gives the degrees of freedom for the whole model not for each\nsmoother. We can obtain the dfs for each smoother by adding them one\nat a time and obtaining\n\\[\n\\E[D(\\hat{\\bg{\\eta}}_2;\\hat{\\bg{\\eta}}_1)] \\approx \\tr(2\\bR_1 -\n\\bR_1'\\bA_1\\bR_1\\bA_1^{-1}) - \\tr( 2\\bR_2 - \\bR_2'\\bA_2\\bR_2\\bA_2^{-1})\n\\]\n\nIn general, the crude approximation $df_j = \\tr(\\bS_j)$ is used.\n\n\\subsection{An Example}\n The kyphosis data frame has 81 rows representing  data on\n 81  children  who have had corrective spinal surgery.  The binary\n outcome Kyphosis indicates the presence or absence of a postoperative\n deformity (called Kyphosis). The other three \n variables are {\\tt Age} in months, {\\tt Number} of vertebra involved in the\n operation, and  the beginning of the range of vertebrae involved\n ({\\tt Start}). \n \n\nUsing GLM these are the results we obtain\n\\renewcommand{\\baselinestretch}{1}\n\\begin{verbatim}\n                   Value  Std. Error   t value \n(Intercept) -1.213433077 1.230078549 -0.986468\n        Age  0.005978783 0.005491152  1.088803\n     Number  0.298127803 0.176948601  1.684827\n      Start -0.198160722 0.065463582 -3.027038\n\nNull Deviance: 86.80381 on 82 degrees of freedom\n\nResidual Deviance: 65.01627 on 79 degrees of freedom\n\\end{verbatim}\n\\renewcommand{\\baselinestretch}{2}\n\n\\centerline{\\epsfig{figure=Plots/plot-08-01.ps,angle=270,width=.8\\textwidth}}\n\nThe dotted lines are smooths of the residuals. This does not appear to\nbe a very good fit. \n\nWe may be able to modify it a bit, by choosing a better model than a\nsum of lines. We'll use smoothing and GAM to see what ``the data says''.\n\nHere are some smooth versions of the data:\n\n\\centerline{\\epsfig{figure=Plots/plot-08-02.ps,angle=270,width=.8\\textwidth}}\n\nAnd here are the gam results:\n\n\\renewcommand{\\baselinestretch}{1}\n\\begin{verbatim}\nNull Deviance: 86.80381 on 82 degrees of freedom\n\nResidual Deviance: 42.74212 on 70.20851 degrees of freedom\n\nNumber of Local Scoring Iterations: 7 \n\nDF for Terms and Chi-squares for Nonparametric Effects\n\n            Df Npar Df Npar Chisq    P(Chi) \n(Intercept)  1                             \n     s(Age)  1     2.9   6.382833 0.0874180\n   s(Start)  1     2.9   5.758407 0.1168511\n  s(Number)  1     3.0   4.398065 0.2200849\n\\end{verbatim}\n\\renewcommand{\\baselinestretch}{2}\n\nNotice that it is a much better fit and not many more degrees of\nfreedom. Also notice that the tests for linearity are close to\n``rejection at the 0.05 level''.\n\n\\centerline{\\epsfig{figure=Plots/plot-08-03.ps,angle=270,width=.8\\textwidth}}\n\nWe can either be happy considering these plots as descriptions of the\ndata, or we can use it to inspire a parametric model:\n\nBefore doing so, we decide not to include Number becuase it seems to\nbe associated with ``Start'' and not adding much to the fit. \nThis and other considerations suggest we not include {\\tt Number}\n. The gam\nplots suggest the following ``parametric'' model.\n\n\\renewcommand{\\baselinestretch}{1}\n \n\n\\begin{verbatim}\nglm2 <- glm(Kyphosis~poly(Age,2) + I((Start > 12) * (Start - 12)),\n            family=binomial)\n\\end{verbatim}\n\\renewcommand{\\baselinestretch}{2}\n\nHere are the results of this fit... much better than the original\nGLM fit.\n\n\\renewcommand{\\baselinestretch}{1}\n\\begin{verbatim}\nCoefficients:\n                                     Value Std. Error    t value \n                   (Intercept)  -0.5421608  0.4172229 -1.2994512\n                 poly(Age, 2)1   2.3659699  4.1164283  0.5747628\n                 poly(Age, 2)2 -10.5250479  5.2840926 -1.9918364\nI((Start > 12) * (Start - 12))  -1.3840765  0.5145248 -2.6900094\n\n(Dispersion Parameter for Binomial family taken to be 1 )\n\n    Null Deviance: 86.80381 on 82 degrees of freedom\n\nResidual Deviance: 56.07235 on 79 degrees of freedom\n\nNumber of Fisher Scoring Iterations: 6 \n\\end{verbatim}\n\\renewcommand{\\baselinestretch}{1}\n\nHere are the residual plots:\n\n\\centerline{\\epsfig{figure=Plots/plot-08-04.ps,angle=270,width=.8\\textwidth}}\n\n\\subsection{Prediction using GAM}\nOften we wish to evaluate the fitted model at some new values.\n\nWith parametric models this is simple because all we do is form a\nnew design matrix and multiply by the estimated parameters.\n\nSome of the functions used to create design matrices in lm, glm a\nand gam are data dependent. For example {\\tt bs()}, {\\tt\n  poly()}, make some standardization of the covariate before fitting\nand therefore new covariates would change the meaning of the parameters.\n\nAs an example look at what happens when we predict fitted values\nfor new values of AGE in the Kyphosis example using {\\tt predict()}.\n\nThe solution is to use {\\tt predict.gam()} that takes this into account \n\n\\centerline{\\epsfig{figure=Plots/plot-08-05.ps,angle=270,width=.8\\textwidth}}\n\n\n{\\tt predict.gam} is especially useful when we want to make surface\nplots. For example:\n\n\\centerline{\\epsfig{figure=Plots/plot-08-06.ps,angle=270,width=\\textwidth}}\n\n\\newpage\n\n\n\\subsection{Over-interpreting additive fits}\nOne of the advantages of GAM is their flexibility. However, because of\nthis flexibility we have to be careful  not to ``over-fit'' and interpret\nthe results incorrectly. \n\nBinary data is especially sensitive. We construct a simulated example\nto see this.\n\nThe following figure shows the functional components $f_1$ and $f_2$\nof a GAM \n\\[\n\\mbox{logit}\\{\\Pr(Y=1|U,V)\\} = -1 + f_1(U) + f_2(V)\n\\] \nwith $U$ and $V$ independent uniform(0,1).\n\n\\centerline{\\epsfig{figure=Plots/plot-08-07.ps,angle=270,width=\\textwidth}}\n\nWe also show the ``smooths'' obtained for a data set of 250\nobservations and a data set of 50 observations. Notice how ``bad'' the\nsecond fit is. \n\nIf we make a plot of the mean $\\mu(u,v)$ and of it's estimate we see\nwhy this happens.\n\n\\centerline{\\epsfig{figure=Plots/plot-08-08.ps,width=\\textwidth}}\n\nWe have relatively large neighborhoods of $[0,1] \\times [0,1]$ that\ncontain only 1s or only 0s. The estimates in these regions will have\nlinear part close to infinity and minus infinity! \n\nOne way to detect this when we don't know ``the truth'' is to look at\nthe estimates with standard errors and partial residuals. If the\npartial residuals follow the fit to closely and the standard errors\n``explode'' we know something is wrong.\n\n\\centerline{\\epsfig{figure=Plots/plot-08-09.ps,angle=270,width=\\textwidth}}\n\n\\newpage\n", "meta": {"hexsha": "2e3cf6f5a839764bb5735a77099ef066c9615051", "size": 16246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-08-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-08-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-08-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": 32.6224899598, "max_line_length": 90, "alphanum_fraction": 0.6948787394, "num_tokens": 5309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.606512014558757}}
{"text": "\\input{../../UCLHeader.tex}\n\\input{../../UCLCommands.tex}\n\\begin{document}\n\\title{Error Correction Lecture 4}\n\\author{with Dan Browne}\n\\maketitle\n\\tableofcontents\n\\section{The Stabiliser Formalism}\nThis is a state-independent formalism. It was first introduced by Gottesmann, This is by far one of the most important formalisms that made error correction a realistic prospect. \n\nThe Stabiliser formalism can correct any Pauli Error. It relies on the mathematical properties of Pauli matrices, and can also be used to explain multi-qubit entanglement. It is a very useful tehnique. \n\n\\subsection{Example: 3-qubit repetition code}\n\nThe 3-qubit repetition code is an example of the stabiliser formalism. For an arbitrary state\n\\beq\n\\ket{\\psi} = \\alpha \\ket{000} + \\beta \\ket{111}\n\\eeq\nwe can detect a $X$ bit flip error by measuring $ZZI, ZIZ$ or $IZZ$. Because the third measurement is superfluous, we need only measure the first two. \n\nRecall the effect of an error on the qubits. We have\n\n\\begin{tabular} {cc}\nError & States \\\\ \\hline\n$XII$ & $\\alpha \\ket{100} + \\beta\\ket{011}$ \\\\\n$IXI$ & $\\alpha \\ket{010} + \\beta \\ket{101}$ \\\\\n$IIX$ & $\\alpha \\ket{001} + \\beta \\ket{110}$\n\\end{tabular}\n\nSimilarly, for a syndrome measurement using the previous measurements, we find\n\n\\begin{tabular}{ccc}\n$ZZI$ & $ZIZ$ & $IZZ$ \\\\ \\hline\n+ & + & + \\\\\n-- & -- & + \\\\\n-- & + & -- \\\\\n+ & -- & --\n\\end{tabular}\n\nFrom this, we note that we are clearly dealing with a non-degenerate code. But instead of looking at the state and working out the entire syndrome table, we can ask: does the error commute with the error detection? That is, \n\\beq\n[M, E] =^? 0\n\\eeq\nWe can summarise this in a table as well. \n\n\\begin{tabular}{c|ccc}\n& $ZZI$  & $ZIZ$ & $IZZ$ \\\\ \\hline\n$III$ & $\\surd$ & $\\surd$ & $\\surd$ \\\\\n$XII$ & $\\times$ & $\\times $ & $\\surd$ \\\\\n$IXI$ & $\\times $ & $\\surd$ & $\\times$ \\\\\n$IIX$ & $\\surd$ & $\\times$ & $\\times$ \n\\end{tabular}\nNote the similarity of the tables. \n\nWe can then prove that given an error $E$ and error detection measurement $M$, if they anti-commute, we get $-1$ and if they commute, we get $+1$, should we measure. \n\nSo when $M$ anti-commutes with the error $E$, we detect the error. Note that all the error detecting measurements commute. And note as well that on an error-free codewords, all outcomes of $M$ are + (which is exactly what we want) because\n\\beq\n[M, I] = 0\n\\eeq\nNOte talso that there is a product sturcture outcome of $IZZ$, since it is a product of outcomes $ZIZ$ and $ZZI$. That is, we still only need to make two measurements because even the outcome of the third one will always be obtained from the other two. \n\nThese important group properties will come into play here. But before we proceed, we must show that the Pauli group is closed. THe identity, inverse and associativity are already taken care of. \n\n\\section{Definition of the Stabiliser Group}\nWe must first define the notion of \\textbf{stabilisation}. A group element is stabilised if another group element leaves it invariant. \n\nThus, given a set of codewords space basis states, $\\ket{x}_L$, where for $x = 00\\ldots 00$ to $x = 11 \\ldots 11$ (which we can call binary vectors) we say that $P$ stabilises the odespace if\n\\beq\nP\\ket{x}_L = \\ket{x}_L\n\\eeq\nfor all $x$. Note that this is an eigenvalue equation with eigenvalue $+1$. Thus, $\\ket{x}_L$ is an eigenvector of $P$ with eigenvalue  $+1$ for all $x$. \n\nIn the Stabiliser formalism, we identify Pauli operators that we measure to detect errors with operators that stabilise our codewords. We saw the stabiliser for $\\ket{000}$ and $\\ket{111}$. They are $ZZI$, and $ZIZ$. What properties will they have? \n\nIt is not always true that anti-commuting operators do not share eigenvalues. Two Pauli operators share a joint eigenbasis if and only if they commute. \n\nConsider therefore two commuting Pauli operators $P$ and $Q$ that both stabilise $\\ket{x}_L$. We find that \n\\beq\nP\\ket{x}_L = \\ket{x}_L\n\\eeq\n\\beq\nQ \\ket{x}_L = \\ket{x}_L\n\\eeq\nThen, it follows that \n\\beq\nPQ \\ket{x}_L = P\\ket{x}_L = \\ket{x}_L\n\\eeq\nSo, $PQ$ does also stabilise $\\ket{x}_L$. \n\nThus, given a code space $\\ket{x}_L$, its stabiliser group is the set of all Pauli operators $S_j$ that satisfy\n\\beq\nS_j \\ket{x}_L = \\ket{x}_L\n\\eeq\nfor all $x$ and for all $j$. The set $\\{S_j\\}$ forms a group! It is a subgroup of the $N$-qubit Pauli group $\\{i, X, Z\\}$. \n\nRecall that a group with only commuting elements is abelian. The stabiliser group only has commuting operators, and hence is an abelian subgroup of the Pauli group. \n\nAny quantum error correcting code for which the error detection measurements are an abelian subgroup of the $N$-qubit Pauli group is called a stabiliser group. \n\nAll codes seen in the course so far are in fact examples of stabiliser groups. \n\n\\textbf{Exercise for the student}: Go back and check this. Look at the commutators of the various operators. \n\nFor example, the 3-qubit code has stabilisers $ZZI, ZIZ, IZZ, III$. The 3-Qubit phase flip code has stabilisers $XXI, XIX, IIX, III$. Fruthermore, the Shor and the Steane code and the 5-qubit code are all examples of stabiliser codes. Finally, we have topological surface codes, which also fall into this category. \n\nNote that nay group can be represented by its generators. Thus, for our future studies of stabiliser groups, we will have to look only at the stabiliser generators. \n\n\\section{Order of group and group generators}\nThe \\textbf{order} of the group is the number of group elements. \n\nAny group $G$ can be described a set of generators (which is not unique) from which all elements can be obtained. We write this as\n\\beq\nG = \\braket{g_1 \\ldots g_n}\n\\eeq\n\nAs an example, take the 3-qubit code. For the 3-qubit code, we have three possible sets of generators for the stabiliser group. $\\braket{ZZI, ZIZ}$, $\\braket{ZIZ, IZZ}$ and $\\braket{ZZI, IZZ}$. \n\nIn general, a stabiliser group with $m$ generators has $2^m$ elements. The generators must be \\textbf{independent}. By independent, we mean that we choose the minimum number of generators that can generate the entire group. This is similar to choosing a vector basis. \n\nFor self-inverse elements, such as the Pauli group, $2^m$ also holds. Since $(g_j)^2 = I$ and since elements commute, the order of multiplication does not matter. Any element can in fact be written\n\\beq\nS = \\prod_{j = 1}^m g_j^{x_j}\n\\eeq\nwhere $x_j$ is an $m$-bit string. Then, we do indeed get $2^m$ elements. \n\nSo, $m$ is always our generator index. In fact, describing the group by its generators gives us an exponential saving, since in order to speak of the group,  we only have to consider $m$ elements instead of $2^m$ elements. \n\nHowever, how many generators do we need for the stabiliser formalism? \n\n\\section{The Number of Generators}\nFor the 3-qubit code, we had $m = 2$, $n = 3$ and $k = 1$. For the Shor code, we similarly had $n = 9$ and $k = 1$. The generators for that stabiliser group were $Z_1Z_2, Z_2Z_3, Z_3Z_4, Z_4Z_5, Z_5Z_6, Z_6Z_7, Z_7Z_8Z_8Z_9$ and $X_1X_2X_3X_4X_5X_6, X_1X_2X_3X_7X_8X_9$. \n\nFrom these two examples, we can see a pattern. In general\n\\beq\nm = n-k\n\\eeq\nThis is satisfied by any stabiliser code. In words, given $k$ qubits encoded in $n$ physical qubits, the stabiliser has $m$ independent generators. A proof can e found in one of the problem sheets. \n\nThe key idea is to use $m$ generators to describe the entire code. \n\n\\section{Aside:Stabiliser states}\nIf $k = 0$ we end up with $m = n$. That is, we have no encoded states at all. We say that we have a 0-dimensional code space, which means that there is one single vector in the codespace. Note that they do not encode an entire qubit, since this requires two basis states. Instead, this code can be used to encode one single state. \n\nStates like these are called \\textbf{stabiliser states}. It is a state which is the joint $+1$ eigenstate of $n$ independent, commuting pauli operators (since $m = n$). A $k = 0$ code is also called a stabiliser code. \n\nThey are important because they use canonically entangled states. \n\nHere are some examples of single states and their stabiliser generators. \n\n\\begin{tabular}{cc}\nState $(n = 1)$& Stabiliser generator \\\\ \\hline\n$\\ket{0}$ & $Z$ \\\\\n$\\ket{1}$ & $-Z$ \\\\\n$\\ket{+}$ & $X$ \\\\\n$\\ket{-}$ & $-X$ \\\\\n$\\ket{+i}$ & $Y$ \\\\\n$\\ket{-i}$ & $-Y$\n\\end{tabular}\n\nAnd for states with more than one physical qubit,\n \n\\begin{tabular}{ccc}\nStates $n = 2$ & Stabiliser generator  & Full group\\\\ \\hline\n$\\ket{00} + \\ket{11}$ & $ZZ, XX$  & $ZZ, XX, -YY, II$\\\\\n$\\ket{00} - \\ket{11}$ & $ZZ, -XX$  & $ZZ, -XX, YY, II$\\\\\n$\\ket{01} + \\ket{10}$ & $-ZZ, XX$ & $-ZZ, XX, YY, II$\\\\\n$\\ket{01} - \\ket{10}$ & $- ZZ, -XX$ & $-ZZ, -XX, -YY, II$\n\\end{tabular}\n\nFor $n = 3$ physical qubits, we end up with states such as the GHZ state: $\\ket{000} + \\ket{111}$ which is stabilised by $XXX; ZZI, ZIZ$. For any $n >3$, we get so-called cluster states or graph states. \n\n\\section{Detection of Errors in the Stabiliser Formalism}\nConsider a stabiliser codeword $\\ket{\\psi}$ and its stabiliser element $S_j$. Let this codeword be affected by a Pauli error $E$. The final state is $E\\ket{\\psi}$ and we measure $S_j$. Then, if\n\\beq\n[S_j, E] = 0\n\\eeq\nthe outcome is $+1$. However, if \n\\beq\n\\{S_j, E\\} = 0\n\\eeq\nthe outcome is $-1$ and we know that an error has occurred. \n\nProof: We want to know what the eigenstates of $E$ applied to the state is. That is, what are the eigenstates $\\lambda_j$ in \n\\beq\nS_j \\left( E\\ket{\\psi}\\right) = \\lambda_j \\left(E \\ket{\\psi}\\right)\n\\eeq\nAssume first that $[S_j, E] = 0$. Then, \n\\beq\nS_j E \\ket{\\psi} = E S_j \\ket{\\psi} = E\\ket{\\psi}\n\\eeq\nFrom which we see that the eigenvalue is indeed $+1$. However, if $\\{S_j, E\\} = 0$, we have\n\\beq\nS_j E \\ket{\\psi} = - E S_j \\ket{\\psi} = - E \\ket{\\psi}\n\\eeq\nThe eigenvalue is $-1$. \n\nThe central question in the stabiliser formalism is: does the error commute or anti-commute with the stabiliser? \n\n\\section{Limitations of a Stabiliser Code}\nFor a Pauli error $E$ to be detectable, it must anti-commute with at least 1 element of the stabiliser. So, must we then go on to consider all elements in the group? It turns out that we can map the entire behaviour of the code by just considering the generators. If the error anti-commutes with just a single generator, it is detectable. This works because $S_j$ is a product of generators. \n\nSo the only thing we need to measure are the generators. However, any error that commutes with all generators is undetectable. E.g. $Z$ in the bit-flip code, which we already saw was undetectable. Recall that the generators were $[XXX, ZIZ, IZZ]$ and so a single $Z$ error would indeed commute with them. \n\nQuestion: It seems to me that $Z$ does not commute with $XXX$. However, $XXX$ is clearly a generator, as it maps the codeword $\\ket{000} + \\ket{111}$ into itself. \n\nAttempt at answer: $XXX$ only maps one single codeword onto itself, namely the superposition. For a state in $\\ket{000}$, it does not map onto the same codeword. However, does this means that it is not a generator? \n\nTo clarify, \n\\beq\nXXX \\left( \\alpha \\ket{000} + \\beta\\ket{111} \\right) = \\alpha \\ket{111} + \\beta \\ket{000}\n\\eeq\nHere, $XXX$ is a logical $X$ operator which maps codespace vectors back into the codespace. If an error is undetectable, it must be a logical operator on the codespace, and vice versa. In particular in stabiliser codes, undetectable Pauli errors are logical Pauli operators. \n\nSo, the logical Pauli operators are the set of logical operators that commute with the entire stabiliser. \n\nAgain, we can look at the bit flip code. The stabiliser itself is $ZZi, IZZ, ZIZ, III$. All of these are equal to the logical identity operator $\\bar{I}$. These are \\emph{not} errors (but they could be, and then we couldn't possibly correct for them). \n\nIt turns out that every element of the stabiliser is always $\\bar{I}$. But, note that for $XXX = \\bar{X}$, we have\n\\beq\n(XXX) S_j \\ket{\\psi} = (XXX) \\ket{\\psi}\n\\eeq\nSo any product of the stabiliser and $\\bar{X}$ is also a logical operator! So, given out three generators, we have four equivalent $\\bar{X}$, \n\\beq\nXXX, -YYX, -YXY, -XXY\n\\eeq\nThe same goes for $\\bar{Z}$ and $\\bar{Y}$. This is a way to find all the undetectable errors. Recall that for the logical $\\bar{Z}$ for the bit flip code, we have $\\bar{Z} = ZII$. So we get\n\\beq\nIZI, IIZ, ZZZ\n\\eeq\nare all equivalent $\\bar{Z}$. \n\nThese are examples of \\textbf{cosets}. In fact, we say that these are constructions of cosets. We can easily identify these sets of operators. This works for all stabiliser codes. We have that \n\\beq\n\\bar{Y} = \\mbox{any logical } \\bar{X} \\times  \\mbox{any logical } \\bar{Z}\n\\eeq\nWe can prove this by writing\n\\beq\n\\bar{X} S_j \\bar{Z} S_k = \\bar{X} \\bar{Z} (S_j S_k)\n\\eeq\nThis creates four different logical $\\bar{Y}$. \n\n\\section{Overview of Error Correction}\nLet us here summarise what we have learnt so far. \n\n\\begin{description}\n\\item[Detection] An error $E$ is detected if it anti-commutes with at least one stabiliser generator. \n\n\\item[Correction] From the syndrome, we can determine a correction operator $C$. Then we apply  $C$ to the state. \n \n\\item[Stabilisation] It turns out that if $C$ and $E$ both form the stabiliser, such that \n\\beq\nCE \\ket{\\psi} = S_j  \\ket{\\psi}\n\\eeq\nthen the error is successfully corrected. This way, we can easily find the right correction method. Otherwise, $CE$ must be a logical operator. Note that error correction can always fail!\n\n\\end{description}\n\n\\subsection{Successful correction example}\nConsider the error $XII$. If we apply the generators, we see that $ZZI$ anti-commutes with the error and $IZZ$ commutes. Thus, we get a $-1$ outcome for the first one and a $+1$ for the second one. \n\nThen, we correct the error with $XII$. We see that\n\\beq\n(XII)^2 = III\n\\eeq\nThis is a stabiliser, and so the error is corrected. \n\nConsider now the error $IXX$. It has syndrome $-1$ for $ZZI$ and $+1$ for $IZZ$. We cannot correct this error because its syndrome is degenerate with the first case. Applying the same correction method will give us $XXX = \\bar{X}$. \n\nHowever, since 1 error is more likely than two, out chances are pretty good. \n\n\\section{How to compute codeword kets}\nLet us now see how we recover the states from the Stabiliser formalism. That is, given a stabiliser formalism, what are the codewords? From the stabiliser generators and logical operators, we can find the states. \n\nWe first make an observation. Let $\\braket{g_1 \\ldots g_n}$ be the stabiliser generators, and let $\\bar{Z}$ be the logical $Z$ operator. Then, $\\ket{0}_L$ states obey\n\\beq\nS_j \\ket{0}_L = \\ket{0}_L\n\\eeq\n\\beq\n\\bar{Z} \\ket{0}_L = \\ket{0}_L\n\\eeq\nIn fact $\\ket{0}_L$ is the only state that satisfies both of these equations. However, this is cumbersome. Instead, we can create projectors onto this codespace. This leaves behind the codespacae vector. \n\nSo, for each $g_j$, we construct a projector\n\\beq\nP_j = \\frac{I + g_j}{2}\n\\eeq\nWe can check that it is a projector, \n\\beq\nP^2 = P = \\left( \\frac{I + g_j}{2} \\right)^2 = \\frac{I + g_j }{2}\n\\eeq\nThen, for any element in the codespace, we require\n\\beq\n\\left( \\frac{i + g_j}{2} \\right) \\ket{x} = \\ket{x}\n\\eeq\nAnything outside the codespace (such as an error) will give\n\\beq\ng_j \\ket{\\psi} = - \\ket{\\psi}\n\\eeq\nWe can rearrange the above to get\n\\beq\n\\left( \\frac{I+ g_j}{2} \\right) \\ket{\\psi} = 0\n\\eeq\nForm this we see that the projector indeed does only project onto the codespace. WE are essentially removing anything orthogonal to the codespace. We can take the product of all projectors, \n\\beq\n\\prod_{j = 1}^m \\left( \\frac{I + g_j}{2}\\right) = P\n\\eeq\nThis is the projector onto the entire codespace. Every vector in the codespace is mapped to the codespace. \n\nNow, let the projector be \n\\beq\n\\frac{I + \\bar{Z}}{2}\n\\eeq\nIt has the following properties. It leaves $\\ket{0}_L$ unchanged, But, we find\n\\beq\n\\frac{I + \\bar{Z}}{2} \\ket{1}_L = 0\n\\eeq\nThen we can show that \n\\beq\n\\prod^m_{j = 1}\\left( \\frac{I + g_j}{2} \\right) \\left( \\frac{I + \\bar{Z}}{2} \\right) = \\ket{0}_L \\bra{0}_L\n\\eeq\nbecause the $\\bar{Z}$ projector picks out the same projector from $P$. Thus, we can easily obtain the codewords if we know the logical operators and the generators. \n\nAnother property is that \n\\beq\n\\prod_{j = 1}^m \\left( \\frac{I + g_j}{2} \\right) = \\frac{1}{2^m} \\sum_{ \\forall S \\in \\mbox{Stabiliser group} }S\n\\eeq\n\n\\section{5-qubit code}\nLet us now have a look at the 5-qubit code. It is defied within the Stabiliser formalism via its operators. It is a $(n = 5, k= 1, m = 4)$ code. We have\n\\beq\ng_1 = XZZXI\n\\eeq\n\\beq\ng_2 = IXZZX\n\\eeq\n\\beq\ng_3 = XIXZZ\n\\eeq\n\\beq\ng_4 = ZXIXZ\n\\eeq\nThe logical operators are (simply enough)\n\\beq\n\\bar{Z} = ZZZZZ\n\\eeq\n\\beq\n\\bar{X} = XXXXX\n\\eeq\nFrom the stabilisers and the logical, we can work out the weight for the minimum undetectable error. We ask: What is the smallest weight logical operator? \n\nWe can calculate the distance of the code. Consider $\\bar{Z}g_1$, which is another logical $Z$. We find\n\\beq\n\\bar{Z} g_1 = - YIIYZ\n\\eeq\nThis is weight 3 (count all the operators that are not identity). This is the smallest weight undetectable error. Hence, the code distance is $d = 3$. The number of arbitrary errors that can be detected are\n\\beq\n\\frac{3 - 1}{2} \\sim 1\n\\eeq\nNote that this does \\emph{as well} as the Steane code. See NC for the entire list of the codewords, section 10.104. They are superpositions of 16 terms, so we will not write them out here! \n\n \n\n\n\\end{document}", "meta": {"hexsha": "06ebb400abf2bd92cf98458b5168b927878439a8", "size": 17435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Error Correction Lecture 4 March 2016.tex", "max_stars_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_stars_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-04-01T04:53:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-09T07:01:28.000Z", "max_issues_repo_path": "Error Correction Lecture 4 March 2016.tex", "max_issues_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_issues_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Error Correction Lecture 4 March 2016.tex", "max_forks_repo_name": "sqvarfort/Quantum-Error-Correction-Notes", "max_forks_repo_head_hexsha": "3628ece1bf999b4ed57ce1badb376bd91b40dc26", "max_forks_repo_licenses": ["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.7671232877, "max_line_length": 392, "alphanum_fraction": 0.7149412102, "num_tokens": 5490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.606512014558757}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{multicol}\n\\usepackage{fancyhdr}\n\\usepackage{geometry}\n\\usepackage{graphicx}\n\\usepackage{mdframed}\n\\usepackage{indentfirst}\n\\usepackage{enumitem}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{mathtools}\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\geometry{\n    a4paper,\n    left=20mm,\n    right=20mm,\n    bottom=33mm\n}\n\n% This section defines the title, author and the date. To display these elements, call the \"\\maketitle\" command\n\\title{\\vspace{70mm}\\textbf{SIR Model Explained}}\n\\author{Samuel Atkins}\n\\date{December 2020}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{\\leftmark}\n\\lfoot{Samuel Atkins}\n\\rfoot{Page \\thepage}\n\\renewcommand{\\headrulewidth}{2pt}\n\\renewcommand{\\footrulewidth}{1pt}\n\n\\begin{document}\n\\maketitle\n\\pagebreak\n\\section{The Model}\nThere are three variables that the SIR model depends on, $S$, $I$, and $R$. $S(t)$ is the number of susceptible individuals, $I(t)$ is the number of infected individuals, and $R(t)$ is the number of recovered individuals. We define the following variables to make our future calculations more simple:\n\n\\[s(t) = \\frac{S(t)}{N}\\]\n\\[i(t) = \\frac{I(t)}{N}\\]\n\\[r(t) = \\frac{R(t)}{N}\\]\n\n\\section{Model Assumptions}\n\\begin{enumerate}[label=\\arabic*.]\n\\item The total number of individuals in the population, $N$, is constant\n\\item Individuals do not immigrate to or from the population in question\n\\item There are no births\n\\item There is no loss of immunity (we could assume a loss of immunity and derive different equations)\n\n\\end{enumerate}\nSince the total number of individuals in the population, $N$, is constant $s(t) + i(t) + r(t) = 1$ because $S(t) + I(t) + R(t) = N$. Given our assumptions, we are effectively assuming that the only way an individual leaves the susceptible group is by becoming infected. Thus, the number of susceptible individuals is always decreasing. \n\n\\section{The Differential Equations}\nThe rate at which the number of susceptible individuals decreases is dependent on how many infected individuals the susceptible group comes into contact with. If an infected individual comes into contact with $b$ susceptible individuals per day, then, on average, each infected individual generates $b \\cdot s(t)$ new infected individuals per day. Furthermore, a fixed fraction of the infected group, $k$, recovers every day. Using these assumptions, we arrive at the following differential Equations:\n\n\\[\\frac{dS}{dt} = -b s(t) I(t) \\implies \\frac{ds}{dt} = \\frac{-b s(t) I(t)}{N}\\]\n\\[\\frac{ds}{dt} = -b s(t) i(t)\\]\n\n\\noindent\nThe $i(t)$ factor is present because given our assumption, if there is just one infected person then the number of susceptible people decreases by a factor of $b s(t)$. Therefore, if there are 2 infected people, then the number of susceptible people decreases by a factor of $2b s(t)$. For $I(t)$ infected people, the number of susceptible people decreases by a factor of $b \\hspace{0.5mm} s(t) I(t)$. \n\n\\[\\frac{dR}{dt} = k I(t) \\implies \\frac{dr}{dt} = k i(t)\\]\n\n\\noindent\nThis follows from the fact that $k$ infected individuals recover every day. Now, since the number of infected people increases as a function of $b \\hspace{0.5mm} s(t) I(t)$ and $k \\hspace{0.5mm} I(t)$, we have the following:\n\n\\[\\frac{dI}{dt} = -k I(t) + b s(t) I(t) \\implies \\frac{dI}{dt} = -\\frac{dR}{dt} - \\frac{dS}{dt} \\implies \\frac{ds}{dt} + \\frac{di}{dt} + \\frac{dr}{dt} = 0\\]\n\n\\subsubsection*{SIR Equations Summary}\n\\[\\frac{ds}{dt} = -b s(t) i(t)\\]\n\\[\\frac{di}{dt} = - \\frac{dr}{dt} - \\frac{ds}{dt}\\]\n\\[\\frac{dr}{dt} = k i(t)\\]\n\n\\section{Initial Conditions}\nTo solve this set of differential equations, we need to supply some initial conditions. We assume that a tiny fraction of our population is infected and the rest of our population is healthy. Thus, for a population of size 5,000,000, we have the following:\n\n\\[S(0) = 4,999,990\\]\n\\[I(0) = 10\\]\n\\[R(0) = 0\\]\n\n\\[s(0) = 0.999998 \\approx 1\\]\n\\[i(0) = 2 x 10^{-6}\\]\n\\[r(0) = 0\\]\n\n\\section{Euler's Method}\nWe do not numerically solve the SIR equations. Instead, we use Euler's method. For a single time dependent variable, $x$, Euler's method is as follows:\n\n\\[x_i = x_{i-1} + \\frac{dx(t-1)}{dt} \\cdot \\Delta t\\]\n\n\\noindent\nSince we have three variables in the context of the SIR model, we have three Euler formulas:\n\n\\[s_i = s_{i-1} + \\frac{ds}{dt}\\Bigr|_{i-1} \\cdot \\Delta t\\]\n\\[i_i = i_{i-1} + \\frac{di}{dt}\\Bigr|_{i-1}  \\cdot \\Delta t\\]\n\\[r_i = r_{i-1} + \\frac{dr}{dt}\\Bigr|_{i-1}  \\cdot \\Delta t\\]\n\n\\noindent\nGiven the SIR differential equations, we have:\n\n\\[s_i = s_{i-1} - b \\hspace{0.5mm} s_{i-1} i_{i-1} \\cdot \\Delta t\\]\n\\[i_i = i_{i-1} + (- k i_{i-1} + b \\hspace{0.5mm} s_{i-1} i_{i-1}) \\cdot \\Delta t\\]\n\\[r_i = r_{i-1} + k \\hspace{0.5mm} i_{i-1} \\cdot \\Delta t\\]\n\n\\section{Finding Optimal Parameters for a Dataset}\nThere are a few ways to go about this. The first way is to estimate $b$ and $k$ based on the recovery rate and $R$ value typically associated with an SIR outbreak. The other way, which is far more involved, is to define a loss function between the predictions of the model and the data. Then, compute the sum of that loss function over all of the observations. This method gives us a way to quantify the difference between our model's predictions and the data. Using this method, we can then perform a grid search over all of the possible parameters to obtain the optimal model. \n\\end{document}", "meta": {"hexsha": "fe690d64b74a95564788d58091350c8eb8809dd2", "size": 5463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sir-explanation/sir.tex", "max_stars_repo_name": "atkinssamuel/COVID-19-projection", "max_stars_repo_head_hexsha": "4ae2b15fdc7ae4987f9ee021d0f5f966fa5cf632", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sir-explanation/sir.tex", "max_issues_repo_name": "atkinssamuel/COVID-19-projection", "max_issues_repo_head_hexsha": "4ae2b15fdc7ae4987f9ee021d0f5f966fa5cf632", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sir-explanation/sir.tex", "max_forks_repo_name": "atkinssamuel/COVID-19-projection", "max_forks_repo_head_hexsha": "4ae2b15fdc7ae4987f9ee021d0f5f966fa5cf632", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.119266055, "max_line_length": 579, "alphanum_fraction": 0.7116968699, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6065120070727001}}
{"text": "\\subsection{Definition of Concrete Map}\nFor any type of $\\CKey$ and $\\CVal$,\nthe concrete map is defined as a partial map of $\\CKey$ to $\\CVal$,\n$i.e., ~ \\CMap$.\\\\\nThere are 4 helper methods to handle a map:\\\\\n\n$\\begin{array}{rl}\n\\textsf{contains} & \\in (\\CMap) \\times \\CKey \\rightarrow \\textbf{Boolean} \\\\\n& \\textsf{contains}(m, k) = k \\in \\Dom(m) \\\\\n\\textsf{lookup} & \\in (\\CMap) \\times \\CKey \\rightarrow \\CVal \\cup \\{ \\texttt{false} \\}\\\\\n& \\textsf{lookup}(m, k) = \\left \\{ \\begin{array}{ll}\nm(k) & \\textrm{if } k \\in \\Dom(m) \\\\\n\\texttt{false} & \\textrm{otherwise} \\\\\n\\end{array} \\right. \\\\\n\\textsf{update} & \\in (\\CMap) \\times \\CKey \\times \\CVal \\rightarrow (\\CMap) \\\\\n& \\textsf{update}(m, k, v) = \\left \\{ \\begin{array}{ll}\n(m \\setminus \\{ [k \\mapsto m(k)] \\}) \\cup \\{ [k \\mapsto v] \\} & \\textrm{if } k \\in \\Dom(m) \\\\\nm \\cup \\{ [k \\mapsto v] \\} & \\textrm {otherwise} \\\\\n\\end{array} \\right.\\\\\n\\textsf{delete} & \\in (\\CMap) \\times \\CKey \\rightarrow (\\CMap) \\\\\n& \\textsf{delete}(m, k) = \\left \\{ \\begin{array}{ll}\n(m \\setminus \\{ [k \\mapsto m(k)] \\}) & \\textrm{if } k \\in \\Dom(m) \\\\\nm & \\textrm{otherwise} \\\\\n\\end{array} \\right. \\\\\n\\end{array}$\\\\\\\\\n$\\Dom$ is a property of a $\\CMap$:\\\\\n\n$\\forall m \\in \\CMap:\n\\Dom(m) = \\{ k \\in \\CKey \\mid \nm \\textrm{ has a mapped value for key } k \\}$\n", "meta": {"hexsha": "499fe16d00b24d0e01b5f569eb462d0201c98abf", "size": 1287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/obj/conmap.tex", "max_stars_repo_name": "aliahsan07/safe-development", "max_stars_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-25T12:53:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T23:29:49.000Z", "max_issues_repo_path": "doc/obj/conmap.tex", "max_issues_repo_name": "aliahsan07/safe-development", "max_issues_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "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/obj/conmap.tex", "max_forks_repo_name": "aliahsan07/safe-development", "max_forks_repo_head_hexsha": "542e4ebe5142912ad212a8517051462633bede2c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-03T21:38:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T21:38:53.000Z", "avg_line_length": 41.5161290323, "max_line_length": 93, "alphanum_fraction": 0.5866355866, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6064183044276705}}
{"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{eurosym}\n\\usepackage{enumerate}\n\n\\title{\\textbf{Week 6.} Sequential games with complete information II: Subgame perfection and repeated games}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\vspace{-1cm}\n\n\\subsection*{Exercise 1: Battle of the sexes with an outside option}\n\nThe battle of sexes is a game where two people would prefer to do something\ntogether, but each person likes a different activity best. The payoff matrix is\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & a_1 & a_2 \\\\\n        \\begin{block}{c(cc)}\n            a_1 & (3, 1) & (0, 0) \\\\\n            a_2 & (0, 0) & (1, 3) \\\\\n        \\end{block}\n    \\end{blockarray}\n\\end{equation*}\n\nNow suppose that before playing this game, player 1 can choose whether to play\nthis game or to exit. If player 1 exits, both players obtain a payoff of 2.\n\n\\textbf{Show that the battle of sexes with an outside option has two pure\nsubgame perfect equilibria:}\n\n\\begin{enumerate}[(i)]\n    \\item Player 1 plays, and both players choose activity \\(a_1\\).\n    \\item Player 1 exits, because if they were to play they would both choose\n    activity \\(a_2\\).\n\\end{enumerate}\n\n\\underline{\\textbf{Bonus question:}} Can you give a compelling argument why\nplayer 1 may be able to undermine the second equilibrium?\n\n\\subsection*{Exercise 2: Two rounds of rock-paper-scissors}\n\nConsider the game rock, paper, scissors with the following matrix\n\n\\begin{equation*}\n    \\begin{blockarray}{cccc}\n        & \\text{rock} & \\text{paper} & \\text{scissors} \\\\\n        \\begin{block}{c(ccc)}\n            \\text{rock}     & (0, 0)  & (-1, 1) & (1, -1) \\\\\n            \\text{paper}    & (1, -1) & (0, 0) & (-1, 1) \\\\\n            \\text{scissors} & (-1, 1) & (1, -1) & (0, 0) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n\\end{equation*}\n\n\\begin{enumerate}[(i)]\n    \\item If this game is played once, show that the strategy profile where both\nplayers use the mixed strategy (\\(\\frac{1}{3}, \\frac{1}{3}, \\frac{1}{3}\\)) is\nthe unique Nash equilibrium (You do not need to show uniqueness, only that it is\na Nash equilibrium).\n    \\item What is the subgame perfect equilibrium if the game is played twice?\n\\end{enumerate}\n\n\\textbf{Interpret the result.}\n\n\\subsection*{Bonus 1: Cooperation in a finitely repeated game}\n\nConsider the game with the payoff matrix\n\n\\begin{equation*}\n    \\begin{blockarray}{cccc}\n        & C & D_1 & D_2 \\\\\n        \\begin{block}{c(ccc)}\n            C   & (3, 3)   & (0, 4)   & (-12, 0) \\\\\n            D_1 & (4, 0)   & (1, 1)   & (-10, 0) \\\\\n            D_2 & (0, -12) & (0, -10) & (-5, -5) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n\\end{equation*}\n\n\\textbf{Show that:}\n\n\\begin{enumerate}[(i)]\n    \\item If the game is only played once, there is \\underline{no} Nash equilibrium\n    in which \\(C\\) is played with a positive probability.\n    \\item If the game is played twice, there is a subgame perfect equilibrium\n    in which \\(C\\) is played in the first round.\n\\end{enumerate}\n\n\n[Hint: Consider the strategy: Play \\(C\\) in the first round. If both players\nplayed \\(C\\) in the first round play \\(D_1\\) in the second round, otherwise play\n\\(D_2\\).]\n\n\\subsection*{Bonus Exercise 2: Repeated prisoner's dilemma}\n\nConsider the infinitely repeated prisoner's dilemma with payoffs,\n\n\\begin{equation*}\n    \\begin{blockarray}{ccc}\n        & C & D \\\\\n        \\begin{block}{c(cc)}\n            C & (3, 3) & (0, 4) \\\\\n            D & (4, 1) & (1, 1) \\\\\n        \\end{block}\n    \\end{blockarray}\\qquad\n\\end{equation*}\n\n\n\\textbf{Prove that there are sequences of actions such that players' average payoff,}\n\n\\[\\frac{1}{T+1} \\sum\\limits_{t=0}^{T} u^{(i)}(a_t)\\]\n\n\\textbf{does not converge as \\(T \\rightarrow \\infty\\).}\n\n[Hint: Consider the case that both players first play \\(C\\) for one round. Then they\nplay \\(D\\) for 2 rounds. Then they play \\(C\\) for four rounds. Then they play\n\\(D\\) for 8 rounds, etc]\n\n\\end{document}\n\n", "meta": {"hexsha": "f1fc6175793cf617201b5252772b3a8cc1a5c1f2", "size": 4166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "teaching/classical_game_theory/exercises/w6.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/w6.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/w6.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": 31.0895522388, "max_line_length": 109, "alphanum_fraction": 0.6476236198, "num_tokens": 1295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.8438951045175642, "lm_q1q2_score": 0.6064182900243182}}
{"text": "\\section{Displacement and Area}\\label{sec:AreaProb}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\\begin{example}{Object Moving in a Straight Line}{ObjectMovingStraightLine}\r\nAn object moves in a straight line so that\r\nits speed at time $t$ is given by $v(t)=3t$ in, say, cm/sec. If the\r\nobject is at position $10$ on the straight line when $t=0$, where is\r\nthe object at any time $t$? \r\n\\end{example}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\\begin{solution} \r\nThere are two reasonable ways to approach this problem. If $s(t)$ is\r\nthe position of the object at time $t$, we know that\r\n$s'(t)=v(t)$. Based on our knowledge of derivatives, we\r\ntherefore know that $\\ds s(t)=3t^2/2+k$, and because $s(0)=10$ we easily\r\ndiscover that $k=10$, so $\\ds s(t)=3t^2/2+10$. For example, at $t=1$ the\r\nobject is at position $3/2+10=11.5$.\r\nThis is certainly the easiest way to deal with this problem. Not all\r\nsimilar problems are so easy, as we will see; the second approach to\r\nthe problem is more difficult but also more general.\r\n\r\nWe start by considering how we might approximate a solution. We know\r\nthat at $t=0$ the object is at position 10. How might we approximate\r\nits position at, say, $t=1$? We know that the speed of the object at\r\ntime $t=0$ is $0$; if its speed were constant then in the first second\r\nthe object would not move and its position would still be 10 when\r\n$t=1$. In fact, the object will not be too far from 10 at $t=1$, but\r\ncertainly we can do better. Let's look at the times $0.1$, $0.2$,\r\n$0.3$, \\dots, $1.0$, and try approximating the location of the object\r\nat each, by supposing that during each tenth of a second the object is\r\ngoing at a constant speed. Since the object initially has speed 0, we\r\nagain suppose it maintains this speed, but only for a tenth of second;\r\nduring that time the object would not move. During the tenth of a\r\nsecond from $t=0.1$ to $t=0.2$, we suppose that the object is\r\ntraveling at $0.3$ cm/sec, namely, its actual speed at $t=0.1$. In\r\nthis case the object would travel $(0.3)(0.1)=0.03$ centimeters: $0.3$\r\ncm/sec times $0.1$ seconds. Similarly, between $t=0.2$ and $t=0.3$ the\r\nobject would travel $(0.6)(0.1)=0.06$ centimeters.  Continuing, we get\r\nas an approximation that the object travels\r\n$$ \r\n  (0.0)(0.1)+(0.3)(0.1)+(0.6)(0.1)+\\cdots+(2.7)(0.1)=1.35\r\n$$ \r\ncentimeters, ending up at position 11.35. This is a better\r\napproximation than 10, certainly, but is still just an\r\napproximation. (We know in fact that the object ends up at position\r\n$11.5$, because we've already done the problem using the first\r\napproach.) Presumably, we will get a better approximation if we divide\r\nthe time into one hundred intervals of a hundredth of a second each,\r\nand repeat the process:\r\n$$\r\n  (0.0)(0.01)+(0.03)(0.01)+(0.06)(0.01)+\\cdots+(2.97)(0.01)=1.485.\r\n$$\r\nWe thus approximate the position as $11.485$. Since we know the exact\r\nanswer, we can see that this is much closer, but if we did not already\r\nknow the answer, we wouldn't really know how close.\r\n\r\nWe can keep this up, but we'll never really know the exact answer if\r\nwe simply compute more and more examples. Let's instead look at a\r\n``typical'' approximation. Suppose we divide the time into $n$ equal\r\nintervals, and imagine that on each of these the object travels at a\r\nconstant speed. Over the first time interval we approximate the\r\ndistance traveled as $(0.0)(1/n)=0$, as before. During the second time\r\ninterval, from $t=1/n$ to $t=2/n$, the object travels approximately\r\n$\\ds 3(1/n)(1/n)=3/n^2$ centimeters. During time interval number $i$, the\r\nobject travels approximately $\\ds (3(i-1)/n)(1/n)=3(i-1)/n^2$\r\ncentimeters, that is, its speed at time $(i-1)/n$, $3(i-1)/n$, times\r\nthe length of time interval number $i$, $1/n$.\r\nAdding these up as before, we approximate the distance traveled as\r\n$$\r\n  (0){1\\over n}+3{1\\over n^2}+3(2){1\\over n^2}+\r\n  3(3){1\\over n^2}+\\cdots+3(n-1){1\\over n^2}\r\n$$\r\ncentimeters. What can we say about this? At first it looks rather less\r\nuseful than the concrete calculations we've already done, but in fact\r\na bit of algebra reveals it to be much more useful. We can factor out\r\na 3 and $\\ds 1/n^2$ to get\r\n$$\r\n  {3\\over n^2}(0+1+2+3+\\cdots+(n-1)),\r\n$$\r\nthat is, $\\ds 3/n^2$ times the sum of the first $n-1$ positive\r\nintegers. Now we make use of a fact you may have run across before, Gauss's Equation:\r\n$$\r\n  1+2+3+\\cdots+k={k(k+1)\\over2}.\r\n$$\r\nIn our case we're interested in $k=n-1$, so\r\n$$\r\n  1+2+3+\\cdots+(n-1)={(n-1)(n)\\over2}={n^2-n\\over2}.\r\n$$\r\nThis simplifies the approximate distance traveled to \r\n$$\r\n  {3\\over n^2}{n^2-n\\over2}={3\\over2}{n^2-n\\over n^2}=\r\n  {3\\over2}\\left({n^2\\over n^2}-{n\\over n^2}\\right)=\r\n  {3\\over2}\\left(1-{1\\over n}\\right).\r\n$$\r\nNow this is quite easy to understand: as $n$ gets larger and larger\r\nthis approximation gets closer and closer to $(3/2)(1-0)=3/2$, so that\r\n$3/2$ is the exact distance traveled during one second, and the final\r\nposition is $11.5$.\r\n\r\nSo for $t=1$, at least, this rather cumbersome approach gives the same\r\nanswer as the first approach. But really there's nothing special about\r\n$t=1$; let's just call it $t$ instead. In this case the approximate\r\ndistance traveled during time interval number $i$ is $\\ds\r\n3(i-1)(t/n)(t/n)=3(i-1)t^2/n^2$, that is, speed $3(i-1)(t/n)$ times\r\ntime $t/n$, and the total distance traveled is approximately\r\n$$\r\n  (0){t\\over n}+3(1){t^2\\over n^2}+3(2){t^2\\over n^2}+\r\n  3(3){t^2\\over n^2}+\\cdots+3(n-1){t^2\\over n^2}.\r\n$$\r\nAs before we can simplify this to\r\n$$\r\n  {3t^2\\over n^2}(0+1+2+\\cdots+(n-1))={3t^2\\over n^2}{n^2-n\\over2}=\r\n  {3\\over2}t^2\\left(1-{1\\over n}\\right).\r\n$$ \r\nIn the limit, as $n$ gets larger, this gets closer and closer to $\\ds\r\n(3/2)t^2$ and the approximated position of the object gets closer and\r\ncloser to $\\ds (3/2)t^2+10$, so the actual position is $\\ds\r\n(3/2)t^2+10$, exactly the answer given by the first approach to the\r\nproblem.\r\n\\end{solution}\r\n\r\n\\begin{example}{Area under the Line}{area under line} \r\nFind the area under the\r\ncurve $y=3x$ between $x=0$ and any positive value $x$. \r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThere is here\r\nno obvious analogue to the first approach in the previous example, but\r\nthe second approach works fine. (Since the function $y=3x$ is so\r\nsimple, there is another approach that works here, but it is even more\r\nlimited in potential application than is approach number one.)  How\r\nmight we approximate the desired area? We know how to compute areas of\r\nrectangles, so we approximate the area by rectangles. Jumping straight\r\nto the general case, suppose we divide the interval between 0 and $x$\r\ninto $n$ equal subintervals, and use a rectangle above each\r\nsubinterval to approximate the area under the curve. There are many\r\nways we might do this, but let's use the height of the curve at the\r\nleft endpoint of the subinterval as the height of the rectangle, as in\r\nfigure~\\xrefn{fig:approximating area by rectangles}. The height of\r\nrectangle number $i$ is then $3(i-1)(x/n)$, the width is $x/n$, and\r\nthe area is $\\ds 3(i-1)(x^2/n^2)$. The total area of the rectangles is\r\n$$\r\n  (0){x\\over n}+3(1){x^2\\over n^2}+3(2){x^2\\over n^2}+\r\n  3(3){x^2\\over n^2}+\\cdots+3(n-1){x^2\\over n^2}.\r\n$$\r\nBy factoring out $\\ds 3x^2/n^2$ this simplifies to \r\n$$\r\n  {3x^2\\over n^2}(0+1+2+\\cdots+(n-1))={3x^2\\over n^2}{n^2-n\\over2}=\r\n  {3\\over2}x^2\\left(1-{1\\over n}\\right).\r\n$$\r\nAs $n$ gets larger this gets closer and closer to $\\ds 3x^2/2$, which must\r\ntherefore be the true area under the curve.\r\n\\end{solution}\r\n\r\n\\figure[H]\r\n\\centerline{\\vbox{\\beginpicture\r\n\\normalgraphs\r\n%\\ninepoint\r\n\\setcoordinatesystem units <0.5truecm,0.2truecm>\r\n\\setplotarea x from 0 to 10, y from 0 to 30\r\n\\axis left shiftedto x=0 /\r\n\\axis bottom shiftedto y=0 /\r\n\\put {$\\ldots$} at 6.5 8\r\n\\setlinear\r\n\\plot 0 0 10 30 /\r\n\\setdashes <2pt>\r\n\\putrule from 1 0 to 1 3\r\n\\putrule from 2 0 to 2 6\r\n\\putrule from 3 0 to 3 9\r\n\\putrule from 4 0 to 4 9\r\n\\putrule from 9 0 to 9 27\r\n\\putrule from 10 0 to 10 27\r\n\\putrule from 1 3 to 2 3\r\n\\putrule from 2 6 to 3 6\r\n\\putrule from 3 9 to 4 9\r\n\\putrule from 9 27 to 10 27\r\n\\endpicture}}\r\n\\caption{Approximating the area under $y=3x$ with rectangles. \\label{fig:approximating area by rectangles}}\r\n\\endfigure\r\n\r\nWhat you will have noticed, of course, is that while the problem in\r\nthe second example appears to be much different than the problem in\r\nthe first example, and while the easy approach to problem one does not\r\nappear to apply to problem two, the ``approximation'' approach works\r\nin both, and moreover the {\\it calculations are identical.} As we will\r\nsee, there are many, many problems that appear much different on the\r\nsurface but turn out to be the same as these problems, in the\r\nsense that when we try to approximate solutions we end up with\r\nmathematics that looks like the two examples, though of course the\r\nfunction involved will not always be so simple.\r\n\r\nEven better, we now see that while the second problem did not appear\r\nto be amenable to approach one, it can in fact be solved in the same\r\nway. The reasoning is this: we know that problem one can be solved\r\neasily by finding a function whose derivative is $3t$. We also know\r\nthat mathematically the two problems are the same, because both can be\r\nsolved by taking a limit of a sum, and the sums are\r\nidentical. Therefore, we don't really need to compute the limit of\r\neither sum because we know that we will get the same answer by\r\ncomputing a function with the derivative $3t$ or, which is the same\r\nthing, $3x$.\r\n\r\nIt's true that the first problem had the added complication of the\r\n``10'', and we certainly need to be able to deal with such minor\r\nvariations, but that turns out to be quite simple. The lesson then is\r\nthis: whenever we can solve a problem by taking the limit of a sum of\r\na certain form, instead of computing the (often nasty) limit we can\r\nfind a new function with a certain derivative.\r\n\r\n\r\n\\subsection{Sigma Notation}\r\n\\vskip\\baselineskip\r\nTo refine the area approximations we use more rectangles. The notation can become unwieldy, as we add up longer and longer lists of numbers. For this reason we introduce \\textbf{sigma notation}. \\index{sigma!notation}\\\\\r\n\r\n\r\nSuppose we wish to add up a list of numbers $a_1$, $a_2$, $a_3$, \\ldots, $a_9$. Instead of writing $$a_1+a_2+a_3+a_4+a_5+a_6+a_7+a_8+a_9,$$ we use sigma notation and write \r\n\\begin{center}\r\n%\\includegraphics[scale=.7]{figures/figrie_notation}\r\n\\begin{tikzpicture}[scale=1.5,>=latex]\r\n%\\draw [thin,step=1cm] (0,0) grid  (3,3);\r\n\\draw  (1,1) node {$\\displaystyle \\sum_{i=1}^9 a_i$.};\r\n\r\n\\draw [{\\colorone}] (-.2,0) node [text width=45pt,align=center](a) {\\scriptsize \\centering $i$=index \\\\[-5pt] of summation};\r\n\\draw [{\\colorone},->] (a) -- (.6,.5);\r\n\r\n\\draw [{\\colorone}] (2,0) node [text width=20pt,align=center] (b) {\\scriptsize \\centering lower\\\\[-5pt] bound};\r\n\\draw [{\\colorone},->] (b) -- (1.05,.5);\r\n\r\n\\draw [{\\colorone}] (0,2) node [text width=32pt,align=center] (c) {\\scriptsize \\centering upper\\\\[-5pt] bound};\r\n\\draw [{\\colorone},->] (c) -- (.7,1.5);\r\n\r\n\\draw [{\\colorone}] (2,2) node [text width=32pt,align=center] (d) {\\scriptsize \\centering summand};\r\n\\draw [{\\colorone},->] (d) -- (1.4,1.2);\r\n\r\n\\draw [{\\colorone}] (-1,1) node [text width=50pt,align=center] (e) {\\scriptsize \\centering summation \\\\[-1pt] symbol \\\\[-1pt] (an upper case\\\\[-5pt] sigma)};\r\n\\draw [{\\colorone},->] (e) -- (.6,1);\r\n\\end{tikzpicture}\r\n\\caption{Understanding sigma notation.}\\label{fig:rie_notation}\r\n\\end{center}\r\n\r\nThe upper case sigma represents the term ``sum.'' The index of summation in this example is $i$; any symbol can be used. By convention, the index takes on only the integer values between (and including) the lower and upper bounds. \r\n\r\nLet's practice using this notation.\\\\\r\n\r\n\\begin{example}{Using sigma notation}{ex_rie3}{\r\nLet the numbers $\\{a_i\\}$ be defined as $a_i = 2i-1$ for integers $i$, where $i\\geq 1$. So $a_1 = 1$, $a_2 = 3$, $a_3 = 5$, etc. (The output is the positive odd integers). Evaluate the following summations:\r\n$$ 1.\\ \\sum_{i=1}^6 a_i \\qquad\\qquad\\qquad 2.\\ \\sum_{i=3}^7 (3a_i-4)\\qquad\\qquad \\qquad 3.\\ \\sum_{i=1}^4 (a_i)^2$$\r\n}\r\n\\end{example}\r\n\\begin{solution}\r\n{\\begin{enumerate}\r\n\t\t\\item\t\t\\noindent\\vskip-45pt%\\begin{minipage}[t]{\\linewidth}\r\n\t\t\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\t\\sum_{i=1}^6 a_i &= a_1+a_2+a_3+a_4+a_5+a_6\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&=\t1+3+5+7+9+11 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&=\t36.\r\n\t\t\t\t\t\\end{align*}\r\n%\t\t\t\t\t\\end{minipage}\r\n\t\t\\item\tNote the starting value is different than 1:\r\n\t\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\\sum_{i=3}^7 a_i &= (3a_3-4)+(3a_4-4)+(3a_5-4)+(3a_6-4)+(3a_7-4) \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= 11+17+23+29+35 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= 115.\r\n\t\t\t\t\t\\end{align*}\r\n\t\t\\item\t\t\\noindent\\vskip-45pt%\\begin{minipage}[t]{\\linewidth}\r\n\t\t\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\t\\sum_{i=1}^4 (a_i)^2 &=\t(a_1)^2+(a_2)^2+(a_3)^2+(a_4)^2\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&=\t1^2+3^2+5^2+7^2 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t&=\t84\r\n\t\t\t\t\t\t\\end{align*}\r\n\\end{enumerate}\t\t\t\t\t\t\t\t\t\t\t\t\r\n}\r\n\\end{solution}\r\n\r\n\r\nIt might seem odd to stress a new, concise way of writing summations only to write each term out as we add them up. It is. The following theorem gives some of the properties of summations that allow us to work with them without writing individual terms. The first three properties are typically referred to as the \\textit{linearity properties}. Examples will follow.\r\n\r\n\\begin{theorem}{Properties of Summations}{summation}\r\n{\\noindent\\begin{minipage}[t]{200pt}\\index{summation!properties}\r\n\\begin{enumerate}\r\n\t\t\\item\t\t$\\ds \\sum_{i=1}^n c = c\\cdot n$, where $c$ is a constant.\r\n\t\t\\item\t\t$\\ds \\sum_{i=m}^n (a_i\\pm b_i) = \\sum_{i=m}^n a_i \\pm \\sum_{i=m}^n b_i$\r\n\t\t\\item\t\t$\\ds \\sum_{i=m}^n c\\cdot a_i = c\\cdot\\sum_{i=m}^n a_i$\r\n\t\t\\item\t\t$\\ds \\sum_{i=m}^j a_i + \\sum_{i=j+1}^n  a_i = \\sum_{i=m}^n a_i$\r\n%\t\t\\item\t\t$\\ds \\sum_{i=1}^n i = \\frac{n(n+1)}2$\r\n%\t\t\\item\t\t$\\ds \\sum_{i=1}^n i^2 = \\frac{n(n+1)(2n+1)}6$\r\n%\t\t\\item\t\t$\\ds \\sum_{i=1}^n i^3 = \\left(\\frac{n(n+1)}2\\right)^2$\r\n\t\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}[t]{200pt}\r\n\\begin{enumerate}\\addtocounter{enumi}{4}\r\n%\t\t\\item\t\t$\\ds \\sum_{i=1}^n c = c\\cdot n$, where $c$ is a constant.\r\n%\t\t\\item\t\t$\\ds \\sum_{i=m}^n (a_i\\pm b_i) = \\sum_{i=m}^n a_i \\pm \\sum_{i=m}^n b_i$\r\n%\t\t\\item\t\t$\\ds \\sum_{i=1}^n c\\cdot a_i = c\\cdot\\sum_{i=1}^n a_i$\r\n%\t\t\\item\t\t$\\ds \\sum_{i=m}^j a_i + \\sum_{i=j+1}^n  a_i = \\sum_{i=m}^n a_i$\r\n\t\t\\item\t\t$\\ds \\sum_{i=1}^n i = \\frac{n(n+1)}2$\r\n\t\t\\item\t\t$\\ds \\sum_{i=1}^n i^2 = \\frac{n(n+1)(2n+1)}6$\r\n\t\t\\item\t\t$\\ds \\sum_{i=1}^n i^3 = \\left(\\frac{n(n+1)}2\\right)^2$\r\n\t\\end{enumerate}\r\n\\end{minipage}\r\n}\r\n\r\n\\end{theorem}\r\n\r\n\\begin{example}{Evaluating summations using Theorem \\ref{thm:summation}}{ex_rie4}\r\n{Revisit Example \\ref{exa:ex_rie3} and, using Theorem \\ref{thm:summation}, evaluate $$\\sum_{i=1}^6 a_i = \\sum_{i=1}^6 (2i-1).$$\r\n}\r\n\\end{example}\r\n\\begin{solution}\r\n{\\begin{align*}\r\n\t\t\\sum_{i=1}^6 (2i-1) & = \\sum_{i=1}^6 2i - \\sum_{i=1}^6 (1)\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&=\t\\left(2\\sum_{i=1}^6 i \\right)- 6 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&= 2\\frac{6(6+1)}{2} - 6 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t&= 42-6 = 36\r\n \\end{align*}\r\n We obtained the same answer without writing out all six terms. When dealing with small sizes of $n$, it may be faster to write the terms out by hand. However, Theorem \\ref{thm:summation} is incredibly important when dealing with large sums as we'll soon see.\r\n }\r\n \\end{solution}\r\n\r\n\r\n\\subsection{Approximating the Area of a Plane Region}\r\nAs we have observed above, if $ f(t) $ is a positive velocity function, then the area under the graph of $ f(x) $ over the interval $ [t_1,t_2] $ is the distance travelled over the same time interval.  Note that if $ f(t) $ is allowed to be negative, then the area provides the displacement over the interval.\\\\  \r\n\r\n\r\n\r\n\r\n% left hand sums\r\n%\\begin{tikzpicture}[/pgf/declare function={f=4/x;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=9,ymin=0,ymax=4,\r\n%    domain=0:10,\r\n%    samples=100,\r\n%    axis lines=middle\r\n%]\r\n%\\addplot [thick, red] {f};\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    left segments=7,\r\n%    left=1:8\r\n%] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n\r\n\r\n\r\n\r\n\r\nFor the rest of this section, we assume that $f(x)$ is {\\bf{continuous and positive}}, so that the graph lies above the $x$-axis. Our goal is to compute the area ``under the graph\", that is, the area between the graph and the $x$-axis.  As a first step, we approximate the area using rectangles.\\\\\r\n\r\nThere are three common ways to determine the height of these rectangles: the \\textbf{Right Hand Rule} (LHR), the \\textbf{Left Hand Rule} (RHR), and the \\textbf{Midpoint Rule} (MPR). The \\textbf{Riight Hand Rule} says to evaluate the function at the right--hand endpoint of the subinterval and make the rectangle that height. \r\n\r\nThe \\textbf{Left Hand Rule} says the opposite: on each subinterval, evaluate the function at the left endpoint and make the rectangle that height. \r\n\r\nThe \\textbf{Midpoint Rule} says that on each subinterval, evaluate the function at the midpoint and make the rectangle that height. \r\n\r\n\r\n%Suppose we wish to find the area under $y = x^2$ between $x = 0$ and $x = 1$. \r\n%\r\n%\\begin{tikzpicture}[/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle\r\n%]\r\n%\\addplot [thick, red, ,name path=A] {f};\r\n% \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n%  \\addplot [green] fill between[of=A and B,soft clip={domain=0:1}]; % filling\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\r\n%\r\n%\r\n%\r\n%We can first approximate the area using the RHR. Divide $[0,1]$ into three strips of width $\\frac{1}{3}$, and draw rectangles in those strips, the heights of which are the same as the height of the function at the right end of that strip. Four strips gives a better approximation, and five is even better...\\\\\r\n%\\begin{figure}\r\n%% right hand sums\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%     xtick parsed={0, 1/3, 2/3, 1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=3,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%     xtick parsed={0, 1/4, 1/2, 3/4, 1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=4,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%     xtick parsed={0, 1/5, 2/5, 3/5, 4/5, 1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=5,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\r\n%\\caption{Approximating the area under $ f(x)=x^2 $ using the RHR, $ n=3, 4,$ and $ 5 $ (right-hand) rectangles, respectively. \\label{fig:ApproxAreaRHR1}}\r\n%\\end{figure}\r\n%\r\n%\r\n%\r\n%If we use more and more rectangles we get better and better approximations.\r\n%\r\n%\\begin{figure}\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     ]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=10,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     ]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=20,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%     ]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    right segments=40,\r\n%    right=0:1,\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\r\n%\\caption{Approximating the area under $ f(x)=x^2 $ using the RHR, $ n=10, 20,$ and $ 40 $ (right-hand) rectangles, respectively. \\label{fig:ApproxAreaRHR2}}\r\n%\\end{figure}\r\n%\r\n%\r\n% Alternatively, we could use the LHR to determine the heights of the rectangles.\r\n%\r\n%\\begin{figure}\r\n%\\begin{tikzpicture}[scale=.7,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%    xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%         xtick parsed={0, 1/3, 2/3, 1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green, opacity=.2,\r\n%    left segments=3,\r\n%    left=0:1\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.7,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%    xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%         xtick parsed={0, 1/4, 1/2, 3/4,1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green, opacity=.2,\r\n%    left segments=4,\r\n%    left=0:1\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\begin{tikzpicture}[scale=.7,/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle,\r\n%    xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n%         xtick parsed={0, 1/5, 2/5, 3/5,4/5,1}\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green, opacity=.2,\r\n%    left segments=5,\r\n%    left=0:1\r\n%] {f};\r\n%\\addplot [thick, red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\\caption{Approximating the area under $ f(x)=x^2 $ using the LHR, $ n=3, 4,$ and $ 5 $ (left-hand) rectangles, respectively. \\label{fig:ApproxAreaLHR}}\r\n%\\end{figure}\r\n%\r\n%\r\n%We could also use the midpoint rule (MPR).\r\n%\r\n%\\begin{figure}\r\n%% mid point\r\n%\\begin{tikzpicture}[/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    midpoint segments=3,\r\n%    midpoint=0:1,\r\n%] {f};\r\n%\\addplot [thick,red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%% mid point\r\n%\\begin{tikzpicture}[/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    midpoint segments=4,\r\n%    midpoint=0:1,\r\n%] {f};\r\n%\\addplot [thick,red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%% mid point\r\n%\\begin{tikzpicture}[/pgf/declare function={f=x^2;}]\r\n%\\begin{axis}[\r\n%        xmin=0,xmax=1.2,ymin=0,ymax=2,\r\n%    domain=0:1.1,\r\n%    samples=100,\r\n%    axis lines=middle\r\n%]\r\n%\\addplot [\r\n%    black!80,fill=green,opacity=.3,\r\n%    midpoint segments=5,\r\n%    midpoint=0:1,\r\n%] {f};\r\n%\\addplot [thick,red] {f};\r\n%\\end{axis}\r\n%\\end{tikzpicture}\r\n%\r\n%\r\n%\\caption{Approximating the area under $ f(x)=x^2 $ using the MPR, $ n=3, 4,$ and $ 5 $ (mid-point) rectangles, respectively. \\label{fig:ApproxAreaMP}}\r\n%\\end{figure}\r\n\r\n\r\n\\begin{example}{Using the Left Hand, Right Hand and Midpoint Rules}{ex_rie2}\r\n \r\nApproximate the value of $\\int_0^4 (4x-x^2)\\ dx$ using the Left Hand Rule, the Right Hand Rule, and the Midpoint Rule, using 4 equally spaced subintervals.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n We break the interval $[0,4]$ into four subintervals. In Figure \\ref{fig:rie2a} we see 4 rectangles drawn on $f(x) = 4x-x^2$ using the Left Hand Rule. \r\n\r\n\\begin{minipage}[t]{\\linewidth}\r\n%\\begin{figure}\r\n\\begin{center}\r\n\\begin{tikzpicture}[/pgf/declare function={f=(4*x-x^2);}]\r\n\\begin{axis}[\r\n        xmin=0,xmax=4.1,ymin=0,ymax=4.5,\r\n    domain=0:4,\r\n    samples=100,\r\n    axis lines=middle,\r\n   % xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n   %      xtick parsed={0, 1, 2, 3, 4}\r\n]\r\n\\addplot [\r\n    black!80,fill=green, opacity=.2,\r\n    left segments=4,\r\n    left=0:4,\r\n] {f};\r\n\\addplot [thick, red] {f};\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\caption{Approximating the area under $f(x)= 4x-x^2$ on $ [0,4] $ using the Left Hand Rule \\label{fig:rie2a}}\r\n\\end{center}\r\n\\end{minipage}\r\n%\\end{figure}\r\n\r\n\\noindent Note how in the first subinterval, $[0,1]$, the rectangle has height $f(0)=0$. We add up the areas of each rectangle (height$\\times$ width) for our Left Hand Rule approximation:\r\n\t\\begin{align*} f(0)\\cdot 1 + f(1)\\cdot 1+ f(2)\\cdot 1+f(3)\\cdot 1 &=\\\\\r\n\t0+3+4+3&= 10.\r\n\t\\end{align*}\r\n\t\r\nFigure \\ref{fig:rie2b} shows 4 rectangles drawn under $f$ using the Right Hand Rule; note how the $[3,4]$ subinterval has a rectangle of height 0. \r\n\r\n\\begin{minipage}[t]{\\linewidth}\r\n\\begin{center}\r\n\\begin{tikzpicture}[/pgf/declare function={f=4*x-x^2;}]\r\n\\begin{axis}[\r\n        xmin=0,xmax=4.1,ymin=0,ymax=4.5,\r\n            domain=0:4,\r\n            samples=100,\r\n            axis lines=middle,\r\n         %   xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n         %        xtick parsed={0, 1, 2, 3, 4}\r\n]\r\n\\addplot [\r\n    black!80,fill=green, opacity=.2,\r\n    right segments=4,\r\n    right=0:4\r\n] {f};\r\n\\addplot [thick, red] {f};\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\caption{Approximating the area under $f(x)= 4x-x^2$ on $ [0,4] $ using the Right Hand Rule \\label{fig:rie2b}}\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\\noindent In this example, these rectangle seem to be the mirror image of those found in Figure \\ref{fig:rie2a}. (This is because of the symmetry of our shaded region.) Our approximation gives the same answer as before, though calculated a different way:\r\n\t\\begin{align*} f(1)\\cdot 1 + f(2)\\cdot 1+ f(3)\\cdot 1+f(4)\\cdot 1 &=\\\\\r\n\t3+4+3+0&= 10.\r\n\t\\end{align*}\r\n\r\nFigure \\ref{fig:rie2c} shows 4 rectangles drawn under $f$ using the Midpoint Rule.\r\n\r\n\\begin{minipage}[t]{\\linewidth}\r\n\\begin{center}\r\n\\begin{tikzpicture}[/pgf/declare function={f=4*x-x^2;}]\r\n\\begin{axis}[\r\n       xmin=0,xmax=4.1,ymin=0,ymax=4.5,\r\n           domain=0:4,\r\n           samples=100,\r\n           axis lines=middle,\r\n       %    xticklabel style={/pgf/number format/frac, /pgf/number format/frac shift=2},\r\n      %          xtick parsed={0, 1, 2, 3, 4}\r\n]\r\n\\addplot [\r\n    black!80,fill=green, opacity=.2,\r\n    midpoint segments=4,\r\n    midpoint=0:4\r\n] {f};\r\n\\addplot [thick, red] {f};\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\caption{Approximating the area under $f(x)= 4x-x^2$ on $ [0,4] $ using the Midpoint Rule \\label{fig:rie2c}}\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\\noindent This gives an approximation of \r\n\\begin{align*} f(0.5)\\cdot 1 + f(1.5)\\cdot 1+ f(2.5)\\cdot 1+f(3.5)\\cdot 1 &=\\\\\r\n\t1.75+3.75+3.75+1.75&= 11.\r\n\t\\end{align*}\r\nOur three methods provide two approximations of the area under $f(x)=4x-x^2 $ on $ [0.4] $: 10 and 11.\r\n\\end{solution}\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\\subsection{Riemann Sums}\r\n\r\n\r\nFor now, we continue to focus on determining an accurate estimate of area through the use of a sum of the areas of rectangles, doing so in the setting where $f(x) \\ge 0$ on $[a,b]$.  Throughout, unless otherwise indicated, we also assume that $f$ is continuous on $[a,b]$.\r\n\r\nThe first choice we make in any such approximation is the number of rectangles.  \r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_2_Interval}\r\n\\caption{Subdividing the interval $[a,b]$ into $n$ subintervals of equal length $\\triangle x$.} \\label{F:4.2.Interval}\r\n\\end{center}\r\n\\end{figure}\r\nIf we say that the total number of rectangles is $n$, and we desire $n$ rectangles of equal width to subdivide the interval $[a,b]$, then each rectangle must have width $\\triangle x = \\frac{b-a}{n}$. We observe further that $x_1 = x_0 + \\triangle x$, $x_2 = x_0 + 2 \\triangle x$, and thus in general $x_{i} = a + i\\triangle x,$ as pictured in Figure~\\ref{F:4.2.Interval}.\r\n\r\nWe use each subinterval $[x_i, x_{i+1}]$ as the base of a rectangle, and next must choose how to decide the height of the rectangle that will be used to approximate the area under $y = f(x)$ on the subinterval.  The three standard choices are the left endpoint, right endpoint, or the midpoint of each.  These are precisely the options encountered in the previous section.  We next explore how these choices can be reflected in sigma notation.\r\n\r\nIf we now consider an arbitrary positive function $f$ on $[a,b]$ with the interval subdivided as shown in Figure~\\ref{F:4.2.Interval}, and choose to use left endpoints, then on each interval of the form $[x_{i}, x_{i+1}]$, the area of the rectangle formed is given by\r\n$$A_{i+1} = f(x_i) \\cdot \\triangle x,$$\r\nas seen in Figure~\\ref{F:4.2.LeftSum}.\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_2_LeftSum}\r\n\\caption{Subdividing the interval $[a,b]$ into $n$ subintervals of equal length $\\triangle x$ and approximating the area under $y = f(x)$ over $[a,b]$ using left rectangles.} \\label{F:4.2.LeftSum}\r\n\\end{center}\r\n\\end{figure}\r\nIf we let $L_n$ denote the sum of the areas of rectangles whose heights are given by the function value at each respective left endpoint, then we see that\r\n\\begin{eqnarray*}\r\nL_n & = & A_1 + A_2 + \\cdots + A_{i+1} + \\cdots + A_n \\\\\r\n\t& = & f(x_0) \\cdot \\triangle x + f(x_1) \\cdot \\triangle x + \\cdots + f(x_i) \\cdot \\triangle x + \\cdots + f(x_{n-1}) \\cdot \\triangle x.\r\n\\end{eqnarray*}\r\nIn the more compact sigma notation, we have \r\n$$L_n = \\sum_{i = 0}^{n-1} f(x_i) \\triangle x.$$\r\nNote particularly that since the index of summation begins at $0$ and ends at $n-1$, there are indeed $n$ terms in this sum.  We call $L_n$ the \\emph{left Riemann sum} \\index{Riemann sum} \\index{Riemann sum!left} for the function $f$ on the interval $[a,b]$.\r\n\r\nThere are now two fundamental issues to explore:  the number of rectangles we choose to use and the selection of the pattern by which we identify the height of each rectangle.  It is best to explore these choices dynamically, and the applet\\footnote{Marc Renault, Geogebra Calculus Applets.} found at \\href{http://gvsu.edu/s/a9}{\\texttt{http://gvsu.edu/s/a9}} is a particularly useful one.  There we see\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\scalebox{0.35}{\\includegraphics{figures/4_2_RenaultAppletRS.pdf}}\r\n\\caption{A snapshot of the applet found at \\href{http://gvsu.edu/s/a9}{\\texttt{http://gvsu.edu/s/a9}}.} \\label{F:4.2.RenaultAppletRS}\r\n\\end{center}\r\n\\end{figure}\r\nthe image shown in Figure~\\ref{F:4.2.RenaultAppletRS}, but with the opportunity to adjust the slider bars for the left endpoint and the number of subintervals.  By moving the sliders, we can see how the heights of the rectangles change as we consider left endpoints, midpoints, and right endpoints, as well as the impact that a larger number of narrower rectangles has on the approximation of the exact area bounded by the function and the horizontal axis.  \r\n\r\nTo see how the Riemann sums for right endpoints and midpoints are constructed, we consider Figure~\\ref{F:4.2.RightMidSum}.\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_2_RightMidSum}\r\n\\caption{Riemann sums using right endpoints and midpoints.} \\label{F:4.2.RightMidSum}\r\n\\end{center}\r\n\\end{figure}\r\nFor the sum with right endpoints, we see that the area of the rectangle on an arbitrary interval $[x_i, x_{i+1}]$ is given by\r\n$$B_{i+1} = f(x_{i+1}) \\cdot \\triangle x,$$\r\nso that the sum of all such areas of rectangles is given by\r\n\\begin{eqnarray*}\r\nR_n & = & B_1 + B_2 + \\cdots + B_{i+1} + \\cdots + B_n \\\\\r\n\t& = &  f(x_1) \\cdot \\triangle x + f(x_2) \\cdot \\triangle x + \\cdots + f(x_{i+1}) \\cdot \\triangle x + \\cdots + f(x_{n}) \\cdot \\triangle x \\\\ \r\n\t& = & \\sum_{i=1}^{n} f(x_i) \\triangle x.\r\n\\end{eqnarray*}\r\nWe call $R_n$ the \\emph{right Riemann sum} \\index{Riemann sum!right} for the function $f$ on the interval $[a,b]$.  For the sum that uses midpoints, we introduce the notation\r\n$$\\overline{x}_{i+1} = \\frac{x_{i} + x_{i+1}}{2}$$\r\nso that $\\overline{x}_{i+1}$ is the midpoint of the interval $[x_i, x_{i+1}]$.  For instance, for the rectangle with area $C_1$ in Figure~\\ref{F:4.2.RightMidSum}, we now have\r\n$$C_1 = f(\\overline{x}_1) \\cdot \\triangle x.$$\r\nHence, the sum of all the areas of rectangles that use midpoints is \r\n\\begin{eqnarray*}\r\nM_n & = & C_1 + C_2 + \\cdots + C_{i+1} + \\cdots + C_n \\\\\r\n\t& = &  f(\\overline{x_1}) \\cdot \\triangle x + f(\\overline{x_2}) \\cdot \\triangle x + \\cdots + f(\\overline{x}_{i+1}) \\cdot \\triangle x + \\cdots + f(\\overline{x}_{n}) \\cdot \\triangle x \\\\ \r\n\t& = & \\sum_{i=1}^{n} f(\\overline{x}_i) \\triangle x,\r\n\\end{eqnarray*}\r\nand we say that $M_n$ is the \\emph{middle (or midpoint) Riemann sum} \\index{Riemann sum!middle} for $f$ on $[a,b]$.\r\n\r\nWhen $f(x) \\ge 0$ on $[a,b]$, each of the Riemann sums $L_n$, $R_n$, and $M_n$ provides an estimate of the area under the curve $y = f(x)$ over the interval $[a,b]$. As $ n $ increases, each of the approximations get better and better:\r\n\r\n\\begin{figure}\r\n\\begin{subfigure}{.33\\textwidth}\r\n  \\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n      domain=0:1.1,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n      black!80,fill=green,opacity=.3,\r\n      right segments=4,\r\n      right=0:1,\r\n  ] {f};\r\n  \\addplot [thick, red] {f};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{}\r\n  \\label{fig:approx_area1}\r\n\\end{subfigure}%\r\n\\begin{subfigure}{.33\\textwidth}\r\n  \\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n      domain=0:1.1,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n      black!80,fill=green,opacity=.3,\r\n      right segments=10,\r\n      right=0:1,\r\n  ] {f};\r\n  \\addplot [thick, red] {f};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{}\r\n  \\label{fig:approx_area2}\r\n\\end{subfigure}\r\n\\begin{subfigure}{.33\\textwidth}\r\n  \\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n      domain=0:1.1,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n      black!80,fill=green,opacity=.3,\r\n      right segments=40,\r\n      right=0:1,\r\n  ] {f};\r\n  \\addplot [thick, red] {f};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{}\r\n  \\label{fig:approx_area3}\r\n\\end{subfigure}\r\n\\caption{The approximations get better and better as the number of strips ($ n $) increases. \\label{fig:subst12}}\r\n\\label{fig:test}\r\n\\end{figure}\r\n\r\n\r\n\r\nThe following example lets us practice using the Right Hand Rule and the summation formulas introduced in Theorem \\ref{thm:summation}.\\\\\r\n\r\n\\begin{example}{Approximating definite integrals using sums}{ex_rie7}\r\n{\r\nApproximate the area $ A $ under $f(x) = 4x-x^2 \\ dx$ on $ [0,4] $ using the Right Hand Rule with 16 and 1000 equally spaced intervals.\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{Using 16 equally spaced intervals and the Right Hand Rule, we can approximate the area as \r\n$$\\sum_{i=1}^{16}f(x_{i+1})\\Delta x.$$\r\nWe have $\\Delta x = 4/16 = 0.25$. Since $x_i = 0+(i-1)\\Delta x$, we have \r\n\\begin{align*}\r\nx_{i+1} &= 0 + \\big((i+1)-1\\big)\\Delta x \\\\\r\n\t\t\t\t&=\ti\\Delta x\r\n\\end{align*}\r\n%In our examples using the Right Hand Rule is simpler notationally as $f(x_{i+1}) = f(i\\Delta x)$. \r\nThis gives:\\\\\r\n\\begin{minipage}{.6\\textwidth}\r\n\r\n\\begin{align}\r\n\\text{ Area } = A  &\\approx \\sum_{i=1}^{16} f(x_{i+1})\\Delta x \\notag\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^{16} f(i\\Delta x) \\Delta x\\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^{16} \\big(4i\\Delta x - (i\\Delta x)^2\\big)\\Delta x\\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^{16} (4i\\Delta x^2 - i^2\\Delta x^3)\\notag\\\\\t\t\r\n\t\t\t\t\t\t\t\t\t&= (4\\Delta x^2)\\sum_{i=1}^{16} i - \\Delta x^3 \\sum_{i=1}^{16} i^2 \\label{eq:rie7}\\\\\r\n\t\t\t\t\t\t\t\t\t&= (4\\Delta x^2)\\frac{16\\cdot 17}{2} - \\Delta x^3 \\frac{16(17)(33)}6 \\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&=\t4\\cdot 0.25^2\\cdot 136-0.25^3\\cdot 1496\\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&=10.625\\notag\r\n\\end{align}\r\n\\end{minipage}\r\n\\begin{minipage}{.35\\textwidth}\r\n\\begin{center}\r\n\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=(4*x-x^2);}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=4.1,ymin=0,ymax=4.1,\r\n      domain=0:4,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n      black!80,fill=green,opacity=.3,\r\n      right segments=16,\r\n      right=0:4,\r\n  ] {f};\r\n  \\addplot [thick, red] {f};\r\n\t  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{ \\label{fig:rie7} %Approximating with the Right Hand Rule and 16 evenly spaced subintervals.\r\n  }\r\n\\end{center}\r\n\\end{minipage}\r\n\r\nWe were able to sum up the areas of 16 rectangles with very little computation. In Figure \\ref{fig:rie7} the function and the 16 rectangles are graphed. \r\n\r\n%\\begin{minipage}[c]{.5\\textwidth}\r\n%\\centering\r\n%\\begin{tikzpicture}[scale=.75,/pgf/declare function={f=(4*x-x^2);}]\r\n%  \\begin{axis}[\r\n%          xmin=0,xmax=4.1,ymin=0,ymax=4.1,\r\n%      domain=0:4,\r\n%      samples=10,\r\n%      axis lines=middle,\r\n%       ]\r\n%  \\addplot [\r\n%      black!80,fill=green,opacity=.3,\r\n%      right segments=16,\r\n%      right=0:4,\r\n%  ] {f};\r\n%  \\addplot [thick, red] {f};\r\n%\t  \\end{axis}\r\n%  \\end{tikzpicture}\r\n%\\captionof{figure}{} %{Approximating with the Right Hand Rule and 16 evenly spaced subintervals.}\r\n%\\label{fig:rie7}\r\n%\\end{minipage}\r\n\r\nWhile some rectangles over--approximate the area, others under--approximate the area (by about the same amount). Thus our approximate area of 10.625 is likely a fairly good approximation. \r\n\r\nNotice  Equation \\eqref{eq:rie7}; by changing the 16's to 1,000's (and appropriately changing the value of $\\Delta x$), we can use that equation to sum up 1000 rectangles!\r\n\r\n\r\nWe do so here, skipping from the original summand to the equivalent of Equation \\eqref{eq:rie7} to save space. Note that $\\Delta x = 4/1000 = 0.004$.\r\n\\begin{align}\r\nA &\\approx \\sum_{i=1}^{1000} f(x_{i+1})\\Delta x \\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&= (4\\Delta x^2)\\sum_{i=1}^{1000} i - \\Delta x^3 \\sum_{i=1}^{1000} i^2 \\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&= (4\\Delta x^2)\\frac{1000\\cdot 1001}{2} - \\Delta x^3 \\frac{1000(1001)(2001)}6 \\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&=\t4\\cdot 0.004^2\\cdot 500500-0.004^3\\cdot 333,833,500\\notag\\\\\r\n\t\t\t\t\t\t\t\t\t&=10.666656\\notag\r\n\\end{align}\r\n\r\nUsing many, many rectangles, we have a likely good approximation of the area. That is, $$A \\approx 10.666656.$$\r\n}\r\n\\end{solution}\r\n\r\n\r\nThe previous example motivates the following definition.\r\n\r\n\\begin{definition}{Area}{area}\r\nThe area $ A $ of the region that lies under the graph of a continuous nonnegative function $ f $ over the interval $ [a,b] $ is the limit of the sum of the areas of approximating rectangles:\r\n\\[\r\nA = \\lim_{n\\to \\infty} R_n = \\sum_{i=1}^{n} f(x_i) \\Delta x, \r\n\\]\r\nwhere $ \\Delta x = \\frac{b-a}{n} $, and $ x_i=a+1\\Delta x $.\r\n\\end{definition}\r\n\r\n\\begin{example}{Approximating definite integrals with a formula, using sums}{ex_rie9}\r\n{\r\nRevisit Example \\ref{exa:ex_rie7}. Use Definition \\ref{def:area} to determine the area under $f(x) = 4x-x^2 \\ dx$ on $ [0,4] $ .}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nWe have $\\Delta x = \\frac{4-0}{n} = 4/n$, and $x_i = 0 + \\Delta x(i) = 4i/n$.\r\n\r\nWe construct the Riemann sum as follows. Be sure to follow each step carefully. If you get stuck, and do not understand how one line proceeds to the next, you may skip to the result and consider how this result is used. You should come back, though, and work through each step for full understanding.\r\n\\begin{align*}\r\n\t\tR_n &= \\sum_{i=1}^n f(x_{i+1})\\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^n f\\left(\\frac{4i}{n}\\right) \\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&=\t\\sum_{i=1}^n \\left[4\\frac{4i}n-\\left(\\frac{4i}n\\right)^2\\right]\\Delta x\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&=\t\\sum_{i=1}^n \\left(\\frac{16\\Delta x}{n}\\right)i - \\sum_{i=1}^n \\left(\\frac{16\\Delta x}{n^2}\\right)i^2 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&=\t\\left(\\frac{16\\Delta x}{n}\\right)\\sum_{i=1}^n i - \\left(\\frac{16\\Delta x}{n^2}\\right)\\sum_{i=1}^n i^2  \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\left(\\frac{16\\Delta x}{n}\\right)\\cdot \\frac{n(n+1)}{2} - \\left(\\frac{16\\Delta x}{n^2}\\right)\\frac{n(n+1)(2n+1)}{6} \\quad \\left(\\parbox{35pt}{\\scriptsize \\centering recall $\\Delta x = 4/n$}\\right)\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&=\\frac{32(n+1)}{n} - \\frac{32(n+1)(2n+1)}{3n^2} \\quad \\text{\\scriptsize (now simplify)} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac{32}{3}\\left(1-\\frac{1}{n^2}\\right)\r\n\\end{align*}\r\nTherefore, we have\r\n\\[\r\nA=\\lim_{n\\to \\infty}R_n = \\lim_{n\\to \\infty}\\frac{32}{3}\\left(1-\\frac{1}{n^2}\\right)=\\frac{32}{3}\\left(1-0\\right)=\\frac{32}{3}\r\n\\]\r\nNote that our approximation in Example \\ref{exa:ex_rie7} using 16 subintervals was actually quite a good estimate. \r\n\\end{solution}\r\n\r\n\r\n\r\n\r\nIt can be proved that the limit in Definition \\ref{def:area} always exists (as $ f $) is assumed to be continuous). Moreover, we get the same value of we take the limit using left endpoints, or midpoints. \r\n\r\n\r\n\r\n$$A = \\lim_{n \\to \\infty} R_n = \\lim_{n \\to \\infty} L_n = \\lim_{n \\to \\infty} M_n.$$  \r\n\r\n\r\nMomentarily, we will discuss the meaning of Riemann sums in the setting when $f$ is sometimes negative.  We also recall that in the context of a nonnegative velocity function $y = v(t)$, the corresponding Riemann sums are approximating the distance traveled on $[a,b]$ by the moving object with velocity function $v$.\r\n\r\nThere is a more general way to think of Riemann sums, and that is to not restrict the choice of where the function is evaluated to determine the respective rectangle heights.  That is, rather than saying we'll always choose left endpoints, or always choose midpoints, we simply say that a point $x_{i+1}^*$ will be selected at random in the interval $[x_i, x_{i+1}]$ (so that $x_i \\le x_{i+1}^* \\le x_{i+1}$), which makes the Riemann sum given by \r\n$$f(x_1^*) \\cdot \\triangle x + f(x_2^*) \\cdot \\triangle x + \\cdots + f(x_{i+1}^*) \\cdot \\triangle x + \\cdots + f(x_n^*) \\cdot \\triangle x = \\sum_{i=1}^{n} f(x_i^*) \\triangle x.$$\r\n\r\nDefinition \\ref{def:area} could also be made using this more general Riemann sum:\r\n\r\n\\begin{formulabox}[Area: another definition]\r\n$$A = \\lim_{n \\to \\infty} R_n = \\lim_{n \\to \\infty} L_n = \\lim_{n \\to \\infty} M_n = \\lim_{n \\to \\infty} \\sum_{i=1}^{n} f(x_i^*) \\triangle x.$$  \r\n\\end{formulabox}\r\n\r\nIn general, the \\textbf{lower} (resp. \\textbf{upper}) \\textbf{sums} are formed by choosing the sample points $ x_i^* $ so that $ f(x_i^*) $ is the minimum (resp. maximum) value of on the $ i $th subinterval. In the special case that $ f $ is monotone increasing  (resp. decreasing), the left and right endpoint approximations correspond to the lower and upper (resp. upper and lower) sums.\r\n   \r\n\r\n\\begin{figure}\r\n\\centering\r\n\\begin{subfigure}{.45\\textwidth}\r\n  \\begin{tikzpicture}[scale=.75,/pgf/declare function={f=x^2;}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n      domain=0:1.1,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n      black!80,fill=green,opacity=.3,\r\n      right segments=5,\r\n      right=0:1,\r\n  ] {f};\r\n  \\addplot [\r\n        black!80,fill=blue,opacity=.3,\r\n        left segments=5,\r\n        left=0:1,\r\n    ] {f};\r\n  \\addplot [thick, red] {f};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{$ f $ monotone increasing:\\\\ $ L_n\\le \\text{ Area } \\le R_n $}\r\n  \\label{fig:approx_area1}\r\n\\end{subfigure}%\r\n\\begin{subfigure}{.45\\textwidth}\r\n  \\begin{tikzpicture}[scale=.75,/pgf/declare function={f=(x-1)^2;}]\r\n  \\begin{axis}[\r\n          xmin=0,xmax=1.1,ymin=0,ymax=1.5,\r\n      domain=0:1.1,\r\n      samples=10,\r\n      axis lines=middle,\r\n       ]\r\n  \\addplot [\r\n        black!80,fill=blue,opacity=.3,\r\n        left segments=5,\r\n        left=0:1,\r\n    ] {f};\r\n    \\addplot [\r\n          black!80,fill=green,opacity=.3,\r\n          right segments=5,\r\n          right=0:1,\r\n      ] {f};\r\n  \\addplot [thick, red] {f};\r\n  \\end{axis}\r\n  \\end{tikzpicture}\r\n  \\caption{$ f $ monotone decreasing:\\\\ $ R_n\\le \\text{ Area } \\le L_n $}\r\n  \\label{fig:approx_area1}\r\n\\end{subfigure}%\r\n\\caption{For monttonic functions lower and upper sums are given by $ L_n $ or $ R_n $.}\r\n\\label{fig:test}\r\n\\end{figure}\r\n\r\n\r\nAt \\href{http://gvsu.edu/s/a9}{\\texttt{http://gvsu.edu/s/a9}}, the applet noted earlier and referenced in Figure~\\ref{F:4.2.RenaultAppletRS}, by unchecking the ``relative'' box at the top left, and instead checking ``random,'' we can easily explore the effect of using random point locations in subintervals on a given Riemann sum.  In computational practice, we most often use $L_n$, $R_n$, or $M_n$, while the random Riemann sum is useful in theoretical discussions.  \r\n\r\n\r\n\\subsection*{When the function is sometimes negative}\r\n\r\nFor a Riemann sum such as \r\n$$L_n = \\sum_{i=0}^{n-1} f(x_i) \\triangle x,$$\r\nwe can of course compute the sum even when $f$ takes on negative values.  We know that when $f$ is positive on $[a,b]$, the corresponding left Riemann sum $L_n$ estimates the area bounded by $f$ and the horizontal axis over the interval.  \r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_2_NegF}\r\n\\caption{At left and center, two left Riemann sums for a function $f$ that is sometimes negative; at right, the areas bounded by $f$ on the interval $[a,d]$.} \\label{F:4.2.NegF}\r\n\\end{center}\r\n\\end{figure}\r\nFor a function such as the one pictured in Figure~\\ref{F:4.2.NegF}, where in the first figure a left Riemann sum is being taken with 12 subintervals over $[a,d]$, we observe that the function is negative on the interval $b \\le x \\le c$, and so for the four left endpoints that fall in $[b,c]$, the terms $f(x_i) \\triangle x$ have negative function values.  This means that those four terms in the Riemann sum produce an estimate of the \\emph{opposite} of the area bounded by $y = f(x)$ and the $x$-axis on $[b,c]$.\r\n\r\nIn Figure~\\ref{F:4.2.NegF}, we also see evidence that by increasing the number of rectangles used in a Riemann sum, it appears that the approximation of the area (or the opposite of the area) bounded by a curve appears to improve.  For instance, in the middle graph, we use $ 24 $ left rectangles, and from the shaded areas, it appears that we have decreased the error from the approximation that uses 12.  When we proceed to the next section, we will discuss the natural idea of letting the number of rectangles in the sum increase without bound.  \r\n\r\nFor now, it is most important for us to observe that, in general, any Riemann sum of a continuous function $f$ on an interval $[a,b]$ approximates the difference between the area that lies above the horizontal axis on $[a,b]$ and under $f$ and the area that lies below the horizontal axis on $[a,b]$ and above $f$.  In the notation of Figure~\\ref{F:4.2.NegF}, we may say that\r\n$$L_{24} \\approx A_1 - A_2 + A_3,$$\r\nwhere $L_{24}$ is the left Riemann sum using $ 24 $ subintervals shown in the middle graph, and $A_1$ and $A_3$ are the areas of the regions where $f$ is positive on the interval of interest, while $A_2$ is the area of the region where $f$ is negative.  We will also call the quantity $A_1 - A_2 + A_3$ the \\emph{net signed area} \\index{net signed area} bounded by $f$ over the interval $[a,d]$, where by the phrase ``signed area'' we indicate that we are attaching a minus sign to the areas of regions that fall below the horizontal axis.\r\n\r\nFinally, we recall that in the context where the function $f$ represents the velocity of a moving object, the total sum of the areas bounded by the curve tells us the total distance traveled over the relevant time interval, while the total net signed area bounded by the curve computes the object's change in position on the interval.\r\n\r\n%\\nin \\framebox{\\hspace*{3 pt}\r\n%\\parbox{6.25 in}{\r\nSummary:\r\n\\begin{itemize}\r\n\\item A Riemann sum is simply a sum of products of the form $f(x_i^*) \\triangle x$ that estimates the area between a positive function and the horizontal axis over a given interval.  If the function is sometimes negative on the interval, the Riemann sum estimates the difference between the areas that lie above the horizontal axis and those that lie below the axis.\r\n\\item The three most common types of Riemann sums are left, right, and middle sums, plus we can also work with a more general, random Riemann sum.  The only difference among these sums is the location of the point at which the function is evaluated to determine the height of the rectangle whose area is being computed in the sum.  For a left Riemann sum, we evaluate the function at the left endpoint of each subinterval, while for right and middle sums, we use right endpoints and midpoints, respectively.\r\n\\item The left, right, and middle Riemann sums are denoted $L_n$, $R_n$, and $M_n$, with formulas\r\n$$L_n = f(x_0) \\triangle x + f(x_1) \\triangle x + \\cdots + f(x_{n-1}) \\triangle x = \\sum_{i = 0}^{n-1} f(x_i) \\triangle x,$$\r\n$$R_n = f(x_1) \\triangle x + f(x_2) \\triangle x + \\cdots + f(x_{n}) \\triangle x = \\sum_{i = 1}^{n} f(x_i) \\triangle x,$$\r\n$$M_n = f(\\overline{x}_1) \\triangle x + f(\\overline{x}_2) \\triangle x + \\cdots + f(\\overline{x}_{n}) \\triangle x = \\sum_{i = 1}^{n} f(\\overline{x}_i) \\triangle x,$$\r\nwhere $x_0 = a$, $x_i = a + i\\triangle x$, and $x_n = b$, using $\\triangle x = \\frac{b-a}{n}$.  For the midpoint sum, $\\overline{x}_{i} = (x_{i-1} + x_i)/2$.\r\n\\end{itemize}\r\n\r\n\\subsection{The Definite Integral}\r\n\r\nIn the previous examples it appears that as the number of rectangles got larger and larger, the values of $L_n$, $M_n$, and $R_n$ all grew closer and closer to the same value.  It turns out that this occurs for any continuous function on an interval $[a,b]$, and even more generally for a Riemann sum using any point $x_{i+1}^*$ in the interval $[x_i, x_{i+1}]$.  Said differently, as we let $n \\to \\infty$, it doesn't really matter where we choose to evaluate the function within a given subinterval, because\r\n$$\\lim_{n \\to \\infty} L_n = \\lim_{n \\to \\infty} R_n = \\lim_{n \\to \\infty} M_n = \\lim_{n \\to \\infty} \\sum_{i=1}^{n} f(x_i^*) \\triangle x.$$  \r\nThat these limits always exist (and share the same value) for a continuous\\footnote{It turns out that a function need not be continuous in order to have a definite integral.  For our purposes, we assume that the functions we consider are continuous on the interval(s) of interest.  It is straightforward to see that any function that is piecewise continuous on an interval of interest will also have a well-defined definite integral.} function $f$ allows us to make the following definition.\r\n\\begin{definition} \\label{D:4.3.DefInt}\r\nThe \\emph{definite integral} of a continuous function $f$ on the interval $[a,b]$, denoted $\\ds \\int_a^b f(x) \\, dx$, is the real number given by\r\n$$\\int_a^b f(x) \\, dx = \\lim_{n \\to \\infty} \\sum_{i=1}^{n} f(x_i^*) \\triangle x,$$\r\nwhere $\\triangle x = \\frac{b-a}{n}$, $x_i = a + i\\triangle x$ (for $i = 0, \\ldots, n$), and $x_i^*$ satisfies $x_{i-1} \\le x_i^* \\le x_i$ (for $i = 1, \\ldots, n$).\r\n\\end{definition}\r\nWe call the values $a$ and $b$ the \\emph{lower and upper limits of integration} respectively\\index{limits of integration}.  The process of determining the real number $\\int_a^b f(x) \\, dx$ is called \\emph{evaluating the definite integral}.  \r\n\r\n\\begin{example}{Finding definite integrals with Riemann sums}{ex_rie10}\r\n{\r\nFind  $\\ds \\int_{-1}^5 x^3\\ dx$ using the limit definition of the definite integral..\r\n}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n{As we may choose $ x_i^* $ freely in Definition \\ref{def:D:4.3.DefInt}, we will use the right hand rule, so \r\nwe have $\\Delta x = (b-a)/n= \\frac{5-(-1)}{n} = 6/n$, and $x_i = a+i\\Delta x = (-1) +  i \\Delta x$.\r\nThe Riemann sum corresponding to the Right Hand Rule is (followed by simplifications):\r\n\\begin{align*}\r\n\\int_{-1}^5 x^3\\ dx \t&\\approx \\sum_{i=1}^n f(x_{i+1})\\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^n f(-1+i\\Delta x)\\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^n (-1+i\\Delta x)^3\\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^n \\big((i\\Delta x)^3 -3(i\\Delta x)^2 + 3i\\Delta x -1\\big)\\Delta x \\quad \\text{\\scriptsize (now distribute $\\Delta x$)} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\sum_{i=1}^n \\big(i^3\\Delta x^4 - 3i^2\\Delta x^3 + 3i\\Delta x^2 -\\Delta x\\big) \\quad \\text{\\scriptsize (now split up summation)}\\\\\r\n%\\end{align*}\r\n%\\begin{align*}\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\Delta x^4 \\sum_{i=1}^ni^3 -3\\Delta x^3 \\sum_{i=1}^n i^2+ 3\\Delta x^2 \\sum_{i=1}^n i - \\sum_{i=1}^n \\Delta x \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\Delta x^4 \\left(\\frac{n(n+1)}{2}\\right)^2 -3\\Delta x^3 \\frac{n(n+1)(2n+1)}{6}+ 3\\Delta x^2 \\frac{n(n+1)}{2} - n\\Delta x \r\n\t\t\t\t\t\t\t\t\t\t\t\t\\intertext{\\scriptsize (use $\\Delta x = 6/n$)}\r\n\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1296}{n^4}\\cdot\\frac{n^2(n+1)^2}{4} - 3\\frac{216}{n^3}\\cdot\\frac{n(n+1)(2n+1)}{6} + 3\\frac{36}{n^2}\\frac{n(n+1)}2 -6\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t&= 324\\cdot\\left(\\frac{n+1}{n}\\right)^2-108\\cdot\\frac{n+1}{n}\\cdot\\frac{2n+1}{n}+54 \\cdot\\frac{n+1}{n}-6\\\\ \r\n\t\t\t\t\t\t\t\t\t\t\t&= 324\\cdot\\left(1+\\frac{1}{n}\\right)^2-108\\cdot\\left(1+\\frac{1}{n}\\right)\\cdot\\left(2+\\frac{1}{n}\\right)+54 \\cdot\\left(1+\\frac{1}{n}\\right)-6\\\\\r\n%\t\t\t\t\t\t\t\t\t\t\t&\\frac{1296}{n^4}\\cdot\\frac{n^2(n+1)^2}{4} - 3\\frac{216}{n^3}\\cdot\\frac{n(n+1)(2n+1)}{6} + 3\\frac{36}{n^2}\\frac{n(n+1)}2 -6\r\n%\t\t\t\t\t\t\t\t\t\t\t\\intertext{\\scriptsize (use $\\Delta x = 6/n$)}\r\n%\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1296}{n^4}\\cdot\\frac{n^2(n+1)^2}{4} - 3\\frac{216}{n^3}\\cdot\\frac{n(n+1)(2n+1)}{6} + 3\\frac{36}{n^2}\\frac{n(n+1)}2 -6\r\n%\t\t\t\t\t\t\t\t\t\t\t\\intertext{\\scriptsize (now do a sizable amount of algebra to simplify)}\r\n%\t\t\t\t\t\t\t\t\t\t\t&=156 + \\frac{378}n + \\frac{216}{n^2}\r\n\\end{align*}\r\n\r\nNow find the exact answer using a limit:\r\n$$\\int_{-1}^5 x^3\\ dx = \\lim_{n\\to\\infty} \\left(324\\cdot\\left(1+\\frac{1}{n}\\right)^2-108\\cdot\\left(1+\\frac{1}{n}\\right)\\cdot\\left(2+\\frac{1}{n}\\right)+54 \\cdot\\left(1+\\frac{1}{n}\\right)-6\\right) = 156.$$\r\n}\r\n\\end{solution}\r\n\r\n\r\nIf we wish to compute the value of a definite integral using the definition, we have to take the limit of a sum.  While this is possible to do in select circumstances, it is also tedious and time-consuming; moreover, computing these limits does not offer much additional insight into the meaning or interpretation of the definite integral.  Instead, in the next section, we will learn the Fundamental Theorem of Calculus, a result that provides a shortcut for evaluating a large class of definite integrals.  This will enable us to determine the exact net signed area bounded by a continuous function and the $x$-axis in many circumstances.\r\n\r\nWhile we will come to understand that there are several different interpretations of the value of the definite integral, for now the most important is that $\\int_a^b f(x) \\, dx$ measures the net signed area bounded by $y = f(x)$ and the $x$-axis on the interval $[a,b]$. \r\n\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_3_DefIntInterp}\r\n\\caption{A continuous function $f$ on the interval $[a,d]$.} \\label{F:4.3.DefIntInterp}\r\n\\end{center}\r\n\\end{figure}\r\nFor example, in the notation of the definite integral, if $f$ is the function pictured in Figure~\\ref{F:4.3.DefIntInterp} and $A_1$, $A_2$, and $A_3$ are the exact areas bounded by $f$ and the $x$-axis on the respective intervals $[a,b]$, $[b,c]$, and $[c,d]$, then\r\n$$\\int_a^b f(x) \\, dx = A_1, \\ \\int_b^c f(x) \\, dx = -A_2, \\ \\int_c^d f(x) \\, dx = A_3,$$\r\nand\r\n$$\\int_a^d f(x) \\, dx = A_1 - A_2 + A_3.$$\r\n\r\n\r\nIf a given curve produces regions whose areas we can compute exactly through known area formulas, we can thus compute the exact value of the integral.  Let's look at a few more examples.\r\n\r\n\r\n\r\n\\begin{example}{Finding definite integrals as signed areas}{ex_disa}\r\nEvaluate the following integrals by interpreting each in terms of signed areas:\r\n\\begin{enumerate}\r\n\\item $ \\ds \\int_{0}^{2} \\sqrt{4-x^2}\\; dx $\r\n\\item $ \\ds \\int_{0}^{3} 2-x\\; dx $\r\n\\item $ \\ds \\int_1^4 2x+2\\; dx $\r\n\\item $ \\ds \\int_{0}^{3} |2-x|\\; dx $\r\n\\end{enumerate}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n\\begin{enumerate}\r\n\\item Since $ f(x) =  \\sqrt{4-x^2}\\ge 0 $, the integral corresponds to the area under the curve $ y=f(x) $ between $ x=0 $ and $ x=2. $  Since $ y= \\sqrt{4-x^2} \\Rightarrow y^2=4-x^2\\Rightarrow x^2+y^2=4 $, the region we are interested in is that of a quarter circle with radius $ 2 $. So we have\r\n\r\n\\begin{minipage}[c]{.3\\textwidth}\r\n\\begin{tikzpicture}[scale=.6,/pgf/declare function={f=sqrt(4-x^2);}]\r\n\\begin{axis}[\r\n        xmin=-0.1,xmax=2.1,ymin=-0.1,ymax=2.1,\r\n    domain=0:2,\r\n    samples=100,\r\n    axis lines=middle\r\n]\r\n\\addplot [thick, red, ,name path=A] {f};\r\n \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [green] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\\begin{minipage}[c]{.5\\textwidth}\r\n\\begin{center}\r\n\\[\r\n\\int_{0}^{2} \\sqrt{4-x^2}\\; dx = \\frac14 \\pi (2)^2=\\pi.\r\n\\]\r\n\\end{center}\r\n\\end{minipage}\r\n\\item The region between the $ x $-axis and $ y=2-x $ over the interval $ [0,3] $ consists of two triangular regions of areas $ 2 $ and $ \\frac12 $. Since the second triangle is below the $ x $-axis, it has a signed area of $ -\\frac{1}{2} $. so we have \r\n\r\n\\begin{minipage}[c]{.3\\textwidth}\r\n\\begin{tikzpicture}[scale=.6,/pgf/declare function={f= 2-x;}]\r\n\\begin{axis}[\r\n        xmin=-1.1,xmax=3.1,ymin=-1.1,ymax=3.1,\r\n    domain=0:3,\r\n    samples=10,\r\n    axis lines=middle\r\n]\r\n\\addplot [thick, red, ,name path=A] {f};\r\n \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [green] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n  \\addplot [red] fill between[of = A and B,soft clip={domain=2:3}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\\begin{minipage}[c]{.5\\textwidth}\r\n\\begin{center}\r\n\\[\r\n\\int_{0}^{3} 2-x\\; dx = 2-\\frac12=\\frac32.\r\n\\]\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\\item Observe that the region bounded by this function and the $x$-axis is the trapezoid, and by the known formula for the area of a trapezoid, its area is $A = \\frac{1}{2}(3+9) \\cdot 3 = 18$, so\r\n\r\n\\begin{minipage}[c]{.3\\textwidth}\r\n\\begin{tikzpicture}[scale=.6,/pgf/declare function={f=2*x+1;}]\r\n\\begin{axis}[\r\n        xmin=-1.1,\r\n        xmax=4.3,\r\n        ymin=-1.1,\r\n        ymax=9.2,\r\n    domain=0:4,\r\n    samples=10,\r\n    axis lines=middle,\r\n    xtick={1,4},\r\n    ytick={3,9},\r\n]\r\n\\addplot [thick, red, ,name path=A] {f};\r\n \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [green] fill between[of = A and B,soft clip={domain=1:4}]; % filling\r\n  %\\addplot [red] fill between[of = A and B,soft clip={domain=2:3}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\\begin{minipage}[c]{.5\\textwidth}\r\n\\begin{center}\r\n$$\\int_1^4 (2x+1) \\, dx = 18.$$\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\r\n\\item The region between the $ x $-axis and $ y=|2-x| $ over the interval $ [0,3] $ consists of two triangular regions of areas $ 2 $ and $ \\frac12 $. Both are above the $ x $-axis, so have a positive signed area, and we have \r\n\r\n\\begin{minipage}[c]{.3\\textwidth}\r\n\\begin{tikzpicture}[scale=.6,/pgf/declare function={f=abs(2-x);}]\r\n\\begin{axis}[\r\n        xmin=-1.1,\r\n        xmax=3.1,\r\n        ymin=-1.1,\r\n        ymax=3.1,\r\n      domain=0:3,\r\n      samples=10,\r\n    axis lines=middle,\r\n     %xlabel=$t$,\r\n     % ylabel=$v$,\r\n     % xtick={-4,...,4},\r\n     % ytick={1,...,5},\r\n    ]\r\n\\addplot [thick, red, ,name path=A] {f};\r\n \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [green] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n  \\addplot [green] fill between[of = A and B,soft clip={domain=2:3}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n\\begin{minipage}[c]{.5\\textwidth}\r\n\\begin{center}\r\n\\[\r\n\\int_{0}^{3} 2-x\\; dx = 2+\\frac12=\\frac52.\r\n\\]\r\n\\end{center}\r\n\\end{minipage}\r\n\r\n\r\n\\end{enumerate}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\nWe can also use definite integrals to express the change in position and distance traveled by a moving object.  In the setting of a velocity function $v$ on an interval $[a,b]$, it follows from our work above and in preceding sections that the change in position, $s(b) - s(a)$, is given by\r\n$$s(b) - s(a) = \\int_a^b v(t) \\, dt.$$\r\nIf the velocity function is nonnegative on $[a,b]$, then $\\int_a^b v(t) \\,dt$ tells us the distance the object travelled.  When velocity is sometimes negative on $[a,b],$ the areas bounded by the function on intervals where $v$ does not change sign can be found using integrals, and the sum of these values will tell us the distance the object travelled. \r\n\r\n\\begin{example}{Understanding motion given velocity}{ex_defint6}\r\n{\r\nConsider the graph of a velocity function of an object moving in a straight line, given in Figure \\ref{fig:defint6}, where the numbers in the given regions gives the area of that region.  Find the maximum speed of the object and its maximum displacement from its starting position.\r\n}\r\n\\end{example}\r\n\\begin{center}\r\n\\begin{figure}\r\n\\begin{tikzpicture}[scale=.9]\r\n\\begin{axis}[ %width=\\marginparwidth+25pt,%\r\n            %tick label style={font=\\scriptsize},\r\n            axis y line=middle,\r\n            axis x line=middle,\r\n            name=myplot,\r\n            axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={2,6,8},\r\n\t\t\textra x tick labels={$\\ a$,$b\\ $,$\\ c$},\r\n\t\t\tytick={-5,5,10,15},\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=-9,ymax=17,%\r\n\t\t\txmin=-.5,xmax=8.5%\r\n]\r\n\r\n\\addplot [smooth,red,fill={green},area style,domain=0:8] {15/64*x*(x-2)*(x-6)*(x-8)} \\closedcycle;\r\n\\addplot [smooth,thick,red,domain=0:8] {15/64*x*(x-2)*(x-6)*(x-8)};\r\n\r\n\\draw (axis cs:.9,-4) node { $11$};\r\n\\draw (axis cs:7.1,-4) node { $11$};\r\n\\draw (axis cs:4,8) node { $38$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $t$ (s)};\r\n\\node [above] at (myplot.above origin) { $y$ (m/s)};\r\n\\end{tikzpicture}\r\n\\caption{A graph of a velocity in Example \\ref{exa:ex_defint6}.\\label{fig:defint6}}\r\n\\end{figure}\r\n\\end{center}\r\n\r\n\\begin{solution}\r\nSince the graph gives velocity, finding the maximum speed is simple: it looks to be $ 15 $m/s.\r\n\r\nAt time $t=0$, the displacement is $ 0 $; the object is at its starting position. At time $t=a$, the object has moved backward $ 11 $ meters. Between times $t=a$ and $t=b$, the object moves forward $ 38 $ meters, bringing it into a position $ 27 $ meters forward of its starting position. From $t=b$ to $t=c$ the object is moving backwards again, hence its total displacement is $ 27 $ meters from its starting position.\r\n\\[\r\n\\text{Total Displacement} = \\int_0^c v(t)\\;dt = -11+38-11=16m.\r\n\\]\r\n\\[\r\n\\text{Maximum Displacement} = \\int_0^b v(t)\\;dt = -11+38=27m.\r\n\\]\r\n\\end{solution}\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\\subsection*{Some properties of the definite integral}\r\n\r\nWith the perspective that the definite integral of a function $f$ over an interval $[a,b]$ measures the net signed area bounded by $f$ and the $x$-axis over the interval, we naturally arrive at several different standard properties of the definite integral.  In addition, it is helpful to remember that the definite integral is defined in terms of Riemann sums that fundamentally consist of the areas of rectangles.\r\n\r\nIf we consider the definite integral $\\int_a^a f(x) \\, dx$ for any real number $a$, it is evident that no area is being bounded because the interval begins and ends with the same point.  Hence, \r\n\r\n\\vspace*{5pt}\r\n\\noindent \\framebox{\\hspace*{3 pt}\r\n\\parbox{6.25 in}{\r\nIf $f$ is a continuous function and $a$ is a real number, then $\\ds \\int_a^a f(x) \\,dx = 0.$\r\n} \\hspace*{3 pt}}\r\n\\vspace*{1pt}\r\n \r\n\r\nNext, we consider the results of subdividing a given interval. In Figure~\\ref{F:4.3.AdditiveProp}, we see that\r\n$$\\int_a^b f(x) \\, dx = A_1, \\ \\int_b^c f(x) \\, dx = A_2, \\ \\mbox{and} \\ \\int_a^c f(x) \\, dx = A_1 + A_2,$$ \r\nwhich is indicative of the following general rule.\r\n  \r\n\\begin{figure}[h]\r\n\\begin{center}\r\n%\\includegraphics{figures/4_3_AdditiveProp}\r\n\\begin{tikzpicture}[/pgf/declare function={f=-x^3+5*(x^2)-3*x-3;}]\r\n  \\begin{axis}[\r\n    axis y line = left,\r\n    axis x line = bottom,\r\n    xtick       = {-1.2,2,4.2},\r\n    xticklabels = {$a$,$b$,$c$},\r\n     ytick       = {},\r\n    yticklabels = {},\r\n    samples     = 160,\r\n    domain      = -1.2:4.2,\r\n    xmin = -2, xmax = 5,\r\n    ymin = -5, ymax = 10,\r\n  ]\r\n  \\addplot[name path=poly, black, thick, mark=none, ] {f};\r\n   \\addplot [draw=none,name path=B] {-5};     % “fictional” curve\r\n%  \\addplot[name path=line, gray, no markers, line width=1pt] {3};\r\n \\addplot [green!60] fill between[of = poly and B,soft clip={domain=-1.2:2}]; % filling\r\n  \\addplot [red!60] fill between[of = poly and B,soft clip={domain=2:4.2}]; % filling\r\n  ];\r\n  %% Choosing the coordinates manually is annoying:\r\n  \\node at (axis cs:-.7,-2.3) {$A_1$};\r\n  \\node at (axis cs:3,-0.3) {$A_2$};\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\r\n\\caption{The area bounded by $y=f(x)$ on the interval $[a,c]$.} \\label{F:4.3.AdditiveProp}\r\n\\end{center}\r\n\\end{figure}\r\n  \r\n  \r\n\\vspace*{5pt}\r\n\\noindent \\framebox{\\hspace*{3 pt}\r\n\\parbox{6.25 in}{\r\nIf $f$ is a continuous function and $a$, $b$, and $c$ are real numbers, then $$\\ds \\int_a^c f(x) \\,dx = \\int_a^b f(x) \\,dx + \\int_b^c f(x) \\,dx.$$\r\n} \\hspace*{3 pt}}\r\n\\vspace*{1pt}\r\n\r\n\\noindent While this rule is most apparent in the situation where $a < b < c$, it in fact holds in general for any values of $a$, $b$, and $c$.  This result is connected to another property of the definite integral, which states that if we reverse the order of the limits of integration, we change the sign of the integral's value.\r\n\r\n\\vspace*{5pt}\r\n\\noindent \\framebox{\\hspace*{3 pt}\r\n\\parbox{6.25 in}{\r\nIf $f$ is a continuous function and $a$ and $b$ are real numbers, then $\\ds \\int_b^a f(x) \\,dx = -\\int_a^b f(x) \\,dx.$\r\n} \\hspace*{3 pt}}\r\n\\vspace*{1pt}\r\n\r\n\\noindent This result makes sense because if we integrate from $a$ to $b$, then in the defining Riemann sum $\\triangle x = \\frac{b-a}{n}$, while if we integrate from $b$ to $a$, $\\triangle x = \\frac{a-b}{n} = -\\frac{b-a}{n}$, and this is the only change in the sum used to define the integral.\r\n\r\nThere are two additional properties of the definite integral that we need to understand.  Recall that when we worked with derivative rules in Chapter~\\ref{C:2}, we found that both the Constant Multiple Rule and the Sum Rule held.  The Constant Multiple Rule tells us that if $f$ is a differentiable function and $k$ is a constant, then\r\n$$\\frac{d}{dx} [kf(x)] = kf'(x),$$\r\nand the Sum Rule states that if $f$ and $g$ are differentiable functions, then\r\n$$\\frac{d}{dx}[f(x) + g(x)] = f'(x) + g'(x).$$\r\nThese rules are useful because they enable us to deal individually with the simplest parts of certain functions and take advantage of the elementary operations of addition and multiplying by a constant.  They also tell us that the process of taking the derivative respects addition and multiplying by constants in the simplest possible way.  \r\n\r\nIt turns out that similar rules hold for the definite integral.  First, let's consider the situation pictured in Figure~\\ref{F:4.3.ConstMult},\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_3_ConstMult}\r\n\\caption{The areas bounded by $y = f(x)$ and $y = 2f(x)$ on $[a,b]$.\\label{F:4.3.ConstMult}} \r\n\\end{center}\r\n\\end{figure}\r\nwhere we examine the effect of multiplying a function by a factor of 2 on the area it bounds with the $x$-axis.  Because multiplying the function by 2 doubles its height at every $x$-value, we see that if we consider a typical rectangle from a Riemann sum, the difference in area comes from the changed height of the rectangle:  $f(x_i)$ for the original function, versus $2f(x_i)$ in the doubled function, in the case of left sum.  Hence, in Figure~\\ref{F:4.3.ConstMult}, we see that for the pictured rectangles with areas $A$ and $B$, it follows $B = 2A$.  As this will happen in every such rectangle, regardless of the value of $n$ and the type of sum we use, we see that in the limit, the area of the red region bounded by $y = 2f(x)$ will be twice that of the area of the blue region bounded by $y = f(x)$.  As there is nothing special about the value $2$ compared to an arbitrary constant $k$, it turns out that the following general principle holds.\r\n\r\n\\vspace*{5pt}\r\n\\noindent \\framebox{\\hspace*{3 pt}\r\n\\parbox{6.25 in}{\r\n{\\bf Constant Multiple Rule:}\\index{definite integral!constant multiple rule} If $f$ is a continuous function and $k$ is any real number then $$\\ds \\int_a^b k \\cdot f(x) \\,dx = k \\int_a^b f(x) \\,dx.$$\r\n} \\hspace*{3 pt}}\r\n\\vspace*{1pt}\r\n\r\nFinally, we see a similar situation geometrically with the sum of two functions $f$ and $g$.\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_3_Sum}\r\n\\caption{The areas bounded by $y = f(x)$ and $y = g(x)$ on $[a,b]$, as well as the area bounded by $y = f(x) + g(x)$.} \\label{F:4.3.Sum}\r\n\\end{center}\r\n\\end{figure}\r\nIn particular, as shown in Figure~\\ref{F:4.3.Sum}, if we take the sum of two functions $f$ and $g$, at every point in the interval, the height of the function $f+g$ is given by $(f+g)(x_i) = f(x_i) + g(x_i)$, which is the sum of the individual function values of $f$ and $g$ (taken at left endpoints).  Hence, for the pictured rectangles with areas $A$, $B$, and $C$, it follows that $C = A + B$, and because this will occur for every such rectangle, in the limit the area of the gray region will be the sum of the areas of the blue and red regions.  Stated in terms of definite integrals, we have the following general rule.\r\n\r\n\\vspace*{5pt}\r\n\\noindent \\framebox{\\hspace*{3 pt}\r\n\\parbox{6.25 in}{\r\n{\\bf Sum Rule:}\\index{definite integral!sum rule} If $f$ and $g$ are continuous functions, then $$\\ds \\int_a^b [f(x) + g(x)] \\,dx = \\int_a^b f(x) \\,dx + \\int_a^b g(x) \\,dx.$$\r\n} \\hspace*{3 pt}}\r\n\\vspace*{1pt}\r\n\r\nMore generally, the Constant Multiple and Sum Rules can be combined to make the observation that for any continuous functions $f$ and $g$ and any constants $c$ and $k$,\r\n$$\\ds \\int_a^b [c f(x) \\pm k g(x)] \\,dx = c \\int_a^b f(x) \\,dx \\pm k \\int_a^b g(x) \\,dx.$$\r\n\r\nIn summary we have the following:\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\n\r\n%\\subsection{How the definite integral is connected to a function's average value} \\index{average value of a function}\r\n%\r\n%One of the most valuable applications of the definite integral is that it provides a way to meaningfully discuss the average value of a function, even for a function that takes on infinitely many values.  Recall that if we wish to take the average of $n$ numbers $y_1$, $y_2$, $\\ldots$, $y_n$, we do so by computing\r\n%$$\\mbox{Avg} = \\frac{y_1 + y_2 + \\cdots + y_n}{n}.$$\r\n%\r\n%Since integrals arise from Riemann sums in which we add $n$ values of a function, it should not be surprising that evaluating an integral is something like averaging the output values of a function.  Consider, for instance, the right Riemann sum $R_n$ of a function $f$, which is given by\r\n%$$R_n = f(x_1) \\triangle x + f(x_2) \\triangle x + \\cdots + f(x_n) \\triangle x = (f(x_1) + f(x_2) + \\cdots + f(x_n))\\triangle x.$$\r\n%Since $\\triangle x = \\frac{b-a}{n}$, we can thus write \r\n%\\begin{equation} \\label{E:RAvg}\r\n%R_n = (f(x_1) + f(x_2) + \\cdots + f(x_n))\\cdot \\frac{b-a}{n} = (b-a) \\frac{f(x_1) + f(x_2) + \\cdots + f(x_n)}{n}.\r\n%\\end{equation}\r\n%Here, we see that the right Riemann sum with $n$ subintervals is the length of the interval $(b-a)$ times the average of the $n$ function values found at the right endpoints.  And just as with our efforts to compute area, we see that the larger the value of $n$ we use, the more accurate our average of the values of $f$ will be.  Indeed, we will define the average value of $f$ on $[a,b]$ to be \r\n%$$f_{\\mbox{\\tiny{AVG}}[a,b]} = \\lim_{n \\to \\infty} \\frac{f(x_1) + f(x_2) + \\cdots + f(x_n)}{n}.$$  But we also know that for any continuous function $f$ on $[a,b]$, taking the limit of a Riemann sum leads precisely to the definite integral.  That is, $\\ds \\lim_{n \\to \\infty} R_n = \\int_a^b f(x) \\, dx$, and thus taking the limit as $n \\to \\infty$ in Equation~(\\ref{E:RAvg}), we have that\r\n%\\begin{equation} \\label{E:RAvg2}\r\n%\\int_a^b f(x) \\, dx = (b-a) \\cdot f_{\\mbox{\\tiny{AVG}}[a,b]}.\r\n%\\end{equation}\r\n%Solving Equation~(\\ref{E:RAvg2}) for $f_{\\mbox{\\tiny{AVG}}[a,b]}$, we have the following general principle.\r\n%\r\n%\\begin{definition}{The Average Value of a Function}{avg_value}\r\n%If $f$ is a continuous function on $[a,b]$, then its average value on $[a,b]$ is given by the formula\r\n%$$f_{\\mbox{\\tiny{AVG}}[a,b]} = \\frac{1}{b-a} \\cdot \\int_a^b f(x) \\, dx.$$\r\n%\\end{definition}\r\n%\r\n%Observe that Equation~(\\ref{E:RAvg2}) tells us another way to interpret the definite integral:  the definite integral of a function $f$ from $a$ to $b$ is the length of the interval $(b-a)$ times the average value of the function on the interval.  In addition, Equation~(\\ref{E:RAvg2}) has a natural visual interpretation when the function $f$ is nonnegative on $[a,b]$.  \r\n%\\begin{figure}[h]\r\n%\\begin{center}\r\n%\\includegraphics{figures/4_3_AvgVal}\r\n%\\caption{A function $y = f(x)$, the area it bounds, and its average value on $[a,b]$.} \\label{F:4.3.AvgVal}\r\n%\\end{center}\r\n%\\end{figure}\r\n%Consider Figure~\\ref{F:4.3.AvgVal}, where we see at left the shaded region whose area is $\\int_a^b f(x) \\, dx$, at center the shaded rectangle whose dimensions are $(b-a)$ by $f_{\\mbox{\\tiny{AVG}}[a,b]}$, and at right these two figures superimposed.  Specifically, note that in dark green we show the horizontal line $y = f_{\\mbox{\\tiny{AVG}}[a,b]}$.  Thus, the area of the green rectangle is given by $(b-a) \\cdot f_{\\mbox{\\tiny{AVG}}[a,b]}$, which is precisely the value of $\\int_a^b f(x) \\, dx$.  Said differently, the area of the blue region in the left figure is the same as that of the green rectangle in the center figure; this can also be seen by observing that the areas $A_1$ and $A_2$ in the rightmost figure appear to be equal.  Ultimately, the average value of a function enables us to construct a rectangle whose area is the same as the value of the definite integral of the function on the interval.  The java applet\\footnote{David Austin, \\href{http://gvsu.edu/s/5r}{\\texttt{http://gvsu.edu/s/5r}}.} at \\href{http://gvsu.edu/s/az}{\\texttt{http://gvsu.edu/s/az}} provides an opportunity to explore how the average value of the function changes as the interval changes, through an image similar to that found in Figure~\\ref{F:4.3.AvgVal}.\r\n\r\n\r\n\r\n\r\nSummary\r\n\r\n\\begin{itemize}\r\n\\item Any Riemann sum of a continuous function $f$ on an interval $[a,b]$ provides an estimate of the net signed area bounded by the function and the horizontal axis on the interval.  Increasing the number of subintervals in the Riemann sum improves the accuracy of this estimate, and letting the number of subintervals increase without bound results in the values of the corresponding Riemann sums approaching the exact value of the enclosed net signed area.\r\n\\item When we take the just described limit of Riemann sums, we arrive at what we call the definite integral of $f$ over the interval $[a,b]$.  In particular, the symbol $\\int_a^b f(x) \\, dx$ denotes the definite integral of $f$ over $[a,b]$, and this quantity is defined by the equation\r\n$$\\int_a^b f(x) \\, dx = \\lim_{n \\to \\infty} \\sum_{i=1}^{n} f(x_i^*) \\triangle x,$$\r\nwhere $\\triangle x = \\frac{b-a}{n}$, $x_i = a + i\\triangle x$ (for $i = 0, \\ldots, n$), and $x_i^*$ satisfies $x_{i-1} \\le x_i^* \\le x_i$ (for $i = 1, \\ldots, n$).\r\n\\item The definite integral $\\int_a^b f(x) \\,dx$ measures the exact net signed area bounded by $f$ and the horizontal axis on $[a,b]$.%in addition, the value of the definite integral is related to what we call the average value of the function on $[a,b]$: $f_{\\mbox{\\tiny{AVG}}[a,b]} = \\frac{1}{b-a} \\cdot \\int_a^b f(x) \\, dx.$  \r\nIn the setting where we consider the integral of a velocity function $v$, $\\int_a^b v(t) \\,dt$ measures the displacement of the moving object on $[a,b]$; when $v$ is nonnegative, $\\int_a^b v(t) \\,dt$ is the object's distance traveled on $[a,b]$.  \r\n\\item The definite integral is a sophisticated sum, and thus has some of the same natural properties that finite sums have.  Perhaps most important of these is how the definite integral respects sums and constant multiples of functions, which can be summarized by the rule\r\n$$\\ds \\int_a^b [c f(x) \\pm k g(x)] \\,dx = c \\int_a^b f(x) \\,dx \\pm k \\int_a^b g(x) \\,dx$$\r\nwhere $f$ and $g$ are continuous functions on $[a,b]$ and $c$ and $k$ are arbitrary constants.\r\n\\end{itemize}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:AreaProb}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Suppose an object moves in a straight line so that its speed at\r\ntime $t$ is given by $v(t)=2t+2$, and that at $t=1$ the object is at\r\nposition 5. Find the position of the object at $t=2$.\r\n\\begin{sol}\r\n 10\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Suppose an object moves in a straight line so that its speed at\r\ntime $t$ is given by $\\ds v(t)=t^2+2$, and that at $t=0$ the object is at\r\nposition 5. Find the position of the object at $t=2$.\r\n\\begin{sol}\r\n $35/3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n  Find the area under $y=2x$ between $x=0$ and any\r\n  positive value for $x$.\r\n\\begin{sol}\r\n $\\ds x^2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n  Find the area under $y=4x$ between $x=0$ and any\r\n  positive value for $x$.\r\n\\begin{sol}\r\n $\\ds 2x^2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n  Find the area under $y=4x$ between $x=2$ and any\r\n  positive value for $x$ bigger than 2.\r\n\\begin{sol}\r\n $\\ds 2x^2-8$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n  Find the area under $y=4x$ between any two positive\r\n  values for $x$, say $a<b$.\r\n\\begin{sol}\r\n $\\ds 2b^2-2a^2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $\\ds f(x)=x^2+3x+2$. Approximate the area under the curve\r\nbetween $x=0$ and $x=2$ using 4 rectangles and also using 8\r\nrectangles. \r\n\\begin{sol}\r\n 4 rectangles: $41/4=10.25$, \r\n8 rectangles: $183/16= 11.4375$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Let $\\ds f(x)=x^2-2x+3$. Approximate the area under the curve\r\nbetween $x=1$ and $x=3$ using 4 rectangles. \r\n\\begin{sol}\r\n $ 23/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "80bdab9b94229dd4c7e0de9c3844b7b519155d61", "size": 80456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6-integration/6-1-area-prob.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-1-area-prob.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-1-area-prob.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.4382901866, "max_line_length": 1254, "alphanum_fraction": 0.6563836134, "num_tokens": 27328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494678483918, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.6064062811578018}}
{"text": "\\documentclass[11pt,letter]{article}\n\n\\usepackage{latexsym, color, graphicx, comment}\n\\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{hyperref}\n\\usepackage{empheq}\n\\hypersetup{colorlinks=true,linkcolor=blue}\n\n\\newcommand{\\vect}[1]{\\mbox{\\boldmath $#1$}}\n\\newcommand{\\gyrophase}{\\varphi}\n\\newcommand{\\energy}{\\varepsilon}\n\\renewcommand{\\Re}{\\mathrm{Re}}\n\\renewcommand{\\Im}{\\mathrm{Im}}\n\\newcommand{\\todo}[1]{\\textcolor{red}{#1}}\n%\\newcommand{\\kxfac}{\\kappa_x}\n\\newcommand{\\kxfac}{\\mathtt{kxfac}}\n\\newcommand{\\bmag}{\\mathtt{bmag}}\n\\newcommand{\\smz}{\\mathtt{smz}}\n\\newcommand{\\gdstwo}{\\mathtt{gds2}}\n\\newcommand{\\gdstwoone}{\\mathtt{gds21}}\n\\newcommand{\\gdstwotwo}{\\mathtt{gds22}}\n\\newcommand{\\gbdrift}{\\mathtt{gbdrift}}\n\\newcommand{\\gbdriftO}{\\mathtt{gbdrift0}}\n\\newcommand{\\cvdrift}{\\mathtt{cvdrift}}\n\\newcommand{\\cvdriftO}{\\mathtt{cvdrift0}}\n\\newcommand{\\fprim}{\\mathtt{fprim}}\n\\newcommand{\\tprim}{\\mathtt{tprim}}\n\\newcommand{\\gradpar}{\\mathtt{gradpar}}\n\\newcommand{\\delthet}{\\mathtt{delthet}}\n\\newcommand{\\codedt}{\\mathtt{code\\_dt}}\n\\newcommand{\\stellopt}{{\\ttfamily stellopt}}\n\\newcommand{\\vboot}{{\\ttfamily vboot}}\n\\newcommand{\\vmec}{{\\ttfamily vmec}}\n\\newcommand{\\bootsj}{{\\ttfamily bootsj}}\n\\newcommand{\\sfincs}{{\\ttfamily sfincs}}\n\\newcommand{\\curtor}{{\\ttfamily curtor}}\n\\newcommand{\\ac}{{\\ttfamily ac}}\n\n\n\\title{Computing \\vmec's \\ac~current profile and \\curtor~from a bootstrap current code}\n\\author{Matt Landreman}\n\\date{March 1, 2018}\n\n\\begin{document}\n\\maketitle\n\nIn this note, we detail how to compute the \\vmec~input parameters \\curtor~and \\ac~(or {\\ttfamily ac\\_aux\\_f})\nfrom the averaged parallel current computed by neoclassical codes, $\\langle \\vect{j}\\cdot\\vect{B} \\rangle$. Here,\n$\\langle \\ldots \\rangle$ denotes a flux surface average,  $\\vect{j}$ is the current density, and $\\vect{B}$ is the magnetic field. \nThe proper result involves a term that is neglected by the \\bootsj~code. This term is small\nin $\\beta = 2 \\mu_0 p / B^2$, but it does not require much work to keep, so we may as well keep it.\nPhysically, neoclassical codes compute a gyrophase-averaged distribution function and so the current they obtain\nis parallel to $\\vect{B}$, whereas the total toroidal current also has a contribution from the diamagnetic\ncurrent perpendicular to $\\vect{B}$. The purpose of this note is to compute the proper relationship between these \nparallel and perpendicular currents and the net toroidal current.\n\n\nThe calculation here is a more detailed version of Appendix C of \\cite{LandremanCatto},\nexcept that Gaussian units were used in that paper whereas\nSI units are used throughout this note. \n\n\n\\section{Overview}\nBootstrap current codes like \\bootsj~and \\sfincs~solve the drift kinetic equation\nfor the gyrophase-averaged distribution function $f$. The parallel velocity moment of $f$, weighted by species charge and summed over\nspecies, yields the parallel current $j_{||} = \\vect{j}\\cdot\\vect{b}$, where $\\vect{b} = \\vect{B} / |\\vect{B}|$.\nThe spatial variation of $j_{||}$ over a magnetic surface can be determined analytically for any geometry and collisionality using mass conservation, so the results of a drift-kinetic calculation can be summarized by any weighted average of the parallel current over a flux surface. By convention, the average typically\nreported is $\\langle \\vect{j}\\cdot\\vect{B}\\rangle$.\n\nThe \\vmec~code takes as an input the profile of net toroidal current inside a flux surface.\nTherefore, to interface a bootstrap current code with \\vmec, the relationship between this\nnet toroidal current and the parallel current must be calculated. We now calculate this relationship.\n\n\\section{Derivation}\n\nLet $I(s)$ denote the total toroidal current inside a flux surface labelled by any flux function $s$,\nwhere we require that $s=0$ on the magnetic axis.\nThis total current is the flux (area integral) of the current density $\\vect{j}$ through a surface of constant toroidal angle $\\zeta$:\n\\begin{equation}\nI(s) = \\int d^2\\vect{a} \\cdot \\vect{j}\n=\\int_0^{s} ds' \\int_0^{2\\pi}d\\theta \\sqrt{g} \\vect{j}\\cdot\\nabla\\zeta,\n\\label{eq:I_definition}\n\\end{equation}\nwhere $\\theta$ is a poloidal angle, the integrand is evaluated at $s'$ rather than $s$, and\n\\begin{equation}\n\\sqrt{g} = \\frac{\\partial \\vect{r}}{\\partial s} \\cdot \\frac{\\partial\\vect{r}}{\\partial\\theta} \\times \\frac{\\partial\\vect{r}}{\\partial\\zeta}\n= \\frac{1} {\\nabla s \\cdot \\nabla\\theta\\times\\nabla\\zeta}\n\\end{equation}\nis the Jacobian of the $(s,\\theta,\\zeta)$ coordinates. \nIt turns out to be convenient to write (\\ref{eq:I_definition}) in differential rather than integral form, by applying $d/ds$:\n\\begin{equation}\n\\frac{dI}{ds}\n= \\int_0^{2\\pi}d\\theta \\sqrt{g} \\vect{j}\\cdot\\nabla\\zeta.\n\\label{eq:I_differential}\n\\end{equation}\nThese expressions so far are all valid for any angle coordinates $(\\theta,\\zeta)$ (\\vmec, Boozer, {\\ttfamily pest}, Hamada, etc.)\n\nNext, consider that to leading order in $\\rho/L \\ll 1$, where $\\rho$ is a typical gyroradius and $L$ is a typical equilibrium scale length,\nthe current perpendicular to $\\vect{B}$ is given by the diamagnetic current:\n\\begin{equation}\n\\vect{j}_\\perp = \\frac{1}{B^2} \\frac{dp}{ds} \\vect{B}\\times\\nabla s,\n\\end{equation}\nwhere $p(s)$ is the total pressure.\nThis result can be obtained, for example, by applying $\\vect{B}\\times(\\ldots)$ to the MHD equilibrium relation \n$\\vect{j}\\times\\vect{B} = \\nabla p$. Therefore the total current vector is\n\\begin{equation}\n\\vect{j} = \\frac{j_{||}}{B} \\vect{B} +  \\frac{1}{B^2} \\frac{dp}{ds} \\vect{B}\\times\\nabla s.\n\\end{equation}\nSubstituting this result into (\\ref{eq:I_differential}),\n\\begin{equation}\n\\frac{dI}{ds}=\n\\int_0^{2\\pi}d\\theta \\sqrt{g} \n\\left[\n\\frac{j_{||}}{B} \\vect{B} \\cdot\\nabla\\zeta +  \\frac{B_\\theta}{B^2} \\frac{dp}{ds} \\nabla\\theta \\times\\nabla s\\cdot\\nabla\\zeta\n\\right],\n\\label{eq:I2}\n\\end{equation}\nwhere to get the last term we have expressed $\\vect{B}$ in components\n\\begin{equation}\n\\vect{B} = B_s \\nabla s + B_\\theta \\nabla \\theta + B_\\zeta \\nabla\\zeta.\n\\label{eq:B_components}\n\\end{equation}\nThe important message from (\\ref{eq:I2}) is that the total toroidal current $I$ needed for \\vmec~consists\n not only of the parallel current determined by neoclassical physics (the first right-hand-side term), but\nalso by the diamagnetic current $\\propto dp/ds$ in the last term.\n\nWhile the calculation so far is true for any angle coordinates $(\\theta,\\zeta)$,\nfor the rest of this section it is convenient to use Boozer coordinates.\nThe main result will turn out to be independent of the choice of angle coordinates.\nIn any straight-field-line coordinates such as Boozer coordinates, the magnetic field can be written as\n\\begin{equation}\n\\vect{B} = \\frac{d\\psi}{ds} \\left[ \\nabla s \\times\\nabla \\theta + \\iota \\nabla \\zeta\\times\\nabla s\\right],\n\\label{eq:straight_field_lines}\n\\end{equation}\nwhere $2\\pi\\psi$ is the toroidal flux enclosed by surface $s$, and $\\iota(s)$ is the rotational transform. Hence, the geometric factor appearing\nin the first right-hand-side term of (\\ref{eq:I2}) is\n\\begin{equation}\n\\vect{B}\\cdot\\nabla\\zeta =  \\frac{d\\psi}{ds}  \\nabla s \\times\\nabla \\theta \\cdot\\nabla\\zeta = \\frac{d\\psi}{ds} \\frac{1}{\\sqrt{g}},\n\\end{equation}\nand so (\\ref{eq:I2}) reduces to\n\\begin{equation}\n\\frac{dI}{ds} =\n \\int_0^{2\\pi}d\\theta \n\\left[\n\\frac{d\\psi}{ds}\n\\frac{j_{||}}{B}  -  \\frac{B_\\theta}{B^2} \\frac{dp}{ds} \n\\right].\n\\label{eq:I3}\n\\end{equation}\n\nFurthermore, in Boozer coordinates, $B_\\theta$ and $B_\\zeta$ in (\\ref{eq:B_components})\nare flux functions, i.e. they depend only on $s$,\nand we can show that $B_\\theta$ is related to $I(s)$ as follows.\nThe curl of (\\ref{eq:B_components}) is\n\\begin{equation}\n\\nabla\\times\\vect{B} =\\nabla B_s \\times \\nabla s + \\frac{d B_\\theta}{ds} \\nabla s \\times \\nabla \\theta + \\frac{d B_\\zeta}{ds} \\nabla s \\times \\nabla\\zeta.\n\\end{equation}\nSubstituting this expression into Ampere's Law $\\mu_0 \\vect{j} = \\nabla\\times\\vect{B}$,\nand using the result to eliminate $\\vect{j}$ in \n(\\ref{eq:I_definition}),\n\\begin{align}\n\\mu_0 I(s) &= \\int_0^{s} ds' \\int_0^{2\\pi}d\\theta \\sqrt{g} \n\\left[ \n\\frac{\\partial B_s}{\\partial\\theta}\n\\nabla \\theta \\times \\nabla s \\cdot\\nabla\\zeta + \\frac{d B_\\theta}{ds} \\nabla s \\times \\nabla \\theta \\cdot\\nabla\\zeta\n\\right] \\\\\n&= \\int_0^{s} ds' \\int_0^{2\\pi}d\\theta \n\\left[ -\n\\frac{\\partial B_s}{\\partial\\theta}\n+ \\frac{d B_\\theta}{ds} \n\\right] = \\int_0^{s} ds' \\int_0^{2\\pi}d\\theta \n \\frac{d B_\\theta}{ds}  \\nonumber \\\\\n &=2\\pi [ B_\\theta(s) - B_\\theta(0) ]. \\nonumber\n\\end{align}\nAt the magnetic axis ($s=0$), $B_\\theta$ must vanish, since in (\\ref{eq:B_components}) it multiplies $\\nabla\\theta$ which diverges on axis, and the product\nmust be regular. Hence,\n\\begin{equation}\nB_\\theta (s) = \\frac{\\mu_0 I(s)}{2\\pi}.\n\\end{equation}\nUsing this result in (\\ref{eq:I3}), and applying a toroidal average $(2\\pi)^{-1} \\int_0^{2\\pi} d\\zeta (\\ldots)$,\n\\begin{equation}\n \\frac{dI}{ds} =\n \\frac{1}{2\\pi}\n\\frac{d\\psi}{ds}\n\\int_0^{2\\pi}d\\theta  \\int_0^{2\\pi} d\\zeta \\frac{j_{||}}{B}\n-\n\\frac{\\mu_0 I}{4\\pi^2}\n\\frac{dp}{ds} \n\\int_0^{2\\pi}d\\theta  \\int_0^{2\\pi} d\\zeta\n \\frac{1}{B^2} .\n\\label{eq:I4}\n\\end{equation}\n\nThe angular averages in this last expression can be written in terms of the flux surface average, which for any quantity $Q$\nis\n\\begin{equation}\n\\langle Q \\rangle\n= \\frac{ \\int_0^{2\\pi}d\\theta \\int_0^{2\\pi} d\\zeta \\sqrt{g} Q}{ \\int_0^{2\\pi}d\\theta \\int_0^{2\\pi} d\\zeta \\sqrt{g}}\n=\\frac{ \\int_0^{2\\pi}d\\theta \\int_0^{2\\pi} d\\zeta \\sqrt{g} (Q/B^2)}{ \\int_0^{2\\pi}d\\theta \\int_0^{2\\pi} d\\zeta /B^2}.\n\\label{eq:FSA}\n\\end{equation}\nIn the last equation, we have used the fact that the Jacobian in Boozer coordinates is $\\sqrt{g} = (d\\psi / ds) (B_\\zeta + \\iota B_\\theta) / B^2$,\nwhich follows from the product of (\\ref{eq:B_components}) and (\\ref{eq:straight_field_lines}).\nFrom (\\ref{eq:FSA}) we see that\n\\begin{equation}\n\\langle B^2 \\rangle = \\frac{ 4 \\pi^2}{ \\int_0^{2\\pi}d\\theta \\int_0^{2\\pi} d\\zeta /B^2}.\n\\label{eq:FSAB2}\n\\end{equation}\nUsing (\\ref{eq:FSA})-(\\ref{eq:FSAB2}), (\\ref{eq:I4}) can be written\n\\begin{equation}\n\\boxed{\n \\frac{dI}{ds} \n +\\frac{\\mu_0 I}{\\langle B^2 \\rangle}\n\\frac{dp}{ds} \n =\n2\\pi\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle} {\\langle B^2 \\rangle}.\n}\n\\label{eq:I5}\n\\end{equation}\nThis result is the key equation for relating\nthe current density $\\langle j_{||} B \\rangle$ from a neoclassical code to the radial profile \nof total current in an MHD equilibrium code.\nWhile we used Boozer angles to derive this result,% main result (\\ref{eq:main_result}),\n%all the expressions from (\\ref{eq:I5})-(\\ref{eq:main_result}) are \nit is independent of any particular choice of angles.\n\n%Since $I$ appears both with and without a radial derivative in (\\ref{eq:I5}), some thought needs to be given to\nThere are several ways to implement (\\ref{eq:I5}) numerically, which we will now describe.\nIn each case, an iteration must be performed between the MHD equilibrium code and the bootstrap current code.\nWe will use a subscript $i$ to denote the iteration step.\n\n\\subsection{Low $\\beta$ approximation}\nIt can be seen that the $dp/ds$ term in (\\ref{eq:I5}) is smaller than the $dI/ds$ term preceding it by a factor of $\\beta$.\nTherefore for $\\beta\\ll 1$ it is a reasonable approximation to neglect the $dp/ds$ term. Then\nthe current profile is updated according to\n\\begin{equation}\n \\frac{dI_{i+1}}{ds} \n =\n2\\pi\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle_i} {\\langle B_i^2 \\rangle}.\n\\label{eq:iteration_low_beta}\n\\end{equation}\nThis is the approach adopted in \\bootsj.\n\n\\subsection{Lagging the $dp/ds$ term}\nA more accurate approach to solving (\\ref{eq:I5}) numerically is to evaluate the updated $dI/ds$ term using the $dp/ds$ term\nfrom the previous iteration:\n\\begin{equation}\n \\frac{dI_{i+1}}{ds} \n =-\\frac{\\mu_0 I_i}{\\langle B_{i}^2 \\rangle}\n\\frac{dp}{ds} \n+\n2\\pi\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle_{i}} {\\langle B_{i}^2 \\rangle}.\n\\label{eq:iteration_lag}\n\\end{equation}\n For $\\beta\\ll1$ this iteration should converge rapidly since the $dp/ds$ term is small, and since the factor of $I$ in the $dp/ds$ term is smoother than $dI/ds$. This is the approach that is used for the \\stellopt~\\vboot~iteration using \\sfincs.\n\n\\subsection{Integrating factor}\nA third approach to solving (\\ref{eq:I5}) is to interpret this expression as an ordinary differential equation for $I(s)$, introducing an integrating factor:\n\\begin{equation}\n\\frac{d}{ds} \\left( I F\\right)  =\n2\\pi F\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle} {\\langle B^2 \\rangle},\n\\label{eq:main_result_differential}\n\\end{equation}\nwhere the integrating factor is\n\\begin{equation}\nF(s) =   \\exp\\left( \\mu_0 \\int_0^s \\frac{ds'}{\\langle B^2 \\rangle} \\frac{dp}{ds} \\right).\n\\end{equation}\n(Again, the integrand is evaluated at $s'$ rather than $s$.)\nOne can see from this definition that $F = 1 + \\mathcal{O}(\\beta)$.\nImposing the boundary condition $I(0)=0$\n(there is no enclosed toroidal current on the magnetic axis),\nthe solution to (\\ref{eq:main_result_differential}) is then\n\\begin{equation}\n I(s)  = \\frac{2\\pi}{F(s)} \\int_0^s ds''\nF\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle} {\\langle B^2 \\rangle},\n\\label{eq:main_result}\n\\end{equation}\nwhere the integrand is evaluated at $s''$. From this expression,\nwe obtain the iterative scheme\n\\begin{equation}\n I_{i+1}(s)  = \\frac{2\\pi}{F_i(s)} \\int_0^s ds''\nF_i\n\\frac{d\\psi}{ds}\n\\frac{ \\langle j_{||} B \\rangle_i} {\\langle B_i^2 \\rangle},\n\\label{eq:iteration_integrating_factor}\n\\end{equation}\n\n\\section{VMEC definitions}\n\n\n\nThe current profile is provided to \\vmec~using two quantities. The first is the number \\curtor, which is\nthe total toroidal current inside the outermost \\vmec~magnetic surface. My understanding of \\vmec's sign convention is\nthat \\curtor~is positive when the current is in the $\\nabla\\zeta$ direction, where $\\zeta$ is the toroidal angle\nused in \\vmec~(also called $\\phi$ or $v$ in the code and its documentation).\nI also believe \\vmec's $\\zeta$ always increases in the counter-clockwise direction when the plasma\nis viewed from above, so $(R,\\zeta,Z)$ is a right-handed system.\nFor comparison, (\\ref{eq:I_definition}) indicates that $I(s)$ is positive if the current is in the direction\n$\\sqrt{g} \\nabla\\zeta$, which is opposite to the $\\nabla \\zeta$ direction if $\\sqrt{g} < 0$. \nIn my understanding, $\\sqrt{g}$ is \\emph{always} $<0$ in\n\\vmec~output.\n(The notation $\\sqrt{g}$ is confusing, since square roots are normally defined to be positive.)\nThus, \n\\begin{equation}\n\\mathtt{curtor} = \\mathtt{signgs} \\;I(1),\n\\label{eq:curtor}\n\\end{equation}\nwhere {\\ttfamily signgs}$=- 1$ is the \nname for the sign of $\\sqrt{g}$ in the \\vmec~{\\ttfamily wout*.nc} output file.\nIn (\\ref{eq:curtor}) we have used the \\vmec~convention that $s=1$ is the\noutermost magnetic surface in the code.\nThe particular definition of $s$ used in \\vmec~is that $s$ is the toroidal flux\nnormalized to range from 0 on the magnetic axis to 1 at the outermost surface.\n\n\nThe other relevant \\vmec~input parameters are \\ac~or {\\ttfamily ac\\_aux\\_f}; I'll write just \\ac~here \nto denote whichever one is used based on the {\\ttfamily pcurr\\_type} parameter. The profile determined by \\ac~(using a power series, spline, or other function) corresponds to \n$dI/ds$ up to an overall scale factor.\nThe \\ac~profile is always scaled by \\vmec~so the total current at the outermost surface is \\curtor.\nHence,\n\\begin{equation}\n\\frac{dI/ds}{(dI/ds)_{s=1}}\n=\\frac{\\mathtt{ac}(s)}{\\mathtt{ac}(1)}.\n\\end{equation}\nWe can therefore set \\ac~equal to (\\ref{eq:iteration_low_beta}), to (\\ref{eq:iteration_lag}), or to the radial derivative\nof (\\ref{eq:main_result}) (times any constant.)\n\nTo evaluate any of these three expressions, we need $d\\psi/ds$.\nSince $s\\propto \\psi$ in \\vmec,\n$d\\psi/ds$ is just the constant $\\psi_{edge}$,\nthe toroidal flux at the outermost magnetic surface.\nHowever, we must be careful about the sign.\nApplying the operation\n$ \\int_0^1 ds \\int_0^{2\\pi} d\\theta \\sqrt{g} \\nabla\\zeta \\cdot (\\ldots)$\nto (\\ref{eq:straight_field_lines}) gives\n\\begin{equation}\n\\int_0^1 ds \\int_0^{2\\pi} d\\theta \\sqrt{g} \\vect{B} \\cdot \\nabla\\zeta\n= \n\\int_0^1 ds \\int_0^{2\\pi} d\\theta \\sqrt{g} \n\\frac{d\\psi}{ds}  \\nabla s \\times\\nabla \\theta \\cdot \\nabla\\zeta\n=2 \\pi \\frac{d\\psi}{ds} = 2\\pi \\psi_{edge}.\n\\end{equation}\nFrom this equation, we see the sign convention for $d\\psi/ds$ in (\\ref{eq:main_result})\nis that a positive value corresponds to the magnetic field pointing in the direction\n$\\sqrt{g} \\nabla\\zeta$.\nIn contrast, I believe \\vmec's convention is that the output toroidal flux variable {\\ttfamily phi}\nis positive if the magnetic field points in the direction\n$\\nabla\\zeta$. Also, {\\ttfamily phi} is the flux \\emph{not} divided by $2\\pi$, in contrast to $\\psi$ in this note.\nHence, the value of $d\\psi/ds$ to use in (\\ref{eq:main_result}) is\n\\begin{equation}\n\\frac{d\\psi}{ds} = \\mathtt{signgs}\\frac{\\mathtt{phi}(s=1)}{2\\pi}.\n\\end{equation}\nNote that the output quantity {\\ttfamily phips} differs from {\\ttfamily phi}\nby a factor $2\\pi${\\ttfamily signgs}, so we could equivalently use $d\\psi/ds = \\mathtt{phips}$.\n\n\n%\\bibliographystyle{plain}\n%\\bibliography{computing_vmec_ac_profile_from_a_bootstrap_current_code}\n\n\\begin{thebibliography}{1}\n\n\\bibitem{LandremanCatto}\nM~Landreman and P~J Catto.\n\\newblock {\\em Phys. Plasmas}, {\\bf 19}, 056103 (2012).\n\n\\end{thebibliography}\n\n\\end{document} \n", "meta": {"hexsha": "412a8a7ed0193132467f727f09813fb8839e6fff", "size": 17396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SHARE/doc/computing_vmec_AC_profile_from_a_bootstrap_current_code/computing_vmec_AC_profile_from_a_bootstrap_current_code.tex", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "SHARE/doc/computing_vmec_AC_profile_from_a_bootstrap_current_code/computing_vmec_AC_profile_from_a_bootstrap_current_code.tex", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "SHARE/doc/computing_vmec_AC_profile_from_a_bootstrap_current_code/computing_vmec_AC_profile_from_a_bootstrap_current_code.tex", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 45.6587926509, "max_line_length": 319, "alphanum_fraction": 0.7189008968, "num_tokens": 5831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.6859494485880928, "lm_q1q2_score": 0.6064062620352623}}
{"text": "\\section{Introduction}\n\\begin{frame}\n  \\frametitle{The proof system Coq}\n  A language to:\n  \\begin{itemize}\n    \\item state theorems\n    \\item write proofs verified by computer\n    \\item write algorithms\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}[fragile]\n  \\frametitle{Raw example}\n  \\begin{verbatim}\nFixpoint fact (n:nat) : nat :=\n  match n with\n    | O => 1\n    | S n => S n * fact n\n  end.\n\nLemma lt_O_fact n : 0 < fact n.\nProof.\n  induction n; simpl; auto with arith.\nQed.\n  \\end{verbatim}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{The proof system Coq}\n  An environment to:\n  \\begin{itemize}\n    \\item reason interactively\n    \\item organize and distribute proofs\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{IDE}\n  \\begin{center}\n    \\includegraphics[width=9cm]{images/ide}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Distribute}\n  \\begin{center}\n    \\includegraphics[width=10cm]{images/opam}\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Usage}\n  Maths:\n  \\begin{itemize}\n    \\item four colors theorem (Gontier 04)\n    \\item Feit -- Thompson theorem (odd order theorem) (Gontier \\& all, 12)\n  \\end{itemize}\n\n  Software written and proven in Coq:\n  \\begin{itemize}\n    \\item certified \\textsc{C} compiler CompCert (Xavier Leroy \\& all)\n    \\item \\emph{Bedrock} library for low-level programs (Adam Chlipala \\& all)\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Usage}\n  Many conference papers with Coq proofs in annex.\n\\end{frame}\n\n% \\begin{frame}\n%   \\frametitle{Historique}\n%   \\begin{itemize}\n%     \\item Calcul des Constructions (\\textsc{CoC}) par \\emph{Thierry Coquand} (85)\n%     \\item implémentation du \\textsc{CoC} donnant lieu à \\textsc{Coq}\n%     \\item Calculus of Inductive Constructions (\\textsc{CiC}) par \\emph{Christine Paulin} (91)\n%   \\end{itemize}\n% \\end{frame}\n\n% \\begin{frame}\n%   \\frametitle{Logique}\n%   \\begin{itemize}\n%     \\item théorie des types plutôt que ensembles\n%     \\item logique intuitionniste et constructive\n%     \\item axiomes du tiers exclu, du choix optionels\n%   \\end{itemize}\n% \\end{frame}\n", "meta": {"hexsha": "7135c76034d07069a87a08a015b0b5f4931fd32c", "size": 2081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "intro.tex", "max_stars_repo_name": "clarus/presentation-coq-lab", "max_stars_repo_head_hexsha": "5f9173d5835bd85cc66a587b5d92b47affb51a43", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "clarus/presentation-coq-lab", "max_issues_repo_head_hexsha": "5f9173d5835bd85cc66a587b5d92b47affb51a43", "max_issues_repo_licenses": ["MIT"], "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": "clarus/presentation-coq-lab", "max_forks_repo_head_hexsha": "5f9173d5835bd85cc66a587b5d92b47affb51a43", "max_forks_repo_licenses": ["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.6477272727, "max_line_length": 95, "alphanum_fraction": 0.684766939, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6063279483432019}}
{"text": "\\problemname{Wiseguy}\n\n\\noindent Paulie Cicero is a made man who runs the underworld of Brooklyn along with his associates Jimmy ``the Gent\" Conway, Tommy DeVito, and the young but ambitious Henry Hill. The crew just got wind of a one-in-a-lifetime opportunity to raid \\$6 million from the Lufthansa vault at John F. Kennedy International Airport. If they plan carefully and succeed, this will go down as the greatest heist of all time.\\\\\n\nJimmy plans to hire $N$ new recruits for the operation, whom he plans to organize into a hierarchy of leadership. Recruits arrive one-by-one on a rolling basis. The first recruit has no leader, but every subsequent recruit that comes in must immediately be assigned to exactly one boss (who must be some previous recruit already in the hierarchy). Henry points out that for things to go smoothly, each recruit should in the end only be assigned $0$, $1$, or $2$ subordinates -- either a left-hand man, or a right-hand man, or neither, or both. Setting a limit at $2$ will reduce each individual's responsibility of having to manage lots of people.\\\\\n\nEach recruit also has a distinct ``strength\" level (say, as a distinct integer from $1$ to $N$), which Jimmy will evaluate and consider as he is assigning leadership. We can assume that the strength levels across all of the recruits are uniformly random, and that recruits arrive in no particular order of strengths. That is, the final sequence of strengths among the $N$ recruits ordered from oldest to newest is drawn uniformly randomly from the set of all $N!$ possible permutations.\\\\\n\nPaulie knows from experience that having a strong recruit leading other weaker recruits is a bad idea (the boss might abuse the subordinates), as is having a weak recruit leading only stronger recruits (being more qualified than your boss can lead to insubordination). Henry came up with a simple rule to mitigate this problem and bring some balance: For each recruit $i$, the left-hand man (if he exists) should always be weaker than recruit $i$ himself. Conversely, the right-hand man (if he exists) should always be stronger than recruit $i$ himself.\\\\\n\nEach new recruit that comes in is first handed to the first recruit (except the first recruit himself). Based on Henry's rule, the new recruit is passed down to become either the left- or right-hand man of the current recruit that has custody of him. If there is already a left- or right-hand man, then the recruit is passed down further. This repeats until there are no conflicts and the new recruit is settled in as a subordinate of an existing recruit who previously only had either $0$ or $1$ subordinates. The diagram below illustrates the boss assignment process for $N = 4$ recruits, who arrive in the following order of strengths: $3$, $1$, $4$, $2$.\\\\\n\n\\begin{center}\n\\includegraphics[width=300pt]{wiseguy}\n\\end{center}\n\nWhile Henry's strategy of limiting the number of subordinates to $2$ per person is good for distributing responsibility, the hierarchy can also become quite ``vertical\". Having excessively long chains of command can lead to miscommunication and broken telephones, which the crew cannot afford in a delicate operation like this. The ``height\" of a hierarchy is defined as the maximum number of times that a message needs to be passed from the first recruit to be able to reach any other recruit in the hierarchy. For example, the height of a hierarchy with a single leaderless recruit is 0, and the height of the last hierarchy in the above diagram is $2$.\\\\\n\nGiven the uniform randomness of new recruit strengths as well as the rules above for assigning leaders, Henry needs your help in finding out the expected height of the final hierarchy. This can be thought of as the ``average\" height of hierarchies across all possible arrival orders. For example, in the case of having to organize $N = 2$ recruits, both possible hierarchies have a height of $1$. In the case of $N = 3$, two of the possible hierarchies have a height of $1$, and the remaining four possible hierarchies have a height of $2$, resulting in an expected height of $(1 + 1 + 2 + 2 + 2 + 2)/6 = 5/3 \\approx 1.66667$.\\\\\n\nPlease help Henry predict the height for a hierarchy of $N$ recruits, so he can decide whether the plan will be feasible. A true wiseguy never gets caught, but a bad judgment or miscommunication in the ranks can easily bring shame to your crew. You'd better not mess up, or you might as well listen to Billy Batt's advice for Tommy -- quit the mob life, go home and get your shine box.\\\\\n\n\\section*{Input}\nThe first line of input consists of a single integer $T$ ($1 \\leq T \\leq 500$), specifying the number of test cases to follow.\\\\\n$T$ lines follow, each of which is a test case consisting of a single integer $N$ ($1 \\leq N \\leq 500$), specifying the number of recruits that will need to be organized for the heist.\\\\\n\n\\section*{Output}\nFor each test case, print, on a separate line, a single real number denoting the expected height for the hierarchy.\\\\\nNote: your answer must have at most $10^{-5}$ absolute or relative error to be considered correct.\\\\\n", "meta": {"hexsha": "7ac4843ca4a14865f57f7d77bc1bae1a531a1bbe", "size": 5117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "wiseguy/problem_statement/problem.en.tex", "max_stars_repo_name": "csecutsc/utscode2", "max_stars_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-30T15:06:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T06:50:25.000Z", "max_issues_repo_path": "wiseguy/problem_statement/problem.en.tex", "max_issues_repo_name": "csecutsc/utscode2", "max_issues_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "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": "wiseguy/problem_statement/problem.en.tex", "max_forks_repo_name": "csecutsc/utscode2", "max_forks_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T04:10:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T04:10:51.000Z", "avg_line_length": 170.5666666667, "max_line_length": 660, "alphanum_fraction": 0.7731092437, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6063279412641618}}
{"text": "  \n\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{tcolorbox}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{xcolor}\n\\usepackage{float}\n\\usepackage[\ntop    = 2.50cm,\nbottom = 2.50cm,\nleft   = 2.75cm,\nright  = 2.75cm]{geometry}\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\lhead{Analysis 1}\n\\rhead{EPFL/Alp Ozen}\n\n\\newtheorem{remark}{Remark}[section]\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{prop}{[Proposition]}\n\\newtheorem{definition}{Definition}\n\\numberwithin{equation}{subsection}\n\n\\title{Analysis}\n\\author{SemesterOne analysis at EPFL}\n\\date{\\vspace{-5ex}}\n\\newtheorem{example}{Example}[section]\n\\newtheorem{axiom}{Axiom}\n\\newtheorem{cor}{Corollary}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Proofs and the reals}\n\\subsection{Some general proofs}\nA valid proof is set of lines where each line logically follows from the next. \nA most famous proof is that $\\sqrt{2} $ is irrational. \n\n\\begin{tcolorbox}\n\\begin{proof}\n\tSuppose that $\\sqrt{2} = \\frac{a}{b}$ where $a,b \\in \\mathbb{Z}$ and $gcd(a,b) = 1$\n\t\\\\\n\tNow we have that $\\sqrt{2}b = a$ which means that $2b^2 = a^2$.\n\tAs result, $2 \\vert a^2$ hence also $2 \\vert a$. Thus we get that $a = 2k$ which also means that $b^2 = 2k^2$ hence $2 \\vert b$. As result, $gcd(a,b) = 2$ which is a contradiction. Therefore, $\\sqrt{2}$ must be irrational. \n\t\\end{proof}\n\\end{tcolorbox}\n\nQuite interestingly, we can also construct a 'wrong' proof just through one fallacious assumption and a set of correct steps. \n\n\\begin{tcolorbox}\n    \\textbf{Claim:} 1 is the largest integer.\n    \\\\\n    Proof: \n    \\\\\n    Let $n$ be the largest integer. Then we have $n \\geq n^2$. Which also means $0 \\geq n^2 - n = n(n-1)$. Now we have that either $n < 0$ or $n - 1 < 0$. But we know that $ n \\nless 0$ as $n$ is at least 1. Hence, $n - 1 < 0$ giving us the result $n < 1$ proving our theorem. Note that the mistake here is solely the assumption we made at the start that there was a largest integer. \n\\end{tcolorbox}\n\\subsection{Proofs relating to infinite processes}\nConsider the claim that $0.999\\ldots = 1$.\nOne way to prove this claim, rather naively is this.\n\n\\begin{align*}\n    9 \\times 0.999\\ldots \\\\\n    = (10 - 1) \\times 0.999\\ldots\\\\\n    = 9.999\\ldots - 0.999\\ldots \n    = 1\n\\end{align*}\n\nNow a more formal proof is to use an infinite sum and limits. Here it is. \n\n\\begin{tcolorbox}\n\\textbf{Analysis proof of 0.999\\ldots = 1}\n    \\begin{align*}\n        0.999\\ldots = 9\\lim_{k\\to\\infty}\\sum_{i=1}^{k} (10^{-k})\\\\\n        \\lim_{k\\to\\infty}\\sum_{i=1}^{k}(10^{-k}) = \\frac{10^{-1} - 10^{-(k+1)}}{1-10^{-1}}\\\\\n        = 9 \\times \\frac{1}{10} \\times \\frac{10}{9}\\\\\n        = 1\n    \\end{align*}\n\\end{tcolorbox}\n\n\\subsection{Basic notions of sets}\nThe breakdown of sets used in 'standard' analysis are $\\mathbb{N} \\subseteq \\mathbb{Z} \\subseteq \\mathbb{Q} \\subseteq \\mathbb{R}$.\n\\\\\nThere are also some common set related notation that must be known. \n\\begin{itemize}\n    \\item a \\textbf{subset} $a \\subseteq b$ is defined as $\\{x \\in b \\vert \\text{\"condition\"}\\}$\n    \\item a \\textbf{open interval} is defined as $\\left]a,b[; r\\in A, a < r < b$\n    \\item an \\textbf{open ball} $B(a,\\lambda) = \\left]a-\\lambda,a+\\lambda[$\n\\end{itemize}\n\n\\subsection{The Reals}\n\nThe reals, denoted \\mathbb{R} are an ordered field. Here is a more precise definition.\n\n\\begin{tcolorbox}\nThe reals are a set that have the 3 following axioms:\n\\begin{itemize}\n    \\item \\mathbb{R} is an abelian group under (+) and \\mathbb{R*} is an abelian group under ($\\times$). In addition to this, multiplication distributes over addition.\n    \\item The order relation $\\leq$ holds $\\forall x \\in \\mathbb{R}$ That is:\n    \\begin{align*}\n        x \\leq y \\otimes y \\leq x\\\\\n        x \\leq y, y \\leq x \\implies x = y\\\\\n        x \\leq y \\implies \\forall a \\in \\mathbb{R},\\  x + a \\leq y + a\\\\\n        0 \\leq x, 0 \\leq y \\implies 0 \\leq xy\n    \\end{align*}\n    \\item The inf and sup axioms hold\n\\end{itemize}\n\nWe shall now come the \\textbf{inf} and \\textbf{sup} axioms. It should be intuitively clear that any subset of \\mathbb{R} \n\\end{tcolorbox}\n\n\\subsection{Bounds}\nTake some subset S in \\mathbb{R}. An element B is called an upper bound of S if $\\forall x \\in S, B \\geq x$. Similarly, it is a lower bound of S if $\\forall x \\in S, B \\leq x$.\n\\\\\nThe maximum B of a set S denoted $max(S)$ is such that $B \\in S, \\forall x \\in S B \\geq x$. \n\\\\\nThe supremum of a set S(if it exists) is the lowest upper bound. That is $sup(S) = b$ is such that,\n\n\n    \\begin{align}\n        \\forall x \\in S, b \\geq x\\\\\n        \\forall \\epsilon > 0, \\exists x_{\\epsilon}, b - x_{\\epsilon} \\leq \\epsilon\n    \\end{align}\n    \n    \n    \n    \n    \n\\begin{remark}\n\n   In our above definition, b does not have to be in S.\n\n\\end{remark}\n\n\n\\begin{remark}\n    Condition 1 states that b is an upper bound of S. \n \n\\end{remark}\n\n\n\\begin{remark}\n       Given condition 1, b is the \\textit{minimum} of the upper bounds of S.\n\\end{remark}\n    \nSome examples of $sup$ and $inf$\n\n\\begin{example}\n\\begin{align*}\n Sup ]a,b[ = b\\\\\n Inf ]a,b[ = a\\\\\n Sup \\{ x\\in \\mathbb{R} \\vert x = 2k\\} \\implies \\text{Sup doesn't exist.}\n\\end{align*}\n\\end{example}\n\n\nWe now establish the infinimum axiom.\n\\begin{axiom}\nAll non-empty subsets of $\\mathbb{R}_{+}^{*}$ have a highest lower boundary(aka.infinimum)\n\\end{axiom}\n\n\\subsection{\\mathbb{Q} is dense in \\mathbb{R}}\nWe claim that between every real number, one can find a rational number. Here's the proof,\n\n\\begin{tcolorbox}\n\\begin{proof}\n    Let $x<y \\in \\mathbb{R}$ Suppose now that $\\exists a \\in \\mathbb{Q}$ such that $x<a<y$. By the Archimedean principle(there is always a greater natural number, $n > \\frac{1}{y-x}$ which implies $ny>nx+1$ Now since $ny>nx+1$, there is guaranteed to be some integer in the open bound $]nx,ny[$ which we denote $P$. Dividing by $n$, we get that $\\frac{P}{n} \\in ]x,y[$ which proves the theorem. \n    \\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\\subsection{Integer and fractional part}\n\nAny number $\\in \\mathbb{R}$ has a integer and fractional part(at least intuitively). Let's formally define these. For some $x \\in \\mathbb{R}$, let $S := \\{n\\in\\mathbb{N} \\vert n > x\\}$ Now since $S$ is bounded from below, letting $N$ be the minimum of this set, we obtain that $N \\not\\in S$. N-1 is thus called the integer part of x denoted [x]. ie. [6.4] = 6\n\\\\\nSimilarly, the fractional part of x denoted {x} is simply ${x} = x - [x]$\n\n\\subsection{Pinning it down:Sup/Inf, bounds, max/min}\n\\begin{definition}\nfor a given set $S \\subseteq \\mathbb{R}$, we have the following:\n\\\\\n\\textbf{Sup s = b} $\\iff \\forall \\epsilon > 0, \\exists x_{\\epsilon} \\in S, s.t. b - x_{\\epsilon} < \\epsilon$ (resp. Inf s has the flipped argument)\n\\\\\n\\textbf{Upper bound = b} $\\iff \\forall x \\in S, b\\geq x$(resp. lower bound)\n\\\\\n\\textbf{Max s = b} $\\iff$ b is an upper bound and $b \\in S$\n\n\\end{definition}\n\\\\\n\nAnd for the sake of repeating the early axiom(but very important) the infimum axiom is:\n\\begin{axiom}\nFor all non-empty subsets of $\\mathbb{R}$, $inf S$ exists. \n\\end{axiom}\n\nNow we make the first claim in this course that uses an epsilon proof.\n\\begin{tcolorbox}\n\n\\begin{prop}\nWhenever $S \\subseteq \\mathbb{N}$, then $inf S = min S$\n\\end{prop}\n\n\\begin{proof}\n    Now, by our axiom, we have that $\\mathbb{N} \\subseteq \\mathbb{R}$ hence we know that $inf S$ exists. We now have to show that $inf S = min S$. \n    \\\\\n    \n    Suppose that $inf S \\not =  min S$ and let $inf S = b$. Now clearly, $b+\\epsilon$ is not a lower bound of S. Now, let $\\epsilon = \\frac{1}{2}$. Because, $b + \\epsilon$ is not a lower bound, we know that $\\exists s_{e} < b + \\epsilon$. \n    \\\\\n    \n    Now $s_{e$ is also not a lower bound, so let's pick $\\epsilon^{\\prime\\prime} = s_{\\epsilon} - d$. Now again, $s_{\\epsilon^{\\prime\\prime}}$ must exist. We obtain yet the following:\n    \\\\\n    \\begin{equation*}\n        d < s_{\\epsilon^{\\prime\\prime}} < s_{\\epsilon} < d + 1/2 \n    \\end{equation*}\n    \n    Now, two natural numbers clearly can not be in an interval which is only $\\frac{1}{2}$ units long. Hence, contradiction which means that $d \\in S$\n    \\tag*{\\qedhere}\n\\end{proof}\n\n\\end{tcolorbox}\n\\\\\nLet's now prove that $\\sqrt{2}$ belongs to the reals. For this, we need the following corollary and axiom. \n\n\\begin{cor}\nEvery non-empty subset of \\mathbb{R} with an upper boundary admits a supremum. \n\\end{cor}\n\n\\begin{axiom}\nAn ordered field F, which \\mathbb{R} is, has the Archimedean property if given any positive x and y in F, $\\exists n \\in \\mathbb{Z}$ s.t. $nx > y$\n\\end{axiom}\n\n\\begin{tcolorbox}\n\n\\begin{prop}\n$\\sqrt{2} \\in \\mathbb{R}$\n\\end{prop}\n\n\\begin{proof}\nSuppose we define a set $S = \\{r \\in \\mathbb{R} \\vert r \\geq 0, r^{2} < 2\\}$. Now, as $S$ is a non-empty subset of $\\mathbb{R}$ bounded from above(i.e. 2 is an upper bound) we know that $sup S = x$ exists. Our goal is to show that both $x^{2} < 2$ and $x^{2} > 2$ lead to a contradiction. \n\\\\\n\n\\textbf{Case 1:} Suppose $x^{2} < 2$. We want to find $x + \\frac{1}{2} \\in S$ which implies that $x$ is not an upper bound as $x < x + \\frac{1}{2}$ \n\\\\\n$$(x+\\frac{1}{2})^2 = x^2 \\frac{2}{x} + \\frac{1}{n^2} \\leq x^2 + \\frac{2}{x} + \\frac{1}{n} = x^2 + \\frac{1}{n}(2x + 1) $$\n\\\\\nNow, we want to show that we can pick an $n$ s.t. $ x^2 + \\frac{1}{n}(2x + 1) < 2$. If we can pick such an $n$, then we know by transitivity of $<$ that $(x+\\frac{1}{n})^2 < 2$ as  $x^2 \\frac{2}{x} + \\frac{1}{n^2} \\leq x^2 + \\frac{2}{x} + \\frac{1}{n}$\n\\\\\nReordering the terms, we get $\\frac{1}{n} < \\frac{2 - x^2}{2x + 1}$ and clearly, $\\frac{2 - x^2}{2x + 1}$ is positive as $x^2 < 2$ and $x \\geq 0$. This way, we apply the archimedean property to know that $n$ exists s.t. $\\frac{1}{n} < \\frac{2 - x^2}{2x + 1}$. Given this, we now know that  $ x^2 + \\frac{1}{n}(2x + 1) < 2$ which in turn implies $x + \\frac{1}{n} \\in S$ This contradicts that $x = sup S$ hence $x^2 \\not < 2$\n\\\\\n\n\\textbf{Case 2:} In turn, we consider the case where $x^2 > 2$ and try to derive a contradiction. We want to show that $\\exists m \\in \\mathbb{N}$ s.t. $x - \\frac{1}{m}$ is also an upper bound of $S$ which would mean that $x \\not = inf S$. Now:\n\n$$ (x - \\frac{1}{m})^2 = x^2 - \\frac{2x}{m} + \\frac{1}{m^2} > x^2 - \\frac{2x}{m}$$\n\nWe want to choose $m$ s.t. $x^2 - \\frac{2x}{m} > 2$. This way, if $x^2 - \\frac{2x}{m} > 2$ holds, then since $(x - \\frac{1}{m})^2 > x^2 - \\frac{2x}{m}$, we will have that $x - \\frac{1}{m}$ is an upper bound. We obtain:\n$$\\frac{x^2 -2}{2x} > \\frac{1}{m}$$\n\\\\\nNow as $\\frac{x^2 -2}{2x}$ is positive, ${1}{m}$ dpes exist. Hence, $x - \\frac{1}{m}$ is also an upper bound that implies $x \\not = sup S$ if $x^2 > 2$.\n\\\\\nTherefore, $sup S = x = \\sqrt{2}$ and since every $sup S \\in \\mathbb{R}$, $\\sqrt{2} \\in \\mathbb{R}$\n   \n    \\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\\subsection{More theorems about \\mathbb{R}}\n\n\\begin{tcolorbox}\n\\begin{prop}\nIf $a < b$ are real numbers, then $\\exists c \\in \\mathbb{Q}, a < c < b$ \n\\end{prop}\n\n\\begin{proof}\nNow our goal is to show that for any real number $a,b$ we can always find such a $c$. \nNow take some arbitrary $n$ and set it to $n = [ \\frac{1}{b-a}] + 1$ Now clearly, $n>\\frac{1}{b-a}$ and hence $\\frac{1}{n} < b-a$. We will now use this result. Realize that $a = \\frac{an}{n} < \\frac{[an + 1]}{n} \\leq \\frac{an + 1}{n} = a + \\frac{1}{n} < a + b - a = b$ Therefore, we have found that $a < \\frac{[an]+1}{n}< b$ where $c = \\frac{[an]+1}$\n   \n    \\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\\begin{tcolorbox}\n\\begin{prop}\nIf $a < b$ are real numbers, then $\\exists c \\in \\mathbb{R\\backslash Q}, a < c < b$ \n\\end{prop}\n\n\\begin{proof}\nUsing the above proposition, we know that $\\exists c$ for any $\\frac{a}{\\sqrt{2}} < \\frac{b}{\\sqrt{2}} $ and now we get that $a < \\sqrt{2}c < b $ where $\\sqrt{2}c$ is irrational as whenever one term in $x\\times y = z$ is rational and the other irrational, we have (supposing $x$ is irrational) $x = \\frac{z}{y}$ and if also $z$ were rational, it would make $x$ rational which is a contradiction. \n    \\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\\begin{definition}\nThe absolute value function $x$ is a function $f: \\mathbb{R} \\to \\mathbb{R^{+}}$ such that:\n\n\\[ \\begin{cases}  \n      f(x) = x , x \\geq 0 \\\\\n      f(x) = - x , x < 0\n   \\end{cases}\n\\]\n\\end{definition}\n\nAbsolute value respects multiplication and division, that is:\n\n\\begin{align*}\n    |a||b| = |ab|\\\\\n    \\frac{|a|}{|b|} = |\\frac{a}{b}|\n\\end{align*}\n\nBut this doesn't hold for addition. For addition we have the triangle inequality: \n\n\\begin{equation*}\n    |x+y| \\leq |x| + |y| \n\\end{equation*}\n\nTo prove the above: \n\n\n\\begin{proof}\nTake $|x+y| < 0$. Then $|x+y| = -(x+y) = -x -y \\leq |x| + |y|$ Take $|x+y| \\geq 0$. Then $|x+y| = x + y \\leq |x| + |y|$\n    \\tag*{\\qedhere}\n\\end{proof}\n\\clearpage\n\\section{Sequences}\n\n\\subsection{Basics}\n\\begin{tcolorbox}\nLet's begin by formally defining sequences. A sequence is a function $f:\\mathbb{N} \\to \\mathbb{R}$ generally denoted $(x_{n})_{n\\geq0}$ And here are some more definitions on sequences:\n\\\\\nA sequence is:\n\\begin{itemize}\n    \\item constant if $\\exists \\ C \\in \\mathbb{R};\\ x_{n} = C \\ \\forall \\ n \\in \\mathbb{N}$\n    \\item bounded from below(resp. above) if $\\exists \\ m \\in \\mathbb{R} \\ ; m \\leq x_{n} \\forall \\ n \\in \\mathbb{N}$\n    \\item bounded if bounded from both directions\n    \\item increasing(resp. decreasing) if $x_{n+1} \\geq x_{n} \\forall \\ n \\in \\mathbb{N}$\n    \\item strictly increasing(resp.decreasing) if $x_{n+1} \\leq x_{n} \\forall \\ n \\in \\mathbb{N}$\n    \\item monotonous if it is increasing or decreasing(resp. strictly)\n\\end{itemize}\n\\end{tcolorbox}\n\nLet's now consider a proof on the following proposition:\n\n\\begin{tcolorbox}\nDefine $x_{n} = \\sqrt{4 + x_{n-1}}, \\ x_{0} = 1$. We claim that $x_{n}$ is bounded and more precisely that $1 \\leq x \\leq 3$.\n\n\\begin{proof}\nBase case: $x_{0} = 1$ hence holds.\n\\\\\nNow supposing proposition is true for all $n-1$ we get\n\n$$ 1 \\leq x_{n-1} \\leq 3 $$\n$$ 5 \\leq x_{n-1} + 4 \\leq 7$$\n\nNow we get:\n\n$$ \\sqrt{5} \\leq \\sqrt{x_{n-1} + 4} \\leq \\sqrt{7}$$\n$$ 1 \\leq \\sqrt{5} \\leq \\sqrt{x_{n-1} + 4} \\leq \\sqrt{7} \\leq 3 $$\n\\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\n\\begin{definition}\nA sequence $x_{n} $\\mathbb{conveges} to $x$ if $\\forall \\epsilon > 0$ we can find $n_{0} \\in \\mathbb{N}$ such that $n\\geq n_{0} \\rightarrow |x_{n} - x| \\leq \\epsilon $\n\\end{definition}\n\nNow in an intuitive sense, suppose the sequence converges to $x$ from both the right and the left. $x$ being our central point, we move a distance $\\epsilon$ away from this $x$. Now, if we can pick some $n_{0}$ such that for another $n \\geq n_{0}$ we have that $|x_{n} - x| \\leq \\epsilon$ this means that no matter how small we make epsilon we are able to find some $x_{n}$ in this region. \n\\\\\nHaving established convergence, any sequence that is not convergent is said to be \\textbf{divergent}. \n\\\\\nLet's now prove that a sequence is divergent. \n\n\\begin{tcolorbox}\n\n\\begin{proof}\n\nTake $x_{n} = (-1)^{n}$ Now suppose that $x_{n}$ converges to $x$. Then for $\\epsilon = \\frac{1}{2}, \\ \\exists n_{\\frac{1}{2}} \\in \\mathbb{N}$ s.t. $\\forall n \\geq n_{\\frac{1}{2}}$ we would have $|x_{n} - x| \\leq \\frac{1}{2}$. In particular if $n^{\\prime}$ is any other integer $n^{\\prime}>n_{\\frac{1}{2}}$ then we would have $x_{n} - x_{n^{\\prime}} \\leq |x_{n} - x| + |x - x_{n^{\\prime}}| \\leq \\frac{1}{2} + \\frac{1}{2}$ which implies a contradiction as $|x_{n} - x_{n+1}| = 2 > 1$\n\\tag*{\\qedhere}\n\\end{proof}\n\\end{tcolorbox}\n\n\\subsection{Limits and their algebra}\n\\begin{definition}\nIf a sequence $x_{n}$ converges to some $x$, we say that $x$ is the \\textbf{limit} of the sequence and is denoted $\\lim_{n\\to \\infty}{x_{n}} = x $ \n\\end{definition}\n\nHere are some properties of limits:\n\n\\begin{tcolorbox}\nFor sequences $x_{n}$ and $y_{n}$ with limits $x,y$ we have:\n\\begin{itemize}\n    \\item $$\\lim_{n \\to \\infty} {x_{n} \\cdot y_{n}} =  x\\cdot y $$\n    \\item $$\\lim_{n \\to \\infty} {x_{n} + y_{n}} =  x+y $$\n    \\item $$\\lim_{n \\to \\infty} \\frac{x_{n}}{y_{n}} = \\frac{x}{y} ; y \\not = 0$$\n    \\item if $\\exists \\ n_{0} \\in \\mathbb{N}, \\ x_{n} \\leq y_{n} \\ \\forall n \\geq n_{0}$ then $x\\leq y$ \n\\end{itemize}\n\\end{tcolorbox}\n\nWe now introduce the famous \\textbf{squeeze theorem} and prove it. \n\n\\begin{theorem}\nSqueeze theorem\n\\\\\nLet $a_{n}$ and $b_{n}$ be both sequences that converge to $a$. In addition, let $c_{n}$ be such that $ \\exists n_{0} \\in \\mathbb{N}, \\ \\forall n \\geq n_{0}, \\ a_{n} \\leq c_{n} \\leq b_{n}$ Then we clearly have the following:\n\\begin{proof}\n\\begin{equation}\n\\label{1}\n\\forall \\epsilon > 0, \\ \\exists N_{1}, \\ n \\geq N_{1} \\rightarrow |a_{n} - a| < \\epsilon \\equiv a - \\epsilon < a_{n} < a + \\epsilon\n\\end{equation}\nSimilarly, for $b_{n}$ we have that:\n\\begin{equation}\n\\label{2}\n     \\forall \\epsilon > 0, \\ \\exists N_{2}, \\ n \\geq N_{2} \\rightarrow |b_{n} - a| < \\epsilon \\equiv b - \\epsilon < b_{n} < a + \\epsilon\n\\end{equation}\nNow set $N = \\max{\\{N_{1},N_{2},n_{0}\\}}$. Now since $N \\geq N_{1},N_{2},n_{0}$ we have that both \\ref{1} and \\ref{2} hold $\\forall n > N$ This further gives us the result that:\n\n\\begin{align*}\n    a - \\epsilon < a_{n} \\leq c_{n} \\leq b_{N} < a + \\epsilon \\\\\n    |c_{n} - a| < \\epsilon\n\\end{align*}\n\\tag*{\\qedhere}\n\\end{proof}\n\\end{theorem}\n\n\nWe now list some useful inequalities that may be used along with the squeeze theorem and also a sample limit problem and a solution to it:\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale = 0.9]{epflSemesterOne/analysis/figures/usefula.JPG}\n    \\caption{Useful inequalities}\n    \\label{fig1}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{epflSemesterOne/analysis/figures/usefula2.JPG}\n    \\caption{Solution to hard limit problem}\n    \\label{fig2}\n\\end{figure}\n\n\\subsection{More on sequences}\nSuppose we want to show that some geometric sequence does not have a limit, simply that it is not converging.\n\nWe first establish the \\textit{Bernoulli inequality} which we shall prove later. We will use this result immediately. \n\n\\begin{equation}\n    q^n \\geq 1 + n(q-1)\n\\end{equation}\n\n\\begin{tcolorbox}\nTake $x_{n} = 4^n$. Now we claim that $x_{n}$ is not bounded.\n\\begin{proof}\nIt is not bounded if we can show that it increasing in increments that do not decrease. Suppose now that $b$ is some upper bound to $x_{n}$. Now by Bernoulli, we have that $4^n \\geq 1 + n^\\cdot3$. If we can show that $4^n \\geq 1 + n\\cdot3 > b$ we indeed get that there can be no upper bound $b$. We have that $n > \\frac{b-1}{3}$ and such an $\\n \\in \\mathbb{N}$ exists if we set it to $n:= [\\frac{b-1}{3} + 1]$ Now since $4^n \\geq 1 + n\\cdot3$ we have that $x_{n}$ is not bounded. \n\n\\end{proof}\n\\end{tcolorbox}\n\n\\begin{theorem}\nEvery converging sequence is bounded(a lower or upper bound exists obviously and if convergent the latter also exists.)\n\\end{theorem}\n\n\\clearpage\n\nLet's now get on to proving the rules we established for limit arithmetic.\n\n\\begin{proof}(Proof to sum rule)\nNow we are given that $x_{n}$ converges to $x$ and that $y_{n}$ converges to $y$. We want to show that $x_{n} + y_{n}$ converges to $x+y$. By definition, this is true if we can show that \n\\begin{equation*}\n    |(x_{n} + y_{n}) - (x+y)| \\leq \\epsilon, \\ \\forall \\epsilon \\in \\mathbb{R}\n\\end{equation*}\n\nNow luckily we have that $|(x_{y} + y_{n}) - (x+y)| = |(x_{n} - x) + (y_{n} - y)|$ And by the triangle inequality we know that $|(x_{n} - x) + (y_{n} - y)| \\leq |x_{n}-x| + |y_{n} - y|$ Thus if we can show that $|x_{n}-x| + |y_{n} - y| < \\epsilon$ we are guaranteed that $|(x_{n} - x) + (y_{n} - y)| < \\epsilon$ We will succeed with the latter part if we can show that both parts $(x_{n} - x)$ and $(y_{n} - y)$ are smaller than $\\frac{\\epsilon}{2}$. Now we have by definition of convergence that:\n\n$$ \\exists n \\geq n_{\\frac{\\epsilon}{2}}^{x} \\rightarrow |x_{n} - x| \\leq \\frac{\\epsilon}{2}$$\nSimilarly:\n\n$$ \\exists n \\geq n_{\\frac{\\epsilon}{2}}^{y} \\rightarrow |y_{n} - y| \\leq \\frac{\\epsilon}{2}$$\nNow fixing $n_{\\epsilon} := \\max{n_{\\frac{\\epsilon}{2}}^{x}, n_{\\frac{\\epsilon}{2}}^{y}}$(we do this since it assures both conditions to hold we have that because each of $(x_{n} - x)$ and $(y_{n} - x)$ are smaller than $\\epsilon$, so must $|x_{n}-x| + |y_{n} - y|$ by the triangle inequality. \n\\end{proof}\n\n\nLet's now do more applications of the squeeze theorem to show limits. \n\\begin{example}\nWe want to show that $aq^{n}$ converges to $0$ for $a\\not = 0$ and $|q|<1$. Now as a property we use that $\\lim_{n\\to\\infty}{x_{n}} = 0 \\rightarrow \\lim_{n\\to\\infty}{|x_{n}|}=0$ It is clear that we have an inequality of the form $0\\leq|aq^{n}|\\leq ?$ Doing more algebra(our goal is to find another sequence of form $\\frac{1}{x}$ converging to 0 to get:\n\n$$ \\frac{1}{?} \\leq \\frac{1}{|a\\cdot q^n|} = \\frac{1}{|a|} \\cdot (\\frac{1}{|q|})^n$$\n\nNow using Bernoulli we have:\n\n$$(\\frac{1}{|q|})^n \\geq 1 + n(\\frac{1}{|q|}-1)$$ which happily means:\n\n$$(\\frac{1}{a}\\cdot\\frac{1}{|q|})^n \\geq (\\frac{1}{a}\\cdot(1 + n(\\frac{1}{|q|}-1))$$ \nAnd finally taking the reciprocal all to get back to $aq^n$ we are left with \n\n$$ 0 \\leq |aq^n| \\leq \\frac{1}{\\frac{1}{a}\\cdot(1+n(\\frac{1}{|q|}-1)}$$ and clearly we see that the RHS is also a sequence that converges to 0 since all terms in the denominator but $n$ are constants. Hence, we have \\textbf{squeezed} our sequence. The key here was that we found a RHS sequence which we wanted to be of form $\\frac{1}{x}$ And in addition, we took the reciprocal of the inequality at the start simply to be able to use the bernoulli inequality. \n\\end{example}\n\nLet's now consider a harder example.\n\n\\begin{example}\nConsider the sequence $x_{n} = \\sqrt[n]{n}$ Now is this sequence converging? Well we know that $1\\leq\\sqrt[n]{n}$ and now another sequence we know which approaches to 1 is $1 + \\frac{1}{\\sqrt{n}}$. Now we only need to show that:\n\n$$\\sqrt[n]{n} \\leq 1 + \\frac{1}{\\sqrt{n}} $$ holds and if we can show this, we'll have that our sequence converges to 1. \n\nNow we get:\n$$ n \\leq (1 + \\frac{1}{\\sqrt{n}})^n$$ And notice how $(1 + \\frac{1}{\\sqrt{n}})^n$ is simply a binomial hence if any one of the terms in the binomial expansion is greater than $n$ our inequality will hold(this works as all $n$ are positive). Well for $\\sum_{i=0}^{n}{n\\choose i}(\\frac{1}{\\sqrt{n})^{i}}$ when observe that for $i=4$ we get:\n\n$$\\frac{(n-1)(n-2)(n-3)}{24n} \\geq n$$ further reducing to:\n$$\\frac{24n^2}{(n-1)(n-2)(n-3)} \\leq 1$$ and we know this is valid as \n\n$$\\lim_{n\\to\\infty}{\\frac{24n^2}{(n-1)(n-2)(n-3)}} = 0$$\n \nHence we get that $$\\sqrt[n]{n} \\leq 1 + \\frac{1}{\\sqrt{n}} $$ meaning that $\\sqrt[n]{n}$ converges to 1. \n\\end{example}\n\nLet's do one last example:\n\n\\begin{example}\nConsider $x_{n} = \\frac{2^n}{x!}$ Now clearly $0\\leq\\frac{2^n}{x!}$ and observing that $\\frac{2^n}{x!} = \\frac{2}{1} \\cdot \\frac{2}{2} \\cdot \\frac{2}{3} \\ldots $ it is obvious that $\\frac{2^n}{x!} \\leq 2 \\cdot (\\frac{2}{3})^{n-2}$ But we know that $\\lim_{n\\to\\infty}{2 \\cdot (\\frac{2}{3})^{n-2}}=0$ hence we have again squeezed our sequence!\n\\end{example}\n\n\\begin{theorem}\nIf $\\lim_{n\\to\\infty}{x_{n}}=0$ and $y_{n}$ is bounded, then $\\lim_{n\\to\\infty}{x_{n}\\cdot y_{n}}=0$\n\\end{theorem}\n\n\\begin{theorem}\n\\label{monotone}\nIf a sequence is bounded and increasing(monotone) it converges to the supremum (resp. infimum). \n\\end{theorem}\n\n\\begin{proof}\nNow because $y_{n}$ is bounded, we have that $\\exists M$ s.t. $M\\geq y_{n} \\forall n$. Hence we obtain that $x_{n}y_{n} \\leq Mx_{n}$ and clearly since $Mx_{n}$ converges to $0$ we have squeezed $x_{n}y_{n}$ and have that it also converges to 0. \n\\end{proof}\n\n\nWe consider the famous sequence of \\textbf{Fibonacci quotients}\n\\\\\nNow the fibonacci sequence is defined as $x_{0}=x_{1} = 1$, $x_{n+1} = x_{n} + x_{n-1}$ and we define the sequence of fibonacci quotients as $y_{n} = \\frac{x_{n+1}}{x_{n}}$ Our first theorem is that fibonacci quotient sequence is bounded between 1 and 2. Let's now fnd it's limit. Notice firstly that $y_{n+1} = 1 + \\frac{1}{y_{n}}$\n    $$y = \\lim_{n \\to \\infty}{y_{n}} = \\lim_{n \\to \\infty}{y_{n+1}} = 1 + \\frac{1}{\\lim_{n\\to \\infty}{y_{n}}} $$ Hence we get:\n    \n    $$ y = 1 + \\frac{1}{y}$$ which gives $\\frac{1+\\sqrt{5}}{2}$ as the only valid solution. But we still have to show that our sequence converges. A smart way to do so is to show that $z_{n} := |y_{n} - \\frac{1+\\sqrt{5}}{2}|$ converges which by limit arithmetic would imply $\\lim_{n \\to \\infty}{y_{n}} = \\frac{1+\\sqrt{5}}{2}$ Our goal is to squeeze $z_{n}$ in doing so. Notice that $z_{n+1} = |y_{n+1} - \\frac{1+\\sqrt{5}}{2}|= \\underbrace{1 + \\frac{1}{y_{n}} - (1 + \\frac{2}{1+\\sqrt{5}})}_{\\text{ using definition }} $ This yields the inequality $z_{n + 1} = \\frac{|y_{n} - \\frac{1+\\sqrt{5}}{2}|}{y_{n}\\frac{1+\\sqrt{5}}{2}}= \\frac{2}{1+\\sqrt{5}}\\frac{|y_{n - \\frac{1+\\sqrt{5}}{2}}|}{y_{n}}$ to give us that $z_{n+1} \\leq \\frac{2}{1+\\sqrt{5}}|y_{n - \\frac{1+\\sqrt{5}}{2}}|}$ because we know that $y_{n} \\geq 1$. Now finally this simplifies to $z_{n+1} \\leq \\frac{2}{1+\\sqrt{5}}z_{n}$ which applying the definition of $z_{n}$ gives $z_{n} \\leq \\frac{2}{1+\\sqrt{5}}^{2}z_{n-1} $ to result in $z_{n} \\leq \\frac{2}{1+\\sqrt{5}}^{n}z_{0}$ which converges to 0. Hence we have squeezed $z_{n}$\n    \n    \\clearpage\n    \n    In general this is the scheme one should use for finding limits of recursive sequences:\n    \n     \\begin{tcolorbox}[drop shadow, title = (Limit of recursive sequence),lower separated=true]\n     \\begin{enumerate}\n         \\item Assuming there is a limit, compute it using limit algebra.\n         \\item Showing some upper and lower bound(using induction) exclude any extra answers.\n         \\item Finally show that the sequence converges by showing that $\\lim_{n\\to\\infty}{x_{n}-x}=0$\n     \\end{enumerate}\n\\end{tcolorbox}\n\nWe now come to define \\textbf{approaching infinities}.\n\\begin{definition}\nThe definition of approaching $\\infty$ is as intuitive as saying for any real number I pick, the sequence has a term larger than it. Hence we define $\\lim_{n\\to \\infty}{x_{n}} = \\infty$ as $\\forall A \\in \\mathbb{R}$ $\\exists n_{A} \\in \\mathbb{N}$ such that $n\\geq n_{A}$ and $x_{n} \\geq A$. The similar definition applies for approaching $-\\infty$\n\\end{definition}\n\n\\begin{example}\nNotice that for a geometric sequence $x_{n} = aq^{n}$ if $a>0$ and $q>1$ it approaches $\\infty$ and if $a<0$ and $q>1$ it approaches $-\\infty$ \n\\end{example}\n\nA set of useful theorems on approaching infinities is the following:\n\n\\begin{theorem}(Theorems on approaching infinity)\n\\\\\nIf $\\lim_{n\\to\\infty}{x_{n}} = \\infty$ and $y_{n}$ is bounded from below, then $\\lim_{n\\to\\infty}{x_{n} + y_{n}} = \\infty$\n\\\\\nIf $x_{n}$ and $y_{n}$ both approach infinity, so does their product.\n\\\\\nIf $y_{n}$ is bounded and $x_{n}$ approaches infinity, then $\\lim_{n\\to\\infty}{\\frac{y_{n}}{x_{n}}} = 0$\n\\end{theorem}\n\nWe note that when it is the case that $\\lim_{n\\to\\infty}{x_{n}}=\\infty$ and  $\\lim_{n\\to\\infty}{x_{n}}=-\\infty$ we may have different cases such as:\n\n$$ \\lim_{n\\to\\infty}\\underbrace{n}_{x_{n}} + \\underbrace{(-n)}_{y_{n}} = 0 $$\n\n$$\\lim_{n\\to\\infty}\\underbrace{2n}_{x_{n}} + \\underbrace{(-n)}_{y_{n}} = \\infty$$\n\n$$\\lim_{n\\to\\infty}\\underbrace{2n + (-1)^{n}n}_{x_{n}} + \\underbrace{(-2n)}_{y_{n}} = (-1)^{n}n \\text{ which is unbounded hence does not approach anything}$$\n\n\n\\begin{theorem}(Squeeze theorem for approaching infinities)\nFor sequences $x_{n}$ and $y_{n}$ if $\\exists n_{0} \\in \\mathbb{N}$ such that $\\forall n \\geq n_{0}$, $x_{n} \\leq y_{n}$ we have:\n\\\\\n(1) If $\\lim_{n\\to\\infty}{x_{n}} = \\infty$ then $\\lim_{n\\to\\infty}{y_{n}} = \\infty$\n\\\\\n(2) If $\\lim_{n\\to\\infty}{y_{n}} = -\\infty$ then $\\lim_{n\\to\\infty}{x_{n}} = -\\infty$\n\\end{theorem}\n\n\\begin{theorem}(D'Alembert Theorem)\n\\\\\n$\\forall x_{n} \\not = 0$ and $\\lim_{n\\to \\infty}{|\\frac{x_{n+1}}{x_{n}}|} = \\infty$ then we have that $x_{n}$ diverges. \n\\end{theorem}\n\nAnd now we provide an example of sandwich for infinities. \n\n\\begin{example}\nDefine $x_{n}:= \\frac{x!}{2^{n}}$ We have that $\\frac{n}{2} \\cdot \\frac{n-1}{2} \\ldots \\cdot \\frac{3}{2} \\ldots \\geq \\frac{n}{2} \\cdot \\frac{3}{2}^{q-1}$ for some $n$. And because the latter is a geometric sequence which noticeably approaches infinity we have that $x_{n}$ approaches infinity. \n\\end{example}\n\n\\begin{proof}(We present a proof to theorem \\ref{monotone})\n\\\\\nNow set $S:=sup\\{x_{n}|n\\in\\mathbb{N}\\}$ and let $0<\\epsilon\\in\\mathbb{R}$ By definition $S$ is the smallest bound hence $S-\\epsilon$ is not the smallest bound. By def. again, $\\exists n_{\\epsilon}$ such that $S-\\epsilon<x_{n_{\\epsilon}}$ and we now get (for $n\\geq n_{\\epsilon}$ \n$$S - \\epsilon < x_{n_{\\epsilon}} < x_{n} < S < S+\\epsilon$$ and this is exactly the definition of convergence hence $S$ is the limit.\n\\end{proof}\n\\clearpage\n\n     \\begin{tcolorbox}[drop shadow, title = (Exploration of e),lower separated=true]\n   We define $x_{n} = (1 + \\frac{1}{n})^n$ We first ask is $x_{n}$ increasing. Consider the claim $(1+\\frac{1}{n})^{n} < (1+\\frac{1}{n+1})^{n+1}$\n   Now let's consider both the expansions of $(1 + \\frac{1}{n})^n$ and of $(1 + \\frac{1}{n+1})^{n+1}$\n   \n   $$ (1 + \\frac{1}{n})^n = \\sum_{i=0}^{n} \\binom{n}{i} (\\frac{1}{n^n}) = \\sum_{i=0}^{n} \\frac{1}{i!} \\frac{n\\cdot (n-1) \\ldots (n-i+1)}{n^i} = \\sum_{i=0}^{n} \\frac{1}{i!} (1 - \\frac{1}{n}) \\ldots (1 - \\frac{i-1}{n})    $$\n   \n   Similarly we have:\n   $$ (1 + \\frac{1}{n + 1})^{n+1} = \\sum_{i=0}^{n} \\frac{1}{i!} (1-\\frac{1}{n+1}) \\ldots  (1 - \\frac{i-1}{n}) $$\n   \n   and because generally $\\frac{\n   q}{j} > \\frac{q}{j+1}$ we have that terms on the RHS of the first expression are larger hence $(1+\\frac{1}{n})^{n} < (1+\\frac{1}{n+1})^{n+1}$ And we also have that our sequence is less than 3(which we do not show).\n   \n   Thus we define $$\\lim_{x \\to \\infty}{(1+\\frac{1}{n})^{n}} = e$$\n\\end{tcolorbox}\n\nAnd now we present an example of a bounded sequence that is decreasing which converges to its infimum. Consider $x_{n+1} = \\frac{1}{2}(x_{n} + \\frac{1}{x_{2}})s$ and $x_{0}= 2$.\n\\\\\nWe claim 1 is a lower bound which is true by induction(easy to show). Similarly, the sequence is decreasing as $x_{n} - x_{n+1} = \\frac{1}{2}(x_{n}-\\frac{1}{x_{2}} \\geq 0$ since $x_{n} \\geq 1$ And applying the recursive formula as usual we find that the limit is either -1 or 1 and ruling out -1 we get 1.  \n\n\\subsection{More definitions and theorems}\n\nWe come to an interesting definition. That of \\textit{LimSup & LimInf}.\n\n\\begin{definition}(LimSup and LimInf)\nLet $x_{n}$ be a bounded sequence. Then:\n$$y_{n} := \\sup{\\{x_{k}|n\\leq k \\in \\mathbb{N}\\}} \\text{(resp. inf)}}$$\n\\end{definition}\n\nNow the sequence $y_{n}$ is clearly decreasing as we are looking over a smaller set for each $n+1$. Similarly considering the respective inf definition, we have that it is increasing as each time we are removing elements from the largest set for $n=0$ meaning that our inf is at least as large as $y_{0}$ or bigger. Now since $y_{n}$ is valid sequence definition, it naturally has a limit as well defined as:\n\n$$y_{n} := \\lim_{n\\to\\infty}{\\sup{\\{x_{k}|n \\leq k \\in \\mathbb{N}\\}} \\text{(resp. inf)}}}$$\n\nHere's an example:\n\n\\begin{example}\nConsider $x_{n} = (-1)^{n}$. Defining $y_{n} = \\sup{\\{x_{k}|n\\leq k \\in \\mathbb{N}\\}}$ we get that the limit of $y_{n}$ as n goes to infinity is 1. \n\\end{example}\n\nAnd now we define what it means to be a subsequence. \n\n\\begin{definition}\nLet $x_{n}$ be a sequence. Then $x_{n_{k}}$ is a subsequence of $x_{n}$ where each $k$ is mapped to some $n_{k}$ by some rule $f: \\mathbb{N} \\to \\mathbb{N}$\n\\end{definition}\n\n\\begin{example}\nSuppose we define $x_{n} = \\frac{1}{n}\\sin{n}$ And define the subsequence $x_{2\\pi k}$ we notice that this subsequence is constant with all values mapping to $0$\n\\end{example}\n\nAnd yet a meetier example is:\n\n\\begin{example}\nDefine $x_{n} = (1 + \\frac{2}{n})^{n}$ and a subsequence $x_{2k}$. We notice that \n$$ \\lim_{k \\to \\infty}{(1 + \\frac{1}{k})^{2k}} = \\lim_{k \\to \\infty}{(1 + \\frac{1}{k})^{k})^{2}} = e^{2}$$\n\\end{example}\n\n\\clearpage\n\n\\begin{theorem}\nIf a sequence $x_{n}$ converges to $a$, then so do all subsequences of $x_{n}$\n\\end{theorem}\n\n\\begin{proof}(Simply using invoking definition of convergence)\nNow accepting the if true, we have that:\n\n$$ \\forall \\epsilon > 0, \\ \\exists n_{\\epsilon} \\ \\text{s.t.} n\\geq n_{\\epsilon} \\rightarrow |x_{n} - a| \\leq \\epsilon$$\n\n\\textcolor{red}{We now fix $n_{\\epsilon} = n_{k}$ hence proof. (this proof is to be revisited, it may be false.}\n\\end{proof}\n\n\\begin{example}\nConsider a sequence that jumps between $e$ and $-e$ as $n \\to \\infty$ defined by $x_{n} = (-1)^{n}(1 + \\frac{1}{n})^{n}$ For all subsequences with an even domain, the limit is $e$ and for subssequences with an odd domain, limit is $-e$\n\\end{example}\n\n\\begin{theorem}(Bolzano Weierstrass)\nEvery bounded sequence contains a convergent subsequence. \n\\end{theorem}\n\n\\begin{proof}\nLet's define $y_{n} = \\sup{x_{k}:k\\geq n}$. Now given that $y_{n}$ is bounded from below(because $x_{n}$ is bounded) and that it is decreasing, we have that $y_{n}$ converges to some $y$ meaning:\n$$ \\forall \\epsilon > 0, \\forall N, \\exists n_{\\epsilon} \\geq N \\ , \\underbrace{|y_{n} - y|\\leq \\frac{1}{2}\\epsilon}_{\\text{definition of convergence}}$$\n\nAnd by definition of sup and how we defined $y_{n}$ we have that \n$$ \\forall \\epsilon > 0, \\exists n_{1} \\geq n \\rightarrow |x_{n_{1}} - y_{n}| \\leq \\frac{1}{2}\\epsilon$$\n\nConsidering that we want an expression like $|x_{n_{1}} - y|\\leq\\epsilon$ And we get this by:\n\n$$ |x_{n_{1}} - y| = |x_{n_{1}} - y_{n} + y_{n} - y| \\leq \\underbrace{|x_{n_{1}} - y_{n}| + |y_{n} - y_{n}|}_{\\text{using triangle ineq.}} \\leq \\frac{1}{2}\\epsilon + \\frac{1}{2}\\epsilon = \\epsilon $$\nNow the last part is enough for the proof because we are assured that for any subsequence choice we make, it holds that there is an $N$ such that $n_{k} \\geq N$\n\\end{proof}\n\n\n\\begin{definition} (Cauchy convergence)\nA sequence is Cauchy convergent if $\\forall \\epsilon > 0$, $\\exists n_{\\epsilon}$ such that $\\forall n,m \\geq n_{\\epsilon}$ we have that $|x_{n} - x_{m}| \\leq \\epsilon$\n\\end{definition}\n\nA very important theorem concerning Cauchy convergence is:\n\n\\begin{theorem}\n$x_{n}$ is convergent iff. it is Cauchy convergent. \n\\end{theorem}\n\n\\begin{proof} (1)Suppose $x_{n}$ is convergent. Now set $x := \\lim_{n \\to \\infty}{x_{n}}$ By definition we have that $\\forall \\epsilon$ $\\exists n_{\\frac{\\epsilon}{2}}$ such that $\\forall n,m \\geq n_{\\frac{\\epsilon}{2}}$ \n\\begin{align*}\n    |x_{n} - x| \\leq \\frac{1}{2}\\epsilon\\\\\n    |x_{m} - x| \\leq \\frac{1}{2}\\epsilon\n\\end{align*}\nAnd noticing that $|x_{n} - x_{m}| = |x_{n} - x + x - x_{m}| \\leq |x_{n} - x| + |x - x_{m}| \\leq \\epsilon$\n\\\\\n(2) We now prove the opposite direction. \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\\end{document} \n", "meta": {"hexsha": "26e376cc27f8b3354508a6e2272ae7937ef99dce", "size": 34615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "epflSemesterOne/analysis/ch1.tex", "max_stars_repo_name": "Tsathogguaa/epflSemesterOne", "max_stars_repo_head_hexsha": "849be142ccc68890fde2794833960f9b581cc745", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "epflSemesterOne/analysis/ch1.tex", "max_issues_repo_name": "Tsathogguaa/epflSemesterOne", "max_issues_repo_head_hexsha": "849be142ccc68890fde2794833960f9b581cc745", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "epflSemesterOne/analysis/ch1.tex", "max_forks_repo_name": "Tsathogguaa/epflSemesterOne", "max_forks_repo_head_hexsha": "849be142ccc68890fde2794833960f9b581cc745", "max_forks_repo_licenses": ["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.2767379679, "max_line_length": 1084, "alphanum_fraction": 0.6423226925, "num_tokens": 12604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.8031738057795402, "lm_q1q2_score": 0.6063279341851215}}
{"text": "\\chapter{Sphere collision}\n\\label{cha:spherecollision}\n\nSpheres are the simplest of bounding shapes used in collision detection. This chapter presents tests for two versions of algorithms -- naive $O(N^2)$ approach and with partitioned space. While the simpler algorithm has a far greater number of collision checks per frame, it allocates almost no memory per frame. A more complex method will minimise the number of checks, but additional structure and steps added may influence overall execution time in an unexpected way.\n\n\n\\begin{figure}[h!]\n  \\caption{Example rendering of tested sphere collision system}\n  \\label{img:spheres}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/render.png}\n\\end{figure}\n\n\\section{Algorithm description}\n\\label{sec:spherealgorithmdescription}\n\nCollision detection for spheres is a trivial task. If distance between two spheres is smaller than the sum of their radiuses, spheres collide.\n\n$\\sqrt{(S_1.x - S_2.x)^2 + (S_1.y - S_2.y)^2 + (S_1.z - S_2.z)^2} < S_1.radius + S_2.radius$\n\nWhile the equation is simple, with the large number N of colliding objects the complexity of this detection is $O(N^2)$. Methods of space partitioning are used to reduce the number of checks. The one used in this benchmark is Octree.\nThe base for the algorithm is a tree-like structure of bounding boxes. Whenever a box contains more than one colliding object, it is divided into eight smaller boxes, by partitioning each edge by 2. When a maximum tree depth is reached, multiple objects are stored in one box. One object may be referenced from multiple boxes, when its size and position make them intersect. Each movement requires a check if the object has already moved to one of the neighbour boxes.\n\n\\begin{figure}[h!]\n  \\caption{Octree structure. Source: http://en.wikipedia.org/wiki/File:Octree2.svg/}\n  \\label{img:octree2}\n  \\centering\n\t\\includegraphics[width=10cm]{octree/octree2.png}\n\\end{figure} \n\nHaving objects grouped in boxes reduces the complexity of the collision check. Since an object may collide only with objects in the same box, the number of checks is much smaller. Overall complexity of Octree checks is $O(N log{N})$.\n\n\\begin{figure}[h!]\n  \\caption{Example of WebGL Octree debug rendering. Available online at http://pawlowski.it/octtree/}\n  \\label{img:octree}\n  \\centering\n\t\\includegraphics[width=10cm]{octree/octree.png}\n\\end{figure} \n\nWhen collision is detected, collision response is calculated. From the rule of conservation of momentum:\n\n\\begin{center}\n$m_1 * \\vec{v_1} + m_2 * \\vec{v_2} = m_1 * \\vec{v'_1} + m_2 * \\vec{v'_2}$\n\\end{center}\n\nMeaning that change of both momentums is of equal value.\n\\begin{center}\n$m_1*\\vec{v'_1} =  m_1*\\vec{v_1} - \\Delta P$\n\n$m_2*\\vec{v'_2} =  m_2*\\vec{v_2} + \\Delta P$\n\n$\\vec{v'_1} =  \\vec{v_1} - \\frac{\\Delta P}{m_1}$\n\n$\\vec{v'_2} =  \\vec{v_2} + \\frac{\\Delta P}{m_2}$\n\\end{center}\n\nTo simplify response, rotation and deformation of spheres are ignored. This does not affect performance analysis, since operations in tests are performed all in the same way.\n\nLet\n\\begin{center}\n$P = |\\Delta P|$\n\n$N = \\hat{pos_1 - pos_2}$\n\\end{center}\n\nSince transference of momentum occurs only along single points of contact:\n\\begin{center}\n$ \\Delta P = P * \\hat{\\vec{N}}$\n\n$\\vec{v'_1} =  \\vec{v_1} - \\frac{P}{m_1} * \\vec{N}$\n\n$\\vec{v'_2} =  \\vec{v_2} + \\frac{P}{m_2} * \\vec{N}$\n\\end{center}\n\nLet us split each velocity into two scalars, the perpendicular and parallel value of velocity vector, and introduce $\\vec{Q}$, similar to $\\vec{N}$, a perpendicular normalised vector lining along the exchanged momentum.\n\n \\begin{center}\n$\\vec{v_1} =  a_1 * \\vec{N} + b_1 * \\vec{Q}$\n\n$\\vec{v_2} =  a_2 * \\vec{N} + b_2 * \\vec{Q}$\n\n$\\vec{v'_1} =  a'_1 * \\vec{N} + b'_1 * \\vec{Q}$\n\n$\\vec{v'_2} =  a'_2 * \\vec{N} + b'_2 * \\vec{Q}$\n\\end{center}\n\n\\begin{figure}[h!]\n  \\caption{Illustration for collision response}\n  \\label{img:spheresbounce}\n  \\centering\n\t\\includegraphics[width=8cm]{spheres/bounce.jpg}\n\\end{figure} \n\nDeriving from previous equations:\n\n \\begin{center}\n$a_1' =  a_1 - \\frac{P}{m_1}$\n\n$b_1' = b_1$\n\n$a_2' =  a_2 + \\frac{P}{m_2}$\n\n$b_2' = b_2$\n\\end{center}\n\nNow let us use the rule of energy conservation to solve P:\n\n \\begin{center}\n$\\frac{m_1}{2} * ||\\vec{v_1}||^2 + \\frac{m_2}{2} * ||\\vec{v_2}||^2 = \\frac{m_1}{2} * ||\\vec{v'_1}||^2 + \\frac{m_2}{2} * ||\\vec{v'_2}||^2$\n\n$\\frac{m_1}{2} * ({a_1}^2 + {b_1}^2) + \\frac{m_2}{2} * ({a_2}^2 + {b_2}^2) = \\frac{m_1}{2} * ({a'_1}^2 + {b'_1}^2) + \\frac{m_2}{2} * ({a'_2}^2 + {b'_2}^2)2$\n\n$P = \\frac{2*m_1*m_2*(a_1-a_2)}{m_1+m_2}$\n\\end{center}\n\nand finally, using the result from the conservation of momentum:\n\n \\begin{center}\n$\\vec{v'_1} =  \\vec{v_1} - \\frac{2*(a_1-a_2)}{m_1+m_2} * m_2 * \\vec{N}$\n\n$\\vec{v'_2} =  \\vec{v_2} + \\frac{2*(a_1-a_2)}{m_1+m_2} * m_1 * \\vec{N}$\n\\end{center}\n\nFrom this result, using only the dot product of velocity vectors and normalised vector $pos_1 - pos_2$ the correct response to collision is calculated. In tested scenarios, the mass of all spheres is equal since it does not affect the complexity of calculations and produces less random results.\n\n\n\\section{{$O(N^2)$} approach}\n\\label{sec:sphereinitial}\n\nThe naive approach for collision detection proves to by easy to implement in JavaScript. Since almost no memory is allocated in each frame, no garbage collection issues appear. All methods are well defined and work mostly on floats. This results in a highly optimised binary code produced by the compiler, as shown on \\ref{img:spheres1profile}.\n\n\\begin{figure}[h!]\n  \\caption{Chart of time used in optimised version of JavaScript}\n  \\label{img:spheres1profile}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/spheres1-profile.png}\n\\end{figure} \n\nMultiple tests with N=1000 and different number of frames rendered show that for simple mathematical tasks, the performance of JavaScript is very close to that of C++. On average, the JavaScript version of benchmark runs 15\\% longer than a C++ one.\n\n\\begin{figure}[h!]\n  \\caption{Comparison of total execution time. N = 1000, varying number of frames.}\n  \\label{img:spheres1-time-total}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/time-total.png}\n\\end{figure} \n\\begin{figure}[h!]\n  \\caption{Comparison of execution time per frame. N = 1000, varying number of frames.}\n  \\label{img:spheres1-time-per-frame}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/time-per-frame.png}\n\\end{figure}\n\n\\section{Octree-partitioned space}\n\\label{sec:sphereoctree}\n\n\\begin{figure}[h!]\n  \\caption{Octree partitioned sphere collision system}\n  \\label{img:spheres}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/render2.png}\n\\end{figure}\n\nTests with Octree partitioning were executed with N=1000 spheres and T=1000 frames. The varying value is the maximum depth of Octree, ranging from 1 to 10.\nChanging the maximum depth reduces the number of collision checks between spheres, as shown on \\ref{img:octree-collisions}.\n\n\\begin{figure}[h!]\n  \\caption{Number of collisions in Octree}\n  \\label{img:octree-collisions}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/octree-collisions.png}\n\\end{figure}\n\nFor low values, the overall complexity of checks does not change significantly, since most spheres are in one or a few bounding cubes, and no checks are skipped. Additional operations related to Octree actually make this solution slower than $O(n^2)$ approach. For depth values in the optimal zone, the number of collisions is reduced by a factor of at least 10, while keeping Octree overhead reasonable. Interesting thing happens when the maximum level of Octree is very high and the edge of the smallest Octree cube approaches the size of the spheres. The number of transitions between partitioning cubes, related memory allocation and cleanups actually make this approach much slower, as shown on \\ref{img:octree-time}. Moreover, some spheres are references in more than one cube, raising again the number of collision checks.\n\n\\begin{figure}[h!]\n  \\caption{Run times in Octree system}\n  \\label{img:octree-time}\n  \\centering\n\t\\includegraphics[width=16cm]{spheres/octree-time.png}\n\\end{figure}\n\nIt's clearly visible that the number of collision checks and run time is correlated only up to a certain point. For deep Octrees, the number of checks does not improve further, but the overall run time gets longer. The performance of JavaScript in relation to C++ varies between 30\\% to 80\\% overhead. In comparison with $O(n^2)$ approach, optimal Octree in JavaScript runs over 92\\% faster and C++ over 94\\% faster.\n", "meta": {"hexsha": "9ea7b2ad9e0d17e89859608c28510ab1fc5ae9a0", "size": 8513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/rozdzial4.tex", "max_stars_repo_name": "fridek/Thesis-physics", "max_stars_repo_head_hexsha": "bf6ec43579aac7e4946b8c98a721e87053eeeac6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-06-15T01:20:42.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-09T02:26:19.000Z", "max_issues_repo_path": "doc/rozdzial4.tex", "max_issues_repo_name": "fridek/Thesis-physics", "max_issues_repo_head_hexsha": "bf6ec43579aac7e4946b8c98a721e87053eeeac6", "max_issues_repo_licenses": ["MIT"], "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/rozdzial4.tex", "max_forks_repo_name": "fridek/Thesis-physics", "max_forks_repo_head_hexsha": "bf6ec43579aac7e4946b8c98a721e87053eeeac6", "max_forks_repo_licenses": ["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.2663043478, "max_line_length": 829, "alphanum_fraction": 0.7338188653, "num_tokens": 2553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342624, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6063279243872206}}
{"text": "\\subsubsection{Specification of Time-Varying Parameters: Long Parameter Lines} \n\nTime-varying specifications for a parameter are invoked using elements 8 - 14 in the \\hyperlink{paraOrder}{long parameter line setup}. Each element and the options for selection related to time-varying parameters are as described below.\n\n\\hypertarget{EnvVar}{}\n\\begin{itemize}\n\n\\item Environmental Link and variable (env\\_var\\&link; element 8)\n\n\t\\begin{itemize}\n\t   \\item The environmental link and variable input is two inputs specified using a single three digit number. The hundreds place contains the option for the link function, while the tens and ones place is used to specify the environmental variable or derived quantity to which the parameter is linked. Note that environmental variables can only be included on an annual basis, so seasonal models would have the same effect applied to all seasons. If the environmental link and variable input is positive, then the parameter is linked to a variable specified in the data file environmental data; if it is negative, then the parameter is linked to a derived quantity. For example, env\\_var\\&link input 103 would use link type 1 and apply it to environmental data column 3, while the input -103  would use link type 1 and apply it to the \"-3\" column which is ln(relative summary biomass). The other options for both elements are enumerated below.\n\t   \\item The link function options (hundreds place) for the env\\_var\\&link input are:\n\t   \\begin{itemize}\n\t       \\item 1 = exponential scalar: $P_{y} = P_{base}e^{P_{t}E_{y}}$\n\t\t   \\item 2 = linear offset: $P_{y} = P_{base} + P_{t}E_{y}$\n\t\t   \\item 3 = Bounded replacement: $P_{y} = min(P_{base})+\\frac{max(P_{base})-min(P_{base})}{1+e^{P_tE_y+ln((P_{base}-min(P_{base})+0.0000001)/(max(P_{base})-P_{base}+0.0000001))}}$\n\t\t   \\item 4 = Logistic: $P_{y} = P_{base}\\frac{2}{1+e^{-P_{t2}(E_{y}-P_{t1})}}$\n\t   \\end{itemize}\n\t\twhere:\n\t   \\begin{itemize}\n\t       \\item $P_{y}$ = Parameter value in year $y$\n           \\item $P_{base}$ = Base parameter value\n           \\item $P_{t}$ = Link parameter value\n           \\item $P_{t1}$ = First of 2 link parameters (offset)\n           \\item $P_{t2}$ = Second of 2 link parameters (slope)\n           \\item $E_{y}$ = Environmental index value or derived quantity value in year $y$\n           \\item $min(P_{base})$ = the minimum parameter bound of base parameter\n           \\item $max(P_{base})$ = the maximum parameter bound of base parameter\n        \\end{itemize}\n\t\t\\item The variable options (tens and ones place, or $E_{y}$) for the env\\_var\\&link input are either 1) a positive integer from 1 to 99 referencing a time-series located in the \\hyperlink{env-dat}{environmental data section} of the data file, or 2) a negative value of -1 to -4 where $E_y$ is one of the following model-derived quantities:\n\t\t\\begin{itemize}\n\t\t\t\\item -1;  for ln(relative spawning biomass)\n\t\t\t\\item -2;  for recruitment deviation\n\t\t\t\\item -3;  for ln(relative summary biomass) (e.g., current year summary biomass divided by the unfished summary biomass)\n\t\t\t\\item -4;  for ln(relative summary numbers)\n\t\t\\end{itemize}\n\t\t\\item The four derived quantities are all calculated at the beginning of each year within the model, so they are available to use as the basis for time-varying parameter links without violating any order of operations rules.\n\t\\end{itemize}\n\t\n\\item Deviation Link (element 9). A positive integer invokes parameter deviations, but otherwise should be left as 0. SS3 expects the estimated deviations to be normal in distribution and the deviation values are multiplied by the standard error parameter as they are used. This differs from recruitment deviations and from the approach in SS3 v.3.24. Link options for parameter deviations are:\n\t\\begin{itemize}\n\t\t\\item 1 = multiplicative: $P_y = P_{base,y}e^{\\text{dev}_y*\\text{dev}_{se}}$,\n\t\t\\item 2 = additive: $P_y = P_{base,y} + \\text{dev}_y*\\text{dev}_{se}$,\n\t\t\\item 3 = random walk. Random walk options are implemented by using $\\rho$ in the objective function. $P_y = P_{base,y} + \\sum_{n=1}^{y} \\text{dev}_n*\\text{dev}_{se}$\n\t\t\\item 4 = mean reverting random walk with $\\rho$.\n\t\t\\begin{itemize}\n\t\t    \\item $X_1 = \\text{dev}_1*\\text{dev}_{se}$\n\t\t\t\\item $P_1 = P_{base,y} + X_1$\n\t\t\t\\item $X_y = \\rho*X_{y-1} + \\text{dev}_y*\\text{dev}_{se}$\n\t\t\t\\item $P_y = P_{base,y} + X_y$\n\t\t\\end{itemize}\n\t\t\\item 5 = mean reverting random walk with $\\rho$ and a logit transformation to stay within the minimum and maximum parameter bounds (approach added in SS3 v.3.30.16)\n\t    \\begin{itemize}\n\t\t    \\item $X_1 = \\text{dev}_1*\\text{dev}_{se}$\n\t\t\t\\item $R = P_{max} - P_{min}$\n\t\t\t\\item $Y_1 = ln(\\frac{P_{base,y} - P_{min} + \\text{nil}}{P_{max} - P_{base,y} + nil})$\n\t\t\t\\item $P_1 = P_{min} + \\frac{R}{1 + e^{-Y_1 - X_1 }}$. For the first year.\n\t\t\t\\item $X_y = \\rho*X_{y-1} + \\text{dev}_y*\\text{dev}_{se}$ \n\t\t\t\\item $Y_y = ln(\\frac{P_{base,y} - P_{min} + nil}{P_{max} + P_{base,y} + nil})$\n\t\t\t\\item $P_1 = P_{min} + \\frac{R}{1 + e^{-Y_y - X_y }}$. For years after the first year.\n\t\t\\end{itemize}\n\t\t\\item 6 = mean reverting random walk with penalty to keep the root mean squared error (RMSE) near 1.0. Same as case 4, but with penalty applied.\n\t\t\\item The option of extending the final model year deviation value subsequent years (i.e., into the forecast period) was added in v. 3.30.13.  This new option is specified by selecting the appropriate deviation link option (1, 2, 3, or 4) and appending a 2 at the front (21, 22, 23, or 24) which will use the final year deviation value for all forecast years\n\t\\end{itemize}\n\twhere: \n\t\\begin{itemize}\n\t     \\item $P_{y}$ = Parameter value in year $y$\n         \\item $P_{base,y}$ = Base parameter value for year $y$\n\t\t \\item $\\text{dev}_y$ = deviation in year $y$\n\t\t \\item $\\text{dev}_{se}$ = standard error of the deviation\n\t\t \\item nil is a small value (e.g., 0.0000001)\n\t\\end{itemize}\n\\item Deviation Minimum Year (element 10). Year deviations start for the parameter. This must be specified if using parameter deviations, but otherwise should be left as 0.\n\t\n\\item Deviation  Maximum Year (element 11). Year deviations end for parameter. This must be specified if using parameter deviations, but otherwise should be left as 0.\n\t\n\\item Deviation Phase (element 12). The phase in which the deviations for the parameter should be estimated. This must be specified if using parameter deviations, but otherwise should be left as 0.\n%is there a recommended phase to use if wanting to estimate devs?\n\t\n\\item Use Time Blocks or Trends (element 13). Time blocks and trends are both specified using this input. If neither are used, this should be left as 0. For trend options, the cumulative normal distribution function is used as the shape of the trend in all cases, but the parameterization differs. In general, the trend used is: \n    \\begin{equation}\n\t    P_y = P_{base} + P_{\\text{offset}}\\phi(\\frac{y - P_{\\text{infl}}}{P_{width}})\n\t\\end{equation}\n\twhere\n\t\\begin{itemize} \n\t    \\item $P_y$ is the final parameter value in year $y$\n\t\t\\item $P_{base}$ is the base parameter value\n\t\t\\item $P_{\\text{offset}}$ is the parameter offset value\n\t\t\\item $\\phi$ is the standard cumulative normal distribution function\n\t\t\\item $P_{\\text{infl}}$ is the inflection year (i.e., the year in which half of the total change from the base parameter has occured)\n\t\t\\item $P_{width}$ is the standard deviation.\n\t\\end{itemize}\nIn all cases, 3 parameters are estimated and hence 3 short parameter lines are required. These parameter lines differ amongst the trend options.\n\nThe input value options for element 13 are:\n\t\\begin{itemize}\n% TODO: add more information about how the above equation relates to theoptions -1 and -3.\n\t\t\\item >0: time block index for parameter. See the \\hyperlink{timeblocks}{time blocks section} of the control file for more information on specifying time blocks.\n\t\t\\item -1: Trend Offset option. Three parameters are estimated: end trend value as a logistic offset (input as $ln(P_{\\text{offset}})$), inflection year logistic offset (input as $ln(P_{\\text{infl}})$, and width ($P_{width}$. Offset trend value is in natural log space. Inflection year is also in natural log space and offset from ln(0.5). Width is directly specified.\n\t\t\\item -2: Trend Direct input option. In this case, $P_{\\text{offset}} = 1$. Three parameters are input via short parameter lines: end trend parameter value ($P_y$ where $y$ is the final year), inflection year ($P_{\\text{infl}}$, and width ($P_{width}$). \n\t\t\\item -3: Trend Fractional option. In this case, $P_{\\text{offset}} = 1$. Three parameters will be estimated: end trend parameter value as a fraction of base parameter maximum - minimum, inflection year as a fraction of end year - start year, and width ($P_{width}$). Width is directly input.\n\t\\end{itemize}\n\t\n\\item Time Block Functional Form (element 14). Leave as 0, unless time blocks are used.\n\t\\begin{itemize}\n\t\t\\item 0: multiplicative parameter ($P_{block} = P_{base}*e^{P_t}$)\n\t\t\\item 1: additive parameter ($P_{block} = P_{base} + P_t$)\n\t\t\\item 2: replace parameter ($P_{block} = P_t$)\n\t\t\\item 3: random walk across blocks ($P_{block} = P_{block,-1} + P_t$)\n\t\\end{itemize}\n\twhere:\n\t\\begin{itemize}\n        \\item $P_{block}$ = Final parameter value in time block $block$\n        \\item $P_{base}$ = Base parameter value\n\t\t\\item $P_{t}$ = Time-varying parameter value for a time block\n\t\t\\item $P_{block,-1}$ = Final parameter value in the previous time block\n     \\end{itemize}\n\\end{itemize}\n\n\nCode for the deviation link can be found in \\href{https://github.com/nmfs-stock-synthesis/stock-synthesis/blob/main/SS_timevaryparm.tpl}{SS\\_timevaryparm.tpl}, search for \"SS\\_Label\\_Info\\_14.3\".\n\n\n\\subsubsection{Specification of Time-Varying Parameters: Short Parameter Lines} \n\nIf a time-varying specification set up in the long parameter lines for a particular section requires additional parameters, short parameter lines need to be created following the long parameter lines for the section (unless \\hyperlink{autogen}{autogeneration} is used, which creates short parameter lines in control.ss\\_new upon running the model). The number of parameter lines required depends on the time-varying parameter specification.\n\nFor example, if two parameters were specified to have environmental linkages in the MG parameter section, below the MG parameters would be two parameter lines (when not auto-generating these lines), which is an environmental linkage parameter for each time-varying base parameter:\n\n\\begin{longtable}{ p{0.7cm} p{0.7cm} p{0.7cm}  p{1cm}  p{1.4cm}  p{1cm} p{1cm} p{6.7cm}  }\n\t\\hline\n\t&    &      & Prior &  Prior & Prior & & \\Tstrut\\\\\n\tLO & HI & INIT & Value &  SD    & Type  & Phase & Parameter Label \\Bstrut\\\\\n\t\\hline\n\t\\endfirsthead\n\t\n\t\\hline\n\t&    &      & Prior &  Prior & Prior &  & \\Tstrut\\\\\n\tLO & HI & INIT & Value &  SD    & Type  & Phase & Parameter Label \\Bstrut\\\\\n\t\\hline\n\t\\endhead\n\t\n\t\\endfoot\n\t\n\t\\endlastfoot\n\t\n\t\\multicolumn{7}{l}{COND: Only if MG parameters are time-varying} \\Tstrut\\\\\n\t-99   & 99  & 1 & 0 & 0.01 & 0 & -1 &\\#Wtlen\\_1\\_Fem\\_ENV\\_add\\Tstrut\\\\\n\t-99   & 99  & 1 & 0 & 0.01 & 0 & -1 &\\#Wtlen\\_2\\_Fem\\_ENV\\_add\\Bstrut\\\\\n\t\\hline\n\\end{longtable}\n\nIn SS3 v.3.30, the time-varying input short parameter lines are organized such that all parameters that affect a base parameter are clustered together with time blocks (or trend) first, then environmental linkages, then parameter deviations. For example, if the mortality-growth (MG) base parameters 3 and 7 had time varying changes, the order would look like:\n \n \\begin{center}\n \t\\begin{longtable}{p{5cm} p{10cm}}\n \t\t\\hline\n \t\tMG base parameter 3 & Block parameter 3-1\\Tstrut\\\\\n \t\t& Block parameter 3-2\\\\\n \t\t& Environmental link parameter 3-1\\\\\n \t\t& Deviation se parameter 3 \\\\\n \t\t& Deviation $\\rho$ parameter 3 \\Bstrut\\\\\n \t\tMG base parameter 7 & Block parameter 7-1 \\\\\n \t\t& Deviation se parameter 7 \\\\\n \t\t& Deviation $\\rho$ parameter 7 \\Bstrut\\\\\n \t\t\\hline\t \t                    \t\t\n \t\\end{longtable}\n \\end{center}\n \nThe number of short parameter lines for each time-varying setup selected depends on the selection options. The \\hyperlink{autogen}{autogeneration} feature can be used to figure out which parameter lines are needed. The short parameter lines needed for different time-varying options are:\n\\begin{itemize}\n\t\\item Environmental Linkages: Requires 1 short parameter line ($P_{t}$), except for link option 4, which requires 2 short parameter lines ($P_{t1}$ and $P_{t2}$).\n\t\\item Parameter deviations: Requires 2 short parameter lines, one for the standard error ($\\text{dev}_{se}$), followed by one for $\\rho$. Note that an input for $\\rho$ is required but only used with random walk options. For the random walk options, $\\rho$ can be set at 1 for a random walk with no drift or >1 for a random walk with drift.\n\t\\item Time Blocks: One parameter for each time block ($P_{t}$) set up in the pattern.\n\t\\item Trends: Requires 3 parameter lines. The interpretation of the parameters differs by the trend option selected, but in general they are a parameter for the final parameter value, a parameter for the inflection point year, and a parameter for the width (i.e., the standard deviation).\n\\end{itemize}\n\n\\subsubsection{Example Time-varying Parameter Setups}\n\nThe time-varying parameter options in Stock Synthesis are flexible. Below are some example setups that illustrate how the time-varying options could be used in a model, although there are many more possible setups.\n\n\\myparagraph{Environmental linkages}\n\n\\begin{itemize}\n\t\\item Suppose growth rate is found to be linked with an index of water temperature. The water temperature proxy could be input into the data file as environmental data. If it is input as index number 1, the growth parameter $K$ (if using a von Bertalanffy growth equation) could be linked to the water temperature proxy data by specifying the code \"201\" in the env\\_var\\&link function input. This would establish an offset link between the parameter and the temperature proxy. One additional parameter line is required after the \"MG parameter\" long parameter lines section.\n\t\\item Suppose for a fishery, selectivity is thought to shift depending on population size. Smaller fish are selected when there are lower population numbers, while larger fish are selected when there are higher population numbers. The selectivity parameter could be made time-varying using the code \"-104\" in the env\\_var\\&link option, which assumes a exponential scalar link between the base selectivity parameter and the time varying parameter value. One additional parameter line is required at the end of the selectivity long parameter lines section.\n\\end{itemize}\n\n\\myparagraph{Parameter Deviations}\n\n\\begin{itemize}\n\t\\item Suppose a selectivity parameter is thought to drift every year during 2000-2010. This could be represented using a random walk link option available within the parameter deviations options. To implement this, the user could input 3 into the \"dev link\" input on the long parameter line for the selectivity parameter, and then input values 2000 and 2010 for \"dev min yr\" and \"dev max yr\", respectively. The dev phase could be set to 3. With this setup, 2 additional short parameter lines would be expected, one for the standard error and one for $\\rho$. Both of these will be used since a random walk option is selected. To use a random walk without drift, $\\rho$ is set at 1 with a negative phase.\n\\end{itemize}\n\n\\myparagraph{Time Blocks}\n\n\\begin{itemize}\n\t\\item Offset approach: One or more time blocks are created and cover all or a subset of the years. Each block gets a parameter that is used as an offset from the base parameter (time block functional form 1). In this situation, typically the base parameter and each of the offset parameters are estimated. In years not covered by blocks, the base parameter alone is used.  However, if blocks cover all the years, then the value of the block parameter is completely correlated with the mean of the block offsets, so model convergence and variance estimation could be affected.  The recommended approach when using offsets is to not have all years covered by blocks or to fix the base parameter value at a reasonable level when doing offsets for all years.\t\n\t\n\t\\item Replacement approach, Option A: Time blocks are created which cover a subset of the years. The base parameter is used in the non-block years and the value of the base parameter is replaced by the block parameter in each respective block (time block functional form 2). In this situation, typically the base parameter and each of the block parameters are estimated.\t\n\t\n\t\\item Replacement approach, Option B: Replacement time blocks are created for all the years, so the base parameter is simply a placeholder that is always replaced by a block parameter (time block functional form 2). In this situation, do not allow the model to estimate the base parameter and only estimate the corresponding block replacement parameters, otherwise, the search algorithm will be attempting to estimate parameters that do not contribute to the log likelihood, so model convergence and variance estimation could be affected.\n\\end{itemize}\n\n\\myparagraph{Trends}\n\n\\begin{itemize}\n\t\\item Suppose natural mortality was thought to increase from 0.1 to 0.2 during 2000 to 2010. This could be input as a trend. First, the natural mortality parameter would be fixed at an initial value of 0.1. Then, a value of -2 could be input into the \"use block\" column of the natural mortality long parameter line to indicate that the direct input option for trends should be used. The long parameter line for M could look like:\n\t\\begin{center}\n\t\t\\begin{longtable}{p{1cm} p{1cm} p{1cm}  p{1.5cm}  p{1cm}  p{1.5cm}  p{1.5cm} p{1.5cm} p{3cm}}\n\t\t\t\n\t\t\t\\hline\n\t\t\tLO \\Tstrut & HI & INIT & <other entries> & PHASE & <other entries> & Use\\_Block & Block Fxn & Parameter Label\\Bstrut\\\\\n\t\t\t\\hline\n\t\t\t0          & 4 & 0.1 &  \\multicolumn{1}{c}{...} & -1 & \\multicolumn{1}{c}{...} & -2 & 0 & \\#M \\Bstrut\\\\\n\t\t\t\\hline\n\t\t\\end{longtable}\n\t\\end{center}\n\n\t\\item Three short parameter lines are then expected after the mortality-growth long parameter lines, one for the final value, one for the inflection year and one for the width. The final value could be fixed by using 0.2 as the final value on the short parameter line and a negative phase value. The inflection year could be fixed at 2005 by inputting 2005 for the inflection year in the short parameter line with a negative phase. Finally, the width value (i.e., standard deviation of the cumulative normal distribution) could be set at 3 years. The short parameter lines could look like:\n\t\n\t\\begin{longtable}{ p{0.7cm} p{0.7cm} p{0.7cm}  p{1cm}  p{1.4cm}  p{1cm} p{1cm} p{6.7cm}}\n\t\\hline\n\t&    &      & Prior &  Prior & Prior & & \\Tstrut\\\\\n\tLO & HI & INIT & Value &  SD    & Type  & Phase & Parameter Label \\Bstrut\\\\\n\t\\hline\n\t\\endfirsthead\n\t\n\t\\hline\n\t&    &      & Prior &  Prior & Prior &  & \\Tstrut\\\\\n\tLO & HI & INIT & Value &  SD    & Type  & Phase & Parameter Label \\Bstrut\\\\\n\t\\hline\n\t\\endhead\n\t\n\t\\endfoot\n\t\n\t\\endlastfoot\n\t\n\t0.001 & 4    & 0.2  & 0 & 0.01 & 0 & -1 &\\#M\\_TrendFinal\\Tstrut\\\\\n\t1999  & 2011 & 2005 & 0 & 0.01 & 0 & -1 &\\#M\\_TrendInfl\\Bstrut\\\\\n\t-99   & 99   & 3    & 0 & 0.01 & 0 & -1 &\\#M\\_TrendWidth\\_yrs\\Bstrut\\\\\n\t\\hline\n\\end{longtable}\n\\end{itemize}\n\n", "meta": {"hexsha": "7e8b006857dbd35868aff63d1898fc1385fb5187", "size": 19337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tv_parameter_description.tex", "max_stars_repo_name": "nmfs-stock-synthesis/ss-documentation", "max_stars_repo_head_hexsha": "941401b1f21582ad9d17b3b261761b307d6ea669", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-05T22:03:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T15:23:29.000Z", "max_issues_repo_path": "tv_parameter_description.tex", "max_issues_repo_name": "nmfs-stock-synthesis/ss-documentation", "max_issues_repo_head_hexsha": "941401b1f21582ad9d17b3b261761b307d6ea669", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 70, "max_issues_repo_issues_event_min_datetime": "2021-03-02T22:47:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-30T17:51:05.000Z", "max_forks_repo_path": "tv_parameter_description.tex", "max_forks_repo_name": "nmfs-stock-synthesis/ss-documentation", "max_forks_repo_head_hexsha": "941401b1f21582ad9d17b3b261761b307d6ea669", "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.6056910569, "max_line_length": 944, "alphanum_fraction": 0.727362052, "num_tokens": 5426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.6654105521116443, "lm_q1q2_score": 0.6063085923069643}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb,fouriernc,parskip,amsthm}\n\\usepackage{hyperref}\n\\hypersetup{\n  citecolor=red,\n  colorlinks=true\n}\n\\title{Fixed Point}\n\\date{}\n\\author{}\n\\begin{document}\n\\theoremstyle{definition}\n\\newtheorem{thm}{Theorem}[section]\n\\newtheorem{lem}[thm]{Lemma}\n\\newtheorem{defn}[thm]{Definition}\n\n\\maketitle\n\nFix a valid fixed point format $fmt$, and let $Fixed$ be the set of all \nfixed point numbers in this format (i.e., the set of all real numbers $x$ for \nwhich $is\\_fixed(fmt,x)$ is true).\n\n\\section{Rounding}\n\n\\begin{lem}\n\\label{fixedfinite}\n\\begin{equation*}\nFINITE(Fixed)\n\\end{equation*}\n\\begin{proof} Let $I = \\{0, 1, \\ldots, 2r^{p - 1} - 1\\}$. $I$ is finite \n(FINITE\\_NUMSEG). Let\n\\begin{equation*}\nf(i) = \\left \\{\n\\begin{array}{ll}\n0 & \\text{if $i = 0$}\\\\\n(i + 1)/2 \\cdot r^{e - p + 1} & \\text{if $i$ is odd}\\\\\ni/2 \\cdot r^{e - p + 1} & \\text{if $i$ is even}\n\\end{array} \\right .\n\\end{equation*}\nLet $s \\in Fixed$; then $|s| = f \\cdot r^{e - p + 1}$ and $0 \\leq f < r^{p - 1}$.\nIf $s = 0$, $s = f(0)$. If $s > 0$, $f > 0$, and $s = f(2f - 1)$. If $s < 0$,\nthen $f > 0$, and $s = f(2f)$.\n\nWe have shown $Fixed \\subset f(I)$. $Fixed$ is therefore finite. (FINITE\\_IMAGE)\n\\end{proof}\n\\end{lem}\n\n\\begin{defn}\n\\label{bounds}\nFor any $x \\in \\mathbb{R}$, let\n\\begin{align*}\nS_x^- &= \\{ \\; s \\in Fixed \\; | \\; s \\leq x \\; \\}\\\\\nS_x^+ &= \\{ \\; s \\in Fixed \\; | \\; s \\geq x \\; \\}\n\\end{align*}\nand $x^- = \\sup{\\big ( \\; S_x^- \\; \\big )}$, $x^+ = \\inf{\\big ( \\; S_x^+ \\; \n\\big )}$.\n\\end{defn}\n\n\\begin{lem}\n\\label{distance}\n\\begin{equation*}\n\\forall u, v \\in Fixed \\; . \\; u \\leq v \\; \\wedge \\; v \\leq u + fulp \\;\n\\Longrightarrow \\; v = u \\; \\vee \\; v = u + fulp\n\\end{equation*}\n\\begin{proof} Assume the antecedent, so we have $u \\leq v \\leq u + fulp$.\nSuppose the goal is not true. Then in fact\n\\begin{equation*}\nu < v < u + fulp \n\\end{equation*}\nwhich implies\n\\begin{equation*}\nff(u) \\cdot r^{e - p + 1} < ff(v) \\cdot r^{e - p + 1} < (ff(u) + 1) \\cdot r^{e - p + 1}\n\\end{equation*}\nDividing by the non-zero $r^{e - p + 1}$ gives\n\\begin{equation*}\nff(u) < ff(v) < ff(u) + 1\n\\end{equation*}\na contradiction, as the fractions are natural numbers.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{bounddistance}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\; x^- \\leq x^+ \\; \\wedge \\; x^+ \\leq x^- + fulp\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Since $|x| \\leq finf$, $S_x^-$ and\n$S_x^+$ are non-empty (they contain $-finf$ and $finf$ respectively).\nHence, $x^-$ and $x^+$ are maximal and minimal elements of $S_x^-$ and\n$S_x^+$, respectively (SUP\\_UNIQUE\\_FINITE).\n\nLet $s = x^- + fulp > x^-$. $s$ is a fixed point number with fraction\n$ff(x^-) + 1$. Either $s \\leq x$ or $s \\geq x$. If $s \\leq x$, then\n$s \\leq x^-$ by defn of $x^-$, which is impossible. If $s \\geq x$, then\n$s \\geq x^+$.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{bounddistance2}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\; x^+ = x^- \\; \\vee \\; x^+ = x^- + fulp\n\\end{equation*}\n\\begin{proof} Simple combination of ~\\ref{distance} and ~\\ref{bounddistance}.\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{boundbetw}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\; \n\\forall s \\in Fixed \\; . \\; s \\leq x^- \\; \\vee \\; s \\geq x^+\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Suppose, for a contradiction, that\nthere is some $s$ with $s > x^-$ and $s < x^+$. Then $s \\geq x^-$ and\n$s \\leq x^+ \\leq x^- + fulp$ from ~\\ref{bounddistance2}. It then follows\nfrom ~\\ref{distance} that $s = x^-$ or $s = x^- + fulp$, both contradictions.\n\\end{proof}\n\\end{lem}\n\n\\begin{thm}\n\\label{rndnear}\n\\begin{align*}\n&\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\\\\n& \\quad \\Big [ \\; \\forall s^* \\in Fixed \\; . \\; s^* = round(to\\_nearest,x) \\; \n\\Longleftrightarrow \\\\\n& \\quad \\Big [ \\; \\forall s' \\in Fixed \\; . \\; \n\\neg closer(s^*, s', x) \\; \n\\Longrightarrow\n\\; \\big(\\neg closer(s', s^*, x) \\; \\wedge \\; even(ff(s^*)) \\big) \\; \\Big ]\n\\; \\Big ]\n\\end{align*}\n\\begin{proof} Assume the antecedent. $round(to\\_nearest,x)$ is either\n$x^-$ or $x^+$, with the corresponding assumptions and properties\n(SUP\\_UNIQUE\\_FINITE again).\n\nSuppose $round(to\\_nearest, x) = x^-$, so $s^* = x^-$. \n\nSuppose $closer(x^-, x^+,x)$ is true. Suppose there is an $s' \\in Fixed$\nwith $\\neg closer(s^*, s', x)$. If $s' = x^-$, contradiction. If\n$s' = x^+$, contradiction. Otherwise, from ~\\ref{boundbetw}, $s' < x^-$\nor $s' > x^+$. In either case, contradiction (I'm assuming arith rule\ncan take over here).\n\nSuppose $closer(x^-, x^+,x)$ is false, but $ff(x^-)$ is true, so\nagain $s^* = x^-$. Suppose there is an $s' \\in Fixed$\nwith $\\neg closer(s^*, s', x)$. If $s' = x^-$, contradiction. If\n$s' = x^+$, then $\\neg closer(s', s^*, x)$ and $ff(s^*)$; OK. Otherwise, \nfrom ~\\ref{boundbetw}, $s' < x^-$ or $s' > x^+$. In either case, contradiction.\n\nThe proof is similar for $x^+$.\n\\end{proof}\n\\end{thm}\n\nThe proofs for other rounding modes are similar.\n\n\\begin{thm}\n\\label{abserror}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\; \\Longrightarrow \\;\n|round(to\\_nearest, x) - x| \\leq fulp/2\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Since $|x| \\leq finf$, \n$x^-$ and $x^+$ have the desired property that $x^- \\leq x$ and\n$x \\leq x^+$.\n\nSuppose $round(to\\_nearest,x) = x^-$ (with the corresponding assumptions).\nEither $x > x^-$ or $x = x^-$. If $x = x^-$, the error is zero. If $x > x^-$,\nthen $x^- < x \\leq x^+$ and $|x^- - x| \\leq |x^+ - x|$ (defn of closer). \nIt then follows (I'm thinking arith tac can do it) that \n$|x^-  - x| \\leq |x^+ - x^-| / 2$. From ~\\ref{bounddistance}, \n$|x^+ - x^-| \\leq fulp$, whence $|x^- - x| \\leq fulp/2$.\n\nThe proof for $x^+$ is similar.\n\\end{proof}\n\\end{thm}\n\nThe proof for the other rounding modes is similar, but easier, and the\nbound on the absolute error is $fulp$ instead of $fulp/2$.\n\n\\begin{lem}\n\\label{rnddown}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\;\n\\big [ \\; x < x^- + fulp/2 \\; \\Longrightarrow \\; round(to\\_nearest, x) = x^-\n\\; \\big ]\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Then $x^-$ and $x^+$ exist with the\ndesired properties. From ~\\ref{bounddistance2}, $x^+ = x^-$ or $x^+ =\nx^- + fulp$. If $x^+ = x^-$, then no matter what, $round(to\\_nearest,x)$\nrewrites to $x^-$.\n\nSuppose $x^+ = x^- + fulp$. It then follows that\n\\begin{equation*}\nx - x^- < fulp/2 = (x^+ - x^-)/2\n\\end{equation*}\nand hence (arith tac?) $x - x^- < x^+ - x$, or $|x - x^-| < |x^+ - x|$. \nTherefore, $closer(x^-, x^+, x)$, and $round(to\\_nearest, x) = x^-$ \n(probably some extra steps here in HOL light).\n\\end{proof}\n\\end{lem}\n\n\\begin{lem}\n\\label{rndup}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\;\n\\Longrightarrow \\;\n\\big [ \\; x > x^- + fulp/2 \\; \\Longrightarrow \\; round(to\\_nearest, x) = x^+\n\\; \\big ]\n\\end{equation*}\n\\begin{proof} Similar proof.\n\\end{proof}\n\\end{lem}\n\n\\begin{thm}\n\\label{relerror}\n\\begin{equation*}\n\\forall x \\in \\mathbb{R} \\; . \\; |x| \\leq finf \\; \\wedge \\; x \\neq 0 \\;\n\\Longrightarrow \\;\n\\left | \\frac{round(to\\_nearest, x) - x}{x} \\right | \\leq 1\n\\end{equation*}\n\\begin{proof} Assume the antecedent. Either $0 < |x| \\leq fulp/2$ or \n$|x| > fulp/2$. If $0 < |x| \\leq fulp/2$, then $-fulp/2 \\leq x \\leq fulp/2$.\nIt then follows from ~\\ref{rnddown} and ~\\ref{rndup} with $x^- = 0$ and\n$x^+ = 0$ (depending on the case) that $round(to\\_nearest,x) = 0$, and so\n\\begin{equation*}\n\\left | \\frac{round(to\\_nearest, x) - x}{x} \\right | = 1\n\\end{equation*}\nSuppose $|x| > fulp/2$. Since $|x| \\leq finf$, from\n~\\ref{abserror} we have\n\\begin{equation*}\n\\left | round(to\\_nearest, x) - x \\right | \\leq fulp/2\n\\end{equation*}\nIt then follows that\n\\begin{equation*}\n\\left | \\frac{round(to\\_nearest, x) - x}{x} \\right | \n\\leq \\frac{fulp/2}{|x|} \\leq 1\n\\end{equation*}\n\\end{proof}\n\\end{thm}\n\n\\end{document}\n", "meta": {"hexsha": "9a97483b5163b9350487fb25af594ef83a65a954", "size": 7946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "formal/ieee754/fixed/fixed.tex", "max_stars_repo_name": "monadius/FPTaylor", "max_stars_repo_head_hexsha": "55214506eaf1a5fbbecf098221b81c4cc375ac6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-11-24T20:52:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T15:04:48.000Z", "max_issues_repo_path": "formal/ieee754/fixed/fixed.tex", "max_issues_repo_name": "oanaoana/FPTaylor", "max_issues_repo_head_hexsha": "c14d05eb9dc59a1736f043789e9f8d2659f742a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2016-10-31T16:46:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-07T04:35:37.000Z", "max_forks_repo_path": "formal/ieee754/fixed/fixed.tex", "max_forks_repo_name": "oanaoana/FPTaylor", "max_forks_repo_head_hexsha": "c14d05eb9dc59a1736f043789e9f8d2659f742a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-01-11T17:52:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-24T01:52:59.000Z", "avg_line_length": 32.0403225806, "max_line_length": 87, "alphanum_fraction": 0.5990435439, "num_tokens": 3222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6062883811326111}}
{"text": "% 24 Feb 1997 mg\n\\chapter{Catalog of Program Packages and Entries}\n\\section*{Elementary Functions}\n\\begin{DLtt}{12345678901}\n\\item[B002 PRMFCT] Prime Numbers and Prime Factor Decomposition\n\\item[B100 RBINOM] Binomial Coefficient\n\\item[B101 ATG] Arc Tangent Function\n\\item[B102 ASINH] Hyperbolic Arcsine\n\\item[B105 RPLNML] Value of a Polynomial\n\\item[B300 RSRTNT] Integral of type $R(x,\\sqrt{a+bx+cx^2})$\n\\end{DLtt}\n\\section*{Equations and Special Functions}\n\\begin{DLtt}{12345678901}\n\\item[C200 RZEROX] Zero of a Function of One Real Variable\n\\item[C201 RSNLEQ] Numerical Solution of Systems of Nonlinear Equations\n\\item[C202 RMULLZ] Zeros of a Real Polynomial\n\\item[C205 RZERO] Zero of a Function of One Real Variable\n\\item[C207 RRTEQ3] Roots of a Cubic Equation\n\\item[C208 RRTEQ4] Roots of a Quartic Equation\n\\item[C209 CPOLYZ] Zeros of a Complex Polynomial\n\\item[C210 NZERFZ] Number of Zeros of a Complex Function\n\\item[C300 ERF] Error Function and Complementary Error Function\n\\item[C301 FREQ] Normal Frequency Function\n\\item[C302 GAMMA] Gamma Function for Positive Argument\n\\item[C303 GAMMF] Gamma Function for Real Argument\n\\item[C304 ALGAMA] Logarithm of the Gamma Function\n\\item[C305 CGAMMA] Gamma Function for Complex Argument\n\\item[C306 CLGAMA] Logarithm of the Gamma Function for Complex Argument\n\\item[C309 CCLBES] Coulomb Wave, Bessel, and Spherical Bessel\nFunctions for Complex Argument(s) and \\\\ Order\n\\item[C312 BESJ0] Bessel Functions J and Y of Orders Zero and One\n\\item[C313 BESI0] Modified Bessel Functions I and K of Orders\nZero and One\n\\item[C315 RRIZET] Riemann Zeta Function\n\\item[C316 RPSIPG] Psi (Digamma) and Polygamma Functions\n\\item[C317 CPSIPG] Psi (Digamma) and Polygamma Functions for Complex\nArgument\n\\item[C318 RELFUN] Jacobian Elliptic Functions sn, cn, dn\n\\item[C320 CELFUN] Jacobian Elliptic Functions sn, cn, dn for\nComplex Argument\n\\item[C321 CGPLG] Nielsen's Generalized Polylogarithm\n\\item[C322 RFRSIN] Fresnel Integrals\n\\item[C323 RFERDR] Fermi-Dirac Function\n\\item[C324 RATANI] Arctangent Integral\n\\item[C326 RCLAUS] Clausen Function\n\\item[C327 BSIR4] Modified Bessel Functions I and K of\nOrder 1/4, 1/2 and 3/4\n\\item[C328 CWHITM] Whittaker Function M of Complex Argument and\nComplex Indices\n\\item[C330 RASLGF] Legendre and Associated Legendre Functions\n\\item[C331 RFCONC] Conical Functions of the First Kind\n\\item[C332 RDILOG] Dilogarithm Function\n\\item[C334 RGAPNC] Incomplete Gamma Functions\n\\item[C335 CWERF] Complex Error Function\n\\item[C336 RSININ] Sine and Cosine Integrals\n\\item[C337 REXPIN] Exponential Integral\n\\item[C338 CEXPIN] Complex Exponential Integral\n\\item[C339 RDAWSN] Dawson's Integral\n\\item[C340 BSIR3] Modified Bessel Functions I and K of Order 1/3 and 2/3\n\\item[C341 BSKA] Modified Bessel Functions K of Certain Order\n\\item[C342 RSTRH0] Struve Functions of Orders Zero and One\n\\item[C343 BSJA] Bessel Functions J and I with Positive\nArgument and Non-Integer Order\n\\item[C344 CBSJA] Bessel Functions J with Complex Argument\nand Non-Integer Order\n\\item[C345 RBZEJY] Zeros of Bessel Functions J and Y\n\\item[C346 RELI1] Elliptic Integrals of First, Second, and Third Kind\n\\item[C347 RELI1C] Complete Elliptic Integrals of First,\nSecond, and Third Kind\n\\item[C348 CELINT] Elliptic Integral for Complex Argument\n\\item[C349 RTHETA] Jacobian Theta Functions\n\\end{DLtt}\n\\section*{Integration, Minimization, Non-linear Fitting}\n\\begin{DLtt}{12345678901}\n\\item[D101 SIMPS] Integration by Simpson's Rule\n\\item[D102 RADAPT] Adaptive Gaussian Quadrature\n\\item[D103 GAUSS] Adaptive Gaussian Quadrature\n\\item[D104 RCAUCH] Cauchy Principal Value Integration\n\\item[D105 RTRINT] Integration over a Triangle\n\\item[D106 RGS56P] Gaussian Quadrature with Five- and Six-Point Rules\n\\item[D107 RGQUAD] N-Point Gaussian Quadrature\n\\item[D108 TRAPER] Trapezoidal Rule Integration with an Estimated Error\n\\item[D110 RGMLT] Gaussian Quadrature for Multiple Integrals\n\\item[D113 CGAUSS] Adaptive Complex Integration Along a Line Segment\n\\item[D114 RIWIAD] Adaptive Multidimensional Monte-Carlo Integration\n{\\bf [Obsolete]}\n\\item[D120 RADMUL] Adaptive Quadrature for Multiple Integrals over\n$N$-Dimensional Rectangular Regions\n\\item[D151 DIVON4] Multidimensional Integration or Random Number\nGeneration {\\bf [Obsolete]}\n\\item[D200 RRKSTP] First-order Differential Equations (Runge-Kutta)\n\\item[D201 RDEQBS] First-order Differential Equations\n(Gragg--Bulirsch--Stoer)\n\\item[D202 RDEQMR] First-order Differential Equations\n(Runge--Kutta--Merson)\n\\item[D203 RRKNYS] Second-order Differential Equations\n(Runge--Kutta--Nystr\\\"om)\n\\item[D300 EPDE1] Elliptic Partial Differential Equation\n\\item[D302 ELPAHY] Fast Partial Differential Equation Solver\n\\item[D401 RDERIV] Numerical Differentiation\n\\item[D501 LEAMAX] Constrained Non-Linear Least Squares and Maximum\n                   Likelihood Estimation\n\\item[D503 RMINFC] Minimum of a Function of One Variable\n\\item[D506 MINUIT] Function Minimization and Error Analysis\n\\item[D510 FUMILI] Fitting Chisquare and Likelihood Functions\n{\\bf [Obsolete]}\n\\item[D601 RFRDH1] Solution of a Linear Fredholm Integral\nEquation of Second Kind\n\\item[D700 RFT] Real Fast Fourier Transform\n\\item[D702 CFT] Complex Fast Fourier Transform\n\\item[D705 RFSTFT] Real Fast Fourier Transform\n\\item[D706 CFSTFT] Complex Fast Fourier Transform\n\\end{DLtt}\n\\section*{Interpolation, Approximations, Linear Fitting}\n\\begin{DLtt}{12345678901}\n\\item[E100 POLINT] Polynomial Interpolation\n\\item[E102 MAXIZE] Maximum and Minimum Elements of Arrays\n\\item[E103 AMAXMU] Largest Absolute Number in Scattered Vector\n\\item[E104 FINT] Multidimensional Linear Interpolation\n\\item[E105 DIVDIF] Function Interpolation\n\\item[E106 LOCATR] Binary Search for Element in Ordered Array\n\\item[E201 RLSQPM] Least Squares Polynomial Fit\n\\item[E208 LSQ] Least Squares Polynomial Fit {\\bf [Obsolete]}\n\\item[E210 NORBAS] Polynomial Splines / Normalized B-Splines\n\\item[E211 RCSPLN] Cubic Splines and their Integrals\n\\item[E222 RCHEBN] Solution of Overdetermined Linear System in the\nChebychev Norm\n\\item[E230 TL] Constrained and Unconstrained Linear Least Squares Fitting\n\\item[E250 LFIT] Least-Squares Fit to Straight Line\n\\item[E255 PARLSQ] Least-Squares Fit to Parabola {\\bf [Obsolete]}\n\\item[E406 RCHECF] Chebyshev Series Coefficients of a Function\n\\item[E407 RCHSUM] Summation of Chebyshev Series\n\\item[E408 RCHPWS] Conversion of Chebyshev to Power and Power to\nChebyshev Series\n\\item[E409 RTRGSM] Summation of Trigonometric Series\n\\end{DLtt}\n\\section*{Matrices, Vectors and Linear Equations}\n\\begin{DLtt}{12345678901}\n\\item[F001 LAPACK] Linear Algebra Package\n\\item[F002 RVADD] Elementary Vector Processing\n\\item[F003 RMADD] Elementary Matrix Processing\n\\item[F004 RMMLT] Matrix Multiplication\n\\item[F010 RINV] Linear Equations, Matrix Inversion\n\\item[F011 RFACT] Repeated Solution of Linear Equations,\nMatrix Inversion, Determinant\n\\item[F012 RSINV] Symmetric Positive-Definite Linear Systems\n\\item[F105 POLROT] Rotate a Three-Dimensional Polar Coordinate System\n\\item[F110 MXPACK] TC Matrix Manipulation Package {\\bf [Obsolete]}\n\\item[F112 TR] Manipulation of Triangular and Symmetric Matrices\n\\item[F116 DOTI] Scalar Product of Two Space-Time Vectors\n\\item[F117 CROSS] Vector Product of Two 3-Vectors\n\\item[F118 ROT] Rotating a 3-Vector\n\\item[F121 VECMAN] Vector Algebra\n\\item[F122 SCATTER] Search Operations on Sparse Vectors\n\\item[F123 BVSL] Bit Vector Manipulation Package\n\\item[F150 MXDIPR] Direct or Tensor Matrix Product\n\\item[F406 RBEQN] Banded Linear Equations\n\\item[F500 RLHOIN] Linear Homogenous Inequalities\n\\end{DLtt}\n\\section*{Statistical Analysis and Probability}\n\\begin{DLtt}{12345678901}\n\\item[G100 PROB] Upper Tail Probability of Chi-Squared Distribution\n\\item[G101 CHISIN] Inverse of Chi-Square Distribution\n\\item[G102 PROBKL] Kolmogorov Distribution\n\\item[G103 TKOLMO] Kolmogorov Test\n\\item[G104 STUDIS] Student's T-Distribution and Its Inverse\n\\item[G105 GAUSIN] Inverse of Gaussian Distribution\n\\item[G106 GAMDIS] Gamma Distribution\n\\item[G110 LANDAU] Landau Distribution\n\\item[G115 VAVLOV] Approximate Vavilov Distribution and its Inverse\n\\item[G116 VVILOV] Vavilov Density and Distribution Functions\n\\item[G900 RANF] Random Number Generator {\\bf [Obsolete]}\n\\end{DLtt}\n\\section*{Operation Research Techniques and Management Science}\n\\begin{DLtt}{12345678901}\n\\item[H101 RSMPLX] Linear Optimization Using the Simplex Algorithm\n\\item[H301 ASSNDX] Assignment Problem\n\\end{DLtt}\n\\section*{Input/Output}\n\\begin{DLtt}{12345678901}\n\\item[I101 EPIO] EP Standard Format Input/Output Package\n\\item[I202 KUIP] KUIP - Kit for a User Interface Package\n\\item[I302 FFREAD] Format-Free Input Processing {\\bf [Obsolete]}\n\\end{DLtt}\n\\section*{Output and Graphical Data Presentation}\n\\begin{DLtt}{12345678901}\n\\item[J200 VIZPRI] Print Large Characters\n\\item[J530 BINSIZ] Reasonable Intervals for Histogram Binning\n\\end{DLtt}\n\\section*{Executive Routines}\n\\begin{DLtt}{12345678901}\n\\item[L210 COMIS] COMIS - Compilation and Interpretation System\n\\item[L400 PATCHY] Source Code Maintenance\n\\end{DLtt}\n\\section*{Data Handling}\n\\begin{DLtt}{12345678901}\n\\item[M101 SORTZV] Sort One-Dimensional Array\n\\item[M103 FLPSOR] Sort One-Dimensional Array into Itself\n\\item[M104 SORCHA] Sort One-Dimensional Character Array into Itself\n\\item[M107 SORTR] Sort Rows of a Matrix\n\\item[M109 SORTRQ] Sort Rows of a Matrix\n\\item[M215 PSCALE] Find Power-of-Ten Scale for Printing\n\\item[M220 IE3CONV] Conversion To and From IEEE Number Format\n\\item[M400 CHTOI] Portable Conversion Between Type CHARACTER\nand Type INTEGER\n\\item[M409 UBUNCH] Concentrate and Disperse Character Strings\n{\\bf [Partially obsolete]}\n\\item[M421 BITBYT] Package for Handling Bits and Bytes\n\\item[M422 PACBYT] Handling Packed Vectors of Bytes\n\\item[M423 INCBYT] Increment a Byte of a Packed Vector\n\\item[M426 BLOW] Unpack Full Words into Bytes\n\\item[M427 PKCHAR] Pack/Unpack Continuous Byte-strings\n\\item[M428 LOCBYT] Search for Byte-Content\n\\item[M429 NUMBIT] Number of One-Bits in a Word\n\\item[M431 IFROMC] Convert Between Character String and Packed\nASCII Form\n\\item[M432 CHPACK] Utility Routines for Character String Parsing\nand Construction\n\\item[M433 INDEXX] Utility Package for Character Manipulation\n\\item[M434 VXINV] Fast VAX Byte Inversion\n\\item[M436 BUNCH] Pack Bytes into Full Words\n\\item[M437 GETBIT] Set or Retrieve a Bit in a String\n\\item[M438 BTMOVE] Move Bit String\n\\item[M439 GETBYT] Set or Retrieve a Bit String\n\\item[M441 BITPAK] Handling Bits and Bytes, Bit Zero the Least\nSignificant\n\\item[M442 NAMEFD] Fortran Emulation of VM/CMS NAMEFIND Command\n\\item[M501 IUSAME] Locating a String of Same Words\n\\item[M502 UOPTC] Decoding Options Characters\n\\item[M503 UBITS] Locate the One-Bits of a Word or an Array\n\\item[M507 LENOCC] Occupied Length of a Character String\n\\item[M508 BITPOS] Find One-Bits in a String\n\\end{DLtt}\n\\section*{Debugging, Error Handlng}\n\\begin{DLtt}{12345678901}\n\\item[N001 KERSET] Error Processing for Sections A-H of KERNLIB\n{\\bf [Partially obsolete]}\n\\item[N002 MTLSET] Error Processing for MATHLIB\n\\item[N100 LOCF] Address of a Variable\n\\item[N103 IUWEED] Detect Indefinite and Infinite in an Array\n\\item[N105 TRACEQ] Print Trace-Back\n\\item[N203 TCDUMP] Memory Dump\n\\end{DLtt}\n\\section*{Service or Housekeeping Programming Aids}\n\\begin{DLtt}{12345678901}\n\\item[Q100 ZEBRA] Dynamic Data Structure and Memory Manager\n\\item[Q120 HIGZ] High Level Interface to Graphics and Zebra\n\\item[Q121 PAW] PAW - Physics Analysis Workstation Package\n\\item[Q122 SIGMA] SIGMA - System for Interactive Graphical\nMathematical Applications\n\\item[Q123 FATMEN] Distributed File and Tape Management System\n\\item[Q124 CSPACK] Client Server Routines and Utilities\n\\item[Q180 HEPDB] Distributed Database Management System\n\\item[Q210 ZBOOK] Dynamic Memory Management {\\bf [Obsolete]}\n\\item[Q901 INDENT] Indent Fortran Source\n\\item[Q902 FLOP] FLOP - Fortran Language Oriented Parser\n\\item[Q904 CONVERT] Fortran 77 to Fortran 90 source form conversion tool\n\\item[Q905 WYLBUR] Wylbur Phoenix - a Line Editor for ASCII Text Files\n                   \\textbf{[Obsolete]}\n\\end{DLtt}\n\\section*{Magnet and Beam Design, Electronics}\n\\begin{DLtt}{12345678901}\n\\item[T604 POISCR] Solution of Poisson's or Laplace's Equation in\nTwo-Dimensional Regions\n\\end{DLtt}\n\\section*{Quantum Mechanics, Particle Physics}\n\\begin{DLtt}{12345678901}\n\\item[U101 LOREN4] Lorentz Transformation\n\\item[U102 LORENF] Lorentz Transformations\n\\item[U111 RWIG3J] Wigner 3-j, 6-j, 9-j Symbols; Clebsch-Gordan,\nRacah W-, Jahn U-Coefficients\n\\item[U112 RTCLGN] Clebsch-Gordan Coefficients in Rational Form\n\\item[U501 RDJMNB] Beta-Term in Wigner's D-Function\n\\end{DLtt}\n\\section*{Random Numbers and General Purpose Utilities}\n\\begin{DLtt}{12345678901}\n\\item[V104 RNDM] Uniform Random Numbers {\\bf [Obsolete]}\n\\item[V105 NRAN] Arrays of Uniform Random Numbers {\\bf [Obsolete]}\n\\item[V113 RANMAR] Uniform Random Number Generator\n\\item[V114 RANECU] Uniform Random Number Generator\n\\item[V115 RANLUX] Uniform Random Numbers of Guaranteed Quality\n\\item[V116 RM48]   Double Precision Uniform Random Numbers\n\\item[V120 RNORML] Gaussian-distributed Random Numbers\n\\item[V122 CORSET] Correlated Gaussian-distributed Random Numbers\n\\item[V130 RAN3D]  Random Three-Dimensional Vectors {\\bf [Obsolete]}\n\\item[V131 RN3DIM] Random Three-Dimensional Vectors\n\\item[V135 RNGAMA] Gamma or Chi-Square Random Numbers\n\\item[V136 RNPSSN] Poisson Random Numbers\n\\item[V137 RNBNML] Binomial Random Numbers\n\\item[V138 RNMNML] Multinomial Random Numbers\n\\item[V149 RNHRAN] Random Numbers According to Any Histogram\n\\item[V150 HISRAN] Random Numbers According to Any Histogram\n{\\bf [Obsolete]}\n\\item[V151 FUNRAN] Random Numbers According to Any Function\n{\\bf [Obsolete]}\n\\item[V152 FUNLUX] Random Numbers According to Any Function\n\\item[V202 PERMU] Permutations and Combinations\n\\item[V300 UZERO] Preset Parts of an Array\n\\item[V301 UCOPY] Copy an Array\n\\item[V302 UCOCOP] Copy a Scattered Vector\n\\item[V304 IUCOMP] Search a Vector for a Given Element\n\\item[V306 PROXIM] Adjusting an Angle to Another Angle\n\\item[V401 GRAPH] Find Compatible Node-Nets in an Incompatibility Graph\n\\item[V700 RVNSPC] Volume of Intersection of a Circular Cylinder\nwith a Sphere\n\\end{DLtt}\n\\section*{High Energy Physics Simulation, Kinematics, Phase Space}\n\\begin{DLtt}{12345678901}\n\\item[W150 TRSPRT] Transport, Second-Order Beam Optics\n\\item[W151 TURTLE] Beam Transport Simulation, Including Decay\n\\item[W505 FOWL] General Monte-Carlo Phase-Space\n\\item[W515 GENBOD] N-Body Monte-Carlo Event Generator\n\\end{DLtt}\n\\section*{Statistical Data Analysis and Presentation}\n\\begin{DLtt}{12345678901}\n\\item[Y201 IUCHAN] Find Histogram-Channel\n\\item[Y250 HBOOK] Statistical Analysis and Histogramming\n\\item[Y251 HPLOT] HPLOT : HBOOK Graphics Interface for Histogram\nPlotting\n\\end{DLtt}\n\\section*{Miscellaneous System-Dependent Facilities}\n\\begin{DLtt}{12345678901}\n\\item[Z001 KERNGT] Print KERNLIB Version Numbers\n\\item[Z007 DATIME] Job Time and Date\n\\item[Z009 CALDAT] Calendar Date Conversion\n\\item[Z020 UMON] Usage Monitor for VAX/VMS\n\\item[Z035 ABEND] Abnormal Termination of Fortran Programs\n\\item[Z036 ABUSER] Intercept a Fortran Abend on IBM\n\\item[Z037 VAXAST] Routines to Handle Control-C Interrupts on Vax\n\\item[Z041 QNEXTE] Restart of Next Event\n\\item[Z042 JUMPXN] Calling a Subroutine by its Address {\\bf [Obsolete]}\n\\item[Z044 INTRAC] Identify Job as Interactive\n\\item[Z045 IFBATCH] Identify Job as Running in Batch Mode\n\\item[Z203 XINOUT] Short List Reading and Writing\n\\item[Z264 IARGC] Returns Command Line Arguments\n\\item[Z265 CINTF] Immediate Interface Routines to the C Library\n\\item[Z266 WHOAMI] Get the Name of the Executing Module\n\\item[Z267 FTOVAX] Convert File-name to and from UNIX Syntax\n\\item[Z301 VAXTIO] VAX Fortran Interface for Reading and\nWriting 'Foreign' Tapes\n\\item[Z303 KAPACK] Random Access I/O Using Keywords {\\bf [Obsolete]}\n\\item[Z310 CFIO] Handle Fixed-length Records on Unix Streams\n\\item[Z311 CIO] Handle Unix Disk Files\n\\item[Z313 TMREAD] Terminal Dialog Routines\n\\end{DLtt}\n", "meta": {"hexsha": "644a178d4d71623e890024323e28c9bcea29c005", "size": 16026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "shortwrups/crnlbcat.tex", "max_stars_repo_name": "berghaus/cernlib-docs", "max_stars_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-24T12:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-24T12:30:01.000Z", "max_issues_repo_path": "shortwrups/crnlbcat.tex", "max_issues_repo_name": "berghaus/cernlib-docs", "max_issues_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "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": "shortwrups/crnlbcat.tex", "max_forks_repo_name": "berghaus/cernlib-docs", "max_forks_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "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.3179190751, "max_line_length": 73, "alphanum_fraction": 0.7983901161, "num_tokens": 4700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6062883770600265}}
{"text": "%File: feature.tex\n%Date: Fri Jan 03 20:48:19 2014 +0800\n\n\n\\subsection{Feature Extraction}\n\n\\subsubsection{MFCC}\n\\label{sec:mfcc}\n\\textbf{Mel-Frequency Cepstral Coefficient} is a representation of the short-term power spectrum of a sound,\nbased on a linear cosine transform of a log power spectrum on a nonlinear mel-scale of frequency \\cite{mfcc} .\nMFCC is the mostly widely used features in Automatic Speech Recognition(ASR), and it can also be applied to Speaker Recognition task.\n\n\nThe process to extract MFCC feature is demonstrated in \\figref{mfcc}\n\\begin{figure}\n\n  \\centering\n  \\includegraphics[width=\\textwidth]{img/MFCC.png}\n  \\caption{MFCC feature extraction process\\label{fig:mfcc}}\n\n\\end{figure}\n\nFirst, the input speech should be divided into successive short-time frames of length $L$,\nneighboring frames shall have overlap $R$.\nThose frames are then windowed by Hamming Window, as shown in \\figref{framming}.\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.7\\textwidth]{img/MFCC-windowing-frames.png}\n  \\caption{Framing and Windowing \\label{fig:framming}}\n\\end{figure}\n\nThen, We perform Discrete Fourier Transform (DFT) on windowed signals to compute their spectrums.\nFor each of $N$ discrete frequency bands we get a complex number $X[k]$ representing\nmagnitude and phase of that frequency component in the original signal.\n\nConsidering the fact that human hearing is not equally sensitive to all frequency bands, and especially,\nit has lower resolution at higher frequencies.\nScaling methods like Mel-scale are aimed at scaling the frequency domain to better fit human auditory perception.\nThey are approximately linear below 1 kHz and logarithmic above 1 kHz, as shown below in \\figref{melscale}:\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{img/mel-scale.png}\n  \\caption{Mel-scale plot \\label{fig:melscale}}\n\\end{figure}\n\nIn MFCC, Mel-scale is applied on the spectrums of the signals.\nThe expression of Mel-scale warpping is as followed:\n\\[ M(f) = 2595 \\log_{10}(1 + \\dfrac{f}{700}) \\]\n\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=0.5\\textwidth]{img/bank.png}\n  \\caption{Filter Banks (6 filters) \\label{fig:bank}}\n\\end{figure}\nThen,  we appply the bank of filters according to Mel-scale on the spectrum,\ncalculate the logarithm of energy under each bank by $E_i[m] = \\log (\\sum_{k=0}^{N-1}{X_i[k]^2 H_m[k]}) $ and apply Discrete\nCosine Transform (DCT) on $E_i[m](m = 1, 2, \\cdots M) $ to get an array $c_i $:\n\\[ c_i[n] = \\sum_{m=0}^{M-1}{E_i[m]\\cos(\\dfrac{\\pi n}{M}(m - \\dfrac{1}{2}))} \\]\n\nThen, the first $k$ terms in $c_i $ can be used as features for future training.\nThe number of $k$ varies in different cases, we will further discuss the choice of $k$ in \\secref{result}.\n\n\\subsubsection{LPC}\n\\textbf{Linear predictive coding} is a tool used mostly in audio signal processing and speech\nprocessing for representing the spectral envelope of a\ndigital signal of speech in compressed form, using the information of a linear predictive model.\\cite{lpc}\n\nThe basic assumption in LPC is that,\n    in a short period, the $n$th signal is a linear combination of previous $p$ signals:\n    $ \\hat{x}(n) = \\sum_{i=1}^pa_i x(n-i)$\n    Therefore, to estimate the coefficients $ a_i$, we have to minimize the squared error\n    $ \\text{E}\\left[ \\hat{x}(n) - x(n)\\right]$.\n    This optimization can be done by Levinson-Durbin algorithm.\\cite{levinson-durbin}\n\n    Therefore, we first split the input signal into frames, as is done in MFCC feature extraction \\secref{mfcc}.\n    Then we calculate the $k$ order LPC coefficients for the signal in this frame.\n    Since the coefficients is a compressed description for the original audio signal,\n    the coefficients is also a good feature for speech/speaker recognition.\n    The choice of $k$ will also be further discussed in \\secref{result}.\n\n", "meta": {"hexsha": "4536934e1ad8083548eaa329d527b81affd08b8c", "size": 3847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Final-Report-Complete/feature.tex", "max_stars_repo_name": "ppwwyyxx/speaker-recognition", "max_stars_repo_head_hexsha": "15d7bf32ad4ba2f1543e1287b03f3f2e6791d4dd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 717, "max_stars_repo_stars_event_min_datetime": "2015-01-03T15:25:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T12:45:45.000Z", "max_issues_repo_path": "doc/Final-Report-Complete/feature.tex", "max_issues_repo_name": "zxynbnb/speaker-recognition", "max_issues_repo_head_hexsha": "15d7bf32ad4ba2f1543e1287b03f3f2e6791d4dd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2015-03-19T09:25:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-19T08:51:26.000Z", "max_forks_repo_path": "doc/Final-Report-Complete/feature.tex", "max_forks_repo_name": "zxynbnb/speaker-recognition", "max_forks_repo_head_hexsha": "15d7bf32ad4ba2f1543e1287b03f3f2e6791d4dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 315, "max_forks_repo_forks_event_min_datetime": "2015-01-21T00:06:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T08:13:36.000Z", "avg_line_length": 47.4938271605, "max_line_length": 133, "alphanum_fraction": 0.7499350143, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6062883690121771}}
{"text": "\\lab{Modelling the spread of an epidemic: SIR models}{Modelling the spread of an epidemic: SIR models}\n\\label{lab:SIRModels}\n\n% Many industry grade ode solvers are similar to the RK4 method already described. A common, reliable method that is a good choice for initially studying most problems is the Dormand-Prince method. This method is implemented in Python's \\li{scipy.integrate} module as \\li{dopri5}, and in MatLab as \\li{ode45}. A similar method is the Runge-Kutta-Fehlberg method (RKF45).\n%\n% The Dormand-Prince method is a Runge-Kutta method that computes a fourth order accurate solution, followed by a fifth order accurate solution. These solutions are used to estimate the error in the fourth order solution. In turn, the estimated error is used to help determine the size of each step $h_i = t_i-t_{i-1}$ used by the method, instead of used a fixed stepsize $h = (b-a)/n$.\n%\n% We will demonstrate how to solve the initial value problem\n% \\begin{align*}\n% y'(t) &= 6+2t-y, \\\\\n% y(0) &= 2,\n% \\end{align*}\n% using \\li{dopri5}. We start with importing several useful modules and defining the ode.\n% The \\li{ode} class is imported from the \\li{scipy.integrate} module.\n% This class functions as an interface to several numerical ode methods, one of which is \\li{dopri5}.\n% These other methods can be useful in certain situations; however, \\li{dopri5} is a good solver to try on new problems.\n%\n%\n%\n% We create an instance of the \\li{ode} class and initialize it using the \\li{set_integrator} and \\li{set_initial_value} methods.\n% Useful parameters are \\li{atol} and \\li{rtol}, which set the maximum allowed absolute and relative tolerances for the solution.\n% Other parameters and methods are explained in the documentation for \\li{scipy}.\n% Here the method solves for $y(1.6)$:\n%\n% \\begin{lstlisting}\n% from scipy.integrate import ode\n% import numpy as np\n% import matplotlib.pyplot as plt\n%\n% a, ya, b = 0., 2., 1.6\n% def ode_f(t,y): return np.array([-1.*y+6.+2.*t])\n%\n% ode_object = ode(ode_f)\n% ode_object.set_integrator('dopri5',atol=1e-5)\n% ode_object.set_initial_value(ya,a)\n% print ode_object.integrate(b)\n% \\end{lstlisting}\n%\n% Alternatively, let us solve for $y$ on a evenly spaced mesh, and then plot the results.\n% %# The output of this function must have the shape (dim,), where dim\n% %# is the dimension of the system.\n% \\begin{lstlisting}\n% ode_object = ode(ode_f).set_integrator('dopri5',atol=1e-5)\n% ode_object.set_initial_value(ya,a)\n%\n% dim, t = 1, np.linspace(a,b,51)\n% Y = np.zeros((len(t),dim))\n% Y[0,:] = ya\n% for j in range(1,len(t)): Y[j,:] = ode_object.integrate(t[j])\n%\n% plt.plot(t,Y[:,0],'-k')\n% plt.show()\n% \\end{lstlisting}\n%\n% \\begin{figure}[ht]\n% \\centering\n% \\includegraphics[width=\\textwidth]{Example1.pdf}\n% \\caption{The solution of $y'(t) = 6+2t-y$, $y(0) = 2$, on the interval $[0,1.6]$, using the solver \\li{dopri5} from \\li{scipy.integrate}.}\n% \\label{sir:example1}\n% \\end{figure}\n%\n%\n% \\begin{problem}\n% Using \\li{dopri5}, solve the IVP\n% \\begin{align*}\n% 5y''' + y'+2y &= 0, \\,\\, 0 \\leq x \\leq 16,\\\\\n% y(0) &=0,\\\\\n% y'(0) &= 1,\\\\\n% y''(0) &= -2.\n% \\end{align*}\n% \\end{problem}\n%\n% Another good ode solver to try is \\li{odeint}, also in \\li{scipy.integrate}. \\li{odeint} is a Python wrapping for the function \\li{lsoda} from the Fortran library \\li{odepack}. One of the nice features of \\li{lsoda} is that it automatically switches between stiff and nonstiff solvers depending on the behavior of the problem.\n%\n%\n% \\section*{The SIR Model}\nThe SIR model describes the spread of an epidemic throughout a large population.\nIt does this by describing the movement of the population through three phases of the disease: those individuals who are \\emph{susceptible}, those who are \\emph{infectious}, and those who have been \\emph{removed} from the disease.\nThose individuals in the removed class have either died, or have recovered from the disease and are now immune to it.\nIf the outbreak occurs over a short period of time, we may reasonably assume that the total population is fixed, so that $S'(t) + I'(t) + R'(t) = 0$.\nWe may also assume that $S(t) + I(t) + R(t) = 1$, so that $S(t)$ represents the \\textit{fraction} of the population that is susceptible, etc.\n\nIndividuals may move from one class to another as described by the flow\n\\[S \\to I \\to R.\\]\nLet us consider the transition rate between $S$ and $I $.\nLet $\\beta$ represent the average number of contacts made per day that could spread the disease.\nThe proportion of these contacts that are with a susceptible individual is $S(t)$.\nThus, one infectious individual will on average infect $\\beta S(t)$ others per day.\nLet $N$ represent the total population size.\nThen we obtain the differential equation\n\\[\\frac{d}{dt}(S(t) N) = -\\beta S(t) (I(t) N)\\]\n\n Now consider the transition rate between $I$ and $R$.\nWe assume that there is a fixed proportion $\\gamma$ of the infectious group who will recover on a given day, so that\n\\[\\frac{d}{dt}R(t) = -\\gamma I(t).\\]\nNote that $\\gamma$ is the reciprocal of the average length of time spent in the infectious phase.\n\nSince the derivatives sum to $0$, we have $I'(t) = - S'(t) - R'(t)$, so the  differential equations are given by\n\\begin{align*}\n\\frac{dS}{dt} &=-\\beta IS ,\\\\\n\\frac{dI}{dt} &= \\beta I S-\\gamma I,\\\\\n\\frac{dR}{dt} &=\\gamma I.\n\\end{align*}\n\n\\begin{problem}\nSolve the IVP\n\\begin{align*}\n\\frac{dS}{dt} &=-\\frac{1}{2} IS ,\\\\\n\\frac{dI}{dt} &= \\frac{1}{2} I S-\\frac{1}{4} I, \\\\\n\\frac{dR}{dt} &=\\frac{1}{4} I,\\\\\nS(0) &= 1-6.25\\cdot10^{-7},\\\\\nI(0) &= 6.25\\cdot10^{-7},\\\\\nR(0) &=0,\n\\end{align*}\non the interval $[0,100]$. \\label{prob_sir1}\n\\end{problem}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{SIR1.pdf}\n\\caption{Solution to Problem (\\ref{prob_sir1})}\n\\label{sir1}\n\\end{figure}\n\n\\begin{problem}\nSuppose that, in a city of approximately three million, five have recently entered the city carrying a certain disease.\n(Suppose they have just entered the infectious state.)\n\nEach of those individuals has a contact each day that could spread the disease, and an average of three days is spent in the infectious state.\nFind the solution of the corresponding SIR equations for the next fifty days.\n\n\nAt the peak of the infection, how many in the city will still be able to work? (Assume for simplicity that those who are in the infectious state either cannot go to work or are unproductive, etc.)\nAnswer the same question if instead of three days, an average of seven days is spent in the infectious state.\n\\end{problem}\n\n\n\\begin{problem}\nSuppose that, in a city of approximately three million, five have recently entered the city carrying a certain disease.\n(Suppose they have just entered the infectious state.)\n\nEach of those individuals will make three contacts every ten days that could spread the disease, and an average of four days is spent in the infectious state.\nFind the solution of the corresponding SIR equations.\nChoose an appropriate time interval and plot your results.\n\\end{problem}\n\n\\section*{Variations on the SIR Model}\n\nSIS Models describe diseases where individuals who have recovered from the disease do not gain\nany lasting immunity.\nThere are only two compartments in this model: those who are \\emph{susceptible}, and those who are \\emph{infectious}.\n\nThe basic equations are given by\n\\begin{align*}\n\\frac{dS}{dt} &=-\\beta I S + \\gamma I ,\\\\\n\\frac{dI}{dt} &= \\beta I S-\\gamma I\n\\end{align*}\n\nIf we add to our basic SIR model to account for the death rate and an equal birth rate, the equations become\n\\begin{align*}\n\\frac{dS}{dt} &=\\mu(1 -S) - \\beta I S,\\\\\n\\frac{dI}{dt} &= \\beta I S - (\\gamma + \\mu)I, \\\\\n\\frac{dR}{dt} &= \\gamma I - \\mu R\n\\end{align*}\n\nSIRS models take the previous model and allow the transfer of individuals from the recovered/removed class to rejoin the susceptible class.\n\\begin{align*}\n\\frac{dS}{dt} &= fR + \\mu(1 -S) - \\beta I S,\\\\\n\\frac{dI}{dt} &= \\beta I S - (\\gamma + \\mu)I, \\\\\n\\frac{dR}{dt} &= -fR + \\gamma I - \\mu R.\n\\end{align*}\n\nThe next exercise uses a variation of the basic SIR model to describe the spread of measles.\nIt assumes that the rate at which measles is contracted depends on the season, i.e. the rate is periodic.\nThat allows us to formulate the yearly occurrence rate for measles as a boundary value problem.\nTo solve this problem we will use a full-featured BVP solver that is available as a Python package.\nSeveral industrial-grade BVP solvers have been written in Fortran.\nOne of these, \\li{bvp_solver}, has been wrapped for Python and is available as a scikit.\nIf you have not installed it, you can install it by running the command \\li{pip install scikits.bvp_solver} in the command line.\nThe code below demonstrates how to use \\li{bvp_solver} to solve the BVP\n\\begin{align*}\n\t\\epsilon y'' + yy' - y &= 0, \\quad y(-1) = 1, \\quad y(1) = -1/3.\n\\end{align*}\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scikits import bvp_solver\nimport matplotlib.pyplot as plt\n\nepsilon, lbc, rbc = .1, 1., - 1. / 3.\n\ndef ode(x , y):\n    return np.array([y[1] , (1. / epsilon) * (y[0] - y[0] * y[1])])\n\n# The BVP solver package expects you to pass it the boundary\n# conditions as a callable function that computes the difference\n# between a guess at the boundary conditions\n# and the desired boundary conditions.\n# When we use the BVP solver, we will tell it how many constraints\n# there should be on each side of the domain so that it knows\n# how many entries to expect in the tuples BCa and BCb.\n# In this case, we have one boundary condition on either side.\n# These constraints are expected to evaluate to 0 when the\n# boundary condition is satisfied.\ndef bcs(ya, yb):\n    BCa = np.array([ya[0] - lbc])   # 1 Boundary condition on the left\n    BCb = np.array([yb[0] - rbc])   # 1 Boundary condition on the right\n    return BCa, BCb\n\nproblem = bvp_solver.ProblemDefinition(num_ODE=2,\n                                     num_parameters=0,\n                                     num_left_boundary_conditions=1,\n                                     boundary_points=(-1, 1),\n                                     function=ode,\n                                     boundary_conditions=bcs)\n\nsolution = bvp_solver.solve(problem, solution_guess=(- 1. / .3, - 4. / 3.))\n\nA = np.linspace(-1., 1., 200)\nT = solution(A)\nplt.plot(A, T[0,:], '-k', linewidth=2.)\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{measles.pdf}\n\\caption{Solution to Problem (\\ref{prob:sir_measles})}\n\\label{fig:sir4}\n\\end{figure}\n\n\\begin{problem}\nSEIR models are another variation of the basic SIR model.\nBasically they added another compartment, called the \\emph{exposed} or \\emph{latency} phase, to the basic compartments \\emph{susceptible}, \\emph{infectious}, and \\emph{recovered}.\n\nAn SEIR model is used to describe the spread of measles (see \\footnote{Numerical Solution of Boundary Value Problems for Ordinary Differential Equations, by Aescher, Mattheij, and Russell}).\nThe rate at which susceptible individuals may contract measles is seasonal, and corresponds to a periodic function $\\beta(t) = \\beta_0(1 + \\beta_1 \\cos{2\\pi t})$.\nParameters $\\mu$ and $\\lambda$ represent the birth rate of the population and the latency period of measles, respectively.\n$\\eta$ represents the infectious period before an individual moves from the infectious class to the recovered class.\nAfter recovery an individual remains immune.\nThe boundary value problem is given by\n\\begin{align*}\n\\left[\\begin{array}{c}S \\\\ E \\\\ I\\end{array}\\right]' &= \\left[\\begin{array}{c}\\mu - \\beta(t) S I \\\\\\beta(t) SI - E/\\lambda \\\\E/\\lambda - I/\\eta\\end{array}\\right],\\\\\nS(0) &= S(1),\\\\\nE(0) &= E(1),\\\\\nI(0) &= I(1)\n% \\left[\\begin{array}{c}S \\\\E \\\\I\\end{array}\\right](0) &= \\left[\\begin{array}{c}S \\\\E \\\\I\\end{array}\\right](1).\n\\end{align*}\nSolve this BVP with parameters $\\beta_1 = 1,$ $\\beta_0 = 1575,$ $\\eta = 0.01,$ $\\lambda = .0279,$ and $\\mu = .02.$\nNote: in this case, time is measured in years, so run the solution over the interval $\\left[0, 1\\right]$ to show a one-year cycle.\nThe boundary conditions are really just saying that the year will begin and end in the same state.\n\nHint: \\li{bvp_solver} requires \\emph{separated boundary conditions}.\nIn other words, each equation in the set of boundary conditions can only include values at one end of the interval.\nTo deal with this, let $C = [C_1, C_2, C_3]$, and add the equation\n\\[C' = 0\\]\nto the system of ODEs given above (for a total of 6 equations).\nThen the boundary conditions can be separated using the following trick:\n\\begin{align*}\n\t\\begin{pmatrix}C_1(0) \\\\C_2(0) \\\\ C_3(0) \\end{pmatrix} &= \\begin{pmatrix}S(0) \\\\E(0) \\\\ I(0) \\end{pmatrix}, \\quad \t\\begin{pmatrix}C_1(1) \\\\C_2(1) \\\\ C_3(1) \\end{pmatrix} = \\begin{pmatrix}S(1) \\\\E(1) \\\\ I(1) \\end{pmatrix}.\n\\end{align*}\nNow $C_1,C_2,C_3$ become the 4th, 5th, and 6th rows of your solution matrix, so the 3 boundary conditions for the left are obtained by subtracting the last three entries of $y(0)$ from the first three entries. Similarly, your right boundary conditions will look like $yb[0:3]-yb[3:]$.\n\n%This translates to 3 boundary conditions for the left and 3 for the right.  Now $C_1,C_2,C_3$ become the 4th, 5th, and 6th rows of your solution matrix.  \n%The formulae you will want to use for the boundary conditions can be formed by subtracting one side of these equations from the other. That is, subtract the last 3 entries of $y(a)$ from the %first 3 entries for the left boundary conditions, and similarly for the right.\nWhen you code your boundary conditions, note that \\li{bvp_solver} changes the initial conditions to force all the entries in the two arrays to be zero.\nYou can use the initial conditions from Fig.~\\ref{fig:sir4} as your initial guess (which will be an array of 6 elements). Remember that the initial infected proportion is small, not 0.\n\n\\label{prob:sir_measles}\n\\end{problem} ", "meta": {"hexsha": "2a6f7cb95af8c137588f77eecbccdc81666943a1", "size": 13845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/SIR/SIR.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/SIR/SIR.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/SIR/SIR.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": 51.2777777778, "max_line_length": 386, "alphanum_fraction": 0.7117370892, "num_tokens": 4039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6992544335934766, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.606278593119592}}
{"text": "% main.tex\n\\documentclass{report}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\graphicspath{{./figures/}}\n\\usepackage{subfigure}\n\\begin{document}\n\\chapter{Introduction}\\label{ch:intro}\nHello\n\\section{Euler}\\label{sec:euler}\n\\begin{equation}\\label{eq:euler}\ne^{i\\pi}+1=0\n\\end{equation}\nEquation~\\eqref{eq:euler} is a beauty.\n\n\\begin{equation}\\label{eq:einstein}\nE = mc^2 \\tag{*}\n\\end{equation}\nEquation~\\eqref{eq:einstein} is not bad either.\n\n\\begin{equation}\\label{eq:gaslaw}\nPV = nRT\n\\end{equation}\nEquation~\\eqref{eq:gaslaw} is a classic.\n\n\\begin{figure}[ht]\n\\centering\n\\subfigure[Union]{\\includegraphics[scale=0.25]{AcupB}\\label{fig:union}}\n\\subfigure[Intersection]{\\includegraphics[scale=0.25]{AcapB}\\label{fig:intersection}}\n\\subfigure[Complement]{\\includegraphics[scale=0.25]{Acomp}\\label{fig:complement}}\n\\caption{Three figures using \\texttt{subfigure}.\\label{fig:setops-subfig}}\n\\end{figure}\n\n\nGoodbye\n\\end{document}", "meta": {"hexsha": "c226285e786f70367c1913d48232aa6da14be23b", "size": 923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/test_misc/main.tex", "max_stars_repo_name": "imagingbook/latextree", "max_stars_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-16T22:41:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-16T22:41:21.000Z", "max_issues_repo_path": "tex/test_misc/main.tex", "max_issues_repo_name": "imagingbook/latextree", "max_issues_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_issues_repo_licenses": ["MIT"], "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_misc/main.tex", "max_forks_repo_name": "imagingbook/latextree", "max_forks_repo_head_hexsha": "272ee1594b3bdea39a043fb2ac2b86ac9a1728e8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-11T09:38:25.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-11T15:30:21.000Z", "avg_line_length": 25.6388888889, "max_line_length": 85, "alphanum_fraction": 0.7551462622, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624890918021, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6062373635323358}}
{"text": "\\chapter{Some applications}\nWith all this setup, we now take the time to develop some nice\nresults which are of independent interest.\n\n\\section{Frobenius divisibility}\n\\begin{theorem}\n\t[Frobenius divisibility]\n\tLet $V$ be a complex irrep of a finite group $G$.\n\tThen $\\dim V$ divides $|G|$.\n\\end{theorem}\nThe proof of this will require algebraic integers\n(developed in the algebraic number theory chapter).\nRecall that an \\emph{algebraic integer} is a complex number\nwhich is the root of a polynomial with integer coefficients,\nand that these algebraic integers form a ring $\\ol\\ZZ$\nunder addition and multiplication, and that $\\ol\\ZZ \\cap \\QQ = \\ZZ$.\n\nFirst, we prove:\n\\newcommand{\\tempuuujbhtkx}{$\\ZZ[G]$}\n\\begin{lemma}[Elements of \\tempuuujbhtkx\\ are integral]\n\t\\label{lem:group_ring_integral}\n\tLet $\\alpha \\in \\ZZ[G]$.\n\tThen there exists a monic polynomial $P$ with integer coefficients\n\tsuch that $P(\\alpha) = 0$.\n\\end{lemma}\n\\begin{proof}\n\tLet $A_k$ be the $\\ZZ$-span of $1, \\alpha^1, \\dots, \\alpha^k$.\n\tSince $\\ZZ[G]$ is Noetherian,\n\tthe inclusions $A_0 \\subseteq A_1 \\subseteq A_2 \\subseteq \\dots$\n\tcannot all be strict, hence $A_k = A_{k+1}$ for some $k$,\n\twhich means $\\alpha^{k+1}$ can be expressed in terms of\n\tlower powers of $\\alpha$.\n\\end{proof}\n\n\\begin{proof}\n\t[Proof of Frobenius divisibility]\n\tLet $C_1$, \\dots, $C_m$ denote the conjugacy classes of $G$.\n\tThen consider the rational number \\[ \\frac{|G|}{\\dim V}; \\]\n\twe will show it is an algebraic integer, which will prove the theorem.\n\tObserve that we can rewrite it as\n\t\\[\n\t\t\\frac{|G|}{\\dim V}\n\t\t= \\frac{|G| \\left< \\chi_V, \\chi_V \\right>}{\\dim V}\n\t\t= \\sum_{g \\in G} \\frac{\\chi_V(g) \\ol{\\chi_V(g)}}{\\dim V}.\n\t\\]\n\tWe split the sum over conjugacy classes, so\n\t\\[\n\t\t\\frac{|G|}{\\dim V}\n\t\t=\n\t\t\\sum_{i=1}^m \\ol{\\chi_V(C_i)} \\cdot \\frac{|C_i| \\chi_V(C_i)}{\\dim V}.\n\t\\]\n\tWe claim that for every $i$,\n\t\\[ \\frac{|C_i| \\chi_V(C_i)}{\\dim V}\n\t\t= \\frac{1}{\\dim V} \\Tr T_i \\]\n\tis an algebraic integer,\n\twhere \\[ T_i \\defeq \\rho\\left(\\sum_{h \\in C_i} h\\right). \\]\n\tTo see this, note that $T_i$ commutes with elements of $G$,\n\tand hence is an intertwining operator $T_i : V \\to V$.\n\tThus by Schur's lemma, $T_i = \\lambda_i \\cdot \\id_V$\n\tand $\\Tr T = \\lambda_i \\dim V$.\n\tBy \\Cref{lem:group_ring_integral}, $\\lambda_i \\in \\ol\\ZZ$, as desired.\n\t\n\tNow we are done, since $\\ol{\\chi_V(C_i)} \\in \\ol\\ZZ$ too\n\t(it is the sum of conjugates of roots of unity),\n\tso $\\frac{|G|}{\\dim V}$ is the sum of products of algebraic integers,\n\thence itself an algebraic integer.\n\\end{proof}\n\n\\section{Burnside's theorem}\nWe now prove a group-theoretic result.\nThis is the famous poster child for representation theory\n(in the same way that RSA is the poster child of number theory)\nbecause the result is purely group theoretic.\n\nRecall that a group is \\vocab{simple} if it has no normal subgroups.\nIn fact, we will prove:\n\\begin{theorem}[Burnside]\n\tLet $G$ be a nonabelian group of order $p^a q^b$ (where $p,q$ are distinct primes and $a,b \\ge 0$).\n\tThen $G$ is not simple.\n\\end{theorem}\nIn what follows $p$ and $q$ will always denote prime numbers.\n\n\\begin{lemma}[On $\\gcd(|C|, \\dim V) = 1$]\n\t\\label{lem:burnside_ant_lemma}\n\tLet $V = (V, \\rho)$ be an complex irrep of $G$.\n\tAssume $C$ is a conjugacy class of $G$ with $\\gcd(|C|, \\dim V) = 1$.\n\tThen for any $g \\in C$, either\n\t\\begin{itemize}\n\t\t\\ii $\\rho(g)$ is multiplication by a scalar, or\n\t\t\\ii $\\chi_V(g) = \\Tr \\rho(g) = 0$.\n\t\\end{itemize}\n\\end{lemma}\n\\begin{proof}\n\tIf $\\eps_i$ are the $n$ eigenvalues of $\\rho(g)$ (which are roots of unity),\n\tthen from the proof of Frobenius divisibility we know\n\t$\\frac{|C|}{n} \\chi_V(g) \\in \\ol\\ZZ$,\n\tthus from $\\gcd(|C|, n) = 1$ we get \n\t\\[ \\frac1n \\chi_V(g) = \\frac1n(\\eps_1 + \\dots + \\eps_n) \\in \\ol\\ZZ. \\]\n\tSo this follows readily from a fact from algebraic number theory,\n\tnamely \\Cref{prob:rep_lemma}:\n\teither $\\eps_1 = \\dots = \\eps_n$ (first case) or\n\t$\\eps_1 + \\dots + \\eps_n = 0$ (second case).\n\\end{proof}\n\n\\begin{lemma}\n\t[Simple groups don't have prime power conjugacy classes]\n\tLet $G$ be a finite simple group.\n\tThen $G$ cannot have a conjugacy class of order $p^k$ (where $k > 0$).\n\\end{lemma}\n\\begin{proof}\n\tBy contradiction.\n\tAssume $C$ is such a conjugacy class, and fix any $g \\in C$.\n\tBy the second orthogonality formula (\\Cref{prob:second_orthog})\n\tapplied $g$ and $1_G$ (which are not conjugate since $g \\neq 1_G$) we have\n\t\\[ \\sum_{i=1}^r \\dim V_i \\chi_{V_i}(g) = 0 \\]\n\twhere $V_i$ are as usual all irreps of $G$.\n\t\\begin{exercise}\n\t\tShow that there exists a nontrivial irrep $V$\n\t\tsuch that $p \\nmid \\dim V$ and $\\chi_V(g) \\neq 0$.\n\t\t(Proceed by contradiction to show that $-\\frac1p \\in \\ol\\ZZ$ if not.)\n\t\\end{exercise}\n\tLet $V = (V, \\rho)$ be the irrep mentioned.\n\tBy the previous lemma, we now know that $\\rho(g)$ acts as a scalar in $V$.\n\n\tNow consider the subgroup\n\t\\[ H = \\left< ab\\inv \\mid a,b \\in C \\right> \\subseteq G. \\]\n\tWe claim this is a nontrivial normal subgroup of $G$.\n\tIt is easy to check $H$ is normal,\n\tand since $|C| > 1$ we have that $H$ is nontrivial.\n\tAs represented by $V$ each element of $H$ acts trivially in $G$,\n\tso since $V$ is nontrivial and irreducible, $H \\neq G$.\n\tThis contradicts the assumption that $G$ was simple.\n\\end{proof}\n\nWith this lemma, Burnside's theorem follows by partitioning\nthe $|G|$ elements of our group into conjugacy classes.\nAssume for contradiction $G$ is simple.\nEach conjugacy class must have order either $1$ (of which there are $|Z(G)|$ by \\Cref{prob:class_eq})\nor divisible by $pq$ (by the previous lemma), but on the other hand the sum equals $|G| = p^aq^b$.\nConsequently, we must have $|Z(G)| > 1$.\nBut $G$ is not abelian, hence $Z(G) \\neq G$,\nthus the center $Z(G)$ is a nontrivial normal subgroup,\ncontradicting the assumption that $G$ was simple.\n\n\n\n\\section{Frobenius determinant}\nWe finish with the following result,\nthe problem that started the branch of representation theory.\nGiven a finite group $G$,\nwe create $n$ variables $\\{x_g\\}_{g \\in G}$,\nand an $n \\times n$ matrix $M_G$ whose $(g,h)$th entry is $x_{gh}$.\n\\begin{example}[Frobenius determinants]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\\ii If $G = \\Zc 2 = \\left< T \\mid T^2 = 1\\right>$\n\tthen the matrix would be \\[ M_G =\n\t\\begin{bmatrix} x_{\\id} & x_T \\\\ x_T & x_{\\id} \\end{bmatrix}. \\]\n\tThen $\\det M_G = (x_{\\id}-x_T)(x_{\\id}+x_T)$.\n\t\\ii If $G = S_3$, a long computation gives\n\tthe irreducible factorization of $\\det M_G$ is\n\t\\[\n\t\t\\left( \\sum_{\\sigma \\in S_3} x_{\\sigma} \\right)\n\t\t\\left( \\sum_{\\sigma \\in S_3} \\sign(\\sigma)x_\\sigma \\right)\n\t\t\\Big( F\\left(x_\\id, x_{(123)}, x_{(321)}\\right)\n\t\t- F\\left(x_{(12)}, x_{(23)}, x_{(31)}\\right) \\Big)^2 \\]\n\twhere $F(a,b,c) = a^2+b^2+c^2-ab-bc-ca$;\n\tthe latter factor is irreducible.\n\t\\end{enumerate}\n\\end{example}\n\\begin{theorem}\n\t[Frobenius determinant]\n\tThe polynomial $\\det M_G$ (in $|G|$ variables) factors\n\tinto a product of irreducible polynomials such that\n\t\\begin{enumerate}[(i)]\n\t\t\\ii The number of polynomials equals the number\n\t\tof conjugacy classes of $G$, and\n\t\t\\ii The multiplicity of each polynomial\n\t\tequals its degree.\n\t\\end{enumerate}\n\\end{theorem}\nYou may already be able to guess how the ``sum of squares'' result\nis related! (Indeed, look at $\\deg\\det M_G$.)\n\nLegend has it that Dedekind observed this behavior first in 1896.\nHe didn't know how to prove it in general,\nso he sent it in a letter to Frobenius,\nwho created representation theory to solve the problem.\n\nWith all the tools we've built, it is now fairly straightforward\nto prove the result.\n\n\\begin{proof}\n\tLet $V = (V, \\rho) = \\Reg(\\CC[G])$ and let $V_1$, \\dots, $V_r$\n\tbe the irreps of $G$.\n\tLet's consider the map $T \\colon \\CC[G] \\to \\CC[G]$\n\twhich has matrix $M_G$ in the usual basis of $\\CC[G]$, namely\n\t\\[ T : T(\\{x_g\\}_{g \\in G}) = \\sum_{g \\in G} x_g \\rho(g) \\in \\Mat(V). \\]\n\tThus we want to examine $\\det T$.\n\n\tBut we know that $V = \\bigoplus_{i=1}^r V_i^{\\oplus \\dim V_i}$\n\tas before, and so breaking down $T$ over its subspaces we know\n\t\\[\n\t\t\\det T\n\t\t= \\prod_{i=1}^r \\left( \\det (T \\restrict{V_i})  \\right)^{\\dim V_i}.\n\t\\]\n\tSo we only have to show two things:\n\tthe polynomials $\\det T_{V_i}$ are irreducible,\n\tand they are pairwise different for different $i$.\n\n\tLet $V_i = (V_i, \\rho)$, and pick $k = \\dim V_i$.\n\t\\begin{itemize}\n\t\t\\ii \\emph{Irreducible}:\n\t\tBy the density theorem, for any $M \\in \\Mat(V_i)$ there exists\n\t\ta \\emph{particular} choice of complex numbers $x_g \\in G$ such that\n\t\t\\[\n\t\t\tM = \\sum_{g \\in G} x_g\n\t\t\t\\cdot \\rho_i(g)\n\t\t\t= (T \\restrict{V_i})(\\{x_g\\}).\n\t\t\\]\n\t\tView $\\rho_i(g)$ as a $k \\times k$ matrix with complex coefficients.\n\t\tThus the ``generic'' $(T \\restrict{V_i})(\\{x_g\\})$, viewed as a matrix with\n\t\tpolynomial entries, must have linearly independent entries\n\t\t(or there would be some matrix in $\\Mat(V_i)$ that we can't achieve).\n\n\t\tThen, the assertion follows (by a linear variable change)\n\t\tfrom the simple fact that the polynomial\n\t\t$\\det (y_{ij})_{1 \\le i, j \\le m}$ in $m^2$ variables\n\t\tis always irreducible.\n\n\t\t\\ii \\emph{Pairwise distinct}:\n\t\tWe show that from $\\det T|_{V_i}(\\{x_g\\})$ we can read\n\t\toff the character $\\chi_{V_i}$, which proves the claim.\n\t\tIn fact\n\t\t\\begin{exercise}\n\t\t\tPick \\emph{any} basis for $V_i$.\n\t\t\tIf $\\dim V_i = k$, and $1_G \\neq g \\in G$, then\n\t\t\t\\[\n\t\t\t\t\\chi_{V_i} (g)\n\t\t\t\t\\text{ is the coefficient of } x_g x_{1_G}^{k-1}.\n\t\t\t\\]\n\t\t\\end{exercise}\n\t\tThus, we are done. \\qedhere\n\t\\end{itemize}\n\\end{proof}\n", "meta": {"hexsha": "0e1a02ed57047cde58b46f0293c2bc834ded5699", "size": 9381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/rep-theory/applications.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/applications.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/applications.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.1341463415, "max_line_length": 101, "alphanum_fraction": 0.6718899904, "num_tokens": 3270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.606237347533609}}
{"text": "\\subsection{Selection}\n\nThe selection operator describes the process by which individuals are chosen\nfrom the current population to generate the next. Almost always, the likelihood\nof an individual being selected is determined by their fitness. This is because\nthe purpose of selection is to preserve favourable qualities and encourage some\nhomogeneity within future generations~\\cite{Back1994}.\n\n\\inputtikz[.8\\imgwidth]{selection}{%\n    The selection process with the inclusion of some lucky individuals.\n}\n\\input{tex/algorithms/selection.tex}\n\nIn EDO, a modified truncation selection method is used~\\cite{Jebari2013}, as can\nbe seen in Figure~\\ref{fig:selection}. Truncation selection takes a fixed\nnumber, \\(n_b = \\lceil bN\\rceil\\), of the fittest individuals in a population\nand makes them the `parents' of the next. It has been observed that, despite\nits efficiency as a selection operator, truncation selection can lead to\npremature convergence at local optima~\\cite{Jebari2013, Tatsuya2002}. The\nmodification for EDO is an optional stage after the best individuals have been\nchosen: with some small \\(l\\), a number, \\(n_l = \\lceil lN\\rceil\\), of the\nremaining individuals can be selected at random to be carried forward. Hence,\nallowing for a small number of randomly selected individuals may encourage\ndiversity and further exploration throughout the run of the algorithm. It should\nbe noted that regardless of this step, an individual could potentially be\npresent throughout the entirety of the algorithm.\n\nAfter the parents have been selected, there are two adjustments made to the\ncurrent search space. The first is that the subtypes for each family in\n\\(\\mathcal{P}\\) are updated to only those present in the parents. The second\nadjustment is a process which acts on the distribution parameter limits for\neach subtype in \\(\\mathcal{P}\\). This adjustment gives the ability to `shrink'\nthe search space about the region observed in a given population. This method is\nbased on a power law described in~\\cite{Amirjanov2016} that relies on a shrink\nfactor, \\(s\\). At each iteration, \\(t\\), every distribution subtype which is\npresent in the parents has its parameter's limits, \\(\\left(l_t, u_t\\right)\\),\nadjusted. This adjustment is such that the new limits, \\(\\left(l_{t+1},\nu_{t+1}\\right)\\) are centred about the mean observed value, \\(\\mu\\), for that\nparameter:\n\\begin{align}\n    \\label{eq:shrinking_lower}\n    l_{t+1}&= \\max \\left\\{l_t, \\ \\mu - \\frac{1}{2} (u_t - l_t) s^t\\right\\}\\\\\n    \\label{eq:shrinking_upper}\n    u_{t+1}&= \\min \\left\\{u_t, \\ \\mu + \\frac{1}{2} (u_t - l_t) s^t\\right\\}\n\\end{align}\n\nThe shrinking process is given explicitly in\nAlgorithm~\\ref{algorithm:shrinking}. Note that the behaviour of this process can \nproduce reductive results for some use cases and is optional.\n\n\\input{tex/algorithms/shrinking.tex}\n", "meta": {"hexsha": "331193f8c998ba0f050bb61d069c7cd50f7fe074", "size": 2840, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/algorithm/selection.tex", "max_stars_repo_name": "daffidwilde/edo-paper", "max_stars_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_stars_repo_licenses": ["MIT"], "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/algorithm/selection.tex", "max_issues_repo_name": "daffidwilde/edo-paper", "max_issues_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_issues_repo_licenses": ["MIT"], "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/algorithm/selection.tex", "max_forks_repo_name": "daffidwilde/edo-paper", "max_forks_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_forks_repo_licenses": ["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.6153846154, "max_line_length": 81, "alphanum_fraction": 0.7700704225, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6062373434609436}}
{"text": "\n\\subsection{Latent variable models for genomics}\n\nWith the exponential growth in the use of high-throughput genomics, biological datasets are increasingly high dimensional, both in terms of samples and features. A key principle of biological datasets is that variation between the features results from differences in underlying, often unobserved, processes. Such processes, whether driven by biological or technical effects, are manifested by coordinated changes in multiple features. This key assumption sets off an entire statistical framework of exploiting the redundancy encoded in the data set to learn the (latent) sources of variation in an unsupervised fashion. This is the aim of dimensionality reduction techniques, or latent variable models \\cite{Komili2008, Stegle2012, Leek2007, Pournara2007, Dai2017, Genevieve2018, Meng2016}.\n\n\n\\subsubsection{Mathematical formulation}\n\nGiven a dataset $\\bfY$ of $N$ samples and $D$ features, latent variable models attempt to exploit the dependencies between the features by reducing the dimensionality of the data to a potentially small set of $K$ latent variables, also called factors. The mapping between the low-dimensional space and the high-dimensional space is performed via a function $f(\\bfX|\\bTheta)$ that depends on some parameters $\\bTheta$.\\\\\nThe choice of $f(\\bfX|\\bTheta)$ is essentially the field of dimensionality reduction. A trade-off exists between complexity and interpretation: while non-linear functions such as deep neural networks provide more explanatory power, this leads to considerable challenges in interpretation \\cite{Zhang2018_NN}. Hence, for most applications where interpretability is essential, $f(\\bfX|\\bTheta)$ is assumed to be linear:\n% \\begin{equation} \n% \ty_{nd} = \\sum_{k=1}^{K} w_{dk}z_{n,k}\n% \\end{equation}\n\\begin{equation} \\label{eq:linear_model}\n\t\\mathbf{Y} = \\mathbf{Z}\\mathbf{W}^{T}\n\\end{equation}\nwhere $\\bfZ \\in \\R^{N \\times K}$ is a matrix that contains the low-dimensional representation for each sample (i.e. the factors). The matrix $\\bfW \\in \\R^{D \\times K}$ contains the weights, which provide the linear mapping between the features and the factors.\\\\\nNote that the aim of dimensionality reduction is to exploit the coordinated heterogeneity between features, and hence features can be assumed to be centered without loss of generality.\n\nThe inference procedure consists in learning the values of all unobserved variables, including factors and weights. As we shall demonstrate, different inference schemes and assumptions on the prior distributions lead to significantly different model outputs \\cite{Rattray2009}.\n\n\n\\subsection{Principal Component Analysis} \\label{section:pca}\n\nPrincipal Component Analysis (PCA) is the most popular technique for dimensionality reduction \\cite{Hotelling1933,Ringner2008}.Two formulations of PCA exist \\cite{Bishop2006}: in the maximum variance formulation, the aim is to infer an orthogonal projection of the data onto a low-dimensional space such that variance explained by the projected data is maximised. Formally, the aim in PCA is to infer the matrix $\\bfW$ such that the variance of $\\bfZ$ (the projected data) is maximised. If we consider a single latent factor, the variance of the projected data is:\n\\begin{equation*}\n\t\\sigma^2 = \\frac{1}{N}\\sum_{n=1}^{N} (\\bfz_n - \\hat{\\bfz})^{2} = \\frac{1}{N}\\sum_{n=1}^{N} (\\bfy_n^T \\bfw - \\hat{\\bfy}^T\\bfw)^{2}\n\\end{equation*}\n\nwhere $\\hat{\\bfy}$ is a vector with the feature-wise means. If we assumed centered data this simplifies to:\n\\begin{equation*}\n\t\\sigma^2 = \\frac{1}{N}\\sum_{n=1}^{N} (\\bfy_n^T \\bfw)^{2}\n\\end{equation*}\nSome algebra allows us to define this equation in terms of the (centered) data covariance matrix: $\\bfS = \\frac{1}{N}\\sum_{n=1}^{N} \\bfy_n\\bfy_n^T$:\n\\begin{align*}\n\t\\sigma^2 &= \\frac{1}{N}\\sum_{n=1}^{N} (\\bfy_n^T \\bfw)^T (\\bfy_n^T \\bfw) \\\\\n\t=& (\\bfw^T \\bfy_n) (\\bfy_n^T \\bfw) \\\\\n\t=& \\bfw^T (\\bfy_n \\bfy_n^T) \\bfw \\\\\n\t=& \\bfw^T \\bfS \\bfw\n\\end{align*}\n\nThus, for a single principal component, the optimisation problem is:\n\\begin{equation} \\label{eq:pca}\n\t%\\argmax_{\\|\\bfw\\|=1} & \\sum_{n=1}^{N} (\\bfw_1^T \\bfy_n)^2 = \\\\\n\t\\argmax_{\\|\\bfw\\|=1} = \\bfw^T \\bfS \\bfw\n\\end{equation}\n\n% where $\\bfY^T \\bfY=\\bfS \\in \\R^{D \\times D}$ is the data covariance matrix and $\\bfw_1^T$ is the vector of weights. \\\\\nThe $k$-th principal component can be found by subtracting from $\\bfY$ the reconstructed data by the previous $k-1$ principal components. If we define $\\bfz_k=\\bfw_k^T \\bfY$ to be the $k$-th principal component:\n\\[\n\t\\hat{\\bfY} = \\bfY - \\sum_{k=1}^{K} (\\bfz_k \\bfw_k^T)\n\\]\nRe-applying \\Cref{eq:pca} defines the new optimisation problem.\n\nIn its minimum error formulation, the aim is to find an equivalent projection that minimises the mean squared error between the observations and the data reconstructed using the principal components:\n\\[\n\t\\argmax_{\\|\\bfw\\|=1} \\Vert \\bfY - \\sum_{k=1}^{K} (\\bfz_k \\bfw_k^T) \\Vert^{2}\n\\]\nwhere $\\Vert \\cdot \\Vert^{2}$ is the Frobenius norm.\n\nRemarkably, in both cases, solving the optimisation problems via Lagrange multipliers leads to master eigenvalue-eigenvector equation:\n\\begin{equation}\n\t\\bfS \\bfw_k = \\lambda_k \\bfw_k\n\\end{equation}\nwhere the weight vectors $\\bfw_k$ can be calculated as the eigenvectors of the covariance matrix $\\bfS$ \\cite{Bishop2006}.\n\nInterestingly, the reason why the maximum variance solution and the minimum reconstruction error solution are the same can be understood by applying Pythagoras theorem to the right triangle defined by the projection of a sample $\\bfy_{n}$ to a weight vector $\\bfw$ (\\Cref{fig:pca2}).\nAssuming again centered data, the variance of $\\bfy_{n}$ is $\\|\\bfy_{n}\\| = \\bfy_{n}^T \\bfy_{n}$. This variance decomposes as the sum of the variance in the latent space $\\|\\bfz_{n}\\| = \\bfz_{n}^T \\bfz_{n}$ and the residual variance after reconstruction $\\|\\bfy_{n} - \\bfz_{n} \\bfw^T \\|$:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.8\\linewidth]{pca2}\n\t\\caption[Maximizing the variance in the principal component space is equivalent to minimizing the data reconstruction error]{In the maximum variance formulation the aim is to maximise the variance of the projected data (blue line), whereas in the minimum error formulation the aim is to minimise the residual variance (red line). Given a fixed total variance (black line), both strategies are equivalent}\n\t\\label{fig:pca2}\n\\end{figure}\n\nThe main strength of PCA relies on its simplicity and closed form solution. Additionally, the linear mapping has the advantage of yielding interpretable feature weights, so that inspection of $\\bfw_k$ reveals which features are jointly affected by the $k$-th principal component.\\\\\nHowever, PCA suffers from serious drawbacks when applying it to real datasets \\cite{Li2017b}. First, biological measurements are inherently noisy, and there is no explicit account of noise in PCA. In practice, high variance components are often asociated with signal whereas low-variance components are assumed to be noise, but an ideal model should explicitly disentangle the uncoordinated variability that is attributed to noise from the coordinated variability that is characterised as signal. Second, in its original formulation, no missing data is allowed \\cite{Ilin2010}. Third, it does not offer a principled way of modelling prior information about the data.\n\n\\subsection{Probabilistic Principal Component Analysis and Factor Analysis} \\label{section:probabilistic_pca}\nA probabilistic version of PCA was initially proposed in \\cite{Tipping1999}. It can be formulated by converting some (or all) fixed parameters into random variables and adding an explicit noise term to \\Cref{eq:linear_model}:\n\\begin{equation}\n\\mathbf{Y} = \\mathbf{Z}\\mathbf{W}^{T}  + \\bepsilon\n\\end{equation}\nwhere the weights $\\bfW$ are assumed to be non-probabilistic parameters, but the noise $\\bepsilon$ and the latent variables $\\bfZ$ (the principal components) are assumed to follow an isotropic normal distribution:\n\\begin{align*}\n\tp(\\bfZ) &= \\prod_{n=1}^{N} \\prod_{k=1}^{K} \\Ndist{z_{nk}}{0,1} \\\\\n\tp(\\epsilon) &= \\Ndist {\\epsilon}{0,\\tau^{-1}}\n\\end{align*}\nwhere $\\tau$ is the precision (inverse of the variance).\n%The alternative strategy of treating $\\bfZ$ as random variables and $\\bfW$ as parameters has also been explored \\cite{Lawrence2005}.\\\\\n\nAll together, this leads to a Gaussian likelihood:\n\\begin{equation} \\label{eq:ppca_lik}\n\t% p(\\bfY|\\bfW,\\bfZ,\\sigma) = \\Ndist{\\bfY}{\\bfW \\bfZ,\\sigma^2 \\I}\n\tp(\\bfY|\\bfZ,\\bfW,\\tau) = \\prod_{n=1}^{N} \\prod_{d=1}^{D} \\Ndist{y_{n,d}}{\\bfz_{n,:} \\bfw_{,:k},\\tau^{-1} \\I}\n\\end{equation}\n\nThe corresponding graphical model is:\n\\begin{figure}[H]\n\t\\centering\n\t\\input{graphical_models/pPCA}\n\t\\caption{\\textbf{Graphical model for probabilistic PCA}. The latent variables are modelled as random variables, whereas the weights and the noise are modelled as deterministic parameters.}\n\t\\label{fig:pPCA}\n\\end{figure}\n\nImportantly, the choice of the distribution for $\\epsilon$ implies that the noise of each feature is independent but restricted to have the same precision $\\tau$. In practice this is a limiting assumption, as different features are expected to show different degrees of noise, albeit this constraint can be relaxed and forms the basis of Factor Analysis \\cite{Rubin1982,Bishop2006}.\n\nThe inference procedures involves learning the parameters $\\bfW$, and $\\tau$ and a posterior probability distribution for $\\bfZ$. As the model depends on latent variables, inference can be performed using the iterative Expectation-Maximisation (EM) algorithm \\cite{Rubin1982,Bishop2006}. In the expectation step, the posterior distribution for $\\bfZ$ is computed in closed form (due to conjugacy between the likelihood and the prior), given current estimates for the parameters $\\bfW$, and $\\tau$. In the maximisation step, the parameters are calculated by maximising the expectation of the joint log likelihood under the posterior distribution of $\\bfZ$ found in the E step \\cite{Tipping1999}.\\\\\nInterestingly, the EM solution of probabilistic PCA lies in the same subspace as the traditional PCA solution \\cite{Tipping1999}, but the use of a probabilistic framework brings several benefits. First, model selection can be performed by comparing likelihoods across different settings of parameters. Second, missing data can naturally be accounted for by ignoring the missing observations from the likelihood. Finally, the probabilistic formulation sets the core framework for a Bayesian treatment of PCA, enabling a broad range of principled extensions tailored different types of datasets.\n\n\n\\subsection{Bayesian Principal Component Analysis and Bayesian Factor Analysis} \\label{section:bayesian_pca}\n\nThe full Bayesian treatment of PCA requires the specification of prior probability distributions for all unobserved variables:\n\\begin{align*}\n\tp(\\bfZ) &= \\prod_{n=1}^{N} \\prod_{k=1}^{K} \\Ndist{z_{nk}}{0,1} \\\\\n\tp(\\bfW) &= \\prod_{d=1}^{D} \\prod_{k=1}^{K} \\Ndist{w_{dk}}{0,1} \\\\\n\tp(\\epsilon) &= \\Ndist {\\epsilon}{0,\\tau^{-1}} \\\\\n\tp(\\tau) &= \\Gdist{\\tau}{a_0,b_0}\n\\end{align*}\nA generalisation to Bayesian Factor Analysis follows by allowing a separate noise term per feature:\n\\begin{align*}\n\tp(\\bepsilon) &= \\prod_{d=1}^{D} \\Ndist {\\epsilon_d}{0,\\tau_d^{-1}} \\\\\n\tp(\\btau) &= \\prod_{d=1}^{D} \\Gdist{\\tau_d}{a_0,b_0}\n\\end{align*}\nwhere $a_0$ and $b_0$ are fixed hyperparameters. As in \\Cref{eq:ppca_lik}, this results in a Normal likelihood:\n\\[\n\tp(\\bfY|\\bfW,\\bfZ,\\btau) = \\prod_{n=1}^{N} \\prod_{d=1}^{D} \\Ndist{y_{nd}}{\\bfw_{d}^T \\bfz_{n},\\tau_d}\n\\]\n\nThe corresponding graphical model is:\n\n\\begin{figure}[H] \n\t\\centering\n\t\\input{graphical_models/bayesianFA}\n\t\\caption{\\textbf{Graphical model for Bayesian Factor Analysis}. All unobserved variables are modelled as random variables.}\n\t\\label{fig:bayesianFA}\n\\end{figure}\n\n\n\\subsection{Hierarchical priors}  \\label{section:hierarchical_priors}\n\nA key advantage of the full Bayesian treatment is that it explicitly captures uncertainity on the estimation of all unobserved variables, as opposed to the probabilistic PCA model \\cite{Bishop1999a,Bishop1999b}. Yet, more importantly, the use of (hierarchical) prior distributions allow different modelling assumptions to be encoded, providing a flexible and principled approach to extend PCA to a myriad of modelling scenarios, including multi-view generalisations \\cite{Klami2008,Virtanen2012,Klami2015,Bunte2016,Khan2014,Zhao2016}.\n\n\\subsubsection{Automatic relevance determination} \\label{section:ard}\n\n\nAs an example, a major challenge in PCA is how to determine the dimensionality of the latent space (i.e. the number of principal components). As we will show, the use of hierarchical prior distributions allows the model to introduce sparsity assumptions on the weights in such a way that the model automatically learns the number of factors.\\\\\nIn the context of Factor Analysis, one of the first sparsity priors to be proposed was the Automatic Relevance determination (ARD) prior \\cite{Neal1995,Mackay1996,Bishop1999a,Bishop1999b}. \n\\begin{equation*} \\label{eq:ard}\n\tp(\\bfW|\\balpha) = \\prod_{k=1}^{K} \\Ndist{\\bfw_{:,k}}{0,\\frac{1}{\\alpha_{k}}\\I_{D}} \\\\\n\t\\qquad\\qquad\n\tp(\\balpha) = \\prod_{k=1}^{K} \\Gdist{\\alpha_k}{a_0^\\alpha, b_0^\\alpha}\n\\end{equation*}\nThe aim of this prior is two-fold. First, the zero-mean normal distribution specifies that, \\textit{a priori}, no information is available and all features are \\textit{inactive}. When exposed to some data, the posterior distribution for $\\bfW$ will be estimated by weighting the contribution from the likelihood, potentially allowing features to escape from the zero-centered prior (\\Cref{fig:ard}).\\\\\nSecond, performing inference on the variable $\\balpha = \\{ \\alpha_1, \\cdots, \\alpha_k \\}$ enables the model to discard inactive factors. To understand this, let us assume that only $K=5$ true factors exist, but the model is initialised with $K=20$ factors. In such case, inactive factors can be prunned out by driving the corresponding $\\alpha_k$ to infinity. In turn, this causes the posterior $p(\\bfw_{:,k}|\\bfY)$ to be sharply peaked at zero, resulting in the inactivation of all its weights. %\\Cref{fig:hinton}.\n\n\\begin{figure}[H] \\begin{center}\n\t\\includegraphics[width=0.7\\textwidth]{Chapter2/Figs/ard}\n\t\\caption{Visualisation of the sparsity-inducing Automatic Relevance Determination prior}\n\t\\label{fig:ard}\n\\end{center} \\end{figure}\n\n% \\begin{figure}[H] \\begin{center}\n% \t\\includegraphics[width=0.8\\textwidth]{Chapter2/Figs/hinton}\n%             \\caption[Hinton plot of the weight matrix for a Bayesian Factor Analysis model with an ARD prior]{Hinton plots display the values of the weight matrix, similar to a heatmap, where bigger squares depict larger weights. Shown are the Hinton plots for (a) the true weights, (b) the infered weights by a Factor Analysis model with no ARD prior (middle), and (c) the infered weights by a Factor Analysis model with ARD prior per factor. This figure was generated using simulated data with $N=100$ samples, $D=10$ features and $K=3$ factors.}\n% \t\\label{fig:hinton}\n% \\end{center} \\end{figure}\n\n\\subsubsection{Spike-and-slab prior} \\label{section_spikeslab}\n\nSparse extensions of the Bayesian factor analysis model have been proposed as a regularisation mechanism but also to model inherent assumptions regarding the sparse nature of biological data \\cite{Stegle2012,Gao2013}.\\\\\nThe variability observed in biological data is driven both by technical factors and biological factors. Technical factors (i.e. batch effects) tend to be relatively strong and alter the expression of a large proportion of genes, whereas the biological factors are potentially weak effects driven by changes in small gene regulatory networks \\cite{Gao2013}. Hence, a practical factor analysis model should be able to learn factors with different degrees of sparsity.\\\\\nThe ARD prior proposed in \\Cref{eq:ard} allows entire factors to be dropped out from the model, but it provides a weak degree of regularisation when it comes to inactivating individual weights within the active factors.\n\nA sparse generalisation of the Factor Analysis model proposed above can be achieved by combining the ARD prior with a spike-and-slab prior \\cite{Mitchell1988,Titsias2011}. For every weight $w_{d,k}$:\n\\begin{align}\n\tp(w_{d,k} \\mid \\alpha_k,\\theta_k) &= (1-\\theta_k) \\mathds{1}_0(w_{d,k}) + \\theta_k \\Ndist{w_{d,k}}{0, \\alpha_k^{-1}} \\\\\n\tp(\\theta_k) &= \\Bdist{\\theta_k}{a_0^\\theta,b_0^\\theta} \\\\\n\tp(\\alpha_k) &= \\Gdist{\\alpha_k}{a_0^\\alpha, b_0^\\alpha}\n\\end{align}\n\nThe corresponding graphical model is:\n\n\\begin{figure}[H] \\begin{center}\n\t\\input{graphical_models/bayesian_sparseFA}\n\t\\label{fig:bayesianFA}\n\t\\caption{\\textbf{Graphical model for Bayesian sparse Factor Analysis}. A double sparsity-inducing prior is used on the weights: an ARD prior to prune inactive factors and a spike-and-slab prior to inactive individual features within the active factors.}\n\\end{center} \\end{figure}\n\nThe spike-and-slab prior is effectively a mixture model where features are sampled from a zero-inflated Gaussian distribution, where $\\theta_k \\in (0,1)$ dictates the level of sparsity per factor (i.e. how many active features). A value of $\\theta_k$ close to $0$ implies that most of the weights of factor $k$ are shrunk to $0$ (i.e. a sparse factor), whereas a value of $\\theta_k$ close to $1$ implies that most of the weights are non-zero (i.e. dense factors). By learning $\\theta_k$ from the data, the model naturally accounts for combinations of sparse and dense factors.\n\n\n\\subsection{Multi-view factor analysis models}\n\nProbabilistic PCA and Factor Analysis perform dimensionality reduction from a single input matrix. In some occasions data is collected from multiple data sources that exibit heterogeneous statistical properties, resulting in a structured data set where features are naturally partitioned into views \\cite{Xu2013,Li2016,Zeng2018}. A clear biological example is multi-omics data, where, for the same set of samples, multiple molecular layers are profiled. Each of the data modalities can be analysed separately using conventional (single-view) methods, but in the ideal strategy a single model should be used to leverage information across all molecular layers using a flexible and principled approach. This is referred to as the multi-view learning problem \\cite{Xu2013,Li2016}.\\\\\nA tempting approach to circumvent the multi-view learning problem is to simply concatenate all datasets before applying conventional (single-view) latent variable models \\cite{Ritchie2015}. However, this is prone to fail for several reasons. First, heterogeneous data modalities cannot always be modelled using the same likelihood function. For example, continuous measurements are often modelled using a normal distribution, but binary and count-based traits are not appropriately modelled by this distribution \\cite{Pilling2018}. Second, even if all views are modelled with the same likelihood, differences in the scale and the magnitude of the variance can lead to some views being overrepresented in the latent space. Finally, in a multi-view data set we expect multiple sources of variation, some driven by a single view, whereas others could capture shared variability across multiple views. In other words, from a structured input space, one can also expect a structured latent representation. Not taking this behaviour into account can lead to challenges in the interpretability of the latent space.\n\nA comprehensive review of multi-view machine learning methods can be found in \\cite{Xu2013} and a more genomics-oriented perspective in \\cite{Ritchie2015}. For the purpose of this thesis, I will describe only the use of latent variable models for multi-view data integration.\n\n\\subsection{Canonical Correlation Analysis} \\label{cca}\n\nCanonical Correlation Analysis (CCA) is a simple extension of PCA to find linear components that capture correlations between two datasets \\cite{Hotteling1936,Hardle2007}.\\\\\nGiven two data matrices $\\bfY_1 \\in \\R^{N \\times D_1}$ and $\\bfY_2 \\in \\R^{N \\times D_2}$ CCA finds a set of linear combinations $\\bfU \\in \\R^{D_1 \\times K}$ and $\\bfV \\in \\R^{D_2 \\times K}$ with maximal cross-correlation.\nFor the first pair of canonical variables, the optimisation problem is:\n\\[\n\t(\\hat{\\bfu_1}, \\hat{\\bfv_1}) = \\argmax_{\\bfu_1,\\bfv_1} corr(\\bfu_{1}^T \\bfY_1, \\bfv_{1}^T \\bfY_2)\n\\]\nAs in conventional PCA, the linear components are constraint to be orthogonal. Hence, the first pair of canonical variables $\\bfu_1$ and $\\bfv_1$ contain the linear combination of variables that have maximal correlation. Subsequently, the second pair of canonical variables $\\bfu_2$ and $\\bfv_2$ is found from the residuals of the first canonical variables.\n\nGiven the similarity with PCA, both methods share statistical properties, including the linear mapping between the low-dimensional space and the high-dimensional space, and the closed-form solution using singular value decomposition \\cite{Hotteling1936,Hardle2007}.\\\\\nBecause of its simplicity and efficient computation, CCA has widespread use as a dimensionality reduction technique \\cite{Hardle2007}. Yet, as expected, CCA suffers from the same pitfalls as PCA: difficulties in selecting the number of components, lack of sparsity in the solutions and absence of probabilistic formulation. In addition, CCA have been shown to overfit for datasets where $D>>N$ \\cite{McCabe2018,Guo2016}. Hence, probabilistic versions with sparsity assumptions that reduce overfitting and improve interpretability followed.\n\n\n\\subsubsection{Probabilistic Canonical Correlation Analysis} \\label{section_probabilisticCCA}\n\nFollowing the derivation of probabilistic PCA \\cite{Tipping1999}, a similar effort enabled a probabilistic formulation of CCA as a generative model \\cite{Bach2005}.\\\\\nIn this model, the two matrix of observations $\\bfY^{1}$ and $\\bfY^{2}$ are decomposed in terms of two weight matrices $\\bfW^{1}$ and $\\bfW^{2}$ but a joint latent matrix $\\bfZ$:\n\\begin{align*}\n\t\\bfY^{1} &= \\bfW^{1} \\bfZ + \\epsilon^{1} \\\\\n\t\\bfY^{2} &= \\bfW^{2} \\bfZ + \\epsilon^{2}\n\\end{align*}\nWith the following prior probability distributions:\n\\begin{align*}\n\tp(z_{nk}) &= \\Ndist{z_{nk}}{0,1} \\\\\n\tp(\\epsilon^{1}) &= \\Ndist {\\epsilon^{1}}{0,\\tau_{1}^{-1}} \\\\\n\tp(\\epsilon^{2}) &= \\Ndist {\\epsilon^{2}}{0,\\tau_{2}^{-1}}\n\\end{align*}\nAs in \\cite{Tipping1999}, the weights and the variance of the noise are assumed to be non-probabilistic parameters, whereas the factors are probabilistic unobserved variables. This yields the following likelihood functions:\n\\begin{align} \\label{eq:probabilistic_cca_likelihood}\n\tp(\\bfY^{1}|\\bfW^{1},\\bfZ,\\tau_{1}) &= \\prod_{n=1}^{N} \\prod_{d=1}^{D_1} \\Ndist{y^{1}_{n,d}}{(\\bfw_{:,k}^{1})^T \\bfz_{n},\\tau_{1}^{-1}} \\\\\n\tp(\\bfY^{2}|\\bfW^{2},\\bfZ,\\tau_{2}) &= \\prod_{n=1}^{N} \\prod_{d=1}^{D_2} \\Ndist{y^{2}_{n,d}}{(\\bfw_{:,k}^{2})^T \\bfz_{n},\\tau_{2}^{-1}} \\nonumber\n\\end{align}\n\nThe corresponding graphical model is:\n\\begin{figure}[H] \\begin{center}\n\t\\input{graphical_models/CCA}\n\t\\label{fig:graphical_CCA}\n\t\\caption{Graphical model for probabilistic Canonical Correlation Analysis}\n\\end{center} \\end{figure}\n\nNotice that the observations for both datasets are generated from the same set of latent variables $\\bfZ$. This ensures that the model is focused on capturing the variation associated with cross-correlated groups of features.\n\nAnalogously to probabilistic PCA, the expected value of the posterior distribution $p(\\bfZ|\\bfY^{1},\\bfY^{2})$ span the same subspace as standard CCA \\cite{Bach2005}. Nonetheless, one of the many advantage of a probabilistic formulation is that it enables a broad range of principled extensions into larger graphical models.\n\n\n\\subsubsection{Bayesian Canonical Correlation Analysis} \\label{section:bayesian_cca}\n\nA fully Bayesian treatment of CCA followed based on exactly the same principle presented in \\Cref{section:bayesian_pca} by introducing prior distributions to all unobserved variables \\cite{Wang2007,Klami2013}:\n\\begin{align*} \n\tp(\\bfZ) &= \\prod_{n=1}^{N} \\prod_{k=1}^{K} \\Ndist{z_{nk}}{0,1} \\\\\n\tp(\\epsilon^{1}) &= \\Ndist {\\epsilon^{1}}{\\sigma_{1}^{2}} \\\\\n\tp(\\epsilon^{2}) &= \\Ndist {\\epsilon^{2}}{\\sigma_{2}^{2}} \\\\\n\tp(\\bfW^1|\\balpha) &= \\prod_{k=1}^{K} \\Ndist{\\bfw^{1}_{:,k}}{0,\\frac{1}{\\alpha_{k}}\\I_{D_1}} \\\\\n\tp(\\bfW^2|\\balpha) &= \\prod_{k=1}^{K} \\Ndist{\\bfw^{2}_{:,k}}{0,\\frac{1}{\\alpha_{k}}\\I_{D_2}} \\\\\n\tp(\\balpha) &= \\prod_{k=1}^{K} \\Gdist{\\alpha_k}{a_0^\\alpha, b_0^\\alpha}\n\\end{align*}\nResulting in the same likelihood model as in \\Cref{eq:probabilistic_cca_likelihood}. Yet, notice that an ARD is introduced per factor, allowing an automatic inference of the dimensionality in the latent subspace.\nAlso, there is some flexibility in the definition of noise. Whereas an independent noise term can be defined per view, one can also model correlated noise by introducing a multivariate Gaussian distribution with full-rank covariance \\cite{Wang2007,Klami2013}.\n\nThe corresponding graphical model is:\n\\begin{figure}[H] \\begin{center}\n\t\\input{graphical_models/bayesianCCA}\n\t\\label{fig:graphical_bayesianCCA}\n\t\\caption{Graphical model for Bayesian Canonical Correlation Analysis}\n\\end{center} \\end{figure}\n\nAs expected, the sparsity priors yield a more sparse solution than traditional CCA, which is more appropriate for biological data analysis. However, this solution is still limited to $M=2$ views, which leads us to the next model extension.\n\n% (\\Cref{fig:hinton_cca}):\n% \\begin{figure}[H]\n% \t\\centering\n% \t\\includegraphics[width=0.85\\linewidth]{hinton_cca}\n% \t\\caption{Comparison of the Hinton's diagram of $\\bfW^{1}$ and $\\bfW^{2}$ for the maximum likelihood CCA model (two left plots) and the variational Bayes CCA model (two right plots). Reprinted from \\cite{Wang2007} with modifications.}\n% \t\\label{fig:hinton_cca}\n% \\end{figure}\n\n\n\\subsection{Group Factor Analysis} \\label{section:gfa}\n\nGroup Factor Analysis (GFA) is the natural generalisation of Bayesian Canonical Correlation Analysis to an arbitrary number of views.\nThe original idea was originally presented in \\cite{Virtanen2012} and a series of generalisations followed, tailored with specific assumptions for different applications \\cite{Klami2015,Leppaaho2017,Bunte2016,Khan2014,Zhao2016,Remes2015}. In this section we will outline the core principle of GFA.\n\nGiven a data set of $M$ views $\\bfY_1, \\cdots, \\bfY_M$, the task of GFA is to find $K$ factors that capture the variability \\textit{within} as well as the variability \\textit{between} views. In other words, we want to capture factors that not only explain variance that is shared across all views but we also want to capture factors that explain variance within a single view or between different subsets of views.\\\\\nThe starting point is to generalise the Bayesian CCA model (\\Cref{section:bayesian_cca}) to $M$ views:\n\\begin{align*}\n\t\\bfY^{1} &= \\bfW^{2} \\bfZ + \\epsilon^{1} \\\\\n\t\\bfY^{2} &= \\bfW^{2} \\bfZ + \\epsilon^{2} \\\\\n\t& \\cdots \\\\\n\t\\bfY^{M} &= \\bfW^{M} \\bfZ + \\epsilon^{M}\n\\end{align*}\nNotice that there is a common factor space for all views, but there is a view-specific weight matrix. The key to disentangle the activity of each factor in each view lies on the sparsity structure imposed in the weights. Intuitively, if a factor $k$ is not driving any variation in a specific view $m$ we want all the individual weights to be pushed to zero. As shown before, this behaviour can be achieved using Automatic Relevance Determination (ARD) priors. However, if we were to use the same approach as in Bayesian CCA, where the ARD prior for factor $k$ is shared across all views, then factors would be restricted to have the same activity across all views.\\\\\nIn GFA this is generalised as follows:\n\\begin{align}\n\tp(\\bfW) &= \\prod_{m=1}^{M} \\prod_{k=1}^{K} \\Ndist{\\bfw_{:,k}^m}{0,\\frac{1}{\\alpha_k^m}} \\\\\n\tp(\\balpha) &= \\prod_{m=1}^{M} \\prod_{k=1}^{K} \\Gdist{\\alpha_k^m}{a_0^\\alpha, b_0^\\alpha}\n\\end{align}\nThis is effectively setting an ARD prior per factor $k$ and view $m$. The matrix $\\balpha \\in \\R^{M \\times K}$ defines four types of factors: (1) Inactive factors that do not explain variance in any view, which corresponds to all values $\\balpha_k$ being large. (2) Fully shared factors that explain variance across all views, which corresponds to all values $\\balpha_k$ being small. (3) Unique factors that explain variance in a single view, which corresponds to all values $\\balpha_k$ being large, except for one entry. (4) Partially shared factors that explain variance in a subsets views, which corresponds to a mixture of small and large values for $\\balpha_k$.\\\\\n\nThe corresponding graphical model is:\n\n\\begin{figure}[H] \\begin{center}\n\t\\input{graphical_models/GFA}\n\t\\label{fig:graphical_GFA}\n\t\\caption{Graphical model for Bayesian Group Factor Analysis}\n\\end{center} \\end{figure}\n\n\nFinally, notice that if $M=1$ the model reduces to Bayesian PCA (\\Cref{section:bayesian_pca}), but when $M=2$ the model does \\textit{not} reduce to Bayesian CCA because in the GFA setting factors are also allowed to capture both inter-specific variability (i.e. across views) and intra-specific variability (within a view). In Bayesian CCA, the views share a common ARD prior per factor to enforce the factors to explain variation in both views, at the expense of ignoring sources of variability that are specific to a single view.\n", "meta": {"hexsha": "fc015f0130e9247a1c8386c32eb9f0266b5e281b", "size": 29358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/factor_analysis.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/factor_analysis.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/factor_analysis.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": 94.3987138264, "max_line_length": 1107, "alphanum_fraction": 0.7627222563, "num_tokens": 7918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6061353379548694}}
{"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{\\fromlectures}{{\\\\ \\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\\newcommand{\\rtp}{{\\\\ \\color{blue} \\hspace*{\\fill}(required to prove)} \\\\}\n\n\\newcommand{\\f}[1]{o_{#1}x_{#1}y_{#1}z_{#1}}\n\\newcommand{\\rx}[1]{\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & cos(#1) & -sin(#1) & 0 \\\\ 0 & sin(#1) & cos(#1) & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\rz}[1]{\\begin{bmatrix} cos(#1) & -sin(#1) & 0 & 0 \\\\ sin(#1) & cos(#1) & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\iden}{\\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\\newcommand{\\trans}[3]{\\begin{bmatrix} 1 & 0 & 0 & #1 \\\\ 0 & 1 & 0 & #2 \\\\ 0 & 0 & 1 & #3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}}\n\n\\title{CSci 5551 - HW3}\n\\author{Yashasvi Sriram Patkuri\\\\patku001@umn.edu}\n\n\\begin{document}\n\\maketitle\n\\pagebreak\n\n\\section{}\nRobot arm has 3 DOF as illustrated in the Figure \\ref{fig:q1.1}.\nI am assuming that length of link 3 is $L_3$ since it is not mentioned in the figure.\n\\given\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{q1.png}\n  \\caption{3DOF robot arm}\n  \\label{fig:q1.1}\n\\end{figure}\n\nAssigning frames according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    % F1\n    \\draw [->]       (0, 0) -- (2, 0) node [right] {$x_1$};\n    \\draw [->]       (0, 0) -- (0, 2) node [left] {$z_1$};\n    % F2\n    \\draw [->]       (4, 0) -- (6, 0) node [right] {$x_2$};\n    \\draw            (4, 0) circle (0.15cm);\n    \\draw [fill]     (4, 0) circle (0.07cm) node [left] {$z_2$};\n    % F3\n    \\draw [->]       (6, 2) -- (7.414, 3.414) node [right] {$x_3$};\n    \\draw            (6, 2) circle (0.15cm);\n    \\draw [fill]     (6, 2) circle (0.07cm) node [left] {$z_3$};\n    % F4\n    \\draw [->]       (5, 4) -- (3.656, 5.514) node [right] {$x_4$};\n    \\draw            (5, 4) circle (0.15cm);\n    \\draw [fill]     (5, 4) circle (0.07cm) node [right] {$z_4$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q1.2}\n\\end{figure}\n\\begin{enumerate}[nolistsep]\n  \\item The z-axes are chosen along the axes of rotation.\n  \\item The choice of $z_4$ is free, so it is chosen to be parallel to $z_3$ for simplicity.\n  \\item The choice of $x_1$ is free, so it chosen in the direction of $x_2$ for simplicity.\n  \\item $x_2$ lies along the common normal to $z_1$ and $z_2$ which is unique.\n  \\item There are many common normal to $z_2$ and $z_3$ as they are parallel, so $x_3$ is chosen to be in the plane of paper for simplicity.\n  \\item $x_4$ is chosen in a similar manner.\n  \\item Each y-axis (not shown) just form a right handed coordinate system with respective frame.\n\\end{enumerate}\n\n\\subsubsection*{DH parameters}\nThe DH parameters for the frames shown in Figure \\ref{fig:q1.2} are as follows\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $1 \\to 2$ & $\\theta_1$ & 0 & $L_1$ & $90^{\\circ}$ \\\\\n $2 \\to 3$ & $\\theta_2$ & 0 & $L_2$ & $0^{\\circ}$ \\\\\n $3 \\to 4$ & $\\theta_3$ & 0 & $L_3$ & $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Transformation from $F_1$ to $F_3$}\n\\[\n  T_{13} \\equiv T_{12} * T_{23}\n\\]\n$T_{12}, T_{23}$ can be constructed using DH parameters.\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{12}$\n\\[\n  T_{12} \\equiv Rot_{z,\\theta_1} * Trans_{z, 0} * Trans_{x, L_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_1} * \\trans{0}{0}{0} * \\trans{L_1}{0}{0} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_1} * \\trans{L_1}{0}{0}\n    * \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{12} \\equiv \\rz{\\theta_1}\n  * \\begin{bmatrix} 1 & 0 & 0 & L_1 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix} c\\theta_1 & 0 & s\\theta_1 & L_1c\\theta_1 \\\\ s\\theta_1 & 0 & -c\\theta_1 & L_1s\\theta_1 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\nConsider $T_{23}$\n\\[\n  T_{23} \\equiv Rot_{z,\\theta_2} * Trans_{z, 0} * Trans_{x, L_2} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{23} \\equiv \\rz{\\theta_2} * \\trans{0}{0}{0} * \\trans{L_2}{0}{0} * \\rx{0^{\\circ}}\n\\]\n\\[\n  T_{23} \\equiv \\rz{\\theta_2} * \\trans{0}{0}{0} * \\trans{L_2}{0}{0} * \\iden\n\\]\n\\[\n  T_{23} \\equiv \\rz{\\theta_2} * \\trans{L_2}{0}{0}\n\\]\n\\[\n  T_{23} \\equiv\n  \\begin{bmatrix} c\\theta_2 & -s\\theta_2 & 0 & L_2c\\theta_2 \\\\ s\\theta_2 & c\\theta_2 & 0 & L_2s\\theta_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\n\\[\n  T_{13} \\equiv T_{12} * T_{23}\n\\]\nSubstituting $T_{12}, T_{23}$ we have,\n\\[\n  T_{13} \\equiv\n  \\begin{bmatrix} c\\theta_1 & 0 & s\\theta_1 & L_1c\\theta_1 \\\\ s\\theta_1 & 0 & -c\\theta_1 & L_1s\\theta_1 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} c\\theta_2 & -s\\theta_2 & 0 & L_2c\\theta_2 \\\\ s\\theta_2 & c\\theta_2 & 0 & L_2s\\theta_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{13} \\equiv\n  \\begin{bmatrix}\n    c\\theta_1c\\theta_2 & -c\\theta_1s\\theta_2 & s\\theta_1 & L_2c\\theta_1c\\theta_2 + L_1c\\theta_1 \\\\\n    s\\theta_1c\\theta_2 & -s\\theta_1s\\theta_2 & -c\\theta_1 & L_2s\\theta_1c\\theta_2 + L_1s\\theta_1 \\\\\n    s\\theta_2 & c\\theta_2 & 0 & L_2s\\theta_2 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\n\\pagebreak\n\n\\section{}\nRobot arm has 6 DOF as illustrated in the Figure \\ref{fig:q2.1}.\n\\given\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.6\\textwidth]{q2.png}\n  \\caption{6DOF robot arm}\n  \\label{fig:q2.1}\n\\end{figure}\n\nAssigning frames according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    % F0\n    \\draw [->]       (0, 0) -- (1, 0) node [right] {$x_0$};\n    \\draw [->]       (0, 0) -- (0, 1) node [left] {$z_0$};\n    % F1\n    \\draw [->]       (0, 2) -- (1, 2) node [right] {$x_1$};\n    \\draw [->]       (0, 2) -- (0, 3) node [left] {$z_1$};\n    % F2\n    \\draw [->]       (0, 4) -- (1, 4) node [right] {$x_2$};\n    \\draw            (0, 4) circle (0.15cm);\n    \\draw [fill]     (0, 4) circle (0.07cm) node [left] {$z_2$};\n    % F3\n    \\draw [->]       (3, 4) -- (4, 4) node [right] {$x_3$};\n    \\draw            (3, 4) circle (0.15cm);\n    \\draw [fill]     (3, 4) circle (0.07cm) node [left] {$z_3$};\n    % F4\n    \\draw [->]       (6, 4) -- (7, 4) node [right] {$x_4$};\n    \\draw            (6, 4) circle (0.15cm);\n    \\draw [fill]     (6, 4) circle (0.07cm) node [left] {$z_4$};\n    % F5\n    \\draw [->]       (9, 4) -- (10, 4) node [right] {$x_5, z_6$};\n    \\draw [->]       (9, 4) -- (9, 5) node [left] {$z_5$};\n    \\draw            (9, 4) circle (0.15cm);\n    \\draw [fill]     (9, 4) circle (0.07cm) node [left] {$x_6$};\n    % F6\n    \\draw [->]       (15, 4) -- (16, 4) node [right] {$z_t$};\n    \\draw [->]       (15, 4) -- (15, 3) node [left] {$x_t$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q2.2}\n\\end{figure}\n\\begin{enumerate}[nolistsep]\n  \\item The z-axes are chosen along the axes of rotation or translation.\n  \\item $z_0$, $z_1$ are co-incident, therefore $x_1$ is chosen at the end of link 1 for simplicity.\n  \\item $z_1$, $z_2$ intersection is taken as origin of $F_2$ with $x_2$ perpendicular to plane formed by $z_2$ and $z_1$.\n  \\item $z_2$, $z_3$ are parallel so $x_3$ is chosen to be on plane of paper for simplicity.\n  \\item $x_4$ is chosen in the same ways as $x_3$.\n  \\item $z_4$, $z_5$ have a unique common normal, thus there is only one choice of $x_5$.\n  \\item $z_5$, $z_6$ intersection is taken as origin of $F_6$ with $x_6$ perpendicular to plane formed by $z_5$ and $z_6$.\n  \\item Note that this step is probably most non-trivial in this procedure as origins of $F_5$ and $F_6$ coincide.\n\\end{enumerate}\n\n\\subsubsection*{DH parameters}\nI am assuming that the lengths $l_2$ and $l_7$ are constant link lengths and the prismatic joints $J_1$ and $J_6$ provide additional (signed) lengths of $q_1$ and $q_6$ respectively.\nWith this the DH parameters for the frames shown in Figure \\ref{fig:q2.2} are as follows,\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $0^{\\circ}$    & $l_1$                      & $0$     &   $0^{\\circ}$   \\\\\n $1 \\to 2$ & $0^{\\circ}$    & $l_2 + q_1$                & $0$     &   $90^{\\circ}$  \\\\\n $2 \\to 3$ & $q_2$          & $0$                        & $l_3$   &   $0^{\\circ}$   \\\\\n $3 \\to 4$ & $q_3$          & $0$                        & $l_4$   &   $0^{\\circ}$   \\\\\n $4 \\to 5$ & $q_4$          & $0$                        & $l_5$   &   $-90^{\\circ}$ \\\\\n $5 \\to 6$ & $q_5$          & $0$                        & $0$     &   $-90^{\\circ}$ \\\\\n $6 \\to t$ & $90^{\\circ}$   & $l_6 + l_7 + q_6$          & $0$     &   $0^{\\circ}$ \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Transformation from $F_0$ to $F_4$}\n\\[\n  T_{04} \\equiv T_{01} * T_{12} * T_{23} * T_{34}\n\\]\n$T_{01}, T_{12}, T_{23}, T_{34}$ can be constructed using DH parameters.\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nConsider $T_{01}$,\n\\[\n  T_{01} \\equiv Rot_{z, 0} * Trans_{z, l_1} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{01} \\equiv \\rz{0} * \\trans{0}{0}{l_1} * \\trans{0}{0}{0} * \\rx{0^{\\circ}}\n\\]\nEvaluating trigs,\n\\[\n  T_{01} \\equiv \\iden * \\trans{0}{0}{l_1} * \\trans{0}{0}{0} * \\iden\n\\]\nRemoving identities,\n\\[\n  T_{01} \\equiv \\trans{0}{0}{l_1}\n\\]\nConsider $T_{12}$,\n\\[\n  T_{12} \\equiv Rot_{z, 0} * Trans_{z, l_2 + q_1} * Trans_{x, 0} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{12} \\equiv \\rz{0} * \\trans{0}{0}{l_2 + q_1} * \\trans{0}{0}{0} * \\rx{90^{\\circ}}\n\\]\nEvaluating trigs,\n\\[\n  T_{12} \\equiv \\iden * \\trans{0}{0}{l_2 + q_1} * \\trans{0}{0}{0}\n  * \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nRemoving identities,\n\\[\n  T_{12} \\equiv \\trans{0}{0}{l_2 + q_1}\n  * \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{12} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & l_2 + q_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{23}$,\n\\[\n  T_{23} \\equiv Rot_{z, q_2} * Trans_{z, 0} * Trans_{x, l_3} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{23} \\equiv \\rz{q_2} * \\trans{0}{0}{0} * \\trans{l_3}{0}{0} * \\rx{0^{\\circ}}\n\\]\nEvaluating trigs,\n\\[\n  T_{23} \\equiv \\rz{q_2} * \\trans{0}{0}{0} * \\trans{l_3}{0}{0} * \\iden\n\\]\nRemoving identities,\n\\[\n  T_{23} \\equiv \\rz{q_2} * \\trans{l_3}{0}{0}\n\\]\n\\[\n  T_{23} \\equiv\n  \\begin{bmatrix} cq_2 & -sq_2 & 0 & l_3cq_2 \\\\ sq_2 & cq_2 & 0 & l_3sq_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{34}$,\n\\[\n  T_{34} \\equiv Rot_{z, q_3} * Trans_{z, 0} * Trans_{x, l_4} * Rot_{x, 0^{\\circ}}\n\\]\nThis is same as $T_{23}$ except for the variables, therefore we can use the final form of $T_{23}$ with replaced variables.\n\\[\n  T_{34} \\equiv\n  \\begin{bmatrix} cq_3 & -sq_3 & 0 & l_4cq_3 \\\\ sq_3 & cq_3 & 0 & l_4sq_3 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nFinally,\n\\[\n  T_{04} \\equiv T_{01} * T_{12} * T_{23} * T_{34}\n\\]\n\\[\n  T_{04} \\equiv\n  \\trans{0}{0}{l_1}\n  *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & l_2 + q_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} cq_2 & -sq_2 & 0 & l_3cq_2 \\\\ sq_2 & cq_2 & 0 & l_3sq_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} cq_3 & -sq_3 & 0 & l_4cq_3 \\\\ sq_3 & cq_3 & 0 & l_4sq_3 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying first two,\n\\[\n  T_{04} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & l_1 + l_2 + q_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} cq_2 & -sq_2 & 0 & l_3cq_2 \\\\ sq_2 & cq_2 & 0 & l_3sq_2 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix} cq_3 & -sq_3 & 0 & l_4cq_3 \\\\ sq_3 & cq_3 & 0 & l_4sq_3 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying last two,\n\\[\n  T_{04} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & l_1 + l_2 + q_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    cq_2cq_3 - sq_2sq_3 & -(sq_2cq_3 + cq_2sq_3) & 0 & l_4(cq_2cq_3 - sq_2sq_3) + l_3cq_2 \\\\\n    sq_2cq_3 + cq_2sq_3 & cq_2cq_3 - sq_2sq_3    & 0 & l_4(sq_2cq_3 + cq_2sq_3) + l_3sq_2 \\\\\n    0                   & 0                      & 1 & 0 \\\\\n    0                   & 0                      & 0 & 1\n  \\end{bmatrix}\n\\]\nUsing trig identity $s(a + b) \\equiv s(a)c(b) + c(a)s(b), c(a + b) \\equiv c(a)c(b) - s(a)s(b)$\n\\[\n  T_{04} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & l_1 + l_2 + q_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    c(q_2 + q_3) & -s(q_2 + q_3) & 0 & l_4c(q_2 + q_3) + l_3cq_2 \\\\\n    s(q_2 + q_3) & c(q_2 + q_3)  & 0 & l_4s(q_2 + q_3) + l_3sq_2 \\\\\n    0            & 0             & 1 & 0 \\\\\n    0            & 0             & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  T_{04} \\equiv\n  \\begin{bmatrix}\n    c(q_2 + q_3) & -s(q_2 + q_3) & 0 & l_4c(q_2 + q_3) + l_3cq_2 \\\\\n    0 & 0 & -1 & 0 \\\\\n    s(q_2 + q_3) & c(q_2 + q_3)  & 0 & l_4s(q_2 + q_3) + l_3sq_2 + l_1 + l_2 + q_1 \\\\\n    0 & 0 & 0 & 1 \\\\\n  \\end{bmatrix}\n\\]\n\n\\pagebreak\n\n\\section{}\nMOM manipulator is illustrated in the Figure \\ref{fig:q3.1}.\nThe lengths of various parts are labeled on the image in red ink.\nSpecifically the distance from base to joint 1 is $l_1$, distance b/w shoulder and forearm is $l_2$ and the distance b/w wrist and end-effector is $l_3$.\n\\given\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=1\\textwidth]{q3.png}\n  \\caption{MOM manipulator}\n  \\label{fig:q3.1}\n\\end{figure}\n\n\\pagebreak\nAssigning frames according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    \\draw [dashed, red]       (-2, -3) -- (-2, 2) node [right] {$l_1$};\n    \\draw [dashed, red]       (5, 2) -- (5, 1) node [right] {$l_2$};\n    % F0\n    \\draw [->]       (0, -3) -- (0, -2) node [right] {$z_0$};\n    \\draw            (0, -3) circle (0.15cm);\n    \\draw [fill]     (0, -3) circle (0.07cm) node [right] {$x_0$};\n    % F1,2\n    \\draw [->]       (0, 2) -- (1, 2) node [right] {$z_1, z_2$};\n    \\draw            (0, 2) circle (0.15cm);\n    \\draw [fill]     (0, 2) circle (0.07cm) node [left] {$x_1, x_2$};\n    % F3\n    \\draw [->]       (4, 1) -- (4, 0) node [right] {$x_3$};\n    \\draw            (4, 1) circle (0.15cm);\n    \\draw [fill]     (4, 1) circle (0.07cm) node [right] {$z_3$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment for joints 1-3: Front view}\n  \\label{fig:q3.2}\n\\end{figure}\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    \\draw [dashed, red]       (3, -2) -- (-1, -2) node [left] {$l_3$};\n    % F3\n    \\draw [->]       (7, 1) -- (7, 0) node [left] {$x_3$};\n    \\draw [->]       (7, 1) -- (6, 1) node [left] {$z_3$};\n    % F4,5,6\n    \\draw [->]       (3, 1) -- (3, 0) node [left] {$x_4$};\n    \\draw [->]       (3, 1) -- (3, 2) node [left] {$z_5$};\n    \\draw [->]       (3, 1) -- (2, 1) node [left] {$z_4, z_6$};\n    \\draw            (3, 1) circle (0.15cm);\n    \\draw [fill]     (3, 1) circle (0.07cm) node [right] {$x_5, x_6$};\n    % F7\n    \\draw [->]       (-1, 1) -- (-2, 1) node [left] {$z_7$};\n    \\draw            (-1, 1) circle (0.15cm);\n    \\draw [fill]     (-1, 1) circle (0.07cm) node [right] {$x_7$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment for joints 4-7: Side view}\n  \\label{fig:q3.3}\n\\end{figure}\n\\begin{enumerate}[nolistsep]\n  \\item The base frame z-axis is chosen to be upward and its x-axis in the direction of end-effector for the pose in Figure \\ref{fig:q3.1}.\n  \\item The side in which $x_0$ comes out of paper and $z_0$ goes up is referred to as the front view in Figure \\ref{fig:q3.2}. The side view formed by it is used in Figure \\ref{fig:q3.3}.\n  \\item The end-effector frame z-axis is chosen as shown in Figure \\ref{fig:q3.3}.\n  \\item The z-axes are chosen along the axes of rotation/translation.\n  \\item $z_0$ and $z_1$ intersection is taken as origin of $F_1$, $x_1$ is chosen to be normal to plane formed by $z_0$ and $z_1$.\n  \\item $z_1$ and $z_2$ coincide, so $x_2$ is chosen to be coincident to $x_1$ for simplicity.\n  \\item $z_2$ and $z_3$ have a unique common normal, so $x_3$ is chosen according to that.\n  \\item $F_1 \\to F_2$ captures joint 1 effect. $F_2 \\to F_3$ captures joint 2 effect.\n  \\item Spherical joint is made using three rotational joints as described in lecture slides captured by frames $F_4, F_5, F_6$.\n  \\item $z_3$ and $z_4$ are coincident, so $x_4$ is chosen to be on the end of forearm for simplicity.\n  \\item $z_4$ and $z_5$ intersection is taken as origin for $F_5$ and $x_5$ is chosen perpendicular to plane of $z_4$ and $z_5$.\n  \\item $x_6$ is chosen in the same way.\n  \\item $z_6$ and $z_7$ are coincident so $x_7$ is chosen on the end-effector for simplicity.\n  \\item Each y-axis (not shown) just form a right handed coordinate system with respective frame.\n\\end{enumerate}\n\n\\subsubsection*{DH parameters}\nDH parameters for the frames shown in Figure \\ref{fig:q3.2} and \\ref{fig:q3.3} are as follows,\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $0^{\\circ}$    & $l_1$                      & $0$     &   $-90^{\\circ}$    \\\\\n $1 \\to 2$ & $q_1$          & $0$                        & $0$     &   $0^{\\circ}$      \\\\\n $2 \\to 3$ & $90^{\\circ}$   & $q_2$                      & $l_2$   &   $90^{\\circ}$     \\\\\n $3 \\to 4$ & $0^{\\circ}$    & $q_3$                      & $0$     &   $0^{\\circ}$      \\\\\n $4 \\to 5$ & $q_4$          & $0$                        & $0$     &   $-90^{\\circ}$    \\\\\n $5 \\to 6$ & $q_5$          & $0$                        & $0$     &   $90^{\\circ}$     \\\\\n $6 \\to 7$ & $q_6$          & $l_3$                      & $0$     &   $0^{\\circ}$      \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Transformation from $F_0$ to $F_3$}\n\\[\n  T_{03} \\equiv\n  T_{01}\n  * T_{12}\n  * T_{23}\n\\]\n$T_{01}, T_{12}, T_{23}$ can be constructed using DH parameters.\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nAlso observe,\n\\[\n  Rot_{z, 0^{\\circ}} \\equiv \\rz{0^{\\circ}} \\equiv I\n\\]\n\\[\n  Trans_{z, 0} \\equiv \\trans{0}{0}{0} \\equiv I\n\\]\n\\[\n  Trans_{x, 0} \\equiv \\trans{0}{0}{0} \\equiv I\n\\]\n\\[\n  Rot_{x, 0^{\\circ}} \\equiv \\rx{0^{\\circ}} \\equiv I\n\\]\nConsider $T_{01}$,\n\\[\n  T_{0,1} \\equiv Rot_{z, 0} * Trans_{z, l_1} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv I * Trans_{z, l_1} * I * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv Trans_{z, l_1} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv \\trans{0}{0}{l_1} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv \\trans{0}{0}{l_1} *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{0,1} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & -1 & 0 & l_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{12}$,\n\\[\n  T_{1,2} \\equiv Rot_{z, q_1} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{1,2} \\equiv Rot_{z, q_1} * I * I * I\n\\]\n\\[\n  T_{1,2} \\equiv Rot_{z, q_1}\n\\]\n\\[\n  T_{1,2} \\equiv \\rz{q_1}\n\\]\nConsider $T_{23}$,\n\\[\n  T_{2,3} \\equiv Rot_{z, 90^{\\circ}} * Trans_{z, q_2} * Trans_{x, l_2} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{2,3} \\equiv \\rz{90^{\\circ}} * \\trans{0}{0}{q_2} * \\trans{l_2}{0}{0} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{2,3}\n  \\equiv\n  \\begin{bmatrix} 0 & -1 & 0 & 0 \\\\ 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\trans{0}{0}{q_2}\n  * \\trans{l_2}{0}{0}\n  * \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying first two,\n\\[\n  T_{2,3}\n  \\equiv\n  \\begin{bmatrix} 0 & -1 & 0 & 0 \\\\ 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & q_2 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\trans{l_2}{0}{0}\n  * \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying last two,\n\\[\n  T_{2,3}\n  \\equiv\n  \\begin{bmatrix} 0 & -1 & 0 & 0 \\\\ 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & q_2 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} 1 & 0 & 0 & l_2 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 &  & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{2,3}\n  \\equiv\n  \\begin{bmatrix} 0 & 0 & 1 & 0 \\\\ 1 & 0 & 0 & l_2 \\\\ 0 & 1 & 0 & q_2 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nFinally,\n\\[\n  T_{03} \\equiv\n  T_{01}\n  * T_{12}\n  * T_{23}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & -1 & 0 & l_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\rz{q_1}\n  * \\begin{bmatrix} 0 & 0 & 1 & 0 \\\\ 1 & 0 & 0 & l_2 \\\\ 0 & 1 & 0 & q_2 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix} cq_1 & -sq_1 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ -sq_1 & -cq_1 & 0 & l_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} 0 & 0 & 1 & 0 \\\\ 1 & 0 & 0 & l_2 \\\\ 0 & 1 & 0 & q_2 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{03} \\equiv\n  \\begin{bmatrix} -sq_1 & 0 & cq_1 & -l_2sq_1 \\\\ 0 & 1 & 0 & q_2 \\\\ -cq_1 & 0 & -sq_1 & -l_2cq_1 + l_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\n\\subsubsection*{Transformation from $F_0$ to $F_6$}\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n\\]\nConsider $T_{34}$,\n\\[\n  T_{3,4} \\equiv Rot_{z, 0} * Trans_{z, q_3} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{3,4} \\equiv I * Trans_{z, q_3} I * I\n\\]\n\\[\n  T_{3,4} \\equiv Trans_{z, q_3}\n\\]\n\\[\n  T_{3,4} \\equiv \\trans{0}{0}{q_3}\n\\]\nConsider $T_{45}$,\n\\[\n  T_{4,5} \\equiv Rot_{z, q_4} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{4,5} \\equiv Rot_{z, q_4} * I * I * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{4,5} \\equiv Rot_{z, q_4} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{4,5} \\equiv \\rz{q_4} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{4,5} \\equiv \\rz{q_4}\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{4,5} \\equiv\n  \\begin{bmatrix} cq_4 & 0 & -sq_4 & 0 \\\\ sq_4 & 0 & cq_4 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{56}$,\n\\[\n  T_{5,6} \\equiv Rot_{z, q_5} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{5,6} \\equiv Rot_{z, q_5} * I * I * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{5,6} \\equiv Rot_{z, q_5} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{5,6} \\equiv \\rz{q_5} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{5,6} \\equiv \\rz{q_5} *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{5,6} \\equiv\n  \\begin{bmatrix} cq_5 & 0 & sq_5 & 0 \\\\ sq_5 & 0 & -cq_5 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nFinally,\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n\\]\nSubstituting $T_{34}, T_{45}$,\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * \\trans{0}{0}{q_3}\n  * \\begin{bmatrix} cq_4 & 0 & -sq_4 & 0 \\\\ sq_4 & 0 & cq_4 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{56}\n\\]\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * \\begin{bmatrix} cq_4 & 0 & -sq_4 & 0 \\\\ sq_4 & 0 & cq_4 & 0 \\\\ 0 & -1 & 0 & q_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{56}\n\\]\nSubstituting $T_{56}$,\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * \\begin{bmatrix} cq_4 & 0 & -sq_4 & 0 \\\\ sq_4 & 0 & cq_4 & 0 \\\\ 0 & -1 & 0 & q_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_5 & 0 & sq_5 & 0 \\\\ sq_5 & 0 & -cq_5 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{06} \\equiv\n  T_{03}\n  * \\begin{bmatrix} cq_4cq_5 & -sq_4 & cq_4sq_5 & 0 \\\\ sq_4cq_5 & cq_4 & sq_4sq_5 & 0 \\\\ -sq_5 & 0 & cq_5 & q_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nSubstituting $T_{03}$,\n\\[\n  T_{06} \\equiv\n  \\begin{bmatrix} -sq_1 & 0 & cq_1 & -l_2sq_1 \\\\ 0 & 1 & 0 & q_2 \\\\ -cq_1 & 0 & -sq_1 & -l_2cq_1 + l_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_4cq_5 & -sq_4 & cq_4sq_5 & 0 \\\\ sq_4cq_5 & cq_4 & sq_4sq_5 & 0 \\\\ -sq_5 & 0 & cq_5 & q_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{06} \\equiv\n  \\begin{bmatrix} -s_1c_4c_5 - c_1s_5 & s_1s_4 & -s_1c_4s_5 + c_1c_5 & q_3c_1 - l_2s_1 \\\\ s_4c_5 & c_4 & s_4s_5 & q_2 \\\\ -c_1c_4c_5 + s_1s_5 & c_1s_4 & -c_1c_4s_5 - s_1c_5 & -q_3s_1 + l_1 - l_2c_1 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nwhere $c_i \\equiv cos(q_i), s_i \\equiv sin(q_i)$.\n\n\\pagebreak\n\n\\section{}\nA human hand is illustrated in the Figure \\ref{fig:q4.1}.\nThe lengths of various parts are labeled on the image in red ink.\nSpecifically the distance from shoulder joint to elbow is $l_1$, distance from elbow and wrist is $l_2$ and the distance from wrist and tip of fingers is $l_3$.\nThe tip of the hand frame is drawn a bit incorrectly. It just needs to be translated to the tip of fingers, without changing the orientation.\nThe joints in the fingers are ignored.\n\\given\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=0.68\\textwidth]{q4.png}\n  \\caption{Human hand}\n  \\label{fig:q4.1}\n\\end{figure}\n\n\\pagebreak\nAssigning frames according to DH convention we have,\n\\fromlectures\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]\n    \\draw [dashed, red]       (-3, 0) -- (-3, -5) node [right] {$l_1$};\n    \\draw [dashed, red]       (3, -5) -- (3, -10) node [right] {$l_2$};\n    \\draw [dashed, red]       (-3, -10) -- (-3, -12) node [right] {$l_3$};\n    % F1,2,3\n    \\draw [->]       (0, 0) -- (-1, 0) node [left] {$x_0, x_1$};\n    \\draw            (0, 0) circle (0.15cm);\n    \\draw [fill]     (0, 0) circle (0.07cm) node [below] {$z_0, x_2$};\n    \\draw [->]       (0, 0) -- (0, 1) node [left] {$z_1$};\n    \\draw [->]       (0, 0) -- (1, 0) node [right] {$z_2$};\n    % F4\n    \\draw [->]       (0, -5) -- (0, -6) node [left] {$x_3$};\n    \\draw            (0, -5) circle (0.15cm);\n    \\draw [fill]     (0, -5) circle (0.07cm) node [above] {$z_3$};\n    % F5,6,7\n    \\draw [->]       (0, -10) -- (0, -11) node [left] {$x_4, x_5, z_6$};\n    \\draw [->]       (0, -10) -- (1, -10) node [right] {$z_5$};\n    \\draw            (0, -10) circle (0.15cm);\n    \\draw [fill]     (0, -10) circle (0.07cm) node [left] {$z_4, x_6$};\n    % F8\n    \\draw [->]       (0, -12) -- (0, -13) node [left] {$z_7 \\equiv a$};\n    \\draw [->]       (0, -12) -- (1, -12) node [right] {$x_7 \\equiv s$};\n  \\end{tikzpicture}\n  \\caption{DH frame assignment}\n  \\label{fig:q4.2}\n\\end{figure}\n\\begin{enumerate}[nolistsep]\n  \\item The spherical joint at the shoulder is modeled using 3 revolute joints captured by $F_0, F_1, F_2$, elbow by $F_3$ and wrist by $F_4, F_5, F_6$ and tip of hand by $F_7$. The lengths labeled in Figure \\ref{fig:q4.1} are replicated in Figure \\ref{fig:q4.2}.\n    \\begin{enumerate}[nolistsep]\n      \\item $q_1$ models sideways rotation.\n      \\item $q_2$ models hand twisting rotation.\n      \\item $q_3$ models forward/backward rotation.\n      \\item $q_4$ models elbow rotation\n      \\item $q_5$ models wrist yaw.\n      \\item $q_6$ models wrist pitch.\n      \\item $q_7$ models forearm axial roll.\n    \\end{enumerate}\n  \\item z-axes are chosen using joints.\n  \\item $z_0, z_1$ intersection point is chosen as origin for $F_1$, and $x_1$ is chosen perpendicular to $z_0, z_1$.\n  \\item $x_2$ is chosen similarly.\n  \\item $z_2, z_3$ have a unique common normal, so $x_3$ is chosen along that.\n  \\item $z_3, z_4$ are parallel therefore $x_4$ is chosen to be on the paper for simplicity.\n  \\item $z_4, z_5$ intersection point is chosen as origin for $F_5$, and $x_5$ is chosen perpendicular to $z_4, z_5$.\n  \\item $x_6$ is chosen similarly.\n  \\item $F_7$ is given, I assume that a $\\equiv$ z-axis and s $\\equiv$ x-axis.\n\\end{enumerate}\n\n\\paragraph{Note} The joints and frames are re-ordered to achieve the required `tip of the hand' transformation. Specifically joints 5 (axial roll), 6 (wrist yaw), 7 (wrist pitch) are mapped to DH parameters $q_7, q_5, q_6$ respectively. This re-ordering can be done because z-axis of joints 4 (elbow) and 6 (wrist yaw) are always parallel for a human hand and joints 5 (axial roll), 6 (wrist yaw), 7 (wrist pitch) together can form a spherical joint.\n\n\\subsubsection*{DH parameters}\nDH parameters for the frames shown in Figure \\ref{fig:q4.2} are as follows,\n\\begin{center}\n\\begin{tabular}{ c | c c c c }\n \\hline\n $F_i \\to F_j$ & $\\theta$ & d & r & $\\alpha$ \\\\\n \\hline\n $0 \\to 1$ & $q_1$    & $0$       & $0$     &   $90^{\\circ}$   \\\\\n $1 \\to 2$ & $q_2$    & $0$       & $0$     &   $-90^{\\circ}$  \\\\\n $2 \\to 3$ & $q_3$    & $0$       & $l_1$   &   $90^{\\circ}$   \\\\\n $3 \\to 4$ & $q_4$    & $0$       & $l_2$   &   $0^{\\circ}$   \\\\\n $4 \\to 5$ & $q_5$    & $0$       & $0$     &   $-90^{\\circ}$  \\\\\n $5 \\to 6$ & $q_6$    & $0$       & $0$     &   $-90^{\\circ}$   \\\\\n $6 \\to 7$ & $q_7$    & $l_3$     & $0$     &   $0^{\\circ}$    \\\\\n \\hline\n\\end{tabular}\n\\end{center}\n\n\\subsubsection*{Transformation from $F_0$ to $F_7$}\n\\[\n  T_{07} \\equiv\n  T_{01}\n  * T_{12}\n  * T_{23}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\n$T_{01}, T_{12}, T_{23}, T_{34}, T_{45}, T_{45}, T_{67}$ can be constructed using DH parameters.\nGiven frame i and frame j with DH parameters [ $\\theta$, d, r, $\\alpha$ ] the transformation matrix is\n\\[\n  T_{i,j} \\equiv Rot_{z,\\theta} * Trans_{z, d} * Trans_{x, r} * Rot_{x, \\alpha}\n\\]\n\\fromlectures\nAlso observe,\n\\[\n  Rot_{z, 0^{\\circ}} \\equiv \\rz{0^{\\circ}} \\equiv I\n\\]\n\\[\n  Trans_{z, 0} \\equiv \\trans{0}{0}{0} \\equiv I\n\\]\n\\[\n  Trans_{x, 0} \\equiv \\trans{0}{0}{0} \\equiv I\n\\]\n\\[\n  Rot_{x, 0^{\\circ}} \\equiv \\rx{0^{\\circ}} \\equiv I\n\\]\nConsider $T_{01}$,\n\\[\n  T_{0,1} \\equiv Rot_{z,q_1} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv Rot_{z,q_1} * I * I * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv Rot_{z,q_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv \\rz{q_1} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{0,1} \\equiv\n  \\rz{q_1}\n  *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{0,1} \\equiv\n  \\begin{bmatrix} cq_1 & 0 & sq_1 & 0 \\\\ sq_1 & 0 & -cq_1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{12}$,\n\\[\n  T_{1,2} \\equiv Rot_{z,q_2} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{1,2} \\equiv Rot_{z,q_2} * I * I * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{1,2} \\equiv Rot_{z,q_2} * Rot_{x, -90^{\\circ}}\n\\]\n\\[\n  T_{1,2} \\equiv \\rz{q_2} * \\rx{-90^{\\circ}}\n\\]\n\\[\n  T_{1,2} \\equiv\n  \\rz{q_2}\n  *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{1,2} \\equiv\n  \\begin{bmatrix} cq_2 & 0 & -sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{23}$,\n\\[\n  T_{2,3} \\equiv Rot_{z,q_3} * Trans_{z, 0} * Trans_{x, l_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{2,3} \\equiv Rot_{z,q_3} * I * Trans_{x, l_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{2,3} \\equiv Rot_{z,q_3} * Trans_{x, l_1} * Rot_{x, 90^{\\circ}}\n\\]\n\\[\n  T_{2,3} \\equiv \\rz{q_3} * \\trans{l_1}{0}{0} * \\rx{90^{\\circ}}\n\\]\n\\[\n  T_{2,3} \\equiv\n  \\rz{q_3}\n  *\n  \\trans{l_1}{0}{0}\n  *\n  \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{2,3} \\equiv\n  \\rz{q_3}\n  *\n  \\begin{bmatrix} 1 & 0 & 0 & l_1 \\\\ 0 & 0 & -1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  T_{2,3} \\equiv\n  \\begin{bmatrix} cq_3 & 0 & sq_3 & l_1cq_3 \\\\ sq_3 & 0 & -cq_3 & l_1sq_3 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{34}$,\n\\[\n  T_{3,4} \\equiv Rot_{z,q_4} * Trans_{z, 0} * Trans_{x, l_2} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{3,4} \\equiv Rot_{z,q_4} * I * Trans_{x, l_2} * I\n\\]\n\\[\n  T_{3,4} \\equiv Rot_{z,q_4} * Trans_{x, l_2}\n\\]\n\\[\n  T_{3,4} \\equiv \\rz{q_4} * \\trans{l_2}{0}{0}\n\\]\n\\[\n  T_{3,4} \\equiv\n  \\begin{bmatrix} cq_4 & -sq_4 & 0 & l_2cq_4 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{45}$,\n\\[\n  T_{4,5} \\equiv Rot_{z,q_5} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\nThis form is similar to $T_{12}$. So we can directly use the final form of $T_{12}$ with $q_1$ substituted by $q_5$.\n\\[\n  T_{4,5} \\equiv\n  \\begin{bmatrix} cq_5 & 0 & -sq_5 & 0 \\\\ sq_5 & 0 & cq_5 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{56}$,\n\\[\n  T_{5,6} \\equiv Rot_{z,q_6} * Trans_{z, 0} * Trans_{x, 0} * Rot_{x, -90^{\\circ}}\n\\]\nThis form is similar to $T_{12}$. So we can directly use the final form of $T_{12}$ with $q_1$ substituted by $q_6$.\n\\[\n  T_{5,6} \\equiv\n  \\begin{bmatrix} cq_6 & 0 & -sq_6 & 0 \\\\ sq_6 & 0 & cq_6 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{67}$,\n\\[\n  T_{6,7} \\equiv Rot_{z,q_7} * Trans_{z, l_3} * Trans_{x, 0} * Rot_{x, 0^{\\circ}}\n\\]\n\\[\n  T_{6,7} \\equiv Rot_{z,q_7} * Trans_{z, l_3} * I * I\n\\]\n\\[\n  T_{6,7} \\equiv Rot_{z,q_7} * Trans_{z, l_3}\n\\]\n\\[\n  T_{6,7} \\equiv \\rz{q_7} * \\trans{0}{0}{l_3}\n\\]\n\\[\n  T_{6,7} \\equiv\n  \\begin{bmatrix} cq_7 & -sq_7 & 0 & 0 \\\\ sq_7 & cq_7 & 0 & 0 \\\\ 0 & 0 & 1 & l_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nConsider $T_{07}$,\n\\[\n  T_{07} \\equiv\n  T_{01}\n  * T_{12}\n  * T_{23}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\nSubstituting $T_{01}, T_{12}$,\n\\[\n  T_{07} \\equiv\n  \\begin{bmatrix} cq_1 & 0 & sq_1 & 0 \\\\ sq_1 & 0 & -cq_1 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_2 & 0 & -sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{23}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\n\\[\n  T_{07} \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{23}\n  * T_{34}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\nSubstituting $T_{23}, T_{34}$,\n\\[\n  T_{07} \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_3 & 0 & sq_3 & l_1cq_3 \\\\ sq_3 & 0 & -cq_3 & l_1sq_3 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_4 & -sq_4 & 0 & l_2cq_4 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\nMultiplying $T_{23}, T_{34}$,\n\\[\n  T_{07} \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_3cq_4 & -cq_3sq_4 & sq_3 & l_2cq_3cq_4 + l_1cq_3 \\\\ sq_3cq_4 & -sq_3sq_4 & -cq_3 & l_2sq_3cq_4 + l_1sq_3 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{45}\n  * T_{56}\n  * T_{67}\n\\]\nSubstituting $T_{45}, T_{56}$,\n\\[\n  T_{07} \\equiv\n  A\n  * \\begin{bmatrix} cq_5 & 0 & -sq_5 & 0 \\\\ sq_5 & 0 & cq_5 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_6 & 0 & -sq_6 & 0 \\\\ sq_6 & 0 & cq_6 & 0 \\\\ 0 & -1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{67}\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_3cq_4 & -cq_3sq_4 & sq_3 & l_2cq_3cq_4 + l_1cq_3 \\\\ sq_3cq_4 & -sq_3sq_4 & -cq_3 & l_2sq_3cq_4 + l_1sq_3 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying $T_{45}, T_{56}$,\n\\[\n  T_{07} \\equiv\n  A\n  * \\begin{bmatrix} cq_5cq_6 & sq_5 & -cq_5sq_6 & 0 \\\\ sq_5cq_6 & -cq_5 & -sq_5sq_6 & 0 \\\\ -sq_6 & 0 & -cq_6 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * T_{67}\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_3cq_4 & -cq_3sq_4 & sq_3 & l_2cq_3cq_4 + l_1cq_3 \\\\ sq_3cq_4 & -sq_3sq_4 & -cq_3 & l_2sq_3cq_4 + l_1sq_3 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nSubstituting $T_{67}$,\n\\[\n  T_{07} \\equiv\n  A\n  * \\begin{bmatrix} cq_5cq_6 & sq_5 & -cq_5sq_6 & 0 \\\\ sq_5cq_6 & -cq_5 & -sq_5sq_6 & 0 \\\\ -sq_6 & 0 & -cq_6 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_7 & -sq_7 & 0 & 0 \\\\ sq_7 & cq_7 & 0 & 0 \\\\ 0 & 0 & 1 & l_3 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix} cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\ sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\ sq_2 & 0 & cq_2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n  * \\begin{bmatrix} cq_3cq_4 & -cq_3sq_4 & sq_3 & l_2cq_3cq_4 + l_1cq_3 \\\\ sq_3cq_4 & -sq_3sq_4 & -cq_3 & l_2sq_3cq_4 + l_1sq_3 \\\\ sq_4 & cq_4 & 0 & l_2sq_4 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\nMultiplying,\n\\[\n  T_{07} \\equiv\n  A\n  \\begin{bmatrix} c_5c_6c_7 + s_5s_7 & -c_5c_6s_7 + s_5c_7 & -c_5s_6 & -l_3c_5s_6 \\\\ s_5c_6c_7 - c_5s_7 & -s_5c_6s_7 - c_5c_7 & -s_5s_6 & -l_3s_5s_6 \\\\ -s_6c_7 & s_6s_7 & -c_6 & -l_3c_6 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix}\n    cq_1cq_2 & -sq_1 & -cq_1sq_2 & 0 \\\\\n    sq_1cq_2 & cq_1 & -sq_1sq_2 & 0 \\\\\n    sq_2 & 0 & cq_2 & 0 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n  *\n  \\begin{bmatrix}\n    cq_3cq_4 & -cq_3sq_4 & sq_3 & l_2cq_3cq_4 + l_1cq_3 \\\\\n    sq_3cq_4 & -sq_3sq_4 & -cq_3 & l_2sq_3cq_4 + l_1sq_3 \\\\\n    sq_4 & cq_4 & 0 & l_2sq_4 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nMultiplying,\n\\[\n  T_{07} \\equiv\n  A\n  \\begin{bmatrix}\n    c_5c_6c_7 + s_5s_7 & -c_5c_6s_7 + s_5c_7 & -c_5s_6 & -l_3c_5s_6 \\\\\n    s_5c_6c_7 - c_5s_7 & -s_5c_6s_7 - c_5c_7 & -s_5s_6 & -l_3s_5s_6 \\\\\n    -s_6c_7 & s_6s_7 & -c_6 & -l_3c_6 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix}\n    c_1c_2c_3c_4 - s_1s_3c_4 - c_1s_2s_4 & -c_1c_2c_3s_4 + s_1s_3s_4 - c_1s_2c_4 & c_1c_2s_3 + s_1c_3 & t_1 \\\\\n    s_1c_2c_3c_4 + c_1s_3c_4 - s_1s_2s_4 & -s_1c_2c_3c_4 - c_1s_3s_4 - s_1s_2c_4 & s_1c_2s_3 - c_1c_3 & t_2 \\\\\n    s_2c_3c_4 + c_2s_4 & -s_2c_3c_4 + c_2c_4 & s_2s_3 & s_2(l_2c_3c_4 + l_1c_3) + c_2(l_2s_4) \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  t_1 \\equiv  c_1c_2(l_2c_3c_4 + l_1c_3) -s_1(l_2s_3s_4 + l_1s_3) -c_1s_2(l_2s_4)\n\\]\n\\[\n  t_1 \\equiv s_1c_2(l_2c_3c_4 + l_1c_3) + c_1(l_2s_3s_4 + l_1s_3) -s_1s_2(l_2s_4)\n\\]\nTherefore $T_{07}$,\n\\[\n  T_{07} \\equiv A * B\n\\]\n\\[\n  A \\equiv\n  \\begin{bmatrix}\n    c_1c_2c_3c_4 - s_1s_3c_4 - c_1s_2s_4 & -c_1c_2c_3s_4 + s_1s_3s_4 - c_1s_2c_4 & c_1c_2s_3 + s_1c_3 & t_1 \\\\\n    s_1c_2c_3c_4 + c_1s_3c_4 - s_1s_2s_4 & -s_1c_2c_3c_4 - c_1s_3s_4 - s_1s_2c_4 & s_1c_2s_3 - c_1c_3 & t_2 \\\\\n    s_2c_3c_4 + c_2s_4 & -s_2c_3c_4 + c_2c_4 & s_2s_3 & s_2(l_2c_3c_4 + l_1c_3) + c_2(l_2s_4) \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\n\\[\n  t_1 \\equiv  c_1c_2(l_2c_3c_4 + l_1c_3) -s_1(l_2s_3s_4 + l_1s_3) -c_1s_2(l_2s_4)\n\\]\n\\[\n  t_1 \\equiv s_1c_2(l_2c_3c_4 + l_1c_3) + c_1(l_2s_3s_4 + l_1s_3) -s_1s_2(l_2s_4)\n\\]\n\\[\n  B \\equiv\n  \\begin{bmatrix}\n    c_5c_6c_7 + s_5s_7 & -c_5c_6s_7 + s_5c_7 & -c_5s_6 & -l_3c_5s_6 \\\\\n    s_5c_6c_7 - c_5s_7 & -s_5c_6s_7 - c_5c_7 & -s_5s_6 & -l_3s_5s_6 \\\\\n    -s_6c_7 & s_6s_7 & -c_6 & -l_3c_6 \\\\\n    0 & 0 & 0 & 1\n  \\end{bmatrix}\n\\]\nwhere $c_i \\equiv cos(q_i), s_i \\equiv sin(q_i)$.\n\\end{document}\n", "meta": {"hexsha": "97471a4b314b345e848f8e40628c188805072f02", "size": 38865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3/hw3.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": "hw3/hw3.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": "hw3/hw3.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": 35.4284412033, "max_line_length": 450, "alphanum_fraction": 0.5314035765, "num_tokens": 19068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6061353178339732}}
{"text": "\\chapter{Nash Equilibrium}\nIn the previous chapter we discussed several ways to find optimal behaviour for\nplayers. However, there is a big class of games where these method do not work;\ne.g. the game corresponding to \\Cref{table:heads-and-tales-game}.\n\n\\section{No Regrets Strategies}\nThe core ideas leading to understanding of the optimal behaviour are Nash\nequilibria and the notion of mixed strategies.\n\nTo understand the equilibria, consider the pair of strategies ``cooperates'',\n``cooperates'' in prisoner's dilemma. This situation is bad because each player\ncan change their behaviour and improve his/her situation; i.e., this situation\nis not stable.\n\\begin{definition}\n  Let $(X, Y, A, B)$ be a game in normal form. We say that a pair of strategies\n  $x \\in X$ and $y \\in Y$ are in \\emph{Nash equilibrium} if \n  \\begin{gather*}\n    A(x, y) \\ge A(x', y) \\\\\n    \\text{and} \\\\\n    B(x, y) \\ge B(x, y')\n  \\end{gather*}\n  for all $x' \\in X$ and $y' \\in Y$.\n\\end{definition}\nIn other words, if two players decided to stick to $x$ and $y$ that are in Nash\nequilibrium, they do not regret not violating their agreement.\n\\begin{exercise}\n  \\begin{itemize}\n    \\item Check that the pair of strategies ``defects'', ``defects'' are in Nash\n      equilibrium in the prisoner's dilemma.\n    \\item Check that there are no Nash equilibrium in the game corresponding to\n      \\Cref{table:heads-and-tales-game}.\n  \\end{itemize}\n\\end{exercise}\n\nNote that some games may have several Nash equilibria. For example, let us\nconsider the following game.\n\\begin{game}\n  Two people are leaving in a flat. They need to call a plumber and stay in the\n  flat while the plumber works.\n  \\begin{itemize}\n    \\item If none of them call the plumber, the water leaks and each of them\n      will need to spend $1$ hours cleaning the apartment.\n    \\item If one of them calls the plumber, he/she will spend $1$ hour waiting\n      pipes to be fixed.\n    \\item Alternatively they can call together and wait for one our together.\n  \\end{itemize}\n  This game is a version of \\emph{volunteer's dilemma}.\n\\end{game}\nIt is clear that this game can be described using the following table.\n\\begin{center}\n  \\begin{tabular}{l l l  l  l  l  l  l  l}\n    \\toprule\n                       & do nothing  & call the plumber   \\\\\n    \\midrule\n    do nothing         & -1, -1    & 0, -1    \\\\\n    call the plumber   & -1, 0       & -1, -1   \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\nWe may notice that in this game all pairs except ``call the plumber'', ``call the\nplumber'' are in Nash equilibrium. However, the pair of strategies ``do\nnothing'', ``do nothing'' is not efficient since one may improve the situation\nfor one of the players without harming the other. Moreover, if the players know\nthat this situation is going to repeat it self they may agree to call the\nplumber in turns and reduce the total time they wasted. \n\n\\section{Mixed Strategies}\nRecall that we still do not have any optimal behaviour in the game corresponding\nto \\Cref{table:heads-and-tales-game}; however, it seems clear that in real life\nthe best behaviour would be to flip coins and choose strategies accordingly.\n\nThis observation leads to the notion of mixed strategies.\n\\begin{definition}\n  Let $(X, Y, A, B)$ be a game in normal form. We say that a probability\n  distribution $\\bar{x}$ over $X$ is a mixed strategy for the first player.\n  Similarly we say that a probability distribution $\\bar{y}$ over $Y$ is a mixed\n  strategy for the second player.\n\n\n  We say that the payoffs of the players if they choose mixed strategies\n  $\\bar{x}$ and $\\bar{y}$ are $A(\\bar{x}, \\bar{y})$ and $B(\\bar{x}, \\bar{y})$ \n  such that\n  \\begin{gather*}\n    A(\\bar{x}, \\bar{y}) = \n      \\expectation[x \\gets \\bar{x}]{\\expectation[y \\gets \\bar{y}]{A(x, y)}} \\\\ \n    \\text{and} \\\\\n    B(\\bar{x}, \\bar{y}) = \n      \\expectation[x \\gets \\bar{x}]{\\expectation[y \\gets \\bar{y}]{B(x, y)}}.\n  \\end{gather*}\n\\end{definition}\n\n\\begin{exercise}\n  Let $f : \\Omega_1 \\times \\Omega_2 \\to \\R$ and let $\\Distribution{D}_1$ and\n  $\\Distribution{D}_2$ be probability distributions on $\\Omega_1$ and\n  $\\Omega_2$, respectively. Show that \n  \\[\n  \\expectation[\\omega_1 \\gets \\Distribution{D}_1]{\n    \\expectation[\\omega_2 \\gets \\Distribution{D}_2]{f(\\omega_1, \\omega_2)}\n  } = \n  \\expectation[\\omega_2 \\gets \\Distribution{D}_2]{\n    \\expectation[\\omega_1 \\gets \\Distribution{D}_1]{f(\\omega_1, \\omega_2)}}.\n  \\]\n\\end{exercise}\n\nLet us find the payoffs in the game corresponding  to\n\\Cref{table:heads-and-tales-game} if the players choose heads with the\nprobability $1 / 2$; i.e., for the strategies $\\bar{x}$ and $\\bar{y}$ such that\n$\\bar{x}(x) = \\bar{y}(y) = 1 / 2$ for all $x \\in X$ and $y \\in Y$. It is clear\nthat \n\\begin{multline*}\n  A(\\bar{x}, \\bar{y}) = \n  \\frac{1}{4} A(\\text{heads}, \\text{heads}) + \n  \\frac{1}{4} A(\\text{heads}, \\text{tails}) + \\\\\n  \\frac{1}{4} A(\\text{tails}, \\text{heads}) +\n  \\frac{1}{4} A(\\text{tails}, \\text{tails}) = 0.\n\\end{multline*}\n\nIt is clear that a mixed strategy $\\bar{x}$ such that $\\bar{x}(x) = 1$ is\nessentially the same as $x$ so we call such a strategy a \\emph{pure strategy}.\n\nThe most important result about the connection between mixed strategies and Nash\nequilibrium is von Neumann's minimax theorem.\n\\begin{theorem}[von Neumann's minimax theorem]\n\\label{theorem:von-neumanns-minimax}\n  Let $(X, Y, A, B)$ be a zero-sum matrix game. Then there are mixed\n  strategies $\\bar{x}$ and $\\bar{y}$ that are in Nash equilibrium; i.e., \n  \\begin{gather*}\n    A(\\bar{x}, \\bar{y}) \\ge A(\\bar{x}', \\bar{y}) \\\\\n    \\text{and} \\\\\n    A(\\bar{x}, \\bar{y}) \\le A(\\bar{x}, \\bar{y}')\n  \\end{gather*}\n  for all mixed strategies $\\bar{x}'$ and $\\bar{y}'$\n\\end{theorem}\nNote that this theorem can be interpreted as the following equality \n\\[\n  \\max_{\\bar{x}} \\min_{\\bar{y}} A(\\bar{x}, \\bar{y}) = \n  \\min_{\\bar{y}} \\max_{\\bar{x}} A(\\bar{x}, \\bar{y}),\n\\]\nwhich give this theorem its name.\n\n\\section{Solution of All $2 \\times 2$ Matrix Games.}\nTo better understand the notion of Nash equilibrium, let us devise a method to\nfind it for games defined by $2 \\times 2$ matrices.\n\nLet $X = Y = 0, 1$ and let $A$ be defined by the matrix \n\\[\n  \\begin{pmatrix}\n    a & b \\\\\n    d & c\n  \\end{pmatrix}.\n\\]\n\nWe need to consider two options: either there is an equilibrium in pure\nstrategies, or there is no equilibrium in pure strategies.\nIn the first case, there are $x$ and $y$ such that \n\\begin{gather*}\n  A(x, y) \\ge A(x', y) \\\\\n  \\text{and} \\\\\n  A(x, y) \\le A(x, y') \n\\end{gather*}\nfor all $x'$ and $y'$ (such a point is also called a saddle point).\n\nAssume that the game does not have a saddle point; without loss of generality we\nmay also assume that $a \\ge b$. Since $0, 1$ is not a saddle point $b < c$.\nThe pair $1, 1$ is also not a saddle point so $d < c$. Finally, $d < a$ and $a >\nb$ since $1, 0$ and $0, 0$ are not saddle points either. Consider $\\bar{x}$ such\nthat $\\bar{x}(0) = p$. Note that $A(\\bar{x}, 0) =  p a + (1 - p) d = \nd + p (a - d)$ which is increasing when $p$ is increasing and \n$A(\\bar{x}, 1) =  p b + (1 - p) c = c + p (b - c)$ which is decreasing when $p$\nis increasing. Hence, the maximum is achieved when \n$p = (c - d) / (a - b + c - d)$. Similarly we may consider $\\bar{y}$ such that\n$\\bar{y}(0) = q$, and show that $q$ should be equal to \n$(c - b) / (a - b + c - d)$.\n", "meta": {"hexsha": "d8308ba1181dbf75ae8d2c529e88161d22c45105", "size": 7324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_6/chapter_28_nash_equilibrium.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_6/chapter_28_nash_equilibrium.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_6/chapter_28_nash_equilibrium.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": 42.091954023, "max_line_length": 81, "alphanum_fraction": 0.6671217914, "num_tokens": 2271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.6060834336064505}}
{"text": "\\section{Asset Allocation with Transaction Costs}\n\n\\begin{frame}{Problem Formulation}\n\t\\onslide<1->{\n\t\\begin{block}{Investor's Goal}\n\t\tHow to dynamically invest the available capital in a portfolio of different assets in order to maximize the expected total return or another relevant performance measure.\n\t\\end{block}\n\t}\n\t\n\t\\onslide<2->{\n\t\\textbf{Rewards}: portfolio log-return with transaction costs\n\t\t\\begin{equation*}\n\t\t\tR_{t+1} = \\log \\left\\{ 1 + \\sum^{I}_{i=0} \\left[ \n\t\t\t\t\\tikz[baseline]{\n\t\t        \t\\node[anchor=base] (t1) {$a_t^i X_{t+1}^i$};\n\t\t        } - \n\t\t        \\tikz[baseline]{\n\t\t        \t\\node[anchor=base] (t2) {$\\delta_i \\left| a_t^i - \\widetilde{a}_t^i \\right|$};\n\t\t       \t} -\n\t\t       \t\\tikz[baseline]{\n\t\t       \t\t\\node[anchor=base] (t3) {$\\delta_s {(a_t^i)}^-$};\n\t\t       \t} \\right] -\n\t\t       \t\\tikz[baseline]{\n\t\t       \t\t\\node[anchor=base] (t4) {$\\delta_f \\mathbf{1}_{{a}_t \\neq \\tilde{{a}}_{t-1}}$};\n\t\t       \t} \\right\\}\t \t\n\t\t \\end{equation*}\n\t}\n\t\n\t\\onslide<7->{\n\t\\textbf{Actions}: Portfolio weights\n\t\t\\begin{equation*}\n\t\t\t\\{a_t^i\\}_{i=0}^I \\;\\;\\; \\text{s.t.}\\;\\;\\; \\sum^{I}_{i=0} a_t^i = 1 \\;\\;\\;\\;\\; \\forall t \\in \\{0, 1, 2, \\ldots\\}\n\t\t\\end{equation*}\n\t}\n\n\t\\onslide<8->{\n\t\\textbf{States}: assets past returns and current allocation\n\t\t\\begin{equation*}\n\t\t\tS_t = \\{X, X_t, X_{t-1}, \\ldots, X_{t-P}, \\tilde{a}_t\\}\n\t\t\\end{equation*}\n\t}\n\t\n\t\\onslide<3|handout:0>{\n\t\t\\begin{tikzpicture}[overlay]\n\t\t\t\t\\node[draw=SteelBlue, circle, line width=3pt, minimum size=2cm] at (t1) {};\n\t\t\\end{tikzpicture}\n\t}\n\t\n\t\\onslide<4|handout:0>{\n\t\t\\begin{tikzpicture}[overlay]\n\t\t\t\t\\node[draw=SteelBlue, circle, line width=3pt, minimum size=2cm] at (t2) {};\n\t\t\\end{tikzpicture}\n\t}\n\t\t\n\t\\onslide<5|handout:0>{\n\t\t\\begin{tikzpicture}[overlay]\n\t\t\t\t\\node[draw=SteelBlue, circle, line width=3pt, minimum size=2cm] at (t3) {};\n\t\t\\end{tikzpicture}\n\t}\n\t\t\t\n\t\\onslide<6|handout:0>{\n\t\t\\begin{tikzpicture}[overlay]\n\t\t\t\t\\node[draw=SteelBlue, circle, line width=3pt, minimum size=2cm] at (t4) (g) {};\n\t\t\\end{tikzpicture}\n\t}\n\\end{frame}\n\n\\begin{frame}[c]{Synthetic Asset: Convergence}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=5cm,width=0.8\\textwidth]{Images/6_0_single_synthetic_neutral_convergence}\n\\end{figure}\n\\end{frame}\n\n\n\\begin{frame}[c]{Synthetic Asset: Backtest Performance}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[height=6cm,width=0.8\\textwidth]{Images/6_1_single_synthetic_neutral_performance}\n\\end{figure}\n\\end{frame}\n\n\\begin{frame}[c]{Synthetic Asset: Impact of Transaction Costs}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=3cm,width=0.8\\textwidth]{Images/6_2_impact_transaction_costs}\n\\end{figure}\n\\begin{figure}[t!]\n\t\\centering\n\t\\includegraphics[height=3cm,width=0.8\\textwidth]{Images/6_3_impact_short_selling_fees}\n\\end{figure}\n\\end{frame}\n\n\\begin{frame}{Not So Fast}\n\n\t\\onslide<1->{\n\t\\begin{columns}\n\t\\begin{column}{0.6\\textwidth}\n\t   \\begin{alertblock}{Insuccess on Historical Data}\n\t   Successfully applying these RL algorithms to historical data is much more challenging\n\t   \\begin{enumerate}\n\t   \t\t\\item Fail to converge\n\t   \t\t\\item The strategies learned are not profitable\n\t   \\end{enumerate}\n\t   \\end{alertblock}\n\t\\end{column}\n\t\\begin{column}{0.4\\textwidth}\n\t    \\begin{center}\n\t     \\includegraphics[width=1\\textwidth]{Images/8_9_single_hist_neutral_performance}\n\t     \\end{center}\n\t\\end{column}\n\t\\end{columns}\n\t}\n\t\n\t\\onslide<2->{\t\n\t\\begin{block}{Possible Explanations}\n\t\t\\begin{enumerate}\n\t\t\t\\item<2-> \\textbf{Low signal-to-noise ratio}: extremely difficult to find tradable patterns in markets\n\t\t\t\\item<3-> \\textbf{Quality of data}: unlikely to find patterns in daily prices of liquid stocks\n\t\t\t\\item<4-> \\textbf{Weak features}: parametric policy must be powerful enough to capture the signal\n\t\t\t\\item<5-> \\textbf{Non-stationarity of financial time-series}: a signal needs to be persistent\n\t\t\\end{enumerate}\n\t\\end{block}\n\t}\n\n\\end{frame}\n\n", "meta": {"hexsha": "19e8ccadfefa2da1f99f585d25f6c4b036d69f66", "size": 3882, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Presentation/Sections/3_asset_allocation_problem.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": "Presentation/Sections/3_asset_allocation_problem.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": "Presentation/Sections/3_asset_allocation_problem.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": 30.328125, "max_line_length": 172, "alphanum_fraction": 0.670015456, "num_tokens": 1384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219505, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6060834287888358}}
{"text": "\\subsection{Jianqing's summary}\n\\subsubsection{Fast autoaugment details}\nLet $\\mathbb{O}$ be a set of augmentation (image transformation) operations\n$\\mathcal{O}$:$\\mathcal{X}\\rightarrow\\mathcal{X}$ defined on the input image space $\\mathcal{X}$. Each operation $\\mathcal{O}$ have two parameters: the calling probability $p$ and the magnitude $\\lambda$ which determines the variability of operation. Let $\\mathcal{S}$ be the set of sub-policies where a sub-policy $\\tau \\in \\mathcal{S}$ consists of $N_{\\tau}$ consecutive operations\n\\{$\\mathcal{O}_n^{(\\tau)}$($x$;$p_n^{(\\tau)}$,$\\lambda_n^{(\\tau)}$):$n$=1,\\ldots,$N_\\tau$\\}\n$$\\mathcal{O}(x;p,\\lambda):=\\left\\{\n\\begin{aligned}\n\\mathcal{O}(x;\\lambda) &&with&&probability&& p \\\\\nx&&with&&probability&&1-p\n\\end{aligned}\n\\right.\n$$\nThe output of sub-policy $\\tau(x)$ can be described by a composition of operations as:\\\\\n\\begin{equation}\n\\tilde{x}_{(n)}=\\mathcal{O}_n^{(\\tau)}(\\tilde{x}_{(n-1)}),n=1,\\ldots,N_{\\tau}\n\\end{equation}\n\nFigure 1 shows a specific example of augmented images by $\\tau$ .\nNote that each sub-policy $\\tau$ is a random sequence of image transformations which depend on $p$ and $\\lambda$,and this enables to cover a wide range of data augmentations.\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{fast_fig_1.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\nFinal policy $T$ is a collection of $N_T$ sub-policies and $T(D)$ indicates a set of augmented images of dataset $D$ transformed by every\nsub-policies $\\tau\\in T$ :\n\\begin{equation}\nT(D)=\\cup_{\\tau \\in T}\\{(\\tau(x),y):(x,y)\\in D\\}\n\\end{equation}\nUse both continuous values of probability $p$ and magnitude $\\lambda$ at $[0; 1]$ which has more possibilities than discretized search space.\n\n\nConsider searching the augmentation policy as a density matching between\na pair of datasets. Let $\\mathcal{D}$ be a probability distribution on $\\mathcal{X}\\times\\mathcal{Y}$ and assume dataset $D$ is sampled\nfrom this distribution. For a given classification model $\\mathcal{M}(\\cdot|\\theta)$ : $\\mathcal{X}\\times\\mathcal{Y}$ that is parameterized by $\\theta$, the expected accuracy and the expected loss of $\\mathcal{M}(\\cdot|\\theta)$ on dataset $D$ are denoted by $\\mathcal{R}(\\theta |D)$ and $\\mathcal{L}(\\theta |D)$.\n\nFor any given pair of $D_{train}$ and $D_{valid}$, our goal is to improve the generalization ability by searching\nthe augmentation policies that match the density of $D_{train}$ with density of augmented $D_{valid}$.\nIt is impractical to compare these two distributions directly for an evaluation of every candidate policy.\nPerform this evaluation by measuring how much one dataset follows the pattern of the other by making use of the model predictions on both datasets.\n\nSplit $D_{train}$ into $D_{M}$ and $D_{A}$ that are used for learning the model parameter $\\theta$ and exploring the augmentation policy $T$.Employ the following objective to find a set of learned augmentation policies\n\\begin{equation}\nT_{*}=argmax_T \\mathcal{R}(\\theta^*|T(D_A))\n\\end{equation}\nwhere model parameter $\\theta^*$ is trained on $D_{M}$.It is noted that in this objective, $T_{*}$ approximately minimizes the distance between density of $D_{M}$ and density of $T(D_A)$ from the perspective of maxmizing the performance of both model predictions with the same parameter $\\theta$.\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{fast_fig_2.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\nTo achieve (3), we propose an efficient strategy for augmentation policy search (see Figure 2). First,we conduct the K-fold stratified shuffling to split the train dataset into $D_{train}^{(1)},...,D_{train}^{(m)}$ where each $D_{train}^{(k)}$ consists of two datasets $D_M^{k}$ and $D_A^{k}$. Next, we train model parameter $\\theta$ on $D_M$ from scratch without data augmentation.\n\nAfter training the model parameter,for each step $1\\leq t\\leq T$, explore $B$ candidate policies\n$\\mathcal{B}=\\{T_1,\\ldots,T_B\\}$via Bayesian optimization method which repeatedly samples a sequence of\nsub-policies from search space $\\mathcal{S}$ to construct a policy $T=\\{\\tau_1,\\ldots,\\tau_{N_\\tau}\\}$ and tunes corresponding\ncalling probabilities $\\{p_1,\\ldots,p_{N_\\tau}\\}$ and magnitudes $\\{\\lambda_1,\\ldots,\\lambda_{N_\\tau}\\}$ to minimize the expected loss\n$\\mathcal{L}(\\theta |\\cdot)$ on augmented dataset $T(D_A)$.\n\nAs the algorithm completes the exploration step, select top-N policies over $\\mathcal{B}$ and denote them $T_t$,Finally, merge every $T_t$ into $T_*$. Augment the whole dataset $D_{train}$ with $T_*$ and retrain the model parameter $\\theta$.Through the proposed method, we can expect the performance $\\mathcal{R}(\\theta|\\cdot)$ on augmented dataset $T_*(D_A)$\nis statistically higher than that on $D_A$:\n\\begin{equation}\n\\mathcal{R}(\\theta|T_*(D_A))\\geq\\mathcal{R}(\\theta|D_A)\n\\end{equation}\n\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{fast_fig_3.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\n\\subsubsection{SGDR}\n\\begin{equation}\n\\eta_t = \\eta_{min} + \\frac{1}{2}(\\eta_{max} - \\eta_{min})\\left(1 +\\cos\\left(\\frac{T_{cur}}{T_{i}}\\pi\\right)\\right)\n\\end{equation}\n\nwhere $\\eta_{min}^i$ and $\\eta_{max}^i$  are ranges for the learning rate, and $T_{cur}$ accounts for how many epochs have been performed since the last restart. Since $T_{cur}$ is updated at each batch iteration $t$. Thus, $\\eta_t = \\eta_{max}^i$ when $t = 0$ and $T_{cur} = 0$. Once $T_{cur} = T_i$, the cos function will output $-1$ and thus $\\eta_t = \\eta_{min}^i$. The decrease of the learning rate is shown in Figure 4 for fixed $T_i = 50$, $T_i = 100$ and $T_i = 200$.\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{SGDR.png}\n\t%\\caption{SGDR}\\label{}\n\\end{figure}\n\n\\subsubsection{Experient result in Cifar100}\nInit learning rate:0.1\\\\\nNormal augment:ramdom crop and random horizontal flip.\\\\\n\\begin{tabular}{| l | c | c | c | c | c | r |}\n\t\\hline\n\tAugment & Optim & Learning rate & Warm up & Epoch & Train acc & Valid acc \\\\\n\t\\hline\n\tFAA   & SGD   & cosine        & Yes     & 3000  & 97.9\\%    & 81.6\\%\\\\\n\t\\hline\n\tNormal   & SGD   & cosine        & Yes     & 3000  & 99.9\\%    & 80.3\\%\\\\\n\t\\hline\n\tNormal   & SGD   & cosine        & No      & 3000  & 99.9\\%    & 79.2\\%\\\\\n\t\\hline\n\\end{tabular}\n\n\\subsubsection{Experient result in Linear Constraint ResNet}\nAll experients use same setup:600epoch, leanring rate:initial value is 0.1 and using cosine method to decrease,warmup,SGD.\\\\\n\\begin{tabular}{| l | c | c | c | r |}\n\t\\hline\n\tNetwork                            &Augment   & Paper acc &  acc      &  Parameters\\\\\n\t\\hline\n\tpre-act ResNet18$(A^{l,i},B^{l,i})$ & Normal   &   74.33\\%  & 78.70\\%  &   11M\\\\\n\t\\hline\n\tpre-act ResNet18$(A^{l,i},B^{l,i})$ &   FAA    &            & 78.30\\%  &   11M\\\\\n\t\\hline\n\tpre-act ResNet18$(A^l,B^{l,i})$     & Normal   &    74.51\\% & 77.69\\%  &   8.1M\\\\\n\t\\hline\n\tpre-act ResNet18$(A^l,B^{l,i})$     & FAA      &            & 78.92\\%  &   8.1M\\\\\n\t\\hline\n\tpre-act ResNet34$(A^{l,i},B^{l,i})$ & Normal   &    77.25\\% & 78.28\\%  &   21M\\\\\n\t\\hline\n\tpre-act ResNet34$(A^{l,i},B^{l,i})$ &   FAA    &            & 80.29\\%  &   21M\\\\\n\t\\hline\n\tpre-act ResNet34$(A^l,B^{l,i})$     & Normal   &   77.40\\%  & 79.63\\%  &   13M\\\\\n\t\\hline\n\tpre-act ResNet34$(A^l,B^{l,i})$     & FAA      &             & 80.53\\% &   13M\\\\\n\t\\hline\n\\end{tabular}\n\nAs can be seen from the above table, the accuracy using normal augmentation methods is higher than the paper, which may be due to multiple epochs and different learning rate methods. Except the pre-act ResNet18$(A^{l,i},B^{l,i})$,using FAA can impove the accuracy, it's doubt that the accuracy of pre-act ResNet18$(A^{l,i},B^{l,i})$, I will do exoerients to verify. In FAA experients, the training accuracy in 600epoch about 0.97, I guess trainning more epoch will get better auuracy.\n\n\\subsubsection{wresnet under different augment number}\nIn wresnet 40*2 network, using cosine learning rate method and initial is 0.1, under different augment method, the probability is 0.5 for every sub-policy. The result in le below table.\\\\\n\\begin{tabular}{| l | c | c | c | c | r |}\n\t\\hline\n\tpolicy num   & train acc & train+aug acc & test accuracy  &  test+aug acc & test acc drop\\\\\n\t\\hline\n\t2          &  99.97   & 99.97       &  75.45         &   74.60            &  0.85\\\\\n\t\\hline\n\t4          &  99.97   & 99.88       &  75.30         &   73.73            &  1.57\\\\\n\t\\hline\n\t6          &  99.97   & 97.46       &  77.50         &   73.90            &  3.60\\\\\n\t\\hline\n\t8          &  99.97   & 97.80       &  77.01         &   73.69            &  3.32\\\\\n\t\\hline\n\t25         &  99.96   & 96.83       &  77.11         &   72.96            &  4.15\\\\\n\t\\hline\n\t50         &  99.95   & 96.61       &  77.22         &   73.54            &  3.68\\\\\n\t\\hline\n\t75         &  99.92   & 96.47       &  76.77         &   73.07            &  3.70\\\\\n\t\\hline\n\t100        &  99.96   & 96.52       &  77.13         &   72.32            &  4.81\\\\\n\t\\hline\n\t125        &  99.96   & 96.70       &  77.37         &   72.64            &  4.73\\\\\n\t\\hline\n\t150        &  99.95   & 96.40       &  77.25         &   73.24            &  4.01\\\\\n\t\\hline\n\t175        &  99.96   & 96.49       &  77.72         &   73.19            &  4.53\\\\\n\t\\hline\n\t200        &  99.92   & 95.93       &  77.27         &   72.67            &  4.60\\\\\n\t\\hline\n\t225        &  99.95   & 96.42       &  77.61         &   72.70            &  4.91\\\\\n\t\\hline\n\t250        &  99.96   & 96.56       &  77.04         &   72.81            &  4.23\\\\\n\t\\hline\n\t275        &  99.94   & 96.49       &  77.22         &   72.95            &  4.27\\\\\n\t\\hline\n\t300        &  99.94   & 96.61       &  77.66         &   73.52            &  4.14\\\\\n\t\\hline\n\t325        &  99.94   & 96.36       &  77.27         &   73.27            &  4.00\\\\\n\t\\hline\n\t350        &  99.95   & 96.56       &  77.26         &   72.79            &  4.47\\\\\n\t\\hline\n\t375        &  99.95   & 96.64       &  77.46         &   72.74            &  4.72\\\\\n\t\\hline\n\t400        &  99.95   & 96.49       &  76.78         &   73.02            &  3.66\\\\\n\t\\hline\n\t425        &  99.96   & 96.48       &  77.30         &   73.27            &  4.03\\\\\n\t\\hline\n\t450        &  99.95   & 96.51       &  77.42         &   73.40            &  4.02\\\\\n\t\\hline\n\t475        &  99.95   & 96.42       &  76.66         &   72.81            &  3.85\\\\\n\t\\hline\n\t497        &  99.93   & 95.99       &  76.88         &   72.47            &  4.41\\\\\n\t\\hline\n\\end{tabular}\n\nI guess cutout is one of the reasons for this, so next I remove cutout for FAA, and do some experients, the result in the below table.\\\\\n\\begin{tabular}{| l | c | c | c | c | r |}\n\t\\hline\n\tpolicy num   & train acc & train+aug acc & test accuracy  &  test+aug acc & test acc drop\\\\\n\t\\hline\n\t1          &  99.98   & 99.97       &  75.21         &   74.77            &  0.44\\\\\n\t\\hline\n\t2          &  99.97   & 99.96       &  75.14         &   74.44            &  0.70\\\\\n\t\\hline\n\t3          &  99.89   & 99.89       &  75.05         &   73.77            &  1.28\\\\\n\t\\hline\n\t4          &  99.88   & 99.88       &  75.26         &   74.10            &  1.16\\\\\n\t\\hline\n\t5          &  99.64   & 99.62       &  75.70         &   73.70            &  2.00\\\\\n\t\\hline\n\t6          &  97.56   & 97.61       &  76.99         &   73.91            &  3.08\\\\\n\t\\hline\n\t7          &  97.72   & 97.86       &  77.59         &   73.89            &  3.70\\\\\n\t\\hline\n\t8          &  97.80   & 97.76       &  76.90         &   73.60            &  3.30\\\\\n\t\\hline\n\t9          &  96.93   & 96.97       &  77.62         &   72.95            &  4.67\\\\\n\t\\hline\n\t10         &  97.16   & 96.98       &  77.90         &   73.32            &  4.58\\\\\n\t\\hline\n\t25         &  96.36   & 96.51       &  76.84         &   72.88            &  3.96\\\\\n\t\\hline\n\t50         &  96.12   & 95.97       &  77.41         &   73.18            &  4.23\\\\\n\t\\hline\n\t75         &  96.57   & 96.70       &  77.02         &   72.95            &  4.07\\\\\n\t\\hline\n\t100        &  96.46   & 96.34       &  77.31         &   73.58            &  3.73\\\\\n\t\\hline\n\\end{tabular}\n\nWe can see that if $N$ is small number, the drop test accuracy is upward trend, but when $N>10$, the trend is vanish.\\\\\n\n\\subsubsection{wresnet under different probability}\nUsing differenr $p$, the result in below table.\\\\\n\\begin{tabular}{| l | c | c | c | c | r |}\n\t\\hline\n\tp          & train acc & train+aug acc & test accuracy  &  test+aug acc & test acc drop\\\\\n\t\\hline\n\t0.0          &  99.97   & 99.97       &  74.78         &   74.11            &   0.67  \\\\\n\t\\hline\n\t0.1          &  99.97   & 98.53       &  76.44         &   74.56            &   1.88  \\\\\n\t\\hline\n\t0.2          &  99.96   & 97.83       &  76.72         &   73.68            &   3.04  \\\\\n\t\\hline\n\t0.3          &  99.96   & 97.35       &  76.75         &   73.92            &   2.83  \\\\\n\t\\hline\n\t0.4          &  99.96   & 96.83       &  76.78         &   73.45            &   3.33  \\\\\n\t\\hline\n\t0.5          &  99.96   & 96.66       &  77.07         &   72.61            &   4.46  \\\\\n\t\\hline\n\t0.6          &  99.95   & 95.91       &  77.29         &   72.75            &   4.54  \\\\\n\t\\hline\n\t0.7          &  99.93   & 95.51       &  77.67         &   72.59            &   5.08  \\\\\n\t\\hline\n\t0.8          &  99.92   & 95.13       &  77.67         &   72.05            &   5.62  \\\\\n\t\\hline\n\t0.9          &  99.91   & 94.27       &  77.68         &   71.25            &   6.43  \\\\\n\t\\hline\n\t1.0          &  99.75   & 93.22       &  77.67         &   70.31            &   7.36  \\\\\n\t\\hline\n\\end{tabular}\n\n\\subsubsection{Use SE block in MgNet}\n\\subsubsection{SE block}\nThe structure of the SE building block is depicted in Fig. 1. For any given transformation $F_{tr}$ mapping the input $X$ to the feature maps $U$ where $U \\in R^{H*W*C}$,we can construct a corresponding SE block to perform feature recalibration. The features $U$ are first passed through a squeeze operation, which produces a channel descriptor by aggregating feature maps across their spatial dimensions $(H*W)$. The function of this descriptor is to produce an embedding of the global distribution of channel-wise feature responses, allowing information from the global receptive field of the network to be used by\nall its layers. The aggregation is followed by an excitation operation, which takes the form of a simple self-gating mechanism that takes the embedding as input and produces a collection of per-channel modulation weights. These weights are applied to the feature maps $U$ to generate the output of the SE block which can be fed directly into subsequent layers of the network.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{seblock.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\nSqueeze: Global Information Embedding\\\\\nIn order to tackle the issue of exploiting channel dependencies, we first consider the signal to each channel in the output features. Each of the learned filters operates with a local receptive field and consequently each unit of the transformation output $U$ is unable to exploit contextual\ninformation outside of this region. To mitigate this problem, we propose to squeeze global spatial information into a channel descriptor. This is\nachieved by using global average pooling to generate channel-wise statistics. Formally, a statistic $z \\in R^C$ is generated by shrinking $U$ through its spatial dimensions $H*W$, such that the c-th element of z is calculated by:\n\\begin{equation}\nz_c=F_{sq}(u_c)=\\frac{1}{H*W}\\sum_{i=1}^H\\sum_{j=1}^Wu_c(i,j)\n\\end{equation}\nExcitation: Adaptive Recalibration\\\\\nTo make use of the information aggregated in the squeeze operation, we follow it with a second operation which aims to fully capture channel-wise dependencies. To fulfil this objective, the function must meet two criteria: first, it must be flexible (in particular, it must be capable of learning\na nonlinear interaction between channels) and second, it must learn a non-mutually-exclusive relationship since we would like to ensure that multiple channels are allowed to be emphasised (rather than enforcing a one-hot activation). To meet these criteria, we opt to employ a simple gating mechanism with a sigmoid activation:\n\\begin{equation}\ns = F_{ex}(z,W)=\\sigma(g(z,W)) = \\sigma(W_2\\delta(W_1z))\n\\end{equation}\nwhere $\\delta$ refers to the ReLU function,$W_1 \\in  R^{\\frac{C}{r}*C}$ and$W_2 \\in  R^{C*\\frac{C}{r}}$. To limit model complexity and aid generalisation, we parameterise the gating mechanism by forming a bottleneck with two fully-connected (FC) layers around the non-linearity, i.e. a dimensionality-reduction layer with reduction ratio $r$, a ReLU and then a dimensionality-increasing layer returning to the channel dimension of the transformation output $U$. The final output of the block is obtained by rescaling $U$ with the activations $s$:\n\\begin{equation}\nx_c = F_{scale}(u_c,s_c) = s_cu_c\n\\end{equation}\nwhere $X = [x_1,x_2,\\dot ,x_C]$and $F_{scale}(u_c,s_c)$ refers to\nchannel-wise multiplication between the scalar sc and the\nfeature map $u_c \\in R^{H*W}$.\n\n\n\\subsubsection{Add SE block in MgNet}\nModle:MgNet,[2,2,2,2],256 chanels. Add SE block in the end of every Extraction and Restriction block.The result in below table.\\\\\n\\begin{tabular}{| l | c | c | c | r |}\n\t\\hline\n\tAdd SE & FAA & epoch & train acc & test acc \\\\\n\t\\hline\n\tNo     & No  &  300  & 99.95     & 77.64    \\\\\n\t\\hline\n\tYes    & No  &  300  & 99.97     & 78.66    \\\\\n\t\\hline\n\tNo     & Yes &  300  & 79.36     & 73.65    \\\\\n\t\\hline\n\tYes    & Yes &  300  & 95.95     & 80.17    \\\\\n\t\\hline\n\tYes    & Yes &  500  & 97.87     & 80.96    \\\\\n\t\\hline\n\\end{tabular}\n\nNew result:\\\\\n\\begin{tabular}{| l | c | c | c | r |}\n\t\\hline\n\tAdd SE & FAA & epoch & train acc & test acc \\\\\n\t\\hline\n\tNo     & No  &  500  & 99.72     & 79.16    \\\\\n\t\\hline\n\tYes    & No  &  500  & 99.68     & 80.04    \\\\\n\t\\hline\n\tYes    &Yes  &  500  & 96.79    &  81.85    \\\\\n\t\\hline\n\\end{tabular}\n\nWe can conclude that adding SE block in Mgnet will impove trainning accuracy. We only add SE block in the feature space$U$,next,we will test SE block in Image space $F$, and the number of SE block.\\\\\n\n\\subsubsection{Using SOTA tricks in MgNet}\n\\begin{itemize}\n\t\\item Aim:Using the SOTA tricks in MgNet, and get the best performance in the MgNet.\\\\\n\t\\item Approch:All the tricks are divided into three methods: data processing, network structure optimization and training algorithm, study the performance of networks with or without every trick, \\\\\n\t\\item Network:MgNet[2,2,2,2],ResNet-18,pre-act ResNet-18,WResNet40*2\\\\\n\t\\item Dataset:Cifar100,Cifar10\\\\\n\t\\item Timetabel:Plan to complete one or two projects a week.\n\\end{itemize}\n\n\n\\begin{tabular}{| l |  c  | r |}\n\t\\hline\n\tDataset             &      Network   &           Train Algorithm\\\\\n\t\\hline\n\tCutout              &       SE       &            \\\\\n\t\\hline\n\tMixup               &       GE       &            \\\\\n\t\\hline\n\tCutmix              &       SK       &             \\\\\n\t\\hline\n\tFAA                 &                &             \\\\\n\t\\hline\n\\end{tabular}\n\n\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=14cm]{dataset-duibi.jpg}\n\t\\caption{Three different dataset augment methods.}\\label{Three different dataset augment methods.}\n\\end{figure}\n\n%\\subsubsection{Cutout}\n%\\begin{figure}[H]\n%  \\centering\n%  % Requires \\usepackage{graphicx}\n%  \\includegraphics[width=13cm]{cutout.jpg}\n%%  %\\caption{}\\label{}\n%\\end{figure}\n\n\\subsubsection{Mixup}\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=10cm]{mixup.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\n\\subsubsection{CutMix}\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=10cm]{cutmix.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\n\\subsubsection{GE}\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=18cm]{GE.png}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\n\\subsubsection{SK}\n\\begin{figure}[H]\n\t\\centering\n\t% Requires \\usepackage{graphicx}\n\t\\includegraphics[width=12cm]{SK.jpg}\n\t%  %\\caption{}\\label{}\n\\end{figure}\n\n\n\\newpage\n\\subsubsection{Add or not add cutout in different models result}\n\\quad\nTable 1:The accuracy in cifar10 for different models.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &          95.28         &     94.56          \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &          94.40         &     94.82          \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &          94.67         &     95.17          \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &          96.12         &     96.06          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-256         &      8.2M       &                        &     96.00          \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-256         &      8.3M       &                        &     95.98          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512         &      33.1M       &                        &               \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nTable 2:The accuracy in cifar10 for different models with cutout=16.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &          96.01         &     95.19          \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &                        &     95.74          \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &          95.88         &     95.87          \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &          96.92         &     96.95          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-256         &      8.2M       &                        &     96.89          \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-256         &      8.3M       &                        &     96.90          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512         &      33.1M       &                        &    97.13          \\\\\n\t\\hline\n\\end{tabular}\n\n\n\\vbox{}\nTable 3:The accuracy in cifar10 for different models with FAA.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &                         &      96.46         \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &                         &                  \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &         96.30           &              \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &         97.30           &               \\\\\n\t\\hline\n\tMgNet[2,2,2,2]         &      8.2M       &                         &       97.29         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]         &      8.3M       &                         &       97.51          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512     &      33.1M      &                        &       97.81         \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512,lr:resnet&      33.1M      &              &                \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nTable 4:The accuracy in cifar100 for different models.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &            77.54       &       76.38(75.38)        \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &            74.40       &       75.68        \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &            74.00       &              \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &            81.20       &               \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-256     &      8.2M       &                        &       79.23         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-256     &      8.3M       &                        &       79.66           \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512     &      33.1M      &                        &       80.43         \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512,lr:resnet &      33.1M      &                        &       81.12         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-512     &      33.1M      &                        &       80.78         \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nTable 5:The accuracy in cifar100 for different models with cutout=16.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &         78.04           &      76.28         \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &                         &      76.63         \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &         74.80           &              \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &         81.60           &               \\\\\n\t\\hline\n\tMgNet[2,2,2,2]         &      8.2M       &                         &       80.93         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]         &      8.3M       &                         &       81.63          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512     &      33.1M      &                        &       81.83         \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512,lr:resnet  &      33.1M      &                        &                \\\\\n\t\\hline\n\\end{tabular}\n\n\n\n\\vbox{}\nTable 6:The accuracy in cifar100 for different models with FAA.\\\\\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\tNetwork                &     Parameters   &       paper accuracy   &   my accuracy     \\\\\n\t\\hline\n\tResNet18               &      11.2M      &                         &      79.47         \\\\\n\t\\hline\n\tPreActResNet18         &      11.2M      &                         &                  \\\\\n\t\\hline\n\tWide ResNet(40*2)      &      2.2M       &         79.40           &              \\\\\n\t\\hline\n\tWide ResNet(28*10)     &      36.5M      &         82.70           &               \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-256     &      8.2M       &                         &       82.66         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-256     &      8.3M       &                         &       83.51          \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512     &      33.1M      &                        &       83.75(3)         \\\\\n\t\\hline\n\tMgNet[2,2,2,2]-512,lr:resnet&      33.1M      &              &       83.33         \\\\\n\t\\hline\n\tMgNet[3,4,6,3]-512     &      33.1M      &              &       84.14         \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nTable 7: The accuracy in cifar100 for MgNet with FAA.\\\\\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                             &     Parameters   &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2],[64,128,256,512]     &      9.9M        &        64.36      \\\\\n\t\\hline\n\\end{tabular}\n\\vbox{}\n\n\n\\subsubsection{Multi-step MgNet}\nChebyshev-semi MgNet:\\\\\n\\begin{equation}\nu^{l,i} = \\omega ^{l,i}(u^{l,i-1} + B^{l,i}(f^l - A^l(u^{{l,i-1}}))) + (1 - \\omega ^{l,i})u^{l,i-2},i = 1:v_l\n\\end{equation}\n\nChoose $\\omega ^{l,i} = \\frac{1}{2}$, the cifar100 results are shown in the table below:\\\\\n\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                  &     Parameters   &       accuracy  \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256,C     &      8.3M        &        79.48    \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256       &      8.3M        &        79.23    \\\\\n\t\\hline\n\tMgNet[3,4,6,3],256,C     &      8.3M        &        80.04    \\\\\n\t\\hline\n\tMgNet[3,4,6,3],256       &      8.3M        &        79.66    \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nChange Chebyshev-semi MgNet into below formula:\\\\\n\\begin{equation}\nu^{l,i} = \\alpha_1 ^{l,i}(u^{l,i-1} + B^{l,i}(f^l - A^l(u^{{l,i-1}}))) + \\alpha_2 ^{l,i}u^{l,i-2},i = 1:v_l\n\\end{equation}\n\\vbox{}\n$\\alpha_1$ and $\\alpha_2$ can use trianable parameter or take the definite value.\\\\\n\n\\begin{tabular}{| l | c | c | r |}\n\t\\hline\n\t$\\alpha$ mode &     Network             &     Parameters   &       accuracy   \\\\\n\t\\hline\n\ttrainable     &    MgNet[4,2,2,2],256   &       8.3M       &        79.43   \\\\\n\t\\hline\n\ttrainable     &    MgNet[4,4,4,4],256   &       8.3M       &        79.74   \\\\\n\t\\hline\n\ttrainable     &    MgNet[6,2,2,2],256   &       8.3M       &        79.98 \\\\\n\t\\hline\n\t&                         &                  &              \\\\\n\t\\hline\n\t0.5           &    MgNet[4,2,2,2],256   &       8.3M       &        80.96 \\\\\n\t\\hline\n\t0.5           &    MgNet[4,4,4,4],256   &       8.3M       &        80.87 \\\\\n\t\\hline\n\t0.5           &    MgNet[6,2,2,2],256   &       8.3M       &        81.42 \\\\\n\t\\hline\n\t0.5           &    MgNet[8,2,2,2],256   &       8.3M       &        81.32 \\\\\n\t\\hline\n\t&                         &                  &              \\\\\n\t\\hline\n\t1             &    MgNet[4,2,2,2],256   &       8.3M       &        80.99 \\\\\n\t\\hline\n\t1             &    MgNet[4,4,4,4],256   &       8.3M       &        79.28 \\\\\n\t\\hline\n\t1             &    MgNet[6,2,2,2],256   &       8.3M       &        80.87 \\\\\n\t\\hline\n\t1             &    MgNet[8,2,2,2],256   &       8.3M       &        80.50 \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nMulti-step MgNet:\\\\\n\\begin{equation}\nu^{l,i} = \\sum _{j=0}^{i-1}\\alpha _j^{l,i}(u^{l,j} + B_j^{l,i}(f^l-A^l(u^{l,j}))),i = 1:v_l\n\\end{equation}\n\n\\begin{equation}\nu^{l,i} = \\alpha_1(u^{l,i-1}+B^{l,i-1}(f^l-A^l(u^{l,j}))) + \\alpha_2\\sum _{j=0}^{i-2}(u^{l,j} + B_j^{l,i}(f^l-A^l(u^{l,j}))),i = 1:v_l\n\\end{equation}\n\n\\vbox{}\nchoose $\\alpha_1=\\alpha_2=0.5$, have below result:\\\\\n\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                  &     Parameters   &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256     &      8.3M          &        79.94       \\\\\n\t\\hline\n\tMgNet[4,2,2,2],256     &      8.3M          &        80.24       \\\\\n\t\\hline\n\tMgNet[4,4,4,4],256     &      8.3M          &        80.38      \\\\\n\t\\hline\n\tMgNet[6,2,2,2],256     &      8.3M          &        80.27       \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nchoose $\\alpha_1=\\alpha_2=1$, have below result:\\\\\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                &     Parameters     &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256     &      8.3M          &        78.86       \\\\\n\t\\hline\n\tMgNet[4,2,2,2],256     &      8.3M          &        79.72       \\\\\n\t\\hline\n\tMgNet[6,2,2,2],256     &      8.3M          &        79.67       \\\\\n\t\\hline\n\tMgNet[8,2,2,2],256     &      8.3M          &        79.45       \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nchoose $\\alpha_1=\\alpha_2=trainable$, have below result:\\\\\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                &     Parameters     &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256     &      8.3M          &        76.52       \\\\\n\t\\hline\n\tMgNet[4,2,2,2],256     &      8.3M          &        79.90       \\\\\n\t\\hline\n\tMgNet[6,2,2,2],256     &      8.3M          &        80.40       \\\\\n\t\\hline\n\tMgNet[8,2,2,2],256     &      8.3M          &               \\\\\n\t\\hline\n\\end{tabular}\n\n\\vbox{}\nchoose $\\alpha_1=1,\\alpha_2=trainable$, have below result:\\\\\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                &     Parameters     &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2],256     &      8.3M          &        79.32       \\\\\n\t\\hline\n\tMgNet[4,2,2,2],256     &      8.3M          &        79.89       \\\\\n\t\\hline\n\tMgNet[6,2,2,2],256     &      8.3M          &                    \\\\\n\t\\hline\n\tMgNet[8,2,2,2],256     &      8.3M          &                    \\\\\n\t\\hline\n\\end{tabular}\n\n\\subsubsection{Retrieval DenseNet in cifar100 result}\n\\begin{tabular}{| l   | c | c  | r |}\n\t\\hline\n\tNetwork                  &     Parameters   &       my accuracy  & paper accuracy   \\\\\n\t\\hline\n\tDenseNet(k=12,100)       &     0.8M         &       76.91        & 77.63 \\\\\n\t\\hline\n\tDenseNet(k=24,250)       &     15.3M         &      81.03        & 82.40 \\\\\n\t\\hline\n\\end{tabular}\n\n\\subsubsection{Increasing the number of channels in MgNet }\nIn the previous , the number of channels in MgNet is a fixed value, such as 256,this will greatly increase the parameters of the first module. In this seceion, we will increasing channel number in each MgNet block.\\\\\n\\vbox{}\n\\begin{tabular}{| l | c | r |}\n\t\\hline\n\tNetwork                  &     Parameters   &       accuracy   \\\\\n\t\\hline\n\tMgNet[2,2,2,2]           &      9.4M        &      79.28  \\\\\n\t\\hline\n\tMgNet[4,2,2,2]           &      9.4M        &      79.27  \\\\\n\t\\hline\n\tMgNet[6,2,2,2]           &      9.4M        &      79.71  \\\\\n\t\\hline\n\tMgNet[10,2,2,2]          &      9.4M        &      78.52  \\\\\n\t\\hline\n\tMgNet[4,4,4,4]           &      9.4M        &      78.32  \\\\\n\t\\hline\n\tMgNet[3,4,6,3]           &      9.4M        &      78.30  \\\\\n\t\\hline\n\tMgNet[2,2,2,6]           &      9.4M        &      77.87  \\\\\n\t\\hline\n\\end{tabular}\n\n\\newpage\n\\section{MgNet test in Imagenet}\n\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | c | r |}\n\t\t\\hline\n\t\tmodel          &   num ite                 &      channels          &     paras   &   epoch      &    last  acc  &  max  acc \\\\\n\t\t\\hline\n\t\t%MgNet          &   3,3,5,2(wise-B)         &  [64,128,256,512]      &   14.98M    &  160         &    74.98      & 75.13     \\\\\n\t\t%\\hline\n\t\t%MgNet          &   3,4,6,3(wise-B)         &  [64,128,256,512]      &   18.08M    &  160         &    75.63      & 75.73     \\\\\n\t\t%\\hline\n\t\t%MgNet          &   2,2,2,2(not wise-B)     &  [128,256,512,1024]    &   38.52M    &  160         &    76.74      & 76.82     \\\\\n\t\t%\\hline\n\t\t%MgNet          &   2,2,2,2(wise-B)         &  [128,256,512,1024]    &   51.05M    &  160         &    77.17      & 77.27     \\\\\n\t\t%\\hline\n\t\t%MgNet          &   2,2,4,2(not wise-B)     &  [128,256,512,1024]    &   38.52M    &  160         &    77.41      & 77.58     \\\\\n\t\t%\\hline\n\t\t%MgNet          &   2,2,4,2(wise-B)         &  [128,256,512,1024]    &   55.77M    &  160         &    77.89      & 77.94     \\\\\n\t\t%\\hline\n\t\tDenseNet-121   &   6,12,24,16              &  -                     &     9M      &              &    -          & 74.98     \\\\\n\t\t\\hline\n\t\tDenseNet-169   &   6,12,32,32              &  -                     &     14M     &              &    -          & 76.20     \\\\\n\t\t\\hline\n\t\tDenseNet-201   &   6,12,48,32              &  -                     &     20M     &              &    -          & 77.42     \\\\\n\t\t\\hline\n\t\tDenseNet-264   &   6,12,64,48              &  -                     &     33M     &              &    -          & 77.85     \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\\subsection{Huang Huang's results}\n\\subsubsection{Fix channel in MgNet}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite    &      channels      &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2,2]   &         256        &    8.5M         &   70.83           &  71.01          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsubsection{Increase channel in MgNet}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite    &      channels      &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2,2]   &  [64,128,256,512]  &    9.9M         &   72.32           &  72.32          \\\\\n\t\t\\hline\n\t\t[2,2,4,2]   &  [64,128,256,512]  &    9.9M         &   73.04           &  73.04          \\\\\n\t\t\\hline\n\t\t[2,2,8,2]   &  [64,128,256,512]  &    9.9M         &   73.66           &  73.72          \\\\\n\t\t\\hline\n\t\t[2,2,16,2]  &  [64,128,256,512]  &    9.9M         &   73.74           &  73.81          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[3,3,5,2]   &  [64,128,256,512]  &    9.9M         &   73.39           &  73.47          \\\\\n\t\t\\hline\n\t\t[3,4,6,3]   &  [64,128,256,512]  &    9.9M         &   73.69           &  73.78          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[2,2,2,2]   & [128,256,512,1024] &   38.5M         &   76.75           &  76.82          \\\\\n\t\t\\hline\n\t\t[2,2,4,2]   & [128,256,512,1024] &   38.5M         &   77.41           &  77.58           \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsection{Jianqing's results}\n\\subsection{Increase channel in MgNet with wise-B}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite    &      channels      &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2,2]   &  [64,128,256,512]  &    13.0M         &   73.24           &  73.36          \\\\\n\t\t\\hline\n\t\t[4,2,2,2]   &  [64,128,256,512]  &    13.1M         &   73.48           &  73.56          \\\\\n\t\t\\hline\n\t\t[3,3,5,2]   &  [64,128,256,512]  &    15.4M         &   74.46           &  74.54          \\\\\n\t\t\\hline\n\t\t[3,4,6,3]   &  [64,128,256,512]  &    18.1M         &   75.23           &  75.23          \\\\\n\t\t\\hline\n\t\t[2,2,4,2]   &  [64,128,256,512]  &    14.7M         &   74.37           &  74.58          \\\\\n\t\t\\hline\n\t\t[2,2,8,2]   &  [64,128,256,512]  &    16.6M         &   75.16           &  75.18          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[2,2,2,2]   &  [128,256,512,1024]    &   51.1M     &    77.17          & 77.27     \\\\\n\t\t\\hline\n\t\t[2,2,4,2]   &  [128,256,512,1024]    &   55.7M     &    77.89          & 77.94     \\\\\n\t\t\\hline\n\t\t[3,4,6,3]   &  [128,256,512,1024]    &   66.7M     &                   & 78.65     \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\newpage\n\\section{MgNet test in Cifar100}\n\n\\subsection{The DenseNet Classification Results on CIFAR}\n\\begin{tabular}{| l | c | c | c  | c | c | r |}\n\t\\hline\n\tMethod              &   Depth   & Params   & C10    & C10+    & C100   &   C100+ \\\\\n\t\\hline\n\tDensenet(k=12)      &    40     & 1.0M     & 93.00  & 94.76   & 72.45  &   75.58  \\\\\n\t\\hline\n\tDensenet(k=12)      &   100     & 7.0M     & 94.23  & 95.90   & 76.21  &   79.80  \\\\\n\t\\hline\n\tDensenet(k=24)      &   100     & 27.2M    & 94.17  & 96.26   & 76.58  &   80.75  \\\\\n\t\\hline\n\tDensenet-BC(k=12)   &   100     & 0.8M     & 94.08  & 95.49   & 75.85  &   77.73  \\\\\n\t\\hline\n\tDensenet-BC(k=24)   &   250     & 15.3M    & 94.81  & 96.38   & 80.36  &   82.40  \\\\\n\t\\hline\n\tDensenet-BC(k=40)   &   190     & 25.6M    & -      & 96.54   & -      &   82.72  \\\\\n\t\\hline\n\\end{tabular}\n\\\\ \\hspace*{\\fill} \\\\\nRefer the DenseNet with $\\alpha<1$ as DenseNet-C, and  set $\\alpha=0.5$in experiment.When both the bottleneck and transition layers with $\\alpha<1$\nare used, refer  as DenseNet-BC.\\\\\n$'+'$ indicates standard data augmentation.\n\n\\subsection{Huang Huang's result}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels           &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2,2]      & [64,128,256,512]        &    9.43M        &    78.22          &  78.25          \\\\\n\t\t\\hline\n\t\t[4,2,2,2]      & [64,128,256,512]        &    9.43M        &    78.33          &  78.52          \\\\\n\t\t\\hline\n\t\t[8,2,2,2]      & [64,128,256,512]        &    9.43M        &    78.29          &  78.42          \\\\\n\t\t\\hline\n\t\t[16,2,2,2]     & [64,128,256,512]        &    9.43M        &    78.13          &  78.25          \\\\\n\t\t\\hline\n\t\t[32,2,2,2]     & [64,128,256,512]        &    9.43M        &    78.69          &  78.80          \\\\\n\t\t\\hline\n\t\t[4,4,4,4]      & [64,128,256,512]        &    9.43M        &    77.89          &  77.99          \\\\\n\t\t\\hline\n\t\t[3,3,5,2]      & [64,128,256,512]        &    9.43M        &    78.38          &  78.54          \\\\\n\t\t\\hline\n\t\t[2,8,2,2]      & [64,128,256,512]        &    9.43M        &    78.53          &  78.68          \\\\\n\t\t\\hline\n\t\t[2,2,8,2]      & [64,128,256,512]        &    9.43M        &    78.38          &  78.70          \\\\\n\t\t\\hline\n\t\t[2,8,8,2]      & [64,128,256,512]        &    9.44M        &    78.33          &  78.44          \\\\\n\t\t\\hline\n\t\t[2,2,16,2]     & [64,128,256,512]        &    9.44M        &    78.77          &  78.95          \\\\\n\t\t\\hline\n\t\t[2,16,2,2]     & [64,128,256,512]        &    9.43M        &    78.42          &  78.52          \\\\\n\t\t\\hline\n\t\t[2,2,32,2]     & [64,128,256,512]        &    9.45M        &    78.48          &  78.67          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsection{Jianqing's result}\n\\subsubsection{Increase channel in MgNet}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels        &  trick     &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2,2]      & [64,128,256,512]     &  wise B    &    12.2M        &    78.57          &  78.86          \\\\\n\t\t\\hline\n\t\t[4,2,2,2]      & [64,128,256,512]     &  wise B    &    12.5M        &    79.01          &  79.23          \\\\\n\t\t\\hline\n\t\t[8,2,2,2]      & [64,128,256,512]     &  wise B    &    12.8M        &    79.44          &  79.55          \\\\\n\t\t\\hline\n\t\t[16,2,2,2]     & [64,128,256,512]     &  wise B    &    13.1M        &    80.05          &  80.39          \\\\\n\t\t\\hline\n\t\t[24,2,2,2]     & [64,128,256,512]     &  wise B    &    13.4M        &    80.52          &  80.52          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[2,2,8,2]      & [64,128,256,512]     &  wise B    &    16.1M        &    80.20          &  80.24          \\\\\n\t\t\\hline\n\t\t[2,2,16,2]     & [64,128,256,512]     &  wise B    &    20.8M        &    79.83          &  80.03          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[4,4,4,4]      & [64,128,256,512]     &  wise B    &    18.8M        &    78.42          &  78.80          \\\\\n\t\t\\hline\n\t\t[6,6,6,6]      & [64,128,256,512]     &  wise B    &    25.1M        &    78.73          &  78.84          \\\\\n\t\t\\hline\n\t\t[8,8,8,8]      & [64,128,256,512]     &  wise B    &    31.4M        &    79.09          &  79.10          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\\subsubsection{Fix channel in MgNet}\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels        &  trick     &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[4,2,2,2]      &      256             &  wise-B    &    11.9M        &       80.48       &  80.63          \\\\\n\t\t\\hline\n\t\t[6,2,2,2]      &      256             &  wise-B    &    13.1M        &       80.94       &  81.11          \\\\\n\t\t\\hline\n\t\t[8,2,2,2]      &      256             &  wise-B    &    14.3M        &       81.42       &  81.42          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[4,2,2,2]      &      256             &  csbv,wise-B      &    11.9M         &       81.30       &  81.32         \\\\\n\t\t\\hline\n\t\t[6,2,2,2]      &      256             &  csbv,wise-B      &    13.1M         &       81.08       &  81.33          \\\\\n\t\t\\hline\n\t\t[8,2,2,2]      &      256             &  csbv,wise-B      &    14.3M         &       81.21       &  81.32          \\\\\n\t\t\\hline\n\t\t[16,2,2,2]     &      256             &  csbv,wise-B      &    18.9M         &       81.18       &  81.19          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[3,4,6,3]      &      256             &  csbv,wise-B      &    15.4M         &       81.05       &  81.15          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsubsection{Architecture from ResNet}\nIn ResNet and DenseNet cifar experiments, the networks have three mesh size and in every mesh size have the same number blocks(layers), use this method for design MgNet networks.\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels        &  wise-B     &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2]        &   [128,256,512]      &  No         &    9.2M         &    79.37          &  79.42          \\\\\n\t\t\\hline\n\t\t[4,4,4]        &   [128,256,512]      &  No         &    9.2M         &    79.74          &  79.85          \\\\\n\t\t\\hline\n\t\t[6,6,6]        &   [128,256,512]      &  No         &    9.2M         &    79.01          &  79.01          \\\\\n\t\t\\hline\n\t\t[8,8,8]        &   [128,256,512]      &  No         &    9.2M         &    78.45          &  78.51          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[2,2,2]        &   [128,256,512]      &  Yes        &    12.3M        &    79.82          &  79.92          \\\\\n\t\t\\hline\n\t\t[4,4,4]        &   [128,256,512]      &  Yes        &    18.5M        &    81.27          &  81.27          \\\\\n\t\t\\hline\n\t\t[6,6,6]        &   [128,256,512]      &  Yes        &    24.7M        &    80.53          &  80.69          \\\\\n\t\t\\hline\n\t\t[8,8,8]        &   [128,256,512]      &  Yes        &    30.9M        &    80.17          &  80.36          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[10,10,4]      &   [128,256,512]      &  Yes        &    22.9M        &    80.86          &  80.96          \\\\\n\t\t\\hline\n\t\t[12,12,4]      &   [128,256,512]      &  Yes        &    24.4M        &    80.55          &  80.90          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsubsection{Bottleneck}\nIn this part, I designed the bottleleck of MgNet in the same way as ResNet, the restriction as below:\n\\begin{equation}\nu^{\\ell,i} = u^{\\ell,i-1} + C^{\\ell}B^{\\ell,i}  (f^\\ell -  A^{\\ell} (u^{\\ell,i-1})).\n\\end{equation}\nand $A^{\\ell},C^{\\ell}\\in \\mathbb{R}^{c\\times c\\times 3\\times 3},\\quad B^{\\ell,i}\\in \\mathbb{R}^{c\\times c\\times 1\\times 1}$\n\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels        &  wise-B     &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[2,2,2]        &   [128,256,512]      &  No         &    9.5M         &    78.54          &  78.64          \\\\\n\t\t\\hline\n\t\t[4,4,4]        &   [128,256,512]      &  No         &    9.5M         &    78.49          &  78.55          \\\\\n\t\t\\hline\n\t\t[6,6,6]        &   [128,256,512]      &  No         &    9.6M         &    78.03          &  78.35          \\\\\n\t\t\\hline\n\t\t[8,8,8]        &   [128,256,512]      &  No         &    9.6M         &    77.69          &  77.73          \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[2,2,2]        &   [128,256,512]      &  Yes        &    9.9M         &    78.78          &  78.92          \\\\\n\t\t\\hline\n\t\t[4,4,4]        &   [128,256,512]      &  Yes        &    10.6M        &    79.10          &  79.42          \\\\\n\t\t\\hline\n\t\t[6,6,6]        &   [128,256,512]      &  Yes        &    11.3M        &    79.46          &  79.61          \\\\\n\t\t\\hline\n\t\t[8,8,8]        &   [128,256,512]      &  Yes        &    12.0M        &    76.27          &  76.45          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsubsection{Bottleneck-Juncai}\nIn this part, Juncai He designed the bottleleck of MgNet as below:\n\\begin{equation}\nu^{\\ell,i} = u^{\\ell,i-1} + P^{\\ell,i}B^{\\ell,i}Q^{\\ell,i}(f^\\ell -  A^{\\ell} (u^{\\ell,i-1})).\n\\end{equation}\nand $A^{\\ell},B^{\\ell,i}\\in \\mathbb{R}^{c_{in}\\times c_{out}\\times 3\\times 3},\\quad P^{\\ell,i},Q^{\\ell,i} \\in \\mathbb{R}^{c_{in}\\times c_{out}\\times 1\\times 1}$\n\n\\begin{table}[H]\n\t\\begin{tabular}{| l | c | c | c | c | r |}\n\t\t\\hline\n\t\tnum ite       &      channels        &  wise-B     &    Parameters   &   last accuracy   &  best accuracy  \\\\\n\t\t\\hline\n\t\t[6,6,6]        &   [128,256,512]      &  Yes        &    8.3M         &      78.81        &    78.81        \\\\\n\t\t\\hline\n\t\t[8,8,8]        &   [128,256,512]      &  Yes        &    9.1M         &      77.97        &    77.97        \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[3,4,6,3]      & [64,128,256,512]     &  Yes        &    7.6M         &      76.64       &    76.64        \\\\\n\t\t\\hline\n\t\t[3,4,8,3]      & [64,128,256,512]     &  Yes        &    7.8M         &      76.58       &    76.86        \\\\\n\t\t\\hline\n\t\t[3,4,12,3]     & [64,128,256,512]     &  Yes        &    8.1M         &      76.68       &    77.01        \\\\\n\t\t\\hline\n\t\t\\hline\n\t\t[3,4,6,3]      & [128,256,512,1024]   &  Yes        &    30.4M        &      79.13       &    79.29        \\\\\n\t\t\\hline\n\t\t[3,4,8,3]      & [128,256,512,1024]   &  Yes        &    30.9M        &      79.57       &    79.57        \\\\\n\t\t\\hline\n\t\t[3,4,12,3]     & [128,256,512,1024]   &  Yes        &    32.1M        &      78.45       &    78.80        \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\\newpage\n\\subsection{MgNet Summary}\n\\subsubsection{Comprision of  fixed channels version MgNet  and increase channels version MgNet}\n\\begin{enumerate}\n\\item In cifar100, fixed channels accuracy higher than increase channels.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: $B^{\\ell,i}=\\sigma \\circ \\eta^{\\ell} \\circ \\sigma,\\quad c_\\ell=c_1$}\n\t%\\label{tabel:mgnet-1}\n\t\\begin{center}\n\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,   &  test accuracy\n\t\t\t& parameters   \\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2], 256    &  79.94(79.67)  & 8.3M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\t\n\t\t\t[2,2,2,2],512     & 81.35(81.12)     & 33.1M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2],768     & 81.74(81.67)     & 74.4M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2],1024    & 81.89(81.58)   & 132.2M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\t\t\t\t\n\t\t\\end{tabular}\n\t\t%\t}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: $B^{\\ell,i}=\\sigma \\circ \\eta^{\\ell} \\circ \\sigma$, increase$c_\\ell$}\n\t%\\label{tabel:mgnet-2}\n\t\\begin{center}\n\t\t%\t\\resizebox{\\textwidth}{!}{\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  test accuracy\n\t\t\t& parameters  \\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2], [32,64,128,256]   &  74.95(74.75)  & 2.3M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\t\n\t\t\t[2,2,2,2], [64,128,256,512]      & 78.06(78.04)     & 12.5M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2],[128,256,512,1024]     & 80.29(80.28)      & 37.5M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2],[256,512,1024,2048]     & 81.49(81.41)    & 150.0M\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\t\t\t\t\n\t\t\\end{tabular}\n\t\t%\t}\n\t\\end{center}\n\\end{table}\n\n\n\n\n\\item In ImageNet, increase channels higher than fixed channels accuracy.\n\\begin{table}[!htbp]\n    \\begin{center}\n        \\begin{tabular}{| l | c | c | c | r |}\n        \\hline\n        $[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  test accuracy & parameters\n        \\tabularnewline\n        \\hline\n        [2,2,2,2],256                           &    70.83(71.01)&     8.5M\n        \\tabularnewline\n        \\hline\n        \\end{tabular}\n     \\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n    \\begin{center}\n        \\begin{tabular}{| l | c | c | c | r |}\n        \\hline\n        $[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  test accuracy & parameters\n        \\tabularnewline\n        \\hline\n        [2,2,2,2],[64,128,256,512]             &   72.32(72.32) &   9.9M\n        \\tabularnewline\n        \\hline\n        \\end{tabular}\n    \\end{center}\n\\end{table}\n\n\\end{enumerate}\n\n\n\\subsubsection{Increase channels in MgNet}\n\\begin{enumerate}\n\\item In cifar100, increase channels in fix channels  version MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[2,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], 256                         &  79.94(79.67)         & 8.3M             \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], 512                         &  81.35(81.12)         & 33.1M            \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], 1024                        &  81.89(81.58)          & 132.2            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[4,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[4,2,2,2], 256                         &  80.25(80.02)         & 8.3M             \\tabularnewline\n                \\hline\n\t\t\t\t[4,2,2,2], 512                         &  81.53(81.25)         & 33.1M            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[8,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[8,2,2,2], 256                         &  80.32(80.12)         & 8.3M             \\tabularnewline\n                \\hline\n\t\t\t\t[8,2,2,2], 512                         &  81.83(81.59)         & 33.1M            \\tabularnewline\n                \\hline\n\t\t\t\t[8,2,2,2], 1024                        &  82.46(82.20)         & 132.2M           \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\newpage\n\\item In ImageNet, increase channels in increase channels version MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[2,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], [64,128,256,512]            &  72.32(72.32)         & 9.9M             \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], [128,256,512,1024]          &  76.82(76.75)         & 38.5             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[2,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,4,2], [64,128,256,512]            &  73.04(73.04)         & 9.9M             \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,4,2], [128,256,512,1024]          &  77.58(77.41)         & 38.5M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[2,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], [64,128,256,512](wise-B)    &  73.36(73.24)         & 13.0M             \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,2,2], [128,256,512,1024](wise-B)  &  77.27(77.17)         & 51.1M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $c_\\ell$  with $\\nu=[2,2,2,2]$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,4,2], [64,128,256,512](wise-B)    &  74.58(74.37)         & 14.7M             \\tabularnewline\n                \\hline\n\t\t\t\t[2,2,4,2], [128,256,512,1024](wise-B)  &  77.94(77.89)         & 55.7M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n\n\n\n\n\\newpage\n\\subsubsection{Increase $\\nu$}\n\\begin{enumerate}\n\\item In cifar100, increase $\\nu_1$ in fix channels MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_1$  with $c_\\ell=256$}\n\t%\\label{raw MgNet results 1-256 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last) & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 256                         &  79.94(79.67)         & 8.3M             \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[4,2,2,2], 256                         &  80.25(80.02)         & 8.3M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[8,2,2,2], 256                         &  80.32(80.12)         & 8.3M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[16,2,2,2], 256                        &  80.42(80.22)         & 8.3M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[32,2,2,2], 256                        &  80.89(80.65)         & 8.3M             \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_1$  with $c_\\ell=512$}\n\t%\\label{raw MgNet results 1-512 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &   accuracy  best(last) & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 512                         &   81.35(81.12)         & 33.1M            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[4,2,2,2], 512                         &   81.53(81.25)         & 33.1M            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[8,2,2,2], 512                         &   81.83(81.59)         & 33.1M            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[16,2,2,2], 512                        &   81.97(81.58)         & 33.1M            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_1$  with $c_\\ell=1024$}\n\t%\\label{raw MgNet results 1-1024 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,  &  accuracy  best(last)   & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 1024                        &   81.89(81.58)          & 132.2            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[8,2,2,2], 1024                        &   82.46(82.20)          & 132.2            \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\newpage\n\\item In cifar100, increase $\\nu_2$,$\\nu_3$,$\\nu_4$ the effect is not obvious in fix channels MgNet.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_2$}\n\t%\\label{raw MgNet results 2 }\n\t\\begin{center}\n\t\t%\\resizebox{\\textwidth}{!}{\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n\t\t\t\t\\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 256                         &  79.94(79.67)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,4,2,2], 256                         &  79.96(79.65)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,8,2,2], 256                         &  79.92(79.71)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,16,2,2], 256                        &  79.97(79.66)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\t%}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_3$}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 256                         &  79.94(79.67)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,4,2], 256                         &  79.85(79.51)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,8,2], 256                         &  79.91(79.89)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,16,2], 256                        &  79.77(79.63)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_4$}\n\t%\\label{raw MgNet results 4 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\t\\hline\n                $[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], 256                         &  79.94(79.67)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,2,4], 256                         &  79.60(79.33)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,8], 256                         &  79.28(79.06)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,16], 256                        &  79.47(79.23)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\newpage\n\\item In ImageNet, increase $\\nu_3$ in increase channels  version MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_3$}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], [64,128,256,512]            &  72.32(72.32)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,4,2], [64,128,256,512]            &  73.04(73.04)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,8,2], [64,128,256,512]            &  73.72(73.66)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,16,2],[64,128,256,512]            &  73.81(73.74)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\tNetworks                                 &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,4,2], [128,256,512,1024]            &  77.58(77.41)         &     38.5M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,4,2], [128,256,512,1024](wise-B)    &  77.94(77.89)         &     55.7M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\end{enumerate}\n\n\\subsubsection{Use wise-B}\n\\begin{enumerate}\n\\item In cifar100, Using wise-B in fix channels version MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[4,2,2,2], 256                         &  80.25(80.02)         &     8.3 M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[4,2,2,2], 256(wise-B)                 &  80.63(80.48)         &     11.9M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[8,2,2,2], 256                         &  80.32(80.12)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[8,2,2,2], 256(wise-B)                 &  81.42(81.42)         &     14.3M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\item In ImageNet, Using wise-B in increase channels version MgNet will increase accuracy.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], [64,128,256,512]            &  72.32(72.32)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,2,2], [64,128,256,512](wise-B)    &  73.36(73.24)         &     13.0M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,4,2], [64,128,256,512]            &  73.04(73.04)         &     9.9M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,4,2], [64,128,256,512](wise-B)    &  74.58(74.37)         &     14.7M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,2,2], [128,256,512,1024]          &  76.82(76.75)         &     38.5M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,2,2], [128,256,512,1024](wise-B)  &  77.27(77.17)         &     51.1M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[2,2,4,2], [128,256,512,1024]            &  77.58(77.41)         &     38.5M         \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,4,2], [128,256,512,1024](wise-B)    &  77.94(77.89)         &     55.7M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n\n\\newpage\n\\subsubsection{MgNet VS DenseNet}\n\\begin{enumerate}\n\\item In cifar100.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_3$}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\tMgNet[8,2,2,2], 1024                   &  82.46(82.20)         &     132.2M       \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\tMgNet[8,2,2,2], 256,wise-B             &  81.42(81.42)         &     14.3M        \\tabularnewline\n\t\t\t\t\\hline\n                DenseNet-BC(k=24),250                  &  82.40(-)             &     15.3M        \\tabularnewline\n\t\t\t\t\\hline\n                DenseNet-BC(k=40),190                  &  82.72(-)             &     25.6M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\item In ImageNet.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet: increase $\\nu_3$}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\tMgNet[3,4,8,3],[128,256,512,1024],wise-B &  78.73(78.65)       &     113.7M       \\tabularnewline\n\t\t\t\t\\hline\n                DenseNet-BC(6,12,64,48),264            &  77.85(-)             &     33.0M        \\tabularnewline\n\t\t\t\t\\hline\n                DenseNet-BC(6,12,48,32),201            &  77.42(-)             &     20.0M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n\n\\newpage\n\\subsubsection{divide $\\nu_{\\ell}$}\n\\begin{table}[!htbp]\n\t\\caption{MgNet:scale-B: $u^{\\ell,i} = u^{\\ell,i-1} + s^{\\ell,i} \\sigma \\circ \\eta^{\\ell} \\circ \\sigma   ({f^\\ell -  \\xi^{\\ell} (u^{\\ell,i-1})}).$}\n\t\\label{tabel:mgnet-scale}\t\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell, s^{\\ell,i}$,  &  test accuracy\n\t\t\t& parameters  \\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2], 256, 1   &  79.78(79.45)   & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\n\t\t\t[2,2,2,16], 256, 1   &  78.43(78.14)    & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,32], 256, 1   & 77.99(77.60)    & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\n\t\t\t[2,2,2,2], 256, 1,warm-up   &  79.93(79.61)   & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\n\t\t\t[2,2,2,16], 256, 1 ,warm-up  & 79.50(79.23)   & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,32], 256, 1 ,warm-up  &  79.39(79.22)     & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,2], 256, $\\frac{1}{\\nu_\\ell}$   &  79.54(79.31)    & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,16], 256, $\\frac{1}{\\nu_\\ell}$   & 79.04(78.79)     & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,32], 256, $\\frac{1}{\\nu_\\ell}$   &  78.85(78.35)   & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,2], 256, $\\frac{1}{\\nu_\\ell}$,warm-up   &  79.75(79.47)     & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,16], 256, $\\frac{1}{\\nu_\\ell}$,warm-up   & 79.37(79.03)   & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,32], 256, $\\frac{1}{\\nu_\\ell}$ ,warm-up  &  79.12(78.89) & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\t[2,2,2,16], 256, $\\frac{1}{\\nu_\\ell c_\\ell}$   &  70.13(69.27)    & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\t\t\n\t\t\t[2,2,2,16], 256, $\\frac{1}{\\nu_\\ell c_\\ell}$,warm-up   &  70.39(69.40)    & -\n\t\t\t\\tabularnewline\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\subsubsection{MgNet-DenseNet}\n$\\nu_\\ell$ level: input: $u^{\\ell}$,$f^{\\ell}$,$A^{\\ell}$,$r^{\\ell}=f^{\\ell}-A^{\\ell}u^{\\ell}$\n\n\\begin{equation}\\label{eq:densenet}\n\\begin{cases}\nu^{\\ell},f^{\\ell},A^{\\ell},r^{\\ell,0}=f^{\\ell}-A^{\\ell}u^{\\ell}, \\\\\n\n\\quad\\text{\\bf For}\\quad i = 1:\\nu_{\\ell} \\\\\n\\quad\\quad \\widetilde{r}=B^{\\ell,i}\\ast r^{\\ell,i-1} \\\\\n\\quad\\quad u^{\\ell,i}=P^{\\ell,i}\\ast u^{\\ell,i-1}+r^{\\ell,i}\\\\\n\\quad\\quad r^{\\ell,i}=\\widetilde{r}-\\widetilde{A}\\ast u^{\\ell,i}\\\\\n\\quad\\quad u^{\\ell,i}=[u^{\\ell,i-1},u^{\\ell,i}],r^{\\ell,i}=[r^{\\ell,i-1},r^{\\ell,i}]\\\\\n\\quad \\text{\\bf EndFor} \\\\\nu^{\\ell+1}=P^{\\ell+1}_{l}\\ast_2 u^{\\ell,\\nu_l},f^{\\ell+1}=R \\ast_2 r^{\\ell,\\nu_\\ell}-A^{\\ell+1}\\ast u^{\\ell+1}\n\\end{cases}\n\\end{equation}\n\nThe test result in cifar100.\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell,\\widetilde{A}=\\widetilde{A}^{\\ell}$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[4,4,4,4], 256,k=24                         &  76.03(76.03)         &     8.3M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[6,6,6,6], 256,k=24                         &  76.54(76.43)         &     9.5M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[8,8,8,8], 256,k=24                         &  76.96(76.78)         &     10.7M        \\tabularnewline\n\t\t\t\t\\hline\n                [10,10,10,10],256,k=24                      &  77.21(77.15)         &     11.9M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell,\\widetilde{A}=\\widetilde{A}^{\\ell,i}$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[4,4,4,4], 256,k=24                         &  76.53(76.47)         &     8.8M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[6,6,6,6], 256,k=24                         &  77.32(77.08)         &     11.2M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[8,8,8,8], 256,k=24                         &  77.92(77.73)         &     13.5M        \\tabularnewline\n\t\t\t\t\\hline\n                [10,10,10,10],256,k=24                      &  77.97(77.90)         &     15.8M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\subsection{Task in 2020/09/01-2020/09/07}\n\\subsubsection{test in MgNet-DenseNet}\n\\begin{enumerate}\n\\item In every MgRetriction, the channel of u and f fixed to 256, the result show in below:\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell,\\widetilde{A}=\\widetilde{A}^{\\ell,i}$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[4,4,4,4], 256,k=24                         &  76.53(76.47)         &     8.8M         \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\t[6,6,6,6], 256,k=24                         &  77.32(77.08)         &     11.2M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[8,8,8,8], 256,k=24                         &  77.92(77.73)         &     13.5M        \\tabularnewline\n\t\t\t\t\\hline\n                [10,10,10,10],256,k=24                      &  77.97(77.90)         &     15.8M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\item In every MgRetriction, $num~channel~u^{k+1} = 0.5*num~channel~u^k$\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell,\\widetilde{A}=\\widetilde{A}^{\\ell,i}$   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[8,8,8,8],k=24                         &  78.73(78.20)         &     7.18M        \\tabularnewline\n\t\t\t\t\\hline\n                [10,10,10],k=24                        &  78.47(78.38)        &     6.89M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n\n\n\\subsubsection{Using every levels information in calssfication}\n\\begin{equation}\\label{eq:densenet}\n\\begin{cases}\n\\quad\\text{\\bf For}\\quad \\ell = 1:J\\\\\n\\quad\\quad\\text{\\bf For}\\quad\\quad i = 1: \\nu_{\\ell}\\\\\n\\quad\\text\\quad\\quad\\quad\\quad u^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i}(f^{\\ell}-A^{\\ell}u^{\\ell,i-1)}\\\\\n\\quad\\quad\\text{\\bf EndFor} \\\\\n\\quad\\text feature^{\\ell} = avgpooling(u^{\\ell,\\nu_{\\ell}})\\\\\n\\quad\\text u^{\\ell+1,0}=\\Pi u^{\\ell,\\nu_{\\ell}},\\quad f^{\\ell+1}=R(f^{\\ell}-A^{\\ell}u^{\\ell,\\nu_{\\ell}})+A^{\\ell+1}u^{\\ell+1,0}\\\\\n\\quad\\text{\\bf EndFor} \\\\\n\\quad mode_1 \\quad u_{out}=fc\\circ feature^{J}\\\\\n\\quad mode_2 \\quad u_{out}=fc\\circ \\sum_{\\ell=1}^{J}feature^{\\ell}\\\\\n\\quad mode_3 \\quad u_{out}= \\sum_{\\ell=1}^{J}fc^{\\ell}\\circ feature^{\\ell}\\\\\n\\end{cases}\n\\end{equation}\n\n\\begin{table}[!htbp]\n\t%\\caption{MgNet wise-B in cifar100}\n\t%\\label{raw MgNet results 3 }\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J], c_\\ell$,mode   &  accuracy best(last)  & mgnet parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t[2,2,2,2],256,mode=0                       &  79.23(-)             &     10.66M        \\tabularnewline\n\t\t\t\t\\hline\n                [2,2,2,2],256,mode=1                       &  79.66(79.41)         &     10.66M        \\tabularnewline\n                \\hline\n                [2,2,2,2],256,mode=2                       &  80.09(80.05)         &     10.74M        \\tabularnewline\n\t\t\t\t\\hline\n                [8,2,2,2],256,mode=0                       &  81.42(-)             &     14.21M        \\tabularnewline\n\t\t\t\t\\hline\n                [8,2,2,2],256,mode=1                       &  80.18(79.84)         &     14.21M        \\tabularnewline\n                \\hline\n                [8,2,2,2],256,mode=2                       &  80.33(80.25)         &     14.28M        \\tabularnewline\n\t\t\t\t\\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\newpage\n\\subsubsection{DenseMgNet result in 09/07-09/14}\n\\begin{enumerate}\n\\item Four levels is better than three levels.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J]$,$k$,$f_0,u_0$              &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[8,8,8],k=24,f_0=u_0=4k=96$                  &  76.54(76.26)         &     5.9M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[8,8,8,8],k=24,f_0=u_0=4k=96$                &  77.77(77.76)         &     8.8M        \\tabularnewline\n                \\hline\n                \\hline\t\t\n\t\t\t\t$[10,10,10],k=24,f_0=u_0=4k=96 $              &  77.50(77.37)         &     8.6M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=4k=96$            &  78.94(78.84)         &     13.0M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\n\\item Adding $nu_{ell}$ will increase accuracy in four levels.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J],k,u_0~channel$  &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\t\t\n\t\t\t\t$[8,8,8,8],k=24,f_0=u_0=4k=96$                &  77.77(77.76)         &     8.8M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=4k=96$            &  78.94(78.84)         &     13.0M        \\tabularnewline\n                \\hline\n                $[15,15,15,15],k=24,f_0=u_0=4k=96$            &  79.00(78.82)         &     27.7M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\n\\item Adding $k$ will increase accuracy in four levels.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J],k,u_0~channel$   &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\t\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=4k=96$            &  78.94(78.84)         &     13.0M        \\tabularnewline\n                \\hline\n                $[10,10,10,10],k=40,f_0=u_0=4k=160$           &  79.56(79.46)         &     36.0M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n\n\\subsubsection{DenseMgNet result in 09/14-09/21}\n\\begin{enumerate}\n\\item New DenseMgNet framework(discussed with Juncai He).\n\\end{enumerate}\n\\begin{equation}\\label{eq:densenet}\n\\begin{cases}\nIteration\\\\\n\\quad\\text{\\bf For}\\quad i = 1:\\nu_{\\ell} \\\\\n\\quad\\quad f^{\\ell}\\in \\mathbb{R}^{c_{\\ell}\\times n_{\\ell}\\times n_{\\ell}},\n           u^{\\ell,i-1} \\in \\mathbb{R}^{c_{\\ell}+(i-1)k \\times n_{\\ell} \\times n_{\\ell}},\\\\\n\\quad\\quad A^{\\ell} \\in \\mathbb{R}^{c_{\\ell}\\times c_{\\ell} \\times 3 \\times 3},B^{\\ell,i}\\in \\mathbb{R}^{c_{\\ell}\\times k \\times 3 \\times 3},\n           P^{\\ell,i} \\in \\mathbb{R}^{c_{\\ell}+(i-1)k \\times c_{\\ell} \\times 1 \\times 1}\\\\\n\\quad\\quad \\widetilde{u}=B^{\\ell,i}\\ast (f^{\\ell}-A^{\\ell}\\ast P^{\\ell,i}\\ast u^{\\ell,i-1}) \\\\\n\\quad\\quad u^{\\ell,i} = [u^{\\ell,i-1},\\widetilde{u}]\\\\\n\\quad \\text{\\bf EndFor} \\\\\nRestriction:\\\\\n\\Pi^{\\ell+1}_{\\ell} \\in \\mathbb{R}^{c_{\\ell}+\\nu_{\\ell}k \\times c_{\\ell+1} \\times 1 \\times 1},\nR^{\\ell+1}_{\\ell}\\in \\mathbb{R}^{c_{\\ell}\\times c_{\\ell+1}\\times 1 \\time 1},\\\\\nA^{\\ell+1}\\in \\mathbb{R}^{c_{\\ell+1}\\times c_{\\ell+1}\\times 3 \\times 3},\nP\\in \\mathbb{R}^{c_{\\ell}+\\nu_{\\ell}k \\times c_{\\ell} \\times 1 \\times 1}\\\\\nu^{\\ell+1,0}=\\Pi ^{\\ell+1}_{l}\\ast_2 u^{\\ell,\\nu_{\\ell}},\\\\\nf^{\\ell+1}=R^{\\ell+1}_{\\ell} \\ast_2 (f^{\\ell}-A^{\\ell}\\ast P \\ast u^{\\ell,\\nu_{\\ell}})+A^{\\ell+1}*u^{\\ell+1,0}\\\\\n\\end{cases}\n\\end{equation}\n\n\n\n\\begin{enumerate}\n\\item Four levels is better than three levels.\n\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J]$,$k$,$f_0,u_0$              &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10],k=24,f_0=u_0=64$                            &  77.82(77.55)         &     4.2M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=64$                         &  78.84(78.65)         &     7.1M        \\tabularnewline\n                \\hline\n                \\hline\t\t\n\t\t\t\t$[12,12,12],k=24,f_0=u_0=96 $                        &  78.39(78.04)         &     6.1M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=96$                      &  78.74(78.74)         &     10.4M        \\tabularnewline\n                \\hline\n                \\hline\n                MgNet[8,2,2,2], 256,wise-B                    &  81.42(81.42)         &     14.3M        \\tabularnewline\n                \\hline\n                DenseNet-BC(k=40),190                         &  82.72(-)             &     25.6M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\n\n\\item Adding $f_0,u_0$ channels will increase accuracy.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J]$,$k$,$f_0,u_0$              &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=64$                         &  78.84(78.65)         &     7.1M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=96$                         &  78.97(78.77)         &     7.9M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=128$                        &  79.74(79.68)         &     9.0M        \\tabularnewline\n                \\hline\n                \\hline\t\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=64 $                        &  78.74(78.74)         &     10.4M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=96$                         &  79.03(79.00)         &     11.4M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=128$                        &  80.67(80.63)         &     12.5M        \\tabularnewline\n                \\hline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=24,f_0=u_0=64 $                        &  78.56(78.46)         &     16.8M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=24,f_0=u_0=96$                         &  -                    &     -             \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=24,f_0=u_0=128$                        &  80.92(80.88)         &     19.5M        \\tabularnewline\n                \\hline\n                \\hline\n                MgNet[8,2,2,2], 256,wise-B                    &  81.42(81.42)         &     14.3M        \\tabularnewline\n                \\hline\n                DenseNet-BC(k=40),190                         &  82.72(-)             &     25.6M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\item Adding k will increase accuracy.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J]$,$k$,$f_0,u_0$              &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=128$                        &  79.74(79.68)         &     9.0M        \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=40,f_0=u_0=128$                        &  80.89(80.89)         &     20.6M        \\tabularnewline\n                \\hline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=24,f_0=u_0=128 $                       &  80.92(80.88)         &     19.5M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=40,f_0=u_0=128$                        &  81.41(81.34)         &     48.1M        \\tabularnewline\n                \\hline\n                \\hline\n                MgNet[8,2,2,2], 256,wise-B                    &  81.42(81.42)         &     14.3M        \\tabularnewline\n                \\hline\n                DenseNet-BC(k=40),190                         &  82.72(-)             &     25.6M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\n\\newpage\n\\item Adding $\\nu_{\\ell}$ in the right circumstances will increase accurcy, such as $k$ and $f_0,u_0$ not too small.\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\t\\begin{tabular}{|c|c|c|}\n                \\hline\n\t\t\t\t$[\\nu_1,\\nu_2,\\cdots,\\nu_J]$,$k$,$f_0,u_0$              &  accuracy best(last)  &   parameters \\tabularnewline\n\t\t\t\t\\hline\t\t\n\t\t\t\t$[10,10,10,10],k=24,f_0=u_0=64$                         &  78.84(78.65)         &     7.1M        \\tabularnewline\n\t\t\t\t\\hline\n                $[12,12,12,12],k=24,f_0=u_0=64 $                        &  78.74(78.74)         &     10.4M        \\tabularnewline\t\t\n                \\hline\n                $[15,15,15,15],k=24,f_0=u_0=64 $                        &  78.56(78.46)         &     16.8M        \\tabularnewline\t\t\n                \\hline\n                \\hline\n                $[10,10,10,10],k=24,f_0=u_0=96$                         &  78.97(78.77)         &     7.9M        \\tabularnewline\t\t\n                \\hline\t\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=96$                         &  79.03(79.00)         &     11.4M        \\tabularnewline\n                \\hline\n                $[15,15,15,15],k=24,f_0=u_0=96$                         &  -                    &     -             \\tabularnewline\t\t\n                \\hline\n                \\hline\n                $[10,10,10,10],k=24,f_0=u_0=128$                        &  79.74(79.68)         &     9.0M        \\tabularnewline\t\t\n                \\hline\t\n\t\t\t\t$[12,12,12,12],k=24,f_0=u_0=128$                        &  80.67(80.63)         &     12.5M        \\tabularnewline\n                \\hline\t\t\n\t\t\t\t$[15,15,15,15],k=24,f_0=u_0=128$                        &  80.92(80.88)         &     19.5M        \\tabularnewline\n                \\hline\n                \\hline\n                $[10,10,10,10],k=40,f_0=u_0=128$                        &  80.89(80.89)         &     20.6M        \\tabularnewline\n                \\hline\n                $[12,12,12,12],k=24,f_0=u_0=128$                        &  -                    &     12.5M        \\tabularnewline\n                \\hline\n                $[15,15,15,15],k=40,f_0=u_0=128$                        &  81.41(81.34)         &     48.1M        \\tabularnewline\n                \\hline\n                \\hline\n                MgNet[8,2,2,2], 256,wise-B                    &  81.42(81.42)         &     14.3M        \\tabularnewline\n                \\hline\n                DenseNet-BC(k=40),190                         &  82.72(-)             &     25.6M        \\tabularnewline\n                \\hline\n\t\t\t\\end{tabular}\n\t\\end{center}\n\\end{table}\n\\end{enumerate}\n", "meta": {"hexsha": "3ad59f7f16f3898ff0a0a8612f37f663801b126f", "size": 84096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/jianqingCNN.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/jianqingCNN.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/jianqingCNN.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.0690345173, "max_line_length": 616, "alphanum_fraction": 0.4773354262, "num_tokens": 32802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891261650248, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.606083416081829}}
{"text": "\\section{Slater-backflow wavefunction implementation details}\n\nFor simplicity, consider $N$ identical fermions of the same spin (e.g., up electrons) at spatial locations $\\{\\bs{r}_1,\\bs{r}_2,\\dots,\\bs{r}_{N}\\}$. Then the Slater determinant can be written as\n\\begin{align}\nS=\\det M\\:,\n\\end{align}\nwhere each entry in the determinant is an SPO evaluated at a particle position\n\\begin{align}\nM_{ij} = \\phi_i(\\bs{r}_j)\\:.\n\\end{align}\n\nWhen backflow transformation is applied to the determinant, the particle coordinates $\\bs{r}_i$ that go into the SPOs are replaced by quasi-particle coordinates $\\bs{x}_i$:\n\\begin{align}\nM_{ij} = \\phi_i(\\bs{x}_j)\\:, \\label{eq:psiM}\n\\end{align}\nwhere\n\\begin{align}\n\\bs{x}_i=\\bs{r}_i+\\sum\\limits_{j=1,j\\neq i}^N\\eta(r_{ij})(\\bs{r}_i-\\bs{r}_j)\\:. \\label{eq:quasi}\n\\end{align}\n$r_{ij}=\\vert\\bs{r}_i-\\bs{r}_j\\vert$. The integers i,j label the particle/quasi-particle. There is a one-to-one correspondence between the particles and the quasi-particles, which is simplest when $\\eta=0$.\n\n\\subsection{Value}\nThe evaluation of the Slater-backflow wavefunction is almost identical to that of a Slater wavefunction. The only difference is that the quasi-particle coordinates are used to evaluate the SPOs. The actual value of the determinant is stored during the inversion of the matrix $M$ (\\verb|cgetrf|$\\rightarrow$\\verb|cgetri|). Suppose $M=LU$, then $S=\\prod\\limits_{i=1}^N L_{ii} U_{ii}$. \\\\\n\n\\begin{lstlisting}\n// In DiracDeterminantWithBackflow::evaluateLog(P,G,L)\nPhi->evaluate(BFTrans->QP, FirstIndex, LastIndex, psiM,dpsiM,grad_grad_psiM);\npsiMinv = psiM;\nLogValue=InvertWithLog(psiMinv.data(),NumPtcls,NumOrbitals\n  ,WorkSpace.data(),Pivot.data(),PhaseValue);\n\\end{lstlisting}\n\nQMCPACK represents the complex value of the wavefunction in polar coordinates $S=e^Ue^{i\\theta}$. Specifically, \\verb|LogValue| $U$ and \\verb|PhaseValue| $\\theta$ are handled separately. In the following, we will consider derivatives of the log value only.\n\n\\subsection{Gradient}\nTo evaluate particle gradient of the log value of the Slater-backflow wavefunction, we can use the $\\log\\det$ identity in Equation~\\ref{eq:logdet}. This identity maps the derivative of $\\log\\det M$ with respect to a real variable $p$ to a trace over $M^{-1}dM$:\n\\begin{align}\n\\frac{\\partial}{\\partial p}\\log\\det M = \\tr\\left( M^{-1} \\frac{\\partial M}{\\partial p} \\right) \\label{eq:logdet}.\n\\end{align}\n\nFollowing Kwon, Ceperley, and Martin~\\cite{Kwon1993backflow}, the particle gradient\n\\begin{align}\nG_i^\\alpha \\equiv \\frac{\\partial}{\\partial r_i^\\alpha} \\log\\det M = \\sum\\limits_{j=1}^N \\sum\\limits_{\\beta=1}^3 F_{jj}^\\beta A_{jj}^{\\alpha\\beta}\\:, \\label{eq:grad}\n\\end{align}\nwhere the quasi-particle gradient matrix\n\\begin{align}\nA_{ij}^{\\alpha\\beta} \\equiv \\frac{\\partial x_j^\\beta}{\\partial r_i^\\alpha}\\:,\n\\end{align}\nand the intermediate matrix\n\\begin{align}\nF_{ij}^\\alpha\\equiv\\sum\\limits_k M^{-1}_{ik} dM_{kj}^\\alpha\\:,\n\\end{align}\nwith the SPO derivatives (w.r. to quasi-particle coordinates)\n\\begin{align}\ndM_{ij}^\\alpha \\equiv \\frac{\\partial M_{ij}}{\\partial x_j^\\alpha}\\:.\n\\end{align}\nNotice that we have made the name change of $\\phi\\rightarrow M$ from the notations of ref.~\\cite{Kwon1993backflow}. This name change is intended to help the reader associate M with the QMCPACK variable \\verb|psiM|.\n\\begin{lstlisting}\n// In DiracDeterminantWithBackflow::evaluateLog(P,G,L)\nfor(int i=0; i<num; i++) // k in above formula\n{\n  for(int j=0; j<NumPtcls; j++)\n  {\n    for(int k=0; k<OHMMS_DIM; k++) // alpha in above formula\n    {\n      myG(i) += dot(BFTrans->Amat(i,FirstIndex+j),Fmat(j,j));\n    }\n  }\n}\n\\end{lstlisting}\n\nEquation~\\ref{eq:grad} is still relatively simple to understand. The $A$ matrix maps changes in particle coordinates $d\\bs{r}$ to changes in quasi-particle coordinates $d\\bs{x}$. Dotting A into F propagates $d\\bs{x}$ to $dM$. Thus $F\\cdot A$ is the term inside the trace operator of Equation~\\ref{eq:logdet}. Finally, performing the trace completes the evaluation of the derivative.\n\n\\subsection{Laplacian}\nThe particle Laplacian is given in ref.~\\cite{Kwon1993backflow} as\n\\begin{align}\nL_i \\equiv \\sum\\limits_{\\beta} \\frac{\\partial^2}{\\partial (r_i^\\beta)^2} \\log\\det M = \\sum\\limits_{j\\alpha} B_{ij}^\\alpha F_{jj}^\\alpha - \\sum\\limits_{jk}\\sum\\limits_{\\alpha\\beta\\gamma} A_{ij}^{\\alpha\\beta}A_{ik}^{\\alpha\\gamma}\\times\\left(F_{kj}^\\alpha F_{jk}^\\gamma -\\delta_{jk}\\sum\\limits_m M^{-1}_{jm} d2M_{mj}^{\\beta\\gamma}\\right), \\label{eq:lap}\n\\end{align}\nwhere the quasi-particle Laplacian matrix\n\\begin{align}\nB_{ij}^{\\alpha} \\equiv \\sum\\limits_\\beta \\frac{\\partial^2 x_j^\\alpha}{\\partial (r_i^\\beta)^2}\\:,\n\\end{align}\nwith the second derivatives of the single-particles orbitals being\n\\begin{align}\nd2M_{ij}^{\\alpha\\beta} \\equiv \\frac{\\partial^2 M_{ij}}{\\partial x_j^\\alpha\\partial x_j^\\beta}\\:.\n\\end{align}\n\nSchematically, $L_i$ has contributions from three terms of the form $BF, AAFF, and \\tr(AA,Md2M)$, respectively. $A, B, M ,d2M,$ and $F$ can be calculated and stored before the calculations of $L_i$. The first $BF$ term can be directly calculated in a loop over quasi-particle coordinates $j\\alpha$.\n\\begin{lstlisting}\n// In DiracDeterminantWithBackflow::evaluateLog(P,G,L)\nfor(int j=0; j<NumPtcls; j++)\n  for(int a=0; a<OHMMS_DIM; k++)\n    myL(i) += BFTrans->Bmat_full(i,FirstIndex+j)[a]*Fmat(j,j)[a];\n\\end{lstlisting}\nNotice that $B_{ij}^\\alpha$ is stored in \\verb|Bmat_full|, NOT \\verb|Bmat|. \n\nThe remaining two terms both involve $AA$. Thus, it is best to define a temporary tensor $AA$:\n\\begin{align}\n{}_iAA_{jk}^{\\beta\\gamma} \\equiv \\sum\\limits_\\alpha A_{ij}^{\\alpha\\beta} A_{ij}^{\\alpha\\gamma}\\:,\n\\end{align}\nwhich we will overwrite for each particle $i$. Similarly, define $FF$:\n\\begin{align}\nFF_{jk}^{\\alpha\\gamma} \\equiv F_{kj}^\\alpha F_{jk}^\\gamma\\:,\n\\end{align}\nwhich is simply the outer product of $F\\otimes F$. Then the $AAFF$ term can be calculated by fully contracting $AA$ with $FF$.\n\\begin{lstlisting}\n// In DiracDeterminantWithBackflow::evaluateLog(P,G,L)\nfor(int j=0; j<NumPtcls; j++)\n  for(int k=0; k<NumPtcls; k++)\n    for(int i=0; i<num; i++)\n    {\n      Tensor<RealType,OHMMS_DIM> AA = dot(transpose(BFTrans->Amat(i,FirstIndex+j)),BFTrans->Amat(i,FirstIndex+k));\n      HessType FF = outerProduct(Fmat(k,j),Fmat(j,k));\n      myL(i) -= traceAtB(AA,FF);\n    }\n\\end{lstlisting}\nFinally, define the SPO derivative term:\n\\begin{align}\nMd2M_j^{\\beta\\gamma} \\equiv \\sum\\limits_m M^{-1}_{jm} d2M_{mj}^\\beta\\:,\n\\end{align}\nthen the last term is given by the contraction of $Md2M$ (\\verb|q_j|) with the diagonal of $AA$.\n\\begin{lstlisting}\nfor(int j=0; j<NumPtcls; j++)\n{\n  HessType q_j;\n  q_j=0.0;\n  for(int k=0; k<NumPtcls; k++)\n    q_j += psiMinv(j,k)*grad_grad_psiM(j,k);\n  for(int i=0; i<num; i++)\n  {\n    Tensor<RealType,OHMMS_DIM> AA = dot(\n      transpose(BFTrans->Amat(i,FirstIndex+j)),\n      BFTrans->Amat(i,FirstIndex+j)\n    );\n    myL(i) += traceAtB(AA,q_j);\n  }\n}\n\\end{lstlisting}\n\n\\subsection{Wavefunction parameter derivative}\nTo use the robust linear optimization method of ref.~\\cite{Toulouse2007linear}, the trial wavefunction needs to know its contributions to the overlap and hamiltonian matrices. In particular, we need derivatives of these matrices with respect to wavefunction parameters. As a consequence, the wavefunction $\\psi$ needs to be able to evaluate $\\frac{\\partial}{\\partial p} \\ln \\psi$ and $\\frac{\\partial}{\\partial p} \\frac{\\mathcal{H}\\psi}{\\psi}$, where $p$ is a parameter.\n\nWhen 2-body backflow is considered, a wavefunction parameter $p$ enters the $\\eta$ function only (Equation~\\ref{eq:quasi}). $\\bs{r}$, $\\phi$, and $M$ do not explicitly dependent on $p$. Derivative of the log value is almost identical to particle gradient. Namely, Equation~\\ref{eq:grad} applies upon the substitution $r_i^\\alpha\\rightarrow p$.\n\\begin{align}\n\\frac{\\partial}{\\partial p} \\ln\\det M = \\sum\\limits_{j=1}^N \\sum\\limits_{\\beta=1}^3 F_{jj}^\\beta \\left({}_pC_{j}^{\\beta}\\right)\\:,\n\\end{align}\nwhere the quasi-particle derivatives are stored in \\verb|Cmat|\n\\begin{align}\n{}_pC_{i}^{\\alpha} \\equiv \\frac{\\partial}{\\partial p} x_{i}^{\\alpha}\\:.\n\\end{align}\n\nThe change in local kinetic energy is a lot more difficult to calculate\n\\begin{align}\n\\frac{\\partial T_{\\text{local}}}{\\partial p} = \\frac{\\partial}{\\partial p} \\left\\{ \\left( \\sum\\limits_{i=1}^N \\frac{1}{2m_i} \\nabla^2_i \\right) \\ln \\det M \\right\\} = \\sum\\limits_{i=1}^N \\frac{1}{2m_i} \\frac{\\partial}{\\partial p} L_i\\:, \\label{eq:dK}\n\\end{align}\nwhere $L_i$ is the particle Laplacian defined in Equation~\\ref{eq:lap}. To evaluate Equation~\\ref{eq:dK}, we need to calculate parameter derivatives of all three terms defined in the Laplacian evaluation. Namely $(B)(F)$, $(AA)(FF)$, and $\\tr(AA,Md2M)$, where we have put parentheses around previously identified data structures. After $\\frac{\\partial}{\\partial p}$ hits, each of the three terms will split into two terms by the product rule. Each smaller term will contain a contraction of two data structures. Therefore, we will need to calculate the parameter derivatives of each data structure defined in the Laplacian evaluation:\n\\begin{align}\n{}_pX_{ij}^{\\alpha\\beta} \\equiv \\frac{\\partial}{\\partial p} A_{ij}^{\\alpha\\beta}\\:, \\\\\n{}_pY_{ij}^{\\alpha} \\equiv \\frac{\\partial}{\\partial p} B_{ij}^{\\alpha}\\:, \\\\\n{}_pdF_{ij}^{\\alpha} \\equiv \\frac{\\partial}{\\partial p} F_{ij}^{\\alpha}\\:, \\\\\n{}_{pi}{AA'}_{jk}^{\\beta\\gamma} \\equiv \\frac{\\partial}{\\partial p}  {}_iAA_{jk}^{\\beta\\gamma}\\:, \\\\\n{}_p {FF'}_{jk}^{\\alpha\\gamma} \\equiv \\frac{\\partial}{\\partial p} FF_{jk}^{\\alpha\\gamma}\\:, \\\\\n{}_p {Md2M'}_{j}^{\\beta\\gamma} \\equiv \\frac{\\partial}{\\partial p} Md2M_j^{\\beta\\gamma}\\:.\n\\end{align}\nX and Y are stored as \\verb|Xmat| and \\verb|Ymat_full| (NOT \\verb|Ymat|) in the code. dF is \\verb|dFa|. $AA'$ is not fully stored; intermediate values are stored in \\verb|Aij_sum| and \\verb|a_j_sum|. $FF'$ is calculated on the fly as $dF\\otimes F+F\\otimes dF$. $Md2M'$ is not stored; intermediate values are stored in \\verb|q_j_prime|.\n", "meta": {"hexsha": "9ccd6468341c3699602b1df38c3e27f93bcc5b66", "size": 9988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "legacy_manual/backflow_implementation.tex", "max_stars_repo_name": "djstaros/qmcpack", "max_stars_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "legacy_manual/backflow_implementation.tex", "max_issues_repo_name": "djstaros/qmcpack", "max_issues_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "legacy_manual/backflow_implementation.tex", "max_forks_repo_name": "djstaros/qmcpack", "max_forks_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.1686746988, "max_line_length": 634, "alphanum_fraction": 0.7098518222, "num_tokens": 3266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733963661418, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6060722783440076}}
{"text": "\\chapter{Future work}\nIn this thesis we examined Bayesian neural network exclusively using Markov chain Monte Carlo methods. These methods are often computationally complex, especially in neural network where the posterior is high-dimensional due to number of neural network weights. Therefore it could have been interesting to look at methods that could be more easily scaled to large distributions. Methods such as variational Inference (\\cite{VI}) has gained a lot of popularity due to its scalability to more complex models. Unlike Markov chain Monte Carlo methods, variational inference is not an exact method. Instead of sampling directly from the posterior the idea is to have a parametric distribution $q\\lr{\\boldsymbol{\\phi}}$, called the variational distribution, to sample from instead. The parameters of the variational distribution are optimized in such a way that the variational distribution is as close as possible to the true posterior distribution in terms of a measure called the evidence lower bound. In this context it could have been interesting to look into the work by \\cite{ADVI}, who has built an automatic differentiation variational inference algorithm, that can automatically optimize the parameters for the variational distribution. \n\\\\\n\\\\\nAnother interesting way to design Bayesian neural networks is proposed by \\cite{blundell2015weight} and is called Bayes-by-backprop, which is a variational inference methods combined with reparamitzation trick to ensure that backpropagation works as we described in section \\ref{alg:back_prop}, but over the variational distribution parameters $\\boldsymbol{\\phi}$, which makes it possible to learn the variational distribution by using optimization algorithms like the ones described in section \\ref{sec:gradient_optimization}. \n\\\\\n\\\\\nAnother popular option worth examining is modelling uncertainty in neural networks by using dropout (\\cite{srivastava2014dropout}) to approximate the variational distribution. \\cite{mc_dropout} do this by using a type of ensemble learning, where they generate random predictions for test examples by the dropout method and interpret these as coming from a distribution. They call this method Monte Carlo dropout and states, that it produces faster results than both MCMC methods and variational inference. \n\n", "meta": {"hexsha": "ee852ff520e23f4a536a29c01cf2cfa9da6cf272", "size": 2313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "for_futureWork.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": "for_futureWork.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": "for_futureWork.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": 231.3, "max_line_length": 1241, "alphanum_fraction": 0.8240380458, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6060028269827042}}
{"text": "\\section{Overview}\nThis report contains figures related to the calibration\nprocess of autocorrelator data from Odin-SMR.\\\\\n\\newline\nThe topic examined is:\\\\\n\\newline\nCalibration of sky signals using linear and quadratic interpolations\\\\\nThe calibration of sky signals using two different interpolation\nmethods are compared.\nThe results from the two methods are very comparable\n(depending a bit on the settings for the quadratic interpolation),\nwith statistically similar mean and median values\nand similar distribution.\n\n\n\\clearpage\n\\newpage\n\n\\section{Calibration of sky signals}\nWe know from earlier studies that mean values\nof calibrated sky signals differs somewhat from \nthe expected \\(T_{sky}\\sim0 K\\). In this report we examine\nif a weighted quadratic interpolation routine\nwill improve the results.   \n\n\n\n\\subsection{Basics}\nThe calibration of sky signals is done by:\n\\begin{equation}\n\\label{eq:skysig}\nT^{'}_{sky}=\\frac{c_{sky}-c^{'}_{sky}}{g^{'}}+T_{sky}\\approx(\\frac{g}{g^{'}}-1)T_{sys},\n\\end{equation}\nwhere \\(T^{'}_{sky}\\) is the estimation of the brightness temperature\nof the sky signal, \\(c_{sky}\\approx g(T_{sys}+T_{sky})\\approx gT_{sys}\\) is the measured sky signal,\n \\(c^{'}_{sky}\\) is the reference estimated sky signal\nwhich is retrieved using linear/quadratic interpolation using\nthe measured sky signals around the target \\(c_{sky}\\),   \n\\(g\\) is the true\ngain, and \\(g^{'}\\) is the estimated gain, \\(T_{sys}\\) is the system\nnoise temperature.\n\\subsection{Reference interpolation}\nFor each channel (\\(c_{i}\\)) of the autocorrelators \nwe fit a second degree polynomial,\n\\begin{equation}\nc_{i}(t)=a+bt+ct^{2},\n\\end{equation}\nto the time series of reference measurements (\\(c_{i}(t_{0})\\),\\(c_{i}(t_{1})\\),...,\\(c_{i}(t_{n})\\)). For time zero a weighted quadratic fit can \nbe estimated as\n\\begin{equation}\nc_{i}(0)=\\frac{1}{\\Delta}\\left|\n\\begin{array}{ccc}\n\\sum \\frac{c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{2}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\sum \\frac{t_{j}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}^{2}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{3}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\sum \\frac{t_{j}^{2}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}^{3}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{4}c_{i}(t_{j})w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\end{array}\n\\right|,\n\\end{equation}\n\n\\begin{equation}\n\\Delta=\\left|\n\\begin{array}{ccc}\n\\sum \\frac{w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{2}w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\sum \\frac{t_{j}w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}^{2}w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{3}w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\sum \\frac{t_{j}^{2}w^{2}(t_{j})}{\\sigma^{2}(t_{j})} & \n\\sum \\frac{t_{j}^{3}w^{2}(t_{j})}{\\sigma^{2}(t_{j})} &\n\\sum \\frac{t_{j}^{4}w^{2}(t_{j})}{\\sigma^{2}(t_{j})}\\\\\n\\end{array}\n\\right|,\n\\end{equation}\nand we use an exponential drop off weighting\n\\begin{equation}\nw(t_{j})=exp\\left(-\\frac{|t_{j}|}{\\lambda} \\right),\n\\end{equation}\nwhere \\(\\lambda\\) controls the weighting,\nand \\(\\sigma(t_{j})\\) represents the uncertainty of each measurement\n\\begin{equation}\n\\sigma(t_{j})\\sim\\frac{1}{\\sqrt{t_{int}}},\n\\end{equation}\nwhere \\(t_{int}\\) is the integration time.\n\n\\subsection{Test results}\n\nIn this section we compare calibration of sky signals\nusing linear interpolation and the previously described\nquadratic interpolation. Data from six orbits, including around\n10000 sky signals, are considered. \n\n\n\\subsubsection{Linear interpolation}\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4linear.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing linear interpolation. \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4linear.png}\n\\end{figure}\n\nThe upper panel of Figure 1 shows a mean spectrum\nof calibrated sky signals from 6 orbits (~10000 sky signals). \nIt can clearly be seen\nthat this spectrum deviates from 0 K (approximately the true brightness \ntemperature of the sky signal).\n\nThe lower panel shows some additional statistics.\nThe standard deviation of the spectrum is around 2 K,\nwhich agrees well with the expected theoretical noise level\n(\\(\\Delta T =T_{sys}/\\sqrt{B*\\tau} \\approx 3000 K / \\sqrt{2MHz*0.8s}=2.37 K\\)).\nThe percentiles (for example the 25 and 75) are fairly evenly\ndisplaced from the 50\\% percentile (median),\nwhich means that the errors are at least close to Gaussian\ndistributed.  \nThe median has the same pattern as the mean (which is hard to see\ndue to the scale).\n\nThe reason for the median deviation from 0 K is most likely due to \nthat the gain does not vary\ncompletely linearly with time between three sky signals\nmeasurements.\n\n\\subsubsection{Quadratic interpolation setup}\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_dem.png}\\\\\n\\caption{The upper panel shows mean of band1 of level1a data\nfrom several scans.\nThe middle panel shows a zoom in of the black dots in the upper panel,\nand the black square is the fitted value\n(the fit is performed for each channel).\nThe lower panel shows the corresponding weights (x=8) of each measurement \nin the fit. }\n\\label{fig:study4_dem.png}\n\\end{figure}\n\nThe quadratic fit of a reference measurement at time \\(t\\)\nis done in the following way (see Figure 2).  \nWe first find out the time-interval \\(\\Delta T\\) of the scan that\nthe measurement belongs to. \nIn the fit, we then consider all reference measurements\nthat where performed during the time interval \n\\(t-\\Delta T\\) to \\(t+\\Delta T\\). \nThe weighting parameter \\(\\lambda\\) is then given\nthe value  \\(\\Delta T /x\\), where we tested the performance\nof several values of x (4,8,16,32,64,and 128).\n\n\\clearpage\n\\newpage\n\\subsubsection{Quadratic interpolation}\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_4.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=4). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_4.png}\n\\end{figure}\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_8.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=8). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_8.png}\n\\end{figure}\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_16.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=16). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_16.png}\n\\end{figure}\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_32.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=32). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_32.png}\n\\end{figure}\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_64.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=64). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_64.png}\n\\end{figure}\n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_128.png}\\\\\n\\caption{The upper panel shows a mean spectrum of calibrated\nsky signals from AC2 stratospheric mode 1,\nusing quadratic interpolation (x=128). \nThe lower panel show a standard deviation spectrum\nand percentiles spectra.}\n\\label{fig:study4_.png}\n\\end{figure}\n\nFigures 3 to 8 show similar data as Figure 1 but using quadratic\ninterpolation with different setups\n(weight parameter \\(\\lambda = \\Delta T /x, x=4,8,16,32,64,128\\)). \nIn general, the results from the quadratic interpolations\nare very similar as the result from the linear interpolation.\nThe same pattern in mean and median values are observed, and\nsimilar distributions of data.\nThe result from x=32 setup seems to be slightly better\nthan for other values of x in terms of standard deviation,\nand the results agree very well with the result from linear interpolation.\nFor such high value of \\(x\\) fairly few number of data\npoints are effectively used in the fit (see Figure 9).\nFigure 9 indicates that the fit in this case should be \nvery close to a linear interpolation.\n\n   \n\n\\begin{figure}[!t]\n\\centering\n\\includegraphics[scale=0.35]{study4_demo32.png}\\\\\n\\caption{The upper panel shows mean of band1 of level1a data\nfrom several scans.\nThe middle panel shows a zoom in of the black dots in the upper panel,\nand the black square is the fitted value\n(the fit is performed for each channel). \nThe lower panel shows the corresponding weights (x=32) of each measurement \nin the fit. }\n\\label{fig:study4_dem32.png}\n\\end{figure}\n\n", "meta": {"hexsha": "50b78d47ff6e249d45bdd8f8b4991542737f547e", "size": 9237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "odincal/docs/part4.tex", "max_stars_repo_name": "Odin-SMR/odincal", "max_stars_repo_head_hexsha": "4c40f0d762b5ee8cbfd7f305cf6aa7ed9ec50206", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "odincal/docs/part4.tex", "max_issues_repo_name": "Odin-SMR/odincal", "max_issues_repo_head_hexsha": "4c40f0d762b5ee8cbfd7f305cf6aa7ed9ec50206", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "odincal/docs/part4.tex", "max_forks_repo_name": "Odin-SMR/odincal", "max_forks_repo_head_hexsha": "4c40f0d762b5ee8cbfd7f305cf6aa7ed9ec50206", "max_forks_repo_licenses": ["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.8023255814, "max_line_length": 146, "alphanum_fraction": 0.7302154379, "num_tokens": 2804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6060028159467136}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Alex Li}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\n  On April 9, 1975, Congressman Robert Michel brandished a list of new\n    NSF grants on the floor of the House of Representatives and selected\n      a few that he thought might represent a waste of the taxpayers'\n        money. One of them \\ldots was called ``Studies in Complex\n          Analysis.'' Michel's comment was, `` `Simple Analysis' would,\n            hopefully, be cheaper.''\n              \\byline{Gerald B. Folland} % the American Mathematical Monthly (vol 780, Oct 1998, pg. 780)\n              \\end{inspiration}\n\n              \\section{Terminology}\n\n              \\begin{problem}\n                What is a \\textbf{simply-connected} domain?\n                \\end{problem}\n                \\begin{solution}\n                A open set $U\\subset \\C$ is said to be a simply connected domain if it is connected and, any two piecewise smooth closed curves $\\gamma_1, \\gamma_2: [0, 1]\\mapsto U$ with the same start and end point are \\textbf{homologous}.\n                \\end{solution}\n                \\begin{problem}\n                  What does it mean to say that two curves $\\alpha: [0, 1]\\mapsto U$ and $\\beta: [0, 1]\\mapsto U$ are\n                    \\textbf{homologous}?\n                    \\end{problem}\n                    \\begin{solution}\n                    It means that $\\alpha, \\beta$ are piecewise smooth and $\\alpha(0) = \\beta(0)$ and $\\alpha(1) = \\beta(1)$ and that $\\alpha - \\beta$ is null homotopic.\n                    \\end{solution}\n                    \\begin{problem}\n                      What is a \\textbf{null homotopic} path?\n                      \\end{problem}\n                      \\begin{solution}\n                      A path (or formal sum of paths $\\sum_{i} \\gamma_i$) of a function $f: U \\mapsto \\C$ is said to be null homotopic if for all $x\\in \\C \\setminus U$, the winding number of the paths sum to 0: $\\sum_i n(\\gamma_i, x) = 0.$\n                      \\end{solution}\n                      \\begin{problem}\n                        Given a function $f : U \\to \\C$, what is meant by a \\textbf{branch} of $\\log f$?\n                        \\end{problem}\n                        \\begin{solution}\n                        A branch of $\\log f$ is an analytic function $g: U \\to \\C$ such that $e^g = f$.\n                        \\end{solution}\n\n                        \\section{Numericals}\n\n                        \\begin{problem}\n                          Let $f(z) = (z^2-z-1)/z^3$, and consider the curve\n                            $\\gamma : [0,2\\pi] \\to \\C$ by $\\gamma(\\theta) = f(e^{i\\theta})$.\n                              Compute the winding number $n(\\gamma,0)$.\n                              \\end{problem}\n                              \\begin{solution}\n                              Let $u=e^{it}$\n                              \\begin{align*}\n                                  n(\\gamma, 0) &= \\frac{1}{2\\pi i}\\int_\\gamma \\frac{1\\, d\\gamma}{\\gamma}\\\\\n                                      &= \\frac{1}{2\\pi i}\\int_{t=0}^{2\\pi} \\frac{u^3\\frac{d}{du}(\\frac{1}{u} - \\frac{1}{u^2} - \\frac{1}{u^3})z'}{(u^2-u-1)}dt\\\\\n                                          &= \\frac{1}{2\\pi i}\\int_{t=0}^{2\\pi} \\frac{(-u + 2 + 3zu{-1})u'}{(u^2-u-1)}dt\n                                          \\end{align*}\n                                          Let $\\gamma_2$ be the positively oriented unit circle. Since $\\gamma_2' = z'$, \n                                          \\begin{align*}\n                                              n(\\gamma, 0) &= \\frac{1}{2\\pi i}\\int_{\\gamma_2} \\frac{(-z + 2 + 3z^{-1})\\, dz}{(z^2-z-1)}\\\\\n                                                  &= \\frac{1}{2\\pi i}\\int_{\\gamma_2} \\frac{(-z^2 + 2z + 3)dz}{z(z^2-z-1)}\\\\\n                                                      &= \\frac{1}{2\\pi i}\\int_{\\gamma_2} \\frac{-3}{z} + \\frac{1}{z - \\frac{1+\\sqrt{5}}{2}} + \\frac{1}{z + \\frac{1-\\sqrt{5}}{2}}dz \\quad\\color{purple} \\text{Partial Fraction Decomp}\\\\\n                                                          &= -3n(\\gamma_2, 0) + n(\\gamma_2,\\frac{1+\\sqrt{5}}{2}) + n(\\gamma_2, \\frac{1-\\sqrt{5}}{2})\\\\\n                                                              &= -3 + 0 + 1 = -2\n                                                              \\end{align*}\n                                                              \\end{solution}\n                                                              \\begin{problem}\n                                                                Evaluate the \\textbf{Dirichlet integral}\n                                                                  \\[\n                                                                      \\int_0^\\infty \\frac{\\sin x}{x} \\, dx.\n                                                                        \\]\n                                                                        \\end{problem}\n                                                                        \\begin{solution}\n                                                                        Let \n                                                                        \\[\n                                                                        I(t) = \\int_0^\\infty e^{-tx}\\frac{\\sin x}{x}\\, dx\n                                                                        \\]\n                                                                        We would like to find $I(0)$. Consider differentiating w.r.t t:\n                                                                        \\begin{align*}\n                                                                        \\frac{d}{dt}I(t) = -\\int_0^\\infty e^{-tx}\\sin x\\, dx\n                                                                        \\end{align*}\n                                                                        Now, do integration by parts twice to compute \\(I_2 = \\int_0^\\infty e^{-tx}\\sin x\\, dx\\):\n                                                                        \\begin{align*}\n                                                                        &\\color{purple} u=e^{-tx}, u'=-te^{-tx}, v = \\cos x, v' = -\\sin x\\\\\n                                                                        I_2 &= -e^{-tx}\\cos x\\big|_{x=0}^\\infty - \\int_0^\\infty te^{-tx}\\cos x\\, dx\\\\\n                                                                        &= 1 - t\\int_0^\\infty e^{-tx}\\cos x\\, dx\\\\\n                                                                        &\\color{purple} u=e^{-tx}, u'=-te^{-tx}, v = \\sin x, v' = \\cos x\\\\\n                                                                        \\int_0^\\infty e^{-tx}\\cos x\\, dx &= -e^{-tx}\\sin x|_{0}^{\\infty} + \\int_0^\\infty te^{-tx}\\sin x dx\\\\\n                                                                        &= tI_2\\, dx\n                                                                        \\end{align*}\n                                                                        Thus \n                                                                        \\[\n                                                                        I_2 = 1 - t^2I_2 \\implies (t^2+1)I_2 = 1 \\implies I_2 = \\frac{1}{t^2+1} \\implies \\frac{d}{dt}I(t) = \\frac{-1}{t^2+1}\n                                                                        \\]\n                                                                        With the goal of recovering $I(0)$, we want to integrate. To remove the constant term, let's compute $I(\\infty) = \\lim_{t\\to\\infty} \\int_0^\\infty e^{-tx}\\frac{\\sin x}{x}$. As this converges pointwise to 0, $I(\\infty) = 0$.\n                                                                        \\begin{align*}\n                                                                        I(0) - I(\\infty) = I(0) = \\int_\\infty^0 \\frac{-dt}{t^2 + 1} = \\tan^{-1}(t)\\big|_\\infty^0 = -0 - -\\pi/2 = \\pi/2\n                                                                        \\end{align*}\n                                                                        \\end{solution}\n                                                                        \\begin{problem}\n                                                                          Define $\\gamma : [0,2\\pi] \\to \\C$ by $\\gamma(\\theta) = e^{i\\theta}$.\n                                                                            Suppose $p \\in \\C[z]$ is a degree $n$ polynomial with distinct roots\n                                                                              $z_1,\\ldots,z_n$ in the unit disk, and evaluate\n                                                                                \\[\n                                                                                    \\int_\\gamma \\frac{z^m \\, p'(z)}{p(z)} \\, dz.\n                                                                                      \\]\n                                                                                      \\end{problem}\n                                                                                      \\begin{solution}\n                                                                                      \\begin{align}\n                                                                                      \\int_\\gamma \\frac{z^m \\, p'(z)}{p(z)} \\, dz &= \\int_\\gamma z^m\\sum_{i=1}^n \\frac{1}{z-z_i} \\, \\, dz\\\\\n                                                                                      \\label{sum_of_int_zm_z_zi}\n                                                                                      &= \\sum_{i=1}^n \\int_\\gamma \\frac{z^m}{z-z_i} \\, \\, dz\n                                                                                      \\end{align}\n                                                                                      Now Cauchy's integral formula shows us that for any root $z_i$ and holomorphic function $f$,\n                                                                                      \\begin{align*}\n                                                                                      f(z_i) &= \\frac{1}{2\\pi i}\\int_\\gamma \\frac{f(z)}{z - z_i}\\,dz\\\\\n                                                                                      2\\pi i z_i^m &= \\int_\\gamma \\frac{z^m}{z - z_i}\\,dz\n                                                                                      \\end{align*}\n                                                                                      Plugging this into \\ref{sum_of_int_zm_z_zi},\n                                                                                      \\begin{align*}\n                                                                                      \\int_\\gamma \\frac{z^m \\, p'(z)}{p(z)} \\, dz &= 2\\pi i\\sum_{i=1}^n z^m\n                                                                                      \\end{align*}\n                                                                                      \\end{solution}\n\n                                                                                      \\begin{problem}\n                                                                                        Again define $\\gamma : [0,2\\pi] \\to \\C$ by\n                                                                                          $\\gamma(\\theta) = e^{i\\theta}$, and then evaluate\n                                                                                            \\[\n                                                                                                \\int_\\gamma \\frac{\\conj{w}}{w - z} \\, dw\n                                                                                                  \\] for $z \\in \\C$ with $\\abs{z} < 1$.\n                                                                                                  \\end{problem}\n                                                                                                  \\begin{solution}\n                                                                                                  \\begin{align*}\n                                                                                                      \\int_\\gamma \\frac{\\conj{w}}{w - z} \\, dw &=\n                                                                                                          \\int_0^{2\\pi} \\frac{e^{-it}(-ie^{it})}{e^{it} - z} \\, dt\\\\\n                                                                                                              &= -i\\int_0^{2\\pi} \\frac{e^{-it}}{1 - ze^{-it}} \\, dt\n                                                                                                              \\end{align*}\n                                                                                                              The denominator has positive real part - by assumption $\\abs{z}< 1$, and as $\\abs{e^{it}} =1$, $\\abs{ze^{-it}}  < 1$ so $\\Re(1-ze^{-it}) > \\abs{1} - \\abs{ze^{-it}} > 0$. Thus, $\\Log$ is a branch of the logarithm function defined in a simply connnected domain containing the curve $\\gamma(t) = 1-ze^{-it}$.\n\n                                                                                                              Notice that $\\frac{d}{dt}\\log(1-ze^{-it}) = \\frac{-ize^{-it}}{1-ze^{-it}}$, so we can simplify our expression further:\n                                                                                                              \\begin{align*}\n                                                                                                                  \\int_\\gamma \\frac{\\conj{w}}{w - z} \\, dw &=\n                                                                                                                      \\frac{1}{z}\\Log(1 - ze^{-it})|_0^{2\\pi} = 0\n                                                                                                                      \\end{align*}\n\n                                                                                                                      \\end{solution}\n                                                                                                                      \\begin{problem}\n                                                                                                                        Consider subsets of the real line $A = (-\\infty,-1] \\cup [1,\\infty)$\n                                                                                                                          and $B = [-1,1]$.  Is it possible to define a branch of the\n                                                                                                                            logarithm of $z^2 - 1$ on $\\C \\setminus A$?  What about on\n                                                                                                                              $\\C \\setminus B$?\n                                                                                                                              \\end{problem}\n                                                                                                                              \\begin{solution}\n                                                                                                                              From Theorem 4.1 of Palka, it's possible to define a branch of the logarithm on a set $U$ iff $\\int_{\\gamma} \\frac{f'(z)dz}{f(z)} \\, dz= 0$ for every closed curve $\\gamma\\subset U$.\n\n                                                                                                                              \\begin{align*}\n                                                                                                                                  \\int_\\gamma \\frac{2z}{z^2 - 1}\\, dz &=     \\int_\\gamma \\frac{1}{z- 1}\\,dz + \\int_\\gamma\\frac{1}{z+1}\\, dz\\\\\n                                                                                                                                      &= n(\\gamma, 1) + n(\\gamma, -1)\n                                                                                                                                      \\end{align*}\n                                                                                                                                      It's geometrically clear that any curve $\\gamma\\subset \\C\\setminus A$ must have $n(\\gamma, 1) = n(\\gamma, -1) = 0$, so there is a branch of the log function here.\n\n                                                                                                                                      On the other hand, on the set $\\C\\setminus B$, the curve $\\gamma = 2e^{it}$ for $0\\leq t \\leq 2\\pi$ has $n(\\gamma, 1)+ n(\\gamma, -1) = 1 + 1 \\neq 0$, so we cannot define a branch of the logarithm function here.\n                                                                                                                                      \\end{solution}\n                                                                                                                                      \\section{Exploration}\n\n                                                                                                                                      \\begin{problem}\n                                                                                                                                        If we can find a branch of $\\log f$ then we can define a\n                                                                                                                                          single-valued $\\sqrt{f(z)}$ via $e^{(1/2) \\, \\log f}$.  Does the\n                                                                                                                                            converse hold?  Find an open set $U \\subset \\C$ and a holomorphic\n                                                                                                                                              function $f : U \\to \\C$ so that there is \\textit{no} branch of\n                                                                                                                                                $\\log f$ but it is nevertheless possible to define a single-valued\n                                                                                                                                                  $\\sqrt{f(z)}$.\n                                                                                                                                                  \\end{problem}\n                                                                                                                                                  \\begin{solution}\n                                                                                                                                                  Let $U = \\C \\setminus \\{0\\}$ and $f(z) = z^2$. There is no branch of $\\log f$ here: suppose that $e^g = f$ for some holomorphic $g$, then \n                                                                                                                                                  \\[\n                                                                                                                                                  g'e^{g} g\\cdot f= f' \\implies g' = \\frac{f'}{f}\n                                                                                                                                                  \\]\n                                                                                                                                                  Then since $g$ is holomorphic, so is $g'$. Thus the integral of $g$ around the positively oriented unit circle $\\gamma$ is nonzero:\n                                                                                                                                                  \\[\n                                                                                                                                                  \\int_\\gamma g(z) dz =\\int_\\gamma \\frac{f'}{f} dz = \\int_\\gamma \\frac{2}{z} dz = 4\\pi i \\neq 0\n                                                                                                                                                  \\]\n                                                                                                                                                  Thus, $g$ isn't holomorphic, so there is no branch of $\\log f$.\n\n                                                                                                                                                  On the other hand, $z = \\sqrt{f(z)}$ is a branch of the square root function that is analytic on the whole set.\n                                                                                                                                                  \\end{solution}\n\n                                                                                                                                                  \\begin{problem}\n                                                                                                                                                    Liouville's theorem (\\ref{liouville-theorem}) states that a\n                                                                                                                                                      nonconstant holomorphic function $f : \\C \\to \\C$ is not bounded.\n                                                                                                                                                        Seeing \\ref{entire-is-dense}, we might ask how ``small'' can the\n                                                                                                                                                          image of holomorphic function be.  Find a holomorphic function\n                                                                                                                                                            $f : \\C \\to \\C$ with image equal to $\\C \\setminus \\{w\\}$.\n                                                                                                                                                              (Incidentally, by \\textbf{Picard's little theorem}, you will have\n                                                                                                                                                                trouble finding an entire function with image missing two points.)\n                                                                                                                                                                \\end{problem}\n                                                                                                                                                                \\begin{solution}\n                                                                                                                                                                Notice that $f(x) = e^x$ has image $\\C \\setminus \\{0\\}$, since $f^{-1}(re^{i\\theta}) = \\log r + i\\theta$. However, the real function $\\log r$ is not invertible for $r=0$, so the image doesn't contain only 0. \n\n                                                                                                                                                                Thus, $f(x-w)$ has image $\\C\\setminus \\{w\\}$.\n                                                                                                                                                                \\end{solution}\n\n                                                                                                                                                                \\begin{problem}\\label{cauchy-inequalities-2}Suppose\n                                                                                                                                                                  $f(z) = \\sum_{n=0}^\\infty a_n z^n$ is holomorphic in the disk\n                                                                                                                                                                    $B_R(0)$.  If $0 < r < R$, show that\n                                                                                                                                                                      \\[\n                                                                                                                                                                          \\abs{a_n} \\leq \\frac{1}{r^n} \\displaystyle\\sup_{z \\in \\partial B_r(0)} \\abs{f(z)}.\n                                                                                                                                                                            \\]\n                                                                                                                                                                              This extends \\ref{cauchy-inequalities}.\n                                                                                                                                                                              \\end{problem}\n                                                                                                                                                                              \\begin{solution}\n                                                                                                                                                                              Let $\\gamma$ be the positively oriented border of $B_R(0)$.\n                                                                                                                                                                              By Cauchy's integral formula,\n                                                                                                                                                                              \\begin{align*}\n                                                                                                                                                                              f^{(n)}(0) &= \\frac{n!}{2\\pi i}\\int_{\\gamma} \\frac{f(z)\\, dz}{z^{n+1}}\\\\\n                                                                                                                                                                              &= \\frac{n!}{2\\pi}\\abs{\\int_{\\gamma} \\frac{f(z)\\, dz}{z^{n+1}}}\\\\\n                                                                                                                                                                              &\\leq \\frac{n!}{2\\pi}\\int_{\\gamma} \\frac{\\abs{f(z)}\\, dz}{r^{n+1}}\\\\\n                                                                                                                                                                              &\\leq n!\\frac{\\sup_{z\\in\\partial B_r(0)} \\abs{f(z)}}{r^{n}}\\quad \\color{purple} \\int_\\gamma d|\\gamma| = 2\\pi r\n                                                                                                                                                                              \\end{align*}\n\n                                                                                                                                                                              Also, by taking derivatives, \n                                                                                                                                                                              \\begin{align*}\n                                                                                                                                                                                  f^{(n)}(z) = \\frac{\\partial^n \\sum_{k=0}^\\infty a_kz^k }{\\partial ^n} = n!a_n + \\sum_{k=n+1}^\\infty k!a_k z^{n-k}\n                                                                                                                                                                                  \\end{align*}\n                                                                                                                                                                                  When $z=0$, this implies $f^{(n)}(0) = n!a_n$.\n                                                                                                                                                                                  Comparing the two expressions,\n                                                                                                                                                                                  \\begin{align*}\n                                                                                                                                                                                      n!a_n \\leq n!\\frac{\\sup_{z\\in\\partial B_r(0)} \\abs{f(z)}}{r^{n}}\n                                                                                                                                                                                          a_n \\leq \\frac{\\sup_{z\\in\\partial B_r(0)} \\abs{f(z)}}{r^{n}}.\n                                                                                                                                                                                          \\end{align*}\n                                                                                                                                                                                          \\end{solution}\n\n                                                                                                                                                                                          \\begin{problem}\n                                                                                                                                                                                            Consider a nonconstant polynomial $p \\in \\mathbb{C}[z]$ of degree $n$.  Compute\n                                                                                                                                                                                              \\[\n                                                                                                                                                                                                  \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{p'(z)}{p(z)} - \\frac{n}{z} \\right) dz.\n                                                                                                                                                                                                    \\]\n                                                                                                                                                                                                      Can you perform this computation \\textit{without} appealing to the\n                                                                                                                                                                                                        fundamental theorem of algebra?\n                                                                                                                                                                                                        \\end{problem}\n                                                                                                                                                                                                        \\begin{solution}\n                                                                                                                                                                                                        Let $\\displaystyle{p(z) = \\sum_{k=0}^n a_kz^k}$.\n                                                                                                                                                                                                        \\begin{align*}\n                                                                                                                                                                                                            \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{p'(z)}{p(z)} - \\frac{n}{z} \\right) dz &= \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{\\sum_{k=1}^n a_kz^{k-1} }{\\sum_{k=0}^n a_kz^{k}} - \\frac{n}{z} \\right) dz \\\\\n                                                                                                                                                                                                                &= \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{\\sum_{k=1}^n ka_kz^{k-1} }{\\sum_{k=0}^n a_kz^{k}} - \\frac{n}{z} \\right) dz \\\\\n                                                                                                                                                                                                                    &= \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{\\sum_{k=1}^n ka_kz^{k} - n\\sum_{k=0}^n a_kz^{k+1} }{\\sum_{i=0}^k a_kz^{k+1}} \\right) dz \\\\\n                                                                                                                                                                                                                        &= \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{\\sum_{k=0}^{n-1} (k-n)a_kz^{k} }{\\sum_{k=0}^n a_kz^{k+1}} \\right) dz = f(r)\n                                                                                                                                                                                                                        \\end{align*}\n                                                                                                                                                                                                                        This is the integral of something $O(\\frac{1}{z^2})$, so it's 0. More precisely, choose $r$ such that $\\abs{a_{n-1}r^{n-1}} > \\sum_{k=0}^{n-1} \\abs{(k-n)a_kr^{k}}$ and $\\abs{a_nr^{n+1}} > \\frac{1}{2}(\\sum_{k=0}^{n-1} \\abs{a_kr^{k+1}})$\n                                                                                                                                                                                                                        \\begin{align*}\n                                                                                                                                                                                                                            f(r) &\\leq \\int_{\\partial B_r(0)} \\left( \\abs{\\frac{\\sum_{k=0}^{n-2} (k-n)a_kz^{k} }{\\sum_{k=0}^n a_kz^{k+1}}}\\right) dz\\\\\n                                                                                                                                                                                                                                &\\leq \\int_{\\partial B_r(0)} \\left( \\frac{\\abs{a_{n-1}r^{n-1}}+\\sum_{k=0}^{n-1} \\abs{(k-n)a_kr^{k}}}{\\abs{a_nr^{n+1}} - \\sum_{k=0}^{n-1} \\abs{a_kr^{k+1}}}\\right) dz \\\\\n                                                                                                                                                                                                                                     &\\leq \\int_{\\partial B_r(0)} \\left( \\frac{\\abs{2a_{n-1}r^{n-1}}}{\\abs{\\frac{1}{2}a_nr^{n+1}}}\\right) dz \\qquad \\color{purple}C:=\\frac{4a_{n-1}}{a_n}\\\\\n                                                                                                                                                                                                                                          &= C\\int_{\\partial B_r(0)} \\abs{\\frac{1}{r^2}} dz \\leq C\\frac{1}{r^2}2\\pi r\n                                                                                                                                                                                                                                          \\end{align*}\n                                                                                                                                                                                                                                          As $r\\to 0$, this expression also goes to 0.\n                                                                                                                                                                                                                                          \\end{solution}\n\n\n                                                                                                                                                                                                                                          \\begin{problem}\\label{uniformly-approximate-conj}For $\\epsilon > 0$, is there a polynomial $p \\in \\mathbb{C}[z]$ so\n                                                                                                                                                                                                                                            that $\\abs{p(z) - \\conj{z}} < \\epsilon$ for $z \\in B_1(0)$?  In\n                                                                                                                                                                                                                                              other words, can we uniformly approximate $\\conj{z}$ by a polynomial\n                                                                                                                                                                                                                                                in $z$?\n                                                                                                                                                                                                                                                \\end{problem}\n                                                                                                                                                                                                                                                \\begin{solution}\n                                                                                                                                                                                                                                                No. Suppose $p(z) - \\conj{z} < 1$ for all points in $B_1(0)$. \n                                                                                                                                                                                                                                                Let $\\gamma:[0,2\\pi]$ with $\\gamma(t) = .5e^{it}$. Then\n                                                                                                                                                                                                                                                \\begin{align*}\n                                                                                                                                                                                                                                                    \\int_{\\gamma} p(z) - \\conj{z}dz = \n                                                                                                                                                                                                                                                            \\int_{\\gamma} p(z) - \\int_{\\gamma} \\frac{1}{z} dz = 0-2\\pi i\n                                                                                                                                                                                                                                                            \\end{align*}\n                                                                                                                                                                                                                                                            However, \n                                                                                                                                                                                                                                                            \\begin{align*}\n                                                                                                                                                                                                                                                                \\abs{\\int_{\\gamma} p(z) - \\conj{z} dz} &=\n                                                                                                                                                                                                                                                                        \\abs{\\int_0^{2\\pi} \\gamma'(p(\\gamma(t)) - \\conj{\\gamma(t)}) dt}\\\\\n                                                                                                                                                                                                                                                                                &\\leq \\int_0^{2\\pi} .5 \\abs{p(\\gamma(t)) - \\conj{\\gamma(t)})} dz \\leq \\pi\n                                                                                                                                                                                                                                                                                \\end{align*}\n                                                                                                                                                                                                                                                                                And since $|2\\pi i|\\not\\leq \\pi$, we have a contradiction.\n                                                                                                                                                                                                                                                                                \\end{solution}\n\n\n                                                                                                                                                                                                                                                                                \\section{Prove or Disprove and Salvage if Possible}\n\n                                                                                                                                                                                                                                                                                \\begin{problem}\\label{entire-is-dense}If $f : \\C \\to \\C$ is\n                                                                                                                                                                                                                                                                                  holomorphic, then the image of $f$ is dense in $\\C$.\n                                                                                                                                                                                                                                                                                  \\end{problem}\n                                                                                                                                                                                                                                                                                  \\begin{solution}\n                                                                                                                                                                                                                                                                                  No, let $f(z)=0$. That's pretty holomorphic and pretty not dense. \n\n                                                                                                                                                                                                                                                                                  To show that the image is dense, it suffices to show that for any $w$, there is no open ball around $w$ in the image such that no point of $f$ maps to the open ball around $w$. If $w\\in \\text{Image} f$ then we are done! Otherwise, consider the function $g(z) =\\frac{1}{f(z) - w}$, it's holomorphic since $f(z) - w$ has no zeros, and hence it is unbounded, and thus $\\forall \\epsilon > 0$ there is a point $z$ such that $\\frac{1}{f(z) - w} > \\frac{1}{\\epsilon}$, so $f(z) - w < \\epsilon$. Hence there are points arbitrarily close to $w$ in the image of $f$, implying density.\n                                                                                                                                                                                                                                                                                  \\end{solution}\n\n                                                                                                                                                                                                                                                                                  \\begin{problem}\\label{identity-dominate-entire}Suppose $f : \\C \\to \\C$\n                                                                                                                                                                                                                                                                                    is holomorphic and for all $z \\in \\C$ we have\n                                                                                                                                                                                                                                                                                      $\\abs{f(z)} \\leq \\abs{z}$.  Then $f(z) = \\lambda z$ for some\n                                                                                                                                                                                                                                                                                        $\\lambda \\in \\C$.\n                                                                                                                                                                                                                                                                                        \\end{problem}\n                                                                                                                                                                                                                                                                                        \\begin{solution}\n\n                                                                                                                                                                                                                                                                                        Since $f$ is holomorphic in $\\C$, it is analytic and can be represented by an everywhere convergent power series.\n                                                                                                                                                                                                                                                                                        \\[\n                                                                                                                                                                                                                                                                                        f(z) = \\sum_{i=0}^\\infty a_iz^i\n                                                                                                                                                                                                                                                                                        \\]\n                                                                                                                                                                                                                                                                                        Since $\\abs{f(0)} \\leq \\abs{0}$, $f(0)=0$ and thus $a_0=0$. Define $g(z) = \\sum_{i=0}^\\infty a_{i+1}z^i$ so that\n                                                                                                                                                                                                                                                                                        \\begin{align}\\label{f_z_is_z_g_z}\n                                                                                                                                                                                                                                                                                        f(z) = z\\sum_{i=0}^\\infty a_{i+1}z^i = zg(z)\n                                                                                                                                                                                                                                                                                        \\end{align}\n\n                                                                                                                                                                                                                                                                                        $g(z)$ must be convergent everywhere, since if $z = 0$ $g(z)=a_1$ and otherwise, multiplication by $z$ gives $f(z)$. Thus, $g(z)$ is an analytic function.\n\n                                                                                                                                                                                                                                                                                        Since $f(|z|)\\leq |z|$, $f(0)=0$, and dividing out we have that at other points, $\\abs{\\frac{f(z)}{z}}\\leq 1$. Combining this with \\ref{f_z_is_z_g_z},\n                                                                                                                                                                                                                                                                                        \\[ \n                                                                                                                                                                                                                                                                                        \\frac{f(z)}{z} = g(z) \\leq 1\n                                                                                                                                                                                                                                                                                        \\]\n                                                                                                                                                                                                                                                                                        Thus liouville's theorem shows that $g(z)$ is a constant $\\lambda$, and therefore \n                                                                                                                                                                                                                                                                                        \\[f(z) = z\\lambda.\\]\n                                                                                                                                                                                                                                                                                        \\end{solution}\n                                                                                                                                                                                                                                                                                        \\begin{problem}\n                                                                                                                                                                                                                                                                                          There is a nonconstant holomorphic function $f : \\C \\to \\C$ so that\n                                                                                                                                                                                                                                                                                            for all $n \\in \\Z$ we have $f(z + n) = f(z)$.  (Such a function is\n                                                                                                                                                                                                                                                                                              \\textbf{periodic}.)\n                                                                                                                                                                                                                                                                                              \\end{problem}\n                                                                                                                                                                                                                                                                                              \\begin{solution}\n                                                                                                                                                                                                                                                                                              Let $f(z) = \\sin(2\\pi z)$. This is clearly not constant, and\n                                                                                                                                                                                                                                                                                              \\[\n                                                                                                                                                                                                                                                                                              f(z+n) = \\sin(2\\pi (z + n)) + \\sin(2\\pi z + 2\\pi n) = \\sin(2\\pi z) = f(z) .\n                                                                                                                                                                                                                                                                                              \\]\n                                                                                                                                                                                                                                                                                              $f$ is holomorphic since $\\sin = \\frac{e^{i\\theta} - e^{-i\\theta}}{2i}$ is holomorphic and we are just composing it with addition and multiplication by a constant.\n                                                                                                                                                                                                                                                                                              \\end{solution}\n\n                                                                                                                                                                                                                                                                                              \\begin{problem}\\label{doubly-periodic}There is a nonconstant holomorphic function $f : \\C \\to \\C$ so that\n                                                                                                                                                                                                                                                                                                for all $\\omega \\in \\Z[i]$ we have $f(z + \\omega) = f(z)$.  (Such a\n                                                                                                                                                                                                                                                                                                  function is \\textbf{doubly periodic}.)\n                                                                                                                                                                                                                                                                                                  \\end{problem}\n                                                                                                                                                                                                                                                                                                  \\begin{solution}\n                                                                                                                                                                                                                                                                                                  False. If so, then the image of $f:\\C \\mapsto \\C$ is the same as the image of $f$ restricted to the unit square. As $f$ is continuous, and the unit square is compact, the image of $f$ is bounded, contradicting the fact that $f$ is entire.\n\n                                                                                                                                                                                                                                                                                                  Since any constant function is holomorphic, we can salvage by saying that for any holomorphic $f$, $f$ is doubly periodic iff it is constant.\n                                                                                                                                                                                                                                                                                                  \\end{solution}\n\n                                                                                                                                                                                                                                                                                                  \\begin{problem}\\label{maximum-modulus-principle}\n                                                                                                                                                                                                                                                                                                  Consider a connected open subset $U \\subset \\C$ and a holomorphic\n                                                                                                                                                                                                                                                                                                    function $f : U \\to \\C$.  If there is a point $z_0 \\in U$ so that\n                                                                                                                                                                                                                                                                                                      for all $z \\in U$ we have $\\abs{f(z_0)} \\geq \\abs{f(z)}$, then $f$\n                                                                                                                                                                                                                                                                                                        is constant.  \\textit{Hint:} show that $g(z) = \\abs{f(z)}$ is\n                                                                                                                                                                                                                                                                                                          constant and invoke \\ref{open-mapping-theorem-preview}.  This is the\n                                                                                                                                                                                                                                                                                                            \\textbf{maximum modulus principle}.\n                                                                                                                                                                                                                                                                                                            \\end{problem}\n                                                                                                                                                                                                                                                                                                            \\begin{solution}\n                                                                                                                                                                                                                                                                                                            Choose a ball of radius $r$ around $z_0$ contained in $U$ parameterized by $\\gamma$. By Cauchy's integral formula,\n                                                                                                                                                                                                                                                                                                            \\begin{align*}\n                                                                                                                                                                                                                                                                                                            f(z_0) = \\frac{1}{2\\pi i}\\int_{\\gamma} \\frac{f(z) \\, dz}{z - z_0}\\\\\n                                                                                                                                                                                                                                                                                                            \\abs{f(z_0)} = \\frac{1}{2\\pi}\\abs{\\int_{\\gamma} \\frac{f(z) \\, dz}{z-z_0}}\\\\\n                                                                                                                                                                                                                                                                                                            = \\frac{1}{2\\pi}\\abs{\\int_0^{2\\pi} \\frac{f(e^{it})(rie^{it}) \\, dz}{z - z_0}}\\\\\n                                                                                                                                                                                                                                                                                                            \\leq \\frac{1}{2\\pi}\\int_0^{2\\pi} \\frac{\\abs{f(e^{it})(rie^{it})} \\, dz}{r}\\\\\n                                                                                                                                                                                                                                                                                                            \\leq \\frac{1}{2\\pi}\\int_0^{2\\pi} \\abs{f(e^{it})} \\, dz\n                                                                                                                                                                                                                                                                                                            \\leq    \\frac{1}{2\\pi}\\int_0^{2\\pi} \\abs{f(e^{it})} \\, dz\n                                                                                                                                                                                                                                                                                                            \\end{align*}\n                                                                                                                                                                                                                                                                                                            This means that the average value of $f(z)$ around the point $z_0$ is at least $z_0$, but since $f(z_0)$ is the max, $f(z)=f(z_0)$ on $\\gamma$. As this argument holds for any ball of radius $\\gamma$ contained in $U$, the set $V = \\{z:f(z) = f(z_0)\\}$ is open. The set $V^c = \\{z:f(z)\\neq f(z_0)\\}$ is also open since it's the preimage of an open set, so $V$ is closed. Since $U$ is connected, $V=U$.\n                                                                                                                                                                                                                                                                                                            \\end{solution}\n\n                                                                                                                                                                                                                                                                                                            \\end{document}\n\n\n", "meta": {"hexsha": "a852281ab0f28b84ff0934379ef14e0210f86a50", "size": 67633, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-solutions/sol5.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/sol5.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/sol5.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": 183.785326087, "max_line_length": 848, "alphanum_fraction": 0.1610012864, "num_tokens": 7647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.78793120560257, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6059823267409233}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\n\\usepackage{float}\n\\usepackage{graphicx}\n\\usepackage{bm}\n\\begin{document}\n\n\\title{APPM 5510 HW 5}\n\\author{Zane Jakobs}\n\n\\maketitle\n\n\\subsection*{1} Let $\\bm{\\Pi}_{i;j}$ be the Jacobian of the flow map $\\Psi$ at time $i$ with respect to the initial condition at time $j$. Varying one parameter at a time, starting with $\\bm{x}_0$, we have\n\\[\n\\begin{aligned}\n\\nabla J_1 \\cdot \\delta\\bm{x}_0 &= \\nabla J_0 \\cdot \\bm{x}_0 + \\lambda^T\\bm{\\Pi}_{1;0} \\cdot \\bm{x}_0\\\\\n&= 2(\\bm{x}_0 - \\bm{x}_b)^T\\bm{B}_0^{-1}\\cdot \\delta\\bm{x}_0 + 2 (\\bm{x}_1 - \\Psi(\\bm{x}_0))^T\\bm{B}_1^{-1}\\Pi_{1;0}^T \\cdot \\delta\\bm{x}_0 + 2(\\bm{y}_0 - \\bm{H}_0\\bm{x}_0)^T\\bm{R}_0^{-1}\\bm{H}_0\\cdot \\delta\\bm{x}_0\n\\end{aligned}\n\\]\nand with $\\bm{x}_1$, we get\n\\[\n\\begin{aligned}\n\\nabla J_1 \\cdot \\delta\\bm{x}_1 &=  \\nabla J_0 \\cdot \\delta\\bm{x}_1 - \\lambda^T \\cdot\\delta\\bm{x}_1\\\\\n&= 2(\\bm{x}_1 - \\Psi(\\bm{x}_0))^T\\bm{B}_1^{-1} \\cdot\\delta\\bm{x}_1 + 2(\\bm{y}_1 - \\bm{H}_1\\bm{x}_1)^T\\bm{R}_1^{-1}\\bm{H}_1\\cdot \\delta\\bm{x}_1 - \\bm{\\lambda}^T\\cdot\\delta\\bm{x}_1\n\\end{aligned}\n\\]\nWe now have the equation\n\\[\n\\begin{aligned}\n0 &= \\nabla J_1 \\cdot\\bm{x}\\\\\n&= 2(\\bm{x}_0 - \\bm{x}_b)^T\\bm{B}_0^{-1}\\cdot \\delta\\bm{x}_0 + 2(\\bm{x}_1 - \\Psi(\\bm{x}_0))^T\\bm{B}_1^{-1} (\\bm{I} \\cdot \\delta\\bm{x}_1+ \\Pi_{1;0}^T\\cdot\\bm{x}_0) \\\\\n&- (\\bm{y}_0 -  \\bm{H}_0\\bm{x}_0)^T\\bm{R}_0^{-1}\\bm{H}_0\\cdot \\delta\\bm{x}_0 - (\\bm{y}_1 - \\bm{H}_1\\bm{x}_1)^T\\bm{R}_1^{-1}\\bm{H}_1\\cdot \\delta\\bm{x}_1 - \\bm{\\lambda}^T\\cdot\\delta\\bm{x}_1.\n\\end{aligned}\n\\]\n\nDividing out differentials and rearranging terms, we see that\n\\[\n\\begin{aligned}\n\\bm{\\lambda} &= 2\\bm{B}_0^{-T}(\\bm{x}_0 - \\bm{x}_b) + 2(\\bm{I} + \\Pi_{1;0}^T)^T\\bm{B}_1^{-T}(\\bm{x}_1 - \\Psi(\\bm{x}_0)) \\\\\n&- \\bm{H}_0^T\\bm{R}_0^{-T}(\\bm{y}_0 - \\bm{H}_0\\bm{x}_0) - \\bm{H}_1^T\\bm{R}_1^{-T}(\\bm{y}_1 - \\bm{H}_1\\bm{x}_1)\n\\end{aligned}\n\\]\nThe difference between this and the gradient in the notes is that here, we have a term depending on the actual value of $\\bm{x}_1$ (instead of the flow map from $\\bm{x}_0$ to time $1$), and we only need to compute one $\\bm{\\lambda}$, instead of two (for two times) because of the constraint that $\\bm{x}_1 = \\Psi(\\bm{x}_0).$\n\n\n\\subsection*{2}\n(Note: code attached to the back of the assignment)\n\\begin{figure}[H]\n\\includegraphics[scale=0.5]{/Users/zanejakobs/Desktop/4dvarlossr.png}\n\\end{figure}\n\n\\subsection*{3}\nLetting $\\bm{x} = (x,y)^T$, we have $x_{j+1} = a_j x_j + y_j + \\eta_0$, $y_{j+1} = x_j + 2y_j$, and $a_{j+1} = a_j.$ Since $a$ is independent of $x$, differentiating each equation w.r.t. each element of $(x,y,a)$ gives the following Jacobian matrix:\n\\[\n\\begin{bmatrix}a & 1 & 0 \\\\ 1 & 2 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}\n\\]\n\\subsection*{Code}\n\\begin{Verbatim}\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# x_t -> x_{t+1}\ndef xmap(x):\n    return 3.95 * x * (1 - x)\n\ndef psi(x0,t):\n    i = 0\n    x = x0\n    while i < t:\n        x = xmap(x)\n        i += 1\n    return x\n\ndef H(x):\n    return x + np.random.normal(0, 0.01)\n\n\ndef obs_error(y, x, t):\n    xt = psi(x,t)\n    return y - H(xt)  \n\ndef varobjective4d(x0, y):\n    xb = 1./3.\n    b0 = 0.1 ** 2\n\n    R = 0.01 ** 2\n\n    J = (1/b0) * (x0 - xb) ** 2 \n\n    for i in range(len(y)):\n        e = obs_error(y[i], x0, i)\n\n        J += (1./R) * (e ** 2)\n\n    return J\n\nif __name__ == '__main__':\n    \n    true_obs = [0.25]\n    for i in range(4):\n        true_obs.append(xmap(true_obs[-1]))\n\n    obs = [H(x) for x in true_obs]\n\n    Jvals = []\n\n    for i in range(1,len(obs)):\n        Jvals.append(varobjective4d(obs[0], obs[:i]))\n\n\n    plt.plot(Jvals)\n    plt.title(\"4DVAR objective function vs number of data points\")\n    plt.xlabel(\"Number of observations\")\n    plt.ylabel(\"4DVAR objective\")\n    plt.show()\n\\end{Verbatim}\n\n\n\n\n\\end{document}", "meta": {"hexsha": "d7d2175bf36f72fbb463e47774b9bdb2b1631c2c", "size": 3813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW-Text/HW5.tex", "max_stars_repo_name": "DiffeoInvariant/Data-Assimilation", "max_stars_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_stars_repo_licenses": ["MIT"], "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-Text/HW5.tex", "max_issues_repo_name": "DiffeoInvariant/Data-Assimilation", "max_issues_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_issues_repo_licenses": ["MIT"], "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-Text/HW5.tex", "max_forks_repo_name": "DiffeoInvariant/Data-Assimilation", "max_forks_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_forks_repo_licenses": ["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.0, "max_line_length": 324, "alphanum_fraction": 0.5974298453, "num_tokens": 1586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6059823184002491}}
{"text": "%!TEX root = TTK4215-Summary.tex\n\\section{Model reference adaptive control (MRAC)}\nMRAC requires a plant and a reference model. A controller is made so that the controller and plant together behave similar to the reference model. An adaptive algorithm estimates the controller parameters $\\theta$. There are two main categories:\n\\begin{itemize}\n\t\\item \\emph{Direct}, where $\\theta$ is equal to the controller gains.\n\t\\item \\emph{Indirect}, where the controller gains are a function of $\\theta$.\n\\end{itemize}\nHuge drawback: Requires plant of minimum phase. Also requires known relative degree and bounded plant order.\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics[width = \\textwidth]{MRAC}\n\\caption{MRAC structure}\n% \\label{fig:MRAC}\n\\end{center}\n\\end{figure}\n\n\\subsection{How to... MRAC}\nGiven a plant $y(s) = \\frac{b}{s+a}u(s)$ and a reference model $y_m(s) = \\frac{b_m}{s+a_m}r$ where $r \\in L_\\infty$.\nThen the optimal ideal controller has the structure $u^* = -\\theta_1^* y + \\theta_2^* r$, where $\\theta_1^*$ and $\\theta_2^*$ is optimal controller parameters. The optimal parameters can be found by comparison between $y$ and $y_m$:\n\\begin{equation}\n\\begin{split}\ny &= \\frac{b}{s+a}(-\\theta_1^* y + \\theta_2^* r) \\\\\ny(1+\\frac{b\\theta_1^*}{s+a} ) &= \\frac{b\\theta_2^*}{s+a}r \\\\\ny &= \\frac{b\\theta_2^*}{s+a+b\\theta_1^*}r\n\\end{split}\n\\end{equation}\nwhich gives us $\\theta_1^* = \\frac{a_m-a}{b}$ and $\\theta_2^* = \\frac{b_m}{b}$. The closed loop differential equations is\n\n\\begin{equation}\n\\begin{split}\n\\dot{y} &= -ay +bu \\\\\n& =-ay + b (-\\theta_1 y + \\theta_2 r) \\\\\n& = (-a- b \\theta_1) y + b \\theta_2 r \\\\\n\\dot{y_m} &= -a_m y_m + b_m r\n\\end{split}\n\\end{equation}\nWe now define $e \\triangleq y - y_m$, $\\tilde{\\theta_1}  \\triangleq \\theta_1 - \\theta_1^*$, $\\tilde{\\theta_2}  \\triangleq \\theta_2 - \\theta_2^*$ and derive the error dynamics.\n\n\\begin{equation}\n\\begin{split}\n\\dot{e} &= \\dot{y}-\\dot{y_m} \\\\\n&= (-a- b \\theta_1) y + b \\theta_2 r - ( -a_m y_m + b_m r ) \\\\\n&= -a_m y +  a_m y_m + (-a + a_m- b \\theta_1) y + b \\theta_2 r - b_m r \\\\\n&= -a_m e + (-a + a_m- b (\\tilde{\\theta_1} +\\frac{a_m-a}{b})) y + b (\\tilde{\\theta_2} + \\frac{b_m}{b})r - b_m r \\\\\n&= -a_m e - \\tilde{\\theta_1}b y + \\tilde{\\theta_2}b r\n\\end{split}\n\\end{equation}\nWe now use a Lyapunov (ish?) function $V = \\frac{1}{2}e^2 + \\frac{b}{2\\gamma_1}\\tilde{\\theta_1^2} + \\frac{b}{2\\gamma_2}\\tilde{\\theta_2^2} $.\n\n\\begin{equation}\n\\begin{split}\n\\dot{V} &= e\\dot{e} \t+ \\frac{b}{\\gamma_1}\\tilde{\\theta_1}\\dot{\\tilde{\\theta_1}}\n\t\t\t\t+ \\frac{b}{\\gamma_2} \\tilde{\\theta_2}\\dot{\\tilde{\\theta_2}} \\\\\n&= \te (-a_m e - \\tilde{\\theta_1}b y + \\tilde{\\theta_2}b r)\n\t+ \\frac{b}{\\gamma_1}\\tilde{\\theta_1}\\dot{\\theta_1}\n\t+ \\frac{b}{\\gamma_2}\\tilde{\\theta_2}\\dot{\\theta_2} \\\\\n&= -a_m e^2 \t+ \\frac{b}{\\gamma_1}\\tilde{\\theta_1}(\\dot{\\theta_1}  - \\gamma_1 y e)\n\t\t\t+ \\frac{b}{\\gamma_2}\\tilde{\\theta_2}(\\dot{\\theta_2} + \\gamma_2 r e )\n\\end{split}\n\\end{equation}\nThe update laws are selected such that the derivative Lyapunov function are negative semi-definite.\n\n\\begin{equation}\n\\begin{split}\n(\\dot{\\theta_1}  - \\gamma_1 y e) &= 0 \\Rightarrow \\dot{\\theta_1} = \\gamma_1 y e \\\\\n(\\dot{\\theta_2} + \\gamma_2 r e ) &= 0 \\Rightarrow \\dot{\\theta_2} = \\gamma_2 r e\n\\end{split}\n\\end{equation}\nIt can now be shown that $e,\\tilde{\\theta_1}, \\tilde{\\theta_2},r,y_m,y,\\dot{e} \\in L_\\infty$ and $e \\in L_2$, which leads to $\\lim_{t \\to \\infty} e(t) \\rightarrow 0$ from Lemma 3.2.5.\n", "meta": {"hexsha": "c351541f2f4819ad2c70c29d30c2710910c0a073", "size": 3421, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4215 System identification and adaptive control/sec-mrac.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-mrac.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-mrac.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": 48.1830985915, "max_line_length": 245, "alphanum_fraction": 0.6559485531, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6059823171661863}}
{"text": "\\section{A case study in clustering}\\label{section:examples}\n\n\\subsection{\\(k\\)-means clustering}\n\nThe following examples act as a form of validation for EDO, and also highlight\nsome of the nuances in its use. The objective of these examples is to use the\nproposed method to reproduce some known results about the clustering of data in\nthe absence of any external forces, and to examine how clustering algorithms are\ntypically evaluated. In particular, the focus will be on the well-known\n\\(k\\)-means (Lloyd's) algorithm. Clustering was chosen as it is a\nwell-understood problem that is easily accessible \\-- especially when restricted\nto two dimensions. The \\(k\\)-means algorithm is an iterative, centroid-based\nmethod that aims to minimise the `inertia' of the current partition, \\(Z =\n\\left\\{Z_1, \\ldots, Z_k\\right\\}\\), of some dataset \\(X\\):\n\\begin{equation}\n    I(Z, X) := \\frac{1}{|X|} \\sum_{j=1}^{k} \\sum_{x \\in Z_j} {d(x, z_j)}^2\n    \\label{eq:inertia}\n\\end{equation}\n\nA full statement of the algorithm to minimise~(\\ref{eq:inertia}) is given\nin~\\ref{app:kmeans}. \n\nThis inertia function is taken as the objective of the \\(k\\)-means algorithm,\nand is used for evaluating the final clustering. This is particularly true when\nthe algorithm is not being considered an unsupervised classifier where accuracy\nmay be used~\\cite{Huang1998}. With that, the first example will use this inertia\nas the fitness function in EDO.\\ That is, to find datasets which minimise \\(I\\).\n\nFor the purposes of visualisation, EDO is restricted to the space containing\nonly two-dimensional datasets, i.e.\\ \\(C = \\left((2, 2)\\right)\\). In addition to\nthis, all columns are formed from uniform distributions where the bounds are\nsampled from the unit interval. Thus, the only family in \\(\\mathcal{P}\\) is:\n\\begin{equation}\n    \\mathcal{U} := \\left\\{U(a, b)~|~a, b \\in [0, 1]\\right\\}\n\\end{equation}\n\nThe remaining parameters are as follows: \\(N~=~100\\), \\(R~=~(3, 100)\\),\n\\(M~=~1000\\), \\(b~=~0.2\\), \\(l~=~0\\), \\(p_m~=~0.01\\), and shrinkage is excluded.\nFigure~\\ref{fig:small-inertia-50} shows an example of the fitness (above) and\ndimension (below) progression of the evolutionary algorithm under these\nconditions up until the \\(50^{th}\\) epoch.\n\nThere is a steep learning curve here; within the first 50 generations an\nindividual is found with a fitness of roughly \\(10^{-10}\\) which could not be\nimproved on for a further 900 epochs. The same quick convergence is seen in the\nnumber of rows. This behaviour is quickly recognised as preferable and was\ndominant across all the trials conducted in this work. This preference for\ndatasets with fewer rows is expected given that \\(I\\) is the sum of the mean\nerror from each cluster centre. With that, when \\(k\\) is fixed \\textit{a\npriori}, reducing the number of points in each cluster (i.e.\\ the terms of the\nsecond summation) quickly reduces the mean error of that cluster and thus the\nvalue of \\(I\\).\n\n\\addtocounter{figure}{1}\n\\begin{figure}[htbp]\n    \\ContinuedFloat%\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig7a-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig7a-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for final inertia and dimension across the first 50\n        epochs with \\(R~=~(3,100)\\).\n    }\\label{fig:small-inertia-50}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\ContinuedFloat%\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig7b-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig7b-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for final inertia and dimension across the first 50 epochs\n        with \\(R~=~(50,100)\\).\n    }\\label{fig:large-inertia-50}\n\\end{figure}\n\nHowever, something that may be seen as unwanted is a compaction of the cluster\ncentres. Referring to Figure~\\ref{fig:small-inertia-inds}, the best and median\nindividuals show two clusters that are essentially the same point whereas the\nworst is a random cloud across the whole of \\(\\mathcal{U}\\) which was found in\nthe initial population. The kind of behaviour exhibited by the best performing\nindividuals here occurs in part because it is allowed. There are two immediate\nways in which this allowed: first, that a near-trivial case is included in \\(R\\)\nand, secondly, that the fitness function does nothing to penalise the proximity\nof the inter-cluster means, as well as aiming to reduce the intra-cluster means.\nThis kind of unwanted behaviour highlights a subtlety in how EDO should be used;\nthat experimentation and rigour are required to properly understand an\nalgorithm's quality.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\subfloat[][]{%\n        \\label{fig:small-inertia-inds}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig8a.pdf}\n    }\\\\\n\n    \\subfloat[][]{%\n        \\label{fig:large-inertia-inds}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig8b.pdf}\n    }\n    \\caption[]{%\n        Representative individuals based on inertia with:\n        \\subref{fig:small-inertia-inds} \\(R~=~(3,100)\\);\n        \\subref{fig:large-inertia-inds} \\(R~=~(50,100)\\). Centroids displayed as\n        crosses.\n    }\\label{fig:inertia-inds}\n\\end{figure}\n\nHence, consider Figure~\\ref{fig:large-inertia-inds} where the individuals have\nbeen generated with the same parameters as previously except with adjusted row\nlimits, \\(R = (50, 100)\\), so as to exclude this trivial case. In these trials,\nthe results are equivalent: the worst performing individuals are without\nstructure whilst the best-performing individuals display clusters that are dense\nabout a single point despite the minimum number of rows being increased.\nSupposing this was not already a known result, we can see mounting evidence in\nfavour of this compaction being `optimal' behaviour in a dataset for \\(k\\)-means\nclustering.\n\nHowever, the fitness function may be addressed still, and more extensive\nstudying may be done. Indeed, the final inertia could be considered a flawed or\nfragile fitness function if it is supposed to evaluate the efficacy of the\n\\(k\\)-means algorithm. Incorporating the inter-cluster spread to the fitness\nof an individual dataset would reduce this observed compaction. For instance,\nthe silhouette coefficient is a metric used to evaluate the appropriateness of a\nclustering to a dataset and does precisely that. The silhouette coefficient of a\nclustering of a dataset is given by the mean of the silhouette value,\n\\(S(x)\\), of each point \\(x \\in Z_j\\) in each cluster:\n\\begin{equation}\n    \\begin{gathered}\n        A(x) := \\frac{1}{|Z_j| - 1} \\sum_{y \\in Z_j \\setminus \\{x\\}} d(x, y),\n        \\\\\n        B(x) := \\min_{k \\neq j} \\frac{1}{|Z_k|} \\sum_{w \\in Z_k} d(x, w),\n        \\\\\n        S(x) := \n            \\begin{cases}\n                \\frac{B(x) - A(x)}{\\max\\left\\{A(x), B(x)\\right\\}}\n                &\\quad \\text{if } |Z_j| > 1\\\\\n                0 &\\quad \\text{otherwise}\n            \\end{cases}\n    \\end{gathered}\\label{eq:silhouette}\n\\end{equation}\\\\\n\nThe optimisation of the silhouette coefficient is analogous to finding a dataset\nwhich increases both the intra-cluster cohesion (the inverse of \\(A\\)) and\ninter-cluster separation (\\(B\\)). Hence, the objective of minimising inertia is\naddressed by maximising cohesion. Meanwhile, the additional desire to spread out\nthe clusters is considered by maximising separation.\n\nRepeating the trials with the same parameters as with inertia, the silhouette\nfitness function yields the results summarised in\nFigures~\\ref{fig:small-silhouette}~and~\\ref{fig:large-silhouette}. Irrespective\nof row limits, the datasets produced show increased separation from one another\nwhilst maintaining low values in the final inertia of the clustering as shown in\nFigure~\\ref{fig:silhouette-inds}. Again, the form of the individual clusters is\nmuch the same. The low values of inertia correspond to tight clusters, and the\ntightest clusters are those with a minimal number of points, i.e.\\ a single\npoint. As with the previous example, albeit at a much slower rate, the\npreferable individuals are those leading toward this case. That this gradual\nreduction in the dimension of the individuals occurs despite adjusting the\nfitness function and considering the space which excludes the trivial case\nbolsters the claim that the base case is also optimal.\n\nAt this point, it should be noted that, due to the nature of the implementation,\nany individual from any generation may be retrieved and studied should the final\nresults be too concentrated on any given case. The summary provided here is one\nparticular way of studying the body of datasets generated with this method and\nthis transparency in the history and progression of the proposed method is\nsomething that sets it apart from other methods such as GANs which have a\nreputation of providing so-called `black box' solutions.\n\n\\addtocounter{figure}{1}\n\\begin{figure}[htbp]\n    \\ContinuedFloat%\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig9a-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig9a-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for silhouette and dimension across 1000 epochs at 100\n        epoch intervals with \\(R~=~(3, 100)\\).\n    }\\label{fig:small-silhouette}\n\\end{figure}\n\n\\begin{figure}\n    \\ContinuedFloat%\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig9b-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig9b-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for silhouette and dimension across 1000 epochs at 100\n        epoch intervals with \\(R~=~(50,100)\\).\n    }\\label{fig:large-silhouette}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\subfloat[][]{%\n        \\label{fig:small-silhouette-inds}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig10a.pdf}\n    }\\\\\n\n    \\subfloat[][]{%\n        \\label{fig:large-silhouette-inds}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig10b.pdf}\n    }\n    \\caption[]{%\n        Representative individuals based on silhouette with:\n        \\subref{fig:small-silhouette-inds} \\(R~=~(3,100)\\);\n        \\subref{fig:large-silhouette-inds} \\(R~=~(50,100)\\). Centroids displayed\n        as crosses.\n    }\\label{fig:silhouette-inds}\n\\end{figure}\n\n\\subsection{Comparison with DBSCAN}\\label{subsec:dbscan}\n\nThe extent of the capabilities EDO holds as a tool to better understand an\nalgorithm are especially apparent when comparing an algorithm against another\n(or set of others) simultaneously. This is done by utilising the freedom of\nchoice in a fitness function for EDO.\\ Consider two algorithms, \\(A\\) and \\(B\\),\nand some common metric between them, \\(g\\). Then their similarities and\ncontrasts can be explored by considering the differences in this metric on the\ntwo algorithms. In terms of EDO, this means using \\(f = g_A - g_B\\), \\(f = g_B -\ng_A\\) or \\(f = \\left| g_B - g_A \\right|\\) as the fitness function. By doing so,\npitfalls, edge cases or fundamental conditions for the method may be\nhighlighted. Overall, this process allows the researcher to more deeply learn\nabout the method of interest beyond the traditional method of literature\ncomparison on a particular example.\n\nConsider the following use case with another clustering algorithm of a different\nform, Density Based Spatial Clustering of Applications with Noise (DBSCAN). In\nthis particular case, the objective is to find datasets for which the method of\ninterest, \\(k\\)-means, outperforms its alternative, DBSCAN.\\ Here there is no\nconcept of inertia as DBSCAN is density-based and is able to identify\noutliers~\\cite{Ester1996}. As such, a valid metric must be chosen. One such\nmetric is the silhouette score as defined in~(\\ref{eq:silhouette}).\n\nIn this case, however, an adjustment to the fitness function must be made so as\nto accommodate for the condition of the silhouette coefficient that there must\nbe more than one cluster present. Let \\(S_k (X)\\) and \\(S_D (X)\\) denote the\nsilhouette coefficients of the clustering found by \\(k\\)-means and DBSCAN\nrespectively. Then the fitness function is defined to be:\n\\begin{equation}\n    f(X) = \n        \\begin{cases}\n            S_D (X) - S_k (X), &\\quad \\text{%\n                \\begin{tabular}{l}%\n                    if DBSCAN identifies two or\n                    \\\\\n                    more clusters (inc.\\ noise)\n                \\end{tabular}\n            }\\\\\n            \\infty &\\quad \\ \\ \\text{otherwise.}\n        \\end{cases}\\label{eq:dbscan-fitness}\n\\end{equation}\n\nThere are several remarks to be made here. First, note the order of the\nsubtraction here as EDO minimises fitness functions by default. Also, \\(f\\)\ntakes values in the range \\([-2, 2]\\) where \\(-2\\) is the best, i.e.\\ \\(S_D(X) =\n-1\\) and \\(S_k(X) = 1\\). Likewise, 2 is the worst score. Finally, the silhouette\ncoefficient requires at least two clusters to be present and so if DBSCAN\nidentifies a single cluster then that individual will be penalised heavily under\nthis fitness function when, in fact, that clustering may be of high quality. As\nsuch, this fitness function may require adjustment.\n\nIt must also be acknowledged that \\(k\\)-means and DBSCAN share no common\nparameters and so direct comparison is more difficult. For the purposes of this\nexample, only one set of parameters is used but a thorough investigation should\ninclude a parameter sweep in similar, real-world use cases. The parameters being\nused are \\(k~=~3\\) for \\(k\\)-means, and \\(\\epsilon~=~0.1,\\ MinPoints~=~5\\) for\nDBSCAN.\\ This set was chosen following informal experimentation using the Python\nlibrary Scikit-learn~\\cite{scikit} to find comparable parameters in the given\nsearch space defined by the EDO parameters used previously with\n\\(R~=~(50,100)\\).\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig11-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig11-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for difference in silhouette (\\(k\\)-means-preferable) and\n        dimension across 1000 epochs at 100 epoch intervals.\n    }\\label{fig:dbscan-silhouette}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\subfloat[][]{%\n        \\label{fig:dbscan-inds-k}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig12a.pdf}\n    }\\\\\n    \\subfloat[][]{%\n        \\label{fig:dbscan-inds-d}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig12b.pdf}\n    }\n    \\caption[]{%\n        Representative individuals from a \\(k\\)-means-preferable run with\n        clustering by: \\subref{fig:dbscan-inds-k} \\(k\\)-means;\n        \\subref{fig:dbscan-inds-d} DBSCAN.\\ Concave and convex hulls illustrated\n        by shading and outline respectively. \n    }\\label{fig:dbscan-inds}\n\\end{figure}\n\nFigure~\\ref{fig:dbscan-silhouette} shows a summary of the progression of EDO\nfor this use case. As with the previous examples where \\(R~=~(50, 100)\\), the\nvariation in the population fitness is unstable but there is a clear trend of\nimprovement in the best individual over the course of the run. There is also a\nconvergence seen in the number of rows a dataset has. The resting dimension\nvaried across the trials conducted in this work but none exhibited a dramatic\nshift toward the lower limit of 50 rows as with previous examples. This is\nsuggestive of a more competitive environment for individuals where slight\nchanges to an individual can drastically alter their fitness.\n\nThe effect of such changes can be seen in Figure~\\ref{fig:dbscan-inds} where\nrepresentative individuals are shown for this example. Here, the best performing\nindividual, when clustered by \\(k\\)-means, shows three clear and nicely\nseparated clusters. Note that they are not so tightly packed; again, this\nsuggests that the route to an optimal individual is less clearly defined. In\ncontrast, when the same dataset is clustered by DBSCAN a single cluster is found\nwith a single noise point held within the convex hull of the cluster, i.e.\\\nthere are overlapping clusters (since noise points form a single cluster).\nHence, along with the fact that the larger cluster is widely spread, it follows\nthat the clustering has a relatively small, negative silhouette coefficient.\n\nAnother point of interest here is the convexity of the clusters. A known\ncondition for the success of \\(k\\)-means is that the presented clusters are of\nroughly equal size and are convex. This is due to the overall objective being to\napproximate the centroidal Voronoi tessellation~\\cite{Du2006}. Without this\ncondition, up to the correct choice of \\(k\\), the algorithm will fail to produce\nadequate results for either inertia or silhouette. DBSCAN, on the other hand,\ndoes not have this condition and is able to detect non-convex clusters so long\nas they are dense enough. Figure~\\ref{fig:dbscan-inds} shows the clustering\nfound by each method and the respective convex and concave hulls of the clusters\nfound. The `concave hull' of a cluster is taken to be the \\(\\alpha\\)-shape of\nthe cluster's data points~\\cite{Edelsbrunner1983} where \\(\\alpha\\) is determined\nto be the smallest value such that all the points in the cluster are contained\nin a single polygon. The convexity of cluster \\(Z_j\\), denoted\n\\(\\mathcal{C}_j\\), is then determined to be the ratio of the area of its concave\nhull, \\(H_c\\), to the area of its convex hull, \\(H_v\\)~\\cite{Sonka1993}:\n\\begin{equation}\n    \\mathcal{C}_j := \\frac{area(H_c)}{area(H_v)}\n\\end{equation}\n\nWith this definition, it should be clear that a perfectly convex cluster, such\nas a single point or line, would have \\(\\mathcal{C}_j = 1\\).\n\nIt can be seen that the convexity of the clustering found by \\(k\\)-means appears\nto be higher than that by DBSCAN.\\ This was apparent across all trials conducted\nin this work and indicates that the condition for convex clusters is being\nsought out during the optimisation process. Meanwhile, however, it is not clear\nwhether the performance of DBSCAN falls owing to its parameters or the method\nitself. This is a point where parameter sweeping would prove most useful so as\nto determine a crossing point for these two driving forces.\n\nNow, to add to the discussion above, the inverse optimisation should be\nconsidered. That is, using the same parameters, the datasets for which DBSCAN\noutperforms \\(k\\)-means with respect to the silhouette coefficient are to be\ninvestigated. This is equivalent to using \\(-f\\) as the fitness function\nexcept with the same penalty of \\(\\infty\\) for the case set out\nin~(\\ref{eq:dbscan-fitness}).\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{tabular}{c}\n        \\includegraphics[width=\\imgwidth]{Fig13-1.pdf}\n        \\\\\n        \\includegraphics[width=\\imgwidth]{Fig13-2.pdf}\n    \\end{tabular}\n    \\caption{%\n        Progressions for difference in silhouette (DBSCAN-preferable) and\n        dimension across 1000 epochs at 100 epoch intervals.\n    }\\label{fig:negative-prog}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\subfloat[][]{%\n        \\label{fig:neg-inds-k}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig14a.pdf}\n    }\\\\\n    \\subfloat[][]{%\n        \\label{fig:neg-inds-d}\n        \\centering\n        \\includegraphics[width=\\imgwidth]{Fig14b.pdf}\n    }\n    \\caption[]{%\n        Representative individuals from a DBSCAN-preferable run with clustering\n        by: \\subref{fig:dbscan-inds-k} \\(k\\)-means; \\subref{fig:dbscan-inds-d}\n        DBSCAN.\\ Concave and convex hulls illustrated by shading and outline\n        respectively. \n    }\\label{fig:negative-inds}\n\\end{figure}\n\nFigures~\\ref{fig:negative-prog}~and~\\ref{fig:negative-inds} show the same\nsummary as above with the revised fitness function. Inspecting the former, it is\nseen that the best fitness found is worse than with the previous example. This,\nin part, is due to the fact that \\(k\\)-means cannot find a clustering with\nnegative values as no clusters may overlap. It can, however, produce results\nwith small silhouette scores where the clusters are tightly packed. Hence, the\nbest fitness score is now \\(-1\\) whereas the worst is 2, still.\n\nNote in the first two frames of Figure~\\ref{fig:neg-inds-k} how \\(k\\)-means is\nforced to split what is evidently a single cluster in two whereas DBSCAN is able\nto identify the single cluster and the outlying noise\n(Figure~\\ref{fig:neg-inds-d}). The proximity of these clusters has then dragged\nthe silhouette score down for \\(k\\)-means. Referring to\nFigure~\\ref{fig:neg-inds-d}, this kind of behaviour is certainly preferable for\nDBSCAN under these parameters: the beginning individuals are likely random\nclouds (as seen in the rightmost two frames of the figure) and the simplest step\ntoward a fit dataset is one that maintains that vaguely dense body with minimal\nnoise points far from it.\n\nAs has already been stated, the software implementation of the EDO method\nhas been produced in line with the best practices of open source software\ndevelopment and reproducible research. In aid of this, all of the source code\nused in these examples (including to create the figures) has been archived\nunder the DOI\n\\href{https://doi.org/10.5281/zenodo.3492236}{10.5281/zenodo.3492236}.\nLikewise, all of the data produced to support this case study have been archived\nunder the DOI\n\\href{https://doi.org/10.5281/zenodo.3492228}{10.5281/zenodo.3492228}.\n\n\n", "meta": {"hexsha": "84fb901fa057c5c16c74dcee9518bf75cb6746de", "size": 21369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/examples.tex", "max_stars_repo_name": "daffidwilde/edo-paper", "max_stars_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_stars_repo_licenses": ["MIT"], "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/examples.tex", "max_issues_repo_name": "daffidwilde/edo-paper", "max_issues_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_issues_repo_licenses": ["MIT"], "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/examples.tex", "max_forks_repo_name": "daffidwilde/edo-paper", "max_forks_repo_head_hexsha": "5bd803f7fe52a7043ce39fbec0ae7974ce89029a", "max_forks_repo_licenses": ["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.1283783784, "max_line_length": 80, "alphanum_fraction": 0.7289531564, "num_tokens": 5503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879312056025699, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6059823100595748}}
{"text": "\\section{Exercise 01}\n\\subsection{}\n\n\\begin{frame}\n\\frametitleTC{Direct synthesis for set point tracking}\n\\framesubtitleTC{Some examples}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item Example 1 (OK):\n       \\begin{displaymath}\n        \\begin{array}{lcl}\n         P(z)              = \\frac{(z-0.5)}{(z-0.4)^2},\\,\n         G_{yw}^{\\circ}(z) = \\frac{0.2}{z-0.8} &\n         \\Rightarrow &\n         C(z)              = \\frac{0.2(z-0.4)^2}{(z-1)(z-0.5)}.\n        \\end{array}\n       \\end{displaymath}\n \\item Example 2 (\\red{NO}, process pole outside the circle $\\Rightarrow$ unstable hidden part):\n       \\begin{displaymath}\n        \\begin{array}{lcl}\n         P(z)              = \\frac{1}{\\red{z-2}},\\,\n         G_{yw}^{\\circ}(z) = \\frac{0.2}{z-0.8} &\n         \\Rightarrow &\n         C(z)              = \\frac{0.2\\red{(z-2)}}{z-1}.\n        \\end{array}\n       \\end{displaymath}\n \\item Example 3 (\\red{NO}, infeasible relative degree):\n       \\begin{displaymath}\n        \\begin{array}{lcl}\n         P(z)              = \\frac{1}{(z-0.4)^2},\\,\n         G_{yw}^{\\circ}(z) = \\frac{0.2}{z-0.8} &\n         \\Rightarrow &\n         C(z)              = \\frac{0.2(z-0.4)^{\\textcolor{red}{2}}}{z-1}.\n        \\end{array}\n       \\end{displaymath}\n \\item Try one/two cases of your own, verify that everything is clear,\\\\\n       ask questions if necessary.\n \\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Direct synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item If the process has poles on or outside the circle, we must preserve them in the desired loop transfer\n       function\n       \\begin{displaymath}\n        L^{\\circ}(z) = \\frac{G_{yw}^{\\circ}(z)}{1-G_{yw}^{\\circ}(z)}\n       \\end{displaymath}\n       so as to not have $C(z)$ cancel them and generate an unstable hidden part.\n \\item If the process has zeroes on or outside the circle, we must include them in $G_{yw}^{\\circ}(z)$\\\\\n       -- hence in $L^{\\circ}(z)$ -- so that $C(z)$ does not cancel them either; this may\\\\\n       require to also add poles to have at least as many as there are zeroes.\n \\item If the relative degree of $G_{yw}^{\\circ}(z)$ is infeasible, we need to add ``fast''\\\\\n       (near to the origin) poles and/or delay terms.\n \\item\\vfill Let us clarify with a few simulation examples. \n \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}[fragile]\n\\frametitleTC{Direct synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations -- Scilab script (1/3, copy{\\&}paste to try at home)}\n{\\tiny\n\\def\\baselinestretch{0.3}\n\\begin{verbatim}\n// Direct synthesis examples -- set point tracking\nclear; clc; z = %z;\n// Reference and time vectors\nw  = ones(1,30); \nk  = 0:length(w)-1;\n// Process 1, asymptotically stable, no zeroes\nP1 = syslin('d',2/(z-0.5)^2);\n// Infeasible relative degree\nTo = syslin('d',0.2/(z-0.8));\nR  = 1/P1*To/(1-To); disp(R); y1 = dsimul(tf2ss(To),w);\n// Adding a fast pole for a realisable R\nTo = syslin('d',0.16/(z-0.8)/(z-0.2));\nR  = 1/P1*To/(1-To); disp(R); y2 = dsimul(tf2ss(To),w);\n// Adding a faster pole\nTo = syslin('d',0.19/(z-0.8)/(z-0.05));\nR  = 1/P1*To/(1-To); disp(R); y3 = dsimul(tf2ss(To),w);\n// Adding a one-step delay\nTo = syslin('d',0.2/(z-0.8)/z);\nR  = 1/P1*To/(1-To); disp(R); y4 = dsimul(tf2ss(To),w);\n// Using two poles, both faster than the design one\np1 = 0.75;\np2 = 0.45;\nTo = syslin('d',(1-p1)*(1-p2)/(z-p1)/(z-p2));\nR  = 1/P1*To/(1-To); disp(R); y5 = dsimul(tf2ss(To),w);\n\\end{verbatim}\n}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitleTC{Direct synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations -- Scilab script (2/3)}\n{\\tiny\n\\def\\baselinestretch{0.3}\n\\begin{verbatim}\n// Process 2, asymptotically stable,, 1 zero outside the circle\nP2 = syslin('d',(z-2)/(z-0.5)^2);\n// Infeasible To\nTo = syslin('d',0.2/(z-0.8));\nR  = 1/P2*To/(1-To); disp(R); y6 = dsimul(tf2ss(To),w);\n// Adding the required zero to To\nTo = syslin('d',-0.18*(z-2)/(z-0.8)/(z-0.1));\nR  = 1/P2*To/(1-To); disp(R); y7 = dsimul(tf2ss(To),w);\n// Improving by acting on the To poles\np1 = 0.78;\np2 = 0.02;\nTo = syslin('d',-(1-p1)*(1-p2)*(z-2)/(z-p1)/(z-p2));\nR  = 1/P2*To/(1-To); disp(R);\ny8 = dsimul(tf2ss(To),w);\n\\end{verbatim}\n}\n\\end{frame}\n\n\\begin{frame}[fragile]\n\\frametitleTC{Direct synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations -- Scilab script (3/3)}\n{\\tiny\n\\def\\baselinestretch{0.3}\n\\begin{verbatim}\n// Plot the results for process 1\nh               = scf(0); clf;\nh.figure_size   = [500,500];\ntitle(\"${\\Large \\text{Cases 1--5}$\");\nxlabel(\"k\");\nplot(k,y1,'r',k,y1,'r.');\nplot(k,y2,'b',k,y2,'b.');\nplot(k,y3,'m',k,y3,'m.');\nplot(k,y4,'g',k,y4,'g.');\nplot(k,y5,'k',k,y5,'k.');\nax              = gca();\nax.data_bounds  = [0,0;max(k),1.1];\nax.tight_limits = \"on\";\n// Plot the results for process 2\nh               = scf(1); clf;\nh.figure_size   = [500,500];\ntitle(\"${\\Large \\text{Cases 6--8}$\");\nxlabel(\"k\");\nplot(k,y6,'r',k,y6,'r.');\nplot(k,y7,'b',k,y7,'b.');\nplot(k,y8,'k',k,y8,'k.');\nax              = gca();\nax.data_bounds  = [0,-0.3;max(k),1.1];\nax.tight_limits = \"on\";\n\\end{verbatim}\n}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations -- summary}\n\\myPause\n\\begin{center}\n {\\scriptsize\n \\begin{tabular}{llll}\n  \\hline\nCase & Process                   & Requirement                                                           & Controller  \\\\\n\\hline\\hline\n1& $P_1(z)=\\frac{2}{(z-0.5)^2}$  & $G_{yw,11}^{\\circ}(z)=\\frac{0.2}{z-0.8}$                              & Infeasible  \\\\\n2&                               & $G_{yw,12}^{\\circ}(z)=\\frac{0.16}{(z-0.8)(z-0.2)}$                    & $C_{12}(z)$ \\\\\n3&                               & $G_{yw,13}^{\\circ}(z)=\\frac{0.19}{(z-0.8)(z-0.05)}$                   & $C_{13}(z)$ \\\\\n4&                               & $G_{yw,14}^{\\circ}(z)=\\frac{0.2}{z(z-0.8)}$                           & $C_{14}(z)$ \\\\\n5&                               & $G_{yw,15}^{\\circ}(z)=\\frac{(1-0.75)(1-0.45)}{(z-0.75)(z-0.45)}$      & $C_{15}(z)$ \\\\\n\\hline\n6& $P_2(z)=\\frac{z-2}{(z-0.5)^2}$& $G_{yw,21}^{\\circ}(z)=\\frac{0.2}{z-0.8}$                              & Infeasible  \\\\\n7&                               & $G_{yw,22}^{\\circ}(z)=-\\frac{0.18(z-2)}{(z-0.8)(z-0.1)}$              & $C_{22}(z)$ \\\\\n8&                               & $G_{yw,23}^{\\circ}(z)=-\\frac{(1-0.78)(1-0.02)(z-2)}{(z-0.78)(z-0.02)}$& $C_{23}(z)$ \\\\\n  \\hline\n \\end{tabular}\n }\n\\end{center}\n\\end{frame}\n\n\\begin{frame}\n\\frametitleTC{Synthesis for set point tracking}\n\\framesubtitleTC{Dealing with the limitations -- results}\n\\myPause\n\\begin{center}\n {\\scriptsize\n \\begin{tabular}{ll}\n  \\includegraphics[width=0.35\\textwidth]{./Unit-05/img/PS02-ex01-res-1to5.pdf} &\n  \\includegraphics[width=0.35\\textwidth]{./Unit-05/img/PS02-ex01-res-6to8.pdf}      \\\\\n   \\red{$P_1,G_{yw,11}^{\\circ}\\Rightarrow$ infeasible} &  \\red{$P_2,G_{yw,21}^{\\circ}\\Rightarrow$ infeasible} \\\\\n  \\blue{$P_1,G_{yw,12}^{\\circ}\\Rightarrow$ $C_{12}$}   & \\blue{$P_2,G_{yw,22}^{\\circ}\\Rightarrow$ $C_{22}$}   \\\\\n   \\mgt{$P_1,G_{yw,13}^{\\circ}\\Rightarrow$ $C_{13}$}   &       $P_2,G_{yw,23}^{\\circ}\\Rightarrow$ $C_{23}$    \\\\\n   \\grn{$P_1,G_{yw,14}^{\\circ}\\Rightarrow$ $C_{14}$}   \\\\\n        $P_1,G_{yw,15}^{\\circ}\\Rightarrow$ $C_{15}$    \\\\\n \\end{tabular}\n }\n\\end{center}\n\\end{frame}\n\n\n\\begin{frame}\n\\frametitleTC{Synthesis for set point tracking}\n\\framesubtitleTC{Summary}\n\\myPause\n \\begin{itemize}[<+-| alert@+>]\n \\item The technique is powerful, however there are \\TC{objective} limits.\n \\item In many of the cases seen the controller has one or two zeroes and one or two poles, \n       one of which in $z=1$.\n \\item We shall soon call this a PI(D).\n \\item \\vfill You can try at home: open Scilab, launch the code editor SciNotes\\\\\n       from the \\texttt{Applications} menu, enter the code from the previous\\\\\n       slides (copy{\\&}paste) and run with the \\texttt{Execute} command\\\\\n       --- all IDEs look pretty much the same, in the end...\n \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "714dc963ad5e0f541e3b0232f394cc75665ddcf2", "size": 8030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/Unit-05/sections/02-PS02-ex01.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/02-PS02-ex01.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/02-PS02-ex01.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": 37.523364486, "max_line_length": 121, "alphanum_fraction": 0.5683686177, "num_tokens": 2936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6059823023997855}}
{"text": "\\documentclass[10pt,letterpaper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{tikz}\n\\usepackage{hyperref}\n\n\\newcommand{\\volume}{{\\ooalign{\\hfil$V$\\hfil\\cr\\kern0.08em--\\hfil\\cr}}}\n\n\\author{Thaddeus Hughes \\\\ hughes.thad@gmail.com \\\\ thaddeus-maximus.github.io}\n\\date{\\today}\n\\title{Adiabatic Model of a Pneumatic Cylinder}\n\n\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\begin{abstract}\n\t\tThere are some basic models for pneumatic cylinders that result in modeling cylinders as constant-force devices, or nearly so. This is a rough first pass at creating a model that is a little more sophisticated. This model assumes that the air in the cylinder is adiabatic; that is, no heat transfer takes place. This model will be a differential equation intended to be used in conjunction with a numerical DE solver due to the non-linear nature of many conditions.\n\t\t\n\t\tPneumatic pistons can be used for many scenarios- they can act as quick stops, can push or pull heavy loads, or can be configured to quickly launch objects. Depending on the nature of the system, they can behave quite differently, and this model may capture more of the underlying physics that affects these various use cases.\n\t\\end{abstract}\n\t\n\t\\section*{System Definition}\n\t\n\tWe will analyze the open system that is the air contained within a pneumatic cylinder, plus the air in the hose leading up to it (inclusion of the hose will become of crucial importance and will be evident later on).\n\t\\begin{center}\n\t\\begin{tikzpicture}[x=1.0in,y=1.0in]\n\t\t\\draw[->] (-0.5,0)--(-0.1,0) node[pos=0, left]{$P_{in}$, $\\dot{\\volume}_{in}$, $T_{in}$};\n\t\t\n\t\t\\draw[] (0.3,-0.1)--(0,-0.1)--(0,0.1)--(0.3,0.1)--(0.3,0.5)--(1.2,0.5)--(1.2,-0.5)--(0.3,-0.5)--cycle;\n\t\t\\node (state) [text width=0.4] at (0.65,0) {$m_s$ \\\\ $P_s$ \\\\ $\\volume_s$ \\\\ $T_s$};\n\t\t\\draw[->] (1.0, 0.6)--(1.4, 0.6) node[pos=0.5, above] {$v$, $x$};\n\t\t%\\draw[->] (1.9,0)--(1.4,0) node[pos=0, above] {$F = P_{atm} A$};\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tAir at pressure $P_{in}$ and temperature $T_{in}$ enters the cylinder at rate $\\dot{\\volume}_{in}$.\n\tIt mixes with air in the cylinder ($m_s$, $\\volume_s$) and is assumed to become of uniform pressure and temperature $P_s$ and $T_s$.\n\t\n\tThe piston ram is moving at velocity $v$ and with position $x$. $x$ is zero when the cylinder is bottomed out (no air in the cylinder). \n\t\n\t\\begin{center}\n\t\\begin{tikzpicture}[x=1.0in,y=1.0in]\n\t\t\\draw[ultra thick] (0,-0.5)--(0,0.5);\n\t\t\\draw[] (0,-0.15)--(0,0.15)--(1,0.15)--(1,-0.15)--cycle;\n\t\t\n\t\t\\node (ctr) [] at (0.5,0) {$M$};\n\t\t\n\t\t\\draw[->] (-0.3,0)--(-0.1,0) node[pos=0,left]{$P_s A$};\n\t\t\\draw[->] (-0.3,0.2)--(-0.1,0.2); \\draw[->] (-0.3,0.4)--(-0.1,0.4); \\draw[->] (-0.3,-0.2)--(-0.1,-0.2); \\draw[->] (-0.3,-0.4)--(-0.1,-0.4);\n\t\t\n\t\t\\draw[->] (1.3,0)--(1.1,0) node[pos=0,right]{$F_{load}$};\n\t\t\\draw[->] (0.3,0.3)--(0.1,0.3) node[pos=0,right]{$P_{atm} A$};\n\t\t\\draw[->] (0.3,-0.3)--(0.1,-0.3);\n\t\\end{tikzpicture}\n\t\\end{center}\n\t\n\tThe cylinder itself is considered to have a mass $M$ and sees the cylinder pressure, a resistive force $F_{load}$, and atmospheric pressure.\n\t\n\t\\section*{Conservation Principles In The Cylinder}\n\t\n\tFirst, let's apply conservation of mass to the air.\n\t\n\t\\begin{align}\n\t\t\\frac{d}{dt} m_{sys} &= \\sum_{+ in} \\dot{m} \\nonumber\n\t\\end{align}\\begin{align} \\label{eq:ddt_m}\n\t\t\\frac{d}{dt} m_s &= \\dot{m}_{in}\n\t\\end{align}\n\t\n\tWe can use the ideal gas law $P \\volume = m R T$ to write this in terms of knowns.\n\t\\begin{align}\n\t\t\\dot{m}_{in} = \\frac{P_{in} \\dot{\\volume}_{in}}{R T_{in}} \\nonumber\n\t\\end{align}\n\t\n\tWe'll assume that the primary flow restriction comes from the tube. We can use an equation derived from \\href{https://www.engineeringtoolbox.com/pressure-drop-compressed-air-pipes-d_852.html}{this empirical pipe flow equation in The Engineering ToolBox}.\n\t\n\t\\begin{align} \n\t\t\\dot{\\volume} = 0.0197862 (d_{tube}^5 [P_{in}-P_{atm}] [P_{in}-P_{s}]/L_{tube})^{20/37} \\nonumber\n\t\\end{align}\n\t(Assuming units of $Pa$, $m$, and $m^3/s$)\n\t\n\t\\begin{align} \\label{eq:sup_mdot}\n\t\t\\dot{m}_{in} = \\frac{0.0197862}{R T_{in}} (d_{tube}^5 [P_{in}-P_{atm}] [P_{in}-P_{s}]/L_{tube})^{20/37}\n\t\\end{align}\n\t\n\tNow, let's apply conservation of energy.\n\t\n\t\\begin{align}\n\t\t\\frac{d}{dt} E_{sys} = \\sum \\dot{Q}_{in} + \\sum \\dot{W}_{in} + \\sum_{+in} \\dot{m} (v^2/2 + gz + h) \\nonumber\n\t\\end{align}\n\t\n\tWe will assume:\n\t\\begin{itemize}\n\t\t\\item The energy of the system is entirely thermal; $E_sys$ = $m_s u(T)$\n\t\t\\item No heat transfer; $\\dot{Q}_{in} = 0$\n\t\t\\item Work is out of the system, defined by the pressure of the system and velocity of the ram; $\\dot{W}_{in} = - \\vec{F} \\cdot \\vec{v} = - P_s A v$\n\t\t\\item Mass transfer into the system has negligible velocity ($v$) and head height ($gz$), leaving only enthalpy $h(T)$.\n\t\\end{itemize}\t\t\n\t\n\t\\begin{align}\n\t\t\\frac{d}{dt} [m_s u(T)] = - P_s A v + \\dot{m}_{in} (h(T_{in} + (\\frac{\\dot{\\volume}}{\\pi / 4 \\ d_{tube}})^2) \\nonumber\n\t\\end{align}\n\t\n\tThe derivative here is quite ugly, since both the mass and temperature of the system are changing. However, it can be broken up with the product rule ($\\frac{d}{dt}[xy] = y \\frac{dx}{dt} + x \\frac{dy}{dt}$).\n\t\n\t\\begin{align} \n\t\tm_s \\frac{d u(T_s)}{dt} + u(T_s) \\frac{d m_s}{dt} = - P_s A v + \\dot{m}_{in}  (\\frac{\\dot{\\volume}}{\\pi / 4 \\ d_{tube}})^2 + \\dot{m}_{in} h(T_{in}) \\nonumber \\\\\n\t\tm_s \\frac{d u(T_s)}{dt} = \\dot{m}_{in} h(T_{in}) - P_s A v - u(T_s) \\frac{d m_s}{dt} + \\dot{m}_{in}  (\\frac{\\dot{\\volume}}{\\pi / 4 \\ d_{tube}})^2\\nonumber\n\t\\end{align}\n\t\n\tRecognizing that $u(T)$ and $h(T)$ can be approximated as $u(T) = c_p T$ and $h(T) = c_v T$, we can then solve the equation for $\\frac{dT_s}{dt}$.\n\t\n\t\\begin{align} \\label{eq:ddt_T}\n\t\t\\frac{d T_s}{dt} = \\frac{ \\dot{m}_{in}[ c_v T_{in} - c_p T_s + (\\frac{\\dot{\\volume}}{\\pi / 4 \\ d_{tube}})^2]     - P_s A v}{c_p m_s}\n\t\\end{align}\n\t\n\tAll of these are knowns or states aside from $P_s$, which can be determined with the ideal gas law, and the modeling of the system volume as based on cylinder extension, crossectional area, and initial (i.e. hose) dead volume.\n\t\n\t\\begin{align}\n\t\tP_s = \\frac{m_s R T_s}{\\volume_s} \\nonumber\n\t\\end{align}\\begin{align} \\label{eq:sup_P}\n\t\tP_s = \\frac{m_s R T_s}{\\volume_{dead} + x A}\n\t\\end{align}\n\t\n\t\\section*{Conservation Principles on the Piston}\n\t\n\tWe can simply apply conservation of linear momentum to the piston.\n\t\n\t\\begin{align}\n\t\t\\frac{d}{dt} P_{sys}= \\sum F + \\sum \\dot{m} v \\nonumber\n\t\\end{align}\n\t\n\tWe will assume:\n\t\\begin{itemize}\n\t\t\\item No mass transfer in this system, so $\\frac{d}{dt} P_{sys} = M \\frac{dv}{dt}$ and $\\dot{m}=0$\n\t\t\\item The forces acting on the piston are the cylinder pressure, atmospheric pressure, and the external load.\n\t\\end{itemize}\n\t\n\t\\begin{align}\n\t\tM \\frac{dv}{dt} &= P_s A - P_{atm} A - F_{load} \\nonumber\n\t\\end{align}\\begin{align}  \\label{eq:ddt_v}\n\t\t\\frac{dv}{dt} &= \\frac{(P_s - P_{atm}) A - F_{load}}{M}\n\t\\end{align}\n\t\n\tWe are also interested in the position of the piston.\n\t\n\t\\begin{align} \\label{eq:ddt_x}\n\t\t\\frac{dx}{dt} = v\n\t\\end{align}\n\t\n\t\\section*{Limiting the Model}\n\tIn review we have:\n\t\n\t\\begin{itemize}\n\t\t\\item A model for rate of change of $m_s$\n\t\t\\item A model for rate of change of $T_s$\n\t\t\\item Supporting equation for cylinder pressure $P_s$\n\t\t\\item Supporting equation for massflow into cylinder $\\dot{m}$\n\t\t\\item A model for velocity $v$\n\t\t\\item A model for position $x$\n\t\\end{itemize}\n\t\n\tWe simply now need initial conditions, \"bumper\" conditions, and termination criteria.\n\t\n\tWe will assume the initial temperature $T_s$ will be set to that of the input gas $T_{in}$. (This may seem like it would negate all the point of this model, but recall that when gases expand/contract, they change pressure)\n\t\n\t\\begin{align} \\label{eq:ic_T}\n\t\tT_s(t=0) = T_{in}\n\t\\end{align}\n\t\n\tThe initial mass of cylinder air can be found with the ideal gas law, assuming we start at atmospheric pressure (wholly unpressurized)\n\t\n\t\\begin{align} \\label{eq:ic_m}\n\t\tm_s(t=0) = \\frac{P_{atm} L_{tube} \\frac{\\pi}{4} d_{tube}^2}{R T_s(t=0)}\n\t\\end{align}\n\t\n%\tThere's an interesting edge case that our model doesn't look at, and that's when we overfill the cylinder. Air can't keep coming into our cylinder. An orifice model may be more appropriate, but let's just say that if the cylinder pressure is greater than the input pressure, no more air can be added.\n\t\n%\t\\begin{equation} \\label{eq:bump_pres}\n%\t\t\\mbox{if } P_s > P_{in} \\mbox{ then } \\dot{m}_{in} = 0\n%\t\\end{equation}\t \n\t\n\tAssume the piston starts from rest.\n\t\n\t\\begin{align} \\label{eq:ic_x}\n\t\tx(t=0) &= 0\n\t\\end{align}\\begin{align}\\label{eq:ic_v}\n\t\tv(t=0) &= 0\n\t\\end{align}\n\t\n\tAnd that the piston cannot go past its endstops at $x=x_f$ or $x=0$.\n\t\n\t\\begin{align} \\label{eq:bump_end}\n\t\t\\mbox{if } x \\geq x_f &\\mbox{ then } x = x_f, v \\leq 0\n\t\\end{align}\\begin{align}\\label{eq:bump_start}\n\t\t\\mbox{if } x \\leq 0   &\\mbox{ then } x = 0, v \\geq 0  \n\t\\end{align}\n\t\t\n\tWe will terminate our simulation when we reach the endstop and fully pressurize.\n\t\n\t\\begin{align} \\label{eq:term}\n\t\t\\mbox{terminate simulation if } x \\geq x_f \\mbox{ and } P_s \\geq P_{in}\n\t\\end{align}\n\t\n\t\\section*{The Full Model}\n\t\n\t\\begin{align}\n\t\t\\dot{m}_{in} &= \\frac{0.0197862}{R T_{in}} (d_{tube}^5 [P_{in}-P_{atm}] [P_{in}-P_{s}]/L_{tube})^{20/37} \\tag{\\ref{eq:sup_mdot}} \\\\\n\t\tP_s &= \\frac{m_s R T_s}{L_{tube} \\frac{\\pi}{4} d_{tube}^2 + x A} \\tag{\\ref{eq:sup_P}} \\\\\t\t\t\n\t\t\\mbox{if } x \\geq x_f &\\mbox{ then } x = x_f, v \\leq 0 \\tag{\\ref{eq:bump_end}} \\\\\n\t\t\\mbox{if } x \\leq 0   &\\mbox{ then } x = 0, v \\geq 0 \\tag{\\ref{eq:bump_start}} \\\\\n\t\t\\frac{d}{dt} m_s &= \\dot{m}_{in} \\tag{\\ref{eq:ddt_m}} \\\\\n\t\t\\frac{d T_s}{dt} &= \\frac{ \\dot{m}_{in} c_v T_{in} - P_s A v - c_p T_s \\dot{m}_{in} }{c_p m_s} \\tag{\\ref{eq:ddt_T}} \\\\\n\t\t\\frac{dv}{dt} &= \\frac{(P_s - P_{atm}) A - F_{load}}{M} \\tag{\\ref{eq:ddt_v}} \\\\\n\t\t\\frac{dx}{dt} &= v \\tag{\\ref{eq:ddt_x}} \\\\\n\t\tT_s(t=0)& = T_{in} \\tag{\\ref{eq:ic_T}} \\\\\n\t\tm_s(t=0) &= \\frac{P_{atm} L_{tube} \\frac{\\pi}{4} d_{tube}^2}{R T_s(t=0)} \\tag{\\ref{eq:ic_m}} \\\\\n\t\tv(t=0) &= 0 \\tag{\\ref{eq:ic_v}} \\\\\n\t\tx(t=0) &= 0 \\tag{\\ref{eq:ic_x}} \\\\\n\t\t\\mbox{terminate}& \\mbox{ if } x \\geq x_f \\mbox{ and } P_s \\geq P_{in} \\tag{\\ref{eq:term}}\n\t\\end{align}\n\t\n\tThere's a lot going on here. But let's do a sanity check and see if there's going to be any issues going forth.\n\t\n\tThe big equation of interest is $dT_s/dt$.\n\t\\begin{itemize}\n\t\t\\item If the heat capacity or system mass is larger, then the rate of temperature change decreases (makes sense)\n\t\t\\item If the cylinder expands ($v > 0$) then the gas expands, lowering the temperature.\n\t\t\\item Let's focus on this term\n\t\t\t\\begin{align}\n\t\t\t\t  & \\dot{m}_{in} c_v T_{in} - c_p T_s \\dot{m}_{in} \\nonumber \\\\\n\t\t\t\t=\\ & \\dot{m} [c_v T_{in} - c_p T_s] \\nonumber \\\\\n\t\t\t\t=\\ & \\dot{m} [h(T_{in}) - u(T_s)] \\nonumber \\\\\n\t\t\t\t=\\ & \\dot{m} [u(T_{in}) + P_{in} / \\rho_{in} - u(T_s)] \\nonumber \\\\\n\t\t\t\t\\approx \\ & \\dot{m} [u(T_{in}-T_s) + P_{in} / \\rho_{in}] \\nonumber\n\t\t\t\\end{align}\n\t\t\t\n\t\t\tRecognizing that $T_in > T_s$ since the cylinder is expanding, we see that yes, the massflow into the system corresponds to higher thermal energy transfer, and higher pressure energy transfer.\n\t\t\\item The mass of the system $m_s$ is in the denominator - if this is zero, the derivative would not exist, so it is imperative that we begin our simulation with some mass (hence, the dead mass $L_{tube} \\frac{\\pi}{4} d_{tube}^2$ term)\n\t\\end{itemize}\n\t\n\t\\section*{Implemented Simulation and Examples}\n\t\n\tThis has been implemented into my \\href{http://thaddeus-maximus.github.io/swissarmyengineer/}{Swiss Army Engineer} suite. Here are some example cases, starting with a base case.\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_1.png}\n\t\n\tThis case has mass, and a load much higher than the mass (simulating, say, a piston pushing on a spring). The results aren't too interesting - air inrushes into the cylinder rather quickly, producing the quadratic position profile you'd expect of a constant-force system.\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_2.png}\n\t\n\tThis case increases the mass by ten times. The timescale, accordingly, stretches out, taking much longer to reach its end stop.\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_3.png}\n\t\n\tThis case removes the load and returns to the lighter system mass, so that this is a purely inertial system. In this case, the piston accelerates like normal, but the cylinder pressure actually begins to decrease as the inertia of the system carries it further forwards. Eventually the hardstop is hit, and at this point the piston can fully pressurize with air.\n\t\n\tWhat happens if we choke it out even further, by shrinking the line diameter?\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_4.png}\n\t\n\tThe line diameter here has been shrunk to 2mm. We see this same decayed acceleration as in the previous example, but to a larger degree.\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_5.png}\n\t\n\tIf we add a large load, the position curve becomes linear, as the cylinder has to fight the heavy load and its air supply eventually becomes the limiting factor on speed.\n\t\n\t\\includegraphics[width=\\textwidth]{pneu_case_6.png}\n\t\n\tIf we make the load an expression, we could model a piston pulling on a spring, giving us this very neat mass-spring system.\n\t\n\t\\section*{Validation}\n\t\tNo validation has been performed yet on these models, as I don't have access to the equipment to test them. If anyone wants to perform this testing, it would be very cool!\n\t\t\n\t\\section*{Future Improvements (and when to say no)}\n\t\tThe next obvious improvement to make would be to model the flow restriction provided by valves. Beyond that, looking at pressure drop in the tank as air is consumed, or flow restriction as a result of the pressure regulator seems to me to be splitting hairs, and chasing high-speed actuation which would require significant testing anyways.\n\t\n\t\n\\end{document}", "meta": {"hexsha": "e1d5cde85c531478b7b4af472dca7743d02807a5", "size": 13797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/adiabatic_cylinder_model.tex", "max_stars_repo_name": "Thaddeus-Maximus/swissarmyengineer", "max_stars_repo_head_hexsha": "3b2a289bc91ce5013b02149681a118d511e7610a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-27T03:38:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-16T22:52:39.000Z", "max_issues_repo_path": "docs/adiabatic_cylinder_model.tex", "max_issues_repo_name": "Thaddeus-Maximus/swissarmyengineer", "max_issues_repo_head_hexsha": "3b2a289bc91ce5013b02149681a118d511e7610a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 50, "max_issues_repo_issues_event_min_datetime": "2020-03-22T15:43:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-10T01:40:08.000Z", "max_forks_repo_path": "docs/adiabatic_cylinder_model.tex", "max_forks_repo_name": "Thaddeus-Maximus/swissarmyengineer", "max_forks_repo_head_hexsha": "3b2a289bc91ce5013b02149681a118d511e7610a", "max_forks_repo_licenses": ["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.275, "max_line_length": 467, "alphanum_fraction": 0.6708704791, "num_tokens": 4872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6059822947399959}}
{"text": "%! Author = tstreule\n\n\\section{SPECT \\textnormal{-- Single Photon Emission CT}}\n\n$\\textrm{SNR} \\propto \\sqrt{\\textrm{total \\#detected gamma-rays}}$\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Radioactivity in the body}\n%\n\\highlight{$Q = -\\frac{dN}{dt} = \\lambda \\cdot N \\implies N(t) = N_0 \\eu^{-\\lambda t}$}\\\\\n$[Q] = \\unit{Curie} = \\unit{Ci} = 3.7 \\cdot 10^{10} \\unit{Bq}$\n\\quad where \\quad $1\\unit{Bq} = 1\\unitfrac{disintegration}{s}$\n\n\\textbf{Physical} $t\\ped{1/2} = \\frac{\\ln 2}{\\lambda}$, \\quad \\textbf{biological} $t\\ped{1/2 bio} = \\frac{\\ln 2}{\\lambda\\ped{bio}}$\n\n$N(t) = N_0 \\eu^{-(\\lambda + \\lambda\\ped{bio}) t} = N_0\\eu^{-\\lambda\\ped{1/2 eff}t}$\n\\quad where \\quad $t\\ped{1/2 eff} = \\frac{t\\ped{1/2} \\cdot t\\ped{1/2 bio}}{t\\ped{1/2} + t\\ped{1/2 bio}}$\n\n\\textbf{$\\gamma$ photons: Absorption} or \\textbf{Scattering}: Change of direction by $\\theta$. \\highlight{$E_{\\gamma}' = \\frac{m_e \\cdot c^2}{m_e c^2 / E_\\gamma + 1 - \\cos \\theta}$}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Interaction of $\\gamma$ photons with matter}\n%\n\\textbf{Absorption} leads to ejection of orbital electron\\\\\n\\textbf{Scattering}: Change of direction by $\\theta$. \\highlight{$\\displaystyle E_{\\gamma}' = \\frac{m_e \\cdot c^2}{m_e c^2 / E_\\gamma + 1 - \\cos \\theta}$}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Anger Camera}\n\\textbf{Collimation} necessary $\\implies$ losses of 99.9\\%\n\n\\includegraphics[width = \\linewidth]{SPECT_NuclearCollimator}\nBad isolation of \\textbf{septa} (lamellae) $\\implies L\\ped{eff} = L - \\frac{2}{\\mu\\ped{septa}}$\\\\\n%\n\\highlight{$\\displaystyle R_0(x) = \\frac{2 r_{col}}{L_{\\text{eff}}}(x + \\frac{L_{\\text{eff}}}{2})$} \\; \\highlight{$\\displaystyle \\textrm{FWHM} = \\Delta r_{col}(x) = \\frac{2 r_{col}}{L_{\\text{eff}}}(x + L_{\\text{eff}})$}\\\\\n\n\\textbf{Signal Path}: $\\gamma$-rays @140keV $\\to$ Scintillation crystal $\\to$ PMT $\\to$ (Pos. network || pulse height analyzer) $\\to$ digitizer\n\\begin{itemize}\n    \\item Scintillation crystal efficiency: \\highlight{$\\displaystyle \\epsilon = 1 - \\eu^{-\\mu d}$}. $\\mu$: attenuation coefficient of crystal, $d$: its thickness\n\n    \\item Usually many PMTs per crystal. Positioning network calculates where the event in the crystal was.\n\n    \\item $U_{PMT} \\propto \\gamma$ energy. Scattering $\\implies$ $E\\ped{scattered photons}\\downarrow$. Pulse height analyzer has energy window $\\Delta E$ around $E_0$.\n\n    \\item Poisson distributed $P_n(N)\\vert \\sigma^2 = \\mu \\implies \\highlight{SNR = \\sqrt{\\mu}}$\n\n    \\item \\textbf{Spatial resolution}: $R_{system}^2 = R\\ped{gamma}^2 + R_{coll}^2$ \\quad $R\\ped{gamma}$ = uncertainty of positioning network. $R\\ped{coll}$ see above.\n\\end{itemize}\n\n\\textbf{CT Version}: Res.: best at edge, worst in center. $\\approx$ 7mm\\\\\n\nFor small objects: Use \\textbf{pinhole} (cone-shaped, tungsten) camera: Problem: more dose needed, ``transparency'' around hole\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Generation of Technetium}\nNo cyclotron needed, only generator: Essentially \\ce{^{99}_{42}Mo} ($\\unit[67]{h} \\;\\widehat{=}\\; \\unit[2.9\\E{-6}]{s^{-1}}$) decays into \\ce{^{99}_{43}Tc} ($\\unit[6]{h} \\;\\widehat{=}\\; \\unit[3.1\\E{-5}]{s^{-1}}$)\n\n\\textbf{Kinetic equations}:\\\\\n$\\deriv{~}{t}N_{Mo} = -k_{Mo}N_{Mo}$ and $\\deriv{~}{t}N_{Tc} = k_{Mo}N_{Mo} - k_{Tc} N_{Tc}$\\\\\n\\highlight{$\\displaystyle \\implies N_{Tc}(t) = N_{Mo}(0) \\frac{k_{Mo}}{k_{Tc} - k_{Mo}} (e^{-k_{Mo}t} - e^{-k_{Tc} t})$} {\\scriptsize exp. decay}\n", "meta": {"hexsha": "d2c8d1493944b5c01f41c1a6856769ff9a269cab", "size": 3485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/BMI18/sections/05_spect.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/05_spect.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/05_spect.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": 62.2321428571, "max_line_length": 221, "alphanum_fraction": 0.6146341463, "num_tokens": 1249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6058994268636306}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{margtfr}\n\\section*{\\hspace*{-1.6cm} margtfr}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nMarginals and energy of a time-frequency representation.\n\\end{minipage}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[margt,margf,E] = margtfr(tfr)\n[margt,margf,E] = margtfr(tfr,t)\n[margt,margf,E] = margtfr(tfr,t,f)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty margtfr} calculates the time and frequency marginals and the\n        energy of a time-frequency representation. The definitions used for\n        the computation are the following\\,:\n\\begin{eqnarray*}\nm_f(t)=\\int_{-\\infty}^{+\\infty} \\mbox{tfr}(t,f)\\ df && \\mbox{\\it time\nmarginal}\\\\ \nm_t(f)=\\int_{-\\infty}^{+\\infty} \\mbox{tfr}(t,f)\\ dt && \\mbox{\\it frequency\nmarginal}\\\\\nE= \\int_{-\\infty}^{+\\infty}\\int_{-\\infty}^{+\\infty} \\mbox{tfr}(t,f)\\ df\\ dt && \\mbox{\\it energy}\n\\end{eqnarray*}\n \n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty tfr} & time-frequency representation {\\ty (M,N)}\\\\\n        {\\ty t}   & vector containing the time samples in sec. \n               & {\\ty (1:N)}\\\\\n        {\\ty f}   & vector containing the frequency samples in Hz, not\n               necessary uniformly sampled & {\\ty (1:M)}\\\\\n \\hline {\\ty margt} & time marginal\\\\\n        {\\ty margf} & frequency marginal\\\\\n        {\\ty E}     & energy of {\\ty tfr}\\\\\n\n\\hline\n\\end{tabular*}\n\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Example}\n\\vspace*{-.1cm}\n\\begin{verbatim}\n         S=amgauss(128).*fmlin(128); \n         [tfr,t,f]=tfrscalo(S,1:128,8,.05,.45,128,1);\n         [margt,margf,E] = margtfr(tfr); \n         subplot(211); plot(t,margt); \n         subplot(212); plot(f,margf);\n\\end{verbatim}\n\\vspace*{.3cm}\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\nmomttfr, momftfr.\n\\end{verbatim}\n\\end{minipage}\n\n", "meta": {"hexsha": "c6c374447772f82376ba0c0d382b04290aefaacc", "size": 2269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/margtfr.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/margtfr.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/margtfr.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 27.0119047619, "max_line_length": 96, "alphanum_fraction": 0.6231820185, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6058547015980166}}
{"text": "\\chapter[Additional Derivations and Formulae]{Additional Derivations and \\\\ Formulae}\n\\label{app:derivations}\n\\stoptocwriting\nThis appendix outlines further derivations and formulae used throughout this thesis.\n\n\\section{Ellipse Geometry}\n\\label{app:derivellipse}\n\nSection \\ref{s:trphysprop} considers the change in area when distorting a unit circle to an ellipse with the same circumference.\nAn ellipse can be defined in terms of the major and minor axis radii, denoted $a$ and $b$ respectively.\nThe distortion can then be described by the eccentricity, $\\xi$, given by:\n\\begin{equation}\n\t\\xi = \\left(1-\\frac{b^2}{a^2}\\right)^{1/2}.\n\\end{equation}\nThe circumference of an ellipse of given eccentricity, $C\\left(\\xi\\right)$, can then be calculated from the complete elliptic integral of the second kind,\n\\begin{equation}\n\t\\label{eq:ellipsec}\n\tC\\left(\\xi\\right) = 4a\\int_0^{\\pi/2} \\left(1-\\xi^2\\sin^2\\theta\\right)^{1/2}\\dd\\theta,\n\\end{equation}\nwhilst the area is given more straightforwardly by\n\\begin{equation}\n\tA = \\pi ab.\n\\end{equation}\nThe relative area between an ellipse and a unit circle for a given eccentricity is then\n\\begin{equation}\n \tA/A^0=ab,\n\\end{equation} \nwhere $a$,$b$ satisfy $C\\left(\\xi\\right)=2\\pi$.\n\n\\section{Aboav\\--Weaire with aG}\n\\label{app:derivag}\n\nSection \\ref{s:toptmapconfigspace} considers the meaning of the \\aw{} parameter for aG systems \\ie{} those containing just 5\\--, 6\\-- and 7\\--rings.\nFor these relatively constrained systems, $\\alpha$ can be related specifically to the proportions of specific ring adjacencies.\nTo derive this relationship, results are used from sections \\ref{s:theorynodeprob} and \\ref{s:toptmapconfigspace}.\n\nThe aG system has the node joint degree distribution\n\\begin{align}\n\t\\mathbf{e} &= \\begin{blockarray}{*{3}{c} l}\n\t\\begin{block}{*{3}{>{$\\footnotesize}c<{$}} l}\n\t5 & 6 & 7 \\\\\n\t\\end{block}\n\t\\begin{block}{[*{3}{c}]>{$\\footnotesize}l<{$}}\n\te_{55} & e_{56} & e_{57} \\: \\bigstrut[t]& 5\\\\\n\te_{65} & e_{66} & e_{67} & 6 \\\\\n\te_{75} & e_{76} & e_{77} & 7\\\\\n\t\\end{block}\n\t\\end{blockarray} .\n\\end{align}\nTaking the \\aw{} law, equation \\eqref{eq:aboavweaire}, and noting that $m_5=\\sumk ke_{5k}/q_5$, leads to the relationship\n\\begin{equation}\n\t\\frac{5}{q_5}\\left(5e_{55}+6e_{56}+7e_{57}\\right) = \\ki^2+\\mu_2+\\ki\\left(1-\\alpha\\right)\\left(5-\\ki\\right),\n\\end{equation}\nto which several simplifications can be made.\nThese arise from the constraints $\\ki=6$ and $\\sumk e_{5k}=q_5$, which on substitution and rearrangement yield:\n\\begin{align}\n\t\\frac{5}{q_5}\\left(5e_{55}+6\\left(q_5-e_{55}-e_{57}\\right)+7e_{57}\\right) &= 36+\\mu_2-6\\left(1-\\alpha\\right) \\nonumber \\\\\n\t\\frac{5}{q_5}\\left(e_{57}-e_{55}\\right)&=\\mu_2+6\\alpha.\n\\end{align}\nThis can be further simplified by applying the relationships $q_5=5p_5/6$, $p_5=\\left(1-p_6\\right)/2$, $\\mu_2=1-p_6$ and introducing the parameter $\\chi_{75}^{5}=e_{57}-e_{55}$, to obtain:\n\\begin{equation}\n\t\\alpha=\\frac{12\\chi_{75}^5-\\left(1-p_6\\right)^2}{6\\left(1-p_6\\right)}.\n\\end{equation}\nThis final relationship is the same as equation \\eqref{eq:agalpha}, which expresses the \\aw{} parameter in terms of the difference between the 5\\--7 and 5\\--5 ring adjacencies.\n\n\\clearpage\n\\section{Relating Aboav\\--Weaire to Assortativity}\n\\label{app:derivalphaassort}\n\nSection \\ref{s:assortativity} provides a relationship between the assortativity  and the \\aw{} parameter, the derivation for which is detailed here.\nThe assortativity is defined\n\\begin{equation}\n\tr = \\frac{\\sumjk jk\\left(e_{jk}-q_jq_k\\right)}{\\sumk k^2q_k - \\left(\\sumk kq_k\\right)^2}\\,,\n\\end{equation}\nwhich can be rewritten by noting that $q_k=kp_k/\\ki$, in the form\n\\begin{equation}\n\t\\label{appeq:assort}\n\tr = \\frac{\\ki^2\\sumjk jke_{jk}-\\kii^2}{\\ki\\kiii-\\kii^2}\\,.\n\\end{equation}\nThe mean node degree about a node of degree $j$ is given by $m_j=\\frac{1}{q_j}\\sumk e_{jk}$, which leads to the relationship\n\\begin{equation}\n\t\\sumjk jk e_{jk} = \\sumj jq_jm_j = \\frac{1}{\\ki}\\sumj jp_j jm_j\\,,\n\\end{equation}\nthat contains within it the left hand component of the \\aw{} law, equation \\eqref{eq:aboavweaire}.\nSubstituting and simplifying gives:\n\\begin{align}\n\t\\sumjk jk e_{jk} &= \\frac{1}{\\ki}\\sumj jp_j\\left[\\ki^2+\\mu_2+\\ki\\left(1-\\alpha\\right)\\left(j-\\ki\\right)\\right] \\\\\n\t&= \\frac{1}{\\ki}\\left[ \\ki\\left(1-\\alpha\\right)\\sumj j^2p_j + \\left(\\alpha\\ki^2+\\mu_2\\right)\\sumj jp_j\\right] \\nonumber \\\\\n\t&= \\kii\\left(1-\\alpha\\right)+\\alpha\\ki^2+\\mu_2 \\nonumber \\\\\n\t&=-\\alpha\\mu_2+\\mu_2+\\kii\\,.\n\\end{align}\nThis allows equation \\eqref{appeq:assort} to be written\n\\begin{align}\n\tr &= \\frac{-\\alpha\\mu_2+\\mu_2\\ki^2+\\kii\\ki^2-\\kii^2}{\\ki\\kiii-\\kii^2} \\\\[0.5em]\n\tr &= \\frac{-\\alpha\\mu_2-\\mu_2^2\\ki^2}{\\ki\\kiii-\\kii^2} \\nonumber \\\\[0.5em]\n\t\\alpha &= -\\frac{r\\left(\\ki\\kiii-\\kii^2\\right)}{\\mu_2\\ki^2}-\\frac{\\mu_2}{\\ki^2}\\,,\n\\end{align}\nwhich is the final form given in equation \\eqref{eq:rawlink}.\n\n\\clearpage\n\\section{Assortativity of Crystalline Lattices}\n\\label{app:crystals}\n\nCrystalline systems can provide a useful comparison point to contrast with random networks, as is demonstrated for procrystalline lattices in chapter \\ref{ch:procrystals}.\nFigure \\ref{appfig:crystals} shows two series of crystalline motifs taken from Altman \\etal{} \\cite{Malashevich2016}, and their corresponding assortativities.\n\nAn example calculation for these crystals is included for the $8 - 6^1 - 5^2$ lattice, figure \\ref{appfig:86152}.\nThe edge joint degree distribution is given by:\n\\begin{align}\n\t\\mathbf{e} &= \\frac{1}{24}\\, \\begin{blockarray}{*{3}{c} l}\n\t\\begin{block}{*{3}{>{$\\footnotesize}c<{$}} l}\n\t5 & 6 & 8 \\\\\n\t\\end{block}\n\t\\begin{block}{[*{3}{c}]>{$\\footnotesize}l<{$}}\n\t2 & 4 & 4 \\: \\bigstrut[t]& 5\\\\\n\t2 & 2 & 2 & 6 \\\\\n\t4 & 2 & 2 & 8\\\\\n\t\\end{block}\n\t\\end{blockarray}.\n\\end{align}\nThe rows are deduced using two considerations.\nFirstly, the relative ring adjacencies for each ring size are accounted for \\eg{} each 8\\--ring has $4\\times5$\\--ring neighbours, $2\\times6$\\--ring neighbours and $2\\times8$\\--ring neighbours.\nSecondly, the relative ring proportions are factored in to the row sums \\ie{} $p_5=2p_6=2p_8$.\nOnce this matrix has been constructed, the assortativity can be calculated using equation \\eqref{appeq:assort}.\n\n\\begin{figure}[h!]\n     \\centering\n     \n\t\\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_60_52.pdf}\n         \\caption{$8 - 6^0 - 5^2$, \\\\$r=-0.350$}\n         \\label{appfig:86052}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_61_52.pdf}\n         \\caption{$8 - 6^1 - 5^2$, \\\\$r=-0.185$}\n         \\label{appfig:86152}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_62_52.pdf}\n         \\caption{$8 - 6^2 - 5^2$, \\\\$r=-0.373$}\n         \\label{appfig:86252}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_63_52.pdf}\n         \\caption{$8 - 6^3 - 5^2$, \\\\$r=-0.220$}\n         \\label{appfig:86352}\n     \\end{subfigure}\n     \\hfill     \n     \n     \\vspace{2mm}\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_60_4.pdf}\n         \\caption{$8 - 6^0 - 4$, \\\\$r=-0.500$}\n         \\label{appfig:8604}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_61_4.pdf}\n         \\caption{$8 - 6^1 - 4$, \\\\$r=-0.260$}\n         \\label{appfig:8614}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_62_4.pdf}\n         \\caption{$8 - 6^2 - 4$, \\\\$r=-0.412$}\n         \\label{appfig:8624}\n     \\end{subfigure}\n     \\hfill\n      \\begin{subfigure}[b]{0.15\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{./appendices/figures/crystal_8_63_4.pdf}\n         \\caption{$8 - 6^3 - 4$, \\\\$r=-0.395$}\n         \\label{appfig:8634}\n     \\end{subfigure}\n     \\hfill\n     \n\t\n     \\caption{Repeating units from two series of crystalline motifs and their assortativities.\n      Panels (a)\\--(d) show the series $8-6^i-5^2$ with half the number of 8\\-- as 5\\--rings, interspersed with varying numbers of 6\\--rings. Panels (e)\\--(h) show the series $8-6^i-4$ with equal numbers of 8\\-- and 4\\--rings, interspersed with varying numbers of 6\\--rings.}\n     \\label{appfig:crystals}\n\\end{figure}\n\n\\resumetocwriting", "meta": {"hexsha": "a4c1a34c1d8dbf5e6ff2db198f110ecf315aad4f", "size": 8742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendices/derivations.tex", "max_stars_repo_name": "dormrod/Thesis", "max_stars_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-14T11:17:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-14T11:17:18.000Z", "max_issues_repo_path": "appendices/derivations.tex", "max_issues_repo_name": "dormrod/Thesis", "max_issues_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_issues_repo_licenses": ["MIT"], "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/derivations.tex", "max_forks_repo_name": "dormrod/Thesis", "max_forks_repo_head_hexsha": "77ddd9fcb3b563a5dc93457682724046053e1137", "max_forks_repo_licenses": ["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.0618556701, "max_line_length": 275, "alphanum_fraction": 0.6749027682, "num_tokens": 3121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6058547006637123}}
{"text": "\\subsubsection{TypicalHistoryFromHistorySet}\n\\label{TypicalHistoryFromHistorySet}\n\nThis Post-Processor performs a simplified procedure of \\cite{wilcox2008users} to form a ``typical'' time series from multiple time series. The input should be a HistorySet, with each history in the HistorySet synchronized. For HistorySet that is not synchronized, use Post-Processor method \\textbf{HistorySetSync}  to synchronize the data before running this method.\n\nEach history in input HistorySet is first converted to multiple histories each has maximum time specified in \\xmlNode{outputLen} (see below). Each converted history $H_i$ is divided into a set of subsequences $\\{H_i^j\\}$, and the division is guided by the \\xmlNode{subseqLen} node specified in the input XML. The value of \\xmlNode{subseqLen} should be a list of positive numbers that specify the length of each subsequence. If the number of subsequence for each history is more than the number of values given in \\xmlNode{subseqLen}, the values in \\xmlNode{subseqLen} would be reused.\n\nFor each variable $x$, the method first computes the empirical CDF (cumulative density function) by using all the data values of $x$ in the HistorySet. This CDF is termed as long-term CDF for $x$. Then for each subsequence $H_i^j$, the method computes the empirical CDF by using all the data values of $x$ in $H_i^j$. This CDF is termed as subsequential CDF. For the first interval window (i.e., $j=1$), the method computes the Finkelstein-Schafer (FS) statistics \\cite{finkelstein1971improved} between the long term CDF and the subsequential CDF of $H_i^1$ for each $i$. The FS statistics is defined as following.\n\\begin{align*}\nFS & = \\sum_x FS_x\\\\\nFS_x &= \\frac{1}{N}\\sum_{n=1}^N\\delta_n\n\\end{align*}\nwhere $N$ is the number of value reading in the empirical CDF and $\\delta_n$ is the absolute difference between the long term CDF and the subsequential CDF at value $x_n$. The subsequence $H_i^1$ with minimal FS statistics will be selected as the typical subsequence for the interval window $j=1$. Such process repeats for $j=2,3,\\dots$ until all subsequences have been processed. Then all the typical subsequences will be concatenated to form a complete history.\n\n\\ppType{TypicalHistoryFromHistorySet}{TypicalHistoryFromHistorySet}\n\nIn the \\xmlNode{PostProcessor} input block, the following XML sub-nodes are required,\nindependent of the \\xmlAttr{subType} specified:\n\n\\begin{itemize}\n   \\item \\xmlNode{pivotParameter}, \\xmlDesc{string, optional field}, ID of the temporal variable\n   \\default{Time}\n   \\item \\xmlNode{subseqLen}, \\xmlDesc{integers, required field}, length of the divided subsequence (see above)\n   \\item \\xmlNode{outputLen}, \\xmlDesc{integer, optional field}, maximum value of the temporal variable for the generated typical history\n   \\default{Maximum value of the variable with name of \\xmlNode{pivotParameter}}\n\\end{itemize}\n\nFor example, consider history of data collected over three years in one-second increments,\nwhere the user wants a single \\emph{typical year} extracted from the data.\nThe user wants this data constructed by combining twelve equal \\emph{typical month}\nsegments.  In this case, the parameter \\xmlNode{outputLen} should be \\texttt{31536000} (the number of seconds\nin a year), while the parameter \\xmlNode{subseqLen} should be \\texttt{2592000} (the number of seconds in a\nmonth).  Using a value for \\xmlNode{subseqLen} that is either much, much smaller than \\xmlNode{outputLen} or\nof equal size to \\xmlNode{outputLen} might have unexpected results.  In general, we recommend using a\n\\xmlNode{subseqLen} that is roughly an order of magnitude smaller than \\xmlNode{outputLen}.\n", "meta": {"hexsha": "f9de08f658f0a14b2bed04901fa7153ad967b7db", "size": 3657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/PostProcessors/TypicalHistoryFromHistorySet.tex", "max_stars_repo_name": "archmagethanos/raven", "max_stars_repo_head_hexsha": "d727cc3da3dff5254b418fb3691a2e45deb20136", "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/user_manual/PostProcessors/TypicalHistoryFromHistorySet.tex", "max_issues_repo_name": "archmagethanos/raven", "max_issues_repo_head_hexsha": "d727cc3da3dff5254b418fb3691a2e45deb20136", "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/user_manual/PostProcessors/TypicalHistoryFromHistorySet.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": 101.5833333333, "max_line_length": 614, "alphanum_fraction": 0.786163522, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6058455314619704}}
{"text": "\\subsubsection*{Unary Operations\\hspace*{\\fill}\\hyperlink{ElementwiseOperations}{(up)}\\hypertarget{unaryOperations}{}}\\addcontentsline{toc}{subsubsection}{Unary Operations}\nUnary operations involve calculations on a single \\ttbf{view}. Functions which involve a calculation where the answer is a scalar, such as \\ttbf{sumval} generally have a \\ttbf{val} as part of the root name. \n\\begin{table}[H]\n\\caption{Unary Operations}\n\\label{tab:unaryOperations}\n\\begin{center}\n\\begin{tabular}{|l|l|}\\hline\n\\hlnkFunc{arg} & Argument\\\\\n\\hlnkFunc{ceil} & Ceiling\\\\\n\\hlnkFunc{conj} & Conjugate\\\\\n\\hlnkFunc{cumsum} & Cumulative Sum\\\\\n\\hlnkFunc{euler} & Euler\\\\\n\\hlnkFunc{floor} & Floor\\\\\n\\hlnkFunc{mag} & Magnitude\\\\\n\\hlnkFunc{cmagsq} & Complex Magnitude Squared\\\\\n\\hlnkFunc{meanval} & Mean Value\\\\\n\\hlnkFunc{meansqval} & Mean Square Value\\\\\n\\hlnkFunc{modulate} & Modulate\\\\\n\\hlnkFunc{neg} & Negate\\\\\n\\hlnkFunc{recip} & Reciprocal\\\\\n\\hlnkFunc{round} & Round\\\\\n\\hlnkFunc{rsqrt} & reciprocal Square Root\\\\\n\\hlnkFunc{sq} & Square\\\\\n\\hlnkFunc{sumval} & Sum Value\\\\\n\\hlnkFunc{sumsqval} & Sum of Squares Value\\\\\n\\hline\\end{tabular}\n\\end{center}\n%\\label{default}\n\\end{table}%\n", "meta": {"hexsha": "4dd94b6eafa0c30d8ff4ef74896ec8c7d26071fe", "size": 1155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/jvsip_book/UnaryOperations.tex", "max_stars_repo_name": "rrjudd/jvsip", "max_stars_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-01-16T04:10:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T02:17:44.000Z", "max_issues_repo_path": "doc/jvsip_book/UnaryOperations.tex", "max_issues_repo_name": "rrjudd/jvsip", "max_issues_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-11T04:48:03.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-11T13:44:29.000Z", "max_forks_repo_path": "doc/jvsip_book/UnaryOperations.tex", "max_forks_repo_name": "rrjudd/jvsip", "max_forks_repo_head_hexsha": "56a965fff595b027139ff151d27d434f2480b9e8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-06-13T21:48:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-26T15:07:44.000Z", "avg_line_length": 38.5, "max_line_length": 207, "alphanum_fraction": 0.7411255411, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6058455306753908}}
{"text": "% Project Specifications\n\n\\chapter{Quantization}\n\n%In such networks a large part of the computation is done with an\n%operation called the \\gls{gemm}. An efficient implementation of \\gls{gemm} is crucial to the\n%acceleration. However, \\glspl{cnn} are normally implemented with floating-point numbers, which are usually less\n%efficient to handle in hardware than fixed-point numbers. A class of techniques called quantization can\n%be used to carry out the computation in fixed-point numbers and then convert the result back to\n%floating-point numbers, realizing high performance in hardware. Chapter 4 provides a detailed discussion\n%of the quantization scheme used in this project.\n\nMachine learning programs normally represent numbers as floating-point. Although floating-point numbers\nhave limited precision and can sometimes lead to numerical instability when the numbers involved get too\nsmall or too large, they are intuitive and easy to work with. But floating-point arithmetic can be rather\nexpensive to implement in hardware. Modern \\glspl{fpga} contain dedicated \\gls{dsp} units, some of which\nnatively\nsupport floating-point, others require special \\gls{ip} cores to implement the relevant\ncircuitry. \\gls{fpga}'s processing power mainly shines on fixed-point. In order to run our model in fixed-point\non \\gls{fpga}, it is necessary to convert the model into fixed-point representation, through a process known as\nquantization. When the result is computed by \\gls{fpga}, it is then converted back to floating-point, which is\nnaturally called dequantization.\n\nQuantization brings additional benefits with the compression of model size. When 32-bit floating-point\nweights are quantized to 8-bit, the model size can be reduced up to $75\\%$. This cuts down memory bandwidth\nrequirement and improves memory efficiency. Consequently, the power consumption can be greatly reduced.\n\nOne could imagine that quantization would cause a tremendous loss to the precision of a model, for example, when\n32-bit floating-point numbers \nare converted to\n8-bit unsigned integers, the range drops from $(1.175494351 \\times 10^{-38}, 3.402823466 \\times 10^{38})$ to $(0, 255)$. However, one of the peculiar\nproperties of neural networks is that they are very resilient to noise. Of course this is also one of the\nreasons why they are so successful in real world applications. We could view the internal precision loss of\nquantization as a form of internal noise. It turned out that the precision loss incurred is rather small\n\\cite{vincent2011}.\n\nThere exist several different quantization methods. This project adopted the quantization scheme\nimplemented in Google's \\textit{gemmlowp} library \\cite{github:gemmlowp}\nas well as described in \\cite{DBLP:journals/corr/abs-1712-05877}. \\textit{gemmlowp} is\na low precision \\gls{gemm} implementation for fixed-point numbers.\nThe original 32-bit single-precision weights represented in \\mintinline{c}{float} are mapped to \n\\mintinline{c}{uint8_t}. \\gls{gemm} is then\ncarried out on the \\gls{fpga} board with these 8-bit integers. Intermediate \\gls{mac} results are 32-bit\nintegers to accommodate the accumulation. Eventually the final output of the model is converted back to\n\\mintinline{c}{float}.\n\nThe quantization works by first identifying the range of the data. In neural networks, the values are usually\ndistributed within a relatively small range. For instance, for 8-bit quantization, if the minimum value of the\nweights is $-10.0$ and maximum value is $20.0$, then $-10.0$ would be mapped to $0$ while $20.0$ would be mapped to $255$.\nHowever, there is an additional requirement that can bring great benefits to subsequent computations:\nthe real value $0$ should be exactly representable. As will be shown, this can be achieved with a small\nmodification to the mapping equation.\n\nTh quantization scheme can be derived with basic algebra. Define a real number $f$ as the result of an affine\nmapping $f = S q + B$, where $q$ is the corresponding quantized integer, $S \\in \\mathbb{R}$ is a constant\nscaling factor, and $B \\in \\mathbb{R}$ is a constant shift. Next, modify the mapping a bit so that the\nreal value $0$ is exactly representable:\n\n\\begin{equation} \\label{eq:dequantization}\n  f = S(q - Z),\n\\end{equation}\n\nwhere $Z \\in \\mathbb{N}$ is a constant shift applied to $q$. Since convolution and transposed convolution\nboth can involve zero-paddings, having an exact representation of $0$ avoids the accumulation of errors\n(essentially a form of bias). With this form of affine mapping, $0$ is trivially mapped to $q = Z$. $S$ and\n$Z$ are called the quantization parameters of this mapping. From equation \\ref{eq:dequantization},\nit is clear that the quantization mapping is done with\n\n\\begin{equation} \\label{eq:quantization}\n  q = \\frac{f}{S} + Z\n\\end{equation}\n\nLet $A \\in \\mathbb{R}^{m \\times k}$, $B \\in \\mathbb{R}^{k \\times n}$, $A B = C \\in \\mathbb{R}^{m \\times n}$,\nlet the corresponding quantization parameters for $A$, $B$ and $C$ be $S_A$ and $Z_A$, $S_B$ and $Z_B$,\n$S_C$ and $Z_C$. These parameters can be predetermined, since in most cases the ranges of numbers in these matrices\nare known. Let $p$, $q$, $r$ be the entries in the quantized version of $A$, $B$ and $C$. \n\nFor an entry $f_C$ in $C$, $f_C = \\sum_{i}^{} A_i B_i$, where $i$ is the index of entries in a particular\nrow in $A$ and corresponding column in $B$,\n\n\\begin{equation}\n\\begin{split}\n  f_C & = \\sum_{i} A_i B_i \\\\\n      & = \\sum_{i} S_A (p_i - Z_A) S_B (q_i - Z_A) \\\\\n      & = S_A S_B \\sum_{i} (p_i - Z_A) (q_i - Z_B)\n\\end{split}\n\\end{equation}\n\nClearly the term $\\sum_{i} (p_i - Z_A) (q_i - Z_B)$ is the computational core here, let it be\n$\\mathfrak{K}$. Then,\n\n\\begin{equation}\n\\begin{split}\n  r_C & = \\frac{f_C}{S_C} + Z_C \\\\\n      & = \\frac{S_A S_B}{S_C} \\mathfrak{K} + Z_C\n\\end{split}\n\\end{equation}\n\nTherefore, once $\\mathfrak{K}$ is computed, it can be simply multiplied by a constant multiplier\n$M = \\frac{S_A S_B}{S_C}$ and added the zero offset $Z_C$ to obtain the quantized value $r_C$. The\nmultiplication by $M$ can be implemented by multiplying $\\mathfrak{K}$ by a constant integer and right shifting the\nresult by a fixed number of bits. These can be predetermined as well. The computation of $\\mathfrak{K}$ might seem problematic at first glance:\nit contains a subtraction operation for each entry,\nwhich would bring extra overhead to the \\gls{gemm} computation. To solve this, expand the expression $\\mathfrak{K}$:\n\n\\begin{equation}\n\\begin{split}\n  \\mathfrak{K} & = \\sum_{i} (p_i - Z_A) (q_i - Z_B) \\\\\n               & = \\sum_{i} (p_i q_i - Z_B p_i - Z_A q_i + Z_A Z_B) \\\\\n               & = \\sum_{i} p_i q_i - \\sum_{i} Z_B p_i - \\sum_{i} Z_A q_i + \\sum_{i} Z_A Z_B \\\\\n               & = \\sum_{i} p_i q_i - Z_B \\sum_{i} p_i - Z_A \\sum_{i} q_i + k Z_A Z_B\n\\end{split}\n\\end{equation}\n\nNote that $\\sum_{i} 1$ is k, which is the number of columns of $A$ and the number of rows of $B$. Four terms are\nobtained here. The first term $\\sum_{i} p_i q_i$ is the main term. The second term, $- Z_B \\sum_{i} p_i$\nis the product of $- Z_B$ and the sum of the current row, which only needs to be calculated once and added\nto each result of the first term. The third term $- Z_A \\sum_{i} q_i$ and the fourth term $k Z_A Z_B$ are\nsimilar. The computation can be carried out by computing the first term as the core, and add the rest three\nterms one by one.\n\n\\section{Handling of Biases}\n\nBiases are added to the 32-bit accumulator result. Recall that $f_C = \\sum_{i} A_i B_i = S_A S_B \\mathfrak{K}$,\nit is clear that biases should be quantized with $S = S_A S_B$ and $Z = 0$. When zero offset is $0$, negative\nnumbers will remain negative, consequently the type of bias values should be signed 32-bit integers.\n\n\\clearpage %force the next chapter to start on a new page. Keep that as the last line of your chapter!\n", "meta": {"hexsha": "0784eb73a29e3e15ee96d478329132987d8cb737", "size": 7844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/quantization.tex", "max_stars_repo_name": "lambdalainen/metropolia-thesis-latex", "max_stars_repo_head_hexsha": "d7e705ad24f1f8065b2e7f026db5fdc90a7c8b3a", "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/quantization.tex", "max_issues_repo_name": "lambdalainen/metropolia-thesis-latex", "max_issues_repo_head_hexsha": "d7e705ad24f1f8065b2e7f026db5fdc90a7c8b3a", "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/quantization.tex", "max_forks_repo_name": "lambdalainen/metropolia-thesis-latex", "max_forks_repo_head_hexsha": "d7e705ad24f1f8065b2e7f026db5fdc90a7c8b3a", "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": 60.8062015504, "max_line_length": 149, "alphanum_fraction": 0.7432432432, "num_tokens": 2193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321843145405, "lm_q2_score": 0.752012568201972, "lm_q1q2_score": 0.6058455279525421}}
{"text": "\\graphicspath{ {./img/TheFEM/} }\r\n\\chapter{Interpolation in the Finite Element Method}\r\n\r\n\\section*{Preliminary}\r\nIn a broad sense the finite element method is nothing else than an \r\napproximation technique for solutions to boundary and initial value problems. \r\nIn this section we will discuss some fundamental and basic aspects related to \r\nthe approximation of functions through interpolation. In the finite element \r\nmethod, such approximation takes place for the geometry of the computational \r\ndomain and for the field variable of the problem at hand. As it will be seen, \r\nthe concept of finite element it self corresponds to a local domain or \r\nsub-domain in which the solution function is approximated via interpolation \r\ntechniques. We will cover this subject from a materialistic point of view, as \r\nrequired on the implementation of a first finite element algorithm, with \r\nmathematical rigor left to the excellent texts on the subject. The set of notes \r\nstarts with the problem definition and its solution in terms of the Lagrange \r\ninterpolation theorem. From that point the notes discuss practical applications \r\nincluding its implementation in Python scripts built for finite element \r\nanalysis. \r\n\r\nAt the end of this chapter\\footnote{This chapter, together with theoretical and \r\ncomputational learning activities is complemented by Jupyter Notebooks 1 \r\nthrough 4 available at the course's repository.} the student should be able to:\r\n\r\n\r\n\\begin{itemize}\r\n\\item[•] Formulate appropriate interpolation schemes to generate approximate functions out of sets of discrete values representing the behavior of the unknown functions over one-dimensional and two-dimensional domains.\r\n\\item[•] Recognize the differences in terms of advantages and limitations  between global and local interpolation schemes. This includes the pathologies associated with each method.\r\n\\item[•] Recognize the concept {\\bf finite element} like a family of locally defined interpolation schemes valid over canonical domains.\r\n\\item[•] Develop efficient and effective  Python implementations of interpolation schemes within the context of the finite element method for one-dimensional and two-dimensional applications.\r\n\\end{itemize}  \r\n\r\n\\section{Statement of the problem}\r\nLet $f(x)$ be an unknown function, whose values, however, 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]$ and different to one of the $n$ points.\r\n\r\nThe problem of interpolation is precisely that of finding the unknown value of $f(x)$ using the known values $\\left\\{ {{f^1},{f^2},...,{f^n}} \\right\\}$. As schematically described in \\cref{fig:interpol1} it involves two steps:\r\n\r\n\\begin{itemize}\r\n\\item[i]  Fitting an approximate function, known as the interpolating polynomial, to the known data points.\r\n\\item[ii] Evaluating the function at the point of interest where the function is unknown.\r\n\\end{itemize}\r\n\r\nWe can (i) follow a global approach using all the known $n$-data points and fit an $(n-1)$-th order polynomial to these data points\\footnote{As this approach is problem-dependent it is also cumbersome and difficult to code and therefore not amenable to be used in finite elements.}(\\cref{fig:interpol1})  or (ii) use a local approach where one splits the domain into sub-intervals and fits lower order polynomials to the data points within each sub-interval(\\cref{fig:interpol2}).\r\n\r\nLocal interpolation uses a finite number of nearest-neighbors and generates interpolated versions of $f(x)$ that do not in general have continuous first or higher derivatives. The advantage of this local approach lies in the fact that independent of the function or the number of data points, the interpolation operation always uses the same polynomial. For instance in \\cref{fig:interpol2} only first-order polynomials are being used in each local sub-domain: as a result a computer implementation of this scheme would only need to store the local polynomial once. In the jargon of the finite element method the interpolation functions or its resulting local polynomials are termed a finite element.\r\n\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=10cm]{img/interpol1.pdf}\r\n\\caption{The black points represent known values of an otherwise unknown function. The dashed line represents an approximation to the unknown function in terms of a polyonmial of order $n-1$.}\r\n\\label{fig:interpol1}\r\n\\end{figure}\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=10cm]{img/interpol2.pdf}\r\n\\caption{Interpolation takes place inside each sub-interval producing a piecewise interpolation approximation to the unknown function}\r\n\\label{fig:interpol2}\r\n\\end{figure}\r\n\r\n\\section{One-dimensional scalar functions}\r\n\\subsection{Lagrange interpolation theorem}\r\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;\r\n\r\n\\begin{equation}\\label{eq:inter_expl}\r\np(x) = {L^1}(x)f({x^1}) + {L^2}(x)f({x^2}) +  \\ldots  + {L^n}(x)f({x^n})\r\n\\end{equation}\r\n\r\nand the term ${L^I}(x)$ is computed as;\r\n\r\n\\begin{equation}\\label{eq:coef}\r\n  L^I(x) = \\prod_{\\substack{J = 1\\\\ I \\ne J}}^n \\frac{(x - x^J)}{(x^I - x^J)}.\r\n\\end{equation}\r\n\r\nThe approximate function $p(x)$ of order $n-1$ is termed {\\bf the interpolating polynomial} such\r\n\r\n\r\n\\[f(x)\\simeq p(x)\\]\r\n\r\n\r\nwhile each one of the terms ${L^I}(x)$, also of order $n-1$, are termed {\\bf the interpolation functions}. In the context of the finite element method these are also called {\\bf shape functions}.\r\n\r\nThe use of index notation, and particularly the summation convention, can be extended to represent the linear superposition of functions given by \\cref{eq:inter_expl}. We use capital super-scripts to denote interpolation in such a way that a capital superscript denotes a data point in the interpolation scheme. Accordingly \\cref{eq:inter_expl} can be equivalently written like:\r\n\r\n\r\n\\begin{equation}\\label{eq:pol}\r\n  p(x^I) = L^I(x) f(x^I)  \r\n\\end{equation}\r\n\r\nwhere the fact that $I=1,2,...,n$ is implicit in the notation.\r\n\r\nRecall that the interpolating polynomial $p(x)$ is just an approximation to the actual function $f(x)$. However, the approximation should at least be such that $p(x^I) = f(x^I)$ at the $n$ nodal points. To satisfy this condition the interpolation polynomials must be such that:\r\n\r\n\\[L^I(x^J) = \\delta^{IJ}\\]\r\n\r\nand where ${\\delta ^{IJ}}$ is the delta function extended to the interpolation polynomials.\r\n\r\n\\begin{tcolorbox}\r\nThe approximate function $p(x)$ resulting from the interpolation process is called the {\\bf interpolating polynomial} while the Lagrange polynomials $L^I(x)$ are called interpolation functions. In the language of the finite element methods these are simply called {\\bf shape functions}. \r\n\\end{tcolorbox}\r\n\r\n\r\n\\begin{tcolorbox}\r\n\\paragraph*{A note regarding superscripts in indicial notation:} In this Class Notes superscripts associated to symbols like in the expression $x^4$ are frequently used to describe a variable associated to a nodal point: for instance, in this context the expression $x^4$ represents the $x$-coordinate of nodal point $4$. However, in some other cases this same expression might appear, for example, in the definition of a function like in $f(x) = {x^4} + 4{x^3}$. In both cases the specific meaning should be clear by the context in which it appears.\r\n\r\nPython function {\\bf LagrangPoly()} in NB-1 generates Lagrange interpolation polynomials of different order and over a varying range.\r\n\\end{tcolorbox}\r\n\r\n\\paragraph*{Example: Interpolation of a function using 3 data points}\r\n\r\nUse a Lagrange interpolation scheme to find an interpolating polynomial that approximates the function \r\n\r\n\\[ f(x) = {x^3} + 4{x^2} - 10 \\]\r\n\r\nat the sampling (or also nodal) points ${x^1} =  - 1.0$, ${x^2} =  + 1.0$ and ${x^3} = 0.0$ over the interval $[-1,1]$ together with its first order derivative at $x = 0.7$.  Assume that the values of the first derivative at the nodal points are unknown. \r\n\r\n\\Cref{ejemplo2} contains the exact values for the function\r\n\r\n\\begin{center}\r\n\\begin{tabular}{ll}\r\n  \\hline\r\n  $x$ & $f(x)$ \\\\\r\n  \\hline \r\n  $-1.0$  & $-7.000$  \\\\\r\n  $ 0.00$  & $-10.00$  \\\\\r\n  $ 1.00$  & $-5.000$  \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\captionof{table}{Known values of the function $f(x) = {x^3} + 4{x^2} - 10$ over the interval $[-1,1]$}\r\n\\label{ejemplo2}\r\n\\end{center}\r\n\r\nThe formulation of the interpolation scheme consists in finding the interpolation polynomials $L^I(x)$ and the interpolating function $p(x)$. From \\cref{eq:coef} the interpolation functions, shown in \\cref{fig:pols}, are:\r\n\\begin{align*}\r\nL^1(x) = \\frac{(x - x^2)(x - x^3)}{(x^1 - x^2)(x^1-x^3)} & \\equiv  - \\frac{1}{2}(1 -  x)x\\\\\r\nL^2(x) = \\frac{(x - x^1)(x - x^3)}{(x^2 - x^1)(x^2 - x^3)} & \\equiv +   \\frac{1}{2}(1 + x)x\\\\\r\nL^3(x) = \\frac{(x - x^1)(x - x^2)}{(x^3 - x^1)(x^3 - x^2)} & \\equiv + (1 - x^2).\r\n\\end{align*}\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[width=10cm]{func1.pdf}\r\n  \\caption{(top) Interpolation polynomials $L^1(x)$, $L^2(x)$ and $L^3(x)$ as per \\cref{eq:coef} computed for a second order scheme with 3 nodal points.}\r\n  \\label{fig:pols}\r\n\\end{figure}\r\n\r\nThe interpolating polynomial approximating the function is obtained using \\cref{eq:pol} which in this case is given by\r\n\r\n\r\n\\[p(x) = 10{x^2} + \\frac{7}{2}(1 - x)x - \\frac{5}{2}(1 + x)x - 10.\\]\r\n\r\nThe approximate and actual function are compared in \\cref{fig:functions}. Clearly $p(x)$, being a second order function differs with $f(x)$, which is a third order function. However, as stated in the interpolation theorem both functions coincide at the nodal points where the known values of the function are available.\r\n\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[width=10cm]{func2.pdf}\r\n  \\caption{Resulting interpolating function $p(x)$ as per \\cref{eq:pol} compared with the exact function $f(x) = {x^3} + 4{x^2} - 10$. The Python code used for the interpolation is available in NB-1}\r\n  \\label{fig:functions}\r\n\\end{figure}\r\n\r\n\r\nIn finding an approximations to the first derivative recall that at the nodal points the values of these first derivatives are unknown. Thus the only available choice is to operate directly on $p(x)$ and use it to approximate also the first derivative like:\r\n\r\n\r\n\\begin{equation}\\label{eq:der}\r\n  \\frac{ dp(x)}{dx} = \\frac{dL^1(x)}{dx} f^1 + \\frac{dL^2(x)}{dx}(x) f^2 + \\frac{dL^3(x)}{dx} f^3\r\n\\end{equation}\r\n\r\nIt is evident that the approximation takes the form of a lineal superposition of products between interpolation functions (which in this case are derivatives of the $L^I$) and known values of the function. The first derivative obtained in this form differs from the actual derivative of $f(x)$ since this approach uses the values of $f$ and not those of $\\frac{{df(x)}}{{dx}}$ and $\\frac{dL^I(x)}{dx}$ instead of $L^I$ and these functions do not satisfy the condition $\\frac{dL^I(x^J)}{dx} = \\delta ^{IJ}$.\r\n\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[width=10cm]{deriv.pdf}\r\n  \\caption{Comparison between the first order derivative of $p(x)$ with the closed-form result of $\\frac{{df(x)}}{{dx}}$}\r\n  \\label{fig:deriv}\r\n\\end{figure}\r\n\r\n\r\n\\Cref{fig:first der 1} shows the approximation to $f'(x)$ when $p(x)$ is computed using 4th-order polynomials.\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[width=10cm]{firstder.pdf}\r\n  \\caption{Comparison between the first order derivative of $p(x)$ computed using 4th-order polynomials with the closed-form result of $\\frac{{df(x)}}{{dx}}$}\r\n  \\label{fig:first der 1}\r\n\\end{figure}\r\n\r\nTo identify the variation in the solution with different interpolation schemes \\cref{fig:several interpol} compares the exact and interpolated solution for polynomials of order 1, 2 and 4 respectively. The left column displays the interpolation polynomials ${{L^I}(x)}$.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{lineal.pdf}\r\n\t\t\\caption{First order. }\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{interlin.pdf}\r\n\t\t\\caption{Actual and interpolated function.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{quadra.pdf}\r\n\t\t\\caption{Second order.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{interqua.pdf}\r\n\t\t\\caption{Actual and interpolated function.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{third.pdf}\r\n\t\t\\caption{Fourth order.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{intertri.pdf}\r\n\t\t\\caption{Actual and interpolated function.}\r\n\t\\end{subfigure}\r\n\\caption{Interpolation of the function $f(x) = {x^3} + 4{x^2} - 10$ using Lagrange polynomials of increasing order.}\r\n\\label{fig:several interpol}\r\n\\end{figure}\r\n\r\n\\subsection{Local interpolation using a piece-wise continuous function}\r\nAn alternative to the non-uniform nodal distribution approach used in the previous section to improve the interpolation scheme is based on splitting the solution interval $[x_1, x_n]$ in smaller sub-domains where the interpolation is performed locally. For instance \\cref{subdo} shows such a partition for the interval $[-1.0, 1.0]$ where each sub-domain is conformed by a pair of consecutive nodes. The table shows values of the function $f(x) = {x^3} + 4{x^2} - 10$ at the edges of the sub-domains. In this particular case, considering each sub-domain to be conformed by a pair of points, the lineal interpolation scheme reduces to finding the straight line (first order polynomial) that passes along the pair of nodes. Higher order local schemes are possible if additional points are added to the sub-domains.\r\n\r\n\\begin{center}\r\n\\begin{tabular}{ccc}\r\n  \\hline\r\n  Subdomain & Range & Values for $f(x)$ \\\\\r\n  \\hline \r\n   1  & $[-1.0, -0.5]$ & $[-7.000, -9.125]$  \\\\\r\n   2  & $[-0.5,  0.00]$ & $[-9.125, -10.00]$  \\\\\r\n   3  & $[+0.0,  +0.5]$ & $[-10.00, -8.875]$   \\\\\r\n   4  & $[+0.5, +1.0]$ & $[-8.875, -5.000]$   \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\captionof{table}{Partition of the interval $[-1.0, 1.0]$ into subdomains}\r\n\\label{subdo}\r\n\\end{center}\r\n\r\n\\begin{tcolorbox}\r\n\r\nUsing piecewise interpolation over constant size intervals implies also the use of constant polynomials. In the finite element method each sub-domain is mapped into a constant size interval facilitating systematization of the interpolation process.\r\nNotebook 2 in the REPO shows the Python implementation of piecewise interpolation.\r\n\r\n\\end{tcolorbox}\r\n\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[width=10cm]{localone.pdf}\r\n  \\caption{Local interpolating polynomials.}\r\n  \\label{fig:loc-pols}\r\n\\end{figure}\r\n\r\nThis approach results in an interpolating polynomial as shown in \\cref{fig:fully local 1} and where the approximated function is piece-wise continuous. As a result the local based technique the first derivative of the function is now discontinuous at the boundaries of the subdomains. However this local schema is advantageous since the local polynomials are unique and the scheme can be used for an arbitrary number of nodal points facilitating computer implementation.\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{localfun.pdf}\r\n\t\t\\caption{Approximation to the function using first order interpolation polynomials.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{localfirst.pdf}\r\n\t\t\\caption{Variation of the first order derivative.}\r\n\t\\end{subfigure}\\\\\r\n\r\n\\caption{Locally based interpolation scheme for the function $f(x) = {x^3} + 4{x^2} - 10$.}\r\n\\label{fig:fully local 1}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\subsection{Distribution of the sampling (or nodal) points}\r\nThe simple problems considered so far have used a small number of sample points and a constant separation distance. This approach worked nicely considering the smooth functions involved. However if the function to be interpolated exhibits strong gradients, as might be the case in problems of wave propagation, the approximation with a small number of data points is very likely insufficient. The natural solution seems to be the addition of data points and thus an increase in the order of the interpolating polynomial. Unfortunately, as we will show here this approach does not always works in the desired direction.\r\n\r\n\r\nConsider the function:\r\n\r\n\\[f(x) = \\frac{1}{{1 + 25{x^2}}}\\]\r\n\r\nshown in \\cref{fig:rungelag}.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=8cm]{runge.pdf}\r\n\\caption{Runge function $f(x) = \\frac{1}{1 + 25{x^2}}$.}\r\n\\label{fig:rungelag}\r\n\\end{figure}\r\n\r\nThis function shows a strong spatial variation requiring an interpolating polynomial of larger order and as a result a larger number of nodal points. The 11 black dots shown in the figure represent nodal points equally spaced at $\\Delta x = 0.2$ and where the function is assumed to be known. We wish to approximate this function using these 11 points and an order 10 interpolating Lagrange polynomial.\r\n\r\n\r\n\r\n\\Cref{fig:rungeequi} shows the 11 order-10 Lagrange interpolation polynomials for the equidistant nodal distribution and the resulting interpolating polynomial $p(x)$. Clearly the approximation is highly inaccurate, specially near the edges of the interval where it exhibits strong oscillations. This spurious result along the edges is introduced by the equidistant separation of the sampling points. The interpolation scheme can be improved using a non-uniform nodal spacing. The resulting alternative scheme is shown in  \\cref{fig:rungechevy} where there is a large concentration of nodal points along the edges.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.50\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{lag11.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{rungaprlag.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\\\\r\n\r\n\\caption{(a) Lagrange interpolation polynomials of order 10 associated to the 11 sampling points for \\cref{fig:rungelag}. (b) Interpolating polynomial to approximate the Runge function with the order-10 polynomials from part (a).}\r\n\\label{fig:rungeequi}\r\n\\end{figure}\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.50\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{lagchv.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{rungaprchv.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\\\\r\n\r\n\\caption{(a) Order 10 Lagrange interpolation polynomials associated to non-equidistant sampling points. (b) Interpolating polynomial to approximate a Runge function built with the polynomials derived in part (a).}\r\n\\label{fig:rungechevy}\r\n\\end{figure}\r\n\r\nTo understand this numerical pathology, related with the distribution of the nodal points, consider the interpolation polynomials corresponding to the central point and to the edge point of the equidistant distribution (\\cref{fig:rungeequi}) as shown in part(a) of \\cref{fig:compara}. The green line corresponds to the polynomial associated to the central node, while the blue line is that of the edge nodal point. Clearly, the central-point polynomial introduces a strong variation along the edges of the sampling interval, while the edge-point polynomial exhibits a rather smooth variation. Similarly, part(b) in the same figure shows once again the central-point and the edge-point polynomials associated to non-uniform nodal distribution. It can be observed how in this last case both polynomials exhibit a smooth variation over the interval eliminating the strong oscillation towards the edges.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{central.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{extremo.pdf}\r\n\t\t\\caption{}\r\n\t\\end{subfigure}\\\\\r\n\r\n\\caption{(a) Equidistant nodal points (b) Non-uniform nodal points.}\r\n\\label{fig:compara}\r\n\\end{figure}\r\n\r\n\\section{Extension to two-dimensional domains}\r\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 $\\overrightarrow x = x \\hat{\\imath} + y\\hat{\\jmath}$. We want to know, via interpolation, the value of a function $f(\\overrightarrow x)$ at an arbitrary point $\\overrightarrow x$ provided we know the set of n-pairs of the form $\\{(\\overrightarrow x ^1, f^1),\\cdots,(\\overrightarrow x ^n, f^n)\\}$. The domain and the visualization of the function are shown in \\cref{fig:element}.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{element.pdf}\r\n\t\t\\caption{Square two-dimensional domain}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{surface.pdf}\r\n\t\t\\caption{Interpolated function $f(x,y)$.}\r\n\t\\end{subfigure}\\\\\r\n\r\n\\caption{Function $f(x,y)$ over a square two-dimensional domain with nodal points labeled 1 , 2 , 3 , 4.}\r\n\\label{fig:element}\r\n\\end{figure}\r\n\r\nSince now the function $f$ depends on the 2D space coordinates $(x , y)$ it is natural to expect that interpolation functions depend also on $(x , y)$. Using this condition on the function approximation we have:\r\n\r\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\\]\r\n\r\nwhere now $N^Q(x,y)$ is the 2D interpolation (or shape) function associated to the sampling point $Q$. Using indicial summation convention, we can write the interpolated function as:\r\n\r\n\\[f(x,y) = N^Q(x,y)f^Q\\]\r\n\r\nwhere now $Q = 1,...,N$.\r\n\r\n\r\nThe method to find the required 2D shape functions $N^Q(x,y)$ consists in the recursive (or iterated) application of the Lagrange one-dimensional scheme discussed previously in terms of interpolating polynomials $L^Q(\\eta)$ and where now $\\eta$ is a dummy variable that can assume the role of $x$ or $y$.\r\n\r\nIn the domain shown in  \\cref{fig:element} assume that we wish to interpolate the value of the function along the 1-4 direction. Note that along this line x is constant and then the function depends only on $y$. Fixing $x = x^A$ it is possible to conduct 1-dimensional interpolation along the $y$ direction as shown in \\cref{fig:onedimn}. In this case $\\eta$ assumes the role of $y$ and we have:\r\n\r\n\\[f(x^A,y) = L^1(y)f^1 + L^4(y)f^4.\\]\r\n\r\nSince the interpolation scheme is taking place along the 1-4 direction in terms of the 2 nodal values $f^1$ and $f^4$, the functions $L^1$ and $L^4$ in this case are the first order Lagrange polynomials associated to the points 1 and 4 respectively, and obtained with the already known product formula given in \\cref{eq:coef}.\r\n\r\n\r\n\r\nClearly, the above scheme provides the value of the function for an arbitrary point $A$ along the 1-4 line. Proceeding similarly along the 2-3 direction, that is setting $x = x^B$ and interpolating once again along the $y$ direction we have:\r\n\\[f(x^B,y) = L^2(y)f^2 + L^3(y)f^3.\\]\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=10cm]{inter1D.pdf}\r\n\\caption{Interpolation along the $y$-direction}\r\n\\label{fig:onedimn}\r\n\\end{figure}\r\n\r\n\r\n\r\nSo far, we have captured only the dependence on $y$ since $x$ was assumed constant as indicated by $f(x^A,y)$ and $f(x^B,y)$. The dependence on $x$ is now captured proceeding similarly along the arbitrary line $A-B$ using the functions $f(x^A,y)$ and $f(x^B,y)$ respectively as follows;\r\n\r\n\\[f(x,y) = L^A(x) f(x^A,y) + L^B(x)f(x^B,y)\\]\r\n\r\nwhich after substituting with the found expressions for $f(x^A,y)$ and $f(x^B,y)$ becomes\r\n\r\n\\begin{align*}\r\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\\}\\\\\r\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 .\r\n\\end{align*}\r\n\r\nNote that strictly speaking there are only 2 interpolation functions of the form $L^Q(\\eta)$ since one-dimensional interpolation is taking place. Thus the interpolating polynomials satisfy the following equivalences:\r\n\r\nwhere\r\n\\begin{align*}\r\nL^A(x) & \\equiv L^1(x)\\\\\r\nL^B(x) & \\equiv L^2(x)\\\\\r\nL^1(y) & \\equiv L^1(y)\\\\\r\nL^2(y) & \\equiv L^1(y)\\\\\r\nL^3(y) & \\equiv L^2(y)\\\\\r\nL^4(y) & \\equiv L^2(x) \\enspace .\r\n\\end{align*}\r\n\r\nThe resulting two-variable shape functions $N^Q(x,y)$ follow from the product of one-dimensional interpolation functions like:\r\n\r\n\\begin{align*}\r\nN^1(x,y) & = L^1(x)L^1(y)\\\\\r\nN^2(x,y) & = L^2(x)L^1(y)\\\\\r\nN^3(x,y) & = L^2(x)L^2(y)\\\\\r\nN^4(x,y) & = L^1(x)L^2(y) \\enspace .\r\n\\end{align*}\r\n\r\nIn the actual computer implementation of the discussed interpolation scheme it is desirable to have the actual functions embedded into the code instead of having the computer finding the corresponding Lagrange polynomials each time the size of the square domain changes. In practice, the functions $N^Q(x,y)$ are coded for a canonic square of general side $h$. This resulting canonic domain can be referred as a finite element.\r\n\r\n\\paragraph*{A 2D finite element}\r\nFrom the geometric point of view a {\\bf finite element} is a canonical interpolation domain together with a set of shape functions and its derivatives. \\Cref{fig:four-nodes-interp} shows the shape functions for a so-called bi-linear element of side $h = 1.0$. The element is called bi-linear as linear (or first order) interpolation is used along the $x$ and $y$ directions. Elements of higher order result after adding nodal points and the required corrections to the 2D-shape functions $N^Q(x,y)$.\r\n\r\n%The shape functions for a 9-noded element are displayed in \\cref{fig:nine-nodes-interp}.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-1.pdf}\r\n\t\t\\caption{Shape function ${N^1(x,y)=\\frac{1}{4}(1-x)(1-y)}$. }\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-2.pdf}\r\n\t\t\\caption{Shape function ${N^2(x,y)=\\frac{1}{4}(1+x)(1-y)}$.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-3.pdf}\r\n\t\t\\caption{Shape function ${N^3(x,y)=\\frac{1}{4}(1+x)(1+y)}$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{shape_func-4-nodes-4.pdf}\r\n\t\t\\caption{Shape function ${N^4(x,y)=\\frac{1}{4}(1-x)(1+y)}$.}\r\n\t\\end{subfigure}\r\n\\caption{Shape functions for a 4-nodes element.}\r\n\\label{fig:four-nodes-interp}\r\n\\end{figure}\r\n\r\n\\begin{tcolorbox}\r\n\r\nSee Notebooks 3 and 4 for an easy to follow Python implementation of interpolation resembling the finite element method.\r\n\r\n\\end{tcolorbox}\r\n\r\n\r\n\r\n%\\begin{figure}[H]\r\n%\\centering\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-1.pdf}\r\n%\t\t\\caption{Shape function $N^1(x,y)$. }\r\n%\t\\end{subfigure}\\,\r\n%%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-2.pdf}\r\n%\t\t\\caption{Shape function $N^2(x,y)$.}\r\n%\t\\end{subfigure}\\\\\r\n%%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-3.pdf}\r\n%\t\t\\caption{Shape function $N^3(x,y)$.}\r\n%\t\\end{subfigure}\\,\r\n%%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-4.pdf}\r\n%\t\t\\caption{Shape function $N^4(x,y)$.}\r\n%\t\\end{subfigure}\\\\\r\n%\t%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-5.pdf}\r\n%\t\t\\caption{Shape function $N^5(x,y)$.}\r\n%\t\\end{subfigure}\\,\r\n%%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-6.pdf}\r\n%\t\t\\caption{Shape function $N^6(x,y)$.}\r\n%\t\\end{subfigure}\r\n%\t\\caption{Shape functions for a 9-nodes element.}\r\n%\t\\label{fig:nine-nodes-interp}\r\n%\\end{figure}\r\n%%\r\n%\\begin{figure} [H]\r\n%\t\\ContinuedFloat\r\n%\t\\centering\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-7.pdf}\r\n%\t\t\\caption{Shape function $N^7(x,y)$.}\r\n%\t\\end{subfigure}\\,\r\n%%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-8.pdf}\r\n%\t\t\\caption{Shape function $N^8(x,y)$.}\r\n%\t\\end{subfigure}\\\\\r\n%\t%\r\n%\t\\begin{subfigure}[b]{0.45\\textwidth}\\qquad\r\n%\t\t\\includegraphics[width=\\textwidth]{shape_func-9-nodes-9.pdf}\r\n%\t\t\\caption{Shape function $N^9(x,y)$.}\r\n%\t\\end{subfigure}\r\n%\\caption{Shape functions for a 9-nodes element. (Continued)}\r\n%\\end{figure}\r\n\r\n\r\n\\begin{tcolorbox}\r\n\\paragraph*{Finite element mesh}\r\nSpatial-discretization of the computational domain is in the core of finite element analysis. This corresponds to the partition of the whole domain into {\\bf finite elements}. The complete set of finite elements, and its defining attributes, corresponding to a particular domain is termed a {\\bf mesh}. If the geometry is irregular the mesh would contain mostly distorted elements with respect to the canonical shape. In the finite element method this is nicely solved using space transformations between the distorted and the canonical shape.\r\n\r\n\\end{tcolorbox}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\r\n\\section{Interpolation over distorted domains}\r\nSo far all the 2D interpolation operations have taken place over perfectly squared domains of side $h$ where the interpolation functions are known at least in terms of the side parameter $h$. In many cases and particularly in finite element methods it is common to find distorted interpolation domains (see \\cref{fig:physical}) which difficult the interpolation operation as the interpolation polynomials would be element-dependent and the problem would become impossible to code in a systematic way.\r\n\r\n\r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=6cm]{rombo}\r\n\\caption{Distorted quadrilateral interpolation domain.}\r\n\\label{fig:physical}\r\n\\end{figure} \r\n\r\nIn these cases the solution approach is based upon the continuous mapping of the distorted domain and the functions defined in this space into a constant or canonical element where the interpolation functions are always the same. Moreover, the mapping between both spaces is conducted also using interpolation theory. This idea is explained next with reference to \\cref{fig:natural domain}.\r\n\r\n\r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=8cm]{figure1.pdf}\r\n\\caption{Schematic representation of the one-to-one mapping between points in the physical space (left) and the natural or canonical space (right).}\r\n\\label{fig:natural domain}\r\n\\end{figure} \r\n\r\nIn the figure the space of the distorted domain, and with position vectors $\\overrightarrow x$, is termed the physical space as this corresponds to the space of interest in a particular problem. The figure also shows a perfectly squared domain where we denote space coordinates by a position vector $\\overrightarrow r$: we refer to this perfectly squared element as the canonical element and to its mathematical space as the natural space. For reasons that will be explained later, it is convenient to  have canonical elements of side $h = 2.0$. Note also that since the canonical element is a constant square of side $h$ the corresponding Lagrange interpolation functions are always the same. This implies that if the interpolation process were to be conducted over the natural space it could be easily coded as it would amount to coding the interpolation functions per se.\r\n\r\nIn mathematical language the connection between both spaces is written in terms of general functional relations as:\r\n\r\n\\begin{equation}\r\n\\begin{aligned}\r\nx_i &=x_i(\\overrightarrow r)\\\\\r\nr_I &=r_I(\\overrightarrow x).\r\n\\end{aligned}\r\n\\label{eq:trans}\r\n\\end{equation}\r\n\r\nThe first of these functional relationships maps every point $\\overrightarrow r$ from the canonical space into a point $\\overrightarrow x$ of the physical space. In particular the relationship \\ref{eq:trans}(a) can be written using:\r\n\r\n\r\n\\begin{equation}\r\nx_i=N^Q(\\overrightarrow r)x^Q.\r\n\\label{eq:trans_iso}\r\n\\end{equation}\r\n\r\n\r\nwhere the physical space has been represented as an interpolated approximation using as the exact functions the coordinates of the nodal points of the physical space. In particular, the first expression provides the position vector $\\overrightarrow x$ in the physical space for a point that in the canonical space occupies the position vector $\\overrightarrow r$. Similarly, the inverse relation gives the position vector $\\overrightarrow r$ in the canonical space for a point that occupies the position vector $\\overrightarrow x$ in the physical space. Note that since in \\ref{eq:trans}(a) we have used the interpolation functions formulated for the perfectly squared canonical space to approximate the geometry or actual physical space this same transformation can be used to transform functions as explained next.\r\n\r\nAssume that $f=f(\\overrightarrow x)$ is a function that describes the space variation of a quantity of interest over a given domain.  Using  the mapping \\ref{eq:trans} it is also possible to obtain the variation of the quantity in the canonical space after writing:\r\n\r\n\r\n\\[ f=f(\\overrightarrow x)\\equiv f\\lbrack x_i(\\overrightarrow r)\\rbrack\\equiv F(\\overrightarrow r). \\]\r\n\r\nIn the above expression $F = F(\\overrightarrow r)$ represents the same physical variable but expressed in terms of the position vector in the canonical space. Being able to represent functions in the physical and the canonical space is an important result since it is now possible to conduct interpolation of functions over constant domains as:\r\n\r\n\\begin{equation}\r\nF(\\overrightarrow r)=N^Q(\\overrightarrow r)f^Q.\r\n\\label{eq:trans_inter}\r\n\\end{equation}\r\n\r\nNote that as a result of the space transformation \\ref{eq:trans}, finding the physical function at a point $r_I$ is equivalent to finding the function at an associated point $x_i$ in the physical domain.\r\n\r\n\r\n\\begin{tcolorbox}\r\n\r\nNotebooks 3 and 4 in the REPO make use of Pyhton functions to perform interpolation over two-dimensional domains. In particular, NB4 applies interpolation over arbitrary domains to visualize closed-form solutions.\r\n\r\n\\end{tcolorbox}\r\n\r\n%\r\n\\paragraph*{Proposed problems}\r\n\\begin{enumerate}\r\n\r\n\\item \\label{punto01} For the computational domain $x\\in\\lbrack-1.0\\;,\\;1.0\\rbrack$ and 3 nodal points corresponding to $x^1 = -1.0$, $x^2 = +1.0$ and $x^3 = 0.0$ find the Lagrange polynomials $L^1(x)$, $L^2(x)$ and $L^3(x)$.\r\n\r\n\\item \\label{punto02} Verify that the polynomials $L^1(x)$, $L^2(x)$ and $L^3(x)$ satisfy the property $L^I(x^J)=\\delta^{IJ}$. \r\n\r\n\\item \\label{punto03} Implement a Python script that uses the vector of known values of a function $[f^1 , f^2 , f^3 ]$ and the polynomials from problem 1 and compute the interpolating polynomial $p(x)$.\r\n\r\n\\item \\label{punto04} Using $p(x)$ from problem 3 compute and plot the first order derivative of $f(x)$ in the interval $[-1 , 1]$.\r\n\r\n\\item \\label{punto 05} For the function  $f(x) = {x^3} + 4{x^2} - 10$ for $x$ in the range $[-1.0, 1.0]$ find values at nodal points that result from splitting the complete interval into 4 sub-domains each one with 3 nodal points. Using these values implement a local interpolation scheme using 2-nd order local interpolation polynomials. Plot the interpolation polynomial in each sub-domain and the corresponding interpolating function $p(x)$. In the same plot compare $p(x)$ and $f(x)$. Additionally, plot the first derivative of the function obtained from $p(x)$ and $f(x)$.\r\n\r\n\\item \\label{punto 06} For the Runge function defined by:\r\n\r\n\\[f(x) = \\frac{1}{{1 + 25{x^2}}}\\]\r\n\r\nimplement an interpolation scheme using local 1st-order Lagrange polynomials. Use (i) sub-domains of constant size $\\Delta x = 0.2$ and (ii) sub-domains whose size decreases towards the edges of the interval.\r\n\r\n\\item \\label{punto 07} Using an independent script (or a notebook) implement a local interpolation scheme using a canonical element of size 2.0 and use it to approximate the Runge function.\r\n\r\n\\item \\label{punto 08} Assume that at the 4 nodal points of a 2D square domain of side $2h$ we know the vector field\r\n\r\n\\[\\overrightarrow u=u(x,y)\\widehat i+v(x,y)\\widehat j \\]\r\n\r\nand where $u(x,y)$ and $v(x,y)$ are the scalar rectangular components along the $x$ and $y$ direction of a cartesian coordinate system.\r\n\r\n\\begin{itemize}\r\n\\item[•] Implement an interpolation scheme to compute the vector field $\\overrightarrow u\\;=\\;\\overrightarrow u(x,y)$ at an arbitrary point $(x,y)$.\r\n\\item[•] Use the interpolation scheme to compute $\\varepsilon_{xx}=\\frac{\\partial u}{\\partial x}$ and $\\varepsilon_{yy}=\\frac{\\partial v}{\\partial y}$\r\n\\item[•] Implement a Python script to visualize the vector field and the scalars $\\varepsilon_{xx}$ and $\\varepsilon_{yy}$.\r\n\\end{itemize}\r\n\r\n\\item \\label{punto 09}\r\nImplement a Python script to visualize analytic (or numerical) solutions available at a set of nodes. Use the following steps;\r\n\r\n\\begin{itemize}\r\n\\item[•] Use external software\\footnote{Gmsh is an open source software for pre and post processing of complex 1D, 2D and 3D domains. Meshio is a set of Python scripts to read and write Gmsh readable files using dictionaries.} to define and mesh and arbitrary solution domain.\r\n\\item[•] Evaluate the solution at the nodal points of the mesh and store the results into arrays.\r\n\\item[•] Use Python triangularization objects together with matplotlib routines to visualize the solution.\r\n\\end{itemize}\r\n\r\n\r\n\\end{enumerate}\r\n", "meta": {"hexsha": "900c2d596e19fa176cde4f0fdcb4304693c15b9e", "size": 37967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course_notes/src/interpolation.tex", "max_stars_repo_name": "AppliedMechanics-EAFIT/Introductory-Finite-Elements", "max_stars_repo_head_hexsha": "a4b44d8bf29bcd40185e51ee036f38102f9c6a72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2019-11-26T13:28:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T17:57:11.000Z", "max_issues_repo_path": "course_notes/src/interpolation.tex", "max_issues_repo_name": "jgomezc1/Introductory-Finite-Elements", "max_issues_repo_head_hexsha": "a4b44d8bf29bcd40185e51ee036f38102f9c6a72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "course_notes/src/interpolation.tex", "max_forks_repo_name": "jgomezc1/Introductory-Finite-Elements", "max_forks_repo_head_hexsha": "a4b44d8bf29bcd40185e51ee036f38102f9c6a72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-02-17T07:24:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T07:54:28.000Z", "avg_line_length": 57.7006079027, "max_line_length": 900, "alphanum_fraction": 0.7329523007, "num_tokens": 10428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6058455269844075}}
{"text": "\\documentclass[12pt, letterpaper, oneside, notitlepage, onecolumn]{article}\n\\author{Buck Baskin}\n\\title{Vector-Rotation to Euler Angles}\n\\pagestyle{plain}\n\n\\usepackage{parskip}\n\n\\usepackage{textcomp}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{verbatim}\n\\usepackage{soul}\n\\usepackage[margin=0.69in]{geometry}\n\n% math\n\\usepackage{amsmath, amssymb, amsthm, gensymb}\n\n\\usepackage{graphicx}\n\\graphicspath{ {images/tc1/} }\n% \\includegraphics[height=6.75in,angle=270]{HW25}\n\n\\definecolor{dkgreen}{rgb}{0,0.6,0}\n\\definecolor{gray}{rgb}{0.5,0.5,0.5}\n\\definecolor{mauve}{rgb}{0.58,0,0.82}\n\n\\lstset{frame=tb,\n  language=Matlab,\n  aboveskip=3mm,\n  belowskip=3mm,\n  showstringspaces=false,\n  columns=flexible,\n  basicstyle={\\small\\ttfamily},\n  numbers=none,\n  numberstyle=\\tiny\\color{gray},\n  keywordstyle=\\color{blue},\n  commentstyle=\\color{dkgreen},\n  stringstyle=\\color{mauve},\n  breaklines=true,\n  breakatwhitespace=true,\n  tabsize=3\n}\n\n\\DeclareMathOperator*{\\argmax}{arg\\,max}\n\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n\\newcommand{\\subsubsubsection}{\\paragraph}\n\\newcommand{\\bbs}[1]{\\section{#1}}\n\\newcommand{\\bbss}[1]{\\subsection{#1}}\n\\newcommand{\\bbsss}[1]{\\subsubsection{#1}}\n\\newcommand{\\bbssss}[1]{\\subsubsubsection{#1}}\n\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\begin{document}\n\\maketitle\n\nSome calculations were verified using Python.\n\n\\section{Answer}\n\n$R_{BA} = R_{y}(\\alpha) R_{x}(\\beta) R_{y}(\\gamma)$\n\n$R_{y} (\\alpha) = \n\\left[\\begin{matrix}\\cos{\\left (\\alpha \\right )} & 0 & \\sin{\\left (\\alpha \\right )}\\\\0 & 1 & 0\\\\- \\sin{\\left (\\alpha \\right )} & 0 & \\cos{\\left (\\alpha \\right )}\\end{matrix}\\right]$\n\n$R_{x} (\\beta) = \n\\left[\\begin{matrix}1 & 0 & 0\\\\0 & \\cos{\\left (\\beta \\right )} & - \\sin{\\left (\\beta \\right )}\\\\0 & \\sin{\\left (\\beta \\right )} & \\cos{\\left (\\beta \\right )}\\end{matrix}\\right]$\n\n$R_{y} (\\gamma) = \n\\left[\\begin{matrix}\\cos{\\left (\\gamma \\right )} & 0 & \\sin{\\left (\\gamma \\right )}\\\\0 & 1 & 0\\\\- \\sin{\\left (\\gamma \\right )} & 0 & \\cos{\\left (\\gamma \\right )}\\end{matrix}\\right]$\n\n$R_{BA} = \n\\left[\\begin{matrix}\\cos{\\left (\\alpha \\right )} & 0 & \\sin{\\left (\\alpha \\right )}\\\\0 & 1 & 0\\\\- \\sin{\\left (\\alpha \\right )} & 0 & \\cos{\\left (\\alpha \\right )}\\end{matrix}\\right]\n\\left[\\begin{matrix}1 & 0 & 0\\\\0 & \\cos{\\left (\\beta \\right )} & - \\sin{\\left (\\beta \\right )}\\\\0 & \\sin{\\left (\\beta \\right )} & \\cos{\\left (\\beta \\right )}\\end{matrix}\\right]\n\\left[\\begin{matrix}\\cos{\\left (\\gamma \\right )} & 0 & \\sin{\\left (\\gamma \\right )}\\\\0 & 1 & 0\\\\- \\sin{\\left (\\gamma \\right )} & 0 & \\cos{\\left (\\gamma \\right )}\\end{matrix}\\right]$\n\n$R_{BA} = \n\\left[\\begin{matrix}- \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\beta \\right )} + \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\gamma \\right )} & \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\beta \\right )} & \\sin{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )} + \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\alpha \\right )}\\\\\\sin{\\left (\\beta \\right )} \\sin{\\left (\\gamma \\right )} & \\cos{\\left (\\beta \\right )} & - \\sin{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )}\\\\- \\sin{\\left (\\alpha \\right )} \\cos{\\left (\\gamma \\right )} - \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} & \\sin{\\left (\\beta \\right )} \\cos{\\left (\\alpha \\right )} & - \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\gamma \\right )} + \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )}\\end{matrix}\\right]$\n\nThe equivalent rotation to $R(\\begin{bmatrix}1/\\sqrt{3} \\\\ 1/\\sqrt{3} \\\\ 1/\\sqrt{3}\\end{bmatrix}, -90 \\degree)$ using Rodriguez Formula:\n\n$e^{\\hat{\\omega} \\theta} = I + \\hat{\\omega} sin(\\theta) + (1 - cos(\\theta) )\\hat{\\omega}^{2}$\n\nFor $\\theta = -90$:\n\n$e^{\\hat{\\omega} \\theta} = I - \\hat{\\omega} + \\hat{\\omega}^{2}$\n\n% ---- %\n$\\hat{\\omega} = \n\\left[\\begin{matrix}0 & - \\frac{\\sqrt{3}}{3} & \\frac{\\sqrt{3}}{3}\\\\\\frac{\\sqrt{3}}{3} & 0 & - \\frac{\\sqrt{3}}{3}\\\\- \\frac{\\sqrt{3}}{3} & \\frac{\\sqrt{3}}{3} & 0\\end{matrix}\\right]$\n\n$\\hat{\\omega}^{2} = \n\\left[\\begin{matrix}- \\frac{2}{3} & \\frac{1}{3} & \\frac{1}{3}\\\\\\frac{1}{3} & - \\frac{2}{3} & \\frac{1}{3}\\\\\\frac{1}{3} & \\frac{1}{3} & - \\frac{2}{3}\\end{matrix}\\right]$\n\n$e^{\\hat{\\omega} \\theta} = I - \n\\left[\\begin{matrix}0 & - \\frac{\\sqrt{3}}{3} & \\frac{\\sqrt{3}}{3}\\\\\\frac{\\sqrt{3}}{3} & 0 & - \\frac{\\sqrt{3}}{3}\\\\- \\frac{\\sqrt{3}}{3} & \\frac{\\sqrt{3}}{3} & 0\\end{matrix}\\right]\n + \n\\left[\\begin{matrix}- \\frac{2}{3} & \\frac{1}{3} & \\frac{1}{3}\\\\\\frac{1}{3} & - \\frac{2}{3} & \\frac{1}{3}\\\\\\frac{1}{3} & \\frac{1}{3} & - \\frac{2}{3}\\end{matrix}\\right]$\n\n$e^{\\hat{\\omega} \\theta} = \\left[\\begin{matrix}\\frac{1}{3} & \\frac{1}{3} + \\frac{\\sqrt{3}}{3} & - \\frac{\\sqrt{3}}{3} + \\frac{1}{3}\\\\- \\frac{\\sqrt{3}}{3} + \\frac{1}{3} & \\frac{1}{3} & \\frac{1}{3} + \\frac{\\sqrt{3}}{3}\\\\\\frac{1}{3} + \\frac{\\sqrt{3}}{3} & - \\frac{\\sqrt{3}}{3} + \\frac{1}{3} & \\frac{1}{3}\\end{matrix}\\right] = R_{BA} =$\n$\\begin{bmatrix}\nr_{11} & r_{12} & r_{13} \\\\\nr_{21} & r_{22} & r_{23} \\\\\nr_{31} & r_{32} & r_{33} \\\\\n\\end{bmatrix}$\n\n$\\left[\\begin{smallmatrix}- \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\beta \\right )} + \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\gamma \\right )} & \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\beta \\right )} & \\sin{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )} + \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\alpha \\right )}\\\\\\sin{\\left (\\beta \\right )} \\sin{\\left (\\gamma \\right )} & \\cos{\\left (\\beta \\right )} & - \\sin{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )}\\\\- \\sin{\\left (\\alpha \\right )} \\cos{\\left (\\gamma \\right )} - \\sin{\\left (\\gamma \\right )} \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} & \\sin{\\left (\\beta \\right )} \\cos{\\left (\\alpha \\right )} & - \\sin{\\left (\\alpha \\right )} \\sin{\\left (\\gamma \\right )} + \\cos{\\left (\\alpha \\right )} \\cos{\\left (\\beta \\right )} \\cos{\\left (\\gamma \\right )}\\end{smallmatrix}\\right] = $\n$\\begin{bmatrix}\nr_{11} & r_{12} & r_{13} \\\\\nr_{21} & r_{22} & r_{23} \\\\\nr_{31} & r_{32} & r_{33} \\\\\n\\end{bmatrix}$\n\n\\subsection{Solving for $\\alpha, \\beta, \\gamma$}\n\n\\subsubsection{$\\beta$}\n\nUsing the atan method, one can solve for $\\beta$ using the middle column of the matrix. The middle value, $r_{22} = cos(\\beta)$. Using $r_{12}^{2} + r_{32}^{2} = sin^{2}(\\beta)(sin^{2}(\\gamma) + cos^{2}(\\gamma)) = sin^{2}(\\beta)$, $sin(\\beta) = \\sqrt{r_{12}^{2} + r_{32}^{2}}$. Therefore, $\\beta = atan2(\\sqrt{r_{12}^{2} + r_{32}^{2}}, r_{22})$.\n\n\\subsubsection{$\\gamma$}\n\nLooking at two elements in the middle row of the matrix, one can solve for $\\gamma$ using the atan method. $r_{21} = sin(\\beta) sin(\\gamma)$, so $sin(\\gamma) = r_{21} / sin(\\beta)$. $r_{23} = -sin(\\beta) cos(\\gamma)$, so $cos(\\gamma) = -r_{23} / sin(\\beta)$. Therefore, $\\gamma = atan2(r_{21} / sin(\\beta), -r_{23} / sin(\\beta))$.\n\n\\subsubsection{$\\alpha$}\n\n$r_{12} = sin(\\alpha) sin(\\beta)$, $sin(\\alpha) = r_{12} / sin(\\beta)$\n\n$r_{32} = cos(\\alpha) sin(\\beta)$, $cos(\\alpha) = r_{32} / sin(\\beta)$\n\n$\\alpha = atan2(r_{12} / sin(\\beta), r_{32} / sin(\\beta))$\n\n\\subsection{Conclusion}\n\nSubstituting the correct values from $R_{BA}$ calculated by Rodriguez Formula into the spaces allocated by $r_{ij}$ that were solved into an $atan2$ formula using $R_{BA}$ calculated by the rotation matrices gives the solution for the equivalent rotations in radians (rounded to 3 decimal places).\n\n$\\alpha = 1.833, \\beta = 1.231, \\gamma = -2.880$\n\n\\end{document}\n", "meta": {"hexsha": "51fc93c7ef41d0fb055f036035d8838a5abf606a", "size": 7531, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example.tex", "max_stars_repo_name": "buckbaskin/paPYrus", "max_stars_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example.tex", "max_issues_repo_name": "buckbaskin/paPYrus", "max_issues_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example.tex", "max_forks_repo_name": "buckbaskin/paPYrus", "max_forks_repo_head_hexsha": "815858715beb74814699277ae0377894d4f54f5b", "max_forks_repo_licenses": ["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.0352112676, "max_line_length": 915, "alphanum_fraction": 0.596600717, "num_tokens": 2892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.79053032607222, "lm_q1q2_score": 0.605778363535813}}
{"text": "\\chapter{Yao's Principle}\nUsing game theory we may develop a method for proving lower bounds on complexity\nof randomized algorithms. To illustrate this method we will study the problem we\nduscussed in \\Cref{chapter:expectation,chapter:structural-induciton}: Alice\nchoose a number from $\\range{1000}$, Bob can flip a coin and ask yes/no\nquestions; Bob would like to guess it using, on average, as few questions as\npossible. We claim that Bob needs at least $9$ questions.\n\\begin{theorem}\n\\label{theorem:randomized-dts-lower-bound}\n  Let $\\Omega$ be a set of $B$-decision trees and $\\Distribution{D}$ be a\n  probability distribution on $\\Omega$. If $\\DTValue{T}{x} = x$ for all \n  $x \\in \\range{1000}$ and $T \\in \\Omega$, then\n  $\\expectation[\\Distribution{D}]{\\DTValue{T}{x}} \\ge 9$ for some $x \\in\n  \\range{1000}$.\n\\end{theorem}\n\nTo prove this statement we would need to give formal notions of randmoized\n$B$-decision tree complexity and heuristic $B$-decision tree cmplexity.\n\\begin{definition}\n  Let $f : [1000] \\to \\Z$ be a function. We say that $\\bar{T} = \n  (\\Omega, \\Distribution{T})$ is a \\emph{randomized}\\footnote{%\n    In fact, there are many notions of randomized computation; the algorithms\n    discussed in this chapter are usually called zero-error randomized\n    algorithms.\n  }\n  \\emph{$B$-decision tree for $f$ of cost $C$}\n  if $\\Omega$ is a set of $B$-decision trees, $\\Distribution{T}$ is a\n  probability distribution on $\\Omega$, $\\DTValue{T}{x} = f(x)$ for all $x \\in\n  \\range{1000}$, and \n  $\\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}} = C$.\n\n  We also say that $T$ is a \\emph{heuristic $B$-decision tree for $f$ of\n  expected cost $C$ with respect to a distribution $\\Distribution{X}$} if \n  $\\DTValue{T}{x} = f(x)$ for all $x \\in \\range{1000}$ and\n  $\\expectation[x \\gets \\Distribution{X}]{\\DTHeight[x]{T}} = C$.\n\n  The \\emph{randmoized $B$-decision tree complexity $\\RandCBDT{f}$ of $f$}\n  is equal to the minimal $C$ such that there is a randomized $B$-decision tree\n  for $f$ of cost $C$.\n\n  The \\emph{heuristic $B$-decision tree complexity\n  $\\HeurCBDT[\\Distribution{X}]{f}$ of $f$ with respect to $\\Distribution{X}$} is\n  equal to the minimal $C$ such that there is a $B$-decision tree for $f$ of\n  expected cost $C$ with respect to $\\Distribution{X}$. Finally, \\emph{the\n  heuristic $B$-decision tree complexity $\\HeurCBDT{f}$ of $f$} is equal to the\n  maximum of $\\HeurCBDT[\\Distribution{X}]{f}$ over all distributions\n  $\\Distribution{X}$.\n\\end{definition}\n\nNonetheless that we have not had the notion of randomized complexity before, we\nproved upper bounds in \\Cref{chapter:expectation}. Unfortunately, proving lower\nbounds directly for randomized complexity is not easy, but it is usually way\neasier to prove lower bounds on heuristic complexity. Yao's principle (also\ncalled Yao's minimax principle or Yao's lemma) gives a connection between these\nmeasures.\n\\begin{theorem}[Yao's principle]\n\\label{theorem:yaos-principle}\n  Let $f : [1000] \\to \\Z$ be a function. Then $\\RandCBDT{f} = \n  \\HeurCBDT{f}$.\n\\end{theorem}\n\n\nUsing this principle is easy to prove the lower bound.\n\\begin{proof}[Proof of \\Cref{theorem:randomized-dts-lower-bound}]\n  Note that the theorem says that $\\RandCBDT{\\identity{\\range{1000}}} \\ge 9$;\n  hence, it is enough to prove that $\\HeurCBDT{\\identity{\\range{1000}}} \\ge 9$.\n  Let us assume the opposite; i.e., that for any distribution $\\Distribution{X}$\n  there is a $B$-decision tree $T$ such that $\\DTValue{T}{x} = x$ for all $x \\in\n  \\range{1000}$ and $\\expectation[x \\gets \\Distribution{X}]{\\DTHeight[x]{T}} <\n  9$.\n  This implies that there is a $B$-decision tree $T$ such that \n  $\\frac{1}{1000} \\sum_{x \\in \\range{1000}} \\DTHeight[x]{T} < 9$; we are going to prove that\n  this is impossible. Let us fix such a $T$.\n\n  We prove, using induction by $|S|$ that $\\sum_{x \\in S} \\DTHeight[x]{T} \\ge\n  |S| \\log_2 |S|$. The base case for $|S| = 1$ is clear since \n  $\\DTHeight[x]{T} \\ge 1$ for all $x \\in \\range{1000}$. \n  \n  Let us prove the induction step. Let $T = \\DTIf{f}{T_0}{T_1}$, and let \n  $S_0 = \\set[f(x) = 0]{x \\in S}$ and $S_1 = \\set[f(x) = 1]{x \\in S}$.\n  It is clear that $\\sum_{x \\in S} \\DTHeight[x]{T} = |S| + \n  \\sum_{x \\in S_0} \\DTHeight[x]{T} + \\sum_{x \\in S_1} \\DTHeight[x]{T}$. By the\n  induction hypothesis, this implies that $\\sum_{x \\in S} \\DTHeight[x]{T} = |S|\n  + |S_0| \\log_2 |S_0| + |S_1| \\log_2 |S_1| \\ge |S| + |S| \\log_2 (|S| / 2) =\n  |S| \\log_2 |S|$.\n\n  Therefore, $\\frac{1}{1000} \\sum_{x \\in \\range{1000}} \\DTHeight[x]{T} \\ge\n  \\log_2 1000 > 9$, which contradicts the assumption.\n\\end{proof}\n\nNow we are ready to prove Yao's principle.\n\\begin{proof}[Proof of \\Cref{theorem:yaos-principle}]\n  We start from proving that $\\RandCBDT{f} \\ge \\HeurCBDT{f}$. Assume the\n  opposite; i.e., that $\\RandCBDT{f} < \\HeurCBDT{f}$. \n  \n  \n  Let $\\bar{T} = (\\Omega, \\Distribution{T})$ be a randomized $B$-decision tree\n  for $f$ of cost $C < \\HeurCBDT{f}$. Note that \n  $\\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}} \\le C$ for all $x \\in\n  \\range{1000}$. Hence, \n  $\\expectation[x \\gets \\Distribution{X}]{\n    \\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}}\n  } \\le C$. However, \n  \\begin{multline*}\n    C \\ge \n    \\expectation[x \\gets \\Distribution{X}]{\n      \\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}}\n    } = \\\\\n    \\expectation[T \\gets \\Distribution{T}]{\n      \\expectation[x \\gets \\Distribution{X}]{\\DTHeight[x]{T}}\n    } \\ge\n    \\expectation[T \\gets \\Distribution{T}]{\n      \\HeurCBDT[\\Distribution{X}]{f}\n    } = \\HeurCBDT[\\Distribution{X}]{f}.\n  \\end{multline*}\n  As a result, $C \\ge \\HeurCBDT{f}$, which is a contradiction to the assumption.\n\n\n  Let us prove that $\\RandCBDT{f} \\le \\HeurCBDT{f}$. To prove this inequality we\n  are going to use von Neumann's minimax theorem (\\Cref{theorem:von-neumanns-minimax}).\n  Let $X = \\range{1000}$, $Y$ be a set of all $B$-decision trees $T$ such that\n  $\\DTHeight{T} \\le 1000$ and $\\DTValue{T}{x} = f(x)$ for all $x \\in\n  \\range{1000}$, and $A(x, T) = - B(x, T) = \\DTHeight[x]{T}$.\n\n  \\Cref{theorem:von-neumanns-minimax} implies that there are distributions\n  $\\Distribution{X}$ and $\\Distribution{T}$ over $X$ and $Y$ respectively such\n  that \n  \\[\n    \\expectation[x \\gets \\Distribution{X}]{\\DTHeight[x]{T'}} \\ge \n    \\expectation[x \\gets \\Distribution{X}]{\n      \\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}}\n    } \\ge \n    \\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x']{T}}\n  \\]\n  for all $x' \\in X$ and $T' \\in Y$. Which implies that \n  \\[\n    \\HeurCBDT[\\Distribution{X}]{f} \\ge \n    \\expectation[x \\gets \\Distribution{X}]{\n      \\expectation[T \\gets \\Distribution{T}]{\\DTHeight[x]{T}}\n    } \\ge \\RandCBDT{f}.\n  \\]\n\\end{proof}\n", "meta": {"hexsha": "9b8387ded9b5fd26feb1b34ea5aea5837a40a299", "size": 6720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_6/chapter_29_yaos_principle.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_6/chapter_29_yaos_principle.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_6/chapter_29_yaos_principle.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.993006993, "max_line_length": 92, "alphanum_fraction": 0.6636904762, "num_tokens": 2276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.766293653760418, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.605778358738408}}
{"text": "\\RequirePackage[l2tabu, orthodox]{nag}\n\\documentclass{article}\n\n\\usepackage[letterpaper]{geometry}\n\\usepackage{booktabs}\n\\usepackage{mathtools}\n\\usepackage[binary-units=true]{siunitx}\n\\usepackage{tikz}\n\n\\title{ECE 487 Assignment 6}\n\\author{Michael Kwok}\n\\begin{document}\n\n\\maketitle\n\\subsection*{CSMA/CD minimum frame size}\nPropagation Time: \\(T_p = \\frac{1200}{3 \\times 10^8} = 4\\times 10 ^{-6}\\) \\\\\nFrame time: \\(T_{fr} \\geq 8 \\times 10^{-6} = \\SI{8}{\\micro\\second}\\) \\\\\nMinimum frame size: \\( \\SI{10}{\\mega\\bit\\per\\second} \\cdot \\SI{8}{\\micro\\second} = 80 \\text{ bits}\\)\n\n\\subsection*{Reservation Access Method}\nReservation phrase: \\(\\SI{10}{\\micro\\second} \\cdot 5 = \\SI{50}{\\micro\\second}\\) \\\\\nData transmission time: \\( \\frac{5 \\cdot 1000}{10 \\times 10^6} = \\SI{0.00055}{\\second} \\) \\\\\nThroughput: \\(\\frac{0.001}{0.00055} = \\SI{1.818}{\\mega\\bit\\per\\second}\\)\n\n\\subsection*{WLAN}\n\\begin{enumerate}\n    \\item First transmission: \\(\\text{DIFS} + \\SI{200}{\\micro\\second} = \\SI{250}{\\micro\\second}\\)\n    \\item \\(\\text{RTS}+ \\text{SIFS} + \\text{CTS} + \\text{SIFS} + \\text{DATA} + \\text{SIFS} + \\text{ACK} + (\\text{Station 2 timer} - \\text{Station 1 timer}) = \\SI{1580}{\\micro\\second}\\)\n\\end{enumerate}\n\n\n\\end{document}\n", "meta": {"hexsha": "247640f4d31fe9a2f023aacea5d8d8e7b0ce1519", "size": 1218, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/ECE487/Assignment6.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/ECE487/Assignment6.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/ECE487/Assignment6.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": 36.9090909091, "max_line_length": 184, "alphanum_fraction": 0.6658456486, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6057783578632897}}
{"text": "\\documentclass[axodraw]{amsart}\n\\usepackage{amsmath}\n\\usepackage{feyn}\n\\usepackage{feynmp}\n\\begin{document}\n\n\\section{feyn}\n\n\\begin{align*}\n    \\feyn{a} \\\\\n    \\feyn{b} \\\\\n    \\feyn{c} \\\\\n    \\feyn{d} \\\\\n    \\feyn{e} \\\\\n    \\feyn{f} \\\\\n    \\feyn{g} \\\\\n    \\feyn{h} \\\\\n    \\feyn{i} \\\\\n    \\feyn{j} \\\\\n    \\feyn{k} \\\\\n    \\feyn{l} \\\\\n    \\feyn{m} \\\\\n    \\feyn{n} \\\\\n    \\feyn{o} \\\\\n    \\feyn{p} \\\\\n    \\feyn{q} \\\\\n    \\feyn{r} \\\\\n    \\feyn{s} \\\\\n    \\feyn{t} \\\\\n    \\feyn{u} \\\\\n    \\feyn{v} \\\\\n    \\feyn{w} \\\\\n    \\feyn{x} \\\\\n    \\feyn{y} \\\\\n    \\feyn{z} \\\\\n\\end{align*}\n\\[\n\\Diagram{\\vertexlabel^a \\\\\n  fd \\\\\n& g\\vertexlabel_{\\mu,c} \\\\\n\\vertexlabel_b fu \\\\\n}\n=\n\\Diagram{\\vertexlabel^a \\\\\n  fdA \\\\\n& gA\\vertexlabel_{\\mu,c} \\\\\n\\vertexlabel_b fuV \\\\\n}\n=\n\\Diagram{\\momentum{fdA}a\\\\\n   & \\vertexlabel_{\\gamma_\\mu} \\momentum{gA}{\\mu,c} \\\\\n\\momentum{fuV}b\n}\n=\nig\\gamma_\\mu (T^c)_{ab}\n\\]\n\nTwo-loop diagram:\n\\[\n\\feyn{ff gl ff}\n\\to\n\\feyn{ff\\bigbosonloopA\\smallbosonloopV ff}\n=\n\\feyn{!{fA}p f!{glBV}k !{glSA}l a\\vertexlabel_{p+k-l} ff}\n\\]\n\nBremsstrahlung:\n\\[\n  \\Diagram{        & x \\\\\n                   & ![ulft]{gvV}{q=p'+k-p}   & !{guA}k \\\\\n           ![bot]{fA}p & ![bot]{fA}{p'+k} & ![lrt]{fA}{p'} \\\\\n        }\n        +\n  \\Diagram{    & !{guA}k \\\\\n           !{fA}p & fs ![bot]{fA}{p-k} & !{fA}{p'} \\\\\n               &         & ![lrt]{gvA}{q=p'+k-p} \\\\\n               &         & x\\\\\n        }\n\\]\n\n\n\nOPE:\n\\def\\bracket#1{\\langle #1 \\rangle}\n\\begin{eqnarray*}\n-i\\Sigma_{\\mathrm{ope}} &=&\n     \\left[\\feyn{faf + fsfglffs \n                 + \\cdots} \\right] 1 \\\\\n     && \\quad{}+ \n           \\left[ \\feyn{ fxfs0glfs0xf \n                  + \\cdots} \\right]\n         \\bracket{\\overline\\psi M \\psi} \\\\\n     && \\quad{}+ \\left[\n         \\Diagram{   &x  &x  \\\\\n                     &gv &gv \\\\\n                  fs &fs &fs \\\\} + \\cdots\n         \\right]\n         \\bracket{G_{\\mu\\nu}^a G_{\\mu\\nu}^a}\\\\\n\\end{eqnarray*}\n\nComplete vertex:\n\\begin{eqnarray*}\n\\feyn{fcf} &=& \\feyn{faf + fpf + fpfpf + \\cdots} \\\\\n    &=& \\sum_{n=0}^\\infty \\feyn{fA ( pfA)}^n \\\\\n    &=& \\feyn{\\frac{fA}{1-(pfA)}}.\n\\end{eqnarray*}\n\n\n\\section{feynmp}\n\\begin{fmffile}{simple} \\begin{fmfgraph}(40,25)\n% Note that the size is given in normal parentheses % instead of curly brackets.\n% Define external vertices from bottom to top\n\\fmfleft{i1,i2}\n\\fmfright{o1,o2}\n\\fmf{fermion}{i1,v1,o1}\n\\fmf{fermion}{i2,v2,o2}\n\\fmf{photon}{v1,v2}\n\\end{fmfgraph}\n\\end{fmffile}\n\n\\begin{fmffile}{simple_tree} \\begin{fmfgraph}(40,25)\n\\fmfleft{i} \\fmfright{o1,o2,o3} \\fmf{fermion}{i,v1,o1} \\fmf{photon}{v1,v2} \\fmf{fermion}{o2,v2,o3}\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{simple_box} \\begin{fmfgraph}(40,25)\n\\fmfleft{i1,i2} \\fmfright{o1,o2} \\fmf{fermion}{i1,v1,v2,o1} \\fmf{fermion}{o2,v4,v3,i2} \\fmf{photon}{v1,v3} \\fmf{photon}{v2,v4}\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{simple_labels} \\begin{fmfgraph*}(40,25)\n\\fmfleft{i1,i2} \\fmfright{o1,o2}\n\\fmflabel{$e^-$}{i1} \\fmflabel{$e^+$}{i2} \\fmflabel{$e^+,\\mu^+$}{o1} \\fmflabel{$e^-,\\mu^-$}{o2}\n\\fmflabel{$i\\sqrt{\\alpha}$}{v1} \\fmflabel{$i\\sqrt{\\alpha}$}{v2}\n\\fmf{fermion}{i1,v1,i2} \\fmf{fermion}{o1,v2,o2}\n\\fmf{photon,label=$\\gamma,,Z^0$}{v1,v2} \\end{fmfgraph*}\n\\end{fmffile}\n\n\\begin{fmffile}{tree} \\begin{fmfgraph}(40,30)\n\\fmfbottom{i1,d1,o1} \\fmfright{o0,o2,o3} \\fmf{fermion}{i1,v1,o1} \\fmffreeze \\fmf{fermion}{o2,v2,o3} \\fmf{photon,tension=1.5}{v1,v2}\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{simple_cross} % This is a bad sample. \\begin{fmfgraph}(40,25)\n\\fmfleft{i1,i2} \\fmfright{o1,o2} \\fmf{fermion}{i1,v1,o2} \\fmf{fermion}{i2,v2,o1} \\fmf{photon}{v1,v2}\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{penguin_both} \\begin{fmfgraph}(40,25)\n\\fmfleft{i1,i2} \\fmfright{o1,o2} \\fmf{fermion}{i1,v1,o1} \\fmf{fermion}{i2,v2,v3,v4,o2} \\fmf{photon}{v1,v3} \\fmf{photon,left=0.5,tension=0.2}{v2,v4} % W line\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{penguin_oneside} \\begin{fmfgraph*}(40,30)\n\\fmfstraight \\fmfleft{g1,g2,i3} % g1 and g2 will be used later \\fmfright{o1,o2,o3} \\fmf{fermion}{i3,v2,v3,v4,o3} \\fmf{fermion}{o1,v1,o2} \\fmf{photon,label=$Z^0$}{v1,v3} \\fmf{photon,left=0.5,tension=0.2}{v2,v4}\n\\fmf{phantom}{g1,v1,g2} % pull Z0 from the left \\end{fmfgraph*}\n\\end{fmffile}\n\n\n\\begin{fmffile}{sunset} \\begin{fmfgraph}(40,40)\n\\fmfleft{i} \\fmfright{o} \\fmf{plain,tension=5}{i,v1} \\fmf{plain,tension=5}{v2,o} \\fmf{plain,left,tension=0.4}{v1,v2,v1} \\fmf{plain}{v1,v2} \\fmfdot{v1,v2}\n\\end{fmfgraph} \\end{fmffile}\n\n\\begin{fmffile}{ears} \\begin{fmfgraph}(50,30)\n\\fmftop{t0,t1,t2,t3} \\fmfbottom{b0,b1,b2,b3} \\fmf{phantom}{t1,v1,b1} \\fmf{phantom}{t2,v2,b2} \\fmffreeze \\fmf{plain,right}{v1,v2,v1} \\fmf{plain,tension=0.8,right=270}{v1,v1} \\fmf{plain,tension=0.8,right}{v2,v2} \\fmfdot{v1,v2}\n\\end{fmfgraph} \\end{fmffile}\n\n\n\\begin{fmffile}{eyeglasses} \\begin{fmfgraph}(50,30)\n\\fmfleft{i} \\fmfright{o} \\fmf{phantom,tension=10}{i,i1} \\fmf{phantom,tension=10}{o,o1} \\fmf{fermion,left,tension=0.4}{i1,v1,i1} \\fmf{fermion,right,tension=0.4}{o1,v2,o1} \\fmf{dashes}{v1,v2}\n\\end{fmfgraph} \\end{fmffile}\n\n\n\\end{document}\n", "meta": {"hexsha": "21879d3be3d5b98cb289cc2062c84e65fb244542", "size": 4998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texshowcase/feynmandiagrams/feynSample.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": "texshowcase/feynmandiagrams/feynSample.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": "texshowcase/feynmandiagrams/feynSample.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": 29.4, "max_line_length": 224, "alphanum_fraction": 0.5898359344, "num_tokens": 2350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996142, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6057783460806836}}
{"text": "\\batchmode\n\\documentclass[paper=a4, fontsize=12pt, prl, notitlepage]{revtex4-1}\n\\usepackage[ssp]{xetex_import}\n\\linespread{1.4}\n\\errorstopmode\n\n\\begin{document}\n\n\\title{Math behind Bayesian uncertainty propagation using normal approximations}\n\\author{Christopher Körber}\n\\affiliation{%\nDepartment of Physics,\nUniversity of California,\nBerkeley, CA 94720, USA\\\\\nNuclear Science Division, %\nLBNL,\nBerkeley, CA 94720, USA\n}\n\\date{\\today}\n\\begin{abstract}\nThis document addresses the math used to propagate errors and to infer posterior distributions (Bayesian statistics) used in \\href{https://github.com/pennsignals/chime_sims/pull/49}{the performance boost through normal approximations PR in the \\texttt{pennsignals/chime\\_sims} repo}.\n\\end{abstract}\n\n\\maketitle\n\n%==============================================================================\n% Content\n%==============================================================================\n\n\\section{Assumptions}\nThe general theme of this document is: \\textit{casting everything to normal distribution simplifies computations}.\n\nIn general, the techniques in PR \\#49 make two approximations\n\\begin{enumerate}\n    \\item All model and data \\textit{input} distributions can be sufficiently approximated with multivariate normal distributions\n    \\item The posterior distributions can be sufficiently approximated by a multivariate normal distribution\n\\end{enumerate}\n\n\\section{Error propagation}\nThe \\texttt{gvar} module is used to analytically propagate errors.\nThe eqution used to computed the standard deviation $\\sigma_f$ of a function $f(\\vec p)$ at a given point in the parameter space $\\bar {\\vec p}$ is\n\\begin{equation}\n    \\sigma_f^2(\\bar {\\vec p})\n    =\n    \\left[\n        \\sum_{i,j=1}^N\n        \\frac{\\partial f(\\vec p)}{\\partial p_i}\n        \\left(\\Sigma_p\\right)_{ij}\n        \\frac{\\partial f(\\vec p)}{\\partial p_j}\n    \\right]_{\\vec p = \\bar {\\vec p}}\n    \\, ,\n\\end{equation}\nwhere $\\Sigma_p$ is the covariance matrix of the normally distributed parameters $\\vec p$.\nIn the uncorrelated case, this simplifies to\n\\begin{equation}\n    \\sigma_f^2(\\bar {\\vec p})\n    =\n    \\left[\n        \\sum_{i=1}^N\n        \\left(\\frac{\\partial f(\\vec p)}{\\partial p_i}\\right)^2\n        \\sigma_{p_i}^2\n    \\right]_{\\vec p = \\bar {\\vec p}}\n    \\, .\n\\end{equation}\n\nThe module \\texttt{gvar} is capable of tracing such derivatives since implemented functions are aware of their analytical derivatives.\n\n\\subsubsection{Example}\nFor example, suppose\n\\begin{align}\n    f(x, y)\n    &=\n    x y^2\n    && \\Rightarrow &\n    \\sigma_f^2(\\bar{\\vec p})\n    &=\n    y^4 (\\Sigma_p)_{xx}\n    + 2 x y^3  \\left[ (\\Sigma_p)_{xy} + (\\Sigma_p)_{yx} \\right]\n    + 4 x^2 y^2 (\\Sigma_p)_{yy}\n\\end{align}\nThus, if $x, y$ follow a multivariate normal distribution of mean $\\bar{\\vec p}$ and covariance $\\Sigma_p$, one finds\n\\begin{align}\n    \\bar{\\vec p}\n    &=\n    \\begin{pmatrix}\n        1 \\\\ -2\n    \\end{pmatrix}\n    \\, , &\n    \\Sigma_p\n    &=\n    \\begin{pmatrix}\n        2 & 1 \\\\ 1 & 1\n    \\end{pmatrix}\n    &\n    \\Rightarrow\n    \\sigma_f(\\bar{\\vec p})\n    &=\n    \\sqrt{32 - 32 + 16} = 4\n\\end{align}\nThe corresponding \\texttt{gvar} code returns\n\\begin{lstlisting}[style=python]\nfrom gvar import gvar\n\nmean = [1, -2]\ncov = [[2, 1], [1, 1]]\nx, y = gvar(mean, cov)\nf = x * y ** 2\nprint(f)\n\n> 4.0(4.0)\n\\end{lstlisting}\n\n\n\\section{Computation of the posterior}\n\nThis section explains how the \\texttt{lsqfit} module approximates the posterior distribution $P(\\vec p|D,M)$ given data $D$, an input model $M$ and it's corresponding priors $P(\\vec p| M)$.\n\n\\subsection{Defintions}\n\nThe posterior distribution $P(\\vec p|D, M)$ is proportional to the prior times the probability of the data given the model and parameters $P(D|\\vec p, M)$ (the likelihood)\n\\begin{align}\n    P(\\vec p|D, M) &=\n    \\frac{P(D|\\vec p, M)P(\\vec p | M)}{P(D|M)}\n    \\propto\n    P(D|\\vec p, M)P(\\vec p | M)\n    \\, .\n\\end{align}\nThe marginal likelihood of the data $D$ given the model $M$ is obtained by integrating over the whole parameter space\n\\begin{equation}\n    P(D|M)\n    =\n    \\int d \\vec p P(D|\\vec p, M)P(\\vec p | M) \\, .\n\\end{equation}\nBecause the posterior is normalized by the ratio of both distributions, one can neglect constant factors in the computation.\n\nThe likelihood of the data given the model and parameters is described by a $\\chi^2$ distribution\n\\begin{equation}\n    P(D|\\vec p, M)\n    \\sim\n    \\exp\\left\\{\n        - \\frac{1}{2}\n        \\sum_{i,j=1}^N\n        \\left[y_i - \\vec f_M(x_i, \\vec p)\\right]\n        \\left(\\Sigma_y^{-1}\\right)_{ij}\n        \\left[y_j - \\vec f_M(x_j, \\vec p)\\right]\n    \\right\\}\n    =\n    \\exp\\left\\{\n        - \\frac{1}{2}\n        \\chi^2_D(\\vec p)\n    \\right\\}\n    \\, ,\n\\end{equation}\nwhere $\\Sigma_y$ is the covariance matrix of the data and $f_M(x_j, \\vec p)$ the model function evaluated at point $x_j$ which aims to describe the data point $y_j$.\n\nMaximizing the Likelihood as a function of $\\vec p$ corresponds to minimizing the exponent--which is the standard $\\chi^2$-minimization procedure.\nComputing the posterior distribution function for a given prior $P(\\vec p| M)$ is called Bayesian inference.\nNormal approximations of the posterior distribution are somewhere in the middle of a full Bayesian treatment and regular $\\chi^2$-minimization.\n\n\\subsection{Normal approximation of the posterior}\nIncluding the multivariate normal prior distribution with mean $\\vec p_0$ and covariance $\\Sigma_{p_0}$, the posterior distribution is proportional to\n\\begin{align}\n    P(\\vec p|D, M)\n    &\\sim\n    \\exp\\left\\{\n        - \\frac{1}{2}\n        \\chi^2_D(\\vec p)\n        - \\frac{1}{2}\n        \\chi^2_M(\\vec p)\n    \\right\\}\n    =\n    \\exp\\left\\{\n        - \\frac{1}{2}\n        \\chi^2_{DM}(\\vec p)\n    \\right\\}\n    \\, , &\n    \\chi^2_M(\\vec p)\n    &=\n    \\left[\\vec p - \\vec p_0\\right]^T \\cdot\n    \\Sigma_{p_0}^{-1}\n    \\left[\\vec p - \\vec p_0\\right]\\, .\n\\end{align}\nIn short, the \\texttt{lsqfit} module approximates the posterior by expressing the function $\\chi^2_{DM}(\\vec p)$ up to second order in $\\vec p$ at the point $\\bar{\\vec p}$ where the first derivative vanishes (stationary or almost always minimal point)\n\\begin{align}\n    \\chi^2_{DM}(\\vec p)\n    & \\approx\n    \\chi^2_{DM}(\\bar{\\vec p})\n    +\n    \\left[\\vec p - \\bar{\\vec p}\\right]^T\n    \\Sigma_{DM}^{-1}(\\bar{\\vec p})\n    \\left[\\vec p - \\bar{\\vec p}\\right]^T\n    \\, , & &\n    \\left.\\frac{\\partial \\chi^2_{DM}(\\vec p)}{\\partial p_\\alpha}\\right|_{\\vec p = \\bar{\\vec p}} = 0 \\, \\quad \\forall_\\alpha \\, .\n\\end{align}\nIn this approximation, the posterior is again a multivariate normal distribution of mean $\\bar{\\vec p}$ (same as maximal likelihood estimation) with covariance $\\Sigma_{DM}(\\bar{\\vec p})$.\nThe \\texttt{nonlinear\\_fit} method numerically computes the vector which minimizes the posterior $\\bar{\\vec p}$ (fitting) and analytically computes and evaluates the covariance matrix $\\Sigma_{DM}(\\bar{\\vec p})$ at this point.\nThe appendix A of \\cite{Bouchard:2014ypa} describes how $\\Sigma_{DM}(\\bar{\\vec p})$ is estimated using derivatives of the residuals with respect of prior parameters.\n%\n% \\subsubsection{Example}\n%\n% Suppose the fit function is a linear function $f(x_i, \\vec p) = p^{(0)} + p^{(1)} x_i$.\n% In this case, the normal approximation of the posterior is exact\n% \\begin{align}\n%     \\chi^2_{DM}(\\vec p)\n%     & =\n%     \\sum_{i,j=1}^N\n%     \\left[y_i - p^{(0)} - p^{(1)} x_i \\right]\n%     \\left(\\Sigma_y^{-1}\\right)_{ij}\n%     \\left[y_j  - p^{(0)} - p^{(1)} x_j\\right]\n%     +\n%     \\left[\\begin{pmatrix} p^{(0)} \\\\ p^{(1)} \\end{pmatrix} - \\vec p_0 \\right]^T\n%     \\left(\\Sigma_p^{-1}\\right)_{ij}\n%     \\left[\\begin{pmatrix} p^{(0)} \\\\ p^{(1)} \\end{pmatrix} - \\vec p_0 \\right]\n%     \\\\\n%     & =\n%     \\left[\n%         \\sum_{i,j=1}^N y_i \\left(\\Sigma_y^{-1}\\right)_{ij} y_j\n%         + \\vec p_0^T\n%         \\left(\\Sigma_p^{-1}\\right)\n%         \\vec p_0\n%     \\right]\n%     +\n%     \\left[\\begin{pmatrix} p^{(0)} \\\\ p^{(1)} \\end{pmatrix} - \\bar{\\vec p} \\right]\n%     \\left(\\Sigma_{DM}^{-1}\\right)_{ij}\n%     \\left[\\begin{pmatrix} p^{(0)} \\\\ p^{(1)} \\end{pmatrix} - \\bar{\\vec p} \\right]^T\n%     \\, ,\n% \\end{align}\n% with\n% \\begin{align}\n%     \\bar{\\vec p} &= \\ldots\n%     \\\\\n%     \\Sigma_{DM}^{-1} &= \\ldots\n% \\end{align}\n\n%==============================================================================\n% End Content\n%==============================================================================\n\\bibliography{notes.bib}{}\n\\bibliographystyle{plainurl}\n\n\\batchmode\n\\end{document}\n", "meta": {"hexsha": "edd927d95851a856c13d6183cfe5ef4c3b6a2923", "size": 8480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bayes_chime/normal/doc/notes.tex", "max_stars_repo_name": "DarkShadeKnigh/chime_sims", "max_stars_repo_head_hexsha": "1e2994a9f48d17e531a6d9b5129392dcdfe8b6b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2020-04-14T01:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-12T17:50:36.000Z", "max_issues_repo_path": "bayes_chime/normal/doc/notes.tex", "max_issues_repo_name": "DarkShadeKnigh/chime_sims", "max_issues_repo_head_hexsha": "1e2994a9f48d17e531a6d9b5129392dcdfe8b6b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2020-04-09T17:46:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-18T22:22:16.000Z", "max_forks_repo_path": "bayes_chime/normal/doc/notes.tex", "max_forks_repo_name": "DarkShadeKnigh/chime_sims", "max_forks_repo_head_hexsha": "1e2994a9f48d17e531a6d9b5129392dcdfe8b6b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2020-04-08T22:41:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-02T21:34:29.000Z", "avg_line_length": 34.8971193416, "max_line_length": 283, "alphanum_fraction": 0.6172169811, "num_tokens": 2638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.6791786926816161, "lm_q1q2_score": 0.6056990541007242}}
{"text": "\\section{Synthesis}\n\\subsection{Resource Graph}\nA resource graph is a graph $G_R = (V_R, E_R), V_R = V_S \\cup V_T$, where\n$V_S$ are the nodes from the sequence graph and $V_T$ are the different resource\ntypes. It is bipartite, $E_R = V_S \\times V_T, (v_s, v_t) \\in E_R$ means $v_s$\ncan be executed on resource type $v_t$. Additionally there is a cost function\n$c: V_T \\to \\mathbb{Z}$ and a execution time function $w: E_R \\to \\mathbb{Z}^{\\geq 0}$\n\nFurthermore $\\alpha(v_t)$ denotes the number of available instances of resource\ntype $v_t$, $\\beta(v_s)$ denotes on which resource type $v_s$ is running, and\n$\\gamma(v_s)$ denotes on which instance of this resource type it is running.\n\n\\subsection{Scheduling}\nA schedule is a function $\\tau: V_S \\to \\mathbb{Z}^{>0}$ that determines the\nstarting times of operations. It is feasible if\n\\begin{equation*}\n\t\\forall (v_i, v_j) \\in E_S . \\tau(v_j) - \\tau(v_i) \\geq w(v_i)\n\\end{equation*}\nwhere $w(v_i) = w(v_i, \\beta(v_i))$ denotes the execution time of $v_i$.\n\nThe latency $L$ is $L = \\tau(v_n) - \\tau(v_0)$, the differnce between the\nstarting times.\n\n\\subsubsection{ASAP}\n\\begin{lstlisting}[escapeinside={(*}{*)}]\nASAP((*$V_S$*), (*$E_S$*), w) {\n\t\\tau((*$v_0$*)) = 1\n\tdo {\n\t\t(*$v_i \\leftarrow \\set{v \\in V_S | \\text{v's predecessors are planned}}$*);\n\t\t(*$\\tau(v_i) = \\max\\set{\\tau(v_j) + w(v_j) | (v_j, v_i) \\in E_S}$*);\n\t} while (unplanned operations exist);\n}\n\\end{lstlisting}\n\n\\subsection{ALAP}\n\\begin{lstlisting}[escapeinside={(*}{*)}]\nALAP((*$V_S$*), (*$E_S$*), w, (*$L_{max}$*)) {\n\t(*$\\tau(v_n)$*) = (*$L_{max}$*) + 1;\n\tdo {\n\t\t(*$v_i \\leftarrow \\set{v \\in V_S | \\text{v's successors are planned}}$*);\n\t\t(*$\\tau(v_i) = \\min\\set{\\tau(v_j) | (v_i, v_j) \\in E_S} - w(v_i)$*);\n\t} while (unplanned operations exist);\n}\n\\end{lstlisting}\n\n\\subsection{Bellman Ford}\nOne might add additional constraints as weighted edges in the sequence graph,\nwhich can be resolved using Bellman Ford to find the single source longest path.\nSet the weight of the normal edges to their execution times.\n\n\\begin{lstlisting}[escapeinside={(*}{*)}]\nBELLMAN-FORD((*$V_S$*), (*$E_S$*), W) {\n\t(*$\\tau_0^0$*) = 0;\n\tfor (int i = 0; i < (*$\\abs{V_S}$*); i++) (*$\\tau_i^0 = w(v_0, v_i)$*);\n\tfor (int j = 0; i < (*$\\abs{V_S}$*); i++) {\n\t\tfor (int i = 0; i < (*$\\abs{V_S}$*); i++) {\n\t\t\t(*$\\tau_i^{j+1}$*) = (*$\\max\\set{\\tau_i^j, \\tau_k^j + w(v_k, v_i) | k \\neq i}$*);\n\t\t}\n\t\tif ((*$\\forall i \\,.\\, \\tau_i^{j+1} = \\tau_i^j$*)) return true; // success\n\t}\n\treturn false; // failed\n}\n\\end{lstlisting}\n\n\\subsubsection{Example constraints}\n\\begin{tikzpicture} [node distance=1.5cm]\n\t\\tikzset{nop/.append style={minimum width=5mm}}\n\t\\tikzset{inner/.append style={minimum width=5mm}}\n\t\\node[nop]\t\t(0)\t\t\t\t\t\t{0};\n\t\\node[inner]\t(1) [below left of=0]\t{1};\n\t\\node[inner]\t(2) [below of=1]\t\t{2};\n\t\\node[inner]\t(3) [below right of=0]\t{3};\n\t\\node[inner]\t(4)\t[below of=3]\t\t{4};\n\t\\node[nop]\t\t(5) [below right of=2]\t{5};\n\n\t\\path\n\t\t(0) edge[dashed]\t\tnode[above]\t{0}\t\t(1)\n\t\t(0) edge[dashed]\t\tnode[above]\t{0}\t\t(3)\n\t\t(1) edge[->]\t\t\tnode[right]\t{2}\t\t(2)\n\t\t(1) edge[->]\t\t\tnode[above]\t{2}\t\t(4)\n\t\t(3) edge[->]\t\t\tnode[right]\t{2}\t\t(4)\n\t\t(2) edge[dashed]\t\tnode[above]\t{1}\t\t(5)\n\t\t(4) edge[dashed]\t\tnode[above]\t{1}\t\t(5)\n\t\t;\n\\end{tikzpicture}\n\nWe add the following constraints\n\\begin{itemize}\n\t\\item Between 1 and 2 there are at most 3 time units\n\t\\item Between 0 and 4 there are at least 4 time units\n\\end{itemize}\n\n\\begin{tikzpicture} [node distance=1.5cm]\n\t\\tikzset{nop/.append style={minimum width=5mm}}\n\t\\tikzset{inner/.append style={minimum width=5mm}}\n\t\\node[nop]\t\t(0)\t\t\t\t\t\t{0};\n\t\\node[inner]\t(1) [below left of=0]\t{1};\n\t\\node[inner]\t(2) [below of=1]\t\t{2};\n\t\\node[inner]\t(3) [below right of=0]\t{3};\n\t\\node[inner]\t(4)\t[below of=3]\t\t{4};\n\t\\node[nop]\t\t(5) [below right of=2]\t{5};\n\n\t\\path\n\t\t(0) edge[dashed]\t\tnode[above]\t{0}\t\t(1)\n\t\t(0) edge[dashed]\t\tnode[above]\t{0}\t\t(3)\n\t\t(1) edge[->]\t\t\tnode[right]\t{2}\t\t(2)\n\t\t(1) edge[->]\t\t\tnode[above]\t{2}\t\t(4)\n\t\t(3) edge[->]\t\t\tnode[right]\t{2}\t\t(4)\n\t\t(2) edge[dashed]\t\tnode[above]\t{1}\t\t(5)\n\t\t(4) edge[dashed]\t\tnode[above]\t{1}\t\t(5)\n\t\t(2) edge[bend left, ->]\tnode[left]\t{-3}\t(1)\n\t\t(0) edge[->]\t\t\tnode[left]\t{4}\t\t(4)\n\t\t;\n\\end{tikzpicture}\n\n\\subsection{List Scheduling}\n\\begin{lstlisting}[escapeinside={(*}{*)}]\nLIST((*$V_S$*), (*$E_S$*), (*$V_R$*), (*$E_R$*), (*$\\alpha$*), (*$\\beta$*), priorities) {\n\t(*$V_T$*) = (*$V_R - V_S$*);\n\tt = 1;\n\tdo {\n\t\tforeach((*$v_k \\in V_T$*)) {\n\t\t\t(*$U_k$*) = candidates to be scheduled;\n\t\t\t(*$T_k$*) = running operations;\n\t\t\t(*$S_k$*) = subset of (*$U_k$*) with maximal priority and (*$\\abs{S_k} + \\abs{T_k} \\leq \\alpha(v_k)$*);\n\t\t\tforeach((*$v_i \\in S_k$*)) { (*$\\tau(v_i)$*) = t; }\n\t\t}\n\t\tt = t + 1;\n\t} while ((*$v_n$*) unplanned);\n}\n\\end{lstlisting}\n\n\\subsection{Integer Linear Programming}\nTo get optimal results one can use ILP. First, for each $v_i \\in V_S$ we have\nto determine $l_i$ and $h_i$, the earliest and latest starting time\nrespectively, using ASAP and ALAP with a suitable $L_{max}$. $x_{i,t} = 1 \\iff$\noperation $v_i$ starts at time $t$.\n\\begin{align*}\n\t\\min \\tau(v_n) - \\tau(v_0) &\\qquad \\text{subject to} \\\\\n\t\\forall v_i \\in V_S \\forall l_i \\leq t \\leq h_i &\\,.\\,x_{i,t} \\in \\set{0, 1} \\\\\n\t\\forall v_i \\in V_S &\\,.\\, \\sum_{t = l_i}^{h_i} x_{i,t} = 1 \\\\\n\t\\forall v_i \\in V_S &\\,.\\, \\sum_{t = l_i}^{h_i} t \\cdot x_{i,t} = \\tau(v_i) \\\\\n\t\\forall (v_i, v_j) \\in E_S &\\,.\\, \\tau(v_j) - \\tau(v_i) \\geq w(v_i) \\\\\n\t\\forall v_k \\in V_T \\forall 1 \\leq t \\leq \\max_i\\set{h_i} &\\,.\\, \\sum_{\\forall i. (v_i, v_k) \\in E_R} \\sum_{p' = \\max(0, t - h_i)}^{\\min(w(v_i) - 1, t - l_i)} x_{i, t - p'} \\leq \\alpha(v_k)\n\\end{align*}\n\n\\subsubsection{Modifications}\nTo adapt the ILP to iterative algorithms (marked graphs, pipelining), replace\n\\begin{align*}\n\t\\forall (v_i, v_j) \\in E_S &\\,.\\, \\tau(v_j) - \\tau(v_i) \\geq w(v_i) \\\\\n\t\\forall v_k \\in V_T \\forall 1 \\leq t \\leq \\max_i\\set{h_i} &\\,.\\, \\sum_{\\forall i. (v_i, v_k) \\in E_R} \\sum_{p' = \\max(0, t - h_i)}^{\\min(w(v_i) - 1, t - l_i)} x_{i, t - p'} \\leq \\alpha(v_k)\n\\end{align*}\nby\n\\begin{align*}\n\t\\forall (v_i, v_j) \\in E_S &\\,.\\, \\tau(v_j) - \\tau(v_i) \\geq w(v_i) - d_{i,j} \\cdot P\\\\\n\t\\forall v_k \\in V_T \\forall 1 \\leq t \\leq \\max_i\\set{h_i} &\\,.\\, \\sum_{\\forall i. (v_i, v_k) \\in E_R}\n\t\\sum_{p' = 0}^{w(v_i) - 1} \\sum_{\\forall p \\,.\\, l_i \\leq t - p' + p \\cdot P \\leq h_i} x_{i, t - p' + p \\cdot P} \\leq \\alpha(v_k)\n\\end{align*}\n\nand\n\n\nwhere $d_{i,j}$ is the amount of tokens on edge $(i,j)$.\n\n\\subsection{DVS ILP}\n\\begin{align*}\n\t\\min \\sum_{k \\in K} \\sum_{v_i \\in V_S} y_{ik} \\cdot e_k(v_i) &\\qquad\\text{subject to} \\\\\n\t\\forall v_i \\in V_S, k \\in K &\\,.\\, y_{ik} \\in \\set{0,1} \\\\\n\t\\forall v_i \\in V_S &\\,.\\, \\sum_{k \\in K} y_{ik} = 1 \\\\\n\t\\forall (v_i, v_j) \\in E_S &\\,.\\, \\tau(v_j) - \\tau(v_i) \\geq \\sum_{k \\in K} y_{ik} \\cdot w_k(v_i) \\\\\n\t\\forall v_i \\in V_S & \\,.\\, \\tau(v_i) + \\sum_{k \\in K} y_{ik} \\cdot w_k(v_i) \\leq d(v_i)\n\\end{align*}\nwhere $K$ is the set of voltage levels and there are no resource constraints.\n", "meta": {"hexsha": "3aa4129ce34086e1ff4b33d04f4b6bd20fb9242a", "size": 6921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "embedded systems/sections/synthesis.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/synthesis.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/synthesis.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": 39.775862069, "max_line_length": 190, "alphanum_fraction": 0.5942782835, "num_tokens": 2956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835534888478, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.605617189192895}}
{"text": "\\chapter{confcheck} \\label{confcheck}\n\n\\section{Introduction}\n\nThe \\texttt{confcheck} command perform a \\emph{confluence analysis} on the LPE in order to determine which \\istep{} summands are \\emph{confluent}\nA confluent \\istep{} summand is an \\istep{} summand with the property that the possible behavior of a system is the same up to branching bisimulation before and after the application of that summand.\n\nThe \\texttt{confcheck} command will rename confluent \\istep{}s to \\cistep{}s.\nAfterwards, the \\texttt{confelm} command can be used next in order to prioritize \\cistep{}s, which may reduce the state space.\n\n\\section{Algorithm}\n\nConsider all possible summands pairs, referencing the elements of the summands conform \\ref{summandelements}.\nSelect all pairs $(s_\\alpha, s_\\beta)$ of which $C_\\alpha$ equals \\istep{}.\n\nSince it cannot be assumed that\n\\begin{align*}\n\\{ x_1(1), \\cdots{} x_1(m_1) \\} \\cap \\{ x_2(1), \\cdots{} x_2(m_2) \\} = \\emptyset{}\n\\end{align*}\n\na substitution $X$ is introduced such that\n\\begin{align*}\nX = [ x_2(j) \\rightarrow q(x_2(j)) \\;|\\; 1 \\leq j \\leq m_2 ]\n\\end{align*}\n\nwhere $q(x)$ is a surjective function that yields fresh variables.\n\nWe also define\n\\begin{align*}\nV_{1} &= [p_j \\rightarrow v_1(p_j) \\;|\\; 1 \\leq j \\leq k] \\\\\nV_{2} &= [p_j \\rightarrow v_2(p_j)[X] \\;|\\; 1 \\leq j \\leq k]\n\\end{align*}\n\nUsing the definitions above, a particular \\istep{} summand $s_1$ is confluent if the following expression is a tautology for all pairs $(s_1, s_2)$ such that $s_2 \\neq s_1$:\n\\begin{align*}\ng_1 \\land g_2[X] \\rightarrow g_1[V_2] \\land g_2[X][V_1] \\land \\bigwedge\\limits_{j=1}^{k} p_j[V_2][V_1] = p_j[V_1][V_2]\n\\end{align*}\n\nNote that this approach does \\emph{not} yield all confluent \\istep{} summands (it is an under-approximation).\n\n\\section{Example}\n\nConsider the following example:\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A :: Int](x, y :: Int)\n  = A ? i [[x<=9 /\\ x==i]] >-> example[A](x+1, y)\n  + ISTEP [[y<=9]] >-> example[A](x, y+1)\n  ;\n\n//Initialization:\nexample[A](0, 0);\n\\end{lstlisting}\n\nLet $s_1$ be the first and $s_2$ the second summand.\nIs $s_2$ confluent?\n\nFirst, since $\\{ x_1(1), \\cdots{} x_1(m_1) \\} \\cap \\{ x_2(1), \\cdots{} x_2(m_2) \\} = \\emptyset{}$, $X$ can be ignored.\n\nSecond, if\n\\begin{align*}\ng_1 \\land g_2 \\Leftrightarrow (x \\leq 9 \\land x=i) \\land (y \\leq 9)\n\\end{align*}\n\nholds, then\n\\begin{align*}\ng_1[V_2] \\land g_2[V_1] &\\Leftrightarrow (x \\leq 9 \\land x=i)[ y \\rightarrow y+1 ] \\land (y \\leq 9)[ x \\rightarrow y+1 ] \\\\\n&\\Leftrightarrow (x \\leq 9 \\land x=i) \\land (y \\leq 9)\n\\end{align*}\n\nholds as well.\n\nThird, it is the case that\n\\begin{align*}\nx[V_1][V_2] = x+1 = x[V_2][V_1] \\\\\ny[V_1][V_2] = y+1 = y[V_2][V_1]\n\\end{align*}\n\nTherefore the confluence condition holds, which means that $s_2$ is confluent.\n\nTo store the new information about the second summand, the channel is renamed to \\cistep{}:\n\n\\begin{lstlisting}\n//Process definition:\nPROCDEF example[A :: Int](x, y :: Int)\n  = A ? i [[x<=9 /\\ x==i]] >-> example[A](x+1, y)\n  + CISTEP [[y<=9]] >-> example[A](x, y+1)\n  ;\n\n//Initialization:\nexample[A](0, 0);\n\\end{lstlisting}\n\n", "meta": {"hexsha": "c70a9b440575afaf7c340c8d3714c488293a33b7", "size": 3117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sys/lpeops/tex/lpeopsDoc/confcheck.tex", "max_stars_repo_name": "ikbendedjurre/TorXakis", "max_stars_repo_head_hexsha": "a791ce9960e88df576733404fe4d60114c35e50a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 44, "max_stars_repo_stars_event_min_datetime": "2017-06-09T08:17:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T02:17:01.000Z", "max_issues_repo_path": "sys/lpeops/tex/lpeopsDoc/confcheck.tex", "max_issues_repo_name": "ikbendedjurre/TorXakis", "max_issues_repo_head_hexsha": "a791ce9960e88df576733404fe4d60114c35e50a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 746, "max_issues_repo_issues_event_min_datetime": "2017-06-13T07:36:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T19:14:31.000Z", "max_forks_repo_path": "sys/lpeops/tex/lpeopsDoc/confCheck.tex", "max_forks_repo_name": "ikbendedjurre/txs-develop", "max_forks_repo_head_hexsha": "bc11f4b93a15e220bf6941d395d5b4cd361bfe74", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2017-11-16T11:33:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-26T16:33:36.000Z", "avg_line_length": 32.8105263158, "max_line_length": 199, "alphanum_fraction": 0.6746871992, "num_tokens": 1145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6056171872471197}}
{"text": "\\documentclass[11 pt]{scrartcl}\n\\usepackage[header, margin, koma]{tyler}\n\n\\newcommand{\\hwtitle}{Calculus and Probability Review}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyhead[l]{\\hwtitle{}}\n\\fancyhead[r]{CS 70 Staff}\n\\cfoot{\\thepage}\n\n% TODO: add a joint pdf example to the double int. section\n\n\\begin{document} \n\\title{\\Large \\hwtitle{}}\n\\author{\\large CS 70 Staff}\n\\date{\\large\\today}\n\n\\maketitle \n\nThis is a quick refresher of single and multi variable calculus in the context of probability. If any material needs refreshing, \\cite{stewart} is the canonical calculus textbook, while Khan Academy has fantastic video explanations. Finally, this is a reminder that \\textbf{calculus will not be over-emphasized on the final}; after all, this is a probability course, not a calculus course.  \n%\\tableofcontents\n\n\\section{Derivatives}\nSingle variable calculus starts with the notion of a derivative, which represents the \\emph{instantaneous} rate of change of a function $f(x)$. Formally, \n\n\\begin{definition}[Derivative]\n    The \\textbf{derivative} of a function $f(x)$ is defined to be\n    \\[ f'(x) = \\lim_{h\\to 0} \\dfrac{f(x+h)-f(x)}{h}.\\]\n    We sometimes also denote it by $\\frac{df}{dx}$ or $\\frac{d}{dx} f(x)$ to emphasize that the derivative is with respect to $x$. \n\\end{definition}\n\nThe idea is that this value gives us the slope of the secant line passing through $(x, f(x))$ and $(x+h, f(x+h))$, and as $h$ becomes smaller and smaller, the secant line becomes the tangent line at the point $x$. \n\nThis definition is seldomly used once we know the basics of dealing with derivatives though. That comes in the form of the following common forms and properties. Assume $c\\in \\RR$ is a constant. \n\n\\begin{itemize}\n    \\ii $\\frac{d}{dx} c = 0$.\n    \\ii $\\frac{d}{dx} x^n = nx^{n-1}$. \n    \\ii $\\frac{d}{dx} \\sin x = \\cos x$.\n    \\ii $\\frac{d}{dx} \\cos x = -\\sin x$.\n    \\ii $\\frac{d}{dx} e^x = e^x$ (the only such function!).\n    \\ii $\\frac{d}{dx} c^x = c^x\\ln c$.\n    \\ii $\\frac{d}{dx} \\ln x = \\frac{1}{x}$.\n\\end{itemize}\n\nOf course, derivatives add and subtract, and with the next two rules, you're ready to differentiate nearly any function you come across. \n\n\\begin{lemma}[Product Rule]\n    For any two functions $f(x)$ and $g(x)$,\n    \\[ \\dfrac{d}{dx} (f\\cdot g)(x) = f'(x) g(x) + f(x)g'(x) \\] \n    or in other words, \n    \\[ (fg)' = f'g + fg'.\\]\n\\end{lemma}\n\n\\begin{lemma}[Chain Rule]\n    Suppose I have a function $f(x) = g(h(x))$. Then \n    \\[ f'(x) = g'(h(x))\\cdot h'(x).\\] \n    Equivalently, \n    \\[ \\dfrac{df}{dx} = \\dfrac{df}{dh} \\dfrac{dh}{dx}.\\] \n\\end{lemma}\n\nIn other words, I keep unrolling my derivatives from outside in when I use the chain rule. \n\n\\begin{example}\n    Compute the derivative of $f(x) = x^2e^{2x}$.  \n\\end{example}\n\\begin{proof}[Solution]\n    Applying the product rule followed by the chain rule gives \n    \\[ f'(x) = (x^2)'e^{2x} + x^2 (e^{2x})' = 2xe^{2x} + x^2 e^{2x} (2x)' = 2xe^{2x} + 2x^2e^{2x}.\\] \n\\end{proof}\n\n\\begin{exercise}\n    Find the derivatives of the following functions: \n    \\alphanum\n        \\ii $F(x) = 5(5-x)^4$\n        \\ii $F(x) = e^{-3x}$\n        \\ii $F(x) = \\sqrt{x^3}$\n    \\enumend\n\\end{exercise}\n\n\\section{Integrals}\n\\subsection{Definitions}\nComplementing the derivative is first the \\emph{definite} integral, which represents the signed\\footnote{Meaning positive if we're above the $x$-axis and negative otherwise.} area under the curve. The nice interpretations and motivations for this come from physics, so I'll move on and give an informal definition. \n\n\\begin{definition}[Definite Integral]\n    The \\textbf{definite integral} $\\int_a^b f(x) dx$ is the signed area of the region of the $xy$-plane bounded by the graph of $f$, the $x$-axis, and the vertical lines $x = a$, $x = b$.   \n\\end{definition}\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[scale=0.5]{def_integral.png}\n    \\caption{An example of such an integral.}\n\\end{figure}\n\nIt turns out that integration and differentiation are inverse operations. So we have the notion of an \\emph{antiderivative}, a function $F$ whose derivative is a given function $f$, which is also sometimes called an \\emph{indefinite} integral. \n\n\\begin{definition}[Indefinite Integral]\n    An antiderivative $F(x)$ of $f(x)$ is called an \\textbf{indefinite integral}, and written as \n    \\[ F(x) =  \\int f(x) dx.\\] \n\\end{definition}\n\nOne important point to note is that since constants vanish under differentiation, given an antiderivative $F(x)$, any other function $F(x) + c$ where $c$ is a constant is also an antiderivative. Never forget to plus $c$! \n\nIn the midst of all this back and forth, it's still not clear at all how we'd compute the area under the curve in order to actually find the definite integral. This is where the Fundamental Theorem of Calculus comes into play; it creates the connection between the definite and indefinite integrals (and therefore between definite integrals and derivatives). \n\n\\begin{theorem}[Fundamental Theorem of Calculus]\n    If $f$ is a real-valued, integrable function on $[a,b]$, and $F$ is an antiderivative of $f$ on $[a,b]$ (so that $F' = f$), then \n    \\[ \\int_a^b f(x) dx = F(b) - F(a).\\] \n\\end{theorem}\n\nThis theorem is paramount for going back and forth between integrals and derivatives. If you think about it, this theorem is what lets us use CDFs to evaluate our pdfs. So under the surface, problems like Example~\\ref{example:ft_rv} are really using the fundamental theorem somewhere. \n\n\nHere are some common integrals you should know: \n\\begin{itemize}\n    \\ii $\\int x^n\\; dx = \\frac{x^{n+1}}{n+1} + C$ for $n \\not= -1$. \n    \\ii $\\int \\frac{1}{x}\\; dx = \\ln |x| + C$\n    \\ii $\\int e^x\\; dx = e^x + C$ \n    \\ii $\\int \\sin x\\; dx = - \\cos x + C$\n    \\ii $\\int \\cos x\\; dx = \\sin x + C$\n\\end{itemize}\n\n\\begin{example}\n    Compute $\\int_0^4 x^2 dx$. \n\\end{example}\n\\begin{proof}[Solution]\n    By inspection (or by looking at the list above) we find that an antiderivative is $F(x) = \\frac{x^3}{3}$, and so by the fundamental theorem, our answer is just $F(4) - F(0)$. Written more concisely, \n    \\[ \\int_0^4 x^2 dx = \\dfrac{x^3}{3}\\Big\\rvert^4_0 = \\dfrac{4^3}{3} - \\dfrac{0}{3} = \\dfrac{64}{3}.\\] \n\\end{proof}\n\n\\subsection{Integrating techniques: $u$-sub, integration by parts, and others}\nThere's two common techniques you'll use when solving integrals. The first is pretty simple. It's utilizing a change of variables, otherwise known as $u$-substitution. \n\n\\begin{example}\n    Compute $\\int_0^5 e^{-6x}dx$. \n\\end{example}\n\\begin{proof}[Solution]\n    This isn't an integral of one of the above forms since we have extra coefficients in the exponent, so we'll perform a change of variables to get it to look like it. Let $u = -6x$, so $du = -6 dx$ or $-\\frac 16 du = dx$. Now if we change variables, we will get an antiderivative of \n    \\[\\int e^{-6x} dx = \\int -\\frac 16 e^{u} du = -\\frac 16 e^u + C = -\\frac 16 e^{-6x} + C.\\] \n    \n    Plugging this in gives \n\\[ \\int_0^5 e^{-6x} dx = -\\frac 16 e^{-6x} \\Big\\rvert^5_0 = -\\frac 16 e^{-30} + \\frac 16 .\\]\n\\end{proof}\n\nThe second technique is \\emph{integration by parts}, which is not as straightforward. The idea is that we want to be able to integrate products of functions that aren't as nice. This reminds us of the product rule for derivatives, which states that if I had two functions $u(x)$ and $v(x)$, then \n\\[ (uv)' = u'v + uv'.\\] \n\nIntegrating both sides with respect to $x$ gives \n\\[ u(x) v(x) = \\int (u(x) v(x))' dx  = \\int u'(x) v(x) dx + \\int u(x) v'(x) dx \\]\n\nIf we use differentials and let $du = u'(x) dx$ and $dv = v'(x) dx$,\\footnote{A differential is change in the function based on the dependent variable (how far up we move based on horizontal movement and the slope).} we can write this in a format thats more recognizable, namely \n\\[ u(x) v(x) = \\int v(x) du + \\int u(x) dv \\implies \\boxed{\\int u\\; dv = uv - \\int v\\; du}.\\] \n\nSo now we can take an integral that's hard to compute, and flip around what we're integrating to make it potentially easier to simplify. It's easiest to understand through an example. \n\n\\begin{example}\n    Compute $\\int xe^{3x}\\; dx$. \n\\end{example}\n\\begin{proof}[Solution]\n    If I'm applying integration by parts, I need to find one expression to take the derivative of (which will be $u$) and another to take the integral of (which will be $dv$) to simplify. Here, I'll let $u = x$ and $dv = e^{3x} dx$, so that $du = dx$ and $v = \\frac 13 e^{3x}$. Then applying integration by parts gives \n    \\[ \\int xe^{3x} = \\int u\\; dv = uv - \\int v\\; du = \\frac 13 xe^{3x} - \\int \\frac 13 e^{3x} dx = \\frac 13 xe^{3x} - \\frac 19 e^{3x} + C.\\] \n\\end{proof}\n\nIt's not always obvious what I should be setting $u$ and $dv$ to typically. A good rule of thumb is to set $u$ to the first term you see in this list: \n\\begin{itemize}\n    \\ii Logarithm \n    \\ii Inverse trig function \n    \\ii Algebraic function (e.x. polynomials)\n    \\ii Trig function \n    \\ii Exponential function\n\\end{itemize}\n\nHere's another example. \n\\begin{example}\n    Compute $\\int \\ln x \\; dx$.  \n\\end{example}\n\\begin{proof}[Solution]\n    You might think that we can't apply integration by parts here since we only have one term. But in fact, let $u = \\ln x$ and $dv = dx$ so that $du = \\frac{1}{x} dx$ and $v = x$. Then \n    \\[ \\int \\ln x\\; dx = \\int u \\; dv = uv - \\int v\\; du = x\\ln x - \\int x\\cdot \\frac{1}{x} \\; dx = x\\ln x - x + C.\\] \n\\end{proof}\n\nYou should also search for the tabular method if you want to speed things up when doing multiple integrations by parts (Khan academy is a good place to watch). \n\n\\begin{exercise}\n    Compute $\\int x^2e^{3x}\\; dx$. \n\\end{exercise}\n\n\\section{Series}\nA quick informal definition so everyone's on the same page here. \n\n\\begin{definition}[Series]\n    Given some sequence of terms $(a_1, a_2, \\dots, a_n)$, the \\textbf{series} corresponding to this sequence is the sum \n    \\[ a_1 + a_2 + \\dots + a_n.\\] \n    If the sequence is infinite, then the series will contain infinitely many summands. \n\\end{definition}\n\nSeries come up often in discrete probability when we ask what the probability of some range of events is. So it's useful to know how to sum the two main types of series and some tricks we can do with them. \n\nThere's two main series to know: the geometric series, and the Taylor series.\n\nIn a geometric series, we have an initial term $a$, and every term after that is some common ratio, $r$, times the previous terms. So a typical finite geometric series looks something like \n\n\\[ S = a + ar + ar^2 + \\dots + ar^k\\] \n\nwhere $S$ is the final value of the series. To calculate this, notice that \n\n\\[ rS = ar + ar^2 + \\dots + ar^k + ar^{k+1},\\] \n\nso if we subtract one from the other, all the middle terms cancel out, leaving us with \n\n\\[ S - rS = a - ar^{k+1} \\implies \\boxed{S = \\dfrac{a(1-r^{k+1})}{1-r}}.\\] \n\n\nIf we take $k \\to \\infty$, then we get an infinite geometric series, for which \n\\[ \\sum_{i=0}^\\infty ar^i = \\dfrac{a}{1-r}\\] \n\nbut only when $|r| < 1$ (otherwise the series won't converge). Here's an example that utilizes geometric series for a very fitting distribution.\n\\begin{example}\n    Show that the sum of the probabilities of a random variable $X \\sim \\Geo(p)$ is 1. \n\\end{example}\n\\begin{proof}[Solution]\n    Recall that $\\PP(X = k) = (1-p)^{k-1} p$. Then \n    \\[ \\sum_{k=1}^\\infty \\PP(X=k) = \\sum_{k=1}^\\infty (1-p)^{k-1} p.\\] \n    But this is a \\emph{geometric} series with initial term $p$ and ratio $1-p$, so the sum is $\\frac{p}{1-(1-p)} = 1$. \n\\end{proof}\n\nThe idea of a Taylor series is to approximate a function $f(x)$ by its derivatives. This looks like \n\n\\[ f(x) = f(0) + f'(0)x + \\dfrac{1}{2!} f''(0) x^2 + \\dfrac{1}{3!} f'''(0)x^3 + \\dots = \\sum_{k=0}^\\infty \\dfrac{1}{k!}f^{(k)}(0)x^k\\] \n\nwhere $f^{(k)}$ is the $k$th derivative of $f$. The only one you'll need for this class is $e^x$: \n\n\\[ e^x = 1 + x + \\dfrac{x^2}{2!} + \\dfrac{x^3}{3!} + \\dots = \\sum_{k=0}^\\infty \\dfrac{x^k}{k!}.\\] \n\nOne last interesting note is that geometric series are \\emph{also} Taylor series. If we let $f(r) = \\frac{a}{1-r}$, then the derivatives are \n\n\\[ f(r) = \\frac{a}{1-r}, \\quad\\quad f'(r) = \\frac{a}{(1-r)^2}, \\quad\\quad f''(r) = 2!\\cdot\\frac{a}{(1-r)^3}, \\quad\\dots,\\quad f^{(k)}(r) = k!\\cdot \\dfrac{a}{(1-r)^{k+1}} \\]\n\nso \n\n\\[ f(0) = a, \\quad\\quad f'(0) = 1!\\cdot a, \\quad\\quad f''(0) = 2!\\cdot a, \\quad\\dots,\\quad f^{(k)}(0) = k!\\cdot a.\\]\n\nPlugging this into the Taylor series expansion gives \n\n\\[ f(r) = \\dfrac{a}{1-r} = a + ar + ar^2 + \\dots\\]\n\nwhich is the geometric distribution as expected. \n\n\\begin{exercise}\n    Show that the sum of the probabilities of a Poisson random variable $X\\sim \\text{Poisson}(\\lambda)$ is 1. \n\\end{exercise}\n\n\\section{Intermission: Calculus and Series in Probability}\nNow that we've covered some calculus, let's look at how the different results we've seen so far are used in probability. \n\nHere's two problems that make use of the Taylor series for $e^x$. \n\\begin{example}[Dis 12 \\#3]\n    Let $X \\sim \\Geo(p)$ and $Y \\sim \\Poisson(\\lambda)$ be independent random variables. Compute $\\PP(X > Y)$. \n\\end{example}\n\\begin{proof}[Solution]\n    Let's condition on $Y$ so that we can use $\\PP(X > k) = (1-p)^k$. This gives \n    \\begin{align*}\n        \\PP(X > Y) &= \\sum_{y=0}^\\infty \\PP(Y=y) \\PP(X > y | Y = y) \\\\ \n                   &= \\sum_{y=0}^\\infty \\dfrac{e^{-\\la}\\la^y}{y!}\\cdot (1-p)^y \\\\ \n                   &= e^{-\\la}\\sum_{y=0}^\\infty \\dfrac{(\\la(1-p))^y}{y!} \n    \\end{align*}\n    But this sum is the Taylor series for $e^{\\la(1-p)}$, so the probability is just $e^{-\\la}e^{\\la-\\la p} = e^{-\\la p}$. \n\\end{proof}\n\nThis somewhat surprising result was derived in Lecture 21. \n\\begin{example}\n    Let $X_n$ be a random variable counting the number of fixed points of a permutation on $n$ variables. What is the distribution of $X_n$ as $n\\to\\infty$?  \n\\end{example}\n\\begin{proof}[Solution]\n    We wish to compute $\\PP(X_n = j)$, so we count the number of permutations with $j$ fixed points. We need to choose $j$ points to be fixed and the rest to not have any fixed points, which means they form a derangment, so there are $\\binom{n}{j}D_{n-j}$ such permutations. Hence \n    \\[ \\PP(X_n = j) = \\dfrac{\\binom{n}{j}  D_{n-j}}{n!}.\\]\n\n    Recalling that $D_j = j!\\sum_{k=0}^j \\frac{(-1)^k}{k!}$, we find \n    \\begin{align*}\n        \\PP(X_n = j) &= \\dfrac{1}{n!}\\left[ \\dfrac{n!}{j!(n-j)!} (n-j)! \\sum_{k=0}^{n-j}\\dfrac{(-1)^k}{k!}\\right] \\\\ \n                     &= \\dfrac{1}{j!} \\sum_{k=0}^{n-j}\\dfrac{(-1)^k}{k!}.\n    \\end{align*}\n    But when $n\\to\\infty$, this is the Taylor Series for $e^{-1}$, so \n    \\[ \\lim_{n\\to\\infty} \\PP(X_n = j) = \\frac{e^{-1} 1^j }{j!} \\] \n    which is the pdf of a $\\Poisson(1)$ distribution. \n\\end{proof}\nThis result also agrees with the fact that $\\EE[X_n] = 1$, which is true by linearity of expectation.  \n\nHere's an idea similar to Discussion 13, Problem 2 but in a different context. Under the hood, you should realize that we can do this cdf manipulation thanks to the Fundamental Theorem of Calculus. \n\\begin{example}\n    Let $X, Y$ be a random variables where $Y = X^2$. Express the pdf of $Y$, $f_Y$, in terms of the pdf of $X$, $f_X$.   \n    \\label{example:ft_rv}\n\\end{example}\n\\begin{proof}[Solution]\n    The first step should usually be to compute the cdf of $Y$ in terms of $X$'s cdf. This gives \n    \\[ F_Y(x) = \\PP(Y \\leq x) = \\PP(X^2 \\leq x) = \\PP(-\\sqrt{x} \\leq X \\leq \\sqrt{x}) = F_X(\\sqrt{x}) - F_X(-\\sqrt{x}).\\] \n    From here, we differentiate with respect to $X$ (being careful to use the chain rule) and get \n    \\[ f_Y(x) = \\dfrac{dF_Y}{dx} = \\dfrac{1}{2\\sqrt{x}}F_X'(\\sqrt{x}) - \\left(-\\dfrac{1}{2\\sqrt{x}}\\right)F_X'(-\\sqrt{x}) \n    = \\dfrac{1}{2\\sqrt{x}} (f_X(\\sqrt{x})+f_X(-\\sqrt{x})) \\]\n\n\\end{proof}\n\n\\section{Double Integrals}\nNow we're finally talking about multivariable calculus. Before we start, we should ask the question: what even is a double integral? \n\nWe should first think about what a single integral represented. In summary, we defined it as \n\\[ \\boxed{\\text{Finding an \\textcolor{blue}{area} under } f(x) \\text{ over a \\textcolor{blue}{one-dim. interval} } {\\color{blue} [a,b]} \\text{ on the } {\\color{blue} x \\text{-axis: }} A = \\int_a^b f(x) \\; dx.}\\] \n\nThe double integral will be the natural generalization of this. Instead of integrating an area over an interval, we will be integrating a volume over a region in 2D space. \n\\[ \\boxed{\\text{Finding a \\textcolor{red}{volume} under } f(x,y) \\text{ over a \\textcolor{red}{two-dim. region} } {\\color{red} \\mathcal{R}} \\text{ on the } {\\color{red} xy \\text{-plane: }} V = \\iint_\\mathcal{R} f(x,y) \\; dA.}\\] \n\nThe hardest part of solving double integrals is often figuring out the region of integration and setting up the limits. After that, it's just single-variable calculus. Let's look at an example. \n\n\\begin{example}\n    Integrate $f(x,y) = x^2 + y^2$ over the $4\\times 4$ square centered at $(0,0)$. \n\\end{example}\n\\begin{proof}[Solution]\nBefore we begin, take a look at this visualization of our integral. \n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[scale=0.5]{x2y2.jpeg}\n    \\caption{A visualization of the integral of $f(x,y) = x^2 + y^2$ over the square $[-2,2]\\times [-2,2]$.}\n\\end{figure}\n\nAs you can tell, we're looking for the volume under the curve. Our region of integration is the region bounded by the lines $x = -2, x = 2, y = -2, y = 2$. \n\nThere's two ways in which we can integrate over this region: we can either integrate with respect to $x$ first, or with respect to $y$ first. Either way is the same in this case since everything is symmetric, so I'll set it up as the former. \n    This means our integral is \n\\[ \\int_{-2}^2 \\int_{-2}^2 x^2+y^2 \\; dx \\; dy.\\]\n\nIn order to integrate this, we treat the inside integral like a single integral and treat everything that's not $x$ like a constant. This gives \n\n\\[ \\int_{-2}^2 \\int_{-2}^2 x^2+y^2 \\; dx \\; dy = \\int_{-2}^2 \\left(\\frac{x^3}{3}+xy^2\\right)\\Big\\rvert^2_{x=-2} \\; dy = \\int_{-2}^2 \\frac{16}{3} + 4y^2 \\; dy\\]\n\nNow that we've gotten rid of our $x$ variable (as expected), all that's left is to finish the single integral, which gives us \n\n\\[ \\int_{-2}^2 \\frac{16}{3} + 4y^2 \\; dy = \\left(\\frac{16}{3}y + \\frac{4}{3} y^3\\right)\\Big\\rvert^{2}_{-2} = \\frac{128}{3}.\\]\n\\end{proof}\n\nHere's one where the region of integration is trickier. \n\n\\begin{example}\n    Integrate $ye^{-x}$ over the \\emph{triangle} enclosed by $y = x$, $y = 3$, and $x = 0$. \n    \\label{ex:ye-x}\n\\end{example}\n\\begin{proof}[Solution]\n    \\begin{figure}[!htb]\n        \\centering\n        \\begin{minipage}{0.45\\linewidth}\n            \\includegraphics[scale=0.35]{boundary.png}\n        \\end{minipage}%\n        \\begin{minipage}{0.45\\linewidth}\n            \\includegraphics[scale=0.45]{ye-x.png}\n        \\end{minipage}%\n        \\caption{The boundary and the integral of $f(x,y) = ye^{-x}$ over the region in Example~\\ref{ex:ye-x}.}\n    \\end{figure}\n\n    We already know the region is a triangle, but we need to figure out how to integrate over it. If we first integrate over $y$ then $x$, then the limits of our outer integral should go from $0$ to 3. In this case, we then have the variable $x$ to work with to set up our limits for $y$. Using the equations, we find that we should integrate from $x$ to $3$. Setting up our integral and simplifying gives \n\n    \\begin{align*}\n    \\int_0^3 \\int_x^3 ye^{-x} \\; dy \\; dx &= \\int_0^3 \\frac 12 (y^2 e^{-x})\\Big\\rvert^3_{y = x} \\; dx \\\\ \n                                          &= \\frac 12 \\int_0^3 9e^{-x} - x^2e^{-x}\\; dx\n    \\end{align*}\n    \n    which would require the use of \\emph{two} integrations by parts to evaluate; yuck! Let's see what happens if we set up our integral the other way. The outer limits are still from 0 to 3, but the inner ones are now from 0 to $y$ (convince yourself of this), so the integral is \n    \\begin{align*}\n    \\int_0^3 \\int_0^y ye^{-x} \\; dx \\; dy &= \\int_0^3  (-y e^{-x})\\Big\\rvert^y_{x = 0} \\; dy  = \\int_0^3 -y e^{-y} + y \\; dy \\\\ \n                                          &= \\int_0^3 y \\; dy - \\left(-ye^{-y}\\Big\\rvert^3_0 + \\int_0^3 e^{-y}\\; dy \\right) \\\\ \n                                          &= \\frac{9}{2} - (-3e^{-3} + 1 - e^{-3}) = \\boxed{\\frac{7}{2} + \\frac{4}{e^3}}.\n    \\end{align*}\n\\end{proof}\n\nWe don't always have to integrate using $x$ and $y$ though. Sometimes it's more natural for us to use \\emph{polar} coordinates where we label every point as $(r, \\theta)$, $r$ being its distance from the origin and $\\theta$ being its angle with the $x$-axis. \n\n\\begin{example}\n    Integrate $f(x,y) = x^2 + y^2$ over the circle of radius $2$ centered at $(0,0)$. \n\\end{example}\n\\begin{proof}[Solution]\n    The first step is to translate our function in terms of $r$ and $\\theta$. We know that $x^2 + y^2 = r^2$, so $f(r, \\theta) = r^2$. Our region is $0\\leq r \\leq 2$, so our integral is \n\n\\[ \\int_{0}^{2\\pi} \\int_{0}^2 r^2 \\; dr\\; d\\theta = \\int_0^{2\\pi} \\frac{r^3}{3} \\Big\\rvert^2_{r=0} \\; d\\theta = \\int_0^{2\\pi} \\frac{8}{3} \\; d\\theta = \\dfrac{16}{3}\\pi.\\] \n\\end{proof}\nWe did something similar with Buffon's needle, where we integrated with respect to $y$ and $\\theta$. All that matters is that we find the appropriate regions and limits to integrate over. \n\n\\begin{exercise}\n    Integrate $e^{x+y}$ over the rectangular region determined by the lines $y = 0$, $x = 0$, $y = 3$, $x = 2$. \n\\end{exercise}\n\\begin{exercise}\n    Integrate $-\\frac{xe^x}{y^2}$ over the region defined by the lines $x = 5$, $y = -x$, $y = x$. \n\\end{exercise} \n\\begin{exercise}\n    Suppose $X \\sim \\Exp(\\la_1), Y \\sim \\Exp(\\la_2)$ are independent exponential distributions so that $f(x,y) = \\la_1\\la_2 e^{-(\\la_1+\\la_2)x}$ for $x, y \\geq 0$ is the density of their joint distribution. \n    Show that the integral of this density is 1. % over its support.\\footnote{The \\emph{support} a function $f$ are all inputs where its nonzero. For example, the support of a uniform random variable on $[a,b]$ is just $[a,b]$.}\n\\end{exercise}\n\n%\\section{Joint Densities of Continuous Random Variables}\n\n\n\\begin{thebibliography}{12}\n\t\\bibitem{stewart}\n\t\tJames Stewart, \\textit{Calculus 7 ed}. Cengage Learning, 2012. \n\\end{thebibliography}\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "06bb6f08afd600b4095182aab4d5be3af67cd51a", "size": 22161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CS70/calc_review/calc_review.tex", "max_stars_repo_name": "cbugwadia32/course-notes", "max_stars_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-07-20T19:22:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T01:19:16.000Z", "max_issues_repo_path": "CS70/calc_review/calc_review.tex", "max_issues_repo_name": "cbugwadia32/course-notes", "max_issues_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CS70/calc_review/calc_review.tex", "max_forks_repo_name": "cbugwadia32/course-notes", "max_forks_repo_head_hexsha": "cc269a2606bab22a5c9b8f1af23f360fa291c583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-13T08:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-07T17:21:17.000Z", "avg_line_length": 53.9197080292, "max_line_length": 406, "alphanum_fraction": 0.6497901719, "num_tokens": 7351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6056171822813589}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\begin{document}\n\n\\title{APPM 5510 HW2}\n\\author{Zane Jakobs}\n\\date{}\n\\maketitle\n\n\\subsection*{1(a)} \nThe Bayesian update for the mean of this linear process can be obtained from the Kalman gain matrix\n\\[\n\\begin{aligned}\nK &= BH^T(HBH^T + \\gamma^2)^{-1}\\\\\n&= \\dfrac{1}{\\sigma_1^2 + \\gamma^2} \\begin{pmatrix}\\sigma_1^2 \\\\ \\sigma_1\\sigma_2 r\\end{pmatrix}, \\\\\n\\end{aligned}\n\\]\nwhose action we then apply to the observation error term, \n\\[\n\\begin{aligned}\n\\epsilon &= y - H\\mathbf{\\mu}\\\\\n&= y - \\mu_1.\n\\end{aligned}\n\\]\nThus, the Bayesian update is \n\\[\n\\begin{aligned}\n\\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} \\to \\ & \\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} + K\\epsilon\\\\\n\t\t\t&= \\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} + \\dfrac{(y-\\mu_1)}{\\sigma_1^2 + \\gamma^2} \\begin{pmatrix}\\sigma_1^2 \\\\ \\sigma_1\\sigma_2 r\\end{pmatrix}.\n\\end{aligned}\n\\]\n\\subsection*{1(b)} If $r = 0$, then the posterior mean is\n\\[\n\\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} + \\dfrac{\\sigma_1^2(y-\\mu_1)}{\\sigma_1^2 + \\gamma^2} \\begin{pmatrix}1 \\\\ 0\\end{pmatrix},\n\\]\nand the unobserved variable that is now uncorrelated with the observed variable is not updated at all.\n\\subsection*{1(c(1))} As the measurement variance $\\gamma$ goes to infinity, the posterior mean approaches the prior mean, with their difference going to zero as $O(\\frac{1}{\\gamma^2})$. This makes sense; as the measurement variance gets larger, we should \"trust\" the observation less, and hence update our beliefs less. \n\\subsection*{1(c(2))} As the measurement variance goes to zero, the posterior mean becomes\n\\[\n\\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} + \\dfrac{(y-\\mu_1)}{\\sigma_1^2} \\begin{pmatrix}\\sigma_1^2 \\\\ \\sigma_1\\sigma_2 r\\end{pmatrix},\n\\]\nand thus the magnitude of the update to the mean depends on only on how uncertain we think the random variable is to begin with, as having zero observation error is essentially equivalent to directly sampling from the random variable.\n\n\\subsection*{1(c(3))} In this limit, the posterior mean is \n\\[\n\\begin{pmatrix}\\mu_1 \\\\ \\mu_2 \\end{pmatrix} + \\dfrac{(y-\\mu_1)}{\\sigma_1^2 + \\gamma^2} \\begin{pmatrix}1 \\\\ r\\end{pmatrix},\n\\]\nso the magnitude of the update goes to zero linearly as $\\sigma_1^2$ and $\\sigma_2^2$ go to infinity.\n\n\\subsection*{2} First, the restriction that $X_a$ has mean $x$ implies that $x = \\alpha x + \\beta x\\implies \\ \\alpha = 1-\\beta.$ We now want to minimize $\\mathrm{Var}(X_a) = \\alpha^2 \\mathrm{Var}(X_b) + \\beta^2 \\mathrm{Var}(Y) = (1-\\beta)^2\\sigma_x^2 + \\beta^2\\sigma_y^2$ subject to that constraint. We differentiate w.r.t. $\\beta$ and set the expression equal to zero to get\n\\[\n0 = \\dfrac{\\partial\\mathrm{Var}(X_a)}{\\partial\\beta} = -2(1-\\beta)\\sigma_x^2 + 2\\beta\\sigma_y^2,\n\\]\nwhich reduces to \n\\[\n\\dfrac{\\beta}{1-\\beta} = \\dfrac{\\sigma_x^2}{\\sigma_y^2} \\implies \\ \\beta = \\dfrac{\\sigma_x^2/ \\sigma_y^2}{1+\\frac{\\sigma_x^2}{\\sigma_y^2}} = \\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2},\n\\]\n\nand then $\\alpha = 1 - \\beta = 1 -  \\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2}$. Thus,\n\n\\[\nX_a  \\left( 1 - \\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2}\\right) X_b +  \\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2} Y.\n\\]\nThe variance of $X_a$ can be obtained from the fact that \n\\[\n\\begin{aligned}\n\\mathrm{Var}(X_a) &= \\alpha^2\\mathrm{Var}(X_b) + \\beta^2 \\mathrm{Var}(Y)\\\\\n&= \\left( 1 - \\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2}\\right)^2 \\sigma_x^2 + \\left(\\dfrac{\\sigma_x^2}{\\sigma_y^2 + \\sigma_x^2}\\right)^2\\sigma_y^2.\n\\end{aligned}\n\\]\n\n\\subsection*{3(a)} Bayes' theorem gives us that the posterior pdf $[X | y]$ is (a constant times) $[y | x][X]$, which are easily obtained quantities. Specifically, we have \n\\[\n[y | x] = \\exp(- |y - x - 1|)/2\n\\]\nfrom the definition of $Y$, and the following prior on $X$:\n\\[\n[X] = \\dfrac{1}{c}\\exp(-\\frac{(x - \\mu)^2}{\\sigma_x^2}).\n\\]\nThis gives us the posterior distribution \n\\[\n\\begin{aligned}\n[X | y] &= \\dfrac{1}{c} \\exp(- |y - x - 1|)\\exp(-\\frac{(x - \\mu)^2}{\\sigma_x^2})\\\\\n&= \\dfrac{1}{c}\\exp\\left(-\\frac{(x - \\mu)^2}{\\sigma_x^2} - |y - x - 1|\\right).\n\\end{aligned}\n\\]\n\n\\subsection*{3 (b)} We seek to maximize $\\exp\\left(-\\frac{x^2}{2} - |0.2 - x |\\right)$ over $x$, which is obtained when the absolute value of the quantity in the exponent, $-\\frac{x^2}{2} - |0.2 - x |$ (which is clearly negative definite), is minimized. This happens at $x = 0.2$, with can be justified either by noting that, since $x^2$ grows faster than $x$ when $|x| >> 0$, and slower than $x$ when $|x|\\approx 0$, the minimum is obtained at the zero of the absolute value, or by numerically (or even symbolically!) maximizing with Mathematica (or whatever your preferred symbolic optimization software is). \n\n\\end{document}\n", "meta": {"hexsha": "9342cbaf6a61c6cebd435fc74840e65e2610b578", "size": 4732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW-Text/5510-hw-2.tex", "max_stars_repo_name": "DiffeoInvariant/Data-Assimilation", "max_stars_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_stars_repo_licenses": ["MIT"], "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-Text/5510-hw-2.tex", "max_issues_repo_name": "DiffeoInvariant/Data-Assimilation", "max_issues_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_issues_repo_licenses": ["MIT"], "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-Text/5510-hw-2.tex", "max_forks_repo_name": "DiffeoInvariant/Data-Assimilation", "max_forks_repo_head_hexsha": "7afe25b1efb87a6988bea6df34e17650d9eb86fa", "max_forks_repo_licenses": ["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.4347826087, "max_line_length": 611, "alphanum_fraction": 0.6715976331, "num_tokens": 1703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.6056171807966965}}
{"text": "\\documentclass{article}\n\n% to avoid loading the natbib package, add option nonatbib:\n% \\usepackage[nonatbib]{style}\n\n\\usepackage[final]{style}\n\n\\usepackage[utf8]{inputenc} % allow utf-8 input\n\\usepackage[T1]{fontenc}    % use 8-bit T1 fonts\n\\usepackage{hyperref}       % hyperlinks\n\\usepackage{url}            % simple URL typesetting\n\\usepackage{booktabs}       % professional-quality tables\n\\usepackage{amsfonts}       % blackboard math symbols\n\\usepackage{nicefrac}       % compact symbols for 1/2, etc.\n\\usepackage{microtype}      % microtypography\n\\usepackage{verbatim}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\title{Linear Algebra Primer Part 2}\n\n% The \\author macro works with any number of authors. There are two\n% commands used to separate the names and addresses of multiple\n% authors: \\And and \\AND.\n%\n% Using \\And between authors leaves it to LaTeX to determine where to\n% break the lines. Using \\AND forces a line break at that point. So,\n% if LaTeX puts 3 of 4 authors names on the first line, and the last\n% on the second line, try using \\AND instead of \\And before the third\n% author name.\n\n\\author{\n  Liangcheng Tao, Vivian Hoang-Dung Nguyen, Roma Dziembaj, Sona Allahverdiyeva \\\\\n  Department of Computer Science\\\\\n  Stanford University\\\\\n  Stanford, CA 94305 \\\\\n  \\texttt{\\{lctao13, vnguyen2, romad, sonakhan\\}@cs.stanford.edu} \\\\\n}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Vectors and Matrices Recap}\n\\subsection{Vector}\nA column vector $\\textbf{v} \\in {\\rm I\\!R^{nx1}}$ where $$ \\textbf{v} = \\begin{bmatrix}\n    v_1 \\\\\n    v_2 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{bmatrix}\n $$\n\\newline\nA row vector $\\textbf{v}^T \\in {\\rm I\\!R^{1xn}}$ where $$ \\textbf{v}^T = \\begin{bmatrix}\n    v_1 & v_2 & \\cdots & v_n\n  \\end{bmatrix}\n $$\n\\newline\n$T$ denotes the transpose operation.\n\\newline\n\\newline\nThe $\\textbf{norm}$ is $$||x||_2 = \\sqrt{\\sum_{i=1}^{n} x_i^2}$$\nFormally, the norm can also be defined as any function $f:{\\rm I\\!R^{n}} \\mapsto {\\rm I\\!R}$ that satisfies 4 properties:\n\\begin{itemize}\n\\item \\textbf{Non-negativity:} For all $x \\in {\\rm I\\!R^{n}}$, $f(x) \\geq 0$\n\\item \\textbf{Definiteness:} $f(x) = 0$ if and only if $x = 0$\n\\item \\textbf{Homogeneity:} For all $x \\in {\\rm I\\!R^{n}}$, $t \\in {\\rm I\\!R}$, $f(tx) = |t|f(x)$\n\\item \\textbf{Triangle inequality:} For all $x,y \\in {\\rm I\\!R^{n}}$, $f(x+y) \\leq f(x) + f(y)$\n\\end{itemize}\n\\subsubsection{Projection}\nA \\textbf{projection} is an inner product (dot product) of vectors. If $B$ is a unit vector, then $A \\cdot B$ gives the length of $A$ which lies in the direction of $B$.\n\\subsection{Matrix}\nA matrix $\\textbf{A} \\in {\\rm I\\!R^{mxn}}$ is an array of numbers with size $m$ by $n$.\n$$ \\textbf{A} = \\begin{bmatrix}\n    a_{11} & a_{12} & a_{13} & \\cdots & a_{1n} \\\\\n    a_{21} & a_{22} & a_{23} & \\cdots & a_{2n} \\\\\n    \\vdots & & & & \\vdots \\\\\n    a_{m1} & a_{m2} & a_{m3} & \\cdots & a_{mn}\n  \\end{bmatrix}\n$$\n\\newline\nIf $m=n$, we say that $\\textbf{A}$ is square.\n\\subsubsection{An Application of Matrices}\nGrayscale images have one number per pixel and are stored as an $m\\times n$ matrix. Color images have 3 numbers per pixel - red, green, and blue \\section{Transformation Matrices}\nMatrices can be\tused to transform vectors in useful ways, through multiplication:\n$x’= Ax$. The simplest application of that is through scaling, or multiplying a scaling matrix with scalars on its diagonal by the vector.\n\nWe can also use matrices to rotate vectors. When we multiply a matrix and a vector; the resulting $x$ coordinate is the original vector \\textbf{dot} the first row.\n\n\nIn order to rotate a vector by an angle $\\theta$, counter-clockwise:\n\n$x'= cos\\theta x -sin \\theta y$ and\n\n$y'= cos\\theta y +sin \\theta x$\n\ntherefore, we multiply it by the matrix\n\n\\[\nM=\n  \\begin{bmatrix}\n    cos\\theta & -sin\\theta \\\\\n    sin\\theta & cos\\theta\n  \\end{bmatrix}\n\\]\n\nwhich gives us that $P'= R P$.\n\nWe can also use multiple matrices to transform a point. For example, $p' = R_2 R_1 S p$. The transformations are applied one after another, from right to left. In our example, this would be $(R_2(R_1(S p)))$.\n\nIn order to translate vectors, we have to implement a somewhat hacky solution of adding a \"1\" at the very end of the vector. This way, using these \"homogeneous coordinates\", we can also translate vectors. The multiplication works out so the rightmost column of our matrix gets added to the respective coordinates. $A$ homogenous matrix will have [0 0 1] in the bottom row to ensure that the elements get added correctly, and the resulting vector has '1' at the bottom.\n\nBy convention, in homogeneous coordinates, we divide the result by its last coordinate after doing matrix multiplication.\n\n\\[\n  \\begin{bmatrix}\n    x \\\\\n    y \\\\\n    7\n  \\end{bmatrix}\n\\]\n\n\\[\n    \\begin{bmatrix}\n    x/7 \\\\\n    y/7 \\\\\n    1\n  \\end{bmatrix}\n  \\]\n\nSo to obtain the result of\n$P(x,y) -> P' = (s_x x, s_y y)$\n\nwe have to first $P = (x, y) -> (x,y,1)$ and then $P' = (s_x x, s_y y) -> (s_x x, s_y y, 1)$ so we can then do the matrix multiplication S*P. Though, we have  to note that scaling and translating is not the same as translating and scaling. In other words, $T*S*P \\neq S*T*P$\n\nAny rotation matrix R belongs to the category of normal matrices, and it satisfies interesting properties. For example, $R \\dot R^T = I$ and $det(R) = 1$\n\nThe rows of a rotation matrix are always mutually perpendicular (a.k.a. orthogonal) unit vectors; this is what allows for it to satisfy some of the few unique properties mentioned above.\n\n\\section{Matrix Inverse}\nGiven a matrix $A$, its inverse $A^{-1}$ is a matrix such that:\n$$AA^{-1} = A^{-1}A = I$$\nwhere $I$ is the identity matrix of the same size.\n\nAn example of a matrix inverse is:\n$$\n  \\begin{bmatrix}\n    2 & 0 \\\\\n    0 & 3 \\\\\n  \\end{bmatrix}^{-1}\n  =\n  \\begin{bmatrix}\n    \\frac{1}{2} & 0 \\\\\n    0 & \\frac{1}{3} \\\\\n  \\end{bmatrix}\n$$\n\nA matrix does not necessarily have an inverse. If $A^{-1}$ exists, $A$ is known as \\textit{invertible} or \\textit{non-singular}.\n\nSome useful identities for matrices that are invertible are:\n\\begin{itemize}\n\\item $(A^{-1})^{-1} = A$\n\\item $(AB)^{-1} = B^{-1}A^{-1}$\n\\item $A^{-T} \\triangleq (A^T)^{-1} = (A^{-1})^T$\n\\end{itemize}\n\n\\subsection{Pseudoinverse}\n\nFrequently in linear algebra problems, you want to solve the equation $AX=B$ for $X$. You would like to compute $A^{-1}$ and multiply both sides to get $X=A^{-1}B$. In python, this command would be: np.linalg.inv(A)*B.\n\nHowever, for large floating point matrices, calculating inverses can be very expensive and possibly inaccurate. An inverse could also not even exist for $A$. What should we do?\n\nLuckily, we have what is known as a \\textit{pseudoinverse}. This other matrix can be used to solve for $AX=B$. Python will try many methods, including using the pseudo-inverse, if you use the following command: np.linalg.solve(A,B). Additionally, using the pseudo-inverse, Python finds the closest solution if there exists no solution to $AX=B$.\n\n\\section{Matrix Rank}\n\\begin{itemize}\n\\item The rank of a transformation matrix  $A$ tells you how many dimensions it transforms a matrix to.\n\n\\item col-rank($A$) = maximum number of linearly independent column vectors of $A$\n\n\\item row-rank($A$) = maximum number of linearly independent row vectors of $A$.\nColumn rank always equals row rank.\n\n\\item For transformation matrices, the rank tells you the dimensions of the output.\n\n\\item For instance, if rank of $A$ is $1$, then the transformation $p' =Ap$ points onto a line.\n\n\\item Full rank matrix- if $mxm$ and rank is $m$\n\n\\item Singular matrix- if $mxm$ matrix rank is less than $m$, because at least one dimension is getting collapsed. (No way to tell what input was from result) --> inverse does not exist for non-square matrices.\n\\end{itemize}\n\n\\section{Eigenvalues and Eigenvectors (SVD)}\n\n\\subsection{Definitions}\nAn \\textit{eigenvector} \\textbf{x} of a linear transformation $A$ is a non-zero vector that, when $A$ is applied to it, does not change its direction.\nApplying $A$ to the eigenvector scales the eigenvector by a scalar value $\\lambda$, called an \\textit{eigenvalue}.\n\nThe following equation describes the relationship between eigenvalues and eigenvectors:\n$$A\\mathbf{x}=\\lambda \\mathbf{x}, \\quad \\mathbf{x}\\neq \\mathbf{0}$$\n\n\\subsection{Finding eigenvectors and eigenvalues}\nIf we want to find the eigenvalues of $A$, we can manipulate the above definition as follows:\n\n$$A\\mathbf{x}=\\lambda \\mathbf{x}, \\quad \\mathbf{x}\\neq \\mathbf{0}$$\n$$A\\mathbf{x}=(\\lambda I \\mathbf{x}), \\quad \\mathbf{x}\\neq \\mathbf{0}$$\n$$(\\lambda I-A)\\mathbf{x}=\\mathbf{0}, \\quad \\mathbf{x}\\neq \\mathbf{0}$$\n\nSince we are looking for non-zero \\textbf{x}, we can equivalently write the above relation as:\n\n$$|\\lambda I-A|=\\mathbf{0}$$\n\nSolving this equation for $\\lambda$ gives the eigenvalues of A, and these can be substituted back into the original equation to find the corresponding eigenvectors.\n\n\\subsection{Properties}\n\\begin{itemize}\n\\item The trace of A is equal to the sum of its eigenvalues:\n$$tr(A)=\\sum_{i=1}^{n} \\lambda_i$$\n\\item The determinant of A is equal to the product of its eigenvalues:\n$$|A|=\\prod_{i=1}^{n} \\lambda_i$$\n\\item The rank of A is equal to the number of non-zero eigenvalues of A.\n\\item The eigenvalues of a diagonal matrix $D = diag(d_1, \\ldots, d_n)$ are just the diagonal entries $d_1, \\ldots d_n$.\n\\end{itemize}\n\n\\subsection{Spectral Theory}\n\\subsubsection{Definitions}\n\\begin{itemize}\n\\item An \\textit{eigenpair} is the pair of an eigenvalue and its associated eigenvector.\n\\item An \\textit{eigenspace} of $A$ associated with $\\lambda$ is the space of vectors where:\n$$(A-\\lambda I) = 0$$\n\\item The \\textit{spectrum} of $A$ is the set of all its eigenvalues:\n$$\\sigma(A)=\\lbrace\\lambda \\in \\mathbb{C}: \\lambda I - A \\textrm{ is singular}\\rbrace$$\nWhere $\\mathbb{C}$ is the space of all eigenvalues of $A$\n\\item The \\textit{spectral radius} of $A$ is the magnitude of its largest magnitude eigenvalue:\n$$\\rho(A)=max\\lbrace |\\lambda_1|, \\ldots, |\\lambda_n| \\rbrace$$\n\n\\end{itemize}\n\\subsubsection{Theorem: Spectral radius bound} Spectral radius is bounded by the infinity norm of a matrix:\n$$\\rho(A)=\\lim_{k\\to\\infty} ||A^k||^{1/k}$$\n\\textit{Proof}:\n$$|\\lambda|^k||\\mathbf{v}||=||\\lambda|^k\\mathbf{v}||=||A^k\\mathbf{v}||$$\nBy the Cauchy–Schwarz inequality ($||\\mathbf{u}\\mathbf{v}|| \\leq ||\\mathbf{u}||\\cdot||\\mathbf{v}||$):\n$$|\\lambda|^k||\\mathbf{v}|| \\leq ||A^k||\\cdot||\\mathbf{v}||$$\nSince $\\mathbf{v} \\neq 0$:\n$$|\\lambda|^k \\leq ||A^k||$$\nAnd we thus arrive at:\n$$\\rho(A)=\\lim_{k\\to\\infty} ||A^k||^{1/k}$$\n\n\\subsection{Diagonalization}\nAn $n\\times n$ matrix A is diagonalizable if it has $n$ linearly independent eigenvectors.\n\nMost square matrices are diagonalizable\n\\begin{itemize}\n\\item Normal matrices are diagonalizable\n\nNote: Normal matrices are matrices that satisfy:\n$$A^* A=AA^*$$\nWhere $A^*$ is the complex conjugate of $A$\n\\item Matrices with $n$ distinct eigenvalues are diagonalizable\n\\end{itemize}\n\n\\textbf{Lemma:} Eigenvectors associated with distinct eigenvalues are linearly independent.\n\nTo diagonalize the matrix $A$, consider its eigenvalues and eigenvectors. We can construct matrices $D$ and $V$, where $D$ is the diagonal matrix of the eigenvalues of $A$, and $V$ is the matrix of corresponding eigenvectors:\n$$D=\\begin{bmatrix}\n    \\lambda_1 & & \\\\\n    & \\ddots &    \\\\\n    & & \\lambda_n\n\\end{bmatrix}\n$$\n\n$$V=\\begin{bmatrix}\n    v_1 & v_2 & \\dots & v_n\n\\end{bmatrix}\n$$\n\nSince we know that:\n$$AV=VD$$\nWe can diagonalize $A$ by:\n$$A=VDV^{-1}$$\nIf all eigenvalues are unique, then $V$ is orthogonal. Since the inverse of an orthogonal matrix is its transpose, we can write the diagonalization as:\n$$A=VDV^T$$\n\\subsection{Symmetric Matrices}\nIf $A$ is symmetric, then all its eigenvalues are real, and its eigenvectors are orthonormal. Recalling the above diagonalization equation, we can diagonalize $A$ by:\n$$A=VDV^T$$\n\nUsing the above relation, we can also write the following relationship:\n\nGiven $y=V^Tx$:\n$$x^TAx=x^TVDV^Tx=y^TDy=\\sum_{i=1}^{n} \\lambda_i y_i^2$$\n\nThus, if we want to do the following maximization:\n$$ max_{x\\in\\mathbb{R}^n} (x^TAx) \\quad \\textrm{ subject to   } ||x||_2^2=1$$\n\nThen the maximizing $x$ can be found by finding the eigenvector corresponding to the largest eigenvalue of $A$.\n\n\\subsection{Applications}\nSome applications of eigenvalues and eigenvectors include, but are not limited to:\n\\begin{itemize}\n\\item PageRank\n\\item Schroedinger's equation\n\\item Principle component analysis (PCA)\n\\end{itemize}\n\\section{Matrix Calculus}\n\\subsection{The Gradient}\nIf a function $f:{\\rm I\\!R^{mxn}} \\mapsto {\\rm I\\!R}$ takes as input a matrix $A$ of size $(m\\times n)$ and returns a real value, then the gradient of $f$ is\n\\newline\n$$\\nabla_A f(A) \\in {\\rm I\\!R^{mxn}} = \\begin{bmatrix}\n    \\frac{\\partial f(A)}{\\partial A_{11}} & \\frac{\\partial f(A)}{\\partial A_{12}} & \\cdots & \\frac{\\partial f(A)}{\\partial A_{1n}} \\\\\n    \\frac{\\partial f(A)}{\\partial A_{21}} & \\frac{\\partial f(A)}{\\partial A_{22}} & \\cdots & \\frac{\\partial f(A)}{\\partial A_{2n}} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    \\frac{\\partial f(A)}{\\partial A_{m1}} & \\frac{\\partial f(A)}{\\partial A_{m2}} & \\cdots & \\frac{\\partial f(A)}{\\partial A_{mn}}\n\\end{bmatrix}\n$$\n\\newline\nEvery entry in the matrix is: $$\\nabla_A f(A)_{ij} = \\frac{\\partial f(A)}{\\partial A_{ij}}$$\n\\newline\nThe size of $\\nabla_A f(A)$ is always the same as the size of $A$. Thus, if $A$ is a vector $x$:\n$$\\nabla_x f(x) = \\begin{bmatrix}\n\t\\frac{\\partial f(x)}{\\partial x_{1}} \\\\\n    \\frac{\\partial f(x)}{\\partial x_{2}} \\\\\n    \\vdots \\\\\n    \\frac{\\partial f(x)}{\\partial x_{n}}\n\\end{bmatrix}\n$$\n\\subsection{The Gradient: Properties}\n\\begin{itemize}\n\\item $\\nabla_x (f(x) + g(x)) = \\nabla_x f(x) + \\nabla_x g(x)$\n\\item For $t \\in {\\rm I\\!R}$, $\\nabla_x (t f(x)) = t \\nabla_x f(x)$\n\\end{itemize}\n\\subsection{The Hessian}\nThe Hessian matrix with respect to $x$ can be written as $\\nabla_x^2 f(x)$ or as $H$. It is an $nxn$ matrix of partial derivatives\n\\newline\n$$\\nabla_x^2 f(x) \\in {\\rm I\\!R^{nxn}} = \\begin{bmatrix}\n    \\frac{\\partial^2 f(x)}{\\partial x_1^2} & \\frac{\\partial^2 f(x)}{\\partial x_1 \\partial x_2} & \\cdots & \\frac{\\partial^2 f(x)}{\\partial x_1 \\partial x_n} \\\\\n    \\frac{\\partial^2 f(x)}{\\partial x_2 \\partial x_1} & \\frac{\\partial^2 f(x)}{\\partial x_2^2} & \\cdots & \\frac{\\partial^2 f(x)}{\\partial x_2 \\partial x_n} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    \\frac{\\partial^2 f(x)}{\\partial x_n \\partial x_1} & \\frac{\\partial^2 f(x)}{\\partial x_n \\partial x_2} & \\cdots & \\frac{\\partial^2 f(x)}{\\partial x_n^2} \\\\\n\\end{bmatrix}\n$$\n\\newline\nEvery entry in the matrix is: $$\\nabla_x^2 f(x)_{ij} = \\frac{\\partial^2 f(x)}{\\partial x_i \\partial x_j}$$\n\\newline\nIt's important to note that the Hessian is the gradient of \\textbf{every entry} of the gradient of the vector. For instance, the first column of the Hessian is the gradient of $\\frac{\\partial f(x)}{\\partial x_1}$.\n\\subsection{The Hessian: Properties}\nSchwarz's theorem: The order of partial derivatives doesn't matter so long as the second derivative exists and is continuous.\n\\newline\n\\newline\nThus, the Hessian is always symmetric:\n$$\\frac{\\partial^2 f(x)}{\\partial x_i \\partial x_j} = \\frac{\\partial^2 f(x)}{\\partial x_j \\partial x_i}$$\n\\subsection{Example Calculations}\n\\subsubsection{Example Gradient Calculation}\nFor $x \\in {\\rm I\\!R^{n}}$, let $f(x) = b^Tx$ for some known vector $b \\in {\\rm I\\!R^{n}}$\n$$ f(x) = \\begin{bmatrix}\n    b_1 & b_2 & \\cdots & b_n\n  \\end{bmatrix}^T\n  \\begin{bmatrix}\n  \tx_1 \\\\\n    x_2 \\\\\n    \\vdots \\\\\n    x_n\n  \\end{bmatrix}\n $$\n\\newline\nThus, $$f(x) = \\sum_{i=1}^{n} b_i x_i$$\n$$\\frac{\\partial f(x)}{\\partial x_k} = \\frac{\\partial}{\\partial x_k}\\sum_{i=1}^{n} b_i x_i = b_k$$\nTherefore, we can conclude that: $\\nabla_x b^Tx = b$.\n\\subsubsection{Example Hessian Calculation}\nConsider the quadratic function $f(x) = x^TAx$\n$$f(x) = \\sum_{i=1}^{n} \\sum_{j=1}^{n} A_{ij} x_i x_j$$\n$$\\frac{\\partial f(x)}{\\partial x_k} = \\frac{\\partial}{\\partial x_k}\\sum_{i=1}^{n}\\sum_{j=1}^{n} A_{ij} x_i x_j$$\n$$= \\frac{\\partial}{\\partial x_k}[\\sum_{i \\neq k} \\sum_{j \\neq k} A_{ij} x_i x_j + \\sum_{i \\neq k} A_{ik} x_i x_k + \\sum_{j \\neq k} A_{kj} x_k x_j + A_{kk}x_k^2]$$\n$$= \\sum_{i \\neq k} A_{ik} x_i + \\sum_{j \\neq k} A_{kj} x_j + 2 A_{kk}x_k$$\n$$= \\sum_{i=1}^{n} A_{ik} x_i + \\sum_{j=1}^{n} A_{kj} x_j = 2\\sum_{i=1}^{n} A_{ki} x_i$$\n$$\\frac{\\partial^2 f(x)}{\\partial x_k \\partial x_l} = \\frac{\\partial}{\\partial x_k}[\\frac{\\partial f(x)}{\\partial x_l}] = \\frac{\\partial}{\\partial x_k}[\\sum_{i=1}^{n} 2 A_{li} x_i]$$\n$$= 2A_{lk} = 2A_{kl}$$\nThus, $$\\nabla_x^2 f(x) = 2A$$\n% References\n% \\small\n% \\bibliographystyle{plain}\n% \\bibliography{bibliography}\n\\end{document}\n", "meta": {"hexsha": "6106f787a5d50385d562c56bffbc01aa73c47d01", "size": 16696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs131_notes/lecture03/lecture03.tex", "max_stars_repo_name": "suryadheeshjith/CS_131", "max_stars_repo_head_hexsha": "98fd6511b684cd14f99d3a8d280385d36732e568", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs131_notes/lecture03/lecture03.tex", "max_issues_repo_name": "suryadheeshjith/CS_131", "max_issues_repo_head_hexsha": "98fd6511b684cd14f99d3a8d280385d36732e568", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs131_notes/lecture03/lecture03.tex", "max_forks_repo_name": "suryadheeshjith/CS_131", "max_forks_repo_head_hexsha": "98fd6511b684cd14f99d3a8d280385d36732e568", "max_forks_repo_licenses": ["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.592689295, "max_line_length": 468, "alphanum_fraction": 0.6830378534, "num_tokens": 5533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.6055825476319914}}
{"text": "\\section{Background Subtraction: autobk algorithm}\n\n\n\\begin{frame} \\frametitle{Background Subtraction: $\\mu_0(E)$}\n\n\\begin{cenpage}{130mm}\n\n  \\[ \\chi(E) = \\frac{\\mu(E) - \\mu_0(E)}{\\Delta \\mu_0(E_0)} \\]\n\n\\vmm\nWe don't know ${\\mu_0(E)}$, so use a {\\BlueEmph{spline}}: a smooth, adjustable function.\n\n\\vmm\n\nThis could be dangerous -- a flexible enough spline would remove all the XAFS.\n\n\\vmm\n\\pause\n\nThe {\\autobk} method in {\\larch} chooses a background spline for $\\mu_0(E)$ to\n\n\\begin{center}\n  \\begin{postitbox}{55mm}\n    {\\RedEmph{minimize the low-$R$ components of $\\chi$}}\n  \\end{postitbox}\n\\end{center}\n\n\\begin{enumerate}\n  \\item Spline parameters for $\\mu_0(E)$ are guessed.\n  \\item $\\chi(k)$ is Fourier Transformed to $\\chi(R)$.,\n  \\item Spline parameters optimized so that $\\chi(R)$ below \\feffc{R_{\\rm bkg}} is minimized.\n  \\item Note that $\\chi(R)$ above \\feffc{R_{\\rm bkg}} is completely ignored!\n\\end{enumerate}\n\n\n\\vmm  \\hrule \\vmm\n\nMost important parameters:\n\n\\begin{enumerate}\n\\item \\feffc{R_{\\rm bkg}}: $R$ below which $\\chi(R)$ is reduced.\n\\item {\\Red{$k$-weight}}:  used for Fourier transform:   use 1, or 2.\n\\item \\feffc{E_0}:         May need to adjust for initial guess (max of $d\\mu/dE$).\n\\end{enumerate}\n\n\\end{cenpage}\n\\end{frame}\n\n\n\\begin{frame} \\frametitle{Background Subtraction in {\\xasviewer} }\n\n  \\begin{cenpage}{130mm}\n\nEffect of \\feffc{R_{\\rm bkg}}  on XAFS $\\chi(k)$ and $\\chi(R)$:\n\n\\begin{tabular}{ll}\n  \\begin{minipage}{65mm}\n    \\includegraphics[width=60mm]{figs/experiment/bkg_ksp1}\n  \\end{minipage} &\n  \\begin{minipage}{65mm}\n    \\includegraphics[width=60mm]{figs/experiment/bkg_rsp1}\n  \\end{minipage} \\\\\n  \\begin{minipage}{55mm}\n    $\\chi(k)$ for FeO with\n    $R_{\\rm bkg}=0.1\\, \\rm \\AA$ \\\\\n    (stiff spline)  and $R_{\\rm bkg}=1.0\\, \\rm \\AA$.\n  \\end{minipage} &\n  \\begin{minipage}{55mm}\n    $\\chi(R)$ for FeO with\n    $R_{\\rm bkg}=0.1\\, \\rm \\AA$ \\\\\n    (stiff spline)   and  $R_{\\rm bkg}=1.0\\, \\rm \\AA$.\n  \\end{minipage} \\\\\n\\end{tabular}\n\n\\vmm \\pause \\vmm\\vmm\n\nRules of thumb:\n\n\\begin{postitbox}{76mm}\n  Use  $R_{\\rm bkg}=1.0\\, \\rm \\AA$ or half the near-neighbor distance.\n\\end{postitbox}\n\n\\begin{postitbox}{76mm}\n  Don't spend too much time on background subtraction.\n\\end{postitbox}\n\n\\end{cenpage}\n\n\\end{frame}\n\n\n\\begin{frame} \\frametitle{Background Subtraction in {\\xasviewer}  }\n\n\n  \\begin{cenpage}{130mm}\n\n\nDon't make \\feffc{R_{\\rm bkg}} too big!\n\n\\begin{tabular}{ll}\n  \\begin{minipage}{65mm}\n    \\includegraphics[width=60mm]{figs/experiment/bkg_ksp2}\n  \\end{minipage} &\n  \\begin{minipage}{55mm}\n    \\includegraphics[width=60mm]{figs/experiment/bkg_rsp2}\n  \\end{minipage} \\\\\n  \\begin{minipage}{55mm}\n    $\\chi(k)$ for FeO with $R_{\\rm bkg}=2.0\\, \\rm \\AA$\n  \\end{minipage} &\n  \\begin{minipage}{55mm}\n    $\\chi(R)$ for FeO with $R_{\\rm bkg}=2.0\\, \\rm \\AA$  Note: we have\n    removed the first shell!!\n\n  \\end{minipage} \\\\\n\\end{tabular}\n\n\\vmm\n\n    \\vmm\n    Having $R_{\\rm bkg}$ too big is the most important thing to avoid.\n\n    \\vmm\n\n    $R_{\\rm bkg}$  that's a little bit small  and gives a small peak at\n    very low $R$ is not that big of a problem.\n\n    \\end{cenpage}\n\\vfill\n\n\n\\end{frame}\n", "meta": {"hexsha": "171869a4b50f1ca4984cf2f4395546cfc32a1c80", "size": 3133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/autobk.tex", "max_stars_repo_name": "newville/xafsfun", "max_stars_repo_head_hexsha": "525b0b8fb6ec61396dc7dd2950a3e2a3ab6c17d1", "max_stars_repo_licenses": ["MIT"], "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/autobk.tex", "max_issues_repo_name": "newville/xafsfun", "max_issues_repo_head_hexsha": "525b0b8fb6ec61396dc7dd2950a3e2a3ab6c17d1", "max_issues_repo_licenses": ["MIT"], "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/autobk.tex", "max_forks_repo_name": "newville/xafsfun", "max_forks_repo_head_hexsha": "525b0b8fb6ec61396dc7dd2950a3e2a3ab6c17d1", "max_forks_repo_licenses": ["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.7348484848, "max_line_length": 93, "alphanum_fraction": 0.6520906479, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6055235213100884}}
{"text": "%${LICENSE}$\n\\documentclass[twocolumn, noxcolor, maketitle]{rbt-mathnotes-hw}\n\\mathnotes{\n  instructor  = Prof.~Ruth Charney ,\n  name        = Rebecca Turner ,\n  email       = rebeccaturner@brandeis.edu ,\n  course      = \\textsc{math} 104a (Intro to Topology) ,\n  institution = Brandeis University ,\n  semester    = Spring 2020 ,\n}\n\\title{Homework 1}\n\\date{2020-01-18}\n\\def\\T{\\mathcal{T}}\n\\def\\basis{\\mathcal{B}}\n\\usepackage[\n  letterpaper,\n  margin = 1in,\n]{geometry}\n\\raggedbottom\n\\begin{document}\n\\maketitle\n\n\\section{Topological Spaces}\n\\subsection{Open Sets and the Definition of a Topology}\n\\begin{problem}[1.7]\n  Define a topology on $\\R$ (by listing the open sets within it) that contains\n  the open sets $(0,2)$ and $(1,3)$ that contains as few open sets as possible.\n\\end{problem}\n$\\T = \\{ \\emptyset, (0,2), (1,3), (1,2), (0,3), \\R \\}$.\n\n\\subsection{Basis for a Topology}\n\\begin{problem}[1.10]\n  Show that $\\mathcal{B} = \\{[a,b) \\subset \\R : a < b\\}$ is a basis for a\n  topology on $\\R$.\n\\end{problem}\n\\begin{enumerate}\n  \\item \\textbf{$\\emptyset \\in \\T$, $\\R \\in \\T$.} $\\emptyset \\in \\T$ (by the\n    definition of the completion of a basis to a topology).\n\n    Next, we show $\\R \\in \\T$. For all $n \\in \\Z_{\\ge 0}$, $[n-1, n) \\in \\basis$\n    and $[-n + 1, -n) \\in \\basis$. We know that if $b_1, b_2 \\in \\basis$, $b_1\n    \\union b_2 \\in \\T$, so these short intervals can be gathered together (``unionized'')\n    to produce $\\R$:\n    \\[ \\bigunion_{n=1}^{\\infty} \\left( [n-1, n) \\union [-n + 1, -n] \\right) = \\R, \\]\n    so $\\R \\in \\T$.\n\n  \\item \\textbf{$\\T$ contains all finite intersections of elements of $\\T$.}\n    Suppose we have two intervals $[a, b)$ and $[c, d)$. Then, we define\n    \\begin{alignat*}{1}\n      a' &= \\max(a, c) \\\\\n      b' &= \\min(b, d).\n    \\end{alignat*}\n    If $a' > b'$, the intersection $[a, b) \\inter [c, d) = \\emptyset$, which is\n    in $\\T$. Otherwise, the intersection is $[a', b')$, which is an element of\n    $\\basis$. All elements of the basis are in $\\T$, so the intersection of two\n    elements is in the topology.\n\n    Thankfully, the intersection is itself always a basis element, so we can\n    use the same process to show that finite intersections are in $\\T$ by\n    induction.\n\n  \\item \\textbf{Unions of elements of $\\T$ are in $\\T$.} By the definition of\n    the completion of a basis to a topology, this is true (all unions of basis\n    elements are included in $\\T$).\n\\end{enumerate}\n\n\\begin{problem}[1.12]\n  % See example 1.9 for defn of \\R_l\n  Determine which of the following are open sets in $\\R_l$. In each case, prove\n  your assertion.\n  \\[ A = [4,5)\n    \\quad B = \\{3\\}\n    \\quad C = [1,2]\n    \\quad D = (7,8) \\]\n\\end{problem}\n\\begin{enumerate}\n  \\item $A$ is open in $\\R_l$; $[4,5) \\in \\basis$.\n  \\item $B$ is not an open set in $\\R_l$; there is no $[a, b) \\subset \\R$ where\n    both $b > a$ and $|[a, b)| = 1$ (because $[0,1) \\cong \\R$, i.e.~all\n    intervals contain infinitely many points).\n\n    (Where $\\cong$ means ``is isomorphic to.'')\n  \\item $C$ is not open in $\\R_l$ because the upper bound of an open set in\n    $\\R_l$ is never inclusive. There is no set of intervals $[a_1, b_1), \\dots$\n    where the union or intersection of the intervals has an inclusive upper bound.\n  \\item $D$ is open because we can take\n    \\[ D = \\lim_{n\\to\\infty} \\left[7 + \\frac{1}{n}, 8\\right), \\]\n    where $[7 + 1/n, 8) \\in \\basis$ for any $n \\in \\R$ with $n \\ne 0$.\n\\end{enumerate}\n\n\\pagebreak\n\\begin{problem}[1.15]\n  An arithmetic progression in $\\Z$ is a set\n  \\[ A_{a,b} = \\{\\dots, a - 2b, a - b, a, a + b, a + 2b, \\dots\\} \\]\n  with $a,b \\in \\Z$ and $b \\ne 0$. Prove that the collection of arithmetic\n  progressions\n  \\[ \\mathcal{A} = \\{ A_{a,b} : a, b \\in \\Z \\text{ and } b \\ne 0 \\} \\]\n  is a basis for a topology on $\\Z$. The resulting topology is called the\n  arithmetic progression topology on $\\Z$.\n\\end{problem}\n\n\\begin{proof}\n  \\def\\Ar#1#2{A_{#1,#2}}\n  \\def\\Ars{\\mathcal{A}}\n  Let us describe the \\emph{minimal form} of an arithmetic progression $\\Ar ab$\n  to be the progression $\\Ar{a'}{b'} = \\Ar ab$ with $a', b' > 0$ and the\n  smallest possible $a'$; in particular, that $a' < b'$.\n\n  We can obtain the minimal form of the progression like so:\n  \\begin{alignat*}{1}\n    a' &= a \\bmod b \\\\\n    b' &= |b|, \\\\\n    \\Ar{a'}{b'} &= \\Ar ab.\n  \\end{alignat*}\n\n  \\begin{remark}\n    Two arithmetic progressions have the same elements if their minimal forms are\n    the same; this give an equivalence relation on $\\Ars$.\n  \\end{remark}\n\n  Now, suppose we have two arithmetic progressions $\\Ar ab$ and $\\Ar cd$. We\n  assume that the progressions are in minimal form without loss of generality. We\n  also assume that $b \\le d$ (by swapping $(a,b)$ with $(c,d)$ if necessary),\n  again without loss of generality.\n\n  If $b \\mid d$ and $a = c$, we have $\\Ar ab \\subset \\Ar cd$. In particular, $\\Ar\n  ab \\inter \\Ar cd = \\Ar cd$.\n\n  If $b \\mid d$ and $a \\ne c$, we have $\\Ar ab \\inter \\Ar cd = \\emptyset$.\n\n  If $b \\nmid d$, we have a different progression. An intersection is generated by\n  an index $(n_1, n_2)$, where\n  \\begin{alignat*}{1}\n    a + b n_1 &= c + d n_2. \\\\\n    \\intertext{We can then solve for $n_1$:}\n    t(n) &= c - a + dn \\\\\n    n_1 &= \\frac{t(n_2)}{b}. \\\\\n    \\intertext{Next, we have an infinite \\emph{set} of possibilities for $n_2$:}\n    n_2 &\\in \\left\\{n \\in \\Z : t(n) \\mid b \\right\\}.\n    \\intertext{Sorting the possible values of $n_2$ by absolute value, let us call\n      the smallest two values $i_1$ and $i_2$. Then, the difference between\n      adjacent elements in the intersection progression $\\Ar ab \\inter \\Ar cd$\n      is $i_2 - i_1$.\n      \\endgraf\n      Let}\n    a' &= a + bi_1 \\\\\n    b' &= i_2 - i_1 \\\\\n    \\Ar ab \\inter \\Ar cd &= \\Ar{a'}{b'}.\n  \\end{alignat*}\n  This isn't super rigorous, admittedly (we're missing some inductive reasoning\n  about the integers to prove that there are an infinite set of valid values of\n  $n_2$, in particular), but I have some fairly convincing Haskell code. And the\n  missing steps are mostly boilerplate, and it's late at night already\\dots\n\n  In all cases, the intersection of two arithmetic progressions is either empty or\n  another arithmetic progression (i.e.~either the empty set or another basis\n  element), so the same argument given above for $\\R_l$ holds (namely that we can\n  extend this to all finite intersections of elements of $\\Ars$ inductively).\n\n  Therefore, finite intersections are in the basis. Unions are in the completion\n  of the basis (again by definition). The special element $\\emptyset$ is in the\n  completion (by definition), and $\\Z = \\Ar01$, so $\\Z \\in \\basis$. Therefore,\n  $\\Ars$ forms the basis of a topology on $\\Z$.\n\\end{proof}\n\n\\pagebreak\n\\subsection{Closed Sets}\n\\begin{problem}[1.27(a)]\n  The infinite comb $C$ is the subset of the plane illustrated in Figure~1.17\n  and defined by\n  \\begin{multline*}\n    C = \\{(x,0) : 0 \\le x \\le 1\\} \\;\\union \\\\\n    \\bigg\\{ \\left( \\frac{1}{2^n}, y \\right) : n = 0,1,2, \\dots \\\\\n      \\text{ and } 0 \\le y \\le 1 \\bigg\\}.   \n  \\end{multline*}\n  Prove that $C$ is not closed in the standard topology on $\\R^2$.\n\\end{problem}\n\\begin{proof}\n  Suppose $C$ is closed in the standard topology on $\\R^2$. Then, its complement\n  $C^c = \\R^2 \\setminus C$ must be an open set.\n\n  The point $(0, 1)$ is not in $C$, so $(0, 1) \\in C^c$. Every open ball in $\\R^2$\n  containing $(0, 1)$ also contains a smaller open ball centered about $(0, 1)$.\n  (For example, the open ball about $(-1, 1)$ of radius $1.1$ contains the open\n  ball centered about $(0, 1)$ of radius $0.1$.)\n\n  However, every open ball centered about $(0, 1)$ contains infinitely many\n  points of $C$; if the ball has radius $r$, all the comb's ``tines'' at $x =\n  1/2^n$ for $n > - \\log_2 r$ intersect with the ball.\n\n  Therefore, every open ball containing $(0, 1)$ also contains points in $C$. As\n  a result, $C^c$ is not open, which contradicts our assumption. Therefore, $C$\n  is not closed.\n\\end{proof}\n\n\\begin{problem}[1.32]\n  Prove that intervals of the form $[a, b)$ are closed in the lower limit\n  topology on $\\R$.\n\\end{problem}\n\\begin{proof}\n  Take some interval $[a, b)$. Its complement is given by $(-\\infty, a) \\union\n  [b, \\infty)$. Given that\n  \\begin{alignat*}{1}\n    (-\\infty, a) &= \\bigunion_{n=1}^\\infty [a-n, a) \\\\\n    [b, \\infty) &= \\bigunion_{n=1}^\\infty [b, b+n),\n  \\end{alignat*}\n  the complement of $[a, b)$ is the union of a number of lower-limit intervals\n  in $\\R$, i.e.~the basis elements. The basis elements and its unions are open\n  sets, so the complement of $[a, b)$ is an open set. Then, by the definition of\n  a closed set, $[a, b)$ is closed in $\\R_l$.\n\\end{proof}\n\n\n\\end{document}\n", "meta": {"hexsha": "c6a52973ee02fb2d3f436c0cd6de7cbba6b98dc6", "size": 8669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/topology-hw-1.tex", "max_stars_repo_name": "9999years/mathnotes", "max_stars_repo_head_hexsha": "2a0a220de476570151a286affcd0cd4c2d1f6683", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-02T00:26:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-23T13:11:17.000Z", "max_issues_repo_path": "examples/topology-hw-1.tex", "max_issues_repo_name": "9999years/mathnotes", "max_issues_repo_head_hexsha": "2a0a220de476570151a286affcd0cd4c2d1f6683", "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": "examples/topology-hw-1.tex", "max_forks_repo_name": "9999years/mathnotes", "max_forks_repo_head_hexsha": "2a0a220de476570151a286affcd0cd4c2d1f6683", "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": 40.3209302326, "max_line_length": 89, "alphanum_fraction": 0.6339831584, "num_tokens": 2943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6055235213100884}}
{"text": "%!TEX program = xelatex\n\n\\documentclass[12pt,a4paper]{article}\n\\usepackage{xeCJK}\n\\usepackage{amsmath}\n\\setCJKmainfont{STSongti-SC-Regular}\n\\usepackage{setspace}\n\\usepackage{caption}\n\\usepackage{graphicx, subfig}\n\\usepackage{float}\n\\usepackage{listings}\n\\usepackage{booktabs}\n\n\n\n\\begin{document} \n\\title{homework3}\n\t\\author{11611118 郭思源}  \n\n\\section{Problem 1}\n\\begin{lstlisting}[language=matlab]\n%指数分布\nset(gcf,'Units','centimeters','Position',[0 0 30 30]);\nnum = [100,1000,5000];\nmu = 3;\nfor i = 1:3\nsample = exprnd(mu,num(i),1);% Simulated data\nx=min(sample):1:max(sample);\nsubplot(3,3,3*i-2)\nhistogram(sample,x);\ntitle(sprintf('Exponential distribution (n=%d)', num(i)));\nfprintf(\"i=%d\",i);\n[muhat,muci] = expfit(sample, 0.05)\nend\n\n%泊松分布\nnum = [100,1000,5000];\nlam=70;\nfor i = 1:3\nsample=poissrnd(lam,num(i),1);% Simulated data\nx=min(sample):1:max(sample);\nsubplot(3,3,3*i-1)\nhistogram(sample,x);\ntitle(sprintf('Poisson distribution (n=%d)', num(i)));\nfprintf(\"i=%d\",i);\n[Lambdahat, Lambdaci]=poissfit (sample, 0.05)\nend\n\n%正态分布\nnum = [100,1000,5000]*2;\nfor i = 1:3\nsample = normrnd(0,1,num(i),1);\nx=min(sample):0.1:max(sample);\nsubplot(3,3,3*i)\nhistogram(sample,x);\ntitle(sprintf('Normal distribution (n=%d)', num(i)));\nfprintf(\"i=%d\",i);\n[muhat,sigmahat,muci,sigmaci]=normfit(sample, 0.05)\nend\n\\end{lstlisting}\n\n\\begin{figure}[htbp]\n\\centering\n\\includegraphics[bb=400 400 1300 1300,scale=.3]{figure/HW3_1.jpg}\n\\end{figure}\n\n\\begin{table}[htbp]\n\\caption{Exponential distribution confidence interval (95)\\% \\\\ $\\lambda=3$} \n\\centering\n\\begin{tabular}{lll}\n\t\\toprule \n\tNumber of samples & \n\tEstimates the mean $\\lambda$ & \n\tConfidence intervals for the mean $\\lambda$ \\\\ \n\t\\midrule \n\t100 & 2.7511 & [ 2.2826, 3.3813 ] \\\\ \n\t1000 & 3.0171 & [ 2.8385, 3.2132 ] \\\\\n\t5000 & 2.9651 & [ 2.8846, 3.0490 ] \\\\ \n\t\\bottomrule \n\\end{tabular} \n\\end{table}\n\n\\newpage\n\n\\begin{table}[htbp]\n\\caption{Poisson distribution confidence interval (95)\\% \\\\ $\\lambda=70$} \n\\centering\n\\begin{tabular}{lll}\n\t\\toprule \n\tNumber of samples & \n\tEstimates the mean $\\lambda$ & \n\tConfidence intervals for the mean $\\lambda$ \\\\ \n\t\\midrule \n\t100 & 70.4200 & [ 68.7753, 72.0647 ] \\\\ \n\t1000 & 70.2070 & [ 69.6877, 70.7263 ] \\\\\n\t5000 & 69.8896 & [ 69.6579, 70.1213 ] \\\\ \n\t\\bottomrule \n\\end{tabular} \n\\end{table}\n\n\\begin{table}[htbp]\n\n\\caption{Exponential distribution confidence interval (95)\\% \\\\ \n\t\t$\\mu=0$ \\\\ $\\sigma=1$} \n\\centering\n\n\\begin{tabular}{lll}\n\n\t\\toprule \n\tNumber of samples & \n\tEstimates the mean $\\mu$ & \n\tConfidence intervals for the mean $\\mu$ \\\\ \n\t\\midrule \n\t200 & 0.0279 & [ -0.1152, 0.1710 ] \\\\ \n\t2000 & 0.0099 & [ -0.0339, 0.0536 ] \\\\\n\t10000 & -0.0122 & [ -0.0318, 0.0074 ] \\\\ \n\t\\bottomrule \n\n\\end{tabular} \n\n\\begin{tabular}{lll}\n\n\t\\toprule \n\tNumber of samples & \n\tEstimates the mean $\\sigma$ & \n\tConfidence intervals for the mean $\\sigma$ \\\\ \n\t\\midrule \n\t200 & 1.0263 & [ 0.9346, 1.1381 ] \\\\ \n\t2000 & 0.9977 & [ 0.9677, 1.0296 ] \\\\\n\t10000 & 0.9990 & [ 0.9854, 1.0131 ] \\\\ \n\t\\bottomrule \n\n\\end{tabular} \n\n\\end{table}\n\n\n\\newpage\n\n\\section{Problem 2}\n\n\\subsection{0-norm}\nAs we know the error \n$\\left\\|e\\right\\|_0$ = the number of ${y_i-ax_i-b\\ne0}$\\\\\nso that we choose the line y=ax+b such that the most point lie on the line.\\\\\nso we just choose two point $(x_i,y_i)$ $(x_j,y_j)$\\\\\n\nThen: \\\\\n\\begin{equation}\n\t\\begin{aligned}\n\t\ta &= \\frac{y_i-y_j}{x_i-x_j}\\\\\n\t\tb &= \\frac{y_j x_i-x_j y_i}{x_i-x_j}\\\\\n\t\\end{aligned}\n\\end{equation}\n\n\n\\subsection{1-norm}\n \n\nAs we know the error $\\left\\|e\\right\\|_1$=$\\sum_{i=1}^n|y_i-ax_i-b|$\\\\\n\nError: \\\\\n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\Bar{e} &= \\frac{\\sum_{i=1}^n|y_i-ax_i-b|}{n} \\\\\n\t\te_i &= |y_i-ax_i-b|\\\\\n\t\\end{aligned}\n\\end{equation}\n\nSo we define y$_i$$'$=$y_i-| e_i- \\Bar{e} |$\\\\\n\n\\noindent So that we can know that those  y$_i$$'$ lie on two parallel lines. and the fit line is the middle line of those tow liens. \n\nSo is y$_i$$'$ satisfy:\\\\\n\\begin{equation}\n\t\\begin{aligned}\n\t\ty &= ax+b \\pm \\Bar{e} \\\\ \n\t\\end{aligned}\n\\end{equation}\n \n\n\n\n\\newpage\n\\subsection{2-norm}\nAs we know the error $\\left\\|e\\right\\|_2$=$\\sum_{i=1}^n(y_i-ax_i-b)^2$\\\\\n\nSo : \n\\begin{equation}\n\t\\begin{aligned}\n\t\t\\frac{\\partial e}{\\partial a} &= 0 \\\\\n\t\t\\frac{\\partial e}{\\partial b} &= 0 \\\\\\\\\n\t\\end{aligned}\n\\end{equation}\n\nThen :\n\\begin{equation}\n\t\\begin{aligned}\n\t\ta &= \\frac{m \\sum_{i=1}^n{x_i y_i}-\\sum_{i=1}^n{x_i} \\sum_{i=1}^n{y_i}}{m \\sum_{i=1}^n{x_i^2}-(\\sum_{i=1}^n{x_i})^2}\\\\\\\\\n\t\tb &= \\frac{\\sum_{i=1}^n{x_i^2} \\sum_{i=1}^n{y_i}-\\sum_{i=1}^n{x_i} m \\sum_{i=1}^n{x_i y_i}}{m \\sum_{i=1}^n{x_i^2}-(\\sum_{i=1}^n{x_i})^2}\n\t\\end{aligned}\n\\end{equation}\n\n\n\\subsection{$\\infty$-norm}\nAs we know the error $\\left\\|e\\right\\|_\\infty$=$\\max{|y_i-ax_i-b|}$\\\\\nSuppose when i=k,$|y_i-ax_i-b|$ is maximum\\\\\nso that we just make the a,b to satisfy $ax_k-b=y_k$ \\\\\nThen we will get the min $\\left\\|e\\right\\|_\\infty$\\\\\n\n\n\\newpage\n\n\\section{Problem 3}\nThe lasso in Matlab is used for lasso or elastic net regularization for linear models. \\\\\\\\\n\\textbf{The syntax of the lasso function:}\\\\\n\n\\noindent \\textbf{B = lasso(X,Y):}\\\\\nReturns fitted least-squares regression coefficients for linear models of the predictor data X and the response y. Each column of B corresponds to a particular regularization coefficient in Lambda. By default, lasso performs lasso regularization using a geometric sequence of Lambda values.\\\\\n\n\\noindent \\textbf{B = lasso(X,Y,Name,Value):}\\\\\nFits regularized regressions with additional options specified by one or more name-value pair arguments. For example, 'Alpha',0.5 sets elastic net as the regularization method, with the parameter Alpha equal to 0.5.\\\\\n\n\\noindent \\textbf{$\\textbf{[B,FitInfo]}$ = lasso($\\_\\_\\_$):}\\\\\nFor any previous input syntax, also returns a structure containing information about the fits. It invokes a normalized regression analysis that is appropriate for additional options with specific names and values.\\\\\n\n\\noindent \\textbf{Input: }\\\\\\\\\n\\textbf{X} is the numeric matrix. Each row represents one observation, and each column represents one predictor (variable).\\\\\\\\\n\\textbf{Y} is the numeric vector of length n, where n is the number of rows of \\textbf{X}. \\textbf{Y(i)} is the response to row i of \\textbf{X}.\\\\\n\n\\noindent \\textbf{ADMM algorithm:}\\\\\\\\\nADMM algorithm is used in an agrument called AbsTol which is used in the lasso to deal with tall array data.\\\\\nADMM is the algorithm that expands by ALM solves convex optimization problems by breaking them into smaller pieces, each of which are then easier to handle. It is aimed to make up the shortcomings of secondary punishment to make the algorithm more stable\\\\\n\n\\end{document}\n\n", "meta": {"hexsha": "37301a4b04c0927299a1667f90971f24b049fb36", "size": 6590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/HW3/HW3.tex", "max_stars_repo_name": "c235gsy/Sustech_Mathematical-Modeling", "max_stars_repo_head_hexsha": "e2187b3d181185af4927255c50b4c08ba2a5fb3e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-30T11:32:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-30T11:32:36.000Z", "max_issues_repo_path": "Latex/HW3/HW3.tex", "max_issues_repo_name": "c235gsy/Sustech_Mathematical-Modeling", "max_issues_repo_head_hexsha": "e2187b3d181185af4927255c50b4c08ba2a5fb3e", "max_issues_repo_licenses": ["MIT"], "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/HW3/HW3.tex", "max_forks_repo_name": "c235gsy/Sustech_Mathematical-Modeling", "max_forks_repo_head_hexsha": "e2187b3d181185af4927255c50b4c08ba2a5fb3e", "max_forks_repo_licenses": ["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.805907173, "max_line_length": 292, "alphanum_fraction": 0.6772382398, "num_tokens": 2424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6055235165073527}}
{"text": "\\section{Approach and Secret Weapon}\n\n\\subsection{Serial Implementation}\nWe first implemented Baum-Welch in Python with numpy, using a mix of vectorized and non-vectorized code.  \\footnote{We also used the range function instead of the xrange function in some places.  Our Python implementation also uses the default data type of numpy/Python; our later parallel implementation uses a mix of doubles and floats.  Our project desires to make a comparison based on scaling, so we don't consider these ``constant factor\" sorts of differences to be an issue.}  Our initial\nimplementation ran into serious underflow issues from the calculations of\n$\\alpha$'s and $\\beta$'s due to multiplying probabilities together. We solve\nthis by following the methods detailed by Zhai~\\cite{normalizer}. We normalize by scaling $\\alpha_i(t)$'s such that they sum up to $1$ over $i$'s---that is over all states. So \n\n\\begin{equation} \n\\sum_{i=1}^N \\hat{\\alpha}_t(i) = 1\n\\end{equation}\n\nand we want to define the normalizers $\\eta_k$ such that\n\n\\begin{equation} \n    \\hat{\\alpha}_t(i) = \\alpha_i(t) \\prod_{k=1}^t \\frac{1}{\\eta_k}\n\\end{equation}\n\nthen \n\\begin{equation}\n\\prod_{k=1}^t \\eta_k =\\sum_{i=1}^N \\alpha_t(i)\n\\end{equation}\n\nWe can define \n\\begin{equation} \n    \\hat{\\beta}_{i}(t) = \\beta_{i}(t) \\prod_{k=t+1}^T \\frac{1}{\\eta_k}\n\\end{equation}\n\nthen the formulas for $\\gamma$'s and $\\xi$'s remain the same since the normalizers cancel out.\n\nWe verify the correctness of our implementation with the library HMM function in\nMATLAB~\\cite{matlab}, and our calculations of $\\alpha$, $\\beta$, and $\\gamma$ seemed to match, though we found some disagreement in the final results, on both corner cases and non-corner cases in our final checks.  We believe that MATLAB may handle some corner cases differently, and in addition, may have a different method for computing some of the final sums necessary to update the model parameters.  Regardless, we don't think we missed anything in our implementation that would cause the performance to drastically differ, and that is what we are interested in here. \n\n\\subsection{Failed Parallel Attempt}\nWe first approached the challenge by representing the Hidden Markov model computation as one over a bipartite graph.  Consider the Markov chain that underlies the hidden Markov model.  We created two vertices for each state in this chain, one designated the ``odd vertex\" and one designated the ``even vertex\".  Call original vertex $u$'s two vertices $u_{odd}$ and $u_{even}$. For each original edge $(u, v)$ in the hidden Markov model, we created two edges in our bipartite graph, $(u_{odd}, v_{even})$, $(u_{even}, v_{odd})$.   Each vertex $v$, regardless of being an odd or even vertex, stores: \n\n\\begin{itemize}\n\t\\item Two arrays of size $\\Theta(T)$, where $T$ is the length of the observation sequence: one for each of the original state $v$'s forward and backward probabilities.  Odd vertices store forward-backward probabilities corresponding to odd time steps, and even vertices store probabilities corresponding to even time steps.  Note that it is possible to save space by a constant factor in this implementation by allocating an array of roughly $T/2$ in size.  In our initial implementation, we did not end up making this space optimization.  \n\t\n\t\\item The column of the observation matrix corresponding to its associated state in the original Markov chain, of size $\\Theta(M)$.  Note that in this approach, both copies of the vertex---odd and even---receive the same column of the observation matrix, though this redundant space usage does not affect our asymptotic space usage.\n\\end{itemize}\n\nEdges initially store the appropriate entry of the initial transition matrix $A$.  Like the observation matrix columns, the edge $a_{ij}$ values are duplicated, one for each version of an edge.\n\nWith this computation graph, one can now ``ping pong\" the computations of the forward and backward probabilities across the graph's sides.  Recall the recursive case for the forward probabilities as in equation \\ref{alpha}.\n\nSuppose $t+1$ is an even number.  Then vertex $j_{even}$ can compute a sum based\non its incoming edges, one for each original state $i$ of the form $(i_{odd},\nj_{even})$.  Vertex $i_{odd}$ stores the forward probability $\\alpha_{i}(t)$,\nsince $t$ is an odd number.  Of course, the edge joining these vertices stores\nthe relevant transition probability $a_{ij}$.  The relevant emission probability\n$b_j(O_{t + 1})$ is on the vertex $j_{even}$ too.  Thus, this sum can be computed using GraphLab's $\\tt{triple\\_apply}$ function, each relevant edge adding one term each to an accumulator variable on its right endpoint, $j_{even}$.  The backward probabilities can be computed in a similar way.\n\nRecall the equation for the next phase of the Baum-Welch training algorithm, computing $\\gamma_{it}$ values (as in equation \\ref{gamma}).\n\nThis parameter is straightforward to compute in parallel, given our graph representation: every vertex can simply compute the $\\gamma_{it}$ for odd or even $t$ pertaining to its original state $i$ in the Markov chain.  This computation can be done in parallel across all vertices.   Note that in our implementation, the normalization scheme is such that $\\sum_{j = 1}^N \\alpha_{j}(t)\\beta_{j}(t) = 1$, so the division is unnecessary, which simplifies this portion of the algorithm.\n\nBefore we get to the good stuff---updating the $A$ matrix---we need to compute\none more parameter, $\\xi_{i,j}(t)$ (see equation \\ref{xi}).\nAgain, due to normalization, the denominator here turns out to be 1.  We also\nnoted a potential optimization that we applied in serial as well: the update of\nthe hidden markov model parameters only relies on the sum $\\sum_{t = 1}^{T-1}\n\\xi_{i,j}(t) $ for fixed $(i, j)$, so in our implementation, we only store the sum for each $(i, j)$.\n\nThe numerator seemed like a perfect fit for another $\\tt{triple\\_apply}$\nfunction call.  An edge joins the node storing the $\\alpha_{i}(t)$ and the node\nstoring $\\beta_{j}(t+1)$, since one of these $t$ values is odd and the other is\neven.  This edge then provides the relevant transition probability $a_{ij}$ and\nthe observation matrix entry can just be grabbed off the version of node $j$,\nodd or even.  We realized a problem. There are, as stated before, two copies of\nthe nodes, and two edges joining copies with different parities.  The sums of\nthe $\\xi_{i,j}(t)$ values that are computed on each edge will only have access roughly half of the terms from the desired $(i, j)$ sum, because of the duplication of nodes into odd and even versions in this approach.  Communication would be required to combine the two values, and send them out to each edge for updates.  We considered performing join operations on the associated edge data table, but we worried about performance of this fix and ultimately opted for what we think is a simpler approach.\n\n\\subsection{Final Parallel Implementation}\n\nOur final parallel implementation uses a much simpler graph representation: the graph is simply the hidden Markov chain in question! No duplicated edges or vertices.  The vertices and edges store the same data as the previous implementation, except that each vertex stores all of its forward and backward probabilities, not just half of them.  By design, this approach is compact, and also distributes space for the data evenly across each of the vertices.\n\nComputation of the forward probabilities, backward probabilities, and\n$\\gamma_{it}$ probabilities can be computed similarly to before.\\footnote{In our\n    implementation, we perform the computation of the $\\gamma_{it}$ using\nvectorized arithmetic operations that GraphLab provides on the associated vertex\ndata table.}  Computation of the $\\xi_{i, j}(t)$ values can be computed similar to before, except now each edge has full access to the relevant $\\alpha$, $\\beta$ values for all $t$, not just half of them.\n\n\\subsection{Secret Weapon}\n\nWe had a lot of secret weapons. \n\n\\begin{itemize}\n    \\item \\textbf{GraphLab Create SDK (C++)}~\\cite{graphlab-create}.  Released in December 2014, this SDK ``provide[s] 3rd party extensibility to GraphLab Create.\"  After difficulty with achieving strong performance in the GraphLab programming assignment, Surat Teerapittayanon suggested that we try this SDK, and we found it powerful.\n\n    \\item \\textbf{Dato Forum}~\\cite{datoforum}.  Dato, the company behind GraphLab, was extremely helpful with our reports of bugs and other issues when working with their SDK.  We even suggested an optimization for the core library of GraphLab, which they recommended we implement and submit in a pull request!\n\n\\item \\textbf{MATLAB}~\\cite{matlab}.  MATLAB comes with an HMM library in its Machine Learning Toolkit, and this library offers invaluable functions that allow one to see $\\alpha_i(t)$, $\\beta_i(t)$,  and $\\gamma_{it}$ values for given training sequences, which was enormously invaluable in debugging.  MATLAB also reports which normalizing values are used, and used a trial-and-error debugging approach to figure out what was wrong with our code at times.  See the disclaimer earlier in the paper about matching the MATLAB implementation. \n\\end{itemize}\n", "meta": {"hexsha": "0be3519a3b944d3e75571db87af71fc23ab8d27b", "size": 9195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/approach.tex", "max_stars_repo_name": "cs205-project-group/hmm", "max_stars_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-10T04:53:33.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-10T04:53:33.000Z", "max_issues_repo_path": "paper/approach.tex", "max_issues_repo_name": "cs205-project-group/hmm", "max_issues_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_issues_repo_licenses": ["MIT"], "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/approach.tex", "max_forks_repo_name": "cs205-project-group/hmm", "max_forks_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_forks_repo_licenses": ["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.7894736842, "max_line_length": 599, "alphanum_fraction": 0.7672648178, "num_tokens": 2210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.6055235079710052}}
{"text": "\\section{Adaptive AR Model Based Time-Frequency Estimation}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n\n%% a)\n\\item\n%\n\nIn figure \\ref{fig:4_2_a_1} the non-stationary frequency, $f(n)$, and the corresponding phase, $\\phi(n)$, time-series are provided.\nClearly, the frequency is time-variant, hence a model capable of capturing non-stationarity is required.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/frequency}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/phase}\n    \\end{subfigure}\n    \\caption{FM: non-stationary frequency and phase time-series.}\n    \\label{fig:4_2_a_1}\n\\end{figure}\n\nAs expected, the static autoregressive order 1 model, AR(1), in figure \\ref{fig:4_2_a_2}, fails to adapt to $f(n)$ over time, since a single peak is detected.\nIncreasing model order does not improve performance, since the static approach is incapable of dealing with non-stationary series, regardless the capacity of the model.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/complete_aryule_1}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/complete_aryule_5}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/complete_aryule_10}\n    \\end{subfigure}\n    \\caption{FM: power spectrum and AR(p) models.}\n    \\label{fig:4_2_a_2}\n\\end{figure}\n\nThe frequency $f(n)$ is a branch function, a constant, a linear and a quadratic function, for different values of $n$. Splitting the signal into three series of segment length $N_{segment} = 500$,\nwe confirm that only the first segment (constant frequency $f = 100 Hz$ over time) can be adequately modelled, while the rest are failed due to their non-stationary nature.\nFigure \\ref{fig:4_2_a_2} illustrates the power spectral density estimates for the three segments.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/minibatch_1_aryule_1}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/minibatch_2_aryule_1}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.32\\textwidth}\n        \\centering\n        \\includegraphics[height=1in]{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/a/minibatch_3_aryule_1}\n    \\end{subfigure}\n    \\caption{FM: power spectrum of segments.}\n    \\label{fig:4_2_a_3}\n\\end{figure}\n\n%% b)\n\\item\n%\n\nHaving considered the deficiencies of the static AR models, a dynamic approach is now taken, using the CLMS algorithm, since the signal is complex.\nComparing figure \\ref{fig:4_2_b}, the time-frequency spectrum plots, with the time-series $f(n)$ in figure \\ref{fig:4_2_a_1}, we verify that the dynamic CLMS AR(1) model\nenables the modelling of non-stationary processes.\n\nThe step-size $\\mu$ of the CLMS filter is also varied, where for small values (i.e $\\mu = 0.001$) the filter does not converge in-time to the correct frequencies,\nwhile large $\\mu$ values (i.e $\\mu = 0.1$) lead to oscillations around the target value. This reflect once again the trade-off between convergence rate and steady-state error.\nThe wider bounds in the time-frequency plots (i.e for $\\mu = 0.1$) the less certain the estimate is.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/b/time_frequency-mu_0.001}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/b/time_frequency-mu_0.010}.pdf}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/b/time_frequency-mu_0.050}.pdf}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{{report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/assets/b/time_frequency-mu_0.100}.pdf}\n    \\end{subfigure}\n    \\caption{FM: CLMS time-frequency plots.}\n    \\label{fig:4_2_b}\n\\end{figure}\n\n%\n\\end{enumerate}", "meta": {"hexsha": "9980b7df484778f0b0e192d8aaebd0c9067a8e95", "size": 5669, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/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/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/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/widely-linear-filtering-and-adaptive-spectrum-estimation/adaptive-AR-model-based-time-frequency-estimation/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": 50.1681415929, "max_line_length": 196, "alphanum_fraction": 0.7422825895, "num_tokens": 1596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6055235042373938}}
{"text": "\\chapter{Frame Camera Models}\n\nAmes Stereo Pipeline supports a generic Pinhole camera model with\nseveral lens distortion models which cover common calibration methods,\nand also the somewhat more complicated panoramic (\\textit{optical bar})\ncamera model.\n\n\\section{Pinhole Models}\n\\label{pinholemodels}\n\n\\section{Overview}\n\nThe generic Pinhole model uses the following parameters:\n\n\\begin{itemize}{}\n\\item  \\textit{fu} = The focal length in horizontal pixel units.\n\\item  \\textit{fv} = The focal length in vertical pixel units.\n\\item  \\textit{cu} = The horizontal offset of the principal \npoint of the camera in the image plane in pixel units, from 0,0.\n\\item  \\textit{cv} = The vertical offset of the principal \npoint of the camera in the image plane in pixel units, from 0,0.\n\\item  \\textit{pitch} = The size of each pixel in the units used to specify\nthe four parameters listed above.  This will usually either be 1.0 if they\nare specified in pixel units or alternately the size of a pixel in millimeters.\n\\end{itemize}\n\nThe focal length is sometimes known as the \\textit{principal\ndistance}. The value $cu$ is usually approximately half the image width in\npixels times the pitch, while $cv$ is often the image height in pixels\ntimes the pitch, though there are situations when these can be quite different.\n\nA few sample Pinhole models are shown later in the text. The underlying mathematical model\nis described in section \\ref{pinholemath}.\n\nAlong with the basic Pinhole camera parameters, a lens distortion model\ncan be added.  Note that the units used in the distortion model must\nmatch the units used for the parameters listed above.  For example, if the\ncamera calibration was performed using units of millimeters the focal lengths etc. must be given in\nunits of millimeters and the pitch must be equal to the size of each pixel in millimeters.\nThe following lens distortion models are currently supported:\n\n\\begin{itemize}{}\n\\item  \\textbf{Null} = A placeholder model that applies no distortion.\n\n\\item  \\textbf{Tsai} = A common distortion model similar to the one used by OpenCV and THEIA.\n This model uses the following parameters:\n  \\begin{description}\n    \\item \\textit{K1, K2} = Radial distortion parameters.\n    \\item \\textit{P1, P2} = Tangential distortion parameters.\n  \\end{description}\n\\hfill \\\\ The following equations describe the distortion, starting with the undistorted pixel $(Px, Py)$:\n\n\\[ (x, y) = \\left(\\frac{Px - cu}{fu}, \\frac{Py-cv}{fv}\\right) \\]\n\\[ r^{2} = x^{2} + y^{2} \\]\n\\[ x(distorted) = x\\left(K_{1}r^{2} + K_{2}r^{4} + 2P_{1}y + P_{2}\\left(\\frac{r^{2}}{x} + 2x\\right)\\right)  \\]\n\\[ y(distorted) = y\\left(K_{1}r^{2} + K_{2}r^{4} + 2P_{2}x + P_{1}\\left(\\frac{r^{2}}{y} + 2y\\right)\\right)  \\]\n\\hfill \\\\ References:\n\\begin{description}\n   \\item Roger Tsai, A Versatile Camera Calibration Technique for a High-Accuracy 3D\n          Machine Vision Metrology Using Off-the-shelf TV Cameras and Lenses\n\\end{description}\n\\hfill \\\\ Note that this model uses normalized pixel units.\n\n\\item  \\textbf{Adjustable Tsai} = A variant of the Tsai model where any number of \\textit{K} terms and a skew term (alpha) can be used.  Can apply the AgiSoft Lens calibration parameters.\n\n\\item  \\textbf{Brown-Conrady} = An older model based on a centering angle.\n\n This model uses the following parameters:\n  \\begin{description}\n    \\item \\textit{K1, K2, K3} = Radial distortion parameters.\n    \\item \\textit{P1, P2} = Tangential distortion parameters.\n    \\item \\textit{xp, yp} = Principal point offset.\n    \\item \\textit{phi} = Tangential distortion angle in radians.\n  \\end{description}\n\\hfill \\\\ The following equations describe the distortion:\n\\[ x = x(distorted) - xp \\]\n\\[ y = y(distorted) - yp \\]\n\\[ r^{2} = x^{2} + y^{2} \\]\n\\[ dr = K_{1}r^{3} + K_{2}r^{5} + K_{3}r^{7} \\]\n\\[ x(undistorted) = x + x\\frac{dr}{r} - (P_{1}r^{2} +P_{2}r^{4})\\sin(phi) \\]\n\\[ y(undistorted) = y + y\\frac{dr}{r} + (P_{1}r^{2} +P_{2}r^{4})\\cos(phi) \\]\n\\hfill \\\\ Note that this model uses non-normalized pixel units, so they\nare in mm.\n\n\n\\hfill \\\\ References:\n\\begin{description}\n   \\item Decentering Distortion of Lenses - D.C. Brown, \n          Photometric Engineering, pages 444-462, Vol. 32, No. 3, 1966\n   \\item Close-Range Camera Calibration - D.C. Brown, \n          Photogrammetric Engineering, pages 855-866, Vol. 37, No. 8, 1971\n\\end{description}\n\n\\item  \\textbf{Photometrix} = A model matching the conventions used by the Australis software from Photometrix.\n\n  \\begin{description}\n    \\item \\textit{K1, K2, K3} = Radial distortion parameters.\n    \\item \\textit{P1, P2} = Tangential distortion parameters.\n    \\item \\textit{xp, yp} = Principal point offset.\n    \\item \\textit{B1, B2} = Unused parameters.\n  \\end{description}\n\\hfill \\\\ The following equations describe the distortion:\n\\[ x = x(distorted) - xp \\]\n\\[ y = y(distorted) - yp \\]\n\\[ r^{2} = x^{2} + y^{2} \\]\n\\[ dr = K_{1}r^{3} + K_{2}r^{5} + K_{3}r^{7} \\]\n\\[ x(undistorted) = x + x\\frac{dr}{r} + P_{1}(r^{2} +2x^{2}) + 2P_{2}xy \\]\n\\[ y(undistorted) = y + y\\frac{dr}{r} + P_{2}(r^{2} +2y^{2}) + 2P_{1}xy \\]\n\\hfill \\\\ Note that this model uses non-normalized pixel units, so they\nare in mm.\n\n\\item  \\textbf{RPC} = A rational polynomial coefficient model.\n\nIn this model, one goes from distorted coordinates $(x, y)$ to undistorted\ncoordinates via the formula\n\n\\[ x(undistorted) = \\frac{P_1(x, y)}{Q_1(x, y)} \\]\n\\[ y(undistorted) = \\frac{P_2(x, y)}{Q_2(x, y)} \\]\n\nThe functions in the numerator and denominator are polynomials in $x$\nand $y$ with certain coefficients. The degree of\npolynomials can be any positive integer.\n\nRPC distortion models can be generated as approximations to other pre-existing\nmodels with the tool \\texttt{convert\\_pinhole\\_model} (section \\ref{convertpinholemodel}).\n\nThis tool also creates RPC to speed up the reverse operation, of going\nfrom undistorted to distorted pixels, and those polynomial coefficients\nare also saved as part of the model.\n\n\\end{itemize}\n\n\\hrule\n\\subsection{File Formats}\n\\label{file_format}\n\\bigskip\n\nASP Pinhole model files are written in an easy to work with plain text format \nusing the extension \\texttt{.tsai}.\nA sample file is shown below. \n\n\\begin{verbatim}\nVERSION_4\nPINHOLE\nfu = 28.429\nfv = 28.429\ncu = 17.9712\ncv = 11.9808\nu_direction = 1  0  0\nv_direction = 0  1  0\nw_direction = 0  0  1\nC = 266.943 -105.583 -2.14189\nR = 0.0825447 0.996303 -0.0238243 -0.996008 0.0832884 0.0321213 0.0339869 0.0210777 0.9992\npitch = 0.0064\nPhotometrix\nxp = 0.004\nyp = -0.191\nk1 = 1.31024e-04\nk2 = -2.05354e-07\nk3 = -5.28558e-011\np1 = 7.2359e-006\np2 = 2.2656e-006\nb1 = 0.0\nb2 = 0.0\n\\end{verbatim}\n\nThe first half of the file is the same for all Pinhole models:\n\n\\begin{itemize}{}\n\\item  \\texttt{VERSION\\_X} = A header line used to track the format of the file.\n\\item  \\texttt{PINHOLE} = The type of camera model, so that other types can be stored with the .tsai extension.\n\\item  \\texttt{fu, fv, cu, cv} = The first four intrinsic parameters described in the previous section.\n\\item  \\texttt{u, v, and w\\_direction} = These lines allow an additional permutation of the \naxes of the camera coordinates.  By default, the positive column direction aligns with x, the\npositive row direction aligns with y, and downward into the image aligns with z.\n\\item  \\texttt{C} = The location of the camera center, usually in the geocentric coordinate system (GCC/ECEF).\n\\item  \\texttt{R} = The rotation matrix describing the camera's absolute pose in the coordinate system (section \\ref{pinholemath}).\n\\item  \\texttt{pitch} = The pitch intrinsic parameter described in the previous section.\n\\end{itemize}\n\nThe second half of the file describes the lens distortion model being used.  The name of the\ndistortion model appears first, followed by a list of the parameters for that model.  The number\nof parameters may be different for each distortion type.  Samples of each format are shown below:\n\n\\begin{itemize}{}\n\\item  \\textbf{Null}\n\\begin{verbatim}\nNULL\n\\end{verbatim}\n\n\\item  \\textbf{Tsai}\n\\begin{verbatim}\nTSAI\nk1 = 1.31024e-04\nk2 = -2.05354e-07\np1 = 0.5\np2 = 0.4\n\\end{verbatim}\n\n\\item  \\textbf{Adjustable Tsai}\n\\begin{verbatim}\nAdjustableTSAI\nRadial Coeff: Vector3(1.31024e-04, 1.31024e-07, 1.31024e-08)\nTangential Coeff: Vector2(-2.05354e-07, 1.05354e-07)\nAlpha: 0.4\n\\end{verbatim}\n\n\\item  \\textbf{Brown-Conrady}\n\\begin{verbatim}\nBrownConrady\nxp = 0.5\nyp = 0.4\nk1 = 1.31024e-04\nk2 = -2.05354e-07\nk3 = 1.31024e-08\np1 = 0.5\np2 = 0.4\nphi = 0.001\n\\end{verbatim}\n\n\\item  \\textbf{Photometrix}\n\\begin{verbatim}\nPhotometrix\nxp = 0.004\nyp = -0.191\nk1 = 1.31024e-04\nk2 = -2.05354e-07\nk3 = -5.28558e-011\np1 = 7.2359e-006\np2 = 2.2656e-006\nb1 = 0.0\nb2 = 0.0\n\\end{verbatim}\n\n\\item  \\textbf{RPC}\n\n\\begin{verbatim}\nRPC\nrpc_degree = 1\nimage_size = 5760 3840\ndistortion_num_x   = 0 1 0\ndistortion_den_x   = 1 0 0\ndistortion_num_y   = 0 0 1\ndistortion_den_y   = 1 0 0\nundistortion_num_x = 0 1 0\nundistortion_den_x = 1 0 0\nundistortion_num_y = 0 0 1\nundistortion_den_y = 1 0 0\n\\end{verbatim}\n\nThis sample RPC lens distortion model represents the case of no distortion, \nwhen the degree of the polynomials is 1, and both the distortion and undistortion \nformula leave the pixels unchanged, that is, the distortion transform is\n\\begin{equation*}\n(x, y) \\to (x, y) = \\left(\\frac{ 0 + 1\\cdot x + 0\\cdot y}{1 + 0\\cdot x + 0\\cdot y},\n \\frac{0 + 0\\cdot x + 1\\cdot y)}{1 + 0\\cdot x + 0\\cdot y}\\right).\n\\end{equation*}\n\nIn general, if the degree of the polynomials is $n$, there are $2(n+1)(n+2)$ coefficients. \nThe zero-th degree coefficients in the denominator are always set to 1.\n\n\\end{itemize}{}\n\nFor several years Ames Stereo Pipeline generated Pinhole files in the binary \\texttt{.pinhole} format.\nThat format is no longer supported.\n\nAlso in the past Ames Stereo Pipeline has generated a shorter version of the current file\nformat, also with the extension \\texttt{.tsai}, which only supported the TSAI lens distortion model.\nExisting files in that format can still be used by ASP.\n\nNote that the \\texttt{orbitviz} tool can be useful for checking the formatting of \\texttt{.tsai}\nfiles you create and to estimate the position and orientation. To inspect the orientation use \nthe optional \\texttt{.dae} model file input option and observe the rotation of the 3D model.\n\n\\subsection{How the Pinhole model is applied}\n\\label{pinholemath}\n\nAs mentioned in section \\ref{file_format}, the ASP Pinhole models store\nthe focal length as $fu$ and $fv$, the optical center $(cu, cv)$ (which\nis the pixel location at which the ray coming from the center of the\ncamera is perpendicular to the image plane, in units of the pixel\npitch), the vector $C$ which is the camera center in world coordinates\nsystem, and the matrix $R$ that is the transform from camera to world\ncoordinates.\n\nTo go in more detail, a point $Q$ in the camera coordinate system gets transformed\nto a point $P$ in the world coordinate system via:\n\\begin{equation*}\n P = RQ + C\n\\end{equation*}\n\nHence, to go from world to camera coordinates one does:\n\\begin{equation*}\n Q = R^{-1}  P - R^{-1}  C\n\\end{equation*}\n\nFrom here the pixel location is computed as:\n\n\\begin{equation*}\n \\frac{1}{p} \\left(fu \\frac{Q_1}{Q_3} + cu, fv \\frac{Q_2}{Q_3} + cv\\right)\n\\end{equation*}\n\nwhere $p$ is the pixel pitch.\n\n\\section{Panoramic Camera Model}\n\\label{panoramic}\n\nASP also supports a simple panoramic/optical bar camera model for use with images such as\nthe declassified Corona KH4 and Keyhole KH9 images. It implements the model\nfrom \\cite{schenk2003rigorous} with the motion compensation from \\cite{sohn2004mathematical}.\n\nSuch a model looks as follows:\n\\begin{verbatim}\nVERSION_4\nOPTICAL_BAR\nimage_size = 110507 7904\nimage_center = 55253.5 3952\npitch = 7.0e-06\nf = 0.61000001430511475\nscan_time = 0.5\nforward_tilt = -0.261799\niC = -1047140.9611702315 5508464.4323527571 3340425.4078937685\niR = -0.96635634448923746 -0.16918164442572045 0.1937343197650008 -0.23427205529446918 0.26804084264169648 -0.93448954557235941 0.10616976770014927 -0.94843643849513648 -0.29865750042675621\nspeed = 7700\nmean_earth_radius = 6371000\nmean_surface_elevation = 4000\nmotion_compensation_factor = 1.0\nscan_dir = left\n\\end{verbatim}\n\nHere, the image size and center are given in pixels, with the width followed by the\nheight. The pixel pitch and focal length \\texttt{f} are in meters. The\nscan time is seconds, the forward tilt is in radians,\nthe speed is in meters per second, and the Earth radius and mean\nsurface elevation are in meters. The initial camera center \\texttt{iC} is \nin meters, and the rotation matrix \\texttt{iR} stores the absolute pose.\n\\texttt{scan\\_dir} must be set to 'left' or 'right'.\n\\texttt{scan\\_dir} and \\texttt{use\\_motion\\_compensation}\ncontrol how the sensor model accounts accounts for the motion of the satellite\nduring the image scan.  Without the benefit of detailed historical documents it may\nrequire experimentation to find the good initial values for these cameras.  When using\n\\texttt{bundle\\_adjust}, the intrinsic parameters that are solved for are \n\\texttt{speed}, \\texttt{motion\\_compensation\\_factor}, and \\texttt{scan\\_time}.\n", "meta": {"hexsha": "ed0d9a1a03dca3a945cf2891893bf4efe6a60f73", "size": 13079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/book/pinholemodels.tex", "max_stars_repo_name": "AndrewAnnex/StereoPipeline", "max_stars_repo_head_hexsha": "084c3293c3a5382b052177c74388d9beeb79cf0b", "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": "docs/book/pinholemodels.tex", "max_issues_repo_name": "AndrewAnnex/StereoPipeline", "max_issues_repo_head_hexsha": "084c3293c3a5382b052177c74388d9beeb79cf0b", "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/book/pinholemodels.tex", "max_forks_repo_name": "AndrewAnnex/StereoPipeline", "max_forks_repo_head_hexsha": "084c3293c3a5382b052177c74388d9beeb79cf0b", "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": 38.0203488372, "max_line_length": 189, "alphanum_fraction": 0.7329306522, "num_tokens": 4153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.605440493562437}}
{"text": "\\section{The Classical Banach Spaces}\n\\subsection{The $L^p$ Spaces}\n  \\paragraph{1.}\n  \\begin{proof}\n    Put $S=\\|f\\|_\\infty$ and $T=\\|g\\|_\\infty$. Then $|f(t)|\\le S$ and $|g(t)|\\le\n    T$ a.e. Hence, $S+T\\ge |f(t)|+|g(t)| \\ge |f(t)+g(t)|$ a.e. Namely, $m\\{t:\n    \\,|f(t)+g(t)|>S+T\\}=0$. Thus, $S+T\\ge \\|f+g\\|_\\infty$ by the definition of \n    $\\esssup$.\n  \\end{proof}\n\n  \\paragraph{2.}\n  \\begin{proof}\n    Put $S=\\|f\\|_\\infty$. Since $S\\ge |f|$ a.e., \n    \\[\n      \\|f\\|_p=\n      \\left\\{\\int_0^1|f|^p\\right\\}^{1/p} \\le \n      \\left\\{\\int_0^1S^p\\right\\}^{1/p} = S.\n    \\]\n    Therefore, $\\uplim_{p\\to\\infty}\\|f\\|_p \\le S$. For the converse part, let \n    $\\vep$ be any positive number. Then the measure $\\delta$ of $E=\\{t:\\,|f(t)|>\n    S-\\vep\\}$ is positive. Hence,\n    \\[\n      \\left\\{\\int_0^1|f|^p\\right\\}^{1/p} \\ge\n      \\left\\{\\int_E|f|^p\\right\\}^{1/p} \\ge \n      \\delta^{1/p}(S-\\vep) \\to \n      S-\\vep\\quad\\text{as $p\\to\\infty$.}\n    \\]\n    Hence, $\\lowlim_{p\\to\\infty}\\ge S$, completing the proof.\n  \\end{proof}\n\n  \\paragraph{3.}\n  \\begin{proof}\n    \\[\n      \\|f+g\\|_1 = \\int|f+g| \\le \\int|f|+\\int|g| = \\|f\\|_1+\\|g\\|_1.\n    \\]\n  \\end{proof}\n\n  \\paragraph{4.}\n  \\begin{proof}\n    For every $M>\\|g\\|_\\infty$, $|g|\\le M$ a.e. Hence,\n    \\[\n      \\int|fg|\\le M\\int|f| = \\|f\\|_1 M.\n    \\]\n    Since the choice of $M$ is arbitrary, $\\int|fg|\\le \\|f\\|_1\\|g\\|_\\infty$.\n  \\end{proof}\n% end\n\n\\subsection{The Minkowski and Hölder Inequalities}\n  \\paragraph{8}\n  \\begin{proof}\n    $\\,$\\par\n    (a) The logarithm function is concave, so \n    \\[\n      \\log(a^p/p+b^q/q) \\ge \\frac{1}{p}\\log a^p + \\frac{1}{q}\\log b^q = \\log ab.\n    \\]\n    Taking $\\exp$ on the both sides yields the inequality. The equality holds \n    iff $a^p=b^q$. \\par\n    (b) The case where $p=\\infty$ has been proved in Problem 4 and the case \n    where $\\|f\\|_p=0$ or $\\|g\\|=0$ is straightforward. Hence, we assume that \n    $1<p,q<\\infty$ and $\\|f\\|_p\\|g\\|_q\\ne 0$. \\par\n    Suppose $\\alpha=\\|f\\|_p$ and $\\beta=\\|g\\|_q$. By Young's inequality, \n    \\[\n      \\left|\\frac{fg}{\\alpha\\beta}\\right| \\le \n      \\frac{1}{p}\\left(\\frac{|f|}{\\alpha}\\right)^p + \n      \\frac{1}{q}\\left(\\frac{|g|}{\\beta}\\right)^q\n    \\]\n    for every $x$. Therefore,\n    \\begin{equation}\n      \\label{eq:6.2.8.1}\n      \\int|fg| = \\alpha\\beta\\int\\left|\\frac{fg}{\\alpha\\beta}\\right|\n      \\le \\alpha\\beta\\int\\left\\{\\frac{1}{p}\\left(\\frac{|f|}{\\alpha}\\right)^p + \n      \\frac{1}{q}\\left(\\frac{|g|}{\\beta}\\right)^q\\right\\}\n      = \\alpha\\beta.\n    \\end{equation}\n    The equality holds iff the equality in Young's inequality holds a.e. iff \n    $\\beta|f|^p = \\alpha|g|^q$ a.e.\\par\n    (c) Let $p\\hp=1/p$ and $q\\hp=1-p\\hp=-q/p$. Then for any nonnegative $c$ and\n    $d$, by Young's inequality,\n    \\[\n      cd \\le \\frac{c^{p\\hp}}{p\\hp}+\\frac{d^{q\\hp}}{q\\hp}=\n      pc^{1/p} - \\frac{p}{q}d^{-q/p} \\quad\\Rightarrow\\quad\n      c^{1/p} \\ge \\frac{cd}{p} + \\frac{d^{-q/p}}{q}.\n    \\]\n    Putting $c=(ab)^p$ and $d=b^{-p}$ yields the desired inequality.\\par\n    (d) Just reverse the inequality in \\eqref{eq:6.2.8.1}.\n  \\end{proof}\n% end\n\n\\subsection{Convergence and Completeness}\n  \\paragraph{9.}\n  \\begin{proof}\n    Suppose $\\langle f_n\\rangle\\subset X$ converges to $f\\in X$. Namely, for\n    every $\\vep>0$, there exists some $N$ such that for all $n>N$, $\\|f_n-f\\|<\n    \\vep$. Hence, for every $n,m>N$, by Minkowski inequality,\n    \\[\n      \\|f_n-f_m\\| \\le \\|f_n-f\\|+\\|f-f_m\\| < 2\\vep.\n    \\]\n    Hence, $\\langle f_n\\rangle$ is a Cauchy sequence.\n  \\end{proof}\n\n  \\paragraph{10.}\n  \\begin{proof}\n    Suppose $f_n\\to f$. Then $M_n=\\|f_n-f\\|_\\infty=\\esssup|f_n-f|\\to 0$. Let\n    $E_n=\\{x:\\,|f_n(x)-f(x)|>M_m\\}$, each of which is with measure zero. And\n    therefore $E=\\bigcup_{n=1}^\\infty E_n$ is with measure zero. Note that \n    $\\tilde{E}=\\{x:\\,|f_n(x)-f(x)|<M_n,\\forall\\,n\\}$, which implies the uniform\n    convergence of $f_n$ since $M_n\\to 0$.\\par\n    For the converse part, the uniform convergence on $\\tilde{E}$ implies that\n    for every $\\vep>0$, there exists some $N$ such that for every $n>N$ and $x\n    \\in\\tilde{E}$, $|f_n(x)-f(x)|<\\vep$. Since $mE=0$, this implies $\\|f_n-f\n    \\|_\\infty=\\esssup|f_n(x)-f(x)|<\\vep$. Hence, $f_n\\to f$ in $L^\\infty$.\n  \\end{proof}\n\n  \\paragraph{11.}\n  \\begin{proof}\n    Let $\\langle f_n\\rangle\\subset L^\\infty$ be absolutely summable. Put $M_n=\n    \\|f_n\\|_\\infty$ and $A_n=\\{t:\\,|f_n(t)|>M_n\\}$. By the definition of $\\|\n    \\cdot\\|_\\infty$, $mA_n=0$. Hence, $A=\\bigcup_{n=1}^\\infty A_n$ is of measure\n    zero. \\par\n    Note that $|f_n(x)|\\le M_n$ for every $n$ and $x\\in E\\setminus A$. Thus, by\n    the Weierstrass M-test, $\\sum_{n=1}^\\infty f_n$ converges uniformly. Hence,\n    on $E\\setminus A$, $\\sup|\\sum_{n=1}^\\infty f_n - \\sum_{n=1}^N f_n|\\to 0$ as\n    $N\\to\\infty$. Since $mA=0$, this implies the summability of $\\langle f_n\n    \\rangle$.\n  \\end{proof}\n\n  \\paragraph{13.}\n  \\begin{proof}\n    Suppose $\\langle f_n\\rangle\\subset C$ be absolutely summable. Since for\n    every $x$, $0\\le|f_n(x)|\\le\\|f_n\\|$, $\\langle f_n\\rangle$ is uniformly\n    convergent on $[0,1]$. Put $s=\\sum_{n=1}^\\infty f_n$. Since each $f_n$ is \n    continuous, so is $s$. Therefore, $s\\in C$. \\par\n    For every $\\vep>0$, there exists some $N$ such that for every $n>N$ and $x\n    \\in[0,1]$, $\\left|s(x)-\\sum_{k=1}^nf_k(x)\\right|<\\vep$. Hence, $\\|s-\n    \\sum_{k=1}^nf_k\\|<\\vep$. Thus, $\\langle f_n\\rangle$ is summable and\n    therefore $C$ is a Banach space.\n  \\end{proof}\n\n  \\paragraph{16.}\n  \\begin{proof}\n    Since $\\|f_n-f\\| \\ge |\\|f_n\\|-\\|f\\||$, $f_n\\to f$ in $L^p$ implies $\\|f_n\\|\n    \\to \\|f\\|$. For the converse part, note that $2^p(|f_n|^p+|f|^p)-|f_n-f|^p\n    \\ge 0$ and for almost every $x$,\n    \\[\n      2^p(|f_n|^p+|f|^p)-|f_n-f|^p \\to 2^{p+1}|f|^p.\n    \\]\n    By Fatou's Lemma,\n    \\begin{align*}\n      2^{p+1}\\|f\\|^p = 2^{p+1}\\int|f|^p \n      &\\le \\lowlim\\int\\{2^p(|f_n|^p+|f|^p)-|f_n-f|^p\\} \\\\\n      &= 2^{p+1}\\|f\\|^p - \\uplim\\|f_n-f\\|^p.\n    \\end{align*}\n    Hence, $\\uplim\\|f_n-f\\|^p \\le 0$. Since clear that $\\lowlim\\|f_n-f\\|^p\\ge0$,\n    $\\lim\\|f_n-f\\|=0$, i.e., $f_n \\to f$ in $L^p$.\n  \\end{proof}\n\n  \\paragraph{17.}\n    I assume that $1/p+1/q=1$.\n  \\begin{proof}\n    Since $g\\in L^p$, $|g|^q$ is integrable on $E=[0,1]$ and therefore for every\n    $\\vep>0$, there exists some $\\delta$ such that for every $A\\subset E$ with\n    $mA<\\delta$, $\\int_A|g|^q<\\vep$. Meanwhile, since $f_n(x)\\to f(x)$ for \n    almost every $x$, by Egoroff's Theorem, there exists some $A\\subset E$ with\n    $mA<\\delta$ such that $f_ng$ converges to $fg$ uniformly on $E\\setminus A$.\n    \\par\n    From the uniform convergence we conclude\n    \\begin{equation}\n      \\label{eq:6.17.1}\n      \\int_{E\\setminus A} fg = \\lim_{n\\to\\infty}\\int_{E\\setminus A}f_ng.\n    \\end{equation}\n    Meanwhile, by Hölder inequality,\n    \\begin{align*}\n      \\left|\\int_A (f-f_n)g\\right| \\le \\int_A|(f-f_n)g|\n      &\\le\\left\\{\\int_A|f_n-f|^p\\right\\}^{1/p}\\left\\{\\int_A|g|^q\\right\\}^{1/q}\n      \\le M\\vep^{1/q}.\n    \\end{align*}\n    Hence, \\eqref{eq:6.17.1} can be extended to $E$.\\par\n    For $p=1$, this is not true. $f_n=n\\chi_{[0,1/n]}$ and $g=\\chi_{[0,1]}$ \n    gives a counterexample.\n  \\end{proof}\n\n  \\paragraph{18.}\n  \\begin{proof}\n    By Minkowski inequality, \n    \\[\n      \\|g_nf_n-gf\\| = \\|g_n(f_n-f)+(g_n-g)f\\| \\le \\|g_n(f_n-f)\\|+\\|(g_n-g)f\\|.\n    \\]\n    Fix $\\vep>0$. Since $f,g_n,g\\in L^p$, $|g_n-g|^p|f|^p$ is integrable and \n    therefore there exists some $\\delta>0$ such that for all subsets with \n    measure $<\\delta$, the integral of over it $<\\vep$. Meanwhile, since $g_n\\to\n    g$ a.e., by Egoroff's Theorem, there exists some $A\\subset E=[0,1]$ with $mA\n    <\\delta$ such that $g_n\\to g$ uniformly on $E\\setminus A$ and therefore \n    there exists some $N_1>0$ such that for all $n>N_1$, $|g_n(x)-g(x)|^p<\\vep$\n    for $x\\in E\\setminus A$. Thus, for every $n>N_1$,\n    \\begin{align*}\n      \\|(g_n-g)f\\|\n      &=\\left\\{\\int_{E\\setminus A}|g_n-g|^p|f|^p\\right\\}^{1/p} + \n        \\left\\{\\int_A|g_n-g|^p|f|^p\\right\\}^{1/p} \\\\\n      & \\le \\sqrt[p]{\\vep}\\|f\\| + \\sqrt[p]{\\vep} \\le (\\|f\\|+1)\\vep.\n    \\end{align*}\n    Since $|g_n|\\le M$, $\\|g_n(f_n-f)\\|\\le M\\|f_n-f\\|$. And since $f_n\\to f$ in \n    $L^p$, there exists some $N_2>0$ such that for all $n>N_2$, $\\|f_n-f\\|<\n    \\vep$. Put $N=\\max(N_1,N_2)$, then for every $n>N$,\n    \\[\n      \\|g_nf_n-gf\\| \\le (\\|f\\|+1+M)\\vep.\n    \\]\n    Hence, $g_nf_n\\to gf$ in $L^p$.\n  \\end{proof}\n% end\n\n\\subsection{Approximation in $L^p$}\n  \\paragraph{19.}\n  \\begin{proof}\n    Since $\\|T_\\Delta f\\|\\le \\|T_\\Delta|f|\\|$ and $\\|f\\|=\\||f|\\|$, we may assume\n    without loss of generality that $f\\ge 0$. For $p>1$, by Jensen's inequality,\n    \\begin{align*}\n      \\|T_\\Delta f\\|_p^p \n      &= \\sum_{k=1}^m\\int_{\\xi_{k-1}}^{\\xi_k}\n      \\left(\\frac{1}{\\xi_k-\\xi_{k-1}}\\int_{\\xi_{k=1}}^{\\xi_k}f\\right)^p \\\\\n      &\\le \\sum_{k=1}^m\\int_{\\xi_{k-1}}^{\\xi_k}\n      \\frac{1}{\\xi_k-\\xi_{k-1}}\\int_{\\xi_{k-1}}^{\\xi_k}f^p \\\\\n      &= \\sum_{k=1}^m\\int_{\\xi_{k-1}}^{\\xi_k}f^p \\\\\n      &= \\int_0^1f^p = \\|f\\|_p^p.\n    \\end{align*}\n  \\end{proof}\n% end\n", "meta": {"hexsha": "86e8aec26836e39d2717e5efdfaabf3235e2ea83", "size": 9018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real_analysis_3rd/ch6_the_classical_banach_spaces.tex", "max_stars_repo_name": "Engineev/solutions", "max_stars_repo_head_hexsha": "4e33274fe1ed9e46fd0e6671c57cb589704939bd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-07-13T08:36:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T17:37:17.000Z", "max_issues_repo_path": "real_analysis_3rd/ch6_the_classical_banach_spaces.tex", "max_issues_repo_name": "Engineev/solutions", "max_issues_repo_head_hexsha": "4e33274fe1ed9e46fd0e6671c57cb589704939bd", "max_issues_repo_licenses": ["MIT"], "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_3rd/ch6_the_classical_banach_spaces.tex", "max_forks_repo_name": "Engineev/solutions", "max_forks_repo_head_hexsha": "4e33274fe1ed9e46fd0e6671c57cb589704939bd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-28T00:05:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-28T00:05:28.000Z", "avg_line_length": 39.7268722467, "max_line_length": 80, "alphanum_fraction": 0.5545575516, "num_tokens": 3844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.6053768229185922}}
{"text": "\\chapter{Good behaviour inside math mode}\n\n\n\n\n\n\\section{Using the right commands and symbols}\n\n\n\n\\subsection{General symbols}\n\\index{symbols}\n\nUse the correct symbols.\n\\Cref{wrong symbol list} shows some popular sources of this problem.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begin{tabular}{@{}lllll@{}}\n      \\toprule\n      \\theading{symbol}\n      &\n      \\multicolumn{2}{c}{\\theading{right commands}}\n      &\n      \\multicolumn{2}{c}{\\theading{wrong commands}}\n    \\\\\n    \\midrule\n      element relation\n      &\n      \\comname{in}%\n      \\massindex{in}[\\comname]\n      &\n      $\\in$\n      &\n      \\comname{epsilon}%\n      \\massindex{epsilon}[\\comname]\n      &\n      $\\epsilon$\n    \\\\\n      {}\n      &\n      {}\n      &\n      {}\n      &\n      \\comname{varepsilon}%\n      \\massindex{varepsilon}[\\comname]\n      &\n      $\\varepsilon$\n    \\\\\n      {}\n      &\n      \\comname{ni}%\n      \\massindex{ni}[\\comname]\n      &\n      $\\ni$\n      &\n      \\comname{backepsilon}%\n      \\massindex{backepsilon}[\\comname]\n      &\n      $\\backepsilon$\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      empty set\n      &\n      \\comname{emptyset}%\n      \\massindex{emptyset}[\\comname]\n      &\n      $\\emptyset$\n      &\n      \\comname{phi}%\n      \\massindex{phi}[\\comname]\n      &\n      $\\phi$\n    \\\\\n      {}\n      &\n      \\comname{varnothing}%\n      \\massindex{varnothing}[\\comname]\n      &\n      $\\varnothing$\n      &\n      {}\n      &\n      {}\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      set difference\n      &\n      \\inlinecode{A {\\tbs}setminus B}%\n      \\massindex{setminus}[\\comname]\n      &\n      $A \\setminus B$\n      &\n      \\inlinecode{A {\\tbs}backslash B}%\n      \\massindex{backslash}[\\comname]\n      &\n      $A \\backslash B$\n    \\\\\n      {}\n      &\n      \\inlinecode{A {\\tbs}smallsetminus B}%\n      \\massindex{smallsetminus}[\\comname]\n      &\n      $A \\smallsetminus B$\n      &\n      {}\n      &\n      {}\n    \\\\\n      {}\n      &\n      \\inlinecode{A - B}\\index{minus sign}\n      &\n      $A - B$\n      &\n      {}\n      &\n      {}\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      implication\n      &\n      \\comname{implies}%\n      \\massindex{implies}[\\comname]\n      &\n      $\\implies$\n      &\n      \\comname{Rightarrow}%\n      \\massindex[arrows]{Rightarrow}[\\comname]\n      &\n      $\\Rightarrow$\n    \\\\\n      {}\n      &\n      {}\n      &\n      {}\n      &\n      \\inlinecode{=>}\n      &\n      $=>$\n    \\\\\n      {}\n      &\n      \\comname{impliedby}%\n      \\massindex{impliedby}[\\comname]\n      &\n      $\\impliedby$\n      &\n      \\comname{Leftarrow}%\n      \\massindex[arrows]{Leftarrow}[\\comname]\n      &\n      $\\Leftarrow$\n    \\\\\n      {}\n      &\n      {}\n      &\n      {}\n      &\n      \\inlinecode{<=}\n      &\n      $<=$\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      equivalence\n      &\n      \\comname{iff}%\n      \\massindex{iff}[\\comname]\n      &\n      $\\iff$\n      &\n      \\comname{Leftrightarrow}%\n      \\massindex[arrows]{Leftrightarrow}[\\comname]\n      &\n      $\\Leftrightarrow$\n    \\\\\n      {}\n      &\n      {}\n      &\n      {}\n      &\n      \\inlinecode{<=>}\n      &\n      <=>\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      definition\n      &\n      \\comname{coloneqq}%\n      \\massindex{coloneqq}[\\comname]\n      &\n      $\\coloneqq$\n      &\n      \\inlinecode{:=}\n      &\n      $:=$\n    \\\\\n      {}\n      &\n      \\comname{eqqcolon}%\n      \\massindex{eqqcolon}[\\comname]\n      &\n      $\\eqqcolon$\n      &\n      \\inlinecode{=:}\n      &\n      $=:$\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      norm\n      &\n      \\inlinecode{{\\tbs}| x {\\tbs}|}%\n      \\massindex[delimiters]{\\indexline}[\\comname]\n      &\n      $\\| x \\|$\n      &\n      \\inlinecode{|| x ||}\n      &\n      $|| x ||$\n    \\\\\n      {}\n      &\n      \\inlinecode{{\\tbs}lVert x {\\tbs}rVert}%\n      \\massindex[delimiters]{lVert}[\\comname]%\n      \\massindex[delimiters]{rVert}[\\comname]\n      &\n      {}\n      &\n      {}\n      &\n      {}\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      pointy brackets\n      &\n      \\inlinecode{{\\tbs}langle x {\\tbs}rangle}%\n      \\massindex[delimiters]{langle}[\\comname]%\n      \\massindex[delimiters]{rangle}[\\comname]\n      &\n      $\\langle x \\rangle$\n      &\n      \\inlinecode{< x >}\n      &\n      $< x >$\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      infinity\n      &\n      \\comname{infty}%\n      \\massindex{infty}[\\comname]\n      &\n      $\\infty$\n      &\n      \\inlinecode{oo}\n      &\n      $oo$\n    \\\\\n    \\cmidrule(lr){2-3} \\cmidrule(l){4-5}\n      function colon\n      &\n      \\inlinecode{f {\\tbs}colon X {\\tbs}to Y}%\n      \\massindex{colon}[\\comname]%\n      \\massindex{ni}[\\comname]\n      &\n      $f \\colon X \\to Y$\n      &\n      \\inlinecode{f : X {\\tbs}to Y}\n      &\n      $f : X \\to Y$\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n  \\caption{Right symbols and wrong symbols.}\n  \\label{wrong symbol list}\n\\end{table}\nNote that the commands~\\comname{rightarrow}\\massindex[arrows]{rightarrow}[\\comname] and~\\comname{to}\\massindex[arrows]{to}[\\comname] give the same arrow.\nSo use whichever is more appropriate in the given situation.\n\n\n\n\\subsection{Operations}\n\nMany mathematical operations have both a binary version and an operator version, where the operation can range over some index set.\nOne should not confuse the two of them.\n\\Cref{binary vs operator} shows some popular binary operations and their operator counterpart.\n\\begin{table}[tb]\n  \\begin{center}\n    \\begingroup\n    \\renewcommand{\\arraystretch}{1.3}\n    \\begin{tabular}{@{}llclc@{}}\n      \\toprule\n      \\theading{operation}\n      &\n      \\multicolumn{2}{c}{\\theading{binary}}\n      &\n      \\multicolumn{2}{c}{\\theading{generalized}}\n      \\\\\n      \\cmidrule(lr){2-3}\n      \\cmidrule(l){4-5}\n      sum\n      &\n      \\inlinecode{+}\n      &\n      $a + b$\n      &\n      \\comname{sum}\n      &\n      $\\sum_i x_i$\n      \\\\\n      multiplication\n      &\n      \\comname{cdot}\n      &\n      $a \\cdot b$\n      &\n      \\comname{prod}\n      &\n      $\\prod_i x_i$\n      \\\\\n      direct sum\n      &\n      \\comname{oplus}\n      &\n      $A \\oplus B$\n      &\n      \\comname{bigoplus}\n      &\n      $\\bigoplus_i X_i$\n      \\\\\n      tensor product\n      &\n      \\comname{otimes}\n      &\n      $A \\otimes B$\n      &\n      \\comname{bigotimes}\n      &\n      $\\bigotimes_i X_i$\n      \\\\\n      wedge\n      &\n      \\comname{wedge}\n      &\n      $a \\wedge b$\n      &\n      \\comname{bigwedge}\n      &\n      $\\bigwedge_i X_i$\n      \\\\\n      union\n      &\n      \\comname{cup}\n      &\n      $A \\cup B$\n      &\n      \\comname{bigcup}\n      &\n      $\\bigcup_i X_i$\n      \\\\\n      intersection\n      &\n      \\comname{cap}\n      &\n      $A \\cap B$\n      &\n      \\comname{bigcap}\n      &\n      $\\bigcap_i X_i$\n      \\\\\n      product\n      &\n      \\comname{times}\n      &\n      $A \\times B$\n      &\n      \\comname{prod}\n      &\n      $\\prod_i X_i$\n      \\\\\n      {}\n      &\n      \\comname{sqcap}\n      &\n      $A \\sqcap B$\n      &\n      \\comname{bigsqcap}\n      &\n      $\\bigsqcap_i X_i$\n      \\\\\n      coproduct\n      &\n      \\comname{amalg}\n      &\n      $A \\amalg B$\n      &\n      \\comname{coprod}\n      &\n      $\\coprod_i X_i$\n      \\\\\n      {}\n      &\n      \\comname{sqcup}\n      &\n      $A \\sqcup B$\n      &\n      \\comname{bigsqcup}\n      &\n      $\\bigsqcup_i X_i$\n      \\\\\n      \\bottomrule\n    \\end{tabular}\n    \\endgroup\n  \\end{center}\n  \\caption{Binary operation and operator version.}\n  \\label{binary vs operator}\n\\end{table}\nThe command \\comname{bigsqcap} requires the package \\packname{stmaryrd}.\n\n\n\n\\subsection{Negations}\n\nFor some mathematical symbols there also exists a negated version, which is formed by diagonal line through the symbol.\nA general way of introducing such a line is the command \\comname{not}\\massindex[negation]{not}[\\comname].\n\\begin{showlatex}*{Using \\comname{not}}\n  It follows that $A \\not\\ni x$.\n\\end{showlatex}\nBut in practice this command should seldom be used, as it often produces very bad looking output.\nConsider the following example:\n\\begin{showlatex}{Why not to use \\comname{not}}\n  Hence $A \\not\\implies B$.\n\\end{showlatex}\nThere are two solutions to this problem:\n\nMany symbols already have a predefined lined-out version available.\nA few of them are collected in~\\cref{negation list}.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begin{tabular}{@{}lclc@{}}\n    \\toprule\n      \\multicolumn{2}{c}{\\theading{right}}\n    &\n      \\multicolumn{2}{c}{\\theading{wrong}}\n    \\\\\n    \\cmidrule(r){1-2} \\cmidrule(l){3-4}\n      \\comname{notin}%\n      \\massindex[negation]{notin}[\\comname]\n      &\n      $\\notin$\n      &\n      \\inlinecode{{\\tbs}not{\\tbs}in}\n      &\n      $\\not\\in$\n    \\\\\n      \\comname{nexists}%\n      \\massindex[negation]{nexists}[\\comname]\n      &\n      $\\nexists$\n      &\n      \\inlinecode{{\\tbs}not{\\tbs}exists}\n      &\n      $\\not\\exists$\n    \\\\\n      \\comname{neq}%\n      \\massindex[negation]{neq}[\\comname]\n      &\n      $\\neq$\n      &\n      \\inlinecode{{\\tbs}not =}\n      &\n      $\\not =$\n    \\\\\n      \\comname{nleq}%\n      \\massindex[negation]{nleq}[\\comname]\n      &\n      $\\nleq$\n      &\n      \\inlinecode{{\\tbs}not{\\tbs}leq}\n      &\n      $\\not\\leq$\n    \\\\\n      \\comname{nrightarrow}%\n      \\massindex[negation,arrows]{notrightarrow}[\\comname]\n      &\n      $\\nrightarrow$\n      &\n      \\inlinecode{{\\tbs}not{\\tbs}rightarrow}\n      &\n      $\\not\\rightarrow$\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n  \\caption{Negated versions of popular symbols.}\n  \\label{negation list}\n\\end{table}\nIf the required symbol is not predefined then the command~\\comname{centernot}\\massindex[negation]{centernot}[\\comname] from the package~\\packname{centernot}\\massindex[packages]{centernot}[\\packname] often produces better looking output than~\\comname{not}:\n\\begin{showlatex}{Using the command~\\comname{centernot}}\n  Consider\n  \\[\n    A \\centernot\\ni x\n    \\quad\\text{versus}\\quad\n    \\quad\n    A \\not\\ni x \\,.\n  \\]\n  Consider also\n  \\[\n    A \\centernot\\implies B\n    \\quad\\text{versus}\\quad\n    A \\not\\implies B \\,.\n  \\]\n\\end{showlatex}\n\n\n\n\\subsection{Don’t use \\comtitle{limits}}\n\nPeople seem to think that they have to put \\comname{limits}\\massindex[limits]{limits}[\\comname] after a command to add limits to it:\n\\begin{showlatex}*{Using~\\comname{limits}}\n\\[\n  \\sum\\limits_{k=1}^n k\n  =\n  \\frac{n(n+1)}{2}\n\\]\n\\end{showlatex}\nBut this is not only unnecessary, but also dangerous.\nIt is unnecessary because (most of) the commands in questions already have this functionality built in:\n\\begin{showlatex}*{Using built-in limits}\n\\[\n  \\sum_{k=1}^n k\n  =\n  \\frac{n(n+1)}{2}\n\\]\n\\end{showlatex}\nThese built-in limits have the advantage that they can distinguish between inline math and display math:\n\\begin{showlatex}*{Inline math vs.\\ display math with built-in limits}\nThe sum $\\sum_{k=0}^n 2^k = 2^{n+1} - 1$ is inline while the sum\n\\[\n  \\sum_{k=0}^n 3^k\n  \\neq\n  3^{n+1} - 1\n\\]\nis in display mode.\n\\end{showlatex}\nWe can see that the inline version does not only use the smaller summation sign but also sets the limits to the right of the summation sign.\nThis is a feature which \\comname{limits} version is missing:\n\\begin{showlatex}*{Inline math with~\\comname{limits}}\nSo here is some text which will generate some lines.\nThe text itself isn’t important, but we really want it to fill some lines.\nThe important thing is the sum $\\sum\\limits_{k=0}^n k$.\nWell, not really the sum itself, but the use of \\texttt{{\\textbackslash}limits} for typesetting it.\n\\end{showlatex}\nThe limits are still placed above the top and below the summation sign.\nThis has its price:\nThe line in which the sum resides breaks the usual vertical space between lines, which gives the text an inconsistent and unorganized look.\nCompare this to the version without \\comname{limits}:\n\\begin{showlatex}*{Inline with built-in limits}\nSo here is some text which will generate some lines.\nThe text itself isn’t important, but we really want it to fill some lines.\nThe important thing is the sum $\\sum_{k=0}^n k$.\nWell, not really the sum itself, but use of built-in limits for typesetting it.\n\\end{showlatex}\nHere the line distance is nicely consistent and pleasing to the eye.\n\nThe usual predefined commands on which one would expect limits already have them defined, e.g.\\ \\comname{sum}, \\comname{prod} or \\comname{lim}, as the following example shows:\n\\begin{showlatex}{Inline vs.\\ display for different commands with built-in limits}\nCompare the inline versions $\\sum_{k=0}^n k$ and $\\prod_{k=1}^n k$ and $\\lim_{n \\to \\infty} a_n$ with the display versions\n\\[\n  \\sum_{k=0}^n k \\,,\n  \\quad\n  \\prod_{k=1}^n k \\,,\n  \\quad\n  \\lim_{n \\to \\infty} a_n \\,.\n\\]\n\\end{showlatex}\nIf a new commands are defined with~\\comname{DeclareMathOperator}\\massindex[defining commands]{DeclareMathOperator}[\\comname] or~\\comname{operatorname}\\massindex[defining commands]{operatorname}[\\comname] then one can make them support limits by using \\comname{DeclareMathOperator*}\\massindex[defining commands, limits]{DeclareMathOperator*}[\\comname] and \\comname{operatorname*}\\massindex[defining commands, limits]{operatorname*}[\\comname] instead.\nSuppose for example that we have made in the preamble the following definition:\n\\begin{showcode}{Using \\comname{DeclareMathOperator*} to define~\\comname{colim}}\n\\DeclareMathOperator*{\\colim}{colim}\n\\end{showcode}\nWe can then do the following:\n\\begin{showlatex}{Using~\\comname{colim}}\nInline we have $\\colim_{X' \\leq X} F(X')$ and in display mode we get\n\\[\n  \\colim_{X' \\leq X} F(X') \\,.\n\\]\n\\end{showlatex}\nThe command~\\comname{operatorname*} was named~\\comname{operatornamewithlimits} in the past, but this name is deprecated.\n\n% If for some extremly strange reason one \\emph{really} needs the limits to be in display style, then one should commit to it by using \\comname{displaystyle}.\n% Consider the following example:\n% \\begin{showlatex}{Forcing displaystyle with \\comname{displaystyle}}\n% \\[\n%   \\begin{pmatrix}\n%     \\frac{n^2+1}{n^2 + 2}\n%     &\n%     \\frac{n^2+2}{n^2 + 3}\n%     \\\\\n%     \\frac{n^2+2}{n^2 + 3}\n%     &\n%     \\frac{n^2+3}{n^2 + 4}\n%   \\end{pmatrix}\n%   =\n%   \\begin{pmatrix}\n%     \\displaystyle\n%     \\frac{n^2+1}{n^2 + 2}\n%     &\n%     \\displaystyle\n%     \\frac{n^2+2}{n^2 + 3}\n%     \\\\[1.5em]\n%     \\displaystyle\n%     \\frac{n^2+2}{n^2 + 3}\n%     &\n%     \\displaystyle\n%     \\frac{n^2+3}{n^2 + 4}\n%   \\end{pmatrix}\n% \\]\n% \\end{showlatex}\n% In the above example we have put~\\comname{displaystyle} before every matrix entry to ensure that it has the usual style of display mathematics.\n% We have also put replaced the basic line break~\\comname{\\tbs} by~\\inlinecode{{\\tbs}{\\tbs}[1.5em]} for some additional spacing between the two rows of the resulting matrix.\n% (Otherwise the fractions are far too close.)\n\n\n\n\\subsection{Use extensible arrows instead of \\comtitle{overset} and \\comtitle{underset}}\n\\label{extensible arrows}\n\nSome people put text above or under arrows by wrongly using the commands~\\comname{overset}\\massindex{overset}[\\comname] or \\comname{underset}\\massindex{underset}[\\comname]:\n\\begin{showlatex}{Using~\\comname{overset} and~\\comname{underset} to put text above or below an arrow}\n\\[\n  X\n  \\overset{f}{\\longrightarrow}\n  Y\n  \\underset{g \\circ h \\circ k}{\\longrightarrow}\n  Z\n\\]\n\\end{showlatex}\nWe can see above that the length of the arrow does not adjust to the size of the text above it or below it.\nThe proper way to put text on top of an arrow or bellow an arrow of the form~\\enquote{$\\to$} is therefore the command~\\comname{xrightarrow}\\massindex[arrows]{xrightarrow}[\\comname]:\n\\begin{showlatex}{Using~\\comname{xrightarrow} to put text above or below an arrow}\n\\[\n  X\n  \\xrightarrow{f}\n  Y\n  \\xrightarrow[g \\circ h \\circ k]{}\n  Z \\,.\n\\]\n\\end{showlatex}\nThe package~\\packname{amsmath}\\massindex[packages]{amsmath}[\\packname] defines only the two most basic extensible arrows\\index{extensible arrows}\\index{arrows!extensible}.\nMany more kinds of extensible arrows are provided by the package~\\packname{mathtools}\\massindex[packages]{mathtools}[\\packname] and some more are contained in the package~\\packname{extarrows}\\massindex[packages]{extarrows}[\\packname].\nAn overview of the various kinds of extensible arrows can be found in \\cref{extensible arrow table}.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begingroup\n  \\renewcommand{\\arraystretch}{0.9}\n  \\begin{tabular}{@{}lccc@{}}\n    \\toprule\n    \\packname{amsmath}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xrightarrow{f} B$\n      \\\\\n      \\comname{xrightarrow}%\n      \\massindex[arrows]{xrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftarrow{f} B$\n      \\\\\n      \\comname{xleftarrow}%\n      \\massindex[arrows]{xleftarrow}[\\comname]\n    \\end{tabular}\n    &\n    {}\n    \\\\[1.5em]\n%     \\midrule\n    \\packname{mathtools}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xmapsto{f} B$\n      \\\\\n      \\comname{xmapsto}%\n      \\massindex[arrows]{xmapsto}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftrightarrow{f} B$\n      \\\\\n      \\comname{xleftrightarrow}%\n      \\massindex[arrows]{xleftrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xRightarrow{f} B$\n      \\\\\n      \\comname{xRightarrow}%\n      \\massindex[arrows]{xRightarrow}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLeftarrow{f} B$\n      \\\\\n      \\comname{xLeftarrow}%\n      \\massindex[arrows]{xLeftarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLeftrightarrow{f} B$\n      \\\\\n      \\comname{xLeftrightarrow}%\n      \\massindex[arrows]{xLeftrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xhookleftarrow{f} B$\n      \\\\\n      \\comname{xhookleftarrow}%\n      \\massindex[arrows]{xhookleftarrow}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xhookrightarrow{f} B$\n      \\\\\n      \\comname{xhookrightarrow}%\n      \\massindex[arrows]{xhookrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xrightharpoondown{f} B$\n      \\\\\n      \\comname{xrightharpoondown}%\n      \\massindex[arrows]{xrightharpoondown}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xrightharpoonup{f} B$\n      \\\\\n      \\comname{xrightharpoonup}%\n      \\massindex[arrows]{xrightharpoonup}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xrightleftharpoons{f} B$\n      \\\\\n      \\comname{xrightleftharpoons}%\n      \\massindex[arrows]{xrightleftharpoons}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftharpoondown{f} B$\n      \\\\\n      \\comname{xleftharpoondown}%\n      \\massindex[arrows]{xleftharpoondown}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftharpoonup{f} B$\n      \\\\\n      \\comname{xleftharpoonup}%\n      \\massindex[arrows]{xleftharpoonup}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftrightharpoons{f} B$\n      \\\\\n      \\comname{xleftrightharpoons}%\n      \\massindex[arrows]{xleftrightharpoons}[\\comname]\n    \\end{tabular}\n    &\n    {}\n    &\n    {}\n    \\\\[1.5em]\n%     \\midrule\n    \\packname{extarrows}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xlongequal{f} B$\n      \\\\\n      \\comname{xlongequal}%\n      \\massindex[arrows]{xlongequal}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xleftrightarrow{f} B$\n      \\\\\n      \\comname{xleftrightarrow}%\n      \\massindex[arrows]{xleftrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLeftrightarrow{f} B$\n      \\\\\n      \\comname{xLeftrightarrow}%\n      \\massindex[arrows]{xLeftrightarrow}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xlongleftarrow{f} B$\n      \\\\\n      \\comname{xlongleftarrow}%\n      \\massindex[arrows]{xlongleftarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xlongrightarrow{f} B$\n      \\\\\n      \\comname{xlongrightarrow}%\n      \\massindex[arrows]{xlongrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xlongleftrightarrow{f} B$\n      \\\\\n      \\comname{xlongleftrightarrow}%\n      \\massindex[arrows]{xlongleftrightarrow}[\\comname]\n    \\end{tabular}\n    \\\\[1.5em]\n    {}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLongleftarrow{f} B$\n      \\\\\n      \\comname{xLongleftarrow}%\n      \\massindex[arrows]{xLongleftarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLongrightarrow{f} B$\n      \\\\\n      \\comname{xLongrightarrow}%\n      \\massindex[arrows]{xLongrightarrow}[\\comname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{@{}c@{}}\n      $A \\xLongleftrightarrow{f} B$\n      \\\\\n      \\comname{xLongleftrightarrow}%\n      \\massindex[arrows]{xLongrightarrow}[\\comname]\n    \\end{tabular}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\endgroup\n  \\end{center}\n \\caption{Extensible arrows in \\packname{amsmath}, \\packname{mathtools} and \\packname{extarrows}.}\n \\label{extensible arrow table}\n\\end{table}\n\nThe author recommends to define custom commands as shortcuts for the most used arrows.\n\\begin{showlatex}{Defining arrow commands as shortcuts}\n\\newcommand{\\xto}{\\xrightarrow}\n\\newcommand{\\xlongto}[1]{\\xlongrightarrow{\\;#1\\;}}\nThe function $A \\xto{f} B$ is the same as\n\\[\n  A \\xlongto{f} B \\,.\n\\]\n\\end{showlatex}\n\n% TODO: Defining new kind of stretchable arrows\n\n\n\n\n\n\\subsection{Know your ellipses}\n\\index{dots!zzzz@\\igobble |see {ellipsis}}\n\\index{ellipses|(}\n\nAn ellipsis\\index{ellipses} should \\emph{never} by written as~\\inlinecode{...} (three single dots).\n{\\LaTeX} instead provides different kinds of ellipses to use in math mode, namely\n\\begin{center}\n    \\comname{dotsb},\n    \\quad\n    \\comname{dotsc},\n    \\quad\n    \\comname{dotsm},\n    \\quad\n    \\comname{dotsi},\n    \\quad\n    \\comname{dotso},\n    \\\\\n    \\comname{cdots},\n    \\quad\n    \\comname{ddots},\n    \\quad\n    \\comname{vdots},\n    \\quad\n    \\comname{ldots}.\n\\end{center}\nEach of these have they own role and (mostly) distinct look and feel.\nThere are two groups of ellipses.\nThe first group consists of \\comname{dotsb}, \\comname{dotsc}, \\comname{dotsm}, \\comname{dotsi},\\comname{dotso}, whereas the second group consists of \\comname{cdots}, \\comname{ddots}, \\comname{vdots}, \\comname{ldots}.\n\nThe ellipses in the first group are named after their function, see \\cref{ellipses with function}.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begingroup\n  \\renewcommand{\\arraystretch}{1.3}\n  \\begin{tabular}{@{}lll@{}}\n    \\toprule\n    %\n    \\theading{command}\n    &\n    \\theading{where to use}\n    &\n    \\theading{example}\n    \\\\\n    \\midrule\n    %\n    \\comname{dotsb}%\n    \\massindex[ellipses]{dotsb}[\\comname]\n    &\n    between binary relations\n    &\n    $x_1 \\leq \\dotsb \\leq x_n$\n    \\\\\n    {}\n    &\n    and binary operations\n    &\n    $x_1 + \\dotsb + x_n$\n    \\\\\n    \\comname{dotsc}%\n    \\massindex[ellipses]{dotsc}[\\comname]\n    &\n    between commas\n    &\n    $x_1, \\dotsc, x_n$\n    \\\\\n    \\comname{dotsm}%\n    \\massindex[ellipses]{dotsm}[\\comname]\n    &\n    abbreviating multiplication\n    &\n    $x_1 \\dotsm x_n$\n    \\\\\n    \\comname{dotsi}%\n    \\massindex[ellipses]{dotsi}[\\comname]\n    &\n    iterated integrals\\index{integral}\n    &\n    $\\int_{X_1} \\dotsi \\int_{X_n}$\n    \\\\\n    \\comname{dotso}%\n    \\massindex[ellipses]{dotso}[\\comname]\n    &\n    others\n    &\n    {}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\endgroup\n  \\end{center}\n  \\caption{Ellipses with a specific functions.}\n  \\label{ellipses with function}\n\\end{table}\nNote that the members of this group all have names of the form \\comname{dots*}, where \\optname{*} is a letter that specifies the semantic use of the ellipsis.\n\nThe ellipses in the second group are not named after their function but after their orientation, see \\cref{ellipses with orientation}\n\\begin{table}[tb]\n  \\begin{center}\n  \\begingroup\n  \\renewcommand{\\arraystretch}{1.3}\n  \\begin{tabular}{@{}llc@{}}\n    \\toprule\n    %\n    \\theading{command}\n    &\n    \\theading{description}\n    &\n    \\theading{look}\n    \\\\\n    \\midrule\n    %\n    \\comname{cdots}%\n    \\massindex[ellipses]{cdots}[\\comname]\n    &\n    Horizontal dots, vertically centered.\n    &\n    $\\cdots$\n    \\\\\n    \\comname{ddots}%\n    \\massindex[ellipses]{ddots}[\\comname]\n    &\n    Diagonal dots.\n    &\n    $\\ddots$\n    \\\\\n    \\comname{vdots}%\n    \\massindex[ellipses]{vdots}[\\comname]\n    &\n    Vertical dots, horizontally centered.\n    &\n    $\\vdots$\n    \\\\\n    \\comname{ldots}%\n    \\massindex[ellipses]{ldots}[\\comname]\n    &\n    Lowered dots.\n    &\n    $\\ldots$\n    % making this line as high as the others\n    \\vphantom{$\\vdots$}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\endgroup\n  \\end{center}\n  \\caption{Ellipses with a specific orientation.}\n  \\label{ellipses with orientation}\n\\end{table}\nThe ellipses~\\comname{cdots},~\\comname{ddots} and~\\comname{vdots} are typically used in matrices.\n\\begin{showlatex}{Typical usage of the ellipses~\\comname{cdots},~\\comname{vdots},~\\comname{ddots}}\n\\[\n  \\begin{pmatrix}\n    a_{11} & \\cdots & a_{1n} \\\\\n    \\vdots & \\ddots & \\vdots \\\\\n    a_{n1} & \\cdots & a_{nn}\n  \\end{pmatrix}\n\\]\n\\end{showlatex}\nThe command~\\comname{ldots} may be used to denote left out digits or symbols.\n\\begin{showlatex}{Using the ellipsis~\\comname{ldots}}\nWe find that\n\\[\n  x = 0.1234567891011\\ldots\n\\]\nConsider the word $w = a_1 \\ldots a_n$ where $a_1, \\dotsc, a_n$ are letters in an alphabet $\\Sigma$.\n\\end{showlatex}\nNote that the members of this second group of dots all have names of the form~\\comname{*dots}, where~\\optname{*} is a letter that specified the positioning of these dots.\n\n% The following should \\emph{never} be used to denote a product:\n% \\begin{showcode}{Wrong way of abbreviating multiplication~I}\n% x_1 \\cdot {any kind of dots} \\cdot x_n\n% \\end{showcode}\n% So all of the following are \\emph{wrong}, and some of them look even worse then the other ones.\n% \\begin{showlatex}*{Wrong way of abbreviating multiplication~II}\n% \\begin{gather*}\n%   x_1 \\cdot \\dotsb \\cdot x_n \\\\\n%   x_1 \\cdot \\dotsc \\cdot x_n \\\\\n%   x_1 \\cdot \\dotsm \\cdot x_n \\\\\n%   x_1 \\cdot \\dotsi \\cdot x_n \\\\\n%   x_1 \\cdot \\cdots \\cdot x_n \\\\\n%   x_1 \\cdot \\ldots \\cdot x_n\n% \\end{gather*}\n% \\end{showlatex}\n% (The author hopes that nobody is stupid enough to even trying using \\comname{ddots} or \\comname{vdots} in this situation.)\n\nSo overall one should use the ellipses~\\comname{cdots}, \\comname{ddots} and \\comname{vdots} for matrices, and otherwise the ellipses~\\comname{dotsb}, \\comname{dotsc}, \\comname{dotsm}, \\comname{dotsi} and occasionally \\comname{dotso}.\n\nThere also exists the generic command~\\comname{dots}\\massindex[ellipses]{dots}[\\comname] which tries to automagically use the right kind of positioning and spacing.\nBut the author recommends not using this command as it can lead to inconsistent results:\n\\begin{showlatex}{Inconsistent results with \\comname{dots}}\nThe ellipses in $x_1 \\leq x_2 \\leq \\dots \\leq x_n$ and $y_1 \\leq y_2 \\leq \\dots$ should look the same.\n\\end{showlatex}\n\n\\index{ellipses|)}\n\n\n\n\\subsection{Know your matrices}\n\\index{matrices|(}\n\nThe package~\\packname{amsmath}\\massindex[packages]{amsmath}[\\packname] provides various environments for matrices, the most basic of which is the environment~\\envname{matrix}\\massindex[matrices!normal sized]{matrix}[\\envname].\n\\begin{showlatex}*{The basic matrix environment~\\envname{matrix}}\n\\[\n  \\begin{matrix}\n    a & b \\\\\n    c & d\n  \\end{matrix}\n\\]\n\\end{showlatex}\nThere are five more variants of this basic matrix environment, that put different delimiters around the matrix.\nThe package~\\packname{mathtools}\\massindex[packages]{mathtools}[\\packname] also provides small versions of all six kinds of matrices.\nSee \\cref{table of matrices} for a table of all these kinds of matrices.\n\\begin{table}\n  \\begin{center}\n  \\begin{tabular}{@{}lccc@{}}\n    \\toprule\n    %\n    \\theading{size}\n    &\n    \\multicolumn{3}{c}{\\theading{matrices}}\n    \\\\\n    \\midrule\n    %\n    normal\n    &\n    \\begin{tabular}{c}\n      $\\begin{matrix} a & b \\\\ c & d \\end{matrix}$ \\\\\n      \\envname{matrix}%\n      \\massindex[matrices!normal sized]{matrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}$ \\\\\n      \\envname{pmatrix}%\n      \\massindex[matrices!normal sized]{pmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix}$ \\\\\n      \\envname{bmatrix}%\n      \\massindex[matrices!normal sized]{bmatrix}[\\envname]\n    \\end{tabular}\n    \\\\[2.5em]\n    {}\n    &\n    \\begin{tabular}{c}\n      $\\begin{Bmatrix} a & b \\\\ c & d \\end{Bmatrix}$ \\\\\n      \\envname{Bmatrix}%\n      \\massindex[matrices!normal sized]{Bmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{vmatrix} a & b \\\\ c & d \\end{vmatrix}$ \\\\\n      \\envname{vmatrix}%\n      \\massindex[matrices!normal sized]{vmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{Vmatrix} a & b \\\\ c & d \\end{Vmatrix}$ \\\\\n      \\envname{Vmatrix}%\n      \\massindex[matrices!normal sized]{Vmatrix}[\\envname]\n    \\end{tabular}\n    \\\\[2.5em]\n    small\n    &\n    \\begin{tabular}{c}\n      $\\begin{smallmatrix} a & b \\\\ c & d \\end{smallmatrix}$ \\\\\n      \\envname{smallmatrix}%\n      \\massindex[matrices!small sized]{smallmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{psmallmatrix} a & b \\\\ c & d \\end{psmallmatrix}$ \\\\\n      \\envname{psmallmatrix}%\n      \\massindex[matrices!small sized]{psmallmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{bsmallmatrix} a & b \\\\ c & d \\end{bsmallmatrix}$ \\\\\n      \\envname{bsmallmatrix}%\n      \\massindex[matrices!small sized]{bsmallmatrix}[\\envname]\n    \\end{tabular}\n    \\\\[2.5em]\n    {}\n    &\n    \\begin{tabular}{c}\n      $\\begin{Bsmallmatrix} a & b \\\\ c & d \\end{Bsmallmatrix}$ \\\\\n      \\envname{Bsmallmatrix}%\n      \\massindex[matrices!small sized]{Bsmallmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{vsmallmatrix} a & b \\\\ c & d \\end{vsmallmatrix}$ \\\\\n      \\envname{vsmallmatrix}%\n      \\massindex[matrices!small sized]{vsmallmatrix}[\\envname]\n    \\end{tabular}\n    &\n    \\begin{tabular}{c}\n      $\\begin{Vsmallmatrix} a & b \\\\ c & d \\end{Vsmallmatrix}$ \\\\\n      \\envname{Vsmallmatrix}%\n      \\massindex[matrices!small sized]{Vsmallmatrix}[\\envname]\n    \\end{tabular}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n  \\caption{Different kinds of matrices.}\n  \\label{table of matrices}\n\\end{table}\n\nThe package~\\packname{mathtools}\\massindex[packages]{mathtools}[\\packname] also provides starred versions of the matrices.\nThese starred versions allow to specify as an optional argument the alignment of the columns, see \\cref{table of matrices}.\nThe three possible arguments are~\\optname{l}\\massindex{l}[\\optname] for left-alignment,~\\optname{c}\\massindex{c}[\\optname] for centered alignment and~\\optname{r}\\massindex{r}[\\optname] for right-alignment.\nThe standard alignment is~\\optname{c}.\n\\begin{showlatex}{Aligning matrix entries}\n\\[\n  \\begin{bmatrix*}[l]\n      a & -b \\\\\n     -c &  d\n  \\end{bmatrix*}\n  \\qquad\n  \\begin{bmatrix*}[c]\n    a & -b \\\\\n    -c &  d\n  \\end{bmatrix*}\n  \\qquad\n  \\begin{bmatrix*}[r]\n     a & -b \\\\\n    -c &  d\n  \\end{bmatrix*}\n  \\qquad\n  \\begin{bmatrix}\n     a & -b \\\\\n    -c &  d\n  \\end{bmatrix}\n\\]\n\\end{showlatex}\n\nOne should choose the kind of matrix, its size and alignment dependent on convention, usage and the matrix entries. \n\\begin{showlatex}*{Using the right kind of matrix}\nWe consider the morphism\n\\[\n  X \\oplus Y\n  \\xrightarrow{\\,\n    \\begin{bsmallmatrix*}[r]\n      f & -d \\\\\n      0 &  g\n    \\end{bsmallmatrix*}\n    \\,\n  }\n  X' \\oplus Y' \\,.\n\\]\n\\end{showlatex}\n\n\\index{matrices|)}\n\n\n\n\n\n\\section{Avoid bad notation}\n\n\n\n\\subsection{Don’t use \\comtitle{subset}}\n\nSome people use~$\\subset$~(\\comname{subset}\\massindex{subset}[\\comname]) to denote inclusion and~$\\subsetneq$~(\\comname{subsetneq}\\massindex{subsetneq}[\\comname]) to denote proper inclusion, while some other people use~$\\subseteq$~(\\comname{subseteq}\\massindex{subseteq}[\\comname]) to denote inclusion and~$\\subset$ to denote proper inclusion.\nThe second convention has the advantage of making sense and being consistent with the usual use of~$\\leq$ and~$<$, whereas the first convention has the non-advantage of existing.\nThe problem is that both conventions are wide-spread while using the symbol~$\\subset$ is different ways.\n\nThe conflict between the above two conventions has abused the symbol~$\\subset$ to a point that it should \\emph{never} be used.\nInstead one should always use~$\\subseteq$ for inclusion, $\\subsetneq$ for proper inclusion and~$\\nsubseteq$~(\\comname{nsubseteq}\\massindex{nsubseteq}[\\comname]) for non-inclusion.\n\nSome people prefer the symbols~$\\subseteqq$~(\\comname{subseteqq}\\massindex{subseteqq}[\\comname]) and~$\\subsetneqq$~(\\comname{subsetneqq}\\massindex{subsetneqq}[\\comname]) instead.\nThe author thinks that these symbols are unnecessary large and recommends not to use them.\n(But they do at least leave poor old~$\\subset$ alone.)\n\n\n\n\\subsection{Don’t underline}\n\\index{underlining}\n\nUnderlining works well on the blackboard, in handwriting, and was useful in the in the (dark) age of typewriters.\nDon’t do it in {\\LaTeX}.\n\n\n\n\\subsection{Use \\texorpdfstring{$\\mathrm{d}x$}{dx} instead of \\texorpdfstring{$dx$}{dx}}\n\nA differential\\index{differential} is written as \\inlinecode{{\\tbs}mathrm\\{d\\}x}, not as \\inlinecode{dx}.\nWhen it occurs at the end of an integral\\index{integral} then a slight spacing~\\comname{,}\\index{spacing!in math mode} is also introduced in front of it.\nSo don’t do the following:\n\\begin{showlatex}*{Wrong kind of differentials}\n\\[\n  \\int_a^b f(x) dx\n\\]\n\\end{showlatex}\nInstead do the following:\n\\begin{showlatex}*{Right kind of differential}\n\\[\n  \\int_a^b f(x) \\,\\mathrm{d}x\n\\]\n\\end{showlatex}\n\n\n\n\\subsection{Don’t force fancy fractions}\n\\index{fractions|(}\n\nWhen fractions are placed inline, are part of an exponent or part of an index, then they should be of the form $a/b$.\nThe notation\n\\[\n  \\frac{a}{b}\n\\]\nis reserved for display style.\nSo don’t do the following:\n\\begin{showlatex}{Full fractions in exponent, index and inline}\nConsider $e^{\\frac{1}{x}}$ and $x_{\\frac{1}{n}}$ and $\\frac{2}{3}$.\n\\end{showlatex}\nDo the following instead:\n\\begin{showlatex}{Flat fractions in exponent, index and inline}\nConsider $e^{1/x}$ and $x_{1/n}$ and $2/3$.\n\\end{showlatex}\n\nDon’t use funky fractions like $\\faktor{a}{b}$. They’ll make you go blind and burn down your house.\n\n% TODO: Finding out the proper term for flat fractions. See Chicago Manual?\n\n\\index{fractions|)}\n\n\n\n\n\n\\section{Defining new commands}\n\nMany mathematical operators have predefined commands, which should be used when needed.\n\\begin{showlatex}{Using commands vs.\\ not using them}\nUse $\\sin(x)$ instead of $sin x$, use $\\dim V$ instead of $dim V$ and use $\\lim_{n \\to \\infty} a_n$ instead of $lim_{n \\to \\infty} a_n$.\n\\end{showlatex}\nNew commands can be defined in various ways:\n\n\n\\subsection{\\comtitle{DeclareMathOperator}}\n\nCommands of the form~\\comname{WordCommand}, that are supposed to print~\\enquote{$\\mathrm{WordOutupt}$}, can easily be defined using the command~\\comname{DeclareMathOperator}\\massindex[defining commands]{DeclareMathOperator}[\\comname].\n\\begin{showcode}{Syntax of~\\comname{DeclareMathOperator}}\n\\DeclareMathOperator{\\WordCommand}{WordOutput}\n\\end{showcode}\nThe command \\comname{DeclareMathOperator} can only be used in the preamble.\n\nTo define the command~\\comname{End} we use the following text in the preamble:\n\\begin{showcode}{Declaring a mathematical operator with~\\comname{DeclareMathOperator}}\n% in the preamble:\n\\DeclareMathOperator{\\End}{End}\n\\end{showcode}\nThe command \\comname{End} can then be used in the usual way:\n\\begin{showlatex}{Using a declared mathematical operator}\nThus $\\End(V) = \\End_k(V)$ becomes a vector space.\n\\end{showlatex}\n\nIf a command~\\comname{WordCommand} is defined with \\comname{DeclareMathOperator} then {\\LaTeX} will automatically insert some space around\\index{spacing!in math mode} \\comname{WordCommand} when needed:\n\\begin{showlatex}*{Automatic spacing of~\\comname{DeclareMathOperator}}\n\\begin{align*}\n&x \\End V\n\\\\\n&x \\End(V)\n\\\\\n&x \\End {(V)}\n\\end{align*}\n\\end{showlatex}\nNote that in the first expression {\\LaTeX} inserts some spacing both to the left and to the right of $\\End$.\nIn the second expression {\\LaTeX} observes that the used math operator is follows by a parenthesis and thus inserts no additional spacing.\nFor the third expression we prevent {\\LaTeX} from making such an observation by using a pair of curly brackets.\n\nThis behavior leads to a bad looking output when \\comname{DeclareMathoperator} is abused.\nSuppose that we want a command \\comname{Complex} that inserts the code \\comname{mathbb\\{C\\}}.\n\\begin{showcode}{Wrong way of using \\comname{DeclareMathOperator}}\n% in the preamble:\n\\DeclareMathOperator{\\Complex}{\\mathbb{C}}\n\\end{showcode}\nThis will lead to the following problem:\n\\begin{showlatex}{Wrong output when \\comname{DeclareMathOperator} is abused}\nThe span of $x_1, \\dotsc, x_n \\in \\Complex^m$ equals $\\Complex x_1 + \\dotsb + \\Complex x_n$.\n\\end{showlatex}\nWe expect the output $\\mathbb{C} x_1 + \\dotsb + \\mathbb{C} x_n$ but get some unwanted spacing instead.\n\n\n\n\\subsection{\\comtitle{operatorname}}\n\nThe command~\\comname{operatorname}\\massindex[defining commands]{operatorname}[\\comname] can be used to give the formatting of a mathemical operator without defining a new command.\n\\begin{showlatex}{Using \\comname{operatorname}}\nThus $\\operatorname{Hom}(V,W) = \\operatorname{Hom}_k(V,W)$ becomes a vector space.\n\\end{showlatex}\nIf the same command is used multiple times then one should use \\comname{DeclareMathOperator} instead of \\comname{operatorname}, to keep the code clean.\n\n\n\n\\subsection{Don’t abuse \\comtitle{mathrm}}\n\nThe commands~\\comname{mathrm}\\massindex{mathrm}[\\comname] and \\comname{operatorname} do not give the same formatting.\nWith \\comname{operatorname} we get the necessary spacing\\index{spacing!in math mode} when not using parentheses\nWe don’t get this from \\comname{mathrm}.\n\\begin{showlatex}{Missing spacing after~\\comname{mathrm}}\nCompare $\\operatorname{End} V$ to $\\mathrm{End} V$, and also~$2 \\operatorname{Fr}(x)$ to~$\\mathrm{Fr}(x)$.\n\\end{showlatex}\n\n\n\n\\subsection{\\comtitle{newcommand}}\n\nA very general way of defining new commands is given by \\comname{newcommand}\\massindex[defining commands]{newcommand}[\\comname].\nIts syntax is as follows:\n\\begin{showcode}{Syntax of \\comname{newcommand}}\n\\newcommand{\\name}[number of arguments n]{ definition including #1, ..., #n }\n\\end{showcode}\nConsider the following example:\n\\begin{showlatex}{Using the command~\\comname{newcommand}}\n\\newcommand{\\bimodule}[2]{#1-#2-bimodule}\nLet $M$ be an \\bimodule{$A$}{$B$}.\n\\end{showlatex}\nOne may think about \\comname{DeclareMathOperator} as a combination of \\comname{newcommand} and \\comname{operatorname}:\n\\begin{showlatex}{\\comname{DeclareMathOperator} = \\comname{newcommand} plus \\comname{operatorname}}\n\\newcommand{\\Ouv}{\\operatorname{Ouv}}\n$\\Ouv X$\n\\end{showlatex}\n\nTrying to define an already existing command with \\comname{newcommand} will lead to an error.\nTo overwrite an already existing command one can use \\comname{renewcommand}\\massindex[defining commands]{renewcommand}[\\comname] instead.\nBut this shouldn’t really be done (unless you really, \\emph{really} know what you’re doing).\nEven if you don’t like a particular command it may happen that some of the packages which you’re using rely on it:\noverwriting the command can then easily lead to some unexpected new problems.\n\n\n\n\\subsection{\\comtitle{DeclarePairedDelimiter}}\n\\index{delimiters!zzzz@\\igobble |seealso {\\comname{DeclarePairedDelimiter}}}\n\nMathematical operations like the absolute value~$\\lvert \\,\\cdot\\, \\rvert$ and a norm~$\\lVert \\,\\cdot\\, \\rVert$ are denoted by putting certain delimiters around the argument.\nTo define a corresponding {\\LaTeX} command like~\\comname{abs} or \\comname{norm} one should use the command~\\comname{DeclarePairedDelimiter}\\massindex[defining commands]{DeclarePairedDelimiter}[\\comname] (which is provided by the package~\\packname{mathtools}).\n\\begin{showcode}{Syntax of \\comname{DeclarePairedDelimiter}}\n\\DeclarePairedDelimiter{\\name}{left delimiter}{right delimiter}\n\\end{showcode}\nAs an example we use \\comname{DeclarePairedDelimiter} to define a command~\\comname{abs} for absolute value:\n\\begin{showcode}{Defining the command~\\comname{abs} with \\comname{DeclarePairedDelimiter}}\n\\DeclarePairedDelimiter{\\abs}{\\lvert}{\\rvert}\n\\end{showcode}\nThe defined command can now be used as expected:\n\\begin{showlatex}{Using a declared delimiter}\n  \\[\n    \\abs{-5} = 5\n  \\]\n\\end{showlatex}\n\nDeclaring a command via~\\comname{DeclarePairedDelimiter} will automatically also define a starred version that scales the surrounding delimiters according to the given content between them.\nOne can also specify a scaling size like \\comname{big}\\massindex[scaling]{big}[\\comname], \\comname{bigg}\\massindex[scaling]{bigg}[\\comname], etc.\\ to scale the delimiters.\n\\begin{showlatex}{Scaling of declared delimiters}\n\\begin{align*}\n  \\abs{-\\frac{1}{2}}\n  &=\n  \\frac{1}{2} \\,,\n  \\\\\n  \\abs*{-\\frac{1}{2}}\n  &=\n  \\frac{1}{2} \\,,\n  \\\\\n  \\abs[\\bigg]{-\\frac{1}{2}}\n  &=\n  \\frac{1}{2}\n\\end{align*}\n\\end{showlatex}\n\nThe variant~\\comname{DeclarePairedDelimiterX}\\massindex[defining commands]{DeclarePairedDelimiterX}[\\comname] allows building more sophisticated commands:\n\\begin{showcode}{Syntax of \\comname{DeclarePairedDelimiterX}}\n\\DeclarePairedDelimiterX{\\name}\n  [number of arguments n]\n  {left delimiter}{right delimiter}\n  {expression build from #1, #2, ..., #n}\n\\end{showcode}\nIf the built up expression contains a delimiter, then by prefixing this delimiter with the command~\\comname{delimsize}\\massindex[scaling]{delimsize}[\\comname] will ensure that the delimiter scales in the same way as the two surrounding delimiters.\nAs an example we define a command~\\comname{inner} for inner product.\n\\begin{showcode}{Using \\comname{DeclarePairedDelimiterX} for more advanced delimiters}\n\\DeclarePairedDelimiterX{\\inner}[2]{\\langle}{\\rangle}{#1 \\,\\delimsize\\vert\\, #2}\n\\end{showcode}\nThe defined command~\\comname{inner} takes two arguments and inserts a line~(\\comname{vert}) with some surrounding space~(\\comname{,}) between them.\n\\begin{showlatex}{Using more advanced delimiters}\n\\[\n  \\inner{\\psi_1}{\\psi_2}\n  \\quad\n  \\inner*{\\frac{f}{g}}{\\frac{h}{k}}\n\\]\n\\end{showlatex}\nThere is also the variant~\\comname{DeclarePairedDelimiterXPP}\\massindex[defining commands]{DeclarePairedDelimiterXPP}[\\comname] that is even more flexible than \\comname{DeclarePairedDelimiterX}.\nWe refer to \\cite{mathtools} for more details on these commands.\n\n\n\n\\subsection{The package~\\packtitle{xparse}}\n\nA useful way for defining commands -- in particular more involved ones -- is provided by the package~\\packname{xparse}\\massindex[packages]{xparse}[\\packname].\nThis package provides the command~\\comname{NewDocumentCommand}\\massindex[defining commands]{NewDocumentCommand}[\\comname].\n\\begin{showcode}{Syntax of \\comname{NewDocumentCommand}}\n\\NewDocumentCommand{\\name}{arguments}{definition}\n\\end{showcode}\nThe field~\\inlinecode{arguments} specifies what kinds of arguments the command~\\comname{name} will take:\n\n\\subsubsection{Mandatory arguments}\n\nMandatory arguments can be declared with the option~\\optname{m}\\expandafter\\index\\expandafter{\\ciname{NewDocumentCommand}!mandatory argument}:\n\\begin{showlatex}{Mandatory arguments with \\comname{NewDocumentCommand}~II}\n% in the preamble\n\\NewDocumentCommand{\\double}{m}{#1 #1}\n% in the main text\n\\double{sometext}\n\\end{showlatex}\nOne can also specify multiple arguments:\n\\begin{showlatex}{Mandatory arguments with \\comname{NewDocumentCommand}~II}\n% in the preamble\n\\NewDocumentCommand{\\swap}{m m}{#2 #1}\n% in the main text\n\\swap{first}{second}\n\\end{showlatex}\n\n\\subsubsection{Optional arguments without default value}\n\nOptional arguments can be declared with the option~\\optname{o}\\massindex{o}[\\optname]\\expandafter\\index\\expandafter{\\ciname{NewDocumentCommand}!optional argument!without default value}.\nIt needs to be checked with the command~\\comname{IfNoValueTF} if this optional argument was assigned a value.\n\\begin{showcode}[label = {syntax of ifvaluetf}]{Syntax of \\comname{IfValueTF}}\n\\IfValueTF{#number of argument}\n  {if the argument has been set}\n  {if the argument has not been set}\n\\end{showcode}\nOne can similarly use~\\comname{IfNoValueTF} instead of~\\comname{IfNoValueTF}.\nThis has the same effect as switching the cases in \\cref{syntax of ifvaluetf}.\n\nLet’s look at a specific example:\n\\begin{showlatex}{Optional arguments with \\comname{NewDocumentCommand},~I}\n% in the preamble\n\\NewDocumentCommand\n{\\module}\n{m o}\n{\\IfNoValueTF{#2}{#1-module}{#1-#2-bimodule}}\n% in the main text\nLet $M$ be an \\module{$R$} and let $N$ be an \\module{$R$}[$S$].\n\\end{showlatex}\nIt is useful to properly indent the source code.\nBut we have to be careful here:\nIt can easily happen that this indentation introduces some unwanted whitespace.\nLet’s consider the naive code first:\n\\begin{showlatex}{Optional arguments with \\comname{NewDocumentCommand},~I}\n% in the preamble\n\\NewDocumentCommand\n{\\module}\n{m o}\n{\n  \\IfNoValueTF{#2}\n    {#1-module}\n    {#1-#2-bimodule}\n}\n% in the main text\nLet $M$ be an \\module{$R$} and let $N$ be an \\module{$R$}[$S$].\n\\end{showlatex}\nNow let’s \\enquote{comment out} the additional whitespace.\n\\begin{showlatex}{Optional arguments with \\comname{NewDocumentCommand},~I}\n% in the preamble\n\\NewDocumentCommand\n{\\module}\n{m o}\n{%\n  \\IfNoValueTF{#2}\n    {#1-module}\n    {#1-#2-bimodule}%\n}\n% in the main text\nLet $M$ be an \\module{$R$} and let $N$ be an \\module{$R$}[$S$].\n\\end{showlatex}\n\n\\subsubsection{Optional arguments with default value}\n\nOne can use \\optname{O\\{default value\\}}\\massindex{O\\{ \\}}[\\optname]\\expandafter\\index\\expandafter{\\ciname{NewDocumentCommand}!optional argument!with default value} instead of \\optname{o} to declare an optional argument that has a default value.\n\nLet’s start with an example where this default value is empty:\n\\begin{showlatex}{Optional arguments with \\comname{NewDocumentCommand},~II}\n% in the preamble\n\\NewDocumentCommand{\\restrict}{m m O{}}{#1|_{#2}^{#3}}\n% in the main text\nLet $f = \\restrict{g}{X}$ and $f' = \\restrict{g'}{X}[Y]$\n\\end{showlatex}\nNow let’s do an example which has a standard value:\n\\begin{showlatex}{Optional arguments with \\comname{NewDocumentCommand},~III}\n% in the preamble\n\\NewDocumentCommand{\\favorite}{O{colour} m}{My favorite #1 is #2.}\n% in the main text\n\\favorite{blue}\n\\favorite[food]{spam}\n\\end{showlatex}\n\n\\subsubsection{Starred versions}\n\nOne can use the argument~\\optname{*} together with the command~\\comname{IfBooleanTF}\\massindex[\\ciname{NewDocumentCommand}]{IfBooleanTF}[\\comname] to check for the occurrence of a star.\nThis can be used to also define a starred version of a command.\n\\begin{showlatex}{Starred versions with \\comname{NewDocumentCommand}}\n% in the preamble\n\\NewDocumentCommand{\\choice}{s m m}{\\IfBooleanTF{#1}{#3}{#2}}\n% in the main text\nDon’t confuse \\choice{first}{second} with \\choice*{first}{second}.\n\\end{showlatex}\n\n\n\n\n\n\\section{Stretch your arrows}\n\nIf some expression occurs atop or below an arrow, then this arrow must be stretched suffciently long to accommodate this expression.\nThe extensible arrows introduced in \\cref{extensible arrows} automatically do so.\n\n\n\n\\subsection{Stretching columns}\n\nIf an arrow in a commutative diagram isn’t long enough then this arrow must also be stretched:\n\\begin{showlatex}{Commutative diagram with an arrow too short}\n\\[\n\\begin{tikzcd}\n  X \\arrow{r}{f \\circ g - g \\circ f} \\arrow{d}\n  &\n  Y \\arrow{r}{k} \\arrow{d}\n  &\n  Z \\arrow[equal]{d}\n  \\\\\n  X' \\arrow[dashed]{r}{h'}\n  &\n  Y' \\arrow{r}{k'}\n  &\n  Z'\n\\end{tikzcd}\n\\]\n\\end{showlatex}\nThe column distance of a commutative diagram is governed by the option~\\optname{column~sep}\\massindex[\\piname{tikz-cd}]{column sep}[\\optname].\nThe value of \\optname{column~sep} is expected to be a distance, e.g.~\\optname{4em}.\nSome standard distances are predefined, see \\cref{column sep settings}.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begin{tabular}{@{}lcccccc@{}}\n    \\toprule\n    \\theading{name}\n    &\n    \\optname{tiny}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{tiny}[\\optname]\n    &\n    \\optname{small}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{small}[\\optname]\n    &\n    \\optname{scriptsize}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{scriptsize}[\\optname]\n    &\n    \\optname{normal}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{normal}[\\optname]\n    &\n    \\optname{large}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{large}[\\optname]\n    &\n    \\optname{huge}\\massindex[\\piname{tikz-cd}!\\optname{column sep}]{huge}[\\optname]\n    \\\\\n    \\theading{distance}\n    &\n    \\optname{0.6em}\n    &\n    \\optname{1.2em}\n    &\n    \\optname{1.8em}\n    &\n    \\optname{2.4em}\n    &\n    \\optname{3.6em}\n    &\n    \\optname{4.8em}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n  \\caption{Standard distances for~\\optname{column sep}.}\n  \\label{column sep settings}\n\\end{table}\nWith~\\optname{column~sep} one can fix the above diagram.\n\\begin{showlatex}{Using~\\optname{column sep}}\n\\[\n\\begin{tikzcd}[column sep = huge]\n  X \\arrow{r}{f \\circ g - g \\circ f} \\arrow{d}\n  &\n  Y \\arrow{r}{k} \\arrow{d}\n  &\n  Z \\arrow[equal]{d}\n  \\\\\n  X' \\arrow[dashed]{r}{h'}\n  &\n  Y' \\arrow{r}{k'}\n  &\n  Z'\n\\end{tikzcd}\n\\]\n\\end{showlatex}\nOne can also increase the width of a specific column by specifying the additional width at the correct~\\&\\nbd-symbol in the first row.\n(In the above examples, the difference between \\optname{normal} and \\optname{huge} is~\\optname{2.4em}.)\n\\begin{showlatex}{Explicit column spacing}\n\\[\n\\begin{tikzcd}\n  X \\arrow{r}{f \\circ g - g \\circ f} \\arrow{d}\n  &[2.4em]\n  Y \\arrow{r}{k} \\arrow{d}\n  &\n  Z \\arrow[equal]{d}\n  \\\\\n  X' \\arrow[dashed]{r}{h'}\n  &\n  Y' \\arrow{r}{k'}\n  &\n  Z'\n\\end{tikzcd}\n\\]\n\\end{showlatex}\n\n\n\n\\subsection{Stretch rows}\n\nOne can similarly use the option~\\optname{row~sep} to change the distance of the rows.\nSome predefined distances can be found in \\cref{row sep settings}.\n\\begin{table}[tb]\n  \\begin{center}\n  \\begin{tabular}{@{}lcccccc@{}}\n    \\toprule\n    \\theading{name}\n    &\n    \\optname{tiny}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{tiny}[\\optname]\n    &\n    \\optname{small}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{small}[\\optname]\n    &\n    \\optname{scriptsize}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{scriptsize}[\\optname]\n    &\n    \\optname{normal}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{normal}[\\optname]\n    &\n    \\optname{large}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{large}[\\optname]\n    &\n    \\optname{huge}\\massindex[\\piname{tikz-cd}!\\optname{row sep}]{huge}[\\optname]\n    \\\\\n    \\theading{distance}\n    &\n    \\inlinecode{0.45em}\n    &\n    \\inlinecode{0.9em}\n    &\n    \\inlinecode{1.35em}\n    &\n    \\inlinecode{1.8em}\n    &\n    \\inlinecode{2.7em}\n    &\n    \\inlinecode{3.6em}\n    \\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n  \\caption{Standard distances for~\\optname{row sep}.}\n  \\label{row sep settings}\n\\end{table}\nThey are the same as for~\\optname{column~sep} but scaled down by a factor of~$0.75$.\nOne can also explicitely specify an additional space between two rows after the correct~\\comname{\\tbs}.\n\\begin{showlatex}{Using~\\optname{row sep} and explicit row spacing}\n\\[\n  \\begin{tikzcd}[row sep = huge]\n    A \\arrow{r} \\arrow{d}\n    &\n    B \\arrow{d}\n    \\\\\n    C \\arrow{r} \\arrow{d}\n    &\n    D \\arrow{d}\n    \\\\\n    E \\arrow{r}\n    &\n    F\n  \\end{tikzcd}\n  \\qquad\n  \\begin{tikzcd}\n    A \\arrow{r} \\arrow{d}\n    &\n    B \\arrow{d}\n    \\\\[1.8em]\n    C \\arrow{r} \\arrow{d}\n    &\n    D \\arrow{d}\n    \\\\\n    E \\arrow{r}\n    &\n    F\n  \\end{tikzcd}\n\\]\n\\end{showlatex}\n\n\n\n\n\\section{Beware of spacings}\n\n\\index{spacing!in math mode|(}\n\n{\\LaTeX} classifies symbols and expressions into certain groups and then adds spacing around these symbols, which depends on the group they belong to.\nThree of these groups are \\enquote{operators}, \\enquote{relation symbols} and \\enquote{binary operations}.\nThe symbols~\\inlinecode{=} and~\\inlinecode{<} are for example treated as relations symbols, and the symbols~\\inlinecode{+} and~\\comname{cdot} as binary operations.\nWe can see in the following example how some space is automatically added around these symbols:\n\\begin{showlatex}{Standard spacing around relation symbols and binary operators}\n\\[\n  a = b  \\qquad  a < b  \\qquad  a + b  \\qquad  a \\cdot b\n\\]\n\\end{showlatex}\nTo compare this to a version without spacing we can surround the symbols by a pair of curly brackets.\nThis circumvents {\\LaTeX} from taking the surrounding code into consideration.\n\\begin{showlatex}{Disabling the standard spacing around a symbol}\n\\[\n  a {=} b   \\qquad  a {<} b  \\qquad  a {+} b  \\qquad  a {\\cdot} b\n\\]\n\\end{showlatex}\nThe automatic spacing can become a problem, as the following examples illustrate:\n\\begin{showlatex}*{Clashing spacings around symbols}\n\\[\n  X/\\sim\n  \\quad\n  R/\\operatorname{J}(R)\n  \\quad\n  \\operatorname{id} \\otimes h\n\\]\n\\end{showlatex}\nThese problems can be fixed by surrounding the respective symbols with curly brackets.\n\\begin{showlatex}*{Preventing a clash of spacings}\n\\[\n  X/{\\sim}\n  \\quad\n  R/{\\operatorname{J}(R)}\n  \\quad\n  {\\operatorname{id}} \\otimes h\n\\]\n\\end{showlatex}\nOne can also tell {\\LaTeX} a symbol should be treated.\n\\begin{showlatex}*{Specifying the role (and thus spacing) of a symbol}\n\\[\n  a | b\n  \\quad\n  a \\mathop{|} b\n  \\quad\n  a \\mathrel{|} b\n  \\quad\n  a \\mathbin{|} b\n\\]\n\\end{showlatex}\nWe can thus define a command~\\comname{divides}, which expresses that a number~$n$ divides a number~$m$, as follows:\n\\begin{showlatex}*{Defining and using \\comname{divides}}\n\\newcommand{\\divides}{\\mathrel{|}}\n\\[\n  n \\divides m\n\\]\n\\end{showlatex}\nFor more on this topic we refer to \\cite{tex_binrel}.\n\n\\index{spacing!in math mode|)}\n\n\n\n\n", "meta": {"hexsha": "afb531874ee5d3bcfd0487990b9500f0b1688575", "size": 53905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/math_mode.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_mode.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_mode.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": 29.216802168, "max_line_length": 449, "alphanum_fraction": 0.6549856229, "num_tokens": 17003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6053128170096228}}
{"text": "\\section{Background}\n\n% Description\nHopfield \\parencite{hopfield1982} proposed a model in which memory storage and retrieval emerge as properties of the collective behavior of its units, or neurons.\nThis connectionist model is capable of recovering a previously presented pattern or patterns from partial cues, being able to complete the missing information. \n\nHopfield networks behave as fixed-point attractor networks as their internal state evolves towards a stable single state or fixed point.\nThis is given by their energy function.\nThese types of systems have been used as models of associative memory \\parencite{amit1992}.\n\n% Currents\nIn the classic model as described by Hopfield \\parencite{hopfield1982}, neurons are binary units: the activation state of each neuron can be either firing or not (on or off). The activity of each unit asynchronously changes in a discrete time scale.\n\n% Weights\nAs in other connectionist systems, the strength of connections between nodes is described by its weight matrix.\nWeights are only updated upon network initialization and depend on the patterns presented to all network units.\nThe weight matrix takes the shape of a square, symmetric matrix in which all the values in the main diagonal are always zero.\nAll neurons are connected to each other.\nAlso, every neuron is both an input and output node for memory pattern presentation and retrieval.\nTo compose the weight matrix, each node is updated according to a local incremental learning rule, related to Hebbian learning.\nHebb's rule states that neurons that fire together when a certain pattern is present strengthen the connections between them \\parencite{hebb1949}.\n\n% Modifications\nIn the work by Recantesi \\textit{et al.} \\parencite{recanatesi2015}, modifications to the original Hopfield model have been introduced, with new properties of memory retrieval: the model was adapted to induce transitions between attractor states (recalled memories).", "meta": {"hexsha": "dc7eadf01ffa6d6500df953af8158c41c6cb6cc8", "size": 1951, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/2-background.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": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-20T07:18:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T22:22:20.000Z", "max_issues_repo_path": "files/2-background.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": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-25T11:42:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-25T11:42:00.000Z", "max_forks_repo_path": "files/2-background.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": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-19T20:39:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-19T20:39:31.000Z", "avg_line_length": 81.2916666667, "max_line_length": 266, "alphanum_fraction": 0.8185545874, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6053128124832244}}
{"text": "\\vspace*{-0.4cm}\n\\section{Techniques description}\n\nThe different coding schemes that have been implemented rely on several transforms and entropy coders that are introduced here.\n\n\\subsection{Run-Length Encoding (RLE)}\n\nThe RLE transforms a bilevel image into a sequence of runs. A run is the number of successive occurrences of the same value in the file. For example, the sequence $[0,0,0,1,1,1,1]$ would be coded $[3,4]$ by a coder assuming the first received symbol is a $0$.\n\n\\subsection{Move to Front transform (MTF)}\n\nThe purpose of the MTF is to reduce the entropy of the image \\cite{benzid}. It is also based on the concept of runs but replaces each symbol of a run by 0 except the first one. The first one is replaced by the index of the symbol in the alphabet of the source. For example, for a sequence $[1,1,1,0,0,0,0]$, the alphabet is $[0,1]$. The index of 1 in the alphabet is 1, so that the sequence becomes $[\\textbf{1},\\textbf{0},\\textbf{0},0,0,0,0]$. The 1 is moved to the front of the alphabet (hence the name of the MTF), and the sequence of 0's now needs to be encoded. The alphabet is now $[1,0]$, so that the index of 0 is 1. The final sequence is $[1,0,0,1,0,0,0]$ and the final alphabet is $[0,1]$.\n\n\\subsection{Two-Role Encoder (TRE)}\n\nThe TRE is a variant of the RLE which is more suited when one symbol is more probable than the other \\cite{benzid}, so that it is meant to be used after the MTF. Each non-zero element is shifted by 24 bits, while the sequence of zeros is simply encoded as the run length. To follow the previous example, the sequence $[1,0,0,1,0,0,0]$ would be encoded as $[2^{23},2,2^{23},3]$. The stream can be decoded knowing that a symbol that is repeated is encoded with a number greater than $2^{23}$, while a run cannot be greater than $2^{23}$.\n\n\\subsection{Exp-Golomb coding}\n\nThe Exp-Golomb coding is a variable length prefix code meant for entropy coding. The $i$\\textsuperscript{th} symbol is mapped to the binary representation of $i+1$, preceded by M zeros with $M=\\left \\lfloor{\\log_2(i)}\\right \\rfloor $. When the short codewords are assigned to most probable symbols, compression can be achieved \\cite{H264}.\n\n\\subsection{Arithmetic coding}\n\nAn arithmetic encoder converts a sequence of data symbols into a single fractional number and can approach the optimal fractional number of bits required to represent each symbol. In general, it outperforms prefix codes \\cite{H264}. An integer version of the coder was implemented to cope with finite precision problems. When the interval corresponding to the symbol stream becomes too small, some bits are already extracted and the interval is made wider again.", "meta": {"hexsha": "385e2bd2e2566b7528aa3faa8c89cdd997504c91", "size": 2667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/description.tex", "max_stars_repo_name": "mpetitjean/BilevelImageCompression", "max_stars_repo_head_hexsha": "d3a6c9903fb5fefe311b63ae316f4ac3d499bc37", "max_stars_repo_licenses": ["MIT"], "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/description.tex", "max_issues_repo_name": "mpetitjean/BilevelImageCompression", "max_issues_repo_head_hexsha": "d3a6c9903fb5fefe311b63ae316f4ac3d499bc37", "max_issues_repo_licenses": ["MIT"], "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/description.tex", "max_forks_repo_name": "mpetitjean/BilevelImageCompression", "max_forks_repo_head_hexsha": "d3a6c9903fb5fefe311b63ae316f4ac3d499bc37", "max_forks_repo_licenses": ["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.125, "max_line_length": 699, "alphanum_fraction": 0.7577802775, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6052536041347236}}
{"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{February 19, 2014}\n\\rhead{Jon Allen}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\section*{Chapter 3}\n\\subsection*{4.}\nShow that if $n+1$ integers are chosen from the set $\\{1,2,\\dots,2n\\}$, then there are always two which differ by 1.\n\\subsection*{proof}\nSince we want all the integers to differ by more than one, we can only pickevery other integer from $\\{1,2,\\dots,2n\\}$. This gives us a maximum of $n$ integers. Since we are choosing $n+1$ integers, we know that at least two of them must differ by only one.$\\Box$\n\\subsection*{5.}\nShow that if $n+1$ distinct integers are chosen from the set $\\{1,2,\\dots,3n\\}$, then there are always two which differ by at most 2.\n\\subsection*{proof}\nSince we want all the integers to differ by more than two, we can only pickevery third integer from $\\{1,2,\\dots,3n\\}$. This gives us a maximum of $n$ integers. Since we are choosing $n+1$ integers, we know that at least two of them must differ by two or less.$\\Box$\n\\subsection*{6.}\nGeneralize Exercises 4 and 5.\n\\subsection*{hypothesis}\nIf $n+1$ distinct integers are chosen from the set $\\{1,2,\\dots,mn\\}$ where $m$ is a positive integer then there are always two which differ by at most $m-1$.\n\\subsection*{proof}\nWe can select at most $n$ integers which have a difference of $m$ or more. Since we are selecting $n+1$ integers then we must have at least two which differ by $m-1$ or less.$\\Box$\n\\subsection*{8.}\nUse the pigeonhole principle to prove that the decimal expansion of a rational number $m/n$ eventually is repeating. For example,\n\\begin{align*}\n  \\frac{34,478}{99,900}&=0.345125125125\\cdots.\n\\end{align*}\n\\subsection*{proof}\nWe assume the $n>0$ because if $n=0$ we don't really have a rational number and if $n<0$ we can simply multiply by $\\frac{-1}{-1}$ to make $n$ positive.\n\nNow we will start building our decimal representation of our number by dividing.\n\\begin{align*}\n  m&=q_0n+r_0,\\qquad 0\\le r_0\\le n-1\n\\end{align*}\nNow we have an integer part $q_0$ and our fractional decimal part $\\frac{r_0}{n}$. We expand our fractional decimal digits by multiplying successive remainders by 10 and dividing by $n$ repeatedly. So for our $\\frac{1}{10^i}$ place we have:\n\\begin{align*}\n  r_{i-1}\\cdot10&=q_in+r_i\n\\end{align*}\nThis will give us $q_i$ which is the digit in the $\\frac{1}{10^i}$th spot. Notice that because we are dividing by $n$ our remainders will always satisfy $0\\le r_i\\le n-1$. Now lets take some sequence of $n$ remainders from our fractional expansion. Say $r_i,\\dots,r_{i+n-1}$. Because we have $n$ remainders which can have $n-1$ possible values, we know from the pigeon hole principle that at least two of these remainders are the same. Lets pick $r_j$ from the sequence $r_i,\\dots,r_{i+n-1}$ such that $r_j=r_i$. Applying the division algorithm to obtain:\n\\begin{align*}\n  r_{i}\\cdot10&=q_{i+1}n+r_{i+1}=r_{j}\\cdot10\\\\\n  r_{j}\\cdot10&=q_{j+1}n+r_{j+1}=r_{i}\\cdot10\n\\end{align*}\nWe know that because the remainders and quotients of division are unique $q_{i+1}=q_{j+1}$ and $r_{i+1}=r_{j+1}$. Given this we can say from induction that for any integer $1\\le k$\n\\begin{align*}\n  q_{i+k}&=q_{j+k}\\\\\n  r_{i+k}&=r_{j+k}\n\\end{align*}\nAnd in fact $q_{i+k}=q_{j+k}=q_{i+2(j-i)+k}=q_{i+3(j-i)+k}=q_{i+4(j-i)+k}=\\dots$ and so we see that fractional part of the decimal representation of the ratio will at some point begin to repeat.$\\Box$\n\\subsection*{12.}\nShow by example that the conclusion of the Chinese rmainder theorem (Application 6) need not hold when $m$ and $n$ are not relatively prime.\n\nTake 3 and 9 for $m$ and $n$. Take $2$ and $4$ for $a$ and $b$. Then we should be able to find an $x$ such that:\n\\begin{align*}\n  x&=3p+2\\\\\n  x&=9q+4\\\\\n  3p+2&=9q+4\\\\\n  3p&=9q+2\\\\\n  3&\\mid 3p\\\\\n  3&\\nmid 9q+2\\\\\n  3p&\\neq9q+2\\\\\n\\end{align*}\nSo we see that $x$ does not exist\n\\end{document}\n", "meta": {"hexsha": "eded5fcfb00ba6aeea7c237164ac8bc476bbbfdf", "size": 4106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-hw-2014-02-19.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-02-19.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-02-19.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": 54.7466666667, "max_line_length": 555, "alphanum_fraction": 0.7131027764, "num_tokens": 1391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6052535881637228}}
{"text": "\\documentclass[a4paper]{article}\n\n\\title{Efficient numerical methods to solve ballistic equations}\n\\author{Javier Burguete}\n\\date{\\today}\n\n\\newcommand{\\ABS}[1]{\\left|#1\\right|}\n\\newcommand{\\C}[1]{\\left[#1\\right]}\n\\newcommand{\\COMB}[2]{\\left(\\begin{array}{c}#1\\\\#2\\end{array}\\right)}\n\\newcommand{\\D}[3]{\\DD{^{#3}#1}{#2^{#3}}}\n\\newcommand{\\DD}[2]{\\frac{d#1}{d#2}}\n\\newcommand{\\EQ}[2]{\\begin{equation}#1\\label{#2}\\end{equation}}\n\\newcommand{\\PA}[1]{\\left(#1\\right)}\n\\newcommand{\\PARTIAL}[2]{\\frac{\\partial #1}{\\partial #2}}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Introduction}\n\nWe are interested in solving ordinary differential equations (ODE) as:\n\\EQ{\\DD{u}{t}=f\\PA{t,\\,u(t)}.}{EqODE}\n\nThe following notation has been used in this work:\n\\[u_0=u\\PA{t_0},\\quad f_0=f\\PA{t_0,\\,u\\PA{t_0}},\\]\n\\[\n\tf_{n\\,t}=\\PARTIAL{^nf}{t^n},\\quad\n\tf_{n\\,t,m\\,u}=\\PARTIAL{^{n+m}f}{t^n\\,\\partial u^m},\n\\]\n\\[F_{0,0}=f_0,\\quad F_{1,0}=\\PA{f_t+f\\,f_u}_0,\\quad F_{1,1}=\\PA{f_u}_0,\\]\n\\[\n\tF_{2,0}=\\PA{f_{2t}+2\\,f\\,f_{t,u}+f^2\\,f_{2u}}_0,\\quad\n\tF_{2,1}=\\PA{f_{t,u}+f\\,f_{2u}}_0,\\quad\n\tF_{2,2}=\\PA{f_{2u}}_0,\n\\]\n\\[\\cdots\\]\n\\[\n\tF_{i,j}=\\C{\\sum_{k=0}^{i-j}\\COMB{i-j}{k}\\,f^k\\,f_{(i-j-k)\\,t,(j+k)\\,u}}_0,\n\t\\quad j\\leq i.\n\\]\n\nThe following recurrence rule is hold:\n\\EQ{\\DD{F_{i,j}}{t}=F_{i+1,j}+(i-j)\\,F_{i,j+1}\\,F_{1,0}.}{EqdF}\n\nThen,\n\\[\\left.\\DD{u}{t}\\right|_0=F_{0,0},\\]\n\\[\\left.\\D{u}{t}{2}\\right|_0=F_{1,0},\\]\n\\[\\left.\\D{u}{t}{3}\\right|_0=F_{2,0}+F_{1,1}\\,F_{1,0},\\]\n\\[\n\t\\left.\\D{u}{t}{4}\\right|_0=F_{3,0}+3\\,F_{2,1}\\,F_{1,0}+F_{2,0}\\,F_{1,1}\n\t+F_{1,1}^2\\,F_{1,0},\n\\]\n\\[\n\t\\left.\\D{u}{t}{5}\\right|_0=F_{4,0}+6\\,F_{3,1}\\,F_{1,0}+F_{3,0}\\,F_{1,1}\n\t+3\\,F_{2,2}\\,F_{1,0}^2+4\\,F_{2,1}\\,F_{2,0}+7\\,F_{2,1}\\,F_{1,1}\\,F_{1,0}\n\\]\n\\[\n\t+F_{2,0}\\,F_{1,1}^2+F_{1,1}^3\\,F_{1,0},\n\\]\n\nWhen $f=f(t)$ is a function depending only in time, the above relatons are\nconsiderably simplified:\n\\[\n\t\\left.\\D{u}{t}{n}\\right|_0=F_{n,0};\\quad\n\tF_{i,j}=0,\\;\\forall j>0.\n\\]\n\nNumerical methods to solve ODE (\\ref{EqODE}) are based in approximations of the \nTaylor's serie. For instance, in 5-th order:\n\\[\n\tu\\PA{t_0+h}=u_0+h\\,\\left.\\DD{u}{t}\\right|_0\n\t+\\frac{h^2}{2}\\,\\left.\\D{u}{t}{2}\\right|_0\n\t+\\frac{h^3}{6}\\,\\left.\\D{u}{t}{3}\\right|_0\n\t+\\frac{h^4}{24}\\,\\left.\\D{u}{t}{4}\\right|_0\n\t+\\frac{h^5}{120}\\,\\left.\\D{u}{t}{5}\\right|_0\n\\]\n\\[+O\\PA{h^6}\\]\n\\[\n\t=u_0+h\\,F_{0,0}+\\frac{h^2}{2}\\,F_{1,0}\n\t+\\frac{h^3}{6}\\,\\PA{F_{2,0}+F_{1,1}\\,F_{1,0}}\n\\]\n\\[\n\t+\\frac{h^4}{24}\\,\\PA{F_{3,0}+3\\,F_{2,1}\\,F_{1,0}+F_{2,0}\\,F_{1,1}\n\t+F_{1,1}^2\\,F_{1,0}}\n\\]\n\\[\n\t+\\frac{h^5}{120}\\,\\left(F_{4,0}+6\\,F_{3,1}\\,F_{1,0}+F_{3,0}\\,F_{1,1}\n\t+3\\,F_{2,2}\\,F_{1,0}^2+4\\,F_{2,1}\\,F_{2,0}+7\\,F_{2,1}\\,F_{1,1}\\,F_{1,0}\n\t\\right.\n\\]\n\\EQ{\\left.+F_{2,0}\\,F_{1,1}^2+F_{1,1}^3\\,F_{1,0}\\right)+O\\PA{h^6}.}{EqTaylor}\n\n\\subsection{Decay ODE}\n\nA common particular case of ODE are the ''decay equations'' defined as:\n\\EQ{\\DD{u}{t}=-|g(u)|\\,u,\\quad g_u\\geq0.}{EqDODE}\nwith $g$ an increasing function on $u$. In these equations the variable module\ndecreases always in time:\n\\[\\frac{du}{u}=-|g|\\,dt\\Rightarrow\\]\n\\[u(t)=u_0\\,\\exp\\PA{-\\int_0^t|g|\\,dt}\\Rightarrow\\]\n\\EQ{|u(t)|=\\ABS{u_0}\\,\\exp\\PA{-\\int_0^t|g|\\,dt.}}{EqDecay}\nAs $|g|$ is positive the integral is an increasing function. Then, $|u|$ is a\ndecreasing function. Another interesting property of these equations is that $u$\ncannot change the sign:\n\\EQ{\\frac{u(t)}{u_0}=\\exp\\PA{-\\int_0^t|g|\\,dt}\\geq 0.}{EqDODEP}\nSolving DODE (\\ref{EqDODE}) numerically in first order using the Euler's rule:\n\\[u\\PA{t_0+h}=u\\PA{t_0}-h\\,\\ABS{g\\PA{u\\PA{t_0}}}\\,u\\PA{t_0}\\Rightarrow\\]\n\\EQ{\\frac{u\\PA{t_0+h}}{u\\PA{t_0}}=1-h\\,\\ABS{g\\PA{u\\PA{t_0}}}.}{EqDODEI}\nThen, to prevent numerical variable sign changes the time step size has to be\nlimited by:\n\\EQ\n{\n\t\\frac{u\\PA{t_0+h}}{u\\PA{t_0}}\\geq0\\Rightarrow\\;\n\t1-h\\,\\ABS{g\\PA{u\\PA{t_0}}}\\geq0\\Rightarrow\\;\n\th\\leq\\frac{1}{|g|}.\n}{EqDODELimit}\nIn these equations, we use the time step size as:\n\\EQ{h=\\frac{k_t}{|g|},}{EqDODE dt}\nwith $k_t\\leq1$ the dimensionless stability factor. \n\n\\subsection{Ballistic ODE}\n\nBallistic equations are a particular form of ODE follow a form:\n\\EQ{\\ddot{\\vec{r}}(t)=\\ddot{\\vec{r}}\\PA{\\dot{\\vec{r}}(t)},}{EqBODE}\nwhere $\\vec{r}$, $\\dot{\\vec{r}}$, $\\ddot{\\vec{r}}$ are the vectors of position,\nvelocity and acceleration respectively.\n\n\\section{Runge-Kutta methods}\n\nWe use a variation of the Einstein's notation, where repeated indeces are\nsummed, in order to simplify the notation:\n\\EQ{f_{i,j}\\,g_j\\equiv\\sum_{j=0}^{i-1}f_{i,j}\\,g_j.}{EqNotation}\nRunge-Kutta methods are methods in the form:\n\\EQ\n{\n\tu_i=u_0+h\\,b_{i,j}\\,f_j,\\quad\n\tf_i=f\\PA{t+d_i\\,h,u_i},\\quad\n\td_0=0,\\quad\n\td_i=\\sum_{j=0}^{i-1}b_{i,j}.\n}{EqRK}\nEvery $i$-th step introduces $i$ new freedom degrees.\n\nDeveloping the steps in Taylor's series to 5-th order:\n\\[u_1=u_0+h\\,d_1\\,F_{0,0},\\]\n\\[\n\tf_1=F_{0,0}+h\\,d_1\\,F_{1,0}+\\frac{h^2\\,d_1^2}{2}\\,F_{2,0}\n\t+\\frac{h^3\\,d_1^3}{6}\\,F_{3,0}+\\frac{h^4\\,d_1^4}{24}\\,F_{4,0}+O\\PA{h^5},\n\\]\n\\[\n\tu_2=u_0+h\\,d_2\\,F_{0,0}+h^2\\,b_{2,j}\\,d_j\\,F_{1,0}\n\t+\\frac{h^3\\,b_{2,j}\\,d_j^2}{2}\\,F_{2,0}\n\t+\\frac{h^4\\,b_{2,j}\\,d_j^3}{6}\\,F_{3,0}\n\\]\n\\[\t+\\frac{h^5\\,b_{2,j}\\,d_j^4}{24}\\,F_{4,0}+O\\PA{h^6},\\]\n\\[\n\tf_2=F_{0,0}+h\\,d_2\\,F_{1,0}+\\frac{h^2\\,d_2^2}{2}\\,F_{2,0}\n\t+h^2\\,b_{2,j}\\,d_j\\,F_{1,1}\\,F_{1,0}+\\frac{h^3\\,d_2^3}{6}\\,F_{3,0}\n\\]\n\\[\n\t+\\frac{h^3\\,b_{2,j}\\,d_j^2}{2}\\,F_{2,0}\\,F_{1,1}\n\t+\\frac{h^4\\,d_2^4}{24}\\,F_{4,0}\n\t+\\frac{h^4\\,d_2^2\\,b_{2,j}\\,d_j}{2}\\,F_{3,1}\\,F_{1,0}\n\\]\n\\[\n\t+\\frac{h^4\\,b_{2,j}\\,d_j^3}{6}\\,F_{3,0}\\,F_{1,1}\n\t+\\frac{h^4\\,\\PA{b_{2,j}\\,d_j}^2}{2}\\,F_{2,2}\\,F_{1,0}^2\n\t+\\frac{h^4\\,d_2\\,b_{2,j}\\,d_j^2}{2}\\,F_{2,1}\\,F_{2,0}\n\t+O\\PA{h^5},\n\\]\n\\[\n\tu_3=u_0+h\\,d_3\\,F_{0,0}+h^2\\,b_{3,j}\\,d_j\\,F_{1,0}\n\t+\\frac{h^3\\,b_{3,j}\\,d_j^2}{2}\\,F_{2,0}\n\t+h^3\\,b_{3,j}\\,b_{j,k}\\,d_k\\,F_{1,1}\\,F_{1,0}\n\\]\n\\[\n\t+\\frac{h^4\\,b_{3,j}\\,d_j^3}{6}\\,F_{3,0}\n\t+\\frac{h^4\\,b_{3,j}\\,b_{j,k}\\,d_k^2}{2}\\,F_{2,0}\\,F_{1,1}\n\t+\\frac{h^5\\,b_{3,j}\\,d_j^4}{24}\\,F_{4,0}\n\\]\n\\[\n\t+\\frac{h^5\\,b_{3,j}\\,d_j^2\\,b_{j,k}\\,d_k}{2}\\,F_{3,1}\\,F_{1,0}\n\t+\\frac{h^5\\,b_{3,j}\\,b_{j,k}\\,d_k^3}{6}\\,F_{3,0}\\,F_{1,1}\n\t+\\frac{h^5\\,b_{3,j}\\,\\PA{b_{j,k}\\,d_k}^2}{2}\\,F_{2,2}\\,F_{1,0}^2\n\\]\n\\[\n\t+\\frac{h^5\\,b_{3,j}\\,d_j\\,b_{j,k}\\,d_k^2}{2}\\,F_{2,1}\\,F_{2,0}\n\t+O\\PA{h^6}\n\\]\n\\[\n\tf_3=F_{0,0}+h\\,d_3\\,F_{1,0}+\\frac{h^2\\,d_3^2}{2}\\,F_{2,0}\n\t+h^2\\,b_{3,j}\\,d_j\\,F_{1,1}\\,F_{1,0}+\\frac{h^3\\,d_3^3}{6}\\,F_{3,0}\n\\]\n\\[\n\t+h^3\\,d_3\\,b_{3,j}\\,d_j\\,F_{2,1}\\,F_{1,0}\n\t+\\frac{h^3\\,b_{3,j}\\,d_j^2}{2}\\,F_{2,0}\\,F_{1,1}\n\t+h^3\\,b_{3,j}\\,b_{j,k}\\,d_k\\,F_{1,1}^2\\,F_{1,0}\n\t+\\frac{h^4\\,d_3^4}{24}\\,F_{4,0}\n\\]\n\\[\n\t+\\frac{h^4\\,d_3^2\\,b_{3,j}\\,d_j}{2}\\,F_{3,1}\\,F_{1,0}\n\t+\\frac{h^4\\,b_{3,j}\\,d_j^3}{6}\\,F_{3,0}\\,F_{1,1}\n\t+\\frac{h^4\\,\\PA{b_{3,j}\\,d_j}^2}{2}\\,F_{2,2}\\,F_{1,0}^2\n\\]\n\\[\n\t+\\frac{h^4\\,d_3\\,b_{3,j}\\,d_j^2}{2}\\,F_{2,1}\\,F_{2,0}\n\t+h^4\\,d_3\\,b_{3,j}\\,b_{j,k}\\,d_k\\,F_{2,1}\\,F_{1,1}\\,F_{1,0}\n\t+\\frac{h^4\\,b_{3,j}\\,b_{j,k}\\,d_k^2}{2}\\,F_{2,0}\\,F_{1,1}^2\n\\]\n\\[+O\\PA{h^5},\\]\n\\[\n\tu_4=u_0+h\\,d_4\\,F_{0,0}+h^2\\,b_{4,j}\\,d_j\\,F_{1,0}\n\t+\\frac{h^3\\,b_{4,j}\\,d_j^2}{2}\\,F_{2,0}\n\t+h^3\\,b_{4,j}\\,b_{j,k}\\,d_k\\,F_{1,1}\\,F_{1,0}\n\\]\n\\[\n\t+\\frac{h^4\\,b_{4,j}\\,d_j^3}{6}\\,F_{3,0}\n\t+h^4\\,b_{4,j}\\,d_j\\,b_{j,k}\\,d_k\\,F_{2,1}\\,F_{1,0}\n\t+\\frac{h^4\\,b_{4,j}\\,b_{j,k}\\,d_k^2}{2}\\,F_{2,0}\\,F_{1,1}\n\\]\n\\[\n\t+h^4\\,b_{4,j}\\,b_{j,k}\\,b_{k,l}\\,d_l\\,F_{1,1}^2\\,F_{1,0}\n\t+\\frac{h^5\\,b_{4,j}\\,d_j^4}{24}\\,F_{4,0}\n\t+\\frac{h^5\\,b_{4,j}\\,d_j^2\\,b_{j,k}\\,d_k}{2}\\,F_{3,1}\\,F_{1,0}\n\\]\n\\[\n\t+\\frac{h^5\\,b_{4,j}\\,b_{j,k}\\,d_k^3}{6}\\,F_{3,0}\\,F_{1,1}\n\t+\\frac{h^5\\,b_{4,j}\\,\\PA{b_{j,k}\\,d_k}^2}{2}\\,F_{2,2}\\,F_{1,0}^2\n\t+\\frac{h^5\\,b_{4,j}\\,d_j\\,b_{j,k}\\,d_k^2}{2}\\,F_{2,1}\\,F_{2,0}\n\\]\n\\[\n\t+h^5\\,b_{4,j}\\,d_j\\,b_{j,k}\\,b_{k,l}\\,d_l\\,F_{2,1}\\,F_{1,1}\\,F_{1,0}\n\t+\\frac{h^5\\,b_{4,j}\\,b_{j,k}\\,b_{k,l}\\,d_k^2}{2}\\,F_{2,0}\\,F_{1,1}^2\n\t+O\\PA{h^6}\n\\]\n\nComparing with the Taylor's series (\\ref{EqTaylor}) a $i$-steps Runge-Kutta\nmethod has to hold the following conditions to get different approximation\norders:\n\\begin{itemize}\n\\item First order:\n\t\\EQ{d_i=1.}{EqRKI}\n\\item Second order:\n\t\\EQ{b_{i,j}\\,d_j=\\frac12.}{EqRKII}\n\\item Third order:\n\t\\EQ\n\t{\n\t\tb_{i,j}\\,d_j^2=\\frac13,\\quad\n\t\tb_{i,j}\\,b_{j,k}\\,d_k=\\frac16.\n\t}{EqRKIII}\n\\item Fourth order:\n\t\\EQ\n\t{\n\t\tb_{i,j}\\,d_j^3=\\frac14,\\quad\n\t\tb_{i,j}\\,d_j\\,b_{j,k}\\,d_k=\\frac18,\\quad\n\t\tb_{i,j}\\,b_{j,k}\\,d_k^2=\\frac1{12},\\quad\n\t\tb_{i,j}\\,b_{j,k}\\,b_{k,l}\\,d_l=\\frac1{24}.\n\t}{EqRKIV}\n\\item Fifth order:\n\t\\[\n\t\tb_{i,j}\\,d_j^4=\\frac15,\\quad\n\t\tb_{i,j}\\,d_j^2\\,b_{j,k}\\,d_k=\\frac1{10},\\quad\n\t\tb_{i,j}\\,b_{j,k}\\,d_k^3=\\frac1{20},\n\t\\]\n\t\\[\n\t\tb_{i,j}\\,\\PA{b_{j,k}\\,d_k}^2=\\frac1{20},\\quad\n\t\tb_{i,j}\\,d_j\\,b_{j,k}\\,d_k^2=\\frac1{15},\\quad\n\t\tb_{i,j}\\,d_j\\,b_{j,k}\\,b_{k,l}\\,d_l=\\frac7{120},\n\t\\]\n\t\\EQ\n\t{\n\t\tb_{i,j}\\,b_{j,k}\\,b_{k,l}\\,d_l^2=\\frac1{60},\\quad\n\t\tb_{i,j}\\,b_{j,k}\\,b_{k,l}\\,b_{l,m}\\,d_m=\\frac1{120}.\n\t}{EqRKV}\n\\end{itemize}\n\nOn equations depending only in time, first of the above equations are\nsufficient:\n\\begin{itemize}\n\\item $n$-th order:\n\t\\EQ{b_{i,j}\\,d_j^{n-1}=\\frac1n.}{EqRKt}\n\\end{itemize}\n\n\\subsection{Strong stability}\n\nGeneral Runge-Kutta methods (\\ref{EqRK}) can also be expressed as:\n\\EQ\n{\n\tu_i=\\sum_{j=0}^{i-1}a_{i,j}\\,\\PA{u_j+h\\,c_{i,j}\\,f_j},\\quad\n\t\\sum_{j=0}^{i-1}a_{i,j}=1.\n}{EqRKac}\nThe following relation is hold:\n\\EQ{b_{i,j}=(a\\,c)_{i,j}+\\sum_{k=j+1}^{i-1}a_{i,k}\\,b_{k,j}.}{EqRKacb}\nThis form introduces new $i-1$ freedom degrees for each $i$-th step.\n\nIn the context of propagation equations it has been demonstrated that a\nRunge-Kutta method preserves monotonicity, and therefore absence of numerical\nspurious oscillations, if:\n\\EQ{a_{i,j},\\,c_{i,j}\\geq0,\\quad k_t\\leq\\frac1{\\max\\PA{c_{i,j}}}}{EqRKTVD}\n\n\\subsection{Simple stability}\n\nOn decay ODE a more simple stability condition can be obtained. In these\nequations we define a Runge-Kutta method as ''simple stable'' when it preserves\nthe variable sign for each time step. Assuming positive $u$:\n\\[\n\tb_{i,j}\\geq0\\Rightarrow\\;\n\tu_i=u_0-h\\,b_{i,j}\\,\\ABS{g_j}\\,u_j\\leq u_0\\Rightarrow\\;\n\tf_i\\leq f_0\\Rightarrow\n\\]\n\\EQ\n{\n\tu_i\\geq u_0-h\\,\\sum_jb_{i,j}\\,\\ABS{g_0}\\,u_0\n\t=u_0\\,\\PA{1-h\\,d_i\\,\\ABS{g_0}}\n}{EqRKSimpleCondition}\nwherefrom preserving sign in $u$ is ensured by:\n\\EQ{b_{i,j}\\geq0,\\quad k_t\\leq\\frac{1}{\\max\\PA{d_i}}}{EqRKSimple}\nThese conditions are sufficient but not necessary.\n\nA strong stable method is always simple stable, (\\ref{EqRKTVD}) conditions\nensures:\n\\[\\frac{u_j+h\\,c_{i,j}\\,f_j}{u_j}\\geq0\\Rightarrow\\]\n\\EQ{\\frac{u_i}{u_0}=\\sum_ja_{i,j}\\,\\frac{u_j+h\\,c_{i,j}\\,f_j}{u_j}\\geq0.}\n{EqRKSimpleStrong}\n\n\\subsection{Ballistic ODE}\n\nFor ballistic ODE, Runge-Kutta methods are adapted by doing:\n\\EQ\n{\n\t\\vec{r}_i=\\vec{r}_0+h\\,b_{i,j}\\,\\dot{\\vec{r}}_j,\\quad\n\t\\dot{\\vec{r}}_i=\\dot{\\vec{r}}_0+h\\,b_{i,j}\\,\\ddot{\\vec{r}}_j,\\quad\n\t\\ddot{\\vec{r}}_i=\\ddot{\\vec{r}}\\PA{\\dot{\\vec{r}}_i}.\n}{EqRKBODE}\n\n\\subsection{One step first order (Euler's method)}\n\nThe one step first order method, proposed by Euler, is defined by the\ncoefficient matrices of table~\\ref{TableRKiI}.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|c}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1 & 1\n\t\\end{tabular},~\n\t\\begin{tabular}{c}\n\t\t$a_{i,j}$ \\\\ \\hline\n\t\t1\n\t\\end{tabular},~\n\t\\begin{tabular}{c}\n\t\t$c_{i,j}$ \\\\ \\hline\n\t\t1\n\t\\end{tabular}\n\t\\caption{Coefficients of the one step first order Runge-Kutta method (RK1-1).\n\t\t\\label{TableRKiI}}\n\\end{table}\nThis a first order method with strong and simple stability for $k_t\\leq1$.\n\n\\subsection{Two steps second order}\n\nWe consider two interesting two steps second order methods defined by the\ncoefficients matrices of tables~\\ref{TableRKiiIIa} and~\\ref{TableRKiiIIb}.\nFirst method is second order, third order in equations depending only in time,\nsimple stable for $k_t\\leq1$ and strong stable for $k_t\\leq1/2$. Second method\nis second order and simple and strong stable for $k_t\\leq1$.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|cc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t2/3 & 2/3 \\\\\n\t\t1 & 1/4 & 3/4\n\t\\end{tabular},~\n\t\\begin{tabular}{cc}\n\t\t$a_{i,j}$ \\\\ \\hline\n\t\t1 \\\\\n\t\t5/8 & 3/8\n\t\\end{tabular},~\n\t\\begin{tabular}{cc}\n\t\t$c_{i,j}$ \\\\ \\hline\n\t\t2/3 \\\\\n\t\t0 & 2\n\t\\end{tabular}\n\t\\caption{Coefficients of the two steps second order Runge-Kutta method optime\n\t\tin accuracy (RK2-2(3)).\\label{TableRKiiIIa}}\n\\end{table}\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|cc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1 & 1 \\\\\n\t\t1 & 1/2 & 1/2\n\t\\end{tabular},~\n\t\\begin{tabular}{cc}\n\t\t$a_{i,j}$ \\\\ \\hline\n\t\t1 \\\\\n\t\t1/2 & 1/2\n\t\\end{tabular},~\n\t\\begin{tabular}{cc}\n\t\t$c_{i,j}$ \\\\ \\hline\n\t\t1 \\\\\n\t\t0 & 1\n\t\\end{tabular}\n\t\\caption{Coefficients of the two steps second order Runge-Kutta method optime\n\t\tin strong stability (RK2-2).\\label{TableRKiiIIb}}\n\\end{table}\n\n\\subsection{Three steps third order}\n\nThe most interesting three steps Runge-Kutta is the defined by the coefficients\nof the table~\\ref{TableRKiiiIII}.\nThis method is third order, fourth order in equations depending only in time and\nsimple and strong stable for $k_t\\leq1$.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|ccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1 & 1 \\\\\n\t\t1/2 & 1/4 & 1/4 \\\\\n\t\t1 & 1/6 & 1/6 & 2/3\n\t\\end{tabular},~\n\t\\begin{tabular}{ccc}\n\t\t$a_{i,j}$ \\\\ \\hline\n\t\t1 \\\\\n\t\t3/4 & 1/4 \\\\\n\t\t1/3 & 0 & 2/3\n\t\\end{tabular},~\n\t\\begin{tabular}{ccc}\n\t\t$c_{i,j}$ \\\\ \\hline\n\t\t1 \\\\\n\t\t0 & 1 \\\\\n\t\t0 & 0 & 1\n\t\\end{tabular}\n\t\\caption{Coefficients of the three steps third order Runge-Kutta method\n\t\t(RK3-3(4)).\\label{TableRKiiiIII}}\n\\end{table}\n\n\\subsection{Four steps fourth order}\n\nThe only four steps fourth order simple stable for $k_t\\leq1$ is the defined by\nthe coefficients of the table~\\ref{TableRKivIV}.\nThey are not fourth order strong stable Runge-Kutta methods of four steps.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|cccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1/2 & 1/2 \\\\\n\t\t1/2 & 0 & 1/2 \\\\\n\t\t1 & 0 & 0 & 1 \\\\\n\t\t1 & 1/6 & 1/3 & 1/3 & 1/6\n\t\\end{tabular}\n\t\\caption{Coefficients of the four steps fourth order Runge-Kutta method\n\t\t(RK4-4).\\label{TableRKivIV}}\n\\end{table}\n\n\\subsection{Five steps fourth order}\n\nIt is not possible to build a fifth order Runge-Kutta method with five steps.\nThe method defined in table~\\ref{TableRKvIV} is simple stable for $k_t\\leq1$,\nfourth order and fifth order in equations depending only on time.\n\\begin{table}[ht]\n\t\\renewcommand*{\\arraystretch}{1.3}\n\t\\centering\n\t\\begin{tabular}{c|ccccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t$\\frac{11}{40}$ & $\\frac{11}{40}$ \\\\\n\t\t1 & $\\frac{223}{803}$ & $\\frac{580}{803}$ \\\\\n\t\t$\\frac12$ & $\\frac{1.41}{146}$ & $\\frac25$ & $\\frac{13.19}{146}$ \\\\\n\t\t$\\frac{17}{20}$ & $\\frac{661.15057}{19272}$ & \n\t\t\t$\\frac{11289.7731}{46574}$ & $\\frac{156.50557}{50808}$\n\t\t\t& $\\frac{2737}{4800}$ \\\\\n\t\t1 & $\\frac{107}{1122}$ & $\\frac{64000}{198099}$ & $\\frac7{522}$ & \n\t\t\t$\\frac{46}{189}$ & $\\frac{8000}{24633}$\n\t\\end{tabular}\n\t\\caption{Coefficients of the five steps fourth order, fifth order in\n\t\tequations depending only in time, Runge-Kutta method (RK5-4(5)).\n\t\t\\label{TableRKvIV}}\n\\end{table}\n\n\\section{Runge-Kutta pairs}\n\n\\EQ{\\hat{u}_i=u_0+h\\,\\hat{b}_{i,j}\\,f_j.}{EqRKpair}\n\n\\EQ{E_i=\\hat{u}_i-u_i=h\\,\\PA{\\hat{b}-b}_{i,j}\\,f_j.}{EqRKpairE}\n\n\\subsection{Two steps first-second order pairs}\n\nThe two second order methods defined by the coefficients matrices of\ntables~\\ref{TableRKiiIIa} and~\\ref{TableRKiiIIb} can be combined con the\nEuler's method defined in table~\\ref{TableRKiI} to build the two steps second\norder Runge-Kutta pairs defined in tables~\\ref{TableRKIiiIIa}\nand~\\ref{TableRKIiiIIb}.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|cc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t2/3 & 2/3 \\\\\n\t\t1 & 1/4 & 3/4 \\\\ \\hline\n\t\t$\\hat{b}_{2,j}$ & 1 & 0 \\\\ \\hline\n\t\t$e_{2,j}$ & 3/4 & -3/4\n\t\\end{tabular}\n\t\\caption{Coefficients of the two steps first-second order, first-third order\n\t\tin equations depending only in time, Runge-Kutta pair (RK2-1-2(3)).\n\t\t\\label{TableRKIiiIIa}}\n\\end{table}\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|cc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1 & 1 \\\\\n\t\t1 & 1/2 & 1/2 \\\\ \\hline\n\t\t$\\hat{b}_{2,j}$ & 1 & 0 \\\\ \\hline\n\t\t$e_{2,j}$ & 1/2 & -1/2\n\t\\end{tabular}\n\t\\caption{Coefficients of the two steps first-second order Runge-Kutta pair\n\t\toptime in strong stability (RK2-1-2).\\label{TableRKIiiIIb}}\n\\end{table}\n\n\\subsection{Three steps second-third order pair}\n\nThe three steps third order Runge-Kutta defined in table~\\ref{TableRKiiiIII}\ncan be combined with the second order defined in table~\\ref{TableRKiiIIb} to\nproduce the three steps second-third order pair defined in\ntable~\\ref{TableRKIIiiiIII}.\n\\begin{table}[ht]\n\t\\centering\n\t\\begin{tabular}{c|ccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t1 & 1 \\\\\n\t\t1/2 & 1/4 & 1/4 \\\\\n\t\t1 & 1/6 & 1/6 & 2/3 \\\\ \\hline\n\t\t$\\hat{b}_{3,j}$ & 1/2 & 1/2 & 0 \\\\ \\hline\n\t\t$e_{3,j}$ & 1/3 & 1/3 & -2/3\n\t\\end{tabular}\n\t\\caption{Coefficients of the three steps second-third order, second-fourth\n\t\torder in equations depending only in time, Runge-Kutta pair (RK3-2-3(4)).\n\t\t\\label{TableRKIIiiiIII}}\n\\end{table}\n\n\\subsection{Four steps second-third order pair}\n\nIt is not possible to build a four steps third-fourth order pair but they are\ninfinity two-three order pairs of four steps. The defined in\ntable~\\ref{TableRKIIivIII} is moreover simple stable for $k_t\\leq1$ and \nthird-fourth order in equations depending only on time.\n\\begin{table}[ht]\n\t\\renewcommand*{\\arraystretch}{1.3}\n\t\\centering\n\t\\begin{tabular}{c|cccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t$\\frac13$ & $\\frac13$ \\\\\n\t\t1 & 0 & 1 \\\\\n\t\t$\\frac23$ & $\\frac16$ & $\\frac14$ & $\\frac14$ \\\\\n\t\t1 & $\\frac18$ & $\\frac38$ & $\\frac18$ & $\\frac38$ \\\\ \\hline\n\t\t$\\hat{b}_{4,j}$ & 0 & $\\frac34$ & $\\frac14$ & 0 \\\\ \\hline\n\t\t$e_{4,j}$ & $-\\frac18$ & $\\frac38$ & $\\frac18$ & $-\\frac38$\n\t\\end{tabular}\n\t\\caption{Coefficients of the four steps second-third order, third-fourth order\n\t\tin equations depending only in time, Runge-Kutta pair (RK4-2(3)-3(4)).\n\t\t\\label{TableRKIIivIII}}\n\\end{table}\n\n\\subsection{Five steps third-fourth order pair}\n\nThey are infinity third-fourth order pairs of five steps. The defined in\ntable~\\ref{TableRKIIIvIV} is moreover simple stable for $k_t\\leq1$ and \nfourth-fifth order in equations depending only on time.\n\\begin{table}[ht]\n\t\\renewcommand*{\\arraystretch}{1.3}\n\t\\centering\n\t\\begin{tabular}{c|ccccc}\n\t\t$d_{i}$ & $b_{i,j}$ \\\\ \\hline\n\t\t$\\frac{11}{40}$ & $\\frac{11}{40}$ \\\\\n\t\t1 & $\\frac{223}{803}$ & $\\frac{580}{803}$ \\\\\n\t\t$\\frac12$ & $\\frac{141}{14600}$ & $\\frac25$ & $\\frac{1319}{14600}$ \\\\\n\t\t$\\frac{17}{20}$ & $\\frac{66115057}{1927200000}$ & \n\t\t\t$\\frac{112897731}{465740000}$ & $\\frac{15650557}{5080800000}$\n\t\t\t& $\\frac{2737}{4800}$ \\\\\n\t\t1 & $\\frac{107}{1122}$ & $\\frac{64000}{198099}$ & $\\frac7{522}$ & \n\t\t\t$\\frac{46}{189}$ & $\\frac{8000}{24633}$ \\\\ \\hline\n\t\t$\\hat{b}_{5,j}$ & $\\frac16$ & 0 & $\\frac16$ & $\\frac23$ & 0 \\\\ \\hline\n\t\t$e_{5,j}$ & $\\frac{40}{561}$ & $-\\frac{64000}{198099}$ & $\\frac{40}{261}$\n\t\t\t& $\\frac{80}{189}$ & $-\\frac{8000}{24633}$\n\t\\end{tabular}\n\t\\caption{Coefficients of the five steps third-fourth order, fourth-fifth order\n\t\tin equations depending only in time, Runge-Kutta pair (RK-3(4)-4(5)).\n\t\t\\label{TableRKIIIvIV}}\n\\end{table}\n\n\\section{Multi-steps methods}\n\n\\section{Multi-steps pairs}\n\n\\section{Tests}\n\n\\section{Conclusions}\n\n\\end{document}\n", "meta": {"hexsha": "127091f653ba501723568d46c4908fd83e935e04", "size": 18897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode.tex", "max_stars_repo_name": "jburguete/ode", "max_stars_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061", "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": "ode.tex", "max_issues_repo_name": "jburguete/ode", "max_issues_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061", "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": "ode.tex", "max_forks_repo_name": "jburguete/ode", "max_forks_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061", "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": 31.495, "max_line_length": 80, "alphanum_fraction": 0.6110493729, "num_tokens": 8954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6052178488038897}}
{"text": "\\subsection{Support Vector Machine}\r\n\r\n\\begin{figure}[h]\r\n\\center\\includegraphics[width = .8\\textwidth]{svm.png}\r\n\\caption{Parameter Tuning of SVM}\r\n\\label{svm}\r\n\\end{figure}\r\n\r\nKernel support vector machines (SVMs) are supervised learning models with associated learning algorithms commonly used in classification.\\cite{cristianini2000introduction}\r\n\r\nThe effectiveness of SVM depends on the selection of kernel, the kernel's parameters, and soft margin parameter C. A common choice is a Gaussian kernel, which has a single parameter $\\gamma$. The best combination of C and $\\gamma$ is often selected by a grid search with exponentially growing sequences of C and $\\gamma$. Each combination of parameter choices is checked using cross validation, and the parameters with best cross-validation accuracy are picked. We can do this with function \\emph{tune} given a list of C. In Figure \\ref{svm} we can see the CV error and test error of SVM using different cost and gamma. The best C is 0.05 and the best $\\gamma$ is 0.135.\r\n\r\nWith the parameters tunned we can conduct classfication. The test error are shown in Table \\ref{tblsvm}. The Type \\uppercase\\expandafter{\\romannumeral1} error is slightly larger than random forest, but Type \\uppercase\\expandafter{\\romannumeral2} error is significantly lower than random forest. So SVM made less mistake in predicting raining days compared to random forest. This could partly be explained by the fact that this isn't a linearly separable case. \r\n\r\n\\begin{table}[h]\r\n\\setlength{\\belowcaptionskip}{5pt}\r\n\\caption{Confusion Matrix and Error Rates of SVM}\r\n\\label{tblsvm}\r\n\\centering\r\n\\renewcommand\\arraystretch{1.5}\r\n\\begin{tabular}{rrrrr}\r\n\\hline\r\n\\hline\r\n & & \\multicolumn{2}{c}{True Condition} & \\\\\r\n\\hline\r\n & & Non-Precipitation & Precipitation & \\\\\r\n\\cline{1-4}\r\n\\multirow{2}{*}{Prediction} & {Non-Precipitation} & 326 & 47 & \\\\\r\n\\cline{2-4}\r\n&Precipitation&54&231&\\\\\r\n\\hline\r\n&Error Rate & 0.142 & 0.169 & 0.1535\\\\\r\n\\cline{2-5}\r\n& & Type \\uppercase\\expandafter{\\romannumeral1} & Type \\uppercase\\expandafter{\\romannumeral2} & Overall\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{table}", "meta": {"hexsha": "7d10e415c5a4fec5e7981670834fbb051c5ea960", "size": 2117, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/svm.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/svm.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/svm.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": 57.2162162162, "max_line_length": 671, "alphanum_fraction": 0.7553141238, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6052178488038897}}
{"text": "\\section*{Exercise 7.1}\r\nThe estimator of p is\r\n\\spl{\r\n    \\hat{p}=\\frac{E}{n}=\\frac{\\overline{X}}{n}=\\frac{0\\cdot39+1\\cdot23+2\\cdot12+3\\cdot1}{75\\cdot24}=\\frac{1}{36}.\r\n}\r\n\r\nThe expected frequency can be calculated by $E_i=nP[X=i]=n\\binom{n}{i}\\hat{p}^i(1-\\hat{p})^{n-i}$.\r\n\\begin{table}[H]\r\n    \\centering\r\n    \\begin{tabular}{ccccc}\\hline\r\n        Values & 0 & 1 & 2 & 3\\\\\\hline\r\n        Expected Frequency & 38.145 & 26.156 & 8.594 & 2.105\\\\\\hline\r\n    \\end{tabular}\r\n\\end{table}\r\n\r\nWe notice that $E_i\\geq5$ less than 80\\% categories. Thus we merge the last two categories.\r\n\\begin{table}[H]\r\n    \\centering\r\n    \\begin{tabular}{ccccc}\\hline\r\n        Values & 0 & 1 & 2\\\\\\hline\r\n        Expected Frequency & 38.145 & 26.156 & 10.699\\\\\\hline\r\n    \\end{tabular}\r\n\\end{table}\r\n\r\nThen,we calculate the Pearson's Statistic\r\n\\spl{\r\n    X^2=\\sum_{i=1}^N\\frac{(O_i-E_i)^2}{E_i}=\\frac{(39-38.145)^2}{38.145}+\\frac{(23-26.156)^2}{26.156}+\\frac{(13-10.699)^2}{10.699}=0.876.\r\n}\r\n\r\nThe degree of freedom is $3-1-1=1$. Hence, $X^2=0.876<\\chi^2_{0.05,1}=3.84$. Hence, we conclude that follows binomial distribution at 5\\% level of significance.\r\n\r\n\\section*{Exercise 7.2}\r\n\\begin{table}[h]\r\n    \\centering\r\n    \\begin{tabular}{c|cccc|c}\r\n        Mounting Position & A & B & C & D & \\\\\\hline\r\n        1 & 22 & 46 & 18 & 9 & 95\\\\\r\n        2 & 4 & 17 & 6 & 12 & 39\\\\\\hline\r\n        & 26 & 63 & 24 & 21 & 134\\\\\r\n    \\end{tabular}\r\n\\end{table}\r\n\r\n\\spl{\r\n    H_0:\\ p_{ij}=p_{i\\cdot}p_{\\cdot j}\r\n}\r\n\r\nSince $E_{ij}=\\frac{n_{i\\cdot}n_{\\cdot j}}{n}$, then\r\n\\spl{\r\n    E_{11}&=18.43,\\quad E_{12}=44.66,\\quad E_{13}=17.01,\\quad E_{14}=14.88\\\\\r\n    E_{21}&=7.57,\\quad E_{22}=18.34,\\quad E_{23}=6.99,\\quad E_{24}=6.11\\\\\r\n}\r\n\r\n\\spl{\r\n    X_{(2-1)(4-1)}^2=\\sum_{i=1}^r\\sum_{j=1}^c\\frac{(O_{ij}-E_{ij})^2}{E_{ij}}=10.71.\r\n}\r\n\r\nSince the statistic follows 3 degrees of freedom chi-squared distribution, we compare the value with $\\chi_{0.05,3}^2=7.8147$. We find that $X_3^2>\\chi_{0.05,3}^2$. Thus, we reject the hypothesis at 5\\% level of significance. We claim that the type of failure depends on the mounting position.\r\n\r\n\\section*{Exercise 7.3}\r\n\\begin{table}[h]\r\n    \\centering\r\n    \\begin{tabular}{c|ccccc|c}\r\n        & 1 & 2 & 3 & 4 & 5 &\\\\\\hline\r\n        Male & 50 &47 & 103 & 76 & 24 & 300\\\\\r\n        Female & 21 & 27 & 50 & 35 & 17 & 150\\\\\\hline\r\n        & 71 & 74 & 153 & 111 & 41 & 450\\\\\r\n    \\end{tabular}\r\n\\end{table}\r\nWe assume that the increase in the salary is independent od the workers' gender, saying that\r\n\\spl{\r\n    H_0:\\ p_{ij}=p_{i\\cdot}p_{\\cdot j}\r\n}\r\n\r\nSince $E_{ij}=\\frac{n_{i\\cdot}n_{\\cdot j}}{n}$, then\r\n\\spl{\r\n    E_{11}&=47.33,\\quad E_{12}=49.33,\\quad E_{13}=102,\\quad E_{14}=74,\\quad E_{15}=27.33\\\\\r\n    E_{21}&=23.67,\\quad E_{22}=24.67,\\quad E_{23}=51,\\quad E_{24}=37,\\quad E_{25}=13.67\\\\\r\n}\r\n\r\n\\spl{\r\n    X_{(2-1)(5-1)}^2=\\sum_{i=1}^r\\sum_{j=1}^c\\frac{(O_{ij}-E_{ij})^2}{E_{ij}}=2.19.\r\n}\r\n\r\nSince the statistic follows 4 degrees of freedom chi-squared distribution, we compare the value with $\\chi_{0.05,4}^2=9.4877$. We find that $X_4^2<\\chi_{0.05,3}^2$. Thus, we support the hypothesis at 5\\% level of significance. We claim that increase in salary is independent of the gender.\r\n\r\n\\section*{Exercise 7.4}\r\nUsing the Helmert transformation $\\textbf{Y}\\rightarrow\\textbf{D}$, we rewrite $SSE_{pe}$\r\n\\spl{\r\n    SSE_{pe}&=\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\sum_{j=1}^{n_i}(Y_{ij}-\\overline{Y_{ij}})^2\\\\\r\n    &=\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\bigg[\\sum_{j=1}^{n_i}Y_{ij}^2-n_i\\overline{Y_{ij}}^2\\bigg]\\\\\r\n    &=\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\bigg[\\sum_{j=1}^{n_i}D_{ij}^2-D_{i1}^2\\bigg]\\\\\r\n    &=\\frac{1}{\\sigma^2}\\sum_{i=1}^k\\bigg[\\sum_{j=2}^{n_i}D_{ij}^2\\bigg]\\\\\r\n    &=\\frac{1}{\\sigma^2}\\bigg[\\sum_{i=1}^nD_i^2-\\sum_{i=1}^kD_{i1}^2\\bigg]\\\\\r\n    &=\\sum_{i=1}^n\\frac{D_i^2}{\\sigma^2}-\\sum_{i=1}^k\\frac{D_{i1}^2}{\\sigma^2},\r\n}\r\nwhich is the sum of square of $(n-k)$ normally distributed variables. Hence, it follows $(n-k)$ degrees of freedom chi-squared distribution.\r\n\r\n\\section*{Exercise 7.5}\r\nConsider $\\cov(\\overline{Y},\\hat{\\beta}_1)$, we obtain\r\n\\spl{\r\n    \\hat{\\beta}_1&=B_1=\\frac{S_{xy}}{S_{xx}}\\\\\r\n    \\cov(\\overline{Y},\\hat{\\beta}_1)&=E[\\overline{Y}\\hat{\\beta}_1]-E[\\overline{Y}]E[B_1]\\\\\r\n    &=E\\bigg[\\frac{\\sum_{i=1}^n(x_i-\\bar{x})Y_i\\overline{Y}}{\\sum_{i=1}^n(x_i-\\bar{x})^2}\\bigg]-(\\beta_0+\\beta_1\\bar{x})\\beta_1\\\\\r\n    &=\\frac{\\sum_{i=1}^n(x_i-\\bar{x})E[Y_i\\overline{Y}]}{\\sum_{i=1}^n(x_i-\\bar{x})^2}-(\\beta_0+\\beta_1\\bar{x})\\beta_1\\\\\r\n    &=\\frac{\\sum_{i=1}^n(x_i-\\bar{x})(\\beta_0+\\beta_1 x_i)(\\beta_0+\\beta_1\\bar{x})}{\\sum_{i=1}^n(x_i-\\bar{x})^2}-(\\beta_0+\\beta_1\\bar{x})\\beta_1\\\\\r\n    &=0\r\n}\r\n\r\nConsider $\\cov(\\hat{\\beta_0},\\hat{\\beta_1})$, we obtain\r\n\\spl{\r\n    \\cov(\\hat{\\beta_0},\\hat{\\beta_1})&=E[B_0B_1]-E[B_0]E[B_1]\\\\\r\n    &=E[(\\overline{Y}-B_1\\bar{x})B_1]-\\beta_0\\beta_1\\\\\r\n    &=E[B_1\\overline{Y}-B_1^2\\bar{x}]-\\beta_0\\beta_1\\\\\r\n    &=E[B_1\\overline{Y}]-E[B_1^2\\bar{x}]-\\beta_0\\beta_1\\\\\r\n    &=(\\beta_0+\\beta_1\\bar{x})\\beta_1-\\bar{x}E[B_1^2]-\\beta_0\\beta_1\\\\\r\n    &=\\bar{x}(\\beta_1^2-E[B_1^2])\\\\\r\n    &=-\\bar{x}(E\\bigg[(\\frac{S_{xy}}{S_{xx}})^2\\bigg]-E\\bigg[\\frac{S_{xy}}{S_{xx}}\\bigg]^2)\\\\\r\n    &=-\\bar{x}\\var(B_1)\\\\\r\n    &=-\\bar{x}\\frac{\\sigma^2}{S_{xx}}\\\\\r\n    &=-\\frac{\\bar{x}}{S_{xx}}\\sigma^2.\r\n}\r\n\r\n\\section*{Exercise 7.6}\r\n\\enum{\r\n\\item\r\n\\spl{\r\n    B_1&=\\frac{S_{xy}}{S_{xx}}=184.6\\\\\r\n    B_0&=\\overline{Y}-B_1\\bar{x}=-2150\r\n}\r\n\\item\r\n\\spl{\r\n    S^2=\\hat{\\sigma}^2=\\frac{S_{yy}-B_1S_{xy}}{n-2}=1.15\\e{5}.\r\n}\r\n\\item\r\nFor a 100(1-0.1)\\% confidence interval,\r\n\\spl{\r\n    B_1\\pm t_{0.1/2,n-2}\\frac{S}{\\sqrt{S_{xx}}}&=184.6\\pm1.68\\cdot\\frac{339.2185}{\\sqrt{828.2412}}=184.6\\pm19.8.\\\\\r\n    B_0\\pm t_{0.1/2,n-2}\\frac{S\\sqrt{\\sum x_i^2}}{\\sqrt{nS_{xx}}}&=-2150\\pm1.68\\cdot\\frac{339.2185\\cdot182.8296}{\\sqrt{42\\cdot828.2412}}=-2150\\pm560.\\\\\r\n}\r\n\\item\r\n\\spl{\r\n    &H_0:\\ \\text{the linear regression is appropriate}\\\\\r\n    &H_1:\\ \\text{the linear regression is not appropriate}\r\n}\r\n\\spl{\r\n    SSE_{pe}&=\\sum_{i=1}^k\\sum_{j=1}^{n_i}(Y_{ij}-\\overline{Y}_i)^2=109500.\\\\\r\n    SSE_{lf}&=SSE-SSE_{pe}=4.49\\e{6}.\r\n}\r\nHence,\r\n\\spl{\r\n    F_{37-2,42-37}=\\frac{4.49\\e{6}/(37-2)}{109500/(42-37)}=5.8621\r\n}\r\n\r\nSince $f_{0.05,35,5}=4.4775<F_{35,5}$, then we claim that the linear regression model is not appropriate at 5\\% level of significance.\r\n\r\n\\item\r\n\\spl{\r\n    R^2=\\frac{S_{yy}-SSE}{S_{yy}}=0.8597.\r\n}\r\nThe coefficient of determination is the proportion in $S_{yy}$ that is determined by $X$. The larger $R^2$ is, the more $Y$ are determined by $X$.\r\n\r\n\\item\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=9cm]{images/1}\r\n    \\caption{Residuals vs. Density}\r\n\\end{figure}\r\nThe assumption of constant variance is unreliable because the is irregular.\r\n}\r\n\r\n\\section*{Exercise 7.7}\r\n\\enum{\r\n\\item\r\n\\begin{figure}[H]\r\n    \\centering\r\n    \\includegraphics[height=9cm]{images/2}\r\n    \\caption{Linear regression model}\r\n\\end{figure}\r\n\r\n\\item\r\n\\spl{\r\n    R^2=\\frac{S_{yy}-SSE}{S_{yy}}=0.9998.\r\n}\r\nHence,\r\n\\spl{\r\n    \\frac{R\\sqrt{n-2}}{\\sqrt{1-R^2}}=191.994>t_{0.025,12}=2.18.\r\n}\r\nIt implies that our linear regression model is appropriate.\r\n\r\n\\item\r\n\\spl{\r\n    &H_0:\\ \\text{the linear regression is appropriate}\\\\\r\n    &H_1:\\ \\text{the linear regression is not appropriate}\r\n}\r\n\\spl{\r\n    SSE_{pe}&=\\sum_{i=1}^k\\sum_{j=1}^{n_i}(L_{ij}-\\overline{L}_i)^2=0.0322.\\\\\r\n    SSE_{lf}&=SSE-SSE_{pe}=0.0398547-0.0322=0.00765.\r\n}\r\nHence,\r\n\\spl{\r\n    F_{8-2,14-8}=\\frac{0.00765/(8-2)}{0.0322/(14-8)}=0.2376.\r\n}\r\n\r\nSince $f_{0.05,6,6}=4.2839>F_{6,6}$, then we claim that the linear regression model is appropriate at 5\\% level of significance.\r\n}\r\n\r\n\\section*{Exercise 7.8}\r\n\\spl{\r\n    \\textbf{LHS}-\\textbf{RHS}&=\\frac{S_{xy}}{S\\sqrt{S_{xx}}}-\\frac{\\sqrt{n-2}S_{xy}/\\sqrt{S_{xx}S_{yy}}}{\\sqrt{1-S_{xy}^2/S_{xx}S_{yy}}}\\\\\r\n    &=\\frac{S_{xy}}{S\\sqrt{S_{xx}}}-\\frac{\\sqrt{n-2}S_{xy}}{\\sqrt{S_{xx}S_{yy}-S_{xy}^2}}\\\\\r\n    &=\\frac{S_{xy}}{\\sqrt{(S_{xx}S_{yy}-S_{xy}^2)/(n-2)}}-\\frac{\\sqrt{n-2}S_{xy}}{\\sqrt{S_{xx}S_{yy}-S_{xy}^2}}\\\\\r\n    &=\\frac{\\sqrt{n-2}S_{xy}}{\\sqrt{S_{xx}S_{yy}-S_{xy}^2}}-\\frac{\\sqrt{n-2}S_{xy}}{\\sqrt{S_{xx}S_{yy}-S_{xy}^2}}\\\\\r\n    &=0.\\\\\r\n}", "meta": {"hexsha": "b5ac9b814c014b922918d0db31085a700f99350e", "size": 8072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VE401ProbStat/Assignments/Assignment7/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/Assignment7/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/Assignment7/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": 37.7196261682, "max_line_length": 294, "alphanum_fraction": 0.5895688801, "num_tokens": 3543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6052178457496213}}
{"text": "\\section*{Appendix: Curve fitting}\nIn order to plot the evolution of both Lift and Drag for each phase, the computated velocity - solved from each respective ODE system - has been fitted from the resultant set of data points into a curve.\\\\\nFor this, the native \\texttt{polyfit} and \\texttt{poly2sym} \\textsc{matlab} functions have ben employed. \n\nTo correctly fit a set of points into a curve and avoid overfitting the polynomial (thus dealing with excessive oscillations and Runge's phenomemenon among others), the lienar Least Squares Method (LLS) has been used. The following plots show the square root sum and the norm of the squared regression value for each phase's velocity fit.\n\n\\begin{center}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/1/1reg.jpg}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/1/1fit.jpg}\n\t\\vspace{0.5cm}\n\t\\captionof{figure}{Lift and drag on the cruise phase. Own elaboration.}\n\t\\label{fig:1reg}\n\t\\captionof{figure}{Lift and drag on the cruise phase. Own elaboration.}\\vspace{0.25cm}\n\t\\label{fig:1fit}\n\\end{center}\n\n\\begin{center}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/2reg.jpg}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/2fit.jpg}\n\t\\vspace{0.5cm}\n\t\\captionof{figure}{Lift and drag on the half loop. Own elaboration.}\n\t\\label{fig:2reg}\n\t\\captionof{figure}{Lift and drag on the half loop. Own elaboration.}\\vspace{0.25cm}\n\t\\label{fig:2fit}\n\\end{center}\n\n\\begin{center}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/3reg.jpg}\n\t\\includegraphics[width=0.45\\linewidth]{../matlab/3fit.jpg}\n\t\\vspace{0.5cm}\n\t\\captionof{figure}{Lift and drag on the half loop. Own elaboration.}\n\t\\label{fig:3reg}\n\t\\captionof{figure}{Lift and drag on the half loop. Own elaboration.}\\vspace{0.25cm}\n\t\\label{fig:3fit}\n\\end{center}", "meta": {"hexsha": "81c1f2c59764bf2ea68725ee0d9a1c72f17acc4f", "size": 1764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/appendix-curve-fitting.tex", "max_stars_repo_name": "isimo00/immelmann-turn", "max_stars_repo_head_hexsha": "1b3f9b02e575a8e523cdf6c30d2d62c2dbfb1fce", "max_stars_repo_licenses": ["MIT"], "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/appendix-curve-fitting.tex", "max_issues_repo_name": "isimo00/immelmann-turn", "max_issues_repo_head_hexsha": "1b3f9b02e575a8e523cdf6c30d2d62c2dbfb1fce", "max_issues_repo_licenses": ["MIT"], "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/appendix-curve-fitting.tex", "max_forks_repo_name": "isimo00/immelmann-turn", "max_forks_repo_head_hexsha": "1b3f9b02e575a8e523cdf6c30d2d62c2dbfb1fce", "max_forks_repo_licenses": ["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.4, "max_line_length": 338, "alphanum_fraction": 0.7579365079, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6052178457496213}}
{"text": "Implements the SMT compliant \\emph{Simplex} method presented in \\cite{DM06}.\nHence, this module can decide the consistency of any conjunction\nconsisting only of linear real arithmetic constraints. Furthermore,\nit might also find the consistency of a conjunction of constraints\neven if they are not all linear and calls a backend after removing\nsome redundant linear constraints, if the linear constraints are satisfiable\nand the found solution does not satisfy the non-linear constraints. Note that the \n\\lraModuleClass might need to communicate a lemma/tautology to a preceding \n\\satModuleClass, if it receives a constraint with the relation symbol $\\neq$\n and the strategy needs for this reason to define a \\satModuleClass at any \n position before an \\lraModuleClass.\n\n\\paragraph{Integer arithmetic} In order to find integer solutions, this\nmodule applies, depending on which settings are used, branch-and-bound,\nthe construction of Gomory cuts and the generation of cuts from \nproofs~\\cite{DilligDA11}. It is also supported to combine these approaches. Note that\nfor all of them the \\lraModuleClass needs to communicate a lemma/tautology to a\npreceding \\satModuleClass and the strategy needs for this reason to define a \n\\satModuleClass at any position before an \\lraModuleClass.\n\n\\paragraph{Efficiency} The worst case complexity of the implemented\napproach is exponential in the number of variables occurring in the\nproblem to solve. However, in practice, it performs much faster, and\nthe worst case applies only on very artificial examples. This module\noutperforms any module implementing a method that is designed for \nsolving formulas with non-linear constraints. If the received formula\ncontains integer valued variables, the aforementioned methods might not\nterminate.", "meta": {"hexsha": "5ce20ab9250fc9426ea9d15b0b08e4dca366b9ad", "size": 1777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/smtrat-modules/LRAModule/LRAModule.tex", "max_stars_repo_name": "minemebarsha/smtrat", "max_stars_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_stars_repo_licenses": ["MIT"], "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/smtrat-modules/LRAModule/LRAModule.tex", "max_issues_repo_name": "minemebarsha/smtrat", "max_issues_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_issues_repo_licenses": ["MIT"], "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/smtrat-modules/LRAModule/LRAModule.tex", "max_forks_repo_name": "minemebarsha/smtrat", "max_forks_repo_head_hexsha": "eaada50cdf9bbfe4dd4f6a54776387484c37b0f2", "max_forks_repo_licenses": ["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.4642857143, "max_line_length": 85, "alphanum_fraction": 0.8204839617, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6052075242594138}}
{"text": "%!TEX root = ../main.tex\n\n\\chapter{Notation}\n\\label{appendix:notation}\n\\vspace{-7mm}\n\nThis appendix contains a summary of the notation used in this book.\n\n\n\\softsection{Math notation}\n\n{ \\small\n\\noindent\n\\begin{tabularx}{\\textwidth}{@{}rlp{5.9cm}@{}} \n\\toprule\nExpression  \t&\tRead as  \t& Used to denote\t\t\t\\\\\n\\midrule\n$a,b,x,y$\t\n\t& \n\t& variables \\\\\n$=$\t\n\t& is equal to \n\t& expressions that have the same value \\\\ % have the same value\t\\\\\n$\\eqdef$\n\t& is defined as \n\t& a new variable definition  \\\\\n$a+b$\n\t& $a$ plus $b$\n\t& the combined lengths of $a$ and $b$ \\\\\n$a-b$\t\n\t& $a$ minus $b$\n\t& the difference in lengths between $a$ and $b$ \\\\\n$a\\times b = ab$\n\t& $a$ times $b$\n\t& the area of a rectangle   \\\\\n$a^2= aa$\n\t& $a$ squared \n\t& the area of a square of side length $a$ \\\\\n$a^3= aaa$\n\t& $a$ cubed \n\t& the volume of a cube of side length $a$ \\\\\n$a^n$\n\t& $a$ to the $n$\n\t%raised to the $n$\\textsuperscript{th} power\n\t& $a$ multiplied by itself $n$ times \t\t\\\\\n$\\sqrt{a} = a^{\\frac{1}{2}}$\n\t& square root of $a$\n\t& the side length of a square of area $a$ \\\\\n$\\sqrt[3]{a}= a^{\\frac{1}{3}}$\n\t& cube root of $a$\n\t& the side length of a cube with volume $a$  \\\\\n$a/b = \\frac{a}{b}$\n\t& $a$ divided by $b$\n\t& $a$ parts of a whole split into $b$ parts \\\\[0.8mm]\n$a^{-1}= \\frac{1}{a}$\n\t& one over $a$\n\t& division by $a$ \t\t\t\t\t\\\\[2mm]\n$f(x)$\t\n\t& $f$ of $x$\n\t& the function $f$ applied to input $x$ \t\\\\\n$f^{-1}$ \n\t& $f$ inverse \n\t& the inverse function of $f(x)$   \\\\\n$f \\circ g$ \n\t& $f$ compose $g$ \n\t& function composition; $f \\circ g(x) = f(g(x))$   \\\\[2mm]\n$e^x$ \n\t& $e$ to the $x$ \n\t& the exponential function base $e$ \\\\\n$\\ln(x)$ \n\t& natural log of $x$ \n\t& the logarithm base $e$ \t\t\t\t\\\\\n$a^x$ \n\t& $a$ to the $x$ \n\t& the exponential function base $a$ \\\\\n$\\log_a(x)$ \n\t& log base $a$ of $x$ \n\t& the logarithm base $a$ \t\t\t\t\\\\[2mm]\n$\\theta,\\phi$\n\t& \\emph{theta}, \\emph{phi}\n\t& angles \t\t\t\t\t\\\\\n$\\sin,\\cos,\\tan$\n\t& sin, cos, tan \n\t& trigonometric ratios \t\t\t\\\\\n%\\; \\\\\n$\\%$\n\t& percent\n\t& proportions of a total; $a\\%=\\frac{a}{100}$ \t\t\\\\\n\\bottomrule\n\\end{tabularx}\n}%\n", "meta": {"hexsha": "22dc680f8b26ee7f30ad4e8a266a91ec3d4c37b6", "size": 2051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sources/extracted/99_03_notation.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/extracted/99_03_notation.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/extracted/99_03_notation.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": 22.2934782609, "max_line_length": 67, "alphanum_fraction": 0.5636274988, "num_tokens": 799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.60505173641456}}
{"text": "%begin-include\n\n\\section{Propositional logic. General definitions}\n\n\\begin{para}[A note on circularity]\nFrom now on, we will be working with propositional logic and predicate logic as object theories.\nThis unavoidably leads one to wonder what kind of reasoning they should be able to use in their metatheory.\nI mean, it does not seem legit to use propositional logic in order to study propositional logic, right?\n\nTurns out we can safely do it.\nWhat we will be studying is not propositional logic itself, but a formalisation of propositional logic.\nIt should be out of question to any rational being that propositional logic is perfectly valid (and, thus, that there is no harm in using it).\nWhat will not be obvious, however, is that the formalisation of propositional logic that we are about to present is correct and faithfully represents it.\n\\end{para}\n\n\\begin{definition}\nThe formal system $\\mathsf{P}$ of propositional logic is defined by the tuple $(L_P,\\Xi_P,R_P)$ where $L_P$ is the language defined in \\ref{lp}, the set of axioms $\\Xi_P$ consists of all the formulas of the form\n\\begin{axioms}[P]\n\\item \\label{axp1} $A\\limplies (B \\limplies A)$,\n\\item \\label{axp2} $(A\\limplies(B\\limplies C))\\limplies ((A\\limplies B)\\limplies (A\\limplies C))$,\n\\item \\label{axp3} $(\\lnot A \\limplies \\lnot B) \\limplies (B\\limplies A)$,\n\\end{axioms}\nfor $A,B,C\\in F_P$, and $R_P$ has a single rule of inference:\n\\[ \\{A,(A\\limplies B)\\} \\vdash_{\\mathsf{P}} B\\]\nfor all $A,B\\in F_P$. This rule is known as \\emph{modus ponens}, MP for short.\n\\end{definition}\n\n\\begin{para}\nAs you may have already noticed, axioms such as \\ref{axp1}, \\ref{axp2} and \\ref{axp3} are not axioms per se. Instead, they are ``rules'' for constructing the axioms; that is why they are called \\emph{axiom schemata} instead of axioms. The axioms that are constructed using a particular axiom schema are said to be \\emph{instances} of the schema. For example, the axiom $(p_1\\limplies p_2)\\limplies p_1$ is an instance of the axiom schema \\ref{axp1}.\n\\end{para}\n\n\\begin{definition}\nAn interpretation of $L_P$ based on the semantics of propositional logic is a function $i : T_P \\longrightarrow \\{0,1\\}$. Each interpretation $i$ induces a \\emph{valuation} function $v_i: F_P \\longrightarrow \\{0,1\\}$  verifying the following semantic rules:\n\\begin{enumerate}\n\\item The function $v_i$ takes the same values as $i$ on the set of propositional variables $T_P \\subseteq F_P$.\n\\item If $A\\in F_P$, then $v_i(A) \\neq v_i(\\lnot A)$.\n\\item If $A,B\\in F_P$, then $v_i(A\\limplies B) = 0$ if and only if $v_i(A) = 1$ and $v_i(B) = 0$.\n\\end{enumerate}\nGiven any propositional form $A$, we say that $A$ is true in $i$ if $v_i(A) = 1$. If, instead, $v_i(A) = 0$, we say that $A$ is false.\n\nValid propositional forms --- that is, valid formulas in the context of propositional logic --- are referred to as \\emph{tautologies}.\nPropositional forms that are false under any interpretation of propositional logic are said to be \\emph{contradictions}.\n\\end{definition}\n\n\\begin{para}\nIt should be obvious that an interpretation is nothing more than an assignment of truth values. The interpretation function $i$ defined for the propositional symbols represents the assignment and then the ``truth value'' of the remaining formulas, given by their image under $v_i$, is obtained inductively by applying the semantic rules that define the connectives $\\lnot$ and $\\limplies$.\n\nIt should be obvious, according to the semantic rules that we have used, that getting the value of $v_i(A)$ for a propositional form $A$ and an interpretation $i$ is the same as getting the truth value of $A$ under the assignment of truth values induced by $i$. Thus, all the informal methods that can used to decide the truth or falsity of a propositional forms can be safely used to compute valuations.\n\nNotice, by the way, how we have redefined tautologies. The underlying meaning, however, is the same.\n\\end{para}\n\n\\begin{definition}\nLet $L = (\\Sigma,T,F, \\Lambda)$ be a language and $\\mathsf{FS} = (L,\\Xi,R)$ be a formal system containing all instances of axiom schemata \\ref{axp1}, \\ref{axp2} and \\ref{axp3} among its axioms.\n\\begin{itemize}\n\\item If there exists no formula $A \\in F$ such that $\\vdash_\\mathsf{FS} A $ and $\\vdash_\\mathsf{FS} \\lnot A$, the system $\\mathsf{FS}$ is said to be \\emph{consistent}.\n\\item If, for every sentence $A\\in \\Lambda$, we have $\\vdash_\\mathsf{FS} A$ or $\\vdash \\lnot A$, we say that $\\mathsf{FS}$ is \\emph{syntactically complete} or, for short, \\emph{complete}.\n\\item The system $\\mathsf{FS}$ is said to be \\emph{semantically complete} if every valid formula is a theorem in $\\mathsf{FS}$. Conversely, if every theorem is a valid formula, $\\mathsf{FS}$ is said to be \\emph{sound}.\n\\end{itemize}\nLet $A$ be an axiom and let $\\mathsf{FS}^*$ be the formal system obtained by removing the axiom $A$ from $\\mathsf{FS}$. If neither $A$ nor $\\lnot A$ are theorems of $\\mathsf{FS}^*$, $A$ is said to be an \\emph{independent axiom}. Ideally, we want all axioms to be independent in order to avoid redundancy.\n\\end{definition}\n\n\n\\begin{example} \\label{dedaa}\nWe will prove that $\\vdash A \\limplies A$ for any formula $A$. We will write down all the steps of the deduction together with their justification.\n\n\\begin{deduction}{dtp}\n\\dstep[a1]{\\ref{axp1}}{A\\limplies([A\\limplies A]\\limplies A),}\n\\dstep[a2]{\\ref{axp2}}{(A\\limplies([A\\limplies A]\\limplies A))\\limplies( (A\\limplies[A\\limplies A])\\limplies(A\\limplies A)),}\n\\dstep[a3]{MP on \\dref{a1}, \\dref{a2}}{( (A\\limplies[A\\limplies A])\\limplies(A\\limplies A)),}\n\\dstep[a4]{\\ref{axp1}}{A\\limplies(A\\limplies A),}\n\\dstep{MP on \\dref{a4}, \\dref{a3}}{A\\limplies A.}\n\\end{deduction}\n\\end{example}\n\n\n\\begin{theorem}[Deduction theorem in $\\mathsf{P}$]\n\\label{dedthmprop}\nFor any collection of propositional forms $\\Gamma\\subseteq F_P$ and any formulas $A,B\\in F_P$, one can deduce $\\Gamma\\cup\\{A\\}\\vdash_{\\mathsf{P}} B$ if and only if $\\Gamma \\vdash_\\mathsf{P} (A\\limplies B)$. \n\\label{}\n\\end{theorem}\n\n\\begin{proof}\n\nWe will first show that $\\Gamma \\cup \\{A\\} \\vdash B$ implies $\\Gamma \\vdash (A\\limplies B)$ following a proof by induction on the length $n$ of the deduction of $\\Gamma\\cup\\{A\\}\\vdash B$.\nIf $n = 1$, there are only three possibilities: either $B = A$, $B\\in \\Gamma$, or $B\\in \\Xi_P$. \n\nAccording to \\ref{dedaa}, any formula $A$ verifies $\\vdash (A\\limplies A)$, so, in particular, $\\Gamma \\vdash (A\\limplies A)$.\nThus, if $B = A$, it is obvious that $\\Gamma\\cup\\{A\\}\\vdash A$ implies $\\Gamma \\vdash (A\\limplies A)$. \n\nIf $B\\in \\Gamma$ or $B\\in \\Xi_P$, $\\Gamma \\vdash (A\\limplies B)$ follows from a trivial application of MP to $B$ and \\ref{axp1}.\\footnote{Be aware that, when applying \\ref{axp1}, ``$A$'' in \\ref{axp1} should be substituted by ``$B$'' and ``$B$'' by ``$A$.''}\n\nLet us now assume the result to hold for deductions of an arbitrary length $n$ and prove it for those of length $n+1$.\nIf the deduction is of length $n+1$, the formula $B$ may be, as in the base case, an axiom, equal to $A$, or an element of $\\Gamma$.\nBut it may also have been obtained from an application of MP on two previous elements of the deduction.\nIn this case, those elements have deductions of length smaller than $n+1$ and, therefore, they satisfy the result by the inductive hypothesis. Let us then assume that $B$ has been obtained from an application of MP to two formulas of the form $X$ and $X\\limplies B$ verifying $\\Gamma \\vdash (A\\limplies X)$ and $\\Gamma \\vdash (A\\limplies(X \\limplies B))$. Under these conditions, we can make the following deduction from $\\Gamma$.\n\n\\begin{deduction}{thdedprop1}\n\\dstep[h1]{By hypothesis, can be deduced from $\\Gamma$}{A\\limplies X,}\n\\dstep[h2]{By hypothesis, can be deduced from $\\Gamma$}{A\\limplies (X\\limplies B),}\n\\dstep[a1]{\\ref{axp1}}{(A \\limplies (X\\limplies B))\\limplies ( (A\\limplies X) \\limplies (A\\limplies B) ),}\n\\dstep[c1]{MP on \\dref{h2}, \\dref{a1}}{(A\\limplies X)\\limplies (A\\limplies B),}\n\\dstep[c2]{MP on \\dref{h1}, \\dref{c1}}{A\\limplies B.}\n\\end{deduction}\n\nWe shall now prove the converse: assuming that $\\Gamma \\vdash (A\\limplies B)$, we will show that $\\Gamma\\cup \\{A\\} \\vdash B$.\nThis is easy. Keeping in mind that $\\Gamma \\vdash (A\\limplies B)$ and, therefore, that $\\Gamma\\cup\\{A\\}\\vdash (A\\limplies B)$, we can write an explicit deduction of $\\Gamma\\cup\\{A\\}\\vdash B$:\n\\begin{deduction}{thdedprop2}\n\\dstep[h1]{By hypothesis, can be deduced from $\\Gamma\\cup\\{A\\}$}{A\\limplies B,}\n\\dstep[h2]{Belongs to $\\Gamma\\cup\\{A\\}$}{A,}\n\\dstep{MP on \\dref{h2}, \\dref{h1}}{B.}\n\\end{deduction}\nThis concludes the proof.\n\\end{proof}\n\n\\begin{para}\n\\label{remarkdedp}\nThe deduction theorem is, perhaps, one of the most significant results in this section, for it explains the confusion that the implication connective $\\limplies$ generates.\n\nThe formula $A\\limplies B$ is a formula in the object language, full stop.\nWhat we have shown is that the meta-theoretic statement $\\vdash (A\\limplies B)$ meaning ``$(A\\limplies B)$ is a theorem in $\\mathsf{P}$'' is equivalent to the meta-theoretic statement $A\\vdash B$ meaning ``$B$ can be deduced from $A$''.\n\nWe will later introduce the first-order version of this metatheorem, which will shed even more light on this matter.\n\\end{para}\n\n\\begin{theorem}\n\\label{pprop}\nThe following metatheorems about propositional logic are true:\n\\begin{statements}\n\\item \\label{pprop:sound} If $\\Gamma \\subseteq F_P$ and $X\\in F_P$ are such that $\\Gamma \\vdash X$, then $\\Gamma\\vDash X$. In particular, if a formula $X\\in F$ is a theorem in $\\mathsf{P}$, it is a tautology; which is to say that $\\mathsf{P}$ is sound.\n\\item The formal system $\\mathsf{P}$ is consistent.\n\\item Every tautology is a theorem in $\\mathsf{P}$. In other words, $\\mathsf{P}$ is semantically complete.\n\\end{statements}\nThese results show beyond any doubt that $\\mathsf{P}$ is a correct formalisation of propositional logic.\n\\end{theorem}\n\n\\begin{proof}\n\\begin{parlist}\n\\item We proceed by induction on the length $n$ of the deduction.\nIf $n = 1$, then either $X \\in \\Gamma$ (in which case the result is obvious) or $X$ is an axiom of $\\mathsf{P}$.\nIn order for the result to hold, we need to see that every axiom of $\\mathsf{P}$ is true under any interpretation, i.e., that it is a tautology.\n\nWe shall first analyse \\ref{axp1}.\nI think we can both agree that, given any $A,B\\in F$, the formula $A\\limplies (B\\limplies A)$ either is or is not a tautology.\nThus, we just need to show that it is impossible for $A\\limplies (B\\limplies A)$ not to be a tautology.\nWere that formula not a tautology, there would necessarily exist an interpretation $i$ under which it would be false.\nNonetheless, according to the semantic rules of propositional logic, that would mean that $v_i(A) = 1$ yet $v_i(B\\limplies A) = 0$.\nBut, by those same rules, $v_i(B\\limplies A) = 0$ can only mean that $v_i(B) = 1$ and $v_i(A) = 0$.\\\nConsequently, $A\\limplies (B\\limplies A)$ can only be false under an interpretation $i$ verifying both $v_i(A) = 0$ and $v_i(A) = 1$.\nAs that is impossible, we can safely conclude that all the axioms defined by the schema \\ref{axp1} are tautologies.\n\nWe can proceed in a similar fashion regarding \\ref{axp2}.\nLet $A,B,C\\in F_P$ be formulas.\nIf an interpretation $i$ is such that\n\\[ v_i( \\underbrace{(A\\limplies(B\\limplies C))}_{D_1} \\limplies \\overbrace{((A\\limplies B) \\limplies (A\\limplies C))}^{D_2}) = 0,\\]\nthen we necessarily have $v_i(D_1) = 1$ and $v_i(D_2) = 0$.\nHaving $v_i(D_2) = 0$ implies that $v_i(A\\limplies C) = 0$ and $v_i(A\\limplies B) = 1$, which can only mean that $v_i(A) = 1$, that $v_i(C) = 0$ and that $v_i(B) = 1$.\nSimultaneously, $v_i(D_1) = 1$ with $v_i(A) = 1$ leads to $v_i(B\\limplies C) = 1$, which --- with $v_i(C) = 0$ --- could only be the case if $v_i(B) = 0$.\nHaving reached a contradiction, we can conclude that all the axioms defined by \\ref{axp2} need be true under any interpretation and, therefore, that they are all tautologies.\n\nFinally, let us tackle \\ref{axp3}. Given any two formulas $A,B\\in F_P$, if we assume an interpretation $i$ to exist such that\n\\[ v_i\\left( (\\lnot A \\limplies \\lnot B) \\limplies (B \\limplies A) \\right) = 0,\\]\nit will need to verify $v_i(B \\limplies A) = 0$ and $v_i(\\lnot A\\limplies \\lnot B) = 1$.\nThe former of these conditions implies that $v_i(A) = 0$ and $v_i(B) = 1$, which --- according to the semantic rules --- is equivalent to having $v_i(\\lnot A) = 1$ and $v_i(\\lnot B) = 0$. If $v_i(\\lnot A\\limplies \\lnot B) = 1$ and, as we have just shown, $v_i(\\lnot A) = 1$, then we necessarily have $v_i(\\lnot B) = 1$, which is, as expected, a contradiction.\nThis proves that all the axioms defined by \\ref{axp3} are tautologies.\n\nNow that we have completed the base case, let us assume the result to hold for deductions of length equal to or smaller than $n$, and we will prove it for those of length $n+1$.\nIf the deduction has length $n+1$, $X$ may be an element of $\\Gamma$ or an axiom as in the base case, or it may have been obtained from an application of MP on two previous elements of the deduction that, therefore, verify the result according to the inductive hypothesis.\nThus, we need to show that, given any two formulas of the form $A$ and $A\\limplies B$, if they are true in any particular interpretation $i$, so is $B$.\n\nIf $v_i(A) = 1$ and $v_i(A\\limplies B) = 1$, it is obvious that we need to have $v_i(B) = 0$. Indeed, if $v_i(B) = 0$ and $v_i(A) = 1$, that would yield $v_i(A\\limplies B) = 0$.\nThus, we have shown that, for any interpretation $i$ in which any two formulas $A$ and $A\\limplies B$ are true, $B$ is true too.\n\n\\item Let $A$ be a theorem in $\\mathsf{P}$.\nBy \\ref{pprop:sound}, $A$ need be a tautology and, therefore, for an interpretation $i$, we will have $v_i(A) = 1$.\nAccording to the semantic rules, this means that, under any interpretation $i$, $v_i(\\lnot A) = 0$.\nConsequently, $\\lnot A$ is not a tautology and since, by \\ref{pprop:sound}, being a tautology is a necessary condition for any formula to be a theorem in $\\mathsf{P}$, $\\lnot A$ cannot be a theorem.\n\nThis shows that no formula $A$ can verify both $\\vdash_{\\mathsf{P}} A$ and $\\vdash_{\\mathsf{P}} \\lnot A$, and, therefore, that $\\mathsf{P}$ is consistent.\n\n\\item The details of this proof are pretty tedious to go through. If you feel motivated enough to do it, feel free to visit \\ref[appendix]{psemcom} in the appendices.\n\\end{parlist}\n\\end{proof}\n\n\\begin{lemma}[Conjunction introduction rule]\nLet $\\Gamma$ be a collection of propositional forms and let $A$ and $B$ be two arbitrary propositional forms. One can deduce $\\Gamma\\vdash_\\mathsf{P} (A\\land B)$ if and only if one can deduce both $\\Gamma \\vdash_{\\mathsf{P}}A$ and $\\Gamma \\vdash_{\\mathsf{P}}B$.\n\\label{cinr}\n\\end{lemma}\n\n\\begin{proof}\nIf $\\Gamma \\vdash (A\\land B)$, then, since $(A\\land B) \\limplies A$ and $(A\\land B)\\limplies B$ are both tautologies --- and, therefore, theorems in $\\mathsf{P}$ --- it follows by a direct application of the MP rule that $\\Gamma \\vdash A$ and $\\Gamma \\vdash B$.\n\nConversely, if $\\Gamma \\vdash A$ and $\\Gamma \\vdash B$, we know $A\\limplies (B\\limplies (A\\land B))$ to be another tautology. Two applications of MP yield $\\Gamma \\vdash (A\\land B)$.\n\\end{proof}\n\n\\begin{proposition}\n\\label{piff}\nGiven any propositional forms $A$ and $B$, $\\Gamma \\vdash_{\\mathsf{P}} (A \\liff B)$ if and only if $\\Gamma  \\vdash_\\mathsf{P} (A\\limplies B)$ and $\\Gamma \\vdash_\\mathsf{P} (B\\limplies A)$.\n\nIn particular, if $\\Gamma = \\emptyset$, $A\\liff B$ is a theorem of $\\mathsf{P}$ if and only if so are $A\\limplies B$ and $B\\limplies A$.\n\\end{proposition}\n\n\\begin{proof}\nIf we have both $\\Gamma\\vdash (A\\limplies B)$ and $\\Gamma \\vdash (B\\limplies A)$, by \\ref{cinr}, we know that $\\Gamma \\vdash ( (A\\limplies B) \\land (B\\limplies A))$, which is, according to our definition of $\\liff$, the same as $\\Gamma \\vdash (A\\liff B)$.\nThe converse is also a direct consequence of \\ref{cinr}.\n\\end{proof}\n\n\n\\begin{lemma}\nLet $A$, $X$ and $Y$ be propositional forms. If $X\\liff Y$ is a tautology and $A'$ denotes the propositional form resulting from replacing each appearance of $X$ in $A$ by $Y$, then $A\\liff A'$ is a tautology and, therefore, a theorem in $\\mathsf{P}$.\n\\label{replacetautology}\n\\end{lemma}\n\n\\begin{proof}\nLet $i$ be any interpretation.\nIt suffices to notice that, as $X \\liff Y$ is a tautology, we always have $v_i(X) = v_i(Y)$.\nTherefore, as $A'$ is obtained by replacing every occurrence of $X$ by an occurrence of $Y$, we necessarily have $v_i(A) = v_i(A')$.\nConsequently, $v_i(A\\liff A') = 1$.\n\\end{proof}\n\n\\begin{para}\n\\label{lpinformal}\nIt is very easy to see that the following formulas are tautologies for any propositional forms $A$, $B$ and $C$:\n\\begin{statements}\n\\item $(A\\liff B) \\liff (B\\liff A)$,\n\\item $(A\\land B) \\liff (B\\land A)$,\n\\item $((A\\land B) \\land C) \\liff (A\\land (B \\land C))$,\n\\item $((A\\lor B) \\lor C) \\liff (A\\lor (B \\lor C))$,\n\\end{statements}\nThis, together with \\ref{replacetautology}, should be enough to convince you that the conventions we introduced in \\ref[prel]{hierarchy} can be safely used when working with $L_P$ in $\\mathsf{P}$.\nIn particular, this shows that there is no harm in swapping formulas around the $\\lor$, $\\land$ and $\\liff$ connectives.\n\\end{para}\n\n\n\\begin{proposition}\n\\label{impsystemp}\nLet $A$, $B$, $A_1$, $A_2$, $B_1$ and $B_2$ be propositional forms and $\\Gamma$ a set of propositional forms.\n\\begin{statements}\n\\item One can deduce $\\Gamma \\vdash_\\mathsf{P} (A \\limplies (B_1\\land B_2))$ if and only if one can deduce both $\\Gamma \\vdash_\\mathsf{P} (A\\limplies B_1)$ and $\\Gamma \\vdash_\\mathsf{P} (A\\limplies B_2)$. In particular, if $\\Gamma = \\emptyset$, $A\\limplies (B_1\\land B_2)$ is a theorem of $\\mathsf{P}$ if and only if so are $A\\limplies B_1$ and $A \\limplies B_2$.\n\n\\item One can deduce $\\Gamma \\vdash_\\mathsf{P} ( (A_1\\land A_2) \\limplies B_1 )$ if and only if one can deduce $\\Gamma \\vdash_\\mathsf{P} (A_1 \\limplies (A_2 \\limplies B))$ or $\\Gamma \\vdash_\\mathsf{P} (A_2 \\limplies (A_1 \\limplies B)$. In particular, if $\\Gamma = \\emptyset$, $(A_1\\land A_2) \\limplies B$ is a theorem if and only if so are $A_1\\limplies (A_2\\limplies B)$ or $A_2 \\limplies (A_1 \\limplies B)$.\n\\end{statements}\n\\label{implesmani}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{parlist}\n\\item Follows from a direct application of MP taking into account \\ref{piff} and the fact that \\[(A\\limplies (B_1\\land B_2)) \\liff ((A\\limplies B_1) \\land (A\\limplies B_2))\\] is a tautology.\n\\item Follows from a direct application of MP taking \\ref{piff} into account together with the fact that both\n\\begin{gather*}\n((A_1 \\land A_2)\\limplies B) \\liff (A_1 \\limplies (A_2 \\limplies B)),\\\\\n((A_1 \\land A_2)\\limplies B) \\liff (A_2 \\limplies (A_1 \\limplies B))\n\\end{gather*}\nare tautologies.\n\\end{parlist}\n\\end{proof}\n\n\\begin{proposition}[Principle of explosion]\n\\label{pexpprop}\nAnything can be deduced from a false premise: given any two propositional forms $A,B\\in F_P$, we have $A,\\lnot A \\vdash B$. \n\\end{proposition}\n\n\\begin{proof}\nIt is easy to see that the formulas $A\\limplies (A\\lor B)$ and $\\lnot A \\limplies ( (A\\lor B) \\limplies B )$ are tautologies. We know $\\mathsf{P}$ to be semantically complete and, therefore, we know those tautologies to be theorems of $\\mathsf{P}$. The deduction of $B$ from $A,\\lnot A$ is then very simple.\n\\begin{deduction}{dedpexpprop}\n\\dstep[h1]{Premise}{A,}\n\\dstep[h2]{Premise}{\\lnot A,}\n\\dstep[t1]{Theorem}{A\\limplies (A\\lor B),}\n\\dstep[t2]{Theorem}{\\lnot A \\limplies ( (A\\lor B) \\limplies B),}\n\\dstep[d1]{MP on \\dref{h1}, \\dref{t1}}{A \\lor B,}\n\\dstep[d2]{MP on \\dref{h2}, \\dref{t2}}{(A\\lor B) \\limplies B,}\n\\dstep{MP on \\dref{d1}, \\dref{d2}}{B.}\n\\end{deduction}\nThis completes the proof.\n\\end{proof}\n\n\n", "meta": {"hexsha": "543399fd585bad4b77f9340d62693f51316b4e1c", "size": 19708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch1/sec2.tex", "max_stars_repo_name": "gonzalezcastillo/leavingthecave", "max_stars_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "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": "ch1/sec2.tex", "max_issues_repo_name": "gonzalezcastillo/leavingthecave", "max_issues_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "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": "ch1/sec2.tex", "max_forks_repo_name": "gonzalezcastillo/leavingthecave", "max_forks_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "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": 70.8920863309, "max_line_length": 449, "alphanum_fraction": 0.7110817942, "num_tokens": 6441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6050517254197887}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsfonts}\n\\usepackage{amsmath} \n\\usepackage{hyperref}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{tikz}\n\\usepackage{geometry}\n\\usepackage{mathtools}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{proposition}[theorem]{Proposition}\n\\newtheorem{corollary}[theorem]{Corollary}\n\n\n\\title{Sample LaTex Document}\n\\author{Tom Grubb}\n\\date{January 2021}\n\n\n\\begin{document}\n\n\\maketitle\n\n\\abstract{Abstract abstract abstract abstract abstract wow what a useful informative abstract.}\n\n\\section{Introduction}\nThis is a very basic LaTex document. It was created for UCSD's Math 157 class to highlight some of LaTex's functionality. The .tex file starts with a \\emph{preamble}, which includes details on the title of this document, as well as several import statements. The result of compiling that .tex file is this pdf. This document was created online using Overleaf.\n\n\\section{A Theorem, a Proof, and the Align Environment}\nIn this section we will prove a basic fact about \\textbf{natural numbers}. Look at how the phrase natural numbers is \\emph{bolded} and how the word bolded is italicized; you can see how this was done in the source file.\n\n\\begin{theorem}\nFor an integer $n,$ $n\\geq 1$, we have \n$$\n\\sum_{k = 1}^{n} k = \\frac{n(n+1)}{2}\n$$\n\\end{theorem}\n\n\\begin{proof}\nWe induct on $n$. In the base case, $n=1$. In this case the sum on the left hand side has a single term equal to $1$ in it. The right hand side simplifies to \n$$\n\\frac{1\\cdot 2}{2} = 1.\n$$\nThus the base case holds. \n\nFor the induction step, assume the theorem holds for some integer $n$. Then \n$$\n\\sum_{k=1}^{n+1} = (n+1) + \\sum_{k=1}^nk.\n$$\nBy the induction hypothesis, \n$$\n\\sum_{k=1}^{n}k = \\frac{n(n+1)}{2},\n$$\nand thus \n$$\n\\sum_{k=1}^{n+1} = (n+1)+ \\frac{n(n+1)}{2}.\n$$\nSimplifying the right hand side gives \n\\begin{align*}\n\\sum_{k=1}^{n+1} &= \\frac{2(n+1)+n(n+1)}{2} \\\\\n&=\\frac{(n+1)(n+2)}{2}.\n\\end{align*}\nThis finishes the proof of our theorem.\n\\end{proof}\n\nIn the next section we will explore other LaTex environments.\n\n\\section{LaTex Lists}\nIn LaTex you can make bulleted and numbered lists. A bulleted list uses the itemize environment:\n\\begin{itemize}\n    \\item This is the first entry in a bulleted list.\n    \\item This is the second entry in a bulleted list.\n\\end{itemize}\nA numbered list uses the enumerate environment:\n\\begin{enumerate}\n    \\item This is the first entry in a numbered list.\n    \\item This is the second entry in a numbered list. It has a sublist in it!\n    \\begin{enumerate}\n        \\item This is a sublist within my numbered list! It uses a nested enumerate environment.\n        \\item Wow!\n    \\end{enumerate}\n\\end{enumerate}\n\n\\section{LaTex Tables}\nThere are two ways of making tables in LaTex. The tabular environment is for making \\emph{text based tables}. Often you highlight a tabular environment using the \\emph{center} environment:\n\\begin{center}\n    \\begin{tabular}{c|c}\n    The columns are separated by ampersands & This is column 2 \\\\\n    The rows are separated by two backslashes.  & This is row 2, column 2\n\\end{tabular}\n\\end{center}\nYou can add horizontal lines to the table using the hline command. Vertical lines are formed by adding pipes into the table metadata: \\{ $\\vert$ c $\\vert$ c $\\vert$\\} means you have two columns which are \\emph{centrally aligned} and have vertical lines in between each column: \n\\begin{center}\n    \\begin{tabular}{|c|c|}\n    \\hline\n    The columns are separated by ampersands & This is column 2 \\\\\n    \\hline\n    The rows are separated by two backslashes.  & This is row 2, column 2\\\\\n    \\hline\n\\end{tabular}\n\\end{center}\nYou could optionally change the alignment using l, c, or r in the table metadata:\n\\begin{center}\n    \\begin{tabular}{|l|c|r|}\n    \\hline\n    Col 1& Col 2& Col3\\\\\n    \\hline\n    Left aligned & Centrally aligned & Right aligned \\\\\n    \\hline\n    \n\\end{tabular}\n\\end{center}\n\nAn array environment is similar to a tabular environment, but it is for math mode/numeric data. In particular, it should go between double dollar signs, or in an equation environment:\n\\begin{equation}\n    \\begin{array}{|c|c|}\n    \\hline\n        \\pi & \\tau \\\\\n        \\hline\n         3.14\\dots&6.28\\dots \\\\\n         \\hline\n    \\end{array}\n\\end{equation}\nNote that the equation environment implicitly numbers the equations. You can change this by messing around with the settings if you wanted. \n\n\\section{Tikz}\nIf you want to get fancy with your files, you can use Tikz to create images/plots within your file. This is more advanced and will not be necessary for this class, but here are some examples that I have taken from Overleaf's documentation (available here: \\url{https://www.overleaf.com/learn/latex/TikZ_package}):\n\\begin{center}\n\\begin{tikzpicture}\n\n\\draw (-2,0) -- (2,0);\n\\filldraw [gray] (0,0) circle (2pt);\n\\draw (-2,-2) .. controls (0,0) .. (2,-2);\n\\draw (-2,2) .. controls (-1,0) and (1,0) .. (2,2);\n\n\\end{tikzpicture}\n\n\\end{center}\n\n\\begin{center}\n\\begin{tikzpicture}[\nroundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm},\nsquarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},\n]\n%Nodes\n\\node[squarednode]      (maintopic)                              {2};\n\\node[roundnode]        (uppercircle)       [above of=maintopic] {1};\n\\node[squarednode]      (rightsquare)       [right of=maintopic] {3};\n\\node[roundnode]        (lowercircle)       [below of=maintopic] {4};\n\n%Lines\n\\draw[->] (uppercircle.south) -- (maintopic.north);\n\\draw[->] (maintopic.east) -- (rightsquare.west);\n\\draw[->] (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.east);\n\\end{tikzpicture}\n\\end{center}\nFor more on TikZ, I recommend Google or Office Hours.\n\\section{Conclusion}\nHopefully this document helps! LaTex is very well documented online, so Googling is always a good way to get more information. But you can always reach out to course staff for a more in depth discussion of LaTex!\n\n\\end{document}\n", "meta": {"hexsha": "f7ae8886c53804556c7c0f0570d9bb4012b1dd96", "size": 6043, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lectures/Lecture02/SampleTexFile.tex", "max_stars_repo_name": "tomgrubbmath/IntroMathSoftware", "max_stars_repo_head_hexsha": "da15f9f0649989b9c2f12c06015b65b32e728061", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lectures/Lecture02/SampleTexFile.tex", "max_issues_repo_name": "tomgrubbmath/IntroMathSoftware", "max_issues_repo_head_hexsha": "da15f9f0649989b9c2f12c06015b65b32e728061", "max_issues_repo_licenses": ["MIT"], "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/Lecture02/SampleTexFile.tex", "max_forks_repo_name": "tomgrubbmath/IntroMathSoftware", "max_forks_repo_head_hexsha": "da15f9f0649989b9c2f12c06015b65b32e728061", "max_forks_repo_licenses": ["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.6242424242, "max_line_length": 359, "alphanum_fraction": 0.7059407579, "num_tokens": 1795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754371026367, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.6050517174698367}}
{"text": "\\documentclass{article}\n\\usepackage{bbold}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{commath}\n\\usepackage{bm}\n\\usepackage[makeroom]{cancel}\n\n\\begin{document}\n\n\\section{TCRen scoring}\n\n\\subsection{Deriving empirical contact scoring matrices} \n\nLet $\\tilde{n}_{ab}$ denote number of contacts between residues of amino acid $a$ of TCR CDR regions and $b$ of an epitope. We compute the symmetrized matrix $n_{ab} = \\frac{1}{2} \\left(\\tilde{n}_{ab} + \\tilde{n}_{ba}\\right)$ and marginals $n_a = \\sum_{b} n_{ab}$ and $n = \\sum_a n_{a}$.\n\nWe define an observed-to-expected contact frequency matrix as\n\n\\begin{equation}\n\\phi_{ab} = n^{obs}_{ab} /  n^{exp}_{ab} = \\frac{n_{ab} n}{n_a n _b}\n\\end{equation}\n\nand use it to derive scores for amino acid pairs similar to BLOSUM matrix derivation where scores are calculated as $S_{ab} \\sim \\log \\phi_{ab}$.\n\nWe decompose $\\phi_{ab}$ into (empirical) baseline interaction score $S_{a}$ for a given amino acid defined as\n\n\\begin{equation}\nS_{a} = \\frac{1}{20} \\sum_{b} \\log \\phi_{ab}\n\\end{equation}\n\nand specific interaction score $S_{ab}$ defined based on the formula\n\n\\begin{equation}\n\\log \\phi_{ab}= S_{ab} + S_{a} + S_{b}\n\\end{equation}\n\neffectively decoupling pairwise interactions from raw amino acid frequencies in contacting regions. E.g. by using this correction we account for Glycine residues that are frequent in the central region of CDR3$\\beta$ that is almost always close to an antigen in any TCR:pMHC complex.\n\nIn present study we compute a single scoring matrix based on CDR1,2,3 regions of both TCR$\\alpha$ and $\\beta$ chains.\n\n\\subsection{Scoring TCR:pMHC pairs}\n\nWe score each TCR:pMHC pair having residues $\\left\\{a_i\\right\\}$ of the TCR and $\\left\\{b_i\\right\\}$ of the antigen using by subtracting the non-specific binding score from the specific one:\n\n\\begin{equation}\nS\\left(\\left\\{a_i\\right\\},\\left\\{b_i\\right\\}\\right)=\\sum_{i,j} S_{a_{i}b_{j}} \\delta_{ij} - \\sum_{i} S_{a_{i}} - \\sum_{j} S_{b_{j}}\n\\end{equation}\n\nwhere $\\delta_{ij} \\in \\left\\{0, 1\\right\\}$ is $1$ for contacting residues and $0$ otherwise. We subtract baseline scores in order to account for intrinsic properties of amino acids to bind in a non-specific manner. As four flanking residues from both sides of CDR3 are involved in the $\\Omega$-loop formation, are almost never involved in TCR:antigen contacts and are subject to strong bias from V/J segment choice, we would substitute $\\left\\{a_i\\right\\}$ by $\\left\\{a_i\\right\\} / \\left\\{a_{1..4}\\right\\} \\cup \\left\\{a_{-4..-1}\\right\\}$ for CDR3 regions in our calculations.\n\n\\subsection{Physical interpretation of scoring}\n\n(Experimental, not sure it should be included) The scoring can be decomposed into the following components\n\n\\begin{align}\n\\begin{split}\nS\\left(\\left\\{a_i\\right\\},\\left\\{b_i\\right\\}\\right) &= \\sum_{i,j} S_{a_{i}b_{j}} \\delta_{ij} \\\\ &- \\sum_{i} S_{a_{i}} \\left(1 - \\delta_i\\right) - \\sum_{j} S_{b_{j}} \\left(1 - \\delta_j\\right) \\\\ &- \\sum_{i} S_{a_{i}} \\delta_i - \\sum_{j} S_{b_{j}} \\delta_j \\\\\n &= -\\left(E_{bound} - E_{unbound} - E_{bound,nonspec}\\right) \\\\\n &= -\\left(\\Delta E_{bound} - E_{bound,nonspec}\\right) = -\\Delta \\Delta E\n\\end{split}\n\\end{align}\n\nwhere $\\delta_i = \\max_{j} \\delta_{ij}$ identifying a residue having at least one contact, assuming $E_{unbound,nonspec}=0$.\n\n\\end{document}\n", "meta": {"hexsha": "bdfeb77618473bf4e41ea1de3633fe3b98e7d67d", "size": 3313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "formalism/tcren_formalism.tex", "max_stars_repo_name": "antigenomics/tcren-ms", "max_stars_repo_head_hexsha": "006d8274fe12183f293553948e442b411c477e17", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-05T12:48:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T12:48:00.000Z", "max_issues_repo_path": "formalism/tcren_formalism.tex", "max_issues_repo_name": "antigenomics/tcren-ms", "max_issues_repo_head_hexsha": "006d8274fe12183f293553948e442b411c477e17", "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": "formalism/tcren_formalism.tex", "max_forks_repo_name": "antigenomics/tcren-ms", "max_forks_repo_head_hexsha": "006d8274fe12183f293553948e442b411c477e17", "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": 50.196969697, "max_line_length": 576, "alphanum_fraction": 0.7156655599, "num_tokens": 1063, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6050117800916219}}
{"text": "\\section{Basic advance}\nTo change between the different ways of advancing the solution, change\nthe code in advance() between the godunov, molrk2 and molrk3 options.\n\nMOLRK2 follows the same RK2 algorithm as CNS.\nMOLRK3 follows the algorithm described in gottlieb, et al.\n$$\nu^(1) = u^n +  + \\dt L(u^n)  \\\\\nu^(2) = (3/4) u^n + (1/4) u^(1)  + (1/4) L(u^(1))\nu^{n+1} = (1/3) u^n + (2/3) u^(2)  + (2/3) L(u(2))\n$$\n\n\\subsection{Flux register factors}\n\nSince \n$$\nu^{n+1} = (1/3) u^n + (2/3) u^(2)  + (2/3) \\dt L(u(2))\n$$\n\nThis means \n$$\nu^{n+1} = (1/3) u^n + (2/3)((3/4)(u^n) + (1/4)(u^1) + (1/4)\\dt L(u^1))  + (2/3)( \\dt L(u(2)))\n$$\n\nwhich, in turn, means\n$$\nu^{n+1} = (1/3) u^n + (2/3)((3/4)(u^n) + (1/4)(u^n + \\dt L(u^n)) + (1/4)\\dt L(u^1))  + (2/3)( \\dt L(u^2))\n$$\n\nSo the coefficient of $L(u^n) = (2/3)(1/4)\\dt$, so I should set the\nflux register coefficient for the first evaluation $c_n = (1/6)\\dt$.\nThe coeffcient of $L(u^1) = (2/3)(1/4)\\dt = 1/6 \\dt$\nThe coeffcient of $L(u^2) = (2/3) \\dt$.   So for the three evaluations\nof the operator, the time step  that fluxes should see are $\\dt/6,\ndt/6, 2\\dt/3$, respectively.\n\n\n\\section{Stuff I am not sure about}\n\n\\begin{itemize}\n  \\item I am not sure where to set the time levels  in the fill patch thing.\n  \\item I am not sure what time to use for time dependent\n    vellocities.   \n\\end{itemize}\n\n\n\\section{Basic Algorithm}\n\nWe start with cell averaged scalar $<\\phi>$ and a pointwise velocity at faces.\n\n\\begin{itemize}\n  \\item Get pointwise $\\phi$ because I will need this to get higher\n    order gradient at faces.  \n$$\n\\phi = <\\phi> -\\frac{h^2}{24}(L(<\\phi>)),\n$$\n   where $L$ is the standard second order Laplacian.\n\\item Get the average of the scalar over the faces .\n$$\n<\\phi>_{i+1/2} =  \\frac{7}{12}(<\\phi>_i    + <\\phi>_{i+1})\n                -\\frac{1}{12}(<\\phi>_{i-1} + <\\phi>_{i+2})\n$$\n\n\\item Get the point values of the scalar on faces from the face\n  average:\n$$\n\\phi_{i+1/2} = <\\phi>_{i+1/2} - \\frac{1}{24} L^T(<phi>)_{i+1/2},\n$$\nwhere $L^T$ is the Laplacian that does not include terms normal to the\nface (what McCorquodale refers to as the ``transverse Laplacian'').\n\n\\item Compute pointwise fluxes $F$ (including diffusion fluxes).\n$$\nF_{i+1/2} = u_{i+1/2} \\phi_{i+1/2}  - nu G^x(phi)_{i+1/2}\n$$\nwhere the normal gradient $G^x$ is computed using fourth order finite\ndifferences  of the pointwise cell-centered scalar $\\phi$.\n$$\nG^x(\\phi)_{i+1/2} = \\frac{\\partial \\phi}{\\partial x} + O(h^4) \n= (1/h)(\\phi_{i+1}-\\phi_{i}) \n- (1/(4h))((\\phi_{i+2} + \\phi_i - 2\\phi_{i+1}) - (\\phi_{i+1} + \\phi_{i-1} - 2\\phi_{i}))\n$$\n\n\\item Transform the pointwise fluxes $F$ into face-averaged fluxes $<F>$\n$$\n<F> = F - (1/24) L^T(F).\n$$    \n\nAlgorithm seems to work.  To fully test, I need to\n\\begin{itemize}\n  \\item Write MPI=based convergence script.\n  \\item Run tests (with and without AMR), record results.\n  \\item Write up document.\n\\end{itemize}\n\\end{itemize}\n", "meta": {"hexsha": "49a957273ba76a92497f0ec5fe55f0304e760cc3", "size": 2913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tutorials/Amr/ScalarAdvectionDiffusion/Doc/working_notes.tex", "max_stars_repo_name": "malvarado27/Amrex", "max_stars_repo_head_hexsha": "8d5c7a37695e7dc899386bfd1f6ac28221984976", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-20T13:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-20T13:04:05.000Z", "max_issues_repo_path": "Tutorials/Amr/ScalarAdvectionDiffusion/Doc/working_notes.tex", "max_issues_repo_name": "malvarado27/Amrex", "max_issues_repo_head_hexsha": "8d5c7a37695e7dc899386bfd1f6ac28221984976", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/Amr/ScalarAdvectionDiffusion/Doc/working_notes.tex", "max_forks_repo_name": "malvarado27/Amrex", "max_forks_repo_head_hexsha": "8d5c7a37695e7dc899386bfd1f6ac28221984976", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.34375, "max_line_length": 105, "alphanum_fraction": 0.6141434947, "num_tokens": 1144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6050117546656123}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\begin{document}\n$\\tau \\sim (\\rho H R^2_p/\\sigma)^{1/2}$\n\n\\section*{Charge}\nWe find that\n\\[q = k E_0 V_d^{2/3},\\] \nwith $k=5.01 \\times 10^{-11} \\pm  2.85 \\times 10^{-11}$ and $R^2 = 0.946$.\n\\\\\n\\begin{eqnarray*}\nq = k E_0 V_d^{2/3},\n\\end{eqnarray*}\nwith $k \\approx 1.3 \\times 10^{-10}$ (Griffiths, 1999).\n\\\\\n\\[q = 4 \\pi \\epsilon_0 \\beta E_0 R_d^2, \\]\nwith $\\beta \\approx 2.63$, (Takamatsu \\emph{et al.}, 1981).\n\\\\\nSurface potential $\\varphi_s$ is related to characteristic electric field by\n\\[ E_0  = \\frac{\\varphi_s \\kappa}{4 \\pi \\epsilon l}. \\]\n\n\\section*{Parameter Estimation}\nWe can't directly measure $q$ experimentally, but we can estimate it by fitting the dynamical model to the data. Bayes' theorem:\n\\[\\begin{array}{lll}\n& \\centering \\mbox{prob}(X|D, I) & \\mbox{posterior probability density function},\\\\\n& \\centering \\mbox{prob}(D|X, I) & \\mbox{likelihood function},\\\\\n& \\centering \\mbox{prob}(X|I) &  \\mbox{prior probability density function},\\\\\n& \\centering \\mbox{prob}(D|I) &  \\mbox{evidence}.\n\\end{array}\n\\]\nThe Maximum Likelihood Estimate of the model parameters is found by maximizing the probability\n\\[\\mathcal{M} = \\ln(\\mathcal{L}) = \\ln(\\mbox{prob}(D|X, I)) = \\mbox{const} - \\frac{\\chi^2}{2}.\\]\n\n\\section*{Parameter Estimation}\nMathematically we state that we find the parameters $\\mathbf{x}$ that solve the inverse problem $G(\\mathbf{x}) = \\mathbf{d}$, using a direct search method (\\emph{Nelder-Mead}). \n\\[\n\\mbox{min} \\hspace{2 mm} \\chi^2 = \\mbox{min} \\hspace{2 mm} \\sum^n_{i=1} \\frac{\\left({y_d(t)}_i - y_G(t, \\mathbf{x})_i \\right)^2}{y_G(t, \\mathbf{x})_i}\n\\]\n\\begin{eqnarray*} \\mbox{} \\hspace{2 mm} \\begin{split} \\mathbf{x} = \\left\\{ \\begin{array}{ll}      & q\\\\\n\t\t  &\tV_d\\\\\n          & \\sigma \n          \\end{array} \\right. \n          \\end{split} \\hspace{2 mm} \\mbox{subject to constraints} \\hspace{2 mm} \\begin{split}\n          g = \\left\\{ \\begin{array}{ll}\n           V_d &\\pm \\hspace{2 mm} u_{exp}\\\\\n      \t   \\sigma &\\pm  \\hspace{2 mm} u_{exp}\\\\\n      \t   y_0 &\\pm \\hspace{2 mm} u_{exp}\\\\\n      \t   t_0 &\\pm \\hspace{2 mm} u_{exp}\\\\\n          \\end{array} \\right. \n          \\end{split}\n\\end{eqnarray*}\nwhere $y_G(t, \\mathbf{x})$ is a numerical solution of the equation of motion\n\\[\nm y'' = \\frac{1}{2} \\rho C_D A_d {y'}^2 + q E(y) + K q^2 y^{-2} \\]\n\n\\section*{Governing Equation}\n\\begin{equation*}\nm y'' = - \\mathbf{F}_D - \\mathbf{F}_E, \\hspace{5 mm} y(0) = R_d, \\hspace{5 mm} y'(0) = U_0,\n\\label{gov_eqn}\n\\end{equation*}\n\\\\\n\\begin{equation*}\\label{force_density}\n\\mathbf{F}_E = \\rho_f \\mathbf{E} + \\frac{1}{2} \\left| E \\right|^2 \\nabla \\epsilon - \\nabla \\left( \\frac{1}{2} \\rho \\left( \\frac{\\partial \\epsilon}{\\partial \\rho} \\right)_T \\left| E \\right|^2 \\right) .\n\\end{equation*}\n\\\\\n\\begin{eqnarray*}\n \\mathbf{F}_E &=& q \\mathbf{E} + \\mathbf{F}_{DEP} + \\mathbf{F}_I \\\\\n &=& q \\mathbf{E} + \\frac{k q^2}{16 \\pi \\epsilon_0 } y^{-2} \\hat{\\mathbf{j}} + 2 \\pi R_d^3 \\kappa_1 \\epsilon_0 K \\nabla E^2, \n\\end{eqnarray*}\n\\\\\n\\begin{eqnarray*} \\label{gov_eqn_subs}\n&m y'' = - \\frac{1}{2} C_D \\rho A {y'}^2 - q E - \\frac{k q^2}{16 \\pi \\epsilon_0} y^{-2}- 2 \\pi R_d^3 \\kappa_1 \\epsilon_0 K \\nabla E^2,& \\nonumber \\\\\n&y(0) = R, \\hspace{1 mm} y'(0) = U_0 .&\n\\end{eqnarray*}\n\\\\\nWe note we can neglect polarization stresses when\n\\begin{eqnarray}\n\\frac{ \\kappa_2 \\epsilon_0 K R_d^2 E_0}{q} \\ll 1. \\nonumber\n\\end{eqnarray}\n\n\\newpage\n\\section*{Scaling}\nIntroducing the scaled variables\n\\begin{equation*}\n \\bar{t} = \\frac{t}{t_c}, \\hspace{10 mm} \\bar{y} = \\frac{y}{y_c}, \n \\end{equation*}\nwhere $y_c$ and $t_c$ are characteristic length and time scales respectively, and using the coordinate transformation $y(0) - R = 0$, the governing equation becomes\n\\begin{eqnarray*}\n& \\bar{y}'' = - \\mathbf{\\Pi}_1 \\bar{y}'^2\n- \\mathbf{\\Pi}_2 \\bar{E} ( \\bar{y} ) \n- \\mathbf{\\Pi}_3 \\left( \\mathbf{\\Pi}_4  \\bar{y} + 1 \\right)^{-2}, & \\nonumber \\\\\n& \\bar{y}(0) = 0, \\hspace{1 mm} \\bar{y}'(0) = \\mathbf{\\Pi}_5&, \\label{scaled_eqn}\n\\end{eqnarray*}\nwith\n\\[ \\mathbf{\\Pi}_1 = \\frac{C_D \\rho A y_c}{2 m}, \\hspace{5 mm}\n\\mathbf{\\Pi}_2 = \\frac{q E_0 t_c^2}{m y_c}, \\hspace{5 mm}\n\\mathbf{\\Pi}_3 = \\frac{k q^2 t_c^2}{16 \\pi \\epsilon_0 R^2 m y_c}, \\hspace{5 mm}\n\\mathbf{\\Pi}_4 = \\frac{y_c}{R}, \\hspace{5 mm}\n\\mathbf{\\Pi}_5 = \\frac{U_0 t_c}{y_c}.\\]\n\\section*{Scaling: short-times limit}\nWith $y_c \\sim U_0 t_c$ and picking $t_c$ such that Coulombic force $\\mathbf{\\Pi}_2 \\sim \\mathcal{O}(1)$, the intrinsic scales become\n\\[ t_c \\sim \\frac{m U_0}{q E_0}, \\hspace{5 mm}\ny_c \\sim \\frac{m U_0^2}{q E_0} .\n\\]\nWith these scales the governing equation is\n\\begin{eqnarray*}\n& \\bar{y}'' = -1 - \\mathbb{I}\\mbox{m} \\left( \\mathbb{E}\\mbox{u}\\bar{y} + 1 \\right)^{-2} ,& \\nonumber \\\\\n& \\bar{y}(0) = 0, \\hspace{1 mm} \\bar{y}'(0) = 1 .& \\label{img_limit}\n\\end{eqnarray*} \nwith \n\\[ \\mathbb{I}\\mbox{m} \\equiv \\frac{k q}{16 \\pi \\epsilon_0 R_d^2 E_0} = \\mathbf{\\Pi}_3 = \\frac{\\mbox{Image force}}{\\mbox{Coulomb force}}, \\hspace{5 mm}\n\\mathbb{E}\\mbox{u} \\equiv \\frac{m U_0^2}{q E_0 R_d} = \\mathbf{\\Pi}_4 = \\frac{\\mbox{Inertia}}{\\mbox{Coulomb force}}.\n\\]\n\\section*{Scaling: long-times limit}\n\\[ t_c \\sim \\frac{R_d^2}{L^2} \\frac{4 \\pi m U_0}{q E_0}, \\hspace{5mm} y_c \\sim \\frac{R_d^2}{L^2} \\frac{4 \\pi m U_0^2}{q E_0}.\n\\]\nWith this scaling the non-dimensional governing equation is \n\\begin{eqnarray*}\n&\\bar{y}'' = - \\mathbb{D}\\mbox{g} \\mathbb{E}\\mbox{u}_+ \\bar{y}'^2 - \\left( \\mathbb{E}\\mbox{u}_+ \\bar{y} + 1 \\right)^{-2}, & \\nonumber \\\\\n& \\bar{y}(0) = 0, \\hspace{1 mm} \\bar{y}'(0) = 1 & \\label{drag_limit}\n\\end{eqnarray*}\nwhere $\\mathbb{D}\\mbox{g}$ the drag number, $\\mathbb{D}\\mbox{g} \\equiv \\frac{C_D \\rho_a}{\\rho_l} = \\mathbf{\\Pi}_1 {\\mathbb{E}\\mbox{u}}_+^{-1}$ and $\\mathbb{E}\\mbox{u}_+ = 4 \\pi \\frac{R_d^2}{L^2} \\mathbb{E}\\mbox{u}$.\n\n\\newpage\n\\section*{Escape Velocity}\nAs ${\\mathbb{E}\\mbox{u}}_+$ grows, the time-of-flight grows rapidly, approaching an asymptote at a certain critical velocity; this is an electrostatic escape velocity, $U_e$. From\n\\[ m u' = - \\frac{q E_0 y_c^2}{y^2}, \\]\nwe find\n\\[ u(y) = \\pm U_0 \\left[1 + \\frac{2q E_0 y_c^2}{m U_0^2} \\left( \\frac{1}{y} - \\frac{1}{R_d} \\right) \\right]^{1/2}.\n\\]\nThis equation has an asymptotic velocity, $U_{\\infty}$ at $y = \\infty$ which is real if \n\\[ U_0 \\geq  U_e = y_c \\sqrt{\\frac{2 q E_0 }{m R_d}}.\n\\]\nDrops will escape the electric field when\n\\begin{equation*}\\label{escape}\n{\\mbox{B}^2 \\mathbb{E}\\mbox{u}}^3 > 1,\n\\end{equation*}\nwhere $B^2= 8 \\pi\\frac{ R_d^2}{L^2}$.\n\\newpage\n\\section*{Asymptotic Estimate of Trajectory Apoapse}\nThe scaled equation is still non-linear but we can get an approximate analytical solution by means of a regular perturbation, using the naive expansion\n\\[ \\bar{y}(\\bar{t}) \\sim \\bar{y}_0(\\bar{t}) + \\epsilon \\bar{y}_1(\\bar{t}) + \\epsilon^2 \\bar{y}_2(\\bar{t}) \\ldots \\epsilon^n\\bar{y}_n(\\bar{t})  \n,\\]\nwe obtain\n\\begin{eqnarray*}\n&\\bar{y}(\\bar{t}) = \\bar{t} + \\frac{\\bar{t}^{2}}{2} \\left(-1 - \\alpha\\right) + \\epsilon \\left(\\frac{\\alpha \\bar{t}^{3}}{3} + \\frac{\\alpha \\bar{t}^{4}}{12} \\left(-1 - \\alpha\\right)\\right)& \\\\\n&+ \\epsilon^{2} \\left(- \\frac{\\alpha \\bar{t}^{4}}{4} + \\frac{\\alpha \\bar{t}^{5}}{60} \\left(9 + 11 \\alpha\\right) + \\frac{\\alpha \\bar{t}^{6}}{360} \\left(-9 - 20 \\alpha - 11 \\alpha^{2}\\right)\\right) + \\mathcal{O}(\\epsilon^3).&\n\\end{eqnarray*}\n\n\\end{document}", "meta": {"hexsha": "954d4eec5a10aee9fe3d07c97cae60f57e8e40bc", "size": 7355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/figures/presentation/mathscratch.tex", "max_stars_repo_name": "7deeptide/Thesis_scratch", "max_stars_repo_head_hexsha": "d776d57f642de4df718c1f655f080c8fe402e092", "max_stars_repo_licenses": ["MIT"], "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/figures/presentation/mathscratch.tex", "max_issues_repo_name": "7deeptide/Thesis_scratch", "max_issues_repo_head_hexsha": "d776d57f642de4df718c1f655f080c8fe402e092", "max_issues_repo_licenses": ["MIT"], "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/figures/presentation/mathscratch.tex", "max_forks_repo_name": "7deeptide/Thesis_scratch", "max_forks_repo_head_hexsha": "d776d57f642de4df718c1f655f080c8fe402e092", "max_forks_repo_licenses": ["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.0718954248, "max_line_length": 223, "alphanum_fraction": 0.6227056424, "num_tokens": 3128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256432832333, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6049311918589653}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Numerical, Graphical, Algebraic, and Verbal}\n\n\n\\objective{Use functions defined numerically, graphically, algebraically, or verbally.}\n\n\n\nA \\gls{function} is a relation that uniquely associates members of one \\gls{set} \nwith members of another set.  \nMore simply, a function connects members of a \\gls{domain} to members of a \\gls{range}, \nwith the proviso that each element in the domain maps onto only one element in the range.  \nWhen graphing a function, it is customary to plot the \\emph{input} or \\gls{independent variable} \non the $x$-axis (going left to right), and the \\emph{output} or \\gls{dependent variable} on \nthe $y$-axis (going down to up).  The independent variable is so-called because it may \nbe arbitrarily chosen from within the domain.  The dependent \nvariable is then forced to be a particular value (by the function).\n\n\\subsubsection{Numerically}\nTypically, information is gathered about the physical world as \\gls{discrete} numbers, \noccurring at fixed points. Such information may be represented as in table~\\ref{tab:Numerically}.\n\n\\columntable[-0.75in]{1.6in}{\n  \\begin{tabular}{ lr }\n  \\hline\n  \\textbf{x} (months since) & \\textbf{y} (100's of \\$)\\\\\n  \\hline\n  0 & 1200.00 \\\\\n  1 & 840.00 \\\\\n  10 & 1680.24 \\\\\n  16 & 2072.98 \\\\\n  23 & 2264.72 \\\\\n  36 & 4303.93 \\\\\n  48 & 6770.53 \\\\\n  \\hline\n  \\end{tabular}\n   }{Monthly income represented numerically\\label{tab:Numerically}}\n    \n    \n\\subsubsection{Graphical}\nA helpful way to visualize relationships between input and output \nsets is a \\gls{graph} of the function.  Similar techniques\ninclude diagrams (see Figure for an example) and maps (see Figure for an example).  \n``Mapping diagrams'' blur the line between numerical and graphical data \n(see Figure ~\\ref{fig:graphically} for an example).\n\n\\begin{figure}[h]\n\\centering\n\\begin{tikzpicture}\n\\begin{axis}[samples=500,domain=0:48,restrict y to domain =0:8500]\n\\addplot[very thick,orange ]plot (\\x, {1000*(pow(1.04,\\x))+200*cos((\\x r)*3.1415)});\n\\end{axis}\n\\end{tikzpicture}\n\\caption[Graph]{Monthly Income  - Graphically\\label{fig:graphically}}\n\\end{figure}\n\n\n\\subsubsection{Algebraically}\nTypically, graphs come from humans or machines plotting many, \nmany points derived from an \\gls{algebraic} formula.\nAlgebra is a powerful tool for describing natural phenomena, \nbut it cannot do everything.  Important numbers\n--- such as \\gls{pi} or $e$ --- cannot be defined via algebraic techniques.  \nWorse, many confuse manipulation of the symbols with actual mathematics.\nHowever, the symbols are very concise, as you might see in Tab.~\\ref{tab:algebra}.\n\n\\columntable[-0.75in]{0.3in}{\n\\begin{center}\n$y=1000\\cdot1.04^x+200\\cos(\\pi x)$.\n\\end{center}}\n{Monthly Income - Algebraically\\label{tab:algebra}}\n\n\n\n\\subsubsection{Verbally}\nOrdinary language serves us well most of the time, with an average level of \nprecision and an average level of\nemotional content.  Sometimes, however, what we wish to convey is more \nmeaningful and deep than\nregular wording can describe.  Conversely, we might wish to exclude a whole \nhost of meanings, and narrowly\nzoom in on precise terminology, in order to avoid error to the fullest extent possible\n(see Fig.~\\ref{fig:lol}).\n\n\\marginfig[-0in]{\\chapdir/pics/levelsoflanguage}{Levels of language\\label{fig:lol}}\n\nMost of us encounter poetic language\\index{language} in the form of songs, since ours is an \nage sadly bereft of\npoetry, something that was not true a century ago or more.  Another common \nphenomenon is to meet \ntechnical language when it is not expected or welcome, such as when we read the \ninstruction manual for new\nhardware or legal documents.  However, such documents are typically not aiming at \neasy comprehension, but\nprecision.  Like most jargon, they tend to use mostly ordinary words in extraordinary \nways, similar but opposite\nto poetry.\n\nMathematics is no different.  This textbook is a formal setting, and as such, \nit uses technical language, carefully\nchoosing each word according the conventions and definitions ``in house''.  \nAs you cross the threshold into the\nbeginning stages of advanced mathematics, you must cultivate the skill of \nusing this ``jargon'', something you \ndo not ordinarily do.  It may help your comprehension to paraphrase \nwhat you are learning into the ``vernacular,''\nbut you should not consider a topic concluded until you are able to \nre-articulate the mater in mathematical terminology.\nFor example, the equation above might be described as in Fig.~\\ref{fig:verbally}.\n\n\\begin{figure}\n\\emph{The income ($y$) may be modeled by the number of months since \ninception ($x$) as a sinusoid with an amplitude of 200, a period of 2, and a\nmidline of an exponential growth rate of 4\\% beginning at \\$1,000.}\n\\caption{Monthly Income - Verbally\\label{fig:verbally}}\n\\end{figure}\n\n\\subsubsection{Mathematical Models}\nFunctions that can be used to make predictions and \ninterpretations of real-world phenomena are called \\textbf{mathematical\nmodels}.\nIt is important to be clear which variable is being used as input \nand which is output, so that a meaningful\nrelationship between independent and dependent variables \ncan be ascertained.  In the model of income above,\ntime does not depend upon money, but rather money upon time.  \nThe domain of the function is the initial time\nindex of zero until four years later, so in months $0\\le x \\le 48$.  \nThe income varies from as low as \\$840 but\ngenerally goes up from there, so the range is $y\\ge840$.\n\n\\begin{example}\n\t\\exProblem\nThere are only so many hours in a day.  If you decide to stay up \\emph{all} night studying, \nyou will surely get\na bad grade on the test tomorrow, due to sleep deprivation.  \nSketch a reasonable graph showing hours spent sleep the day before\na test and the grade you will get on said test.  Give the domain and range of the function.\n\n\t\\exSolution\nOne cannot possibly get less than zero hours of sleep, and presumedly around \n12 or so hours of sleep is\nlong enough to have slept through the exam and angered one's parents!  \nTest scores are typically measured in percents, ranging from 0 to 100.\n\n\\marginfig[-1.8in]{\\chapdir/pics/sleep.png}{Possible graph of sleep vs. grade}\n\\end{example}\n\n~\\vfill", "meta": {"hexsha": "ce67fef8d0ea07fb5849dc2266a948b3c47b9eb8", "size": 6220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch01/0101.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/0101.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/0101.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": 41.4666666667, "max_line_length": 97, "alphanum_fraction": 0.7590032154, "num_tokens": 1657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6048614615859695}}
{"text": "\n\n\\chapter[ICA on the Sphere]{Independent Component Analysis on the Sphere}\n\\label{ch_mrs_ica}\n\n\n\\section{Introduction}\n\\index{blind source separation}\n\\index{ICA}\n\n\nBlind Source Separation (BSS) is a problem that occurs in multi-dimensional data processing. The overall goal is to recover \nunobserved signals, images or \\emph{sources} $S$ from mixtures of these sources $X$ observed typically at the output of an \narray of sensors. The simplest mixture model takes the form:\n\\begin{equation}\\label{model0}\nX = A S\n\\end{equation}\nwhere $X$ and $S$ are random vectors of respective sizes $m \\times 1$, $n \\times 1$ and $A$ is an $m \\times n$ matrix. The \nentries of $S$ are assumed to be independent random variables. Multiplying $S$ by $A$ linearly mixes the $n$ sources into \n$m$ observed processes. \\\\ \n   \nIndependent Component Analysis methods were developed to solve the BSS problem, \\emph{i.e.} given a batch of $T$ observed \nsamples of $X$, estimate the mixing matrix $A$ and reconstruct the corresponding $T$ samples of the source vector $S$, relying \nmostly on the statistical independence of the source processes. Note that with the above model, the independent sources can \nonly be recovered up to a multiplication by a \\emph{non-mixing} matrix \\emph{i.e.} up to a permutation and a scaling of the \nentries of $S$. Although independence is a strong assumption, it is in many cases physically plausible. The point is that \nit goes beyond the simple second order decorrelation obtained for instance using Principal Component Analysis (PCA) : decorrelation \nis not enough to recover the source processes since any rotation of a white random vector remains a white random vector.\\\\\n\n\nAlgorithms for blind component separation and mixing matrix estimation depend on the model used for the probability distribution \nof the sources~\\cite{ica:3easy}. In a first set of techniques, source separation is achieved in a noise-less setting, based on the \nnon-Gaussianity of all but possibly one of the components. Most mainstream ICA techniques belong to this category : JADE~\\cite{ica:jade}, \nFastICA, Infomax~\\cite{ica:icabook}. In a second set of blind techniques, the components are modeled as Gaussian processes, either \nstationary or non stationary and, in a given representation, separation requires that the sources have diverse, \\emph{i.e.} non \nproportional, variance profiles. The Spectral Matching ICA method (SMICA) ~\\cite{ica:Del2003}, considers in this sense the case of \nmixed stationary Gaussian components and goes further than the above model (Eq.~\\ref{model0}) by taking into account additive \n\\emph{instrumental } noise $N$:\n\\begin{equation}\\label{model1}\nX = A S + N\n\\end{equation}\nMoving to a Fourier representation, the idea is that colored components can be separated based on the diversity of their power spectra.\\\\ \n \nThe next two sections give a short overview of two significant ICA methods mentioned above and implemented in the \\mrs package: \nJADE and SMICA. A shorter description of FastICA ~\\cite{ica:icabook} is also given. This is followed by a description of ways to \ncombine wavelets and ICA techniques. Some useful properties of wavelet transforms can indeed come enhance the performance of ICA \nmethods in several situations. \n\n    \n\\section{JADE}\n\\index{ICA!jade}\n\nThe Joint Approximate Diagonalization of Eigenmatrices method (JADE) assumes the observed data $X$ follows the noiseless mixture \nmodel~(\\ref{model0}) where the independent sources $S$ are non-Gaussian \\emph{i.i.d.}\\footnote{The letters \\emph{i.i.d.} stand for \nindependently and identically distributed meaning that each entries of $X$ at a given time $t$ are independent of $X$ at any other \ntime $t'$ and that the distribution of $X$ does not depend on time. } random processes. The mixing matrix is assumed to be square \nand invertible so that (de)mixing is actually just a change of basis.\n\nAs mentioned above, second order statistics do not retain enough information for source separation in this context: finding a change of \nbasis in which the data covariance matrix is diagonal will not in general enable to identify the independent sources properly. Nevertheless, \ndecorrelation is \\emph{half the job}~\\cite{ica:tutorial} and one may seek the basis in which the data is represented by maximally independent \nprocesses among those bases in which the data is decorrelated. This leads to so-called orthogonal algorithms: after a proper whitening of \nthe data by multiplication with the inverse of a square root of the covariance matrix of the data $W$, one is then seeking a rotation $R$ \n(which leaves things white) so that $\\hat{ S}$ defined by\n\\begin{equation}\n\\hat{ S} = W^{-1} \\, Y =  W^{-1}\\, R \\, X_{\\textrm{white}}  = W^{-1}\\, R \\, W \\, X \n\\end{equation}\nand $\\hat{B} = \\widehat{A^{-1}} =  W^{-1}\\, R \\, W$ are estimations of the sources and of the inverse of the mixing matrix.\\\\\n\nJADE is such an orthogonal ICA method and, like most mainstream ICA techniques, it exploits higher order statistics so as to achieve some \nsort of \\emph{ non linear decorrelation}. Precisely, in the case of JADE, statistical independence is assessed using fourth order cross cumulants : \n\\begin{eqnarray}  \\nonumber\t \nF_{ijkl} & = & \\textrm{cum}( y_i, y_j, y_k, y_l )   \\nonumber    \\\\\n  & =& \\mathcal{E} (y_i y_j y_k y_l) - \\mathcal{E} (y_i y_j)\\mathcal{E} (y_k y_l)\\nonumber \\\\\n  & & -\\mathcal{E} (y_iy_l)\\mathcal{E} ( y_j y_k)-\\mathcal{E} (y_iy_k)\\mathcal{E} (y_j y_k)\n\\end{eqnarray}\nwhere $\\mathcal{E}$ stands for statistical expectation and the $y_i$'s are the entries of vector $Y$ modeled as random variables, \nand the correct change of basis (\\emph{i. e.} rotation) is found by somehow \\emph{diagonalizing} the fourth order cumulant tensor. \nIndeed, if the $y_i$'s were independent, all the cumulants with at least two different indices would be zero. As a consequence of \nthe independence assumption of the source processes $S$ and of the \\emph{whiteness} of $Y$ for all rotations $R$, the fourth order \ntensor $F$ is well structured: JADE was precisely devised to take advantage of the algebraic properties of $F$. JADE's objective \nfunction is given by\n\\begin{eqnarray}  \\nonumber\t \n%\\mathcal{J}_{\\textrm{jade}}( R )   &=& \\sum _{ijkl \\ne ijkk}  \\textrm{cum}(  y_i, y_j, y_k, y_l )^2  \\nonumber    \\\\\n  \\mathcal{J}_{\\textrm{jade}}( R ) & =&  \\sum _{ij}   \\sum_{k \\ne l} \\textrm{cum}(  y_i, y_j, y_k, y_l )^2  \n\\end{eqnarray}\nwhich can be interpreted as a joint diagonalization criterion. Fast and robust algorithms are available for the minimization \nof $\\mathcal{J}_{\\textrm{jade}}( R )$ with respect to $R$ based on Jacobi's method for matrix diagonalization~\\cite{ica:pham2001}. \nMore details on JADE can be found in~\\cite{ica:jade,ica:tutorial,ica:icabook}.\n\n\n\\subsubsection{JADE for spherical maps}\n\nApplying JADE on multichannel data mapped to the sphere does not require any particular modification of the algorithm. Indeed, JADE estimates \nthe fourth order cumulant tensor from the available data samples assuming an \\emph{i.i.d.} random field. Hence, given a pixelization scheme on \nthe sphere such as provided by the Healpix package, JADE can be directly applied to the multichannel spherical data pixels.\n\n\n\\section{FastICA}\n\\index{ICA!fastica}\n\nFastICA is by now a standard technique in ICA. Like JADE, it is meant for the analysis of mixtures of independent non-Gaussian sources in \na noise-less setting. A complete description of this method can be found in \\cite{ica:icabook} and references therein. Many papers on this \nalgorithm are available at \\emph{http://www.cs.helsinki.fi/ u/ahyvarin/papers/fastica.shtml}. We give here a brief and simplified account \nof the algorithm. FastICA, again like JADE, is a so-called orthogonal ICA method: the independent components are sought by maximizing a \nmeasure of non-Gaussianity under the constraint that they are decorrelated. Intuitively, one should understand that mixtures of independent \nnon-Gaussian random variables tend to \\emph{ look more Gaussian}. An enlightening view on the relation between mutual information, which is \na natural measure of independence, decorrelation and non-Gaussianity can be found in~\\cite{ica:3easy,ica:geomindep}. Non-Gaussianity is assessed \nin FastICA using a contrast function $G$ based on a non-linear approximation to \\emph{negentropy}~\\cite{ica:icabook}. In practice, depending \non the application, different approximations or non-linear (non-quadratic) functions should be experimented with. In a simple deflation scheme, \nfor sphered data, the directions are found sequentially : a direction $r$ of maximal non-Gaussianity is sought by maximizing \n\\begin{equation}\nJ_G(r) = \\Big( \\mathcal{E} \\{ G(r^T x_{\\textrm{white}}  ) \\} - \\mathcal{E} \\{ G(\\nu ) \\} \\Big)^2 \n\\end{equation}\nwhere $\\nu$ stands for centered unit variance Gaussian variable, under the constraint that $r$ has unit norm and that $r$ is orthogonal \nto the directions found previously. The contrast function $G$ can for instance be chosen among the following~\\cite{ica:icabook}:\n\\begin{eqnarray}\nG_0 (u)  & = &  \\frac{1}{a} \\textrm{log}\\,\\textrm{cosh} (a u ) \\nonumber    \\\\\nG_1 (u)  & = &  -\\frac{1}{a} \\textrm{exp}(- a u^2 / 2 )   \\nonumber\t   \\\\\nG_2 (u)  & = &  \\frac{1}{4} u^4 \\nonumber    \\\\\n\\end{eqnarray}\nwhere $a$ is a constant to be determined depending on the application. It can be shown that the maxima of $J_G$ occur at certain maxima \nof $\\mathcal{E} \\{ G(r^T x_{\\textrm{white}} ) \\} $. These are obtained for $r$ solution to :\n\\begin{equation}\n\\mathcal{E} \\{ x_{\\textrm{white}} g(r^T x_{\\textrm{white}}  ) \\} - \\lambda r = 0 \n\\end{equation}\nwhere $\\lambda$ is a constant easily expressed in terms of the optimal direction $r_0$, and $g$ is the derivative of $G$. Solving this \nequation using Newton's method, and a few approximations, a \\emph{fixed-point} algorithm is derived which consists in repeating the \nfollowing two steps until convergence :\n\\begin{eqnarray}\nr  & \\leftarrow & \\mathcal{E} \\{ x_{\\textrm{white}} g(r^T x_{\\textrm{white}}  ) \\} - \\mathcal{E} \\{ g'(r^T x_{\\textrm{white}}  ) \\} r     \\nonumber  \\\\\nr  & \\leftarrow  &  \\frac{r}{\\| r \\|}   \\nonumber\t   \\\\\n\\end{eqnarray}\nA simple implementation of this algorithm is included in the present package. It is largely based on the $\\textbf{Matlab}^{TM}$ code \navailable at \\emph{www.cis.hut.fi/projects/ica/fastica/}. \n\n%\\section{SMICA}\n%\\index{smica}\n%\\index{ICA!smica}\n%\n%Spectral Matching ICA (SMICA) was designed to address some of the general problems raised by Cosmic Microwave Background data analysis \n%where the major component of interest (CMB itself) is well modeled by an isotropic stationary Gaussian random field. Although standard \n%ICA methods may be used in this context, they are not expected to perform as well as methods based on Gaussian model especially in the \n%presence of additive Gaussian instrumental noise as in (\\ref{model1}).   \n%\n%SMICA belongs to a set of blind source separation techniques where the components are modeled in a given representation as \\emph{locally i.i.d.} \n%centered Gaussian processes. Independent Gaussian sources can then be separated based on their statistical independence (which obviously reduces \n%\\emph{locally} to decorrelation) provided they have diverse (\\emph{i.e.} non proportional) variance profiles \\emph{i.e.} energy distributions in \n%that representation. SMICA considers in this sense the case of mixed stationary Gaussian components in a noisy context as in model~(\\ref{model1}) : \n%moving to a Fourier representation, colored components can be separated based on the diversity of their power spectra. \n%\n%\\subsection{SMICA's objective function} \n%\n%In order to derive the Spectral Matching ICA criterion, we assume that, in the Fourier domain, the \\emph{locally i.i.d.} Gaussian sources $S$ \n%and noise $N$ processes in (\\ref{model1}) actually have constant spectral covariance matrices $R_f^S(q) \\in \\mathbb{R}^{n\\times n}$ and $R_f^N(q) \n%\\in \\mathbb{R}^{m \\times m} $ on each of a set of $Q$ frequency bands. Clearly, the appropriate notion of frequency should be used, depending on \n%whether the data $X$ is a set of time series, a set of 2D maps, etc. The assumption of statistical independence between the components $S$ implies \n%that the $R_f^S(q)$ are diagonal matrices. With a similar assumption regarding  the noise processes in the $m$ different channels, the $R_f^N(q)$ \n%also are diagonal matrices. Applying a Fourier transform on (\\ref{model1}) does not affect the mixing matrix $A$, so that the model covariance \n%matrix of the observations $X$ in the $q^{\\textrm{th}}$ frequency band is structured as  \n%\\begin{equation}\n%\\label{structure}\n%R_f^X(q) = A R_f^S(q) A^{\\dagger} +   R_f^N(q)\n%\\end{equation}\n%where we assumed that the instrumental noise is independent of the sources. Then, provided estimates $\\widehat{R}_f^X(q) $ of $R_f^X(q) $ can be \n%obtained from the available data (\\emph{e.g.} empirical covariance estimator), SMICA consists in minimizing \n%\\begin{equation}\\label{Cost_fourier}\n% \\Phi_f (\\theta) =  \\sum _{q=1}^{Q}  \\alpha_q \\mathcal{D} \\left( \\widehat{R}_f^X(q) \\ , A R_f^S(q) A^{\\dagger} +   R_f^N(q) \\right)\n%\\end{equation}\n%for some sensible choice of the weights $\\alpha_q$ and of the matrix mismatch measure $\\mathcal{D}$, with respect to the full set of parameters \n%$\\theta = (A,R_f^S(q), R_f^N(q) )$ or a subset thereof. As discussed in ~\\cite{ica:Del2003}, a good choice for $\\mathcal{D}$ is\n%\\begin{equation}\\label{eq:kl}\n%  \\mathcal{D}_{KL} (R_1, R_2 )  =  \\frac{1}{2} \\Big( \\mathrm{tr} (R_1R_2^{-1}) - \\log\\det (R_1R_2^{-1}) - m  \\Big)\n%\\end{equation}\n%which is the Kullback-Leibler divergence between two $m$-variate zero-mean Gaussian distributions with covariance matrices $R_1$ and $R_2$. \n%With this mismatch measure, the SMICA criterion is shown to be related to the likelihood of the data in a Gaussian model, so that we can resort \n%to the EM algorithm to minimize~(\\ref{Cost_fourier}). The weights $\\alpha_q$ should be chosen to reflect the variability of the estimate of the \n%corresponding covariance matrix. Following the derivation in~\\cite{ica:Del2003}, these are taken to be the number of Fourier modes in each band $q$. \\\\\n%\n%\\subsection{Source map estimation}\\label{sect:mapesti}\n%\n%As a result of applying SMICA, power densities in each frequency band are estimated for the sources and detector noise along with \n%the estimated mixing matrix. These may be used in reconstructing the source maps \\emph{via} for instance Wiener filtering in each band: \n%a Fourier mode $X(\\nu)$ in frequency band $q$ is used to reconstruct the maps according to\n%\\begin{equation}\n%  \\widehat{S}(\\nu) \n%  =\n%  (\\widehat{A}\\adj \\widehat{R}_f^N(q)^{-1} \\widehat{A} + \\widehat{R}_f^S(q)^{-1})\\inv \n%  \\widehat{A}\\adj \\widehat{R}_f^N(q)^{-1} X(\\nu)\n%  \\label{Wiener}\n%\\end{equation}\n%In the limiting case where noise is small compared to signal components, this filter reduces to \n%\\begin{equation}\n% \\widehat{S}(\\nu)  =\n%  (\\widehat{A}\\adj \\widehat{R}_f^N(q)^{-1} \\widehat{A} )\\inv \n%  \\widehat{A}\\adj \\widehat{R}_f^N(q)^{-1} X(\\nu)\n%  \\label{Wiener1}\n%\\end{equation}\n%Clearly, the above Wiener filter is optimal only in front of stationary Gaussian processes. For non Gaussian maps, such as given by \n%the Sunyaev Zel'dovich effect, better reconstruction can be expected from non linear methods.\n%\n%\\subsection{SMICA for spherical maps}\\label{sect:smicas}\n%\n%In the linear mixture model~(\\ref{model1}), $X$ now stands for an array of observed spherical maps, $S$ is now an array of spherical source maps \n%to be recovered and $N$ is an array of spherical noise maps. The mixing matrix $A$ achieves a pixelwise linear mixing of the source maps, in the \n%Healpix scheme for instance.\n% \n%Extending SMICA to deal with multichannel data mapped to the sphere is straightforward~\\cite{ica:Del2003}. The idea is simply to substitute the \n%spherical harmonics transform to the Fourier transform used in the above description of SMICA. Then, data covariance matrices are estimated in \n%this representation over $Q$ intervals in multipole number $l$, assuming the components are stationary and isotropic over the sphere. These $Q$ \n%covariance matrices are still structured according to~(\\ref{structure}) and source separation can be achieved by minimizing the spectral matching \n%criterion~(\\ref{Cost_fourier}). Source maps reconstruction follows as in section~\\ref{sect:mapesti}.\\\\\n%\n%SMICA has already been applied in astrophysical data analysis, showing significant success for CMB spectral estimation in multidetector \n%experiments~\\cite{ica:Del2003,ica:patanchon}. Working in the frequency domain does offer several benefits such as easy handling of detector \n%dependent point spread functions. However, the non locality of the Fourier or the spherical harmonics transform will have some undesired \n%effects when dealing with non-stationary components or noise, or with incomplete data maps. The latter is a common issue in astrophysical \n%data analysis : either the instrument scanned only a fraction of the sky or some regions of the sky were masked due to localized strong \n%astrophysical sources of contamination (compact radio-sources or galaxies, strong emitting regions in the galactic plane). A simple way \n%to overcome these effects is to move instead to a wavelet representation so as to benefit from the localization property of wavelet filters. \n%This leads to WSMICA~\\cite{starck:yassir05}, an extension of SMICA which is reviewed in section~\\ref{sect:wsmica} below. \n\n\n\n\\section{ICA and Wavelets} \n\\index{wavelet!ICA}\n\\index{ICA!wavelet}\n\n\nSeveral properties of wavelets have been recognized as particularly useful in multichannel data processing : bringing wavelets and \nindependent component analysis together has proven quite profitable. Extensions WJADE and WSMICA of the two ICA methods described \npreviously are discussed in this section.\n\nWavelets are remarkable at data compression meaning data that is structured in the initial representation requires fewer significant \ncoefficients in a wavelet representation. In imprecise and general terms, wavelets grab the coherence between coefficients of the \nstructured data and produces a smaller set of significant coefficients which are then less coherent and which have a sparser statistical \ndistribution. Then, the super-Gaussian\\footnote{A super-Gaussian distribution is also called a lepto-kurtic distribution, referring to a \ndistribution with a narrow central peak and heavy tails. A typical example is the Laplacian distribution.} \\emph{i.i.d.} statistical model \nwhich appears in most standard ICA methods may better suit the wavelet coefficients of the data than the data samples in the initial representation. \n\nWavelets have been developed for the analysis of non-stationary and singular data in order to overcome certain difficulties attached to \nthe Fourier transform. Wavelets are widely used to reveal variations in the spectral content of time series or images as they permit to \nsingle out regions in direct space while retaining localization in the frequency domain. Astrophysical data analysis has much to gain in \navoiding the assumption of stationarity underlying Fourier analysis. Moreover, observed data maps are commonly imperfectly shaped and \nincomplete with missing or masked patches due to experimental settings, scanning strategies, etc. This will impair direct application of \nthe Spectral Matching ICA method described previously. One might consider resorting to wavelets.     \n          \n \n%In dealing with non stationary data or incomplete data, an attractive feature of  wavelet filters over the spherical harmonic transform is that they are well localized in the initial representation. \n\n%Dealing with non stationary data or incomplete data is made simpler due to the good localization of wavelet coefficients in the initial representation.In the smaller scales, most of the samples in the filtered signal will  be unaffected by the presence of gaps and only these samples should be used to estimate the data covariance matrices on each wavelet scale.\n\n\\subsection{WJADE}\\label{sec:wjade}\n\\index{ICA!wjade}\n\\index{jade!wavelet}\n\nWavelets come into play as a sparsifying transform. Applying a wavelet transform on both sides of~(\\ref{model0}) does not affect the \nmixing matrix and the model structure is preserved. Also, moving the data to a wavelet representation does not affect its information \ncontent. However, the statistical distribution of the data coefficients in the new representation is different: wavelets are known to \nlead to sparse \\emph{i.i.d.} representations of structured data. Further, the \\emph{local} (coefficient wise) signal to noise ratio \ndepends on the choice of a representation. A wavelet transform tends to grab the informative coherence between pixels while averaging \nthe noise contributions, thus enhancing structures in the data. Although the standard ICA model~(\\ref{model0}) is for a noiseless setting, \nthe derived methods can be applied to real data. Performance will depend on the detectability of significant coefficients \\emph{i.e.} on \nthe sparsity of the statistical distribution of the coefficients. Moving to a wavelet representation will often lead to more robustness to noise.    \n\nOnce the data has been transformed to a proper representation (\\emph{e.g.} wavelets but also ridgelets and curvelets in the case of strongly \nanisotropic 2D or 3D data), WJADE consists in applying the standard JADE method to the new multichannel coefficients. Once the mixing matrix \nis estimated, the initial source maps are obtained using the adequate inverse transform after some non linear denoising or thresholding of \nthe coefficients if necessary.\n\n\\subsection{Covariance matching in wavelet space : WSMICA}\\label{sect:wsmica}\n\\index{ICA!wsmica}\n\\index{smica!wavelet}\n\\index{wavelet!transform}\n\nLet us consider the case of spherical maps as in \\ref{sect:smicas} but possibly incomplete, partly masked or non-stationary. As a model case, \nwe actually consider incomplete data maps in which the positions of the missing pixels are known in advance. Moving to a wavelet representation, \nit is possible to keep track of the missing pixels on each scale so that we can derive a covariance matching ICA criterion, WSMICA, robust to \ngaps in the data. Indeed, an attractive feature of wavelet filters over the spherical harmonic transform is that they are well localized in the \ninitial representation. Provided the wavelet filter response on scale $j$ is short enough compared to data size and gap widths, most of the \nsamples in the filtered signal will then be unaffected by the presence of gaps. Using exclusively these samples yields an estimated covariance \nmatrix $\\widehat{R}_w^X(j)$ which is not biased by the missing data. The price to pay is a possibly slight increase in variance which depends on scale $j$.\n\nWith the Isotropic Undecimated Wavelet Transform on the Sphere (UWTS) decribed in section~\\ref{sect_wts}, the multichannel data $X$ is decomposed \ninto $J$ detail maps $X_{j}^w$ and a smooth approximation map $X_{J+1}^w$ over a dyadic resolution scale which simply sum back as: \n\\begin{equation}  \nX(\\vartheta, \\varphi) = X_{J+1}^w (\\vartheta, \\varphi) + \\sum_{j=1}^{J} X_{j}^w(\\vartheta, \\varphi)\n\\end{equation}\nDenoting $l_j$ the size of the set $\\mathcal{M}_j$ of wavelet coefficients unaffected by the gaps at scale $j$, the wavelet covariances are empirically estimated using\n\\begin{equation}\n\\widehat{R}_w^X (j) = \\frac{1}{l_j }  \\sum_{t \\in  \\mathcal{M}_j } X_j^w( \\vartheta_t, \\varphi_t )X_j^w( \\vartheta_t, \\varphi_t ) ^\\dagger \n\\end{equation}\n\nClearly, applying the above UWTS on both sides of~(\\ref{model1}) does not affect the mixing matrix $A$ so that \nthe model covariance matrix of the observations at scale $j$, is still structured as  \n\\begin{equation}\nR_w^X(j) = A R_w^S(j) A^{\\dagger} +   R_w^N(j) \n\\end{equation}\nwhere $R_w^S(j)$ and $R_w^N(j)$ are the model diagonal spectral covariance matrices in the wavelet representation of $S$ and $N$ respectively \nat scale $j$. Given an estimation of $R_w^X(j)$ from the data, $\\widehat{R}_w^X(j)$, source separation follows from  minimizing the following \ncovariance matching criterion WSMICA-S in this \\emph{spherical wavelets} representation:  \n\\begin{equation}\\label{Cost_wavelet}\n \\Phi (\\theta) =  \\sum _{j=1}^{J+1}  \\alpha_j \\mathcal{D} \\left( \\widehat{R}_w^X(j), \\,\n    A R_w^S(j) A^{\\dagger} + R_w^N(j) \\right)\n\\end{equation}\nwith respect to the full set of parameters $\\theta = (A,R_w^S(j), R_w^N(j) )$ or a subset thereof. Again, a good choice for $\\mathcal{D}$ is \nthe Kullback-Leibler divergence given in equation~\\ref{eq:kl}. With this mismatch measure, we can again resort to the EM algorithm to minimize~(\\ref{Cost_wavelet}). \n\nThe weights in the covariance mismatch~(\\ref{Cost_wavelet}) should be chosen to reflect the variability of the estimate of the corresponding\ncovariance matrix. Since WSMICA-S uses wavelet filters with only limited overlap, in the case of complete data maps we follow the derivation \nin~\\cite{ica:Del2003} and take $\\alpha_j$ to be proportional to the number of spherical harmonic modes in the spectral domain covered at \nscale $j$. In the case of data with gaps, we must further take into account that only a fraction $\\beta_j$ of the wavelet coefficients are \nunaffected so that the $\\alpha_j$ should be modified in the same ratio. \n\nSource maps may be reconstructed outside the possible gaps by Wiener filtering on each scale prior to inverting the wavelet transform, following \nthe procedure described in section~\\ref{sect:mapesti}. Non linear filtering techniques may yield better results in the case of non-Gaussian components. \n\n\\subsubsection{WSMICA for \\emph{flat} maps}\n\nWSMICA can be easily implemented in the case of flat 2D data maps by substituting the 2D isotropic undecimated \\emph{\\`a trous} algorithm with \nthe cubic box-spline~\\cite{starck:book02} as scaling function to the UWTS used in the previous section to deal with incomplete spherical maps.\nThis transform has several favorable properties for astrophysical data analysis. In particular, it is a shift invariant transform, the wavelet \ncoefficient maps on each scale are the same size as the initial image, and the wavelet and scaling functions have small compact supports in the \ninitial representation. As in the case of spherical maps, these properties allow  missing patches in the data maps to be handled easily.\n\nWSMICA was used in~\\cite{starck:yassir05} to process realistic CMB multichannel data as expected from the Planck experiment however on small enough \nmaps so that curvature could be neglected. The reported numerical experiments clearly confirm the benefits of correctly processing existing gaps. \nWavelets are able to correctly grab the spectral content of partly masked data maps and from there allow for better component separation.  \n\n\\section{Applications}\n\n\\subsection{CMB data analysis}\\label{sect:NUMEXP}\n\\index{CMB}\n\\index{CMB!ICA}\n\\index{ICA!CMB}\n\nAs an application of WSMICA on the sphere, we consider here the problem of CMB data analysis but in the special case where the use of a galactic \nmask is a cause of non-stationarity which impairs the use of the spherical harmonics transform. \n\nThe simulated CMB, galactic dust and Sunyaev Zel'dovich (SZ) maps used, shown on the left-hand side of figure~\\ref{components}, were obtained as \ndescribed in~\\cite{ica:Del2003}. The problem of instrumental point spread functions is not addressed here, and all maps are assumed to have the \nsame resolution.The high level foreground emissions from the galactic plane region were discarded using the $Kp2$ mask from the WMAP team \nwebsite\\footnote{\\emph{http://lambda.gsfc.nasa.gov/product/map/intensity\\_mask.cfm}}. These three \\emph{incomplete} maps were mixed using the matrix \nin table~\\ref{MatrixA}, in order to simulate observations in the six channels of the Planck high frequency instrument~(HFI).\n\n\\begin{table}[!h]\n  \\begin{center}\n   \\footnotesize {\n    \\begin{tabular}{@{} cccc|c @{}}\n      CMB & DUST & SZ &  & channel \\\\\n      & & & &\\\\\n      \\hline\n      & & & &\\\\\n      $\\quad1.0\\quad$  &  $ 1.0 $    \t\t&  $\\quad-1.51\\quad$\t \t&& 100~GHz\\\\\n      $\\quad1.0 \\quad$ & $ 2.20$   \t\t& $\\quad-1.05\\quad$  \t\t&& 143~GHz\\\\\n      $\\quad1.0 \\quad$ &  $ 7.16 $  \t\t& $\\quad0.0\\quad $ \t\t\t&& 217~GHz\\\\\n      $\\quad1.0 \\quad$ &   $56.96 $\t\t&  $\\quad 2.22\\quad$ \t&&353~GHz\\\\\n      $\\quad1.0 \\quad$ &  $1.1\\times10^{3}$ \t\t&   $\\quad5.56\\quad$  \t&&545~GHz\\\\\n      $\\quad1.0\\quad $ &  $1.47\\times10^{5}$  \t& $ \\quad11.03\\quad $\t&& 857~GHz\\\\\n    \\end{tabular}}\n    \\caption{Entries of $A$, the mixing matrix used in our simulations.}\\label{MatrixA}\n  \\end{center}\n\\end{table}\n\nGaussian \\emph{instrumental} noise was added in each channel according to model~(\\ref{model0}). The relative noise standard deviations between channels \nwere set according to the nominal values of the Planck HFI given in table~\\ref{NoiseScale}. \n\n\\begin{table}[!h]\n  \\begin{center}\n     \\footnotesize {\n    \\begin{tabular}{@{} cccccc|c @{}}\n      100&143&217&353&545&857&channel \\\\\n          & & & & & &\\\\\n  \\hline\n          & & & & & &\\\\\n    $ 2.65\\!\\!\\times\\!\\!10^{-6}$&$2.33\\!\\!\\times\\!\\!10^{-6}$&$3.44\\!\\!\\times\\!\\!10^{-6}$&$1.05\\!\\!\\times\\!\\!10^{-5}$&$1.07\\!\\!\\times\\!\\!10^{-4}$& $4.84\\!\\!\\times\\!\\!10^{-3}$ &noise std\\\\\n          & & & & & &\\\\\n  % \\hline \n   %    & & & \\\\\n   %   353~GHz&545~GHz  &857~GHz  &   channel\\\\\n       %   & & &  \\\\\n  %\\hline\n  %    & & & \\\\\n   %$1.05\\times10^{-5}$&$1.07\\times10^{-4}$ & $4.84\\times10^{-3}$ &   noise std\\\\\n     % & & &  \\\\     \n      \\end{tabular}}\n    \\caption{Nominal noise standard deviations in the six channels of the Planck HFI.}\\label{NoiseScale}\n  \\end{center}\n\\end{table}\n\nThe synthetic observations were decomposed into six scales using the isotropic UWTS and WSMICA was used to obtain estimates of the mixing matrix \nand of the initial source templates. The resulting component maps estimated using WSMICA, for nominal noise levels, are shown on the right-hand \nside of figure~\\ref{components} where the quality of reconstruction can be visually assessed by comparison to the initial components. The component \nseparation was also performed with SMICA based on Fourier statistics computed in the same six dyadic bands imposed by our choice of wavelet transform, \nand with JADE. In figure~\\ref{resultats}, the performances of SMICA, WSMICA and JADE, are compared in the particular case of CMB map estimation, \nin terms of the relative standard deviation of the reconstruction error, $MQE$, defined by\n \\begin{equation}\n  MQE  = \\frac{\\mathbf{std}  ( CMB(\\vartheta, \\varphi)  - \\alpha \\times \\widehat{CMB}(\\vartheta, \\varphi)  )}{\\mathbf{std}  ( CMB(\\vartheta, \\varphi)   ) }\n  \\label{MQE}\n\\end{equation}  \n\\index{jade}\n\\index{smica}\n\\index{smica!wavelet}\n\\index{jade!wavelet}\nwhere $\\mathbf{std}$ stands for empirical standard deviation  obviously computed outside the masked regions), and $\\alpha$ is a linear regression \ncoefficient estimated in the least squares sense. As expected, since it is meant to be used in a noiseless setting, JADE performs well when noise \nis very low. However, as the noise level increases, its performance degrades quite rapidly compared to the covariance matching methods. Further, \nthese results clearly show that using wavelet-based covariance matrices provides a simple and efficient way to cancel the bad impact that gaps \nhave on the performance of source separation using statistics based on the non local Fourier representation. \n\n\\begin{figure*}[htb]\n% \\begin{center}\n% \\includegraphics[width=7cm]{CMB_map}\n% \\includegraphics[width= 7cm]{CMB_w0db}\n% \\includegraphics[width= 7cm]{hist_equal_dust}\n% \\includegraphics[width= 7cm]{hist_equal_dust_w_0db}\n% \\includegraphics[width= 7cm]{sz_map3}\n% \\includegraphics[width= 7cm]{sz_w_0db_bis}\n% \\caption{%%\n% The maps on the left are the templates for CMB, galactic dust and SZ used in the experiment \n  % described in section~\\ref{sec:NUMEXP}. The maps on the right were estimated using wSMICA \n  %  and scalewise Wiener filtering. (The different maps are drawn here in different color scales \n   % in order to enhance structures and ease visual comparisons).  } \n% \\label{components}\n% \\end{center}\n\\vbox{\n\\centerline{\n\\hbox{\n% \\psfig{figure=CMB_w0db.ps,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n\\psfig{figure=CMB_map.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n\\psfig{figure=CMB_w0db.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=hist_equal_dust.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n\\psfig{figure=hist_equal_dust_w_0db.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n}}\n\\centerline{\n\\hbox{\n\\psfig{figure=sz_map3.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n\\psfig{figure=sz_w_0db_bis.pdf,bbllx=0.5cm,bblly=7.5cm,bburx=21.5cm,bbury=20cm,width=7cm,clip=}\n}}}\n\\caption{The maps on the left are zero mean templates for CMB ($\\sigma =  4.17\\times 10^{-5}$), galactic dust ($\\sigma = 8.61\\times 10^{-6}$) \nand SZ ($\\sigma = 3.32\\times 10^{-6}$) used in the experiment described in section~\\ref{sect:NUMEXP}. The standard deviations given are for \nthe region outside the galactic mask. The maps on the right were estimated using WSMICA and scalewise Wiener filtering as is explained in Appendix~2. \nObviously, map reconstruction using Wiener filtering is optimal only in front of stationary Gaussian processes. For non Gaussian maps, such as \ngiven by the Sunyaev Zel'dovich effect, better reconstruction can be expected from non linear methods. The different maps are drawn here in \ndifferent color scales in order to enhance structures and ease visual comparisons. }\n\\label{components}\n\\end{figure*}\n\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=8cm]{resultats_aa}\n\\caption{Relative reconstruction error defined by~(\\ref{MQE}) of the CMB component map using SMICA, WSMICA and JADE as a function of the instrumental noise level in dB relative to the nominal values in table~\\ref{NoiseScale}.} \n\\label{resultats}\n\\end{center}\n\\end{figure}\n\n\n\n\\subsection{Sunyaev-Zeldovich cluster detection}\n\nAnother application of component separation techniques in astrophysics and cosmology is in the reconstruction of Sunyaev-Zel'dovich (SZ) \ngalaxy clusters in future SZ-survey experiments such as Olimpo, APEX, or Planck which will use multiband bolometer cameras. The goal is \nto optimize SZ-Cluster extraction from the multichannel observed noisy maps. Resorting to blind methods is again attractive.\n\nA complete description of the method we developed is given in~\\cite{cluster:sz_cluster}. Before the actual detection of the SZ clusters, \nthe multichannel data maps are combined and filtered to produce a clean map of the SZ component, with greater signal to noise ratio. We used \nan ICA approach to estimate the mixing matrix and perform the separation. A non linear filtering technique in the wavelet domain was used \nfor the purpose of denoising. Finally a detection algorithm extracts the SZ clusters candidates from the restored SZ map. This is a new \napplication of ICA to multichannel astrophysical data analysis. \n\nIn the 100 to 600~GHz range, the brightest components of the sky are the Cosmic Microwave Background (CMB), the Infrared Point Sources, \nthe Galactic dust emission and, swamped in the previous ones, the SZ clusters. It follows that the true sky map $X_{\\nu}(\\vartheta, \\varphi)$, \nin a given optic band centered on $\\nu$, can be modeled as a sum of distinct astrophysical radiations as in\n\\begin{equation} \\label{SkyBandModel1}\n\tX_{\\nu}(\\vartheta, \\varphi)  =  CMB_{\\nu}(\\vartheta, \\varphi)  + IR_{\\nu}(\\vartheta, \\varphi)  + Gal_{\\nu}(\\vartheta, \\varphi)  + SZ_{\\nu}(\\vartheta, \\varphi) \n\\end{equation}\nwhere $\\vartheta, \\varphi$ denote spatial or angular indexes on 2D or spherical maps. Assuming again that the radiative properties of the sources \nare completely isotropic in the sense that they do not depend on the direction of observation, the above model can be rewritten in the following factored form:\n\\begin{equation} \\label{SkyBandModel2}\nX_{\\nu}(\\vartheta, \\varphi) =  \\sum_{i} a_{\\nu, i} S_{i}(\\vartheta, \\varphi)  \\,\\,+\\,\\, N_{\\nu}(\\vartheta, \\varphi)\n\\end{equation}\nwhere $S_{i}$ is the spatial template and $a_{\\nu, i}$  the emission law of the $i\\,{\\textrm{th}}$ astrophysical component. Although this is \na coarse approximation in the case of Infrared Point Sources, it is mostly valid for the other three components. With observations available \nin $m$ channels, assuming the beam varies only slightly as a function of $\\nu$, equation~(\\ref{SkyBandModel2}) can be written in matrix form : \n\\begin{equation} \\label{SkyBandModel3}\nX(\\vartheta, \\varphi) = A\\,\\, S(\\vartheta, \\varphi)  \\,\\,+\\,\\, N(\\vartheta, \\varphi)\n\\end{equation}\nwhere $X(\\vartheta, \\varphi)$ is a vector in $\\mathbb{R}^m$, $A$ is an $m\\times n$ matrix, n is the number of contributing astrophysical components, \n$S(\\vartheta, \\varphi)$ is now a vector in  $\\mathbb{R}^n$ and $N(\\vartheta, \\varphi)$ in $\\mathbb{R}^m$. Equation~(\\ref{SkyBandModel3}) expresses \nthat the observations consist of linear mixtures of astrophysical components with different weights and additive noise. \n\nSimulations of the major contributions in the frequency range considered here were generated according to the procedure described \nin~\\cite{cluster:sz_cluster}. Figure~\\ref{RawMaps} shows such typical simulations. These four physical components are linearly \ncombined into a ``true\" sky maps which are then convolved  with the experimental beam. Then instrumental noise is added. The resulting \nnoisy mixture maps, as shown on figure~\\ref{NoisyMaps} would be what the analysis team would recover from the data, after pointing \nreconstruction, outlier removal, de-correlation of instrumental systematics in the data, and map-making. \n\n\\begin{figure*}[htp]\n\\vbox{\n\\centerline{\n\\hbox{\n\\psfig{figure=CMB.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.5cm,width=6.5cm,clip=}\n\\hspace{0.2cm}\n\\psfig{figure=SZOld.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.5cm,width=6.5cm,clip=}\n}}\n\\vspace{0.3cm}\n\\centerline{\n\\hbox{\n\\psfig{figure=IR.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.5cm,width=6.5cm,clip=}\n\\hspace{0.2cm}\n\\psfig{figure=TheGalax.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.5cm,width=6.5cm,clip=}\n}}\n}\n\\caption{The 4 physical components of the sky included in our simulation: \n{\\bf a)} is a map of the CMB's anisotropies in unit of $\\mu$K, \n{\\bf b)} is the SZ Cluster map, in unit of y Compton, \n{\\bf c)} is the IR point source map, convolved with a beam of 2 arcmin, in Jy at 350GHz, finally \n{\\bf d)} is the Galactic dust map in unit of MJy/st at 100 $\\mu$m.}\n\\label{RawMaps}\n\\end{figure*}\n\n\n\n%\n%\n%\n\\begin{figure*}[htp]\n\\vbox{\n\\centerline{\n\\hbox{\n\\psfig{figure=c143GHz.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.0cm,width=6.0cm,clip=}\n\\hspace{0.2cm}\n\\psfig{figure=c217GHz.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.0cm,width=6.0cm,clip=}\n}}\n\\vspace{0.2cm}\n\\centerline{\n\\hbox{\n\\psfig{figure=c385GHz.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.0cm,width=6.0cm,clip=}\n\\hspace{0.2cm}\n\\psfig{figure=c600GHz.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.7cm,height=7.0cm,width=6.0cm,clip=}\n}}\n}\n\\caption{Simulated maps in Olimpo's four frequency bands. {\\bf upper right} is the 147 GHz Band, {\\bf upper left)} is the 217 GHz Band, {\\bf lower right} is \nthe 385 GHz Band: CMB anisotropies, IR point sources and Galactic Dust blend in this band {\\bf lower left} 500 GHz: IR point sources and Galactic Dust are \nthe dominant features at high frequencies. SZ cluster signal is dominated by other astrophysical sources at all frequencies.}\n\\label{NoisyMaps}\n\\end{figure*}\n%\n%\n%\n\n\n\nAny mainstream ICA algorithm for sparse sources, based on maximizing non-Gaussianity, would probably be successful at separating the SZ component map. \nWe chose to use JADE in the wavelet domain, as described in section~\\ref{sec:wjade}. Wavelets come into play as a sparsifying transform : data is sparse \non a basis when this basis allows to describe that signal with a small number of coefficients. This is a highly desirable property, since noise is not \nexpected to be sparse at the same time on such a basis. Choosing a sparsifying basis thus allows to enhance signal to noise ratio. Moving the data to \na wavelet representation does not affect its information content and applying a wavelet transform on both sides of~(\\ref{model0}) does not affect the \nmixing matrix and the model structure is preserved. However, the statistical distribution of the data coefficients in the new representation is different: \nwavelets are known to lead to sparse approximately \\emph{i.i.d.} representations of structured data. Further, the \\emph{local} (coefficient wise) signal \nto noise ratio depends on the choice of a representation. A wavelet transform tends to grab the informative coherence between pixels while averaging \nthe noise contributions, thus enhancing structures in the data. Although the standard ICA model is for a noiseless setting, the derived methods can be \napplied to real data. Performance will depend on the detectability of significant coefficients \\emph{i.e.} on the sparsity of the statistical distribution \nof the coefficients. Moving to a wavelet representation will then often lead to more robustness to noise. We noted that the estimation of the mixing matrix \ncould be slightly enhanced by prefiltering the data using a Gaussian with the same width as the optical beam. The resulting SZ component map is shown \non figure~\\ref{JADEMaps}. Different filtering techniques were applied on this map and the results of a quantitative comparison are given in~\\cite{cluster:sz_cluster}.\n\n\n\n\n\\begin{figure}[htp]\n \\centerline{\n\\hbox{\n%\\psfig{figure=SZJadeG1_69w.ps}\n\\psfig{figure=SZJadeG1_69w.pdf,bbllx=3.cm,bblly=6.cm,bburx=19.1cm,bbury=21.8cm,height=6.5cm,width=6.5cm,clip=}\n}\n}\n\\caption{SZ component map extracted by JADE from the four observed noisy maps. The SZ cluster signal, subdominant at all observed frequencies, \nnow appears clearly. No obvious leftovers from other astrophysical sources are seen. \\textbf{Remaining noise is small, because we prefiltered \ndata before JADE processing, and we simulated the nominal noise levels of an ambitious project: Olimpo.}}\n\\label{JADEMaps}\n\\end{figure}\n\n\n \n", "meta": {"hexsha": "6661c5474a8418c2084606848df792d9cad52903", "size": 42631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_isap/archive_tex/mrs_ica.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_isap/archive_tex/mrs_ica.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_isap/archive_tex/mrs_ica.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": 72.2559322034, "max_line_length": 363, "alphanum_fraction": 0.7568436115, "num_tokens": 11756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6048614561290584}}
{"text": "\\documentclass{article}\n\n\\usepackage{lipsum}\n\\usepackage[margin=1.5in]{geometry}\n\\usepackage{titlesec}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\n\\usepackage{mathtools, amssymb, nccmath}\n\\usepackage{bigstrut, changepage, lipsum}\n\\usepackage{mathtools}\n\n\\newcommand{\\code}{\\texttt}\n\\newcommand{\\norm}[1]{\\left\\lVert#1\\right\\rVert}\n\n\\usepackage{siunitx} % Required for alignment\n\n\n% Specify images directory\n\\graphicspath{ {./report-images/} }\n\n% Header and Footer stuff\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\fancyhead{}\n\\fancyfoot{}\n\\fancyfoot[R]{ \\thepage\\ }\n\\renewcommand{\\headrulewidth}{0pt}\n\\renewcommand{\\footrulewidth}{0pt}\n\\newcommand{\\sectionbreak}{\\clearpage}\n\\setlength{\\parindent}{0pt}\n\n%\n\n\\begin{document}\n\n%----------------------------------------------------------------------------------------\n%\tTITLE PAGE\n%----------------------------------------------------------------------------------------\n\n\\begin{titlepage} % Suppresses displaying the page number on the title page and the subsequent page counts as page 1\n\t\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}% Defines a new command for horizontal lines, change thickness here\n\t\n\t\\center % Centre everything on the page\n\t\n\t%------------------------------------------------\n\t%\tHeadings\n\t%------------------------------------------------\n\t\n\t\\textsc{\\Large Basic orthogonal and periodic functions}\\\\[0.5cm] % Major heading such as course name\n\t\n\t\\textsc{\\large Exercise 3}\\\\[0.5cm] % Minor heading such as course title\n\t\n\t%------------------------------------------------\n\t%\tTitle\n\t%------------------------------------------------\n\t\n\t\\HRule\\\\[0.6cm]\n\t\n\t{\\huge\\bfseries Least-squares Approximation of cos(2x) and cos(4x) Using Chebyshev Polynomials}\\\\[0.25cm] % Title of your document\n\t\n\t\\HRule\\\\[1.5cm]\n\t\n\t%------------------------------------------------\n\t%\tAuthor(s)\n\t%------------------------------------------------\n\t\n\t\\begin{minipage}{0.4\\textwidth}\n\t\t\\begin{flushleft}\n\t\t\t\\large\n\t\t\t\\textit{Author}\\\\\n\t\t\t\\textsc{Cesare De Cal} % Your name\n\t\t\\end{flushleft}\n\t\\end{minipage}\n\t~\n\t\\begin{minipage}{0.4\\textwidth}\n\t\t\\begin{flushright}\n\t\t\t\\large\n\t\t\t\\textit{Professor}\\\\\n\t\t\t\\textsc{Annie Cuyt}\\\\ % Supervisor's name\n\t\t\t[0.25cm]\n\t\t\t\\textit{Assistant Professor}\\\\\n\t\t\t\\textsc{Ferre Knaepkens} % Supervisor's name\n\n\t\t\\end{flushright}\n\t\\end{minipage}\n\t\t\n\t\\vfill\\vfill\\vfill\n\t\n\t{\\large\\today}\n\t\t\n\t\\vfill\n\t\n\\end{titlepage}\n\n%----------------------------------------------- Introduction ------------------------------------------------------\n\\section{Introduction}\\label{sec:intro}\nThis exercise asks to compute the Chebyshev approximation\n$$t(x)=\\sum^n_{j=0}{a_jT_j(x)}$$\n\nfor the functions $f(x)=\\cos(2x)$ and $f(x)=cos(4x)$ over the interval $[-\\pi,\\pi]$ for $n = 6$ and then plot the original functions with the approximations and draw conclusions on the results.\\\\\n\nAs we've seen in class, Chebyshev polynomials are a set of orthogonal polynomials that can be used to approximate to a least squares fit. For this exercise, I'll first compute the roots of the polynomial (also called Chebyshev nodes), then calculate its coefficients for both the functions. Finally, I'll calculate the y values of the approximation to see how well it approximates the original function. During this process, I'll make sure to choose the correct data points and the correct number of data points to exploit the properties of these basis functions.\n\n%---------------------------------- Tools ---------------------------------------------------------------------------\n\\section{Tools}\nTo solve this problem, I've used MATLAB as requested by the exercise. To make the computation more efficient, I wrote my own function which calculates the Chebyshev polynomial instead of using the built-in MATLAB function $\\code{chebyshevT}$ which was noticeably slower. Writing my own function was just a matter of using the compact closed-form expression for the Chebyshev polynomials:\n\n$$T_i(x)=\\cos{(i\\arccos(x))}$$ \n\nBuilt-in MATLAB functions have been used such as $\\code{cos(x)}$ and $\\code{acos(x)}$ to calculate the cosine and the inverse cosine function. $\\code{linspace(start, end, nrOfPoints)}$ was used to create an array of equidistant points for plotting. The functions $\\code{plot(x, y)}$, $\\code{legend()}$, $\\code{axis([xmin xmax ymin ymax])}$, $\\code{ylabel(label)}$, and $\\code{xlabel(label)}$ were also used for plotting.\n\n\\section{Computation}\nGiven $n=6$, I first calculate the nodes of the Chebyshev polynomial by using the formula:\n\n$$x_j=\\cos \\Big( \\frac{2j-1}{2n}\\pi \\Big), j=1,\\dots,n+1$$\n\nThe resulting zeros are:\n\n$$\n\\begin{bmatrix} \n9.749279121818236e-01\\\\\n7.818314824680298e-01\\\\\n4.338837391175582e-01\\\\\n6.123233995736766e-17\\\\\n-4.338837391175581e-01\\\\\n-7.818314824680295e-01\\\\\n-9.749279121818237e-01\\\\\n\\end{bmatrix}\n$$\n\nLet's first analyze the function $\\cos(2x)$. We've seen in class we can calculate the coefficients with the formula given by:\n\n$$c_j=\\frac{2}{N}\\sum_{k=0}^{n}f(x_j)T_j(x_k)$$\n\nTo better exploit the properties of Chebyshev polynomials, I rescale the interval from $[-\\pi,\\pi]$ to $[-1,1]$. This is done in the function calculation $f(x_j)$ by multiplying the argument by $\\pi$. I find the following coefficients:\n\n$$\n\\begin{bmatrix} \n4.407675118300712e-01\\\\\n3.489272363107635e-16\\\\\n5.739892333362830e-01\\\\\n-2.537652627714643e-16\\\\\n6.516380108719009e-01\\\\\n-1.554312234475219e-15\\\\\n-7.019674665493458e-01\\\\\n\\end{bmatrix}\n$$\n\nThe polynomial for the first function $\\cos{2x}$ looks like this:\n\n\\begin{equation}\n  \\begin{array}{l}\n    t(x) = 4.407675118300712e-01 \\times T_0(x)+ 3.489272363107635e-16 \\times T_1(x) + \\\\ \n    5.739892333362830e-01 \\times T_2(x) + \\dots -7.019674665493458e-01 \\times T_6(x)\n  \\end{array}\n\\end{equation}\n\nTo plot these coefficients in the graph, I need to calculate their associated y values:\n\n$$\n\\begin{bmatrix}\n9.876173836808355e-01\\\\\n1.986723718905843e-01\\\\\n-9.149466098687946e-01\\\\\n9.999999999999993e-01\\\\\n-9.149466098687926e-01\\\\\n1.986723718905768e-01\\\\\n9.876173836808371e-01\\\\\n\\end{bmatrix}\n$$\n\nCalculating the coefficients for the $\\cos(4x)$ function now only requires minor changes in the code. The following are the coefficients of the polynomial:\n$$\n\\begin{bmatrix} \n6.879841220704104e-01\\\\\n2.537652627714643e-16\\\\\n-1.535576743556636e-01\\\\\n-1.459150260935920e-15\\\\\n1.012919200612446e+00\\\\\n-1.094362695701940e-15\\\\\n5.104689360033142e-01\n\\end{bmatrix}\n$$\n\nThe polynomial for the second function $\\cos{4x}$ looks like this:\n\n\\begin{equation}\n  \\begin{array}{l}\n    t(x) = 6.879841220704104e-01 \\times T_0(x) + 2.537652627714643e-16 \\times T_1(x) \\\\ \n    -1.535576743556636e-01 \\times T_2(x) + \\dots + 5.104689360033142e-01 \\times T_6(x)\n  \\end{array}\n\\end{equation}\n\nThe associated y values for the given roots are the following:\n\n$$\n\\begin{bmatrix} \n9.507761930971577e-01\\\\\n-9.210585772947382e-01\\\\\n6.742545978208001e-01\\\\\n1.000000000000000e+00\\\\\n6.742545978207990e-01\\\\\n-9.210585772947411e-01\\\\\n9.507761930971639e-01\\\\\n\\end{bmatrix}\n$$\n\nIn order to properly calculate the associated y values, I had to subtract half of the first coefficient from the calculation. This is done because the formula I used to calculate the coefficients isn't correct for the first coefficient. The plots for both functions have been added to the next section.\\\\\n\n\\section{Plots}\nFunction $\\cos(2x)$ and $\\cos(4x)$ respectively:\\\\\n\\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{cos2x.jpg}\\\\\n\\includegraphics[width=\\textwidth,height=\\textheight,keepaspectratio]{cos4x.jpg}\n\\section{Observations}\nI first calculated the zeros of the polynomial so I could use them as nodes in polynomial interpolation because the resulting interpolation polynomial minimizes the effect of Runge's phenomenon. The functions, however, still display a little bit of Runge's phenomenon. \\\\\n\nThe Chebyshev approximation for the function $\\cos(2x)$ is pretty accurate, whereas the approximation for $\\cos(4x)$ not so much as it doesn't take into account some of the spikes of the original function.\n\n\\end{document}", "meta": {"hexsha": "d8212dfc1c34b13e6f3b3ec96438c93bc71946c5", "size": 8006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Orthogonal Basis Function/Report.tex", "max_stars_repo_name": "csr/MATLAB-Scientific-Programming", "max_stars_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Orthogonal Basis Function/Report.tex", "max_issues_repo_name": "csr/MATLAB-Scientific-Programming", "max_issues_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Orthogonal Basis Function/Report.tex", "max_forks_repo_name": "csr/MATLAB-Scientific-Programming", "max_forks_repo_head_hexsha": "ac2d64ea235d7bee9cf0de8bbe42d06a3986bd5a", "max_forks_repo_licenses": ["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.3909090909, "max_line_length": 563, "alphanum_fraction": 0.6799900075, "num_tokens": 2376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.6048614488531765}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%% DYMOLA INTERFACE  %%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dymola Interface}\nModelica is \"a non-proprietary, object-oriented, equation-based language to conveniently model complex physical systems containing, e.g., mechanical, electrical, electronic, hydraulic,\nthermal, control, electric power or process-oriented subcomponents.\"\\footnote{\\url{http://www.modelica.org}}.  Modelica models (with a file extension of .mo) are built, translated (compiled), and simulated in Dymola (http://www.modelon.com/p-\nroducts/dymola/), which is a commercial modeling and simulation environment based on the Modelica modeling language.\nA standard Modelica example called BouncingBall, which simulates the trajectory of an object falling in one dimension from a height, is shown as an example:\n\\begin{lstlisting}\nmodel BouncingBall\n  parameter Real e=0.7 \"coefficient of restitution\";\n  parameter Real g=9.81 \"gravity acceleration\";\n  parameter Real hstart = 10 \"height of ball at time zero\";\n  parameter Real vstart = 0 \"velocity of ball at time zero\";\n  Real h(start=hstart,fixed=true) \"height of ball\";\n  Real v(start=vstart,fixed=true) \"velocity of ball\";\n  Boolean flying(start=true) \"true, if ball is flying\";\n  Boolean impact;\n  Real v_new;\n  Integer foo;\n\nequation\n  impact = h <= 0.0;\n  foo = if impact then 1 else 2;\n  der(v) = if flying then -g else 0;\n  der(h) = v;\n\n  when {h <= 0.0 and v <= 0.0,impact} then\n    v_new = if edge(impact) then -e*pre(v) else 0;\n    flying = v_new > 0;\n    reinit(v, v_new);\n  end when;\n\n  annotation (uses(Modelica(version=\"3.2.1\")),\n    experiment(StopTime=10, Interval=0.1),\n    __Dymola_experimentSetupOutput);\n\nend BouncingBall;\n\\end{lstlisting}\n\n\\subsubsection{Files}\nWhen a modelica model, e.g., BouncingBall model, is implemented in Dymola, the platform dependent C-code from a Modelica model and the corresponding executable code\n(i.e., by default dymosim.exe on the Windows operating system) are generated for simulation.  After the executable is generated, it may be run multiple times (with Dymola license).\nA separate TEXT file (by default dsin.txt) containing model parameters and initial conditions are also generated as part of the build process.  The RAVEN Dymola interface\nmodifies input parameters by changing copies of this file.  Both the executable and TEXT parameter file (or simulation initialization file) names must be provided to RAVEN. The TEXT parameter file must be of type 'DymolaInitialisation'.  In the case of\nthe BouncingBall model previously mentioned on the Windows operating system, the \\textless Files\\textgreater  specification would look like:\n\\begin{lstlisting}[style=XML]\n<Files>\n  <Input name='dsin.txt' type='DymolaInitialisation'>dsin.txt</Input>\n</Files>\n\\end{lstlisting}\n\nThe Dymola interface can only pass scalar values into the TEXT parameter file. If the user wants to pass vector information to Dymola, he can do so by providing an optional TEXT vector file to Dymola. This file must have the type 'DymolaVectors'. This additional file can then be read by the Dymola model. If vecor data is passed from RAVEN to the Dymola interface and the TEXT vector file is not specified, the interface will display an error and stop the Dymola execution. If the TEXT vector file is specified (and vector data is passed to the interface), the interface will write the datd into the specified file, but also display a warning, saying that the Dymola interface found vector data to be passed and if this data is supposed to go into the simulation initialisation file of type 'DymolaInitialisation' the array must be split into scalars. The \\textless Files\\textgreater specification for the vector data look as follows:\n\\begin{lstlisting}[style=XML]\n<Files>\n  <Input name='timeSeriesData.txt' type='DymolaVectors'>timeSeriesData.txt</Input>\n</Files>\n\\end{lstlisting}\n\n\\subsubsection{Models}\nAn executable (dymosim.exe) and a simulation initialization file (dsin.txt) can be generated after either translating or simulating the\nModelica model (BouncingBall.mo) using the Dymola Graphical User Interface (GUI) or Dymola Application Programming Interface (API)-routines.\nTo generate an executable and a simulation initialization file, use the Dymola API-routines (or Dymola GUI) to translate the model as follows:\n\\lstset{\n    frame=single,\n    breaklines=true,\n    postbreak=\\raisebox{0ex}[0ex][0ex]{\\ensuremath{\\color{red}\\hookrightarrow\\space}}\n}\n\\begin{enumerate}\n\\item Change to the directory containing the .mo file to generate an executable.  In Dymola GUI, this corresponds to File/Change Directory in menus:\n\\begin{lstlisting}\n>> cd(\"C:/msys64/home/KIMJ/projects/raven/framework/CodeInterfaces/Dymola\");\nC:/msys64/home/KIMJ/projects/raven/framework/CodeInterfaces/Dymola\n = true\n\\end{lstlisting}\n\\item Reads the specified file and displays its window.  In Dymola GUI, this corresponds to File/Open in the menus:\n\\begin{lstlisting}\n>> openModel(\"BouncingBall.mo\")\n = true\n\\end{lstlisting}\n\\item Compile the model (with current settings), and create the model executable and the corresponding simulation initialization file.  In Dymola GUI, this corresponds to Translate Model in the menus:\n\\begin{lstlisting}\n>> translateModel(\"BouncingBall\");\n = true\n\\end{lstlisting}\nAt this point the model executable and the simulation initialization file should have been created in the same directory as the original model file.\nAdditionally, they could be created by simulating the model.  The following command corresponds to Simulate in the menus in Dymola GUI:\n\\begin{lstlisting}\n>> simulateModel(\"BouncingBall\", stopTime=10, numberOfIntervals=0, outputInterval=0.1, method=\"dassl\", resultFile=\"BouncingBall\");\n = true\n\\end{lstlisting}\nThe file extension (.mat) is automatically added to a output file (resultFile), e.g., BouncingBall.mat.  If the generated executable code is triggered directly from a\ncommand prompt, the output file is always named as \"dsres.mat\".\n\\end{enumerate}\nThe model executable is specified to RAVEN using the \\textless Models\\textgreater  section of the input file as follows:\n\\begin{lstlisting}[style=XML]\n<Simulation>\n    ...\n  <Models>\n    <Code name=\"BouncingBall\" subType = \"Dymola\">\n      <executable>dymosim.exe</executable>\n    </Code>\n  </Models>\n    ...\n</Simulation>\n\\end{lstlisting}\nRAVEN works best with Comma-Separated Value (CSV) files.  Therefore, the default\n.mat output type needs to be converted to .csv output.\nThe Dymola interface will automatically convert the .mat output to human-readable\nforms, i.e., .csv output, through its implementation of the finalizeCodeOutput function.\n\\\\In order to speed up the reading and conversion of the .mat file, the user can specify\nthe list of variables (in addition to the Time variable) that need to be imported and\nconverted into a csv file minimizing\nthe IO memory usage as much as possible. Within the \\xmlNode{Code} the following\nXML\nnode (in addition ot the \\xmlNode{executable} one) can be inputted:\n\n\\begin{itemize}\n   \\item \\xmlNode{outputVariablesToLoad}, \\xmlDesc{space separated list, optional\n   parameter}, a space separated list of variables that need be exported from the .mat\n   file (in addition to the Time variable). \\default{all the variables in the .mat file}.\n\\end{itemize}\nFor example:\n\\begin{lstlisting}[style=XML]\n<Simulation>\n    ...\n  <Models>\n    <Code name=\"BouncingBall\" subType = \"Dymola\">\n      <executable>dymosim.exe</executable>\n      <outputVariablesToLoad>var1 var2 var3</outputVariablesToLoad>\n    </Code>\n  </Models>\n    ...\n</Simulation>\n\\end{lstlisting}\n", "meta": {"hexsha": "c5c96502f9053e661c670d4874e50be40cda608b", "size": 7613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/code_interfaces/dymola.tex", "max_stars_repo_name": "greenwoodms06/raven", "max_stars_repo_head_hexsha": "f8e789c3c58356cdeab53c057b940d3ee96cd0d6", "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/user_manual/code_interfaces/dymola.tex", "max_issues_repo_name": "greenwoodms06/raven", "max_issues_repo_head_hexsha": "f8e789c3c58356cdeab53c057b940d3ee96cd0d6", "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/user_manual/code_interfaces/dymola.tex", "max_forks_repo_name": "greenwoodms06/raven", "max_forks_repo_head_hexsha": "f8e789c3c58356cdeab53c057b940d3ee96cd0d6", "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": 55.9779411765, "max_line_length": 935, "alphanum_fraction": 0.7608038881, "num_tokens": 1890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6048614473969275}}
{"text": "% JuliaCon Proceedings\n% Template with instructions: https://www.overleaf.com/read/dqjbrhqxjpwq\n\n\\documentclass{juliacon}\n\\setcounter{page}{1}\n\\usepackage{url}\n\\usepackage{amsmath}\n\\usepackage[]{algorithm2e}\n\\newcommand\\EatDot[1]{}\n\n\\begin{document}\n\n\\input{header}\n\n\\maketitle\n\n\\begin{abstract}\n\n\\small{\\texttt{StateSpaceModels.jl}} is an open-source Julia package for modeling, forecasting and simulating time series in a state-space framework. The package represents a straightforward tool that can be useful for a wide range of applications that deal with time series. In addition, it contains features that are not present in related commercial software, such as Monte Carlo simulation and the possibility of setting any user-defined linear model.\n\n\\end{abstract}\n\n\\section{Motivation} \\label{sec:introduction}\n\nState-space modeling is a classical framework in control engineering that represents a system through the definition of input, state, and output variables \\cite{zadeh2008linear}. Input variables are external entities that are inserted into the system and can serve as control inputs or noise. State variables represent unobserved components that evolve through time following a given state equation and also depending on the values of the input variables. Finally, output variables result from the realization of the state plus noise factors and represent the observable outcome of the system. In general, state-space models make use of the Kalman filter \\cite{kalman1960new, welch1995introduction} to obtain predictive estimates for the state.\n\nDue to its comprehensive form and wide range of potential applications, state-space models found a niche in time-series modeling, forecasting, and simulation, representing a flexible framework for time-series analysis with time-varying parameters \\cite{durbin2012time}. The ability to conveniently define the evolution of a time series allows the characterization of stochastic components, such as trend and seasonality, that are non-trivial to model in other frameworks.\n\nThere are several packages focused on state-space models for time-series analysis in other languages, such as \\texttt{KFAS} in R \\cite{kfas} and \\texttt{Statsmodels} in Python \\cite{seabold2010statsmodels}, as well as commercial software such as \\texttt{STAMP} \\cite{koopman2000stamp}. Among related Julia packages, we highlight:\n\\begin{itemize}\n    \\item ~\\texttt{Kalman.jl} \\cite{kalmanjl}, which implements Kalman filtering and smoothing.\n    \\item ~\\texttt{StateSpace.jl} \\cite{statespacejl}, a control-oriented package with several versions of the Kalman filter.\n    \\item ~\\texttt{ControlSystems.jl} \\cite{controlsystemsjl}, a package aimed at control applications with numerous features, including state-space modeling.\n\\end{itemize}\n\nThe contributions brought by these packages notwithstanding, there are currently no state-space model packages aimed at time-series analysis in Julia. Furthermore, some have not been updated for a long time and are not functional in Julia 1.0. Thus, the main objectives of \\texttt{StateSpaceModels.jl} \\cite{statespacemodels} are:\n\n\\begin{enumerate}\n    \\item to fill this gap by implementing a general and intuitive framework in Julia for modeling, estimating, forecasting and simulating time series with state-space models;\n    \\item to provide an open-source package that is capable of performing the same functions as related commercial software such as \\texttt{STAMP} and more;\n    \\item to develop a package for time-series analysis with state-space models that is fully implemented in Julia, contrary to related packages in other languages that depend on C or Fortran \\mbox{routines} \\cite{kfas}.\n\\end{enumerate}\n\nThe remainder of this paper is organized as follows. In Section \\ref{sec:statespace}, the Gaussian state-space framework is introduced. In Section \\ref{sec:modeling}, the procedures for model specification are presented. Section \\ref{sec:estimation} explains the filtering, estimation and smoothing processes. Section \\ref{sec:diagnostics} discusses the available diagnostics to evaluate the model specification and estimation. In Section \\ref{sec:forecasting}, the forecasting and simulation procedures are presented. Section \\ref{sec:applications} contains examples of applications that illustrate the use of the package. Finally, conclusions and future work are provided in Section \\ref{sec:conclusion}.\n\n\\section{Gaussian state-space framework} \\label{sec:statespace}\n\nFor the sake of consistency and readability, we utilize in the package the same notation as \\cite{durbin2012time}. Suppose we have a series of observations $y_{1}, \\dots, y_{n}$. In a state-space framework, it is assumed that the observations depend on a set of unobserved components denominated states, or simply the state, and denoted by $\\alpha_{1}, \\dots, \\alpha_{n}$. The state components often have physical interpretations, such as trend and seasonality in a time-series context or position and speed in a control setting.\n\nThe main idea behind state-space modeling is to define the evolution of the state and its relation with the observed variables. This is done through the following two equations, denoted the observation equation and the state equation, respectively:\n%\n\\begin{align}\n    y_{t} &= Z_{t} \\alpha_{t} + \\varepsilon_{t}, \\hspace{0.08\\columnwidth} \\varepsilon_{t} \\sim N(0, H_{t}), \\label{eq:obs_equation} \\\\\n    \\alpha_{t+1} &= T_{t} \\alpha_{t} + R_{t} \\eta_{t}, \\quad \\eta_{t} \\sim N(0, Q_{t}), \\label{eq:state_equation}\n\\end{align}\n%\n\\noindent where $y_{t}$ is a $p \\times 1$ vector of observations and $\\alpha_{t}$ is an unobserved $m \\times 1$ vector representing the state at instant $t$. Note that the behavior of the system over time is determined by $\\alpha_{t}$ as defined in \\mbox{Eq. \\eqref{eq:state_equation}}, but $\\alpha_{t}$ cannot be directly observed, contrary to $y_{t}$.\n\nMatrices $Z_{t}$, $T_{t}$, and $R_{t}$ are the ones that define how the observations relate to the state and how the state evolves over time, and are generally assumed to be known. The error terms $\\varepsilon_{t}$ and $\\eta_{t}$ are supposed to be serially independent and independent of each other. Finally, $H_{t}$ and $Q_{t}$ are the covariance matrices of the error terms. In this package, it is assumed that $T$, $R$, $H$, and $Q$ are not time-varying, as this is the case for the vast majority of practical applications. Conversely, $Z_{t}$ is allowed to vary over time.\n\nNext, for illustration purposes, we present an example model and show how it can be inserted into the state-space framework. Consider the following model, called the linear trend model:\n%\n\\begin{align}\n    y_{t} &= \\mu_{t} + \\varepsilon_{t}, \\hspace{0.115\\columnwidth} \\varepsilon_{t} \\sim N(0, \\sigma^{2}_{\\varepsilon}), \\label{eq:lineartrend1} \\\\\n    \\mu_{t+1} &= \\mu_{t} + \\nu_{t} + \\xi_{t}, \\quad \\xi_{t} \\sim N(0, \\sigma^{2}_{\\xi}), \\label{eq:lineartrend2} \\\\\n    \\nu_{t+1} &= \\nu_{t} + \\zeta_{t}, \\hspace{0.12\\columnwidth} \\zeta_{t} \\sim N(0, \\sigma^{2}_{\\zeta}), \\label{eq:lineartrend3}\n\\end{align}\n%\n\\noindent where $\\mu_{t}$ represents the trend component and $\\nu_{t}$ the slope component. Note that the we can rewrite this model in the framework of Eq. \\eqref{eq:obs_equation}--\\eqref{eq:state_equation} in the following manner:\n%\n\\begin{align}\n    y_{t} &= \\begin{bmatrix} 1 & 0 \\end{bmatrix} \\alpha_{t} + \\varepsilon_{t}, \\hspace{0.15\\columnwidth} \\varepsilon_{t} \\sim N(0, \\sigma^{2}_{\\varepsilon}), \\\\\n    \\alpha_{t+1} &= \\begin{bmatrix} 1 & 1 \\\\ 0 & 1 \\end{bmatrix} \\alpha_{t} + \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\\!\\eta_{t}, \\quad \\eta_{t} \\sim N \\bigg(\\!\\begin{bmatrix} 0 \\\\ 0 \\end{bmatrix}\\!, \\begin{bmatrix} \\sigma^{2}_{\\xi} & 0 \\\\ 0 & \\sigma^{2}_{\\zeta} \\end{bmatrix}\\!\\bigg).\n\\end{align}\n%\nSimilarly, more complex and sophisticated models can also be modeled in the state-space framework.\n\n\\section{Model specification} \\label{sec:modeling}\n\nModel specification is the step wherein the user defines the state-space model they want to consider. This is done through the creation of a \\texttt{StateSpaceModel} structure that contains the observations $y_{t}$ as well as matrices $Z_{t}$, $T$, and $R$.\n\n\\subsection{Predefined models} \\label{subsec:predefined}\n\nA set of predefined classical models is available, namely the local level model, the linear trend model, the basic structural model, and the structural model with exogenous variables. These models can be conveniently defined by calling a function and providing the observations $y_{t}$. Note that all models automatically extend to the multivariate case.\n\n\\subsubsection{Local level model}\n\nThe local level model consists of a stochastic level component that is defined by a random walk:\n%\n\\begin{align}\n    y_{t} &= \\mu_{t} + \\varepsilon_{t}, \\quad \\varepsilon_{t} \\sim N(0, \\sigma^{2}_\\varepsilon), \\label{eq:locallevel1} \\\\\n    \\mu_{t+1} &= \\mu_{t} + \\xi_{t}, \\quad \\xi_{t} \\sim N(0, \\sigma^{2}_\\xi). \\label{eq:locallevel2}\n\\end{align}\n%\nA local level \\texttt{StateSpaceModel} can be created using:\n%\n\\begin{lstlisting}[language = Julia]\nmodel = local_level(y)\n\\end{lstlisting}\n%\n\\noindent where \\texttt{y} is an observation vector in the univariate case or a matrix in column-wise fashion in the multivariate case, i.e., each column representing a variable and each line representing a time period.\n%\n\n\\subsubsection{Linear trend model}\n\nThe linear trend model consists of a local level model with the addition of a stochastic slope term, as seen in Eq. \\eqref{eq:lineartrend1}--\\eqref{eq:lineartrend3}. A linear trend \\texttt{StateSpaceModel} can be created using:\n%\n\\begin{lstlisting}[language = Julia]\nmodel = linear_trend(y)\n\\end{lstlisting}\n\n\\subsubsection{Structural model}\n\nThe basic structural model consists of three stochastic components: trend, slope, and seasonality, defined in the following manner:\n%\n\\begin{align}\n    y_{t} &= \\mu_{t} + \\gamma_{t} + \\varepsilon_{t}, \\hspace{0.09\\columnwidth} \\varepsilon_{t} \\sim N(0, \\sigma^{2}_\\varepsilon), \\label{eq:structural1} \\\\\n    \\mu_{t+1} &= \\mu_{t} + \\nu_{t} + \\xi_{t}, \\hspace{0.095\\columnwidth} \\xi_{t} \\sim N(0, \\sigma^{2}_\\xi), \\label{eq:structural2} \\\\\n    \\nu_{t+1} &= \\nu_{t} + \\zeta_{t}, \\hspace{0.18\\columnwidth} \\zeta_{t} \\sim N(0, \\sigma^{2}_\\zeta), \\label{eq:structural3} \\\\\n    \\gamma_{t+1} &= \\sum_{j=1}^{s-1} \\gamma_{t+1-j} + \\omega_{t}, \\quad \\omega_{t} \\sim N(0, \\sigma^{2}_\\omega). \\label{eq:structural4}\n\\end{align}\n%\nIn this model, there is a stochastic trend that contains a slope component, similarly to the linear trend model. Furthermore, a stochastic seasonal component is modeled so that its sum over the seasonality period $s$ is equal to zero except for a noise factor. A basic structural \\texttt{StateSpaceModel} can be created using:\n%\n\\begin{lstlisting}[language = Julia]\nmodel = structural(y, s)\n\\end{lstlisting}\n\nAdditionally, a structural model can contain exogenous variables, also known as explanatory variables. Exogenous variables represent external factors that are correlated to the phenomenon in question and can, thus, be used to improve the estimation and forecasting by increasing the available information. This model is identical to \\eqref{eq:structural1}--\\eqref{eq:structural4} except for the observation equation, which has an additional exogenous factor:\n%\n\\begin{align}\n    y_{t} &= \\mu_{t} + \\gamma_{t} + \\theta^{\\top} X_{t} + \\varepsilon_{t}, \\quad \\varepsilon_{t} \\sim N(0, \\sigma^{2}_\\varepsilon) \\label{eq:structural_exogenous}\n\\end{align}\n%\nA structural model with exogenous variables can be created with:\n%\n\\begin{lstlisting}[language = Julia]\nmodel = structural(y, s; X = X)\n\\end{lstlisting}\n%\n\\noindent where \\texttt{X} is a matrix containing the exogenous variables observations in column-wise fashion.\n\n\\subsection{User-defined models}\n\nApart from the well-known predefined models presented in Section \\ref{subsec:predefined}, the package allows the input of any user-defined linear model through the definition of matrices $Z_{t}$, $T$, and $R$ through the following constructor:\n%\n\\begin{lstlisting}[language = Julia]\nmodel = StateSpaceModel{Float64}(y, Z, T, R)\n\\end{lstlisting}\n\nIn the simpler case where $Z_{t}$ is constant, the argument \\texttt{Z} can be input as an \\texttt{Array\\{Float64, 2\\}}. Conversely, if $Z_{t}$ is time-varying, it must be input as an \\texttt{Array\\{Float64, 3\\}} where the third dimension represents the time periods. Any desired float precision can be employed within the model.\n\n\\section{Filtering, estimation, and smoothing} \\label{sec:estimation}\n\nNext, the model needs to be estimated. In this step, values for the covariance matrices $H$ and $Q$, initially assumed to be unknown, are obtained via maximum likelihood estimation \\cite{casella2002statistical}. In order to do that, the Kalman filter needs to be utilized. Additionally, a smoother is applied in order to obtain the so-called smoothed estimates for the state.\n\nAfter specifying the model, the estimation step can be called with the function \\texttt{statespace}:\n%\n\\begin{lstlisting}[language = Julia]\nss = statespace(model; verbose = 1)\n\\end{lstlisting}\n\nIn this step, the Kalman filtering, the maximum likelihood estimation of the fixed parameters, and the smoothing are conducted. The optional argument \\texttt{verbose}, which defaults to 1, specifies the verbosity: 0 for no output, 1 for some progress information, 2 for progress information and summary of the optimization result and 3 for progress information as well as the full optimization log.\n\nAn example of the estimation log with default verbosity can be seen below.\n%\n\\begin{lstlisting}[language = Julia]\njulia> ss = statespace(model)\n==============================================================\n                  StateSpaceModels.jl v0.2.0\n (c) Raphael Saavedra, Guilherme Bodin, and Mario Souto, 2019\n--------------------------------------------------------------\n            Starting state-space model estimation.\n    Initiating maximum likelihood estimation with 3 seeds.\n--------------------------------------------------------------\n             Seed 0 is aimed at degenerate cases.\n--------------------------------------------------------------\n||    seed    |     log-likelihood      |      time (s)     ||\n||       0    |        -16217.4939      |          0.21     ||\n||       1    |         -1350.4763      |          2.65     ||\n||       2    |         -1350.4763      |          4.08     ||\n||       3    |         -1350.4763      |          5.69     ||\n--------------------------------------------------------------\n           Maximum likelihood estimation complete.\n                  Log-likelihood: -1350.4763\n             End of state-space model estimation.\n==============================================================\n\\end{lstlisting}\n\n\\subsection{Filtering}\n\nThe filtering step derives the predictive and filtered states as well as their covariance matrices at every time period via the Kalman filter. The predictive state and its variance are given by\n%\n\\begin{align}\n    a_{t+1} &= \\mathbb{E}[\\alpha_{t+1} | Y_{t}], \\\\\n    P_{t+1} &= \\mathbb{V}[\\alpha_{t+1} | Y_{t}],\n\\end{align}\n%\nwhile the filtered state and its variance are given by\n%\n\\begin{align}\n    a_{t|t} &= \\mathbb{E}[\\alpha_{t} | Y_{t}], \\\\\n    P_{t|t} &= \\mathbb{V}[\\alpha_{t} | Y_{t}],\n\\end{align}\n%\nwhere $Y_{t}$ denotes the set of time periods $y_{1}, \\dots, y_{t}$.\n\nFurthermore, the filter also computes the innovations, or prediction errors, as well as their covariance matrix at every time period:\n%\n\\begin{align}\n    v_{t} &= y_{t} - Z a_{t}, \\\\\n    F_{t} &= \\mathbb{V}[v_{t}].\n\\end{align}\n%\n\nThe package contains an implementation of the standard Kalman filter and the square-root Kalman filter \\cite{durbin2012time}. The latter is a variant which utilizes Cholesky decomposition to ensure that the computed covariance matrices are positive semidefinite, thus avoiding numerical errors.\n\nAdditionally, in order to provide a flexible framework, we allow the utilization of any user-implemented variant of the Kalman filter through an abstract type called \\texttt{AbstractFilter}:\n%\n\\begin{lstlisting}[language = Julia]\nstruct MyKalmanFilter <: AbstractFilter\n\\end{lstlisting}\n\nThe choice of the filter type must be done in the estimation step as follows:\n%\n\\begin{lstlisting}[language = Julia]\nss = statespace(model; filter_type = SquareRootFilter{Float64})\n\\end{lstlisting}\n\nFilters allow any desired float precision. If no \\texttt{filter\\_type} is provided, the standard type \\texttt{KalmanFilter\\{Float64\\}} is utilized as a default option. Further information on Kalman filtering can be found in Chapter 4.3 of \\cite{durbin2012time}.\n\n\\subsection{Estimation}\n\nThe Kalman filter is responsible for deriving estimates for the predictive state and for its covariance matrix at each time period, but it is dependent on the values of the noise covariances $H$ and $Q$. Thus, these constant parameters need to be estimated via maximum likelihood \\cite{casella2002statistical}. The log-likelihood function is given by\n%\n\\begin{align}\n    \\ell(Y_{n}) = -\\frac{np}{2} \\log 2 \\pi - \\frac{1}{2} \\sum_{t=1}^{n} (\\log |F_{t}| + v_{t}^{\\top} F_{t}^{-1} v_{t}),\n\\end{align}\n%\nwhich depends on the innovations and their covariance matrix at each time period. Therefore, at each optimization iteration, the Kalman filter needs to be executed.\n\nThe implemented optimization method \\texttt{RandomSeedsLBFGS} generates random initial values for the parameters and then uses the L-BFGS algorithm \\cite{liu1989limited} to maximize the log-likelihood function via the unconstrained optimization package \\texttt{Optim.jl} \\cite{mogensen2018optim}.\n\nAdditionally, similar to the filtering step, users are able to define any desired optimization method through abstract type \\texttt{AbstractOptimizationMethod}:\n%\n\\begin{lstlisting}[language = Julia]\nstruct MyOptimizationMethod <: AbstractOptimizationMethod\n\\end{lstlisting}\n\nAs with the filter type, the choice of optimization method must be done in the estimation step:\n%\n\\begin{lstlisting}[language = Julia]\nss = statespace(model; optimization_method = RandomSeedsLBFGS())\n\\end{lstlisting}\n\nMore advanced parameters, such as optimizer tolerances and the number of seeds, can be set within the \\texttt{RandomSeedsLBFGS} constructor.\n\n\\subsection{Smoothing}\n\nThe smoothing step is conducted after estimation is complete. It consists in obtaining the so-called smoothed state and its covariance matrix at each time period, i.e.,\n%\n\\begin{align}\n    \\hat{\\alpha}_{t} &= \\mathbb{E}[\\alpha_{t} | Y_{n}], \\\\\n    V_{t} &= \\mathbb{V}[\\alpha_{t} | Y_{n}].\n\\end{align}\n%\nSimilar to the filtering step, the smoothing is conducted through an iterative process. The procedure is done backwards, starting from the final time period $n$. The smoothed state estimates are useful for analyzing the behavior of the state components. Further information on state smoothing can be found on Chapter 4.4 of \\cite{durbin2012time}.\n\n\\subsection{Missing observations}\n\nOne interesting property of the Kalman filter and smoother is their ability to treat missing observations. Suppose we have a time series spanning time periods $t = 1, \\dots, n$, but for some periods $\\tau, \\dots, \\tau^{*}$ we have no observations available. This represents an obstacle for estimating a model in several frameworks. Nonetheless, the Kalman filter and smoother allow the derivation of minimum variance linear unbiased estimates for the missing observations so that a completion of the time series is possible. Conveniently, the only necessary modification in the filtering and smoothing equations is considering $Z_{t} = 0$ for the missing period.\n\nIn the package, this is implemented so that any \\texttt{NaN} values in the observations are considered missing observations and automatically treated in the filtering and smoothing steps. In this way, the estimation is successfully conducted even when the time series of interest is incomplete.\n\nConsider the following simulated time series composed by a growing trend plus a Gaussian noise. Additionally, we remove observations 10 through 20 to treat them as missing:\n%\n\\begin{lstlisting}[language = Julia]\n# Create growing trend series with Gaussian noise\ny = collect(1:0.25:20) + 0.5*randn(77)\n# Remove observations 10 through 20\ny[10:20] .= NaN\n# Specify the state-space model and estimate it\nmodel = linear_trend(y)\nss = statespace(model)\n\\end{lstlisting}\n%\nThe results of the estimation step are presented in Fig. \\ref{fig:missing_observations}. The predictive, filtered, and smoothed state estimates can be accessed in \\texttt{ss.filter.a}, \\texttt{ss.filter.att}, and \\texttt{ss.smoother.alpha}, \\mbox{respectively}. It is clear in Fig. \\ref{fig:missing_observations} that the filter and smoother are able to effectively capture the growing linear trend of the series even in the period where observations are missing.\n%\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{Figures/missing_obs.pdf}\n\t\\caption{Automatic completion of missing observations in the filtering and smoothing.}\n\t\\label{fig:missing_observations}\n\\end{figure}\n\n\\subsection{Estimation outputs}\n\nAt the end of the filtering, estimation, and smoothing routine executed by the \\texttt{statespace} function, a \\texttt{StateSpace} structure is returned. It contains six fields:\n\n\\begin{itemize}\n    \\item ~\\texttt{model}: the previously defined \\texttt{StateSpaceModel}.\n    \\item ~\\texttt{filter}: a \\texttt{FilterOutput} structure representing the result of the Kalman filter. It contains the predictive and filtered states as well as the innovations and their covariance matrices at each time period. Furthermore, there is a flag indicating if steady state was attained and the time period when it was attained.\n    \\item ~\\texttt{smoother}: a \\texttt{SmoothedState} structure representing the result of the smoothing procedure. It contains the smoothed state as well as its covariance matrix at each time period.\n    \\item ~\\texttt{covariance}: a \\texttt{StateSpaceCovariance} structure which contains the covariance matrices of the observation and state noises.\n    \\item ~\\texttt{filter\\_type}: the defined filter type.\n    \\item ~\\texttt{optimization\\_method}: the defined optimization method.\n\\end{itemize}\n\n\\section{Diagnostics} \\label{sec:diagnostics}\n\nAs a way of evaluating the model specification and estimation, the package contains statistical diagnostics that can be conducted over the residuals. The available diagnostics are the Jarque-Bera normality test \\cite{jarque1980efficient}, the Ljung-Box independence test \\cite{box1970distribution}, and an homoscedasticity test \\cite{durbin2012time}. The diagnostics can be run through function \\texttt{diagnostics}.\n\nAn example of the diagnostics log can be seen below.\n%\n\\begin{lstlisting}[language = Julia]\njulia> diagnostics(ss)\n==============================================================\n                    Running diagnostics...\n                Jarque-Bera: p-value = 0.89683\n                  Ljung-Box: p-value = 0.95855\n           Homoscedasticity: p-value = 0.30752\n==============================================================\n\\end{lstlisting}\n\n\\section{Forecasting and Simulation} \\label{sec:forecasting}\n\nFinally, after the model has been estimated, forecasting and Monte Carlo simulation can be conducted. In the case of forecasting, estimates for the future values of the time series are computed along with their probability distributions. Alternatively, it is possible to simulate an arbitrary number of future scenarios of the series, which is useful for a wide range of applications such as stochastic optimization.\n\nThe minimum mean square error forecasts for $y_{t}$ can be obtained by treating future values of $y_{t}$ as missing values. Forecasting is conducted with the function \\texttt{forecast}, which receives a \\texttt{StateSpace} structure coming from the estimation step and the number of time periods ahead to be forecast, and outputs the minimum square error forecasts and the predictive distributions of $y_{t}$ at each time period:\n%\n\\begin{lstlisting}[language = Julia]\npred, dist = forecast(ss, N)\n\\end{lstlisting}\n%\nAlternatively, another powerful tool is the simulation of future scenarios, since these are used as input by several applications, such as certain stochastic optimization models. Performing Monte Carlo simulation in a time-series state-space framework involves sampling several scenarios for the observation and state errors utilizing the estimated variances $H$ and $Q$ at each time period, and then computing the state-space recursions for each scenario.\n\nMonte Carlo simulation can be conducted with the use of the function \\texttt{simulate}, which receives a \\texttt{StateSpace} structure coming from the estimation step, the number of time periods ahead $N$, and the number of scenarios $S$ to be simulated, and outputs an $N \\times S$ matrix of scenarios for $y_{t}$:\n%\n\\begin{lstlisting}[language = Julia]\nscenarios = simulate(ss, N, S)\n\\end{lstlisting}\n\n\\section{Applications} \\label{sec:applications}\n\nIn this section, we present several practical applications which can be addressed via state-space modeling. We utilize \\texttt{StateSpaceModels.jl} to tackle the presented problems and provide the results. Furthermore, for the sake of reproducibility, the code of some of the examples is in the folder \\texttt{examples} in the \\texttt{StateSpaceModels.jl} repository.\n\n\\subsection{Airline passengers}\n\nAs a first example, let us use the classical monthly airline passengers time series. In order to avoid multiplicative effects, we use the well-known approach of taking the log of the series. Fig. \\ref{fig:log_airline_forecast} shows the log-airline passengers time series. We can estimate a structural \\texttt{StateSpaceModel} as follows.\n%\n\\begin{lstlisting}[language = Julia]\n# Load the AirPassengers dataset\nAP = CSV.read(\"AirPassengers.csv\")\n# Take the log of the series\nlogAP = log.(Vector{Float64}(AP[:Passengers]))\n# Specify the state-space model\nmodel = structural(logAP, 12)\n# Estimate the state-space model\nss = statespace(model)\n\\end{lstlisting}\n\nBy estimating a structural model, we can analyzed the individual components of the series, such as trend and seasonality. These components are presented in Fig. \\ref{fig:log_airline_components} and represent dimensions 1 and 3 of the smoothed state, respectively.\n\nWe can also forecast the following two years of the time series by using the \\texttt{forecast} function. The result is displayed in Fig. \\ref{fig:log_airline_forecast}.\n%\n\\begin{lstlisting}[language = Julia]\n# Number of months ahead to be forecast\nN = 24\n# Perform forecasting\npred, dist = forecast(ss, N)\n\\end{lstlisting}\n%\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{Figures/log_airline_forecast.pdf}\n\t\\caption{Log-airline passengers historical data and forecasting.}\n\t\\label{fig:log_airline_forecast}\n\\end{figure}\n%\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{Figures/log_airline_components.pdf}\n\t\\caption{Smoothed trend and seasonal components of the log-airline passengers time series.}\n\t\\label{fig:log_airline_components}\n\\end{figure}\n\n\\subsection{Electricity consumption}\n\nAnother practical example is the study of monthly electricity consumption in a given area. In this example, we will use real data from a Brazilian distribution company. In addition, we will consider a temperature series, which is highly correlated to electricity consumption in Brazil, as an exogenous variable. A similar study using \\texttt{StateSpaceModels.jl} was conducted in \\cite{saavedra2018simulating}.\n\nIn this case, our objective is to simulate a large set of future scenarios that can be used as inputs in a stochastic optimization problem with the goal of obtaining the best contracting strategy for a distribution company. To this end, the function \\texttt{simulate} will be used to perform Monte Carlo simulation. We will also use the square-root Kalman filter for this application.\n%\n\\begin{lstlisting}[language = Julia]\n# Specify the state-space model\nmodel = structural(consumption, 12; X = temperature)\n# Estimate the state-space model\nss = statespace(model; filter_type = SquareRootFilter{Float64})\n# Number of months ahead to be simulated\nN = 24\n# Number of scenarios to be simulated\nS = 1000\n# Perform simulation\nsim = simulate(ss, N, S)\n\\end{lstlisting}\n\nThe time series and the resulting simulation can be seen in Fig. \\ref{fig:energy_simulation}. The future scenarios are graphically represented by their mean, which is identical to the forecast at each time period, as well as the 5\\% and 95\\% quantiles.\n%\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{Figures/energy_simulation.pdf}\n\t\\caption{Monthly energy consumption historical data and simulation of future scenarios.}\n\t\\label{fig:energy_simulation}\n\\end{figure}\n\n\\subsection{Vehicle tracking}\n\nFinally, in order to illustrate one application that does not fall into any of the predefined models, thus requiring a user-defined model, let us consider an example from control theory. More precisely, we are going to use \\texttt{StateSpaceModels.jl} to track a vehicle from noisy sensor data. In this case, $y_t$ is a $2 \\times 1$ observation vector representing the corrupted measurements of the vehicle's position on the two-dimensional plane in instant $t$. Since sensors collect the observations with the presence of additive Gaussian noise, we need to filter the observation in order to obtain a better estimate of the vehicle's position.\n\nThe position and speed in each dimension compose the state of the vehicle. Let us refer to $x_t^{(d)}$ as the position on the axis $d$ and to $\\dot{x}^{(d)}_t$ as the speed on the axis $d$ in instant $t$. Additionally, let $\\eta^{(d)}_t$ be the input drive force on the axis $d$, which acts as state noise. For a single dimension, we can describe the vehicle dynamics as \n\\begin{equation}\n\\begin{aligned}\n    & x_{t+1}^{(d)} = x_t^{(d)} + \\Big( 1 - \\frac{\\rho \\Delta_t}{2} \\Big) \\Delta_t \\dot{x}^{(d)}_t + \\frac{\\Delta^2_t}{2} \\eta_t^{(d)}, \\\\\n    & \\dot{x}^{(d)}_{t+1} = (1 - \\rho) \\dot{x}^{(d)}_{t} + \\Delta_t \\eta^{(d)}_t,\n\\end{aligned}\\label{eq_control}\n\\end{equation}\nwhere $\\Delta_t$ is the time step and $\\rho$ is a known damping effect on speed. \n\nWe can cast the dynamical system (\\ref{eq_control}) as a state-space model in the following manner:\n\\begin{align*} \n    y_t &= \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 \\end{bmatrix} \\alpha_{t+1} + \\varepsilon_t, \\\\\n    \\alpha_{t+1} &= \\begin{bmatrix} 1 & (1 - \\tfrac{\\rho \\Delta_t}{2}) \\Delta_t & 0 & 0 \\\\ 0 & (1 - \\rho) & 0 & 0 \\\\ 0 & 0 & 1 & (1 - \\tfrac{\\rho \\Delta_t}{2}) \\\\ 0 & 0 & 0 & (1 - \\rho) \\end{bmatrix} \\alpha_{t} + \\begin{bmatrix} \\tfrac{\\Delta^2_t}{2} & 0 \\\\ \\Delta_t & 0 \\\\ 0 & \\tfrac{\\Delta^2_t}{2} \\\\ 0 & \\Delta_t \\end{bmatrix} \\eta_{t},\n\\end{align*}\nwhere $\\alpha_t = (x_t^{(1)}, \\dot{x}^{(1)}_{t}, x_t^{(2)}, \\dot{x}^{(2)}_{t})^{\\top}$ and $\\eta_t = (\\eta^{(1)}_t, \\eta^{(2)}_t)^{\\top}$.\n\n\\vspace{0.3cm}\n\nWe can formulate the vehicle tracking problem in the \\texttt{StateSpaceModels.jl} framework as:\n\n\\begin{lstlisting}[language = Julia]\n# State transition matrix\nT = kron(Matrix{Float64}(I, p, p), [1 (1 - ρ * Δ / 2) * Δ; 0 (1 - ρ * Δ)])\n# Input matrix\nR = kron(Matrix{Float64}(I, p, p), [.5 * Δ^2; Δ])\n# Output (measurement) matrix\nZ = kron(Matrix{Float64}(I, p, p), [1 0])\n# User defined model\nmodel = StateSpaceModel{Float64}(y, Z, T, R)\n# Estimate vehicle speed and position\nss = statespace(model)\n\\end{lstlisting}\n\nIn this example, we define the noise variances $H$ and $Q$, generate the noises and simulate a random vehicle trajectory using the state-space equations.\n%\n\\begin{lstlisting}[language = Julia]\n# Generate random actuators\nQ = .5 * Matrix{Float64}(I, q, q)\nη = MvNormal(zeros(q), Q)\n# Generate random measurement noise\nH = 2. * Matrix{Float64}(I, p, p)\nε = MvNormal(zeros(p), H)\n# Simulate vehicle trajectory\nα = Matrix{Float64}(undef, n + 1, m)\ny = Matrix{Float64}(undef, n, p)\nfor t in 1:n\n    y[t, :] = Z * α[t, :] + rand(ε)\n    α[t + 1, :] = T * α[t, :] + R * rand(η)  \nend\n\\end{lstlisting}\n\nAn illustration of the results can be seen in Fig. \\ref{fig:vehicle_tracking}. It can be seen that the measurements are reasonably noisy when compared to the true position. Furthermore, the estimated positions, represented by the smoothed state, effectively estimate the true positions with small inaccuracies. \n%\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{Figures/vehicle_tracking.pdf}\n\t\\caption{Vehicle tracking using a state-space model.}\n\t\\label{fig:vehicle_tracking}\n\\end{figure}\n\n\\section{Conclusion} \\label{sec:conclusion}\n\n\\texttt{StateSpaceModels.jl} is a flexible package for time-series modeling, forecasting, and simulating that is fully implemented in Julia. The package contains an implementation of the Kalman filter and smoother as well as their square-root variants. Additionally, users have the ability to use any implemented filter or optimization method. Missing observations in the form of \\texttt{NaN} values are automatically treated in the filtering and smoothing steps. \n\nBesides comprising several predefined classical models, it is also possible to define any linear model with the \\texttt{StateSpaceModel} constructor. Forecasting and Monte Carlo simulation of future scenarios are also available. Finally, the package documentation contains a manual with straightforward examples that are simple to reproduce.\n\n\\input{bib.tex}\n\n\\end{document}\n", "meta": {"hexsha": "f8d4dce7a875657ae773d141cba3f615e772d186", "size": 33597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "UnofficialJuliaMirrorSnapshots/StateSpaceModels.jl-99342f36-827c-5390-97c9-d7f9ee765c78", "max_stars_repo_head_hexsha": "f04d27cab1dbb1383c0101fcc2d4a718d8f7ee4d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-25T02:41:15.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-25T02:41:15.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "agutieda/StateSpaceModels.jl", "max_issues_repo_head_hexsha": "c5d686eeaf1666d8e66f8eeac51cae9037276296", "max_issues_repo_licenses": ["MIT"], "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/paper.tex", "max_forks_repo_name": "agutieda/StateSpaceModels.jl", "max_forks_repo_head_hexsha": "c5d686eeaf1666d8e66f8eeac51cae9037276296", "max_forks_repo_licenses": ["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.8463114754, "max_line_length": 744, "alphanum_fraction": 0.742536536, "num_tokens": 8585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.6048614419400162}}
{"text": "\\chapter{Neural Networks}\n\\label{cha:neural_networks}\n\\epigraph{In the recent years Neural Networks (NN) have solved more and more\n  tasks that have previously been too difficult or simply too tedious to solve\n  with traditionally coded algorithms. They have been successfully applied to a\n  variety of problems such as pattern recognition, image classification and\n  prediction.  As the NN algorithms learn from data, they seem to be good\n  candidates for finding anomalies without any prior knowledge about the\n  given dataset, as long as it is big enough. By applying online learning\n  algorithms that learn and adapt continuously it should in theory be possible\n  to create an automated, adaptive outlier detection.\\\\ This chapter describes\n  the mechanics of NNs from the ground up. Starting with the widely used\n  \\emph{feedforward networks} (FNN), we go on to \\emph{recurrent neural nets}\n  (RNN). Similar to biological neural networks, they have cyclic connections,\n  and are capable of processing sequences. After that, a special kind of RNN is\n  introduced, that dramatically cuts computational costs and solves some\n  notorious problems that arise during RNN training. In addition to the general\n  difficulty of training NNs, they often rely on hyper-parameters, that are\n  typically set by manually tuning the network.  This chapter is closed with a\n  brief description of hyper-parameter optimization techniques which were used\n  to automate this task.\n}\n\n\\section{Feedforward Neural Networks}\n\\label{sec:feedforward_neural_networks}\n\nThe idea for artificial neural networks is based on the human brain,\nwhich is a highly complex, non-linear, and parallel computer.  Just like the\nbrain, neural networks are constructed from small units that are connected to each other\nwith weights. In analogy to its biological counterpart these units are also\ncalled \\emph{neurons}. Older literature also often refers to them as\n\\emph{perceptrons}.  They are capable of processing and passing on incoming\ninformation.\nTraditional \\emph{feedforward neural networks} (FNN) implement static\ninput-output mappings, which mathematically makes them pure functions of the\ninput signals. Figure \\ref{fig:perceptron} shows a simple schematic of a single\nneuron.  It generally has $n$ inputs $u_j$ and one output.  Each of the inputs\nhas an assigned weight $w_j$, which determines the contribution of a given\ninput to the output.  The output of a neuron will further be referred to as\n\\emph{activation} $y$:\n\\begin{equation}\n  \\label{eq:ffn_eq}\n  y = \\varphi \\left( \\sum_j (w_j u_j) + b  \\right)\n       = \\varphi (\\vec{w} \\cdot \\vt{u} + b).\n\\end{equation}\nThe sum over all the inputs multiplied by their weights can conveniently be\nrepresented by a dot product.  Often a bias term $b$ is included, which can be\ntaken as a measure of how easy it is to activate the neuron.  The function\n$\\varphi$ is called activation function and can have various different forms,\nfrom a simple binary function to an arbitrary (non-linear), monotonically\nincreasing function.  A frequently used activation function in FNNs is the\nsigmoid function\n\\begin{equation}\n  \\sigma (z) = \\frac{1}{1 + e^{-z}},\n\\end{equation}\nwhich is shown in Fig.~\\ref{fig:sigmoid}. To create a \\emph{layer} of neurons\nthey are simply stacked on top of each other:\n\\begin{equation}\n  \\vt{y} = \\varphi (\\wmatr{} \\vt{u} + \\vec{b}).\n\\end{equation}\n\n\\begin{figure}\n  \\begin{minipage}{.42\\textwidth}\n    \\centering\n    \\Perceptron\n    \\vspace{4.5mm}\n    \\caption{Schematic of a neuron [\\cite{Nielsen2015}].\n    The activation function is represented by the circle.}\n    \\label{fig:perceptron}\n  \\end{minipage}\n  \\hspace{.02\\textwidth}\n  \\begin{minipage}{.54\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{sigmoid_tanh.pdf}\n    \\caption{Sigmoid function $\\varphi$. Typically used as an activation function\n    in feedforward neural nets.}\n    \\label{fig:sigmoid}\n  \\end{minipage}\n\\end{figure}\n\nThe final FNN with multiple layers (such as in\nFig.~\\ref{fig:feedforward_network}) is created by feeding the output of one\nlayer to another one until the last layer of the network is reached.  The\n\\emph{universal approximation theorem} [\\cite{uni_approx_theorem}] states the\nability of FNNs to approximate an arbitrary non-linear function $f$\n\\begin{equation}\n   \\vt{d} = f(\\vt{u})\n\\end{equation}\nwith arbitrary precision. This means that given any $\\epsilon > 0$ we can find\nan FNN $F$, such that\n\\begin{equation}\n  ||F(\\Theta, \\vt{u}) - f(\\vt{u})||_2 < \\epsilon\n\\end{equation}\n\nfor all possible inputs $\\vt{u}$. The exact form of the approximation $F$\ndepends on the network architecture, but generally it depends on a set of\nparameters $\\Theta$ called weights (and biases), which represent several layers\nof the FNN.  Of course, the universal approximation theorem does not say\nanything about the practical learnability of a task, which will be discussed in\nSec.~\\ref{sub:gradient_descent}.\n\nEach layer of an FNN can be represented by a matrix, and therefore only has the\ncomputational expressibility of linear functions. This linearity is only broken\nby the activation function. Without the non-linear activation an arbitrary\nnumber of layers would not be more effective than a single one.  Through the\norganization in layers FNNs are able to model not only arbitrary functions but\nalso to separate datasets that are not linearly separable.\nFig.~\\ref{fig:feedforward_network} shows an FNN where the first (input) layer\nrepresents the data that is fed into the network, followed by one or more\nhidden layers, and an output layer.  Hidden layers act as a non-linear\ntransform that distorts the input in such a way that its classes become\nlinearly separable by the output layer.  An interactive explanation of how this\nworks can be found in a blog post by [\\cite{colah_topology}].\n\n\\begin{figure}\n  \\centering\n  \\FeedForwardNet{2}\n  \\caption{Fully connected feedforward neural network with a single hidden\n    layer and two output neurons.}\n  \\label{fig:feedforward_network}\n\\end{figure}\n\nEvery network that has more than two or three hidden layers is typically called\na \\emph{deep neural network}. It is fundamentally not different from the basic\narchitecture of the described feedforward networks but holds the potential of\nmore powerful transformations of the input. The type of neural network that is\nshown in Fig.~\\ref{fig:feedforward_network} is called \\emph{feedforward\nnetwork}, because the input data is entering the network at the input layer and\nthen passed through the network towards the output layer.  Feedforward nets are\noften applied to classification tasks, such as the recognition of a certain\nshape in an image.\n\nThe goal of the machine learning approach is to find a weight configuration\nthat captures the \\emph{essence} of the presented dataset, meaning that it\ngeneralizes well, including over inputs that it has not been trained with.\nThis is typically approached by some variation of Gradient Descent (GD). GD\nalgorithms try to minimize a certain loss or cost function with respect to a\ngiven weight configuration (more detailed description in\nSec.~\\ref{sub:gradient_descent}).  However, the pursued generalization of the\nnetwork is highly dependent on the training dataset. It should ideally include\nthe total variability of possible inputs.  This is very hard to achieve in\npractice and the available datasets are typically split randomly into three\ncategories: \\emph{training}, \\emph{validation}, and \\emph{test} set.  The\ntraining set is used to optimize the network. Its loss is minimized by a GD\nalgorithm. The validation set is used to determine the performance of the\nnetwork on inputs that are not included in the training set.  The optimization\nshould be stopped as soon as the error on the validation set is not decreasing\nany more in order to reduce the risk of overfitting. This is one of many\nregularization methods that are applied in ML in order to achieve a\ngeneralization over previously unseen datapoints. Because the information of\nthe validation set is leaking into the network via the early stopping\ncriterion, a third dataset is needed to evaluate the actual performance and\ngeneralization of the network.  This third set is called the test set.\n\nFeedforward networks outperform conventional algorithms at tasks such as image\nrecognition and other classification and pattern recognition.  They are,\nhowever, not very suitable to model time series, as they cannot model correlations\nof previous inputs. This means that they are not designed for the prediction of\nsequences.  To be able to process sequences and make predictions,\n\\emph{recurrent} weight connections are introduced in\nSec.~\\ref{sec:recurrent_neural_networks}.  Despite the compelling results that\ncan be achieved by FNNs, they have a few drawbacks.  Backpropagation algorithms\ntypically need very large amounts of data to train the network. The gradient\ndescent steps have to be small enough to not jump over the desired minima,\nwhich leads to very long training times.  Additionally the nature of the\ntraining data can lead to biases of the resulting network if it does not\nproperly represent the possible parameter space.  It is hard to infer\nafterwards how the network came to a specific result, as the weight matrices do\nnot represent a traceable way of reasoning or logic.  A trained network is like\na black box, which does not come with an obvious way of determining how or why\na certain classification was made.\n\n\n\\subsection{Convolutional Neural Nets}%\n\\label{sub:convolutional_neural_nets}\n\nA breakthrough in image classification performance was achieved by the\nintroduction of a subtype of FNNs, the \\emph{convolutional neural networks}\n(CNN), which can leverage the spatial structure of the input data.  They\ncombine the concept of filters from signal processing with the ML approach by\nlearning their own filters (often referred to as kernels as well) for feature\ndetection in images.  The convolutional operation of a given filter $F$ and an\nimage $H$ is defined by:\n\\begin{align}\n  G &= H * F \\text{, where}\\\\\n  G[i,j] &= \\sum_{u=-k}^k \\sum_{v=-k}^k H[i-u, j-v]F[u,v]\n\\end{align}\n\nA well known example of a filter for edge detection looks like this:\n\\begin{equation}\n  F = \\begin{bmatrix} \n    -1 & -1 & -1 \\\\ \n    -1 & 8  & -1 \\\\ \n    -1 & -1 & -1  \n  \\end{bmatrix}\n\\end{equation}\n\nApplying it to a (black and white) image $H$\n\\begin{equation}\n  H = \\begin{bmatrix}\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t  1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0\\\\\n\t\\end{bmatrix}\n\\end{equation}\n\nand padding the convoluted image $G$ to obtain the original dimensions results\nin a filtered image $R$, which is zero everywhere except at the location of the\nedge:\n\n\\begin{equation}\n  \\newcommand{\\nan}{-}\n  \\newcommand{\\minus}{\\text{-}}\n\tR = \\begin{bmatrix}\n    \\nan & \\nan & \\nan & \\nan & \\nan & \\nan  & \\nan & \\nan & \\nan\\\\\n    \\nan & 0 & 0 & 0 & 3 & \\minus 3 & 0 & 0 & \\nan\\\\\n    \\nan & 0 & 0 & 0 & 3 & \\minus 3 & 0 & 0 & \\nan\\\\\n    \\nan & 0 & 0 & 0 & 3 & \\minus 3 & 0 & 0 & \\nan\\\\\n    \\nan & 0 & 0 & 0 & 3 & \\minus 3 & 0 & 0 & \\nan\\\\\n    \\nan & \\nan & \\nan & \\nan & \\nan & \\nan  & \\nan & \\nan & \\nan\\\\\n  \\end{bmatrix}\n\\end{equation}\n\nA convolutional layer consists of multiple kernels, which are learned via GD.\nEach kernel can be thought of as a neuron that sees only a small part of the\ninput image at a time and slides over the whole image. Its output therefore\nrepresents the local structure of said part of the image, which makes\na CNN capable of exploiting spatial structures in images (see schematic in\nFig.~\\ref{fig:conv_layer}).  The kernels which are sliding over the input\nimages naturally lead to a translation invariance of the learned patterns\n[\\cite{lecun1995convolutional}]. A pattern that is recognized by a filter in one\nregion of the image can just as well be detected somewhere else, which stands\nin contrast to fully connected layers for which the same pattern in different\nparts of an image looks completely different.  Scale invariance can be achieved\nby using multiple kernels of different size.  Feedforward nets, which are fully\nconnected to the input cannot leverage the spatial information as efficiently.\nAdditionally, CNNs decrease the number of parameters in comparison to a normal\nFNN, which reduces the risk of overfitting and thus leads to a better\ngeneralization of NNs.\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=0.4\\linewidth]{conv_layer.png}\n  \\caption{The 2D input image on the left is transformed into a 3D output\n  volume by applying multiple convolutions to the input [\\cite{conv_layer_wiki}].}\n  \\label{fig:conv_layer}\n\\end{figure}\n\nAn interesting example of a CNN outside the realm of image classification is\nAtomNet [\\cite{dzamba1510atomnet}], which is used to predict bioactivity of\nmolecules for drug discovery by exploiting the local structure of biochemical\ninteractions.\n\n\n\\subsection{Gradient Descent}\n\\label{sub:gradient_descent}\n\nThe most common technique to train neural networks is Gradient Descent.\nIt is based on minimizing a \\emph{loss} (cost or penalty) function $\\mathcal{L}$\n\\begin{equation}\n  \\label{eq:batch_loss}\n  \\mathcal{L}(\\Theta) = \\sum_{\\vt{u} \\in \\mathcal{U}} \n                        ||F(\\Theta, \\vt{u}) - \\vt{d}||_2,\n\\end{equation}\nwhich defines how close the network is to producing the\ndesired results.  The loss function that is used throughout this thesis is\ngiven by Eq.~\\ref{eq:batch_loss}, where the target outputs, given a certain\ninput $\\vec{u}$ out of all training examples $\\mathcal{U}$, are denoted by\n$\\vt{d}$.  \n\nInitially, the weights of the network are set randomly and are to be adjusted\nin the optimization phase, also called learning or training.  The loss is, of\ncourse, dependent on all the weights and biases, which is where the gradient\ndescent comes into play.  The partial derivatives of the loss function are\ntaken with respect to all the weight and biases of the network to find the\ngradient which points in the direction of steepest descent.  With this\ncalculated direction we can step the weights towards the nearest local minimum\nand like that gradually increase the performance of the network.\n\\begin{equation}\n  \\label{eq:gradient_descent}\n  \\Theta' = \\Theta + \\eta \\dd{\\mathcal{L}}{\\Theta}\n\\end{equation}\nThe size of the steps is defined by the \\emph{learning rate} $\\eta$, which has\nto be chosen carefully.  If it is too large, the algorithm will oscillate\naround the desired minimum, but if chosen too small, the training times will\nbecome too long.  Several adaptive gradient computation algorithms address this\nissue. One promising algorithm is called \\emph{Adam} (Adaptive Moment\nEstimation). Adam combines adaptive gradient descent methods with\nmomentum based algorithms [\\cite{ADAM}]. Momentum-based optimizers add a fraction\nof the previously used weight update to simulate an acceleration of the\ngradient descent.  The method of applying the gradient descent algorithm to\nmulti-layer (deep) neural networks is called \\emph{backpropagation} (BP),\nbecause the gradient calculation is started at the last layer and iteratively\npropagated back through the whole network by applying the chain rule. A more\ndetailed description of BP is given in Sec.~\\ref{sub:backpropagation}.\n\nThere are three different variations of gradient descent, which only differ in\nthe way the sum in Eq.~\\ref{eq:batch_loss} is interpreted.  Summing over all\navailable training examples $\\vt{u}$, namely the whole \\emph{batch}, is called\n{\\em batch GD}. Calculating the loss only for a single randomly chosen example,\nis called \\emph{stochastic gradient descent} (SGD). The compromise of the two,\nmini-batch GD, uses a subset of the training examples, performs a weight\nupdate, and then goes on to the next mini-batch.  Both stochastic and\nmini-batch GD end up calculating an approximate loss $L$ from a subset $U\n\\subset \\mathcal{U}$:\n\\begin{equation}\n  \\mathcal{L}(\\Theta) \\approx L(\\Theta) = \n    \\sum_{\\vt{u} \\in U} ||F(\\Theta, \\vt{u}) - \\vt{d}||_2,\n\\end{equation}\n\nwhich also leads to an approximated gradient. The updates that are performed\nwith the approximate gradient are hoped to enable the optimizer to jump out of\nshallow local minima and saddle points, which is discussed further in the next\nparagraph.\n\n\\subsubsection{Local Minima of the Error Surface}%\n\\label{ssub:local_minima_of_the_error_surface}\n\nAs BP is a gradient-based method, there is no guarantee at all, that the\nalgorithm will find the global minimum of the error surface.  To illustrate\nthis, Fig.~\\ref{fig:error_surface_bgd} depicts a two dimensional error surface\nwith a global and a local minimum.  Depending on where on the surface the\noptimization is started, it ends up in the local or global minimum.  It was\nshown that for linear activation functions, the error surface contains only a\nsingle minimum, the global one, with all other locations of zero gradient being\nsaddle points [\\cite{BALDI}]. Momentum-based optimizers can find the global\nminimum quite efficiently in such cases. However, this cannot be generalized to\nthe practically used NNs that almost exclusively use non-linear activations.\nOptimizers that include momentum like the Adam optimizer can still sometimes\nyield better results, as depicted in Fig.~\\ref{fig:error_surface_bgd}.  The two\nplots both show a two dimensional error surface, where the coordinates $x$ and\n$y$ are regarded as the weights that have to be optimized.  The black, dotted\nlines show different runs with varying initial values of $x$ and $y$.  The left\nplot shows the convergence paths of plain batch GD algorithm as described\nabove, which converges towards the global minimum in three out of five cases.\nAs GD is a purely gradient based method, the path always advances in the\ndirection of steepest descent.  With the more advanced Adam optimizer, the\nglobal minimum is found in four out of five cases. The momentum towards the\nglobal minimum that is gained in the beginning carries the optimization away\nfrom the local minimum.  Of course there are numerous cases where this approach\nwill not yield a global minimum. Additionally the Adam algorithm is much more\ncomputationally expensive than plain GD and needs more steps, as can be seen\nfrom the denser dots on the black lines.\n\\begin{figure}\n  \\begin{minipage}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{gradient_descent.pdf}\n    GD\n  \\end{minipage}\n  \\hspace{.02\\textwidth}\n  \\begin{minipage}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{adam.pdf}\n    Adam\n  \\end{minipage}\n  \\caption{On the left we can see a plain GD optimizer while on the right the\n    Adam optimizer was used.  Depending on the starting values of the two\n    variables, there are cases in which the optimization ends in the local\n    minimum on the right. The GD optimizer needs fewer steps, while Adam finds\n    the global minimum in one more case.}\n  \\label{fig:error_surface_bgd}\n\\end{figure}\n\n\\begin{figure}\n  \\begin{minipage}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{stochastic_gradient_descent.pdf}\n    stochastic GD\n  \\end{minipage}\n  \\hspace{.02\\textwidth}\n  \\begin{minipage}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{stochastic_adam.pdf}\n    stochastic Adam\n  \\end{minipage}\n  \\caption{Convergence paths of stochastic GD algorithms. The noisy paths are\n    due to the approximation of the gradient through mini-batches.}\n  \\label{fig:error_surface_sgd}\n\\end{figure}\nTo date, the most commonly used technique to encourage GD to converge to the\nglobal minimum is mini-batch gradient descent.  Instead of evaluating the\n\\emph{true} loss of the whole training set as indicated by\nEq.~\\ref{eq:batch_loss}, SGD adapts the weights after every mini-batch $X$.\nThis leads to an approximation of the gradient and causes oscillations in the\nconvergence path, which should make it more probable to escape local minima.\nFig.~\\ref{fig:error_surface_sgd} again compares plain GD and Adam, but now with\nthe perturbing effect of evaluating an approximate loss. The number of training\nsteps that have to be taken increase significantly, but plain SGD is able to\nfind the global minimum in four out of five cases. Stochastic Adam almost\nreaches the minimum in all five cases, but seems to get stuck right before\nthe global minimum in the last case.  The conclusion we can draw from the above\nexamples is that care has to be taken with respect to the convergence of NNs.\nDifferent optimizers, gradient descent variations, and initializations can\nyield vastly different results. However, experience has shown that in most\npattern recognition tasks, SGD algorithms can find a local minimum that yields\nsatisfactory performance, even though it is not guaranteed that this minimum is\nglobal.  In most applications, an increase in the network connections is\nsupposed to create paths around suboptimal local minima [\\cite{rumelhart1986}].\nAdditionally, in most applications the training is actually stopped early,\nmeaning at the time the validation error does not decrease further.  This is\ndone because a network that is fitted perfectly to the training data would most\nprobably not generalize well over new inputs.  In most cases it is therefore\nacceptable or even desirable to remain in a \\emph{good} local minimum that\nresults in a good generalization of the network.\n\n\n\\subsection{Backpropagation}%\n\\label{sub:backpropagation}\n\nBackpropagation is the basic algorithm that carries out the GD minimizations\nthat were introduced previously. It was invented in the 1970s but not widely\nused until the paper by~[\\cite{rumelhart1986}], which marks a breakthrough in the\nfield of machine learning.  For an easy to read but in depth description of the\nsubtleties of BP the reader is referred to the book \\emph{Neural Networks and\nDeep Learning} by [\\cite{Nielsen2015}].\n\nFundamentally, BP is nothing more than the application of the chain rule to the\ncost function of a neural network, which can be solved by an \\emph{automatic\ndifferentiation} (AD) algorithm. In fact, BP is a special case of AD called\n\\emph{reverse mode} AD~[\\cite{autodiff}].  To illustrate the BP algorithm we will\nconsider a network with $L$ feedforward layers, where the activations of the\nfirst layer are just the inputs to the network ($\\vec{u} = \\vec{y}_1$) and the\nlast layer contains the network outputs $\\vec{y}_L$. The components $y^j_l$ of\nthe vector $\\vec{y}_l$ that contains all activations of a layer $l$ are\ncalculated based on the previous layer:\n\\begin{equation}\n\\begin{aligned}\n  z^j_l &= \\sum_k w^{jk}_l y^k_{l-1} + b^k_L \\\\\n  y^j_l &= \\varphi(z^k_l) \\label{eq:forward_pass},\n\\end{aligned}\n\\end{equation}\nwhere $\\vec{z}_l$ are called the \\emph{weighted inputs}.  The system above may\nbe altered such that a given activation depends on any \\emph{previous} layer\nactivation, but \\emph{not} on activations of any \\emph{next} layer. This step is\nnamed \\emph{forward pass}.  During the forward pass, all activations are\ncalculated starting from the first layer. The goal of the \\emph{backward pass}\nis to adjust all the weights $w^{jk}_l$ (and biases $b^k_L$) such that the loss $L$\n\\begin{equation}\n  L = \\frac{1}{2}\\sum_k (d^k - y^k_L)^2\n\\end{equation}\nof a single input example $\\vec{u}$ is minimized. BP solves this by iteratively\ncalculating the gradients needed for Eq.~\\ref{eq:gradient_descent} starting\nfrom the last layer.  Before directly calculating the necessary gradients it is\neasier to compute the \\emph{error} $\\delta_L$ of the weighted inputs for each\nunit $j$ of the last layer:\n\\begin{equation}\n  \\delta^j_L = \\dd{L}{z^j_L} = \\frac{1}{2}\\sum_k \\dd{}{z^j_L}(d^k - y^k_L)^2\n             = \\dd{L}{y^j_L}\\dd{y^j_L}{z^j_L}\n             = (d^j - y^j_L) \\varphi'(z^j_L) \\label{eq:delta_last_layer},\n\\end{equation}\nwhere the sum vanishes because $y^k_L$ only depends on $z^j_L$ if $j = k$.\nNow the error of any layer $l$ can be expressed in terms of the error of the\nnext layer $l+1$:\n\\begin{equation}\n  \\delta^j_{l} = \\dd{L}{z^j_l} = \\sum_k \\dd{L}{z^j_{l+1}}\\dd{z^j_{l+1}}{z^j_l}\n  = \\sum_k \\delta^j_{l+1} \\dd{z^j_{l+1}}{z^j_l}\n  = \\sum_k \\delta^j_{l+1} w^{kj}_{l+1} \\varphi'(z^j_l). \\label{eq:delta_other_layer}\n\\end{equation}\n\nThe desired error gradients can be found to be:\n\\begin{equation}\n\\begin{aligned}\n  \\dd{L}{b^j_l} &= \\delta^j_l, \\\\\n  \\dd{L}{w^{jk}_l} &= y^j_{l-1} \\delta^j_l. \\label{eq:error_grads}\n\\end{aligned}\n\\end{equation}\nThey can be used to incrementally update the weights and biases according\nto Eq.~\\ref{eq:gradient_descent}.\n\n\\subsubsection{The Backpropagation Algorithm}%\n\\label{ssub:the_backpropagation_algorithm}\n\n\\begin{enumerate}\n  \\item \\emph{Input}: $\\vec{u}$ is the activation vector of the first layer\n    $\\vec{y}_1$\n  \\item \\emph{Forward pass}: Compute activations $\\vec{y}_l$ for each\n    $l=2,3,...,L$ (Eq.~\\ref{eq:forward_pass})\n  \\item \\emph{Output error}: Compute error $\\delta_L$ of last layer\n    (Eq.~\\ref{eq:delta_last_layer})\n  \\item \\emph{Backpropagate}: Compute $\\delta_{l-1}$ based on error of layer\n    $l$ (Eq.~\\ref{eq:delta_other_layer})\n  \\item \\emph{Output}: Obtain the gradients of the cost function\n    (Eq.~\\ref{eq:error_grads})\n\\end{enumerate}\n", "meta": {"hexsha": "49dbed0fb229d6c16f6ed24321d7cd6702a9d292", "size": 25358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mainmatter/feedforward_nets.tex", "max_stars_repo_name": "nmheim/thesis", "max_stars_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-22T12:17:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-22T12:17:23.000Z", "max_issues_repo_path": "mainmatter/feedforward_nets.tex", "max_issues_repo_name": "nmheim/thesis", "max_issues_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_issues_repo_licenses": ["MIT"], "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/feedforward_nets.tex", "max_forks_repo_name": "nmheim/thesis", "max_forks_repo_head_hexsha": "feafb9f5c7bcf6b6473d3fca844a33dc25dcff0f", "max_forks_repo_licenses": ["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.0698151951, "max_line_length": 88, "alphanum_fraction": 0.760115151, "num_tokens": 6725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.6893056295505783, "lm_q1q2_score": 0.6048496916197835}}
{"text": "\\documentclass[letterpaper,10pt]{article}\n\\usepackage{epsfig,comment,amssymb,listings,amsmath}\n\\setlength{\\parskip}{1.8mm}\n\\setlength{\\parindent}{0mm}\n\\begin{document}\n%\\date{}\n\\title{\\Large \\bf Commutation relations in Fock space}\n\n\\author{\n{\\rm Daniel Tang}\\\\\n}\n\n\\maketitle\n\n% Use the following at camera-ready time to suppress page numbers.\n% Comment it out when you first submit the paper for review.\n%\\thispagestyle{empty}\n\n\\section{Commutation identities}\n%##########################################################\n\n\\begin{equation}\nAB = BA + [A,B]\n\\end{equation}\n\n\\begin{equation}\n[A, BC] = [A,B]C + B[A,C]\n\\end{equation}\n\n\\begin{equation}\n[AB, C] =  A[B,C] + [A,C]B\n\\end{equation}\n\n\\begin{equation}\n[A,B + C] = [A,B] + [A,C]\n\\label{sumcommute}\n\\end{equation}\n\\begin{equation}\n[A,mB] = m[A,B]\n\\end{equation}\nwhere $m$ is a scalar multiplicative constant.\n\\begin{equation}\n[A,B] = -[B,A]\n\\end{equation}\n\n\\begin{equation}\n[ab,AB] = a[b,A]B + [a,A]bB + Aa[b,B] + A[a,B]b\n\\end{equation}\n\\begin{equation}\n = a[b,A]B  + [a,A]Bb + aA[b,B] + A[a,B]b\n\\end{equation}\n\n\\begin{equation}\n[A,B^n] = \\sum_{q=1}^n B^{q-1}[A,B]B^{n-q}\n\\end{equation}\n\n\\begin{equation}\n[A,B^{n+1}] = [A,B]B^n + [A,B^n]B - [[A,B^n],B]\n\\end{equation}\n\n\\begin{multline}\n[[A,C],[B,D]]=[[[A,B],C],D]+[[[B,C],D],A]\n\\\\+[[[C,D],A],B]+[[[D,A],B],C]\n\\end{multline}\n(source Wikipedia \"Commutator\")\n\n\\begin{equation}\n[[A,H],[B,H]]=[[[A,B],H],H]+[[[B,H],H],A]-[[[A,H],B],H]\n\\end{equation}\nso\n\\begin{multline}\n[[^nA,H],[^mB,H]]=[^2[[^{n-1}A,H],[^{m-1}B,H]],H]\n\\\\+[[^{m+1}B,H],[^{n-1}A,H]]-[[[^nA,H],[^{m-1}B,H]],H]\n\\end{multline}\n\n\nIf we define $[^nA,H] = [\\dots [[A,H],H] \\dots ,H]$ to be the $n$-fold commutation:\n\n\\begin{equation}\n[^n AB,H] = \\sum_{m=0}^n {n \\choose m}[^mA,H][^{n-m}B,H]\n\\end{equation}\n\n\\begin{equation}\n[^n ABC,H] = \\sum_{a+b+c = n} \\frac{n!}{a!b!c!}[^aA,H][^bB,H][^cC,H]\n\\end{equation}\n\n\\section{Annihilation and creation operators}\n%##########################################################\n\nBeginning with\n\n\\[\n[a_\\psi,a_\\phi^\\dag] = a_\\psi a_\\phi^\\dag - a_\\phi^\\dag a_\\psi = \n\\begin{cases}\n 1 & \\text{if }\\psi=\\phi \\\\\n 0 & \\text{otherwise} \\\\\n \\end{cases}\n\\]\n\n\n\\section{$a^\\dag$ and $a$ operators}\n%##########################################################\n\n\\begin{equation}\n[a^m, a^\\dag] = ma^{m-1}\n\\end{equation}\n\n\\begin{equation}\n[a,a^{\\dag m}] = ma^{\\dag(m-1)}\n\\end{equation}\nthe above holds for all m, even -ve.\n\\begin{equation}\n[a^-,a^m] = ((a^- + a)^m - a^m)a^-\n\\end{equation}\n\n\\begin{equation}\n[a^n,a^{\\dag m}] = \\sum_{q=1}^{\\min(m,n)} \\frac{m!n!}{q!(m-q)!(n-q)!} a^{\\dag m-q}a^{n-q}\n\\end{equation}\n\n\n\\begin{equation}\n[a^{\\dag p}a^m, a^{\\dag q}a^n] = \na^{\\dag p}[a^m, a^{\\dag q}] a^n - \na^{\\dag q} [a^n, a^{\\dag p}]a^m\n\\end{equation}\n\n\\section{$a^-$ operator}\n%##########################################################\n\nDefine the $a^-$ operator such that\n\\[\na^-a^\\dag = I\n\\]\nwhere $I$ is the identity operator. Given this we can see immediately that $[a^\\dag,a^-a^\\dag] = 0$, so\n\\[\na^\\dag a^-a^\\dag -a^-a^\\dag a^\\dag = [a^\\dag,a^-]a^\\dag = 0\n\\]\nSo, for all states, $S$ other than the ground state,\n\\[\n[a^\\dag,a^-]S = 0\n\\]\nFor the ground state, $\\emptyset$, in order to ensure $[a^\\dag,a^-]\\emptyset = 0$ we define\n\\[\na^\\dag (a^-\\emptyset) = \\emptyset\n\\]\nHowever, such terms as $a^-\\emptyset$ will never arise through annihilation operators as they will always be multipllied by zero.\n\n\\section{$L_{ir}$ operator}\n%##########################################################\n\nChanges $\\lambda_i$ to $(1-r)\\lambda_i$\n\n\\begin{equation}\n[L_{ir}, a_i^\\dag] = 0\n\\end{equation}\n\n\n\\begin{equation}\n[L_{ir}, a_i] = r\\lambda_i L_{ir}\n\\end{equation}\n\n\\begin{equation}\n[L_{ir}, a_i^n] =  L_{ir}(a_i^n - (a_i-r\\lambda_i)^n)\n\\end{equation}\n\n\\section{$g_{ir}$ operator}\n%##########################################################\n\nMultiplies each basis by $(1-r)^{\\Delta_i}$\n\n\\[\ng_{ir}D_0 = 1\n\\]\n\n\\begin{equation}\n[a_i^\\dag, g_{ir}] = ra_i^\\dag g_{ir}\n\\end{equation}\n\n\\begin{equation}\n[a_i, g_{ir}] = \\frac{r(\\lambda - a_i)}{1-r}g_{ir}\n\\end{equation}\nso\n\\begin{equation}\ng_{ir}a_i^{\\dag n} = (1-r)^na_i^{\\dag n}g_{ir}\n\\end{equation}\nand\n\\begin{equation}\n[g_{ir}, a_i^{\\dag n}] = ((1-r)^n - 1)a_i^{\\dag n}g_{ir}\n\\end{equation}\nalso\n\\begin{equation}\ng_{ir}a_i = \\frac{a_i-r\\lambda_i}{1-r}g_{ir}\n\\end{equation}\nso\n\\begin{equation}\ng_{ir}a_i^n = \\left(\\frac{a_i-r\\lambda_i}{1-r}\\right)^ng_{ir}\n\\end{equation}\n\\begin{equation}\ng_{ir}a_i^n = (1-r)^{-n}\\sum_{m=0}^n{n \\choose m} a_i^m(-r\\lambda_i)^{n-m}g_{ir}\n\\end{equation}\n\nand\n\\begin{equation}\n[g_{ir},a_i^n] = \\left((1-r)^{-n}\\sum_{m=0}^n{n \\choose m} a_i^m(-r\\lambda_i)^{n-m} - a_i^n\\right) g_{ir}\n\\end{equation}\nso\n\\begin{equation}\n[g_{ir},a_i^{\\dag n}a_i^m] = \\left((1-r)^{n-m}\\sum_{l=0}^m{m \\choose l} a_i^{\\dag n}a_i^l(-r\\lambda_i)^{m-l} - a_i^{\\dag n}a_i^m\\right) g_{ir}\n\\end{equation}\n\n\\section{$Lg_{ir}$ operator}\n%##########################################################\n\nWe can join the $L$ and $g$ operators into a compound operator that multiplies bases by $(1-r)^\\Delta_i$ and multiplies $\\lambda_i$ by $(1-r)$. It has the properties:\n\n\\begin{equation}\n[Lg_{ir}, a_i^\\dag] = -ra_i^\\dag Lg_{ir}\n\\end{equation}\n\n\n\\begin{equation}\n[Lg_{ir}, a_i] = \\frac{ra_i}{1-r} Lg_{ir}\n\\end{equation}\n\nSo\n\\begin{equation}\nLg_{ir}a_i^{\\dag n}a_i^m = (1-r)^{n-m}a_i^{\\dag n}a_i^mLg_{ir}\n\\end{equation}\nand\n\\begin{equation}\n[Lg_{ir},a_i^{\\dag n}a_i^m] = ((1-r)^{n-m} - 1)a_i^{\\dag n}a_i^mLg_{ir}\n\\end{equation}\n\n\n\n%{\\footnotesize \\bibliographystyle{acm}\n%\\bibliography{sample}}\n\n\n%\\theendnotes\n\n\\end{document}\n", "meta": {"hexsha": "eab2907bab39c3532ef69016448eed82a91371dc", "size": 5532, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/commutation.tex", "max_stars_repo_name": "deselby-research/ProbabilisticABM", "max_stars_repo_head_hexsha": "6c76a9a18e2caafc1ff00ab970d0df4d703f0119", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2019-02-04T15:50:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-09T17:15:15.000Z", "max_issues_repo_path": "doc/commutation.tex", "max_issues_repo_name": "deselby-research/ProbabilisticABM", "max_issues_repo_head_hexsha": "6c76a9a18e2caafc1ff00ab970d0df4d703f0119", "max_issues_repo_licenses": ["MIT"], "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/commutation.tex", "max_forks_repo_name": "deselby-research/ProbabilisticABM", "max_forks_repo_head_hexsha": "6c76a9a18e2caafc1ff00ab970d0df4d703f0119", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-16T10:52:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-25T09:37:20.000Z", "avg_line_length": 22.7654320988, "max_line_length": 166, "alphanum_fraction": 0.5645336226, "num_tokens": 2220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6047299327695164}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 12.1 One-Dimensional Table Look Up, Interpolation, \\hbox{and Differentiation}\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nGiven a table, $(x_i$, $y_i)$, of independent variable values and the\ncorresponding dependent variable values, this subroutine finds the\npoints in the table closest to a given value of the independent\nvariable and uses these points to interpolate for the corresponding\nvalue of the dependent variable.  Error estimates, Hermite\ninterpolation (i.e.\\ using $(x_i$, $y_i$, $y_i^\\prime)$), different\nlook up methods, and the computation of derivative information are\navailable.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NTAB, NDEG, LUP, IOPT}$(\\geq k_1)$\\newline\n[$k_1 \\geq 2$ depends on options used.]\n\n\\item[REAL]  \\ {\\bf X, Y, XT}$(\\geq $NTAB){\\bf , YT}$(\\geq $NTAB){\\bf ,\\newline\nEOPT}$(\\geq k_2$) [$k_2 \\geq 1$ depends on options used .]\n\\end{description}\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SILUP (X, Y, NTAB, XT, YT,\\\\\nNDEG, LUP, IOPT, EOPT)\\\\\n\\end{tabular}}\n\\end{center}\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[X]  [in] Independent variable where value of interpolant is desired.\n\n\\item[Y]  [out] Value of interpolant.\n\n\\item[NTAB]  [in] Number of points in the table, $\\geq \\text{NDEG}+k$,\n  where $k=1$ if NDEG is odd and 2 if NDEG is even, and must be one\n  bigger than this if an error estimate is requested.\n\n\\item[XT()]  [in] Array of independent variable values, XT($i)=x_i$. Must be\nmonotone increasing or monotone decreasing, but this is not checked\nfor. (XT(I$)=$ XT(I+1) is permitted, but has a special meaning, see\nSection~C.) If the $x_i$ are equally spaced one should set LUP (below) to~3,\nand provide $x_1$ in XT(1) and $x_2-x_1$ in XT(2).\n\n\\item[YT()]  [in] Array of dependent variable values. YT($i)=y_i.$\n\n\\item[NDEG]  [in] Nominal degree of the polynomial to be used in the\ninterpolation. Require $0\\leq $ NDEG $\\leq 15.$\n\nFor NDEG $=0$, Y is set to YT($k)$, where $k$ minimizes $|\\text{X} -x_k|.$\n\nFor NDEG odd, Y is the result of standard polynomial interpolation of degree\nNDEG using NDEG + 1 points. The interpolating function is continuous, but\nthe first derivative is usually discontinuous at tabular points.\n\nFor NDEG $>$ 0 and even, Y is obtained from a function that is a linear\ncombination of two polynomials of degree NDEG. This function is a polynomial\nof degree NDEG + 1 using NDEG + 2 points that interpolates all but the two\nouter points. It has a continuous first derivative but the second derivative\nis usually discontinuous at tabular points.\n\nUsually $|error|$ in the interpolant will tend to decrease in a fairly\nregular way for increasing values of NDEG until either errors due to a lack\nof precision in YT, or the inherent instability of high degree polynomial\ninterpolation causes errors to get worse. If one wants a continuous first\nderivative, even values of NDEG $>$ 0 should be used.\n\n\\item[LUP]  [inout] Defines the type of look up method. (Changed only if LUP\n$\\leq 0$ on input.)\n\n\\begin{itemize}\n\\item[$\\leq 0$]  \\ If LUP $=0$, start with a binary search, else do a\nsequential search starting with an index of $-$LUP. On exit, LUP is set to $%\n-k$, where $k$ minimizes $|$X $-$ XT($k)|.$\n\\item[$= 1$]  Binary search. Use this when accesses are not sequential, and\nXT values are not close to being equally spaced.\n\\item[$= 2$]  Start a sequential search with an index $=[1.5+($NTAB$-$1)\n(X $-$ XT(1))/(XT(NTAB) $-$ XT(1))]. Use this when points are almost equally\nspaced and accesses are not sequential.\n\\item[$= 3$]  YT(I) corresponds to XT(1) + (I$-$1)*XT(2), no search is\nrequired to do the look up and XT can have dimension XT(2). This is\nrecommended when the XT values are equally spaced since it takes the least\nspace and should usually be fastest.\n\\item[$= 4$]  Internal information connected with the $x_k$ values used in\nthe last interpolation is reused. (Don't use this value if there is any\nchance for an intervening call to this subroutine.) Only YT should be\nchanged; IOPT is not examined. This option saves time when interpolating\ncomponents after the first of a vector valued function.\n\\end{itemize}\n\n\\item[IOPT()]  [inout] IOPT(1) is used to return a status as follows:\n\n\\begin{itemize}\n\\item[$-$10 ]  \\ An option index is out of range.\n\\item[$-$9 ]  \\ NTAB is outside allowed limits.\n\\item[$-$8 ]  \\ NDEG is outside allowed limits.\n\\item[$-$7 ]  \\  LUP $>$ 3 when program was not ready for it.\n\\item[$-$6 ]  \\ Option 3 (compute derivatives), has requested more than\n15~derivatives.\n\\item[$-$5 ]  \\ LUP = 3, and XT(2) = 0.\n\\item[$-$4 ]  \\ XT(1) = XT(NTAB), and NTAB is not~1.\n\\item[$-$3 ]  \\ Bad points (see option 6) mean only 0 or 1 points were\navailable for interpolation..\n\\item[$-$2 ]  \\ There is only one table entry; the estimated error that was\nrequested was not computed.\n\\item[$-$1 ]  \\ The accuracy requested was not obtained.\n\\item[0 ]  \\ Normal return, no exceptional conditions.\n\\item[1 ]  \\ X was outside the domain of the table, extrapolation used.\n\\item[2 ]  \\ Available table values were so few that this restricted the\ndegree of the polynomial.  A valid error estimate is not returned in this\ncase.\n\\end{itemize}\n\nStarting with IOPT(2) options are specified by integers in the range 0 to~7,\nfollowed in some cases by integers providing argument(s) for the option.\nEach option, with its arguments if any, is followed in IOPT by the next\noption or by a~0.  If an option index is specified more than once,\nonly the last specification is used.\n\n\\begin{itemize}\n\\item[0]  End of the option list; this must always be the last option\nspecified in IOPT.\n\n\\item[1]  An error estimate is to be returned in EOPT(1).\n\n\\item[2]  (Argument: K2) K2 gives the polynomial degree to use when\nextrapolating. The default for K2 is NDEG if NDEG $\\leq $ 2 or if NDEG is\neven, else it is NDEG~$-$~1.\n\n\\item[3]  (Arguments: K3, L3) Save $(k^{th}$ derivative of interpolating\npolynomial$)/k!$ in EOPT(K3+$k-$1) for $k=1$, 2, ..., L3. These values are\nthe coefficients of the polynomial in the monomial basis expanded about X.\nRequire $0\\leq $ L3 $\\leq 15.$\n\n\\item[4]  (Argument K4) The absolute and relative errors expected in YT\nentries are specified in EOPT(K4) and EOPT(K4+1) respectively. The values\nprovided here are used in estimating the error in the interpolation. An\nerror estimate is returned in EOPT(1).\n\n\\item[5]  (Argument K5, L5) Do the interpolation to the accuracy requested\nby the absolute error tolerance specified in EOPT(K5) and the relative error\ntolerance in EOPT(K5+1) respectively. An attempt is made to keep the final\nerror $<$ EOPT(K5) + EOPT(K5+1)\\thinspace ($|$YT($k)|$ + $|$YT($k^{\\prime\n})|)$, where $k$ and $k^{\\prime }$ are indices for table values close to X.\nStandard polynomial interpolation is done, but here NDEG gives the maximal\ndegree polynomial to use in the interpolation. The actual degree used in\ndoing the interpolation is stored in the space for the argument L5. If both\nEOPT's specified are $\\leq $ 0, IOPT(1) is not set to $-$1, and no error\nmessage is generated due to an unsatisfied accuracy request. An error\nestimate is returned in EOPT(1).\n\n\\item[6]  (Argument K6) Do not use point (XT$(k)$, YT($k))$ in the\ninterpolation if YT($k$) = EOPT(K6). This option is useful if one has a table\nwith equally spaced points, but with some bad data points, and may also be\nused by the multiple dimensional interpolation subroutine. Points are\nselected for use in the interpolation as if points flagged with YT($k$) =\nEOPT(K6) were not present.\n\n\\item[7] (Argument K7) YT(K7+$k$) gives the first derivative\ncorresponding to the function value in YT($k$).  These derivatives\nare to be used in doing the interpolation.  One gets a continuous\ninterpolant only for NDEG = 3, 7, 11, and 15; these cases also give a\ncontinuous first derivative in the interpolant.  The interpolating\npolynomial satisfies $p$(XT($k$)) = YT($k$), $p^\\prime $(XT($k$)) =\nYT(K7+$k$) for values of $k$ that give values of XT close to X.\n(Section~D describes how points are selected.) If NDEG is even, a\nvalue of YT($k$) is used without using the corresponding value of\nYT(K7+$k$).\n\n\n\\end{itemize}\n\n\\item[EOPT]  [inout] Array used to return an error estimate and used for\noptions.\n\n\\begin{description}\n\\item[EOPT$(1)$]  [out] contains an estimate of the error in the\ninterpolation if an error estimate has been requested by setting\noption 1, 4 or~5.\n\n\\item[EOPT$(>1)$]  [in or out] for use by options~3--6.\n\\end{description}\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SILUP to DILUP, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nDRSILUP below is a sample program that interpolates in a table of $\\sin\n(x)$ given with a spacing of~0.5 for NDEG = 2 to~10, and obtains an error\nestimate. ODSILUP below gives the results of running DRSILUP on an IBM PC,\nwhich uses IEEE 32~bit floating point arithmetic.\n\nThe user is reminded that polynomial interpolation of high degree is\nhazardous, where ``high\" depends strongly on the kind of data being\ninterpolated. The error estimates provided by the program are usually\ngreater than the actual error, but on any given interpolation may be much\ntoo small. Similarly, the order selected by the program to satisfy a given\nerror criterion will usually do a good job, but will (infrequently) use too\nlow a degree due to an overly optimistic error estimate or an overly\npessimistic conclusion that the corrections are starting to diverge. When\nmany interpolations are going to be done in a table we recommend trying\nseveral degrees at enough points to cover the kinds of functional behavior\nin different areas of the table and examining the error estimates. Then\nlater interpolations can be done using the fixed degree that appears best\nfor the accuracy desired.\n\nIf one has a table with discontinuities, one can set XT(I) = XT(I+1) =\nthe point of the discontinuity. The $x_j$'s that are used in the\ninterpolation will be selected so that all $j$ satisfy $j \\leq $ I, or\n$j \\geq$ I + 1.  If the discontinuity lies between two points, use\noption 6 to define the value at the point of discontinuity.\n\n\\subsection{Functional Description}\n\nThe look up process identifies the point in the table, XT($k)$, nearest to\nthe input value X.  To obtain continuity in the interpolant, remaining\npoints are selected one at a time, keeping the number of points on either\nside of X balanced as long as this is possible.  Thus XT($k)$ and\nXT($k^{\\prime})$, the second entry selected, will bracket X if\nextrapolation is not required.  When NDEG $>0$ is even (and Hermite\ninterpolation is not being used), a linear combination of the polynomials\nof degree NDEG interpolating the left NDEG + 1 and the right NDEG + 1\npoints is used.  (A total of NDEG + 2 points is used.) If it is not\npossible to select $(\\text{NDEG}+2) / 2$ points on either side of X, then\njust NDEG + 1 points are used to obtain a polynomial of degree NDEG as in\nthe odd case.  When extrapolating, the default action is to use standard\npolynomial interpolation of degree $2\\times \\max (1,\\lfloor\n$NDEG$/2\\rfloor )$.  This default can be changed using an option value\nof~2 in IOPT().  Interpolations are done using the Newton divided\ndifference form of the interpolating polynomial as described for\nAlgorithms I (NDEG odd) and IV (NDEG$>0$, even) by Krogh in\n\\cite{Krogh:1970:EAP}.  The derivatives are computed as described for\nAlgorithm V in \\cite{Krogh:1970:EAP}.\n\nDefine $E_{Min}$ by the following:\n\\begin{equation*}\nE_{Min}=E_{Abs}+E_{Rel\\,}(|\\text{YT}(i)|+|\\text{YT}(i^{\\prime })|),\n\\end{equation*}\nwhere $E_{Abs}$ = EOPT(K4) if option~4 is used, and is otherwise~0; $E_{Rel}$\n= EOPT(K4+1) if option~4 is used and is otherwise the smallest positive\nfloating point number that gives a number different from~1 when added to~1;\nand $i$ and $i^{\\prime}$ are the indices for the first two table entries\nselected for use in the interpolation.\n\nThen the error is estimated by\n\n\\begin{equation*}\n\\hspace{-5pt}\\text{error est.}=1.5\\left( |y_c-P_{k+1}|+\n\\frac{|P_k-P_{k-1}|}{32}\\right)+E_{Min},\n\\end{equation*}\nwhere $y_c$ is the value being returned for Y, $P_k$ is the result obtained\nby standard polynomial interpolation of degree $k$, and $k$ is NDEG unless\nthe degree has been reduced because of extrapolation in which case $k$ is\nthe degree actually used. If there are not sufficient points available to\ncompute $P_{k+1}$, then the error estimate is given by~1.5 $%\n|P_k-P_{k-1}|+E_{Min}.$\n\nThe choice of degree for option~5 makes use of the following quantities.\n\\begin{align*}\ne_0 &= |P_0|\\\\\n\\overline{e}_1&=\\max (.75,\\ e_1/(e_1+e_0)\\\\\ne_j &= |P_j - P_{j-1}|,\\quad j = 1,\\ 2,\\ ...\\\\\n\\overline{e}_j&=\\frac 12\\overline{e}_{j-1}+e_j/(e_j+e_{j-1}),\\quad j=2,\n 3,\\ ...\\\\\n\\widehat{e}_j&=\\frac 12e_{j-1}\\overline{e}_{j-1}/j,\\quad j=2,\\ 3,\\ ...\n\\end{align*}\nThe value of $j$ is allowed to increase until either $e_j+e_{j-1}\\leq $\nerror request, or $e_j\\geq \\widehat{e}_j$ for two successive steps with $j>1$%\n. The quantity, $\\overline{e}_j$ indicates the rate of decrease in $e_j$ for\nsuccessive values of $j$. A good rate of decrease in the past causes a\nbetter rate to be required in the future. Also, better convergence is\nrequired as the degree gets larger. The final error estimate is given by~1.5\n$(e_j+.0625e_{j-1})+E_{Min\\text{.}}$ When derivatives are being computed,\nthe error request is decreased by the factor $|(x-x_i)/(x_i-x_{i^{\\prime }})|\n$, where $i$ and $i^{\\prime }$ are the indices for the first two table\nentries selected.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nValues of IOPT$(1) < 0$ ordinarily cause an error message to be printed, and\nthose $< -3$ do not ordinarily result in a return to the user. One can\nchange the action on errors by calling the message/error routine MESS\nof Chapter~19.3 before calling this routine.\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} \\\\\nDILUP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DILUP, DMESS, MESS\\rule[-5pt]{0pt}{8pt}}\\\\\nSILUP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, MESS, SILUP, SMESS}\\\\\n\\end{tabular}\n\nSubroutine designed and written by: Fred T. Krogh, JPL, May~1991.\nHermite interpolation added December~1994.\n\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSILUP}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{silup}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSILUP}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{silup}}\n\\end{document}\n", "meta": {"hexsha": "f027d5d1a424ddaa70f097094b40a942db7ca9db", "size": 14990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch12-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/ch12-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/ch12-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": 45.5623100304, "max_line_length": 98, "alphanum_fraction": 0.7348232155, "num_tokens": 4512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6047299236191694}}
{"text": "\\section{08/24}\nThis course will involve only a few techniques with a variety of applications.\nMany domains, such as Distributed Computing, Networks, etc., all depend on\nrandomized algorithms.\n\nWe will focus on a few techniques that lead to understanding.\n\\begin{enumerate}\n    \\item Union Bound\n    \\item Linearity of Expectation\n    \\item Markov's Inequality\n    \\item Chernoff Bounds\n\\end{enumerate}\nThese four things prove very useful in the design and understanding of\nalgorithms.\n\n\\subsection{Basic Definitions}\n\\begin{definition}{}{}\n    A \\emph{Sample Space} is a set $S$ whose elements consist of \\emph{simple\n    events} (also called \\emph{elementary} events). When $S$ is finite or\n    countably infinite, we say it is a \\emph{Discrete} sample space.\n\\end{definition}\n\n\\begin{definition}{}{}\n    An \\emph{event} in a sample space $S$ is a subset of $S$.\n\\end{definition}\n\n\\begin{definition}{}{}\n    A \\emph{Probability Distribution} on $S$ is a function $\\Pr: 2^S \\to [0, 1]$\n    that satisfies\n    \\begin{enumerate}\n        \\item $\\prob{S} = 1$\n        \\item If $E_1$, $E_2$, $\\dots$ are pairwise disjoint events (i.e., $E_i\n        \\cap E_j = \\emptyset$ for all pairs $i, j$, also called mutually\n        exclusive), ed by some finite or countably infinite set $I$, then\n        \\[\\prob{\\bigcup_{i \\in I} E_i} = \\sum_{i \\in I} \\prob{E_i}\\]\n    \\end{enumerate}\n\\end{definition}\n\n\\subsection{Conditional Probability}\nThe expression $\\prob{E_2 \\given E_1}$ is read ``the probability of $E_2$ given\n$E_1$.'' For example, if we randomly select a person from Texas, we might write\n\\begin{align*}\n    E_1 &= \\hbox{person chosen is in Houston}\\\\\n    E_2 &= \\hbox{person chosen is a UH student}\n\\end{align*}\nin which case $\\prob{E_2 \\given E_1}$ is simply the probability that a randomly\nselected person from Texas is a UH student \\emph{given that they are in\nHouston}.\n\n\\begin{definition}{Conditional Probability}{}\n    The conditional probability $\\prob{E_2 \\given E_1}$ is defined\n\\[\\prob{E_2 \\given E_1} = \\frac{\\prob{E_2 \\cap E_1}}{\\prob{E_1}}\\]\n\\end{definition}\n\nIntuitively, this can be thought of as taking the probability that $E_2$ and\n$E_1$ occur and ``normalizing it'' by dividing by the probability that $E_1$\noccurs. \n\n\\subsection{Independence}\n\\begin{definition}{Independent Events}{}\nTwo events, $E_1$ and $E_2$, are \\emph{independent} if\n\\[\\prob{E_1 \\cap E_2} = \\prob{E_1}\\prob{E_2}\\]\nor, equivalently, if\n\\[\\prob{E_1 \\given E_2} = \\prob{E_1}\\]\n\\end{definition}\nFor example, suppose $C_1$ and $C_2$ are the outcomes of two fair coin tosses.\nThese are independent, since\n\\[\\prob{C_1 = H \\cap C_2 = T} = \\prob{C_1 = H}\\prob{C_2 = T} = \\frac{1}{4}\\]\nIndependence is not always related to physical independence. For example, say we\nare given a fair die and let\n\\begin{align*}\n    E_1 &= \\hbox{roll is even}\\\\\n    E_2 &= \\hbox{roll is less than or equal to 4}\n\\end{align*}\nIn this case, we can enumerate the sample space and explicitly determine\n$\\prob{E_1}$, $\\prob{E_2}$, $\\prob{E_1 \\cap E_2}$, and $\\prob{E_1}\\prob{E_2}$,\nto see if the events are independent:\n\\begin{align*}\n    E_1 &= \\set{2, 4, 6}\\\\\n    E_2 &= \\set{1, 2, 3, 4}\\\\\n    E_1 \\cap E_2 &= \\set{2, 4}\n\\end{align*}\nThen\n\\begin{align*}\n    \\prob{E_1} &= \\frac{3}{6} = \\frac{1}{2}\\\\\n    \\prob{E_2} &= \\frac{4}{6} = \\frac{2}{3}\\\\\n    \\prob{E_1 \\cap E_2} &= \\frac{2}{6} = \\frac{1}{3}\\\\\n    \\prob{E_1}\\prob{E_2} &= \\frac{1}{2} \\cdot \\frac{2}{3} = \\frac{1}{3}\n\\end{align*}\nThus, we see the events are independent. On the other hand, if $E_2$ is the\nevent that the roll is \\emph{strictly less} than 4, we have\n\\begin{align*}\n    E_1 &= \\set{2, 4, 6}\\\\\n    E_2 &= \\set{1, 2, 3}\\\\\n    E_1 \\cap E_2 &= \\set{2}\n\\end{align*}\nThen\n\\begin{align*}\n    \\prob{E_1} &= \\frac{3}{6} = \\frac{1}{2}\\\\\n    \\prob{E_2} &= \\frac{3}{6} = \\frac{1}{2}\\\\\n    \\prob{E_1 \\cap E_2} &= \\frac{1}{6}\\\\\n    \\prob{E_1}\\prob{E_2} &= \\frac{1}{2} \\cdot \\frac{1}{2} = \\frac{1}{4}\n\\end{align*}\nand we see that the events are \\emph{not independent}.\n\n\\subsection{The Inclusion-Exclusion Principle}\n%TODO insert venn diagram\nA basic result in set theory is that\n\\begin{align*}\n    \\card{A \\cup B} &= \\card{A} + \\card{B} - \\card{A \\cap B}\\\\\n    \\card{A \\cup B \\cup C} &= \\card{A} + \\card{B} + \\card{C} - \\card{A \\cap B} - \\card{A \\cap C} - \\card{B \\cap C} + \\card{A \\cap B \\cap C}\n\\end{align*}\nwhich can be generalized to an arbitrary finite union by\n\\[\\bigcup_{i=1}^n A_i = \\sum_{k=1}^n (-1)^{k+1} \\left(\\sum_{1 \\leq i_1 < \\dots < i_k \\leq n} \\card{A_{i_1} \\cap \\cdots \\cap A_{i_k}} \\right)\\]\nor equivalently\n\\[\\card{\\bigcup_{i=1}^n A_i} = \\sum_{\\emptyset \\neq J \\subseteq \\set{1,\\dots,n}}\n(-1)^{\\card{J}+1} \\card{\\bigcap_{j\\in J} A_j}\\]\nThis yields the probability formulas\n\\begin{theorem}{Inclusion-Exclusion Principle}{}\n    For any events $E_1$, $E_2$, \\dots, $E_n$,\n\\begin{align*}\n    \\prob{E_1 \\cup E_2} &= \\prob{E_1} + \\prob{E_2} - \\prob{E_1 \\cap E_2}\\\\\n    \\prob{\\bigcup_{i=1}^n E_i} &= \\sum_{\\emptyset \\neq J \\subseteq \\set{1,\\dots,n}}\n(-1)^{\\card{J}+1} \\prob{\\bigcap_{j\\in J} E_j}\n\\end{align*}\n\\end{theorem}\n\n\\subsection{Union Bound}\n\\begin{theorem}{Union Bound}{}\n    Let $E_1$, $E_2$, \\dots, be any countable set of events. Then\n\\[\\prob{\\bigcup E_i} \\leq \\sum\\prob{E_i}\\]\n\\end{theorem}\nWhile this bound is often not very precise, it is useful in many cases where the\nevents $E_i$ are ``bad'' and we can bound the likelihood of a single $E_i$. This\nallows us to bound the likelihood of \\emph{any} $E_i$. \n\n\\subsection{Conditioning on Multiple Events (Chain Rule)}\nBy repeatedly applying the definition of conditional probability, we have\n\\begin{align*}\\prob{E_1 \\cap E_2 \\cap \\dots \\cap E_n}\n    &= \\prod_{i=1}^n \\prob{E_i \\given E_1 \\cap E_2 \\cap \\dots \\cap E_{i-1}}\\\\\n    &= \\prob{E_1}\\prob{E_2 \\given E_1}\\cdots \\prob{E_n \\given E_1 \\cap E_2 \\cap \\dots \\cap E_{n - 1}}\\\\\n\\end{align*}\n\n\\subsection{Birthday Paradox}\n\\begin{problem}{Birthday Paradox}{}\nSuppose $n$ people are in a room and they have birthdays chosen uniformly at\nrandom from the 365 calendar days. What is the probability that two people share\na birthday?\n\\end{problem}\n\nThe probability that \\emph{no two} people share a birthday can be calculated by\nconsidering the following events:\n\n\\begin{align*}\n    E_1 &= \\hbox{person 1 has a birthday}\\\\\n    E_2 &= \\hbox{person 2 has a different birthday than person 1}\\\\\n    \\phantom{..}&\\vdots\\\\\n    E_i &= \\hbox{person $i$ has a different birthday than people 1 through $i - 1$}\n\\end{align*}\n\nSpecifically, the probability that no two people share a birthday is\n\\begin{align*}\\prob{E_1 \\cap E_2 \\cap \\dots \\cap E_n}\n    &= \\prob{E_1}\\prob{E_2 \\given E_1}\\cdots \\prob{E_n \\given E_1 \\cap E_2 \\cap \\dots \\cap E_{n - 1}}\\\\\n    &= 1 \\times \\left(1 - \\frac{1}{365}\\right) \\times \\left(1 - \\frac{2}{365}\\right) \\times \\cdots \\times \\left(1 - \\frac{365 - n + 1}{365}\\right) \n\\end{align*}\n\nFor what value of $n$ is the above probability less than $\\sfrac{1}{2}$?", "meta": {"hexsha": "3d2b5b36c451c1e030c5a42a3dd4bc27becdb171", "size": 6912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0824.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/0824.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/0824.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": 41.3892215569, "max_line_length": 147, "alphanum_fraction": 0.6616030093, "num_tokens": 2511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.6046672362082599}}
{"text": "\\section{Mathematics components}\n\\comp{const}\n{Output a constant}\n{}{out:float}\nOutputs a constant value.\n\\startparams\nval & float & value to output\\\\\n\\end{tabularx}\n\n\\comp{add}\n{Adds the inputs together}\n{in1:float,in2:float}{$mul1\\times(in1+add1) + mul2\\times(in2+add2)$}\nAdds together the inputs, after they have been processed through\nsome parameters.\n\\startparams\nadd1 & float & added to input 1 before multiplication by mul1\\\\\nadd2 & float & added to input 2 before multiplication by mul2\\\\\nmul1 & float & multiplies $in1+add1$\\\\\nmul2 & float & multiplies $in2+add2$\\\\\n\\end{tabularx}\n\n\\comp{mul}\n{Multiplies the inputs together.}\n{in1:float,in2:float}{$mul1\\times(in1+add1) \\times mul2\\times(in2+add2)$}\nMultiplies together the inputs, after they have been processed through\nsome parameters. Yes, the two multiplies are redundant.\n\\startparams\nadd1 & float & added to input 1 before multiplication by mul1\\\\\nadd2 & float & added to input 2 before multiplication by mul2\\\\\nmul1 & float & multiplies $in1+add1$\\\\\nmul2 & float & multiplies $in2+add2$\\\\\n\\end{tabularx}\n\n\\comp{mul}\n{Clamps the input to a range}\n{in:input}{output clamped to range}\nClamps the output to ensure it is within a given range.\n\\startparams\nmin & float & minimum value\\\\\nmax & float & maximum value\\\\\n\\end{tabularx}\n\n\\clearpage\n\\comp{func}\n{Performs one of a number of functions on the sum of the inputs.}\n{in1:float,in2:float}{$addout+mulout\\times f \\big(mul1(in1+add1)+ mul2(in2+add2)\\big)$}\nTakes the two inputs and processes them through multiply and add\nparameters, puts the result through a function, and then puts the\noutput through another multiply and add stage. If an input is\nnot connected, it is zero. Thus, the output is:\n\\[\np_{addout} + p_{mulout} \\times f\\Big((p_{add1}+in_1)\\times p_{mul1} +\n(p_{add2}+in_2)\\times p_{mul2} \\Big)\n\\]\nFunctions supported include: sine, cosine, gaussian(x+y), x mod y, abs(x+y).\n\\startparams\nadd1 & float & added to input 1 before multiplication by mul1\\\\\nmul1 & float & multiplies $in1+add1$\\\\\nadd2 & float & added to input 2 before multiplication by mul2\\\\\nmul2 & float & multiplies $in2+add2$\\\\\nfunc & enum & function to perform\\\\\nmulout & float & multiplies function output\\\\\naddout & float & added to output\n\\end{tabularx}\n\n\\clearpage\n\\comp{perlin}{Perlin coherent noise generator (input is values or current time)}\n{x:float,y:float}{out:perlin(x+y),zerocrosstrig:int}\nCalculates \n\\[\np_{addout} + p_{mulout} \\times \\operatorname{perlin}\\Big((p_{add1}+in_1)\\times p_{mul1} +\n(p_{add2}+in_2)\\times p_{mul2} \\Big)\n\\]\nwhere \\emph{perlin} is the Perlin noise function with range [-1,1].\nThus, it generates\nsmoothly varying coherent random noise. If neither input is connected, \n$in_1$ is the current time. If the output crosses zero, i.e. the previous\noutput was one side of zero and the new output is the other side, \nthe \\emph{zerocrosstrig} output is set high. This is typically used\nwith no inputs to generate randomly timed events, with \\emph{mul1} set\nto control the frequency.\n\\startparams\noctaves & int & number of octaves in noise function -- the higher, the\nmore ``fractal'' the noise and the ``busier'' it becomes\\\\\npersistence & float & the noise persistence -- how much the amplitudes\ndecrease for each successive octave\\\\\nadd1 & float & added to input 1 (or time if no inputs are connected) \nbefore multiplication by mul1\\\\\nmul1 & float & multiplies $in1+add1$\\\\\nadd2 & float & added to input 2 before multiplication by mul2\\\\\nmul2 & float & multiplies $in2+add2$\\\\\nmulout & float & multiplies function output\\\\\naddout & float & added to output\n\\end{tabularx}\nFor more information on \\emph{octaves} and \\emph{persistence}, and Perlin\nnoise is general, see the documentation for \\texttt{libnoise}.\n", "meta": {"hexsha": "761d8f71fdce62bb82247a561e604b341fe2c73c", "size": 3734, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "music/doc/math.tex", "max_stars_repo_name": "jimfinnis/stumpy2", "max_stars_repo_head_hexsha": "4011e42b7082f847396816b1b5aee46d7ce93b2b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "music/doc/math.tex", "max_issues_repo_name": "jimfinnis/stumpy2", "max_issues_repo_head_hexsha": "4011e42b7082f847396816b1b5aee46d7ce93b2b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-05-18T12:03:16.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-01T19:05:26.000Z", "max_forks_repo_path": "music/doc/math.tex", "max_forks_repo_name": "jimfinnis/stumpy2", "max_forks_repo_head_hexsha": "4011e42b7082f847396816b1b5aee46d7ce93b2b", "max_forks_repo_licenses": ["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.4948453608, "max_line_length": 89, "alphanum_fraction": 0.7431708623, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.6757645944891558, "lm_q1q2_score": 0.604667035026119}}
{"text": "\\chapter[Synchrotron radiation]{Synchrotron radiation}\n\n\\section{Method}\n\nThe spectral distribution of the mean photon number of synchrotron radiation   \n$d\\bar{N}/d\\omega$ produced by an ultrarelativistic electron moving in a \nconstant uniform magnetic field along a trajectory with length $L$ can be \nexpressed by definition in terms of the spectrum of the mean energy loss of \nthe radiation $d\\bar{\\Delta}/d\\omega$  by the following expression \\cite{maier}:\n\n\\begin{equation}\n\\frac{d\\bar{N}}{d\\omega} = \\frac{1}{\\omega}\\frac{d\\bar{\\Delta}}{d\\omega} = \n\\frac{\\sqrt{3}}{2\\pi}\\alpha\\left(\\frac{L\\gamma}{R}\\right)\\frac{1}{\\omega_{c}}\n\\int_{\\omega/\\omega_{c}}^{\\infty}K_{5/3}(\\eta)d\\eta   .\n\\end{equation}\n\nHere:    \n\\begin{eqnarray*}\n\\omega    &  &  \\mbox{photon energy}\\\\   \n\\alpha    &  &  \\mbox{fine structure constant}\\\\   \nR         &  &  \\mbox{instantaneous radius of curvature of the trajectory}\\\\ \nK         &  &  \\mbox{Macdonald function}\\\\ \n\\omega_c  &  &  \\mbox{characteristic energy of synchrotron radiation}\\\\\n\\end{eqnarray*} \n$\\omega_c = 1.5\\beta(\\hbar c/R)\\gamma^3$, $\\hbar$ is the Planck constant, \nand $\\beta = v/c$  is the ratio of the electron velocity $v$  to the speed of \nlight $c$). In the SI system of units: $R(m) = P(GeV/c)/0.3B_{\\bot}(T)$ , \nwhere  $B_{\\bot}$ is the component of magnetic flux density perpendicular to \nthe electron velocity, and $P$  is the electron momentum (for the case \nconsidered $R \\approx const$   along the whole trajectory) . For the \nsimulation of the energy spectrum of synchrotron radiation by the Monte-Carlo \nmethod we need to calculate the integral distribution of the mean number of \nphotons with the energy more than the given one: $\\bar{N}_{>\\omega}$  . \nTransforming  $d\\bar{N}/d\\omega$ by the integral representation of \nthe Macdonald function \\cite{abram}, we have :\n\n\\begin{eqnarray}\n\\bar{N}_{>\\omega}& = &\n\\int_{\\omega}^{\\infty}\\frac{d\\bar{N}}{d\\omega'}d\\omega' \\nonumber\\\\\n& = &\n\\frac{\\sqrt{3}}{2\\pi}\\alpha\\left(\\frac{L\\gamma}{R}\\right)\n\\int_0^{\\infty}\\frac{\\cosh\\left(\\frac{5}{3}t\\right)}{\\cosh^2(t)}\n\\exp\\left[-\\frac{\\omega}{\\omega_c}\\cosh(t)\\right]dt .\n\\end{eqnarray}\n\nThe latter integral is calculated numerically by the quadrature Laguerre \nformula \\cite{korn} . The calculations show that taking into account \nabout 50 roots of \nthe Laguerre polynomials results in an accuracy of the integral estimation \nbetter than $10^{-4}$ [Bag98] . The mean number of synchrotron radiation photons\n$\\bar{N}$  (= $\\bar{N}_{>0}$) produced by an ultrarelativistic electron \nmoving in a constant magnetic field along a trajectory with the length $L$\n  , is given by :\n\n\\begin{eqnarray}\n\\bar{N} = \\bar{N}_{>0}& = & \n\\frac{\\sqrt{3}}{2\\pi}\\alpha\\left(\\frac{L\\gamma}{R}\\right)\n\\int_0^{\\infty}\\frac{\\cosh\\left(\\frac{5}{3}t\\right)}{\\cosh^2(t)}dt \\nonumber\\\\\n& = &\n\\frac{5}{2\\sqrt{3}}\\alpha\\left(\\frac{L\\gamma}{R}\\right) \\approx \n10^{-2}\\left(\\frac{L\\gamma}{R}\\right) .\n\\end{eqnarray}\n\nQualitatively this result can be manipulated using the fact that the mean \nnumber of photons produced along the formation zone length \n$z \\approx R/\\gamma$  is proportional to $\\alpha$  .\n Then for the length $L$ , $\\bar{N} \\approx \\alpha L/(R/\\gamma)$ . Note, that \nfor the ultrarelativistic case $\\gamma\\gg1$   , when $R \\sim \\gamma$ , \n$\\bar{N}$ does not depend on the electron energy but is defined by the \nvalues of $L$ and $B_{\\bot}$ only. The mean energy loss for synchrotron \nradiation $\\bar\\Delta$ , corresponding to a trajectory with the length $L$, \nexperiences the essential relativistic rise instead :\n\n\\begin{equation}\n\\bar{\\Delta} = \\int_0^{\\infty}\\omega\\frac{d\\bar{N}}{d\\omega}d\\omega =\n\\frac{2}{3}\\alpha\\hbar c\\left(\\frac{L\\gamma^2}{R^2}\\right)\\beta\\gamma^2 =   \n\\frac{8\\bar{N}}{15\\sqrt{3}}\\omega_{c} \n\\approx 0.31\\bar{N}\\omega_{c} \\sim \\gamma^2\n\\end{equation}\n\nThe angular distribution of synchrotron radiation produced by ultrarelativistic \nelectron shows the clear 'searchlight' effect. The main number of photons is \nradiated in the angle limit of the order of $1/\\gamma$   around the electron \ntrajectory direction. In the interesting region of $\\gamma > 10^3$ \nthe angular resolution of \nX-ray and gamma detectors usually does not allow us to measure the details \nof the angular distribution of synchrotron radiation. Therefore, the angular \ndistribution is roughly set to be flat in the range $0 - 1/\\gamma$ .\n\n\\section{Simulation of synchrotron radiation}\n\nThe distance $x$ along electron/positron trajectory to the next point of \ncreation of synchrotron radiation \nphoton is simulated according to exponential distribution,\n$exp(-x\\bar{N}/L)$. The energy $\\omega$ of synchrotron radiation photon \nis simulated\naccording the distribution $\\bar{N}_{>\\omega}/\\bar{N}$. The angles $\\theta$ \nand $\\varphi$ counted from the electron trajectory (the electron momentum \nis considered to be parallel to the local z-axis) are rouhgly set to be \ndistributed randomly in the ranges\n$0 - 1/\\gamma$ and $0 - 2\\pi$ respectively\n\n\\section{Status of this document}\n15.10.98 created by V.Grichine\n\n\\begin{thebibliography}{99}\n\n\\bibitem[Abram64]{abram} Edited by M. Abramovwitz and I.A. Stegan.\n{\\em Handbook of Mathemaatical Functions,\n NBS Applied Mathematics Series 55} (1964)\n\n\\bibitem[Bag98]{bag} Bagulya A.V. and Grichine V.M.\n{Bulletin of Lebedev Institute, no.9-10, 7 } (1998)\n\n\\bibitem[Korn61]{korn}G.A. Korn and T.M. Korn. \n{\\em Mathematical Handbook for scientists and \n    engineers, McGRAW-HILL BOOK COMPANY, INC} (1961)\n\n\\bibitem[Maier91]{maier}  R. Maier.\n{\\em Synchrotron Radiation, CERN Report 91-04, 97-115} (1991)\n\n\\end{thebibliography}\n\n\n\n\n", "meta": {"hexsha": "b29e6c19de45a058a6375b3295d5b6f22af063fb", "size": 5604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "geant4/electromagnetic/standard/synch.tex", "max_stars_repo_name": "berghaus/cernlib-docs", "max_stars_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-24T12:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-24T12:30:01.000Z", "max_issues_repo_path": "geant4/electromagnetic/standard/synch.tex", "max_issues_repo_name": "berghaus/cernlib-docs", "max_issues_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "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": "geant4/electromagnetic/standard/synch.tex", "max_forks_repo_name": "berghaus/cernlib-docs", "max_forks_repo_head_hexsha": "76048db0ca60708a16661e8494e1fcaa76a83db7", "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.125984252, "max_line_length": 80, "alphanum_fraction": 0.7166309779, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6045465217584719}}
{"text": "\\section{The Reals}\r\n\\subsection{The Need of the Reals}\r\nWe already have $\\mathbb N, \\mathbb Z, \\mathbb Q$, then why are we introducing the reals?\r\nWhy don't we stop at $\\mathbb Q$?\r\n\\begin{proposition}\r\n    There is no rational $x$ with $x^2=2$.\r\n\\end{proposition}\r\nwe can assume $x$ is positive since $(-x)^2=x^2$.\r\n\\begin{proof}\r\n    Suppose we have some rational $x$ with $x^2=2$, then suppose $x=a/b$ for some positive integers $a,b$.\r\n    So $2b^2=a^2$, but the power of $2$ in the prime factorization of $a^2$ is even but that in $2b^2$ is odd.\r\n    This is a contradiction.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Same argument shows that if $k\\in\\mathbb N$ is $x^2$ for some $x\\in\\mathbb N$, then $k$ is a perfect square.\r\n\\end{remark}\r\n\\begin{proof}[Alternative proof]\r\n    Again suppose that $x=a/b$ where $a,b\\in\\mathbb N$ has $x^2=2$.\r\n    So every $cx+d$ where $c,d\\in\\mathbb Z$ is of the form $e/b$ for some $e\\in\\mathbb Z$.\r\n    So $cx+d>0\\implies cx+d\\ge 1/d$, but then $0<x-1<1$, so $0<(x-1)^n<1/b$ for $n$ large, which is a contradiction since all $(x-1)^n$ is of the form $cx+d$ for some integer $c,d$ using $x^2=2$.\r\n\\end{proof}\r\nHow, in $\\mathbb Q$, could we say $\\mathbb Q$ has a gap?\r\nConsider the set of rationals whose squares are less than 2.\r\nNow all of these rationals are less than $2$, so $2$ is an upper bound.\r\n$1.5,1.42,1.415,\\ldots$ are all upper bounds of this set, but there is no least upper bound.\r\nSo that establishes the notion of there being a ``gap'', which is the thing we try to eliminate in our dream model of $\\mathbb R$.\r\n\\begin{definition}\r\n    The real numbers $\\mathbb R$ is an ordered field with the least upper bound property.\\\\\r\n    Put it into axiom, the reals consists of a set $\\mathbb R$, the binary operations $+,\\times$, elements $1\\neq 0$, and an order $<$ where\\\\\r\n    1. $(\\mathbb R,+,0)$ is an abelian group.\\\\\r\n    2. $(\\mathbb R,\\times,1)$ is an abelian group.\\\\\r\n    3. $\\times$ is distributive over $+$, so $\\forall a,b,c\\in\\mathbb R,a\\times(b+c)=a\\times b+a\\times c$.\\\\\r\n    4. For any $a,b\\in\\mathbb R$, exactly one of $a<b,a=b,a>b$ is true.\r\n    Also $a<b\\land b<c\\implies a<c$.\\\\\r\n    5. $\\forall a,b,c\\in\\mathbb R$, $a<b\\implies a+c<b+c$, $c>0\\implies(a<b\\implies ac<bc)$.\\\\\r\n    6. (Least-upper-bound property) For any nonempty $S\\subset\\mathbb R$ such that it is bounded from above (i.e. $\\exists M\\in\\mathbb R, \\forall x\\in S,x<M$), there is a least upper bound of $S$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. We can already conclude $0<1$ from axioms 1 to 5.\r\n    Indeed, if not, then $1<0$, so $0<-1$, so $0=0(-1)<(-1)(-1)=1$, contradiction.\\\\\r\n    2. We can embed $\\mathbb Q$ into $\\mathbb R$, but the Least-upper-bound property is false in $\\mathbb Q$.\\\\\r\n    3. We do need the ``nonempty'' and ``bounded above'' conditions.\r\n    We need the former to ensure that there is indeed some element in $S$ to talk about order, and we need the latter to ensure that there is at least one upper bound.\\\\\r\n    4. We could constuct $\\mathbb R$ from $\\mathbb Q$ and we can check that axioms 1 to 6 hold.\r\n\\end{remark}\r\nWe write $\\sup S$ to denote the least upper bound of $S$.\r\n\\begin{example}\r\n    1. $S=\\{x\\in\\mathbb R:0\\le x\\le 1\\}$ be the closed interval $[0,1]$.\r\n    $2$ is an upper buond for $S$ since $\\forall x\\in S, x\\le 2$, but $3/4$ is not since $1\\in S$ but $1>3/4$.\r\n    The least upper bound is $1$, since $1$ is an upper bound for $S$ and for every upper bound $s$ of $S$ must be at least $1$ since $1\\in S$.\\\\\r\n    2. $S=\\{x\\in\\mathbb R:0<x<1\\}$ be the open interval $(0,1)$.\r\n    Again, $2$ is an upper bound but $3/4$ is not since $S\\ni 5/6>3/4$.\r\n    The least upper bound is $1$ since $1$ is an upper bound and for any upper bound $s$, if $s<1$ (note that $s<0$), we must have $S\\ni (1+s)/2>s$ which is a contradiction.\\\\\r\n    3. $S=\\{1-1/n:n\\in\\mathbb N\\}$, then $\\sup S=1$, since $1$ is clearly an upper bound and if there is an upper bound $s\\in S$ such that $0<s<1$, then we take a natural number $n>1/(1-s)$, then $1-1/n>1-(1-s)=s$.\r\n\\end{example}\r\nNote that in example 3, we have assumed the following proposition which we shall prove now.\r\n\\begin{proposition}[Axiom of Archimedes]\r\n    $\\forall x\\in\\mathbb R,\\exists n\\in\\mathbb N,n>x$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose not, the $\\mathbb N$ is bounded above, so let $c=\\sup\\mathbb N$, then $c-1$ is not an upper bound of $\\mathbb N$, so $\\exists n\\in\\mathbb N, n>c-1\\implies\\mathbb N\\ni n+1>c$, contradiction.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Let $t\\in\\mathbb R_{>0}$, then there is some $n\\in\\mathbb N$ such that $1/n<t$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Take $n>1/t$.\r\n\\end{proof}\r\nSo the reals do not contain infinity or infinitesimal.\r\n\\begin{remark}\r\n    1. $\\sup X$ might not be in $X$.\r\n    E.g. $\\sup(0,1)=1\\notin(0,1)$\\\\\r\n    2. The least-upper-bound property gives as well the existence of greatest lower bound for bounded-below subsets of $\\mathbb R$.\r\n    Indeed, suppose $S\\neq\\varnothing$ is bounded below, then $-S=\\{-s:s\\in\\mathbb S\\}$ is bounded above, so there is some $x=\\sup-S$.\r\n    Immediately $-x$ would be the greatest lower bound of $S$.\r\n    We denote it by $\\inf S$.\r\n\\end{remark}\r\n\\begin{theorem}\r\n    There is $x\\in\\mathbb R$ such that $x^2=2$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the set $S=\\{r\\in\\mathbb R:r^2<2\\}$ which is nonempty ($1\\in S$) and bounded above ($\\forall s\\in S,s<2$).\r\n    So there is some $c=\\sup S$, also $1\\le c<2$.\\\\\r\n    Consider $c^2$, if $c^2<2$, then for any $0<t<1$, we have $(c+t)^2=c^2+2ct+t^2\\le c^2+5t$, so we choose any $0<t<(2-c^2)/5$, then $(c+t)^2<2$, so $c+t\\in S$ but $c+t>c$, contradicting the assumption that $c$ is an upper bound.\\\\\r\n    If $c^2>2$, then for any $0<t<1$, we have $(c-t)^2=c^2-2ct+t^2\\ge c^2-4t$, so we can choose $t$ such that $0<t<(c^2-2)/4$, therefore $(c-t)^2>2$, thus $c-t$ is an upper bound of $S$ as well, contradicting the fact that $c$ is the least upper bound.\\\\\r\n    Therefore $c^2=2$.\r\n\\end{proof}\r\nSimilarly, for any $x>0,n\\in\\mathbb N$, $\\sqrt[n]{x}$ exists.\r\n\\begin{definition}\r\n    A real $x$ that is not rational is called irrational.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\sqrt 2,\\sqrt 3,\\sqrt 5,3+5\\sqrt 2$ are irrational.\r\n\\end{example}\r\n\\begin{proposition}\r\n    For any $a,b\\in\\mathbb R,a<b,\\exists q\\in\\mathbb Q, a<q<b$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $a<b$ and WLOG $a,b\\ge 0$.\r\n    Choose $n\\in\\mathbb N$ with $1/n<|b-a|=b-a$.\r\n    So we can find $k\\in\\mathbb N$, $k/n\\le a$ and $(k+1)/n>a$.\r\n    Now if $(k+1)/n\\ge b$, then $1/n<|b-a|\\le (k+1)/n-k/n=1/n$, contradiction.\r\n    So $a<(k+1)/n<b$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    For any $a,b\\in\\mathbb R,a<b,\\exists i\\in\\mathbb R\\setminus\\mathbb Q, a<i<b$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $\\exists q\\in\\mathbb Q, a/\\sqrt 2<q<b/\\sqrt 2$, so $i=q\\sqrt 2$ works.\r\n\\end{proof}\r\n\\subsection{Sequences and Their Limits}\r\nWhat does $1+1/2+1/4+1/8+\\ldots=2$ mean?\r\nWhy does $0.33333\\ldots=1/3$?\r\nWhen we come to think about it, we mean that, for example in the first case, $1,1+1/2,1+1/2+1/4,\\ldots$ ``$\\to$'' $2$.\r\nBut what do we mean by that?\r\nWe do not mean that the sequence will be eventually $x$, but can be ``arbitrarily close'' to that.\r\n\\begin{definition}\r\n    The absolute value function $|x|$ is defined by\r\n    $$\\forall x\\in\\mathbb R,|x|=\r\n    \\begin{cases}\r\n        x\\text{, if $x\\ge 0$}\\\\\r\n        -x\\text{, otherwise}\r\n    \\end{cases}$$\r\n\\end{definition}\r\nRegarding absolute value, we also have the triangle inequality\r\n\\begin{proposition}\r\n    $|x-y|\\le|x-z|+|z-y|$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For a sequence $(x_n)$ of reals and $x\\in\\mathbb R$, we say $x_n\\to x$ (as $n\\to\\infty$) or\r\n    $$\\lim_{n\\to\\infty}x_n=x$$\r\n    if $\\forall\\epsilon>0,\\exists N\\in\\mathbb N,\\forall n>N,|x_n-x|<\\epsilon$.\r\n\\end{definition}\r\nSo it means $x_n$ will ``eventually'' go $\\epsilon$-close to $x$.\r\n\\begin{example}\r\n    1. Consider the sequence $1/2,1/2+1/4,1/2+1/4+1/8,\\ldots$, so $x_n=1-1/2^n$ inductively.\r\n    $\\forall\\epsilon>0$, we can choose $N\\in\\mathbb N$ such that $1/N<\\epsilon$, for any $n\\ge N$, $|1-x_n|=|1/2^n|\\le |1/n|\\le 1/N<\\epsilon$, so $x_n\\to 1$.\\\\\r\n    2. Any constant sequence converges to that constant.\r\n    Indeed, for any $\\epsilon>0$, choose $N=1$, so for every $n>N$, the sequence is $c$ hence is $\\epsilon$-close to the constant.\\\\\r\n    3. Consider $x_n=(-1)^n$.\r\n    This sequence does not converge to a limit.\r\n    Suppose it does, then suppose the limit is $c$, then we can choose $\\epsilon=1$, then there is some $N\\in\\mathbb N$, such that $\\forall k>N, |x_n-c|<\\epsilon=1$, but we can choose $n$ such that $2n>N$, but $2=|x_{2n}-x_{2n+1}|\\le |x_{2n}-c|+|x_{2n+1}-c|<2\\epsilon=2$, contradiction.\\\\\r\n    3. Sequence needs not have a closed form, we can take\r\n    $$x_n=\r\n    \\begin{cases}\r\n        1/n\\text{, if $n$ is odd}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Then it is trivial that $x_n\\to 0$.\r\n    $\\forall\\epsilon>0$, we choose $N$ such that $N>1/\\epsilon$, then $\\forall n\\ge N,|x_n-0|\\le 1/N<\\epsilon$.\r\n\\end{example}\r\n\\begin{remark}\r\n    1. If $x_n\\to c$ for some $c$, we say the sequence $(x_n)$ or $(x_n)_{n=1}^\\infty$ is convergent.\r\n    If it is not the case, then we say it is divergent.\r\n    Note that the example $(-1)^n$ shows that a divergent sequence needs not to go to infinity.\\\\\r\n    2. Limits, if exist, are unique.\r\n    If $x_n\\to c$ and $x_n\\to d$, then $c=d$.\r\n    Indeed, if $c\\neq d$, then $|c-d|>0$, so we choose $\\epsilon=|c-d|/2$, so $\\exists N_1\\in\\mathbb N,\\forall n\\ge N, |x_n-c|<\\epsilon,\\exists N_2\\in\\mathbb N,\\forall n\\ge N_2, |x_n-d|<\\epsilon$, so let $N=\\max\\{N_1,N_2\\}$, so $|c-d|=2\\epsilon >|x_N-c|+|x_N-d|\\ge |c-d|$, contradiction.\r\n\\end{remark}\r\nA sequence given in the form $x_1,x_1+x_2,x_1+x_2+x_3,\\ldots$ is called a series.\r\nWe can write\r\n$$\\sum_{n=1}^\\infty x_n$$\r\nfor the series, and the $k^{th}$ term of it is\r\n$$\\sum_{n=1}^k x_n$$\r\nThis is called a partial sum of the series.\r\nIf a series is convergent, one can also write the infinite sum as its limit, so\r\n$$\\sum_{n=1}^\\infty \\frac{1}{2^n}=1$$\r\nWe should not write and cannot write something like ``let $c$ be the limit of $(x_n)$ and blah blah blah'' before ensuring that the sequence does converge since such a number may not exist.\\\\\r\nLimits do behave nicely.\r\n\\begin{example}\r\n    1. If $x_n\\le d$ always, and $x_n\\to c$, then $c\\le d$.\r\n    Indeed, if $c>d$, then we can take $\\epsilon=c-d$, so $|c-x_n|=c-x_n=(c-d)+(d-x_n)\\ge c-d=\\epsilon$, contradiction.\\\\\r\n    2. If $x_n<d$ always, and $x_n\\to c$, then we need not have $c<d$, since we can take for example $x_n=-1/n\\to 0$ and $d=0$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    If $x_n\\to x$, $y_n\\to y$, then $z_n=x_n+y_n\\to x+y$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $\\forall\\epsilon>0$, choose $N_1$ with $\\forall n>N_1, |x_n-x|<\\epsilon/2$ and $N_2$ with $\\forall n>N_2, |y_n-y|<\\epsilon/2$, then choose $N=\\max\\{N_1,N_2\\}$, then $\\forall n>N,|z_n-(x+y)|\\le |x_n-x|+|y_n-y|<2\\epsilon/2=\\epsilon$, so $z_n\\to x+y$.\r\n\\end{proof}\r\nWe say a sequence $x_1,x_2,\\ldots$ is increasing if $x_n\\le x_{n+1}$ for every $n\\in\\mathbb N$.\r\nIt is called bounded above if $\\{x_n:n\\in\\mathbb N\\}$ is bounded above.\r\n\\begin{theorem}\r\n    An incresing sequence that is bounded above is convergent.    \r\n\\end{theorem}\r\nNote that this is false in $\\mathbb Q$.\r\n\\begin{proof}\r\n    Suppose $(x_n)$ is such a sequence.\r\n    We claim that it converges to $c=\\sup\\{x_n:n\\in\\mathbb N\\}$.\r\n    For any $\\epsilon>0$, $c-\\epsilon$ cannot be an upper bound, so there is some $N\\in\\mathbb N$ such that $c\\ge x_N>c-\\epsilon$, then for any $n>N$, $c\\ge x_n\\ge x_N>c-\\epsilon$, so $|c-x_n|<\\epsilon$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. It is equivalent to say that a decreasing sequence (i.e. $x_n\\ge x_{n+1}$ for all $n\\in\\mathbb N$) bounded below is convergent.\r\n    So as a corollary, a bounded monotone sequence is convergent.\\\\\r\n    2. In series, the equivalent form would be that if the partial sums of the series is bounded above and all terms are nonnegative, then it converges by corollary just stated.\r\n\\end{remark}\r\nThere are a few applications of the theorem (and its corollaries).\r\n\\begin{proposition}\r\n    $\\sum_{n=1}^\\infty n^{-1}$ diverges, and $\\sum_{n=1}^\\infty n^{-2}$ converges.\r\n\\end{proposition}\r\nNote that as sequences, neither of the sums has a (nice) closed form.\r\nOur main idea would be doing comparisons with other series whose sums we are more familiar with.\r\n\\begin{proof}\r\n    For the first part of the proposition, choose any partial sum\r\n    $$P=\\sum_{n=1}^k n^{-1}$$\r\n    then consider the least $r$ such that $2^{r}>k$, so\r\n    $$\\sum_{n=1}^{2^{r+1}} \\frac{1}{n}\\ge P+\\sum_{n=2^r}^{2^{r+1}} \\frac{1}{n}\\ge P+\\frac{2^{r}}{2^{r+1}}=P+\\frac{1}{2}$$\r\n    So it is unbounded, hence does not converge.\r\n    For the second part,\r\n    $$\\sum_{n=2^r}^{2^{r+1}-1} \\frac{1}{n^2}\\le \\frac{2^r}{2^{2r}}=\\frac{1}{2^r}\\implies \\sum_{n=1}^\\infty\\frac{1}{n^2}\\le \\sum_{r=0}^\\infty\\frac{1}{2^r}=2$$\r\n    So it is bounded, hence it converges.\r\n\\end{proof}\r\nThe last sum actually tends to $\\pi^2/6$, the proof of this will be covered somewhere else.\\\\\r\nSecondly, decimal expansion.\r\nWhen we are thinking of $0.a_1a_2a_3\\ldots$, how do we know the limit $0.a_1,0.a_1a_2,\\ldots$ always exists?\r\nObviously, we want to analyze the infinite sum\r\n$$\\sum_{n=1}^\\infty \\frac{a_n}{10^n}$$\r\nThis does converge, since\r\n$$\\sum_{n=1}^\\infty \\frac{a_n}{10^n}\\le \\sum_{n=1}^\\infty \\frac{10}{10^n}<\\sum_{k=0}^\\infty\\frac{1}{10^k}<2$$\r\nConversely, given any real number $0<x<1$, we first choose $a_1\\in\\{0,1,\\ldots,9\\}$ such that $a_1/10\\le x<(a_1+1)/10$, and when we have chosen $a_k$, we choose $a_{k+1}\\in\\{0,1,\\ldots,9\\}$ by choosing it to be such that\r\n$$\\sum_{n=1}^k\\frac{a_n}{10^n}+\\frac{a_{k+1}}{10^{k+1}}\\le x <\\sum_{n=1}^k\\frac{a_n}{10^n}+\\frac{a_{k+1}+1}{10^{k+1}}$$\r\nsuch $a_{k+1}$ always exists due to the definitions of $a_1,a_2,\\ldots,a_k$.\r\n\\begin{remark}\r\n    1. The decimal (or binary or other bases) expansion of any rational number is periodic.\r\n    Conversely, a real number whose decimal (or binary or other bases) expansion is periodic is rational.\\\\\r\n    2. Decimal expansion may not be unique (in a way) since $0.500\\ldots =0.499\\ldots$, but this is kind of the only way that this would happen.\r\n\\end{remark}\r\n\\begin{definition}\r\n    We define $e$ to be $1+1/1!+1/2!+1/3!+1/4!+\\cdots$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    $e$ is well defined.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The partial sum is bounded since\r\n    $$\\sum_{i=0}^\\infty\\frac{1}{i!}\\le 1+\\sum_{k=0}^\\infty\\frac{1}{2^k}=3$$\r\n    Also each term is positive, therefore the sequence of partial sums is increasing, hence it converges.\r\n\\end{proof}\r\n\\subsection{Transcendental Numbers}\r\n\\begin{definition}\r\n    A real number $a$ is called algebraic if it is the root of some nonzero polynomial with integer coefficients.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Every rational number is algebraic.\\\\\r\n    2. $\\sqrt[q]{p}+r$ is algebraic for any $p,q,r\\in\\mathbb Q$ (given that it is well-defined).\r\n\\end{example}\r\nHowever, there can be real numbers that is not algebraic.\r\nTo start with, we shall show that $e$ is irrational.\r\n\\begin{proposition}\r\n    $e$ is irrational.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose for the sake of contradiction that $e=p/q$ such that $p\\in\\mathbb Z,q\\in\\mathbb N$.\r\n    Obviously $q>1$.\r\n    So\r\n    $$\\frac{p}{q}=1+\\frac{1}{1!}+\\frac{1}{2!}+\\cdots\\implies p(q-1)!=q!\\left(\\sum_{n=0}^q\\frac{1}{n!}\\right)+\\sum_{n=q+1}^\\infty\\frac{q!}{n!}$$\r\n    Note that the first term in the right hand side is integral, but for the second term,\r\n    $$0<\\sum_{n=q+1}^\\infty\\frac{q!}{n!}=\\frac{1}{q+1}+\\frac{1}{(q+1)(q+2)}+\\cdots\\le\\sum_{k=1}^\\infty\\frac{1}{(q+1)^k}=\\frac{1}{q}<1$$\r\n    Thus the right hand side is not an integer, but the left hand side is.\r\n    This is a contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    If a real number $x$ is not algebraic, we say it is transcendental.\r\n\\end{definition}\r\n$e$ is actually transcendental, but we will not prove it here.\r\nHowever, we will give an example of a transcendental number.\r\n\\begin{proposition}\r\n    Take\r\n    $$c=\\sum_{k=1}^\\infty \\frac{1}{10^{k!}}$$\r\n    then $c$ is transcendental.\r\n\\end{proposition}\r\nIt is trivial that $c$ is well defined.\r\nWe will need the following facts about polynomials.\r\n\\begin{proposition}\r\n    1. For any polynomial $P$, we have some constant $K>0$ such that $|P(x)-P(y)|\\le K|x-y|$ for each $x,y\\in [0,1]$.\\\\\r\n    2. A polynomial of degree $d$ has at most $d$ roots.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1. Suppose $P(x)=\\sum_{i=0}^da_ix^i$, then for $x,y\\in[0,1]$,\r\n    $$|P(x)-P(y)|=\\left|\\sum_{i=1}^da_i(x^i-y^i)\\right|\\le d\\sum_{i=1}^d|a_i||x-y|=K|x-y|,K=d\\sum_{i=1}^d|a_i|$$\r\n    2. Polynomial division.\r\n\\end{proof}\r\nNow we are ready for the proof.\r\n\\begin{proof}[Proof that $c$ is transcendental]\r\n    Suppose for the sake of contradiction that there is some polynomial\r\n    $$P(x)=\\sum_{k=0}^da_kx^k$$\r\n    such that $a_k\\in\\mathbb Z$ and $P(c)=0$.\r\n    Let\r\n    $$c_n=\\sum_{k=1}^n \\frac{1}{10^{k!}}$$\r\n    So $c_n\\to c$.\r\n    Note that $|c_n-c|\\le 2/10^{(n+1)!}$.\r\n    Since $P$ has at most $d$ roots, $\\exists N\\in\\mathbb N,\\forall n>N,P(c_n)\\neq 0$.\r\n    As $P$ has integer coefficients, for $n>N$,\r\n    $$\\frac{1}{10^{n!d}}\\le|P(c_n)|=|P(c_n)-P(c)|\\le K|c_n-c|\\le\\frac{2K}{10^{(n+1)!}}$$\r\n    by the preceding proposition.\r\n    This fails when $n$ is large, contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    We say $x\\in\\mathbb R\\setminus\\mathbb Q$ is a Liouville number if $\\forall n\\in\\mathbb N,\\exists p\\in\\mathbb Z,q\\in\\mathbb N,$\r\n    $$\\left|x-\\frac{p}{q}\\right|<\\frac{1}{q^n}$$\r\n    That is, $x$ has a very good rational approximations.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Every Liouville number is transcendental.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Similar as above.\r\n\\end{proof}\r\n\\begin{remark}\r\n    $e$ is not a Liouville number.\r\n\\end{remark}\r\n", "meta": {"hexsha": "a88fbd444010f99e755df5ab514618fafc9e129f", "size": 17983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/real.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": "4/real.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": "4/real.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": 57.0888888889, "max_line_length": 289, "alphanum_fraction": 0.6394928544, "num_tokens": 6570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975978, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.6045465209206277}}
{"text": "\\section*{Ex.2.2}\n\\subsection*{Size of hash function $h$ output for collision probability is 0}\n\nIf such a function exists, then $m$ must be at least as large as $\\abs{U}$ otherwise you would with probability 1 get a collision if all keys from $U$ was hashed.", "meta": {"hexsha": "846909d1791ee08d4258a3fa175800177b6badfa", "size": 259, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.2.2.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": "Uge3/Ex.2.2.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": "Uge3/Ex.2.2.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": 64.75, "max_line_length": 162, "alphanum_fraction": 0.7451737452, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6045465079684001}}
{"text": "% !TeX root = ../main.tex\n% Add the above to each chapter to make compiling the PDF easier in some editors.\n\n\n\\chapter{Functional B-trees in Isabelle}\\label{chapter:abs-set}\n\nProving higher level properties of data structures\ntends to be easier on a functional level than on an imperative\nlevel.\nThis is mostly due to the fact that many details of implementation\ncan be abstracted away or expressed in a simpler manner.\nThe work therefore begins with a functional specification of B-trees\nin HOL that is not aware of the existence of heaps and uses\npersistent data structures.\n\n\\section{Basic Definitions}\n\\label{sec:basic-defs}\n%Definition used for this implementation.\n%(esp. order)\n%note that k refers to keys+subtrees rather than only keys/subtrees (false! we have k pairs)\n\n% TODO all function equations similar to math equations, setting variables in italics\n\nAs discussed in \\Cref{chapter:introduction},\nwe define B-trees recursively to either\nbe a \\textit{Node}, comprising a list\nof subtrees and keys or to be a \\textit{Leaf}\nthat contains no information.\nThe only room for interpretation is how to actually\nstore the subtrees and separators.\nFor trees of variable but constantly bounded size,\nan explicit constructor for each possible size may be given.\nAn example may be found for the 234-trees analysed by Nipkow\\parencite{DBLP:conf/itp/Nipkow16},\nwhere the number of subtrees is maximally 5.\nHowever in B-trees, the number of subtrees\nis bounded only by $k$, which is neither constant\nnor bounded by a constant.\n\nOne possible solution is to make nodes\nextensible by definition.\nThat is, instead of whole nodes,\nnode segments are defined that form a node together.\nThis resembles the definition of linked lists,\njust integrating the shape into the node definition.\nThe result is that a node segment either has one subtree,\none element and a pointer to a subsequent segment of the node or\nit is the last entry and has only one subtree.\nThis approach was implemented by Ernst \\parencite{DBLP:journals/sosym/ErnstSR15}.\nHowever, from our point of view, this approach has a number of downsides.\nFirst of, all operations on the tree were defined co-recursively,\nwhich adds a layer of complexity to all proofs.\nFurther, general lemmas for lists or similar data types can not\nbe used directly for this structure and would need to be transferred manually\nor newly derived.\n\nTherefore, we use an intermediate data structure to store the subtrees.\nThis approach is called nested recursive definition\nand will become clearer in the actual code in \\Cref{lst:btree-def}.\nThe intuitive idea is to choose sets as an abstract\ndata type to hold subtrees and keys, as was the first step by Fielding \\parencite{Fielding80}.\nHowever here we are limited as recursive nested definitions\nonly make sense for finitely bounded subtypes.\\footnote{\n    More information on this topic and potential remedies\n    may be found in the tutorial to data type definition in Isabelle\n    \\parencite{isabelleDatatypeManual}.\n}\nSets themselves are potentially of infinite cardinality\nand hence not bounded and working with finite sets\nintroduces additional complexity that we want\nto circumvent in the abstract definition.\n\nTherefore we resort to the list data type,\ndefining each node to hold a list of key-node pairs.\nBy storing subtrees and keys next to each other,\nproperties that relate subtrees to their immediately\nneighboring separators (i.e. sortedness)\ncan be defined locally on each pair in the list.\nThis also implicitly enforces the relationship of the number of subtrees\nand separators and makes the explicit use of length and index relationships unnecessary.\n\nA similar approach was chosen by Malecha \\parencite{DBLP:conf/popl/MalechaMSW10}.\nThere, the B-tree data type was defined directly on the heap\nand comprised the height of the tree, a pointer to the last subtree and\nan array of fixed size that contains pairs of values and pointers.\nWe will store subtrees and keys in pairs too,\nhowever, with a different in-pair order,\nsuch that the subtree to the left of a key is the first element\nin a tuple and the key is the second element,\nas visualized in \\Cref{fig:btree-basic}.\\footnote{\n    Writing this down in code or lemmas,\n    this also appears as \"subtree to the left on the left side of the tuple\".\n}\nMoreover in a functional context, we will not make use of arrays\nbut rather resort to lists.\nIn \\parencite{DBLP:conf/popl/MalechaMSW10} the height attribute was\nused to inductively define a shape predicate that is only valid\nif the height decreases for subtrees.\nHowever, the finite size of the abstract tree is an implicit\nresult of its recursive definition.\nWe therefore also do not explicitly store the height of the tree.\n\n\\begin{lstlisting}[mathescape=true, language=Isabelle,label=lst:btree-def]\ndatatype 'a btree = Leaf | Node (( 'a btree * 'a ) list) ('a btree)\n\\end{lstlisting}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{figures/btree-basic.pdf}\n    \\caption[Visualization of the implementation choice for B-Trees]\n    {The B-tree from figure \\Cref{fig:btree-basic-nopair} as concretely specified.\n    Subtrees and separators that lie in pairs in the implementation are surrounded by parentheses.}\n    \\label{fig:btree-basic}\n\\end{figure}\n\n\nAs said, this definition makes it easy to relate any separator\nto the subtree to its left, as this is subtree in the same tuple.\nIf we need to access the subtree to the right,\nwe may obtain the head of the remaining list by pattern matching\nand take the subtree of the first tuple.\nIn case the remaining list is empty,\nwe need to choose the last tree.\n\nThe balancedness of a B-tree is defined recursively, making use\nof an intuitively defined height.\\footnote{\n    The operator $`$ denotes the image of all elements of a set for a given function.\n    In this case we map all subtrees to their respective height.\n}\nThe height of all subtrees must be equal.\nHowever it is not completely intuitive\nwhat would be the best way to express this property.\nEither we fix the height of all trees\nto some existentially quantified number or to a known value.\nSince we know the last tree in the node exists and further\nknow that if all subtrees of the node have the same height,\nthen their height is equal to the last tree,\nwe simply choose the height of the last tree as an anchor point.\n\n\n\\begin{lstlisting}[mathescape=true, language=Isabelle]\n\nfun height :: 'a btree $\\Rightarrow$ nat where\n  height Leaf = 0 |\n  height (Node ts t) = 1 + Max (height ` (set (subtrees ts@[t]))\n\nfun bal :: 'a btree $\\Rightarrow$ bool where\n    bal Leaf = True |\n    bal (Node ts t) = (\n        ($\\forall$sub $\\in$ set (subtrees ts). height sub = height t) $\\wedge$\n        ($\\forall$sub $\\in$ set (subtrees ts). bal sub) $\\wedge$ bal t\n    )\n\\end{lstlisting}\n\nAnother option, demonstrated by Fielding, is\nto define balancedness as defined by Bayer\nto be that all paths from the root to the node are of equal length,\nor that the set of lengths of all paths be of size 1.\nHowever reasoning on set cardinality is likely to be more difficult\nin a mechanized proof than on paper\nand the definition for the mechanized proof by Ernst resembles\nours more closely, so we did not experiment much with this option.\n\nFurther the order of the trees needs to be formally defined.\nAs discussed in \\Cref{sec:data_structure_defs}, the most useful choice here is\nto allow for at least $k$ and at most $2k+1$ subtrees.\nSince the last subtree is fixed, and subtrees and children are residing as pairs in the same list,\nwe simply require the length of that list to be between $k$ and $2k$.\nNote that we also need a special property $order^r$ for the root of the tree,\nwhich has between one and $2k$ elements.\nIn mathematical equations, we will denote \"order $k$ $t$\" as \"$\\order_k t$\"\nfor convenience (likewise for \"order$^r$ $k$ $t$\"), which is to be read as\n\"tree $t$ is of order $k$\".\n\n\\begin{lstlisting}[mathescape=true, language=Isabelle]\n\nfun order :: nat $\\Rightarrow$ 'a btree $\\Rightarrow$ bool where\n    order k Leaf = True |\n    order k (Node ts t) = (\n        (length ts $\\ge$ k)  $\\wedge$\n        (length ts $\\le$ 2*k) $\\wedge$\n        ($\\forall$sub $\\in$ set (subtrees ts). order k sub) $\\wedge$ order k t\n    )\n\nfun order$^r$ where\n    order$^r$ k Leaf = True |\n    order$^r$ k (Node ts t) = (\n        (length ts $>$ 0) $\\wedge$\n        (length ts $\\le$ 2*k) $\\wedge$\n        ($\\forall$s $\\in$ set (subtrees ts). order k s) $\\wedge$ order k t\n    )\n\n\\end{lstlisting}\n\nWe define the sortedness of a B-tree based on the \\textit{inorder} of the tree,\nwhich is the catenation of all elements in the tree in in-order traversal.\nAn example can be seen in \\Cref{fig:inorder-basic}.\nThe library function $concat$ on lists of lists\nis employed here to express catenation of\nthe inorder of subtrees and the separators.\nThis definition reads a bit inconveniently\nas the node internal list is first mapped and then concatenated.\nHowever since we make recursive use of the inorder-function\ninside the mapping expression, mapping the subtree list is inconvenient to externalize.\nWe only later cover up this expression by using abbreviations.\nIn the following, we will not distinguish between lists, \npairs or trees when talking about their inorder representation.\nThe function with the correct type from the below listing is meant instead.\n\n\\begin{lstlisting}[mathescape=true, language=Isabelle]\nfun inorder :: 'a btree $\\Rightarrow$ 'a list where\n    inorder Leaf = [] |\n    inorder (Node ts t) = \n        concat (map ($\\lambda$ (sub, sep). inorder sub @ [sep]) ts) @ inorder t\n\nabbreviation inorder_pair  $\\equiv$ $\\lambda$(sub,sep). inorder sub @ [sep]\nabbreviation inorder_list ts $\\equiv$ concat (map inorder_pair ts)\n\\end{lstlisting}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.3\\linewidth]{figures/inorder-basic.pdf}\n    \\caption[Example inorder of a B-Tree]\n    {The inorder view on the B-tree from figure \\Cref{fig:btree-basic}.}\n    \\label{fig:inorder-basic}\n\\end{figure}\n\nThat way we can express sortedness of the tree $t$ as a simple $\\sorted (\\inorder t)$,\nwhere $sorted$ is the property of being sorted strictly (with resprect to $<$)\nin ascending order.\nThis definition is very compact and brings forward another benefit\npointed out by Nipkow \\parencite{DBLP:conf/itp/Nipkow16}:\n\nMany properties of search trees follow intuitively by considering\nthe inorder view on the tree.\nOften, it is supposed to be invariant (i.e. stealing from the neighbor node to the right)\nor only deviates in a manner we expect it to deviate given the inorder view\n(i.e. insert an element at the correct position).\nWe will see later how the use of this fact comes in handy for proving\nimportant properties of the implementation.\n\nSince our B-tree definition really only makes sense for positive $k$,\nwe obtain the following overall invariant for B-trees.\n\n\\begin{definition}\n    \\label{def:btree-def}\n    $k > 0 \\Longrightarrow \\btree_k t = \\bal t \\wedge \\order^r_k t \\wedge \\sorted (\\inorder t)$\n\\end{definition}\n\nAll trees that satisfy this invariant have a very small\nheight considering the number of inserted elements.\nThis fact is examined closer in the following section.\n % TODO note benefit over btree_sorted\n\n\\section{Height of B-Trees}\n\n%Height etc.\nAs pointed out by Bayer \\parencite{DBLP:journals/acta/BayerM72},\nthe height of B-trees is logarithmic with respect to the number\nof nodes of the tree.\nThe original paper even gives a precise lower and upper bound,\nthe proof of which we will quickly sketch in the following.\n\nFirst, we define the number of nodes in a tree:\n\\begin{lstlisting}[mathescape=true, language=Isabelle]\nfun nodes :: 'a btree $\\Rightarrow$ nat where\n    nodes Leaf = 0 |\n    nodes (Node ts t) =\n        1 + $\\sum$t$\\leftarrow$subtrees ts. nodes t + nodes t\n\\end{lstlisting}\n\n%To work with this equation, we just need to add one auxiliary lemmas to the standard canon\n%\\begin{lemma}\n%\\begin{lstlisting}[mathescape=true, language=Isabelle]\n%    sum_list (replicate n c) = n*c\n%\\end{lstlisting}\n%\\end{lemma}\n\nWe obtain bounds\non the number of nodes of a subtree with respect to its height\nby induction on the computation of the nodes function.\n\n\\begin{lemma}\n    \\label{lem:bound_internal_node}\n    $\\order_k t \\wedge \\bal t \\longrightarrow$\n    \\begin{align}\n        (k+1)^{\\height t} - 1 &\\le \\nodes t * k \\\\\n        \\nodes t * 2k &\\le (2k+1)^{\\height t} - 1\n    \\end{align}\n\\end{lemma}\n\nFrom \\Cref{lem:bound_internal_node} we can almost directly obtain\nthe bounds on valid roots of B-trees.\nThe only difference to the bound of internal nodes occurs on the lower bound side.\nThe issue here is that a root node may contain less elements than\na valid internal node (namely only one), which yields two subtrees with known height\nplus one for the node itself.\nNote that these are the exact same bounds as obtained by Bayer \\parencite{DBLP:journals/acta/BayerM72}\\footnote{\n    The operation $div$ denotes integer division here.\n    It does not make much difference though as all terms are divisible\n    without remainder.\n},\nexcept for the fact that we have generalized the equation,\nincorporating whether $t$ is a tree or not.\\footnote{\n    If $t$ is a \\textit{Leaf},\n    $2((k+1)^{\\height t - 1} - 1) \\div k + (t \\neq Leaf)$ becomes a fancy way of writing $0$.\n}\n\n\\begin{theorem}\n    \\label{thm:bound_btree}\n    $\\rootorder_k t \\wedge \\bal t \\wedge k > 0 \\longrightarrow$\n    \\begin{equation}\n        2((k+1)^{\\height t - 1} - 1) \\div k + (t \\neq Leaf) \\le \\nodes t \\le ((2k+1)^{\\height t} - 1) \\div 2k\n    \\end{equation}\n\\end{theorem}\n\nThese results are very interesting, because\nthe runtime of all further operations will be\ndirectly proportional to the height of the tree.\nTherefore, we are glad to see that the height is logarithmic\nwith respect to the number of nodes stored in the tree.\n\nThese bounds are sharp.\nWe prove this by providing in \\Cref{lst:sharp-trees-def}.\nfunctions that generate exactly those trees\nthat satisfy the requirements of B-trees, have a given height\nand satisfy the inequality from \\Cref{thm:bound_btree}\nwith equality.\nAs might be expected, these trees are simply those\nthat are minimally or maximally filled in each node with respect\nto the order property.\n\n%TODO (?) images of slim/full trees\n\\begin{figure}\n\\begin{lstlisting}[mathescape=true, language=Isabelle,label={lst:sharp-trees-def},\n    caption={The functions generating trees with minimal size and maximal size for given height.}]\n\nfun full_node where\n  full_node k c 0 = Leaf |\n  full_node k c (Suc n) = (\n      Node\n        (replicate (2*k) ((full_node k c n),c))\n        (full_node k c n)\n  )\n\nfun slim_node where\n  slim_node k c 0 = Leaf |\n  slim_node k c (Suc n) = (\n      Node\n        (replicate k ((slim_node k c n),c))\n        (slim_node k c n)\n    )\n\ndefinition full_tree = full_node\n\nfun slim_tree where\n  slim_tree k c 0 = Leaf |\n  slim_tree k c (Suc h) =\n    Node\n        [(slim_node k c h, c)]\n        (slim_node k c h)\n\n\\end{lstlisting}\n\\end{figure}\n\nThe proof for internal nodes follows by induction over the creation.\n\n\\begin{lemma} $t_f := \\fullnode k\\ a\\ h \\wedge t_s := \\slimnode k\\ a\\ h \\longrightarrow$\n    \\begin{align}\n    h = \\height t_s = \\height t_f \\wedge \\\\\n    ((2k+1)^h - 1) &= \\nodes t_f * (2k) &\\wedge \\order_k t_f \\wedge \\bal t_f \\\\ \n    ((k+1)^h - 1) &= \\nodes t_s * k  &\\wedge \\order_k t_s \\wedge \\bal t_s\n    \\end{align}\n\\end{lemma}\n\nThe rule for the roots follows directly, making use of the lemma\nfor the internal nodes.\nNote how for the root node the result is simply two times the\nvalue for trees of one height less, which are the minimally\nrequired two subtrees.\n\n% TODO prove div version of thm\n\\begin{theorem}\n    $k > 0 \\wedge t_f = \\fulltree k\\ a\\ h \\wedge t_s = \\slimtree k\\ a\\ h \\longrightarrow$\n    \\begin{align*}\n    h = \\height t_s &= \\height t_f &\\wedge \\\\\n        ((2k+1)^h - 1) \\div 2k &= \\nodes t_f &\\wedge \\rootorder_k t_f \\wedge \\bal t_f \\\\ \n        2((k+1)^{h-1} - 1) \\div k + (t_s \\neq Leaf) &= \\nodes t_s &\\wedge \\rootorder_k t_s \\wedge \\bal t_s\n    \\end{align*}\n\\end{theorem}\n\n\n\\section{Set operations}\n\nWe say that B-trees store linearly ordered values\nthat could be stored in an abstract set,\nand the that a B-tree is a concretization\nof this set.\nWith this specification of B-trees we need to provide functions that allow\nset-like operations on the trees -\nmembership queries, insertion and deletion.\nIn the Isabelle/HOL framework, there is a standard interface\nfor data structures that provide an implementation of sets.\n\n\\subsection{The Set Interface}\n% Description of the set interface\n\nAs described by Nipkow \\parencite{DBLP:conf/itp/Nipkow16},\nan implementation \\textit{'a t} of sets of elements of type \\textit{'a} is required to provide the following\noperations:\n\n\\begin{itemize}\n    \\itshape\n    \\item set :: 'a t $\\Rightarrow$ 'a set\n    \\item inv :: 'a t $\\Rightarrow$ bool\n    \\item empty :: 'a t \\textup{\\textbf{where}} set empty = $\\emptyset$\n    \\item isin :: 'a t $\\Rightarrow$ 'a $\\Rightarrow$ bool \\textup{\\textbf{where}} inv t $\\Longrightarrow$ isin x t = x $\\in$ set t\n    \\item insert :: 'a $\\Rightarrow$ 'a t $\\Rightarrow$ 'a t \\textup{\\textbf{where}} inv t $\\Longrightarrow$ set (insert t x) = set t $\\cup$ {x}\n    \\item delete :: 'a $\\Rightarrow$ 'a t $\\Rightarrow$ 'a t \\textup{\\textbf{where}} inv t $\\Longrightarrow$ set (delete t x) = set t $\\backslash$ {x}\n\\end{itemize}\n\nFor this work, using the definition from \\Cref{lst:btree-def},\nwe consider \\textit{'a t = 'a btree}.\nThe standard approach is to provide functions on B-tree and show\nthat they have the same effect as membership test, insertion and deletion \nin abstract sets with the same elements (specified above after \"where\").\nFurther, the invariant needs to remain valid for the results of the operations\nas well as the $empty$ element (i.e. $inv\\ t \\Longrightarrow inv\\ (insert\\ x\\ t)$).\n\nWe know from \\Cref{sec:basic-defs} that one of the invariants\nof the tree is that it is always sorted.\nWhile this is expressed in a somewhat cumbersome manner\nin the original definition by Bayer \\parencite{DBLP:journals/acta/BayerM72},\nthis requirement is nothing else but a sortedness of the inorder view of the tree.\nKnowing this, we resort to a specialized set interface\nproposed by Nipkow \\parencite{DBLP:conf/itp/Nipkow16}.\nTheir approach yielded automatic proofs for 2-3-trees\nand 234-trees, which are specializations of B-trees.\nThe modified Set interface reasons based on the \\textit{inorder}\nview on the tree instead of the \\textit{set} abstraction.\n\n\\begin{itemize}\n    \\itshape\n    \\item inorder :: 'a t $\\Rightarrow$ 'a list\n    \\item inv :: 'a t $\\Rightarrow$ bool\n    \\item empty :: 'a t \\textup{\\textbf{where}} inorder empty = []\n    \\item isin :: 'a t $\\Rightarrow$ 'a $\\Rightarrow$ bool \\textup{\\textbf{where}}\\\\\n     inv t $\\wedge$ sorted(inorder t) $\\Longrightarrow$ isin x t = x $\\in$ set (inorder t)\n    \\item insert :: 'a $\\Rightarrow$ 'a t $\\Rightarrow$ 'a t \\textup{\\textbf{where}}\\\\\n     inv t $\\wedge$ sorted(inorder t) $\\Longrightarrow$ inorder (insert t x) = ins$_{list}$ (inorder t) x\n    \\item delete :: 'a $\\Rightarrow$ 'a t $\\Rightarrow$ 'a t \\textup{\\textbf{where}}\\\\\n     inv t $\\wedge$ sorted(inorder t) $\\Longrightarrow$ inorder (delete t x) = del$_{list}$ (inorder t) x\n\\end{itemize}\n\nThe invariant and inorder functions for this set interface\nfollow directly from the definition of B-trees.\nHence, we specify $k > 0 \\wedge \\order^r_k t \\wedge \\bal t$\nas the invariant of B-trees and use\nthe concatenation function from \\Cref{sec:basic-defs} to specify the\nlist abstraction \\textit{inorder}.\nNote that sortedness is not part of the invariant\nbut will be required for all operations and preserved\ndue to the definition of $ins_{list}$ and $del_{list}$.\nThe interface is then implemented by providing set operations\nand the proofs of invariant preservation\nwith respect to this inorder abstraction.\n\nSome parts of the set specification are trivial.\nIn the following, \\textit{Leaf} is an empty tree and hence represents\nthe empty set, satisfying the first part of the specification.\nIt can be seen directly that the leafs already satisfy all three \nproperties of the invariant.\nThe following sections will describe the implementation \nand proofs of the non-trivial set operations.\n\n\\subsection{The split-Function}\n\n\\begin{figure}\n    \n\\begin{lstlisting}[mathescape=true, language=Isabelle]\nfun linear_split_help where\n  linear_split_help [] x prev = (prev, []) |\n  linear_split_help ((sub, sep)#xs) x prev = (\n      if sep < x then\n        linear_split_help xs x (prev @ [(sub, sep)])\n      else\n        (prev, (sub,sep)#xs)\n  )\n\nfun linear_split:: ('a btree$\\times$'a) list $\\Rightarrow$ 'a $\\Rightarrow$ (_ list $\\times$ _ list) where\n  linear_split xs x = linear_split_help xs x []\n\\end{lstlisting}\n\\begin{lemma}\n    \\begin{equation*}\n    \\lsplitfun\\ xs\\ x = (\\takewhile (\\lambda(\\_,s).\\ s < x)\\ xs,\\ \\dropwhile (\\lambda(\\_,s).\\ s < x))\n    \\end{equation*}\n\\end{lemma}\n\\caption[An implementation of the abstract split function specifications.]\n{An implementation of the abstract split function specifications.\nThis functions scans linearly through the list, returning the first tuple where the separator\nor subtree could potentially contain the value $x$.\nIt is similar to a combination of library functions, simplifying proofs on its properties.}\n\\label{fig:linear_split}\n\n\\end{figure}\n% Description of the implementation of the set interface.\n\nNaturally, the set operations are defined recursively on the nodes of the tree.\nSince each node contains a number of elements that is not bounded by a constant,\na generalized function to navigate to the correct separator and subtree\nis central to all operations.\\footnote{\n    Opposing to that, in 234-trees determining the correct subtree\n    and separator could be hard coded for every case, as done by Nipkow \\parencite{DBLP:conf/itp/Nipkow16}.\n}\n\nWe call this function \\textit{split}-function.\nIt determines the \"correct\" position in the list of separators and subtrees\nfor recursion.\nAt this position, the range spanned by the subtree to the left\nand the separator is exactly the range in which the desired element\nmust be contained if it is contained in the tree.\nHence, either the separator is equal to the desired value or\nwe need to recurse into the subtree to the left.\nThe approach of generalizing the tree navigation has\nsurprisingly little popularity in the implementations examined.\nNotably, it was implemented in the work of Malecha and Fielding,\nbut not described in detail \\parencite{DBLP:conf/popl/MalechaMSW10,Fielding80}.\\footnote{\n    In Fieldings approach the corresponding function is called \\textit{index} and the final implementation is a linear search.\n    Malecha calls it \\textit{findSubtree} and looses no more words about it.\n}\nUsually however, it is integrated into the set-operation\nby a linear search that is promised to be replaced by a more efficient binary search\nin the actual implementation \\parencite{DBLP:books/daglib/0023376,DBLP:journals/acta/BayerM72}\nor left in the final code \\parencite{DBLP:journals/sosym/ErnstSR15}.\n\nThe precise inner workings of the split function are not of interest here\nand actually are not supposed to be interesting on the functional level.\nOf course we need to know that \\textit{some} kind of function\nexists that correctly splits the key-value list.\nAn example is given in \\Cref{fig:linear_split}.\nIn the process of implementing the set specifications,\nthis concrete function was used to explore the provability of the set methods.\nHowever it quickly turned out that 1) only specific lemmas about the split\nfunction are useful during proofs and 2) only relying on an abstract specification of\nthe split method would simplify integrating alternative splitting functions.\nMost notably, the abstraction allows to later plug in an efficient splitting\nfunction, e.g. based on binary search.\n\n\n\\begin{samepage}\nTherefore all set functions are defined based on an abstract function\n\\textit{split} that fulfils the following requirements for a list of subtrees\nand separators \\textit{xs} and a partitioning value $p$:\n\n\\begin{itemize}\n    \\item $\\splitfun xs\\ p = (ls,rs) \\Longrightarrow xs = ls @ rs$\n    \\item $\\splitfun xs\\ p = (ls@[(sub,sep)],rs) \\wedge \\sorted (\\separators xs) \\Longrightarrow sep < p$\n    \\item $\\splitfun xs\\ p = (ls,(sub,sep)\\#rs) \\wedge \\sorted (\\separators xs) \\Longrightarrow p \\le sep$\n\\end{itemize}\n\\end{samepage}\n\nDescribed in natural language, the split function should return two lists\nthat concatenate to the original list\n(we refer to them further as the \\textit{first} and \\textit{second} part of the list).\nIf the elements came in sorted order,\nthe list is split such that the key to the left is strictly\nless than $p$ and the key to the right\nshould be less or equal than $p$.\n\nNote how the split function really only needs to\nconsider the separators and not the subtrees themselves.\nBy requiring only sortedness of the separators,\nwe weaken the requirements to fulfil the split abstraction.\nHowever these weakened assumptions are sufficient to guarantee\nfunctional correctness.\nSortedness of the whole tree is part of the established invariant of B-trees.\nIf the whole tree is sorted, the separators are sorted too.\nWe prove this once and from it follows that\nwe may use the split function for sorted trees\nand obtain the desired results.\n\n\\subsection{Membership tests}\n\n%-------------------------------------------------\n% TODO move to abstract description?\nThe simplest operation required in the set interface is\nthe \\textit{isin} function.\nIt should return the same value for a B-tree \nas a membership queries on the set abstraction of the tree.\n% Note reference to i.e. Bauer retrieval algorithm\nThe definition in \\Cref{lst:isin-fun} is straightforward \nand also shows example usage of the split function.\nIn case the second part of the split list is non-empty,\nwe check the element at its head and recurse in the given subtree\nif necessary.\nOtherwise, we may directly recurse to the last tree in the node.\\footnote{\n    This function recurses on results of the split function.\n    In order to show that this function terminates, we need to show\n    the system that the obtained subtrees are of smaller size than the current tree.\n    Adding this fact to the default termination simplification set resolves\n    the issue for all coming functions.\n}\n%-------------------------------------------------\n\n\\begin{figure}\n\\begin{lstlisting}[mathescape=true, language=Isabelle, caption=The \\textit{isin} function, label=lst:isin-fun]\nfun isin :: 'a btree $\\Rightarrow$ 'a $\\Rightarrow$ bool where\n    isin (Leaf) x = False |\n    isin (Node ts t) x = (\n        case split ts x of (_,(sub,sep)#rs) $\\Rightarrow$ (\n            if x = sep then\n                True\n            else\n                isin sub x\n        ) | (_,[]) $\\Rightarrow$\n            isin t x\n    )\n\\end{lstlisting}\n\\end{figure}\n\nBy the standard set interface the operation is only required to work on\nsorted, balanced trees of a certain order, however only the first property\nis actually required for correctness.\nThe following lemma shows the required property of the function\n\n\\begin{theorem}\n    \\label{thm:isin-set}\n    $\\sorted (\\inorder t) \\Longrightarrow \\isinfun t\\ x = x \\in \\setfun (\\inorder t)$\n\\end{theorem}\n\nIt follows by induction on the evaluation of the isin function.\nTo prove it, we invoke two specialized lemmas,\nthat simplify arguments about the choice of the node for recursion.\nThe lemmas specialize an idea proposed by Nipkow \\parencite{DBLP:conf/itp/Nipkow16}\nand similar lemmas will be used for the correctness proofs of \nthe \\textit{insert} and \\textit{delete} function.\n\n\\begin{lemma} $\\sorted (\\inorder (Node\\ ts\\ t) \\wedge \\splitfun ts\\ x = (ls, rs) \\Longrightarrow$ \\\\\n    \\begin{center}\n    $x \\in \\setfun (\\inorder (Node\\ ts\\ t)) = x \\in \\setfun (\\inorder rs @ \\inorder t)$\n    \\end{center}\n\\end{lemma}\n\nThe idea of this fact is to argue that, if the split function has provided\nus with a given splitting, it is safe to limit the further search\nto the second part of the split.\nIt follows directly from the requirements on the split function.\nIf $rs$ is empty, we can follow that the element has to reside in the inorder\nof the last tree of the node.\nWhen used in the inductive proof of \\Cref{thm:isin-set}, we can then deduce that this is\nequal to \\textit{isin t x}, the branch taken in the isin-function\n(see \\Cref{lst:isin-fun}) if the second list in the split result is empty.\nIf $rs$ is not empty, we need an additional lemma.\n\n\\begin{lemma}\n    $\\sorted (\\inorder (Node\\ ts\\ t)) \\wedge \\splitfun ts\\ x = (ls, (sub,sep)\\#rs) \\wedge sep \\neq x \\Longrightarrow$ \\\\\n    \\begin{center}\n    $x \\in \\setfun (\\inorder ((sub,sep)\\#rs) @ \\inorder t) = x \\in \\setfun (\\inorder sub)$\n    \\end{center}\n\\end{lemma}\n\nWith this lemma we know that the first subtree\nin the second part of the split result\nis the correct child to recurse into.\nThe requirement of $sep \\neq x$ is because if $sep = x$,\nno recursion is required at all.\nThe desired element was just found.\n\nThis operation has no effect on the tree, it only walks through it.\nThis fact follows directly due to the persistence of functional data structures.\nHence, no proof of invariant preservation is required,\nin contrast to the following tree-modifying operations.\n\n\\subsection{Insertion}\n\\label{sec:abs-ins}\n\n\n% TODO what is this for?\n%There are not many provably correct functional implementations to our knowledge.\n%However there is a relationship between 234-trees and B-trees,\n%due to which the approach to the functional definition is inspired by the implementation\n%in \\parencite{DBLP:conf/itp/Nipkow16}.\n%In that work, a correct implementation of the Set interface for 234-trees \n%are provided.\n\nThe implementation of the insertion function\nas described in \\Cref{par:intro-ins} is documented in \\Cref{lst:ins-fun}.\nRather than manually checking whether the lowest level was reached,\nwe recurse until we reach a leaf.\nInserting into it is defined to cause an overflow that will be handled\nby the lowest internal nodes in the same manner as for other internal nodes.\n\nThe $ins$ function is a recursive helper function,\nthat recurses down into the correct leaf node for insertion.\nAs a possible intermediate result of insertion\nmay be two trees that are the result of an obligatory split,\nit returns data in a new data type called \\textit{up}$_i$.\nThis data type carries either a singleton valid B-tree or two trees and a separator\nthat could correctly be part of a node when placed next to each other.\nThe original subtree is replaced by\nthe result of the recursive call.\nIf an overflow occured in the lower node, the additional element and\nsubtree are inserted into the current node list\nafter the element that flowed over.\nThe resulting list may have an overflow itself.\n\nTo modularize insertion, the check for the overflow of\nthe nodes list has been\nextracted to the function \\textit{node}$_i$.\nIn case the node that was passed in violates the order invariant,\nit performs the splitting and returns two trees and the additional separator.\nThis construction is useful for handling overflow\nin a functional context and appears similarly in the\nverified functional 234-tree implementation by Nipkow \\parencite{DBLP:conf/itp/Nipkow16}.\n\nFinally, the \\textit{insert} function calls the \\textit{ins} helper function\nand transforms the result into a valid B-tree by allocating a new root if necessary.\n\n\\begin{figure}\n    \n\\begin{lstlisting}[mathescape=true, language=Isabelle, label=lst:ins-fun, caption={\n    The \\textit{insert} function\n}]\ndatatype 'b up$_i$ = T$_i$ 'b btree | Up$_i$ 'b btree 'b 'b btree\n\nfun split_half where\n  split_half xs = (take (length xs div 2) xs, drop (length xs div 2) xs)\n\nfun node$_i$ :: nat $\\Rightarrow$ ('a btree $\\times$ 'a) list $\\Rightarrow$ 'a btree $\\Rightarrow$ 'a up$_i$ where\n  node$_i$ k ts t = (\n  if length ts $\\le$ 2*k then T$_i$ (Node ts t)\n  else (\n    case split_half ts of (ls, (sub,sep)#rs) $\\Rightarrow$\n      Up$_i$ (Node ls sub) sep (Node rs t)\n    )\n  )\n\nfun ins :: nat $\\Rightarrow$ 'a $\\Rightarrow$ 'a btree $\\Rightarrow$ 'a up$_i$ where\n  ins k x Leaf = (Up$_i$ Leaf x Leaf) |\n  ins k x (Node ts t) = (\n  case split ts x of\n    (ls,(sub,sep)#rs) $\\Rightarrow$ \n      (if sep = x then T$_i$ (Node ts t)\n      else\n        (case ins k x sub of \n          Up$_i$ l a r $\\Rightarrow$\n            node$_i$ k (ls @ (l,a)#(r,sep)#rs) t | \n          T$_i$ a $\\Rightarrow$ T$_i$ (Node (ls @ (a,sep) # rs) t))) |\n    (ls, []) $\\Rightarrow$\n      (case ins k x t of\n         Up$_i$ l a r $\\Rightarrow$\n            node$_i$ k (ls@[(l,a)]) r |\n         T$_i$ a $\\Rightarrow$ T$_i$ (Node ls a)\n  )\n)\n\nfun tree$_i$ :: 'a up$_i$ $\\Rightarrow$ 'a btree where\n  tree$_i$ (T$_i$ sub) = sub |\n  tree$_i$ (Up$_i$ l a r) = (Node [(l,a)] r)\n\nfun insert::nat $\\Rightarrow$ 'a $\\Rightarrow$ 'a btree $\\Rightarrow$ 'a btree where\n  insert k x t = tree$_i$ (ins k x t)\n\\end{lstlisting}\n\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.43\\linewidth]{figures/btree-basic.pdf}\\\\\n    \\vspace*{1cm}\n    \\includegraphics[width=0.48\\linewidth]{figures/btree-basic-ins9.pdf}\\\\\n    \\vspace*{1cm}\n    \\includegraphics[width=0.48\\linewidth]{figures/btree-basic-ins9-ins1.pdf}\n    \\caption[An example B-Tree after two insertion operations]\n    {The tree from \\Cref{fig:btree-basic} (top) after \n    successive insertion of $9$ (middle) and $1$ (bottom).}\n    \\label{fig:btree-basic-ins}\n\\end{figure}\n%TODO\n\nTo fulfil the set interface requirements,\nwe need to show that this function preserves the invariants\nand acts the same as inserting element $x$ into the inorder list of the tree.\nNote that for these proofs, a separate notion of height, balancedness, order\nand inorder had to be introduced for the \\textit{up}$_i$ data type.\nHeight, balancedness and inorder are\ndefined such that they are invariant to splitting and merging of nodes.\nFor example, \"$\\height ts\\ t = \\height^{up_i} (\\node_i k\\ ts\\ t)$\".\nThe modified order function simply subsumes that all subtrees have\nthe given order.\nNaturally, making a one-element tree of an up$_i$ element will thus\ngive a node of root-order, while inserting the elements\nwill not violate the recursive order requirement.\n\nProving that balancedness is invariant \nunder insertion requires an additional lemma,\nnamely that the height is also invariant under insertion.\nTechnically, height preservation is only required when modifying balanced\ntrees, however we have shown the stronger statement that this is even the case for non-balanced trees.\nThis follows by induction using the\nassociativity and commutativity of the maximum function.\nWith height invariance, the proof for balancedness follows much the same way.\nOverall, the fact that the operation does preserve balancedness and\nheight should come at no surprise to the reader.\nAfter all, the operations are never directly affecting the height of any tree,\nand all trees generated by splitting a node comprise trees\nthat had been there before, now simply distributed along to two nodes\nin the same level.\n\n\\begin{lemma}\n    \\begin{align*}\n    \\height t & = \\height^{up_i} (\\insfun_k x\\ t) \\\\\n    \\bal t & \\Longrightarrow \\bal^{up_i} (\\insfun_k x\\ t)\n    \\end{align*}\n\\end{lemma}\n\nThe order invariant is the second property that needs\nto be shown to stay invariant.\nSince the central function to ensure order is the node$_i$ function,\nwe first show the following lemma:\n\n\\begin{lemma}\n\\label{lem:nodei-order}\n    If all children have order $k$ and $\\length ts \\ge k$ and $\\length ts \\le 4k+1$\n    then all trees in $\\node_i k\\ ts\\ t$ have order $k$.\n\\end{lemma}\n\nEven though in the case of insertion the length of the list\nnever exceeds $2k+1$, the statement holds up to $4k+1$.\nThe statement is proven by case distinction whether \"$\\length ts \\le 2k$\".\nLooking at the definition in \\Cref{lst:ins-fun}\nwe see that if this is the case nothing happens and the lemma is trivial.\nIn case \"$\\length ts > 2k$\", a split occurs.\nThe median element is passed up as a seperator, leaving\n$\\lfloor\\frac{\\length ts}{2}\\rfloor$ and $\\lceil\\frac{\\length ts}{2}\\rceil - 1$\nelements for the node to the left or right respectively.\nGiven the constraint on the maximum length of $ts$\nthis will always be below or equal $2k$.\nFurther, as we require a size of at least $2k+1$ elements for a split to occur,\nthe resulting nodes each have at least $k$ elements.\nThis argument hardly changes comparing the upper bounds $2k+1$ and $4k+1$,\nbut with the weaker upper bound \\textit{node}$_i$ can be used for merging nodes\nin the deletion function as well.\n\nUsing the above, the order invariant for \\textit{ins}\nfollows quite directly by induction.\n\n\\begin{lemma}\n    $\\order_k t \\Longrightarrow \\order^{up_i}_k (\\insfun_k x\\ t)$\n\\end{lemma}\n\nSince the invariant on B-trees only requires root order of $k$ on the\ntree, we had to additionally derive versions of\nthese invariants for this weaker order.\nThey are straightforward however as all trees in the inductive case\nhave order $k$, for which preservation was just proven.\nPutting things together, we obtain preservation of the invariants.\n\n\\begin{theorem}\n    \\label{thm:ins-invar}\n    $\\order^r_k t \\wedge \\bal t \\Longrightarrow\n    \\order^r_k (\\insertfun_k x\\ t) \\wedge \\bal (\\insertfun_k x t)$\n\\end{theorem}\n\n\nThe set interface further requires that the insertion returns a tree\nthat has the same inorder view as the original inorder with the element\ninserted at the correct position.\n\nLooking at the \\textit{ins} function in \\Cref{lst:ins-fun},\nwe see that, in an inductive proof, the main obligation\nis to argue for the choice of the subtree for recursion.\nSimilar to the proof of \\Cref{thm:isin-set},\nwe use two auxiliary lemmas, that turn the remaining\nproof in simple case distinctions and chains of equations.\n\n\\begin{lemma}\n    \\label{lem:sorted-left-x-in}\n    $\\sorted(\\inorder (Node\\ ts\\ t)) \\wedge \\splitfun ts\\ x = (ls, rs) \\Longrightarrow$ \\\\\n    \\begin{center}\n    $\\inslist x\\ (\\inorder (Node\\ ts\\ t))) = \\inorder ls\\ @\\ \\inslist x\\ (\\inorder rs\\ @\\ \\inorder t)$\n    \\end{center}\n\\end{lemma}\n\n\\begin{lemma}\n    \\label{lem:sorted-right-x-in}\n    $\\sorted (\\inorder (Node\\ ts\\ t)) \\wedge \\splitfun ts\\ x = (ls, (sub,sep)\\#rs) \\wedge sep \\neq x \\Longrightarrow$ \\\\\n    \\begin{center}\n    $\\inslist x\\ (\\inorder ((sub,sep)\\#rs)\\ @\\ \\inorder t)) =$\\\\\n    $ (\\inslist x\\ (\\inorder sub))\\ @\\ sep \\# \\inorder rs\\ @\\ \\inorder t$\n    \\end{center}\n\\end{lemma}\n\nThe only case not covered by the above lemmas is the case $sep = x$.\nIn that case, the tree does not change.\nThis is due to the fact that $x$ is already in the set represented by the tree\nand hence does not need to be inserted.\nThe same happens when inserting $x$ into a list that already contains $x$\n(i.e. the inorder of the tree),\nwhich follows simply by induction on the list.\n\n\\begin{lemma}\n    \\label{lem:sorted-x-in}\n    $\\sorted xs \\wedge x \\in \\setfun xs \\Longrightarrow \\inslist x\\ xs = xs$\n\\end{lemma}\n\n\\Cref{lem:sorted-left-x-in}, \\Cref{lem:sorted-right-x-in} and \\Cref{lem:sorted-x-in} are sufficient to show correctness\nof the \\textit{ins} function inductively.\nThe theorem for \\textit{insert} follows again automatically,\nwhich concludes the proof of the insertion part.\n\n\\begin{theorem}\n    \\label{thm:ins-set}\n    $\\sorted  (\\inorder t)\\Longrightarrow$\\\\\n    \\begin{center}\n    $\\inorder (\\insertfun_k x\\ t) = \\insfun_{list} x\\ (\\inorder t)$\n    \\end{center}\n\\end{theorem}\n\n\n\\subsection{Deletion}\n\n\n\\begin{figure}\n\\begin{lstlisting}[mathescape=true, language=Isabelle,label={lst:rebalance-def},\n    caption={The rebalancing functions}]\nfun rebalance_middle_tree where\n  rebalance_middle_tree k ls Leaf sep rs Leaf = (Node (ls@(Leaf,sep)#rs) Leaf) |\n  rebalance_middle_tree k ls (Node mts mt) sep rs (Node tts tt) = (\n    if length mts $\\ge$ k $\\wedge$ length tts $\\ge$ k then\n        Node (ls@(Node mts mt,sep)#rs) (Node tts tt)\n    else (\n        case rs of [] $\\Rightarrow$ (\n            case node$_i$ k (mts@(mt,sep)#tts) tt of\n                T$_i$ u $\\Rightarrow$ Node ls u |\n                Up$_i$ l a r $\\Rightarrow$ Node (ls@[(l,a)]) r\n            ) |\n        (Node rts rt,rsep)#rs $\\Rightarrow$ (\n            case node$_i$ k (mts@(mt,sep)#rts) rt of\n                T$_i$ u $\\Rightarrow$\n                   Node (ls@(u,rsep)#rs) (Node tts tt) |\n                Up$_i$ l a r $\\Rightarrow$\n                   Node (ls@(l,a)#(r,rsep)#rs) (Node tts tt)\n            )\n        )\n    )\n\nfun rebalance_last_tree where\n    rebalance_last_tree k ts t = (\n        case last ts of (sub,sep) $\\Rightarrow$\n            rebalance_middle_tree k (butlast ts) sub sep [] t\n    )\n\\end{lstlisting}\n\\end{figure}\n\nThe procedures described in \\Cref{par:intro-del}\nare implemented here with a\ncertain flavor due to the definition of B-trees.\nThe \\textit{rebalancing} as implemented in \\Cref{lst:rebalance-def}\ncomprises merging and splitting neighboring nodes.\nFor simplicity of the function and proofs, we always\nmerge with the sibling to the right.\nThe only exception, which is unavoidable due to the asymmetry of the data structure,\nis an underflow in the last subtree.\nIt will be merged with the second-to-last subtree, the last\ntree in the variable length list of the node.\nNote also how the tree does not change when asked to rebalance a leaf.\nThe reason is that rebalancing leafs may only happen if it is preceded\nby deletion from a leaf - which does not change the tree at all.\n\nThe other detail is regarding the \\textit{split\\_max} function\nemployed when deleting elements from inner nodes.\nIt is defined in \\Cref{lst:del-def}.\nHere, some freedom exists whether to swap with the maximum lesser\nor the minimum greater element in the tree.\nIn our definition, the last tree of the node is explicitly stored in each node\nand the subtree to the left of a separator lies within the same\npair inside the node list.\nUsing pattern matching, it is hence significantly\neasier to obtain the maximum of the subtree to the left,\nthan than to obtain the minimum of the subtree to the right.\nTherefore, we will always swap with the former, maximal lesser element.\n%---------------------------------------------------------\n\nThe most interesting property for the rebalancing operations is the order property,\nwhich is meant to be restored after underflows.\nIt is important to note here that we can not guarantee\nthat at least one element remains in the node that\nis passed back upwards.\nThis violates even the weakest order formulation up until now,\nthe root order invariant.\nHence before making the result of rebalancing\na final tree, we need to recover root order.\nWe can guarantee that all subtrees of the result are of order $k$\nand that there are no more than $2k$ elements in the result,\nwhich is sufficient.\nWe say that if a tree $t$ has at most $2k$ elements\nand all subtrees of $t$ have order $k$, then $t$ has\n\\textit{almost order} $k$ ($\\order^a_k t$).\nUsing this new definition we formulate the invariant for\nthe rebalancing operation.\n\n\\begin{lemma}\n    If all subtrees in ls, rs are of order k \n    and of sub and t, only one may have almost order k and the other has order k,\n    and all subtrees have equal height, then \\\\\n    \\begin{center}\n    $\\order^a_k (\\rebalancemt_k ls\\ sub\\ sep\\ sep\\ rs\\ t)$\n    \\end{center}\n\\end{lemma}\n\nIt might be suprising that we require all subtrees to have equal height\nfor this operation.\nHowever, a close look at \\Cref{lst:rebalance-def} may clarify this requirement.\nIn order to successfully rebalance an internal node, we need neighboring\nnodes that are not leafs.\nAs this fact is already expressed in the pattern matching of the function,\nit is simply \\textit{undefined} if not all subtrees have equal height.\nBut we know that B-trees are always balanced,\nso we may assume equal subtree height for all proofs\ninvolving \\textit{rebalance\\_middle\\_tree}.\nFor this proof, we re-use \\Cref{lem:nodei-order},\nas two nodes of order $k$ will always contain\na maximum of $4k+1$ separators.\n\nAs mentioned, the result may have an empty list as key-value list.\nThis happens exactly when one of the two subtrees of a root\nwith minimal size underflowed.\nAfter this operation, the tree shrinks in height.\nThe shrinked tree then is exactly the one remaining subtree in the original node.\nSee the operation \\textit{reduce\\_root} in \\Cref{lst:del-def} for the exact implementation\nof this step.\nSince rebalancing always restores $\\order k$ for all subtrees\nof the current node and \\textit{delete} employs \\textit{reduce\\_root},\nthe final result always has at least $\\order^r k$.\n\n\n\\begin{figure}\n\\begin{lstlisting}[mathescape=true, language=Isabelle,label={lst:del-def},\n    caption={The $delete$ function}]\n\nfun split_max where\n    split_max k (Node ts t) = (\n        case t of Leaf $\\Rightarrow$ (\n            let (sub,sep) = last ts in (Node (butlast ts) sub, sep)\n        ) |\n        _ $\\Rightarrow$ case split_max k t of (sub, sep) $\\Rightarrow$\n                (rebalance_last_tree k ts sub, sep)\n        )\n\nfun del where\n    del k x Leaf = Leaf |\n    del k x (Node ts t) = (\n    case split ts x of (ls,[]) $\\Rightarrow$\n        rebalance_last_tree k ls (del k x t) |\n    (ls,(sub,sep)#rs) $\\Rightarrow$\n        if sep $\\neq$ x then\n            rebalance_middle_tree k ls (del k x sub) sep rs t\n        else if sub = Leaf then\n            Node (ls@rs) t\n        else let (sub_s, max_s) = split_max k sub in\n            rebalance_middle_tree k ls sub_s max_s rs t\n    )\n \nfun reduce_root where\n    reduce_root Leaf = Leaf |\n    reduce_root (Node ts t) = (case ts of\n        [] $\\Rightarrow$ t |\n        _ $\\Rightarrow$ (Node ts t)\n    )\n \nfun delete where delete k x t = reduce_root (del k x t)\n\\end{lstlisting}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.54\\linewidth]{figures/btree-basic-ins9-ins1.pdf}\\\\\n    \\vspace*{1cm}\n    \\includegraphics[width=0.48\\linewidth]{figures/btree-basic-ins9-ins1-del10.pdf}\\\\\n    \\vspace*{1cm}\n    \\includegraphics[width=0.48\\linewidth]{figures/btree-basic-ins9-ins1-del10-del3.pdf}\n    \\caption[An example B-Tree after two deletion operations]{The tree from \\Cref{fig:btree-basic-ins} (top) after \n    successive deletion of $10$ (middle) and $3$ (bottom).\n    For the first deletion, the value 10 and is swapped with value 9 before it is removed from the tree.\n    The middle subtree is then in an underflow, resulting in a merge with the right subtree and the new separator 9.\n    During the second deletion, an underflow is caused in the left subtree,\n    resulting in a merge with the separator 5 and the middle subtree and a subsequent split.\n    Note how the final result differs from approaches that would only steal single elements\n    from neighbors to handle underflow.}\n    \\label{fig:btree-basic-del}\n\\end{figure}\n\nThe proofs for balancedness invariance follow similarly to\nthe ones in \\Cref{sec:abs-ins} by first showing height invariance.\nBoth properties follow using the associativity\nand commutativity of the maximum operation.\n\\footnote{\n    When inspecting the proof documents,\n    one will notice that the proof of height, balancedness and order\n    are interleaved for the\n    intermediate functions, especially\n    \\textit{split\\_max} and \\textit{rebalance\\_middle\\_tree}.\n    This is due to the fact that these operations\n    are only well defined for balanced trees.\n    Moreove \\textit{split\\_max} requires at least\n    one element in the node list, an equivalent\n    to $\\order^r k$.\n}\n\nWith the basic operations covered,\nthe invariant preservation of the \\textit{del} function\ncan be derived inductively.\nNote that the function will return a tree of almost order $k$,\nwhere the remaining root-underflow is coverered by \\textit{reduce\\_root}.\nMoreover we do not need an additional lemma\nfor an input with nodes that have normal order $k$.\nAs $k > 0$, order $k$ implies a root order of $k$.\nAnd even though it might seem to be beneficial to know\nwhether the input has normal order or root order, this is not the case.\nThe rebalancing functions only require\nalmost order $k$ and return a list of trees of valid order.\nWe are never interested in the length of that list itself\nuntil reaching the root, so we are satisfied with statements\non the order of subtrees,\nwhich are made by almost order $k$ sufficiently.\n\n\\begin{lemma}\n    $k > 0 \\wedge \\order^r_k t \\wedge \\bal t \\Longrightarrow\n    \\order^a_k (\\delfun_k x\\ t) \\wedge \\bal (\\delfun_k x t)$\n\\end{lemma}\n\nFrom this and our inspection of \\textit{reduce\\_root}\nfollows almost directly the fact about the invariant\npreservation of \\textit{delete}.\n\n\\begin{samepage}\n\\begin{theorem}\n    $k > 0 \\wedge \\order^r_k t \\wedge \\bal t \\Longrightarrow$ \\\\\n    \\begin{center}\n    $\\order^r_k (\\deletefun_k x\\ t) \\wedge \\bal (\\deletefun_k x t)$\n    \\end{center}\n\\end{theorem}\n\\end{samepage}\n\nNote that now (as opposed to insertion) $k > 0$ is required.\nThe main reason is that,\nif $k = 0$, rebalancing would not always work anymore\nas we could not be certain to have at least two subtrees per node.\n\nIn order to prove that \\textit{delete} acts the same as\n\\textit{delete}$_{list}$ on the inorder of the tree,\nwe need to show some inorder properties for the intermediate functions.\nFor the \\textit{del} helper function, \nwe use the same specialized lemmas\nas for \\Cref{thm:isin-set} and \\Cref{thm:ins-set}\nand induct over the execution of the \\textit{del}-function.\n% TODO state or no state? \nRather than stating the specialized lemmas again, we would like to point\nout the benefits of the inorder method at this point.\nIn a first proof attempt, the whole deletion operation was\nproven correct with respect to the standard set interface.\nThis attempt is compared in the following with a rough sketch\nthe proof worked in the inorder approach.\n\nThe reason the rebalancing operations preserve the sortedness and set properties\nis plain when considering the inorder view of the tree:\nit does not change at all.\nA manual proof about the set and sortedness properties\nrequired complicated, unnecessarily lengthy proofs,\nthat involved many case distinctions and sophisticated solvers\nto argue for the validity of node merges.\nFor the inorder view, \nsince the definition can be easily unfolded\nby the automatic simplifier,\nthe following property can be shown automatically.\n\n\\begin{lemma}\n    \\label{lem:rebalance-inorder}\n    All subtrees have the same height $\\Longrightarrow$ \\\\\n    \\begin{align*}\n    \\inorder&\\ (\\rebalancemt_k ls\\ sub\\ sep\\ rs\\ t) =\\\\\n    \\inorder&\\ (Node\\ (ls@(sub,sep)\\#rs)\\ t)\n    \\end{align*}\n\\end{lemma}\n\nConsidering the function split\\_max,\nthe standard approach required showing\nthat the element returned is in fact the maximum\nof the subtree to the left\nand that the remaining tree union the maximum element\ngives the whole original tree set.\nInstead we simply show the following,\ncomprising both facts:\n\n\\begin{lemma}\n    \\label{lem:splitmax-inorder}\n    If t has more than two subtrees, and the last two have equal height, then\n    \\begin{equation*}\n    \\inorder\\ (\\splitmax_k t) = \\inorder t\n    \\end{equation*}\n\\end{lemma}\n\nThis fact follows easily by induction on the computation of split\\_max,\nusing \\Cref{lem:rebalance-inorder}.\nThe reason that these proofs follow so easily\nis the intention behind the definition of both operations.\nThe idea is to obtain the same elements, in the same order,\njust now in a configuration from which we can easily obtain\na new, valid B-tree.\n\nFinally we obtain the last important property of the set interface.\n\\begin{theorem}\n    $k > 0 \\wedge \\order^r_k t \\wedge \\bal t \\wedge \\sorted  (\\inorder t)\\Longrightarrow$\\\\\n    \\begin{center}\n    $\\inorder\\ (\\deletefun_k x\\ t) = \\delfun_{list} x\\ (\\inorder t)$\n    \\end{center}\n\\end{theorem}\n\nWith this, we have proven that \nour implementation of B-trees is proven correct\nfulfils the specifications of the set interface based on an inorder view.\nThe next step towards imperative B-trees is to implement\nan imperative refinement of these set operations.\n", "meta": {"hexsha": "e47ef649ea83a12c940c4d110b49a9ec30d677b0", "size": 52107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_functional.tex", "max_stars_repo_name": "nielstron/btrees-thesis", "max_stars_repo_head_hexsha": "14b6d8a4819378140e5a977e5278ae0a48057f6f", "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": "chapters/02_functional.tex", "max_issues_repo_name": "nielstron/btrees-thesis", "max_issues_repo_head_hexsha": "14b6d8a4819378140e5a977e5278ae0a48057f6f", "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": "chapters/02_functional.tex", "max_forks_repo_name": "nielstron/btrees-thesis", "max_forks_repo_head_hexsha": "14b6d8a4819378140e5a977e5278ae0a48057f6f", "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": 42.5710784314, "max_line_length": 150, "alphanum_fraction": 0.7326462855, "num_tokens": 13643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6044543994280086}}
{"text": "\\subsection{2017 Free-Response Answers}\r\n\r\n\\begin{enumerate}\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Using a left Riemann sum,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{0}^{10}{A(h)\\d{h}} \\approx (2-0)50.3 + (5-2)14.4 + (10-5)6.5 = 100.6 + 43.2 + 32.5 = 176.3.\r\n \t\t\t\\end{equation*}\r\n \t\t\tSo, we approximate that the volume of the tank is 176.3 cubic feet.\r\n \t\t\\item Since we are given that the function is decreasing over the interval, a left Riemann sum will overestimate the volume.\r\n \t\t\\item Integrating $f$ from $h=0$ to $h=10$,\r\n \t\t\t\\begin{equation*}\r\n \t\t\t\t\\int_{0}^{10}{\\frac{50.3}{e^{0.2h}+h}\\d{h}} \\approx 101.325.\r\n \t\t\t\\end{equation*}\r\n \t\t\tSo, the volume of the tank given by $f$ is 101.325 cubic feet.\r\n \t\t\\item We know from (c) that\r\n \t\t\t\\begin{equation*}\r\n \t\t\t\tV(h) = \\int_{0}^{h}{f(x)\\d{x}}.\r\n \t\t\t\\end{equation*}\r\n \t\t\tDifferentiating with respect to $t$, and applying the chain rule,\r\n \t\t\t\\begin{equation*}\r\n \t\t\t\t\\dd{V}{t} = f(h)\\cdot\\dd{h}{t}.\r\n \t\t\t\\end{equation*}\r\n \t\t\tPlugging in $h=5$ and $\\dd{h}{t}=0.26$,\r\n \t\t\t\\begin{equation*}\r\n \t\t\t\t\\dd{V}{t}_{h=5} = \\frac{50.3}{e^1 + 5}\\cdot 0.26 \\approx 1.694.\r\n \t\t\t\\end{equation*}\r\n \t\t\tSo, when $h=5$ feet, the volume is changing at a rate of 1.694 cubic feet per minute.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Finding the area enclosed by $f$ from $\\theta=0$ to $\\theta=\\pi/2$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tA = \\frac{1}{2}\\int_{0}^{\\pi/2}{\\left(1+\\sin{\\theta}\\cos{(2\\theta)}\\right)^2d\\theta} \\approx 0.648.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Our ray $\\theta=k$ will represent a lower bound in one integral and an upper bound in the other.\r\n\t\t\tFinding equal areas between $g$ and $f$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\frac{1}{2}\\int_{0}^{k}{\\left(\\left(2\\cos{\\theta}\\right)^2-\\left(1+\\sin{\\theta}\\cos{(2\\theta)}\\right)^2\\right)d\\theta} = \\frac{1}{2}\\int_{k}^{\\pi/2}{\\left(\\left(2\\cos{\\theta}\\right)^2-\\left(1+\\sin{\\theta}\\cos{(2\\theta)}\\right)^2\\right)d\\theta}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item\r\n\t\t\tSince both $f$ and $g$ are polar functions evaluated at $\\theta$, the distance between then will simply be the difference in their radii.\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tw(\\theta) = g(\\theta) - f(\\theta).\r\n\t\t\t\\end{equation*} \r\n\t\t\tFinding the average of $w$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tw_A = \\frac{1}{\\pi/2 - 0}\\int_{0}^{\\pi/2}{(2\\cos{\\theta}-(1+\\sin{\\theta}\\cos{(2\\theta)}))\\d{\\theta}} \\approx 0.485.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item Solving $w(\\theta) = w_A$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t2\\cos{\\theta}-(1+\\sin{\\theta}\\cos{(2\\theta)}) = 0.485 \\implies \\theta \\approx 0.518.\r\n\t\t\t\\end{equation*}\r\n\t\t\tEvaluating $w^\\prime(0.518)$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tw^\\prime(0.518) \\approx -0.581.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, $w$ is decreasing at this value.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Applying the Fundamental Theorem of Calculus,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\int_{-6}^{-2}{f^\\prime(x)\\d{x}} &= f(-2) - f(-6) = 7 - f(-6) = 4 \\implies f(-6) = 3 \\\\\r\n\t\t\t\t\\int_{-2}^{5}{f^\\prime(x)\\d{x}} &= f(5) - f(-2) = f(5) - 7 = -2\\pi + 3 \\implies f(5) = 10 - 2\\pi.\r\n\t\t\t\\end{align*}\r\n\t\t\\item $f$ is increasing when its derivative is positive.\r\n\t\t\tLooking at the graph of $f^\\prime$, we see it is positive on $[-6,2) \\cup (2,5)$.\r\n\t\t\tSo, $f$ is increasing on $[-6,2] \\cup [2,5]$\\footnote{I personally don't think $f$ is ``increasing'' on the open endpoints where the derivative is 0. I think it's neither increasing nor decreasing. However, the test writers and graders feel differently, and I can't say their view is necessarily wrong.}.\r\n\t\t\\item We see that the critical points of $f^\\prime$ are $x=-2$ and $x=2$.\r\n\t\t\tA minimum can occur at a left/right endpoint that will/was decreasing.\r\n\t\t\tSo, the two points we need to consider for the absolute minimum are $x=-6$ and $x=2$.\r\n\t\t\tWe know from (a) that $f(-6)=3$.\r\n\t\t\tApplying the Fundamental Theorem of Calculus again,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\int_{-2}^{2}{f^\\prime(x)\\d{x}} = f(2) - f(-2) = f(2) - 7 = 2\\pi \\implies f(2) = 7-2\\pi.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince  $7-2\\pi < 3$, the absolute minimum of $f$ is at $x=2$.\r\n\t\t\\item $f^{\\prime\\prime}(-5) = -\\frac{1}{2}$ because $f$ is continuous at -5, and the left and right hand limits are both the slope of the line, which is $-\\frac{1}{2}$.\r\n\t\t\t$f^{\\prime\\prime}(3) = \\text{DNE}$.\r\n\t\t\tThe left hand limit is the slope of the left hand line, which is 2, and the right hand limit is the left of the right hand line, which is -1.\r\n\t\t\tSince the limits do not agree, $f^\\prime$ is not continuous, and hence not differentiable at $x=3$.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Writing the line in point-slope form and then converting to standard form,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\ty - y_0 &= m(t-t_0) \\\\\r\n\t\t\t\ty - H(0) &= \\dd{H}{t}_{t=0}(t-0) \\\\\r\n\t\t\t\ty - 91 &= -16t \\\\\r\n\t\t\t\ty &= -16t + 91.\r\n\t\t\t\\end{align*}\r\n\t\t\tUsing this line to approximate $H(3)$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\ty = -16(3) + 91 = 43.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, the tangent line at $t=0$ approximates $H(3)$ to be $43^\\circ C$.\r\n\t\t\\item Taking the derivative of $\\dd{H}{t}$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\dd{^2H}{t^2} = -\\frac{1}{4}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSince the graph is concave down at every point, the tangent line at $t=0$ gives an overestimate of $H(3)$.\r\n\t\t\\item This is a separable differential equation.\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\dd{G}{t} &= -(G-27)^{2/3} \\\\\r\n\t\t\t\t\\frac{\\d{G}}{(G-27)^{2/3}} &= -1\\d{t} \\\\\r\n\t\t\t\t\\int{\\frac{\\d{G}}{(G-27)^{2/3}}} &= \\int{-1\\d{t}} \\\\\r\n\t\t\t\t3(G-27)^{1/3} &= -t + C \\\\\r\n\t\t\t\t(G-27)^{1/3} &= -t/3 + C \\\\\r\n\t\t\t\tG - 27 &= \\left(-t/3 + C\\right)^3 \\\\\r\n\t\t\t\tG &= \\left(-t/3 + C\\right)^3 + 27.\r\n\t\t\t\\end{align*}\r\n\t\t\tSolving for $C$ using $G(0)=91$,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t91 &= \\left(-0/3 + C\\right)^2 + 27 \\\\\r\n\t\t\t\t64 &= C^3 \\\\\r\n\t\t\t\tC &= 4.\r\n\t\t\t\\end{align*}\r\n\t\t\tSo, our overall solution for $G$ is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tG(t) = \\left(4 - t/3\\right)^3 + 27.\r\n\t\t\t\\end{equation*}\r\n\t\t\tEvaluating at $t=3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tG(3) = \\left(4 - 3/3\\right)^3 + 27 = 3^3  + 27 = 54.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, the internal temperature of the potato at $t=3$ minutes is $54^\\circ C$.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Applying the quotient rule,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tf^\\prime(x) = \\frac{(2x^2-7x+5)(0)-3(4x-7)}{(2x^2-7x+5)^2} = \\frac{-12x+21}{(2x^2-7x+5)^2}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tEvaluating at $x=3$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\tf^\\prime(3) = \\frac{-12(3)+21}{(2(3)^2-7(3)+5)^2} = -\\frac{15}{(18-21+5)^2} = -\\frac{15}{4}.\r\n\t\t\t\\end{equation*}\r\n\t\t\\item $f^\\prime(x)=0$ only when the numerator is 0,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t-12x + 21 = 0 \\implies x = \\frac{7}{4}.\r\n\t\t\t\\end{equation*}\r\n\t\t\t$f^\\prime$ is negative to the left of $\\frac{7}{4}$ and positive to the right of it.\r\n\t\t\tTherefore, $x=\\frac{7}{4}$ is a relative maximum by the first derivative test.\r\n\t\t\\item Evaluating the limit using the given partial fraction decomposition,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\int_{5}^{\\infty}{f(x)\\d{x}} &= \\int_{5}^{\\infty}{\\left(\\frac{2}{2x-5}-\\frac{1}{x-1}\\right)\\d{x}} \\\\\r\n\t\t\t\t&= \\ln{(2x-5)} - \\ln{(x-1)} \\biggr\\rvert_{5}^{\\infty} \\\\\r\n\t\t\t\t&= \\ln{\\left(\\frac{2x-5}{x-1}\\right)} \\biggr\\rvert_{5}^{\\infty} \\\\\r\n\t\t\t\t&= \\lim_{b\\to\\infty}{\\ln{\\left(\\frac{2b-5}{b-1}\\right)}} - \\ln{\\left(\\frac{5}{4}\\right)} \\\\\r\n\t\t\t\t&= \\ln{2} - \\ln{\\left(\\frac{5}{4}\\right)} \\\\\r\n\t\t\t\t&= \\ln{\\left(\\frac{8}{5}\\right)}.\r\n\t\t\t\\end{align*}\r\n\t\t\\item For $n \\geq 5$, $f(n)$ is positive and decreasing.\r\n\t\t\tUsing our work from part (c), we know that the integral of $f$ from 5 to $\\infty$ converges.\r\n\t\t\tSo, by the Integral test, the series also converges.\r\n\t\\end{enumerate}\r\n\r\n\t\\item \\begin{enumerate}\r\n\t\t\\item Calculating the first four derivatives and the general derivative,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tf(0) &= 0 \\\\\r\n\t\t\t\tf^\\prime(0) &= 1 \\\\\r\n\t\t\t\tf^{\\prime\\prime}(0) &= -1\\cdot f^\\prime(0) = -1 \\\\\r\n\t\t\t\tf^{(3)}(0) &= -2\\cdot f^{\\prime\\prime}(0) = 2 \\\\\r\n\t\t\t\tf^{(4)}(0) &= -3\\cdot f^{(3)}(0) = -6.\r\n\t\t\t\tf^{(n+1)}(0) &= -n\\cdot f^{(n)}(0) = (-1)^{n+1}n!.\r\n\t\t\t\\end{align*}\r\n\t\t\tApplying the Maclaurin series formula,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tP_n(x) &= \\frac{f(0)}{0!} + \\frac{f^\\prime(0)}{1!}x + \\frac{f^{\\prime\\prime}(0)}{2!}x^2 + \\ldots + \\frac{f^{(n)}(0)}{n!}x^n \\\\\r\n\t\t\t\t&= \\frac{0}{1} + \\frac{1}{1}x + \\frac{-1}{2}x^2 + \\frac{2}{6}x^3 + \\frac{-6}{24}x^4 + \\ldots + \\frac{(-1)^{n+1}(n-1)!}{n!}x^n \\\\\r\n\t\t\t\t&= x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\frac{x^4}{4} + \\ldots + (-1)^{n+1}\\frac{x^n}{n}.\r\n\t\t\t\\end{align*}\r\n\t\t\\item At $x=1$, the series is\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\sum_{n=1}^{\\infty}{(-1)^{n+1}\\frac{1}{n}}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tThis series converges by the Alternating Series test, which determines conditional converges.\r\n\t\t\tSo, the series converges conditionally at $x=1$.\r\n\t\t\\item Integrating term-by-term,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\tg(x) &= \\int_{0}{x}{f(t)\\d{t}} \\\\\r\n\t\t\t\t&= \\int_{0}^{x}{\\left(t-\\frac{t^2}{2}+\\frac{t^3}{3}-\\frac{t^4}{4}+\\ldots+(-1)^{n+1}\\frac{t^n}{n}\\right)\\d{t}} \\\\\r\n\t\t\t\t&= \\frac{t^2}{2} - \\frac{t^3}{6} + \\frac{t^4}{12} - \\frac{t^5}{20} + \\ldots + (-1)^{n+1}\\frac{t^{n+1}}{n(n+1)} \\biggr\\rvert_{0}^{x} \\\\\r\n\t\t\t\t&= \\frac{x^2}{2} - \\frac{x^3}{6} + \\frac{x^4}{12} - \\frac{x^5}{20} + \\ldots + (-1)^{n+1}\\frac{x^{n+1}}{n(n+1)}.\r\n\t\t\t\\end{align*}\r\n\t\t\\item The Alternating Series Estimation Theorem tells us that the upper bound for the error is the absolute value of the first not included term.\r\n\t\t\tFor $P_4$, this term is $-\\frac{x^5}{20}$.\r\n\t\t\tSo,\r\n\t\t\t\\begin{align*}\r\n\t\t\t\t\\biggr\\lvert P_4\\left(\\frac{1}{2}\\right) - g\\left(\\frac{1}{2}\\right) \\biggr\\rvert < \\biggr\\lvert -\\frac{\\left(\\frac{1}{2}\\right)^5}{20} \\biggr\\rvert = \\frac{1}{640} < \\frac{1}{500}.\r\n\t\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\r\n\\end{enumerate}", "meta": {"hexsha": "877abfb86b81cb74cdb2459eb34ae845e35363fd", "size": 9543, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/additional_materials/2017_answers.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/additional_materials/2017_answers.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/additional_materials/2017_answers.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": 48.6887755102, "max_line_length": 308, "alphanum_fraction": 0.5704705019, "num_tokens": 3931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6044543922472825}}
{"text": "\n\\subsection{One-dimensional uniform dataset}\n\n% We train a two-dimensional map over $25000$ samples drawn from a uniform distribution ($\\mathcal{U}(0, 1)$). The map consists of $1024$ units (neurons) and it is being trained for $25000$ epochs (all the parameters can be found in Table~\\ref{table:parameters}). Figure~\\ref{fig:one-dim}{\\bfseries \\sffamily A} shows the neural space topology of the two-dimensional map after sampling a blue noise distribution and placing the neurons on the corresponding nodes. Figure~\\ref{fig:one-dim}{\\bfseries \\sffamily B} indicates the learned representations after training. In this case the mapping of real numbers within the interval $[0, 1]$ is illustrated in color-code with blue color representing number zero and yellow representing one. It is clear that the map has organize the representations in a descending order starting from the upper left corner (one) of the map to the lower right corner (zero).\n\n% Neurons of both the Kohonen and VSOM maps develop receptive filters during training. Each of these receptive fields usually captures a portion of the input space and learns the reciprocal representations. Therefore, we examine the receptive fields of neurons by evaluating their response to a stimulus. To this end, we feed the map with $6$ input samples after discretizing the interval $[0, 1]$. The activity of each neuron is  computed as the Euclidean distance between the input sample and the neuron's code word. Figures~\\ref{fig:one-dim} {\\sffamily \\bfseries C}-{\\sffamily \\bfseries H}  show the neural activity on the map for $6$ input samples. It is apparent that different regions of the map respond to different stimuli, implying that the topographic organization has been successfully accomplished. \n\n\n\\begin{figure}\n  \\includegraphics[width=\\columnwidth]{experiment-1D-uniform.pdf}\n  \\vspace{2mm}\n  \\centering\n  \\includegraphics[width=.975\\columnwidth]{figures/colormap.pdf}\n  %\n  \\caption{%\n  %\n  {\\bfseries \\sffamily One dimensional uniform dataset with holes (results)}\n  %\n  Randomized SOM made of $1024$ neurons with a $3$-nearest neighbors induced topology. Model has been trained for $25,000$ epochs on one-dimensional points drawn from a uniform distribution on the unit segment. \\textbf{A} Map topology in neural space. \\textbf{B} Map topology in data space. \\textbf{C to H} Receptive field of the map for six samples.\n  %\n  }\n  \\label{fig:1D-uniform:results}\n\\end{figure}\n", "meta": {"hexsha": "931a487a6b66d84b257be71a3c8809a705b4f408", "size": 2445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "article-overleaf/05-appendix-A.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-A.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-A.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": 101.875, "max_line_length": 901, "alphanum_fraction": 0.7775051125, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6044543868617377}}
{"text": "\\newpage\n\\section{Classification Algorithms and Regression Trees}\nThis is from the book by Breiman et. al.\n\nAt the university of California, San Diego Medical Center, when a\nheart attack patient is admitted, 19 variables are measured during the\nfirst 24 hours. They include BP, age and 17 other binary covariates\nsummarizing the medical symptoms considered as important indicators of\nthe patient's condition.\n\nThe goal of a medical study can be to develop a method to identify\nhigh risk patients on the basis of the initial 24-hour data.\n\nThe next figure shows  a picture of a tree structured classification\nrule that was produced in the study. The letter F means no high and\nthe letter G means high risk.\n\n\\centerline{\\epsfig{figure=Plots/plot-07-06.ps,width=\\textwidth}}\n\nHow can we use data to construct trees that give us useful\nanswers. There is a large amount of work done in this type of problem.\nWe will give a brief description in this section.\n\n%%%Karl's notes\n\\subsection{Classifiers as Partitions}\nSuppose we have a categorical outcome\n$y \\in \\mathcal{C} = \\{1, 2, \\ldots, J\\}$. We call ${\\cal C}$ the set\nof classes. Denote  with ${\\cal X}$ the space \nof all possible covariates.\n\nWe can define a classification rule as a function $d(\\bx)$ defined on\n${\\cal X}$ so that for every $\\bx$, $d(\\bx)$ is equal to one of the numbers\n$1,\\dots,J$. \n\nThis could be considered a systematic way of predicting class\nmembership from the covariates.\n\nAnother way to define classifiers is to partition  ${\\cal X}$\ninto disjoint sets $A_1,\\dots,A_j$ with $d(\\bx)=j$ for all $\\bx \\in A_j$.\n\nBut how do we construct these classifiers from data? \n\n\\subsection{What is truth?}\nWe are now going to describe how to construct classification rules\nfrom data. The \ndata we use to construct the tree is called the training set $\\cal L$\nwhich is simply $\\{ (\\bx_1,j_1),\\dots,(\\bx_n,j_n) \\}$.\n\nOnce a classification rule $d(X)$ is constructed how do we define it's\naccuracy? \n\nIn this section we will define the {\\it true misclassification rate}\n$R^*(d)$.\n\n\nOne way to estimate $R^*(d)$ is to draw another very large subset\n(virtually infinite) from the same population as $\\cal L$ and observe\nthe rate of correct classification in that set. The proportion\nmisclassified by $d$ is our estimate of $R^*(d)$. \n\nTo make this definition more precise, define the space ${\\cal X} \\times\n{\\cal C}$ as the set of all couples \n$(\\bx,j)$ where $\\bx \\in {\\cal X}$ and $j \\in {\\cal C}$. Let\n$\\Pr(A,j)$ be a probability distribution on  ${\\cal X} \\times {\\cal\n  C}$. Assume each element of $\\cal L$ is an iid outcome\nfrom this distribution. \n\nWe define the misclassification rate as \n\\begin{equation}\n\\label{mr}\nR^*(d) = \\Pr[d(\\bx) \\neq j | {\\cal L}]\n\\end{equation}\nwith $(\\bx,j)$ an outcome independent of $\\cal L$.\n\nHow do we obtain an estimate of this?\n\nThe {\\it substitution estimate} simply counts how many times we are\nright with the data we have, i.e.\n\\[\nR(d) = \\frac{1}{N} \\sum_{n=1}^N 1_{d(\\bx_n) \\neq j_n}.\n\\]\nThe problem with this estimate is that most classification algorithms\nconstruct $d$ trying to minimize the above equation. If we have enough\ncovariates we can define a rule that always has $d(\\bx_n) = j_n$ and\nrandomly allocates any other $\\bx$. This has an $R(d)=0$ but one can\nsee that, in general, $R^*(d)$ will be much bigger.\n\nAnother popular approach is the {\\it test sample} estimate. Here we\ndivide the data $\\cal L$ into two groups ${\\cal L}_1$ and\n${\\cal L}_2$. We then use ${\\cal L}_1$ to define $d$ and ${\\cal L}_2$\nto estimate $R^*(d)$ with\n\\[\nR(d) =\\frac{1}{N_2} \\sum_{\\bx_n \\in {\\cal L}_2} 1_{d(\\bx_n) \\neq j_n}\n\\]\nwith $N_2$ the size of ${\\cal L}_2$. A popular choice for $N_2$ is\n1/3 of $N$, the size of $\\cal L$.\n\nA problem with this procedure is that we don't use 1/3 of the data\nwhen constructing $d$. In situations where $N$ is very large this may\nnot be such a big problem.\n\nThe third approach is cross validation. We divide the data into many\nsubsets of equal (or approximately equal) size ${\\cal L}_1,\\dots{\\cal\n  L}_V$, define a $d_v$ for each of these groups, and use the estimate\n\\[\nR(d) = \\frac{1}{V}\\sum_{v=1}^V \\frac{1}{N_v} \\sum_{\\bx_n \\in {\\cal L}_v} \n 1_{d(\\bx_n) \\neq j_n}.\n\\]\n\n\\subsection{Bayes Rule}\nThe major guide that has been used in the construction of classifiers\nis the concept of the Bayes rule. A Bayes rule is the $d_B$ for which\n\\[\n\\Pr[d_B(\\bx) \\neq j) \\leq \\Pr[d(\\bx) \\neq y].\n\\]\nfor all classification rules $d(\\bx)$.\n\nIf we assume that $\\Pr(A | j)$ has a probability density  $f_j(\\bx)$\nsuch that\n\\[\n\\Pr(A|j) = \\int_A f_j(\\bx) \\, dx\n\\]\nthen we can show\nthat\n\\[\nd_B(\\bx) = j \\mbox{ on } A_j = \\{\\bx; f_j(\\bx)\\Pr(j) = \\max_i\nf_i(\\bx)\\Pr(j) \\}.\n\\]\n\n\nDiscriminant analysis, kernel density estimation, and $k$-th nearest\nneighbor smoothing attempt to estimate $f_j(\\bx)$ and $\\Pr(j)$ in\norder to estimate the Bayes rule. They make many assumptions so the\nmethods are not always useful.\n\n\n\\subsection{Constructing tree classifiers}\nNotice how big the space of all possible classifiers is. In the simple\ncase where ${\\cal X} = \\{0,1\\}^p$ this space has $2^p$ elements. \n\nBinary trees are a special case of this partition. Binary trees are\nconstructed by repeated splits of the subsets of ${\\cal X}$ into two\ndescendant subsets, beginning with ${\\cal X}$ itself. \n\n\\setlength{\\unitlength}{1.0cm}\n\\begin{center}\n\\begin{picture}(12,11)\n\n% circles\n\\thicklines\n\\put(6,10){\\circle{2}}\n\\put(3.5,7.5){\\circle{2}}\n\\put(8.5,7.5){\\circle{2}}\n\\put(10.5,4.5){\\circle{2}}\n\n% boxes\n\\put(1.25,3.5){\\framebox(1.5,1.5)[]{${\\cal X}_5$}}\n\\put(4.25,3.5){\\framebox(1.5,1.5)[]{${\\cal X}_6$}}\n\\put(6.25,3.5){\\framebox(1.5,1.5)[]{${\\cal X}_7$}}\n\\put(8.25,0.5){\\framebox(1.5,1.5)[]{${\\cal X}_8$}}\n\\put(11.25,0.5){\\framebox(1.5,1.5)[]{${\\cal X}_9$}}\n\n% lines\n\\put(5.5,9.5){\\line(-1,-1){1.5}}\n\\put(6.5,9.5){\\line(1,-1){1.5}}\n\\put(3,7){\\line(-1,-2){1}}\n\\put(4,7){\\line(1,-2){1}}\n\\put(8,7){\\line(-1,-2){1}}\n\\put(9,7){\\line(1,-2){1}}\n\\put(10,4){\\line(-1,-2){1}}\n\\put(11,4){\\line(1,-2){1}}\n\n% text\n\\put(6,10){\\makebox(0,0)[]{${\\cal X}$}}\n\\put(3.5,7.5){\\makebox(0,0)[]{${\\cal X}_2$}}\n\\put(8.5,7.5){\\makebox(0,0)[]{${\\cal X}_3$}}\n\\put(10.5,4.5){\\makebox(0,0)[]{${\\cal X}_4$}}\n\n\\put(6,8.75){\\makebox(0,0)[]{Split 1}}\n\\put(3.45,6){\\makebox(0,0)[]{Split 2}}\n\\put(8.45,6){\\makebox(0,0)[]{Split 3}}\n\n\\put(10.45,3){\\makebox(0,0)[]{Split 4}}\n\\end{picture} \\end{center}\n\nThe subsets created by the splits are called {\\it nodes}. The subsets\nwhich are not split are called terminal nodes. \n\nEach terminal nodes gets\nassigned to one of the classes. So if we had 3 classes we could get $A_1\n= {\\cal X}_5 \\cup {\\cal X}_9$, $A_2 ={\\cal X}_6$ and $A_3 ={\\cal X}_7 \\cup {\\cal X}_8$.\nIf we are using  the data we assign the class most frequently found in\nthat subset of ${\\cal X}$. We call these classification tress.\n\nVarious question still remain to be answered\n\\begin{itemize}\n\\item How do we define truth?\n\\item How do we construct the trees from data?\n\\item How do we assess trees, i.e. what makes a good tree?\n\\end{itemize}\n\nThe first problem in tree construction is how to use $\\cal L$ to\ndetermine the binary splits of $\\cal X$ into smaller and smaller\npieces. The fundamental idea is to select each split of a subset so that\nthe data in each of the descendant subsets are ``purer'' than the data\nin the parent subset.\n\nThis can be implemented in the following way\n\n\\begin{itemize}\n\\item Define the node proportions $p(j|t)$ to be the proportion of\n  cases $\\bx_n \\in t$ belonging to class $j$ so that $\\sum_j p(j|t) =\n  1$.\n\n\\item Define a measure of impurity $i(t)$ as a nonnegative function\n  $\\phi$ such that it reaches its maximum at $\\phi(1/n,\\dots,1/n)$,\n$\\phi(1,0,\\dots,0)=0$,  and is symmetric with respect to its entries.\n\nA popular example is the entropy\n\\[\ni(t) = - \\sum_{j=1}^J p(j|t) \\log p(j|t),\n\\]\nbut there are many other choices.\n\n\\item Define a set $\\cal S$ of binary splits $s$ at each node. Then we\n  chose the split that minimize the impurity of the new left and right\n  nodes\n\\[\n\\Delta i(s,t) = i(t) - p_L i(t_l) + p_R i(t_R)\n\\]\n\n\\end{itemize}\n\n\nThere are many different possible splits. For continuous variables\nthere are an infinite amount. We need to define the set of splits\n$\\cal S$ that we consider.\n\nMost implementations require that the the splits are defined by only\none covariate, but fancier versions permit the use of linear combinations. \n\nIf the covariate is continuous or ordered then the split must be\ndefined by $x < c$ and $x \\geq c$.  \n\nIf the covariate is categorical then we simply consider all splits\nthat divide original set into two.\n\n\\setlength{\\unitlength}{1.0cm}\n\\begin{center}\n\\begin{picture}(12,11)\n\n% circles\n\\thicklines\n\\put(6,10){\\circle{2}}\n\\put(3.5,7.5){\\circle{2}}\n\\put(8.5,7.5){\\circle{2}}\n\\put(10.5,4.5){\\circle{2}}\n\n% boxes\n\\put(1.25,3.5){\\framebox(1.5,1.5)[]{1}}\n\\put(4.25,3.5){\\framebox(1.5,1.5)[]{2}}\n\\put(6.25,3.5){\\framebox(1.5,1.5)[]{1}}\n\\put(8.25,0.5){\\framebox(1.5,1.5)[]{2}}\n\\put(11.25,0.5){\\framebox(1.5,1.5)[]{3}}\n\n% lines\n\\put(5.5,9.5){\\line(-1,-1){1.5}}\n\\put(6.5,9.5){\\line(1,-1){1.5}}\n\\put(3,7){\\line(-1,-2){1}}\n\\put(4,7){\\line(1,-2){1}}\n\\put(8,7){\\line(-1,-2){1}}\n\\put(9,7){\\line(1,-2){1}}\n\\put(10,4){\\line(-1,-2){1}}\n\\put(11,4){\\line(1,-2){1}}\n\n% text\n\\put(6,10){\\makebox(0,0)[]{$x_1$}}\n\\put(3.5,7.5){\\makebox(0,0)[]{$x_2$}}\n\\put(8.5,7.5){\\makebox(0,0)[]{$x_3$}}\n\\put(10.5,4.5){\\makebox(0,0)[]{$x_2$}}\n\n\\put(4.25,9.25){\\makebox(0,0)[]{$< 5$}}\n\\put(7.75,9.25){\\makebox(0,0)[]{$\\ge 5$}}\n\\put(1.75,6){\\makebox(0,0)[]{$> 3$}}\n\\put(5.25,6){\\makebox(0,0)[]{$\\le 3$}}\n\\put(6.75,6){\\makebox(0,0)[]{$= 2$}}\n\\put(10.25,6){\\makebox(0,0)[]{$\\ne 2$}}\n\\put(8.75,3){\\makebox(0,0)[]{$> 1$}}\n\\put(12.25,3){\\makebox(0,0)[]{$\\le 1$}}\n\\end{picture} \n\\end{center}\n\nNow all we need is a stopping rule and we are ready to create trees. A\nsimple stopping rule is that $\\Delta i(s,t) < \\delta$, but this does\nnot work well in practice. \n\nWhat is usually done is that we let the trees grow to a size that is\nbigger than what we think makes sense and then prune. We remove node\nby node and compare the trees using estimates of $R^*(d)$.\n\nSometimes to save time and/or choose smaller trees we define a\npenalized criterion based on  $R^*(d)$. \n\n\nThe big issue here is \\emph{model selection}.  The model\nselection problem consists of four orthogonal components.\n\n\\begin{enumerate}\n\n\\item Select a space of models\n\n\\item Search through model space\n\n\\item Compare models\n  \\begin{itemize}\n    \\item of the same size\n    \\item of different sizes (penalize complexity)\n  \\end{itemize}\n\n\\item Assess the performance of a procedure\n\n\\end{enumerate}\n\n%\\vsphalf\n\n\\textbf{Important points}:\n\\begin{itemize}\n\\item Components 2 and 3 are often confused (e.g., in\n  stepwise regression).  That's bad.  \n\n\\item People often forget component 1.\n  \n\\item People almost always ignore component 4; it can be the hardest.\n\n\\end{itemize} \n\n\nBetter trees may be found by doing a one-step ``look ahead,'' but this\ncomes with the cost of a great increase in computation.\n\n\n\\subsection{Regression Trees}\nIf instead of classification we are interested in predicting we can\nassign a predictive value to each of the terminal nodes. Notice that\nthis defines an estimate for the regression function\n$\\E(Y|X_1,\\dots,X_n)$ that is like a multidimensional bin smoother.\nWe call these regression trees.\n\nRegression trees are constructed in a similar way to classification\ntrees. They are used for the case where $Y$ is a\ncontinuous random variable. \n\n\n\nA regression tree partitions $x$-space into disjoint regions $A_k$\nand provides a fitted value $\\E(y | x \\in A_k)$ within each region.\n\n\\setlength{\\unitlength}{1.0cm}\n\\begin{center}\n\\begin{picture}(12,11)\n\n% circles\n\\thicklines\n\\put(6,10){\\circle{2}}\n\\put(3.5,7.5){\\circle{2}}\n\\put(8.5,7.5){\\circle{2}}\n\\put(10.5,4.5){\\circle{2}}\n\n% boxes\n\\put(1.25,3.5){\\framebox(1.5,1.5)[]{13}}\n\\put(4.25,3.5){\\framebox(1.5,1.5)[]{34}}\n\\put(6.25,3.5){\\framebox(1.5,1.5)[]{77}}\n\\put(8.25,0.5){\\framebox(1.5,1.5)[]{51}}\n\\put(11.25,0.5){\\framebox(1.5,1.5)[]{26}}\n\n% lines\n\\put(5.5,9.5){\\line(-1,-1){1.5}}\n\\put(6.5,9.5){\\line(1,-1){1.5}}\n\\put(3,7){\\line(-1,-2){1}}\n\\put(4,7){\\line(1,-2){1}}\n\\put(8,7){\\line(-1,-2){1}}\n\\put(9,7){\\line(1,-2){1}}\n\\put(10,4){\\line(-1,-2){1}}\n\\put(11,4){\\line(1,-2){1}}\n\n% text\n\\put(6,10){\\makebox(0,0)[]{$x_1$}}\n\\put(3.5,7.5){\\makebox(0,0)[]{$x_2$}}\n\\put(8.5,7.5){\\makebox(0,0)[]{$x_3$}}\n\\put(10.5,4.5){\\makebox(0,0)[]{$x_2$}}\n\n\\put(4.25,9.25){\\makebox(0,0)[]{$< 5$}}\n\\put(7.75,9.25){\\makebox(0,0)[]{$\\ge 5$}}\n\\put(1.75,6){\\makebox(0,0)[]{$> 3$}}\n\\put(5.25,6){\\makebox(0,0)[]{$\\le 3$}}\n\\put(6.75,6){\\makebox(0,0)[]{$= 2$}}\n\\put(10.25,6){\\makebox(0,0)[]{$\\ne 2$}}\n\\put(8.75,3){\\makebox(0,0)[]{$> 1$}}\n\\put(12.25,3){\\makebox(0,0)[]{$\\le 1$}}\n\\end{picture} \\end{center}\n\nIn other words, this is a decision tree where the outcome is a\nfitted value for $y$.\n\n\nWe need a new definition $d(\\bx)$ and $R^*(d)$.\n\nNow $d(\\bx_j)$ will simply be the average of the terminal node where\n$\\bx_j$ lies. So $d(\\bx)$ defines a step-function ${\\mathbb R}^p\n\\rightarrow {\\mathbb R}$.\n\nInstead of misclassification rate, we can define mean squared error\n\\[\nR^*(d) = \\E[ Y - d(\\bx) ]^2\n\\]\n\nThe rest is pretty much the same.\n\\subsection{General points}\n\nFrom Karl Broman's notes.\n\n\\begin{itemize}\n\n\\item This is most natural when the explanatory variables are\n  categorical (and it is especially nice when they are \\emph{binary}).\n\n\\item There is nothing special about the tree structure...the tree\n  just partitions $x$-space, with a fitted value in each region.\n\n\\item \\textbf{Advantage}: These models go after\n  \\emph{interactions\\/} immediately, rather than as an afterthought.  \n\n\\item \\textbf{Advantage}: Trees can be easy to explain to\n  non-statisticians. \n  \n\\item \\textbf{Disadvantage}: Tree-space is huge, so we may need\n  \\emph{a lot\\/} of data.\n  \n\\item \\textbf{Disadvantage}: It can be hard to assess uncertainty in\n  inference about trees.\n\n\\item \\textbf{Disadvantage}: The results can be quite variable.  (Tree\n  selection is not very \\emph{stable}.)\n\n\\item \\textbf{Disadvantage}: Actual \\emph{additivity\\/} becomes a mess\n  in a binary tree.  This problem is somewhat alleviated by allowing\n  splits of the form $x_1 + b x_2 < (\\ge) \\; d$.\n\n\\end{itemize}\n\n\n\n\n\n\\centerline{\\textbf{Computing with trees}}\n\n%\\HRule\n\n%\\vsphalf\n\n\n\\textbf{R}: \\verb|library(tree)|; \\verb|library(rpart)|  \n[MASS, ch 10]\n\n%\\vspone\n\n\\textbf{An important issue}: Storing trees\n\n%\\vsphalf\n\nBinary trees are composed of nodes (root node, internal nodes and\nterminal nodes).\n\n%\\vsphalf\n\n\\emph{Root and internal nodes}:\n\\begin{itemize}\n\\item Splitting rule (variable + what goes to right)\n\\item Link to left and right daughter nodes\n\\item Possibly a link to the parent node (null if this is the root\n  node)\n\\end{itemize}\n\n\\emph{Terminal nodes}:\n\\begin{itemize}\n\\item Fitted value\n\\item Possibly a link to the parent node\n\\end{itemize}\n\n%\\vspone\n\n\\textbf{C}: Use pointers and structures (\\verb|struct|)\n\n%\\vsphalf\n\n\\textbf{R}: It beats me.  Take a look.\n\n\n\n\n\\textbf{Ref}: Breiman et al (1984) Classification and regression\ntrees.  Wadsworth.\n", "meta": {"hexsha": "f375ecbefacb18a4fc00c814f8616e75f140a2de", "size": 15078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-07-03.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-07-03.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-07-03.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": 29.9761431412, "max_line_length": 87, "alphanum_fraction": 0.6795330946, "num_tokens": 5305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.604391066675588}}
{"text": "\\subsection{Well-balanced Property with Uncertain Topography}\n\nIn this section it is shown that the stochastic Galerkin model satisfies the well-balanced property for a lake-at-rest with uncertain topography.\nA lake at rest is an idealised scenario where the free-surface is entirely flat and motionless, much like still water in a lake.\nAssuming a lake-at-rest for the stochastic model, the mean free-surface elevation is constant and the mean discharge is zero, and there is no uncertainty in the free-surface elevation or discharge.\nThe bed elevation can have any spatial profile and stochastic profile.\n\nSince the free-surface elevation is constant and the averaged bed elevation is continuous at interfaces then $\\eta_{i+1/2,p}^- - z^\\star_{i+1/2,p} = \\eta_{i+1/2,p}^+ - z^\\star_{i+1/2,p}$, hence $h^{-,\\star}_{i+1/2,p} = h^{+,\\star}_{i+1/2,p}$ for all $i = 0, \\ldots, M$ and $p = 0, \\ldots, P$.\nShorthand notation is introduced such that\n$\\eta_p$ is the $p$\\textsuperscript{th} expansion coefficient of the spatially uniform free-surface elevation, and\n$h^\\star_{i+1/2,p} = h^{-,\\star}_{i+1/2,p} = h^{+,\\star}_{i+1/2,p}$.\nSince $h^\\star_{i+1/2,p}$ is continuous at interfaces and the discharge is zero then the numerical flux is equal to the physical flux.\n\nIn order to preserve a lake-at-rest solution in element $i$ then the ensemble average of the flux gradient must balance the ensemble average of the source term vector in equation~\\eqref{eqn:swe-pc}.\nThe balance of mass and momentum components can be considered separately.\nThe mass continuity equation balances because the discharge is zero.\nFor the momentum equation, the following equality must hold for all $l = 0, \\ldots, P$:\n\\begin{align}\n\\frac{\\Ensemble{F_{i+1/2}^{(n)} \\pcbasis_l} - \\Ensemble{F_{i-1/2}^{(n)} \\pcbasis_l}}{\\Delta x}\n-\n\\Ensemble{S_i^{(n)} \\pcbasis_l}\n= 0\n\\label{eqn:momentum-balance-separate}\n\\end{align}\nwhere the ensemble average of the bed slope source term $\\Ensemble{S_i^{(n)} \\pcbasis_l}$ is given by equation~\\eqref{eqn:pc-source} and the momentum flux $F_{i+1/2}^{(n)}$ is\n\\begin{align}\nF_{i+1/2}^{(n)} = \\frac{g}{2}\n\\left\\{\\sum_{p=0}^P h^\\star_{i+1/2,p} \\pcbasis_p\\right\\}\n\\left\\{\\sum_{s=0}^P h^\\star_{i+1/2,s} \\pcbasis_s\\right\\}\n\\end{align}\nand similarly for $F_{i-1/2}^{(n)}$.\nDue to the distributivity property of the basis (equation~\\ref{eqn:distributive}), equation~\\eqref{eqn:momentum-balance-separate} can be rewritten as\n\\begin{align}\n\\Ensemble{\\frac{F_{i+1/2}^{(n)} \n-\nF_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n=\n\\Ensemble{ S_i^{(n)} \\pcbasis_l}\n\\label{eqn:momentum-balance}\n\\end{align}\nThe ensemble average of the momentum flux gradient is\n\\begin{align}\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &=\n    \\frac{g}{2 \\Delta x}\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left( h^\\star_{i+1/2,p} \\, h^\\star_{i+1/2,\\palt} - \n    h^\\star_{i-1/2,p} \\, h^\\star_{i-1/2,\\palt} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l}\n    \\label{eqn:momentum-flux-unfactorised}\n%\n\\intertext{To be able to factorise equation~\\eqref{eqn:momentum-flux-unfactorised}, the first step is to add then subtract the term $h^\\star_{i-1/2,p} h^\\star_{i+1/2,s}$ to yield}\n%\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &=\n    \\frac{g}{2 \\Delta x}\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left( h^\\star_{i+1/2,p} \\, h^\\star_{i+1/2,\\palt} - \n    h^\\star_{i-1/2,p} \\, h^\\star_{i-1/2,\\palt} + \\right. \\nonumber \\\\\n    &\\left.\n    \\hspace{6em}\n    h^\\star_{i-1/2,p} \\, h^\\star_{i+1/2,s} -\n    h^\\star_{i-1/2,p} \\, h^\\star_{i+1/2,s} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l}\n    \\label{eqn:momentum-flux-4term}\n%\n\\intertext{Using the distributivity property of multiplication, and associativity of summation, equation~\\eqref{eqn:momentum-flux-4term} can be rewritten as}\n%\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &=\n    \\frac{g}{2 \\Delta x}\n    \\left[\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left( h^\\star_{i+1/2,p} \\, h^\\star_{i+1/2,\\palt} - \n    h^\\star_{i-1/2,p} \\, h^\\star_{i-1/2,\\palt} + \n    h^\\star_{i-1/2,p} \\, h^\\star_{i+1/2,s}\n    \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l}\n    \\right.\n    \\nonumber \\\\\n    &\\left.\n    \\hspace{2.5em}\n    - \n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    h^\\star_{i-1/2,p} \\, h^\\star_{i+1/2,s}\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l} \\right]\n    \\label{eqn:momentum-flux-split}\n%\n\\intertext{\nThe final term in equation~\\eqref{eqn:momentum-flux-split} can be rewritten as $\\sum_{p=0}^P \\sum_{s=0}^P h^\\star_{i-1/2,s} \\, h^\\star_{i+1/2,p} \\Ensemble{\\pcbasis_p \\pcbasis_s \\pcbasis_l}$ due to commutativity of summation and product operators as well as the basis function (equation~\\ref{eqn:commutative}).\nThen, by associativity of summation:\n}\n%\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &=\n    \\frac{g}{2 \\Delta x}\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left( h^\\star_{i+1/2,p} \\, h^\\star_{i+1/2,\\palt} - \n    h^\\star_{i-1/2,p} \\, h^\\star_{i-1/2,\\palt} + \\right. \\nonumber \\\\\n    &\\left.\n    \\hspace{6em}\n    h^\\star_{i-1/2,p} \\, h^\\star_{i+1/2,s} -\n    h^\\star_{i-1/2,s} \\, h^\\star_{i+1/2,p} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l}\n    \\label{eqn:momentum-flux-4term-reordered}\n%\n\\intertext{Finally, equation~\\eqref{eqn:momentum-flux-4term-reordered} can be factorised as}\n%\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &= \n    \\frac{g}{2 \\Delta x}\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left( h^\\star_{i-1/2,p} + h^\\star_{i+1/2,p} \\right)\n    \\left( h^\\star_{i+1/2,s} - h^\\star_{i-1/2,s} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l} \\\\\n%\n\\intertext{and, given that $h^\\star_{i+1/2,s} = \\eta_s - \\zmodified_{i+1/2,s}$ and $h^\\star_{i-1/2,s} = \\eta_s - \\zmodified_{i-1/2,s}$, then}\n    \\Ensemble{\\frac{F_{i+1/2}^{(n)} \n    -\n    F_{i-1/2}^{(n)}}{\\Delta x} \\pcbasis_l}\n    &=\n    -\\frac{g}{\\Delta x}\n    \\sum_{p=0}^P \\sum_{\\palt=0}^P\n    \\left(\n    \\frac{h^{+,\\star}_{i-1/2,p} + h^{-,\\star}_{i+1/2,p}}{2}\n    \\right)\n    \\left( \\zmodified_{i+1/2,\\palt} - \\zmodified_{i-1/2,\\palt} \\right)\n    \\Ensemble{\\pcbasis_p \\pcbasis_\\palt \\pcbasis_l}\n    \\label{eqn:momentum-flux}\n\\end{align}\nEquation~\\eqref{eqn:momentum-flux} is equal to the ensemble average of the bed slope source term $\\Ensemble{S_i^{(n)} \\pcbasis_l}$ given in equation~\\eqref{eqn:pc-source}, hence discrete balance is preserved.\n", "meta": {"hexsha": "acd69969cfa3e8f6e9986595a74fff8b0e3d5189", "size": 6508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "overleaf/cproperty.tex", "max_stars_repo_name": "hertzsprung/seamless-wave-uq", "max_stars_repo_head_hexsha": "10a9b2e18d11cf3f4e711a90523f85758e5fb531", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "overleaf/cproperty.tex", "max_issues_repo_name": "hertzsprung/seamless-wave-uq", "max_issues_repo_head_hexsha": "10a9b2e18d11cf3f4e711a90523f85758e5fb531", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "overleaf/cproperty.tex", "max_forks_repo_name": "hertzsprung/seamless-wave-uq", "max_forks_repo_head_hexsha": "10a9b2e18d11cf3f4e711a90523f85758e5fb531", "max_forks_repo_licenses": ["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.8309859155, "max_line_length": 309, "alphanum_fraction": 0.6425937308, "num_tokens": 2578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6043910585652688}}
{"text": "\\section{Rule Derivation}\n\nRules derived are stored in \\textit{rule\\_base.txt}, together with the definitions of fuzzy sets.\n\n\\subsection{Manual Rule Derivation}\n\nAfter observing a couple of patterns from data in the prototyping set and reasoning about their validities, we come up with several heuristics.\n\nFirst we notice that $Extent$ is a very good feature to start with: triangles have a $Extent$ ratio close to 0.5, rectangles and squares have a $Extent$ ratio close to 1, while circles and ellipses have a $Extent$ ratio of around 0.75 $\\sim$ 0.85.\n\nThen we can use $Thinness$ ratio to distinguish circles and ellipses, because circle has the smallest thinness ($=4\\pi$) among all 2D figures,.\n\nSimilarily, when rectangles have $Thinness$ ratio close to 16, they become squares.\n\nFor the feature $Corners$, as mentioned in Section 3.3, it's a very shaky feature for our task. Therefore we decide not to use it.\n\nFinally, we obtain 5 simple rules:\n\n\\begin{enumerate}\n\n\\item \\textit{IF Thinness IS LIKE Circle AND Extent IS LIKE ellipse THEN Shape IS Circle}\n\\item \\textit{IF Thinness IS NOT LIKE Circle AND Extent IS LIKE ellipse THEN Shape IS Ellipse}\n\\item \\textit{IF Extent IS LIKE Triangle THEN Shape IS Triangle}\n\\item \\textit{IF Thinness IS LIKE Square AND Extent IS LIKE rectangle THEN Shape IS Square}\n\\item \\textit{IF Thinness IS NOT LIKE Square AND Extent IS LIKE rectangle THEN Shape IS Rectangle}\n\n\\end{enumerate}\n\n\\subsection{Autonomous Rule Derivation}\n\nWe will discuss the possibility of autonomous rule derivation in Section 7.\n", "meta": {"hexsha": "00265f5aac1939292625d270cf00b826d64042d9", "size": 1550, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/rule_derivation.tex", "max_stars_repo_name": "dnc1994/Shape", "max_stars_repo_head_hexsha": "9d49bd4bdbbc18404dede74c0f878418b1074d8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-01-13T08:42:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T17:31:57.000Z", "max_issues_repo_path": "report/rule_derivation.tex", "max_issues_repo_name": "dnc1994/Shape", "max_issues_repo_head_hexsha": "9d49bd4bdbbc18404dede74c0f878418b1074d8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-01-13T08:47:58.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-10T18:17:12.000Z", "max_forks_repo_path": "report/rule_derivation.tex", "max_forks_repo_name": "dnc1994/Shape", "max_forks_repo_head_hexsha": "9d49bd4bdbbc18404dede74c0f878418b1074d8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-04-30T14:42:59.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-30T14:42:59.000Z", "avg_line_length": 48.4375, "max_line_length": 247, "alphanum_fraction": 0.7806451613, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998714925403, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6041950902223197}}
{"text": "\\chapter{Feature Selection}\n\n\\newthought{Sometimes, measuring features is expensive} or training a model needs to be fast yet accurate. It can also happen that a large number of features make the model difficult to interpret. Hence it is handy to know which features are actually important for the model and which are redundant. And in order to determine which are those features, we use a process called feature scoring.\n\n\\begin{wrapfigure}{o}{0.6\\textwidth}\n    \\vspace{-0.5cm}\n    \\includegraphics[scale=0.4]{workflow.png}\n\\end{wrapfigure}\n\nThere are several scoring methods, some of which are univariate (they look at the relationship between a single feature and the target variable), some are multivariate (they can consider multiple features), and some are model-based (they use models to estimate feature importance). \n\nOne such scoring technique is called \\textit{information gain}. Let us consider feature X and the target variable Y. Information gain is a univariate method measuring the amount of information gained Y knowing the value of X.\n\n%box plot\nA similar method is \\textit{Gini decrease}, which also measures decrease in impurity after observing the variable (X). They both favor multilabel features, because they tend to split the data more resulting in purer subsets. This was the reason behind conception of \\textit{Relief} (later improved to ReliefF), which handles multilabel and numeric data better. It also has one important advantage - it is a multivariate method, which means it can handle the so-called XOR problems\\marginnote{An XOR problem is a problem where the final class would be a result of }\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4]{test_and_score.png}\n    \\caption{Cross validation splits the data sets into, say, 10 different non-overlapping subsets we call folds. In each iteration, one fold will be used for testing, while the data from all other folds will be used for training. In this way, each data instance will be used for testing exactly once.}\n\\end{figure}\n", "meta": {"hexsha": "2051ec110e5ede6a74b67c32ecd228bff05618d4", "size": 2032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/033-feature-selection/feature-selection.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/033-feature-selection/feature-selection.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/033-feature-selection/feature-selection.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": 92.3636363636, "max_line_length": 564, "alphanum_fraction": 0.7898622047, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6041950741821941}}
{"text": "\\documentclass{article}\n%include polycode.fmt\n\n\\begin{document}\n\nNot so long ago, an older post of mine about \\href{2018-07-12-llc-in-agda.html}{LLC in Agda} circulated on Twitter.\nOne comment was: \\emph{it's typing with leftovers!}. What does that mean? you may ask; let me show.\n\nThis is the post with fancy \\LaTeX\\ formulas :)\n\n\\subsection{An example with times}\n\nIn \\href{2019-06-26-linear-church-encodings.html}{Church encoding of linear types} post,\nwe wrote a right rule for times as (slightly adjusted)\n\n\n\\begin{code}\n Γ ==> x : X    Γ ==> y : Y\n---------------------------- ⊗R\n Γ₁,Γ₂ ==> pair x y : X ⊗ Y\n\\end{code}\n\nAnd the fancy \\LaTeX\\ version of it looks like:\n\n\\begin{equation*}\n\\prftree[r]{${\\otimes}\\text{R}$}{\n\\Gamma_1 \\Longrightarrow x:X\n}{\n\\Gamma_2 \\Longrightarrow y:Y\n}{\n\\Gamma_1,\\Gamma_2 \\Longrightarrow \\mathtt{pair}\\;x\\;y : X \\otimes Y\n}\n\\end{equation*}\n\nIn this version, we somehow know how to split the context into two parts,\nto construct halves of times-pair.\n\nAnother way to formulate rules, is using leftover contexts:\n\n\\begin{equation*}\n\\prftree[r]{${\\otimes}\\text{R}$}{\n\\Gamma_1 \\xRightarrow{\\displaystyle\\;x:X\\;\\;} \\Gamma_2\n}{\n\\Gamma_2 \\xRightarrow{\\displaystyle\\;y:Y\\;\\;} \\Gamma_3\n}{\n\\Gamma_1 \\xRightarrow{\\displaystyle\\;\\mathtt{pair}\\;x\\;y : X \\otimes Y\\;\\;} \\Gamma_3\n}\n\\end{equation*}\n\nWe start with $\\Gamma_1$ context, try to construct $x:X$. Its construction\nuses as much stuff from context as it needs, leaving over some context $\\Gamma_2$.\nThen we continue with $\\Gamma_2$ context trying to construct $y:Y$, and get\nanother residual context $\\Gamma_3$. So starting with $\\Gamma_1$ context,\nwe can construct a pair $X \\otimes Y$, with a leftover $\\Gamma_3$.\n\n\\subsection{A few more rules}\n\nWe'll need few more rules to make large enough fragment of logic to show\nmeaningful example: Identity rule, left rule for times an\nright and left rules for linear implication and one.\nThis fragment is called \\emph{Multiplicative Intuitionistic Linear Logic},\nor MILL for short.\n\n\\begin{equation*}\n\\prfbyaxiom{\\sc Id}\n{\n\\Gamma, x : X \\xRightarrow{\\displaystyle\\; x : X\\;\\;} \\Gamma\n}\n\\end{equation*}\n\n\\begin{equation*}\n\\frac{\n\\Gamma_1, x : X, y : Y \\xRightarrow{\\displaystyle\\;z : Z\\;\\;} \\Gamma_2\n}{\n\\Gamma_1, p : X \\otimes Y \\xRightarrow{\\displaystyle\\mathtt{case}\\;p\\;\\mathtt{of}\\;\\mathtt{pair}\\;x\\;y \\mathrel{\\mapsto} z : Z\\;\\;} \\Gamma_2\n}\\,{\\otimes}\\text{L}\n\\end{equation*}\n\n\\begin{equation*}\n\\frac {\n\\Gamma_1, x : X \\xRightarrow{\\displaystyle\\;y:Y\\;\\;} \\Gamma_2\n}{\n\\Gamma_1 \\xRightarrow{\\displaystyle\\;\\lambda\\,x \\mapsto y : X \\multimap Y} \\Gamma_2\n}\\,{\\multimap}\\text{R}\n\\qquad\\qquad\n\\frac{\n\\Gamma_1 \\xRightarrow{\\displaystyle\\;x : X\\;\\;} \\Gamma_2\n\\qquad\n\\Gamma_2, f\\,x : Y \\xRightarrow{\\displaystyle\\; z : Z \\;\\;}\\Gamma_3\n}{\n\\Gamma_1, f : X \\multimap Y \\xRightarrow{\\displaystyle\\; z : Z\\;\\;} \\Gamma_3\n}\\,{\\multimap}\\text{L}\n\\end{equation*}\n\n\\begin{equation*}\n\\prftree[r]{$1\\text{R}$}\n{\\\n}\n{\n\\Gamma \\RightarrowLabel{\\mathtt{one} : 1} \\Gamma\n}\n\\qquad\\qquad\n\\prftree[r]{$1\\text{L}$}\n{\n\\Gamma_1 \\RightarrowLabel{z : Z} \\Gamma_2\n}\n{\n\\Gamma_1, x : 1 \\RightarrowLabel{z : Z} \\Gamma_2\n}\n\\end{equation*}\n\n\\subsection{Linear curry}\n\nLet us see how this work in practice. Let's write\n$\\mathtt{curry} : ((X \\otimes Y) \\multimap Z) \\multimap X \\multimap Y \\multimap Z$.\n\nFirst we'll write in \"a traditional style\". I'll omit proof terms for brevity.\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\multimap}\\text{R}^3$}{\n  \\prftree[r]{${\\multimap}\\text{L}$}{\n    \\prftree[r]{${\\otimes}R$}{\n      \\prfbyaxiom{\\sc Id}{X \\Longrightarrow X}\n    }{\n      \\prfbyaxiom{\\sc Id}{Y \\Longrightarrow Y}\n    }{\n      X,Y \\Longrightarrow X \\otimes Y\n    }\n  }{\n    \\prfbyaxiom{\\sc Id}{Z \\Longrightarrow Z}\n  }{\n  X \\otimes Y \\multimap Z, X, Y  \\Longrightarrow Z\n  }\n}{\n\\bullet \\Longrightarrow (X \\otimes Y \\multimap Z) \\multimap X \\multimap Y \\multimap Z\n}\n\\end{equation*}\n\nThe proof term is\n\n\\begin{code}\ncurry = \\f x y -> f (pair x y)\n\\end{code}\n\nLet's see the with leftovers derivation tree.\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\multimap}\\text{R}^3$}{\n  \\prftree[r]{${\\multimap}\\text{L}$}{\n    \\prftree[r]{${\\otimes}R$}{\n      X,Y \\RightarrowLabel{X} Y\n    }{\n      Y \\RightarrowLabel{Y} \\bullet\n    }{\n      X,Y \\RightarrowLabel{X \\otimes Y} \\bullet\n    }\n  }{\n    \\prfbyaxiom{\\sc Id}{Z \\RightarrowLabel{Z} \\bullet}\n  }{\n    X \\otimes Y \\multimap Z, X, Y \\RightarrowLabel{Z} \\bullet\n  }\n}{\n  \\bullet \\RightarrowLabel{ (X \\otimes Y \\multimap Z) \\multimap X \\multimap Y \\multimap Z} \\bullet\n}\n\\end{equation*}\n\nNot so surpsingly, the proof term is the same\n\n\\begin{code}\ncurry = \\f x y -> f (pair x y)\n\\end{code}\n\n\\subsection{What's the point?}\n\nThe leftover approach seems more complicated, why to use it?\nThere is at least two reasons. First is that proof search is a lot more direct.\nLet us examine the $\\mathtt{curry}$ derivation more closely.\n\nThis fragment of linear logic is so well behaving, that a \"try whatever fits\"\nstrategy will find a solution. Let us however make it a bit more precise:\n\n\\begin{enumerate}\n  \\item Use {\\sc Id}-rule if it applies.\n  \\item Try right rules.\n  \\item Try left rules.\n  \\item Go to 1.\n\\end{enumerate}\n\nLet's see how that strategy works on $\\mathtt{curry}$. First we try right rules\nwhile they match. We arrive at \\\n\n\\begin{equation*}\n X \\otimes Y \\multimap Z, X, Y \\RightarrowLabel{Z} \\bullet\n\\end{equation*}\n\nsituation. $Z$ is atomic formula, so no right rule match. {\\sc Id} doesn't apply either.\nSo we have to use some left rule. In this situation we don't have a choice,\nas only $\\otimes$L applies. The goal state has two obligations, note how\nwe don't yet know what $\\Gamma_1$ will become.\n\n\\begin{equation*}\nX,Y \\RightarrowLabel{X \\otimes Y} \\Gamma_1 \\qquad\\qquad \\Gamma_1,Z \\RightarrowLabel{Z} \\bullet\n\\end{equation*}\n\nWe continue with the leftmost derivation. $\\otimes_R$ rule applies. Note,\nhow rule output and input context form kind of a chain:\n\n\\begin{equation*}\nX,Y \\RightarrowLabel{X} \\Gamma_2 \\qquad\\qquad \\Gamma_2 \\RightarrowLabel{Y} \\Gamma_1 \\qquad\\qquad \\Gamma_1,Z \\RightarrowLabel{Z} \\bullet\n\\end{equation*}\n\nNow, {\\sc Id}-rule applies, and we infer that $\\Gamma_2 = Y$.\n\n\\begin{equation*}\nY \\RightarrowLabel{Y} \\Gamma_1 \\qquad\\qquad \\Gamma_1,Z \\RightarrowLabel{Z} \\bullet\n\\end{equation*}\n\n{\\sc Id}-rule applies again, $\\Gamma_1 = \\bullet$\n\n\\begin{equation*}\nZ \\RightarrowLabel{Z} \\bullet\n\\end{equation*}\n\nand again. Finally we are left with no obligations and an empty context, as was required.\nProof search completes successfully. Note how we didn't need to an arbitrary guess\nhow to split the context. With \"traditional\" sequents, we'd need to guess how to split\ncontext when using $\\multimap$L and $\\otimes$R rules, for example in a situation like:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{\\Gamma_1 \\Longrightarrow X}\n{\\Gamma_2 \\Longrightarrow Y}\n{X, Y \\Longrightarrow X \\otimes Y}\n\\end{equation*}\n\nWhat should $\\Gamma_1$ and $\\Gamma_2$ be? With leftovers approach,\nwe just continue with full context, and see what's left.\n\nIt's worth pointing out, that in ordinary lambda calculus, there are no such\nproblem. If we would need to find a term for $\\Gamma \\vdash X \\times Y$, we'd\nsplit the search into to sub-searches: $\\Gamma \\vdash X$ and $\\Gamma \\vdash Y$,\nas we can reuse assumptions as many times as needed.\n\n\\subsubsection{DILL and annotations}\n\nIn a \\href{2019-07-03-from-modal-necessity-to-dill.html}{recent post} I described DILL.\nIt works with leftover typing as well. For example a $\\otimes$R-rule would look like:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{\\Gamma; \\Delta_1 \\RightarrowLabel{x : X} \\Delta_2}\n{\\Gamma; \\Delta_2 \\RightarrowLabel{y : Y} \\Delta_3}\n{\\Gamma; \\Delta_1 \\RightarrowLabel{\\mathtt{pair}\\;x\\;y : X \\otimes Y} \\Delta_3}\n\\end{equation*}\n\nYet, it's more interesting to use annotations. The assumptions\nstay always the same, but their usage changes:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{\\Gamma; M_1 \\RightarrowLabel{x : X} M_2}\n{\\Gamma; M_2 \\RightarrowLabel{y : Y} M_3}\n{\\Gamma; M_1 \\RightarrowLabel{\\mathtt{pair}\\;x\\;y : X \\otimes Y} M_3}\n\\end{equation*}\n\nwhere, type type of $M_1$, $M_2$ and $M_3$ depend on $\\Gamma$ (they are \"lists\" of the same length).\nNot a big change, but that's how \\href{2018-07-12-llc-in-agda.html}{LLC in Agda}\nis encoded. And I think that encoding is quite simple.\n\nFor example, in a following simple derivation the variables stay always the same: $x : X, y : Y$,\nonly their multiplicities change during the course. I'll write multiplicities reusing variable names:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{x : X, y : Y; x^1, y^1 \\RightarrowLabel{x : X} x^0, y^1}\n{x : X, y : Y; x^0, y^1 \\RightarrowLabel{y : Y} x^0, y^0}\n{x : X, y : Y; x^1, y^1 \\RightarrowLabel{\\mathtt{pair}\\;x\\;y : X \\otimes Y} x^0, y^0}\n\\end{equation*}\n\nThis approach is also how you could represent and type-check\nlinear logic using \\href{https://hackage.haskell.org/package/bound}{\\texttt{bound}}-library.\nSee an \\href{https://github.com/phadej/write-yourself-a-typed-functional-language/blob/master/src/LLC.hs}{example} from my \\href{https://skillsmatter.com/skillscasts/12389-write-yourself-a-typed-functional-language}{HaskellX 2018 talk}.\n\nSo the implementation concerns are second reason to use leftover typing.\nThis idea is described in \\emph{Typing with Leftovers - A mechanization of Intuitionistic Multiplicative-Additive Linear Logic} by Guillaume Allais (TYPES 2017).\n\n\\subsubsection{Scoping...}\n\nWe must be careful, as using leftovers scoping is different.\nLook closely at left over rules for $\\otimes$.\nConsider the re-associating term, from $A \\otimes (B \\otimes C)$ to\n$(A \\otimes B) \\otimes C$, first omitting the proof terms:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{L}$}{\n  \\prftree[r]{${\\otimes}\\text{R}$}{\n    \\prftree[r]{${\\otimes}\\text{R}$}{\n      \\prfbyaxiom{\\sc Id}{A, B \\otimes A \\RightarrowLabel{A} B \\otimes C}\n    }{\n      \\prftree[r]{${\\otimes}\\text{L}$}{\n        \\prfbyaxiom{\\sc Id}{B,C \\RightarrowLabel{B} C}\n      }{\n        B \\otimes C \\RightarrowLabel{B} C\n      }\n    }{\n      A, B \\otimes C \\RightarrowLabel{A \\otimes B} C\n    }\n  }{\n    \\prfbyaxiom{\\sc Id}{C \\RightarrowLabel{C} \\bullet}\n  }{\n    A, B \\otimes C \\RightarrowLabel{(A \\otimes B) \\otimes C} \\bullet\n  }\n}{\n  A \\otimes (B \\otimes C) \\RightarrowLabel{(A \\otimes B) \\otimes C} \\bullet\n}\n\\end{equation*}\n\nIf I haven't made any mistake during type-setting, that tree uses\nthe specified $\\otimes$ leftover rules. But look at the resulting proof\nterm:\n\n\\begin{code}\ncase abc of\n  pair a bc -> pair\n    (pair a (case bc of\n      pair b c -> b))\n    c\n\\end{code}\n\nLooks like |c| is out-of-scope, but it isn't, given the rules.\nThis \\emph{might} affect what we can do with $\\&$ and $\\oplus$ rules.\nThere are also might be some consequences for substitution. I'm not sure.\n\nNote however, that this unconvential behaviour isn't possible in \"LLC in Agda\"\nlike encoding: there the scoping is normal, only usages are tracked with\nleftovers. So the above example would be rejected by a type-checked with\n\"Variable not in scope: |c|\" error.\n\n\n\\subsection{You don't expect this, but: regular expressions}\n\nLinear logic is a substructural logic, where so called structural rules\nof contraction (duplication) and weakening (removing) are removed.\nThere's third structural rule: exchange (using out-of-order).\n\n\\begin{itemize}\n  \\item all rules: intuitionistic logic\n  \\item without contraction: affine logic\n  \\item without weakening: relevant logic\n  \\item without contraction and weakening: linear logic\n  \\item without contraction, weakening, and exchange: ordered logic\n\\end{itemize}\n\nOrdered logic (also known as non-commutative linear logic, I use NCILL for intuitionistic variant)\nfeels very restrictive, and it is. In ordered logic,\n\"traditional\" ${\\otimes}\\text{R}$ rule must be read literally,\nassumptions have to be used in order, first $\\Gamma_1$, then $\\Gamma_2$.\nIn intuitionistic logic context is like a set, in linear logic\nlike a multiset, and in ordered logic like a list.\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{\\Gamma_1, \\Gamma_2, \\Gamma_3 \\RightarrowLabel{X} \\Gamma_2, \\Gamma_3}\n{\\Gamma_2, \\Gamma_3 \\RightarrowLabel{Y} \\Gamma_3}\n{\\Gamma_1, \\Gamma_2, \\Gamma_3 \\RightarrowLabel{X \\otimes Y} \\Gamma_3}\n\\end{equation*}\n\nThis makes proof search even more simpler, you'll ever need to look at the\nfront of the context (when applying right rules).\n\nAnd it turns out, that NCILL describes how regular expressions match:\nthe match string forms a context (of atomic \"propositions\"), the regular expression\nis a type of expression we want, and for complete match we expect\nleftover context to be empty. For complete regular expressions, we'll\nneed to add lists to the language, but it works out.\n\nLet's match a string \\texttt{XY} against \\texttt{X(Y$|$Z)} regular expression,\nin other words is\n\n\\begin{equation*}\n  X, Y \\RightarrowLabel{X \\otimes (Y \\oplus Z)} \\bullet\n\\end{equation*}\n\nderivable? It is:\n\n\\begin{equation*}\n\\prfinterspace=2em\n\\prftree[r]{${\\otimes}\\text{R}$}\n{\\prfbyaxiom{\\sc Id}{X,Y \\RightarrowLabel{X} Y}}\n{\\prftree[r]{${\\oplus}\\text{R}_1$}\n{\\prfbyaxiom{\\sc Id}{Y \\RightarrowLabel{Y} \\bullet}}\n{Y \\RightarrowLabel{Y \\oplus Z} \\bullet}\n}\n{X, Y \\RightarrowLabel{X \\otimes (Y \\oplus Z)} \\bullet}\n\\end{equation*}\n\nThe proof search algorithm grew out of regular expression matching\nalgorithm using \\href{https://en.wikipedia.org/wiki/Brzozowski_derivative}{Brzozowski derivatives}.\nThe result is in implementation of \\href{2018-09-13-regular-expressions-of-types.html}{Regular expressions of types}\ni.e. \\href{https://github.com/phadej/kleene-type}{\\texttt{kleene-type}} (\\href{http://oleg.fi/haddocks/kleene-type/}{haddocks}).\n\nSee [Certified Proof Search for Intuitionistic Linear Logic](https://gallais.github.io/proof-search-ILLWiL/).\nI'm rediscovering things Guillaume Allais alrady did.\n\n\\subsection{Conclusion}\n\nWhat could I say. Everything seems to be connected in theoretical computer science.\nLinear logic and regular expressions. Lambda calculi and automata.\n\nMore seriously. We can formulate logics differently, so their expressive\npower stays the same, but the resulting \"programming language\"\nwould look different. Maybe more convinient to use, or better in some\nother way.\n\n\\end{document}\n", "meta": {"hexsha": "efa7dd3dd6c6dfd742a8abafa0226847aaa56d2a", "size": 14414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "posts/2019-10-30-typing-with-leftovers.tex", "max_stars_repo_name": "phadej/gists", "max_stars_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-03-31T19:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-28T16:49:57.000Z", "max_issues_repo_path": "posts/2019-10-30-typing-with-leftovers.tex", "max_issues_repo_name": "phadej/gists", "max_issues_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-19T16:33:09.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T16:33:09.000Z", "max_forks_repo_path": "posts/2019-10-30-typing-with-leftovers.tex", "max_forks_repo_name": "phadej/gists", "max_forks_repo_head_hexsha": "cefb69faa61dd5737e91532f046278b7327aee91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-31T07:50:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-19T14:05:45.000Z", "avg_line_length": 33.9952830189, "max_line_length": 236, "alphanum_fraction": 0.7117385875, "num_tokens": 4567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998663336158, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6041950741821941}}
{"text": "\\section{Link-level Transmission Success Probability}\n\\label{sec:trans_succ_p_pair}\nWe first study the transmission success probability $p_s(r)$ for a given uplink between a BS at the origin and a device $x_0$ at distance $r$. Using Slivnyak's theorem~\\cite{vaze2015random}[Theorem 2.3.3], combining $(\\ref{eq:path-loss})$ and $(\\ref{eq: sinr-definition})$, we have:\n\\begin{align}\np_{s} \\left( r\\right)\n& =\\mathbb{P}\\left\\lbrace \\frac{H \\exp(\\chi) r^{-\\gamma}}{\\sum_{x_j \\in \\Phi_{m}} H_{x_j} \\exp(\\chi_{x_j}) r_{x_j}^{-\\gamma}}  \\geq \\theta_T \\right\\rbrace. \\nonumber\n\\end{align}\nLet $I=\\sum_{x_j \\in \\Phi_{m}} H_{x_j} \\exp(\\chi_{x_j}) r_{x_j}^{-\\gamma}$, which is the cumulative interference suffered by $x_0$. Conditioned on log-normal shadowing component $\\exp(\\chi_{x_j}) $, as shown in~\\cite{haenggi2009interference}, $p_{s}\\left( r \\right)$ can be expressed in terms of Laplace transform of cumulative interference $\\mathcal{L}_{I}(s)$ at point $\\theta_{T} e^{-\\chi} r^{\\gamma}$:\n\\begin{align}\n\\label{eq:def_ps}\np_{s}\\left( r \\right)  &= Pr \\left\\lbrace H  \\geq I \\theta_{T} e^{-\\chi}r ^{\\gamma}  \\right\\rbrace \\nonumber\\\\ \n% The follwing line can be hidden, not necessary in FINAL_VERSION\n%&=\\mathbb{E}_{\\chi}\\left\\lbrace  \\mathbb{E}_{I} \\left[ \\exp(-\\theta_{T} \\exp(-g) r^{\\gamma}  I ) \\vert \\chi = g\\right]\\right\\rbrace   \\nonumber\\\\\n&= \\int_{-\\infty}^{+\\infty} \\left[ \\int_{0}^{+\\infty} \\exp(-y \\theta_{T} e^{-x} r^{\\gamma} ) f_{I}(y)dy\\right] f_{\\chi}(x) dx  \\nonumber\\\\\n&= \\mathbb{E}_{\\chi} \\left[ \\mathcal{L}_{I}\\left\\lbrace \\theta_{T} e^{-\\chi} r^{\\gamma}\\right\\rbrace \\right],\n\\end{align}\nwhere $f_{X} (x)$ is probability density function (PDF) of r.v. $X$, $\\mathbb{E}_{X} \\left[ \\cdot \\right] $ is the expectation operator with respect to $X$.\n\\subsection{Slotted ALOHA}\nIn slotted ALOHA, the cumulative interference is constant during each slot. The geometry-aware interference analysis for slotted ALOHA is well investigated. Reference~\\cite{haenggi2009interference} gives a closed-form expression about the Laplace transform of cumulative interference. With independent Rayleigh fading and log-normal shadowing, we have:\n\\begin{align}\n\\label{eq:lp_tr_slotted}\n%\\mathcal{L}_{I}\\left( s \\right) &=\\exp\\left\\lbrace -p\\lambda_m K_{\\text{slotted}} \\mathbb{E}\\left[ H^{\\frac{2}{\\gamma}}\\exp(\\frac{2}{\\gamma}\\chi)\\right]s^{\\frac{2}{\\gamma}}  \\right\\rbrace\n\\mathcal{L}_{I}\\left( s \\right)  &=\\exp \\left\\lbrace\n-p\\lambda_m \\pi A  \\exp \\left( 2\\sigma^2/\\gamma^2\\right) s^{2/\\gamma}  \n\\right\\rbrace,\n\\end{align}\nwhere $A = \\Gamma(1-\\frac{2}{\\gamma})\\Gamma(1+\\frac{2}{\\gamma})$ and $\\Gamma(z)=\\int_{0}^{+\\infty} x^{z-1} e^{-x} dx$. \n%is called the spatial contention factor~\\cite{haenggi2009outage}, $\\Gamma(z)$ is the gamma function defined as $\\Gamma(z)=\\int_{0}^{+\\infty} x^{z-1} e^{-x} dx$. \n%Since $H$ and $\\chi$ are independent, $\\mathbb{E}\\left[ H^{\\frac{2}{\\gamma}}\\exp(\\frac{2}{\\gamma}\\chi)\\right] = \\Gamma(1+\\frac{2}{\\gamma}) \\exp \\left( \\frac{\\sqrt{2}\\sigma}{\\gamma}\\right) ^2$.\n\\subsection{Pure ALOHA}\n\\label{subsec: pure-aloha}\nIn pure ALOHA, the cumulative interference $I(t)$ suffered by a given packet transmitted in interval $\\left[ T, T+B\\right]$ is variable during the packet transmission. When advanced transmission techniques (e.g., interleaving, robust channel coding, etc.) are used, $p_{s}(r)$ is a function of the average interference $I^{\\text{mean}} = \\frac{1}{B}\\int_{T}^{T+B} I(t)dt$, which replaces $I$ in $(\\ref{eq: sinr-definition})$.\n\nB{\\l}aszczyszyn et al. propose a Poisson-rain model~\\cite[Sec.2.4]{blaszczyszyn2015interference} that approximates well this case and allows to compute the cumulative interference. They prove that formula $(\\ref{eq:lp_tr_slotted})$ can be reused by letting $A=\\frac{2\\gamma}{\\gamma + 2} \\Gamma(1-\\frac{2}{\\gamma})\\Gamma(1+\\frac{2}{\\gamma})$.\n%\\subsection{Pure ALOHA, maximum interference}\n\nAnother case of pure ALOHA is assumed to have no error correction neither interleaving techniques for the purpose of reducing the device-side cost. In this case, the packet is delivered if and only if each bit is correctly received. Hence, the SINR should be larger than or equal to $\\theta_{T}$ during $B$. Hence, $p_{s}$ is a function of maximum interference $I^{\\text{max}} = \\max_{t \\in \\left[ T, T+B\\right]} I(t)$. According to~\\cite[Sec.2.4]{blaszczyszyn2015interference}, there is no closed-form for $I^{\\text{max}} $, and the authors use a simulation approach to study. Next, we propose a simple upper bound to estimate $I^{\\text{max}}$. Section~\\ref{sec:simulation} shows that the bias is at an acceptable level.\n\nConsider a packet transmitted in interval $\\left[ T, T+B\\right]$. Any device generating its interference at $T$ terminates packet transmission before $T+B$. The interfering packets at $T+B$ do not exist at $T$, because the packet transmission duration is $B$. \nHence, cumulative interference $I(T)$ and $I(T+B)$ are two independent and identically distributed random variables. Furthermore, any device generating interference on the packet is either active at $T$  or at $T+B$. The maximum interference is thus upper bounded by $I(T)+I(T+B)$. Therefore, the Laplace transform of maximum cumulative interference upper bound $\\mathcal{L}_{I^{\\text{upper}}}\\left( s \\right)$ during interval $\\left[ T, T+B\\right]$ is equal to $ \\mathcal{L}_{I(T)+I(T+B)}\\left( s\\right)= \\left[ \\mathcal{L}_{I(T)}\\left( s\\right) \\right]^2$. \n\nWe can reuse $(\\ref{eq:lp_tr_slotted})$ to calculate $\\mathcal{L}_{I(T)}\\left( s\\right)$. Thus, Laplace transform of $I^{\\text{upper}}$ can be unified into $(\\ref{eq:lp_tr_slotted})$ by letting $A=2 \\Gamma(1-\\frac{2}{\\gamma}) \\Gamma(1+\\frac{2}{\\gamma})$. \n\nCombining $(\\ref{eq:def_ps})$ and $(\\ref{eq:lp_tr_slotted})$, we can express $p_s(r)$ with a formula common to all ALOHA cases:\n\\begin{align}\n\\label{eq:def_ps_2}\np_{s}(r) & = \\mathbb{E}_{\\chi}\\left[ \\exp(-p \\lambda_{m} \\pi A \\theta_{T}^{\\frac{2}{\\gamma}} e^{\\frac{2\\sigma^2}{\\gamma^2}}  r^2 e^{-\\frac{2}{\\gamma}\\chi}) \\right],\n\\end{align}\n%\\begin{align}\n%\\label{eq:conditional_lp_trans}\n%\\mathcal{L}_{I}\\left\\lbrace \\theta_{T} \\exp(-\\chi) r^{\\gamma}\\right\\rbrace = \\exp\\left\\lbrace -A K r^2\\exp(-\\frac{2}{\\gamma}\\chi)\\right\\rbrace,\n%\\end{align}\nwhere $\\sigma = \\frac{\\ln(10)}{10}\\sigma_{dB}$ and:\n\\[ \\!\\!\\!\\!A =\n\\begin{cases} \n\\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right)\\Gamma\\!\\!\\left( 1+\\frac{2}{\\gamma}\\right) ,  & \\text{for slotted ALOHA }\\\\\n\\frac{2\\gamma}{\\gamma+2}\\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right)\\Gamma\\!\\!\\left( 1+\\frac{2}{\\gamma}\\right),  & \\parbox[t]{.41\\columnwidth}{for pure ALOHA, average interference }\\\\\n2\\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right)\\Gamma\\!\\!\\left( 1+\\frac{2}{\\gamma}\\right),  & \\parbox[t]{.4\\columnwidth}{for pure ALOHA, maximum interference }\n\\end{cases}\n\\]\n%With substitution of $(\\ref{eq:conditional_lp_trans})$ into $(\\ref{eq:def_ps})$, \n%Although expression $(\\ref{eq:def_ps_2})$ is not in closed-form, it simplifies the analysis in Sec.~\\ref{sec:op_over_infinite_plane}. \n\n%The authors of paper: Interference and SINR coverage in spatial non-slotted ALOHA networks, state that: We have not been able to derive closed formulas when the maximal interference constraint is used; this case is studied by simulations in Section 5.\n\n%\\[ \\!\\!\\!\\!K\\!\\!\\!=\\!\\!\\!\n%\\begin{cases} \n%\\pi \\Gamma\\left( 1-\\frac{2}{\\gamma}\\right),  & \\text{for slotted ALOHA }\\\\\n%\\frac{2\\gamma\\pi}{\\gamma+2}\\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right),  & \\parbox[t]{.41\\columnwidth}{for pure ALOHA, average interference }\\\\\n%2\\pi \\Gamma\\left( 1-\\frac{2}{\\gamma}\\right),  & \\parbox[t]{.4\\columnwidth}{for pure ALOHA, maximum interference }\n%\\end{cases}\n%\\]\n%\n%\\[ K\\!\\!\\!=\\!\\!\\!\n%\\begin{cases} \n%\\pi \\Gamma\\left( 1-\\frac{2}{\\gamma}\\right),  & \\text{for slotted ALOHA }\\\\\n%\\!\\!\\frac{2\\gamma\\pi}{\\gamma+2}\\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right),  & \\!\\!\\!\\text{for pure ALOHA, average interference}\\\\\n%\\!\\!2\\pi \\Gamma\\!\\!\\left( 1-\\frac{2}{\\gamma}\\right),  & \\!\\!\\!\\!\\!\\!\\!\\text{for pure ALOHA, maximum interference }\n%\\end{cases}\n%\\]", "meta": {"hexsha": "52c9a849aebabfb418bfc06028cf4eedb51c0a61", "size": 8012, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter5/bs_rx_divers_op_pair.tex", "max_stars_repo_name": "hansomesong/PhD-Thesis", "max_stars_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_stars_repo_licenses": ["MIT"], "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/bs_rx_divers_op_pair.tex", "max_issues_repo_name": "hansomesong/PhD-Thesis", "max_issues_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_issues_repo_licenses": ["MIT"], "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/bs_rx_divers_op_pair.tex", "max_forks_repo_name": "hansomesong/PhD-Thesis", "max_forks_repo_head_hexsha": "4bdd0a41012030398a23ae16a66d5a02631f76f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 100.15, "max_line_length": 721, "alphanum_fraction": 0.6849725412, "num_tokens": 2739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568416, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6041950621520997}}
{"text": "\\documentclass[12pt, letterpaper]{article}\n\\usepackage{amsmath}\n\\usepackage[utf8]{inputenc} % this enables utf-8, and is currently commented out\n\\usepackage{cprotect}\n% \\usepackage{tikz}\n% \\usepackage[bottom]{footmisc}\n% \\usepackage[preprint]{spconfa4}\n\\usepackage{hyperref}\n\n\\cprotect\\title{The inner workings of \\verb|Function::from_points|}\n\\author{Liam Bloom}\n\\date{January 14, 2021}\n\n\\begin{document}\n\n\\maketitle\n\n\\section*{Introduction}\n\nThis library takes, as input, a series of $n$ points \n\\((x_0, y_0), (x_1, y_1)\\cdots \\\\ (x_{n-2}, y_{n-2}), \n(x_{n-1}, y_{n-1})\\), and returns {\\textit a} \\verb|Function| that \nproduces these points. Note that this will not be the only such\n\\verb|Function|, only the one that my code feels makes the most sense. \nHere are, in order, the types of functions that may be returned, and\nhow they are calculated.\n\n\\section{Polynomial}\n\n{\\textbf Form:} \\(f(x)=ax^{n-1}+bx^{n-2}\\cdots cx^1+d\\) \\vspace{2ex}\n\nA polynomial of the $n$-th degree, the standard form of which is shown\nabove, can be generated from a series of $\\geq n+1$ points using linear\nalgebra. We begin by creating a system of equations:\n\n\\[y_0=ax_0^{n-1}+bx_0^{n-2}\\cdots cx_0^1+d\\]\n\\[y_1=ax_1^{n-1}+bx_1^{n-2}\\cdots cx_1^1+d\\]\n\\[\\vdots\\]\n\\[y_{n-2}=ax_{n-2}^{n-1}+bx_{n-2}^{n-2}\\cdots cx_{n-2}^1+d\\]\n\\[y_{n-1}=ax_{n-1}^{n-1}+bx_{n-1}^{n-2}\\cdots cx_{n-1}^1+d\\]\n\nThis can be rewritten as a linear algebra equation:\n\n% NOTE: The final row is $1$, NOT \\(x^0\\), because $d$ is multiplied by 1 even when \\(x=0\\) (\\(0^0\\neq 0\\))\n\n\\[\n    \\begin{bmatrix} \n    x_0^{n-1} & x_0^{n-2} & \\cdots & x_0^1 & 1 \\\\\n    x_1^{n-1} & x_1^{n-2} & \\cdots & x_1^1 & 1 \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n    x_{n-2}^{n-1} & x_{n-2}^{n-2} & \\cdots & x_{n-2}^1 & 1 \\\\\n    x_{n-1}^{n-1} & x_{n-1}^{n-2} & \\cdots & x_{n-1}^1 & 1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    a \\\\\n    b \\\\\n    \\vdots \\\\\n    c \\\\\n    d\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n    y_0 \\\\\n    y_1 \\\\\n    \\vdots \\\\\n    y_{n-2} \\\\\n    y_{n-1}\n    \\end{bmatrix}\n\\]\n\nand solved by multiplying both sides by the inverse:\n\n\\[\n    \\begin{bmatrix}\n    a \\\\\n    b \\\\\n    \\vdots \\\\\n    c \\\\\n    d\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix} \n    x_0^{n-1} & x_0^{n-2} & \\cdots & x_0^1 & 1 \\\\\n    x_1^{n-1} & x_1^{n-2} & \\cdots & x_1^1 & 1 \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n    x_{n-2}^{n-1} & x_{n-2}^{n-2} & \\cdots & x_{n-2}^1 & 1 \\\\\n    x_{n-1}^{n-1} & x_{n-1}^{n-2} & \\cdots & x_{n-1}^1 & 1\n    \\end{bmatrix}^{-1}\n    \\begin{bmatrix}\n    y_0 \\\\\n    y_1 \\\\\n    \\vdots \\\\\n    y_{n-2} \\\\\n    y_{n-1}\n    \\end{bmatrix}\n\\]\n\nWe then plug \\(a, b \\cdots c, d\\) into the standard form to generate \nour function.\n\n\\subsection{Old Polynomial Method}\n\nThe above linear algebra method was not used for determining polynomial\nfunctions prior to commit \\cprotect{\\href{\nhttps://github.com/liambloom/pattern-finder/commit/1f190e5aca4f2f4dda9d342b1e721a6458b44415\n}}{\\verb|1f190e5|}. Instead, the following method was used:\n\n\\section{Exponential}\n{\\textbf Form:} \\(f(x)=ab^x+c\\) \\vspace{2ex}\n\nAn exponential equation, as shown above, can be generated from \n$\\geq 3$ points\n\n% TODO\n\n\\section{The Future}\n\nThis section lists what types of functions may or may not be added\nto this library in the future, and if not, why.\n\n\\subsection{Likely to be added}\n\\begin{itemize}\n    \\item Rational\n    \\item Fibonacci-like\n\\end{itemize}\n\n\n\\subsection{May be added}\n\\begin{itemize}\n    \\item Trig\n    \\item Absolute Value\n\\end{itemize}\n\n\\subsection{Unlikely to be added}\n\\begin{itemize}\n    \\item Radical functions would most likely require storage of \n        irrational numbers, which is impossible\n    \\item Logarithmic functions for the same reason as radicals\n    \\item Conic Sections because they cannot be represented as functions\n    \\item Modulus because it would be quite difficult to implement\n    \\item \\(\\frac{|x|}{x}\\) because it is very niche\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "3a0802325e84db70df84fb4ec2ed193249e9c192", "size": 3944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/LaTeX/math.tex", "max_stars_repo_name": "liambloom/pattern-finder", "max_stars_repo_head_hexsha": "468486ee12ea556f3d09aa97aab098e5fa5209bd", "max_stars_repo_licenses": ["MIT"], "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/LaTeX/math.tex", "max_issues_repo_name": "liambloom/pattern-finder", "max_issues_repo_head_hexsha": "468486ee12ea556f3d09aa97aab098e5fa5209bd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-17T05:02:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-17T05:02:59.000Z", "max_forks_repo_path": "math/LaTeX/math.tex", "max_forks_repo_name": "liambloom/pattern-finder", "max_forks_repo_head_hexsha": "468486ee12ea556f3d09aa97aab098e5fa5209bd", "max_forks_repo_licenses": ["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.2, "max_line_length": 107, "alphanum_fraction": 0.6348884381, "num_tokens": 1485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.6041822713189929}}
{"text": "\\subsection{Bias of static models and spurious correlations}\n\\subsubsection{Static models}\n\nStatic models are of the form:\n\n\\(y_{t}=\\alpha+\\beta x_{t}+\\epsilon_{t}\\)\n\nThese have no lagged variables or difference operators.\n\n\\subsubsection{Bias of static models}\n\n\n", "meta": {"hexsha": "8a9222c9a7c885784015f09053f6c54cb1630cc6", "size": 264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/time/01-01-spurious.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/01-01-spurious.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/01-01-spurious.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.3076923077, "max_line_length": 60, "alphanum_fraction": 0.7651515152, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.6859494485880928, "lm_q1q2_score": 0.6041822656641879}}
{"text": "\\chapter{PID}\n\\label{chp:pid}\nThe Proportional-, Integral- and Derivative(PID)-controller can be used for motion and error correction. An example of a feedback loop with error correction is shown in figure \\ref{fig:PID_Circuit}. \n \n\\myFigure{Theory/PID/PID_Circuit}{PID using error feedback. From the book \\citep{FBS}}{fig:PID_Circuit}{0.7}\n\nPID can be used for motion correction such as correcting the steering of a car. For example if the error is defined as the crosstrack error which means how far the car is off the intended course. The PID controller can then be feed with the error, and the different parts of the PID controller can then adjust the control signal which affects the steering of the car. \n\n\n\\section{Proportional-, Integral- and Derivative(PID)-controller}\nThere are three parts in the PID controller. First there is the Proportional part.\nThe proportional part is calculated by: Kp*CurrentError. The result of this is shown in figure \\ref{fig:prop}.\n\\myFigure{Theory/PID/proportional}{Proportional part of PID.}{fig:prop}{0.5}\n\nAs figure \\ref{fig:prop} shows by only having the proportional part the curve will be marginally stable. This result in an oscillation.\n\nToo compensate for oscillation the derivative part is added. The derivative part can also be helpful against overshooting. This is seen in figure \\ref{fig:derivative}.\n\n\\myFigure{Theory/PID/derivative}{Derivative part of PID.}{fig:derivative}{0.5}\n\nIn figure \\ref{fig:derivative} the \"PD controller\" curve gets to the correct course faster than the \"P controller\" curve does. The derivative part is calculated by: Kd*(CurrentError - PreviousError).\n\nBut is the PD controller enough ? No. An example would be if there is a systematic bias. This can result in an constant offset. The PD controller alone cannot compensate for this offset. \n\nThat is why the integral part is needed. \n\nFigure \\ref{fig:integral} shows that the integral will overtime compensate for this offset. \n\n\\myFigure{Theory/PID/integral}{Integral part of PID.}{fig:integral}{0.5}\n\nThe integral part is calculated by: (Summation of errors)*Ki. \n\nIn figure \\ref{fig:pid_calc} the calculation for the output u can be seen. This calculation are with all three part proportional, integral and derivative.\n\n\\myFigure{Theory/PID/pid_calc}{PID with all parts.}{fig:pid_calc}{0.5}\n\nIn figure \\ref{fig:pid_calc} all three gains are shown {Kp, Ki, Kd} and the error and time are also used to calculate the control signal u.\n\n\\section{PID Tuning}\n\nTheir are many ways of tuning a PID controller. Two of them are Twiddle and Ziegler-Nichols.\nTwiddle is hill climbing algorithm. it works by trial and error. The problem with this is that it typically finds the local minima, and not the global minima. \n\nZiegler-Nichols works by initially Ki and Kd are set to zero. Then Kp is raised until oscillation appears. Then Kc is set to value of Kp and Tc is the period of the oscillation. When Kc and Tc are found the table in figure \\ref{fig:zig} can be used to get Kp, Ti and Td.\n\n\\myFigure{Theory/PID/zig}{Ziegler-Nichols frequency response method. From the book \\citep{FBS}}{fig:zig}{0.5}\n\nThe problem with Ziegler-Nichols is that it gives an aggressive gain and overshoot. \n\nTuning a PID controller will always depend on the application. Which makes it difficult to generalize the solution of tuning a PID controller.\n", "meta": {"hexsha": "4d9e9d6a1daa809188e1393c90b104bd9bf0aa2b", "size": 3359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/chapter/PID.tex", "max_stars_repo_name": "Rotvig/AI-Robotics-Project", "max_stars_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_stars_repo_licenses": ["MIT"], "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/PID.tex", "max_issues_repo_name": "Rotvig/AI-Robotics-Project", "max_issues_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_issues_repo_licenses": ["MIT"], "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/PID.tex", "max_forks_repo_name": "Rotvig/AI-Robotics-Project", "max_forks_repo_head_hexsha": "af8d96a429df4c55d9716c4ff0453188d9c8c799", "max_forks_repo_licenses": ["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.862745098, "max_line_length": 368, "alphanum_fraction": 0.7823757071, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6041695401086354}}
{"text": "\\section{Introduction}\n\nThe planar incompressible Stokes equations describe\ncreeping flows in two dimensions.\n%\nLet $\\Omega \\subset \\R^2$\nbe a bounded domain with $C^2$ boundary denoted by $\\Gamma$.\n%\nThe Stokes eigenvalue problem is to find\nvalues $k^2$ such that \n\n\\begin{equation}\n\\begin{aligned}\n  -\\Delta \\uu + \\nabla p &= k^2 \\uu \\quad \\textrm{in} \\quad\n  \\Omega \\label{eq:ostokes} \\; , \\\\\n  \\nabla \\cdot \\uu &= 0 \\; ,\n\\end{aligned}\n\\end{equation}\nsubject to boundary conditions, has a non-trivial solution $(\\uu,p)$.\n%\nIn this work, we consider the eigenvalue problem subject to \nthe Dirichlet boundary condition,\n\\begin{equation}\n  \\uu = \\bz \\quad \\textrm{on} \\quad \\Gamma \\label{eq:ostokes_dir} \\; .\n\\end{equation}\nIt is well known that the values $k^2$ are necessarily\nreal and positive and that there is a countable collection of such\nvalues $0 < k_{1}^{2} \\leq k_{2}^2 \\leq \\ldots \\uparrow \\infty$,\ncounting multiplicities.\n\n\\begin{remark}\n  When $k = i\\alpha$, the differential equation\n  \\cref{eq:ostokes} is known as the modified Stokes\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:ostokes} as the\n  oscillatory Stokes equation.\n\\end{remark}\n\nThe eigenvalues (and eigenfunctions)\nof the Stokes operator have applications in the\nstability analysis of stationary solutions of the\nNavier--Stokes equations \\cite{osborn1976approximation},\nin the study of decaying two dimensional turbulence\n\\cite{schneider2008final}, and as a trial basis for\nnumerical simulations of the Navier--Stokes\nequations~\\cite{batcho1994generalized}.\n%\nThe eigenvalues and eigenfunctions of the Stokes\noperator are also the subject of intense analytical\ninvestigation\n\\cite{taylor1933buckling,szego1950membranes,\n  polya1951isoperimetric,bramble1963pointwise,\n  ashbaugh1996fundamental,leriche2004stokes,\n  kelliher2009eigenvalues,antunes2011buckling},\nespecially as they relate to the eigenvalues and\neigenfunctions of the Laplacian.\n\nHistorically, the Stokes eigenvalue problem serves as a\ncommon model problem for numerical eigenvalue analysis\nwith a fourth order operator (here, the bi-Laplacian).\n%\nFurther, numerical simulation has long played an\nimportant role in the analyses cited above --- both for\ncomputing the eigenvalues and eigenfunctions\non domains of practical interest and in forming\nnew conjectures.\n\nBorrowing the language of~\\cite{zhao2015robust},\nwhich concerns the eigenvalues of the Laplacian\n(also known as the membrane or ``drum'' problem),\nthe numerical treatment of the Stokes eigenvalue\nproblem can be divided into two basic approaches.\n%\nThe first class of methods\ndirectly discretize the\ndifferential operator, typically with a\nfinite element basis, and the eigenvalues are found\nas the eigenvalues of the discrete system.\n%\nThe second class of methods reformulate the \noscillatory Stokes equations as a boundary integral\nequation (BIE) which is discretized.\nThe eigenvalues are then found\nby a nonlinear search for the values of\n$k$ where the BIE is not invertible.\n%\n\nThere is a large body of research on the first class of methods\nfor the Stokes eigenvalue problem.\n%\nWe do not seek to review this literature here,\nbut point to \\cite{johnson1974beam,\n  rannacher1979nonconforming,\n  mercier1981eigenvalue,bjorstad1999high,\n  jia2009approximation,chen2006approximation,\n  lovadina2009posteriori,huang2011numerical,\n  carstensen2014guaranteed}\nfor some representative examples.\n\nAs noted in~\\cite{zhao2015robust}, integral\nequation based methods provide several advantages.\n%\nBecause the BIE is defined on the\nboundary alone, there is a reduction in the\ndimension of the domain to be discretized.\n%\nThis approach reduces the number of unknowns over finite\nelement discretizations, and does not suffer\nfrom high-frequency ``pollution'' due to the \nlarge number of unknowns required to resolve\nthe computation when $k$ is large\n\\cite{babuska1997pollution} (which typically affects\nfinite element approaches to determining the eigenvalues).\n\nFurther, Zhao and Barnett~\\cite{zhao2015robust}\nshow how to alleviate some of the costliness of the\nnonlinear optimization introduced by formulating the \nproblem as an integral equation.\n%\nThe standard approach searches for ``V''-shaped minima\nof the singular values of the BIE; see, for\ninstance, \\cite{trefethen2006computed}.\n%\nInstead, Zhao and Barnett utilize the Fredholm\ndeterminant (see \\cref{sec:dets}) which, for certain\nBIEs, is an analytic function of $k$ with roots\nprecisely when $k^2$ is an eigenvalue.\n%\nThe Fredholm determinant can be estimated using\na Nystr\\\"{o}m discretization of the BIE\n\\cite{bornemann2010numerical,zhao2015robust}.\n%\nThen, the eigenvalues can be estimated efficiently\nby using high order root finding methods applied\nto the discretized determinant.\n\nWith the efficiency of the approach of\n\\cite{zhao2015robust} for the drum problem in mind,\nwe develop an integral equation based method for the\nStokes eigenvalue problem.\n%\nThis requires that a layer\npotential representation of the solution\nof \\cref{eq:ostokes} be given and that the resulting BIE\nis not invertible precisely when $k^2$ is an eigenvalue.\n%\nThe first requirement is straightforward to\nsatisfy because \nwell-known layer potential representations for the\nmodified Stokes equation~\\cite{Pozrikidis1992,biros2002embedded,\n  jiang2013second,ladyzhenskaya1969mathematical}\nare directly applicable.\n%\nProving the invertibility of the associated operators\naway from the eigenvalues is a more involved task\nand forms the bulk of the theoretical component\nof this paper.\n\n\\subsection{Relation to other work}\n\nWhile integral equation based methods for the\nrelated ``buckling'' eigenvalue problem\n(which is equivalent  on simply connected domains\n\\cite{kelliher2009eigenvalues})\nhave been considered previously,\nthese typically relied on first-kind integral\nequation formulations of the underlying PDE,\ni.e. formulations in which the BIE operator is\ncompact \\cite{kitahara2014boundary,antunes2011buckling}.\n%\nThis is unsatisfying from a numerical\nperspective, because the spectrum of a\ncompact operator either contains zero\nor has zero as a limit point\n(by design, the representations in\n\\cite{kitahara2014boundary,antunes2011buckling}\nare not injective precisely when\n$k^2$ is an eigenvalue).\n%\nThis obscures the relation between\nthe non-invertibility of discrete approximations\nof the operator and the eigenvalues;\nin particular, common measures of the\n``non-invertibility'' of a matrix, like the\nsmallest singular value or the determinant,\nconverge rapidly to zero for all values\nof $k^2$ as the boundary is refined.\nThe measure of whether $k^2$ is an\napproximate eigenvalue is then {\\em relative to the\n  current grid} for first kind formulations.\n\nThe classical single and double layer representations\nfor oscillatory Stokes considered in this paper\nresult in second kind equations, i.e. integral equations\nof the form $\\mathcal{I} - \\mathcal{K}_k$ where\n$\\mathcal{K}_k$ is compact.\n%\nSuch equations have a more satisfying theory\n\\cite{reed1972methods,colton1983integral,kress1989linear},\nwhich translates well to numerical implementation\n\\cite{atkinson2009numerical,bornemann2010numerical,\n  hackbusch2012integral,zhao2015robust}.\n%\nThe use of a second kind representation is standard\nfor the drum problem \\cite{backer2003numerical,zhao2015robust}\nand was used recently to compute the vibrating\nmodes of thin, clamped plates~\\cite{lindsay2018boundary}.\n\n\\subsection{Paper outline and contributions}\n\nThe rest of this paper proceeds as follows.\n%\nIn \\cref{sec:prelim}, we set the notation, provide some\nmathematical preliminaries, and review \nproperties of single and double layer potentials\nfor the oscillatory Stokes equations.\n%\nThen, in \\cref{sec:analysis}, we develop the necessary\ntheory for proving the main results of this work \n(\\cref{thm:dlmain,thm:cfmain}),\nwhich show that the BIEs resulting from these\nlayer potential representations are not invertible\nprecisely when $k^2$ is an eigenvalue.\n%\nThese theoretical developments include a detailed\ndiscussion of the uniqueness of oscillatory Stokes\nboundary value problems in exterior domains.\n%\nTo the best of our knowledge, the invertibility\nand uniqueness results are new to the literature.\n%\n\\Cref{sec:dets} then outlines how the Fredholm determinant\ncan be used in the oscillatory Stokes context.\n%\nIn \\cref{sec:numerical}, we describe the numerical\nmethods we use to discretize the BIEs and to perform\ndeterminant calculations.\n%\nWhile the underlying methods are well-established,\nthe combination of a high-order singular quadrature\nrule and a fast-direct method for determinant evaluations\nin a BIE framework is novel.\n%\nAt the moderate frequencies considered in this\npaper, we find that standard fast-direct\nsolvers provide a reasonably efficient determinant\nevaluation.\n%\nWe also present numerical experiments\nwhich demonstrate some of the paper's analytical\nclaims as well as the effectiveness of the overall\nframework.\n%\nFinally, we provide some concluding thoughts,\ndescribe plans for future research,\nand outline some open questions in\n\\cref{sec:conclusion}.\n", "meta": {"hexsha": "69a1c358bdcb3d1403904d9bfb0370c0fe2878bc", "size": 9163, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01-stokes/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-stokes/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-stokes/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": 35.3783783784, "max_line_length": 70, "alphanum_fraction": 0.8049765361, "num_tokens": 2303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6041695363420675}}
{"text": "\n\\subsection{Karush-Kuhn-Tucker conditions}\n\nIf our problem is non-convex, or if Slater's condition does not hold, how else can be find a solution?\n\nA solution, \\(p^*\\) can satisify KKT conditions.\n\n", "meta": {"hexsha": "baa67b0f9969f5f41ba5a5fe8bc67a136622d62a", "size": 199, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/06-03-KKT.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-03-KKT.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-03-KKT.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.875, "max_line_length": 102, "alphanum_fraction": 0.7487437186, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6040969879777289}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 18}\n\\subsection{Lecture Notes - Moment of Inertia Tensor}\n\\subsubsection{Review of Last Day's Results}\n\\[\\v{L} = \\v{L}_{CM} + \\v{L}_{rel}\\]\n\\[T = T_{CM} + T_{rel}\\]\n\\[U = U_{CM} + U_{rel}\\]\nWe can decompose the angular momentum and energies into the center of mass term and the relative to the COM term. We note that for rigid bodies, $U_{rel}$ is constant. \n\\newline Last time (see 17.1.5) we observed that the angular momentum vector and the rotation vector are, in general, not parallel. Let us solve a question with a similar idea. Suppose we have a rotating dumbbell of two masses $m$ which move in circles (radius $a$) at a z displacement $l$ and $-l$, joined by a massless rod. The Angular velocity vector is given by $\\bm{\\omega} = \\omega\\zhat$. What is the direction of $\\v{L}$?\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-18/l18-img1.png}\n    \\includegraphics[scale=0.5]{Lecture-18/l18-img2.png}\n\\end{center}\n\\begin{s}\nDirection E. Use the right hand rule with $\\v{L} = \\v{r} \\times \\v{v}$ and the add the angular momenta of the two terms.\n\\end{s}\nFollow-up question; consider the body frame where the position of the masses are $(0, a, l)$, $(0, -a, -l)$. What is the $I_{zz}$ component of the inertia tensor?\n\\begin{s}\nRecall that $I_{zz} = \\sum_\\alpha m_\\alpha(x_\\alpha^2 + y_\\alpha^2)$. Applying the formula, we have that $I_zz = ma^2 + m(-a)^2 = 2ma^2$.\n\\end{s}\n\\noindent Next, what is the $I_{xz}$ component of the inertia tensor?\n\\begin{s}\nRecall that $I_{xz} = -\\sum_\\alpha x_\\alpha z_\\alpha$. We see that $x = 0$ for both masses so hence $I_{xz} = 0$.\n\\end{s}\n\\noindent What's $I_{yz}$?\n\\begin{s}\nRecall that $I_{yz} = -\\sum_\\alpha m_\\alpha y_\\alpha z_\\alpha$. We therefore have that $I_{yz} = -mal - m(-a)(-l) = -2mal$.\n\\end{s}\n\\noindent What is the kinetic energy of the system?\n\\begin{s}\nWe use that $T = \\frac{1}{2}I_{zz}\\omega^2 = \\frac{1}{2}(2ma^2)\\omega^2 = ma^2\\omega^2$.\n\\end{s}\n\\noindent \\textit{Remark:} We can genrealize this to be $T = \\frac{1}{2}\\bm{\\omega} \\cdot \\v{L}$.\n\n\\subsubsection{Angular momentum for rigid body with angular velocity along arbitrary direction}\nWe have that:\n\\[\\bm{\\omega} = \\m{\\omega_x \\\\ \\omega_y \\\\ \\omega_z}\\]\nAs well as that:\n\\[\\v{L} = \\sum_\\alpha m_\\alpha \\left(\\v{r}_\\alpha \\times (\\bm{\\omega} \\times \\v{v}_\\alpha)\\right)\\]\nWe apply the BAC-CAB rule, that is:\n\\[\\v{A} \\times (\\v{B} \\times \\v{C}) = \\v{B}(\\v{A} \\cdot \\v{C}) - \\v{C}(\\v{A} \\cdot \\v{B})\\]\nUsing this, the above expression for the angular momentum becomes:\n\\[\\v{L} = \\m{L_x \\\\ L_y \\\\ L_z} = \\sum_\\alpha m_\\alpha \\m{(y_\\alpha^2 + z_\\alpha^2)\\omega x & - x_\\alpha y_\\alpha \\omega_y & -x_\\alpha z_\\alpha \\omega_z\n\\\\ -y_\\alpha x_\\alpha \\omega_x & (z_\\alpha^2 + x_\\alpha^2)\\omega_y & -y_\\alpha z_\\alpha \\omega_z\n\\\\ -z_\\alpha x_\\alpha \\omega_x & -z_\\alpha y_\\alpha \\omega_y & (x_\\alpha^2 + y_\\alpha^2)\\omega_z}\\]\nWe may pull out these coefficients and define a moment of inertia matrix/tensor:\n\\[\\II = \\m{I_{xx} & I_{xy} & I_{xz} \\\\ I_{yx} & I_{yy} & I_{yz} \\\\ I_{zx} & I_{zy} & I_{zz}}\\]\nWhere $\\v{L} = \\II\\bm{\\omega}$. Note that this matrix is both real symmetric, as $I_{ij} = I_{ji}$, and hence contains 6 independent elements. We also note that this means $\\II^T = \\II$ (equal to its transpose). For example, using the definition, we can say that:\n\\[I_{xx} = \\sum_\\alpha m_\\alpha(y_\\alpha^2 + z_\\alpha^2)\\]\n\\[I_{xy} = -\\sum_\\alpha m_\\alpha x_\\alpha y_\\alpha = -\\sum_\\alpha m_\\alpha y_\\alpha x_\\alpha = I_{yx}\\]\nWe can extend this notion to continuous mass distributions:\n\\[\\II = \\int dV\\rho(x, y, z)\\m{y^2 + z^2 & -xy & -xz \\\\ -xy & x^2 + z^2 & -yz \\\\ -xz & -yz & x^2 + y^2\n}\\]\n\\subsubsection{Index notation}\nNote that when we write $\\v{L} = \\II\\bm{\\omega}$, this is equivalent to $L_i = \\sum_j I_{ij}\\omega_j$. We can also write this compactly by introducing the Kronecker Delta notation:\n\\[\\delta_{ij} = \\begin{cases}\n1 & \\text{if $i = j$}\n\\\\ 0 & \\text{otherwise}\n\\end{cases}\\]\nHence we could write the above expression for the inertia tensor more compactly as:\n\\[I_{ij} = \\int dV\\rho(x,y,z)\\left(\\v{r}^2\\delta_{ij} - r_ir_j\\right)\\]\n\n\\subsubsection{Example: Components of Inertia Tensor for rotation of cube about corner}\n\\begin{center}\n    \\includegraphics[scale=1]{Lecture-18/l18-img3.png}\n\\end{center}\nWe have a uniform solid cube of mass $M$ and side $b$, rotating about a corner (the origin). We assume a constant $\\rho$ of $\\rho = \\frac{M}{b^3}$. Calculating $I_{xx}$, we have:\n\\[I_xx = \\rho\\int_0^bdx \\int_0^bdy \\int_0^bdz (y^2 + z^2) = \\ldots = \\frac{2}{3}Mb^2\\]\nNote we have pulled out $\\rho$ from the integration as these are constant. By symmetry of the object, $I_{xx} = I_{yy} = I_{zz}$. What about the off diagonal terms? Calculating $I_{xy}$ we have:\n\\[I_{xy} = \\rho\\int_0^bdx\\int_0^bdy\\int_0^bdz(-xy) = -\\frac{M}{4}b^4\\]\nAnd we would expect the other off diagonal elements to again be identical by symmetry. Writing the total inertia tensor, we then have:\n\\[\\II = Mb^2\\m{2/3 & -1/4 & -1/4 \\\\ -1/4 & 2/3 & -1/4 \\\\ -1/4 & -1/4 & 2/3}\\]\n\n\\subsubsection{Example: Components of Inertia Tensor for rotation of cube about COM}\n\\begin{center}\n    \\includegraphics[scale=1]{Lecture-18/l18-img4.png}\n\\end{center}\nOur bounds of integration will change compared to the last case. Calculating $I_{xx}$, we have:\n\\[I_{xx} = \\rho\\int_{-b/2}^{b/2}dz\\int_{-b/2}^{b/2}dy\\int_{-b/2}^{b/2}dz(y^2 + z^2) = \\frac{Mb^2}{6}\\]\nAgain by symmetry, $I_{xx} = I_{yy} = I_{zz}$. We note that this is different from before! Calculating $I_{xy}$, we have:\n\\[I_{xy} = \\rho\\int_{-b/2}^{b/2}dz\\int_{-b/2}^{b/2}dy\\int_{-b/2}^{b/2}dz(-xy) = 0\\]\nThe integral is immediately zero by the fact that the integrand is odd. The same goes for the other off diagonal elements, which yields the final inertia tensor:\n\\[\\II = \\frac{Mb^2}{6}\\m{1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1}\\]\nWhich is diagonal! This happens to be the case because this is a principal axis of rotation, where the inertia tensor has a particularly simple (diagonal) form.\n\n\\subsubsection{Parallel Axis Theorem}\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-18/l18-img5.png}\n\\end{center}\nIf $I_{ij}$ is the inertia tensor calculated in the CM coordinates, and $J_{ij}$ is the tensor element in the displaced coordinates (where $\\v{R} = \\v{r} + \\v{a}$), then:\n\\[J_{ij} = I_{ij} + M(a^2\\delta_{ij} - a_ia_j)\\]\n\n\\subsubsection{Example: Applying the Parallel Axis Theorem to the Cube}\nFor the displacement of coordinates from the center of the mass of the cube to the corner of the cube, we have that:\n\\[\\v{a} = \\m{-b/2 \\\\ -b/2 \\\\ -b/2}, \\quad a^2 = \\abs{\\v{a}}^2 = \\frac{3}{4}b^2\\]\nThen, for the diagonal elements we have:\n\\[M(a^2\\delta_{ii} - a_ia_i) = M\\left[\\frac{3}{4}b^2 - \\frac{-b}{2}\\cdot\\frac{-b}{2}\\right] = \\frac{Mb^2}{2}\\]\nAnd for the off diagonals:\n\\[M(a^2\\delta_{ij} - a_ia_j) = M\\left[-\\frac{-b}{2}\\frac{-b}{2}\\right] = -\\frac{Mb^2}{4}\\]\nHence calculating the inertia tensor about the corner of the cube (in the displaced coordinates) we get:\n\\[\\mathbb{J} = Mb^2\\m{1/6 & 0 & 0 \\\\ 0 & 1/6 & 0 \\\\ 0 & 0 & 1/6} + Mb^2\\m{1/2 & -1/4 & -1/4 \\\\ -1/4 & 1/2 & -1/4 \\\\ -1/4 & -1/4 & 1/2} = Mb^2\\m{2/3 & -1/4 & -1/4 \\\\ -1/4 & 2/3 & -1/4 \\\\ -1/4 & -1/4 & 2/3}\\]\nWhich agrees with the result obtained from the direct calculation.\n\n\\subsubsection{Principal axes}\nIf $\\v{L} = \\lambda\\bm{\\omega}$ for a scalar $\\lambda$, the body rotates around one of its principal axes. $\\lambda$ is the \"Moment of inertia\" about that axis. So if:\n\\[\\II = \\m{\\lambda_1 & 0 & 0 \\\\ 0 & \\lambda_2 & 0 \\\\ 0 & 0 & \\lambda_3}\\]\nThen the chosen axes are the principal axes and $\\lambda_i$ are the principal moments. For any rigid body and any point $O$, there are three perpendicular axes with respect to which the inertia tensor is diagonal! This is a consquence of the fact that the moment of inertia tensor has real entries and is symmetric. \n\\newline Which of the following statements are a consequence of the fact that the inertia tensor is a 3x3 matrix with real positive eigenvalues and orthogonal eigenvectors?\n\\begin{enumerate}\n    \\item The matrix can be diagonalized\n    \\item The matrix of eigenvectors is an orthogonal matrix\n    \\item The matrix of eigenvectors is a rotation matrix (if properly normalized)\n    \\item In the coordinate system aligned with the eigenvectors, the tensor is diagonal.\n\\end{enumerate}\n\\begin{s}\n    All 4 are correct. \n\\end{s}\n\\end{document}", "meta": {"hexsha": "82bbe0542b2419291c22df2c5f01aed17d083aab", "size": 8424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-18/Lecture-Notes-18.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-18/Lecture-Notes-18.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-18/Lecture-Notes-18.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": 70.2, "max_line_length": 428, "alphanum_fraction": 0.6724833808, "num_tokens": 2951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718435083355187, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6040929575104178}}
{"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 1 Seminar \\& HW}\\\\\n\n\\textbf{Problem 1:} Two dice, each having $M$ faces, are thrown. Each die has numbers from $1$ to $M$ written on its faces. Find the probability that the sum of two numbers equals $i$. Provide the answer for $M=10,$ and $i=15.$\n\\\\\n\n\\textbf{Problem 2:} A random subset is chosen from the set $\\{1,\\dots,N\\}.$ Find the probability that the cardinality (number of elements) of thus subset is an even number.\n\\\\\n\n\\textbf{Problem 3:} Two subsets, $A_1$ and $A_2,$ of $\\{1,\\dots,n\\}$ are chosen randomly (they may coincide). Find the probability that $A_1 \\cap A_2 = \\emptyset$\n\\\\\n\n\\textbf{Problem 4:} \nAn algebra is a set of subsets of $\\Omega$ that 1) contains $\\Omega$, 2) is closed under complement (if $A$ is in the algebra – $\\bar{A},$ its complement, is also) and union (if $A$ and $B$ are in the algebra – $A\\cup B$ is as well). Can these two operations from point 2) be replaced with\n\\begin{enumerate}\n    \\item $\\Delta$ (symmetric difference) and $\\textbackslash$ (set difference, also called relative complement)?\n    \\item $\\overline{A\\cap B}$ (just one operation, complement of the intersection)?\n\\end{enumerate}\n\\\\\n\n\\textbf{Problem 5:} Let $\\mathcal{F}_1,~\\mathcal{F}_2$ be $\\sigma$-algebras. Is it true that 1) $\\mathcal{F}_1\\cap\\mathcal{F}_2$ and 2)$\\mathcal{F}_1\\cup\\mathcal{F}_2$ are $\\sigma$-algebras?\n\n\\end{document}\n", "meta": {"hexsha": "e98e9554bffdcbc8c823daee3e544c76863b24ea", "size": 1866, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week01_geometric_probability/Week01_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": "week01_geometric_probability/Week01_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": "week01_geometric_probability/Week01_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": 41.4666666667, "max_line_length": 289, "alphanum_fraction": 0.7207931404, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.604092941664406}}
{"text": "\\chapter{n-step bootstrapping}\n\\section{Summary}\n\n\\subsection{n-step TD prediction}\n\nMonte Carlo updates the estimate $V(S)$ using the complete return (equation~\\ref{eq:complete return of an episode}. TD(0) only watches one step ahead, a compromised is too take an n-step prediction window as illustrated by equation~\\ref{eq:return estimate for n step method}. The state learning algorithm them becomes equation~\\ref{eq:state learning algorithm n-step return}.\n\n\\begin{equation}\nG_t = R_{t+1} + \\gamma R_{t+2} + \\gamma^2 R_{t+3} + ... + \\gamma^{T-t-1}R_T\n\\label{eq:complete return of an episode}\n\\end{equation}\n\n\\begin{equation}\nG_{t:t+n} = R_{t+1} + \\gamma R_{t+2} + ... \\gamma^{n--1} R_{t+n} + \\gamma^nV_{t+n-1}(S_{t+n})\n\\label{eq:return estimate for n step method}\n\\end{equation}\n\n\\begin{equation}\nV_{t+n}(S_t) = V_{t+n-1}(S_t) + \\alpha [G_{t:t+n} - V_{t+n-1}(S_t)]\n\\label{eq:state learning algorithm n-step return}\n\\end{equation}\n\n\\subsection{n-step Sarsa}\n\nThe previous Sarsa is often called Sarsa(0), the generalized version is call n-step Sarsa. The return value can be estimated by equation~\\ref{eq:return estimate for n step sarsa}. The update rule for Q then becomes equation~\\ref{eq:n step sarsa learning algorithm}.\n\n\\begin{equation}\nG_{t:t+n} = R_{t+1} + \\gamma R_{t+2} ... \\gamma^{n-1} R_{t+n-1} \\gamma^n Q_{t+n-1}(S_{t+n}, A_{t+n})\n\\label{eq:return estimate for n step sarsa}\n\\end{equation}\n\n\\begin{equation}\nQ_{t+n}(S_{t}, A_{t}) := Q_{t+n-1}(S_t, A_t) + \\alpha \\left[G_{t:t+n} - Q_{t+n-1}(S_t, A_t)\\right]\n\\label{eq:n step sarsa learning algorithm}\n\\end{equation}\n\nThe same logic can be applied to expected SARSA. The value function can be defined as equation~\\ref{eq:expected n step sarsa value function}. Using equation~\\ref{eq:expected n step sarsa value function} the n-step expected sarsa return value is defined by equation~\\ref{eq:n step expected sarsa return value}. The update is still equation~\\ref{eq:n step sarsa learning algorithm} but using the new $G_{t:t+n}$ from equation~\\ref{eq:n step expected sarsa return value}.\n\n\\begin{equation}\nV_t(S_t) = \\sum_a P(a) Q(S_t, a)\n\\label{eq:expected n step sarsa value function}\n\\end{equation}\n\n\\begin{equation}\nG_{t:t+n} = R_{t} + \\gamma R_{t+1} + ... \\gamma^{n-1} R_{t+n-1} + V_t(S_{t+n}, A_{t+n})\n\\label{eq:n step expected sarsa return value}\n\\end{equation}\n\n\\subsection{n-step Off-policy Learning}\n\n\\begin{equation}\nQ_{t+n}(S_{t}, A_{t}) := Q_{t+n-1}(S_t, A_t) + \\rho_{t:t+n} \\alpha \\left[G_{t:t+n} - Q_{t+n-1}(S_t, A_t)\\right]\n\\label{eq:n step off policy sarsa learning algorithm}\n\\end{equation}\n\n\\begin{equation}\nV_{t+n}(S_t) = V_{t+n-1}(S_t) + \\rho_{t:t+n-1} \\alpha [G_{t:t+n} - V_{t+n-1}(S_t)]\n\\label{eq:state learning algorithm n-step off policy return}\n\\end{equation}\n\n\\begin{equation}\n\\rho_{t:h} = \\prod_{k=t}^{min(h, T-1)} \\frac{\\pi(A_k|S_k)}{b(A_k|S_k)}\n\\label{eq:n step off policy sarsa importance sampling ratio}\n\\end{equation}\n\n\\subsection{Per Decision  Methods with Control Variates}\n\nThe previous sections are inefficient implementations of the n-step algorithm. The n-step return can be written recursively as $G_{t:h} = R_{t+1} + \\gamma G_{t+1:h}$, with $G_{h:h}=V_{n-1}(S_h)$. The importance sampling weighting is still $\\rho_t = \\frac{\\pi(S_t, A_t)}{b(s_t, A_t)}$. Using this recursive definition we can define the return as equation~\\ref{eq:off policy definition of return estimate with control variate}.\n\n\\begin{equation}\nG_{t:h} = \\rho_t(R_{t+1} + \\gamma G_{t+1:h}) + (1-\\rho) V_{h-1}(S_t)\n\\label{eq:off policy definition of return estimate with control variate}\n\\end{equation}\n\nThe term $(1-\\rho) V_{h-1}(S_t)$ in equation~\\ref{eq:off policy definition of return estimate with control variate} is called the control variate. It has an expected value of one because $\\EX[\\rho]=1$ so $\\EX[1-\\rho]=0$.\n\nThe return state of a n-step off policy with control variate is defined by equation~\\ref{eq:n step off policy form with control variate}. The recursion ends with $G_{h:h}=Q_{h-1}(S_h, A_h)$\n\n\\begin{equation}\nG_{t:h} = R_{t+1} + \\gamma [ \\rho_{t+1} G_{t+1:h} + V_{h-1}(S_{t+1})-\\rho_{t+1}Q_{h-1}(S_{t+1}, A_{t+1})]\n\\label{eq:n step off policy form with control variate}\n\\end{equation}\n\n\n\\subsection{Off-Policy Learning Without Importance Sampling: The n-step Tree Backup Algorithm}\n\nInstead of only using the value estimations of the actual path taken in n-steps. We can generalize the expected SARSA algorithm, from equation~\\ref{eq:one step return expected sarsa} to equation~\\ref{eq:tree backup rule n-step return}. \n\n\\begin{equation}\nG_{t:t+1} = R_{t+1} + \\gamma \\sum_{a} \\pi (a | S_{t+1})Q_t(S_{t+1}, a)\n\\label{eq:one step return expected sarsa}\n\\end{equation}\n\n\\begin{equation}\n\\begin{split}\nG_{t:t+n} & = 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& = R_{t+1} + \\gamma \\pi (A_{t+1}| S_{t+1}) [G_{t+1:h}-Q_{h-1}(S_{t+1}, A_{t+1})] + \\gamma V_{h-1} (S_{t+1})\n\\label{eq:tree backup rule n-step return}\n\\end{split}\n\\end{equation}\n\nAdding the control variate to Equation~\\ref{eq:tree backup rule n-step return} gives equation~\\ref{eq:n-step sigma}.\n\n\\begin{equation}\nG_{t:t+n}  = R_{t+1} + \\gamma \\pi (\\sigma_{t+1}\\rho_{t+1} + (1-\\sigma_{t+1})\\pi(A_{t+1}|S_{t+1})) [G_{t+1:h}-Q_{h-1}(S_{t+1}, A_{t+1})] + \\gamma V_{h-1} (S_{t+1})\n\\label{eq:n-step sigma}\n\\end{equation}\n\n\\subsection{*A Unifying Algorithm: n-step Q(Sigma)}\n\n\n\\section{Exercises}\n\n\\subsection{Exercise 7.1}\n\nThe Monte carlo error can be written as a sum of TD errors, with TD(0) this becomes:\n\n$\nG_t = R_{t+1} + \\gamma G_{t+1}\n$\n\n$\n\\delta{t} = R_{t+1} + \\gamma V(S_{t+1}) - V(S_t)\n$\n\n$\nG_t - V(S) = R_{t+1} + \\gamma G_{t+1} - V(S_{t}) = \\sum^{T-1}_{k=t} \\gamma^{k-1}\\delta_k\n$\\\\\n\nWith an n step we get:\n\n$\nG_t = R_{t+1} + \\gamma G_{t+1}\n$\n\n$\n\\delta{t} =  \\sum_{k=1}^{n} \\gamma^{k-1} R_{t+k} + \\gamma^{n}V(S_{t+n}) - V(S_{t})\n$\\\\\n\nBy putting them together we get:\n\n$\nG_t - V(S_t)\\\\\n= R_{t+1} + \\gamma G_{t+1} - V(S_t)\\\\\n= R_{t+1} + \\gamma G_{t+1} - V(S_t)\\\\\n+  \\sum_{k=2}^{n} \\gamma^{k-1} R_{t+k} - \\sum_{k=2}^{n}\\gamma^{k-1} R_{t+k}\\\\\n+ \\gamma^{n}V(S_{t+n}) - \\gamma^{n}V(S_{t+n})\\\\\n= \\delta_t + \\gamma (G_{t+1} - \\gamma^{n-1}V(S_{t+n}))  - \\sum_{k=2}^{n}\\gamma^{k-1} R_{t+k}\n$\n\nI don't see how to continue from here. \n\n\\subsection{Excercise 7.3 page 145}\n\\textbf{question: Why do you think a larger random walk task (19 states instead of 5) was 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 form 0 to -1 made in the larger walk? Do you think that made any difference in the best value of n?}\n\nIf a random walk with length of 5 was used the results would not be best around an n of 4 or 8. As a you need a large enough episode to learn from a step of 4 or 8 samples.\n\nWhen the walk is smaller, smaller n's will give better results then current results. \n\nIf the left side is negative, the first time the walk will go into it. That negative result will propagate n-steps, instead of 1 with TD(0).\n\n\\subsection{Excercise 7.4 page 148}\nSimilar to excercise 7.1, still TODO, first finish 7.1.\n\n", "meta": {"hexsha": "1d1fb8718019d41c9258af2d0b430375fa23ea46", "size": 7132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RL/notes/TeX_files/chapter07.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/chapter07.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/chapter07.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": 43.2242424242, "max_line_length": 468, "alphanum_fraction": 0.6800336511, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6040522379543666}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{inputenc}\n\\begin{document}\n\\section{Pre 9.1}\n\\textbf{Pages} 184-185:\nOn page 184,:\n\\textit{If $a_2$ is deleted, we maintain .....}\nError: c=A-CGC \nCorrection: c=A-TGC\nWhy?: The statement says $a_2$ is deleted, which is correctly depicted by $c$\nbut then it also makes an erroneous substitution at $a_3$\n\n\\it\nOn page 185:\n\\textit{Define $S=S'-5 log s$ ....}\nError: $\\delta=log(\\sqrt(s)/r)$\nCorrection: $\\delta=log(s/r)$\nWHY?:\nLet's start from scratch:\\\\\nGiven: $S=S' -5\\ log\\ s$ and $log(p/s)=1$\n\\begin{subequations}\n\\label{eq:185}\nS'= 3\\ log\\ p + log\\ q + 2\\ log\\ r \\\\\nS = S'-5 log\\ s = 3(log\\ p - log\\ s) + (log\\ q - log\\ s) + 2(log\\ r - log\\ s)  \\\\\nS = 3 - $\\mu$ - 2$\\delta$\n\\end{subequations}\n\nComparing \\ref{eq:185}b and \\ref{eq:185}c we see: \\\\\n$\\delta = log(s/r)$ \n\\end{document}\n", "meta": {"hexsha": "5f6ab936acc66428074d966a8e8ddf30e6606694", "size": 864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Waterman_Introduction_to_Computational_Biology/Chapter9/errata.tex", "max_stars_repo_name": "saketkc/errata", "max_stars_repo_head_hexsha": "3b9bf503c61962d42babf2f4cf60a40244c23fd8", "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": "Waterman_Introduction_to_Computational_Biology/Chapter9/errata.tex", "max_issues_repo_name": "saketkc/errata", "max_issues_repo_head_hexsha": "3b9bf503c61962d42babf2f4cf60a40244c23fd8", "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": "Waterman_Introduction_to_Computational_Biology/Chapter9/errata.tex", "max_forks_repo_name": "saketkc/errata", "max_forks_repo_head_hexsha": "3b9bf503c61962d42babf2f4cf60a40244c23fd8", "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.1818181818, "max_line_length": 81, "alphanum_fraction": 0.6377314815, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324611869563, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6040522365979062}}
{"text": "\\subsection{Classification}\n\\label{sec:impl_classification}\n\n\nThe first naive idea, which assigns a cluster, i.e., writing style group, to a blog post, is to calculate the \\textit{Euclidean} distance from the blog post to the central points of each cluster.\nThe resulting cluster would then be the one with the lowest distance.\nWhile this method is computationally simple and fast, it might not provide the best possible results.\nTherefore we looked at more sophisticated approaches that were used for similar problems before.\nWe applied two of those methods, a \\textit{k-nearest neighbor} algorithm~\\cite{peterson2009k} and a \\textit{support vector machine}~\\cite{kolari2006svms}.\nThe training data for these algorithms is based on the clustering results, as described in Section~\\ref{sec:clustering}.\n\n\n\\subsubsection{K-Nearest Neighbor}\n\\label{sec:k_nearest_neighbor}\n\n\nThe \\textit{k-nearest neighbor} algorithm selects the $k$ vectors from the training data, which are closest to the feature vector of the new blog post.\nThen it returns the cluster that is prevalent amongst these neighbors as a result.\nFor example consider the scenario depicted in Figure~\\ref{fig:naive}.\nThe naive method of calculating the \\textit{Euclidean} distance between the cluster center and the feature vector of the new blog post would have cluster 2 as a result.\nHowever the \\textit{k-nearest neighbor} algorithm with, for example $k=5$, returns cluster 1, because four out of the five closest neighbors belong to cluster 1.\nIntuitively, this appears as the better solution, because the feature vector of the new blog post seems to be naturally belonging to cluster 1.\n\n\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{images/naive.pdf}\n    \\caption{The naive approach, which calculates the \\textit{Euclidean} distance to the center of the cluster, would put the new blog post into cluster 2. The \\textit{k-nearest neighbor} algorithm would return cluster 1 as a result.}\n    \\label{fig:naive}\n\\end{figure}\n\n\n\\subsubsection{Support Vector Machine}\n\\label{sec:support_vector_machine}\n\n\nA \\textit{support vector machine} creates a model to distinguish between the different clusters of the training data by calculating borders between them.\nThese borders can be thought of as functions in the same vector space as the feature vectors.\nIf the \\textit{support vector machine} uses a linear model, this might look such as shown in Figure~\\ref{fig:svm}, represented in a two-dimensional graph.\nBoth, the dotted and the dashed line serve as examples for a possible border, but the \\textit{support vector machine} should usually tend to use the model with more distance to all feature vectors.\nIn this case, the dashed line would more accurately divide cluster 1 and 2.\n\n\nWe used the \\textit{support vector machine} implementation LIBSVM\\footnote{\\url{http://www.csie.ntu.edu.tw/~cjlin/libsvm/}}, as described by Fan et al.~\\cite{fan2005working}.\nWe followed the configuration procedure proposed by Hsu et al.~\\cite{hsu2003practical}.\nIn the end we used the default configuration of type C-SVC and a radial basis function kernel for the \\textit{support vector machine}.\nThe only parameter we adapted was $c=1000$, which was done using cross-validation, as recommended by Hsu et al. to prevent overfitting on our data set.\n\n\n\\begin{figure}[ht!]\n    \\centering\n    \\includegraphics[width=0.6\\textwidth]{images/svm.pdf}\n    \\caption{Two differently configured \\textit{support vector machines} might provide the two different lines as borders between the different clusters. The dotted line would result in the blog post belonging to cluster 1, while the dashed line would return cluster 2 as a result.}\n    \\label{fig:svm}\n\\end{figure}\n", "meta": {"hexsha": "9a8604c501133d7bcd8019bddaeb7d7c745c724b", "size": 3738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/03c_classification.tex", "max_stars_repo_name": "tabergma/similar_author_identification", "max_stars_repo_head_hexsha": "15ca2bd44f1ff19bf62317f7b146f501a2e60699", "max_stars_repo_licenses": ["MIT"], "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/03c_classification.tex", "max_issues_repo_name": "tabergma/similar_author_identification", "max_issues_repo_head_hexsha": "15ca2bd44f1ff19bf62317f7b146f501a2e60699", "max_issues_repo_licenses": ["MIT"], "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/03c_classification.tex", "max_forks_repo_name": "tabergma/similar_author_identification", "max_forks_repo_head_hexsha": "15ca2bd44f1ff19bf62317f7b146f501a2e60699", "max_forks_repo_licenses": ["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.75, "max_line_length": 282, "alphanum_fraction": 0.7897271268, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6040522355498014}}
{"text": "\\documentclass[letterpaper,11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[hmargin=1.25in,vmargin=1in]{geometry}\n\\usepackage{booktabs}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{lmodern}\n\\usepackage{microtype}\n\n\\title{Coursework 1: STAT 570}\n\\author{Philip Pham}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\begin{enumerate}\n\\item The data we analyze are from a 1970s study that investigated insurance\n  redlining on $n = 47$ zipcodes. Information on who was being refused\n  homeowners is not available so instead we take as response the number of FAIR\n  plan policies written and renewed in Chicago by zip code over the period\n  December 1977 to May 1978. The FAIR plan was offered by the city of Chicago as\n  a default policy to homeowners who had been rejected by the voluntary market.\n  The data we will analyze are named \\texttt{chredlin} and are in the\n  \\texttt{faraway} package. The variable \\texttt{involact} are the number of new\n  FAIR plan policies and renewals per 100 housing units.\n\n  We will consider five covariates for modeling the response: racial composition\n  in percent minority (\\texttt{race} $x_{i1}$), fires per 100 housing units\n  (\\texttt{fire} $x_{i2}$), theft per 1000 population (\\texttt{theft} $x_{i3}$),\n  percent of housing units built before 1939 (\\texttt{age} $x_{i4}$), log\n  median family income in thousands of dollars (\\texttt{lincome} $x_{i5}$`),\n  $i = 1,\\ldots,47$.\n\n  We will examine the model with the main effects due to race, fire, theft, age\n  and $\\log(\\mathrm{income})$.\n\n  We let $Y_i$ represent \\texttt{involact}, and\n  $x_i = \\left(x_{i1}, x_{i2}, \\ldots, x_{i5}\\right)$, the covariates, for\n  individual $i$, $i = 1,2,\\ldots,47$. We fit the model\n  \\begin{equation}\n    y_i = \\beta_0 + \\sum_{j=1}^5x_{ij}\\beta_j + \\epsilon_i\n    \\label{eqn:p1_model}\n  \\end{equation}\n  for $i=1,\\ldots,n$ using least squares.\n\n  \\begin{enumerate}\n  \\item Provide informative plots to illustrate what we might expect to learn\n    from the model in Equation \\ref{eqn:p1_model}.\n    \\label{part:p1a}\n\n    \\begin{description}\n    \\item[Solution:] See Figure \\ref{fig:p1_pair_plots} and the corresponding\n      code in\n      \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw1/chredlin\\_explore.ipynb}{\\texttt{chredlin\\_explore.ipynb}}.\n\n      \\texttt{fire}, \\texttt{race}, and \\texttt{age} appear to be positively\n      correlated with \\texttt{involact}. \\texttt{income} appears to be\n      negatively correlated.\n\n      Zipcodes in the northern \\texttt{side} of Chicago have a lower minority\n      population and higher income. \\texttt{involact} is smaller in these\n      northern zipcodes, too.\n    \\end{description}\n  \\item Give interpretations of the parameters $\\beta_j$, $j = 1,\\ldots,5$.\n    \\label{part:p1b}\n    \\begin{table}\n      \\centering\n      \\input{p1_model_parameters.tex}\n      \\caption{The result of fitting the model described in Equation\n        \\ref{eqn:p1_model}. The procedure for obtaining the estimates and test\n        statistics is described in Part \\ref{part:p1_model}.}\n      \\label{tab:p1_model_parameters}\n    \\end{table}\n\n    \\begin{description}\n    \\item[Solution:] Fitting such a model, we get the estimates in Table\n      \\ref{tab:p1_model_parameters} for $\\beta_j$.\n\n      The percent of minorities (\\texttt{race}) and frequency of fires\n      (\\texttt{fire}) are positively correlated with the number of FAIR plan\n      policies. \\texttt{involact} is the number of FAIR plans per 100 housing\n      units. Thus, every percent increase in racial minorities means about 1\n      FAIR plan, and for every fire per 100 housing units, there are 3 FAIR\n      plans.\n\n      \\texttt{age} seems to have postive effect on \\texttt{involact}, while\n      \\texttt{theft} has a negative effect.\n\n      \\texttt{log\\_income} doesn't seem to tell us anything new: it's correlated\n      with other covariates, and its effect is mainly due to chance.      \n    \\end{description}\n    \n  \\item Reproduce every number in the handout using matrix and arithmetic\n    operations.\n    \\label{part:p1_model}\n\n    \\begin{description}\n    \\item[Solution:] Let us assume that\n      $\\epsilon_i \\sim \\mathcal{N}\\left(0, \\sigma^2\\right)$. The log-likelihood\n      of this model is\n      \\begin{align}\n        \\sum_{i=1}^n \\log\\mathbb{P}\\left(y_i \\mid x_i, \\beta, \\sigma^2\\right)\n        &= -\\frac{n}{2}\\log\\left(2\\pi\\sigma^2\\right)\n          - \\frac{1}{2\\sigma^2}\\sum_{i=1}^n \\left(y_i - x_i^\\intercal\\beta\\right)^2\n          \\nonumber \\\\\n        &= -\\frac{n}{2}\\log\\left(2\\pi\\sigma^2\\right) - \\frac{1}{2\\sigma^2}\\left\\lVert\n          y - X\\beta\n          \\right\\rVert_2^2,\n          \\label{eqn:p1_log_likelihood}\n      \\end{align}\n      where we $0$-index $\\beta$ and the columns of $X$, so each row of $X$ is\n      $x_i = \\left(1, x_{i1}, x_{i2},\\ldots,x_{i5}\\right)$.\n\n      \\subsection*{Estimating $\\hat{\\beta}$}\n\n      To maximize Equation \\ref{eqn:p1_log_likelihood}, we choose $\\hat{\\beta}$\n      such that $X\\hat{\\beta}$ is the projection of $y$ onto the hyperplane\n      spanned by the columns of $X$. Thus, we must have that\n      $X^\\intercal\\left(y - X\\hat{\\beta}\\right) = 0$ since the residuals will\n      orthogonal to the columns of $X$ if $X\\hat{\\beta}$ is the projection that\n      minimizes the squared error. Solving for $\\hat{\\beta}$, we have that\n      \\begin{equation}\n        \\hat{\\beta} = \\left(X^\\intercal X\\right)^{-1} X^\\intercal y.\n        \\label{eqn:p1_beta_hat}\n      \\end{equation}\n      The results of apply Equation \\ref{eqn:p1_beta_hat} can be seen in the\n      first column of Table \\ref{tab:p1_model_parameters}.\n\n      \\subsection*{Estimating $\\hat{\\sigma}^2$}\n\n      Let us derive an unbiased estimator for residual standard error. Consider\n      the residual random vector.\n\n      \\begin{equation}\n        R = y - X\\hat{\\beta}\n      \\end{equation}\n\n      As stated earlier, the residuals are orthogonal to hyperplane spanned by\n      the columns of $X$, so they must lie in some orthonormal hyperplane of\n      $N - p$ vectors, where $p = \\dim(\\beta)$. Thus, residuals are $y$\n      projected down to this space.\n\n      Let $w_1,\\ldots,w_{n-p}$ be an orthonormal basis of this space. Let $W$ be\n      matrix with these basis vectors as the columns.\n\n      We have that\n      \\begin{align}\n        R &= y - X\\hat{\\beta} \\nonumber\\\\\n          &= W\\left(W^\\intercal y\\right) \\nonumber\\\\\n          &= W\\left(W^\\intercal\\left(X\\beta + \\sigma\\epsilon\\right)\\right) \\nonumber\\\\\n          &= W\\left(W^\\intercal X\\right)\\beta + \\sigma W\\left(W^\\intercal\\epsilon\\right) \\nonumber\\\\\n          &= \\sigma W\\left(W^\\intercal\\epsilon\\right).\n      \\end{align}\n\n      Now, $W^\\intercal\\epsilon \\sim \\mathcal{N}\\left(0, I_{n-p}\\right)$. To see\n      this, note that the $i$th entry is\n      $\\sum_{j=1}^n w_{ij}\\epsilon_j \\sim \\mathcal{N}\\left(0, 1\\right)$, and for\n      $i \\neq i^\\prime$,\n      \\begin{align*}\n        \\operatorname{Cov}\\left(\n        \\left(W^\\intercal\\epsilon\\right)_i, \\left(W^\\intercal\\epsilon\\right)_{i^\\prime}\\right)\n        &=\n          \\mathbb{E}\\left[\n          \\left(\\sum_{j=1}w_{ij}\\epsilon_j\\right)\\left(\\sum_{k=1}w_{i^\\prime k}\\epsilon_k\\right)\n          \\right] \\\\\n        &= \\sum_{j=1}^n\\mathbb{E}\\left[w_{ij}w_{i^\\prime j} \\epsilon_j^2\\right] +\n          2\\sum_{j=1}^{n-1}\\sum_{k=j+1}^n \\mathbb{E}\\left[w_{ij}w_{i^\\prime k} \\epsilon_j\\epsilon_k\\right] \\\\\n        &= w_i^\\intercal w_{i^\\prime} + 2\\sum_{j=1}^{n-1}\\sum_{k=j+1}^n w_{ij}w_{i^\\prime k}\n          \\mathbb{E}\\left[\\epsilon_j\\epsilon_k\\right] \\\\\n        &= 0,\n      \\end{align*}\n      where the first term disappears by since the two vectors are orthonormal,\n      and the second term disappears because of independence of the errors.\n\n      Thus, we have that\n\n      \\begin{equation}\n        R^\\intercal R\n        = \\sigma^2 \\left(W^\\intercal\\epsilon\\right)^\\intercal W^\\intercal W \\left(W^\\intercal\\epsilon\\right)\n        = \\sigma^2 \\left(W^\\intercal\\epsilon\\right)^\\intercal\\left(W^\\intercal\\epsilon\\right)\n        \\sim \\sigma^2 \\chi^2_{n-p}.\n        \\label{eqn:p1_residual_distribution}\n      \\end{equation}\n\n      Finally, we have that\n\n      \\begin{equation*}\n        \\mathbb{E}\\left[R^\\intercal R\\right] = \\sigma^2\\left(n - p\\right)\n        \\Rightarrow\n        \\mathbb{E}\\left[\\frac{\\sum_{i=1}^n \\left(y - X\\hat{\\beta}\\right)^2}{n-p}\\right] = \\sigma^2.\n      \\end{equation*}\n\n      Our consistent estimator is\n\n      \\begin{equation}\n        \\hat{\\sigma}^2 = \\frac{\\sum_{i=1}^n \\left(y - X\\hat{\\beta}\\right)^2}{n-p}.\n        \\label{eqn:p1_sample_variance}\n      \\end{equation}\n\n      Applying Equation \\ref{eqn:p1_sample_variance}, we obtain\n      \\boxed{\\hat{\\sigma} = \\input{p1_residual_standard_error.txt}\\unskip.}\n\n      \\subsection*{Hypothesis Testing}\n\n      We can rewrite $y$ as $y = X\\beta + \\sigma \\epsilon$, where each element\n      of $\\epsilon$ is drawn from $\\mathcal{N}\\left(0, 1\\right)$. Substituting,\n      we have that\n      \\begin{align}\n        \\hat{\\beta}\n        &= \\left(X^\\intercal X\\right)^{-1}X^\\intercal\\left(X\\beta + \\sigma\\epsilon\\right) \\nonumber\\\\\n        &= \\beta + \\sigma\\left(X^\\intercal X\\right)^{-1}X^\\intercal \\epsilon.\n          \\label{eqn:p1_beta_hat_distribution}\n      \\end{align}\n\n      Thus, $\\hat{\\beta}_j \\sim \\mathcal{N}\\left(\\beta_j, \\sigma^2\\left(X^\\intercal X\\right)^{-1}_{jj}\\right)$.\n\n      This gives us that\n      \\begin{equation*}\n        \\frac{\\hat{\\beta}_j - \\beta_j}{\\sqrt{\\sigma^2\\left(X^\\intercal X\\right)^{-1}_{jj}}} \\sim\n        \\mathcal{N}\\left(0, 1\\right).\n      \\end{equation*}\n\n      From Equations \\ref{eqn:p1_residual_distribution} and \\ref{eqn:p1_sample_variance},\n      \\begin{equation}\n        (n - p)\\frac{\\hat{\\sigma}^2}{\\sigma^2} \\sim \\chi^2_{n-p}.\n      \\end{equation}\n\n      $\\hat{\\beta}$ and $\\hat{\\sigma}^2$ are independent by\n      \\href{https://en.wikipedia.org/wiki/Basu\\%27s_theorem}{Basu's theorem}:\n      $\\hat{\\sigma}^2$ is an ancillary statistic that does not depend on the\n      model parameters, $\\beta$. Thus, we have that\n      \\begin{equation}\n        \\left.\n          \\frac{\\hat{\\beta}_j - \\beta_j}{\\sqrt{\\sigma^2\\left(X^\\intercal X\\right)^{-1}_{jj}}}\n          \\middle/\n          \\sqrt{\\frac{(n - p)\\frac{\\hat{\\sigma}^2}{\\sigma^2}}{n-p}}\n        \\right. \n        = \\frac{\\hat{\\beta}_j - \\beta_j}{\\sqrt{\\hat{\\sigma}^2\\left(X^\\intercal X\\right)^{-1}_{jj}}}\n        \\sim t_{n-p}.\n        \\label{eqn:p1_beta_hat_j_distribution}\n      \\end{equation}\n\n      That is, we have $t$ distribution with $n - p$ degrees of freedom. The\n      denominator of Equation \\ref{eqn:p1_beta_hat_j_distribution} gives the\n      second column of Table \\ref{tab:p1_model_parameters}.\n\n      For each $\\beta_j$, our null hypothesis is $H_0: \\beta_j = 0$. Thus, our\n      $t$-test statistic is obtain from substituting $\\beta_j$ into Equation\n      \\ref{eqn:p1_beta_hat_j_distribution},\n      \\begin{equation*}\n        \\hat{t}_j = \\frac{\\hat{\\beta}_j}{\\sqrt{\\hat{\\sigma}^2\\left(X^\\intercal X\\right)^{-1}_{jj}}},\n      \\end{equation*}\n      which gives us the third column of Table \\ref{tab:p1_model_parameters}.\n\n      The fourth column is the probability of obtaining evidence that\n      contradicts the null hypothesis at least as much. Let $F^{-1}_{t_{n-p}}$\n      be the inverse cumulative distribution function. The $p$-value is\n      \\begin{equation*}\n        \\mathbb{P}\\left(\n          \\left\\lvert T_{n - p}\\right\\rvert \\geq\n          \\left\\lvert \\hat{t}_j\\right\\rvert\n          \\mid\n          \\hat{t}_j\n        \\right) = \n        2\\left(1 - F^{-1}_{n - p}\\left(\\left\\lvert\\hat{t}_j\\right\\rvert\\right)\\right).\n      \\end{equation*}\n\n      These calculations are carried out in\n      \\href{https://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw1/chredlin\\_model.ipynb}{\\texttt{chredlin\\_explore.ipynb}}.\n    \\end{description}\n    \n  \\item What assumptions are valid for:\n    \\begin{enumerate}\n    \\item An unbiased estimate of $\\beta_j$, $j = 1,\\ldots,5$.\n      \\label{part:p1di}\n        \n      \\begin{description}\n      \\item[Solution:] From Equation \\ref{eqn:p1_beta_hat_distribution}, we have\n        that\n        \\begin{equation}\n          \\mathbb{E}\\left[\\hat{\\beta}\\right]\n          =\n          \\beta + \\left(X^\\intercal X\\right)^{-1}X^\\intercal \\mathbb{E}\\left[\\epsilon\\right]\n        \\end{equation}\n        since expectation is a linear operator. In our previous calcuations, we\n        assumed that the $\\epsilon_i$ were independent and normally distributed.\n\n        It's sufficient, however, that\n        $\\boxed{\\mathbb{E}\\left[\\epsilon\\right] = \\mathbf{0}.}$ Then, we'll have\n        \\begin{equation*}\n          \\operatorname{bias}\\left(\\hat{\\beta}\\right) =\n          \\mathbb{E}\\left[\\hat{\\beta}\\right] - \\beta\n          = \\beta - \\beta = 0.\n        \\end{equation*}\n      \\end{description}\n    \\item An accurate estimate of the standard error of $\\hat{\\beta}_j$,\n      $j = 1,\\ldots,5$.\n\n      \\begin{description}\n      \\item[Solution:] From Equation \\ref{eqn:p1_beta_hat_distribution}, we can\n        estimate the standard error exactly if $\\sigma^2$ is known. For\n        $\\hat{\\beta}_j$, we get $\\sigma\\sqrt{\\left(X^\\intercal X\\right)_{jj}^{-1}}$.\n\n        When $\\sigma^2$ is unknown, but our errors are still independent and\n        normally distributed, we apply Equation\n        \\ref{eqn:p1_beta_hat_j_distribution}. Since $\\hat{\\beta}_j$ has Student's\n        $t$-distribution, we can estimate the standard error for $\\hat{\\beta}_j$\n        with $\\sqrt{\\hat{\\sigma}^2\\left(X^\\intercal X\\right)_{jj}^{-1}}$.\n\n        If our errors are not normally distributed, our estimate is only\n        accurate if the number of observations is large, and our errors have a\n        distribution that converges to a normal distribution.\n      \\end{description}\n    \\item Accurate coverage probabilities for $100\\left(1 - \\alpha\\right)\\%$\n      confidence intervals of the form\n      \\begin{equation}\n        \\hat{\\beta}_j \\pm \\sqrt{\\hat{\\sigma}_j^2}z_{1-\\alpha/2},\n        \\label{eqn:p1_confidence_interval_normal}\n      \\end{equation}\n      where $z_{1-\\alpha/2}$ represents the $\\left(1-\\alpha/2\\right)$ quantile\n      of an $\\mathcal{N}\\left(0, 1\\right)$ random variable, and\n      $\\hat{\\sigma}_j^2 = \\hat{\\sigma}^2\\left(X^\\intercal X\\right)_{jj}^{-1}$.\n\n      \\begin{description}\n      \\item[Solution:] Firstly, the assumptions from the previous part must hold\n        for $\\hat{\\sigma}_j^2$ to be meaningful.\n\n        From Equation \\ref{eqn:p1_beta_hat_j_distribution}, $\\hat{\\sigma}_j^2$\n        has Student's $t$-distribution, so the normal approximation for the the\n        confidence interval (Equation \\ref{eqn:p1_confidence_interval_normal})\n        only holds when $n$ is large.\n      \\end{description}\n            \n    \\item Accurate coverage probabilities for $100\\left(1 - \\alpha\\right)\\%$\n      confidence intervals of the form\n\n      \\begin{equation}\n        \\hat{\\beta}_j \\pm \\sqrt{\\hat{\\sigma}_j^2}t_{n-p}\\left(1-\\alpha/2\\right),\n        \\label{eqn:p1_confidence_interval_t}\n      \\end{equation}\n      where $p = \\dim\\left(\\beta\\right)$ and $t_{n-p}\\left(1-\\alpha/2\\right)$\n      represents the $\\left(1-\\alpha/2\\right)$ quantile of standard Student's\n      $t$ random variable with $n - p$ degrees of freedom.\n\n      \\begin{description}\n      \\item[Solution:] Equation \\ref{eqn:p1_beta_hat_j_distribution} shows that\n        this is exactly the correct distribution when the $\\epsilon_i$ are\n        independent and identically distributed as normal random variables with\n        mean zero.\n\n        It may still prove to be an accurate confidence interval if the errors\n        have distributions that are well-approximated by the normal\n        distribution and the number of observations is large.\n      \\end{description}\n    \\item An accurate prediction for an \\emph{observed} outcome at $x_0$.\n      \n      \\begin{description}\n      \\item[Solution:] Suppose we were to observe\n        $\\left(x_0, y_0 = x_0^\\intercal\\beta + \\epsilon_0\\right)$. Let our\n        prediction be $\\hat{y}_0 = x_0^\\intercal\\hat{\\beta}$. If the conditions\n        in Part \\ref{part:p1di} are satisfied, the error has mean zero, and our\n        estimate for $\\hat{\\beta}$ is unbiased, so\n        \\begin{equation*}\n          \\mathbb{E}\\left[y_0\\right]\n          = x_0^\\intercal\\beta\n          = \\mathbb{E}\\left[\\hat{y}_0\\right].\n        \\end{equation*}\n        \n        We want to compare our prediction with $\\hat{y}_0$ with some\n        hypothetical observed response $y_0$. We'll call our prediction\n        accurate within $\\delta > 0$ if\n        \\begin{equation*}\n          \\hat{y}_0 - \\delta \\leq y_0 \\leq \\hat{y}_0 + \\delta.\n        \\end{equation*}\n\n        We want the probability of this event to be high, so we'll say accurate\n        within $\\delta$ at confidence level $1 - \\alpha$ if\n        \\begin{equation*}\n          \\mathbb{P}\\left(\\hat{y}_0 - \\delta \\leq y_0 \\leq \\hat{y}_0 + \\delta\\right)\n          = \\mathbb{P}\\left(-\\delta \\leq y_0 - \\hat{y}_0 \\leq \\delta\\right)\n          \\geq 1 - \\alpha.\n        \\end{equation*}\n        Our prediction is accurate if for small $\\alpha$, we have small\n        $\\delta$.\n\n        If we assume normality, we can calculate the minimum $\\delta$ for a\n        specific $\\alpha$, which we'll denote $\\delta_\\alpha$.\n\n        Since $\\hat{\\beta}$ satisfies\n        $\\left(X^\\intercal X\\right)\\hat{\\beta} = X^\\intercal y$, we have that\n        the intercept estimate is\n        \\begin{equation}\n          \\hat{\\beta}_0 = \\bar{y} - \\sum_{j=1}^p \\hat{\\beta}_j \\bar{X}_{:,j}.\n        \\end{equation}\n\n        Consider trying to predict $\\hat{y} = x^\\intercal\\hat{\\beta}$ for some\n        $x$. We have that\n        \\begin{equation}\n          \\hat{y} = \\bar{y} + \\sum_{j=1}^p \\left(x_i - \\bar{X}_{:,j}\\right)\\hat{\\beta}_j,\n        \\end{equation}\n        so the variance of the prediction increases with values far from data.\n\n        Let $\\bar{X}$ be the vector of column-wise means of $X$. Since\n        $\\bar{\\epsilon}$ is an ancillary statistic, this can also be written as\n\n        \\begin{equation}\n          \\hat{y} \\mid x \\sim \\mathcal{N}\\left(\n            x^\\intercal \\beta,\n            \\sigma^2 \\left(\n              \\frac{1}{n} +\n              \\left(x - \\bar{X}\\right)^\\intercal\n              \\left(X^\\intercal X\\right)^{-1}\n              \\left(x - \\bar{X}\\right)\n            \\right)\n          \\right).\n        \\end{equation}\n\n        Using the same method as in deriving Equation\n        \\ref{eqn:p1_beta_hat_j_distribution}, if we replace $\\beta$ with\n        $\\hat{\\beta}$ and $\\sigma^2$ with $\\hat{\\sigma}^2$, we have\n        \\begin{equation}\n          \\frac{\\hat{y} - x^\\intercal\\hat{\\beta}}{\n            \\sqrt{\\hat{\\sigma}^2\\left(\\frac{1}{n} +\n              \\left(x - \\bar{X}\\right)^\\intercal\n              \\left(X^\\intercal X\\right)^{-1}\n              \\left(x - \\bar{X}\\right)\\right)}}\n          \\sim t_{n-p}.\n          \\label{eqn:p1_response_confidence_interval}\n        \\end{equation}\n\n        Noting that\n        $y_0 \\sim \\mathcal{N}\\left(x_0^\\intercal\\beta, \\sigma^2\\right)$, we can\n        apply Equation \\ref{eqn:p1_response_confidence_interval} to\n        $\\left(x_0, y_0\\right)$, which gives us\n        \\begin{equation*}\n          \\boxed{\n            \\delta_\\alpha\n            =\n            t_{n-p}\\left(1 - \\alpha/2\\right)\n            \\sqrt{\\hat{\\sigma}^2\\left(\n                1 + \\frac{1}{n} +\n                \\left(x_0 - \\bar{X}\\right)^\\intercal\n                \\left(X^\\intercal X\\right)^{-1}\n                \\left(x_0 - \\bar{X}\\right)\n              \\right).\n            }\n          }\n        \\end{equation*}\n\n        Thus, our predictions will always have standard error of at least\n        $\\sigma$, but they will be more accurate when $x_0$ is close to\n        $\\bar{X}$.\n      \\end{description}\n    \\end{enumerate}\n  \\item Summarize the relationship between $y$, and $x_1$, $x_2$, $x_3$, $x_4$,\n    $x_5$, fitting any other models that you see fit to.\n\n    \\begin{description}\n    \\item[Solution:] The relationship between $y$ and the covariates was\n      described in Parts \\ref{part:p1a} and \\ref{part:p1b}.\n\n      Particularly, we see \\texttt{income} does not explain much about\n      \\texttt{involact} due to multicollinearity: it is correlated with\n      \\texttt{race} and \\texttt{fire}.\n\n      Removing \\texttt{log\\_income} from the model gives us the model parameters\n      in Table \\ref{tab:p1_model_parameters_custom}. The residual standard error\n      for this model was \\input{p1_residual_standard_error_custom.txt}\\unskip,\n      which is actually ever so slightly smaller than the model that includes\n      income.\n\n      \\begin{table}\n        \\centering\n        \\input{p1_model_parameters_custom.tex}\n        \\caption{The result of fitting a model without considering income.}\n        \\label{tab:p1_model_parameters_custom}\n      \\end{table}\n\n      I tried adding an indicator for \\texttt{side} but it suffers from the same\n      issue as \\texttt{income}: its effect is already explained by the other\n      covariates.\n    \\end{description}\n  \\end{enumerate}\n\n  \\pagebreak\n\\item Consider the following distributions:\n  \\begin{description}\n  \\item[Poisson:] \\begin{equation}\n      p\\left(y \\mid \\mu\\right) = \\frac{\\exp\\left(-\\mu\\right)\\mu^y}{y!},\n      \\label{eqn:p2_poisson}\n    \\end{equation}\n    for $y = 0,1,2,\\ldots$.\n    \n  \\item[Gamma:] \\begin{equation}\n      p\\left(y \\mid \\alpha, \\beta\\right) =\n      \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}y^{\\alpha - 1}\\exp(-\\beta y)\n      \\label{eqn:p2_gamma}\n    \\end{equation}\n    for $y > 0$ and with $\\alpha$ known.\n    \n  \\item[Inverse Gaussian:]\n    \\begin{equation*}\n      p\\left(y \\mid \\mu, \\delta\\right) =\n      \\left(\\frac{\\delta}{2\\pi y^3}\\right)^{1/2}\n      \\exp\\left[\n        \\frac{-\\delta\\left(y-\\mu\\right)^2}{2\\mu^2y}\n      \\right]\n      \\label{eqn:p2_inverse_gaussian}\n    \\end{equation*}\n    for $y > 0$ and $\\delta$ known.\n\n  \\end{description}\n\n  A distribution is said to be a member of the one parameter exponential family\n  of distributions if it can be written as\n  \\begin{equation}\n    p\\left(y \\mid \\eta_1,\\eta_2\\right) = h(y)\\exp\\left[\n      \\eta_1y + \\eta_2T_2(y) - A\\left(\\eta_1,\\eta_2\\right)\n    \\right],\n    \\label{eqn:p2_exponential}    \n  \\end{equation}\n  where $\\eta_2$ is known.\n  \n  \\begin{enumerate}\n  \\item Show that each of the above distributions is a member of the exponential\n    family and identify $\\eta_1$, $\\eta_2$, $T_2(y)$,\n    $A\\left(\\eta_1,\\eta_2\\right)$, and $h(y)$.\n    \\label{part:p2a}\n    \\begin{description}\n    \\item[Solution:] For each distribution, we can do some algebra.\n      \n      \\begin{description}\n      \\item[Poisson:] We can rewrite Equation \\ref{eqn:p2_poisson} as Equation\n        \\ref{eqn:p2_exponential}, where\n        \\begin{align*}\n          \\eta_1 &= \\log\\mu \\\\\n          \\eta_2 &= 0 \\\\\n          T_2(y) &= 0 \\\\          \n          A\\left(\\eta_1,\\eta_2\\right) &= \\exp(\\eta_1) \\\\\n          h(y) &= \\frac{1}{y!}.\n        \\end{align*}\n      \\item[Gamma:] We can rewrite Equation \\ref{eqn:p2_gamma} as Equation\n        \\ref{eqn:p2_exponential}, where\n        \\begin{align*}\n          \\eta_1 &= -\\beta \\\\\n          \\eta_2 &= \\alpha - 1 \\\\\n          T_2(y) &= \\log(y) \\\\\n          A\\left(\\eta_1,\\eta_2\\right)\n                 &=-\\left(\\eta_2 + 1\\right)\\log\\left(-\\eta_1\\right) +\n                   \\log\\Gamma\\left(\\eta_2 + 1\\right)\\\\\n          h(y) &= 1.\n        \\end{align*}\n      \\item[Inverse Gaussian:] We can rewrite Equation \\ref{eqn:p2_inverse_gaussian} as\n        Equation \\ref{eqn:p2_exponential}, where\n        \\begin{align*}\n          \\eta_1 &= -\\frac{\\delta}{2\\mu^2} \\\\\n          \\eta_2 &= -\\frac{\\delta}{2} \\\\\n          T(y) &= \\frac{1}{y} \\\\\n          A\\left(\\eta_1,\\eta_2\\right)\n                 &= -2\\sqrt{\\eta_1\\eta_2} -\n                   \\frac{1}{2}\\log\\left(-2\\eta_2\\right) \\\\\n          h(y) &= \\frac{1}{\\sqrt{2\\pi y^3}}.\n        \\end{align*}\n      \\end{description}      \n    \\end{description}\n  \\item Identify $\\mathbb{E}\\left[Y \\mid \\theta\\right]$ and\n    $\\operatorname{Var}\\left(Y \\mid \\theta\\right)$.\n    \\begin{description}\n    \\item[Solution:] We can derive a general formula for computing the mean and\n      variance from Equation \\ref{eqn:p2_exponential}.\n\n      The log-likelihood function is\n      \\begin{equation}\n        l\\left(\n          \\eta_1, \\eta_2\n        \\right) =\n        \\log h(y) + \\eta_1y + \\eta_2 T_2(y) - A\\left(\\eta_1,\\eta_2\\right).\n      \\end{equation}\n\n      If $\\eta_2$ is known, the score function is\n      \\begin{equation}\n        S\\left(\\eta_1, \\eta_2\\right) = \\frac{\\partial l\\left(\\eta_1,\\eta_2\\right)}{\\partial \\eta_1}\n        =\n        y - \\frac{\\partial A\\left(\\eta_1,\\eta_2\\right)}{\\partial \\eta_1}.\n      \\end{equation}\n\n      The expectation of the score is $0$, so\n      \\begin{equation}\n        \\boxed{\\mathbb{E}\\left[y \\mid \\eta_1, \\eta_2\\right] =\n        \\frac{\\partial A\\left(\\eta_1,\\eta_2\\right)}{\\partial \\eta_1}.}\n        \\label{eqn:p2_score_mean}\n      \\end{equation}\n\n      The variance of the score is Fisher information, so\n      \\begin{align}\n        \\mathcal{I}\\left(\\eta_1, \\eta_2\\right)\n        &=\n        \\operatorname{Var}\\left(\n        S\\left(\\eta_1, \\eta_2\\right)\n          \\right) \\nonumber\\\\\n        &= \\mathbb{E}\\left[\n          \\left(y -\n          \\frac{\\partial A\\left(\\eta_1,\\eta_2\\right)}{\\partial \\eta_1}\n          \\right)^2\n          \\mid\n          \\eta_1, \\eta_2\n          \\right]\\nonumber\\\\\n        &= \\operatorname{Var}\\left(y \\mid \\eta_1, \\eta_2\\right)\n          \\label{eqn:p2_fisher_variance}\n      \\end{align}\n      by Equation \\ref{eqn:p2_score_mean}\n      and using that the mean of the score function is $0$.\n\n      An alternative definition of the Fisher information is the expected value\n      of the observed information:\n      \\begin{equation}\n        \\mathcal{I}\\left(\\eta_1, \\eta_2\\right) =\n        - \\frac{\\partial^2 l\\left(\\eta_1,\\eta_2\\right)}{\\partial\\eta_1^2}\n        = \\frac{\\partial^2 A\\left(\\eta_1,\\eta_2\\right)}{\\partial\\eta_1^2}.\n        \\label{eqn:p2_fisher_expectation}\n      \\end{equation}\n\n      Combining Equations \\ref{eqn:p2_fisher_variance} and\n      \\ref{eqn:p2_fisher_expectation}, we obtain\n      \\begin{equation}\n        \\boxed{\n          \\operatorname{Var}\\left(y \\mid \\eta_1, \\eta_2\\right)\n          =\n          \\frac{\\partial^2 A\\left(\\eta_1,\\eta_2\\right)}{\\partial\\eta_1^2}.\n        }\n        \\label{eqn:p2_score_variance}\n      \\end{equation}\n\n      We can now apply Equations \\ref{eqn:p2_score_mean} and\n      \\ref{eqn:p2_score_variance} to our the results from Part \\ref{part:p2a}.\n      \\begin{description}\n      \\item[Poisson:]\n        \\begin{align*}\n          \\mathbb{E}\\left[y \\mid \\eta_1, \\eta_2\\right]\n          &= \\exp\\left(\\eta_1\\right) = \\mu \\\\\n          \\operatorname{Var}\\left(y \\mid \\eta_1, \\eta_2\\right)\n          &= \\exp\\left(\\eta_1\\right) = \\mu.\n        \\end{align*}\n      \\item[Gamma:]\n        \\begin{align*}\n          \\mathbb{E}\\left[y \\mid \\eta_1, \\eta_2\\right]\n          &= -\\frac{\\eta_2 + 1}{\\eta_1} = \\frac{\\alpha}{\\beta} \\\\\n          \\operatorname{Var}\\left(y \\mid \\eta_1, \\eta_2\\right)\n          &= \\frac{\\eta_2 + 1}{\\eta_1^2} = \\frac{\\alpha}{\\beta^2}.\n        \\end{align*}\n      \\item[Inverse Gaussian:]\n        \\begin{align*}\n          \\mathbb{E}\\left[y \\mid \\eta_1, \\eta_2\\right]\n          &= \\sqrt{\\frac{\\eta_2}{\\eta_1}} = \\mu \\\\\n          \\operatorname{Var}\\left(y \\mid \\eta_1, \\eta_2\\right)\n          &= \\frac{1}{2}\\sqrt{\\frac{\\eta_2}{\\eta_1^3}} = \\frac{\\mu^3}{\\delta}.\n        \\end{align*}\n      \\end{description}\n    \\end{description}\n\n  \\item The canonical link function is such that $g(\\mu) = \\eta_1$. Determine the\n    canonical link for each distribution.\n    \\begin{description}\n    \\item[Solution:] We can use the results from Part \\ref{part:p2a}.\n      \\begin{description}\n      \\item[Poisson:] $\\displaystyle g(\\mu) = \\exp(\\mu)$.\n      \\item[Gamma:] $\\displaystyle g(\\mu) = -\\frac{\\alpha}{\\mu} \\propto \\mu^{-1}$,\n        where $\\alpha$ is known.\n      \\item[Inverse Gaussian:]\n        $\\displaystyle g(\\mu) = -\\frac{\\delta}{2\\mu^2} \\propto \\mu^{-2}$, where $\\delta$ is\n        known.\n      \\end{description}\n    \\end{description}\n  \\end{enumerate}\n\\end{enumerate}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\textwidth]{p1_pair_plots.pdf}\n  \\caption{The empirical univariate and joint distributions for the\n    \\texttt{chredlin} dataset.}\n  \\label{fig:p1_pair_plots}\n\\end{figure}\n\n\\end{document}\n\n", "meta": {"hexsha": "7589770e4739a981ebefd2fca41aa1255856afde", "size": 28377, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw1/solutions.tex", "max_stars_repo_name": "ppham27/stat570", "max_stars_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-22T11:05:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T22:46:11.000Z", "max_issues_repo_path": "hw1/solutions.tex", "max_issues_repo_name": "ppham27/stat570", "max_issues_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_issues_repo_licenses": ["MIT"], "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/solutions.tex", "max_forks_repo_name": "ppham27/stat570", "max_forks_repo_head_hexsha": "859832aed3ae172abc8b6fbcd2221eb552291a00", "max_forks_repo_licenses": ["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.1260869565, "max_line_length": 139, "alphanum_fraction": 0.6131021602, "num_tokens": 8870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.604052229548767}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\setlength\\parindent{0pt}\n\\usepackage{multirow}\n\\usepackage{graphicx}\n\\usepackage{siunitx}\n\\usepackage{float}\n\\usepackage{derivative}\n\\usepackage{amsmath,amssymb}\n\n\n\\title{Assignment 2 description and solutions \\\\ CTA200H}\n\\author{Lechung Xing - 1004705170 }\n\\date{May 8th 2020}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question 1}\n\\subsection{Methods}\nIn order to plot the complex number z on a 2D plane, I separated z and c(the fixed point $x + iy$) into Real and Imaginary parts corresponding to x and y (axis) components, respectively. I found the expression \\(Z_{n+1}= [(ReZ_n)^2-(ImZ_n)^2+x] + 2i[(ReZ_n)(ImZ_n) + y]\\) for the sequence \\(Z_{n+1} = (Z_n)^2 + c, Z_0 = 0\\) as n increases. To test the divergence, I selected some c points with iteration steps varying from $10 to 50$ and computed the \\(|z|^2\\)for each step. The iteration terminated if \\(|z|^2\\) is larger than 2, which indicated the sequence is diverging under the initial choice of c. I created a n-dim array to partition the domain of c into a \\(Matrix_{n\\times{n}}\\) so that I can collect the diverging c points and marked them with colours to distinguish from the bounded ones. I attempted to demonstrate the rate of divergence for the diverging c points according to the relative difference between their  \\(|z|^2\\) value (i.e. the magnitude of the entries in \\(Matrix_{n\\times{n}} = np.abs(z)\\)).\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.7]{diverge(1,1).png}\n    \\includegraphics[scale=0.7]{2colours.png}\n    \\includegraphics[scale=0.5]{colorbar.png}\n    \\caption{a) The set of c points confined within a 4 by 4 square are plotted on the complex plane for $c = 1 + 1i$. b) The shaded region represents the c points that generate diverging sequence \\(z_{i+1}=(z_i)^2 + c\\). The yellow region shows the c points that yield bounded sequences. c)The rate of divergence with color bar generated from n-dim matrix entries. The color resembles the $3rd$ axis apart from x and y axis. }\n    \\label{fig:Q1}\n\\end{figure}\n\n\\section{Discussion}\nIn Fig. 1a, since $c = 1 + 1i$ yields diverging sequence from the $8th$ iteration step, the blue dots are far away from each other as expected. In Fig. 1b, the bounded c points are bounded by an open ball of radius 2 centered at the origin. The n-dim array of \\(|z|^2\\) contains different entries, unlike the homogeneous color as shown in Fig. 1c.\n\n\n\\section{Question 2}\n\\subsection{Methods}\nI implemented the initial condition: $N = 1000, S(t) + I(t) + R(t) = N for any t\\in[0, 200]$ to solve the ODE by using the $Scipy.odeint$ package. The parameters: $\\beta and \\gamma$ determine the slope of the first derivative of S, I, R. I expect S to decrease while I increases in the beginning followed by the delayed increase in R. To take into account of the death rate arising from the infected population, I added $D(t)*I(t)$ to $dI/dt$ and subtracted the death term from $dR/dt$ to satisfy the initial condition. \n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.31]{3curvesSIR.png}\n    \\includegraphics[scale=0.8]{4curvesSIR (1).png}\n    \\caption{a) The S(t), I(t), R(t) curves plotted for \\(t=200days\\), representing the number of vulnerable(not yet affected) individuals, infected individuals and recovered individuals, respectively. The first graph has parameters \\(\\beta=9\\times10^6, \\gamma=0.01\\), second one with \\(\\beta=3\\times10^6, \\gamma=0.05\\) and the last one with \\(\\beta=9\\times10^6, \\gamma=0.003\\). The initial condition is \\(S(0)=999, I(0)=1 and R(0)=0\\) b)Same as a) with a death term included \\(\\beta=3\\times10^6, \\gamma=0.005, death2 = 0.01\\). }\n    \\label{fig:Q2}\n\\end{figure}\n\n\\section{Discussion}\nAmong the 3 figures in Fig. 2a, the one the middle best represents the disease spreading model with a reasonable infected curve and a flattened out recovered curve. Unlike the first and the third plot, the decaying tails of $I(t)$ and $R(t)$ expanded beyond the 200 days time interval which is too slow for most common diseases. In Fig. 2b, the death rate exceeds the recovered rate near $t = 180days$. Vulnerable but not infected individuals vanished after $t=75days$, they become either recovered or dead as shown in this new model. \n\n\n\\end{document}", "meta": {"hexsha": "61681678dd460710b9484527feaac9bef733e375", "size": 4266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/main.tex", "max_stars_repo_name": "xinglech/CTA200-assignment", "max_stars_repo_head_hexsha": "c6c764241d9be99836783cda25e30d37d31d4dda", "max_stars_repo_licenses": ["MIT"], "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/main.tex", "max_issues_repo_name": "xinglech/CTA200-assignment", "max_issues_repo_head_hexsha": "c6c764241d9be99836783cda25e30d37d31d4dda", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "xinglech/CTA200-assignment", "max_forks_repo_head_hexsha": "c6c764241d9be99836783cda25e30d37d31d4dda", "max_forks_repo_licenses": ["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.0384615385, "max_line_length": 1020, "alphanum_fraction": 0.7358180966, "num_tokens": 1243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.604052229548767}}
{"text": "%!TEX root = ../thesis.tex\n% ******************************* Thesis Appendix A ****************************\n\\chapter{Tables}\\label{chap:AppendixOne}\n\n\\section{Sequential Probability Ratio Test Tables of A and B as functions of the parameters  \\texorpdfstring{$\\alpha$} \\text{ and} \\texorpdfstring{$\\beta$}.}\n\n\\begin{table}[!ht]\n\\centering\n\\caption{A table of values of A=$\\frac{1 - \\beta}{\\alpha}$, where $\\alpha$ is the significance and $1 - \\beta$  is the power of the Sequential Probability Ratio Test (SPRT)}\n\\begin{tabular}{| c |cccccccccc|} \n\\toprule\n\\diagbox{$\\beta$}{$\\alpha$} & \\makecell{0.05}& \\makecell{0.1} & \\makecell{0.15} & \\makecell{0.2}& \\makecell{0.25}& \\makecell{0.3} & \\makecell{0.35}& \\makecell{0.4}& \\makecell{0.45}& \\makecell{0.5}  \\\\ \n\\midrule\n0.05 & 19.00 & 18.00 & 17.00 & 16.00 & 15.00 & 14.00 & 13.00 & 12.00 & 11.00 & 10.00 \\\\\n0.1 & 9.50 & 9.00 & 8.50 & 8.00 & 7.50 & 7.00 & 6.50 & 6.00 & 5.50 & 5.00 \\\\\n0.15 & 6.33 & 6.00 & 5.67 & 5.33 & 5.00 & 4.67 & 4.33 & 4.00 & 3.67 & 3.33 \\\\\n0.2 & 4.75 & 4.50 & 4.25 & 4.00 & 3.75 & 3.50 & 3.25 & 3.00 & 2.75 & 2.50 \\\\\n0.25 & 3.80 & 3.60 & 3.40 & 3.20 & 3.00 & 2.80 & 2.60 & 2.40 & 2.20 & 2.00 \\\\\n0.3 & 3.17 & 3.00 & 2.83 & 2.67 & 2.50 & 2.33 & 2.17 & 2.00 & 1.83 & 1.67 \\\\\n0.35 & 2.71 & 2.57 & 2.43 & 2.29 & 2.14 & 2.00 & 1.86 & 1.71 & 1.57 & 1.43 \\\\\n0.4 & 2.37 & 2.25 & 2.12 & 2.00 & 1.88 & 1.75 & 1.62 & 1.50 & 1.38 & 1.25 \\\\\n0.45 & 2.11 & 2.00 & 1.89 & 1.78 & 1.67 & 1.56 & 1.44 & 1.33 & 1.22 & 1.11 \\\\\n0.5 & 1.90 & 1.80 & 1.70 & 1.60 & 1.50 & 1.40 & 1.30 & 1.20 & 1.10 & 1.00 \\\\\n\\bottomrule\n\\end{tabular}\n\\label{table:SPRTA}\n\\end{table}\n\n\n\n\\begin{table}[!ht]\n\\centering\n\\caption{A table of values of B=$\\frac{\\beta}{1-\\alpha}$, where $\\alpha$ is the significance and $1 - \\beta$ is the power of the Sequential Probability Ratio Test (SPRT)}\n\\begin{tabular}{| c |cccccccccc|} \n\\toprule\n\\diagbox{$\\beta$}{$\\alpha$} & \\makecell{0.05}& \\makecell{0.1} & \\makecell{0.15} & \\makecell{0.2}& \\makecell{0.25}& \\makecell{0.3} & \\makecell{0.35}& \\makecell{0.4}& \\makecell{0.45}& \\makecell{0.5}  \\\\ \n\\midrule\n0.05 & 0.05 & 0.11 & 0.16 & 0.21 & 0.26 & 0.32 & 0.37 & 0.42 & 0.47 & 0.53 \\\\\n0.1 & 0.06 & 0.11 & 0.17 & 0.22 & 0.28 & 0.33 & 0.39 & 0.44 & 0.50 & 0.56 \\\\\n0.15 & 0.06 & 0.12 & 0.18 & 0.24 & 0.29 & 0.35 & 0.41 & 0.47 & 0.53 & 0.59 \\\\\n0.2 & 0.06 & 0.12 & 0.19 & 0.25 & 0.31 & 0.37 & 0.44 & 0.50 & 0.56 & 0.62 \\\\\n0.25 & 0.07 & 0.13 & 0.20 & 0.27 & 0.33 & 0.40 & 0.47 & 0.53 & 0.60 & 0.67 \\\\\n0.3 & 0.07 & 0.14 & 0.21 & 0.29 & 0.36 & 0.43 & 0.50 & 0.57 & 0.64 & 0.71 \\\\\n0.35 & 0.08 & 0.15 & 0.23 & 0.31 & 0.38 & 0.46 & 0.54 & 0.62 & 0.69 & 0.77 \\\\\n0.4 & 0.08 & 0.17 & 0.25 & 0.33 & 0.42 & 0.50 & 0.58 & 0.67 & 0.75 & 0.83 \\\\\n0.45 & 0.09 & 0.18 & 0.27 & 0.36 & 0.45 & 0.55 & 0.64 & 0.73 & 0.82 & 0.91 \\\\\n0.5 & 0.10 & 0.20 & 0.30 & 0.40 & 0.50 & 0.60 & 0.70 & 0.80 & 0.90 & 1.00 \\\\\n\\bottomrule\n\\end{tabular}\n\\label{table:SPRTB}\n\\end{table}\n", "meta": {"hexsha": "48a376927e1cd5f8225acc6c99e28131e2be9e97", "size": 2903, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix1/appendix1.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": "Appendix1/appendix1.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": "Appendix1/appendix1.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": 55.8269230769, "max_line_length": 201, "alphanum_fraction": 0.5277299346, "num_tokens": 1567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.60405222654825}}
{"text": "\\documentclass{memoir}\n\\usepackage{notestemplate}\n\n%\\logo{./resources/pdf/logo.pdf}\n%\\institute{Rice University}\n%\\faculty{Faculty of Whatever Sciences}\n%\\department{Department of Mathematics}\n%\\title{Class Notes}\n%\\subtitle{Based on MATH xxx}\n%\\author{\\textit{Author}\\\\Gabriel \\textsc{Gress}}\n%\\supervisor{Linus \\textsc{Torvalds}}\n%\\context{Well, I was bored...}\n%\\date{\\today}\n\n\\begin{document}\n\n% \\maketitle\n\n% Notes taken on 01/27/21\n\n\\begin{defn}[Norm of Integral Domain]\n\tLet \\(R\\) be an integral domain. Any function \\(N:R\\to \\Z^{+}\\cup \\left\\{ 0 \\right\\} \\) with \\(N(0)\\) is called a \\textbf{norm} on the integral domain \\(R\\). If \\(N(a) > 0\\) for \\(a\\neq 0\\) then \\(N\\) is a \\textbf{positive norm}\n\\end{defn}\nThis is a pretty loose construction, and an integral domain can have many norms on it.\\\\\n\n\\begin{defn}[Euclidean Function]\n\tAn integral domain \\(R\\) is a \\textbf{Euclidean Domain} if there exists a norm called the \\textbf{Euclidean function} \\(N:R\\setminus\\left\\{ 0 \\right\\} \\to \\N\\) that satisfies \\(\\forall a,b \\in R\\setminus \\left\\{ 0 \\right\\} \\):\n\t\\begin{align*}\n\t\tN(ab) \\geq \\textrm{max}\\left\\{ N(a),N(b) \\right\\}\\\\\n\t\t\\exists q,r \\in R \\text{ such that }a = qb + r \\text{ and }\\left[ r = 0 \\text{ or }N(r)<N(b) \\right] \n\t\\end{align*}\n\tWe call the element \\(q\\) the \\textbf{quotient} and the element \\(r\\) the  \\textbf{remainder}.\n\\end{defn}\nThe existence of a Euclidean function is integral to constructing a Euclidean algorithm to perform division of elements \\(a,b \\in R\\). We can perform successive divisions to get\n\\begin{align*}\n\ta = q_0b + r_0\\\\\n\tb = q_1r_0 + r_1\\\\\n\tr_0 = q_2r_1 + r_2\\\\\n\t\\vdots\\\\\n\tr_{n-1}= q_nr_{n-1}+r_n\\\\\n\tr_{n-1} = q_{n+1}r_n\n\\end{align*}\nwhere \\(r_n\\) is the last nonzero remainder. This \\(r_n\\) always exists as the norms form a decreasing sequence of nonnegative integers. However, these elements are not necessarily unique.\n\n\\begin{prop}\n\tEvery ideal in a Euclidean Domain is principal. That is, if \\(I\\triangleleft R\\) is a nontrivial ideal in \\(R\\), then \\(I = (d)\\) for some nonzero element of \\(I\\) with minimum norm.\n\\end{prop}\nThis also makes it convenient to show an integral domain is not a Euclidean Domain by simply finding a non-principal ideal. Moreover, it motivates the notion of greatest common divisors from \\(\\Z\\) into comumutative rings.\n\n\\begin{defn}[Greatest Common Divisor]\n\tLet \\(R\\) be a commutative ring and let \\(a,b \\in R\\) with \\(b\\neq 0\\). Then \\(a\\) is said to be a \\textbf{multiple} of \\(b\\) if there exists an element \\(x \\in R\\) with \\(a=bx\\). In this case, we say \\(b\\) \\textbf{divides} \\(a\\) (or is a \\textbf{divisor} of \\(a \\)) written \\(b\\mid a\\).\\\\\n\n\tA \\textbf{greatest common divisor} of \\(a,b\\) is a nonzero element \\(d\\) such that\n\t\\begin{align*}\n\t\td \\mid a, \\; d \\mid b \\\\\n\t\td'\\mid a \\; d'\\mid b \\implies d'\\mid d\n\t\\end{align*}\n\tWe will denote a greatest common divisor by \\(\\textrm{gcd}(a,b)\\), or sometimes simply \\((a,b)\\) if it is clear from context.\\\\\n\n\tIf \\(gcd(a,b) = 1_R\\), then we say that \\(a\\) and \\(b\\) are \\textbf{relatively prime}.\n\\end{defn}\nWe can easily extend this to finite sequences of elements \\((a_1,a_2,\\ldots,a_n)\\).\\\\\n\nRecall that in a ring \\(b\\mid a \\iff a \\in (b) \\iff (a) \\subset (b)\\). Hence, we can discuss greatest common factors in terms of ideals. That is, if \\(I = (a,b)\\) is the ideal of \\(R\\) generated by \\(a,b\\), then \\(d = \\textrm{gcd}(a,b)\\) if \\(I\\subset (d)\\) and if \\(I\\subset (d') \\implies (d)\\subset (d')\\). Thus, it is the unique smallest principal ideal containing \\(a\\) and \\(b\\). However, it may not exist in all rings.\n\n\\begin{prop}[Sufficient Conditions for Existence]\n\tIf \\(a,b \\in R\\) are nonzero elements in a commutative ring such that \\(I = (a,b) = (d)\\), then \\(d\\) is the greatest common divisor of \\(a,b\\).\n\\end{prop}\nObviously this is a sufficient and not a necessary condition. But it also clarifies why \\((a,b)\\) is used both for ideals and greatest common divisors. Any integral domain that satisfies the above condition for all ideals of two elements is called a \\textbf{Bezout Domain}.\n\n\\begin{prop}\n\tLet \\(R\\) be an integral domain. If two elements \\(d,d' \\in R\\) generate the same principal ideal, i.e. \\((d) = (d')\\), then \\(d' = ud\\) for some unit \\(u \\in R\\). In particular, this tells us that greatest common divisors are unique up to units.\n\\end{prop}\n\n\\begin{thm}\n\tLet \\(R\\) be a Euclidean Domain and let \\(a,b \\in R\\) be nonzero. Let \\(d = r_n\\) be the last nonzero remainder in the Euclidean Algorithm for \\(a,b\\) described earlier. Then \\(d = \\textrm{gcd}(a,b)\\) and \\((d) = (a,b)\\). That is, \\(d\\) can be written as an \\textbf{\\(R\\)-linear combination} of \\(a,b\\):\n\t\\begin{align*}\n\t\td = ax+by\n\t\\end{align*}\n\tfor some \\(x,y \\in R\\).\n\\end{thm}\nNotice that \\(x,y\\) are not unique in this case. One can show that that if \\(x_0,y_0\\) are solutions to\n\\begin{align*}\n\tax+by=N\n\\end{align*}\nthen any other solutions are of the form\n\\begin{align*}\n\tx = x_0 + m \\frac{b}{(a,b)}\\\\\n\ty = y_0 - m \\frac{a}{(a,b)}\n\\end{align*}\nfor \\(m \\in \\Z\\). This is really strong as it gives a complete solution of the first order Diophantine equation provided we have one solution. Our work here essentially tells us that \\(ax+by = N\\) is solvable in integers \\(x,y\\) if and only if \\(\\textrm{gcd}(a,b)\\mid N\\).\n\n\\begin{proof}\n\t\n\\end{proof}\n\nFinally, we discuss a definition that is useful to determine whether an integral domain is a Euclidean Domain.\n\\begin{defn}[Universal Side Divisor]\n\tLet \\(R\\) be an integral domain, and define \\(\\tilde{R}= R^{\\times }\\cup \\left\\{ 0 \\right\\} \\). We say an element \\(u \\in R-\\tilde{R}\\) is a \\textbf{universal side divisor} if for every \\(x \\in R\\) there is a \\(z \\in \\tilde{R}\\) such that\n\t\\begin{align*}\n\t\tu\\mid x-z\n\t\\end{align*}\n\tThat is, every \\(x\\) can be written\n\t\\begin{align*}\n\t\tx = qu + z\n\t\\end{align*}\n\twhere \\(z\\) is either zero or a unit.\n\\end{defn}\n\n\\begin{prop}\n\tLet \\(R\\) be an integral domain that is not a field. If \\(R\\) is a Euclidean Domain, then there exist universal side divisors in \\(R\\).\n\\end{prop}\nIt is often simpler to show that an integral domain can't have universal side divisors by assuming one exists of minimal norm, finding candidates, then showing they fail to satisfy the necessary properties.\n\n\\begin{hw}\n\tLet \\(F = \\Q(\\sqrt{D} )\\) be a quadratic field with quadratic integer ring \\(\\mathcal{O}\\) and field norm \\(N\\).\n\t\\begin{itemize}\n\t\t\\item Suppose \\(D \\in \\left\\{ -1,-2,-3,-7,-11 \\right\\} \\). Prove that \\(\\mathcal{O}\\) is a Euclidean Domain with respect to \\(N\\). %Hint: Modify the proof for Z[i] in the text. For D = -3,-7, -11, prove that every element of F differs from an element in O by an element whose norm is at most (1+|D|)^2 / (16|D|), which is less than 1 for these values. Plotting the points of O might be helpful\n\t\t\\item Suppose that \\(D \\in \\left\\{ -43,-67,-163 \\right\\} \\). Prove that \\(\\mathcal{O}\\) is not a Euclidean Domain with respect to any norm. %Apply same proof as D = -19 from text\n\t\\end{itemize}\n\tThese numbers are specially chosen because they are the only negative values of \\(D\\) that makes every ideal in \\(\\mathcal{O}\\) principal.\n\\end{hw}\n\n\\subsection{Principal Ideal Domains}\n\\label{sub:principal_ideal_domains}\n\n\\begin{defn}[Princiapl Ideal Domain]\n\tA \\textbf{Principal Ideal Domain} is an integral domain in which every ideal is principal.\n\\end{defn}\nWe have already shown that every Euclidean Domain is a Principal Ideal Domain. The converse does not hold. The biggest difference from a practicality angle is that while PIDs have gcds, there is no algorithm to compute them.\n\n\\begin{prop}\n\tLet \\(R\\) be a Principal Ideal Domain and let \\(a,b \\in R\\) be nonzero. Let \\(d\\) be a generator for the principal ideal generated by \\(a,b\\). Then \\(d = \\textrm{gcd}(a,b)\\) and can be written as an \\(R\\)-linear combination\n\t\\begin{align*}\n\t\td = ax+by\n\t\\end{align*}\n\tfor \\(x,y \\in R\\). Finally, \\(d\\) is unique up to multiplication by a unit.\n\\end{prop}\nRecall that maximal ideals are always prime ideals but the converse is not true in general. Fortunately, PIDs have enough structure so this holds.\n\n\\begin{prop}\n\tEvery nonzero prime ideal in a Principal Ideal Domain is a maximal ideal.\n\\end{prop}\n\\begin{proof}% Try yourself\n\t\n\\end{proof}\n\n\\begin{cor}\n\tIf \\(R\\) is any commutative ring such that \\(R[x]\\) is a PID, then \\(R\\) is necessarily a field.\n\\end{cor}\n\\begin{proof}\n\t\n\\end{proof}\n\nWe construct some definitions that help us distinguish PIDs and EDs.\n\n\\begin{defn}[Dedeking-Hasse Norm]\n\tDefine \\(N\\) to be a \\textbf{Dedekind-Hasse norm} if \\(N\\) is a positive norm and for every \\(a,b \\in R\\) nonzero either \\(a \\in (b)\\) or there exists \\(s,t \\in R\\) with \\(0 < N(sa-tb) < N(b)\\) (that is, a nonzero element in the ideal \\((a,b)\\) with norm smaller than \\(b\\)).\n\\end{defn}\nThis is a weakening of the Euclidean condition. \\(R\\) is an ED with respect to a positive norm \\(N\\) if it is always possble to satisfy the above condition with \\(s=1\\).\n\n\\begin{prop}\n\tThe integral domain \\(R\\) is a PID if and only if \\(R\\) has a Dedeking-Hasse norm.\n\\end{prop}\n\n\\begin{exmp}\n\t%Show that in Z[1+sqrt(-19) / 2] N()=a^2+ab+5b%2 is a Dedekind-Hasse norm\n\\end{exmp}\n\n\\subsection{Unique Factorization Domain}\n\\label{sub:unique_factorization_domain}\n\nUnique Factorization Domains capture the idea that some rings admit a proper factorization on elements.\n\n\\begin{defn}[Reducibility and Primes]\n\tLet \\(R\\) be an integral domain\n\t\\begin{itemize}\n\t\t\\item Suppose \\(r \\in R\\) is nonzero and not a unit. Then \\(r\\) is called \\textbf{irreducible in \\(R\\)} if for all \\(a,b \\in R\\), \\(r = ab\\) implies that either \\(a\\) or \\(b\\) is a unit. Otherwise, we say \\(r\\) is \\textbf{reducible}.\n\t\t\\item Let \\(p \\in R\\) be nonzero. We say it is \\textbf{prime in \\(R\\)} if the ideal \\((p)\\) is a prime ideal. An equivalent statement is that \\(p\\) is not a unit and if \\(p\\mid ab\\), then \\(p\\mid a\\) or \\(p\\mid b\\).\n\t\t\\item If \\(a=ub\\) for \\(a,b \\in R\\) and \\(u \\in R\\) a unit, then we say \\(a\\) and \\(b\\) are \\textbf{associates}.\n\t\\end{itemize}\n\\end{defn}\n\n\\begin{prop}\n\tIn an integral domain, a prime element is always irreducible.\n\\end{prop}\nThe converse does not hold in general. However, in a PID, the converse does hold.\n\n\\begin{proof}% Try yourself, also try showing that in a PID it does hold\n\t\n\\end{proof}\nThis is also a useful tool to show a ring is not a PID.\n\n\\begin{defn}[Proper Factorization]\n\tLet \\(a \\in R\\) be a nonzero nonunit. A \\textbf{proper factorization} of \\(a\\) is a finite product \\(a=p_1p_2\\ldots p_n\\), where \\(p_i\\) are not units of \\(R\\). If this exists, we say \\(\\left\\{ p_i \\right\\} \\) are \\textbf{proper factors} of \\(a\\).\n\\end{defn}\nOf course, an irreducible element has no proper factorizations.\n\n\\begin{defn}[Unique Factorization Domain]\n\tAn integral domain \\(R\\) is a \\textbf{unique factorization domain} if every nonzero, non-unit element has a proper factorization\n\t\\begin{align*}\n\t\tr = p_1p_2\\ldots p_n\n\t\\end{align*}\n\twhere \\(\\left\\{ p_i \\right\\} \\) are irreducible elements and unique up to associates and reordering.\n\\end{defn}\nIt turns out that primes are equivalent to irreducibles in a UFD as well.\n\n\\begin{prop}\n\tIn a Unique Factorization Domain, a nonzero element is a prime if and only if it is an irreducible.\n\\end{prop}\nWe will also see that UFDs admit a greatest common divisor via its factorization\n\n\\begin{prop}\n\tLet \\(a,b \\in R\\) be nonzero elements of a UFD \\(R\\) and suppose\n\t\\begin{align*}\n\t\ta = up_1^{e_1}p_2^{e_2}\\ldots p_n^{e_n}\\\\\n\t\tb= v p_1^{f_1}p_2^{f_2}\\ldots p_n^{f_n}\n\t\\end{align*}\n\tare prime factorizations with \\(u,v\\) units, primes \\(p_1,p_2,\\ldots,p_n\\) distinct, and exponents \\(e_i,f_i \\geq 0\\). Then the element\n\t\\begin{align*}\n\t\td = p_1^{\\textrm{min}(e_1,f_1)}p_2^{\\textrm{min}(e_2,f_2)}\\ldots p_n^{\\textrm{min}(e_n,f_n)}\n\t\\end{align*}\n\tis a greatest common divisor of \\(a\\) and \\(b\\).\n\\end{prop}\n\n\\begin{hw}\n\tLet \\(R\\) be a UFD.\n\t\\begin{enumerate}[(a).]\n\t\t\\item Let \\(b\\) and \\(a_1,\\ldots,a_s\\) be nonzero elements of \\(R\\). For \\(d \\in R\\), show that\n\t\t\t\\begin{align*}\n\t\t\t\tbd = gcd(ba_1,\\ldots,ba_s) \\iff d = gcd(a_1,\\ldots,a_s)\n\t\t\t\\end{align*}\n\t\t\\item Let \\(f(x) \\in R[x]\\) where \\(f(x) = bf_1(x)\\) for \\(f_1(x)\\) \\textbf{primitive} (i.e. \\(gcd(\\text{coefficients of }f_1(x)) = 1_R\\) ). Show that\n\t\t\t\\begin{align*}\n\t\t\t\tb = gcd(\\left\\{ \\text{coefficients of }f(x) \\right\\} ).\n\t\t\t\\end{align*}\n\t\\end{enumerate}\n\\end{hw}\n\nThis leads us to the full description of the structure of these domains.\n\n\\begin{thm}\n\tEvery Principal Ideal Domain is a Unique Factorization Domain. Hence, every Euclidean Domain is a Unique Factorization Domain.\n\\end{thm}\n\\begin{proof}\n\t\n\\end{proof}\n\nThis forms a strict classification hierarchy by\n\\begin{align*}\n\t\\textbf{Euclidean Domains} \\subset \\textbf{Principal Ideal Domains} \\subset \\textbf{Unique Factorization Domains} \\subset \\textbf{Integral Domains} \\subset \\textbf{commutative rings}\n\\end{align*}\n\n\\begin{cor}\n\tThe integers \\(\\Z\\) are a UFD.\n\\end{cor}\n\n\\begin{cor}\n\tLet \\(R\\) be a PID. Then there exists a multiplicative Dedekind-Hausse norm on \\(R\\).\n\\end{cor}\n\n\\end{document}\n", "meta": {"hexsha": "6580d202d71bf1f5de55e0a00bde67a65b7d17ac", "size": 13021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture2 - ED_UFD_PID.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": "Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture2 - ED_UFD_PID.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": "Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture2 - ED_UFD_PID.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": 49.5095057034, "max_line_length": 424, "alphanum_fraction": 0.6845864373, "num_tokens": 4218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850932, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.6040508350121915}}
{"text": "\\providecommand{\\main}{../..}\n\\documentclass[\\main/thesis.tex]{subfiles}\n\\begin{document}\n\n\\section{Digit: the basic building block}\\label{digit}\n\nAs the fundamental building block of numerals, we will devise a suitable\nrepresentation for digits in this section.\n\n\\subsection{Fin}\n\nTo represent a digit, we use a datatype conventionally called \\textit{Fin}\nwhich can be indexed to have an exact number of inhabitants.\n\n\\begin{lstlisting}\ndata Fin : ℕ → Set where\n    zero : {n : ℕ} → Fin (suc n)\n    suc  : {n : ℕ} (i : Fin n) → Fin (suc n)\n\\end{lstlisting}\n\nThe definition of {\\lstinline|Fin|} looks the same as {\\lstinline|ℕ|} on the term\nlevel, but different on the type level. The index of a {\\lstinline|Fin|} increases\nwith every {\\lstinline|suc|}, and there can only be at most {\\lstinline|n|} of\nthem before reaching {\\lstinline|Fin (suc n)|}. In other words, {\\lstinline|Fin n|}\nhas exactly \\textit{n} inhabitants.\n\n\\subsection{Definition of \\lstinline|Digit|}\n\n{\\lstinline|Digit|} is simply just a synonym for {\\lstinline|Fin|}, indexed by\nthe number of digits {\\lstinline|d|} of a system.\nSince the same digit may represent different values in different numeral systems,\nit is essential to make the context clear.\n\n\\begin{lstlisting}\nDigit : ℕ → Set\nDigit d = Fin d\n\\end{lstlisting}\n\nOrdinary binary digits for example can thus be represented as:\n\n\\begin{lstlisting}\nBinary : Set\nBinary = Digit 2\n\n零 : Binary\n零 = zero\n\n一 : Binary\n一 = suc zero\n\\end{lstlisting}\n\n\\subsection{Digit Assignment}\n\n\\begin{center}\n    \\begin{adjustbox}{max width=\\textwidth}\n        \\begin{tikzpicture}\n            % the frame\n            \\path[clip] (-1, -1) rectangle (11, 2);\n            % the spine\n            \\draw[ultra thick] (0,0) -- (1,0);\n            \\draw[ultra thick] (9,0) -- (10,0);\n            % the body\n\n            \\foreach \\i in {1,...,8} {\n                \\draw[ultra thick, fill=white] ({\\i+0.05}, -0.2) rectangle ({\\i+0.95}, +0.2);\n            };\n\n            % ticks\n            \\draw (0,0.2) -- (0,-0.2) node[below] {$0$};\n\n            % labels\n            \\draw[->, ultra thick] (1.5,1) -- (1.5,0.5)\n                node at (1.5, 1.3) {$o$};\n            \\draw[->, ultra thick] (8.5,1) -- (8.5,0.5)\n                node at (8.5, 1.3) {$o+d$};\n            \\node at (5, -0.7) {{\\lstinline|ℕ|}};\n        \\end{tikzpicture}\n    \\end{adjustbox}\n\\end{center}\n\nDigits are assigned to {\\lstinline|ℕ|} together with the offset {\\lstinline|o|}\nof a system, ranging from $ o $ to $ d + o $.\n\n\\begin{lstlisting}\nDigit-toℕ : ∀ {d} → Digit d → ℕ → ℕ\nDigit-toℕ x o = toℕ x + o\n\\end{lstlisting}\n\\footnote{\n    {\\lstinline|toℕ : ∀ {n} → Fin n → ℕ|}\n    \\newline\\hspace*{4em} converts from {\\lstinline|Fin n|} to {\\lstinline|ℕ|}.\n}\n\nHowever, not all natural numbers can be converted to digits.\nThe value has to be in a certain range, between $ o $ and $ d + o $.\nValues less than $ o $ are increased to $ o $.\nValues greater than $ d + o $ are prohibited by the supplied upper-bound.\n\n\\begin{lstlisting}\nDigit-fromℕ : ∀ {d}\n    → (n o : ℕ)\n    → (upper-bound : d + o ≥ n)\n    → Digit (suc d)\nDigit-fromℕ {d} n o upper-bound with n ∸ o ≤? d\nDigit-fromℕ {d} n o upper-bound | yes p = fromℕ≤ (s≤s p)\nDigit-fromℕ {d} n o upper-bound | no ¬p = contradiction p ¬p\n    where   p : n ∸ o ≤ d\n            p = start\n                    n ∸ o\n                ≤⟨ ∸n-mono o upper-bound ⟩\n                    (d + o) ∸ o\n                ≈⟨ m+n∸n≡m d o ⟩\n                    d\n                □\n\\end{lstlisting}\n\\footnote{\n    {\\lstinline|fromℕ≤ : ∀ {m n} → m < n → Fin n|}\n    \\newline\\hspace*{4em} converts from {\\lstinline|ℕ|} to {\\lstinline|Fin n|} given the number is small enough.\n}\n\n\n\\subsubsection{Properties of \\lstinline|Digit|}\n\n\\begin{center}\n    \\begin{tikzpicture}\n        \\matrix (m) [matrix of nodes,row sep=6em,column sep=8em,minimum width=4em]\n            {\n                {\\lstinline|ℕ|} & {\\lstinline|Digit d|} \\\\\n            };\n        \\path[-stealth]\n            ($(m-1-1.east)+(0,+0.1)$)\n                edge node [above] {{\\lstinline|Digit-fromℕ|}}\n                ($(m-1-2.west)+(0,+0.1)$)\n            ($(m-1-2.west)+(0,-0.1)$)\n                edge node [below] {{\\lstinline|Digit-toℕ|}}\n                ($(m-1-1.east)+(0,-0.1)$)\n            ;\n    \\end{tikzpicture}\n\\end{center}\n\n{\\lstinline|Digit-fromℕ-toℕ|} states that the value of a natural number should\nremain the same, after converting back and forth between {\\lstinline|Digit|} and\n{\\lstinline|ℕ|}.\n\n\\begin{lstlisting}\nDigit-fromℕ-toℕ : ∀ {d o}\n    → (n : ℕ)\n    → (lower-bound :     o ≤ n)\n    → (upper-bound : d + o ≥ n)\n    → Digit-toℕ (Digit-fromℕ {d} n o upper-bound) o ≡ n\nDigit-fromℕ-toℕ {d} {o} n lb ub with n ∸ o ≤? d\nDigit-fromℕ-toℕ {d} {o} n lb ub | yes q =\n    begin\n        toℕ (fromℕ≤ (s≤s q)) + o\n    ≡⟨ cong (λ x → x + o) (toℕ-fromℕ≤ (s≤s q)) ⟩\n        n ∸ o + o\n    ≡⟨ m∸n+n≡m lb ⟩\n        n\n    ∎\nDigit-fromℕ-toℕ {d} {o} n lb ub | no ¬q = contradiction q ¬q\n    where   q : n ∸ o ≤ d\n            q = +n-mono-inverse o (\n                start\n                    n ∸ o + o\n                ≈⟨ m∸n+n≡m lb ⟩\n                    n\n                ≤⟨ ub ⟩\n                    d + o\n                □)\n\\end{lstlisting}\n\\footnote{\n    {\\lstinline|toℕ-fromℕ≤ : ∀ {m n} (m<n : m < n) → toℕ (fromℕ≤ m<n) ≡ m|}\n    \\newline\\hspace*{4em} states that a number should remain the same after converting back and forth.\n}\n\nDigits have a upper-bound and a lower-bound after evaluated to \\lstinline|ℕ|.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\nDigit-upper-bound : ∀ {d} → (o : ℕ) → (x : Digit d) → Digit-toℕ x o < d + o\nDigit-upper-bound {d} o x = +n-mono o (bounded x)\n\nDigit-lower-bound : ∀ {d} → (o : ℕ) → (x : Digit d) → Digit-toℕ x o ≥ o\nDigit-lower-bound {d} o x = m≤n+m o (toℕ x)\n\\end{lstlisting}\n\\footnote{\n    {\\lstinline|bounded : ∀ {n} (i : Fin n) → toℕ i < n|}\n    \\newline\\hspace*{4em} a property about the upper-bound of a {\\lstinline|Fin n|}.\n}\n\n\\subsection{Functions on \\lstinline|Digit|}\n\n\\subsubsection{Increment}\n\nTo increment a digit, the digit must not be \\textit{the greatest}.\n\n\\begin{lstlisting}\ndigit+1 : ∀ {d}\n    → (x : Digit d)\n    → (¬greatest : ¬ (Greatest x))\n    → Digit d\ndigit+1 x ¬greatest =\n    fromℕ≤ {suc (toℕ x)} (≤∧≢⇒< (bounded x) ¬greatest)\n\\end{lstlisting}\n%\nwhere {\\lstinline|≤∧≢⇒< (bounded x) ¬greatest : suc (toℕ x) < d|}.\n\n\\begin{center}\n    \\begin{tikzpicture}\n        \\matrix (m) [matrix of nodes,row sep=6em,column sep=8em,minimum width=4em]\n            {\n                {\\lstinline|Digit d|} & {\\lstinline|Digit d|} \\\\\n                {\\lstinline|ℕ|} & {\\lstinline|ℕ|} \\\\\n            };\n      \\path[-stealth]\n            (m-1-1)\n                edge node [left] {{\\lstinline|Digit-toℕ|}} (m-2-1)\n                edge node [above] {{\\lstinline|digit+1|}} (m-1-2)\n            (m-2-1.east|-m-2-2)\n                edge node [below] {{\\lstinline|suc|}} (m-2-2)\n            (m-1-2)\n                edge node [right] {{\\lstinline|Digit-toℕ|}} (m-2-2);\n                % edge [dashed,-] (m-2-1);\n    \\end{tikzpicture}\n\\end{center}\n\nA digit taking these two routes should result in the same {{\\lstinline|ℕ|}}.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\ndigit+1-toℕ : ∀ {d o}\n    → (x : Digit d)\n    → (¬greatest : ¬ (Greatest x))\n    → Digit-toℕ (digit+1 x ¬greatest) o ≡ suc (Digit-toℕ x o)\ndigit+1-toℕ {d} {o} x ¬greatest =\n    begin\n        Digit-toℕ (digit+1 x ¬greatest) o\n    ≡⟨ cong (λ w → w + o) (toℕ-fromℕ≤ (≤∧≢⇒< (bounded x) ¬greatest)) ⟩\n        suc (Digit-toℕ x o)\n    ∎\n\\end{lstlisting}\n\n\\subsubsection{Increase and then Subtract}\n\nIncreases a digit and then subtract it by $ n $.\nThis function is useful for implementing \\textit{carrying}.\nWhen the digit to increase is already the greatest,\nit has to be subtracted from an amount (usually the base) after the increment.\n\n\\begin{lstlisting}\ndigit+1-n : ∀ {d}\n    → (x : Digit d)\n    → Greatest x\n    → (n : ℕ)\n    → n > 0\n    → Digit d\ndigit+1-n x greatest n n>0 =\n    fromℕ≤ (digit+1-n-lemma x greatest n n>0)\n\\end{lstlisting}\n\n\\begin{center}\n    \\begin{tikzpicture}\n        \\matrix (m) [matrix of nodes,row sep=4em,column sep=6em,minimum width=2em]\n            {\n                {\\lstinline|Digit d|} & & {\\lstinline|Digit d|} \\\\\n                {\\lstinline|ℕ|} & {\\lstinline|ℕ|} & {\\lstinline|ℕ|} \\\\\n            };\n      \\path[-stealth]\n            (m-1-1)\n                edge node [left] {{\\lstinline|Digit-toℕ|}} (m-2-1)\n                edge node [above] {{\\lstinline|digit+1-n|}} (m-1-3)\n            (m-2-1)\n                edge node [below] {{\\lstinline|suc|}} (m-2-2)\n            (m-2-2)\n                edge node [below] {{\\lstinline|∸ n|}} (m-2-3)\n            (m-1-3)\n                edge node [right] {{\\lstinline|Digit-toℕ|}} (m-2-3);\n    \\end{tikzpicture}\n\\end{center}\n\nA digit taking these two routes should result in the same {{\\lstinline|ℕ|}}.\n\n\\begin{lstlisting}[basicstyle=\\ttfamily\\scriptsize]\ndigit+1-n-toℕ : ∀ {d o}\n    → (x : Digit d)\n    → (greatest : Greatest x)\n    → (n : ℕ)\n    → (n>0 : n > 0)\n    → n ≤ d\n    → Digit-toℕ (digit+1-n x greatest n n>0) o ≡ suc (Digit-toℕ x o) ∸ n\ndigit+1-n-toℕ {zero}  {o} () greatest n n>0 n≤d\ndigit+1-n-toℕ {suc d} {o} x greatest n n>0  n≤d =\n    begin\n        toℕ (digit+1-n x greatest n n>0) + o\n    ≡⟨ cong (λ w → w + o) (toℕ-fromℕ≤ (digit+1-n-lemma x greatest n n>0)) ⟩\n        suc (toℕ x) ∸ n + o\n    ≡⟨ +-comm (suc (toℕ x) ∸ n) o ⟩\n        o + (suc (toℕ x) ∸ n)\n    ≡⟨ sym (+-∸-assoc o {suc (toℕ x)} {n} (\n        start\n            n\n        ≤⟨ n≤d ⟩\n            suc d\n        ≈⟨ sym greatest ⟩\n            suc (toℕ x)\n        □)\n    ⟩\n        (o + suc (toℕ x)) ∸ n\n    ≡⟨ cong (λ w → w ∸ n) (+-comm o (suc (toℕ x))) ⟩\n        suc (toℕ x) + o ∸ n\n    ∎)\n\\end{lstlisting}\n\n\n\\subsection{Special Digits}\n\n\\subsubsection{The Greatest Digit}\n\nThe greatest digit of a system is constructed by converting the index\n{\\lstinline|d|} to {\\lstinline|Fin|}.\n\n\\begin{lstlisting}\ngreatest-digit : ∀ d → Digit (suc d)\ngreatest-digit d = fromℕ d\n\\end{lstlisting}\n\\footnote{\n    {\\lstinline|fromℕ : ∀ {n} → Fin n → ℕ|}\n    \\newline\\hspace*{4em} construct the greatest possible {\\lstinline|Fin n|}\n    when given an index {\\lstinline|n|}.\n}\n\n\\paragraph{predicates}\n\nWe can see whether a digit is the greatest by converting it to {\\lstinline|ℕ|}.\nThis predicate also comes with a decidable version.\n\n\\begin{lstlisting}\nGreatest : ∀ {d} (x : Digit d) → Set\nGreatest {d} x = suc (toℕ x) ≡ d\n\nGreatest? : ∀ {d} (x : Digit d) → Dec (Greatest x)\nGreatest? {d} x = suc (toℕ x) ≟ d\n\\end{lstlisting}\n\n\\paragraph{properties}\n\nConverting from the greatest digit to {\\lstinline|ℕ|} should result in\n{\\lstinline|d + o|}.\n\n\\begin{lstlisting}\ngreatest-digit-toℕ : ∀ {d o}\n    → (x : Digit (suc d))\n    → Greatest x\n    → Digit-toℕ x o ≡ d + o\ngreatest-digit-toℕ {d} {o} x greatest = cancel-suc (\n    begin\n        suc (Digit-toℕ x o)\n    ≡⟨ refl ⟩\n        suc (toℕ x) + o\n    ≡⟨ cong (λ w → w + o) greatest ⟩\n        suc d + o\n    ∎)\n\\end{lstlisting}\n\nA digit is the greatest if and only if it is greater than or equal to all other\ndigits. This proposition is proven by induction on both of the compared digits.\n\n\\begin{lstlisting}\ngreatest-of-all : ∀ {d} (o : ℕ) → (x y : Digit d)\n    → Greatest x\n    → Digit-toℕ x o ≥ Digit-toℕ y o\ngreatest-of-all o zero    zero     refl     = ≤-refl\ngreatest-of-all o zero    (suc ()) refl\ngreatest-of-all o (suc x) zero     greatest\n    = +n-mono o {zero} {suc (toℕ x)} z≤n\ngreatest-of-all o (suc x) (suc y)  greatest\n    = s≤s (greatest-of-all o x y (cancel-suc greatest))\n\\end{lstlisting}\n\n\\subsubsection{The Carry}\n\nA carry is a digit that is transferred to a more significant digit to compensate\nthe ``loss'' of the original digit.\n\nThe carry is defined as the greater of these two values:\n\n\\begin{itemize}\n    \\item the least digit of a system\n    \\item the digit that is assigned to $ 1 $\n\\end{itemize}\n\nWe define the carry as the greater number of $ 1 $ and $ o $.\nIn case that the least digit (which is determined by $o$) is assigned to $ 0 $,\nrendering the carry useless.\n\n\\begin{lstlisting}\ncarry : ℕ → ℕ\ncarry o = 1 ⊔ o\n\\end{lstlisting}\n\nThe corresponding numeral of the carry is constructed by converting\n{\\lstinline|carry o|} to {\\lstinline|Digit|}.\n\n\\begin{lstlisting}\ncarry-digit : ∀ d o → 2 ≤ suc d + o → Digit (suc d)\ncarry-digit d o proper =\n    Digit-fromℕ\n        (carry o)\n        o\n        (carry-upper-bound {d} proper)\n\\end{lstlisting}\n\n\\paragraph{properties}\n\nThe value of the carry should remain the same after convertions.\n\n\\begin{lstlisting}\ncarry-digit-toℕ : ∀ d o\n    → (proper : 2 ≤ suc (d + o))\n    → Digit-toℕ (carry-digit d o proper) o ≡ carry o\ncarry-digit-toℕ d o proper\n    = Digit-fromℕ-toℕ\n        (carry o)\n        (m≤n⊔m o 1)\n        (carry-upper-bound {d} proper)\n\\end{lstlisting}\n\nThe carry also have an upper-bound and a lower-bound,\nsimilar to that of {\\lstinline|Digit|}.\n\n\\begin{lstlisting}\ncarry-lower-bound : ∀ {o} → carry o ≥ o\ncarry-lower-bound {o} = m≤n⊔m o 1\n\ncarry-upper-bound : ∀ {d o} → 2 ≤ suc d + o → carry o ≤ d + o\ncarry-upper-bound {d} {zero}  proper = ≤-pred proper\ncarry-upper-bound {d} {suc o} proper = n≤m+n d (suc o)\n\\end{lstlisting}\n\n\\end{document}\n", "meta": {"hexsha": "8f58e25e188989f16118c9d528086629058d33d8", "size": 13177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/tex/constructions/digit.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/digit.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/digit.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": 30.0844748858, "max_line_length": 112, "alphanum_fraction": 0.5733474994, "num_tokens": 4600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6040508349201368}}
{"text": "\\section{Function extensionality}\n\\label{chap:funext}\n\n\\subsection{Equivalent forms of function extensionality}\n\\begin{defn}\n  The \\define{axiom of function extensionality} asserts that for any type family $B$ over $A$, and any two dependent functions $f,g:\\prd{x:A}B(x)$, the canonical map\n  \\begin{equation*}\n    \\mathsf{htpy\\usc{}eq}:(f=g)\\to (f\\htpy g)\n  \\end{equation*}\n  is an equivalence.\n\\end{defn}\n\nIn other words, the axiom of function extensionality asserts that any an identification of any two dependent functions is equivalent to an identification of all their values. By \\cref{thm:id_fundamental} 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 axiom of function extensionality is equivalent to any of the following statements:\\index{function extensionality}\n\\begin{enumerate}\n\\item\n  The principle of \\define{homotopy induction}\\index{homotopy induction}:\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,\\mathsf{htpy\\usc{}refl}_f)\n\\end{equation*}\ngiven by $s\\mapsto s(f,\\mathsf{htpy\\usc{}refl}_f)$ has a section.\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 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 (i) and (ii) 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\nTo prove function extensionality from weak function extensionality, observe that it suffices by \\cref{thm:id_fundamental} to show that\n\\begin{equation*}\n\\sm{g:\\prd{x:A}B(x)}f\\htpy g\n\\end{equation*}\nis contractible.\n\nSince the type $\\sm{b:B(x)}f(x)=b$ is contractible for each $x:X$, it follows by our assumption of weak function extensionality that the type $\\prd{x:A}\\sm{b:B(x)}f(x)=b$ is contractible. By \\cref{ex:contr_retr} it therefore suffices to show that\n\\begin{equation*}\n\\sm{g:\\prd{x:A}B(x)}f\\htpy g\n\\end{equation*}\nis a retract of the type $\\prd{x:A}\\sm{b:B(x)}f(x)=b$. We have the functions\n\\begin{align*}\ni & \\defeq \\ind{\\Sigma}(\\lam{g}{H}{x}\\pairr{g(x),H(x)}) \\\\\nr & \\defeq \\lam{p}\\pairr{\\lam{x}\\proj 1(p(x)),\\lam{x}\\proj 2(p(x))}.\n\\end{align*}\nIt remains to show that $r\\circ i\\htpy \\idfunc$. This homotopy is constructed by $\\Sigma$-induction. Let $g:\\prd{x:A}B(x)$ and let $H:f\\htpy g$. Then we have\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*}\nIn other words, the homotopy $r\\circ i\\htpy \\idfunc$ is given by $\\ind{\\Sigma}(\\lam{g}{H}\\refl{(\\pairr{g,H})})$. \n\\end{proof}\n\nFrom now on we will assume that the function extensionality axiom holds.\n\n\\begin{defn}\n  Consider a type family $B$ over $A$ and let $f,g:\\prd{x:A}B(x)$. We define\n  \\begin{equation*}\n    \\mathsf{eq\\usc{}htpy}: (f\\htpy g) \\to (f = g)\n  \\end{equation*}\n  to be the inverse of $\\mathsf{htpy\\usc{}eq}$. \n\\end{defn}\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}\nAssume function extensionality. Then for any type family $B$ over $A$ one has\\index{truncated}\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, 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}\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 \\define{type theoretic principle of choice}\\index{type theoretic choice|textbf} asserts that \\emph{$\\Pi$ distributes over $\\Sigma$}. More precisely, it asserts that the canonical map\n\\begin{equation*}\n  \\mathsf{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 $\\mathsf{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 $\\mathsf{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  \\mathsf{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\n  \\begin{equation*}\n    \\mathsf{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    \\mathsf{choice}\\circ\\mathsf{choice}^{-1}\\htpy\\idfunc,\\qquad\\text{and}\\qquad\n    \\mathsf{choice}^{-1}\\circ\\mathsf{choice}\\htpy\\idfunc.\n  \\end{equation*}\n  For the first homotopy it suffices to construct an identification\n  \\begin{equation*}\n    \\mathsf{choice}(\\mathsf{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    \\mathsf{choice}(\\mathsf{choice}^{-1}(f,g))\n    & \\jdeq \\mathsf{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)}:\\mathsf{choice}(\\mathsf{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    \\mathsf{choice}^{-1}(\\mathsf{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    \\mathsf{choice}^{-1}(\\mathsf{choice}(h))\n    & \\jdeq \\mathsf{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    \\mathsf{eq\\usc{}pair}(\\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}\\mathsf{eq\\usc{}htpy}(\\lam{x}\\mathsf{eq\\usc{}pair}(\\refl{\\proj 1(h(x))},\\refl{\\proj 2(h(x))}):\\mathsf{choice}^{-1}\\circ\\mathsf{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\\subsection{Universal properties}\nThe function extensionality principle allows us to prove \\emph{universal properties}: characterizations of all maps out of (or into) a given type. 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}\nLet $B$ be a type family over $A$, and let $X$ be a type. Then the map\n\\begin{equation*}\n\\mathsf{ev\\usc{}pair}:\\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}:\\mathsf{ev\\usc{}pair}\\circ\\ind{\\Sigma}\\htpy\\idfunc\n\\end{equation*}\n\nTo show that $\\ind{\\Sigma}\\circ\\mathsf{ev\\usc{}pair}\\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}\nLet $A$, $B$, and $X$ be types. Then the map\n\\begin{equation*}\n\\mathsf{ev\\usc{}pair}: (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}: 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}\nLet $B$ be a type family over $A$, and let $a:A$. Then the map\n\\begin{equation*}\n\\mathsf{ev\\usc{}refl}:\\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 $\\mathsf{ev\\usc{}refl}\\circ\\varphi\\htpy \\idfunc$.\n\nTo see that $\\varphi\\circ \\mathsf{ev\\usc{}refl}\\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 \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}\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. 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}\\mathsf{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\\mathsf{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 a half-adjoint equivalence. Since we have $K(x):G(f(x))=\\ap{f}{H(x)}$ it suffices to show that\n\\begin{equation*}\n\\mathsf{tr}_P(\\ap{f}{H(x)},hgf(x))=h(x).\n\\end{equation*}\nA simple path-induction argument yields that\n\\begin{equation*}\n\\mathsf{tr}_P(\\ap{f}{p})\\htpy \\mathsf{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\\mathsf{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\\mathsf{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\\item Show that the functions\n\\begin{align*}\n\\mathsf{htpy\\usc{}inv} & : (f \\htpy g) \\to (g \\htpy f) \\\\\n\\mathsf{htpy\\usc{}concat}(H) & : (g \\htpy h) \\to (f \\htpy h) \\\\\n\\mathsf{htpy\\usc{}concat}'(K) & : (f \\htpy g) \\to (f \\htpy h)\n\\end{align*}\nare equivalences for every $f,g,h : \\prd{x:A}B(x)$. Here, $\\mathsf{htpy\\usc{}concat}'(K)$ is the function defined by $H\\mapsto \\ct{H}{K}$.\n\\item \\label{ex:isprop_istrunc}\n\\begin{subexenum}\n\\item Show that for any type $A$ the type $\\iscontr(A)$ is a proposition. %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.\n\\end{subexenum}\n\\item \\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!post-composition|textit}\n\\item The map $f\\circ\\blank : X^A\\to Y^A$ is an equivalence for every type $A$.\n\\end{enumerate}\n\\item \\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.\n\\item Use \\cref{ex:prop_equiv,ex:isprop_istrunc} to show that $\\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\\item \\label{ex:prop_equiv}\n\\begin{subexenum}\n\\item \\label{ex:equiv-bi-implication}Let $P$ and $Q$ be propositions. Show that\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\\item Show that $\\mathsf{path\\usc{}split}(f)$ and $\\mathsf{half\\usc{}adj}(f)$ are propositions for any map $f:A\\to B$. Conclude that we have equivalences\n  \\begin{equation*}\n    \\isequiv(f) \\eqvsym \\mathsf{path\\usc{}split}(f) \\eqvsym \\mathsf{half\\usc{}adj}(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,\"\\mathsf{tr}_B(p)\"] & C(a) \\arrow[d,\"\\mathsf{tr}_C(p)\"] \\\\\n%B(a') \\arrow[r,swap,\"g\"] & C(a')\n%\\end{tikzcd}\n%\\end{equation*}\n%commutes for every homotopy $H:\\mathsf{tr}_{B(x)\\to C(x)}(p,f)\\htpy g$. In other words, construct a function of type\n%\\begin{equation*} \n%\\Big(\\mathsf{tr}_{B(x)\\to C(x)}(p,f)\\htpy g\\Big)\\to \\Big(\\mathsf{tr}_C(p)\\circ f\\htpy g\\circ \\mathsf{tr}_B(p)\\Big)\n%\\end{equation*}\n%\\item Show that this map is an equivalence.\n%\\end{subexenum}\n\\item \\label{ex:idfunc_autohtpy}Construct for any type $A$ an equivalence\n\\begin{equation*}\n\\eqv{\\mathsf{is\\usc{}invertible}(\\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 $\\mathsf{is\\usc{}invertible}(\\idfunc[A])\\not\\eqvsym\\isequiv(\\idfunc[A])$.\n\\item \n\\begin{subexenum}\n\\item Show that the type\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\\item Consider two types $A$ and $B$.\n\\begin{subexenum}\n\\item Show that the map\n\\begin{equation*}\n  \\mathsf{ev\\usc{}inl\\usc{}inr}: \\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 $\\mathsf{ind\\usc{}coprod}(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\\item \n\\begin{subexenum}\n\\item Show that the map\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 $\\mathsf{ind\\usc{}unit}(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\\item \\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 $\\mathsf{sec}(g)$ is a retract of $\\mathsf{sec}(f)$.\n\\item Show that if $g$ has a retraction, then $\\mathsf{retr}(h)$ is a retract of $\\mathsf{sec}(f)$.\n\\end{subexenum}\n\\item \\label{ex:equiv_pi}Let $e_i:\\eqv{A_i}{B_i}$ be an equivalence for every $i:I$. Show that the map\n\\begin{equation*}\n\\lam{f}{i}e_i\\circ f:\\Big(\\prd{i:I}A_i\\Big)\\to\\Big(\\prd{i:I}B_i\\Big)\n\\end{equation*}\nis an equivalence.\n\\item \\label{ex:triangle_fib}Consider a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}[column sep=tiny]\nA \\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*}\nNote: 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{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\\item \\label{ex:sq_fib}Consider a diagram of the form\n\\begin{equation*}\n\\begin{tikzcd}\nA \\arrow[d,swap,\"f\"] & B \\arrow[d,\"g\"] \\\\\nX \\arrow[r,swap,\"h\"] & Y.\n\\end{tikzcd}\n\\end{equation*}\nShow 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%\\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\\item \\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} from $A$ to $B$, i.e., the type of quadruples $(f,g,H,K)$ consisting of\n\\begin{align*}\nf & : A\\to B \\\\\ng & : B\\to A \\\\\nH & : f\\circ g = \\idfunc[B] \\\\\nK & : g\\circ f = \\idfunc[A].\n\\end{align*}\n\\item \\label{ex:pi_sec}Let $B$ be a type family over $A$, and consider the maps\n  \\begin{align*}\n    \\proj 1 & : \\sm{x:A} B(x)\\to A \\\\\n    \\proj1 \\circ \\blank & : \\Big(\\sm{x:A} B(x)\\Big)^A \\to A^A.\n  \\end{align*}\n  Construct equivalences\n  \\begin{equation*}\n    \\Big(\\prd{x:A}B(x)\\Big) \\eqvsym \\mathsf{sec}(\\proj 1) \\eqvsym \\fib{\\proj 1 \\circ\\blank}{\\idfunc[A]}.\n  \\end{equation*}\n\\item Suppose that $A:I\\to \\UU$ is a type family over a set $I$ with decidable equality. Show that\n  \\begin{equation*}\n    \\Big(\\prd{i:I}\\iscontr(A_i)\\Big)\\leftrightarrow \\iscontr\\Big(\\prd{i:I}A_i\\Big).\n  \\end{equation*}\n\\item Construct equivalences\n  \\begin{align*}\n    \\mathsf{Fin}(n^m) & \\simeq (\\mathsf{Fin}(m)\\to\\mathsf{Fin}(n)) \\\\\n    \\mathsf{Fin}(n!) & \\simeq (\\mathsf{Fin}(n)\\simeq\\mathsf{Fin}(n)).\n  \\end{align*}\n\\end{exercises}\n", "meta": {"hexsha": "764340ccfd00611cc6880caed7666552aba1ea89", "size": 24207, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/funext.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/funext.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/funext.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": 48.414, "max_line_length": 646, "alphanum_fraction": 0.6817036394, "num_tokens": 8726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.603996806245551}}
{"text": "% Copyright 2018 Markus J. Pflaum, licensed under GNU FDL v1.3\n% main author: \n%   Markus J. Pflaum\n%\n\\section{Unbounded linear operators}\n\\label{sec:unbounded-linear-operators}\n%\n\\para \nIn this section let $\\banachV,\\banachW$ always denote Banach spaces over the field \n$\\fldK =\\R$ or $\\fldK=\\C$. The symbols $\\hilbertH$, $\\hilbertH_1$, ... will always stand for Hilbert spaces over $\\fldK$. \n\n\\begin{definition} \n  By an \\emph{unbounded $\\fldK$-linear operator} or shortly by an \n  \\emph{unbounded operator} from $\\banachV$ to $\\banachW$ we understand a linear map \n  $A: \\Dom (A) \\to \\banachW$ defined on a $\\fldK$-linear subspace $\\Dom (A)\\subset \\banachV$.\n  As usual, $\\Dom (A)$ is called the \\emph{domain} of the operator $A$.\n  The space of unbounded $\\fldK$-linear operators from $V$ to $W$ will be \n  denoted $\\linOps_\\fldK (V,W)$ or just  $\\linOps (V,W)$.\n\\end{definition}\n\n\\begin{remark}\n  In this work, the term ``unbounded'' is meant in the sense of\n  ``not necessarily bounded''. Sometimes we just say \n  \\emph{linear operator} or even only \\emph{operator} instead of\n  ``unbounded linear operator''.\n\\end{remark}\n\n\\para Observe that besides the domain $\\Dom (A)$ of an unbounded operator \n  $A \\in \\linOps (\\banachV,\\banachW)$ the \n  \\emph{kernel} \n  \\[\\Ker(A)=\\big\\{ v \\in \\banachV \\bigmid Av = 0 \\big\\}\\subset\\banachV \\ , \\]\n  the \\emph{image} \n  \\[\\Img(A)=\\big\\{ w \\in \\banachW \\bigmid \\exists v\\in \\Dom (A): w = Av \\big\\}\n  \\subset \\banachW \\ , \\] \n  and the \\emph{graph}\n  \\[\\Graph(A)=\\big\\{ (v,w) \\in \\Dom (A) \\times \\banachW \\bigmid \n    w = Av \\big\\} \\subset \\banachV \\times \\banachW \\]\n  of $A$  are all linear subspaces. We will frequently make use of this.\n  \n\\begin{definition}\n  An unbounded operator $A\\in \\linOps (\\banachV,\\banachW)$ is called \n  \\emph{densely defined} if $\\Dom (A)$ is dense in $\\banachV$,\n  and \\emph{closed} if the graph $\\Gr (A)$ \n  is closed in $\\banachV \\times \\banachW$.\n  The operator $A \\in \\linOps (V,W)$ is called \\emph{closable} if the closure\n  $\\closure{\\Gr(A)}$ is the graph of an unbounded operator \n  from $\\banachV$ to $\\banachW$. \n\n  An operator $A \\in \\linOps (V,W)$ is called an \\emph{extension} of \n  $B \\in \\linOps (V,W)$ if $\\Gr (B) \\subset \\Gr (A)$. One writes in this\n  situation $B \\subset A$. \n\\end{definition}\n\n  \n   \n", "meta": {"hexsha": "2fe04eaa3adc01a34e9022cdd95e18c221b8e75e", "size": 2295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/unbounded-linear-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/unbounded-linear-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/unbounded-linear-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": 40.9821428571, "max_line_length": 122, "alphanum_fraction": 0.660130719, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738010682209, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.603996806245551}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{parskip}\n\\usepackage{booktabs}\n\\usepackage{amsmath}\n\\pagenumbering{gobble}\n\n\\begin{document}\n\n\\section{Select your strategies}\n\n\n$$A=\n\\begin{pmatrix}\n2 & -2\\\\\n-1 & 1\n\\end{pmatrix}\n\\qquad\nB=\n\\begin{pmatrix}\n-2 & 2\\\\\n1 & -1\n\\end{pmatrix}\n$$\n\n\\begin{enumerate}\n\\item Choose your strategies (as the column player) against the mixed strategy.\n\\item Wait for me to generate random strategies according to the random distribution.\n\\end{enumerate}\n\\vspace{1cm}\n\n\\begin{center}\n\\begin{tabular}{c|c|c|c|c|c|c}\n\\toprule\n& \\multicolumn{2}{c|}{$\\sigma_1 = (.2,.8)$} & \\multicolumn{2}{|c|}{$\\sigma_1 = (.9,.1)$} & \\multicolumn{2}{|c}{$\\sigma_1=(1/3,2/3)$}\\\\\nRound&$s_2$&$\\sum u_2$&$s_2$&$\\sum u_2$&$s_2$&$\\sum u_2$\\\\\n\\midrule\n&&&&&&\\\\\n1&&&&&&\\\\\n&&&&&&\\\\\n&&&&&&\\\\\n2&&&&&&\\\\\n&&&&&&\\\\\n&&&&&&\\\\\n3&&&&&&\\\\\n&&&&&&\\\\\n&&&&&&\\\\\n4&&&&&&\\\\\n&&&&&&\\\\\n&&&&&&\\\\\n5&&&&&&\\\\\n&&&&&&\\\\\n&&&&&&\\\\\n6&&&&&&\\\\\n&&&&&&\\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "82e6a3d8329b736ff7b9e56ebfd553a84a59991a", "size": 995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/assets/activities/bestresponsetomixedstrategies.tex", "max_stars_repo_name": "prokolyvakis/gt", "max_stars_repo_head_hexsha": "e679e5d54d9a98583ad4981411ce505cea31f028", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2017-05-25T08:10:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-07T21:01:51.000Z", "max_issues_repo_path": "docs/assets/activities/bestresponsetomixedstrategies.tex", "max_issues_repo_name": "prokolyvakis/gt", "max_issues_repo_head_hexsha": "e679e5d54d9a98583ad4981411ce505cea31f028", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2017-05-23T16:12:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T13:42:25.000Z", "max_forks_repo_path": "docs/assets/activities/bestresponsetomixedstrategies.tex", "max_forks_repo_name": "prokolyvakis/gt", "max_forks_repo_head_hexsha": "e679e5d54d9a98583ad4981411ce505cea31f028", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2017-06-19T11:04:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-30T11:28:00.000Z", "avg_line_length": 15.7936507937, "max_line_length": 134, "alphanum_fraction": 0.5708542714, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6039968027025796}}
{"text": "\\chapter{Arithmetic}\n\\label{chap:Arithmetic}\n\nIn this chapter, we will learn how to perform basic\narithmetic with libzahl: addition, subtraction,\nmultiplication, division, modulus, exponentiation,\nand sign manipulation. \\secref{sec:Division} is of\nspecial importance.\n\n\\vspace{1cm}\n\\minitoc\n\n\n\\newpage\n\\section{Addition}\n\\label{sec:Addition}\n\nTo calculate the sum of two terms, we perform\naddition using {\\tt zadd}.\n\n\\vspace{1em}\n$r \\gets a + b$\n\\vspace{1em}\n\n\\noindent\nis written as\n\n\\begin{alltt}\n   zadd(r, a, b);\n\\end{alltt}\n\nlibzahl also provides {\\tt zadd\\_unsigned} which\nhas slightly lower overhead. The calculates the\nsum of the absolute values of two integers.\n\n\\vspace{1em}\n$r \\gets \\lvert a \\rvert + \\lvert b \\rvert$\n\\vspace{1em}\n\n\\noindent\nis written as\n\n\\begin{alltt}\n   zadd_unsigned(r, a, b);\n\\end{alltt}\n\n\\noindent\n{\\tt zadd\\_unsigned} has lower overhead than\n{\\tt zadd} because it does not need to inspect\nor change the sign of the input, the low-level\nfunction that performs the addition inherently\ncalculates the sum of the absolute values of\nthe input.\n\nIn libzahl, addition is implemented using a\ntechnique called ripple-carry. It is derived\nfrom that observation that\n\n\\vspace{1em}\n$f : \\textbf{Z}_n, \\textbf{Z}_n \\rightarrow \\textbf{Z}_n$\n\\\\ \\indent\n$f : a, b \\mapsto a + b + 1$\n\\vspace{1em}\n\n\\noindent\nonly wraps at most once, that is, the\ncarry cannot exceed 1. CPU:s provide an\ninstruction specifically for performing\naddition with ripple-carry over multiple words,\nadds twos numbers plus the carry from the\nlast addition. libzahl uses assembly to\nimplement this efficiently. If, however, an\nassembly implementation is not available for\nthe on which machine it is running, libzahl\nimplements ripple-carry less efficiently\nusing compiler extensions that check for\noverflow. In the event that neither an\nassembly implementation is available nor\nthe compiler is known to support this\nextension, it is implemented using inefficient\npure C code. This last resort manually\npredicts whether an addition will overflow;\nthis could be made more efficient, by never\nusing the highest bit in each character,\nexcept to detect overflow. This optimisation\nis however not implemented because it is\nnot deemed important enough and would\nbe detrimental to libzahl's simplicity.\n\n{\\tt zadd} and {\\tt zadd\\_unsigned} support\nin-place operation:\n\n\\begin{alltt}\n   zadd(a, a, b);\n   zadd(b, a, b);           \\textcolor{c}{/* \\textrm{should be avoided} */}\n   zadd_unsigned(a, a, b);\n   zadd_unsigned(b, a, b);  \\textcolor{c}{/* \\textrm{should be avoided} */}\n\\end{alltt}\n\n\\noindent\nUse this whenever possible, it will improve\nyour performance, as it will involve less\nCPU instructions for each character addition\nand it may be possible to eliminate some\ncharacter additions.\n\n\n\\newpage\n\\section{Subtraction}\n\\label{sec:Subtraction}\n\nTODO % zsub zsub_unsigned\n\n\n\\newpage\n\\section{Multiplication}\n\\label{sec:Multiplication}\n\nTODO % zmul zmodmul\n\n\n\\newpage\n\\section{Division}\n\\label{sec:Division}\n\nTo calculate the quotient or modulus of two integers,\nuse either of\n\n\\begin{alltt}\n   void zdiv(z_t quotient, z_t dividend, z_t divisor);\n   void zmod(z_t remainder, z_t dividend, z_t divisor);\n   void zdivmod(z_t quotient, z_t remainder,\n                z_t dividend, z_t divisor);\n\\end{alltt}\n\n\\noindent\nThese function \\emph{do not} allow {\\tt NULL}\nfor the output parameters: {\\tt quotient} and\n{\\tt remainder}. The quotient and remainder are\ncalculated simultaneously and indivisibly, hence\n{\\tt zdivmod} is provided to calculated both; if\nyou are only interested in the quotient or only\ninterested in the remainder, use {\\tt zdiv} or\n{\\tt zmod}, respectively.\n\nThese functions calculate a truncated quotient.\nThat is, the result is rounded towards zero. This\nmeans for example that if the quotient is in\n$(-1,~1)$, {\\tt quotient} gets 0. That is, this % TODO try to clarify\nwould not be the case for one of the sides of zero.\nFor example, if the quotient would have been\nfloored, negative quotients would have been rounded\naway from zero. libzahl only provides truncated\ndivision.\n\nThe remainder is defined such that $n = qd + r$ after\ncalling {\\tt zdivmod(q, r, n, d)}. There is no\ndifference in the remainer between {\\tt zdivmod}\nand {\\tt zmod}. The sign of {\\tt d} has no affect\non {\\tt r}, {\\tt r} will always, unless it is zero,\nhave the same sign as {\\tt n}.\n\nThere are of course other ways to define integer\ndivision (that is, \\textbf{Z} being the codomain)\nthan as truncated division. For example integer\ndivison in Python is floored — yes, you did just\nread `integer divison in Python is floored,' and\nyou are correct, that is not the case in for\nexample C. Users that want another definition\nfor division than truncated division are required\nto implement that themselves. We will however\nlend you a hand.\n\n\\begin{alltt}\n   #define isneg(x) (zsignum(x) < 0)\n   static z_t one;\n   \\textcolor{c}{__attribute__((constructor)) static}\n   void init(void) \\{ zinit(one), zseti(one, 1); \\}\n\n   static int\n   cmpmag_2a_b(z_t a, z_b b)\n   \\{\n       int r;\n       zadd(a, a, a), r = zcmpmag(a, b), zrsh(a, a, 1);\n       return r;\n   \\}\n\\end{alltt}\n\n% Floored division\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_floor(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && isneg(n) != isneg(d))\n           zsub(q, q, one), zadd(r, r, d);\n   \\}\n\\end{alltt}\n\n% Ceiled division\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_ceiling(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && isneg(n) == isneg(d))\n           zadd(q, q, one), zsub(r, r, d);\n   \\}\n\\end{alltt}\n\n% Division with round half aways from zero\n% This rounding method is also called:\n%    round half toward infinity\n%    commercial rounding\n\\begin{alltt}\n   /* \\textrm{This is how we normally round numbers.} */\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_from_zero(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && cmpmag_2a_b(r, d) >= 0) \\{\n           if (isneg(n) == isneg(d))\n               zadd(q, q, one), zsub(r, r, d);\n           else\n               zsub(q, q, one), zadd(r, r, d);\n       \\}\n   \\}\n\\end{alltt}\n\n\\noindent\nNow to the weird ones that will more often than\nnot award you a face-slap. % Had positive punishment\n% been legal or even mildly pedagogical. But I would\n% not put it past Coca-Cola.\n\n% Division with round half toward zero\n% This rounding method is also called:\n%     round half away from infinity\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_to_zero(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && cmpmag_2a_b(r, d) > 0) \\{\n           if (isneg(n) == isneg(d))\n               zadd(q, q, one), zsub(r, r, d);\n           else\n               zsub(q, q, one), zadd(r, r, d);\n       \\}\n   \\}\n\\end{alltt}\n\n% Division with round half up\n% This rounding method is also called:\n%     round half towards positive infinity\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_up(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       int cmp;\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && (cmp = cmpmag_2a_b(r, d)) >= 0) \\{\n           if (isneg(n) == isneg(d))\n               zadd(q, q, one), zsub(r, r, d);\n           else if (cmp)\n               zsub(q, q, one), zadd(r, r, d);\n       \\}\n   \\}\n\\end{alltt}\n\n% Division with round half down\n% This rounding method is also called:\n%     round half towards negative infinity\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_down(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       int cmp;\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && (cmp = cmpmag_2a_b(r, d)) >= 0) \\{\n           if (isneg(n) != isneg(d))\n               zsub(q, q, one), zadd(r, r, d);\n           else if (cmp)\n               zadd(q, q, one), zsub(r, r, d);\n       \\}\n   \\}\n\\end{alltt}\n\n% Division with round half to even\n% This rounding method is also called:\n%     unbiased rounding        (really stupid name)\n%     convergent rounding      (also quite stupid name)\n%     statistician's rounding\n%     Dutch rounding\n%     Gaussian rounding\n%     odd–even rounding\n%     bankers' rounding\n% It is the default rounding method used in IEEE 754.\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_to_even(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       int cmp;\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && (cmp = cmpmag_2a_b(r, d)) >= 0) \\{\n           if (cmp || zodd(q)) \\{\n               if (isneg(n) != isneg(d))\n                   zsub(q, q, one), zadd(r, r, d);\n               else\n                   zadd(q, q, one), zsub(r, r, d);\n           \\}\n       \\}\n   \\}\n\\end{alltt}\n\n% Division with round half to odd\n\\newpage\n\\begin{alltt}\n   void \\textcolor{c}{/* \\textrm{All arguments must be unique.} */}\n   divmod_half_to_odd(z_t q, z_t r, z_t n, z_t d)\n   \\{\n       int cmp;\n       zdivmod(q, r, n, d);\n       if (!zzero(r) && (cmp = cmpmag_2a_b(r, d)) >= 0) \\{\n           if (cmp || zeven(q)) \\{\n               if (isneg(n) != isneg(d))\n                   zsub(q, q, one), zadd(r, r, d);\n               else\n                   zadd(q, q, one), zsub(r, r, d);\n           \\}\n       \\}\n   \\}\n\\end{alltt}\n\n% Other standard methods include stochastic rounding\n% and round half alternatingly, and what is is\n% New Zealand called “Swedish rounding”, which is\n% no longer used in Sweden, and is just normal round\n% half aways from zero but with 0.5 rather than\n% 1 as the integral unit, and is just a special case\n% of a more general rounding method.\n\nCurrently, libzahl uses an almost trivial division\nalgorithm. It operates on positive numbers. It begins\nby left-shifting the divisor as much as possible with\nletting it exceed the dividend. Then, it subtracts\nthe shifted divisor from the dividend and add 1,\nleft-shifted as much as the divisor, to the quotient.\nThe quotient begins at 0. It then right-shifts\nthe shifted divisor as little as possible until\nit no longer exceeds the diminished dividend and\nmarks the shift in the quotient. This process is\nrepeated until the unshifted divisor is greater\nthan the diminished dividend. The final diminished\ndividend is the remainder.\n\n\n\n\\newpage\n\\section{Exponentiation}\n\\label{sec:Exponentiation}\n\nExponentiation refers to raising a number to\na power. libzahl provides two functions for\nregular exponentiation, and two functions for\nmodular exponentiation. libzahl also provides\na function for raising a number to the second\npower, see \\secref{sec:Multiplication} for\nmore details on this. The functions for regular\nexponentiation are\n\n\\begin{alltt}\n   void zpow(z_t power, z_t base, z_t exponent);\n   void zpowu(z_t, z_t, unsigned long long int);\n\\end{alltt}\n\n\\noindent\nThey are identical, except {\\tt zpowu} expects\nan intrinsic type as the exponent. Both functions\ncalculate\n\n\\vspace{1em}\n$power \\gets base^{exponent}$\n\\vspace{1em}\n\n\\noindent\nThe functions for modular exponentiation are\n\\begin{alltt}\n   void zmodpow(z_t, z_t, z_t, z_t modulator);\n   void zmodpowu(z_t, z_t, unsigned long long int, z_t);\n\\end{alltt}\n\n\\noindent\nThey are identical, except {\\tt zmodpowu} expects\nand intrinsic type as the exponent. Both functions\ncalculate\n\n\\vspace{1em}\n$power \\gets base^{exponent} \\mod modulator$\n\\vspace{1em}\n\nThe sign of {\\tt modulator} does not affect the\nresult, {\\tt power} will be negative if and only\nif {\\tt base} is negative and {\\tt exponent} is\nodd, that is, under the same circumstances as for\n{\\tt zpow} and {\\tt zpowu}.\n\nThese four functions are implemented using\nexponentiation by squaring. {\\tt zmodpow} and\n{\\tt zmodpowu} are optimised, they modulate\nresults for multiplication and squaring at\nevery multiplication and squaring, rather than\nmodulating the result at the end. Exponentiation\nby modulation is a very simple algorithm which\ncan be expressed as a simple formula\n\n\\vspace{-1em}\n\\[ \\hspace*{-0.4cm}\n    a^b =\n    \\prod_{k \\in \\textbf{Z}_{+} ~:~ \\left \\lfloor \\frac{b}{2^k} \\hspace*{-1ex} \\mod 2 \\right \\rfloor = 1}\n    a^{2^k}\n\\]\n\n\\noindent\nThis is a natural extension to the\nobservations\\footnote{The first of course being\nthat any non-negative number can be expressed\nwith the binary positional system. The latter\nshould be fairly self-explanatory.}\n\n\\vspace{-1em}\n\\[ \\hspace*{-0.4cm}\n    \\forall b \\in \\textbf{Z}_{+} \\exists B \\subset \\textbf{Z}_{+} : b = \\sum_{i \\in B} 2^i\n    ~~~~ \\textrm{and} ~~~~\n    a^{\\sum x} = \\prod a^x.\n\\]\n\n\\noindent\nThe algorithm can be expressed in psuedocode as\n\n\\vspace{1em}\n\\hspace{-2.8ex}\n\\begin{minipage}{\\linewidth}\n\\begin{algorithmic}\n    \\STATE $r, f \\gets 1, a$\n    \\WHILE{$b \\neq 0$}\n      \\STATE $r \\gets r \\cdot f$ {\\bf unless} $2 \\vert b$\n      \\STATE $f \\gets f^2$ \\textcolor{c}{\\{$f \\gets f \\cdot f$\\}}\n      \\STATE $b \\gets \\lfloor b / 2 \\rfloor$\n    \\ENDWHILE\n    \\RETURN $r$ \n\\end{algorithmic}\n\\end{minipage}\n\\vspace{1em}\n\n\\noindent\nModular exponentiation ($a^b \\mod m$) by squaring can be\nexpressed as\n\n\\vspace{1em}\n\\hspace{-2.8ex}\n\\begin{minipage}{\\linewidth}\n\\begin{algorithmic}\n    \\STATE $r, f \\gets 1, a$\n    \\WHILE{$b \\neq 0$}\n      \\STATE $r \\gets r \\cdot f \\hspace*{-1ex}~ \\mod m$ \\textbf{unless} $2 \\vert b$\n      \\STATE $f \\gets f^2 \\hspace*{-1ex}~ \\mod m$\n      \\STATE $b \\gets \\lfloor b / 2 \\rfloor$\n    \\ENDWHILE\n    \\RETURN $r$ \n\\end{algorithmic}\n\\end{minipage}\n\\vspace{1em}\n\n{\\tt zmodpow} does \\emph{not} calculate the\nmodular inverse if the exponent is negative,\nrather, you should expect the result to be\n1 and 0 depending of whether the base is 1\nor not 1.\n\n\n\\newpage\n\\section{Sign manipulation}\n\\label{sec:Sign manipulation}\n\nlibzahl provides two functions for manipulating\nthe sign of integers:\n\n\\begin{alltt}\n   void zabs(z_t r, z_t a);\n   void zneg(z_t r, z_t a);\n\\end{alltt}\n\n{\\tt zabs} stores the absolute value of {\\tt a}\nin {\\tt r}, that is, it creates a copy of\n{\\tt a} to {\\tt r}, unless {\\tt a} and {\\tt r}\nare the same reference, and then removes its sign;\nif the value is negative, it becomes positive.\n\n\\vspace{1em}\n\\(\n    r \\gets \\lvert a \\rvert =\n    \\left \\lbrace \\begin{array}{rl}\n        -a & \\quad \\textrm{if}~a \\le 0 \\\\\n        +a & \\quad \\textrm{if}~a \\ge 0 \\\\\n    \\end{array} \\right .\n\\)\n\\vspace{1em}\n\n{\\tt zneg} stores the negated of {\\tt a}\nin {\\tt r}, that is, it creates a copy of\n{\\tt a} to {\\tt r}, unless {\\tt a} and {\\tt r}\nare the same reference, and then flips sign;\nif the value is negative, it becomes positive,\nif the value is positive, it becomes negative.\n\n\\vspace{1em}\n\\(\n    r \\gets -a\n\\)\n\\vspace{1em}\n\nNote that there is no function for\n\n\\vspace{1em}\n\\(\n    r \\gets -\\lvert a \\rvert =\n    \\left \\lbrace \\begin{array}{rl}\n         a & \\quad \\textrm{if}~a \\le 0 \\\\\n        -a & \\quad \\textrm{if}~a \\ge 0 \\\\\n    \\end{array} \\right .\n\\)\n\\vspace{1em}\n\n\\noindent\ncalling {\\tt zabs} followed by {\\tt zneg}\nshould be sufficient for most users:\n\n\\begin{alltt}\n   #define my_negabs(r, a)  (zabs(r, a), zneg(r, r))\n\\end{alltt}\n", "meta": {"hexsha": "2c5a9d32d37bd3340496689c1f30d628f46561d2", "size": 15158, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/arithmetic.tex", "max_stars_repo_name": "maandree/libzahl", "max_stars_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2016-03-06T10:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T10:40:14.000Z", "max_issues_repo_path": "doc/arithmetic.tex", "max_issues_repo_name": "maandree/libzahl", "max_issues_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2016-05-09T12:34:47.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-22T13:11:49.000Z", "max_forks_repo_path": "doc/arithmetic.tex", "max_forks_repo_name": "maandree/libzahl", "max_forks_repo_head_hexsha": "cf4b5d338225ac30d8f7434768c45619928bf3bf", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-10-14T12:23:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T12:10:26.000Z", "avg_line_length": 27.9667896679, "max_line_length": 105, "alphanum_fraction": 0.6664467608, "num_tokens": 4663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6039967982386801}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\\begin{document}\n\n\\subsection{Motivation}\n\nIt is considered a problem of constructing a phase trajectory of a video file using tensor-based singular spectrum analysis method. Usually, phase trajectory of a time series is constructed using SSA method that is applied to a matrix with two indices \\cite{golyandina, usmanova}. In this work it is proposed to apply tensor-based SSA method that constructs a trajectory matrix that has 3 indices, then apply HOSVD method for extracting principal components.\n\n\\subsection{Problem statement}\n\nGiven a sequence of images that composes a gray-scale video. Let us consider this as a time series system. Each time series is a sequence of a particular pixel brightness:\n\n$$F^{(k)} = (f_j^{(k)})_{j=0}^{N-1}, \\quad k = 1, \\dots, hw,$$\n\n\\noindent\nwhere $h$ is the video height, $w$ is the video width, $hw$ is a number of signals with length $N$.\n\nThe purpose is to construct a phase trajectory of the time series system and make a forecast $\\hat{\\mathbf{X}}^\\prime$ using tensor-based SSA method and HOSVD.\n\n\\subsection{Problem solution}\n\nIt is proposed to solve a problem with tensor-based singular spectrum analysis and make a forecast using HOSVD.\n\n\\textbf{1st step: Embedding}\n\nLet $L$ be a window length, $1 < L < N$. The embedding procedure forms $K = N-L+1$ lagged vectors for every time series:\n\n$$X_l^{(k)} = (f_{l-1}^{(k)}, \\dots, f_{l+L-2}^{(k)})^\\top.$$\n\nThe trajectory matrix of the time series system $F^{(1)}, \\dots, F^{(hw)}$ is a tensor that has a form\n\n$$\\hat{\\mathbf{X}} = (\\mathbf{X}^{(1)}, \\dots, \\mathbf{X}^{(hw)}),$$\n\n\\noindent\nwhere $\\mathbf{X}^{(k)} = (X_l^{(k)})_{l=0}^{K}$.\n\n\\textbf{2nd step: HOSVD}\n\nTruncated HOSVD is performed:\n\n$$\\hat{\\mathbf{X}} = \\mathbf{S} \\times_1 U_1 \\times_2 U_2 \\times_3 U_3,$$\n\n\\noindent\nwhere $\\mathbf{S}$ is a core tensor, $U_1, U_2, U_3$ are matrices with unitary columns containing a basis of the left singular vectors corresponding to the nonzero singular values of the standard factor-$k$ flattening $X_{(k)}$ of $X$ for $k = 1, 2, 3$.\n\nThe HOSVD of $\\hat{\\mathbf{X}}$ can be represent as\n\n$$\\hat{\\mathbf{X}} = \\hat{\\mathbf{X}}_1 + \\dots + \\hat{\\mathbf{X}}_d,$$\n\n\\noindent\nwhere $\\hat{\\mathbf{X}}_i$ has rank equal to 1.\n\n\\textbf{3rd step: Grouping}\n\nThe grouping procedure partitions the\nset of indices $\\{1, \\dots, d\\}$ into $m$ disjoint subsets $I_1, \\dots, I_m$. Let $I = {i_1, \\dots, i_p}$. Then the resultant matrix $\\hat{\\mathbf{X}}$ corresponding to the group $I$ is defined as $\\hat{\\mathbf{X}}_I = \\hat{\\mathbf{X}}_{i_1} + \\dots + \\hat{\\mathbf{X}}_{i_p}$. Thus, we have the grouped decomposition:\n\n$$\\hat{\\mathbf{X}} = \\hat{\\mathbf{X}}_{I_1} + \\dots + \\hat{\\mathbf{X}}_{I_m}.$$\n\n\\textbf{4th step: Diagonal averaging}\n\nThe last step is in a sense opposite to the first step and transforms each matrix of the grouped decomposition into a system of new (reconstructed) series of length $N$ by hankelization-like procedure.\n\n\\subsection{Code analysis}\n\nCode for HOSVD decomposition was taken from GitHub repository\\footnote{https://github.com/hottbox/hottbox}. Code of the computational experiment can be found in the repository\\footnote{https://github.com/gorpinich-m/Math-methods-of-forecasting}.\n\n\\subsection{Experiment}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{sections/gorpinich/trajectories_base.pdf}\n\\caption{Some description}\n\\label{fig:1}\n\\end{figure}\n\nFig. \\ref{fig:1} plots phase trajectories of 4 pixels of the basic video.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{sections/gorpinich/mario_trajectory.pdf}\n\\caption{Some description}\n\\label{fig:2}\n\\end{figure}\n\nFig. \\ref{fig:1} plots phase trajectories of 1000 pixels of the video.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{sections/gorpinich/ssa_base.pdf}\n\\caption{Some description}\n\\label{fig:3}\n\\end{figure}\n\nFig. \\ref{fig:3} plots SSA decomposition of the basic video. We can see that the first component is a trend and other 2 components depict periodicity ans seasonality.\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{sections/gorpinich/ssa_mario.pdf}\n\\caption{Some description}\n\\label{fig:4}\n\\end{figure}\n\nFig. \\ref{fig:4} plots SSA decomposition of the more complex video.\n\n\\end{document}", "meta": {"hexsha": "3c659540e1d503b0f3e06bc0c5e8b126c738eca9", "size": 4311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Gorpinich2021Lab5/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/Gorpinich2021Lab5/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/Gorpinich2021Lab5/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": 40.6698113208, "max_line_length": 458, "alphanum_fraction": 0.7283692879, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6039967963968241}}
{"text": "\n\\section{Introduction}\nThe bread-first search is an algorithm visiting a graph in amplitude. It starts from a node, \noften called the root or source node, and continues visiting all its descendants level\nby level, whereas the $i$-th level will contain all the nodes at a distance \n$i$ from the root.\nFor each node visited the algorithm checks its label to count the occurrences of the target label.\nThe assumption underlying all the work is that the input to the algorithm is a direct and \nacyclic graph. In addition, for the sake of clarity, the notation used is summarized below:\n\\subsection{Notation}\nLet $\\mathcal{G} = (V, E)$, $|V| = n$ is the number of node and $|E| = m$ is the number of edges. \nFor all the node $v \\in V$:\n\\begin{itemize}\n    \\item $\\mathcal{N}(v) = \\{u : (v, u) \\in E\\}$ is the neighborhood of $v$;\n    \\item $k_{in}(v) = |\\{e: e=(u, v) \\in E\\}|$ is the in-degree of $v$;\n    \\item $k_{out}(v) = |\\mathcal{N}(v)|$ is the out-degree of $v$;\n    \\item $k(v) = k_{in}(v) + k_{out}(v)$ is the degree of $v$.\n    \\item $d(u, v)$ is the distance from $u$ to $v$, i.e. the minimum path from $u$ to $v$.\n    \\item $C(v)$ is the clustering coefficient, i.e.e $\\frac{2 \\cdot L_i}{k_i\\cdot(k_i - 1)}$, where $L_i$ represents the number of edges between the $k_i$ neighbors of node i.\n\\end{itemize}\nUsing the node-focus notation above,\n it is possible to define general properties for the graph:\n\\begin{itemize}\n    \\item $\\bar{k}(G)$ is the average degree;\n    \\item $\\bar{d}(G)$ is the average distance;\n    \\item $\\bar{h}(G)$ is the diameter, hence the maximum distance among any two nodes.\n\\end{itemize}\nIn addition, we can define \nthe graph inducted by a node $v$ as the subgraph $G'=(V', E')$ containing all the nodes reachable from v.  \n\\subsection{Preliminary analysis}\n\\subsubsection{Data structure}\nBefore entering in the algorithmic details let's first introduce the data structure used.\nThere are many ways to represent a graph; among these the main ones are the adjacency list and the adjacency\nmatrix. The choices among them is mainly a matter of the usage of the adjacency information and the \nexpected nature of the graph. As for every node $v$ of the graph, induced by the root, it will be necessary\nto go through each node $u \\in \\mathcal{N}(v)$, the adjacency list is way more efficient since for each\nnode $v$ the listing of $\\mathcal{N}(v)$ takes a time proportional to $k_{out}(v)$, which is thus optimal.\nMoreover, if the expected input of the algorithm are \"real\" graphs, since they are very sparse, the representation as a adjacency list is way \nmore efficient in terms of space complexity.\n\\\\\nIn particular, the solution implements a graph $G$ as a vector of nodes.\n The node is a pair, the first component is the label of the node, while the second\n component is the adjacency list containing the indices of the nodes in the graph.\nIn addition, to mark each node as visited, a vector of boolean is used (having a space complexity of $O(log_2n)$). This vector is called in the report \n\\textit{vector of visits}.\n\n \\subsubsection{Sequential version}\n\\label{sub:seq-version}\nThe sequential version is a straightforward implementation of the problem\ndescription. It uses two vectors $F_i$ and $F_{i+1}$: the former is the frontier \nwhile the latter is used to add new nodes and therefore represents the frontier \nto be used in the next iteration. At the beginning, the algorithm initializes the vector of visits,\n the frontier with the neighborhood of the source node and marks each child as visited. Then it marks the source node \nas visited and updates occurrences if needed (i.e. if the root has the searched label). After this first phase,\n the algorithm starts the first loop which iterates on each level checking that $F_i$ is not empty.\n Subsequently, for each level, it goes through each node $v \\in F_i$, updates occurrences if needed and\n then goes through each node $u \\in \\mathcal{N}(v)$.\n For each node $u$ in the neighborhood, if the node $u$ is not marked as visited, \n it adds $u$ to $F_{i+1}$. After having exhausted all the nodes of $F_i$, the algorithm\n swaps $F_i$ with $F_{i+1}$ and then clears $F_{i+1}$.\n\n", "meta": {"hexsha": "44738824d83e4a4cc6f8688f1055e9721e88867e", "size": 4166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/1.tex", "max_stars_repo_name": "giuseppegrieco/parallel-bfs", "max_stars_repo_head_hexsha": "0a2829febd37dc98c1c4a77f4bdda25f517ff815", "max_stars_repo_licenses": ["MIT"], "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/1.tex", "max_issues_repo_name": "giuseppegrieco/parallel-bfs", "max_issues_repo_head_hexsha": "0a2829febd37dc98c1c4a77f4bdda25f517ff815", "max_issues_repo_licenses": ["MIT"], "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/1.tex", "max_forks_repo_name": "giuseppegrieco/parallel-bfs", "max_forks_repo_head_hexsha": "0a2829febd37dc98c1c4a77f4bdda25f517ff815", "max_forks_repo_licenses": ["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.1935483871, "max_line_length": 176, "alphanum_fraction": 0.7316370619, "num_tokens": 1109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795403, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6039967963968241}}
{"text": "\\section{Results and Discussion}\n\\label{sec:Results_and_Discussion}\nThis section contains lists of all important results and summarizes the most important things.\n\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r||c|c|c}\n\t\t& \\textbf{Measured} ($\\mu$m) & \\textbf{True Value} ($\\mu$m) & \\textbf{Deviation} (\\%) \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Slit 1} & 39.41 $\\pm$ 0.93 & 40 & -1.5 \\\\\n\t\t\\textbf{Slit 2} & 101.26 $\\pm$ 6.77 & 100 & +1.3 \\\\ \\hline\n\t\t\\textbf{Anti-Slit 1} & 239.10 $\\pm$ 23.34 & 230 & +4.0 \\\\\n\t\t\\textbf{Anti-Slit 2} & 123.39 $\\pm$ 6.80 & 124 & -0.5 \\\\ \\hline\n\t\t\\textbf{Circular Aperture 1} & 151.39 $\\pm$ 10.24 & 150 & +0.9 \\\\\n\t\t\\textbf{Circular Aperture 2} & 101.62 $\\pm$ 4.60 & 100 & +1.6 \\\\ \\hline\n\t\t\\textbf{Cross-Grid 1} & 28.53 $\\pm$ 0.57 & 28 & +1.9 \\\\\n\t\t\\textbf{Cross-Grid 2} & 50.22 $\\pm$ 0.30 & 50 & +0.44 \\\\ \\hline\n\t\\end{tabular}\n\t\\caption{Summary of all Results}\n\t\\label{tab:results}\n\\end{table}\n\nTable \\ref{tab:results} shows that all the calculated mean values are really close to their true values (all values are within < 4 \\% deviation). The other important thing is to check, wheter their true value lies between the measured value and its uncertainty. This is shown in the following figure \\ref{fig:Graphical_Comparison}:\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.94]{Graphical_Comparison}\n\t\\caption{Graphical Comparison}\n\t\\label{fig:Graphical_Comparison}\n\\end{figure}\n\nFigure \\ref{fig:Graphical_Comparison} shows a graphical comparison between the calculated values (black cross with red uncertainty bar) and their respective true values (blue cross). The display order is the same as in the above table \\ref{tab:results}. Although it is difficult to see for the values with a small error bar, \\textbf{all their true values lie between their calculated values and their uncertainties}.\n", "meta": {"hexsha": "6147ea3a1c371776707c3e347c7bd9e76ed2746a", "size": 1861, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/results_discussion.tex", "max_stars_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_stars_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/results_discussion.tex", "max_issues_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_issues_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "glaL3_O_9_Interference_and_Diffraction/sections/results_discussion.tex", "max_forks_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_forks_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_forks_repo_licenses": ["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.7352941176, "max_line_length": 416, "alphanum_fraction": 0.7055346588, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6039653217400993}}
{"text": "\\documentclass{beamer}\n\n\\usepackage{beamerthemevictor,comment,verbatim,graphicx,rotating}\n\n\\input slidemacs\n\\input{tutmacs}\n\\input idxmacs\n\\input logicmacs\n\n\\begin{document}\n\n\\title{Logic and lambda calculus in \\TeX}\n\\author{Victor Eijkhout}\n\\date{Notes for CS 594 -- Fall 2004}\n\n\\frame{\\titlepage}\n\n\\section{Introduction}\n\\subsection{Markup}\n\n\\frame[containsverbatim]{\n  \\frametitle{}\n\\begin{itemize}\n\\item Expansion is very powerful\n\\item Implement logic, numbers, lambda calculus\n\\end{itemize}\n}\n\n\\def\\Ignore#1{}\n\\def\\Identity#1{#1}\n\\def\\First#1#2{#1}\n\\def\\Second#1#2{#2}\n\n\\frame[containsverbatim]{\n  \\frametitle{auxiliaries}\n\\begin{inputwithcode}\n\\def\\Ignore#1{}\n\\def\\Identity#1{#1}\n\\def\\First#1#2{#1}\n\\def\\Second#1#2{#2}\n\\end{inputwithcode}\n}\n\n\\let\\True=\\First\n\\let\\False=\\Second\n\\def\\And#1#2{#1{#2}\\False}\n\\def\\Or#1#2{#1\\True{#2}}\n\\def\\Twiddle#1#2#3{#1{#3}{#2}}\n\\let\\Not=\\Twiddle\n\n\\frame[containsverbatim]{\n  \\frametitle{Truth}\n\\begin{inputwithcode}\n\\let\\True=\\First\n\\let\\False=\\Second\n\\end{inputwithcode}\nand logical operators:\n\\begin{inputwithcode}\n\\def\\And#1#2{#1{#2}\\False}\n\\def\\Or#1#2{#1\\True{#2}}\n\\def\\Twiddle#1#2#3{#1{#3}{#2}}\n\\let\\Not=\\Twiddle\n\\end{inputwithcode}\n}\n\n\\frame[containsverbatim]{\n  \\frametitle{Truth test}\n\\begin{quote}\n\\test{True takes first of TF}{\\True}\n\\test{False takes second of TF}{\\False}\n\\test{Not true is false}{\\Not\\True}\n\n\\test{And truth table TrueTrue}{\\And\\True\\True}\n\\test{And truth table TrueFalse}{\\And\\True\\False}\n\\test{And truth table FalseTrue}{\\And\\False\\True}\n\\test{And truth table FalseFalse}{\\And\\False\\False}\n\n\\test{Or truth table TrueTrue}{\\Or\\True\\True}\n\\test{Or truth table TrueFalse}{\\Or\\True\\False}\n\\test{Or truth table FalseTrue}{\\Or\\False\\True}\n\\test{Or truth table FalseFalse}{\\Or\\False\\False}\n\\end{quote}\n}\n\n\\sectionframe{Lists}\n\n\\frame[containsverbatim]{\n  \\frametitle{Definition}\nWe implement a list as an operator with two arguments:\n\\begin{itemize}\n\\item If the list is not empty, the first argument is applied to the\n  head, and the tail is evaluated;\n\\item If the list is empty, the second argument is evaluated.\n\\end{itemize}\nIn other words\n\\[ L \\, a_1 \\, a_2 =\n      \\left\\{\\begin{array}{rl}a_2&\\mbox{if $L=()$}\\\\\n             a_1(x) \\, Y&\\mbox{if $L=(x,Y)$}\n      \\end{array}\\right. \\]\n}\n\n\\let\\Nil=\\Second\n% \\Cons <head> <tail> <arg1> <arg2>\n\\def\\Cons#1#2#3#4{#3{#1}{#2}}\n\\def\\Error{{ERROR}}\n\\def\\Head#1{#1\\First\\Error}\n\\def\\Tail#1{#1\\Second\\Error}\n\n\\frame[containsverbatim]{\n  \\frametitle{Construction}\n\\begin{inputwithcode}\n\\let\\Nil=\\Second\n% \\Cons <head> <tail> <arg1> <arg2>\n\\def\\Cons#1#2#3#4{#3{#1}{#2}}\n\\def\\Error{{ERROR}}\n\\def\\Head#1{#1\\First\\Error}\n\\def\\Tail#1{#1\\Second\\Error}\n\\end{inputwithcode}\n}\n\n\\def\\Singleton#1{\\Cons{#1}\\Nil}\n\n\\frame[containsverbatim]{\n  \\frametitle{List examples}\n\\begin{inputwithcode}\n\\def\\Singleton#1{\\Cons{#1}\\Nil}\n\\end{inputwithcode}\n\\begin{quote}\n\\test{Head of a singleton}{\\Head{\\Singleton\\True}}\n\\test{Head of a tail of a 2-elt list}%\n     {\\Head{\\Tail{\\Cons\\True{\\Singleton\\False}}}}\n\\end{quote}\n}\n\n\\def\\Transcribe#1{#1\\TranscribeHT\\gobbletwo}\n\\def\\TranscribeHT#1#2{1\\Transcribe{#2}}\n\n\\frame[containsverbatim]{\n  \\frametitle{Visualization}\n\\begin{inputwithcode}\n\\def\\gobbletwo#1#2{}\n\\def\\Transcribe#1{#1\\TranscribeHT\\gobbletwo}\n\\def\\TranscribeHT#1#2{1\\Transcribe{#2}}\n\\end{inputwithcode}\n}\n\n\\def\\ListApply#1#2#3{#3{\\ListApplyp{#1}{#2}}{#2}}\n\\def\\ListApplyp#1#2#3#4{#1{#3}{\\ListApply{#1}{#2}{#4}}}\n\n\\frame[containsverbatim]{\n  \\frametitle{Functions on lists}\nGiven function~$f$, \ninitial argument~$e$, and list~$X$, then\n\\[ \\mathtt{Apply}\\, f\\, e\\, X \\Rightarrow\n     f\\, x_1\\,(f\\, x_2\\, (\\ldots (f\\, x_n\\, e)\\ldots)) \\]\n\\begin{inputwithcode}\n% #1=function #2=initial arg #3=list\n\\def\\ListApply#1#2#3{#3{\\ListApplyp{#1}{#2}}{#2}}\n\\def\\ListApplyp#1#2#3#4{#1{#3}{\\ListApply{#1}{#2}{#4}}}\n\\end{inputwithcode}\n}\n\n\\def\\Cat#1#2{\\ListApply\\Cons{#2}{#1}}\n\n\\frame[containsverbatim]{\n  \\frametitle{Concatenate}\n\\begin{inputwithcode}\n\\def\\Cat#1#2{\\ListApply\\Cons{#2}{#1}}\n\\end{inputwithcode}\nFor example:\n\\begin{quote}\n\\test{Cat two lists}%\n  {\\Transcribe{\\Cat{\\Singleton\\Nil}{\\Cons\\Nil{\\Singleton\\Nil}}}}\n\\end{quote}\n}\n\n\\sectionframe{Numbers}\n\\subsection{Definition}\n\n\\let\\Zero\\Nil\n\\def\\AddOne#1{\\Cons\\Nil{#1}}\n\n\\frame[containsverbatim]{\n  \\frametitle{Adding one}\n\\begin{inputwithcode}\n\\let\\Zero\\Nil\n\\def\\AddOne#1{\\Cons\\Nil{#1}}\n\\end{inputwithcode}\nExamples:\n\\begin{quote}\n\\ttest{Transcribe zero}{\\Zero}\n\\ttest{Transcribe one}{\\AddOne\\Zero}\n\\ttest{Transcribe three}{\\AddOne{\\AddOne{\\AddOne\\Zero}}}\n\\end{quote}\n}\n\n\\newtoks\\dtoks\\newcount\\nn\n\\def\\ndef#1#2{\\nn=#2 \\dtoks={\\Zero}\\nndef#1}\n\\def\\nndef#1{\n  \\ifnum\\nn=0 \\edef\\tmp{\\def\\noexpand#1{\\the\\dtoks}}\\tmp\n  \\else \\edef\\tmp{\\dtoks={\\noexpand\\AddOne{\\the\\dtoks}}}\\tmp\n        \\advance\\nn by -1 \\nndef#1\n  \\fi}\n\\ndef\\One1 \\ndef\\Two2 \\ndef\\Three3 \\ndef\\Four4 \\ndef\\Five5\n%\\show\\Three\n\\ndef\\Seven7\\ndef\\Six6\n\n\\def\\Sub#1#2{#1{\\SubFrom{#2}}{#2}}\n\\def\\SubFrom#1#2#3{#1{\\SubMinOne{#3}}\\Error}\n\\def\\SubMinOne#1#2#3{\\Sub{#1}{#3}}\n\\def\\SubOne#1{#1\\Second\\Error}\n\n\\frame[containsverbatim]{\n  \\frametitle{Subtracting one}\n\\begin{inputwithcode}\n\\def\\SubOne#1{#1\\Second\\Error}\n\\end{inputwithcode}\n\\begin{quote}\n\\ttest{Predecessor of two}{\\SubOne{\\AddOne{\\AddOne\\Zero}}}\n\\end{quote}\n}\n\n\\subsectionframe{Arithmetic}\n\n\\frame[containsverbatim]{\n  \\frametitle{Addition}\n\\begin{inputwithcode}\n\\let\\Add=\\Cat\n\\end{inputwithcode}\n\\begin{quote}\n\\ttest{Adding numbers}{\\Add{\\Three}{\\Five}}\n\\end{quote}\n}\n\n\\def\\GreaterThan#1#2{#2{\\GreaterThanp{#1}}\\False}\n\\def\\GreaterThanp#1#2#3{#1{\\GreaterThanx{#3}}\\True}\n\\def\\GreaterThanx#1#2#3{\\GreaterThan{#1}{#3}}\n\n\\frame[containsverbatim]{\n  \\frametitle{Comparison}\n\\begin{inputwithcode}\n\\def\\GreaterThan#1#2{#2{\\GreaterThanp{#1}}\\False}\n\\def\\GreaterThanp#1#2#3{#1{\\GreaterThanx{#3}}\\True}\n\\def\\GreaterThanx#1#2#3{\\GreaterThan{#1}{#3}}\n\\end{inputwithcode}\n\\begin{quote}\n\\test{Greater (true result)}{\\GreaterThan\\Two\\Five}\n\\test{Greater (false result)}{\\GreaterThan\\Three\\Two}\n\\test{Greater (equal case)}{\\GreaterThan\\Two\\Two}\n\\test{Greater than zero}{\\GreaterThan\\Two\\Zero}\n\\test{Greater than zero}{\\GreaterThan\\Zero\\Two}\n\\end{quote}\n}\n\n\\frame[containsverbatim]{\n\\begin{quote}\n\\ttest{Use true result}{\\GreaterThan\\Two\\Five\\Three\\One}\n\\ttest{Use false result}{\\GreaterThan\\Three\\Two\\Three\\One}\n\\end{quote}\n\\begin{quote}\n\\test{$3<(5-1)$}{\\GreaterThan\\Three{\\Sub\\One\\Five}}\n\\test{$3<(5-4)$}{\\GreaterThan\\Three{\\Sub\\Four\\Five}}\n\\end{quote}\n}\n\n\\frame[containsverbatim]{\n  \\frametitle{Integers}\n\\begin{inputwithcode}\n% \\StreamOp <operator> <initial value>\n\\def\\StreamOp#1#2{\\Cons{#2}{\\StreamOp{#1}{#1{#2}}}}\n\\def\\Integers{\\StreamOp\\AddOne\\Zero}\n\\end{inputwithcode}\n\\begin{quote}\n\\ttest{Integers}{\\Head{\\Tail{\\Integers}}}\n\\ttest{Integers}%\n  {\\Head{\\Tail{\\Tail{\\Tail{\\Tail{\\Tail{\\Integers}}}}}}}\n\\end{quote}\n}\n\n\\end{document}\n\\frame[containsverbatim]{\n  \\frametitle{}\n}\n\n\\frame[containsverbatim]{\n  \\frametitle{}\n}\n\n\\frame[containsverbatim]{\n  \\frametitle{}\n}\n\n\\end{document}\n\n\\frame[containsverbatim]{\n  \\frametitle{}\n\\begin{itemize}\n\\item\n\\end{itemize}\n}\n\n", "meta": {"hexsha": "1cc12426724390a66b8de83b51f78ab06641200d", "size": 7015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lambda.tex", "max_stars_repo_name": "wvqusrai/the-science-of-tex-and-latex", "max_stars_repo_head_hexsha": "a96fd5cd0f7a6b9208675ba38ddcaec0264a9e31", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-07T08:21:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-07T08:21:41.000Z", "max_issues_repo_path": "slides/lambda.tex", "max_issues_repo_name": "wvqusrai/the-science-of-tex-and-latex", "max_issues_repo_head_hexsha": "a96fd5cd0f7a6b9208675ba38ddcaec0264a9e31", "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": "slides/lambda.tex", "max_forks_repo_name": "wvqusrai/the-science-of-tex-and-latex", "max_forks_repo_head_hexsha": "a96fd5cd0f7a6b9208675ba38ddcaec0264a9e31", "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": 23.2284768212, "max_line_length": 68, "alphanum_fraction": 0.6979330007, "num_tokens": 2683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085708384736, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6039653059905842}}
{"text": "\\section{Preliminaries}\n\\label{sect:ressat-preliminaries}\n\nA random-exist quantified SSAT formula $\\Qf$ has the form $\\random{} X,\\exists Y.\\pf(X,Y)$,\nwhere $X$ and $Y$ are two disjoint sets of Boolean variables,\nand $\\pf(X,Y)$ is a CNF formula.\n\n\\subsection{Generalization of SAT/UNSAT minterms}\n\\label{sect:ressat-generalize}\n\nGiven an assignment $\\as$ over $X$,\nif $\\pcf{\\pf(X,Y)}{\\as}$ is satisfiable (resp. unsatisfiable),\n$\\as$ is called a SAT (resp. an UNSAT) minterm of $\\pf$ over $X$.\nThe generalization process of a SAT or an UNSAT minterm $\\as$ aims at expanding it to a cube $\\as^+$,\nwhile maintaining the satisfiability of $\\pcf{\\pf(X,Y)}{\\as^+}$ the same as $\\pcf{\\pf(X,Y)}{\\as}$.\n\\begin{example}\n    \\label{ex:ressat-assign}\n    Consider formula $\\pf(x_1,x_2,y_1,y_2)=x_1 \\land (\\lnot x_2 \\lor y_1 \\lor y_2)$.\n    The complete assignment $\\as = x_1 x_2$ over $X$, i.e., $\\as(x_1)=\\top, \\as(x_2)=\\top$,\n    is a SAT minterm of $\\pf$ over $X$ because $\\pcf{\\pf}{\\as}$ is satisfiable by the assignment $\\mu = y_1y_2$.\n    On the other hand, the partial assignment $\\as^+ = \\lnot x_1$, i.e., $\\as^+(x_1)=\\bot$,\n    is an UNSAT cube of $\\pf$ as $\\pcf{\\pf}{\\as^+}$ is unsatisfiable.\n\\end{example}\n\n\\subsubsection{Minimum satisfying assignment}\nFor a CNF formula $\\pf(X,Y)$,\nlet $\\as$ be a SAT minterm over $X$ and let $\\mu$ be a satisfying complete assignment for the induced formula $\\pcf{\\pf(X,Y)}{\\as}$ over $Y$.\nTo generalize $\\as$ into a cube, one can find a subset of literals from $\\as$ and $\\mu$ that are able to satisfy all clauses in $\\pf$ while the number of literals taken from $\\as$ is as few as possible.\nIf some literals in $\\as$ are irrelevant to the satisfiability,\nthey can be dropped from $\\as$, thus expanding $\\as$ to a SAT cube $\\as^+$.\nThe generalized cube $\\as^+$ is called a \\textit{minimum satisfying assignment} if the number of literals taken from $\\as$ is minimized.\nThe process of finding a minimum satisfying assignment is also known as finding a \\textit{minimum hitting set}.\n\n\\subsubsection{Minimum conflicting assignment}\nGiven an UNSAT minterm $\\as$ of a formula $\\pf$,\nmodern SAT solvers, e.g., \\minisat~\\cite{Een2003Solver,Een2003Incremental},\nare able to compute a conjunction of literals from $\\as$ that is responsible for the conflict.\nIf some literals in $\\as$ are irrelevant to the conflict,\nthey are dropped from $\\as$,\nthus expanding $\\as$ to an UNSAT cube $\\as^+$.\nIf the number of literals in an UNSAT cube $\\as^+$ is minimized,\n$\\as^+$ is called a \\textit{minimum conflicting assignment}.\nThe process of finding a minimum conflicting assignment is also known as finding a \\textit{minimum UNSAT core}.", "meta": {"hexsha": "f6811737a75cd8fa09f5b80a5999d56b2e1f8f78", "size": 2656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/random-exist-ssat/preliminaries.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/random-exist-ssat/preliminaries.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/random-exist-ssat/preliminaries.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": 61.7674418605, "max_line_length": 202, "alphanum_fraction": 0.7085843373, "num_tokens": 791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6039653056984812}}
{"text": "\\chapter{Predicates and Connectives}\n\\label{chapter:predicates}\n\\marginurl{%\n  Connectives and Propositions:\\\\\\noindent\n  Introduction to Mathematical Reasoning \\#5\n}{youtu.be/0unvlq2OTaE}\n\\section{Propositions and Predicates}\nIn the previous chapters we used the word ``statement'' without any even\nrelatively formal definition of what it means. In this chapter we are going to\ngive a semi-formal definition and discuss how to create complicated statements\nfrom simple statements.\n\nIt is difficult to give a formal definition of what a mathematical statement is,\nhence, we are not going to do it; the goal of this section is to\nenable the reader to recognize mathematical statements.\n\nA \\emph{proposition} or a mathematical statement is a declarative sentence\nwhich is either true or false but not both. Consider the following list of\nsentences.\n\\begin{enumerate}\n  \\item $2 \\times 2 = 4$\n  \\item $\\pi = 4$\n  \\item $n$ is even\n  \\item 32 is special\n  \\item The square of any odd number is odd.\n  \\item The sum of any even number and one is prime.\n\\end{enumerate}\nOf those, the first two are propositions; note that this says nothing about\nwhether they are true or not. Actually, the first is true and the second is\nfalse. However, the third sentence becomes a proposition only when the value\nof $n$ is fixed. The fourth is not a proposition. Finally, the last\ntwo are propositions (the fifth is true and the sixth is false).\n\nThe third statement is somewhat special, because there is a simple way to make\nit a proposition: one just needs to fix the value of the variable. Such\nsentences are called predicates and the variables that need to be specified are\ncalled free variables of these predicates.\n\nNote that the fourth sentence is also interesting, since if we define what it\nmeans to be special, the phrase becames a proposition.\nAs it is illustrated by the last two statements mathematicians tend to do such\nthings to give mathematical meanings to everyday words.\n\n\\section{Connectives}\n\nMathematicians often need to decide whether a given proposition is true or\nfalse. Many statements are complicated and constructed from simpler statements\nusing \\emph{logical connectives}. For example we may consider the following\nstatements:\n\\begin{enumerate}\n  \\item $3 > 4$ and $1 < 1$;\n  \\item $1 \\times 2 = 5$ or $6 > 1$.\n\\end{enumerate}\n\n\\paragraph{Logical connective ``OR''.}\nThe second statement is an example of usage of this connective. The statement\n``P or Q'' is true if and only if at least one of P and Q is true. We may\ndefine the connective using the truth table of it.\n\\begin{center}\n    \\begin{tabular}{l l l}\n        \\toprule\n        P & Q & P or Q \\\\\n        \\midrule\n        T & T & T \\\\\n        T & F & T \\\\\n        F & T & T \\\\\n        F & F & F \\\\\n        \\bottomrule\n  \\end{tabular}\n\\end{center}\n\nThe or connective is also called \\emph{disjunction} and the disjunction of $P$\nand $Q$ is often denoted as $P \\lor Q$.\n\n\\nomenclature[L]{$P \\lor Q$}{denotes the statement saying that at least one of\n$P$ and $Q$ is true}\n\n\\begin{warning}\n  Note that in everyday speech ``or'' is often used in the exclusive case, like\n  in the sentence ``we need to decide whether it is an insect or a spider''.\n  In this case the precise meaning of ``or'' is made clear by the context.\n  However, mathematical language should be formal, hence, we always use ``or''\n  inclusively.\n\\end{warning}\n\n\\paragraph{Logical connective ``AND''.}\nThe first statement is an example of this connective. The statement ``P and Q''\nis true if and only if both P and Q are true. We may define the\nconnective using the truth table of it.\n\\begin{center}\n  \\begin{tabular}{l l l}\n      \\toprule\n      P & Q & P and Q \\\\\n      \\midrule\n      T & T & T \\\\\n      T & F & F \\\\\n      F & T & F \\\\\n      F & F & F \\\\\n      \\bottomrule\n  \\end{tabular}\n\\end{center}\n\nThe and connective is also called \\emph{conjunction} and the conjunction of\n$P$ and $Q$ is often denoted as $P \\land Q$.\n\n\\nomenclature[L]{$P \\land Q$}{denotes the statement saying that $P$ and $Q$\nare both true}\n\n\\begin{warning}\n  Not all the properties of ``and'' from everyday speech are captured by\n  logical conjunction. For example, ``and'' sometimes implies order. For\n  example, ``They got married and had a child'' in common language means that\n  the marriage came before the child. The word ``and'' can also imply a\n  partition of a thing into parts, as ``The American flag is red, white, and\n  blue.'' Here it is not meant that the flag is at once red, white, and blue,\n  but rather that it has a part of each color.\n\\end{warning}\n\n\\paragraph{Logical connective ``NOT''.}\nThe last connective is called \\emph{negation} and examples of usage of it are\nthe following:\n\\begin{enumerate}\n  \\item 5 is not greater than 8;\n  \\item Does not exist an integer $n$ such that $n^2 = 2$.\n\\end{enumerate}\n\nNote that it is not straightforward where to put the negation in these\nsentences.\n\nThe negation of a statement $P$ is denoted as $\\lnot P$ (sometimes it is also\ndenoted as $\\sim P$).\n\\nomenclature[L]{$\\lnot P$}{denotes the statement saying that $P$ is false}\n\n\n\n\\begin{chapterendexercises}\n  \\exercise Construct truth tables for the statements\n    \\begin{itemize}\n      \\item not ($P$ and $Q$);\n      \\item (not $P$) or (not $Q$);\n      \\item $P$ and (not $Q$);\n      \\item (not $P$) or $Q$;\n    \\end{itemize}\n  \\exercise[recommended] Consider the statement ``All gnomes like cookies''. Which of\n    the following statements is the negation of the above statement?\n    \\begin{itemize}\n      \\item All gnomes hate cookies.\n      \\item All gnomes do not like cookies.\n      \\item Some gnomes do not like cookies.\n      \\item Some gnomes hate cookies.\n      \\item All creatures who like cookies are gnomes.\n      \\item All creatures who do not like cookies are not gnomes.\n    \\end{itemize}\n  \\exercise Using truth tables show that the following statements are\n    equivalent:\n    \\begin{itemize}\n      \\item $P \\implies Q$,\n      \\item $(P \\lor Q) \\iff Q$\n        ($A \\iff B$ is the same as $(A \\implies B) \\land (B \\implies A)$),\n      \\item $(P \\land Q) \\iff P$\n    \\end{itemize}\n  \\exercise Prove that three connectives ``or'', ``and'', and ``not'' can\n    all be written in terms of the single connective ``notand'' where ``$P$\n    notand $Q$'' is interpreted as ``not ($P$ and $Q$)'' (this operation is\n    also known as Sheffer stroke or NAND).\n  \\exercise Show the same statement about the connective ``notor'' where\n    ``$P$ notor $Q$'' is interpreted as ``not ($P$ or $Q$)'' (this operation is\n    also known as Peirce's arrow or NOR).\n\\end{chapterendexercises}\n", "meta": {"hexsha": "5621ab0ba583956ae7802b3b82e00b4ebe327513", "size": 6609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_5_predicates_and_connectives.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_5_predicates_and_connectives.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_5_predicates_and_connectives.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.8764705882, "max_line_length": 85, "alphanum_fraction": 0.7037373279, "num_tokens": 1791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.7853085733507947, "lm_q1q2_score": 0.6039653037663045}}
{"text": "\\problemname{Beautiful Primes}\n\n\\noindent John Nash is a talented mathematician at Princeton. Due to his prolific contributions in academia, he was even recruited to the Pentagon at a young age to crack enemy encrypted telecommunication. In his first task, John was able to decipher the code mentally, much to the astonishment of other decrypters. In his everyday life, he is constantly looking for patterns in magazines to newspapers to keep his senses sharp.\\\\\n\nRecently, he has been cracking away at a cryptography problem that involves prime numbers. Given a positive integer $N$, the puzzle needs him to produce a ``beautiful\" list of $N$ primes. A list of $N$ primes numbers is considered beautiful if each prime is at most $1\\,000\\,000$, and their product has exactly $N$ digits.\\\\\n\nFor example, if $N = 1$, then the list $[5]$ is beautiful because its length is $1$, and its product $5$ has $1$ digit.\\\\\n\nFor $N = 2$, the list $[3, 7]$ is beautiful because its product $3 \\times 7 = 21$ has the required digit count of $2$.\\\\\n\nFor $N = 3$, the list $[5, 5, 7]$ is beautiful because its product $5 \\times 5 \\times 7 = 175$ has the required digit count of $3$.\\\\\n\nJohn wants to practice his mental math and impress his colleagues. He needs you to write a program that helps him practice this interesting task. John Nash has a beautiful mind, so won't you help him find some beautiful primes?\n\n\\section*{Input}\nThe first line of input consists of a single integer $T$ ($1 \\leq T \\leq 50$), the number of test cases.\\\\\n$T$ lines follow, each of which is a test case consisting of a single integer $N$ ($1 \\leq N \\leq 1\\,000$).\n\n\\section*{Output}\nFor each test case, print, on a separate line, a list of $N$ space-delimited beautiful primes that are each no greater than $1\\,000\\,000$. The primes do not have to be distinct, and may be printed in any order. If there are multiple answers, you may print any of them.\\\\\n", "meta": {"hexsha": "735251f70f0379a58a1503f6a38d0557fd20512a", "size": 1921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "beautifulprimes/problem_statement/problem.en.tex", "max_stars_repo_name": "csecutsc/utscode2", "max_stars_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-30T15:06:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T06:50:25.000Z", "max_issues_repo_path": "beautifulprimes/problem_statement/problem.en.tex", "max_issues_repo_name": "csecutsc/utscode2", "max_issues_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "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": "beautifulprimes/problem_statement/problem.en.tex", "max_forks_repo_name": "csecutsc/utscode2", "max_forks_repo_head_hexsha": "469367528cc5697e0c5c0ccee28420591335d899", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T04:10:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T04:10:51.000Z", "avg_line_length": 91.4761904762, "max_line_length": 430, "alphanum_fraction": 0.7407600208, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6039653012499216}}
{"text": "\\documentclass[notitlepage]{simple}\n\n\\title{Algebraic Properties of the Gaussian Integers}\n\\author{Matt McCarthy}\n\\date{April 2016}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{thm*}\n\tThe Gaussian Integers, denoted $\\ZZ(i)$, form a Euclidean domain.\n\\end{thm*}\n\n\\section{Background}\n\nBefore we can talk about Euclidean domains, we first need to introduce the definition of a ring.\n\n\\begin{definition}[Ring]\n\tLet $R$ be a nonempty set, and let $+:R^2\\rightarrow R$ and $\\cdot:R^2\\rightarrow R$ be binary operations on $R$.\n\tThen we say $R$ is a \\textit{ring} if all of the following hold.\n\t\\begin{enumerate}\n\t\t\\item The structure $(R,+)$ is an abelian group whose identity we denote as 0.\n\t\t\\item For any $a,b,c\\in R$, $a(bc)=(ab)c$ (Multiplicative Associativity).\n\t\t\\item For any $a,b,c\\in R$, $a(b+c)=ab+ac$ (Left Distributivity).\n\t\t\\item For any $a,b,c\\in R$, $(a+b)c=ac+bc$ (Right Distributivity).\n\t\\end{enumerate}\n\tIf one says $R$ is a ring, we imply that there exists some addition and some multiplication operators which we denote as $a+b$ and $ab$ respectively.\n\\end{definition}\n\n\\begin{definition}[Ring with Unity]\n\tLet $R$ be a ring.\n\tThen $R$ is a \\textit{ring with unity} if there exists a $1\\in R$ such that for any $a\\in R$, $a\\cdot 1 = 1\\cdot a = a$.\n\tIf such a $1$ exists, we call it the \\textit{unity}.\n\\end{definition}\n\n\\begin{definition}[Commutative Ring]\n\tLet $R$ be a ring.\n\tThen we say $R$ is \\textit{commutative} if for any $a,b\\in R$, $ab=ba$.\n\\end{definition}\n\nThe integers, denoted $\\ZZ$, are a commutative ring with unity because they satisfy all of the above properties under the usual addition and multiplication.\nAnother helpful definition is that of a subring.\n\n\\begin{definition}[Subring]\n\tLet $R$ be a ring and let $S$ be a nonempty subset of $R$.\n\tThen $S$ is a \\textit{subring} of $R$ if $(S,+,\\cdot)$ is also a ring.\n\\end{definition}\n\nFurthermore, we have a test which makes it easier to show a subset is a subring.\n\n\\begin{proposition}[Subring Test]\n\tLet $R$ be a ring, and let $S\\subseteq R$ be nonempty.\n\tThen $S$ is a subring of $R$ if and only if for any $a,b\\in S$, $a-b$ and $ab$ are also in $S$.\n\\end{proposition}\n\nNow we need a few more definitions and then we can proceed to proving the theorem.\nFirst, we need to define what a zero divisor is.\n\n\\begin{definition}[Zero Divisor]\n\tLet $R$ be a ring and let $a\\in R$ be nonzero.\n\tWe say $a$ is a \\textit{zero divisor} if there exists a nonzero $b\\in R$ such that $ab = 0$.\n\\end{definition}\n\nAn example of a zero divisor is 2 in $\\ZZ_6$, since $2\\cdot 3\\equiv 0\\mod{6}$.\nAn important property of zero divisors is that they cannot be inverted.\nThus, if our ring has no zero divisors it is fairly nice; in fact it is nice enough that we name it.\n\n\\begin{definition}[Integral Domain]\n\tLet $R$ be a commutative ring with unity.\n\tThen we say $R$ is an \\textit{integral domain} if $R$ has no zero-divisors.\n\\end{definition}\n\nWe call these structures integral domains, because they behave like the integers.\nThat is there is a unity, multiplication commutes, and we can multiply any nonzero elements together to get another nonzero element.\n\nNext we will define one of the strongest structures in algebra, the field.\n\n\\begin{definition}[Field]\n\tLet $\\FF$ be a commutative ring with unity.\n\tThen $\\FF$ is a \\textit{field}, if for each $a\\in\\FF\\setminus\\set{0}$, there exists a $a^{-1}\\in\\FF$ such that $aa^{-1}=1$.\n\\end{definition}\n\nOne field that we will use in our proof is the complex numbers, denoted $\\CC$.\nLastly, we define Euclidean domains.\n\n\\begin{definition}[Euclidean Domain]\n\tLet $R$ be an integral domain.\n\tThen we say $R$ is a \\textit{Euclidean domain} if there exists a function $d:R\\rightarrow(\\ZZ^+\\cup\\set{0})$ such that\n\t\\begin{enumerate}\n\t\t\\item for any $x,y\\in R\\setminus\\set{0}$, $d(xy)\\geq d(x)$,\n\t\t\\item and there exist $q,r\\in R$ where $x=yq+r$ with $r=0$ or $d(r) < d(y)$.\n\t\\end{enumerate}\n\tAny such $d$ is called a \\textit{measure}.\n\\end{definition}\nEssentially, Euclidean domains are rings where the division algorithm works.\n\n\\section{Solution}\n\nTo start, we define $\\ZZ(i)$, the Gaussian Integers.\n\n\\begin{definition}[Gaussian Integers]\n\tThe \\textit{Gaussian Integers} are\n\t\\[\n\t\t\\ZZ(i)=\\set{a+bi|a,b\\in\\ZZ}.\n\t\\]\n\\end{definition}\n\nWe first need to show that $\\ZZ(i)$ is an integral domain.\n\n\\begin{lemma}\n\t$\\ZZ(i)$ is an integral domain under standard complex addition and multiplication.\n\\end{lemma}\n\\begin{proof}\n\tWe know that $\\CC$ is a field, therefore it is a commutative ring with identity and no zero divisors.\n\tThus, it suffices to show that $\\ZZ(i)$ is a subring of $\\CC$ that contains 1.\n\tSince $1,0\\in\\ZZ$, $1+0i=1\\in\\ZZ(i)$.\n\tThus $\\ZZ(i)$ is nonempty since it contains the unity.\n\tWe now need to show that for any $z=a+bi,w=c+di\\in\\ZZ(i)$, $z-w,zw\\in\\ZZ(i)$.\n\tWe know that $z-w=(a-c)+(b-d)i$ and $zw=(ac-bd)+(ad+bc)i$.\n\tSince $\\ZZ$ is a ring, $a-c,b-d,ac-bd$, and $ad+bc$ are in $\\ZZ$ by closure.\n\tTherefore, $z-w,zw\\in\\ZZ(i)$.\n\tThus $\\ZZ(i)$ is a commutative ring with unity that has no zero divisors.\n\tHence, $\\ZZ(i)$ is an integral domain.\n\\end{proof}\n\nSince $\\ZZ(i)$ is an integral domain, we can embed it in what we call the \\textit{field of fractions}, otherwise known as $\\QQ(i)$.\nWe will assume that $\\QQ(i)=\\set{a+bi|a,b\\in\\QQ}$, which is true but requires a significant amount of background to show.\nThe proof of the following theorem hinges upon the previous assumption.\n\n\\begin{thm}\n\t$\\ZZ(i)$ is a Euclidean domain.\n\\end{thm}\n\\begin{proof}\n\tIn order to show that an integral domain is a Euclidean domain, we need to propose a measure.\n\tWe claim that $d:\\ZZ(i)\\rightarrow\\ZZ^{+}\\cup\\set{0}$ given by $d(z)=|z|^2$ is such a measure.\n\n\tTo start we need to show that for any $z,w\\in\\ZZ(i)\\setminus\\set{0}$, $d(zw)\\geq d(z)$.\n\tWe know that $d(zw)=|zw|^2$.\n\tHowever, from Euler's formula, we know that $|zw|=|z||w|$.\n\tTherefore, $d(zw)=|z|^2|w|^2$.\n\tFurthermore, by Euler's formula, the only element with modulus less than 1 in $\\ZZ(i)$ is 0.\n\tTherefore, $d(zw)\\geq |z|^2=d(z)$.\n\n\tNext, we need to find $q,r\\in\\ZZ(i)$ such that $z=wq+r$ where $r=0$ or $d(r) < d(w)$.\n\tTo do so, we embed $\\ZZ(i)$ is $\\QQ(i)$ and consider $z/w$.\n\tWe know $z/w=\\alpha+\\beta i$ with $\\alpha,\\beta\\in\\QQ$.\n\tLet $\\alpha',\\beta'$ be the nearest integers to $\\alpha$ and $\\beta$ respectively.\n\tThen $|\\alpha-\\alpha'|\\leq 1/2$ and $|\\beta-\\beta'|\\leq 1/2$.\n\tFurthermore,\n\t\\[\n\t\t\\frac{z}{w}=\\alpha-\\alpha'+\\alpha' + (\\beta-\\beta'+\\beta')i=(\\alpha'+\\beta' i)+((\\alpha-\\alpha')+(\\beta-\\beta')i).\n\t\\]\n\tSolving for $z$ yields,\n\t\\[\n\t\tz=(\\alpha'+\\beta' i)w+((\\alpha-\\alpha')+(\\beta-\\beta')i)w.\n\t\\]\n\tSince $\\alpha',\\beta'\\in\\ZZ$, we know that $\\alpha'+\\beta' i\\in\\ZZ(i)$.\n\tThus,\n\t\\[\n\t\t((\\alpha-\\alpha')+(\\beta-\\beta')i)w=z-(\\alpha'+\\beta' i)w\\in\\ZZ(i)\n\t\\]\n\tby closure.\n\tTake $q=\\alpha'+\\beta' i$ and $r=((\\alpha-\\alpha')+(\\beta-\\beta')i)w$.\n\tIf $r=0$, we are done, otherwise consider $d(r)$.\n\t\\[\n\t\td(r)=|(\\alpha-\\alpha')+(\\beta-\\beta')i|^2d(w)=(|\\alpha-\\alpha'|^2+|\\beta-\\beta'|^2)d(w)\n\t\\]\n\tHowever, we know that $|\\alpha-\\alpha'|\\leq 1/2$ and $|\\beta-\\beta'|\\leq 1/2$.\n\tTherefore,\n\t\\[\n\t\td(r)\\leq \\paren{\\frac{1}{4}+\\frac{1}{4}}d(w)=\\frac{1}{2}d(w) < d(w)\n\t\\]\n\tand $d$ is a measure on $\\ZZ(i)$.\n\tThus $\\ZZ(i)$ is Euclidean.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "05e32f6f076f8b642e9a1e6d10b86e4d179e366c", "size": 7243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-spring/gaussian-integral-domain/gaussian-integral-domain.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-spring/gaussian-integral-domain/gaussian-integral-domain.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-spring/gaussian-integral-domain/gaussian-integral-domain.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": 40.4636871508, "max_line_length": 156, "alphanum_fraction": 0.6767913848, "num_tokens": 2441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321964553658, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.603949934968104}}
{"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 5}\n\nSuppose you are given a relation with four attributes ABCD and the following set of FDs: $\\{AB\\rightarrow C, BC\\rightarrow D\\}$.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Identify the candidate key(s) for $R$.\n\\item Determine if R is in BCNF, 3NF, or neither of them.\nIf it is not in BCNF, decompose it into a set of BCNF relations.\n\\end{enumerate}\n\n\\textbf{Solution:}\n\nTable \\ref{table1} is constructed to find candidate key(s) for $R$.\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{Closure of different combinations of relation $R$}\\label{table1}\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{table}\n\nAs shown in Table \\ref{table1}(a), set of minimal candidate keys are $\\{AB\\}$.\nTo check if $R$ is in \\textit{BCNF} or \\textit{3NF}, closure of functional dependencies are constructed in Equation \\ref{equation1}.\n\n\\begin{equation}\\label{equation1}\nF^+ = \\{AB\\rightarrow C, BC\\rightarrow D\\} \\cup \\{AB\\rightarrow D\\}\n\\end{equation}\n\nEach functional dependency (FD) is now verified to conform to $BCNF$ and $3NF$ form, as given in Table \\ref{table2}.\n\n\\begin{table}[H]\n\\centering\\caption{Conformance verification of relation $R$}\\label{table2}\n\\begin{tabular}{|r||c|c|c|}\n\\hline\n & $AB\\rightarrow C$ & $BC\\rightarrow D$ & $AB \\rightarrow D$\\\\\n\\hline\n$BCNF$ & \\checkmark & $\\times$ & \\checkmark \\\\\n$3NF$ & \\checkmark & $\\times$ & \\checkmark \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nAs 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.\n", "meta": {"hexsha": "14dcee0da41ec0efb409c53b9704f82e5de536fc", "size": 2466, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/src/tex/f01/f01q05.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/f01/f01q05.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/f01/f01q05.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": 39.1428571429, "max_line_length": 200, "alphanum_fraction": 0.6670721817, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.6039396170669298}}
{"text": "\\subsection{Test 3}\r\n\r\n\\begin{enumerate}[label=\\arabic*.]\r\n\t\\item\r\n\t\tWrite the integral definition of the Laplace transform.\r\n\t\\item \r\n\t\tFind the Laplace transform of the following functions. Be sure to give the domains. Use the integral definition for (a) and (e). Be sure to state the domain of the transformed function and any rules of Laplace transforms you use.\r\n\t\t\\begin{enumerate}[label = (\\alph*)]\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tf(x) = e^x\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\th(t) = \\sin{t} + 2\\cos{3t}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tj(t) = e^{3t}\\left(t^2 + 3t + 2\\right)\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tb(t) = \\dd{}{t}{(e^{3t+1} + e^{1-t})}\r\n\t\t\t\t\\end{equation*}\r\n%\t\t\t\\item\r\n%\t\t\t\t\\begin{equation*}\r\n%\t\t\t\t\t\\delta(x) = \\lim\\limits_{a \\to 0}{\\frac{1}{\\abs{x}\\sqrt{\\pi}}e^{(x/a)^2}}\r\n%\t\t\t\t\\end{equation*}\r\n\t\t\\end{enumerate}\r\n\t\\item\r\n\t\tFind the inverse Laplace transform of the following functions.\r\n\t\t\\begin{enumerate}[label=(\\alph*)]\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tF(s) = \\frac{1}{1+s}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tH(s) = \\frac{s^2+2s+1}{s^3 - 4s^2 + 5s - 2}\t\t\t\t\t\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tJ(s) = \\frac{s-4}{s^2 -8s + 32}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tA(s) = \\frac{768}{(2s+3)^5}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\\end{enumerate}\r\n\t\\item\r\n\t\tFind the general solution to the following differential equation using one of the methods you learned previously and by Laplace transform. Show that the two methods give the same answer.\r\n\t\t\\begin{equation*}\r\n\t\t\t2y'' - 3y' + y = 10\\sin{x}\r\n\t\t\\end{equation*}\r\n\t\\item\r\n\t\tSolve the following IVP by Laplace transform.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{cases}\r\n\t\t\t\t2y'' + 4y' - 6y = te^{-3t} \\\\\r\n\t\t\t\ty'(0) = 0 \\\\\r\n\t\t\t\ty(0) = 1\r\n\t\t\t\\end{cases}\r\n\t\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "f20614c93ea48445a0b9446faf3a852ac773efff", "size": 1901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/additionalResources/tests/test3.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/additionalResources/tests/test3.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/additionalResources/tests/test3.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": 29.703125, "max_line_length": 232, "alphanum_fraction": 0.5802209363, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6037866683182789}}
{"text": "% Copyright (C) He Guanyuming 2020\n% The file is licensed under the MIT license.\n\n\\section{Integers and Rationals}\nNow we are going to extend natural numbers to integers and rationals.\n\n\\subsection{The Integers}\n\n\\declareexercise{4.1.1}\n\\begin{proof}\nIt is immediately given by the fact that \n\\[\na+b = a+b \\equiv a -- b = a -- b\n\\]\n\\end{proof}\n\n\\paragraph{Lemma 4.1.3}\n\\[\n(m--0)+(n--0) = (m+n)--0\n\\]\n\\[\n(m--0) \\times (n--0) = (mn) -- 0\n\\]\nensures that the definition $m--0:=m$ is consistent with addition and multiplication.\n\n\\declareexercise{4.1.2}\n\\begin{proof}\n\\[\na--b = a'--b' \\equiv a=b \\wedge a'=b'\n\\]\nThen, \n\\[\n(b--a) = (b'--a') \\equiv -(a--b) = -(a'--b')\n\\]\n\\end{proof}\n\n\\declareexercise{4.1.3}\n\\begin{proof}\n\\begin{align*}\n-1 \\times a \n&= (0 -- 1) \\times (a -- 0) \\\\\n&= (0\\times a + 1 \\times 0) -- (0 \\times 0 + 1 \\times a) \\\\\n&= 0 -- a \\\\\n&= -a\n\\end{align*}\n\\end{proof}\n\n\\declareexercise{4.1.4}\n\\begin{proof}\nLet $x=(a--b),y=(c--d),z=(e--f)$.\n\n(1)\n\\begin{align*}\n(a--b) + (c--d) \n&= (a+c) -- (b+d) \\\\\n&= (c+a) -- (d+b) \\\\\n&= (c--d) + (a--b)\n\\end{align*}\n\n(2)\n\\begin{align*}\n((a--b) + (c--d)) + (e--f)\n&= ((a+c)+e) -- ((b+d)+f) \\\\\n&= (a+(c+e)) -- (b+(d+f)) \\\\\n&= (a--b) + ((c--d) + (e--f))\n\\end{align*}\n\n(3)\nFirst ,\n\\[\n(a--b) + (0--0) = (a--b)\n\\].\n\nSecond, by (1) we have $0+x=x+0$.\n\n(4)\nFirst, \n\\begin{align*}\n(a--b) + (b--a) \n&= (a+b) -- (a+b) \\\\\n&= 0 -- 0 \\tag{$a+b+0=a+b+0$}\n\\end{align*}\n\nSecond, by (1) we have $x+(-x) = (-x) + x$.\n\n(5)\n\\begin{align*}\n(a--b)(c--d)\n&= (ac + bd) -- (ad + bc) \\\\\n&= (ca + db) -- (cb + da) \\\\\n&= (c--d)(a--b)\n\\end{align*}\n\n(6)\nThe book proved this.\n\n(7)\nFirst,\n\\[\n(1--0)(a--b) = (1a + 0b) -- (1b+0a) = (a--b)\n\\]\n\nSecond, by (5) we have $1x=x1$.\n\n(8)\n\\begin{align*}\n&(a--b)((c--d)+(e--f)) \\\\\n&= (a--b)((c+e)--(d+f)) \\\\\n&= (a(c+e) + b(d+f)) -- (a(d+f) + b(c+e)) \\\\\n&= ((ac + bd)+(ae + bf)) -- ((ad + bc)+(af + be)) \\\\\n&= (ac+bd)--(ad+bc) + (ae+bf)--(af+be) \\\\\n&= (a--b)(c--d) + (a--b)(e--f)\n\\end{align*}\n\n(9)\nThis can be easily concluded from (5) and (8).\n\\end{proof}\n\n\\declareexercise{4.1.5}\n\\begin{proof}\nWe need to show that \n\\[\na \\neq 0 \\wedge b \\neq 0 \\Longrightarrow ab \\neq 0\n\\]\n\nSince $a,b$ are not 0, they can be either positive or negative. If they are both positive, the case is \nalready proven.\n\nWhen at least one of them is negative, we can divide the $-1$ from the negative ones. That is, if $a=-m$, \nwhere $m$ is positive, then we substitute $a$ with $-1 \\times m$. Then we may get $ab$ in either the form \n$(-1)(-1) mn$ or $(-1) mn$, where the former is a positive number because $(-1)(-1) =1$ and the latter is \nnegative.\n\\end{proof}\n\n\\declareexercise{4.1.6}\n\\begin{proof}\nWe check the value of $ac-bc$. We know that $ac=bc$, so $ac - bc = 0 - 0 = 0$. According to (9) in \nProposition 4.1.6, \n\\[\nac - bc = ac+(-b)c = (a+(-b))c = 0\n\\]\n\nAs stated by Proposition 4.1.8, since that $c \\neq 0$, $a+(-b) = 0$, which means $a-b=0$. Then we have \n$a=b$.\n\\end{proof}\n\n\\declareexercise{4.1.7}\nIn the following contents, $p$ stands for a positive natural number, $n$ stands for a natural number.\n\n\\begin{proof}\n(a)\n\\begin{align*}\na>b \n&\\equiv a = b+p \\\\\n&\\equiv a+(-b) = b + (-b) + p  \\tag{See the following explanation} \\\\\n&\\equiv a-b = p\n\\end{align*}\nWe now explain why $a = b+p \\equiv a+(-b) = b + (-b) + p$. Using the substitution law and the \ncommutativity of addition, it is clear to see that $a = b+p \\Longrightarrow a+(-b) = b + (-b) + p$. We now \nshow the cancellation law of addition, that is,\n\\begin{lem}\n\\[\na+c = b+c \\Longrightarrow a = b\n\\]\n\\end{lem}\n\\begin{proof}\n\\begin{align*}\na+c=b+c\n&\\Longrightarrow a+c+(-c) = b+c+(-c) \\\\\n&\\Longrightarrow a+(c+(-c)) = b + (c+(-c)) \\\\\n&\\Longrightarrow a=b\n\\end{align*}\n\\end{proof}\n\nSo we get the inverse result: $a = b+p \\Longleftarrow a+(-b) = b + (-b) + p$.\n\nNote that by the definition of integer and what we have know now, we can conclude that \n\\begin{lem}\nFor every integer \n$i = a - b, j = c - d$, there exists exactly one integer $k$ such that $i = j+k$.\n\\end{lem}\n\n(b)\n\\begin{align*}\na>b\n&\\equiv a = b + p \\\\\n&\\Longrightarrow a+c = b+c+p \\\\\n&\\Longrightarrow a+c>b+c\n\\end{align*}\n\n(c)\n\\begin{align*}\na>b\n&\\equiv a=b+p \\\\\n&\\Longrightarrow ac = (b+p)c = bc + pc \\\\\n&\\Longrightarrow ac > bc \\tag{$pc > 0$ by Lemma 2.3.3}\n\\end{align*}\n\n(d)\n\\[\na>b \\equiv a = b+p\n\\]\nThen\n\\[\n-a = -(b+p) = (-1)(b+p) = -b - p\n\\]\nSo\n\\[\n-a+p=-b-p+p\n\\]\nThat is,\n\\[\n-b=-a+p \\equiv -b>-a\n\\]\n\n(e)\nLet\n\\[\na = b+p_1,b=c+p_2\n\\]\nThen $a = c+(p_1+p_2)$. Obviously $p_1+p_2$ is positive, so $a>c$.\n\nNote that $-a,-b$ are also integers, and plus that $-(-a)=a$, so we can give a stronger conclusion:\n\\[\na>b \\equiv -a<-b\n\\]\n\n(f)\nIf $a,b$ are all natural numbers, the statement was proven before. \n\nIf one of them (say $a$) is negative, \nthe other ($b$) is a natural number, then $a=-n$, and we know that $b>0$ and \n$0 = a+n \\Longrightarrow 0 >-a$, so by (e) we have $b>a$.\n\nIf they are both negative, then their negations satisfy the statement. Then\n\\[\n-a<-b \\equiv a>b, -a=-b \\equiv a=b, -a>-b \\equiv a<b\n\\].\n\\end{proof}\n\n\\declareexercise{4.1.8}\nAn example: $P(i): i>=0$. It is obvious that $P(0)$ and $P(i) \\Longrightarrow P(i+1)$ is true. But for any  \nnegative integer $n$, $P(n)$ is not true.\n\nWe additionally prove one more property:\n\\begin{lem}\nFor integers $a,b$,\n\\[\na-b=0\\Longrightarrow a=b\n\\]\n\\end{lem}\n\\begin{proof}\nWe can add $b$ to both side to obtain $a=b$.\n\\end{proof}\n\n\\subsection{The Rationals}\n\\declareexercise{4.2.1}\n\\begin{proof}\nReflectivity:\n\\[\na//b = a//b \\equiv ab=ab\n\\] \n\nBeing Symmetric:\n\\begin{align*}\na//b = c//d \n&\\equiv ad = bc \\\\\n&\\equiv cb = da \\\\\n&\\equiv c//d = a//d\n\\end{align*}\n\nTransitivity:\n\\[\na//b = c//d \\equiv ad = bc\n\\]\n\\[\nc//d = e//f \\equiv cf = de\n\\]\nThus,\n\\[\n(ad)(cf) = (bc)(de)\n\\]\nWe then have\n\\[\nafcd = becd\n\\]\nWe can cancel $d$ since $d \\neq 0$ to obtain $afc=bec$. If $a=0$, we can conclude that $c,e$ also must be \n$0$. Under this occasion, $af=be$ is also true because they all equal to $0$. \n\\end{proof}\n\n\\paragraph{Definition 4.2.2}\nIt is useful to prove that \n\\begin{lem} \\label{lem4.2.3}\n\\[\n(-a)//b = a//(-b)\n\\]\n,\n\\[\na//b = (-a)//(-b)\n\\]\n\\end{lem}\n\\begin{proof}\nThe first is immediately given since $(-a)(-b) = ab$. The latter is proven as $a(-b) = b(-a) = -ab$.\n\\end{proof}\n\nWe may notice that subtraction is not mentioned here. This is because that we can get $a-b$ by adding $a$ \nand $-b$, where addition $+$ and negation $-$ are mentioned.\n\n\\declareexercise{4.2.2}\n\\begin{proof}\n(1) is deduced in the book.\n\n(2)\nI don't quiet understand why Tao used this $*$ sign instead of $\\times$. I know it is a new definition, \nbut the $\\times$ sign is undefined for rationals (except for integers, but for which we can verify that \nthe two definitions are the same). We will use the $\\times $ sign or just leave it off here.\n\n\\[\n(a'//b')(c//d) \\equiv a'd = b'c \\equiv ad=bc \\equiv (a//b)(c//d)\n\\]\nSimilarly we can verify this for $c'//d'$.\n\n(3)\n\\[\n-ab'=-a'b \\equiv (-a)//b = (-a')//b'\n\\]\n\\end{proof}\n\nFor the sake of simplification, we hereby introduce some useful lemmas:\n\\begin{lem} \\label{lem4.2.1}\n\\[\nb=d\\neq 0 \\Longrightarrow (a//b = c//d \\equiv a=c)\n\\]\n\\end{lem}\n\\begin{proof}\nAssume that $b=d\\neq 0$.\n\nOn one hand, if $a//b=c//d$, then $ad=bc$. Since that $b=d \\neq 0$, we can cancel them to obtain $a=c$.\n\nOn the other hand, if $a=c$, then if we multiply them by the same integer (namely $b=d$), and the \nresults are still equal ($ad=bc$). So $a//b=c//d$.\n\\end{proof}\n\\begin{lem} \\label{lem4.2.2}\n\\[\nc \\neq 0 \\Longrightarrow a//b=ac//bc\n\\]\n\\end{lem}\n\\begin{proof}\nAssume that $c\\neq 0$.\n\nFirst we know that $ab=ab$. Then we can further obtain $abc=abc$, which \nmeans $a//b=ac//bc$.\n\\end{proof}\n\n\\declareexercise{4.2.3}\n\\begin{proof}\n(1)\nWe have\n\\[\na//b + c//d = (ad+bc)//(bd)\n\\]\n\\[\nc//d + a//b = (cb+da)//(db)\n\\]\nIt is easy to see that they are equal.\n\n(2)\nIt is proven in the book.\n\n(3)\nWe just deduce $x+0=x$ here, for we have $0+x=x+0$ according to (1).\n\\[\na//b + 0//1 = (a1+b0)//(b1) = a//b\n\\]\n\n(4)\nWe only prove $x+(-x)=0$ here, for we have $x+(-x)=(-x)+x$ according to (1).\n\\[\na//b+(-a)//b= (ab-ab)//bb = 0//b^2=0\n\\]\n\n(5)\n\\begin{align*}\na//b \\times c//d\n&= ac//bd \\\\\n&= ca//db \\\\\n&= c//d \\times a//b\n\\end{align*}\n\n(6)\n\\begin{align*}\n&(a//b \\times c//d) \\times e//f \\\\\n&= ac//bd \\times e//f \\\\\n&= ace//bdf \\\\\n&= a//b \\times ce//df \\\\\n&= a//b \\times (c//d \\times e//f)\n\\end{align*}\n\n(7)\nWe only prove $x1=x$ here, for we have $x1=1x$ according to (4).\n\\[\na//b \\times 1//1 = a1//b1 = a//b\n\\]\n\n(8)\n\\begin{align*}\n&a//b (c//d + e//f) \\\\\n&= a//b ((cf+ed) // (df)) \\\\\n&= a(cf+ed)//bdf \\\\\n&= ab(cf+ed) // b^2df \\tag{See Lemma \\ref{lem4.2.2}} \\\\\n&= ((ac)(bf) + (bd)(ae)) // (bd)(bf) \\\\\n&= ac//bd + ae//bf \\\\\n&= (a//b \\times c//d) + (a//b + e//f)\n\\end{align*}\n\n(9)\nThis can be deduced from (5) and (8).\n\n(10)\nWe merely conclude $xx^{-1} = 1$ here, since we have $xx^{-1} = x^{-1}x$ from (5).\n\n\\[\na//b \\times b//a  = ab//ba = (ab)1//(ab)1 = 1//1\n\\]\nThe last step is done by Lemma \\ref{lem4.2.2}.\n\\end{proof}\n\n\\declareexercise{4.2.4}\n\\begin{proof}\nFor any rational $r = a/b$, $a,b$ are integers.\nThey are either positive, $0$, or negative (except that $b$ cannot be 0). When $a,b$ are both positive, \nthen $r$ is also positive. When $a$ is positive but $b$ is negative, then let $b=-p$, where $p$ is \npositive, thus $a/b = a/(-p) = (-a)/p$ is negative. When $a=0$, $r=0$. When $a$ is negative, and $b$ is \npositive, then by definition $r$ is negative. When $a,b$ are both negative, according to Lemma \n\\ref{lem4.2.3}, $r$ is positive.\n\nTherefore, we have iterated through all possible situations and verified that there is and only is one \nstatement for a rational is true.\n\\end{proof}\n\n\\declareexercise{4.2.5}\n\\begin{proof}\nLet $x=a/b,y=c/d,z=e/f$. Before proving the following components, we will introduce some useful \npropositions here.\n\\begin{lem} \\label{lem4.2.4}\n\\begin{enumerate}\n\\item $x>0$ is logically equivalent to $x$ being positive.\n\\item $x<0$ is logically equivalent to $x$ being negative.\n\\end{enumerate}\n\\end{lem}\n\\begin{proof}\n\\[\nx-0 =x\n\\]\nis itself, so whether $x$ is positive or negative, the same is $x-0$, then we can deduce $x>0$ or $x<0$, \nand vice versa.\n\\end{proof}\n\nWe can now use simplified notation $x>0$ to express the same meaning: $x$ is positive. \n\n(a)\nWe check the value of \n\\[\n\\delta = x-y = a/b +(-c)/d = (ad-bc)/bd\n\\]\n$\\delta$ is also a rational number. According to the previous exercise, it is either positive, negative, \nor $0$. So $x$ either $>y$, $<y$, or $=y$ (We haven't yet proven $x-y=0 \\Longrightarrow x = y$. Let's \nprove it now. We can add $y$ to both side of $x-y=0$ to obtain the result).\n\n(b)\nAccording to Lemma \\ref{lem4.2.4}, $x<y \\Longrightarrow x-y<0$. Then we multiply $-1/1$ with $x-y$ to \nobtain (It is easy to see that for rational number $r$, $-1r = -r$ and $-(-r)=r$)\n\\[\n-1/1 \\times (x + (-y)) = -x + -(-y) = y - x\n\\]\nSince $x-y$ is negative, and the negation of a positive number is negative, so the negation of $x-y$, \n$y-x$, is positive, which means that $y>x$.\n\n(c)\nBy the hypothesis, $x-y<0 \\wedge y-z<0$. We are now proving that $i,j<0 \\Longrightarrow i + j <0$. We can \nwrite $i,j$ as $o/p,q/s$ respectively. Let $p,s>0$, then $o,q<0$. Then $o/p+q/s = (os+pq)/ps$. We know \nthat $os,pq<0$ (Write a negative integer as a negation of a positive integer to see that the product of a \npositive and a negative is also negative). \n\nNow we show that for two positive integers, their sum is still \npositive. Integers who are positive are also natural number, and their sum remains a natural number. So \nthe sum itself equals to $0$ plus itself, which means it is positive. The negation of this sum, which is \nalso $-m+(-n)$, is thus negative. Since that $-m,-n$ can present any negative integer, the fact means that \nthe sum of two negative integers remains a negative integer.\n\nSo $os+pq<0$. But $ps>0$, so $i+j<0$. Thus, $(x-y) + (y-z) = x-z<0$, which means $x<z$.\n\n(d)\n\\begin{align*}\nx+z-(y+z) \n&= x+z + (-)(y+z) \\\\\n&= x+z + (-1)(y+z) \\\\\n&= x+z -z - y \\\\\n&= x-y <0\n\\end{align*}\n\n(e)\nIt is easy to verify that the product of two positive rationals is still positive (Writing them as \n$a/b,c/d$, where $a,b,c,d>0$, then $ac/bd$ also $>0$). Then $xz-yz=z(x-y)$, which is the product of a \npositive number and a negative number, and is thus a negative number.\n\\end{proof}\n\n\\declareexercise{4.2.6}\n\\begin{proof}\nAccording to (e) of Proposition 4.2.9, we need only to show that $x<y \\Longrightarrow -x>-y$. Then we can \nmultiply $xz>yz$ with $-1$ to obtain what we want.\n\nWe know that the negation operation will turn a positive into negative and vice versa. Now we have \n$x-y<0$, so the negation $-(x-y) = -x+y = -x - (-y)>0$, which means that $-x>-y$.\n\\end{proof}\n\nThere are still many properties about rationals that we use for granted (e.g. $x^-1$ has the same sign as \n$x$; the two definitions of order are the same, that is, $x-y>0 \\equiv x=y+p \\equiv x>y$, where $p>0$). \nAlthough they need to be proven prior to being used, we can not cover all of them here. We will \nprove some of them in the future only if they are used. Also, most of them are not hard to prove. We need \nnot to worry.\n\nWe will prove some important ones here:\n\\begin{prop} \\label{prop.different.def.of.order}\nFor rational numbers $x,y,p>0$\n\\[\nx-y>0 \\equiv x=y+p \\equiv x>y\n\\]\n\\end{prop}\n\\begin{proof}\n$x-y>0 \\equiv x>y$ is the definition of order. We merely need to prove $x-y>0 \\equiv x=y+p$ here.\n\nOn one hand, if $x-y>0$, then $p$ is not others, but the very number $x-y$.\n\nOn the other hand, if there exists a $p>0$ such that $x=y+p$. Then add $-y$ to the both side of the \nequation, and we can get $x-y = p$, which means $x-y$ is positive. So $x-y>0$.\n\\end{proof}\n\n\\begin{prop} \\label{prop.4.2.add.ineq}\nWe can add two inequalities together. That is,\n\\[\na<b \\wedge c<d \\Longrightarrow a+c<b+d\n\\]\n\\end{prop}\n\\begin{proof}\nWe know that\n\\[\na<b \\Longrightarrow a+c<b+c \n\\]\n, and\n\\[\nc<d \\Longrightarrow b+c<d+b \n\\]\nAccording to the transitivity of order, we can derive that\n\\[\na+c<b+c<b+d\n\\]\n\\end{proof}\n\n\\begin{prop} \\label{prop.4.2.multiply.ineq}\nWe can multiply two inequalities of positives or negatives together. That is,\n\\[\na,b,c,d >0 \\wedge a<b \\wedge c<d \\Longrightarrow ac<bd\n\\]\n, and\n\\[\na,b,c,d <0 \\wedge a<b \\wedge c<d \\Longrightarrow ac>bd\n\\]\n\\end{prop}\n\\begin{proof}\nWhen they are all positive,\nwe know that\n\\[\na<b \\Longrightarrow ac<bc\n\\]\n, and\n\\[\nc<d \\Longrightarrow bc<bd\n\\]\nAccording to the transitivity of order, we can derive that\n\\[\nac<bc<bd\n\\]\n\nWhen they are all negative,\nwe know that\n\\[\na<b \\Longrightarrow ac>bc\n\\]\n, and\n\\[\nc<d \\Longrightarrow bc>bd\n\\]\nAccording to the transitivity of order, we can derive that\n\\[\nac>bc>bd\n\\]\n\\end{proof}\n\nNote that we can already add or multiply equations because of the axiom of substitution, so we can change \nthe $<$ in the inequalities to $\\leq$ in the previous two propositions whenever needed.\n\n\\subsection{Absolute Value and Exponentiation}\n\\declareexercise{4.3.1}\n\\begin{proof}\n(a)\n$x>0 \\Rightarrow |x| >0$, $x=0\\Rightarrow |x|=0$, $x<0 \\Rightarrow |x| >0$. So $|x| \\geq 0$.\n\nAnd we can see that only when $x=0$ can $|x| = 0$.\n\n(b)\nThis one is very tedious to prove. Let's enumerate all conditions:\n\\begin{enumerate}\n\\item $x,y>0$. On this occasion, \n\\[\n|x+y| = x+y = |x|+|y|\n\\]\n\n\\item At least one of them is $0$. On this occasion, let's just let $x$ be 0, the other \nsituations are similar.\n\\[\n|x+y| = |0+y| = |y| = |0| + |y| = |x| + |y|\n\\]\n\n\\item $x=y>0$. On this occasion, $|x+y| = |2x| = 2x = |x|+|x|$.\n\n\\item $x=y<0$. On this occasion, $|x+y| = |2x| = -2x = |x|+|x|$.\n\n\\item $x,y<0$. On this occasion, $|x+y| = -(x+y) = -x -y = |x| + |y|$.\n\n\\item One of them is positive, the other is negative. We specify $x>0,y<0$ here. But the other conditions \nare similar. Under this condition, we further divide the situation into three occasions:\n\\begin{itemize}\n\\item $x+y>0$ On this occasion, $|x+y| = x+y$, $|x| + |y| = x-y$. Note that $x-y = x+y +2(-y)$, where \n$2(-y) >0$, so $|x+y| < |x|+|y|$ (See Proposition \\ref{prop.different.def.of.order}).\n\\item $x+y<0$ On this occasion, $|x+y| = -x-y$, $|x|+|y|=x-y$. Note that $-x-y - (x-y) = 2(-x) < 0$, so \n$|x+y| < |x| + |y|$.\n\\item $x+y=0$ On this occasion, $|x+y| = 0 \\leq |x| + |y|$ (Recall that the sum of two positive rationals \nremains positive).\n\\end{itemize}\n\\end{enumerate}\n\nWe have iterated through all conditions.\n\n(c)\nWe shall prove that \n\\[\n-|x| \\leq x \\leq |x|\n\\]\nfirst.\n\n\\begin{enumerate}\n\\item If $x>0$, then $x=|x|>0$. And $0>-|x|$, so by the transitivity of order, $-|x| < x$.\n\\item If $x=0$, then $|x|=-|x| = x=0$.\n\\item If $x<0$, then $x=-|x|<0$ And $0<|x|$, so $x<|x|$.\n\\end{enumerate}\nThis also means that $x$ either equals to $|x|$ or $-|x|$.\n\nThen we prove that $-y \\leq x \\leq y \\equiv y \\geq |x|$.\n\nOn one hand, if $-y \\leq x \\leq y$, then when $x=|x|$, we have $|x| \\leq y$; when $x=-|x|$, we have \n$-y \\leq -|x| \\equiv y \\geq |x|$. As stated previously, we know that at least one of the two conditions \nare satisfied.\n\nOn the other hand, if $y \\geq |x|$, then $-y \\leq -|x|$. But since that $-|x| \\leq x \\leq |x|$, we can \nobtain what we want by the transitivity of order.\n\n(d)\n\\begin{enumerate}\n\\item If $x=y=0$, then $|xy| = 0 = |x||y|$.\n\\item If $x,y>0$, then $|xy| = xy = |x||y|$.\n\\item If $x,y<0$, then $xy>0$, $|xy| = xy = (-x)(-y) = |x||y|$.\n\\item If one of them is positive, and the other is negative, (say $x>0,y<0$), then \n$|xy|=-xy=x(-y)=|x||y|$. The other conditions are similar.\n\\end{enumerate}\n\nThus, $|-x| = |-1||x| = 1|x| = |x|$.\n\n(e)\nThis can be easily conclude from (a).\n\n(f)\nSince that $|-x|=|x|$, we have $|x-y| = |-(x-y)| = |y-x|$.\n\n(g)\nNote that $x-z = (x-y) = (y-z)$. Then from (b) we can deduce that $|x-z| \\leq |x-y| + |y-z|$, which is \n$d(x,z) \\leq d(x,y) + d(y,z)$.\n\\end{proof}\n\n\\declareexercise{4.3.2}\n\\begin{proof}\n(a)\nIf $x=y$, then $|x-y| = 0$. And any positive rational $\\varepsilon >0$, so $|x-y|\\leq\\varepsilon$.\n\nThe other statement is much better easier to prove after we have know the denseness of rationals. We \nessentially repeat some of the proof work that are done afterwards here.\nOn the other hand, suppose the negation, that is, $(\\forall \\varepsilon>0)(|x-y| \\leq \\varepsilon)$, but \n$x\\neq y$. Then $x-y \\neq 0$. Let $\\delta = |x-y| \\neq 0$. We know that $2^{-1} = 1/2 > 0$, so \n$\\delta / 2 > 0$. Also we have $\\delta /2 + \\delta /2 = \\delta \\Longrightarrow \\delta /2 < \\delta$. Then let \n$\\varepsilon = \\delta /2$. So we have both $|x-y| < \\delta/2$ and $|x-y| > \\delta /2$, which is impossible. \n\n(b)\nIt is immediately derived from $|x-y| = |y-x|$.\n\n(c)\n\\[\n|x-z| \\leq |x-y| + |y-z| \\leq \\varepsilon + \\delta\n\\]\n\n(d)\n\\[\n|x+z - (y+w)| = |x-y + z-w| \\leq |x-y| + |z-w| \\leq \\varepsilon + \\delta\n\\]\n\\[\n|x-z - (y-w)| = |x-y + w-z)| \\leq |x-y| + |w-z| \\leq \\varepsilon + \\delta\n\\]\n\n(e)\n\\[\n|x-y| \\leq \\varepsilon < \\varepsilon'\n\\]\n\n(f)\nFrom (c) of Proposition 4.3.3, we can derive that\n\\[\n|x-z| \\leq \\varepsilon \\equiv -\\varepsilon \\leq x-z \\leq \\varepsilon \n\\equiv z-\\varepsilon \\leq x \\leq z+ \\varepsilon\n\\]\n, and that\n\\[\n|x-y| \\leq \\varepsilon \\equiv y-\\varepsilon \\leq x \\leq y + \\varepsilon\n\\]\nThus we have\n\\[\ny-\\varepsilon \\leq x \\leq z + \\varepsilon\n\\]\n\nWe will only prove the statement when $z\\leq w \\leq y$, another one is similar. On this occasion, \n$-y \\leq -w \\leq -z$. Add this inequality to $y-\\varepsilon \\leq x \\leq z + \\varepsilon$ to obtain that \n\\[\n-\\varepsilon \\leq x-w \\leq \\varepsilon\n\\]\n\n(g)\n\\[\n|xz-yz| = |x-y||z| \\leq \\varepsilon|z|\n\\]\n\n(h)\nWe will explain why $|a| \\leq \\varepsilon \\wedge |b| \\leq \\delta$ implies \n$|a||z| + |b||x| + |a||b| \\leq \\varepsilon|z| + \\delta|x| + \\varepsilon\\delta$.\n\nFirst, multiply $|a| \\leq \\varepsilon$ with $|z|$ to obtain $|a||z| \\leq \\varepsilon |z|$. Then add both sides \nof the inequality with $|b||x| + |a||b|$ to gain \n\\[\n|a||z| + |b||x| + |a||b| \\leq \\varepsilon |z| + |b||x| + |a||b| \\tag{1}\n\\]\nSimilarly,\n\\[\n|a||z| + |b||x| + |a||b| \\leq |a||z| + \\delta |x| + |a||b| \\tag{2}\n\\]\nFinally, we can multiply $|a| \\leq \\varepsilon$ with $|b| \\leq \\delta$ as stated by Proposition \n\\ref{prop.4.2.multiply.ineq} to derive $|a||b| \\leq \\varepsilon\\delta$. So after some addition we have\n\\[\n|a||z| + |b||x| + |a||b| \\leq |a||z| + |b||x| + \\varepsilon\\delta \\tag{3}\n\\]\n\nUsing Proposition \\ref{prop.4.2.add.ineq}, we add (1),(2) and (3) together:\n\\[\n3(|a||z| + |b||x| + |a||b|) \\leq (\\varepsilon|z| + \\delta|x| + \\varepsilon\\delta) + 2(|a||z| + |b||x| + |a||b|)\n\\],\nwhich can be simplified to\n\\[\n|a||z| + |b||x| + |a||b| \\leq \\varepsilon|z| + \\delta|x| + \\varepsilon\\delta\n\\]\n\nAlso note that if we use $x-y$ as $a$, $z-w$ as $b$, and derive $|xz-yw|$ from \n\\[\nxz=(y+a)(w+b),\n\\]\nthen what we will get is that $xz,yw$ are ($\\delta|y| + \\varepsilon|w| + \\delta\\varepsilon$) close.\n\nThis consequence may seem obvious, but in fact it isn't. And should we change some variables of them, the \nresult may vary. This example tells us that we should be very cautious when dealing with inequalities. What we \nshould do is to carefully derive conclusions from what we have proven instead of taking intuitive things for \ngranted.\n\\end{proof}\n\n\\declareexercise{4.3.3}\n\\begin{proof}\n(a)\n\\begin{enumerate}\n\\item Use induction. We induct on $m$. First, $x^nx^0 = x^n1 = x^{n+0}$.\n\nSuppose that for $m$, the statement is already true. Then \n\\begin{align*}\nx^nx^{m+1} \n&= x^n(x^m\\times x)\\\\\n&= x^nx^m \\times x \\\\\n&= x^{n+m} \\times x \\tag{The induction hypothesis} \\\\\n&= x^{n+m+1}\n\\end{align*}\n\n\\item Use induction. We induct on $m$. First, $(x^n)^0 = 1 = x^{n\\times 0}$.\n\nSuppose that for $m$, the statement is already true. Then \n\\begin{align*}\n(x^n)^{m+1} \n&= (x^n)^m \\times x^n \\\\\n&= x^{mn} \\times x^n \\tag{The induction hypothesis} \\\\\n&= x^{mn + n} \\tag{By the previous statement} \\\\\n&= x^{n(m+1)}\n\\end{align*}\n\n\\item Use induction. We induct on $n$. First, $(xy)^0 = 1 = x^0y^0$.\n\nSuppose that for $m$, the statement is already true. Then \n\\begin{align*}\n(xy)^{m+1} \n&= (xy)^m \\times xy \\\\\n&= x^my^m \\times xy \\tag{The induction hypothesis} \\\\\n&= x^m \\times x \\times y^m \\times y \\\\\n&= x^{m+1} y^{m+1}\n\\end{align*}\n\\end{enumerate}\n\n(b)\nOn one hand, if $x=0$, then for $n>0$, $0^n=0$.\n\nOn the other hand, if for $n>0$, $x^n=0$, we need to prove $x=0$. We try to show that \n$x \\neq 0 \\Longrightarrow x^n \\neq 0$. Use induction. Since that $n\\neq 0$, we start from $n=1$. \n$x^1 = x^0 \\times x = x$. \n\nSuppose that for $n$, the statement is already true. Then \n\\[\nx^{n+1} = x^n \\times x,\n\\]\nwhich is the product of two positive rationals, and which is thus positive. \n\n(c)\n(1)\nUse induction: $x^0 = y^0 =1>0$.\n\nSuppose that for $n$, the statement is already true. Then we have two inequalities here:\n\\[\nx^n \\geq y^n \\geq 0\n\\]\nand\n\\[\nx \\geq y \\geq 0\n\\]\nWe can multiply the two because of Proposition \\ref{prop.4.2.multiply.ineq}. Then we have \n\\[\nx^{n+1} \\geq y^{n+1} \\geq 0\n\\]\n\nIf $n>0$, then we induct from $1$. The process resembles to what we have just done, so I don't write it here.\n\n(d)\nUse induction: $|x^0| = |1| =1 =|1|^0$. \n\nSuppose that for $n$, the statement is already true. Then \n\\[\n|x^{n+1}| = |x^n \\times x| = |x^n| |x| = |x|^n |x| = |x|^{n+1}\n\\]\n\\end{proof}\n\n\\paragraph{Definition 4.3.11}\nWe can see that there are now two versions of $x^{-1}$. Now we try to show that they express the same thing. \nWrite $x$ as $a/b$. The first version is $x^{-1} = b/a$. \n\nThe second version is $x^{-1} = 1/x = 1 \\times x^{-1}\\text{(version 1)} = x^{-1} = b/a$.\n\nNote that only after we have known this can we say that for the second version of $x^{-1}$, \n$(x^{-1})^{-1} = x$.\n\nNow we can also say that $x^{-n} = (x^n)^{-1}$\n\n\\declareexercise{4.3.4}\n\\begin{proof}\nExcept for (3),\nwe have already proven these properties when $m,n \\in \\mathbb{N}$. Then we will just write $m,n$ as $-m,-n$.\n\n(a)\n(1)\n\\[\nx^{-m}x^{-n} = \\frac{1}{x^m}\\frac{1}{x^n} = \\frac{1}{x^mx^n}=1/x^{m+n} = x^{-m-n}\n\\]\n\n(2)\nBefore doing this, we must derive that for integers $a,b$ and natural number $n$, $(a/b)^n = a^n/b^n$. Use \ninduction: $(a/b)^0 = 1 = 1/1 = a^0/b^0$.\n\nSuppose that for $n$, the statement is already true. Then \n\\[\n(a/b)^{n+1} = (a^n/b^n)(a/b) = (a^{n+1}/b^{n+1})\n\\]\n\nWe can now close the induction.\n\nThus, \n\\begin{align*}\n&(x^{-n})^{-m} \\\\\n&= ((1/(x^n))^m)^{-1} \\tag{$x^{-n} = (x^n)^{-1}$} \\\\\n&= (1/(x^n)^m)^{-1} \\\\\n&= (x^n)^m \\\\\n&= x^{mn}\n\\end{align*}\n\n(3)\n\\begin{align*}\n(xy)^{-n} \n&= 1/(xy)^n \\\\\n&= 1/(x^ny^n) \\\\\n&= (1/x^n) (1/y^n) \\\\\n&= x^{-n}y^{-n}\n\\end{align*}\n\n(b)\n\\begin{lem}\nFor $x = (a/b) >  y = (c/d) > 0$,\n\\[\n0 < x^{-1} < y{-1}\n\\]\n\\end{lem}\n\\begin{proof}\nLet $a,b,c,d>0$. We know that\n\\[\na \\times b^{-1} > c \\times d^{-1}\n\\]\nMultiply it with $bd>0$, we have\n\\[\nad>bc\n\\].\nMultiply it with $a^{-1}c^{-1} >0$, we have\n\\[\nd/c>b/a\n\\]\nThat is,\n\\[\ny^{-1} > x^{-1}\n\\]\nAnd they are obviously bigger than $0$.\n\\end{proof}\n\nAccording to the lemma,\n\\[\nx^{n} \\geq y^{n} \\Longrightarrow ((x^{n})^{-1} \\leq (y^{n})^{-1} \\equiv x^{-n} \\leq y^{-n})\n\\]\n\n(c)\nWe first show that for positive integer $n$, the statement is true. We assume that $x>y$. Another situation is \nsimilar.\nUse induction, we try to prove that $x\\neq y \\Longrightarrow x^n \\neq y^n$. We need to start from $n=1$. First, \n$x^1=x > y^1=y$. \n\nSuppose that for $n$, the statement is already true. Then\nMultiply $x>y$ with $x^n > y^n$, \nwe have $x^{n+1} > y^{n+1}$.\n\nWe can now close the induction.\n\nThen for negative ones, we know that $1/x = 1/y$ iff $x=y$, so $x^n \\neq y^n \\equiv x^{-n} \\neq y^{-n}$.\n\n(d)\nIt is immediately derived since $1/x = 1/y \\equiv x=y$.\n\\end{proof}\n\n\\declareexercise{4.3.5}\n\\begin{proof}\nUse induction from $1$.\n\n$2^1 = 2 >1$.\n\nSuppose that for $N$, the statement is already true. Then\n\\[\n2^{N+1} = 2\\times 2^N > 2N \\geq N+1\n\\]\n(Note that $N\\geq 1 \\Longrightarrow 2N \\geq N+1$)\n\\end{proof}\n\n\\subsection{Gaps In The Rational Numbers}\n\\declareexercise{4.4.1}\n\\begin{proof}\nExistence: We show that when $x \\geq 0$, $(\\exists n \\in \\mathbb{Z})(n \\leq x < n+1)$. Write $x$ as $a/b$, \nwhere $a \\geq 0,b>0$. If $a= 0$, then $x=0$, $n=0$. If $a\\neq 0$, then according to Proposition 2.3.9, \n\\[\n\\exists m \\exists r(a = mb+r),\n\\]\nwhere $m,r \\in \\mathbb{N}$ and $r < b$. Because of this, $mb+b >a$, so $(mb+b)/b>a/b=x$, which means $m+1>x$. \nOn the other hand, $mb \\leq a$, so $mb/b \\leq a/b =x$, which means $m \\leq x$.\n\nThen when $x<0$, then $-x>0$, and $(\\exists n \\in \\mathbb{Z})(n \\leq -x < n+1)$, so \n\\[\n-n \\geq x > -n -1\n\\]\n$\\geq$ means $>$ or $=$ (exclusive). When $-n > x >-n-1$, let $m=-n-1$, then $m \\leq x < m+1$ is true. When \n$-n =x > -n-1$, let $m=-n$, then $m \\leq x < m+1$ is also true. So $m$ is the integer we want if $x<0$.\n\nUniqueness:\nFor $n \\leq x < n+1$, and $m \\neq n$, we try to prove that $m \\leq x<m+1$ is not possible. Before doing this, \nwe need some lemmas:\n\\begin{lem}\n(1) For integers $i,j$, $i<j \\equiv i+1\\leq j$.\n(2) For integer $i$, there is no integer $j$ such that $i<j<i+1$.\n\\end{lem}\n\\begin{proof}\n(1) It has already been proven for natural numbers. If $i,j<0$, then $-i,-j>0$.\n\\[\ni<j \\equiv -i>-j \\equiv -i \\geq -j+1 \\equiv i \\leq j-1 \\equiv i+1 \\leq j\n\\]\n\n(2)\nSuppose the negation, that there exists a integer $j$ such that $i<j<i+1$. We know that \n$i<j \\equiv i+1 \\leq j \\equiv j \\geq i+1$. But we also have $j<i+1$, which is impossible.\n\\end{proof}\n\n$m$ either $<$ or $>n$. On the former case, $m+1\\leq n\\leq x$, so $m+1>x$ is not possible. One the latter case, \n$x<n+1\\leq m$, so $m \\leq x$ is impossible.\n\\end{proof}\n\n\\declareexercise{4.4.2}\n\\begin{proof}\n(a) We will use a different approach from the hint the book provided here. After assuming the negation, we \ntry to prove that \n$a_n \\leq a_0 -n$. Note that subtraction may results in a overflow (that is, natural numbers flows to negative \nintegers). So we will first define $a_n$ as integers. And we try to show that no such infinite descent \nsequences can only lie in  $\\mathbb{N}$.\n\nUse induction: $a_0 \\leq a_0-0$.\n\nSuppose the statement for $n$ is already true, then \n$a_{n+1} < a_n \\equiv a_{n+1} +1 \\leq a_n \\equiv a_{n+1} \\leq a_n - 1$. Then we have \n$a_{n+1} \\leq (a_0 -n -1 = a_n -(n+1))$. We can now close the induction.\n\nHowever, let $n = a_0$, then $a_{n+1} \\leq n-n-1 = -1$, which means that $a_{n+1}$ does not lie in \n$\\mathbb{N}$.\n\n(b)\n(1) Yes. For example, $a_n:=-n$ satisfies our restrictions.\n\n(2) Yes. Because it is always possible to find a rational between $0$ and $a_0$.\n\\end{proof}\n\n\\declareexercise{4.4.3}\n\\begin{proof}\n(1) Suppose the negation, that natural number $n=2k=2k'+1$, where $k,k'$ are also natural. Then $2k=2k'+1$\nThen we have $2k > 2k' \\Longrightarrow k>k'$. But $2k+1 = 2(k'+1)$, so $2(k'+1) > 2k \\Longrightarrow k'+1 >k$. \nBut we know that between $k',k'+1$ there exists no natural numbers. so it is impossible. (Note that we don't \nhave a proposition saying $ac>bc \\Longrightarrow a>b$ for natural numbers, but we can first deal with them with \nthe range of rationals. Multiply them with $c^{-1}$, and we will see that the result of the two sides are also \nnatural numbers, so for natural numbers this is true.)\n\n(2)\n\\[\np^2 = (2k+1)^2 = 4k^2+4k + 1 = 2(2k^2+2k) +1\n\\]\n\n(3)\nTreat $p,q$ as rationals.\n$p^2/2=q^2 \\Longrightarrow q^2<p^2$. We show that $q \\geq p$ can not be true. It is obvious that $q \\neq p$. \nAnd when $q>p$, multiply it with itself, $q^2>p^2$, which is impossible.\n\\end{proof}", "meta": {"hexsha": "c62d24ec32749dda389b01e2ed5e20d33fcdfee0", "size": 29183, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Integers and Rationals.tex", "max_stars_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_stars_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Integers and Rationals.tex", "max_issues_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_issues_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Integers and Rationals.tex", "max_forks_repo_name": "Little-He-Guan/Notebook-for-Analysis-of-Tao", "max_forks_repo_head_hexsha": "e040260e4346ae65ce28af11dbd2bb5d9d5ac96b", "max_forks_repo_licenses": ["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.4534336783, "max_line_length": 112, "alphanum_fraction": 0.6055237638, "num_tokens": 11277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6037866606862428}}
{"text": "\\documentclass[11pt]{article}\n\\title{Lagrange Multipliers}\n\\author{Suhas Arehalli}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}[section]\n\n\\theoremstyle{definition}\n\\newtheorem{definition}{Definition}[section]\n\n\n\\begin{document}\n\\maketitle\n\n\\section{Preliminaries}\n\\begin{definition}[Manifold]\n    A smooth $k$-manifold $M$ in $\\mathbb{R}^n$ can be defined as a set of points\n    \\[ M = \\{ \\mathbf{x} \\in \\mathbb{R}^n | F(\\mathbf{x}) = \\mathbf{0}\\} \\]\n    For some function $F: \\mathbb{R}^n \\rightarrow \\mathbb{R}^{n-k}$ such that\n    $\\left[\\mathbf{D}F(\\mathbf{x})\\right]$ has maximal rank for all $\\mathbf{x}$. \n    This is equivalent to the conventional definition in terms of local charts and \n    such.\n\\end{definition}\n\\begin{definition}[Tangent Space]\n    The tangent space to a manifold at point $\\mathbf{a}$ is defined as the set of vectors\n    that locally describe movement on the manifold. Since staying on the manifold requires \n    that it's defining constaint function $F$ remains 0, we can formally define the tangent\n    space at $\\mathbf{a}$ as\n    \\begin{align*}\n        T_{\\mathbf{a}}M &= \\{ \\mathbf{x} \\in \\mathbb{R}^n | [\\mathbf{D}F(\\mathbf{a})]\\mathbf{x} = \\mathbf{0}\\} \\\\\n        T_{\\mathbf{a}}M &= ker[\\mathbf{D}F(\\mathbf{a})]\n    \\end{align*}\n\\end{definition}\n\\section{Background}\nGiven a function $f: \\mathbb{R}^n \\rightarrow \\mathbb{R}$, we'd like to find a vector $\\mathbf{x}$ on\na smooth $k$-manifold $M$ embedded in $\\mathbb{R}^n$. That maximizes or minimizes the function $f$. This\nis called \\textit{Constrained Optimization}, and can be solved using the method of Lagrange Multipliers.\n\nDue to the definition of a manifold we gave earlier, we can phrase this problem in a somewhat more \naccessable light. Suppose we have a system of $p$ \\textit{constraint equations} of $n$ variables  \nrepresented by the equation $F(x) = 0$ for  $F: \\mathbb{R}^n \\rightarrow \\mathbb{R}^{p}$. This \ndefines a set of points in $\\mathbb{R}^n$ that satisfy these equations, and if we find that \nthe derivative of $F$ is onto, then we know that these points form a smooth manifold. Now given\nthese constraints, it seems natural in many practical scenarios that we'd want to find extremum\nthat satisfy these constaints. For instance, we'd like to know how to minimize cost or maximize\nprofit or utility given some set of constraints. Given some cost or utility function $f$, Lagrange\nmultipliers give us a way to answer that question.\n\n\\section{Statement}\n\\begin{theorem}[Method of Lagrange Multipliers]\n    Suppose $M$ is a smooth $k$-manifold described by the function $F: \\mathbb{R}^n \\rightarrow \\mathbb{R}^{n-k}$\n    such that $F(\\mathbf{x}) = 0$ and $\\mathbf{a}$ is an extremum of some function  $f: \\mathbb{R}^n \n    \\rightarrow \\mathbb{R}$ on $M$. Then\n    \\[ \\left[ \\mathbf{D}f(\\mathbf{a}) \\right] = \\sum_i^{n-k} \\lambda_i \\left[\\mathbf{D}F_i(\\mathbf{a})\\right] \\]\n    Or in terms of gradients,\n    \\[ \\nabla f(\\mathbf{a}) = \\sum_i^{n-k} \\lambda_i \\nabla F_i(\\mathbf{a}) \\]\n    \\[ \\nabla f(\\mathbf{a}) \\in span\\left(\\{\\nabla F_1(\\mathbf{a}), \\dots,\\nabla F_{n-k}(\\mathbf{a})\\}\\right) \\]\n\\end{theorem}\n\n\\section{Intuition}\nFirst let's discuss \\textit{why} this should be true, and then discuss a strategy for proving it. \n\nNaively, we begin to optimize functions by using the first derivative test - a function is at a local\nextremum if movement in any direction will no longer increase/descrease the value of the function. \nMore precisely, if the directional derivative is $0$ for all vectors ($[\\mathbf{D}f(\\mathbf{a})]\\mathbf{v} = \\mathbf{0}, \\forall \\mathbf{v} \\in \\mathbb{R}^n$), then we're at a potential extremum.\n\nNote, however, that in order to maximize $f$ on the manifold, we cannot simply seek out a maximum for $f$.\nThere's no guarantee that any maximum of $f$ exists in $\\mathbb{R}^n$, let alone lies on $M$. Thus we must begin\nworking from the manifold, rather than from the function we optimize. \n\nThe main benefit of working on the manifold is that we have few directions we can move, and thus it is easier \nto be a local extremum. Consider that the gradient $\\nabla f$ is considered the direction of greatest \nincrease, and it's negation is the direction of greatest decrease. If we want to be at an extremum, these must \nbe orthogonal to the manifold - no movement on the manifold can change the value of $f$. However, the consider \neach of the  individual constraint functions, $F_1, ..., F_{n-k}$. Each of these has a gradient function \n$\\nabla F_i$ which is orthogonal to the manifold - In fact, these span the orthogonal complement of the\ntangent space of the manifold at a point. Thus, at an extrema, $\\nabla f$ should be in the span of \n$\\{ \\nabla F_1, ..., \\nabla F_{n-k} \\}$, which is exactly what the method of Lagrange Multipliers \nsays.\n\n\\section{Proof}\nAt a local maximum of $f$ on $M$, $\\mathbf{a}$, we must be able to move in every direction on the \nmanifold without increasing the value of the $f$ (otherwise, a point $\\varepsilon$ in that direction\nwould give a greater value of $f$ than $\\mathbf{a}$, contradicting the fact that $\\mathbf{a}$ is a\nlocal maximum. The same argument goes for minima - we must be able to move in every direction without\ndecreasing $f$. Since derivatives are continuous on smooth manifolds, we must have \n    \\[\\forall \\mathbf{v} \\in T_{\\mathbf{a}}M = \\ker[\\mathbf{D}F(\\mathbf{a})] \\]\nthat \n    \\begin{align*}\n    [\\mathbf{D}f(\\mathbf{a})&]\\mathbf{v} = 0  \\\\\n    \\mathbf{v} \\in \\ker&[\\mathbf{D}f(\\mathbf{a})] \n    \\end{align*}\nWhich implies that\n    \\[\\ker[\\mathbf{D}F(\\mathbf{a})] \\subset  \\ker[\\mathbf{D}f(\\mathbf{a})] \\]\nThis is often one stopping point for this result, but deriving the original equation requires further \nmanipulation. First note that since $[\\mathbf{D}F(\\mathbf{a})]\\mathbf{v} = \\mathbf{0}$ (since \n$\\mathbf{v} \\in \\ker[\\mathbf{D}F(\\mathbf{a})]$), then $\\forall i \\in \\{1, \\dots,  n-k\\}$\n    \\[ [\\mathbf{D}F_i(\\mathbf{a})]\\mathbf{v} = 0 \\]\nplus, from the above \n    \\[ [\\mathbf{D}f(\\mathbf{a})]\\mathbf{v} = 0 \\] \nFor all $\\mathbf{v} \\in T_{\\mathbf{a}}M$. We can consider these in terms of gradients:\n\\begin{align*}\n    \\nabla F_1 \\cdot \\mathbf{v} &= 0  \\\\\n    \\dots \\\\\n    \\nabla F_{n-k} \\cdot \\mathbf{v} &= 0 \\\\\n    \\nabla f \\cdot \\mathbf{v} &= 0 \n\\end{align*}\nNow it is clear to see that $\\{\\nabla f, \\nabla F_1, ..., \\nabla F_{n-k}\\}$ lie in the orthogonal complement\nto the Tangent Space $T_{\\mathbf{a}}M$ (they're all orthogonal to every vector in the tangent space!). \n\nNow, since they both live in $\\mathbb{R}^n$, the orthogonal complement\nshould have dimension $n - dim(T_{\\mathbf{a}}M) = n - k$, since the sum of dimension of any space and \nit's orthogonal complement must be the dimension of the space it's embedded in. Now we have $n-k+1$ \nvectors in a space with dimension $n-k$. Thus they cannot be linearly independent, and one must be a linear \ncombination of the others. thus we can write\n    \\[ \\nabla f = \\sum_i^{n-k} \\lambda_i \\nabla F_i \\]\nOr, back in matrix notation,\n    \\[ [\\mathbf{D}f(\\mathbf{a})] = \\sum_i^{n-k} [\\mathbf{D}F_i(\\mathbf{a})] \\]\nConcluding our proof.\n\\end{document}\n", "meta": {"hexsha": "7cf2b9f79316a01da406205df8272c0bab26111a", "size": 7159, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Other/LagrangeMultipliers.tex", "max_stars_repo_name": "SArehalli/ReviewSheet", "max_stars_repo_head_hexsha": "a8bb8c04cb55ce1a4a728ec2dfb044e3bca6b319", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Other/LagrangeMultipliers.tex", "max_issues_repo_name": "SArehalli/ReviewSheet", "max_issues_repo_head_hexsha": "a8bb8c04cb55ce1a4a728ec2dfb044e3bca6b319", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Other/LagrangeMultipliers.tex", "max_forks_repo_name": "SArehalli/ReviewSheet", "max_forks_repo_head_hexsha": "a8bb8c04cb55ce1a4a728ec2dfb044e3bca6b319", "max_forks_repo_licenses": ["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.2032520325, "max_line_length": 195, "alphanum_fraction": 0.6974437771, "num_tokens": 2284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.787931185683219, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6037866587782337}}
{"text": "\\documentclass{article}\r\n\\usepackage{algpseudocode}\r\n\\usepackage{algorithm}\r\n\\usepackage[english]{babel}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{fancyhdr}\r\n\\usepackage{listings}\r\n\\usepackage{graphicx}\r\n\\usepackage[section]{placeins}\r\n\\usepackage{titlesec}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1in]{geometry}\r\n\\pagestyle{fancy}\r\n\\fancyhf{}\r\n\\rhead{Rahul Shah}\r\n\\lhead{Machine Learning: Nanodegree}\r\n\\rfoot{\\thepage}\r\n\\title{Supervised Learning: Linear Regression}\r\n\\begin{document}\r\n\\maketitle\r\n\\section{Motivation}\r\n% Talk about the housing problem and trying to predict the next house in\r\nImagine you are trying to predict the prices of houses. The only data you have available to you are the prices of a bunch of houses, and the square footage of all the houses. If given another house, alongside the square footage of said house, can you predict the price of the house?\r\n\r\nIf we assume that increasing square footage is approximately proportional to the price by a constant (the data is approximately linear), we can plot each point $P_i = (x, y) = (sq ft, \\$\\$)$ in a scatter plot and find a line of best fit to the data.\r\n\r\n\\section{Fitting a Line}\r\n% If we know the thing is linear, then we can use a linear model to predict it\r\nFor any set of data \\emph{assuming the data is approximately linear}, we can use a linear model to predict the output of any new data that comes in. \r\n% make sure you mention the linear model we are using and what the coefficients mean\r\nAs a reminder, the linear model we are working with (for now) is:\\newline $\\hat{y} = \\beta_1x + \\beta_2$\\newline where \\newline $\\hat{y} :=$ Predicted output of the linear model.\\newline Note that if we increase $\\beta_1$, we rotate the line CCW, if we decrease $\\beta_1$, we rotate the line CW, and increasing/decreasing $\\beta_2$ pulls up/down the line.\r\n\\section{Moving a Line Towards a Point}\r\n% This is how we can approximate a line movement\r\nLet's assume the line we have to work with is: $y(x) = \\beta_1x + \\beta_2$ ($y(x)$ will be treated as y unless explicitly used as a function), where $\\beta_1, \\beta_2$ are arbitrary constants, like a really bad guess as to what the actual line would be. Place a point reasonably far away from the line, $P = (p, q)$. How do we, using the data that we have, move the line such that it gets closer to the point? \r\n\\subsection{Absolute Trick}\r\nThe Absolute Trick is as such: Every iteration, we change $\\beta_1$ by the value $p$ (the x coordinate), and change the value $\\beta_2$ by the value 1 (we will get to cases where we increase/decrease in a second). So our model transforms to:\\\\\r\n$y = \\beta_1x+\\beta_2 \\rightarrow y = (\\beta_1 \\pm p)x+(\\beta_2 \\pm 1)$, where each $\\pm$ is independent of one another\\\\\r\nIf we continue under the assumption that the point is far away, we might get a good approximation. In all likelihood, however, we are likely to overshoot. So instead we iterate over this multiple times, taking steps towards the right solution. We can do this by multiplying $p$ and 1 by $\\alpha$, the learning rate. So our formula becomes:\\\\\r\n$y = \\beta_1x+\\beta_2 \\rightarrow y = (\\beta_1 \\pm p\\alpha)x+(\\beta_2 \\pm \\alpha)$\\\\\r\nTo determine whether to use + or -, we need to look at how we want the line to move. For $\\beta_1$, we see which direction (CCW or CW) we should rotate the line to reach the point (smallest angle to sweep across so the line meets the point). For $\\beta_2$, do the same thing, but this time your distance is up/down.\r\n\\subsection{Square Trick}\r\nThe above trick works to get near to the point, but we never factor in the y distance from the line (other than to determine the sign). What if we adjust $\\beta_1$ and $\\beta_2$ the same way as above, but also account for the vertical distance from the point to the line? We can do this by multiplying our $p\\alpha$ and $\\alpha$ term by $q-\\hat{q}$, where $\\hat{q} = y(p)$. So our formula for the square trick becomes:\\\\\r\n$y = \\beta_1x+\\beta_2 \\rightarrow y = (\\beta_1 + p\\alpha(q-\\hat{q}))x+(\\beta_2 + \\alpha(q-\\hat{q}))$\\\\\r\nNote that we don't need to use $\\pm$ anymore because multiplying by $q-\\hat{q}$ means that if our point is below our line, this difference will yield a negative number,  and if the point is above our line, the difference will yield a positive number.\r\n\\subsection{Why not just do $\\frac{q}{p}x$ as our line?}\r\nObviously these tricks are pretty bad standalone operations, but their power is in the fact that they aren't exact. When we do linear regression, we're modifying our line of best fit so it coincides with all the data, and, unless all of our data points are co-linear (HIGHLY unlikely!), we want our line of best fit to be close to all of our data points. Think of each point pulling towards a line, the farther away the point from the line, the harder it pulls the line towards it.\r\n\r\n\\section{What is the Line of Best Fit}\r\n% Note that if we define error as the difference between our predicted y from our actual point, our best fit line is essentially the placement of the line such that the sum of all errors is at its smallest\r\nNow that we have an iterative approach to pulling a line closer to a point, we need to define what a line of best fit is. If we define error (roughly) as the difference between our predicted y for each x value in our data, $\\hat{y} = y(x)$, and the actual y value from each data point in our value, then our line of best fit is such that $\\sum f(|y-\\hat{y}|)$, such that $f$ is a monotonic function, is at a minimum.\r\n\r\n\\section{Linear Least Squares}\r\n% Note on Linear Least Squares (matrix solution), and how, though it does solve the problem completely, it also involves inverting a matrix, which can be computationally taxing.\r\n\r\nTurns out, finding the exact line of best fit for a set of points $(x_i, y_i)$ is an already solved problem, with a nice, closed form solution. Let our linear model be $\\beta_1 x + \\beta_0 = y$. If we consider the linear system:\\\\\r\n$X\\beta = y$\\\\\r\nWhere:\\\\\r\n$X :=$ the overdetermined matrix\r\n$\\begin{bmatrix}\r\n\t1 & x_1\\\\\r\n\t\\vdots & \\vdots\\\\\r\n\t1 & x_n\r\n\\end{bmatrix}$\\\\\r\n$y:=$ the vector of y values associated with each x in the data\\\\\r\n$\\beta :=$ the vector of beta constants in the linear system (from this model, it's $\\beta_1$ and $\\beta_0$)\\\\\r\nWe have an overdetermined system that does not have exact solutions for $\\beta_1, \\beta_0$. Since we need a square matrix were $X$ is, so we can solve it, we can multiply both sides by $X^T$ to get:\\\\\r\n$X^TX\\beta=X^Ty$\\\\\r\nSolving for $\\beta$, we get:\\\\\r\n$\\beta=(X^TX)^{-1}y$, where $\\beta$ is guaranteed to be such that our model $\\beta_1 x + \\beta_0 = y$ minimizes the error.\r\n\r\n%NEED TO CHECK THIS THERE IS A WAY BUT I DONT WANT TO DO THIS\r\n%This can even be generalized, if we have a model $y = \\beta_0 + \\sum_{1}^{n} beta_if_i(\\vec{x})$, where each $f$ is a polynomial, we can make the entries of each row of our matrix the functions $f_i(\\vec{x})$, with every row in the matrix being one point from the input data $\\vec{x} = x_1, ..., x_n$\\\\\r\n\r\nUnfortunately, this linear least squares approach is rarely used. This is because the formula $\\beta=(X^TX)^{-1}y$ means that we need to calculate the inverse of a matrix, which is an $O(n^3)$ operation. \r\n\r\n% So, we take an iterative approach, (mention the mountain thing, and how, to get to the bottom, you just go where it falls off the most)\r\n\r\nSince we can't solve this exactly, we need to get an approximation of our answer via iterative methods. \r\n\r\n\\section{Error Functions}\r\nSince our method must be iterative and will not give us the exact answer, it would be useful to have an idea of what our error for any given model is. \r\n\\subsection{Mean Approximation Error (MAE)}\r\nMAE $=\\frac{1}{m}\\sum |y_i - \\hat{y}(x_i)$\\\\\r\nWe use absolute value so we do not have negative differences accidentally canceling positive ones. It's also a metric.\r\n\\subsection{Mean Squared Error (MSE)}\r\nMSE $=\\frac{1}{2m}\\sum (y_i - \\hat{y}(x_i))^2$\\\\\r\nThe added $\\frac{1}{2} is a constant added for convienience.$\r\n\r\n\\section{Gradient Descent}\r\n% Gradient is basically just the slope of the moutain at any point around you\r\nSince our goal is to minimize error, why not just change $\\beta_0, \\beta_1$ in the direction of the greatest decrease of the error function, multiplied by a small number (so we don't overshoot)? That is, every iteration,\\\\\r\n$\\beta_i = \\beta_i - \\alpha\\frac{\\partial}{\\partial \\beta_i} Error = \\beta_i - \\alpha\\frac{\\partial Error}{\\partial y_i}\\frac{\\partial y_i}{\\partial x_i}$\\\\\r\nIf we apply this to our MAE and MSE square functions, we essentially get the Absolute and Square Trick, respectively\r\n\r\n\r\n\\subsection{Types of Gradient Descent}\r\n% Batch, Stochastic, and Mini-Batch\r\n% First two are basically terrible\r\n% give pseudocode for mini-batch\r\nBatch - compute the average change in $\\beta$ using all data points, update $\\beta$, and iterate over that\r\nStochastic - compute the change in $\\beta$ using one data point, updating $\\beta$, then do another, etc.\r\nMini-Batch - Split your data into small, even groups, and compute the change, and iterate over that.\r\n\r\nBatch and Stochastic are pretty slow, so we do mini batch typically\r\n% Can we make b just part of the matrix\r\n\\begin{algorithm}\r\n\t\\caption{Gradient Descent- Mini Batch with MSE}\r\n\t\\begin{algorithmic}\r\n\t\t\\Procedure{Step}{$X$, $\\beta$, $y$, $b$, $\\alpha$}\\\\\r\n\t\t\t \\Comment $X$ the matrix containing loaded input data, $\\beta$ the current values of our model's coefficients, $b$ current value of the regression intercept ($\\beta_0$), $\\alpha$ the step size. \r\n\t\t\t \r\n\t\t\t $\\hat{y} = XW + b$\r\n\t\t\t $error = y - \\hat{y}$\r\n\t\t\t \r\n\t\t\t $W += \\alpha\\times error\\times X$ \\Comment this is just the derivative (negative is removed)\r\n\t\t\t $b += \\alpha * \\sum error_i$\r\n\t\t\\EndProcedure\r\n\t\\end{algorithmic}\r\n\\end{algorithm}\r\n\r\n\\section{Generalizing to Higher Dimensions}\r\n% Absolutely give matrix translations here or else nothing makes any goddamn sense\r\n\r\nFor an input vector $\\vec{x} = x_1, ..., x_n$, we get an $n-1$ dimensional hyperplane.\r\n\r\n\\section{Warnings}\r\n% Just copy whats on the Udacity site basically\r\n\r\n\\section{Polynomial Regression}\r\nBasically, you can fit your model to any polynomial, so long as you treat each power of each input variable as another term on your x vector. Meaning, to model a quadratic,, you need rows of length 3 (const, power 1, power 2)\r\n\r\n\\section{Regularization}\r\nNaturally we can fit multiple models to the same set of data. We can also minimize error by just doing linear least squares to a polynomial of an arbitrarily high power, but this makes an extremely computationally complex problem to solve. We also end up with a model that does not generalize to new data. To account for that, we regularize the model by summing up the elements in $\\beta$ and tacking that onto our total error. Models that do not generalize well will have a much larger regularization parameter. \r\n\r\nSometimes, we want our model to be more accurate (less actual error) and are okay if the model is complex, so we multiply this regularization parameter by $\\lambda$ to lower the error \"punishment\". If we can tolerate higher errors & need simplicity (perhaps operating on a lot of data), we use a higher $\\lambda$ on our regularization parameter. \\\\\r\n\r\n2 kinds of regularization:\\\\\r\nL1: take the L1 distance of the coefficients\\\\\r\nL2:    \"     L2             \"\r\n\\section{Feature Scaling}\r\nWhen we implement regularization or are using a distance based metric, we need to scale the range of our input vector values so that the penalty for error is uniform, and you reach convergence faster. Essentially what you want to do is to make each feature (each $x_i$ for each piece of data) and make it so its mean is 0 and standard deviation is 1. You can also just normalize the data from 0 to 1 or standardize the values such that each value is a z-score\r\n\\section{External Resources}\r\n%no later i hate this\r\n\\end{document}\r\n", "meta": {"hexsha": "159f6555aa78a57314120590f6b9560b7202a215", "size": 11909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine_Learning/Linear Regression/Linear Regression.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": "Machine_Learning/Linear Regression/Linear Regression.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": "Machine_Learning/Linear Regression/Linear Regression.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": 82.1310344828, "max_line_length": 514, "alphanum_fraction": 0.7338147619, "num_tokens": 3094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6037866579995309}}
{"text": "% !TEX root = ../master/master.tex\n\n%% Dexter Barrows, 2016\n%% dbarrows.github.io\n\n\n\tParticle filters are similar to MCMC-based methods in that they use likelihoods to evaluate the validity of proposed parameter sets given observed data $D$, but differ in that they are largely trying to produce point estimates of the parameters instead of samples from the posterior distribution.\n\n\tInstead of constructing a Markov chain and approximating its stationary distribution, a cohort of ``particles'' are used to move through the data in an on-line (sequential) fashion with the cohort being culled of poorly-performing particles at each iteration via importance sampling. If the culled particles are not replenished, this will be a Sequential Importance Sampling (SIS) particle filter. If the culled particles are replenished from surviving particles, in a sense setting up a process analogous to Darwinian selection, then this will be a Sequential Importance Resampling (SIR) particle filter \\cite{Arulampalam2002}.\n\n\n\\section{Formulation}\n\n\tParticle filters, also called Sequential Monte-Carlo (SMC) filters, feature similar core functionality as the venerable Kalman Filter. As the algorithm moves through the data (sequence of observations), a prediction-update cycle is used to simulate the evolution of the model $M$ with different particular parameter selections, track how closely these predictions approximate the new observed value, and update the current cohort appropriately \\cite{Arulampalam2002}.\n\n\tTwo separate functions are used to simulate the evolution and observation processes. The ``true'' state evolution is specified by\n\n\t\\begin{equation}\n\t\tX_{t+1} \\sim f_1 (X_t, \\theta),\n\t\\end{equation}\n\n\tAnd the observation process by\n\n\t\\begin{equation}\n\t\tY_t \\sim f_2 (X_t, \\theta).\n\t\\end{equation}\n\n\tComponents of $\\theta$ can contribute to both functions, but a typical formulation is to have some components contribute to $f_1 (\\cdot, \\theta)$ and others to $f_2 (\\cdot,\\theta)$.\n\n\tThe prediction part of the cycle uses $f_1 (\\cdot, \\theta)$ to update each particle's current state estimate to the next time step, while $f_2 (\\cdot, \\theta)$ is used to evaluate a weighting $w$ for each particle which will be used to determine how closely that particle is estimating the true underlying state of the system. Note that $f_2 (\\cdot, \\theta)$ could be thought of as a probability of observing a piece of data $y_t$ given the particle's current state estimate and parameter set, $P(y_t | X_t, \\theta)$. Then, the new cohort of particles is drawn from the old cohort proportional to the weights. This process is repeated until the set of observations $D$ is exhausted.\n\n\n\\section{Algorithm}\n\n    Now we will formalize the particle filter.\n\n    We will denote each particle $p^{(j)}$ as the $j^{\\text{th}}$ particle consisting of a state estimate at time $t$, $X_t^{(j)}$, a parameter set $\\theta^{(j)}$, and a weight $w^{(j)}$. Note that the state estimates will evolve with the system as the cohort traverses the data.\n\n    The algorithm for a Sequential Importance Resampling particle is shown in Algorithm [\\ref{pfsir}].\n    \n    \\begin{algorithm}\n\n        \\BlankLine\n\n        \\SetKwInOut{Input}{Input}\n        \\SetKwInOut{Output}{Output}\n        \\DontPrintSemicolon\n\n        \\tcc{Select a starting point}\n        \\Input{Observations $D = y_1, y_2, ..., y_T$, initial particle distribution $P_0$ of size $J$}\n\n        \\BlankLine\n\n        \\tcc{Setup}\n        Initialize particle cohort by sampling $(p^{(1)}, p^{(2)}, ..., p^{(J)})$ from $P_0$\n\n        \\BlankLine\n\n        \\For{$t = 1:T$}{\n\n            \\BlankLine\n\n            \\tcc{Evolve}\n            \\For{j = 1:J}{\n            \t$X_t^{(j)} \\gets f_1 (X_{t-1}^{(j)}, \\theta^{(j)})$\n            }\n\n            \\BlankLine\n\n            \\tcc{Weight}\n            \\For{j = 1:J}{\n            \t$w^{(j)} \\gets P(y_t | X_t^{(j)}, \\theta^{(j)}) = f_2 (X_t^{(j)}, \\theta^{(j)})$\n            }\n\n            \\BlankLine\n\n            \\tcc{Normalize}\n            \\For{j = 1:J}{\n            \t$w^{(j)} \\gets w^{(j)} / \\sum_{1}^{J} w^{(j)}$\n            }\n\n            \\BlankLine\n\n            \\tcc{Resample}\n            $p^{(1:J)} \\gets \\text{sample}(p^{(1:J)}, \\text{prob} = w, \\text{replace} = true)$\n        }\n\n        \\BlankLine\n\n        \\tcc{Samples from approximated posterior distribution}\n        \\Output{Cohort of posterior samples $(\\theta^{(1)},\\theta^{(2)},...,\\theta^{(J)})$}\n\n        \\BlankLine\n\n        \\caption{SIR particle filter \\label{pfsir}}\n\n    \\end{algorithm}\n\n\\section{Particle Collapse}\n\n\tOften, a situation may arise in which a single particle is assigned a normalized weight very close to 1 and all the other particles are assigned weights very close to 0. When this occurs, the next generation of the cohort will overwhelmingly consist of descendants of the heavily-weighted particle, termed particle collapse or degeneracy \\cite{Bengtsson2008}\\cite{Arulampalam2002}.\n\n\tSince the basic SIR particle filter does not perturb either the particle system states or system parameter values, the cohort will quickly consist solely of identical particles, effectively halting further exploration of the parameter space as new data is introduced.\n\n\tA similar situation occurs when a small number of particles (but not necessarily a single particle) split almost all of the normalized weight between them, then jointly dominate the resampling process for the remainder of the iterations. This again halts the exploration of the parameter space with new data.\n\n\tIn either case, the hallmark feature used to detect collapse is the same -- at some point the cohort will consist of particles with very similar or identical parameter sets which will consequently result in their assigned weights being extremely close together.\n\n\tMathematically, we are interested in the number of effective particles, $N_{\\small\\text{eff}}$, which represents the number of particles that are acceptably dissimilar. This is estimated by evaluating\n\n\t\\begin{equation}\n\t\tN_{\\small\\text{eff}} = \\frac{1}{\\sum_1^J (w^{(j)})^2}.\n\t\\end{equation}\n\n\tThis can be used to diagnose not only when collapse has occurred, but can also indicate when it is near \\cite{Arulampalam2002}.\n\n\n\\section{Iterated Filtering and Data Cloning}\n\n\tA particle filter hinges on the idea that as it progresses through the data set $D$, its estimate of the posterior carried in the cohort of particles approaches maximum likelihood. However, this convergence may not be fast enough so that the estimate it produces is of quality before the data runs out. One way around this problem is to ``clone'' the data and make multiple passes through it as if it were a continuation of the original time series. Note that the system state contained in each particle will have to be reset with each pass.\n\n\tRigorous proofs have been developed \\cite{Ionides2006}\\cite{Ionides2015} that show that by treating the parameters as stochastic processes instead of fixed values, the multiple passes through the data will indeed force convergence of the process mean toward maximum likelihood, and the process variance toward 0.\n\n\n\\section{Iterated Filtering 2 (IF2)}\n\n\tThe successor to Iterated Filtering 1 \\cite{Ionides2006}, Iterated Filtering 2 \\cite{Ionides2015} is simpler, faster, and demonstrated better convergence toward maximum likelihood. The core concept involves a two-pronged approach. First, a data cloning-like procedure is used to allow more time for the parameter stochastic process means to converge to maximum likelihood, and frequent cooled perturbation of the particle parameters allow better exploration of the parameter space while still allowing convergence to good point estimates.\n\n\tIF2 is not designed to estimate the full posterior distribution, instead to produce a Maximum Likelihood (ML) point estimate. Further, IF2 thwarts the problem of particle collapse by keeping at least some perturbation in the system at all times. It is important to note that while true particle collapse will not occur, there is still risk of a pseudo-collapse in which all particles will be extremely close to one another so as to be virtually indistinguishable. However this will only occur with the use of overly-aggressive cooling strategies or by specifying an excessive number of passes through the data.\n\n\tAn important new quantity is the particle perturbation density denoted $h(\\theta|,\\sigma)$. Typically this is multivariate Normal with $\\sigma$ being a vector of variances proportional to the expected values of $\\theta$. In practice the proportionality can be derived from current means or specified ahead of time. Further, these intensities must decrease over time. This can be done via exponential or geometric cooling, a decreasing step function, a combination of these, or through some other similar scheme.\n\n\tThe algorithm for IF2 can be seen in Algorithm [\\ref{if2}].\\\\\n\n    \\begin{algorithm}\n\n        \\BlankLine\n\n        \\SetKwInOut{Input}{Input}\n        \\SetKwInOut{Output}{Output}\n        \\DontPrintSemicolon\n\n        \\tcc{Select a starting point}\n        \\Input{Observations $D = y_1, y_2, ..., y_T$, initial particle distribution $P_0$ of size $J$, decreasing sequence of perturbation intensity vectors $\\sigma_1, \\sigma_2, ..., \\sigma_M$}\n\n        \\BlankLine\n\n        \\tcc{Setup}\n        Initialize particle cohort by sampling $(p^{(1)}, p^{(2)}, ..., p^{(J)})$ from $P_0$\n\n        \\BlankLine\n\n        \\tcc{Particle seeding distribution}\n        $\\Theta \\gets P_0$\n\n        \\BlankLine\n\n        \\For{$m = 1:M$}{\n\n        \t\\BlankLine\n\n        \t\\tcc{Pass perturbation}\n            \\For{j = 1:J}{\n            \t$p^{(j)} \\sim h(\\Theta^{(j)}, \\sigma_m)$\n            }\n\n            \\BlankLine\n\n\t        \\For{$t = 1:T$}{\n\n\t        \t\\BlankLine\n\t        \t\n\t\t        \\For{j = 1:J}{\n\n\t\t        \t\\BlankLine\n\t\t        \t\\tcc{Iteration perturbation}\n\t            \t$p^{(j)} \\sim h(p^{(j)}, \\sigma_m)$\n\n\t            \t\\BlankLine\n\t            \t\\tcc{Evolve}\n\t            \t$X_t^{(j)} \\gets f_1 (X_{t-1}^{(j)}, \\theta^{(j)})$\n\n\t            \t\\BlankLine\n\t            \t\\tcc{Weight}\n\t            \t$w^{(j)} \\gets P(y_t | X_t^{(j)}, \\theta^{(j)}) = f_2 (X_t^{(j)}, \\theta^{(j)})$\n\n\t            }\n\n\t            \\BlankLine\n\n\t            \\tcc{Normalize}\n\t            \\For{j = 1:J}{\n\t            \t$w^{(j)} \\gets w^{(j)} / \\sum_{1}^{J} w^{(j)}$\n\t            }\n\n\t            \\BlankLine\n\n\t            \\tcc{Resample}\n\t            $p^{(1:J)} \\gets \\text{sample}(p^{(1:J)}, \\text{prob} = w, \\text{replace} = true)$\n\n\t        }\n\n\t        \\BlankLine\n\n\t        \\tcc{Collect particles for next pass}\n\t        \\For{$j = 1:J$}{\n\t        \t$\\Theta^{(j)} \\gets p^{(j)}$\n\t        }\n\n\t    }\n\n        \\BlankLine\n\n        \\tcc{Samples from approximated posterior distribution}\n        \\Output{Cohort of posterior samples $(\\theta^{(1)},\\theta^{(2)},...,\\theta^{(J)})$}\n\n        \\BlankLine\n\n        \\caption{IF2 \\label{if2}}\n\n    \\end{algorithm}\n\n\n\\section{IF2 Fitting}\n\n    Here we will examine a test case in which IF2 will be used to fit a Susceptible-Infected-Removed (SIR) epidemic model to mock infectious count data.\n\n    As in the previous section, the model in Equation [\\ref{sirode}] was use to produce synthetic data. The same parameters and initial conditions were used, namely: parameter values were set to $\\mathcal{R}_0 = 3.0, \\gamma = 0.1, N = 500$, initial conditions were set to 5 infectious individuals, 495 people susceptible to infection, and no one had yet recovered from infection and been removed, and observation error was taken to be $\\varepsilon_{obs} \\sim \\mathcal{N}(0,\\sigma)$, where individual values were drawn for each synthetic data point.\n\n    Figure [\\ref{mcmcdataplot}] in the previous section shows the true SIR ODE system solution and data.\n\n    The IF2 algorithm was implemented in C++ for speed, and integrated into the R workflow using the Rcpp package.\n\n    There are three primary reasons we implemented our own version of IF2 instead of using POMP. First, POMP does not provide final particle state distributions, making it difficult to calibrate the algorithm parameters against the parameters used in RStan (this procedure is described in the next chapter). Second, it is prudent to cross-check the validity of an algorithm using another implementation. Third, this code can then serve as a jumping-off point for further development using Graphics Processing Unit acceleration (outlined in Chapter 8). We must acknowledge the disadvantages as well: POMP has been extensively vetted with real-world usage, and using it would require far less work as we would only need to specify the model. That being said, we believe the advantages outweigh the disadvantages in this case, and so have proceeded to develop our own implementation of IF2.\n\t\n\tFigure [\\ref{if2kernelplot}] shows the final kernel estimates for four of the key parameters. As with HMC, the distributions are not perfect, but are promising. Unlike with HMC, these distributions are not meant to consist of samples from the true posterior distribution, but rather serve a diagnostic role.\n\n    \\begin{figure}\n        \\centering\n        \\captionsetup{width=0.8\\linewidth}\n        \\includegraphics[width=0.8\\textwidth]{./images/if2kernels.pdf}\n        \\caption{Kernel estimates for four essential system parameters. True values are indicated by dashed lines. \\label{if2kernelplot}}\n    \\end{figure}\n", "meta": {"hexsha": "8d0d95846d10fdc64ac2860473ba89ce8b6ed842", "size": 13367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writing/PF-IF2/pf-text.tex", "max_stars_repo_name": "dbarrows/epidemic-forecasting", "max_stars_repo_head_hexsha": "a0865fa20c992dc4159e79bb332500e3ff2357ae", "max_stars_repo_licenses": ["MIT"], "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/PF-IF2/pf-text.tex", "max_issues_repo_name": "dbarrows/epidemic-forecasting", "max_issues_repo_head_hexsha": "a0865fa20c992dc4159e79bb332500e3ff2357ae", "max_issues_repo_licenses": ["MIT"], "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/PF-IF2/pf-text.tex", "max_forks_repo_name": "dbarrows/epidemic-forecasting", "max_forks_repo_head_hexsha": "a0865fa20c992dc4159e79bb332500e3ff2357ae", "max_forks_repo_licenses": ["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.7827868852, "max_line_length": 887, "alphanum_fraction": 0.7009052143, "num_tokens": 3260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6037428175268171}}
{"text": "\\section{Washburn's Algorithm}\n\nWe have attempted to break down Washburn's algorithm and explain it in\nsomewhat more detail than he does in his paper. Readers should be\nwarned that we use different notation and our $i,j$ indices are\ntransposed from his.\n\nWashburn notes that the problem can be conceived as that of finding\nthe appropriate links to draw between the two parts of a bipartite\ngraph with Area nodes on one side and Resource nodes on the other. For\nexample, in Figure \\ref{Fig:wbnodes} there are 4 areas (index $i$) and\n3 resources (index $j$).\n\\begin{figure}[htbp]\n  \\begin{center}\n    \\includegraphics{wbnodes.eps}\n    \\caption{Illustration of the nodes in a Washburn graph. Any link between A and R is an allocation of resource $j$ to area $i$.}\n    \\label{fig:wbnodes}\n  \\end{center}\n\\end{figure}\nIn his paper, Washburn proves that an optimal allocation will involve\nno cycles in the graph. That proof is what makes his algorithm\npossible.\n\n\n\\subsection{Initialization Step}\n\\label{sec:init}\nTo start the algorithm, choose an initial set of links and initialize\nsome variables. Let $G$ be the corresponding graph.\n\\begin{enumerate}\n\\item Choose an initial set of links (corresponding to combinations\n  which would have $t_{ij} > 0)$ if we used this as our allocation) such that:\n  \\begin{enumerate}\n  \\item Each resource is assigned. $\\forall T_j > 0, \\exists i :\n    t_{ij} > 0$\n  \\item If $t_{ij} > 0$, $w_{ij} > 0$. Otherwise the algorithm breaks.\n  \\item $G$ is a forest. (It contains no cycles.)\n  \\end{enumerate}\n\\item Let $\\Delta_1 = 0$  \\fbox{Necessary?}\n\\item Let $p = 1$. \\fbox{Necessary?}\n\\end{enumerate}\n\nWe have made an arbitrary resource allocation. A fine choice is to\nallocate all resources to area 1. Washburn initially allocates all\nresources to some highly improbable fake area. It does not seem to be\nimportant. \n\nThe overview is that with each iteration we update our choices by\ndeleting some links and adding others. In Washburn's paper, he\ncalculates the resulting $t_ij$ at every step. However, that appears\nto be unnecessary. Note that we do not calculate or specify them for\nthis initialization step.\n\n\n\\subsection{Step 1}\n\\label{sec:step1}\n\n\n\\subsection{Step 2: Construct $\\lambda$ and $\\mu$}\n\\label{sec:step2}\nConstruct vectors $\\lambda$ and $\\mu$ such that:\n\\begin{enumerate}\n\\item $\\lambda_j = w_{ij}\\mu_i$ for every edge $(ij)$ in $G$\n\\item $\\lambda_j > 0, j = 1..R$\n\\item $\\mu_i > 0, i = 1..A$\n\\end{enumerate}\nYou are free to set your initial $\\mu$ to 1. The $\\mu$s correspond to\nareas, and the $\\lambda$s correspond to resources. If there are any\njoins in the graph (several resources assigned to the same area, or\nseveral areas served by the same resource), there will be some\nconstraints on your choice of $\\mu$. However, because there will be no\ncycles, you can just walk the tree of nearest neighbors from your\nfirst node setting things as you go. We have sample MATLAB code that\ndoes this.\n\n\n\\subsection{Section 3: Find the $\\alpha$s}\n\\label{sec:alpha}\n\nThe graph $G$ may not be connected.\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: master\n%%% End: \n\n\n", "meta": {"hexsha": "aa4093ceef55746b1c20810ecdbb80fcecfe26f0", "size": 3118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SORAL/Documentation/Latex/algorithm.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/algorithm.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/algorithm.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.8390804598, "max_line_length": 131, "alphanum_fraction": 0.7389352149, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6037428142208188}}
{"text": "\\chapter{Chapter 3. Elementary Set Theory}\n\n\\section*{3.9 Self-Study Questions}\n\n\t\\begin{enumerate}\n\t\n\t\t\\item[3.9.1] (a) is the definition of $X\\subseteq Y$. Note that (d) is equivalent to (a): if there exists no $x\\in X$ such that $x\\notin Y$, then every $x\\in X$ must also be in $Y$. Why? Well, can you find a counterexample? (h) is perhaps the most difficult to see to be correct. Also here it helps to think whether you can find a counterexample if (h) holds. Suppose that $X\\nsubseteq Y$ and that (h) holds. That $X\\nsubseteq Y$ means that there exists an $x\\in X$ and $x\\notin Y$. And (h) says that every $x\\notin Y$ is also such that $x\\notin X$. This would mean that some $x$ would need to be both such that $x\\in Y$ and $x\\notin X$, which is impossible. Hence $X\\nsubseteq Y$ cannot be and we have to have $X\\subseteq Y$, instead.\n\t\t\n\t\t\\item[3.9.2] (e) is the only correct answer.\n\t\t\n\t\t\\item[3.9.3] (a) is correct by the axiom of extensionality. (b) is not correct, since we might have, for example, \\emph{one} element which is in both sets (and hence in the one iff in the other), but \\emph{another} which is only in one and not the other (and hence the sets are different). (c) is more or less obviously not enough. (d) can be seen to be correct by the reasoning from 3.9.1.(d). (e) is not correct since it's not enough that we can ``pair'' the elements, they need to be the same. And (f) is too weak, it only implies $X\\subseteq Y$.\n\t\t\n\t\t\\item[3.9.4] Remember that two sets are distinct as soon as they have different members.\n\t\n\t\t\\item[3.9.5--3.9.8] The correct answers follow immediately from the definitions of $\\cap$ and $\\cup$. Note that in logic and mathematics, we read ``or'' inclusively and therefore (e) is also correct in 3.9.5. Note further that to say that it's not the case that one thing or the other is the case is to say that both are not the case. Similarly, to say that it's not the case that two things are the case is to say that at least one of them is not the case. This, hopefully, helps with 3.9.6 and 3.9.8. \n\t\t\n\t\t\\item[3.9.9] The correct answers follow directly from the conditions on what a function needs to do.\n\t\t\n\t\t\\item[3.9.10] Remember from 3.6.11 that $\\{f(x):x\\in X'\\}$ for $f:X\\to Y$ and $X'\\subseteq X$ is defined as the set $\\{y:\\text{there exists a }x\\in X'\\text{, such that }y=f(x)\\}$. This means that an element $m$ is not in the set $\\{n^2:n\\in\\mathbb{N}\\text{ and }0\\leq n\\leq 10\\}$ just in case it's not the case that there exists an $n\\in\\mathbb{N}$ such that $0\\leq n\\leq 10$ and $m=n^2$. But that's just the same as (b). Note that (a) is not correct since $4\\in \\{n^2:n\\in\\mathbb{N}\\text{ and }0\\leq n\\leq 10\\}$ since $0\\leq 2\\leq 4$ and $2^2=4$ but there exists nine numbers $0\\leq n\\leq 10$ with $n^2\\neq 4$: $0^2=0, 1^2=1, 3^2=9, \\mathellipsis, 10^2=100$. \n\t\n\t\\end{enumerate}\n\n\\section*{3.10 Exercises}\n\n\t\\begin{itemize}\n\n\t\\item[3.10.1]\n\t\n\t\\begin{enumerate}[(a)]\n\t\t    \\item $\\{1,3\\}$\n \t\t   \\item $\\{1,2,3,5\\}$\n \t\t   \\item $X\\setminus Y = \\{2\\},\\ Y\\setminus X = \\{5\\}$\n   \t\t \\item $\\wp(X) = \\{\\emptyset,\\{1\\},\\{2\\},\\{3\\}, \\{1,2\\},\\{1,3\\},\\{2,3\\},\\{1,2,3\\}\\}$\\\\$\\wp(Y)=\\{\\emptyset,\\{1\\},\\{3\\},\\{5\\}, \\{1,3\\},\\{1,5\\},\\{3,5\\},\\{1,3,5\\}\\} $\n   \t\t \\item $X \\times Y = \\{(1,1),(1,3),(1,5),(2,1),(2,3),(2,5),(3,1),(3,3),(3,5)\\}$\\\\$Y \\times X = \\{(1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(5,1),(5,2),(5,3)\\}$\n\t\t\\end{enumerate}\n\n      \\item[3.10.2]\n\n        \\begin{enumerate}[(a)]\n\n          \\item To prove $X\\subseteq Y$ iff $X\\cup Y = Y$, we need to prove both directions.\\\\$\\Rightarrow\\\\ to\\ prove:\\\\$If $ X\\subseteq Y,\\ $then $ X\\cup Y = Y \\\\$ Suppose $X \\subseteq Y$. We'll show that $X \\cup Y = Y$. To show this, we must prove two things:\n\n                \\begin{enumerate}[(i)]\n                  \\item $Y \\subseteq X \\cup Y$: from the definition of union follows that $X\\cup Y$ consists of all elements in $X$ and all elements in $Y$, hence all elements in $Y$ are in $X\\cup Y$, which is what we needed to show.\n                  \\item $X\\cup Y \\subseteq Y$ Let $x$ be an arbitrary element of $X \\cup Y$.\n                        By the definition of union, we know that $x \\in Y$ or $X \\in X$.\n                        We now make a distinction by cases (see \\S2.3.9).\n                        When $x \\in Y$, we are fine, as we want to show that $x \\in Y$.\n                        When $x \\in X$, we know by our assumption that $X\\subseteq Y$, that $x \\in Y$.\n                        Therefore all $x \\in X\\cup Y$ are in $Y$, therefore $X\\cup Y \\subseteq Y$.\n                \\end{enumerate}\n            Using the axiom of Extensionality, we can now conclude that $X \\cup Y = Y$. \\\\\\\\\n            $\\Leftarrow\\\\to\\ prove:$\\\\If $X\\cup Y=Y$, then $X\\subseteq Y$. We'll prove the contrapositive. We assume that $X \\not \\subseteq Y$. Hence there must be some element $x\\in X$ such that $x\\not \\in Y$. As $X \\cup Y$ contains all elements of $X$, it must also contain $x$. As there's one element that is in $X\\cup Y$ and not in $Y$, $X \\cup Y \\neq Y$, which is what we needed to prove.\\\\\\\\ As we've now proved both directions, we've proved $X\\subseteq Y$ iff $X\\cup Y = Y \\square$\n\n          \\item  We aim to show that $X \\subseteq Y$ iff $X \\cap Y = X$. To prove this we need to prove both sides of the biconditional:\n            \\begin{itemize}\n              \\item $\\Rightarrow$. We need to show that if $X \\subseteq Y$ then  $X \\cap Y = X$. So, assume $X \\subseteq Y$.\n                We want to show that $X \\cap Y = X$.\n                By extionsionality, we must show two things:\n                \\begin{itemize}\n                  \\item First, we need to show that $X \\cap Y \\subseteq X$.\n                    So, let an element $x \\in X \\cap Y$.\n                    That means, by definition of $\\cap$, that $x \\in X$ and $x \\in Y$.\n                    But then certainly, $x \\in X$, as desired.\n                  \\item Second, we need to show that $X \\subseteq X \\cap Y$.\n                    So, let an element $x \\in X$.\n                    We have assumed that $X \\subseteq Y$,\n                    from which it follows that $x \\in Y$.\n                    As such we have $x \\in X$ and $x \\in Y$, which means, by definition of $\\cap$, that $x \\in X \\cap Y$.\n                \\end{itemize}\n\n                By the axiom of extensionality we can conclude $X \\cap Y = X$.\n\n              \\item $\\Leftarrow$. We need to show that if $X \\cap Y = X$, then $X \\subseteq Y$.\n                We do a proof by contraposition.\n                So, assume $X \\not \\subseteq Y$.\n                That means there is an element $x \\in X$ for which $x \\not \\in Y$.\n                If $x \\not \\in Y$, then $x \\not \\in X \\cap Y$.\n                So $X \\not \\subseteq X \\cap Y$ (because there is an $x \\in X$ for which $x \\not \\in X \\cap Y$) so $X \\not = X \\cap Y$.\n\n            \\end{itemize}\n\nWe have now proved both directions, so $X \\subseteq Y$ iff $X \\cap Y = X$.\n\n\\end{enumerate}\n\\item[3.10.3] \\\n\\begin{enumerate}\n    \\item $\t\\begin{matrix}\n\t\t(1,1) && \\overset{f}{\\mapsto} && 1 \\\\ \n\t\t(1,2) && \\overset{f}{\\mapsto} && 1 \\\\ \n\t\t(1,3) && \\overset{f}{\\mapsto} && 1 \\\\\n\t\\end{matrix} \n\t\\qquad\t\n\t\\begin{matrix}\n\t\t(2,1) && \\overset{f}{\\mapsto} && 1 \\\\\n\t\t(2,2) && \\overset{f}{\\mapsto} && 2\\\\\n\t\t(2,3) && \\overset{f}{\\mapsto} && 2\\\\\n\t\\end{matrix}\n\t\\qquad\n\t\t\\begin{matrix}\n \t\t(3,1)&& \\overset{f}{\\mapsto} && 1\\\\\n\t\t(3,2)&& \\overset{f}{\\mapsto} && 2\\\\\n\t\t(3,3) && \\overset{f}{\\mapsto} && 3\\\\\n\t\\end{matrix}$\n\t\\item $\\begin{array}{c|ccc}\n\t\tf & 1 & 2 & 3 \\\\ \\hline\n\t\t1 & 1& 1& 1 \\\\\n\t\t2 & 1 & 2 &2 \\\\\n\t\t3 & 1 & 2 & 3 \n\t\\end{array}$\n\t\\item \t$\n\tf((x, y)) = \n\t\\begin{cases}\n\tx \\text{ if } x < y,\\\\\n\ty \\text{ otherwise}\n\t\\end{cases}\n\t$\n\\end{enumerate}{}\n\n      \\item[3.10.5] We want to prove that $f(n,m) = n + m$ for all $n, m \\in \\mathbb{N}$.\n        We use the principal of mathematical induction.\n        \\emph{Base case}:\n        We need to show that $f(n,0) = n + 0$.\n        By the definition $f(n,0) = n$.\n        It is trivial that $n = n + 0$.\n        \\emph{Induction step}:\n        We need to show that for all $n, m \\in \\mathbb{N}$,\n        if $f(n,m)=n+m$, then $f(n,m+1)=(n+m)+1$.\n        So, let $n, m \\in \\mathbb{N}$.\n        Assume the induction hypothesis that $f(n,m) = n + m$ (IH).\n        Consider $f(n, m + 1)$.\n        By the definition $f(n,m+1) = f(n,m) + 1$.\n        By the IH and get $f(n,m+1) = n + m + 1$, which is what we had to show.\n        By the principle of mathematical induction,\n        we conclude that for all $n, m \\in \\mathbb{N}$ it is true that $f(n,m) = n + m$.\n\n\\item[3.10.7]\n\\begin{enumerate}[(a)]\n    \\item \n    $l: Gargle \\rightarrow \\mathbb{N}$:\\begin{enumerate}[(i)]\n        \\item \\begin{enumerate}[(a)]\n            \\item $l(\\clubsuit) = 1$\n        \\item $l(\\spadesuit) = 1$\n        \\end{enumerate}\n        \\item \\begin{enumerate}[(a)]\n            \\item $l(\\Diamond x\\Diamond)= l(x) + 2$\n            \\item $l(x\\heartsuit y)= l(x)+l(y)+1 $\n        \\end{enumerate}\n    \\end{enumerate}\n\n\n    \\item     $\\textbf{1}_\\heartsuit: Gargle \\rightarrow \\{0,1\\}$:\\begin{enumerate}[(i)]\n        \\item    $\\textbf{1}_\\heartsuit(\\clubsuit) =\\textbf{1}_\\heartsuit(\\spadesuit) = 0$\n        \\item \\begin{enumerate}[(a)]\n            \\item $\\textbf{1}_\\heartsuit(\\Diamond x\\Diamond)= \\textbf{1}_\\heartsuit(x)$\n            \\item $\\textbf{1}_\\heartsuit (x\\heartsuit y)= 1$\n        \\end{enumerate}\n    \\end{enumerate}\n\\end{enumerate}\n\\item[3.10.8] We will prove by induction that the amount of $\\Diamond$'s in a gargle is always even.\n\\begin{enumerate}[(i)]\n    \\item Base case 1: $\\spadesuit$ has an even number of $\\Diamond$'s, as 0 is even.\nBase case 2: $\\clubsuit$ has an even number of $\\Diamond$'s, as 0 is even.\n\\item \\begin{enumerate}[(a)]\n    \\item Assume $x$ has an even number of $\\Diamond$'s.Then $\\Diamond x \\Diamond$ must also have an even number of $\\Diamond$'s, as the number of $\\Diamond$'s of $\\Diamond x \\Diamond$ is the number of $\\Diamond$'s of $x$+2. We know that an even number +2 results in another even number.\n    \\item Assume $x,\\ y$ have an even number of $\\Diamond$'s. Then the number of $\\Diamond$'s of $x\\heartsuit y$ will be the number of $\\Diamond$'s of $x$ + the number of $\\Diamond$'s of $y$, which will be an even number, as an even number added to an even number results in an even number, which is what we needed to show.\\\\\n\\end{enumerate}\n\\end{enumerate}\n    By means of induction we've now proved that the number of $\\Diamond$'s in a Gargle is always even. \n\\item[3.10.9]\nWe will prove that $\\spadesuit\\Diamond\\heartsuit\\spadesuit \\not \\in Gargle$. We have just proven that every gargle has an even amount of $\\Diamond$, but this one has exactly 1, and $1 = 0 \\cdot 2 + 1$. Therefore 1 is odd, and not even. So we must conclude it's not a Gargle.\n\\end{itemize}\t\n\t\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../../logic.tex\"\n%%% End:\n", "meta": {"hexsha": "fac5a2a5a2fd783de8c8910037798f5d7adcacce", "size": 10826, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/notes/tex/appendix/ans-fund-sets.tex", "max_stars_repo_name": "jkorb/logic-introduction", "max_stars_repo_head_hexsha": "316ff2b8c60d98c63df528a75baddda156d8a27b", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-09-12T17:29:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T08:03:21.000Z", "max_issues_repo_path": "lib/notes/tex/appendix/ans-fund-sets.tex", "max_issues_repo_name": "jkorb/logic-introduction", "max_issues_repo_head_hexsha": "316ff2b8c60d98c63df528a75baddda156d8a27b", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2020-09-04T16:24:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-18T13:54:07.000Z", "max_forks_repo_path": "lib/notes/tex/appendix/ans-fund-sets.tex", "max_forks_repo_name": "jkorb/logic-introduction", "max_forks_repo_head_hexsha": "316ff2b8c60d98c63df528a75baddda156d8a27b", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-09-04T08:49:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-30T11:24:44.000Z", "avg_line_length": 60.8202247191, "max_line_length": 737, "alphanum_fraction": 0.5874745982, "num_tokens": 3721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834732, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.6037428020784962}}
{"text": "\\section{Polar Coordinates}\\label{sec:PolarCoordinates}\nCoordinate systems are tools that let us use algebraic methods to\nunderstand geometry. While the \\dfont{rectangular} (also called\n\\dfont{Cartesian}) coordinates that we\nhave been using are the most common, some problems are easier to\nanalyze in alternate coordinate systems. \\index{Cartesian coordinates} \\index{rectangular coordinates}\n\nA coordinate system is a scheme that allows us to identify any point\nin the plane or in three-dimensional space by a set of numbers. In\nrectangular coordinates these numbers are interpreted, roughly\nspeaking, as the lengths of the sides of a rectangle. \nIn \\dfont{polar coordinates}\\index{polar coordinates} a \npoint in the plane is identified by a pair of numbers $(r,\\theta)$.\nThe number $\\theta$ measures the angle between the positive\n$x$-axis and a ray that goes through the point,\nas shown in Figure~\\ref{fig:polar coordinates}; the number\n$r$ measures the distance from the origin to the\npoint (the radius). Figure~\\ref{fig:polar coordinates} shows the point with\nrectangular coordinates $\\ds (1,\\sqrt3)$ and polar coordinates \n$(2,\\pi/3)$, 2 units from the origin and $\\pi/3$ radians from the\npositive $x$-axis.\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%%\\ninepoint\n\\setcoordinatesystem units <15truemm,15truemm>\n\\setplotarea x from 0 to 1.25, y from 0 to 1.9\n\\axis left ticks length <2pt> withvalues \n  {1.728} / at 1.728 / /\n\\axis bottom ticks length <2pt> withvalues {$1$} / at 1 / /\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.2 2.078\n\\put {$(2,\\pi/3)$} [l] <3pt,0pt> at 1 1.73\n\\put {$\\bullet$} at 1 1.728\n\\circulararc 60 degrees from 0.2 0 center at 0 0\n\\endpicture}}\n\\caption{Polar coordinates of the point $\\ds (1,\\sqrt3)$. \\label{fig:polar coordinates}}\n\\endfigure\n\nJust as we describe curves in the plane using equations involving $x$\nand $y$, so can we describe curves using equations involving $r$ and\n$\\theta$. Most common are equations of the form $r=f(\\theta)$.\n\n\\begin{example}{Circle in Polar Coordinates}{circleinpolar}\n Graph the curve given by $r=2$. \n\\end{example}\n\n\\begin{solution}\nAll points with $r=2$ are at\ndistance 2 from the origin, so $r=2$ describes the circle of radius 2\nwith center at the origin.\n\\end{solution}\n\n\\begin{example}{Cardioid}{cardiodexample}\n Graph the curve given by $r=1+\\cos\\theta$. \n\\end{example}\n\n\\begin{solution}\nWe first consider\n$y=1+\\cos x$, as in figure~\\ref{fig:cardioid}. As $\\theta$ goes\nthrough the values in $[0,2\\pi]$, the value of $r$ tracks the value of\n$y$, forming the ``cardioid'' \nshape of  figure~\\ref{fig:cardioid}.\nFor example, when $\\theta=\\pi/2$, $r=1+\\cos(\\pi/2)=1$, so we graph the\npoint at distance 1 from the origin along the positive $y$-axis, which\nis at an angle of $\\pi/2$ from the positive $x$-axis. When\n$\\theta=7\\pi/4$, $\\ds r=1+\\cos(7\\pi/4)=1+\\sqrt2/2\\approx 1.71$, and the\ncorresponding point appears in the fourth quadrant. If we look at the curve, we should explain the indentation which occurs at $\\theta=\\pi$. It should be obvious that $\\cos x<0$ on $(\\pi/2,3\\pi/2)$, thus $r=1+\\cos\\theta<1$. Specifically, when $\\theta=\\pi$, $\\cos\\pi=-1$, so $r=0$, and we get the resulting indentation. This illustrates\none of the potential benefits of using polar coordinates: the equation\nfor this curve in rectangular coordinates would be \\emph{quite} complicated.\n\\end{solution}\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%%\\ninepoint\n\\setcoordinatesystem units <12truemm,12truemm>\n\\setplotarea x from 0 to 6.2832, y from 0 to 2.2\n\\axis left ticks length <2pt> numbered from 0 to 2 by 1 /\n\\axis bottom ticks length <2pt> withvalues \n  {$\\pi/2$} {$\\pi$} {$3\\pi/2$} {$2\\pi$} / at 1.57 3.14 4.7 6.28 / /\n\\multiput {$\\bullet$} at 1.57 1 5.5 1.71 /\n\\setquadratic\n\\plot\n0.000 2.000 0.105 1.995 0.209 1.978 0.314 1.951 0.419 1.914 \n0.524 1.866 0.628 1.809 0.733 1.743 0.838 1.669 0.942 1.588 \n1.047 1.500 1.152 1.407 1.257 1.309 1.361 1.208 1.466 1.105 \n1.571 1.000 1.676 0.895 1.780 0.792 1.885 0.691 1.990 0.593 \n2.094 0.500 2.199 0.412 2.304 0.331 2.409 0.257 2.513 0.191 \n2.618 0.134 2.723 0.086 2.827 0.049 2.932 0.022 3.037 0.005 \n3.142 0.000 3.246 0.005 3.351 0.022 3.456 0.049 3.560 0.086 \n3.665 0.134 3.770 0.191 3.875 0.257 3.979 0.331 4.084 0.412 \n4.189 0.500 4.294 0.593 4.398 0.691 4.503 0.792 4.608 0.895 \n4.712 1.000 4.817 1.105 4.922 1.208 5.027 1.309 5.131 1.407 \n5.236 1.500 5.341 1.588 5.445 1.669 5.550 1.743 5.655 1.809 \n5.760 1.866 5.864 1.914 5.969 1.951 6.074 1.978 6.178 1.995 \n6.283 2.000 /\n\\setcoordinatesystem units <12truemm,12truemm> point at -8 -1\n\\setplotarea x from -1 to 2.5, y from -1.5 to 1.5\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 /\n\\put {$\\bullet$} at 0 1\n\\put {$\\bullet$} at 1.207 -1.207\n\\setquadratic\n\\plot 2.000 0.000 1.984 0.208 1.935 0.411 1.856 0.603 1.748 0.778 \n1.616 0.933 1.464 1.063 1.295 1.166 1.117 1.240 0.933 1.285 \n0.750 1.299 0.572 1.285 0.405 1.245 0.251 1.182 0.115 1.098 \n-0.000 1.000 -0.094 0.891 -0.165 0.775 -0.214 0.657 -0.241 0.542 \n-0.250 0.433 -0.242 0.333 -0.221 0.246 -0.191 0.172 -0.155 0.112 \n-0.116 0.067 -0.079 0.035 -0.047 0.015 -0.021 0.005 -0.005 0.001 \n0.000 0.000 -0.005 -0.001 -0.021 -0.005 -0.047 -0.015 -0.079 -0.035 \n-0.116 -0.067 -0.155 -0.112 -0.191 -0.172 -0.221 -0.246 -0.242 -0.333 \n-0.250 -0.433 -0.241 -0.542 -0.214 -0.657 -0.165 -0.775 -0.094 -0.891 \n0.000 -1.000 0.115 -1.098 0.251 -1.182 0.405 -1.245 0.572 -1.285 \n0.750 -1.299 0.933 -1.285 1.117 -1.240 1.295 -1.166 1.464 -1.063 \n1.616 -0.933 1.748 -0.778 1.856 -0.603 1.935 -0.411 1.984 -0.208 \n2.000 0.000 /\n\\setdashes\n\\arrow <4pt> [0.35, 1] from 0 0 to 1.207 -1.207\n\\endpicture}}\n\\caption{A cardioid: $y=1+\\cos x$ on the left, $r=1+\\cos\\theta$ on the right.\\label{fig:cardioid}}\n\\endfigure\n\nEach point in the plane is associated with exactly one pair of numbers\nin the rectangular coordinate system; each point is associated with an\ninfinite number of pairs in polar coordinates. In the cardioid example,\nwe considered only the range $0\\le \\theta\\le2\\pi$, and\nalready there was a duplicate: $(2,0)$ and $(2,2\\pi)$ are the same\npoint. Indeed, every value of $\\theta$ outside the interval $[0,2\\pi)$\nduplicates a point on the curve $r=1+\\cos\\theta$ when\n$0\\le\\theta<2\\pi$. We can even make sense of polar coordinates like\n$(-2,\\pi/4)$: Go to the direction $\\pi/4$ and then move a distance 2\nin the opposite direction; see figure~\\ref{fig:negative r\ncoordinate}. As usual, a negative angle $\\theta$ means an angle\nmeasured clockwise from the positive $x$-axis. The point in\nfigure~\\ref{fig:negative r coordinate} also has coordinates\n$(2,5\\pi/4)$ and $(2,-3\\pi/4)$.\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\eightpoint\n\\setcoordinatesystem units <10truemm,10truemm>\n\\setplotarea x from -2 to 2, y from -2 to 2\n\\axis left shiftedto x=0 ticks length <2pt> \n  withvalues $-2$ $-1$ {} $1$ $2$ / quantity 5 /\n\\axis bottom shiftedto y=0 ticks length <2pt> \n  withvalues $-2$ $-1$ {} $1$ $2$ / quantity 5 /\n\\put {$\\pi/4$} [bl] <3pt,-4pt> at 0.4 0.3\n\\put {$\\bullet$} at -1.4142 -1.4142\n\\circulararc 45 degrees from 0.4 0 center at 0 0\n\\setdashes\\arrow <4pt> [0.35, 1] from 1 1 to -1.4142 -1.4142\n\\endpicture}}\n\\caption{The point $(-2,\\pi/4)=(2,5\\pi/4)=(2,-3\\pi/4)$ in polar coordinates.\\label{fig:negative r coordinate}}\n\\endfigure\n\nThe relationship between rectangular and polar coordinates is quite easy to\nunderstand. The point with polar coordinates $(r,\\theta)$ has\nrectangular coordinates $x=r\\cos\\theta$ and $y=r\\sin\\theta$; this\nfollows immediately from the definition of the sine and cosine\nfunctions. Using figure~\\ref{fig:negative r coordinate} as an example, the point shown has rectangular coordinates \n$\\ds x=(-2)\\cos(\\pi/4)=-\\sqrt2\\approx 1.4142$ and \n$\\ds y=(-2)\\sin(\\pi/4)=-\\sqrt2$.  This makes it very easy to convert\nequations from rectangular to polar coordinates. \\index{polar coordinates!convert to rectangular}\n\n\\begin{example}{Straight Line in Polar Coordinates}{StraightLineinPolar}\n Find the equation of the line $y=3x+2$ in polar\ncoordinates.\n\\end{example}\n\n\\begin{solution}\nWe merely substitute: $r\\sin\\theta=3r\\cos\\theta+2$, or \n$\\ds r= {2\\over \\sin\\theta-3\\cos\\theta}$.\n\\end{solution}\n\n\n\\begin{example}{Equation of a Circle}{equationofcircleinpolar}\n Find the equation of the circle $\\ds (x-1/2)^2+y^2=1/4$ in polar\ncoordinates. \n\\end{example}\n\n\\begin{solution}\nAgain substituting:\n$\\ds (r\\cos\\theta-1/2)^2+r^2\\sin^2\\theta=1/4$. A bit of algebra turns this\ninto $r=\\cos(t)$. You should try plotting a few $(r,\\theta)$ values to\nconvince yourself that this makes sense.\n\\end{solution}\n\n\n\\begin{example}{Spiral of Archimedes}{spiralofArchimedes}\n Graph the polar equation $r=\\theta$. \n\\end{example}\n\n\\begin{solution}\nHere the distance from\nthe origin exactly matches the angle, so a bit of thought makes it\nclear that when $\\theta\\ge0$ we get the spiral of \nArchimedes in figure~\\ref{fig:spiral of Archimedes}. When $\\theta<0$, $r$ is also\nnegative, and so the full graph is the right hand picture in the figure.\n\\end{solution}\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\eightpoint\n\\setcoordinatesystem units <5truemm,5truemm>\n\\setplotarea x from -3.4 to 6.5, y from -4.8 to 2\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 /\n\\multiput {$\\bullet$} at 0.54 0.84 0 1.57 -3.14 0 6.28 0 /\n\\put {$(2\\pi,2\\pi)$} [b] <0pt,3pt> at 6.28 0\n\\put {$(\\pi,\\pi)$} [br] <-3pt,0pt> at -3.14 0\n\\put {$(\\pi/2,\\pi/2)$} [br] <-2pt,4pt> at 0 1.57\n\\put {$(1,1)$} [bl] <3pt,0pt> at 0.54 0.84\n\\plot 0.000 0.000 0.104 0.011 0.205 0.044 0.299 0.097 0.383 0.170\n0.453 0.262 0.508 0.369 0.545 0.490 0.561 0.623 0.554 0.762\n0.524 0.907 0.469 1.052 0.388 1.195 0.283 1.332 0.153 1.458\n0.000 1.571 -0.175 1.666 -0.370 1.741 -0.582 1.793 -0.809 1.818\n-1.047 1.814 -1.293 1.779 -1.542 1.712 -1.790 1.612 -2.033 1.477\n-2.267 1.309 -2.487 1.107 -2.689 0.874 -2.868 0.610 -3.020 0.317\n-3.142 0.000 -3.229 -0.339 -3.278 -0.697 -3.287 -1.068 -3.253 -1.448\n-3.174 -1.833 -3.050 -2.216 -2.879 -2.593 -2.663 -2.957 -2.401 -3.304\n-2.094 -3.628 -1.746 -3.922 -1.359 -4.183 -0.936 -4.405 -0.482 -4.582\n0.000 -4.712 0.504 -4.791 1.023 -4.814 1.553 -4.781 2.087 -4.688\n2.618 -4.534 3.139 -4.321 3.644 -4.047 4.125 -3.714 4.575 -3.324\n4.988 -2.880 5.357 -2.385 5.677 -1.845 5.941 -1.263 6.145 -0.646\n6.283 0.000 /\n\\setcoordinatesystem units <5truemm,5truemm> point at -18 0\n\\setplotarea x from -6.5 to 6.5, y from -4.8 to 2\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0 /\n\\multiput {$\\bullet$} at -0.54 0.84 0 1.57 3.14 0 -6.28 0 /\n\\put {$(-2\\pi,-2\\pi)$} [b] <0pt,3pt> at -6.28 0\n\\put {$(-\\pi,-\\pi)$} [bl] <3pt,2pt> at 3.14 0\n\\put {$(-\\pi/2,-\\pi/2)$} [br] <-2pt,4pt> at 0 1.57\n\\put {$(-1,-1)$} [t] <0pt,0pt> at -1.5 -1\n\\plot -6.283 0.000 -6.145 -0.646 -5.941 -1.263 -5.677 -1.845 -5.357 -2.385\n-4.988 -2.880 -4.575 -3.324 -4.125 -3.714 -3.644 -4.047 -3.139 -4.321\n-2.618 -4.534 -2.087 -4.688 -1.553 -4.781 -1.023 -4.814 -0.504 -4.791\n0.000 -4.712 0.482 -4.582 0.936 -4.405 1.359 -4.183 1.746 -3.922\n2.094 -3.628 2.401 -3.304 2.663 -2.957 2.879 -2.593 3.050 -2.216\n3.174 -1.833 3.253 -1.448 3.287 -1.068 3.278 -0.697 3.229 -0.339\n3.142 0.000 3.020 0.317 2.868 0.610 2.689 0.874 2.487 1.107\n2.267 1.309 2.033 1.477 1.790 1.612 1.542 1.712 1.293 1.779\n1.047 1.814 0.809 1.818 0.582 1.793 0.370 1.741 0.175 1.666\n0.000 1.571 -0.153 1.458 -0.283 1.332 -0.388 1.195 -0.469 1.052\n-0.524 0.907 -0.554 0.762 -0.561 0.623 -0.545 0.490 -0.508 0.369\n-0.453 0.262 -0.383 0.170 -0.299 0.097 -0.205 0.044 -0.104 0.011\n0.000 0.000 0.104 0.011 0.205 0.044 0.299 0.097 0.383 0.170\n0.453 0.262 0.508 0.369 0.545 0.490 0.561 0.623 0.554 0.762\n0.524 0.907 0.469 1.052 0.388 1.195 0.283 1.332 0.153 1.458\n0.000 1.571 -0.175 1.666 -0.370 1.741 -0.582 1.793 -0.809 1.818\n-1.047 1.814 -1.293 1.779 -1.542 1.712 -1.790 1.612 -2.033 1.477\n-2.267 1.309 -2.487 1.107 -2.689 0.874 -2.868 0.610 -3.020 0.317\n-3.142 0.000 -3.229 -0.339 -3.278 -0.697 -3.287 -1.068 -3.253 -1.448\n-3.174 -1.833 -3.050 -2.216 -2.879 -2.593 -2.663 -2.957 -2.401 -3.304\n-2.094 -3.628 -1.746 -3.922 -1.359 -4.183 -0.936 -4.405 -0.482 -4.582\n0.000 -4.712 0.504 -4.791 1.023 -4.814 1.553 -4.781 2.087 -4.688\n2.618 -4.534 3.139 -4.321 3.644 -4.047 4.125 -3.714 4.575 -3.324\n4.988 -2.880 5.357 -2.385 5.677 -1.845 5.941 -1.263 6.145 -0.646\n6.283 0.000 /\n\\setdashes <2pt>\n\\setlinear\n\\plot -2 -0.9 -0.54 0.84 /\n%\\altarrow <4pt,5pt> [0.35, 1] from -2 -0.9 to -0.54 0.84\n\\endpicture}}\n\\caption{The spiral of Archimedes and the full graph of $r=\\theta$.\\label{fig:spiral of Archimedes}}\n\\endfigure\n\nConverting polar equations to rectangular equations can be somewhat\ntrickier, and graphing polar equations directly is also not always easy.\n\n\\begin{example}{Graphing Polar Equations}{graphingpolarequations}\n Graph $r=2\\sin\\theta$. \n\\end{example}\n\n\\begin{solution}\nGiven that the sine is periodic, we know\nthat we will get the entire curve for values of $\\theta$ in\n$[0,2\\pi)$. As $\\theta$ runs from 0 to $\\pi/2$, $r$ increases from 0\nto 2. Then as $\\theta$ continues to $\\pi$, $r$ decreases again to\n0. When $\\theta$ runs from $\\pi$ to $2\\pi$, $r$ is negative, and it\nis not hard to see that the first part of the curve is simply traced\nout again, so in fact we get the whole curve for values of $\\theta$\nin $[0,\\pi)$. Thus, the curve looks something like\nfigure~\\ref{fig:circle from polar equation}. Now, this suggests\nthat the curve could possibly be a circle, and if it is, it would\nhave to be the circle $\\ds x^2+(y-1)^2=1$. Having made this guess, we\ncan easily check it. First we substitute for $x$ and $y$ to get\n$\\ds (r\\cos\\theta)^2+(r\\sin\\theta-1)^2=1$; expanding and simplifying\ndoes indeed turn this into $r=2\\sin\\theta$.\n\\end{solution}\n\n\\figure[H]\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%%\\ninepoint\n\\setcoordinatesystem units <15truemm,15truemm>\n\\setplotarea x from -1 to 1, y from 0 to 2.2\n\\axis left shiftedto x=0 ticks length <2pt> numbered from 1 to 1 by 1 /\n\\axis bottom ticks length <2pt> numbered from -1 to 1 by 1 /\n\\circulararc 360 degrees from 1 1 center at 0 1\n\\endpicture}}\n\\caption{Graph of $r=2\\sin\\theta$.\\label{fig:circle from polar equation}}\n\\endfigure\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:PolarCoordinates}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\nPlot these polar coordinate points on one graph:\n$(2,\\pi/3)$, $(-3,\\pi/2)$, $(-2,-\\pi/4)$, $(1/2,\\pi)$, $(1,4\\pi/3)$, \n$(0,3\\pi/2)$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind an equation in polar coordinates that has the same\ngraph as the given equation in rectangular coordinates.\n\\begin{multicols}{3}\n\\begin{enumerate}\n\t\\item\t$\\ds y=3x$\n\t\\item\t$\\ds y=-4$\n\t\\item\t$\\ds xy^2=1$\n\t\\item\t$\\ds x^2+y^2=5$\n\t\\item\t$\\ds y=x^3$\n\t\\item\t$\\ds y=\\sin x$\n\t\\item\t$\\ds y=5x+2$\n\t\\item\t$\\ds x=2$\n\t\\item\t$\\ds y=x^2+1$\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{multicols}{3}\n\\begin{enumerate}\n\t\\item\t$\\ds \\theta=\\arctan(3)$\n\t\\item\t$\\ds r=-4\\csc\\theta$\n\t\\item\t$\\ds r=\\sec\\theta\\csc^2\\theta$\n\t\\item\t$\\ds r=\\sqrt{5}$\n\t\\item\t$\\ds r^2=\\sin\\theta\\sec^3\\theta$\n\t\\item\t$\\ds r\\sin\\theta=\\sin(r\\cos\\theta)$\n\t\\item\t$\\ds r=2/(\\sin\\theta-5\\cos\\theta)$\n\t\\item\t$\\ds r=2\\sec\\theta$\n\t\\item\t$\\ds 0=r^2\\cos^2\\theta-r\\sin\\theta+1$\n\\end{enumerate}\n\\end{multicols}\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\nSketch the following curves:\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$\\ds r=\\cos\\theta$\n\t\\item\t$\\ds r=1+\\theta^1/\\pi^2$\n\t\\item\t$\\ds r=\\sin(\\theta+\\pi/4)$\n\t\\item\t$\\ds r=-\\sec\\theta$\n\t\\item\t$\\ds r=\\theta/2$, $\\theta\\ge0$\n\t\\item\t$\\ds r=\\cot\\theta\\csc\\theta$\n\t\\item\t$\\ds r={1\\over\\sin\\theta+\\cos\\theta}$\n\t\\item\t$\\ds r^2=-2\\sec\\theta\\csc\\theta$\n\\end{enumerate}\n\\end{multicols}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind an equation in rectangular coordinates that has the same\ngraph as the given equation in polar coordinates.\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$\\ds r=\\sin(3\\theta)$\n\t\\item\t$\\ds r=\\sin^2\\theta$\n\t\\item\t$\\ds r=\\sec\\theta\\csc\\theta$\n\t\\item\t$\\ds r=\\tan\\theta$\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$\\ds (x^2+y^2)^2=4x^2y-(x^2+y^2)y$\n\t\\item\t$\\ds (x^2+y^2)^{3/2}=y^2$\n\t\\item\t$\\ds x^2+y^2=x^2y^2$\n\t\\item\t$\\ds x^4+x^2y^2=y^2$\n\\end{enumerate}\n\\end{multicols}\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "2e6436af936cc9bd74ce564ade043e5ea13ee971", "size": 16231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11-polar-coord-parametric-eq/11-1-polar-coordinates.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-1-polar-coordinates.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-1-polar-coordinates.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.7814070352, "max_line_length": 335, "alphanum_fraction": 0.6793789662, "num_tokens": 6850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587586, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.6037303966923018}}
{"text": "% $Id$\n%\n% Author: David Fournier\n% Copyright (c) 2008 Regents of the University of California\n%\n\n\n\\section{The Kalman filter}\n\nThe Kalman filter is a device for estimating parameters in\na class of ``time-series''-like models that are put into state-space\nform. We have used the \nnotation from \\cite{harvey1990}, Chapter~3.\n\\X{state-space form}\n\\X{Kalman filter}\nThe general state-space form is an  multivariate time series\n$$y_t=Z_t\\alpha_t+d_t+\\epsilon_t$$ \nwhere $Z_t$ is an $N\\times m$ matrix, $d_t$ is an $N$-dimensional\nvector, $y_t$ is an $N$-dimensional vector, and $\\epsilon_t$ is\na set of serially uncorrelated $N$-dimensional random vectors\nwith mean $0$ and correlation $H_t$.\nThe elements of $\\alpha_t$ are not observable, but are\nassumed to be generated by a first-order Markov process\n$$\\alpha_t=T_t\\alpha_{t-1}+c_t+R_t\\eta_t$$\nwhere $T_t$ is an $m\\times m$ matrix, $c_t$ is an $m\\times 1$\nvector, $R_t$ is an $m\\times g$ matrix and $\\eta_t$\nis a $g\\times 1$ vector of serially uncorrelated \nrandom vectors with mean $0$ and covariance matrix $H_t$.\nThe specification of the state-space system is completed by\ntwo further assumptions:\n\\begin{enumerate}\n  \\item The initial state vector $\\alpha_0$ has a mean of $a_0$ and a \nvariance of~$P_0$.\n  \\item The random vectors $\\epsilon_t$ and $\\eta_t$ are uncorrelated\nwith each other, and uncorrelated with the initial state.\n\\end{enumerate}\n\nIn applications of the model, many of the\nparameters $Z_t$, $d_t$, $H_t$, $T_t$, $c_t$, $R_t$, and $Q_t$\nmay be independent of $t$, in which case we will write them\nwithout the subscript. Also, $R$ may be the identity matrix,\nin which case we will omit it.\n\nAs a simple example of such a model, consider the (2-dimensional) random walk observed with error: %fixed.\n \\begin{align}\n  \\nonumber \\alpha_t =&\\alpha_{t-1}+\\eta_t\\\\\n   y_t =&\\alpha_t+\\epsilon_t\n \\end{align}\nFor this model, the following parameters are fixed\n$$ T=\\begin{pmatrix}1 & 0\\\\\n                    0 & 1 \\end{pmatrix}\n  \\quad\n   Z=\\begin{pmatrix}1 & 0\\cr\n                    0 & 1 \\end{pmatrix}\n  \\quad\n   R=\\begin{pmatrix}1 & 0\\cr\n                    0 & 1\\end{pmatrix}\n  \\quad\n  d=(0,0)\n  \\quad\n  c=(0,0)\n$$\nwhile the covariance matrices $Q$ and $H$ are estimated. The true values of $Q$ and $H$ used in the simulation were %fixed\n$$\n   Q=\\begin{pmatrix}1 & 0.8\\cr\n                   0.8 & 1 \\end{pmatrix}\n  \\quad\n   H=\\begin{pmatrix}3 & -2.5\\cr\n                   -2.5 & 3 \\end{pmatrix}\n$$\nand the initial value of $a$ is $(0,0)$.%fixed\n \n\\section{Equations for the Kalman filter}\n\nFor a moment, go back to the general state-space model.\nGiven $a_0$ and $P_0$, we recursively calculate the a number of quantities\nvia the relationships\n \\begin{align}\n   \\nonumber  \\aone &= T_t\\, a_{t-1}+c_t\\\\[3pt]\n    \\nonumber   \\Pone &=T_t\\, P_{t-1}\\, T^\\prime_t +R_t\\, Q_t\\, R^\\prime_t\\\\[3pt]\n   \\nonumber    v_t &=y_t-Z_t\\, \\aone-d_t\\\\[3pt]\n    \\nonumber   F_t &=Z_t\\, \\Pone\\, Z_t^\\prime+H_t\\\\[3pt]\n    \\nonumber   a_t &=\\aone-\\Pone\\, Z_t^\\prime\\, F_t^{-1}\\, v_t\\\\[3pt]\n      P_t &= \\Pone-\\Pone\\, Z_t^\\prime\\, F_t^{-1}\\, Z_t\\, \\Pone\n \\end{align}\nThe log-likelihood function for the models parameters is\ngiven by:\n$$\\log L = -\\tfrac{NT}{ 2}\\log 2\\pi -0.5 \\sum_{t=1}^T \\log|F_t|\n        -0.5 \\sum_{t=1}^T v_t F_t^{-1} v_t\n$$\n\nThe \\textsc{tpl} file for the random walk Kalman filter code\nfollows:\n\\begin{lstlisting}\nDATA_SECTION\n  init_int nt\n  init_int N\n  init_int m\n  int m1\n  init_matrix Y(1,nt,1,N)\n  matrix P0(1,m,1,m)\n !! P0.initialize(); \n !! m1=m*(m+1)/2; \nPARAMETER_SECTION\n  init_bounded_vector Qcoff(1,m1,-10.,10.1)\n  init_bounded_vector Hcoff(1,m1,-10.,10.1)\n  init_vector a0(1,m)\n  matrix T(1,m,1,m)\n  matrix TT(1,m,1,m)\n  vector d(1,N)\n  vector c(1,m)\n  matrix chQ(1,m,1,m)\n  sdreport_matrix Q(1,m,1,m)\n  matrix chH(1,N,1,N)\n  sdreport_matrix H(1,N,1,N)\n  matrix Z(1,N,1,m)\n  matrix TZ(1,m,1,N)\n  objective_function_value f\n LOCAL_CALCS\n   d.initialize();\n   c.initialize();\n   Z.initialize();\n   Z(1,1)=1; Z(2,2)=1;\n   T.initialize();\n   T(1,1)=1; T(2,2)=1;\n   TZ=trans(Z);\n   TT=trans(T);\nPROCEDURE_SECTION\n  setup_Q();\n  setup_H();\n  f+=kalman_filter();\n  cout << \" f = \" << f << endl;\n\nFUNCTION setup_Q\n  chQ.initialize();\n  int ii=1;\n  for (int i=1;i<=m;i++)\n    for (int j=1;j<=i;j++)\n      chQ(i,j)=Qcoff(ii++);\n  Q=chQ*trans(chQ);    \nFUNCTION setup_H\n  chH.initialize();\n  int ii=1;\n  for (int i=1;i<=N;i++)\n    for (int j=1;j<=i;j++)\n      chH(i,j)=Hcoff(ii++);\n  H=chH*trans(chH);    \n\nFUNCTION dvariable kalman_filter(void)  \n  dvar3_array P(0,nt,1,m,1,m);\n  dvar3_array P1(1,nt,1,m,1,m);\n  dvar3_array F(1,nt,1,N,1,N);\n  dvar3_array Finv(1,nt,1,N,1,N);\n  dvar_matrix Ptemp(1,m,1,m);\n  dvar_matrix a(0,nt,1,m);\n  dvar_matrix a1(1,nt,1,m);\n  dvar_matrix v(1,nt,1,N);\n  a(0)=a0;\n  P(0)=P0;\n  // This is the Kalman filter recursion. The objects tmp1\n  // and tmp2 hold common calculations to optimize a bit\n  int t;\n  for (t=1;t<=nt;t++)\n  {\n    a1(t)=T*a(t-1)+c;\n    P1(t)=T*P(t-1)*TT+Q;\n    dvar_vector pred_y=Z*a1(t)+d;\n    v(t)=Y(t)-pred_y;\n    dvar_matrix tmp1=P1(t)*TZ;\n    F(t)=Z*tmp1+H;\n    Finv(t)=inv(F(t));\n    dvar_matrix tmp2= tmp1*Finv(t);\n    P(t)=P1(t)-tmp2*Z*P1(t);\n    a(t)=a1(t)+tmp2*v(t);\n  }\n  int sgn=0;\n  dvariable f=0.0;\n  for (t=1;t<=nt;t++)\n    f+=ln_det(F(t),sgn)+v(t)*Finv(t)*v(t);\n  return f;  \nTOP_OF_MAIN_SECTION\n  arrmblsize=20000000;\n  gradient_structure::set_CMPDIF_BUFFER_SIZE(3000000);\n  gradient_structure::set_GRADSTACK_BUFFER_SIZE(1000000);\n\\end{lstlisting} \nThis example was deliberately not optimized as much as it could be,\nin order to retain the flavor of the more general state-space\nproblem. For example, since $T$ is the identity matrix and $c$ is the\nzero vector, the line of code \n\\begin{lstlisting}\n  a1(t)=T*a(t-1)+c;\n\\end{lstlisting} \nreduces to\n\\begin{lstlisting}\n  a1(t)=a(t-1);\n\\end{lstlisting} \nThe parameters being estimated are  $a_0$, $Q$, and~$H$. \n\nTo parameterize the covariance matrices, the Choleski decomposition\nparameterization was used. This ensures that the covariance matrices are\npositive (semi-) definite. The technique can be seen in the function\n\\texttt{setup\\_Q}. \nThe lower triangular matrix \\texttt{ch\\_Q} is filled with parameters\nfrom a bounded vector:\n\\begin{lstlisting}\nFUNCTION setup_Q\n  chQ.initialize();\n  int ii=1;\n  for (int i=1;i<=m;i++)\n    for (int j=1;j<=i;j++)\n      chQ(i,j)=Qcoff(ii++);\n  Q=chQ*trans(chQ);   // chQ is the choleski decomposition of Q \n\\end{lstlisting}\nNotice that the bounded vector \\texttt{Qcoff} has slightly asymmetric\nbounds. This is a simple way to ensure that its initial value is not\nidentically zero, which would lead to a singular covariance matrix.\n\\begin{lstlisting}\n  init_bounded_vector Qcoff(1,m1,-10.,10.1)\n\\end{lstlisting}\n\nThe model parameters, standard deviations, and \ncorrelations are reproduced from the\nstandard \\textsc{admb} report.\n\n\\begin{smallcode}\n index   name    value      std.dev    7      8      9     10     11     12     13     14     15      16   \n    7   a0    -1.1682e+00 9.0191e-01  1.000\n    8   a0     1.2218e+00 8.6442e-01  0.352  1.000\n    9   Q      9.9468e-01 1.0862e-01  0.059 -0.006  1.000\n   10   Q      7.8808e-01 7.8737e-02  0.038  0.028  0.683  1.000\n   11   Q      7.8808e-01 7.8737e-02  0.038  0.028  0.683  1.000  1.000\n   12   Q      8.7279e-01 9.6118e-02 -0.018  0.069  0.185  0.721  0.721  1.000\n   13   H      3.1352e+00 1.8123e-01 -0.015 -0.007 -0.305 -0.136 -0.136 -0.018  1.000\n   14   H     -2.7119e+00 1.4922e-01 -0.021  0.001 -0.102 -0.238 -0.238 -0.139 -0.692  1.000\n   15   H     -2.7119e+00 1.4922e-01 -0.021  0.001 -0.102 -0.238 -0.238 -0.139 -0.692  1.000  1.000\n   16   H      3.2264e+00 1.7936e-01  0.015 -0.029 -0.031 -0.121 -0.121 -0.249  0.370 -0.698 -0.698  1.000\n\\end{smallcode}\n\n\n\\section{Parameterizing the covariance\\br matrix parameterizations}\n\nThe Choleski decomposition parameterization merely ensures that the \nmatrix is positive semi-definite. By adding a small positive number to the\ndiagonal elements, one can ensure that the covariance matrix is\npositive definite, and can speed up and improve the stability of the\nestimation. Of course, what is meant by ``small'' will depend on the\nparticular problem being considered. \nA modified form of the routine \\texttt{setup\\_Q}\nfollows:\n\\begin{lstlisting}\nFUNCTION setup_Q\n  int i;\n  chQ.initialize();\n  int ii=1;\n  for (i=1;i<=m;i++)\n    for (int j=1;j<=i;j++)\n      chQ(i,j)=Qcoff(ii++);\n  Q=chQ*trans(chQ);   // chQ is the choleski decomposition of Q \n  for (i=1;i<=m;i++)\n    Q(i,i)+=0.1;   // make Q positive definite\n\\end{lstlisting}\nPerforming this modification for the present model for both $Q$ and\n$H$ causes the program to converge about twice as fast.\n\n", "meta": {"hexsha": "78916d5aeb9ba153db611595242dc104ff1be0dd", "size": 8687, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/manuals/admb/kalman.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/kalman.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/kalman.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": 32.7811320755, "max_line_length": 122, "alphanum_fraction": 0.6575342466, "num_tokens": 3215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.6757646010190476, "lm_q1q2_score": 0.6036668743688793}}
{"text": "\\subsection{Time Series Decomposition}\n\\label{decomp}\n\nConcerning the time table in Figure \\ref{f:timetable}, a seasonal demand\n    pattern is inherent to both horizontal and vertical time series.\nFirst, the weekday influences if people eat out or order in with our partner\n    receiving more orders on Thursday through Saturday than the other four\n    days.\nThis pattern is part of both types of time series.\nSecond, on any given day, demand peaks occur around lunch and dinner times.\nThis only regards vertical series.\nStatistical analyses show that horizontally sliced time series indeed exhibit\n    a periodicity of $k=7$, and vertically sliced series only yield a seasonal\n    component with a regular pattern if the periodicity is set to the product\n    of the number of weekdays and the daily time steps indicating a distinct\n    intra-day pattern per weekday.\n\nFigure \\ref{f:stl} shows three exemplary STL decompositions for a\n    $1~\\text{km}^2$ pixel and a vertical time series with 60-minute time steps\n    (on the x-axis) covering four weeks:\nWith the noisy raw data $y_t$ on the left, the seasonal and trend components,\n    $s_t$ and $t_t$, are depicted in light and dark gray for increasing $ns$\n    parameters.\nThe plots include (seasonal) na\\\"{i}ve forecasts for the subsequent test day\n    as dotted lines.\nThe remainder components $r_t$ are not shown for conciseness.\nThe periodicity is set to $k = 7 * 12 = 84$ as our industry partner has $12$\n    opening hours per day.\n\n\\begin{center}\n\\captionof{figure}{STL decompositions for a medium-demand pixel with hourly\n                   time steps and periodicity $k=84$}\n\\label{f:stl}\n\\includegraphics[width=.95\\linewidth]{static/stl_gray.png}\n\\end{center}\n\nAs described in Sub-section \\ref{stl}, with $k$ being implied by the\n    application, at the very least, the length of the seasonal smoothing\n    window, represented by the $ns$ parameter, must be calibrated by the\n    forecaster:\nIt controls how many past observations go into each smoothened $s_t$.\nMany practitioners, however, skip this step and set $ns$ to a big number, for\n    example, $999$, then referred to as \"periodic.\"\nFor the other parameters, it is common to use the default values as\n    specified in \\cite{cleveland1990}.\nThe goal is to find a decomposition with a regular pattern in $s_t$.\nIn Figure \\ref{f:stl}, this is not true for $ns=7$ where, for\n    example, the four largest bars corresponding to the same time of day a\n    week apart cannot be connected by an approximately straight line.\nOn the contrary, a regular pattern in the most extreme way exists for\n    $ns=999$, where the same four largest bars are of the same height.\nThis observation holds for each time step of the day.\nFor $ns=11$, $s_t$ exhibits a regular pattern whose bars adapt over time:\nThe pattern is regular as bars corresponding to the same time of day can be\n    connected by approximately straight lines, and it is adaptive as these\n    lines are not horizontal.\nThe trade-off between small and large values for $ns$ can thus be interpreted\n    as allowing the average demand during peak times to change over time:\nIf demand is intermittent at non-peak times, it is reasonable to expect the\n    bars to change over time as only the relative differences between peak and\n    non-peak times impact the bars' heights with the seasonal component being\n    centered around $0$.\nTo confirm the goodness of a decomposition statistically, one way is to verify\n    that $r_t$ can be modeled as a typical error process like white noise\n    $\\epsilon_t$.\n\nHowever, we suggest an alternative way of calibrating the STL method in an\n    automated fashion based on our unified CV approach.\nAs hinted at in Figure \\ref{f:stl}, we interpret an STL decomposition as a\n    forecasting method on its own by just adding the (seasonal) na\\\"{i}ve\n    forecasts for $s_t$ and $t_t$ and predicting $0$ for $r_t$.\nThen, the $ns$ parameter is tuned just like a parameter for an ML model.\nTo the best of our knowledge, this has not yet been proposed before.\nConceptually, forecasting with the STL method can be viewed as a na\\\"{i}ve\n    method with built-in smoothing, and it outperformed all other\n    benchmark methods in all cases.\n", "meta": {"hexsha": "62cb78ba73efbedc8466c22af681d5a62b6827e2", "size": 4232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3_mod/6_decomp.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/3_mod/6_decomp.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/3_mod/6_decomp.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": 54.961038961, "max_line_length": 78, "alphanum_fraction": 0.7566162571, "num_tokens": 1008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6035850971355342}}
{"text": "%!TEX root = main.tex\nWe demonstrate the performance and capability of Bempp-Exafmm via electrostatic simulations, including computing the solvation energy of a Zika virus.\nThis section presents five types of results.\nThe first result explains the behavior of two variants of the mathematical formulation, from the conditioning point of view. \nSecond, we show solution verification through two grid-convergence studies: with a spherical molecule (having an analytical solution), and with a real biomolecule (using Richardson extrapolation).\nThird, we compare our results with those obtained with the APBS package using 8 other molecules.\nThe fourth type of result looks at performance with problem sizes between 8,000 and 2 million elements, including timings, breakdowns, and computational complexity.\nOur final result is a demonstration using a structure with about 1.6 million atoms, the Zika virus, discretized with about 10 million boundary elements.\n\nWe ran all experiments on a single CPU node of \\textit{Pegasus}, a Linux cluster at the George Washington University.\nEach node is equipped with two 20-core Intel Xeon Gold 6148 CPUs (base frequency at 2.4 GHz, max turbo frequency at 3.7 GHz) and 192GB RAM.\nAll runs are based on Bempp-cl version 0.2.2 and Exafmm-t version 0.1.0.\nWe compiled Exafmm with Intel compiler (version 19.0.5.281) and enabled \\texttt{-xHost} option for vectorization.\nWe used the full GMRES from the SciPy library as our linear solver.\n\nIn all of the following test cases, the relative permittivity is $\\epsilon_1 = 4$ in the solute region and $\\epsilon_2 = 80$ in the solvent region, and the inverse of Debye length in the solvent region is $\\kappa = 1/8\\ {\\si{\\angstrom}}^{-1}$.\nWe downloaded the molecule structures from the Protein Data Bank (PDB), parameterized them with \\texttt{pdb2pqr}~\\cite{DolinskyETal2004}, and generated meshes on the solvent-excluded surface (SES) using \\texttt{Nanoshaper} with a probe radius of $1.4 \\si{\\angstrom}$.\n\n\\paragraph{Matrix conditioning of two derivative formulations} \\label{result_conditioning}\nSection \\ref{s:formulation} presents the two formulations to solve the integral equations  \\eqref{eq:volume_potential} derived from the Poisson-Boltzmann model of biomolecular electrostatics: \nthe \\emph{direct}~\\cite{YoonLenhoff1990}  and \\emph{derivative}~\\cite{JufferETal1991} formulations.\nThe latter is well-known to lead to a better-conditioned matrix.\nIts most common solution method finds the potential and its derivative in the interior of the boundary via equations \\eqref{eq:juffer}, but an alternative is to solve for the exterior fields via \\eqref{eq:lu}.\nBempp unfetters the user to experiment with these variants of the boundary element solution method, editing just a few lines of Python.\nWe could easily try both the interior and exterior versions of the derivative formulation, whereas previous publications opted for one method and used it throughout.\nThe programming effort required to implement a second formulation would have been a good reason.\nIn our experiments, the exterior version used by Lu and coworkers~\\cite{LuETal2006,LuETal2009,ZhangETal2019} took about half as many iterations to converge than the interior version---a sizable advantage.\nThis led us to study the properties of the two variants of the derivative formulation in more detail.\nThe results in this section aim to give a simple explanation for the different numerical behavior of the two methods.\nOur ability to explore and explain this issue showcases the power of interactive computing with a high-productivity software platform, like that provided by Bempp-Exafmm.\n\nGMRES methods have an intricate convergence behavior \\cite{mark1999a}.\nHeuristically, if the eigenvalues are clustered with the cluster being sufficiently far away from the origin, we expect fast convergence of GMRES to the desired solution.\nFigures \\ref{fig:derivative_interior_eig} and \\ref{fig:derivative_exterior_eig} show the eigenvalues of the interior and exterior derivative formulations, respectively, on the complex plane.\nWith the interior formulation, eigenvalues cluster around two points, while eigenvalues cluster around only one point with the exterior formulation.\n\nThe difference is due to the diagonal of the corresponding system of integral equations.\nIn the case of the interior formulation, the associated left-hand side operator takes the form\n$$\n\\begin{bmatrix}\\frac{1}{2}(1 + \\frac{\\epsilon_2}{\\epsilon_1})I & 0 \\\\ 0 & \\frac{1}{2}(1 + \\frac{\\epsilon_1}{\\epsilon_2})I\n\\end{bmatrix} + \\mathcal{C}_{int},\n$$\nwhere $\\mathcal{C}_{int}$ is a compact operator on sufficiently smooth domains. (On smooth domains the single-layer, double-layer and adjoint double-layer operators are compact operators.\nFurthermore, the difference of the hypersingular operators is compact \\cite{Hiptmair2006-om}.)\nThe eigenvalues of the interior derivative operator hence accumulate at the points $\\frac{1}{2}(1 + \\frac{\\epsilon_2}{\\epsilon_1})$ and $\\frac{1}{2}(1 + \\frac{\\epsilon_1}{\\epsilon_2})$.\nIn contrast, the exterior derivative operator has the form\n$$\n\\begin{bmatrix}\\frac{1}{2}(1 + \\frac{\\epsilon_1}{\\epsilon_2})I & 0 \\\\ 0 & \\frac{1}{2}(1 + \\frac{\\epsilon_1}{\\epsilon_2})I\n\\end{bmatrix} + \\mathcal{C}_{ext},\n$$\nwhere $\\mathcal{C}_{ext}$ is again a compact operator.\nWe now only have one accumulation point, namely $\\frac{1}{2}(1 + \\frac{\\epsilon_1}{\\epsilon_2})$.\nUnless $\\epsilon_1\\approx \\epsilon_2$ we therefore expect the eigenvalues to be much closer together than in the interior derivative case and therefore the GMRES convergence to be faster for the exterior derivative formulation.\n\nWe want to emphasize that the above argument is valid for the continuous operators.\nUnder discretization, the resulting eigenvalue problem is of the form $A\\mathbf{x}=\\lambda M\\mathbf{x}$ (or equivalently $M^{-1}A\\mathbf{x}=\\lambda \\mathbf{x}$, where $A$ is the $2\\times 2$ block operator associated with the Galerkin discretization of the integral operator system and $M = \\text{diag}(\\hat{M}, \\hat{M})$ is a block diagonal mass matrix, where the matrix $\\hat{M}$ is the matrix containing the surface inner products $\\int_{\\Gamma}\\psi_i(\\mathbf{r})\\phi_j(\\mathbf{r})ds(\\mathbf{r})$ for test functions $\\psi_j$ and trial functions $\\phi_i$ (which are both chosen as continuous, piecewise linear basis functions for the derivative formulation in this paper).\nThe mass-matrix preconditioned linear system of equations to solve has the form $M^{-1}A\\mathbf{x} = M^{-1}\\mathbf{b}$ for vector of unknowns $\\mathbf{x}$ and right-hand side $\\mathbf{b}$ and Figures \\ref{fig:derivative_interior_eig} and \\ref{fig:derivative_exterior_eig} show the eigenvalues of $M^{-1}A$ for the interior and exterior derivative formulation.\nIn practice, the action of $M^{-1}$ can be computed through a sparse LU decomposition of $M$.\nHowever, for problems with millions of unknowns this is becoming expensive.\nFor practical electrostatic computations we have therefore chosen a simple mass lumping approach, in which we substitute $M$ by a diagonal matrix, where each diagonal entry is the sum of the corresponding row values of $M$.\nThis diagonal matrix can then be trivially inverted.\nIn our experiments the mass lumping only led to a modest increase in the number of iterations compared to using the LU decomposition of the mass matrix $M$.\nWe stress that mass matrix preconditioning is necessary to solve the interior and exterior formulations in a reasonable number of iterations.\nThe approximation of the inverse of the mass matrix $M$ through mass lumping only affects the preconditioner and not the solution of the underlying linear system of equations itself.\n\nIn each of the following studies, we present two sets of results: one from using the exterior derivative formulation with piecewise linear elements, preconditioned by a mass lumping matrix, and the other from using the direct formulation with piecewise constant elements, preconditioned by a block-diagonal matrix presented by Altman and co-workers \\cite{AltmanBardhanWhiteTidor2009}.\n\n\n\\begin{figure*}\n    \\begin{center}\n        \\subfloat[][]{\\includegraphics[width=0.4 \\textwidth]{derivative_interior_eig.pdf}\n        \\label{fig:derivative_interior_eig}}\\qquad\n        \\subfloat{\\includegraphics[width=0.4 \\textwidth]{derivative_exterior_eig.pdf}\n        \\label{fig:derivative_exterior_eig}}\n    \\end{center}\n    \\caption{Eigenvalues of the system matrix of the derivative formulation for interior field (\\textbf{a}) and for exterior field (\\textbf{b}).\n    }\n\\end{figure*}\n\n\\paragraph{Mesh refinement study using a spherical molecule} \\label{result_convergence_sphere}\n\nAs a form of solution verification with the Bempp-Exafmm software, we completed two mesh-refinement studies.\nThe first used a spherical molecule with an off-center charge, for which we have an analytical solution.\nIn the next sub-section, we present a mesh-refinement study with a real molecule of biological relevance.\nFigure \\ref{fig:sketch_sphere_convergence} depicts the problem setup for the current case:\na spherical molecule of radius 4 \\AA\\ and relative permittivity $\\epsilon_1 = 4$, with a unit charge located at $(1,1,1)$.\nThe solvent region has the relative permittivity of water ($\\epsilon_2 = 80$), and a salt concentration of $150$mM $(\\kappa = 1/8\\ {\\si{\\angstrom}}^{-1})$.\nOther simulation parameters are listed in Table \\ref{tab:convergence}.\nWith an expansion order of 10, our \\fmm achieved 9 digits of accuracy.\nWe computed the solvation energy of this molecule using $5$ different meshes, obtained using a constant refinement factor of 4.\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{lc}\n    \\hline\n    \\gmres tolerance          & $10^{-7}$ \\\\\n    \\# regular quadrature points  & 6    \\\\\n    \\fmm expansion order      & 10   \\\\\n    \\fmm $\\ncrit$             & 500  \\\\\n    \\hline  \\vspace{0.3 cm}\n    \\end{tabular}\n\n    \\begin{tabular}{cc}\n    number of elements & mesh density ($\\#/{\\si{\\angstrom}}^2$) \\\\\n    \\hline\n    3032               & 1                                       \\\\\n    6196               & 2                                       \\\\\n    12512              & 4                                       \\\\\n    25204              & 8                                       \\\\\n    50596              & 16                                     \n    \\end{tabular}\n    \\caption{Simulation parameters for the grid-refinement studies (top); mesh sizes/densities used in the grid refinement study on 5PTI. Mesh densities measured as number of elements per square Angstrom.}\n    \\label{tab:convergence}\n\\end{table}\n\nKirkwood's derivation \\cite{kirkwood1934theory} allows us to compute the analytical solution for the solvation energy in this case, to compare with the numerical result: $-12.258363$ [kcal/mol].\nFigure \\ref{fig:sphere_convergence} shows the error in the solvation energy, converging at the expected rate of $1/N$ for both formulations.\nThe observed order of convergence is 1.001 for the direct formulation and 0.999 for the derivative formulation, using the middle three values.\n\n\\paragraph{Mesh refinement study using 5PTI} \\label{result_convergence_5PTI}\n\nNext, we tested our software using a real biomolecule: bovine pancreatic trypsin inhibitor (PDB code 5PTI), whose structure \\cite{wlodawer1984structure} is shown in Figure \\ref{fig:5PTI_structure}.\nWe parameterized the molecule with \\texttt{pdb2pqr} and the \\texttt{charmm} force field, and then computed the solvation energy using 5 meshes with the element density ranging from 1 to 16 (Table \\ref{tab:convergence}).\nThis test used the same parameters listed in Table \\ref{tab:convergence}, which are fine enough to reveal the discretization error.\nSince an analytical solution is not available for this geometry, we obtained the reference values for error estimation via Richardson extrapolation.\nThe estimated relative error with the finest mesh is 1.2\\% with the direct formulation, and 1.5\\% with the derivative formulation.\n\n\n\nFigure \\ref{fig:5PTI_convergence} shows that the error of the computed solvation energy for 5PTI converges linearly with respect to $N$.\nThe observed order of convergence is 1.156 for the direct formulation and 1.038 for the derivative formulation, using the middle three values.\nBoth convergence results provide solution verification, and are evidence that our software solves the mathematical model correctly.\n\n\\begin{figure*}\n        \\centering\n     \\subfloat[][Sphere with an off-center unit charge at $(1,1,1)$.]{\\includegraphics[width=0.4 \\textwidth]{sketch_sphere_convergence.pdf}\n        \\label{fig:sketch_sphere_convergence}}\\quad\n     \\subfloat[][Structure of 5PTI.]{\\includegraphics[width=0.35 \\textwidth]{5PTI.png}\n        \\label{fig:5PTI_structure}}\\\\\n     \\subfloat[][]{\\includegraphics[width=0.4 \\textwidth]{sphere_convergence.pdf}\n        \\label{fig:sphere_convergence}}\n     \\subfloat[][]{\\includegraphics[width=0.4 \\textwidth]{5PTI_convergence.pdf}\n        \\label{fig:5PTI_convergence}}\n    \\caption{Mesh refinement studies using a spherical molecule and a real biomolecule: bovine pancreatic trypsin inhibitor (PDB code 5PTI).\n    \\textbf{c}, Mesh convergence study on a spherical molecule with an off-center charge, using both direct formulation and derivative formulation. The error on the solvation energy with respect to the analytical solution is plotted for five meshes:\n    the sphere discretized with 512, 2048, 8192, 32768 and 131072 boundary elements.\n    \\textbf{d}, Mesh convergence study of the solvation energy of bovine pancreatic trypsin inhibitor (PDB code 5PTI), using both direct formulation and derivative formulation.\n    The error is with respect to the extrapolated solution using Richardson extrapolation.\n    }\n\\end{figure*}\n\n% add comparison with results from APBS\n\\paragraph{Comparison with trusted community software} \\label{comparison}\nWe build more confidence on Bempp-Exafmm by comparing our results with a well-established finite-difference code APBS (version 1.5), using 5PTI and 8 other molecules.\nWe prepared the molecular structures using the \\texttt{charmm} force field.\nFor each molecule, we created three successive meshes to study the convergence with each software.\nFor Bempp-Exafmm, we used \\texttt{Nanoshaper} to generate three surface meshes with the element density set to 4, 8, 16 ${\\si{\\angstrom}}^{-2}$, respectively.\nIn APBS, we controlled the multigrid parameters to ensure that three grid spacings are refined with a constant factor of 2.\nAll mesh sizes are listed in Appendix \\ref{sec:apbs_mesh}.\nOther parameters are the same as our previous grid-convergence study, as listed in Table \\ref{tab:convergence}.\n\nTable \\ref{tab:APBS_result} presents the convergence results of both codes using a set of molecules.\nBempp used the derivative formulation throughout.\nIn each case, we obtained an extrapolated value of the solvation energy of each molecule, which serves as the reference value to estimate the discretization error with each software.\nAs expected, the solvation energy computed from Bempp converges at the rate of $\\mathcal{O}(N^{-1})$, where $N$ is the number of elements.\nWith APBS, the average observed order of convergence over all cases is 1.25, with respect to the grid spacing $h$; other studies \\cite{CooperBardhanBarba2014,GengKrasny2013} have reported a similar rate. \nOur $\\mathcal{O}(N^{-1})$ convergence corresponds to $\\mathcal{O}(h^{-2})$ convergence in grid size, but for boundary elements (surface triangles) it is more natural to look at convergence with respect to $N$.\nThe difference in the extrapolated solvation energies obtained with the two codes varies between 0.8\\% and 1.8\\% across all cases.\nA discrepancy is expected because Bempp-Exafmm and APBS use different geometrical representations for the molecular surface, while the atomic charges in the molecule are mapped to grid points through interpolation in APBS.\n(We also compared our results with MIBPB \\cite{chen2011mibpb} using only the finest mesh: the details can be found in Appendix \\ref{sec:comp_mibpb}.)\n\n\\begin{table*}[]\n    \\centering\n    \\resizebox{\\textwidth}{!}{%\n    \\begin{tabular}{cc|ccc|cc|ccc|cc}\n      &   & \\multicolumn{5}{c|}{APBS}                                                                    & \\multicolumn{5}{c}{Bempp}                                                                   \\\\\n      &   & \\multicolumn{3}{c|}{Error}     & \\multirow{2}{*}{$\\Delta G_{solv}$} & \\multirow{2}{*}{Order$(1/h)$} & \\multicolumn{3}{c|}{Error}     & \\multirow{2}{*}{$\\Delta G_{solv}$} & \\multirow{2}{*}{Order$(1/N)$} \\\\\n    ID   & $N_{atoms}$ & coarse   & medium   & fine     &                                    &                        & coarse   & medium   & fine     &                                    &                        \\\\ \\hline\n    1AJJ & 513 & 4.40e-02 & 1.33e-02 & 4.00e-03 & -266.15                            & 1.73                   & 2.75e-02 & 1.12e-02 & 4.59e-03 & -268.67                            & 1.29                   \\\\\n    1VJW & 826 & 3.09e-02 & 1.45e-02 & 6.77e-03 & -297.06                            & 1.09                   & 4.92e-02 & 2.23e-02 & 1.01e-02 & -302.50                            & 1.14                   \\\\\n    5PTI & 892 & 3.68e-02 & 1.38e-02 & 5.14e-03 & -311.69                            & 1.42                   & 5.12e-02 & 2.23e-02 & 9.67e-03 & -314.34                            & 1.20                   \\\\\n    1R69 & 997 & 4.31e-02 & 2.10e-02 & 1.02e-02 & -261.02                            & 1.04                   & 5.09e-02 & 2.34e-02 & 1.08e-02 & -265.02                            & 1.12                   \\\\\n    1A2S & 1272 & 5.25e-02 & 2.40e-02 & 1.10e-02 & -456.56                            & 1.13                   & 4.21e-02 & 1.93e-02 & 8.86e-03 & -461.25                            & 1.12                   \\\\\n    1SVR & 1433 & 5.28e-02 & 2.21e-02 & 9.28e-03 & -393.45                            & 1.25                   & 6.48e-02 & 2.89e-02 & 1.29e-02 & -398.83                            & 1.16                   \\\\\n    1A63 & 2065 & 4.51e-02 & 1.88e-02 & 7.82e-03 & -559.39                            & 1.26                   & 5.82e-02 & 2.60e-02 & 1.16e-02 & -567.24                            & 1.16                   \\\\\n    1A7M & 2804 & 4.13e-02 & 1.88e-02 & 8.53e-03 & -524.29                            & 1.14                   & 4.93e-02 & 2.24e-02 & 1.02e-02 & -531.48                            & 1.14                   \\\\\n    1F6W & 8247 & 6.45e-02 & 2.78e-02 & 1.20e-02 & -1277.51                           & 1.21                   & 4.18e-02 & 1.80e-02 & 7.76e-03 & -1301.08                           & 1.22                     \n    \\end{tabular}\n    }\n    \\caption{Convergence results of the solvation energy of 9 molecules using APBS and Bempp with derivative formulation.\n    The error is with respect to an extrapolated value of the solvation energy using Richardson extrapolation.\n    The solvation energy $\\Delta G_{solv}$ is in units of kcal/mol.\n    The observed order of convergence is with respect to the grid spacing $h$ for APBS (volumetric-based solver) and with respect to the number of elements $N$ for Bempp (boundary-element solver).}\n    \\label{tab:APBS_result}\n\\end{table*}\n\n\n\\paragraph{Performance study with direct and derivative formulations} \\label{result_performance}\n\nIn this sub-section, we investigate the computational performance of Bempp-Exafmm using a spherical molecule.\nThe sphere has a radius of 1 \\AA\\, and 100 charges are placed randomly inside, representing the atoms in the solute.\nWe used the same dielectric constants and salt concentration as in previous grid-convergence studies.\nOther simulation parameters are listed in Table \\ref{tab:sim_params_performance}.\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{lc}\n    \\hline\n    \\gmres tolerance          & $10^{-4}$ \\\\\n    \\# regular quadrature points  & 6    \\\\\n    \\fmm expansion order      & 5   \\\\\n    \\fmm $\\ncrit$             & 500  \\\\\n    \\hline\n    \\end{tabular}\n    \\caption{Simulation parameters used in the performance study for a spherical molecule.}\n    \\label{tab:sim_params_performance}\n\\end{table}\n\nTo cover a wide range of problem sizes, we used five surface discretizations, with the number of elements ranging from 8 thousand to 2 million.\nTable \\ref{tab:sphere_time} presents the assembly time, the solution time and the number of iterations to converge in each case for both formulations.\nThe assembly time includes the time to pre-compute the \\fmm invariant matrices, create sparse and singular assemblers and calculate preconditioners.\nThe algebraic convergence shows that the condition number grows as the problem size increases with the direct formulation, while it remains at the same level with the derivative formulation.\n\n\\begin{table*}[]\n    \\centering\n    \\begin{tabular}{c|cccc|cccc}\n                                                                 & \\multicolumn{4}{c|}{direct}                                                                                                                                                                       & \\multicolumn{4}{c}{derivative}                                                                                                                                                                        \\\\ \\hline\n    \\begin{tabular}[c]{@{}c@{}}number of\\\\ elements\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}total\\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}assembly\\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}GMRES\\\\ time (s)\\end{tabular} & \\# iterations & \\begin{tabular}[c]{@{}c@{}}total\\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}assembly\\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}GMRES\\\\ time (s)\\end{tabular} & \\# iterations \\\\ \\hline\n    8192                                                         & 14.0                                                     & 5.4                                                         & 8.6                                                      & 20            & 16.1                                                     & 9.6                                                         & 6.5                                                      & 5            \\\\\n    32768                                                        & 35.1                                                     & 11.7                                                        & 23.4                                                     & 24            & 35.5                                                     & 22.2                                                        & 13.3                                                     & 4            \\\\\n    131072                                                       & 144.2                                                    & 32.8                                                        & 111.4                                                    & 34            & 114.7                                                    & 67.2                                                        & 47.5                                                     & 4            \\\\\n    524288                                                       & 675.8                                                    & 121.6                                                       & 554.2                                                    & 51            & 421.3                                                    & 256.3                                                       & 165.0                                                    & 4            \\\\\n    2097152                                                      & 3159.8                                                   & 483.3                                                       & 2676.5                                                   & 70            & 1592.1                                                   & 1011.6                                                      & 580.5                                                    & 4           \n    \\end{tabular}\n    \\caption{Assembly and solution times of calculating the solvation energy of a spherical molecule with 100 random charges inside, using the direct and derivative (exterior) formulations.\n    6 regular quadrature points were used per element and the \\fmm expansion order was set to 5.}\n    \\label{tab:sphere_time}\n\\end{table*}\n\nIn our implementation, each iteration in direct formulation requires $8$ \\fmm evaluations, whereas each iteration in the derivative formulation requires 19, making it more than twice as expensive.\nThat explains why the direct formulation leads to a shorter solution time (\\gmres time), despite a slower convergence, in the two smaller cases.\nFor larger problem sizes, faster convergence in the derivative formulation offsets the larger cost per iteration.\n\nAs for the assembly time, the derivative formulation is about $2\\times$ slower, since it needs to construct twice as many operators as the direct formulation.\nIn addition, the two hypersingular operators make it even more involved.\nFigure \\ref{fig:sphere_assembly_time} shows the linear scaling of the assembly time with respect to $N$.\n\nNext, we confirm that the time complexity of mat-vecs in \\gmres is also $\\mathcal{O}(N)$.\nThe Poisson equation requires \\fmm with a Laplace kernel and the linearized Poisson-Boltzmann equation requires \\fmm with a Yukawa kernel.\nAs mentioned, each iteration involves multiple \\fmm evaluations: 4 Laplace {\\fmm}s and 4 Yukawa {\\fmm}s for the direct formulation, 8 and 11 for the derivative formulation.\nWe averaged the time spent on 1 Laplace \\fmm and 1 Yukawa \\fmm respectively using direct formulation, and plotted it with respect to $N$ in Figure \\ref{fig:sphere_fmm}.\nUsing an \\fmm order of 5, we achieve about 5 digits of accuracy in each mat-vec.\nThe timings and linear scaling substantiate the efficiency of our \\fmm implementation.\nIn the largest case with over 12 million quadrature points, one Laplace \\fmm costs $2.1$s and one Yukawa \\fmm costs $5.4$s to compute.\n\nIn Bempp, the matrix-vector product has the shape $A\\mathbf{x} = P_2^T (G - C)P_1 \\mathbf{x} + S \\mathbf{x}$ (see Equation \\ref{eq:bempp_fmm_matvec}), where the dominant costs are the \\fmm evaluation of the Green's function matrix $G$ and the on-the-fly evaluation of the singular correction matrix $C$. Moreover, as stated above for the full $2\\times 2$ block system a number of \\fmm passes together with corresponding singular corrections need to be performed.\nTherefore, the \\gmres time reported here consists of \\fmm time, singular correction time, as well as the time spent on other steps in the \\gmres algorithm.\nFigure \\ref{fig:sphere_gmres_direct} and \\ref{fig:sphere_gmres_derivative} show the time breakdown of \\gmres in percentages.\nAs problem size increases, \\fmm evaluations dominate the solution time.\n\nWe also measured the peak memory usage using the GNU time command \\texttt{/usr/bin/time -v}. (Some Linux distributions do not ship with GNU time.)\nWe observed a linear space complexity as shown in Figure \\ref{fig:sphere_memory}.\nThe largest case, with more than $2$ million elements, requires $36$GB for the direct formulation and $43$GB for the derivative formulation.\n\n\\begin{figure*}[t]\n\\centering\n    \\subfloat[][Assembly time]{\\includegraphics[width=0.33\\textwidth]{sphere_assembly_time.pdf}\n        \\label{fig:sphere_assembly_time}}\n   \\subfloat[][Average evaluation time.]{\\includegraphics[width=0.33\\textwidth]{sphere_fmm.pdf}\n        \\label{fig:sphere_fmm}}\n    \\subfloat[][Overall memory consumption in GB.]{\\includegraphics[width=0.33\\textwidth]{sphere_memory.pdf}\n        \\label{fig:sphere_memory}}\\\\\n    \\subfloat[][]{\\includegraphics[width=0.4\\textwidth]{sphere_gmres_direct.pdf}\n        \\label{fig:sphere_gmres_direct}}\n  \\subfloat[][]{\\includegraphics[width=0.4\\textwidth]{sphere_gmres_derivative.pdf}\n        \\label{fig:sphere_gmres_derivative}}\n    \\caption{Performance on a spherical molecule with 100 random charges inside;\n    6 regular quadrature points per element; \\fmm expansion order set to 5 to achieve 5 digits of accuracy. Problem size represented by number of elements, $N$. Evaluation time (b) is an average for 1 Laplace \\fmm evaluation and 1 Yukawa \\fmm evaluation across all iterations in GMRES using direct formulation.\n    \\textbf{c},\\textbf{d}, Time breakdown of \\gmres in percentage using direct formulation (\\textbf{c}) and derivative formulation (\\textbf{d}).}\n\\end{figure*}\n\n\\paragraph{Solvation energy of a Zika virus} \\label{result_zika}\n\nFinally, we present a more challenging problem that studies the solvation energy of the Zika virus (PDB code 6CO8), whose structure \\cite{sevvana2018refinement} is shown in Figure \\ref{fig:6CO8_assembly}.\nWe parameterized the molecular structure with the \\texttt{amber} force field, and generated a mesh on the SES using \\texttt{Nanoshaper}. (Mesh generation took less than 5 min.)\nThe prepared structure contains about 1.6 million atoms and our mesh has around 10 million boundary elements and a total surface area of $3.14\\times 10^6 {\\si{\\angstrom}}^{2}$, corresponding to an element density of $3.16 {\\si{\\angstrom}}^{-2}$.\nIn this experiment, 3 quadrature points were used for regular Galerkin integrals over disjoint elements.\nThe \\fmm expansion order was set to 4 obtain 4 digits of accuracy in mat-vecs and the tolerance of \\gmres was $10^{-4}$.\n\n\\begin{table*}[]\n    \\centering\n    \\begin{tabular}{c|c|ccccc}\n                 & \\begin{tabular}[c]{@{}c@{}}$\\Delta G_{\\mathrm{solv}}$\\\\ (kcal/mol)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}total \\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}assembly \\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}c@{}}GMRES \\\\ time (s)\\end{tabular} & \\begin{tabular}[c]{@{}l@{}}memory\\\\ (GB)\\end{tabular} & \\# iterations \\\\ \\hline\n    direct     & -116587.5                                               & 11005.4                                                   & 1534.5                                                       & 9470.9                                                    & 109.7                                                 & 105           \\\\\n    derivative & -116254.9                                               & 8370.3                                                    & 3553.9                                                       & 4816.4                                                    & 152.0                                                 & 18            \n    \\end{tabular}\n    \\caption{Results of computing the solvation energy of a Zika virus with Bempp using both the direct and derivative formulations.\n    3 regular quadrature points were used per element and the \\fmm expansion order was set to 4.\n    The mesh generation time is minor and not included in the total time.\n    To verify our result, we ran the same case with \\pygbe using the direct formulation on a workstation with a 24-core CPU.\n    The solvation energy computed from \\pygbe is -117261.1 [kcal/mol].\n    }\n    \\label{tab:6CO8_result}\n\\end{table*}\n\n\\begin{figure*}\n    \\subfloat[][]{\\includegraphics[width=0.25\\textwidth]{6CO8_assembly.png}\n        \\label{fig:6CO8_assembly}}\n\\subfloat[][]{\\includegraphics[width=0.75\\textwidth]{6CO8_potential.png}\n        \\label{fig:6CO8_potential}}\n    \\caption{\\textbf{a}, Structure of Zika virus (PDB code 6CO8) in assembly view. Each color indicates a polymer chain.\n    \\textbf{b}, Surface electrostatic potential of a Zika virus.\n    The color bar is in units of [kcal/mol$\\cdot$e].\n    Visualization generated using ParaView.\n    The starfish pattern seen in the polymer-chain colorization of Figure \\ref{fig:6CO8_assembly} is faintly visible in the potential.\n    }\n\\end{figure*}\n\nTable \\ref{tab:6CO8_result} summarizes the results and performance.\nAgain, we confirmed that the derivative formulation yields a well-conditioned system, which converged in 18 iterations and took less than 1.5 hours to solve.\nBy contrast, the direct formulation took almost twice as long to converge.\n\nIn this case, we also verified against \\pygbe \\cite{cooper2016pygbe}, a Python \\bem library for biomolecular electrostatics.\nBased on the solvation energy computed from \\pygbe: $-117261.1$ [kcal/mol], the relative difference of our result is 0.6\\% with the direct formulation and 0.9\\% with the derivative formulation.\nFigure \\ref{fig:6CO8_potential} shows the computed electrostatic potential on the surface.\n\n\\paragraph{Reproducibility package}\n\nBesides releasing all our software with an open-source license, we spared no effort to maximize the reproducibility of this work, compiling a ``repro-pack\" in a version-control repository.\nIt contains all raw data from the experiments and a small Python package---\\texttt{bempp\\_pbs}, to facilitate running PB simulations with Bempp.\n\\texttt{bempp\\_pbs} comprises a collection of scripts, including all post-processing scripts that are necessary to produce every result presented in this section, and driver and utility scripts for different formulations, with which readers can run these cases on their own hardware.\nIn addition, the ``repro-pack\" also provides a Jupyter notebook for each study to generate secondary data and results.\nThe notebook corresponding to section \\ref{result_conditioning} showcases how we could run a simple case of a spherical molecule using two formulations with just a few lines of code, and then compare their conditioning quantitatively with the help of other scientific Python tools.\nThese supplementary materials are included in our paper's GitHub repository at \\href{https://github.com/barbagroup/bempp\\_exafmm\\_paper/}{https://github.com/barbagroup/bempp\\_exafmm\\_paper/}, which is also archived on Zenodo at \\href{http://doi.org/10.5281/zenodo.4568951}{doi:10.5281/zenodo.4568951}.\nWe made separate archival deposits of input data (meshes and \\texttt{pqr} files ) on the Zenodo service.\nThe deposit can be downloaded from \\href{http://doi.org/10.5281/zenodo.4568768}{doi:10.5281/zenodo.4568768}.\n", "meta": {"hexsha": "46ba26ef69d1ddb5f18a7e212635f2c40f417b7e", "size": 34095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/results.tex", "max_stars_repo_name": "barbagroup/bempp_exafmm_paper", "max_stars_repo_head_hexsha": "d628305aa7a7713d8d37234e80260e2a4160b9c8", "max_stars_repo_licenses": ["MIT", "BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-06-21T04:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T03:18:36.000Z", "max_issues_repo_path": "tex/results.tex", "max_issues_repo_name": "barbagroup/bempp_exafmm_paper", "max_issues_repo_head_hexsha": "d628305aa7a7713d8d37234e80260e2a4160b9c8", "max_issues_repo_licenses": ["MIT", "BSD-3-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2021-02-06T19:28:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T20:09:48.000Z", "max_forks_repo_path": "tex/results.tex", "max_forks_repo_name": "barbagroup/bempp_exafmm_paper", "max_forks_repo_head_hexsha": "d628305aa7a7713d8d37234e80260e2a4160b9c8", "max_forks_repo_licenses": ["MIT", "BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-01T03:24:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T03:24:03.000Z", "avg_line_length": 101.1721068249, "max_line_length": 673, "alphanum_fraction": 0.658424989, "num_tokens": 8346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303236047049, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6035570709238254}}
{"text": "%Chapter \"Elemental Matrices\"\n%\n\\chapter{Explicit Dynamic Analysis}\n\n\\section{Statement of the Problem}\nConsider the discrete dynamic equilibrium equations at time $t$\n\n\\begin{equation}\nM^{t}A+C^{t}V+K^{t}U=^{t}F\n\\label{equil}\n\\end{equation}\n\nwhere $M$, $C$, $K$ are the assembled mass, damping and stiffness matrix respectively and similarly $^{t}A$, $^{t}V$, $^{t}U$, ${t}F$ are the nodal accelerations, velocities, displacements and external loads vectors at time $t$. In terms of forces \\eqref{equil} can be written like;\n\n\\begin{equation}\n^{t}F^I+^{t}F^D+^{t}F^s=^{t}F\n\\label{force equil}\n\\end{equation}\n\nwhere $^{t}F^I$, $^{t}F^D$ and $^{t}F^s$ are inertial, damping and elastic components respectively.\n\nExpanding the acceleration and velocity terms at time $t$ in a consistent finite central differences scheme we have;\n\n\\begin{equation}\n\\begin{aligned}\n^{t}A&=\\dfrac{1}{\\Delta t^2}\\left(^{t-\\Delta t}U-2^{t}U+^{t+\\Delta t}U\\right)\\\\\n^{t}V&=\\dfrac{1}{2\\Delta t}\\left(-^{t-\\Delta t}U+^{t+\\Delta t}U\\right)\n\\end{aligned}\n\\label{finitediff}\n\\end{equation}\n\nUsing \\eqref{finitediff} in \\eqref{force equil} yields;\n\n\n\\begin{equation}\n\\left(\\dfrac{1}{\\Delta t^2}M+\\dfrac{1}{2\\Delta t}C\\right) ^{t+\\Delta t}U=^{t}F-\\left(K-\\dfrac{2}{\\Delta t^2}M\\right) ^{t}U-\\left(\\dfrac{1}{\\Delta t^2}M-\\dfrac{1}{2\\Delta t^2}C\\right)^{t-\\Delta t}U\n\\label{resequil}\n\\end{equation}\n\nRedefine forces as follows\n\\begin{equation}\n\\begin{aligned}\n^{j}F^I&=\\dfrac{1}{\\Delta t^2}M ^{j}U\\\\\n^{j}F^D&=\\dfrac{1}{2 \\Delta t}C ^{j}U\\\\\n^{j}F^S&=K ^{j}U\n\\end{aligned}\n\\label{redefine}\n\\end{equation}\n\nand write \\eqref{resequil} as;\n\n\\begin{equation}\n^{t+\\Delta t}F^I+^{t+\\Delta t}F^D=^{t}F-^{t}F^s+2 ^{t}F^I-^{t-\\Delta t}F^I+^{t-\\Delta t}F^D\n\\label{force equil 2}\n\\end{equation}\n\n\\begin{itemize}\n\\item \\eqref{force equil 2} is an equilibrium equation at time $t=t$ allowing to predict the displacements at time $t=t+\\Delta t$ in terms of previously known values at times $t$ and $t=t-\\Delta t$.\n\n\\item The equation is exact within the error introduced by the expansion used in \\eqref{finitediff}.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/figure7_0.pdf}\n\\caption{Definition of the general iteration}\n\\label{fig:time iteration}\n\\end{figure}\n\n\\item The first predicted solution is at $t=\\Delta t$ and we require data at $t=-\\Delta t$ and at $t=0$.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/figure7_1.pdf}\n\\caption{Definition of the general iteration}\n\\label{fig:initial time iteration}\n\\end{figure}\n\n\\end{itemize}\n\n\\subsection{Damping Assumptions}\n\n\\begin{itemize}\n\\item[1] Use Rayleigh Damping and retain the velocity expansion used in \\eqref{finitediff}. That is;\n\n\\begin{equation}\nC=\\alpha M+\\beta K\n\\end{equation}\n\nthen we have (in terms of forces);\n\n\\begin{equation}\n(1+\\beta \\Delta t^2) ^{t+\\Delta t}F^I+\\dfrac{\\alpha}{2\\Delta t} ^{t+\\Delta t}F^S=^{t}\\hat{F}\n\\label{Rayleigh}\n\\end{equation}\n\nwhere;\n\n\\[\n^{t}\\hat{F}=^{t}R-^{t}F^S+2 ^{t}F^I-^{t-\\Delta t}F^I+^{t-\\Delta t}F^D\n\\]\n\nSolution in equation \\eqref{Rayleigh} requires the full assembly and factorization of an effective stiffness matrix.\n\n\\item[2] Neglect damping (This is however inconvenient for finite domains) \n\n\n\\begin{equation}\n^{t+\\Delta t}F^I=^{t}F-^{t}F^S+2 ^{t}F^I-^{t-\\Delta t}F^I\n\\label{Nodamping}\n\\end{equation}\n\n\\item[3] Use Rayleigh damping but modify the velocity expansion introduced in \\eqref{finitediff}. Using\n\n\\begin{equation}\n^{t}V=\\dfrac{1}{\\Delta t}(^{t}U-^{t-\\Delta t}U)\n\\label{velocity}\n\\end{equation}\n\nyielding;\n\n\\begin{equation}\n^{t+\\Delta t}F^I=^{t}F-^{t}F^S+2 ^{t}F^{I}-^{t}F^D+^{t-\\Delta t}F^D-^{t-\\Delta t}F^I\n\\end{equation}\n\nDefining a set of forces associated to the initial conditions like;\n\n\\[\n^{t-\\Delta t}F^{IC}=^{t-\\Delta t}F^I-^{t-\\Delta t}F^D\n\\]\n\nwe have\n\n\\begin{equation}\n^{t+\\Delta t}F^I=^{t}F-^{t}F^S+2 ^{t}F^{I}-^{t}F^D-^{t-\\Delta t}F^{IC}\n\\label{modvelocity}\n\\end{equation}\n\n\\end{itemize}\n\n\\subsection{Algorithm corresponding to the damping assumption 3}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/figure5.pdf}\n\\caption{Definition of the general iteration}\n\\label{fig:general iteration}\n\\end{figure}\n\nLet us write \\eqref{modvelocity} like\n\n\\begin{equation}\n^{j+1}F^I=^{j}F-^{j}F^S+2 ^{j}F^{I}-^{j}F^D-^{j-1}F^{IC}\n\\label{modveliter}\n\\end{equation}\n\nwhere the initialization process corresponds to;\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=12cm]{img/figure6.pdf}\n\\caption{Definition of the initial iteration}\n\\label{fig:initial iteration}\n\\end{figure}\n\nApplying \\eqref{modveliter} for $t=0$ we have;\n\n\\[\n^{0}F^I=^{0}F-^{0}F^S+2 ^{0}F^{I}-^{0}F^D-^{-\\Delta t}F^{IC}\n\\]\n\nfrom which it is clear that we require $-^{\\Delta t}U$. Applying the central difference expansion at $t=0$ and solving for $-^{\\Delta t}U$ yields;\n\n\\begin{equation}\n^{-\\Delta t}U=^{0}F-\\Delta t ^{0}V+\\dfrac{\\Delta t^2}{2} ^{0}A\n\\label{initialU}\n\\end{equation}\n\nUsing \\eqref{initialU} in \\eqref{modveliter} allows us to start up the algorithm.\n\n\\subsubsection{Particulars}\nIn what follows we concentrate on this last algorithm and in order to study some details we return to its standard displacements form. Writing \\eqref{modveliter} in terms of displacements and re-arranging yields;\n\n\n\\begin{equation}\n\\dfrac{1}{\\Delta t^2}M ^{t+\\Delta t}U=^{t}F-(1+\\dfrac{\\beta}{\\Delta t})K ^{t}U+(\\dfrac{2}{\\Delta t^2}-\\dfrac{\\alpha}{\\Delta t})M ^{t}U-(\\dfrac{1}{\\Delta t^2} - \\dfrac{\\alpha}{\\Delta t})M ^{t-\\Delta t}U+(\\dfrac{\\beta}{\\Delta t}) K ^{t-\\Delta t}U\n\\label{disequil}\n\\end{equation}\n\nLet;\n\n\n\\[\n\\begin{aligned}\na_1&=1+\\dfrac{\\beta}{\\Delta t}\\\\\na_2&=\\dfrac{2}{\\Delta t^2}-\\dfrac{\\alpha}{\\Delta t}\\\\\na_3&=\\dfrac{1}{\\Delta t^2} - \\dfrac{\\alpha}{\\Delta t}\\\\\na_4&=\\dfrac{\\beta}{\\Delta t}\n\\end{aligned}\n\\]\n\n\n\\begin{equation}\n^{t+\\Delta t}F^I=^{t}F-a_1K ^{t}U+a_2M ^{t}U-a_3M ^{t-\\Delta t}U+a_4K ^{t-\\Delta t}U\n\\label{equliassum3}\n\\end{equation}\n\n\n\\subsection{Decoupling}\nConsider the equation for the $i$-th d.o.f;\n\n\\begin{equation}\n\\dfrac{1}{\\Delta t^2}M_{ij} ^{t+ \\Delta t}U_j=^{t}F_i-a_1K_{ij} ^{t}U_j+a_2M_{ij}^{t}U_j-a_3M_{ij} ^{t-\\Delta t}U_j+a_4K_{ij}^{t-\\Delta t}U_j\n\\label{equildecoupled1}\n\\end{equation}\n\nwhere we keep $i$ fixed in \\eqref{equildecoupled1}. For a lumped mass matrix we can write;\n\n\\[\nM_{ij}=m_I\\delta_{ij}\n\\]\n\nthen \\eqref{equildecoupled1} becomes;\n\n\\begin{equation}\n\\dfrac{1}{\\Delta t^2}m_I ^{t+ \\Delta t}U_i= ^{t}F_I-a_1 K_{ij} ^{t}U_j+a_2 m_I ^{t}U_i-a_3 m_I ^{t-\\Delta t} U_i+a_4 K_{ij} ^{t-\\Delta t} U_j\n\\label{equildecoupled2}\n\\end{equation}\n\nLet;\n\n\\begin{equation}\n\\begin{aligned}\n^{t+\\Delta t} F_i^I&=\\dfrac{1}{\\Delta t^2} m_{I} ^{t+\\Delta t}U_i\\\\\n^{t} \\hat{F}^S_i&=a_1 K_{ij} ^{t}U_j\\\\\n^{t}\\hat{F}_i^I&=a_2m_{I} ^{t}U_i\\\\\n^{t-\\Delta t}\\hat{F}_i^I&=a_3m_{I} ^{t-\\Delta t}U_i\\\\\n^{t-\\Delta t}\\hat{F}_i^S&=a_4K_{ij}^{t-\\Delta t}U_j\n\\end{aligned}\n\\label{forces2}\n\\end{equation}\n\nso the recursive equation takes the form;\n\n\\begin{equation}\n^{t+\\Delta t} F_i^I=^{t}F_i-^{t} \\hat{F}^S_i+^{t}\\hat{F}_i^I-^{t-\\Delta t}\\hat{F}_i^I+^{t-\\Delta t}\\hat{F}_i^S\n\\label{forces3}\n\\end{equation}\n\nand the algorithm then reduces to;\n\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwData{Time span, Geometry, Material Paramters}\n\\KwResult{Displacements, Velocity and Acceleration time histories }\nCompute $^{t+\\Delta t} F_i^I$\\\\\nSolve for $^{t+\\Delta t}U_i=\\left(\\dfrac{\\Delta t^2}{m_I}\\right) ^{t+\\Delta t}F_{i}^I$\\\\\nUpdate $^{t}V_i$, $^{t}A_i$\n\\caption{Summarized Algorithm}\n\\end{algorithm}\n\nTo initialize the algorithm we apply the FD's equations at $t=0$\n\n\\[\n\\dfrac{1}{\\Delta t^2}m_I ^{\\Delta t}U_i=^{0}F_i-a_1 K_{ij} ^{0}U_j+a_2 m_I ^{0}U_i-a_3 m_I ^{-\\Delta t} U_i+a_4 K_{ij} ^{-\\Delta t} U_j\n\\]\n\nwhere $^{-\\Delta t} U_i$ is obtained from \\eqref{initialU}\n\n\\begin{equation}\n^{-\\Delta t}U_i=^{0}U_i-\\Delta t ^{0}V_i+\\dfrac{\\Delta t^2}{2} ^{0}A_i\n\\label{initialU2}\n\\end{equation}\n\nThe initial acceleration is obtained after assuming homogeneous IC's;\n\n\\[\nm_{I} ^{0}A_i+C_{ij} ^{0}V_j +K_{ij} ^{0}U_j=^{0}F_i\n\\]\n\ntherefore\n\n\\[\n\\begin{aligned}\nm_{I} ^{0}A_i=\\dfrac{^{0}F_i}{m_I}\\\\\n^{-\\Delta t} U_i=\\dfrac{\\Delta t^2}{2m_I}^{0}F_i\n\\end{aligned}\n\\]\n\nMoreover, neglecting the damping effects on the prediction of $^{\\Delta t}U_i$ yields;\n\n\\[\n^{\\Delta t} U_i=\\dfrac{\\Delta t^2}{2m_I}^{0}F_i\n\\]\n\n\\begin{algorithm}[H]\n \\SetAlgoLined\n \\KwData{Time span, Geometry, Material Paramters}\n \\KwResult{Displacements, Velocity and Acceleration time histories }\n Initialize solution vectors ($j=1$)\\;\n $^{0}U_i\\longrightarrow ^{1}U_i=0$, $^{0}V_i=0$, $^{1}A_i=\\dfrac{^{1}R_i}{m_I}$ \\;\n Select $\\Delta t$ and integration constants $a_1$,$a_2$, $a_3$, $a_4$\\;\n Fix 1-st predicted value (let $j=2$)\\;\n \\[\n^{\\Delta t} U_i \\longleftarrow \\dfrac{\\Delta t^2}{2m_I} ^{0}F_i\\longleftrightarrow \\left[^{2}U_i \\longleftarrow\\dfrac{\\Delta t^2}{2m_I} ^{1}F_i \\right]\n \\]\nTime Integration Phase\\;\n\\While{$j \\leq N$}{\n\\[\n\\begin{aligned}\n^{j+1}F^I_i\\longleftarrow& ^{j}F_i-a_1 K_{ij} ^{j}U_j+a_2 m_I ^{j}U_j-a_3 m_I ^{j-1} U_i+a_4 K_{ij} ^{j-1} U_j\\\\\n ^{j+1}U_i\\longleftarrow&\\dfrac{\\Delta t^2}{2m_I} ^{0}F^I_i\\\\\n ^{j}A_i\\longleftarrow&\\dfrac{1}{\\Delta t^2}\\left(^{j-1}U_i-2^{j}U_i+^{j+1}U_i\\right)\\\\\n ^{j}V_i\\longleftarrow&\\dfrac{1}{2\\Delta t}\\left(-^{j-1}U_i+^{j+1}U_i\\right)\\\\\n j\\longleftarrow&j+1\n\\end{aligned}\n\\]\n}\n\\caption{Full Algorithm}\n\\end{algorithm}\n\n\\subsubsection{Nodal Assembler}\nIn the uncoupled explicit finite element formulation the equation solving process proceeds one degree of freedom at a time. This implies a different assembly process to the one used in an implicit algorithm where a formal coefficient matrix is assembled and inverted. Now the mass, damping and stiffness elemental matrices are used to obtain effective nodal forces at each degree of freedom. In summary the mesh is not covered in an element by element basis, but in a node by node basis. In the following algorithm we discuss this nodal assembly process where in order to solve the displacement at a given degree of freedom prior knowledge of the element contributing to the given node is necessary. In the nodal assembler algorithm the following arrays are needed.\n\n\\noindent\nILIST(): Stores the elements connected to the current node.\\\\\nLPLIST():Stores the local position of the current node in each one of the elements of ILIST().\\\\\nNIEL():Number of elements at the current node. This array is used to access ILIST().\\\\\n\n\n\\begin{algorithm}[H]\n\\SetAlgoLined\n\\KwData{Number of nodal points, number of elements, Model}\n\\KwResult{Displacements, Velocity and Acceleration time histories }\n\\While {$i \\leq NUMNP$}\n{\n$K\\leftarrow NIEL(i)$\n%\\while {$ik \\leq 2$}{\n%$jK \\leftarrow ID(ik,i)$\n%}\n}\n\\caption{Nodal Assembler}\n\\end{algorithm}\n\n\n\n\n\n\n", "meta": {"hexsha": "9f27335df3a266ec28cf8dc9ab7ec64e9bafc7a8", "size": 10613, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/explicit.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/explicit.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/explicit.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": 30.3228571429, "max_line_length": 765, "alphanum_fraction": 0.6864223123, "num_tokens": 4112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.603557046857441}}
{"text": "\n\\section{Discretization and Solution Approach for the Solid Mechanics Model}\\label{sec:discretization_mechanics}\n\nAfter the formulation of linear and nonlinear models for solid mechanics in \\cref{sec:model_muscle_contraction}, this section discusses their discretization and derives finite element formulations for the linearized model and the nonlinear model, both static and dynamic.\nWe also describe the algorithms used to obtain a numerical solution.\n\nThe implementation of a solver for generic hyperelastic descriptions is an interdisciplinary endeavor, if parallel execution is exploited and the model is integrated in a multi-scale biomechanics model.\nTherefore, we give a comprehensive derivation of the formulas used to numerically solve the equations matching the implementation in OpenDiHu, such that the implementation is also comprehensible for readers that are not specialized in the field of continuum mechanics. More details on finite element discretizations for solid mechanics models can be found in the literature \\cite{zienkiewicz1977finite,SUSSMAN1987357,zienkiewicz2005finite}.\n\n% ---x---\n\\subsection{Discretization of the Linear Model}\\label{sec:linearized_mechanics_model}\n\nIn this section, we discuss the linearized and static model. Besides the nonlinear model, our software OpenDiHu also implements the linearized description. The linear model exhibits better numerical properties and can be solved faster than the generic model. Thus, it can serve as a toy problem or can be used for mechanical systems, where the linearization assumptions are valid.\n\nBy assuming small strains, we can use the linearized kinematic relation in \\cref{eq:linearized_helper3} to express the linear strain tensor $\\bfeps$. The material model is Hooke's law formulated in \\cref{eq:linearized_helper2}. It relates the strain to the Cauchy stress by $\\bfsigma = \\C:\\bfeps$.\n\n% linear, static and dynamic\n\nUsing variational calculus, the system response of external forces and infinitesimal, compatible, virtual displacements $δ\\bfu$ is studied. \nWe start with the \\emph{principle of virtual work}, which states that in equilibrium the virtual work $δW$ performed by external forces along any virtual displacements $δ\\bfu$ is zero. Equivalently, the external virtual work $δW_\\text{ext}$ is equal to the internal virtual work $δW_\\text{int}$:\n\\begin{align}\n  δW_\\text{int}(\\bfu,δ\\bfu) &= δW_\\text{ext}(δ\\bfu) \\qquad && \\forall δ\\bfu \\in H^1_0(\\Omega)\\label{eq:linearized_helper1}.\n\\end{align}\nHere, the external virtual work $δW_\\text{ext}$ is given by the product of external forces $\\bft$ and the virtual displacements $δ\\bfu$ at the same location. The internal virtual work $δW_\\text{int}$ is the body's response in terms of stresses $\\bfsigma$ and virtual strains $\\bfeps$.\nIn summary, \\cref{eq:linearized_helper1} is equivalent to the following equilibrium equation:\n\\begin{align}\n  \\ds\\int_\\Omega \\bfsigma(\\bfu) : δ\\bfeps\\,\\d\\bfx &= \\ds\\int_{∂\\Omega} \\bft : δ\\bfu\\,\\d \\bfx &&\\forall δ\\bfu \\in H^1_0(\\Omega).\\label{eq:linearized_helper1b}\n\\end{align}\nThe vectors contain the degrees of freedom of a finite element discretization. The operator \\say{:} denotes the component-wise product. \n\nOften, it is easier to write the equations in component form. Indices $a,b,c,\\dots$ are used to specify a dimension index in $\\{1,\\dots,d\\}$. The letters $L,M \\in \\{1,\\dots,N\\}$ denote indices over degrees of freedom in a mesh with $N$ nodes. The Einstein sum convention is used where repeated indices implicitly indicate summation, except when the indices are in parentheses.\nThus, the right-hand side $\\bff$ of \\cref{eq:linearized_helper1b} with ansatz functions $\\phi^L$ and the degrees of freedom $δu_a^L$ of $δ\\bfu$ can be written as:\n\\begin{align}\\label{eq:linearized_mechanics_rhs}\n  \\bff_a = \\ds\\int_{∂\\Omega} t_{(a)}\\,δu_{(a)}^L\\,\\phi^L \\,\\d \\bfx.\n\\end{align}\n\nBy combining the kinematic relation between displacements $\\bfu$ and linearized strains $\\bfeps$ in \\cref{eq:linearized_helper3}, the material relation between $\\bfeps$ and the stress $\\bfsigma$ in \\cref{eq:linearized_helper2}, the equilibrium relation between $\\bfsigma$ and the right-hand side vector $\\bff$ in \\cref{eq:linearized_helper1b} and after discretizing displacements and virtual displacements, we get the following linear matrix equation:\n\\begin{align}\\label{eq:linearized_helper4}\n  \\bfK\\,\\bfu = \\bff.\n\\end{align}\nThe stiffness matrix $\\bfK$ has rows and columns for every combination of degree of freedom $L,M \\in \\{1,\\dots,N\\}$ and dimension indices $a,b \\in \\{1,2,3\\}$. The entries are given by:\n\\begin{align*}\n  \\bfK_{LaMb} = \\ds\\int_{\\Omega} \\mathbb{C}_{adbc}\\p{\\phi^L(\\bfx)}{x_{d}}\\p{\\phi^M(\\bfx)}{x_{c}}\\,\\d \\bfx.\n\\end{align*}\n%\nThe resulting model in \\cref{eq:linearized_helper4} describes the passive behavior of a body under the linearization assumptions and can be used in an appropriate biomechanical application.\n\nHowever, for contracting muscle tissue, we also need to incorporate active stresses that are generated at the sarcomeres in the muscle. As described in \\cref{eq:active_stress_linear}, an active stress term $\\bfsigma^\\text{active}$  can be considered. Because this active term is prescribed by the activation dynamics and the subcellular model, it has to appear on the right-hand side of the linear model.\nWe add the active stress term $\\bfsigma^\\text{active}$ to the external virtual work in \\cref{eq:linearized_helper1}, yielding the equation:\n\\begin{align}\\label{eq:linearized_helper5}\n  δW_\\text{int}(\\bfu,δ\\bfu) &= \\bff + \\ds\\int_\\Omega \\bfsigma^\\text{active} : δ\\bfeps_{-}\\,\\d\\bfx &&\\forall δ\\bfu \\in H^1_0(\\Omega).\n\\end{align}\n%\nThe active stress is associated with compression, i.e., negative virtual strains $δ\\bfeps < 0$. Therefore, we use $δ\\bfeps_{-}$ which is defined equal to $δ\\bfeps$ for $δ\\bfeps < 0$ and zero otherwise.\nFrom \\cref{eq:linearized_helper5}, we get the same discretized linear system as in \\cref{eq:linearized_helper4}, but with an additional term $\\bff^\\text{ active}$ in the right-hand side that contains the discretized prescribed active stress field $\\bfsigma^\\text{active}_{ab}(\\bfx)$:\n\\begin{align}\\label{eq:linearized_helper6}\n  \\bff^\\text{ active}_{La} = \\ds\\int_{Ω}\\bfsigma^\\text{active}_{ab}(\\bfx)\\,\\p{\\phi^L(\\bfx)}{x_{b}} \\,\\d\\bfx.\n\\end{align}\n%\n\\subsection{Discretization of the Nonlinear Static Hyperelastic Model}\\label{sec:static_hyperelastic_fe_model}\n\nNext, we discuss the discretization of the nonlinear solid mechanics model, which uses the model equations introduced in \\cref{sec:model_muscle_contraction}.\nWe begin with the discretization of a static, incompressible problem, where no velocities have to be considered.\nThe discretization is extended to the dynamic model in \\cref{sec:solver_dynamic_hyperelasticity_fe_model}.\n\n%In \\cref{sec:linearized_mechanics_model}, the ingredients of a solid mechanics model derivation consisting of equilibrium, material and kinematic equations were outlined and used to derive a linearized description. For the nonlinear model, the material equations were discussed in \\cref{sec:material_modeling} and the stress and elasticity tensors were derived in \\cref{sec:stress_and_elasticity}. This section uses these building blocks and presents the full derivation for the generic hyperelastic finite element model.\nAs described in \\cref{sec:assumptions_and_model_equations}, the equilibrium equation can be formulated in terms of the \\emph{Hellinger-Reissner energy functional} $\\Pi_L(\\bfu,p) = \\Pi_\\text{int}(\\bfu,p) + \\Pi_\\text{ext}(\\bfu)$\ngiven in \\cref{eq:hellinger_reissner}.\nIt consists of the external energy functional, given in \\cref{eq:pi_ext} as\n\\begin{align*}\n  \\Pi_\\text{ext}(\\bfu) = -\\ds\\int_{\\Omega_0} \\bfB\\, \\bfu\\,\\d V - \\ds\\int_{∂\\Omega_0^t}\\bar{\\bfT}\\,\\bfu\\,\\d S,\n\\end{align*}\nwith body force $\\bfB$ and surface traction $\\bar{\\bfT}$, and of the internal energy functional\n\\label{sec:section_with_pi_int}\n\\begin{align}\\label{eq:mechanics_helper1}\n  \\Pi_\\text{int}(\\bfu,p) = \\ds\\int_{\\Omega_0} \\Psi_\\text{iso}\\big(\\bar\\bfC(\\bfu)\\big)\\,\\d V\n    + \\ds\\int_{\\Omega_0} p\\,\\big(J(\\bfu) - 1\\big)\\,\\d V.\n\\end{align}\n%\nHere, $\\Psi_\\text{iso}$ is the isochoric strain-energy density function introduced in \\cref{eq:psi_iso} in terms of the reduced right Cauchy-Green tensor $\\bar{\\bfC}$ defined in \\cref{eq:reduced_fc}.\nThe first term in \\cref{eq:mechanics_helper1} describes the isochoric elastic response of the material, the second term adds the incompressibility constraint $J=1$ with the Lagrange multiplier $p$. The value of $p$ is computed as part of the model and can be identified as the hydrostatic pressure. Therefore, the second term is interpreted as the elastic response to compression and is included in the internal energy functional $\\Pi_\\text{int}$.\n\nAccording to the \\emph{principle of stationary potential energy}, the system is in equilibrium, if the potential energy functional is stationary.\nThis is the case, if the first variation $δ\\Pi_L$ is zero.\nUsing the additive structure of $\\Pi_L$, we can express the principle of stationarity as\n\\begin{subequations}\n  \\begin{align}\n    D_{δ\\bfu}\\Pi_L(\\bfu, p) &= D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p) + D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) \\overset{!}{=} 0, & \\forall δ\\bfu  \\label{eq:variations_functional_zero_a}\\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu, p) &= D_{δp}\\Pi_\\text{int}(\\bfu,p) \\overset{!}{=} 0 & \\forall δp. \\label{eq:variations_functional_zero_b}\n  \\end{align}\n\\end{subequations}\nThe variations of the internal and external energy functionals are defined as\n\\begin{align}\\label{eq:def_variation}\n  D_{δ\\bfu}\\Pi(\\bfu) &= \\d{\\eps} \\Pi(\\bfu + \\epsδ\\bfu)\\big|_{\\eps=0}, & \n  D_{δp}\\Pi(p) &= \\d{\\eps} \\Pi(p + \\epsδp)\\big|_{\\eps=0}.\n\\end{align}\nThey can be identified as the internal and external virtual work,\n\\begin{align*}\n  D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p) &= δW_\\text{int}, & D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) &= -δW_\\text{ext}.\n\\end{align*}\nThus, \\cref{eq:variations_functional_zero_a} can be expressed as \n\\begin{align*}\n  δW_\\text{int} - δW_\\text{ext} &= 0,\n\\end{align*}\nwhich is the form of the equilibrium equation that was used in \\cref{eq:linearized_helper1} in the derivation of the linearized model in \\cref{sec:linearized_mechanics_model} . The Euler-Lagrange equations corresponding to the variational problem are the local incompressibility constraint and the partial differential equation of balance of momentum presented in \\cref{eq:contraction_1,eq:contraction_2}.\n\nExecuting the derivative in the definitions of the variations in \\cref{eq:def_variation} yields the following terms:\n\\begin{align*}\n  &D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p)  = \\ds\\int_{\\Omega_0} \\bfS(\\bfu,p): δ\\bfE(δ\\bfu)\\,\\d V,\n  \\qquad D_{δp}\\Pi_\\text{int}(\\bfu,p) =\\ds\\int_{\\Omega_0} \\big(J(\\bfu) - 1\\big)δp\\,\\d V, \\\\[4mm]\n  &D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) = -\\ds\\int_{\\Omega_0} \\bfB\\cdot δ\\bfu\\,\\d V - \\ds\\int\\limits_{∂\\Omega^t_0} \\bar{\\bfT}\\cdot δ\\bfu\\,\\d S,\n\\end{align*}\nwhere the variational variables $δp,δ\\bfu$ and $δ\\bfE$ are the virtual pressure, virtual displacements, and virtual strains.\n\n% discretization\nWe discretize the solutions of the functional for the displacements $\\bfu(\\bfx)$ and pressure $p(\\bfx)$ and their variations using different ansatz functions $\\phi^L$, $L=1,\\dots,N_u$ and $\\psi^L$, $L=1,\\dots,N_p$:\n\\begin{align*}\n   u_a &= \\hat{u}_a^L \\phi_{(a)}^L, & δu_a &= δ\\hat{u}_a^L \\phi_{(a)}^L,   & p &= \\hat{p}^L \\psi^L, & δp &= δ\\hat{p}^L \\psi^L.\n\\end{align*}\nAgain, Einstein summation over repeated indices, in this case the index $L$, is used. The displacements function is vector-valued and given by $\\bfu(\\bfx) = (u_1(\\bfx), u_2(\\bfx), u_3(\\bfx))^\\top$. The vectors containing the degrees of freedom are denoted by $\\hat{\\bfu} = (\\hat{u}^L)_{L=1,\\dots,N_u}$ and $\\hat{\\bfp} = (\\hat{p}^L)_{L=1,\\dots,N_p}$.\n\nThe kinematics equation to compute virtual strains from virtual displacements follows from \\cref{eq:green_lagrange_u} in Lagrangian description and is given by $δ\\bfE = \\sym(\\bfF^\\top ∇\\bfu)$. Its discretized form is given as follows, where the subscript comma $\\square_{,A}$  indicates the derivative with respect to the indexed coordinate $\\bfX_A$:\n\\begin{align*}\n  δE_{AB} &= \\dfrac12\\left(F_{aB}\\, \\phi_{(a),A}^M + F_{aA}\\, \\phi_{(a),B}^M\\right)δ\\hat{u}_{a}^M.\n\\end{align*}\n%\n% summarize equations\nIn summary, the resulting set of discretized nonlinear equations can be formulated as:\n\\begin{align}\\label{eq:mechanics_static_system}\n  δW_\\text{int}(\\bfu,p) - δW_\\text{ext} &= 0 \\qquad \\forall\\,δ\\bfu, \\\\[4mm]\n  D_{δp}\\Pi_L(\\bfu) &= 0 \\qquad \\forall\\,δp,\n\\end{align}\nwith the following discretized terms:\n\\begin{subequations}\\label{eq:mechanics_static_system2}\n  \\begin{align}\n    δW_\\text{int}(\\hat{\\bfu},\\hat{\\bfp})  = \\ds\\int_{\\Omega}\\dfrac12  S_{AB}(\\hat{\\bfu},\\hat{\\bfp})\\, \\left(F_{aB}\\, \\phi_{(a),A}^M + F_{aA}\\, \\phi_{(a),B}^M\\right)δ\\hat{u}_{a}^M \\,\\d V,\\\\[4mm]\n    δW_\\text{ext}  = \\ds\\int_{\\Omega} B_a \\phi_{(a)}^M\\,δ\\hat{u}^M_a \\,\\d V +\\ds\\int_{∂\\Omega}  \\bar{T}^L_a\\,\\phi_{(a)}^L\\, \\phi_{(a)}^M\\,δ\\hat{u}^M_a\\,\\d S, \\\\[4mm]\n    D_{δp}\\Pi_L(\\hat{\\bfu}) = \\ds\\int_\\Omega \\big(J(\\hat{\\bfu}) - 1\\big)\\,δp\\,\\d V .\n  \\end{align}\n\\end{subequations}\n\nThe nonlinear system of equations in \\cref{eq:mechanics_static_system,eq:mechanics_static_system2} can now be solved for the unknown vectors  $\\hat{\\bfu}$ and $\\hat{\\bfp}$ of degrees of freedom using a Newton scheme.\n\n\\subsection{Discretization of the Nonlinear Dynamic Hyperelastic Model}\n\nWe extend the discretization of the static model in the last section for the dynamic model.\nThe vector of unknowns is extended by a velocity function $\\bfv: \\Omega_t \\to \\R^3$. The additional equation $\\dot{\\bfu} = \\bfv$ relates the displacements and the velocity.\n\nAs noted in the derivation of the equilibrium equation in \\cref{sec:assumptions_and_model_equations}, the body force term $\\bfB$ in the external energy functional also includes the inertial forces $\\bfB_\\text{inertial} = \\rho_0\\,\\dot{\\bfv}$ to describe the dynamic behavior.\n\nThe resulting nonlinear system of equations is given as follows:\n\\begin{subequations}\\label{eq:mechanics_dynamic0}\n  \\begin{align}\n    δW_\\text{int}(\\bfu,p) - δW_\\text{ext}(\\bfv) &= 0 \\qquad \\forall\\,δ\\bfu,\\label{eq:mechanics_dynamic_system1}\\\\[4mm]\n    \\bfv &= \\dot{\\bfu},\\label{eq:mechanics_dynamic_system2}\\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu) &= 0 \\qquad \\forall\\,δp.\\label{eq:mechanics_dynamic_system3}\n  \\end{align}\n\\end{subequations}\n\n\\subsection{Computation of the Stress Tensor and the Elasticity Tensor}\\label{sec:stress_and_elasticity}\n\nIn the Newton solver, we need to compute the stress tensor $\\bfS$ and its derivative $\\C$, called the elasticity tensor, given the current displacement field $\\bfu$. The relations are defined by the material model given by the strain energy function. This section presents the algorithm how to obtain the values of $\\bfS$ and $\\C$ from the displacements $\\bfu$. While the derivation is formulated in terms of the displacement function $\\bfu$, it is also valid for the finite element discretization, i.e., using the vector $\\hat{\\bfu}$  of degrees of freedom instead.\n\nFollowing \\cref{eq:material_model_helper1}, the second Piola-Kirchhoff stress $\\bfS$ is given by the derivative of the strain energy function $\\Psi$ with respect to $\\bfC$.\nFor the representation using the invariants, the chain rule has to be used:%\n\\begin{align*}\n   \\bfS &= 2\\,\\p{\\Psi(\\bfC)}{\\bfC} = \\p{\\Psi}{I_a}\\p{I_a}{\\bfC}.\n\\end{align*}\nUsing the decoupled form, the resulting stresses are also decoupled as $\\bfS = \\bfS_\\text{vol}+\\bfS_\\text{iso}$. The volumetric stress $\\bfS_\\text{vol}$ describes the elastic response to compression, the isochoric stress $\\bfS_\\text{iso}$ describes the response to the deviatoric deformation. In the following, all steps to compute these stresses are listed. The rationale is to give a condensed reference of the implemented algorithm in OpenDiHu to facilitate further development.\nFor the derivation of all intermediate steps, we refer to the literature \\cite{holzapfel2000nonlinear}.\n\nAt first, the reduced stress tensor $\\bar{\\bfS}$ that neglects the volumetric change is formulated as:%\n%\n\\begin{align*}\n  \\bar{\\bfS} = 2\\p{\\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2,\\bar{I}_4,\\bar{I}_5)}{\\bar{\\bfC}} &= \\bar{\\gamma}_1\\,\\bfI + \\bar{\\gamma}_2\\,\\bar{\\bfC}\n  + \\bar{\\gamma}_4\\, \\bfa_0 \\otimes \\bfa_0 + \\bar{\\gamma}_5\\,(\\bfa_0 \\otimes \\bar{\\bfC}\\,\\bfa_0 + \\bfa_0\\bar{\\bfC}\\otimes \\bfa_0).\n\\end{align*}\nIn case of an isotropic material, the terms involving $\\bfa_0$ are not needed. The prefactors are given by derivatives of the strain energy function with respect to the reduced invariants:\n%\n\\begin{align*}\n  \\bar{\\gamma}_1 &= 2\\left(\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_1} + \\bar{I}_1\\,\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_2}\\right),\n  &\\bar{\\gamma}_2 &= -2\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_2},\n  &\\bar{\\gamma}_4 &= 2\\p{\\Psi_\\text{iso}}{\\bar{I}_4}\\\\[4mm]\n  \\bar{\\gamma}_5 &= 2\\p{\\Psi_\\text{iso}}{\\bar{I}_5}\n\\end{align*}\n%\nUsing the fourth order identity tensor $\\mathbb{I}$ and the projection tensor $\\mathbb{P}$,%\n\\begin{align*}\n  (\\mathbb{I})_{abcd} &= \\delta_{ac}\\,\\delta_{bd}, &\n  \\mathbb{P} &= \\mathbb{I} - \\dfrac13 \\bfC^{-1} \\otimes \\bfC,\n\\end{align*}\nthe stress tensors can finally be computed as\n\\begin{align*}\n  \\bfS_\\text{iso} &= J^{-2/3}\\mathbb{P}:\\bar{\\bfS}, &\n  \\bfS_\\text{vol} &= J\\,p\\,\\bfC^{-1}, &\n  \\bfS &= \\bfS_\\text{iso} + \\bfS_\\text{vol}.\n\\end{align*}\nIn the compressible case including the penalty method, the value of $p$, that is needed for $\\bfS_\\text{vol}$, is given by the constitutive model as $p = \\d \\Psi_\\text{vol}(J)/\\d J$. In the incompressible case, $p$ is the unknown Lagrange multiplier that gets computed as part of the numerical solution. In that case, $p$ has the physical meaning of the hydrostatic pressure.\n\nUsing the present algorithm, the stress tensor $\\bfS$ can, thus, be computed from derivatives of the strain energy function $\\Psi$ and the right Cauchy Green tensor $\\bfC$, which can be calculated from the displacement field $\\bfu$.\n\nAnother important quantity for the numerical solution of the nonlinear system is the fourth order elasticity tensor $\\C$, which is defined as\n\\begin{align*}\n  \\C = 2\\p{\\bfS(\\bfC)}{\\bfC} = 4\\dfrac{\\partial^2 \\Psi(\\bfC)}{\\partial\\bfC\\partial\\bfC}.\n\\end{align*}\nIt is the derivative of the stress tensor and is required in the Jacobian matrix of an iteration of the nonlinear Newton solver. Like the material tensor in \\cref{eq:symmetries}, it shows major and minor symmetries and has 21 independent entries.\n\nLike the stress tensor, the elasticity tensor is also additively composed into a volumetric term $\\C_\\text{vol}$ and an isochoric term $\\C_\\text{iso}$. The volumetric term can be computed by:%\n\\begin{align*}\n  \\mathbb{C}_\\text{vol} &= J\\,\\tilde{p}\\,\\bfC^{-1} \\otimes \\bfC^{-1} - 2\\,J\\,p\\,\\bfC^{-1} \\odot \\bfC^{-1}, &\n  \\big(\\bfC^{-1} \\odot \\bfC^{-1}\\big)_{abcd} &= \\dfrac12\\big(C^{-1}_{ac}\\,C^{-1}_{bd} + C^{-1}_{ad}\\,C^{-1}_{bc}\\big).\n\\end{align*}\nThe term includes two pressure variables $\\tilde{p}$ and $p$. In the incompressible formulation, both variables equals the Lagrange multiplier $p$. For the compressible formulation, $\\tilde{p}$ is derived as $\\tilde{p} = p + J\\,\\d p/\\d J$ and $p$ is computed from the volumetric strain energy function as stated above.\n\nThe isochoric term $\\mathbb{C}_\\text{iso}$ of the elasticity tensor follows from the following algorithm listing the quantities to compute:%\n\\begin{align*}\n  &\\bar{\\delta}_1 = 4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_1} + 2\\,\\bar{I}_1\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_2} +\\dfrac{∂\\Psi_\\text{iso}}{∂\\bar{I}_2} + \\bar{I}_1^2\\,\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}\\right), \\,\n  \\bar{\\delta}_2 = -4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_2} + \\bar{I}_1\\,\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}\\right),\\\\[4mm]\n  &\\bar{\\delta}_3 = 4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}, \\quad\n  \\bar{\\delta}_4 = -4\\dfrac{∂\\Psi_\\text{iso}}{∂\\bar{I}_2}, \\quad\n  \\bar{\\delta}_5 = 4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_4} +\\bar I_1 \\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_4}\\right),\\\\[4mm]\n  &\\bar{\\delta}_6 = -4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_4}, \\,\\,\\,\\,\n  \\bar{\\delta}_7 = 4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_4\\,∂\\bar{I}_4}, \\,\\,\\,\\,\n  \\mathbb{I}_{abcd} = δ_{ac}\\,δ_{bd}, \\,\\,\\,\\,\n  \\bar{\\mathbb{I}}_{abcd} = δ_{ad}\\,δ_{bc}, \\,\\,\\,\\,\n  \\mathbb{S} = (\\mathbb{I} + \\bar{\\mathbb{I}}) / 2, \\\\[4mm]\n  &\\p{\\bar I_5}{\\bar\\bfC} = \\bfa_0 \\otimes \\bar\\bfC\\,\\bfa_0 + \\bfa_0\\,\\bar\\bfC \\otimes \\bfa_0, \\quad\n  \\dfrac{∂^2\\bar{I}_5}{∂\\bar{\\bfC}∂\\bar{\\bfC}} = \\p{\\bar{\\bfC}}(\\bfa_0 \\otimes \\bar\\bfC\\,\\bfa_0 + \\bfa_0\\,\\bar\\bfC \\otimes \\bfa_0),\n\\end{align*}\n\\begin{align*}\n  &\\bar{\\mathbb{C}} = J^{-4/3}\\bigg(\\bar{\\delta}_1\\,\\bfI \\otimes \\bfI + \\bar{\\delta}_2\\,\\big(\\bfI \\otimes \\bar{\\bfC} + \\bar{\\bfC} \\otimes \\bfI\\big) + \\bar{\\delta}_3\\bar{\\bfC} \\otimes \\bar{\\bfC} + \\bar{\\delta}_4\\,\\mathbb{S}\n  +\\bar{δ}_5\\,(\\bfI \\otimes \\bfa_0 \\otimes \\bfa_0 + \\bfa_0 \\otimes \\bfa_0 \\otimes \\bfI)\\\\[4mm]\n  &\\hspace*{1cm} +\\bar{δ}_6\\,(\\bar{\\bfC} \\otimes \\bfa_0 \\otimes \\bfa_0 + \\bfa_0 \\otimes \\bfa_0 \\otimes \\bar{\\bfC})\n  +\\bar{δ}_7\\,(\\bfa_0 \\otimes \\bfa_0 \\otimes \\bfa_0 \\otimes \\bfa_0) \\\\[4mm]\n  &\\hspace*{1cm} + \\bar{δ}_8\\,\\Big(\\bfI \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bfI \\Big)\n  + \\bar{δ}_9\\,\\Big(\\bar{\\bfC} \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bar{\\bfC} \\Big) + \\bar{δ}_{10}\\Big(\\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}}\\Big) \\\\[4mm]\n  &\\hspace*{1cm}+ \\bar{δ}_{11} \\Big(\\bfa_0 \\otimes \\bfa_0 \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bfa_0 \\otimes \\bfa_0 \\Big) + \\bar{δ}_{12} \\dfrac{∂^2\\bar{I}_5}{∂\\bar{\\bfC}∂\\bar{\\bfC}}\\bigg)\\\\[4mm]\n  &\\tilde{\\mathbb{P}} = \\bfC^{-1} \\odot \\bfC^{-1} - \\dfrac13 \\bfC^{-1} \\otimes \\bfC^{-1} \\\\[4mm]\n  &\\mathbb{C}_\\text{iso} = \\mathbb{P} : \\bar{\\mathbb{C}} : \\mathbb{P}^\\top + \\dfrac23 J^{-2/3} \\bar{\\bfS} : \\bfC\\,\\tilde{\\mathbb{P}} - \\dfrac23\\big(\\bfC^{-1}\\otimes \\bfS_\\text{iso} + \\bfS_\\text{iso}\\otimes \\bfC^{-1}\\big)\n\\end{align*}\nThen, $\\C = \\C_\\text{vol} + \\C_\\text{iso}$ can be calculated.\n%\n%\n\n% invariants: I1-I5\n% transversely isotropic\n% reduced invariants, reduced quantities for compressible materials\n% strain energy function, derivative\n% elasticity tensor\n% -> computation of S and C\n\n\\subsection{Nonlinear Solver for the Solid Mechanics Model}\\label{sec:solver_static_hyperelastic_fe_model}\n\n% Newton solver\nThe governing nonlinear system of equations is solved by a Newton scheme. We define the vector of the unknown degrees of freedom as $(\\hat{\\bfu},\\hat{p}) =: \\bfz$. Then, the nonlinear equation takes the general form $\\bfW(\\bfz) = 0$. By linearization around a value $\\bfz$, we get%\n\\begin{align*}\n  \\bfW(\\bfz+Δ\\bfz) = \\bfW(\\bfz) + \\bfJ\\,Δ\\bfz + o(\\bfz + Δ\\bfz),\n\\end{align*}\nwith the increment $Δ\\bfz = (Δ\\hat\\bfu, Δ\\hat{p})$ and the Jacobian matrix $\\bfJ = \\partial {\\bfW}/\\partial {\\bfz}$.\nNeglecting the sublinear error term $o(z + Δz)$, we can start from an initial guess $\\bfz^{(0)}$ and proceed to find the root of $\\bfW$ using the following iterative Newton scheme:%\n\\begin{subequations}\\label{eq:newton_scheme}\n  \\begin{align}\n    \\bfJ\\,Δ\\bfz^{(n)} = -\\bfW(\\bfz^{(n)}),\\label{eq:mechanics_linear_system}\\\\[4mm]\n    \\bfz^{(n+1)} = \\bfz^{(n)} + Δ\\bfz^{(n)}.\n  \\end{align}\n\\end{subequations}\n\\Cref{eq:mechanics_linear_system} is a linear system of equations with the system matrix given by $\\bfJ$, which has to be solved in every iteration step $n$. The linear system of equations can be expressed as follows:\n\\begin{align}\\label{eq:static_newton_iteration}\n  \\matt{\\bfk_{δ\\bfu,Δ\\bfu} & \\bfk_{δp,Δ\\bfu}^\\top \\\\[2mm]\n  \\bfk_{δp,Δ\\bfu} & \\bfzero} \\, \\matt{Δ\\hat{\\bfu} \\\\[2mm] Δ\\hat{p}} \n  =\n  \\matt{-\\bfR_{δ\\bfu} \\\\[2mm] -\\bfR_{δp}}.\n\\end{align}\nThe definition of the right-hand sides $\\bfR_{δ\\bfu} = δW_\\text{int} - δW_\\text{ext}$ and $\\bfR_{δp}=D_{δp}\\Pi_L$ is given in \\cref{eq:mechanics_static_system}. The system matrix is composed as follows. The upper left part consists of 3 times 3 blocks of submatrices, each with size $N_u \\times N_u$ and the entries given by:\n\\begin{align*}\n  \\bfk_{δ\\bfu,Δ\\bfu,(L,a),(M,b)} &= \\ds\\int_\\Omega \\phi_{(a),B}^L\\tilde{k}_{abBD}\\phi_{(b),D}^M\\,\\d V &\\text{with}\\quad \n  \\tilde{k}_{abBD} &= δ_{ab}\\,S_{BD} + F_{aA}\\,F_{bC}\\,\\mathbb{C}_{ABCD}.\n\\end{align*}\nHere, $S_{BD}$ and $\\mathbb{C}_{ABCD}$ are entries of the second Piola-Kirchhoff stress tensor $\\bfS$ and the elasticity tensor $\\mathbb{C}$. The computation of these terms uses the description in \\cref{sec:stress_and_elasticity}.\n\nThe lower left part of the system matrix in \\cref{eq:static_newton_iteration} is given by 1 times 3 blocks of submatrices, each with size $N_p \\times N_u$ and entries given by:\n\\begin{align*}\n  \\bfk_{δp,Δ\\bfu,L,(M,a)} = \\ds\\int_\\Omega J\\,\\psi^L\\,(F^{-1})_{Ba}\\,\\phi_{(a),B}^M \\,\\d V.\n\\end{align*}\nThe upper right part equals the transposed lower left block such that the system matrix is symmetric. Solving the system in \\cref{eq:static_newton_iteration} in every iteration of the Newton scheme in \\cref{eq:newton_scheme} converges to the solution of the static solid mechanics problem.\n\n\\subsection{Discretization and Solution of the Dynamic Hyperelastic Model}\\label{sec:solver_dynamic_hyperelasticity_fe_model}\n% dynamic hyperelasticity (6.9.2)\n\n\nThe dynamic model is given by the system of nonlinear equations in \\cref{eq:mechanics_dynamic}. In addition to the spatial discretization with finite elements, we need to discretize the temporal derivatives of the displacement field $\\bfu$ and the velocity field $\\bfv$.\nThe time derivatives are discretized to timesteps $t=i\\cdot \\dt$ with an implicit Euler scheme:\n\\begin{align*}\n  \\dot{\\bfu} &\\leadsto \\dfrac1{\\dt}(\\bfu^{(i+1)} - \\bfu^{(i)}), & \\dot{\\bfv} &\\leadsto \\dfrac1{\\dt}(\\bfv^{(i+1)} - \\bfv^{(i)}).\n\\end{align*}\n%\n\nBecause of the added inertial body force, the external virtual work now depends on the vector of unknowns.\nIn consequence, we split the external virtual work $δW_\\text{ext}$ into a dead part $δW_\\text{ext,dead}$ that solely depends on external forces and an inertial part:%\n\\begin{align*}\n  δW_\\text{ext} = δW_\\text{ext,dead} + \\ds\\int_{\\Omega} \\rho_0\\,\\dfrac{v^{(i+1),L}_{(a)} - v^{(i),L}_{(a)}}{\\dt}\\,\\phi_{(a)}^L\\, \\phi_{(a)}^M\\,δ\\hat{u}^M_a \\,\\d V = 0.\n\\end{align*}\nIn summary, the system of equations to proceed from timestep $i$ to $(i+1)$ is given as:\n\\begin{subequations}\\label{eq:mechanics_dynamic}\n  \\begin{align}\n    δW_\\text{int}({\\bfu^{(i+1)}},p^{(i+1)}) - δW_\\text{ext}(\\bfv^{(i)},\\bfv^{(i+1)}) &= 0 \\qquad &&\\forall\\,δ\\bfu,\\label{eq:mechanics_dynamic1}\\\\[4mm]\n    \\dfrac1{\\dt}(\\bfu^{(i+1)} - \\bfu^{(i)}) - \\bfv^{(i+1)} &= 0,\\label{eq:mechanics_dynamic2}\\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu^{(i+1)}) &= 0 \\qquad &&\\forall\\,δp.\\label{eq:mechanics_dynamic3}\n  \\end{align}\n\\end{subequations}\nHere, \\cref{eq:mechanics_dynamic1} is the principle of virtual work, \\cref{eq:mechanics_dynamic2} relates displacements $\\bfu$ and velocities $\\bfv$ and \\cref{eq:mechanics_dynamic3} is the incompressibility constraint.\n\nThe system is again solved using the Newton scheme presented in \\cref{sec:solver_static_hyperelastic_fe_model}.\nThe linear system for each Newton iteration takes the following form:\n\\begin{align*}\n  \\matt{\n    \\bfk_{δ\\bfu,Δ\\bfu} & \\bfl_{δ\\bfu,Δ\\bfv} & \\bfk_{δp,Δ\\bfu}^\\top \\\\[2mm]\n    \\bfl_{δ\\bfv,Δ\\bfu} & \\bfl_{δ\\bfv,Δ\\bfv} & \\bfzero \\\\[2mm]\n    \\bfk_{δp,Δ\\bfu} & \\bfzero & \\bfzero\n  } \\, \n  \\matt{Δ\\hat{\\bfu} \\\\[2mm] Δ\\hat{\\bfv} \\\\[2mm] Δ\\hat{p}} \n  =\n  \\matt{-\\bfR_{δ\\bfu} \\\\[2mm] -\\bfR_{δ\\bfv} \\\\[2mm] -\\bfR_{δp}}.\n\\end{align*}\nThe entries $\\bfk_{δ\\bfu,Δ\\bfu}$ and $\\bfk_{δp,Δ\\bfu}$ are the same as in the static case in \\cref{eq:static_newton_iteration}.\nThe other non-zero entries are given by \n\\begin{align*}\n  \\bfl_{δ\\bfu,Δ\\bfv,(L,a),(M,b)} &= \\dfrac1{\\dt}\\delta_{ab} \\ds\\int_{\\Omega} \\rho_0\\,\\,\\phi_{(b)}^M \\,\\phi_{(a)}^L \\,\\d V, & \n  \\bfl_{δ\\bfv,Δ\\bfu,(L,a),(M,b)} &= \\dfrac{1}{\\dt}\\delta_{ab}\\,\\delta^{LM},\\\\[4mm]\n  \\bfl_{δ\\bfv,Δ\\bfv,(L,a),(M,b)} &= -\\delta_{ab}\\,\\delta^{LM}.\n\\end{align*}\n\nNote that in the dynamic problem, the system matrix is unsymmetric. It would be symmetric if the entries $\\bfl_{δ\\bfu,Δ\\bfv}$ and $\\bfl_{δ\\bfv,Δ\\bfu}^\\top$ were the same. This would be the case for a density of one, $\\rho_0 = 1$, and if the term $\\int_{\\Omega} \\phi_{b}^M \\phi_{a}^L \\,\\d V$ would be replaced by $\\delta_{ab}\\delta^{LM}$. The second condition means that a lumped mass matrix would be used where the diagonal entries are set to the row sums of the original matrix.\n\nWe discretize the finite element solution in space by \\emph{Taylor-Hood} elements. This type of element uses quadratic ansatz functions $\\phi$ for the displacements and velocities and linear ansatz functions $\\psi$ for the Lagrange multiplier or hydrostatic pressure $p$ on a 3D hexahedral mesh. This choice was proven to exhibit no locking \\cite{zienkiewicz2005finite}. Locking is a phenomenon of degraded convergence of the finite element method for solid mechanics problems and occurs for improper discretization schemes.\n\nFor a compressible material, the incompressibility constraint which is the last equation in the systems \\cref{eq:mechanics_static_system} or \\cref{eq:mechanics_dynamic} is removed. Instead of solving for the pressure $p$ as a Lagrange multiplier, the value is given by the constitutive model as described in \\cref{sec:material_modeling}. In consequence, the system matrix of the linear system of equations that is solved in the Newton iterations has a smaller size for compressible materials.\n\nMoreover, the size varies depending on whether the static or the dynamic problem given in \\cref{sec:solver_static_hyperelastic_fe_model,sec:solver_dynamic_hyperelasticity_fe_model} is solved. Assuming a linear mesh with $N_p$ degrees of freedom and a quadratic mesh with $N_u$ degrees of freedom, the square system matrix has $3\\,N_u$ rows and columns for a static compressible formulation, $3\\,N_u + N_p$ for a static incompressible formulation, $6\\,N_u$ for a dynamic compressible model, and $6\\,N_u+N_p$ for a dynamic incompressible model.\n\n% static compressible:    3*N_u\n% static incompressible:  3*N_u + N_p\n% dynamic compressible:   3*N_u + 3*N_u\n% dynamic incompressible: 3*N_u + 3*N_u + N_p\n\n\nIn any case, the mechanics model can be linked to the subcellular model by defining the active stress as given in \\cref{eq:active_stress_term}. Since the active stress does not depend directly on the passive behavior, the active stress term can be added as a constant to the passive stress term. This constant also has no influence on the Jacobian matrix $\\bfJ$. As the subcellular model depends on the fiber stretch $\\lambda_f = \\sqrt{I_4}$, there is a feedback loop between the subcellular and the solid mechanics model.\n\nDetails on the connection to the subcellular model as well as details on the numerical solution schemes are given in \\cref{sec:solid_mechanics_solver}.\n\n%, including the solver schemes, how initial values are chosen and measures to speed up convergence such as load stepping are discussed in the implementation and result sections.\n%To speed up the computation, the initial guess of the vector of unknowns in every timestep is linearly extrapolated from the two previous timesteps.\n\n\n", "meta": {"hexsha": "271514d7fc27de91f4d091341b4f8aa23da754c5", "size": 31384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/05_theory_3.tex", "max_stars_repo_name": "maierbn/phd_thesis_source", "max_stars_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-05T19:00:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T19:00:04.000Z", "max_issues_repo_path": "document/05_theory_3.tex", "max_issues_repo_name": "maierbn/phd_thesis_source", "max_issues_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "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": "document/05_theory_3.tex", "max_forks_repo_name": "maierbn/phd_thesis_source", "max_forks_repo_head_hexsha": "babee64f01f15d93cb75140eb8c8424883b33c6c", "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": 88.4056338028, "max_line_length": 566, "alphanum_fraction": 0.7165115983, "num_tokens": 10628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.6723316991792861, "lm_q1q2_score": 0.603549006608292}}
{"text": "\\section{Task 5}\n% We Consider a 16-by-16 torus (tori) interconnection network and determine the following\n% interconnection network properties:\nGiven a n-by-n tori where $n=16$, we determine the requested properties.\n\n\\subsection{Task 5.a}\n% network diameter\nThe network diameter is $16$.\n\n\n\\subsection{Task 5.b}\n% bisection bandwidth, assuming that each link has a bandwidth of 100 Mbits/s\nBisection width is $2n = 32$, this is multiplied by the link bandwidth giving a\nbisection bandwidth of $32 \\cdot 100\\text{Mb/s} = 3200\\text{Mb/s}$.\n\n\\subsection{Task 5.c}\n% the bandwidth per node\nThe tori have switch degree 4, so each node have 4 links with each\n$100\\text{Mb/s}$ this bandwidth needs to be split in both directions so the\nbandwith available for each node in each link is $50\\text{Mb/s}$ giving a total\nbandwidth per node of\n\\[\n\\text{switch degree} \\cdot \\frac{bandwidth}{2} = 4 \\cdot\n\\frac{100}{2} = 200\\text{Mb/s}.\n\\]\n", "meta": {"hexsha": "c1600f11817e3b384674a32d32affa10ce4cfdc1", "size": 928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment4/report/task5.tex", "max_stars_repo_name": "martinnj/PMPH2015", "max_stars_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assignment4/report/task5.tex", "max_issues_repo_name": "martinnj/PMPH2015", "max_issues_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment4/report/task5.tex", "max_forks_repo_name": "martinnj/PMPH2015", "max_forks_repo_head_hexsha": "2555ef889fb49e68485775a5ae7fd8b147623d70", "max_forks_repo_licenses": ["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.6923076923, "max_line_length": 89, "alphanum_fraction": 0.744612069, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6034887757522446}}
{"text": "\\documentclass{article}\n\\usepackage{fullpage}\n\\usepackage{nopageno} \n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{April 9, 2014}\n\\maketitle\ngenerating function is $\\sum\\limits_{n=0}^\\infty{h_nx^n}$ and exponential generating function is $\\sum\\limits_{n=0}^\\infty{h_nx^n/n!}$\n\n\\subsection*{theorem}\nlet $S$ be the multiset $\\{n_1\\cdot a_1,n_2\\cdot a_2,n_3\\cdot a_3,dots,n_k\\cdot a_k,\\}$and $h_n$ be the number of $n$-permutations of $S$. The exponential generating function for $h_0,h_1,\\dots$ is $g^{(e)}(x)=f_{n1}(x)f_{n2}(x)f_{n3}(x)\\dots f_{nk}(x)$\n\\subsubsection*{proof}\nsee page 224(237)\n\n\\subsection*{example}\nfind $g^{(e)}$ for the number of n-digit numbers with digits 3,5,7 where the \\# of 5's is even the number of 3's is more than 1 and at most 4 sevens.\n\n\\begin{align*}\n  (x^2/2!+x^3/3!+\\dots)(1+x^2/2!+x^4/4!+\\dots)(1+x+x^2/2!+x^3/3!+x^4/4!)\\\\\n  \\left(\\sum\\limits_{n=0}^\\infty{x^{n+2}/(n+2)!}\\right)\\left(\\sum\\limits_{n=0}^\\infty{x^{2n}/(2n)!}\\right)\\left(\\sum\\limits_{n=0}^4{x^{n}/(n)!}\\right)\\\\\n  (e^x-1-x)(\\frac{e^x+e^{-x}}{2})(...)\n\\end{align*}\n\nfind the number of ways to color the squares of a 1xn chessboard with red blue and green so that the number of red squares is odd and the number of green squares is positive.\n\n\\begin{align*}\n  \\frac{e^x-e^{-x}}{2}e^x\\sum\\limits_{n=0}^\\infty{x^{n+1}/(n+1)!}\\\\\n  \\frac{e^x-e^{-x}}{2}e^x(e^x-1)\\\\\n  \\frac{e^x-e^{-x}}{2}(e^{2x}-e^x)\\\\\n  \\frac{e^{3x}-e^{2x}-e^{x}+1}{2}\\\\\n  \\frac{1}{2}+\\frac{1}{2}\\sum\\limits_{n=0}^\\infty{(3x)^n/n!-(2x)^n/n!-x^n/n!}\\\\\n\\end{align*}\n\\end{document}\n\n", "meta": {"hexsha": "b098075b96b58c32f7321de8b84f53f724ef769c", "size": 1645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "combinatorics/combinatorics-notes-04-09.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-notes-04-09.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-notes-04-09.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": 40.1219512195, "max_line_length": 253, "alphanum_fraction": 0.643768997, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6034887757522445}}
{"text": "%% Chapter 4 : Model for PV Energy Evaluation\n\n\\section{Air Mass Ratio}\n\\\n\\\n\\\n\\\nSolar radiation has to pass through the earth's atmosphere to reach the surface. The atmosphere consists of various components which absorb a part of the solar radiation, hence reducing the solar radiation reaching the earth's surface. Moreover, longer the path the solar radiation takes through the atmosphere, more is the absorption and eventually more is the reduction in the amount of radiation reaching the surface.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m1}\n\\caption{The Air Mass Ratio is a measure of the amount of atmosphere the Sun's rays must pass through to reach Earth's surface [5]}\n\\label{figc3h1} %% to refer use, \\ref{}\n\\end{figure}\n\nFrom the Fig (\\ref{figc3h1}) we say that the air mass ratio is the ratio of the actual distance h_{2} taken by the radiation through the atmosphere to reach the surface and the shortest distance h_{1} when the sun is directly overhead, with an additional assumption that the earth's surface is flat. The eq (\\ref{amr}) give the air mass ratio formula.\n\n\\begin{equation}\n\\label{amr}\n\\text{Air Mass Ratio}\\quad m=\\frac{h_{2}}{h_{1}}=\\frac{1}{•\\sin{\\beta}}\n\\end{equation}\\\\\nwhere,\\\\\n$ m $ = Air Mass Ratio \\\\\n$ \\beta $ = Altitude angle of the Sun $ (Degrees) $ \\\\\n\n\\section{Earth's Orbit}\n\\\n\\\n\\\n\\\nEarth revolves around the sun in an elliptical orbit, as the eccentricity of this orbit is small the orbit is fairly circular. However, the distance of the earth from the sun varies everyday, with the furthest distance being when earth is at the aphelion and the shortest distance being when earth is at the perihelion. The Fig (\\ref{figc4h2}) illusrates this variation in the distance of earth from the sun. We see that the summer solstice and the winter solstice happen at the aphelion and perihelion respectively; whereas the equinoxes happen visually in the midway between aphelion and perihelion.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m2}\n\\caption{Tilt of the Earth's Axis with respect to the Ecliptic Plane [5]}\n\\label{figc4h2} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{eo}) gives the variation of earth's distance from the sun.\n\n\\begin{equation}\n\\label{eo}\nd=1.5\\times10^{8}\\left \\{\\ 1+0.017 \\sin \\left[ \\frac{360(n-93)}{365} \\right] \\right\\} \\ \\text{km}\n\\end{equation}\\\\\nwhere,\\\\\n$ d $ = Distance of Earth from Sun $ (km) $\\\\ \n$ n $ = Julian day number\\\\\n\n\n\\section{Solar Declination}\n\\\n\\\n\\\n\\\nEarth revolves around the sun in an elliptical orbit with its north-south axis tilted at an angle of 23.45^{\\circ}; this causes the apparent movement of the sun in the day sky to be the highest during the summers in the northern-hemisphere and lowest during the winters. Hence, the sun reaches the highest point in the sky on summer solstice (21^{st} June) when it is directly overhead the Tropic of cancer at latitude 23.45^{\\circ}, and it is at the lowest point on the winter solstice (21^{st} December) when it is directly overhead the Tropic of Capricorn at the latitude 23.45^{\\circ} below the equator. Moreover on both the vernal (21^{st} March) and autumnal (21^{st} September) equinox the sun is directly overhead the equator at latitude 0^{\\circ}. The Fig (\\ref{figc4h3}) illustrates this apparent movement of the sun in the day sky. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m3}\n\\caption{The angle between Sun and Equator is called Solar Declination [5]}\n\\label{figc4h3} %% to refer use, \\ref{}\n\\end{figure}\n\nHence, the angle formed between the plane of the equator and the line drawn from the center of the sun to the earth's center is called the solar declination angle, which is given by eq (\\ref{sdec}).\n\n\\begin{equation}\n\\label{sdec}\n\\delta =23.45 \\sin \\left[ \\frac{360}{365} (n-81)\\right]  \n\\end{equation}\\\\\nwhere,\\\\\n$ \\delta $ = Declination angle $ (Degrees) $\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m4}\n\\caption{A south-facing collector tipped up to an angle equal to its latitude is perpendicular to the Sun's rays at noon during Equinoxes [5]}\n\\label{figc4h4} %% to refer use, \\ref{}\n\\end{figure}\n\nThe Fig (\\ref{sdec}) shows the utilization of the solar declination angle in setting up the tilt of a solar panel for maximum energy output. It can be seen that, if the PV module located at a particular latitude is given a tilt equal to the tilt of the latitude the sun would be directly overhead the PV module on the equinoxes giving the best annual energy output performance for a fixed tilt PV module system.\n\n\\newpage\n\n\\section{Sun's Position}\n\\\n\\\n\\\n\\\nThe position of the sun in the sky is described using two angles: the azimuth and the altitude angle. The azimuth angle by convention is the angle made by the with respect to the south, being positive in the eastern direction and negative in the western direction. The altitude angle is angle made by the sun as measured positively from the earth's surface to its vertical position in the sky. The Fig (\\ref{figc4h7}) illustrates the azimuth and altitude angles clearly.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m7}\n\\caption{Sun's Position described by its Altitude angle and Azimuth angle [5]}\n\\label{figc4h7} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{alt},\\ref{azm}) give the formulas for the altitude and azimuth angles, it can be seen that they are functions of the latitude, the hour angle and the solar declination.\n\n\\begin{equation}\n\\label{alt}\n\\sin{(\\beta)}=\\cos{(L)}\\cos{(\\delta)}cos{(H)}+\\sin{(L)}\\sin{(\\delta)}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\beta  $ = Altitude Angle $ (Degrees) $\\\\\n$ H $ = Hour Angle $ (Degrees) $\\\\\n\n\\begin{equation}\n\\label{azm}\n\\sin{(\\phi_{S})}=\\frac{\\cos{(\\delta)}\\sin{(H)}}{\\cos{(\\beta)}}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\phi_{S}  $ = Azimuth Angle of Sun $ (Degrees) $\\\\\n\nThe Fig (\\ref{figc4h9}) illustrates the concept of the hour angle. It is the number of degrees that the earth rotates before the sun is directly overhead the local meridian (line of longitude passing through the location). So, the hour angle can also be defined as the difference between the local and the sun's meridian; it is positive till the point the sun crosses the local meridian ,and then on negative.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m8}\n\\caption{The Hour angle is he number of degrees the Earth must turn before the sun is directly over the local meridian [5]}\n\\label{figc4h9} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{ha}) gives the formula for the hour angle. The factor $ \\frac{15^{\\circ}}{\\text{hour}} $ appears as the earth takes one hour to rotate through 15^{\\circ}. \n\n\\begin{equation}\n\\label{ha}\n\\text{Hour Angle}\\ H=\\left(\\frac{15^{\\circ}}{\\text{hour}}\\right).(\\text{hours before solar noon})\n\\end{equation}\n\nThe eq (\\ref{hac}) provides the necessary condition for determining if th azimuth is greater or lesser than 90^{\\circ} away from the south. This condition has to be applied because during spring and summer in the early morning and late afternoon the magnitude of sun's azimuth is liable to be more than 90^{\\circ}; which would eventually cause the ambiguous nature of the inverse sine in eq (\\ref{azm})to manifest itself.\n\n\\begin{equation}\n\\label{hac}\n\\text{if,} \\quad \\cos{(H)}\\geq\\frac{\\tan{(\\delta)}}{\\tan{(L)}}; \\hspace{1cm} \\text{then,} \\ |\\phi_{S}|\\leq90^{\\circ}; \\hspace{1cm} \\text{otherwise,} \\ |\\phi_{S}|>90^{\\circ}\n\\end{equation}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{SunPath1}\n\\caption{Sun Path Diagram generated by the Sun Path Diagram App}\n\\label{figc4h8} %% to refer use, \\ref{}\n\\end{figure}\n\nThe Fig (\\ref{figc4h8}) shows the output of the Sun Path Diagram App developed, for the Julian Day of 100 at 30^{\\circ} latitude at a resolution of 5 minutes. The red and blue curves show the summer and winter soltice sun paths, whereas the green curve shows the sun path during the two equinoxes, and the black curve shows the sun path for the 100^{th} Julian Day.\n\n\\newpage\n\n\\section{Relationship Between Solar Time and Civil Time}\n\nThe Solar Time (ST) is the time, where everything is measured relative to the solar noon at the longitude of the location, whereas the  Civil Time (CT) is the time, where everything is measured relative to the solar noon at the longitude of the regional time zone. In order to have a connection between the ST and CT two adjustments : Longitude adjustment and Equation of time adjustment, have to be done.\\\\\n\nThe Longitude correction involves the time taken by the sun to travel between the regional time meridian and the location time meridian. It takes 4 minutes for the sun to pass through 1^{\\circ} of longitude due to the earth's rotation. Hence the factor of $ \\frac{4 \\ \\text{min}}{\\text{degree}} $ is seen in the eq (\\ref{solartime}).\\\\\n\nThe Equation of time adjustment is required due to the earth's ellipticl orbit around the sun, which causes the length of the solar day (Solar noon to solar noon) to vary throughout the year. The Fig (\\ref{figc4h10}) shows the variation in the length of the solar day throughout the year.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m10}\n\\caption{The Equation of Time plotted for all year days [5]}\n\\label{figc4h10} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{eot}) give the expression for calculating equation of time.\n\n\\begin{equation}\n\\label{eot}\nE= 9.87\\sin{(2B)} -7.53\\cos{(B)} -1.5\\sin{(B)} \\quad \\text{minutes}\n\\end{equation}\n\n\\begin{equation}\n\\label{eotb}\nB=\\frac{360}{364}(n-81)\n\\end{equation}\\\\\nwhere,\\\\\n$ E $ = Equation of Time $ (mins) $ \\\\\n$ B $ = Equation of Time angle $ (Degrees) $ \n\nFinally, combining everything together we get the connection between the ST and CT whic is given by the eq (\\ref{solartime}).\n\n\\begin{equation}\n\\label{solartime}\n\\text{Solar Time (ST)}= \\text{Clock Time (CT)}+ \\frac{4 \\ \\text{min}}{\\text{degree}}(\\text{Local Time Meridian}- \\text{Local Logitude})^{\\circ} + E(\\text{min})\n\\end{equation}\n\n\\subsection{Sunrise and Sunset Times}\n\\\n\\\n\\\n\\\nThe eq (\\ref{alt},\\ref{azm}) can be used to calculate the sun rise and sun set times approximately. These equations are solve for the hour angle  by putting \\beta = 0 (since altitude angle of the sun during sun rise and set is zero) as seen in eq (\\ref{sunrise1},\\ref{sunrise2}),    \n    \n\\begin{equation}\n\\label{sunrise1}\n\\sin{(\\beta)}=\\cos{(L)}\\cos{(\\delta)}cos{(H)}+\\sin{(L)}\\sin{(\\delta)}=0\n\\end{equation}\n\n\\begin{equation}\n\\label{sunrise2}\n\\cos{(H)}=-\\frac{\\sin{(L)}\\sin{(\\delta)}}{\\cos{(L)}\\cos{(\\delta)}}=-\\tan{(L)}\\tan{(\\delta)}\n\\end{equation}\n\nHence, solving for the hour angle we get eq (\\ref{sunrise3}).\n\n\\begin{equation}\n\\label{sunrise3}\nH_{SR}=\\cos^{-1}{(-\\tan{(L)}\\tan{(\\delta)})} \\quad \\text{(+ for sunrise)}\n\\end{equation}\n\nAs we have see that the earth rotates $ 15^{\\circ}/h $, we get the geometric sunrise time from the eq (\\ref{sunrise4}). \n\n\\begin{equation}\n\\label{sunrise4}\n\\text{Sunrise(geometric)}= 12:00-\\frac{H_{SR}}{15^{\\circ}/h}\n\\end{equation}\n\nThe geometric sun rise time refers to the point in time when the sun's center has crossed the horizon, which makes it inaccurate. Moreover, the the refraction caused by the atmosphere causes the sun to appear to rise about 2.4 minutes earlier than the geometric sun rise time and set 2.4 minutes later. Also, the definition of sun rise and sun set according to the weather services is the time when the upper limb of the sun crosses the horizon, but for us it is the crossing of the sun's center across the horizon. Futhermore, this is complicated even more by the fact that the sun rises and sets quicker around equinoxes than around the solstices due to the additional sideward movement the the later periods. Hence, in order to adjust to all these factors an adjustment factor called Q is given by the U.S. Department of Energy in 1978, its expression is given in eq (\\ref{sunrise5}).\n\n\\begin{equation}\n\\label{sunrise5}\nQ=\\frac{3.467}{\\cos{(L)}\\cos{(\\delta)}\\sin{(H_{SR})}} \\quad (\\text{min})\n\\end{equation}\\\\\nwhere,\\\\\n$ Q $ = Adjustment factor $ (mins) $ \\\\\n    \n\\newpage\n    \n\\section{Types of Radiation}\n\\\n\\\n\\\n\\\nThe solar radiation striking the solar collector (PV modules) consists of three components. The first one is the direct-beam radiation, it is the part of solar radiation which passes in a straight line through the atmosphere to the solar collector. The second is the diffuse radiation, it the part of solar radiation which is scattered by the molecules and aerosols. Finally the last one is the reflected radiation, it is the part of solar radiation which gets reflected from the ground surface onto the solar collectors surface. The Fig (\\ref{figc4h11}) illustrates the three components of solar radiation which are impressed on the solar collectors surface.\\\\\n\nNote: All the equations henceforth for solar radiation were developed by Threkeld and Jordan (1958), these equations are used in the AHRAE Clear-Day Solar Flux Model.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{m11}\n\\caption{Solar radiation striking a collector is a combination of Direct Beam, Diffuse and Reflected radiations [5]}\n\\label{figc4h11} %% to refer use, \\ref{}\n\\end{figure}\n\nThe Fig (\\ref{figc4h12}) shows the extra-terrestrial solar insolation, which is the the solar radiation passing perpendicularly through an imaginary surface just outside earth's surface.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{m12}\n\\caption{Extraterrestrial Solar Flux [5]}\n\\label{figc4h12} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{etr1}) gives the expression for the extra-terrestrial solar insolation.\n\n\\begin{equation}\n\\label{etr1}\nI_{0}=\\text{SC}. \\left[1+0.0334\\cos\\left(\\frac{360n}{365}\\right)\\right] \\quad (\\text{W/m}^{2})\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{0} $ = Extra Terrestrial Solar Insolation $ (W/m^{2}) $ \\\\\n$ SC $ = Solar constant $ (1.353 kW/m^{2}) $ \\\\\n\n\\subsection{Beam Radiation}\n\\\n\\\n\\\n\\\nThe earth's atmosphere with its mixture of gases and man made aerosols causes the attenuation of the beam radiation passing through it due to absorption. The attenuation can be quantified approximately using the exponential decal function as given in the eq (\\ref{beam1}).\n    \n\\begin{equation}\n\\label{beam1}\nI_{B}=Ae^{-km}\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{B} $ = Beam portion of the radiation $ (W/m^{2})$\\\\\n$ A $ = Apparent Extra-Terrestrial Flux $ (kW/m^{2})$\\\\\n$ k $ = Optical depth \\\\\n\nA given in eq (\\ref{beam2}) is the apparent extra-terrestrial insolation, k given in eq (\\ref{beam3}) is a dimenionless quantity called the optical depth and m is the air mass ratio as computed in eq (\\ref{amr}).\n\n\\begin{equation}\n\\label{beam2}\nA=1160+75\\sin\\left[\\frac{360}{365}(n-275)\\right] \\quad (\\text{W/m}^{2})\n\\end{equation}\n\n\\begin{equation}\n\\label{beam3}\nk=0.174+0.035\\sin\\left[\\frac{360}{365}(n-100)\\right]\n\\end{equation}\n\nThe Fig (\\ref{figc4h13}) illustrayes the direct beam radiation incident on a solar collector.\n    \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{m14}\n\\caption{Incidence angle between Sun and normal to the collector surface [5]}\n\\label{figc4h13} %% to refer use, \\ref{}\n\\end{figure}\n\nThe component of direct beam radiation striking the surface of the solar collector is given by the eq (\\ref{beamc1}).\n\n\\begin{equation}\n\\label{beamc1}\nI_{BC}=I_{B}\\cos{(\\theta)}\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{BC} $ = Beam radiation normal to the surface of the collector $ (W/m^{2})$\\\\\n$ \\theta $ = Angle between a line drawn normal to the solar collector face and the incoming beam\nradiation $ (Degrees)$\\\\\n\nThe Fig (\\ref{figc4h14) shows a complicated geometry of a solar collector, which has a tilt angle and an azimuth angle. The computation of the incidence angle of this solar collector is done with the eq (\\ref{beamc3).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{m13}\n\\caption{Solar and Collector Azimuth and Altitude angles along with Collector Tilt angle [5]}\n\\label{figc4h14} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{equation}\n\\label{beamc3}\n\\cos{(\\theta)}=\\cos{(\\beta)}\\cos{(\\phi_{S}-\\phi_{C})}\\sin{(\\Sigma)}+\\sin{(\\beta)}\\cos{(\\Sigma)}\n\\end{equation}\\\\\nwhere,\\\\\n$ \\phi_{S} $ = Azimuth angle of Sun $ (Degrees)$\\\\\n$ \\phi_{C} $ = Azimuth angle of the solar collector $ (Degrees)$\\\\\n$ \\sigma $ = Tilt angle of the solar collector $ (Degrees)$\\\\ \n    \n\\subsection{Diffuse Radiation}\n\\\n\\\n\\\n\\\nThe computation of diffuse radiation is complicated, as it includes the radiation scattered by the atmospheric gases, moisture etc., and also the radiation reflected from the surface which is scattered again by the atmosphere back to ground. It is fair to assume diffuse radiation to be coming with equal intensity from all directions (sky is assumed to be isotropic).\n    \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{m16}\n\\caption{Diffuse radiation on a collector is assumed to be proportional to the fraction of the sky that the collector \"sees\"  [5]}\n\\label{figc4h15} %% to refer use, \\ref{}\n\\end{figure}\n\nThe eq (\\ref{diff1})shows that the diffuse radiation is always dirrectly proportional to the beam radiation, where C given by the eq (\\ref{diff2}) is the sky diffuse factor.\n\n\\begin{equation}\n\\label{diff1}\nI_{DH}=CI_{B}\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{DH} $ = Diffused portion of the radiation striking the solar collector $ (W/m^{2})$\\\\\n$ C $ = Sky-Diffuse factor\\\\ \n\n\\begin{equation}\n\\label{diff2}\nC=0.095+0.04\\sin\\left[\\frac{360}{365}(n-100)\\right]\n\\end{equation}\n\nThe diffuse radiation striking the solar collector depend on the amount of sky seen by the collector. Moreover, the amount of sky seen by a solar collector is inversely proportional to its tilt angle in a sinusoidal way as given in the eq (\\ref{diffc1}).\n\n\\begin{equation}\n\\label{diffc1}\nI_{DC}=I_{DH}\\left(\\frac{1+\\cos{(\\Sigma)}}{2}\\right)=CI_{B}\\left(\\frac{1+\\cos{(\\Sigma)}}{2}\\right)\n\\end{equation}\n    \n    \n\\subsection{Reflected Radiation}\n\\\n\\\n\\\n\\\nThe beam and diffuse radiation incident on the ground surface, results in the their reflection off the ground surface. In the simplest model it is fair to assume that the reflected radiation from the ground surface is in equal intensity in all directions as illustrated in the Fig (\\ref{figc4h16}). \n    \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{m15}\n\\caption{The ground is assumed to reflect radiation with equal intensities in all directions [5]}\n\\label{figc4h16} %% to refer use, \\ref{}\n\\end{figure} \n\nThe Component reflected radiation striking the solar collector depend on the amount of ground seen by the collector. Moreover, the amount of ground seen by a solar collector is directly proportional to its tilt angle in a sinusoidal way as given in the eq (\\ref{ref1}).\n\n\\begin{equation}\n\\label{ref1}\nI_{RC}=\\rho(I_{BH}+I_{DH})\\left(\\frac{1-\\cos{(\\Sigma)}}{2}\\right)\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{RC} $ = Reflected portion of the radiation striking the solar collector $ (W/m^{2})$\\\\\n$ \\rho $ = Ground Reflectance $ (Range 0.1-0.8) $\\\\\n\n\\subsection{Total Solar Radiation}    \n\\\n\\\n\\\n\\\nThe total radiation striking the solar collector is the sum of the beam, diffuse and reflected  as computed in the previous sections, it is given in the eq (\\ref{totc1}).\n     \n\\begin{equation}\n\\label{totc1}\nI_{C}=I_{BC}+I_{DC}+I_{RC}\n\\end{equation}\\\\\nwhere,\\\\\n$ I_{C} $ = Total radiation incident on the solar collector $ (W/m^{2})$\n\nA more detailed equation for the total solar radiation striking the solar collector is given by eq (\\ref{totc2}), by substituting eq (\\ref{beamc1},\\ref{diffc1},\\ref{ref1}) in eq (\\ref{totc1}).\n\n\\begin{equation}\n\\label{totc2}\n    \\begin{aligned}\n        I_{C}\n        =Ae^{-km} \\left[ \\cos{(\\beta)}\\cos{(\\phi_{S}-\\phi_{C})}\\sin{(\\Sigma)} \\\\\n       & + \\sin{(\\beta)}\\cos{(\\Sigma)} + C\\left(\\frac{1+\\cos{(\\Sigma)}}{2}\\right) \\\\ \\\\\n      & +\\rho(\\sin{(\\beta)}+C)\\left.\\left(\\frac{1-\\cos{(\\Sigma)}}{2}\\right)\\right]\n   \\end{aligned}\n\\end{equation}\n    \n   \n    \n\\section{Radiation Equations}\n\\\n\\\n\\\n\\\nThe equation developed in the previous sections for the beam, diffuse and reflected radiation striking the solar collector are modified for different orientations of the Solar PV modules: Fixed Tilt, Seasonal Tilt, Single Axis Tracker and Double Axis Tracker, and presented in the following sub-sections\\\\\n   \n\\subsection{Fixed Tilt Equations}\n\\\n\\\n\\\n\\ \nThe equations for the beam, diffuse and reflected radiations striking the solar PV module in a fixed tilt orientation are given by eq (\\ref{ft1},\\ref{ft2},\\ref{ft3}).\n\n\\begin{equation}\n\\label{ft1}\nI_{BC}=I_{B}\\cos{(\\theta)}\n\\end{equation}\n\n\\begin{equation}\n\\label{ft2}\nI_{DC}=CI_{B}\\left(\\frac{1+\\cos{(\\Sigma)}}{2}\\right)\n\\end{equation}\n\n\\begin{equation}\n\\label{ft3}\nI_{RC}=\\rho I_{B}(\\sin{(\\beta)}+C)\\left(\\frac{1-\\cos{(\\Sigma)}}{2}\\right)\n\\end{equation}\n\n\n\\subsection{Seasonal Tilt Equations}\n\\\n\\\n\\\n\\\nThe equations for the beam, diffuse and reflected radiations striking the solar PV module in a fixed tilt orientation are given by eq (\\ref{st1},\\ref{st2},\\ref{st3}).\n\n\\begin{equation}\n\\label{st1}\nI_{BC}=I_{B}\\cos{(\\theta_{\\text{Tilt Type}})}\n\\end{equation}\n\n\\begin{equation}\n\\label{st2}\nI_{DC}=CI_{B}\\left(\\frac{1+\\cos{(\\Sigma_{\\text{Tilt Type}})}}{2}\\right)\n\\end{equation}\n\n\\begin{equation}\n\\label{st3}\nI_{RC}=\\rho I_{B}(\\sin{(\\beta)}+C)\\left(\\frac{1-\\cos{(\\Sigma_{\\text{Tilt Type}})}}{2}\\right)\n\\end{equation}\\\\\nwhere,\\\\\n\\textit{Tilt Type} = It can be normal, summer and winter season tilt\\\\\n\n\n\\subsection{Single-Axis Tracker Equations}\n\\\n\\\n\\\n\\\nThe equations for the beam, diffuse and reflected radiations striking the solar PV module in a fixed tilt orientation are given by eq (\\ref{sat1},\\ref{sat2},\\ref{sat3}).\n\n\\begin{equation}\n\\label{sat1}\n\\Sigma_{effective}=90^{\\circ}-\\beta +\\delta\n\\end{equation}\n\n\\begin{equation}\n\\label{sat2}\nI_{BC}=I_{B}\\cos{(\\delta)}\n\\end{equation}\n\n\\begin{equation}\n\\label{sat3}\nI_{DC}=CI_{B} \\left[ \\frac{1+\\cos{(90^{\\circ}-\\beta+\\delta)}}{2} \\right]\n\\end{equation}\n\n\n\\begin{equation}\n\\label{sat4}\nI_{RC}=\\rho(I_{BH}+I_{DH})\\left[\\frac{1-\\cos{(90^{\\circ}-\\beta+\\delta)}}{2}\\right]\n\\end{equation}\n\n\n\\subsection{Dual Axis Tracker Equations}\n\\\n\\\n\\\n\\\nThe equations for the beam, diffuse and reflected radiations striking the solar PV module in a fixed tilt orientation are given by eq (\\ref{tda1},\\ref{tda2},\\ref{tda3}).\n\n\\begin{equation}\n\\label{tda1}\nI_{BC}=I_{B}\n\\end{equation}\n\n\\begin{equation}\n\\label{tda2}\nI_{DC}=CI_{B} \\left[ \\frac{1+\\cos{(90^{\\circ}-\\beta)}}{2} \\right]\n\\end{equation}\n\n\\begin{equation}\n\\label{tda3}\nI_{RC}=\\rho(I_{BH}+I_{DH})\\left[\\frac{1-\\cos{(90^{\\circ}-\\beta)}}{2}\\right]\n\\end{equation}\n\n\\newpage\n \n\\section{Power Flow through Solar PV Grid Connected System}\n\\\n\\\n\\\n\\\nThe Fig (\\ref{PVloss}) illustrates the power flow through a solar PV system and the various losses incurred in the this system.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.80]{SolarPVLosses}\n\\caption{Flow Diagram - Power Flow and Power Losses in a Solar PV System}\n\\label{PVloss} %% to refer use, \\ref{}\n\\end{figure} \n\n\\subsection{Shading, Soiling and Incidence Angle Loss}\n\\\n\\\n\\\n\\\nAs seen in chapter 2, shading of PV modules leads to a reduction in power output. Shading is caused by shadows cast by near (near shading) as well as far (far shading) objects. These shadows inhibit the solar radiation from striking the PV modules causing shading and the subsequent loss in power output. To avoid shading losses the design of the PV arrays should be such that they do not cast shadow on each other, any near by objects casting shadow on the PV modules should be removed and the location of the PV system should be such that no far away objects cast shadow on the modules.\\\\\n\nSoil and dust accumulated on the PV module surface reduces the amount of radiation striking the module surface causing reduction in power output. To avoid power loss due to soiling regular cleaning of PV modules has to be performed.\\\\\n\nAs the surface of the PV module is made out of glass there is some radiation which is reflected from the PV module surface. This results in module power loss due to the incidence angle of the beam radiation. The ASHRAE (American Society of Heating, Refrigeration, and Air Conditioning ) model for IAM is given in eq (\\ref{iam}). It is a simple model as it requires only one parameter $ b_{0} $, however its accuracy reduces at higher incidence angles (Abella et al., 2003).\n\n\\begin{equation}\n\\label{iam}\nIAM=1-b_{0} \\left[ \\frac{1}{ \\cos {(\\theta)}}-1 \\right]  \n\\end{equation}\\\\\nwhere,\\\\\n$ IAM $ = Incidence Angle Modifier\\\\\n$ b_{0} $ = Constant\\\\\n$ \\theta $ = Incidence Angle  $ ^{\\circ}C $\\\\ \n\n\nFrom the Fig (\\ref{IAM1}) it can be observed that the IAM factor reduces from 1 at 0^{\\circ} to 0 at 90^{\\circ}. Hence, more the incident angle more is the reflection of the radiation from the PV module surface  . To avoid IAM losses significantly single axis or double axis tracker systems are used as they always try to maintain the incidence angle to the minimum (especially the double axis tracking system). \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{IAM}\n\\caption{ASHRAE IAM Model}\n\\label{IAM1} %% to refer use, \\ref{}\n\\end{figure} \n    \n\\subsection{Effect of Temperature and Irradiance on PV Module Output}\n\\\n\\\n\\\n\\\nThe PV module rated power given in the datasheet by the manufacturer is experimentally measured under the STC conditions of 25^{\\circ}C temperature and 1000 W/m^{2} of irradiance. However, in the field the temperature and irradiance levels change continuously throughout the day and the year depending on the location of the PV system.\\\\\n\nAs we have seen in chapter 2, PV module power is directly proportional to solar irradiance and inversely proportional to temperature, there will be conditions when the module will generate lower than rated power (due to either high temperature or low irradiance or both), similarly thre can be conditions when the module generates more than the rated power (due to either low temperature or high irradiance or both). The eq (\\ref{PVTemIrr}) gives the relationship between the actual power generated by the module.\n\n\\begin{equation}\n\\label{PVTemIrr}\nP_{Actual}=P_{Rated}\\left[1-\\bigtriangledown T]\\right \\frac{G_{Actual}}{G_{STC}} \n\\end{equation}\\\\\nwhere,\\\\\n$ P_{Actual} $ = Actual Power generated by the PV mdule $ (W) $\\\\\n$ P_{Rated} $ = PV module rated power $ (W) $\\\\\n$ \\bigtriangledownT $ = Difference between Ambient and STC temperatures $ (^{\\circ}C)$\\\\\n$ G_{Actual} $ = Actual Solar Irradiance $ (W/m^{2}) $\\\\\n$ G_{STC} $ = STC Solar Irradiance $ (W/m^{2}) $\\\\\n    \n\\subsection{Array Mismatch and Ohmic Loss}\n\\\n\\\n\\\n\\\nMismatch losses are caused due to the differences in the outputs of individual modules in an array. The major differences between modules are of two kinds: difference in open-circuit voltage and/or difference in short-circuit current. These difference eventually cause lowering of the power output of the entire array.\\\\\n\nThe Fig (\\ref{MisMat1}) shows two modules connected in series. In a series connection voltages of individual modules get added to give the total voltage of the string and the current flowing through all modules is the same. Hence, in this case the difference in open-circuit voltage is benign, but difference in short-circuit current is severe as the current output of the entire string is determined by the lowest current producing module, this severely reduces the the power output of the entire string. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Mismatch1}\n\\caption{Mismach in Series Connnected Modules [PV Education]}\n\\label{MisMat1} %% to refer use, \\ref{}\n\\end{figure} \n\nSimilarly in Fig (\\ref{MisMat2}) shows two modules connected in parallel. In a parallel connection currents of individual modules get added to give the total current of the array and the voltage across all modules is the same. Hence, in this case the difference in  short-circuit curren is benign, but difference in open-circuit voltage is severe as the voltage output of the entire array is determined by the lowest voltage producing string, this severely reduces the the power output of the entire array. Hence, in order to reduce these array mismatch losses the manufacturing process of the modules have to be standardized so that every module is exactly similar to the other.\n\nDC cabling is done to interconnect modules within a string, strings within an array and then to connect the PV system to the inverters. Also, AC cabling is done to connect the inverters to the transformer, and the transformer to the grid. All these cables add to the resistance of the PV system causing huge ohmic losses. Hence, in order to reduce these ohmic losses, the length of the cabling should be minimum and the cable material should be of low resistivity.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{Mismatch2}\n\\caption{Mismach in Parallely Connnected Modules [PV Education]}\n\\label{MisMat2} %% to refer use, \\ref{}\n\\end{figure}  \n\n\n    \n\\subsection{Inverter and Transformer Loss}   \n\\\n\\\n\\\n\\\nInverters are at the heart of the Solar PV system, the convert the DC power generated in modules to AC power which can be fed to the grid. Additionally they perform the task of maximum power point tracking, which helps in extracting maximum power from the PV modules at every temperature and irradiance condition. However, inverters are power electronic devices which are made up of high frequency switching devices; the switching devices cause loss in power due to the swtiching losses. To avoid inverter losses, a good quality inverter should be used.\\\\\n\nTransformers are another indispensible part of the grid connected Solar PV systems. They step-up the voltage of the PV system output, so that the power can be transferred to the transmission lines operating at higher voltages. But, transformers consist of copper coils which result in resistive losses, and iron cores which cause iron losses. Hence, the power output to the grid from the the PV system is reduced.\n   \n\\newpage    \n   \n\\section{MATLAB Model Algorithm}   \n\nThe Fig (\\ref{figc4halgo1} ) depicts an simplified flowchart of the algorithm which is developed for the creation of the Solar Energy Estimation Application. \n    \n    \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.5]{SolarAppAlgorithm}\n\\caption{Solar Photovoltaic Energy Estimation Schematic}\n\\label{figc4halgo1} %% to refer use, \\ref{}\n\\end{figure}\n\n\\newpage\n\nBased on the theory discussed in previous sections of this chapter and the algorithm developed as illustrated in Fig (\\ref{PVloss},\\ref{figc4halgo1}); a GUI based application for energy estimation solar photovoltaic grid connected power plants is developed in MATLAB, the results of which are presented in the next section and the application GUIs can be found in the Appendix.\n    \n\\section{Results of Solar Energy Estimation App}\n\\\n\\\n\\\n\\    \nThis section illustrates the results of energy simulation of Backbone 5MW Solar Power Plant. It is situated in Samakhiyali, Kutch, Gujarat. It has 145W Thin Film modules which are supported by a single axis east-west tracker system. Monthly enrgy output of the plant have been simulated in both the developed MATLAB application and then a comparison is done with the PVsyst simulation of the same plant.\\\\\n\nThe Table (\\ref{SolarAppTab1}) gives the site and PV module information of the Backbone 5MW SPVP.\n\n\\begin{table}[H]\n  \\centering\n  \\caption{BackBone 5MW SPVP Information Table}\n    \\begin{tabular}{|l|c|}\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{BackBone 5MW SPVP}} \\bigstrut\\\\\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{SITE INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{LATITUDE} & 23.357 \\bigstrut\\\\\n    \\hline\n    \\textbf{LONGITUDE} & 70.358 \\bigstrut\\\\\n    \\hline\n    \\textbf{PLANT CAPACITY (MW)} & 5 \\bigstrut\\\\\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{PV MODULE INFORMATION}} \\bigstrut\\\\\n    \\hline\n    \\textbf{DESCRIPTION} & Micro-Amorphous \\bigstrut\\\\\n    \\hline\n    \\textbf{MAKE} & NT-145AX \\bigstrut\\\\\n    \\hline\n    \\textbf{CRYSTALLINE/THIN-FILM} & Thin-Film \\bigstrut\\\\\n    \\hline\n    \\textbf{RATING (W)} & 145 \\bigstrut\\\\\n    \\hline\n    \\textbf{Vmpp (V)} & 64.2 \\bigstrut\\\\\n    \\hline\n    \\textbf{Impp (A)} & 2.26 \\bigstrut\\\\\n    \\hline\n    \\textbf{Voc (V)} & 85.5 \\bigstrut\\\\\n    \\hline\n    \\textbf{Isc (A)} & 2.54 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Voc} & -0.32 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Isc} & 0.07 \\bigstrut\\\\\n    \\hline\n    \\textbf{TEMP COEFF OF Pmp} & -0.28 \\bigstrut\\\\\n    \\hline\n    \\textbf{TOTAL MODULES} & 34485 \\bigstrut\\\\\n    \\hline\n    \\textbf{LENGTH (mm)} & 1412 \\bigstrut\\\\\n    \\hline\n    \\textbf{BREADTH (mm)} & 1112 \\bigstrut\\\\\n    \\hline\n    \\textbf{AREA (m2)} & 1.570144 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{SolarAppTab1}%\n\\end{table}%\n\n\n\nFigure (\\ref{PVG1}) hows the graph of energy output of Backbone 5MW SPV for the year 2014 for different orientations computed using developed MATLAB application.\n       \n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{PVresultG1}\n\\caption{MATLAB Application Backbone Plant month-wise energy estimation for different orientations}\n\\label{PVG1} %% to refer use, \\ref{}\n\\end{figure}\n\nIn the tables FT-Fixed Tilt, ST-Seasonal Tilt, E-W-Single Axis East-West Tracker, N-S-Single Axis North-South Tracker and D-A- Double Axis Tracker\\\\\n\n\\begin{table}[H]\n  \\centering\n  \\caption{MATLAB BackBone Application Simulation}\n    \\begin{tabular}{|l|r|r|r|r|r|r|}\n    \\hline\n    \\multicolumn{7}{|c|}{\\textbf{MATLAB BackBone Application Simulation}} \\bigstrut\\\\\n    \\hline\n       & \\multicolumn{1}{l|}{\\textbf{Actual }} & \\multicolumn{1}{l|}{\\textbf{FT}} & \\multicolumn{1}{l|}{\\textbf{ST}} & \\multicolumn{1}{l|}{\\textbf{E-W}} & \\multicolumn{1}{l|}{\\textbf{N-S }} & \\multicolumn{1}{l|}{\\textbf{D-A}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Jan} & 624 & 908 & 968 & 674 & 1095 & 1134 \\bigstrut\\\\\n    \\hline\n    \\textbf{Feb} & 678.7 & 876 & 909 & 712 & 1014 & 1064 \\bigstrut\\\\\n    \\hline\n    \\textbf{Mar} & 917.5 & 1087 & 1066 & 992 & 1215 & 1317 \\bigstrut\\\\\n    \\hline\n    \\textbf{Apr} & 997.4 & 817 & 832 & 800 & 859 & 1029 \\bigstrut\\\\\n    \\hline\n    \\textbf{May} & 1030 & 787 & 832 & 858 & 845 & 1045 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jun} & 921 & 708 & 741 & 822 & 744 & 944 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jul} & 693 & 575 & 575 & 640 & 617 & 764 \\bigstrut\\\\\n    \\hline\n    \\textbf{Aug} & 646.9 & 613 & 613 & 633 & 670 & 782 \\bigstrut\\\\\n    \\hline\n    \\textbf{Sep} & 682.8 & 640 & 640 & 602 & 714 & 769 \\bigstrut\\\\\n    \\hline\n    \\textbf{Oct} & 697.7 & 763 & 763 & 641 & 871 & 902 \\bigstrut\\\\\n    \\hline\n    \\textbf{Nov} & 562.7 & 829 & 878 & 628 & 987 & 1011 \\bigstrut\\\\\n    \\hline\n    \\textbf{Dec} & 619.9 & 949 & 1020 & 685 & 1160 & 1191 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab1}%\n\\end{table}%\n\nFrom Figure (\\ref{PVG1}) and Table (\\ref{PVresultTab1}) we see that the MATLAB application estimates the month-wise energy estimation of Backbone 5MW SPV for different orientation types. It can be seen that that there is a consistent increase in estimated energy from FT to D-A; the only outlier being the E-W estimation, this is because the tracking system has maximum and minimum azimuths of 45 and -45 respectively, and it would have been beneficial to have larger azimuths for tracking.\\\\\n\nFigure (\\ref{PVG2}) shows the graph of energy output of Backbone 5MW SPV for different orientations computed using PVsyst.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{PVresultG2}\n\\caption{PVsyst Backbone Plant month-wise energy estimation for different orientations}\n\\label{PVG2} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Pvsyst BackBone Simulation Results}\n    \\begin{tabular}{|l|r|r|r|r|r|r|}\n    \\hline\n    \\multicolumn{7}{|c|}{\\textbf{Pvsyst BackBone Simulation Results}} \\bigstrut\\\\\n    \\hline\n       & \\multicolumn{1}{l|}{\\textbf{Actual }} & \\multicolumn{1}{l|}{\\textbf{FT}} & \\multicolumn{1}{l|}{\\textbf{ST}} & \\multicolumn{1}{l|}{\\textbf{E-W}} & \\multicolumn{1}{l|}{\\textbf{N-S }} & \\multicolumn{1}{l|}{\\textbf{D-A}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Jan} & 624 & 866 & 967 & 908 & 985 & 1176 \\bigstrut\\\\\n    \\hline\n    \\textbf{Feb} & 678.7 & 789 & 820 & 874 & 841 & 1023 \\bigstrut\\\\\n    \\hline\n    \\textbf{Mar} & 917.5 & 943 & 903 & 1155 & 975 & 1250 \\bigstrut\\\\\n    \\hline\n    \\textbf{Apr} & 997.4 & 858 & 872 & 1146 & 895 & 1189 \\bigstrut\\\\\n    \\hline\n    \\textbf{May} & 1030 & 850 & 874 & 1183 & 923 & 1210 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jun} & 921 & 746 & 771 & 1028 & 825 & 1049 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jul} & 693 & 585 & 601 & 742 & 637 & 751 \\bigstrut\\\\\n    \\hline\n    \\textbf{Aug} & 646.9 & 574 & 586 & 710 & 610 & 721 \\bigstrut\\\\\n    \\hline\n    \\textbf{Sep} & 682.8 & 741 & 745 & 903 & 761 & 952 \\bigstrut\\\\\n    \\hline\n    \\textbf{Oct} & 697.7 & 859 & 870 & 1003 & 903 & 1144 \\bigstrut\\\\\n    \\hline\n    \\textbf{Nov} & 562.7 & 799 & 872 & 845 & 887 & 1058 \\bigstrut\\\\\n    \\hline\n    \\textbf{Dec} & 619.9 & 804 & 911 & 808 & 929 & 1081 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab2}%\n\\end{table}%\n\nFrom Figure (\\ref{PVG2}) and Table (\\ref{PVresultTab2}) we see the month-wise energy estimation of Backbone 5MW SPV for different orientation types computed using PVsyst. It can be seen that that there is a consistent increase in estimated energy from FT to D-A; here too the only outlier being the E-W estimation.\\\\\n\nTable (\\ref{PVresultTab3}) shows the month-wise percentage errors in the energy estimation of Backbone plant for different orientations computed using the developed MATLAB application with PVsyst being the reference.\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Comparison of PVsyst and MATLAB Application}\n    \\begin{tabular}{|l|r|r|r|r|r|}\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{Comparison of PVsyst and MATLAB Application}} \\bigstrut\\\\\n    \\hline\n       & \\multicolumn{1}{l|}{\\textbf{FT}} & \\multicolumn{1}{l|}{\\textbf{ST}} & \\multicolumn{1}{l|}{\\textbf{E-W}} & \\multicolumn{1}{l|}{\\textbf{N-S }} & \\multicolumn{1}{l|}{\\textbf{D-A}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Jan} & -4.8 & -0.1 & 25.7 & -11.1 & 3.6 \\bigstrut\\\\\n    \\hline\n    \\textbf{Feb} & -11.1 & -10.8 & 18.6 & -20.6 & -4 \\bigstrut\\\\\n    \\hline\n    \\textbf{Mar} & -15.3 & -18 & 14.1 & -24.6 & -5.4 \\bigstrut\\\\\n    \\hline\n    \\textbf{Apr} & 4.8 & 4.5 & 30.2 & 4  & 13.4 \\bigstrut\\\\\n    \\hline\n    \\textbf{May} & 7.4 & 4.8 & 27.4 & 8.5 & 13.6 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jun} & 5.2 & 3.8 & 20 & 9.8 & 10 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jul} & 1.7 & 4.4 & 13.7 & 3.1 & -1.8 \\bigstrut\\\\\n    \\hline\n    \\textbf{Aug} & -6.7 & -4.7 & 10.8 & -9.9 & -8.5 \\bigstrut\\\\\n    \\hline\n    \\textbf{Sep} & 13.7 & 14.2 & 33.3 & 6.1 & 19.3 \\bigstrut\\\\\n    \\hline\n    \\textbf{Oct} & 11.2 & 12.3 & 36.1 & 3.6 & 21.1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Nov} & -3.8 & -0.7 & 25.6 & -11.3 & 4.5 \\bigstrut\\\\\n    \\hline\n    \\textbf{Dec} & -18.1 & -11.9 & 15.3 & -24.9 & -10.2 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab3}%\n\\end{table}%\n\nFrom (\\ref{PVresultTab3}) it is observed that the MATLAB application has underestimated the energy production on majority of the times as compared to PVsyst, also it can be seen that the errors for E-W is abnormally higher than other orientation types. If we consider absolute values of the errors the average error percentage between PVsyst and MATLAB application is 12.3\\%, moreover if we do not take into account E-W values the error reduces to 9.3\\%. This shows that the energy estimation model developed is computing reliable estimation of energy as it is using the site data and not the generalized data used by PVsyst.\\\\\n\nFigure (\\ref{PVG5}) shows a comparison between the energy estimation of the Backbone 5MW SPV, with its actual orientation of single axis east-west tracker computed using PVsyst (E-W1, associate error is Error1, in Table (\\ref{PVresultTab4})) and MATLAB application (E-W2, associated error is Error2, in Table (\\ref{PVresultTab4})).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{PVresultG5}\n\\caption{Comparison of PVsyst, MATLAB and Actual Energy}\n\\label{PVG5} %% to refer use, \\ref{}\n\\end{figure}\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Comparison of PVsyst and MATLAB Application with Actual Energy}\n    \\begin{tabular}{|l|r|r|r|r|r|}\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{Comparison of PVsyst and MATLAB Application with Actual Energy}} \\bigstrut\\\\\n    \\hline\n       & \\multicolumn{1}{l|}{\\textbf{Actual }} & \\multicolumn{1}{l|}{\\textbf{E-W1}} & \\multicolumn{1}{l|}{\\textbf{E-W2}} & \\multicolumn{1}{l|}{\\textbf{Error1 \\%}} & \\multicolumn{1}{l|}{\\textbf{Error2 \\%}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Jan} & 624 & 908 & 674.3 & -45.5 & -8.1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Feb} & 678.7 & 874 & 711.5 & -28.8 & -4.8 \\bigstrut\\\\\n    \\hline\n    \\textbf{Mar} & 917.5 & 1155 & 992.2 & -25.9 & -8.1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Apr} & 997.4 & 1146 & 799.5 & -14.9 & 19.8 \\bigstrut\\\\\n    \\hline\n    \\textbf{May} & 1029.6 & 1183 & 858.5 & -14.9 & 16.6 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jun} & 921 & 1028 & 822.2 & -11.6 & 10.7 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jul} & 693 & 742 & 640.2 & -7.1 & 7.6 \\bigstrut\\\\\n    \\hline\n    \\textbf{Aug} & 646.9 & 710 & 633 & -9.8 & 2.1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Sep} & 682.8 & 903 & 602.4 & -32.2 & 11.8 \\bigstrut\\\\\n    \\hline\n    \\textbf{Oct} & 697.7 & 1003 & 640.7 & -43.7 & 8.2 \\bigstrut\\\\\n    \\hline\n    \\textbf{Nov} & 562.7 & 845 & 628.3 & -50.2 & -11.7 \\bigstrut\\\\\n    \\hline\n    \\textbf{Dec} & 619.9 & 808 & 684.6 & -30.3 & -10.4 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab4}%\n\\end{table}%\n\nFrom Figure (\\ref{PVG5}) and Table (\\ref{PVresultTab4}) we can compare the performance of the PVsyst and MATLAB Application with actual plant data. It is observed that PVsyst overestimates the energy production with an average error percentage of 26\\% (absolute values of errors), whereas the MATLAB application estimates the energy with an average error of 10\\% (absolute values of errors). Hence, the developed MATLAB application performs better than PVsyst for energy estimation of the given plant.\\\\\n\nFigure (\\ref{PVG3}) shows a comparison between the energy estimation of the Backbone 5MW SPV, with its actual orientation of single axis east-west tracker computed the daily insolation time series file obtained from the plant (E-W3, associate error is Error3, in Table (\\ref{PVresultTab5}) and using modified clear sky model (E-W4, associated error is Error4, in Table (\\ref{PVresultTab5}).\n\n\\begin{table}[H]\n  \\centering\n  \\caption{ MATLAB Application Simulation Comparison of Actual, Insolation Mode and Clear Sky Model Mode}\n    \\begin{tabular}{|l|r|r|r|r|c|}\n    \\hline\n    \\multicolumn{6}{|c|}{\\textbf{Comparison of Actual, Insolation Mode and Clear Sky Model Mode}} \\bigstrut\\\\\n    \\hline\n       & \\multicolumn{1}{l|}{\\textbf{Actual }} & \\multicolumn{1}{l|}{\\textbf{E-W3}} & \\multicolumn{1}{l|}{\\textbf{E-W4}} & \\multicolumn{1}{l|}{\\textbf{Error3 \\%}} & \\multicolumn{1}{l|}{\\textbf{Error4 \\%}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Jan} & 624 & 674.3 & 676.1 & -8.1 & -8.4 \\bigstrut\\\\\n    \\hline\n    \\textbf{Feb} & 678.7 & 711.5 & 685.1 & -4.8 & -1 \\bigstrut\\\\\n    \\hline\n    \\textbf{Mar} & 917.5 & 992.2 & 881.6 & -8.1 & 3.9 \\bigstrut\\\\\n    \\hline\n    \\textbf{Apr} & 997.4 & 799.5 & 947.7 & 19.8 & 5 \\bigstrut\\\\\n    \\hline\n    \\textbf{May} & 1029.6 & 858.5 & 1026.1 & 16.6 & 0.3 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jun} & 921 & 822.2 & 826.9 & 10.7 & 10.2 \\bigstrut\\\\\n    \\hline\n    \\textbf{Jul} & 693 & 640.2 & 783.1 & 7.6 & -13 \\bigstrut\\\\\n    \\hline\n    \\textbf{Aug} & 646.9 & 633 & 797.4 & 2.1 & -23.3 \\bigstrut\\\\\n    \\hline\n    \\textbf{Sep} & 682.8 & 602.4 & 650.6 & 11.8 & 4.7 \\bigstrut\\\\\n    \\hline\n    \\textbf{Oct} & 697.7 & 640.7 & 779.2 & 8.2 & -11.7 \\bigstrut\\\\\n    \\hline\n    \\textbf{Nov} & 562.7 & 628.3 & 643.1 & -11.7 & -14.3 \\bigstrut\\\\\n    \\hline\n    \\textbf{Dec} & 619.9 & 684.6 & 616.8 & -10.4 & 0.5 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab5}%\n\\end{table}%\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{PVresultG3}\n\\caption{Comparison of Insolation mode and modified Clear Sky Model mode}\n\\label{PVG3} %% to refer use, \\ref{}\n\\end{figure}\n\nFrom Figure (\\ref{PVG3}) and Table (\\ref{PVresultTab5}) we can compare two out of the three simulation modes of the MATLAB application i.e. Insolation File mode and modified clear sky model mode (SPV generation data has been correlated to the rainfall to drive clearness index). It is clearly observed that the modified clear sky mode performs better than the insolation file mode.\\\\\n\nFigure (\\ref{PVG4}) shows the graph of intra-day energy generation with a resolution of 15 minutes for three distinct seasonal days.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=1]{PVresultG4}\n\\caption{Intra-Day Energy Estimation of Backbone Plant }\n\\label{PVG4} %% to refer use, \\ref{}\n\\end{figure}\n\nFigure (\\ref{PVG4}) shows the intra-day values of energy produced by Backbone 5MW SPV at a resolution of 15 minutes. The Gaussian bell shape of the curves are due to the Gaussian disintegration of the daily insolation value received from the plant. Hence, the application has the capability to compute energy for sub-hourly resolutions.\\\\\n\n\\newpage\n\nTable (\\ref{PVresultTab6}) gives the plant performance of the Backbone 5MW SPV (with E-W orientation) computed by the developed MATLAB application according to the IEC Standard 61724\n\n\\begin{table}[H]\n  \\centering\n  \\caption{Plant Performance Analysis}\n    \\begin{tabular}{|l|r|}\n    \\hline\n    \\multicolumn{2}{|c|}{\\textbf{Plant Performance Analysis}} \\bigstrut\\\\\n    \\hline\n    \\textbf{Final Yeild (Yf)} & 1.790451 \\bigstrut\\\\\n    \\hline\n    \\textbf{Reference Yield (Yr)} & 2.0145 \\bigstrut\\\\\n    \\hline\n    \\textbf{Array Yeild (Ya)} & 1.902521 \\bigstrut\\\\\n    \\hline\n    \\textbf{Temperature Corrected Reference Yeild (Yt)} & 1.990852 \\bigstrut\\\\\n    \\hline\n    \\textbf{Thermal Capture Loss (Lct)} & 0.023647 \\bigstrut\\\\\n    \\hline\n    \\textbf{Array Capture Loss (Lc)} & 0.111979 \\bigstrut\\\\\n    \\hline\n    \\textbf{Miscelleneous Capture Losses (Lcm)} & 0.088332 \\bigstrut\\\\\n    \\hline\n    \\textbf{PR} & 0.888782 \\bigstrut\\\\\n    \\textbf{System Losses (Ls)} & 0.11207 \\bigstrut\\\\\n    \\hline\n    \\hline\n    \\textbf{CUF} & 0.204389 \\bigstrut\\\\\n    \\hline\n    \\textbf{Temperature Corrected PR} & 0.87847 \\bigstrut\\\\\n    \\hline\n    \\end{tabular}%\n  \\label{PVresultTab6}%\n\\end{table}%\n\n\n\n", "meta": {"hexsha": "fc2c7b5633caf153a8e5f96b894166f2738463f5", "size": 46335, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8_ProjectReport/2_ProjectProposal/Latex Support Files/Chapters/Ch4.tex", "max_stars_repo_name": "ninadkgaikwad/ARMA_TimeSeries_Forecasting_Project", "max_stars_repo_head_hexsha": "18329e436f823d55d2aad02b1d81d8cdda506ab2", "max_stars_repo_licenses": ["MIT"], "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_ProjectReport/2_ProjectProposal/Latex Support Files/Chapters/Ch4.tex", "max_issues_repo_name": "ninadkgaikwad/ARMA_TimeSeries_Forecasting_Project", "max_issues_repo_head_hexsha": "18329e436f823d55d2aad02b1d81d8cdda506ab2", "max_issues_repo_licenses": ["MIT"], "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_ProjectReport/2_ProjectProposal/Latex Support Files/Chapters/Ch4.tex", "max_forks_repo_name": "ninadkgaikwad/ARMA_TimeSeries_Forecasting_Project", "max_forks_repo_head_hexsha": "18329e436f823d55d2aad02b1d81d8cdda506ab2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-28T05:21:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T05:21:48.000Z", "avg_line_length": 46.5210843373, "max_line_length": 887, "alphanum_fraction": 0.7076508039, "num_tokens": 14458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.603488771239486}}
{"text": "\\documentclass[11pt, oneside]{article}\n\n\\usepackage{../shared/preamble}\n%\\addbibresource{../shared/references.bib}\n\n%\\usepackage{sorting}\n\n\\title{Sorting}\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 formalizes the notion of sorting to illustrate the relation between\na specification and an implementation, and how to prove that an implementation satisfies\na specification.\n\\end{abstract}\n\n\\section{Sorting}\n\nSuppose we are given a finite list of numbers and are asked to sort it.\nBy sorting we mean that the result should contain exactly the same set of numbers, with the same multiplicities,\narranged in ascending order.\n\n\\subsection{Lists, $LIST$}\n\nLet $LIST$ denote a finite sequence of integers.\n\n\\begin{zed}\nLIST == \\seq \\num\n\\end{zed}\n\n\\subsection{Ascending Order $ascending$}\n\nA list is in ascending order when any element that appears earlier in the list is less than\nor equal to any element that appears later in the list.\nLet $ascending$ denote the set of all lists that are in ascending order.\n\n\\begin{zed}\nascending == \\{~ s: LIST | (\\forall i, j: \\dom s | i < j @ s(i) \\leq s(j)) ~\\}\n\\end{zed}\n\nAlthough mathematically correct, the definition of $ascending$ is not in a \nform that can be implemented efficiently on a computer.\nThe definition implies that if the list contains $n$ elements then\nthere are $n(n+1)/2$ pairs $(i, j)$ such that $i \\leq j$ for which $s$ has to be checked.\nThe complexity of the direct, naive implementation of this check is therefore $O(n^2)$.\nClearly, we can reduce this complexity to $O(n)$.\n\n\\subsection{Refinement of Ascending Order $ascending1$}\n\nA more efficient definition of ascending order is given by $ascending1$.\n\n\\begin{zed}\nascending1 == \\{~ s: LIST | (\\forall i: \\dom s | i < \\# s @ s(i) \\leq s(i + 1)) ~\\}\n\\end{zed}\n\nClearly, a direct implementation of this definition has complexity $O(n)$.\n\n\\subsection{Theorem $ascending = ascending1$}\n\nAlthough the equivalence of $ascending$ and $ascending1$ is obvious to a human,\nother similar optimizations may not be.\nIt is therefore instructive to prove the equivalence.\n\nThe plan of the proof is to prove $ascending \\subseteq ascending1$ and $ascending1 \\subseteq ascending$\nwhich corresponds to unfolding the definition of equality for sets.\n\nFirst prove $ascending \\subseteq ascending1$.\n\n\\begin{argue}\ns: ascending \t\t\t\t\t\t\t& assumption \\\\\n\\forall i, j : \\dom s | i < j @ s(i) \\leq s(j)\t\t& def of $ascending$ \\\\\ni: \\dom s | i < \\# s\t\t\t\t\t\t& intro $i$ \\\\\nj == i + 1\t\t\t\t\t\t\t\t& intro $j$ \\\\\nj \\in \\dom s\t\t\t\t\t\t\t& def of $\\dom$ \\\\\ni < j\t\t\t\t\t\t\t\t\t& def of $<$ \\\\\ns(i) \\leq s(j)\t\t\t\t\t\t\t& $\\forall$-elim \\\\\ns(i) \\leq s(i + 1)\t\t\t\t\t\t\t& def of $j$ \\\\\n\\forall i: \\dom s | i < \\# s @ s(i) \\leq s(i + 1)\t\t& $\\forall$-intro \\\\\ns \\in ascending1\t\t\t\t\t\t& def of $ascending1$ \\\\\ns: ascending \\implies s \\in ascending1\t\t& $\\implies$-intro \\\\\nascending \\subseteq ascending1\t\t\t& $s$-elim QED\n\\end{argue}\n\nNext prove  $ascending1 \\subseteq ascending$.\nThis proof requires induction on the length of the list.\n\n\\begin{argue}\ns: ascending1\t\t\t\t\t\t\t& assumption \\\\\n\\forall i: \\dom s | i < \\# s @ s(i) \\leq s(i + 1)\t\t& def of $ascending1$ \\\\\n\\# s = 0\t\t\t\t\t\t\t\t& assumption \\\\\ns \\in ascending\t\t\t\t\t\t\t& def of $ascending$ \\\\\n\\# s = 0 \\implies s \\in ascending\t\t\t\t& $\\implies$-intro \\\\\n\\# s = 1\t\t\t\t\t\t\t\t& assumption \\\\\ns in ascending\t\t\t\t\t\t\t& def of $ascending$ \\\\\n\\# s = 1 \\implies s \\in ascending\t\t\t\t& $\\implies$-intro \\\\\nn: \\nat_1 | n > 1\t\t\t\t\t\t\t& intro $n$ \\\\\n\\#s = n \\implies s \\in ascending\t\t\t\t& inductive assumption\n\n\\end{argue}\n\n%\\printbibliography\n\n\\end{document}  ", "meta": {"hexsha": "6d3f22d9fecc77d6da089e2813eb62bd61363191", "size": 3615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tictactoe_project/docs/sorting/sorting.tex", "max_stars_repo_name": "agryman/sean", "max_stars_repo_head_hexsha": "11baf69c6eb9308266126bf9c8b1c67c6fd33afc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-28T18:17:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-28T18:17:52.000Z", "max_issues_repo_path": "tictactoe_project/docs/sorting/sorting.tex", "max_issues_repo_name": "agryman/sean", "max_issues_repo_head_hexsha": "11baf69c6eb9308266126bf9c8b1c67c6fd33afc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-21T21:33:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:33:00.000Z", "max_forks_repo_path": "tictactoe_project/docs/sorting/sorting.tex", "max_forks_repo_name": "agryman/sean", "max_forks_repo_head_hexsha": "11baf69c6eb9308266126bf9c8b1c67c6fd33afc", "max_forks_repo_licenses": ["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.4722222222, "max_line_length": 112, "alphanum_fraction": 0.6766251729, "num_tokens": 1058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754548076477, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6034471090718779}}
{"text": "\\documentclass[12pt]{amsart}\n\\title{Optimal Ricci matrix computations.}\n\\begin{document}\n\\maketitle\n\n\\section{Notation}\n\\label{sec:Notation}\n\nThroughout the paper we use $\\times$ to denote pointwise multiplication. Consequently, we also use $f^{\\times2}$ to denote pointwise powers. We also assume that operators are represented by matrices and functions are column vectors. \n\nWe will use $M_i$ to denote a row of a matrix, and $M_{:i}$ to denote its column.\n\nSuppose $r$ is a row vector, $c$ is a column vector and $M$ is a matrix. We can perform pointwise operations between objects not having the same size. For example $c+M$ should be understood as the column is first promoted to a square matrix with the same column repeated. The same way we can promote a row to a matrix, or a number to any shape. Note that such extension of $+$ and $-$ preserves distributive property of matrix multiplication. We can also apply the promotion to pointwise multiplication $\\times$.\n\nWe will exploit the following property:\n\\begin{align}\\label{property}\n    r(M\\times c)&=(r\\times c^T)M, \\qquad r\\text{ can be a matrix}\\\\\n    (r\\times M)c &= M(c\\times r^T), \\qquad c\\text{ can be a matrix}.\n\\end{align}\nNote that $r\\times c^T$ gives a row vector, while $r\\times c$ would give a matrix (both $r$ and $c$ would be promoted first).\n\n\\section{Initial computations}\nWe start with\n\\begin{align*}\n    \\Gamma(L, f, h) = \\frac{1}{2} \\left(L(f\\times h) - f\\times Lh-h\\times Lf\\right),\n\\end{align*}\nwhich is a column vector.\nWe are interested in\n\\begin{align}\n    \\Gamma_2(L, f, f) &= \\frac{1}{2}L\\Gamma(L, f, f) - \\Gamma(L, Lf, f)=\\cdots=\\nonumber\n    \\\\&=\\frac{1}{4} L^2f^{\\times2}-L(f\\times Lf)+\\frac{1}{2}f\\times L^2f+\\frac{1}{2}(Lf)^{\\times2}.\\label{Gamma2}\n\\end{align}\n\nWe have a squared distance matrix $D$ (size $n\\times x$), Laplace matrix $L$, and a set of functions $f$, one for each entry of $D$ (pair of points).\n\nWe have $f^{(i,j)}=D_{:i}-D_{:,j}$. We take a difference of two columns. Hence we have $n^2$ functions with $n$ entries each. This makes it hard to store all of them.\n\nEach function $f^{(i,j)}$ is used to find one entry $R_{i,j}$ in the Ricci matrix:\n\\begin{align*}\n    R_{i,j} = \\Gamma_2(L, f^{(i,j)}, f^{(i,j)})_{i}.\n\\end{align*}\nWe take $i$-th row from a column vector $\\Gamma_2(\\ldots)$.\n\\section{One row in Ricci matrix}\n\\label{sec:RowInRicci}\nWe will try to compute the whole row of the Ricci matrix at once.\n\nWe define the functions matrix $F(i)=D_{:i}-D$.  Then $F(i)$ encodes all functions $f^{(i,\\cdot)}$ as its columns.\n\nWe can use $F(i)$ in place of $f$ in the formula \\eqref{Gamma2} for $\\Gamma_2$. We get \n\\begin{align*}\n    R_{i} = \\left(\\frac{1}{4} L^2F(i)^{\\times2}-L(F(i)\\times LF(i))+\\frac{1}{2}F(i)\\times L^2F(i)+\\frac{1}{2}(LF(i))^{\\times2}\\right)_{i}.\n\\end{align*}\nSince we are computing just one row, we can do that in each term. To further simplify the notation we drop $(i)$ from $F$.\n\nNote that for matrices $(A \\times B)_i = A_i\\times B_i$ and $(AB)_i = A_i B$. Hence\n\\begin{align}\\label{RicciRow}\n    R_{i} = \\frac{1}{4} (L^2)_i F^{\\times2}-L_i(F\\times LF)+\\frac{1}{2}F_i\\times (L^2)_iF+\\frac{1}{2}(LF)^{\\times2}_i.\n\\end{align}\n\nFirst note that\n\\begin{align*}\nLF = L(D_{:i}-D)=(LD)_{:i}-LD.\n\\end{align*}\n\nWe can precompute a few matrix products independent of $i$:\n\\begin{align*}\n    A&=L^2,\\\\\n    B&=LD,\\\\\n    C&=AD.\n\\end{align*}\n\\textbf{Note that $B$ and $C$ are not symmetric, since products of symmetric matrices generally are not symmetric.}\n\nNow we will look at each term in \\eqref{RicciRow}. The last term is the simplest:\n\\begin{align*}\n    (LF)^{\\times2}_i&=(B_{:i}-B)^{\\times2}_i=(B_{ii}-B_i)^{\\times2}\n    \\\\&=\n    (B^{\\times2})_i+(B^{\\times2})_{ii}-2B_i\\times B_{ii}.\n\\end{align*}\nHence it can be computed as row$\\times$row operation.\n\n    The first term can also be simplified:\n    \\begin{align*}\n\t(L^2)_i F^{\\times2} &= A_i(D^{\\times2}+D^{\\times2}_{:i}-2D\\times D_{:i})\n\t\t\t\\\\&=\n\t\t\tA_iD^{\\times2}+A_i(D^{\\times2})_{:i} -2 A_i (D\\times D_{:i})\n\t\t\t\\\\&=\n\t\t\t(A D^{\\times2})_i+(A D^{\\times2})_{ii} -2 (A\\times D)_iD,\n    \\end{align*}\n    In the last step we used symmetry of $D$ and \\eqref{property}. For nonsymmetric matrix column $D_{:,i}$ would simply need to be transposed instead of changing to $D_i$. \n    Next we have\n    \\begin{align*}\n\tF_i\\times (L^2)_iF &= (D_{ii}-D_i)\\times [A_i (D_{:i}-D)] \n\t\\\\&=\n\t(D_{ii}-D_i)\\times ((AD)_{ii}-(AD)_i)\n\t\\\\&=\n\t(D_{ii}-D_i)\\times (C_{ii}-C_i)\n\t\\\\&=\n\t(D\\times C)_i + (D\\times C)_{ii} - D_i\\times C_{ii},\n    \\end{align*}\n    since $D_{ii}=0$.\n    Finally\n    \\begin{align*}\n\tL_i(F\\times LF)&=L_i((D_{:i}-D) \\times (B_{:i}-B)) =\n\t\\\\&=\n\tL_i\\left(D\\times B+(D\\times B)_{:i}-D\\times B_{:i}-B\\times D_{:i}\\right)=\n\t\\\\&=\n\tG_i+G_{ii}-(L_i\\times (B^T)_i)D-(L_i\\times D_i)B\n\t\\\\&=\n\tG_i+G_{ii}-(L\\times B^T)_{i}D-(L\\times D)_iB,\n    \\end{align*}\n    where $G=L(D\\times B)$. \n\n    To make our notation even more compact we let $diag(M)$ be a column vector composed of the diagonal elements of $M$. Then\n    \\begin{align*}\n\t\\overline M = M + diag(M)\n    \\end{align*}\nsatisfies \n\\begin{align*}\n\\overline M_i = M_i+M_{ii}.\n\\end{align*}\nWith this notation we can represent a row of Ricci matrix (given by \\eqref{RicciRow}) as\n\\begin{align*}\n    R_i &= \\frac{1}{4}\\left( \\overline{AD^{\\times2}} \\right)_i -  \\frac{1}{2}(A\\times D)_i D \n    \\\\&\n    -\\left( \\overline{L(D\\times B)} \\right)_i +(L\\times B^T)_iD +(L\\times D)_i B\n    \\\\&\n    + \\frac{1}{2}\\left(  \\overline{D\\times C}\\right)_i - \\frac{1}{2}D_i\\times C_{ii}\n    \\\\&\n    + \\frac{1}{2}\\left(\\overline{ B^{\\times2}}\\right)_i - B_i\\times B_{ii}.\n\\end{align*}\n\n\\section{Full Ricci matrix}\nNote that the formula for the row of the Ricci matrix contains only take a row operations for various matrices. We can also combine all overline operations. Hence\n\n\\begin{align}\n    R &= \\overline{\\frac{1}{4}AD^{\\times2} -L(D\\times B) +\\frac{1}{2}D\\times C + \\frac{1}{2}B^{\\times2}}\\nonumber\n    \\\\&\n    +\\left((L\\times B^T)-  \\frac{1}{2}(A\\times D)\\right)D +(L\\times D) B\\label{2ndline}\n     \\\\&\n     - \\frac{1}{2}D\\times diag(C) - B\\times diag(B),\\nonumber\n\\end{align}\nwith $A=L^2$, $B=LD$ and $C=AD$, a $diag$ denoting a column vector composed of the diagonal of a matrix.\n\n\\section{Order of computations}\n\\label{sec:OrderOfComputations}\n\nWe want to minimize the number of multiplications while keeping memory requirement small. Clearly, 7 matrix multiplications and 3 extra matrices are enough. Although it should be possible to bring this down to 2 extra matrices. Furthermore, Laplacian could be just computed as needed, since it is really fast.\n\n\\subsection{Only 2 temporary matrices}\n\\label{sec:Only2Temporary}\n\nWe will avoid computing $A$ by taking $L$ out of the first two terms.\n\\begin{itemize}\n    \\item Compute $B\\leftarrow D^{\\times2}/4$ first, then $A\\leftarrow LB$ (1st M-M multiply).\n    \\item Compute $B\\leftarrow LD$ (2nd M-M multiply), then $A\\leftarrow A-D\\times B$.\n    \\item Now $R\\leftarrow LA$ (3rd M-M multiply).\n    \\item Compute $A\\leftarrow LB$ (4th M-M multiply, called C in the section above), then finish adding $diag$ terms and overline.\n\\end{itemize}\nNow we need the second line terms from \\eqref{2ndline}. We already have $B$ computed.\n\\begin{itemize}\n    \\item Find $A\\leftarrow LL$ (5th M-M multiply), then $A\\leftarrow \\Big((L\\times B^T)-  \\frac{1}{2}(A\\times D)\\Big)$.\n            \\item Now $R \\leftarrow R+AD$ (6th M-M multiply, full dgemm).\n                \\item Finally, $A\\leftarrow D\\times L$, then $R\\leftarrow R+AB$ (7th M-M multiply, full dgemm).\n\\end{itemize}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "74cac44c5de5f7b7c53373468b36bf4f9e3dc6b9", "size": 7540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/newRicci.tex", "max_stars_repo_name": "tonyache/Ricci_project", "max_stars_repo_head_hexsha": "abaa164b2969f9ad5202d1cf1d313f0b159b8ad9", "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/newRicci.tex", "max_issues_repo_name": "tonyache/Ricci_project", "max_issues_repo_head_hexsha": "abaa164b2969f9ad5202d1cf1d313f0b159b8ad9", "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/newRicci.tex", "max_forks_repo_name": "tonyache/Ricci_project", "max_forks_repo_head_hexsha": "abaa164b2969f9ad5202d1cf1d313f0b159b8ad9", "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.3529411765, "max_line_length": 512, "alphanum_fraction": 0.6586206897, "num_tokens": 2683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6034281268884876}}
{"text": "\\mainsection{Math Library}\r\nEventually we expect every floating point type to\r\nhave a full set of math functions. \r\nRemember the \\verb|ClearIEEE| type is must faster than\r\nthe \\verb|ClearFixed<K,F>| type, but the \\verb|SecretFixed<K,F>| \r\nis generally much faster than the \\verb|SecretIEEE| type.\r\nTo include the functions in the math library use\r\n\\begin{lstlisting}\r\n    use scale_std::math::*;\r\n\\end{lstlisting}\r\nThis captures traits \\verb|Floor|, \\verb|FAbs|\r\nand \\verb|Sqrt| (implementing member functions\r\n\\verb|floor()|, \\verb|fabs()| and \\verb|sqrt()| respectively), \r\nplus also a supertrait called\r\n\\verb|Float| which captures much of the properties\r\ncommon to all floating point types.\r\n\r\nCurrently the following are available (we comment the\r\nfunction out if it is not yet fully tested/implemented):\r\n\r\n\\subsection{Generic Routines}\r\n\r\n\\func{poly_eval(poly, x)}\r\nThis generic function with signature\r\n\\begin{lstlisting}\r\n  pub fn poly_eval<S, C, const N: u64>(poly: Array<C, N>, x: S) -> S\r\n  where\r\n    S: Float,\r\n    S: Add<C, Output = S>,\r\n    S: Mul<S, Output = S>,\r\n    C: Float,\r\n\\end{lstlisting}\r\nallows one to evaluate a polynomial in type \\verb|C| \r\n(a clear floating point type) at a value of type \r\n\\verb|S| (which is either the {\\em same} clear floating\r\npoint type, or its {\\em associated} secret variant).\r\n\r\n\\func{Pade(P, Q, x)}\r\nThis generic function with signature\r\n\\begin{lstlisting}\r\n  pub fn Pade<S, C, const N: u64>\r\n   (poly_p: Array<C, N>, poly_q: Array<C, N>, x: S) -> S\r\n  where\r\n    S: Float,\r\n    S: Add<S, Output = S>,\r\n    S: Mul<S, Output = S>,\r\n    S: Div<S, Output = S>,\r\n    S: Mul<C, Output = S>,\r\n    S: From<C>,\r\n    C: Float,\r\n\\end{lstlisting}\r\nallows one to evaluate the Pade approximation given\r\nby polynomials $P$ and $Q$ in type \\verb|C|\r\n(a clear floating point type) at a value of type\r\n\\verb|S| (which is either the {\\em same} clear floating\r\npoint type, or its {\\em associated} secret variant).\r\nThe polynomials $P$ and $Q$ must have the same degree.\r\n\r\n\r\nAll floating point types \\verb|T| have predefined constants\r\n\\begin{lstlisting}\r\n   T::two_pi();\r\n   T::pi();\r\n   T::half_pi();\r\n   T::ln2();\r\n   T::e();\r\n\\end{lstlisting}\r\n\r\n\r\n\\subsection{ClearIEEE}\r\nThe following are all implemented via a local function call\r\nto the SCALE C++ runtime; thus are relatively fast.\r\n\\begin{lstlisting}\r\n    let c = ClearIEEE::from(0.5431);\r\n    let t = c.acos();\r\n    let t = c.asin();\r\n    let t = c.atan();\r\n    let t = c.cos();\r\n    let t = c.cosh();\r\n    let t = c.sin();\r\n    let t = c.sinh();\r\n    let t = c.tan();\r\n    let t = c.tanh();\r\n    let t = c.exp();\r\n    let t = c.exp2()\r\n    let t = c.log();\r\n    let t = c.log2();\r\n    let t = c.log10();\r\n    let t = c.ceil();\r\n    let t = c.fabs();\r\n    let t = c.floor();\r\n    let t = c.sqrt();\r\n\\end{lstlisting}\r\nNote, \\verb|exp2()| computes the function $2^x$.\r\n\r\n\\subsection{SecretIEEE}\r\nThe following functions are implemented\r\n\\begin{lstlisting}\r\n    let s = SecretIEEE::from(0.5431);\r\n    let t = s.acos();\r\n    let t = s.asin();\r\n    let t = s.atan();\r\n    let t = s.cos();\r\n    let t = s.cosh();\r\n    let t = s.sin();\r\n    let t = s.sinh();\r\n    let t = s.tan();\r\n    let t = s.tanh();\r\n    let t = s.exp();\r\n    let t = s.exp2()\r\n    let t = s.log();\r\n    let t = s.log2();\r\n    let t = s.log10();\r\n    let t = s.ceil();\r\n    let t = s.fabs();\r\n    let t = s.floor();\r\n    let t = s.sqrt();\r\n\\end{lstlisting}\r\nNote logarithms of negative values result in undefined\r\nbehaviour.\r\n\r\n\\subsection{ClearFixed}\r\nThe following functions are implemented\r\n\\begin{lstlisting}\r\n    let c: ClearFixed<40,20>= ClearFixed::from(0.5431);\r\n    let t = c.acos();\r\n    let t = c.asin();\r\n    let t = c.atan();\r\n    let t = c.cos();\r\n    let t = c.cosh();\r\n    let t = c.sin();\r\n    let t = c.sinh();\r\n    let t = c.tan();\r\n    let t = c.tanh();\r\n    let t = c.exp();\r\n    let t = c.exp2()\r\n    let t = c.log();\r\n    let t = c.log2();\r\n    let t = c.log10();\r\n    let t = c.ceil();\r\n    let t = c.fabs();\r\n    let t = c.floor();\r\n    let t = c.sqrt();\r\n\\end{lstlisting}\r\n\r\n\\subsection{SecretFixed}\r\nThe following functions are implemented\r\n\\begin{lstlisting}\r\n    let s: SecretFixed<40,20>= SecretFixed::from(0.5431);\r\n    let s = c.acos();\r\n    let s = c.asin();\r\n    let s = c.atan();\r\n    let s = c.cos();\r\n    let s = c.cosh();\r\n    let s = c.sin();\r\n    let s = c.sinh();\r\n    let s = c.tan();\r\n    let s = c.tanh();\r\n    let s = c.exp();\r\n    let s = c.exp2()\r\n    let s = c.log();\r\n    let s = c.log2();\r\n    let s = c.log10();\r\n    let s = c.ceil();\r\n    let s = c.fabs();\r\n    let s = c.floor();\r\n    let s = c.sqrt();\r\n\\end{lstlisting}\r\n\r\n", "meta": {"hexsha": "a9076fdfd2025738e430191dc3bdc110cafedc07", "size": 4636, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "RustDocumentation/Math.tex", "max_stars_repo_name": "karannewatia/SCALE-MAMBA", "max_stars_repo_head_hexsha": "467b33a6c80050789204ea3ee3b5cf0113354f85", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-26T06:10:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T06:10:49.000Z", "max_issues_repo_path": "RustDocumentation/Math.tex", "max_issues_repo_name": "karannewatia/SCALE-MAMBA", "max_issues_repo_head_hexsha": "467b33a6c80050789204ea3ee3b5cf0113354f85", "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": "RustDocumentation/Math.tex", "max_forks_repo_name": "karannewatia/SCALE-MAMBA", "max_forks_repo_head_hexsha": "467b33a6c80050789204ea3ee3b5cf0113354f85", "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": 27.2705882353, "max_line_length": 69, "alphanum_fraction": 0.5828300259, "num_tokens": 1387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6034207606037104}}
{"text": "\n\\chapter{Multiscale Entropy Theory}\n\\label{ch_entrop}\n\\index{entropy}\n\\section{Entropy and Image Restoration}\n\n\\subsection{Introduction}\n\nThe term ``entropy'' is due to Clausius (1865), and the concept of \nentropy was introduced by Boltzmann into statistical mechanics\nin order to measure the number of microscopic ways that a given macroscopic\nstate can be realized. Shannon (1948) \\cite{ima:shannon48} founded the mathematical theory of\ncommunication when he suggested that the information gained in a \nmeasurement depends on the number of possible outcomes out of \nwhich one is realized. Shannon also suggested that \nthe entropy can be used for maximization of the bit transfer rate under\na quality constraint. Jaynes (1957) \\cite{entropy:jaynes57} \nproposed to use the entropy measure\nfor radio interferometric image deconvolution,  in\norder to select between a set of possible solutions that which contains the\nminimum of information or, following his entropy definition, that \nwhich has maximum entropy. In principle, the solution verifying such \na condition should be the most reliable. A great deal of work has been \ncarried out \nin the last 30 years on the use of the entropy for the general problem\nof data filtering and deconvolution \n\\cite{entropy:ables74,entropy:bontekoe94,entropy:burg67,entropy:frieden75,entropy:gull91,entropy:narrayan86,starck:pan96,entropy:skilling89,entropy:weir92,entropy:djafari94,entropy:djafari98}. \n\nTraditionally information and entropy are determined from events and the\nprobability of their occurrence.  Signal and noise are basic building-blocks \nof signal and data analysis in the physical sciences.  Instead of the \nprobability of an event, we are led to consider the probabilities of our\ndata being either signal or noise. \n\nObserved data $Y$ in the physical sciences \nare generally corrupted by noise, which is often additive and which \nfollows in many cases a Gaussian distribution, a Poisson distribution, or\na combination of both.  Other noise models may also be considered.\n Using Bayes' theorem to evaluate the probability distribution of the \nrealization of the original signal $X$,\nknowing the data $Y$, we have\n \n\\begin{eqnarray}\n \\mathrm{p}(X|Y) = \\frac{\\mathrm{p}(Y|X).\\mathrm{p}(X)}{\\mathrm{p}(Y)}\n\\label{eqn_bayes}\n\\end{eqnarray}\n$\\mathrm{p}(Y|X)$ is the conditional probability distribution of getting the data \n$Y$ given an original signal $X$, i.e.\\ it represents the distribution \nof the noise. It is given, in the case of uncorrelated Gaussian \nnoise with variance $\\sigma^2$, by:\n\\begin{eqnarray}\n \\mathrm{p}(Y|X) = \\mathrm{exp} \\left\\{\n-\\sum_{pixels} \\frac{ (Y-X)^2}{2{\\sigma}^2} \\right\\}\n\\label{eqn_proba}\n\\end{eqnarray}\nThe denominator in  equation \\ref{eqn_bayes} is independent of $X$ and\n is considered as a constant (stationary noise). \n$\\mathrm{p}(X)$ is the a priori distribution \nof the solution $X$. In the absence of any information on the solution \n$X$ except its positivity, a possible course of action \nis to derive the probability\nof $X$ from its entropy, which is defined from information theory.\n\nThe main idea of information theory \\cite{ima:shannon48} is to establish\na relation between the received information and the probability of\nthe observed event \\cite{ima:bijaoui84}. If we note ${\\cal I}(E)$ the information\nrelated to the event $E$, and $p$ the probability of this\nevent happening, then we consider that\n\\begin{eqnarray}\n%\\cal{I}(E) =    f(p)       \n{\\cal I}(E) = f(p)\n\\end{eqnarray}\n\nThen we assume the two following principles:\n\\begin{itemize}\n\\item The information is a decreasing function of the probability. This \nimplies that the more information we have, the  less will be the probability \nassociated with one event.\n\\item Additivity of the information. If we have two independent events \n$E_1$ and $E_2$, the information ${\\cal I}(E)$ associated with the happening\nof both is equal\nto the addition of the information of each of them.\n\\begin{eqnarray}\n{\\cal I}(E) = {\\cal I}(E_1) + {\\cal I}(E_2)\n\\end{eqnarray}\n\\end{itemize}\n\nSince $E_1$ (of probability $p_1$) and $E_2$ (of probability $p_2$) are \nindependent, then the probability of both happening is equal to the\nproduct of $p_1$ and $p_2$.  Hence\n\\begin{eqnarray}\nf(p_1 p_2) = f(p_1) + f(p_2) \n\\end{eqnarray}\n\nThen we can say that the information measure is\n\\begin{eqnarray}\n{\\cal I}(E) = k \\ln(p)\n\\end{eqnarray}\nwhere k is a constant. Information must be positive, and $k$\nis generally fixed at $-1$.\n\nAnother interesting measure is the mean information which is denoted\n\\begin{eqnarray}\nH = - \\sum_i p_i \\ln(p_i)\n\\end{eqnarray}\nThis quantity is called the entropy of the system and was established by \nShannon in 1948 \\cite{ima:shannon48}.\n\nThis measure has several properties:\n\\begin{itemize}\n\\item It is maximal when all events have the same probability \n$p_i = 1/ N_e$ ($N_e$ being the number of events), and is equal to \n$\\ln(N_e)$. It is in this \nconfiguration that the system is the most undefined.\n\\item It is minimal when one event is sure. In this case, the system is \nperfectly known, and no information can be added.\n\\item The entropy is a positive, continuous, and symmetric function.\n%\\item The mean information, obtained in two steps, can be added.\n\\end{itemize}\n\nIf we know the entropy $H$ of the solution (the next section \ndescribes different ways to calculate it), \nwe derive its probability by\n\\begin{eqnarray}\n\\mathrm{p}(X) = \\mathrm{exp}(- \\alpha H(X))\n\\label{info_prop}\n\\end{eqnarray}\n\nGiven the data, the most probable image is obtained by maximizing\n$\\mathrm{p}(X|Y)$. Taking the logarithm of equation \\ref{eqn_bayes}, we \nthus need to maximize\n\\begin{eqnarray}\n \\ln (\\mathrm{p}(X|Y))  = - \\alpha  H(X) + \\ln(\\mathrm{p}(Y|X)) - \n\\ln(\\mathrm{p}(Y))\n\\end{eqnarray}\nThe last term is a constant and can be omitted.\nThen, in the case of Gaussian noise, the solution is found by minimizing \n\\begin{eqnarray}\nJ(X) = \\sum_{pixels} \\frac{{(Y-X)}^{2}}{2 {\\sigma}^{2}} + {\\alpha} H(X)\n= \\frac{{\\chi}^2}{2} + {\\alpha} H(X)\n\\label{eqn_j1}\n\\end{eqnarray}\nwhich is a linear combination of two terms: the entropy of the signal,\nand a quantity corresponding to ${\\chi}^2$ in statistics measuring the\ndiscrepancy between the data and the predictions of the model.\n$\\alpha$ is a parameter that can be viewed alternatively as \na Lagrangian parameter or a value fixing the relative weight between \nthe goodness-of-fit and the entropy H. \n\nFor the deconvolution problem, the object-data relation is given by the\nconvolution\n\\begin{eqnarray}\nY = P * X\n\\end{eqnarray}\nwhere $P$ is the point spread function, and the solution is found (in the case\nof Gaussian noise) by minimizing\n\\begin{eqnarray}\nJ(X) = \\sum_{pixels} \\frac{{(Y-P*X)}^{2}}{2 {\\sigma}^{2}} + {\\alpha} H(X)\n\\end{eqnarray}\n\nThe way the entropy is defined is fundamental, because from its definition\nwill depend the solution. The next section discusses the different approaches \nwhich have been proposed in the past.\n\n\\clearpage\n\\newpage\n\n\\subsection{The concept of entropy}\n\\label{sect_entr}\nWe wish to estimate an unknown probability density $p(X)$ of the data.\n Shannon \\cite{ima:shannon48}, in the framework of the information \n theory, has defined the entropy of an image $X$ by \n\\begin{eqnarray}\nH_s(X) = - \\sum_{k=1}^{N_b} p_k \\log p_k\n\\end{eqnarray}\nwhere  $X=\\left\\{X_1,.. X_N \\right\\}$ is an image \ncontaining integer values, $N_b$ is number of possible values which can \ntake a given pixel $X_k$ \n(256 for a 8 bits image), and \n $p_k$ values are derived the histogram of $X$:\n\\begin{eqnarray}\np_k = {  \\mbox{\\#} X_j = k \\over  N} \n\\end{eqnarray}\n$\\mbox{\\#} X_j = k $ giving the number of pixels  $X_j = k$.\n\nIf the image contains floating values, it is possible to\nto build up the histogram $L$ of values $L_i$, using\na suitable interval $\\Delta$, counting up how many times $m_k$ each interval\n$(L_k, L_k + \\Delta)$ occurs among the N occurrences. Then the probability\nthat a data value belongs to an interval $k$ is $p_k = \\frac{m_k}{N}$, and\neach data value has a probability $p_k$.  \n\nThe entropy is minimum and equal to zero when the signal is flat, and\nincreases when we have some fluctuations. Using this entropy in \nequation~\\ref{eqn_j1} leads to minimize:\n\\begin{eqnarray}\nJ(X) = \\frac{{\\chi}^2}{2} + {\\alpha} H_s(X)\n\\label{eqn_j2}\n\\end{eqnarray}\nIt is a minimum entropy restoration method.\n \nThe trouble with this approach is that, because the number of occurrences is\nfinite, the estimate $p_k$ will be in error by an amount proportional\nto $m_k^{-\\frac{1}{2}}$~\\cite{entropy:frieden91}. The error becomes significant when\n$m_k$ is small. Furthermore this kind of entropy definition is not\neasy to use for signal restoration, because the gradient of \nequation~\\ref{eqn_j2} is not easy to compute. \nFor these reasons, other\nentropy functions are generally used. The main ones are:\n\\begin{itemize}\n\\item Burg \\cite{entropy:burg67}:\n\\begin{eqnarray}\nH_b(X) = -\\sum_{k=1}^N \\ln(X_k) \n\\end{eqnarray}\n\\item Frieden \\cite{entropy:frieden75}:\n\\begin{eqnarray}\nH_f(X) = -\\sum_{k=1}^N X_k \\ln(X_k)\n\\end{eqnarray}\n\\item Gull and Skilling \\cite{entropy:gull91}:\n\\begin{eqnarray}\nH_g(X) = \\sum_{k=1}^N  X_k - M_k - X_k \\ln({X_k \\over M_k})\n\\end{eqnarray}\nwhere $M$ is a given model, usually taken as a flat image\n\\end{itemize}\nwhere $N$ is the number of pixels, and $k$ represents an index pixel.\n\nEach of these entropies can be used, and they correspond to different\nprobability distributions that one can associate with \nan image \\cite{entropy:narrayan86}.\n(See \\cite{entropy:frieden75,entropy:skilling89} for descriptions).\nThe last definition of the entropy has the advantage of having a zero\n maximum when $X$ equals the model $M$. \nAll of these entropy measures are negative (if $X_k > 1$), \nand maximum when the image is flat.\nThey are negative because an offset term is omitted which has no importance\nfor the minimization of the functional. The fact that we consider that\na signal has maximum information value when it is flat is evidently\na curious way to measure information. A consequence is that we must\nnow maximize the entropy if we want a smooth solution, and\nthe probability of $X$ \nmust be redefined by:\n\\begin{eqnarray}\n\\mathrm{p}(X) = \\mathrm{exp}(\\alpha H(X))\n\\end{eqnarray}\nThe sign has been inverted\n(see equation~\\ref{info_prop}), which is natural if we want the best\nsolution to be the smoothest. These three entropies, above, lead to the \nMaximum Entropy Method method (MEM), for which the \nsolution is found by minimizing \n(for Gaussian noise)\n\\begin{eqnarray}\nJ(X) = \\sum_{k=1}^N \\frac{{(Y_k-X_k)}^{2}}{2 {\\sigma}^{2}} - {\\alpha} H(X)\n\\label{eqn_j3}\n\\end{eqnarray}\n\nThese different entropy functions  which have\nbeen proposed for image restoration have the property of being maximal when\nthe image is flat, and of decreasing when we introduce some information.\nSo minimizing the information is equivalent to maximizing the entropy, and\nthis has led to the well known Maximum Entropy Method (MEM). For the Shannon\nentropy (which is obtained from the histogram of the data), \nthis is the opposite. The entropy is null for a flat image, and increases\nwhen the data contains some information. So, if the Shannon entropy were \nused for restoration, this would lead to a Minimum Entropy Method.\n\nIn 1986, Narayan and Nityanda \\cite{entropy:narrayan86} \ncompared several entropy functions,\n and finally \nconcluded by saying that all were comparable if they have good\nproperties, i.e.\\ they enforce positivity, and they have a negative \nsecond derivative which discourages ripple. They showed also that \nresults varied strongly with the background level, and\nthat these entropy functions produced poor results\nfor negative structures, i.e.\\ structures under the background level\n(absorption area in an image, absorption band in a spectrum, etc.), and \ncompact structures in the signal.\nThe Gull and Skilling entropy gives rise to  \nthe difficulty of estimating a model.\nFurthermore it has been shown \\cite{entropy:bontekoe94} \nthat the solution is dependent on this choice.\n\nThe determination of the $\\alpha$ parameter is also not an easy task and in \nfact it is a very serious problem facing the maximum entropy method.\nIn the historic MAXENT algorithm of Skilling and Gull, the choice of $\\alpha$ \nis such that it must satisfy the ad hoc constraint $\\chi^2=N$ when \nthe deconvolution is achieved, $N$ being\n the number of degrees of freedom of the system i.e.\\ the number of pixels \nin image deconvolution problems.\nBut this choice systematically leads to an under-fitting of the data \n \\cite{entropy:titterington85} which is clearly apparent for imaging problems \nwith little blurring. In reality, the $\\chi^2$ statistic is expected to \nvary in the range $N\\pm\\sqrt{2N}$ from one data realization to another.\n In the Quantified Maximum Entropy point of view \\cite{entropy:skilling89}, the \noptimum value of $\\alpha$ is determined by including its probability \nP($\\alpha$) in Bayes' equation and then by maximizing the marginal \nprobability of having $\\alpha$, knowing the data and the model $m$.\n In practice, a value of $\\alpha$ which is too large gives a resulting image \nwhich is too regularized\n\\index{regularization}\nwith a large loss of resolution.  A value which is too small\nleads to a poorly regularized solution showing unacceptable artifacts. \nTaking a flat model of the prior image softens the discontinuities \nwhich may appear unacceptable for astronomical images often containing \nstars and other point-like objects. Therefore the basic maximum entropy \nmethod appears to be not very\nappropriate for this kind of image which contains high and low spatial \nfrequencies \nat the same time. Another point to be noted \nis a ringing effect of the maximum entropy method algorithm,\nproducing artifacts around bright sources.\n\n To solve these problems while still using the maximum entropy concept, some \nenhancements of the maximum entropy method have been proposed.\nNoticing that neighboring pixels of reconstructed images with MAXENT \ncould have values differing a lot in expected flat regions \\cite{entropy:charter89}, \nGull and Skilling introduced the concepts of hidden image $S$ and intrinsic \n correlation function $C$ (Gaussian or cubic spline-like) \nin the Preblur MAXENT algorithm.\n\\index{maximum entropy method}\n\\index{MEM}\n\\index{intrinsic correlation function}\n\n The ICF describes a minimum scale length of correlation in the desired \nimage $O$ which is achieved by assuming that\n\\begin{eqnarray}\n O=C*S\n\\end{eqnarray}\nThis corresponds to imposing a  \nminimum resolution on the solution $O$. \nSince the hidden space image $S$ is not \nspatially correlated, this can be regularized by the entropy \n\\begin{eqnarray}\nH_g(h)=\\sum_{k=1}^N  S_k - M_k - S_k \\ln(\\frac{S_k}{M_k})\n\\end{eqnarray}\n\nSince in astronomical images many scale lengths are present, the \n{\\it Multi-channel Maximum Entropy Method}, developed by Weir \n\\index{maximum entropy method}\n\\index{MEM}\n\\cite{entropy:weir91,entropy:weir92}, uses a set of \nICFs having different scale lengths, each defining a channel. The \nvisible-space image is now formed by a weighted sum of \n the visible-space image\nchannels $O_j$:\n   \n\\begin{eqnarray}\n  O= \\sum_{j=1}^{N_c} p_j O_j\n\\end{eqnarray}\nwhere $N_c$ is the number of channels.\nLike in Preblur MAXENT, each solution $O_j$ is supposed to be the result of the\nconvolution between a hidden image $S_j$ with a low-pass filter (ICF) $C_j$:\n\\begin{eqnarray}\nO_j = C_j * S_j\n\\end{eqnarray}\n\nBut such a method has several drawbacks:\n\\begin{enumerate}\n\\item The solution depends on the width of the ICFs \\cite{entropy:bontekoe94}.\n\\item There is no rigorous way to fix the weights $p_j$ \\cite{entropy:bontekoe94}.\n\\item The computation time increases linearly with the number of pixels.\n\\item The solution obtained depends on the choice of the models $M_j$ \n($j = 1 \\dots N_c$) which were chosen independently of the channel.\n\\end{enumerate}\n\\index{intrinsic correlation function}\n\nIn 1993, Bontekoe et al.\\ \\cite{entropy:bontekoe94} used a special application \nof this method which \nthey called Pyramid Maximum Entropy on infrared image data.\n\\index{pyramid}\nThe pyramidal approach allows the user to have constant ICF width, and the \ncomputation time is reduced. It is demonstrated \\cite{entropy:bontekoe94} that\nall weights can be fixed ($p_j = 1$ for each channel). \n\nThis method eliminates the first three drawbacks, and\ngives better reconstruction of the sharp \nand smooth structures. But in addition \nto the two last drawbacks, a new one is added:\nas the images $O_j$ have different sizes (due to the pyramidal approach),\n\\index{pyramid}\nthe solution $O$ is built by duplicating the pixels of \nthe subimages $O_j$ of each channel. This procedure is known to produce \nartifacts due to the  appearance of high frequencies which are\nincompatible with the \nreal spectrum of the true image $\\hat{O}$.\n\nHowever this problem can \nbe easily overcome by duplicating the pixels before convolving with the ICF, \nor expanding the channels using linear \ninterpolation. Thus the introduction of the ``pyramid of resolution'' has \nsolved some problems and brought lots of improvements to the classic maximum\nentropy method, but has also raised other questions. In order to derive the\nmodel from a physical value, Pantin and Starck \\cite{starck:pan96} \nintroduced the wavelet \ntransform, and defined entropy as follows:\n\\begin{eqnarray}\nH(O) =  \\frac{1}{\\sigma_I^2}\\sum_{j=1}^l \\sum_{k=1}^{N_j} \\sigma_j( w_{j,k}- M_{j,k}- |w_{j,k}|\\ln{\\frac{|w_{j,k}|}{M_{j,k}}})\n\\label{eqn_entr}\n\\end{eqnarray}\nwhere $\\sigma_I$ is the noise standard deviation in the data, $l$ is the number of scales, and\n$N_j$ is the number of samples in the band $j$\n($N_j = N$ for the \\`a trous algorithm). \nThe multiscale entropy is the sum of the entropy at each scale.\n\nThe coefficients $w_{j,k}$ are wavelet coefficients, and we \ntake the absolute value of $w_{j,k}$ in this definition because the  \nvalues of $w_{j,k}$ can be positive or negative, and a negative signal \ncontains also some information in\nthe wavelet transform. \n\nThe advantage of such a definition of entropy is\n the fact we can use previous work concerning the wavelet transform and\nimage restoration \\cite{starck:mur95_2,starck:sta94_1,starck:sta94_4}. \nThe noise behavior has already been studied in the wavelet transform \nand we can estimate the standard deviation of the noise $\\sigma_j$ \nat scale $j$. These estimates can be naturally introduced in our \nmodels $m_j$\n\\begin{eqnarray}\nM_{j,k} = k_{m} \\sigma_j\n\\end{eqnarray}\n The model $M_j$ at scale $j$ represents \nthe value taken by a wavelet coefficient in the absence of any relevant\n signal and, in  practice, it must be a small value compared to \nany significant signal value.\nFollowing the Gull and Skilling procedure, we take $M_j$ as a fraction of the \nnoise because the value of \n$\\sigma_j$ can be considered as a sort of physical limit under which a signal \ncannot be distinguished from the noise ($k_m = \\frac{1}{100}$).\n\n\\subsection{Conclusion}\n\\label{sect_5pt}\n\nAs described above, many studies   \nhave been carried out in order to improve the functional to be minimized.\nBut the question which should be raised is: what is a good entropy for \nsignal restoration?\n\nTrying to answer, this corresponds to asking what is the information\nin the signal. We first assume that a signal $X$ can be decomposed in\nseveral components:\n\\begin{eqnarray}\n X = S + B + N\n\\end{eqnarray}\nwhere $S$ is the signal of interest, $B$ lis the background, and $N$  the noise.\n\nThe entropy should verify the following criteria \\cite{starck:sta98_2}:\n{\\bf\n\\begin{enumerate}\n\\item The information in a flat signal is zero ($S=0$, $N=0$ et $B=\\mathrm{Cst}$). \n\\item The amount of information in a signal is independent of the background\n($H(X)$ is independent of $B$).\n\\item The amount of information is dependent on the noise \n($H(X)$ is dependent of $N$). \nA given signal $X$ doesn't furnish the  same information if \nthe noise $N$ is high or small.\n\\item The entropy must work in the same way for a pixel which\nhas a value $B + \\epsilon$, and\nfor a pixel which has a value $B - \\epsilon$.\n$H(X)$ must be a function of the absolute value of $S$ instead of $S$.\n\\item The amount of information is dependent on the correlation in the signal.\nIf the signal $S$  presents large features above the noise, it contains\na lot of information. By generating a new set of  data from $S$, by \nrandomly taking the pixel values in $S$, the large features will\nevidently disappear, and this new signal will contain less information.\nBut the pixel values will be the same as in $S$.\n\\end{enumerate}\n}\n% \\begin{figure}[htb]\n% \\centerline{\n% \\hbox{\n% \\psfig{figure=lenna256.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}\n% \\psfig{figure=scrambled_lenna.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}\n% }}\n% \\caption{Lena image (left) and the same data distributed differently (right). \n% These\n% two images have the same entropy, using any of the standard entropy methods.}\n% \\label{fig_lenna}\n% \\end{figure}\n\\begin{figure}[h]\n\\centerline{\n\\vbox{\n\\hbox{\n\\psfig{figure=fig_saturn.ps,bbllx=1.7cm,bblly=12.9cm,bburx=11.2cm,bbury=25.6cm,width=9.cm,height=12.3cm,clip=}\n\\psfig{figure=fig_saturn_scramble.ps,bbllx=1.7cm,bblly=12.9cm,bburx=11.2cm,bbury=25.6cm,width=9.cm,height=12.3cm,clip=}\n% \\vspace{21cm}\n}\n}}\n\\caption{Saturn image (left) and the same data distributed differently (right). \r\nThese\ntwo images have the same entropy, using any of the standard entropy \ndefinitions.}\n\\label{fig_saturn}\n\\end{figure}\n \nFig.~\\ref{fig_saturn} illustrates the last point perfectly. \nThe second image is obtained  by distributing randomly the Saturn image pixel \nvalues, and the standard entropy definitions  produce the same information\nmeasurement for both images. The concept of information becomes really\nsubjective, or at least it depends on the application domain. Indeed, for \nsomeone who is\nnot involved in image processing, the second image contains \n{\\em less} information\nthan the first one. For someone working on image transmission, it is clear\nthat the second image will require more bits for lossless transmission,\nand from this point of view, he/she will consider that the second \nimage contains\n{\\em more} information. Finally, for data restoration, all fluctuations\ndue to noise are not of interest, and do not contain relevant \ninformation. From this physical point of view, \nthe standard  definition of entropy seems badly adapted to information \nmeasurement in signal restoration.\n\n% \\clearpage\n% \\newpage\n", "meta": {"hexsha": "99993669874f67f62545c19dcfbb2f008723b2c8", "size": 22616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/intro.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/intro.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/intro.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": 44.0, "max_line_length": 193, "alphanum_fraction": 0.7612752034, "num_tokens": 6125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6034141937418586}}
{"text": "\\documentclass[simplex.tex]{subfiles}\n% NO NEED TO INPUT PREAMBLES HERE\n% packages are inherited; you can compile this on its own\n\n\\begin{document}\n\\subsection{Law of Large Graphs}\nWe note that low-rank methods can often be more easily interpreted. Moreover, eigenmode is observed among the embedded latent positions, with respect to different lobes in particular. This suggests to use low-rank methods from another perspective. \nFor all the 70 different regions based on the Desikan atlas (35 for each hemisphere), each one is assigned to one of the 10 lobes (5 for each hemisphere), i.e. Frontal, Parietal, Occipital, Temporal, and other. And we do a permutation test as following.\n\n70 vertices are connected spatially as in the Desikan atlas. Let the adjacency matrix of these 70 vertices to be $A$. $A_{ij} = 1$ means vertex $i$ and vertex $j$ are spatially connected. We say vertex $j$ is a neighbor of vertex $i$ if $A_{ij} = 1$. We define $l_i$ be the lobe i.d. for vertex $i$.\n\nWe define a uniform $1$-flip to be:\n\\begin{itemize}\n\\item Select a pair of adjacent vertices (vertex $i_1$ and vertex $j_1$) across the boundary of lobes uniformly, i.e. $A_{i_1 j_1} = 1$ and $l(i_1) \\ne l(j_1)$;\n\\item Uniformly select another pair of adjacent vertices (vertex $i_2$ and vertex $j_2$ where $i_1 \\ne i_2$ and $j_1 \\ne j_2$) across the same boundary of lobes uniformly, i.e. $A_{i_2 j_2} = 1$ and $l(i_1) = l(i_2)$ and $l(j_1) = l(j_2)$;\n\\item Reassign vertex $j_1$ to lobe $l_{i_1}$ and reassign vertex $i_2$ to lobe $l_{j_2}$.\n\\end{itemize}\n\nBy the definition, after a uniform $1$-flip, the number of vertices in each lobe keeps the same, where only two vertices are changed to a different lobe.\n\nWe define a uniform $k$-flip to be:\n\\begin{itemize}\n\\item Sequentially run the uniform $1$-flip $k$ times.\n\\end{itemize}\n\nNote that after a uniform $k$-flip, the number of vertices in each lobe still keeps the same.\n\nLet $X = [X_1, \\cdots, X_n]^{\\top}$ be the latent positions, where $X_i$ is the latent position for vertex $i$ sampled from distribution $f$. Test statistic $T(X, l)$ is defined as:\n\\[\nT(X, l) = \\frac{\\sum_{i \\ne j, l(i) = l(j)} \\|X_i - X_j \\|_2}{\\sum_{i \\ne j, l(i) = l(j)} 1} -\n\\frac{\\sum_{i \\ne j, l(i) \\ne l(j)} \\|X_i - X_j \\|_2}{\\sum_{i \\ne j, l(i) \\ne l(j)} 1}\n\\]\n\n\n\n$H_0$: Differences between latent positions within lobes are the same compared to across lobes, i.e. $E_f[T(X, l)] = 0$.\n\n$H_A$: Differences between latent positions within lobes are smaller compared to across lobes, i.e. $E_f[T(X, l)] < 0$.\n\nWe ran 1000 simulations for each number of flips and plot the results for the permutation test as in Figure~\\ref{fig:violin}. The x-axis represents the different number of flips, while the y-axis represents the measure according to the lobe assignment, i.e. within lobes distances minus the across lobe distances. The dashed line is the baseline for the measure based on the true lobe assignment without any flipping. As the number of flips increases, we can see a clear evidence that $H_0$ is rejected with respect to $H_A$. Thus the embedded latent positions based on the low-rank method reflect the eigenmode with respect to different lobes.\n\n\\begin{figure}\t\n\\begin{cframed}\n\\centering\n\\includegraphics[height=.8\\linewidth]{../../figs/violinplot_new_flip_2norm_1_8.pdf}\n\\caption{\\textbf{Violin plot of the permutation test.} We ran 1000 simulations for each number of flips. The x-axis represents the different number of flips, while the y-axis represents the measure according to the lobe assignment, i.e. within lobes distances minus the across lobe distances. The dashed line is the baseline for the measure based on the true lobe assignment without any flipping. As the number of flips increases, we can see a clear evidence that $H_0$ is rejected with respect to $H_A$. Thus the embedded latent positions based on the low-rank method reflect the eigenmode with respect to different lobes.}\n\\label{fig:violin}\n\\end{cframed}\n\\end{figure}\n\n%\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "12c00733f31549bb901a953658d6ff74eb66a711", "size": 4006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Reporting/reports/2017-05/lawOfLargeGraphs.tex", "max_stars_repo_name": "openconnectome/SIMPLEX_Q2", "max_stars_repo_head_hexsha": "f10a6c4b9548670f9bf8e177914aa8d25fa1230b", "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": "Reporting/reports/2017-05/lawOfLargeGraphs.tex", "max_issues_repo_name": "openconnectome/SIMPLEX_Q2", "max_issues_repo_head_hexsha": "f10a6c4b9548670f9bf8e177914aa8d25fa1230b", "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": "Reporting/reports/2017-05/lawOfLargeGraphs.tex", "max_forks_repo_name": "openconnectome/SIMPLEX_Q2", "max_forks_repo_head_hexsha": "f10a6c4b9548670f9bf8e177914aa8d25fa1230b", "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": 74.1851851852, "max_line_length": 644, "alphanum_fraction": 0.7416375437, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6034141923920775}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrrppag}\n\\section*{\\hspace*{-1.6cm} tfrrppag}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nReassigned pseudo Page time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,rtfr,hat] = tfrrppag(x)\n[tfr,rtfr,hat] = tfrrppag(x,t)\n[tfr,rtfr,hat] = tfrrppag(x,t,N)\n[tfr,rtfr,hat] = tfrrppag(x,t,N,h)\n[tfr,rtfr,hat] = tfrrppag(x,t,N,h,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrrppag} computes the pseudo Page distribution and its\n        reassigned version. The reassigned pseudo Page distribution is\n        given by the following expressions\\,:\n\\begin{eqnarray*}\n\\hspace*{-.5cm}PP_x^{(r)}(t',\\nu';h)=\\iint_{-\\infty}^{+\\infty}\nPP_x(t,\\nu;h)\\ \\delta(t'-\\hat{t}(x;t,\\nu))\\\n\\delta(\\nu'-\\hat{\\nu}(x;t,\\nu))\\ dt\\ d\\nu,\n\\end{eqnarray*}\nwhere \n\\begin{eqnarray*}\n\\hat{t}(x;t,\\nu)=t\\ \\ \\mbox{ and }\\ \\ \n\\hat{\\nu}(x;t,\\nu)=\\nu+\\Im\\left\\{\\dfrac{F_x(t,\\nu;\\ens{D}_h)\\ F_x^*(t,\\nu;h)}\n{2\\pi|F_x(t,\\nu;h)|^2}\\right\\}.    \n\\end{eqnarray*}\n$\\ens{D}_h(t)=\\frac{dh}{dt}(t)$ and $F_x(t,\\nu;h)$ is the short-time\nFourier transform of $x(t)$ with a causal analysis window $h(t)$.\\\\\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)})\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty h}     & frequency smoothing window, {\\ty h(0)} being forced to {\\ty 1}\n                                         & {\\ty window(odd(N/4))}\\\\\n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr, rtfr} & time-frequency representation and its reassigned\n            version\\\\\n        {\\ty hat}   & complex matrix of the reassignment vectors\\\\ \n  \n\\hline\n\\end{tabular*}\n\\vspace*{.5cm}\n\nWhen called without output arguments, {\\ty tfrrpmh} runs {\\ty tfrqview}.\n\\end{minipage}\n\n%\\newpage\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,.1,.4);\n         h=window(65,'gauss'); \n         tfrrppag(sig,1:128,128,h,1);\n\\end{verbatim}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Reference}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] F. Auger, P. Flandrin ``Improving the Readability of Time-Frequency and\nTime-Scale Representations by the Reassignment Method'' IEEE Transactions\non Signal Processing, Vol. 43, No. 5, pp. 1068-89, 1995.\n\\end{minipage}\n\n", "meta": {"hexsha": "348ca0027461bbced3a5aa6737d7d90699552a55", "size": 3011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrrppag.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrrppag.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrrppag.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 29.8118811881, "max_line_length": 84, "alphanum_fraction": 0.6114247758, "num_tokens": 1114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301567, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6034141896925151}}
{"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\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 1 for Pattern Recognition}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 1}\n{\n    It is equivalent to prove $R^2 = r^2$ and to prove $$\\sum_1^n (\\bar{y} - \\hat{y}_i)^2 \\cdot \\sum_1^n (\\bar{x} - x_i)^2 = (\\sum_1^n (\\bar{x} - x_i)(\\bar{y} - y_i))^2,$$\n\n    With $\\hat{y}_i = b x_i + \\bar{y} - b \\bar{x}$, we have the left-hand side\n    $$\\sum_1^n (\\bar{y} - \\hat{y}_i)^2 \\cdot \\sum_1^n (\\bar{x} - x_i)^2 = b^2 \\cdot (\\sum_1^n (\\bar{x} - x_i)^2)^2.$$\n\n    Since the regression coefficient $$b = \\frac{\\sum_1^n (\\bar{x} - x_i)(\\bar{y} - y_i)}{\\sum_1^n (\\bar{x} - x_i)^2},$$ plug it in and we find the left-hand side equals the right-hand side. Thus, the equation above is proved.\n}\n\n\\section*{Question 2}\n{\n    \\subsection*{Case 1: $N=10$, $\\sigma = 0.5$}\n    {\n        Linear model: $$\\hat{y} = 5.9758 + 3.0841x ,\\quad R^2 = 0.9963$$\n        Quadratic model: $$\\hat{y} = 5.9826 + 3.0843x - 0.0047x^2 ,\\quad R^2 = 0.9963$$\n        Cubic model: $$\\hat{y} = 5.9864 + 2.9573x + 0.0045x^2 + 0.0356x^3 ,\\quad R^2 = 0.9965$$\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-linear-10-0.5.png}\n            \\caption{Linear}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-quadratic-10-0.5.png}\n            \\caption{Quadratic}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-cubic-10-0.5.png}\n            \\caption{Cubic}\n        \\end{figure}\n\n        Linear model (on testing set): $$\\mathrm{RSS} = 7.4800, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0018$$\n\n        Quadratic model (on testing set): $$\\mathrm{RSS} = 7.4650, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0017$$\n\n        Cubic model (on testing set): $$\\mathrm{RSS} = 7.2292, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0017$$\n    }\n\n    \\subsection*{Case 2: $N=100$, $\\sigma = 0.5$}\n    {\n        Linear model: $$\\hat{y} = 6.0152 + 2.9775x ,\\quad R^2 = 0.9939$$\n        Quadratic model: $$\\hat{y} = 6.0469 + 2.9708x - 0.0311x^2 ,\\quad R^2 = 0.9941$$\n        Cubic model: $$\\hat{y} = 6.0504 + 2.9986x - 0.0367x^2 - 0.0109x^3 ,\\quad R^2 = 0.9941$$\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-linear-100-0.5.png}\n            \\caption{Linear}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-quadratic-100-0.5.png}\n            \\caption{Quadratic}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-cubic-100-0.5.png}\n            \\caption{Cubic}\n        \\end{figure}\n\n        Linear model (on testing set): $$\\mathrm{RSS} = 6.6353, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0014$$\n\n        Quadratic model (on testing set): $$\\mathrm{RSS} = 6.5180, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0014$$\n\n        Cubic model (on testing set): $$\\mathrm{RSS} = 6.8288, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.0015$$\n    }\n\n    \\subsection*{Case 3: $N=10$, $\\sigma = 2$}\n    {\n        Linear model: $$\\hat{y} = 5.6122 + 4.3460x ,\\quad R^2 = 0.6779$$\n        Quadratic model: $$\\hat{y} = 5.7220 + 4.3487x - 0.0745x^2 ,\\quad R^2 = 0.6783$$\n        Cubic model: $$\\hat{y} = 5.7827 + 2.3172x + 0.0726x^2 + 0.5700x^3 ,\\quad R^2 = 0.6967$$\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-linear-10-2.0.png}\n            \\caption{Linear}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-quadratic-10-2.0.png}\n            \\caption{Quadratic}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-cubic-10-2.0.png}\n            \\caption{Cubic}     \n        \\end{figure}\n\n        Linear model (on testing set): $$\\mathrm{RSS} = 1914, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.3002$$\n\n        Quadratic model (on testing set): $$\\mathrm{RSS} = 1911, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.2996$$\n\n        Cubic model (on testing set): $$\\mathrm{RSS} = 1850, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.2901$$\n    }\n\n    \\subsection*{Case 4: $N=100$, $\\sigma = 2$}\n    {\n        Linear model: $$\\hat{y} = 6.2433 + 2.6398x ,\\quad R^2 = 0.3337$$\n        Quadratic model: $$\\hat{y} = 6.7499 + 2.5323x - 0.4973x^2 ,\\quad R^2 = 0.3527$$\n        Cubic model: $$\\hat{y} = 6.8062 + 2.9781x - 0.5878x^2 - 0.1743x^3 ,\\quad R^2 = 0.3560$$\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-linear-100-2.0.png}\n            \\caption{Linear}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-quadratic-100-2.0.png}\n            \\caption{Quadratic}\n        \\end{figure}\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{2-2-cubic-100-2.0.png}\n            \\caption{Cubic}\n        \\end{figure}\n\n        Linear model (on testing set): $$\\mathrm{RSS} = 1698, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.3049$$\n\n        Quadratic model (on testing set): $$\\mathrm{RSS} = 1668, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.2995$$\n\n        Cubic model (on testing set): $$\\mathrm{RSS} = 1748, \\quad \\mathrm{RSS}/\\mathrm{TSS} = 0.3138$$\n    }\n\n    \\subsection*{Conclusion}\n    {\n        \\begin{itemize}\n            \\item (\\emph{Complexity}) For $\\sigma = 0.5$ (small), the data have good linearity, and therefore, the quadratic and the cubic terms are close to 0, which means the linear model is adequate to explain the data. For $\\sigma = 2$ (large), however, the linear term has a small impact on the response, compared to the error term. In this circumstance, the quadratic and the cubic term is not neglegible. \n\n            \\item For the 4 linear models, we have the following two tables:\n\n            \\begin{table}[!hbp]\n                \\begin{tabular}{|c|c|c|}\n                \\hline\n                . & $N=10$ & $N=100$ \\\\\n                \\hline\n                $\\sigma=0.5$ & 0.9963 & 0.9939 \\\\\n                \\hline\n                $\\sigma=2$ & 0.6779 & 0.3337 \\\\\n                \\hline\n                \\end{tabular}\n                \\caption{$R^2$ on training set}\n            \\end{table}\n\n            \\begin{table}[!hbp]\n                \\begin{tabular}{|c|c|c|}\n                \\hline\n                . & $N=10$ & $N=100$ \\\\\n                \\hline\n                $\\sigma=0.5$ & 0.9982 & 0.9986 \\\\\n                \\hline\n                $\\sigma=2$ & 0.6998 & 0.6951 \\\\\n                \\hline\n                \\end{tabular}\n                \\caption{$R^2$ on testing set}\n            \\end{table}\n\n            We see the the $R^2$ on training set decreases dramatically with $N$ when $\\sigma$ is large. \n\n            \\item The training $R^2$ and the testing $R^2$ are different if they are based on different $N$s. Also, there is some stocasticity rooted in this experiment, which depends on the random seed.\n\n        \\end{itemize}\n    }\n}\n\n\\section*{Question 3}\n{\n    \\subsection*{Without interactive terms}\n    {\n        $$\\hat{y} = 726.0731 - 0.7537x_1 - 161.5401x_2 + 61.4084x_3, \\quad R^2 = 0.2304$$.\n        Plug in $x = (110, 3, 1)$, one has $$\\hat{y} = 219.9584$$.\n    }\n\n    \\subsection*{With interactive terms}\n    {\n        $$\\hat{y} = 1929.531 - 4.7578x_1 - 924.4123x_2 + 3.6749x_3 + 2.5331x_1 x_2 - 137.5951x_2 x_3 - 0.2866x_3 x_1, \\quad R^2 = 0.6050$$.\n        Plug in $x = (110, 3, 1)$, one has $$\\hat{y} = -607.9640$$.\n\n        What is unique about the interactive terms is that they give a much higher $R^2$, which seems to better the explainability of the model. But the prediction value is negative, and makes an outlier. This condraction is caused by the collinearity of the raw data.\n    }\n\n    \\subsection*{Alternative: Half interactive terms}\n    {\n        We propose an alternative method, in which we keep interactive terms except $x_1 x_2$. We find this trick works!\n\n        $$\\hat{y} = 669.9723 - 0.8563x_1 - 107.6020x_2 + 160.5363x_3 - 98.7687x_2 x_3 + 0.2065x_3 x_1, \\quad R^2 = 0.2437$$.\n        Plug in $x = (110, 3, 1)$, one has $$\\hat{y} = 139.9174$$.\n\n        In other words, we assume the the gene and the tumor size have no interactive effect. Under this assumption, we have a model with better $R^2$, and also give a reasonable prediction.\n    }\n}\n\n\\section*{Source Code}\n{\n    Please download the souece code from http://39.106.23.58/files/PR1\\_2015011506.7z\n}\n\n\\clearpage\n\\end{document}\n    ", "meta": {"hexsha": "2ec0717144cf39fed1de808a98e72d0dc5050ff9", "size": 9104, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW1/Homework1.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": "HW1/Homework1.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": "HW1/Homework1.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": 38.7404255319, "max_line_length": 412, "alphanum_fraction": 0.5638181019, "num_tokens": 3247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390162, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6034141877195957}}
{"text": "\\subsection{Conics}\\label{sec:Conics}\r\n\r\nIn this section we review equations of parabolas, circles, ellipses and hyperbolas.\r\nWe will give the equations of various conics in \\dfont{standard form} along with a sketch.\r\nA useful mnemonic is the following.\\\\\r\n\r\n\\begin{formulabox}[Mnemonic]\r\nIn each conic formula presented, the terms $\\,x-h\\,$ and $\\,y-k\\,$ will always appear. \r\nThe point $(h,k)$ will alway represent either the centre or vertex of the particular conic.\r\n\\end{formulabox}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%\\subsubsection{Parabolas, circles, ellipses and hyperbolas}\r\n\r\n\\bigskip\\noindent\r\n\\dfont{Vertical Parabola:} The equation of a vertical parabola is:\r\n$$y-k=a(x-h)^2$$\r\n$$\\includegraphics[width=85mm]{images/conics1}$$\r\n\\begin{multicols}{2}\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{vertex} of the parabola.\r\n\t\\item $a$ is the vertical \\ifont{stretch factor}. \r\n\t\\item If $a>0$, the parabola opens \\ifont{upward}.\r\n\t\\item If $a<0$, the parabola opens \\ifont{downward}.\r\n\\end{itemize}\r\n\\end{multicols}\r\n\r\n\\bigskip\\noindent\r\n\\dfont{Horizontal Parabola:} The equation of a horizontal parabola is:\r\n$$x-h=a(y-k)^2$$\r\n$$\\includegraphics[width=85mm]{images/conics2}$$\r\n\\begin{multicols}{2}\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{vertex} of the parabola.\r\n\t\\item $a$ is the horizontal \\ifont{stretch factor}. \r\n\t\\item If $a>0$, the parabola opens \\ifont{right}.\r\n\t\\item If $a<0$, the parabola opens \\ifont{left}.\r\n\\end{itemize}\r\n\\end{multicols} \r\n\r\n\\bigskip\\noindent\r\n\\dfont{Circle:} The equation of a circle is:\r\n$$(x-h)^2+(y-k)^2=r^2$$\r\n$$\\includegraphics[width=40mm]{images/conics3}$$\r\n\\begin{multicols}{2}\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{centre} of the circle.\r\n\t\\item  $r$ is the \\ifont{radius} of the circle.\r\n\\end{itemize}\r\n\\end{multicols}\r\n\r\n\\bigskip\\noindent\r\n\\dfont{Ellipse:} The equation of an ellipse is:\r\n$$\\frac{(x-h)^2}{a^2}+\\frac{(y-k)^2}{b^2}=1$$\r\n$$\\includegraphics[width=40mm]{images/conics4}$$\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{centre} of the ellipse.\r\n\t\\item $a$ is the \\ifont{horizontal distance} from the centre to the edge of the ellipse.\r\n\t\\item $b$ is the \\ifont{vertical distance} from the centre to the edge of the ellipse.\r\n\\end{itemize}\r\n\r\n\\bigskip\\noindent\r\n\\dfont{Horizontal Hyperbola:} The equation of a horizontal hyperbola is:\r\n$$\\frac{(x-h)^2}{a^2}-\\frac{(y-k)^2}{b^2}=1$$\r\n%$$\\includegraphics[width=40mm]{images/conics5}$$\r\n\\begin{multicols}{2}\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{centre} of the hyperbola.\r\n\t\\item $a,b$ are the \\ifont{reference box} values. The box has a centre of $(h,k)$.\r\n\t\\item $a$ is the \\ifont{horizontal distance} from the centre to the edge of the box.\r\n\t\\item $b$ is the \\ifont{vertical  distance} from the centre to the edge of the box.\r\n\\end{itemize}\r\n\\end{multicols}\r\nGiven the equation of a horizontal hyperbola, one may sketch it by first placing a dot at \r\nthe point $(h,k)$. Then draw a box around $(h,k)$ with horizontal distance $a$ and vertical distance $b$ to the edge of the box. Then draw dotted lines (called the \\dfont{asymptotes} of the hyperbola) through the corners of the box. Finally, sketch the hyperbola in a horizontal direction as illustrated below.\r\n$$\\includegraphics[width=150mm]{images/conics6}$$\r\n\r\n\\bigskip\\noindent\r\n\\dfont{Vertical Hyperbola:} The equation of a vertical hyperbola is:\r\n$$\\frac{(x-h)^2}{a^2}-\\frac{(y-k)^2}{b^2}=-1$$\r\n%$$\\includegraphics[width=40mm]{images/conics7}$$\r\n\\begin{multicols}{2}\r\n\\begin{itemize}\r\n\t\\item $(h,k)$ is the \\ifont{centre} of the hyperbola.\r\n\t\\item $a,b$ are the \\ifont{reference box} values. The box has a centre of $(h,k)$.\r\n\t\\item $a$ is the \\ifont{horizontal distance} from the centre to the edge of the box.\r\n\t\\item $b$ is the \\ifont{vertical  distance} from the centre to the edge of the box.\r\n\\end{itemize}\r\n\\end{multicols}\r\nGiven the equation of a vertical hyperbola, one may sketch it by following the same steps as with a horizontal hyperbola, but sketching the hyperbola going in a vertical direction.\r\n$$\\includegraphics[width=150mm]{images/conics8}$$\r\n\r\n\\begin{formulabox}[Determining the Type of Conic]\r\nAn equation of the form\r\n$$Ax^2+Bxy+Cy^2+Dx+Ey+F=0$$\r\ngives rise to a graph that can be generated by performing a conic section (parabolas, circles, ellipses, hyperbolas).\r\nNote that the $Bxy$ term involves conic rotation. The $Dx$, $Ex$, and $F$ terms affect the vertex and centre.\r\nFor simplicity, we will omit the $Bxy$ term.\r\nTo determine the type of graph we focus our analysis on the values of $A$ and $C$.\r\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\r\n\t\\item If $A=C$, the graph is a \\ifont{circle}.\r\n\t\\item If $AC>0$ (and $A\\neq C$), the graph is an \\ifont{ellipse}.\r\n\t\\item If $AC=0$, the graph is a \\ifont{parabola}.\r\n\t\\item If $AC<0$, the graph is a \\ifont{hyperbola}.\r\n\\end{itemize}\r\n\\end{formulabox}\r\n\r\n%\\subsubsection{Completing the square}\r\n%The technique of \\dfont{completing the square} allows us to determine the center of a circle/ellipse or the vertex of a parabola.\r\n%It is also an important technique used for other purposes (for example, to derive the quadratic formula you can start by completing the square in $ax^2+bx+c=0$, $a\\neq 0$).\r\n%\r\n%The main idea behind completing the square is to turn:\r\n%$$ ax^2 + bx + c$$\r\n%into\r\n%$$a(x - h)^2 + k.$$\r\n%One way to complete the square is to use the following formula:\r\n%$$ax^2+bx+c=a\\left(x+\\frac{b}{2a}\\right)^2-\\frac{b^2}{4a^2}+c.$$\r\n%But this formula is a bit complicated, so some students prefer following the steps outlined in the next example.\r\n%\r\n%\\begin{example}{Completing the Square}{CompletingSquare}\r\n%Solve $2x^2+12x-32=0$ by completing the square.\r\n%\\end{example}\r\n%\r\n%\\begin{solution}\r\n%In this instance, we will \\ifont{not} divide by $2$ first (usually you would) in order to demonstrate what you should do when the `$a$' value is not $1$.\r\n%\r\n%\\bigskip\r\n%\r\n%\\begin{tabular}{rl}\r\n%$2x^2+12x-32=0$ & Start with original equation.\\\\\r\n%\\\\\r\n%$2x^2+12x=32$ & Move the number over to the other side.\\\\\r\n%\\\\\r\n%$2(x^2+6x)=32$ & Factor out the $a$ from the $ax^2+bx$ expression.\\\\\r\n%\\\\\r\n%$6~~\\to~~\\frac{6}{2}=3~~\\to~~3^2=\\dfont{9}$ & Take the number in front of $x$, \\\\\r\n%\t&  \\dfont{divide by $2$}, \\\\\r\n%\t&  then \\dfont{square} it.\\\\\r\n%\\\\\r\n%$\\ifont{2}(x^2+6x+\\dfont{9})=32+\\ifont{2}\\cdot\\dfont{9}$ & Add the result to both sides, \\\\\r\n%\t&  taking $a=2$ into account.\\\\\r\n%\\\\\r\n%$2(x+3)^2=50$ & Factor the resulting perfect square trinomial.\\\\\r\n%\\\\\r\n%~ & \\ifont{You have now completed the square!}\\\\\r\n%\\\\\r\n%$(x+3)^2=25~~\\to~~x=2 \\mbox{ or } x=-8$ & To solve for $x$, simply divide by $a=2$ \\\\\r\n%\t& and take square roots.\\\\\r\n%\\end{tabular}\r\n%\\end{solution}\r\n\r\n\\begin{example}{Center and Radius of a Circle}{CenterRadius}\r\nFind the centre and radius of the circle $y^2 + x^2 - 12x + 8y + 43 = 0$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe need to complete the square twice, once for the $x$ terms and once for the $y$ terms.\r\nWe'll do both at the same time.\r\nFirst let's collect the terms with $x$ together, the terms with $y$ together, and move the number to the other side.\r\n%$$y^2 + x^2 - 12x + 8y + 43 = 0$$\r\n$$(x^2-12x)+(y^2+8y)=-43$$\r\nWe add $36$ to both sides for the $x$ term ($-12\\to \\frac{-12}{2}=-6\\to (-6)^2=36$), and $16$ to both sides for the $y$ term ($8\\to \\frac{8}{2}=4\\to (4)^2=16$):\r\n$$(x^2-12x+36)+(y^2+8y+16)=-43+36+16$$\r\nFactoring gives:\r\n$$(x-6)^2+(y+4)^2=3^2.$$\r\nTherefore, the centre of the circle is $(6,-4)$ and the radius is $3$.\r\n\\end{solution} \r\n\r\n\\begin{example}{Type of Conic}{TypeConic}\r\nWhat type of conic is $4x^2-y^2-8x+8=0$?\r\nPut it in standard form.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nHere we have $A=4$ and $C=-1$.\r\nSince $AC<0$, the conic is a hyperbola.\r\nLet us complete the square for the $x$ and $y$ terms.\r\nFirst let's collect the terms with $x$ together, the terms with $y$ together, and move the number to the other side.\r\n$$(4x^2-8x)-y^2=-8$$\r\nNow we factor out $4$ from the $x$ terms.\r\n$$4(x^2-2x)-y^2=-8$$\r\nNotice that we don't need to complete the square for the $y$ terms (it is already completed!). To complete the square for the $x$ terms we add \\dfont{1} ($-2\\to\\frac{-2}{2}=-1\\to(-1)^2=1$), taking into consideration that the $a$ value is $4$:\r\n$$\\ifont{4}(x^2-2x+\\dfont{1})-y^2=-8+\\ifont{4}\\cdot\\dfont{1}$$\r\nFactoring gives:\r\n$$4(x-1)^2-y^2=-4$$\r\nA hyperbola in standard form has $\\pm1$ on the right side and a positive $x^2$ on the left side, thus, we must divide by $4$:\r\n$$(x-1)^2-\\frac{y^2}{4}=-1$$\r\nNow we can see that the equation represents a vertical hyperbola with centre $(1,0)$ (and with $a$ value $\\sqrt{1}=1$, and $b$ value $\\sqrt{4}=2$).\r\n\\end{solution} \r\n\r\n\r\n\r\n\r\n\\begin{example}{Equation of Parabola}{EquationParabola}\\label{EquationParabola}\r\nFind an equation of the parabola with vertex $(1,-1)$ that passes through the points $(-4, 24)$ and $(7, 35)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe first need to determine if it is a vertical parabola or horizontal parabola.\r\nSee figure \\ref{fig:EquationParabola} for a sketch of the three points $(1,-1)$, $(-4, 24)$ and $(7, 35)$ in the $xy$-plane.\r\n\\figure[!ht]\r\n$$\\includegraphics[width=60mm]{images/conics9}$$\r\n\\caption{Figure for Example \\ref{EquationParabola}\\label{fig:EquationParabola}}\r\n\\endfigure\r\nNote that the vertex is $(1,-1)$.\r\nGiven the location of the vertex, the parabola cannot open downwards.\r\nIt also cannot open left or right (because the vertex is between the other two points - if it were to open to the right, every other point would need to be to the right of the vertex; if it were to open to the left, every other point would need to be to the left of the vertex).\r\nTherefore, the parabola must open upwards and it is a vertical parabola.\r\nIt has an equation of\r\n$$y-k=a(x-h)^2.$$\r\n\\begin{multicols}{2}\r\nAs the vertex is $(h,k)=(1,-1)$ we have:\r\n$$y-(-1)=a(x-1)^2$$\r\nTo determine $a$, we substitute one of the points into the equation and solve.\r\nLet us substitute the point $(x,y)=(-4,24)$ into the equation:\\\\\r\n$$\\begin{array}{rcl}\r\n24-(-1) & = & a(-4-1)^2 \\\\\r\n25 & = & 25a \\\\\r\na & = & 1\r\n\\end{array}$$\r\n\r\nTherefore, the equation of the parabola is:\r\n$$y+1=(x-1)^2.$$\r\nNote that if we substituted $(7,35)$ into the equation instead, we would also get $a=1$.\r\n\r\n$$\\includegraphics[scale=0.4]{images/ExQuadratic}$$\r\n\\end{multicols}\r\n\r\n\\end{solution}\r\n\r\n\r\n", "meta": {"hexsha": "95a566142fd29d60db107ef0a3d1d8b42e1ecdb6", "size": 10318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-2-3-conics.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-3-conics.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-3-conics.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.474137931, "max_line_length": 311, "alphanum_fraction": 0.6733863152, "num_tokens": 3486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6034141857466758}}
{"text": "\\documentclass[12pt,english]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{mathtools}\n\\usepackage{relsize} % make some math large\n\\usepackage{bm} % make some math bold\n\\usepackage{bbm}\n% url package\n\n\\usepackage{hyperref}\n\\hypersetup{\n    colorlinks=true,\n    linkcolor=blue,\n    filecolor=magenta,\n    urlcolor=cyan,\n}\n\n% Titling and Author\n\\title{Latex Example, Multiple Lines Equations}\n\\author{\\href{https://fanwangecon.github.io/}{Fan Wang}\\thanks{https://fanwangecon.github.io, repository: \\href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Indicator Function}\n\\begin{align}\\label{eq:indi}\n  \\begin{gathered}\n    \\mathbbm{1}\\left\\{1 + 2 +3\\right\\}\n    \\\\\n    \\mathlarger{\\mathlarger{\\mathlarger{\n      \\mathbbm{1}\n    }}}\n    \\left\\{\n      \\begin{array}{cc}\n          1 + 2 + 3\\\\\n          + 4 + 5\\\\\n          > 0\\\\\n      \\end{array}\n    \\right\\}\n    \\\\\n    \\mathlarger{\\mathlarger{\\mathlarger{\n    \\mathlarger{\\mathlarger{\\mathlarger{\n      \\mathbbm{1}\n    }}}}}}\n    \\left\\{\n      \\begin{array}{cc}\n          1 + 2 + 3\\\\\n          + 4 + 5 + 6 \\\\\n          + 7 + 8 + 9 \\\\\n          > 0\\\\\n      \\end{array}\n    \\right\\}\n  \\end{gathered}\n\\end{align}\n\n\n\\section{Multiple Lines of Equation}\n\nBelow, I demonstrate several possible ways of aligning and labeling four lines of equations. First, I label some of the four lines with own labels and align by equality sign. Second, we align by the equality sign but use one single label for all lines of equations. Third, we center align on page label each line using gather. Fourth, we center align on page with one label putting gather inside align.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% A.1 Align and Split\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\pagebreak\n\\subsection{Align and Split}\n\\subsubsection{Align and Label Lines}\n\\begin{verbatim}\n  \\begin{align}\n    x_1  =& 1        \\label{eq:lineone}\\\\\n    x_2  =& 1        \\nonumber\\\\\n    h(x) =& f(-20 + 15 + 17) \\label{eq:linethree}\\\\\n    h(x) =& f(12) \\approx 1  \\label{eq:linefour}\n  \\end{align}\n\\end{verbatim}\n\\begin{align}\n  x_1  =& 1        \\label{eq:lineone}\\\\\n  x_2  =& 1        \\nonumber\\\\\n  h(x) =& f(-20 + 15 + 17) \\label{eq:linethree}\\\\\n  h(x) =& f(12) \\approx 1  \\label{eq:linefour}\n\\end{align}\n\\subsubsection{Align Split One Label}\n\\begin{verbatim}\n\\begin{align}\\label{eq:split}\n  \\begin{split}\n    x_1 &= 1 \\\\\n    y &= 1        \\\\\n    h(x) &= f(-20 + 10 + 20) \\\\\n    g(x) &= f(12) \\approx 2\n  \\end{split}\n\\end{align}\n\\end{verbatim}\n\\begin{align}\\label{eq:split}\n  \\begin{split}\n    x_1 &= 1 \\\\\n    y &= 1        \\\\\n    h(x) &= f(-20 + 10 + 20) \\\\\n    g(x) &= f(12) \\approx 2\n  \\end{split}\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% A.2 Align and Gather\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\pagebreak\n\\subsection{Align and Gather}\n\\subsubsection{Gather and Label Lines}\n\\begin{verbatim}\n  \\begin{gather}\n    x_1  = 1        \\label{eq:lineone}\\\\\n    x_2  = 1        \\nonumber\\\\\n    h(x) = f(-20 + 15 + 17) \\label{eq:linethree}\\\\\n    h(x) = f(12) \\approx 1  \\label{eq:linefour}\n\\end{gather}\n\\end{verbatim}\n\\begin{gather}\n  x_1  = 1        \\label{eq:lineone}\\\\\n  x_2  = 1        \\nonumber\\\\\n  h(x) = f(-20 + 15 + 17) \\label{eq:linethree}\\\\\n  h(x) = f(12) \\approx 1  \\label{eq:linefour}\n\\end{gather}\n\\subsubsection{Align Gathered}\n\\begin{verbatim}\n  \\label{eq:gathered}\n  \\begin{gathered}\n    x_1 = 1       \\\\\n    x_2 = 1        \\\\\n    h(x) = f(-20 + 15 + 17) \\\\\n    h(x) = f(12) \\approx 1\n  \\end{gathered}\n\\end{verbatim}\n\\begin{align}\n  \\label{eq:gathered}\n  \\begin{gathered}\n    x_1 = 1       \\\\\n    x_2 = 1        \\\\\n    h(x) = f(-20 + 15 + 17) \\\\\n    h(x) = f(12) \\approx 1\n  \\end{gathered}\n\\end{align}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%% B. Substack vs Array\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\pagebreak\n\\section{Substack vs Array}\n\\begin{verbatim}\n\\begin{align}\n    \\begin{split}\n    \\label{eq:Value}\n    v_{ih}\\left(a,z\\right)\n        =\n        \\max_{\n            \\substack{\n                c>0\\\\\n                a' \\in \\{0,[\\bar{A}_{ih},\\infty)\\}\n                }\n            }\n        u\\left(c\\right)+  \\beta \\int v_{ih}\\left(a',z'\\right)f(z'|z)dz'\\\\\n    \\label{eq:Value}\n    v_{ih}\\left(a,z\\right)\n        =\n        \\max_{\n            \\begin{array}{cc}\n                c>0\\\\\n                a' \\in \\{0,[\\bar{A}_{ih},\\infty)\\}\\\\\n            \\end{array}\n            }\n        u\\left(c\\right)+  \\beta \\int v_{ih}\\left(a',z'\\right)f(z'|z)dz'\\\\\n    \\end{split}\n\\end{align}\n\\end{verbatim}\n\nUsing Substack, fonts are small under max:\n\\begin{align}\n    \\begin{split}\n        \\label{eq:Value}\n        v_{ih}\\left(a,z\\right)\n        =\n        \\max_{\n            \\substack{\n                c>0\\\\\n                a' \\in \\{0,[\\bar{A}_{ih},\\infty)\\}\n                }\n            }\n        u\\left(c\\right)+  \\beta \\int v_{ih}\\left(a',z'\\right)f(z'|z)dz'\\\\\n    \\end{split}\n\\end{align}\n\nUsing Array, fonts are larger under max:\n\\begin{align}\n    \\begin{split}\n        \\label{eq:Value}\n        v_{ih}\\left(a,z\\right)\n        =\n        \\max_{\n            \\begin{array}{cc}\n                c>0\\\\\n                a' \\in \\{0,[\\bar{A}_{ih},\\infty)\\}\\\\\n            \\end{array}\n            }\n        u\\left(c\\right)+  \\beta \\int v_{ih}\\left(a',z'\\right)f(z'|z)dz'\\\\\n    \\end{split}\n\\end{align}\n\n\\pagebreak\n\n\\section{Multiple Lines}\n\n\\begin{verbatim}\n\\begin{align}\n    x = y + z +\n    \\left\\{\n      \\begin{array}{l}\n            a \\\\\n            + b \\\\\n            + c \\\\\n            + d \\\\\n      \\end{array}\n    \\right\\}\n\\end{align}\n\\end{verbatim}\n\n\\begin{align}\n    x = y + z +\n    \\left\\{\n      \\begin{array}{l}\n            a \\\\\n            + b \\\\\n            + c \\\\\n            + d \\\\\n      \\end{array}\n    \\right\\}\n\\end{align}\n\n\\section{Brackets}\n\nThen in your document:\n\n\\[\n\\left(\\rule{0cm}{2cm}\n \\frac{\\prod_0^\\infty k}{\\sum_0^\\infty n}\n\\right)\n\\]\n\n\\end{document}\n", "meta": {"hexsha": "e5f99fc7cd40f99788b73083f3216444b039b155", "size": 5954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_other/equation/multilines.tex", "max_stars_repo_name": "guohui-jiang/Tex4Econ", "max_stars_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_other/equation/multilines.tex", "max_issues_repo_name": "guohui-jiang/Tex4Econ", "max_issues_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_other/equation/multilines.tex", "max_forks_repo_name": "guohui-jiang/Tex4Econ", "max_forks_repo_head_hexsha": "7bdbfb29e956d31239bd592b6392574e4aec5c15", "max_forks_repo_licenses": ["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.0080645161, "max_line_length": 402, "alphanum_fraction": 0.5067181727, "num_tokens": 2009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390164, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6034141827355446}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Symmetry of the Ricci tensor}\n\nThis simple example shows that, for the metric connection, the Ricci tensor is symmetric, that is $R_{ab} = R_{ba}$.\n\n\\vspace{15pt}\n\n\\begin{cadabra}\n   {a,b,c,d,e,f,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices(position=independent).\n\n   \\partial{#}::PartialDerivative;\n\n   g_{a b}::Symmetric;\n   g^{a b}::Symmetric;\n\n   g_{a b}::Depends(\\partial{#});\n   g^{a b}::Depends(\\partial{#});\n\n   dgab := \\partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \\partial_{c}{g_{e f}}. # cdb (dgab,dgab)\n\n   Gamma := \\Gamma^{a}_{b c} ->\n            (1/2) g^{a e} (   \\partial_{b}{g_{e c}}\n                            + \\partial_{c}{g_{b e}}\n                            - \\partial_{e}{g_{b c}}).     # cdb (Chr,Gamma)\n\n   Rabcd := R^{a}_{b c d} ->\n           \\partial_{c}{\\Gamma^{a}_{b d}} + \\Gamma^{a}_{e c} \\Gamma^{e}_{b d}\n         - \\partial_{d}{\\Gamma^{a}_{b c}} - \\Gamma^{a}_{e d} \\Gamma^{e}_{b c}.\n                                                          # cdb (Rabcd,Rabcd)\n\n   Rab := R_{a b} -> R^{c}_{a c b}.                       # cdb (Rab,Rab)\n\n   eqn := 2 (R_{a b} - R_{b a}).\n\n   substitute (eqn, Rab)\n   substitute (eqn, Rabcd)\n   substitute (eqn, Gamma)\n\n   distribute   (eqn)\n   product_rule (eqn)\n   canonicalise (eqn)                                     # cdb (final1,eqn)\n\n   substitute   (eqn,dgab)\n   canonicalise (eqn)                                     # cdb (final2,eqn)\n\\end{cadabra}\n\n\\subsection*{Symmetry of the Ricci tensor}\n\n\\begin{minipage}[t]{0.60\\textwidth}\n\\begin{align*}\n   g^{a b}{}_{,c}   &:=\\cdb{dgab}\\\\\n   \\Gamma^{a}_{bc}  &:=\\cdb{Chr}\\\\\n   R^a{}_{bcd}      &:=\\cdb{Rabcd}\\\\\n   R_{ab}           &:=\\cdb{Rab}\\\\[10pt]\n   2(R_{ab}-R_{ba}) &= \\cdb{final1}\\\\\n                    &= \\cdb{final2}\n\\end{align*}\n\\end{minipage}\n\\hskip 1cm\n\\lower16pt\\hbox{%\n\\begin{minipage}[t]{0.40\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      g^{a b}{}_{,c}   &:=\\cdb{dgab}\\\\\n      \\Gamma^{a}_{bc}  &:=\\cdb{Chr}\\\\\n      R^a{}_{bcd}      &:=\\cdb{Rabcd}\\\\\n      R_{ab}           &:=\\cdb{Rab}\\\\[10pt]\n      2(R_{ab}-R_{ba}) &= \\cdb{final1}\\\\\n                       &= \\cdb{final2}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "7d3d2fca5f44ea57f25b77f7f9911089c658b0b8", "size": 2239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cadabra/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": "cadabra/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": "cadabra/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": 28.3417721519, "max_line_length": 116, "alphanum_fraction": 0.4863778473, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6034141764017121}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Tri-Nilplex Numbers}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn exo-3 real number has the form\n\\begin{equation}\n    a_{0} + a_{1} W + a_{2} X + a_{3} WX + a_{4} Y + a_{5} WY + a_{6} XY + a_{7} WXY\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the exo-2 reals.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "0ab66be46d25a53b724b4432fb8a7dfec1dc6093", "size": 2142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/K.tex", "max_stars_repo_name": "meirizarrygelpi/plexifications", "max_stars_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_stars_repo_licenses": ["MIT"], "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/K.tex", "max_issues_repo_name": "meirizarrygelpi/plexifications", "max_issues_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_issues_repo_licenses": ["MIT"], "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/K.tex", "max_forks_repo_name": "meirizarrygelpi/plexifications", "max_forks_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_forks_repo_licenses": ["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.6818181818, "max_line_length": 84, "alphanum_fraction": 0.2016806723, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.6688802735722128, "lm_q1q2_score": 0.6032769435673934}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% shortestpath.tex last revised 29 Jan 2014 by Stuart Ambler.\n% Explanation of correctness of bidirectional breadth first search algorithm for\n% finding a shortest path between two nodes in an unweighted undirected graph.\n% Copyright (c) 2014 Stuart Ambler.\n% Permission is granted to copy, distribute and/or modify this document\n% under the terms of the GNU Free Documentation License, Version 1.3\n% or any later version published by the Free Software Foundation;\n% with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.\n% A copy of the license is included in the section entitled \"GNU\n% Free Documentation License\".\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\documentclass{article}\n\\usepackage{amsmath,amsfonts,amssymb,amsthm,amsxtra,url}\n\n% Part of GNU FDL LaTeX code (rest in section GNU Free Documentation License)\n% Some lines commented out, marked with added trailing comment SA.\n% This is set up to run with pdflatex.\n%---------The file header---------------------------------------------\n%\\documentclass[a4paper,12pt]{book}  % SA\n\n\\usepackage[english]{babel} %language selection\n\\selectlanguage{english}\n\n\\pagenumbering{arabic}\n\n\\usepackage{hyperref}\n\\hypersetup{colorlinks, \n           citecolor=black,\n           filecolor=black,\n           linkcolor=black,\n           urlcolor=black,\n           bookmarksopen=true,\n           pdftex}\n\n\\hfuzz = .6pt % avoid black boxes\n           \n%\\begin{document}  % SA\n%---------------------------------------------------------------------\n\\begin{document}\n\n\\title{Why the Bidirectional Breadth First Search Algorithm Finds a Shortest Path}\n\\author{Stuart Ambler}\n\\maketitle\n\nSuppose you have an unweighted undirected graph, given for every node $x$ of the graph the set $E_x$ of nodes on edges meeting $x$ (i.e. $E_x$ is the edgelist of $x$), and want a shortest path between two nodes $a$ and $b$.\n\nA \\textbf{unidirectional breadth first search} starting from $a$ will find one.  Let $A_0 = \\{ a \\}$, and for $k > 0$, $A_k = (\\cup_{x \\in A_{k-1}} E_x) \\setminus \\cup_{0 \\le j < k} A_j$ (all the nodes in all the edgelists of all the nodes in $A_{k-1}$, but removing nodes in all previous $A_j$).  Define $d(x,a)$ as the distance from $x$ to $a$, the length of the shortest path from $x$ to $a$.  This is a metric, in particular for any $x, y, z$, $d(x,y) = 0 \\Leftrightarrow x = y$ and $d(x,z) \\le d(x,y) + d(y,z)$.  The latter is true because you can make a path from $x$ to $z$ by concatenating shortest paths from $x$ to $y$ and $y$ to $z$, though this concatenation may not be the shortest path from $x$ to $z$.\n\nClaim: $A_k = \\{ x | d(x, a) = k \\}$.  If $d(a,x) = k$, then $x \\in A_k$ because there is a path of length $k$ from $a$, and no shorter path (which would cause $x \\in A_j$ for some $j < k$).\n\nOn the other hand, if $x \\in A_k$, there is a path of length $k$ from $a$ to $x$, so $d(a,x) \\le k$.  It's not possible that $d(a,x) = j < k$, because if it were, then $x \\in A_j$ and thus not in $A_k$.  Thus $d(a,x) = k$.\n\nA breadth first search for $b$ starting from $a$, implemented as in bfs1.py, in effect creates the sets $A_j$ for $j < k = d(a,b)$, and some part of $A_k$ until it encounters $b$ in that set.  This is because nodes are added to the queue from edgelists of nodes popped off the queue (which is initialized with $a$ and is FIFO), but only if they have not been previously encountered.  The code implicitly shifts from $A_j$ to $A_{j+1}$ when all the edgelists of nodes belonging to $A_{j-1}$ have been processed.\n\nFor every node in $A_j$ added to the queue, the code keeps track of which node in $A_{j-1}$ owned the edgelist on which it was first encountered.  A shortest path from $a$ to $b$ is then built by reversing what is obtained by following these parent relationships backwards.\n\nA \\textbf{bidirectional breadth first search} can be faster, due to the potentially exponential fan-out of breadth first search.  Define the $A_k$ as before, and the $B_k$ similarly starting from $B_0 = \\{ b \\}$.  Supposing that we start from the one end with $A_0$, from the other with $B_0$, that some choice is made at each iteration whether to move from $A_r$ to $A_{r+1}$ or $B_s$ to $B_{s+1}$, and that we stop when $A_r \\cap B_s \\ne \\emptyset$ for the first time.  From the two paths from the ends we get a path between the endpoints $a$ and $b$ of length $r+s$.  In fact, there is no shorter path.  To see this, use the fact that if the equations below for $A_0$ through $A_k$ hold, then the logical equivalence for $A_{k+1}$ holds.\n\\begin{align}\n&\\text{If}  \\notag \\\\\nA_0 \\cap B_0 &= \\emptyset \\notag \\\\\nA_1 \\cap B_0 &= \\emptyset \\notag \\\\\n&\\cdots \\notag \\\\\nA_k \\cap B_0 &= \\emptyset \\notag \\\\\n&\\text{then}  \\notag \\\\\nA_{k+1} \\cap B_0 &= \\emptyset \\Leftrightarrow A_r \\cap B_s = \\emptyset, \\notag \n\\end{align}\nfor any nonnegative $r, s$ with $r + s = k + 1$.\n\nThis can be seen as follows. If $A_{k+1} \\cap B_0 \\ne \\emptyset$, then recalling the properties of unidirectional breadth first search from $a$, there is a shortest path of length $k+1$ from $a$ to $b$.  This can be split into two pieces of lengths $r$ and $s$, reversing one of them, that are shortest paths of those lengths from $a$ to some $x$ and from $b$ to $x$, so that $x \\in A_r \\cap B_s$, which is thus nonempty.  Conversely, if there is an $x \\in A_r \\cap B_s$, by concatenating paths, one of them reversed, we get a path of length $r+s = k+1$ from $a$ to $b$, so that $d(a,b) \\le k+1$.  But $d(a,b) \\le k$ is false because of all the intersections empty by hypothesis.  Thus $d(a,b) = k+1$, and thus $A_{k+1} \\cap B_0 \\ne \\emptyset$.\n\nThen, to see that the path we construct that meets at a point in the first nonempty $A_r \\cap B_s$ is a shortest path from $a$ to $b$, if $A_0 \\cap B_0 \\ne \\emptyset$, then $a=b$ and the path is of length $0$.  Otherwise, use the above fact repeatedly, noting that we have some sequence of $A_{r_i} \\cap B_{s_i} = \\emptyset$, $r_i + s_i = k_i = 1,2,\\dots,r+s-1$, implying $A_{k_i} \\cap B_0 = \\emptyset$ until finally we arrive at $A_r \\cap B_s \\ne \\emptyset \\Rightarrow A_{r+s} \\cap B_0 \\ne \\emptyset \\Rightarrow d(a,b) = r+s$.\n\nThe code in bfs2.py works with the $A_{r_i}$ and $B_{s_i}$ fairly explicitly, using the lists r\\_level\\_nodes and t\\_level\\_nodes for them (r for root or $a$, t for target or $b$).  It processes a whole level, or one of these sets, at a time, before going on to the next.  It finds a nonempty intersection of the two by finding a newly encountered node in the one that it's building, that is in the other that it's already built, and stops when this first happens.\n\n\\bigskip\n\\begin{quote}\n    Copyright \\copyright{} 2014 Stuart Ambler.\n    Permission is granted to copy, distribute and/or modify this document\n    under the terms of the GNU Free Documentation License, Version 1.3\n    or any later version published by the Free Software Foundation;\n    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.\n    A copy of the license is included in the section entitled ``GNU\n    Free Documentation License''.\n\\end{quote}\n\\bigskip\n    \n\\pagebreak\n\\section{GNU Free Documentation License}\n%\\chapter*{\\rlap{GNU Free Documentation License}}  % SA\n\\phantomsection  % so hyperref creates bookmarks\n\\addcontentsline{toc}{chapter}{GNU Free Documentation License}\n%\\label{label_fdl}\n\n \\begin{center}\n\n       Version 1.3, 3 November 2008\n\n\n Copyright \\copyright{} 2000, 2001, 2002, 2007, 2008  Free Software Foundation, Inc.\n \n \\bigskip\n \n%     \\texttt{<http://fsf.org/>}  % SA\n     \\url{http://fsf.org/}\n  \n \\bigskip\n \n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\\end{center}\n\n\n\\begin{center}\n{\\bf\\large Preamble}\n\\end{center}\n\nThe purpose of this License is to make a manual, textbook, or other\nfunctional and useful document ``free'' in the sense of freedom: to\nassure everyone the effective freedom to copy and redistribute it,\nwith or without modifying it, either commercially or noncommercially.\nSecondarily, this License preserves for the author and publisher a way\nto get credit for their work, while not being considered responsible\nfor modifications made by others.\n\nThis License is a kind of ``copyleft'', which means that derivative\nworks of the document must themselves be free in the same sense.  It\ncomplements the GNU General Public License, which is a copyleft\nlicense designed for free software.\n\nWe have designed this License in order to use it for manuals for free\nsoftware, because free software needs free documentation: a free\nprogram should come with manuals providing the same freedoms that the\nsoftware does.  But this License is not limited to software manuals;\nit can be used for any textual work, regardless of subject matter or\nwhether it is published as a printed book.  We recommend this License\nprincipally for works whose purpose is instruction or reference.\n\n\n\\begin{center}\n{\\Large\\bf 1. APPLICABILITY AND DEFINITIONS\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{1. APPLICABILITY AND DEFINITIONS}\n\\end{center}\n\nThis License applies to any manual or other work, in any medium, that\ncontains a notice placed by the copyright holder saying it can be\ndistributed under the terms of this License.  Such a notice grants a\nworld-wide, royalty-free license, unlimited in duration, to use that\nwork under the conditions stated herein.  The ``\\textbf{Document}'', below,\nrefers to any such manual or work.  Any member of the public is a\nlicensee, and is addressed as ``\\textbf{you}''.  You accept the license if you\ncopy, modify or distribute the work in a way requiring permission\nunder copyright law.\n\nA ``\\textbf{Modified Version}'' of the Document means any work containing the\nDocument or a portion of it, either copied verbatim, or with\nmodifications and/or translated into another language.\n\nA ``\\textbf{Secondary Section}'' is a named appendix or a front-matter section of\nthe Document that deals exclusively with the relationship of the\npublishers or authors of the Document to the Document's overall subject\n(or to related matters) and contains nothing that could fall directly\nwithin that overall subject.  (Thus, if the Document is in part a\ntextbook of mathematics, a Secondary Section may not explain any\nmathematics.)  The relationship could be a matter of historical\nconnection with the subject or with related matters, or of legal,\ncommercial, philosophical, ethical or political position regarding\nthem.\n\nThe ``\\textbf{Invariant Sections}'' are certain Secondary Sections whose titles\nare designated, as being those of Invariant Sections, in the notice\nthat says that the Document is released under this License.  If a\nsection does not fit the above definition of Secondary then it is not\nallowed to be designated as Invariant.  The Document may contain zero\nInvariant Sections.  If the Document does not identify any Invariant\nSections then there are none.\n\nThe ``\\textbf{Cover Texts}'' are certain short passages of text that are listed,\nas Front-Cover Texts or Back-Cover Texts, in the notice that says that\nthe Document is released under this License.  A Front-Cover Text may\nbe at most 5 words, and a Back-Cover Text may be at most 25 words.\n\nA ``\\textbf{Transparent}'' copy of the Document means a machine-readable copy,\nrepresented in a format whose specification is available to the\ngeneral public, that is suitable for revising the document\nstraightforwardly with generic text editors or (for images composed of\npixels) generic paint programs or (for drawings) some widely available\ndrawing editor, and that is suitable for input to text formatters or\nfor automatic translation to a variety of formats suitable for input\nto text formatters.  A copy made in an otherwise Transparent file\nformat whose markup, or absence of markup, has been arranged to thwart\nor discourage subsequent modification by readers is not Transparent.\nAn image format is not Transparent if used for any substantial amount\nof text.  A copy that is not ``Transparent'' is called ``\\textbf{Opaque}''.\n\nExamples of suitable formats for Transparent copies include plain\nASCII without markup, Texinfo input format, LaTeX input format, SGML\nor XML using a publicly available DTD, and standard-conforming simple\nHTML, PostScript or PDF designed for human modification.  Examples of\ntransparent image formats include PNG, XCF and JPG.  Opaque formats\ninclude proprietary formats that can be read and edited only by\nproprietary word processors, SGML or XML for which the DTD and/or\nprocessing tools are not generally available, and the\nmachine-generated HTML, PostScript or PDF produced by some word\nprocessors for output purposes only.\n\nThe ``\\textbf{Title Page}'' means, for a printed book, the title page itself,\nplus such following pages as are needed to hold, legibly, the material\nthis License requires to appear in the title page.  For works in\nformats which do not have any title page as such, ``Title Page'' means\nthe text near the most prominent appearance of the work's title,\npreceding the beginning of the body of the text.\n\nThe ``\\textbf{publisher}'' means any person or entity that distributes\ncopies of the Document to the public.\n\nA section ``\\textbf{Entitled XYZ}'' means a named subunit of the Document whose\ntitle either is precisely XYZ or contains XYZ in parentheses following\ntext that translates XYZ in another language.  (Here XYZ stands for a\nspecific section name mentioned below, such as ``\\textbf{Acknowledgements}'',\n``\\textbf{Dedications}'', ``\\textbf{Endorsements}'', or ``\\textbf{History}''.)  \nTo ``\\textbf{Preserve the Title}''\nof such a section when you modify the Document means that it remains a\nsection ``Entitled XYZ'' according to this definition.\n\nThe Document may include Warranty Disclaimers next to the notice which\nstates that this License applies to the Document.  These Warranty\nDisclaimers are considered to be included by reference in this\nLicense, but only as regards disclaiming warranties: any other\nimplication that these Warranty Disclaimers may have is void and has\nno effect on the meaning of this License.\n\n\n\\begin{center}\n{\\Large\\bf 2. VERBATIM COPYING\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{2. VERBATIM COPYING}\n\\end{center}\n\nYou may copy and distribute the Document in any medium, either\ncommercially or noncommercially, provided that this License, the\ncopyright notices, and the license notice saying this License applies\nto the Document are reproduced in all copies, and that you add no other\nconditions whatsoever to those of this License.  You may not use\ntechnical measures to obstruct or control the reading or further\ncopying of the copies you make or distribute.  However, you may accept\ncompensation in exchange for copies.  If you distribute a large enough\nnumber of copies you must also follow the conditions in section~3.\n\nYou may also lend copies, under the same conditions stated above, and\nyou may publicly display copies.\n\n\n\\begin{center}\n{\\Large\\bf 3. COPYING IN QUANTITY\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{3. COPYING IN QUANTITY}\n\\end{center}\n\n\nIf you publish printed copies (or copies in media that commonly have\nprinted covers) of the Document, numbering more than 100, and the\nDocument's license notice requires Cover Texts, you must enclose the\ncopies in covers that carry, clearly and legibly, all these Cover\nTexts: Front-Cover Texts on the front cover, and Back-Cover Texts on\nthe back cover.  Both covers must also clearly and legibly identify\nyou as the publisher of these copies.  The front cover must present\nthe full title with all words of the title equally prominent and\nvisible.  You may add other material on the covers in addition.\nCopying with changes limited to the covers, as long as they preserve\nthe title of the Document and satisfy these conditions, can be treated\nas verbatim copying in other respects.\n\nIf the required texts for either cover are too voluminous to fit\nlegibly, you should put the first ones listed (as many as fit\nreasonably) on the actual cover, and continue the rest onto adjacent\npages.\n\nIf you publish or distribute Opaque copies of the Document numbering\nmore than 100, you must either include a machine-readable Transparent\ncopy along with each Opaque copy, or state in or with each Opaque copy\na computer-network location from which the general network-using\npublic has access to download using public-standard network protocols\na complete Transparent copy of the Document, free of added material.\nIf you use the latter option, you must take reasonably prudent steps,\nwhen you begin distribution of Opaque copies in quantity, to ensure\nthat this Transparent copy will remain thus accessible at the stated\nlocation until at least one year after the last time you distribute an\nOpaque copy (directly or through your agents or retailers) of that\nedition to the public.\n\nIt is requested, but not required, that you contact the authors of the\nDocument well before redistributing any large number of copies, to give\nthem a chance to provide you with an updated version of the Document.\n\n\n\\begin{center}\n{\\Large\\bf 4. MODIFICATIONS\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{4. MODIFICATIONS}\n\\end{center}\n\nYou may copy and distribute a Modified Version of the Document under\nthe conditions of sections 2 and 3 above, provided that you release\nthe Modified Version under precisely this License, with the Modified\nVersion filling the role of the Document, thus licensing distribution\nand modification of the Modified Version to whoever possesses a copy\nof it.  In addition, you must do these things in the Modified Version:\n\n\\begin{itemize}\n\\item[A.] \n   Use in the Title Page (and on the covers, if any) a title distinct\n   from that of the Document, and from those of previous versions\n   (which should, if there were any, be listed in the History section\n   of the Document).  You may use the same title as a previous version\n   if the original publisher of that version gives permission.\n   \n\\item[B.]\n   List on the Title Page, as authors, one or more persons or entities\n   responsible for authorship of the modifications in the Modified\n   Version, together with at least five of the principal authors of the\n   Document (all of its principal authors, if it has fewer than five),\n   unless they release you from this requirement.\n   \n\\item[C.]\n   State on the Title page the name of the publisher of the\n   Modified Version, as the publisher.\n   \n\\item[D.]\n   Preserve all the copyright notices of the Document.\n   \n\\item[E.]\n   Add an appropriate copyright notice for your modifications\n   adjacent to the other copyright notices.\n   \n\\item[F.]\n   Include, immediately after the copyright notices, a license notice\n   giving the public permission to use the Modified Version under the\n   terms of this License, in the form shown in the Addendum below.\n   \n\\item[G.]\n   Preserve in that license notice the full lists of Invariant Sections\n   and required Cover Texts given in the Document's license notice.\n   \n\\item[H.]\n   Include an unaltered copy of this License.\n   \n\\item[I.]\n   Preserve the section Entitled ``History'', Preserve its Title, and add\n   to it an item stating at least the title, year, new authors, and\n   publisher of the Modified Version as given on the Title Page.  If\n   there is no section Entitled ``History'' in the Document, create one\n   stating the title, year, authors, and publisher of the Document as\n   given on its Title Page, then add an item describing the Modified\n   Version as stated in the previous sentence.\n   \n\\item[J.]\n   Preserve the network location, if any, given in the Document for\n   public access to a Transparent copy of the Document, and likewise\n   the network locations given in the Document for previous versions\n   it was based on.  These may be placed in the ``History'' section.\n   You may omit a network location for a work that was published at\n   least four years before the Document itself, or if the original\n   publisher of the version it refers to gives permission.\n   \n\\item[K.]\n   For any section Entitled ``Acknowledgements'' or ``Dedications'',\n   Preserve the Title of the section, and preserve in the section all\n   the substance and tone of each of the contributor acknowledgements\n   and/or dedications given therein.\n   \n\\item[L.]\n   Preserve all the Invariant Sections of the Document,\n   unaltered in their text and in their titles.  Section numbers\n   or the equivalent are not considered part of the section titles.\n   \n\\item[M.]\n   Delete any section Entitled ``Endorsements''.  Such a section\n   may not be included in the Modified Version.\n   \n\\item[N.]\n   Do not retitle any existing section to be Entitled ``Endorsements''\n   or to conflict in title with any Invariant Section.\n   \n\\item[O.]\n   Preserve any Warranty Disclaimers.\n\\end{itemize}\n\nIf the Modified Version includes new front-matter sections or\nappendices that qualify as Secondary Sections and contain no material\ncopied from the Document, you may at your option designate some or all\nof these sections as invariant.  To do this, add their titles to the\nlist of Invariant Sections in the Modified Version's license notice.\nThese titles must be distinct from any other section titles.\n\nYou may add a section Entitled ``Endorsements'', provided it contains\nnothing but endorsements of your Modified Version by various\nparties---for example, statements of peer review or that the text has\nbeen approved by an organization as the authoritative definition of a\nstandard.\n\nYou may add a passage of up to five words as a Front-Cover Text, and a\npassage of up to 25 words as a Back-Cover Text, to the end of the list\nof Cover Texts in the Modified Version.  Only one passage of\nFront-Cover Text and one of Back-Cover Text may be added by (or\nthrough arrangements made by) any one entity.  If the Document already\nincludes a cover text for the same cover, previously added by you or\nby arrangement made by the same entity you are acting on behalf of,\nyou may not add another; but you may replace the old one, on explicit\npermission from the previous publisher that added the old one.\n\nThe author(s) and publisher(s) of the Document do not by this License\ngive permission to use their names for publicity for or to assert or\nimply endorsement of any Modified Version.\n\n\n\\begin{center}\n{\\Large\\bf 5. COMBINING DOCUMENTS\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{5. COMBINING DOCUMENTS}\n\\end{center}\n\n\nYou may combine the Document with other documents released under this\nLicense, under the terms defined in section~4 above for modified\nversions, provided that you include in the combination all of the\nInvariant Sections of all of the original documents, unmodified, and\nlist them all as Invariant Sections of your combined work in its\nlicense notice, and that you preserve all their Warranty Disclaimers.\n\nThe combined work need only contain one copy of this License, and\nmultiple identical Invariant Sections may be replaced with a single\ncopy.  If there are multiple Invariant Sections with the same name but\ndifferent contents, make the title of each such section unique by\nadding at the end of it, in parentheses, the name of the original\nauthor or publisher of that section if known, or else a unique number.\nMake the same adjustment to the section titles in the list of\nInvariant Sections in the license notice of the combined work.\n\nIn the combination, you must combine any sections Entitled ``History''\nin the various original documents, forming one section Entitled\n``History''; likewise combine any sections Entitled ``Acknowledgements'',\nand any sections Entitled ``Dedications''.  You must delete all sections\nEntitled ``Endorsements''.\n\n\\begin{center}\n{\\Large\\bf 6. COLLECTIONS OF DOCUMENTS\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{6. COLLECTIONS OF DOCUMENTS}\n\\end{center}\n\nYou may make a collection consisting of the Document and other documents\nreleased under this License, and replace the individual copies of this\nLicense in the various documents with a single copy that is included in\nthe collection, provided that you follow the rules of this License for\nverbatim copying of each of the documents in all other respects.\n\nYou may extract a single document from such a collection, and distribute\nit individually under this License, provided you insert a copy of this\nLicense into the extracted document, and follow this License in all\nother respects regarding verbatim copying of that document.\n\n\n\\begin{center}\n{\\Large\\bf 7. AGGREGATION WITH INDEPENDENT WORKS\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{7. AGGREGATION WITH INDEPENDENT WORKS}\n\\end{center}\n\n\nA compilation of the Document or its derivatives with other separate\nand independent documents or works, in or on a volume of a storage or\ndistribution medium, is called an ``aggregate'' if the copyright\nresulting from the compilation is not used to limit the legal rights\nof the compilation's users beyond what the individual works permit.\nWhen the Document is included in an aggregate, this License does not\napply to the other works in the aggregate which are not themselves\nderivative works of the Document.\n\nIf the Cover Text requirement of section~3 is applicable to these\ncopies of the Document, then if the Document is less than one half of\nthe entire aggregate, the Document's Cover Texts may be placed on\ncovers that bracket the Document within the aggregate, or the\nelectronic equivalent of covers if the Document is in electronic form.\nOtherwise they must appear on printed covers that bracket the whole\naggregate.\n\n\n\\begin{center}\n{\\Large\\bf 8. TRANSLATION\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{8. TRANSLATION}\n\\end{center}\n\n\nTranslation is considered a kind of modification, so you may\ndistribute translations of the Document under the terms of section~4.\nReplacing Invariant Sections with translations requires special\npermission from their copyright holders, but you may include\ntranslations of some or all Invariant Sections in addition to the\noriginal versions of these Invariant Sections.  You may include a\ntranslation of this License, and all the license notices in the\nDocument, and any Warranty Disclaimers, provided that you also include\nthe original English version of this License and the original versions\nof those notices and disclaimers.  In case of a disagreement between\nthe translation and the original version of this License or a notice\nor disclaimer, the original version will prevail.\n\nIf a section in the Document is Entitled ``Acknowledgements'',\n``Dedications'', or ``History'', the requirement (section~4) to Preserve\nits Title (section~1) will typically require changing the actual\ntitle.\n\n\n\\begin{center}\n{\\Large\\bf 9. TERMINATION\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{9. TERMINATION}\n\\end{center}\n\n\nYou may not copy, modify, sublicense, or distribute the Document\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense, or distribute it is void, and\nwill automatically terminate your rights under this License.\n\nHowever, if you cease all violation of this License, then your license\nfrom a particular copyright holder is reinstated (a) provisionally,\nunless and until the copyright holder explicitly and finally\nterminates your license, and (b) permanently, if the copyright holder\nfails to notify you of the violation by some reasonable means prior to\n60 days after the cessation.\n\nMoreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\nTermination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, receipt of a copy of some or all of the same material does\nnot give you any rights to use it.\n\n\n\\begin{center}\n{\\Large\\bf 10. FUTURE REVISIONS OF THIS LICENSE\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{10. FUTURE REVISIONS OF THIS LICENSE}\n\\end{center}\n\n\nThe Free Software Foundation may publish new, revised versions\nof the GNU Free Documentation License from time to time.  Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.  See\n% \\texttt{http://www.gnu.org/copyleft/}.  % SA\n\\url{http://www.gnu.org/copyleft/}.\n\nEach version of the License is given a distinguishing version number.\nIf the Document specifies that a particular numbered version of this\nLicense ``or any later version'' applies to it, you have the option of\nfollowing the terms and conditions either of that specified version or\nof any later version that has been published (not as a draft) by the\nFree Software Foundation.  If the Document does not specify a version\nnumber of this License, you may choose any version ever published (not\nas a draft) by the Free Software Foundation.  If the Document\nspecifies that a proxy can decide which future versions of this\nLicense can be used, that proxy's public statement of acceptance of a\nversion permanently authorizes you to choose that version for the\nDocument.\n\n\n\\begin{center}\n{\\Large\\bf 11. RELICENSING\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{11. RELICENSING}\n\\end{center}\n\n\n``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any\nWorld Wide Web server that publishes copyrightable works and also\nprovides prominent facilities for anybody to edit those works.  A\npublic wiki that anybody can edit is an example of such a server.  A\n``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the\nsite means any set of copyrightable works thus published on the MMC\nsite.\n\n``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0\nlicense published by Creative Commons Corporation, a not-for-profit\ncorporation with a principal place of business in San Francisco,\nCalifornia, as well as future copyleft versions of that license\npublished by that same organization.\n\n``Incorporate'' means to publish or republish a Document, in whole or\nin part, as part of another Document.\n\nAn MMC is ``eligible for relicensing'' if it is licensed under this\nLicense, and if all works that were first published under this License\nsomewhere other than this MMC, and subsequently incorporated in whole\nor in part into the MMC, (1) had no cover texts or invariant sections,\nand (2) were thus incorporated prior to November 1, 2008.\n\nThe operator of an MMC Site may republish an MMC contained in the site\nunder CC-BY-SA on the same site at any time before August 1, 2009,\nprovided the MMC is eligible for relicensing.\n\n\n\\begin{center}\n{\\Large\\bf ADDENDUM: How to use this License for your documents\\par}\n\\phantomsection\n\\addcontentsline{toc}{section}{ADDENDUM: How to use this License for your documents}\n\\end{center}\n\nTo use this License in a document you have written, include a copy of\nthe License in the document and put the following copyright and\nlicense notices just after the title page:\n\n\\bigskip\n\\begin{quote}\n    Copyright \\copyright{}  YEAR  YOUR NAME.\n    Permission is granted to copy, distribute and/or modify this document\n    under the terms of the GNU Free Documentation License, Version 1.3\n    or any later version published by the Free Software Foundation;\n    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.\n    A copy of the license is included in the section entitled ``GNU\n    Free Documentation License''.\n\\end{quote}\n\\bigskip\n    \nIf you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,\nreplace the ``with \\dots\\ Texts.''\\ line with this:\n\n\\bigskip\n\\begin{quote}\n    with the Invariant Sections being LIST THEIR TITLES, with the\n    Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.\n\\end{quote}\n\\bigskip\n    \nIf you have Invariant Sections without Cover Texts, or some other\ncombination of the three, merge those two alternatives to suit the\nsituation.\n\nIf your document contains nontrivial examples of program code, we\nrecommend releasing these examples in parallel under your choice of\nfree software license, such as the GNU General Public License,\nto permit their use in free software.\n\n%---------------------------------------------------------------------\n\\end{document}\n", "meta": {"hexsha": "fd397a76b6626371805b054a676e6f884c64abe1", "size": 32656, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/shortestpath.tex", "max_stars_repo_name": "xmhbbovru/one-pair-shortest", "max_stars_repo_head_hexsha": "b2f56323ed43aea97e3a8dbe2ab6b93dd4787832", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-12-05T00:59:07.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-05T00:59:07.000Z", "max_issues_repo_path": "tex/shortestpath.tex", "max_issues_repo_name": "xmhbbovru/one-pair-shortest", "max_issues_repo_head_hexsha": "b2f56323ed43aea97e3a8dbe2ab6b93dd4787832", "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": "tex/shortestpath.tex", "max_forks_repo_name": "xmhbbovru/one-pair-shortest", "max_forks_repo_head_hexsha": "b2f56323ed43aea97e3a8dbe2ab6b93dd4787832", "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": 49.7804878049, "max_line_length": 744, "alphanum_fraction": 0.7617283195, "num_tokens": 7835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6032765631301931}}
{"text": "\\documentclass[11pt]{amsbook}\n\n\\usepackage{../HBSuerDemir}\t% ------------------------\n\\usepackage{graphicx,wrapfig,lipsum}\n\\setcounter{tocdepth}{3}\n\n\\usepackage{fancyhdr} % Header/Footer\n\\pagestyle{fancy}\n\\thispagestyle{fancy}\n\\fancyfoot{}\n\\fancyfoot[L]{\\footnotesize \n\tFreshman Calculus by Suer \\& Demir  \\textbf{DRAFT} \\\\\n\t\\LaTeX ~by Haluk Bingol \n\t\\href{http://www.cmpe.boun.edu.tr/~bingol}\n\t{http://www.cmpe.boun.edu.tr/bingol} \n\t%\\large \n\t%\\footnotesize \n\t\\today}\n\\fancyfoot[R]{{\\thepage} of \\pageref{LastPage}}\n\n\\begin{document}\n\n% ++++++++++++++++++++++++++++++++++++++\n\\hPage{b1p2/344}\n% ++++++++++++++++++++++++++++++++++++++\n\\\\\n\\centerline{\\thepage}\n\n\\section{METHODS OF INTEGRATION}\n\\par\nIn calculus there are essentialy two methods of integration :\n\"change of variables\" and \"by parts\".\n\n\\subsection{Integration by change of variable (substitution)}\\hfill\n\\par\nLet the indefinite integral\n$$I = \\int f(x)~dx$$\nto be evaluated.\n\\par\nOne makes (tries) the substitution\n$$x = u(t) \\quad \\textrm{or} \\quad t = u^{-1}(x) = v(x)$$\n$$I = \\int f(x) ~dx = \\int f(u(t)).u'(t)~dt = \\int g(t)~dt$$\nIf the substitution is properly selected the new integral is\nmore easily integrable than the original one, getting G(t) + c\nand replacing t by v(x), one has\n$$G(t) + c = G(v(x)) + c = F(x) + c$$\n\\begin{exmp}\n\tEvaluate\n\t$$I = \\int \\frac{ dx }{(1-x^2)^{3/2}}$$\n\\end{exmp}\n\\begin{wrapfigure}{r}{2.2cm}\n\t\\includegraphics[width=0.25\\textwidth]{images/b1p2-344-fig01}\n\t\\centering\n\tsin Triangle\\footnote{wrapfig package is used}\n\t\\caption{}\\label{wrap-fig:1}\n\\end{wrapfigure}\n{\n\t\\begin{sltn}\n\t\tSince square root is not involved, $1-x^2 > 0$ follows\n\t\tand the substitution $x = sin \\theta $ may work\n\t\t$$I = \\int \\frac{cos \\theta ~d\\theta}{(1-sin^2\\theta)^{3/2}}\n\t\t=\\int \\frac{cos \\theta ~d\\theta}{cos^3\\theta}\n\t\t=\\int sec^2\\theta ~d\\theta\n\t\t=tan\\theta + c$$\n\t\\end{sltn}\n\t\\par\n\tThe result is to be written in terms of x.\n\tUsing the relation $x = sin \\theta$ we have\n\t$$I = tan\\theta + c = \\frac{x}{\\sqrt{1-x^2}} + c$$\n\n\\begin{exmp}\n\tEvaluate\n\t$$I = \\int (x^3-2x+3)^{15}(3x^2-2)~dx$$\\\\\n\t\\\\\n\\end{exmp}\n\\begin{sltn}\n\tObserving that, $D(x^3-2x+3) = (3x^2-2)$ the proper\n\tsubstitution is $$u = (x^3-2x+3)\\;\\textrm{,} \\quad du = (3x^2-2)~dx$$\n\\end{sltn}\n\n% =======================================================\n\\end{document}  \n", "meta": {"hexsha": "579bf539bf32ef7d0263dac58800e21d1f2e8d7d", "size": 2314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw1/non-merged/MUSTAFA BUGRA CIL_35913_assignsubmission_file_/2011400249/pages/b1p2-344.tex", "max_stars_repo_name": "yildirimyigit/cmpe220_2016_3", "max_stars_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-15T22:03:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-15T22:03:34.000Z", "max_issues_repo_path": "hw1/non-merged/MUSTAFA BUGRA CIL_35913_assignsubmission_file_/2011400249/pages/b1p2-344.tex", "max_issues_repo_name": "yildirimyigit/cmpe220_2016_3", "max_issues_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_issues_repo_licenses": ["MIT"], "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/non-merged/MUSTAFA BUGRA CIL_35913_assignsubmission_file_/2011400249/pages/b1p2-344.tex", "max_forks_repo_name": "yildirimyigit/cmpe220_2016_3", "max_forks_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_forks_repo_licenses": ["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.8795180723, "max_line_length": 70, "alphanum_fraction": 0.6136560069, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506526772883, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6032765594104362}}
{"text": "\\newlecture{3}{Maths}\n\n\\section{Use Maths in \\LaTeX}\n\n\\subsection{Math Expressions}\n\n\\begin{frame}[fragile]{Introduction}\nBasic equations in \\LaTeX\\ can be easily ``programmed'', for example: \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Mathematical_expressions}}\n\\begin{latexexample}\nThe well known Pythagorean theorem \\(x^2 + y^2 = z^2\\) was \nproved to be invalid for other exponents. \nMeaning the next equation has no integer solutions:\n\n\\[ x^n + y^n = z^n \\]\n\\end{latexexample}\n\\end{frame}\n\n\\begin{frame}[fragile]{Subscripts and Superscripts}\nThe use of superscripts and subscripts is very common in mathematical expressions involving exponents, indexes, and in some special operators. \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Subscripts_and_superscripts}}\n\n\\begin{latexexample}\n\\[ a_1^2 + a_2^2 = a_3^2 \\]\n\\end{latexexample}\n\nNote that here we use \\LC|\\[| and \\LC|\\]| to typeset a mathematical expression. You may see many people (including myself in the past) using a pair of \\LC|$$| instead. It is a plain-\\TeX\\ command, and is nowadays heavily deprecated. See this discussion \\urllink{https://tex.stackexchange.com/questions/503/why-is-preferable-to} on Stack Exchange for more information. \n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nIf the expression contains long superscripts or subscripts, these need to be collected in braces, as \\LaTeX normally applies the mathematical commands \\LC{^} and \\LC{_} only to the following character:\n\n\\begin{latexexample}\n\\[ x^{2 \\alpha} - 1 = y_{ij} + y_{ij}  \\]\n\\[ (a^n)^{r+s} = a^{nr+ns}  \\]\n\\[ x^abc, \\quad x_abc, \\quad x^abc_abc \\]\n\\[ x^{abc}, \\quad x_{abc}, \\quad x^{abc}_{abc} \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Brackets and Parentheses}\nParentheses and brackets are very common in mathematical formulas. You can easily control the size and style of brackets in \\LaTeX. \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Brackets_and_Parentheses}} \\medskip\n\nHere's how to type some common math braces and parentheses in \\LaTeX: \\medskip\n\n\\begin{center}\n\\begin{tabular}{ ccc }\nType & \\LaTeX & Code \\\\\\hline\nParentheses; round brackets\t & \\LCX{(x+y)} \\\\\nBrackets; square brackets &\t \\LCX{[x+y]} \\\\\nBraces; curly brackets\t& \\LCX{\\{x+y\\}} \\\\\nAngle brackets\t& \\LCX{\\langle x+y \\rangle} \\\\\nPipes; vertical bars & \\LCX{|x+y|} \\\\\nDouble pipes & \\LCX{\\|x+y\\|} \\\\\nFloor brackets & \\LCX{\\lfloor x+y \\rfloor} \\\\\nCeil brackets & \\LCX{\\lceil x+y \\rceil} \\\\\n\\end{tabular}\n\\end{center}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nThe size of brackets and parentheses can be manually set, or they can be resized dynamically in your document, as shown in the next example:\n\n\\begin{latexexample}\n\\[ F = G \\left( \\frac{m_1 m_2}{r^2} \\right) \\]\n\\end{latexexample}\n\nNotice that to insert the parentheses or brackets, the \\LC{\\left} and \\LC{\\right} commands are used. Even if you are using only one bracket, both commands are mandatory, you can use invisible brackets \\LC{\\left.} or \\LC{\\right.} for this.\n\n\\begin{latexexample}\n\\[ \\int_a^b x^2 {\\rm d} x = \\left. \\frac{1}{3}x^3 \\right|_a^b \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nSometimes you may want to control the sizes of the brackets yourselves, which is called manually sized brackets. The commands listed are designed for thus purpose. \\medskip\n\n\\begin{center}\n\\begin{tabular}{ ccc }\nSize & \\LaTeX & Code \\\\[2pt] \\hline\nbig\t & \\LCX{\\big( \\big)} \\\\[5pt]\nBig &\t \\LCX{\\Big[ \\Big]} \\\\[5pt]\nbigg\t& \\LCX{\\bigg\\{ \\bigg\\}} \\\\[5pt]\nBigg\t& \\LCX{\\Bigg| \\Bigg|} \\\\\n\\end{tabular}\n\\end{center}\n\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]{Mathematical Modes}\n\n\\LaTeX\\ allows two writing modes for mathematical expressions: the \\structure{inline} mode and the \\structure{display} mode. The first one is used to write formulas that are part of a text. The second one is used to write expressions that are not part of a text or paragraph, and are therefore put on separate lines. \\medskip\n\nTo put your equations in \\structure{inline} mode use \\LC|\\(| and \\LC|\\)|, \\LC|$| and \\LC|$| or \\LC|\\begin{math} | and \\LC|\\end{math}|. They all work and the choice is a matter of taste.\n\n\\begin{latexexample}\nIn physics, the mass-energy equivalence is stated \nby the equation $E=mc^2$, discovered in 1905 by Albert Einstein.\n\\end{latexexample}\n\nThe \\structure{display} mode is usually used with mathematical environments together, which will be discussed in the next subsection.\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]{Numbering of Equations}\nThe \\structure{display} mode has two versions: \\structure{numbered} and \\structure{unnumbered}.\n\n\\begin{latexexample}\nThe mass-energy equivalence is described by the famous equation\n\\[E=mc^2\\]\ndiscovered in 1905 by Albert Einstein. \nIn natural units ($c$ = 1), the formula expresses the identity\n\\begin{equation}\nE=m\n\\end{equation}\n\\end{latexexample}\n\\end{frame}\n\n\\subsection{Math Environments}\n\n\n\\begin{frame}[fragile]{The \\packagename{equation} Environment}\n\tAn \\packagename{equation} environment contains a set of maths equations\n\t\\begin{command}\n\t\t\\begin{minted}{latex}\n\\begin{equation(*)}\n% ...\n\\end{equation(*)}\n\t\t\\end{minted}\n\t\\end{command}\n\t\\begin{example}\n\t\t\\input{../examples/curl.tex}\n\t\\end{example}\n\tIf a star(\\structure{*}) is added, the sequence number of the equation won't be displayed (this feature is from the \\packagename{amsmath} package, and should behave very similar as directly using \\LC|\\[| and \\LC|\\]|). Note that the environment name in the \\LC{\\begin} and \\LC{\\end} statements must be the same (both or neither have a \\structure{*} here).\n\\end{frame}\n\n\\begin{frame}[fragile]\n\tThe \\LaTeX\\ script of the equation above is quite long, but not so difficult as you think so. All of the useless spaces are omitted, so please pay attention to the necessary spaces (marked in \\textvisiblespace). \\medskip\n\n\t\\inputminted[showspaces]{latex}{../examples/curl.tex}\n\t\n\tIn math environments, unlike in plain text, normal spaces will not lead to visible spaces in output. Only  \\LC|\\|\\packagename{\\textvisiblespace} or \\LC{\\quad,\\qquad} etc. will create spaces between words. \\medskip\n\t\n\t\\LC{\\partial} prints the symbol \\structure{$\\partial$}, \\LC{\\frac{...}{...}} makes a \\structure{fraction}. \\medskip\n\t\n\t\\LC{\\left(} and \\LC{\\right(} make \\structure{braces} that fit the equation's height. \\medskip\n\t\n\tIt is written in plain-\\LaTeX, and things can even be easier with packages like \\packagename{physics}, which will be demonstrated later.\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{split} Environment (inline)}\n\nIn order to deal with extremely long equations or equation with multiple lines, we can use the \\packagename{split} environment. It is an \\structure{inline} environment being used in other maths environments.\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\begin{split}\n    F &= 1+2+3+4+5 \\\\\n      &= 15\n  \\end{split}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\LC{&} is used to align the equal marks, and \\LC{\\\\} is used to split the equation into two lines. Only one equation number will be generated in an \\packagename{equation} environment. \\medskip\n\nThe \\packagename{split} environment is designed to serve as the entire body of an equation, or an entire line of an \\packagename{align} or \\packagename{gather} environment. There cannot be any printed material before or after it within the same enclosing structure. \n\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{aligned} Environment (inline)}\nFor linear equation systems, the \\packagename{aligned} environment can be used, which is similar to the \\packagename{split} environment above. It is also an \\structure{inline} environment, which can be used in \\structure{inline} mode such as \\LC|$$|! Here \\packagename{split} doesn't work because \\LC|\\left| and \\LC|\\right| is an enclosing structure. See this discussion \\urllink{https://tex.stackexchange.com/questions/187938/whats-the-difference-between-split-and-aligned} for more information.\n\n\\begin{latexexamplesplit}\nEquations:\n$\n  \\left\\lbrace\\begin{aligned}\n    x+y &= 1 \\\\ x-y &= 1\n  \\end{aligned}\\right.\n  \\Longrightarrow\n  \\left\\lbrace\\begin{aligned}\n    x &= 1 \\\\ y &= 0\n  \\end{aligned}\\right.\n$\n\\end{latexexamplesplit}\n\nActually things can also be easier with packages like \\packagename{systeme}, which will be demonstrated later.\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{align} Environment}\n\nAn \\packagename{align} environment can be used to simply the \\packagename{split} or \\packagename{aligned} in the  \\packagename{equation} environment. But it numbers the equation on each line.\n\n\\begin{latexexamplesplit}\n\\begin{align}\n  F &= 1+2+3+4+5 \\\\\n    &= 15\n\\end{align}\n\\end{latexexamplesplit}\n\nUse \\packagename{align*} so that there will be no number(s).\n\n\\begin{latexexamplesplit}[0.6]\n\\begin{align*}\n  a+b & \\Leftrightarrow b+a \\\\\n  (a+b)+c & \\Leftrightarrow a+(b+c)\n\\end{align*}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nThe ampersand character \\LC{&} determines where the equations align. The odd columns are right-aligned, and the even ones are left-aligned, so you can use \\LC{&&} if you want to make two neighbor column aligned to the same direction.\n\n\\setlength{\\belowdisplayskip}{-10pt}\n\\begin{latexexample}\n\\begin{align*}\n  \\text{(right)} & \\text{(left)} && \\text{(left)} & \\text{(right)} \n  &&  \\text{(right)} & \\text{(left)} \\\\\n  x     &=y     &&  w   &=z        &&  a&=b+c \\\\\n  2x    &=-y    &&  3w  &=z/2      &&  a&=b \\\\\n  -4+5x &=2+y   &&  w+2 &=-1+w     &&  ab&=cb\n\\end{align*}\n\\end{latexexample}\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]{The \\packagename{cases} Environment (inline)}\n\nThe linear system of equations can also be typeset simply with the \\packagename{cases} environment. It is less flexible than an \\packagename{aligned} environment, eg., there can only be one \\LC{&} on each row. Another minor difference is that the horizontal space before  \\LC{&} is larger than other similar environments.\n\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\left\\lbrace\\begin{aligned}\n    x+y &= 1 \\\\ \n    x-y &= 1\n  \\end{aligned}\\right.\n\\end{equation}\n\n\\begin{equation}\n  \\begin{cases} \n    x+y &= 1 \\\\ \n    x-y &= 1\n  \\end{cases}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]{The \\packagename{gather} Environment}\n\nIf you just need to display a set of consecutive equations, centered and with no alignment whatsoever, use the \\packagename{gather} environment. The asterisk trick to set/unset the numbering of equations also works here.\n\n\\begin{latexexamplesplit}\n\\begin{gather} \n  2x - 5y =  8 \\\\ \n  3x^2 + 9y =  3a + c\n\\end{gather}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{gathered} Environment (inline) }\n\nThere is also an \\structure{inline} version of \\packagename{gather}, called \\packagename{gathered}. The relationship of them is similar to \\packagename{align} and \\packagename{aligned}.\n\n\\begin{latexexamplesplit}\n\\begin{equation} \n  \\begin{gathered} \n    2x - 5y =  8 \\\\ \n    3x^2 + 9y =  3a + c\n  \\end{gathered}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]{The \\packagename{multline} Environment}\nFor equations longer than a line use the \\packagename{multline} environment. Insert a double backslash to set a point for the equation to be broken. The first part will be aligned to the left and the second part will be displayed in the next line and aligned to the right.\n\n\\begin{latexexample}\n\\begin{multline}\n  p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3 \\\\ \n         - 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3\n\\end{multline}\n\\end{latexexample}\n\nThe equation number will be in the last line, use \\packagename{multline*} for no numbering.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nFor equations equal or longer then three lines,\n\n\\begin{latexexample}\n\\begin{multline*}\n  a+b+c=1 \\\\ \n  b+c=2 \\\\\n  c+d=1 \\\\\n  d=3\n\\end{multline*}\n\\end{latexexample}\n\nHere, the first column is left-aligned, the last column is right-aligned and the others ones are center-aligned. \n\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{flalign} Environment}\nFor equations aligned left, use the \\packagename{flalign} environment. It is similar to the \\packagename{align} environment.\n\n\\begin{latexexample}\n\\begin{flalign}\n  a+b &=1=& b+a \\\\\n  b   &=2=& c\n\\end{flalign}\n\\end{latexexample}\n\nYou may notice that the columns are flushed left (start from the left most position) and the right most column is flushed right, different from the \\packagename{align} environment.\n\n\\end{frame}\n\n\n\\subsection{Spacing in Math Mode}\n\n\\begin{frame}[fragile]{Horizontal Spacing}\nHorizontal spacing in maths mode is useful in several situations, let's see an example: \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Spacing_in_math_mode}} \\medskip\n\n\\begin{latexexample}\nAssume we have the next sets\n\\[\nS = \\{ z \\in \\mathbb{C}\\, |\\, |z| < 1 \\} \\quad \n\\textrm{and} \\quad S_2=\\partial{S}\n\\]\n\\end{latexexample}\n\nAs you see in this example, a mathematical text can be explicitly spaced by means of some special commands.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nThe spacing depends on the command you insert, the example below contains a complete list of spaces and how they look like.\n\n\\begin{latexexamplesplit}\n\\begin{align*}\nf(x) =& x^2\\! +3x\\! +2 \\\\\nf(x) =& x^2+3x+2 \\\\\nf(x) =& x^2\\, +3x\\, +2 \\\\\nf(x) =& x^2\\: +3x\\: +2 \\\\\nf(x) =& x^2\\; +3x\\; +2 \\\\\nf(x) =& x^2\\ +3x\\ +2 \\\\\nf(x) =& x^2\\quad +3x\\quad +2 \\\\\nf(x) =& x^2\\qquad +3x\\qquad +2\n\\end{align*}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Vertical Spacing}\n    When the space between \\structure{display} maths and the main body paragraph is considered larger than expectation, is there any way to modify the line spacing? \\medskip\n    \n    In default style of \\structure{display} mode is like\n\n\\begin{latexexample}\nyour body paragraph is supposed to be typed here\n\\begin{equation}\n  a \\times b = c \n\\end{equation}\nyour body paragraph is supposed to be typed here\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nYou can use \\LC{\\setlength} to set the \\structure{displayskip}. \\medskip\n\t\n\\begin{command}\n\\begin{LCL}\n\\setlength\\abovedisplayskip{<length>}\n\\setlength\\belowdisplayskip{<length>}\n\\end{LCL}\n\\end{command}\n\n\\begin{latexexample}\n\\setlength\\abovedisplayskip{0em}\n\\setlength\\belowdisplayskip{0em}\nyour body paragraph is supposed to be typed here\n\\begin{equation}\n  a \\times b = c \n\\end{equation}\nyour body paragraph is supposed to be typed here\n\\end{latexexample}\n\n\\end{frame}\n\n\n\n%\\subsection{Inline}\n\n%\\begin{frame}[fragile]\n%\t\\frametitle{A simple method of entering math environment}\n%\tUsually, we can use \\alert{\\$\\$}\\dots\\alert{\\$\\$} to display a maths equation instead of \\samplecommand{begin}\\{equation*\\}\\dots\\samplecommand{end}\\{equation*\\}, which almost have same effect.\\\\[0.5em]\n%\tHowever, there is another style of math environment, inline style, which will display the maths equation on the same line of the text before it. It is used like \\alert{\\$}\\dots\\alert{\\$}\n%\t\\begin{example}\n%\t\t\\begin{minted}{latex}\n%This is a simple equation $$x^2+y^2=1$$\n%This is a simple inline equation $x^2+y^2=1$  \\\\\n%The concentration of [H$_3$O$^+$] ([$H_3O^+$]) is \\dots\n%\t\t\\end{minted}\n%\t\\end{example}\n%\t\tThis is a simple equation $$x^2+y^2=1$$\n%\t\tThis is a simple inline equation $x^2+y^2=1$  \\\\\n%\t\tThe concentration of [H$_3$O$^+$] ([$H_3O^+$]) is ...\n%\\end{frame}\n\n%\\begin{frame}\n%\t\\frametitle{The difference between inline and normal}\n%\tActually, the display style of inline and normal equations have some differences.\n%\t\\begin{example}\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\centering Expression\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering inline\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering normal\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{left(}\\samplecommand{frac}\\{1\\}\\{\\samplecommand{frac}\\{1\\}\\{2\\}\\}\\samplecommand{right)}\\\\\n%\t\t\t\\^{}\\{\\samplecommand{frac}\\{1\\}\\{2\\}\\}\\}\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\left(\\frac{1}{\\frac{1}{2}}\\right)^{\\frac{1}{2}}$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\left(\\frac{1}{\\frac{1}{2}}\\right)^{\\frac{1}{2}}$$\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{lim}\\_\\{n\\samplecommand{to}\\samplecommand{infty}\\}a\\_n=+\\samplecommand{infty}\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\lim_{n\\to\\infty}a_n=+\\infty$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\lim_{n\\to\\infty}a_n=+\\infty$$\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{sum}\\_\\{k=1\\}\\^{}\\{10\\}k=55\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\sum_{k=1}^{10}k=55$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\sum_{k=1}^{10}k=55$$\n%\t\t\\end{minipage}\n%\t\\end{example}\n%\\end{frame} \n%\n%\\begin{frame}\n%\tHowever, most of the differences can be fixed by some other commands\n%\t\\begin{example}\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\centering Expression\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering inline\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering normal\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{left(}\\samplecommand{dfrac}\\{1\\}\\{\\samplecommand{frac}\\{1\\}\\{2\\}\\}\\samplecommand{right)}\\\\\n%\t\t\t\\^{}\\{\\samplecommand{frac}\\{1\\}\\{2\\}\\}\\}\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\left(\\dfrac{1}{\\frac{1}{2}}\\right)^{\\frac{1}{2}}$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\left(\\dfrac{1}{\\frac{1}{2}}\\right)^{\\frac{1}{2}}$$\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{lim}\\samplecommand{limits}\\_\\{n\\samplecommand{to}\\samplecommand{infty}\\}a\\_n=+\\samplecommand{infty}\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\lim\\limits_{n\\to\\infty}a_n=+\\infty$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\lim\\limits_{n\\to\\infty}a_n=+\\infty$$\n%\t\t\\end{minipage}\n%\t\t\\vfill\n%\t\t\\begin{minipage}{0.48\\linewidth}\n%\t\t\t\\samplecommand{sum}\\samplecommand{limits}\\_\\{k=1\\}\\^{}\\{10\\}k=55\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t\\centering $\\sum\\limits_{k=1}^{10}k=55$\n%\t\t\\end{minipage}\n%\t\t\\begin{minipage}{0.24\\linewidth}\n%\t\t\t$$\\sum\\limits_{k=1}^{10}k=55$$\n%\t\t\\end{minipage}\n%\t\\end{example}\n%\tHere the command \\samplecommand{limits} can be used in much more situations to fix the position of the bounds. The command \\samplecommand{dfrac} is used to print a fraction in normal size.\n%\\end{frame}\n\n\\subsection{Basic Math Commands}\n\n\\begin{frame}[fragile]{Fractions and Binomials}\nFractions and binomial coefficients are common mathematical elements with similar characteristics - one number goes on top of another. \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Fractions_and_Binomials}} \n\n\\begin{command}\n\\begin{LCL}\n\\frac{top}{bottom}  % fraction\n\\binom{top}{bottom} % binomial coefficients\n\\end{LCL}\n\\end{command}\n\nUsing fractions and binomial coefficients in an expression is straightforward.\n\n\\begin{latexexample}\nThe binomial coefficient is defined by the next expression:\n\\[ \\binom{n}{k} = \\frac{n!}{k!(n-k)!} \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nIn \\structure{inline} and \\structure{display} mode, the appearance of the fractions and binomials may differ. You can use \\LC|\\displaystyle| or \\LC|\\textstyle| to adjust the size of the fractions and binomials, or use \\LC|\\dfrac| if not all fractions in an equation need to be resized.\n\n\\begin{latexexample}\nWhen displaying fractions in-line, for example $\\frac{3x}{2}$\nyou can set a different display style:  $ \\displaystyle \\frac{3x}{2} $.\nOr you can use $\\dfrac{3x}{2}$. This is also true the other way around\n\\[ f(x)=\\binom{n}{x}=\\frac{n!}{x!(n-x)!} \\quad \\textrm{and} \\quad\n   f(x)=\\textstyle\\binom{n}{x}=\\frac{n!}{x!(n-x)!} \\]\n\\end{latexexample}\n\nThe command \\LC|\\displaystyle| will format the fractions and binomials as if they were in mathematical display mode. On the other side, \\LC|\\textstyle| will change the style of them as if they were part of the text.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nThe usage of fractions is quite flexible, they can be nested to obtain more complex expressions. And \\LC|\\cfrac| can be used to make continued fractions.\n\n\\begin{latexexample}\nThe fractions can be nested\n\\[ \\frac{1+\\frac{a}{b}}{1+\\frac{1}{1+\\frac{1}{a}}} \\]\nNow a wild example\n\\[ a_0+\\cfrac{1}{a_1+\\cfrac{1}{a_2+\\cfrac{1}{a_3+\\cdots}}} \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Operators}\nCharacters in mathematical mode are usually shown in italics, but sometimes especial function names require different formatting (font and skip), this is accomplished by using operators defined in \\LaTeX. \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Operators}}\\medskip\n\nTrigonometrical functions, logarithms, and some others can be written in a document by means of some special commands. \n\n\\begin{latexexample}\n\\[ \\sin(a + b ) = \\sin(a)\\cos(b) + \\cos(a)\\sin(b) \\]\n\\[ \\log_a b = \\frac{\\log_c b}{\\log_c a} = \\frac{\\ln b}{\\ln a} \\]\n\\[ \\tan a,\\quad \\arccos a,\\quad \\arcsin a,\\quad \\arctan a \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Integrals}\n\nIntegral expression can be added using the command\n\\begin{command}\n\\begin{LCL}\n\\int_{lower}^{upper} \n\\end{LCL}\n\\end{command}\n\nNote, that integral expression may seems a little different in \\structure{inline} and \\structure{display} math mode - in \\structure{inline} mode the integral symbol and the limits are compressed.\n\n\\begin{latexexamplesplit}\nIntegral $\\int_{a}^{b} x^2 dx$ inside text\n\\[ \\int_{a}^{b} x^2 dx \\]\n\\end{latexexamplesplit}\n\nThere is always an argue about whether \\textit{italic} or roman style of ``d'' should be used in integrals and derivatives. There's no right or wrong. If you prefer to use roman style, try \\packagename{commath} or \\packagename{physics} package. Either of them provides some macros to insert the ``d'' you want simply.\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Multiple Integrals}\n\nTo obtain double/triple/multiple integrals you must use \\packagename{amsmath} package.\n\n\\begin{latexexamplesplit}[0.52]\n\\begin{gather*}\n\\iint_V \\mu(u,v) \\,du\\,dv \\\\\n\\iiint_V \\mu(u,v,w) \\,du\\,dv\\,dw \\\\\n\\iiiint_V \\mu(t,u,v,w) \\,dt\\,du\\,dv\\,dw \\\\\n\\idotsint_V \\mu(u_1,\\dots,u_k) \\,du_1 \\dots du_k \\\\\n\\end{gather*}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Cyclic Integrals}\n\nTo obtain cyclic integrals you must use \\packagename{esint} package.\n\n\\begin{latexexamplesplit}[0.52]\n\\begin{gather*}\n\\oint_V f(s) \\,ds \\\\\n\\oiint_V f(s,t) \\,ds\\,dt \\\\\n\\end{gather*}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Limits, Sums and Products}\n\nLike integrals, limits, sums and products expression are compressed in \\structure{inline} mode.\n\n\\begin{command}\n\\begin{LCL}\n\\limits_{lower}\n\\sum_{lower}^{upper} \n\\prod_{lower}^{upper} \n\\end{LCL}\n\\end{command}\n\n\\begin{latexexample}\nLimit $\\lim_{x\\to\\infty} f(x)$ inside text\t\n\\[ \\lim_{x\\to\\infty} f(x) \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\n\\begin{latexexample}\nSum $\\sum_{n=1}^{\\infty} 2^{-n} = 1$ inside text\n\\[ \\sum_{n=1}^{\\infty} 2^{-n} = 1 \\]\n\\end{latexexample}\n\n\n\\begin{latexexample}\nProduct $\\prod_{i=a}^{b} f(i)$ inside text\n\\[ \\prod_{i=a}^{b} f(i) \\]\n\\end{latexexample}\n\\end{frame}\n\n\\begin{frame}[fragile]{Improvement of Integrals, Limits, Sums and Products}\n\nIn \\structure{inline} math mode the integral/sum/product lower and upper limits are placed right of integral symbol. Similar is for limit expressions. If you want the limits of an integral/sum/product to be specified above and below the symbol in \\structure{inline} math mode (or in \\structure{display} mode), use the \\LC|\\limits| command before limits specification.\n\n\\begin{latexexample}\nIntegral $\\int_{a}^{b} x^2 dx$ inside text \\par\nImproved integral $\\int\\limits_{a}^{b} x^2 dx$ inside text \\par\nUse limits in display mode \\[ \\int\\limits_{a}^{b} x^2 dx \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nMoreover, adding \\LC|\\displaystyle| beforehand will make the symbol in \\structure{inline} mode large and easier to read, as in \\structure{display} mode.\n\n\\begin{latexexample}\nLimit $\\lim_{x\\to\\infty} f(x)$ inside text \\par\nDisplay style limit $\\displaystyle\\lim_{x\\to\\infty} f(x)$ inside text \n\\end{latexexample}\n\nOn the other hand, \\LC|\\mathlarger| command (provided by \\packagename{relsize} package) is used to get bigger integral symbol in display.\n\n\\begin{latexexample}\n$\\int\\frac{1}{2}dx - \\mathlarger{ \\int\\frac{1}{2}dx}$\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Other Math Symbols}\n\nSome examples of other common used math symbols are shown.\n\n\\begin{center}\n\\begin{tabular}{ ccc }\nName & \\LaTeX & Code \\\\\\hline\nSquare Root\t & \\LCX{\\sqrt{a}\\ \\sqrt[b]{a}} \\\\\nOver/Under Line & \\LCX{\\overline{a+b}\\ \\underline{a+b}} \\\\\nOver Brace & \\LCX{\\overbrace{1+2+\\cdots+n}^n} \\\\\nUnder Brace & \\LCX{\\underbrace{1+2+\\cdots+n}_n} \\\\\nOver Arrow & \\LCX{\\overrightarrow{a+b}\\ \\overleftarrow{a+b}} \\\\\nUnder Arrow & \\LCX{\\underrightarrow{a+b}\\ \\underleftarrow{a+b}} \\\\\nDots & \\LCX{\\dots\\ \\cdot\\ \\cdots\\ \\vdots\\ \\ddots} \\\\\n\\multirow{2}{*}{Arrows} & \\LCX{\\rightarrow\\ \\leftarrow\\ \\leftrightarrow} \\\\\n& \\LCX{\\Rightarrow\\ \\Leftarrow\\ \\Leftrightarrow} \\\\\n& \\LCX{\\longleftarrow\\ \\Longrightarrow}\n\\end{tabular}\n\\end{center}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Mathematical Fonts}\nIn mathematical mode as well as in text mode, you can change the typeface as needed. For instance, it's customary to represent real numbers with a blackboard bold font, or topological spaces with calligraphic font. \\footnote[1]{Some of this part is ported from the tutorial of Overleaf: \\urllink{https://www.overleaf.com/learn/latex/Mathematical_fonts}}\\medskip\n\nFor some elements is convenient to have the possibility of changing the font typeface.\n\n\\begin{latexexample}\nLet \\( \\mathcal{T} \\) be a topological space, a basis is defined as\n\\[ \\mathcal{B} = \\{B_{\\alpha} \\in \\mathcal{T}\\, |\\,  \n   U = \\bigcup B_{\\alpha} \\forall U \\in \\mathcal{T} \\} \\]\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Mathematical Fonts for Capital Letters}\n\nThere are some font typefaces that support only a limited number of characters; these fonts usually denote some special sets.\n\n\\begin{latexexamplesplit}\n\\begin{gather*}\n  RQSZ \\\\\n  \\mathcal{RQSZ} \\\\\n  \\mathfrak{RQSZ} \\\\\n  \\mathbb{RQSZ}\n\\end{gather*}\n\\end{latexexamplesplit}\n\nThis example shows Calligraphic, Fraktur and Blackboard bold typefaces. For instance, to display the R in blackboard bold typeface \\LC|$\\mathbb{R}$| will do the trick.\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Other Mathematical Fonts}\n\nIt's possible to set a different font family for a complete mathematical expression.\n\n\\begin{latexexamplesplit}[0.6]\n\\begin{gather*}\n  3x^2 \\in R \\subset Q \\\\\n  \\mathnormal{3x^2 \\in R \\subset Q} \\\\\n  \\mathrm{3x^2 \\in R \\subset Q} \\\\\n  \\mathit{3x^2 \\in R \\subset Q} \\\\\n  \\mathbf{3x^2 \\in R \\subset Q} \\\\\n  \\mathsf{3x^2 \\in R \\subset Q} \\\\\n  \\mathtt{3x^2 \\in R \\subset Q} \n\\end{gather*}\n\\end{latexexamplesplit}\n\nIn this case, not only letters but all characters change its appearance, for example \\LC|$\\mathit{3x^2}$| italicises the entire expression.\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Define Own Symbols}\n\nIf you need to add a personalized operator to be displayed in Roman font instead of italics use \\LC|\\DeclareMathOperator|, provided by the the package \\packagename{amsmath}.\n\n\\begin{example}\n\\begin{LCL}\n\\DeclareMathOperator{\\Mr}{M_{\\mathbb{R}}}\nUser-defined operator for matrices with Real entries $ x \\in \\Mr $\n\\end{LCL}\nUser-defined operator for matrices with Real entries $ x \\in \\Mr $\n\\end{example}\n\nThe command can be slightly modified if you need that your defined operator uses subscripts, as the \\LC|\\lim| operator, in such case use \\LC|\\DeclareMathOperator*|. \\medskip\n\nYou can also use \\LC|\\mathop| to define a italics math operator supporting subscripts, and change it to Roman font by hand.\n\n\\begin{latexexamplesplit}[0.78]\n\\[ \\mathop{\\mathrm{limsup}}_{n\\to\\infty}\\mathop{rot}F_n \\]\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\n\\subsection{Matrices and Arrays}\n\n\\begin{frame}[fragile]{The \\packagename{matrix} Environment (inline)}\nThere are various kinds of matrix environments defined in \\packagename{amsmath} package, they are \\packagename{matrix}, \\packagename{pmatrix}, \\packagename{bmatrix}, \\packagename{Bmatrix}, \\packagename{vmatrix}, \\packagename{Vmatrix}.\n\\begin{command}\n\\begin{LCL}\n\\begin{[p/b/B/v/V]matrix}\n  a_{11} & a_{12} & ... & a_{1n} \\\\\n  a_{21} & a_{22} & ... & a_{2n} \\\\\n  ...    & ...    & ... & ...    \\\\\n  a_{n1} & a_{n2} & ... & a_{nn} \\\\\n\\end{[p/b/B/v/V]matrix}\n\\end{LCL}\n\\end{command}\n\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\begin{pmatrix}\n    a_{11} & a_{12} & a_{13} \\\\\n    a_{21} & a_{22} & a_{23} \\\\\n    a_{31} & a_{32} & a_{33} \\\\\n  \\end{pmatrix}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}\n\tHere is some examples of the style of these matrix.\n\t\\begin{example}\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{matrix}\n\t\t\t$$\\begin{matrix}a&b\\\\c&d\\\\\\end{matrix}$$\n\t\t\\end{minipage}\n\t\t\\hfill\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{bmatrix}\n\t\t\t$$\\begin{bmatrix}a&b\\\\c&d\\\\\\end{bmatrix}$$\n\t\t\\end{minipage}\n\t\t\\hfill\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{vmatrix}\n\t\t\t$$\\begin{vmatrix}a&b\\\\c&d\\\\\\end{vmatrix}$$\n\t\t\\end{minipage}\n\t\t\\vfill\n\t\t\\ \\\\[1em]\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{pmatrix}\n\t\t\t$$\\begin{pmatrix}a&b\\\\c&d\\\\\\end{pmatrix}$$\n\t\t\\end{minipage}\n\t\t\\hfill\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{Bmatrix}\n\t\t\t$$\\begin{Bmatrix}a&b\\\\c&d\\\\\\end{Bmatrix}$$\n\t\t\\end{minipage}\n\t\t\\hfill\n\t\t\\begin{minipage}{0.3\\linewidth}\n\t\t\t\\centering \\packagename{Vmatrix}\n\t\t\t$$\\begin{Vmatrix}a&b\\\\c&d\\\\\\end{Vmatrix}$$\n\t\t\\end{minipage}\n\t\\end{example}\n\t\nSome packages may also help simplify the typesetting of matrix, for example, there is some macros defined in the \\packagename{physics} package to make identity matrix, or generate the examples above more simply. \n\t\n\\end{frame}\n\n\\begin{frame}[fragile]\nIf you need to create matrices with different delimiters, you can add them manually to a plain matrix. For example:\n\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\left\\lceil\n  \\begin{matrix}\n    1 & 2 & 3 \\\\\n    a & b & c\n    \\end{matrix}\n  \\right\\rceil\n\\end{equation}\n\n\\begin{equation}\n  \\left\\langle\n  \\begin{matrix}\n    1 & 2 & 3 \\\\\n    a & b & c\n  \\end{matrix}\n  \\right\\rangle\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{smallmatrix} Environment}\nWhen typesetting inline math, the usual \\packagename{matrix} environments above may look too big. It may be better to use \\packagename{smallmatrix} in such situations, although you will need to provide your own delimiters.\n\n\\begin{latexexample}\nTrying to typeset an inline matrix here\n$\\begin{pmatrix}\n  a & b \\\\ \n  c & d\n\\end{pmatrix}$ \nbut it looks too big, so let's try \n$\\big(\\begin{smallmatrix}\n  a & b \\\\\n  c & d\n\\end{smallmatrix}\\big)$ instead.\n\\end{latexexample}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{The \\packagename{array} Environment}\nAn \\packagename{array} environment is actually a math mode \\packagename{tabular} environment, and the usage of them are almost the same. You can refer to the lecture about tables for this part. \\medskip\n\nA simple example is given here:\n\\begin{latexexamplesplit}[0.4]\n\\begin{equation}\n  \\chi(\\lambda) = \n  \\left| \\begin{array}{ccc}\n    \\lambda - a & -b & -c \\\\\n    -d & \\lambda - e & -f \\\\\n    -g & -h & \\lambda - i \n  \\end{array} \\right|\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\n\\section{Useful Maths Packages}\n\n\\subsection{Common Packages}\n\n\\begin{frame}[fragile]{The \\packagename{AMS-\\LaTeX} Packages}\nAMS-\\LaTeX\\ is a collection of \\LaTeX\\ document classes and packages developed for the American Mathematical Society (AMS). \\medskip\n\nIt is an extension of plain-\\LaTeX\\ maths, with many new maths environments (most of them were introduced in the previous section), maths symbols and maths fonts. \\medskip\n\nUsually you can insert all of the commands in the preamble of your document.\n\n\\begin{command}\n\\begin{LCL}\n\\usepackage{amsmath}  % loads maths environments\n\\usepackage{amssymb}  % loads maths symbols\n\\usepackage{amsfonts} % loads maths fonts\n\\end{LCL}\n\\end{command}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Some Other Packages}\n\nRecall that we also use some other packages in this lecture:\n\n\\begin{command}\n\\begin{LCL}\n\\usepackage{esint}    % for cyclic integrals\n\\usepackage{relsize}  % for \\mathlarger\n\\end{LCL}\n\\end{command}\n\nFor a better \\packagename{array} environment, though it's not mandatory (you can use it without the package), you're recommended to add the \\packagename{array} package.\n\n\\begin{command}\n\\begin{LCL}\n\\usepackage{array}\n\\end{LCL}\n\\end{command}\n\n\\end{frame}\n\n\\subsection{The \\packagename{physics} Package}\n\n\\begin{frame}[fragile]{The \\packagename{physics} Package}\n\nTo use the \\packagename{physics} package, simply insert the command in the preamble of your document.\n\n\\begin{command}\n\\begin{minted}{latex}\n\\usepackage{physics}\n\\end{minted}\n\\end{command}\n\nThe goal of this package is to make typesetting equations for \\packagename{physics} simpler, faster, and more human-readable. But it can also be used in various maths circumstances. \\medskip\n\nTo that end, the commands included in this package have names that make the purpose of each\ncommand immediately obvious and remove any ambiguity while reading and editing \\packagename{physics} code. \\medskip\n\nThe documentation of the \\packagename{physics} package can be found in \\url{http://mirrors.ctan.org/macros/latex/contrib/physics/physics.pdf}.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nRecall the equation:\n\\inputminted{latex}{../examples/curl.tex}\n\nNow we can rewrite it with the commands defined in the \\packagename{physics} package.\n\n\\begin{latexexample}\n\\begin{equation}\n  \\mathop{\\rm rot}F=\\qty(\\pdv{F_z}{y}-\\pdv{F_y}{z})\\hat{n_x}+\n                    \\qty(\\pdv{F_x}{z}-\\pdv{F_z}{x})\\hat{n_y}+\n                    \\qty(\\pdv{F_y}{x}-\\pdv{F_x}{y})\\hat{n_z}\n\\end{equation}\n\\end{latexexample}\n\n\\end{frame}\n\n\n% copy from physics package docs\n\\newcommand\\Vtextvisiblespace[1][.3em]\n{%\n\t\\mbox{\\kern.06em\\vrule height.3ex}%\n\t\\vbox{\\hrule width#1}%\n\t\\hbox{\\vrule height.3ex}\n}\n\\newcommand{\\cbox}[2][cyan]\n{\\mathchoice\n\t{\\setlength{\\fboxsep}{0pt}\\colorbox{#1}{$\\displaystyle#2$}}\n\t{\\setlength{\\fboxsep}{0pt}\\colorbox{#1}{$\\textstyle#2$}}\n\t{\\setlength{\\fboxsep}{0pt}\\colorbox{#1}{$\\scriptstyle#2$}}\n\t{\\setlength{\\fboxsep}{0pt}\\colorbox{#1}{$\\scriptscriptstyle#2$}}\n}\n\\newcommand{\\typical}{\\cbox{\\phantom{A}}}\n\\newcommand{\\tall}{\\cbox{\\phantom{A^{\\vphantom{x^x}}_x}}}\n\\newcommand{\\grande}{\\cbox{\\phantom{\\frac{1}{xx}}}}\n\\newcommand{\\venti}{\\cbox{\\phantom{\\sum_x^x}}}\n\n\\begin{frame}[fragile]{Automatic Bracing}\n\nWhen typesetting maths equations, you may use something like \\LC{\\left(} and \\LC{\\right)} to make the braces taller than the typical ones. The \\packagename{physics} package provides some macros to simplify and replace them. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\quantity| & \\LCS|\\qty(\\typical)| $\\displaystyle\\rightarrow \\qty(\\typical)$ & automatic $\\qty(\\;)$ braces \\\\\n& \\LCS|\\qty(\\tall)| $\\displaystyle\\rightarrow \\qty(\\tall)$ & \\\\\n& \\LCS|\\qty(\\grande)| $\\displaystyle\\rightarrow \\qty(\\grande)$ & \\\\\n& \\LCS|\\qty[\\typical]| $\\rightarrow \\qty[\\typical]$ & automatic $\\qty[\\;]$ braces \\\\[2pt]\n& \\LCS+\\qty|\\typical|+ $\\rightarrow \\qty|\\typical|$ & automatic $\\qty|\\;|$ braces \\\\[2pt]\n& \\LCS|\\qty{\\typical}| $\\rightarrow \\qty{\\typical}$ & automatic $\\qty{\\;}$ braces \\\\[2pt]\n& \\LCS|\\qty\\big{}| $\\rightarrow \\qty\\big{}$ & \\multirow{2}{*}{\\parbox{4cm}{manual sizing (works with any of the above bracket types)}} \\\\\n& \\LCS|\\qty\\Big{}| $\\rightarrow \\qty\\Big{}$ & \\\\\n& \\LCS|\\qty\\bigg{}| $\\rightarrow \\qty\\bigg{}$ & \\\\\n& \\LCS|\\qty\\Bigg{}| $\\rightarrow \\qty\\Bigg{}$ & \\\\\n& \\LCS|\\pqty{}| $\\leftrightarrow$ \\LCS|\\qty()| & \\multirow{2}{*}{\\parbox{4cm}{alternative syntax; robust and more \\LaTeX-friendly}} \\\\[2pt]\n& \\LCS|\\bqty{}| $\\leftrightarrow$ \\LCS|\\qty[]| & \\\\[2pt]\n& \\LCS+\\vqty{}+ $\\leftrightarrow$ \\LCS+\\qty||+ & \\\\[2pt]\n& \\LCS|\\Bqty{}| $\\leftrightarrow$ \\LCS|\\qty{}| & \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\absolutevalue| & \\LCS|\\abs{a}| $\\rightarrow \\abs{a}$ & automatic sizing; equivalent to \\LCS|\\qty| \\!\\!\\texttt{|a|} \\\\\n& \\LCS|\\abs\\Big{a}| $\\rightarrow \\abs\\Big{a}$ & inherits manual sizing syntax from \\LCS|\\qty| \\\\\n& \\LCS|\\abs*{\\grande}| $\\displaystyle\\rightarrow \\abs*{\\grande}$ & star for no resize \\\\\n\\LCS|\\norm| & \\LCS|\\norm{a}| $\\rightarrow \\norm{a}$ & automatic sizing \\\\\n& \\LCS|\\norm\\Big{a}| $\\rightarrow \\norm\\Big{a}$ & manual sizing \\\\\n& \\LCS|\\norm*{\\grande}| $\\displaystyle\\rightarrow \\norm*{\\grande}$ & star for no resize \\\\\n\\LCS|\\evaluated| & \\LCS|\\eval{x}_0^\\infty| $\\displaystyle\\rightarrow \\eval{x}_0^\\infty$ & vertical bar for evaluation limits \\\\\n& \\LCS|\\eval(x| \\!\\!\\texttt{|}\\!\\! \\LCS|_0^\\infty| $\\displaystyle\\rightarrow \\eval(x|_0^\\infty$ & alternate form \\\\\n& \\LCS|\\eval[x| \\!\\!\\texttt{|}\\!\\! \\LCS|_0^\\infty| $\\displaystyle\\rightarrow \\eval[x|_0^\\infty$ & alternate form \\\\\n& \\LCS|\\eval[\\venti| \\!\\!\\texttt{|}\\!\\! \\LCS|_0^\\infty| $\\displaystyle\\rightarrow \\eval[\\venti|_0^\\infty$ & automatic sizing\\\\\n& \\LCS|\\eval*[\\venti| \\!\\!\\texttt{|}\\!\\! \\LCS|_0^\\infty| $\\displaystyle\\rightarrow \\eval*[\\venti|_0^\\infty$ & star for no resize \\\\\n\\LCS|\\order| & \\LCS|\\order{x^2}| $\\rightarrow \\order{x^2}$ & order symbol; automatic sizing and space handling \\\\\n& \\LCS|\\order\\Big{x^2}| $\\rightarrow \\order\\Big{x^2}$ & manual sizing \\\\\n& \\LCS|\\order*{\\grande}| $\\displaystyle\\rightarrow \\order*{\\grande}$ & star for no resize \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Vector Notation}\n\nYou may use \\LC|\\mathbf| to make bold maths symbols, However, it won't always work. For example, with \\LC|\\mathbf{\\alpha}| you may have $\\mathbf{\\alpha}$, which is actually not bold. These commands will help provide the correct $\\vb*{\\alpha}$. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\vectorbold| & \\LCS|\\vb{a}| $\\rightarrow \\vb{a}$ & upright/no Greek \\\\\n& \\LCS|\\vb*{a}|, \\LCS|\\vb*{\\theta}| $\\rightarrow \\vb*{a}$, $\\vb*{\\theta}$ & italic/Greek \\\\\n\\LCS|\\vectorarrow| & \\LCS|\\va{a}| $\\rightarrow \\va{a}$ & upright/no Greek \\\\\n& \\LCS|\\va*{a}|, \\LCS|\\va*{\\theta}| $\\rightarrow \\va*{a}$, $\\va*{\\theta}$ & italic/Greek \\\\\n\\LCS|\\vectorunit| & \\LCS|\\vu{a}| $\\rightarrow \\vu{a}$ & upright/no Greek \\\\\n& \\LCS|\\vu*{a}|, \\LCS|\\vu*{\\theta}| $\\rightarrow \\vu*{a}$, $\\vu*{\\theta}$ & italic/Greek \\\\\n\\end{tabular}\\bigskip\n\n\\normalsize\nThere are also some shorthand for vector operations. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\dotproduct| & \\LCS|\\vdot| $\\rightarrow \\vdot$ as in $\\vb{a} \\vdot \\vb{b}$ & note: \\LCS|\\dp| is a protected \\TeX\\ primitive \\\\\n\\LCS|\\crossproduct| & \\LCS|\\cross| $\\rightarrow \\cross$ as in $\\vb{a} \\cross \\vb{b}$ & alternate name \\\\\n& \\LCS|\\cp| $\\rightarrow \\cp$ as in $\\vb{a} \\cp \\vb{b}$ & shorthand name \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\n\\begin{frame}[fragile]\n\nThe default del (nabla) symbol $\\vnabla$ used in \\packagename{physics} vector notation can be switched to appear with an arrow $\\vec{\\vnabla}$ by including the option \\packagename{arrowdel} in the document preamble $\\rightarrow$ \\LC|\\usepackage[arrowdel]{physics}|. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\divergence| & \\LCS|\\div| $\\rightarrow \\div$ & note: \\packagename{amsmath} symbol $\\divisionsymbol$ renamed \\LCS|\\divisionsymbol| \\\\\n& \\LCS|\\div{\\vb{a}}| $\\rightarrow \\div{\\vb{a}}$ & default mode \\\\\n& \\LCS|\\div(\\vb{a}+\\tall)| $\\displaystyle\\rightarrow \\div(\\vb{a}+\\tall)$ & long-form \\\\\n& \\LCS|\\div[\\vb{a}+\\tall]| $\\displaystyle\\rightarrow \\div[\\vb{a}+\\tall]$ & \\\\[5pt]\n\\LCS|\\curl| & \\LCS|\\curl| $\\rightarrow \\curl$ & $\\phantom{\\tall}$ \\\\ \n& \\LCS|\\curl{\\vb{a}}| $\\rightarrow \\curl{\\vb{a}}$ & default mode $\\phantom{\\tall}$ \\\\\n& \\LCS|\\curl(\\vb{a}+\\tall)| $\\displaystyle\\rightarrow \\curl(\\vb{a}+\\tall)$ & long-form \\\\\n& \\LCS|\\curl[\\vb{a}+\\tall]| $\\displaystyle\\rightarrow \\curl[\\vb{a}+\\tall]$ & \\\\[5pt]\n\\LCS|\\laplacian| & \\LCS|\\laplacian| $\\rightarrow \\laplacian$ & $\\phantom{\\tall}$ \\\\\n& \\LCS|\\laplacian{\\Psi}| $\\rightarrow \\laplacian{\\Psi}$ & default mode $\\phantom{\\tall}$ \\\\\n& \\LCS|\\laplacian(\\Psi+\\tall)| $\\displaystyle\\rightarrow \\laplacian(\\Psi+\\tall)$ & long-form \\\\\n& \\LCS|\\laplacian[\\Psi+\\tall]| $\\displaystyle\\rightarrow \\laplacian[\\Psi+\\tall]$ & \n\\end{tabular}\n\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Operators}\nThe standard set of trig functions is redefined in \\packagename{physics} to provide automatic braces that behave like \\LC|\\qty()|. In addition, an optional power argument is provided. This behavior can be switched off by including the option \\packagename{notrig} in the preamble $\\rightarrow$ \\LC|\\usepackage[notrig]{physics}|. \\medskip\n\nFor example,\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\sin| & \\LCS|\\sin(\\grande)| $\\displaystyle\\rightarrow \\sin(\\grande)$ & automatic braces; old \\LCS|\\sin| renamed \\LCS|\\sine| \\\\\n& \\LCS|\\sin[2](x)| $\\rightarrow \\sin[2](x)$ & optional power \\\\\n& \\LCS|\\sin x| $\\rightarrow \\sin x$ & can still use without an argument\n\\end{tabular}\\medskip\n\n\\normalsize\nSimilar behavior has also been extended to the following functions: \\medskip\n\n\\scriptsize\n\\begin{tabular}{ p{2cm} p{1.6cm} p{3cm} p{4cm} }\n\\LCS|\\exp(\\tall)| & $\\exp(\\tall)$ & & \\LCS|\\exponential| \\\\\n\\LCS|\\log(\\tall)| & $\\log(\\tall)$ & & \\LCS|\\logarithm| \\\\\n\\LCS|\\ln(\\tall)| & $\\ln(\\tall)$ & old definitions $\\Rightarrow$ & \\LCS|\\naturallogarithm| \\\\\n\\LCS|\\det(\\tall)| & $\\det(\\tall)$ & & \\LCS|\\determinant| \\\\\n\\LCS|\\Pr(\\tall)| & $\\Pr(\\tall)$ & & \\LCS|\\Probability|\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nThere are also some new operators: \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2cm} p{5cm} p{4cm} }\n\\LCS|\\trace| or \\LCS|\\tr| & \\LCS|\\tr\\rho| $\\rightarrow \\tr\\rho$ also \\LCS|\\tr(\\tall)| $\\rightarrow \\tr(\\tall)$  & trace; same bracing as trig functions \\\\\n\\LCS|\\Trace| or \\LCS|\\Tr| & \\LCS|\\Tr\\rho| $\\rightarrow \\Tr\\rho$ & alternate \\\\[5pt]\n\\LCS|\\rank| & \\LCS|\\rank M| $\\rightarrow \\rank M$ & matrix rank \\\\[5pt]\n\\LCS|\\erf| & \\LCS|\\erf(x)|$\\rightarrow \\erf(x)$ & Gauss error function \\\\[5pt]\n\\LCS|\\Res| & \\LCS|\\Res[f(z)]|$\\rightarrow \\Res[f(z)]$ & residue; same bracing as trig functions \\\\[5pt]\n\\LCS|\\principalvalue| & \\LCS|\\pv{\\int f(z) \\dd{z}}|$\\rightarrow \\pv{\\int f(z) \\dd{z}}$ & Cauchy principal value \\\\ \n& \\LCS|\\PV{\\int f(z) \\dd{z}}|$\\rightarrow \\PV{\\int f(z) \\dd{z}}$ & alternate \\\\[5pt]\n\\LCS|\\Re| & \\LCS|\\Re{z}| $\\rightarrow \\Re{z}$ & old \\LCS|\\Re| renamed to \\LCS|\\real| $\\rightarrow \\real$ \\\\\n\\LCS|\\Im| & \\LCS|\\Im{z}| $\\rightarrow \\Im{z}$ & old \\LCS|\\Im| renamed to \\LCS|\\imaginary| $\\rightarrow \\imaginary$\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Quick Quad Text}\n\nThis set of commands produces text in math-mode padded by \\LC|\\quad| spacing on either side. This is meant to provide a quick way to insert simple words or phrases in a sequence of equations. Each of the following commands includes a starred version which pads the text only on the right side with \\LC|\\quad| for use in aligned environments such as \\packagename{cases}. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.75cm} p{3cm} p{5cm} }\n\\LCS|\\qqtext| & \\LCS|\\qq{}| & general quick quad text with argument \\\\\n& \\LCS|\\qq{word or phrase}| $\\rightarrow$ \\Vtextvisiblespace[1em]$\\text{word or phrase}$\\Vtextvisiblespace[1em] & normal mode; left and right \\LCS|\\quad| \\\\\n& \\LCS|\\qq*{word or phrase}| $\\rightarrow \\text{word or phrase}$\\Vtextvisiblespace[1em] & starred mode; right \\LCS|\\quad| only\n\\end{tabular}\\bigskip\n\n\\normalsize\nSome special macros: \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.75cm}  p{7cm} }\n\\LCS|\\qcomma| or \\LCS|\\qc| $\\rightarrow ,$\\Vtextvisiblespace[1em] & right \\LCS|\\quad| only \\\\\n\\LCS|\\qcc| $\\rightarrow$\\Vtextvisiblespace[1em]$\\text{c.c.}$\\Vtextvisiblespace[1em] & complex conjugate; left and right \\LCS|\\quad| unless starred \\LCS|\\qcc*| $\\rightarrow \\text{c.c.}$\\Vtextvisiblespace[1em] \\\\\n\\LCS|\\qif| $\\rightarrow$\\Vtextvisiblespace[1em]$\\text{if}$\\Vtextvisiblespace[1em] & left and right \\LCS|\\quad| unless starred \\LCS|\\qif*| $\\rightarrow \\text{if}$\\Vtextvisiblespace[1em]\n\\end{tabular}\\medskip\n\n\\begin{tabular}[l]{ l }\n\\LCS|\\qthen|, \\LCS|\\qelse|, \\LCS|\\qotherwise|, \\LCS|\\qunless|, \\LCS|\\qgiven|, \\LCS|\\qusing|, \\LCS|\\qassume|, \\LCS|\\qsince|, \\\\\n\\LCS|\\qlet|, \\LCS|\\qfor|, \\LCS|\\qall|, \\LCS|\\qeven|, \\LCS|\\qodd|, \\LCS|\\qinteger|, \\LCS|\\qand|, \\LCS|\\qor|, \\LCS|\\qas|, \\LCS|\\qin|\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Derivatives}\n\nThe default differential symbol $\\dd$ which is used in \\LC|\\differential| and \\LC|\\derivative| can be switched to an italic form $d$ by including the option \\packagename{italicdiff} in the preamble $\\rightarrow$ \\LC|\\usepackage[italicdiff]{physics}|. \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.75cm} p{4cm} p{4.25cm} }\n\\LCS|\\differential| & \\LCS|\\dd| $\\rightarrow \\dd$ & \\\\[2pt]\n& \\LCS|\\dd x| $\\rightarrow \\dd x$ & no spacing (not recommended) \\\\\n& \\LCS|\\dd{x}| $\\rightarrow$ \\textvisiblespace\\,$\\dd{x}$\\textvisiblespace & automatic spacing based on neighbors \\\\\n& \\LCS|\\dd[3]{x}| $\\rightarrow \\dd[3]{x}$ & optional power \\\\[2pt]\n& \\LCS|\\dd(\\cos\\theta)| $\\rightarrow \\dd(\\cos\\theta)$ & long-form; automatic braces \\\\\n\\LCS|\\derivative| & \\LCS|\\dv{x}| $\\displaystyle\\rightarrow \\dv{x}$ & one argument \\\\\n& \\LCS|\\dv{f}{x}| $\\displaystyle\\rightarrow \\dv{f}{x}$ & two arguments \\\\\n& \\LCS|\\dv[n]{f}{x}| $\\displaystyle\\rightarrow \\dv[n]{f}{x}$ & optional power \\\\\n& \\LCS|\\dv{x}(\\grande)| $\\displaystyle\\rightarrow \\dv{x}(\\grande)$ & long-form; automatic braces, spacing \\\\\n& \\LCS|\\dv*{f}{x}| $\\displaystyle\\rightarrow \\dv*{f}{x}$ & inline form using \\LCS|\\flatfrac| \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.75cm} p{4cm} p{4.25cm} }\n\\LCS|\\partialderivative| & \\LCS|\\pderivative{x}| $\\displaystyle\\rightarrow \\pderivative{x}$ & alternate name \\\\\n& \\LCS|\\pdv{x}| $\\displaystyle\\rightarrow \\pdv{x}$ & shorthand name \\\\\n& \\LCS|\\pdv{f}{x}| $\\displaystyle\\rightarrow \\pdv{f}{x}$ & two arguments \\\\\n& \\LCS|\\pdv[n]{f}{x}| $\\displaystyle\\rightarrow \\pdv[n]{f}{x}$ & optional power \\\\\n& \\LCS|\\pdv{x}(\\grande)| $\\displaystyle\\rightarrow \\pdv{x}(\\grande)$ & long-form \\\\\n& \\LCS|\\pdv{f}{x}{y}| $\\displaystyle\\rightarrow \\pdv{f}{x}{y}$ & mixed partial \\\\[5pt]\n& \\LCS|\\pdv*{f}{x}| $\\displaystyle\\rightarrow \\pdv*{f}{x}$ & inline form using \\LCS|\\flatfrac| \\\\[5pt]\n\\LCS|\\variation| & \\LCS|\\var{F[g(x)]}| $\\rightarrow \\var{F[g(x)]}$ & functional variation (works like \\LCS|\\dd|) \\\\\n& \\LCS|\\var(E-TS)| $\\rightarrow \\var(E-TS)$ & long-form \\\\\n\\LCS|\\functionalderivative| & \\LCS|\\fdv{g}| $\\displaystyle\\rightarrow \\fdv{g}$ & functional derivative (works like \\LCS|\\dv|) \\\\\n& \\LCS|\\fdv{F}{g}| $\\displaystyle\\rightarrow \\fdv{F}{g}$ & \\\\\n& \\LCS|\\fdv{V}(E-TS)| $\\displaystyle\\rightarrow \\fdv{V}(E-TS)$ & long-form \\\\[5pt]\n& \\LCS|\\fdv*{F}{x}| $\\displaystyle\\rightarrow \\fdv*{F}{x}$ & inline form using \\LCS|\\flatfrac|\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]{Matrices}\n\nThe following matrix macros produce unformatted rows and columns of matrix elements for use as separate matrices as well as blocks within larger matrices. For example, the command \\LC|\\identitymatrix{2}| which has also has the shortcut \\LC|\\imat{2}| produces the elements of a $2 \\times 2$ identity matrix $\\smqty{\\imat{2}}$ without braces or grouping. This allows the command to also be used within another matrix, as in: \n\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\begin{pmatrix}\n    \\imat{2} \\\\ \n    a & b\n  \\end{pmatrix}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nTo specify elements on the right of left sides of our \\LC|\\imat{2}| sub-matrix we use the grouping command \\LC|\\matrixquantity| or \\LC|\\mqty| to effectively convert \\LC|\\imat{2}| into a single matrix element of a larger matrix:\n\n\\begin{latexexamplesplit}[0.6]\n\\begin{equation}\n  \\begin{pmatrix}\n    \\mqty{\\imat{2}} & \\mqty{a\\\\b} \\\\ \n    \\mqty{c & d}    & e\n  \\end{pmatrix}\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nThe extra \\LC|\\mqty| groups were required in this case in order to get the $a$ and $b$ elements to behave as a single element, since \\LC|\\mqty{\\imat{2}}| also acts like a single matrix element (the same can be said of the grouped $c$ and $d$ elements). Finally, the outermost \\texttt{pmatrix} environment could have also been replaced with the \\texttt{physics} macro \\LC|\\mqty()|, allowing the above example to be written on one line:\n\n\\begin{latexexamplesplit}[0.6]\n\\begin{equation}\n  \\mqty(\n    \\mqty{\\imat{2}} & \\mqty{a\\\\b} \\\\ \n    \\mqty{c & d}    & e\n  )\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nThe matrix commands are listed below: \\medskip\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.25cm} p{5.25cm} p{3.5cm} }\n\\LCS|\\matrixquantity| & \\LCS|\\mqty{a & b \\\\ c & d}| $\\displaystyle\\rightarrow \\mqty{a & b \\\\ c & d}$ & groups a set of matrix elements into a single object \\\\\n& \\LCS|\\mqty(a & b \\\\ c & d)| $\\displaystyle\\rightarrow {\\mqty(a & b \\\\ c & d)}$ & parentheses \\\\\n& \\LCS|\\mqty*(a & b \\\\ c & d)| $\\displaystyle\\rightarrow {\\mqty*(a & b \\\\ c & d)}$ & alternate parentheses \\\\\n& \\LCS|\\mqty[a & b \\\\ c & d]| $\\displaystyle\\rightarrow {\\mqty[a & b \\\\ c & d]}$ & square brackets \\\\\n& \\LCS+\\mqty|a & b \\\\ c & d|+ $\\displaystyle\\rightarrow {\\mqty|a & b \\\\ c & d|}$ & vertical bars \\\\\n& \\LCS|\\pmqty{}| $\\leftrightarrow$ \\LCS|\\mqty()| & \\multirow{2}{*}{\\parbox{3.5cm}{alternative syntax; robust and more \\LaTeX-friendly}} \\\\\n& \\LCS|\\Pmqty{}| $\\leftrightarrow$ \\LCS|\\mqty*()| & \\\\\n& \\LCS|\\bmqty{}| $\\leftrightarrow$ \\LCS|\\mqty[]| & \\\\\n& \\LCS|\\vmqty{}| $\\leftrightarrow$ \\LCS+\\mqty||+ & \\\\\n\\LCS|\\smallmatrixquantity| & \\LCS|\\smqty{a & b \\\\ c & d}| $\\displaystyle\\rightarrow \\smqty{a & b \\\\ c & d}$ & the \\packagename{smallmatrix} form of \\LCS|\\mqty| \\\\\n& \\LCS|\\smqty()| or \\LCS|\\spmqty{}| & small version of \\LCS|\\mqty()| \\\\\n& \\LCS|\\smqty*()| or \\LCS|\\sPmqty{}| & small version of \\LCS|\\mqty*()|\\\\\n& \\LCS|\\smqty[]| or \\LCS|\\sbmqty{}| & small version of \\LCS|\\mqty[]| \\\\\n& \\LCS+\\smqty||+ or \\LCS|\\svmqty{}| & small version of \\LCS+\\mqty||+ \\\\\n\\LCS|\\matrixdeterminant| & \\LCS|\\mdet{a & b \\\\ c & d}| $\\displaystyle\\rightarrow {\\mdet{a & b \\\\ c & d}}$ & matrix determinant \\\\\n& \\LCS|\\smdet{a & b \\\\ c & d}| $\\displaystyle\\rightarrow {\\smdet{a & b \\\\ c & d}}$ & small matrix determinant \\\\\n\\LCS|\\identitymatrix| & \\LCS|\\imat{n}| & elements of $n \\times n$ identity matrix \\\\\n& \\LCS|\\smqty(\\imat{3})| $\\displaystyle\\rightarrow \\smqty(\\imat{3})$ & formatted with \\LCS|\\mqty| or \\LCS|\\smqty| \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\n\\scriptsize\n\\begin{tabular}[l]{ p{2.25cm} p{5.25cm} p{3.5cm} }\n\\LCS|\\xmatrix| & \\LCS|\\xmat{x}{n}{m}| & elements of $n \\times m$ matrix filled with $x$ \\\\\n& \\LCS|\\smqty(\\xmat{1}{2}{3})| $\\displaystyle\\rightarrow \\smqty(\\xmat{1}{2}{3})$ & formatted with \\LCS|\\mqty| or \\LCS|\\smqty| \\\\\n& \\LCS|\\smqty(\\xmat*{a}{3}{3})| $\\displaystyle\\rightarrow \\smqty(\\xmat*{a}{3}{3})$ & star for element indices \\\\\n& \\LCS|\\smqty(\\xmat*{a}{3}{1})| $\\displaystyle\\rightarrow \\smqty(\\xmat*{a}{3}{1})$ & as a vector with indices \\\\\n& \\LCS|\\smqty(\\xmat*{a}{1}{3})| $\\displaystyle\\rightarrow \\smqty(\\xmat*{a}{1}{3})$ & \\\\\n\\LCS|\\zeromatrix| & \\LCS|\\zmat{n}{m}| & $n \\times m$ matrix filled with zeros \\\\\n& \\LCS|\\smqty(\\zmat{2}{2})| $\\displaystyle\\rightarrow \\smqty(\\zmat{2}{2})$ & equivalent to \\LCS|\\xmat{0}{n}{m}| \\\\\n\\LCS|\\paulimatrix| & \\LCS|\\pmat{n}| & $n^\\text{th}$ Pauli matrix \\\\\n& \\LCS|\\smqty(\\pmat{0})| $\\displaystyle\\rightarrow \\smqty(\\pmat{0})$ & $n\\in \\lbrace 0,1,2,3$ or $x,y,z \\rbrace$ \\\\\n& \\LCS|\\smqty(\\pmat{1})| $\\displaystyle\\rightarrow \\smqty(\\pmat{1})$ & \\\\\n& \\LCS|\\smqty(\\pmat{2})| $\\displaystyle\\rightarrow \\smqty(\\pmat{2})$ & \\\\\n& \\LCS|\\smqty(\\pmat{3})| $\\displaystyle\\rightarrow \\smqty(\\pmat{3})$ & \\\\\n\\LCS|\\diagonalmatrix| & \\LCS|\\dmat{a,b,c,...}| & \\multirow{2}{*}{\\parbox{3.5cm}{specify up to eight diagonal or block diagonal elements}} \\\\\n& \\LCS|\\mqty(\\dmat{1,2,3})| $\\displaystyle\\rightarrow \\mqty(\\dmat{1,2,3})$ & \\\\\n& \\LCS|\\mqty(\\dmat[0]{1,2})| $\\displaystyle\\rightarrow \\mqty(\\dmat[0]{1,2})$ & optional argument to fill spaces \\\\\n& \\LCS|\\mqty(\\dmat{1,2&3\\\\4&5})| $\\displaystyle\\rightarrow \\mqty(\\dmat{1,2&3\\\\4&5})$ & \\parbox{3.5cm}{enter matrix elements for each block as a single diagonal element} \\\\\n\\LCS|\\antidiagonalmatrix| & \\LCS|\\admat{a,b,c,...}| & same as syntax as \\LCS|\\dmat| \\\\\n& \\LCS|\\mqty(\\admat{1,2,3})| $\\displaystyle\\rightarrow \\mqty(\\admat{1,2,3})$ & \\\\\n\\end{tabular}\n\n\\end{frame}\n\n\n\\subsection{The \\packagename{systeme} Package}\n\n\\begin{frame}[fragile]{The \\packagename{systeme} Package}\n\nTo use the \\packagename{systeme} package, simply insert the command in the preamble of your document.\n\n\\begin{command}\n\\begin{minted}{latex}\n\\usepackage{systeme}\n\\end{minted}\n\\end{command}\n\nThis package can make it really easy when typesetting linear systems by the command \\LC|\\systeme|.\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\systeme{\n    2a-3b+4c=2,\n    a+8b+5c=8,\n    -a+2b+c=-5\n  }\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nIt also works for subscripts.\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\systeme{\n    4x_1-x_2=3,\n    -x_1+5x_2=-1\n  }\n\\end{equation}\n\\end{latexexamplesplit}\n\nIt can also reorder the variables and numbers in the equations.\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\systeme{\n    3y+2x=0,\n    x-z+9=0,\n    2+3x+5-y-7+z=0\n  }\n\\end{equation}\n\\end{latexexamplesplit}\n\n\\end{frame}\n\n\\begin{frame}[fragile]\n\nComplicated coefficients can be handle correctly. Note that \\LC{+} and \\LC{-} should be replaced with \\LC{\\+} and \\LC{\\-} in the coefficients.\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\systeme{\n    (2\\+\\sqrt{2})x-\n    (1\\-\\sqrt{2})y=1,\n    x+(1\\+\\sqrt{2})y=-1\n  }\n\\end{equation}\n\\end{latexexamplesplit}\n\nThe documentation of the \\packagename{systeme} package can be found in \\url{http://mirrors.ctan.org/macros/generic/systeme/systeme_fr.pdf}, however it's in French, and the author is \\structure{Manuel de l'utilisateur}.\n\n\\end{frame}\n\n\\subsection{The \\packagename{gauss} Package}\n\n\\begin{frame}[fragile]{The \\packagename{gauss} Package}\n\nTo use the \\packagename{gauss} package, simply insert the command in the preamble of your document.\n\n\\begin{command}\n\\begin{minted}{latex}\n\\usepackage{gauss}\n\\end{minted}\n\\end{command}\n\nThis package provides \\LaTeX-macros for typesetting operations on a\nmatrix. By an ``operation on a matrix'' we understand a row operation\nor a column operation. It is named \\packagename{gauss} because \\structure{Gauss Elimination} is a widely used application of matrix operations. \\medskip\n\nThe documentation of the \\packagename{systeme} package can be found in \\url{http://mirrors.ctan.org/macros/latex/contrib/gauss/gauss-doc.pdf}.\n\n\\end{frame}\n\n\\begin{frame}[fragile]\nFor example, if you are taking VV285 or working with other linear algebra stuffs in \\LaTeX, you may use the \\packagename{gmatrix} environment provided by the \\packagename{gauss} package.\n\n\\begin{latexexamplesplit}\n\\begin{equation}\n  \\begin{array}{ccc|}\n    4 & 2 & -2 \\\\\n    -3 & 1 & 0 \\\\\n    1 & 4 & 2\n  \\end{array}\n  \\begin{gmatrix}\n    -2 \\\\ 6 \\\\ -9\n    \\rowops\n    \\swap{0}{2}\n    \\add[*(3)]{0}{1}\n  \\end{gmatrix}\n\\end{equation}\n\\end{latexexamplesplit}\n\\end{frame}\n\n\n", "meta": {"hexsha": "608e6cb716ba7f616959197b9fa4c4d28547a2b0", "size": 55839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture/c3/main.tex", "max_stars_repo_name": "SJTU-UMJI-Tech/LaTeX", "max_stars_repo_head_hexsha": "79ff2b3791e075430af16ed49309ff741aa7e7a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2017-03-21T10:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T03:12:52.000Z", "max_issues_repo_path": "lecture/c3/main.tex", "max_issues_repo_name": "SJTU-UMJI-Tech/LaTeX", "max_issues_repo_head_hexsha": "79ff2b3791e075430af16ed49309ff741aa7e7a1", "max_issues_repo_licenses": ["MIT"], "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/c3/main.tex", "max_forks_repo_name": "SJTU-UMJI-Tech/LaTeX", "max_forks_repo_head_hexsha": "79ff2b3791e075430af16ed49309ff741aa7e7a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-03-24T07:34:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T03:21:16.000Z", "avg_line_length": 39.1577840112, "max_line_length": 496, "alphanum_fraction": 0.6909328605, "num_tokens": 18770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6032765489440136}}
{"text": "\\subsection{Problem Formulation and Solution}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[t]\n\n\\begin{defn}[Stochastic Forward Problem (SFP)]\\label{defn:forward-problem}\n  Given a probability measure $\\PP_\\pspace$ on $(\\pspace, \\pborel)$, and QoI map $\\qoi$, the \\emph{stochastic forward problem} is to determine a measure, $\\PP_\\dspace$, on $(\\dspace, \\dborel)$ that satisfies\n  \\begin{equation}\\label{eq:forward-problem}\n    \\PP_\\dspace (E) = \\PP_\\pspace \\left ( \\qoi^{-1}(E) \\right ), \\; \\forall \\; E \\in \\dborel.\n  \\end{equation}\n\\end{defn}\n\n\\end{frame}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[t]\n\n\\begin{defn}[Stochastic Forward Problem (SFP)]\\label{defn:forward-problem}\n  Given a probability measure $\\PP_\\pspace$ on $(\\pspace, \\pborel)$, and QoI map $\\qoi$, the \\emph{stochastic forward problem} is to determine a measure, $\\PP_\\dspace$, on $(\\dspace, \\dborel)$ that satisfies\n  \\begin{equation}\\label{eq:forward-problem}\n    \\PP_\\dspace (E) = \\PP_\\pspace \\left ( \\qoi^{-1}(E) \\right ), \\; \\forall \\; E \\in \\dborel.\n  \\end{equation}\n\\end{defn}\n\n\\begin{defn}[Stochastic Inverse Problem (SIP)]\\label{defn:inverse-problem}\nGiven a probability measure, $\\PP_\\dspace$, on $(\\dspace, \\dborel)$ the \\emph{stochastic inverse problem} is to determine a probability measure, $\\PP_\\pspace$, on $(\\pspace, \\pborel)$ satisfying\n\\begin{equation}\\label{eq:inverse-problem}\n\\PP_\\pspace (\\qoi^{-1}(E)) = \\PP_\\dspace(E), \\; \\forall \\; E \\in \\mathcal{B}_\\dspace.\n\\end{equation}\n\\end{defn}\n\nEquation~\\eqref{eq:inverse-problem} is referred to as the \\emph{consistency condition}.\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}\n\n\\begin{defn}[Consistent Solution and Density]\\label{defn:consistent-solution}\n  If $\\PP_\\pspace$ or $\\PP_\\dspace$ absolutely continuous w.r.t $\\pmeas$ or $\\dmeas$, resp, then we write\n\n  \\begin{equation*}\n    \\pp_\\pspace := \\frac{d\\PP_\\pspace}{d\\pmeas} \\;\\text{ or }\\; \\pp_\\dspace := \\frac{d\\PP_\\dspace}{d\\dmeas}\n  \\end{equation*}\n  to denote the Radon-Nikodym derivatives of $\\PP_\\pspace$ and $\\PP_\\dspace$, resp.\n  \\bigskip\n\n  In such a case, we can rewrite \\eqref{eq:forward-problem} and \\eqref{eq:inverse-problem} using these pdfs:\n  \\begin{equation*}\n  \\PP_\\pspace (\\qoi^{-1}(E)) = \\int_{\\qoi^{-1}(E)} \\pp_\\pspace \\lam \\, d\\pmeas = \\int_E \\pp_\\dspace \\Q \\, d\\dmeas = \\PP_\\dspace(E)\n  \\end{equation*}\n\n\\end{defn}\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}\n\n\\begin{defn}[Initial Distribution]\\label{defn:initial}\n  When $\\PP_\\pspace$ in \\eqref{eq:forward-problem} quantifies the characterization of uncertainty in parameter variability before observations on QoI are taken into account, it is referred to as the \\emph{initial measure} $\\initialP$.\n\n  \\bigskip\n  Given a dominating $\\mu_\\pspace$ on $(\\pspace, \\pborel)$, the Radon-Nikodym derivative $\\initial$ w.r.t $\\pmeas$ is referred to as the \\emph{initial distribution}.\n\n\\end{defn}\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}\n\\begin{defn}[Predicted Distribution]\\label{defn:predicted}\n The \\emph{predicted distribution} is the push-forward of $\\initial$ under the map $\\qoi$, and is denoted as $\\predicted$.\n\n \\bigskip\n  Given as Radon-Nikodym derivative (w.r.t $\\dmeas$) of pushforward measure:\n\n \\begin{equation}\\label{eq:predicted}\n    \\predictedP (E) = \\initialP \\left ( \\qoi^{-1}(E) \\right ), \\; \\forall \\; E \\in \\dborel.\n  \\end{equation}\n\n\\end{defn}\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}\n\n\\begin{defn}[Observed Distribution]\\label{defn:observed}\nWhen $\\PP_\\dspace$ in \\eqref{eq:inverse-problem} quantifies the characterization of uncertainty in the QoI data, it is referred to as the \\emph{observed measure}, $\\observedP$.\n\n\\bigskip\nGiven a dominating $\\mu_\\dspace$ on $(\\dspace, \\dborel)$, the Radon-Nikodym derivative $\\observedP$ w.r.t. $\\dmeas$ is referred to as the  \\emph{observed distribution} $\\observed$.\n\n\\end{defn}\n\n\\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{\\it The one where we define the solution to the Stochastic Inverse Problem.}\n\nWe now have all of the definitions required for the \\emph{updated distribution} which solves the SIP:\n\n\\bigskip\n\\begin{equation}\\label{eq:updated-pdf}\n\t\\updated(\\param) := \\initial(\\param)\\frac{\\observed(Q(\\param))}{\\predicted(Q(\\param))}.\n\\end{equation}\n\n\\end{frame}\n\n%\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Summarizing}\n% \\begin{itemize}\n% \t\\item ``Push-forward'' \\textbf{initial} beliefs using $\\qoi$ to \\textbf{compare} to \\textbf{observed} (data)\n% \t\\item Solve forward problem to construct solution to inverse problem\n% \t\\item The push-forward density of $\\initial$ under the map $\\qoi$ is denoted by $\\predicted$\n%\n% \t\\begin{defn}[Predicted Density]\\label{defn:predicted}\n% \t\t$\\predicted$ is given as the Radon-Nikodym derivative (with respect to $\\mu_\\dspace$) of the push-forward probability measure defined by:\n% \t\t\\begin{equation}\\label{eq:pred}\n% \t\t\t\\predictedP (E)  = \\initialP \\left ( \\qoi^{-1}(E) \\right ), \\; \\forall \\; E \\in \\dborel.\n% \t\t\\end{equation}\n% \t\\end{defn}\n%\n% \\end{itemize}\n%\n% \\end{frame}\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{The Updated Density solves the SIP}\n% These definitions are combined to form the \\textbf{updated density}:\n% \\begin{equation}\\label{eq:up}\n% \\updated \\lam = \\initial \\lam \\frac{\\observed \\qlam }{\\predicted \\qlam }, \\; \\param, \\in \\pspace.\n% \\end{equation}\n%\n% \\begin{itemize}\n% \t\\item $\\observed$ and $\\predicted$ defined on $(\\dspace, \\dborel)$ are evaluated at $\\qlam$\n% \t\\item The map $\\qoi$ impacts the structure of the update\n% \t\\item $\\dspace$ itself depends on $\\qoi$\n% \t\\item Primary effort in solving for $\\updated$ (in \\eqref{eq:up}) requires constructing $\\predicted$\n% \t\\item This is because $\\initial$ and $\\observed$ are given \\emph{a priori} (often parametric)\n% \t\\item Updated derived through use of Disintegration Theorem in \\cite{BJW18a}\n% \t\\item Existence and Uniqueness given a \\emph{predictability assumption}\n% \\end{itemize}\n% \\end{frame}\n%\n%\n%\n% \\subsection{Properties and Assumptions of the Update}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}\n% \\begin{assumption}[Predictability Assumption]\\label{as:pred}\n% \tThe measure associated with $\\observed$ is absolutely continuous with respect to the measure associated with $\\predicted$.\n% \\end{assumption}\n%\n%\n% The requirement is guaranteed if the following is satisfied:\n%\n% \\begin{equation}\\label{eq:pred}\n% \t\\exists \\; C>0 \\text{ s.t. } \\observed (d) \\leq C \\predicted (d) \\text{ for a.e. } d\\in \\dspace,\n% \\end{equation}\n%\n% where $d = \\qlam$ for some $\\param \\in \\pspace$.\n% By \\cite{BJW18}, if \\eqref{as:pred} holds, we have:\n%\n% \\begin{theorem}[Existence and Uniqueness]\n% \tFor any set $A\\in \\pborel$, the solution $\\updatedP$ given defined by\n% \t\\begin{equation}\\label{eq:cb_sol}\n% \t\t\\updatedP (A) = \\int_\\dspace \\left (  \\int_{\\pspace \\in \\qoi^{-1}(d)}  \\initial\\param \\frac{\\observed(d)}{\\predicted(d)} \\, d\\mu_{\\pspace, d} \\param \\right ) \\, d\\mu_\\dspace(d), \\; \\forall \\; A \\in \\pborel\n% \t\\end{equation}\n%\n% \tis a consistent solution, and is unique up to choice of $\\initialP$ on $(\\pspace, \\pborel)$.\n% \\end{theorem}\n%\n% \\end{frame}\n%\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Stability}\n%\n% All the stability and convergence results presented are with respect to:\n% \\vspace{0.5in}\n%\n% \\begin{defn}{Total Variation / Statistical Distance}\n% \t\\begin{equation}\\label{eq:tv}\n% \t\td_{\\text{TV}} (\\PP_f, \\PP_g) := \\int \\abs{f - g} \\, d\\mu,\n% \t\\end{equation}\n% where $f,g$ are the densities (Radon-Nikodym derivatives with respect to $\\mu$) associated with measures $\\PP_f, \\PP_g$, respectively.\n% \\end{defn}\n%\n% \\end{frame}\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}\n%\n% \\begin{defn}[Stability of Updates I]\\label{defn:stableobs}\n% \tWe say that $\\updatedP$ is \\emph{stable} with respect to perturbations in $\\observedP$ if for all $\\eps > 0$, there exists a $\\delta > 0$ such that\n% \t\\begin{equation}\n% \t\td_{\\text{TV}} (\\observedP, \\widehat{\\observedP}) < \\delta \\implies d_{\\text{TV}} (\\updatedP, \\widehat{\\updatedP}) < \\eps.\n% \t\\end{equation}\n% \\end{defn}\n%\n% \\vspace{0.5in}\n% In \\cite{BJW18}, it is shown that $d_{\\text{TV}} (\\widehat{\\updatedP}, \\updatedP) = d_{\\text{TV}} (\\widehat{\\observedP}, \\observedP)$, implying that:\n% \\vspace{0.5in}\n%\n% \\begin{theorem}\n% \t$\\updatedP$ is stable with respect to perturbations in $\\observedP$.\n% \\end{theorem}\n%\n% \\end{frame}\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}\n% \\begin{defn}[Stability of Updates II]\\label{defn:stableinitial}\n% Let $\\sett{\\PP_{\\pspace, d}}{d\\in\\dspace}{}$ and $\\sett{\\widehat{\\PP_{\\pspace, d}}}{d\\in\\dspace}{}$ be the conditional probabilities defined by the disintegration of $\\initialP$ and $\\widehat{\\initialP}$, respectively.\n%\n% We say that $\\updatedP$ is \\emph{stable} with respect to perturbations in $\\initialP$ if for all $\\eps > 0$, there exists a $\\delta > 0$ such that for almost every $d\\in\\supp(\\observed)$,\n% \\begin{equation}\\label{eq:stableinitial}\n% d_{\\text{TV}} (\\PP_{\\pspace, d}, \\widehat{\\PP_{\\pspace, d}}) < \\delta \\implies d_{\\text{TV}} (\\updatedP, \\widehat{\\updatedP}) < \\eps.\n% \\end{equation}\n% \\end{defn}\n%\n% \\begin{theorem}\n% $\\updatedP$ is stable with respect to perturbations in the initial.\n% \\label{thm:stableinitial}\n% \\end{theorem}\n%\n%\n% \\end{frame}\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}{Properties of the Updated Density}\n% \\begin{itemize}\n%\n% \t\\item Taken together, these stability results provide assurances that the updated we obtain is accurate up to the level of experimental error polluting $\\observed$ and error in incorrectly specifying initial assumptions.\n% \t\\item Given that specifying the definition of a ``true'' initial is somewhat nebulous, we are less interested in the consequences of the latter conclusion.\n% \t\\item Generating samples from $\\predicted$ requires a numerical approximation to $\\predicted$, which introduces \\textbf{additional errors} in $\\predicted$.\n%\n% \\end{itemize}\n%\n% \\end{frame}\n%\n%\n% \\subsection{Numerical Approximation and Sampling}\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}\n% \\begin{itemize}\n% \t\\item Let $\\widehat{\\predicted}$ be a computational approximation to $\\predicted$ and $\\widehat{\\updated}$ the associated approximate updated $\\updated$\n% \t\\item The conditional densities from the Disintegration theorem are\n% \\[\n% \\frac{\\widehat{d\\PP_{\\pspace, d}}}{d\\mu_{\\pspace, d}\\lam} = \\frac{\\initial\\lam}{ \\widehat{\\predicted (d)} }\n% \\]\n% \\vspace{0.25in}\n% \t\\item To approximate the push-forward of the initial density, we require:\n% \\begin{assumption}\\label{as:predx}\n% There exists some $C>0$ such that\n% \\[\n% \\observed (d) \\leq C \\widehat{\\predicted(d)} \\text{ for a.e. } d\\in \\dspace.\n% \\]\n% \\end{assumption}\n%\n% \\end{itemize}\n%\n% \\end{frame}\n%\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \\begin{frame}\n% \\begin{assumption}\\label{as:predx}\n% There exists some $C>0$ such that\n% \\[\n% \\observed (d) \\leq C \\widehat{\\predicted(d)} \\text{ for a.e. } d\\in \\dspace.\n% \\]\n% \\end{assumption}\n%\n% If this assumption is satisfied, we can prove the following cite{BJW18}:\n%\n% \\begin{theorem}\n% The error in the approximate updated is:\n% \\begin{equation}\\label{eq:pred_bound}\n% d_{\\text{TV}} (\\updatedP, \\widehat{\\updatedP}) \\leq C d_{\\text{TV}} (\\predictedP, \\widehat{\\predictedP}),\n% \\end{equation}\n% where the $C$ is the constant taken from \\eqref{as:predx}.\n% \\end{theorem}\n%\n% \\end{frame}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[t]{\\it The one with some practical considerations.}\n\n\\begin{itemize}\n\n  \\item May evaluate $\\updated$ directly for any sample of $\\pspace$ (one model solve).\n\n  \\bigskip\n  \\item Stable w.r.t. perturbations in the Total Variation metric.\n\n  \\bigskip\n  \\item Accuracy proportional approximation error of the predicted density.\n\n  \\bigskip\n  \\item Approximate $\\predicted$ with density estimation using samples from $\\initial$.\n\n\n  \\bigskip\n  \\item We (currently) use Gaussian KDE:\n\t\\begin{itemize}\n\t\t\t\\item Let $\\dimD$ be the dimension of $\\dspace$\n\t\t\t\\item Let $\\nsamps$ be the number of samples from $\\initial$ propagated through $\\qoi$.\n\t\t\t\\item Converges at a rate of $\\mathcal{O}(\\nsamps^{-4/(4+\\dimD)})$ in mean-squared error.\n\t\t\t\\item Converges at a rate of $\\mathcal{O}(\\nsamps^{-2/(4+\\dimD)})$ in $L^1$-error.\n\t\\end{itemize}\n\n\\end{itemize}\n\n\\end{frame}\n", "meta": {"hexsha": "0c8369d31e2a0896ae0c029618b452e2561130fe", "size": 12743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/content/problem_formulation.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": "presentation/content/problem_formulation.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": "presentation/content/problem_formulation.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": 39.2092307692, "max_line_length": 234, "alphanum_fraction": 0.6372910618, "num_tokens": 3975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059462938815, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6032765470841351}}
{"text": "% -*-latex-*-\n\n\\title{Orbiter Technical Notes: Nonspherical gravitational field perturbations}\n\\author{Martin Schweiger}\n\\date{September 21, 2005}\n\n\\documentclass[a4paper]{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{times}\n\\usepackage{cite}\n\n\\begin{document}\n\n%\\renewcommand{\\vec}[1]{\\ensuremath{\\mathbf{#1}}}\n\n\\newcommand{\\vR}[1]{\\ensuremath{\\vec{R}_{#1}}}\n\\newcommand{\\nR}[1]{\\ensuremath{|\\vR{#1}|}}\n\n\\maketitle\n\n\\section{Introduction}\nOrbiter uses a zonal representation of the gravitational potential generated by a celestial body, using a Legendre polynomial series expansion in the latitude $\\theta$. The perturbations in longitude ($\\phi$) are assumed to be negligible.\n\\begin{figure}\\centering\n\\includegraphics[width=0.45\\textwidth]{sphere.eps}\n\\caption{Planet-relative coordinates and polar unit vectors at a point $(r,\\phi,\\theta)$.}\n\\end{figure}\nThe potential is expressed as\n\\begin{equation}\\label{eq:gpot}\nU_G(r,\\phi,\\theta) = -\\frac{GM}{r} \\left[ 1 - \\sum_{n=2}^\\infty J_n \\left(\\frac{R}{r}\\right)^n P_n(\\sin \\theta) \\right]\n\\end{equation}\nwhere $G$ is the gravitational constant, $M$ and $R$ are the mass and mean radius of the central body, respectively, $r$ is the length of the radius vector, $J_n$ are the coefficients of the series expansion, and $P_n$ are the Legendre polynomials of order $n$.\nThe first Legendre polynomials are defined as\n\\begin{equation}\n\\begin{split}\nP_0(x) &= 1\\\\\nP_1(x) &= x\\\\\nP_2(x) &= \\frac{1}{2}(3x^2 - 1)\\\\\nP_3(x) &= \\frac{1}{2}(5x^3 - 3x)\\\\\nP_4(x) &= \\frac{1}{8}(35x^4 - 30x^2 +3)\n\\end{split}\n\\end{equation}\nThe acceleration due to the gravitational field of a test mass at point $\\vec{r} = (r,\\phi,\\theta)$ is then given by the gradient of the potential:\n\\begin{equation}\\label{eq:gacc}\n\\vec{a}_G(r,\\phi,\\theta) = -\\vec{\\nabla} U_G(r,\\phi,\\theta)\n\\end{equation}\nIn spherical polar coordinates, the gradient operator is expressed as\n\\begin{equation}\\label{eq:polargrad}\n\\vec{\\nabla} = \\hat{r} \\frac{\\partial}{\\partial r} + \\frac{1}{r} \\hat{\\theta}\\frac{\\partial}{\\partial \\theta} + \\frac{1}{r \\cos\\theta}\\hat{\\phi}\\frac{\\partial}{\\partial\\phi}\n\\end{equation}\nSubstituting equations \\ref{eq:gpot} and \\ref{eq:polargrad} into \\ref{eq:gacc} yields\n\\begin{equation}\n\\vec{a}_G(r,\\phi,\\theta) = \\hat{r} a_0^{(r)}(r) - \\sum_{n=2}^\\infty \\left[ \\hat{r} a_n^{(r)}(r,\\theta) + \\hat{\\theta} a_n^{(\\theta)}(r,\\theta) \\right]\n\\end{equation}\nwith the first terms given by\n\\begin{equation}\n\\begin{split}\na_0^{(r)}(r) &= -\\frac{GM}{r^2} \\\\\na_2^{(r)}(r,\\theta) &= -\\frac{3}{2} \\frac{GMR^2 J_2}{r^4}(3\\sin^2\\theta - 1)\\\\\na_2^{(\\theta)}(r,\\theta) &= 3 \\frac{GMR^2 J_2}{r^4} \\sin\\theta \\cos\\theta \\\\\na_3^{(r)}(r,\\theta) &= -2 \\frac{GMR^3 J_3}{r^5}(5 \\sin^3\\theta - 3\\sin\\theta)\\\\\na_3^{(\\theta)}(r,\\theta) &= \\frac{3}{2} \\frac{GMR^3 J_3}{r^5} (5 \\sin^2\\theta \\cos\\theta - \\cos\\theta) \\\\\na_4^{(r)}(r,\\theta) &= -\\frac{5}{8} \\frac{GMR^4 J_4}{r^6}(35 \\sin^4\\theta - 30\\sin^2\\theta + 3) \\\\\na_4^{(\\theta)}(r,\\theta) &= \\frac{5}{2} \\frac{GMR^4 J_4}{r^6} (7 \\sin^3\\theta \\cos\\theta - 3 \\sin\\theta \\cos\\theta)\n\\end{split}\n\\end{equation}\nThe coefficients $J_n$ used by Orbiter are listed in Table~\\ref{tab:Jn}.\n\\begin{table}\n\\begin{tabular}{lcccc}\n        & $J_2$     & $J_3$ & $J_4$ & $J_5$ \\\\ \\hline\nMercury & 60        & -     & -     & -     \\\\\nVenus   & 27        & -     & -     & -     \\\\ \nEarth   & 1082.6269 & -2.51 & -1.60 & -0.15 \\\\\nMars    & 1964      & -     & -     & -     \\\\\nJupiter & 14750     & -     & -     & -     \\\\\nSaturn  & 16450     & -     & -     & -     \\\\\nUranus  & 12000     & -     & -     & -     \\\\\nNeptune & 4000      & -     & -     & -\n\\end{tabular}\n\\caption{Coefficients ($\\times 10^6$) for zonal expansion of planetary gravitational potentials.}\n\\label{tab:Jn}\n\\end{table}\n\nThe field perturbations can lead to a rotation of the orbit trajectory of a satellite. This rotation can be expressed in terms of the movement of the longitude of the ascending node ($\\Omega$) and the movement of the argument of periapsis ($\\omega$).\nIf only terms up to $J_2$ are included, approximate values of the movements $\\partial\\Omega/\\partial t$ and $\\partial\\omega/\\partial t$ are given by\n\\begin{eqnarray}\n\\frac{\\partial\\Omega}{\\partial t} &=& -\\frac{3 n}{2} \\left(\\frac{R}{a}\\right)^2 \\frac{\\cos i}{(1-e^2)^2} J_2 \\label{eq:noderate} \\\\\n\\frac{\\partial\\omega}{\\partial t} &=& \\frac{3 n}{4} \\left(\\frac{R}{a}\\right)^2 \\frac{5 \\cos^2 i - 1}{(1-e^2)^2} J_2\n\\end{eqnarray}\nwhere $n=2\\pi/P$ is the mean motion (with orbit period $P$), $a$ is the mean distance, $e$ is the eccentricity, and $i$ is the inclination.\n\n\\subsection*{Example: calculate the inclination for a sun-synchronous polar orbit}\nA sun-synchronous orbits exploits the propagation of the line of nodes to keep the orbital plane synchronised with the relative position of the sun. A satellite can for example be placed in a sun-synchronous orbit so that it continuously flys over the planet's terminator line.\nFrom~\\ref{eq:noderate} we have\n\\begin{equation}\n\\cos i = -\\frac{2}{3 n} \\left(\\frac{a}{R} \\right)^2 \\frac{(1-e^2)^2}{J_2} \\frac{\\partial\\Omega}{\\partial t}\n\\end{equation}\nA sun-synchronous orbit requires the line of nodes to move at a rate of $2\\pi$ per year. For Earth, this is equivalent to $\\partial\\Omega/\\partial t = 1.99\\cdot 10^{-7}$\\,rad/s (about $0.99$ deg. per day). Assume a circular orbit ($e=0$) at an altitude of 300\\,km\n%($a = 6 678 137$\\,m, with $R_E = 6 378 137$\\,m).\n($a = 6 671 010$\\,m, with $R_E = 6 371 010$\\,m).\nWith $P = 2\\pi\\sqrt{a^3/\\mu_E}$ we get $n = \\sqrt{\\mu_E/a^3} = 0.0012$\\,rad/s. This leads to\n\\begin{equation}\n\\cos i_\\text{sync} = -\\frac{2}{0.0035} \\left(\\frac{6 678 137}{6 378 137}\\right)^2 \\frac{1.99\\cdot 10^{-7}}{0.001082630} = -0.116,\n\\end{equation}\nor $i_\\text{sync} = 96.7$\\,deg.\n\\end{document}\n", "meta": {"hexsha": "5d9d89475555f2cec3df196393cb3eb797dd5817", "size": 5812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Doc/Technotes/gravity/gravity.tex", "max_stars_repo_name": "Ybalrid/orbiter", "max_stars_repo_head_hexsha": "7bed82f845ea8347f238011367e07007b0a24099", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1040, "max_stars_repo_stars_event_min_datetime": "2021-07-27T12:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-02T14:24:49.000Z", "max_issues_repo_path": "Doc/Technotes/gravity/gravity.tex", "max_issues_repo_name": "Ybalrid/orbiter", "max_issues_repo_head_hexsha": "7bed82f845ea8347f238011367e07007b0a24099", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2021-07-27T12:25:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-02T12:22:19.000Z", "max_forks_repo_path": "Doc/Technotes/gravity/gravity.tex", "max_forks_repo_name": "Ybalrid/orbiter", "max_forks_repo_head_hexsha": "7bed82f845ea8347f238011367e07007b0a24099", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 71, "max_forks_repo_forks_event_min_datetime": "2021-07-27T14:19:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-02T05:51:52.000Z", "avg_line_length": 53.3211009174, "max_line_length": 277, "alphanum_fraction": 0.6543358568, "num_tokens": 2168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.6926419894793248, "lm_q1q2_score": 0.6030122240256328}}
{"text": "\\chapter{Curved Spacetimes and Gravity}\\label{chap:GR}\nOur current understanding of gravity is manifested in Einsteins theory of General Relativity. In contrast to the treatment of the other fundamental forces, which are all described by gauge theories and summarized in the Standard Model of Particle Physics, gravity is based on the concept of curved spacetime. This chapter summarizes some of the general concepts and notions of General Relativity, needed for a basic understanding of the subject. For most of the concepts we present here, we are following Sean Carroll's lecture notes \\cite{CarrollGR}. At the end of this chapter, we show why gravity can not be quantized in a perturbative manner, in opposition to the other three fundamental forces. For this part we follow \\cite{PawlowskiNPgaugeLecture}. \n\n\\section{An Introduction to Spacetime Geometry}\n When talking about the concept of curved spacetimes, one first needs a mathematical framework to quantify curvature and to understand how mathematical concepts such as differentiation and integration are generalized to curved spaces. \n The central objects in our discussion of curved spaces are \\textit{differentiable manifolds}, i\\,e. topological spaces, that are  locally diffeomorphic to $\\mathbb{R}^n$. Locally in this sense means, that we can find coordinate maps $\\phi_i: M \\underset{\\mathrm{open}}{\\supset} U_i \\rightarrow \\mathbb{R}^n$, such that the image $\\phi_i(U_i)$ is open in  $\\mathbb{R}^n$, for every point on $M$, whereas globally the manifold may have a very complicated topology. A set of such coordinate maps $\\{(U_{\\alpha}, \\phi_{\\alpha})\\}$ that covers the entire manifold and where the charts are smoothly sewed together is called an \\textit{atlas}. For overlapping charts $U_{\\alpha}\\cap U_{\\beta} \\neq \\emptyset$, the maps $(\\phi_{\\alpha} \\circ \\phi_{\\beta}^{-1})$, a.\\,k.\\,a. coordinate transformations, must be smooth and differentiable. They are directly connected to the coordinates $x^{\\mu}$ we'll work with later on. \\\\\nFurther, we need to introduce additional structures, such as vectors and tensors on manifolds, since they are the objects we are interested in when it comes to the discussion of physical models. To be able to talk about vectors, one needs to associate  a \\textit{tangent space} $T_p$ to every point $p$ of the manifold. The tangent space is the set of all vectors at  $p$ and  has the structure of a vector space with the same dimension as $M$. The disjoint union of all tangent spaces on $M$ is called the \\textit{tangent bundle}. To specify the concept of the tangent space we claim, that it can be identified with the space of directional derivative operators along curves $\\gamma: \\mathbb{R} \\rightarrow M$  through $p$. In this case, we find a basis of $T_p$ as the set $\\{\\hat{\\partial}_{\\mu}\\}$ of directional derivatives at $p$. It can be shown, that the directional derivatives can be decomposed into a sum of real numbers times partial derivatives, i.\\,e. $\\frac{d}{d \\lambda} = \\frac{d x^{\\mu}}{d \\lambda}\\partial_{\\mu}$, where $\\lambda$ is the parameter of the curve $\\gamma$. This allows us to represent a vector $V=V^{\\mu}\\partial_{\\mu}$ independently of the chosen coordinates. The basis vectors in some different coordinate system $x^{\\mu^{\\prime}}$ are then simply related to the initial basis via $\\partial_{\\mu^{\\prime}}=\\frac{\\partial x^{\\mu}}{\\partial x^{\\mu^{\\prime}}} \\partial_{\\mu}$ which yields the transformation law for vector components under general coordinate transformations,\n\\begin{align}\n\tV^{\\mu^{\\prime}}=\\frac{\\partial x^{\\mu^{\\prime}}}{\\partial x^{\\mu}} V^{\\mu}. \\label{eqn:contravariant_trafo}\n\\end{align}\nComponents obeying this transformation law are called \\textit{contravariant}. At this point it follows quite naturally to define the \\textit{cotangent space} $T_p^*$ as the set of linear maps $\\omega: T_p \\rightarrow \\mathbb{R}$. Elements of the cotangent space are called one-forms or dual vectors and similarly to the discussion of the tangent space, we find a suitable basis for $T_p^*$ as the gradients $\\{\\dd\\hat{x}^{\\mu}\\}$, allowing us to represent arbitrary one-forms as $\\omega = \\omega_{\\mu} \\dd x^{\\mu}$. As before, we are interested in the transformation behavior of our basis one-forms, i.\\,e. $\\mathrm{d} x^{\\mu^{\\prime}}=\\frac{\\partial x^{\\mu^{\\prime}}}{\\partial x^{\\mu}} \\mathrm{d} x^{\\mu}$, and the dual vector components\n\\begin{align}\n\t\\omega_{\\mu^{\\prime}}=\\frac{\\partial x_{\\mu}}{\\partial x^{\\mu^{\\prime}}} \\omega_{\\mu}.\\label{eqn:covariant_trafo}\n\\end{align}\nThis transformation behavior differs from the one found for vectors. We call components transforming as in equation (\\ref{eqn:covariant_trafo}) \\textit{covariant}.\nNow we are able to generalize these concepts by introducing tensors $T$ of type $(k,l)$ as\n\\begin{align}\nT=T_{\\phantom{\\mu_{1} \\cdots \\mu_{k}}\\nu_{1} \\cdots \\nu_{l}}^{\\mu_{1} \\cdots \\mu_{k}} \\ \\partial_{\\mu_{1}} \\otimes \\cdots \\otimes \\partial_{\\mu_{k}} \\otimes \\mathrm{d} x^{\\nu_{1}} \\otimes \\cdots \\otimes \\mathrm{d} x^{\\nu_{l}}.\n\\end{align}\nHere $\\otimes$ denotes the usual tensor product.\nThe general transformation law for tensors follows naturally as expected from equations (\\ref{eqn:contravariant_trafo}) and (\\ref{eqn:covariant_trafo}),\n\\begin{align}\n\tT_{\\phantom{\\mu_{1}^{\\prime} \\cdots \\mu_{k}^{\\prime}}\\nu_{1}^{\\prime} \\cdots \\nu_{l}^{\\prime}}^{\\mu_{1}^{\\prime} \\cdots \\mu_{k}^{\\prime}}=\\frac{\\partial x^{\\mu_{1}^{\\prime}}}{\\partial x^{\\mu_{1}}} \\cdots \\frac{\\partial x^{\\mu_{k}^{\\prime}}}{\\partial x^{\\mu_{k}}} \\frac{\\partial x^{\\nu_{1}}}{\\partial x^{\\nu_{1}^{\\prime}}} \\cdots \\frac{\\partial x^{\\nu_{l}}}{\\partial x^{\\nu_{l}^{\\prime}}} T^{\\mu_{1} \\cdots \\mu_{k}}_{\\phantom{\\mu_{1} \\cdots \\mu_{k}}\\nu_{1} \\cdots \\nu_{l}}.\n\\end{align}\nHaving understood the basic structures and their respective behavior under coordinate transformations, we are now able to present some of the most important tensors in General Relativity. \\\\\nMaybe the most important object to quantify curved space is the \\textit{metric tensor} $g_{\\mu\\nu}$\\footnote{It is convenient to write the components $T_{\\phantom{\\mu_{1} \\cdots \\mu_{k}}\\nu_{1} \\cdots \\nu_{l}}^{\\mu_{1} \\cdots \\mu_{k}}$ when speaking about tensors $T$.} and its inverse  $g^{\\mu\\nu}$, related via $g^{\\mu\\nu}g_{\\nu\\sigma} = \\delta^{\\mu}_{\\phantom{\\mu}\\sigma}$. The metric and its inverse can be used to raise and lower indices, e.\\,g. $x^{\\mu} = g^{\\mu\\nu}x_{\\nu}$. Additionally we can compute path lengths and proper time via the definition of the line element \n\\begin{align}\n\t\\dd s^{2}=g_{\\mu \\nu} \\mathrm{d} x^{\\mu} \\mathrm{d} x^{\\nu}.\n\\end{align}\n\\begin{minipage}{\\textwidth}\n\tFor arbitrary vector fields $V$ and $W$ the scalar product induced by the metric tensor \\\\ reads\n\\vspace{-0.4cm}\n\\begin{align}\n\tg(V,W) = g_{\\mu\\nu}V^{\\mu}W^{\\nu} = V^{\\mu}W_{\\mu}= g^{\\mu\\nu}V_{\\mu}W_{\\nu} = V_{\\mu}W^{\\mu}.\n\\end{align}\n\\end{minipage}\\vfill\\newpage\nWe will see, that the metric tensor already contains all the information on the geometrical structure of the respective manifold, whose curvature we want to quantify. Nevertheless, we first have to think about differentiation of general tensors again. \\\\\nIn flat space, the partial derivative is a map from $(k, l)$ to $(k, l+1)$ tensor fields satisfying linearity and the Leibniz product rule. We want to generalize this concept to curved space by introducing the \\textit{covariant derivative} $\\nabla$\\footnote{In the context of quantum field theory, the gauge covariant derivative is often written as $D$. Nevertheless, throughout this thesis we will use $\\nabla$ to indicate any kind of covariant derivative.}. In contrast to the usual partial derivative, the covariant derivative is independent of the chosen set of coordinates. Consider for example the covariant derivative of a vector field $V$, which can be written as a partial derivative plus some correction term due to its property to obey the Leibniz rule:\n\\begin{align}\n\\nabla_{\\mu} V^{\\nu}=\\partial_{\\mu} V^{\\nu}+\\Gamma_{\\phantom{\\nu}\\mu \\lambda}^{\\nu} V^{\\lambda}.\n\\label{eqn:cov_deriv}\n\\end{align}\nHere, the correction term is specified by the so-called \\textit{Christoffel symbols}, a.\\,k.\\,a. \\textit{connection coefficients}. They are determined by derivatives of the metric tensor:  \n\\begin{align}\n\\Gamma_{\\phantom{\\alpha}\\mu \\nu}^{\\alpha}=\\frac{1}{2} g^{\\mu \\lambda}\\left(\\partial_{\\mu} g_{\\nu \\lambda}+\\partial_{\\nu} g_{\\mu \\lambda}-\\partial_{\\lambda} g_{\\mu \\nu}\\right)\\footnotemark.\t\n\\end{align}\n\\footnotetext{This holds only true, if the connection is \\textit{torsion free}, i.\\,e. $\nT_{\\phantom{\\lambda}\\mu \\nu}^{\\lambda}=\\Gamma_{\\phantom{\\lambda}\\mu \\nu}^{\\lambda}-\\Gamma_{\\phantom{\\lambda}\\nu \\mu}^{\\lambda}=2 \\Gamma_{\\phantom{\\lambda}[\\mu \\nu ]}^{\\lambda} = 0$, and fullfils \\textit{metric compatibility}, i.\\,e.$\n\\nabla_{\\rho} g_{\\mu \\nu}=0$. For the most important connection in the context of General Relativity, the \\textit{Levi-Civita connection}, these properties are fullfilled. The fundamental theorem of Riemannian geometry states, that for every Riemannian manifold there exists a unique Levi-Civita connection. It is determined by the Koszul formula.}\nIt can be shown, that the connection coefficients themselves do \\textit{not} transform like tensor components, but are constructed in a way such that the combination (\\ref{eqn:cov_deriv}) does. Note, that the covariant derivative reduces to the partial when applied to scalars. With this definition of the connection, we are now finally able to introduce the remaining tensor structures needed for the understanding of the calculations presented later on in this work. \\\\\nThe central object in our discussion of curvature is the \\textit{Riemann tensor} $R_{\\phantom{\\alpha}\\beta \\gamma \\delta}^{\\alpha}$. It is a $(1, 3)$-tensor given by\n\\begin{align} \n\tR_{\\phantom{\\alpha}\\beta \\gamma \\delta}^{\\alpha}=\\partial_{\\gamma} \\Gamma_{\\phantom{\\alpha}\\beta \\delta}^{\\alpha}-\\partial_{\\delta} \\Gamma_{\\phantom{\\alpha}\\beta \\gamma}^{\\alpha}+\\Gamma_{\\phantom{\\alpha}\\beta \\delta}^{\\epsilon} \\Gamma_{\\phantom{\\alpha}\\epsilon \\gamma}^{\\alpha}-\\Gamma_{\\phantom{\\alpha}\\beta \\gamma}^{\\epsilon} \\Gamma_{\\phantom{\\alpha}\\epsilon \\delta}^{\\alpha}.\n\\end{align}\nIt contains all the information about the curvature of the respective manifold. Another useful definition of the Riemann tensor is related to the commutator of two covariant derivatives, acting on a vector field:\n\\begin{align}\n\t\\left[\\nabla_{\\mu}, \\nabla_{\\nu}\\right] A^{\\sigma}=R_{\\phantom{\\alpha}\\rho \\mu \\nu}^{\\sigma} A^{\\rho}. \\label{eqn:Riemann}\n\\end{align}\nWe are also interested in contractions of the Riemann tensor, especially the \\textit{Ricci tensor} \n\\begin{align}\n\tR_{\\mu\\nu} = R^{\\alpha}_{\\phantom{\\alpha}\\mu\\alpha\\nu} = g_{\\alpha\\beta} R^{\\beta}_{\\phantom{\\alpha}\\mu\\alpha\\nu}\n\\end{align}\nand the \\textit{Ricci scalar} \n\\begin{align}\n\\mathcal{R} = g_{\\mu\\nu}R^{\\mu\\nu} = R^{\\mu}_{\\phantom{\\mu}\\mu}.\n\\end{align}\nAt this point, we also want to introduce the \\textit{Einstein tensor}, defined as\n\\begin{align}\n\t G_{\\mu\\nu} = R_{\\mu\\nu} - \\frac{1}{2}g_{\\mu\\nu}\\mathcal{R}.\n\\end{align}\nHaving introduced the setup for the calculations performed in this work, we are now ready to introduce the \\textit{Einstein-Hilbert action}, providing the starting point for an investigation of quantum gravity within the Functional Renormalization Group approach. \n\\section{From Geometry to Einsteins Equations}\nThe Einstein-Hilbert action, given by\n\\begin{align}\n\t\\mathcal{S}_{\\text{EH}} = \\frac{1}{16\\pi G} \\int_x \\sqrt{g} \\ (\\Ricci - 2\\Lambda), \n\\end{align}\nwhere $G$ is Newtons coupling and $\\Lambda$ is the cosmological constant, describes a minimally coupled theory of gravity, leading to a $\\sfrac{1}{r}$ gravitational potential in the non-relativistic limit. Note, that compared to the usual spacetime measure a factor of $\\sqrt{g} := \\sqrt{-\\operatorname{det}g_{\\mu\\nu}}$ is included to preserve diffeomorphism invariance.\\footnote{Diffeomorphism invariance, i.\\,e. the freedom of choosing an appropriate coordinate system, is the central symmetry in the context of General Relativity, based  on the assumption, that coordinates do not exist a priori in nature, but are rather a mathematical tool used to describe it, that should not change the fundamental laws of physics.\\nopagebreak} \\\\ \nVarying the Einstein-Hilbert action w.\\,r.\\,t. the inverse metric $g^{\\mu\\nu}$ yields Einsteins equations in absence of matter:\n\\begin{align}\n\tG_{\\mu\\nu} + \\Lambda g_{\\mu\\nu} = 0.\n\\end{align}\nThe non-vacuum Einstein equations are obtained the same way, after the inclusion of matter in this setting  by adding a matter part to the Einstein-Hilbert action:\n\\begin{equation}\n\t\\mathcal{S} = \\frac{1}{8\\pi G}\\mathcal{S}_{\\mathrm{EH}} + \\mathcal{S}_{\\text{matter}}.\n\\end{equation}\nWith the definition of the Energy-Momentum tensor $T_{\\mu\\nu}$, given by\n\\begin{align}\n\tT_{\\mu\\nu} = \\frac{-2}{\\sqrt{g}} \\frac{\\delta\\mathcal{S}_{\\text{matter}}}{\\delta g^{\\mu\\nu}},\n\\end{align}\nwe arrive at \n\\begin{align}\n\\frac{1}{8\\pi G}\\left[G_{\\mu\\nu} + \\Lambda g_{\\mu\\nu}\\right] = T_{\\mu\\nu}.\t\n\\end{align}\nIn this form, Einsteins equations perfectly embody the direct correlation between curvature (l.\\,h.\\,s.) and the dynamics of the matter content of the theory (r.\\,h.\\,s.). \\\\\nAt the end of this chapter we want to emphasize the problem of perturbative non-renormali- zability in the context of finding a quantum field theoretical description of gravity. \n\\section{Perturbative Non-Renormalizability of Gravity}\nNaively, one could try to quantize gravity via the path integral formalism with a generating functional, given by $\\int_{g_{\\mu\\nu}} \\operatorname{e}^{-\\mathcal{S}_{\\mathrm{EH}}}$, as usual. The main problem in this approach is the lack of positivity of $\\mathcal{S}_{\\mathrm{EH}}$ causing problems with unitarity of the theory. In quantum gravity one usually introduces a linear split of the \\textit{full} metric $g_{\\mu\\nu}$, to perform expansions about a given background $\\bar{g}_{\\mu\\nu}$, comparable to classical perturbation theory, which is based on coupling or amplitude expansions around the free Gaussian theory. The linear split reads\n\\begin{align}\n\tg_{\\mu\\nu} = \\bar{g}_{\\mu\\nu} + \\sqrt{G}h_{\\mu\\nu},\n\t\\label{eqn:metric_split}\n\\end{align}\nwith the metric fluctuation $h_{\\mu\\nu}$ defined as $h_{\\mu\\nu}= 1/\\sqrt{G}\\left(g_{\\mu\\nu}-\\bar{g}_{\\mu\\nu}\\right)$. This allows us to write the path integral in terms of the fluctuation field as\n\\begin{equation}\nZ\\left[J^{\\mu \\nu} ; \\overline{g}_{\\mu \\nu}\\right] \\propto \\int_{h_{\\mu \\nu}} \\operatorname{e}^{-S_{\\mathrm{EH}}\\left[\\bar{g}_{\\mu \\nu}+\\sqrt{G} h_{\\mu \\nu}\\right]+\\int_x \\sqrt{\\bar{g}} \\  J^{\\mu \\nu} h_{\\mu \\nu}}.\n\\end{equation}\nNote, that the source term depends on the determinant of the background metric, otherwise the usual $J^{\\mu\\nu}$ derivatives would not generate the $n$-point functions of the fluctuation field $h_{\\mu\\nu}$. We will come back to this problem, which is often referred to as \\textit{background independence}, at the end of this thesis in chapter \\ref{chap:BGindependence}. \\\\\nAfter a suitable tensor decomposition of the fluctuation field and a gauge fixing procedure \\`a la Faddeev-Popov\\footnote{The functional quantization of gauge theories requires a gauge fixing procedure due to redundancies in the path integral measure. The idea of Faddeev and Popov is to represent the gauge fixing condition, which is implemented in the functional integral, as an additional functional integral over a set of Grassmann fields $c$ and $\\bar{c}$, known as \\textit{Faddeev-Popov ghosts}. Even though they are anticommuting Grassmann fields, they transform as scalars under Lorentz transformations. They also violate spin statistics. Nevertheless, they can be treated as additional particles in the computation of Feynman diagrams. For a detailed discussion, see e.\\,g. ch. 16 in \\cite{PeskinSchroeder1995} or  sec. 5.2 in \\cite{PawlowskiNPgaugeLecture}.},  we are left with the gauge fixed Einstein-Hilbert action\n\\begin{align}\n\t\\mathcal{S}_{\\text{grav}}[\\bar{g},\\Phi] = \\mathcal{S}_{\\text{EH}}[g] + \\mathcal{S}_{\\text{gf}}[\\bar{g}, h] + \\mathcal{S}_{\\text{gh}}[\\bar{g},\\Phi] .\n\\end{align}\n Here the pure gravity multi-field $\\Phi=(h_{\\mu\\nu}, c_{\\mu}, \\bar{c}_{\\mu})$ was introduced. Altogether, this yields the gauge-fixed path integral representation of quantum gravity:\n \\begin{equation}\nZ[J ; \\bar{g}]=\\int_{\\Phi} \\operatorname{e}^{-\\mathcal{S}_{\\text{grav}}\\left[\\bar{g}_{\\mu\\nu}, \\Phi\\right]+\\int_x \\sqrt{\\bar{g}} \\ J \\cdot \\Phi}.\n\\end{equation}\nAn analysis of the canonical momentum dimensions of the essential couplings of this theory, $G$ and $\\Lambda$, results in:\n\\begin{equation}\n\\left[G\\right] = \\left[\\dd^dx \\sqrt{g}\\ \\mathcal{R}\\right] = 2-d,  \\qquad\\qquad\\qquad \\left[\\Lambda\\right] = 2.\n\\end{equation}\nThis implies, that the Newton coupling has a negative mass dimension in $d=4$ spacetime dimensions. To investigate the consequences of this, one can consider the grade of divergence $\\Lambda^{\\delta(\\gamma)}$ for a general graph $\\gamma$ with $E$ external lines, $I$ internal propagators and $L$ loops. Here, $\\Lambda$ is an UV cutoff for the momentum integrals and $\\delta(\\gamma)$ is the index of the graph,\n\\begin{equation}\n\t\\delta(\\gamma) = dL- 2\\left(I-\\sum_{n=3}^{\\infty}\\nu_n\\right),\n\\end{equation}\nwhere the $\\nu_n$ represent $n$-graviton vertices. After expressing the number of loops in terms of the internal lines and the $n$-graviton vertices and restricting ourselves to graphs satisfying $E + 2I = \\sum_{n=3}^{\\infty}\\nu_n$, we find\n\\begin{equation}\n\t\\delta(\\gamma)=d-\\frac{d-2}{2} E+\\sum\\limits_{n=3}^{\\infty} v_{n} \\delta\\left(v_{n}\\right),\n\\end{equation}\nwhere $\\delta\\left(v_{n}\\right)=\\frac{1}{2}(n-2)(d-2)$.\nAfter fixing the number of external lines, e.\\,g. to $E=2$, representing the case of vacuum polarization as depicted in figure (\\ref{fig:vacuum_pol}), one is now able to investigate the grade of divergence for diagrams of different loop orders. t'Hooft and Veltman proved that the theory is renormalizable up to 1-loop order \\cite{tHooftVeltmann1974}, but already at 2-loop order, Goroff and Sagnotti showed, that non-vanishing counterterms are generated \\cite{GoroffSanotti1985}. In general, this is interpreted as the failure of perturbative quantization of gravity due to the negative mass dimension of the Newton coupling. This leads us to our discussion of Asymptotic Safety as a non-perturbative approach based on the FRG we presented in the last chapter.  \n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figs/TikZ/vacuum_pol}\n\\caption[Vacuum polarization diagrams up to $1$-loop order.]{Vacuum polarization diagrams up to $1$-loop order. The double lines represent the graviton propagator.}\t\n\\label{fig:vacuum_pol}\n\\hrulefill\n\\end{figure}", "meta": {"hexsha": "a91961085226e5c088203cb3aa9a3b6cb68d45b0", "size": 18774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/content/03_gravity.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/content/03_gravity.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/content/03_gravity.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": 138.0441176471, "max_line_length": 1506, "alphanum_fraction": 0.7387876851, "num_tokens": 5514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.6926419894793246, "lm_q1q2_score": 0.6030122240256327}}
{"text": "\\chapter{Alternating Current}\n\nWe have discussed the voltage and current created by a battery.  A\nbattery pushes the electrons in one direction at a constant voltage;\nthis is known as \\newterm{Direct Current} or DC. A battery typically\nprovides between 1.5 and 9 volts.\n\nThe electrical power that comes into your home on wires is\ndifferent. If you plotted the voltage over time, it would look like\nthis:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels fill=white, inner sep=1pt,\n  font=\\scriptsize, }, ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.425] (0,-1.85) grid\n(6.6,1.85);\n\n% y tick label\n\\foreach \\y in {-170, -85, 85, 170}{\\node[tl,left=1mm] at (0,{\\y/100})\n  {$\\y$};}\n\n% x tick label\n\\foreach \\x in {0.004,0.008, 0.012, 0.016}{\\node[tl,below=1mm] at\n  ({392.67*\\x},0) {$\\x$};}\n\n% axes\n\\draw[->,thick] (0,0) -- (6.5,0) node[right] {$seconds$};\n\\draw[->,thick] (0,-1.8) -- (0, 1.8) node[above] {$volts$};\n% curve\n\\draw[<->,thick,draw=black,domain=0:6.5,samples=300,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 1.7});\n\\end{tikzpicture}\n\nThe $x$ axis here represents ground. When you insert a two-prong plug\ninto an outlet, one is ``hot'' and the other is ``ground''. Ground\nrepresents 0 volts and should be the same voltage as the dirt under\nthe building.\n\nThe voltage is a sine wave at 60Hz. Your voltage fluctuates between\n-170v and 170v. Think for a second what that means: The power company\npushes electrons at 170v and then pulls electrons at 170v.  It\nalternates back and forth this way 60 times per second.\n\n\\section{Power of AC}\n\nLet's say you turn on your toaster which has a resistance of 14.4\nohms. How much energy (in watts) does it change from electrical energy\nto heat?  We know that $I = V/R$ and we know that watts of power is\n$IV$. So given a voltage of $V$, the toaster is consuming $V^2/R$\nwatts.\n\nHowever, $V$ is fluctuating. Let's plot the power the toaster is consuming:\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] (0,0) grid (6.6,2.1);\n\n% y tick label\n\\foreach \\y in {500, 1000, 1500, 2000}{\\node[tl,left=1mm] at (0,{\\y/1000}) {$\\y$};}\n\n% x tick label\n\\foreach \\x in {0.004,0.008, 0.012, 0.016}{\\node[tl,below=1mm] at ({392.67*\\x},0) {$\\x$};}\n\n% axes\n\\draw[->,thick] (0,0) -- (6.5,0) node[right] {$seconds$};\n\\draw[->,thick] (0,0) -- (0, 2.1) node[above] {$watts$};\n% curve\n\\draw[<->,thick,draw=black,domain=0:6.5,samples=300,variable=\\x]\n      plot (\\x,{sin(deg(\\x))^2 * 2.007});\n\\end{tikzpicture}\n\nAnother sine wave! Here is a lesser-known trig identity: $\\left( \\sin(x) \\right)^2 = \\frac{1}{2} - \\frac{1}{2}\\cos(2x)$\n\nSo this is actually a cosine wave flipped upside down, scaled down by\nhalf the peak power and translated up so that it is never\nnegative. Note that it is also twice the frequency of the voltage sine\nwave.\n\nIf we say the peak voltage is $V_p$ and the resistance of the toaster\nis $R$, the power is given by\n\n$$\\frac{V_p^2}{2R} - \\frac{V_p^2}{2R} \\cos \\left(\\frac{2\\pi t}{120} \\right)$$\n\nAs a toaster user and as someone who pays a power bill, you are mostly\ninterested in the average power.  To get the average power, you take\nthe area under the power graph and divide it by the amount of time.\n\nWe can think of the area under the curve as two easy-to-integrate quantites summed:\n\\begin{itemize}\n\\item A constant function of $y = frac{V_p^2}{2R}$\n\\item A wave $y = - \\frac{V_p^2}{2R} \\cos \\left(\\frac{2\\pi t}{120} \\right)$\n\\end{itemize}\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] (0,-1.1) grid (6.6,1.1);\n\n% y tick label\n\\foreach \\y in {-1000, -500, 500, 1000}{\\node[tl,left=1mm] at (0,{\\y/1000}) {$\\y$};}\n\n% x tick label\n\\foreach \\x in {0.004,0.008, 0.012, 0.016}{\\node[tl,below=1mm] at ({392.67*\\x},0) {$\\x$};}\n\n% axes\n\\draw[->,thick] (0,0) -- (6.5,0) node[right] {$seconds$};\n\\draw[<->,thick] (0,-1.1) -- (0, 1.1) node[above] {$watts$};\n% curve\n\\draw[<->,thick,draw=black] (0,1.003) -- (6.5, 1.003) node[right] {Constant: $\\frac{V_p^2}{2R}$};\n\\draw[<->,thick,draw=black,domain=0:6.5,samples=300,variable=\\x]\n      plot (\\x,{-1 * cos(deg(\\x) * 2) * 1.003}) node[right]{Wave:$- \\frac{V_p^2}{2R} \\cos \\left(\\frac{2\\pi t}{120} \\right)$};\n\\end{tikzpicture}\n    \nWhen we integrate that constant function we get $\\frac{t V_p^2}{2R}$\n\nWhen we integrate that wave for a complete cycle we get...zero! The\npositive side of the wave is canceled out by the negative side.\n\nSo, the average power is $\\frac{V_p^2}{2R}$ watts.\n\nSomeone at some point said ``I'm used to power being $V^2/R$. Can\nwe define a voltage measure for AC power such that this is always true?''\n\nSo we started using $V_{rms}$ which is just\n$\\frac{V_p}{\\sqrt{2}}$. If you look on the back of anything that plugs\ninto a standard US power outlet, it will say something like ``For\n120v''.  What they mean is ``For 120v RMS, so we expect the voltage to\nfluctuate back and forth from 170v to -170v.''\n\nNotice that this is the same Root-Mean-Squared that we defined\nearlier, but now we know that if $y = \\sin(x)$, the RMS of $y$ is\n$1/\\sqrt{2} \\approx 0.707$.\n\nFor current, we do the same thing: If the current is AC, the power\nconsumed by a resistor is $I_{RMS}^2 R$, where $I_{RMS}$ is the peak\ncurrent divided by $sqrt{2}$.\n\n\\section{Power Line Losses}\n\nA wire has some resistance. Thinner wires tend to have more resistance\nthan thicker ones. Aluminum wires tend to have more resistance than\ncopper wires.\n\nLet's say that the power that comes to your house has to travel 20 km\nfrom the generator in a cable that has about $1 \\Omega$ of resistance\nper km.  Let's say that your home is consuming 12 kilowatts of power.\n\nIf that power is 120v RMS from the generator to your home, what\npercentage of the power is lost heating the power line? 10 amps RMS\nflow through your home. When that current goes through the wire, $I^2\nR = (100)(20) = 2000 watts$ is lost to heat.\n\nSo the power company would need to supply 14 kilowatts of power,\nknowing that 2 kilowatts would be lost on the wires.\n\nWhat if the power company moved the power at 120,000 volts RMS? Now\nonly 0.01 amps RMS flow through your home. When that current goes\nthrough the wire $I^2R = (0.0001)(20) = .002$ watts of power are lost\non the power lines.\n\nIt is much, much more efficent. The only problem is that 120,000 volts\nwould be incredibly dangerous.  So the power company moves power long\ndistances at very high voltages, like 765 kV.  Before the power is\nbrought into your home, it is converted into a lower voltage using a\n\\newterm{transformer}.\n\n\\section{Transformers}\n\nA transformer is a device that converts electrical power from one\nvoltage to another. A good tranformer is more than 95\\% efficient. The\ndetails of magnetic fields, flux, and inductance are beyond this scope\nof this chapter, so I am going to give a relatively simple explanation\nand admit that it is incomplete.\n\nA transformer is a ring with two sets of coils wrapped around it.\n\n\\includegraphics[width=0.5\\textwidth]{transformer.png}\n\n(Diagram from Wikipedia)\n\nWhen AC current is run through the primary winding, it create magnetic\nflux in the ring.  The magnetic flux induces current in the secondary\nwinding.\n\nIf $V_P$ is the voltage across the primary winding and $V_S$ is the\nvoltage across the secondary winding, they are related by the\nfollowing equation:\n\n$$\\frac{V_P}{V_S} = \\frac{N_P}{N_S}$$\n\nwhere $N_P$ and $N_S$ are the number of turns in the primary and\nsecondary windings.\n\nThere are usually at least two transformers between you and the very\nhigh voltage lines.  There are tranformers at the substation that make\nthe voltage low enough to travel on regular utility poles. On the\nutility poles, you will see cans that contain smaller\ntransformers. Those step the voltage down to make the power safe to\nenter your home.\n\n\\section{Phase and 3-phase power}\n\nIf two waves that are ``in sync'' we say they have the same \\newterm{phase}.\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels fill=white, inner sep=1pt,\n  font=\\scriptsize, }, ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.425] (0,-1.85) grid\n(13,1.85);\n\n% axes\n\\draw[->,thick] (0,0) -- (13,0);\n% curve\n\\draw[thick,draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 1.7});\n\\draw[thick,dashed, draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 0.9});\n\\end{tikzpicture}\n\nIf they are the same frequency, but are not in-sync, we can talk about\nthe difference in their phase.\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels fill=white, inner sep=1pt,\n  font=\\scriptsize, }, ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.425] (0,-1.85) grid\n(13,1.85);\n\n% axes\n\\draw[->,thick] (0,0) -- (13,0);\n% curve\n\\draw[thick,draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 1.7});\n\\draw[thick,dashed, draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x) - 90) * 0.9});\n\\end{tikzpicture}\n\nHere we see that the smaller wave is lagging by $\\pi/2$ or $90^\\circ$.\n\nIn most power grids, there are usually 3 wires carrying the power.\nThe voltage on each is $2\\pi/3$ out of phase with the other two:\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels fill=white, inner sep=1pt,\n  font=\\scriptsize, }, ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.425] (0,-1.85) grid\n(13,1.85);\n\n% axes\n\\draw[->,thick] (0,0) -- (13,0);\n% curve\n\\draw[thick,draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 1.7});\n\\draw[thick,dashed, draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x) - 120) * 1.7});\n\\draw[thick,draw=sdkblue,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x) + 120) * 1.7});\n\\end{tikzpicture}\n\nThis is nice in two ways:\n\\begin{itemize}\n\\item While the power in each wire is fluctuating, the total power is not fluctuating at all.\n\\item While the power plant is pushing and pulling electrons on each\n  wire, the total number number of electrons leaving the load is zero.\n\\end{itemize}\n(Both these assume that there each wire is attached to a load with the same constant resistance.)\n\nIn big industrial factories, you will see all three wires enter the\nbuilding. Large amounts of smooth power delivery means a lot to an\nindustrial user.\n\nIn residential settings, each home gets its power from one of the three\nwires. However two wires typically carry power into the home. Each\none carries 120V RMS, but they are out of phase by 180 degree. Lights\nand small appliances are connected to one of the wires and ground, so\nthey get 120V RMS.  Large appliances, like air conditioners and\nwashing machines, are connected across the two wires so they get 240V\nRMS.\n\n\\begin{tikzpicture}[\ntl/.style = {% tick labels fill=white, inner sep=1pt,\n  font=\\scriptsize, }, ]\n% grid\n\\draw[sdkblue, very thin, xstep=0.5235, ystep=0.425] (0,-1.85) grid\n(13,1.85);\n\n% axes\n\\draw[->,thick] (0,0) -- (13,0);\n% curve\n\\draw[thick,draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x)) * 1.7});\n\\draw[thick,dashed, draw=black,domain=0:13,samples=500,variable=\\x] plot\n(\\x,{sin(deg(\\x) + 180) * 1.7});\n\\draw[<->, thick, draw=black] (7.85398, 0) -- (7.85398, 1.7) node [midway, right] {120V};\n\\draw[<->, thick, draw=black] (4.712, -1.7) -- (4.712, 1.7);\n\\draw (4.712, 0.8) node[right] {240V};\n\\end{tikzpicture}\n\n\nHow do you get two circuits, 180 degrees out of phase, from one\ncircuit?  Using a center-tap transformer.\n\nFIXME: Diagram here\n\n\n\n\n", "meta": {"hexsha": "095d912f382f4acc0c85cf63a098e49e9511a72e", "size": 11592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Oscillations/ac-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/ac-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/ac-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": 36.5678233438, "max_line_length": 125, "alphanum_fraction": 0.6975500345, "num_tokens": 3858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.6030122237354194}}
{"text": "\\section{The bias-variance trade-off}\n\nIn smoothing in general there is a fundamental trade-off between the\nbias and variance of the estimate, and this trade-off is governed by\nthe smoothing parameter. \n\nThrough out this section we will be using an artifical example defined\nby\n\\begin{equation}\n\\label{sinexample}\ny_i = 5 \\sin (1/x) + \\epsilon_i, i=1,\\dots,n\n\\end{equation}\nwith the $\\epsilon_i$ IID $N(0,1)$ or $t_3$. \n\n\\begin{figure}\n\\centerline{\\epsfig{figure=Plots/plot-05-01.ps,angle=270,width=.8\\textwidth}}\n\\caption{Outcomes of model with $f(x) = 5\\sin(1/x)$ and IID normal\n  errors with $\\sigma^2=1$}\n\\end{figure}\n\nThe trade-off is most easily seen in the case of the running mean\nsmoother. The fitted running-mean smooth can be written as\n\\[\n\\hat{f}_k(x_0) = \\frac{1}{2k+1} \\sum_{i \\in N^S_k(x_0)} y_i\n\\]\nUnder model (\\ref{simplemodel}). The variance is easy to\ncompute. What is it? \n\nThe bias is\n\\[\n\\E[\\hat{f}_k(x_0)] -f(x_0) =  \\frac{1}{2k+1} \\sum_{i \\in N^S_k(x_0)}\n\\{ f(x_i) - f(x_0)   \\}\n\\]\n\n\nNotice that as $k$, in this case the smoothing parameter, grows the\nvariances decreases. However, the bigger the $k$ the more $f(x_i)$'s\nget into the bias.\n\nWe have no idea of what $\\sum_{i \\in N^S_k(x_0)} f(x_i)$ is\nbecause we don't know $f$! Let's see this in a more precise (not\nmuch more) way. \n\n\nSay we think that $f$ is smooth enough for us to assume that its second\nderivative $f''(x_0)$ is bounded. Taylor's theorem says we can write \n\\[\nf(x_i) = f(x_0) + f'(x_0) (x_i - x_0) + \\frac{1}{2}f''(x_0)(x_i-x_0)^2 +\no(|x_i-x_0|^2).\n\\]\nBecause $ \\frac{1}{2}f''(x_0)(x_i-x_0)^2$ is $O(|x_i-x_0|^2)$ we stop\nbeing precise and write \n\\[\nf(x_i) \\approx f(x_0) + f'(x_0) (x_i - x_0) + \\frac{1}{2}f''(x_0)(x_i-x_0)^2.\n\\]\nImplicit here is the assumption that $|x_i-x_0|$ is small. This is the\nway these asymptotics work. We assume that the kernel size\ngoes to 0 as $n$ gets big. \n\n\nWhy did we only go up to the second derivative?\n\nTo makes things simple, let's assume that the covariates $x$ are {\\it equally spaced} and\nlet $\\Delta = x_{j+1}-x_j$ we can write \n\\[\n(2k+1)^{-1}\\sum_{i \\in N^S_k(x_0)} f(x_i) \\approx f(x_0) + (2k+1)^{-1}\\frac{k(k+1)}{6} f''(x_0) \\Delta^2\n\\]\nSo now we see that the bias increases with $k^2$ and the second\nderivative of the ``true'' function $f$. This agrees with our\nintuition.\n \nNow that we have\n\\[\n\\E\\{\\hat{f}_k(x_0) - f(x_0)\\}^2 \\approx \\frac{\\sigma^2}{2k+1} + \\frac{k(k+1)}{6} f''(x_0) \\Delta^2\n\\]\nwe can actually find an optimal $k$\n\\[\nk_{opt} = \\left\\{ \\frac{9\\sigma^2}{2\\Delta^4\\{f''(x_i)\\}^2}\\right\\}\n\\]\nUsually this is not useful in practice because we have no idea of what\n$f''(x)$ is like. So how do we chose smoothing parameters?\n\nIn Figure \\ref{f5.1.2} we show the smooths obtained with a running\nmean smoother with bandwidths of 0.01 and 0.1 on 25 replicates defined\nby (\\ref{sinexample}). The bias-variance trade-off can be clearly seen.\n\n\\begin{figure}\n\\centerline{\\epsfig{figure=Plots/plot-05-02.ps,angle=270,width=.8\\textwidth}}\n\\caption{\\label{f5.1.2}Smooths using running-mean smoother with bandwidths of .01\n  and 0.1. To the right are the smooths 25 replicates}\n\\end{figure}\n\n\n\\subsection{Bias-variance trade-off for linear smoothers}\nDefine $\\bS_{\\lambda}$ as the hat matrix for a particular smoother when\nthe smoothing parameter $\\lambda$ is used. The ``smooth'' will be\nwritten as $\\hat{\\f}_{\\lambda} = \\bS_{\\lambda} \\by$. \n\nDefine \n\\[\n\\bv_{\\lambda} = \\f - \\E(\\bS_{\\lambda}\\by)\n\\] \nas the {\\it bias} vector.\n\nDefine $\\ave(\\bx^2) = n^{-1} \\sum_{i=1}^n x_i^2$ for any vector\n$\\bx$. We can derive the following formulas:\n\\begin{eqnarray*}\n\\mbox{MSE}(\\lambda) &=& n^{-1} \\sum_{i=1}^n\n\\var\\{\\hat{f}_{\\lambda}(x_i)\\} + \\ave ( \\bv_{\\lambda}^2 ) \\\\\n&=& n^{-1}\\tr(\\bS_{\\lambda}\\bS_{\\lambda}') \\sigma^2 + n^{-1}\n\\bv_{\\lambda}'\\bv_{\\lambda}\\\\\n\\mbox{PSE}(\\lambda) &=& \\{1 + n^{-1} \\tr(\\bS_{\\lambda}\\bS_{\\lambda}')\n\\} \\sigma^2 +  n^{-1}\n\\bv_{\\lambda}'\\bv_{\\lambda}.\n\\end{eqnarray*}\n\nNotice for least-squares regression $\\bS_{\\lambda}$ is idempotent so\nthat $\\tr(\\bS_{\\lambda}\\bS_{\\lambda}') = \\tr(\\bS_{\\lambda}) =\n\\mbox{rank}(\\bS_{\\lambda})$ which is usually the\nnumber of parameters in the model. This is why we will sometimes refer\nto $\\tr(\\bS_{\\lambda}\\bS_{\\lambda}')$ as the {\\it equivalent number of\n  parameters} or degrees of freedom of our smoother.\n", "meta": {"hexsha": "bf17a4509eb6cbff0c35715c22d22de66429953f", "size": 4304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-05-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-05-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-05-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": 34.9918699187, "max_line_length": 104, "alphanum_fraction": 0.6721654275, "num_tokens": 1582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.6030045827919925}}
{"text": "\\chapter{Abstract}\n\nMany contemporary proof assistants based on dependent type theories such as Coq and Agda\nare founded on the types-as-propositions paradigm where type checking a program\ncorresponds to verifying a proof of some proposition in a higher-order predicate logic.\nTo ensure decidability of type checking and consistency of the logic,\nthese proof assistants forbid nonterminating recursive functions\nusing guard predicates that only allow structurally recursive functions\nrecurring only on syntactically smaller arguments.\nHowever, these guard predicates are sometimes too restrictive\nand reject obviously-terminating functions that aren't otherwise structurally recursive,\ncreating extra work for the programmer to convince the guard checker.\n\nAn alternative is to use type-based termination checking such as sized types,\nwhere inductively-defined types are annotated with sizes.\nSuccessful type checking guarantees that functions recur only on arguments whose types have smaller sizes,\nrather than merely on syntactic subarguments.\nThere exist many sized dependent type theories,\nbut none simultaneously feature higher-rank size quantification,\nwhich allows for passing around size-preserving functions,\nand bounded size quantification,\nwhich eliminates the need for complex monotonicity checks required by prior sized type systems.\n\nIn this thesis, I design a sized dependent type theory with higher-rank and bounded sizes (\\lang),\nand show that it's suitable for theorem proving by proving its logical consistency with a syntactic model:\nby compiling \\lang into the Extensional Calculus of Inductive Constructions (\\CICE),\na variant of Coq's core type theory,\nand showing that this translation is type preserving,\nthe consistency of \\lang follows from the consistency of \\CICE.\nThis approach, unfortunately, refutes the existence of an ``infinite'' size strictly greater than all sizes,\nwhich is present in prior sized type systems to overcome the limitations of finitary size expressions,\nmeaning that some infinitary constructs aren't definable in \\lang.\n\nEven so, \\lang provides a valid foundation for sized types in a proof assistant,\nopening the way for future work on recovering expressivity lost from the lack of an infinite size\nand on restricting sized types in Agda,\nthe only (inconsistent!) implementation of sized types in a major proof assistant,\nto be consistent.", "meta": {"hexsha": "e6feacdb17246befb673b79e241ae2ab5d4ae675", "size": 2393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/abstract.tex", "max_stars_repo_name": "ionathanch/msc-thesis", "max_stars_repo_head_hexsha": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c", "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/abstract.tex", "max_issues_repo_name": "ionathanch/msc-thesis", "max_issues_repo_head_hexsha": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c", "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/abstract.tex", "max_forks_repo_name": "ionathanch/msc-thesis", "max_forks_repo_head_hexsha": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c", "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": 62.9736842105, "max_line_length": 108, "alphanum_fraction": 0.8286669453, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6030045768789629}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{xcolor}\n\\usepackage{amsthm}\n\\usepackage[mathcal]{euscript}\n\n\\usepackage{url}\n\n\\newcommand{\\Hcal}{\\mathcal{H}}\n\\newcommand{\\real}{\\mathbb{R}}\n\\newcommand{\\T}{\\mathrm{T}}\n\n\\title{Some notes on Boyle, Dykstra (1986)}\n\\author{Nazarov Ivan}\n\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\nLet $(\\Hcal, \\langle\\cdot,\\cdot\\rangle)$ be a Hilbert space. We say that $(x_n)_{n\\geq1} \n\\in \\Hcal$ converges {\\bf strongly} to $x\\in\\Hcal$ if $\\|x_n - x\\| \\to 0$. A sequence \nconverges to $x$ weakly, if $\\langle x_n, z \\rangle \\to \\langle x, z\\rangle$ for all\n$z\\in \\Hcal$. Due to continuity of $\\langle\\cdot,\\cdot\\rangle$ w.r.t the product norm\ntopology and $\\real$, strong convergence implies weak convergence.\n\nA property of sequences, crucial for optimization problems in finite-dimensional spaces,\nis strong sequential compactness: that every bounded sequence has a strongly convergent\nsubsequence (Bolzano-Weierstrass theorem). But in finite dimensional spaces it fails to\nhold.\n\n\\subsection*{Projection onto one convex set} % (fold)\n\\label{sub:projection_onto_one_convex_set}\n\nLet $C \\subseteq \\Hcal$ be a non-empty closed convex subset of $\\Hcal$. Then for any\n$g\\in \\Hcal$ there exists $g^*\\in C$ such that $\\|g - g^*\\| = \\inf_{h\\in C} \\|g - h\\|$.\nThe element $g^*$ is a projection if and only if $\\langle g - g^*, g^* - h\\rangle\n\\geq 0$ for all $h \\in C$. This follows from the minimization problem and the convexity\nof $C$.\n\nIndeed, let $f_t = g^* + t (h - g ^*)$ for any $t \\in [0, 1]$. Then we have $f_t \\in C$\nand $\\|f_t - g\\| \\geq \\|g^* - g\\|$ from the optimality of $g^*$. However\n\\begin{align*}\n  \\|f_t - g \\pm g^*\\|^2 - \\|g^* - g\\|^2\n    &= \\|f_t - g^*\\|^2 + 2 \\langle f_t - g^*, g^* - g\\rangle\n    \\\\\n    &= t^2 \\|h - g^*\\|^2 + 2 t \\langle h - g^*, g^* - g\\rangle\n    \\,,\n\\end{align*}\nwhence\n\\begin{equation} \\label{eq:proj_prop}\n  \\langle h - g^*, g^* - g\\rangle\n    = \\lim_{t \\downarrow 0}\n      \\tfrac1{2 t} \\bigl( t^2 \\|h - g^*\\|^2 + 2 t \\langle h - g^*, g^* - g\\rangle \\bigr)\n      \\geq 0\n      \\,.\n\\end{equation}\nConversely, such $g^*\\in C$ is a minimizer of $\\|h - g\\|$ for $h \\in C$:\n\\begin{equation*}\n  \\|h - g\\|^2 - \\|g - g^*\\|^2\n    = \\|h - g^*\\|^2 + 2 \\langle g^* - h, g - g^*\\rangle\n    \\geq \\|h - g^*\\|^2 \\geq 0\n    \\,.\n\\end{equation*}\n\n% subsection* projection_onto_one_convex_set (end)\n\n\\subsection*{Projection onto and intersection of convex sets} % (fold)\n\\label{sub:projection_onto_and_intersection_of_convex_sets}\n\nLet $K$ non-empty closed convex sets $C_k \\subseteq \\Hcal$ with non-empty intersection.\nConsider the following problem:\n\\begin{equation} \\label{eq:k-projection}  % \\tag{Proj}\n  \\begin{aligned}\n    & \\underset{h \\in \\Hcal}{\\text{minimize}}\n      & & \\tfrac12 \\|h - g\\|^2\n          \\,, \\\\\n    & \\text{s.t.}\n      & & h \\in C = \\bigcap_{k=1}^K C_k\n          \\,.\n  \\end{aligned}\n\\end{equation}\nDykstra's algorithm assumes that it is cheap an easy to project onto $C_k$ for any $k$,\nand proposes the following iterations: {\\bf starting} with $\\delta^0_k = 0$ and $g^0_K = g$\n{\\bf do}\n\\begin{equation} \\label{eq:dykstra_iter}  % \\tag{}\n  \\begin{aligned}\n    g^t_k\n      &= \\mathrm{proj}_{C_k}\\bigl( g^t_{k-1} + \\delta^{t-1}_k \\bigr)\n      \\,,\n      \\, g^t_0 = g^{t-1}_K\n      \\,, \\\\\n    \\delta^t_k\n      &= (g^t_{k-1} + \\delta^{t-1}_k) - g^t_k\n      \\,,\n      \\, k = 1\\ldots K\n  \\end{aligned}\n\\end{equation}\nwhere $\\mathrm{proj}_{C_k}(g) = \\arg\\min_{h \\in C_k} \\tfrac12 \\|g - h\\|^2$. Note\nthat, since $g^t_k$ is the projection of $g^t_{k-1} + \\delta^{t-1}_k$ onto $C_k$,\nthe projection property \\eqref{eq:proj_prop} implies that $\\delta^t_k$ in\n\\eqref{eq:dykstra_iter} satisfy\n\\begin{equation} \\label{eq:dykstra_prop}\n  \\forall{h\\in C_k}\n  \\,\\,\n  \\langle \\delta^t_k, g^t_k - h \\rangle\n  = \\bigl\\langle (g^t_{k-1} + \\delta^{t-1}_k) - g^t_k, g^t_k - h \\bigr \\rangle\n  \\geq 0\n  \\,.\n\\end{equation}\nIn particular, $h$ can be $g^s_k \\in C_k$ for any $s\\geq 1$ or any element of\n$\\bigcap_{j=1}^K C_j \\subseteq C_k$.\n\nBelow we shall show that iterations \\eqref{eq:dykstra_iter} converge to $g^*$, the\nsolution of \\eqref{eq:k-projection}.\n\n% subsection* projection_onto_and_intersection_of_convex_sets (end)\n\n\n\\subsection*{Working with the iterations} % (fold)\n\\label{sub:working_with_the_iterations}\n\nThe proof hinges on a key ``balance'' property of the updates in \\eqref{eq:dykstra_iter}\nand the property of the projection \\eqref{eq:proj_prop}. The relation $g^t_{k-1} - g^t_k =\n\\delta^t_k - \\delta^{t-1}_k$ implies\n\\begin{align}\n  % g^t_k - g^t_{k-1} &= \\delta^{t-1}_k - \\delta^t_k\n  %   \\,, \\notag \\\\\n  g^t_k - g^{t-1}_K\n    &= g^t_k - g^t_0\n      = \\sum_{j=1}^k (\\delta^{t-1}_j - \\delta^t_j)\n    \\,, \\notag \\\\\n  % g^t_K - g^{t-1}_K\n  %   &= \\sum_{j=1}^K \\delta^{t-1}_j - \\delta^t_j\n  %   \\,, \\notag \\\\\n  g^t_K - g^0_K\n    &= \\sum_{s=1}^t (g^s_K - g^{s-1}_K)\n    % = \\sum_{s=1}^t \\sum_{j=1}^K \\delta^{s-1}_j - \\delta^s_j\n    = \\sum_{j=1}^K \\sum_{s=1}^t (\\delta^{s-1}_j - \\delta^s_j)\n    % = \\sum_{j=1}^K \\delta^0_j - \\delta^t_j\n    = \\sum_{j=1}^K \\delta^0_j - \\sum_{j=1}^K \\delta^t_j\n    \\,, \\label{eq:tK_iterate} \\\\\n  g^t_k - g\n    &= g^t_k - g^0_K\n    = - \\sum_{j=1}^K \\delta^{t-1}_j + \\sum_{j=1}^k \\delta^{t-1}_j - \\delta^t_j\n    = - \\sum_{j=1}^k \\delta^t_j - \\sum_{j=k+1}^K \\delta^{t-1}_j\n    \\,. \\notag\n\\end{align}\nThis relation also implies that the difference $\\|g^t_{k-1} - g^*\\|^2 - \\|g^t_k - g^*\\|^2\n= \\ldots$ is\n\\begin{align*}\n  \\ldots\n    % &= 2 \\langle g^t_{k-1} - g^t_k, g^t_k - g^* \\rangle\n    %   + \\| \\delta^t_k - \\delta^{t-1}_k \\|^2\n    &= 2 \\langle \\delta^t_k - \\delta^{t-1}_k, g^t_k - g^* \\rangle\n      + \\| \\delta^t_k - \\delta^{t-1}_k \\|^2\n    \\\\\n    &= 2 \\langle \\delta^t_k, g^t_k - g^* \\rangle\n      - 2 \\langle \\delta^{t-1}_k, g^t_k - g^* \\rangle\n      + \\| \\delta^t_k - \\delta^{t-1}_k \\|^2\n    \\\\\n    &= \\underbrace{2 \\langle \\delta^t_k, g^t_k - g^* \\rangle}_{b^t_k}\n      - \\underbrace{2 \\langle \\delta^{t-1}_k, g^{t-1}_k - g^* \\rangle}_{b^{t-1}_k}\n      + \\underbrace{2 \\langle \\delta^{t-1}_k, g^{t-1}_k - g^t_k\\rangle}_{a^{t-1}_k}\n      + \\underbrace{\\| \\delta^t_k - \\delta^{t-1}_k \\|^2}_{c^t_k}\n    \\,,\n\\end{align*}\nwith $b^0_k = 2 \\langle \\delta^0_k, g^0_k - g^* \\rangle = 0$ and $a^0_k = 2 \\langle\n\\delta^0_k, g^0_k - g^1_k\\rangle = 0$. Furthermore\n\\begin{align}\n  % \\|g^t_{k-1} - g^*\\|^2 - \\|g^t_k - g^*\\|^2\n  %   &= (b^t_k - b^{t-1}_k) + a^{t-1}_k + c^t_k\n  %   \\,, \\notag \\\\\n  \\|g^t_0 - g^*\\|^2 - \\|g^t_k - g^*\\|^2\n    &= \\sum_{j=1}^k (b^t_j - b^{t-1}_j)\n      + \\sum_{j=1}^k \\bigl( a^{t-1}_j + c^t_j \\bigr)\n    \\,, \\label{eq:t0k_norm} \\\\\n  \\bigl \\| g^{t_1}_K - g^* \\bigr \\|^2 - \\bigl \\| g^{t_2}_K - g^* \\bigr \\|^2\n    % &= \\sum_{s=t_1+1}^{t_2} \\|g^{s-1}_K - g^*\\|^2 - \\|g^s_K - g^*\\|^2\n    %   \\notag \\\\\n    &= \\sum_{t=t_1+1}^{t_2} \\Bigl(\n        \\sum_{j=1}^K (b^t_j - b^{t-1}_j)\n          + \\sum_{j=1}^K \\bigl( a^{t-1}_j + c^t_j \\bigr)\n        \\Bigr)\n      \\notag \\\\\n    % &= \\sum_{j=1}^K \\sum_{t=t_1+1}^{t_2} (b^t_j - b^{t-1}_j)\n    %     + \\sum_{j=1}^K \\sum_{t=t_1+1}^{t_2} a^{t-1}_j\n    %     + \\sum_{t=t_1+1}^{t_2} \\sum_{j=1}^K c^t_j\n    %   \\notag \\\\\n    &= \\sum_{j=1}^K (b^{t_2}_j - b^{t_1}_j)\n        + \\sum_{j=1}^K \\sum_{t=t_1}^{t_2-1} a^t_j\n        + \\sum_{t=t_1+1}^{t_2} \\sum_{j=1}^K c^t_j\n      \\notag \\\\\n    &= \\sum_{j=1}^K \\Bigl( b^{t_2}_j + a^{t_1}_j - b^{t_1}_j\n          + \\sum_{t=t_1+1}^{t_2-1} a^t_j + \\sum_{t=t_1+1}^{t_2} c^t_j\n      \\Bigr)\n    \\,, \\label{eq:t1t2K_norm}\n\\end{align}\nFor $t_1 = 0$ and $t_2 = t$, we get\n\\begin{align}\n  \\|g^0_K - g^*\\|^2 - \\|g^t_K - g^*\\|^2\n    &= \\sum_{k=1}^K b^t_k\n        + \\sum_{k=1}^K \\sum_{s=1}^{t-1} a^s_k\n        + \\sum_{s=1}^t \\sum_{k=1}^K \\| \\delta^s_k - \\delta^{s-1}_k \\|^2\n      \\notag \\\\\n    &\\geq\n      \\sum_{s=1}^t \\sum_{k=1}^K \\| \\delta^s_k - \\delta^{s-1}_k \\|^2\n    = \\sum_{s=1}^t \\sum_{k=1}^K \\| g^s_{k-1} - g^s_k \\|^2\n    \\,, \\label{eq:gtk_bound}\n\\end{align}\nsince $b^t_k \\geq 0$ and $a^t_k \\geq 0$ for all $t\\geq 0$ by \\eqref{eq:dykstra_prop}.\nThe first and the last lines imply that $\\|g^0_K - g^*\\| \\geq \\|g^t_k - g^*\\|$, whence\n$(g^t_k)_{t\\geq1}$ is bounded for all $k$.\n\n% subsection* working_with_the_iterations (end)\n\n\\subsection*{Limiting properties} % (fold)\n\\label{sub:limiting_properties}\n\nThis section somewhat follows the proof in \\cite{boyledykstra1986}.\n\nThe partial sum in the right hand side of \\eqref{eq:gtk_bound} is bounded, therefore\nthe limit exists and the series $\\sum_{t\\geq 1} \\sum_{k=1}^K \\| g^t_{k-1} - g^t_k \\|^2$\nconverge. This implies that for any $k$ we have $\\|g^t_{k-1} - g^t_k\\|^2 \\to 0$ as\n$t\\to \\infty$. Furthermore, if $(g^t_k)_{t\\geq 1}\\in \\Hcal$ converges strongly to\n$h$, then so does $(g^t_p)_{t\\geq 1}$ for any $p=1,\\,\\ldots,\\,K$: indeed\n\\begin{equation*}\n  \\limsup_{t\\to \\infty} \\| g^t_p - h \\|\n    \\leq \\limsup_{t\\to \\infty} \\|g^t_k - h\\|\n      + \\sum_{j=p+1}^k \\limsup_{t\\to \\infty} \\| g^t_{j-1} - g^t_j \\|\n    \\,.\n\\end{equation*}\nTherefore proving the convergence of $(g^t_K)_{t\\geq 1}$ is sufficient.\n\nFor any $f\\in C = \\bigcap_{k=1}^K C_k$ we have $\\langle \\delta^t_k,  g^t_k - f \\rangle\n\\geq 0$ by \\eqref{eq:dykstra_prop}, whence\n\\begin{equation*}\n  \\langle g^t_1 - f, g^t_K - g \\rangle\n    % = - \\sum_{k=1}^K \\langle g^t_1 \\pm g^t_k - f, \\delta^t_k \\rangle\n    = \\sum_{k=1}^K \\langle g^t_k - g^t_1, \\delta^t_k \\rangle\n      + (-1) \\sum_{k=1}^K \\langle g^t_k - f, \\delta^t_k \\rangle\n    \\leq \\sum_{k=2}^K \\langle g^t_k - g^t_1, \\delta^t_k \\rangle\n      \\,.\n\\end{equation*}\nIf we put $d_t = \\sum_{k=2}^K \\| g^t_{k-1} - g^t_k \\|$, then we get\n\\begin{align*}\n  \\sum_{k=2}^K \\bigl\\lvert \\langle g^t_k - g^t_1, \\delta^t_k \\rangle \\bigr\\rvert\n    &\\leq \\sum_{k=2}^K \\|\\delta^t_k\\| \\| g^t_k - g^t_1 \\|\n    \\leq \\sum_{k=2}^K \\|\\delta^t_k\\| \\sum_{j=2}^k \\| g^t_{j-1} - g^t_j \\|\n    \\\\\n    &\\leq \\sum_{k=2}^K \\|\\delta^t_k\\| \\, d_t\n    = \\sum_{k=2}^K d_t \\Bigl\\| \\sum_{s=1}^t (\\delta^s_k - \\delta^{s-1}_k) \\Bigr\\|\n    \\\\\n    &\\leq \\sum_{k=2}^K \\sum_{s=1}^t d_t \\|\\delta^s_k - \\delta^{s-1}_k \\|\n    = \\sum_{s=1}^t \\sum_{k=2}^K d_t \\|g^s_{k-1} - g^s_k \\|\n    = \\sum_{s=1}^t d_t d_s\n      \\,.\n\\end{align*}\nObserve that by Cauchy-Schwartz (H{\\\"o}lder for $p=q=2$) inequality we have\n\\begin{equation*}\n  d_t\n    \\leq \\sum_{k=1}^K 1 \\cdot \\| g^t_{k-1} - g^t_k \\|\n    \\leq K^{\\tfrac12} \\biggl(\n      \\sum_{k=1}^K \\| g^t_{k-1} - g^t_k \\|^2\n    \\biggr)^{\\tfrac12}\n    \\,,\n\\end{equation*}\nwhich implies that\n\\begin{equation*}\n  \\sum_{t\\geq 1} d^2_t\n    \\leq K \\sum_{t\\geq 1} \\sum_{k=1}^K \\| g^t_{k-1} - g^t_k \\|^2\n      < +\\infty\n    \\,.\n\\end{equation*}\nFor such series there is $(t_n)_{n\\geq1} \\uparrow$ such that $\\sum_{s=1}^{t_n} d_s\nd_{t_n} \\to 0$ ({\\bf \\color{red} WHY?}). Hence\n\\begin{equation*}\n  \\limsup_{n \\to \\infty} \\langle g^{t_n}_1 - f, g^{t_n}_K - g \\rangle\n    \\leq \\limsup_{n \\to \\infty} \\sum_{s=1}^{t_n} d_s d_{t_n}\n    = 0\n    \\,.\n\\end{equation*}\nSince $\\|g^t_{k-1} - g^t_k \\| \\to 0$ as $t\\to \\infty$ and $(g^t_k)_{t\\geq1}$ is\nbounded for all $k$, we have\n\\begin{align*}\n  \\langle g^{t_n}_K - f, g^{t_n}_K - g \\rangle\n    &= \\langle g^{t_n}_1 - f, g^{t_n}_K - g \\rangle\n        + \\sum_{j=2}^K \\langle g^{t_n}_j - g^{t_n}_{j-1}, g^{t_n}_K - g \\rangle\n      \\\\\n    &\\leq \\langle g^{t_n}_1 - f, g^{t_n}_K - g \\rangle\n      + \\bigl(\n        \\|g\\| + \\sup_{t,k\\geq 1} \\|g^t_k\\|\n      \\bigr) \\sum_{j=2}^K \\|g^{t_n}_j - g^{t_n}_{j-1}\\|\n      \\,.\n\\end{align*}\nTherefore the right-hand side not greater than zero in the upper limit.\n\nNext, since $\\|g^{t_n}_k\\|$ is bounded, it has a convergent subsequence in $\\real$.\nWe can assume that $t_n$ itself is this subsequence, since refining convergent\nsequences does not affect its limiting properties.\n\nFinally, by weak compactness the bounded sequence $(g^{t_n}_K)_{n\\geq 1}$ has another\nsubsequence that weakly converges to some $h \\in \\Hcal$. Again, we are free to let\n$(t_n)_{n\\geq 1}$ be that subsequence.\n\n% So far we have shown that the iterates $g^t_k$ have the following properties:\n% \\begin{itemize}\n%   \\item $(g^t_k)_{t\\geq 1}$ is bounded for all $k$;\n%   \\item if $(g^t_K)_{t\\geq 1}$ converges strongly then so do $(g^t_k)_{\\geq t}$ for $k=1..K$;\n%   \\item there is $(t_n)_{n\\geq1} \\uparrow$ with $\\lim_{n\\to 0} \\langle g^{t_n}_K - f,\n%   g^{t_n}_K - g \\rangle \\leq 0$ for all $f\\in C$.\n% \\end{itemize}\n\n% subsection* limiting_properties (end)\n\n\\subsection*{Finding a convergent sequence} % (fold)\n\\label{sub:finding_a_convergent_sequence}\n\nWe have shown that the iterates $g^t_k$ of \\eqref{eq:dykstra_iter} admit\n$(t_n)_{n \\geq 1} \\uparrow$ such that\n\\begin{itemize}\n  \\item there is $h\\in \\Hcal$ with $g^{t_n}_K \\rightharpoonup h$;\n  \\item there exists $L \\in \\real$ with $\\|g^{t_n}_K\\| \\to L$;\n  \\item $\\limsup_{n\\to \\infty} \\langle g^{t_n}_K - f, g^{t_n}_K - g \\rangle \\leq 0$\n  for all $f\\in C = \\bigcap_{k=1}^K C_k$.\n\\end{itemize}\nObserve also, that if $x_n \\rightharpoonup x$ and $\\|x_n\\| \\to L$, then from\n\\begin{equation*}\n  \\|x\\|^2\n    = \\limsup_{n\\to \\infty} \\langle x_n, x\\rangle\n    \\leq \\limsup_{n\\to \\infty} \\|x_n\\| \\|x\\|\n    = L \\|x\\|\n    \\,,\n\\end{equation*}\nwe conclude that $\\|x\\| \\leq L$. We apply this to $x_n = g^{t_n}_K$ and $x = h$ to\nget $\\|h\\|\\leq L$.\n\nFrom the properties of $(t_n)_{n\\geq1}$ we have\n\\begin{align} \\label{eq:weak_lim_equ}\n  \\limsup_{n\\to \\infty}\n    \\langle g^{t_n}_K - f, g^{t_n}_K - g \\rangle\n    &= \\limsup_{n\\to \\infty} \\bigl(\n        \\|g^{t_n}_K\\|^2 - \\langle g^{t_n}_K, g \\rangle - \\langle f, g^{t_n}_K \\rangle\n      \\bigr) + \\langle f, g \\rangle\n    \\notag \\\\\n    &= L^2 - \\langle h, g \\rangle - \\langle h, g \\rangle\n      + \\langle f, g \\rangle \\pm \\|h\\|^2\n    \\notag \\\\\n    &= L^2 - \\|h\\|^2 + \\langle h - f, h - g \\rangle\n  \\,,\n\\end{align}\nand thus $\\langle h - f, h - g \\rangle \\leq 0$ for any $f \\in C$.\n\nNext, for any $f\\in \\Hcal$ and $k=1..K$ we have the following inequality\n\\begin{equation*}\n  \\limsup_{n\\to\\infty}\\,\n    \\bigl\\lvert\n      \\langle g^{t_n}_K, f \\rangle - \\langle g^{t_n}_k, f \\rangle\n    \\bigr\\rvert\n    \\leq\n      \\|f\\| \\sum_{j=k+1}^K \\limsup_{n\\to\\infty}\n        \\bigl \\|g^{t_n}_{j-1} - g^{t_n}_j \\bigr \\|\n      \\,,\n\\end{equation*}\nwhich implies that $g^{t_n}_k \\rightharpoonup h$ for any $k$. However, for any $k$\nfrom the weak convergence of $x_n = g^{t_n}_k$ to $h$ it is possible to deduce that\nthere is a subsequence $(n^k_i)_{i\\geq1}$ with $\\tfrac1m \\sum_{i=1}^m x_{n^k_i} \\to h$\nstrongly ({\\bf \\color{red} WHY?}). Therefore $h \\in C_k$, since $x_{n^k_i} \\in C_k$\nfor all $i$, and $C_k$ is convex and {\\bf strongly closed}.\n\nTherefore, the weak limit $h$ of $g^{t_n}_k$ is in $C$. From \\eqref{eq:weak_lim_equ}\nfor $f = h$ we conclude that $0 \\geq L^2 - \\|h\\|^2$, whence $\\|h\\| = L$. This implies\nthat $g^{t_n}_k \\to h$, because\n\\begin{equation*}\n  \\limsup_{n\\to\\infty} \\| g^{t_n}_k - h \\|^2\n    = \\| h \\|^2 + \\limsup_{n\\to\\infty} \\|g^{t_n}_k\\|^2 - 2\\langle g^{t_n}_k, h \\rangle\n    = \\| h \\|^2 + L^2 - 2 \\| h \\|^2\n    \\,.\n\\end{equation*}\nTo conclude, we have found a subsequence $(t_n)_{n\\geq1} \\uparrow$ such that\n\\begin{itemize}\n  \\item $g^{t_n}_k \\to h$ strongly for any $k$ and $h=g^*$, since $h \\in C$ and\n  satisfies \\eqref{eq:proj_prop}.\n\\end{itemize}\n\n% subsection* finding_a_convergent_sequence (end)\n\n\\subsection*{Back to the iterations} % (fold)\n\\label{sub:back_to_the_iterations}\n\nFor any $t \\geq t_n$ the result in \\eqref{eq:t1t2K_norm} implies\n% \\begin{align*}\n%   \\bigl \\| g^{t_n}_K - g^* \\bigr \\|^2\n%     &= \\bigl \\| g^t_K - g^* \\bigr \\|^2\n%       + \\sum_{j=1}^K (b^t_j - b^{t_n}_j)\n%       + \\sum_{j=1}^K \\sum_{s=t_n}^{t-1} a^s_j\n%       + \\sum_{j=1}^K \\sum_{s=t_n+1}^t c^s_j\n%       \\\\\n%     &\\geq \\bigl \\| g^t_K - g^* \\bigr \\|^2\n%       - \\sum_{j=1}^K b^{t_n}_j\n%     \\,,\n% \\end{align*}\n\\begin{equation*}\n  \\bigl \\| g^t_K - g^* \\bigr \\|^2\n    \\leq \\bigl \\| g^{t_n}_K - g^* \\bigr \\|^2\n    + \\sum_{k=1}^K b^{t_n}_k\n    \\leq \\bigl \\| g^{t_n}_K - g^* \\bigr \\|^2\n    + 2 \\Bigl \\lvert\n        \\sum_{k=1}^K \\langle \\delta^{t_n}_k, g^{t_n}_k - g^* \\rangle\n      \\Bigr \\rvert\n    \\,.\n\\end{equation*}\nSince \\eqref{eq:tK_iterate} implies $g - g^t_K = \\sum_{k=1}^K \\delta^t_k$, we\ncan get the following upper bound\n\\begin{align*}\n  \\Bigl \\lvert \\sum_{k=1}^K \\langle \\delta^t_k, g^* - g^t_k \\rangle \\Bigr \\rvert\n    &= \\Bigl \\lvert\n      \\Bigl\\langle \\sum_{k=1}^K \\delta^t_k, g^* - g^t_1 \\Bigr \\rangle\n      + \\sum_{k=1}^K \\langle \\delta^t_k, g^t_1 - g^t_k \\rangle\n      \\Bigr \\rvert\n      \\\\\n    &\\leq \\bigl\\lvert \\langle g^t_K - g, g^t_1 - g^* \\rangle \\bigr\\rvert \n      + \\sum_{k=2}^K \\bigl\\lvert \\langle \\delta^t_k, g^t_k - g^t_1 \\rangle \\bigr\\rvert \n      \\\\\n    &\\leq \\bigl\\lvert \\langle g^t_K - g, g^t_1 - g^* \\rangle \\bigr\\rvert \n      + \\sum_{s=1}^t d_t d_s\n      \\,.\n\\end{align*}\nApplying this bound to the subsequence $(t_n)_{n\\geq1}$ we get in the limit\n\\begin{align*}\n  \\limsup_{n\\to \\infty}\n    \\Bigl \\lvert \\sum_{k=1}^K \\langle \\delta^{t_n}_k, g^* - g^{t_n}_k \\rangle \\Bigr \\rvert\n    &\\leq \\limsup_{n\\to \\infty}\n      \\bigl\\lvert \\langle g^{t_n}_K - g, g^{t_n}_1 - g^* \\rangle \\bigr\\rvert\n      + \\limsup_{n\\to \\infty} \\sum_{s=1}^{t_n} d_s d_{t_n}\n      \\\\\n    &\\leq \\limsup_{n\\to \\infty} \\|g^{t_n}_K - g\\| \\|g^{t_n}_1 - g^* \\|\n      = 0\n    \\,,\n\\end{align*}\nbecause $g^{t_n}_k \\to g^*$ and $g^t_k$ is bounded. Therefore for any $\\varepsilon > 0$\nthere is $N_\\varepsilon \\geq 1$ such that $\\|g^{t_n}_K - g^*\\|^2 < \\tfrac\\varepsilon2$\nand $\\lvert \\sum_{k=1}^K \\langle \\delta^{t_n}_k, g^* - g^{t_n}_k \\rangle \\rvert <\n\\tfrac\\varepsilon4$ for every $n \\geq N_\\varepsilon$. Hence for all $t \\geq T_\\varepsilon$,\n$T_\\varepsilon = t_{N_\\varepsilon + 1}$, we get\n\\begin{equation*}\n  \\bigl \\| g^t_K - g^* \\bigr \\|^2\n    \\leq \\bigl \\| g^{t_n}_K - g^* \\bigr \\|^2\n    + 2 \\Bigl \\lvert\n        \\sum_{k=1}^K \\langle \\delta^{t_n}_k, g^{t_n}_k - g^* \\rangle\n      \\Bigr \\rvert\n    < \\tfrac\\varepsilon2 + 2 \\tfrac\\varepsilon4\n    \\,.\n\\end{equation*}\nTherefore $g^t_k$ converges strongly to $g^*$ for any $k=1\\,, \\ldots\\,,K$.\n\n% subsection* back_to_the_iterations (end)\n\n\\subsection*{Application to the GLS estimate} % (fold)\n\\label{sub:application_to_the_gls_estimate}\n\nThe GLS estimate of $y\\sim X$ with weights $\\Omega$ is $\\hat{\\beta} = \\bigl(X^\\T \\Omega^{-1} X\n\\bigr)^{-1} X^\\T \\Omega^{-1} y$ and solves the unconstrained problem\n\\begin{equation} \\label{eq:gls_unc}\n  \\begin{aligned}\n    & \\underset{\\beta\\in \\real^p}{\\text{minimize}}\n      & & \\tfrac12 \\bigl(y - X \\beta\\bigr)^\\T \\Omega^{-1} \\bigl(y - X \\beta\\bigr)\n          \\,.\n  \\end{aligned}\n\\end{equation}\n\nNoting that the objective can be rewritten as\n\\begin{align*}\n  \\bigl(y - X \\beta\\bigr)^\\T \\Omega^{-1} \\bigl(y - X \\beta\\bigr)\n    &= \\bigl(y - X \\hat{\\beta}\\bigr)^\\T \\Omega^{-1} \\bigl(y - X \\hat{\\beta}\\bigr)\n    \\\\\n    &+ 2 \\bigl(y - X \\hat{\\beta}\\bigr)^\\T \\Omega^{-1} X \\bigl(\\hat{\\beta} - \\beta\\bigr)\n    \\\\\n    &+ \\bigl(X \\hat{\\beta} - X \\beta\\bigr)^\\T \\Omega^{-1} \\bigl(X \\hat{\\beta} - X \\beta\\bigr)\n    \\,.\n\\end{align*}\nand that\n\\begin{align*}\n  \\bigl(y - X \\hat{\\beta}\\bigr)^\\T\n    &= \\bigl(y - X \\bigl(X^\\T \\Omega^{-1} X \\bigr)^{-1} X^\\T \\Omega^{-1} y\\bigr)^\\T \\Omega^{-1} X\n    \\\\\n    &= y^\\T \\Omega^{-\\T} \\bigl(\\Omega - X \\bigl(X^\\T \\Omega^{-1} X \\bigr)^{-1} X^\\T \\bigr)^\\T \\Omega^{-1} X\n    \\\\\n    &= y^\\T \\Omega^{-1} \\bigl(X - X \\bigl(X^\\T \\Omega^{-1} X \\bigr)^{-1} X^\\T \\Omega^{-1} X \\bigr)\n    = y^\\T \\Omega^{-1} \\bigl(X - X\\bigr)\n    \\,,\n\\end{align*}\nwe get a reformulation of the constrained GLS problem\n\\begin{equation} \\label{eq:gls_proj}\n  \\begin{aligned}\n    & \\underset{\\beta\\in C}{\\text{minimize}}\n      & & \\tfrac12 \\bigl(\\beta - \\hat{\\beta} \\bigr)^\\T X^\\T \\Omega^{-1} X \\bigl(\\beta - \\hat{\\beta}\\bigr)\n          \\,,\n  \\end{aligned}\n\\end{equation}\nas a projection of $\\hat{\\beta}$ onto $C$ with respect a special metric.\n\n% subsection* application_to_the_gls_estimate (end)\n\n\\end{document}\n", "meta": {"hexsha": "a340f656621bc1e23a9701d61815c62c704121b5", "size": 19736, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scribbles/dykstra1986.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": "scribbles/dykstra1986.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": "scribbles/dykstra1986.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": 38.6223091977, "max_line_length": 107, "alphanum_fraction": 0.5763579246, "num_tokens": 8722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6030045768789629}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Central limit theorem}\\label{sec:clt}\n\nWe will need the following definition of the exponential function $e^x$. This is one of several equivalent definitions.\n\\begin{definition}[The compound interest formula]\\label{def:compound_interest_formula}\nThe exponential function can be defined by\n\\[\ne^x = \\lim_{n\\to\\infty}\\left(1+\\frac{x}{n}\\right)^{n}.\n\\]\n\\end{definition}\n\n%\\begin{lemma}\\label{def:compound_interest_formula}\n%For any constant $c\\in\\R$,\n%\\[\n%\\left(1+\\frac{c}{n}\\right)^n\\to e^c \\quad\\text{as}\\quad n\\to\\infty.\n%\\]\n%\\end{lemma}\n%\\begin{proof}\n%By the binomial theorem,\n%\\begin{align*}\n%\\left(1+\\frac{c}{n}\\right)^n\n%\t& = \\sum_{k=1}^n \\binom{n}{k}\\left(\\frac{c}{n}\\right)^k \\\\\n%\t& = \\sum_{k=1}^n \\frac{n!}{(n-k)!k!}\\left(\\frac{c^k}{n^k}\\right) \\\\\n%\t& = \\sum_{k=1}^n \\frac{c^k}{k!}\\left(\\frac{n(n-1)\\ldots(n-k+1)}{n^k}\\right) \\\\\n%\t& = \\sum_{k=1}^n \\frac{c^k}{k!}\\left[1\\left(1-\\frac{1}{n}\\right)\\left(1-\\frac{2}{n}\\right)\\cdots\\left(1-\\frac{k+1}{n}\\right)\\right] \\\\\n%\t& \\to \\sum_{k=1}^{\\infty} \\frac{c^k}{k!} = e^c \\quad\\text{as}\\quad n\\to\\infty.\n%\\end{align*}\n%\\end{proof}\n\n%-----------------------------\n\\subsection{The Poisson limit theorem}\n\nThe Poisson limit theorem asserts that the $\\text{Binomial}(n,p)$ distribution can be approximated by the $\\text{Poisson}(np)$ distribution when $n$ is large and $p$ is small.\n\n% theorem\n\\begin{theorem}[Poisson limit theorem]\nIf $X_n\\sim\\text{Binomial}(n,\\lambda/n)$ then the distribution of $X_n$ converges to the $\\text{Poisson}(\\lambda)$ distribution as $n\\to\\infty$.\n\\end{theorem}\n\n% proof\n\\begin{proof}\nBy the inversion theorem for CFs, it is enough to show that the CF of $X_n$ converges to the CF of the $\\text{Poisson}(\\lambda)$ distribution as $n\\to\\infty$. \n\n\\bigskip\nRecall that\n\\bit\n\\it the CF of the $\\text{Binomial}(n,p)$ distribution is $\\phi(t)=(1-p+pe^{it})^n$, and\n\\it the CF of the $\\text{Poisson}(\\lambda)$ distribution is $\\phi(t)=e^{\\lambda(e^{it}-1)}$.\n\\eit\nThe CF of $X_n\\sim\\text{Binomial}(n,\\lambda/n)$ is therefore\n\\[\n\\phi_{X_n}(t) \n\t= \\expe(e^{itX_n}) \n\t= \\left(1-\\frac{\\lambda}{n} + \\frac{\\lambda}{n}e^{it}\\right)^n\n\t= \\left[1 + \\frac{\\lambda(e^{it}-1)}{n}\\right]^n\n\\]\nBy definition~\\ref{def:compound_interest_formula},\n\\[\n\\phi_{X_n}(t) \\to e^{\\lambda(e^{it}-1)}\\quad\\text{as}\\quad n\\to\\infty.\n\\]\nThis is the CF of the $\\text{Poisson}(\\lambda)$ distribution, and the result follows by the inversion theorem for CFs.\n\\end{proof}\n\n%-----------------------------\n%\\subsubsection{Taylor approximation}\nLet $X$ be a random variable and let $\\phi_X$ be its characteristic function (CF). We can use the series expansion of the exponential function to show that\n\\begin{align*}\n\\phi_X(t) \n\t= \\expe(e^{itX})\n\t& = \\sum_{k=0}^{\\infty} \\frac{\\expe(X^k)}{k!}(it)^k \\\\\n\t& = 1 + i\\expe(X)t - \\frac{\\expe(X^2)}{2}t^2 -i\\frac{\\expe(X^3)}{6}t^3 + \\ldots\n\\end{align*}\n\n%Characteristic functions $\\phi(t)$ converge for all $t$, and are therefore equal to their \\emph{Taylor series}:\n%\\[\n%\\phi(t) = \\sum_{k=0}^{\\infty} \\frac{\\phi^{(k)}(0)}{k!} t^k \n%\\]\n%where $\\phi^{(k)}(0)$ is the $k$th derivative of $\\phi(t)$ evaluated at $0$, which reduces to\n%\\[\n%\\phi(t)\t= 1 + i\\expe(X)t - \\frac{\\expe(X^2)}{2}t^2 -i\\frac{\\expe(X^3)}{6}t^3 + \\ldots\n%\t\\qquad\\text{for all $|t|<R$.}\n%\\]\nWhen $t$ is small, $t^2$ is smaller and $t^3$ is smaller still: as $k$ increases the corresponding terms thus contribute less and less to the value of the sum. We can therefore approximate $\\phi(t)$ by taking only the first few terms of the sum, and this approximation becomes increasingly accurate as $t$ tends to zero.\n\n\\bigskip\n\\begin{tabular}{lll}\\hline\nLinear (first order)\t& $\\phi(t) =\t1 + i\\expe(X)t + o(t)$ \t\t\t\t\t\t\t\t& as $t\\to 0$, \\\\\nQuadratic (second order)& $\\phi(t) =\t1 + i\\expe(X)t - \\frac{1}{2}\\expe(X^2)t^2 + o(t^2)$ \t& as $t\\to 0$, \\\\\nCubic (third order) \t& $\\phi(t) =\t1 + \\expe(X)t + \\frac{1}{2}\\expe(X^2)t^2 + \\frac{1}{6}\\expe(X^3)t^3 + o(t^3)$ & as $t\\to 0$. \\\\ \\hline\n\\end{tabular}\n\\bigskip\n\nHere $o(t^k)$ represents a quantity that converges to zero faster than $t^k$ in the sense that $o(t^k)/t^k\\to 0$ as $t\\to 0$. Such quantities are represented in this way to indicate that they can be safely ignored when $t$ is sufficiently small. A second order approximation will be needed to prove the central limit theorem. \n\n%-----------------------------\n\\subsection{The central limit theorem}\n\nLet $X_1,X_2,\\ldots$ be independent and identically distributed random variables and consider the sequence of partial sums\n\\[\nS_n = X_1 + X_2 + \\ldots + X_n.\n\\]\nBy independence, $\\expe(S_n)=n\\mu$ and $\\var(S_n)=n\\sigma^2$.\n\nBy the law of large numbers, $S_n$ is approximately equal to its mean $n\\mu$ when $n$ is large. This however does not say much about the \\emph{distribution} of $S_n$ when $n$ is large. \n%\\eit\n\n\\bigskip\nIt turns out that if the $X_i$ have finite mean and variance then \\emph{irrespective of the distribution of the $X_i$} the distribution of the standardised sums\n\\[\nZ_n = \\frac{S_n-\\expe(S_n)}{\\sqrt{\\var(S_n)}} %= \\frac{S_n - n\\mu}{\\sigma\\sqrt{n}}\n\\qquad\\text{or equivalently}\\qquad\nZ_n=\\frac{1}{\\sqrt{n}}\\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma}\\right)\n\\]\nconverges to the standard normal distribution $N(0,1)$ as $n\\to\\infty$.\n\n% theorem\n\\begin{theorem}[Central limit theorem]\nLet $X_1,X_2,\\ldots$ be a sequence of independent and identically distributed with common mean $\\mu$ and variance $\\sigma^2$. If $\\mu$ and $\\sigma^2$ are both finite, then the distribution of the standardised sums\n%\\[\n%Z_n = \\frac{S_n - n\\mu}{\\sigma\\sqrt{n}}\\qquad\\text{where}\\qquad S_n=X_1+\\ldots+X_n,\n%\\]\n\\[\n%Z_n=\\frac{\\sum_{i=1}^n X_i - n\\mu}{\\sigma\\sqrt{n}}\n%\\qquad\\text{or equivalently}\\qquad\nZ_n=\\frac{1}{\\sqrt{n}}\\sum_{i=1}^n\\left(\\frac{X_i-\\mu}{\\sigma}\\right)\n\\]\nconverges to the standard normal distribution $\\text{N}(0,1)$ as $n\\to\\infty$.\n\\end{theorem}\n\n\\begin{proof}\nLet $\\displaystyle Y_i = \\frac{X_i-\\mu}{\\sigma}$. Then $\\expe(Y_i)=0$ and $\\var(Y_i)=1$, and \n\\[\nZ_n  = \\frac{1}{\\sqrt{n}}\\sum_{i=1}^n Y_i \n\\]\n\n\\bit\n\\it Let $\\phi_Y(t)$ denote the common CF of the $Y_i$.\n\\it Let $\\phi_{Z_n}(t)$ denote the CF of $Z_n$.\n\\eit\nBy Taylor's theorem, \n\\[\n\\phi_Y(t) = \\expe(e^{itY}) = \\sum_{j=0}^k \\frac{\\expe(Y^j)}{j!}(it)^j + o((it)^k) \\qquad\\text{as}\\quad t\\to 0.\n\\]\n\nTaking the first three terms in the Taylor expansion of $\\phi_Y(t)$, since $\\expe(Y)=0$ and $\\expe(Y^2)=1$ we get\n\\[\n\\phi_Y(t) =  1 - \\frac{1}{2}t^2 + o(t^2) \\quad\\text{as}\\quad t\\to 0\n\\]\n\nBy the properties of CFs, \n\\begin{align*}\n\\phi_{Z_n}(t)\n\t& = \\phi_{\\frac{1}{\\sqrt{n}}(Y_1+Y_2+\\ldots+Y_n)}(t) \\\\\n\t& = \\phi_{Y_1+Y_2+\\ldots+Y_n}\\left(\\frac{t}{\\sqrt{n}}\\right) \\\\\n\t& = \\left[\\phi_Y\\left(\\frac{t}{\\sqrt{n}}\\right)\\right]^n \\\\\n\t& = \\left[1 - \\frac{t^2}{2n} + o\\left(\\frac{t^2}{n}\\right)\\right]^n \\quad\\text{as $t\\to 0$}\\\\\n\t& \\to e^{-\\frac{1}{2}t^2} \\quad\\text{as $n\\to\\infty$},\n\\end{align*}\nwhere the last step follows by definition~\\ref{def:compound_interest_formula}. This is the CF of the $\\text{N}(0,1)$ distribution, and the result follows by the inversion theorem for CFs.\n\\end{proof}\n\n% example (Erlang)\n\\begin{example}\nThe \\emph{Erlang distribution} with parameters $n\\in\\N$ and $\\lambda>0$ is defined to be the sum of $n$ independent and identically distributed random variables $X_1,X_2,\\ldots,X_n$, where each $X_i$ is exponentially distributed with (rate) parameter $\\lambda$. Show that if $S_n\\sim\\text{Erlang}(n,\\lambda)$, then the random variable \n\\[\nZ_n=\\displaystyle\\frac{\\lambda S_n-n}{\\sqrt{n}}\n\\]\nhas approximately the standard normal distribution when $n$ is large.\n\\end{example}\n\n\\begin{solution}\nLet $S_n\\sim\\text{Erlang}(n,\\lambda)$. Then $S_n$ can be written as the sum of $n$ independent and identically distributed random variables $X_i$:\n\\[\nS_n = X_1 + X_2 + \\ldots + X_n\\qquad\\text{where}\\quad X_i\\sim\\text{Exponential}(\\lambda).\n\\]\nSince $X_i\\sim\\text{Exponential}(\\lambda)$ with $\\lambda > 0$, we have \n\\[\n\\expe(X_i) = \\frac{1}{\\lambda} <\\infty\n\\text{\\quad and\\quad}\n\\var(X_i) = \\frac{1}{\\lambda^2} <\\infty.\n\\]\n\nFurthermore, by independence we have\n\\[\n\\expe(S_n)= \\sum_{i=1}^n \\expe(X_i) = \\frac{n}{\\lambda}\n\\qquad\\text{and}\\qquad\n\\var(S_n) =  \\sum_{i=1}^n \\var(X_i) = \\frac{n}{\\lambda^2}.\n\\]\nHence,\n\\[\n\\frac{S_n - \\expe(S_n)}{\\sqrt{\\var(S_n)}} \n\t= \\frac{S_n - n/\\lambda}{\\sqrt{n/\\lambda^2}} \n\t= \\frac{\\lambda S_n - n}{\\sqrt{n}} \n\\]\nBy the central limit theorem,\n\\[\n\\frac{S_n - \\expe(S_n)}{\\sqrt{\\var(S_n)}} \\to Z \\quad\\text{in distribution as $n\\to\\infty$,}\n\\]\nwhere $Z\\sim\\text{N}(0,1)$. \n\\end{solution}\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nThe continuous uniform distribution on $(a,b)$ has the following PDF:\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{1}{b-a} \t& a < x < b,  \\\\[2ex]\n\t0\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nUse the central limit theorem to deduce the approximate distribution of the sample mean of $n$ independent observations from this distribution when $n$ is large.\n\\begin{answer} \nThe mean is \n\\begin{align*}\n\\mu \n\t& = \\int_{a}^{b}\\frac{x}{b-a}\\,dx = \\frac{a+b}{2},\n\\intertext{and the second moment is}\n\\mu_{2}\n\t& = \\int_{a}^{b}\\frac{x^{2}}{b-a}\\,dx = \\frac{a^{2}+ab+b^{2}}{3}, \n\\intertext{so the variance is}\t\n\\sigma^{2} \n\t& = \\expe(X^{2}) - \\expe(X)^{2} = \\frac{(b-a)^{2}}{12}\n\\end{align*}\nBy the central limit theorem, if $X$ is a random variable with mean $\\mu$ and variance $\\sigma^{2}$, the distribution of the sample mean $\\bar{X}$ of a random sample of $n$ independent observations is approximately $N(\\mu,\\frac{\\sigma^{2}}{n})$, the approximation being better for larger $n$. In this case, the approximate distribution of $\\bar{X}$ is $N\\left(\\frac{a+b}{2},\\frac{(b-a)^{2}}{12n}\\right)$. \n\\end{answer}\n\n\n\\question\nThe exponential distribution with scale parameter $\\theta>0$ has the following PDF:\n\\[\nf(x) = \\begin{cases}\n\t\\displaystyle\\frac{1}{\\theta} e^{-x/\\theta} \t& x > 0,  \\\\[2ex]\n\t0\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nUse the central limit theorem to deduce the approximate distribution of the sample mean of $n$ independent observations from this distribution when $n$ is large.\n\\begin{answer} % <<<\n\\begin{align*}\n\\expe(X) \n\t& = \\frac{1}{\\theta}\\int_{0}^{\\infty} x e^{-x/\\theta}\\,dx = \\theta, \\\\\n\\expe(X^2)\n\t& = \\frac{1}{\\theta}\\int_{0}^{\\infty} x^2 e^{-x/\\theta}\\,dx  = 2\\theta^2 \\\\\n\\var(X)\n\t& = \\expe(X^2) - \\expe(X)^{2} = \\theta^2.\n\\end{align*}\n\nBy the CLT, the distribution of $\\bar{X}$ is approximately $\\text{N}(\\mu,\\frac{\\sigma^{2}}{n})$, the approximation being better for larger $n$. In this case, the approximate distribution of $\\bar{X}$ is $\\text{N}\\left(\\theta,\\theta^2/n\\right)$. \n\\end{answer}\n\n\n\\question\nWe perform a sequence of independent Bernoulli trials, each with probability of success $p$, until a fixed number $r$ of successes is obtained. The total number of failures $Y$ (up to the $r$th succes) has the \\emph{negative binomial} distribution with parameters $r$ and $p$, so the PMF of $Y$ is\n\\[\n\\prob(Y=k) = \\binom{k+r-1}{k} (1-p)^k p^r,\\qquad k=0,1,2,\\ldots\n\\]\nUsing the fact that $Y$ can be written as the sum of $r$ independent geometric random variables, show that this distribution can be approximated by a normal distribution when $r$ is large.\n\n\\begin{answer}\nIf $Y\\sim\\text{NB}(r,p)$, we can write\n\\[\nY = X_1 + X_2 + \\ldots + X_r\\qquad\\text{where}\\quad X_i\\sim\\text{Geometric}(p).\n\\]\nLet $X\\sim\\text{Geometric}(p)$. Since $\\var(X)<\\infty$, it follows by the central limit theorem that \n\\[\n\\frac{Y - r\\expe(X)}{\\sqrt{r\\var(X)}} \\to \\text{N}(0,1) \\quad\\text{in distribution as }r\\to\\infty.\n\\]\nIn fact, since $\\expe(X)=(1-p)/p$ and $\\var(X)=(1-p)/p^2$, we see that $Y$ can be approximated by the \n$\\displaystyle\\text{N}\\left(\\frac{r(1-p)}{p}, \\frac{r(1-p)}{p^2}\\right)$ distribution as $r\\to\\infty$.\n\\end{answer}\n\n\\end{questions}\n\\end{exercise}\n\n", "meta": {"hexsha": "ac6da818f9e7de15bb75c8a87aa542c2c1c5dd52", "size": 11774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/06C_central_limit_theorem.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/06C_central_limit_theorem.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/06C_central_limit_theorem.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": 42.3525179856, "max_line_length": 405, "alphanum_fraction": 0.651520299, "num_tokens": 4315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.6030045524420499}}
{"text": "\\documentclass[a4paper]{article}\n\n\\input{temp}\n\n\\begin{document}\n\n\\title{Complex Methods}\n\n\\maketitle\n\n\\newpage\n\n\\tableofcontents\n\n\\newpage\n\n\\section{Analytic Functions}\n\n\\subsection{The Complex Plane and the Riemann Sphere}\n\nRe = $\\Re$\\\\\nIm = $\\Im$\\\\\n\nAny $z \\in \\C$ can be written in the form $x+iy$ where $x=\\Re(z),y=\\Im(z)$, $x,y\\in \\R$, or $re^{i\\theta}$ where the \\emph{modulus} is $|z| = r = \\sqrt{x^2+y^2}$ and the argument $\\theta = \\arg z$ satisfies $x \\tan \\theta = y$ ($x\\sin\\theta = y\\cos\\theta$).\n\nThe argument is defined only up to multiples of $2\\pi$; the \\emph{principal value} of the argument is the value of $\\theta$ in the range $(-\\pi,\\pi]$.\n\nNote that the formula $\\tan^{-1}(\\frac{y}{x})$ gives the correct value for the principal value of $\\theta$ only if $x>0$; if $x \\leq 0$ then it might be out by $\\pm \\pi$ (consider $z=1+i$ and $-1-i$).\n\n\\begin{defi}\nAn \\emph{open set} $\\mathcal{D}$ is a subset of $\\C$ which does not include its boundary. More technically, $\\mathcal{D} \\subset \\C$ is open if $\\forall z_0 \\in \\mathcal{D}$, $\\exists \\delta > 0$ s.t. the disc $|z-z_0| < \\delta$ is contained in $\\mathcal{D}$. A \\emph{neighbourhood} of a point $z$ is an open set that contains $z$.\n\nA \\emph{domain} is an open set that is connected, i.e. is not composed of two disjoint open sets). A \\emph{simply-connected domain} is one with no holes, i.e. any curve lying in the domain can be shrunk continuously to a point.\n\\end{defi}\n\n\\includegraphics[scale=0.3]{CM_01}\n\nAmong the above three diagrams, the first is not connected, the second is not simply-connected, and the third is simply-connected.\n\n\\begin{defi}\nThe \\emph{extended complex plane} $\\C^*=\\C \\cup \\{\\infty\\}$. We can reach the 'point at infinity' by going off in any direction in the plane, and all are equivalent.\n\nConceptually, we may use the \\emph{Riemann sphere}, which is a sphere resting on the complex plane with its 'South Pole' $S$ at $z=0$.\n\\end{defi}\n\n\\includegraphics[scale=0.3]{CM_02}\n\nFor any point $z$ in $\\C$, drawing a line through the 'North Pole' $N$ of the sphere to $z$, and noting where this intersects the sphere, specifies an equivalent point $P$ on the sphere. Then $\\infty$ is equivalent to the 'North Pole' itself.\n\nTo investigate properties of $\\infty$, we use the substitution $\\zeta = \\frac{1}{z}$. A function $f(z)$ is said to have a particular property at $\\infty$ if $f(\\frac{1}{\\zeta})$ has that same property at $\\zeta = 0$. \n\n\\subsection{Complex Differentiation}\nRecall the definition of differentiation for a real function $f(x)$:\n\\begin{equation*}\n\\begin{aligned}\nf'(x) = \\lim_{\\delta x \\to 0} \\frac{f(x+\\delta x)-f(x)}{\\delta x}\n\\end{aligned}\n\\end{equation*}\nIt is implicitly that the limit must be the same whichever direction we approach from. Consider $|x|$ at $x=0$ for example; if we approach from the right ($\\delta x \\to 0^+$), then the limit is $+1$, whereas from the left ($\\delta x \\to 0^-$), it is $-1$. Because these limits are different, we say that $|x|$ is not differentiable at $x=0$.\n\nNow extend the definition to complex functions $f(z):$ $f$ is differentiable at $z$ if\n\\begin{equation*}\n\\begin{aligned}\nf'(z) = \\lim_{\\delta z\\to 0} \\frac{f(z+\\delta z)-f(z)}{\\delta z}\n\\end{aligned}\n\\end{equation*}\nexists (and is therefore independent of the direction of approach -- but now there is an infinity of possible directions).\n\nWe say that $f$ is \\emph{analytic} at a point $z$ if there exists a neighbourhood of $z$ throughout which $f'$ exists. The terms \\emph{regular} and \\emph{holomorphic} are also used. A function which is analytic throughout $\\C$ is called entire.\n\nThe property of analyticity is in fact a surprisingly strong one! For example, two consequences include:\\\\\n$\\bullet$ If a function is analytic then it is differentiable infinitely many times (c.f. the existence of real functions which can be differentiated $N$ times but no more, for any given $N$).\\\\\n$\\bullet$ A bounded entire function is a constant (c.f. $\\tanh x$ for $x \\in \\R$).\n\n\\begin{defi}\nA \\emph{singularity} of $f$ is a point at which it is \\emph{not} analytic, or not even defined.\n\\end{defi}\n\n\\begin{thm} (Cauchy-Riemann Equations)\\\\\nSeparate $f$ and $z$ into real and imaginary parts:\n\\begin{equation*}\n\\begin{aligned}\nf(z)=u(x,y)+iv(x,y)\n\\end{aligned}\n\\end{equation*}\nwhere $z=x+iy$ and $u,v$ are real functions. Suppose that $f$ is differentiable at $z$. We may take $\\delta z$ in any direction; first take it to be real, $\\delta z = \\delta x$. Then\n\\begin{equation*}\n\\begin{aligned}\nf'(z) &= \\lim_{\\delta x \\to 0} \\frac{f(z+\\delta x) - f(z)}{\\delta x}\\\\\n&=\\lim_{\\delta x\\to 0} \\frac{u(x+\\delta x,y)+iv(x+\\delta x,y) - u(x,y) - iv(x,y)}{\\delta x}\\\\\n&= \\frac{\\partial u}{\\partial x} + i \\frac{\\partial v}{\\partial x}\n\\end{aligned}\n\\end{equation*}\nNow take $\\delta z$ to be pure imaginary, i.e. $\\delta z = i\\delta y$. Then\n\\begin{equation*}\n\\begin{aligned}\nf'(z) &= \\lim_{\\delta y \\to 0} \\frac{f(z+i\\delta y) - f(z)}{i\\delta y}\\\\\n&= \\lim_{\\delta y \\to 0} \\frac{u(x,y+\\delta y) + iv(x,y+\\delta y) - u(x,y) - iv(x,y)}{i\\delta y}\\\\\n&= -i \\frac{\\partial u}{\\partial y} + \\frac{\\partial v}{\\partial y}\n\\end{aligned}\n\\end{equation*}\n\nThe two values for $f'(z)$ must be the same since $f$ is differentiable. So compare real and imaginary parts we get\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\partial u}{\\partial x} = \\frac{\\partial v}{\\partial y},\\\\\n\\frac{\\partial v}{\\partial x} = -\\frac{\\partial u}{\\partial y}\n\\end{aligned}\n\\end{equation*}\nThe \\emph{Cauchy-Riemann equations}. The converse (that a function satisfying the CR equations is differentiable) is true only if we impose additional requirements, for example that the partial derivatives $u_x,u_y,v_x,v_y$ are continuous functions of $x$ and $y$ (together), in the sense described in Analysis II.\n\\end{thm}\n\n\\begin{eg} (Analytic functions)\\\\\n(i) $f(z)=z$ is entire. We check $u=x,v=y$, and the $C-R$ equations are satisfied ($1=1$ and $0=0$).\\\\\n(ii) $f(z)=e^z = e^x(\\cos y+i\\sin y)$ is entire since\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\partial u}{\\partial x} = e^x \\cos y =\\frac{\\partial v}{\\partial y},\\\\\n\\frac{\\partial u}{\\partial y} = -e^x \\sin y = -\\frac{\\partial v}{\\partial x}\n\\end{aligned}\n\\end{equation*}\nAnd obviously the derivatives are all continuous. The derivative is\n\\begin{equation*}\n\\begin{aligned}\nf'(z)=\\frac{\\partial u}{\\partial x} + i\\frac{\\partial v}{\\partial x} = e^x \\cos y + ie^x \\sin y = e^z\n\\end{aligned}\n\\end{equation*}\nas expected.\\\\\n(iii) $f(z)=z^n$ ($n$ a positive integer) is entire.\\\\\nWriting $z=r(\\cos\\theta + i\\sin\\theta)$ we obtain $u=r^n \\cos n\\theta$ and $v=r^n \\sin n\\theta$. We can check the CR equations using $r=\\sqrt{x^2+y^2}$ and $\\tan \\theta = \\frac{y}{x}$. The derivative is $nz^{n-1}$ as expected!\\\\\n(iv) Any rational function, i.e. $f(z) = \\frac{P(z)}{Q(z)}$ where $P,Q$ are polynomials is analytic except at points where $Q(z)=0$. For instance, $f(z)=\\frac{z}{z^2+1}$ is analytic except at $\\pm i$.\\\\\n(v) Many standard real functions can be extended naturally to complex functions and obey the usual rules for their derivatives: for example:\\\\\n$\\bullet$\n\\begin{equation*}\n\\begin{aligned}\n\\sin z \\equiv \\frac{e^{iz}-e^{-iz}}{2i}\n\\end{aligned}\n\\end{equation*}\nhas derivative\n\\begin{equation*}\n\\begin{aligned}\n\\cos z \\equiv \\frac{e^{iz}+e^{-iz}}{2}\n\\end{aligned}\n\\end{equation*}\nWe can also write\n\\begin{equation*}\n\\begin{aligned}\n\\sin z = \\sin(x+iy) &= \\sin x \\cos iy + \\cos x \\sin iy\\\\\n&=\\sin x \\cosh y + i \\cos x \\sinh y\n\\end{aligned}\n\\end{equation*}\nSimilarly for $\\cos z$, $\\sinh z$, $\\cosh z$, etc.\n\n$\\bullet$ $\\log z = \\log|z|+i\\arg z$ has derivative $\\frac{1}{z}$.\n\n$\\bullet$ The product, quotient and chain rules hold in exactly the same way as for real functions. \n\\end{eg}\n\n\\begin{eg} (Non-analytic functions)\\\\\n(i) $f(z) = \\Re(z)$. We have $u=x,y=0$. But $1 \\neq 0$, so $f$ is not analytic anywhere.\\\\\n(ii) $f(z) = |z|$ has $u=\\sqrt{x^2+y^2}$ and $v=0$, and is also nowhere analytic.\\\\\n(iii) $f(z) = \\bar{z} = x-iy$ (complex conjugate) has $u=x, v=-y$. We have $1 \\neq -1$, so $f$ is also nowhere analytic.\\\\\n(iv) $f(z) = |z|^2 = x^2+y^2$ has $u=x^z+y^2$, $v=0$ are satisfied only at the origin. So $f$ is only differentiable at $z=0$. So $f$ is also nowhere analytic.\n\\end{eg}\n\n\\subsubsection{(*)Analytic continuation}\nIf we are given the values of an analytic function in some restricted region -- which could be rather small, such as a short curve somewhere in the complex plane -- then there is a \\emph{unique} extension of the function to the rest of $\\C$ that is still analytic. This extension might have some singularities, and might be multi-valued.\\\\\nThis fact can be useful in extending the domain of definition of a function. We shall see an example in section 5.2.\n\n\\subsection{Harmonic functions}\nSuppose $f(z) = u+iv$ is analytic. Then\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\partial^2 u}{\\partial x^2} = \\frac{\\partial}{\\partial x}(\\frac{\\partial u}{\\partial x}) = \\frac{\\partial}{\\partial x}(\\frac{\\partial v}{\\partial y}) = \\frac{\\partial}{\\partial y}(\\frac{\\partial v}{\\partial x}) = \\frac{\\partial}{\\partial y}(-\\frac{\\partial u}{\\partial y}) = -\\frac{\\partial^2 u}{\\partial y^2}\n\\end{aligned}\n\\end{equation*}\nSo $u$ satisfies Laplace's equation in two dimensions,\n\\begin{equation*}\n\\begin{aligned}\n\\nabla^2 u = \\frac{\\partial^2 u}{\\partial x^2} + \\frac{\\partial^2 u}{\\partial y^2} = 0\n\\end{aligned}\n\\end{equation*}\nSimilarly, so does $v$.\n\nA function satisfying Laplace's equation in an open set is said to be \\emph{harmonic} there.\n\nFunctions $u$ and $v$ satisfying the CR equations are called \\emph{harmonic conjugates}. If we know one then we can find the other, up to a constant. For example, consider $u(x,y) = x^2-y^2$, which is easily verified to be harmonic. Its harmonic conjugate $v$ satisfies\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\partial v}{\\partial y} = \\frac{\\partial u}{\\partial x} = 2x \\implies v = 2xy+g(x)\n\\end{aligned}\n\\end{equation*}\nfor some function $g(x)$. So\n\\begin{equation*}\n\\begin{aligned}\n-2y = \\frac{\\partial u}{\\partial y} = -\\frac{\\partial v}{\\partial x} = -2y - g'(x) \\implies g'(x) = 0\n\\end{aligned}\n\\end{equation*}\nSo $g(x)$ is some constant $\\alpha$. The corresponding analytic function whose real part is $u$ is therefore\n\\begin{equation*}\n\\begin{aligned}\nf(z) &= x^2-y^2+i(2xy+\\alpha)\\\\\n&=(x+iy)^2+i\\alpha\\\\\n&=z^2+i\\alpha\n\\end{aligned}\n\\end{equation*}\n\nIf the domain is not simply connected then this method might give a solution that is multi-valued. For example, if $u=\\frac{1}{2}\\log(x^2+y^2)$, which is harmonic in the domain $0 < |z| < 1$, the corresponding $f(z)$ is $\\log z$.\n\n\\subsection{Multi-valued functions}\nFor $z = re^{i\\theta}$, we define $\\log z = \\log r + i \\theta$. There are therefore infinitely many values of $\\log z$, for $\\theta$ may take an infinity of values. For example,\n\\begin{equation*}\n\\begin{aligned}\n\\log i = \\frac{\\pi i}{2}, \\frac{5\\pi i}{2}, -\\frac{3\\pi i}{2},...\n\\end{aligned}\n\\end{equation*}\nDepending on which choice of $\\theta$ we make.\n\n\\subsubsection{Branch points}\nConsider the three curves shown in the diagram.\n\n\\includegraphics[scale=0.3]{CM_03}\n\nOn $C_1$, we could choose $\\theta$ to be always in the range $(0,\\frac{\\pi}{2})$, and then $\\log z$ would be continuous and single-valued (c.s.v.) going around $C_1$. On $C_2$, we could choose $\\theta \\in (\\frac{\\pi}{2},\\frac{3\\pi}{2})$ and $\\log z$ would again be c.s.v. But for $C_3$, which encircles the origin, there is no such choice; whatever we do, $\\log z$ cannot be made c.s.v. around $C_3$ (it must either 'jump' somewhere or be multi-valued).\n\nA \\emph{branch point} of a function -- here, the origin -- is a point which is impossible to encircle with a curve on which the function is both continuous and single-valued. The function is said to have a \\emph{branch point singularity} at that point.\n\n\\begin{eg}\n(i) $\\log(z-a)$ has a branch point at $z=a$.\\\\\n(ii) $\\log (\\frac{z-1}{z+1}) = \\log(z-1) - \\log(z+1)$ has two branch points at $\\pm 1$.\\\\\n(iii) $z^\\alpha = r^\\alpha e^{i\\alpha \\theta}$ has a branch point at the origin for $\\alpha \\not\\in \\Z$. Consider a circle of radius $r_0$ centred at $O$, and suppose WLOG that we start at $\\theta = 0$ and go once round anti-clockwise.\\\\\n$\\theta$ must vary continuously to ensure continuity of $e^{i\\alpha\\theta}$, so as we get back almost to where we started, $\\theta$ will approach $2\\pi$. But then there will be a jump in $\\theta$ back to $0$ (to satisfy the single-valued requirement) and hence a jump in $z^\\alpha$ from $r_0^\\alpha e^{2\\pi i\\alpha}$ to $r_0^\\alpha$ (note that if $\\alpha \\in \\Z$ then $e^{2\\pi i\\alpha} = 1$, so there's no jump). We cannot, therefore, make $z^\\alpha$ c.s.v. on the circle.\\\\\n(iv) $\\log z$ also has a branch point at $\\infty$, because if $\\zeta = \\frac{1}{z}$ (see section 1.1), $\\log z = -\\log \\zeta$ which has a branch point at $\\zeta = 0$. Similarly, $z^\\alpha$ has a branch point at $\\infty$ for $\\alpha \\not \\in \\Z$.\\\\\n(v) $\\log(\\frac{z-1}{z+1})$ does not have a branch point at $\\infty$, because if $\\zeta = \\frac{1}{z}$ then $\\log(\\frac{z-1}{z+1}) = \\log(\\frac{1-\\zeta}{1+\\zeta})$. For $\\zeta$ close to zero, $\\frac{1-\\zeta}{1+\\zeta}$ remains close to $1$ and therefore well away from the branch point of $\\log$ at the origin. So we can encircle $\\zeta = 0$ without $\\log \\frac{1-\\zeta}{1+\\zeta}$ being discontinuous.\n\\end{eg}\n\n\\subsubsection{Branch cuts}\nIf we wish to ensure that $\\log z$ is c.s.v. on any curve, therefore, we must stop curves from encircling the origin. We do this by introducing a \\emph{branch cut} from $-\\infty$ on the real axis to the origin. No curve is allowed to cross this cut.\n\n\\includegraphics[scale=0.4]{CM_04}\n\nWe can then decide to fix on values of $\\theta$ lying in the range $(-\\pi,\\pi]$ \\emph{only}, and we have defined a \\emph{branch} of $\\log z$ which is c.s.v. on any curve $C$ that doesn't cross the cut. This branch is analytic everywhere with derivative $\\frac{1}{z}$) \\emph{except} on the negative real axis, where it is not even continuous, and at the branch point itself.\n\nThe cut described above is the canonical (i.e. standard) branch cut for $\\log z$, and the branch of $\\log z$ is called the \\emph{principal value of the logarithm}.\n\nWhat are the values of $\\log z$ just above and below the branch cut? Consider a point on the negative real axis, $z=x$, $x<0$. Just above the cut, at $z=x+i0^+$, $\\theta = \\pi$ (in the limit) so\n\\begin{equation*}\n\\begin{aligned}\n\\log z = \\log|x| + i\\pi\n\\end{aligned}\n\\end{equation*}\nJust below it, at $z=x+i0^-$, $\\log z = \\log |x| - i\\pi$.\n\nThis is not the only possible branch of $\\log z$, for example:\n\n(a) We could place the branch cut along the negative imaginary axis and choose $\\theta \\in (-\\frac{\\pi}{2},\\frac{3\\pi}{2}]$.\\\\\n(b) With a branch cut along the negative real axis, we could choose $\\theta \\in (\\pi,3\\pi]$. Then $\\log 1 = 2\\pi i$.\\\\\n(c) With the branch as illustrated, it is more difficult to write down the exact choice of $\\theta$. But this is equally valid.\n\n\\includegraphics[scale=0.3]{CM_05}\n\nAny branch cut that stops curves wrapping round the branch point will do.\n\nExactly the same considerations (and possible branch cuts) apply for $z^\\alpha = r^\\alpha e^{i\\alpha\\theta}$, $\\alpha \\not\\in \\Z$. Another way of seeing this is to note that $z^\\alpha = e^{\\alpha \\log z}$.\n\nWhenever a problem requires the use of a branch, it is important to specify it clearly. This can be done in two ways:\\\\\n$\\bullet$ Define the function and parameter range explicitly, e.g.\n\\begin{equation*}\n\\begin{aligned}\n\\Log z = \\log|z| + i\\arg z, \\arg z \\in (-\\pi,\\pi]\n\\end{aligned}\n\\end{equation*}\n$\\bullet$ Specify the location of the branch cut and give the value of the required branch at a single point not on the cut. The values everywhere else are then defined uniquely by continuity. For example, $\\log z$ with a branch cut along $\\R^-$ and $\\log 1 \\equiv 0$.\n\nNote that a branch cut \\emph{alone} does not specify a branch (compare (b) above with the principal branch, which is a different branch even though it uses the same branch cut), nor a single value of the function sufficient by itself (compare (a) and (c) above).\n\n\\subsubsection{Riemann Surfaces*}\nRiemann imagined different branches as separable copies of $\\C$, all stacked on top of each other but each one joined to the next at the branch cut. This structure is a Riemann surface.\n\n\\includegraphics[scale=0.3]{CM_06}\n\n\\subsubsection{Multiple Branch Cuts}\nWhen there is more than one branch point, we may need more than one branch cut. For\n\\begin{equation*}\n\\begin{aligned}\nf(z) = \\{z(z-1) \\}^{1/3}\n\\end{aligned}\n\\end{equation*}\nthere are branch points at $0$ and $1$, so we need two branch cuts; a possibility is shown below. Then no curve can wrap around either $0$ or $1$.\n\n\\includegraphics[scale=0.4]{CM_07}\n\nFor any $z$, write $z = re^{i \\theta}$ and $z-1$ = $r_1 e^{i\\theta}$, with $\\theta \\in (-\\pi,\\pi]$, $\\theta_1 \\in [0,2\\pi)$, and define\n\\begin{equation*}\n\\begin{aligned}\n\\{ z(z-1\\}^{1/3} = \\sqrt[3]{rr_1} e^{i(\\theta+\\theta_1)/3}.\n\\end{aligned}\n\\end{equation*}\nThis is continuous so long as we don't cross either branch cut.\n\nSometimes we need fewer branch cuts than we might think: wee the worked example.\n\n\\subsection{M$\\ddot{o}$bius maps}\nThe M$\\ddot{o}$bius map\n\\begin{equation*}\n\\begin{aligned}\nz \\to w=\\frac{az+b}{cz+d}, ad-bc \\neq 0\n\\end{aligned}\n\\end{equation*}\nis analytic except at $z=-\\frac{d}{c}$. It can be useful to consider it as a map from $\\C^*$ to $\\C^*$ ($\\C^* = \\C \\cup \\{\\infty\\}$), with $-\\frac{d}{c} \\to \\infty$ and $\\infty \\to \\frac{a}{c}$. It is then bijective, the inverse being\n\\begin{equation*}\n\\begin{aligned}\nw \\to z=\\frac{-dw+b}{cw-a}\n\\end{aligned}\n\\end{equation*}\nwhich is another M$\\ddot{o}$bius map.\n\nA circline is either a circle or a line. M$\\ddot{o}$bius maps take circlines to circlines.\n\\begin{proof}\nAny circline can be expressed as a circle of Apollonius, $|z-z_1|=\\lambda|z-z_2|$ where $z_1,z_2 \\in \\C$, $|lambda \\in \\R^+$ (recall Vectors and Matrices: the case $\\lambda = 1$ corresponds to a line, $\\lambda \\neq 1$ to a circle). We then have\n\\begin{equation*}\\tag{*}\n\\begin{aligned}\n&\\left|\\frac{-dw+b}{cw-a} - z_1\\right| = \\lambda \\left|\\frac{-dw+b}{cw-a} - z_2\\right|\\\\\n\\iff &|(cz_1+d)w-(az_1+b)| = \\lambda |(cz_2+d)w-(az_2)+b|\n\\end{aligned}\n\\end{equation*}\nIf and only if\n\\begin{equation*}\n\\begin{aligned}\n|w-w_1| = \\lambda\\left|\\frac{cz_2+d}{cz_1+d}\\right||w-w_2|\n\\end{aligned}\n\\end{equation*}\nwhere $w_1 = \\frac{az_1+b}{cz_1+d}$, $w_2 = \\frac{az_2+b}{cz_2+d}$, which is another circle of Appolonius (This proof fails if either $cz_1+d$ or $cz_2+d$ vanishes; but in either of these cases, (*) trivially represents a circle).\n\\end{proof}\n\nGeometrically it is clear that choosing three distinct points in $\\C^*$ uniquely specifies a circline (If one of the points is $\\infty$ then we have specified a straight line through the other two points).\n\nGiven $\\alpha,\\beta,\\gamma,\\alpha',\\beta',\\gamma' \\in \\C^*$, we can find a M$\\ddot{o}$bius map which sends $\\alpha \\to \\alpha'$, $\\beta \\to \\beta'$, $\\gamma \\to \\gamma'$.\n\\begin{proof}\nThe M$\\ddot{o}$bius map\n\\begin{equation*}\n\\begin{aligned}\nf_1(z) = \\left(\\frac{\\beta - \\gamma}{\\beta - \\alpha}\\right) \\frac{z-\\alpha}{z-\\gamma}\n\\end{aligned}\n\\end{equation*}\nsends $\\alpha \\to 0$, $\\beta \\to 1$, $\\gamma \\to \\infty$. Let\n\\begin{equation*}\n\\begin{aligned}\nf_2(z) = \\left(\\frac{\\beta' - \\gamma'}{\\beta' - \\alpha'}\\right) \\frac{z-\\alpha'}{z-\\gamma'}\n\\end{aligned}\n\\end{equation*}\nthen $f^{-1}_2 \\circ f_1$ is the required mapping. It is a M$\\ddot{o}$bius map since M$\\ddot{o}$bius maps form a group.\n\nPutting all these results together, we conclude that we can find a M$\\ddot{o}$bius map taking any given circline to any other.\n\\end{proof}\n\n\\subsection{Conformal map}\n\\begin{defi}\nA \\emph{conformal map} $f:U \\to V$ where $U,V$ are \\emph{open} subsets of $\\C$, is one which is analytic with non-zero derivatives in $U$. Although not part of the definition, it is usual (and helpful) to require that $f$ be 1-1 from $U$ to $V$.\n\nAn alternative definition is that a conformal map is one that preserves the angle (in both magnitude and orientation) between intersecting curves. We shall show that our definition implies this. The converse is also true (proof omitted), so the two definitions are equivalent.\n\\begin{proof}\nSuppose that $z_1(t)$ is a curve in $\\C$ parameterised by $t \\in \\R$, which passes through a point $z_0$ when $t=t_1$. Suppose further that its tangent there, $z_1'(t)$, has a well-defined direction; then $z'_1(t_1) \\neq 0$ and the curve makes an angle $\\phi = \\arg z'_1(t_1)$ to the $x$-axis at $z_0$.\n\nConsider the image of the curve, $Z_1(t) = f(z_1(t))$. Its tangent direction at $t=t_1$ is\n\\begin{equation*}\n\\begin{aligned}\nZ'_1(t_1) = z'_1(t_1) f'(z_1(t_1)) = z'_1(t_1) f'(z_0)\n\\end{aligned}\n\\end{equation*}\nand therefore makes an angle with the $x$-axis of $\\arg Z_1(t_1) = \\arg(z'_1(t_1) f'(z_0)) = \\phi+\\arg f'(z_0)$ (noting that $\\arg f'(z_0)$ exists since $f$ is conformal so $f'(z_0) \\neq 0$). In other words, the tangent direction is rotated by $\\arg f'(z_0)$.\n\nNow if $z_2(t)$ is another curve passing through $z_0$, then its tangent direction will also be rotated by $\\arg f'(z_0)$. The result follows.\n\\end{proof}\n\\end{defi}\n\nSometimes we don't know what $V$, the image of $f$ acting on $U$, is in advance. Often, the easiest way to find it is first to find the image of the boundary $\\partial U$, which will form the boundary $\\partial V$ of $V$; but, since this does not reveal upon which side of $\\partial V$ $V$ lies, to then find the image of a single point of our choice within $U$, which will lie within $V$.\n\n\\begin{eg}\n(i) The map $z \\to az + b$, $a,b \\in \\C$, $a \\neq 0$. It rotates by $\\arg a$, enlarges by $|a|$, and translates by $b$, and is conformal everywhere.\\\\\n(ii) $f(z) = z^2$ is a conformal map from\n\\begin{equation*}\n\\begin{aligned}\nU = \\{z:0<|z|<1,0<\\arg z < \\frac{\\pi}{2}\\}\n\\end{aligned}\n\\end{equation*}\nto\n\\begin{equation*}\n\\begin{aligned}\nV = \\{w: 0 < |w| < 1, 0 < \\arg w < \\pi\\}.\n\\end{aligned}\n\\end{equation*}\n\n\\includegraphics[scale=0.4]{CM_08}\n\nNote that the right angle between the two boundary curves at $z=1$ is preserved because $f$ is conformal; similarly at $z=i$. But the right angle at $z=0$ is not preserved because $f'$ is not conformal there ($f'(0) = 0$). Fortunately this doesn't matter since $U$ is an \\emph{open} set so does not include $0$.\n\n(iii) Consider $U=\\{z:\\Re z<0\\}$ and $V=\\left\\{w:-\\frac{\\pi}{4} < \\arg w < \\frac{\\pi}{4} \\right\\}$.\n\n\\includegraphics[scale=0.4]{CM_09}\n\nWe need to halve the angle, so try using $z^{1/2}$, for which we need to choose a branch. The branch cut must \\emph{not} lie in $U$ (since $z^{1/2}$ is not analytic on the branch cut), so choose a cut along the negative imaginary axis: $re^{i\\theta} \\to \\sqrt{r} e^{i\\theta/2}$ where $\\theta$ is chosen to lie in the range $(-\\frac{\\pi}{2},\\frac{3\\pi}{2}]$. Having defined this branch, we now apply $z^{1/2}$ to $U$ to produce the wedge $\\{z':\\frac{\\pi}{4} < \\arg z' < \\frac{3\\pi}{4}\\}$; so we just need to rotate through $-\\frac{\\pi}{2}$. The final map is $f(z) = -iz^{1/2}$.\n\n(iv) $e^z$ takes rectangles conformally to sectors of annuli:\n\n\\includegraphics[scale=0.4]{CM_10}\n\nWith an appropriate choice of branch, $\\log z$ does the reverse.\n\n(v) M$\\ddot{o}$bius maps (which are conformal everywhere except at the point that is sent to $\\infty$) are very useful in taking circles, or parts of them, to straight lines, or vice versa.\n\nConsider $f(z) = \\frac{z-1}{z+1}$ acting on the unit disc $U=\\{z:|z|<1\\}$. The boundary of $U$ is a circle; the three points $-1,i$ and $i+1$ lie on this circle and are mapped to $\\infty$, $i$ and $0$ respectively. Therefore (see section 1.5) the image of $\\partial V$ is the imaginary axis; since $f(0) = -1$, we see that the image of $U$ is the left-hand half-plane.\n\n\\includegraphics[scale=0.4]{CM_11}\n\n*Alternative derivation: $w = \\frac{z-1}{z+1} \\iff z=-\\frac{w+1}{w-1}$. So $|z| < 1 \\iff |w+1|<|w-1|$, i.e. $w$ is closer to $-1$ than it is to $+1$.\n\nIn fact, this particular map can be deployed more generally on quadrants because it permutes $8$ divisions of the complex plane as follows:\n\n\\includegraphics[scale=0.4]{CM_12}\n\n$1 \\to 2 \\to 3 \\to 4 \\to 1$, $5 \\to 6 \\to 7 \\to 8 \\to 5$.\n\n(vi) $f(z) = \\frac{1}{z}$ is another M$\\ddot{o}$bius map for acting on vertical or horizontal lines.\n\\end{eg}\n\nIn practice, complicated conformal maps are usually built up from individual building blocks, each a simple conformal map; the required map is the composition of these (note that the composition of conformal maps is still conformal, see the worked example).\n\n\\subsection{Solving Laplace's Equation using conformal maps}\nThe following algorithm can be used to solve Laplace's equation\n\\begin{equation*}\n\\begin{aligned}\n\\nabla^2 \\phi(x,y) = 0\n\\end{aligned}\n\\end{equation*}\non a tricky domain $U \\subset \\R$ with given Dirichlet boundary conditions on $\\partial U$. We identify subsets of $\\R^2$ with subsets of $\\C$ in the obvious manner.\n\n1. Find a conformal map $f:U \\to V$ where $U$ is now considered a subset of $\\C$ and $V$ is a 'nice' domain of our choice. Our aim is to find a harmonic function $\\Phi$ in $V$ that satisfies the same boundary conditions as $\\phi$.\\\\\n2. Map the boundary conditions on $\\partial U$ directly to the equivalent points on $\\partial V$.\\\\\n3. Now solve $\\nabla^2 \\Phi =0$ in $V$ with the new boundary conditions.\\\\\n4. The required harmonic function $\\phi$ in $U$ is then given by\n\\begin{equation*}\n\\begin{aligned}\n\\phi(x,y) = \\Phi(\\Re f(x+iy), \\Im f(x+iy)).\n\\end{aligned}\n\\end{equation*}\nThis works because, since $\\Phi$ is harmonic, it is the real part of some complex analytic function $F(z) = \\Phi(x,y) + i\\Psi(x,y)$ where $z=x+iy$ (see section 1.3). Now $F(f(z))$ is analytic as it is a composition of analytic functions; so its real part, which is $\\Phi(\\Re f, \\Im f)$, is harmonic.\n\n\\begin{eg}\nSolve $\\nabla^2 \\phi = 0$ in the first quadrant of $\\R^2$ subject to boundary condition $\\phi(x,0) = 0$, $\\phi(0,y) = 1$, where $x,y>0$, and with $\\phi$ bounded near the origin and at $\\infty$.\\\\\nWe choose $f(z) =\\log(z)$ (principal branch) which maps $U$ to the strip $0<\\Im z < \\frac{\\pi}{2}$.\n\n\\includegraphics[scale=0.4]{CM_13}\n\nIt takes the positive real axis to $\\Im z=0$ and the positive imaginary axis to $\\Im z = \\frac{\\pi}{2}$. Therefore we must solve $\\nabla^2 \\Phi = 0$ in $V$ subject to boundary conditions $\\Phi(x,0) = 0$, $\\phi(x,\\frac{\\pi}{2}) = 1$, and $\\Phi$ bounded as $x \\to \\pm \\infty$. By inspection the solution is\n\\begin{equation*}\n\\begin{aligned}\n\\Phi(x,y) = \\frac{2}{\\pi} y.\n\\end{aligned}\n\\end{equation*}\nSo\n\\begin{equation*}\n\\begin{aligned}\nphi(x,y) &= \\Phi(\\Re \\log z, \\Im \\log z)\\\\\n&=\\frac{2}{\\pi} \\Im \\log z\\\\\n&=\\frac{2}{\\pi} \\tan^{-1}\\left(\\frac{y}{x}\\right).\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\newpage\n\n\\section{Contour Integration and Cauchy's Theorem}\n\\subsection{Contours and Integrals}\n\n\\begin{defi}\nA \\emph{curve} $\\gamma(t)$ is a (continuous) map $\\gamma:[0,1] \\to \\C$.\\\\\nA \\emph{closed curve} is one where $\\gamma(0) = \\gamma(1)$.\\\\\nA \\emph{simple curve} is one which does not intersect itself (except at $t=0,1$ in the case of a simple closed curve).\\\\\nA \\emph{contour} is a piecewise smooth curve.\\\\\nWe shall, in an abuse of notation, often use the symbol $\\gamma$ to denote both the map \\emph{and} its image, namely the actual curve in $\\C$ traversed in a particular direction.\\\\\nThe contour $-\\gamma$ is the contour $\\gamma$ traversed in the opposite direction. Given two contours $\\gamma_1$ and $\\gamma_2$, with matching end-points, $i.e. \\gamma_1(1) = \\gamma_2(0)$, $\\gamma_1 + \\gamma_2$ denotes the two contours joined end to end.\\\\\nThe contour integral $\\int_\\gamma f(z) dz$ is defined to be \n\\begin{equation*}\n\\begin{aligned}\n\\int_0^1 f(\\gamma(t)) \\gamma'(t) dt.\n\\end{aligned}\n\\end{equation*}\n\\end{defi}\nAlternatively (and equivalently), for a simple contour we dissect it at points $z_0$, $z_1$, ..., $z_N$ on the contour in that order, where $z_0 = \\gamma(0)$ and $z_N = \\gamma(1)$, and let $\\delta z_n = z_{n+1}-z_n$ for $n=0,...,N-1$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_\\gamma f(z) dz = \\lim_{\\Delta \\to 0} \\sum_{n=0}^{N-1} f(z_n) \\delta z_n\n\\end{aligned}\n\\end{equation*}\nwhere $\\Delta = \\max_{n=0,...,N-1} |\\delta z_n|$ and, as $\\Delta \\to 0$, $N \\to \\infty$.\n\nThe result of a contour integral between two points in $\\C$ \\emph{may} depend on the choice of contour.\n\nFor example, consider\n\\begin{equation*}\n\\begin{aligned}\nI_1 = \\int_{\\gamma_1} \\frac{dz}{z},\\\\\nI_2 = \\int_{\\gamma_2} \\frac{dz}{z}\n\\end{aligned}\n\\end{equation*}\nwhere in both cases we integrate from $z=-1$ to $z=1$. around a unit circle: $\\gamma_1$ above and $\\gamma_2$ below the real axis (see diagram below).\n\n\\includegraphics[scale=0.4]{CM_14}\n\nSubstitute $z=e^{i\\theta}$, then $dz = ie^{i\\theta} d\\theta$. But then\n\\begin{equation*}\n\\begin{aligned}\nI_1 = \\int_\\pi^0 \\frac{ie^{i\\theta}d\\theta}{e^{i\\theta}} = -i\\pi\n\\end{aligned}\n\\end{equation*}\nwhile\n\\begin{equation*}\n\\begin{aligned}\nI_2 = \\int_{-\\pi}^0 \\frac{ie^{i\\theta}d\\theta}{e^{i\\theta}} = i\\pi.\n\\end{aligned}\n\\end{equation*}\n\n\\subsubsection{Elementary properties}\n(i) $\\int_{\\gamma_1+\\gamma_2} f(z) dz = \\int_{\\gamma_1} f(z) dz + \\int_{\\gamma_2} f(z) dz$.\\\\\n(ii) $\\int_{-\\gamma} f(z) dz = -\\int_\\gamma f(z) dz$.\\\\\n(iii) If $\\gamma$ is a contour from $a$ to $b$ in $\\C$ then $\\int_\\gamma f'(z) dz = f(b)-f(a)$ so long as $f$ is differentiable at every point on $\\gamma$ (so, for example, we must not cross a branch cut of $f$).\\\\\n(iv) Integration by substitution and by parts work exactly as for integrals on the real line.\\\\\n(v) If $\\gamma$ has length $L$ and $|f(z)|$ is bounded by $M$ on $\\gamma$, then\n\\begin{equation*}\n\\begin{aligned}\n|\\int_\\gamma f(z) dz| \\leq LM\n\\end{aligned}\n\\end{equation*}\nsince\n\\begin{equation*}\n\\begin{aligned}\n|\\int_\\gamma f(z) dz &\\leq \\int_\\gamma |f(z)| |dz|\\\\\n&\\leq M\\int_\\gamma |dz|\\\\\n&=LM.\n\\end{aligned}\n\\end{equation*}\n\n\\subsubsection{Integrals on closed contours}\nIf $\\gamma$ is a closed contour, then it doesn't matter where we start from on $\\gamma$, as long as we go all the way round.\n\nThe notation $\\oint f(z) dz$ denotes an integral round a closed contour.\n\nThe usual direction of traversal is anticlockwise (the 'positive sense'); if we traverse $\\gamma$ in a negative sense (clockwise) then we get the negation of the previous result. More technically, the positive sense is the direction that keeps the interior of the contour on the left.\n\n\\subsection{Cauchy's theorem}\nIf $f(z)$ is analytic in a simply-connected domain $\\mathfrak{D}$, then for every simple closed contour $\\gamma$ in $\\mathfrak{D}$,\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz = 0.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}(*)\\\\\nThe proof of this remarkable theorem is simple and follows from the Cauchy-Riemann equations and Green's Theorem. Let $u,v$ be the real and imaginary parts of $f$. Then\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz &= \\oint_\\gamma (u+iv)(dx+idy)\\\\\n&= \\oint_\\gamma (udx - vdy) + i\\oint_\\gamma (vdx + udy)\\\\\n&= \\int_S \\left(-\\frac{\\partial v}{\\partial x} - \\frac{\\partial u}{\\partial y}\\right) dxdy + i\\int_S \\left(\\frac{\\partial u}{\\partial x} - \\frac{\\partial v}{\\partial y}\\right)dxdy\n\\end{aligned}\n\\end{equation*}\nwhere $S$ is the region enclosed by $\\gamma$, by applying Green's theorem in the plane,\n\\begin{equation*}\n\\begin{aligned}\n\\oint_{\\partial S} (Pdx+Qdy) = \\int_S \\left(\\frac{\\partial Q}{\\partial x} -\\frac{\\partial P}{\\partial y}\\right) dxdy.\n\\end{aligned}\n\\end{equation*}\nBut both brackets vanish by the Cauchy-Riemann equations because $f$ is differentiable throughout $S$. The result follows.\n\\end{proof}\n\n(**) In fact, this proof requires $u$ and $v$ to have continuous partial derivatives, else Green's theorem isn't applicable. We shall see later that $f$ is in fact differentiable infinitely many times, so $u$ and $v$ do have continuous partial derivatives; unfortunately our proof of that will utilize Cauchy's Theorem. For the complete proof see complex analysis.\n\n\\subsection{Contour deformation}\nSuppose that $\\gamma_1$ and $\\gamma_2$ are two contours from $a$ to $b$, and that $f$ is analytic on and between the contours. Then\n\\begin{equation*}\n\\begin{aligned}\n\\int_{\\gamma_1} f(z) dz = \\int_{\\gamma_2} f(z) dz.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\n\n\\includegraphics[scale=0.4]{CM_15}\n\nSuppose first that $\\gamma_1$ and $\\gamma_2$ do not cross. Then $\\gamma_1-\\gamma_2$ is a simple closed contour, so $\\int_{\\gamma_1-\\gamma_2} f(z) dz = 0$ by Cauchy's Theorem. The result follows.\n\n\\end{proof}\n\nIf $\\gamma_1$ and $\\gamma_2$ do cross, then dissect them at each crossing point (e.g. $c$ in the diagram) and apply the technique above to each section.\n\n\\includegraphics[scale=0.4]{CM_16}\n\nSo, if $f$ has no singularities, $\\int_a^b f(z) dz$ does not depend on the chosen contour at all.\n\n(*) Another way of thinking about path-independence, and indeed Cauchy's Theorem itself, is to consider $\\int f(z)dz$ as a path integral in $\\R^2$. Then\n\\begin{equation*}\n\\begin{aligned}\nf(z)dz &= (u+iv)(dx+idy)\\\\\n&= (u+iv)dx + (-v+iu)dy\n\\end{aligned}\n\\end{equation*}\nis an exact differential:\n\\begin{equation*}\n\\begin{aligned}\n\\frac{\\partial}{\\partial y} (u+iv) = \\frac{\\partial}{\\partial x}(-v+iu)\n\\end{aligned}\n\\end{equation*}\nfrom the Cauchy-Riemann equations. (*)\n\nThe same idea of 'moving the contour' applies to closed contours. Suppose that $\\gamma_1$ is a closed contour that can be continuously deformed into another, $\\gamma_2$, inside it; and suppose that $f$ has no singularities in the region between them.\n\n\\includegraphics[scale=0.4]{CM_17}\n\nConsider the contour $\\gamma$ shown; $\\oint_\\gamma f(z) dz = 0$.\n\n\\includegraphics[scale=0.4]{CM_18}\n\nNow let the distance between the two 'cross-cuts' tend to 0; these contributions cancel out and, in the limit, we have\n\\begin{equation*}\n\\begin{aligned}\n\\oint_{\\gamma_1} f(z) dz - \\oint_{\\gamma_2}f(z) dz = 0.\n\\end{aligned}\n\\end{equation*}\n\n\\subsection{Cauchy's integral formula}\nSuppose that $f$ is analytic in a domain $\\mathfrak{D}$ and that $z \\in \\mathfrak{D}$. Then\n\\begin{equation*} \\tag{*}\n\\begin{aligned}\nf(z) = \\frac{1}{2\\pi i} \\oint_\\gamma \\frac{f(w)}{w-z} dw\n\\end{aligned}\n\\end{equation*}\nfor any simple closed contour $\\gamma$ in $\\mathfrak{D}$ encircling $z$ anticlockwise. (Note that if $z$ does not lie on or inside $\\gamma$ then $\\frac{1}{2\\pi i} \\oint_\\gamma \\frac{f(w)}{w-z} dw = 0$ by Cauchy's Theorem, since there is no singularity).\n\\begin{proof} (*)\\\\\nLet $\\gamma_\\varepsilon$ be a circle of radius $\\varepsilon$ about $z$, within $\\gamma$.\n\n\\includegraphics[scale=0.4]{CM_19}\n\nBy section 2.3, \n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma \\frac{f(w)}{w-z} dw = \\oint_{\\gamma_\\varepsilon} \\frac{f(w)}{w-z} dw\n\\end{aligned}\n\\end{equation*}\nSince the only singularity is at $z$ which is not between $\\gamma_\\varepsilon$ and $\\gamma$. So by substituting $w=z+\\varepsilon e^{i\\theta}$, the above is then equal to\n\\begin{equation*}\n\\begin{aligned}\n&\\int_0^{2\\pi} \\frac{f(z+\\varepsilon e^{i\\theta})}{\\varepsilon e^{i\\theta}} i\\varepsilon e^{i\\theta} d\\theta\\\\\n= &i \\int_0^{2\\pi} (f(z)+O(\\varepsilon))d\\theta\\\\\n\\to &2\\pi i f(z)\n\\end{aligned}\n\\end{equation*}\nas $\\varepsilon \\to 0$. The result follows. (*)\n\n(**) So, if we know $f$ on $\\gamma$ then we know it at all points within $\\gamma$. Another way of looking at this is to write $f=u+iv$, where $u$ and $v$ are harmonic, and $u,v$ are specified by on $\\gamma$; so we have Laplace's equation for $u$ and $v$ with Dirichlet boundary conditions, which has a unique solution inside $\\gamma$. (**)\n\nWe can differentiate CIF(*):\n\\begin{equation*}\n\\begin{aligned}f'(z) = \\frac{1}{2\\pi i}\\oint_\\gamma \\frac{f(w)}{(w-z)^2} dw\n\\end{aligned}\n\\end{equation*}\nDifferentiation under the integral sign is valid because the integrand, both before and after, is a continuous function of both $w$ and $z$, or in short because this is Complex Methods. Repeating we get\n\\begin{equation*}\n\\begin{aligned}\nf^{(n)}(z) = \\frac{n!}{2\\pi i} \\oint_\\gamma \\frac{f(w)}{(w-z)^{n+1}} dw\n\\end{aligned}\n\\end{equation*}\nHence at any point where $f$ is analytic, all its derivatives exist, so it is differentiable infinitely many times, as advertised in section 1.2.\n\n(*) An application of Cauchy's integral formula is Liouville's theorem: any bounded entire function is a constant. Suppose that $|f(z)| \\leq M$ for all $z$, and consider a circle of radius $r$ centered at an arbitrary $z \\in \\C$. Then\n\\begin{equation*}\n\\begin{aligned}\nf'(z) = \\frac{1}{2\\pi i} \\oint_{|w-z|=r} \\frac{f(w)}{(w-z)^2} dw\n\\end{aligned}\n\\end{equation*}\nSo from section 2.1(v),\n\\begin{equation*}\n\\begin{aligned}\n|f'(z)| \\leq \\frac{1}{2\\pi} \\cdot 2\\pi r \\cdot \\frac{M}{r^2} = \\frac{M}{r}\n\\end{aligned}\n\\end{equation*}\nwhich tends to $0$ as $r \\to \\infty$. Hence $f'(z) = 0$ $\\forall z \\in \\C$. So $f$ is constant, i.e. every bounded entire function is a constant. (*)\n\n(*) Another application is the maximum modulus principle: if $f$ is analytic within a bounded domain and on its boundary, then $|f(z)|$ attains its maximum on the boundary (proof omitted). (*)\n\n\\end{proof}\n\n\\newpage\n\n\\section{Laurent Series and Singularities}\n\\subsection{Taylor Series}\nIf $f$ is analytic at $z_0$, then it has a Taylor series \n\\begin{equation*}\n\\begin{aligned}\nf(z) = \\sum_{n=0}^\\infty a_n(z-z_0)^n\n\\end{aligned}\n\\end{equation*}\nin some neighbourhood of $z_0$ (see section 3.3 for more information about the region of convergence).\n\nAll the standard Taylor series from real analysis apply, for example those of $e^z$ and of $(1-z)^{-1}$.\n\n\\subsection{Zeros}\nThe \\emph{zeros} of an analytic function $f(z)$ are the points $z_0$ where $f(z_0)=0$. A zero is of \\emph{order $N$} if, in its Taylor series, the first non-zero coefficient is $a_N$. Equivalently, it is of order $N$ if\n\\begin{equation*}\n\\begin{aligned}\n0 = f(z_0) = f'(z_0) = ... = f^{(N-1)} (z_0)\n\\end{aligned}\n\\end{equation*}\nbut $f^(N) (z_0) \\neq 0$.\n\nA zero of order one (or two, three, etc) is also called a \\emph{simple zero} (or double zero, triple zero etc).\n\n\\begin{eg}\n$z^3+iz^2+z+i = (z-i)(z+i)^2$ has a simple zero at $z=i$ and a zero of order two at $z=-i$.\n\\end{eg}\n\n\\begin{eg}\n$\\sinh z$ has zeros where\n\\begin{equation*}\n\\begin{aligned}\n\\frac{e^z - e^{-z}}{2} = 0 \\iff e^{2z} = 1 \\iff z = n\\pi i\n\\end{aligned}\n\\end{equation*}\nfor $n \\in \\Z$. The zeros are all simple (since $\\cosh n\\pi i = \\cos n\\pi \\neq 0$).\n\\end{eg}\n\n\\begin{eg}\nSince $\\sinh z$ has a simple zero at $z= \\pi i$, $sinh^3 z$ has a zero of order $3$ there. If needed, we can find its Taylor series about $\\pi i$ by writing $\\zeta = z-\\pi i$:\n\\begin{equation*}\n\\begin{aligned}\n\\sinh^3 z &= [\\sinh (\\zeta + \\pi i)]^3\\\\\n&= [-\\sinh \\zeta]^3\\\\\n&= -(\\zeta + \\frac{1}{3!} \\zeta^3 + ...)^3\\\\\n&= -\\zeta^3 - \\frac{1}{2} \\zeta^5 - ...\\\\\n&= -(z-\\pi i)^3 - \\frac{1}{2} (z-\\pi i)^5 - ...\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\subsection{Laurent Series}\nIf $f$ has a singularity at $z_0$, we cannot expect it to have a Taylor series there. Instead, if $f$ is analytic in an annulus $R_1<|z-z_0|<R_2$, then it has a \\emph{Laurent series} about $z_0$,\n\n\\begin{equation*}\n\\begin{aligned}\nf(z) = \\sum_{n=-\\infty}^\\infty a_n (z-z_0)^n\n\\end{aligned}\n\\end{equation*}\nconvergent within the annulus (this definition is a bit different from that in GRM).\n\n\\includegraphics[scale=0.4]{CM_20}\n\n\\begin{proof}(*)\nSee the separate sheet. (*)\n\\end{proof}\n\nIt can be shown that the Laurent Series for $f$ about a particular $z_0$ is unique within any given annulus. Note that Taylor series are just a special case of Laurent Series ($R_1=0$).\n\n\\begin{eg}\n$\\frac{e^z}{z^3}$ has a Laurent series about $z_0=0$ given by\n\\begin{equation*}\n\\begin{aligned}\n\\frac{e^z}{z^3} = \\sum_{m=0}^\\infty \\frac{z^m-3}{m!} = \\sum_{n=-3}^\\infty \\frac{1}{(n+3)!} z^n\n\\end{aligned}\n\\end{equation*}\nso\n\\begin{equation*}\n\\begin{aligned}\na_n = \\frac{1}{(n+3)!}\n\\end{aligned}\n\\end{equation*}\nfor $n \\geq -3$.\n\\end{eg}\n\n\\begin{eg}\n$e^{1/z}$ about $z_0=0$ has\n\\begin{equation*}\n\\begin{aligned}\ne^{1/z} = 1+\\frac{1}{z}+\\frac{1}{2!z^2}+\\frac{1}{3!z^3}+...,\n\\end{aligned}\n\\end{equation*}\nso $a_n = \\frac{1}{(-n)!}$ for $n\\leq 0$.\n\\end{eg}\n\n\\begin{eg}\nIf $f(z) = \\frac{1}{z-a}$ where $a\\in \\C$, then $f$ is analytic in $|z| < |a|$. So it has a Taylor series about $z_0=0$ given by\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{z-a} = -\\frac{1}{a}(1-\\frac{z}{a})^{-1}= -\\sum_{n=0}^\\infty a^{-n-1} z^n\n\\end{aligned}\n\\end{equation*}\nIn $|z|>|a|$, it has a Laurent series (in the 'annaulus' $|a|<|z|<\\infty$) given by\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{z-a} = \\frac{1}{z} (1-\\frac{a}{z})^{-1} = \\sum_{m=0}^\\infty \\frac{a^m}{z^{m+1}} =\\sum_{n=-\\infty}^{-1} a^{-n-1}z^n.\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\begin{eg}\n$f(z) = \\frac{e^z}{z^2-1}$ has a singularity at $z_0=1$ but is analytic in an annulus $0<|z-z_0|<2$ (since the only other singularity is at $z=-1$). Write everything in terms of $\\zeta = z-z_0$, so\n\\begin{equation*}\n\\begin{aligned}\nf(z) &= \\frac{e^{\\zeta}e^z_0}{\\zeta(\\zeta+2)}\\\\\n&=\\frac{e^{z_0}}{2\\zeta} e^\\zeta \\left(1+\\frac{1}{2}\\zeta\\right)^{-1}\\\\\n&= \\frac{e}{2\\zeta} \\left(1+\\zeta+\\frac{1}{2!}\\zeta^2+...\\right) \\left(1-\\frac{1}{2}\\zeta + \\frac{1}{4} \\zeta^2-...\\right)\\\\\n&= \\frac{e}{2\\zeta} \\left((1+\\frac{1}{2}\\zeta+\\frac{1}{4}\\zeta^2+...\\right)\\\\\n&=\\frac{1}{2} e \\left(\\frac{1}{z-z_0} + \\frac{1}{2} + \\frac{z-z_0}{4}+...\\right).\n\\end{aligned}\n\\end{equation*}\nHence $a_{-1} = \\frac{1}{2} e$, $a_0 = \\frac{1}{4}e$, etc. This series is valid in the whole annulus (our expansion of $(1+\\frac{1}{2}\\zeta)^{-1}$ was valid for $|\\frac{1}{2}\\zeta|<1$, i.e. $|z-z_0|<2$).\n\\end{eg}\n\n\\begin{eg}\nThe above doesn't seem to work for $f(z) = z^{-1/2}$: we cannot find a Laurent series about $z_0=0$. The reason is that the required branch cut (see section 1.4) would pass through any annulus about the origin, so we cannot find an annulus in which $f$ is analytic (of course, $z^{-1/2}$ has Taylor series about other points $z_0 \\neq 0$ except those on the branch cut).\n\\end{eg}\n\n\\subsubsection{Radii of convergence}\nSuppose we have a Laurent series that we know to be valid in some annulus $R_1 < |z-z_0| < R_2$ but that there are no singularities on $|z-z_0|=R_2$.\n\n\\includegraphics[scale=0.4]{CM_21}\n\nThen the outer radius of convergence can actually be pushed outwards until the circle touches a singularity, say at $z_2$. Similarly, if there are no singularities on $|z-z_0|=R_1$, then the inner radius can be pulled inwards until that circle touches a singularity, say at $z_1$. Then our Laurent series in fact converges in the new annulus\n\\begin{equation*}\n\\begin{aligned}\n|z_1| \\equiv R'_1 < |z-z_0| < R'_2 \\equiv |z_2|.\n\\end{aligned}\n\\end{equation*}\nIn other words, the annulus of convergence of a Laurent series can always be made maximally large, with a singularity on each of the bounding circles.\n\n(*) This is because we could have stated with $R'_1$ and $R'_2$ in the first place instead of $R_1$ and $R_2$ in the proof that the Laurent series exists; and Laurent series are unique, so this new one must be the same as our old series. (*)\n\nA Taylor series is just a special case of a Laurent series, resulting in the following statement: the radius of convergence of a Taylor series is always the distance to the nearest singularity.\n\n\\begin{eg}\n$\\cosech z$ has Laurent series\n\\begin{equation*}\n\\begin{aligned}\n\\left(z+\\frac{z^3}{3!}+...\\right)^{-1} = z^{-1} \\left(1-\\frac{z^2}{6} + ... \\right) = \\frac{1}{z} - \\frac{z}{6} + ...\n\\end{aligned}\n\\end{equation*}\nfor sufficiently small $z \\neq 0$, but it is hard to work out when the binomial expansion is valid. Nevertheless the singularities closest to the origin are at $z=\\pm \\pi i$, so the annulus of convergence is in fact $0<|z|<\\pi$.\n\\end{eg}\n\n\\subsection{Classification of singularities}\nSuppose that $f$ has a singularity at $z=z_0$. If there is a neighbourhood of $z_0$ within which $f$ is analytic, except at $z_0$ itself, then $f$ has an \\emph{isolated singularity} at $z_0$. If there is no such neighbourhood, then $f$ has a \\emph{non-isolated singularity} (some authors call this an 'essential singularity', but that creates confusion with another type described below).\n\n\\begin{eg}\n$\\cosech z$ has isolated singularities at $z=n\\pi i$, $n \\in \\Z$ (from section 3.2 (ii)).\n\\end{eg}\n\n\\begin{eg}\n$\\cosech \\frac{1}{z}$ has isolated singularities at $z=\\frac{1}{n\\pi i}$, $n\\neq 0$, and a non-isolated singularity at $z=0$ (since there are other arbitrarily close singularities).\n\\end{eg}\n\n\\begin{eg}\n$\\cosech z$ has a non-isolated singularity at $z=\\infty$ (see section 1.1).\n\\end{eg}\n\n\\begin{eg}\n$z^{-1/2}$ has a branch point singularity at $z=0$ (see section 1.4); this is a type of non-isolated singularity (because $z^{-1/2}$ is not analytic at any point on the branch cut), but is usually treated as a separate type of singularity.\n\\end{eg}\n\nIf $f$ has an isolated singularity at $z_0$, we can find an annulus $0<|z-z_0|<r_0$ say within which $f$ is analytic, and therefore has a Laurent series. This gives us a way to classify singularities:\\\\\n(a) Check for a branch point singularity;\\\\\n(b) Check for a non-isolated singularity;\\\\\n(c) Otherwise, consider the coefficients of the Laurent series $\\sum_{n=-\\infty}^\\infty a_n (z-z_0)^n$:\\\\\n(c1) If $a_n=0$ $\\forall n<0$, then $f$ has a \\emph{removable singularity} at $z_0$;\\\\\n(c2) If $\\exists N>0$ such that $a_n = 0$ $\\forall n < -N$, but $a_{-N} \\neq 0$ then $f$ has a \\emph{pole of order $N$} at $z_0$ (For $N=1,2,...$ this is also called a \\emph{simple pole}, \\emph{double pole}, etc.).\\\\\n(c3) If there does not exist such an $N$, then $f$ has an \\emph{essential isolated singularity} at $z_0$.\n\nThe behaviour of $f$ near $z_0$ is as follows:\\\\\n1. At a removable singularity, where\n\\begin{equation*}\n\\begin{aligned}\nf(z) = a_0 + a_1 (z-z_0)+...\n\\end{aligned}\n\\end{equation*}\nfor $0<|z-z_0|<r_0$, $f(z) \\to a_0$ as $z \\to z_0$; so an easy way to tell that a singularity is removable is that $f$ has a finite limit. We can 'remove the singularity' by redefining $f(z_0) = a_0 = \\lim_{z \\to z_0} f(z)$; then $f$ will become analytic at $z_0$.\\\\\n2. At a pole, $|f(z)| \\to \\infty$ as $z \\to z_0$.\\\\\n3. At an essential isolated singularity, $f$ does not tend to any finite or infinite limit. (*) In fact, it can be shown that $f$ takes \\emph{all} possible complex values (bar at most one) in any neighbourhood of $z_0$, however small. For example, $e^{1/z}$ takes all values except $0$.(*)\n\n\\begin{eg}\n(i) $\\frac{1}{z-i}$ has a simple pole at $z=i$ (since it is its own Laurent series).\\\\\n(ii) $\\frac{\\cos z}{z}$ has Laurent series\n\\begin{equation*}\n\\begin{aligned}\nz^{-1} - \\frac{1}{2}z + \\frac{1}{24}z^3 - ...\n\\end{aligned}\n\\end{equation*}\nabout the origin, so has a simple pole at $z=0$.\\\\\n(iii) $\\frac{z^2}{(z-1)^2(z-i)^3}$ has a double pole at $z=1$ and a triple pole at $z=i$. To show formally that, for instance, there is a double pole at $z=1$, notice first that $\\frac{z^2}{(z-i)^3}$ is analytic there, so has a Taylor series\n\\begin{equation*}\n\\begin{aligned}\nb_0+b_1(z-1)+b_2(z-1)^2+...\n\\end{aligned}\n\\end{equation*}\nfor some $b_n$. Hence\n\\begin{equation*}\n\\begin{aligned}\n\\frac{z^2}{(z-1)^2(z-i)^3} = \\frac{b_0}{(z-1)^2} + \\frac{b_1}{z-1} + ...\n\\end{aligned}\n\\end{equation*}\n(iv) If $g(z)$ has a zero of order $N$ at $z=z_0$, then $\\frac{1}{g(z)}$ has a pole of order $N$ there (and vice vesa). Hence $\\cot z$ has a simple pole at the origin, because $\\tan z$ has s simple zero there. To prove the general statement, write $g(z) = (z-z_0)^N G(z)$ for some $G(z)$ with $G(z_0) \\neq 0$, and note that $\\frac{1}{G(z)}$ has a Taylor series about $z_0$.\\\\\n(v) $z^2$ has a double pole at $\\infty$ (see section 1.1).\\\\\n(vi) $e^{1/z}$ has an essential isolated singularity at $z=0$ because all the $a_n$'s are non-zero for $n<0$ (see section 3.3(ii)).\\\\\n(vii) $\\sin \\frac{1}{z}$ also has an essential singularity at $z=0$ because (using the standard Taylor series for $\\sin$) there are non-zero $a_n$ for infinitely many $n<0$.\\\\\n(viii) $f(z) = \\frac{e^z-1}{z}$ has a removable singularity at $z=0$, because\n\\begin{equation*}\n\\begin{aligned}\nf(z)= 1+\\frac{1}{2!}z + \\frac{1}{3!} z^2 + ...\n\\end{aligned}\n\\end{equation*}\nBy defining $f(0)=1$, we would remove the singularity and obtain an entire function.\\\\\n(ix) $f(z) = \\frac{\\sin z}{z}$ is not defined at $z=0$ but has a removable singularity there; remove it by setting $f(0) = \\lim_{z \\to 0} f(z) = 1$.\\\\\n(x) A rational function $f(z) = \\frac{P(z)}{Q(z)}$ where $P,Q$ are polynomials has a singularity at any point $z_0$ where $Q$ has a zero; but if $P(z_0)=0$ as well, then the singularity is removable by redefining $f(z) = \\frac{P'(z_0)}{Q'(z_0)}$ (assuming that $Q$ has a simple zero).\n\\end{eg}\n\n\\subsection{Closed Contour Integrals of Laurent Series}\n\nSuppose that $f$ is analytic within some annulus, so has a Laurent series\n\\begin{equation*}\n\\begin{aligned}\n\\sum_{n=-\\infty}^\\infty a_n (z-z_0)^n\n\\end{aligned}\n\\end{equation*}\nthere, and that $\\gamma$ is an anticlockwise simple closed contour lying within the annulus.\n\n\\includegraphics[scale=0.4]{CA_12}\n\nWhat is $\\oint_\\gamma f(z) dz$?\n\nChoose a circular contour $\\gamma_r$ of radius $r$ lying inside $\\gamma$ but still within the annulus. From section 2.3, we can deform the contour, so\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz &= \\oint_{\\gamma_r} f(z) dz\\\\\n&= \\sum_{n=-\\infty}^\\infty a_n \\oint_{\\gamma_r} (z-z_0)^n dz\n\\end{aligned}\n\\end{equation*}\n(by uniform convergence on $\\gamma_r$). But let $z=z_0+re^{i\\theta}$, then\n\\begin{equation*}\n\\begin{aligned}\n\\oint_{\\gamma_r} (z-z_0)^n dz &= \\int_0^{2\\pi} r^n e^{in\\theta} \\cdot ire^{i\\theta} d\\theta\\\\\n&= ir^{n+1} \\int_0^{2\\pi} e^{i(n+1)\\theta} d\\theta\\\\\n&= \\left\\{\\begin{array}{ll}\n2\\pi & n =-1,\\\\\n\\frac{r^{n+1}}{n+1} [e^{i(n+1)\\theta} ]^{2\\pi}_0 = 0 & n \\neq -1\n\\end{array}\\right.\n\\end{aligned}\n\\end{equation*}\nHence\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz = 2\\pi i a_{-1}.\n\\end{aligned}\n\\end{equation*}\n\n\\newpage\n\n\\section{The Calculus of Residues}\n\\subsection{Residues}\nIf $f$ has an isolated singularity at $z_0$ then it has a Laurent series expansion about that point (see section 3.4). The \\emph{residue} of $f$ at $z_0$ is the coefficient $a_{-1}$ of its Laurent series (we have already seen in section 3.5 that this coefficient is important for evaluating integrals). There is no standard notation but we shall denote the residue by $res_{z=z_0} f(z)$.\n\nAt a \\emph{simple} pole, the residue is given by\n\\begin{equation*}\n\\begin{aligned}\nres_{z = z_0} f(z) = \\lim_{z \\to z_0} \\{(z-z_0) f(z)\\}\n\\end{aligned}\n\\end{equation*}\nsince the RHS is equal to\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{z \\to z_0} \\left\\{(z-z_0)\\left(\\frac{a_{-1}}{z-z_0}+a_0+a_1(z-z_0)+...\\right)\\right\\}\n\\end{aligned}\n\\end{equation*}\nMore generally, at a pole of order $N$ the residue is given by\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{z \\to z_0} \\{\\frac{1}{(N-1)!} \\frac{d^{N-1}}{dz^{N-1}} ((z-_0)^N f(z)) \\}\n\\end{aligned}\n\\end{equation*}\nwhich can be proved in a similar manner (see example sheet).\n\nIn practice, a variety of techniques can be used to evaluate residues: no single techniques is optimal.\n\n\\subsection{The Residue Theorem}\nSuppose that $f$ is analytic in a simply-connected domain except at a finite number of isolated singularities $z_1,...,z_n$; and that a simple closed contour $\\gamma$ encircles the singularities anticlockwise. \n\n\\includegraphics[scale=0.4]{CM_22}\n\nThen\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz = 2\\pi i\\sum_{k=1}^n res_{z=z_k} f(z).\n\\end{aligned}\n\\end{equation*}\n\n\\begin{proof}\nConsider the curve $\\hat{\\gamma}$ shown, consisting of small \\emph{clockwise} circles $\\gamma_1,$...,$\\gamma_n$ around the singularities; cross-cuts, which cancel in the limit as they approach each other in pairs, and the large outer curve (which is the same as $\\gamma$ in the limit). \n\n\\includegraphics[scale=0.4]{CM_23}\n\n$\\hat{\\gamma}$ encircles no singularities, so\n\\begin{equation*}\n\\begin{aligned}\n\\oint_{\\hat{\\gamma}} f(z) dz = 0\n\\end{aligned}\n\\end{equation*}\nby Cauchy's Theorem. So in the limit when the cross-cuts cancel, we have\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma f(z) dz + \\sum_{k=1}^n \\oint_{\\gamma_k} f(z) dz = \\oint_{\\hat{\\gamma}} f(z) dz = 0\n\\end{aligned}\n\\end{equation*}\nBut about each isolated singularity $z_k$ there is a Laurent series valid locally in some annulus, so by seciont 3.5 and section 4.1 we have\n\\begin{equation*}\n\\begin{aligned}\n\\oint_{\\gamma_k} f(z) dz=-2\\pi i \\ res_{z=z_k} f(z).\n\\end{aligned}\n\\end{equation*}\n(the minus sign is because $\\gamma_k$ is a \\emph{clockwise contour}). The result follows.\n\\end{proof}\n\n\\subsection{Applications of the Residue Theorem}\nTo illustrate the technique we shall evaluate\n\\begin{equation*}\n\\begin{aligned}\nI = \\int_0^\\infty \\frac{dx}{1+x^2}\n\\end{aligned}\n\\end{equation*}\n(which we can already do by trigonometric substitutions).\n\n\\includegraphics[scale=0.4]{CM_24}\n\nConsider\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma \\frac{dz}{1+z^2}\n\\end{aligned}\n\\end{equation*}\nwhere $\\gamma$ is the contour shown: from $-R$ to $R$ along the real axis ($\\gamma_0$) then returning to $-R$ via the upper half plane $\\gamma_R$. This is known as 'closing in the upper half plane'. Now\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{1+z^2} = \\frac{1}{(z+i)(z-i)}\n\\end{aligned}\n\\end{equation*}\nSo the only singularity enclosed by $\\gamma$ is a simple pole at $z=i$, where the residue there is\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{z\\to i} \\frac{1}{z+i} = \\frac{1}{2i}\n\\end{aligned}\n\\end{equation*}\nHence by the Residue Theorem\n\\begin{equation*}\n\\begin{aligned}\n\\int_{\\gamma_0} \\frac{dz}{1+z^2} + \\int_{\\gamma_R} \\frac{dz}{1+z^2} &= \\oint_\\gamma \\frac{dz}{1+z^2}\\\\\n&= 2\\pi i \\frac{1}{2i}\\\\\n&= \\pi.\n\\end{aligned}\n\\end{equation*}\nBut \n\\begin{equation*}\n\\begin{aligned}\n\\int_{\\gamma_0} \\frac{dz}{1+z^2} = \\int_{-R}^R \\frac{dx}{1+x^2} \\to 2I\n\\end{aligned}\n\\end{equation*}\nas $R \\to \\infty$. Also\n\\begin{equation*}\n\\begin{aligned}\n\\int_{\\gamma_R} \\frac{dz}{1+z^2} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $R \\to \\infty$ (see below), so we get in the limit\n\\begin{equation*}\n\\begin{aligned}\n2I + 0 = \\pi \\implies I = \\frac{\\pi}{2}.\n\\end{aligned}\n\\end{equation*}\nTo justify $\\int_{\\gamma_R} \\frac{dz}{1+z^2} \\to 0$ as $R \\to \\infty$, we can use a formal or an informal argument:\\\\\nFormal:\n\\begin{equation*}\n\\begin{aligned}\n|1+z^2| \\geq |1-|z|^2| = |1-R^2| = R^2-1\n\\end{aligned}\n\\end{equation*}\nfor large $R$. So\n\\begin{equation*}\n\\begin{aligned}\n\\left|\\frac{1}{1+z^2}\\right| \\leq \\frac{1}{R^2-1}.\n\\end{aligned}\n\\end{equation*}\nFrom section 2.1(v),\n\\begin{equation*}\n\\begin{aligned}\n\\left| \\int_{\\gamma_R} \\frac{dz}{1+z^2} \\right| \\leq \\pi R \\cdot \\frac{1}{R^1-1} \\to 0\n\\end{aligned}\n\\end{equation*}\nas $R \\to \\infty$.\n\nInformal:\n\\begin{equation*}\n\\begin{aligned}\n\\left|\\int_{\\gamma_R} \\frac{dz}{1+z^2}\\right| &\\leq \\pi R \\sup_{z \\in \\gamma_R} \\left|\\frac{1}{1+z^2}\\right|\\\\\n&= \\pi R O(R^{-2})\\\\\n&= O(R^{-1}) \\to 0\n\\end{aligned}\n\\end{equation*}\nas $R \\to \\infty$.\n\nThis example is not in itself impressive, but the method adapts easily to more difficult integrals.\n\nNote that we could also have 'closed in the lower half plane' instead. Most of the argument would be unchanged; the residue would now be $res{z=-i} \\frac{1}{1+z^2} = -\\frac{1}{2i}$, but the contour now goes clockwise, which results in an additional minus sign that cancels each other.\n\n\\begin{eg}\nTo find\n\\begin{equation*}\n\\begin{aligned}\nI = \\int_0^\\infty \\frac{dx}{(x^2+a^2)^2}\n\\end{aligned}\n\\end{equation*}\nwhere $a>0$ is a real constant, consider\n\\begin{equation*}\n\\begin{aligned}\n\\oint_\\gamma \\frac{dz}{(z^2+a^2)^2}\n\\end{aligned}\n\\end{equation*}\nwhere $\\gamma$ is as above. The only singularity within $\\gamma$ is a pole of order $2$ at $z=ia$, at which the residue is\n\\begin{equation*}\n\\begin{aligned}\n\\lim_{z \\to ia} \\frac{d}{dz} \\frac{1}{(z+ia)^2} &= \\lim_{z \\to ia}\\frac{2}{(z+ia)^3} \\\\\n&= -\\frac{1}{4} ia^{-3}\n\\end{aligned}\n\\end{equation*}\nThe integral around $\\gamma_R$ still vanishes as $R \\to \\infty$, since now\n\\begin{equation*}\n\\begin{aligned}\n\\left|\\int_{\\gamma_R} \\frac{dz}{(z^2+a^2)^2}\\right| \\leq \\pi R \\cdot  O(R^{-4}) = O(R^{-3}).\n\\end{aligned}\n\\end{equation*}\nTherefore\n\\begin{equation*}\n\\begin{aligned}\n2I = 2\\pi i (-\\frac{1}{4} ia^{-3})\n\\end{aligned}\n\\end{equation*}\ni.e. $I=\\frac{\\pi}{4a^3}$.\n\\end{eg}\n\n\\subsection{Advanced Applications of the Residue Theorem: using rectangular contours}\n\n\\subsection{Jordan's Lemma}\n\n\\newpage\n\n\\section{Transform Theory}\n\\subsection{Fourier Transforms}\nThe Fourier transforms of a function $f(x)$ that decays sufficiently rapidly as $|x| \\to \\infty$ is\n\\begin{equation*}\n\\begin{aligned}\n\\tilde{f}(k) \\int_{-\\infty}^\\infty f(x) e^{-ikx} dx\n\\end{aligned}\n\\end{equation*}\nand the inverse transform is\n\\begin{equation*}\n\\begin{aligned}\nf(x) = \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty\\tilde{f}(k) e^{ikx} dk\n\\end{aligned} \n\\end{equation*}\nIt is common for the terms $e^{-ikx}$ and $e^{+ikx}$ to be swapped around in these definitions; more rarely, factors of $2\\pi$ or $\\sqrt{2\\pi}$ are rearranged. Traditionally, if $f$ is a function of position $x$ then the transform variable is called $k$; while if $f$ is a function of time $t$ then it is called $\\omega$.\n\n(*) In fact a more precise version of the inverse transform is\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{2}(f(x^+)+f(x^-)) = \\frac{1}{2\\pi} PV \\int_{-\\infty}^\\infty \\tilde{f}(k) e^{+ikx} dk\n\\end{aligned}\n\\end{equation*}\nwhere PV denotes the principal value of the integral. The LHS indicates that at a discontinuity, the inverse transform gives the \\emph{average} value. The RHS shows that only the \\emph{principal value} of the integral, sometimes denoted dashed$\\int$ is required, i.e. $\\lim_{R \\to \\infty} \\int_{-R}^R$ rather than $\\lim_{R \\to \\infty} \\int_{-R}^S$ (several functions have PV integrals but not normal ones: e.g. $PV \\int_{-\\infty^\\infty} \\frac{x}{1+x^2} dx = 0$, but $\\int \\frac{x}{1+x^2} dx$ diverges at both $-\\infty$ and $\\infty$). This is convenient for us in light of the semicircle method of section 4.3 and 4.5.\n\nThe Fourier transform can also be denoted by $\\tilde{f} = \\mathcal{F}(f)$ or $\\tilde{f}(k) = \\mathcal{F}(f) (k)$. In a slight abuse of notation, we often write $\\tilde{f}(k) = \\mathcal{F}(f(x))$.\n\n\\subsubsection{Properties of the Fourier Transform}\n(i) Linearity: $\\mathcal{F}(\\alpha f + \\beta g) = \\alpha \\mathcal{F}(f) + \\beta \\mathcal{F}(g)$;\\\\\n(ii) Translation: $\\mathcal{F}(f(x-x_0)) = e^{-ikx_0} \\tilde{f}(k)$;\\\\\n(iii) Scaling: $\\mathcal{F}(f(\\lambda x)) = \\frac{1}{|\\lambda|} \\tilde{f}(\\frac{k}{\\lambda})$;\\\\\n(iv) Shifting: $\\mathcal{F} (e^{ik_0 x} f(x)) = \\tilde{f}(k-k_0)$;\\\\\n(v) Transform of a derivative: $\\mathcal{F} (f'(x)) = ik \\tilde{f}(k)$,\nMore generally, $\\mathcal{F} (f^{(n)} (x)) = (ik)^n \\tilde{f}(k)$;\\\\\n(vi) Derivative of a transform: $\\tilde{f}'(k) = -i\\mathcal{F}(xf(x))$; More generally, $\\tilde{f}^{(n)}(k) = (-i)^n \\mathcal{F}(x^n f(x))$;\\\\\n(vii) Parseval's identity:\n\\begin{equation*}\n\\begin{aligned}\n\\int_{-\\infty}^\\infty |f(x)|^2 dx = \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty |\\tilde{f}(k)|^2 dk.\n\\end{aligned}\n\\end{equation*}\n(viii) Convolution: if $h=f*g$, that is, $h(x) = \\int_{-\\infty}^\\infty f(x-x') g(x') dx'$, then $\\tilde{h}(k) = \\tilde{f}(k) \\tilde{g}(k)$.\n\n\\subsubsection{Calculating transforms using the calculus of residues}\n\\begin{eg}\n(i) If $f(x) = e^{-x^2/2}$, then\n\\begin{equation*}\n\\begin{aligned}\n\\tilde{f}(k) &= \\int_{-\\infty}^\\infty e^{-x^2/2} e^{-ikx} dx\\\\\n&= \\int_{-\\infty}^\\infty e^{-(x+ik)^2/2} e^{-k^2/2} dx\\\\\n&= e^{-k^2/2} \\int_{\\gamma_0} e^{-z^2/2} dz \\ (z=x_ik)\n\\end{aligned}\n\\end{equation*}\nwhere $\\gamma_0$ is the contour show, running along the line $\\im z = k$, in the limit $R \\to \\infty$. We can show that $\\int_{\\gamma_R} \\to 0$ and $\\int_{\\gamma_{-R}} \\to 0$, and there are no singularities, so $\\int_{\\gamma_0} = -\\int_{\\gamma_1} = \\int_{-\\infty}^\\infty$ in the limit. Hence\n\\begin{equation*}\n\\begin{aligned}\n\\tilde{f}(k) = e^{-k^2/2} \\int_{-\\infty}^\\infty e^{-z^2/2} dz = \\sqrt{2\\pi} e^{-k^2/2}\n\\end{aligned}\n\\end{equation*}\nusing standard result from \\emph{real} analysis.\n\n(ii) When inverting Fourier transforms, we generally use a semicircular contour (in the upper half plane if $x>0$, and lower otherwise) and apply Jordan's lemma: see the worked example.\n\\end{eg}\n\n\\subsection{Laplace transforms}\nThe Fourier transform is a powerful tool for solving differential equations and investigating physical systems, but it has two key restrictions: first many functions of interest grow exponentially and so do not have Fourier transforms; and secondly, there is no way of incorporating initial or boundary conditions in the transform variable (when used to solve an ODE, the Fourier transform merely gives a particular integral: there are no arbitrary constants produced by the method).\n\nTo get around these restrictions we introduce the \\emph{Laplace transform}, but we have to pay the price with a different restriction: it is only defined for functions $f(t)$ which vanish for $t<0$ (by convention). From now on we shall make this assumption, so that if we refer to the function $f(t) = e^t$ for instance, we really mean $f(t) = e^tH(t)$ where $H$ is the Heaviside function.\n\nThe Laplace transform of such a function is defined by \n\\begin{equation*}\n\\begin{aligned}\n\\hat{f}(p) = \\int_0^\\infty f(t) e^{-pt} dt\n\\end{aligned}\n\\end{equation*}\nIt exists for functions that grow no more than exponentially fast as $t \\to \\infty$.\n\nThe notation $\\hat{f} = \\mathcal{L}(f)$ or $\\hat{f}(p) = \\mathcal{L}(f(t))$ is also used, and the symbol $s$ is often used instead of $p$. Many functions (e..g. $t$ and $e^t$) which do not have Fourier transforms do have Laplace transforms.\n\n(*) Note that $\\hat{f}(p) = \\tilde{f}(-ip)$ \\emph{provided that} both transforms exist.\n\n\\begin{eg}\n(i) $\\mathcal{L}(1) = \\int_0^\\infty e^{-pt} dt = \\frac{1}{p}$.\\\\\n(ii) $\\mathcal{L}(t) = \\frac{1}{p^2}$ by integration by parts.\\\\\n(iii)$\\mathcal{L}(e^{\\lambda t}) = \\int_0^\\infty e^{(\\lambda-p)t} dt = \\frac{1}{p-\\lambda}$.\\\\\n(iv) $\\mathcal{L}(\\sin t) = \\mathcal{L}(\\frac{1}{2i}(e^{it} - e^{-it})) = \\frac{1}{2i}\\left(\\frac{1}{p-i}-\\frac{1}{p+i}\\right) = \\frac{1}{p^2+1}$ using (iii).\n\\end{eg}\n\n(*) Note that the integral only converges if $\\Re p$ is sufficiently large; for instance, in example (iii), we require $\\Re p > \\Re \\lambda$. However, once we have calculated $\\hat{f}$ in this domain, we can consider it to exist everywhere in the complex $p=$plane, except at singularities (such as at $p=\\lambda$ in this example), using analytic continuation as described in section 1.2. (*)\n\nIt is useful to build up a 'library' of Laplace transforms:\n\n\\begin{table}[ht]\n\\caption{Library of Laplace transforms} \n\\centering\n\\begin{tabular}{c c c c}\n\\hline\\hline\n$f(t)$ & $\\hat{f}(p)$ & $f(t)$ & $\\hat{f}(p)$ \\\\ [0.5ex] \n\\hline\n$1$ & $1/p$ & $t^n$ & $n!/p^{n+1}$\\\\\n$e^{\\lambda t}$ & $1/(p-\\lambda)$ & $t^n e^{\\lambda t}$ & $n!/(p-\\lambda)^{n+1}$\\\\\n$\\sin wt$ & $(w/p^2+w^2)$ & $\\cos wt$ & $p/(p^2+w^2)$\\\\\n$\\sinh \\lambda t$ & $\\lambda/(p^2-\\lambda^2)$ & $\\cosh \\lambda t$ & $p/(p^2-\\lambda^2)$\\\\\n$\\delta(t)$ & $1$ & $\\delta(t-t_0)$ & $e^{-pt_0}$\\\\\n[0.5ex] \n\\hline\n\\end{tabular} \n\\end{table}\n\n\\subsection{Properties of the Laplace transform}\nThe first 4 properties are easily proved by substitution.\n\n(i) Linearity: $\\mathcal{L}(\\alpha f + \\beta g) = \\alpha \\mathcal{L}(f) + \\beta \\mathcal{L}(g)$.\\\\\n(ii) Translation: $\\mathcal{L}(f(t-t_0)H(t-t_0))=e^{-pt_0}\\hat{f}(p)$.\\\\\n(iii) Scaling: $\\mathcal{L}(f(\\lambda t)) = \\frac{1}{\\lambda} \\hat{f}(\\frac{p}{\\lambda})$, where we require $\\lambda >0$ so that $f(\\lambda t$ vanishes for $t<0$.\\\\\n(iv) Shifting: $\\mathcal{L}(e^{p_0 t} f(t)) = \\hat{f}(p-p_0)$.\\\\\n(v) Transform of a derivative: $\\mathcal{L}(f'(t)) = p \\hat{f}(p) - f(0)$.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\n\\int_0^\\infty f'(t) e^{-pt} dt &= [f(t) e^{-pt}]_0^\\infty + p\\int_0^\\infty f(t) e^{-pt} dt\\\\\n&= p \\hat{f}(p) - f(0).\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\nRepeating the process, we get\n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{L}(f''(t)) &= p\\mathcal{L}(f'(t)) - f'(0)\\\\\n&= p^2 \\hat{f}(p) - pf(0) - f'(0)\n\\end{aligned}\n\\end{equation*}\nans so on. This is the key fact for solving ODEs using Laplace transforms so should be remembered.\n\n(vi) Derivative of a transform: $\\hat{f}'(p) = \\mathcal{L}(-tf(t))$.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\n&\\hat{f}(p) = \\int_0^\\infty f(t) e^{-pt} dt\\\\\n\\implies & \\hat{f};(p) = -\\int_0^\\infty tf(t) e^{-pt} dt.\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\nMore generally,\n\\begin{equation*}\n\\begin{aligned}\n\\hat{f}^{(n)} (p) = \\mathcal{L}((-t)^n f(t))\n\\end{aligned}\n\\end{equation*}\nSo for example,\n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{L} (t\\sin t) &= -\\frac{d}{dp} \\frac{1}{p^2+1}\\\\\n&= \\frac{2p}{(p^2+1)^2}\n\\end{aligned}\n\\end{equation*}\nfrom section 5.2(iv).\n\n(vii) Asymptotic limits:\n\\begin{equation*}\n\\begin{aligned}\np \\hat{f}(p) \\to \\left\\{\\begin{array}{ll}\nf(0) & p \\to \\infty\\\\\nf(\\infty) & p \\to 0\n\\end{array}\\right.\n\\end{aligned}\n\\end{equation*}\n\\begin{proof}\nfrom (v) above we get\n\\begin{equation*}\n\\begin{aligned}\np \\hat{f}(p) = f(0) + \\int_0^\\infty f'(t) e^{-pt} dt\n\\end{aligned}\n\\end{equation*}\n\\end{proof}\nAs $p \\to \\infty$, $e^{-pt} \\to 0$ $\\forall t$, so $p\\hat{f}(p) \\to f(0)$ (since $f'$ grows no more than exponentially fast). Similarly, as $p \\to 0$, $e^{-pt} \\to 1$, so $p\\hat{f}(p) \\to f(0) + \\int_0^\\infty f'(t) dt = f(\\infty)$.\n\n\\subsection{The Inverse Laplace Transform}\nGiven $\\hat{f}(p)$, we can calculate $f(t)$ using the Bromwich inversion formula\n\\begin{equation*}\n\\begin{aligned}\nf(t) = \\frac{1}{2\\pi i} \\int_{C-i\\infty}^{C+i\\infty} \\hat{f}(p) e^{pt} dp.\n\\end{aligned}\n\\end{equation*}\n\nHere $C$ is a real constant and the inversion contour $\\Gamma$ runs along the vertical line $\\Re p = c$. $\\Gamma$ \\emph{must} lie to the right of all the singularities of $\\hat{f}(p)$.\n\n\\includegraphics[scale=0.4]{CM_25}\n\nIn the case that $\\hat{f}(p)$ has only a finite number of isolated singularities $p_k$, $k=1,...,n$, and $f(p) \\to 0$ as $|p| \\to \\infty$,\n\\begin{equation*}\n\\begin{aligned}\nf(t) = \\sum_{k=1}^n res_{p=p_k} (\\hat{f}(p) e^{pt})\n\\end{aligned}\n\\end{equation*}\nfor $t>0$, and vanishes for $t<0$.\n\nNote that this result \\emph{does not hold} if $\\hat{f}(p) \\not\\to 0$ at $\\infty$ (see example (iii) below).\n\\begin{proof}\nWhen $t<0$, consider the contour $\\gamma' = \\gamma_0 + \\gamma'_R$ shown, which encloses no singularities.\n\n\\includegraphics[scale=0.4]{CM_26}\n\nIf $\\hat{f}(p) = o(|p|^{-1})$ as $|p|\\to \\infty$ then\n\\begin{equation*}\n\\begin{aligned}\n\\left|\\int_{\\gamma'_R} \\hat{f}(p) e^{pt} dp\\right| &\\leq \\pi R e^{ct} \\sup_{p \\in \\gamma'_R} |\\hat{f}(p)| \\to 0\n\\end{aligned}\n\\end{equation*}\nas $R \\to \\infty$ (here we have used $|e^{pt}| \\leq e^ct$ which arises from the fact that $\\Re(pt) \\leq ct$, noting that $t<0$).\n\nIf $\\hat{f}$ decays less rapidly at $\\infty$, but still tends to zero there, the same result holds by a slight modification of Jordan's Lemma. So in either case, $\\int_{\\gamma'_R} \\to 0$. Also, $\\int_{\\gamma_0} \\to \\int_\\Gamma$; by Cauchy's theorem, therefore, $f(t) = 0$ for $t<0$ (As it must do for any function with a Laplace transform; this explains why $\\Gamma$ must lie to the right of all the singularities).\n\nWhen $t>0$, we close the contour to the left instead, and let $\\gamma = \\gamma_0+\\gamma_R$ as shown. Once again we can show that $\\int_{\\gamma_R} \\to 0$ as $R \\to \\infty$.\n\n\\includegraphics[scale=0.4]{CM_27}\n\nHence, by the residue theorem,\n\\begin{equation*}\n\\begin{aligned}\n\\int_\\Gamma \\hat{f}(p) e^pt dp &= \\lim_{R \\to \\infty} \\int_{\\gamma_0}\\hat{f}(p) e^pt dp\\\\\n&= \\lim_{R \\to \\infty} \\int_{\\gamma}\\hat{f}(p) e^pt dp\\\\\n&= 2\\pi i \\sum_{k=1}^n res_{p=p_k} (\\hat{f}(p) e^{pt}).\n\\end{aligned}\n\\end{equation*}\nThe result follows (fiddly) from the Bromwich inversion formula.\n\\end{proof}\n\n\\begin{eg}\n(i) $\\hat{f}(p) = \\frac{1}{p-1}$ has a pole at $p=1$, so we must use $c>1$. We have $\\hat{f}(p) \\to 0$ as $|p| \\to \\infty$, so Jordan's lemma applies as above. Hence $f(t) = 0$ for $t<0$, and for $t>0$, $$f(t) = res_{p=1} \\left( \\frac{e^{pt}}{p-1}\\right) = e^t$$.\n\n(ii) $\\hat{f}(p) = p^{-n}$ has a pole of order $n$ at $p=0$, so $c>0$, and $\\hat{f}(p) \\to 0$ as $|p| \\to \\infty$. Hence for $t>0$, \n\\begin{equation*}\n\\begin{aligned}\nf(t) &= res_{p=0} \\left(\\frac{e^{pt}}{p^n}\\right)\\\\\n&= \\lim_{p=0} \\left\\{ \\frac{1}{(n-1)!} \\frac{d^{n-1}}{dp^{n-1}} e^{pt} \\right\\}\\\\\n&= \\frac{t^{n-1}}{(n-1)!}.\n\\end{aligned}\n\\end{equation*}\n\n(iii) In the case $\\hat{f}(p) = \\frac{e^{-p}}{p}$ we \\emph{cannot} use the standard result above since $\\hat{f}(p) \\not\\to 0$ as $|p| \\to \\infty$ in the left-hand half plane. But we can write\n\\begin{equation*}\n\\begin{aligned}\nf(t) &= \\frac{1}{2\\pi i} \\int_\\Gamma \\frac{e^{-p}}{p} e^{pt} dp\\\\\n&= \\frac{1}{2\\pi i} \\int_\\Gamma \\frac{1}{p} e^{pt'} dp\n\\end{aligned}\n\\end{equation*}\nwhere $t' = t-1$. Now we can close to the right when $t'<0$ and to the left when $t'>0$, picking up the residue from the pole of $\\frac{1}{p}$. Hence\n\\begin{equation*}\n\\begin{aligned}\nf(t) &= \\left\\{ \\begin{array}{ll}\n0 & t'<0\\\\\n1 & t'>0\n\\end{array}\\right. \\\\&= \\left\\{ \\begin{array}{ll}\n0 & t<1\\\\\n1 & t>1\n\\end{array}\\right. \\\\&= H(t-1).\n\\end{aligned}\n\\end{equation*}\n\n(iv) \n\n\\includegraphics[scale=0.4]{CM_28}\n\nIf $\\hat{f}(p)$ has a branch point (at $p=0$ say), then we must use a Bromwich keyhole contour as shown.\n\\end{eg}\n\n\\subsubsection{Derivation of the inverse Laplace transform (*)}\n\nSince $f$ has a Laplace transform, it frows no more than exponentially fast; hence there exists $c \\in \\R$ s.t. \n\\begin{equation*}\n\\begin{aligned}\ng(t) = f(t) e^{-ct}\n\\end{aligned}\n\\end{equation*}\ndecays at $\\infty$ (and is zero for $t<0$ of course). So $g$ has a Fourier transform and\n\\begin{equation*}\n\\begin{aligned}\n\\tilde{g}(w) = \\int_{-\\infty}^\\infty f(t) e^{-ct} e^{-iwt} dt = \\hat{f}(c+iw).\n\\end{aligned}\n\\end{equation*}\nThen invert the Fourier transform, we get\n\\begin{equation*}\n\\begin{aligned}\ng(t) &= \\frac{1}{2\\pi} \\int_{-\\infty}^\\infty \\hat{f}(c+iw) e^{iwt} dw\n\\\\ \\implies f(t) e^{-ct} &= \\frac{1}{2\\pi i} \\int_{c-i\\infty}^{c+i\\infty} \\hat{f}(p) e^{(p-c)t} dp \n\\end{aligned}\n\\end{equation*}\nby substituting $p=c+iw$. The result follows.\n\n\\subsection{The Convolution Theorem for Laplace Transforms}\nThe convolution of two functions $f$ and $g$\n\\begin{equation*}\n\\begin{aligned}\n(f*g)(t) = \\int_{-\\infty}^\\infty (t-t') g(t') dt'.\n\\end{aligned}\n\\end{equation*}\nsimplifies when $f$ and $g$ vanish for negative $t$ to\n\\begin{equation*}\n\\begin{aligned}\n(f*g)(t) = \\int_0^t f(t-t') g(t') dt'.\n\\end{aligned}\n\\end{equation*}\nThe convolution theorem states that $\\mathcal{L}(f*g) (p) = \\hat{f}(p) \\hat{g}(p)$, just as for Fourier transforms.\n\\begin{proof}\n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{L}(f*g) (p) &= \\int_0^\\infty \\{\\int_0^t f(t-t') g(t') dt' \\} e^{-pt} dt\\\\\n&= \\int_0^\\infty \\{ \\int_0^t f(t-t') g(t') e^{-pt} dt'\\} dt\\\\\n&= \\int_0^\\infty \\{ \\int_{t'}^\\infty f(t-t') g(t') e^{-pt} dt\\} dt'\n\\end{aligned}\n\\end{equation*}\nby changing the order of integration in the $(t,t')$ plane, then equals\n\\begin{equation*}\n\\begin{aligned}\n&\\int_0^\\infty \\{ \\int_0^\\infty f(u) g(t') e^{-pu} e^{-pt'} du\\} dt'\\\\\n&= \\int_0^\\infty \\{ \\int_0^\\infty f(u) e^{-pu} du\\} g(t') e^{-pt'} dt'\\\\\n&= \\hat{f}(p) \\hat{g}(p)\n\\end{aligned}\n\\end{equation*}\nas required.\n\\end{proof}\n\n\\begin{eg}\nIf $f(t) = t$, then $\\widehat{f*f} (p) = (\\hat{f}(p))^2 = \\frac{1}{p^4}$.\n\nNow $\\mathcal{L}(t^n) = \\frac{n!}{p^{n+1}}$ (see section 5.2). So $(f*f) (t) = \\frac{1}{6} t^3$. This is easily verified by direct calculation:\n\\begin{equation*}\n\\begin{aligned}\n(f*f) (t) &= \\int_0^t (t-t') t' dt'\\\\\n&= \\frac{1}{2} t^3 - \\frac{1}{3}t^3 = \\frac{1}{6}t^3.\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\subsection{Solution of Differential Equation using the Laplace Transform}\n\\begin{eg}\n(i) The Laplace transform converts constant coefficient ODEs to algebraic equations (and PDEs to ODEs): see the worked example.\n\n(ii) Consider\n\\begin{equation*}\n\\begin{aligned}\nt\\ddot{y} + (1-t)\\dot{y} + 2y = 0, \\ y(0) = 1.\n\\end{aligned}\n\\end{equation*}\nNow\n\\begin{equation*}\n\\begin{aligned}\n\\mathcal{L}(t\\dot{y}) &= -\\frac{d}{dp}\\mathcal{L}(\\dot{y})\\\\\n&= -\\frac{d}{dp}(p\\hat{y}-y(0))\\\\\n&= -p\\hat{y}'-y\n\\end{aligned}\n\\end{equation*}\nusing section 5.3 (vi) and (v). Similarly for $\\mathcal{L}(t\\ddot{y})$. hence we obtain (after simplification)\n\\begin{equation*}\n\\begin{aligned}\np(1-p)\\hat{y}' = (p-3)\\hat{y}\n\\end{aligned}\n\\end{equation*}\nwhich is a first-order ODE for $\\hat{y}(p)$. It is easily solved:\n\\begin{equation*}\n\\begin{aligned}\n\\hat{y} = A \\left(\\frac{1}{p} - \\frac{2}{p^2} + \\frac{1}{p^3}\\right)\n\\end{aligned}\n\\end{equation*}\nwhere $A$ is an arbitrary constant. Using section 5.3 (vii),\n\\begin{equation*}\n\\begin{aligned}\ny(0) = \\lim_{p \\to \\infty} p\\hat{y}(p) = A\n\\end{aligned}\n\\end{equation*}\nso $A=1$.\n\nInverting $\\hat{y}$ using the 'library' in section 5.2 we get\n\\begin{equation*}\n\\begin{aligned}\ny = 1 -2t + \\frac{1}{2}t^2.\n\\end{aligned}\n\\end{equation*}\n\\end{eg}\n\n\\end{document}", "meta": {"hexsha": "4b640a60517ce1d1afb97fabd41c08723d5cb5bc", "size": 72920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/Complex Methods.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/Complex Methods.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/Complex Methods.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": 47.4430709174, "max_line_length": 617, "alphanum_fraction": 0.6702139331, "num_tokens": 26055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.6029452370306407}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{fancyvrb}\n%%\\usepackage{hyperref}\n\n\\RecustomVerbatimEnvironment\n  {Verbatim}{Verbatim}\n  {frame=single}\n\n\\title{Simple Cryptography in Erlang}\n\n\\author{Joe Armstrong}\n\n\\begin{document}\n\n\\maketitle\n\n\\tableofcontents\n\n\\section{Introduction}\n\nIn this note we present a number of {\\sl essential} cryptographic algorithms.\nEach of these algorithms solves a different cryptographic problem.\nThey can be used individually or combined to solve different problems.\n\nWe will give examples of the following:\n\n\\begin{itemize}\n\\item Computing a cryptographic hash of data.\n\\item A Public/Private key asymmetric cryptographic system.\n\\item A symmetric key system.\n\\item A secret sharing algorithm.\n\\end{itemize}\n\nAll the code accompanying this article is in the directory\\\\\n\\verb+https://github.com/joearms/paradis/tree/master/examples/crypto+\n\n\\section{Cryptographic hashes}\n\n\n\n\\begin{tabular}{|p{10cm}}\nA cryptographic hash function is a hash function which is considered\npractically impossible to invert, that is, to recreate the input data\nfrom its hash value alone. These one-way hash functions have been\ncalled \"the workhorses of modern cryptography\".[1] The input data is\noften called the message, and the hash value is often called the\nmessage digest or simply the digest.\n\nThe ideal cryptographic hash function has four main properties:\n\n\n\\begin{itemize}\n  \\item it is easy to compute the hash value for any given message\n  \\item it is infeasible to generate a message that has a given hash\n  \\item it is infeasible to modify a message without changing the hash\n  \\item it is infeasible to find two different messages with the same hash.\n\\end{itemize}\n\nFrom: \\verb+http://en.wikipedia.org/wiki/Cryptographic_hash_function+\n\n\\end{tabular}\n\nSHA1 is one of the most commonly used cryptographic hash algorithms.\nIt produces a 120 bit hash of a data set.\nSHA1 is part of the Erlang standard libraries.\n\nThere are two ways of calling it:\n\n\\begin{Verbatim}[frame=single]\ndigest1() ->\n    crypto:hash(sha, \"hello world\").\n\ndigest2() ->\n    S0 = crypto:hash_init(sha),\n    S1 = crypto:hash_update(S0, \"hello \"),\n    S2 = crypto:hash_update(S1, \"world\"),\n    crypto:hash_final(S2).\n\\end{Verbatim}\n\nThe first example can be used when the data whose hash value is needed\nis small.  The second where the data concerned is large. For example, if\nwe wanted to compare digital images of a few MBytes we could use\nthe first method, but to compute the SHA1 checksum of a GByte movie we\nwould use the second method.\n\n\\subsection{Applications of SHA1}\n\nThe single most important application of cryptographic hashing is in {\\sl\n  validation}. Two data sets can be considered identical if they have\nthe same SHA1 checksum.\n\n{\\sl Note: This is not a mathematical certainty. If we have more than $2^{120}$\n  different files then two will have the same SHA1 checksum}\n\n\\section{Public Key Systems}\n\nIn a public key system two different keys are used. One key is used to\nencrypt the data and a different key is used to decrypt the data.\nUse of different keys is called {\\sl Asymmetric Encryption}.\nThe RSA\\footnote{Named after Don Rivest, Adi Shamir and Leonard Adleman.}  \nalgorithm makes use of two keys \\verb+{A,N}+ and\n\\verb+{B,N}+.\n\nHere's a simple example, first we generate two primes \\verb+P+ and \\verb+Q+:\n\n\\begin{verbatim}\n> P=demo:make_prime(10).\n214578232357\n> Q=demo:make_prime(10).\n10643821901\n\\end{verbatim}\n\nThen we make the two keys:\n\n\\begin{verbatim}\n> {A,B,N}=demo:make_key(P,Q).\n{65537,149155912722954489473,2283932489039303450657}\n\\end{verbatim}\n\nThe modulus \\verb+N+ is just \\verb+P*Q+:\n\n\\begin{verbatim}\n> P*Q.\n2283932489039303450657\n\\end{verbatim}\n\nTo encode the integer \\verb+1234+ (a secret), we compute:\n$1234^A mod N$:\n\n\\begin{verbatim}\n> C = lin:pow(1234,A,N). \n88048242822024428139\n\\end{verbatim}\n\nTo decrypt we use the other key:\n\n\\begin{verbatim}\n> lin:pow(C,B,N). \n1234\n\\end{verbatim}\n\nWe could, of course, use the keys in the opposite order:\n\n\\begin{verbatim}\n> C1 = lin:pow(1234,B,N).\n96928412039852238659\n> lin:pow(C1,A,N).       \n1234\n\\end{verbatim}\n\n\\verb+make_key+ is like this:\n\n\\begin{Verbatim}[frame=single]\nmake_key(P, Q) ->\n    N = P * Q,\n    Phi = (P-1) * (Q-1),\n    E = 65537,\n    D = lin:inv(E, Phi),\n    {E,D,N}.\n\\end{Verbatim}\n\n\\verb+inv(A, B)+ computes \\verb+C+ such that \\verb+A*C mod B = 1+\n\n\\subsection{Applications of RSA}\n\nRSA is {\\sl slow} and {\\sl can only encrypt a small amount of data}\n(ie some value less than \\verb+N+). This is not a problem since we\ntypically use it to encrypt an SHA1 checksum (120 bits) or a short password.\n\nThe above algorithm is called ``text book RSA'' - in reality\nthe key has to be padded\\footnote{See OAEP - ``Optimal Asymmetric Encryption padding.''}\nto the N bits of the modulus.\n\nTo speed up modulo arithmetic we might use ``Montgomery reduction''\n(ie computations module N are time consuming, so we do this modulo\n$2^K$ which is easier, then do some transformation to compute modulo\n$N$).\n\n2048 bit modulos are considered secure\\footnote{The world record is\n  RSA-768 (2000 years on single code 2.2GHz AMD Opteron.}.\n\n\n\\section{Symmetric Encryption}\n\nAES\\footnote{The Advanced Encryption Standard.} is a set of encryption\n  methods which use a {\\sl symmetric encryption algorithm}. This means\n  that the same key is used for encryption and decryption. Here's an\n  example, making use of the code in \\verb+lib1_aes.erl+.\n\n\\begin{Verbatim}[frame=single]\ntest1() ->\n    Password = \"hello\",\n    Plain = <<\"this is plain text\">>,\n    Code = lib1_aes:encrypt(Password, Plain),\n    io:format(\"Code=~p ~p~n\",[Code,size(Code)]),\n    Plain = lib1_aes:decrypt(Password, Code).\n\\end{Verbatim}\n\n\\subsection{Stream Encryption}\n\nTo encrypt a stream of data we can use a stream encryption algorithm.\nEach iteration of the algorithm produces a new key to be used for the\nnext iteration of the algorithm, for example, using RC4 we can write:\n\n\\begin{Verbatim}[frame=single]\ntest1() ->\n    K1 = crypto:stream_init(rc4, \"secret password\"),\n    {K2, C1} = crypto:stream_encrypt(K1, \"hello \"),\n    {K3, C2} = crypto:stream_encrypt(K2, \"world\"),\n    %% ...\n    {S1, M1} = crypto:stream_decrypt(K1, C1),\n    {S2, M2} = crypto:stream_decrypt(S1, C2),\n    {M1, M2}.\n\\end{Verbatim}\n\nRunning this:\n\n\\begin{Verbatim}[frame=single]\n> crypto_examples:test1().\n{<<\"hello \">>,<<\"world\">>}\n\\end{Verbatim}\n\n\\section{Secret Sharing}\n\nShamir's Secret sharing algorithm provides a method of sharing a\nsecret into $N$ parts such that any $K$ parts can recover the\nsecret. Here $K <= N$ and $N > 0$.\n\nThe implementation in this directory is due to Robert Newson and was\npublished at \\verb+https://github.com/rnewson/shamir/+\n\nAs an example, suppose we want to share the secret \\verb+hello+ using\nseven shares, so that any three shares unlock the secret. We can\ngenerate the shares like this:\n\n\\begin{Verbatim}[frame=single]\n> L=shamir:share(<<\"hello\">>, 3,7).                                                \n[{share,3,1,<<206,145,84,97,217>>},\n {share,3,2,<<229,208,230,155,102>>},\n {share,3,3,<<67,36,222,150,208>>},\n {share,3,4,<<56,15,170,12,128>>},\n {share,3,5,<<158,251,146,1,54>>},\n {share,3,6,<<181,186,32,251,137>>},\n {share,3,7,<<19,78,24,246,63>>}]\n\\end{Verbatim}\n\nUsing shares 1 2 and 5 we can reconstruct the secret as follows:\n\n\\begin{Verbatim}[frame=single]\n> shamir:recover([lists:nth(1,L),lists:nth(2,L),lists:nth(5,L)]).\n<<\"hello\">>\n\\end{Verbatim}\n\nThe algorithm fails if we don't give it three different shares:\n\n\\begin{Verbatim}[frame=single]\n> shamir:recover([lists:nth(1,L),lists:nth(2,L),lists:nth(2,L)]).\n** exception error: no function clause matching\n   shamir:recover(3,[{1,10},{2,199}]) (shamir.erl, line 50)\n     in function  shamir:'-recover/1-lc$^2/1-1-'/2 (shamir.erl, line 48)\n     in call from shamir:recover/1 (shamir.erl, line 48)\n\\end{Verbatim}\n\nAgain the shared secret should be a password or digest that unlocks or\nvalidates the content of another file.\n\n\\section{Putting it all together}\n\nThis note has shown a number of different cryptographic algorithms.\nTo make a secure system we combine these in various ways. In building a system\nwe combine the cryptographic code with code to read and write files and sockets\nand to serialize and deserialize data.\n\nWe can use the \\verb+gen_tcp+ to read and write TCP sockets, and\n\\verb+term_to_binary+ and \\verb+binary_to_term+ to turn Erlang terms into\ndata packets which can be stored in files or transmitted in data packets.\n\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "008c61fa4a19f3d9630b5b4593fcc26ae297e9c7", "size": 8493, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/crypto/crypto.tex", "max_stars_repo_name": "joearms/paradis", "max_stars_repo_head_hexsha": "62055b8db643926fd86c8b79f038beb9ac50916f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2015-01-13T03:38:30.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-31T06:46:41.000Z", "max_issues_repo_path": "examples/crypto/crypto.tex", "max_issues_repo_name": "joearms/paradis", "max_issues_repo_head_hexsha": "62055b8db643926fd86c8b79f038beb9ac50916f", "max_issues_repo_licenses": ["MIT"], "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/crypto/crypto.tex", "max_forks_repo_name": "joearms/paradis", "max_forks_repo_head_hexsha": "62055b8db643926fd86c8b79f038beb9ac50916f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-05-12T03:47:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-11T06:07:15.000Z", "avg_line_length": 29.9049295775, "max_line_length": 88, "alphanum_fraction": 0.7287177676, "num_tokens": 2387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.60294523152286}}
{"text": "\\section*{Solution improvement}\nThe idea behind our algorithm is that, in the previous stage, we found some groups of exams which have no conflicts among each other. In order to improve the solution without losing its feasibility, we we look for an improving solution trying to move each exam in a better timeslot.\nSo, we exploit the following algorithm:\n\nLoop until the timeout expires:\n\\begin{enumerate}\n\\item Check if a mutation is needed and mutate consequently.\n\\item For each exam:\n\\begin{enumerate}\n\\item Search the timeslots where the exam does not conflict and where the move is not taboo.\n\\item If there exists at least one available timeslot, for each one of them:\n\\begin{enumerate}\n\\item Move the exam to the new timeslot.\n\\item Evaluate the objective function.\n\\end{enumerate}\n\\item Swap to the best position and mark the move as taboo.\n\\item Save the new solution.\n\\end{enumerate}\n\\end{enumerate}\nSimilarly to the previous phase, the size of the taboo list is a critical parameter. A large value would store a large number of forbidden couples timeslot, exam making the search of an available timeslot a difficult operation, while a small value would force a behavior similar to a steepest descent, which conduces to the exploration of local minimums. After several attempts, we notice that a good empiric size is 100.\n\nA mutation is an important but expensive operation in our algorithm. At the beginning, we tried to mutate every 1000 iterations but it was not effective because it would conduce to an exploration of a flat region. We reduced this parameter, realizing that a too little value would entail an unefficient exploration of the solution space and would slow down the execution. We found a good choice in |E|: this value is a trade-off between the mutation cost and a satisfying exploration.\n\\paragraph*{Mutation}\n\\begin{enumerate}\n\\item Choose a random timeslot $t_1$.\n\\item Save the previous solution temporarily.\n\\item Find the best timeslot to swap the $t_1$ exams into:\n\\begin{enumerate}\n\\item Swap all exams in $t_1$ with the ones in other timeslots.\n\\item Evaluate the objective function for each swap.\n\\item Save the best position.\n\\end{enumerate}\n\\item Choose the best timeslot among the available ones, then swap the exams and mark the move as taboo.\n\\item Save the new solution and evaluate its objective function.\n\\item If it is an improving solution, keep it. Otherwise, restore the previously saved one.\n\\end{enumerate}", "meta": {"hexsha": "eed34a04f18f2c0c14ca9ca83a223ba7fde124b8", "size": 2460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/optimization.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": "Report/optimization.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": "Report/optimization.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": 68.3333333333, "max_line_length": 484, "alphanum_fraction": 0.7951219512, "num_tokens": 542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6029452283261731}}
{"text": "%=============================================================================\n\\section{Experimental Results}\\label{sec:resultModel}\n\nWe used $T_k$ values computed as described in Section~\\ref{sec:proposeModel}. We have performed experiments to evaluate the predictions of our model, by comparing these predictions with measurements of executions of the applications over different GPUs showed in Table~\\ref{tab:GPUs}. For all simulations, we considered $5$ cycles for latency in the communication in shared memory and $500$ cycles are considered for latency communication in global memory \\citep{CUDA:Best}. Finally, for the parameter $\\lambda$, which captures the effects of thread divergence, global memory access optimizations, and shared memory bank conflicts, we used the values described in the previous section. We compared the measured times ($T_m$) with the times predicted by the proposed model ($T_k$), and used the ratio $T_k/T_m$ to define the precision of the prediction. \n\nFigure~\\ref{fig:resultsVMApp} and \\ref{fig:ResultsRodinia} show the obtained results for the vector/matrix applications and some Rodinia Kernels. These figures show the box plots of the accuracy of the BSP-based analytical model over the different selected CUDA kernels. The box plots show the median for each GPU and the upper and lower first quartiles, with whiskers representing the 95\\% confidence interval. Outliers are marked as individual points. For vector/matrix applications in the \\ref{fig:resultsVMApp}, the predicted execution time was within 10\\% of the measured time ($T_k/T_m$ between 0.9 and 1.1). We consider this an excellent result, considering that all the complexity in the memory and thread hierarchy was adjusted using a single parameter $\\lambda$. Moreover, this ratio remained nearly constant for all input sizes, which shows that the prediction accuracy is dependent of the problem size.\n\n\\begin{figure}[htpb]\n\\centering\n \\includegraphics[scale=.4]{./images/ResutAnalyticalModel.pdf}\n\\caption{$T_k/T_m$  of vector and matrix algorithms with different values of $\\lambda$, see table~\\ref{tab:Lambda-NCA}}\n\\label{fig:resultsVMApp}\n\\end{figure}\n\n\nFigure~\\ref{fig:ResultsRodinia} shows the rate between the predicted and measured times of each one of the selected Rodinia CUDa kernels for the all the GPUs. This figure shows that predictions of the kernels BCK-1, BCK-2, HTW and HOT were between 0.9 and 1.1, showing a good prediction capability of the model. It was not possible to predict correctly the execution times of the kernels (GAU-1) and (GAU-2) because in both kernels the number of threads decrease in a loop during the execution of whole application. In both kernels execution around 10 threads are launched. GAU-K1 and GAU-K2 in each iteration of their execution decrease the number of threads and consequently the number of instructions. These instruction variations degraded the throughput significantly and the model required calibration of the parameter $\\lambda$ or another adjustable parameter. These samples of GAU-K1 and GAU-K2 represented in big outliers and we have decided solve it in a future, adding parameters based on throughput. \n\n\\begin{figure}[htpb]\n\\centering\n \\includegraphics[scale=.4]{images/ResutAnalyticalModelRodinia.pdf}\n\\caption{$T_k/T_m$  of Rodinia CUDA kernels with different values of $\\lambda$, see table~\\ref{tab:lambdaRodinia}}\n\\label{fig:ResultsRodinia}\n\\end{figure}\n\n\nThese results show that we can use the model in the scenarios with different GPU types of the same architecture and with only one GPU type. In both cases the model can predict applications execution time from measurements on a single board with a single input size. With different GPU types, the prediction is less precise, since the optimal $\\lambda$ value is different for each board. But it can still produce adequate predictions.\n\nBy considering two levels of memory, shared and global memories, we could accurately model the performance of these applications using several GPU models and problem sizes. The usage of two adaptable parameters $\\lambda$ was sufficient to model the effect of data coalescing during read and write operations to the global memory. A similar set of parameters also model the effects of cache hits, computation and communication process of any GPU application. In the majority of the scenarios, the time measured were around $0.8$ to $1.2$ times the model predicted execution time. \n\nNext section will present some main related works using analytical model to predict GPU applications.\n", "meta": {"hexsha": "cb3ebf181849cdf5b9fac24bf7a636256f751027", "size": 4548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/thesis/sections/result-model.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/result-model.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/result-model.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": 146.7096774194, "max_line_length": 1011, "alphanum_fraction": 0.7900175901, "num_tokens": 974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.795658090372256, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6029452266954584}}
{"text": "\\documentclass[12pt,a4paper,onecolumn]{article}\n\n\\usepackage[top=0.6in, left=0.6in,right=0.6in,bottom=0.6in]{geometry}\n\\usepackage{hyperref}\n\\usepackage{natbib}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{graphicx}\n\\usepackage{mathtools}\n\n\\author{Dionisio Perez-Mavrogenis}\n\\title{ELEC6032 Assignment}\n \n\\newcommand*\\justify{%\n  \\fontdimen2\\font=0.4em% interword space\n  \\fontdimen3\\font=0.2em% interword stretch\n  \\fontdimen4\\font=0.1em% interword shrink\n  \\fontdimen7\\font=0.1em% extra space\n  \\hyphenchar\\font=`\\-% allowing hyphenation\n}\n\n\\begin{document}\n\\maketitle\n\n\\section{Part 1}\n\nThe assigned elliptic curve E curve over the finite field $Z_{17}$ is \n\n$$ y^2 = x^3 + 4x + 3$$\n\ntogether with the point at infinity, $O$.\n\n\\subsection{Find the order of your unique group}\n\n\n\\begin{table}[h]\n\\center\n\\caption{Field $E(Z_{17})$}\n\t\\begin{tabular}{c c c c c c}\n$(1,\\pm5)$ & $(1,\\pm12)$ & $(2,\\pm6)$ & $(2,\\pm11)$ & $(3,\\pm5)$ & $(3,\\pm12)$ \\\\\n$(4,\\pm7)$ & $(4,\\pm10)$ & $(7,0)$    & $(11,\\pm1)$ & $(11,\\pm16)$ & $(13,\\pm5)$ \\\\\n$(13,\\pm12)$ & $(14,\\pm7)$ & $(14,\\pm10)$ & $(15,\\pm2)$ & $(15,\\pm15)$ & $(16,\\pm7)$ \\\\\n$(16,\\pm10)$ & $O$\\\\\n\t\\end{tabular}\n\\label{table:points}\n\\end{table}\n\nBy the script given in Listing \\ref{script_ecc} the cardinality of $E(Z_{17})$ is 38, the elements given in Table \\ref{table:points}. Although one would expect that points should occur in pairs due to the symmetrical properties of elliptic curves, e.g. (15,2) and (15,-2), points with negative coordinates are not in $Z_{17}$, but there exist equivalent coordinates satisfying the equation, e.g. (15,15) instead of (15,-2).\n\n\\subsection{Is your group cyclic? Explain your answer}\nEvery elliptic curve over a field is an Abelian group under addition, with $O$ acting as the identity element. Every elliptic curve is a cyclic group or the product of two cyclic groups (i.e. has at most two generators), unless it is or prime order in which case it is cyclic \\citep{website:cloudflare_primer} \\citep{notes:ecc_notes}.\n\n\n\\subsection{Explain how elliptic curves can be used to construct secure ciphers}\nThe following follows closely \\citep{book:ent}.\n\nTwo parties publicly agree on a prime number $p$, an elliptic curve $E$ over $Z/pZ$ (which is the field $Z_p$ of characteristic $p$) and a point $P\\in E(Z_p)$. Then sender $A$ chooses a secret element $a$ and sends $aP$ to  $B$. $B$ also computes his secret element $b$ and sends $bP$ to $A$. They can both compute $abP$, which is their secret key. For an adversary to compute $n$ from $nP$ (or $m$) it would require solving the discrete logarithm problem for elliptic curves over a field.\n\nThe motivation to use elliptic curves is that the discrete logarithm problem is considered (mathematically) harder to solve for an elliptic curve over a field than it is for a finite field. Furthermore they are able to provide the same level of security as traditional PKI systems, with smaller key lengths (making them more attractive for using on smaller devices such as phones).\\\\\n\n\\subsection{Encrypt the following message using an appropriate elliptic curve cipher}\n\"A little knowledge is a dangerous thing\"\\\\\n\n\\section{Part 2}\nI believe this message is enciphered with a Vigenère cipher and the original text is:\\\\\n\n\\texttt{\\justify the message starts here recently hardware trojans have attracted the attention of governments and researchers one of the main concerns is that integrated circuits in military or critical infrastructure applications could be maliciously manipulated during the manufacturing process which often takes place abroad however since there have been no reported hardware trojans in practice yet little is known about how such a trojan would look like and how hard to implement one in practice one example is dopant trojan this can be used to compromise the security of a meaningful real world target while avoiding detection by functional testing as well as trojan detection mechanisms such trojans can be used to establish a hidden side channel in an otherwise side channel resistant design this trojan does not change the logic value of any gate but instead changes only the power profile of two gates an evaluator who is not aware of the trojan cannot attack the trojan design using common side channel attacks the owner of the trojan however can use his knowledge of the trojan power model to establish a hidden side channel that reliably leaks out secret keys this is the end of the message}\\\\\n\nThis message looks like structured text and hence it might be encrypted with some mono-alphabetic substitution method. First I run it through a Caesar cracking tool with no meaningful results. Then I run it through \\citep{tool:vigenere_cracker}, which yielded a meaningful message for key \\texttt{xayxayxayxayxay}. However, by observing the key that \\citep{tool:vigenere_cracker} derived one can see that it repeats itself and hence ,due to the nature of the cipher, the key could simply be \\texttt{xay}. Furthermore Script \\ref{code2} reports that the highest index of coincidence is found for a key length of 18, which is a multiple of 3.\n\nIn order to crack a Vigenère cipher, and due to this text's length which allows for meaningful statistical analysis, one can either employ the Kasisky test or the index of coincidence text to determine they key length. Once the key length has been determined one can treat the parts that correspond to each key-letter as simple mono-alphabetic substitution cipher and employ statistical methods.\n\n\\paragraph{Kasinsky Test} The Kasinski test is founded on the notion that texts which appear similar on the cipher-text will be the same plain-text that coincidentally was encrypted with the same key. The cryptanalyst looks for identical ciphertext bits that are at least three characters long and records the distance between those($\\mathbf{\\Delta} = {\\Delta _1, \\Delta _2, \\dots , \\Delta _n}$), as the distance is likely to be a multiple of the key-length (i.e. $\\text{Length} = \\text{gcd}(\\mathbf{\\Delta})$).\n\n\\paragraph{Index of Coincidence} The IoC method exploits the fact that letters in a language are not uniformly distributed in words and hence some letters will be more frequent than others. If the letter frequency was equal, then the probability of selecting the same random letter twice (in English) would be $\\sum_{i=a}^{i=z}(1/26)^2 = 0.038$. Given the letter frequencies in English this probability is $\\sum_{i=a}^{i=z}f_i ^2 = 0.067$, $f_i$ is the frequency of letter $i$. One can use this fact to test whether the plain-text was enciphered with a \\textit{single-alphabet} cipher (e.g. Caesar) or not ,as the cipher-text's IoC would approximate that of the plain-text, i.e. 0.067/0.038 = 1.73. Once key-lengths that approach plain-text IoC are found they can be factored and a more systematic search can reveal likely key lengths.\n\n\n\\section{Part 3}\nHere we knew that the second stage is an XOR cipher and the first two characters of the output, Hg. We get the key for the first two bytes by doing \\texttt{Q\" XOR Hg = 0x1945}(or 25 69 in decimal). A naive assumption worth investigating is to try this key for every two bytes of text, done by the script shown in Listing \\ref{code1}. This produces the intermediate text shown bellow : \\\\\n\n\\texttt{\\justify {Hgt ltsbuba pm dumt uy hgt lpyh wqpmpxbr sbr tdxyuct lvyhtqv pm hgtl sdd, xbobpib hp tctb hgt aqtshtyh lubry. Yxqtdv sbvpbt igp htddy vpx hgtv gsct hgt sbyitq uy npouba, lsr pq yulwdv luyhsotb. Hgtqt sqt lsbv hgubay hgsh lsot dumt ipqhg gpdruba pb hp sbr yscpxquba. Exh dumt uy xbwqtrukhsedt sbr it sqt pmhtb lvyhtquty tctb hp pxqytdcty. It hgubo yxkktyy, gswwubtyy, gtdwuba phgtqy, pq yxqwsyyuba pxqytdcty iudd lsot dumt ipqhg ducuba, exh it ksb sdisvy et iqpba pq mqxyhqshtr ev tctbhy. Hguy uy s qsbrpl wgqsyt. Wgudpypwgtqy gsct s dph hp ysv sepxh hgt csdxt pm sdd hgtyt hgubay, sbr s duhhdt dtyy hp ysv sepxh pbt pm hgt lpyh csdxsedt hgubay pm sdd: dpct. Yp it ksb et kdtsq tbpxag sepxh igsh uh ltsby mpq dumt hp gsct ltsbuba sbr csdxt, exh igtb it wxh rpib pxq wgudpypwgv eppoy sbr skhxsddv ath pb iuhg ducuba, ltsbuba sbr csdxt ksb et tdxyuct. Ducuba itdd uy lpqt sqh hgsb ykutbkt pq wgudpypwgv. Hgtqtmpqt,  hgt pbdv ytbyt it ksb lsot pm hgt urts hgsh dumt gsy ltsbuba uy hgsh hgtqt sqt yplt qtsypby hp duct qshgtq hgsb hp rut, sbr hgpyt qtsypby sqt hp et mpxbr ub hgt ducuba pm dumt uhytdm.}}\\\\\n\nThis text is sufficiently large to meaningful provide statistical information about its contents. More importantly, it looks like structured text, something which suggests that the first encryption stage might be a mono-alphabetic substitution. By using \\citep{tool:design215} to get frequency overviews and perform substitutions, we get : \\\\\n\n\\texttt{\\justify{the meaning of life is the most profound and elusive mystery of them all, unknown to even the greatest minds. surely anyone who tells you they have the answer is joking, mad or simply mistaken. there are many things that make life worth holding on to and savouring. but life is unpredicTable~and we are often mysteries even to ourselves. we think success, happiness, helping others, or surpassing ourselves will make life worth living, but we can always be wrong or frustrated by events. this is a random phrase. philosophers have a lot to say about the value of all these things, and a little less to say about one of the most valuable things of all: love. so we can be clear enough about what it means for life to have meaning and value, but when we put down our philosophy books and actually get on with living, meaning and value can be elusive. living well is more art than science or philosophy. therefore, the only sense we can make of the idea that life has meaning is that there are some reasons to live rather than to die, and those reasons are to be found in the living of life itself.}}\\\\\n\nIn order to understand the substitutions I looked for 1-letter words, which is most likely the article \\texttt{a}. Having done that 2 and 3-letter words start appearing and analysing those is easier, as well as observing effects on longer words. Furthermore, the three-grams \\texttt{SRB} , \\texttt{SDD} and \\texttt{NGT} are frequently found, and if we assume that \\texttt{S} is really \\texttt{a}, then \\texttt{SRB} is \\texttt{and} and \\texttt{SDD} is \\texttt{all}(that is the most likely scenario for these two words). Making these substitutions helped reveal more common words.\n\nThe next step that helped a lot was letter frequency, exploiTable~due to the texts length. The frequencies produced by \\citep{tool:design215} are give in Table~\\ref{freqs_q3}. Given the text's length it would be a fair to assume that some of the first letters are vowels, and hence substituting \\texttt{T} for \\texttt{e} gave further insight on the text. Now words with odd repetitions could be exploited, like \\texttt{TCTB(eCeB)}, which contains an averagely common letter with another rare one. Furthermore, it would be safe to assume that \\texttt{C} and \\texttt{B} are both consonants. By trying words like \\texttt{ever, even, eyes} revealed more information and the rest of the text was deciphered in a similar fashion.\n \n\\begin{table*}[t]\n\t\\caption{\\footnotesize Statistical information about the second-stage decrypted text. The top row statistics are for the English language, while the bottom refer to the text.}\n\t\\label{freqs_q3}\n\t\\resizebox{18cm}{!} {\n\t\\begin{tabular}{c c c c c c c c c c c c c c c c c c c c c c c c c c}\nE & T & A & O & I & N & S & H & R & D & L & C & U & M & W & F & G & Y & P & B & V & K & J & X & Q & Z\\\\\n12.7 & 9.1 & 8.2 & 7.5 & 7.0 & 6.7 & 3.3 & 6.1 & 6.0 & 4.3 & 4.0 & 2.8 & 2.8 & 2.4 & 2.4 & 2.2 & 2.0 & 2.0 & 1.9 & 1.5 & 1.0 & 0.8 & 0.15 & 0.15 & 0.1 & 0.07\\\\\n\\hline\nT & S & H & P & B & Y & U & D & G & Q & X & C & L & M & A & I & R & V & W & E & K & O & N & F & J & Z\\\\\n113 & 73 & 72 & 68 & 67 & 65 & 56 & 52 & 49 & 41 & 28 & 21 & 21 & 21 & 20 & 19 & 19 & 17 & 15 & 14 & 11 & 8 & 1 & 0 & 0 & 0 \\\\\n12.9 & 8.38 & 8.26 & 7.80 & 7.69 & 7.46 & 6.42 & 5.97 & 5.62 & 4.70 & 3.21 & 2.41 & 2.41 & 2.41 & 2.29 & 2.18 & 2.18 & 1.95 & 1.72 & 1.60 & 1.26 & 0.91 & 0.11 & 0 & 0 & 0\\\\\n\\hline\ne & a & t & o & n & s & i & l & h & r & u & v & m & f & g & w & d & y & p & b & c & k & j \\\\\n \n\t\\end{tabular}\n}\n\\end{table*}\n\n\n\\section{Part 4}\nIn order to solve this part I used some online tools, as well as scripts that I wrote myself. In particular, I used \\citep{tool:freq_analyzer} to perform frequency analysis and interactive letter substitutions, \\citep{website:puzzle_info} to learn how the puzzles work and \\citep{tool:design215} to search for words matching a given pattern.\\\\\n\nAppendix \\ref{headline_images} gives snapshots from the tool with the deciphered headlines and the letter frequencies. \n\\subsection{Headline 1}\n\\paragraph{Solution} I believe this headline is the text: \\texttt{ntsb urges new ways to combat rising runway incidents}.\n\nOne thing to note on this headline is that the first and last words ,\\texttt{YNTS} and \\texttt{CYOCMBYNT}, contain the same trigraph, \\texttt{YNT}. Furthermore \\texttt{CYOCMBYNT} contains two repeated letters and its ending must make sense in another word. The latter reasoning regarding word endings turned out to be misleading, as NTSB is an acronym for National Transportation Safety Board. \n\nAfter going through a couple of words produced with the pattern \\texttt{---------/abcadebfg} by \\citep{tool:design215}, the word \\texttt{incident} seemed to make more sense in the context of a headline and how the substitutions affected other words. Substituting \\texttt{inciMBnts} to the sentence, \\texttt{HCTCYA} turned into \\texttt{HisinA} and hence \\texttt{A} is most likely \\texttt{g}. After performing that substitution and \\texttt{B} for \\texttt{e} it appeared that \\texttt{K} was most likely \\texttt{w}. Now words like \\texttt{QHges new wJVs} are appearing, suggesting text along the lines of \\texttt{urges new ways} (\\texttt{new} was a big give-away) and helping conclude that \\texttt{R} is \\texttt{o} after performing the substitutions so far.\n\nAfter these previously mentioned steps, the rest of the text is fairly simple to deduce, contains no mistakes and makes sense in the context of a newspaper headline.\n\n\\subsection{Headline 2}\n\\paragraph{Result} I believe that this headline is the text: \\texttt{dutch authorities closing in on human smuggling ring}.\\\\\n\nTo decipher this headline I firstly attempted to investigate the repetition of the letter \\texttt{B} in \\texttt{OAXBBJNHB} and the 9-letter words matching this pattern are shown in Table~\\ref{words1}. Furthermore \\texttt{OAXBBJNHB} ends in \\texttt{HB}, as does \\texttt{WNHB} and \\texttt{YJVONHB}.\n\nAdditionally the two two-letter words \\texttt{NH}\nand \\texttt{VH} are in the set shown in Table~\\ref{words2}, both end with the letter \\texttt{H} and should make sense syntactically and meaning-wise. The letter \\texttt{H} in these words eliminates all words with \\texttt{g, l} in their $8^{th}$ position from Table~\\ref{words1}. Furthermore the word list in Table~\\ref{words2} is further filtered by word likeliness, words whose second letter is not in any other word and by the possible $8^{th}$ position letters of Table~\\ref{words1} words. This leaves a reduced list, shown in Table~\\ref{words2}.\n\nAfter using words ending in \\texttt{s} and after using \\texttt{crossties}, it seemed unlikely that \\texttt{B} was \\texttt{s} or that the word started with a \\texttt{c}. Substituting \\texttt{OAXBBJNHB} for the word \\texttt{smuggling} some patterns in the words appeared, starting with the word \\texttt{authorities} and from there on it was a case of the text making sense.\n\n\\begin{table}\n\t\\center\n\t\\caption{9-letter words with repeated 4th and 5th letters, ending on that letter as well.}\n\t\\label{words1}\n\n\t\\begin{tabular}{c c c c c c c}\n\t\\hline\n\tblessings & blottiest & brattiest & brittlest & brummagem & chasseurs &  \tchattiest\\\\\n\tcoassumes & crossings & crosslets & crossties & crossways & draggling &  \tdressings\\\\\n\tglassines & glissades & glossinas & gnattiest & grottiest & knottiest & plottiest\\\\\n\tplussages & pressings & reassigns & scheelite & smuggling & threesome &  trussings\\\\\n\tunseeable  \\\\\n\t\\end{tabular}\n\\end{table}\n\n\\begin{table}\n\\caption{2-letter words and reduced list.}\n\\label{words2}\n\n\t\\begin{tabular}{|c c c c c c c c c c c|}\n\t\\hline\n\tad & am & an & as & at & be & by & de & do & el & en \\\\\n\tgo & he & id & if & in & is & it & ma & me & my & no \\\\\n\tnu & of & oh & on & or & pi & so & to & up & us & we \\\\\n\t\\hline\n\t\\end{tabular}\n\t\\quad\n\t\\begin{tabular}{|c c c c c c c|}\n\t\\hline\n\tan & on & in & as & is & us & at\\\\\n\tit & be & he & me & we & by & my\\\\\n\tdo & go & so & to & no & if & of\\\\\n\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsection{Headline 3}\nI believe this headline is the text : \\texttt{dollar,euro outpace yen in choppy trading}.\\\\\nHow this headline was found follows later.\n\\subsection{Headline 4}\nI believe this headline is the text : \\texttt{ripken looking for quick return from disabled list}.\\\\\nHow this headline was found follows later.\n\\subsection{Headline 5}\nI believe this headline is the text : \\texttt{chrldless employees see discrimination in family friendly policies}.\\\\\n\nThe starting point for this headline was the ending of the word \\texttt{TBDSPKTTY}, the word \\texttt{YTT} and the ending of the word \\texttt{HQUSESTYY}. The word \\texttt{YTT} contains two very frequent letters, and one is a repetition. The letter \\texttt{T} could be a vowel. The word \\texttt{see} seemed like a very good candidate. Substituting \\texttt{see} for \\texttt{YTT} made the word \\texttt{TBDSPKTTY} seem like \\texttt{employees}, and after substitution, the first words started appearing.\n\nThe next stage of decryption was the word \\texttt{JCBRSKJURTWESK}. The tool \\citep{tool:design215} produces a list of words matching this pattern and after trial and error the most likely word is \\texttt{discrimination}. \n\nAfter substitution of \\texttt{discrimination}, the next word that seemed promising is \\texttt{DPSRHRTY}, which most likely seems the be the word \\texttt{policies}.\n\nAfter performing all these substitutions, it is a matter of substituting the remaining letters and deciphering the message. The resulting message contains an error (one would expect ch\\textit{i}ldless rather than ch\\textit{r}ldless), but one would expect more errors to be in the sentence if the mapping was somehow forced to make the resulting plain-text.\n\n\\subsection{Discussion}\nAccording to \\citep{website:puzzle_info}, the first step to solving the puzzle is to build the mixed alphabet. Following the process described on the website (weaving of substitution chains of headlines 2 and 5 here, as I was unable to weave 2 and 3), the mixed alphabet produced was \n\\texttt{girumbnwxachqlsykfjopdetvz}. To verify that this is correct, the mapping generated by sliding the alphabet against itself should decipher the solved headlines and produce meaningful text for the unsolved ones, which happens. The shift in the alphabet that solves each headline is $9, 5, 21, 7, 1$ and by stacking the resulting shifted-putative alphabets we can find the setting word, which I found to be \\texttt{toady}. One can then reorder the alphabet so that \\texttt{toady} is in the first column of the stacked alphabets and hence the shifted alphabet becomes  \\texttt{sykfjopdetvzgirumbnwxachql}. Inputing that into the tool \\citep{website:key_finder} yields the key \\texttt{sycophant} and keyword square presented in Table~\\ref{tab:ks}, indicating that the hat is of length 10.\n\n\n\\begin{table}\n\\center\n\\caption{The keyword square.}\n\\label{tab:ks}\n\t\\begin{tabular}{c}\n\t\t\\texttt{SYCOPHANTB}\\\\\n\t\t\\texttt{DEFGIJKLMQ}\\\\\n\t\t\\texttt{RUVWXZ}\\\\\n\t\\end{tabular}\n\\end{table}\n\n\n\\bibliographystyle{plain}\n\\bibliography{crypto_report}\n\n\\pagebreak\n\\appendix\n\\section{Source code}\n\n\\textbf{Note} : The scripts in this section were produced by me in order to help me understand some concepts or aid my investigation. \\\\\n\n\\definecolor{gray}{rgb}{0.5,0.5,0.5}\n\\definecolor{bggray}{rgb}{0.9,0.9,0.9}\n\\definecolor{mygreen}{rgb}{0,0.5,0}\n\n\\lstdefinestyle{mypy}{\n\tbackgroundcolor=\\color{bggray},\n\tlanguage=Python,\n\tbasicstyle=\\ttfamily,\n  \tcaptionpos=b,\n\tnumbers=left, \n\tkeywordstyle=\\color{blue}, \n\tshowspaces=false,\n\tcommentstyle=\\color{mygreen},\n\tnumberstyle=\\footnotesize\\color{gray},\n}\n\n\\lstinputlisting[caption=Code that performed the XOR operation with the key for question 3.,\n\t\t\t\tlabel=code1,\n\t\t\t\tstyle=mypy]\n\t\t\t\t\t{cw_files/question_3/question_3.py}\n\\lstinputlisting[caption=Code that perform shifting of the putative alphabet.,\n\t\t\t\tlabel=script_shift,\n\t\t\t\tstyle=mypy]\n\t\t\t\t\t{cw_files/question_4/headline.py}\n\n\\lstinputlisting[style=mypy, \n\t\t\t\tcaption=Code that iterates though the field $Z_{17}$ to check for solutions to elliptic curve E with equation $ y^2 \\text{=} x^3 + 4x + 3 $.,\n\t\t\t\tlabel=script_ecc]\n\t\t\t\t\t{cw_files/question_1/ecc.py}\n\n\\pagebreak\n\\lstinputlisting[style=mypy,\n\t\t\t\tcaption=Code that performs Index of Coincidence analysis.,\n\t\t\t\tlabel=code2]\n\t\t\t\t\t{cw_files/question_2/ioc.py}\n\\pagebreak\t\t\t\t\t\t\t\t\t\t\n\n\\section{Headline Puzzle Substitutions}\n\\label{headline_images}\n\n\t\\begin{figure*}[h]\n\t\t\\center\n\t\t\\includegraphics[scale=0.7]{cw_files/question_4/q1/q1_sol.png}\n\t\t\\caption{Letter frequency analysis and mapping for headline 1.}\n\t\\end{figure*}\n\n\t\\begin{figure*}[h]\n\t\t\\center\n\t\t\\includegraphics[scale=0.7]{cw_files/question_4/q2/Q2_sol.png}\n\t\t\\caption{Letter frequency analysis and mapping for headline 2.}\n\t\\end{figure*}\n\t\n\t\\begin{figure*}[h]\n\t\t\\center\n\t\t\\includegraphics[scale=0.7]{cw_files/question_4/q5/puzzle_5.png}\n\t\t\\caption{Letter frequency analysis and mapping for headline 5.}\n\t\\end{figure*}\n\n\\end{document}\n", "meta": {"hexsha": "1eb0e9972ea04ea7c1b08e30df20948130caee6a", "size": 21657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "year_4/crypto/crypto_report.tex", "max_stars_repo_name": "dperezmavro/courseworks_uni", "max_stars_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_stars_repo_licenses": ["MIT"], "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_4/crypto/crypto_report.tex", "max_issues_repo_name": "dperezmavro/courseworks_uni", "max_issues_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_issues_repo_licenses": ["MIT"], "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_4/crypto/crypto_report.tex", "max_forks_repo_name": "dperezmavro/courseworks_uni", "max_forks_repo_head_hexsha": "d65e76576ac22c2cec6c1995e462be2a20717090", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.9151291513, "max_line_length": 1207, "alphanum_fraction": 0.7480722168, "num_tokens": 6372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6029304713177243}}
{"text": "\\section{RNG02: Random Number Generators -- 02}\n[Warren D. Smith provided the analysis and the generators.]\n\nThe goal is to combine several random number generators to get at least the \nrandomness of the strongest of them, but to do it in such a way as\nto get nearly the speed of the fastest of them.\n\nNOTE: I use a lot of global variables here to save statistice,\nnecessary in modula3 since C's \"statisticic\" feature does not exist.\nOf course these variables are local to the current module.\nFor that reason, please keep this a seperate module from others,\ne.g. the derived routines for NormalDeviate, etc. should not be in\nsame module as these underlying routines for uniform deviates.\n\nSome component generators:\nFollowing G.Marsaglia: A current view of RNGs, pages 3-10 in\nComputer Science and Statistics, the interface, Elsevier 1985,\na fair number of my generators are of the FIBO(a,b,\\%) type, where\n$a>b>0$ are integers such that $x^a+x^b+1$ is a primitive trinomial\nmod 2 and \\% is a binary operation.\n\nSuitable values of (b,a) are tabulated in D.Knuth: Seminumerical methods,\nAddison-Wesley 1981, page 28, which is extracted from larger tables in\nN.Zierler \\& J.Brillhart: Information and Control 13 (1968) 541-554;\n14 (1969) 566-569; 15 (1969) 67-69. Some pairs with \"a\" prime which\ngo beyond the Knuth table, which you can use if you *really*\nwant randomness, include: \n\\begin{verbatim}\n  (7,127), (15,127), (30,127), (63,127),    (32,521), (158,521), \n  (105,607), (147,607), (273,607),     (216,1279), (418,1279)\n\\end{verbatim}\n\nThe binary operation \\% could be: [- mod 1] for floating point values,\n[- mod M] or [* mod M] for some integer M,\nor [this NOT recommended; it is same as - only mod 2] XOR.\n\nThen the meta-procedure Fibo(a,b,\\%) is as follows (it\nrequires an auxiliary arr : ARRAY [0..a-1], initially filled with\nrandom seed values, and initially ia=a and ja=b:\n\n\\begin{verbatim}\nMetaRandGen() : Type =\n  BEGIN\n    DEC(i);\n    DEC(j);\n    IF i<0 THEN\n      i := a-1; (* wraparound *)\n    ELSIF j<0 THEN\n      j := a-1; (* wraparound *)\n    END;\n    arr[i] := arr[i] \\% arr[j];\n    RETURN arr[i];\n  END MetaRandGen;\n\\end{verbatim}\n\nPeriod [Marsaglia \\& Tsay:  Lin. Alg. and its\n   Appl. 67, 147-155, 1985]: If \\% is $(- \\mbox{mod} 2^{\\mbox{wordsize}})$,\nthen if at least one of the arr[] is odd\nthe period will be maximal $= (2^a - 1) * 2^{(\\mbox{wordsize}-1)}$ if\nthe characteristic axa matrix T of the recurrence has full order\n$J=(2^a - 1)$ in mod 2 arithmetic (this assured by the trinomial condition)\nand 2*J in mod 4 and 4*J in mod 8 arithmetic. That is, if you square\nT a times, you get back T in mod 2, but do NOT get back T in mod 4,\narithmetic, and if you square T a+1 times, you do not get back T\nin mod 8 arithmetic. In fact, this criterion will work for any\nmatrix T, not necessarily the fibo($-$) one...\n\nIf \\% is $[* \\mbox{mod} 2^{\\mbox{wordsize}}]$, which may be implemented in m3 by Word.Times(),\nthen arr[] must be all odd integers, and by considering discrete logs\nwe see that the period is maximal $= (2^a - 1) * 2^{(\\mbox{wordsize}-3)}$ if\nthe $F(a,b,+ \\mbox{mod} 2^{\\mbox{wordsize}})$ has maximal period\n$(2^a - 1) * 2^{(\\mbox{wordsize}-1)}$.\n\nMarsaglia's test results for Fibo(a,b,\\%) generators with\n(a,b)=(17,5), (31,13) and (55,24):\n\\begin{description}\n\\item[XOR] With \\%=XOR the fibo fail seven of the tests in Marsaglia's battery.\nAs Marsaglia says in his conclusion \"never use XOR.\" Despite this,\nthese generators keep resurfacing, for example the \"r250\" Fibo(250,147,XOR)\ngenerator of S. Kirkpatrick and E.  Stoll, Journal of Computational\nPhysics, 40, p. 517 (1981) and W. L. Maier, \"A Fast Pseudo Random\nNumber Generator\", Dr. Dobb's Journal \\#176.\n\n\\item[Subtraction] With \\%=-, among the tests in Marsaglia's DIEHARD battery\nonly the \"birthday spacings test\" (of frequencies of spacings in sorted sets \nof deviates) is failed, a symptom both of the linear structure\nand also of the specific subtractive structure of these generators.\nNote that the Fibo(55,24,-) generator (which fails this test) is to be found\nin Knuth's book and also is distributed with the DEC SRC implementation of\nmodula-3. Also note that postprocessing Fibo(55,24,-) sequence with a\nBays-Durham shuffler, recommended in Press et al. \"Numerical Recipes\" to\nfix suspicious generators, will NOT work to make it now pass this test, since\nthe birthday spacings test does not depend upon the ordering of the\ndeviates only their values.\n\n\\item[Multiplication] With \\%$=* \\bmod 2^{32}$, these\nFIBO gens passed all the tests in\nMarsaglia's battery.\n\\end{description}\n\nNote that the -,+ and XOR gens are \"linear\" and hence theoretically\nbad and will always fail \"empty slab tests\" see below.\n\nNote that shift register, Fibonacci() generators with +,- or XOR,\nand linear congruential generators x <-- a*x+b mod M, AND linear\ncombinations of such possibly to different moduli, are all\n\"linear\" and thus generate d-tuples of random numbers lying on\nAT MOST $M^{(1/d)}$ hyperplanes in d-space. Consequently,\nthe nonrandomness of a linear RNG with period M is in principle\ndetectable by the \"largest empty slab\" test in .4*logM dimensions\nafter only N,\n\\begin{verbatim}\n  N > e^(5/2) * (.4*logM)^2.5 * loglogM,\n\\end{verbatim}\nrandom numbers have been generated. Hence:\nPlease do not rely on a linear generator.\nIf you are going, foolishly, to use a linear congruential generator, though,\nyou want a \"good multiplier\" a mod M. (Bad multipliers\nwill result in even fewer hyperplanes, for example IBM's\ninfamous RANDU generator generated points lying on only 15 planes in 3-space.\nEven with fairly good multipliers we still get test failures, e.g. Marsaglia's\nspectrally good multiplier $69069 \\bmod 2^{32}$ fails his OPSO test, as does\nthe Berkeley PASCAL $62605 \\bmod 2^{29})$. It will suffice, for\ncomparatively good behavior in d-space, that\n\\begin{verbatim}\n   (a^d mod M)/M\n\\end{verbatim}\nhave only small partial quotients in its continued fraction expansion.\nThis should be tested for $d=1,2,..,8$ at least.\n\nThus for example, consider the prime modulus $M=2^{35} - 849$.\n$(M-1)/2$ is also prime. I found the generator $g=145683$ by computer\nsearch. The continued fraction expansions\n\\begin{verbatim}\nCF(g/p)=[235852,1,3,6,1,1,5,1,1,2,1,1,1,1,6,2]\nCF(g^2/p)=[1,1,1,1,1,1,1,1,21,2,7,1,8,1,2,1,1,2,5,1,1,1,2,1,2,3,12,2]\n\\end{verbatim}\nare rather nice, and the $CF( (g^x \\bmod p)/p )$ for $x=3,4,5,6,7,8,9$ are\nalso not bad (no partial quotient larger than 23):\n\\begin{verbatim}\n [2,1,1,1,1,1,1,1,1,16,1,3,5,1,2,1,1,3,1,1,1,21,1,8,10,5]\n [8,4,3,1,1,3,4,2,7,1,22,22,9,1,12,1,2,2]\n [1,1,1,20,1,23,1,4,2,2,1,1,1,8,1,1,2,1,2,2,1,22,1,2,1,3]\n [1,1,15,1,1,10,2,2,2,1,4,5,1,2,1,1,5,7,7,2,2,4,2]\n [1,1,5,2,2,1,1,1,7,11,3,4,1,9,1,6,3,1,8,1,3,1,1,1,2]\n [1,13,1,7,8,1,1,2,16,2,2,1,1,6,4,1,3,1,1,3,15,2]\n [2,1,2,1,15,2,1,5,1,8,1,1,2,1,4,3,1,3,1,1,1,1,2,1,3,1,3,5]\n\\end{verbatim}\nso we conclude that using g as a multiplier should exhibit comparatively\ngood behavior in dimensions 2-9. This particular (g,M) pair\nhas the virtue that IEEE doubles can represent integers up to and including\n$2^{53} - 1 $exactly, so that the modula-3 statisticement\n\\begin{verbatim} x := (g*x) MOD M; \\end{verbatim}\nwill evaluate it exactly.\n\nAs another example, the Marsaglia multiplier\n$69069 \\bmod 2^{32}$, while spectrally good in\ndimensions 2-5, is bad in dimension 6, as is revealed by the spectral\ntest directly but also simply by noticing that the CF expansion of\n$69069^6 / 2^{32}$ is [1, 75, 1, 2, 2, 1, 20, 10, 3, 10, 2, 2, 1, 12, 9]\nwhich contains the large number 75 early on.\n\nYou also probably want\nfull period M, which happens if [thm page 16 Knuth]\n\\begin{verbatim}\n  (1) GCD(b,M)=1;\n  (2) a-1 is a multiple of p for every prime p dividing M;\n  (3) a-1 is a multiple of 4 if 4 divides M.\n\\end{verbatim}\nIf M is prime and b=0, you get maximal period M-1 if a primitive mod M.\nIf M>=16 is power of 2 and b=0, get maximal period M/4 if a=3 or 5 mod 8.\n\n\\subsection*{Other Fibo generators}\nInstead of just using one lag term and binary operation \\%, you could combine\nwith TWO lag terms via some TERNARY operation, or THREE lag terms\nvia a QUATERNARY operation, etc. I suggest the new generator\n\\begin{verbatim}\n  QuaternaryFibo(a,b,c,d, x0 - (x2 XOR (x1 - x3) mod M) mod M ).\n\\end{verbatim}\n\nIf M is $2^{\\mbox{wordsize}}$ and $x^a+x^b+x^c+x^d+1$, $a>b>c>d>0$,\n is a primitive\npolynomial mod 2, then this generator's period will be at least $2^a - 1$\nsimply by considering the LS bit, which will follow a DeBruijn sequence\nand thus exhibits good randomness in $\\le a$ dimensions.\nMy idea is that by using\nboth XOR and +, we hope to avoid the weak behavior of either operation\nalone, e.g. with respect to the birthday spacings test. This may also\nmake the generator \"nonlinear\" (i.e. not outputting a lattice), a point\nI am unsure about. Ternary generators of this type do not seem to exist since\n4-term primitive polynomials $x^a+x^b+x^c+1 \\bmod 2$ do not exist (you\nneed an odd number of terms, as can easily be shown).\nFor tables of examples of primitive polynomials mod 2, see E.J.Watson: Math. of\nComput. 16 (1962) 368-9 but the ones given are the lexically first examples,\nbad for our purposes.\n\nHence I constructed my own small table below of examples of primitive\npolynomials $P=x^a+x^b+x^c+x^d+1 \\bmod 2$, where a is prime and\n$N=2^a - 1$\nis a Mersenne prime. For such a, P is primitive if $P^N$\ndivides $x^N-1 \\bmod 2$,\nwhich you can test by the algorithm\n\\begin{verbatim}\n  Q := x;\n  FOR i:=1 TO a-1 do\n    Q := Q*Q*x mod P;\n  END;\n  IF Q=1 THEN \"P is primitive.\"\nTable:\nx^19 + x^9 + x^4 + x^3 + 1\nx^19 + x^6 + x^2 + x^1 + 1\nx^31 + x^22 + x^20 + x^8 + 1\nx^31 + x^16 + x^11 + x^6 + 1 \nx^61 + x^5 + x^2 + x^1 + 1 \nx^61 + x^57 + x^2 + x^1 + 1 \nx^61 + x^19 + x^16 + x^9 + 1\nx^89 + x^36 + x^2 + x^1 + 1\nx^89 + x^57 + x^14 + x^5 + 1\nx^89 + x^28 + x^26 + x^9 + 1\nx^89 + x^37 + x^5 + x^1 + 1\nx^107 + x^53 + x^45 + x^12 + 1\nx^107 + x^93 + x^68 + x^2 + 1\nx^127 + x^29 + x^17 + x^7 + \nx^127 + x^67 + x^65 + x^17 + 1\nx^127 + x^60 + x^22 + x^9 + 1\nx^521 + x^46 + x^38 + x^37 + 1\nx^521 + x^249 + x^92 + x^87 + 1\nx^521 + x^353 + x^258 + x^6 + 1 \nx^607 + x^66 + x^60 + x^30 + 1 \nx^607 + x^247 + x^83 + x^71 + 1\nx^607 + x^483 + x^449 + x^298 + 1 \nx^607 + x^442 + x^113 + x^23 + 1 \n\\end{verbatim}\n\nIt is a disgusting fact that in modula3 as well as most high level languages,\nthe machine language multiply instruction that computes a*b to double\nprecision is NOT ACCESSIBLE. Ditto \"add with carry\". This makes an\nefficient implementation of high precision multiplication (\\& modular\nversion) obnoxiously difficult and inefficient. And you really\ndo need multiple precision to get a decent period with a lincong\nor iterated squaring generator.\n[Note the SQUARE ROOT of the period must be unreachably large for\ngood randomness, NOT the period, a common error.]\nHere is a MetaAlgorithm which works\nif numbers 0..modulus*2-2 are representable...:\n\\begin{verbatim}\n  MetaModularMultiply(x,y, modulus: NumType) : NumType =\n  VAR\n    q : NumType := x;\n  BEGIN\n    FOR b = bits of y in MS-->LS order starting\n        at the bit AFTER the first 1 bit DO\n      q := q+q;\n      IF q>=modulus THEN q := q-modulus; END;\n      IF b=1 THEN\n        q := q+x;\n        IF q>=modulus THEN q := q-modulus; END;\n      END;\n    END;\n    RETURN q;\n  END MetaModularMultiply;\n\\end{verbatim}\n\nOne way to improve the randomness of a generator is\nC.Bays and S.D. Durham's shuffling algorithm, ACMTOMS 2 (1976)\n59-64, also described in D.Knuth: Seminumerical algorithms.\nKnuth says this will output a \"considerably more random\" sequence.\nHowever, the set of values will still be the same (although ordered\ndifferently) hence, e.g., the subtractive and XOR fibo gens will\nSTILL fail Marsaglia's birthday spacings test even after improvement\nby shuffling. However, linear congruential generators are probably\nsubstantially improved by shuffling since the lattice structure is\ndestroyed.\n\nL.Blum, M.Blum, M. Shub: A simple unpredictable psuedo-random\nnumber generator, SIAM J. Comput 15,2 (1986) 364-\nfollowing\nA.Yao: Theory and applications of trapdoor fns, 23rd SFOCS (1982) 80-91\nand\nW.Alexi, B.Chor, O.Goldreich, C.P.Schnorr: 25th SFOCS (1984) 449-457.\npoint out that iterated squaring generator\n\\begin{verbatim}\n  x <--- x*x mod M\n\\end{verbatim}\nwhere M=p*q, p, q primes that are 3 mod 4, will have these properties\n(assuming it is computationally infeasible to compute the factorization of M)\n\\begin{enumerate}\n\\item infeasible to predict the PREVIOUS x.\n\\item infeasible to predict the least signif bit of the\n    previous x with correctness prob $>$ 1/2 + 1/polynomial.\n\\item infeasible to predict the boolean \"x<(M-1)/2\" for the\n    previous x with correctness prob $>$ 1/2 + 1/polynomial.\n\\end{enumerate}\nConsequence of (2) is: no polynomial time statistical test\ncan invalidate the randomness of the sequence of LS bits of\nthe iterated squaring generator. \n\nThe full iterated squaring gen, not just its LS bits,\nis a lot faster and (conjecturally!) just as random.\nIts period is (p-1)*(q-1)/4.\n\nExample: Here is a product of two primes both 3 mod 4:\n\\begin{verbatim}\n 94906247 * 94906219 = 9007193062250093 = 2^53 - 6192490899.\n\\end{verbatim}\nHere is a smaller example:\n\\begin{verbatim}\n    M = 9739 * 9719 = 94653341.\n\\end{verbatim}\nThis modulus has the virtue that iterated squaring mod M\nmay be accomplished exactly in IEEE double arithmetic using\n\\begin{verbatim}\n x := x*x MOD M, since M^4 < 2^53 - 1.\n\\end{verbatim}\nAn even smaller modulus suitable for 32-bit unsigned arithmetic is\n\\begin{verbatim}\n    M = 239*251; (* = 59989; 239 and 251 are each primes and 3 mod 4 *).\n\\end{verbatim}\n\nMore generally you could use iterated cubing (subject to the conjecture\nit is infeasible to break any bit of the RSA cryptosystem) or in fact\nany fixed exponent you want (under same conjecture) and in fact almost\nany fixed integer linear operation on the discrete logarithms of a vector\nwill by the same reasoning be immune to any polynomialtime statistical test,\nsubject to RSA-type conjectures. In particular, we conjecture that the\nFibo[a,b,*] generator ought to be immune to polynomialtime statistical tests\nif the modulus is the product of two suitable large primes... which\nexplains the results of the Marsaglia test battery above.\n\n\n\n\n\n", "meta": {"hexsha": "0731a763226c7975b8ab7512ce7e94b6c77d9f62", "size": 14308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "m3-libs/arithmetic/doc/rng02.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/rng02.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/rng02.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": 42.8383233533, "max_line_length": 94, "alphanum_fraction": 0.710301929, "num_tokens": 4759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6029304661445423}}
{"text": "\\documentclass[12pt]{cdblatex}\n\\usepackage{exercises}\n\\usepackage{fancyhdr}\n\\usepackage{footer}\n\n\\begin{document}\n\n% --------------------------------------------------------------------------------------------\n\\section*{Exercise 1.4 Experiments with sorting}\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,x,y,z#}::Indices(position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   expr := C^{f}\n           w^{e}\n           B^{d}\n           v^{c}\n           A^{b}\n           u^{a}.                        # cdb (ex-0104.100,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.101,expr)\n\n   expr := \\Omega_{f}\n           \\gamma_{e}\n           \\Pi_{d}\n           \\beta_{c}\n           \\Gamma_{b}\n           \\alpha_{a}.                   # cdb (ex-0104.200,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.201,expr)\n\n   expr := C^{f}\n           w^{e}\n           B^{d}\n           v^{c}\n           A^{b}\n           u^{a}\n           \\Omega_{f}\n           \\gamma_{e}\n           \\Pi_{d}\n           \\beta_{c}\n           \\Gamma_{b}\n           \\alpha_{a}.                   # cdb (ex-0104.300,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.301,expr)\n\n   expr := \\partial_{f}{C^{f}}\n           w^{l}\n           \\partial_{d}{B^{d}}\n           v^{k}\n           \\partial_{b}{A^{b}}\n           u^{j}\n           \\Omega_{i}\n           \\partial^{e}{ \\gamma_{e}}\n           \\Pi_{h}\n           \\partial^{c}{\\beta_{c}}\n           \\Gamma_{g}\n           \\partial^{a}{\\alpha_{a}}.     # cdb (ex-0104.400,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.401,expr)\n\n   expr := \\partial{C}\n           w\n           \\partial{B}\n           v\n           \\partial{A}\n           u\n           \\Omega\n           \\partial{ \\gamma}\n           \\Pi\n           \\partial{\\beta}\n           \\Gamma\n           \\partial{\\alpha}.             # cdb (ex-0104.500,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.501,expr)\n\n   expr := A_{b}\n           A_{a}\n           A_{c d e}\n           A_{f g}.                      # cdb (ex-0104.600,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.601,expr)\n\n   expr :=  A_{a} A^{a}\n          + A^{a} A_{a}.                 # cdb (ex-0104.700,expr)\n\n   sort_product (expr)                   # cdb (ex-0104.701,expr)\n\n\\end{cadabra}\n\n% \\clearpage\n\n\\begin{dgroup*}[spread=2pt]\n   \\Dmath*{\\cdb*{ex-0104.100}}\\Dmath*{\\cdb*{ex-0104.101}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.200}}\\Dmath*{\\cdb*{ex-0104.201}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.300}}\\Dmath*{\\cdb*{ex-0104.301}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.400}}\\Dmath*{\\cdb*{ex-0104.401}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.500}}\\Dmath*{\\cdb*{ex-0104.501}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.600}}\\Dmath*{\\cdb*{ex-0104.601}\\V{10pt}}\n   \\Dmath*{\\cdb*{ex-0104.700}}\\Dmath*{\\cdb*{ex-0104.701}}\n\\end{dgroup*}\n\n\\end{document}\n", "meta": {"hexsha": "0a89f4f9f1412a33d907fa662e13fc351eec403b", "size": 2854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/exercises/ex-0104.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-0104.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-0104.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": 26.9245283019, "max_line_length": 94, "alphanum_fraction": 0.4236159776, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.6029304587458177}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{alltt}\n\\usepackage[dvipsnames]{xcolor}\n\\usepackage{tkz-graph}\n\n\\title{Probability: Final Exam}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\\section{Problem 1}\n\t\\subsection{Part I}\n\tAlice and Bob each choose a number independently and uniformly random from the interval $[0,2]$. Consider the following events:\\\\\n\t\\textbf{A}. the absolute difference between the two numbers is greater than 1/4.\\\\\n\t\\textbf{B}. Alice's number is greater than 1/4.\\\\\n\tFind $\\mathbf{P}(A\\cap B)$.\\\\\n\t\\\\\n\tThis is the fraction of the area of a $2\\times 2$ square that satisfies both conditions if the $x$ and $y$ axes are Alice's and Bob's numbers, respectively. The inclusive area is made up of two isosceles right triangels with side lengths of 1.75 and 1.5, respectively. The combined area is\n\t\\[\n\t\\frac{1}{2}(1.75)^2 + \\frac{1}{2}(1.5)^2 = 2.65625\n\t\\]\n\tThus, $\\mathbf{P}(A\\cap B) = \\frac{2.65625}{4} = \\frac{85}{128}$.\n\t\\\\\n\t\\subsection{Part II}\n\tThere are $m$ red balls and $n$ white balls in an urn. We draw two balls at random without replacement. What is the probability that the balls are a different color?\\\\\n\t\\\\\n\tThis is the sum of two probabilities: drawing a red then white, and drawing a white then red.\n\t\\[\n\t\\frac{m}{m+n}\\frac{n}{m+n-1} + \\frac{n}{m+n}\\frac{n}{m+n-1} = \\frac{2mn}{(m+n)(m+n-1)}\n\t\\]\n\t\\\\\n\t\\subsection{Part III}\n\t20 black pebbles are arranged in 4 rows of 5 pebbles each. We choose 4 at random and color them red. What is the probability that each red pebble lies in a different row?\\\\\n\t\\\\\n\tThere are $5^4$ possible orderings of 4 pebbles in different rows (5 places for the first, 5 places for the second, etc.). There are $\\binom{20}{4}$ total permutations of the pebble sequences. Thus, the probability is\n\t\\[\n\t\\frac{5^4}{\\binom{20}{4}} = \\frac{5^4 4!16!}{20!}\n\t\\]\n\t\\\\\n\t\\subsection{Part IV}\n\tWe have two light bulbs, A and B. Bulb A has an exponentially distributed lifetime with mean of 4 days. Bulb B has an exponentially distributed lifetime with mean 6 days. We select one bulb at random (each is equally likely). Given that the bulb has been working for 12 hours, what is the probability that we chose bulb A?\\\\\n\t\\\\\n\tBy Bayes theorem, we have\n\t\\[\n\tP(\\text{selecting A}|l.t.>\\text{0.5 days})=\n\t\\frac{P(\\text{selecting A})P(l.t.>\\text{0.5 days}|\\text{selecting A})}{P(l.t.>\\text{0.5 days})}\n\t\\]\n\tFor an exponential random variable, $P(l.t.> t)=\n\te^{\\frac{1}{\\mu}t}$.\n\tThus, we have\n\t\\[\n\t\\frac{(0.5)e^{\\frac{1}{4}\\frac{1}{2}}}{0.5(e^{\\frac{1}{4}\\frac{1}{2}}+e^{\\frac{1}{6}\\frac{1}{2}})} = \\frac{1}{1+e^{1/12 - 1/8}} = \\frac{1}{1+e^{1/24}}\n\t\\]\n\t\\\\\n\t\\subsection{Part V}\n\tA test for a rare disease is correct 95\\% of the time. A false positive has a probability 0.95 and a false negative has a probability 0.95. A random person drawn fro the population has a probability of 0.001 of having the disease. Given that a person just tested positive, what is the probability of having the disease?\\\\\n\t\\\\\n\tBy Bayes theorem,\\\\\n\t$P(\\text{sick}|\\text{positive})=\n\t\\frac{P(\\text{sick})P(\\text{positive}|\\text{sick})}{P(\\text{positive})} = \\frac{(0.001)(0.95)}{(0.001)(0.95)+(0.999)(0.05)}=0.187$\n\t\\\\\n\t\\subsection{Part VI}\n\tLet $X$ be a random variable with\n\t\\[\n\tf_X(x) = \n\t\\begin{cases}\n\t\t 2e^{-2x} & x\\geq 0\\\\\n\t\t 0 & \\text{otherwise}\n\t\\end{cases}\n\t\\]\n\tLet $Y=2X-4$. Find $f_Y(0)$.\\\\\n\t\\\\\n\t\\[\n\tF_Y(y) = P(Y\\leq y) = P\\left(X \\leq \\frac{y}{2}+2\\right) = F_X\\left(\\frac{y}{2}+2\\right)\n\t\\]\n\t\\[\n\t\\frac{d}{dy}F_Y(y) = \\frac{d}{dy}F_X\\left(\\frac{y}{2}+2\\right)\n\t\\]\n\t\\[\n\tf_Y(y) = \\frac{1}{2}f_X\\left(\\frac{y}{2}+2\\right)\n\t\\]\n\t\\[\n\tf_Y(0) = \\frac{1}{2}f_X(2)= e^{-4}\n\t\\]\n\t\\\\\n\t\\subsection{Part VII}\n\t$X$ and $Y$ are independent random variables. $X$ is exponentially distributed with mean $1/3$. $Y$ is Bernoulli with $p=1/2$. Let $Z=X+Y$. What is the transform of $Z$, $M_Z(s)$ evaluated at $s=1$?\\\\\n\t\\\\\n\t\\[\n\tM_X(s) = \\frac{3}{3-s} \\qquad, \\qquad M_Y(s) = \\frac{1}{2}+\\frac{1}{2}e^s\n\t\\]\n\tSince the PDF of $Z$ is the convolution of $X$ and $Y$, in the $s$ domain it is the multiplication of $M_X(s)$ and $M_Y(s)$.\n\t\\[\n\tM_Z(s) = M_X(s)~M_Y(s)\n\t\\]\n\t\\[\n\tM_Z(1) = \\frac{3}{2}\\left(\\frac{1}{2}+\\frac{1}{2}e\\right)=\n\t\\frac{3}{4}(1+e)\n\t\\]\n\t\\\\\n\t\\subsection{Part VIII}\n\tA number $p$ is chosen at random from a uniform distribution $[0,1]$. A sequence of $k$ Bernoulli trials is then performed each with a success probability of $p$. What is the variance of the number of successes in the $k$ trials?\\\\\n\t\\\\\n\tBy the law of total variance,\n\t\\[\n\t\\text{Var}(X) = \\textbf{E}[\\text{Var}(X|P)] + \\text{Var}(\\mathbf{E}[X|P])\n\t\\]\n\t\\[\n\t= \\textbf{E}[kP(1-P)] + \\text{Var}(kP)\n\t\\]\n\t\\[\n\t=k\\textbf{E}[P] - k\\textbf{E}[P^2] + k^2\\text{Var}(P)\n\t\\]\n\t\\[\n\t=k\\textbf{E}[P] -k\\textbf{E}[P^2] + k\\textbf{E}[P]^2 - k\\textbf{E}[P]^2 + k^2\\text{Var}(P)\n\t\\]\n\t\\[\n\t=k\\textbf{E}[P] - k\\text{Var}(P) -k\\textbf{E}[P]^2 + k^2\\text{Var}(P)\n\t\\]\n\t\\[\n\t=\\frac{k}{2} - \\frac{k}{12} - \\frac{k}{4} + \\frac{k^2}{12} = \\frac{k}{6}+\\frac{k^2}{12}\n\t\\]\n\t\\[\n\t=\\frac{k(2+k)}{12}\n\t\\]\n\t\\\\\n\t\\subsection{Part IX}\n\tA police radar always over-estimates the speed of a car by an amount that is uniformly distributed between 0 and 5 mph. Assume that car speeds are uniformly distributed between 60 and 75 mph and are independent of the radar over-estimate. If the radar measures a speed of 76 mph, what is the least-squares estimate of the actual car speed?\\\\\n\t\\\\\n\tThe least squares estimate of $Y$ is \\textbf{E}[$Y|X$]. Given the radar speed of 76 mph. The possible values of the actual speed are uniformly distributed between 71 and 75 (since 75 is the maximum speed). Thus, the least squares estimate is $\\frac{75+71}{2} = 73$ mph.\n\t\\\\\n\t\\subsection{Part X}\n\tA mosquito lands on your back and bites according to a Bernoulli process. The expected time of the first bite is 10 seconds. What is the probability that the second bite occurs at exactly 10 seconds?\\\\\n\t\\\\\n\tThe time to first arrival is a geometric distribution, with the average time equal to $\\frac{1}{p}$. Thus, $p=0.1$.\n\t\n\tThe $k$th arrival time of a Bernoulli process is modeled by the Pascal distribution, where $P_k(t)\n\t= \\binom{t-1}{k-1}p^k (1-p)^{t-k}$.\n\t\\[\n\tP_2(10) = \\binom{10-1}{2-1}\\left(\\frac{1}{10}\\right)^2\\left(\\frac{9}{10}\\right)^{10-2} = \\frac{9!}{8!}\\frac{9^8}{10^2 10^8} = \\frac{9^9}{10^{10}} \\approx 0.0387\n\t\\]\n\t\\subsection{Part XI}\n\tIn order to estimate $p$, the fraction of people who will vote for candidate A in the next election, you conduct a poll of $n$ people drawn randomly and independently from the population Your estimator $M_n$ is obtained by dividing $S_n$, the number of people voting for candidate A in the sample, by $n$. Find the smallest value of $n$ needed to guarantee that\n\t\\[\n\t\\mathbf{P}(|M_n - p|\\geq 0.01) \\leq 0.01\n\t\\]\n\tApplying the WLLN to the Chebyshev inequality, we have\n\t\\[\n\t\\mathbf{P}(|X-\\mu|\\geq \\epsilon) \\leq \\frac{\\sigma^2}{n\\epsilon^2}\n\t\\]\n\tSince each sampled person's vote is a Bernoulli distribution, we have $sigma^2 = p(1-p)$ and $p(1-p)\\leq \\frac{1}{4}$ for all $p\\in [0,1]$. Thus,\n\t\\[\n\t\\mathbf{P}(|M_n-p|\\geq 0.01) \\leq \\frac{\\sigma^2}{n(0.01)^2}\\leq \\frac{1}{n(4)(0.01)^2} \\leq 0.01\n\t\\]\n\t\\[\n\tn \\geq \\frac{1}{4(0.01)^3} = 250,000\n\t\\]\n\t\\subsection{Part XII}\n\tIt rains each day with a probability 0.1, independent of all other days. Use the CLT to approximate the probability that out of 365 days in the year, it will rain on at least 100 days. How good is this approximation?\\\\\n\t\\\\\n\tThe precipitation state on a given day $X_i$ is Bernoulli with $p=0.1$. Thus the average value for a day $\\mu=0.1$, and the variance $\\sigma^2=p(p-1)=0.09$.\n\t\\\\\n\tLet $S_n = X_1 + X_2 + \\dots +X_n$.\n\t\\[\n\t\\mathbf{P}(S_{n=365}\\leq 100) = \\Phi\\left(\n\t\\frac{100 - 365\\mu}{\\sigma\\sqrt{365}}\n\t\\right)=\\Phi\\left(\\frac{635}{3\\sqrt{365}}\n\t\\right)\n\t\\]\n\tSo, $\\mathbf{P}(S_n\\geq 100) = 1 - \\Phi\\left(\\frac{635}{3\\sqrt{(365)}}\\right) \\approx 0$\\\\\n\t\\\\\n\tThe true distribution is Binomial with $p(k) = \\binom{365}{k}p^k(1-p)^{365-k}$\\\\\\\\\n\t\\[\n\t\\mathbf{P}(k\\geq 100) = 1 -\\mathbf{P}(k \\leq 99) = 1-\\sum_{i=0}^{99}\\binom{365}{i}p^i(1-p)^{365-i} = 1.11\\times 10^{-16} \\approx 0\n\t\\]\n\tThe difference between this answer and the approximation with the CLT is within computational rounding difference.\n\t\\pagebreak\n\t\\section{Problem 2}\n\tDeer come to a river according to a Poisson process with arrival rate $\\lambda_d=8$ per hour; elephants come to the river by an independent Poisson process with arrival rate $\\lambda_e=2$ per hour. Assume that elephants and deer are the only animals that go to the river.\n\t\\\\\n\t\\subsection{Part A}\n\tLet $N$ be the number of animals you see during the first 3 hours. Find $\\mathbf{E}[N]$ and Var$(N)$.\\\\\n\t\\\\\n\tLet $D$ and $E$ be the number of deer and elephants seen in the first 3 hours, respectively.\n\t\\[\n\tp_D(k) = \\frac{(3\\lambda_d)^k e^{-3\\lambda_d}}{k!}\n\t\\rightarrow M_D(s) = e^{e\\lambda_d(e^s-1)}\n\t\\]\n\t\\[\n\tp_E(k) = \\frac{(3\\lambda_e)^k e^{-3\\lambda_e}}{k!}\n\t\\rightarrow M_E(s) = e^{e\\lambda_e(e^s-1)}\n\t\\]\n\t\\[\n\tN = D + E \\rightarrow M_N(s) = M_D(s)~M_E(s) = \n\te^{3(\\lambda_d+\\lambda_e)(e^s-1)}\n\t\\]\n\t$N$ is therefore a Poisson process with intensity $3(\\lambda_d+\\lambda_e) = 30$. So, \n\t\\[\n\t\\mathbf{E}[N] = 30 \\qquad , \\qquad \\text{Var}(N)=30\n\t\\]\n\t\\subsection{Part B}\n\tWhat is the probability of seeing your 3rd elephant before your 9th deer?\\\\\n\t\\\\\n\tThe $k$th arrival time in a Poisson process follows an Erlang distribution,\n\t\\[\n\tf_{Y_k}(y) = \\frac{\\lambda^k y^{k-1}e^{-\\lambda y}}{(k-1)!}\n\t\\]\n\tWe can determine this probability through Monte Carlo simulations of the difference in time between the third elephant's arrival and the ninth deer's arrival. The fraction of (a large number of) simulations for which this difference is negative will approach the probability that the third elephant comes first.\n\t\n\t\\begin{alltt}\n\t\\textcolor{ForestGreen}{In [1]:} \\textcolor{OliveGreen}{import} \\textcolor{blue}{numpy} \\textcolor{OliveGreen}{as} \\textcolor{blue}{np}\n\t\\textcolor{ForestGreen}{In [2]:} \\textcolor{OliveGreen}{from} \\textcolor{blue}{scipy.stats} \\textcolor{OliveGreen}{import} erlang\n\t\\textcolor{ForestGreen}{In [3]:} lambda_e = 2.\n\t\\textcolor{ForestGreen}{In [4]:} lambda_d = 8.\n\t\\textcolor{ForestGreen}{In [5]:} third_ele_times = erlang.rvs(3,scale=1/lambda_e,size=5000000)\n\t\\textcolor{ForestGreen}{In [6]:} ninth_deer_times = erlang.rvs(9,scale=1/lambda_d,size=5000000)\n\t\\textcolor{ForestGreen}{In [7]:} diff = third_ele_times - ninth_deer_times\n\t\\textcolor{ForestGreen}{In [8]:} len(np.where(diff<0)[0])/5000000.\n\t\\textcolor{red}{Out[8]:} 0.382903\n\t\\end{alltt}\n\n\tTherefore, we about a 38\\% probability of seeing our third elephant before our ninth deer.\n\t\n\t\\subsection{Part C}\n\tAt the end of 3 hours, you have seen 24 deer but no elephants. What is the probability that you will see an elephant in the next hour?\\\\\n\t\\\\\n\tSince the deer and elephant arrival processes are independent, we can ignore the 24 deer information. Further, since Poisson process is memoryless, the fact that no elephants have been seen in the first three nours has no bearing on the probability of occurrence in the future.\n\t\n\tThe number of elephants seen in a one hour time block is a Poisson random variable with PMF $\\frac{\\lambda_e^k e^{-\\lambda_e}}{k!}$. The probability of seeing \\textit{no} elephants in the next hour is $e^{-\\lambda_e} = e^{-2}$. Thus, the probability of seeing at least one elephant within the hour is $1-e^{-2}$.\n\t\\\\\n\t\\subsection{Part D}\n\tIt has been 6 hours since you have started watching. You have seen 53 deer and no elephants. How many more deer do you expect to see before you see your first elephant?\\\\\n\t\\\\\n\tAgain, since Poisson processes are memoryless, the 6 hours and 53 deer are irrelevant information. At the present moment, the expected arrival time of the first elephant $\\mathbf{E}[T] = \\frac{1}{\\lambda_e}=0.5$ hours. We set this time as $tau$. The expected number of deer seen in $\\tau$ units of time is $\\lambda_d \\tau = 8(0.5)=4$\n\t\\\\\n\t\\subsection{Part E}\n\tYou plan on staying at the river until you have both a picture of a deer and an elephant. How long do you expect to stay?\\\\\n\t\\\\\n\tThe arrival rate for a general animal is the sum of the arrival rates for elephants and deer, $\\lambda_e + \\lambda_d = 10$. Thus, the expected wait time for the first animal of any kind is $\\frac{1}{10}$ hour.\n\t\n\tThere are then two possibilities, a deer was the first to show up (with probability $\\frac{\\lambda_d}{\\lambda_d+\\lambda_e}$), and we wait for an elephant (average time of $\\frac{1}{\\lambda_e}$); or the first animal was an elephant (probability $\\frac{\\lambda_e}{\\lambda_d+\\lambda_e}$), and we wait for a deer (average time of $\\frac{1}{\\lambda_d}$)\n\t\n\tIn total, our expected wait time is\n\t\\[\n\t\\frac{1}{\\lambda_d+\\lambda_e} + \\frac{\\lambda_d}{\\lambda_d+\\lambda_e}\\frac{1}{\\lambda_e}\n\t+\\frac{\\lambda_e}{\\lambda_d + \\lambda_e}\\frac{1}{\\lambda_d} = \\frac{1}{10}+\\frac{4}{(5)(2)}+\\frac{1}{(5)(8)}=\\frac{21}{40}\n\t\\]\n\t\\\\\n\t\\subsection{Part F}\n\tEach time you take a picture, there is a probability of 0.1 that the picture turns our poor. You take a picture each time an animal arrives to the river. let $X$ be the time (in hours) until you get your third picture of an elephant. Find the PDF of $X$.\\\\\n\t\\\\\n\tThis is a Bernoulli process ($p=0.9$) operating on the Poisson process ($\\lambda = \\lambda_e=2$). This results in a Poisson process with intensity $p\\lambda_e$. Therefore, for the arrival time of the third successful picture, we have\n\t\\[\n\tf_X(x) = \n\t\\begin{cases}\n\t\t\\frac{1.8^3 x^2 e^{-1.8x}}{2} & x \\geq 0\\\\\n\t\t0 & \\text{otherwise}\n\t\\end{cases}\n\t\\]\n\t\\pagebreak\n\t\\section{Problem 3}\n\tIf a football team has won the past two games, it has a 0.7 probability of winning the next game. If it lost the last game, but won the game before, it has a 0.4 probability of winning. If it won the last game but lost the one before, it has a 0.6 probability of winning. If it lost the last two games, it has a 0.3 probability of winning the next game. No game can end in a draw. Consider the starting time when the team has won the past two games.\n\t\\subsection{Part A}\n\tGraph the minimum state Markov chain.\n\t\\begin{table}[h!]\n\t\t\\centering\n\t\t\\caption{State Definitions}\n\t\t\\begin{tabular}{c|c}\n\t\t\tState & Description\\\\\n\t\t\t\\hline\n\t\t\t0 & lost both previous games\\\\\n\t\t\t1 & lost last game, won the one before that\\\\\n\t\t\t2 & won last game, lost he one before that\\\\\n\t\t\t3 & won both previous games\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\\begin{tikzpicture}\n\t\t%\\node[draw,circle] at (1,1){$0$};\n\t\t\\SetGraphUnit{3}\n\t\t\\tikzset{LabelStyle/.style = {rectangle,rounded corners, draw, fill=white!50},\n\t\tVertexStyle/.append style={inner sep=8pt}}\n\t\t\\Vertex{0}\n\t\t\\EA(0){1}\n\t\t\\SO(0){3}\n\t\t\\SO(1){2}\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend right}}\n\t\t\\Edge[label=0.6](1)(0)\n\t\t\\Edge[label=0.3](0)(2)\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend left}}\n\t\t\\Edge[label=0.3](3)(1)\n\t\t\\Edge[label=0.6](2)(3)\n\t\t\\tikzset{EdgeStyle/.append style = {<->,bend right}}\n\t\t\\Edge[label=0.4](2)(1)\n\t\t\\Loop[dist=2cm, dir=NO, label=0.7](0.west)\n\t\t\\Loop[dist=2cm, dir=NO, label=0.7](3.west)\n\t\\end{tikzpicture}\n\t\\caption{Markov chain model}\n\t\\end{figure}\n\t\n\t\\subsection{Part B}\n\tFind the probability that the first future loss will be followed by another loss.\\\\\n\t\\\\\n\tSince we are starting in state 3, the first future loss will put us in state 1. The probability that another loss will follow is the probability of moving from state 1 to state 0, which is 0.6.\n\t\\\\\n\t\\subsection{Part C}\n\tLet $X$ be the number of games played up to, but not including, the first loss. Find the PMF of $X$.\\\\\n\t\\\\\n\tThis is the same as the number of games in the initial winning streak. Since we start in state 3, the minimum value of $X$ is 2, with a probability of 0.3 since losing the next game will result in 2 wins. For each game won beyond, we multiply by a probability of 0.7. Thus, the PMF is\n\t\\[\n\tp_X(x) =\n\t\\begin{cases}\n\t\t(0.3)(0.7)^{x-2} & x \\geq 2\\\\\n\t\t0 & \\text{otherwise}\n\t\\end{cases}\n\t\\]\n\t\\subsection{Part D}\n\tEither evaluate the steady state probabilities, or explain why they do not exist.\\\\\n\t\\\\\n\tThe calculation of $[\\pi_0~\\pi_1 ~\\pi_2~\\pi_3]$ evaluates to finding the eigenvector of $P^T$ corresponding to the eigenvalue of 1. $P$ is the probability matrix of the Markov Chain, where $p_{ij}$ is the probability of moving from state $i$ to $j$. The eigenvector must then be normalized by the sum of the elements.\n\t\n\tThis results in $[\\pi_0~\\pi_1 ~\\pi_2~\\pi_3] = [\\frac{1}{3}~\\frac{1}{6}~\\frac{1}{6}~\\frac{1}{3}]$\n\t\\\\\n\t\\subsection{Part E}\n\tFind a good approximation that the team will win it's $1000^{th}$ game, given that the outcomes of games 1000 and 1001 are the same.\\\\\n\t\\\\\n\tAssuming that 1000 games is enough to reach the steady state probabilities, the probability of both game 1000 and game 1001 being won is the same as the probability of being in state 3. The probability of both games being the same is the sum of the probabilities of being in state 3 or state 0. Thus, the probability is\n\t\\[\n\t\\frac{\\pi_3}{\\pi_0 + \\pi_3} = \\frac{1/3}{1/3~+~1/3} = \\frac{1}{2}\n\t\\]\n\t\\subsection{Part F}\n\tLet $T$ be the number of games up to and including the team's 2nd consecutive loss. What is $\\mathbf{E}[T]$?\\\\\n\t\\\\\n\tIn this situation, we must modify the Markov Chain to make state 0 an absorbing state, as shown below.\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t%\\node[draw,circle] at (1,1){$0$};\n\t\t\\SetGraphUnit{3}\n\t\t\\tikzset{LabelStyle/.style = {rectangle,rounded corners, draw, fill=white!50},\n\t\t\tVertexStyle/.append style={inner sep=8pt}}\n\t\t\\Vertex{0}\n\t\t\\EA(0){1}\n\t\t\\SO(0){3}\n\t\t\\SO(1){2}\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend right}}\n\t\t\\Edge[label=0.6](1)(0)\n\t\t%\\Edge[label=0.3](0)(2)\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend left}}\n\t\t\\Edge[label=0.3](3)(1)\n\t\t\\Edge[label=0.6](2)(3)\n\t\t\\tikzset{EdgeStyle/.append style = {<->,bend right}}\n\t\t\\Edge[label=0.4](2)(1)\n\t\t\\Loop[dist=2cm, dir=NO, label=1.0](0.west)\n\t\t\\Loop[dist=2cm, dir=NO, label=0.7](3.west)\n\t\t\\end{tikzpicture}\n\t\t\\caption{Markov chain model with state 0 as an absorbing state.}\n\t\\end{figure}\n\n\tStates 1-3 are transient states since they each reach state 0, but are not reachable by state 0. State 0 itself is a recurrent state. Thus the expected time to reach absorption starting at state 0, $\\mu_0$ is 0.\n\t\n\tFor the $i$th state of $m$ total states, the expected time to reach absorption is $\\mu_i = 1+ \\sum_{j=0}^{m}p_{ij}\\mu_j$. Therefore we get the following system of equations:\n\t\\[\n\t\t\\begin{cases}\n\t\t\\mu_0 = 0\\\\\n\t\t\\mu_1 = 1 + 0.4\\mu_2\\\\\n\t\t\\mu_2 = 1 + 0.4\\mu_1 + 0.6\\mu_3\\\\\n\t\t\\mu_3 = 1 + 0.3\\mu_1 + 0.7\\mu_3\n\t\t\\end{cases}\n\t\\]\n\twhich can be represented in matrix form as\n\t\\[\n\t\\begin{bmatrix}\n\t1 & -0.4 & 0\\\\\n\t-0.4 & 1 & -0.6\\\\\n\t-0.3 & 0 & 0.3\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\\mu_1\\\\\\mu_2\\\\\\mu_3\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t1\\\\1\\\\1\n\t\\end{bmatrix}\n\t\\]\n\tSince we start in state 3, $\\mathbf{E}[T] = \\mu_3$, which evaluates to 7 games.\n\t\\\\\n\t\\subsection{Part G}\n\tThe team is removed from competition after 3 losses in a row. Let $N$ be the number of games that the team will play in competition. What is $\\mathbf{E}[N]$?\\\\\n\t\\\\\n\tWe must add another state to the original Markov chain that signifies losing after being in state 0, shown below.\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t%\\node[draw,circle] at (1,1){$0$};\n\t\t\\SetGraphUnit{3}\n\t\t\\tikzset{LabelStyle/.style = {rectangle,rounded corners, draw, fill=white!50},\n\t\t\tVertexStyle/.append style={inner sep=8pt}}\n\t\t\\Vertex{0}\n\t\t\\EA(0){1}\n\t\t\\SO(0){3}\n\t\t\\SO(1){2}\n\t\t\\WE(0){4}\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend right}}\n\t\t\\Edge[label=0.6](1)(0)\n\t\t\\Edge[label=0.3](0)(2)\n\t\t\\tikzset{EdgeStyle/.append style = {->, bend left}}\n\t\t\\Edge[label=0.3](3)(1)\n\t\t\\Edge[label=0.6](2)(3)\n\t\t\\Edge[label=0.7](0)(4)\n\t\t\\tikzset{EdgeStyle/.append style = {<->,bend right}}\n\t\t\\Edge[label=0.4](2)(1)\n\t\t\\Loop[dist=2cm, dir=NO, label=1.0](4.west)\n\t\t\\Loop[dist=2cm, dir=NO, label=0.7](3.west)\n\t\t\\end{tikzpicture}\n\t\\caption{Markov chain model with added absorbing state 4 for three losses in a row.}\n\t\\end{figure}\n\t\n\tThis new Markov chain results in the following systems of equations for average absorption times.\n\t\\[\n\t\\begin{cases}\n\t\\mu_0 = 1 + 0.3\\mu_2\\\\\n\t\\mu_1 = 1 + 0.6\\mu_0 + 0.4\\mu_2\\\\\n\t\\mu_2 = 1 + 0.4\\mu_1 + 0.6\\mu_3\\\\\n\t\\mu_3 = 1 + 0.3\\mu_1 + 0.7\\mu_3\\\\\n\t\\mu_4 = 0\n\t\\end{cases}\n\t\\]\n\twhich is expressed as matrices by\n\t\\[\n\t\\begin{bmatrix}\n\t1    & 0    & -0.3 & 0\\\\\n\t-0.6 & 1    & -0.4 & 0\\\\\n\t0    & -0.4 & 1    & -0.6\\\\\n\t0    & -0.3 & 0    & 0.3\\\\\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\\mu_0\\\\\\mu_1\\\\\\mu_2\\\\\\mu_3\n\t\\end{bmatrix}\n\t=\n\t\\begin{bmatrix}\n\t1\\\\1\\\\1\\\\1\n\t\\end{bmatrix}\n\t\\]\n\twhich evaluates to $\\mathbf{E}[N] = \\mu_3 = 11.28$ games.\n\\end{document}", "meta": {"hexsha": "1f6b2b5e918d7c2fdcd62e8c03933b2b2967093f", "size": 20634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Exams/Final/final.tex", "max_stars_repo_name": "markditsworth/psa", "max_stars_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Exams/Final/final.tex", "max_issues_repo_name": "markditsworth/psa", "max_issues_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exams/Final/final.tex", "max_forks_repo_name": "markditsworth/psa", "max_forks_repo_head_hexsha": "af38e92111464c0d4ac7e833d9bb235d22c0a4ca", "max_forks_repo_licenses": ["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.8533333333, "max_line_length": 450, "alphanum_fraction": 0.6716099641, "num_tokens": 7531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6029304478983049}}
{"text": "\\chapter{Finite fields}\nIn this short chapter, we classify all fields with finitely many elements\nand compute the Galois groups.\nNothing in here is very hard, and so most of the proofs are just sketches;\nif you like, you should check the details yourself.\n\nThe whole point of this chapter is to prove:\n\\begin{itemize}\n\t\\ii A finite field $F$ must have order $p^n$, with $p$ prime and $n$ an integer.\n\t\\ii In this case, $F$ has characteristic $p$.\n\t\\ii All such fields are isomorphic,\n\tso it's customary to use the notation $\\FF_{p^n}$\n\tfor ``the'' finite field of order $p^n$ if we only care up to isomorphism.\n\t\\ii The extension $F/\\FF_p$ is Galois, and $\\Gal(F/\\FF_p)$ is a cyclic group of order $n$.\n\tThe generator is the automorphism \\[ \\sigma : F \\to F \\quad\\text{by}\\quad x \\mapsto x^p. \\]\n\\end{itemize}\nIf you're in a hurry you can just remember these results and skip to the next chapter.\n\n\\section{Example of a finite field}\nBefore diving in, we give some examples.\n\nRecall that the \\emph{characteristic} of a field $F$\nis the smallest positive integer $p$ such that\n\\[ \\underbrace{1_F + \\dots + 1_F}_{\\text{$p$ times}} = 0 \\]\nor $0$ if no such integer $p$ exists.\n\n\\begin{example}[Base field]\n\tLet $\\FF_p$ denote the field of integers modulo $p$.\n\tThis is a field with $p$ elements, with characteristic $p$.\n\\end{example}\n\n\\begin{example}[The finite field of nine elements]\n\tLet\n\t\\[ F \\cong \\FF_3[X]/(X^2+1) \\cong \\ZZ[i] / (3). \\]\n\tWe can think of its elements as \\[ \\left\\{ a + bi \\mid 0 \\le a,b \\le 2 \\right\\}. \\]\n\tSince $(3)$ is prime in $\\ZZ[i]$, the ring of integers of $\\QQ(i)$,\n\twe see $F$ is a field with $3^2 = 9$ elements inside it.\n\tNote that, although this field has $9$ elements, every element $x$ has the property that\n\t\\[ 3x = \\underbrace{x + \\dots + x}_{\\text{$3$ times}} = 0. \\]\n\tIn particular, $F$ has characteristic $3$.\n\\end{example}\n\n\\section{Finite fields have prime power order}\n\\begin{lemma}\n\tIf the characteristic of a field $F$ isn't zero,\n\tit must be a prime number.\n\\end{lemma}\n\\begin{proof}\n\tAssume not, so $n = ab$ for $a,b < n$.\n\tThen let\n\t\\[ A = \\underbrace{1_F + \\dots + 1_F}_{\\text{$a$ times}} \\neq 0 \\]\n\tand\n\t\\[ B = \\underbrace{1_F + \\dots + 1_F}_{\\text{$b$ times}} \\neq 0. \\]\n\tThen $AB = 0$, contradicting the fact that $F$ is a field.\n\\end{proof}\n\nWe like fields of characteristic zero, but unfortunately for finite fields\nwe are doomed to have nonzero characteristic.\n\n\\begin{lemma}\n\t[Finite fields have prime power orders]\n\tLet $F$ be a finite field.\n\tThen\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Its characteristic is nonzero, and hence some prime $p$.\n\t\t\\ii The field $F$ is a finite extension of $\\FF_p$,\n\t\tand in particular it is an $\\FF_p$-vector space.\n\t\t\\ii We have $\\left\\lvert F \\right\\rvert = p^n$ for some prime $p$, integer $n$.\n\t\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\tVery briefly, since this is easy:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Apply Lagrange's theorem (or pigeonhole principle!)\n\t\tto $(F, +)$ to get the characteristic isn't zero.\n\t\t\\ii The additive subgroup of $(F,+)$ generated\n\t\tby $1_F$ is an isomorphic copy of $\\FF_p$.\n\t\t\\ii Since it's a field extension,\n\t\t$F$ is a finite-dimensional vector space over $\\FF_p$,\n\t\twith some basis $e_1, \\dots, e_n$.\n\t\tIt follows that there are $p^n$ elements of $F$. \\qedhere\n\t\\end{enumerate}\n\\end{proof}\n\\begin{remark}\n\tAn amusing alternate proof of (c) by contradiction:\n\tif a prime $q \\neq p$ divides $\\left\\lvert F \\right\\rvert$, then\n\tby Cauchy's theorem (\\Cref{thm:cauchy_group}) on $(F, +)$\n\tthere's a (nonzero) element $x$ of order $q$.\n\tEvidently \\[ x \\cdot ( \\underbrace{1_F + \\dots + 1_F}_{\\text{$q$ times}} ) = 0 \\] \n\tthen, but $x \\neq 0$, and hence the characteristic of $F$ also divides $q$,\n\twhich is impossible.\n\\end{remark}\n\nAn important point in the above proof is that\n\\begin{lemma}[Finite fields are field extensions of $\\FF_p$]\n\tIf $\\left\\lvert F \\right\\rvert = p^n$ is a finite field,\n\tthen there is an isomorphic copy of $\\FF_p$ sitting inside $F$.\n\tThus $F$ is a field extension of $\\FF_p$.\n\\end{lemma}\n\nWe want to refer a lot to this copy of $\\FF_p$, so in what follows:\n\\begin{abuse}\n\tEvery integer $n$ can be identified as an element of $F$, namely\n\t\\[ n \\defeq \\underbrace{1_F + \\dots + 1_F}_{\\text{$n$ times}}. \\]\n\tNote that (as expected) this depends only on $n \\pmod p$.\n\\end{abuse}\n\nThis notation makes it easier to think about statements like the following.\n\\begin{theorem}\n\t[Freshman's dream]\n\tFor any $a,b \\in F$ we have\n\t\\[ (a+b)^p = a^p + b^p. \\]\n\\end{theorem}\n\\begin{proof}\n\tUse the Binomial theorem, and the fact that $\\binom pi$ is divisible by $p$ for $0 < i < p$.\n\\end{proof}\n\\begin{exercise}\n\tConvince yourself that this proof works.\n\\end{exercise}\n\n\\section{All finite fields are isomorphic}\nWe next proceed to prove ``Fermat's little theorem'':\n\\begin{theorem}\n\t[Fermat's little theorem in finite fields]\n\tLet $F$ be a finite field of order $p^n$.\n\tThen every element $x \\in F$ satisfies\n\t\\[ x^{p^n} - x = 0. \\]\n\\end{theorem}\n\\begin{proof}\n\tIf $x = 0$ it's true; otherwise, use Lagrange's theorem\n\ton the abelian group $(F, \\times)$ to get $x^{p^n-1} = 1_F$.\n\\end{proof}\n\nWe can now prove the following result,\nwhich is the ``main surprise'' about finite fields:\nthat there is a unique one up to isomorphism for each size.\n\\begin{theorem}[Complete classification of finite fields]\n\tA field $F$ is a finite field with $p^n$ elements if and only if\n\tit is a splitting field of $x^{p^n}-x$ over $\\FF_p$.\n\\end{theorem}\n\\begin{proof}\n\tBy ``Fermat's little theorem'', all the elements of $F$ satisfy this polynomial.\n\tSo we just have to show that the roots of this polynomial are distinct\n\t(i.e.\\ that it is separable).\n\n\tTo do this, we use the derivative trick again: the derivative of this polynomial is\n\t\\[ p^n \\cdot x^{p^n-1} - 1  = -1 \\]\n\twhich has no roots at all, so the polynomial cannot have any double roots. \\qedhere\n\\end{proof}\n\n\\begin{definition}\n\tFor this reason, it's customary to denote \\emph{the}\n\tfield with $p^n$ elements by $\\FF_{p^n}$.\n\\end{definition}\n\nNote that the polynomial $x^{p^n}-x \\pmod p$ is far from irreducible, but\nthe computation above shows that it's separable.\n\\begin{example}[The finite field of order nine again]\n\tThe polynomial $x^9-x$ is separable modulo $3$ and has factorization\n\t\\[ x(x+1)(x+2)(x^2+1)(x^2+x+2)(x^2+2x+2) \\pmod 3. \\]\n\n\tSo if $F$ has order $9$, then we intuitively expect it to be the field\n\tgenerated by adjoining all the roots: $0$, $1$, $2$, as well as\n\t$\\pm i$, $1 \\pm i$, $2 \\pm i$.\n\tIndeed, that's the example we had at the beginning of this chapter.\n\n\t(Here $i$ denotes \\emph{an} element of $\\FF_9$ satisfying $i^2=-1$.\n\tThe notation is deliberately similar to the usual imaginary unit.)\n\\end{example}\n\n\\section{The Galois theory of finite fields}\nRetain the notation $\\FF_{p^n}$ now (instead of $F$ like before).\nBy the above theorem, it's the splitting field of a separable polynomial,\nhence we know that $\\FF_{p^n} /\\FF_p$ is a Galois extension.\nWe would like to find the Galois group.\n\nIn fact, we are very lucky: it is cyclic.\nFirst, we exhibit one such element $\\sigma_p \\in \\Gal(\\FF_{p^n} /\\FF_p)$:\n\n\\begin{theorem}[The $p$th power automorphism]\n\tThe map $\\sigma_p : \\FF_{p^n} \\to \\FF_{p^n}$ defined by\n\t\\[ \\sigma_p(x) = x^p \\]\n\tis an automorphism, and moreover fixes $\\FF_p$.\n\\end{theorem}\n\\begin{proof}\n\tIt's a homomorphism since it fixes $1$,\n\trespects multiplication,\n\tand respects addition.\n\t\\begin{ques}\n\t\tWhy does it respect addition?\n\t\\end{ques}\n\tNext, we claim that it is injective. To see this, note that\n\t\\[ x^p = y^p\n\t\t\\iff x^p - y^p = 0\n\t\t\\iff (x-y)^p = 0\n\t\t\\iff x=y.\n\t\\]\n\tHere we have again used the Freshman's Dream.\n\tSince $\\FF_{p^n}$ is finite, this injective map is automatically bijective.\n\tThe fact that it fixes $\\FF_p$ is Fermat's little theorem.\n\\end{proof}\n\nNow we're done:\n\\begin{theorem}\n\t[Galois group of the extension $\\FF_{p^n}/\\FF_p$]\n\tWe have $\\Gal(\\FF_{p^n}/\\FF_p) \\cong \\Zc n$ with generator $\\sigma_p$.\n\\end{theorem}\n\\begin{proof}\n\tSince $[\\FF_{p^n}:\\FF_p] = n$, the Galois group $G$ has order $n$.\n\tSo we just need to show $\\sigma_p \\in G$ has order $n$.\n\n\tNote that $\\sigma_p$ applied $k$ times gives $x \\mapsto x^{p^k}$.\n\tHence, $\\sigma_p$ applied $n$ times is the identity,\n\tas all elements of $\\FF_{p^n}$ satisfy $x^{p^n}=x$.\n\tBut if $k < n$, then $\\sigma_p$ applied $k$ times\n\tcannot be the identity or $x^{p^k}-x$ would have too many roots.\n\\end{proof}\n\nWe can see an example of this again with the finite field of order $9$.\n\\begin{example}\n\t[Galois group of finite field of order $9$]\n\tLet $\\FF_9$ be the finite field of order $9$,\n\tand represent it concretely by $\\FF_9 = \\ZZ[i]/(3)$.\n\tLet $\\sigma_3 : \\FF_9 \\to \\FF_9$ be $x \\mapsto x^3$.\n\tWe can witness the fate of all nine elements:\n\t\\begin{diagram}\n\t\t0 & 1 & 2 & i & 1+i & 2+i \\\\\n\t\t&&& \\dIsom^\\sigma & \\dIsom^\\sigma & \\dIsom^\\sigma \\\\\n\t\t&&& -i & 1-i & 2-i \\\\\n\t\\end{diagram}\n\t(As claimed, $0$, $1$, $2$ are the fixed points, so I haven't drawn arrows for them.)\n\tAs predicted, the Galois group has order two:\n\t\\[ \\Gal(\\FF_9/\\FF_3) = \\left\\{ \\id, \\sigma_3 \\right\\} \\cong \\Zc 2. \\]\n\\end{example}\n\nThis concludes the proof of all results stated at the beginning of this chapter.\n\n\\section\\problemhead\n\\begin{dproblem}[HMMT 2017]\n\t\\gim\n\tWhat is the period of the Fibonacci sequence modulo $127$?\n\t\\begin{hint}\n\tThe Fibonacci sequence is given by\n\t$F_n = \\frac{\\alpha^n - \\beta^n}{\\alpha - \\beta}$\n\twhere $\\alpha = \\frac{1 + \\sqrt5}{2}$ and $\\beta = \\frac{1 - \\sqrt5}{2}$\n\tare the two roots of $P(X) \\overset{\\text{def}}{=} X^2-X-1$.\n\tShow the polynomial $P(X)$ is irreducible modulo $127$;\n\tthen work in the splitting field of $P$, namely $\\FF_{p^2}$.\n\n\tShow that $\\FF_p=-1$, $\\FF_{p+1}=0$, $\\FF_{2p+1}=1$, $\\FF_{2p+2}=0$.\n\t(Look at the action of $\\Gal(\\FF_{p^2}/\\FF_p)$\n\ton the roots of $P$.)\n\t\\end{hint}\n\t\\begin{sol}\n\tRecall that the Fibonacci sequence is given by\n\t\\[ F_n = \\frac{\\alpha^n - \\beta^n}{\\alpha - \\beta} \\]\n\twhere $\\alpha = \\frac{1 + \\sqrt5}{2}$ and $\\beta = \\frac{1 - \\sqrt5}{2}$\n\tare the two roots of $P(X) \\defeq X^2-X-1$.\n\n\tLet $p = 127$ and work modulo $p$.\n\tAs \\[ \\left( \\frac5p \\right) = \\left( \\frac p5 \\right) = \\left( \\frac 25\n\t\t\\right) = -1 \\]\n\twe see $5$ is not a quadratic residue mod $127$.\n\tThus the polynomial $P(X)$,\n\tviewed as a polynomial in $\\FF_p[X]$, is irreducible\n\t(intuitively, $\\alpha$ and $\\beta$ are not elements of $\\FF_p$).\n\tAccordingly we will work in the finite field $\\FF_{p^2}$,\n\twhich is the $\\FF_p$-splitting field of $P(X)$.\n\tIn other words we interpret $\\alpha$ and $\\beta$ as elements\n\tof $\\FF_{p^2}$ which do not lie in $\\FF_p$.\n\n\tLet $\\sigma \\colon \\FF_{p^2} \\to \\FF_{p^2}$ by $t \\mapsto t^p$\n\tbe the nontrivial element of\n\t$\\opname{Gal}\\left( \\FF_{p^2} / \\FF_p \\right)$;\n\tin other words, $\\sigma$ is the non-identity automorphism of $\\FF_{p^2}$.\n\tSince the fixed points of $\\sigma$ are the elements of $\\FF_p$,\n\tthis means $\\sigma$ does not fix either root of $P$; thus we must have\n\t\\begin{align*}\n\t\t\\alpha^p = \\sigma(\\alpha) &= \\beta \\\\\n\t\t\\beta^p = \\sigma(\\beta) &= \\alpha.\n\t\\end{align*}\n\tNow, compute\n\t\\begin{align*}\n\t\tF_{p} &= \\frac{\\alpha^{p} - \\beta^{p}}{\\alpha-\\beta} =\n\t\t\\frac{\\beta-\\alpha}{\\alpha-\\beta} = -1. \\\\\n\t\tF_{p+1} &= \\frac{\\alpha^{p+1} - \\beta^{p+1}}{\\alpha-\\beta} =\n\t\t\\frac{\\alpha\\beta-\\beta\\alpha}{\\alpha-\\beta} = 0. \\\\\n\t\tF_{2p+1} &= \\frac{\\alpha^{2p+1} - \\beta^{2p+1}}{\\alpha-\\beta}\n\t\t\t= \\frac{\\beta^2\\alpha-\\alpha^2\\beta}{\\alpha-\\beta}\n\t\t\t= - \\alpha \\beta = 1.  \\\\\n\t\tF_{2p+2} &= \\frac{\\alpha^{2p+2} - \\beta^{2p+2}}{\\alpha-\\beta}\n\t\t\t= \\frac{\\beta^2\\alpha^2-\\alpha^2\\beta^2}{\\alpha-\\beta} = 0.\n\t\\end{align*}\n\tConsequently, the period must divide $2p+2$ but not $p+1$.\n\n\tWe now use for the first time the exact numerical value $p=127$\n\tto see the period divides $2p+2 = 256 = 2^8$,\n\tbut not $p+1 = 128 = 2^7$.\n\t(Previously we only used the fact that $(5/p)=-1$.)\n\tThus the period must be exactly $256$.\n\t\\end{sol}\n\\end{dproblem}\n", "meta": {"hexsha": "b0816ce5e35a276753a45c725cc63af5a973cdc2", "size": 11909, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/alg-NT/finite-field.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/finite-field.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/finite-field.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": 39.303630363, "max_line_length": 93, "alphanum_fraction": 0.6662188261, "num_tokens": 4051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.9059898299021697, "lm_q1q2_score": 0.6028551869113413}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\newcommand{\\vG}{\\mathbf{G}}\n\\newcommand{\\vr}{\\mathbf{r}}\n\\newcommand{\\vI}{\\mathbf{I}}\n\\title{Notes on Reciprocal-Space Jastrow Factors}\n\\date{\\today}\n\\author{Ken Esler}\n\\begin{document}\n\\maketitle\n\\section{Two-body Jastrow}\n\\begin{equation}\nJ_2 = \\sum_{\\vG\\neq \\mathbf{0}}\\sum_{i\\neq j} a_\\vG e^{i\\vG\\cdot(\\vr_i-\\vr_j)}\n\\end{equation}\nThis may be rewritten as\n\\begin{eqnarray}\nJ_2 & = & \\sum_{\\vG\\neq \\mathbf{0}}\\sum_{i\\neq j} a_\\vG e^{i\\vG\\cdot\\vr_i}e^{-i\\vG\\cdot\\vr_j} \\\\\n& = & \\sum_{\\vG\\neq \\mathbf{0}} a_\\vG \\left\\{\n\\underbrace{\\left[\\sum_i e^{i\\vG\\cdot\\vr_i} \\right]}_{\\rho_\\vG}\n\\underbrace{\\left[\\sum_j e^{-i\\vG\\cdot\\vr_j} \\right]}_{\\rho_{-\\vG}}  -1 \\right\\}\n\\end{eqnarray}\nThe $-1$ is just a constant term and may be subsumed into the $a_\\vG$\ncoefficient by a simple redefintion.  This leaves a simple, but\ngeneral, form:\n\\begin{equation}\nJ_2 = \\sum_{\\vG\\neq\\mathbf{0}} a_\\vG \\rho_\\vG \\rho_{-\\vG}\n\\end{equation}\nWe may now further constrain this on physical grounds.  First, we\nrecognize that $J_2$ should be real.  Since $\\rho_{-\\vG} =\n\\rho_\\vG^*$, it follows that $\\rho_{\\vG}\\rho_{-\\vG} = |\\rho_\\vG|^2$ is\nreal, so that $a_\\vG$ must be real.  Furthermore, we group the $\\vG$'s\ninto $(+\\vG, -\\vG)$ pairs, and sum over only the positive vectors to\nsave time.\n\n\\section{One-body Jastrow}\nThe one-body Jastrow has a similar form, but depends on the\ndisplacment from the electrons to the ions in the system.\n\\begin{equation}\nJ_1 = \\sum_{\\vG\\neq\\mathbf{0}} \\sum_{\\alpha}\n\\sum_{i\\in\\vI^\\alpha}\\sum_{j\\in\\text{elec.}} b^{\\alpha}_\\vG\n  e^{i\\vG\\cdot(\\vI^{\\alpha}_i - \\vr_j)},\n\\end{equation}\nwhere $\\alpha$ denotes the different ionic species.\nWe may rewrite this in terms of $\\rho^{\\alpha}_\\vG$, \n\\begin{equation}\nJ_1 = \\sum_{\\vG\\neq\\mathbf{0}} \\left[\\sum_\\alpha b^\\alpha_\\vG\n  \\rho_\\vG^\\alpha\\right] \\rho_{-\\vG},\n\\end{equation}\nwhere\n\\begin{equation}\n\\rho^\\alpha_\\vG = \\sum_{i\\in\\vI^\\alpha} e^{i\\vG\\cdot\\vI^\\alpha_i}.\n\\end{equation}\nWe note that in the above equation, for a single configuration of the\nions, the sum in brackets can be rewritten as a single constant.  This\nimplies that the per-species one-body coefficents, $b^\\alpha_\\vG$, are\nunderdetermined for single configuration of the ions.  In general, if\nwe have $N$ species, we need $N$ linearly independent ion\nconfigurations to uniquely determine $b^{\\alpha}_\\vG$.  For this\nreason, we will drop the $\\alpha$ superscript of $b_\\vG$ for now.  \n\nIf we do desire to find a reciprocal space one-body Jastrow that is\ntransferable to systems with different ion positions and $N$ \nionic species, we must perform compute $b_\\vG$ for $N$ different ion\nconfigurations.  We may then construct $N$ equations at each value of\n$\\vG$ to solve for the $N$ unknown values, $b^\\alpha_\\vG$.\n\nIn the two-body case, $a_\\vG$ was constrained to be real by the fact\nthat $\\rho_\\vG \\rho_{-\\vG}$ was real.  However, in the one-body case,\nthere is no such guarantee about $\\rho^\\alpha_\\vG \\rho_\\vG$.\nTherefore, in general, $b_\\vG$ may be complex.\n\n\\section{Symmetry considerations}\nFor a crystal, many of the $\\vG$-vectors will be equivalent by\nsymmetry.  It is useful then, to divide the $\\vG$-vectors into\nsymmetry-related groups and then to require that they share a common\ncoefficient.  Two vectors, $\\vG$ and $\\vG'$, may be considered\nsymmetry related if, for all $\\alpha$ and $\\beta$,\n\\begin{equation}\n\\rho^\\alpha_\\vG \\rho^\\beta_{-\\vG} = \\rho^\\alpha_{\\vG'} \\rho^\\beta_{-\\vG'}. \n\\end{equation}\nFor the one-body term, we may also omit from our list of $\\vG$-vectors\nthose for which all species structure factors are zero.  This is\nequivalent to saying that, if we are tiling a primitive cell, we\nshould include only the $\\vG$-vectors of the primitive cell, and not\nthe supercell.  Note that this is not the case for the two-body term,\nsince the exchange-correlation hole should not have the periodicity of\nthe primitive cell.\n\n\\section{Gradients and Laplacians}\n\\begin{eqnarray}\n\\nabla_{\\vr_i} J_2 & = & \\sum_{\\vG \\neq 0} a_\\vG \\left[\\left(\\nabla_{\\vr_i}\\rho_\\vG\\right) \\rho_{-\\vG} + \\text{c.c.}\\right] \\\\\n& = & \\sum_{\\vG\\neq \\mathbf{0}} 2\\vG a_\\vG \\mathbf{Re}\\left(i e^{i\\vG\\cdot\\vr_i} \\rho_{-\\vG} \\right) \\\\\n& = & \\sum_{\\vG\\neq \\mathbf{0}} -2\\vG a_\\vG\\mathbf{Im}\\left(e^{i\\vG\\cdot\\vr_i} \\rho_{-\\vG} \\right)\n\\end{eqnarray}\nThe Laplacian is then given by\n\\begin{eqnarray}\n  \\nabla^2 J_2 & = & \\sum_{\\vG\\neq\\mathbf{0}} a_\\vG \\left[\\left(\\nabla^2 \\rho_\\vG\\right) \\rho_{-\\vG} + \\text{c.c.} \n  + 2\\left(\\nabla \\rho_\\vG)\\cdot(\\nabla \\rho_{-\\vG}\\right)\\right] \\\\\n& = & \\sum_{\\vG\\neq\\mathbf{0}} a_\\vG \\left[ -2G^2\\mathbf{Re}(e^{i\\vG\\cdot\\vr_i}\\rho_{-\\vG}) + \n    2\\left(i\\vG e^{i\\vG\\cdot\\vr_i}\\right) \\cdot \\left(-i\\vG e^{-i\\vG\\cdot\\vr_i}\\right)\n\\right] \\\\\n& = & 2 \\sum_{\\vG\\neq\\mathbf{0}} G^2 a_\\vG  \\left[-\\mathbf{Re}\\left(e^{i\\vG\\cdot\\vr_i}\\rho_{-\\vG}\\right) + 1\\right] \n%  \\nabla^2_{\\vr_i} J_2 & = & \\nabla_{\\vr_i} \\cdot \\nabla_{\\vr_i} J_2 \\\\\n%  & = & -2\\sum_{\\vG \\neq \\mathbf{0}} a_\\vG \\vG \\cdot \\nabla_{\\vr_i} \\mathbf{Im}\\left(e^{i\\vG\\cdot\\vr_i} \\rho_{-\\vG}\\right)\n%  & = & -2\\sum_{\\vG \\neq \\mathbf{0}} a_\\vG \\vG \\cdot \\mathbf{Im}\\left(i\\vG e^{i\\vG\\cdot\\vr_i}\\rho_{-\\vG} -i\\vG \\right)\n\\end{eqnarray}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "e438bbd409f075342c1c4543a3edaa1c0da8391b", "size": 5203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "test/performance-regression/full-apps/qmcpack/src/QMCWaveFunctions/Jastrow/kSpaceJastrowNotes.tex", "max_stars_repo_name": "FeiyangJin/hclib", "max_stars_repo_head_hexsha": "d23c850dce914e2d80cae733670820812a1edeee", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-07-28T01:32:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T16:27:46.000Z", "max_issues_repo_path": "test/performance-regression/full-apps/qmcpack/src/QMCWaveFunctions/Jastrow/kSpaceJastrowNotes.tex", "max_issues_repo_name": "FeiyangJin/hclib", "max_issues_repo_head_hexsha": "d23c850dce914e2d80cae733670820812a1edeee", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 66, "max_issues_repo_issues_event_min_datetime": "2015-06-15T20:38:19.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-26T00:11:43.000Z", "max_forks_repo_path": "test/performance-regression/full-apps/qmcpack/src/QMCWaveFunctions/Jastrow/kSpaceJastrowNotes.tex", "max_forks_repo_name": "FeiyangJin/hclib", "max_forks_repo_head_hexsha": "d23c850dce914e2d80cae733670820812a1edeee", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-26T22:11:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-02T22:09:15.000Z", "avg_line_length": 46.8738738739, "max_line_length": 126, "alphanum_fraction": 0.68614261, "num_tokens": 2031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6027299703377054}}
{"text": "\\section{Evaluation}\n\\label{sec:evaluation}\n\nTo be able to compare the results of different experiments, we have fixed the number of iterations of Stochastic Gradient Descent to a constant value of $20000$.\n\n\\subsection{Train Error}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/error}\n\t\\caption{Train and test error of the network for $P = 1000$. The training is done with a fixed learning rate $\\eta = 0.05$.}\n\t\\label{fig:training_error}\n\\end{figure}\n\n\\cref{fig:training_error} shows the train and test error for the network trained using Stochastic Gradient Descent on the first $1000$ examples.\nBoth the train error and test error drop very quickly during approximately the first $1000$ iterations, then remain almost constant for the rest of the training.\nThe test error is slightly bigger than the train error:\nat the end of the training, the train error is around $0.10$ and the test error around $0.12$.\nSince the test error never increases, the model does not seem to overfit the training data.\n\n\\subsection{Learned Weights}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/weights_p_1000}\n    \\caption{Weights of the hidden units after the training for $P = 1000$.}\n\t\\label{fig:weights}\n\\end{figure}\n\n\\cref{fig:weights} shows the weights learned from the hidden units of the networks after the training for $P = 1000$.\nAs expected, the units learn different weights thanks to the random initialization of the weights.\n\n\\subsection{Train Dataset}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/error_ps}\n\t\\caption{Train and test error of the network for different numbers of training examples $P$. The training is done with a fixed learning rate $\\eta = 0.05$.}\n\t\\label{fig:ps}\n\\end{figure}\n\n\\cref{fig:ps} shows the train and test error for different values of $P$, i.e. for a network trained on training dataset of different dimensions.\nFor very small training datasets ($P = 20$, $P = 50$), the train error drops very quickly and stabilizes close to $0$;\nthe test error is high and even increases during the training for $P = 50$.\nIt seems like the training set is too small for the network to generalize properly to new data, so it tends to overfit the train set.\n\nFor $P = 200$, the train error is higher, but the test error gets significantly smaller.\nStill, the test error increases during the training, which indicates overfitting.\n\nFor $P = 500$, the train and test error get closer and remain constant during most of the training.\nThe results for higher values of $P$ are very similar and are thus not shown here.\n\n\\subsection{Train Policy}\nThe learning rate influences the number of iterations the training algorithm needs to converge to the optimal weights.\nA high learning rate causes the process to be unstable, while a low one takes too long time to converge.\nFor this reason, we implement different schedulers for the learning rate able to change its value over time as a function of the current iteration: \\textit{fixed}, \\textit{step}, \\textit{exponential} and \\textit{cycle}.\n\\cref{fig:learning_rates_policies} shows the learning rate change over time for the different strategies.\nFrom the application of these \\ac{LRPs} we expect a change in the behavior of the error function.\nIn most \\ac{LRPs} the learning rate decreases over time, so the error should get more stable.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/learning_rates}\n\t\\caption{Learning rate evolution over iterations for different learning strategies.}\n\t\\label{fig:learning_rates_policies}\n\\end{figure}\n\n\\cref{fig:lrp_training_error} shows that different \\ac{LRPs} have different effects on the error trend.\nOverall, all implemented \\ac{LRPs} perform better than the \\textit{fixed}($0.05$).\nThe next sections discuss them in more detail.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/error_strategies}\n\t\\caption{Train and test error for different learning strategies.}\n\t\\label{fig:lrp_training_error}\n\\end{figure}\n\n\\subsubsection{Fixed \\ac{LRP}}\nAs the name suggests this \\ac{LRP} leaves the learning rate fixed during iterations.\nThe error to drops down after around $500$ iterations, then decreases very slowly. \nOn our dataset, this strategy yields the best performances for a learning rate $\\eta = 0.02$.\n\n\\subsubsection{Step \\ac{LRP}}\nThis strategy consists in decreasing the learning rate of a defined quantity (\\textit{drop}) after a certain number of iterations (\\textit{step\\_size}).\nAs shown in \\cref{fig:learning_rates_policies}, we chose \\textit{step\\_size} = $5000$ and \\textit{drop} = $0.01$.\n\\cref{fig:lrp_training_error} shows a drop in both train and test error close to the step in the learning rate.\n\n\\subsubsection{Exponential \\ac{LRP}}\nThis strategy consist in decreasing the learning rate in an exponential way, i.e. in dividing it by a constant value at each iteration.\nThis \\ac{LRP} lets the network learn quickly at the beginning, when the currently weights are likely to be far from optimal one, and then slowly, when they are getting closer to it.\n\\cref{fig:lrp_training_error} shows a smoother decrease of both the train and test errors, which reaches a value smaller than $0.1$ after just $3000$ iterations.\n\n\\subsubsection{Cycle}\nThis strategy consists in increasing and decreasing the learning rate linearly over the number of iterations, creating a sawteeth plot, as shown in \\cref{fig:learning_rates_policies}.\nThe aim of this \\ac{LRP} is to avoid local minima letting the value of the learning rate to grow again when it reaches its minimum value.\n\\cref{fig:lrp_training_error} shows that this strategy performs well as far as the value of the learning rate is smaller than $0.02$, then the errors increase following the increase of the learning rate.\n", "meta": {"hexsha": "541571994a65fe7f0802a23eb184e5003c1ad263", "size": 5824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_3/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_3/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_3/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": 61.3052631579, "max_line_length": 219, "alphanum_fraction": 0.7824519231, "num_tokens": 1426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300048, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6027299624548379}}
{"text": "\\documentclass[journal,hidelinks]{IEEEtran}\n\\usepackage[utf8]{inputenc}\n\\usepackage[\n  pdftitle={Assignment \\#1},\n  pdfauthor={Andrei Purcarus},\n  pdfsubject={ECSE-543 -- Numerical Methods in EE}\n]{hyperref}\n\\usepackage{graphicx}\n\\usepackage[all]{hypcap}\n\\usepackage{cleveref}\n\\usepackage{indentfirst}\n\\usepackage[per-mode=symbol]{siunitx}\n\\usepackage{listings}\n\\lstset{showstringspaces=false}\n%\\usepackage[title]{appendix}\n\n\\title{ECSE-543 \\\\ Numerical Methods in EE \\\\ Assignment \\#1}\n\\author{Andrei~Purcarus,~260631911,~\\IEEEmembership{McGill~University}}\n\n\\begin{document}\n\\sloppy\n\n\\maketitle\n\n% \\begin{abstract}\n\n\n\n% \\end{abstract}\n\n% \\section{Introduction}\n\n\\section*{Code Listings and Unit Testing}\n\nThe source code used for this assignment is listed in the appendices. In order to save space, we did not include the unit tests. For the full code, see the \\href{https://github.com/Gripnook/ECSE543-F17-A1}{GitHub repository}.\n\n\\Cref{sec:main} contains the main function. \\Cref{sec:matrix,sec:matrix-util} define a matrix library and helper functions. \\Cref{sec:cholesky} defines functions that perform Cholesky decomposition using banded and non-banded methods. \\Cref{sec:solver} defines a generic solver for systems of equations that have a positive-definite coefficient matrix. \\Cref{sec:mesh-h,sec:mesh-cpp} define a circuit description file generator for an $N * 2N$ resistor mesh. \\Cref{sec:circuit-solver-h,sec:circuit-solver-cpp} define functions that solve a circuit as given by a circuit description file. Finally, \\Cref{sec:finite-differences-h,sec:finite-differences-cpp} define finite difference problem generators and solvers with iterative methods.\n\nWhenever we had to test some functionality, we used unit tests that we will reference in the text. These tests all pass, as shown in \\Cref{fig:test-output}.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth]{test-output.png}\n  \\caption{Output after running the unit test suite.}\n  \\label{fig:test-output}\n\\end{figure}\n\n\\section*{Question 1}\n\nWe first wrote and tested a program that solves the matrix equation $A x = b$ using Cholesky decomposition. The code listings are shown in \\Cref{sec:matrix,sec:matrix-util,sec:cholesky,sec:solver}. To test the solver, we generated several non-singular lower triangular matrices $L$ with positive entries on the main diagonal, then took $A = L L^T$, which guarantees that $A$ has a Cholesky decomposition and hence is positive-definite. For each such $n * n$ matrix, we invented an $n * 1$ vector $x$, multiplied it by $A$ to get an $n * 1$ vector $b$, then tested the solver with $A$ and $b$ and compared the result to $x$. The section of the unit tests which performs this function is shown in \\Cref{sec:solver-test-cpp}. The matrices $L$ used for each of the $2 * 2$, $3 * 3$, $4 * 4$, and $5 * 5$ systems of equations, as well as the vectors $x$, should be clear from the unit test code.\n\nThen, we wrote a program that reads a list of network branches from an input stream and solves for the node voltages. The code is shown in \\Cref{sec:circuit-solver-h,sec:circuit-solver-cpp}. The network branches are expected to be lines of the form\n\\[ N_+ \\  N_- \\  J_k \\  R_k \\  E_k \\]\nwhere $N_+$ and $N_-$ are numeric node labels, $J_k$ is the short circuit current coming out of node $N_+$ and going into node $N_-$, $R_k$ is the equivalent resistance between nodes $N_+$ and $N_-$, and $E_k$ is the open circuit voltage between $N_+$ and $N_-$. This program can read from a file, as shown in \\Cref{sec:main}, but to test it we used our unit testing framework to generate the input stream. An extract of the unit test is shown in \\Cref{sec:circuit-solver-test-cpp}, which solves 5 circuits correctly. These circuits, along with their expected results, are shown in \\Cref{fig:q1-circuit-1,fig:q1-circuit-2,fig:q1-circuit-3,fig:q1-circuit-4,fig:q1-circuit-5}.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth,height=0.4\\columnwidth,keepaspectratio]{question-1/circuit-1.pdf}\n  \\caption{Test circuit 1. $V_1 = \\SI{5}{\\volt}$.}\n  \\label{fig:q1-circuit-1}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth,height=0.35\\columnwidth,keepaspectratio]{question-1/circuit-2.pdf}\n  \\caption{Test circuit 2. $V_1 = \\SI{50}{\\volt}$}\n  \\label{fig:q1-circuit-2}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth,height=0.4\\columnwidth,keepaspectratio]{question-1/circuit-3.pdf}\n  \\caption{Test circuit 3. $V_1 = \\SI{55}{\\volt}$.}\n  \\label{fig:q1-circuit-3}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth,height=0.4\\columnwidth,keepaspectratio]{question-1/circuit-4.pdf}\n  \\caption{Test circuit 4. $V_1 = \\SI{20}{\\volt}$, $V_2 = \\SI{35}{\\volt}$.}\n  \\label{fig:q1-circuit-4}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=\\columnwidth,height=0.6\\columnwidth,keepaspectratio]{question-1/circuit-5.pdf}\n  \\caption{Test circuit 5. $V_1 = \\SI{5}{\\volt}$, $V_2 = \\SI{3.75}{\\volt}$, $V_3 = \\SI{3.75}{\\volt}$.}\n  \\label{fig:q1-circuit-5}\n\\end{figure}\n\n\\section*{Question 2}\n\nWe then wrote a program that generates the network branches for an $N * 2N$ mesh of $\\SI{1}{\\ohm}$ resistors. We chose $\\SI{1}{\\ohm}$ instead of $\\SI{1}{\\kilo\\ohm}$ since $\\SI{1}{\\ohm}$ is simpler to work with and the result will just scale linearly. The code that generates this network is given in \\Cref{sec:mesh-h,sec:mesh-cpp}. Note that the program generates an extra branch, consisting of a $\\SI{1}{\\ampere}$ current source in parallel with another $\\SI{1}{\\ohm}$ resistor between the top right corner and the bottom left corner of the mesh. The equivalent resistance can then be found by using the node voltage at the top right corner, as $R_{eq} = V / (1 - V)$. The code that does this is shown in \\Cref{sec:main}. The scaled results are shown in \\Cref{tab:q2-resistance}.\n\n\\begin{table}[!htb]\n  \\centering\n  \\caption{$R$ vs. $N$ for the $N * 2N$ mesh of $\\SI{1}{\\kilo\\ohm}$ resistors.}\n  \\label{tab:q2-resistance}\n  \\resizebox{0.3\\columnwidth}{!}{\\begin{tabular}{|l|l|}\n    \\hline\n    $N$ & $R(\\SI{}{\\kilo\\ohm})$ \\\\ \\hline\n    2 & 2.05742 \\\\ \\hline\n    3 & 2.49772 \\\\ \\hline\n    4 & 2.82749 \\\\ \\hline\n    5 & 3.09057 \\\\ \\hline\n    6 & 3.30919 \\\\ \\hline\n    7 & 3.49608 \\\\ \\hline\n    8 & 3.65925 \\\\ \\hline\n    9 & 3.80401 \\\\ \\hline\n    10 & 3.93407 \\\\ \\hline\n  \\end{tabular}}\n\\end{table}\n\nIn theory, the time taken to solve the system of equations increases as $O(n^3)$, where $n$ is the size of the square matrix $A$ in the system $A x = b$. In this case, since there are $2N^2 + 3N$ free nodes, $n = O(N^2)$, and so the time taken should increase as $O(N^6)$. We measured the time it took for the program to solve the circuit for different values of $N$. However, since the initial matrix multiplication $A Y A^T$ is $O(N^6)$, we excluded the time needed to form the initial matrices from our measurements. The results are shown in \\Cref{fig:q2-std-time}. We fitted a polynomial of the form $a * N ^ b$ to the data and found that it grows approximately as $O(N^{5.25})$. This agrees with the expectation. The reason that it is slightly lower is that for low values of $N$, lower order terms also contribute a significant amount. We would expect the effective exponent to increase to $6$ with higher values of $N$.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-2/standard_time.eps}\n  \\caption{Time vs. $N$ for solving the $N * 2N$ mesh of $\\SI{1}{\\kilo\\ohm}$ resistors with the standard circuit solver.}\n  \\label{fig:q2-std-time}\n\\end{figure}\n\nWe then modified the program to compute and use the half-bandwidth of the matrix $A$ in solving for the Cholesky decomposition. These changes are shown in \\Cref{sec:cholesky,sec:solver,sec:circuit-solver-h,sec:circuit-solver-cpp}. Since a node connects only to nodes a distance $N$ away using our numbering system, the half-bandwidth is $b = O(N)$. Hence, the time taken should increase as $O(n b^2)  = O(N^4)$. However, since the initial matrix multiplication $A Y A^T$ is $O(N^6)$, the effects will not be noticeable unless we exclude the time taken to form the initial matrices. To get a better measurement, we measured for $N$ up to $32$. The results are shown in \\Cref{fig:q2-band-time}. We fitted a polynomial of the form $a * N ^ b$ to the data and found that it grows approximately as $O(N^4)$. This agrees with the expectation.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-2/banded_time.eps}\n  \\caption{Time vs. $N$ for solving the $N * 2N$ mesh of $\\SI{1}{\\kilo\\ohm}$ resistors with the banded circuit solver.}\n  \\label{fig:q2-band-time}\n\\end{figure}\n\nWe then measured the values of $R$ for $N$ up to $32$ and plotted the results in \\Cref{fig:q2-resistance}. After trying different functions to fit the data, we found that the resistance is best approximated by a function of the form $R(N) = a * log(N + b) + c$. The best such function is included in \\Cref{fig:q2-resistance}. We can see that this function is an almost perfect fit over the entire range. Thus, we can conclude that, asymptotically, we have $R(N) = O(log(N))$.\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-2/resistance.eps}\n  \\caption{$R$ vs. $N$ for the $N * 2N$ mesh of $\\SI{1}{\\kilo\\ohm}$ resistors.}\n  \\label{fig:q2-resistance}\n\\end{figure}\n\n\\section*{Question 3}\n\nWe then wrote a program to use a SOR finite difference method to solve for the potential between two conductors, as given in the assignment specifications. We exploited both the vertical and horizontal symmetries to work with only a quarter of the grid. The code is shown in \\Cref{sec:main,sec:finite-differences-h,sec:finite-differences-cpp}.\n\nWe then set $h = 0.02$ and varied $w$ over the range $[1.0, 2.0)$ in $0.1$ increments. The results are shown in \\Cref{tab:q3-w-sor}. The number of iterations taken for each value of $w$ is also plotted in \\Cref{fig:q3-w}. We omit the point at $w = 1.9$ to better visualize the data. From this we can see that the value of $w = 1.4$ results in the fastest convergence.\n\n\\begin{table}[!htb]\n  \\centering\n  \\caption{Results for SOR with $h = 0.02$ for different values of $w$.}\n  \\label{tab:q3-w-sor}\n  \\resizebox{0.7\\columnwidth}{!}{\\begin{tabular}{|l|l|l|}\n    \\hline\n    $w$ & Iterations & $V_{(0.06,0.04)} (\\SI{}{\\volt})$ \\\\ \\hline\n    1.0 & 38 & 5.52627 \\\\ \\hline\n    1.1 & 31 & 5.52627 \\\\ \\hline\n    1.2 & 26 & 5.52630 \\\\ \\hline\n    1.3 & 21 & 5.52631 \\\\ \\hline\n    1.4 & 20 & 5.52634 \\\\ \\hline\n    1.5 & 25 & 5.52635 \\\\ \\hline\n    1.6 & 37 & 5.52634 \\\\ \\hline\n    1.7 & 54 & 5.52634 \\\\ \\hline\n    1.8 & 92 & 5.52635 \\\\ \\hline\n    1.9 & 903 & 5.52632 \\\\ \\hline\n  \\end{tabular}}\n\\end{table}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-3/w_sor.eps}\n  \\caption{Iterations vs. $w$ for SOR with $h = 0.02$.}\n  \\label{fig:q3-w}\n\\end{figure}\n\nWe then set $w = 1.4$ and varied $h$. The results are shown in \\Cref{tab:q3-h-sor} and plotted in \\Cref{fig:q3-h-v-sor,fig:q3-h-iter-sor}. From this data, it is clear that the potential at the point $(0.06, 0.04)$ is dropping as we decrease $h$. However, it is hard to predict what the value is without trying lower values of $h$, which would take too much time. We can estimate that it is between $\\SI{5.10}{\\volt}$ and $\\SI{5.20}{\\volt}$. To three significant figures, we could therefore estimate it to be around $\\SI{5.14}{\\volt}$, but this estimate is very likely to be wrong. We can also observe from \\Cref{fig:q3-h-iter-sor} that the number of iterations increases at supra-linear rates. That is, the iterations needed increase faster than $1/h$. This has the consequence that decreasing $h$ to find better approximations rapidly becomes impractical.\n\n\\begin{table}[!htb]\n  \\centering\n  \\caption{Results for SOR with $w = 1.4$ for different values of $h$.}\n  \\label{tab:q3-h-sor}\n  \\resizebox{0.7\\columnwidth}{!}{\\begin{tabular}{|l|l|l|}\n    \\hline\n    $1/h$ & iterations & $V_{(0.06,0.04)} (\\SI{}{\\volt})$ \\\\ \\hline\n    50 & 20 & 5.52634 \\\\ \\hline\n    100 & 62 & 5.35057 \\\\ \\hline\n    200 & 209 & 5.28872 \\\\ \\hline\n    250 & 308 & 5.27838 \\\\ \\hline\n    500 & 1009 & 5.25778 \\\\ \\hline\n    1000 & 3215 & 5.23656 \\\\ \\hline\n  \\end{tabular}}\n\\end{table}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-3/h_v_sor.eps}\n  \\caption{$V_{(0.06,0.04)}$ vs. $1/h$ for SOR with $w = 1.4$.}\n  \\label{fig:q3-h-v-sor}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-3/h_iter_sor.eps}\n  \\caption{Iterations vs. $1/h$ for SOR with $w = 1.4$.}\n  \\label{fig:q3-h-iter-sor}\n\\end{figure}\n\nThen, we used the Jacobi method to solve the same problem. The results are shown in \\Cref{tab:q3-h-jacobi} and plotted in \\Cref{fig:q3-h-v-jacobi,fig:q3-h-iter-jacobi}. From this data, we can see that the Jacobi method requires more iterations than SOR for the same values of $h$. However, the rate of increase appears to be similar. Thus, we conclude that the SOR approach has an initial speed advantage, but as $h$ gets smaller its performance drops at the same rate as the Jacobi method. It is possible that varying the value of $w$ can improve the performance of SOR at these smaller spacings. In addition, we notice that the Jacobi method is more accurate than SOR for the same values of $h$, since the potential it computes is slightly lower.\n\n\\begin{table}[!htb]\n  \\centering\n  \\caption{Results for the Jacobi method for different values of $h$.}\n  \\label{tab:q3-h-jacobi}\n  \\resizebox{0.7\\columnwidth}{!}{\\begin{tabular}{|l|l|l|}\n    \\hline\n    $1/h$ & iterations & $V_{(0.06,0.04)} (\\SI{}{\\volt})$ \\\\ \\hline\n    50 & 63 & 5.52614 \\\\ \\hline\n    100 & 227 & 5.34994 \\\\ \\hline\n    200 & 781 & 5.28654 \\\\ \\hline\n    250 & 1153 & 5.27505 \\\\ \\hline\n    500 & 3764 & 5.24523 \\\\ \\hline\n    1000 & 11692 & 5.18932 \\\\ \\hline\n  \\end{tabular}}\n\\end{table}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-3/h_v_jacobi.eps}\n  \\caption{$V_{(0.06,0.04)}$ vs. $1/h$ for the Jacobi method.}\n  \\label{fig:q3-h-v-jacobi}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\centering\n  \\includegraphics[width=0.6\\columnwidth]{question-3/h_iter_jacobi.eps}\n  \\caption{Iterations vs. $1/h$ for the Jacobi method.}\n  \\label{fig:q3-h-iter-jacobi}\n\\end{figure}\n\nWe then modified the program to allow uneven spacing. An interface was provided where the user could input a vector of $x$ positions and a vector of $y$ positions indicating where grid lines would be located. The code is shown in \\Cref{sec:finite-differences-h,sec:finite-differences-cpp}. Using this setup, we separated the grid using the same number of nodes as for $h = 0.01$. We approached this by starting with the grid for $h = 0.02$ and adding lines close to the point $(0.06, 0.04)$ until we got a better result. The resulting $x$ vector was (0.0, 0.02, 0.04, 0.05, 0.055, 0.06, 0.065, 0.07, 0.08, 0.1) and the resulting $y$ vector was (0.0, 0.02, 0.03, 0.04, 0.041, 0.042, 0.045, 0.05, 0.06, 0.07, 0.08, 0.1). Using this setup, we were able to obtain a value of $V_{(0.06,0.04)} = \\SI{5.33519}{\\volt}$, which is closer to the real value than the value obtained with $h = 0.01$.\n\n% \\section{Conclusions}\n\n\n\\newpage\n\\onecolumn\n\n\\begin{appendices}\n\n\\section{Main.cpp}\n\\label{sec:main}\n\\lstinputlisting[language=C++]{src/main.cpp}\n\\newpage\n\n\\section{Matrix.h}\n\\label{sec:matrix}\n\\lstinputlisting[language=C++]{src/matrix.h}\n\\newpage\n\n\\section{Matrix-util.h}\n\\label{sec:matrix-util}\n\\lstinputlisting[language=C++]{src/matrix-util.h}\n\\newpage\n\n\\section{Cholesky.h}\n\\label{sec:cholesky}\n\\lstinputlisting[language=C++]{src/cholesky.h}\n\\newpage\n\n\\section{Solver.h}\n\\label{sec:solver}\n\\lstinputlisting[language=C++]{src/solver.h}\n\\newpage\n\n\\section{Mesh.h}\n\\label{sec:mesh-h}\n\\lstinputlisting[language=C++]{src/mesh.h}\n\\newpage\n\n\\section{Mesh.cpp}\n\\label{sec:mesh-cpp}\n\\lstinputlisting[language=C++]{src/mesh.cpp}\n\\newpage\n\n\\section{Circuit-solver.h}\n\\label{sec:circuit-solver-h}\n\\lstinputlisting[language=C++]{src/circuit-solver.h}\n\\newpage\n\n\\section{Circuit-solver.cpp}\n\\label{sec:circuit-solver-cpp}\n\\lstinputlisting[language=C++]{src/circuit-solver.cpp}\n\\newpage\n\n\\section{Finite-differences.h}\n\\label{sec:finite-differences-h}\n\\lstinputlisting[language=C++]{src/finite-differences.h}\n\\newpage\n\n\\section{Finite-differences.cpp}\n\\label{sec:finite-differences-cpp}\n\\lstinputlisting[language=C++]{src/finite-differences.cpp}\n\\newpage\n\n\\section{Extract from Solver-test.cpp}\n\\label{sec:solver-test-cpp}\n\\begin{lstlisting}[language=C++]\nTEST_CASE(\"solve succeeds for a 2x2 system of equations\")\n{\n    Matrix<double> lower = \"[\"\n                           \"1,0;\"\n                           \"2,1\"\n                           \"]\";\n    Matrix<double> m = lower * transpose(lower);\n    Matrix<double> x = \"[4;3]\";\n    Matrix<double> b = m * x;\n    auto result = solve(m, b);\n    REQUIRE(result == x);\n}\n\nTEST_CASE(\"solve succeeds for a 3x3 system of equations\")\n{\n    Matrix<double> lower = \"[\"\n                           \"4, 0,0;\"\n                           \"5, 1,0;\"\n                           \"9,-1,2\"\n                           \"]\";\n    Matrix<double> m = lower * transpose(lower);\n    Matrix<double> x = \"[1.0;2.5;-2.0]\";\n    Matrix<double> b = m * x;\n    auto result = solve(m, b);\n    REQUIRE(result == x);\n}\n\nTEST_CASE(\"solve succeeds for a 4x4 system of equations\")\n{\n    Matrix<double> lower = \"[\"\n                           \" 1, 0, 0, 0;\"\n                           \" 2, 3, 0, 0;\"\n                           \" 5, 7,11, 0;\"\n                           \"13,17,19,23\"\n                           \"]\";\n    Matrix<double> m = lower * transpose(lower);\n    Matrix<double> x = \"[1;2;4;8]\";\n    Matrix<double> b = m * x;\n    auto result = solve(m, b);\n    REQUIRE(result == x);\n}\n\nTEST_CASE(\"solve succeeds for a 5x5 system of equations\")\n{\n    Matrix<double> lower = \"[\"\n                           \" 1,0,0,0,0;\"\n                           \" 2,1,0,0,0;\"\n                           \" 4,2,1,0,0;\"\n                           \" 8,4,2,1,0;\"\n                           \"16,8,4,2,1\"\n                           \"]\";\n    Matrix<double> m = lower * transpose(lower);\n    Matrix<double> x = \"[13;-7;19;-11;3]\";\n    Matrix<double> b = m * x;\n    auto result = solve(m, b);\n    REQUIRE(result == x);\n}\n\\end{lstlisting}\n\\newpage\n\n\\section{Extract from Circuit-solver-test.cpp}\n\\label{sec:circuit-solver-test-cpp}\n\\begin{lstlisting}[language=C++]\n// Truncates the least significant bits of the value for a better floating point\n// comparison that ignores some round-off error.\nfloat fround(double value)\n{\n    return static_cast<float>(value);\n}\n\nTEST_CASE(\"csolve succeeds for circuit 1\")\n{\n    std::stringstream in{\"1 0 0 10 0\\n\"\n                         \"1 0 0 10 10\\n\"};\n    auto v = csolve(in);\n    CHECK(fround(v(0)) == 5.0f);\n}\n\nTEST_CASE(\"csolve succeeds for circuit 2\")\n{\n    std::stringstream in{\"1 0 10 10 0\\n\"\n                         \"1 0 0 10 0\\n\"};\n    auto v = csolve(in);\n    CHECK(fround(v(0)) == 50.0f);\n}\n\nTEST_CASE(\"csolve succeeds for circuit 3\")\n{\n    std::stringstream in{\"1 0 0 10 10\\n\"\n                         \"1 0 10 10 0\\n\"};\n    auto v = csolve(in);\n    CHECK(fround(v(0)) == 55.0f);\n}\n\nTEST_CASE(\"csolve succeeds for circuit 4\")\n{\n    std::stringstream in{\"1 0 0 10 10\\n\"\n                         \"1 0 0 10 0\\n\"\n                         \"1 2 0 5 0\\n\"\n                         \"2 0 10 5 0\\n\"};\n    auto v = csolve(in);\n    CHECK(fround(v(0)) == 20.0f);\n    CHECK(fround(v(1)) == 35.0f);\n}\n\nTEST_CASE(\"csolve succeeds for circuit 5\")\n{\n    std::stringstream in{\"1 0 0 20 10\\n\"\n                         \"1 2 0 10 0\\n\"\n                         \"1 3 0 10 0\\n\"\n                         \"2 3 0 30 0\\n\"\n                         \"2 0 0 30 0\\n\"\n                         \"3 0 0 30 0\\n\"};\n    auto v = csolve(in);\n    CHECK(fround(v(0)) == 5.0f);\n    CHECK(fround(v(1)) == 3.75f);\n    CHECK(fround(v(2)) == 3.75f);\n}\n\\end{lstlisting}\n\n\\end{appendices}\n\n\\end{document}\n", "meta": {"hexsha": "a1fdb64f46463801da6361b05a52cd94e00d341d", "size": 20086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignment1/report/main.tex", "max_stars_repo_name": "Gripnook/numerical-methods", "max_stars_repo_head_hexsha": "14cb60050e5f2ba413f59690beb24cacb1153563", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-21T01:35:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-21T01:35:02.000Z", "max_issues_repo_path": "Assignment1/report/main.tex", "max_issues_repo_name": "Gripnook/numerical-methods", "max_issues_repo_head_hexsha": "14cb60050e5f2ba413f59690beb24cacb1153563", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Assignment1/report/main.tex", "max_forks_repo_name": "Gripnook/numerical-methods", "max_forks_repo_head_hexsha": "14cb60050e5f2ba413f59690beb24cacb1153563", "max_forks_repo_licenses": ["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.8205128205, "max_line_length": 926, "alphanum_fraction": 0.6679776959, "num_tokens": 6546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6026817064866831}}
{"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 \\#2 \\end{Large} }\n\\author{Jiyu Tian}\n\\date{}\n\n\n\\begin{document}\n\n\\maketitle\n%%---------------------------------------------------------------\n%% Problem 1\n%%---------------------------------------------------------------\n\\section{Problem 2.12}\n\\large{\\textbf{Solution}}: \\\\\n(a) From normalization condition we have:\\\\\n\\begin{equation*}\n1 = \\sum_{i=1}^{c} P(w_i|\\bm{x}) \\leq \\sum_{i=1}^{c} P(w_{max}|\\bm{x}) = c\\times P(w_{max}|\\bm{x})\n\\end{equation*}\nAnd therefore we must have:\n\\begin{equation*}\nP(w_{max}|\\bm{x})\\leq \\frac{1}{c}\n\\end{equation*}\n(b) The probability of error is 1 minus the probability of being correct, that is:\n\\begin{equation*}\n\\begin{aligned}\nP(error) &= 1 - P(correct)\\\\ &= 1-\\int P(correct|\\bm{x})P(\\bm{x}) \\text{ d}\\bm{x}\\\\ & = 1-\\int P(w_{max}|\\bm{x})P(\\bm{x}) \\text{ d}\\bm{x}\n\\end{aligned}\n\\end{equation*}\n(c) With two results above we have:\n\\begin{equation*}\n\\begin{aligned}\nP(error)&=1-\\int P(w_{max}|\\bm{x})P(\\bm{x})\\text{ d}\\bm{x}\\\\ &\\leq 1- \\frac{1}{c}\\int P(\\bm{x})\\text{ d}\\bm{x}\\\\ &= 1-\\frac{1}{c}\n\\end{aligned}\n\\end{equation*}\n(d) Equality occurs if and only if all posteriors are equal:\n\\begin{equation*}\nP(w_i|\\bm{x})=P(w_j|\\bm{x}) \\text{ for all }i,j=1,...,c\n\\end{equation*}\n\n\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Problem 2\n%%---------------------------------------------------------------\n\\section{Problem 3.1}\n\\large{\\textbf{Solution}}: \\\\\n(a) Figure 1 can be plotted with MATLAB:\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{PR31.png}\n\\caption{\\label{fig2}$P(x|\\theta)\\ versus\\ x\\ and\\ \\theta$}\n\\end{figure}\n\\noindent(b) \\\\\n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\theta} &=\\arg\\max_{\\theta}\\ P(D|\\theta) = \\arg\\max_{\\theta}\\ \\prod_{i=1}^{n} P(x_i|\\theta) =\\arg\\max_{\\theta}\\ \\prod_{i=1}^{n} \\theta e^{-\\theta x_i}\\\\ &=\\arg\\max_{\\theta}\\ \\theta^n e^{-\\theta \\sum^{n}_{i=1}x_i} =\\arg\\max_{\\theta}\\ n\\text{ln}\\theta-\\theta \\sum^{n}_{i=1}x_i\n\\end{aligned}\n\\end{equation*}\nTaking the derivative and equating to 0, we have:\n\\begin{equation*}\n\\begin{aligned}\n\\frac{n}{\\hat{\\theta}}-\\sum^{n}_{i=1}x_i = 0\n\\end{aligned}\n\\end{equation*}\nThen the maximum likelihood estimator $\\hat{\\theta}$ is given by\n\\begin{equation*}\n\\hat{\\theta}=\\frac{1}{\\frac{1}{n}\\sum^{n}_{i=1}x_i}.\n\\end{equation*}\n\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Problem 3\n%%---------------------------------------------------------------\n\\section{Problem 3.2}\n\\large{\\textbf{Solution}}: \\\\\n(a) Here we introduce an indicator function $\\bm{1}\\{\\cdot\\}$ which equals to 1 for condition within and 0 otherwise. \n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\theta} &=\\arg\\max_{\\theta}\\ P(D|\\theta) = \\arg\\max_{\\theta}\\ \\prod_{i=1}^{n} P(x_i|\\theta) =\\arg\\max_{\\theta}\\ \\prod_{i=1}^{n} \\frac{1}{\\theta}\\ \\bm{1}\\{0\\leq x_i\\leq \\theta\\}\\\\ \n&=\\arg\\max_{\\theta}\\  \\frac{1}{\\theta^n} \\prod_{i=1}^{n}\\bm{1}\\{0\\leq x_i\\leq \\theta\\}\\\\ \n&= \\arg\\max_{\\theta}\\  \\frac{1}{\\theta^n}\\ \\bm{1}\\{0\\leq\\min_i x_i\\}\\ \\bm{1}\\{\\max_i x_i\\leq\\theta\\}\n\\end{aligned}\n\\end{equation*}\nThe function equals to zero for $\\theta\\leq \\underset{i}{\\max}\\ x_i$ and decreases as $\\theta$ increases for $\\theta\\geq \\underset{i}{\\max}\\ x_i$.  Therefore, the likelihood function is maximized at $\\hat{\\theta} =  \\underset{i}{\\max}\\ x_i$.\n%%---------------------------------------------------------------\n%% Problem 4\n%%---------------------------------------------------------------\n\\section{Problem 3.3}\n\\large{\\textbf{Solution}}: \\\\\n(a) From statement we have $P\\{z_{ik}=1|P(w_i)\\}=P(w_i)$ and $P\\{z_{ik}=0|P(w_i)\\}=1-P(w_i)$, which can be combined as:\n\\begin{equation*}\n\\begin{aligned}\nP(z_{ik}|P(w_i))=P(w_i)^{z_{ik}}(1-P(w_i))^{1-z_{ik}}\n\\end{aligned}\n\\end{equation*}\nThen for the independent states, we have:\n\\begin{equation*}\n\\begin{aligned}\nP(z_{i1},...,z_{ik}|P(w_i))=\\prod^n_{k=1}P(z_{ik}|P(w_i))=\\prod^n_{k=1}P(w_i)^{z_{ik}}(1-P(w_i))^{1-z_{ik}}\n\\end{aligned}\n\\end{equation*}\n(b) With $\\theta = P(w_i)$, the ML estimate for $P(w_i)$ can be expressed as:\n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\theta} &= \\arg\\max_{\\theta}\\ \\prod^n_{k=1}\\theta^{z_{ik}}(1-\\theta)^{1-z_{ik}} =\\arg\\max_{\\theta}\\ \\sum_{k=1}^{n} [z_{ik}\\ln\\theta+(1-z_{ik})\\ln(1-\\theta)]\n\\end{aligned}\n\\end{equation*}\nTaking the derivative and equating to 0, we have:\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{\\hat{\\theta}}\\ \\sum_{k=1}^{n} z_{ik} - \\frac{1}{1-\\hat{\\theta}}\\ \\sum_{k=1}^{n} (1-z_{ik}) = 0\\\\\n\\end{aligned}\n\\end{equation*}\n\\begin{equation*}\n\\begin{aligned}\n\\hat{P}(w_i)=\\hat{\\theta} = \\frac{1}{n}\\sum_{k=1}^{n} z_{ik}\n\\end{aligned}\n\\end{equation*}\nThe ML estimate of prior probability is merely the number of this category divided by total number of samples.\n\\vfill\n\\clearpage\n%%---------------------------------------------------------------\n%% Problem 5\n%%---------------------------------------------------------------\n\\section{Problem 3.4}\n\\large{\\textbf{Solution}}: \\\\\n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\bm{\\theta}} &= \\arg\\max_{\\bm{\\theta}} \\ln P(\\bm{D}|\\bm{\\theta}) =  \\arg\\max_{\\bm{\\theta}} \\ln \\prod^n_{k=1}\\prod^d_{i=1}\\theta_i^{x_{ki}}(1-\\theta_i)^{1-x_{ki}}\\\\\n&=\\arg\\max_{\\bm{\\theta}} \\sum^n_{k=1}\\sum^d_{i=1}x_{ki}\\ln\\theta_i + (1-x_{ki})\\ln(1-\\theta_i)\n\\end{aligned}\n\\end{equation*}\nTaking the partial derivative with respect to $\\theta_i$ and equating to 0, we have:\n\\begin{equation*}\n\\begin{aligned}\n\\frac{1}{\\hat{\\theta_i}}\\sum_{k=1}^n x_{ki} - \\frac{1}{1-\\theta_i} \\sum_{k=1}^n (1-x_{ki}) =0\n\\end{aligned}\n\\end{equation*}\n\n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\theta_i} = \\frac{1}{n} \\sum_{k=1}^n x_{ki}\n\\end{aligned}\n\\end{equation*}\nTherefore the ML estimate for $\\bm{\\theta}$ is \n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\bm{\\theta}} = \\frac{1}{n} \\sum_{k=1}^n x_{k}\n\\end{aligned}\n\\end{equation*}\n\n%%---------------------------------------------------------------\n%% Problem 6\n%%---------------------------------------------------------------\n\\section{Problem 3.17}\n\\large{\\textbf{Solution}}: \\\\\n(a) For n $i.i.d$ samples $D=\\{\\bm{x}_1,...,\\bm{x}_n\\}$, we have:\n\n\\begin{equation*}\n\\begin{aligned}\nP(D|\\bm{\\theta})&=P(\\bm{x_1},...,\\bm{x_n}|\\bm{\\theta}) = \\prod_{k=1}^n P(x_k|\\bm{\\theta})\\\\ &= \\prod_{k=1}^n \\prod^d_{i=1} \\theta_i^{x_{ki}}(1-\\theta_i)^{1-x_{ki}} \\\\ &= \\prod^d_{i=1} \\theta_i^{\\sum_{k=1}^n x_{ki}}(1-\\theta_i)^{\\sum_{k=1}^n (1-x_{ki})}\\\\ &= \\prod^d_{i=1} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}\n\\end{aligned}\n\\end{equation*}\n\\noindent(b) With assumption that $\\bm{\\theta}$ is uniformly distributed, we have $P(\\bm{\\theta})=1$ for $0\\leq \\theta_i \\leq1,\\ i=1,...,d$. From Bayes' theorem we have:\n\\begin{equation*}\n\\begin{aligned}\nP(\\bm{\\theta}|D)&=\\frac{P(D|\\bm{\\theta})P(\\bm{\\theta})}{P(D)} =\\frac{P(D|\\bm{\\theta})P(\\bm{\\theta})}{\\int P(D|\\bm{\\theta})P(\\bm{\\theta})\\text{ d}\\bm{\\theta}}= \\frac{P(D|\\bm{\\theta})}{\\int P(D|\\bm{\\theta})\\text{ d}\\bm{\\theta}}\\\\\n&= \\frac{\\prod^d_{i=1} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}}{\\int \\prod^d_{i=1} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}\\text{ d}\\bm{\\theta}}\\\\\n&=\\frac{\\prod^d_{i=1} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}}{\\int_0^1 ... \\int_0^1 \\prod^d_{i=1} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}\\text{ d}\\theta_1...\\text{d}\\theta_d}\\\\\n&=\\prod_{i=1}^{d} \\frac{\\theta_i^{s_i}(1-\\theta_i)^{n-s_i}}{\\int_0^1 \\theta_i^{s_i}(1-\\theta_i)^{n-s_i}\\text{ d}\\theta_i}\\\\\n&=\\prod_{i=1}^{d} \\frac{\\theta_i^{s_i}(1-\\theta_i)^{n-s_i}}{\\frac{s_i!(n-s_i)!}{(n+1)!}}\\\\\n&=\\prod_{i=1}^{d} \\frac{(n+1)!}{s_i!(n-s_i)!}\\theta_i^{s_i}(1-\\theta_i)^{n-s_i}\\\\\n\\end{aligned}\n\\end{equation*}\n(c) Given $d=1,\\ n=1$, we have: \n\\begin{equation*}\n\\begin{aligned}\nP(\\theta|D)= \\frac{2!}{s_1!(1-s_1)!}\\theta^{s_1}(1-\\theta)^{1-s_1}\\\\\n\\end{aligned}\n\\end{equation*}\nNote that $s_1$ has two values 0 and 1, and the density for each of them:\n\\begin{equation*}\n\\begin{aligned}\n&s_1 = 0\\ :\\ P(\\theta|D)= 2(1-\\theta)\\\\\n&s_1 = 1\\ :\\ P(\\theta|D)= 2\\theta\\\\\n\\end{aligned}\n\\end{equation*}\nThe densities can be plotted with MATLAB as Figure 2.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 1\\textwidth]{pb317.png}\n\\caption{\\label{fig3}$P(x|\\theta)\\ versus\\ x\\ and\\ \\theta$}\n\\end{figure}\n%------------------------------------------------------------------------\n\\noindent(d) Since in Bernoulli case $x_i$ can be either 0 or 1, we have:\n\\begin{equation*}\n\\begin{aligned}\nP(\\bm{x}|D) &= \\int P(\\bm{x}|\\bm{\\theta}) P(\\bm{\\theta}|D)\\text{ d}\\bm{\\theta}\\\\ \n&=\\int \\prod_{i=1}^d\\theta_i^{x_i}(1-\\theta_i)^{1-x_i}\\prod_{i=1}^{d} \\frac{(n+1)!}{s_i!(n-s_i)!}\\theta_i^{s_i}(1-\\theta_i)^{n-s_i} \\text{ d}\\bm{\\theta}\\\\\n&=\\prod_{i=1}^d  \\frac{(n+1)!}{s_i!(n-s_i)!} \\int \\prod_{i=1}^d\\theta_i^{x_i}(1-\\theta_i)^{1-x_i} \\theta_i^{s_i}(1-\\theta_i)^{n-s_i} \\text{ d}\\bm{\\theta}\\\\\n&=\\prod_{i=1}^d  \\frac{(n+1)!}{s_i!(n-s_i)!} \\prod_{i=1}^d \\int \\theta_i^{x_i+s_i}(1-\\theta_i)^{n+1-x_i-s_i} \\\\\n&=\\prod_{i=1}^d  \\frac{(n+1)!}{s_i!(n-s_i)!} \\prod_{i=1}^d  \\frac{(x_i+s_i)!(n+1-x_i-s_i)!}{(n+2)!} \\\\\n&=\\prod_{i=1}^d  \\frac{(n+1)!(x_i+s_i)!(n+1-x_i-s_i)!}{s_i!(n-s_i)!(n+2)!} \\\\\n&=\\prod_{i=1}^d  \\frac{(x_i+s_i)!(n+1-x_i-s_i)!}{s_i!(n-s_i)!(n+2)} \\ \\ \\ \\ \\text{($x_i$ can be 0 or 1)}\\\\\n&=\\prod_{i=1}^d  (\\frac{(s_i+1)!(n-s_i)!}{s_i!(n-s_i)!(n+2)})^{x_i} (\\frac{s_i!(n+1-s_i)!}{s_i!(n-s_i)!(n+2)})^{1-x_i} \\\\\n&=\\prod_{i=1}^d  (\\frac{s_i+1}{n+2})^{x_i} (\\frac{n+1-s_i}{n+2})^{1-x_i} \\\\\n&=\\prod_{i=1}^d  (\\frac{s_i+1}{n+2})^{x_i} (1-\\frac{s_i+1}{n+2})^{1-x_i}\n\\end{aligned}\n\\end{equation*}\n\n\n\n\n\n%-----------------------------------------------------------------------\n\\noindent(e) Comparing the following two equations:\n\\begin{equation*}\n\\begin{aligned}\nP(\\bm{x}|D) = \\prod_{i=1}^d  (\\frac{s_i+1}{n+2})^{x_i} (1-\\frac{s_i+1}{n+2})^{1-x_i}\n\\end{aligned}\n\\end{equation*}\n\\begin{equation*}\n\\begin{aligned}\nP(\\bm{x}|\\bm{\\theta}) = \\prod_{i=1}^d\\theta_i^{x_i}(1-\\theta_i)^{1-x_i}\n\\end{aligned}\n\\end{equation*}\nwe have the effective Bayesian estimate for $\\bm{\\theta}$:\n\\begin{equation*}\n\\begin{aligned}\n\\hat{\\theta_i} = \\frac{s_i+1}{n+2}\n\\end{aligned}\n\\end{equation*}\n\n\n\\end{document}\n\n\n", "meta": {"hexsha": "bfed955df801b9c913c4ed83bb4cf32eea74d07e", "size": 10373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EECE5644-Introduction-to-Machine-Learning-and-Pattern-Recognition/Homework-2/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-2/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-2/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": 40.3618677043, "max_line_length": 306, "alphanum_fraction": 0.5682059192, "num_tokens": 4095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6026817003213157}}
{"text": "\\documentclass[t]{beamer}\n\\usetheme{Copenhagen}\n\\setbeamertemplate{headline}{} % remove toc from headers\n\\beamertemplatenavigationsymbolsempty\n\n\\usepackage{amsmath, bm, tcolorbox}\n\n\\title{Systems of Equations}\n\\author{}\n\\date{}\n\n\\AtBeginSection[]\n{\n  \\begin{frame}\n    \\frametitle{Objectives}\n    \\tableofcontents[currentsection]\n  \\end{frame}\n}\n\n\\begin{document}\n\n\\begin{frame} \n\\maketitle\n\\end{frame}\n\n\\section{Write a system of equations using matrices}\n\n\\begin{frame}{Matrix Multiplication}\nPreviously, we looked at the method for multiplying matrices:\n\\[\n\\begin{bmatrix}\n7\t&\t2\t&\t-1\t\\\\\n0\t&\t5\t&\t4\t\\\\\n-3\t&\t6\t&\t2\t\\\\\n\\end{bmatrix}\n\\cdot\n\\begin{bmatrix}\n2\t\\\\ 1 \\\\ 3 \\\\\n\\end{bmatrix}\n\\onslide<2->{= \\begin{bmatrix}\n13 \\\\ 17 \\\\ 6 \\\\\n\\end{bmatrix}}\n\\] \n\\onslide<3->{In this section, we will use matrix multiplication to solve a system of equations.}\n\\end{frame}\n\n\\begin{frame}\n\\begin{tcolorbox}[colframe=green!20!black, colback = green!30!white,title=\\textbf{System of Equations}]\nA \\textbf{system of equations} consists of 2 or more equations with 2 or more variables.\n\\end{tcolorbox}\n\\vspace{6pt}\n\\onslide<2->{\\textsc{Examples}}\n\\onslide<3->{\n\\begin{align*}\n2x + 5y &= 8 \\\\\n-7x - 3y &= 9 \\\\\n\\end{align*}\n\\begin{align*}\n4x-9y+2z &= 10 \\\\\n-x + z &= 15\t\\\\\n3x+10y-12z &= 0 \\\\\n\\end{align*}\n}\n\\end{frame}\n\n\\begin{frame}{Writing a System of Equations Using Matrices}\nWe can use matrix multiplication with the coefficients and variables to write a system of equations using matrices.\t\t\\newline\\\\\t\t\\pause\n\nSo\n\\begin{align*}\n2x + 5y &= 8 \\\\\n-7x - 3y &= 9 \\\\\n\\end{align*}\n\\onslide<3->{\nbecomes\n\\[\n\\begin{bmatrix}\n2\t&\t5\t\\\\\n-7\t&\t-3\t\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nx\t\\\\\ny\t\\\\\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n8\t\\\\\n9\t\\\\\n\\end{bmatrix}\n\\]}\n\\end{frame}\n\n\\begin{frame}{Writing a System of Equations Using Matrices}\nAnd \n\\begin{align*}\n4x-9y+2z &= 10 \\\\\n-x + z &= 15\t\\\\\n3x+10y-12z &= 0 \\\\\n\\end{align*}\n\\onslide<2->{\nbecomes\n\\[\n\\begin{bmatrix}\n4\t&\t-9\t&\t2\t\\\\\n-1\t&\t\\alert{0}\t&\t1\t\\\\\n3\t&\t10\t&\t-12\t\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nx\t\\\\\ny\t\\\\\nz\t\\\\\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n10\t\\\\\n15\t\\\\\n0\t\t\\\\\n\\end{bmatrix}\n\\]\n}\n\\end{frame}\n\n\\begin{frame}{Example 1}\nWrite each of the following systems of equations using matrices.\t\\newline\\\\\n(a)\t\\quad\n\\begin{align*}\n4y\t+ z &= -1 \\\\\n-4x - 5y + 5z &= 0 \\\\\n6x + 5y &= 25 \\\\\n\\end{align*}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\n0\t&\t4\t&\t1\t\\\\\n-4\t&\t-5\t&\t5\t\\\\\n6\t&\t5\t&\t0\t\\\\\n\\end{bmatrix}\n\\onslide<3->{\n\\begin{bmatrix}\nx \\\\ y \\\\ z \\\\\n\\end{bmatrix}\n}\n\\onslide<4->{\n= \\begin{bmatrix}\n-1 \\\\ 0 \\\\ 25 \\\\\n\\end{bmatrix}\n}\n\\]\n}\n\\end{frame}\n\n\\begin{frame}{Example 1}\n(b) \\quad \n\\begin{align*}\nx - y &= -9 \\\\\n-3x - 4y &= -8 \\\\\n\\end{align*}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\n1 & -1 \\\\\n-3 & -4 \\\\\n\\end{bmatrix}\n\\onslide<3->{\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n}\n\\onslide<4->{\n= \\begin{bmatrix}\n-9 \\\\ -8 \\\\\n\\end{bmatrix}\n}\n\\]\n}\n\\end{frame}\n\n\\section{Solve a system of equations using inverse matrices}\n\n\\begin{frame}{Solving Equations Using Inverse Operations}\nLong ago, you learned that to solve something like\n\\[ 5x = 10 \\]\nyou divide (the inverse operation of multiplication) both sides by 5.\t\\newline\\\\\t\\pause\n\nWe don't ``divide\" matrices in this sense, but we do need to use an inverse operation to solve the previous examples.\n\\end{frame}\n\n\\begin{frame}{Identity Matrices}\n\\begin{tcolorbox}[colframe=green!20!black, colback = green!30!white,title=\\textbf{Identity Matrix}]\nAn \\textbf{identity matrix} is a square matrix with 1s along the diagonal from top left to bottom right, and 0s elsewhere.\n\\end{tcolorbox}\n\\vspace{10pt}\t\\pause\n\\[\nI_2 = \\begin{bmatrix}\n1 & 0 \\\\\n0 & 1 \\\\\n\\end{bmatrix}\n\\quad\nI_3 = \\begin{bmatrix}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1 \\\\\n\\end{bmatrix}\n\\quad\n\\text{etc.}\n\\]\n\\end{frame}\n\n\\begin{frame}{Inverse Matrix}\n\\begin{tcolorbox}[colframe=green!20!black, colback = green!30!white,title=\\textbf{Inverse Matrix}]\nThe \\textbf{inverse matrix} for square matrix $A$ is $A^{-1}$.\n\\end{tcolorbox}\n\\vspace{10pt}\t\\pause\nInverse matrices are such that \n\\[\nA \\cdot A^{-1} = I\n\\]\t\\pause\nand that if $AX = B$ where $A$ is the matrix of coefficients and $B$ are the constants on the right side, then\n\\[\nX = A^{-1} \\cdot B\n\\]\n\\pause\n\\emph{Note:} We will not discuss the techniques of how to actually find the inverse of a matrix without a calculator.\n\\end{frame}\n\n\\begin{frame}{Example 2}\nSolve each of the following using matrices.\t\\newline\\\\\n(a) \\quad \n\\begin{align*}\n4y\t+ z &= -1 \\\\\n-4x - 5y + 5z &= 0 \\\\\n6x + 5y &= 25 \\\\\n\\end{align*}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\n0\t&\t4\t&\t1\t\\\\\n-4\t&\t-5\t&\t5\t\\\\\n6\t&\t5\t&\t0\t\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nx \\\\ y \\\\ z \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n-1 \\\\ 0 \\\\ 25 \\\\\n\\end{bmatrix}\n\\]\n}\n\\end{frame}\n\n\\begin{frame}{Example 2}\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\ z \\\\\n\\end{bmatrix}\n= A^{-1}B\n\\]\n\\pause \\vspace{6pt}\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\ z \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n5 \\\\ -1 \\\\ 3 \\\\\n\\end{bmatrix}\n\\]\n\\pause \\vspace{6pt}\n\\[x = 5, \\quad y = -1, \\quad z = 3\\]\n\\end{frame}\n\n\\begin{frame}{Example 2}\n(b) \\quad \n\\begin{align*}\nx - y &= -9 \\\\\n-3x - 4y &= -8 \\\\\n\\end{align*}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\n1 & -1 \\\\\n-3 & -4 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n-9 \\\\ -8 \\\\\n\\end{bmatrix}\n\\]\n}\n\\end{frame}\n\n\\begin{frame}{Example 2}\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n= A^{-1}B\n\\]\n\\pause \\vspace{6pt}\n\\[\n\\begin{bmatrix}\nx \\\\ y\n\\end{bmatrix}\n= \\begin{bmatrix}\n-4 \\\\ 5\n\\end{bmatrix}\n\\]\n\\pause \\vspace{6pt}\n\\[x = -4, \\quad y = 5\\]\n\\end{frame}\n\n\\begin{frame}{Example 2}\n(c) \\quad \n\\begin{align*}\nx - 3y - 5z &= -18 \\\\\n-2x + 3y + 5z &= 23 \\\\\n-x + 3y + 6z &= 17 \\\\\n\\end{align*}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\n1 & -3 & - 5 \\\\\n-2 & 3 & 5 \\\\\n-1 & 3 & 6 \\\\\n\\end{bmatrix}\n\\cdot\n\\begin{bmatrix}\nx \\\\ y \\\\ z \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n-18 \\\\ 23 \\\\ 17 \\\\\n\\end{bmatrix}\n\\]\n}\n\\end{frame}\n\n\\begin{frame}{Example 2}\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n= A^{-1}B\n\\]\n\\pause \\vspace{6pt}\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\ z\n\\end{bmatrix}\n= \\begin{bmatrix}\n-5 \\\\ 6 \\\\ -1 \\\\\n\\end{bmatrix}\n\\]\n\\pause \\vspace{6pt}\n\\[x = -5, \\quad y = 6, \\quad z = -1\\]\n\\end{frame}\n\n\n\\section{Solve applications of systems of equations}\n\n\\begin{frame}{Applied Systems of Equations}\nSetting up many applied systems of equations problems boils down to \n\\begin{center}\nunit rate $\\times$ amount = total amount\n\\end{center}\nFor instance, \\$2.00 per gallon times 5 gallons of gas costs a total amount of \\$10.\n\\end{frame}\n\n\\begin{frame}{Example 3}\n(a) \\quad How many mL of a solution containing 10\\% pure hydrochloric acid must be mixed with a solution containing 15\\% hydrochloric acid to produce 30 mL of a solution that is 11\\% hydrochloric acid?\t\\pause\t\\newline\\\\\n$x$ = mL of the 10\\% acid solution \\\\\n$y$ = mL of the 15\\% acid solution \\pause\n\\begin{align*}\nx + y &= 30 &\\text{volume of total liquid} \\\\\n0.10x + 0.15y &= 30(0.11) &\\text{volume of total hydrocholic acid} \\\\\n\\end{align*}\t\n\\end{frame}\n\n\\begin{frame}{Example 3}\n\\[\n\\begin{bmatrix}\n1\t&\t1\t\\\\\n0.1\t&\t0.15\t\\\\\n\\end{bmatrix}\n\\cdot \n\\begin{bmatrix}\nx \\\\ y \n\\end{bmatrix}\n= \\begin{bmatrix}\n30 \\\\ 3.3 \\\\\n\\end{bmatrix}\n\\]\n\\vspace{6pt}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n24 \\\\ 6 \\\\\n\\end{bmatrix}\n\\]\n}\n\\newline\\\\ \\pause\nWe need to mix 24 mL of a 10\\% hydrochloric acid solution with 6 mL of a 15\\% hydrochloric acid solution.\n\\end{frame}\n\n\\begin{frame}{Example 3}\n(b) \\quad A coffee shop wants to sell 8 pound bags of a coffee blend for \\$28.64. They will do this by blending coffee that costs \\$2.25 per pound with coffee that costs \\$4.00 per pound. How much of each type of coffee should they use in the blend?\t\\newline\\\\\t\\pause\n$x$ = number of pounds of cheaper coffee (\\$2.25 per pound) \\\\\n$y$ = number of pounds of more expensive coffee (\\$4.00 per pound) \\pause\n\\begin{align*}\nx + y &= 8  &\\text{weight of each bag} \\\\\n2.25x + 4.00y &= 28.64 &\\text{total cost} \\\\\n\\end{align*}\n\\end{frame}\n\n\\begin{frame}{Example 3}\n\\[\n\\begin{bmatrix}\n1\t&\t1\t\\\\\n2.25 & 4\t\\\\\n\\end{bmatrix}\n\\cdot \n\\begin{bmatrix}\nx \\\\ y \n\\end{bmatrix}\n= \\begin{bmatrix}\n8 \\\\ 28.64 \\\\\n\\end{bmatrix}\n\\]\n\\vspace{6pt}\n\\onslide<2->{\n\\[\n\\begin{bmatrix}\nx \\\\ y \\\\\n\\end{bmatrix}\n= \\begin{bmatrix}\n1.92 \\\\ 6.08 \\\\\n\\end{bmatrix}\n\\]\n}\n\\newline\\\\ \\pause\nThey will need 1.92 pounds of the cheaper coffee and 6.08 pounds of the more expensive coffee.\n\\end{frame}\n\n\\end{document}", "meta": {"hexsha": "f456245cce1a86f57b007b3a3ffaaa83dec7c830", "size": 8270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Systems_of_Equations(BEAMER).tex", "max_stars_repo_name": "BryanBain/HA2_BEAMER", "max_stars_repo_head_hexsha": "a5e021f12d3cdd0541353c9e121ff5e4df7decd1", "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": "Systems_of_Equations(BEAMER).tex", "max_issues_repo_name": "BryanBain/HA2_BEAMER", "max_issues_repo_head_hexsha": "a5e021f12d3cdd0541353c9e121ff5e4df7decd1", "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": "Systems_of_Equations(BEAMER).tex", "max_forks_repo_name": "BryanBain/HA2_BEAMER", "max_forks_repo_head_hexsha": "a5e021f12d3cdd0541353c9e121ff5e4df7decd1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-26T15:49:45.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-26T15:49:45.000Z", "avg_line_length": 18.5011185682, "max_line_length": 267, "alphanum_fraction": 0.6334945586, "num_tokens": 3231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.602678838736304}}
{"text": "\\section{$H^\\ast(BU(n))$, splitting principle}\\label{homology-bun}\n%I wanted to share some ideas about the question on the first nonzero homology group of an Eilenberg-MacLane space.\n%One idea was to use this extension $0\\to \\Z\\xar{p^k}\\Z\\to \\Z/p^k\\to 0$.\n%This gives rise to a fiber sequence $K(\\Z,n)\\to K(\\Z,n)\\to K(\\Z/p^k,n)\\to 0$.\n%You could maybe use the Serre spectral sequence here?\n%Another idea that came up was that this is embedded in a long sequence of fibrations, so that you have $K(\\Z,n)\\to K(\\Z,n)\\to K(\\Z/p^k, n) \\to K(\\Z,n+1)\\to\\cdots$.\n%\n%I'm really excited today -- it's more characteristic classes!\n%Last week, I gave you Grothendieck's construction of Chern classes:\n%if you have a complex $n$-plane bundle $\\xi\\downarrow X$, I described $\\PP(\\xi)$, which has a canonical tautologous line bundle $\\lambda_\\xi\\downarrow \\PP(\\xi)$.\n%This has an Euler class $e=e(\\lambda_\\xi)\\in H^2(\\PP(\\xi))$, and this satisfies the following unique relation:\n%$$\n%e^n+c_1e^{n-1} + \\cdots + c_n = 0\n%$$\n%Then $c_k\\in H^{2k}(X)$ are called the Chern classes.\n%\n%This doesn't give you much insight as to how to compute them.\nTheorem \\ref{chern-classes} claimed that the Chern classes, which we\nconstructed in the previous section, generate the cohomology of $BU$ as a\npolynomial algebra. Our goal in this section is to prove this result.\n\\subsection{The cohomology of $BU(n)$}\nRecall that $BU(n)$ supports the universal principal $U(n)$-bundle $EU(n)\\to\nBU(n)$. Given any left action of $U(n)$ on some space, we can form the\nassociated fiber bundle. For instance, the associated bundle of the\n$U(n)$-action on $\\cC^n$ yields the universal line bundle $\\xi_n$.\n\nLikewise, the associated bundle of the action of $U(n)$ on $S^{2n-1}\\subseteq\n\\cc^n$ is the unit sphere bundle $S(\\xi_n)$, the unit sphere bundle. By\nconstruction, the fiber of the map $EU(n)\\times_{U(n)}S^{2n-1}\\to BU(n)$ is\n$S^{2n-1}$. Since\n$$S^{2n-1} = U(n)/(1\\times U(n-1)),$$\nwe can write\n$$EU(n)\\times_{U(n)}S^{2n-1} \\simeq EU(n)\\times_{U(n)} (U(n)/U(n-1)) \\simeq\nEU(n)/U(n-1) = BU(n-1).$$\nIn other words, $BU(n-1)$ is the unit sphere bundle of the tautologous line\nbundle over $BU(n)$. This begets a fiber bundle:\n$$S^{2n-1}\\to BU(n-1)\\to BU(n),$$\nwhich provides an inductive tool (via the Serre spectral sequence) for\ncomputing the homology of $BU(n)$. In \\S \\ref{gysin-sequence}, we observed that\nthe Serre spectral sequence for a spherical fibration was completely described\nbythe Gysin sequence.\n\nRecall that if $B$ is oriented and $S^{2n-1}\\to E\\xar{\\pi} B$ is a spherical\nbundle over $B$, then the Gysin sequence was a long exact sequence\n$$\n\\cdots\\to H^{q-1}(E) \\xar{\\pi_\\ast} H^{q-2n}(B) \\xar{e\\cdot} H^q(B) \\xar{\\pi^\\ast} H^q(E) \\xar{\\pi_\\ast} \\cdots\n$$\nLet us assume that the cohomology ring of $E$ is polynomial and concentrated in\neven dimensions. For the base case of the induction, both these assumptions are\nsatisfied (since $BU(0) = \\ast$ and $BU(1) = \\CP^\\infty$).\n\nThese assumptions imply that if $q$ is even, then the map $\\pi_\\ast$ is zero.\nIn particular, multiplication by $e|_{H^\\mathrm{even}(B)}$ (which we will also\ndenote by $e$) is injective, i.e., $e$ is a nonzero divisor.  Similarly, if $q$\nis odd, then $e\\cdot H^{q-2n}(B) = H^q(B)$. But if $q=1$, then $H^{q-2n}(B) =\n0$; by induction on $q$, we find that $H^\\mathrm{odd}(B) = 0$. Therefore, if\n$q$ is even, then $H^{q-2n+1}(B) = 0$. This implies that there is a short exact\nsequence\n\\begin{equation}\\label{inductive-step-cohomology}\n    0\\to H^\\ast(B) \\xar{e\\cdot} H^\\ast(B) \\to H^\\ast(E) \\to 0.\n\\end{equation}\nIn particular, the cohomology of $E$ is the cohomology of $B$ quotiented by the\nideal generated by the nonzero divisor $e$.\n\nFor instance, when $n=1$, then $B=\\CP^\\infty$ and $E\\simeq \\ast$. We have the\ncanonical generator $e\\in H^2(\\CP^\\infty)$; these deductions tell us the\nwell-known fact that $H^\\ast(\\CP^\\infty) \\simeq \\Z[e]$.\n\nConsider the surjection $H^\\ast(B) \\xar{\\pi^\\ast} H^\\ast(E)$. Since $H^\\ast(E)$\nis polynomial, we can lift the generators of $H^\\ast(E)$ to elements of\n$H^\\ast(B)$. This begets a splitting $s:H^\\ast(E) \\to H^\\ast(B)$. The existence\nof the Euler class $e\\in H^\\ast(B)$ therefore gives a map $H^\\ast(E)[e]\n\\xar{\\overline{s}} H^\\ast(B)$. We claim that this map is an isomorphism.\n\nThis is a standard algebraic argument. Filter both sides by powers of $e$,\ni.e., take the $e$-adic filtration on $H^\\ast(E)[e]$ and $H^\\ast(B)$. Clearly,\nthe associated graded of $H^\\ast(E)[e]$ just consists of an infinite direct sum\nof the cohomology of $E$. The associated graded of $H^\\ast(B)$ is the same,\nthanks to the short exact sequence \\eqref{inductive-step-cohomology}. Thus the\ninduced map on the associated graded $\\gr^\\ast(\\overline{s})$ is an\nisomorphism. In this particular case (but not in general), we can conclude that\n$\\overline{s}$ is an isomorphism: in any single dimension, the filtration is\nfinite. Thus, using the five lemma over and over again, we see that the map\n$\\overline{s}$ an isomorphism on each filtered piece. This implies that\n$\\overline{s}$ itself is an isomorphism, as desired.\n\t\nThis argument proves that\n$$H^\\ast(BU(n-1)) = \\Z[c_1,\\cdots,c_{n-1}].$$\nIn particular, there is a map $\\pi^\\ast:H^\\ast(BU(n)) \\to H^\\ast(BU(n-1))$\nwhich an isomorphism in dimensions at most $2n$. Thus, the generators $c_i$\nhave \\emph{unique} lifts to $H^\\ast(BU(n))$. We therefore get:\n\\begin{theorem}\n    There exist classes $c_i\\in H^{2i}(BU(n))$ for $1\\leq i\\leq n$ such that:\n    \\begin{itemize}\n\t\\item the canonical map $H^\\ast(BU(n)) \\xar{\\pi_\\ast} H^\\ast(BU(n-1))$\n\t    sends\n\t    $$\n\t    c_i \\mapsto \\begin{cases}\n\t\tc_i & i<n\\\\\n\t\t0 & i=n,\\text{ and }\n\t    \\end{cases}\n\t    $$\n\t\\item $c_n := (-1)^n e\\in H^{2n}(BU(n))$.\n    \\end{itemize}\n    Moreover,\n    $$\\boxed{H^\\ast(BU(n)) \\simeq \\Z[c_1,\\cdots,c_n]}.$$\n\\end{theorem}\n\\subsection{The splitting principle}\n\\begin{theorem}\\label{splitting-principle}\n    Let $\\xi\\downarrow X$ be an $n$-plane bundle. Then there exists a space\n    $\\Fl(\\xi) \\xar{\\pi} X$ such that:\n    \\begin{enumerate}\n\t\\item $\\pi^\\ast \\xi = \\lambda_1\\oplus\\cdots\\lambda_n$, where the\n\t    $\\lambda_i$ are line bundles on $Y$, and\n\t\\item the map $\\pi^\\ast: H^\\ast(X) \\to H^\\ast(\\Fl(\\xi))$ is monic.\n    \\end{enumerate}\n\\end{theorem}\n\\begin{proof}\n    We have already (somewhat) studied this space. Recall that there is a\n    vector bundle $\\pi:\\PP(\\xi)\\to X$ such that\n    $$H^\\ast(\\PP(\\xi)) = H^\\ast(X)\\langle 1,e,\\cdots,e^{n-1}\\rangle.$$\n    Moreover, in \\S \\ref{grothendieck-chern}, we proved that there is a complex\n    line bundle over $\\PP(\\xi)$ which is a subbundle of $\\pi^\\ast\\xi$. In other\n    words, $\\pi^\\ast\\xi$ splits as a sum of a line bundle and some other bundle\n    (by Corollary \\ref{split}). Iterating this construction proves the\n    existence of $\\Fl(\\xi)$.\n\\end{proof}\nThis proof does not give much insight into the structure of $\\Fl(\\xi)$.\nRemember that the \\emph{frame bundle} $\\Fr(\\xi)$ of $\\xi$: an element of\n$\\Fr(\\xi)$ is a linear, inner-product preserving map $\\cC^n\\to E(\\xi)$.\nThis satisfies various properties; for instance:\n$$E(\\xi) = \\Fr(\\xi)\\times_{U(n)}\\cC^n.$$\nMoreover,\n$$\\PP(\\xi) = \\Fr(\\xi)\\times_{U(n)} U(n)/(1\\times U(n-1)).$$\n\nThe \\emph{flag bundle} $\\Fl(\\xi)$ is defined to be\n$$\\Fl(\\xi) = \\Fr(\\xi)\\times_{U(n)} U(n)/(U(1)\\times\\cdots\\times U(1)).$$\nThe product $U(1)\\times\\cdots\\times U(1)$ is usually denoted $T^n$, since it is\nthe maximal torus in $U(n)$. For the universal bundle $\\xi_n\\downarrow BU(n)$,\nthe frame bundle is exactly $EU(n)$; therefore, $\\Fl(\\xi_n)$ is just the bundle\ngiven by $BT^n\\to BU(n)$. By construction, the fiber of this bundle is\n$U(n)/T^n$. In particular, there is a monomorphism $H^\\ast(BU(n))\n\\hookrightarrow H^\\ast(BT^n)$. The cohomology of $BT^n$ is extremely simple ---\nit is the cohomology of a product of $\\CP^\\infty$'s, so\n$$H^\\ast(BT^n) \\simeq \\Z[t_1,\\cdots,t_n],$$\nwhere $|t_k| = 2$. The $t_i$ are the Euler classes of $\\pi_i^\\ast\\lambda_i$,\nunder the projection map $\\pi_i:BT^n\\to\\CP^\\infty$.\n", "meta": {"hexsha": "89cac7e77d95b35dd1b34ac51138778becc757bb", "size": 7997, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-71-homology-of-BUn.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-71-homology-of-BUn.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-71-homology-of-BUn.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": 54.0337837838, "max_line_length": 164, "alphanum_fraction": 0.6761285482, "num_tokens": 2728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.602678838736304}}
{"text": "\\section{Linear algebra}\n\nLike in many methods which solve the Schr\\\"odinger equation, linear algebra plays a critical role in QMC algorithms and thus is crucial to the performance of QMCPACK.\nThere are a few components in QMCPACK use BLAS/LAPACK with their own characteristics.\n\n\\subsection{Real space QMC}\n\\subsubsection{Single particle orbitals}\nSpline evaluation as commonly used in solid-state simulations does not use any dense linear algebra library calls.\nLCAO evaluation as commonly used in molecular calculations relies on BLAS2 GEMV to compute SPOs from a basis set.\n\n\\subsubsection{Slater determinants}\nSlater determinants are calculated on $N \\times N$ Slater matrices. $N$ is the number of electrons for a given spin.\nIn the actually implementation, operations on the inverse matrix of Slater matrix for each walker dominate the computation.\nTo initialize it, DGETRF and DGETRI from LAPACK are called. The inverse matrix can be stored out of place.\nDuring random walking, inverse matrices are updated by either Sherman-Morrison rank-1 update or delayed update.\nUpdate algorithms heavily relies on BLAS. All the BLAS operations require S,C,D,Z cases.\n\nSherman-Morrison rank-1 update uses BLAS2 GEMV and GER on $N \\times N$ matrices.\n\nDelayed rank-K update uses\n\\begin{itemize}\n  \\item BLAS1 SCOPY on $N$ array.\n  \\item BLAS2 GEMV, GER on $k \\times N$ and $k \\times k$ matrices. $k$ ranges from 1 to $K$ when updates are delayed and accumulated.\n  \\item BLAS3 GEMM at the final update.\n    \\begin{itemize}\n       \\item 'T', 'N', K, N, N\n       \\item 'N', 'N', N, K, K\n       \\item 'N', 'N', N, N, K\n    \\end{itemize}\n\\end{itemize}\nThe optimal K depends on the hardware but it usually ranges from 32 to 256.\n\nQMCPACK solves systems with a few to thousands of electrons. To make all the BLAS/LAPACK operation efficient on accelerators.\nBatching is needed and optimized for $N < 2000$. Non-batched functions needs to be optimized for $N > 500$.\nNote: 2000 and 500 are only rough estimates.\n\n\\subsubsection{Wavefunction optimizer}\nto be added.\n\n\\subsection{Auxiliary field QMC}\n\nThe AFQMC implementation in QMCPACK relies heavily on linear algebra operations from BLAS/LAPACK. The performance of the code is netirely dependent on the performance of these libraries. See below for a detailed list of the main routines used from BLAS/LAPACK. Since the AFQMC code can work with both single and double precision builds, all 4 versions of these routines (S,C,D,Z) are generally needed, for this reason we omit the data type label.\n\n\\begin{itemize}\n \\item BLAS1: SCAL, COPY, DOT, AXPY\n \\item BLAS2: GEMV, GER\n \\item BLAS3: GEMM\n \\item LAPACK: GETRF, GETRI, GELQF, UNGLQ, ORGLQ, GESVD, HEEVR, HEGVX\n\\end{itemize}\n\nWhile the dimensions of the matrix operations will depend entirely on the details of the calculation, typical matrix dimensions range from the 100s, for small system sizes, to over 20000 for the largest calculations attempted so far.\nFor builds with GPU accelerators, we make use of batched and strided implementations of these routines. Batched implementations of GEMM, GETRF, GETRI, GELQF and UNGLQ are particularly important for the performance of the GPU build on small to medium size problems. Batched implementations of DOT, AXPY and GEMV would also be quite useful, but they are not yet generally available.\nOn GPU builds, the code uses batched implementations of these routines when available by default.\n", "meta": {"hexsha": "cfcb9c1e7150a374a84fd7178ad4352a14188162", "size": 3428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "legacy_manual/linear_algebra.tex", "max_stars_repo_name": "djstaros/qmcpack", "max_stars_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "legacy_manual/linear_algebra.tex", "max_issues_repo_name": "djstaros/qmcpack", "max_issues_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "legacy_manual/linear_algebra.tex", "max_forks_repo_name": "djstaros/qmcpack", "max_forks_repo_head_hexsha": "280f67e638bae280448b47fa618f05b848c530d2", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.4814814815, "max_line_length": 446, "alphanum_fraction": 0.778588098, "num_tokens": 882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.6757645879592642, "lm_q1q2_score": 0.6026543178285003}}
{"text": "This chapter contains little more advanced but still short example programs. Wonder how these programs work? Go figure!\n\n\\section{Quick Sort}\n\nPrerequisites: Array, Function, Recursion, Closure\n\n\\begin{lstlisting}\n10 QSORT = [XS] ~> IF LEN(XS) < 1 THEN NIL ELSE \n    QSORT(FILTER([X] ~> X <  HEAD XS, TAIL XS)) # HEAD(XS)!NIL # \n    QSORT(FILTER([X] ~> X >=HEAD XS, TAIL XS))\n100 L={7,9,4,5,2,3,1,8,6}\n110 PRINT L\n120 PRINT QSORT(L)\n\\end{lstlisting}\n\n\\section{Fast Fibonacci Sequence}\n\nPrerequisites: Array, Function, Recursion, Closure, Monad\n\n\\begin{lstlisting}\n10 FIB_=[N,M] ~> IF LEN(MJOIN(M)) >= N THEN HEAD(MJOIN(M)) ELSE\n    FIB_(N,M >>= ([XS] ~> MRET((XS(0) + XS(1)) ! XS)))\n11 FIB = [N] ~> FIB_(N, MRET({1,1}))\n100 FOR K = 1 TO 10\n110 PRINT FIB(K);\" \";\n120 NEXT\n\\end{lstlisting}\n\n\\section{Count The Length of Chunks}\n\nPrerequisites: Array, Function, Recursion\n\n\\begin{lstlisting}\n10 DEFUN F(STR,XS) = IF (XS == UNDEFINED) THEN F(STR, {})\n   ELSE IF (LEN(STR) == 0) THEN XS\n   ELSE F(RIGHT(STR, LEN(STR) - 1),\n      IF (LEN(XS) == 0) THEN XS ~ {LEFT(STR, 1), 1}\n      ELSE IF (XS(LEN(XS) - 1, 0) >< LEFT(STR, 1)) THEN XS ~ {LEFT(STR, 1), 1}\n      ELSE INIT(XS) ~ {LEFT(STR, 1), 1 + XS(LEN(XS) - 1, 1)}\n   )\n100 PAIRS = F(\"aaaabbbccaxyzzy\")\n110 PRINT PAIRS\n\\end{lstlisting}\n", "meta": {"hexsha": "af380a806ba9a62a7b4bfaa6afae9a57fb59d0a9", "size": 1281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/exercise.tex", "max_stars_repo_name": "curioustorvald/TerranBASIC", "max_stars_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-03T02:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-03T02:33:52.000Z", "max_issues_repo_path": "src/doc/exercise.tex", "max_issues_repo_name": "curioustorvald/TerranBASIC", "max_issues_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-25T23:39:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-25T23:39:15.000Z", "max_forks_repo_path": "src/doc/exercise.tex", "max_forks_repo_name": "curioustorvald/TerranBASIC", "max_forks_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_forks_repo_licenses": ["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.1136363636, "max_line_length": 119, "alphanum_fraction": 0.6307572209, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.6513548511303338, "lm_q1q2_score": 0.6026530169342967}}
{"text": "\\documentclass[./Thesis.tex]{subfiles}\n\\begin{document}\n\n\\chapter{Primality}\n\\label{chap:primality}\n\n\\epigraph{\n  3 is prime, 5 is prime, 7 is prime. By induction, all the odd integers are\n  prime.\n}{\\cite{leroy}}\nIn this chapter we will explore various proof relevant definitions of primality.\nThen we will construct a decision procedure for these definitions via the\nstandard brute force primality algorithm.\n\\begin{code}[hide]\n  module Primality where\n  open import AKS.Nat using (ℕ; zero; suc; _+_; _∸_; _*_; _≤_; _<_; lte; _<?_; _≟_)\n  open import AKS.Nat using (auto-≤; <⇒≱; n≮n; ≤-<-trans; m≤m+n; ≢⇒¬≟; suc-injective-≤; ≤-refl) renaming (n≤m⇒n<m⊎n≡m to n≤m⇒n<m∨n≡m)\n  open import AKS.Nat using (<-irrefl; <-cmp; <-trans; n<1+n; 0<1+n)\n  open import AKS.Nat using (Acc; acc; <-well-founded; Interval; [_,_∣_]; ⊂-well-founded; _⊂_; upward)\n  open import Data.Nat.Properties using (*-identityˡ; *-comm; *-assoc; *-zeroʳ; *-distribʳ-∸; m+n∸n≡m)\n  open import AKS.Nat.Divisibility using (_/_; Euclidean✓; _div_)\n  open import Relation.Nullary using (¬_)\n  open import Relation.Nullary.Decidable using (False; True; from-yes; from-no)\n  open import Relation.Nullary.Negation using (contradiction)\n  open import Relation.Binary using (Reflexive; Transitive; Tri)\n  open Tri\n  open import Relation.Binary.PropositionalEquality\n    using (_≡_; _≢_; module ≡-Reasoning)\n    renaming (refl to ≡-refl; sym to ≡-sym; cong to ≡-cong; cong₂ to ≡-cong₂)\n  open import Data.Empty using (⊥; ⊥-elim)\n  open import Data.Unit using (tt)\n  open import Data.Sum using (inj₁; inj₂)\n  open import Function using (_$_) -- $\n  open ≡-Reasoning\n\\end{code}\n\\section{Divisibility}\n\\label{sec:divisibility}\nBefore we can define primality we require a definition of divisibility. We\nfollow a standard definition of divisibility, namely a natural number $d$\ndivides into another natural $a$ iff there exists some $q$ such that $a = q d$.\n\\begin{code}[hide]\n  infix 3 _∣_\n\\end{code}\n\\begin{code}\n  record _∣_ (d : ℕ) (a : ℕ) : Set where\n    constructor divides\n    field\n      quotient : ℕ\n      equality : a ≡ quotient * d\n\n  _∤_ : ℕ → ℕ → Set\n  d ∤ a = ¬ (d ∣ a)\n\\end{code}\nIn order to make a decision procedure for primality we first require a decision\nprocedure for divisibility. This would have to be a proof relevant algorithm. An\nalgorithm that would take two natural numbers and produce either a proof of\ndivisibility or a proof of non-divisibility. This is no small task, one which\nwill become easier with the correct lemmas. We first prove that the divisibility\nrelation is reflexive, that is that for any $n$ the expression\n$n \\, \\AgdaFunction{∣} \\, n$ is true. After which we will prove that the\ndivisibility relation is transitive. \n\\begin{code}\n  ∣-refl : Reflexive _∣_\n  ∣-refl {n} = divides 1 $ begin n ≡⟨ ≡-sym (*-identityˡ n) ⟩ 1 * n ∎\n\\end{code} % $\n\\begin{code}\n  ∣-trans : Transitive _∣_\n  ∣-trans {x} {y} {z} (divides q₁ y≡q₁*x) (divides q₂ z≡q₂*y) = divides (q₂ * q₁) $\n    z ≡⟨ z≡q₂*y ⟩\n    q₂ * y ≡⟨ ≡-cong (λ t → q₂ * t) y≡q₁*x ⟩\n    q₂ * (q₁ * x) ≡⟨ ≡-sym (*-assoc q₂ q₁ x) ⟩\n    (q₂ * q₁) * x ∎\n\\end{code} % $\nAs \\Agda{} is a proof relevant logic, every proof of divisibility materializes\nsimilarly. The user simply specifies what number to multiply the divisor by to\nget the dividend. Then they supply a proof that the two numbers do indeed multiply\nto the dividend. It the following proof we assume a divisibility relation is\ntrue. We ``consume'' the divisibility relation.\nSpecifically we consider when $0$ divides another number. The only number $0$\ndivides is $0$ itself.\n\\begin{code}\n  0∣n⇒n≡0 : ∀ {n} → 0 ∣ n → n ≡ 0\n  0∣n⇒n≡0 {n} (divides q n≡q*0) = begin\n    n ≡⟨ n≡q*0 ⟩\n    q * 0 ≡⟨ *-zeroʳ q ⟩\n    0 ∎\n\\end{code}\nThe following two lemmas have simple proofs, so we leave the proofs to the\nreader. The first lemma shows that the divisibility relation respects equality\nin its second argument and the second lemma shows that some number $m$ will\ndivide a number if it has $m$ as a factor.\n\\begin{code}\n  ∣-respʳ : ∀ {i n m} → n ≡ m → i ∣ n → i ∣ m\n\n  m∣m*n : ∀ {n m} → m ∣ m * n\n\\end{code}\n\\begin{code}[hide]\n  ∣-respʳ {i} {n} {m} n≡m (divides q n≡q*i) =\n    divides q $ begin\n      m ≡⟨ ≡-sym n≡m ⟩\n      n ≡⟨ n≡q*i ⟩\n      q * i ∎\n\n  m∣m*n {n} {m} = divides n $ begin m * n ≡⟨ *-comm m n ⟩ n * m ∎\n\\end{code}\nThis proof shows is the ``reverse'' of the idea that if a number $i$ divides two\nnumbers $m$ and $n$ then it must divide their sum. This because $i$ is a common\nfactor of the two numbers. If $n + m = q_1 i$ and $m = q_2 i$ then it follows\nthat $n = (q_1 - q_2) * i$. Note that $q_1 \\geq q_2$ as $q_1$ contains $q_2$. This\nis important in the following \\Agda{} proof as the type $\\AgdaDatatype{ℕ}$ does\nnot contain negative numbers. There is a subtraction like function commonly\ncalled ``monus'' that returns $0$ when the difference is negative. This is\ndenoted as $\\AgdaFunction{∸}$ in \\Agda{} and it behaves similarly to subtraction in many\nproofs.\n\\begin{code}\n  ∣n+m∣m⇒∣n : ∀ {i n m} → i ∣ n + m → i ∣ m → i ∣ n\n  ∣n+m∣m⇒∣n {i} {n} {m} (divides q₁ n+m≡q₁*i) (divides q₂ m≡q₂*i) =\n    divides (q₁ ∸ q₂) $ begin\n      n               ≡⟨ ≡-sym (m+n∸n≡m n m) ⟩\n      (n + m) ∸ m     ≡⟨ ≡-cong₂ (λ x y → x ∸ y) n+m≡q₁*i m≡q₂*i ⟩\n      q₁ * i ∸ q₂ * i ≡⟨ ≡-sym (*-distribʳ-∸ i q₁ q₂) ⟩\n      (q₁ ∸ q₂) * i   ∎\n\\end{code} % $\nThis final lemma reduces many proofs about divisibility into proofs about\ninequalities. This lemma occurs multiple times in the following sections and\nchapters. The key idea is that if $n$ divides $m$ then it must be less than or\nequal to $m$ in order to be a factor. Technically this is false when $m = 0$ as\nevery number divides $0$. So we just assume $m \\neq 0$. This proof illustrates\nthe importance of choosing definitions correctly. Using the definition\n$\\exists k. \\, n + k = m$ of $n \\leq m$ makes this proof almost trivial. An\ninductive definition of $n \\leq m$ would complicate this proof by a large measure.\n\\begin{code}\n  ∣⇒≤ : ∀ {n m} → m ≢ 0 → n ∣ m → n ≤ m\n  ∣⇒≤ {n} {zero} m≢0 (divides q m≡q*n) = contradiction ≡-refl m≢0\n  ∣⇒≤ {n} {suc m} m≢0 (divides (suc q) m≡[1+q]*n) =\n    lte (q * n) $ begin\n      n + q * n ≡⟨⟩\n      suc q * n ≡⟨ ≡-sym m≡[1+q]*n ⟩\n      suc m     ∎\n\\end{code} % $\nWith the lemmas out of the way we have one last bookkeeping task. What is the\ncorrect type of decision procedures? A proof relevant decision procedure should\nreturn not just the truth value of the predicate the user is testing. It should\nalso return a proof that the predicate is true or a proof that the predicate is\nfalse. These cases are mutually exclusive so we can represent this idea with the\nfollowing datatype. Note this type can be used generically in decision producers\nover any proposition $P$.\n\\begin{code}[hide]\n  module Decidable where\n\\end{code}\n\\begin{code}\n    data Dec (P : Set) : Set where\n      yes :   P → Dec P\n      no  : ¬ P → Dec P\n\\end{code}\n\\begin{code}[hide]\n  open import Relation.Nullary using (Dec; yes; no)\n\\end{code}\nThe full decision procedure begins by checking if the divisor is $0$. If the\ndivisor is $0$, then we ensure the dividend is $0$ as $0$ only divides $0$.\n\\begin{code}\n  _∣?_ : ∀ (d a : ℕ) → Dec (d ∣ a)\n  d ∣? a with d ≟ 0\n  d ∣? a | yes ≡-refl with a ≟ 0\n  d ∣? a | yes ≡-refl | yes ≡-refl = yes ∣-refl\n  d ∣? a | yes ≡-refl | no a≢0 = no λ 0∣a → contradiction (0∣n⇒n≡0 0∣a) a≢0\n\\end{code}\nIf the divisor is not $0$, then we can divide the dividend by the divisor. If\nthe integer remainder of that division is $0$, then the divisor divides the\ndividend. Otherwise the divisor can not divide the dividend as the remainder is\nstrictly less than the divisor.\n\\begin{code}\n  d ∣? a | no d≢0 with (a div d) {≢⇒¬≟ d≢0}\n  d ∣? a | no d≢0 | Euclidean✓ q r pf r<d with r ≟ 0\n  d ∣? a | no d≢0 | Euclidean✓ q r pf r<d | yes ≡-refl =\n    yes $ divides q $ begin\n      a ≡⟨ pf ⟩\n      0 + d * q ≡⟨⟩\n      d * q ≡⟨ *-comm d q ⟩\n      q * d ∎\n\\end{code}\n\\begin{code}\n  d ∣? a | no d≢0 | Euclidean✓ q r pf r<d | no r≢0 = no ¬d∣a\n\\end{code}\n\\begin{code}[hide]\n    where\n\\end{code}\nIn this $\\AgdaInductiveConstructor{no}$ case we must prove that the divisor\ndividing the dividend leads to a contradiction. All proofs to a contradiction\nstart with assuming truth, so we assume that the divisor does divide the\ndividend $d \\, \\AgdaFunction{∣} \\, a$. We show this contradiction by producing a\nproof that $d \\leq r$.\n\\begin{code}\n    ¬d∣a : d ∣ a → ⊥\n    ¬d∣a d∣a = contradiction d≤r (<⇒≱ r<d)\n\\end{code}\n\\begin{code}[hide]\n      where\n\\end{code}\nOur division algorithm returns a proof of correctness namely that $a = r + dq$.\nWe substitute $a$ with $r + dq$ in our assumption of $d \\mid a$. Then we remove\nthe $d * q$ term from the sum as $d$ trivially divides it. Lastly we transform\nour divisibility relation into an inequality as the remainder is not zero.\nThis illustrates the contradiction and the decision procedure is complete.\n\\begin{code}\n      d∣r+d*q : d ∣ r + d * q\n      d∣r+d*q = ∣-respʳ pf d∣a\n\n      d∣r : d ∣ r\n      d∣r = ∣n+m∣m⇒∣n d∣r+d*q m∣m*n\n\n      d≤r : d ≤ r\n      d≤r = ∣⇒≤ r≢0 d∣r\n\\end{code}\n\\section{Investigating Definitions}\n\\label{sec:investigating-definitions}\nThere are many isomorphic definitions of primality. Unfortunately not all\ndefinitions are equal in the eyes of \\Agda{}. For instance, consider the\nfollowing definition, ``A prime number is a natural number greater than $1$ that\nhas no prime divisors smaller then itself.''. This definition translates\ndirectly into \\Agda{} as shown below.\n\\begin{code}[hide]\n  module Primality₁ where\n    {-# NO_POSITIVITY_CHECK #-}\n\\end{code}\n\\begin{code}\n    record IsPrime (p : ℕ) : Set where\n      inductive\n      constructor IsPrime✓\n      field\n        1<p : 1 < p\n        ∀i[i∤p] : ∀ {i} → i < p → IsPrime i → i ∤ p\n\\end{code}\nThis definition has one critical flaw, it is refused by \\Agda{}. The type is\nrecursively defined but the recursion is in \\textit{negative} position\n\\cite{harper}. This means the recursion occurs in the domain of a function type.\nAllowing recursive calls in negative position makes your logic inconsistent.\nConsider the following code and note that $\\AgdaDatatype{Bad}$ has a recursive\ncall in negative position.\n\\begin{code}[hide]\n  {-# NO_POSITIVITY_CHECK #-}\n\\end{code}\n\\begin{code}\n  data Bad : Set where\n    Bad✓ : (Bad → ⊥) → Bad\n\n  Bad-false : Bad → ⊥\n  Bad-false (Bad✓ b) = b (Bad✓ b)\n\n  Bad-true : Bad\n  Bad-true = Bad✓ Bad-false\n\n  false : ⊥\n  false = Bad-false Bad-true\n\\end{code}\nNote how similar $\\AgdaFunction{false}$ is to the non-terminating\n\\textit{omega combinator} shown in \\ref{eqn:omega}. The only difference is the required\nwrapping and unwrapping of $\\AgdaDatatype{Bad}$ values. Unlike the type\n$\\AgdaDatatype{Bad}$, the type $\\AgdaDatatype{IsPrime}$ given above is actually a safe\nuse of negative recursion. Convincing \\Agda{} of this fact is quite hard and\noutside the scope of this thesis.\n\\begin{align}\n  \\label{eqn:omega}\n  \\Omega = (\\lambda x. \\, x \\, x) (\\lambda x. \\, x \\, x)\n\\end{align}\nWe can remove the recursion by considering when a number can divide a prime. If\nsome number divides a prime then that number is either $1$ or the prime itself.\nThis leads to a non-recursive definition of primality. A natural number is prime\nwhen it is greater than $1$ and its only divisors are $1$ and itself.\n\\begin{code}[hide]\n  module Primality₂ where\n    infixr 3 _or_\n    data _or_ (A : Set) (B : Set) : Set where\n\\end{code}\n\\begin{code}\n    record IsPrime (p : ℕ) : Set where\n      constructor IsPrime✓\n      field\n        1<p : 1 < p\n        ∀i∣p[i≡p] : ∀ {i} → i ∣ p → i ≡ 1 or i ≡ p\n\\end{code}\nThe definition above is usable, but in the following sections most of the proofs\nwill know $1 < i$ for relevant instantiations of $i$. Thus the definition\ngenerates many superfluous cases where the user must show $i = 1$ is impossible.\nSo we bake the fact that $i$ must be greater than $1$ into the definition. This\nyields our final definition.\n\\begin{code}\n  record IsPrime (p : ℕ) : Set where\n    constructor IsPrime✓\n    field\n      1<p : 1 < p\n      ∀i∣p[i≡p] : ∀ {i} → 1 < i → i ∣ p → i ≡ p\n\\end{code}\nUsing this definition we can prove specific natural numbers are prime by hand.\n\\begin{code}\n  3-isPrime : IsPrime 3\n  3-isPrime = IsPrime✓ (from-yes (1 <? 3)) 3-primality\n\\end{code}\n\\begin{code}[hide]\n    where\n\\end{code}\nIn order to prove $3$ is a prime we need to show that any divisor $i$ of $3$ is\nequal to $3$. To accomplish this we perform a case analysis on $i$. \\Agda{} can\ninfer that $i = 0, 1$ are impossible cases so we do not have to fill them out.\nThe case $i = 2$ is impossible as $2 \\nmid 3$ and we can illustrate this fact by\nrunning the decision procedure for divisibility on $2$ and $3$. Finally any\ninput of the form $4 + i$ will not divide $3$ as it will be too large.\n\\begin{code}\n    3-primality : ∀ {i} → 1 < i → i ∣ 3 → i ≡ 3\n    3-primality {suc (suc zero)} _ 2∣3 = contradiction 2∣3 (from-no (2 ∣? 3))\n    3-primality {suc (suc (suc zero))} _ i∣3 = ≡-refl\n    3-primality {suc (suc (suc (suc i)))} _ i∣3 = contradiction 3<3 n≮n\n\\end{code}\n\\begin{code}[hide]\n      where\n\\end{code}\n\\begin{code}\n      3+i<3 : 3 + i < 3\n      3+i<3 = ∣⇒≤ (λ ()) i∣3\n\n      3<3 : 3 < 3\n      3<3 = ≤-<-trans m≤m+n 3+i<3\n\\end{code}\nThis rote work does outline a decision procedure for primality of a number $n$. Test every\nnumber between $2$ and $n - 1$ for divisibility with $n$. If any of the numbers\ndivide $n$ return false, but what does falsehood represent in this instance?\nIn this case it implies that the number is a\ncomposite. So we define another predicate $\\AgdaDatatype{IsComposite}$. A number\nis composite if it has a smaller prime factor. Note every composite number is\nguaranteed by the fundamental theorem of arithmetic to have a a prime factor. \n\\begin{code}\n  record IsComposite (c : ℕ) : Set where\n    constructor IsComposite✓\n    field\n      p : ℕ\n      p<c : p < c\n      p-isPrime : IsPrime p\n      p∣c : p ∣ c\n\\end{code}\nNotice how proving compositionality reduces to proving primality.\n\\begin{code}\n  6-isComposite : IsComposite 6\n  6-isComposite = IsComposite✓ 3 (from-yes (3 <? 6)) 3-isPrime (from-yes (3 ∣? 6))\n\\end{code}\n\\section{A Decision Procedure}\n\\label{sec:a-decision-procedure}\nAs always we require a couple lemmas before we can get into the heart of the\ndecision procedure. First there is no prime less than $2$, this fact is almost\nbaked into the definition. Second we prove that a number $n$ can not be both prime and\ncomposite. As the number is composite it has some prime factor, but as the\nnumber is prime that divisor must be equal to itself. The factor is defined to\nbe less than itself and we reach a contradiction.\n\\begin{code}\n  ¬prime<2 : ∀ p → p < 2 → ¬ (IsPrime p)\n  ¬prime<2 p p<2 (IsPrime✓ 2≤p _) = contradiction 2≤p (<⇒≱ p<2)\n\\end{code}\n\\begin{code}\n  exclusive : ∀ {n} → IsPrime n → IsComposite n → ⊥\n  exclusive {n}\n    (IsPrime✓ 1<n ∀i∣n⇒i≡n)\n    (IsComposite✓ p p<n (IsPrime✓ 1<p _) p∣n)\n    = contradiction p<n p≮n\n\\end{code}\n\\begin{code}[hide]\n    where\n\\end{code}\n\\begin{code}\n    p≮n : ¬ (p < n)\n    p≮n = <-irrefl (∀i∣n⇒i≡n 1<p p∣n)\n\\end{code}\nAs we are working in a proof relevant setting, the types\n$\\AgdaDatatype{IsComposite} \\, n$ and\n$\\AgdaFunction{¬} (\\AgdaDatatype{IsPrime}\\, n)$ do not carry the same amount of\ninformation. The first type knows exactly one factor of $n$ while the\nsecond type knows no factors. Therefore instead of writing a decision procedure\nfor prime or not prime, we write a decision procedure for prime or composite. The\nlater can be easily transformed into the former as will be shown at the end of the\nchapter. Therefore we construct a type that can return a proof of primality or\ncompositionality.\n\\begin{code}\n  data Primality (n : ℕ) : Set where\n    Composite✓ : IsComposite n → Primality n\n    Prime✓ : IsPrime n → Primality n\n\\end{code}\nUnfortunately our final $\\AgdaDatatype{IsPrime}$ type is difficult to construct.\nThis is because the type has ``forgotten'' that every number less than itself\ncan not divide itself. Luckily the original inconsistent definition of primality\nremembers the divisibility of all numbers less than itself. We can break the\nnegative recursion by using the current definition of primality in the negative\nposition. We create a new return type that has this definition inlined into\nitself. Thus the algorithm proceeds as follows. We test all prime divisors of\n$n$ and store them in $\\AgdaDatatype{Compositionality}$ then we convert a\n$\\AgdaDatatype{Compositionality}$ into a $\\AgdaDatatype{Primality}$.\n\\begin{code}\n  data Compositionality (n : ℕ) : Set where\n    Composite✓ : IsComposite n → Compositionality n\n    Prime✓ : (∀ {p} → p < n → IsPrime p → p ∤ n) → Compositionality n\n\\end{code}\nIn practice this algorithm is actually mutually recursive as in order to generate\na $\\AgdaDatatype{Compositionality}$ you need to generate smaller\n$\\AgdaDatatype{IsPrime}$ proofs.\n\\begin{code}\n  compositionality : ∀ n → 1 < n → Acc _<_ n → Compositionality n\n  primality : ∀ n → 1 < n → Acc _<_ n → Primality n\n\\end{code}\n\\begin{code}\n  compositionality n 1<n (acc downward)\n    = loop 2 (from-yes (1 <? 2)) 1<n ⊂-well-founded ¬p<2[p∤n]\n\\end{code}\n\\begin{code}[hide]\n    where\n\\end{code}\nWe store these smaller primes in a list encoded with continuation passing style.\nThe following code is an analog to the nil list case. As there are no primes\nless than $2$, this makes a good empty list.\n\\begin{code}\n    ¬p<2[p∤n] : ∀ {p} → p < 2 → IsPrime p → p ∤ n\n    ¬p<2[p∤n] {p} p<2 p-isPrime _ = contradiction p-isPrime (¬prime<2 p p<2)\n\\end{code}\nNext we need to construct an analog to append. If we have a list of prime\ndivisibility up to but not including $x$ and a proof that $x$ does not\ndivide $n$. Then we can construct a list of prime divisibility including $x$. This\nproof proceeds by comparing $p$ and $x$ using a trichotomous comparison.\n\\begin{code}\n    cons\n      : ∀ {x}\n      → (IsPrime x → x ∤ n)\n      → (∀ {p} → p < x → IsPrime p → p ∤ n)\n      → (∀ {p} → p < 1 + x → IsPrime p → p ∤ n)\n    cons {x} x-isPrime⇒x∤n ∀p<x⇒p∤n {p} p<1+x p-isPrime p∣n with <-cmp p x\n    ... | tri< p<x _ _ = contradiction p∣n (∀p<x⇒p∤n p<x p-isPrime)\n    ... | tri≈ _ ≡-refl _ = contradiction p∣n (x-isPrime⇒x∤n p-isPrime)\n    ... | tri> _ _ x<p = contradiction (suc-injective-≤ p<1+x) (<⇒≱ x<p)\n\\end{code}\nFollowing this proof, we construct the main divisibility testing loop. We count upwards from\n$x = 2$\nuntil we reach $n$ using the accessibility predicate defined at the end of chapter\n\\ref{chap:termination}. We recursively test the primality of $x$. If $x$ is\ncomposite then there is no reason to test divisibility as the prime factor of\n$x$ will have been tested previously in the loop. If $x$ is prime then we test if\n$x$ divides $n$ using the divisibility decision procedure defined earlier in the\nchapter. If $x$ divides $n$ then we immediately return with a proof that $n$ has\na prime divisor. Otherwise we add $x$ into the list and recurse.\n\\begin{code}\n    loop\n      : ∀ x → 1 < x → (x≤n : x ≤ n) → Acc _⊂_ [ x , n ∣ x≤n ]\n      → (∀ {p} → p < x → IsPrime p → p ∤ n)\n      → Compositionality n\n    loop x 1<x x≤n (acc next) ∀p<x⇒p∤n with n≤m⇒n<m∨n≡m x≤n\n    ... | inj₂ ≡-refl = Prime✓ ∀p<x⇒p∤n\n    ... | inj₁ x<n with primality x 1<x (downward x<n)\n    ...   | Composite✓ x-isComposite\n          = loop (1 + x) (<-trans 1<x n<1+n) x<n (next [1+x,n]⊂[x,n]) ∀p<1+x⇒p∤n\n            where\n            [1+x,n]⊂[x,n] : [ 1 + x , n ∣ x<n ] ⊂ [ x , n ∣ x≤n ]\n            [1+x,n]⊂[x,n] = upward n<1+n ≤-refl\n            ∀p<1+x⇒p∤n = cons (λ x-isPrime _ → exclusive x-isPrime x-isComposite) ∀p<x⇒p∤n\n    ...   | Prime✓ x-isPrime with x ∣? n\n    ...     | yes x∣n = Composite✓ (IsComposite✓ x x<n x-isPrime x∣n)\n    ...     | no ¬x∣n = loop (1 + x) (<-trans 1<x n<1+n) x<n (next [1+x,n]⊂[x,n]) ∀p<1+x[p∤n]\n            where\n            [1+x,n]⊂[x,n] : [ 1 + x , n ∣ x<n ] ⊂ [ x , n ∣ x≤n ]\n            [1+x,n]⊂[x,n] = upward n<1+n ≤-refl\n            ∀p<1+x[p∤n] = cons (λ _ x∣n → ¬x∣n x∣n) ∀p<x⇒p∤n\n\\end{code}\nNow we transform compositionalities into primalities. If the number is\ncomposite then we can simply return the same proof. Otherwise we need to\ntransform our continuation passing style list into our final primality condition.\n\\begin{code}\n  primality n 1<n wf@(acc downward) with compositionality n 1<n wf\n  ... | Composite✓ isComposite = Composite✓ isComposite\n  ... | Prime✓ ∀p<n⇒p∤n = Prime✓ (IsPrime✓ 1<n ∀i∣n⇒i≡n)\n\\end{code}\n\\begin{code}[hide]\n    where\n    n≢0 : n ≢ 0\n    n≢0 n≡0 = <-irrefl (≡-sym n≡0) (<-trans 0<1+n 1<n)\n\\end{code}\nTo do this we must handle any possible divisor $i$ of $n$. First we\ntrichotomously compare $i$ and $n$. If $i$ is larger than $n$ we immediately run\ninto a familiar contradiction. If $i$ is equal to $n$ then we are done and we\nreturn the proof that they are equal, and if $i$ is less than $n$ we\nrecursively call our decision procedure on $i$. If $i$ is prime then we have\nreached a contradiction as we have a list of all the primes less than $n$ and\nthey do not divide $n$. If $i$ is composite then it has a prime divisor that\ntransitively divides $n$ and we have reached a contradiction.\n\\begin{code}\n    ∀i∣n⇒i≡n : ∀ {i} → 1 < i → i ∣ n → i ≡ n\n    ∀i∣n⇒i≡n {i} 1<i i∣n with <-cmp i n\n    ... | tri> _ _ n<i = contradiction (∣⇒≤ n≢0 i∣n) (<⇒≱ n<i)\n    ... | tri≈ _ i≡n _ = i≡n\n    ... | tri< i<n _ _ with primality i 1<i (downward i<n)\n    ...   | Prime✓ i-isPrime\n          = contradiction i∣n (∀p<n⇒p∤n i<n i-isPrime)\n    ...   | Composite✓ (IsComposite✓ p p<i p-isPrime p∣i)\n          = contradiction (∣-trans p∣i i∣n) (∀p<n⇒p∤n (<-trans p<i i<n) p-isPrime)\n\\end{code}\nAfter ensuring that our number is greater than $1$, we can invoke\n$\\AgdaFunction{primality}$ and finish our primality decision procedure.\n\\begin{code}\n  prime? : ∀ n → Dec (IsPrime n)\n  prime? n with 1 <? n\n  ... | no ¬1<n = no λ { (IsPrime✓ 1<n _) → ¬1<n 1<n }\n  ... | yes 1<n with primality n 1<n <-well-founded\n  ... | Prime✓ isPrime = yes isPrime\n  ... | Composite✓ isComposite = no λ { isPrime → exclusive isPrime isComposite }\n\\end{code}\n\n\\end{document}\n", "meta": {"hexsha": "cc757b1db728ba7a9869540ca049fbf9ae77b778", "size": 22118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Primality.lagda.tex", "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_issues_repo_path": "tex/Primality.lagda.tex", "max_issues_repo_name": "mckeankylej/thesis", "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_issues_repo_licenses": ["MIT"], "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/Primality.lagda.tex", "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": ["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.368627451, "max_line_length": 133, "alphanum_fraction": 0.6603219098, "num_tokens": 7780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6025631680834561}}
{"text": "\\section{``Euler's theorem'', and ``homology approximation'' - CTC Wall. I) Singular homology, II) CW complexes, III) ``homological algebra''}\n\\begin{theorem}[``Euler'']\nLet $X$ be a space which admits the structure of a finite CW complex. The sum $\\sum_{h=0}^\\infty (-1)^k\\#(k\\text{-cells})$ (generalizes $V-E+F$) is independent of that structure.\n\\end{theorem}\n\\begin{proof}\nPick a CW-structure. We have $0\\to C_n\\to\\cdots\\to C_2\\to C_1\\to C_0\\to 0$. We also have a sexseq $0\\to Z_k\\to C_k\\to B_{k-1}\\to 0$, and another one $0\\to B_k\\to Z_k\\to H_k\\to 0$. Let's use them and facts about rank that I talked about on Monday to compute what this alternating sum is. The Euler sum is the same as:\n\\begin{align*}\n\\sum_{h=0}^\\infty (-1)^k\\#(k\\text{-cells}) & = \\sum^\\infty_{k=0}(-1)^k\\rank(C_k)\\\\\n& = \\sum^\\infty_{k=0}(-1)^k\\rank(Z_k)+\\sum^\\infty_{k=0}(-1)^k\\rank(B_{k-1})\\\\\n& = \\sum^\\infty_{k=0}(-1)^k(\\rank( H_k)+\\rank(B_k)+\\rank(B_{k-1}))\n\\end{align*}\nThe terms $\\rank B_k+\\rank B_{k+1}$ telescope because it's an alternating sum, and hence vanish. The sum is $\\sum^\\infty_{k=0}(-1)^k\\rank( H_k)$. But $ H_k(X)= H_k^\\text{sing}(X)$ is an invariant of the space, independent of the CW-structure.\n\\end{proof}\nGiven $ H_k(X)$, $X$ a finite type CW-complex, what's a lower bound on the number of $k$-cells? Let's see. $ H_k(X)$ is finitely generated because $C_k(X)\\subseteq Z_k(X)$ is, and it surjects onto $ H_k(X)$. Thus $ H_k(X)=\\bigoplus^{t(k)}_{i=1}\\Z/n_i(k)\\Z\\oplus \\Z^{r(k)}$ where the $n_1(k)|\\cdots|n_{t(k)}(k)$ are the torsion indices.\n\nThe minimal chain complex with $ H_k=\\Z$ and $ H_q=0$ for $q\\neq k$ is just the chain complex with $0$ everywhere else except for $\\Z$ in the $k$th degree. The minimal chain complex with $ H_k=\\Z/n\\Z$ and $ H_q=0$ for $q\\neq k$ is just the chain complex with $0$ everywhere else except for $\\Z\\xrightarrow{n}\\Z$ in dimension $k+1$ to $k$. These things are called elementary chain complexes.\n\nA lower bound on the minimal number of $k$-cells is $r(k)+t(k)+t(k-1)$ where the last term comes for the ``torsion generator in dimension $k-1$'' (didn't catch that).\n\\begin{theorem}[Wall]\nLet $X$ be a simply connected CW-complex of finite type. Then there exists a CW complex $Y$ with $r(k)+t(k)+t(k-1)$ $k$-cells, for all $k$, and a homotopy equivalence $Y\\to X$.\n\\end{theorem}\nI'm not going to prove this theorem. You can read Wall's theorem. You really can't ask for more. Oh, also here's a theorem.\n\\begin{theorem}\nLet $X$ be connected and pointed $\\ast\\in X$. Then $\\pi_1(X,\\ast)\\to H_1(X,\\ast)$ exists, called the Hurewicz homomorphism, and it factors as $\\pi_1(X,\\ast)\\to \\pi_1(X,\\ast)^{ab}\\to H_1(X,\\ast)$. The last map is an isomorphism.\n\\end{theorem}\nSome examples of Wall's theorem:\n\\begin{example}\nWe know that $S^k$ has $\\widetilde{ H}_q(X)=\\Z$ when $q=k$ and $0$ else. Can you construct a space with $\\widetilde{ H}_q(X)=\\Z/n\\Z$ when $q=k$ and $0$ else? We need to construct a space with the elementary chain complex with $0$ everywhere else except for $\\Z\\xrightarrow{n}\\Z$ in dimension $k+1$ to $k$. You need to have one $0$-cell, do nothing until you get to dimension $k$, which is when you add a $k$-cell, and then use the attaching map $S^k\\to S^k$ of degree $n$, i.e.:\n\\begin{equation*}\n\\xymatrix{S^k\\ar[r]^{\\text{degree }n}\\ar[d] & S^k\\ar[d]\\\\\nD^{k+1}\\ar[r] & X}\n\\end{equation*}\nFor example, when $k=1$ and $n=2$, you have $\\RP^2$. This is called a ``Moore space''.\n\\end{example}\nI brought up doing this in more generality with generators and relations, and Professor Miller built up on that:\n\\begin{example}\nFor more general abelian groups, you have a free abelian group $F_0$ sitting in a sexseq $0\\to F_1\\to F_0\\to M\\to 0$ (this is an example of a \\emph{resolution of $M$}, which is what I'm going to start talking about). Then $F_1$ is also free. Pick some $k>0$. You get a space whose homology is $F_0$, namely $\\bigvee_\\alpha S^k$, and a space whose homology is $F_1$, namely $\\coprod S^k$. You can construct a map $\\coprod S^k\\to \\bigvee_\\alpha S^k$ such that the map $\\alpha:F_1\\to F_0$ is what's induced on homology. Then you get:\n\\begin{equation*}\n\\xymatrix{\\coprod S^k\\ar[r]^{\\text{gives }\\alpha}\\ar[d] & \\bigvee_\\alpha S^k\\ar[d]\\\\\n\\coprod D^{k+1}\\ar[r] & X}\n\\end{equation*}\nSuch an $X$ is called a Moore space, and has homology $M$ in dimension $k$ and zero everywhere else. You can't make this into a functor, i.e., this can't be made into a functor $\\mathbf{Ab}\\to\\mathbf{Top}$.\n\\end{example}\n\\subsection{Homological algebra}\nYou can put coefficients into homology. Let $M$ an abelian group. You can talk about homology with coefficients in $M$. For example, $M=\\Z,\\QQ,\\Z/n\\Z,\\cdots$. The $\\Z/n\\Z$ case when $n$ is prime is pretty important because it's then a field.\n\nGiven $X$, you get a singular simplicial set $\\Sin_\\ast(X)$. Then we took the free abelian group $S_\\ast$ generated by $\\Sin_\\ast(X)$. I.e., $S_n=\\Z[\\Sin_n(X)]=\\bigoplus_{\\Sin_n(X)}\\Z$. But I could replace $\\Z$ with anything I wanted, and do the \\emph{exact} same construction. I can just as well as put any abelian group here.\n\nDefine the ``singular chain complex with coefficients in $M$'' as $S_n(X;M)=\\bigoplus_{\\Sin_n(X)}M$. There's a boundary map $d:S_n(X;M)\\to S_{n-1}(X;M)$. Then the homology $ H(S_\\ast(X;M))=: H_\\ast(X;M)$. You can verify all the Eilenberg-Steenrod axioms yourself, except for one, namely the dimension axiom - $ H_k(\\ast;M)=\\begin{cases}M & k=0 \\\\ 0 & k\\neq 0\\end{cases}$.\n\nIf you think about it, you'll realize that this whole unit in CW-complexes didn't use anything except for the Eilenberg-Steenrod axioms. This shows, by the way, that if you get some weird homology theory satisfying the Eilenberg-Steenrod axioms you get all the same results as if you used what we constructed before.\n\nAs an experiment, let's compute $ H_\\ast(\\RP^n;\\Z/2\\Z)$. The cellular chain complex is $0\\to \\Z/2\\Z\\to\\cdots\\to\\Z/2\\Z\\to\\Z/2\\Z\\to 0$ where the maps are alternately multiplying by $2$ and $0$. But in this case, all the maps are $0$ because $2=0$! So $ H_k(\\RP^n;\\Z/2\\Z)=\\begin{cases}\\Z/2\\Z & 0\\leq k\\leq n \\\\ 0 & \\text{else}\\end{cases}$. How about $ H_\\ast(\\RP^n;\\QQ)$? Or $ H_\\ast(\\RP^n;\\Z[\\frac{1}{p}])$ where $\\Z[\\frac{1}{p}]\\subseteq \\QQ$? What about $\\Z_{(p)}\\subseteq \\QQ$ where you've localized at $p$?\n\nAnyway, if I consider $ H_\\ast(\\RP^n;\\Z[\\frac{1}{2}])$, then the cellular chain complex simplifies, but in a different way. You have $0\\to \\Z[\\frac{1}{2}] \\to\\cdots\\to \\Z[\\frac{1}{2}] \\to \\Z[\\frac{1}{2}] \\to 0$. Multiplication by $2$, however, is an isomorphism. So, $ H_k(\\RP^n;\\Z[\\frac{1}{2}])=\\begin{cases}\\Z[\\frac{1}{2}] & q=0,n,\\, q \\text{ odd} \\\\ 0 & \\text{else}\\end{cases}$. You get a much simpler result. From this point of view, even projective spaces look like a point, and odd projective spaces look like a sphere!\n\nIt's a little awkward to go through this thing. I'd like to understand:\n\\begin{question}\nHow is $ H_\\ast(X;M)$ related to $ H_\\ast(X)= H_\\ast(X;\\Z)$? This is a reasonable question.\n\\end{question}\nThe answer is called the ``universal coefficient theorem''. I'll spend a few days developing what we need to talk about this.\n\nI want to talk about tensor products. Let me take a poll. Do you know tensor products? Working with a commutative ring instead of $\\Z$? Actually, all of these examples $M=\\Z,\\QQ,\\Z/n\\Z,\\Z[\\frac{1}{p}]\\subseteq\\QQ\\supseteq\\Z_{(p)},\\cdots$ are rings. The boundary map $d:S_n(X;M)\\to S_{n-1}(X;M)$ is a module homomorphism if $M=R$ is a (\\emph{always commutative}) ring.\n\nThis means that if $R$ is a commutative ring, then $ H_\\ast(X;R)$ is an $R$-module. If $R$ is a ring and $M$ is an $R$-module, then $ H_\\ast(X;M)$ is an $R$-module. Just look at what you have here. The $\\bigoplus_{\\Sin_n(X)}M$ is an $R$-module, and $d$ is an $R$-module homomorphism.\n\nI'll admit, this is a little bit scary, because commutative rings are pretty complicated in general. I won't talk about some weirdo rings, though. I'll develop this more on Friday. Let me pass out homework.\n", "meta": {"hexsha": "86776a38e92e69c0a940e7dd9dee600f9a262eb9", "size": 7980, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-19-eulers-thm.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-19-eulers-thm.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-19-eulers-thm.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": 117.3529411765, "max_line_length": 530, "alphanum_fraction": 0.6893483709, "num_tokens": 2741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6025631662713972}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{December exercises}\n\n\\subsection{Exercise 10}\n\nWe have a time series of \\(N\\) data points, \\(D = \\qty{d_i}\\), corresponding to the times \\(t_i\\), which are separated by the constant spacing \\(\\Delta \\).\n\nWe model them as \n%\n\\begin{align}\nd_i = \\underbrace{B_1  \\cos(\\omega t_i) + B_2 \\sin(\\omega t_i)}_{f(t_i)} + n_i\n\\,,\n\\end{align}\n%\nwhere \\(f(t)\\) the signal we want to characterize, which depends on the unknown amplitudes \\(B_1 \\) and \\(B_2 \\) and the unknown frequency \\(\\omega \\); while \\(n_i \\) is the noise: each \\(n_i\\) is i.i.d.\\ as a zero-mean Gaussian with known variance \\(\\sigma^2\\). \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/signal.pdf}\n\\caption{Example of a portion of the signal the model assumes; the true signal should be longer than a few periods, and it is taken to be 20 times as long as this in the numerical examples which follow. The parameters are \\(B_1 = 1/2\\), \\(B_2 = \\sqrt{3} /2\\), \\(\\sigma = 0.2\\), \\(\\Delta = 1\\), \\(\\omega = 0.015\\).}\n\\label{fig:signal}\n\\end{figure}\n\n\\subsubsection{The full likelihood}\n\nThe likelihood of a single datum of index \\(i\\) attaining the value \\(d_i\\) is given\\footnote{Omitting the dependence on previous information for simplicity.} by \n%\n\\begin{align}\n\\mathscr{L} (d_i | \\omega , B_1 , B_2 ) = \\frac{1}{\\sqrt{2 \\pi } \\sigma }\\exp(- \\frac{1}{2 \\sigma^2}\\qty(d_i - f(t_i))^2)\n\\,.\n\\end{align}\n\nNow, since the noise at each point is independent, the full likelihood is the product of the likelihoods of each datum: \n%\n\\begin{align}\n\\mathscr{L}(D | \\omega , B_1 , B_2 ) &= \\frac{1}{(\\sqrt{2 \\pi } \\sigma )^{N}} \\prod_{i=1}^{N} \\exp(- \\frac{1}{2 \\sigma^2} \\qty(d_i - f(t_i))^2)  \\\\\n&= \\frac{1}{(\\sqrt{2 \\pi } \\sigma )^{N}}\n\\exp(- \\frac{1}{2 \\sigma^2} \\sum_{i=1}^{N} \\qty(d_i - f(t_i))^2) \\\\\n&= \\frac{1}{(\\sqrt{2 \\pi } \\sigma )^{N}}\n\\exp(- \\frac{1}{2 \\sigma^2} \\underbrace{\\sum_{i=1}^{N} \\qty(d_i - B_1  \\cos(\\omega t_i) - B_2 \\sin(\\omega t_i))^2}_{Q}) \n\\,.\n\\end{align}\n\nLet us manipulate the sum in the exponent, which we denote as \\(Q\\): \n%\n\\begin{align}\nQ &= \\sum _{i} d_i^2 -2 \\sum _i d_i \\qty(B_1  \\cos(\\omega t_i) + B_2 \\sin(\\omega t_i))\n+ \\sum _{i} \\qty(B_1  \\cos(\\omega t_i) + B_2 \\sin(\\omega t_i))^2  \\\\\n\\begin{split}\n&= N \\overline{d}^2 \n-2 B_1 \\underbrace{\\sum _{i} d_i \\cos(\\omega t_i)}_{R_1(\\omega )}\n-2 B_2 \\underbrace{\\sum _{i} d_i \\sin(\\omega t_i)}_{R_2(\\omega )} + \\\\\n&\\phantom{=}\\ \n+ B_1^2 \\underbrace{\\sum _{i} \\cos^2( \\omega t_i)}_{c}\n+ B_2^2 \\underbrace{\\sum _{i} \\sin^2( \\omega t_i)}_{s}\n+ 2 B_1 B_2 \\sum _{i} \\cos(\\omega t_i) \\sin(\\omega t_i) \n\\end{split}  \\\\\n&= N \\overline{d}^2 - 2 B_1 R_1(\\omega ) -2 B_2 R_2(\\omega ) + B_1^2 c + B_2 s + B_1 B_2 \\underbrace{\\sum _{i} \\sin(2 \\omega t_i)}_{h}\n\\,.\n\\end{align}\n\n\\subsubsection{Large pulsation limit}\n\nThe condition we ask of our signal is to have many data points for each period (\\(\\Delta \\ll \\omega^{-1}\\)) and many sampled periods (\\(N \\Delta  \\gg \\omega^{-1}\\)), which is equivalent to \\((N \\Delta )^{-1 } \\ll \\omega \\ll \\Delta^{-1} \\).\n\nThe values of \\(c\\), \\(s\\) and \\(h\\) for various values of \\(\\omega \\) are shown in figure \\ref{fig:large_pulsation}.\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/large_pulsation}\n\\caption{Values of \\(c\\), \\(s\\) and \\(h\\) for different orders of magnitude of \\(\\omega \\). The sampling frequency is fixed at \\(\\Delta^{-1} = 1\\), and \\(N=500\\) points are always sampled. The conditions we ask, in the context of this plot, would mean that we put ourselves roughly in the middle of the two marked vertical lines, in the region \\(\\omega \\sim \\num{e-1}\\).} \n\\label{fig:large_pulsation}\n\\end{figure}\n\n% However, as we can see in figure \\ref{fig:large_pulsation}, the three functions do not really \\emph{converge} to those values, and stating something like ``\\(\\lim_{\\omega \\to \\infty } c = N /2\\)'' would be incorrect mathematically.\n% This is due to the presence of \\emph{resonance}: if the ratio \\(\\omega \\Delta \\) is a rational multiple of \\(\\pi \\), especially with a small denominator, there will be a bias in the points sampled, resulting in values which may range all the way from 0 to \\(N\\) for \\(c\\) and \\(s\\), and from \\(-N\\) to \\(N\\) for \\(h\\). \n% This should not really be an issue in realistic cases, as the set of points for which happens has measure zero. \n\n% Really, working in the \\(\\omega \\gg \\Delta^{-1}\\) regime is not wise, since we will necessarily have aliasing in the measured signal, as we are trying to measure a signal well above the Nyquist frequency of our sampler.\n\n% Fortunately, there is a regime in the region \\(\\omega \\lesssim \\Delta^{-1}\\) where the approximation we are discussing works well, and there are no aliasing issues. \n\nLet us then assume that we are working in that region. Then, denoting the argument of the functions as \\(x_i = \\omega t_i \\mod 2 \\pi \\), we will have: \n%\n\\begin{align}\nc = \\sum _{i=1}^{N} \\cos^2 x_i &\\approx N \\expval{\\cos^2 x}_{\\text{period}} = \\frac{N}{2} \\\\\ns = \\sum _{i=1}^{N} \\sin^2 x_i &\\approx N \\expval{\\sin^2 x}_{\\text{period}} = \\frac{N}{2} \\\\\nh = \\sum _{i=1}^{N} \\sin (2 x_i) &\\approx N \\expval{\\sin (2x)}_{\\text{period}} = 0 \n\\,,\n\\end{align}\n%\nsince \\(x\\) will be approximately uniformly distributed in the \\([0, 2\\pi )\\) interval.\nThe figure also shows this; the small deviations from these values are due to non-integer amounts of periods being included in the sample, but this is an edge effect, which becomes negligible as \\(N\\) becomes very large.\n\n\\subsubsection{Marginalization}\n\nWith these simplifications, the likelihood looks like \n%\n\\begin{align}\n\\mathscr{L}(D | \\omega , B_1 , B_2 ) &= \\frac{1}{(\\sqrt{2 \\pi } \\sigma )^{N}}\n\\exp(- \\frac{Q}{2 \\sigma^2})  \\\\\nQ &= \nN \\overline{d}^2 - 2 B_1 R_1(\\omega ) -2 B_2 R_2(\\omega ) + B_1^2 \\frac{N}{2} + B_2 \\frac{N}{2}  \\\\\n&= N \\qty(\\overline{d}^2 + \\frac{B_1^2 + B_2^2}{2}) - 2 B_1 R_1(\\omega ) - 2 B_2 R_2(\\omega )\n\\,.\n\\end{align}\n\nThe posterior is proportional to the likelihood, since we are assuming the priors on \\(\\omega \\) and \\(B_i\\) are uniform. \nWe wish to marginalize it over the parameters \\(B_i \\in \\mathbb{R}\\), for \\(i = 1, 2\\).\nThis amounts to solving the integral \n%\n\\begin{align}\nP (\\omega | D) &\\propto \\int_{\\mathbb{R}^2} \\dd{B_1 } \\dd{B_2 } P (\\omega , B_1 , B_2  | D)   \\\\\n&\\propto \\int_{\\mathbb{R}^2} \\dd{B_1 } \\dd{B_2 }\n\\exp(- \\frac{N}{2 \\sigma^2} \\qty(\\underbrace{\\overline{d}^2}_{\\text{constant}} + \\frac{B_1^2 + B_2^2}{2} - 2 B_1 R_1(\\omega ) -2  B_2 R_2(\\omega )))  \\\\\n&\\propto \\int_{\\mathbb{R}^2} \\dd{B_1} \\dd{B_2 } \\exp(- \\frac{1}{2 \\sigma^2} \\qty( \\sum _{i} \\frac{N B_i^2}{2} - 2 B_i R_i)) \\\\\n&\\propto \\prod_i \\int_{\\mathbb{R}} \\dd{B_i}\n\\exp(- \\frac{N B_i^2}{4 \\sigma^2} + \\frac{B_i R_i}{\\sigma^2})  \\\\\n&\\propto \\prod_i \\sqrt{ \\frac{\\pi}{N / (4 \\sigma^2)}}\n\\exp( \\frac{R_i^2}{\\sigma^{4}} \\frac{1}{4} \\frac{4 \\sigma^2 }{N})  \\\\\n&\\propto N^{-1} \\prod_i \\exp( \\frac{R_i^2}{\\sigma^2 N})  \\\\\n&\\propto N^{-1} \\exp(\\frac{R_1^2(\\omega ) + R_2^2(\\omega )}{\\sigma^2 N})\n\\,.\n\\end{align}\n\nIn the last step we have used the usual expression for a univariate Gaussian integral \\eqref{eq:single-variable-gaussian-integral}. \n\nSince the exponential is monotonic and we are keeping \\(\\sigma \\) and \\(N \\) constant, the Maximum A-Posteriori (MAP) estimate is given by the maximum of \\(R_1^2 (\\omega ) + R_2^2 (\\omega )\\).\n\n\\subsubsection{The periodogram}\n\nThe periodogram \\(C\\) is defined as \n%\n\\begin{align}\nC(\\omega ) = \\frac{2}{N} \\abs{\\sum _{k=1}^{N} d_k \\exp(- i \\omega t_k)}^2\n\\,,\n\\end{align}\n%\nand while this definition could be applied for an arbitrary set of times \\(t_k\\), we will only consider it for evenly spaced times \\(t_k = k \\Delta  + t_0 \\) for some \\(t_0 \\): a discrete-time Fourier transform. \n\nWe can rewrite the periodogram as \n%\n\\begin{align}\nC(\\omega ) &= \\frac{2}{N} \\abs{\\sum _{k=1}^{N} d_k \\qty(\\cos(\\omega t_k) - i \\sin(\\omega t_k))}^2  \\\\\n&= \\frac{2}{N} \\qty[ \\qty(\\sum _{k=1}^{N} d_k \\cos(\\omega t_k))^2 + \\qty(\\sum _{k=1}^{N} d_k \\sin(\\omega t_k))^2]  \\\\\n&= \\frac{2}{N} \\qty[R_1^2(\\omega ) + R_2^2 (\\omega )]\n\\,.\n\\end{align}\n\nTherefore, the value of \\(\\omega \\) which maximizes \\(C(\\omega )\\) is the same which maximizes \\(R_1^2 (\\omega ) + R_2^2 (\\omega )\\), which is the MAP estimate. \n\n\\subsubsection{Least-squares fitting}\n\nLeast-squares fitting the sinusoid with the same model means we minimize \\(\\chi^2 =  Q / \\sigma^2\\).\nThis is precisely equivalent to the MAP estimate for the full likelihood, which under the aforementioned conditions can be estimated through the maximum of \\(R_1^2(\\omega ) + R_2^2(\\omega )\\). \n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=\\textwidth]{figures/chisquare_omega.pdf}\n\\caption{\\(N\\) data points \\(d_i\\) are generated with the same distribution as the theoretical model (see figure \\ref{fig:signal}). The value of \\(Q\\) is computed by fixing \\(B_1 \\) and \\(B_2 \\) to their true values, which is why its extremal point is sharper: it assumes more knowledge than the alternative, which is what we must maximize after we marginalize over all possible amplitudes \\(B_{1, 2}\\). }\n\\label{fig:chisquare_omega}\n\\end{figure}\n\nAs is shown in figure \\ref{fig:chisquare_omega}, the maximum of \\(R_1^2 + R_2^2\\) and the minimum of \\(Q\\) do indeed coincide. In fact, \\(Q\\) can also be computed for different values of \\(B_1 \\) and \\(B_2 \\), and it attains its global minimum near the true values of the whole triple \\((\\omega , B_1 , B_2 )\\).\n\nThis procedure would yield a Gaussian likelihood for \\(\\omega \\) under the following (sufficient) conditions: \n\\begin{enumerate}\n    \\item i.i.d.\\ Gaussian noise on each data point;\n    \\item linear dependence of the model \\(f(t)\\) on its parameter \\(\\omega \\).\n\\end{enumerate}\n\nThe first condition is satisfied under our hypotheses, the second is not unless the entire data range lies in a very small region: \\(N \\Delta  \\ll \\omega^{-1}\\), in which case the model can be approximated to linear order; for example, if the region is near the origin we can approximate it as \\(f(t) \\sim B_1 + B_2 \\omega t\\).\n\nIn the general (and typical) case, instead, the likelihood \\(\\mathscr{L} \\propto \\exp(- Q / \\sigma^2)\\) is not Gaussian, and the model is not linear; however the minimum of \\(Q\\) is still rather peaked, and as long as we start near it we can numerically find the MAP, or equivalently least-squares, estimate of \\(\\omega \\). \n\n\\end{document}\n", "meta": {"hexsha": "b8c59bcec16a1f1b1f1f652a65cf178aa6621fc2", "size": 10392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostat_homework/exercise_10.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_third_semester/astrostat_homework/exercise_10.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_third_semester/astrostat_homework/exercise_10.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": 58.0558659218, "max_line_length": 405, "alphanum_fraction": 0.6645496536, "num_tokens": 3596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6025631652364037}}
{"text": "\n\\chapter{Further Directions} \\label{ch-1}\n\nThere are a number of avenues of research we seek to pursue and include within the scope of the thesis. The most natural one being to continue our work on computing the minimal polynomial of the Frobenius endomorphism by extending other approaches, such as the use of the Hasse Invariant \n\n\n\\section{Outcomes}\n\nThere are 3 key outcomes we wish to achieve:\n\n\\begin{enumerate}\n    \\item Devising new algorithms for elementary operations with various classes of skew polynomials. This is builds on both our previous efforts to provide a comprehensive analysis of operations related to skew polynomials, including multiplication, interpolation, and minimal subspace polynomial, in a bit complexity model.\n    \\item Develop new algorithms for computations related to Drinfeld modules, and in particular computing the minimal polynomial of Drinfeld modules of arbitrary rank $r > 2$. A significant amount of work in this regard has already been conducted and presented in chapter 4.\n    \\item Create implementations for existing and new algorithms that achieve optimal theoretical bounds where this is feasible. \n\\end{enumerate}\n\nWith regards to item (1) there are a number of different directions that could be pursued. For example, skew rings where the commutation rule takes alternate forms such as $\\tau a = (\\sigma(a) + \\delta)\\tau$ for $a \\in \\L$ or which obey a Leibniz rule appear to be less well studied. However, inspired by the work on computing approximant bases of Bartz et al. in \\cite{rosen2021}, we've identified multiplication of matrices with coefficients in a skew polynomial ring as a primary focus. In particular, a fast algorithm for computing minimal approximant basis is achieved by transporting the classical algorithm from the commutative case using a suitable bijective mapping. We wonder if a similar approach can be leveraged to construct a suitably fast algorithm for matrix multiplication over skew polynomial rings. \n\nAs noted, a significant amount of work concerning the computation of minimal polynomials for higher rank Drinfeld modules has already carried out. However, we have identified two additional approaches that may yield further algorithms. The first is to generalize the Hasse invariant approach given by Gekeler in \\cite{frobdist}. In the rank-two case when $\\L = \\F_{\\frakp}$, computing the Frobenius trace reduces to computing the degree $m$ coefficient of $\\phi_{\\frakp}$, which is done using a recurrence based on Eisenstein series. analogs of this recurrence exist in higher ranks \\cite{Gekeler1988}, and it may be possible to speed up the algorithm of Garai and Papikian using this approach. The second approach would be to attempt to generalize the algorithm of Kedlaya using $p$-adic cohmology to compute the zeta function for classical elliptic curves \\cite{kedlaya01}. The initial goal with this approach would be to try to derive an algorithm that functions in the rank-two case at minimum, with a view towards extending this to all ranks.\n\nWith respect to item 3, some preliminary work including a number of basic operations and previous algorithms for computing the minimal polynomial of rank-two Drinfeld modules already exists and is publicly available at \\url{https://github.com/ymusleh/Skew}. Our intention is to continue adding both existing algorithms and all algorithms developed as part of this thesis to the repository.\n", "meta": {"hexsha": "51f992147dfefff97efa71585397450f295f9f24", "size": 3427, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MainText/chapter5.tex", "max_stars_repo_name": "DocTrivial/Research-Proposal", "max_stars_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MainText/chapter5.tex", "max_issues_repo_name": "DocTrivial/Research-Proposal", "max_issues_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MainText/chapter5.tex", "max_forks_repo_name": "DocTrivial/Research-Proposal", "max_forks_repo_head_hexsha": "cf988f64aa400d4c398fe4cb6738a4b90264359d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 155.7727272727, "max_line_length": 1047, "alphanum_fraction": 0.8065363292, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6025631644593383}}
{"text": "\\documentclass[twoside]{article}\n\\title{Specification of Vectors and Matrices}\n\\author{CSC315 Programming Language Concepts}\n\\date{01 October 2013}\n\\usepackage{amsmath}\n\\begin{document}\n\\maketitle\n\n\\section{Vector2D}\n\n\\subsection{Addition}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n  \\vec{v} & = (v_x, v_y) \\\\\n  \\vec{u} + \\vec{v} & = (u_x + v_x, u_y + v_y) \n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  \\vec{v} & = (5, 12) \\\\\n  \\vec{u} + \\vec{v} & = (3 + 5, 4 + 12) \\\\\n                          & = (8, 16)\n  \\end{align*}\n\n\\subsection{Subtraction}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n  \\vec{v} & = (v_x, v_y) \\\\\n  \\vec{u} + \\vec{v} & = (u_x - v_x, u_y - v_y) \n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  \\vec{v} & = (5, 12) \\\\\n  \\vec{v} - \\vec{u} & = (5 - 3, 12 - 4) \\\\\n                          & = (2, 8)\n  \\end{align*}\n\n\\subsection{Multiplication by a scalar}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n   scaleFactor \\times \\vec{u} & = (scaleFactor \\times u_x, scaleFactor \\times u_y)\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  2 \\vec{u} & = (6, 8)\n  \\end{align*}\n\n\\subsection{Dot product}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n  \\vec{v} & = (v_x, v_y) \\\\\n  \\vec{u} \\cdot \\vec{v} & = u_x v_x + u_y v_y\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  \\vec{v} & = (5, 12) \\\\\n  \\vec{u} \\cdot \\vec{v} & = 3 \\cdot 5 + 4 \\cdot 12 \\\\\n                             & = 15 + 48 \\\\\n                             & = 63\n  \\end{align*}\n\n\\begin{align*}\n  \\vec{u} \\cdot \\vec{v} & = |\\vec{u}| |\\vec{v}| \\cos \\psi \\;\\;\\;\n    \\parbox{8cm}{where $\\psi$ is the angle between the vectors}\n  \\end{align*}\n\n\\subsection{Magnitude}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n  |\\vec{u}| & = \\sqrt{ u_x^2 + u_y^2} \\\\\n             & = \\sqrt{ \\vec{u} \\cdot \\vec{u} }\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  |\\vec{u}| & = \\sqrt{ 3^2 + 4^2} \\\\\n              & = \\sqrt{9 + 16} \\\\\n              & = \\sqrt{ 25 } \\\\\n              & = 5\n  \\end{align*}\n\n\\subsection{Normalize}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n  \\hat{u} & = \\frac{1}{|\\vec{u}|} \\vec{u} \\\\\n            & = (\\frac{u_x}{\\sqrt{u_x^2 + u_y^2}}, \\frac{u_y}{\\sqrt{u_x^2 + u_y^2}})\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (3, 4) \\\\\n  |\\vec{u}| & = 5 \\\\\n  \\hat{u} & = \\frac{1}{|\\vec{u}|} \\vec{u} \\\\\n            & = (\\frac{3}{5}, \\frac{4}{5})\n  \\end{align*}\n\n\\section{Vector3D}\n\n\\paragraph{Here is the general rule:}\n\n\\subsection{Addition}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y, u_z) \\\\\n  \\vec{v} & = (v_x, v_y, v_z) \\\\\n  \\vec{u} + \\vec{v} & = (u_x + v_x, u_y + v_y, u_z + v_z) \n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 3) \\\\\n  \\vec{v} & = (4, 5, 6) \\\\\n  \\vec{u} + \\vec{v} & = (1 + 4, 2 + 5, 3 + 6) \\\\\n                          & = (5, 7, 9)\n  \\end{align*}\n\n\\subsection{Subtraction}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y, u_z) \\\\\n  \\vec{v} & = (v_x, v_y, v_z) \\\\\n  \\vec{u} + \\vec{v} & = (u_x - v_x, u_y - v_y, u_z - v_z) \n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 3) \\\\\n  \\vec{v} & = (4, 5, 6) \\\\\n  \\vec{v} - \\vec{u} & = (4 - 1, 5 - 2, 6 - 3) \\\\\n                          & = (3, 3, 3)\n  \\end{align*}\n\n\\subsection{Multiplication by a scalar}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y) \\\\\n   scaleFactor \\times \\vec{u} & = (scaleFactor \\times u_x, scaleFactor \\times u_y)\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 3) \\\\\n  2 \\vec{u} & = (2, 4, 6)\n  \\end{align*}\n\n\\subsection{Dot product}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y, u_z) \\\\\n  \\vec{v} & = (v_x, v_y, v_z) \\\\\n  \\vec{u} \\cdot \\vec{v} & = u_x v_x + u_y v_y + u_z v_z\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 3) \\\\\n  \\vec{v} & = (4, 5, 6) \\\\\n  \\vec{u} \\cdot \\vec{v} & = 1 \\cdot 4 + 2 \\cdot 5 + 3 \\cdot 6 \\\\\n                             & = 4 + 10 + 18 \\\\\n                             & = 30\n  \\end{align*}\n\n\\begin{align*}\n  \\vec{u} \\cdot \\vec{v} & = |\\vec{u}| |\\vec{v}| \\cos \\psi \\;\\;\\;\n    \\parbox{8cm}{where $\\psi$ is the angle between the vectors}\n  \\end{align*}\n\n\\subsection{Magnitude}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y, u_z) \\\\\n  |\\vec{u}| & = \\sqrt{ u_x^2 + u_y^2 + u_z^2} \\\\\n             & = \\sqrt{ \\vec{u} \\cdot \\vec{u} }\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 2) \\\\\n  |\\vec{u}| & = \\sqrt{ 1^2 + 2^2 + 2^2} \\\\\n              & = \\sqrt{1 + 4 + 4} \\\\\n              & = \\sqrt{ 9 } \\\\\n              & = 3\n  \\end{align*}\n\n\\subsection{Normalize}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  \\vec{u} & = (u_x, u_y, u_z) \\\\\n  \\hat{u} & = \\frac{1}{|\\vec{u}|} \\vec{u} \\\\\n            & = (\\frac{u_x}{\\sqrt{u_x^2 + u_y^2 + u_z^2}}, \n                    \\frac{u_y}{\\sqrt{u_x^2 + u_y^2 + u_z^2}})\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  \\vec{u} & = (1, 2, 2) \\\\\n  |\\vec{u}| & = 3 \\\\\n  \\hat{u} & = \\frac{1}{|\\vec{u}|} \\vec{u} \\\\\n            & = (\\frac{1}{3}, \\frac{2}{3}, \\frac{2}{3})\n  \\end{align*}\n\n\\section{Matrix2x2}\n\n\\subsection{Special $2 \\times 2$ matrices}\n\n\\subsubsection{Identity}\n\n\\begin{align*}\n  I & = \\left[ \\begin{array}{rr}\n    1 & 0 \\\\\n    0 & 1\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsubsection{Rotation}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  R( \\psi ) & = \\left[ \\begin{array}{rr}\n    \\cos \\psi & -\\sin \\psi \\\\\n    \\sin \\psi & \\cos \\psi\n    \\end{array} \\right]\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  R( \\pi/2 ) & = \\left[ \\begin{array}{rr}\n    0 & -1 \\\\\n    1 & 0\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsubsection{Scaling}\n\n\\begin{align*}\n  S( s_x, s_y ) & = \\left[ \\begin{array}{rr}\n    s_x & 0 \\\\\n    0 & s_y\n    \\end{array} \\right]\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  S( 2, 2 ) & = \\left[ \\begin{array}{rr}\n    2 & 0 \\\\\n    0 & 2\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsection{Multiplication: matrix $\\times$ matrix}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    a_{00} & a_{01} \\\\\n    a_{10} & a_{11}\n    \\end{array} \\right] \\\\\n  B & = \\left[ \\begin{array}{rr}\n    b_{00} & b_{01} \\\\\n    b_{10} & b_{11}\n    \\end{array} \\right] \\\\\n  AB & = \\left[ \\begin{array}{rr}\n    (a_{00} b_{00} + a_{01} b_{10}) & (a_{00} b_{01} + a_{01} b_{11}) \\\\\n    (a_{10} b_{00} + a_{11} b_{10}) & (a_{10} b_{01} + a_{11} b_{11}) \\\\\n    \\end{array} \\right]\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\nA rotation by $30^\\circ$ ($\\pi/6$ radians) followed by a rotation \nby $60^\\circ$ ($\\pi/3$ radians) produces the same result as a\nsingle rotation by $90^\\circ$ ($\\pi/2$ radians).\n\n\\begin{align*}\n  R(\\frac{\\pi}{6}) & = \\left[ \\begin{array}{rr}\n    \\frac{\\sqrt{3}}{2} & -\\frac{1}{2} \\\\\n    \\frac{1}{2} & \\frac{\\sqrt{3}}{2}\n    \\end{array} \\right] \\\\\n  R(\\frac{\\pi}{3}) & = \\left[ \\begin{array}{rr}\n    \\frac{1}{2} & -\\frac{\\sqrt{3}}{2} \\\\\n    \\frac{\\sqrt{3}}{2} & \\frac{1}{2}\n    \\end{array} \\right] \\\\\n  R(\\frac{\\pi}{2}) & = \\left[ \\begin{array}{rr}\n    0 & -1 \\\\\n    1 & 0\n    \\end{array} \\right] \\\\\n  R(\\frac{\\pi}{6}) \\; R(\\frac{\\pi}{3}) & = R(\\frac{\\pi}{2}) \n  \\end{align*}\n\n\\subsection{Multiplication: matrix $\\times$ vector}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    a_{00} & a_{01} \\\\\n    a_{10} & a_{11}\n    \\end{array} \\right] \\\\\n  \\vec{v} & = \\left[ \\begin{array}{r}\n    v_x \\\\\n    v_y )  \n    \\end{array} \\right] \\\\\n  A \\vec{v} & =\n    \\left[ \\begin{array}{rr}\n      a_{00} & a_{01} \\\\\n      a_{10} & a_{11}\n      \\end{array} \\right]\n    \\left[ \\begin{array}{r}\n      v_x \\\\\n      v_y\n      \\end{array} \\right] \\\\\n  & =\n    \\left[ \\begin{array}{rr}\n      a_{00} v_x + a_{01} v_y \\\\\n      a_{10} v_x + a_{11} v_y\n      \\end{array} \\right]\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\subsection{Determinant}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    a_{00} & a_{01} \\\\\n    a_{10} & a_{11} \n    \\end{array} \\right] \\\\\n  |A| & = a_{00} a_{11} - a_{10} a_{01}\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    3 & 2 \\\\\n    6 & 8\n    \\end{array} \\right] \\\\\n  |A| & = 3 \\cdot 8 - 2 \\cdot 6 \\\\\n      & = 24 - 12 \\\\\n      & = 12\n  \\end{align*}\n\n\\subsection{Inverse}\n\n\\paragraph{Here is the general rule:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    a & b \\\\\n    c & d \n    \\end{array} \\right] \\\\\n  A^{-1} & = \\frac{1}{|A|} \\left[ \\begin{array}{rr}\n    d & -b \\\\\n    -c & a\n    \\end{array} \\right] \\\\\n  A A^{-1} & = I\n  \\end{align*}\n\n\\paragraph{Here is a specific example:}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rr}\n    3 & 2 \\\\\n    6 & 8 \n    \\end{array} \\right] \\\\\n  A^{-1} & = \\frac{1}{|A|} \\left[ \\begin{array}{rr}\n    8 & -2 \\\\\n    -6 & 3\n    \\end{array} \\right] \\\\\n  A^{-1} & = \\frac{1}{12} \\left[ \\begin{array}{rr}\n    8 & -2 \\\\\n    -6 & 3\n    \\end{array} \\right] \\\\\n  A^{-1} & = \\left[ \\begin{array}{rr}\n    \\frac{2}{3} & -\\frac{1}{6} \\\\\n    -\\frac{1}{2} & \\frac{1}{4}\n    \\end{array} \\right] \\\\\n  \\left[ \\begin{array}{rr}\n    3 & 2 \\\\\n    6 & 8 \n    \\end{array} \\right] \n  \\left[ \\begin{array}{rr}\n    \\frac{2}{3} & -\\frac{1}{6} \\\\\n    -\\frac{1}{2} & \\frac{1}{4}\n    \\end{array} \\right] & =\n  \\left[ \\begin{array}{rr}\n    1 & 0 \\\\\n    0 & 1\n    \\end{array} \\right]\n  \\end{align*}\n\n\\section{Matrix3x3}\n\n\\subsection{Special $3 \\times 3$ matrices}\n\n\\subsubsection{Identity}\n\n\\begin{align*}\n  I & = \\left[ \\begin{array}{rrr}\n    1 & 0 & 0 \\\\\n    0 & 1 & 0 \\\\\n    0 & 0 & 1\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsubsection{Rotation about the x-axis}\n\n\\begin{align*}\n  R_x( \\psi ) & = \\left[ \\begin{array}{rrr}\n    1 & 0 & 0 \\\\\n    0 & \\cos \\psi & -\\sin \\psi \\\\\n    0 & \\sin \\psi &  \\cos \\psi \n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsubsection{Rotation about the y-axis}\n\n\\begin{align*}\n  R_y( \\psi ) & = \\left[ \\begin{array}{rrr}\n    \\cos \\psi & 0 & \\sin \\psi \\\\\n    0 & 1 & 0 \\\\\n    -\\sin \\psi & 0 & \\cos \\psi\n    \\end{array} \\right]    \n  \\end{align*}\n\n\n\\subsubsection{Rotation about the z-axis}\n\n\\begin{align*}\n  R_z( \\psi ) & = \\left[ \\begin{array}{rrr}\n    \\cos \\psi & -\\sin \\psi & 0 \\\\\n    \\sin \\psi &  \\cos \\psi & 0 \\\\\n    0 & 0 & 1\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsubsection{Scaling}\n\n\\begin{align*}\n  S( s_x, s_y, s_z ) & = \\left[ \\begin{array}{rrr}\n    s_x & 0 & 0 \\\\\n    0 & s_y & 0 \\\\\n    0 & 0 & s_z\n    \\end{array} \\right]\n  \\end{align*}\n\n\\subsection{Multiplication: matrix $\\times$ matrix}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rrr}\n    a_{00} & a_{01} & a_{02} \\\\\n    a_{10} & a_{11} & a_{12} \\\\\n    a_{20} & a_{21} & a_{22} \n    \\end{array} \\right] \\\\\n  B & = \\left[ \\begin{array}{rrr}\n    b_{00} & b_{01} & b_{02} \\\\\n    b_{10} & b_{11} & b_{12} \\\\\n    b_{20} & b_{21} & b_{22} \n    \\end{array} \\right] \\\\\n  C & = AB \\\\\n   & = \\left[ \\begin{array}{rrr}\n    (a_{00} b_{00} + a_{01} b_{10} + a_{02} b_{20}) &\n    (a_{00} b_{01} + a_{01} b_{11} + a_{02} b_{21}) &\n    (a_{00} b_{02} + a_{01} b_{12} + a_{02} b_{22}) \\\\\n    (a_{10} b_{00} + a_{11} b_{10} + a_{12} b_{20}) &\n    (a_{10} b_{01} + a_{11} b_{11} + a_{12} b_{21}) &\n    (a_{10} b_{02} + a_{11} b_{12} + a_{12} b_{22}) \\\\\n    (a_{20} b_{00} + a_{21} b_{10} + a_{22} b_{20}) &\n    (a_{20} b_{01} + a_{21} b_{11} + a_{22} b_{21}) &\n    (a_{20} b_{02} + a_{21} b_{12} + a_{22} b_{22}) \n    \\end{array} \\right]\n  \\end{align*}\n\nLet $c_{ij}$ be the element in the $i^{th}$ row and $j^{th}$ column of\nthe $3 \\times 3$ matrix $C$.\nSimilarly, let $a_{ij}$ and $b_{ij}$ be elements of the $3 \\times 3$\nmatrices $A$ and $B$ whose product is $C$.\n\nThen\\ldots\n\n\\begin{align*}\n  c_{ij} & = \\sum_{k = 0}^2 a_{ik} \\; b_{kj} \\\\\n        & = a_{i0} \\; b_{0j} + a_{i1} \\; b_{1j} + a_{i2} \\; b_{2j}\n  \\end{align*}\n\n\n\\subsection{Multiplication: matrix $\\times$ vector}\n\n\\begin{align*}\n  A & = \\left[ \\begin{array}{rrr}\n    a_{00} & a_{01} & a_{02} \\\\\n    a_{10} & a_{11} & a_{12} \\\\\n    a_{20} & a_{21} & a_{22} \n    \\end{array} \\right] \\\\\n  \\vec{v} & = \\left[ \\begin{array}{r}\n    v_0 \\\\\n    v_1 \\\\\n    v_2\n    \\end{array} \\right] \\\\\n  A \\vec{v} & = \\left[ \\begin{array}{r}\n    a_{00} \\; v_0 + a_{01} \\; v_1 + a_{02} \\; v_2 \\\\\n    a_{10} \\; v_0 + a_{11} \\; v_1 + a_{12} \\; v_2 \\\\\n    a_{20} \\; v_0 + a_{21} \\; v_1 + a_{22} \\; v_2 \\\\\n    \\end{array} \\right]\n  \\end{align*}\n\nThe element in the $i^{th}$ row \nof $A \\vec{v}$ is $\\sum_{k = 0}^2 a_{ik} \\; v_k$.\n\n\\end{document}\n", "meta": {"hexsha": "d3c2f67e672393533d7bac7e6428f4eb5f4fe40f", "size": 13135, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "vector-specification.tex", "max_stars_repo_name": "leontabak/platonic", "max_stars_repo_head_hexsha": "84b56f14895c52d80940b580f2cd2338d1bef483", "max_stars_repo_licenses": ["MIT"], "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-specification.tex", "max_issues_repo_name": "leontabak/platonic", "max_issues_repo_head_hexsha": "84b56f14895c52d80940b580f2cd2338d1bef483", "max_issues_repo_licenses": ["MIT"], "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-specification.tex", "max_forks_repo_name": "leontabak/platonic", "max_forks_repo_head_hexsha": "84b56f14895c52d80940b580f2cd2338d1bef483", "max_forks_repo_licenses": ["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.2477876106, "max_line_length": 84, "alphanum_fraction": 0.4998858013, "num_tokens": 5597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.754914975839675, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6025631574690307}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 25}\n\\subsection{Lecture Notes - The Poisson Brackeet and Liouville's Theorem}\n\\subsubsection{Review}\nOn Monday, we talked about canonical transformations. In Lagrangian picture, we found that Lagrange's equation of motion were invaraint under coordinate transformations. In Hamilton's picture, $p$ and $q$ play the same role. In the phase space spanned by $p$ and $q$, there are a wider class of possible transformations that can be made. Not all of these transformations leave Hamilton's equations invariant. The subclass that do is called canaonical. Adding he total time derivative of a function $F$ is what could accomplish this. \n\n\\subsubsection{Poisson Bracket}\nConsider the phase space function $F(q, p, t)$ (any function of the variables of phase space, could depend on time, could be energy, angular momentum etc.). Let us write the total time derivative of this. As usual, we expand this total derivative to get:\n\\[\\dod{F}{t} = \\sum_j \\dpd{F}{q_j}\\dot{q}_j + \\sum_j\\dpd{F}{p_j}\\dot{p}_j + \\dpd{F}{t}\\]\nUsing Hamilton's equations to replace $\\dot{q}_j$ and $\\dot{p}_j$, we get that:\n\\[\\dod{F}{t} = \\sum_j\\dpd{F}{q_j}\\dpd{\\HH}{p_j} - \\sum_j\\dpd{F}{p_j}\\dpd{\\HH}{q_j} + \\dpd{F}{t}\\]\nWe may write this as:\n\\[[F, H] + \\dpd{F}{t}\\]\nThis is the \\textbf{Poisson Bracket}. It's a shorthand for $\\sum_j\\pd{F}{q_j}\\pd{\\HH}{p_j} - \\sum_j\\pd{F}{p_j}\\pd{\\HH}{q_j}$. As a note of notation, it can also be written with curly brackets \\{ \\}. If $F$ is conserved, an equivalent statement is that $\\dod{F}{t} = 0$, and equivalent to this is that $[F, H] = 0$. \n\n\\subsubsection{Properties of the Poisson Bracket}\n\\begin{enumerate}\n    \\item Anti-symmetry $[F, G] = -[G, H]$, from which we obtain $[F, F] = 0$.\n    \\item Bilinearity $[aF + bG, H] = a[F, H] + b[G, H]$ and $[H, aF + bG] = a[H, F] + b[H, G]$\n    \\item Leibniz' Rule $[FG, H] = [F, H]G + F[G, H]$\n    \\item Jacobi Identity $[F, [G, H]] + [G, [H, F]] + [H, [F, G]] = 0$\n\\end{enumerate}\n\n\\subsubsection{Poisson Bracket and Canonical Transformations}\nWe test if the following transformation is canonical:\n\\[q_i \\mapsto Q_i(p, q), \\quad p_i \\mapsto P_i(p, q), \\quad \\dpd{F}{t} = 0, \\quad K = \\HH\\]\nWe claim that this is the case if the following identities hold for the fundamental Poisson brackets:\n\\[[Q_i, Q_l] = 0, \\quad [P_i, P_l] = 0, [Q_i, P_l] = \\delta_{il}\\]\nare obeyed. As a remark, these identities are \\textit{quite} similar to the canonical commutation relations that we see in quantum mechanics. This shows that the structure in phase space is ready to be quantized. But, we return to this on Friday. For now, we return to the proof. Taking the total time derivative of $F$, we have:\n\\[\\dod{F}{t} = \\ldots = \\sum_l \\dpd{K}{Q_l}[F, Q_l] + \\sum_l \\dpd{K}{P_l}[F, P_l]\\]\nThese identities were just obtained by the chain rule and reordering. We now consider some cases. In the first case, consider $F = Q_i$. In this case,\n\\[\\dot{Q}_i = \\sum_l\\dpd{K}{Q_l}[Q_i, Q_l] + \\sum_l\\dpd{K}{P_l}[Q_i, P_l]\\]\nIn order for Hamilton's equation to be satisfied, we require that this expression is equal to $\\dpd{K}{P_i}$. From this, we require that $[Q_i, Q_l] = 0$, and $[Q_i, P_l] = \\delta_{il}$. In the second case, consider $F =P_i$. Then,\n\\[\\dot{P}_i = \\sum_l\\dpd{K}{Q_l}[P_i, Q_l] + \\sum_l\\dpd{K}{P_l}[P_i, P_l]\\]\nAgain, in order for Hamilton's equations to be satisfied, we require that this is equal to $-\\dpd{K}{Q_i}$. From this we obtain that $[P_i, Q_l] = -\\delta_{il}$, and $[P_i, P_l] = 0$. This completes the proof of the claim. \n\n\\subsubsection{Hamiltonian Flow}\nRecall our discussion of the phase space vector:\n\\[\\v{z} = \\m{\\v{q} \\\\ \\v{p}}\\]\nWhich in general has $2n$ elements for $n$ degrees of freedom (recall the 2d phase space vector for the 1-dimensional harmonic oscillator). Taking the time derivative of this, we get the phase space velocity vector:\n\\[\\dot{\\v{z}} = \\m{\\dot{\\v{q}} \\\\ \\dot{\\v{p}}} = \\m{\\dpd{\\HH}{\\v{p}} \\\\ -\\dpd{\\HH}{\\v{q}}} = \\v{v}(\\v{z})\\]\nThe idea is that the phase space trajectories depend on the total energy of the system. For example with the double well potential:\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-25/l25-img1.png}\n\\end{center}\nNow, let us consider a bunch of systems that are some time close together (in phase space):\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-25/l25-img2.png}\n\\end{center}\nWhat happens to this cloud of points as it goes through a time evolution? These trajectories are unique and deterministic, so at some later point in time, this cloud may have moved in phase space. It also does not have to have the same shape. But, the points inside the cloud have to stay inside the cloud, as trajectories cannot cross in Hamiltonian dynamics. Points inside stay on the inside.\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-25/l25-img3.png}\n\\end{center}\nIn general, there is a hyper-volume (the cloud) in phase space, which moves through the space with time; this is the picture we want to have when thinking about Hamiltonian flow. \n\n\\subsubsection{Liouville's Theorem}\nWe hence consider a map:\n\\[\\v{z}_0 \\mapsto \\v{z}(t)\\]\nwhich is the definition of the Hamiltonian/phase space flow. The statement of Liouville's theorem is that the area initially occupied by the cloud in phase space is the same as the area occupied at some point later (for higher dimensions, replace area with hyper-volume). \n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-25/l25-img4.png}\n\\end{center}\nWe will make this statement more precise as we go on. In order to see this, we again look at this Hamiltonian flow. Hamilton's equations are a description/map of these positions in phase space to a later time. Let us examine the properties of this map for a small time interval:\n\\[q_i \\mapsto Q_i = q_i + \\dot{q}_idt\\]\n\\[p_i \\mapsto P_i = p_i + \\dot{p}_idt\\]\nThis is of course just a first-order Taylor expansion/linear approximation. Of course we can rewrite these expressions using Hamilton's equations:\n\\[q_i \\mapsto q_i + \\dpd{\\HH}{p_i}dt\\]\n\\[p_i \\mapsto p_i - \\dpd{\\HH}{q_i}dt\\]\nThe statement of Liouville's theorem can then be made to say:\n\\[V_{pq} = d\\v{q}d\\v{p} = V_{PQ} = d\\v{P}d\\v{Q}\\]\nWhat happens if we apply this transformation and compare? This is just a statement about a change of variables. Let us recall what we did for integration. When switching integration variables $x = x(u, v)$, $y = y(u, v)$, which of the following is correct?\n\\begin{s}\nWe recall how we did coordinate transformations using the Jacobian:\n\\[\\iint f(x, y)dxdy = \\iint f(x(u, v), y(u, v)) \\abs{\\dpd{(x,y)}{(u, v)}}dudv\\]\nNote that here $\\abs{\\dpd{(x,y)}{(u, v)}}$ is the determinant of the 2x2 matrix containing the partial derivatives (the determinant of the Jacobian), e.g.:\n\\[\\dpd{(x,y)}{(u, v)} = \\m{\\dpd{x}{u} & \\dpd{x}{v} \\\\ \\dpd{y}{u} & \\dpd{y}{v}}\\]\nHence, returning to our discussion of the conserved volumes; we can write $d\\v{P}d\\v{Q}$ as:\n\\[V_{pq} = d\\v{q}d\\v{p} = V_{PQ} = d\\v{P}d\\v{Q} = \\abs{\\dpd{\\v{z}_t}{\\v{z}_0}}d\\v{p}d\\v{q}\\]\nWe can write this Jacobian as:\n\\[\\dpd{\\v{z}_t}{\\v{z}_0} = \\m{\\dpd{Q}{q} & \\dpd{Q}{p} \\\\ \\dpd{P}{q} & \\dpd{P}{p}} = \\m{1 + \\pdv{\\HH}{p}{q}dt & \\dpd[2]{\\HH}{p}dt \\\\ -\\dpd[2]{\\HH}{p}dt & 1 - \\pdv{\\HH}{p}{q}dt }\\]\nWe have done this many times in the past, e.g. when transforming from cartesian to spherical coordinates. The factor $r^2\\sin\\theta$ in this coordinate transformation from cartesian to spherical is the determinant of the Jacobian in that case. Here, we are just transforming from a system at time $t = 0$ to time $t = t$. Hence taking the determinant, we have:\n\\[\\abs{\\dpd{\\v{z}_t}{\\v{z}_0}} = 1 - \\left(\\pdv{\\HH}{p}{q}\\right)^2dt^2 + \\dpd[2]{\\HH}{p}\\dpd[2]{\\HH}{q}dt^2 + \\cdots \\]\nWe note that there are no linear terms in $dt$. Hence, the time derivative of this object is zero. Hence, the phase space volume does not change. Equivalently, $\\od{V}{t} = 0$. The fluid of phase space moves like an incompressable fluid, keeping its volume. \n\\end{s} \n\n\n\\end{document}", "meta": {"hexsha": "a373adc3a44b625b395c567ead03e6b3309fd332", "size": 8021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-25/Lecture-Notes-25.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-25/Lecture-Notes-25.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-25/Lecture-Notes-25.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": 90.1235955056, "max_line_length": 533, "alphanum_fraction": 0.6955491834, "num_tokens": 2635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6025631553990439}}
{"text": "\\chapter{Virtually Abelian Groups}\\label{chapter:polynomial-geodesic-growth}%\n\\label{sec:virtually-abelian-groups}\n\nIt is a well-known result of \\textcite{gromov1981} that a group has polynomial volume growth if and only if it is virtually nilpotent.\nMoreover, from the work of \\textcite{bass1972} we know that virtually nilpotent groups have polynomial volume of integer degrees.\n\\Textcite{bridson2012} asked if there is an analogous classification for groups with polynomial geodesic growth and if there exists a group with intermediate geodesic growth.\nTowards these questions they provided a sufficient condition, given in \\cref{lem:bbes-main-theorem}, for a virtually abelian group to have polynomial geodesic growth, and furnished an example of a virtually $\\mathbb{Z}^2$ group, given in \\cref{eq:virtually-z2-example}, with polynomial geodesic growth.\nBefore this virtually $\\mathbb{Z}^2$ example, the only groups known to have polynomial geodesic growth were virtually cyclic.\nIn this chapter, we take the next step towards a classification of polynomial geodesic growth by characterising the geodesic growth series for all virtually abelian groups with respect to any finite weighted monoid generating sets.\n%We then see in \\cref{thm:geodesic-growth} that this implies that the geodesic growth is either exponential, or polynomial with a rational geodesic growth series.\n\n\\begin{lemma}[Theorem~1 in \\cite{bridson2012}]\\label{lem:bbes-main-theorem}\n\tLet $G$ be a finitely-generated group.\n\tIf there is an element $g \\in G$ whose normal closure is a finite-index abelian subgroup of $G$, then $G$ has polynomial geodesic growth with respect to some generating set.\n\\end{lemma}\n\nIn \\cite{bridson2012}, it was shown that the virtually $\\mathbb{Z}^2$ group\n\\begin{equation}\\label{eq:virtually-z2-example}\n\t\\left\\langle\n\t\ta,b,t\n\t\\mid\n\t\t[a,b] = t^2 = 1,\\,\n\t\ta^t = b\n\t\\right\\rangle\n\\end{equation}\nhas polynomial geodesic growth with respect to the generating set $\\{a,a^{-1},t\\}$.\nThis group was introduced by Cannon~\\cite[Example~4.4.1~on~p.~97]{epstein1992} as an example of a group that is \\textit{short-lex automatic} with respect to one, but not all, generating sets.\nMoreover, it was shown in Example~4.4.2~on~page~98 of~\\cite{epstein1992} that this group has a generating set for which the geodesics do not form a regular language.\nIn \\cref{thm:bounded automata is ET0L}, we show that the language of geodesics for each virtually abelian group is blind multicounter for every generating set.\n\nWe may generalise the construction given in \\cref{eq:virtually-z2-example} to show that for any finitely-generated abelian group, $A$, there is a virtually-$A$ group with polynomial geodesic growth.\nLet $A$ be a finitely-generated abelian group, then from the classification of finitely-generated abelian groups we see that $A = F \\times \\mathbb{Z}^n$ for some $n$ and finite group $F$.\nLet $x_1,x_2,\\ldots,x_n$ be the standard basis for the $\\mathbb{Z}^n$ subgroup of $A$.\nLet\n\\begin{equation}\\label{eq:virt-abel-polynomial}\n\tB\n\t=\n\t\\left\\langle\n\t\tA, t\n\t\\ \\middle\\vert\\ \n\t\t[F,t]=1,\\ \n\t\tx_i^t = x_{i+1}\\text{ for each }i < n,\\ \n\t\tt^n = 1\n\t\\right\\rangle.\n\\end{equation}\nWe see that $B$ contains $A$ as a subgroup of index $n$; and thus $B$ contains $\\mathbb{Z}^n$ as a subgroup of index $n |F|$.\nMoreover, the normal closure of $x_1$ in $B$ is the finite-index free-abelian subgroup $\\mathbb{Z}^n$.\nFrom \\cref{lem:bbes-main-theorem}, we see that $B$ has polynomial geodesic growth with respect to some generating set.\n\nBenson~\\cites{benson1983} showed that the volume growth series for virtually abelian groups is rational with respect to any finite (weighted monoid) generating set.\nThis result was generalised by \\textcite{evetts2019} who showed that the coset, subgroup, and conjugacy growth series of a virtually abelian group is rational with respect to any finite (weighted monoid) generating set.\nIn \\crefrange{sec:patterned-words}{sec:patterned-words/properties} %\nwe modify the methods of Benson, and provide a characterisation of the geodesic growth series in \\cref{sec:geodesic-growth} by combining this with our result on polyhedrally constrained language given in \\cref{prop:polyhedrally-constrained-is-holonomic}.\n\n\\section{Patterned Words}\\label{sec:patterned-words}\n\nLet $G$ be a virtually abelian group that is generated as a monoid by some finite weighted generating set $S$.\nIt is known that $G$ contains a finite-index normal subgroup that is isomorphic to $\\mathbb{Z}^n$ for some $n$.\nThis follows as $G$ must contain an abelian subgroup $A$ of finite index, then from the classification of finitely generated abelian groups we see that $G$ must contain a group $H$ that is isomorphic to $\\mathbb{Z}^n$.\nWe may then obtain a normal subgroup from the core of $H$ as $\\bigcap_{g\\in G} H^g$.\nThis subgroup will be finite index in $G$, and is free abelian as it is a subgroup of a free abelian group $H$~\\cite[100-1]{robinson1996}.\nWithout loss of generality, we assume that $\\mathbb{Z}^n \\triangleleft G$ with $d = [G:\\mathbb{Z}^n]$.\nWe fix a set of coset representatives $T = \\{t_1=1,t_2,\\ldots,t_d\\}$ for $\\mathbb{Z}^n$ in $G$.\nWe then write elements of $G$ in the normal form $g = z \\cdot t$ where $z \\in \\mathbb{Z}^n$ and $t \\in T$.\n\n\\begin{definition}\\label{defn:phi-rho}\n\tLet $\\psi\\colon G \\to \\mathbb{Z}^n$ and $\\rho\\colon G \\to T$ be the maps defined such that the normal form for $g \\in G$ is given by $\\psi(g) \\cdot \\rho(g)$.\n\\end{definition}\n\nBenson~\\cite{benson1983} showed that virtually abelian groups have rational volume growth series by demonstrating that each group element has at least one geodesic representative that can be expressed as a \\emph{patterned word}, where the set of such patterned words is then studied using the theory of polyhedral sets.\nIn this section we modify these arguments to study the set of all geodesic words in $S^*$, in particular, we describe \\cref{algo:word-shuffling} which converts words in $S^*$ to \\emph{patterned words} which represent the same group element with the same weight.\nIn \\cref{sec:patterned-words/properties} we compute the weight and group element of patterned words, and describe the patterned words which correspond to geodesics.\n\nWe begin by defining two finite sets of words $Y,P \\subseteq S^*$ as follows.\n\n\\begin{definition}\\label{defn:sets-Y-P}\n\tFrom the generating set $S$ and the normal subgroup $\\mathbb{Z}^n \\triangleleft G$ with finite index $d = [G : \\mathbb{Z}^n]$, we define the sets\n\t\\begin{align*}\n\t\tY\n\t\t&=\n\t\t\t\\{\n\t\t\t\t\\sigma \\in S^*\n\t\t\t\\mid\n\t\t\t\t1 \\leqslant |\\sigma|_S \\leqslant d\n\t\t\t\t\\ \\,\\mathrm{and}\\,\\ \n\t\t\t\t\\overline{\\sigma} \\in \\mathbb{Z}^n\n\t\t\t\\}\n\t\t\\ \\ \\text{and}\n\t\t\\\\\n\t\tP\n\t\t&=\n\t\t\\{\n\t\t\t\t\\sigma \\in S^*\n\t\t\t\\mid\n\t\t\t\t1 \\leqslant |\\sigma|_S \\leqslant d - 1\n\t\t\t\t\\ \\,\\mathrm{and}\\,\\ \n\t\t\t\t\\overline{\\sigma} \\notin \\mathbb{Z}^n\n\t\t\t\\},\n\t\\end{align*}\n\tand we fix a labelling $\\{y_1,y_2,\\ldots,y_m\\} = Y$ where $m = |Y|$.\n\\end{definition}\n\nWe define the sets $Y$ and $P$ as above so that we have the technical property given in \\cref{lemma:factoring-words}.\nWe will find this property useful in the proof of \\cref{lemma:map-delta} which is then used to construct \\cref{algo:word-shuffling}.\n\n\\begin{lemma}\\label{lemma:factoring-words}\n\tSuppose that $w \\in S^*$ with $1 \\leqslant |w|_S \\leqslant d$ and $w \\notin P$.\n\tThen, there is a factoring $w = \\alpha \\beta \\delta$ with $\\alpha \\in P \\cup \\{ \\varepsilon \\}$, $\\beta \\in Y$ and $\\delta \\in S^*$.\n\tIn particular, there is a unique choice of such a factoring for which $(|\\alpha|_S, |\\beta|_S) \\in \\mathbb{N}^2$ is minimal with respect to the lexicographic ordering on $\\mathbb{N}^2$.\n\\end{lemma}\n\n\\begin{proof}\nLet $w = w_1 w_2 \\cdots w_k$ with $1 \\leqslant k \\leqslant d$ and $w \\notin P$.\n\nNotice that if we have at least one such factorisation, then there is a unique choice of such a factoring where $(|\\alpha|_S, |\\beta|_S) \\in \\mathbb{N}^2$ is minimal with respect to the lexicographic ordering on $\\mathbb{N}^2$.\nThus, all that remains to be shown is that at least one such factoring $w = \\alpha\\beta\\delta$ exists.\n\nIf $|w|_S < d$, then we have such a factorisation given by $\\beta = w$, and $\\alpha = \\delta = \\varepsilon$.\nThus, in the remainder of this proof we consider the case where $|w|_S = d$.\n\nIf $|w|_S = d$, then from the pigeonhole principle on the $d$ cosets, we see that there must be a nontrivial factor $b = w_i w_{i+1} \\cdots w_j$ for which $\\overline{b} \\in \\mathbb{Z}^n$.\nLet $I \\geqslant 1$ be the smallest value for which there is a $J \\geqslant I$ with $\\overline{w_{I} w_{I+1} \\cdots w_J} \\in \\mathbb{Z}^n$, then let $\\alpha = w_1 w_2 \\cdots w_{I-1}$ and $\\beta = w_{I} w_{I+1} \\cdots w_J$.\nFrom our choice of indices $I$ and $J$, we see that $\\beta \\in Y$, and either $\\alpha = \\varepsilon$ or $\\overline{\\alpha} \\notin \\mathbb{Z}^n$.\nMoreover, we see that $|\\alpha|_S = I-1 \\leqslant d - 1$ and thus $\\alpha \\in P\\cup \\{\\varepsilon\\}$.\n\\end{proof}\n\nNotice that $S \\subseteq Y \\cup P$, and thus $Y \\cup P$ generates the group $G$.\nWe will see that for each word $\\sigma \\in S^*$, there is a word $w \\in Y^*(PY^*)^k$, with $0 \\leqslant k \\leqslant d$, such that $w$ represents the same group element as $\\sigma$ with the same weight.\nWe formalise this by defining \\emph{patterns} and \\emph{patterned words} as follows.\n\n\\begin{definition}[Patterned words]\\label{defn:patterned-words}\n\tLet $\\pi = \\pi_1 \\pi_2 \\cdots \\pi_k \\in P^*$ be a word in the letters of $P$ with length $k = |\\pi|_P \\leqslant d$ for which each proper prefix belongs to a distinct coset, that is,\n\t\\begin{equation}\\label{eq:pattern-cosets}\n\t\t1 = \\rho(\\overline{\\varepsilon}),\\ \n\t\t\\rho(\\overline{\\pi_1}),\\ \n\t\t\\rho(\\overline{\\pi_1\\pi_2}),\\ \n\t\t\\ldots,\\ \n\t\t\\rho(\\overline{\\pi_1\\pi_2\\cdots\\pi_{k-1}})\n\t\\end{equation}\n\tare pairwise distinct; and let $v \\in \\mathbb{N}^{(k+1)m}$ be a vector where $m = |Y|$.\n\tThen we say that $\\pi$ is a \\emph{pattern} and that $(v,\\pi)$ is a \\emph{patterned word}.\n\tWe then write\n\t\\begin{equation*}\n\t\tv^\\pi\n\t\t=\n\t\t\\Big(\n\t\t\ty_1^{v_1}\n\t\t\ty_2^{v_2}\n\t\t\t\\cdots\n\t\t\ty_m^{v_m}\n\t\t\\Big)\n\t\t\\pi_1\n\t\t\\Big(\n\t\t\ty_1^{v_{m+1}}\n\t\t\ty_2^{v_{m+2}}\n\t\t\t\\cdots\n\t\t\ty_m^{v_{2m}}\n\t\t\\Big)\n\t\t\\pi_2\n\t\t\\cdots\n\t\t\\pi_k\n\t\t\\Big(\n\t\t\ty_1^{v_{k \\cdot m+1}}\n\t\t\ty_2^{v_{k \\cdot m+2}}\n\t\t\t\\cdots\n\t\t\ty_m^{v_{(k+1)\\cdot m}}\n\t\t\\Big).\n\t\\end{equation*}\n\tNotice that $\\rho(\\overline{\\pi})$ is not included in (\\ref{eq:pattern-cosets}).\n\tIf $\\rho(\\overline{\\pi})$ is also distinct from each coset representative in (\\ref{eq:pattern-cosets}), then we say that $\\pi$ is a \\emph{strong pattern} and that $(v,\\pi)$ is a \\emph{strongly patterned word}.\n\\end{definition}\n\nTo simplify notation in later sections, we introduce the following sets.\n\n\\begin{definition}\\label{defn:pattern-set}\n\tWe write $\\textsc{Patt} \\subseteq P^*$ for the set of all patterns, and we write $\\textsc{StrPatt} \\subseteq \\textsc{Patt}$ for the set of all strong patterns.\n\tNotice that $\\textsc{Patt}$ and $\\textsc{StrPatt}$ are finite, in particular, $|\\textsc{Patt}| \\leqslant |P|^{d+1}$.\n\\end{definition}\n\nTo simplify notation in \\cref{sec:patterned-words/word-shuffling-algorithm}, we extend this as follows.\n\n\\begin{definition}[Extended Patterned Words]\\label{defn:extended-special-form}\n\tIf $(v,\\pi)$ is a (strongly) patterned word, and $\\sigma \\in S^*$, then $((v,\\pi),\\sigma)$ is an \\emph{extended (strongly) patterned word}.\n\\end{definition}\n\nIn \\cref{algo:word-shuffling}, for each word $\\sigma \\in S^*$, we construct a finite sequence of extended patterned words that begins with $((\\mathbf{0},\\varepsilon),\\sigma)$ and ends with an extended patterned word of the form $((v,\\pi),\\varepsilon)$.\nMoreover, this sequence has the property that $v^\\pi$ and $\\sigma$ represent the same group element with the same weight.\nTo simplify notation, we define the following equivalence relation.\n\n\\begin{definition}\\label{defn:equiv-relation}\n\tWe define the equivalence relation $\\simeq$ on $S^*$ such that, for each $w,\\sigma \\in S^*$, we have $w \\simeq \\sigma$ if and only if both $\\overline{w} = \\overline{\\sigma}$ and $\\omega(w) = \\omega(\\sigma)$.\n\\end{definition}\n\nNotice that if we have a patterned word $(v,\\pi)$ with $v^\\pi \\simeq \\sigma$, then $\\sigma$ is a geodesic if and only if the word $v^\\pi$ is a geodesic.\n\n\\subsection{Word Shuffling}\\label{sec:patterned-words/word-shuffling-algorithm}\n\nIn this section we construct \\cref{algo:word-shuffling} which `shuffles' words of the form $\\sigma \\in S^*$ into patterned words $(v,\\pi)$ which represent the same group element with the same weighted length.\nIn particular, for each word $\\sigma$, we compute a finite sequence of extended patterned words\n\\begin{multline}\\label{eq:patterned-sequence}\n\t((\\mathbf{0},\\varepsilon),\\sigma)\n\t=\n\t((u^{(1)},\\tau^{(1)}),\\sigma^{(1)}),\n\t((u^{(2)},\\tau^{(2)}),\\sigma^{(2)}),\\\\\n\t\\ldots,\n\t((u^{(q)},\\tau^{(q)}),\\sigma^{(q)})\n\t=\n\t((v,\\pi),\\varepsilon),\n\\end{multline}\nsuch that\n\\[\n\t(u^{(i)})^{\\tau^{(i)}} \\sigma^{(i)}\n\t\\simeq\n\t(u^{(i+1)})^{\\tau^{(i+1)}}\\sigma^{(i+1)}\n\t\\quad\n\t\\text{and}\n\t\\quad\n\t|\\sigma^{(i)}|_S > |\\sigma^{(i+1)}|_S\n\\]\nfor each $i$.\nNotice that $v^\\pi \\simeq \\sigma$, and $q \\leqslant |\\sigma|_S+1$ where $q$ is the length of the sequence in (\\ref{eq:patterned-sequence}).\nFrom (\\ref{eq:patterned-sequence}), we define $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$ where the patterned word $(v,\\pi)$ has the property that $v^\\pi \\simeq \\sigma$.\n\nThe idea of \\cref{algo:word-shuffling} is to compute each $((u^{(i+1)},\\tau^{(i+1)}),\\sigma^{(i+1)})$ from its previous extended patterned word $((u^{(i)},\\tau^{(i)}),\\sigma^{(i)})$ by replacing a bounded-length prefix of $\\sigma^{(i)}$ with a strictly shorter word, adding at most a unit vector to $u^{(i)}$, and adding at most one letter to $\\tau^{(i)}$.\nIn order to describe our algorithm, we introduce the following additional notation.\n\nRecall that $d = [G : \\mathbb{Z}^n]$ is the index of the $\\mathbb{Z}^n$ normal subgroup of $G$.\nFor each word $\\sigma \\in S^*$, we fix a bounded-length prefix as follows.\n\n\\begin{definition}[Prefixes]\\label{rmk:short-prefix}\n\tWe write $\\mathrm{Prefix} \\colon S^* \\to S^*$ for the function which computes the prefix of a word of length at most $d$, that is, $\\mathrm{Prefix}(\\sigma) = \\sigma_1 \\sigma_2 \\cdots \\sigma_q$ where $q = \\min(d,|\\sigma|_S)$.\n\tNotice that if $w = \\mathrm{Prefix}(\\sigma)$ with $|w|_S < d$, then $\\sigma = w$.\n\\end{definition}\n\nIn sequence (\\ref{eq:patterned-sequence}), each word $\\sigma^{(i+1)}$ is obtained from $\\sigma^{(i)}$ by replacing the prefix $w^{(i)} = \\mathrm{Prefix}(\\sigma^{(i)})$ with a strictly shorter word $w^{(i)\\prime}$.\nWe write these prefix replacements using the following notation.\n\n\\begin{definition}[Prefix Replacements]\nLet $\\sigma \\in S^*$ be a word which factors as $\\sigma = w\\zeta$ where $w,\\zeta \\in S^*$, then for each word $w' \\in S^*$ we write $(w \\mapsto w') \\cdot \\sigma = w'\\zeta$ which we call a \\emph{prefix replacement}.\nWe write a sequence of replacements as\n\\[\n\t(w_n \\mapsto w'_n)\n\t\\cdots\n\t(w_2 \\mapsto w'_2)\n\t(w_1 \\mapsto w'_1)\n\t\\cdot \\sigma\n\\]\nwhere replacements are composed right-to-left.\nNotice that if $\\sigma' = (w \\mapsto w')\\cdot \\sigma$, then $\\omega(\\sigma') = \\omega(\\sigma) - \\omega(w) + \\omega(w')$ where $\\omega \\colon S^* \\to \\mathbb{N}$ is the weight function.\n\\end{definition}\n\nTo understand how prefix replacements are composed, consider the following.\n\n\\begin{example}\\label{ex:prefix-replacement-sequence}\nWe have the sequence of replacements\n\\begin{equation}\\label{eq:prefix-replacement-example}\n\t(c \\mapsto dc)\n\t(ba \\mapsto cb)\n\t(\\varepsilon \\mapsto b)\n\t\\cdot\n\taz\n\t=\n\tdcbz.\n\\end{equation}\nNotice that if $(w \\mapsto w')\\cdot \\sigma$ is defined, then we have $\\sigma = (w' \\mapsto w)(w \\mapsto w')\\cdot \\sigma$, that is, each prefix replacement has an inverse.\nFor example, from the sequence of prefix replacements given in (\\ref{eq:prefix-replacement-example}), we see that\n\\[\n\taz =\n\t(b \\mapsto \\varepsilon)\n\t(cb \\mapsto ba)\n\t(dc \\mapsto c)\n\t\\cdot\n\tdcbz.\n\\]\nThus, we may compute the inverse of a sequence of prefix replacements.\n\\end{example}\n\nFor each pattern $\\pi$, we write $\\mathcal{N}_\\pi$ for the set of all vectors $v$ for which $(v,\\pi)$ is a patterned word, as defined in \\cref{defn:patterned-words}.\nWe introduce the following notation to simplify the description of our algorithm.\n\n\\begin{definition}\\label{defn:standard-basis-elements}\nFor each pattern $\\pi = \\pi_1 \\pi_2 \\cdots \\pi_k \\in P^*$, we write $\\mathcal{Z}_\\pi$ and $\\mathcal{N}_\\pi$ for the sets $\\mathbb{Z}^{(k+1)m}$ and $\\mathbb{N}^{(k+1)m}$, respectively, where $m = |Y|$.\nMoreover, for each $i \\in \\{ 1,2,\\ldots,\\dim(\\mathcal{Z}_\\pi) \\}$ we write $e_{\\pi,i}$ for the $i$-th standard basis element of $\\mathcal{Z}_\\pi$ and $e_{\\pi,\\varnothing} = \\mathbf{0} \\in \\mathcal{Z}_\\pi$ for the zero vector of $\\mathcal{Z}_\\pi$.\n\\end{definition}\n\nWhen computing (\\ref{eq:patterned-sequence}), it may be the case that $|\\tau^{(i)}|_P \\neq |\\tau^{(i+1)}|_P$ and thus the vectors $u^{(i)}$ and $u^{(i+1)}$ lie in different spaces $\\mathcal{N}_{\\tau^{(i)}}$ and $\\mathcal{N}_{\\tau^{(i+1)}}$, respectively.\nWe define the following map to convert between these spaces.\n\n\\begin{definition}\\label{defn:projection}\nFor each pair of patterns $\\pi,\\tau \\in P^*$, let $t = \\dim(\\mathcal{Z}_\\tau)$ and $p = \\dim(\\mathcal{Z}_\\pi)$, then we define the map $\\mathrm{Proj}_{\\pi,\\tau}\\colon \\mathcal{Z}_\\pi \\to \\mathcal{Z}_\\tau$ such that\n\\[\n\t\\mathrm{Proj}_{\\pi,\\tau}(u_1,u_2,\\ldots,u_p)\n\t=\n\t(u_1,u_2,\\ldots,u_p,0,0,\\ldots,0)\n\\]\nif $t > p$, and\n\\[\n\t\\mathrm{Proj}_{\\pi,\\tau}(u_1,u_2,\\ldots,u_p)\n\t=\n\t(u_1,u_2,\\ldots,u_t)\n\\]\notherwise.\nNotice that if $\\dim(\\mathcal{Z}_\\tau) < \\dim(\\mathcal{Z}_\\pi)$, then $\\mathrm{Proj}_{\\pi,\\tau}$ is a projection; otherwise, $\\dim(\\mathcal{Z}_\\tau) \\geqslant \\dim(\\mathcal{Z}_\\pi)$ and $\\mathrm{Proj}_{\\pi,\\tau}$ is an embedding.\n\\end{definition}\n\nIn order to construct \\cref{algo:word-shuffling}, we need to define a map which explicitly describes how to construct the sequence of extended patterned words in~(\\ref{eq:patterned-sequence}).\nWe construct such a map in the following lemma.\n\n\\begin{lemma}\\label{lemma:map-delta}\n\tWe may construct a map\n\t\\[\n\t\t\\Delta \\colon\n\t\t\\textsc{StrPatt} \\times W_1\n\t\t\\to\n\t\t(\\mathbb{N}_+ \\cup \\{\\varnothing\\}) \\times \\textsc{Patt} \\times W_2,\n\t\\]\n\twhere\n\t\\[\n\t\tW_1 = \\{w \\in S^* \\mid 1 \\leqslant |w|_S \\leqslant d\\}\n\t\t\\quad\\text{and}\\quad\n\t\tW_2 = \\{w \\in S^* \\mid |w|_S < d\\}\n\t\\]\n\twith the following properties.\n\tLet $((u,\\tau),\\sigma)$ be an extended strongly patterned word, and let $\\Delta(\\tau,w) = (x,\\tau',w')$ with $w = \\mathrm{Prefix}(\\sigma)$.\n\tWe may then \\emph{apply} $\\Delta$ to obtain an extended patterned word $((u',\\tau'),\\sigma')$ where $u' = \\mathrm{Proj}_{\\tau,\\tau'}(u)+e_{\\tau',x}$ and $\\sigma' = (w\\mapsto w') \\cdot \\sigma$.\n\tThis will be denoted as\n\t\\[\n\t\t((u,\\tau),\\sigma)\n\t\t\\xrightarrow{\\Delta}\n\t\t((u',\\tau'),\\sigma').\n\t\\]\n\tFor each extended strongly patterned word $((u,\\tau),\\sigma)$,\n\t\\begin{enumerate}\n\t\t\\item\\label{lemma:map-delta:prop1}\n\t\t\t$|\\tau|_P \\leqslant |\\tau'|_P$ and thus $\\mathrm{Proj}_{\\tau,\\tau'}\\colon\\mathcal{N}_\\tau \\to \\mathcal{N}_{\\tau'}$ is an embedding;\n\t\t\\item\\label{lemma:map-delta:prop2}\n\t\t\t$u^\\tau \\sigma \\simeq (u')^{\\tau'}\\sigma'$;\n\t\t\\item\\label{lemma:map-delta:prop3}\n\t\t\t$|\\sigma|_S > |\\sigma'|_S$ and $\\omega(w) > \\omega(w')$; and\n\t\t\\item\\label{lemma:map-delta:prop4}\n\t\t\teither $|\\sigma'|_S = 0$, or $((u',\\tau'),\\sigma')$ is an extended strongly patterned word.\n\t\\end{enumerate}\n\tNotice that property~\\ref{lemma:map-delta:prop4} implies that either $((u',\\tau'),\\sigma')$ is equivalent to the patterned word $(u',\\tau')$, or we may apply $\\Delta$ again.\n\tFrom property~\\ref{lemma:map-delta:prop3}, we see that after finitely many applications of the map $\\Delta$, we have a patterned word.\n\\end{lemma}\n\n\\begin{proof}\n\nLet $\\tau = \\tau_1 \\tau_2 \\cdots \\tau_k \\in P^*$ be a strong pattern, that is, $\\tau$ is a pattern for which the coset representatives\n\\[\n\t\\rho(\\overline{\\varepsilon}),\\,\n\t\\rho(\\overline{\\tau_1}),\\,\n\t\\rho(\\overline{\\tau_1 \\tau_2}),\\,\n\t\\rho(\\overline{\\tau_1 \\tau_2 \\tau_3}),\\,\n\t\\ldots,\\,\n\t\\rho(\\overline{\\tau})\n\\]\nare pairwise distinct.\nThen, from the pigeonhole principle on the $d$ cosets of $\\mathbb{Z}^n$ in $G$, we see that $|\\tau|_P = k < d$.\n\nLet $w \\in S^*$ be a word with length $1 \\leqslant |w|_S \\leqslant d$.\nWe separate the remainder of this proof into the cases where $w \\in P$ and $w \\notin P$ as follows.\n\nSuppose that $w \\in P$, then we have a length $k+1$ pattern $\\tau' = \\tau w$,\nmoreover, from the definition of words in $P$, we see that $|w|_S < d$, and from \\cref{rmk:short-prefix} we have $w = \\sigma$.\nWe then define $\\Delta(\\tau,w) = (\\varnothing, \\tau', \\varepsilon)$.\nFor each extended strongly patterned word $((u,\\tau),w)$ with $u \\in \\mathbb{N}^p$, we then obtain an extended patterned word $((u',\\tau'),\\varepsilon)$ where $u' = \\mathrm{Proj}_{\\tau,\\tau'}(u) = (u_1,u_2,\\ldots,u_p,0,0,\\ldots,0)$.\nNotice that we have $(u')^{\\tau'} = u^\\tau w$.\nThis completes our proof for the case that $w \\in P$.\n\nIn the remainder of this proof, we suppose that $w \\notin P$.\nFrom \\cref{lemma:factoring-words}, we factor $w$ uniquely as $w = \\alpha\\beta\\delta$ where $\\alpha \\in P \\cup \\{\\varepsilon\\}$, $\\beta \\in Y$ and $(|\\alpha|_S,|\\beta|_S)$ is minimal with respect to the lexicographic order on $\\mathbb{N}^2$.\nFrom the labelling $Y = \\{y_1,y_2,\\ldots,y_m\\}$, we see that there must be an index $b$ such that $\\beta = y_b$.\n\nLet $((u,\\tau),\\sigma)$ be an extended strongly patterned word with $w = \\mathrm{Prefix}(\\sigma)$ and $u = (u_0, u_1, \\ldots,u_k)$ where each $u_{a} = (u_{a,1}, u_{a,2},\\ldots,u_{a,m}) \\in \\mathbb{N}^m$. \nThen if we factor $\\sigma$ as $\\sigma = w\\zeta$, we see that\n\\begin{multline*}\n\tu^\\tau \\sigma\n\t=\n\t\\Big(\n\t\ty_1^{u_{0,1}}\n\t\ty_2^{u_{0,2}}\n\t\t\\cdots\n\t\ty_m^{u_{0,m}}\n\t\\Big)\n\t\\tau_1\n\t\\Big(\n\t\ty_1^{u_{1,1}}\n\t\ty_2^{u_{1,2}}\n\t\t\\cdots\n\t\ty_m^{u_{1,m}}\n\t\\Big)\n\t\\tau_2\n\t\\\\\n\t\\cdots\n\t\\tau_{k-1}\n\t\\Big(\n\t\ty_1^{u_{k-1,1}}\n\t\ty_2^{u_{k-1,2}}\n\t\t\\cdots\n\t\ty_m^{u_{k-1,m}}\n\t\\Big)\n\t\\tau_k\n\t\\Big(\n\t\ty_1^{u_{k,1}}\n\t\ty_2^{u_{k,2}}\n\t\t\\cdots\n\t\ty_m^{u_{k,m}}\n\t\\Big)\n\t\\alpha y_b \\delta \\zeta.\n\\end{multline*}\nIf there is an index $a$ with $0 \\leqslant a \\leqslant k$ such that $\\rho(\\overline{\\tau_1 \\tau_2 \\cdots \\tau_a}) = \\rho(\\overline{\\pi \\alpha})$, then the choice of such an index $a$ must be unique, and we see that\n\\[\n\t\\overline{\n\t\t\\tau_{a+1}\n\t\t\\Big(\n\t\t\ty_1^{u_{a+1,1}}\n\t\t\ty_2^{u_{a+1,2}}\n\t\t\t\\cdots\n\t\t\ty_m^{u_{a+1,m}}\n\t\t\\Big)\n\t\t\\tau_{a+2}\n\t\t\\cdots\n\t\t\\tau_k\n\t\t\\Big(\n\t\t\ty_1^{u_{k,1}}\n\t\t\ty_2^{u_{k,2}}\n\t\t\t\\cdots\n\t\t\ty_m^{u_{k,m}}\n\t\t\\Big)\n\t\t\\alpha\n\t} \\in \\mathbb{Z}^n\n\\]\ncommutes with $\\overline{y_b} \\in \\mathbb{Z}^n$, that is,\n\\[\n\t{(u_0,\\ldots,u_{a-1},u_a+e_b,u_{a+1},\\ldots,u_k)}^\\tau\n\t\\alpha \\delta \\zeta\n\t\\simeq\n\tu^\\tau \\alpha y_b \\delta \\zeta\n\t=\n\tu^\\tau \\sigma\n\\]\nwhere $e_b \\in \\mathbb{N}^m$ is the $b$-th standard basis element.\nIn this case we define the map $\\Delta(\\tau,w) = (a\\cdot m+b, \\, \\tau,\\, \\alpha\\delta)$ and our proof is complete.\nOtherwise, we see that the coset representatives\n\\[\n\t\\rho(\\overline{\\varepsilon}),\\,\n\t\\rho(\\overline{\\tau_1}),\\,\n\t\\rho(\\overline{\\tau_1\\tau_2}),\\,\n\t\\rho(\\overline{\\tau_1\\tau_2\\tau_3}),\\,\n\t\\ldots,\\,\n\t\\rho(\\overline{\\tau}),\\,\n\t\\rho(\\overline{\\tau\\alpha})\n\\]\nare pairwise distinct and $\\alpha \\neq \\varepsilon$, that is, $\\alpha \\in P$.\nThen we see that the length $k+1$ word $\\tau' = \\tau \\alpha \\in P^*$ is a strong pattern, and that we have\n\\[\n\t(u_0,u_2,\\ldots,u_k,e_b)^{\\tau'} \\delta \\zeta = u^\\tau \\alpha y_b \\delta\\zeta = u^\\tau\\sigma\n\\]\nwhere $e_b \\in \\mathbb{N}^m$ is the $b$-th standard basis vector.\nAfter defining $\\Delta(\\tau,w) = (a\\cdot k+b, \\tau', \\delta)$ our proof is complete.\n\\end{proof}\n\nWe are now ready to define our algorithm as follows.\n\n\\begin{algorithm}[Word Shuffling]\\label{algo:word-shuffling}\n\tLet $\\Delta$ be the map in \\cref{lemma:map-delta}.\n\tFor each word $\\sigma \\in S^*$, there is a finite sequence of extended patterned words\n\t\\begin{multline}\\label{algo:word-shuffling/sequence}\n\t\t((\\mathbf{0},\\varepsilon),\\sigma)\n\t\t=\n\t\t((u^{(1)},\\tau^{(1)}),\\sigma^{(1)})\n\t\t\\xrightarrow{\\Delta}\n\t\t((u^{(2)},\\tau^{(2)}),\\sigma^{(2)})\n\t\t\\\\\\cdots\n\t\t\\xrightarrow{\\Delta}\n\t\t((u^{(q)},\\tau^{(q)}),\\sigma^{(q)})\n\t\t=\n\t\t((v,\\pi),\\varepsilon).\n\t\\end{multline}\n\tFrom this sequence we define $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$.\n\tNotice from property~\\ref{lemma:map-delta:prop3} in \\cref{lemma:map-delta} that we have\n\t\\[\n\t\t|\\sigma|_S = |\\sigma^{(1)}|_S >\n\t\t|\\sigma^{(2)}|_S >\n\t\t|\\sigma^{(3)}|_S >\n\t\t\\cdots >\n\t\t|\\sigma^{(q)}|_S\n\t\t= 0\n\t\\]\n\tand thus $q \\leqslant |\\sigma|_S + 1$.\nFrom property~\\ref{lemma:map-delta:prop2} in \\cref{lemma:map-delta}, we see that $v^\\pi \\simeq \\sigma$.\n\\end{algorithm}\n\nIn the remainder of this section, we compute the group elements and weights of patterned words, and determine which patterned word represents geodesics.\n\n\\subsection{Geodesic Patterned Words}\\label{sec:patterned-words/properties}\n\nFrom \\cref{algo:word-shuffling}, for each word $\\sigma \\in S^*$ we have a well-defined patterned word $(v,\\pi) = \\mathrm{Shuffle}(\\sigma)$ such that $v^\\pi \\simeq \\sigma$, that is, $v^\\pi$ represents the same group element as $\\sigma$ with the same weight.\nWe see that $\\sigma$ is a geodesic if and only if $v^\\pi$ is a geodesic.\n\nIn this section, we modify an argument of Benson~\\cite{benson1983} and show that the group element and weight of any word $v^\\pi$ can be computed with the use of integer affine transforms, and that we may verify that $v^\\pi$ is a geodesic by checking if the vector $v$ belongs to a polyhedral set $\\mathcal{G}_\\pi$.\n\n\\begin{lemma}\\label{lemma:patterned-word-maps}\n\tFor each pattern $\\pi$, there are integer affine transformations $\\Psi_{\\pi} \\colon \\mathcal{Z}_\\pi \\to \\mathbb{Z}^n$ and $\\Omega_{\\pi} \\colon \\mathcal{Z}_\\pi \\to \\mathbb{Z}$ such that for each patterned word $(v,\\pi)$, we have $\\overline{v^\\pi} = \\Psi_\\pi(v) \\cdot \\rho(\\overline{\\pi})$ and $\\omega(v^\\pi) = \\Omega_\\pi(v)$.\n\\end{lemma}\n\n\\begin{proof}\n\nRecall that in \\cref{defn:sets-Y-P} we fixed a labelling $Y = \\{y_1, y_2, \\ldots, y_m\\}$ where $m  = |Y|$.\nDefine the matrix $Z \\in \\mathbb{Z}^{m \\times n}$ such that $e_i Z = \\overline{y_i}$ for each standard basis vector $e_i \\in \\mathbb{Z}^m$.\nThen, we see that $vZ = \\overline{y_1^{v_1}y_2^{v_2} \\cdots y_m^{v_m}}$ for each $v \\in \\mathbb{N}^m$.\nFor each $p \\in P$ we see that $\\overline{p} x \\overline{p}^{-1} \\in \\mathbb{Z}^n$ for each $x \\in \\mathbb{Z}^n \\triangleleft G$; thus we define matrices $R_p \\in \\mathbb{Z}^{n \\times n}$ such that $x R_p = \\overline{p} x \\overline{p}^{-1}$ for each $x \\in \\mathbb{Z}^n$.\n\nTo compute the element $\\overline{v^\\pi}$ we first rewrite $v^\\pi$ as\n\\begin{multline*}\n\t\\Big(\n\t\ty_1^{v_{1}}\n\t\ty_2^{v_{2}}\n\t\t\\cdots\n\t\ty_m^{v_{m}}\n\t\\Big)\n\t\\cdot\n\t\\pi_1\n\t\\Big(\n\t\ty_1^{v_{m+1}}\n\t\ty_2^{v_{m+2}}\n\t\t\\cdots\n\t\ty_m^{v_{2m}}\n\t\\Big)\n\t\\pi_1^{-1}\n\t\\\\\n\t(\\pi_1 \\pi_2)\n\t\\Big(\n\t\ty_1^{v_{2m+1}}\n\t\ty_2^{v_{2m+2}}\n\t\t\\cdots\n\t\ty_m^{v_{3m}}\n\t\\Big)\n\t(\\pi_1 \\pi_2)^{-1}\n\t\\\\\n\t\\cdots\n\t\\pi\n\t\\Big(\n\t\ty_1^{v_{km+1}}\n\t\ty_2^{v_{km+2}}\n\t\t\\cdots\n\t\ty_m^{v_{(k+1)m}}\n\t\\Big)\n\t\\pi^{-1}\n\t\\cdot\n\t\\pi.\n\\end{multline*}\nThen we see that $\\rho(\\overline{v^\\pi}) = \\rho(\\overline{\\pi})$ and $\\psi(\\overline{v^\\pi}) = \\Psi_{\\pi}(v)$ where\n\\begin{multline*}\n\t\\Psi_{\\pi}(v)\n\t=\n\t(v_1,v_2,\\ldots,v_m) Z +\n\t(v_{m+1},v_{m+2},\\ldots,v_{2m}) Z R_{\\pi_1} +\\\\\n\t\\cdots +\n\t(v_{mk+1},v_{mk+2},\\ldots,v_{(k+1)m}) Z R_{\\pi_k} \\cdots R_{\\pi_2} R_{\\pi_1}\n\t+ \\psi(\\pi).\n\\end{multline*}\nConsidering the word $v^\\pi$ we see that $\\omega(v^\\pi) = \\Omega_{\\pi}(v)$ where\n\\[\n\t\\Omega_{\\pi}(v)\n\t=\n\t\\omega(\\pi) +\n\t\\sum_{j=0}^k \\sum_{i=1}^m\n\t\tv_{jm+i} \\cdot \\omega(y_i).\n\\]\nThe maps $\\Psi_{\\pi} \\colon \\mathcal{Z}_\\pi \\to \\mathbb{Z}^n$ and $\\Omega_{\\pi} \\colon \\mathcal{Z}_\\pi \\to \\mathbb{Z}$ are integer affine transforms.\n\\end{proof}\n\nFrom the integer affine transformations defined in \\cref{lemma:patterned-word-maps} and the closure properties of polyhedral sets we have the following result.\n\n\\begin{lemma}\\label{lemma:geodesics-in-special-form}\n\tFor each pattern $\\pi$, there is a polyhedral set $\\mathcal{G}_{\\pi} \\subseteq \\mathcal{N}_\\pi$ such that $v \\in \\mathcal{G}_{\\pi}$ if and only if $(v,\\pi)$ is a patterned word where $v^\\pi$ is a geodesic.\n\\end{lemma}\n\n\\begin{proof}\nFrom \\cref{algo:word-shuffling} we see that the word $v^\\pi$ is a geodesic if and only if there is no patterned word $(u,\\tau)$ with $\\overline{u^\\tau} = \\overline{v^\\pi}$ and $\\omega(u^\\tau) < \\omega(v^\\pi)$.\nFor each pattern $\\pi$, let $E_{\\pi} \\colon \\mathcal{Z}_\\pi \\to \\mathbb{Z}^{n+1}$ be the integer affine transformation defined as $E_{\\pi} (v) = (\\Psi_{\\pi}(v),\\Omega_{\\pi}(v))$,\nand let $\\mathcal{R} \\subseteq \\mathbb{Z}^{2(n+1)}$ be the polyhedral set\n\\[\n\t\\mathcal{R}\n\t=\n\t\\left\\{\n\t\t(\\nu,\\mu) \\in \\mathbb{Z}^{n+1} \\times \\mathbb{Z}^{n+1}\n\t\\,\\middle\\vert\\,\n\t\\begin{aligned}\n\t\t\\nu_1 = \\mu_1,\\,\n\t\t\\nu_2 = \\mu_2,\\,\n\t\t\\ldots,\\,\n\t\t\\nu_n = \\mu_n\\\\\n\t\t\\text{and }\n\t\t\\nu_{n+1} > \\mu_{n+1}\n\t\\end{aligned}\n\t\\right\\}.\n\\]\nThen, we see that $v^\\pi$ is geodesic if and only if there is no patterned word $(u,\\tau)$ with $\\rho(\\overline{\\tau}) = \\rho(\\overline{\\pi})$ and\n$\n\t\\big(E_{\\pi}(v),E_{\\tau}(u)\\big)\n\t\\in\n\t\\mathcal{R}\n$; or equivalently, $v^\\pi$ is a geodesic if and only if the intersection\n\\[\n\t\\Big(\n\t\tE_{\\pi}(\\{v\\})\n\t\t\\times\n\t\tE_{\\tau}\\!\n\t\t\t\\left(\\mathcal{N}_{\\tau}\\right)\n\t\\Big)\n\t\\cap\n\t\\mathcal{R}\n\\]\nis empty for each pattern $\\tau$ with $\\rho(\\overline{\\tau})=\\rho(\\overline{\\pi})$.\n\nLet $f \\colon \\mathbb{Z}^{n+1}\\times \\mathbb{Z}^{n+1} \\to \\mathbb{Z}^{n+1}$ be the projection onto the first $\\mathbb{Z}^{n+1}$ factor, that is, $f(\\nu,\\mu)=\\nu$ for each $(\\nu,\\mu) \\in \\mathbb{Z}^{n+1} \\times \\mathbb{Z}^{n+1}$.\nLet\n\\[\n\t\\mathcal{D}_{\\pi,\\tau}\n\t=\n\t\\mathcal{N}_{\\pi}\n\t\\cap\n\t\\left[\n\t\t\\left(E_{\\pi}\\right)^{-1}\n\t\tf\\left(\n\t\t\\Big(\n\t\t\tE_{\\pi}\\!\n\t\t\t\\left(\\mathcal{N}_{\\pi}\\right)\n\t\t\t\\times\n\t\t\tE_{\\tau}\\!\n\t\t\t\\left(\\mathcal{N}_{\\tau}\\right)\n\t\t\t\\Big)\n\t\t\t\\cap\n\t\t\t\\mathcal{R}\n\t\t\\right)\n\t\\right]\n.\\]\nThen, we see that $v^\\pi$ is a geodesic if and only if $v \\notin \\mathcal{D}_{\\pi,\\tau}$ for each pattern $\\tau$ with $\\rho(\\overline{\\tau})=\\rho(\\overline{\\pi})$.\nThen, $v^\\pi$ is a geodesic if and only if $v \\in \\mathcal{G}_{\\pi}$ where\n\\[\n\t\\mathcal{G}_{\\pi}\n\t=\n\t\\mathcal{N}_{\\pi}\n\t\\setminus\n\t\\bigcup\n\t\\Big\\{\n\t\t\\mathcal{D}_{\\pi,\\tau}\n\t\\ \\Big\\vert\\ \n\t\t\\tau\n\t\t\\text{ is a pattern with }\n\t\t\\rho(\\overline{\\tau})=\\rho(\\overline{\\pi})\n\t\\Big\\}\n\\]\nwhere we see that the above union is finite as there can be only finitely many patterns.\nMoreover, from the closure properties in \\cref{prop:affine-transforms-of-polyhedral-sets,prop:closure-properties-of-polyhedral-sets} we see that each set $\\mathcal{G}_{\\pi} \\subseteq \\mathcal{N}_\\pi$ is polyhedral.\n\\end{proof}\n\n\\section{Geodesic Growth}\\label{sec:geodesic-growth}\n\n\nIn this section we provide a characterisation of the geodesic growth of virtually abelian groups, in particular, we show that the geodesic growth of a virtually abelian group with respect to any finite weighted monoid generating set is either polynomial with rational geodesic growth series, or exponential with holonomic geodesic growth series.\nThis result is provided in \\cref{thm:geodesic-growth}.\n\nThe result in \\cref{thm:geodesic-growth} is proven by first showing that the geodesic growth series is holonomic, then applying the following lemma.\n\n\\begin{lemma}\\label{lemma:holonomic-growth-series}\n\tIf $G$ has a holonomic geodesic growth series with respect to the weighted monoid generating set $S$, then the geodesic growth is either exponential, or the polynomial of an integer degree with a rational geodesic growth series.\n\\end{lemma}\n\n\\begin{proof}\n\tThe proof follows from \\cref{cor:dichotomy-of-characterisation,lemma:holonomic-power-series-poles}.\n\\end{proof}\n\nIn \\cref{lemma:path-to-special-form}, we construct a weight-preserving bijection from the words in $S^*$ to a subset of paths in a weighted graph $\\Gamma$.\nThen, in \\cref{thm:geodesic-growth} we construct a weight-preserving bijection from the set of such paths which correspond to geodesics, and the set of words in a finite number of polyhedrally constrained languages.\nUsing the theory developed in \\cref{sec:holonomic-functions}, we then prove our result.\nWe begin by constructing the graph $\\Gamma$ as follows.\n\n\\begin{definition}\\label{defn:graph-gamma}\n\tLet $\\Delta$ be the map constructed in \\cref{lemma:map-delta}.\n\tLet $\\Gamma$ be the finite weighted directed edge-labelled graph defined as follows.\n\tFor each pattern $\\tau$ and each word $w \\in S^*$ with $|w|_S \\leqslant d = [G:\\mathbb{Z}^n]$, the graph $\\Gamma$ has a vertex $[\\tau,w] \\in \\mathrm{V}(\\Gamma)$.\n\tSuppose $\\tau \\in \\textsc{StrPatt}$, $|w|_S \\geqslant 1$ and that $\\Delta(\\tau,w) = (x,\\tau',w')$;\n\tif $|w|_S = d$, then for each word $\\xi \\in S^*$ with $|w'\\xi|_S \\leqslant d$, the graph $\\Gamma$ has a labelled edge $[\\tau,w] \\xrightarrow{x} [\\tau',w'\\xi]$;\n\totherwise, $1 \\leqslant |w|_S < d$ and the graph $\\Gamma$ has a labelled edge $[\\tau,w] \\xrightarrow{x} [\\tau',w']$.\n\tMoreover, each such edge has weight $\\omega(w)-\\omega(w') > 0$.\n\\end{definition}\n\nWe are interested in paths of the following form.\n\n\\begin{definition}\\label{defn:path-sets}\n\tFor each pattern $\\pi$, we write $\\textsc{Path}_\\pi$ for the set of paths\n\t\\[\n\t\\textsc{Path}_\\pi\n\t=\n\t\\left\\{\n\t\tp\\colon\n\t\t[\\varepsilon,w]\n\t\t\\to^*\n\t\t[\\pi, \\varepsilon]\n\t\\mid\n\t\tw \\in S^* \\text{ with }|w|_S \\leqslant d\n\t\\right\\}.\n\t\\]\n\tWe write $\\textsc{Path}$ for the union of all such sets, that is,\n\t$\n\t\t\\textsc{Path}\n\t\t=\n\t\t\\bigcup_\\pi \\textsc{Path}_\\pi\n\t$.\n\\end{definition}\n\nWe count the instances of each edge label as follows.\n\n\\begin{definition}\n\tLet $\\alpha \\colon \\textsc{Path} \\to \\bigcup\\{ \\mathcal{N}_\\pi \\mid \\pi \\in \\textsc{Patt} \\}$ map paths $p \\in \\textsc{Path}_\\pi$ to vectors in $\\mathcal{N}_\\pi$ such that the $i$-th component of $\\alpha(p)$ counts the number of edges of $p$ that are labelled with $i$, that is, if\n\t$\n\t\tp\\colon\n\t\t\\nu_1 \\xrightarrow{x_1}\n\t\t\\nu_2 \\xrightarrow{x_2}\n\t\t\\cdots \\xrightarrow{x_k}\n\t\t[\\pi,\\varepsilon] \\in \\textsc{Path}_\\pi,\n\t$\n\tthen we have $\\alpha(p) = v \\in \\mathcal{N}_\\pi$ where each $v_i = \\#\\{j \\mid x_j = i\\}$.\n\\end{definition}\n\nIn the following lemma, we construct a weight-preserving bijection that maps from the set of words $S^*$ to the set of paths $\\textsc{Path}$.\n\n\\begin{lemma}\\label{lemma:path-to-special-form}\n\tWe may construct a weight-preserving bijection $S^* \\to \\textsc{Path}$, which we denote as $\\sigma \\mapsto p_\\sigma$, with the following properties.\n\tFor each word $\\sigma \\in S^*$ where $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$, we have $p_\\sigma \\in \\textsc{Path}_\\pi$.\n\tFor each path $p \\in \\textsc{Path}_\\pi$, there is a unique word $\\sigma \\in S^*$ such that $p = p_\\sigma$ and $v^\\pi \\simeq \\sigma$ where $v = \\alpha(p) \\in \\mathcal{N}_\\pi$.\n\\end{lemma}\n\n\\begin{proof}\nLet $\\sigma \\in S^*$, then from \\cref{algo:word-shuffling} there is a finite sequence\n\\begin{multline}\\label{eq:delta-sequence}\n\t((\\mathbf{0},\\varepsilon),\\sigma)\n\t=\n\t((u^{(1)},\\tau^{(1)}),\\sigma^{(1)})\n\t\\xrightarrow{\\Delta}\n\t((u^{(2)},\\tau^{(2)}),\\sigma^{(2)})\n\t\\\\\\cdots\n\t\\xrightarrow{\\Delta}\n\t((u^{(q)},\\tau^{(q)}),\\sigma^{(q)})\n\t=\n\t((v,\\pi),\\varepsilon).\n\\end{multline}\nLet  $w^{(j)} = \\mathrm{Prefix}(\\sigma^{(j)})$ and $\\Delta(\\tau^{(j)},w^{(j)}) = (x^{(j+1)},\\tau^{(j+1)},w^{(j)\\prime})$.\n\nFrom \\cref{lemma:map-delta} we see that each $\\sigma^{(j+1)} = (w^{(j)}\\mapsto w^{(j)\\prime})\\cdot \\sigma^{(j)}$.\nThen,\n\\begin{equation}\\label{eq:path-to-word}\n\t\\sigma\n\t=\n\t(w^{(1)\\prime}\\mapsto w^{(1)})\n\t(w^{(2)\\prime}\\mapsto w^{(2)})\n\t\\cdots\n\t(w^{(q-1)\\prime}\\mapsto w^{(q-1)})\n\t\\cdot\n\t\\varepsilon\n\\end{equation}\nand thus\n\\begin{multline}\\label{eq:total-weight}\n\t\\omega(\\sigma)\n\t=\n\t(\\omega(w^{(1)}) - \\omega(w^{(1)\\prime}))\n\t+ (\\omega(w^{(2)}) - \\omega(w^{(2)\\prime}))\\\\\n\t+ \\cdots\n\t+ (\\omega(w^{(q-1)}) - \\omega(w^{(q-1)\\prime})).\n\\end{multline}\nMoreover, from the properties of $\\Delta$ given in \\cref{lemma:map-delta}, and the definition of the graph $\\Gamma$ given in \\cref{defn:graph-gamma}, we see that\n\\begin{multline}\\label{eq:path-p}\n\tp_\\sigma \\colon\n\t[\\varepsilon,w]\n\t=\n\t\t[\\tau^{(1)}, w^{(1)}]\n\t\\xrightarrow{x^{(2)}}\n\t\t[\\tau^{(2)}, w^{(2)}]\n\t\\xrightarrow{x^{(3)}}\\\\\n\t\\cdots\n\t\\xrightarrow{x^{(q-1)}}\n\t\t[\\tau^{(q-1)}, w^{(q-1)}]\n\t\\xrightarrow{x^{(q)}}\n\t\t[\\tau^{(q)}, w^{(q)}]\n\t= [\\pi, \\varepsilon]\n\\end{multline}\nis a path in $\\textsc{Path}_\\pi$.\nNotice that the weight of the path $p_\\sigma$ is the same as the weight of $\\sigma$ in (\\ref{eq:total-weight}) and thus the map $\\sigma \\mapsto p_\\sigma$ is weight preserving.\nIt remains to be shown that the map $\\sigma \\mapsto p_\\sigma$ is a bijection.\n\nSuppose that we are given a path $p_\\sigma$ as in (\\ref{eq:path-p}).\nThen, we may recover the words $w^{(i)\\prime}$ as $\\Delta(\\tau^{(j)},w^{(j)}) = (x^{(j+1)},\\tau^{(j+1)},w^{(j)\\prime})$.\nHence, we may recover the word $\\sigma$ using equation (\\ref{eq:path-to-word}).\nThus, we see that the map $\\sigma \\mapsto p_\\sigma$ is one-to-one.\nIt remains to be shown that the map $\\sigma \\mapsto p_\\sigma$ is onto, that is, for each $p \\in \\textsc{Path}$, there is a word $\\sigma$ such that $p = p_\\sigma$.\n\nLet $p \\in \\textsc{Path}_\\pi$ be a path written as \n\\begin{multline*}\n\tp \\colon\n\t[\\varepsilon,w]\n\t=\n\t[\\tau^{(1)}, w^{(1)}]\n\t\\xrightarrow{x^{(2)}}\n\t[\\tau^{(2)}, w^{(2)}]\n\t\\xrightarrow{x^{(3)}}\\\\\n\t\\cdots\n\t\\xrightarrow{x^{(q-1)}}\n\t[\\tau^{(q-1)}, w^{(q-1)}]\n\t\\xrightarrow{x^{(q)}}\n\t[\\tau^{(q)}, w^{(q)}]\n\t= [\\pi, \\varepsilon].\n\\end{multline*}\nLet $\\Delta(\\tau^{(j)},w^{(j)}) = (x^{(j+1)},\\tau^{(j+1)},w^{(j)\\prime})$.\nWe define the words $\\sigma^{(j)}$ such that\n\\[\n\t\\sigma^{(j)}\n\t=\n\t(w^{(j)\\prime}\\mapsto w^{(j)})\n\t\\cdot\n\t\\sigma^{(j+1)}\n\\]\nand $\\sigma^{(q)} = \\varepsilon$.\nWe define the vectors $u^{(j)} \\in \\mathcal{N}_{\\tau^{(j)}}$ such that\n\\[\n\tu^{(j+1)}\n\t=\n\t\\mathrm{Proj}_{\\tau^{(j)},\\tau^{(j+1)}}(u^{(j)})\n\t+ e_{\\tau^{(j+1)},x^{(j+1)}}\n\\]\nand $u^{(1)} = \\mathbf{0} \\in \\mathcal{N}_{\\tau^{(1)}}$.\nFrom the property~\\ref{lemma:map-delta:prop1} in \\cref{lemma:map-delta} we see that each $|\\tau^{(j)}|_P \\leqslant |\\tau^{(j+1)}|_P$, and thus from \\cref{defn:projection} we see that\n$u^{(q)} = \\alpha(p)$.\nLet $\\sigma = \\sigma^{(1)}$ and $v = u^{(q)}$, then we see that\n\\begin{multline*}\n\t((\\mathbf{0},\\varepsilon),\\sigma)\n\t=\n\t((u^{(1)},\\tau^{(1)}),\\sigma^{(1)})\n\t\\xrightarrow{\\Delta}\n\t((u^{(2)},\\tau^{(2)}),\\sigma^{(2)})\n\t\\\\\\cdots\n\t\\xrightarrow{\\Delta}\n\t((u^{(q)},\\tau^{(q)}),\\sigma^{(q)})\n\t=\n\t((v,\\pi),\\varepsilon).\n\\end{multline*}\nFrom this, we see that $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$ and that $p = p_\\sigma$ with $\\sigma \\simeq v^\\pi$ where $v = \\alpha(p) \\in \\mathcal{N}_\\pi$.\nMoreover, we see that the map $\\sigma \\mapsto p_\\sigma$ is onto.\n\\end{proof}\n\nWe may now prove our first main theorem as follows.\n\n\\setcounter{theoremx}{0}\n\\TheoremGeodesicGrowth\n\n\\begin{proof}\n\nFrom \\cref{lemma:path-to-special-form}, we may compute the geodesic growth function as\n\\begin{equation}\\label{eq:geod-growth-sum}\n\t\\gamma_S(k)\n\t=\n\t\\sum_{\\pi \\in \\textsc{Patt}}\n\t\\#\n\t\\{\n\t\tp \\in \\textsc{Path}_\\pi\n\t\\mid\n\t\t\\omega(p) \\leqslant k\n\t\t\\text{ and }\\alpha(p) \\in \\mathcal{G}_\\pi\n\t\\}\n\\end{equation}\nwhere $\\omega(p)$ is the weight of $p$, and $\\mathcal{G}_\\pi$ is the polyhedral set in \\cref{lemma:geodesics-in-special-form}.\nNotice that (\\ref{eq:geod-growth-sum}) is a finite sum as we have only finitely many patterns.\n\nLet $\\Sigma$ be the weighted finite alphabet which contains the edges of $\\Gamma$, that is, for each edge $e\\colon \\nu_1 \\xrightarrow{x} \\nu_2$ in $\\Gamma$, there is a letter $(\\nu_1,x,\\nu_2) \\in \\Sigma$ with weight $\\omega(e)$.\nThen, for each pattern $\\pi$, we have a weight-preserving bijection from the paths in $\\textsc{Path}_\\pi$ to the words in a language $L_\\pi \\subseteq \\Sigma^*$, in particular, the language $L_\\pi$ contains all words of the form\n\\[\n\t([\\varepsilon,w],x_1,\\nu_1)\n\t(\\nu_1,x_2,\\nu_2)\n\t(\\nu_2,x_3,\\nu_3)\n\t\\cdots\n\t(\\nu_k,x_{k+1},[\\pi,\\varepsilon]) \\in \\Sigma^*.\n\\]\nNotice that each $L_\\pi$ is a regular language.\n\nWe write $\\Phi(\\nu_1,x,\\nu_2) \\in \\mathbb{N}^{|\\Sigma|}$ to denote the Parikh vector corresponding to the letter $(\\nu_1,x,\\nu_2) \\in \\Sigma$.\nFor each pattern $\\pi$, we define an integer affine transform $E_\\pi \\colon \\mathbb{Z}^{|\\Sigma|} \\to \\mathcal{Z}_\\pi$ such that $E_\\pi(\\Phi(\\nu_1,x,\\nu_2)) = e_{\\pi,x}$ is the $x$-th standard basis element for each $x \\in \\{1,2,\\ldots,\\dim(\\mathcal{Z}_\\pi)\\}$, and $E_\\pi(\\Phi(\\nu_1,x,\\nu_2)) = \\mathbf{0}$ otherwise.\nLet $w \\in L_\\pi$ be the word corresponding to the path $p \\in \\textsc{Path}_\\pi$, then we see that $\\alpha(p) = E_\\pi(\\Phi(w))$.\nFrom \\cref{lemma:path-to-special-form}, we see that the path $p$ corresponds to a geodesic if and only if $\\Phi(w) \\in E^{-1}_\\pi (\\mathcal{G}_\\pi)$.\n\nFor each pattern $\\pi$, we define the constrained language $L^\\mathrm{geod}_\\pi \\subseteq L_\\pi$ as\n\\[\n\tL_\\pi^\\mathrm{geod}\n\t=\n\t\\{\n\t\tw \\in L_\\pi\n\t\\mid\n\t\t\\Phi(w) \\in E^{-1}(\\mathcal{G}_\\pi)\n\t\\}.\n\\]\nNotice that there is a weight-preserving bijection between $L^\\mathrm{geod}_\\pi$ and the set of geodesics $\\sigma \\in S^*$ with $p_\\sigma \\in \\textsc{Path}_\\pi$.\nFrom \\cref{prop:affine-transforms-of-polyhedral-sets} we see that $E^{-1}(\\mathcal{G}_\\pi)$ is a polyhedral set and thus each $L^\\mathrm{geod}_\\pi$ is a polyhedrally constrained language, as studied in \\cref{sec:polyhedrally-constrained-languages}.\nThen, from \\cref{prop:polyhedrally-constrained-is-holonomic} we see that the multivariate generating function $f_\\pi(x_1,x_2,\\ldots,x_{|\\Sigma|})$ of each $L^\\mathrm{geod}_\\pi$ is holonomic.\n\nLet $a_{\\pi,i}\\in \\mathbb{N}_+$ be the weight of the letter that corresponds to the variable $x_{i}$ in the generating function $f_\\pi(x_1,x_2,\\ldots,x_{|\\Sigma|})$.\nLet $h_\\pi(z) \\in \\mathbb{C}[[z]]$ be defined as\n\\[\n\th_\\pi(z) =\n\tf_\\pi(z^{a_{\\pi,1}}, z^{a_{\\pi,2}}, \\ldots, z^{a_{\\pi,|\\Sigma|}}).\n\\]\nThen we see that the coefficient of $z^k$ in $h_\\pi(z)$ counts the geodesics $\\sigma \\in S^*$ for which $p_\\sigma \\in \\textsc{Path}_\\pi$ and $\\omega(\\sigma) = k$.\nLet $g(z) \\in \\mathbb{C}[[z]]$ be defined as\n\\[\n\tg(z) = \\frac{1}{1-z} \\cdot \\sum_{\\pi \\in \\textsc{Patt}} h_\\pi(z),\n\\]\nThen we see that the coefficient of $z^k$ in $g(z)$ is given by $\\gamma_S(k)$, that is, $g(z)$ is the geodesic growth series $g(z) = \\sum_{k = 0}^\\infty \\gamma_S(k) z^k$.\nMoreover, from the closure properties in \\cref{lemma:holonomic-closure-properties} we see that the function $g(z)$ is holonomic.\n\nOur result then follows from \\cref{lemma:holonomic-growth-series}.\n\\end{proof}\n\n\\section{Language of Geodesics}\\label{sec:language-of-geodesics}\n\nIn the previous section, we characterised the geodesic growth of virtually abelian groups.\nIn our proof of this result, we found a bijection between the geodesics of the virtually abelian group and a finite union of formal languages.\nIt is then natural to ask if there is a formal language characterisation for the language of geodesics.\nIn this section we show that the language of geodesics can be recognised by blind multicounter automaton.\nInformally, we prove this result in \\cref{thm:virtually-abelian-are-blind-counter} by implementing \\cref{algo:word-shuffling} on a blind multicounter automaton, we then check if the word is geodesic using \\cref{lemma:geodesics-in-special-form}.\n\n\\setcounter{theoremx}{2}\n\\TheoremBlindMulticounter\n\n\\begin{proof}\n\nLet $G$ be a virtually abelian group that is generated as a monoid by a finite weighted set $S$, and let $\\mathbb{Z}^n \\triangleleft G$ with finite index $d = [G : \\mathbb{Z}^n]$.\nLet $\\sigma \\in S^*$, then from \\cref{algo:word-shuffling} we have a patterned word $(v,\\pi) = \\mathrm{Shuffle}(\\sigma)$ for which $v^\\pi \\simeq \\sigma$ and thus $\\sigma$ is a geodesic if and only if $v \\in \\mathcal{G}_{\\pi}$ where $\\mathcal{G}_\\pi \\subseteq \\mathcal{N}_\\pi$ is the polyhedral set given by \\cref{lemma:geodesics-in-special-form}.\n\nThe idea of our proof is to simulate \\cref{algo:word-shuffling} on a blind multicounter automaton, while maintaining enough information on the machine's counters so that we may verify the membership of the vector $v$ to the set $\\mathcal{G}_{\\pi}$.\n\nFor each polyhedral set $\\mathcal{G}_\\pi$, we fix a finite union of basic polyhedral sets\n\\[\n\t\\mathcal{G}_{\\pi}\n\t=\n\t\\bigcup_{i=1}^{N_\\pi}\n\t\\mathcal{B}_{\\pi,i}.\n\\]\nThen, for each basic polyhedral set $\\mathcal{B}_{\\pi,i}$, we fix a finite intersection\n\\begin{multline}\\label{eq:decompose-basic-poly}\n\t\\mathcal{B}_{\\pi,i}\n\t=\n\t\\bigcap_{j=1}^{K_{\\pi,i,1}}\n\t\t\\left\\{\n\t\t\tz \\in \\mathcal{Z}_\\pi\n\t\t\\,\\middle\\vert\\,\n\t\t\t\\alpha_{\\pi,i,j} \\cdot z > \\beta_{\\pi,i,j}\n\t\t\\right\\}\n\t\\\\\\cap\n\t\\bigcap_{j=1}^{K_{\\pi,i,2}}\n\t\t\\left\\{\n\t\t\tz \\in \\mathcal{Z}_\\pi\n\t\t\\,\\middle\\vert\\,\n\t\t\t\\chi_{\\pi,i,j} \\cdot z \\equiv \\eta_{\\pi,i,j}\\ (\\bmod\\ \\theta_{\\pi,i,j})\n\t\t\\right\\}\n\t\\\\\\cap\n\t\\bigcap_{j=1}^{K_{\\pi,i,3}}\n\t\t\\left\\{\n\t\t\tz \\in \\mathcal{Z}_\\pi\n\t\t\\,\\middle\\vert\\,\n\t\t\t\\xi_{\\pi,i,j} \\cdot z = \\lambda_{\\pi,i,j}\n\t\t\\right\\}\n\\end{multline}\nwhere $\\alpha_{\\pi,i,j},\\chi_{\\pi,i,j},\\xi_{\\pi,i,j} \\in \\mathcal{Z}_\\pi$, $\\beta_{\\pi,i,j},\\eta_{\\pi,i,j},\\lambda_{\\pi,i,j} \\in \\mathbb{Z}$ and $\\theta_{\\pi,i,j} \\in \\mathbb{N}_+$.\n\nLet $k \\in \\mathbb{N}$ be such that $k \\geqslant K_{\\pi,i,1} + K_{\\pi,i,2} + K_{\\pi,i,3}$ for each basic polyhedral set $\\mathcal{B}_{\\pi,i}$.\nIn the remainder of this proof, we construct a blind $k$-counter automaton $M = (Q,S,\\delta,q_0,F,\\mathfrak{e})$ that recognises the language of geodesics.\nNotice that the input alphabet of the machine is the generating set $S$.\n\nFor each basic polyhedral set $\\mathcal{B}_{\\pi,i}$, we define a map $C_{\\pi,i} \\colon \\mathcal{N}_\\pi \\to \\mathbb{Z}^k$ as\n\\begin{multline}\\label{eq:configuration-of-counters}\n\tC_{\\pi,i}(v) = (\n\t\t\\alpha_{\\pi,i,1} \\cdot {v},\\,\n\t\t\\alpha_{\\pi,i,2} \\cdot {v},\\,\n\t\t\\ldots,\\,\n\t\t\\alpha_{\\pi,i,K_{\\pi,i,1}} \\cdot {v},\n\t\\\\\n\t\t\\chi_{\\pi,i,1} \\cdot {v},\\,\n\t\t\\chi_{\\pi,i,2} \\cdot {v},\\,\n\t\t\\ldots,\\,\n\t\t\\chi_{\\pi,i,K_{\\pi,i,2}} \\cdot {v},\\,\n\t\\\\\n\t\t\\xi_{\\pi,i,1} \\cdot {v},\\,\n\t\t\\xi_{\\pi,i,2} \\cdot {v},\\,\n\t\t\\ldots,\\,\n\t\t\\xi_{\\pi,i,K_{\\pi,i,3}} \\cdot {v},\n\t\t0,0,\\ldots,0\n\t).\n\\end{multline}\nNotice that a vector $v \\in \\mathcal{N}_{\\pi}$ belongs to $\\mathcal{B}_{\\pi,i}$ if and only if\n\\[\n\tC_{\\pi,i}(v)\n\t=\n\t(\n\t\ta_1, a_2,\\ldots, a_{K_{\\pi,i,1}},\\,\n\t\tb_1, b_2,\\ldots, b_{K_{\\pi,i,2}},\\,\n\t\tc_1, c_2,\\ldots, c_{K_{\\pi,i,3}},\\,\n\t\t0,0,\\ldots,0\n\t)\n\\]\nwhere each $a_{j} > \\beta_{\\pi,i,j}$, each $b_j \\equiv \\eta_{\\pi,i,j}\\ (\\bmod\\ \\theta_{\\pi,i,j})$ and each $c_{j} = \\lambda_{\\pi,i,j}$.\n\n\\proofsection{State-Space of the Machine}\n\nFor each $\\tau \\in \\textsc{Patt}$, each basic polyhedral set $\\mathcal{B}_{\\pi,i}$, and each word $w \\in S^*$ with $|w|_S \\leqslant d$, we have a state of the form $[\\tau,w,\\pi,i] \\in Q$.\nFrom these states, the machine will perform \\cref{algo:word-shuffling} on its input word.\n\nDuring the construction of our machine, we will ensure that if\n\\[\n\t(q_0,(0,0,\\ldots,0),\\sigma\\mathfrak{e})\n\t\\vdash^*\n\t([\\tau,w,\\pi,i],(c_1,c_2,\\ldots,c_k),\\zeta\\mathfrak{e}),\n\\]\nthen there is a $u \\in \\mathcal{N}_\\tau$ with $u^\\tau w \\zeta \\simeq \\sigma$ and $(c_1,c_2,\\ldots,c_k) = C_{\\pi,i}(\\mathrm{Proj}_{\\tau,\\pi}(u))$.\nIn particular, this vector will correspond to some vector $u^{(i)}$ in the sequence of extended patterned words given in (\\ref{algo:word-shuffling/sequence}) as constructed in \\cref{algo:word-shuffling}.\n\nFor each basic polyhedral set $\\mathcal{B}_{\\pi,i}$, we have an accepting state $q_{\\pi,i} \\in F$.\nMoreover, our construction will have the property that $(q_0,\\mathbf{0},\\sigma\\mathfrak{e})\\vdash^*(q_{\\pi,i},\\mathbf{0},\\mathfrak{e})$ if and only if $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$ with $v \\in \\mathcal{B}_{\\pi,i}$,\nand thus the machine $M$ will accept the word $\\sigma$ if and only if it is a geodesic.\n\n\\proofsection{Nondeterministically Guessing a Basic Polyhedral Set}\n\nThe machine $M$ begins simulating the word shuffling algorithm after nondeterministically guessing a basic polyhedral set $\\mathcal{B}_{\\pi,i}$ for which $\\mathrm{Shuffle}(\\sigma) = (v,\\pi)$ with $v \\in \\mathcal{B}_{\\pi,i}$.\nNotice that such a choice of basic polyhedral set exists if and only if $\\sigma$ is a geodesic.\nWe accomplish this by introducing a relation\n\\[\n\t((q_0,\\varepsilon),([\\varepsilon,\\varepsilon,\\pi,i],\\mathbf{0})) \\in \\delta\n\\]\nfor each basic polyhedral set $\\mathcal{B}_{\\pi,i}$,\nthat is, we have a transition\n\\begin{equation}\\label{eq:first-transition}\n\t(q_0,(0,0,\\ldots,0),\\sigma\\mathfrak{e})\n\t\\vdash\n\t([\\varepsilon,\\varepsilon,\\pi,i],(0,0,\\ldots,0),\\sigma\\mathfrak{e})\n\\end{equation}\nfor each $\\mathcal{B}_{\\pi,i}$.\nNotice that $\\mathbf{0}^\\varepsilon\\sigma \\simeq \\sigma$ and $(0,0,\\ldots,0) = C_{\\pi,i}(\\mathrm{Proj}_{\\varepsilon,\\pi}(\\mathbf{0}))$.\n\n\\proofsection{Performing the Word Shuffling Algorithm}\n\nFor each extended strongly patterned word $((u^{(i)},\\tau^{(i)}),\\sigma^{(i)})$ in sequence (\\ref{algo:word-shuffling/sequence}) in \\cref{algo:word-shuffling}, we will see that $M$ has configurations of the form\n\\[\n\t([w,\\tau^{(i)},\\pi,i],C_{\\pi,i}(u^{(i)}),\\zeta)\n\\]\nwhere $\\sigma^{(i)} = w\\zeta$.\nIn order to apply the map $\\Delta$ from such a configuration we will require that $w = \\mathrm{Prefix}(\\sigma)$.\nWe do so by introducing transitions as follows.\n\nLet $([\\tau,w,\\pi,i], (c_1, c_2, \\ldots, c_k), \\zeta\\mathfrak{e})$ be a configuration of $M$ and let $\\sigma = w \\zeta$,\nthen $w = \\mathrm{Prefix}(\\sigma)$ if and only if either $|w|_S = d$ or $\\zeta = \\varepsilon$.\nThus, for each word $w \\in S^*$ with $|w|_S < d$ and each $s \\in S$, we introduce a relation of the form\n\\[\n\t(([\\tau,w,\\pi,i],s),([\\tau,ws,\\pi,i],\\mathbf{0})) \\in \\delta\n\\]\nfor each $\\tau,\\pi,i$.\nFrom these relations we have a unique partial computation\n\\begin{equation}\\label{eq:finding-prefix}\n\t([\\tau,w,\\pi,i], (c_1, c_2, \\ldots, c_k), \\zeta\\mathfrak{e})\n\t\\vdash^*\n\t([\\tau,w',\\pi,i], (c_1, c_2, \\ldots, c_k), \\zeta'\\mathfrak{e})\n\\end{equation}\nwhere $w' = \\mathrm{Prefix}(\\sigma)$ and $\\sigma = w\\zeta = w'\\zeta'$.\nWe then apply the map $\\Delta$ as follows.\n\nLet $\\tau \\in \\textsc{StrPatt}$ be a strong pattern, let $w,\\zeta \\in S^*$ with $w = \\mathrm{Prefix}(w\\zeta)$ and $|w|_S \\geqslant 1$, and let $\\Delta(\\tau,w) = (x,\\tau',w')$.\nFrom \\cref{lemma:map-delta}, we see that for each vector $u \\in \\mathcal{N}_\\tau$ we have $(u')^{\\tau'}w'\\zeta \\simeq u^\\tau w \\zeta$ where $u' = \\mathrm{Proj}_{\\tau,\\tau'}(u)+e_{\\tau',x}$.\nMoreover, we see that\n\\[\n\tC_{\\pi,i}(\\mathrm{Proj}_{\\tau,\\pi}(u')) =\n\t\tC_{\\pi,i}(\\mathrm{Proj}_{\\tau,\\pi}(u)) +\n\t\tC_{\\pi,i}(\\mathrm{Proj}_{\\tau',\\pi}(e_{\\tau',x})).\n\\]\nNotice that $w = \\mathrm{Prefix}(w\\zeta)$ if and only if either $|w|_S = d$ or $\\zeta = \\varepsilon$.\nIf $|w|_S = d$, then we introduce the relation\n\\[\n\t(([\\tau,w,\\pi,i],\\varepsilon),([\\tau',w',\\pi,i],C_{\\pi,i}(\\mathrm{Proj}_{\\tau',\\pi}(e_{\\tau',x})))) \\in \\delta\n\\]\nfor each $\\pi,i$;\notherwise, if $|w|_S < d$, then we introduce the relation\n\\[\n\t(([\\tau,w,\\pi,i],\\mathfrak{e}),([\\tau',w',\\pi,i],C_{\\pi,i}(\\mathrm{Proj}_{\\tau',\\pi}(e_{\\tau',x})))) \\in \\delta\n\\]\nfor each $\\pi,i$.\nThat is, we may apply the map $\\Delta$ with the above relations.\n\nCombining these transitions with those described in (\\ref{eq:finding-prefix}), we see that after nondeterministically choosing a basic polyhedral set in (\\ref{eq:first-transition}), the machine will deterministically perform \\cref{algo:word-shuffling}, then enter a configuration of the form\n\\begin{equation}\\label{eq:after-word-shuffle}\n\t(\n\t\t[\\tau,\\varepsilon,\\pi,i],(c_1, c_2,\\ldots,c_k), \\mathfrak{e}\n\t)\n\\end{equation}\nwith $(c_1,c_2,\\ldots, c_k) = C_{\\pi,i}(v)$ where $(v,\\tau) = \\mathrm{Shuffle}(\\sigma)$.\n\nFor each pair of patterns $\\pi,\\tau$ with $\\pi \\neq \\tau$, and each basic polyhedral set $\\mathcal{B}_{\\pi,i}$, the machine has no transitions out of any configuration $([\\tau,\\varepsilon,\\pi,i],c,\\mathfrak{e})$ where $c \\in \\mathbb{Z}^k$.\nHence, if the computation enters such a state, it cannot continue to an accepting configuration.\nThus, we may assume without loss of generality that the machine nondeterministically chose the basic polyhedral set $\\mathcal{B}_{\\pi,i}$ with $\\pi = \\tau$ when performing the transition in (\\ref{eq:first-transition}).\nIn the rest of our proof, we describe how the machine verifies that $v \\in \\mathcal{B}_{\\pi,i}$.\n\n\\proofsection{Checking Polyhedral Set Membership}\n\nSuppose that\n\\[\n\t(q_0,(0,0,\\ldots,0),\\sigma\\mathfrak{e})\n\t\\vdash^*\n\t([\\pi,\\varepsilon,\\pi,i],(c_1,c_2,\\ldots,c_k),\\mathfrak{e}),\n\\]\nthen $(c_1,c_2,\\ldots,c_k) = C_{\\pi,i}(v)$ where $(v,\\pi) = \\mathrm{Shuffle}(\\sigma)$.\nFor each state of the form $[\\pi,\\varepsilon,\\pi,i]$, we introduce a relation\n\\[\n\t(([\\pi,\\varepsilon,\\pi,i],\\mathfrak{e}),(q_{\\pi,i},\\mu_{\\pi,i})) \\in \\delta\n\\]\nwhere\n\\begin{multline*}\n\t\\mu_{\\pi,i}\n\t=\n\t(\n\t\t-\\beta_{\\pi,i,1}-1,\n\t\t-\\beta_{\\pi,i,2}-1,\n\t\t\\ldots,\n\t\t-\\beta_{\\pi,i,k}-1,\n\t\\\\\n\t\t-\\eta_{\\pi,i,1},\n\t\t-\\eta_{\\pi,i,2},\n\t\t\\ldots\n\t\t-\\eta_{\\pi,i,k},\n\t\\\\\n\t\t-\\lambda_{\\pi,i,1},\n\t\t-\\lambda_{\\pi,i,2},\n\t\t\\ldots\n\t\t-\\lambda_{\\pi,i,k},\n\t\t0,0,\\ldots,0\n\t).\n\\end{multline*}\nFrom this relation we have\n\\[\n\t([\\pi,\\varepsilon,\\pi,i],(c_1,c_2,\\ldots,c_k),\\mathfrak{e})\n\t\\vdash\n\t(q_{\\pi,i},(c'_1,c'_2,\\ldots,c'_k),\\mathfrak{e})\n\\]\nwhere $v \\in \\mathcal{B}_{\\pi,i}$ if and only if $(c'_1,c'_2,\\ldots,c'_k)$ belongs to the set\n\\[\n\t\\mathbb{N}^{K_{\\pi,i,1}} \\times \n\t\\theta_{\\pi,i,1}\\mathbb{Z}\n\t\\times \\theta_{\\pi,i,2}\\mathbb{Z}\n\t\\times \\cdots\n\t\\times \\theta_{\\pi,i,K_{\\pi,i,2}}\\mathbb{Z}\n\t\\times \\{0\\}^{k-K_{\\pi,i,1}-K_{\\pi,i,2}}.\n\\]\nWe verify $v$'s membership to $\\mathcal{B}_{\\pi,i}$ by introducing additional relations as follows.\nFor each $1 \\leqslant j \\leqslant K_{\\pi,i,1}$, we have\n\\[\n\t((q_{\\pi,i},\\mathfrak{e}),(q_{\\pi,i},-e_j)) \\in \\delta,\n\\]\nwhere $e_j \\in \\mathbb{Z}^k$ is the $j$-th standard basis element, and for each $ 1 \\leqslant j \\leqslant  K_{\\pi,i,2}$\n\\[\n\t((q_{\\pi,i},\\mathfrak{e}),(q_{\\pi,i},\\pm\\theta_{\\pi,i,j} \\, e_{j'})) \\in \\delta\n\\]\nwhere $j' = K_{\\pi,i,1}+j$ and $e_{j'} \\in \\mathbb{Z}^k$ is the $j'$-th standard basis element.\nFrom these relations, we see that we see that\n\\[\n\t(q_0,(0,0,\\ldots,0),\\sigma\\mathfrak{e})\n\t\\vdash^*\n\t(q_{\\pi,i},(0,0,\\ldots,0),\\mathfrak{e}),\n\\]\nif and only if $v \\in \\mathcal{B}_{\\pi,i}$ where $(v,\\pi) = \\mathrm{Shuffle}(\\sigma)$.\n\\end{proof}\n\n\\section{Concluding Remarks}\\label{sec:virt-abel/concluding}\n\nIn this chapter we characterised the geodesic growth for all virtually abelian groups with respect to every generating set.\nMoreover, the proofs in this chapter are constructive, i.e., it is possible to compute the geodesic growth series for any given virtually abelian group.\n\n\\Citeauthor{bridson2012} gave a sufficient condition for a virtually abelian groups to have polynomial geodesic growth (see \\cref{lem:bbes-main-theorem}).\nIt would be interesting to see if this condition is also necessary, that is, we ask the following question.\n\n\\begin{question}\n\tLet $G$ be a virtually abelian group with polynomial geodesic growth.\n\tThen, is there an element $g \\in G$ whose normal closure is a finite-index abelian subgroup of $G$?\n\\end{question}\n\nRecall that the geodesic growth is bounded from below by the volume growth, and thus, any group with polynomial geodesic growth must be virtually nilpotent.\nIn this chapter, we have shown that for any abelian group $A$, there is a virtually-$A$ group with polynomial geodesic growth (see the presentation in \\cref{eq:virt-abel-polynomial}); and we have provided a method to determine if a virtually abelian group has polynomial geodesic growth.\nUntil now, the only known examples of polynomial geodesic growth have been virtually abelian, e.g., the groups studied by \\textcite{bridson2012}.\nIt is then natural to ask if every group with polynomial geodesic growth is virtually abelian, and if not, then what counterexamples are there.\nIn \\cref{chapter:virtually-heisenberg}, we take the next step towards answering this question, and in moving forward to a classification of polynomial geodesic growth.", "meta": {"hexsha": "970c21c67b560362d603fd34ca54f6c811ccb59a", "size": 55719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/05_Virtually_Abelian.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/05_Virtually_Abelian.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/05_Virtually_Abelian.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": 46.6267782427, "max_line_length": 356, "alphanum_fraction": 0.6683895978, "num_tokens": 20307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6025074326309379}}
{"text": "\\chapter{Ranks}\n\\section{Ramanujan's and Dyson's Work}\n\nThe following are the most celebrated congruences due to Ramanujan,\n\n\\begin{equation}\n    p(5k+4) \\equiv 0 \\pmod 5,\n\\end{equation} \n\\begin{equation}\n    p(7k+5) \\equiv 0 \\pmod 7,\n\\end{equation} \n\\begin{equation}\n    p(11k+6) \\equiv 0 \\pmod{11}.\n\\end{equation}\nWe present sophisticated proofs for these great results.\n\\begin{proof}\nFor (3.1)\n\nWe define $E = (q;q)$ and $J = E^3$\n\nNow, using Euler's theorem,\n\n$$E = \\sum_{-\\infty}^\\infty (-1)^n q^{\\frac{(3n^2+n)}{2}}$$\n\nAnd using Jacobi triple product identity,\n$$J = \\sum_{n\\geq 0}(-1)^n(2n+1)q^{\\frac{n^2+n}{2}}$$\n\nWe notice that expnents of series of $E$ are congruent to 0, 1 or 2 modulo 5 and exponents in series of $J$ is congruent to 0, 1 or 3 modulo 5 but whenever the exponent is congruent to 3 modulo 5, the coefficient is divisible by 5.\n\nWe can deduce that\n\\begin{align*}\n    E &= E_0+E_1+E_2, \\\\\n    J &= J_0 + J_1.\n\\end{align*}\n\nNow,\n\\begin{equation}\n\\begin{split}\n    \\sum_{n\\geq 0}p(n)q^n &= \\frac{1}{E} = \\frac{E^4}{E^5} = \\frac{EJ}{E^5} \\\\\n    &= \\frac{(E_0+E_1+E_2)(J_0+J_1)}{E^5}\\\\\n    \\end{split}\n\\end{equation}\nNow we see the coefficients of the form $5n+4$ and arrive at\n\n$$\\sum_{n\\geq0}p(5n+4)q^{5n+4} \\equiv 0 \\pmod{5}$$\n\\end{proof}\n\nA Proof on similar lines can easily be deduced for the other two congruences too.\n\\newpage\nIn fact the first two congruences are a result of the following generating functions\n\\begin{align*}\n    \\sum_{k=0}^\\infty p(5k+4)q^k &= 5\\frac{(q^5;q^5)^5_\\infty}{(q;q)^6_\\infty}\\\\\n    \\sum_{k=0}^\\infty p(7k+5)q^k &= 7\\frac{(q^7;q^7)^3_\\infty}{(q;q)^3_\\infty} + 49q\\frac{(q^7;q^7)^7_\\infty}{(q;q)^8_\\infty}\n\\end{align*}\n\n\n\n\\subsection{Rank of a Partition}\n\nRank of a partition is defined as the difference of the largest part of a partition and the number of parts of a partition i.e.\n\n\\begin{equation}\n    r(\\lambda) = l(\\lambda) - n(\\lambda)\n\\end{equation}\n\nKey points to notice regarding ranks of a partition $\\lambda$ are $r(\\lambda) = -r(\\lambda*)$ and that in general values of ranks of a partitions of $n$ can only be\n\\begin{center}\n    $n-1,n-3,n-4,\\dots,1,0,-1,-2,\\dots, 3-n,1-n$\n\\end{center}\n\nDyson denoted the number of partitions of $n$ with rank $s$ as $N(s,n)$, and the number of partitions of $n$ with rank $s$ modulo $m$ as $N(s,m,n)$. By definition, $$N(s,m,n) = \\sum_{k=-\\infty}^\\infty N(mk+s,n).$$\n\nRamanujan's congruences directly relate to Dyson's notion of the rank of a partition as Dyson conjectured in [4], that \n\\begin{center}\n    $N(s,5,5n+4) = \\frac{p(5n+4)}{5},$\n    \n    $N(t,7,7n+5) = \\frac{p(7n+5)}{7}$\n\\end{center}\n\\newpage\nThe above conjectures were based on computational evidence and in an attempt to give a combinatorial interpretation of Ramanujan's congruences which follows after summing the residue classes.\n\nThe proof was given by Atkin and Swinnerton-Dyer in [1], by establishing generating function for the expression $N(s,l,ln+d)-N(t,l,ln+d) $ for $d = 5, 7$ and $0 \\leq d,s,t \\leq l$. They obtained the difference of all values of $d$ for $l = 5, 7$ and found it to be 0 for $l = 5$, $d = 4$ and $l = 7$ , $d = 5$ which was completely in accordance with Ramanujan's congruences.\n\n\\subsection{$M_2$ Rank Differences}\nTo define $M_2$ rank differences we need to consider partitions without repeated odd parts which are the number of partitions of $n$ where none of the odd parts is repeated.\n\n$M_2$ rank differences is at the heart of most of the conjectures by Mao and the one that we discuss here. The $M_2$ rank of a partition $\\lambda$ without repeated odd parts is defined as\n$$\\ceil*{\\frac{l(\\lambda)}{2}} - n(\\lambda)$$\nwhere $l(\\lambda)$ and $n(\\lambda)$ are defined as above.\nWe define various notations, $N_2(s,n)$ as the number of partitions of $n$ with no repeated odd parts and its $M_2$ rank equal to $s$ and $N_2(s,m,n)$ as the number of partitions of $n$ with distinct odd parts and $M_2$ rank congruent to $s$ modulo $m$.\n", "meta": {"hexsha": "4226d8e609eb76407478ebf387734d0b3e4006be", "size": 3938, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter3.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": "chapter3.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": "chapter3.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": 43.2747252747, "max_line_length": 374, "alphanum_fraction": 0.6802945658, "num_tokens": 1415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.6025074312477998}}
{"text": "\\chapter{\\Pelectron \\Pmuon scattering}\nThis time the scattering between electrons and muons will be considered with spin taken into account. This calculation can be easily extended to similar scattering situations.\n\n\\section{Electron in an EM field}\nAs in Section \\ref{sec:EMdynamics} we replace $p^\\mu \\rightarrow p^\\mu + eA^\\mu$. Then the components transform as\n\\begin{align}\nE \\rightarrow & E + eV \\\\\n\\vec{p} \\rightarrow & \\vec{p} + e\\vec{A}\n\\end{align}\nStarting from the free particle Dirac equation, $(\\vec{\\alpha}\\cdot\\vec{p} + \\beta m)\\psi = E\\psi$, after the substitution we have\n\\begin{equation}\n\\left( \\vec{\\alpha}\\cdot\\vec{p} + \\beta m + e\\left[ \\vec{\\alpha}\\cdot\\vec{A} - VI_4 \\right] \\right) \\psi = E\\psi\n\\end{equation}\nand we may identify $V_D$, the Dirac potential, to be $e\\left( \\vec{\\alpha}\\cdot\\vec{A} - VI_4 \\right)$.\n\n\\section{Current-potential formulation}\nConsider the scattering of a particle with wavefunction $\\psi_i$ off a potential $V_D$ to wavefunction $\\psi_f$. The amplitude is given by\n\\begin{align}\nT_{fi} &= -i \\int \\psi_f^\\dagger \\, V_D \\, \\psi_i \\, \\dd[4]{x} \\\\\n&= -ie \\int \\psi_f^\\dagger \\, \\gamma^0 \\, \\gamma^0 \\left( -VI_4 + \\alpha^k A_k \\right) \\psi_i \\, \\dd[4]{x} \\nonumber \\\\\n&= -ie \\int \\, \\overline{\\psi}_f \\left( -\\gamma^0 V + \\gamma^k A_k \\right) \\psi_i\\dd[4]{x} \\nonumber \\\\\n&= ie \\int \\overline{\\psi}_f \\, \\gamma^\\mu A_\\mu \\psi_i \\, \\dd[4]{x}.\n\\end{align}\nRecall that in the current-potential formulation, the scattering amplitude is given by\n\\begin{equation}\nT_{fi} = -i \\int j^\\mu_{fi} \\, A_\\mu \\, \\dd[4]{x}\n\\end{equation}\nso we identify the current\n\\begin{equation}\nj^\\mu_{fi} = -e \\, \\overline{\\psi}_f \\, \\gamma^\\mu \\, \\psi_i = -e \\, \\overline{u}_f \\, \\gamma^\\mu \\, u_i \\, e^{i(p_f - p_i)x}\n\\end{equation}\nwhere the second equality comes from the plane wavefunction.\n\n\\section{Scattering amplitude}\nNow we can consider the full electron-muon scattering process.\n\\begin{figure}[th]\n\\centering\n\\include{figures/DiracEMuScatter}\n\\caption{Elastic scattering of spin-$\\frac{1}{2}$ electrons and muons. This is a $t$-channel process. \\label{fig:DiracEMuScatter}}\n\\end{figure}\n\nUsing the currents $j_1$, $j_2$ and propagator, the transition amplitude is\n\\begin{align}\nT_{fi} &= -i \\int j_\\mu^1 \\, \\frac{-1}{q^2} \\, j^\\mu_2 \\, \\dd[4]{x} \\\\\n&= -i \\int \\left( -e \\, \\overline{u}(k^\\prime) \\, \\gamma_\\mu \\, u(k) \\, e^{i(k^\\prime - k)x} \\right) \\frac{-1}{q^2} \\left( -e \\, \\overline{u}(p^\\prime) \\, \\gamma^\\mu \\, u(p) \\, e^{i(p^\\prime - p)x} \\right) \\, \\dd[4]{x} \\nonumber \\\\\n&= \\frac{ie^2}{q^2} \\int \\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\mu \\, u(k) \\right]\\left[ \\overline{u}(p^\\prime) \\, \\gamma^\\mu \\, u(p) \\right] \\, e^{i(k^\\prime + p^\\prime - k - p)x} \\, \\dd[4]{x}\n\\end{align}\n\nAs before, in calculating $\\abs{T_{fi}}^2$, one exponential term becomes the phase space factor and the other becomes the 4-space volume. The result is\n\\begin{equation}\n\\abs{T_{fi}}^2 = \\frac{e^4}{q^4} \\, \\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\mu \\, u(k) \\right]^\\dagger \\left[ \\overline{u}(p^\\prime) \\, \\gamma^\\mu \\, u(p) \\right]^\\dagger \\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\nu \\, u(k) \\right]\\left[ \\overline{u}(p^\\prime) \\, \\gamma^\\nu \\, u(p) \\right]\n\\end{equation}\n\nEvaluating the Hermitian conjugate (recall that $(\\gamma^0)^\\dagger = \\gamma^0$, $(\\gamma^k)^\\dagger = -\\gamma^k$, and $\\gamma^0\\gamma^k = -\\gamma^k \\gamma^0$),\n\\begin{align}\n\\left[ \\overline{u}(p^\\prime) \\, \\gamma^0 \\, u(p) \\right]^\\dagger &= \\left[ u^\\dagger(p^\\prime) \\, \\gamma^0 \\, \\gamma^0 \\, u(p) \\right]^\\dagger \\nonumber \\\\\n&= u^\\dagger(p) \\, \\gamma^0 \\, \\gamma^0 \\, u(p^\\prime) \\nonumber \\\\\n&= \\overline{u}(p) \\, \\gamma^0 \\, u(p^\\prime)\n\\end{align}\n\\begin{align}\n\\left[ \\overline{u}(p^\\prime) \\, \\gamma^k \\, u(p) \\right]^\\dagger &= \\left[ u^\\dagger(p^\\prime) \\, \\gamma^0 \\, \\gamma^k \\, u(p) \\right]^\\dagger \\nonumber \\\\\n&= -u^\\dagger(p) \\, \\gamma^k \\, \\gamma^0 \\, u(p^\\prime) \\nonumber \\\\\n&= u^\\dagger(p) \\, \\gamma^0 \\, \\gamma^k \\, u(p^\\prime) \\nonumber \\\\\n&= \\overline{u}(p) \\, \\gamma^k \\, u(p^\\prime)\n\\end{align}\nSo $\\left[ \\overline{u}(p^\\prime) \\, \\gamma^\\mu \\, u(p) \\right]^\\dagger = \\overline{u}(p) \\, \\gamma^\\mu \\, u(p^\\prime)$ and similarly $\\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\mu \\, u(k) \\right]^\\dagger = \\overline{u}(k) \\, \\gamma_\\mu \\, u(k^\\prime)$.\nNow the transition amplitude is\n\\begin{align}\n\\abs{T_{fi}}^2 &= \\frac{e^4}{q^4} \\, \\left[ \\overline{u}(k) \\, \\gamma_\\mu \\, u(k^\\prime) \\right] \\left[ \\overline{u}(p) \\, \\gamma^\\mu \\, u(p^\\prime) \\right] \\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\nu \\, u(k) \\right]\\left[ \\overline{u}(p^\\prime) \\, \\gamma^\\nu \\, u(p) \\right] \\nonumber \\\\\n&= \\frac{e^4}{q^4} \\, ^e\\!L_{\\mu\\nu} \\, ^\\mu\\!L^{\\mu\\nu}\n\\end{align}\nwhere\n\\begin{equation}\n^e\\!L_{\\mu\\nu} = \\left[ \\overline{u}(k) \\, \\gamma_\\mu \\, u(k^\\prime) \\right]\\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\nu \\, u(k) \\right]\n\\end{equation}\nis the electron tensor, and\n\\begin{equation}\n^\\mu\\!L_{\\mu\\nu} = \\left[ \\overline{u}(p) \\, \\gamma_\\mu \\, u(p^\\prime) \\right]\\left[ \\overline{u}(p^\\prime) \\, \\gamma_\\nu \\, u(p) \\right]\n\\end{equation}\nis the muon tensor.\n\n\\subsection{Sum over spins}\n\nFor the whole process we must sum over initial and final spins then average over the initial spins. Then the electron tensor becomes\n\\begin{equation}\n^e\\!L_{\\mu\\nu} = \\frac{1}{2} \\sum_S \\sum_{S^\\prime} \\left[ \\overline{u}(k) \\, \\gamma_\\mu \\, u(k^\\prime) \\right]\\left[ \\overline{u}(k^\\prime) \\, \\gamma_\\nu \\, u(k) \\right].\n\\end{equation}\nWriting out the matrix indices,\n\\begin{align}\n^e\\!L_{\\mu\\nu} &= \\frac{1}{2}\\sum_S \\sum_{S^\\prime} \\overline{u}(k)_\\alpha \\, \\gamma^{\\alpha\\beta}_\\mu \\, u(k^\\prime)_\\beta \\, \\overline{u}(k^\\prime)_\\epsilon \\, \\gamma_\\nu^{\\epsilon\\sigma} \\, u(k)_\\sigma \\nonumber \\\\\n&= \\frac{1}{2} \\sum_S \\sum_{S^\\prime} u(k^\\prime)_\\beta \\, \\overline{u}(k^\\prime)_\\epsilon \\, \\gamma_\\nu^{\\epsilon\\sigma} \\, u(k)_\\sigma \\, \\overline{u}(k)_\\alpha \\, \\gamma_\\mu^{\\alpha\\beta} \\nonumber \\\\\n&= \\left( \\fsl{k^\\prime} + m \\right)_{\\beta\\epsilon} \\, \\gamma_\\nu^{\\epsilon\\sigma} \\, \\left( \\fsl{k} + m \\right)_{\\sigma\\alpha} \\, \\gamma_\\mu^{\\alpha\\beta}\n\\end{align}\nwhere we have used the completeness relation, \\eqref{eq:completeness}, in the last step. This may be written as a trace, such that\n\\begin{align}\n^e\\!L_{\\mu\\nu} &= \\frac{1}{2} \\Tr[(\\fsl{k}^\\prime + m) \\, \\gamma_\\nu \\, (\\fsl{k} + m) \\, \\gamma_\\mu] \\\\\n^\\mu\\!L_{\\mu\\nu} &= \\frac{1}{2} \\Tr[(\\fsl{p}^\\prime + M) \\, \\gamma_\\nu \\, (\\fsl{p} + M) \\, \\gamma_\\mu].\n\\end{align}\nwhere the last equation follows from an identical calculation with the muon tensor, and $m$ and $M$ are the electron and muon masses, respectively.\n\nNow the scattering probability is given by\n\\begin{equation}\n\\abs{T_{fi}}^2 = \\frac{e^4}{q^4} \\, \\frac{1}{2} \\Tr[(\\fsl{k}^\\prime + m) \\, \\gamma_\\nu \\, (\\fsl{k} + m) \\, \\gamma_\\mu] \\, \\frac{1}{2} \\Tr[(\\fsl{p}^\\prime + M) \\, \\gamma_\\nu \\, (\\fsl{p} + M) \\, \\gamma_\\mu].\n\\end{equation}\nUsing the trace theorems from Section \\ref{sec:Trace}, the only non-zero term are those with two or four $\\gamma$-matrices:\n\\begin{align}\n\\abs{T_{fi}}^2 &= \\frac{e^4}{4q^4} \\, \\Tr[\\gamma_\\alpha \\, \\gamma_\\nu \\, \\gamma_\\beta \\, \\gamma_\\mu \\, k^\\prime^\\alpha \\, k^\\beta + \\gamma_\\nu\\, \\gamma_\\mu \\, m^2] \\, \\Tr[\\gamma^\\alpha \\, \\gamma^\\nu \\, \\gamma^\\beta \\, \\gamma^\\mu \\, p^\\prime_\\alpha \\, p_\\beta + \\gamma^\\nu\\, \\gamma^\\mu \\, M^2] \\nonumber \\\\\n&= \\frac{4e^4}{q^4} \\, \\left[ \\left( g_{\\alpha\\nu} \\, g_{\\beta\\mu} - g_{\\alpha\\beta} \\, g_{\\nu\\mu} + g_{\\alpha\\mu} \\, g_{\\nu\\beta} \\right) k^\\prime^\\alpha \\, k^\\beta + g_{\\nu\\mu} m^2 \\right]\\left[ \\left( g^{\\alpha\\nu} \\, g^{\\beta\\mu} - g^{\\alpha\\beta} \\, g^{\\nu\\mu} + g^{\\alpha\\mu} \\, g^{\\nu\\beta} \\right) p^\\prime^\\alpha \\, p^\\beta + g^{\\nu\\mu} M^2 \\right] \\nonumber \\\\\n&= \\frac{8e^4}{q^4} \\left[ (k^\\prime \\cdot p^\\prime)(k \\cdot p) + (k^\\prime \\cdot p)(k \\cdot p^\\prime) - m^2(p^\\prime \\cdot p) - M^2(k^\\prime \\cdot k) + m^2M^2 \\right]\n\\end{align}\n\n\\section{Differential cross section}\nIn the ultrarelativistic limit the masses become negligible and the scattering probability simplifies to\n\\begin{equation}\n\\abs{T_{fi}}^2 = \\frac{8e^4}{q^4} \\left[ (k^\\prime \\cdot p^\\prime)(k \\cdot p) + (k^\\prime \\cdot p)(k \\cdot p^\\prime) \\right]\n\\end{equation}\n\nNow we wish to express this in terms of the Mandelstam variables. The process is $t$-channel, so we have that\n\\begin{align}\nt &= q^2 \\\\\n&= (k - k^\\prime)^2 = (p - p^\\prime)^2 \\nonumber \\\\\n&\\approx -2k\\cdot k^\\prime \\approx -2p\\cdot p^\\prime \\nonumber \\\\\n\\end{align}\nThe centre of momentum energy is\n\\begin{align}\ns &= (k + p)^2 = (k^\\prime + p^\\prime)^2 \\nonumber \\\\\n&\\approx 2k\\cdot p \\approx 2k^\\prime \\cdot p^\\prime\n\\end{align}\nand finally\n\\begin{align}\nu &= (k - p^\\prime)^2 = (p - k^\\prime)^2 \\nonumber \\\\\n&\\approx -2k\\cdot p^\\prime \\approx -2p \\cdot k^\\prime\n\\end{align}\n\nUsing these relations, the scattering probability may be expressed as\n\\begin{align}\n\\abs{T_{fi}}^2 &= \\frac{2e^4}{t^2} \\left( s^2 + u^2 \\right)\n\\end{align}\n\nWe employ the formula for the differential cross section for elastic scaterring,\n\\begin{equation}\n\\dv{\\sigma}{\\Omega} = \\frac{1}{64\\pi^2} \\frac{\\abs{T_{fi}}^2}{s}\n\\end{equation}\nso for the $t$-channel scattering of two spin-half particles with electron charge (e.g.~electrons and muons),\n\\begin{equation}\\boxed{\n\\dv{\\sigma}{\\Omega} = \\frac{e^4}{32\\pi^2 s} \\frac{s^2 + u^2}{t^2}\n}\\end{equation}\n", "meta": {"hexsha": "826f56f6e5ea162f9690b15e1773a8f88c0a0308", "size": 9298, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/10_e_mu_scattering.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/10_e_mu_scattering.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/10_e_mu_scattering.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": 62.8243243243, "max_line_length": 370, "alphanum_fraction": 0.6271241127, "num_tokens": 3689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6025074191649157}}
{"text": "%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\input{../header.tex}\n\\input{../newcommands.tex}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{document}\n\n\\title{DG methods on structured grids}\n\\author{M.~Wiesenberger}\n\\tableofcontents\n\n\\section{ Introduction to discontinuous Galerkin methods} \\label{sec:discretization}\nThis writeup is based on Reference~\\cite{WiesenbergerPhD}. A useful book to consult\nis Reference~\\cite{NodalDG}.\n\nIn recent years, discontinuous Galerkin (dG) methods have been investigated \nas an excellent alternative to finite difference and finite volume schemes \nin numerical simulations involving both parabolic as well as hyperbolic problems \n(for the advection dominated case see, for example, the review article~\\cite{Cockburn2001runge}). \nSuch methods combine many advantages of finite element methods (such as the ease of handling \ncomplicated geometry) with properties more commonly associated with \nfinite difference approximations. Examples of the latter includes the absence \nof a global mass matrix. \nThe main idea of a dG method is to approximate the solution \nof a differential equation by a polynomial in each grid-cell. \nHigher/lower\norder methods can be constructed by simply increasing/decreasing the degree of \nthe polynomials used in each cell. \nIn classical finite element methods continuity is required across cell boundaries. \nIn contrast, dG methods allow discontinuities across cell boundaries, which adds to the flexibility of the method.\n\nFor the discretization of second derivatives we discuss the so-called local discontinuous Galerkin (LDG) method~\\cite{Cockburn1998}.\nThe LDG method and its advantages can also be used for the discretization of \nelliptic equations (including Poisson's equation). \nReference~\\cite{Arnold2002} highlights the relation \nof the method to interior penalty and other alternative methods. \nA superconvergence result for the \nLDG approach was proven on Cartesian grids~\\cite{Cockburn2002},\nwhere the order of convergence is $1/2$ better than on arbitrary meshes.\nReference~\\cite{Yadav2013} later showed a similar result for general, nonlinear elliptic equations.\n\nThe downside of the dG methods is their rather complex and unintuitive notation \nin the existing mathematical literature. Often, algorithms\nare described in terms of arbitrary sets of polynomials and spatial grids. \nWe propose an adapted, simplified, and in our view more practical notation for orthogonal grids and Legendre polynomials, which can be implemented straightforwardly.\nWe reformulate the LDG method in terms of adjoint matrices and\n naturally develop the symmetry of the resulting discretization.\nDoing so, we also propose a new discretization for the general elliptic equation. \nUnfortunately, our discretization has a wider stencil than the existing ones, but \nour numerical experiments indicate superconvergent properties and the resulting\nmatrix equation is better conditioned than the old one. To the knowledge\nof the author these findings are unpublished to date.\n\n\\subsection{ The Legendre polynomials} \\label{sec:legendre}\nFirst, let us consider the one-dimensional case.\nFor simplicity and ease of implementation we choose an equidistant grid with $N$ cells $C_n = [x_{n-1/2},x_{n+1/2}]$ of size $h$;\nwith this choice we are able to construct basis functions of $P(C_n)$, the space of \npolynomials of degree at most $P-1$ on $C_n$, by using orthogonal Legendre polynomials\\footnote{ Often, in the literature the order of the polynomials is denoted by $k$.\nPay attention, that we use the number of polynomial coefficients $P$ instead. We have $P=k+1$}.\nThe Legendre polynomials can be recursively defined on $[-1,1]$ by setting\n$p_0(x) = 1$, $p_1(x) = x$ and (see e.g.~\\cite{AS})\n\\begin{align}\n    (k+1)p_{k+1}(x) = (2k+1)xp_k(x) - kp_{k-1}(x).\n    \\label{eq:recursion}\n\\end{align}\nThe so constructed Legendre polynomials are orthogonal on $[-1,1]$.\nWe write\n$x^a_j$ and $w_j$, $j=0,\\dots,P-1$ denoting the abscissas and weights of\nthe Gauss--Legendre quadrature on the interval $[-1,1]$. Then we note that for $k,l=0, \\dots, P-1$\n\\begin{align}\n    \\int_{-1}^1 p_k(x)p_l(x) \\dx = \\sum_{j=0}^{P-1} w_jp_k (x^a_j)p_l(x^a_j) = \\frac{2}{2k+1}\\delta_{kl}, \n    \\label{}\n\\end{align}\n since Gauss--Legendre quadrature is exact for polynomials of degree at most $2P-1$.\n\nThe discrete completeness relation can then be written as\n\\begin{align}\n    \\sum_{k=0}^{P-1} \\frac{2k+1}{2}w_j p_k(x^a_i)p_k(x^a_j) = \\delta_{ij}.\n    \\label{eq:completeness}\n\\end{align}\nGiven a real function $f:[-1,1]\\rightarrow \\mathbb{R}$ we define $f_j:=f(x^a_j)$ and\n\\begin{align} \\label{eq:ex2}\n    \\bar f^k := \\frac{2k+1}{2}\\sum_{j=0}^{P-1}w_j p_k(x^a_j) f_j\n\\end{align}\nNow let us define the forward transformation matrix by $F^{kj}:=\\frac{2k+1}{2}w_jp_k(x^a_j)$ and\nthe backward transformation matrix by $B_{kj}:= p_j(x^a_k)$.\n\\begin{tcolorbox}[title=Note]\nReference~\\cite{NodalDG} identifies $B$ as the Vandermonde matrix and further denotes $f_i$ as the \\textbf{nodal} representation and $\\bar f^k$ as the \\textbf{modal} representation of $f(x)$.\n\\end{tcolorbox}\n\nThen, using Eq.~\\eqref{eq:ex2}, we get\n\\begin{subequations}\n\\begin{align}\n    \\bar f^k = \\sum_{j=0}^{P-1}F^{kj}f_j \\\\\n    f_j = \\sum_{k=0}^{P-1} B_{jk}\\bar f^k,\n\\end{align}\n\\end{subequations}\n\nLet us now consider an interval $[a,b]$ and an equidistant discretization\nby $N$ cells with cell center $x_n$ and grid size $h=\\frac{b-a}{N}$; in addition, we set $x_{nj}^a := x_n + \\frac{h}{2}x^a_j$.\nGiven a function $f:[a,b]\\rightarrow \\mathbb{R}$ we then define\n$f_{nj} := f(x^a_{nj})$ and note that\n\\begin{subequations}\n\\begin{align}\n    \\bar{ \\vec f} &= (\\Eins\\otimes F) \\vec f \\\\\n    \\vec f &= (\\Eins\\otimes B) \\bar{\\vec f},\n    \\label{}\n\\end{align}\n\\end{subequations}\nwhere $f_{nj}$ are the elements of $\\vec f$,\n $\\Eins\\in\\mathbb{R}^{N\\times N}$ is the identity matrix and $F,B\\in\\mathbb{R}^{P\\times P}$. Furthermore, we use\n$\\otimes$ to denote the Kronecker product which is bilinear and associative.\nThe discontinuous Galerkin expansion $f_h$ of a function $f$ in the interval $[a,b]$ can\nthen readily be given as\n\\begin{align}\n    f_h(x) = \\sum_{n=1}^N \\sum_{k=0}^{P-1} \\bar f^{nk} p_{nk}(x),\n    \\label{eq:dgexpansion}\n\\end{align}\nwhere\n\\begin{align}\n    p_{nk}(x) := \\begin{cases}\n        p_k\\left(  \\frac{2}{h}(x-x_n)\\right),& \\ \\text{for } x-x_n\\in\\left[ -\\frac{h}{2}, \\frac{h}{2} \\right]\\\\\n        0,& \\ \\text{else}.\n    \\end{cases}\n    \\label{}\n\\end{align}\nAs an example, we plot Eq.~\\eqref{eq:dgexpansion} for $f(x)=\\sin(2x)$ in Fig.~\\ref{fig:discretization}.\n\\begin{figure}[htpb]\n    \\includegraphics[width= 0.9\\textwidth]{discretization.pdf}\n    \\caption{ \n    Discretization of a sine function with second order polynomials, $P=3$, \n    on $N=5$ grid cells. Dotted lines depict the cell boundaries. \n    }\n    \\label{fig:discretization}\n\\end{figure}\nAlready with a very low resolution of $P=3$ and $N=5$\nwe get an acceptable function approximation. We clearly see the discontinuities\nat the cell boundaries.\n\nThe use of Legendre polynomials yields a natural approximation of the integrals of $f$\nvia Gauss--Legendre quadrature\n\\begin{subequations}\n\\begin{align}\n    \\langle f_h,g_h\\rangle:=\\int_a^b f_hg_h \\dx &= \\sum_{n=1}^N\\sum_{j=0}^{P-1} \\frac{hw_j}{2} f_{nj} g_{nj} \n    = \\sum_{n=1}^N\\sum_{k=0}^{P-1}\\frac{h}{2k+1}\\bar f^{nk}\\bar g^{nk}  \\\\\n    \\|f_h\\|^2_{L_2} := \\int_a^b |f_h|^2 \\dx &= \\sum_{n=1}^N\\sum_{j=0}^{P-1} \\frac{h w_j}{2}f_{nj}^2 \n    = \\sum_{n=1}^N\\sum_{k=0}^{P-1} \\frac{h}{2k+1}\\left(\\bar f^{nk}\\right)^2. \n    \\label{eq:def_norm}\n\\end{align}\n\\label{eq:gausslegendre}\n\\end{subequations}\nWith these formulas we have a simple, accurate, and fast\nmethod to evaluate integrals on the entire domain. This is applied, for example, to compute\nerrors in the $L_2$-norm.\n\nWe now define some useful quantities that simplify our notation (note that $i,j=0,\\dots,P-1$)\n\\begin{subequations}\n    \\begin{align}\n        S_{ij} &:= \\int_{-h/2}^{h/2} p_i\\left(\\frac{2}{h} x\\right)p_j\\left(\\frac{2}{h} x\\right) \\dx = \\frac{h}{2i+1}\\delta_{ij} \\\\%=: s_i \\delta_{ij}\\\\ \n        T^{ij} &:= S^{-1}_{ij} = \\frac{2i+1}{h}\\delta_{ij} \\\\%=: t_i \\delta_{ij}\\\\\n        W^{ij} &:= \\frac{h w_j}{2}\\delta_{ij}\\\\\n        V_{ij} &:= W_{ij}^{-1} = \\frac{2}{hw_j}\\delta_{ij}. \n    \\end{align}\n    \\label{eq:diagonal}\n\\end{subequations}\nEmploying these relations we can write\n    \\begin{align}\n\t\t\\langle f_h,g_h\\rangle =& \\vec f^{\\mathrm{T}}(\\Eins\\otimes W)\\vec g \n\t\t= \\bar{\\vec f}^{\\mathrm{T}}(\\Eins\\otimes S)\\bar{\\vec g} \n    \\end{align}\n    and \\begin{align}\n        F = TB^{\\mathrm{T}}W.\n        \\label{eq:transformation}\n    \\end{align}\nFurthermore, we note that\n\\begin{subequations}\n    \\begin{align}\n        M_{ij} &:= \\int_{-h/2}^{h/2} p_i\\left(\\frac{2}{h} x\\right)\\partial_xp_j\\left(\\frac{2}{h} x\\right) \\dx\\\\\n\t\tR_{ij} &:= p_i(1)p_j(1) = 1 = R^{\\mathrm{T}}_{ij}\\\\\n\t\tL_{ij} &:= p_i(-1)p_j(-1) = (-1)^{i+j} = L^{\\mathrm{T}}_{ij}\\\\\n        RL_{ij}&:= p_i(1)p_j(-1) = (-1)^j\\\\\n\t\tLR_{ij}&:= p_i(-1)p_j(1) = (-1)^i = RL^{\\mathrm{T}}_{ij}.\n    \\end{align}\n    \\label{eq:legendre_operators}\n\\end{subequations}\nIn order to compute the elements of $M_{ij}$ we first note that $M_{ij} = 0$ for\n$i > j-1$ as $\\partial_x p_j(x)$ is a polynomial of degree $j-1$. Then\nwe use integration by parts to show that \n\\begin{align}\n\t(M+L) = (R-M)^{\\mathrm{T}}.\n    \\label{eq:legendre_derivative}\n\\end{align}\nTherefore, we conclude that $M_{ij} = 1 - (-1)^{i+j}$ for $i\\le (j-1)$. \n\nWe introduce the notation~\\eqref{eq:diagonal} and~\\eqref{eq:legendre_operators} mainly for ease of implementation. If a block-matrix class is written and the\noperations $+$, $-$ and $*$ are defined on it, the assembly of the derivative\nmatrices is simplified to a large extent. \n\n%Note that $\\forall n\\in\\mathbb{N}$ and $x\\in[-1,1]$\n%    $p_n(1) = 1$ and \n%    $p_n(-x) = (-1)^np_n(x)$.\n%For $P=4$ we have e.g.\n%\\begin{align}\n%    D = \\begin{pmatrix}\n%        0 & 2 & 0 & 2 \\\\\n%        0 & 0 & 2 & 0 \\\\\n%        0 & 0 & 0 & 2 \\\\\n%        0 & 0 & 0 & 0 \n%    \\end{pmatrix}\n%    \\label{eq:example_derivative}\n%\\end{align}\n%\n\n\\subsection{Indefinite Integrals}\\label{sec:integrals}\nThe approximation of an indefinite integral $\\int_a^x f_h(x')\\dx'$ is a bit more involved since the integration\nboundary $x$ does not need to coincide with a cell boundary.\nFirst, integrating the Legendre differential equation\n$\\frac{\\d}{\\dx}\\left[ (1-x^2) \\frac{\\d}{\\dx}p_j(x) \\right] + j(j+1)p_j(x) = 0$\nand with the help of Eq.~\\eqref{eq:recursion} and a second recursion for Legendre-Polynomials\n$(x^2-1) \\d p_j(x)/\\dx = jxp_j(x) - j p_{j-1}(x)$\nwe compute\n\\begin{align}\n\\int_{-1}^{x} p_0(x')\\dx' = p_1(x)+p_0(x) \\quad \\int_{-1}^{x} p_j(x') \\dx'  = \\frac{ p_{j+1}(x) - p_{j-1}(x)}{2j+1}\\quad \\forall\\ j>0\n\\end{align}\nNotice that the integral of a polynomial of order $P$ yields a polynomial of order $P+1$.\nThe projection integral onto a base polynomial $p_i(x)$ yields\n\\begin{align}\n N_{00} &:= \\int_{-1}^{1} p_0(x) \\int_{-1}^{x} p_0(x') \\dx' \\dx = 2\\quad\n %N_{i0} := \\int_{-1}^{1} p_i(x) \\int_{-1}^{x} p_0(x') \\dx' \\dx = \\frac{2}{2i+1}\\delta_{i1}\\quad\n \\nonumber\\\\\n N_{ij} &:= \\int_{-1}^{1} p_i(x) \\int_{-1}^{x} p_j(x') \\dx' \\dx\n= \\frac{2}{(2i+1)(2j+1)}\\left[\\delta_{i(j+1)}-\\delta_{i(j-1)}\\right] \\quad i,j\\neq 0,0\n\\end{align}\n\nOur idea is to split the integral $F_h(x) = \\int_a^x f_h(x')\\dx'$ into two parts:\n\\begin{align}\nF_h(x):=\\int_a^x f_h(x') \\dx' = \\int_a^{x_{n-1/2}} f_h(x')\\dx' + \\int_{x_{n-1/2}}^x f_h(x') \\dx'\n\\end{align}\nwhere $n$ is the cell number such that $x_{n-1/2}\\leq x < x_{n+1/2}$.\nInserting $f_h(x) = \\bar f_{nj} p_{nj}(x)$ and projecting onto a base polynomial $p_{ni}(x)$ yields\n\\begin{align}\n\\bar F_{nk} := T_{ki}\\int_{x_{n-1/2}}^{x_{n+1/2}} p_{ni}(x) \\int_a^x f_h(x') \\dx'\\dx\n= \\delta_{k0} \\sum_{m=1}^{n-1} h\\bar f_{m0} + \\frac{h^2}{4}T_{ki}N_{ij} \\bar f_{nj}\n\\end{align}\nwhere we choose the proper normalization $h^2/4$ due to the double integrals in $N_{ij}$.\nNotice that if $f_h(x)$ is discretized using $P$ polynomial coefficients $F_h(x)$ would in\nprinciple need $P+1$ coefficients to be the exact integral.\nHowever, we usually truncate the coefficients at $P$ to match the order of the discretization.\nNumerical tests show that the corresponding truncation error is extremely small.\n\n\\subsection{ Discretization of first derivatives} \\label{sec:firstderivatives}\nFrom here on we write\n$ f_h(x) = \\bar f^{ni}p_{ni}(x)$ and imply the summation over cell index $n$ and polynomial\nindex $i$.\nThe first naive idea to get an approximation to the first derivative of $f_h(x)$\nis to simply set $f_x(x) = \\partial_x f_h(x) = \\bar f^{ni}\\partial_x p_{ni}(x)$ in \nthe interior of each cell $n$. \nUnfortunately, in this approach we loose one polynomial order and the discretization for\n$P=1$ is plain wrong. We would \nlike our discretization to become finite differences in the limit $P=1$.\n\nOn cell boundaries the derivative\nof $p_{ni}(x)$ is actually not well defined, which is why we now retain to \na weak formulation of derivatives. \nConsider \n\\begin{align}\n    \\int_{C_n} \\partial_x f_h(x) p_{ni}(x) \\dx = f_h p_{ni}|_{x_{n-1/2}}^{x_{n+1/2}}  -\n    \\int_{C_n} f_h(x) \\partial_x p_{ni}(x) \\dx.\n    \\label{}\n\\end{align}\nThe approximation $f_h(x)$ is double valued on the cell boundaries, which is why we replace\nthe boundary terms by\n\\begin{align}\n    \\int_{C_n} f_x p_{ni}(x) \\dx\n    = \\hat f p_{ni}|_{x_{n-1/2}}^{x_{n+1/2}}  -\n    \\int_{C_n} \\bar f^{nk} p_{nk} \\partial_x p_{ni} \\dx,\n    \\label{}\n\\end{align}\nwhere $\\hat f(x)$ is the numerical flux across cell boundaries and we call $f_x(x)$ the numerical approximation to the first derivative. We will use three different fluxes in this work. \n\\begin{subequations}\n\\begin{align}\n\t\\hat{f_C}(x) &= \\tfrac{1}{2}(\\lim_{\\eps\\to 0,\\eps>0}f_h(x+\\eps)+\\lim_{\\eps\\to 0,\\eps>0}f_h(x-\\eps)),\\\\\n\t\\hat{f_F}(x) &= \\lim_{\\eps\\to 0,\\eps>0}f_h(x+\\eps), \\\\\n\t\\hat{f_B}(x) &= \\lim_{\\eps\\to 0,\\eps>0}f_h(x-\\eps),\n\\end{align}\n\\end{subequations}\nwhich we call the centered, the forward and the backward flux respectively.\nFor $f\\colon [a,b]\\to\\mathbb{R}$ and periodic boundary conditions, we assume that\n\\begin{equation}\n\t\\lim_{\\eps\\to 0,\\eps>0} f(b+\\eps) = \\lim_{\\eps\\to 0,\\eps>0} f(a+\\eps), \\qquad\n\t\\lim_{\\eps\\to 0,\\eps>0} f(a-\\eps) = \\lim_{\\eps\\to 0,\\eps>0} f(b-\\eps),\n\\end{equation}\nfor homogeneous Dirichlet boundary conditions we assume that\n\\begin{equation}\n    \\hat f(a) = \\hat f(b) = 0,\n\\end{equation}\nand for homogeneous Neumann boundaries we assume that\n\\begin{align}\n    \\hat f(a) = \\lim_{\\eps\\to 0,\\eps>0} f_h(a+\\eps), \\qquad \n    \\hat f(b) = \\lim_{\\eps\\to 0,\\eps>0} f_h(b-\\eps).\n\\end{align}\nAs we see the choice\nof $\\hat f$ is not unique. It actually is the crucial ingredient in every dG method. \nDepending on what flux we choose, we arrive at various \napproximations to the derivative,\ne.g. for $P=1$ (i.e. a piecewise constant approximation in each cell)\nour scheme reduces to the classic centered, forward and backward finite difference\nschemes respectively.\nIn a way all the ingenuity of a dG method lies in the choice of the numerical flux.\n\nFor the following discussion we choose the centered flux $\\hat f_C$ and note\nthat the derivation is analogous for $\\hat f_F$ and $\\hat f_B$.\nWe arrive at\n\\begin{align}\n    \\bar f_x^{ni}= T^{ij}&\\left[ \\quad \\frac{1}{2} \\left(\\bar f^{(n+1)k}p_k(-1)+ \\bar f^{nk}p_k(1)\\right)p_j(1)\\right. \\nonumber\\\\\n        &\\ \\ - \\left.\\frac{1}{2} \\left(\\bar f^{nk}p_k(-1) + \\bar f^{(n-1)k}p_k(1)\\right)p_j(-1) - \\bar f^{nk} M_{kj} \\vphantom{\\frac{1}{2}}\\right]\n    \\label{}\n\\end{align}\nwhere we used that $p_{nk}(x_{n+1/2})\\equiv p_k(1)$ and $p_{nk}(x_{n-1/2}) \\equiv p_k(-1)$ holds true for all $n$.\nTogether with the previously defined quantities in~\\eqref{eq:legendre_operators} we can write\n\\begin{align}\n\t\\bar{\\mathbf f}_x  &= (\\Eins\\otimes T)\\circ \\left[ \\frac{1}{2}(\\Eins^+\\otimes RL + \\Eins \\otimes (M-M^{\\mathrm{T}}) - \\Eins^-\\otimes LR)\\right] \\bar{\\mathbf f}\\nonumber \\\\\n    &=: (\\Eins\\otimes T) \\circ \\bar D^0_{x,per} \\bar {\\mathbf f},\n    \\label{eq:discrete_der}\n\\end{align}\nusing $M+M^{\\mathrm{T}} = R-L$ from Eq.~\\eqref{eq:legendre_derivative}\nand \n\\begin{align}\n    \\Eins^{-}f^{n} &:= f^{n-1}\\\\\n    \\Eins^{+}f^{n} &:= f^{n+1}.\n    \\label{eq:operator_one}\n\\end{align}\nWe define\n\\begin{align*}\n    D^0_{x,per} := (\\Eins\\otimes F^T)\\circ \\bar D^0_{x,per}\\circ (\\Eins\\otimes F).\n    \\label{}\n\\end{align*}\nIf our coefficients are nodal values, we note with the help of Eq.~\\eqref{eq:transformation}\n\\begin{align}\n\t\\mathbf f_x %&= (\\Eins\\otimes V) (\\Eins\\otimes F^{\\mathrm{T}}) \n    %\\bar M_x^{per}\n%\\circ (\\Eins\\otimes F) \\mathbf f%\\nonumber\\\\\n = (\\Eins\\otimes V)\\circ D^0_{x,per} \\mathbf f,\n    \\label{eq:matrix_xspace}\n\\end{align}\nwhere $\\bar D_x^{per}$ and $D_x^{per}$ are skew-symmetric matrices.\n\nFrom Eq.~\\eqref{eq:discrete_der} we are now able to show the matrix representation of the one-dimensional discrete derivative for \nperiodic boundary conditions that can be used\nin the implementation\n\\begin{align}\n    \\bar D^0_{x,per} = \\frac{1}{2}\\begin{pmatrix}\n\t\t(M-M^{\\mathrm{T}}) & RL      &    &   & -LR \\\\\n\t\t-LR  & (M-M^{\\mathrm{T}}) & RL &   &     \\\\\n             &  -LR    & \\dots   &   &     \\\\\n             &         &    & \\dots  & RL    \\\\\n\t\t\t RL &         &    & -LR&(M-M^{\\mathrm{T}}) \n    \\end{pmatrix}\n    \\label{eq:dxcentered}\n\\end{align}\nWe also write down the expressions resulting from the forward and backward fluxes $\\hat f_F$ and $\\hat f_B$ respectively:\n\\begin{align}\n    \\bar D^+_{x,per} = \\begin{pmatrix}\n        -(M+L)^{\\mathrm{T}} & RL      &    &   & 0 \\\\\n\t\t 0   & -(M+L)^{\\mathrm{T}} & RL &   &     \\\\\n             &    0   & \\dots   &   &     \\\\\n             &         &    & \\dots  & RL    \\\\\n\t\t\t RL  &         &    & 0 & -(M+L)^{\\mathrm{T}}\n    \\end{pmatrix}\n    \\label{eq:dxplus}\n\\end{align}\nand\n\\begin{align}\n    \\bar D^-_{x,per} = \\begin{pmatrix}\n\t\t(M+L) & 0      &    &   & -LR \\\\\n\t\t-LR  & (M+L) & 0 &   &     \\\\\n             &   -LR   & \\dots   &   &     \\\\\n             &         &    & \\dots  & 0    \\\\\n\t\t\t 0  &         &    & -LR &(M+L)\n    \\end{pmatrix}.\n    \\label{eq:dxminus}\n\\end{align}\nNote that for $P=1$ we recover the familiar finite difference approximations of the first derivative.\n\\input{boundary_terms.tex}\nFinally we note the boundary terms for homogeneous Dirichlet and Neumann boundaries\nin Table~\\eqref{tab:boundary_terms} noticing that only the\ncorner entries of the matrices change.\n\nAlso note that the centered derivative can be viewed as the average of forward\nand backward derivative\n\\begin{align}\n    D^0_{x} = \\frac{1}{2}\\left( D^+_x + D^-_x\\right)\n\\end{align}\nThis is true for any of the above displayed boundary conditions (periodic,\nDirichlet and Neumann) and can be shown directly from Eqs.~\\eqref{eq:dxcentered},\n\\eqref{eq:dxplus}, \\eqref{eq:dxminus}, Table~\\eqref{tab:boundary_terms}\nand Eq.~\\eqref{eq:legendre_derivative}.\n\nIn our notation the local character of the dG method is apparent.\nTo compute the derivative in one cell we only use values of neighboring\ncells. Therefore, the method is well suited for parallelization which we\nwill exploit in our implementation.\n\nThe generalization to higher dimensions is immediate.\nAll the\nmatrices derived above can readily be extended via the appropriate Kronecker products.\nThe space complexity of \nthe matrices derived is $\\mathcal{O}(P^2 N)$ in one and $\\mathcal{O}(P^3N^2)$ in two dimensions.\n\nFinally, let us remark that we found it practical to always operate on nodal\ncoefficients, i.e.~we use Eq.~\\eqref{eq:matrix_xspace}\nfor our implementations and thus use $\\vec f$ rather than $\\bar{\\vec f}$ to represent the approximation. Function products are easily computed coefficient-wise, i.e.~we use\n\\begin{align}\n    (fg)_{ni}=f_{ni}g_{ni}\n    \\label{}\n\\end{align}\nto represent the corresponding products.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Discretization of elliptic equations} \\label{sec:elliptic}\nWe are now ready to discretize the one-dimensional general elliptic equation \n\\begin{align}\n    -\\frac{\\partial}{\\partial x}\\left( \\chi(x)\\frac{\\partial \\phi}{\\partial x}(x)\\right) = \\rho(x)\n    \\label{eq:elliptic}\n\\end{align}\non the interval $[a,b]$. Here, $\\chi(x)$ and $\\rho(x)$ are given functions.\n\nWe either choose periodic, Dirichlet, or Von-Neumann boundary conditions on the \nleft and right border for $\\phi$. \nAs a first step we rewrite Eq.~\\eqref{eq:elliptic} into two first order differential equations and a function product:\n\\begin{subequations}\n\\begin{align}\n    j'&= \\partial_x \\phi, \\label{eq:polarisationa}\\\\\n    j &= \\chi j', \\label{eq:polarisationb}\\\\\n    \\rho &= -\\partial_x j. \\label{eq:polarisationc}\n\\end{align}\n\\end{subequations}\n%Our plan is to now simply use a forward discretization\\footnote{\n%The choice of forward discretizing the first equation is arbitrary. A backward discretization\n%works equally well} for the first equation\nOur plan is to simply use one of the discretizations developed in the last\nsection for the first equation~\\eqref{eq:polarisationa}\nand its negative adjoint for the third equation~\\eqref{eq:polarisationc}.\nRecall that the adjoint of a square matrix $A$ is defined by the scalar product, i.e.\n\\begin{align}\n    \\vec f^\\mathrm{T} (\\Eins\\otimes W)\\circ A\\vec g = \n    \\vec g^\\mathrm{T} (A^\\mathrm{T}\\circ(1\\otimes W)) \\vec f =:     \\vec g^\\mathrm{T} (\\Eins\\otimes W) A^\\dagger \\vec f. \\nonumber\n    \\label{}\n\\end{align}\nFrom here we immediately get the relation\n\\begin{align}\n    A^\\dagger \\equiv (\\Eins\\otimes V)\\circ A^\\mathrm{T}\\circ (\\Eins\\otimes W).\n    \\label{eq:adjoint}\n\\end{align}\nThere is a close connection between symmetric, $A=A^\\mathrm{T}$, and self-adjoint, $A=A^\\dagger$, matrices.\nIf and only if the matrix $A$ is symmetric, then $(\\Eins\\otimes V)\\circ A$ is self-adjoint. Of course, we have $(AB)^\\dagger = B^\\dagger A^\\dagger$ and $(A^\\dagger)^\\dagger = A$.\n\nThe function product in Eq.~\\eqref{eq:polarisationb} is computed pointwisely on the Gaussian abscissas.\n\\begin{align}\n    \\vec j' &= (\\Eins\\otimes V)\\circ D_x \\vec \\phi, \\nonumber \\\\\n    \\vec j &= \\vec \\chi \\vec j', \\nonumber\\\\\n    \\vec \\rho &= (\\Eins\\otimes V)\\circ D_x^\\mathrm{T}\\vec j = (\\Eins\\otimes V) D_x^\\mathrm{T}\\circ\\chi\\circ (\\Eins\\otimes V)\\circ D_x \\vec \\phi,\n    \\label{eq:naive}\n\\end{align}\nwhere $D_x$ is either $D_x^+$, $D_x^-$, or $D_x^0$ with the correct boundary terms.\nNote, that~\\cite{Cockburn2002} originally only proposed to use the forward or backward discretization for $D_x$.\nEquation~\\eqref{eq:naive} is indeed a self-adjoint\ndiscretization for the second derivative. However, it turns out that \nEq.~\\eqref{eq:naive} is inconsistent for given $\\rho(x)$. The solution does not converge. \nThis problem is solved according to~\\cite{Cockburn2002} by adding a jump term\nto the flux of $j$: \n\\begin{align}\n    \\hat j(x_{n+1/2}) \\rightarrow \\hat j(x_{n+1/2}) + [\\phi(x_{n+1/2})],\n\\end{align}\nwhere $[\\phi(x_{n+1/2}]:=\\phi^n(x_{n+1/2}) - \\phi^{n+1}(x_{n+1/2})$ is the jump term of\n$\\phi$ at $x_{n+1/2}$. That means we have to alter our discretization~\\eqref{eq:naive} according to\n\\begin{align}\n    \\rho =  (\\Eins\\otimes V)[D_x^\\mathrm{T}\\circ \\chi\\circ(\\Eins\\otimes V)\\circ D_x  + J]\\phi\n    \\label{eq:discreteelliptic}\n\\end{align}\nwhere \n\\begin{align}\n    \\bar J = \\begin{pmatrix}\n\t\t(L+R) & -RL      &    &   & -LR \\\\\n\t\t-LR  & (L+R) & -RL &   &     \\\\\n             &   -LR   & \\dots   &   &     \\\\\n             &         &    & \\dots  & -RL    \\\\\n\t\t\t -RL  &         &    & -LR &(L+R)\n    \\end{pmatrix}.\n\\end{align}\nfor periodic boundaries. Again we give the correct boundary terms for Dirichlet\nand Neumann boundary conditions in Table~\\ref{tab:jump_terms}.\n\\input{jump_terms.tex}\nNote that $J$ is symmetric, thus the overall discretization remains self-adjoint. Indeed, with $D_x = D_x^+$ Eq.~\\eqref{eq:discreteelliptic} recovers\nthe discretization proposed by~\\cite{Cockburn2002}. \nIn addition, we remark that the centered discretization in Eq.~\\eqref{eq:discreteelliptic} is symmetric with respect to an inversion of the coordinate system $x\\rightarrow -x$ even for double Dirichlet or Neumann boundaries, while the forward and backward discretization is not. \n\nWe note again that the generalization to two or more dimensions is straightforward\nin a rectangular grid using Kronecker products.\n\\subsection{Numerical experiments} \\label{sec:ellipticexperiments}\nAs an example we solve Eq.~\\eqref{eq:elliptic} in two dimensions for \n\\begin{align*}\n\\chi(x,y) &= 1 + \\sin(x)\\sin(y)\\\\\n\\rho(x,y) &= 2\\sin(x)\\sin(y)\\left[\\sin(x)\\sin(y)+1\\right]-\\sin^2(x)\\cos^2(y)-\\cos^2(x)\\sin^2(y)\n    \\label{}\n\\end{align*}\non the domain $D=[ 0, \\pi]\\times[0,\\pi]$ for double Dirichlet boundary conditions. \nThe analytical solution is given by $\\phi(x,y) = \\sin(x)\\sin(y)$.  \n\nDo not try to insert $\\phi$ into Eq.~\\eqref{eq:discreteelliptic} directly. The result sub-optimally converges to the analytical $\\rho$ or may not converge at all, a phenomenon that is called supraconvergence. Only as a discretization for \nelliptic or parabolic equations the stencil~\\eqref{eq:discreteelliptic} works fine. \n\nWe note that Eq.~\\eqref{eq:discreteelliptic}, when multiplied by $(\\Eins\\otimes W)$, has the form of a symmetric matrix equation\n$A\\vec x=\\vec b$. \nThis equation is solved by a conjugate gradient method with\n$\\Eins\\otimes V$ as a diagonal preconditioner. \nWe use a truncation criterion based on the norm of the residuum\n\\begin{align}\n    ||\\vec r_k|| < \\eps_{res}||\\vec b||_{L_2} + \\eps_{res}\n    \\label{}\n\\end{align}\nwhere $\\vec r_k=A\\vec x_k - \\vec b$ is the residuum of\nthe $k-th$ iteration. In Table~\\ref{tab:polarisation} we summarize our results.\n\\input{table_polarisation.tex}\nWe observe that the forward and backward discretizations give the same results, \nwhich is due to the symmetry of the sine functions. The order of the \nrelative error in the $L_2$-norm coincides with the predicted convergence of order $P$\nfor all $P$. \n\nOn the other side, the centered discretization needs significantly less iterations\nto achieve the same error in the residuum. This indicates that the centered\ndiscretization is better conditioned than the forward and backward discretizations. \nAlso, we observe a superconvergent error of order $P+1$ for $P=3$ and $P=5$. In order to exclude symmetry reasons for these\nphenomena, we repeated the computations on the domain $D=[0, \\pi/2]\\times[0,\\pi/2]$ using Dirichlet boundaries on the left\nand Neumann boundaries on the right side. We find \nequal results; only\nthe equality in the results for forward and \nbackward discretization is broken. \nTo the knowledge of the author this superconvergence has not yet been observed before. \n\n\\section{Interpolation and Projection}\nEq.~\\eqref{eq:dgexpansion} provides a natural way to interpolate any\ndg expanded function $f_h(x)$ on any point in the interval $[a,b]$.\nThe interpolation has the same order $P$ as the expansion and\ncan be formulated as a matrix vector multiplication\n\\begin{align}\nf_h(x_0) = \\sum_{n=1}^N\\sum_{k=0}^{P-1} p_{nk}(x_0) \\bar f^{nk} =: \\sum_{n=1}^N\\sum_{k=0}^{P-1}I_{nk} \\bar f^{nk}\n\\label{eq:basic_interpolation}\n\\end{align}\nwhere the sparse interpolation matrix $I$ has as many rows as there are\npoints to interpolate. $I$ has $P^d$ entries per line, where $d$ is the dimensionality of the grid.\n\n\n\\subsection{Interpolation and Projection}\nA special case emerges when the list of points to interpolate is made up\nby the Gaussian abscissas of another grid.\nSuppose we want to divide each cell $C_n$ of the original grid into $M$ equidistant subcells.\nWe use the letter $c$ to denote the coarse grid and the letter $f$ to denote\nthe fine grid.\nWe denote $q_{ml}(x)$ the polynomials on the fine grid and $x^F_{mj}$ the\ncorresponding Gaussian abscissas.\nIf a vector $\\vec f$ is given on the coarse grid, we can simply interpolate\nit onto the fine grid analogous to Eq.~\\eqref{eq:basic_interpolation} via\n\\begin{align}\n  f^F_{mj} = f_h(x^F_{mj}) = p_{nk}(x^F_{mj})F^{ki} f^C_{ni}  =: {Q_{mj}}^{ni} f^C_{ni}\n  \\label{eq:interpolation}\n\\end{align}\nwhere we denote the special interpolation matrix with $Q$ and implicitly assume the sum of repeated indices.\nNo information is lost in this process if the cells $C_n$ are divided by an\ninteger number $M$ and the number of polynomials is the same, i.e.\n$f^F$ and $f^C$ represent exactly the same expansion $f_h(x)$.\n\\begin{align}\n  f^C(x) = \\bar f_C^{nk}p_{nk}(x) = f^F(x) = \\bar f_F^{ml}q_{ml}(x) \n  \\label{eq:no_loss}\n\\end{align}\n\nVice versa, given an expansion $f^F(x)$ on the fine grid, we can compute the projection integrals from the fine grid to the coarse grid.\nIt can be shown that\n\\begin{align}\n  \\bar f_C^{nk} &:= T_C^{ks}\\int \\dx f^F(x)p_{ns}(x) = T_C^{ks}  W_m^{ij}p_{ns}(x_{mj}) f^F_{mi} \\\\\n  f^C_{nt} &= B_{tk}\\bar f_C^{nk} = V^c_{tk}  {{(Q^T)}^{nk}}_{mj}W_m^{ji} f^F_{mi} =: {P_{nt}}^{mi} f^F_{mi}\n  %\\bar f_C^{nk} = T_C^{ks}\\int \\dx f^F(x)p_{ns}(x) = T_C^{ks} \\bar f_F^{ml} \\int \\dx q_{ml}(x)p_{ns}(x) \\\\\n  %= T_C^{ks} F^{lo}f^F_{mo} \\int \\dx q_{ml}(x)p_{ns}(x)  \\\\\n  %= T_C^{ks} F^{lo}f^F_{mo} W_F^{ij}q_{ml}(x_{mi})p_{ns}(x_{mj})  \\\\\n  %= T_C^{ks} F^{lo}f^F_{mo} W_m^{ij}B_{il}p_{ns}(x_{mj})  \\\\\n  %= T_C^{ks} f^F_{mi} W_m^{ij}p_{ns}(x_{mj})  \\\\\n  %f^C_{nt} = B_{tk}\\bar f_C^{nk} = B_{tk} T_C^{ks} W_m^{ij} p_{ns}(x_{mj}) f^F_{mi}\\\\\n  %= V^c_{tk} F^{sk} W_m^{ij} p_{ns}(x_{mj}) f^F_{mi}\\\\\n  %= V^c_{tk}  {Q_{mj}}^{nk}W_m^{ji} f^F_{mi}\\\\\n  %= V^c_{tk}  {{(Q^T)}^{nk}}_{mj}W_m^{ji} f^F_{mi}\\\\\n  %=: {P_{nt}}^{mi} f^F_{mi}\n  \\label{eq:basic_projection}\n\\end{align}\nfrom where we directly conclude that\n\\begin{align}\n  P = Q^\\dagger = V^C Q^T W_F\n  \\label{eq:projection_adjoint}\n\\end{align}\ni.e. the projection matrix is the adjoint of the interpolation matrix.\nWe can also proof that\n\\begin{align}\n  P\\circ Q = 1_C\n  \\label{}\n\\end{align}\nwhich is a reformulation of Eq.~\\eqref{eq:no_loss}.\nNote that $Q\\circ P \\neq 1$.\nThe projection is not loss-free but it conserves the integral\nvalue of the function on the fine grid and the error in the \n$L_2$-norm between the vectors on fine and coarse grid is \nminimal (proof?).\n\\subsection{Grid transformations}\nThe above transformation Eq.~\\eqref{eq:projection_adjoint} is\nvalid only if the number of cells in the fine grid is an integer multiple of the number of cells in the coarse grid. \nIf this is not the case, the adjoint of the interpolation matrix\ndoes not(!) give a valid projection matrix (tried this \nout in the code).\nHowever, what we can always do is to find the least common multiple grid (c) of two given grids (a) and (b). Then\nwe can interpolate loss-free from the given grid (a) to the \ncommon grid (c) and then project back from (c) to (b).\nIn this way we get the forward and backward transformation matrices\n\\begin{align}\n    \\mathcal T &= P_{c2b}Q_{a2c}\\\\\n    \\mathcal T^\\dagger &= P_{c2a} Q_{b2c}\n    \\label{}\n\\end{align}\nIf the least common grid reduces to either grid (a) or (b) the\ntransformation matrix reduces to either $P_{a2b}$ or $Q_{a2b}$ as expected.\n\n\n\\section{Relation to finite element space}\nThe list of nodal values $f_i$ gives a direct possibility to convert from dG to a finite element space (with linear elements):\n\\begin{align} \\label{eq:fem}\n    f_{\\text{FE}}(x) = f_{i} v_{i}(x)\n\\end{align}\nwhere the linear elements $v_i(x)$ are given by\n\\begin{align}\\label{eq:linear_fem}\n    v_0(x) &= \\begin{cases}\n        1 \\text{ if } x_{a}\\leq x<x_{0} \\\\\n        \\frac{x_{1} - x}{x_{1} - x_{0}} \\text{ if } x_{0}\\leq x<x_{1} \\\\\n         0 \\text{ else}\n    \\end{cases}\n    \\\\\n    v_{i}(x) &= \\begin{cases}\n        \\frac{x - x_{i-1} }{x_{i} - x_{i-1}} \\text{ if } x_{i-1}\\leq x<x_{i} \\\\\n        \\frac{x_{i+1} - x}{x_{i+1} - x_{i}} \\text{ if } x_{i}\\leq x<x_{i+1} \\\\\n         0 \\text{ else}\n    \\end{cases}\n    \\\\\n    v_{N-1}(x) &= \\begin{cases}\n        \\frac{x - x_{N-2} }{x_{N-1} - x_{N-2}} \\text{ if } x_{N-2}\\leq x<x_{N-1} \\\\\n        1 \\text{ if } x_{N-1}\\leq x<x_{b} \\\\\n         0 \\text{ else}\n    \\end{cases}\n\\end{align}\nThe first and the last element begin/end in a constant rather than a linear function\nseeing that these points have no left /right neighbor to interpolate towards.\nWe have $f_{\\text{FE}}(x_{i}) = f_{i}$. Eq.~\\eqref{eq:fem} gives an alternative\ninterpolation method, which amounts to linear interpolation between the two nearest\npoints. Unfortunately, the linear base functions~\\eqref{eq:linear_fem} are not\northogonal, that is the \"mass\" matrix of projection integrals $S_{ij} = \\int \\dx v_i(x)v_j(x)$ is a banded matrix with three diagonals.\nWe can compute the entries from a reference element $[-1,1]$\nwith the dG absicssas $x_j^a$, scaled by $h/2$\n\\begin{align}\n    &S_{ij} := \\int v_i(x)v_j(x)\\dx\\\\\n    &S_{0j} := \\frac{h}{2} \\frac{1}{6}\\begin{pmatrix}\n        6(x^a_0+1) + 2(x^a_1-x^a_0) & (x^a_1-x^a_0) & 0 \\ldots\n    \\end{pmatrix}\n    \\nonumber\\\\\n    S &:= \\frac{h}{2}\\frac{1}{6}\\begin{pmatrix}\n        (x^a_0-(x^a_{P-1}-2)) & 2(x^a_1 - (2-x^a_{P-1})) & (x^a_1 - x^a_0) & 0 & 0 \\\\\n        0 & (x^a_{k} - x^a_{k-1}) & 2(x^a_{k+1}-x^a_{k-1}) & (x^a_{k+1} - x^a_k) & 0 \\\\\n        0 & 0 & (x^a_{P-1} - x^a_{P-2}) & 2( (x^a_0+2) - x^a_{P-2}) & ((x^a_0+2)- x^a_{P-1})\n    \\end{pmatrix}\n    \\nonumber\\\\\n    &S_{(N-1)j} := \\frac{h}{2} \\frac{1}{6}\\begin{pmatrix}\n        \\ldots 0 &(x^a_{P-1} - x^a_{P-2}) & 2(x^a_{P-1} - x^a_{P-2}) + 6( 1 - x^a_{P-1})\n    \\end{pmatrix}\n\\end{align}\nNote that $S$ is diagonally dominant (on an equidistant grid the diagonal entry is twice as large as the sum of the two entries on the same row).\n%What to do for periodic boundaries? or Dirichlet?\nThus reference element consists of the $P\\times(P+2)$ blocks $hS_{\\text{ref}}/2$.\nThe weights of the finite element discretization consist of the base elements\n$h_k = (x^a_{k+1}-x^a_{k-1})2$.\n\\begin{align} \\label{eq:fem_weights}\n    W_k &= \\sum_j S_{kj}\\leftarrow W = S\\cdot \\Eins \\\\\n    W_k &= \\frac{h}{4}\\left( (x^a_1 - (x^a_{P-1}-2)),\\ \\ldots, (x^a_{k+1}-x^a_{k-1}),\\ \\ldots, ( (x^a_0+2) - x^a_{P-2})\\right)\n\\end{align}\nNote that the formula for the left and right internal cell boundaries hold for the domain boundaries as well\ndue to the equidistance in the dG cells $x^a_{P-1} = -x^a_0 $.\nWe here realize that $W^{-1}S$  is a smoothing kernel that represents the\nintegration $w_k^{-1} \\int f(x) v_k(x)\\dx$.\nAlso note that for an equidistant grid the stencil of $S$ reads $(1,4,1)$, which\ncorresponds to Simpson's integration formula.\n\n\\subsection{Interpolation and projection}\nEq.~\\eqref{eq:fem} gives a direct interpolation formula. If we take the existing\nnodes $x_i$, we can refine the grid by inserting points in between the existing points.\nLet us call the resulting interpolation matrix $I$. Then\nit can be shown that\n\\begin{align}\n    I^\\mathrm{T} W_f I = S\n\\end{align}\nwhere $W_f$ are the integration weights (Simpson's 1/3 or 3/8 rule) on the fine grid.\nThus, the adjoint of the interpolation matrix yields a projection integral $\\bar f_j = \\int \\dx v_j(x) g(x)$, which must be inverted with $f_i = S_{ij}^{-1} \\bar f_j$.\nThis inversion is the main downside of the FEM method compared to the dG method\nas it can take a significant amount of time.\n\n\n\\section{Spectral and modal filtering techniques}\nIt is well known from Godunov's theorem that linear high order schemes for hyperbolic (advection) problems\nare prone to oscillations. Discontinuous Galerkin methods are no different in that regard\nespecially the higher order ones and if the numerical flux $f=nu$ is computed via pointwise multiplication\nof the nodal representations of $n$ and $u$ via $f_{ni} = n_{ni} u_{ni}$~\\cite{NodalDG}.\nThis is due to aliasing effects. Recall that pointwise multiplication is different from\nactually multiplying the two polynomials $n_h$ and $u_h$ and projecting the result back onto the\nlower polynomial space. The problem is also known in pure spectral methods like\nFourier representations.\n\nIn finite difference and Fourier codes what is often done is adding so-called hyperdiffusion\n(or \\textbf{spectral viscosity}) to stabilize a purely hyperbolic system.\n\\begin{align}\n    \\partial_t n + \\partial_x( nu) = \\nu (-1)^{s+1}\\partial_x^{2s} n\n\\end{align}\nSince Fourier modes are Eigenfunctions of the Laplace operator this equation reads in Fourier space (disregaring the convection term)\n\\begin{align}\n    \\partial_t n_k = -\\nu k^{2s} n_k\n\\end{align}\nwhich when discretized in time using the Euler method reads\n\\begin{align}\n    n_k^{n+1} = (1-\\nu\\Delta t k^{2s}) n_k^{n}\n\\end{align}\nHere we see that the damping of modes is highest for large wave-numbers and leaves small wave-numbers intact.\nThis can be read in a more general setting as applying a low-pass filter $\\sigma(k)$ to the solution that acts on large wavenumbers\n\\begin{align}\n    n_k^{n+1} = \\sigma(k) n_k^{n}\n\\end{align}\nwhere often $\\sigma(k) = \\exp( - \\nu \\Delta t k^{2s})$ is proposed. The above Euler discretization is\nthen obtained by Taylor-expanding the exponential\n(an implicit Euler is obtained with the Pade approximation of the expontential).\n\nIt is now possible to also discretise the hyperdiffusion directly in a dG framework, however, this\nhas downsides regarding the performance since the Laplace operator is much more expensive than a\nsimple pointwise multiplication as done in Fourier codes and its solution likely needs to be done implicitly\nin order to preserve the time-step restrictions.\n\nThe better solution in a dG framework is to apply \\textbf{modal filtering} and is motivated in much the same\nway as the spectral viscosity above.\nFirst we consider that the Legendre polynomials satisfy a Sturm-Liouville type differential equation.\n\\begin{align}\n    \\frac{d}{\\d x} \\left[ (1-x^2) \\frac{ d }{d x} \\right]p_n(x) = -n(n+1) p_n(x) \\quad x \\in [-1,1]\n\\end{align}\nThis means that the Legendre polynomials are Eigenfunctions of the Sturm-Liouville operator. If we write\n\\begin{align}\n    \\partial_t n = \\nu (-1)^{s+1}\\left[\\frac{d}{\\d x}  m(x) \\frac{ d }{d x} \\right]^s  n\n\\end{align}\nwhere $m(x)$ is $(1-x^2)$ properly scaled onto each discrete cell, and use a dG approach to discretize this equation we get for each mode\n\\begin{align}\n    \\partial_t n_k = -\\nu (k(k+1))^s  n_k\n\\end{align}\nor in a time-discreized way\n\\begin{align}\n    n_k^{n+1} = (1-\\nu \\Delta t (k(k+1))^s ) n_k^n\n\\end{align}\nwhich is entirely analogous to the derivation above.\nIn the same way we can read this as applying a filter function to the Legendre modes.\n\\begin{align}\n    n_k^{n+1} = \\sigma(k) n_k^n\n\\end{align}\nwith $\\sigma(k) = \\exp( - \\nu \\Delta t (k(k+1))^s)$.\nNote that the modal filter, as the spectral filter, does not inhibit oscillations from happening (it is not shock-capturing) but it dampens grid-scale oscillations\nand can stabilize the system.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\bibliography{../references}\n%..................................................................\n\\end{document}\n", "meta": {"hexsha": "817a4f59c13413f545801fa1bd57a4c36d1111fd", "size": 38876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/related_pages/dg_introduction/dg_introduction.tex", "max_stars_repo_name": "RaulGerru/FELTOR_FINAL", "max_stars_repo_head_hexsha": "dd5af5e61d1607eb3b0415b756c1a6cf56b63a2c", "max_stars_repo_licenses": ["MIT"], "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/related_pages/dg_introduction/dg_introduction.tex", "max_issues_repo_name": "RaulGerru/FELTOR_FINAL", "max_issues_repo_head_hexsha": "dd5af5e61d1607eb3b0415b756c1a6cf56b63a2c", "max_issues_repo_licenses": ["MIT"], "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/related_pages/dg_introduction/dg_introduction.tex", "max_forks_repo_name": "RaulGerru/FELTOR_FINAL", "max_forks_repo_head_hexsha": "dd5af5e61d1607eb3b0415b756c1a6cf56b63a2c", "max_forks_repo_licenses": ["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.0334620335, "max_line_length": 279, "alphanum_fraction": 0.6771529993, "num_tokens": 13015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727026, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6025074187995565}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage[margin=0.75in]{geometry}\n\\usepackage[numbers]{natbib}\n\\usepackage{physics}\n\\usepackage[hyphens]{url}\n\\usepackage[labelformat=simple,position=b]{subcaption}\n\\renewcommand\\thesubfigure{(\\alph{subfigure})}\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\rhead{cosmiQ}\n\\lhead{Hackathon 2021}\n\\rfoot{Page \\thepage}\n\n\\usepackage{graphicx}\n\\graphicspath{\n\t{figures}\n}\n\n\\usepackage[hidelinks]{hyperref}\n\n\n\\renewcommand{\\phi}{\\varphi}\n\n\n\\title{Hackathon Docs}\n\\author{cosmiQ}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n%\\thispagestyle{empty}\n\\section*{Introduction}\n\nThe main problem of interest is of the form:\n\\begin{align}\n\\mathcal{H} &= \\sum_{t_0}^{t_f} \\sum_i -\\mu(t,i) \\hat{w}(t,i) + \\sum_{t_0+1}^{t_f} \\left(\\sum_i \\lambda(t,i) \\hat{w}(t,i) - \\hat{w}(t-1,i) \\right)^2 +  \\left(\\sum_i \\lambda(t_0,i) \\hat{w}(t_0,i)\\right)^2\\nonumber\\\\\n&+ \\frac{\\gamma}{2} \\sum_{t_0}^{t_f} \\sum_{ij} \\hat{w}(t,i) \\Sigma^t_{ij} \\hat{w}(t,j) + \\rho \\left(\\sum_i \\hat{w}(t,i) - 1\\right)^2\n\\end{align}\n\nTo further represent it on a quantum computer we use the following:\n\\begin{align}\n\\hat{w}(t,i) = \\frac{1}{K}\\sum_q^{N_q} d^q \\hat{n}(t,i,q),\n\\end{align}\nwhere utilize $N_q$ physical bits of local dimension $d$. For quitrits $d = 3$. We also use $N_t$ number of time samples and $N$ number of assets (indexed by $i$). Typically $K$ is used to control the precision or resolution. For normal circumstance $K = d^{N_q}$ is sufficient. Here $\\mu(t,i)$ represents the profit over the incremental timer interval of assessment. The terms $\\lambda(t,i)$ control the transactions and is written in this form to allowed time-dependence as well as asset class dependence. $\\Sigma^t_{ij}$ are the terms in the covariance matrix and $\\gamma$ controls the penalty for allowing volatile assets. $\\rho$ is the Lagrange multiplier useful to control the constraint.\n\nFrom which we obtain the following compact set of equations:\n\\begin{align}\n\\mathcal{H} &= \\sum_{t_0}^{t_f} \\sum_i \\sum_q (-\\mu(t,i) - 2\\rho) \\frac{d^q}{K} \\hat{n}(t,i,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i<j} \\sum_{q<p} 4(\\frac{\\gamma}{2} \\Sigma^t_{ij} + \\lambda(t,i)\\lambda(t,j) + \\rho)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i<j} \\sum_{q} 2 (\\frac{\\gamma}{2} \\Sigma^t_{ij} + \\lambda(t,i)\\lambda(t,j) + \\rho)\\frac{d^{2q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i} \\sum_{q<p} 2 (\\frac{\\gamma}{2} \\Sigma^t_{ij} + \\lambda(t,i)^2 + \\rho)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i} \\sum_{q}  (\\frac{\\gamma}{2} \\Sigma^t_{ii} + \\lambda(t,i)^2 + \\rho)\\frac{d^{2q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,q) \\nonumber\\\\\n%%\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i<j} \\sum_{q<p} 4(\\lambda(t,i)\\lambda(t,j))\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i<j} \\sum_{q} 2 (\\lambda(t,i)\\lambda(t,j))\\frac{d^{2q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i} \\sum_{q<p} 2 (\\lambda(t,i)^2)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i} \\sum_{q} 2 (\\lambda(t,i)^2)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,q) \\nonumber\\\\\n%%\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i<j} \\sum_{q<p} (-8)(\\lambda(t+1,i)\\lambda(t+1,j))\\frac{d^{p+q}}{K^2} \\hat{n}(t+1,i,q)\\hat{n}(t,j,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i<j} \\sum_{q} (-4)(\\lambda(t+1,i)\\lambda(t+1,j))\\frac{d^{2q}}{K^2} \\hat{n}(t+1,i,q)\\hat{n}(t,j,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i} \\sum_{q<p} (-4) (\\lambda(t+1,i)^2)\\frac{d^{p+q}}{K^2} \\hat{n}(t+1,i,q)\\hat{n}(t,i,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f-1} \\sum_{i} \\sum_{q} (-2) (\\lambda(t+1,i)^2)\\frac{d^{p+q}}{K^2} \\hat{n}(t+1,i,q)\\hat{n}(t,i,q) \\nonumber\\\\\n&+ N_t\n\\end{align}\n\nThese equations have been encoded in the file flatnetwork.py. That file sets up our DMRG calculations, which we use to test the quality of more approximate solutions via quantum hardware or simulation. A simpler version of the equations above can be obtained if we ignore transaction costs and volatility. This serves a useful step towards testing solutions and assessing behaviour (not to mention debugging). These equations are given by:\n\n\\begin{align}\n\\mathcal{H} &= \\sum_{t_0}^{t_f} \\sum_i \\sum_q (-\\mu(t,i) - 2\\rho) \\frac{d^q}{K} \\hat{n}(t,i,q) \n+  \\sum_{t_0}^{t_f} \\sum_{i} \\sum_{q}  (\\rho)\\frac{d^{2q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i} \\sum_{q<p} 2 (\\rho)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,i,p) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i<j} \\sum_{q} 2 (\\rho)\\frac{d^{2q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,q) \\nonumber\\\\\n&+  \\sum_{t_0}^{t_f} \\sum_{i<j} \\sum_{q<p} 4(\\rho)\\frac{d^{p+q}}{K^2} \\hat{n}(t,i,q)\\hat{n}(t,j,p) \\nonumber\\\\\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "5bf61f9310fa63c56445003e68e96a8f547fd143", "size": 4818, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CosmiQ/writeup/CDL_Hackathon_cosmiQ.tex", "max_stars_repo_name": "stared/Hackathon2021", "max_stars_repo_head_hexsha": "69e2ba4345b311e62d09d02f6953b25614229e12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-07-26T13:45:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T09:15:23.000Z", "max_issues_repo_path": "CosmiQ/writeup/CDL_Hackathon_cosmiQ.tex", "max_issues_repo_name": "stared/Hackathon2021", "max_issues_repo_head_hexsha": "69e2ba4345b311e62d09d02f6953b25614229e12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-26T19:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-28T08:32:20.000Z", "max_forks_repo_path": "CosmiQ/writeup/CDL_Hackathon_cosmiQ.tex", "max_forks_repo_name": "stared/Hackathon2021", "max_forks_repo_head_hexsha": "69e2ba4345b311e62d09d02f6953b25614229e12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 35, "max_forks_repo_forks_event_min_datetime": "2021-07-26T13:10:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T05:23:48.000Z", "avg_line_length": 58.756097561, "max_line_length": 694, "alphanum_fraction": 0.6313823163, "num_tokens": 2046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450968, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6025063555433726}}
{"text": "\\subsection{Bonus: Gaussian Curvature and Pizza}\r\nChoose a normal of a surface and consider planes containing that normal.\r\nWe can draw many curves on the surface now by considering the intersection of the planes and the surface and measure their curvatures at that particular point.\r\n\\begin{definition}\r\n    The Gaussian curvature is defined as\r\n    $$K_G=K_{\\rm max} K_{\\rm min}$$\r\n    where $K_{\\rm max}$ and $K_{\\rm min}$ are the maximal and minimal curvatures of such curves.\r\n\\end{definition}\r\nFor example, a flat piece of paper has $K_G=0$.\r\nOf course, we can define this much more rigorously, but that is out of the scope of this course.\r\nFor this definition of surface curvature, Gauss proved that:\r\n\\begin{theorem}[Theorema Egregium]\r\n    The Gaussian curvature is invariant under isometries.\r\n\\end{theorem}\r\nSo it is like when you bend a pizza isometrically, since it still has Gaussian curvature $0$ as it had before, the pizza has to be flopped up so as to be eaten.", "meta": {"hexsha": "e6a7a59bedc91795a3755f207b7119ceea37de5b", "size": 979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/pizza.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": "1/pizza.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": "1/pizza.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.2666666667, "max_line_length": 160, "alphanum_fraction": 0.7568947906, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.6893056104028797, "lm_q1q2_score": 0.6025063421245805}}
{"text": "\\section{Appendix A: Separation Distance from Second Moments}\\label{sec:appA}\n\nFrom the LSST catalogs the following {\\tt Object} table elements are used to define the parameters needed to calculate the separation distance \\citedsp{LSE-163}:\n\n\\begin{center}\n\\begin{tabular}{ccll}\n\\hline\nParameter & Unit & Table Element & Description \\\\\n\\hline\n$x_{\\rm trans},y_{\\rm trans}$ & $\\rm degrees$ & {\\tt DIAObject} {\\tt radec} & transient centroid  \\\\\n$x_{\\rm gal},y_{\\rm gal}$       & $\\rm degrees$ & {\\tt Object} {\\tt radec}       & galaxy centroid      \\\\\n$\\overline{x^2}$,$\\overline{y^2}$,$\\overline{xy}$ & $\\rm arcsec^2$  & {\\tt Object} {\\tt Ixx}, {\\tt Iyy}, {\\tt Ixy} & galaxy second moments \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nThere might be an issue with using the {\\tt Object} catalog second moments: the {\\tt Ixx}, {\\tt Iyy}, and {\\tt Ixy} are defined with with respect to the local tract/patch and not sky coordinates (Jira DM-19519).\nAlthough the local tangent projection will probably work fine for this application of the second moments, this should be verified at the time of implementation.\n\nAs described in Section 10 of E. Bertin's Source Extractor manual\\footnote{Version 2.3: \\url{https://www.astromatic.net/pubsvn/software/sextractor/trunk/doc/sextractor.pdf}} (and presumably many other places), the unitless ellipse parameters $C_{xx},C_{yy},C_{xy}$ can be calculated from the second moments via:\n\n\\begin{equation}\nC_{xx} = \\frac{\\overline{y^2}}{\\sqrt{ \\left( \\frac{\\overline{x^2}-\\overline{y^2}}{2} \\right)^2 + \\overline{xy}^2}}\n\\end{equation}\n\n\\begin{equation}\nC_{yy} = \\frac{\\overline{x^2}}{\\sqrt{ \\left( \\frac{\\overline{x^2}-\\overline{y^2}}{2} \\right)^2 + \\overline{xy}^2}}\n\\end{equation}\n\n\\begin{equation}\nC_{xy} = -2 \\frac{\\overline{xy}}{\\sqrt{ \\left( \\frac{\\overline{x^2}-\\overline{y^2}}{2} \\right)^2 + \\overline{xy}^2}}\n\\end{equation}\n\nThe sky distances between the transient and galaxy centroids are calculated as follows, and include the $\\cos(\\delta)$ factor and a conversion from units of degrees to arcseconds:\n\n\\begin{equation}\nx_r = 3600(x_{\\rm SN} - x_{\\rm gal})\n\\end{equation}\n\n\\begin{equation}\ny_r = 3600(y_{\\rm SN} - y_{\\rm gal})\\cos{y_{\\rm gal}}\n\\end{equation}\n\nFinally, the separation distance $R$ in arcseconds is given by:\n\n\\begin{equation}\nR^2 = C_{xx} x_r^2 + C_{yy} y_r^2 + C_{xy} x_r y_r.\n\\end{equation}\n", "meta": {"hexsha": "7b0e4e55a75bdf87ec6f2aa58f0c48e421a9360d", "size": 2348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AppendixA.tex", "max_stars_repo_name": "lsst-dm/dmtn-151", "max_stars_repo_head_hexsha": "b7d498d4eaa78e444bd76fad112cef23157a6adb", "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": "AppendixA.tex", "max_issues_repo_name": "lsst-dm/dmtn-151", "max_issues_repo_head_hexsha": "b7d498d4eaa78e444bd76fad112cef23157a6adb", "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": "AppendixA.tex", "max_forks_repo_name": "lsst-dm/dmtn-151", "max_forks_repo_head_hexsha": "b7d498d4eaa78e444bd76fad112cef23157a6adb", "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.9183673469, "max_line_length": 311, "alphanum_fraction": 0.6997444634, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6024709016471327}}
{"text": "% !TeX root = thoughts.tex\n\\section{\\label{SEC:tom}Linear tomography}\n\nIn this section the \\gls{HMC} sampler is applied to a linear two dimensional tomography problem. These kind of problems might be high dimensional, and I will eveluate two different sizes of models with varying velocity models. With the aid of model and data resolution matrices we are able to link the quality of the inversions to the actual models and measurement configurations.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/tomography/tomography_1/model_3by7_3s_5r}\n\t\t\\caption{Parameters of model}\n\t\t\\label{fig:linear_tomography.model1.parameters}\n\t\\end{subfigure}%\n\t\\begin{subfigure}{.5\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/tomography/tomography_1/model_3by7_3s_5r_rays}\n\t\t\\caption{Ray coverage of model}\n\t\t\\label{fig:linear_tomography.model1.rays}\n\t\\end{subfigure}\n\t\\caption{Linear tomography model used in the first part of Section~\\ref{SEC:tom}, with 21 dimensions. The ray coverage is variable per cell, and can be better analysed in Figure~\\ref{fig:linear_tomography.resolution1}}\n\t\\label{fig:linear_tomography.model1}\n\\end{figure}\n\n\\subsection{Straight ray tomography and a first model}\n\\index{Straight ray solver}In this part, extensive use is made of the MATLAB package written by Naiara Korta Martiartu and Christian B\\\"ohm (Computational Seismology Group (CSE), ETH Z\\\"urich). I will leave out the details of this algorithm, as it is perfectly explained in the accompanying manual. The important bit is that the algorithm produces the linear system matrix and synthetic data.\n\nStraight ray tomography is especially suited to test \\gls{HMC} for it's forward model is completely linear, and it usually encompasses some interesting correlated parameters and mixed-determined systems. \n\nWe'll start by looking at a relatively simple model of 21 dimensions. The region of interest is composed out of 7x3 blocks of 5 meters wide, as depicted in Figure~\\ref{fig:linear_tomography.model1.parameters}. In this region, 3 sources and 5 receivers are present, set up as in Figure~\\ref{fig:linear_tomography.model1.rays}. This results in $3 \\cdot 5 = 15$ data points. The resulting forward matrix $\\MatrixVariable{G}$ is therefore of size 15x21. Each block in the model has rays passing through it in a different way, and may be differently resolved then the next block.\n\n\\index{Resolution matrix}\\textbf{Note, I actually started on this thinking these were resolution matrices, but I read Hansruedi's script wrong. Still, my analysis stands and I wonder what these matrices actually represent.} To visualize this, we employ the parameter (again, not really the) resolution matrix, for equal data covariance given by $\\MatrixVariable{G}^T\\MatrixVariable{G}$ (which, interestingly enough, is equal to the original proposal of the mass matrix in \\gls{HMC}). In this matrix, the diagonal elements define how well resolved each parameter is relatively, while the rows (as well as the columns, the matrix is symmetric) define averaging kernels.\n\nAs seen in Figure~\\ref{fig:linear_tomography.model1.parameter_resolution}, some parameters are properly resolved, while others are not. Well resolved parameters have higher indices (note that the matrix is normalized, so we can't say anything about absolutely quality). Some parameters also have high off-diagonal elements, which indicates correlation between parameters. This means that if one of these parameters is high, it influences our perception of the other parameter.\n\nFigure~\\ref{fig:linear_tomography.model1.data_resolution} shows the data resolution matrix, given by $\\MatrixVariable{G}\\,\\MatrixVariable{R}\\,\\MatrixVariable{G}^T$ for equal data covariance. This matrix helps us identify which data is relatively important in the resolution of parameters, i.e. which have a large impact on the inversion. For example, data points 7 through 9 have the highest data importance; they relate the  parameter well to the observed value.\n\nThe actual resolution matrices for linear systems are identity matrices, providing not so much insight.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{.48\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/tomography/tomography_1/model_resolution}\n\t\t\\caption{\\index{Resolution matrix!Parameter}Parameter resolution matrix}\n\t\t\\label{fig:linear_tomography.model1.parameter_resolution}\n\t\\end{subfigure}\\;\n\t\\begin{subfigure}{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{figures/tomography/tomography_1/data_resolution}\n\t\t\\caption{\\index{Resolution matrix!Data}Data resolution matrix}\n\t\t\\label{fig:linear_tomography.model1.data_resolution}\n\t\\end{subfigure}\n\t\\caption{Normalized `half' resolution matrices for the model depicted in Figure~\\ref{fig:linear_tomography.model1}.}\n\t\\label{fig:linear_tomography.resolution1}\n\\end{figure}\n\n\\paragraph{Velocity model and inversions}\nThe velocity model used for the synthetic data is a simple homogeneous model with acoustic speed constant at $20000 m/s$. Inversion characteristics are given in Table~\\ref{tab:inversion.tom1}. The parameter which is inverted for is slowness, and the prior means is taking as 1.0/1500.0, with a standard deviation of 0.00025 seconds per meter. A consequence of the system being underdetermined is that less resolved parameters will diverge from the real model in the sense that some will tend towards the prior information, which changes correlated parameters to higher values. The means after inversion are given in Figure~\\ref{fig:linear_tomography.model1.means} and show this characteristic quite strongly.\n\n\\begin{table}[]\n\t\\centering\n\t\\begin{tabular}{r l}\n\t\tNumber of Samples & 1,000,000 \\\\\n\t\tNumber of timesteps & 10 \\\\\n\t\tLength of timestep & 0.1 \\\\ \\hline \n\t\tRuntime & 118.324 s \\\\\n\t\tAccepted samples & 108215 \\\\\n\t\tNumber of U-Turns & 0\n\t\\end{tabular}\n\t\\caption{Inversion parameters for first tomography inversions.}\n\t\\label{tab:inversion.tom1}\n\\end{table}\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=1\\textwidth]{figures/tomography/tomography_1/tomographyMeans}\n\t\n\t\\caption{Means after the initial inversion of approximately 100,000 accepted samples. The parameters at the very horizontal ends of the model are relatively low, probably due to the small entries in the pseudo-resolution matrix. These parameters are not influenced by actual data that much and therefor are pulled more towards the prior informations. At the same time, to compensate for relatively low speeds, parameters in other parts are excessively high. The actual speed in most elements (columns 5 through 20) is however close to the actual forward model of 2000 $m/s$.}\n\t\\label{fig:linear_tomography.model1.means}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=0.6\\textwidth]{figures/tomography/tomography_1/tomographyCovariance}\n\t\n\t\\caption{Parameter covariance of the approximately 100,000 inversion samples. The band of negative correlation of entries $\\sigma_i,j$ and $\\sigma_{i,j\\pm3}$ or $\\sigma_{i\\pm3,j}$ is generated by blocks that lie next to each other; as one speed goes up, the next and previous horizontal blocks compensate by lowering their speed. This behaviour is upon close inspection also visible for the $\\pm6$ bands. Entries in the same model column also experience a kind of grouping, but with positive correlation. The maximum covariance is $3.6 \\cdot 10^{-8}$.}\n\t\\label{fig:linear_tomography.model1.covariance}\n\\end{figure}\n\n\\paragraph{Influence of data dimension on performance}\nBefore we saw the influence of the amount of parameters on the inversion performance. Another possible detrimental factor might be the amount of data, which also alters some computational requirements. The predicted influence is not so big, as in the model propagation the dimension is not increase. The additional computational cost will be mostly present in evaluating misfits and their gradients, but as these numbers are definitely precomputed the influence might be weak. \n\nTo test this, we change the amount of receivers in the previously used homogeneous model. Specifically, we add 5 receivers centered in the model blocks starting from the column at $x=25$, working our way to the column $x=5$. This will add 15 data points each step, increasing all the way to 90. Other inversion characteristics remain unchanged.\n\nAfter each data increase, the model parameters will be better retrieved. Only shown is the last covariance matrix, with 3240 data points. It has relatively less large entries with respect to the largest one. Also the maximum covariance ($2.2 \\cdot 10^{-9}$) is lower than the original ($3.6 \\cdot 10^{-8}$) for the inversion with 15 data points. The actual runtime is almost not influenced by the amount of data points (number of rows of the forward model).\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=0.5\\textwidth]{figures/tomography/tomography_1/increasing_data/performanceData}\n\t\n\t\\caption{Algorithm runtime for increasing amount of datapoints. There seems to be no impact on the algorithm performance with an increasing amount of datapoints.}\n\t\\label{fig:linear_tomography.model1.performanceData}\n\\end{figure}\n\n\\begin{figure}\n\t\\centering\n\t\n\t\\includegraphics[width=0.6\\textwidth]{figures/tomography/tomography_1/increasing_data/tomographyLastCovariance}\n\t\n\t\\caption{Normalized covariance matrix of the last inversion from Figure~\\ref{fig:linear_tomography.model1.performanceData} with 3240 datapoints. Maximum parameter covariance is $2.2 \\cdot 10^{-9}$.}\n\t\\label{fig:linear_tomography.model1.performanceLastCovariance}\n\\end{figure}\n%\\begin{figure}\n%\t\\centering\n%\t\n%\t\\includegraphics[width=1\\textwidth]{figures/tomography/tomography_2/tomographyModel}\n%\t\n%\t\\caption{Velocity model used for the synthetics of the second tomography inversion. The values of the layer from small to large $y$ are 1800, 1600 and 1400 $m/s$ respectively.}\n%\t\\label{fig:linear_tomography.model2.velocity}\n%\\end{figure}\n\n\\subsection{Generalized momentum}\nAt this point I wondered about the influence of implementing the generalized momentum. Implementing this however requires the development of some additional theory. To calculate the generalized momentum we need to invert the mass matrix, which is already an interesting problem. Additionally, we'd like to propose momenta that are correlated according to the mass matrix, so we need to sample from a multivariate correlated Gaussian. I'll start with the second problem, as the result of that simplifies our first problem as we'll see later.\n\n\\paragraph{Sampling from an $n$-dimensional Gaussian}\nUp to now, we've proposed new momenta by regarding the diagonal of the mass matrix as the variance of each mass. By taking the square root of the inverse of the diagonal we obtained standard deviations of each mass, and by setting the mean to zero we drew new momenta using the Box-M\\\"uller transform.\n\nAn extension of this mass matrix interpretation is to regard the off diagonal elements as the covariance between parameters. This yields for an $n \\times n$ matrix an $n$-dimensional correlated Gaussian. \n\n\\index{Affine transform}First we establish the definition of an affine transformation and it's effect on a normal distribution. The distribution $\\mathbf{X} \\sim \\mathcal{N}_n \\left( \\bm{\\mu}, \\bm{\\Sigma} \\right)$ represent a normal distribution of means $\\left[\\bm{\\mu}\\right]_i = \\mu_i$ and covariances $\\left[ \\bm{\\Sigma} \\right]_{ij} = \\sigma_{ij} = \\sigma_i \\sigma_j \\rho_{ij}$ (covariance $\\sigma_{ij}$, standard deviation $\\sigma_i$ and correlation $\\rho_{ij}$). Now, if $\\mathbf{Y} = \\bm{L} \\mathbf{X} + \\bm{c}$ is an affine transformation (that is to say, the transform acts linearly on a vector, which it does for matrix-vector multiplication) then the resulting distribution $\\mathbf{Y}$ has means $\\bm{c} + \\bm{L}\\bm{\\mu}$ and variance $\\bm{L} \\bm{\\Sigma} \\bm{L}^T$ (the proof is given in Appendix~\\ref{APP:affinenormal}).\n\nIf we now sample $\\mathbf{X} = \\mathcal{N}_n \\left( \\mathbf{0},\\mathbf{I} \\right)$ and transform it using $\\bm{L}\\mathbf{X}$ such that $\\bm{L}\\bm{I}\\bm{L}^T = \\bm{L}\\bm{L}^T = \\bm{\\Sigma}$ we have effectively sampled $\\mathbf{Y} = \\mathcal{N}_n \\left( \\mathbf{0},\\mathbf{\\Sigma} \\right)$. Changing the means is as easy as adding the mean vector.\n\n\\index{Momenta!Drawing}Equipped with this we can now draw from a correlated Gaussian in the following way;\n\\begin{itemize}\n\t\\item Draw $n$ uncorrelated samples with mean $\\mu_i$ = 0 and standard deviation $\\sigma_i$ = 1;\n\t\\item Multiple this samples vector with a matrix $M$ ($n \\times n$) which transforms $\\mathbf{I}$ to $\\mathbf{\\Sigma}$ during the affine transform;\n\t\\item Add the wanted mean.\n\\end{itemize}\n\n\\index{Cholesky decomposition}The second step, finding an appropriate matrix, is the most complicated part of the process. Luckily, we have proven already that our mass matrix is positive definite. These types of matrices, given that they are self adjoint/Hermitian, are representable by a Cholesky decomposition. The Hermitian property is easily validated; covariances are symmetric and real. The Cholesky decomposition produces a lower triangular matrix $\\mathbf{L}$ from a positive definite Hermitian matrix $\\mathbf{A}$ with the property:\n\n\\begin{align}\n\t\\mathbf{A} = \\mathbf{L} \\mathbf{L}^\\dagger.\n\\end{align}\nHere, $\\mathbf{L}^\\dagger$ stands for the conjugate transpose of $\\mathbf{L}$. For the real matrices we are working with, this simplifies to transposition only. Finding the appropriate affine transform is now reduced to finding the appropriate Cholesky decomposition of $\\mathbf{\\Sigma}$. To achieve this, the Cholesky-Banachiewicz algorithm is implemented.\n\n\\paragraph{Evaluating the generalized momentum}\n\\index{Momenta!Generalized}\nThe generalized kinetic energy, extended from Equation~\\ref{eq:kineticsimple} according to \\cite{neal2011mcmc}, is given as\n\n\\begin{gather}\n\tK(\\mathbf{p}) = \\frac{1}{2} \\mathbf{p}^T \\mathbf{M}^{-1} \\mathbf{p}.\n\\end{gather}\n\\index{Mass matrix!inverse}\nThe difficulty in evaluating this expression is in calculating the matrix inverse of the mass matrix, which for large systems would result in quite some processing time. But since one already has acquired the Cholesky decomposition we can easily show that:\n\\begin{gather}\n\t\\mathbf{A} ^{-1} = \\left( \\mathbf{L} \\mathbf{L}^T \\right)^{-1} = \\left(\\mathbf{L}^T\\right)^{-1} \\left( \\mathbf{L} \\right) ^{-1}.\n\\end{gather}\nNow, we're still left with a matrix inverse, but inverting a lower triangular matrix is easily done by forward and back substitution algorithms\n\\footnote{https://en.wikipedia.org/wiki/Triangular\\_matrix\\#Forward\\_and\\_back\\_substitution}\n, obtaining every element of a column row by row when inverting $\\mathbf{L} \\mathbf{L}^{-1} = \\mathbf{I}$. Following that we simply use $({\\mathbf{L}^T})^{-1} =({\\mathbf{L}^{-1}})^{T} $ and multiply the two inverse matrices to obtain $\\mathbf{A}^{-1}$.\n\n\n\n\n\n\n", "meta": {"hexsha": "e72f9d6d084123d933b8de7d0ff180735e7a3d9b", "size": 14964, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thoughts/tomography.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/tomography.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/tomography.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": 87.0, "max_line_length": 834, "alphanum_fraction": 0.7825447741, "num_tokens": 3816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.602470885703543}}
{"text": "\\chapter{The PID structure theorem}\nThe main point of this chapter is to discuss a classification\ntheorem for finitely generated abelian groups.\nThis won't take long to do, and if you like, you can read\njust the first section and then move on.\n\nHowever, since I'm here, I will go ahead and state the result as a\nspecial case of the much more general \\emph{structure theorem}.\nIts corollaries include\n\\begin{itemize}\n\t\\ii All finite-dimensional vector spaces are $k^{\\oplus n}$.\n\t\\ii The classification theorem for finitely generated abelian groups,\n\t\\ii The Jordan decomposition of a matrix from before,\n\t\\ii Another canonical form for a matrix: ``Frobenius normal form''.\n\\end{itemize}\n\n\\section{Finitely generated abelian groups}\n\\label{sec:FTFGAG}\n\\begin{remark}\n\tWe talk about abelian groups in what follows, but really the\n\tmorally correct way to think about these structures is as $\\ZZ$-modules.\n\\end{remark}\n\\begin{definition}\n\tAn abelian group $G = (G,+)$ is \\vocab{finitely generated}\n\tif it is finitely generated as a $\\ZZ$-module.\n\t(That is, there exists a finite collection $b_1, \\dots, b_m \\in G$,\n\tsuch that every $x \\in G$ can be written in the form\n\t$c_1 b_1 + \\dots + c_m b_m$ for some $c_1, \\dots, c_m \\in \\ZZ$.)\n\\end{definition}\n\\begin{example}\n\t[Examples of finitely generated abelian groups]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\ZZ$ is finitely generated (by $1$).\n\t\t\\ii $\\Zc n$ is finitely generated (by $1$).\n\t\t\\ii $\\ZZ^{\\oplus 2}$ is finitely generated (by two elements $(1,0)$ and $(0,1)$).\n\t\t\\ii $\\ZZ^{\\oplus 3} \\oplus \\Zc9 \\oplus \\Zc{2016}$ is\n\t\tfinitely generated by five elements.\n\t\t\\ii $\\Zc3\\oplus\\Zc5$ is finitely generated by two elements.\n\t\\end{enumerate}\n\\end{example}\n\\begin{exercise}\n\tIn fact $\\Zc3\\oplus\\Zc5$ is generated by \\emph{one} element.\n\tWhat is it?\n\\end{exercise}\nYou might notice that these examples are not very diverse.\nThat's because they are actually the only examples:\n\\begin{theorem}\n\t[Fundamental theorem of finitely generated abelian groups]\n\tLet $G$ be a finitely generated abelian group.\n\tThen there exists an integer $r$,\n\tprime powers $q_1$, \\dots, $q_m$ (not necessarily distinct) such that\n\t\\[\n\t\tG \\cong \\ZZ^{\\oplus r} \\oplus \\Zc{q_1} \\oplus \\Zc{q_2} \\oplus\n\t\t\\dots \\oplus \\Zc{q_m}. \\]\n\tThis decomposition is unique up to permutation of the $\\Zc{q_i}$.\n\\end{theorem}\n\\begin{definition}\n\tThe \\vocab{rank} of a finitely generated abelian group $G$ is the integer $r$ above.\n\\end{definition}\n\nNow, we could prove this theorem, but it is more interesting to go for the gold\nand state and prove the entire structure theorem.\n\n\\section{Some ring theory prerequisites}\n\\prototype{$R = \\ZZ$.}\nBefore I can state the main theorem, I need to define a few terms for UFD's,\nwhich behave much like $\\ZZ$:\n\\begin{moral}\n\tOur intuition from the case $R = \\ZZ$ basically carries over verbatim.\n\\end{moral}\nWe don't even need to deal with prime ideals and can factor elements instead.\n\n\\begin{definition}\n\tIf $R$ is a UFD, then $p \\in R$ is a \\vocab{prime element}\n\tif $(p)$ is a prime ideal and $p \\neq 0$.\n\tFor UFD's this is equivalent to:\n\tif $p = xy$ then either $x$ or $y$ is a unit.\n\\end{definition}\nSo for example in $\\ZZ$ the set of prime elements is $\\{\\pm2, \\pm3, \\pm5, \\dots\\}$.\nNow, since $R$ is a UFD, every element $r$ factors into a product of prime elements\n\\[ r = u p_1^{e_1} p_2^{e_2} \\dots p_m^{e_m} \\]\n\n\\begin{definition}\n\tWe say $r$ \\vocab{divides} $s$ if $s = r'r$\n\tfor some $r' \\in R$. This is written $r \\mid s$.\n\\end{definition}\n\\begin{example}\n\t[Divisibility in $\\ZZ$]\n\tThe number $0$ is divisible by every element of $\\ZZ$.\n\tAll other divisibility as expected.\n\\end{example}\n\\begin{ques}\n\tShow that $r \\mid s$ if and only if the exponent of each prime in $r$ is\n\tless than or equal to the corresponding exponent in $s$.\n\\end{ques}\n\nNow, the case of interest is the even stronger case when $R$ is a PID:\n\\begin{proposition}\n\t[PID's are Noetherian UFD's]\n\tIf $R$ is a PID, then it is Noetherian and also a UFD.\n\\end{proposition}\n\\begin{proof}\n\tThe fact that $R$ is Noetherian is obvious.\n\tFor $R$ to be a UFD we essentially repeat the proof for $\\ZZ$,\n\tusing the fact that $(a,b)$ is principal in order to extract\n\t$\\gcd(a,b)$.\n\\end{proof}\n\nIn this case, we have a Chinese remainder theorem for elements.\n\\begin{theorem}\n\t[Chinese remainder theorem for rings]\n\tLet $m$ and $n$ be relatively prime elements, meaning $(m) + (n) = (1)$.\n\tThen \\[ R / (mn) \\cong R/(m) \\times R/(n). \\]\n\\end{theorem}\nHere the ring product is as defined in \\Cref{ex:product_ring}.\n\\begin{proof}\n\tThis is the same as the proof of the usual Chinese remainder theorem.\n\tFirst, since $(m,n)=(1)$ we have $am+bn=1$ for some $a$ and $b$.\n\tThen we have a map\n\t\\[ R/(m) \\times R/(n) \\to R/(mn) \\quad\\text{by}\\quad\n\t\t(r,s) \\mapsto r \\cdot bn + s \\cdot am. \\]\n\tOne can check that this map is well-defined and an isomorphism of rings.\n\t(Diligent readers invited to do so.)\n\\end{proof}\n\nFinally, we need to introduce the concept of a Noetherian $R$-module.\n\\begin{definition}\n\tAn $R$-module $M$ is \\vocab{Noetherian}\n\tif it satisfies one of the two equivalent conditions:\n\t\\begin{itemize}\n\t\t\\ii Its submodules obey the ascending chain condition:\n\t\tthere is no infinite sequence of modules\n\t\t$M_1 \\subsetneq M_2 \\subsetneq \\dots$.\n\t\t\\ii All submodules of $M$ (including $M$ itself) are finitely generated.\n\t\\end{itemize}\n\\end{definition}\nThis generalizes the notion of a Noetherian ring:\na Noetherian ring $R$ is one for which $R$ is Noetherian as an $R$-module.\n\\begin{ques}\n\tCheck these two conditions are equivalent. (Copy the proof for rings.)\n\\end{ques}\n\n\\section{The structure theorem}\nOur structure theorem takes two forms:\n\\begin{theorem}\n\t[Structure theorem, invariant form]\n\tLet $R$ be a PID and let $M$ be any finitely generated $R$-module. Then\n\t\\[ M \\cong \\bigoplus_{i=1}^m R/(s_i) \\]\n\tfor some $s_i$ (possibly zero)\n\tsatisfying $s_1 \\mid s_2 \\mid \\dots \\mid s_m$.\n\t% These $s_i$ are unique up to multiplication by units.\n\\end{theorem}\n\\begin{corollary}\n\t[Structure theorem, primary form]\n\tLet $R$ be a PID and let $M$ be any finitely generated $R$-module. Then\n\t\\[ M \\cong R^{\\oplus r}\n\t\t\\oplus R/(q_1) \\oplus R/(q_2) \\oplus \\dots \\oplus R/(q_m) \\]\n\twhere $q_i = p_i^{e_i}$ for some prime element $p_i$ and integer $e_i \\ge 1$.\n\t% The numbers $r$ and $q_i$ are unique up to permutation and multiplication by units.\n\\end{corollary}\n\\begin{proof}\n\t[Proof of corollary]\n\tFactor each $s_i$ into prime factors (since $R$ is a UFD),\n\tthen use the Chinese remainder theorem.\n\\end{proof}\n\\begin{remark}\n\tIn both theorems the decomposition is unique up to\n\tpermutations of the summands; good to know, but\n\tI won't prove this.\n\\end{remark}\n\n\\section{Reduction to maps of free $R$-modules}\n\\begin{definition}\n\tA \\vocab{free $R$-module} is a module of the form $R^{\\oplus n}$\n\t(or more generally, $\\bigoplus_I R$ for some indexing set $I$,\n\tjust to allow an infinite basis).\n\\end{definition}\nThe proof of the structure theorem proceeds in two main steps.\nFirst, we reduce the problem to a \\emph{linear algebra} problem\ninvolving free $R$-modules $R^{\\oplus d}$.\nOnce that's done, we just have to play with matrices;\nthis is done in the next section.\n\nSuppose $M$ is finitely generated by $d$ elements.\nThen there is a surjective map of $R$-modules\n\\[ R^{\\oplus d} \\surjto M \\]\nwhose image on the basis of $R^{\\oplus d}$ are the generators of $M$.\nLet $K$ denote the kernel.\n\nWe claim that $K$ is finitely generated as well.\nTo this end we prove that\n\\begin{lemma}[Direct sum of Noetherian modules is Noetherian]\n\tLet $M$ and $N$ be two Noetherian $R$-modules.\n\tThen the direct sum $M \\oplus N$ is also a Noetherian $R$-module.\n\\end{lemma}\n\\begin{proof}\n\tIt suffices to show that if $L \\subseteq M \\oplus N$,\n\tthen $L$ is finitely generated.\n\tOne guess is that $L = P \\oplus Q$,\n\twhere $P$ and $Q$ are the projections of $L$ onto $M$ and $N$.\n\tUnfortunately this is false\n\t(take $M = N = \\ZZ$ and $L = \\{(n,n) \\mid n \\in \\ZZ\\}$)\n\tso we will have to be more careful.\n\n\tConsider the submodules\n\t\\begin{align*}\n\t\tA &= \\left\\{ x \\in M \\mid (x,0) \\in L \\right\\} \\subseteq M \\\\\n\t\tB &= \\left\\{ y \\in N \\mid \\exists x \\in M : (x,y) \\in L \\right\\}\n\t\t\t\\subseteq N.\n\t\\end{align*}\n\t(Note the asymmetry for $A$ and $B$: the proof doesn't work otherwise.)\n\tThen $A$ is finitely generated by $a_1$, \\dots, $a_k$,\n\tand $B$ is finitely generated by $b_1$, \\dots, $b_\\ell$.\n\tLet $x_i = (a_i, 0)$ and let $y_i = (\\ast, b_i)$ be elements of $L$\n\t(where the $\\ast$'s are arbitrary things we don't care about).\n\tThen $x_i$ and $y_i$ together generate $L$.\n\\end{proof}\n\\begin{ques}\n\tDeduce that for $R$ a PID, $R^{\\oplus d}$ is Noetherian.\n\\end{ques}\nHence $K \\subseteq R^{\\oplus d}$ is finitely generated as claimed.\nSo we can find another surjective map $R^{\\oplus f} \\surjto K$.\nConsequently, we have a composition\n\\begin{diagram}\n\t&& K && && \\\\\n\tR^{\\oplus f} & \\ruSurj(2,1) & \\rTo_T & \\rdInj(2,1)\n\t\t& R^{\\oplus d} & \\rSurj & M\n\\end{diagram}\nObserve that $M$ is the \\emph{cokernel} of the linear map $T$,\ni.e.\\ we have that\n\\[ M \\cong R^{\\oplus d} / \\img(T). \\]\nSo it suffices to understand the map $T$ well.\n\n\\section{Smith normal form}\nThe idea is now that we have reduced our problem to studying\nlinear maps $T : R^{\\oplus m} \\to R^{\\oplus n}$,\nwhich can be thought of as a generic matrix\n\\[ T = \\begin{bmatrix}\n\t\ta_{11} & \\dots & a_{1m} \\\\\n\t\t\\vdots & \\ddots & \\vdots \\\\\n\t\ta_{n1} & \\dots & a_{nm}\n\t\\end{bmatrix} \\]\nfor a basis $e_1$, \\dots, $e_m$ of $R^{\\oplus m}$\nand $f_1$, \\dots, $f_n$ of $N$.\n\nOf course, as you might expect it ought to be possible to change the\ngiven basis of $T$ such that $T$ has a nicer matrix form.\nWe already saw this in \\emph{Jordan form},\nwhere we had a map $T : V \\to V$ and changed the basis\nso that $T$ was ``almost diagonal''.\nThis time, we have \\emph{two} sets of bases we can change,\nso we would hope to get a diagonal basis, or even better.\n\nBefore proceeding let's think about how we might edit the matrix:\nwhat operations are permitted?  Here are some examples:\n\\begin{itemize}\n\t\\ii Swapping rows and columns, which just corresponds\n\tto re-ordering the basis.\n\t\\ii Adding a multiple of a column to another column.\n\tFor example, if we add $3$ times the first column to the second column,\n\tthis is equivalent to replacing the basis \n\t\\[ (e_1, e_2, e_3, \\dots, e_m) \\mapsto (e_1, e_2+3e_1, e_3, \\dots, e_m). \\]\n\t\\ii Adding a multiple of a row to another row.\n\tOne can see that adding $3$ times the first row to the second row\n\tis equivalent to replacing the basis \n\t\\[ (f_1, f_2, f_3, \\dots, f_n) \\mapsto (f_1-3f_2, f_2, f_3, \\dots, f_n). \\]\n\\end{itemize}\nMore generally,\n\\begin{moral}\n\tIf $A$ is an invertible $n \\times n$ matrix we can\n\treplace $T$ with $AT$.\n\\end{moral}\nThis corresponds to replacing \n\\[ (f_1, \\dots, f_n) \\mapsto (A(f_1), \\dots, A(f_n)) \\]\n(the ``invertible'' condition just guarantees the latter is a basis).\nOf course similarly we can replace $X$ with $XB$\nwhere $B$ is an invertible $m \\times m$ matrix;\nthis corresponds to \n\\[ (e_1, \\dots, e_m) \\mapsto (B\\inv(e_1), \\dots, B\\inv(e_m)) \\]\nArmed with this knowledge, we can now approach:\n\\begin{theorem}\n\t[Smith normal form]\n\tLet $R$ be a PID.\n\tLet $M = R^{\\oplus m}$ and $N = R^{\\oplus n}$ be free $R$-modules\n\tand let $T \\colon M \\to N$ be a linear map.\n\tSet $k = \\min\\{m,n\\}$.\n\n\tThen we can select a pair of new bases for $M$ and $N$ such that\n\t$T$ has only diagonal entries $s_1$, $s_2$, \\dots, $s_k$\n\tand $s_1 \\mid s_2 \\mid \\dots \\mid s_k$.\n\\end{theorem}\nSo if $m > n$, the matrix should take the form\n\\[\n\t\\begin{bmatrix} \n\t\ts_1 & 0 & 0 & 0 & \\dots & 0 \\\\\n\t\t0 & s_2 & 0 & 0 & \\dots & 0 \\\\\n\t\t\\vdots & \\vdots & \\ddots & \\vdots & \\dots & \\vdots \\\\\n\t\t0 & 0 & 0 & s_n & \\dots & 0\n\t\\end{bmatrix}.\n\\]\nand similarly when $m \\le n$.\n\\begin{ques}\n\tShow that Smith normal form implies the structure theorem.\n\\end{ques}\n\n\\begin{remark}\n\tNote that this is not a generalization of Jordan form.\n\t\\begin{itemize}\n\t\t\\ii In Jordan form we consider maps $T : V \\to V$;\n\t\tnote that the source and target space are the \\emph{same},\n\t\tand we are considering one basis for the space $V$.\n\t\t\\ii In Smith form the maps $T : M \\to N$ are between\n\t\t\\emph{different} modules, and we pick \\emph{two} sets of bases\n\t\t(one for $M$ and one for $N$).\n\t\\end{itemize}\n\\end{remark}\n\n\\begin{example}\n\t[Example of Smith normal form]\n\tTo give a flavor of the idea of the proof,\n\tlet's work through a concrete example with the $\\ZZ$-matrix\n\t\\[ \\begin{bmatrix}\n\t\t\t18 & 38 & 48 \\\\\n\t\t\t14 & 30 & 32\n\t\t\\end{bmatrix}.  \\]\n\tThe GCD of all the entries is $2$, and so motivated by this,\n\twe perform the \\textbf{Euclidean algorithm on the left column}:\n\tsubtract the second row from the first row,\n\tthen three times the first row from the second:\n\t\\[ \n\t\t\\begin{bmatrix}\n\t\t\t18 & 38 & 48 \\\\\n\t\t\t14 & 30 & 32\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix}\n\t\t\t4 & 8 & 10 \\\\\n\t\t\t14 & 30 & 32\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix}\n\t\t\t4 & 8 & 10 \\\\\n\t\t\t2 & 6 & 2\n\t\t\\end{bmatrix}.\n\t\\]\n\tNow that the GCD of $2$ is present, we move it to the upper-left\n\tby switching the two rows,\n\tand then kill off all the entries in the same row/column;\n\tsince $2$ was the GCD all along, we isolate $2$ completely:\n\t\\[\n\t\t\\begin{bmatrix}\n\t\t\t4 & 8 & 10 \\\\\n\t\t\t2 & 6 & 2\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix}\n\t\t\t2 & 6 & 2 \\\\\n\t\t\t4 & 8 & 10\n\t\t\\end{bmatrix}\n\t\t\\mapsto \n\t\t\\begin{bmatrix} \n\t\t\t2 & 6 & 2 \\\\\n\t\t\t0 & -4 & 6 \\\\\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix}\n\t\t\t2 & 0 & 0 \\\\\n\t\t\t0 & -4 & 6\n\t\t\\end{bmatrix}.\n\t\\]\n\tThis reduces the problem to a $1 \\times 2$ matrix.\n\tSo we just apply the Euclidean algorithm again there:\n\t\\[\n\t\t\\begin{bmatrix} \n\t\t\t2 & 0 & 0 \\\\\n\t\t\t0 & -4 & 6\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix} \n\t\t\t2 & 0 & 0 \\\\\n\t\t\t0 & -4 & 2\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix} \n\t\t\t2 & 0 & 0 \\\\\n\t\t\t0 & 0 & 2\n\t\t\\end{bmatrix}\n\t\t\\mapsto\n\t\t\\begin{bmatrix}\n\t\t\t2 & 0 & 0 \\\\\n\t\t\t0 & 2 & 0\n\t\t\\end{bmatrix}.\n\t\\]\n\\end{example}\n\nNow all we have to do is generalize this proof to work\nwith any PID. It's intuitively clear how to do this:\nthe PID condition more or less lets you perform a Euclidean algorithm.\n\n\\begin{proof}\n\t[Proof of Smith normal form]\n\tBegin with a generic matrix\n\t\\[ T = \\begin{bmatrix}\n\t\ta_{11} & \\dots & a_{1m} \\\\\n\t\t\\vdots & \\ddots & \\vdots \\\\\n\t\ta_{n1} & \\dots & a_{nm}\n\t\\end{bmatrix} \\]\n\tWe want to show, by a series of operations (gradually changing the given basis)\n\tthat we can rearrange the matrix into Smith normal form.\n\n\tDefine $\\gcd(x,y)$ to be any generator of the principal ideal $(x,y)$.\n\t\\begin{claim}[``Euclidean algorithm'']\n\t\tIf $a$ and $b$ are entries in the same row or column,\n\t\twe can change bases to replace $a$ with $\\gcd(a,b)$\n\t\tand $b$ with something else.\n\t\\end{claim}\n\t\\begin{subproof}\n\t\tWe do just the case of columns.\n\t\tBy hypothesis, $\\gcd(a,b) = xa+yb$ for some $x,y \\in R$.\n\t\tWe must have $(x,y) = (1)$ now (we're in a UFD).\n\t\tSo there are $u$ and $v$ such that $xu + yv = 1$.\n\t\tThen\n\t\t\\[\n\t\t\t\\begin{bmatrix} x & y \\\\ -v & u \\end{bmatrix}\n\t\t\t\\begin{bmatrix} a \\\\ b  \\end{bmatrix}\n\t\t\t= \\begin{bmatrix} \\gcd(a,b) \\\\ \\text{something} \\end{bmatrix}\n\t\t\\]\n\t\tand the first matrix is invertible (check this!), as desired.\n\t\\end{subproof}\n\tLet $s_1 = (a_{ij})_{i,j}$ be the GCD of all entries.\n\tNow by repeatedly applying this algorithm,\n\twe can cause $s$ to appear in the upper left hand corner.\n\tThen, we use it to kill off all the entries in the first\n\trow and the first column, thus arriving at a matrix\n\t\\[ \\begin{bmatrix}\n\t\ts_1 & 0 & 0 & \\dots & 0 \\\\\n\t\t0 & a_{22}' & a_{23}' & \\dots & a_{2n}' \\\\\n\t\t0 & a_{32}' & a_{33}' & \\dots & a_{3n}' \\\\\n\t\t\\vdots&\\vdots&\\vdots&\\ddots&\\vdots \\\\\n\t\t0 & a_{m2}' & a_{m3}' & \\dots & a_{mn}' \\\\\n\t\\end{bmatrix}. \\]\n\tNow we repeat the same procedure with this lower-right\n\t$(m-1) \\times (n-1)$ matrix, and so on.\n\tThis gives the Smith normal form.\n\\end{proof}\n\nWith the Smith normal form, we have in the original situation that\n\\[ M \\cong R^{\\oplus d} / \\img T \\]\nand applying the theorem to $T$ completes the proof of the structure theorem.\n\n\\section\\problemhead\nNow, we can apply our structure theorem!\n\\begin{dproblem}\n\t[Finite-dimensional vector spaces are all isomorphic]\n\tA vector space $V$ over a field $k$ has a finite spanning set of vectors.\n\tShow that $V \\cong k^{\\oplus n}$ for some $n$.\n\t\\begin{hint}\n\t\tIn the structure theorem, $k / (s_i) \\in \\{0,k\\}$.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{dproblem}\n\t[Frobenius normal form]\n\tLet $T : V \\to V$ where $V$ is a finite-dimensional vector space\n\tover an arbitrary field $k$ (not necessarily algebraically closed).\n\tShow that one can write $T$ as a block-diagonal matrix whose blocks\n\tare all of the form\n\t\\[ \n\t\t\\begin{bmatrix}\n\t\t\t0 & 0 & 0 & \\dots & 0 & \\ast  \\\\\n\t\t\t1 & 0 & 0 & \\dots & 0 & \\ast  \\\\\n\t\t\t0 & 1 & 0 & \\dots & 0 & \\ast  \\\\\n\t\t\t\\vdots&\\vdots&\\vdots&\\ddots&\\vdots&\\vdots \\\\\n\t\t\t0 & 0 & 0 & \\dots & 1 & \\ast  \\\\\n\t\t\\end{bmatrix}.\n\t\\]\n\t(View $V$ as a $k[x]$-module with action $x \\cdot v = T(v)$.)\n\t\\begin{hint}\n\t\tBy theorem $V \\cong \\bigoplus_i k[x] / (s_i)$ for some polynomials $s_i$.\n\t\tWrite each block in the form described.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{dproblem}\n\t[Jordan normal form]\n\tLet $T : V \\to V$ where $V$ is a finite-dimensional vector space\n\tover an arbitrary field $k$ which is algebraically closed.\n\tProve that $T$ can be written in Jordan form.\n\t\\begin{hint}\n\t\tCopy the previous proof, except using the other form of the structure theorem.\n\t\tSince $k[x]$ is algebraically closed each $p_i$ is a linear factor.\n\t\\end{hint}\n\\end{dproblem}\n\n\\begin{problem}\n\t\\gim\n\tFind two abelian groups $G$ and $H$ which are not isomorphic,\n\tbut for which there are injective homomorphisms\n\t$G \\injto H$ and $H \\injto G$.\n\t\\begin{hint}\n\t\tThe structure theorem is an anti-result here:\n\t\tit more or less implies that finitely generated abelian groups won't work.\n\t\tSo, look for an infinitely generated example.\n\t\\end{hint}\n\t\\begin{soln}\n\t\tTake $G = \\Zc3 \\oplus \\Zc9 \\oplus \\Zc9 \\oplus \\Zc9 \\oplus \\dots$\n\t\tand $H = \\Zc9 \\oplus \\Zc9 \\oplus \\Zc9 \\oplus \\Zc9 \\oplus \\dots$.\n\t\tThen there are maps $G \\injto H$ and $H \\injto G$,\n\t\tbut the groups are not isomorphic since e.g.\\\n\t\t$G$ has an element $g \\in G$ of order $3$\n\t\tfor which there's no $g' \\in G$ with $g = 3g'$.\n\t\\end{soln}\n\\end{problem}\n", "meta": {"hexsha": "fa343074a3468064da12ed6cf66b9c74157cec38", "size": 18203, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/H113/structure.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/H113/structure.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/H113/structure.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.345631068, "max_line_length": 86, "alphanum_fraction": 0.6731308026, "num_tokens": 6319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587586, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.6024344030986659}}
{"text": "\\section[Nonlinear Boson Diffusion Equation]{Thermalization via a Nonlinear Boson Diffusion Equation}\nThe second part of our discussion of the thermalization process of gluons in relativistic heavy-ion collisions is based on a Nonlinear Boson Diffusion equation (NBDE) derived from the Boltzmann equation using a gradient expansion of the respective collision integral.\n\\subsection{Derivation of the NBDE}\nOur central assumptions are spatial homogeneity of the boson distribution function $f(\\mathbf{x},\\mathbf{p},t)$ and spherical symmetry in the momentum dependence. These assumptions allow us to simplify the kinetic equations by performing the angular integration. We arrive at the following expression for the single-particle occupation numbers $n_j=n(\\varepsilon_j,t)$ in a finite Bose system:\n\\begin{equation}\n\\begin{aligned}\n\\frac{\\partial n_1}{\\partial t} &= \\sum_{\\varepsilon_2,\\varepsilon_3,\\varepsilon_4}\\langle V^{2}\\rangle \\cdot G(\\varepsilon_1+\\varepsilon_2,\\varepsilon_3+\\varepsilon_4)\\\\\n&\\times \\left[(1+n_1)(1+n_2)n_3n_4 - (1+n_3)(1+n_4)n_1n_2\\right]\n\\end{aligned}\n\\end{equation}\nHere $\\langle V^{2}\\rangle$ is the second moment of the interaction potential and the function $G$ encodes energy conservation\\footnote{For an infinite system this is simply a delta function $G(\\varepsilon_1+\\varepsilon_2,\\varepsilon_3+\\varepsilon_4)\\rightarrow \\pi\\cdot\\delta(\\varepsilon_1 + \\varepsilon_2 -\\varepsilon_3 - \\varepsilon_4)$ but in a finite system, as we want to have a look at here, the function may acquire a width due to off-shell scatterings between single-particle states which lie apart in the space of possible energies.}. The different indices $1$ to $4$ indicate the respective particles in the elastic $2\\rightarrow 2$ scattering process.\\\\\n\\noindent \nThe collision term on the right hand side can be rewritten in the form of a Master equation (cf. Talha's talk):\n\\begin{equation}\n\\frac{\\partial n_1}{\\partial t} = (1+n_1)\\sum_{\\varepsilon_4}W_{4\\rightarrow 1}n_4\t- \\sum_{\\varepsilon_4}W_{1\\rightarrow 4}(1+n_4),\t\n\\end{equation}\nwith the transition probability\n\\begin{equation}\nW_{4\\rightarrow 1}=  W_{41}g_1 = \\sum_{\\varepsilon_2, \\varepsilon_3} \\langle V^{\\phantom{.}2}\\rangle G(\\varepsilon_1+\\varepsilon_2,\\varepsilon_3+\\varepsilon_4)(1+n_2)n_3\n\\end{equation}\nand $W_{1\\rightarrow 4}$ analogously. Here we already introduced the density of states $g_j\\equiv g(\\varepsilon_j)$ which occur when taking the continuum limit. This also leads us to a replacement of the summations by integrations. Since bosons are interchangeable, $W_{14}=W_{41}$ and \n\\begin{equation}\n\t\tW_{14}=W_{41}=W\\left[\\frac{1}{2}(\\varepsilon_4+\\varepsilon_1),\\underbrace{\\abs{\\varepsilon_4-\\varepsilon_1}}_{=: x}\\right]\n\t\\end{equation}\nfor the case of a finite system where $G$ acquires a width (cf. footnote on the last page). This means that that the transition probabilities depend only on the absolute energy difference $x$ and they are peaked around $x\\simeq 0$.\\\\\n\\noindent\nPerforming a gradient expansion of $n_4$ and $g_4n_4$ around $x\\simeq 0$ and introducing the transport coefficients\n\\begin{align}\n\tD(\\varepsilon,t) = \\frac{g_1}{2}\\int\\limits_0^{\\infty}\\dd x\\ W(\\varepsilon_1,x) \\ x^2\n\\end{align}\nand \n\\begin{equation}\n\t\tv(\\varepsilon,t) = g_1^{-1}\\frac{d}{d\\varepsilon_1}(g_1D) \n\\end{equation}\nvia moments of the transition probability we arrive at a nonlinear partial differential equation for the number density:\n\\begin{equation}\n\t\t\t\\frac{\\partial n}{\\partial t} = -\\frac{\\partial}{\\partial\\varepsilon}\\left[v\\cdot n(1+n) + n\\frac{\\partial n}{\\partial\\varepsilon}\\right] + \\frac{\\partial^2}{\\partial\\varepsilon^2}\\left[Dn\\right]\\label{eqn:nbde1}.\n\\end{equation}\nHere $D(\\varepsilon,t)$ is referred to as diffusion term and $v(\\varepsilon,t)$ as drift term taking dissipative effects into account. Their explicit values are important since they define the equilibrium temperature $T$ via the relation\n\\begin{equation}\n\tT = -\\frac{D}{v}.\n\\end{equation}\nThe minus sign is explained by the fact that the drift is always towards the infrared i.\\,e. the low-energy regime.\\\\\n For our case of relativistic heavy-ion collisions it is well motivated to assume constant transport coefficients which allows us to simplify our equation to\n\\begin{equation}\n\t\t\t\\frac{\\partial n}{\\partial t} = -v\\frac{\\partial}{\\partial\\varepsilon}\\left[n(1+n)\\right] + D\\frac{\\partial^2 n}{\\partial\\varepsilon^2}\\label{eqn:nbde2},\n\t\t\\end{equation}\nwith the well-known Bose-Einstein distribution\t\t\n\\begin{equation}\n\tn_{\\mathrm{eq}}(\\varepsilon) = \\frac{1}{\\exp(\\frac{\\varepsilon-\\mu}{T}) - 1}\n\\end{equation}\nas a stationary solution.\\\\\nAt this point we need to discuss some general features of this model. It does not resolve the second order phase transition to the condensate discussed earlier explicitly but nevertheless the kinetics of Bose condensation before and after the transition are taken into account. After some time $t$ a certain fraction of bosons is pushed into the condensate which is a feature that may not be realized in nature. Of course it is based on particle-number conserving elastic scattering which may not provide the dominant contribution to the thermalization process as emphasized before. Another interesting feature of this certain model is that the particle number is only conserved when the integration is performed over the whole $x$-range opposed to the Boltzmann equation with energy-conserving delta function. We will see this in a moment when we analyze some plots of the solutions of the NBDE for different integration ranges. \\\\\nTo get a first analytical solution of the NBDE in the form of eqn. (\\ref{eqn:nbde2}) we first want to study a linear approximation, the so-called linear relaxation ansatz (RTA).\n\\subsection{Linear Relaxation Ansatz}\nFor a given initial distribution $n_{\\mathrm{t}}(\\varepsilon)$  the linear relaxation-time ansatz reads \n\\begin{equation}\n\t\\frac{\\partial n_{\\mathrm{rel}}}{\\partial t} = \\frac{(n_{\\mathrm{eq}} - n_{\\mathrm{\nrel}})}{\\tau_{\\mathrm{eq}}},\n\\end{equation}\nwhere we introduced the equilibration time $\\tau_{\\mathrm{eq}} = 4D/(9v^2)$ again as a certain ratio of the transport coefficients. General solutions to this simplified model are of the form of\n\\begin{equation}\n\tn_{\\mathrm{rel}}(\\varepsilon,t) = n_{\\mathrm{i}}(\\varepsilon)\\cdot\\exp\\left(-\\frac{t}{\\tau_{\\mathrm{eq}}}\\right) +  n_{\\mathrm{eq}}(\\varepsilon)\\left(1-\\exp\\left(-\\frac{t}{\\tau_{\\mathrm{eq}}}\\right)\\right).\n\\end{equation}\nFollowing ref. \\cite{Mueller1999} we may use an initial distribution of the subsequent form in order to concentrate on a suitable distribution in the context of heavy-ion collisions, i.\\,e.\n\\begin{equation}\n\tn_{\\mathrm{i}}(\\varepsilon) = N_{\\mathrm{i}}\\cdot\\theta\\left(1-\\varepsilon/Q_{\\mathrm{s}}\\right)\\cdot\\theta(\\varepsilon) \\label{eqn:rta_initial}.\n\\end{equation}\nHere we find again the dependency on the saturation $Q_{\\mathrm{s}}\\simeq 1$ GeV as upper limit of the box-shaped initial gluon distribution.\\\\\nThe results for the thermalization process from the NBDE following from the RTA are displayed in figure \\ref{fig:rta1} at the beginning of the next page. We observe that the thermal equilibrium is reached fast after a time of approximately $t\\simeq 2\\tau_{\\mathrm{eq}}$ approaching the Bose-Einstein limit from above in the IR and from below in the UV. At the boundary $p\\simeq Q_{\\mathrm{s}}$ we encounter unphysical discontinuities. Note that here the total gluon number is set to $N_{\\mathrm{i}}=1$ to facilitate the comparison with the exact analytical solutions later on. Additionally we observe that we we are again dealing with an overoccupied system since \n\\begin{equation}\n\tN_{\\mathrm{i}} = (4/3)\\pi\\cdot V\\cdot Q_{\\mathrm{s}}^3\\cdot n_{\\mathrm{i}}\\quad >\\quad N_{\\mathrm{eq}} = 4\\pi\\cdot V \\int_0^{\\infty} n_{\\mathrm{eq}}\\cdot\\varepsilon^2\\ \\dd\\varepsilon\n\\end{equation}\nIf we would assume overall particle number conservation we would come again to the conclusion that the excess particles are driven into a condensate such that not only the gluon number in the thermal spectrum but rather the sum of the thermal gluons and the ones in the condensate is conserved.\n\n\n\\begin{figure}[t]\n\\centering\n\\includegraphics[width = 0.7\\textwidth]{figures/rta}\n\\caption{Linear relaxation of a finite Bose system towards the equilibrium \\cite{Wolschin2018}. \\\\ Here $T = -D/v \\simeq 0.4\\ \\mathrm{GeV}$, $\\tau_{\\mathrm{eq}} = 4D/(9v^2) = 0.33\\cdot 10^{-23} \\mathrm{s} \\simeq 1\\ \\mathrm{fm/c}$ and the timesteps are $\\left\\{0.1, 0.25, 0.5,\\infty\\right\\}$ (in units of $10^{-23}s$) from top to bottom.} \n\\label{fig:rta1}\n\\end{figure}\n\n\n\\subsection{Exact solution of the NBDE}\nTo be able to find a solution to the full NBDE we perform the nonlinear transformation\\footnote{Another possible solution is given by Burger's equation $\\frac{\\partial w}{\\partial t} + w\\frac{\\partial w}{\\partial\\varepsilon} = D\\frac{\\partial^2 w}{\\partial\\varepsilon^2}$ following from the linear transformation $n(\\varepsilon,t) = \\frac{1}{2v}w(\\varepsilon,t) - \\frac{1}{2}$ but we will not discuss the details of this approach here.} \n\\begin{equation}\n\t\tn(\\varepsilon,t) = -\\frac{D}{v}\\frac{\\partial \\ln \\mathcal{Z}(\\varepsilon,t)}{\\partial\\varepsilon}\n\\end{equation}\nwith the usual partition sum $ \\mathcal{Z}(\\varepsilon,t)$ reducing our problem to a linear diffusion equation for the partial sum, i.\\,e.\n\\begin{equation}\n\t\t\\frac{\\partial  \\mathcal{Z}}{\\partial t} = -v\\frac{\\partial  \\mathcal{Z}}{\\partial \\varepsilon} +  D\\frac{\\partial^2  \\mathcal{Z}}{\\partial \\varepsilon^2}.\n\t\\end{equation}\nGeneral solutions of the NBDE are then of the form \t\n\\begin{equation}\nn(\\varepsilon, t)=\\frac{1}{2 v} \\frac{\\int_{-\\infty}^{+\\infty} \\frac{\\varepsilon-x}{t} F(x)\\cdot G_{\\mathrm{free}}(\\varepsilon-x,t)\\ \\dd x}{\\int_{-\\infty}^{+\\infty} F(x)\\cdot G_{\\mathrm{free}}(\\varepsilon-x,t)\\ \\dd x}-\\frac{1}{2},\n\\end{equation}\nwith the free Green's function, being an usual Gaussian,\n\\begin{align}\n\tG_{\\mathrm{free}}(\\varepsilon-x,t) = \\exp\\left[-\\frac{(\\varepsilon-x)^2}{4Dt}\\right],\n\\end{align}\nand the function $F(x)$ taking the initial conditions into account, i.\\,e.\n\\begin{equation}\n\t    F(x)  = \\exp\\left[-\\frac{1}{2D}(vx+2v\\int_0^x n_{\\mathrm{i}}(y) \\dd y) \\right].\n\\end{equation}\nThey define the partition sum via the relation\n\\begin{equation}\n\t\\mathcal{Z}(\\varepsilon,t) = a(t)\\cdot\\int_{-\\infty}^{\\infty} G_{\\mathrm{free}}(\\varepsilon,x,t)\\cdot F(x)\\ \\dd x,\n\\end{equation}\nwith some energy-independent scaling factor $a(t)$ which is in our case not important since it drops out due to the $\\operatorname{log}$-derivative. As already mentioned before one may check that the particle number is not conserved for an integration over only the positive $x$-range. With these definitions in mind we are now set to present the results of the NBDE. At this point I should mention that I will not display the full lengthy expressions for the full analytical solution but rather focus on the plots and the implications arising from these different solutions. In case the reader may be interested in the exact expressions I refer to ref. \\cite{Wolschin2018} for the first part and to ref. \\cite{Wolschin2020_1} for the second part.\n\\begin{figure}[H]\n\\begin{subfigure}[c]{0.49\\textwidth}\n\\includegraphics[width=\\textwidth]{figures/nbde_positive_range}\n\\subcaption{Integration range restricted to $x \\geq 0$.\\\\ The timesteps are $\\left\\{0.005, 0.05, 0.15,0.5\\right\\}$ \\\\ (in units of $10^{-23}s$) from top to bottom.}\n\\end{subfigure}\n\\begin{subfigure}[c]{0.49\\textwidth}\n\\includegraphics[width=\\textwidth]{figures/nbde_full_range}\n\\subcaption{Integration range extended to $-\\infty \\leq x \\leq \\infty$. \\\\ The timesteps are $\\left\\{0.005, 0.05, 0.15,0.5\\right\\}$ \\\\ (in units of $10^{-23}s$) from top to bottom.}\n\\end{subfigure}\n\\caption{Equilibration of a finite Bose system from the NBDE for $T\\simeq 0.4\\ \\mathrm{GeV}$ and \\\\ $\\tau_{\\mathrm{eq}} =  0.33\\cdot 10^{-23} \\mathrm{s}$ \\cite{Wolschin2018}.}\n\\label{fig:full_sol_ranges}\n\\end{figure}\n\\noindent\nIn the above figure \\ref{fig:full_sol_ranges} we present the results for the equilibration following from the exact solutions for different integration ranges to highlight the importance of integrating over the whole $x$-range. In the left figure we find the occupation rising above the thermal limit for very short times but due to redistribution into the condensate it depletes and we have $n(0,t)<1 \\ \\forall t >\\tau_{\\mathrm{eq}}$ which encodes the explicit violation of particle number conservation. In the right plot, representing the solution with integration over the whole range, we directly see the redistribution into the condensate in the IR already at early times and find a new thermal tail developed in the UV. We therefore conclude that these solutions do not reproduce the expected features of the Bose-Einstein equilibrium distribution, yet. This can be explained by the fact that we did not yet include  the singularity of the Bose-Einstein distribution at $\\varepsilon=\\mu <0$. We will see how to resolve this problem in the following.\n\n\\subsection{Including the Singularity}\nTo account for the singularity at $\\varepsilon=\\mu <0$ we have to modify the initial distribution (\\ref{eqn:rta_initial}) in the following way:\n\\begin{equation}\n\t\t\\tilde{n_{\\mathrm{i}}}(\\varepsilon) = n_{\\mathrm{i}}(\\varepsilon) + \\frac{1}{\\exp\\left(\\frac{\\varepsilon-\\mu}{T}\\right)-1}.\n\t\\end{equation}\nFor the subsequent analysis we treat the chemical potential $\\mu$ as a fixed parameter and consider the asymptotics of \tour distribution at the singularity\n\\begin{equation}\n\t \\lim_{\\varepsilon\\rightarrow\\mu^{+}}\\ n(\\varepsilon,t) = \\infty\\ \\forall t \n\\end{equation} \nyielding $\\mathcal{Z}(\\mu,t) = 0$. This results in a modified expression for the Green's function \n \t\\begin{equation}\n\t\tG(\\varepsilon,x,t) = G_{\\mathrm{free}}(\\varepsilon-\\mu,x,t) - G_{\\mathrm{free}}(\\varepsilon-\\mu,-x,t).\n\\end{equation}\nThis means that in general our expressions for the partition sum and the function $F$ stay almost the same except in a shift in the respective argument by the chemical potential $\\mu$. The techniques to solve the NBDE with this boundary condition remain the same and we can therefore have a look at the solutions displayed below in figure (\\ref{fig:singularity}).\n\\begin{figure}[H]\n\\begin{subfigure}[c]{0.47\\textwidth}\n\\includegraphics[width=\\textwidth]{figures/rta_full}\n\\subcaption{Local thermalization of gluons in the linear RTA.\nThe timesteps are $\\left\\{0.02, 0.08, 0.15,0.3,0.6\\right\\}$ ($\\mathrm{fm}/c$) for decreasing dash length.}\n\\end{subfigure}\n\\begin{subfigure}[c]{0.495\\textwidth}\n\\includegraphics[width=\\textwidth]{figures/nbde_full_result}\n\\subcaption{Local thermalization of gluons from the time-dependent solutions of the NBDE.\\\\ Here $\\left\\{6\\cdot10^{-5}, 6\\cdot10^{-4}, 6\\cdot10^{-3},0.12,0.36\\right\\}$ ($\\mathrm{fm}/c$) for decreasing dash length.}\n\\end{subfigure}\n\\caption{Results for the full solution of the NBDE including the singularity at $\\varepsilon=\\mu<0$ at $T \\simeq 513\\ \\mathrm{MeV}$ \\cite{Wolschin2020_1}. }\n\\label{fig:singularity}\n\\end{figure}\n\\noindent\nIn the left figure we see again the simplified solution arising from the RTA where we can already observe that the solution entails the correct physical properties of the Bose-Einstein equilibrium distribution in the UV and finally also in the IR except the discontinuities at $p\\simeq Q_{\\mathrm{s}}$. Note that here the thermalization occurs much slower than in the nonlinear case on the right hand side.\\\\\n\\noindent\nThe full nonlinear solution presented in the right figure now appropriately describes the thermalization process of a finite gluon system encoding all expected properties in the UV and also in the IR opposed to the first solutions omitting the important boundary condition at $\\varepsilon=\\mu$. Note that in our concrete example the numerical values of the transport coefficients have been chosen such that they represent the situation of a Pb-Pb collision at the LHC with a center-of-mass energy of $\\sqrt{s}=5$ TeV leading to a thermalization with $T\\simeq 513$ MeV.", "meta": {"hexsha": "480f0cde23e91e263a4bf8cba35616089908aceb", "size": 16059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "summary/content/04_nbde.tex", "max_stars_repo_name": "mathieukaltschmidt/Thermalization-of-Gluons", "max_stars_repo_head_hexsha": "4fa0a9503f82c007fbb196df3e665772b259355e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "summary/content/04_nbde.tex", "max_issues_repo_name": "mathieukaltschmidt/Thermalization-of-Gluons", "max_issues_repo_head_hexsha": "4fa0a9503f82c007fbb196df3e665772b259355e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "summary/content/04_nbde.tex", "max_forks_repo_name": "mathieukaltschmidt/Thermalization-of-Gluons", "max_forks_repo_head_hexsha": "4fa0a9503f82c007fbb196df3e665772b259355e", "max_forks_repo_licenses": ["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.9423076923, "max_line_length": 1055, "alphanum_fraction": 0.7573946074, "num_tokens": 4661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.6992544210587586, "lm_q1q2_score": 0.6024344018556983}}
{"text": "\\section{Economical Bases: Wavelets and REACT estimators }\nIf one consider the ``equally spaced'' Gaussian regression:\n\\begin{equation}\n\\label{lastmodel}\ny_i = f(t_i) + \\varepsilon_i, i=1,\\dots,n\n\\end{equation}\n$t_i = (i-1)/n$ and the $\\varepsilon_i$s IID $N(0,\\sigma^2)$, many things\nsimplify. \n \nWe can write this in matrix notation: the response vector $\\by$ is \n$N_n(\\f,\\sigma^2{\\mathbf I})$ \nwith $\\f=\\{f(t_1),\\dots,f(t_n)\\}'$. \n\nAs usual we want to find an estimation  procedure that minimizes risk:\n\\[\nn^{-1} \\E || \\hat{\\f} - \\f ||^2 = n^{-1} \\E \\left[ \\sum_{i=1}^m \\{\n \\hat{f}(t_i) - f(t_i) \\}^2\\right].\n\\]\n\nWe have seen that the MLE is $\\hat{f}_i = y_i$ which intuitively does\nnot seem very useful. There is actually an  \nimportant result in statistics that makes this more precise. \n\nStein (1956) noticed that the MLE is \ninadmissible: There is an estimation \nprocedure producing estimates with smaller risk that the MLE for any \n$\\f$.\n\nTo develop a non-trivial theory MLE won't do. A popular procedure is\nto specify\nsome fixed class $\\cal F$ of functions where  $f$ lies and seek an\nestimator $\\hat{f}$ attaining minimax risk  \n\\[\n\\inf_{\\hat{f}} \\sup_{f \\in {\\cal F}} R(\\hat{f},f)\n\\]\n\nBy restricting $f \\in \\cal F$ we make assumptions on the smoothness of\n$f$. For example, the $L^2$ Sobolev family makes an assumption \non the number $m$ of continuous derivatives and a limits the size of the\n$m$th derivative.\n\n\n\\subsection{Useful transformations}\nRemember  $\\f \\in {\\mathbb R}^n$ and that there are many\northogonal bases for this space. Any orthogonal basis can be\nrepresented with an \northogonal transform $\\bU$ that gives us the coefficients for any $\\f$\nby multiplying $\\bxx = \\bU' \\f$. This means that we can represent any\nvector as $\\f = \\bU \\bxx$. \n\nRemember that the eigen analysis of smoothing splines we can view the\neigenvectors a such a transformation.\n\nIf we are smart, we can choose a transformation $\\bU$ such that $\\bxx$\nhas some useful interpretation. Furthermore, certain\ntransformation may be more ``economical'' as we will see.\n\nFor {\\bf equally spaced data} a widely used transformation is the \nDiscrete Fourier Transform (DFT).  Fourier's theorem says that any $\\f\n\\in {\\mathbb R}^n$  \ncan be re-written as \n\\[\nf_i = a_0 + \\sum_{k=1}^{n/2 - 1} \\left\\{\n  a_{k} \\cos \\left(\\frac{2\\pi k}{n}  \\, i \\right) \\, \n  + b_{k} \\sin \\left(\\frac{2 \\pi k}{n} \\,i \\right) \\right\\} + a_{n/2}\n  \\cos (\\pi i) \n\\]\nfor $i=1,\\dots,n$. This defines a basis and the coefficients $\\ba = \n(a_0,a_1,b_1,\\dots,\\dots,a_{n/2})'$ can be obtained via $\\ba = \\bU'\n\\f$ with $\\bU$ having columns of sines and cosines:\n\\begin{eqnarray*} \n  U_1 &=& [n^{-1/2}: 1 \\leq i \\leq n] \\\\\n  U_{2k} &=& [(2/n)^{1/2}\\sin\\{2\\pi k i/n\\} : 1 \\leq i \\leq\n  n], k=1,\\dots,n/2 \\\\\n  U_{2k+1} &=& [(2/n)^{1/2}\\cos\\{2\\pi k i/n\\} : 1 \\leq i \\leq\n  n], k=1,\\dots,n/2-1.\n\\end{eqnarray*}\nNote: This can easily be changed to the case where $n$ is odd by\nsubstituting $n/2$ by $\\lfloor n/2 \\rfloor$ and taking out the last\nterm last term $a_{\\lceil n/2 \\rceil}$.\n\nIf a signal is close to a sine wave $f(t) = \\cos(2 \\pi j t / n +\n\\phi)$ for some integer $1\\leq j \\leq n$, only \ntwo of the coefficients in $\\ba$ will be big, namely the ones associated with\nthe columns $2j-1$ and $2j$, the\nrest will be close to 0. \n\nThis makes the basis associated with the DFT very economical (and the\n{\\it periodogram a \ngood detector of hidden periodicities)}. Consider that if we where to\ntransmit the \nsignal, say using modems and a telephone line, it would be more\n``economical'' to send $\\ba$ instead of \nthe $\\f$. Once $\\ba$ is received, $\\f=\\bU\\ba$ is reconstructed. This\nis basically what data compression is all about.\n\nBecause we are dealing with equally spaced data, the coefficients of\nthe DFT are also related to smoothness. Notice that \nthe columns of $U$ are increasing in frequency and thus decreasing in\nsmoothness. This means that a ``smooth'' $\\f$ should have only the\nfirst $\\ba = \\bU'\\f$ \nrelatively different \nfrom 0. \n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-09.ps,angle=270,width=.75\\textwidth}\n\\end{center}\n\\end{figure}\n\nA close relative of the DFT is the \nDiscrete Cosine Transform (DCT).\n\\begin{eqnarray*}\n  U_1 &=& [n^{-1/2}: 1 \\leq i \\leq n] \\\\\n  U_k &=& [(2/n)^{1/2}\\cos\\{\\pi(2i-1)k/(2/n)\\} : 1\\ \\leq i \\leq n],\n  k=2,\\dots,n \n\\end{eqnarray*}\n\n\n\nEconomical bases together with ``shrinkage'' ideas can be used to\nreduce risk and even to obtain estimates with minimax properties. We\nwill see this through an example\n\n\\subsection{An example}\nWe consider body temperature data taken from a mouse every 30 minutes\nfor a day, so we have $n=48$. We believe measurements will have  \nmeasurement error and maybe environmental variability so we use a\nstochastic model  like\n(\\ref{lastmodel}). We expect body temperature to  change \n``smoothly'' through-out the day  so we believe $f(x)$ is\nsmooth. Under this assumption $\\bxx=\\bU'\\f$, with $\\bU$ the DCT,\nshould have only a few coefficients that are ``big''. \n\nBecause the transformation is orthogonal we have that $\\bz = \\bU'\\by$\nis $N(\\bxx,\\sigma^2 {\\mathbf I})$. An idea we learn from Stein (1956)\nis to consider linear shrunken estimates $\\hat{\\bxx} = \\{ \\bw\\bz; \\bw\n\\in [0,1]^n\\}$. Here the product $\\bw \\bz$ is taken component-wise\nlike in S-plus. \n\nWe can then choose the shrinkage coefficients that\nminimize the risk\n\\[\nE || \\hat{\\bxx} - \\bxx||^2 = E || \\bU \\hat{\\bxx}  - \\f||^2.\n\\]\nRemember that $\\bU \\bxx  = \\bU \\bU'\\f = \\f$.\n\nRelatively simple calculations show that  $\\tilde{\\bw} = \\bxx^2/(\\bxx^2\n+ \\sigma^2)$ minimizes the risk over all possible $\\bw \\in {\\mathbb\n  R}^n$.  The MLE obtained, with $\\bw = (1,\\dots,1)'$, minimizes \nthe risk only if $\\tilde{\\bw} =  (1,\\dots,1)'$ which only happens when\nthere is no variance!   \n \n\n\\begin{figure}[htb]\n\\caption{\\label{f6.4.2}Fitted curves obtained when using shrinkage\ncoefficients of the from $\\bw = \n(1,1,\\dots,1,0,\\dots,0)$, with $2m+1$ the number of 1s used.}\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-10.ps,angle=270,width=.75\\textwidth}\n\\end{center}\n\\end{figure}\n\nNotice that $\\tilde{\\bw}$ makes sense because it shrinks\ncoefficients with small signal to noise ratio. By shrinking small\ncoefficients closer to 0 we reduce variance and the bias we add is not\nvery large, thus reducing risk. However, we don't know $\\bxx$ nor\n$\\sigma^2$ so in practice we can't produce $\\tilde{\\bw}$. Here is\nwhere having economical bases are helpful: we construct estimation\nprocedures that shrink more aggressively the coefficients for which we have\na-priori knowledge that they are ``close to 0'' i.e. have small signal\nto noise ratio.  Two examples of such procedure are:\n\nIn Figure \\ref{f6.4.1}, we show for the body temperature data the\nthe fitted curves obtained when using shrinkage\ncoefficients of the from $\\bw = \n(1,1,\\dots,1,0,\\dots,0)$.\n\n\n\\begin{figure}[htb]\n\\caption{\\label{f6.4.2}Estimates obtained with harmonic model and with REACT. We\n  also show the $\\bz$ and how they have been shrunken.}\n\\begin{center}\n  \\epsfig{figure=Plots/plot-06-11.ps,angle=270,width=.75\\textwidth}\n\\end{center}\n\\end{figure}\n\nIf Figure \\ref{f6.4.2} we show the fitted curve obtained with $\\bw =\n(1,1,\\dots,1,0,\\dots,0)$ and using REACT. \nIn the first plot we show the coefficients shrunken to 0\nwith crosses. In the second $\\bz$ plot we show $\\bw \\bz$ with\ncrosses. Notice that only the first few coefficients of the\ntransformation are ``big''. Here are the same pictures for data\nobtained for 6 consecutive weekends.\n\nFinally in Figure \\ref{f6.4.3} we show the two fitted curves and\ncompare them to the average obtained from observing many days of data.\n\n\\begin{figure}[htb]\n\\caption{\\label{f6.4.3} Comparison of two fitted curves to the \naverage obtained from observing many days of data.}\n\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-12.ps,angle=270,width=.75\\textwidth}\n\\end{center}\n\\end{figure}\n\n\n\nNotice that using $\\bw = (1,1,1,1,0,\\dots,0)$ reduces to a parametric\nmodel that assumes $f$ is a sum of 4 cosine functions. \n\nAny smoother with a smoothing matrix $\\bS$ that is a\nprojection, e.g. linear regression, splines, can be consider a special\ncase of what we have described here. \n\nChoosing the transformation $\\bU$ is an important step in these\nprocedure. The theory developed for Wavelets motivate a choice of\n$\\bU$ that is especially good at handling functions $\\f$ that have\n``discontinuities''.  \n\n\\subsection{Wavelets}\nThe following plot show a nuclear magnetic resonance (NMR) signal. \n\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-13.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\n\nThe signal does appear to have some added noise so  we could use \n(\\ref{lastmodel}) to model the process. However,  $f(x)$ appears to\nhave a peak at around $x=500$ making it not very smooth at that point.\n\nSituations like these are where wavelets analyses is especially useful\nfor ``smoothing''. Now a more appropriate word is ``de-noising''.\n\nThe Discrete Wavelet Transform defines an orthogonal basis just like\nthe DFT and DCT. However the columns of DWT are locally smooth. This\nmeans that the coefficients can be interpreted as local smoothness of\nthe signal for different locations. \n\nHere are the columns of the Haar DWT, the simplest wavelet.\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-14.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\n%\\centerline{\\epsfig{figure=plot28.ps,angle=270,width=\\textwidth}}\n\nNotice that these are step function. However, there are ways (they\ninvolve complicated math and no closed forms) to create ``smoother''\nwavelets. The following are the columns of DWT using the Daubechies wavelets\n\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-15.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\n%\\centerline{\\epsfig{figure=plot29.ps,angle=270,width=\\textwidth}}\n\nThe following plot shows the coefficients of the DWT by smoothness\nlevel and by location:\n\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-16.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\n%\\centerline{\\epsfig{figure=plot30.ps,angle=270,width=\\textwidth}}\n\nUsing wavelet with shrinkage seems to perform better at de-noising\nthan smoothing splines and loess as shown by the following figure.\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-17.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\n%\\centerline{\\epsfig{figure=plot31.ps,angle=270,width=\\textwidth}}\n\n\n\n\n\n\n\\begin{figure}[htb]\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-18.ps,angle=270,width=.5\\textwidth}\n\\end{center}\n\\end{figure}\n\nThe last plot is what the wavelet estimate looks like for the temperature data", "meta": {"hexsha": "cf8d5f079757383bcde4f6639bcebc1418676609", "size": 10715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-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-06-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-06-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": 34.788961039, "max_line_length": 80, "alphanum_fraction": 0.7178721419, "num_tokens": 3345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6024343981267952}}
{"text": "% Created 2020-12-26 Sat 19:42\n% Intended LaTeX compiler: pdflatex\n\\documentclass[11pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{graphicx}\n\\usepackage{grffile}\n\\usepackage{longtable}\n\\usepackage{wrapfig}\n\\usepackage{rotating}\n\\usepackage[normalem]{ulem}\n\\usepackage{amsmath}\n\\usepackage{mathbbol}\n\\usepackage{textcomp}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{capt-of}\n\\usepackage{hyperref}\n\\usepackage{bm}\n\\date{\\today}\n\n\\hypersetup{\n pdfauthor={Rui Ying},\n pdftitle={Principal Component Analysis},\n pdfkeywords={PCA},\n pdfsubject={Statistic},\n pdfcreator={Emacs 27.1 (Org mode 9.4.2)}, \n pdflang={English}}\n\\begin{document}\n\n%\\tableofcontents\n\n\\section{Definition of covariance matrix}\n\\indent\n\nSuppose \\textbf{X} is a d-dimensional random vector (with d random variables), and \\bm{$X_1$},\\dots,\\bm{$X_n$} is n independent copies of \\textbf{X}.\n\nWrite $\\bm{X_i} = (X_i^1,\\dots,X_i^d)^T$, the subscript means the $i_{th}$ copy, the superscript means the number of random variable (i.e. scala). %Then we can combine all the $\\bm{X_i}$ together as a new matrix, $\\mathbb{X}$ (n by d).\n\n\\begin{align}\n  \\bm{X} =\n  \\begin{pmatrix}\n    X^1\\\\\n    X^2\\\\\n    \\dots \\\\\n    X^d\n  \\end{pmatrix}\n  %\n  %\\mathbb{X} =\n  %\\begin{pmatrix}\n  %  \\dots & \\bm{X_1}^T & \\dots\\\\\n  %  \\dots & \\bm{X_2}^T & \\dots\\\\\n  %  \\dots & \\bm{X_3}^T & \\dots\n  %\\end{pmatrix}\n\\end{align}\n\nThen we can know the covariance matrix, which means take two different scalas or coordinates (notice the superscript) from a vector and compute their covariance. For convenience, not use bold X again as before.\n\\begin{align}\n  \\Sigma & = cov(X^i,X^j)\\\\\n         & = \\mathbb{E}(XX^T)-\\mathbb{E}(X)\\mathbb{E}(X)^T\\\\\n         & = \\mathbb{E}[(X-\\mathbb{E}(X))(X-\\mathbb{E}(X))^T]\n\\end{align}\nWhen it comes to empirical data, we use average $\\bar{X}$ to replace expectation\\footnote{Here can be a little comfused because in we used subscript before but here we have $X_i$. This is because in theory, $E(X^1)$ is the expectation of random variable $X^1$, but empirically we sampled many times and calculate their average} and use the empirical covariance matrix \\textbf{S} to replace the $\\Sigma$), \n\n\\begin{align}\n  \\mathbb{E}(X) & =\n  \\begin{pmatrix}\n    \\mathbb{E}(X^1)\\\\\n    \\vdots\\\\\n    \\mathbb{E}(X^d)\n  \\end{pmatrix}\n  \\rightarrow\n  \\begin{pmatrix}\n    \\frac{\\sum}{n} X_i^1\\\\\n    \\vdots\\\\\n    \\frac{\\sum}{n} X_i^d\\\\\n  \\end{pmatrix}\\\\  \n  S &= \\frac{1}{n}\\sum (X_iX_i^T) - \\bar{X}\\bar{X}^T \\label{eq6}\n\\end{align}\n\nIn order to eliminate the sum character, we multiply a $\\mathbb{1}$ to replace the average. $\\mathbb{1}=(1,\\dots,1)^T$\n\\begin{align}\n  &\\bar{X} = \\frac{1}{n}\\sum X_i \\;\\;\\;\\;\\;\\;\n  \\mathbb{X} =\n  \\begin{bmatrix}\n    \\vdots&\\vdots&\\vdots\\\\\n    X_1&X_2&X_n\\\\\n    \\vdots&\\vdots&\\vdots\n  \\end{bmatrix}\\\\\n  &\\frac{1}{n}\\mathbb{X}^T\\mathbb{1}=\\frac{1}{n}\\sum X_i = \\bar{X}\n\\end{align}\nAnd we can see that\n\\begin{align}\n  M_i &=\n  \\begin{bmatrix}\n    0&\\vdots & 0& 0\\\\\n    0&X_i &0&0\\\\\n    0&\\vdots&0&0\\\\\n  \\end{bmatrix}\\\\\n  \\mathbb{X}^T \\mathbb{X} &= \\sum_i^n M_iM_i^T = \\sum_i^nX_iX_i^T\\\\\n  \\mathbb{X}^T &= M_1 + M_2 + \\dots + M_n\n\\end{align}\n\nThen in Eq.6 can be transformed into\n\\begin{align}\n  S = & \\frac{1}{n}\\mathbb{X}^T\\mathbb{X} - \\frac{1}{n^2}\\mathbb{X}^T(\\mathbb{1}\\mathbb{1}^T)\\mathbb{X}\\\\\n  = & \\frac{1}{n}\\mathbb{X^T}(I_d - \\frac{1}{n}\\mathbb{1}\\mathbb{1}^T)\\mathbb{X}\\\\\n  = & \\frac{1}{n}\\mathbb{X}^TH\\mathbb{X}\n\\end{align}\n\nSo, obviously matrix $H$ is a prthogonal projector (you can proof by calculate $H^TH$), what's the subspace this projector project a vector to?\n\\begin{align}\n  H & = (I_d - \\frac{1}{n}\\mathbb{1}\\mathbb{1}^T)\\\\\n& = \\begin{bmatrix}\n  1-\\frac{1}{n} & \\cdots & \\frac{1}{n}\\\\\n  \\vdots & \\ddots & \\vdots\\\\\n  \\frac{1}{n} & \\cdots & 1-\\frac{1}{n}  \n\\end{bmatrix} \n\\end{align}\nso for any vector $\\bm{v}$, we have\n\\begin{align}\n  H\\bm{v} & = \\bm{v} - \\frac{1}{n}(\\bm{v}^T\\mathbb{1})\\mathbb{1}\\\\\n    & = \\bm{v} - \\bar{\\bm{v}}\\mathbb{1}\n\\end{align}\nwhich means a vector minus its means by all elements. And it's clear that\n\\begin{align}\n  avg(H\\bm{v}) = 0\n\\end{align}\nmeans $H$ projects vector $\\bm{v}$ to the subspace that has the mean of 0. Or in another words, Hv $\\perp$ span of $\\mathbb{1}$ because $(Hv)^T\\mathbb{1} = 0$.\n\n\\section{Core: $u^T\\Sigma u$}\n\nTake a vector $\\bm{u} \\in \\mathbb{R}^d$ (column vector), then\n\\begin{align}\n  u^T\\Sigma u & = u^T[E(XX^T) - E(X)E(X)^T]u\\\\\n  & = E[(u^TX)(X^Tu)] - E(u^TX)E(X^Tu)\\\\\n  & = E[(u^TX)^2] - [E(u^TX)]^2\\\\\n  & = var(u^TX)\n\\end{align}\n\nThe transition to Eq.22 is because $u^TX = X^T$ = a number.\nSo this is the magic now, the covariance matrix is equal to the variance of $u^TX$. What's is $u^TX$?\n\n$u^TX$ is the the inner product betwen u and X. Look at my handnote,in geometric, it means the length of red line. So with multiple points, the variance means \\emph{the degree of dispersion along the vector u}.\n\n\\begin{figure}[hb!]\n  \\includegraphics[scale=0.3]{handnote.PNG}\n\\end{figure}\n\nTherefore, we need to find the vector $\\bm{u}$ to maxmize our variance, because we reduce the dimension but don't want to lose too much information (image a 3D olive, we cut it and wanna get the cross section with as long and wide as possible).\n\n\\section{Spectral decomposition/Eigendecomposition}\n\\subsection{Variance is eigenvalue}\nSince $\\Sigma$ and S are symmetric, we can decompose it into this form:\n\\begin{align}\n  \\Sigma = PDP^{T} \\; (or PDP^{-1})\n\\end{align}\nWe know that matrix P consists of all eigenvectors of $\\Sigma$, and \n\\begin{align}\n  \\Sigma v_1 = PDP^Tv_1=\\lambda_1v_1\\\\\n  v_1^T\\Sigma v_1 = \\lambda_1v_1^Tv_1=\\lambda_1\n\\end{align}\nTherefore, the variance along eigenvectors(here $v_1$ means the first and largest eigenvector) is simply the eigevalue $\\lambda$.\n\nAssume $\\bar{X}=0$ to ensure $\\bar{X}\\bar{X}^T=0$ and make calculation easier, the Equation \\ref{eq6} becomes\n\\begin{align}\n  S=\\Sigma X_i X_i^T\n\\end{align}\n\n\\subsection{Another way to proof}\n\nSuppose %$\\lambda_i$ are ordered by number (i.e. $\\lambda_1 > \\lambda_2 > \\dots > \\lambda_n$)\n$y_i=P^TX_i$ (which is the projected vector). Then\n\\begin{align}\n  \\bar{y_i} & = \\overline{P^TX_i} = P^T\\bar{X_i} = 0\\\\\n  S^\\prime & = \\frac{1}{n}\\sum y_iy_i^T\\\\\n  &=\\frac{1}{n}\\sum (P^TX_i)(P^TX_i)^T\\\\\n  &=\\frac{1}{n}\\sum (P^TX_iX_i^TP)\\\\\n  &=\\frac{1}{n}\\sum (P^TSP)\n\\end{align}\nAnd because $S=PDP^T$, we have\n\\begin{align}\n  S^\\prime &= P^T(PDP^T)P\\\\\n  & = D\n\\end{align}\nWe know D is a diagonal matrix made up of eigevalue $\\lambda_i$. So $cov(y^i,y^j)=0$ when $i\\neq j$. In other words, $lambda_i = var(P^TX_i)$.\n\n\\subsection{Why eigenvector is best?}\n\\indent\nHere we need to proof why eigenvectors are the ones make variance largest, because there're so many choices.\n\nSuppose $b=P^Tu$ and $u$ is unit vector.\n\\begin{align}\n  u^TSu = b^TDb=\\sum_{j=1}^d \\lambda_j b_j^2 \\leq \\sum_{j=1}^d \\lambda_1 b_j^2 \n\\end{align}\n\n$\\lambda_1$ here still means the largest eigenvalue. So for any vector $u$, we can know that $\\lambda_1$ is the largest variance and the Nth largest eigenvectors are called ($N_{th}$) Principal Components.\n\nIn extrme cases, if $n >> d$(much more data samples than dimension), then the empirical data converge to a consistent estimator (which means perfect). Otherwise, if $d >> n$, the angle between eigenvectors of $\\Sigma$ and S will be very large (which means very bad estimator). And we need sparse PCA (I don't konw this either).\n\n\n\\end{document}", "meta": {"hexsha": "014f5baaaef03f795a66d271edd47499733549ba", "size": 7417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/post/principal-component-analysis/PCA.tex", "max_stars_repo_name": "Leslieying/starter-academic", "max_stars_repo_head_hexsha": "e0df8c1f55442570d72bcd7a80da8258fa6be744", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-26T15:38:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T15:38:57.000Z", "max_issues_repo_path": "content/post/principal-component-analysis/PCA.tex", "max_issues_repo_name": "ruiying-ocean/starter-academic", "max_issues_repo_head_hexsha": "e0df8c1f55442570d72bcd7a80da8258fa6be744", "max_issues_repo_licenses": ["MIT"], "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/post/principal-component-analysis/PCA.tex", "max_forks_repo_name": "ruiying-ocean/starter-academic", "max_forks_repo_head_hexsha": "e0df8c1f55442570d72bcd7a80da8258fa6be744", "max_forks_repo_licenses": ["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.7178217822, "max_line_length": 405, "alphanum_fraction": 0.663206148, "num_tokens": 2774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743168019989179, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6023220109025385}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{url}\n\\usepackage{graphicx}\n\\usepackage{subcaption}\n\\title{Contextual BO experiment}\n\\author{Feng Zhao}\n\n\\begin{document}\n\\maketitle\n\\section{Experiment 1}\nUsing Contextual BO to find the maximal value of $f(x,a)$ for given $x$.\n\\begin{equation}\\label{eq:f}\n    f(x,a) = \\cos(2 x) \\cos(a) + \\sin(x)\n\\end{equation}\nChoosing $x,y \\in [0,6]$.\nIn this experiment, $x$ is treated as task while $a$ is treated\nas action.\n\nOur goal is to provide a surrogate model of $z=g(x)=\\arg\\max_{a} f(x,a)$.\nThe exact solution is non-continuous, which means that it is very hard to estimate $z=g(x)$ at the\nnon-continuous points. Therefore, we need to sample more points in these places.\nBayesian optimization accomplishes this goal,\nwhich can be verified by the histogram of samples $x$.\n\n\\begin{figure}[!ht]\n    \\begin{subfigure}[b]{0.49\\textwidth}\n        \\centering\n        \\includegraphics[width=\\textwidth]{./cbo_1.png}\n        \\caption{Fitting result}\n        \\label{fig:rk_order_compare}\n    \\end{subfigure}~\n    \\begin{subfigure}[b]{0.49\\textwidth}\n      \\centering\n      \\includegraphics[width=\\textwidth]{./cbo_1_hist.png}\n      \\caption{Histogram}\n      \\label{fig:time_equal_verify}\n    \\end{subfigure}\n    \\caption{}\n\\end{figure}\n\n\\section{Experiment 2}\nUsing the same object function but the adopted action should\nsatisfy the constraints.\n\\begin{equation}\n    \\cos(x)  \\cos(a) - \\sin(x) \\sin(a) + 0.5 \\leq 0    \n\\end{equation}\nThe optimal action is not unique in this constraint\nsetting, we plot $f(x,z)$ against $x$ instead.\n\n\\begin{figure}[!ht]\n    \\centering\n    \\includegraphics[width=6cm]{cbo_2.png}\n\\end{figure}\n\\end{document}\n\n\n", "meta": {"hexsha": "40f660b2ea8d9f8ccd71de5a49e56b29d94db1fb", "size": 1688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "experiment_report.tex", "max_stars_repo_name": "zhaofeng-shu33/OCBO", "max_stars_repo_head_hexsha": "a8e132f3ab77da4a6f58c630b27bfe7e37cc0380", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "experiment_report.tex", "max_issues_repo_name": "zhaofeng-shu33/OCBO", "max_issues_repo_head_hexsha": "a8e132f3ab77da4a6f58c630b27bfe7e37cc0380", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "experiment_report.tex", "max_forks_repo_name": "zhaofeng-shu33/OCBO", "max_forks_repo_head_hexsha": "a8e132f3ab77da4a6f58c630b27bfe7e37cc0380", "max_forks_repo_licenses": ["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.1034482759, "max_line_length": 98, "alphanum_fraction": 0.6996445498, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6023220011892274}}
{"text": "\\chapter{Matlab Basics and Programming }\r\nMatlab is a commercial program\\footnote{The homepage is www.mathworks.com.} which provides an integrated environment for ``Matrix Laboratory\". Matlab is one of many softwares used most ubiquitously in areas of mathematics and engineering. Matlab is very compatible with areas of fields which require numerical simulations because the built-in functions and m-files are based on the standard library LIN-PACK and EISPACK\\footnote{One can obtain the source files from www.netlib.org}.\r\n\r\n\\vv The filenames of Matlab files and script files always end in ``.m\". The program is very convenient to use because almost all of the structures are composed of matrices. In addition, the graphic processing is set so that the numerical analysis results are expressed conveniently.\r\n\r\n\\vv One can get explanation regarding Help by typing\r\n\\matlabp\\texttt{\\textbf{help}} \\vn in the Matlab command window, and one can get explanations regarding every available Matlab functions. For information regarding a specific command, type  \\matlabp\\texttt{\\textbf{help command\\_name}} \\vn For instance, \\matlabp\\texttt{\\textbf{help fft}} \\vn gives explanation for \\texttt{\\textbf{fft}} command. To see the explanation in document form with Hypertext structure, use {\\tt doc} instead of {\\tt help}.\r\n\r\n\\vv This chapter deals with basic usage of Matlab and programming. \r\n%For reference, basic Matlab command list is in appendix %\\ref{A-Matlab}.\r\n\r\n\\section{Basic Command}\r\n\\subsection{Matrix}\r\nMatlab has many different types of built-in matrices. For instance, let us try to make a $7 \\times 7$ matrix with random numbers in each entries. \\vv \\texttt{\\textbf{$\\gg$ rand(7)}} \\vn We can also make a random matrix with a different number of columns and rows by, for example, \\matlabp\\texttt{\\textbf{rand(2,5)}} \\vn For more explanations regarding the function rand, use help or doc command. Another specific matrix, Hilbert matrix, is a typical example used in numerical analysis. \\matlabp\\texttt{\\textbf{hilb(5)}} \\matlabp\\texttt{\\textbf{help hilb}} \\vn $5 \\times 5$ magic square can be made with the following command. \\matlabp\\texttt{\\textbf{magic(5)}} \\matlabp\\texttt{\\textbf{help magic}} \\vn Magic square is a square matrix with the summation of the entries in the row, column, and diagonal all equal. This property of magic square will be explored in subsection 1.3 %\\ref{Matlab-ft}\r\n using matrix multiplication. Many types of matrices used in numerical analysis can be made using built-in functions. \\matlabp\\texttt{\\textbf{eye(6)}} \\matlabp\\texttt{\\textbf{zeros(4,7)}} \\matlabp\\texttt{\\textbf{ones(5)}} \\vn Not only limited to these built-in matrices, one can make different matrices in any form. \\matlabp\\texttt{\\textbf{[1 2 3 5 7 9]}} \\matlabp\\texttt{\\textbf{[1, 2, 3; 4, 5, 6; 7, 8, 9]}} \\matlabp\\texttt{\\textbf{[1 2 RET 3 4 RET 5 6]}} \\vn Here {\\tt RET} means one must press the \"return key\". Matlab grammatical system allows for easy usage of block matrices. \\matlabp\\texttt{\\textbf{[eye(2); zeros(2)]}} \\matlabp\\texttt{\\textbf{[eye(2); zeros(3)]}} \\matlabp\\texttt{\\textbf{[eye(2), ones(2,3)]}} \\vn The second example above gives an error. Why is that?\r\n\r\n\\subsection{Variable}\r\nMatlab has built-in variables, such as {\\tt pi}, {\\tt eps}, and {\\tt ans}. \\matlabp\\texttt{\\textbf{pi}} \\matlabp\\texttt{\\textbf{eps}} \\matlabp\\texttt{\\textbf{help eps}} \\vn \\texttt{\\textbf{who}} is a command which tells us which variables are currently being used. In addition, one can see which variables are being used in the Workspace. \\matlabp\\texttt{\\textbf{who}} \\matlabp\\texttt{\\textbf{help who}} \\vn \\texttt{\\textbf{ans}} is a variable which has the value of the last calculated results that was not assigned a variable. \\matlabp\\texttt{\\textbf{magic(6)}} \\matlabp\\texttt{\\textbf{ans}} \\matlabp\\texttt{\\textbf{x = ans}} \\matlabp\\texttt{\\textbf{x = [x, eye(6)]}} \\matlabp\\texttt{\\textbf{x}} \\matlabp\\texttt{\\textbf{who}} \\vn Since a new variable x has been created, x is a variable being used. In order to delete a variable, use the following command. \\matlabp\\texttt{\\textbf{clear x}} \\matlabp\\texttt{\\textbf{x}} \\matlabp\\texttt{\\textbf{who}} \\vn In order to erase all variables, use \\matlabp\\texttt{\\textbf{clear}} \\vn or \\matlabp\\texttt{\\textbf{clear all}} \\vn Use \\texttt{\\textbf{help}} or {\\tt doc} to figure out the difference between the two.\r\n\r\n\\subsection{Functions} \\label{Matlab-ft}\r\nLet us try the following command. \\matlabp\\texttt{\\textbf{a = magic(4)}} \\vn Now let us find the transpose of a \\matlabp\\texttt{\\textbf{a'}} \\vn If {\\tt a} was a complex matrix, then Matlab would calculate the conjugate transpose, not simply a transpose. \r\n\r\n\\vv Let us explore other arithmetic operations. \\matlabp\\texttt{\\textbf{3*a}} \\matlabp\\texttt{\\textbf{-a}} \\matlabp\\texttt{\\textbf{a + (-a)}} \\matlabp\\texttt{\\textbf{b = max(a)}} \\matlabp\\texttt{\\textbf{max(b)}} \\vn Some Matlab functions may have output with more than one values. If one uses \\texttt{\\textbf{max}} on matrix, then the output is maximum of each column and the indices of the row that contains that maximum. For vector case, the maximum value and the index of that value is presented. \\matlabp\\texttt{\\textbf{[m, i] = max(b)}} \\matlabp\\texttt{\\textbf{[m, i] = min(a)}}\r\n\r\n\\vn Let us try matrix multiplication in order to verify the ``magic\" of magic square.  \\matlabp\\texttt{\\textbf{A = magic(5)}}  \\matlabp\\texttt{\\textbf{b = ones(5,1)}}  \\matlabp\\texttt{\\textbf{A*b}}  \\matlabp\\texttt{\\textbf{v = ones(1,5)}}  \\matlabp\\texttt{\\textbf{v*A}}\r\n\r\n\\vv In Matlab, dot in front of an operation means entry-by-entry operation. In matrix multiplication, {\\tt a.*b} is different from usual matrix multiplication in that the multiplication is done entry-by-entry.  \\matlabp\\texttt{\\textbf{b = 2*ones(4)}}  \\matlabp\\texttt{\\textbf{a.*b}}  \\matlabp\\texttt{\\textbf{a*a}}  \\matlabp\\texttt{\\textbf{a\\defh 2}}  \\matlabp\\texttt{\\textbf{a.\\defh 2}} \\vn The followings are many different arithmetic operations related to matrix.  \\matlabp\\texttt{\\textbf{triu(a)}}  \\matlabp\\texttt{\\textbf{tril(a)}}  \\matlabp\\texttt{\\textbf{diag(a)}}  \\matlabp\\texttt{\\textbf{diag(diag(a))}}  \\matlabp\\texttt{\\textbf{c = rand(4,5)}}  \\matlabp\\texttt{\\textbf{size(c)}}  \\matlabp\\texttt{\\textbf{[m,n] = size(c)}}  \\matlabp\\texttt{\\textbf{m}}  \\matlabp\\texttt{\\textbf{d = .5-c}}\r\n\r\n\\vv Typically, Matlab commands are used for scalar, but there are many functions that can be applied for both scalars and matrices.  \\matlabp\\texttt{\\textbf{sin(d)}}  \\matlabp\\texttt{\\textbf{exp(d)}}  \\matlabp\\texttt{\\textbf{log(d)}}  \\matlabp\\texttt{\\textbf{abs(d)}}\r\n\r\n\\vv There are functions which translates decimal valued numbers into integers in Matlab. {\\tt round}, {\\tt fix}, {\\tt ceil}, and {\\tt floor} are some of these. For instance,  \\matlabp\\texttt{\\textbf{f = [-.5 .1 .5]}}  \\matlabp\\texttt{\\textbf{round(f)}}  \\matlabp\\texttt{\\textbf{fix(f)}}  \\matlabp\\texttt{\\textbf{ceil(f)}}  \\matlabp\\texttt{\\textbf{floor(f)}}\r\n\r\n\\subsection{Logic operation}\r\nLet us think of 1 as ``true\", and 0 as ``false\" in this subsection. \\&, $|$, and $\\sim$ are logic operations which mean ``and\", ``or\", and ``not\", respectively. == is a logic operation which means equal.  \\matlabp\\texttt{\\textbf{a = [1 0 1 0]}}  \\matlabp\\texttt{\\textbf{b = [1 1 0 0]}}  \\matlabp\\texttt{\\textbf{a == b}}  \\matlabp\\texttt{\\textbf{a <= b}}  \\matlabp\\texttt{\\textbf{$\\sim$a}}  \\matlabp\\texttt{\\textbf{a \\$ b}}  \\matlabp\\texttt{\\textbf{a \\$ $\\sim$a}}  \\matlabp\\texttt{\\textbf{a $|$ b}}  \\matlabp\\texttt{\\textbf{a $|$ $\\sim$a}} \\vn There is a comand named {\\tt any} that checks whether the matrix has at least one non-zero entry or not. Not only that, there is also a command named {\\tt all} that checks whether all the entries in the matrix are non-zero or not.  \\matlabp\\texttt{\\textbf{a}}  \\matlabp\\texttt{\\textbf{any(a)}}  \\matlabp\\texttt{\\textbf{c = zeros(1,4)}}  \\matlabp\\texttt{\\textbf{d = ones(1,4)}}  \\matlabp\\texttt{\\textbf{any(c)}}  \\matlabp\\texttt{\\textbf{all(a)}}  \\matlabp\\texttt{\\textbf{all(d)}}  \\matlabp\\texttt{\\textbf{e = [a', b', c', d']}}  \\matlabp\\texttt{\\textbf{any(e)}}  \\matlabp\\texttt{\\textbf{all(e)}}  \\matlabp\\texttt{\\textbf{any(all(e))}}\r\n\r\n\\subsection{Colon}\r\nMatlab provides a useful command for producing and dividng a matrix.  \\matlabp\\texttt{\\textbf{x = -2:1}}  \\matlabp\\texttt{\\textbf{length(x)}}  \\matlabp\\texttt{\\textbf{-2:.5:1}}  \\matlabp\\texttt{\\textbf{-2:.2:1}}  \\matlabp\\texttt{\\textbf{a = magic(5)}}  \\matlabp\\texttt{\\textbf{a(2,3)}} \\vn Now let us try using colon to select specific rows and columns of {\\tt a}.  \\matlabp\\texttt{\\textbf{a(2,:)}} \\matlabp\\texttt{\\textbf{a(:,3)}} \\matlabp\\texttt{\\textbf{a(2:4,:)}} \\matlabp\\texttt{\\textbf{a(:,3:5)}} \\matlabp\\texttt{\\textbf{a(2:4,3:5)}} \\matlabp\\texttt{\\textbf{a(1:2:5,:)}} \\vn In addition, one can freely use row or column vectors in a matrix. \\matlabp\\texttt{\\textbf{a(:,[1 2 5])}} \\matlabp\\texttt{\\textbf{a([2 5],[2 4 5])}}\r\n\r\n\\vn And one can use assignment statements using vectors and matrices. \\matlabp\\texttt{\\textbf{b = rand(5)}} \\matlabp\\texttt{\\textbf{b([1 2],:) = a([1 2],:)}} \\matlabp\\texttt{\\textbf{a(:,[1 2]) = b(:,[3 5])}} \\matlabp\\texttt{\\textbf{a(:,[1 5]) = a(:,[5 1])}} \\matlabp\\texttt{\\textbf{a = a(:,5:-1:1)}} \\vn All of these are simple Matlab functions and examples of matrix multiplication. More functions can be found in the appendix \\ref{A-Matlab}.\r\n\r\n\\subsection{Other features}\r\nThe default setting for Matlab is that the decimals are expressed up to 4 decimal digits. Even though the actual calculation is done up to 16 decimal digits, it is rounded and then expressed. The command \\matlabp\\texttt{\\textbf{format long}} \\vn changes so that all 16 decimal digits are displayed. And, \\matlabp\\texttt{\\textbf{format short}} \\vn changes back to the default setting. Of course, one can display scientific constants long or short, however one wishes, by using the following command \\matlabp\\texttt{\\textbf{format short e}} \\matlabp\\texttt{\\textbf{format long e}}\r\n\r\n\\vv It is not necessary to always display all the calculated values on the screen. If one attaches semicolon(;) at the end of the command, then calculation will proceed, but the values will not be displayed, just like the colon in Maple.\r\n\r\n\\vv Sometimes, a lot of time is spent on making matrices in Matlab session, and one might need to use these matrices next time. One can use Matlab command \\matlabp\\texttt{\\textbf{save filename}} \\vn to make a file named \\texttt{\\textbf{filename.mat}} that saves all the variable values made in the current session. If one does not wish to save all the variable values, then one can use \\matlabp\\texttt{\\textbf{save filename x y z}} to save only variable {\\tt x,y,z} in \\texttt{\\textbf{filename.mat}}. These saved variables can be reused next time using the command \\matlabp\\texttt{\\textbf{load filename}}\r\n\r\n\\vv There are times when one must record all the keyboard inputs and results in Matlab session. The following command allows one to record all the process except for graphs. \\matlabp\\texttt{\\textbf{diary filename}} \\vn produces a file named \\texttt{\\textbf{filename}} and starts the record. \\matlabp\\texttt{\\textbf{diary off}} \\vn stops the record, \\matlabp\\texttt{\\textbf{diary on}} \\vn restarts the record. These processes are saved in text files, so one can edit them.\r\n\r\n\\section{Programming in Matlab}\r\nMatlab is a language, with which one is able to program, just like Maple. A person who wants to write the files can easily do so by using .m files toy write a program and execute it. If one wrote {\\tt myfile.m}, one can execute {\\tt myfile.m} by using the command {\\tt myfile}, just like other Matlab commands. Matlab is an interpreter language, so one can execute a written program without compiling.\r\n\r\n\\subsection{Assignment Statement}\r\nAssignment means one can assign a value to a variable. In other words, {\\tt x=a} means that one is assigning the value {\\tt a} to the variable {\\tt x}. Let us see the following simple program which uses assignment statement.\r\n\r\n\\vv\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{9.5cm}{\\tt function r=mymod(a,d)\\\\ \\\\\r\n\\% r=mymod(a,d). If a and d are integers, then \\\\\r\n\\% r is the integer remainder of a after\\\\\r\n\\% division by d. If a and d are integer matrices, \\\\\r\n\\% then r is the matrix of remainders after division \\\\\r\n\\% by corresponding entries. Compare with REM.\\\\ \\\\\r\nr=a-d.*floor(a./d);} \\end{center} }}\\end{center} \\vn Make the above {\\tt mymod.m} file, and assign an integer value to {\\tt a} and {\\tt d}. Then, if one uses\r\n\r\n\\matlabp \\texttt{\\textbf{mymod(a,d)}}\r\n\r\n\\vn it is executed as if it were a built-in Matlab command. Let us enter the following command.\r\n\r\n\\matlabp \\texttt{\\textbf{help mymod}}\r\n\r\n\\vn Then the 5-lined information above that start with \\% will show up. \\% means that the statements that come after it are ignored when a program is executed. When help command is executed in Matlab, the information on the uppermost part of the announced part of the function is displayed. Using this method, the help command provides a help function that let us know the properties of the function quickly. Let us enter the following.\r\n\r\n\\matlabp\\texttt{\\textbf{type mymod}}\r\n\r\n\\vn This command displays the entire details of the file on the screen for convenient reading. Now let us examine the details of {\\tt mymod.m}. The first row corresponds to ``function announcement statement\". In here, name of the file(always the same as the file name without m), input variable(In this case, {\\tt a} and {\\tt d}), and output variable({\\tt r}) are announced. The next is the `help\" aforementioned. Last, the middle part of the program is displayed on the screen. The variable {\\tt r} is assigned the value {\\tt a-d.*floor(a./d)}. Out of the operations on the right hand side, ``.\" means entry-by-entry operation. Last, ``;\" means that until the last part of the execution, the result is blocked from being printed on the screen. Try executing the program after deleting ``;\". A quite different result will be printed.\r\n\r\n\\subsection{Conditional Statement}\r\nConditional statement has the following structure. \\vv\r\n\r\n\\texttt{\\textbf{if <condition>, <program> end}} \\vn \\texttt{\\textbf{<condition>}} above is a MATLAB function, but it is not a must to have values only 0 and 1. In the conditional statement, \\texttt{\\textbf{<program>}} is executed only when \\texttt{\\textbf{<condition>}} has a non-zero value, and proceeds to the next. Let us not forget that {\\tt a==b} and {\\tt a<=b} are functions perceived as having values 0 or 1. Often, conditional statements have the following form. \\vv \\texttt{\\textbf{if <condition1>, <program1> else <program2> end}} \\vn In this case, if {\\tt <condition1>} has the value 0, then {\\tt <program2>} is performed. There is another form \\vv \\texttt{\\textbf{if <condition1>, <program1>}} \\par \\texttt{\\textbf{elseif <condition2>, <program2>}} \\par \\texttt{\\textbf{end}} In this case, if {\\tt <condition1>} is non-zero, then {\\tt <program1>} is performed, if {\\tt <condition1>} is 0 and {\\tt <condition2>} is non-zero, then {\\tt <program2>} is performed. In other cases, the program exits the conditional statement and proceeds to the next. The following is a simple program that uses conditional statement. \\vv\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{9.4cm}{\\tt function b=even(n)\\\\ \\\\\r\n\\% b=even(n). If n is an even integer, then b=1 \\\\\r\n\\% otherwise b=0 \\\\ \\\\\r\nif mymod(n,2) == 0\\\\\r\n\\phantom{ab}b=1; \\\\\r\n\\phantom{ab}else b=0; \\\\\r\nend} \\end{center} }}\\end{center}\r\n\r\n\\subsection{For Loop}\r\nFor loop has the following structure.\r\n\r\n\\vv \\texttt{\\textbf{for i=1:n, <program>, end}} \\vn Depending on the value of {\\tt i}, \\texttt{\\textbf{<program>}} is repeatedly executed each time. Let us introduce some simple program. The first is matrix multiplication. \\vv\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{10.2cm}{\\tt function c=add(a,b)\\\\ \\\\\r\n\\% c=add(a,b). This is the function which adds \\\\\r\n\\% the matrices a and b. It duplicates the MATLAB \\\\\r\n\\% function a+b.\\\\ \\\\\r\n$[$m,n$]$ = size(a);\\\\\r\n$[$k,l$]$ = size(b);\\\\\r\nif m$\\sim$=k $|$ n$\\sim$=l, \\\\\r\n\\phantom{ab}r='ERROR using add: matrices are not the same size',\\\\\r\n\\phantom{ab}return,\\\\\r\nend \\\\\r\nc=zeros(m,n); \\\\\r\nfor i=1:m,\\\\\r\n\\phantom{ab}for j=1:n,\\\\\r\n\\phantom{ab}\\phantom{ab}c(i,j)=a(i,j)+b(i,j);\\\\\r\n\\phantom{ab}end \\\\\r\nend} \\end{center} }}\\end{center}\r\n\r\n\\vn The next is a program related to matrix multiplication. \\vv\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{9.5cm}{\\tt function c=mult(a,b)\\\\ \\\\\r\n\\% c=mult(a,b). This is the matrix product of  \\\\\r\n\\% the matrices a and b. It duplicates the MATLAB  \\\\\r\n\\% function c=a*b.\\\\ \\\\\r\n$[$m,n$]$=size(a);\\\\\r\n$[$k,l$]$=size(b);\\\\\r\nif n$\\sim$=k  \\\\\r\n\\phantom{ab}r='ERROR using mult: matrices are not compatible \\\\\r\n\\phantom{ab}\\phantom{ab}for multiplication',\\\\\r\n\\phantom{ab}return,\\\\\r\nend \\\\\r\nc=zeros(m,l); \\\\\r\nfor i=1:m,\\\\\r\n\\phantom{ab}for j=1:l,\\\\\r\n\\phantom{ab}\\phantom{ab}for p=1:n,\\\\\r\n\\phantom{ab}\\phantom{ab}\\phantom{ab}c(i,j)=c(i,j)+a(i,p)*b(p,j);\\\\\r\n\\phantom{ab}\\phantom{ab}end \\\\\r\n\\phantom{ab}end \\\\\r\nend} \\end{center} }}\\end{center} \\vn  Let us look carefully at the conditional statement after the {\\tt size} statement in both programs. It is there to print error message. In {\\tt add} case, adding matrices with different dimensions results in printing error message, and in {\\tt mult} case, if the dimension of the column of the left matrix and the dimension of the row of the right column do not match, error message prints. If there is an error even when there is no such error messages, then MATLAB will print a strange calculation result. Observe the single quotation marks in the error message part. The sentence indicated by the quotation marks is regarded as text and is displayed as a value of the variable {\\tt r}. After the error message is the return command. This is an instruction statement which tells us to return back to the function or prompt that called {\\tt add} or {\\tt mult}. Return command is very useful in error message statement.\r\n\r\n\\vv {\\tt i} in the next loop statement\r\n\r\n\\vv \\texttt{\\textbf{for i=1:n, <program>, end}} \\vn can be handled in many different ways in the program. There is no problem in writing a vector in place of {\\tt 1:n} in MATLAB. In the case of loop statement\r\n\r\n\\vv \\texttt{\\textbf{for i=[2,4,5,6,10], <program>, end}} \\vn the program will be executed 5 times repeatedly, with i having the values $2,4,5,6,10$ each time. The developers of MATLAB went further. It's possible to use vector, but what about matrix? Thus the loop statement like the following\r\n\r\n\\vv \\texttt{\\textbf{for i=magic(7), <program>, end}} \\vn is also possible. This program will be executed 7 times (the dimension of the column), with the variable {\\tt i} being the column of {\\tt magic(7)} each time.\r\n\r\n\\subsection {While Loop Statement}\r\nWhile loop statement takes the following form\r\n\r\n\\vv \\texttt{\\textbf{while <condition>, <program>, end}}\r\n\r\n\\vn \\texttt{\\textbf{<condition>}} becomes MATLAB function, just like it did in conditional statement. The program keeps executing as long as \\texttt{\\textbf{<condition>}} has non-zero value. However, there is a risk in using while statement because there is no way to forcefully terminate the while statement. Next is a simple program using a while statement. \\vv\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{8.2cm}{\\tt function l=twolog(n) \\\\ \\\\\r\n\\% l=twolog(n). l is the floor of the base 2 \\\\\r\n\\% logarithm of n.  \\\\ \\\\\r\nl=0; \\\\\r\nm=2; \\\\\r\nwhile m<=n\\\\\r\n\\phantom{ab}l=l+1; \\\\\r\n\\phantom{ab}m=2*m; \\\\\r\nend} \\end{center} }}\\end{center}\r\n\r\n\\subsection{Recursion}\r\nRecursion means that the function calls upon itself. Next is a simple example that uses recursion. \\vv\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{10cm}{\\tt function y=twoexp(n) \\\\ \\\\\r\n\\% y=twoexp(n). This is a recursive program for \\\\\r\n\\%\\phantom{ab}\\phantom{ab}computing \\\\\r\n\\% y=2\\defh n. The program halts only if n is a nonnegative \\\\\r\n\\%\\phantom{ab}\\phantom{ab}integer. \\\\ \\\\\r\nif n==0, y=1;\\\\\r\n\\phantom{ab}else y=2*twoexp(n-1); \\\\\r\nend} \\end{center} }}\\end{center} \\vn Many recursive programs consist of conditional statement just like this program. The condition {\\tt n==0} is the basic part of recursion, and it is the only way for the program to restrict itself from calling itself up. The ``else\" part is the part that shows the recursion. Let us take note on how {\\tt twoexp(n-1)} is executed in a program that calculates {\\tt twoexp(n)}. The principle is calling upon smaller number {\\tt n-1}, and continuing this until n=0 is called upon. Successful recursion means continuously calling upon smaller number.\r\n\r\n\\vv However, there are many dangers in using recursion. First, just like while loop statement, the function can continuously call itself up. Second, although it can be stopped, it might calculate unneccesarily, wasting time, and third, while the recursive program is executing, extra memory is required. In massive calculation, the memory storage is crucial, and it must not be unnecessarily wasted. Then, with all these negative sides, why is recursion used? Actually, users who are familiar with using recursive programs can utilize its merits while avoiding these problems. When using recurisve function, one can program easier than when one does not use recursive function.\r\n\r\n\\subsection{Other Variety of Programs}\r\nOne can use matrix-valued functions as conditional statement or conditions of loop statement. In other words, conditions can have matrices such as {\\tt ones(2)}, {\\tt zeros(2)}, or {\\tt eye(2)} in them. If {\\tt <condition> = eye(2)} in the following program, how will this program execute?\\vv\r\n\\texttt{\\textbf{if <condition>, <program1>,}}\r\n\\par \\texttt{\\textbf{else <program2>, end}}\r\n\\vn Here, {\\tt <program1>} is executed when all the entries in {\\tt <condition>} is non-zero. Hence, {\\tt <program1>} is executed if {\\tt <condition>} is {\\tt magic(2)}, and {\\tt <program2>} is executed if {\\tt <condition>} is {\\tt eye(2)}.\r\n\r\n\\vv Now let us predict how the following program will be executed. \\vv\r\n\\texttt{\\textbf{if A $\\sim$= B, <program>, end}} \\vn Here, {\\tt <program>} will only be executed when the entries of {\\tt A} and {\\tt B} are all different. If we wanted to execute {\\tt <program>} even when only one entry of {\\tt A} and {\\tt B} are different, then how can we do this? There are many ways, but first, we can do \\vv \\texttt{\\textbf{if A == B, else $<$program$>$, end}} \\vn With this program, the ``else\" part will be executed when at least one entry of {\\tt A} and {\\tt B} is different. For a different way, we can use {\\tt A==B} as {\\tt all(all(A==B))} to transform it into binary function. The inner {\\tt all} will produce a binary vector with all the entries as 1 if the {\\tt i}-th column of {\\tt A} and the {\\tt i}-th column of {\\tt B} are the same. If all the entries of this vector is 1, then the outer {\\tt all} will produce 1. Therefore, if at least one entry of {\\tt A} and {\\tt B} is different, then {\\tt all(all(A==B))=0}. Therefore, the following program \\vv \\texttt{\\textbf{if $\\sim$all(all(A==B)), <program>, end}} \\vn will be executed as we want.\r\n\r\n\\vv Very similar method is also used in while loop statement.\r\n\\vv \\texttt{\\textbf{while <condition>, <program>, end}} \\vn With this program, when {\\tt <condition>} takes a matrix value, the program is continuously executed if all the entries are non-zero, and the program exits the loop statement if at least one of the entry is 0.\r\n\r\n\\vv The following program uses many conditional statements at the same time. Let us predict how this program is executed.  \\vv \\texttt{\\textbf{if <condition1> \\& <codition2>,}}\r\n\\par \\texttt{\\textbf{<program>, end}} \\vn Of course, the program is executed when both {\\tt <condition1>} and {\\tt <condition2>} are non-zero. But, does this program always work without any problems? In reality, there are times when {\\tt <condition1> = 0} and {\\tt <condition2>} causes an error during the execution of a program.  For instance, this happens in the following program.  \\vv \\texttt{\\textbf{if i $<=$ m \\& A(i,j)==0, <program>, end}} \\vn Here, {\\tt m} is the dimension of the column of {\\tt A}. If {\\tt i>m}, then we would like the program to proceed on. However, the error message will be displayed on the screen because of {\\tt A(i,j)} part. To avoid this, one can change the conditional statement as follows. \\vv \\texttt{\\textbf{if i$<=$m,}}\r\n\\par\r\n \\quad \\texttt{\\textbf{if A(i,j)==0,}} \\par\r\n\\qquad \\texttt{\\textbf{<program>}} \\par \\quad\r\n\\texttt{\\textbf{end}} \\par \\texttt{\\textbf{end}}\r\n\r\n\\subsection{Script}\r\nScript is m-file without function declaration statement and executes differently from m-file defined by function. Let us assume {\\tt x} is one of the variable in use this session. If we write a program using a function(-defined) file, and we use {\\tt x} in the program even if {\\tt x} is not an input variable of the function, then the program does not use the value of {\\tt x} that was defined during the session, but it takes on the value that was locally allocated in the program. Furthermore, the program does not change the value of {\\tt x} in the session. Therefore, during the execution of function file, it is very convenient in that one does not need to take heed of the variable declared in the session, and this is because of the function that was declared. If there is no part about the declaration, then that script is regarded as a continuous part of the session. Hence, if a used variable is changed in the script during the session, then the variable is changed for the entire session.\r\n\r\n\\subsection{Proposal for Better Programming}\r\nPay special attention to the following details when programming with MATLAB. Of course, these details can be applied with not only Matlab, but also for programming in Maple as well.\r\n\r\n\\begin{enumerate}\r\n\\item Just like the examples until now, it is recommended to use indent while programming. This way, it is easier to read, easier to find  grammatical errors, and easier to think of programming in group.\r\n\r\n\\item Be precise with writing footnote. This is because there can be times when one cannot understand the program that he or she has written. If one uses \\% in a sentence, then everything after \\% in that line becomes footnote.\r\n\r\n\\item Insert the error message just like the examples above. These error messages are very helpful when debugging.\r\n\r\n\\item Always structuralize the output as the same as the form of input of other functions. For example, if the form of output of a program is ``yes-no\", then change it to 1 or 0 instead of ``yes\" and ``no\". This way, they can be used as conditions for conditional statement or loop statement.\r\n\r\n\\item Try to avoid loop statement in MATLAB as much as possible and use optimized built-in MATLAB functions. For example, try to see how much faster {\\tt A*B} is compared to {\\tt mult(A,B)}. One will probably be surprised by the difference in speed.\r\n\r\n\\item If there is a difficult in writing a program, then try taking out the suspicious part and execute it separately. Then come back to the original program and then fix it.\r\n\\end{enumerate}\r\n\\newpage\r\n\\section{Graphics}\r\nA well drawn picture is better than 100-words long explanation. Matlab has powerful graphics processing system that is convenient to use and that expresses given data very well. (The pictures used in this chapter are all drawn using Matlab.)  This section will explain the high-level 2-D and 3-D graphic fuction of Matlab. The low-level factors like graphic objects are not dealt with here. This section deals with only showing a little bit of the power of Matlab graphics. For more details, use {\\tt help} or {\\tt doc}, or reference \\textbf{Matlab User's Guide} or \\textbf{Reference Guide}.\r\n\r\n\\subsection{2-D Graph}\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\mbox{%\r\n\\subfigure[]{%\r\n\\epsfig{file=examplesofplota.eps,width=0.45\\textwidth}} \\quad\r\n\\subfigure[]{%\r\n\\epsfig{file=examplesofplotb.eps,width=0.45\\textwidth}}} \\quad\r\n\\caption{{\\tt plot} 명령의 예} \\label{plot}\r\n\\end{figure}\r\n\r\n2-D graph is drawn using the {\\tt plot} function. In the simplest form, one can display graphs that has only one vector value like {\\tt plot(y)}. In this case, the elements of {\\tt y} are drawn in the order of index. In other words, {\\tt plot(rand(1,20))} graphs 20 random numbers in the order of $1\\sim20$, connects all the consecutive points in lines, and prints the picture on the screen just like picture~\\ref{plot}(a). If {\\tt y} was a matrix, each elements of columns are drawn in order, drawing as many as the number of columns of the matrix. The axis are adjusted with the maximum and minimum values of the data and printed on the screen.\r\n\r\n\\vv The typical form of {\\tt plot} is {\\tt plot(x,y)}. Here, {\\tt x} and {\\tt y} are vectors with same dimensions. Let us execute the following command. \\matlabp\\texttt{\\textbf{x = 0:pi/40:4*pi;}} \\matlabp\\texttt{\\textbf{plot(x, sin(x))}} \\vn In this graph, the coordinate of {\\tt i}-th point is $(\\tt x_{i}, y_{i})$.\r\n\r\n\\vv A line is drawing using the coordinates of {\\tt x} and {\\tt y} vectors. For instance, to draw a line connecting $(0,1)$ and $(4,3)$, type \\matlabp\\texttt{\\textbf{plot([0,4], [1,3])}} \\vn Here, {\\tt [0,4]} mean {\\tt x} coordinates of two points, and {\\tt [1,3]} represent  the associated {\\tt y} coordinates.\r\n\r\n\\vn \\textbf{Practice question:} Draw a line connecting the following each points: $(0,1), (4,3), (2,0), (5,-2)$ \\vn \\textbf{Practice question:} Draw a house similar to the picture~\\ref{plot}(b).\r\n\r\n\\subsubsection{Label}\r\nOne can attach label to the graph using the following commands.\r\n\r\n\\begin{description}\r\n\\item[\\tt gtext('text')] \\hfil \\par\r\nAfter executing this command, when one moves the mouse on the graph window, a cross-shaped thing is shown on the graph and waits for mouse click. After choosing the location by moving the mouse, the sentence {\\tt 'text'} pops up on the graph window upon clicking. \r\n\r\n\\item[\\tt text(x, y, 'text')] \\hfil \\par\r\nPrints {\\tt 'text'} on {\\tt (x,y)} location on the graph window. If {\\tt x} and {\\tt y} are vectors, {\\tt 'text'} is printed on each points.\r\n\r\n\\item[\\tt title('text')] \\hfil \\par\r\nPrints the title {\\tt 'text} at the very top part of the graph window.\r\n\r\n\\item[\\tt xlabel('text')] \\hfil \\par\r\nPuts an explanation on the x-axis.\r\n\r\n\\item[\\tt ylabel('text')] \\hfil \\par\r\nPuts an explanation on the y-axis.\r\n\\end{description}\r\n\r\n\\subsubsection{Drawing Many Graphs on the Same Axis}\r\nThere are at least 3 ways to draw many graphs on the same axis. However, if the recent graph contains data with bigger range than the previous data, then the graph can be rescaled.\r\n\\begin{enumerate}\r\n\\item The easiest way is to the command {\\tt hold}, which holds the current graph on the graphic window. The graphs that are drawn after that are overlapped until the {\\tt hold} status is turned off. The command that turns off {\\tt hold} is {\\tt hold off}.\r\n\r\n\\item The second way is to use the {\\tt plot} command the following way. \\vv \\texttt{\\textbf{plot(x1, y1, x2, y2, x3, y3, $\\ldots$)}} \\vn The merit of this way is that each vector pair is represented with different color/line forms. \r\n\r\n\\item The third way is using {\\tt plot(x,y)}. Here, {\\tt x} and {\\tt y} are either both matrices or one is vector and the other is matrix. If one of them is matrix and the other vector, then the column or row that matches the vector is printed with different color/line form. The column or row is chosen to match the vector. In case of square matrix, the column is selected. If both {\\tt x} and {\\tt y} are matrices that have same dimensions, the column of {\\tt x} is matched with the column of {\\tt y} and printed. If {\\tt x} is not predetermined (just like {\\tt plot(y)}), then the column of {\\tt y} is matched with the index of the row and then drawn.\r\n\r\n\\end{enumerate}\r\n\r\n\\subsubsection{Form of Line, Output Symbol, and Color}\r\nThe form of line and output symbol can be selected by adding sentences to the {\\tt plot} command.\r\n\r\n\\begin{description}\r\n\\item[\\tt plot(x,y, '--')] \\hfil \\par\r\n{\\tt y} is plotted in point-line with respect to {\\tt x}.\r\n\\item[\\tt plot(x,y, 'o')] \\hfil \\par\r\nInstead of connecting each points with line, the points are displayed in circle.\r\n\\item[\\tt plot(x,y, '--o')] \\hfil \\par\r\nEach data is connected with point-line and the points are displayed in circle.\r\n\\item[\\tt plot(x,y, '--m')] \\hfil \\par\r\nDisplays magenta colored point-line. \\end{description} \\vn For diverse usage, refer to {\\tt help plot}.\r\n\r\n\\subsubsection{Axis Scale}\r\nIn Matlab, the axis are automatically adjusted when drawing the graph. One can use command \\vv \\texttt{\\textbf{axis([xmin, xmax, ymin, ymax])}} \\vn to adjust the axis. One can return to the default setting using \\texttt{\\textbf{axis('auto')}}. The next command \\vv \\texttt{\\textbf{v = axis}} \\vn adjusts the current axis scale to the vector {\\tt v}. One can maintain the current axis scale using {\\tt axis(axis)}. Then, executing {\\tt hold}, the next graph is printed with the current scale.\r\n\r\n\\vv Let us draw the following circle. \\matlabp\\texttt{\\textbf{x = 0:pi/40:2*pi;}} \\matlabp\\texttt{\\textbf{plot(cos(x), sin(x))}} \\vn However, the thing that is shown in the screen does not look like circle. Why? The default setting for the length of each axis in Matlab is different. The command {\\tt axis('equal')} equalizes the visual scale of {\\tt x} and {\\tt y} on the screen so that the circle shape will be printed. Use {\\tt axis('normal')} to turn off this setting. Use the command {\\tt axis('on')} and {\\tt axis('off')} to set/erase the axis marking.\r\n\r\n\\subsubsection{Drawing Many Axes Using Subplot}\r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=foursubplots.eps,%height=7cm ,\r\nwidth=11cm, angle=0} \\caption{\\label{subplot}4개의 subplot:\r\n3차원상에서 곡면의 회전}\r\n\\end{figure}\r\n\r\nOne can draw graphs with many different axes in one graphic window using {\\tt subplot}. The command \\texttt{\\textbf{subplot(m, n, p)}} divides the current graphic window into $m \\times n$ small axis, (starting from top left following the row) sets the {\\tt p}-th graph as the current graph. For example, the following program makes four axes just like the picture~\\ref{subplot}.\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{7.6cm}{\\tt \\% test\\!$\\_{}$subplot.m \\\\ \\\\\r\n\\tt [x,y] = meshgrid(-3:0.3:3, -3:0.3,3); \\\\\r\nz = x.* exp(-x.\\^{}2-y.\\^{}2); \\\\\r\nsubplot(2,2,1) \\\\\r\nmesh(z), title('subplot(2,2,1)') \\\\\r\nsubplot(2,2,2) \\\\\r\nmesh(z) \\\\\r\nview(-37.5, 70), title('subplot(2,2,2)') \\\\\r\nsubplot(2,2,3) \\\\\r\nmesh(z) \\\\\r\nview(-37.5, -10), title('subplot(2,2,3)') \\\\\r\nsubplot(2,2,4) \\\\\r\nmesh(z) \\\\\r\nview(0,0), title('subplot(2,2,4)')}  \\end{center} }}\r\n\\end{center}\r\n\\vn The command {\\tt subplot(1,1,1)} sets the graphic axis back to one.\r\n\r\n\\subsubsection{figure, clf, cla}\r\nCommand {\\tt figure} produces a new figure window. \\par\r\n\r\n\\begin{description}\r\n\\item[{\\tt figure(N)}] \\hfil\\par\r\nProduces {\\tt N}-th figure window. Commands related to graphic after this will be executed in this window.\r\n\\item[{\\tt clf}] \\hfil\\par\r\nEverything except the window of the current figure window will be deleted. Thus, the properties of the current window will also be deleted.\r\n\\item[{\\tt cla}] \\hfil\\par\r\nDeletets all the lines, symbols, texts except the axis and axis markings in the current figure window.\r\n\\end{description}\r\n\r\n\\subsubsection{Inputs related to graphics}\r\nThe command \\vv \\texttt{\\textbf{[x, y] = ginput}} \\vn saves all the points that are inputted by the mouse on the current window. Cross shape is shown on the screen, and saves the points the mouse clicks. {\\tt Enter} finishes this command. The command \\vv \\texttt{\\textbf{[x, y] = ginput(n)}} \\vn is exactly the same as {\\tt ginput} except it only saves {\\tt n} points. Use {\\tt help} or {\\tt doc} to earn more information..\r\n\r\n\\subsubsection{Logarithmic plot}\r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=logarithmicplot.eps, height=7cm, %width=10cm,\r\nangle=0} \\caption{\\label{log}Logarithmic plot}\r\n\\end{figure}\r\n\r\nCommand \\texttt{\\textbf{semilogy(x, y)}} displays the graph {\\tt y} with $\\log_{10}$ scale and {\\tt x} with linear scale. For instance, \\matlabp\\texttt{\\textbf{x = 0:0.01:4;}} \\matlabp\\texttt{\\textbf{semilogy(x, exp(x)), grid}} \\vn draws the graph like picture~\\ref{log}. The increase of equidistant interval of {\\tt y}-axis is expressed in exponent of 10. In addition, the marking in the {\\tt y}-axis are drawn to show 1, 2, 3, $\\ldots$, 10, 20, 30, $\\ldots$, 100, $\\ldots$ starting from bottom. There are also similar commands like {\\tt semilogx} and {\\tt loglog}. {\\tt x} and {\\tt y} can be vector or matrix just like they were with {\\tt plot}.\r\n\r\n\\vn \\textbf{Practice question:} Draw graph of $x^{2}, x^{3}, x^{4}, \\exp{x^{2}}$ with $ 0\\leq x \\leq 10$ using {\\tt semilogy}.\r\n\r\n\\subsubsection{Polar Coordinate} \r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=polarplot.eps,height=7cm, %width=10cm,\r\nangle=0} \\caption{Polar plot: $r=\\sin 2\\theta$ } \\label{polar}\r\n\\end{figure}\r\n\r\nThe command \\texttt{\\textbf{polar(theta, r)}} uses angle $\\theta$ and size $r$ to show the position of the point. For instance, \\matlabp\\texttt{\\textbf{x = 0:pi/40:2*pi;}} \\matlabp\\texttt{\\textbf{polar(x, sin(2*x)), grid}} \\vn produces graph like picture~\\ref{polar}.\r\n\r\n\\subsubsection{Drawing a Graph of a Function that Changes Quickly}\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\mbox{%\r\n\\subfigure[]{%\r\n\\epsfig{file=ysina.eps,width=0.45\\textwidth}} \\quad\r\n\\subfigure[]{%\r\n\\epsfig{file=ysinb.eps,width=0.45\\textwidth}}} \\caption{$y\r\n=\\sin(1/x)$} \\label{sin}\r\n\\end{figure}\r\n\r\nUntil now, the graphs were drawn with data that has $x$-axis all distributed equally, like the example \\texttt{\\textbf{x = 0:0.01:4}}. If a function to be drawn rapidly changes in a certain domain, then the distribution of $x$-axis will be inefficient, and the graph will not be drawn properly. For instance, \\matlabp\\texttt{\\textbf{x = 0.01:0.001:0.1;}} \\matlabp\\texttt{\\textbf{plot(x, sin(1./x))}} \\vn will draw the graph like picture~\\ref{sin}(a). However, if the increment of $x$ is reduced to 0.0001, then the graph like picture~\\ref{sin}(b) will be drawn. The two graphs are clearly different in the domain $x < 0.04$.\r\n\r\n\\vv Matlab provides {\\tt fplot}, which is a more efficient function. When it comes to drawing a function like $\\sin(1/x)$, {\\tt fplot} calculates rapid changing places more frequently. However, the command {\\tt fplot} has a demerit, which is it must use function file.\r\n\r\n\\subsubsection{Many Commands related to 2 Dimensional Graphs}\r\nMatlab provides many commands that express functions into graphs. Here, we state some examples, but we wish for the reader to use {\\tt help} or {\\tt doc} to get more detailed information.\r\n\r\n\\begin{description}\r\n\\item[\\tt bar] \\hfil\\par Draws bar graph. \\item[\\tt compass] \\hfil\\par Displays the vector with entries size and direction of complex number with an arrow starting from the origin.\r\n\\item[\\tt errorbar] \\hfil\\par Displays error bar. \\item[\\tt hist] \\hfil\\par Draws histogram. \\item[\\tt quiver] \\hfil\\par Draws many different types of vector fields(for instance, gradient) using little arrows.\r\n\\item[\\tt fill] \\hfil\\par Draws polygon and fills in with given color.\r\n\\end{description}\r\n\r\n\\subsection{3 Dimensional Graph}\r\nMatlab provides many functions that can express 3 dimensional graphs. This susbsection will be a brief introduction to these functions.\r\n\r\n\\subsubsection{Plot3}\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\mbox{%\r\n\\subfigure[]{%\r\n\\epsfig{file=plot3a.eps,width=0.45\\textwidth}} \\quad\r\n\\subfigure[]{%\r\n\\epsfig{file=exampleofplot3b.eps,width=0.45\\textwidth}}} \\quad\r\n\\caption{example of command plot3}\\label{plot3}\r\n\\end{figure}\r\n\r\nThe command {\\tt plot3} is a 3 dimensional version of {\\tt plot}, and if we write \\matlabp\\texttt{\\textbf{plot3(x, y, z)}} \\vn then a line connecting the points $(x_i, y_i, z_i)$ will be drawn in 3 dimension. For instance, \\matlabp\\texttt{\\textbf{plot3(rand(1,10), rand(1,10), rand(1,10))}} \\vn uses 10 random points to draw a line in 3 dimension, like picture~\\ref{plot3}(a). And another example, \\matlabp\\texttt{\\textbf{t = 0:pi/50:10*pi;}} \\matlabp\\texttt{\\textbf{plot3(exp(-0.02*t).*sin(t), exp(-0.02*t).*cos(t), t), \\ldots}} \\par\\texttt{\\textbf{xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis') }}\\vn draws a dwindling spiral like picture~\\ref{plot3}(b). Be careful on the direction of $x$-axis, $y$-axis, $z$-axis, and pay attention to the fact that label was marked for each axis.\r\n\r\n\\subsubsection{Mesh Surface}\r\nThe following is an example regarding mesh surface.\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{8.4cm}{\\tt \\% Mexican\\!$\\_{}$hat.m \\\\ \\\\\r\n\\tt [x y] = meshgrid(-7.5:0.5:7.5, -7.5:0.5:7.5);  \\\\\r\nr = sqrt(x.\\^{}2 + y.\\^{}2) + eps; \\\\\r\nz = sin(r)./r; \\\\\r\nmesh(z);}  \\end{center} }}\r\n\\end{center}\r\n\r\n\\vv To know how these surfaces are drawn, let us study a simple example like $z = x^{2} - y^{2}$. We want a graph that shows the change in $z$ value when there is a change in values in $x$-$y$ plane. Let us think only in the domain $0 \\leq x \\leq 5, 0 \\leq y \\leq 5$ for this example. First use Matlab command {\\tt meshgrid} to produce grid on the $x$-$y$ plane where the surface will be drawn. \\matlabp\\texttt{\\textbf{[x y] = meshgrid(0:5, 0:5)}} \\vn This command produces two matrices {\\tt x, y} like the following.\r\n$$\\begin{array}{ccccccc}\r\n{\\tt x =} & & & & & & \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5 \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5 \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5 \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5 \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5 \\\\\r\n& 0 & 1 & 2 & 3 & 4 & 5\r\n      \\end{array}\\qquad\\qquad\r\n\\begin{array}{ccccccc}\r\n{\\tt y =} & & & & & & \\\\\r\n& 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n& 1 & 1 & 1 & 1 & 1 & 1 \\\\\r\n& 2 & 2 & 2 & 2 & 2 & 2 \\\\\r\n& 3 & 3 & 3 & 3 & 3 & 3 \\\\\r\n& 4 & 4 & 4 & 4 & 4 & 4 \\\\\r\n& 5 & 5 & 5 & 5 & 5 & 5\r\n\\end{array}$$\r\n\r\n\\vn As we can see from above, matrix {\\tt x} represents each grid of $x$-axis, and matrix {\\tt y} represents each grid of $y$-axis. If the grid of $x$-direction and that of $y$-direction are of same shape, then we can write in the following short form. \\matlabp\\texttt{\\textbf{[x y] = meshgrid(0:5)}} \\vn And as can be predicted with the Matlab matrix operation, the command \\texttt{\\textbf{z = x.\\^{}2-y.\\^{}2}} produces the following matrix.\r\n$$\\begin{array}{rrrrrrr}\r\n{\\tt z =} & & & & & & \\\\\r\n& 0  &  1  &  4  &  9  &  16  &  25 \\\\\r\n& -1  &  0  &  3  &  8  &  15  &  24 \\\\\r\n& -4  &  -3  &  0  &  5  &  12  &  21 \\\\\r\n& -9  &  -8  &  -5  &  0  &  7  &  16 \\\\\r\n& -16  &  -15  &  -12  &  -7  &  0  &  9 \\\\\r\n& -25  &  -24  &  -21  &  -16  &  -9  &  0\r\n\\end{array}$$\r\n\r\n\\vn For instance, at the point $(5, 2)$, z takes the value $5^{2}-2^{2} = 21$. Fortunately, one does not need to be concerned with the precise relationship between the coordinate system of the grid and the index of the matrix. This is automatically adjusted by {\\tt meshgrid}.\r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=surface.eps, %fig7surf.eps,\r\nheight=7cm,%width=10cm,\r\nangle=0} \\caption{curved surface $z = x^{2}-y^{2}$} \\label{surf}\r\n\\end{figure}\r\n\r\n\\vv The command {\\tt mesh(z)} produces graph with lattice-like surface, where the points on the grid are raised to the surface and then connected to form the lattice. In other words, {\\tt mesh} draws a `wire mesh'-like surface. If one does not want color, then one can type \\matlabp{\\tt mesh(z,'EdgeColor','black')} \\vn In addition, another command {\\tt surf} draws a lattice-like surface composed of small colored tiles. Use {\\tt help} or {\\tt doc} to learn more about {\\tt mesh} and {\\tt surf}.\r\n\r\nIf one is using Matlab student edition, then one must know that there is a limit to grid size when using {\\tt meshgrid}. The limit is that the size of the row or column of matrix must be at most 32, and the size of matrix must not exceed 8192.\r\n\r\n\\vn \\textbf{Practice question:} Use the command  \\vv \\texttt{\\textbf{[x y] = meshgrid(0:0.25:5);}} \\vn to draw a denser mesh than picture~\\ref{surf}.\r\n\r\n\\vn \\textbf{Practice question:} The distribution of temperature on the iron plate is as follows.\r\n$$u(x, y) = 80 y^{2} e^{-x^{2}-0.3y^{2}}$$ \\noindent With the domain $-2.1 \\leq x \\leq 2.1, -6 \\leq y \\leq 6$, draw the curved surface $u$ with the grid size of each direction as 0.15.\r\n\r\n\\subsubsection{Drawing Contour}\r\n\\begin{figure}\r\n\\centering\r\n\\mbox{%\r\n\\subfigure[]{%\r\n\\epsfig{file=contoura.eps,width=0.45\\textwidth}} \\quad\r\n\\subfigure[]{%\r\n\\epsfig{file=contour3b.eps,width=0.45\\textwidth}}} \\caption{Contour\r\nplot} \\label{contour}\r\n\\end{figure}\r\n\r\nAfter solving the practice questions above, execute the following command. \\matlabp\\texttt{\\textbf{ contour(u)}} \\vn Then, one can earn a contour(isothermal line) about the distribution of temperature like picture~\\ref{contour}(a). The command {\\tt contour} can take second input variable. For this second variable, one inputs how many lines the contour will draw or a vector with specific values for drawing contour. Use command {\\tt contour3} to draw a 3 dimensional contour like picture~\\ref{contour}(b). One can make contour label with the command {\\tt clabel}.\r\n\r\n\\begin{figure}\r\n\\centering\r\n\\mbox{%\r\n\\subfigure[]{%\r\n\\epsfig{file=fig710a.eps,width=0.45\\textwidth}} \\quad\r\n\\subfigure[]{%\r\n\\epsfig{file=fig710b.eps,width=0.45\\textwidth}}} \\caption{(a)\r\nmeshc \\quad (b) Erasing part of curved surface} \\label{meshc}\r\n\\end{figure}\r\n\r\n\\vv To display both contour and mesh together, one can use {\\tt meshc} or {\\tt surfc}. For instance, the following program \\matlabp\\texttt{\\textbf{[x y] = meshgrid(-2:0.2:2); }} \\matlabp\\texttt{\\textbf{ z = x.*exp(-x.\\^{}2 - y.\\^{}2); }} \\matlabp\\texttt{\\textbf{meshc(z);}} \\vn draws a graph like picture~\\ref{meshc}(a).\r\n\r\n\\subsubsection{Deletion of Curved Surface Due to NaN(Not a Number)}\r\nIf the matrix that holds information on the curved surface contains NaN, then this value does not appear in the graph, and because of this, a part of the curved surface will be omitted. Let us study the following example.\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{8.0cm}{\\tt \\% cropping.m \\\\ \\\\\r\n\\tt [x y] = meshgrid(-2:.2:2);  \\\\\r\nz = x.*exp(-x.\\^{}2 - y.\\^{}2); \\\\\r\nc = z;\\qquad \\% preserve the original surface \\\\\r\nc(1:11, 1:21) = nan; \\\\\r\nmesh(c), xlabel(`x-axis'), ylabel(`y-axis')}  \\end{center} }}\r\n\\end{center}\r\n\\vn The above program will display the graph like picture~\\ref{meshc}(b).\r\n\r\n\\subsubsection{quiver}\r\nThe command {\\tt quiver} draws a vector that starts at 2 dimensional point. Although it is drawn in 2 dimensional graph, it is occasionally used with {\\tt contour}, which helps understanding changes in 3 dimensional curved surfaces. For instance, let us think about $V = x^{2} + y$, which is a scalar function with 2 variables for input. The gradient of V is defined as the following vector field.\r\n\\begin{eqnarray*}\r\n\\nabla V & = & \\left(\\frac{\\partial V}{\\partial x}, \\frac{\\partial\r\nV}{\\partial y}\\right) \\\\\r\n         & = & (2x, 1)\r\n\\end{eqnarray*}\r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=fig711.eps,height=7cm, %width=10cm,\r\nangle=0} \\caption{Gradient and contour} \\label{grad}\r\n\\end{figure}\r\n\r\n\\noindent The following program draws the direction of $\\nabla V$ for each points in $x$-$y$ plane(refer to picture~\\ref{grad}).\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{5.6cm}{\\tt \\% test\\!$\\_{}$quiver.m \\\\ \\\\\r\n\\tt [x y] = meshgrid(-2:.2:2);  \\\\\r\nV = x.\\^{}2 + y; \\\\\r\ndx = 2*x; \\\\\r\ndy = ones(size(y)); \\\\\r\naxis equal \\\\\r\ncontour(x, y, V), hold on \\\\\r\nquiver(x, y, dx, dy), hold off}  \\end{center} }}\r\n\\end{center}\r\n\r\n`Contour' is a series of {\\tt level surface}. Gradient of a random point is perpendicular to the level surface that passes through that point. When drawing a contour, the vectors {\\tt x} and {\\tt y} are required for labeling the axes. What will happen if take this out and just use {\\tt contour(V)} and execute the above {\\tt test\\!$\\_{}$quiver.m}? Let us try to predict the result before we execute it.\r\n\r\nAnother option regarding {\\tt quiver} is that one can change the size of the arrows. See {\\tt help} or {\\tt doc}.\r\n\r\nIf it is not possible to differentiate the vector $V$ or if one does not wish to differentiate it, then one can use the command {\\tt gradient} to calculate the derivative.\r\n\\matlabp\\texttt{\\textbf{[dx dy] = gradient(V, 0.2, 0.2);}} \\vn 0.2 means the increment with respect to $x$ and $y$ directions for approximate calculation.\r\n\r\n\\subsubsection{Pseudocolor}\r\nThe following program  \\matlabp\\texttt{\\textbf{[x, y] = meshgrid(-2:.2:2); }} \\matlabp\\texttt{\\textbf{z = x.*exp(-x.\\^{}2 - y.\\^{}2); }} \\matlabp\\texttt{\\textbf{pcolor(z), shading flat, colormap(hot) }} \\vn draws a contour that expresses height using mixture of red, orange, and yellow. The command {\\tt shading flat} eliminates the grid line. {\\tt pcolor} means pseudocolor. Each element of the matrix {\\tt z} is used as index of color map(in this case hot) that determines the color which will express the element. If one wants a cool color, then try {\\tt colormap(cool)}.\\^{}\\^{} Does it feel cool? There is yet another color map, {\\tt colormap(hsv)}, where {\\tt hsv} stands for huge-saturation-value.\r\n\r\n\\subsubsection{Visualization of matrix}\r\n\r\n\\begin{figure}[]\r\n\\center \\epsfig{file=viewmat.eps,height=7cm,%width=10cm,\r\nangle=0} \\caption{visualization of matrix} \\label{mat}\r\n\\end{figure}\r\n\r\nThe command {\\tt mesh} can `visualize' the matrix. The following program displays the graph like picture~\\ref{mat}.\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{4.7cm}{\\tt \\% visual\\!$\\_{}$mat.m \\\\ \\\\\r\n\\tt a = zeros(30);  \\\\\r\na(:,15) = 0.2*ones(30,1); \\\\\r\na(7,:) = 0.1*ones(1,30); \\\\\r\na(15,15) = 1; \\\\\r\nmesh(a)}  \\end{center} }}\r\n\\end{center}\r\n\\vn The size of the matrix {\\tt a} is $30 \\times 30$. The middle element {\\tt a(15,15)} is 1, and every element of the 7-th row is 0.1, and the remaining elements of the 15-th row is 0.2. {\\tt mesh(a)} cognizes every rows and columns of matrix a as coordinates of $x$-$y$. In other words, the value of {\\tt a(i,j)} is the height of the curved surface mesh at point {\\tt (i,j)}.\r\n\r\n\\subsubsection{Rotating 3 Dimensional Graph}\r\n{\\tt view} is a command which designates observation point when viewing a 3 dimensional graph. To see how this works, let us execute the following program which rotates the visualized matrix picture~\\ref{mat}.\r\n\r\n\\begin{center}\r\n\\fbox{\\parbox{10.5cm}{\\begin{center}\r\n\\parbox{5cm}{\\tt \\% rotation.m \\\\ \\\\\r\n\\tt a = zeros(30);  \\\\\r\na(:,15) = 0.2*ones(30,1); \\\\\r\na(7,:) = 0.1*ones(1,30); \\\\\r\na(15,15) = 1; \\\\\r\nel = 30; \\\\\r\nfor az = -37.5:15:-37.5+360 \\\\\r\n\\phantom{for}mesh(a), view(az, el) \\\\\r\n\\phantom{for}pause(0.5) \\\\\r\nend}  \\end{center} }}\r\n\\end{center}\r\n\\vn The command {\\tt view} requires two angles. The first, as can be seen in the example, is azimuth {\\tt az} on the $x$-$y$ plane that has degree as its unit. {\\tt az} rotates the observation point about $z$-axis - in other words, the 'sharp point' at $(15,15)$ in picture~\\ref{mat} - counterclockwise. The default value for {\\tt az} is $-37.5^{\\circ}$. Therefore, the above program rotates the observation point about $z$-axis $15^{\\circ}$ each time from the default value. The second angle of {\\tt view} is {\\tt el} which expresses altitude with degree as its unit. This means the angle between the $z$-axis and $x$-$y$ plane. For instance, $90^{\\circ}$ represents 2 dimensional graphic, in other words, looking down from above. If the value of altitude is positive, then the observer is above the $x$-$y$ plane, and if negative, then is below the plane. The default value is $30^{\\circ}$.\r\n\r\n\\vv The command {\\tt pause(n)} stops the execution for {\\tt n} seconds.\r\n\r\n\\vn \\textbf{Practice question:} Fix the above program so that the value of {\\tt az} is fixed as the default value and and the value of {\\tt el} is gradually changing.\r\n\r\n\\subsubsection{Lighting}\r\nOne can materialize lighting and shadow effect using the command {\\tt surfl}. Try the following.\r\n\r\n\\matlabp\\texttt{\\textbf{[x, y] = meshgrid(-2:0.05:2);}}\r\n\\matlabp\\texttt{\\textbf{z = x.*exp(-x.\\^{}2 - y.\\^{}2); }}\r\n\\matlabp\\texttt{\\textbf{surfl(z, [-20 50]), colormap(gray),\r\nshading flat}} \\vn The location of the source of light is determined by the second variable of {\\tt surfl}, with the first value being azimuth and the second being altitude. To make a natural reflection light, one must set the grid compact so that the grid is not visualizable. (In this case, $81\\times 81$)", "meta": {"hexsha": "e57d2893f1d48266787da704434f8f7f70541c98", "size": 52424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/Matlabe.tex", "max_stars_repo_name": "mireiffe/mas109_matlab_2021_2", "max_stars_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/Matlabe.tex", "max_issues_repo_name": "mireiffe/mas109_matlab_2021_2", "max_issues_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-19T08:29:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T08:29:55.000Z", "max_forks_repo_path": "files/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/Matlabe.tex", "max_forks_repo_name": "mireiffe/mas109_matlab_2021_2", "max_forks_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_forks_repo_licenses": ["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.0756013746, "max_line_length": 1177, "alphanum_fraction": 0.7076339081, "num_tokens": 15694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6023219965789406}}
{"text": "% !TEX root = ./Basilisk-Integrators20170724.tex\n\n\n\\begin{figure}[htb]\n\t\\centerline{\n\t\\includegraphics[]{Figures/integratorDiagram}\n\t}\n\t\\caption{Illustration of the Integrator Diagram}\n\t\\label{fig:intDiag}\n\\end{figure}\n\n\n\\section{Model Description}\n\n\\subsection{Overview}\nThe Basilisk integration capability is implemented in a modular manner such that different integrators can be assigned to the equations of motion that must be solved.  Figure~\\ref{fig:intDiag} illustrates how the integrator functions relative to a dynamical systems model, here the {\\tt SpacecraftPlus()} object.  The ODE's are provided by a sub-class of {\\tt DynamicObject} which must be able to respond to the {\\tt equationsOfMotion()} method.  Integration of the state vector forward one time step is then handled by the {\\tt integrate} method of the integrator class.  By default the {\\tt DynamicObject} is integrated using a fixed time step 4th order Runge-Kutta method.  \n\nAssume the dynamical system is given by\n\\begin{equation}\n\t\\dot{\\bm x} = \\bm f(t, \\bm x)\n\\end{equation}\nThe initial conditions are specified through $\\bm x_{0} = \\bm x(t_{0})$.  In integration time step is given through $h$.  \n\n\\subsection{Implemented Integrators}\n\n\\subsubsection{4th Order Runge Kutta - Default Integrator}\nA standard fixed time step 4th order Runge Kutta integrator is enabled by default.  The 4 $k_{i}$ values are defined as\n\\begin{align}\n\t\\bm k_{1} &= \\bm f(t_{n}, \\bm x_{n}) \\\\\n\t\\bm k_{2} &= \\bm f(t_{n} + \\frac{h}{2}, \\bm x_{n} + \\frac{h}{2} \\bm k_{1}) \\\\\n\t\\bm k_{3} &= \\bm f(t_{n} + \\frac{h}{2}, \\bm x_{n} + \\frac{h}{2} \\bm k_{2}) \\\\\n\t\\bm k_{4} &= \\bm f(t_{n} + h, \\bm x_{n} + h \\bm k_{3}) \n\\end{align}\nThe states at the next integration time $t_{n+1} = t_{n} + h$ is\n\\begin{equation}\n\t\\bm x_{n+1} = \\bm x_{n} + \\frac{h}{6} \\left(\n\t\t\\bm k_{1} + 2 \\bm k_{2} + 2 \\bm k_{3} + \\bm k_{4}\n\t\\right)\n\\end{equation}\n\n\n\\subsubsection{2nd Order Runge Kutta (Heun's Method)}\nA 2nd order Runge-Kutta method is implemented through Heun's method.\\footnote{\\url{http://goo.gl/SWdyBZ}} The 2 $k_{i}$ values are defined as\n\\begin{align}\n\t\\bm k_{1} &= \\bm f(t_{n}, \\bm x_{n}) \\\\\n\t\\bm k_{2} &= \\bm f(t_{n} + h, \\bm x_{n} + h \\bm k_{1}) \n\\end{align}\nThe states at the next integration time $t_{n+1} = t_{n} + h$ is\n\\begin{equation}\n\t\\bm x_{n+1} = \\bm x_{n} + \\frac{h}{2} \\left(\n\t\t\\bm k_{1} +  \\bm k_{2}\n\t\\right)\n\\end{equation}\n\n\n\\subsubsection{1st Order Runge Kutta (Euler's Method)}\nA first order Runge-Kutta method is implemented through Euler's method. The one $k_{1}$ value is defined as\n\\begin{align}\n\t\\bm k_{1} &= \\bm f(t_{n}, \\bm x_{n}) \n\\end{align}\nThe states at the next integration time $t_{n+1} = t_{n} + h$ is\n\\begin{equation}\n\t\\bm x_{n+1} = \\bm x_{n} + h\n\t\t\\bm k_{1}\n\\end{equation}\n", "meta": {"hexsha": "4d4889a13f505a8bdf1f9c0a93fcc9e58e163e97", "size": 2748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/simulation/dynamics/Integrators/_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/simulation/dynamics/Integrators/_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/simulation/dynamics/Integrators/_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": 41.6363636364, "max_line_length": 677, "alphanum_fraction": 0.6786754003, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6023219897749079}}
{"text": "\\section{Representation}\n\n\\subsection{Nodes}\nThe possible nodes for each individual, or parse tree, comprise nodes from a function set and terminal set. As per the implementation of the EvoHyp \\cite{pillay2017evohyp} toolset, the function set - used for possible internal nodes - contains simple addition, subtraction, multiplication and division arithmetic operators. In the case of the division operator, a value of 1 is returned if the denominator is 0. In addition, arithmetic rules were used so the function set also comprises an \\emph{ifelse} operator and\nrelational operators ($<$, $>$, $<=$, $>=$, $==$ and $!=$).\n\nIn terms of the terminal set, there are 3 possible nodes - \\emph{A}, \\emph{C} and \\emph{F} - which represent attributes of a specific city, \\emph{n}, in the TSP instance. \\emph{A} represents the average distance from \\emph{n} to each of its neighbors. \\emph{C} represents the distance between \\emph{n} and its closest neighbor. \\emph{F} represents the distance between \\emph{n} and its furthest neighbor. These end nodes, as well as the aforementioned internal nodes, are described in more detail in table \\ref{tab:nodes}.\n\n\\begin{table}[H]\n\\resizebox{\\textwidth}{!}{\\begin{tabular}{|l|l|l|}\n\\hline\n\\textbf{Symbol} & \\textbf{Arity} & \\textbf{Description}                                                                                \\\\ \\hline\n+               & 2              & Adds its 2 children and returns the result                                                          \\\\ \\hline\n-               & 2              & Subtracts the first child from the second child and returns the result                              \\\\ \\hline\n*               & 2              & Multiplies its 2 children and returns the result                                                    \\\\ \\hline\n/               & 2              & Divides the 1st child by the 2nd child and returns the result; or, returns 1 if the 2nd child is 0  \\\\ \\hline\n\\textit{ifelse} & 3              & If the 1st child evaluates to true the 2nd child is returned; otherwise,  the 3rd child is returned \\\\ \\hline\n\\textless{}     & 2              & True if the 1st child is less than the 2nd child; otherwise, evaluates to false                     \\\\ \\hline\n\\textgreater{}  & 2              & True if the 1st child is greater than the 2nd child; otherwise, evaluates to false                  \\\\ \\hline\n\\textless{}=    & 2              & True if the 1st child is less than or equal to the 2nd child; otherwise, evaluates to false         \\\\ \\hline\n\\textgreater{}= & 2              & True if the 1st child is greater than or equal to the 2nd child; otherwise, evaluates to false      \\\\ \\hline\n==              & 2              & True if the 1st child is equal to the 2nd child; otherwise, evaluates to false                      \\\\ \\hline\n!=              & 2              & True if the 1st child is not equal to the 2nd child; otherwise, evaluates to false                  \\\\ \\hline\nA               & 0              & Returns the average distance from a specific city in the TSP and each of its neighbors              \\\\ \\hline\nC               & 0              & Returns the distance from a specific city in the TSP and its closest neighbor                       \\\\ \\hline\nF               & 0              & Returns the distance from a specific city in the TSP and its furthest neighbor                      \\\\ \\hline\n\\end{tabular}}\n\\caption{Function and Terminal Set}\n\\label{tab:nodes}\n\\end{table}\n\n\\subsection{Individuals}\\label{sec:individuals}\nEach chromosome within a population consists of a parse tree for calculating a priority value for each city in the TSP. To clarify, when evaluating the fitness of an individual, the parse tree will be used to calculate a priority value for all cities in the TSP; then, the cities will be visited in order of these priority values and the total distance determined. Given the possible nodes identified in table \\ref{tab:nodes}, an example of one such parse tree is depicted in figure \\ref{fig:decision_tree}.\n\n% minimum distance between nodes on the same line\n\\setlength{\\GapWidth}{1em}  \n% draw with a thick dashed line, very nice looking\n\\thicklines \\drawwith{\\dottedline{2}}   \n% draw an oval and center it with the rule.  You may want to fool with the\n% rule values, though these seem to work quite well for me.  If you make the\n% rule smaller than the text height, then the GP nodes may not line up with\n% each other horizontally quite right, so watch out.\n\\newcommand{\\gpbox}[1]{\\Ovalbox{#1\\rule[-.7ex]{0ex}{2.7ex}}}\n\n\\begin{figure}[H]\n    \\centering\n    \\resizebox{\\textwidth}{!}{\\begin{bundle}{\\gpbox{+}}\\chunk{\\begin{bundle}{\\gpbox{ifelse}}\\chunk{\\begin{bundle}{\\gpbox{$<$}}\\chunk{\\begin{bundle}{\\gpbox{-}}\\chunk{\\gpbox{A}}\\chunk{\\gpbox{C}}\\end{bundle}}\\chunk{\\begin{bundle}{\\gpbox{-}}\\chunk{\\gpbox{F}}\\chunk{\\gpbox{A}}\\end{bundle}}\\end{bundle}}\\chunk{\\begin{bundle}{\\gpbox{/}}\\chunk{\\gpbox{A}}\\chunk{\\gpbox{C}}\\end{bundle}}\\chunk{\\begin{bundle}{\\gpbox{/}}\\chunk{\\gpbox{A}}\\chunk{\\gpbox{F}}\\end{bundle}}\\end{bundle}}\\chunk{\\begin{bundle}{\\gpbox{*}}\\chunk{\\gpbox{A}}\\chunk{\\begin{bundle}{\\gpbox{/}}\\chunk{\\gpbox{C}}\\chunk{\\gpbox{F}}\\end{bundle}}\\end{bundle}}\\end{bundle}}\n    \\caption{Example Individual}\n    \\label{fig:decision_tree}\n\\end{figure}\n\n\\subsection{Populations}\nOf course, a population consists of a collection of the individuals that have been described. The genetic algorithm applied only made use of a single population consisting of 256 individuals. This means that only a single population was evolved and cross-population breeding was not applied.\n\n\\section{Initial Population Generation}\n\nAs implemented using EvoHyp \\cite{pillay2017evohyp}, the initial population was generated using the \\emph{grow} method proposed by Koza \\cite{koza1992genetic}. At the maximum depth the elements from the terminal set are selected; but, at other levels, elements are selected from both the function and terminal sets, whilst abiding by constraints such that the child of an \\emph{ifelse} node must be one of the conditional operator nodes. The maximum tree depth allowed during the initial population generation was a tree depth of 4.", "meta": {"hexsha": "77e2909769ce7e0edea03cca47db4802a87f1dad", "size": 6174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assets/report/02_representation/representation.tex", "max_stars_repo_name": "marcus-bornman/cos_790_assignment_3", "max_stars_repo_head_hexsha": "662fb0a2ec1b442ac702f195584aa9b913eae7c6", "max_stars_repo_licenses": ["AFL-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": "assets/report/02_representation/representation.tex", "max_issues_repo_name": "marcus-bornman/cos_790_assignment_3", "max_issues_repo_head_hexsha": "662fb0a2ec1b442ac702f195584aa9b913eae7c6", "max_issues_repo_licenses": ["AFL-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": "assets/report/02_representation/representation.tex", "max_forks_repo_name": "marcus-bornman/cos_790_assignment_3", "max_forks_repo_head_hexsha": "662fb0a2ec1b442ac702f195584aa9b913eae7c6", "max_forks_repo_licenses": ["AFL-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.3157894737, "max_line_length": 622, "alphanum_fraction": 0.6637512148, "num_tokens": 1585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6022622688800078}}
{"text": "\\appendix\n\\section{$\\hat{\\mu}$ bias by FBMP}\n\\label{sec:mubias}\n\n\\subsection{Model}\n\nThe model is described in section~\\ref{subsec:fbmp}. \n\n\\begin{equation}\n\\begin{aligned}\n    \\left.\n    \\begin{bmatrix}\n        \\bm{w} \\\\\n        \\bm{q}'\n    \\end{bmatrix}\n    \\right\\vert\\bm{z}\n    &\\sim \\mathrm{Normal}\\left(\n    \\begin{bmatrix}\n        \\bm{V}_\\mathrm{PE}\\bm{z} \\\\\n        \\bm{z}\n    \\end{bmatrix}, \n    \\begin{bmatrix}\n        \\bm{\\Sigma}_z & \\bm{V}_\\mathrm{PE}\\bm{Z} \\\\\n        \\bm{Z}\\bm{V}_\\mathrm{PE}^\\intercal & \\bm{Z}\n    \\end{bmatrix}\n    \\right) \\\\\n    \\bm{\\Sigma}_z &= \\bm{V}_\\mathrm{PE}\\bm{Z}\\bm{V}_\\mathrm{PE}^\\intercal+\\sigma_\\epsilon^2\\bm{I}_M \n\\end{aligned}\n\\end{equation}\n\n\\begin{equation}\n\\begin{aligned}\n    \\nu =& \\log[p(\\bm{w},\\bm{z})] = \\log[p(\\bm{w}|\\bm{z})p(\\bm{z})] \\\\\n    =& -\\frac{1}{2}(\\bm{w}-\\bm{V}_\\mathrm{PE}\\bm{z})^\\intercal\\bm{\\Sigma}_z^{-1}(\\bm{w}-\\bm{V}_\\mathrm{PE}\\bm{z})-\\frac{1}{2}\\log\\det\\bm{\\Sigma}_z-\\frac{N}{2}\\log2\\pi \\\\\n    &+ \\sum_{i}\\log{\\mathrm{Poisson}(z_i,p_i)}\n\\end{aligned}\n\\end{equation}\n\n$\\bm{V}_\\mathrm{PE}$ is a $M\\times N$ matrix, where $N=N_\\mathrm{PE}$ is the simulation truth of PE number. \n\n\\subsection{Approximation}\n\n\\begin{itemize}\n    \\item Poisson $\\rightarrow$ Bernoulli, $z_i=0,\\bm{Z}_{ii}=0$ or $z_i=1,\\bm{Z}_{ii}=\\sigma_q^2$\n    \\item SPE approximation\n    \\begin{itemize}\n    \\item For \\emph{delta} approximation, $\\bm{V}_{PE}=\\begin{bmatrix}\\bm{I} \\\\\\bm{O}\\end{bmatrix}$, $w_i\\sim \\mathrm{Normal}(1,\\sigma_q^2+\\sigma_\\epsilon^2)$\n    \\item For \\emph{flat} approximation, $\\bm{V}_{PE}=\\frac{1}{\\sqrt{M}}\\bm{J}_{M,N}$, $w_i\\sim \\mathrm{Normal}(\\frac{N}{\\sqrt{M}},\\frac{N}{\\sqrt{M}}\\sigma_q^2+\\sigma_\\epsilon^2)$, $\\sum_i^M w_i\\sim \\mathrm{Normal}(N\\sqrt{M},M^{\\frac{3}{2}}N\\sigma_q^2+M\\sigma_\\epsilon^2)$\n    \\end{itemize}\n    \\item flat prior, $P(z_i=1)=\\lambda,P(z_i=0)=1-\\lambda$\n\\end{itemize}\n\nThe factor $\\frac{1}{\\sqrt{M}}$ of $\\bm{V}_{PE}$ in flat approximation is required by FBMP's repeated greedy search (RGS). \n\n\\subsection{Evaluation}\n\nFor a certain $(\\bm{w}, \\bm{z})$, let $K=\\{i|z_i=1\\}$, $|K|=n$, we evaluate the evolution process of $\\nu$ in 2 approximations respectively. \n\n\\subsubsection{Delta approximation}\n\n\\begin{equation}\n\\begin{aligned}\n    \\bm{\\Sigma}_z &= \\begin{bmatrix}\n        \\bm{Z} & \\bm{O} \\\\\n        \\bm{O} & \\bm{O}\n    \\end{bmatrix} + \\sigma_\\epsilon^2\\bm{I}_M \\\\\n    \\det\\bm{\\Sigma}_z &= \\Pi_i (z_i\\sigma_q^2+\\sigma_\\epsilon^2) \\\\\n    \\bm{\\Sigma}_{zij}^{-1} &= \\begin{cases}\n        \\frac{1}{z_i\\sigma_q^2+\\sigma_\\epsilon^2} & \\text{ if } i=j \\\\ \n        0 & \\text{ if } i\\neq j \n    \\end{cases}\n\\end{aligned}\n\\end{equation}\n\nThus, \n\n\\begin{equation}\n\\begin{aligned}\n    -2\\nu =& \\sum_{i\\in K}\\frac{(w_i - 1)^2}{\\sigma_q^2+\\sigma_\\epsilon^2} + \\sum_{i\\in \\bar{K}}\\frac{w_i^2}{\\sigma_\\epsilon^2} \\\\ \n    &+ n\\log(\\sigma_q^2+\\sigma_\\epsilon^2) + (N-n)\\log\\sigma_\\epsilon^2 - 2n\\log\\lambda - 2(N-n)\\log(1-\\lambda) + C.\n\\end{aligned}\n\\end{equation}\n\nAdditionally, \n\n\\begin{equation}\n    \\frac{w_i^2}{\\sigma_\\epsilon^2} = \\frac{1}{\\sigma_\\epsilon^2}\\left((\\sigma_q^2+\\sigma_\\epsilon^2)\\frac{(w_i - 1)^2}{\\sigma_q^2+\\sigma_\\epsilon^2} + 2(w_i - 1) + 1\\right).\n\\end{equation}\n\nSome statistics we use below,\n\n\\begin{equation}\n    \\sum_{i\\in K}\\frac{(w_i - 1)^2}{\\sigma_q^2+\\sigma_\\epsilon^2} \\sim \\chi^2(n).\n\\end{equation}\n\nCalculate expectation on distribution of $\\bm{w}$ and $\\bm{z}$ with $|K|=n$, \n\n\\begin{equation}\n\\begin{aligned}\n    -2E(\\nu)_n =& n + (N - n)\\frac{\\sigma_q^2+\\sigma_\\epsilon^2}{\\sigma_\\epsilon^2} + (N - n)\\frac{1}{\\sigma_\\epsilon^2} \\\\ \n    &+ n\\log(\\sigma_q^2+\\sigma_\\epsilon^2) + (N-n)\\log\\sigma_\\epsilon^2 - 2n\\log\\lambda - 2(N-n)\\log(1-\\lambda) + C.\n\\end{aligned}\n\\end{equation}\n\nThus, \n\n\\begin{equation}\n\\begin{aligned}\n    -2D(\\nu)_n =& -2E(\\nu)_n - (-2E(\\nu)_{n-1}) \\\\ \n    =& 1 - \\frac{\\sigma_q^2+\\sigma_\\epsilon^2}{\\sigma_\\epsilon^2} - \\frac{1}{\\sigma_\\epsilon^2} + \\log(\\sigma_q^2+\\sigma_\\epsilon^2) - \\log\\sigma_\\epsilon^2 - 2\\log\\lambda + 2\\log(1-\\lambda).\n\\end{aligned}\n\\end{equation}\n\nRemember that $\\sigma_q^2 \\gg \\sigma_\\epsilon^2$ and $\\lambda \\ll 1$, set $x=\\sigma_q^2/\\sigma_\\epsilon^2$, then,\n\n\\begin{equation}\n    D(\\nu)_n \\approx \\frac{1}{2}x - \\frac{1}{2}\\log x + \\log\\lambda\n\\end{equation}\n\nwhile $x \\gg 1$, $\\frac{1}{2}x - \\frac{1}{2}\\log x \\gg 1$, the sign of $D(\\nu)_n$ is defined by the relative magnitude of $\\frac{1}{2}x - \\frac{1}{2}\\log x$ and $\\log\\lambda$. \n\n\\subsubsection{Flat approximation}\n\n\\begin{equation}\n\\begin{aligned}\n    \\bm{\\Sigma}_z &= \\frac{1}{M}\\sigma_q^2\\sum_i^N z_i\\bm{J}_M + \\sigma_\\epsilon^2\\bm{I}_M = \\frac{\\sigma_q^2n}{M}\\bm{J}_M+\\sigma_\\epsilon^2\\bm{I}_M \\\\\n    \\det\\bm{\\Sigma}_z &= (\\sigma_\\epsilon^2 + \\sigma_q^2\\sum_i^N z_i)\\sigma_\\epsilon^{2(M-1)} = (\\sigma_\\epsilon^2 + \\sigma_q^2n)\\sigma_\\epsilon^{2(M-1)} \\\\\n    \\bm{\\Sigma}_z^{-1} &= \\frac{1}{\\sigma_\\epsilon^2}\\left(\\bm{I}_M - \\frac{1}{M}\\frac{\\sigma_q^2\\sum_i^N z_i}{\\sigma_q^2\\sum_i^N z_i+\\sigma_\\epsilon^2}\\bm{J}_M\\right) = \\frac{1}{\\sigma_\\epsilon^2}\\left(\\bm{I}_M - \\frac{1}{M}\\frac{1}{1+\\frac{\\sigma_\\epsilon^2}{\\sigma_q^2n}}\\bm{J}_M\\right)\n\\end{aligned}\n\\end{equation}\n\nset $M^\\ast = M(1+\\frac{\\sigma_\\epsilon^2}{\\sigma_q^2n})$, regarding to $\\sigma_q\\gg\\sigma_\\epsilon$, thus $M^\\ast\\approx M$, and\n\n\\begin{equation}\n    \\bm{\\Sigma}_z^{-1} = \\frac{1}{\\sigma_\\epsilon^2}\\left(\\bm{I}_M - \\frac{1}{M^\\ast}\\bm{J}_M\\right).\n\\end{equation}\n\nThus, \n\n\\begin{equation}\n\\begin{aligned}\n    -2\\nu =& \\frac{1}{\\sigma_\\epsilon^2}\\left[\\sum_i^M\\left(w_i-\\frac{n}{\\sqrt{M}}\\right)^2-\\frac{1}{M^\\ast}\\left(\\sum_i^M w_i-n\\sqrt{M}\\right)^2\\right] \\\\\n    &+ \\log(\\sigma_q^2n+\\sigma_\\epsilon^2) - 2n\\log\\lambda - 2(N-n)\\log(1-\\lambda) + C.\n\\end{aligned}\n\\end{equation}\n\nAdditionally, \n\n\\begin{equation}\n\\begin{aligned}\n    \\left(w_i-\\frac{n}{\\sqrt{M}}\\right)^2 =& \\left(w_i - \\frac{N}{\\sqrt{M}}\\right)^2 + 2\\left(w_i - \\frac{N}{\\sqrt{M}}\\right)\\frac{N-n}{\\sqrt{M}} + \\frac{(N-n)^2}{M} \\\\\n    \\left(\\sum_i^M w_i-n\\sqrt{M}\\right)^2 =& \\left(\\sum_i^M w_i-N\\sqrt{M}\\right)^2 + 2\\left(\\sum_i^M w_i-N\\sqrt{M}\\right)(N-n)\\sqrt{M} + (N-n)^2M.\n\\end{aligned}\n\\end{equation}\n\nSome statistics we use below,\n\n\\begin{equation}\n\\begin{aligned}\n    \\sum_i^M\\frac{(w_i - \\frac{N}{\\sqrt{M}})^2}{\\frac{N}{\\sqrt{M}}\\sigma_q^2+\\sigma_\\epsilon^2} &\\sim \\chi^2(M) \\\\\n    \\frac{(\\sum_i^M w_i-N\\sqrt{M})^2}{M^{\\frac{3}{2}}N\\sigma_q^2+M\\sigma_\\epsilon^2} &\\sim \\chi^2(1).\n\\end{aligned}\n\\end{equation}\n\nCalculate expectation on distribution of $\\bm{w}$ and $\\bm{z}$ with $|K|=n$, \n\n\\begin{equation}\n\\begin{aligned}\n    -2E(\\nu)_n =& \\frac{1}{\\sigma_\\epsilon^2}\\left[\\left(N\\sqrt{M}\\sigma_q^2+(N-n)^2\\right)\\left(1-\\frac{M}{M^\\ast}\\right)+\\left(M-\\frac{M}{M^\\ast}\\right)\\sigma_\\epsilon^2\\right] \\\\\n    &+ \\log\\left(\\frac{\\sigma_q^2}{\\sigma_\\epsilon^2}n+1\\right) - 2n\\log\\lambda - 2(N-n)\\log(1-\\lambda) + C.\n\\end{aligned}\n\\end{equation}\n\nThus, \n\n\\begin{equation}\n\\begin{aligned}\n    E(\\nu)_n' =& -\\frac{1}{2}\\Biggl\\{\\frac{1}{\\sigma_\\epsilon^2}\\Bigl[2(n-N)\\left(1-\\frac{M}{M^\\ast}\\right) \\\\\n    &+\\left(N\\sqrt{M}\\sigma_q^2+(N-n)^2+\\sigma_\\epsilon^2\\right)\\frac{M}{M^{\\ast2}}M^{\\ast'}\\Bigr] +\\frac{1}{n+\\frac{\\sigma_\\epsilon^2}{\\sigma_q^2}}\\Biggr\\} + \\log\\lambda - \\log(1-\\lambda)\n\\end{aligned}\n\\end{equation}\nwhere $M^{\\ast'}=-\\frac{M\\sigma_\\epsilon^2}{\\sigma_q^2n^2}$. \n\nWhen $n=N$,\n\n\\begin{equation}\n\\begin{aligned}\n    E(\\nu)_n'|_N =& \\frac{1}{2}\\frac{N}{\\left(N+\\frac{\\sigma_\\epsilon^2}{\\sigma_q^2}\\right)^2}(\\sqrt{M}-1) + \\log\\lambda - \\log(1-\\lambda).\n\\end{aligned}\n\\end{equation}\n\nRemember that $M \\gg 1$, then,\n\n\\begin{equation}\n    C = \\frac{1}{2}\\frac{N}{\\left(N+\\frac{\\sigma_\\epsilon^2}{\\sigma_q^2}\\right)^2}(\\sqrt{M}-1) > 0\n\\end{equation}\n\nthe sign of $E(\\nu)_n'|_N$ is defined by the relative magnitude of $C$ and $\\log\\lambda$. \n\n\\subsection{Discussion}\n\nWhen the time bin is very thin, $\\log\\lambda \\ll 0$, $D(\\nu)_n < 0$. When Bernoulli approximation fails, $D(\\nu)_n > 0$. \n\nWhile we easonably assume $E(\\nu)_n$ is near its maximum when $n=N_\\mathrm{PE}$, considering the fact that RGS in FBMP has imperfect ergodicity, the bias is positive given $D(\\nu)_n > 0$ (or $E(\\nu)_n'|_N > 0$) as RGS does \\emph{not} stop immediately when $n=N_\\mathrm{PE}$. Given $D(\\nu)_n < 0$ (or $E(\\nu)_n'|_N < 0$), the bias is be negative. \n", "meta": {"hexsha": "29bbebd0170621d8068b8bb6835637fc98dd6484", "size": 8230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Note/Appendices.tex", "max_stars_repo_name": "heroxbd/waveform-analysis", "max_stars_repo_head_hexsha": "f4020783159980d184d3ca07692f125e0a70d56c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-08-03T19:59:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T08:11:31.000Z", "max_issues_repo_path": "Note/Appendices.tex", "max_issues_repo_name": "heroxbd/waveform-analysis", "max_issues_repo_head_hexsha": "f4020783159980d184d3ca07692f125e0a70d56c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2020-08-15T07:56:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T07:26:34.000Z", "max_forks_repo_path": "Note/Appendices.tex", "max_forks_repo_name": "heroxbd/waveform-analysis", "max_forks_repo_head_hexsha": "f4020783159980d184d3ca07692f125e0a70d56c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-08-03T20:01:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T01:50:02.000Z", "avg_line_length": 40.1463414634, "max_line_length": 346, "alphanum_fraction": 0.6174969623, "num_tokens": 3414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6021599057075814}}
{"text": "\\documentclass[12pt]{article}\n\\author{David Alves}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amsthm}\n\\usepackage{dirtytalk}\n\\usepackage[a4paper]{geometry}\n\\usepackage{forest}\n\\usepackage{listings}\n\\usepackage{mathtools}\n\\usepackage{nth}\n\\usepackage{relsize}\n\\usepackage{skak}\n\\usepackage{tikz}\n\\usepackage{tikz-qtree}\n\\usepackage{titling}\n\\usepackage{wrapfig}\n\\usepackage{xcolor}\n\n\\DeclarePairedDelimiter\\ceil{\\lceil}{\\rceil}\n\\DeclarePairedDelimiter\\floor{\\lfloor}{\\rfloor}\n\n\\usetikzlibrary{decorations.pathreplacing}\n\\usetikzlibrary{patterns}\n\n\\def\\multichoose#1#2{\\ensuremath{\\left(\\kern-.3em\\left(\\genfrac{}{}{0pt}{}{#1}{#2}\\right)\\kern-.3em\\right)}}\n\n\\newcommand{\\ts}[1]{\\textsuperscript{#1}}\n\n\\newcommand{\\ProblemStatement}[1]{\n\\subsection*{Problem Statement}\n#1\n\\subsection*{Solution}\n}\n\n% If uncommented, next line hides problem statements \n%\\renewcommand{\\ProblemStatement}[1]{}\n\n\n\\title{Math 142 Problem Set 10}\n\\author{David Alves}\n\\date{2016-11-03}\n\n\\begin{document}\n\\pagenumbering{gobble}\n\n\\begin{center}\n\\large \\thetitle \\\\\n\\theauthor \\\\\n\\thedate\n\\end{center}\n\n\\subsection*{Sources}\n\n    \\begin{itemize}\n    \\item http://tex.stackexchange.com and https://www.sharelatex.com for help with \\LaTeX\n    \\end{itemize}\n\n\\section{Stirling Numbers}\n\\ProblemStatement{\nFor general $n$, what are the Stirling numbers of the second kind $S(n,0)$, $S(n,1)$, and $S(n,2)$?\n}\n\nThe Stirling number of the second kind $S(n,k)$ can be defined as the number of ways to put $n$ distinguishable balls into $k$ indistinguishable bins such that each bin contains at least one ball. \n\n\\subsubsection{$n$ Balls into Zero Bins}\n\\[\n    S(n, 0) = \n    \\begin{cases}\n        1&: n=0\\\\\n        0&: n \\ge 1\n    \\end{cases}\n\\]\n\nFor $S(0,0)$, there is one way to put zero balls into zero bins such that all bins have at least one ball (it is vacuously true that all zero bins contain at least one ball). For one or more balls, it is impossible to place them into bins since there are zero bins, therefore $S(n, 0) = 0: n \\ge 1$.\n\n\\subsubsection{$n$ Balls into One Bin}\n\\[\n    S(n, 1) = \n    \\begin{cases}\n        0&: n=0\\\\\n        1&: n \\ge 1\n    \\end{cases}\n\\]\n\nFor $S(0, 1)$, there is no way to put zero balls into one bin such that the bin contains at least one ball. For $S(n, 1): n \\ge 1$, there is one choice for each ball, so there is one choice by the product principle.\n\n\\subsubsection{$n$ Balls into Two Bins}\n\\[\n    S(n, 2) = \n    \\begin{cases}\n        0&: n=0, 1\\\\\n        2^{n-1}-1&: n \\ge 2\n    \\end{cases}\n\\]\n\nFor $S(0, 2)$ and $S(1, 2)$, there are no ways to put the balls into the bins such that each bin contains at least one ball because there are not enough balls. For $S(n, 2): n \\ge 2$, there is only one choice for the first ball because the bins are indistinguishable. After placing the first ball, the bins become distinguishable. Label the bins $A$, which contains the first ball, and $B$, which does not. Thus we must place the remaining $n-1$ balls into 2 distinguishable bins. There are $2^{n-1}$ ways to do so by the product principle. Out of those $2^{n-1}$ configurations, there is exactly one which is not legal: the one which places all $n-1$ balls into $A$, since that leaves $B$ empty. Every other configuration places at least one ball into $B$, and $A$ already has one ball. Thus there are $2^{n-1}-1$ ways to place $n$ balls into 2 bins for $n >= 2$ such that each bin contains at least one ball.\n\n\\section{Counting Primes}\n\\ProblemStatement{\nFind the number of primes less than or equal to 111. (Hint: the number of integers 1 through $n$ divisible by $k$ is $\\floor{\\frac{n}{k}}$. You can take it for granted that all composite numbers less than 111 are divisible by at least one of 2, 3, 5 or 7\n}\n\nThere are 29 primes in $[1, 111]$.\n\n\\begin{proof}\nWe solve this using the inclusion-exclusion principle. Let $D_n$ be the set of positive integers less than or equal to 111 that are divisible by $n$. By the inclusion-exclusion principle, we know that \n\n\\newcommand{\\dlist}[1]{D_{#1}}\n\\begin{multline*}\n    |\\dlist{2} \\cup \\dlist{3} \\cup \\dlist{5} \\cup \\dlist{7}| = |\\dlist{2}| + |\\dlist{3}| + |\\dlist{5}| + |\\dlist{7}|\\\\ \n    -|\\dlist{2} \\cap \\dlist{3}| - |\\dlist{2} \\cap \\dlist{5}| - |\\dlist{2} \\cap \\dlist{7}| - |\\dlist{3} \\cap \\dlist{5}| - |\\dlist{3} \\cap \\dlist{7}| - |\\dlist{5} \\cap \\dlist{7}|\\\\\n    +|\\dlist{2} \\cap \\dlist{3} \\cap \\dlist{5}| + |\\dlist{2} \\cap \\dlist{3} \\cap \\dlist{7}| + |\\dlist{2} \\cap \\dlist{5} \\cap \\dlist{7}| + |\\dlist{3} \\cap \\dlist{5} \\cap \\dlist{7}|\\\\\n    -|\\dlist{2} \\cap \\dlist{3} \\cap \\dlist{5} \\cap \\dlist{7}|\n\\end{multline*}\n\nThe size of an individual set $|D_k| = \\floor{\\frac{111}{k}}$. The intersection of two sets $D_i$ and $D_j$ is all numbers divisible by both, which is therefore $|D_i \\cap D_j| = |D_{ij}| = \\floor{\\frac{111}{ij}}$. Thus the above equation simplifies to \n\n\\newcommand{\\dfloor}[1]{\\floor*{\\frac{111}{#1}}}\n\\begin{multline*}\n    |\\dlist{2} \\cup \\dlist{3} \\cup \\dlist{5} \\cup \\dlist{7}| = \\dfloor{2} + \\dfloor{3} + \\dfloor{5} + \\dfloor{7}\\\\ \n    -\\dfloor{2\\times3} - \\dfloor{2\\times5} - \\dfloor{2\\times7} - \\dfloor{3\\times5} - \\dfloor{3\\times7} - \\dfloor{5\\times7}\\\\\n    +\\dfloor{2\\times3\\times5} + \\dfloor{2\\times3\\times7} + \\dfloor{2\\times5\\times7} + \\dfloor{3\\times5\\times7} -\\dfloor{2\\times3\\times5\\times7}\n\\end{multline*}\n\n\\begin{multline*}\n    |\\dlist{2} \\cup \\dlist{3} \\cup \\dlist{5} \\cup \\dlist{7}| = 55 + 37 + 22 + 15 - 18 - 11 - 7 - 7 - 5 - 3\\\\\n    +3 + 2 + 1 + 1 - 0 = 85\n\\end{multline*}\n\nThus there are 85 numbers less than or equal to 111 that are divisible by 2, 3, 5, or 7, leaving 111-85=26 numbers which are not. One of these 26 numbers is 1, which is defined as not prime, leaving 25 which are primes. Additionally, the numbers 2, 3, 5 and 7 are all prime but are in $\\dlist{2} \\cup \\dlist{3} \\cup \\dlist{5} \\cup \\dlist{7}$. Thus we have $26-1+4 = 29$ primes in $[1, 111]$.\n\\end{proof}\n\n\\section{Spider Socks}\n\\ProblemStatement{\nA spider has 8 different feet, 8 different socks, and 8 different shoes. Find the number of orders that the spider can put on socks and shoes such that all socks and shoes are put on once and the $n\\ts{th}$ sock is put on before the $n\\ts{th}$ shoe for all $n$. Note that any sock can go on any foot and any shoe can go on any foot.}\nThere are $\\frac{8!^216!}{2^8}$ different valid orders. \n\n\\begin{proof}\nLet the $n\\ts{th}$ shoe be $S_n$ and the $n\\ts{th}$ sock be $O_n$. Suppose we wanted to always place the $n\\ts{th}$ sock onto the $n\\ts{th}$ foot and the $n\\ts{th}$ shoe onto the $n\\ts{th}$ foot. Then we would want to find all lists consisting of the elements $S_1, S_2, \\dots, S_8$, $O_1, O_2, \\dots, O_8$ once each in some order such that $O_n$ comes before $S_n$ for all $n$. There are $16!$ permutations of the 16 elements in the list. We then need to divide by two for each $O_i, S_i$ pair by the quotient principle since regardless of whether the sock or shoe comes first when considering that pair, we only want to count one relative ordering of that sock and shoe. This gives a a total of $\\frac{16!}{2^8}$ valid orders where the positions of the socks and shoes are fixed. We then multiply by $8!^2$ to account for all the permutations of which sock goes on which foot and which shoe goes on which foot, giving a total of $\\frac{8!^216!}{2^8}$.\n\\end{proof}\n\n\n\\section{Five Coins}\n\\ProblemStatement{\nYou and your friend flip 5 fair and independent coins in a row. If any two consecutive coins are HT in order, you score a \\say{hit}. If any two consecutive coins are TT in order, your friend scores a \\say{hit}. What's the probability that you score one or more hits and your friend does not? What's the probability that you and your friend both score one or more hits?\n}\n\nThe probability that you and your friend both \\say{hit} and the probability that you \\say{hit} while your friend does not are both $\\frac{21}{32}$.\n\n\\begin{proof}\nThe figure below systematically enumerates all possible sequences of flips. Each state consists of a sequence so far, with the upper and lower outgoing edges indicating heads and tails on the next flip, respectively. States in bold indicate you have gotten at least one \\say{hit} so far, while underlined states indicate that your friend has gotten at least one \\say{hit} so far. After 5 flips, there are $2^5 = 32$ outcomes. There are 21 outcomes where you have gotten a \\say{hit} and your friend has not, and 21 outcomes where you and your friend have both gotten a \\say{hit}. Since the five coins are independent and fair, the 32 possible outcomes are equally likely and thus each have probability $\\frac{1}{32}$. Since the outcomes are disjoint, the probability of any of them happening is the sum of their individual probabilities, giving $\\frac{21}{32}$ as the total. Thus the probability that you and your friend both \\say{hit} and the probability that you \\say{hit} while your friend does not are both $\\frac{21}{32}$.\n\\end{proof}\n\n\\scalebox{0.70}{\n\\begin{forest}\n  for tree={\n    grow'=0,\n    child anchor=west,\n    parent anchor=east,\n    anchor=west,\n    calign=center,\n    inner ysep=0.0pt,\n    fit=band,\n    before computing xy={l=110pt},\n  }    \n[Initial State\n[$H$\n    [$HH$\n        [$HHH$\n            [$HHHH$\n                [$HHHHH$ ]\n                [$\\textbf{HHHHT}$ ]\n            ]\n            [$\\textbf{HHHT}$\n                [$\\textbf{HHHTH}$ ]\n                [$\\underline{\\textbf{HHHTT}}$ ]\n            ]\n        ]\n        [$\\textbf{HHT}$\n            [$\\textbf{HHTH}$\n                [$\\textbf{HHTHH}$ ]\n                [$\\textbf{HHTHT}$ ]\n            ]\n            [$\\underline{\\textbf{HHTT}}$\n                [$\\underline{\\textbf{HHTTH}}$ ]\n                [$\\underline{\\textbf{HHTTT}}$ ]\n            ]\n        ]\n    ]\n    [$\\textbf{HT}$\n        [$\\textbf{HTH}$\n            [$\\textbf{HTHH}$\n                [$\\textbf{HTHHH}$ ]\n                [$\\textbf{HTHHT}$ ]\n            ]\n            [$\\textbf{HTHT}$\n                [$\\textbf{HTHTH}$ ]\n                [$\\underline{\\textbf{HTHTT}}$ ]\n            ]\n        ]\n        [$\\underline{\\textbf{HTT}}$\n            [$\\underline{\\textbf{HTTH}}$\n                [$\\underline{\\textbf{HTTHH}}$ ]\n                [$\\underline{\\textbf{HTTHT}}$ ]\n            ]\n            [$\\underline{\\textbf{HTTT}}$\n                [$\\underline{\\textbf{HTTTH}}$ ]\n                [$\\underline{\\textbf{HTTTT}}$ ]\n            ]\n        ]\n    ]\n]\n[$T$\n    [$TH$\n        [$THH$\n            [$THHH$\n                [$THHHH$ ]\n                [$\\textbf{THHHT}$ ]\n            ]\n            [$\\textbf{THHT}$\n                [$\\textbf{THHTH}$ ]\n                [$\\underline{\\textbf{THHTT}}$ ]\n            ]\n        ]\n        [$\\textbf{THT}$\n            [$\\textbf{THTH}$\n                [$\\textbf{THTHH}$ ]\n                [$\\textbf{THTHT}$ ]\n            ]\n            [$\\underline{\\textbf{THTT}}$\n                [$\\underline{\\textbf{THTTH}}$ ]\n                [$\\underline{\\textbf{THTTT}}$ ]\n            ]\n        ]\n    ]\n    [$\\underline{TT}$\n        [$\\underline{TTH}$\n            [$\\underline{TTHH}$\n                [$\\underline{TTHHH}$ ]\n                [$\\underline{\\textbf{TTHHT}}$ ]\n            ]\n            [$\\underline{\\textbf{TTHT}}$\n                [$\\underline{\\textbf{TTHTH}}$ ]\n                [$\\underline{\\textbf{TTHTT}}$ ]\n            ]\n        ]\n        [$\\underline{TTT}$\n            [$\\underline{TTTH}$\n                [$\\underline{TTTHH}$ ]\n                [$\\underline{\\textbf{TTTHT}}$ ]\n            ]\n            [$\\underline{TTTT}$\n                [$\\underline{TTTTH}$ ]\n                [$\\underline{TTTTT}$ ]\n            ]\n        ]\n    ]\n]\n]\n\\end{forest}\n}\n\n\\section{Choosing Compositions}\n\\ProblemStatement{\nProve that for any fixed positive integer $k$, each positive integer $n$ has a unique representation in the form \n\\[\n    n = \\binom{b_1}{1} + \\binom{b_2}{2} + \\binom{b_3}{3} +\\dots + \\binom{b_k}{k} \n\\]\nwhere $0 \\le b_1 < b_2 < \\dots < b_k$.\n}\n\nWe prove this by providing a method to construct such a representation given $n$ and $k$.\nWe know that $\\binom{b_k}{k} \\le n$ because each of the terms $\\binom{b_1}{1} + \\binom{b_2}{2} + \\binom{b_3}{3} +\\dots + \\binom{b_{k-1}}{k-1}$ is greater than or equal to zero, therefore their sum must be greater than or equal to zero. Let $c_k$ be the largest integer such that $\\binom{c_k}{k} \\le n$. \n\nWe prove that $b_k = c_k$ by contradiction. Assume $b_k$ = $c_k - 1$. Then the largest possible value for $b_{k-1}$ is $c_k-2$, the largest possible value for $b_{k-2}$ is $c_k-3$, etc. This gives $\\sum_{i=1}^{k} \\binom{c_k-i}{k+1-i} \\ge n$. We know that the sum of diagonal elements in Pascal's triangle is $\\binom{n}{k} = \\sum_{i=1}^{n} \\binom{n-i}{k+1-i}$. Thus we have\n\\begin{align*}\n    \\binom{c_k}{k} &= \\left(\\sum_{i=1}^{k} \\binom{c_k-i}{k+1-i}\\right)+\\left(\\sum_{i=k+1}^{n} \\binom{c_k-i}{k+1-i}\\right)\\\\\n    \\binom{c_k}{k} - \\left(\\sum_{i=k+1}^{n} \\binom{c_k-i}{k+1-i}\\right)&= \\left(\\sum_{i=1}^{k} \\binom{c_k-i}{k+1-i}\\right) \\ge n\\\\\n    \\binom{c_k}{k} - \\left(\\sum_{i=k+1}^{n} \\binom{c_k-i}{k+1-i}\\right)&\\ge n\\\\\n    \\binom{c_k}{k} &\\ge n + \\left(\\sum_{i=k+1}^{n} \\binom{c_k-i}{k+1-i}\\right)\n\\end{align*}\n$\\sum_{i=k+1}^{n} \\binom{c_k-i}{k+1-i}$ (need to demonstrate this) is positive, therefore this contradicts our definition of $c_k \\le n$. Thus our assumption must be false, and $b_k$ must be $c_k$ since the maximal value when $b_k < c_k$ is too low. Therefore we know $b_k$ = $c_k$ and can apply the same logic recursively for $b_{k-1} = c_{k-1}$, etc. all the way down to $b_1$. Thus we have shown that there is only one choice for each $b_x$ term, so the solution if it exists is unique.\n\n(This proves uniqueness but not existence. Unfortunately I don't have time to finish this proof.) \n\n\n\\section{Time Spent \\& Thoughts}\nProblems 1-4 weren't very hard but some of them took a long time to write up correctly. I was very unsure about how we were supposed to write up 4 -- are we supposed to start from first principles like the definition of probability measure, or is it ok to gloss over a lot of intuitive stuff? Since we haven't had a probability problem before I wasn't really sure what to do. I probably spent about 10 hours on 1-4.\nProblem 5 was very hard but was interesting. I wrote a program to check for counterexamples and then reworked it to print out how various numbers are decomposed which helped lead me towards a solution, but wasn't able to finish the proof.\n\\end{document}\n", "meta": {"hexsha": "f99fa0d85de2327cd7168f251d3f125144514356", "size": 14417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math142_ps10.tex", "max_stars_repo_name": "dalves/combinatorics", "max_stars_repo_head_hexsha": "059a05b548401df59099a6ba93109f736e0b9ed7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-20T14:26:36.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-20T14:26:36.000Z", "max_issues_repo_path": "math142_ps10.tex", "max_issues_repo_name": "dalves/combinatorics", "max_issues_repo_head_hexsha": "059a05b548401df59099a6ba93109f736e0b9ed7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math142_ps10.tex", "max_forks_repo_name": "dalves/combinatorics", "max_forks_repo_head_hexsha": "059a05b548401df59099a6ba93109f736e0b9ed7", "max_forks_repo_licenses": ["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.204778157, "max_line_length": 1026, "alphanum_fraction": 0.6317541791, "num_tokens": 4638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.6021599020795962}}
{"text": "\\subsection{Preliminaries}\n  We now move on to some preliminary definitions and results.\n  \\subimport{common/definitions/}{trustreduction.tex}\n\n  \\subimport{common/theorems/}{saturationtheorem.tex}\n  \\subimport{common/proofsketches/}{saturationproofsketch.tex}\n\n  \\subimport{common/corollaries/}{trusttransfercorollary.tex}\n  \\subimport{common/proofs/}{trusttransferproof.tex}\n\n  \\subimport{common/theorems/}{invtrustrednaivetheorem.tex}\n  \\subimport{common/proofs/}{invtrustrednaiveproof.tex}\n\n  Until now $MaxFlow$ has been viewed purely as an algorithm. This algorithm is not guaranteed to always return the same\n  flow configuration when executed muliple times on the same graph. However, the corresponding flow value, $maxFlow$, is\n  always the same. Thus $maxFlow$ can be also viewed as a function from a matrix of capacities to a non-negative real number.\n  Under this perspective, we prove the following theorem. Let $\\mathcal{C}$ be the family of all capacity matrices\n  $C = [c_{vw}]_{\\mathcal{V} \\times \\mathcal{V}}$.\n  \\subimport{common/theorems/}{maxflowcontinuitytheorem.tex}\n  \\subimport{common/proofsketches/}{maxflowcontinuityproofsketch.tex}\n\n", "meta": {"hexsha": "b850050fb423665f4b05a261c965d97053b7d4d2", "size": 1161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "may31deliverable/riskinvalgs/preliminaries.tex", "max_stars_repo_name": "OrfeasLitos/TrustNet", "max_stars_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-03-15T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T14:07:45.000Z", "max_issues_repo_path": "may31deliverable/riskinvalgs/preliminaries.tex", "max_issues_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_issues_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-03-07T12:25:26.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-31T14:42:20.000Z", "max_forks_repo_path": "may31deliverable/riskinvalgs/preliminaries.tex", "max_forks_repo_name": "OrfeasLitos/DecentralisedTrustNetwork", "max_forks_repo_head_hexsha": "dfd45afb78ba92d7c0b0a64222aaf173e9627c09", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-03-07T10:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-28T06:32:33.000Z", "avg_line_length": 52.7727272727, "max_line_length": 125, "alphanum_fraction": 0.7846683893, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6021304577351696}}
{"text": "% !TEX program = pdflatex\n% !BIB program = bibtex\n% !TEX enableSynctex = true\n\n\\documentclass[12pt]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{setspace}\n\\onehalfspacing\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{appendix}\n\\renewcommand{\\thesection}{\\arabic{section}} \n\\renewcommand{\\thesubsection}{\\thesection.\\arabic{subsection}}\n\\usepackage{pdflscape}\n\\usepackage{color}   %May be necessary if you want to color links\n\\usepackage[colorlinks = true,\n            linkcolor = blue,\n            urlcolor  = blue,\n            citecolor = blue,\n            anchorcolor = blue]{hyperref}\n\\hypersetup{\n    colorlinks=true, %set true if you want colored links\n    linktoc=all,     %set to all if you want both sections and subsections linked\n    linkcolor=blue,  %choose some color if you want links to stand out\n}\n\\usepackage{algpseudocode}\n\\usepackage{algorithm}\n\\usepackage{bbm}\n\n%For margins\n\\textheight = 22.62cm\n\\textwidth = 15.92cm\n\\topmargin = -0.54cm\n\\oddsidemargin= 0cm\n\\parindent=05mm\n\\usepackage{dashrule}\n\\usepackage{booktabs}\n\\usepackage{bbold}\n\\usepackage{amsmath}\n\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{remark}{Remark}\n\\newtheorem{definition}[theorem]{Definition}\n\\DeclareMathOperator{\\trace}{trace}\n\\DeclareMathOperator{\\Var}{Var}\n\n%Title Definition\n\\title{{\\Large \\vspace{-5em} \\textbf{KSS Bias Correction : Outline} }}\n\\author{}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\\section{Introduction}\nConsider a linear model with nonrandom $x_i \\in \\mathbbm{R}^k$. \n\n\\begin{align*}\n    y_i = x_i' \\beta + \\varepsilon_i\n\\end{align*}\nwhere $i = 1,\\dots,n$ and $\\varepsilon \\sim N(0, \\sigma_i^2)$.\n\n\\begin{definition}\nA (co)variance component is a quadratic form $\\theta = \\beta' A \\beta $, where $A$ is a $k\\times k$ matrix. When A is positive semi-definite we call it a variance component and when A is non-definite we call it covariance component.\n\\end{definition}\n\n\\begin{remark}\nThe plug-in estimator for the (co)variance component $\\theta$ is biased. In particular, we can write \n\n\\begin{align*}\n    \\mathbbm{E}(\\hat{\\theta}) = \\theta + \\underbrace{ \\trace(A \\Var(\\hat{\\beta}))}_\\text{bias}\n\\end{align*}\n\n\\noindent And the bias term can be written as $\\sum_{i=1}^n B_{ii} \\sigma_i^2$, where $B_{ii} = x_i' S_{xx}^{-1} A S_{xx}^{-1} x_i  $, $S_{xx} = \\sum_{i=1}^n x_i x_i'$.\n\\end{remark}\n\n\\begin{remark}\nThe previous remark suggest that we can estimate the bias as\n\n\\begin{align*}\n    \\hat{bias} &= \\sum_{i=1}^n B_{ii} \\hat{\\sigma_i}^2 \\\\    \n    \\hat{\\sigma_i}^2 &= y_i (y_i - x_i' \\hat{\\beta}_{-i}) = y_i \\frac{(y_i - x_i ' \\hat{\\beta})}{1-P_{ii}}\\\\\n\\end{align*}\nwhere $P_{ii}$ is the statistical leverage of observation $i$, and it's defined as $P_{ii} := (X (X'X) X')_{ii}$.\n\n\\end{remark}\n\n\\clearpage\n\\begin{remark}\nIf we compute $\\hat{\\beta}$, $B_{ii}$ and $P_{ii}$ then we can compute the ``bias-corrected'' estimator of the (co)variance components\n\n\\begin{align*}\n    \\hat{\\theta}_{KSS} =  \\hat{\\beta}' A \\hat{\\beta} - \\sum_{i=1}^n B_{ii} y_i \\frac{(y_i - x_i ' \\hat{\\beta})}{1-P_{ii}}\n\\end{align*}\n\\end{remark}\n\n\\vspace{0.5cm}\nOur model of interest is the two-way fixed effects model given by\n\n\\begin{align*}\ny_{gt} = \\alpha_{g} + \\psi_{j(g,t} + x_{gt}' \\delta + \\varepsilon_{gt}\n\\end{align*}\n\n\n\\noindent where $g \\in \\{1,\\dots,N\\}$ denotes the worker identity, $t$ denotes the time period, $j(g,t) \\in \\{1,\\dots,J\\}$ denotes the firm of worker $g$ at time $t$. Moreover, we can index the observations using $i$ instead of $g,t$ and we will denote $n$ as the total number of observations. \n\nThe (co)variance components in this context take the form \n\n\\begin{align*}\n    \\sigma_{\\psi}^2 &= \\frac{1}{n} \\sum_{g=1}^{N} \\sum_{t=1}^{T_g} (\\psi_{j(g,t)} - \\Bar{\\psi})^2  \\\\\n    \\sigma_{\\alpha, \\psi}^2 &= \\frac{1}{n} \\sum_{g=1}^{N} \\sum_{t=1}^{T_g} (\\psi_{j(g,t)} - \\Bar{\\psi}) \\alpha_g  \\\\\n    \\sigma_{\\alpha}^2 &= \\frac{1}{n} \\sum_{g=1}^{N} \\sum_{t=1}^{T_g} (\\alpha_{g} - \\Bar{\\alpha})^2   \\\\\n\\end{align*}\nwhere $\\Bar{\\psi} = \\frac{1}{n} \\sum_{g=1}^{N} \\sum_{t=1}^{T_g} \\psi_{j(g,t)}$. Let $f_i = (\\boldsymbol{1}_{\\{j(g,t)=1\\}},\\dots,\\boldsymbol{1}_{\\{j(g,t)=J\\}})'$ and $d_i = (\\boldsymbol{1}_{\\{g=1\\}},\\dots,\\boldsymbol{1}_{\\{g=N\\}})'$ . We can compute the (co)variance components in this model in quadratic forms using the following $A$ matrices\n\n\\begin{align*}\nA_{\\psi} = \\begin{bmatrix}\n0 & 0 & 0\\\\\n0 & A_{ff} & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{ff} = \\frac{1}{n} \\sum_{i=1}^n (f_i - \\Bar{f})(f_i - \\Bar{f})'\n\\end{align*}\n\n\\begin{align*}\nA_{\\alpha,\\psi} = \\begin{bmatrix}\n0 & A_{df} & 0\\\\\nA_{df}' & 0 & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{df} = \\frac{1}{n} \\sum_{i=1}^n (d_i - \\Bar{d})(f_i - \\Bar{f})'\n\\end{align*}\n\n\\begin{align*}\nA_{\\alpha} = \\begin{bmatrix}\nA_{dd} & 0 & 0\\\\\n0 & 0 & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{dd} = \\frac{1}{n} \\sum_{i=1}^n (d_i - \\Bar{d})(d_i - \\Bar{d})'\n\\end{align*}\n\n\n\n\\section{Matrix Form of the Model}\n\nDefine the dummy variable matrices\n\n\\begin{align*}\n    \\underbrace{D}_\\text{Worker Dummies} &= \\underbrace{\\begin{bmatrix} \\boldsymbol{1}_{\\{g=1\\}} \\iota_n \\dots \\boldsymbol{1}_{\\{g=N\\}} \\iota_n  \\end{bmatrix}}_\\text{One non-zero value per row at most} \\quad \\text{where} \\quad \\iota_n = (1, \\dots, 1)' \\in \\mathbbm{R}^n\n\\end{align*}\n\n\\begin{align*}\n    \\underbrace{F*S}_\\text{Firm Dummies} &= \\underbrace{\\begin{bmatrix} \\boldsymbol{1}_{\\{j(g,t)=1\\}} \\iota_n \\dots \\boldsymbol{1}_{\\{j(g,t)=J\\}} \\iota_n  \\end{bmatrix}}_\\text{One non-zero value per row at most} * \\underbrace{\\begin{bmatrix} I_{J-1} & 0 \\\\ 0 & 0 \\end{bmatrix}}_\\text{Normalize last firm effect to 0}\n    \\quad \\text{where} \\quad I_{J-1}:= \\text{identity matrix}\n\\end{align*}\n\n\n\\begin{align*}\n    \\underbrace{C}_\\text{Control Variables} &= \\begin{bmatrix} x_1' \\\\ \\vdots \\\\ x_n'  \\end{bmatrix}\n\\end{align*}\n\nThen we can write the model in matrix form as\n\n \\begin{align*}\n     Y &= \\begin{bmatrix} D & F*S & C \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\ \\psi \\\\ \\delta \\end{bmatrix} + \\varepsilon\\\\\n     &= X \\beta + + \\varepsilon\n\\end{align*}\n          \nAnd we can estimate $\\beta$ by solving the least-squares problem, and notice that the design matrix, $X$, is very sparse based on the definitions of $D$ and $F*S$.\n\n\n\n\\section{Computation of $B_{ii}$ and $P_{ii}$}\n\nIt can be shown that \n\n\\begin{align*}\n    P_{ii} = x_i' S_{xx}^{-1} x_i \\quad \\text{and} \\quad B_{ii} = x_i' S_{xx}^{-1} A  S_{xx}^{-1} x_i\n\\end{align*}\n\n\\noindent But in practice the computation of $S_{xx}^{-1}$ can be difficult given the high dimension of parameters in the model. The approach taken in KSS is to avoid the computation of this inverse and instead compute \n\n\\begin{align*}\n    z_i^{exact} = S_{xx}^{-1} x_i \\quad \\text{for each} \\quad i=1,\\dots,n\n\\end{align*}\n\nIn other words, we solve separately for each column of $Z$ in the following system\n\n\\begin{align*}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{exact}}_{k\\times n}  = \\underbrace{X'}_{k\\times n}\n\\end{align*}\n\n\\noindent With that solution we compute $P_{ii} = x_i' z_i^{exact}$ and $B_{ii} = {z_i^{exact}}' A z_i^{exact}$\n\n\n\\begin{remark}\nExact computation can be infeasible given the dimensionality of the problem. The authors propose a dimension reduction via Rademacher matrices, also known as Johnson-Lindenstrauss Approximation (JLA). In particular, it consists on transforming the system so that we only require to solve $p$ systems instead of $n$ systems, where $p$ can be significantly smaller than $n$.\n\nIn other words, we solve separately for each column of Z in the following system\n\n\\begin{align*}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{JLA}}_{k\\times p}  = \\underbrace{(R_p *X)'}_{k\\times p}\n\\end{align*}\n\n\n\\end{remark}\n\n\\includegraphics[scale=0.7]{JLA_algorithm.jpg}\n\n\\begin{remark}\nWhen there are no controls in the design matrix, the model simplifies to\n\\begin{align*}\n    X = \\begin{bmatrix} D & F*S \\end{bmatrix} \\quad \\beta = \\begin{bmatrix} \\alpha \\\\ \\psi \\end{bmatrix} \n\\end{align*}\n\n\\noindent Moreover, there's no loss of generality of rewriting as\n\\begin{align*}\n    X = \\begin{bmatrix} D & -F*S \\end{bmatrix} \\quad \\beta = \\begin{bmatrix} \\alpha \\\\ -\\psi \\end{bmatrix} \n\\end{align*}\n\n\\noindent If we do this $X'X$ is symmetric and diagonally dominant, and the normal equations can be solved as a Laplacian system. This is where the preconditioner \\textit{CMG} comes into play in the code.\n\n\n\\end{remark}\n\n\n\\section{Leave-One-Out for Clusters}\n\nWe can extend this framework to allow for leave-out estimation of clusters of observations. Suppose there are $c\\in \\{1,C\\}$ clusters of $n_c$ observations. We can redefine the model as follows\n\n\\begin{align*}\n    y_c = X_c \\quad \\beta + \\varepsilon_c \n\\end{align*}\n\n\\begin{align*}\n    y_c = \\begin{bmatrix} y_{c,1} \\\\ \\vdots \\\\ y_{c,n_c}  \\end{bmatrix} \\quad X_c = \\begin{bmatrix} x_{c,1}' \\\\ \\vdots \\\\ x_{c,n_c}'  \\end{bmatrix} \\quad \\varepsilon_c = \\begin{bmatrix} \\varepsilon_{c,1} \\\\ \\vdots \\\\ \\varepsilon_{c,n_c}  \\end{bmatrix} \n\\end{align*}\n\nIn this case, we can define an analogue for the bias corrected estimator\n\n\\begin{align*}\n    \\hat{\\theta}_{KSS} =  \\hat{\\beta}' A \\hat{\\beta} - \\sum_{i=c}^C y_c' B_c (1- P_c)^{-1} (y_c - X_c   \\hat{\\beta})\n\\end{align*}\n\nwhere\n\n\\begin{align*}\n    P_c = X_c S_{xx}^{-1} X_c' = \\underbrace{ \\begin{bmatrix} x_{c,1}' S_{xx}^{-1}  x_{c,1} & \\dots & x_{c,1}' S_{xx}^{-1}  x_{c,n_c}  \\\\ \\vdots & \\vdots & \\vdots \\\\ x_{c,n_c}' S_{xx}^{-1}  x_{c,1} & \\dots & x_{c,1}' S_{xx}^{-1}  x_{n_c,n_c} \\end{bmatrix} }_\\text{From symmetry we only need to compute upper or lower triangular half }\n\\end{align*}\n\n\\begin{align*}\n    B_c = X_c S_{xx}^{-1} A S_{xx}^{-1} X_c' = \\underbrace{ \\begin{bmatrix} x_{c,1}' S_{xx}^{-1} A S_{xx}^{-1} x_{c,1} & \\dots & x_{c,1}' S_{xx}^{-1} A S_{xx}^{-1} x_{c,n_c}  \\\\ \\vdots & \\vdots & \\vdots \\\\ x_{c,n_c}' S_{xx}^{-1} A S_{xx}^{-1}  x_{c,1} & \\dots & x_{c,1}' S_{xx}^{-1} A S_{xx}^{-1}  x_{n_c,n_c} \\end{bmatrix} }_\\text{From symmetry we only need to compute upper or lower triangular half }\n\\end{align*}\n\nNow, we can solve $M$ systems of equations and solve for\n \\begin{align*}\n     z_{c,l}^{exact} = S_{xx}^{-1} x_{c,l} \\quad \\text{where} \\quad c\\in\\{1,\\dots,C\\} \\quad and \\quad l\\in\\{1,\\dots,n_c\\}\n \\end{align*}\n\nThe function \\textit{index\\_constr()} is the one in charge of computing which observations belong to the same cluster, so that we only need to compute $M$ numbers because of the symmetry of these matrices.\n\n\n\\clearpage\n\\appendix\n\n\\section{Simple Network Example}\n\nSuppose we are given the following dataset\n\n\\begin{table}[h!]\n    \\centering\n\\begin{tabular}{|c c c c|} \n \\hline\n id & year & firmid & outcome \\\\ [0.5ex] \n \\hline\\hline\n 1 & 1 & A &  0,1462\\\\ \n \\hline\n 1 & 2 & B & 0,2968 \\\\\n \\hline\n 2 & 1 & A &  0,5434\\\\\n \\hline\n 2 & 2 & A & 0,4326 \\\\\n \\hline\n 3 & 1 & A & 0,4648 \\\\\n \\hline\n 4 & 1 & A & 0,7306 \\\\\n \\hline\n 4 & 2 & B & 0,6192 \\\\\n \\hline\n 5 & 1 & B &  0,7534\\\\\n \\hline\n 5 & 2 & B &  0,0863\\\\\n \\hline\n6 & 1 & B &  0,3720\\\\\n \\hline\n 6 & 2 & C & 0,9580 \\\\ [1ex] \n \\hline\n\\end{tabular}\n\\end{table}\n\nWe can write the corresponding bipartite graph as follows\n\\begin{figure}[h!]\n    \\centering\n\\includegraphics[scale=0.7]{minimal_unit.png}    \\end{figure}\n\nThe function $\\textit{find\\_connected\\_set()}$ will find the largest connected component of this network, which corresponds to the whole network. This means that we can estimate the coefficients for every worker effect and every firm effect. \n\nNow, the function $\\textit{prunning\\_connected\\_set()}$ will prune the worker vertex that are articulation points and find the largest connected set until no more articulation points are found. In this network it corresponds to worker 6, so all of its edges will be pruned. Notice that this will disconnect firm C with the rest of the network. After that, the network is also the largest connected component with no more articulation points, so the function stops at that point. The network that we get as an output is the following\n\n\\begin{figure}[h!]\n    \\centering\n\\includegraphics[scale=0.7]{pruning.png}    \n\\end{figure}\n\nFinally, the function $\\textit{drop\\_single\\_obs()}$ will delete the workers that only have one observation(edge). In this particular case it corresponds to worker 3. We are required to prune these workers because once we leave-out that observation we can no longer estimate the coefficient for worker 3's effect. Therefore, the leave-one-out connected set is structured as follows\n\n\\begin{figure}[h!]\n    \\centering\n\\includegraphics[scale=0.6]{leaveoutnetwork.png}    \n\\end{figure}\n\nIf we allow ourselves to relabel the vertex of this network starting from the workers we get the following graph: \n\n\\begin{figure}[H]\n    \\centering\n\\includegraphics[scale=0.6]{leaveoutnetwork_relabeled.png}    \n\\end{figure}\n\n\nThe dummy matrix for workers (now relabeled as vertex 1,2,3,4) can be written as: \n\n\\begin{align*}\nD = \\begin{bmatrix}\n1 & 0 & 0& 0\\\\\n1 & 0 & 0& 0\\\\\n0 & 1 & 0& 0\\\\\n0 & 1 & 0& 0\\\\\n0 & 0 & 1& 0\\\\\n0 & 0 & 1& 0\\\\\n0 & 0 & 0& 1\\\\\n0 & 0 & 0& 1\\\\\n\\end{bmatrix} \n\\end{align*}\n\n\nThe dummy matrix for firms (now relabeled as vertex 5,6) can be written as: \n\n\\begin{align*}\nF = \\begin{bmatrix}\n1 & 0 \\\\\n0 & 1 \\\\\n1 & 0 \\\\\n1 & 0 \\\\\n1 & 0 \\\\\n0 & 1 \\\\\n0 & 1 \\\\\n\\end{bmatrix} \n\\end{align*}\n\nOur design matrix X corresponds to  $X = \\begin{bmatrix} D & -F \\end{bmatrix}$. Now notice what the operation $X'*X$ does : \n\n\\begin{align*}\nX'*X = \\begin{bmatrix}\n2 & 0 & 0 & 0 & -1 & -1 \\\\\n0 & 2 & 0 & 0 & -2 & 0 \\\\\n0 & 0 & 2 & 0 & -1 & -2 \\\\\n0 & 0 & 0 & 2 & 0 & 0 \\\\\n-1 & -2 & -1 & 0 & 4 & 0 \\\\\n-1 & 0 & -1 & -2 & 0 & 4 \\\\\n\\end{bmatrix} \n\\end{align*}\n\nNotice that the diagonals are the degree of each vertex, while the non diagonal elements represent the negative of the number of edges between vertex. Since this is a bipartite graph there are no edges between workers , or edges between firms.  In other words, the matrix $X'*X$ is a Laplacian matrix. When we normalize the last firm effects to zero it is equivalent to working with the Grounded Laplacian version of this, which eliminates the last row and column from $X'*X$.\n\n\n\n\\clearpage\n\\section{Linear Algebra Stuff}\n\nRecall that the model of interest is \n\\begin{align*}\ny_{gt} = \\alpha_{g} + \\psi_{j(g,t)} + x_{gt}' \\delta + \\varepsilon_{gt}\n\\end{align*}\n\nWe can define the following matrices \n\\begin{align*}\n    \\underbrace{D}_\\text{Worker Dummies} &= \\underbrace{\\begin{bmatrix} \\boldsymbol{1}_{\\{g=1\\}} \\iota_n \\dots \\boldsymbol{1}_{\\{g=N\\}} \\iota_n  \\end{bmatrix}}_\\text{One non-zero value per row at most} \\quad \\text{where} \\quad \\iota_n = (1, \\dots, 1) \\in \\mathbbm{R}^n\n\\end{align*}\n\n\\begin{align*}\n    \\underbrace{F*S}_\\text{Firm Dummies} &= \\underbrace{\\begin{bmatrix} \\boldsymbol{1}_{\\{j(g,t)=1\\}} \\iota_n \\dots \\boldsymbol{1}_{\\{j(g,t)=J\\}} \\iota_n  \\end{bmatrix}}_\\text{One non-zero value per row at most} * \\underbrace{\\begin{bmatrix} I_{J-1} & 0 \\\\ 0 & 0 \\end{bmatrix}}_\\text{Normalize last firm effect to 0}\n    \\quad \\text{where} \\quad I_{J-1}:= \\text{identity matrix}\n\\end{align*}\n\n\n\\begin{align*}\n    \\underbrace{C}_\\text{Control Variables} &= \\begin{bmatrix} x_1' \\\\ \\vdots \\\\ x_n'  \\end{bmatrix}\n\\end{align*}\n\nand write the model in matrix notation\n\n \\begin{align}\n     Y &= \\begin{bmatrix} D & F*S & C \\end{bmatrix} \\begin{bmatrix} \\alpha \\\\ \\psi \\\\ \\delta \\end{bmatrix} + \\varepsilon\\\\\n     &= X \\beta + + \\varepsilon\n     \\label{eq:matrix}\n\\end{align}\n          \nOur quadratic forms of interest are of the form $\\theta = \\beta' A \\beta$ for different choices of matrices $A$. Let $d_i = row_i(D) = (\\boldsymbol{1}_{\\{j(g,t)=1\\}}  \\dots \\boldsymbol{1}_{\\{j(g,t)=J\\}})'$,  $f_i = row_i(F) = (\\boldsymbol{1}_{\\{j(g,t)=1\\}} \\dots \\boldsymbol{1}_{\\{j(g,t)=J\\}} )'$, and denote $\\Bar{d}$ and $\\Bar{f}$ as the sample means. The $A$ matrices that we're interested in are the following three:\n\n\\begin{align*}\nA_{\\psi} = \\begin{bmatrix}\n0 & 0 & 0\\\\\n0 & A_{ff} & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{ff} = \\frac{1}{n} \\sum_{i=1}^n (f_i - \\Bar{f})(f_i - \\Bar{f})'\n\\end{align*}\n\n\\begin{align*}\nA_{\\alpha,\\psi} = \\begin{bmatrix}\n0 & A_{df} & 0\\\\\nA_{df}' & 0 & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{df} = \\frac{1}{n} \\sum_{i=1}^n (d_i - \\Bar{d})(f_i - \\Bar{f})'\n\\end{align*}\n\n\\begin{align*}\nA_{\\alpha} = \\begin{bmatrix}\nA_{dd} & 0 & 0\\\\\n0 & 0 & 0\\\\\n0 & 0 & 0\n\\end{bmatrix} \\quad \\text{where} \\quad A_{dd} = \\frac{1}{n} \\sum_{i=1}^n (d_i - \\Bar{d})(d_i - \\Bar{d})'\n\\end{align*}\n\nThe code uses the following representation to facilitate the computation of such matrices: \n\n\\begin{align*}\n    A_\\phi &= A_f'A_f\\\\\n    A_\\alpha &= A_d'A_d\\\\\n    A_{\\alpha,\\phi} &= \\frac{1}{2} (A_f'A_d + A_d'A_f)\n\\end{align*}\n\nwhere\n\n\\begin{equation}\n    A_f = n^{-1/2} \\begin{bmatrix}\n0 & f_1 - \\Bar{f} & 0\\\\\n0 & \\dots & 0\\\\\n0 & f_n - \\Bar{f} & 0 \n\\end{bmatrix}\n\\end{equation}\n\n\\begin{equation}\n    A_d = n^{-1/2} \\begin{bmatrix}\nd_1 - \\Bar{d} & 0 & 0\\\\\n\\dots & 0 & 0\\\\\nd_n - \\Bar{d} & 0 & 0 \n\\end{bmatrix}\n\\end{equation}\n\nThe systems that we want to solve are then the following\n\n\\begin{equation}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{exact}}_{k\\times n}  = \\underbrace{ X'}_{k\\times n}\n\\label{eq:exact}\n\\end{equation}\n\n\\begin{equation}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{JLA}^0}_{k\\times p}  = \\underbrace{(R_p *X)'}_{k\\times p}\n    \\label{eq:JLA1}\n\\end{equation}\n\n\\begin{equation}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{JLA}^1}_{k\\times p}  = \\underbrace{(R_b *A_f)'}_{k\\times p}\n        \\label{eq:JLA2}\n\\end{equation}\n\n\\begin{equation}\n    \\underbrace{S_{xx}}_{k\\times k} \\underbrace{Z_{JLA}^2}_{k\\times p}  = \\underbrace{(R_b *A_d)'}_{k\\times p}\n        \\label{eq:JLA3}\n\\end{equation}\n\n\\noindent where $S_{xx} = X'X$, and $R_b$, $R_p$ are two independent $p\\times n$ matrices with Rademacher entries. \n\n\n\\noindent Notice that the operation $R_b *A_f$ is equivalent to \"de-meaning\" the Rademacher matrix instead of the $A$ matrix. In other words, we redefine\n\n\\begin{align}\n    R_b =  R_b .- \\text{mean}(R, dims=2)   \n\\end{align}\n\n\\begin{align}\n    A_d =  \\begin{bmatrix}\nd_1  & 0 & 0\\\\\n\\dots & 0 & 0\\\\\nd_n  & 0 & 0 \n\\end{bmatrix} =   \\begin{bmatrix} D & F*S * 0 & C*0 \\end{bmatrix} =  \\begin{bmatrix} D & 0 & 0 \\end{bmatrix}\n\\end{align}\n\n\\begin{align}\n    A_f =  \\begin{bmatrix}\n0 & f_1  & 0\\\\\n0 & \\dots & 0\\\\\n0 & f_n  & 0 \n\\end{bmatrix} =   \\begin{bmatrix} D*0 & F*S & C*0 \\end{bmatrix} =  \\begin{bmatrix} 0 & F*S & 0 \\end{bmatrix}\n\\end{align}\n\n\\noindent where $A_d$ and $A_f$ are now just taking one block from the $X$ matrix shown in Equation 2 and filling the rest of the entries with zeros.\n\n\\vspace{0.5cm}\n\n\\noindent Finally, Equations 5 and 6 can be written in terms of an augmented system :\n\n\\begin{equation}\n  \\begin{bmatrix}\nI & X \\\\\nX' & 0  \n\\end{bmatrix}  \\begin{bmatrix} U \\\\ Z_{exact} \\end{bmatrix} = \\begin{bmatrix} I_{n\\times n} \\\\ 0 \\end{bmatrix}\n\\label{aug:exact}\n\\end{equation}\n\n\n\\begin{equation}\n  \\begin{bmatrix}\nI & X \\\\\nX' & 0  \n\\end{bmatrix}  \\begin{bmatrix} U \\\\ Z_{JLA}^0 \\end{bmatrix} = \\begin{bmatrix} R_p' \\\\ 0 \\end{bmatrix}\n\\label{aug:JLA1}\n\\end{equation}\n\n\\noindent where $U$ is the matrix of residuals and $Z$ is the matrix of solutions that we're interested in. We are currently unsure whether we can write Equations 7 and 8 in terms of an augmented system.\n\n\\clearpage \n\nWhenever we have a system with $S_xx$ on the left hand side we have the following \\textbf{single} right hand sides: \n\n\\begin{enumerate}\n    \\item $row_k(X)$ for the exact $P_{ii}$ computation.\n    \\item $row_k(R_p * X)$, which is equivalent to using the $1\\times n$ vector $rademacher$ and computing $rademacher * X$. This is used for the JLA computation of $P_{ii}$.\n    \n    \\item $row_k(R_b * A_f)$, which is equivalent to using the $1\\times n$ vector $rademacher$ and computing $rademacher * A_f$. This is used for the JLA computation of $B_{ii}$.\n    \n    \\item $row_k(R_b * A_f)$, which is equivalent to using the $1\\times n$ vector $rademacher$ and computing $rademacher * A_d$. This is used for the JLA computation of $B_{ii}$.\n    \n    \\item $X'*y$. This is used for the computation of the fixed effects coefficients.\n\\end{enumerate}\n\nIt is important to mention that the matrices $A_f$ and $A_d$ can be constructed as transformations of the design matrix, $X$. The construction is done, avoiding the $n^{-1/2}$ normalization and demeaning, in the following way: \n\n\\begin{align}\n    A_f =      \\begin{bmatrix}\n0_{n \\times N} & X[N+1:N+J] \\\\\n\\end{bmatrix}   \n\\end{align}\n\n\\begin{align}\nA_d  =   \\begin{bmatrix}\n  X[1:N] & 0_{n \\times J} \\\\\n\\end{bmatrix}   \n\\end{align}\n\n\n\n\n\\clearpage\n\\section{Inference}\n\nRecall the unfeasible estimator of the (co)variance component: \n\n\\begin{align}\n\\theta^* = \\Hat{\\beta}' A \\Hat{\\beta} - \\sum_{i=1}^n B_{ii} \\sigma_i^2\n\\end{align}\n\nThe finite sample inference results on the (co)variance component will rely on the eigen-decomposition of the following matrix:\n\n\\begin{align}\n    \\Tilde{A} = S_{xx}^{-1/2}  A S_{xx}^{-1/2} \n\\end{align}\n\nThe eigenvalue problem solves\n\n\\begin{align}\n    \\Tilde{A}  Q = Q D\n\\end{align}\n\nwhere $D=diag(\\lambda_1,\\dots,\\lambda_r)$ and $Q$ is a matrix of orthonormal eigenvectors. We can define the following vector $b$, which is a linear combination of r elements of $\\Hat{\\beta}$, and a matrix of generalized eigenvectors:\n\n\\begin{align}\n    \\Hat{b} = Q' S_{xx}^{1/2} \\Hat{\\beta}\n\\end{align}\n\n\\begin{align}\n    \\tilde{Q} = S_{xx}^{-1/2} Q  \n\\end{align}\n\n\n\nUsing these definition we apply Lemma 2, and show that if $\\epsilon_i \\sim N(0,\\sigma_i^2)$ then the following equations must hold: \n\n\n\\begin{align}\n\\Hat{\\beta}' A \\Hat{\\beta} &= \\sum_{l=1}^r \\lambda_l \\Hat{b}^2  \n\\end{align}\n\n\\begin{align}\nVar(\\Hat{b}) &= Q' S_{xx}^{1/2} Var(\\Hat{\\beta}) S_{xx}^{1/2}Q \\\\\n&= Q' S_{xx}^{1/2} S_{xx}^{-1} X' diag(\\sigma_i^2) X S_{xx}^{-1}  S_{xx}^{1/2} Q \\\\\n&= \\Tilde{Q}' X' diag(\\sigma_i^2) X \\Tilde{Q}\n\\end{align}\n\n\\begin{align}\n    \\theta^* = \\sum_{l=1}^r \\lambda_l (\\Hat{b}_l^2 - Var(\\Hat{b_l}))\n\\end{align}\n\nNow notice that instead of solving for $Q$ and constructing $\\Tilde{Q}$ manually (that involves computing $S_{xx}^{-1/2}$, we can solve for $\\Tilde{Q}$ in the following generalized eigendecomposition problem by manipulating the original one:\n\n\\begin{align}\n    S_{xx}^{-1/2} A     S_{xx}^{-1/2} Q &= Q D \\\\\n    A  S_{xx}^{-1/2} Q &=     S_{xx}^{1/2} Q D \\\\\n    A \\Tilde{Q} &= S_{xx}     S_{xx}^{-1/2} Q D \\\\\n    A \\Tilde{Q} &= S_{xx} \\Tilde{Q} D \n\\end{align}\n\nwhere $Q'Q = I$, so that $\\Tilde{Q}'\\Tilde{Q} = S_{xx}^{-1}$, i.e. these eigenvectors must be $S_{xx}$ normalized. This last fact and equation 21 can be used to check if our code is giving us the right solution to the eigendecomposition problem shown in equation 29. \n\n\\end{document}\n\n\n\\end{document}\n", "meta": {"hexsha": "323dde3972dd8d21a30b7d96b30095c566d95f9b", "size": 22695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/rough_notes.tex", "max_stars_repo_name": "Alim-faraji/-VHDFE_different_OS", "max_stars_repo_head_hexsha": "c2cc930f3f51e34df59753f1181e082e71a0451b", "max_stars_repo_licenses": ["MIT"], "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/tex/rough_notes.tex", "max_issues_repo_name": "Alim-faraji/-VHDFE_different_OS", "max_issues_repo_head_hexsha": "c2cc930f3f51e34df59753f1181e082e71a0451b", "max_issues_repo_licenses": ["MIT"], "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/rough_notes.tex", "max_forks_repo_name": "Alim-faraji/-VHDFE_different_OS", "max_forks_repo_head_hexsha": "c2cc930f3f51e34df59753f1181e082e71a0451b", "max_forks_repo_licenses": ["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.2539936102, "max_line_length": 532, "alphanum_fraction": 0.6531835206, "num_tokens": 8310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6021304550733433}}
{"text": "\\section{$n$-step Bootstrapping}\n\n\\subsection{$n$-step TD Prediction}\n\n$n$-step TD prediction is still TD because it changes earlier estimate.\n\nIt did not update anything for the first $n-1$ steps. If $t + n \\geq T$, the missing terms are treated as $0$. It is defined as:\n\n\\begin{equation}\n\tG_{t:t+n} = R_{t+1} + \\gamma R_{t+2} + \\dots + \\gamma^{n-1} R_{t+n} + \\gamma^n V_{t+n-1}(S_{t+n})\n\\end{equation}\n\n\nThe algorithm (\\ref{algo:nsteptdpredition}) contains detail.\n\n\n\\begin{algorithm}\n\t\\caption{$n$-step TD prediction, estimate $v_\\pi$}\\label{algo:nsteptdpredition}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $ \\alpha \\in (0,1]$\n\t\t\\State $V(s) \\gets$ random\n\t\t\\State $t \\gets 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$\n\t\t\t\\State $T \\gets \\infty$\n\t\t\t\\While{$\\tau < T - 1$}\n\t\t\t\t\\If{$t < T$}\n\t\t\t\t\t\\State take action according to $\\pi(\\cdot|S_t)$\n\t\t\t\t\t\\State store $R_{t+1}$ and $S_{t+1}$\n\t\t\t\t\t\\If{$S_{t+1}$ is terminal}\n\t\t\t\t\t\t\\State $T \\gets t+1$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\tau \\gets t - n + 1$ \\Comment $\\tau$ is the pivot of update\n\t\t\t\t\n\t\t\t\t\\If{$\\tau \\geq 0$}\n\t\t\t\t\t\\State $G \\gets \\sum\\limits_{i=\\tau+1}^{\\min (\\tau+n,T)} \\gamma^{i-\\tau-1} R_i$ \\Comment $G_{\\tau:\\tau+n}$\n\t\t\t\t\t\\If{$\\tau + n < T$}\n\t\t\t\t\t\t\\State $G \\gets G + \\gamma^n V(S_{\\tau + n})$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\n\t\t\t\t\t\\State $V(S_\\tau) \\gets V(S_\\tau) + \\alpha \\Big(G - V(S_\\tau)\\Big)$\n\t\t\t\t\\EndIf\n\n\t\t\t\t\\State $t \\gets t+1$\n\t\t\t\\EndWhile\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{$n$-step Sarsa}\n\nIt is the same as $n$-step TD prediction with $q$ and $\\varepsilon$-greedy. \n\n\\begin{equation}\n\tG_{t:t+n} = R_{t+1} + \\gamma R_{t+2} + \\dots + \\gamma^{n-1} R_{t+n} + \\gamma^n Q_{t+n-1}(S_{t+n},A_{t+n})\n\\end{equation}\n\n\nThe algorithm (\\ref{algo:nstepsarsa}) contains detail.\n\n\n\\begin{algorithm}\n\t\\caption{$n$-step Sarsa, estimate $q_\\pi$ or $q_*$}\\label{algo:nstepsarsa}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $ \\alpha \\in (0,1]$\n\t\t\\State $Q(s,a) \\gets$ random\n\t\t\\State $\\pi \\gets$ random $\\varepsilon$-greedy policy or a given fixed policy\n\t\t\\State $t \\gets 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$\n\t\t\t\\State choose action $A_0 \\sim \\pi (\\cdot | S_0)$\n\t\t\t\\State $T \\gets \\infty$\n\t\t\t\\While{$\\tau < T - 1$}\n\t\t\t\t\\If{$t < T$}\n\t\t\t\t\t\\State take action $A_t$ and store $R_{t+1}$ and $S_{t+1}$\n\t\t\t\t\t\\If{$S_{t+1}$ is terminal}\n\t\t\t\t\t\t\\State $T \\gets t+1$\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State choose $A_{t+1} \\sim \\pi(\\cdot|S_{t+1})$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\tau \\gets t - n + 1$ \\Comment $\\tau$ is the pivot of update\n\t\t\t\t\n\t\t\t\t\\If{$\\tau \\geq 0$}\n\t\t\t\t\t\\State $G \\gets \\sum\\limits_{i=\\tau+1}^{\\min (\\tau+n,T)} \\gamma^{i-\\tau-1} R_i$\n\t\t\t\t\t\\If{$\\tau + n < T$}\n\t\t\t\t\t\t\\State $G \\gets G + \\gamma^n Q(S_{\\tau + n}, A_{\\tau + n})$ \\Comment $G_{\\tau:\\tau+n}$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\n\t\t\t\t\t\\State $Q(S_{\\tau}, A_{\\tau}) \\gets Q(S_{\\tau}, A_{\\tau}) + \\alpha \\Big(G - Q(S_{\\tau}, A_{\\tau})\\Big)$\n\t\t\t\t\t\\State update $\\pi_*$ \\Comment update as a $\\varepsilon$-greedy policy if calculating $q_*$\n\t\t\t\t\\EndIf\n\n\t\t\t\t\\State $t \\gets t+1$ \n\t\t\t\\EndWhile\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\n\n\\subsection{$n$-step Expected Sarsa}\n\nIt is the same as $n$-step Sarsa except that it uses expectation at the last step:\n\t\n\\begin{equation}\n\tG_{t:t+n} = R_{t+1} + \\gamma R_{t+2} + \\dots + \\gamma^{n-1} R_{t+n} + \\gamma^n \\sum_a \\pi(a|S_{t+n}) Q_{t+n-1}(S_{t+n},a)\n\\end{equation}\n\n\n\\subsection{$n$-step Off-policy Learning}\n\nnote: $V_{t+n}$ and $Q_{t+n}$ are the result of ($t+n$)th iteration.\n\n\\subsubsection{$n$-step Off-policy TD}\n\nfor $0 \\leq t < T$, the update formula is:\n\n\\begin{equation}\n\tV_{t+n}(S_t)=V_{t+n-1}(S_t)+\\alpha \\prod_{k=t}^{\\min (h,T-1)} \\frac{\\pi(A_k|S_k)}{b(A_k|S_k)} [G_{t:t+n} - V_{t+n-1}(S_t)]\n\\end{equation}\n\n\n\n\\subsubsection{$n$-step Off-policy Sarsa}\n\nfor $0 \\leq t < T$, the update formula is:\n\n\\begin{equation}\n\\begin{split}\n\tQ_{t+n}(S_t,A_t)=&Q_{t+n-1}(S_t,A_t) \\\\\n\t&+\\alpha \\prod_{k=t}^{\\min (h,T-1)} \\frac{\\pi(A_k|S_k)}{b(A_k|S_k)} [G_{t:t+n} - Q_{t+n-1}(S_t,A_t)]\n\\end{split}\n\\end{equation}\n\nSee Algorithm (\\ref{algo:nstepoffsarsa}) for detail.\n\n\n\\begin{algorithm}\n\t\\caption{Off-policy $n$-step Sarsa, estimate $q_\\pi$ or $q_*$}\\label{algo:nstepoffsarsa}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $ \\alpha \\in (0,1]$\n\t\t\\State $Q(s,a) \\gets$ random\n\t\t\\State $\\pi \\gets$ random $\\varepsilon$-greedy policy\n\t\t\\State $t \\gets 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$\n\t\t\t\\State choose action $A_0 \\sim \\pi (\\cdot | S_0)$\n\t\t\t\\State $T \\gets \\infty$\n\t\t\t\\While{$\\tau < T - 1$}\n\t\t\t\t\\If{$t < T$}\n\t\t\t\t\t\\State take action $A_t$ and store $R_{t+1}$ and $S_{t+1}$\n\t\t\t\t\t\\If{$S_{t+1}$ is terminal}\n\t\t\t\t\t\t\\State $T \\gets t+1$\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State choose $A_{t+1} \\sim \\pi(\\cdot|S_{t+1})$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\tau \\gets t - n + 1$ \\Comment $\\tau$ is the pivot of update\n\t\t\t\t\n\t\t\t\t\\If{$\\tau \\geq 0$}\n\t\t\t\t\t\\State $\\rho \\gets \\prod\\limits_{i=\\tau+1}^{\\min (\\tau+n-1,T-1)} \\frac{\\pi(A_i|S_i)}{b(A_i|S_i)}$\n\t\t\t\t\t\\State $G \\gets \\sum\\limits_{i=\\tau+1}^{\\min (\\tau+n,T)} \\gamma^{i-\\tau-1} R_i$ \t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\\If{$\\tau + n < T$}\n\t\t\t\t\t\t\\State $G \\gets G + \\gamma^n Q(S_{\\tau + n}, A_{\\tau + n})$ \\Comment $G_{\\tau:\\tau+n}$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\n\t\t\t\t\t\\State $Q(S_{\\tau}, A_{\\tau}) \\gets Q(S_{\\tau}, A_{\\tau}) + \\alpha \\rho \\Big(G - Q(S_{\\tau}, A_{\\tau})\\Big)$\n\t\t\t\t\t\\State update $\\pi_*$ \\Comment update as a $\\varepsilon$-greedy policy if calculating $q_*$\n\t\t\t\t\\EndIf\n\n\t\t\t\t\\State $t \\gets t+1$\n\t\t\t\\EndWhile\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{$n$-step Tree Backup Algorithm}\n\nThis is an \\cindex{off-policy} learning algorithm without \\cindex{importance sampling}. For each step along the sampling, the non-visited notes contribute probabilistic result according to the policy. The visited node will contribute the updated bootstrapping result.\n\n\n\\begin{equation}\n\t\\begin{split}\n\t\tG_{t:t+n}&=R_{t+1}\\\\\n\t\t&+\\gamma \\sum_{a\\neq A_{t+1}} \\pi(a|S_{t+1}) Q_{t+n-1}(S_{t+1},a) \\text{  \\# other branches} \\\\\n\t\t&+ \\gamma \\pi(A_{t+1}|S_{t+1})G_{t+1:t+n} \\text{  \\# main sample path}\n\t\\end{split}\n\\end{equation}\n\n\nSee Algorithm (\\ref{algo:nsteptreebackup}) for detail.\n\n\n\\begin{algorithm}\n\t\\caption{$n$-step tree backup, estimate $q_\\pi$ or $q_*$}\\label{algo:nsteptreebackup}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $ \\alpha \\in (0,1]$\n\t\t\\State $Q(s,a) \\gets$ random\n\t\t\\State $\\pi \\gets$ random $\\varepsilon$-greedy policy\n\t\t\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$\n\t\t\t\\State choose action $A_0 \\sim \\pi (\\cdot | S_0)$\n\t\t\t\\State $T \\gets \\infty$\n\t\t\t\\State $t \\gets 0$\n\t\t\t\\While{$\\tau < T - 1$}\n\t\t\t\t\\If{$t < T$}\n\t\t\t\t\t\\State take action $A_t$ and store $R_{t+1}$ and $S_{t+1}$\n\t\t\t\t\t\\If{$S_{t+1}$ is terminal}\n\t\t\t\t\t\t\\State $T \\gets t+1$\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State choose $A_{t+1} \\sim \\pi(\\cdot|S_{t+1})$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\tau \\gets t - n + 1$ \\Comment $\\tau$ is the pivot of update\n\t\t\t\t\n\t\t\t\t\\If{$\\tau \\geq 0$}\n\t\t\t\t\t\\If{$t+1 \\geq T$}\n\t\t\t\t\t\t\\State $G \\gets R_T$\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State $G \\gets R_{t+1} + \\gamma \\sum\\limits_a \\pi(a|S_{t+1}) Q(S_{t+1},a)$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\n\t\t\t\t\t\\State \\Comment update $G$ backward using tree-backup method\n\t\t\t\t\t\n\t\t\t\t\t\\For{$k \\gets [\\tau+1,\\dots,\\min (t,T-1)]$} \n\t\t\t\t\t\t\\State $G \\gets R_k + \\gamma \\sum\\limits_{a\\neq A_k} \\pi(a|S_k)Q(S_k,a) + \\gamma \\pi (A_k|S_k)G$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\t\n\t\t\t\t\t\\State $Q(S_{\\tau}, A_{\\tau}) \\gets Q(S_{\\tau}, A_{\\tau}) + \\alpha  \\Big(G - Q(S_{\\tau}, A_{\\tau})\\Big)$\n\t\t\t\t\t\\State update $\\pi_*$ \\Comment update as a $\\varepsilon$-greedy policy if calculating $q_*$\n\t\t\t\t\\EndIf\n\n\t\t\t\t\\State $t \\gets t+1$\n\t\t\t\\EndWhile\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{$n$-step off-policy $Q(\\sigma )$}\n\nLet random variable $\\sigma_t \\sim \\text{Bern}(0,1)$ be the probability of sampling on step $t$, with $\\sigma = 1$ means full sampling and $\\sigma = 0$ means pure expectation. The formula is:\n\n\\begin{equation}\n\t\\begin{split}\n\t\tG_{t:h} =& R_{t+1}+\\gamma \\sum_{a\\neq A_{t+1}} \\pi(a|S_{t+1}) Q_{h-1}(S_{t+1},a) + \\gamma \\pi(A_{t+1}|S_{t+1})G_{t+1:h} \\\\\n\t\t=& R_{t+1} + \\left (\\gamma \\sum_a \\pi(a|S_{t+1})Q_{h-1}(S_{t+1},a) - \\gamma \\pi(A_{t+1}|S_{t+1})Q_{h-1}(S_{t+1},A_{t+1}) \\right)\\\\\n\t\t&+ \\gamma \\pi(A_{t+1}|S_{t+1})G_{t+1:h} \\\\\n\t\t=& R_{t+1} + \\gamma \\sum_a \\pi(a|S_{t+1})Q(S_{t+1},a) \\\\\n\t\t&+ \\gamma \\pi(A_{t+1}|S_{t+1})\\Big (G_{t+1:h} -Q_{h-1}(S_{t+1},A_{t+1})  \\Big)\n\t\\end{split}\n\\end{equation}\n\nReplace $\\pi(A_{t+1}|S_{t+1})$ by $\\Big(\\sigma_{t+1} \\rho_{t+1} + (1-\\rho_{t+1})\\pi(A_{t+1}|S_{t+1}) \\Big)$ ($\\rho$ is the important sampling ratio defined in formula (\\ref{importancsamplingratio})) we have:\n\n\\begin{equation}\n\t\\begin{split}\n\t\tG_{t:h} =& R_{t+1} + \\gamma \\sum_a \\pi(a|S_{k+1})Q(S_{k+1},a) \\\\\n\t\t&+ \\gamma \\Big ( \\sigma_{t+1} \\rho_{t+1} + (1-\\rho_{t+1})\\pi(A_{t+1}|S_{t+1}) \\Big) \\Big(G_{t+1:h} -Q_{h-1}(S_{t+1},A_{t+1}) \\Big)\n\t\\end{split}\n\\end{equation}\n\n\n$\\sum\\limits_a \\pi(a|S_{t})Q(S_{t},a)$ is called \\cindex{expected approximate value} of state $S_t$.\n\n\nSee Algorithm (\\ref{algo:nstepoffrho}) for detail.\n\n\n\\begin{algorithm}\n\t\\caption{Off-policy $n$-step $Q(\\sigma)$, estimate $q_\\pi$ or $q_*$}\\label{algo:nstepoffrho}\t\n\t\n\t\\begin{algorithmic}[1]\n\t\t\\State $ \\alpha \\in (0,1]$\n\t\t\\State $Q(s,a) \\gets$ random\n\t\t\\State $\\pi \\gets$ random $\\varepsilon$-greedy policy\n\t\t\\State random policy $b$ that $\\forall a\\in \\mathcal{A}, s\\in \\mathcal{S}, b(a|s) > 0$\n\t\t\\State $t \\gets 0$\n\t\t\n\t\t\\Statex\n\t\t\n\t\t\\Loop\n\t\t\t\\State choose $S_0$\n\t\t\t\\State choose action $A_0 \\sim b (\\cdot | S_0)$\n\t\t\t\\State $T \\gets \\infty$\n\t\t\t\\While{$\\tau < T - 1$}\n\t\t\t\t\\If{$t < T$}\n\t\t\t\t\t\\State take action $A_t$ and store $R_{t+1}$ and $S_{t+1}$\n\t\t\t\t\t\\If{$S_{t+1}$ is terminal}\n\t\t\t\t\t\t\\State $T \\gets t+1$\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State choose $A_{t+1} \\sim b(\\cdot|S_{t+1})$\n\t\t\t\t\t\t\\State choose $\\sigma_{t+1} \\in \\{ 0, 1\\}$ \\Comment $\\sigma$ is either $0$ or $1$\n\t\t\t\t\t\t\\State $\\rho_{t+1} \\gets \\frac{\\pi(A_{t+1}|S_{t+1})}{b(A_{t+1}|S_{t+1})}$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\EndIf\n\t\t\t\t\n\t\t\t\t\\State $\\tau \\gets t - n + 1$ \\Comment $\\tau$ is the pivot of update\n\t\t\t\t\n\t\t\t\t\\If{$\\tau \\geq 0$}\n\t\t\t\t\t\\For{$k \\gets \\Big [\\min (t+1,T),\\dots,\\tau+1 \\Big ]$}\n\t\t\t\t\t\t\\If{$k=T$}\n\t\t\t\t\t\t\t\\State $G \\gets R_T$\n\t\t\t\t\t\t\\Else\n\t\t\t\t\t\t\t\\State $\\overline{V} \\gets \\sum\\limits_a \\pi(a|S_{k})Q(S_{k},a)$\n\t\t\t\t\t\t\t\\State $G \\gets R_{k} + \\gamma \\overline{V} + \\gamma \\Big ( \\sigma_{k} \\rho_{k} + \\big(1-\\rho_{k})\\pi(A_{k}|S_{k}) \\Big) \\Big(G -Q(S_{k},A_{k}) \\Big  )$\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\t\\State $G(S_\\tau,A_\\tau) \\gets G(S_\\tau,A_\\tau) + \\alpha \\Big(G - G(S_\\tau,A_\\tau)\\Big)$\n\t\t\t\t\t\\State update $\\pi_*$ \\Comment update as a $\\varepsilon$-greedy policy if calculating $q_*$\n\t\t\t\t\\EndIf\n\n\t\t\t\t\\State $t \\gets t+1$\n\t\t\t\\EndWhile\n\t\t\\EndLoop\n\t\\end{algorithmic}\n\\end{algorithm}\n\n", "meta": {"hexsha": "155e919f61c2050e437d3a0595964d25569cb83e", "size": 10585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/reinforcement_learning/rl.6.nstep_sarsa.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/reinforcement_learning/rl.6.nstep_sarsa.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/reinforcement_learning/rl.6.nstep_sarsa.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.860058309, "max_line_length": 267, "alphanum_fraction": 0.5755314124, "num_tokens": 4487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6021304532850636}}
{"text": "\\label{sfp}\n\\begin{chapterbox}\n\\vspace{-60pt}\n\\chapter{Symmetries, Fields and Particles}\\label{chap:sfp}\n\\vspace{-30pt}\n\\centering\\normalsize\\textit{Michaelmas Term 2017 - Professor N. Dorey}\n\\end{chapterbox}\n\\vspace{20pt}\n%\\begin{multicols*}{2}\n\\minitoc\n\\newpage\n\\section{Introduction}\n\\subsection{Mathematical Formulation}\n\n\\begin{definitionbox}\nA Lie Group\\index{group!Lie}, $\\group$, is a group which is also a smooth manifold\\index{manifold}. Each point on the manifold corresponds to an element of the group.\n\\end{definitionbox}\nWe need the group and manifold structure to be compatible, requiring continuity and smoothness for multiplicative and inverse properties of the group. This ensures $\\group$ is almost entirely determined by the behaviour near $e$, i.e. by tangent vectors, $V \\in \\mathcal{T}_e(\\group)$. $\\mathcal{T}_e(\\group)$ is equipped with a Lie Bracket:\n$$\\left[\\,\\,\\, , \\,\\,\\,\\right]:\\mathcal{T}_e(\\group)\\times \\mathcal{T}_e(\\group) \\rightarrow \\mathcal{T}_e(\\group)$$\nwhich defines a Lie Algebra, $\\mathcal{L}(\\group)$. \\boxed{\\textbf{I.i}} \\boxed{\\textbf{I.ii}} \\boxed{\\textbf{I.iii}}\n\n\\subsection{Simple, Complex Lie Algebras}\n\n\\subsubsection{Cartan Classification}\n\n\\begin{definitionbox}\nAll \\emph{finite dimensional semi-simple} Lie Algebras over $\\mathbb{C}$ either belong to four infinite families: $A_n, B_n, C_n, D_n$ with $n \\in \\mathbb{N}$, or are one of the five exceptional cases: $E_6, E_7, E_8, G_2, F_4$.\n\\end{definitionbox}\nIn quantum mechanics, the states of the system are states in some Hilbert space, $\\mathfrak{H}$. To understand the symmetries, we just need to understand the commutators of the symmetry, e.g. $\\left[ \\hat{L}_i , \\hat{L}_j \\right] = i\\epsilon\\indices{_{ijk}} \\hat{L}_k$ which is the algebra of $\\mathcal{L}\\left(\\textrm{SO}(3)\\right)$. The operators often act on some finite dimensional vector space, $\\mathcal{H}$, the \\emph{representation space}. For an electron, this is $\\mathcal{H} = \\mathbb{C}^2$, the operators then lie in a 2-dimensional representation of $\\mathcal{L}\\left(\\textrm{SO}(3)\\right)$: the Pauli matrices, $\\sigma_i$ which preserves the Lie bracket structure. If the system is invariant under this symmetry, then we have $\\left[ \\mathcal{H} , \\hat{L}_i \\right] = 0$ and thus all the states in some irreducible representation have the same energy. This can be generalised:\n\\begin{definitionbox}\nDegeneracies in the spectrum of a quantum system are determined by irreducible representations of a global symmetry.\n\\end{definitionbox}\n\\noindent Global symmetries split into two classes (note that these are distinct from gauge symmetries):\n\\begin{itemize}\n\\item \\emph{Spacetime symmetries:} rotational, Lorentz, Poincar�, supersymmetry (?)\n\\item \\emph{Internal symmetries:} electric charge, flavour, baryon number\n\\end{itemize}\n\n\\subsection{Gauge Symmetry}\n\nIn contrast, a gauge symmetry\\index{symmetry!gauge} is a redundancy in the mathematical description, for example in the phase of the wavefunction, $\\psi \\rightarrow e^{i\\delta}\\psi$, or in Electromagnetism, $A_{\\mu} \\rightarrow A_{\\mu} + \\partial_{\\mu}\\chi$. The Standard Model is a non-Abelian gauge theory with $\\group_{\\textrm{SM}}=\\textrm{SU}(3) \\times \\textrm{SU}(2) \\times \\textrm{U(1)}$.\n\\newpage\n\\section{Lie Groups}\n\n\\subsection{Manifolds}\n\nWe can cover a manifold of dimension $n$ with one-to-one functions called \\emph{charts}\\index{chart}, $\\phi_{\\alpha} : U_{\\alpha} \\rightarrow V_{\\alpha} \\subset \\mathbb{R}^n$.\n\n\\begin{thm}\\label{thm:manifold}\nSuppose we have a map $F : \\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ where $m<n$ with co-ordinates $\\left\\{ x_i \\right\\}$, $i = 1, \\ldots, n$ and $\\left\\{ w_{\\alpha} \\right\\}$, $\\alpha = 1, \\ldots, m$. A manifold $\\mathcal{M}$ is a solution to the equations:\n\\begin{dmath}\nF_{\\alpha}\\left( x_1, \\ldots, x_n \\right) \\hiderel{=} w^{(0)}_{\\alpha} \\hiderel{\\iff} \\mathcal{M} \\hiderel{=} F^{-1}\\left( \\bm{w}^{(0)} \\right) = \\left\\{ \\bm{x} \\hiderel{\\in} \\mathbb{R}^n \\hiderel{:} F_{\\alpha}\\left( \\bm{x} \\right) \\hiderel{=} w^{(0)}_{\\alpha} \\right\\}\n\\end{dmath}\nNow define the Jacobian\\index{Jacobian} matrix:\n\\begin{equation}\n\\mathfrak{J}\\indices{_{\\alpha i}}=\\frac{\\partial F_{\\alpha}}{\\partial x_i}\n\\end{equation}\nThen, if $\\mathfrak{J}$ has full rank, $m$, $\\mathcal{M}$ is a manifold of dimension $(n-m)$.\n\\end{thm}\n\n\\subsection{Back to Lie Groups}\n\nThe dimension of $\\group$, $\\dim \\group$, is the dimension of the group manifold $\\mathcal{M}\\left( \\group \\right)$. We can introduce co-ordinates $\\left\\{ \\theta^i \\right\\}$, $i = 1, \\ldots, \\dim \\group$ in some co-ordinate patch containing the identity $e \\in \\group$. Then the group elements depend continuously on $\\bm{\\theta}$, $g = g(\\bm{\\theta})$. Then:\n\n\\begin{enumerate}\n\\item \\emph{Group Multiplication:} corresponds to a smooth map from $\\group \\times \\group \\rightarrow \\group$. The co-ordinates\n$$\\phi^i = \\phi^i \\left( \\bm{\\theta}, \\bm{\\theta}' \\right)$$\nare differentiable and continuous. Then $g(0) = e \\Rightarrow \\phi^{i} \\left( \\bm{\\theta}, 0 \\right) = \\theta^{i}, \\,\\,\\, \\phi^{i} \\left( 0, \\bm{\\theta}' \\right)  = \\theta^{\\prime i}$.\n\\item \\emph{Group Inversion:} This defines a smooth map from $\\group \\rightarrow \\group$ where the co-ordinates:\\footnote{To be a bit more precise, consider a map $f: \\mM(\\group) \\rightarrow \\mM(\\group)$ that induces a map $\\theta \\mapsto \\tilde{\\theta}$. Suppose we have charts $\\phi$ and $\\tilde{\\phi}$ on the domain space and the image space respectively, then the statement that $\\theta \\mapsto \\tilde{\\theta}$ is a smooth map is really the property that $\\tilde{\\phi}^{-1} \\circ f \\circ \\phi$ is a smooth map from $\\RR^{n}$ to $\\RR^{n}$ where $\\dim \\mM(\\group) = n$.}\n$$\\tilde{\\theta}^i = \\tilde{\\theta}^i\\left( \\bm{\\theta} \\right)$$\n\n\\noindent are continuous and differentiable.\n\\end{enumerate}\n\n\\subsection{Matrix Groups\\index{group!matrix}}\\label{mat}\n\nWe can define the general linear group\\index{group!general linear} and the special linear group\\index{group!special linear} as subsets of the set of $n \\times n$ matrices, $\\textrm{Mat}_n \\left( \\mathbb{F} \\right)$:\n\\begin{align}\n\\textrm{GL} \\left( n, \\mathbb{F} \\right) &= \\left\\{ \\textrm{M} \\in \\textrm{Mat}_n \\left( \\mathbb{F} \\right) : \\det \\textrm{M} \\neq 0 \\right\\} \\\\\n\\textrm{SL} \\left( n, \\mathbb{F} \\right) &= \\left\\{ \\textrm{GL}_n \\left( n, \\mathbb{F} \\right) : \\det \\textrm{M} = 1 \\right\\}\n\\end{align}\nUsing a construction as in Theorem \\ref{thm:manifold} for the case $\\textrm{SL} \\left( n, \\mathbb{R} \\right)$ we can choose $F : \\mathbb{R}^{n^2} \\rightarrow \\mathbb{R}$ to be $F\\left( \\textrm{M} \\right) = \\det \\textrm{M}$ which can be shown to have full rank. Then we deduce $\\textrm{SL} \\left( n, \\mathbb{R} \\right)$ is a Lie Group of dimension $(n^2 - 1)$. This can be done less obviously for $\\textrm{GL} \\left( n, \\mathbb{F} \\right)$ to find:\\footnote{To understand the case of $\\text{GL}\\left(n, \\mathbb{F}\\right)$, one can view the condition $\\det \\text{M} \\neq 0$ as excluding a set of matrices of measure $0$ in the space of $n \\times n$ matrices. To understand why it is a manifold at all, it is useful to consider the idea of algebraic varieties. Note that $\\det \\text{M} = 0$ is an algebraic relation between the co-ordinates (matrix elements). The resulting subset of the larger group (in this case $\\text{Mat}(n, \\mathbb{F})$) is a manifold provided there are no singularities. Arguing as follows, suppose there was some singularity at $g_1 \\in \\group$, then there must be singularities everywhere since $g_2 g^{-1}_1$ is smooth in the larger group. This is a contradiction, so algebraically defined subgroups are indeed manifolds, and hence are Lie groups.}\n\\begin{center}\n\\begin{mytable}{lc}\n\t\\textbf{Group, }$\\group$ \t\t\t\t& \\textbf{Dimension, }$\\dim \\group$\t\\\\ \\midrule\n    \t$\\textrm{SL} \\left( n, \\mathbb{R} \\right)$\t& $n^2 - 1$\t\t\t\t\t\\\\\n\t$\\textrm{SL} \\left( n, \\mathbb{C} \\right)$\t& $2n^2 - 2$\t\t\t\t\t\\\\\n\t$\\textrm{GL} \\left( n, \\mathbb{R} \\right)$\t& $n^2$\t\t\t\t\t\t\\\\\n\t$\\textrm{GL} \\left( n, \\mathbb{C} \\right)$\t& $2n^2$\n\\end{mytable}\n\\captionof{table}{Matrix Lie Groups and their dimensions, note that in the case of $\\textrm{SL} \\left( n, \\mathbb{C} \\right)$, the complex dimension of the space has decreased by $1$, and so the real dimension decreases by $2$.}\n\\end{center}\n\\begin{definitionbox}\nA subgroup, $\\mathscr{H}$ of a Lie Group, $\\group$, such that $\\mathscr{H}$ is also a submanifold of $\\group$ is a Lie subgroup\\index{subgroup!Lie}.\n\\end{definitionbox}\n\n\\subsubsection{Subgroups of $\\textrm{GL} \\left( n, \\mathbb{R} \\right)$\\index{subgroup!matrix}}\n\n\\subsubsection*{Orthogonal Groups\\index{group!orthogonal}}\n\nWe define the orthogonal group, $\\textrm{O}(n)$ by:\n\\begin{equation}\n\\textrm{O}(n) = \\left\\{ \\textrm{M} \\in \\textrm{GL} \\left( n, \\mathbb{R} \\right) : \\textrm{M}^T \\textrm{M} = \\mathbb{I}_n \\right\\}\n\\end{equation}\nWe know that $\\textrm{M} \\in \\textrm{O}(n)$ has $\\det \\textrm{M} = \\pm 1$, so as a Lie group it has two disconnected components which follows from the lemma below applied to the function $\\det : \\textrm{O}(n) \\rightarrow \\left\\{+1, -1\\right\\}$:\n\\begin{thm}\\label{thm:cts}\nAny continuous map from a continuous space to a discrete space must be a constant.\n\\end{thm}\nIf we pick only the part containing the identity we are just left with $\\textrm{SO}(n)$. By considering the real constraints placed on the matrices and noting that since $\\textrm{SO}(n)$ is the identity part of $\\textrm{O}(n)$, it must have the same dimension as a manifold, we may deduce that:\n\\begin{equation}\n\\dim \\textrm{SO}(n) = \\dim \\textrm{O}(n) = \\tfrac{1}{2}n(n-1)\n\\end{equation}\nWe now investigate the manifold structure of $\\textrm{SO}(2)$\\index{SO(2)} and $\\textrm{SO}(3)$\\index{SO(3)}. For matrices in $\\textrm{O}(n)$, the following holds:\n\\begin{itemize}\n\\item $\\lambda$ is an eigenvalue $\\Rightarrow$ $\\lambda^*$ is also.\n\\item $\\left| \\lambda \\right|^2 = 1$\n\\end{itemize}\nWe apply this to the two examples mentioned.\n\\begin{examplebox}[$\\textrm{SO}(2)$]\nFor $\\group = \\textrm{SO}(2)$, the eigenvalues must be $e^{i \\theta}$, $e^{-i \\theta}$, which in turn implies that;\n\\begin{equation}\n\\textrm{M}(\\theta) = \\twobytwo{\\cos\\theta}{-\\sin\\theta}{\\sin\\theta}{\\cos\\theta}\n\\end{equation}\nOn $\\textrm{SO}(2)$, $\\textrm{M}(\\theta_1)\\textrm{M}(\\theta_2) = \\textrm{M}(\\theta_1 + \\theta_2) = \\textrm{M}(\\theta_2)\\textrm{M}(\\theta_1)$, i.e. it is abelian. Noting further that $\\theta \\sim \\theta + 2\\pi$, $\\theta \\in \\mathbb{R}$ we deduce that the group manifold is $\\mathcal{M}\\left( \\textrm{SO}(2) \\right) = \\mathcal{S}^1$.\n\\end{examplebox}\n\\begin{examplebox}[$\\textrm{SO}(3)$]\nThe example of $\\textrm{SO}(3)$ is less trivial. $\\text{M} \\in \\SO{3}$ has eigenvalues $\\set{e^{i\\theta}, e^{-i\\theta}, +1}$. Now consider eigenvector associated to $\\lambda = 1$, $\\vec n \\in \\mathbb{R}^3$ which satisfies $\\text{M} \\vec n = \\vec n$. This is the axis of rotation. Now a general group element is;\n\\begin{equation}\n\\text{M}(\\vec n, \\theta)_{ij} = \\cos \\theta \\delta_{ij} + (1- \\cos \\theta) n_i n_j + \\sin \\theta \\epsilon_{ijk} n_k\n\\end{equation}\nNow since $\\cos(2\\pi - \\theta) = \\cos \\theta$ and $\\sin(2\\pi - \\theta) = -\\sin \\theta$, we deduce that $\\text{M}(\\vec n, 2\\pi - \\theta) = \\text{M}(-\\vec n, \\theta)$. Hence we must restrict to $0 \\leq \\theta \\leq \\pi$, but with the identification $(\\vec n, +\\pi) \\sim (-\\vec n, -\\pi)$. Considering the vector $\\vec w = \\theta \\vec n$, we see that it lies within the $3$-ball, $\\mathcal{B}_3 = \\set{\\vec w \\in \\mathbb{R}^3 : \\abs{\\vec w} \\leq \\pi} \\subset \\mathbb{R}^3$ with the additional structure that antipodal points on the boundary, $\\del \\mathcal{B}_3 = \\set{\\vec w \\in \\mathbb{R}^3 : \\abs{\\vec w} = \\pi}$ are identified. This makes the $3$-ball a manifold, and hence the manifold, $\\mathcal{M}\\left(\\SO{3}\\right)$ is the $3$-ball with boundary, with antipodal points identified.\\footnotemark\n\\end{examplebox}\n\\footnotetext{This is also isomorphic to the real projective space $\\mathbb{R}\\mathbb{P}^3$}\nThere is a little more to say about $\\mathcal{M}\\left(\\SO{3}\\right)$;\n\\begin{enumerate}\n\\item It is compact\\index{compact}, i.e. it is closed and bounded where closed means the manifold contains all limit points, and bounded means $\\exists A > 0 : \\forall x \\in \\mathcal{M}\\left(\\SO{3}\\right), \\| x \\| < A$\n\\item It is without boundary due to the identification\n\\item It is connected\\index{connected}, but not simply connected\\index{connected!simply}. We can draw paths between any two points but not all loops\\index{loop} are contractible\\index{loop!contractible}. A loop is a function $f : \\mathcal{S}^1 \\rightarrow \\mathcal{M}$. Loops are equivalent if they can be continuously transformed. Then the \\emph{homotopy group} is the set of equivalence classes of loops with composition\\index{group!homotopy}. Here the loop $\\ell = \\set{\\alpha \\vec v : \\alpha \\in [-\\pi, \\pi]}$ is not contractible (joins two points on the boundary through the centre of the sphere), so $\\ell \\not\\sim \\set{1}$, but $\\ell^2$ is (can move point at $\\alpha = \\pi$, say, both ways round the sphere to contract the loop to the identity at $\\alpha = - \\pi$. So the first homotopy group is $\\pi_1\\left(\\SO{3}\\right) = \\mathbb{Z}_2$.\n\\end{enumerate}\n\\subsubsection*{Non-compact Subgroups of $\\text{GL}(n, \\mathbb{R})$}\n$\\text{M} \\in \\Orth{n}$ preserve the Euclidean metric on $\\mathbb{R}^n$. More generally, $\\Orth{p,q}$ transformations preserve the flat metric with signature $(p, q)$. A key example of this is the Lorentz group\\index{group!Lorentz}, $\\Orth{3,1}$ which preserves the Minkowski metric\\index{Minkowski metric}. The corresponding group manifolds are non-compact, e.g. $\\SO{1,1}$ has matrices of the form,\n\\begin{equation*}\n\\twobytwo{\\cosh \\phi}{\\sinh \\phi}{\\sinh \\phi}{\\cosh \\phi}\n\\end{equation*}\nwhere $\\phi \\in \\mathbb{R}$, so $\\SO{1,1} \\simeq \\mathbb{R}$.\n\\subsubsection{Subgroups of $\\text{GL}(n, \\mathbb{C})$}\n\\subsubsection*{Unitary Groups\\index{group!unitary}}\n\\begin{equation}\n\\Uni{n} = \\set{\\text{U} \\in \\text{GL}(n, \\mathbb{C}) : \\text{U}^{\\dagger}\\text{U} = \\mathbb{I}_n}\n\\end{equation}\nUnitary transformations take vectors, $\\vec v \\in \\mathbb{C}^n$ and preserve the length $\\abs{\\vec v} = \\vec{v}^{\\dagger} \\vec v$. $\\text{U} \\in \\Uni{n}$ have $\\det \\text{U} = e^{i\\delta}$ for some $\\delta \\in [0,2\\pi)$. The fact that this is a continuous function of $\\delta$ ensures that the unitary group will be connected unlike the orthogonal group.\n\\subsubsection*{Special Unitary Groups\\index{group!special unitary}}\n\\begin{equation}\n\\SU{n} = \\set{\\text{U} \\in \\Uni{n} : \\det \\text{U} = 1}\n\\end{equation}\nSince $\\SU{n}$ and $\\Uni{n}$ have a manifold structure, they are Lie groups, and hence Lie subgroups of $\\text{GL}(n, \\mathbb{C})$. The dimensions of the groups follows by considering the $n^2$ constraints on $\\Uni{n}$ encoded in the columns of the matrix and their normalisation. The determinant condition then imposes one additional constraint. This is shown in Table \\ref{tab:dim_orth_uni}.\n\\begin{center}\n\\begin{mytable}{lc}\n\t\\textbf{Group, }$\\group$ \t\t\t\t& \\textbf{Dimension, }$\\dim \\group$\t\\\\ \\midrule\n    \t$\\Orth{n}$\t\t\t\t\t\t& $\\tfrac{1}{2}n(n - 1)$\t\t\t\t\t\\\\\n\t$\\SO{n}$\t\t\t\t\t\t\t& $\\tfrac{1}{2}n(n - 1)$\t\t\t\t\t\\\\\n\t$\\Uni{n}$\t\t\t\t\t\t\t& $n^2$\t\t\t\t\t\t\\\\\n\t$\\SU{n}$\t\t\t\t\t\t\t& $n^2 - 1$\n\\end{mytable}\n\\captionof{table}{Dimensions of the Unitary and Orthogonal Groups}\n\\label{tab:dim_orth_uni}\n\\end{center}\n\\begin{definitionbox}[Lie Group Isomorphisms]\nTwo Lie Groups $\\group$ and $\\group^{\\prime}$ are isomorphic\\index{group!Lie!isomorphism} if $\\exists$ $1$:$1$ smooth map $f : \\group \\rightarrow \\group^{\\prime}$ such that $\\forall g_1, g_2 \\in \\group$, $f(g_1, g_2) = f(g_1, g_2)$ i.e. it is a homeomorphism of manifolds that preserves the group structure.\n\\end{definitionbox}\nA simple example of this idea is $\\Uni{1}$ and $\\SO{2}$. We can parametrise $z \\in \\Uni{1}$ by $\\theta \\in [0, 2\\pi)$. Then an element in $\\SO{2}$ can be written,\n\\begin{equation}\ng = \\text{M}(\\theta) = \\twobytwo{\\cos\\theta}{\\sin\\theta}{-\\sin\\theta}{\\cos\\theta}\n\\end{equation}\nwhere the periodicity ensures, $\\theta \\sim \\theta + 2\\pi$. So $\\Uni{1} \\simeq \\mathcal{S}^1 \\simeq \\SO{2}$.\n\\begin{examplebox}[The case of $\\SU{2}$]\nIt can be shown that $\\forall g \\in \\SU{2}$\\footnotemark,  we can write;\n\\begin{equation}\n\\label{eq:pauli}\ng = a_0 \\mathbb{I}_2 + i \\vec a \\cdot \\vec \\sigma, \\quad a_0^2 + a_1^2 + a_2^2 + a_3^2 = 1\n\\end{equation}\nThus we deduce that $\\mathcal{M}\\left(\\SU{2}\\right) = \\mathcal{S}^3$. Now $\\pi_1\\left(\\mathcal{S}^3\\right) = \\pi_1\\left(\\SU{2}\\right) = \\varnothing$, so it cannot be the case that $\\SU{2} \\simeq \\SO{3}$ even though they have the same dimension.\n\\end{examplebox}\n\\footnotetext{Simply expand the expression in \\eqref{eq:pauli} in terms of the Pauli matrices, and apply the determinant condition.}\n\\newpage\n\\section{Lie Algebras}\nA Lie algebra\\index{Lie!algebra}, $\\alge$ is a vector space with a bracket, $\\left[\\,\\,\\,, \\,\\,\\right] : \\alge \\times \\alge \\rightarrow \\alge$ which satisfies;\n\\begin{enumerate}\n\\item Anti-symmetry - $\\left[X, Y\\right] = -\\left[Y, X\\right] \\forall X, Y \\in \\alge$\n\\item Linearity - $\\left[\\alpha X + \\beta Y, Z\\right] = \\alpha\\left[X, Z\\right] + \\beta\\left[Y, Z\\right] \\forall X, Y, Z \\in \\alge$\n\\item Jacobi Identity\\index{identity!Jacobi} - $\\left[X, [Y, Z]\\right] + \\left[Z, [X, Y]\\right] + \\left[Y, [Z, X]\\right] = 0$\n\\end{enumerate}\nWith this in mind, if a vector space, $\\mathcal{V}$, has an associative product $\\star : \\mathcal{V} \\times \\mathcal{V} \\rightarrow \\mathcal{V}$ then we can make it a Lie Algebra by setting $[X, Y] = X \\star Y - Y \\star X$. The dimension of a Lie algebra, $\\alge$, is the dimension of the vector space. As it is a vector space, we can choose a basis $\\mathcal{B}$ for $\\alge$;\n\\begin{equation}\n\\mathcal{B} = \\set{T^a, a = 1, \\ldots \\dim \\alge}\n\\end{equation}\nthen we can write $X \\in \\alge$ as $X = X_a T^a$ with $X^a \\in \\mathbb{F}$. Then brackets of the basis elements define the brackets of the vectors $X, Y, \\ldots \\in \\alge$\n\\begin{equation}\n\\left[X, Y\\right] = X_a Y_b \\left[T^a, T^b\\right], \\quad \\left[T^a, T^b\\right] = f\\indices{^{ab}_{c}}T^c\n\\end{equation}\nwhere the $\\set{f\\indices{^{ab}_{c}}}$ are the structure constants satisfying $f\\indices{^{(ab)}_{c}} = 0$.\n\\begin{definitionbox}[Lie Algebra Isomorphism]\nTwo Lie algebras $\\alge$, $\\alge^{\\prime}$ are isomorphic\\index{Lie!algebra!isomorphism} if $\\exists$ a $1$:$1$ linear map $f : \\alge \\rightarrow \\alge^{\\prime}$ such that the bracket structure is preserved;\n\\begin{equation}\n\\left[f(X), f(Y)\\right] = f\\left([X, Y]\\right), \\quad \\forall X, Y \\in \\alge\n\\end{equation}\n\\end{definitionbox}\nA \\emph{subalgebra}\\index{subalgebra} $\\mathfrak{h} \\subset \\alge$ is a subset of $\\alge$ that is also a Lie algebra. Furthermore, an \\emph{ideal}\\index{ideal!of a Lie algebra} is a subalgebra $\\mathfrak{h}$ of $\\alge$ such that $[X, Y] \\in \\mathfrak{h} \\forall X \\in \\alge, Y \\in \\mathfrak{h}$. Every Lie algebra has two trivial ideals; $\\mathfrak{h} = \\varnothing, \\mathfrak{h} = \\alge$, but there are two less trivial examples;\n\\begin{enumerate}\n\\item The \\emph{derived} algebra\\index{algebra!derived}\\index{ideal!derived algebra};\n\\begin{equation}\n\\mathfrak{i} \\coloneqq [\\alge, \\alge] = \\vecspan\\set{[X, Y] : X, Y \\in \\alge}\n\\end{equation}\n\\item The \\emph{centre}\\index{ideal!centre};\n\\begin{equation}\n\\zeta(\\alge) = \\set{X \\in \\alge : [X, Y] = 0 \\quad \\forall Y \\in \\alge}\n\\end{equation}\nAn abelian Lie algebra\\index{Lie algebra!abelian} is one for which $\\zeta(\\alge) = \\alge \\Rightarrow \\mathfrak{i} = \\varnothing$.\n\\end{enumerate}\n\\begin{definitionbox}[Simple Lie Algebras]\n$\\alge$ is \\emph{simple}\\index{Lie algebra!simple} if it is non-abelian and possesses no non-trivial ideal. Cartan's classification encompasses all finite dimensional, complex ($\\mathbb{C}$), simple Lie algebras.\n\\end{definitionbox}\n\\subsection{Lie Algebras from Lie Groups}\n\\subsubsection{Preliminaries}\nLet $\\mathcal{M}$ be a smooth manifold, with $\\dim \\mathcal{M} = D$, and let $p \\in \\mathcal{M}$. Introduce co-ordinates $\\set{x^i}, i = 1, \\ldots, D$ in some region $\\mathcal{P} \\subset \\mathcal{M}$ with $p$ at $x^i = 0$. Then;\n\\begin{itemize}\n\\item The tangent space\\index{tangent space} $\\TpM$ to $\\mathcal{M}$ at $p$ is a $D$-dimensional vector space spanned by $\\set{\\tfrac{\\del}{\\del x^i}}$ acting on functions $f : \\mathcal{M} \\rightarrow \\mathbb{R}$. Then a tangent vector\\index{tangent vector} is defined by;\n\\begin{equation}\nv = v^i \\frac{\\del}{\\del x^i} \\in \\TpM, v^i \\in \\mathbb{R}\n\\end{equation}\nwhich acts on functions, $f = f(x)$ via;\n\\begin{equation}\nv \\cdot f = \\left.v^i \\frac{\\del f}{\\del x^i}\\right|_{x = 0}\n\\end{equation}\n\\item Let $\\mathcal{C}$ be a smooth curve passing through $p$, then;\n\\begin{equation*}\n\\mathcal{C} : t \\in \\mathbb{R} \\mapsto x^i(t) \\in \\mathbb{R}\n\\end{equation*}\nwhere the $\\set{x^i(t)}$ are continuous and differentiable with $x^i(0) = 0 \\,\\, \\forall i$.\n\\item The tangent vector to a curve $\\mathcal{C}$ at the point $p$ is an element of $\\TpM$, $v_{\\mathcal{C}} = \\dot{x}^i(0)\\tfrac{\\del}{\\del x^i}$. Acting on functions corresponds to the derivative of $f$ along $\\mathcal{C}$;\n\\begin{equation}\nv_{\\mathcal{C}} \\cdot f = \\left.\\dot{x}^i(0) \\frac{\\del f(x)}{\\del x^i}\\right|_{x=0} = \\left.\\frac{\\ud f}{\\ud t}\\right|_{t = 0}\n\\end{equation}\n\\end{itemize}\n\\subsubsection{The Lie Algebra, $\\lie{\\group}$}\nLet $\\group$ be a Lie group of dimension $D$. Introduce co-ordinates $\\set{\\theta^i}$ in some region containing the identity ($g = g(\\theta) \\in \\group, g(0) = e$). Then the tangent space at the identity, $\\TeG$ is $D$-dimensional vector space. We can define a bracket $[\\,\\,\\,,\\,\\,] : \\TeG \\times \\TeG \\rightarrow \\TeG$ such that $\\lie{\\group} = \\left(\\TeG, [\\,\\,\\,,\\,\\,]\\right)$ is a Lie algebra. We start by doing this for matrix groups. Let $\\group \\subset \\text{Mat}_n(\\mathbb{F})$ for some $n \\in \\mathbb{N}$. Now we can map tangent vectors to matrices;\n\\begin{equation}\ne : \\TeG \\rightarrow \\text{Mat}_n(\\mathbb{F}), \\quad v^i \\frac{\\del}{\\del \\theta^i} \\in \\TeG \\mapsto \\left.v^i \\frac{\\del g(\\theta)}{\\del \\theta^i}\\right|_{\\theta = 0} \\in \\text{Mat}_n(\\mathbb{F})\n\\end{equation}\nThis allows us to identify $\\TeG$ with a subspace of $\\text{Mat}_n(\\mathbb{F})$ spanned by $\\set{\\left.\\tfrac{\\del g(\\theta)}{\\del \\theta^i}\\right|_{\\theta = 0}}$, which is valid since $e$ is linear and injective (it will span some subspace of $\\text{Mat}_n(\\mathbb{F})$). Now the obvious bracket is just the matrix commutator;\n\\begin{equation}\n[X, Y] \\overset{\\textrm{\\tiny def}}{=} XY - YX, \\quad \\forall X, Y \\in \\TeG\n\\end{equation}\nwhere we make the identification of $X, Y$ with $e(X), e(Y)$. Then since it is just a matrix commutator, all that remains is to show that the bracket is closed i.e. $[X, Y] \\in \\lie{\\group} \\,\\,\\forall X, Y \\in \\lie{\\group}$\\footnotemark. To prove this we use the correspondence between tangent vectors and curves; it is sufficient to construct a curve with tangent vector $[X_1, X_2]$ from two curves with tangent vectors $X_1, X_2$.\n\\footnotetext{This ensures that it is okay to make the identification $X, Y \\mapsto e(X), e(Y)$ as $e$ is only injective. If the commutator went outside the algebra, we would not have a defined inverse to map back to an element of the Lie algebra.}\n\n\\paraskip\nLet $\\mC$ be a smooth curve\\index{curve!in a Lie group} on $\\group$ passing through the identity, $\\mC : t \\mapsto g(t) \\in \\group, g(0) = \\mathbb{I}_n$. Then;\n\\begin{equation}\n\\frac{\\ud g(t)}{\\ud t} = \\frac{\\ud \\theta^i (t)}{\\ud t} \\frac{\\del g(\\theta)}{\\del \\theta^i} \\Rightarrow \\dot{g}(0) = \\dot{\\theta}^i(0)\\left.\\frac{\\del g(\\theta)}{\\del \\theta^i}\\right|_{\\theta = 0} \\in \\TeG\n\\end{equation}\nNow near $t = 0$, $g(t) = \\II_n + X t + o(t)$ with $X = \\dot{g}(0) \\in \\lie{\\group} \\simeq \\TeG$.\\footnotemark$\\,\\,$ Then we can construct curves, $\\mC_{k} : t \\mapsto g_k(t) \\in \\group$ such that near $t = 0$;\n\\begin{equation}\ng_1(t) = \\II_n + X_1 t + W_1 t^2 + o(t^2), \\quad g_2(t) + X_2 t + W_2 t^2 + o(t^2)\n\\end{equation}\nfor some $W_1, W_2 \\in \\text{Mat}_n(\\FF)$ and $X_1 = \\dot{g}_1(0), X_2 = \\dot{g}_2(0) \\in \\lie{\\group}$. Finally consider the curve, $h(t) = g_1^{-1}(t)g_2^{-1}(t)g_1(t)g_2(t) \\in \\group$. Expanding near $t = 0$ we find that;\n\\begin{equation}\nh(t) = \\II_n + [X_1, X_2] t^2 + o(t^3)\n\\end{equation}\nThus, defining a curve, $\\mC_3 : s \\mapsto g_3(s) \\coloneqq h(\\sqrt{s})$, we see that;\n\\begin{equation}\ng_3(s) = \\II_n + s[X_1, X_2] + o\\left(s^{\\tfrac{3}{2}}\\right) \\Rightarrow \\dot{g}_3(0) = [X_1, X_2] \\in \\lie{\\group}\n\\end{equation}\n\\footnotetext{Note that whilst in general $\\dot{g}(0) \\in \\text{Mat}_n (\\FF)$, it is not generally in $\\group$. This is just because the Lie algebra has a different algebraic structure to the group.}\n\nThus, $\\lie{\\group} = \\left(\\TeG, [\\,\\,\\,,\\,\\,]\\right)$ is a Lie algebra of dimension $D$.\\footnote{To fill in the details, we only need our curve to be $\\mC^1$. Differentiating gives lowest order terms $\\mathcal{O}\\left(s^{\\tfrac{1}{2}}\\right)$, so $\\mC_3 \\in \\mC^1$.} We can apply these ideas to examples of matrix Lie groups covered in previous sections. Consider the case $\\SO{n}$, we may write $g(t) = \\text{R}(t) \\in \\SO{n} : \\text{R}(0) = \\II_n$, so $\\text{R}^{\\text{T}}(t) \\text{R}(t) = \\II_n$. Differentiating we find;\n\\begin{equation}\n\\dot{\\text{R}}^{\\text{T}}(t)\\text{R}(t) + \\text{R}^{\\text{T}}\\dot{\\text{R}}(t) = 0 \\,\\,\\, \\forall t \\in \\RR \\overset{t = 0}{\\Longrightarrow} X^{\\text{T}} + X = 0\n\\end{equation}\nwhere we have set $X = \\dot{\\text{R}}(0)$ and used $\\text{R}(0) = \\text{R}^{\\text{T}}(0) = \\II_n$. Importantly, no further constraints come from the determinant condition since we are already in the neighbourhood of $\\II_n$ and hence the determinant must be $1$ as $\\Orth{n}$ is disconnected. Hence, $\\lie{\\Orth{n}} \\simeq \\lie{\\SO{n}} \\simeq \\set{X \\in \\text{Mat}_n(\\RR) : X^{\\text{T}} = - X}$. We could do the same for $\\Uni{n}$ and $\\SU{n}$ (where now we do need the determinant condition\\footnote{We make use of the identity $\\det\\left(\\II_n + Zt + o(t)\\right) = 1 + t(\\text{tr}Z) + o(t)$ to deduce that $\\text{tr}Z = 0$ in the case of $\\SU{n}$.}) to find;\n\\begin{equation}\n\\lie{\\SU{n}} = \\set{Z \\in \\text{Mat}_n(\\CC) : Z^\\dagger = - Z, \\text{tr}Z = 0}\n\\end{equation}\ni.e. the set of traceless\\index{traceless}, anti-hermitian\\index{anti-hermitian} $n \\times n$ matrices. Immediately we see that $\\dim \\SU{n} = \\dim \\lie{\\SU{n}} = n^2 -1$. We can apply this directly to $\\lie{\\SU{2}}$ which has dimension $3$. The three basis elements are provided by the Pauli matrices\\footnotemark\\index{Pauli matrices}, $\\sigma_a$, which are made anti-hermitian by defining the basis $T^a = -\\tfrac{1}{2} i \\sigma_a$. We can calculate the structure constants;\n\\footnotetext{Recall that the Pauli matrices are given by;\n\\begin{equation*}\n\\sigma_1 = \\twobytwo{0}{1}{1}{0}, \\quad \\sigma_2 = \\twobytwo{0}{-i}{i}{0},\\quad \\sigma_3 = \\twobytwo{1}{0}{0}{-1}\n\\end{equation*}\n}\n\\begin{equation}\n[T^a, T^b] = -\\tfrac{1}{4}[\\sigma_a, \\sigma_b] = -\\tfrac{1}{2}i\\epsilon_{abc}\\sigma_c = \\epsilon_{abc}T^c \\Rightarrow f\\indices{^{ab}_{c}} = \\epsilon_{abc}\n\\end{equation}\nPicking the obvious basis for $\\lie{\\SO{3}}$ now;\n\\begin{equation*}\n\\tilde{T}^1 = \\thrbythr{0 & 0 & 0}{0 & 0 & -1}{0 & 1 & 0}, \\quad \\tilde{T}^2 = \\thrbythr{0 & 0 & 1}{0 & 0 & 0}{-1 & 0 & 0}, \\quad \\tilde{T}^3 = \\thrbythr{0 & -1 & 0}{1 & 0 & 0}{0 & 0 & 0}\n\\end{equation*}\nwhich can be shown to have the same structure constants\\index{structure constants} as $\\lie{\\SU{2}}$.\n\\begin{definitionbox}\nIt is sufficient that the structure constants are the same for two Lie algebras to be isomorphic. Hence $\\lie{\\SO{3}} \\simeq \\lie{\\SU{2}}$ despite the fact that $\\SO{3} \\not\\simeq \\SU{2}$. Indeed it is the case that $\\SO{3} \\simeq \\SU{2} / \\ZZ_2$\n\\end{definitionbox}\nTo prove this last statement, suppose we have two Lie algebras $\\alge_1$, $\\alge_2$ of the same dimension with bases $\\set{T^a_1}$ and $\\set{T^a_2}$ respectively such that;\n\\begin{equation*}\n[T_1^a, T_1^b] = f\\indices{^{ab}_{c}}T^c, \\qquad [T^a_2, T^b_2] = g\\indices{^{ab}_{c}}T^c_2\n\\end{equation*}\nTo show that the two are isomorphic, it is sufficient to construct a Lie algebra isomorphism $\\phi : \\alge_1 \\rightarrow \\alge_2$. In other words, a linear vector space automorphism that preserves the bracket structure $\\phi([A, B]) = [\\phi(A), \\phi(B)]$. We propose the linear map that maps $\\phi(T_a^2) = T^a_2$ which are clearly linearly independent in $\\alge_2$ since $\\set{T^a_2}$ is a basis. They also span $\\alge_2$ so this is bijective. Now, consider;\n\\begin{align*}\n\\phi([T^a_1, T^b_1]) &= \\phi(f\\indices{^{ab}_{c}}T^c_1) \\\\\n&= f\\indices{^{ab}_{c}}\\phi(T^c_1) \\\\\n&= f\\indices{^{ab}_{c}}T^c_2 \\\\\n[\\phi(T^a_1), \\phi(T^b_1)] &= [T^a_2, T^b_2] \\\\\n&= g\\indices{^{ab}_{c}}T^c_2\n\\end{align*}\nSo we see that it is sufficient that $f\\indices{^{ab}_{c}} = g\\indices{^{ab}_{c}}$ for the Lie algebra isomorphism property to hold (taking suitable linear combinations of basis vectors). It is not necessary however since the structure constants are basis dependent. \n\\subsection{Why are Lie Groups special?}\nFor each $h \\in \\group$, consider constructing the smooth maps;\\footnote{They must be smooth since multiplication is smooth in $\\mM(\\group)$.}\n\\begin{itemize}\n\\item $L_h : \\group \\rightarrow \\group$ such that $g \\in \\group \\mapsto hg \\in \\group$\n\\item $R_h : \\group \\rightarrow \\group$ such that $g \\in \\group \\mapsto gh \\in \\group$\n\\end{itemize}\nThese are known as left/right translations\\index{translation}. We will now show that these are in fact bijections on $\\group$;\n\n\\paraskip\n\\textbf{Surjective} Consider $h \\in \\group$, now for all $g\\pr \\in \\group$, construct $h^{-1}g\\pr$ which must be in the group. So $h^{-1}g\\pr = g$ for some $g \\in \\group$. So $\\forall g\\pr \\in \\group$ $\\exists g \\in \\group$ such that $g\\pr = hg$. So $\\group = h\\group$. \n\n\\paraskip\n\\textbf{Injective} Suppose that $L_h(g) = L_h(g\\pr)$, then $hg = hg\\pr$, but $h^{-1} \\in \\group$, so $g = h^{-1}hg\\pr \\Rightarrow g = g\\pr$. \n\n\\paraskip\nSo $L_h$ (and in an identical fashion $R_h$) is injective and surjective, so it is bijective. We now switch focus from $\\group$ to $\\mM(\\group)$. As mentioned above, $L_h$ is smooth as a map on $\\mM(\\group)$ and we have just shown it is a bijection, so $L_h$ are \\emph{diffeomorphisms of} $\\mM(\\group)$. Now, if we introduce co-ordinates on the manifold $\\set{\\theta^i}$ in some region containing the identity, and let $\\tilde{g} = g(\\tilde{\\theta}) \\coloneqq L_h\\left(g(\\theta)\\right) = h\\cdot g(\\theta)$. Then $L_h$ is specified by $D$ real functions $\\tilde{\\theta}^i(\\theta)$. But, $L_h$ is a diffeomorphism as a map on manifolds, so the Jacobian;\n\\begin{equation*}\nJ\\indices{^{i}_{j}} = \\frac{\\del \\tilde{\\theta}^i}{\\del \\theta^j}\n\\end{equation*}  \nis non-degenerate/invertible. This is the key feature to what follows.\n\\subsubsection{Vector Fields on $\\mM(\\group)$}\nWe can view the map $L_h$ (or diffeomorphisms in general) as a change of co-ordinates on our manifold $\\theta \\mapsto \\tilde{\\theta}$. In a co-ordinate basis, the tangent spaces are spanned by $\\del/\\del\\theta^i$, so it is natural that $L_h : \\mM(\\group) \\rightarrow \\mM(\\group)$ should induce a map $L_h^{\\star}$ from tangent vectors at $g$ to tangent vectors at $L_h(g)$. We can think of this is a few ways; firstly we can imagine pulling back the vector/co-ordinates from the point $L_h(g)$. Secondly we can imagine changing co-ordinates across the manifold and leaving the vectors in place. More explicitly;\n\\begin{equation*}\nL_h^{\\star} : \\mathcal{T}_g(\\group) \\rightarrow \\mathcal{T}_{hg}(\\group)\n\\end{equation*} \nmaps $v = v^i \\del_{\\theta^i}$ to $\\tilde{v} = \\tilde{v}^i \\del_{\\tilde{\\theta}^i}$, where;\n\\begin{equation*}\n\\tilde{v}^i = J\\indices{^{i}_{j}} v^j\n\\end{equation*}\n$L_h^{\\star}$ is known as the \\emph{differential}\\index{differential} of $L_h$. As we mentioned above, the invertibility of $J$ is key here to ensure that this map has a trivial kernel i.e. no non-zero $v$ can be mapped to $\\tilde{v} = 0$. Taking this further, a \\emph{vector field}\\index{vector field} on $\\mM(\\group)$, $V$ specifies a tangent vector $V(g) \\in \\mathcal{T}_g(\\group)$ at each point $g \\in \\group$. In co-ordinates;\n\\begin{equation*}\nV(\\theta) = v^i(\\theta)\\frac{\\del}{\\del \\theta^i} \\in \\mathcal{T}_{g(\\theta)}(\\group)\n\\end{equation*}\nThe vector field is smooth if the component functions $v^i(\\theta)$ are differentiable. We are now in a position to understand the answer to the question posed at the start of this section. Starting from a tangent vector $\\omega \\in \\mathcal{T}_e(\\group)$, we can define a vector field on $\\group$;\\footnote{Note that we have been somewhat lazy throughout this section about when we use $\\group$ and when we use $\\mM(\\group)$. Essentially the Lie group structure ensures there is a one-to-one correspondence between the two which does not break the algebraic/differentiable structures in each object. As long as you are happy that, for example, $\\group$ doesn't have the notion of a tangent space (it is a group), but $\\mM(\\group)$ does so we can do the calculations there and transform back, then $\\mathcal{T}_g(\\group)$ should cause no confusion.}\n\\begin{equation}\nV(g) = L_g^{\\star}(\\omega) \\qquad \\forall g \\in \\group\n\\end{equation}\nWe know that $L_g^{\\star}$ is smooth, and more importantly invertible. If $\\omega \\neq 0$ initially, then it will remain as such. So $V(g)$ is smooth and everywhere non-vanishing. Starting from a basis $\\set{\\omega^a}$ of $\\mathcal{T}_e(\\group)$, we can thus construct $D$ nowhere vanishing vectors fields known as \\emph{left-invariant vector fields}\\index{vector field!left-invariant} on $\\group$; $V^a(g) = L_g^\\star(\\omega^a)$. This is a very strong constraint on $\\mM(\\group)$. Indeed for $D = 2$, the hairy ball theorem states that $S^2$ does not admit a nowhere vanishing vector field, so it \\emph{cannot be the case} that $\\mM(\\group) = S^2$ for any Lie group $\\group$. In fact, in $D = 2$, the only compact manifold that admits these vector fields is the torus $T^2 = S^1 \\times S^1$, so we can deduce that the only compact $2$-dimensional Lie group is actually $\\Uni{1} \\times \\Uni{1}$\n\\subsubsection*{Left Translation in a Matrix Group}\nSuppose now we have a matrix Lie Group $\\group \\subset \\text{Mat}(n, \\mathbb{F})$, then $\\forall h \\in \\group$ and $X \\in \\mL(\\group)$, we have $L_h^{\\star} = hX \\in \\mathcal{T}_h(\\group)$ where we can unambiguously understand $hX$ as matrix multiplication. We should check that $hX$ really lies in the tangent space at $h$;\n\\begin{examplebox}[Left Translation of a Curve]\nConsider the curve $C : t \\in \\RR \\mapsto g(t) \\in \\group$ such that $g(0) = e$ and $\\dot{g}(0) = X$. Then near $t = 0$ we must have;\n\\begin{equation*}\ng(t) = \\mathbb{I}_n + tX + o(t)\n\\end{equation*}\nNow, define a new curve $C\\pr : t\\in \\RR \\mapsto h(t) = hg(t) \\in \\group$, then near $t = 0$ we have;\n\\begin{equation*}\nh(t) = h + t hX + o(t)\n\\end{equation*}\nSo we see that indeed $hX \\in \\mathcal{T}_h(\\group)$. \n\\end{examplebox}\nWe can extend this idea, indeed for any $V \\in \\mathcal{T}_g(\\group)$, $L_h^\\star(V) \\in \\mathcal{T}_{hg}(\\group)$. Given a smooth curve $g(t) \\in \\group$, $\\dot{g}(t) \\in \\mathcal{T}_{g(t)}(\\group)$. Then, using our construction above;\n\\begin{equation}\nL_{g^{-1}(t)}^{\\star}\\left(g(t)\\right) \\in \\mathcal{T}_{g^{-1}(t)g(t)}(\\group) \\Rightarrow g^{-1}(t)\\dot{g}(t) \\in \\mathcal{T}_e(\\group) \\equiv \\mL(\\group)\n\\end{equation}\nSo we can always construct an element of the \\emph{Lie algebra} from $g^{-1}(t)\\dot{g}(t)$. Seen another way, suppose we are given $X \\in \\mL(\\group)$, we can reconstruct a curve $C : \\RR \\rightarrow \\group$ by solving the ODE:\n\\begin{equation}\n\\label{eq:matrixexp}\ng^{-1}(t)\\frac{\\ud g(t)}{\\ud t} = X \\qquad \\forall t \\in \\RR\n\\end{equation}\nwith boundary conditions $g(0) = \\mathbb{I}_n$. If we define the exponential of a matrix;\n\\begin{equation*}\n\\exp(M) = \\sum_{l = 0}^{\\infty}{\\frac{1}{l!}M^l} \\in \\text{Mat}(n, \\mathbb{F})\n\\end{equation*}\nThen we can solve \\eqref{eq:matrixexp} by setting $g(t) = \\exp(t X)$ for all $t \\in \\RR$. This follows just by noting that clearly $g(0) = \\mathbb{I}_n$ and;\n\\begin{equation*}\n\\dot{g}(t) = \\sum_{l = 1}^{\\infty}{\\frac{1}{(l - 1)!}t^{l - 1}X^l} = \\exp(tX)X\n\\end{equation*}\nThe fact that $g(t)$ solves this differential equation is enough to deduce that $g(t) = \\exp(tX) \\in \\group$. So we can exponentiate elements of the Lie algebra to get elements of the group. For a suitable range $J$, the set;\n\\begin{equation*}\nS_{X, J} = \\set{g(t) = \\exp(t X), \\,\\, \\forall t \\in J \\subset \\RR}\n\\end{equation*}\nis an Abelian Lie subgroup of $\\group$, known as a \\emph{one-parameter subgroup}.\\index{one-parameter subgroup}\n\\subsection{Constructing $\\group$ from $\\mL(\\group)$}\nIf we set $t = 1$ then we have a map $\\exp : \\mL(\\group) \\rightarrow \\group$ that is $1$:$1$ in some neighbourhood of the identity. In such a region we can construct group elements $g_X = \\exp(X)$, $g_Y = \\exp(Y)$ for some $X, Y \\in \\mL(\\group)$. The question then is how to take group products $g_X g_Y$. It turns out that if we identify $g_X g_Y = \\exp(Z) = g_Z$, then we can construct $Z$ \\emph{entirely from Lie Algebra operations} via the Baker-Campbell-Hasudorff formula;\n\\begin{equation}\nZ = X + Y + \\frac{1}{2}[X, Y] + \\frac{1}{12}\\left([X, [X, Y]] + [Y, [Y, X]]\\right) + \\cdots\n\\end{equation}\nNote that this expression definitely lies within the Lie algebra since the Lie bracket is closed. We see then that in a suitable neighbourhood of the identity, the Lie algebra, $\\mL(\\group)$, completely determines $\\group$. However, $\\exp$ is not globally bijective. In particular, $\\exp$ is not surjective when $\\group$ is not connected as is the case for $\\text{O}(3)$. This is because $\\exp$ is continuous and so can only have an image which lies in the neighbourhood of the identity. More generally, the image of $\\mL(\\group)$ under $\\exp$ is the whole of the component connected to the identity.\n\n\\paraskip\nAs an example of this consider $\\group = \\text{O}(n)$. Now $\\mL\\left(\\text{O}(n)\\right) = \\set{X \\in \\text{Mat}(n, \\RR): X + X^{\\text{T}} = 0}$. So $X \\in \\mL\\left(\\text{O}(n)\\right) \\Rightarrow \\tr X = 0$. We can then use;\\footnote{To prove this, or at least convince yourself of its validity, transform to a basis in which $X$ is diagonal.}\n\\begin{equation*}\n\\det\\left(\\exp X\\right) = \\exp\\left(\\tr X\\right) \\Rightarrow \\det\\left(\\exp X\\right) = 1 \\,\\,\\text{for}\\,\\,X \\in \\mL\\left(\\text{O}(n)\\right)\n\\end{equation*}\nSo we see that indeed $\\exp X \\in \\SO{n}$.\n\\subsubsection{Back to $\\SU{2}$ vs. $\\SO{3}$}\nReturning to the discussion of $\\SU{2}$ and $\\SU{3}$, we have seen that $\\mL\\left(\\SU{2}\\right) \\simeq \\mL\\left(\\SO{3}\\right)$, but that the two groups are not isomorphic since they have different homotopy classes. Now, we can construct a \\emph{double-covering}\\footnote{A globally $2$:$1$ map.} of $\\SO{3}$ as follows;\n\\begin{equation}\nd : \\SU{2} \\rightarrow \\SO{3}, \\qquad d(A)_{ij} = \\frac{1}{2}\\tr\\left(\\sigma_i A \\sigma_j A\\dagg\\right)\n\\end{equation}\nWe see that $d(A) = d(-A)$. This map provides an explicit isomorphism;\n\\begin{equation*}\n\\SO{3} \\simeq \\SU{2}/\\ZZ_2\n\\end{equation*}\nwhere $\\ZZ_2 = \\set{\\mathbb{I}, - \\mathbb{I}}$ is the centre of $\\SU{2}$. Geometrically, $\\SU{2} \\simeq S^3$, so $\\SO{3} \\simeq S^3/\\ZZ_2$, which is the $3$-sphere with antipodal points identified as we found previously. Thus we can parametrise $\\SO{3}$ by the upper hemisphere with points on the equator identified.\n\\newpage\n\\section{Introduction to Representations}\nIn what follows, it is useful to keep in mind that there is a clear distinction between \\emph{group} representations and representations of the \\emph{Lie algebra}, although they are very much related as we shall show below.\n\\subsection{Representations of Lie Groups}\n\\begin{definitionbox}[Representation]\nA \\emph{representation}, $D(\\group)$ of any group, $\\group$ (not necessarily Lie), is a linear group action $v \\mapsto D(g)v$ of $\\group$ on a vector space $V$ by invertible transformations. Equivalently, a representation is a set of non-singular matrices;\n\\begin{equation*}\n\\set{D(g) \\in \\text{Mat}(n, \\mathbb{F}), g \\in \\group}\n\\end{equation*}\nThe fact that $D(g)$ is a linear map says that;\n\\begin{equation}\nD(g)(\\alpha v_1 + \\beta v_2) = \\alpha D(g)v_1 + \\beta D(g)v_2\n\\end{equation}\nIn order to be a representation, it must also satisfy;\n\\begin{equation}\nD(g_1 g_2) = D(g_1) D(g_2) \\qquad \\forall g_1, g_2 \\in \\group\n\\end{equation}\nwhich is simply the statement that $D$ is a group homomorphism. In other words, the representation should preserve the group structure.\n\\end{definitionbox}\nThe vector space $V \\simeq \\mathbb{F}^n$ is known as the \\emph{representation space}. The dimension of $V$ is the dimension of the representation. A representation is called \\emph{faithful} if $D(g) = \\mathbb{I}_N$ only for $g = e$. If $\\group$ is also a Lie group, then we further need that $D$ is smooth.\\index{representation!faithful}\n\\subsubsection{Types of Representation}\nThere are a number of representations that are present for all Lie groups. These will reappear when we discuss representations of Lie algebras, whose form can be deduced from those below. In our opinion however, it is more natural to see the group representations first as they appear to be more canonical.\n\\begin{enumerate}\n\\item Let $\\group$ be a matrix Lie group with matrices of dimension $N$, then the representation $D(g) = g$ is called the \\emph{fundamental} representation of the group and is $N$-dimensional.\n\\item The representation of $\\group$ that sets $D(g) = \\mathbb{I}_N$ for all $g \\in \\group$ is known as the \\emph{trivial} representation.\\index{representation}\\index{representation!fundamental}\\index{representation!trivial}\\index{representation!adjoint}\n\\item Let $\\group$ be a matrix Lie group, and let $V = \\mL(\\group)$. The \\emph{adjoint} representation, $\\text{Ad}$, is the natural representation of $\\group$ on $\\mL(\\group)$.\n\\begin{equation}\nD(g)X \\equiv \\text{Ad g}X \\coloneqq g X g^{-1}, \\quad g \\in \\group, \\quad X \\in \\mL(\\group)\n\\end{equation}\nWe should do a few checks to see that this is a well-defined representation.\n\\begin{itemize}\n\\item \\textbf{Closure:} $g X g^{-1} \\in \\mL(\\group)$ follows since there exists some curve $h(t) = \\mathbb{I} + t X + \\cdots$ in $\\group$ with tangent $X$ at $t = 0$. Then $\\tilde{h}(t) = g\\cdot h(t)\\cdot g^{-1}$ is another curve in $\\group$ by group multiplication. But;\n\\begin{equation*}\n\\tilde{h}(t) = \\mathbb{I} + t gX g^{-1} + \\cdots\n\\end{equation*}\nSo we have constructed a curve with tangent $gX g^{-1}$, so $g X g^{-1} \\in \\mL(\\group)$. \n\\item \\textbf{Representation:} We should also show that $\\text{Ad}$ really is a representation. This follows as;\n\\begin{align*}\n(\\text{Ad}g_1 g_2)X &= g_1 g_2 X (g_1 g_2)^{-1} \\\\\n&= g_1 g_2 X g_2^{-1} g_1^{-1} \\\\\n&= \\left(\\text{Ad}g_1\\right)\\left(\\text{Ad}g_2\\right)X\n\\end{align*}\n\\end{itemize}\n\\item An $N$-dimensional representation $D$ of $\\group$ is said to be \\emph{unitary} if $D(g) \\in \\Uni{N}$ for all $g \\in \\group$.\n\\item Two representations are \\emph{equivalent} if $\\tilde{D}(g) = AD(g)A^{-1}$ for some fixed invertible transformation $A$ on $V$. This is just the statement that the two representations are related by a change of basis on $V$.\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%\\end{multicols*}", "meta": {"hexsha": "e94b5e4baba61d405561f2bc5c87dfe26cf2f7b9", "size": 43234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Part III/Revision Notes/sfp.tex", "max_stars_repo_name": "james-alvey-42/LectureNotes", "max_stars_repo_head_hexsha": "2e2c9c8082633379c26be5c06df06aa7a016fa96", "max_stars_repo_licenses": ["MIT"], "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 III/Revision Notes/sfp.tex", "max_issues_repo_name": "james-alvey-42/LectureNotes", "max_issues_repo_head_hexsha": "2e2c9c8082633379c26be5c06df06aa7a016fa96", "max_issues_repo_licenses": ["MIT"], "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 III/Revision Notes/sfp.tex", "max_forks_repo_name": "james-alvey-42/LectureNotes", "max_forks_repo_head_hexsha": "2e2c9c8082633379c26be5c06df06aa7a016fa96", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-26T17:48:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-26T17:48:29.000Z", "avg_line_length": 91.4038054968, "max_line_length": 1272, "alphanum_fraction": 0.6862654392, "num_tokens": 14935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6021304532850636}}
{"text": "% !TEX root = ../thesis.tex\n\n\\chapter{The Hopf map}\n\\label{chap:the-hopf-map}\n\\newcommand*{\\hquat}{h_\\textup{quat}}\n\\newcommand*{\\hproj}{h_\\textup{proj}}\nThe different definitions of $S^3$ and $S^2$ that were explored in the previous chapter\ngo along with different definitions of the Hopf map.\nIn this chapter we will give those definitions,\nand show that they are equivalent in the following sense:\nif $\\hproj$ and $\\hquat$ represent the projective and quaternionic definition of the Hopf map respectively,\nthen the following diagram commutes:\n\n\\vspace{-\\parskip}\n\\begin{center}\n\\begin{tikzcd}\n\\SC \\ar[r, two heads, \"\\hproj\"]\n    \\ar[d, leftrightarrow] &\n\\PC \\ar[d, leftrightarrow] \\\\\nS^3 \\ar[r, two heads, \"\\hquat\"] &\nS^2\n\\end{tikzcd}\n\\end{center}\n\n$S^3$ and $S^3_\\C$ were shown to be homeomorphic in proposition~\\ref{prop:s3-equivalence}.\nIn theorem~\\ref{thm:s2-homeom-p1c} it was stated that $\\PC$ and $S^2$ are homeomorphic,\nwhich we will be able to prove at last.\nFinally, the group actions explored in the previous chapter will be used to examine the fibres of the Hopf map.\n\n\\section{The projective Hopf map}\n\\label{sec:hopf-projective}\nAs we saw in section \\ref{sec:projective-space},\n$\\PC$ can be defined as a quotient of $\\CZ$ with respect to the action of $\\C^*\\!$.\nBecause $\\C^* \\cong \\Rpos \\times S^1\\!$,\nthe quotient map factors over $\\SC$ by theorem~\\ref{thm:quotient-map-factors},\nwhere $\\SC = \\CZ \\, / \\, \\Rpos$ as in definition \\ref{def:s3-complex}.\nThis allows us to define the Hopf map:\n\n\\definition[def:hopf-projective]\nThe \\emph{Hopf map} is the unique continuous map $h : \\SC \\surj \\PC$\nthat makes the following diagram commute:\n\\begin{center}\n\\begin{tikzcd}[column sep = small] &\n\\CZ \\ar[dl, \"r\", two heads, swap]\n    \\ar[dr, \"q\", two heads] & \\\\\n\\SC \\ar[rr, \"h\", two heads] & &\n\\PC\n\\end{tikzcd}\n\\end{center}\nBy theorem~\\ref{thm:quotient-map-factors},\nthe Hopf map is the quotient map of the $S^1$-action on $\\SC$.\n\nThis definition tells a lot about the Hopf map already.\nIt shows that its \\emph{fibres} — the inverse images of points in $\\PC$ —\nare orbits of the $S^1$-action;\nthe fibres can be parametrised by $S^1\\!$.\nIn section~\\ref{sec:fibres} we will explore the geometry of the fibres,\nwhich will turn out to be great circles on $S^3\\!$.\nFurthermore,\nbecause $h$ is the quotient map of a group action,\nit is surjective, continuous, and open by proposition~\\ref{prop:open-quotient-map}.\n\n\\section{The quaternionic Hopf map}\n\\label{sec:hopf-quaternionic}\nIn section \\ref{sec:quaternions} we defined $S^3$ and $S^2$ as subsets of $\\H$,\nwith $S^3$ acting on $S^2\\!$.\nWith this action,\nwe can define the Hopf map as follows:\n\n\\definition[def:hopf-quaternionic]\nThe \\emph{Hopf map} is the map\n\\[ h : S^3 \\longto S^2,\n   \\quad q \\longmapsto q^{-1} \\cdot i \\]\nRecall that ‘${}\\cdot{}$’ denotes the action,\n$q^{-1} \\cdot i = q^{-1} i q$.\nFor quaternion multiplication we will simply use juxtaposition.\nThe reason that we choose $q^{-1} \\cdot i$ here instead of $q \\cdot i$,\nwill become clear in theorem \\ref{thm:hopf-map-equivalence}.\nAn other way to think of this,\nis that $h$ is the map $q \\mapsto i \\cdot q = q^{-1} i q$,\nwhere $\\H^*$ acts \\emph{from the right} on $\\H$.\nThe quaternionic definition is more suitable for doing computations\nthan the projective definition,\nbecause it allows us to work with Cartesian coordinates on $S^2\\!$.\nThe image of the quaternion $q = a + bi + cj + dk \\in S^3$\nunder the Hopf map is given by\n\\begin{equationref}\n\\label{eqn:hopf-coordinates}\n\\begin{aligned}\nh(q) &= q^{-1} \\cdot i = q^{-1} \\, i \\, q = \\overline{q} \\, i \\, q\n  \\\\ &= (a - bi - cj - dk) \\, i \\, (a + bi + cj + dk)\n% \\\\ &= (a - bi - cj - dk) (ai - b + ck - dj)\n% \\\\ &= a^2 i - ab + ack - adj + (- bi - cj - dk) (ai - b + ck - dj)\n% \\\\ &= a^2 i - ab + ack - adj + ab + b^2i + bcj + bdk + (- cj - dk) (ai - b + ck - dj)\n% \\\\ &= a^2 i - ab + ack - adj + ab + b^2i + bcj + bdk + ack + bcj - c^2i - cd + (- dk) (ai - b + ck - dj)\n% \\\\ &= a^2 i - ab + ack - adj + ab + b^2i + bcj + bdk + ack + bcj - c^2i - cd - adj + bdk + cd - d^2i\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i - ab + ack - adj + ab + bcj + bdk + ack + bcj - cd - adj + bdk + cd\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ab - ab) + ack - adj + bcj + bdk + ack + bcj - cd - adj + bdk + cd\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ab - ab) + (cd - cd) + ack - adj + bcj + bdk + ack + bcj - adj + bdk\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ab - ab) + (cd - cd) + (ack + ack) - adj + bcj + bdk + bcj - adj + bdk\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ab - ab) + (cd - cd) + (ack + ack) + (bcj + bcj) - adj + bdk - adj + bdk\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ab - ab) + (cd - cd) + (ack + ack) + (bcj + bcj) + (bdk + bdk) - (adj + adj)\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + (ack + ack) + (bcj + bcj) + (bdk + bdk) - (adj + adj)\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + 2ack + 2bdk + (bcj + bcj) - (adj + adj)\n% \\\\ &= (a^2 + b^2 - c^2 - d^2) i + 2ack + 2bdk + 2bcj - 2adj\n  \\\\ &= (a^2 + b^2 - c^2 - d^2) i + 2 (bc - ad) j + 2 (ac + bd) k\n\\end{aligned}\n\\end{equationref}\nBecause $h$ is given by polynomial equations on every coordinate,\nit is continuous.\nBecause $S^3$ acts transitively on $S^2$ by corollary~\\ref{cor:transitive-s3-action},\n$h$ is surjective.\n\nThe projective definition of the Hopf map in section \\ref{sec:hopf-projective}\nemphasises that the fibres of the Hopf map are orbits of a group action.\nThe quaternionic definition given here,\ninstead emphasises \\emph{stabilisers} of a group action.\nThe fibre above $i$ consists of all $q \\in S^3$ with $q^{-1} \\cdot i = i$,\nthe stabiliser $S^3_i$ of $i$.\nThe fibre above $p \\in S^2$ is a right coset of the stabiliser.\nBecause $S^3$ acts transitively on $S^2$ by corollary~\\ref{cor:transitive-s3-action},\nthere exists an $x \\in S^3$ such that $p = x \\cdot i$.\nThe fibre above $p$ consists of all $q \\in S^3$ such that $q^{-1} \\cdot i = p$.\nIt follows that $q \\cdot x \\cdot i = q \\cdot p = i$,\nthus $qx$ stabilises $i$ and $h^{-1}(p) = S^3_i x^{-1}$.\n\nAt present, it is not at all obvious that the Hopf map as defined in\ndefinition~\\ref{def:hopf-projective} is related to the Hopf map as defined in definition~\\ref{def:hopf-quaternionic}.\nOn the contrary: we have not even proven that the codomains $\\PC$ and $S^2$ are homeomorphic.\nFortunately, we can prove both statements at once.\n\n\\theorem[thm:hopf-map-equivalence]\nDenote by $\\SC$ and $S^3$ the three-sphere as defined by\ndefinition~\\ref{def:s3-complex} and \\ref{def:s3-real} respectively.\nLet $\\Psi : \\CZ \\to \\H^*$ be the restriction\nof the $\\R$-linear isomorphism $(z_1, z_2) \\mapsto z_1 + z_2 j$.\nFrom proposition~\\ref{prop:s3-equivalence} it follows that\n$\\Psi$ descends to $\\psi : \\SC \\to S^3\\!$.\nDenote by $r$ the quotient map,\nby $s$ projection onto $S^3\\!$,\nand by $\\hproj$ and $\\hquat$ the Hopf map as defined in\ndefinition~\\ref{def:hopf-projective} and \\ref{def:hopf-quaternionic} respectively.\nThen there exists a unique homeomorphism $\\phi : \\PC \\to S^2$\nthat makes the following diagram commute:\n\n\\begin{center}\n\\begin{tikzcd}\n\\CZ  \\ar[r, two heads, \"r\"]\n     \\ar[d, \"\\Psi\"] &\n\\SC  \\ar[r, two heads, \"\\hproj\"]\n     \\ar[d, \"\\psi\"] &\n\\PC  \\ar[d, dashed, \"\\exists_! \\phi\"] \\\\\n\\H^* \\ar[r, two heads, \"s\"] &\nS^3  \\ar[r, two heads, \"\\hquat\"] &\nS^2\n\\end{tikzcd}\n\\end{center}\n\n\\proof\nWe will show that $\\Phi = \\hquat \\circ s \\circ \\Psi$ is compatible\nwith the quotient map $\\CZ \\surj \\PC$.\nLet $(z_1, z_2) \\in \\CZ$ and $z \\in \\C^*\\!$,\nsuch that $(z_1 : z_2) = (zz_1 : zz_2)$.\nBecause $\\C^*$ stabilises $i \\in S^2\\!$,\nwe have\n\\begin{align*}\n\\Phi(z z_1, z z_2)\n\\, = \\, (z z_1 + z z_2 j)^{-1} \\cdot i\n\\, = \\, (z_1 + z_2 j)^{-1} \\cdot (z^{-1} \\cdot i)\n\\, = \\, (z_1 + z_2 j)^{-1} \\cdot i\n\\, = \\, \\Phi(z_1, z_2)\n\\end{align*}\nBy the universal property of the quotient topology (theorem \\ref{thm:universal-property-quotient-topology}),\nthere exists a unique continuous map $\\phi$ that makes the diagram commute.\n\nTo give the inverse of $\\phi$,\nlet a point $p \\in S^2$ be given.\nWe saw before that there exists an $x \\in S^3$ with $p = x \\cdot i$,\nsuch that $\\hquat^{-1}(p) = S^3_i x^{-1}$.\nBecause $S^3_i = S^1 \\subseteq \\C^*\\!$,\nwe can write every point in $S^3$ that maps to $p$ as $zx^{-1}$ for some $z \\in S^1$,\nand we can write $x^{-1}$ as $z_1 + z_2 j$ for some $z_1, z_2 \\in \\C$.\nTherefore, all points in the fibre above $p$ map to $(z_1 : z_2)$\nunder $\\hproj \\circ \\psi^{-1}$.\nTo show that this does not depend on the choice of $x$,\nnote that if we had $y \\in S^3$ with $p = y \\cdot i$,\nthen $x = yz^{-1}$ for some $z \\in S^1\\!$,\nso $x^{-1} = z y^{-1}$.\n\nRecall that $S^3_\\C$ is compact by proposition \\ref{prop:s3-equivalence},\nso $\\PC$ is compact,\nfor it is the continuous image of a compact space.\n$S^2$ is Hausdorff because it is a subspace of $\\H$,\nwhich is Hausdorff.\nTherefore, $\\phi$ is a continuous bijection from a compact space to a Hausdorff space.\nIt follows that $\\phi$ is a homeomorphism.\n(See for instance theorem 3.3.11 of \\parencite[p.~81]{runde2005}.)\n\\qed\n\nUsing equation~\\ref{eqn:hopf-coordinates},\nwe can give an explicit expression for $\\phi$.\nUsing equation~\\ref{eqn:transitive-s3-action},\nwe can give an explicit expression for $\\phi^{-1}$:\n\\begin{equationref}\n\\begin{aligned}\n(a + bi : c + di) &\\longmapsto (a^2 + b^2 - c^2 - d^2) i + 2 (bc - ad) j + 2 (ac + bd) k \\\\\n(i + \\alpha i : \\beta + \\gamma i) &\\longmapsfrom \\alpha i + \\beta j + \\gamma k\n\\end{aligned}\n\\end{equationref}\nIt is assumed here that $a^2 + b^2 + c^2 + d^2 = 1$\nand $\\alpha^2 + \\beta^2 + \\gamma^2 = 1$,\nwith $\\alpha \\neq -1$.\nFor $\\alpha = -1$, we have $\\phi^{-1}(-i) = (0 : 1)$.\nNote that it is impossible to give a globally valid expression for $\\phi^{-1}$:\nthe map $\\phi \\circ h : S^3_\\C \\surj S^2$ does not admit a global continuous section.\nIf it did, this would imply that $S^3 = S^2 \\times S^1\\!$,\nwhich is not the case.\n\n\\subsection*{Informal summary}\nIn this section and in the previous section,\nwe have given two definitions of the Hopf map.\nThe projective definition as given in definition~\\ref{def:hopf-projective}\ncan be written as $h : \\SC \\surj \\PC$, $(z_1, z_2) \\mapsto (z_1 : z_2)$.\nRecall that if $z_2$ is nonzero, $(z_1 : z_2)$ may be thought of as $z_1 / z_2$.\nThis shows that multiplying $z_1$ and $z_2$ by $e^{it}$ for any $t \\in \\R$\ndoes not change the image under the Hopf map.\nIt follows that the fibres of the Hopf map are circular,\na feature that will be explored further in the next section.\nDefinition~\\ref{def:hopf-quaternionic} gives an alternative\ndefinition of the Hopf map based on quaternions.\nThis definition is useful for doing computations,\nbecause it allows us to work with Cartesian coordinates on $S^2\\!$.\nTheorem~\\ref{thm:hopf-map-equivalence} shows that both definitions are equivalent.\nThis theorem also shows that $\\PC$ and $S^2$\nare \\emph{homeomorphic},\nmeaning that for topological purposes\nthey are indistinguishable.\n\n\\section{Fibres}\n\\label{sec:fibres}\nThe Hopf map,\na surjective, continuous map from $S^3$ to $S^2\\!$,\nis interesting for many reasons.\nThe primary reason that we are interested in it here,\nare its fibres.\nThose are circles in $S^3$ that — as we will see in section~\\ref{sec:linking} —\nare linked, like keyrings can be linked.\nMoreover, \\emph{all} fibres are linked with \\emph{every} other fibre.\nBefore we can study linking however,\nwe will first introduce the tools for studying the fibres.\n\nIn section~\\ref{sec:hopf-quaternionic},\nwe saw already that the fibre above $p \\in S^2$\nis given by $S^1 x^{-1}$,\nwhere $x \\in S^3$ is such that $x \\cdot i = p$.\nIn combination with equation~\\ref{eqn:transitive-s3-action}\n(an expression for $x$),\nthis allows us to explicitly parametrise the fibres of the Hopf map.\nWhile such an expression is useful for computations,\nit does not give us any geometrical insight.\nTherefore, we will study the fibes of the Hopf map in a different way.\nFor this,\nwe will first revisit the $\\GLC$ action on $\\CZ$.\n\nIn section~\\ref{sec:projective-space} we saw how $\\GLC$ acts on $\\CZ$.\nEvery element of $\\GLC$ induces a homeomorphism $\\CZ \\to \\CZ$.\nThese homeomorphisms are restrictions\nof $\\C$-linear (and thereby also $\\R$-linear) automorphisms $\\C^2 \\to \\C^2\\!$,\nwhich means the action descends to $S^3_\\C$ and $\\PC$.\n\n\\proposition[prop:gl2c-induces-actions]\nLet $\\alpha : \\C^2 \\to \\C^2$ be a $\\C$-linear automorphism.\nThen there exist unique homeomorphisms $\\beta, \\gamma, \\delta$\nthat make the following diagram commute:\n\\begin{center}\n\\begin{tikzcd}\n\\C^2   \\ar[d, \"\\alpha\"] &\n\\CZ    \\ar[d, dashed, \"\\exists_! \\, \\beta\"]\n       \\ar[l, hook, swap, \"i\"]\n       \\ar[r, two heads, \"r\"]\n       \\ar[rr, two heads, bend left, \"q\"{pos = 0.525}] &\nS^3_\\C \\ar[d, dashed, \"\\exists_! \\, \\gamma\"]\n       \\ar[r, two heads, \"h\"] &\n\\PC    \\ar[d, dashed, \"\\exists_! \\, \\delta\"] \\\\\n\\C^2   &\n\\CZ    \\ar[l, hook, swap, \"i\"]\n       \\ar[r, two heads, \"r\"]\n       \\ar[rr, two heads, bend right, swap, \"q\"{pos = 0.525}] &\nS^3_\\C \\ar[r, two heads, \"h\"] &\n\\PC\n\\end{tikzcd}\n\\end{center}\nHere $q$ and $r$ denote the quotient maps,\n$i$ denotes the inclusion,\nand $h$ denotes the Hopf map.\n\n\\proof\nThe map $\\beta$ is the restriction of $\\alpha$ to $\\CZ$.\nThe map $r \\circ \\beta$ is compatible with $r$\nbecause $\\beta$ is $\\R$-linear;\nif two elements are equivalent in $\\CZ$,\nthen their images under $\\beta$ are also equivalent.\nBy the universal property of the quotient topology\n(theorem~\\ref{thm:universal-property-quotient-topology}),\nwe get a unique continuous map $\\gamma$.\nBy applying this argument to $\\beta^{-1}$,\nwe find a unique continuous map $\\gamma^{-1}$ which is the inverse of $\\gamma$,\nso $\\gamma$ is a homeomorphism.\nSimilarly,\nthe map $q \\circ \\beta$ is compatible with $q$,\nbecause if two elements in $\\CZ$ differ by a factor $\\lambda \\in \\C^*\\!$,\nthen their images under $\\beta$ differ by a factor $\\lambda$,\nas $\\beta$ is $\\C$-linear.\nBy the universal property of the quotient topology\nwe get a unique homeomorphism $\\delta$ that makes the diagram commute.\n\\qed\n\nThis proposition tells us that the action of $\\GLC$\ndescends naturally to $S^3_\\C$ and $\\PC$\nby letting $g \\in \\GLC$ act on a representative.\nBeware that although $\\GLC$ acts on $\\CZ$ by linear automorphisms,\nthe induced automorphisms are \\emph{not} linear;\nin general they are not linear automorphisms of $\\R^4$ and $\\R^3$\nrestricted to $S^3$ and $S^2\\!$.\n\nThe general linear group $\\GLR$ also acts on $\\C^2\\!$,\nand by restriction on $\\CZ$\nwhen $\\C^2$ is considered a four-dimensional real vector space.\nThis action induces an action of $\\GLR$ on $S^3_\\C$;\nthe same argument as before holds.\nHowever, this action does \\emph{not} induce an action on $\\PC$,\nbecause elements of $\\GLR$ are not $\\C$-linear automorphisms in general.\n\nWe saw already that the fibres of the projective hopf map are the\norbits of the $S^1$-action on $\\CZ$.\nThis allows us to parametrise fibres easily.\nFor $(z_1 : z_2) \\in \\PC$,\nif we assume that $|z_1|^2 + |z_2|^2 = 1$,\nand if we work with $S^3$ instead of $S^3_\\C$ by taking representatives of unit length,\nwe have:\n\\[ h^{-1}(z_1 : z_2) = \\set{ (e^{it} z_1, e^{it} z_2) \\in S^3 \\mid t \\in \\R } \\]\nFor the fibres above $(1 : 0)$ and $(0 : 1)$,\nthe geometrical picture is clear:\nthe fibres are unit circles in the planes spanned by $(1, 0)$ and $(i, 0)$,\nand $(0, 1)$ and $(0, i)$ respectively.\nBecause the circles have unit radius,\nthey are great circles on $S^3\\!$.\nAn other way to state this,\nis that the fibres are precisely the intersections of $S^3$ with complex linear subspaces of dimension one\n(in particular those are intersections of $S^3$ with real linear subspaces of dimension two).\nFor other points on $\\PC$ however,\nit is not immediately clear what the fibres look like.\nThis is where the $\\GLC$-action is useful.\nVia the homeomorphism $S^3_\\C \\to S^3$ from proposition~\\ref{prop:s3-equivalence},\n$\\GLC$ acts on $S^3\\!$.\nIf $g \\in \\GLC$ maps $(0 : 1)$ to $(z_1 : z_2)$,\nthen commutativity of the diagram in proposition~\\ref{prop:gl2c-induces-actions}\nmeans that $g$ maps the fibre above $(0 : 1)$ into the fibre above $(z_1 : z_2)$.\nThe fibre above $(0 : 1)$ is the intersection of a linear subspace\nwith $S^3\\!$,\nand because $g$ is linear,\nthe fibre above $(z_1 : z_2)$ is also the intersection of a linear subspace\nwith $S^3\\!$.\nTherefore it is a great circle as well.\n\n\\proposition[prop:glc-acts-transitively]\n$\\GLC$ acts transitively on $\\PC$.\n\n\\proof\n$\\GLC$ acts transitively on $\\CZ$.\nBecause $\\PC$ is a quotient space of $\\CZ$,\nevery element can be represented by an element of $\\CZ$,\nand because $\\GLC$ acts transitively,\nevery representative can be reached from e.g. $(0, 1)$.\n\\qed\n\n\\corollary\nAll fibres of the Hopf map are great circles on $S^3\\!$.\nWe saw already that for all $g \\in \\GLC$,\nthe fibre above $g \\cdot (0 : 1)$ is a great circle,\nand because $\\GLC$ acts transitively,\nevery point in $\\PC$ is of this form.\n\n\\section{Stereographic projection}\nThe fibres of the Hopf map that we investigated in the previous section\nare subsets of $S^3\\!$.\nBut $S^3$ can be hard to visualise;\nit is a subset of a four-dimensional space.\nFurthermore, with the goal of constructing a vector field on $\\R^3$ in mind,\nwe somehow have to get to $\\R^3\\!$.\nThe way we can move between $\\R^3$ and $S^3$ is by stereographic projection.\nGiven that $S^3$ and $\\R^3$ are not homeomorphic,\nwe will have to make some concessions.\nFortunately $S^3$ is the one-point compactification of $\\R^3\\!$,\nso if we want to go from $S^3$ to $\\R^3$\nwe only loose a single point.\nNevertheless, this discrepancy will turn out to introduce some artefacts,\nbut these will in turn help to understand the geometry of $S^3\\!$.\n\n\\definition\nThe \\emph{stereographic projection} from $S^n$ onto $\\R^n\\!$,\nwith projection point $p \\in S^n$ is given by\n\\[ \\pi : S^n \\setminus \\set{p} \\longto \\R^n,\n   \\quad x \\longmapsto \\overline{px} \\cap \\R^n \\]\nHere we embed $\\R^n$ in $\\R^{n + 1}$ as $p^\\perp\\!$,\nand $\\overline{px}$ denotes the line connecting $p$ and $x$.\n\nWe will use coordinates $x_0, \\ldots, x_n$ on $\\R^{n + 1}$\nand coordinates $x_1, \\ldots, x_n$ on $\\R^n\\!$.\nSetting $p = (1, 0, \\ldots, 0)$\nfixes the embedding of $\\R^n$ in $\\R^{n + 1}$ via $(x_1, \\ldots, x_n) \\mapsto (0, x_1, \\ldots, x_n)$.\nThe connection line $\\overline{px}$ can then be parametrised as $p + \\lambda(x - p)$ for $\\lambda \\in \\R$.\nIntersecting this line with the hyperplane $x_0 = 0$ by setting\n$p_0 + \\lambda(x_0 - p_0) = 0$ yields $\\lambda = - \\frac{1}{x_0 - 1}$,\nwhere the subscript zero denotes the first coordinate.\nSubstituting $\\lambda$, we find the projection of $x$:\n\\begin{equationref}\n\\label{eqn:stereographic-projection}\n   \\pi(x_0, \\ldots, x_n)\n = \\left(-\\frac{x_1}{x_0 - 1}, \\ldots, -\\frac{x_n}{x_0 - 1} \\right)\n = \\left(\\frac{x_1}{1 - x_0}, \\ldots, \\frac{x_n}{1 - x_0} \\right)\n\\end{equationref}\nConversely, if we have a point $x \\in \\R^n\\!$,\nthen we can embed it in $\\R^{n + 1}$ and parametrise the line through $x$ and $p$\nas $p + \\lambda(x - p)$ for $\\lambda \\in \\R$.\nThis time we want to find the intersection with $S^n\\!$,\nso we must solve $\\nsq{p + \\lambda(x - p)} = 1$.\nThis yields $\\lambda = \\frac{2}{\\nsq{x} + 1}$.\nSubstituting $\\lambda$, we find the inverse image of $x$:\n\\begin{equationref}\n\\label{eqn:inverse-stereographic-projection}\n    \\pi^{-1}(x_1, \\ldots, x_n)\n% = \\left(1 - \\frac{2}{\\nsq{x} + 1}, \\frac{2x_1}{\\nsq{x} + 1}, \\ldots, \\frac{2x_n}{\\nsq{x} + 1} \\right)\n  = \\frac{1}{\\nsq{x} + 1} \\left(\\nsq{x} - 1, \\, 2x_1, \\, \\ldots, \\, 2x_n \\right)\n\\end{equationref}\nFrom equation~\\ref{eqn:stereographic-projection} and \\ref{eqn:inverse-stereographic-projection}\nit is clear that $\\pi$ and $\\pi^{-1}$ are continuous.\nIt follows that $\\pi$ is a homeomorphism between $S^n \\setminus \\set{p}$ and $\\R^n\\!$.\n\nIt turns out that the stereographic projection of a circle on $S^n$\nis a circle in $\\R^n\\!$,\na property that will be useful when studying the fibres of $h \\circ \\pi^{-1}$.\nTo see why this is the case,\nwe will first study the more general mapping of spheres.\n\n\\definition\nA \\emph{sphere} in $S^n$ is the intersection of $S^n$\nwith a hyperplane given by $\\inp{x}{\\hat{n}} = t$,\nwhere $\\hat{n} \\in S^n$ is a normal vector of the hyperplane,\nand $t \\in (-1, 1)$ is its offset to the origin.\nWe choose $|\\,t\\,| < 1$ such that the intersection is not empty or finite.\n\n\\example\nA sphere in $S^2$ is simply a circle.\nIf $t = 0$, it is a great circle.\n\n\\definition\nA \\emph{sphere} in $\\R^n$ with centre $x_c \\in \\R^n$ and radius $r \\in \\Rpos$\nis the set\n\\[ \\set{ x \\in \\R^n \\mid r^{\\,2} = \\nsq{x - x_c} } \\]\nNote that a sphere in $S^n$ is the intersection of a sphere in $\\R^{n + 1}\\!$ with $S^n\\!$.\nBy expanding the square,\nwe may alternatively write a sphere in $\\R^n$\nwith centre $x_c$ and radius $r$ as\n\\begin{equationref}\n\\label{eqn:hypersphere}\n\\set{ x \\in \\R^n \\mid r^{\\,2} - \\nsq{x_c} = \\nsq{x} - 2 \\inp{x}{x_c} }\n\\end{equationref}\nNow we can turn to the relation between spheres in $S^n$ and in $\\R^n\\!$.\n\n\\proposition\nLet $B \\subseteq S^n$ be a sphere defined by the normal vector $\\hat{n} \\in S^n$\nand offset $t \\in (-1, 1)$.\nThen for its image under the stereographic projection $\\pi : S^n \\setminus \\set{p} \\to \\R^n\\!$,\nthe following holds:\n\\begin{enumerate}\n\\item If $p \\notin B$, $\\pi(B)$ is a sphere in $\\R^n\\!$.\n\\item If $p \\in B$, $\\pi(B \\setminus \\set{p})$ is a hyperplane in $\\R^n\\!$.\n\\end{enumerate}\n\n\\proof\nThe image of $B$ or $B \\setminus \\set{p}$ when $p \\in B$,\nis given by the set of $x \\in \\R^n$ such that $\\pi^{-1}(x) \\in B$.\nEmbed $\\R^n$ in $\\R^{n + 1}$ as the hyperplane $x_0 = 0$.\nThen we can write\n\\[ \\pi(B)\n\\ = \\ \\set{x \\in \\R^n \\mid \\inp{\\pi^{-1}(x)}{\\hat{n}} = t }\n\\ = \\ \\set{x \\in \\R^n \\mid n_0(\\nsq{x} - 1) + \\inp{x}{\\hat{n}} = t } \\]\nHere $n_0$ denotes the first coordinate of $\\hat{n}$.\nIf $n_0 \\neq 0$,\nwe recognise equation~\\ref{eqn:hypersphere},\nso $\\pi(B)$ is a sphere in $\\R^n\\!$.\nIf $n_0 = 0$,\nthen the predicate reduces to $\\inp{x}{\\hat{n}} = t$,\nwhich is the equation for a hyperplane in $\\R^n$ with normal $\\hat{n}$\nand offset $t$ to the origin.\nFurthermore, $n_0 = 0$ if and only if $p \\in B$.\n\\qed\n\n\\proposition\nLet $n \\geq 2$ and let $C \\subseteq S^n$ be a circle,\nthe nonempty intersection of $n - 1$ spheres\ndefined by hyperplanes with linearly independent normal vectors.\nThen for its image under the stereographic projection $\\pi : S^n \\setminus \\set{p} \\to \\R^n\\!$,\nthe following holds:\n\\begin{enumerate}\n\\item If $p \\notin C$, $\\pi(C)$ is a circle in $\\R^n\\!$.\n\\item If $p \\in C$, $\\pi(C \\setminus \\set{p})$ is a line in $\\R^n\\!$.\n\\end{enumerate}\n\n\\proof\nWe use the fact that for $U, V \\subseteq S^n\\!$,\nwe have $\\pi(U \\cap V) = \\pi(U) \\cap \\pi(V)$.\nAs $C$ is the intersection of $n - 1$ spheres,\nits image is the intersection of $n - 1$ spheres or hyperplanes.\nThese all lie in distinct hyperplanes with linearly independent normal vectors,\nso the image is a subset of a two-dimensional plane in $\\R^n\\!$.\nIf $p \\notin C$ then at least one of the images will be a sphere,\nso $\\pi(C)$ is a circle.\nIf $p \\in C$ then all of the images will be distinct hyperplanes,\nthe intersection of which is a line.\n\\qed\n\n\\corollary[cor:circles-and-axis]\nThe fibres of $h \\circ \\pi^{-1}$ are all circles in $\\R^3\\!$,\nexcept for the fibre above $(1 : 0)$ which is the $x_1$-axis.\nFurthermore, from equation~\\ref{eqn:stereographic-projection} it is clear\nthat the fibre above $(0 : 1)$ is the unit circle in the $x_2 x_3$-plane.\nThis has been visualised in figure~\\ref{fig:two-fibres}.\n\n\\begin{figure}\n\\definecolor{f1c}{hsb}{0.6, 0.6, 0.5}\n\\definecolor{f2c}{hsb}{0.0, 0.8, 0.6}\n\\margincaption[3em]{\\label{fig:two-fibres}\nFibres of the Hopf map visualised through stereographic projection;\nthe fibre above $ i \\in S^2$ is the $x_1$-axis (coloured {\\color{f2c}•}),\nthe fibre above $-i \\in S^2$ is the unit circle in the plane $x_1 = 0$\n(coloured {\\color{f1c}•}).\nSee also figure~\\ref{fig:more-fibres}.}\n\\begin{python}\nfrom hopf import *\nfrom math import pi\npr         = orthographic_projection(pi * 0.42, pi * -0.1)\nfibre_x2x3 = [compose(pr, projected_fibre_from_spherical([-pi * 0.5, 0.0])), 'f1f', 'back']\nfibre_x1_b = [compose(pr, projected_fibre_from_degenerate(-1.6, -1.4)), 'f2f-dot', 'back']\nfibre_x1   = [compose(pr, projected_fibre_from_degenerate(-1.4,  1.4)), 'f2f', 'back']\nfibre_x1_e = [compose(pr, projected_fibre_from_degenerate( 1.4,  1.6)), 'f2f-dot', 'back']\ncmds = generate_raw_draw_2d(0.5, [fibre_x2x3, fibre_x1, fibre_x1_b, fibre_x1_e])\nbox  = generate_raw_box_2d([1.5, 1.5, 1.5], pr, 'box')\nwrite_items('generated/two-fibres-box.tikz', cons(box, cmds))\n\nlatm   = generate_raw_latitude_2d(0.0, pr, 'dashed')\npoints = [[[-pi * 0.5, 0.0], 'f1c'], [[pi * 0.5, 0.0], 'f2c']]\ncmds   = generate_raw_points_2d(pr, points, '1.3pt')\nwrite_items('generated/two-fibres-sphere.tikz', cons(latm, cmds))\n\\end{python}\n\\begin{center}\n\\tikzexternalenable\n\\tikzsetnextfilename{two-fibres}\n\\begin{tikzpicture}\n\\tikzstyle{back} = [white, line width = 3pt];\n\\tikzstyle{f1f} = [f1c, line width = 1pt];\n\\tikzstyle{f2f} = [f2c, line width = 1pt];\n\\tikzstyle{f2f-dot} = [f2f, dotted, line cap = round];\n\\tikzstyle{box} = [line width = 0.47pt];\n\\coordinate (D) at (-3, 0);\n\\coordinate (C) at ( 3, 0);\n\n\\begin{scope}[shift = {(D)}, scale = 1.2, local bounding box = {domain}]\n\\input{generated/two-fibres-box.tikz}\n\\end{scope}\n\n% Draw S^2.\n\\begin{scope}[shift = {(C)}, scale = 1.5, local bounding box = {codomain}]\n\\draw[line width = 0.47pt] (0, 0) circle (1);\n\\input{generated/two-fibres-sphere.tikz}\n\\end{scope}\n\n% Draw an arrow from the plot to S^2 with tikzcd arrow style.\n\\begin{scope}[commutative diagrams/every diagram]\n\\path let \\p1 = (domain.east) in node (from) at (\\x1 + 1em, 0) {};\n\\path let \\p1 = (codomain.west) in node (to) at (\\x1 - 1em, 0) {};\n\\path[commutative diagrams/.cd, every arrow, every label]\n  (from) edge [commutative diagrams/maps to] node {$h \\circ \\pi^{-1}$} (to);\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\n\\section{Linking}\n\\label{sec:linking}\nThe fibres of the Hopf map — circles, as shown in the previous section — possess an interesting property:\nthey are all linked with every other fibre.\nIn this section we will give a formal definition of linking,\nand prove linkedness of the fibres.\nIn section~\\ref{sec:linked-and-knotted-fields} we will explore a physical application of linking.\n\nLinking is a property of a pair of closed curves\nthat is not intrinsic to the curves as topological spaces themselves,\nbut rather to their embedding in a surrounding space.\nConsidering this, it makes sense to look at the complement of the curves.\nBy studying the fundamental group of the complement,\nwe can tell different situations apart.\nFor instance,\nthe fundamental group of the complement of two linked circles in $\\R^3$\nis the free abelian group on two generators,\nwhereas the fundamental group of the complement of two unlinked circles\nis the free \\emph{nonabelian} group on two generators.\n(See \\parencite[p.~46]{hatcher2002}.\nIncidentally, Hatcher introduces linking\nas one of the main motivations for studying the fundamental group.)\n\n\\definition\nLet $X$ be a topological space.\nAn \\emph{$n$-link} in $X$ is an ordered collection of $n$ continuous maps $\\sigma_i : S^1 \\to X$,\nsuch that the images of $\\sigma_1, \\ldots, \\sigma_n$ are disjoint.\nThe link is called \\emph{proper} if every $\\sigma_i$ is a homeomorphism onto its image.\n\nThis definition is based on \\parencite{milnor1954}.\nBecause in a proper link every $\\sigma_i$ is a homeomorphism onto its image,\nthe components of the link do not self-intersect.\nBecause the images are disjoint,\nthey do not intersect eachother.\n\n\\definition\nTwo $n$-links $(\\sigma_1, \\ldots, \\sigma_n)$ and $(\\tau_1, \\ldots, \\tau_n)$\nare said to be \\emph{homotopic}\nif there exist homotopies $H_i : [0, 1] \\times S^1 \\to X$ from $\\sigma_i$ to $\\tau_i$,\nsuch that for all $t \\in [0, 1]$,\nthe images of $H_i(t, {}\\cdot{})$ are disjoint.\nThe links are said to be \\emph{properly homotopic} if\nfor all $t \\in (0, 1)$ the maps $H_i(t, {}\\cdot{})$ are homeomorphisms onto their images.\nHomotopy and proper homotopy define two equivalence relations on the set of $n$-links.\nWe call a proper $n$-link \\emph{trivial}\nif it is properly homotopic to an $n$-link of $n$ distinct constant functions.\n\nA homotopy between links captures the idea of links being “the same”.\nHomotopy enables us to tell apart many different types of links,\nbut there is one caveat:\na homotopy from one link into another might have self-intersecting components\nat some point in time.\nFor instance, the Whitehead link is homotopic to two unlinked circles,\nbut it can only be unlinked if the components are allowed to self-intersect.\n\\marginfigure{\n\\tikzexternalenable\n\\tikzsetnextfilename{whitehead-link}\n\\begin{center}\n\\hspace{-1em}\n\\begin{tikzpicture}[baseline={(C.base)}]\n\\tikzstyle{back} = [line width = 4.94pt, black]\n\\tikzstyle{knot} = [line width = 4.0pt, white]\n\\setlength{\\kr}{2em}\n\\coordinate (A) at ( 45 : 2\\kr);\n\\coordinate (B) at (-45 : 2\\kr);\n\\coordinate (C) at ($ (A) !.5! (B) $); % Half-way between (A) and (B).\n\n\\useasboundingbox let \\p1 = (A), \\p2 = (B) in\n            (\\x1 - \\kr - 2.5pt, \\y1 + \\kr + 2.5pt) rectangle\n            (\\x2 + \\kr + 2.5pt, \\y2 - \\kr - 2.5pt);\n\n\\draw[back] (C) circle (\\kr);\n\\draw[knot] (C) circle (\\kr);\n\n\\draw[back] ($(B) + (270 : \\kr)$) arc (270 : 135 : \\kr) -- (C) --\n            ($(A) + (-45 : \\kr)$) arc (-45 :  90 : \\kr);\n\\draw[knot] ($(B) + (270 : \\kr)$) arc (270 : 135 : \\kr) -- (C) --\n            ($(A) + (-45 : \\kr)$) arc (-45 :  90 : \\kr);\n\n\\draw[back] ($(A) + (89 : \\kr)$) arc (89 : 225 : \\kr) -- (C) --\n            ($(B) + (45 : \\kr)$) arc (45 : -91 : \\kr);\n\\draw[knot] ($(A) + (88 : \\kr)$) arc (88 : 225 : \\kr) -- (C) --\n            ($(B) + (45 : \\kr)$) arc (45 : -92 : \\kr);\n\n\\draw[back] ($(C) + (120 : \\kr)$) arc (120 : 150 : \\kr);\n\\draw[knot] ($(C) + (119 : \\kr)$) arc (119 : 151 : \\kr);\n\n\\draw[back] ($(C) + (-30 : \\kr)$) arc (-30 : -60 : \\kr);\n\\draw[knot] ($(C) + (-29 : \\kr)$) arc (-29 : -61 : \\kr);\n\\end{tikzpicture}\n\\end{center}\n\\vspace{1em}\n\\caption{The Whitehead link.}}\nWith the notion of proper homotopy we can also differentiate between\nthe Whitehead link and and unlinked circles:\nthe unlinked circles are trivial,\nbut the Whitehead link is not.\nThese types of links are beyond the scope of this thesis though;\nfor the fibres of the Hopf map\nthe notion of homotopy will be sufficient.\nTo determine whether two closed curves are linked,\nwe will examine the fundamental group of the complement of \\emph{one} curve.\nThe other curve then determines an element of the fundamental group.\nIf the fundamental group happens to be $\\Z$,\nwe can quantify linking with an integer.\n\n\\definition\nLet $(\\sigma_1, \\sigma_2)$ be a proper two-link in a topological space $X$.\nSuppose that $G_1 = \\pi_1(X \\setminus \\im \\sigma_1,\\, \\sigma_2(0)) \\cong \\Z$.\nThen $[\\sigma_2]$ is an element of $G_1$,\nso under an isomorphism $G_1 \\to \\Z$ it maps to an integer $n$.\nIts absolute value $|n|$ is independent of the choice of isomorphism.\nThis $|n|$ is the \\emph{linking number} of $\\sigma_2$ with $\\sigma_1$.\n\nThis definition of linking number is not symmetric with regard to $\\sigma_1$ and $\\sigma_2$:\nwe require only the complement of $\\sigma_1$ to have a fundamental group isomorphic to $\\Z$.\nEven in $\\R^3\\!$, the fundamental group of such a complement can be quite surprising.\nFor example, the fundamental group of the complement of an $(m, n)$ torus knot\nis shown in \\parencite[p.~47]{hatcher2002} to be the quotient group\nof the free group with generators $a$ and $b$,\nwhere $a^m$ and $b^n$ are identified.\n\\marginfigure{\n\\tikzexternalenable\n\\tikzsetnextfilename{trefoil-knot}\n\\begin{center}\n\\hspace{0.5em}\n\\begin{tikzpicture}[baseline={(C.base)}]\n\\tikzstyle{back} = [line width = 4.94pt, black]\n\\tikzstyle{knot} = [line width = 4.0pt, white]\n\\setlength{\\kr}{2em}\n\\coordinate (A) at ( 90 : 0.7\\kr);\n\\coordinate (B) at (210 : 0.7\\kr);\n\\coordinate (C) at (330 : 0.7\\kr);\n\\coordinate (Z) at ($(B) !.5! (C) + (90 : \\kr)$);\n\n\\useasboundingbox let \\p1 = (A), \\p2 = (B), \\p3 = (C) in\n            (\\x2 - \\kr - 2.5pt, \\y1 + \\kr + 2.5pt) rectangle\n            (\\x3 + \\kr + 2.5pt, \\y3 - \\kr - 2.5pt);\n\n\\draw[back] ($(C) + (330 : \\kr)$) arc (-30 :  90 : \\kr) -- (Z);\n\\draw[knot] ($(C) + (330 : \\kr)$) arc (-30 :  90 : \\kr) -- (Z);\n\\draw[back] ($(B) + (210 : \\kr)$) arc (210 : 330 : \\kr) --\n            ($(A) + (330 : \\kr)$) arc (-30 :  90 : \\kr);\n\\draw[knot] ($(B) + (210 : \\kr)$) arc (210 : 330 : \\kr) --\n            ($(A) + (330 : \\kr)$) arc (-30 :  90 : \\kr);\n\\draw[back] ($(A) + ( 89 : \\kr)$) arc ( 89 : 210 : \\kr) --\n            ($(C) + (210 : \\kr)$) arc (210 : 331 : \\kr);\n\\draw[knot] ($(A) + ( 88 : \\kr)$) arc ( 88 : 210 : \\kr) --\n            ($(C) + (210 : \\kr)$) arc (210 : 332 : \\kr);\n\\draw[back] (Z) + (0.1pt, 0) -- ($(B) + ( 90 : \\kr)$) arc ( 90 : 211 : \\kr);\n\\draw[knot] (Z) + (0.5pt, 0) -- ($(B) + ( 90 : \\kr)$) arc ( 90 : 212 : \\kr);\n\\end{tikzpicture}\n\\end{center}\n\\vspace{1em}\n\\caption{A 2,3 torus knot, also called a \\emph{trefoil knot}.}}\nThis means that the linking number of a nontrivial torus knot with a circle\nis well-defined,\nbut the linking number of the circle with the knot is not.\nThis problem can be alleviated by considering the first homology group\ninstead of the fundamental group,\nan approach that is taken in \\parencite[p.~132]{rolfsen2003}.\nRolfsen also relates the linking number as defined here to other definitions,\nsuch as the \\emph{Gauss linking integral}.\nIn the remainder of this section,\nwe will only consider curves of which the fundamental group of the complement is isomorphic to $\\Z$.\nFor curves in $\\R^3$ or $S^3\\!$,\nit is shown in theorem~6 of \\parencite[p.~135]{rolfsen2003}\nthat the linking number\ndoes not depend on the order of $\\sigma_1$ and $\\sigma_2$,\nnor on their orientation.\nThis means that the we can quantify the linking of $\\set{\\im \\sigma_1, \\im \\sigma_2}$\nwith a unique nonnegative integer.\nA nonzero linking number implies that two curves are linked,\nbut the converse does not hold:\nthe Whitehead link has linking number zero,\nbut it is not trivial.\nIn any case,\nthe linking number suffices to show that the fibres of the Hopf map are linked.\nBefore we prove the general case\nwe will demonstrate linkedness of two particular fibres.\nBy using the action of $\\GLC$\nthis proof can be extended to the general case.\n\nAs shown in section~\\ref{sec:fibres},\nthe fibres of the Hopf map above $(1 : 0)$ and $(0 : 1)$ may be parametrised as\n\\[ \\sigma_1: [0, 1] \\longto S^3, \\quad t \\longmapsto (e^{2\\pi i t}, 0)\n   \\quad \\textup{and} \\quad\n   \\sigma_2: [0, 1] \\longto S^3, \\quad t \\longmapsto (0, e^{2\\pi i t}) \\]\nIn corollary~\\ref{cor:circles-and-axis} we saw that under stereographic projection,\n$\\sigma_1$ maps to the $x_1$ axis\nand $\\sigma_2$ maps to the unit circle in the $x_2 x_3$-plane.\n\n\\proposition\nLet $\\sigma_1$ and $\\sigma_2$ be as introduced above.\nThen $\\sigma_2$ is linked once with $\\sigma_1$ in $S^3\\!$.\n\n\\proof\nRestricted to $S^3 \\setminus \\im \\sigma_1$,\nthe stereographic projection $\\pi : S^3 \\setminus\\set{p} \\to \\R^3$\nis a homeomorphism onto $\\R^3 \\setminus \\pi(\\im \\sigma_1)$,\nbecause the projection point $p = (1, 0)$ lies on the image of $\\sigma_1$.\nTherefore, it induces an isomorphism\n$\\pi_1(S^3 \\setminus \\im \\sigma_1, \\, \\sigma_2(0)) \\to \\pi_1(\\R^3 \\setminus \\pi(\\im \\sigma_1), \\, \\pi(\\sigma_2(0)))$\non fundamental groups.\nAs we saw before, $\\pi(\\im \\sigma_1)$ is the $x_1$-axis in $\\R^3\\!$,\nso the space $\\R^3 \\setminus \\pi(\\im \\sigma_1)$ deformation retracts onto $\\R^2$ minus the origin\nby projecting on the $x_2 x_3$-plane.\nThis induces an isomorphism\n$\\pi_1(S^3 \\setminus \\im \\sigma_1, \\, \\sigma_2(0)) \\to \\pi_1(\\R^2 \\setminus \\set{0},\\, (1, 0))$.\n(See for example proposition~1.17 of \\parencite[p.~31]{hatcher2002}.)\nBecause the image of $\\pi \\circ \\sigma_2$ lies in the $x_2x_3$ plane,\n$[\\pi \\circ \\sigma_2]$ is an element of $\\pi_1(\\R^2 \\setminus \\set{0},\\, (1, 0))$.\nThis fundamental group is of course isomorphic to $\\Z$,\nand $\\pi \\circ \\sigma_2$ is a curve that goes around the origin once,\nso it is a generator of the fundamental group.\nIt follows that $\\sigma_2$ is linked once with $\\sigma_1$.\n\\qed\n\nTo demonstrate that any two fibres are linked,\nwe will improve upon the result of proposition~\\ref{prop:glc-acts-transitively},\nwhich stated that $\\GLC$ acts transitively on $\\PC$.\nIn fact, the stabiliser $\\GLC_p$ of a point $p \\in \\PC$\nstill acts transitively on $\\PC \\setminus \\set{p}$.\n\n\\proposition[prop:glc-acts-doubly-transitive]\nLet $(z_1 : z_2)$ and $(\\nu_1 : \\nu_2) \\in \\PC$ be distinct points.\nThen there exists a $g \\in \\GLC$,\nsuch that $g \\cdot (1 : 0) = (z_1 : z_2)$ and $g \\cdot (0 : 1) = (\\nu_1 : \\nu_2)$.\n\n\\proof\nConsider the matrix\n\\[ g = \\begin{pmatrix}z_1 & \\nu_1 \\\\ z_2 & \\nu_2 \\end{pmatrix} \\]\nThe columns of this matrix are linearly independent by assumption,\nso its determinant is nonzero.\nIt follows that $g \\in \\GLC$,\nand clearly $g \\cdot (1 : 0) = (z_1 : z_2)$\nand $g \\cdot (0 : 1) = (\\nu_1 : \\nu_2)$.\n\\qed\n\n\\corollary\nAny two fibres of the Hopf map are linked in $S^3$:\nproposition~\\ref{prop:glc-acts-doubly-transitive} tells us that the situation\nof any two fibres can be transformed into the situation of $(1 : 0)$ and $(0 : 1)$\nby a homeomorphism,\nand the linking number is invariant under such a homeomorphism.\n\n\\begin{figure}\n\\margincaption[0.5em]{\\label{fig:more-fibres}\nLinked fibres of the Hopf map visualised through stereographic projection.\nFibres above points near $ i \\in S^2$ (the north pole) are circles with a large radius in $\\R^3\\!$,\nclose to the $x_1$-axis (truncated here).\nFibres above points near $-i \\in S^2$ (the south pole) are circles close to the unit circle in the $x_2 x_3$-plane.}\n\\begin{python}\nfrom hopf import *\nfrom math import pi\ninterval5 = interval_open(5)\ninterval3 = interval_open(3)\npoints_a  = [[[-pi * 0.3, (t * 0.7 + 0.30) * pi], 'a{0}'.format(i)] for (i, t) in enumerate(interval5)]\npoints_b  = [[[-pi * 0.1, (t * 0.4 + 0.50) * pi], 'b{0}'.format(i)] for (i, t) in enumerate(interval5)]\npoints_c  = [[[ pi * 0.3, (t * 0.5 + 1.50) * pi], 'c{0}'.format(i)] for (i, t) in enumerate(interval3)]\npoints_ab = points_a + points_b\npoints    = points_ab + points_c\npr        = orthographic_projection(pi * 0.42, pi * -0.1)\ndef limited(x):\n    f = compose(pr, projected_fibre_from_spherical(x))\n    return lambda t: f((0.910 + t * (1.590 - 0.921)) % 1) # Tweaked to the box boundaries.\nfibres_ab = [[compose(pr, projected_fibre_from_spherical(x)), 'front, ' + st, 'back'] for [x, st] in points_ab]\nfibres_c  = [[limited(x), 'front, ' + st, 'back'] for [x, st] in points_c]\nfibres    = fibres_ab + fibres_c\ncmds      = generate_raw_draw_2d(0.1, fibres)\nbox       = generate_raw_box_2d([1.636, 1.636, 1.636], pr, 'box')\nwrite_items('generated/more-fibres-box.tikz', cons(box, cmds))\n\nlat_a   = generate_raw_latitude_2d(-pi * 0.3, pr, 'dashed')\nlat_b   = generate_raw_latitude_2d(-pi * 0.1, pr, 'dashed')\nlat_c   = generate_raw_latitude_2d( pi * 0.3, pr, 'dashed')\ncmds    = generate_raw_points_2d(pr, points, '1.3pt')\nwrite_items('generated/more-fibres-sphere.tikz', cat([lat_a, lat_b, lat_c], cmds))\n\ncolours_a = generate_colours('a', [[  0.0 + h * 0.4,  0.6, 0.6] for h in interval5])\ncolours_b = generate_colours('b', [[  0.5 + h * 0.4,  0.6, 0.6] for h in interval5])\ncolours_c = generate_colours('c', [[-0.05 + h * 0.27, 0.9, 0.9] for h in interval3])\ncolours   = cat(cat(colours_a, colours_b), colours_c)\nwrite_items('generated/more-fibres-colours.tikz', colours)\n\\end{python}\n\\begin{center}\n\\tikzexternalenable\n\\tikzsetnextfilename{more-fibres}\n\\begin{tikzpicture}\n\\input{generated/more-fibres-colours.tikz}\n\\tikzstyle{back}  = [line width = 3pt, white];\n\\tikzstyle{front} = [line width = 1pt];\n\\tikzstyle{box} = [line width = 0.47pt];\n\\coordinate (D) at (-3, 0);\n\\coordinate (C) at ( 3, 0);\n\n\\begin{scope}[shift = {(D)}, scale = 1.1, local bounding box = {domain}]\n\\input{generated/more-fibres-box.tikz}\n\\end{scope}\n\n% Draw S^2.\n\\begin{scope}[shift = {(C)}, scale = 1.5, local bounding box = {codomain}]\n\\draw[line width = 0.47pt] (0, 0) circle (1);\n\\input{generated/more-fibres-sphere.tikz}\n\\end{scope}\n\n% Draw an arrow from the plot to S^2 with tikzcd arrow style.\n\\begin{scope}[commutative diagrams/every diagram]\n\\path let \\p1 = (domain.east) in node (from) at (\\x1 + 1em, 0) {};\n\\path let \\p1 = (codomain.west) in node (to) at (\\x1 - 1em, 0) {};\n\\path[commutative diagrams/.cd, every arrow, every label]\n  (from) edge [commutative diagrams/maps to] node {$h \\circ \\pi^{-1}$} (to);\n\\end{scope}\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nBecause the stereographic projection is a homeomorphism,\nthe projection of any two fibres in $S^3$ that do not pass through the projection point\nwill be a set of two linked circles in $\\R^3\\!$.\nEven if one of the fibres passes through the projection point\n(and thus projects to the $x_1$-axis),\nthere is a sense of linkedness in $\\R^3$:\nthe fibre that does not pass through the projection point\nwill project to a circle around the $x_1$-axis.\nA few of the fibres have been visualised in figure~\\ref{fig:more-fibres}.\n\n\\subsection*{Informal summary}\nIn this section we used topology to quantify linkedness.\nAn \\emph{$n$-link} is a collection of non-intersecting closed curves,\nand for a \\emph{proper $n$-link} the curves cannot be self-intersecting either.\nIf two links can be defomed into one another by bending and twisting but not intersecting,\nthe links are called \\emph{homotopic}.\nWith homotopy we allow the curves to self-intersect in the process,\nbut for a \\emph{proper homotopy} even this is disallowed.\nIf we want to know whether e.g. a collection of rubber bands can be unlinked,\nwe must ask whether the corresponding link is \\emph{trivial}.\nIf it is, it is possible to separate all of the bands.\nBecause homotopy does not allow us to quantify linkedness,\nwe turn to another quantity: the \\emph{linking number}.\nThe linking number of two closed curves $\\sigma_1$ and $\\sigma_2$\ncounts how many times $\\sigma_2$ winds around $\\sigma_1$,\na concept that can be made precise by using the fundamental group.\nFinally, we showed that any two fibres of the Hopf map have linking number one in $S^3\\!$.\nUsing stereographic projection,\nwe can see that the fibres are linked in $\\R^3$ as well.\n", "meta": {"hexsha": "542443348d9abbb6fe620adcbe3619ff204501a0", "size": 42150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/the-hopf-map.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/the-hopf-map.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/the-hopf-map.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": 45.0320512821, "max_line_length": 117, "alphanum_fraction": 0.670510083, "num_tokens": 14642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.6021304479202245}}
{"text": "\\section{More about Weierstrass' Elliptic Functions; Quotients}\r\n\\subsection{An Elliptic Curve}\r\nWe have seen two general constructions of Riemann surfaces with genus $1$:\r\nThe complex torus and the compactification of the Riemann surface associated with $w^2=z^3-z$.\r\nThese two constructions has to be related, but how?\r\nHere, we shall prove that any complex torus is isomorphic to an algebraic construction.\r\nThis is a corollary of Proposition \\ref{elliptic_wp}.\r\n\\begin{corollary}\r\n    Let $\\mathbb C/\\Lambda$ be a complex torus, then there are constants $g_2,g_3$ such that $\\mathbb C/\\Lambda$ is biholomorphic to a one-point compactification of the graph $X'=\\{(x,y)\\in\\mathbb C^2:y^2=4x^3-g_2x-g_3\\}$.\r\n\\end{corollary}\r\n\\begin{proof}[Sketch of proof]\r\n    Take $g_2,g_3$ exactly as in Proposition \\ref{elliptic_wp}.\r\n    Turns out $X'$ can be compactified into a Riemann surface $X=X'\\cup\\{\\infty\\}$ with charts provided by coordinate projection.\r\n    Define $F:\\mathbb C\\to X$ via $z\\mapsto(\\wp(z),\\wp^\\prime(z))$ where $\\wp=\\wp_\\Lambda$.\r\n    Now $\\operatorname{Im}F\\subset X$ by Proposition \\ref{elliptic_wp} and $F$ is analytic as the charts are coordinate projections.\r\n    So via a quotient, we can use $F$ to induce $\\Phi:\\mathbb C/\\Lambda\\to X$.\r\n    It remains to show that $\\Phi$ is a conformal equivalence.\r\n    As it is analytic, it suffices to show that it is bijective.\r\n    It is surjective as it is nonconstant and everything is compact.\r\n    To see it is injective, consider the period parallelogram centered at $0$, that is the parallelogram with vertices $(\\omega_1+\\omega_2)/2,(\\omega_2-\\omega_1)/2,(-\\omega_1-\\omega_2)/2,(\\omega_1-\\omega_2)/2$.\r\n    It suffices to show that $F$ is injective in the interior of $P$, which will imply injectivity of $\\Phi$ in general due to the valency theorem.\r\n    Suppose $F(z)=F(z')$ for $z,z'\\in P^\\circ$, then $\\wp(z)=\\wp(z')$, so $z=\\pm z'$ as $\\wp$ is even and has degree $2$.\r\n    But also $\\wp^\\prime(z)=\\wp^\\prime(z')=\\pm \\wp^\\prime(z)$ as $\\wp$ is odd, so $z=z'$ as the zeros of $\\wp^\\prime$ are not in $P^\\circ$.\r\n    This completes the proof.\r\n\\end{proof}", "meta": {"hexsha": "764b4ee56cb07d404de514885fc62e97b997f184", "size": 2128, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15/ellip.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/ellip.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/ellip.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": 85.12, "max_line_length": 223, "alphanum_fraction": 0.7030075188, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6021304443848513}}
{"text": "\\subsection{Topological nets}\\label{subsec:topological_nets}\n\nIn this section, \\( X \\) will denote an arbitrary nonempty topological space.\n\n\\begin{definition}\\label{def:topological_net}\n  A \\term{net} or \\term{generalized \\hyperref[def:sequence]{sequence}} or \\term{Moore-Smith sequence} in a nonempty set \\( S \\) is a family of elements of \\( S \\) indexed by a nonempty \\hyperref[def:cartesian_product/indexed_family]{directed set}, i.e. a function from a nonempty directed \\hyperref[def:directed_set]{set} \\( (\\mscrK, \\leq) \\) to \\( S \\). We use the conventional notation for indexed families:\n  \\begin{equation*}\n    \\{ x_k \\}_{k \\in \\mscrK},\n  \\end{equation*}\n  because the preorder on the domain \\( \\mscrK \\) is usually clear from the context.\n\n  If we know that the net is a sequence, we will usually use the notation for sequences given in \\fullref{def:sequence}.\n\n  Note that this definition does not actually require a topology on \\( S \\). Some other important definitions also do not require topologies:\n  \\begin{thmenum}\n    \\thmitem{def:topological_net/frequently_in} We say that \\( \\{ x_k \\}_{k \\in \\mscrK} \\) is \\term{frequently in} the set \\( A \\subseteq S \\) if for every index \\( k_0 \\in \\mscrK \\) there exists an index \\( k \\geq k_0 \\) such that \\( x_k \\in A \\).\n\n    \\thmitem{def:topological_net/eventually_in} We say that \\( \\{ x_k \\}_{k \\in \\mscrK} \\) is \\term{eventually in} the set \\( A \\subseteq S \\) if there exists an index \\( k_0 \\) such that \\( x_k \\in A \\) whenever \\( k \\geq k_0 \\). This is obviously a stronger condition.\n\n    \\thmitem{def:topological_net/subnet}\\mcite[50]{Engelking1989}We say that the net \\( \\{ y_m \\}_{m \\in M} \\subseteq S \\) is a \\term{subnet} of \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq S \\) if there exists an embedding function \\( \\varphi: M \\to \\mscrK \\) such that\n    \\begin{thmenum}\n      \\thmitem{def:topological_net/subnet/directed} To every \\( k \\in \\mscrK \\) there corresponds \\( m \\in M \\) such that \\( \\varphi(m) \\geq k \\).\n      \\thmitem{def:topological_net/subnet/identity} For every \\( m \\in M \\) we have \\( x_{\\varphi(m)} = y_m \\).\n    \\end{thmenum}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:topological_net}\n  \\hyperref[def:topological_net]{Nets} have the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:topological_net/eventually_in_implies_frequently_in} \\enquote{\\hyperref[def:topological_net/eventually_in]{Eventually in}} implies \\enquote{\\hyperref[def:topological_net/frequently_in]{frequently in}}.\n\n    \\thmitem{thm:def:topological_net/net_eventually_in_iff_not_frequently_in_complement} The net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq S \\) is eventually in \\( A \\subseteq S \\) if and only if it is not frequently in \\( S \\setminus A \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:topological_net/eventually_in_implies_frequently_in} Suppose that the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq S \\) is eventually in \\( A \\subseteq S \\). Then there exists an index \\( k_0 \\) such that \\( x_k \\in A \\) for all \\( k \\geq k_0 \\).\n\n  Given any index \\( k_1 \\), we choose \\( k_2 \\) such that \\( k_2 \\geq k_0 \\) and \\( k_2 \\geq k_1 \\) (this is possible by the definition of a directed set). Then \\( x_{k_2} \\in A \\) and \\( k_2 \\) satisfies the existence quantifier in \\fullref{def:topological_net/frequently_in}.\n\n  \\SubProofOf{thm:def:topological_net/net_eventually_in_iff_not_frequently_in_complement} Suppose that \\( \\{ x_k \\}_{k \\in \\mscrK} \\) is both eventually in \\( A \\) and frequently in \\( S \\setminus A \\).\n\n  Since the net is eventually in \\( A \\), we can fix an index \\( k_0 \\) such that \\( x_k \\in A \\) whenever \\( k \\geq k_0 \\).\n\n  Since the net is frequently in \\( A \\), we can fix an index \\( k_1 \\geq k_0 \\) such that \\( k_1 \\in S \\setminus A \\), which is a contradiction.\n\n  This proves that the two conditions are incompatible.\n\\end{proof}\n\n\\begin{definition}\\label{def:net_convergence}\n  Let \\( X \\) be a topological space and \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\) be a net.\n\n  \\begin{thmenum}\n    \\thmitem{def:net_convergence/cluster} If the net is frequently in every neighborhood of \\( x_0 \\in X \\), we say that \\( x_0 \\) is a \\term{cluster point} or an \\term{accumulation point} of \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\).\n\n    \\thmitem{def:net_convergence/limit} If the net is eventually in every neighborhood of \\( x_0 \\in X \\), we say that \\( x_0 \\) is a \\term{limit point} of \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\).\n  \\end{thmenum}\n\n  In general, there can exist multiple limit points (see \\fullref{ex:multiple_limit_points_of_net}) and even more cluster points (see \\fullref{ex:cluster_points/sine}). In Hausdorff spaces, however, limits are unique by \\fullref{thm:t2_iff_singleton_limits}.\n\n  If \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\) has a unique limit, we say that the net \\term[bg=схожда,ru=сходится]{converges} to \\( x_0 \\) use the notation\n  \\begin{equation*}\n    x_0 = \\lim_{k \\in \\mscrK} x_k.\n  \\end{equation*}\n\n  If the net is a \\hyperref[def:sequence]{sequence}, we also use the following notations:\n  \\begin{itemize}\n    \\item \\( x_0 = \\lim_{k \\to \\infty} x_k \\)\n    \\item \\( x_0 = \\lim x_k \\)\n    \\item \\( x_k \\xrightarrow[k \\to \\infty]{} x_0 \\)\n    \\item \\( x_k \\to x_0 \\)\n  \\end{itemize}\n\\end{definition}\n\n\\begin{example}\\label{ex:multiple_limit_points_of_net}\n  Even limits of sequences need not be unique in arbitrary topological spaces. Let \\( X = \\{ y, z \\} \\) be a binary set with the indiscrete \\hyperref[def:standard_topologies/indiscrete]{topology} \\( \\{ \\varnothing, X \\} \\). L\n\n  Define the following \\hyperref[def:sequence]{sequence}\n  \\begin{balign*}\n    x_k \\coloneqq \\begin{cases}\n      y, & k \\text{ is even}, \\\\\n      z, & k \\text{ is odd}.\n    \\end{cases}\n  \\end{balign*}\n\n  The only neighborhood of \\( y \\), the whole space \\( X \\), contains all members of the sequence, therefore \\( y \\) is a limit point of the sequence. The same is true for \\( z \\), however.\n\\end{example}\n\n\\begin{example}\\label{ex:cluster_points/sine}\n  Consider the net \\( \\{ \\sin(k) \\}_{k \\in \\BbbR} \\). It has no limit point, yet every real number in the interval \\( [-1, 1] \\) is a cluster point.\n\\end{example}\n\n\\begin{example}\\label{ex:reverse_inclusion_net}\n  A commonly used technique is to use a variation of a \\term{reverse set inclusion net}.\n\n  Fix an element \\( x_0 \\in X \\) of any topological space and choose an element \\( x_U \\) our of every neighborhood \\( U \\) of \\( x_0 \\). Consider the directed set \\( (\\mscrT(x), \\leq) \\) consisting of all neighborhoods of \\( x_0 \\) ordered by \\term{reverse inclusion}, i.e. \\( U \\leq V \\iff U \\supseteq V \\).\n\n  Choose an element \\( x_U \\) from each neighborhood \\( U \\) of \\( x_0 \\). Then, by construction, \\( x_0 \\) is a limit point of the net \\( \\{ x_U \\}_{U \\in T(x_0)} \\).\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:net_convergence}\n  Convergence of \\hyperref[def:net_convergence]{nets} has the following basic properties:\n\n  \\begin{thmenum}\n    \\thmitem{thm:def:net_convergence/sequence_converges_iff_almost_entirely_in_neighborhood} The point \\( x_0 \\in X \\) is a limit point of the sequence \\( \\{ x_k \\}_{k=1}^\\infty \\subseteq X \\) if and only if, given a neighborhood \\( U \\) of \\( x_0 \\), only finitely many elements of the sequence are outside \\( U \\).\n\n    \\thmitem{thm:def:net_convergence/limit_point_is_cluster_point} Every limit point is a cluster point.\n\n    \\thmitem{thm:def:net_convergence/cluster_point_iff_subnet_limit_point} A point \\( x_0 \\in X \\) is a cluster point of the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\) if and only if \\( x_0 \\) is a limit point of some subnet.\n\n    \\thmitem{thm:def:net_convergence/limit_implies_no_proper_cluster_points} If a net has a limit point, all of its cluster points are limit points.\n\n    \\thmitem{thm:def:net_convergence/unique_limit_point_iff_unique_cluster_point} A net has a unique limit point if and only if has a unique cluster point.\n\n    \\thmitem{thm:def:net_convergence/unique_limit_point_iff_subnets_have_same_limit} A net has a unique limit point if and only if all subnets have the same limit point.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:net_convergence/sequence_converges_iff_almost_entirely_in_neighborhood} This is simply a restatement of \\fullref{def:net_convergence/limit} for the special case of sequences.\n\n  \\SubProofOf{thm:def:net_convergence/limit_point_is_cluster_point} Follows from \\fullref{thm:def:topological_net/eventually_in_implies_frequently_in}.\n\n  \\SubProofOf{thm:def:net_convergence/cluster_point_iff_subnet_limit_point}\n  The definition of a cluster point (\\fullref{def:net_convergence/cluster}) allows us to build a reverse inclusion net in the style of \\fullref{ex:reverse_inclusion_net}.\n\n  \\SubProofOf{thm:def:topological_net/eventually_in_implies_frequently_in} Suppose that the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq S \\) is eventually in \\( A \\subseteq S \\). Then there exists an index \\( k_0 \\) such that \\( x_k \\in A \\) for all \\( k \\geq k_0 \\).\n\n  Given any index \\( k_1 \\), we choose \\( k_2 \\) such that \\( k_2 \\geq k_0 \\) and \\( k_2 \\geq k_1 \\) (this is possible by the definition of a directed set). Then \\( x_{k_2} \\in A \\) and \\( k_2 \\) satisfies the existence quantifier in \\fullref{def:topological_net/frequently_in}.\n\n  \\SubProofOf{thm:def:topological_net/net_eventually_in_iff_not_frequently_in_complement} Suppose that \\( \\{ x_k \\}_{k \\in \\mscrK} \\) is both eventually in \\( A \\) and frequently in \\( S \\setminus A \\).\n\n  Since the net is eventually in \\( A \\), we can fix an index \\( k_0 \\) such that \\( x_k \\in A \\) whenever \\( k \\geq k_0 \\).\n\n  Since the net is frequently in \\( A \\), we can fix an index \\( k_1 \\geq k_0 \\) such that \\( k_1 \\in S \\setminus A \\), which is a contradiction.\n\n  This proves that the two conditions are incompatible.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:limit_point_iff_in_closure}\\mcite[prop. 1.6.3]{Engelking1989}\n  Fix a set \\( A \\subseteq X \\). A point \\( x_0 \\in X \\) belongs to \\( \\cl{A} \\) if and only if there exists a net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\) for which \\( x_0 \\) is a limit point.\n\n  By \\fullref{thm:def:net_convergence/cluster_point_iff_subnet_limit_point}, we can consider cluster points of nets rather than limit points.\n\\end{proposition}\n\\begin{proof}\n  The complement of the empty set is the empty set, hence the statement of the proposition holds vacuously. Assume that \\( A \\) is nonempty.\n\n  \\SufficiencySubProof Suppose that \\( x_0 \\in \\cl{A} \\). If \\( x_0 \\in A \\), then the one-element net \\( (x_0) \\) converges to \\( x_0 \\).\n\n  If \\( x_0 \\in \\fr{A} \\), by \\fullref{def:topological_boundary/neighborhoods}, every neighborhood of \\( x_0 \\) contains points from \\( A \\). Therefore, we can build reverse inclusion net in the style of \\fullref{ex:reverse_inclusion_net} that converges to \\( x_0 \\).\n\n  \\NecessitySubProof Let \\( x_0 \\) be a limit point of \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\). We will show that \\( x_0 \\) belongs every closed set that contains \\( A \\).\n\n  Let \\( F \\supseteq A \\) be a closed set. Denote \\( U \\coloneqq X \\setminus F \\). Suppose that \\( x_0 \\in U \\). Then \\( U \\) is a neighborhood \\( x_0 \\) and, by \\fullref{def:net_convergence/cluster}, the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\) is eventually in \\( U \\). But \\( U \\) does not contains \\( A \\).\n\n  The obtained contradiction shows that \\( x_0 \\) belongs to every closed set containing \\( A \\) and hence to their intersection, the closure \\( \\cl A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:cluster_point_of_set_iff_limit_point_of_net}\n  The point \\( x_0 \\in X \\) is a cluster \\hyperref[def:topological_derived_set/cluster_point]{point} of the set \\( A \\) if and only if it is a limit \\hyperref[def:net_convergence/cluster]{point} of some net in \\( A \\setminus \\{ x_0 \\} \\) (or, equivalently, a cluster point of some net in \\( A \\setminus \\{ x_0 \\} \\)).\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( x_0 \\in \\derived(A) \\). By \\fullref{thm:def:derived_set/cluster_via_neighborhoods}, every neighborhood \\( U \\) of \\( x_0 \\) intersects \\( A \\setminus \\{ x_0 \\} \\). Choose \\( x_U \\in U \\cap (A \\setminus \\{ x_0 \\}) \\) for every neighborhood \\( U \\) of \\( x_0 \\) and form the reverse inclusion \\hyperref[ex:reverse_inclusion_net]{net} \\( \\{ x_U \\}_{U \\in T(x)} \\). Then \\( x_0 \\) is a limit point of this net. Furthermore, the net is contained in \\( A \\setminus \\{ x_0 \\} \\).\n\n  \\NecessitySubProof Conversely, if \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\setminus \\{ x_0 \\} \\) is a net and if \\( x_0 \\) is a limit point of this net, then for every neighborhood \\( U \\) of \\( x_0 \\) there exists an index \\( k_U \\) such that for \\( k \\geq k_U \\) we have \\(  x_k \\in U \\). In particular, \\( U \\cap A \\) contains elements other than \\( x_0 \\). Since this is true for any neighborhood \\( U \\) of \\( x_0 \\), by \\fullref{thm:def:derived_set/cluster_via_neighborhoods} we conclude that \\( x_0 \\) is a cluster point of the set\\( A \\).\n\\end{proof}\n\n\\begin{corollary}\\label{thm:closed_iff_contains_all_net_cluster_points}\n  A set is closed if and only if it contains the limit points of all of its nets (or, equivalently, the cluster points of all of its nets).\n\\end{corollary}\n\\begin{proof}\n  By \\fullref{thm:def:derived_set/closed_iff_contains_all_cluster_points}, the set \\( A \\) is closed if and only if it contains all of its cluster points. By \\fullref{thm:cluster_point_of_set_iff_limit_point_of_net}, this is equivalent to \\( A \\) containing all limit points of its nets.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:net_convergence_via_subbases}\n  Fix a topological space \\( X \\), a point \\( x_0 \\) and a local \\hyperref[def:topological_local_subbase]{subbase} \\( P(x_0) \\). The point \\( x_0 \\) is a limit of the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\) if and only if it is eventually in every element \\( U_P \\) of the local subbase \\( P(x_0) \\).\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Obvious consequence of the definition of local subbase.\n  \\NecessitySubProof Fix a neighborhood \\( U \\) of \\( x_0 \\). By \\fullref{def:topological_local_subbase}, there exists a finite family \\( \\{ U_k \\}_{k=1}^n \\subseteq P(x_0) \\) such that \\( \\bigcap_{k=1}^n U_k \\subseteq U \\). Since the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\) is eventually in each of \\( U_k, k = 1, \\ldots, n \\), from transitivity of inclusion it follows that the net is eventually in \\( U \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:sequential_topological_closure_operator}\n  In analogy to \\fullref{def:topological_closure_operator}, we define the \\term{sequential closure operator}\n  \\begin{balign*}\n     & \\cl^S: \\pow(X) \\to \\pow(X)                                                                                                          \\\\\n     & \\cl^S(A) \\coloneqq \\left\\{ x \\in X \\colon x \\text{ is a limit point of some sequence } \\{ x_k \\}_{k=1}^\\infty \\subseteq A \\right\\}.\n  \\end{balign*}\n\n  If \\( \\cl^S(A) = A \\), we say that \\( A \\) is \\term{sequentially closed}.\n\\end{definition}\n\n\\begin{definition}\\label{def:sequential_space}\n  A topological space is called \\term{sequential} if every sequentially \\hyperref[def:sequential_topological_closure_operator]{closed} set is closed.\n\\end{definition}\n\n\\begin{remark}\\label{rem:sequential_spaces}\n  By \\fullref{thm:limit_point_iff_in_closure}, in a \\hyperref[def:sequential_space]{sequential space}, a set is closed if and only if it is sequentially closed.\n\n  By \\fullref{thm:closed_iff_contains_all_net_cluster_points}, a set is closed if and only if it contains the limit points of all of its nets.\n\n  Therefore, a set in a sequential space is closed if and only if it contains the limit points of all of its sequences.\n\n  Since we are able to define a topology in terms of closed sets, this means that the topology in a sequential space is completely determined by convergent sequences rather than convergent nets as in general topological spaces.\n\n  This allows us to restrict ourselves only to sequences rather than arbitrary nets in certain spaces like \\hyperref[def:metric_space]{metric spaces}.\n\\end{remark}\n\n\\begin{lemma}\\label{thm:sequential_space_convergence}\n  Let \\( X \\) be a sequential space and \\( x_0 \\) limit point of the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\), then we can define a sequence\n  \\begin{equation*}\n    \\{ x_k \\}_{k=1}^\\infty \\subseteq \\{ x_k \\colon k \\in \\mscrK \\},\n  \\end{equation*}\n  consisting of members of the net, for which \\( x_0 \\) is a limit point.\n\\end{lemma}\n\\begin{proof}\n  Let \\( X \\) be a first-countable space and let \\( x_0 \\) be a limit point of the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\).\n\n  Since \\( X \\) is a first countable space, we can fix a countable local \\hyperref[def:topological_local_base]{base} \\( \\{ U_k \\}_{k=1}^\\infty \\) at \\( x_0 \\). For each \\( k = 1, 2, \\ldots \\), define the neighborhood \\( V_k \\coloneqq \\bigcap_{m=1}^k U_m \\), so that \\( V_k \\subseteq V_m \\) whenever \\( k \\geq m \\).\n\n  For each neighborhood \\( V_k \\), since \\( \\{ x_k \\}_{k \\in \\mscrK} \\) is eventually in \\( V_k \\), there exists an index \\( k_k \\) such that \\( x_{k_k} \\in V_k \\).\n\n  Thus, we obtain a sequence \\( \\{ x_{k_k} \\}_{k=1}^\\infty \\) that is eventually in every neighborhood of the local base \\( \\{ V_k \\}_{k=1}^\\infty \\) of \\( x_0 \\), which by \\fullref{thm:net_convergence_via_subbases} is sufficient for \\( x_0 \\) to be a limit point of the sequence.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:first_countable_spaces_are_sequential}\n  Every first-countable space is sequential.\n\\end{proposition}\n\\begin{proof}\n  Let \\( X \\) be a first-countable space and let \\( A \\subseteq X \\) be a sequentially \\hyperref[def:sequential_topological_closure_operator]{closed} set. We must show that it is closed.\n\n  Fix a point \\( x_0 \\in \\cl(A) \\). We will show that \\( x_0 \\in A \\). By \\fullref{thm:limit_point_iff_in_closure}, there is a net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq A \\) for which \\( x_0 \\) is a limit point.\n\n  By \\fullref{thm:sequential_space_convergence}, we can choose a sequence \\( \\{ x_k \\}_{k=1}^\\infty \\) that converges to \\( x_0 \\) out of elements of the net. But since \\( X \\) is a sequential space, the limit points of any sequence are contained in the sequentially closed set \\( A \\).\n\n  We showed that \\( A = \\cl(A) \\). Since \\( A \\) was an arbitrary sequentially closed set, we conclude that the space \\( X \\) is sequential.\n\\end{proof}\n", "meta": {"hexsha": "a5cd64a3f0f4f2cd089ec32d3a14f6096b53a181", "size": 18433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topological_nets.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_nets.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_nets.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.4495798319, "max_line_length": 548, "alphanum_fraction": 0.6941355178, "num_tokens": 5732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6020835569796174}}
{"text": "Total Variation\\subsection{Example: Thermal Conductivity on a 1D Heat Rod}\\label{ex:heat-set-sample-accuracy}\n\nConsider the one-dimensional heat equation with homogeneous Neumann boundary conditions on the unit interval presented in \\ref{ex:heat-set-sample}.\n\n\nThe quantities of interest we study are four point-evaluations of the state variable, at spatial location 0.25, 0.51, 0.67, and 0.98 along the rod.\nChoosing any pair of them for the inversion yields six possible quantities of interest maps.\nAs before, we demonstrate that some choices appear to have advantages over others.\n\nFrom the prior examples, we would suspect that choosing the QoI map with lower skewness results in lower Total Variations.\nHowever in the earlier experiments we utilized maps that inverted into sets of identical size, which is not the case in this nonlinear example; each QoI map scales sets differently depending on the location in the parameter space.\nTo isolate this scaling effect, we attempt to compare QoIs that invert into sets of similar size \\emph{on average} but have differing average skewness.\n\nThis is what motivated our specific choice of spatial locations at which to measure the state variable $T$.\nOur first QoI $\\qoiA$ uses measurements at 0.25 and 0.51, and has average skewness of 1.08, and our second $\\qoiB$ uses measurements at 0.67 and 0.98, with average skewness 1.56.\nWhile we would have liked to use a map with average skewness of 2 for a more similar comparison to the prior examples, this was the best range we could find where the maps inverted into sets of comparable size on average\\footnote{average local scaling is $1.99$ for $\\qoiA$ and $2.19$ for $\\qoiB$.}.\n\nOwing to the nonlinearity of the problem, the Total Variations between reference and estimated probability measures now have an inherent dependence on the location of the point $\\param$ in the parameter space.\nWe ran the simulations for a regular $3\\times3$ grid exploring the interior of the parameter space and present two of the nine reference points that illustrate the differences in the nonlinear case from the linear examples.\nMost notably, the location of truth will impact our ability to approximate the solution to the SIP.\n\nIn the two-dimensional data spaces $\\dspaceA$ and $\\dspaceB$, our uncertainty is a uniform box centered at $\\qoiA(\\paramref)$ with side-lengths of 0.1.\nWhen $\\paramref$ is the bottom-left corner of our $3\\times3$ grid, the two maps produce very different results, with $\\qoiA$ outperforming $\\qoiB$ in a similar manner as we saw in the linear examples (see Fig.~\\ref{fig:NLbotleft}).\nWhen $\\param_{\\text{ref}}$ is in the upper-center of the grid, the inverse images are similar, as shown in Fig.~\\ref{fig:NLtopmid}, and so which map to use forinversion into this part of the parameter spaces is not a clear choice. We might even be tempted to use the more-skewed (on average) map since it inverts into a set with smaller support.\n\n\n\\begin{figure}[h]\n  \\includegraphics[width=\\linewidth]{./images/pt0Plot-reg_BigN_40000_reg_M_1_rand_I_100000}\n  \\caption{Convergence in TV metric for the bottom left reference value in a 3x3 grid in $\\pspace$. There is a notable difference in the accuracy of the measure recovered depending on which QoI map is used.}\n  \\label{fig:NLbotleft}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\includegraphics[width=\\linewidth]{./images/pt5Plot-reg_BigN_40000_reg_M_1_rand_I_100000}\n  \\caption{Convergence in TV metric for the top-middle reference value in a 3x3 grid in $\\pspace$. For this value of truth, there is no distinguishable difference between the solutions that come from using either QoI map. The location in parameter space of truth will impact how sensitive experimental designs are to approximation errors in limited exploration of $\\pspace$.}\n  \\label{fig:NLtopmid}\n\\end{figure}\n\n\nOf the nine reference $\\param$'s we studied, $\\qoiA$ yielded no considerable advantage in terms of the number of samples required to approximate the inverse images in three cases (the plots were similar to that in the right of Fig.~\\ref{fig:NLHD}).\nIn three cases, $\\qoiA$ performed better than $\\qoiB$, (somewhere between the two figures in Fig.~\\ref{fig:NLHD}).\nIn two cases, $\\qoiA$ performed better than  $\\qoiB$, as in the left of Fig.~\\ref{fig:NLHD}.\nIn one case (with $\\param$ in the bottom right corner), the difference was even more dramatic ($\\qoiA$ yielded similar Total Variations with less than a fourth the samples).\n\n\\begin{figure}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--set_N50_em.png}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--sample_N50_mc.png}\n\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--set_N500_em.png}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q1/HeatrodModel--sample_N500_mc.png}\n\n\\caption{The inverse image of the reference measure for $\\qoiA$ for $\\nsamps = 50$ (top) and $\\nsamps = 500$ (bottom). }\n\\label{fig:heatrod-convergence-a}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q2/HeatrodModel--set_N50_em.png}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q2/HeatrodModel--sample_N50_mc.png}\n\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q2/HeatrodModel--set_N500_em.png}\n\\includegraphics[width=.45\\linewidth]{examples/fig_heatrod_q2/HeatrodModel--sample_N500_mc.png}\n\n\\caption{The inverse image of the reference measure for $\\qoiB$ for $\\nsamps = 50$ (top) and $\\nsamps = 500$ (bottom). TK - need to remark about how this map may be more precise but it makes it harder to identify the set that contains truth when few model evaluations are available to us (low $\\nsamps$). }\n\\label{fig:heatrod-convergence-b}\n\\end{figure}\n\n\nThese results motivate further study into utilizing different QoI maps (perhaps some of those other four combinations available to us in this example) depending on where the samples came from in the parameter space.\nIn general, we saw in this example that given that two maps invert into sets of similar size on average, using the one with lower skewness results in less samples required to accurately approximate the inverse image.\nThe maps we used had average skewnesses that differed by 0.5 (instead of by 1), and the trend from the linear examples still held in significant portions of the parameter space.\n", "meta": {"hexsha": "5ad019c8c2382f1670c0aa05395ff2bef59fb218", "size": 6382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/heatrod.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/heatrod.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/heatrod.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": 89.8873239437, "max_line_length": 375, "alphanum_fraction": 0.7892510185, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568416, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6020835530323428}}
{"text": "%&LaTeX\n\n\\section{Feed It Forward}\n\nThis lab covers the basic concepts of filtering and feedforward filters. \nYou may have also heard of feedforward filters referred to as \nfinite impulse response (FIR) filters. In this lab, we will cover the basic idea\nof a filter, its mathematical representation (such as the defining equation,\nfrequency response, and transfer function), the relationship among\nfilter coefficients, zero placement, and filter type (low pass, high\npass, band reject), and some basic properties of filters.\n\n\n\\subsection{Overview of Filtering and Matlab}\n\nA \\emph{digital filter} is a signal processing operation that can be\n  described equivalently by its \\emph{defining\n  equation}, \\emph{transfer function}, or \\emph{frequency response}. \n  Each representation completely defines the filter. It is advantageous \n  to use each of the different representations depending on whether you are\n  \\emph{implementing}, \\emph{analyzing}, or \\emph{designing} an FIR filter:\n\\begin{eqnarray*}\n  y[n] &=& \\underbrace{\\sum_{k=0}^M b_k x[n-k]}_{\\text{defining equation}} \\\\ \n  \\hline \\\\\n  Y &=& H(z) X\\\\\n  H(z) &=& \\underbrace{\\sum_{k=0}^M b_k z^{-k}}_{ \\text{transfer function} } \\\\\n  \\hline \\\\\n  Y &=&  \\mathcal{H}({\\hat{\\omega}}) X \\\\\n  H(e^{j\\hat{\\omega}})  = \\mathcal{H}({\\hat{\\omega}}) \n  &=& \\underbrace{\\sum_{k=0}^M b_k e^{-j \\hat{\\omega}k}}_{\\text{frequency response}} \n\\end{eqnarray*}\n\nIn these equations, $x[n]$ and $y[n]$ are the $n^\\mathrm{th}$ samples\nfrom the input and output, respectively, while $X$ and $Y$ represent\nthe entire input and output signal (all of the samples in the\nsignal). A $k$-sample time delay of a signal is produced by\nmultiplication by the delay operator, $z^{-1} = e^{-j\n  \\hat{\\omega}k}$. In all three cases (but most simply for the\ntransfer function), we can obtain insight into the filter's operation\nfrom the \\emph{coefficients}, $b_k$. We can do this by factoring the\ntransfer function polynomial: its roots are the \\emph{zeros} of the\nfilter and they can be real or complex.  The placement of the zeros in\nthe complex plane (most usefully expressed in polar coordinates) will\ntell us which frequencies are suppressed and to what extent those\nfrequencies are suppressed (we can calculate each using the angle and\nmagnitude of the zero, respectively).\n\nMatlab has a modest set of functions related to filtering (a much more\nsubstantial set of tools comes along with the Matlab Signal Processing\nToolbox, but we will confine ourselves here to using core Matlab). The\n\\verb|filter| function applies a general digital filter to a\nsignal. For this lab, we will stick using this filter as follows:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\na = [1];              % This will be relevant later for feedback filters\nb = [b0 b1 b2];       % Coefficients (remember, Matlab indices start at 1)\ny = filter(b, a, x);  % x is input signal; y is output\n\\end{lstlisting}\nThis allows us to define the $b_k$ coefficients for a filter and provide\nthem to the filter function as a vector so that it can filter the\ninput signal.\n\nWe'd also like to specify a feedforward filter by indicating its zero\nlocations, which we can do by using the \\verb|poly| function to\ncompute the coefficients from a set of roots. So, for example, if we\nwant a feedforward filter with zeros at $0.9 + 0j$ and $0.75e^{\\pm j\n\\pi/4}$, we can compute the $b_k$ values as:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\nr = [ (0.9 + 0.0*j) (0.75*exp(j*pi/4)) (0.75*exp(-j*pi/4))];\nb = poly(r);\na = [1];\ny = filter(b, a, x);\n\\end{lstlisting}\n(Where the definition of \\verb|r| is written a bit more verbosely than\nit has to be.) Note that, from the documentation for \\verb|poly|, the\nvector of coefficients it produces are ordered from highest to lowest\npowers; this corresponds to the same order as the coefficients in the\n\\verb|b| vector, after dividing by $z^{-M}$, the highest delay\nterm.\n\nYou can visualize the zero locations with the following code:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\nplot(complex(r), 'o')\nrectangle('Position', [-1 -1 2 2], 'Curvature', [1 1])\nline([-1 1], [0 0], 'Color', [0 0 0])\nline([0 0], [-1 1], 'Color', [0 0 0])\naxis equal\n\\end{lstlisting}\nHere, we use the unfortunately named \\verb|rectangle| function to draw\nthe unit circle and the \\verb|line| function to draw the real and\nimaginary axes. Note also that we have to make sure that the value of\n$r$ that we pass to the \\verb|plot()| function is complex (since we\nwant to plot it on the complex plane) using the \\verb|complex()|\nfunction, because the roots of a polynomial can be real.\n\nFinally, you can compute and plot the magnitude of the filter's\nfrequency response pretty directly in Matlab:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\nomegahat = [0: 0.01: pi];   % define the frequency axis\nz = exp(j*omegahat);        % define the complex frequency axis\nH = polyval(b, z);          % evaluate the transfer function polynomial\nplot(omegahat, 20*log10(abs(H)/max(abs(H))));\nxlabel('$\\hat{\\omega}$, radians','Interpreter', 'latex');\nylabel('$|\\mathcal{H}(\\hat{\\omega})|$, dB','Interpreter', 'latex')\n\\end{lstlisting}\nYou'll note that the code above plots the ratio of the magnitude of\nthe frequency response to the maximum value of that magnitude. This is\ndone because it is convention to ignore whether a filter amplifies a\nsignal overall; what we are concerned with are the relative amounts\nthat different frequencies are passed or blocked.\n\n\nRemember, we can define a specific filter using either of the methods\nabove. Sometimes it is easier to understand the filter using zeros and\nsometimes it is easier to use the coefficients directly.  Either\nmethod can be used to represent the same filter, and we can go back\nand forth with the \\verb|poly| and \\verb|roots| functions (and back\nand forth between polar and rectangular representations of complex\nnumbers with the \\verb|abs|, \\verb|angle|, and \\verb|exp| functions).\n\n\n\\subsubsection{From Filter Coefficients to Transfer Function and Frequency Response}\n\nGiven the coefficients of an FIR filter we can solve for the zero\nlocations and the frequency response.  For example the two-point\naveraging system is given by:\n\\begin{equation}\ny[n] = \\frac{1}{2}x[n] + \\frac{1}{2}x[n-1]\n\\label{eq:two-point-filter}\n\\end{equation}\nwe can find the transfer function by rewriting the filter using the\ndelay operator, $z$:\n\\begin{eqnarray}\n  Y    & = & \\frac{1}{2} X + \\frac{1}{2} z^{-1} X \\\\\n  H(z) & = & \\frac{Y}{X} = \\frac{1}{2} (1 +  z^{-1})\n\\end{eqnarray}\nIf we're interested in the \\emph{zero location} we can then multiply\n$H(z)$ by $z/z$ to obtain:\n\\begin{equation}\n  H(z) = \\frac{\\frac{1}{2} (z + 1)}{z}\n\\end{equation}\nThe root of the numerator, $z=-1$ is the location of the only zero\n(the root(s) of the denominator for an FIR filter are always at $z=0$,\nand do not affect the frequency response). We can also derive the\nfrequency response from this by remembering that $H(e^{j\\hat{\\omega}})\n= \\mathcal{H}({\\hat{\\omega}})$ or that $z=e^{j\\hat{\\omega}}$. From the\nzero location, $z=-1$, we can immediately tell that the frequency\nresponse is zero at $e^{j\\hat{\\omega}}=-1$ or $\\hat{\\omega}=\\pi$. With\na zero at an angle of $\\hat{\\omega}=\\pi$, this is a low-pass\nfilter. As a warm-up, use Matlab and the coefficients of\nequation~\\ref{eq:two-point-filter} to verify the expected zero\nplacement and frequency response.\n\n\\subsubsection{From Zero Placement to Filter Coefficients}\n\nWhen we are given the zero placement, we can very easily determine the\nfilter coefficients because those zeros are the roots of a factored\npolynomial. For example, given two complex conjugate zeros, $z_1$ and\n$z_2$ (i.e., the real parts are equal, $\\Real[z_{1}] = \\Real[z_{2}] =\n\\Real[z_{1,2}] $, and the imaginary parts are negatives of one another\n$ \\Imag[z_{1}] = -\\Imag[z_{2}] $ or, equivalently in polar\ncoordinates, $z_{1} = r e^{j\\hat{\\omega_0}}$ and $z_{2} = r\ne^{-j\\hat{\\omega_0}}$), the transfer function is:\n\\begin{eqnarray}\n  H(z) & = & (z - z_1)(z - z_2)/z^2 \\\\\n  & = & (z^2 - (z_1 + z_2) z + z_1 z_2)/z^2 \\\\\n  & = & 1 - 2 \\Real[{z_{1,2}}] z^{-1} + r^2 z^{-2} \\\\\n  & = & 1 - 2 \\Real[r(\\cos(\\omega_0) \\pm j\\sin(\\omega_0))] z^{-1} + r^2 z^{-2} \\\\\n  & = & \\underbrace{1}_{b_0} -\\underbrace{2 r\\cos(\\omega_0)}_{b_1} z^{-1} + \\underbrace{r^2}_{b_2} z^{-2}\n\\end{eqnarray}\nAt this point, we can rewrite the transfer function as the filter's\ngenerating equation, using the delay operator $z^{-k}$, $y[n] = x[n] -\n2 r\\cos(\\omega_0)x[n-1] + r^2 x[n-2]$. This allows us to read off the\nfilter coefficients: $b_0 = 1$, $b_1 = -2 r\\cos(\\omega_0)$, and $b_2 =\nr^2$.\n\n\\subsection{Frequency Response and Pole-Zero Plots}\n\n\\paragraph{Step 1.1} Consider a filter that computes a running average\nof three points of our input signal (a \\emph{three-point averager}):\n\\begin{equation}\ny[n] = \\frac{1}{3} \\sum_{k=0}^2 x[n-k] \n     = \\frac{1}{3}x[n] + \\frac{1}{3}x[n-1] + \\frac{1}{3}x[n-2]\n\\end{equation}\n\n\\begin{enumerate}\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\item Draw a block diagram for this filter.\n\n\n\\item How many zeros will this filter have?\n\n\n\\item Find and sketch the zero locations using pencil and paper, then\n  use Matlab to verify this.\n\n\\item From the plot of zero locations, sketch the magnitude of the\n  frequency response as a function of $\\hat{\\omega}$ by hand and\n  verify this using Matlab. How does the minimum of the magnitude of\n  the frequency response relate to the polar representation of the\n  zero locations?  What kind of filter would you say this is?\n\n\\end{enumerate}\n\n\n\\paragraph{Step 1.2} A \\emph{first-difference} filter is an\napproximation to a discrete derivative operation. Its defining\nequation is:\n\\begin{equation}\n  y[n] = x[n] - x[n-1]\n\\end{equation}\n\n\\begin{enumerate}\\renewcommand{\\theenumi}{\\alph{enumi}}\n\n\\item Draw a block diagram for this filter.\n\n\n\\item Derive the transfer function, $H(z)$, for this filter. From\n\t  this, determine the expression for the frequency response,\n\t  $\\mathcal{H}(\\hat{\\omega})=H(e^{j\\hat{\\omega}})$.\n\n\n\\item From the transfer function, determine the filter's zero\n\tlocations and sketch them. Check your results with Matlab.\n\n\n\\item From the zero plot, sketch the magnitude of the filter's\n\t  frequency response as a function of $\\hat{\\omega}$. Use Matlab to\n\t  check your results. What kind of filter would you say this is?\n\t  \n\n\\item Use Matlab to compute this filter's response to the following\n\t  input. Generate an analog signal that is a sinusoid with\n          amplitude of 1, frequency of 2, and duration of 1. Sample\n          it at 32 samples/second and quantize it using 16\n          bits. What is the digital frequency, $\\hat{\\omega}$, of this\n          $f=2$Hz sinusoid?\n\n\\item Produce a figure with two plots: the top should be the\n          original digital signal, $X$, and the bottom should be the\n          filtered signal, $Y$.\n\n\\item Examine the plots of $X$ and $Y$. Note that $Y$ appears\n\t  to be a scaled and shifted sinusoid of the same frequency as\n\t  $X$. The exception is the first point, $y[0]$. Explain why $y[0]$ is\n\t  different (if you are unsure, consider the defining equation\n          and the input values to it for $n=0$).\n\n\n\\item Estimate the frequency, amplitude, and phase of $Y$ directly\n\t  from its plot (ignoring $y[0]$).\n\n\n\\item To compare these measurements to theory, use your\n          expression for the filter's frequency response to calculate\n          the amplitude and phase at the digital frequency\n          $\\hat{\\omega}$ you determined above. How do these compare to\n          what you determined from the Matlab plots?\n\n\n\\end{enumerate}\n\n\\paragraph{Step 1.3} Just as we can compute a discrete first\nderivative with a first-difference filter, we can compute a discrete\nsecond derivative with a \\emph{second difference filter}.\n\n\\begin{enumerate}\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\item Use your expression for the transfer function of the first\n\t  difference filter and your knowledge that the combined transfer\n\t  function of two filters cascaded, or connected in series, is the\n\t  product of their individual transfer functions to determine the\n\t  transfer function for a second-difference filter.\n\n\n\\item Draw a block diagram for this filter.\n\t\n\n\\item Determine the filter's zero locations and sketch them. Check\n\t  your results using Matlab.\n\t  \n\t  \n\n\\item From the zero plot, sketch the magnitude of the filter's\n          frequency response as a function of $\\hat{\\omega}$. Use\n          Matlab to check your results. What kind of filter would you\n          say this is?\n\n\n\\end{enumerate}\n\n\n\\paragraph{Step 1.4} Consider a feedforward filter with complex\nconjugate zeros at $z_{1,2} = -0.5 \\pm j 0.5$.\n\n\\begin{enumerate}\\renewcommand{\\theenumi}{\\alph{enumi}}\n\\item Determine the filter coefficients.\n\n\n\\item Use Matlab to plot the frequency response of the filter.\n\n\\item What are the effects of the zeros on the frequency response?\n\t  What kind of filter would you call this?\n\n\\end{enumerate}\n\n\\subsection{Linearity and Cascading Filters}\n\n\\paragraph{Step 2.1} A system is called \\emph{linear} if a sum of\ndifferent inputs produces an output that is the sum of the outputs for\nthe inputs taken individually.  Perform a simple test of the linearity\nof the filter from step 1.2 by doubling the input amplitude in Matlab\n($X' = 2X = X + X$). How does the new output amplitude compare to the\nold one?\n\n\n\\paragraph{Step 2.2} In one of the self-test exercises in the\ntextbook, two filters with transfer functions $H_1(z) = b_0 +\nb_1z^{-1}$ and $H_2(z) = b'_0 + b'_1z^{-1}$ were connected in series,\nand it was shown that they could be connected in either order to\nproduce the same composite effect (the same overall transfer\nfunction). Redo this exercise using the \\emph{defining equations} for\nthe two filters, i.e., $y_1[n] = F_1(x[n])$ for the filter with\ntransfer function $H_1(z)$ and $y_2[n] = F_2(x[n])$ for the filter\nwith transfer function $H_2(z)$. In other words, show that\n$F_2(F_1(x[n])) = F_1(F_2(x[n]))$.\n\n\n\\paragraph{Step 2.3} Use Matlab to implement a 50\\% duty cycle square\nwave with amplitude 1, frequency 2Hz, and duration 1s. Sample and\nquantize it appropriately (to make your figures look nicer, feel free\nto chose a sampling rate much higher than the minimum). Send the\nresultant digital signal through the previously-defined three-point\naverager filter, and then the output of that filter through the first\ndifference filter. Plot the input and output. What does the output of\nthis combined filter look like?\n\n\n\\paragraph{Step 2.4} Now, switch the order you apply the filters so\nthat the first difference filter is first and the three-point averager\nis second. Plot the input and output. How does the output of this\nconfiguration compare to that of the preceding step? Does this match\nwhat you expected? Why or why not?\n\n\n% LocalWords:  WebQ MATLAB\n", "meta": {"hexsha": "61426bbeaa198a0f4616a04d9b0e5754018799ef", "size": 14926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Matlab Labs/lab4/lab4.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/lab4/lab4.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/lab4/lab4.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": 43.3895348837, "max_line_length": 105, "alphanum_fraction": 0.7222966635, "num_tokens": 4207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6020835488900964}}
{"text": "% Ref fra reliability prob\n\\chapter{Nonhomogenous Poisson process}\n\\section{Introduction}\nIn this chapter we introduce the nonhomogenous Poisson process(NHPP) and its sufficient statistics.\nThe case to be studied is a nonhomogenous Poisson process, NHPP. This is when the rate function for a poisson process is dependent on time. A NHPP is first of all a counting process. The following definitions are from \\cite{rausand2004system}. The definition of a counting process is as follows\n\\begin{defn}\nA stochastic process $\\{N(t), t \\geq 0 \\}$ is said to be a counting process $N(t)$ satisfies:\n\\begin{enumerate}\n\\item $N(t)\\geq 0$.\n\\item $N(t)$ is integer valued.\n\\item If $s<t$, then $N(s) \\leq N(t)$.\n\\item For $s<t$, $[N(t) - N(s)]$ represents the number of failures that have occured in the interval $(s,t]$.\n\\end{enumerate}\n\\end{defn}\nThen the definition of a NHPP is as given below\n\\begin{defn} % S 277\nA coutning process $\\{ N(t), t \\geq 0 \\}$ is a nonhomogeneous (or nonstationary) Poisson process with rate function $\\lambda (t)$ for $t \\geq 0 $, if\n\\begin{enumerate}\n\\item $N(0) = 0$.\n\\item $\\{N(t), t \\geq 0\\}$ has independent increments.\n\\item $Pr(N(t + \\Delta t) - N(t) \\geq 2) = o(\\Delta t)$, which meansthat the system will not experience more than one failure at the same time.\n\\item $Pr(N(t + \\Delta t) - N(t) = 1) = \\lambda(t) \\Delta t + o(\\Delta t)$\n\\end{enumerate}\n\\end{defn}\nFor this NHPP we are going to use a rate function which is a combination of power-law and log-linear. The rate function is as follows,\n\\begin{equation}\n\\lambda (t) = abt^{b-1}e^{ct},\n\\label{eq:rate}\n\\end{equation}\nwhere $a$, $b$ and $c$ are parameters of the model. The parameter for the NHPP can be denoted\n\\begin{equation}\n\\Lambda(t) = \\int_{0}^{t} \\lambda(u) du. \n\\label{eq:largelambda}\n\\end{equation}\nThe NHPP model is given by,\n\\begin{equation}\nP(N(t) = n) = \\frac{\\Lambda(t)^n}{n!}e^{-\\Lambda(t)} \\quad n=0,1,... \\quad 0\\leq t \\leq \\tau.\n\\end{equation}\nTo generate data it is recommended to have around 30 data points or above. This means that the parameters of the NHPP must be chosen to fullfill this. From a NHPP we have that the expected number of events within a time $t$ is $\\Lambda(t)$. Since we have assumed that all values are between 0 and 1, the expected number of events is\n\\begin{equation}\nE[events] = \\Lambda(1).\n\\end{equation}\n\n\n\n\\section{Parameters for rate function}\nSince the rate function is a combination of log-linear and power-law, as seen in equation \\ref{eq:rate}, the shape of the function can vary a lot. The parameters $b$ and $c$ are the one to take notice of. The parameter $a$ is just for scaling number of events. By testing for different parameters we have chosen six shapes of the rate function to be used. These shapes are denoted as model 1 through 6. The different models can be viewed in figures \\ref{fig:SmallLambdaA10B04C2}, \\ref{fig:SmallLambdaA160B2CM3}, \\ref{fig:SmallLambdaA20B2C1}, \\ref{fig:SmallLambdaA30B07C0} \\ref{fig:SmallLambdaA50B2CM1} and \\ref{fig:SmallLambdaA6B3C2}. From these figues we see that model 2 and 4 are close to gamma distributions \\cite{stacy1962generalization}.\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA10B04C2.png}{fig:SmallLambdaA10B04C2}{Plot of rate function for model 1 given $a = 10$, $b = 0.4$ and $c = 2$.}\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA160B2CM3.png}{fig:SmallLambdaA160B2CM3}{Plot of rate function for model 2 given $a = 160$, $b = 2$ and $c = -3$.}\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA20B2C1.png}{fig:SmallLambdaA20B2C1}{Plot of rate function for model 3 given $a = 20$, $b = 2$ and $c = 1$.}\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA30B07C0.png}{fig:SmallLambdaA30B07C0}{Plot of rate function for model 4 given $a = 30$, $b = 0.7$ and $c = 0$.}\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA50B2CM1.png}{fig:SmallLambdaA50B2CM1}{Plot of rate function for model 5 given $a = 50$, $b = 2$ and $c = -1$.}\n\\includefigure[width=0.9\\textwidth]{fig/SmallLambdaA6B3C2.png}{fig:SmallLambdaA6B3C2}{Plot of rate function for model 6 given $a = 6$, $b = 3$ and $c = 2$.}\n\n%\n", "meta": {"hexsha": "cb67660e99804dd32c6312167a592b758295e1ea", "size": 4105, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Thesis/chapters/nhppmodel.tex", "max_stars_repo_name": "mariufa/ProsjektOppgave", "max_stars_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_stars_repo_licenses": ["MIT"], "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/chapters/nhppmodel.tex", "max_issues_repo_name": "mariufa/ProsjektOppgave", "max_issues_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_issues_repo_licenses": ["MIT"], "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/chapters/nhppmodel.tex", "max_forks_repo_name": "mariufa/ProsjektOppgave", "max_forks_repo_head_hexsha": "3ef2fda314c55322de20f19ca861e4268a5e2d08", "max_forks_repo_licenses": ["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.3035714286, "max_line_length": 743, "alphanum_fraction": 0.728136419, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998508568415, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6020835449428221}}
{"text": "\\subsection{Projection algorithm}\n\\paragraph{}\nIn the proposed method, the mesh is generated by method introduced in \\cite{Liu2017} where intersections are calculated between the edge of the element and the triangular surface.\nThese triangular surfaces extracted from the STL files are an approximation of the exact geometry.\nIn order to retain the exact geometry, point projection algorithm is required to find the nearest point in parameter $(u, v)$ on the NURBS surface of the intersection point.\nSome $O(logN)$ algorithms were developed \\citep{Edelsbrunner:1985:CED:4007.4011, Chin1983OptimalAF} while presumably large number of tests on polygons is imposed.\nFurthermore, the accuracy is out of satisfactory for computer graphics and CAD communities.\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,z)$, its projection on the surface $S(u, v)$ so that the distance $|P-S(u,v)|$ is minimum is targeted.\nHowever, in the proposed method, the existence of numerous possible surfaces increases the computational cost significantly.\nThe projection point of the test point $P$ for every existing surface need to be determined and the one with the smallest minimum distance will be selected.\nOne possible improvement could be limit the candidate surfaces to only a few by utilizing its strong convex hull property and the fact that the NURBS surfaces have been divided into multiple sub-surfaces without interior knot in Sec.~\\ref{oct_sc:surface_division}.\nAnother property that can be taken into account is that most of the tests point are expected to be extremely close to their projections on the surfaces.\n\n\\paragraph{}\nThe building of the convex hull is explained in detail in Sec.~\\ref{oct_sec:convex_hull}.\nThe signed distance of the test point to all surfaces' convex hull is calculated and only the surfaces with negative signed distance which indicates that the point is contained in the convex hull will be selected as candidate.\nIf no negative distance is detected, a few number (taken as $3$ in the proposed method) of surfaces with minimum signed distance will be selected.\n\n\\paragraph{}\nIn order to find the projection of the test point $P$ on the surface $S$, the vector $r$ is defined as\n\\begin{equation}\n    \\mathbf{r} (u, v) =\n    \\mathbf{S} (u, v) -\n    \\mathbf{P}\n\\end{equation}\n%\nand two scalars $f$ and $g$ are defined as\n\\begin{equation}\n    \\left\\{\n        \\begin{array}{rl}\n            f (u, v) =\n            \\mathbf{r}(u, v) \\mathbf{\\cdot} \\mathbf{S}_u (u, v)\n            = 0 & \\\\\n            g (u, v) =\n            \\mathbf{r}(u, v) \\mathbf{\\cdot} \\mathbf{S}_v (u, v)\n            = 0 &\n        \\end{array}\n    \\right.\n\\label{oct_eq:projection_function}\n\\end{equation}\n%\nIn order to solve Eq.~\\ref{oct_eq:projection_function}, several notations are introduced\n\\begin{align*}\n    \\delta_i &=\n        \\begin{bmatrix}\n            \\Delta u \\\\\n            \\Delta v\n        \\end{bmatrix} = \n        \\begin{bmatrix}\n            u_{i+1} - u_i \\\\\n            v_{i+1} - v_i\n        \\end{bmatrix} \\\\\n    J_i &=\n        \\begin{bmatrix}\n            f_u & f_v \\\\\n            g_u & g_v\n        \\end{bmatrix} = \n        \\begin{bmatrix}\n            \\boldmath\n            |S_u|^2 + r \\cdot S_{uu}        &       S_u \\cdot S_v + r \\cdot S_{uv} \\\\\n            S_u \\cdot S_v + r \\cdot S_{uv}  &       |S_v|^2 + r \\cdot S_{vv}\n        \\end{bmatrix} \\\\\n    \\kappa_i & = -\n        \\begin{bmatrix}\n            f(u_i, v_i) \\\\\n            g(u_i, v_i)\n        \\end{bmatrix}\n\\end{align*}\n%\nWhere all values in matrix $j_i$ can be evaluated at $(u_i, v_i)$.\n$2$ by $2$ matrix $\\delta_i$ can be determined at step $i$ as\n\\begin{equation}\n    J_i \\delta_i = \\kappa_i\n\\end{equation}\n%\nIt can be derived by utilizing $\\delta_i$ so that\n\\begin{subequations}\n\\begin{align}\n    u_{i+1} & = u_i + \\Delta u \\\\\n    v_{i+1} & = v_i + \\Delta v\n\\end{align}\n\\label{oct_eq:projection_iteration}\n\\end{subequations}\n%\nThe iteration can be concluded as\n\\paragraph{1}\nIs the point coincide with $S(u_i, v_i)$ ?\n\\begin{equation*}\n    |\\mathbf{S} (u_i, v_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{align*}\n    \\frac{\n        |\\mathbf{S}_u (u_i, v_i) \\cdot\n        \\left(\n            \\mathbf{S}(u_i, v_i) - \\mathbf{P}\n        \\right)|\n    }{\n        |\\mathbf{S}_u (u_i, v_i)|\n        |\\mathbf{S}(u_i, v_i) - \\mathbf{P}|\n    } & \\leq \\epsilon_2 \\\\\n    \\frac{\n        |\\mathbf{S}_v (u_i, v_i) \\cdot\n        \\left(\n            \\mathbf{S}(u_i, v_i) - \\mathbf{P}\n        \\right)|\n    }{\n        |\\mathbf{S}_v (u_i, v_i)|\n        |\\mathbf{S}(u_i, v_i) - \\mathbf{P}|\n    } & \\leq \\epsilon_2\n\\end{align*}\n%\nwhere $\\epsilon_2$ stands for the tolerance for cosine.\nIf either of these conditions are met, the iteration is terminated.\nOtherwise Eq.~\\ref{oct_eq:projection_iteration} is performed to find the parameters $u_{i+1}$ and $v_{i+1}$ for next iteration.\n\\paragraph{3} ?\nMake sure $u$ and $v$ are within there domains\n\\begin{align*}\n    u_{i+1} & \\in [a,b] \\\\\n    v_{i+1} & \\in [c,d]\n\\end{align*}\n%\nwhere $a$, $b$, $c$ and $d$ are the lower and upper bounds for the knot vectors of surface $S$.\nIf the surface is open in $u$ direction\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 surface is open in $v$ direction\n\\begin{equation}\n    \\left\\{\n        \\begin{array}{rl}\n            v_{i+1} = c & v_{i+1} < c \\\\\n            v_{i+1} = d & v_{i+1} > d\n        \\end{array}\n    \\right.\n\\end{equation}\n%\nIf the surface is closed in $u$ direction\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%\nIf the surface is closed in $v$ direction\n\\begin{equation}\n    \\left\\{\n        \\begin{array}{rl}\n            v_{i+1} = d - ( c - v_{i+1} ) & v_{i+1} < c \\\\\n            v_{i+1} = c + ( v_{i+1} - d ) & v_{i+1} > d\n        \\end{array}\n    \\right.\n\\end{equation}\n%\n\\paragraph{4}\nThe difference between the new parameters $u_{i+1}$ and $v_{i+1}$ and the old ones $u_i$ and $v_i$ is insignificant ?\n\\begin{equation*}\n    |u(i+1) - u_i| \\mathbf{S}_u (u_i, v_i) +\n    (v_{i+1} - v_i) \\mathbf{S}_v (u_i, v_i) |\n    \\leq \\epsilon_1\n\\end{equation*}\nThe iteration will be terminated if this condition is met.", "meta": {"hexsha": "d4f44721e3bea8bab8a4f565418d19a26ea7b89b", "size": 6607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "octree/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": "octree/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": "octree/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": 37.3276836158, "max_line_length": 264, "alphanum_fraction": 0.6243378235, "num_tokens": 2073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6020324484217742}}
{"text": "\\chapter{Traditional coupled-cluster theory}\n\n\\begin{dfn}\\label{dfn:cc-effective-hamiltonian}\n\\thmtitle{Traditional coupled-cluster theory}\nA \\textit{wave operator} maps a determinant into a correlated wavefunction, $\\Y=\\W\\F$.\nThe \\textit{coupled-cluster Ansatz} is characterized by an exponential parametrization of the wave operator.\n\\begin{align}\n\\label{eq:cc-effective-hamiltonian}\n  H_{\\text{c}}\\Y_{\\text{CC}}\n=\n  E_{\\text{c}}\\Y_{\\text{CC}}\n&&\n  \\Y_{\\text{CC}}\n\\equiv\n  \\text{exp}(T)\n  \\F\n&&\n  T\n\\equiv\n  T_1\n+\n  T_2\n+\n  \\cd\n+\n  T_n\n&&\n  T_k\n\\equiv\n  (\\tfr{1}{k!})^2\n  t_{a_1\\cd a_k}^{i_1\\cd i_k}\n  \\tl{a}^{a_1\\cd a_k}_{i_1\\cd i_k}\n\\end{align}\nThe coupled-cluster Schr\\\"odinger equation can be projected onto the determinant basis to arrive at a series of equations\n\\begin{align}\n\\label{eq:projected-cc-equations}\n  \\ip{\\F|H_{\\text{c}}|\\Y_{\\text{CC}}}\n=\n  E_{\\text{c}}\n&&\n  \\ip{\\F_{ij\\cd}^{ab\\cd}|H_{\\text{c}}|\\Y_{\\text{CC}}}\n=\n  E_{\\text{c}}\n  \\ip{\\F_{ij\\cd}^{ab\\cd}|\\Y_{\\text{CC}}}\n\\end{align}\nwhich specify the coupled-cluster energy and the \\textit{amplitudes}, $t_{ab\\cd}^{ij\\cd}$.\nA different approach, known as \\textit{traditional coupled-cluster (TCC) theory}, first multiplies the Schr\\\"odinger equation on the left by the inverse of the wave operator\n\\begin{align}\n  \\ol{H}_{\\text{c}}\n  \\F\n=\n  E_{\\text{c}}\n  \\F\n&&\n  \\ol{H}_{\\text{c}}\n\\equiv\n  \\text{exp}(-T)\n  H_{\\text{c}}\\,\n  \\text{exp}(T)\n\\end{align}\nto define an \\textit{effective Hamiltonian}, $\\ol{H}_{\\text{c}}$.\nThe eigenvalue of this similarity-transformed\\footnote{See \\url{https://en.wikipedia.org/wiki/Matrix_similarity}.} Hamiltonian is the exact correlation energy, $E_{\\text{c}}$, but its eigenstate is the reference determinant, $\\F$, rather than the correlated wavefunction.\nNote that, unlike the true Hamiltonian, $\\ol{H}_{\\text{c}}$ is non-Hermitian.\nProjection onto the determinant basis yields energy and amplitude equations\n\\begin{align}\n\\label{eq:traditional-cc-equations}\n  \\ip{\\F|\\ol{H}_{\\text{c}}|\\F}\n=\n  E_{\\text{c}}\n&&\n  \\ip{\\F_{ij\\cd}^{ab\\cd}|\\ol{H}_{\\text{c}}|\\F}\n=\n  0\n\\end{align}\nwhich look similar to eq~\\ref{eq:projected-cc-equations}, except that the right-hand side of the amplitude equations is now zero.\nThe next few results show that the TCC similarity transformation removes disconnected terms in eq~\\ref{eq:projected-cc-equations}, of which $E_{\\text{c}}t_{ab\\cd}^{ij\\cd}$ is an example.\n\\end{dfn}\n\n\\begin{thm}\\label{thm:hausdorff}\n\\thmtitle{The Hausdorff Expansion}\n\\thmstatement{\n$\\ds{\n  e^{- X}Ye^{X}\n=\n  \\sum_{n=0}^\\infty\n  \\fr{1}{n!}\n  [\\,\\cdot\\,, X]^n(Y)\n}$\n}\\,\\footnote{\n$\n  [\\,\\cdot\\,, X]^n(Y)\n$\ndenotes a nested commutator,\n$\n  [\\cd[[Y,X],X]\\cd,X]\n$.\nFor $n=0$, we define\n$\n  [\\,\\cdot\\,, X]^0(Y)\n\\equiv\n  Y\n$.\n}\\vspace{5pt}\n\\thmproof{\n  This follows from\n  $\n    \\pd{^n}{\\la^n}\n    e^{-\\la X}Ye^{\\la X}\n  =\n    [\\,\\cdot\\,, X]^n(\n    e^{-\\la X}Ye^{\\la X}\n    )\n  $,\n  which we will prove by induction.\n  This is trivially true for $n=0$.\n  Assuming it holds for $n$, the following shows that it also holds for $n+1$, completing the induction.\n\\begin{align*}\n  \\tpd{^{n+1}}{\\la^{n+1}}\n  e^{-\\la X}Ye^{\\la X}\n=\n  [\\,\\cdot\\,, X]^n(\n  \\tpd{}{\\la}\n  e^{-\\la X}Ye^{\\la X}\n  )\n=\n  [\\,\\cdot\\,, X]^n(\n    e^{-\\la X}Ye^{\\la X} X\n  -\n    X e^{-\\la X}Ye^{\\la X}\n  )\n=\n  [\\,\\cdot\\,, X]^{n+1}(\n    e^{-\\la X}Ye^{\\la X}\n  )\n\\end{align*}\n  Substituting this result into a Taylor expansion of\n  $\n    e^{-\\la X}Ye^{\\la X}\n  $\n  about\n  $\\la=0$\n  evaluated at\n  $\\la=1$\n  completes the proof.\n}\n\\end{thm}\n\n\\begin{ex}\nThe Hausdorff expansion can be used to express the TCC effective Hamiltonian in powers of $T$.\n\\begin{align*}\n  \\ol{H}_{\\text{c}}\n=\n  \\text{exp}(-T)\n  H_{\\text{c}}\\,\n  \\text{exp}(T)\n=\n  H_{\\text{c}}\n+\n  [H_{\\text{c}}, T]\n+\n  \\tfr{1}{2!}\n  [[H_{\\text{c}}, T], T]\n+\n  \\tfr{1}{3!}\n  [[[H_{\\text{c}}, T], T], T]\n+\n  \\tfr{1}{4!}\n  [[[[H_{\\text{c}}, T], T], T], T]\n+\n  \\cd\n\\end{align*}\nThis expansion can be further simplified by analyzing the commutators with $T$ using Wick's theorem.\n\\end{ex}\n\n\\begin{prop}\\label{prop:wicks-theorem-for-commutators}\n\\thmstatement{\nIf $Q$ and $Q'$ are normal ordered and one of them has an even operator count,\n$\n  [Q,Q']\n=\n  \\gno{\n    \\ctr{}{Q}{}{Q}\n    QQ'\n  }\n-\n  \\gno{\n    \\ctr{}{Q}{'}{Q}\n    Q'Q\n  }\n$.%\n}\\vspace{2pt}%\n\\thmproof{\nBy Wick's theorem,\n$\n  QQ'\n-\n  Q'Q\n=\n  \\gno{QQ'}\n+\n  \\gno{\n    \\ctr{}{Q}{}{Q}\n    QQ'\n  }\n-\n  \\gno{Q'Q}\n-\n  \\gno{\n    \\ctr{}{Q}{'}{Q}\n    Q'Q\n  }\n$.\nThe proposition follows from the fact that\n$\n  \\gno{QQ'}\n=\n  \\gno{Q'Q}\n$\nwhen one of the strings contains an even number of operators.\n}\n\\end{prop}\n\n\\begin{cor}\n\\label{cor:tcc-similarity-transformation-connected}\n\\thmstatement{\n  TCC similarity-transformed operators,\n  $\n    \\ol{W}\n  \\equiv\n    \\text{exp}(-T)\n    W\n    \\text{exp}(T)\n  $,\n  can be evaluated as\n  $\n    \\ol{W}\n  =\n    (\n      W\\,\n      \\text{exp}(T)\n    )_{\\text{C}}\n  $,\n  where the subscript $\\text{C}$ denotes a restriction to connected diagrams.\n}\n\\thmproof{\n  \\Cref{prop:wicks-theorem-for-commutators} implies\n$\n  [W,T]\n=\n\\gno{\n  \\ctr{}{W}{}{T}\n  WT\n}\n$\nand, by straightforward induction,\n$\n  [\\,\\cdot\\,,T]^n(W)\n=\n\\gno{\n  \\ctr[1.4]{}{W}{TT\\cd}{T}\n  \\ctr[0.7]{}{W}{T}{T}\n  \\ctr[0.0]{}{W}{}{T}\n  WTT\\cd T\n}\n=\n  (WT^n)_{\\text{C}}\n$,\nsince\n$T$\nhas no contractions with operators to its right.\\footnote{This is easily seen from the diagram.  It comes from the fact that $T$ is composed entirely of quasi-particle creation operators.}\n  Applying \\cref{thm:hausdorff} to $\\ol{W}$ and using this result completes the proof.\n}\n\\end{cor}\n\n\n\\begin{rmk}\\label{rmk:connected-expansion}\nApplying \\cref{cor:tcc-similarity-transformation-connected} to the coupled-cluster effective Hamiltonian gives the following expansion\n\\begin{align}\n  \\ol{H}_{\\text{c}}\n=\n  (H_{\\text{c}}\\,\n   \\text{exp}(T))_{\\text{C}}\n=\n  (\n    H_{\\text{c}}\n  +\n    H_{\\text{c}}\n    T\n  +\n    \\tfr{1}{2!}\n    H_{\\text{c}}\n    T^2\n  +\n    \\tfr{1}{3!}\n    H_{\\text{c}}\n    T^3\n  +\n    \\tfr{1}{4!}\n    H_{\\text{c}}\n    T^4\n  )_{\\text{C}}\n\\end{align}\nwhich ends at the fourth power because $H_{\\text{c}}$ is a linear combination of one- and two-particle operators, which can contract at most two and four $T$'s, respectively.\nUsing this result, the energy and amplitude equations are often written as\n\\begin{align}\n\\label{eq:traditional-cc-equations-2}\n  \\ip{\\F|H_{\\text{c}}\\,\\text{exp}(T)|\\F}_{\\text{C}}\n=\n  E_{\\text{c}}\n&&\n  \\ip{\\F_{ij\\cd}^{ab\\cd}|H_{\\text{c}}\\,\\text{exp}(T)|\\F}_{\\text{C}}\n=\n  0\n\\end{align}\nwhere the subscript $\\text{C}$ on the expectation value ket is shorthand for\n$\n  \\ip{\\F_{ij\\cd}^{ab\\cd}|(H_{\\text{c}}\\,\\text{exp}(T))_{\\text{C}}|\\F}\n$.\n\\end{rmk}\n\n\n\\begin{ntt}\nThe following is suggested notation for the diagonal and off-diagonal contributions to the Fock operator.\n\\begin{align}\n\\diagram{\n  \\draw (-0.5,0) node[circlex] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n=\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n&&\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n\\equiv\n  H_0\n&&\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n\\equiv\n  f_p^q(1-\\delta_p^q)\n  \\tl{a}^p_q\n\\end{align}\nso that\n$\n  H\n=\n  E_{\\text{ref}}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.35);\n  \\draw[-<-] (h1) to ++(0,-0.35);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.35);\n  \\draw[-<-] (h1) to ++(0,-0.35);\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot=white}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.35);\n  \\draw[-<-] (g1) to ++(0,-0.35);\n  \\draw[->-] (g2) to ++(0,+0.35);\n  \\draw[-<-] (g2) to ++(0,-0.35);\n}\n$\\\nis the full electronic Hamiltonian\nand\n$\n  V_{\\text{c}}\n=\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.35);\n  \\draw[-<-] (h1) to ++(0,-0.35);\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot=white}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.35);\n  \\draw[-<-] (g1) to ++(0,-0.35);\n  \\draw[->-] (g2) to ++(0,+0.35);\n  \\draw[-<-] (g2) to ++(0,-0.35);\n}\n$.\nNote that\n\\begin{align*}\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n=\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlez] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[-<-] (h1) to ++(0,+0.5);\n  \\draw[->-] (h1) to ++(0,-0.5);\n}\n&&\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n=\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(-0.25,+0.5);\n  \\draw[-<-] (h1) to ++(+0.25,+0.5);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(-0.25,-0.5);\n  \\draw[-<-] (h1) to ++(+0.25,-0.5);\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[-<-] (h1) to ++(0,+0.5);\n  \\draw[->-] (h1) to ++(0,-0.5);\n}\n\\end{align*}\nwhere the excitation level $\\pm1$ contributions to $H_0$ have been omitted because its interaction tensor is diagonal.\n\\end{ntt}\n\n\n\\begin{rmk}\nIt can be shown that the determinant basis forms an eigenbasis for the diagonal part of the Fock operator.\\footnotemark\n\\begin{align}\n  H_0\\F_{i_1\\cd i_k}^{a_1\\cd a_k}\n=\n  \\mc{E}_{i_1\\cd i_k}^{a_1\\cd a_k}\n  \\F_{i_1\\cd i_k}^{a_1\\cd a_k}\n&&\n  H_0\n\\equiv\n  f_p^p\\tl{a}^p_p\n&&\n  \\mc{E}_{q_1\\cd q_k}^{p_1\\cd p_k}\n\\equiv\n  \\sum_{r=1}^k\n  f_{p_r}^{p_r}\n-\n  \\sum_{r=1}^k\n  f_{q_r}^{q_r}\n\\end{align}\nNoting that $H_0$ is Hermitian, this implies\n$\\ip{\\F_{ij\\cd}^{ab\\cd}|H_0\\,T|\\F}=\\mc{E}_{ij\\cd}^{ab\\cd}\\ip{\\F_{ij\\cd}^{ab\\cd}|T|\\F}=\\mc{E}_{ij\\cd}^{ab\\cd}t_{ab\\cd}^{ij\\cd}$.\nThis can be used to rearrange the amplitude equation in\n(\\ref{eq:traditional-cc-equations-2}) as follows, which defines the working\nequations used to iteratively solve TCC.%\n\\footnote{%\n    Note that $\\ip{\\F_{ij\\cd}^{ab\\cd}|H_0\\,\\exp(T)|\\F}_{\\text{C}}=\\ip{\\F_{ij\\cd}^{ab\\cd}|H_0\\,T|\\F}$.\n}\n\\begin{align}\n  t_{ab\\cd}^{ij\\cd}\n=\n  (\\mc{E}_{ab\\cd}^{ij\\cd})^{-1}\n  \\ip{\\F_{ab\\cd}^{ij\\cd}|V_{\\text{c}}\\,\\text{exp}(T)|\\F}_{\\text{C}}\n&&\n  V_{\\text{c}}\n\\equiv\n  H_{\\text{c}}\n-\n  H_0\n=\n  f_p^q(1-\\delta_p^q)\n  \\tl{a}^p_q\n+\n  \\tfr{1}{4}\n  \\ol{g}_{pq}^{rs}\n  \\tl{a}^{pq}_{rs}\n\\end{align}\nIn M\\o ller-Plesset perturbation theory, $H_0$ is known the \\textit{zeroth order Hamiltonian} and $V_{\\text{c}}$ is the \\textit{perturbation}.\nThese operators are also known as the \\textit{model Hamiltonian} and \\textit{fluctuation potential}, respectively.\n\\end{rmk}\n\\footnotetext{\nThe proof is as follows.\nFirst, note that $a^p_p\\F_\\si = n_p^\\si \\F_\\si$, where $n_p^\\si$ is the occupation of $\\y_p$ in $\\F_\\si$.\nBy Wick's theorem, $a^p_p=\\tl{a}^p_p+n_p^{\\text{ref}}$, where $n_p^{\\text{ref}}$ denotes the occupation of $\\y_p$ in $\\F$.\nTherefore, $\\tl{a}^p_p\\F_\\si = (n_p^\\si - n_p^{\\text{ref}})\\F_\\si$ and $H_0\\F_\\si = \\pr{\\sum_{p\\in\\F_\\si}f_p^p - \\sum_{p\\in\\F}f_p^p}\\F_\\si$.\n}\n\n\n\\begin{dfn}\n\\thmtitle{Excitation level}\nThe \\textit{excitation level} of a graph equals the net number of particles or quasi-particles it creates, divided by two.\nFor example, the quasi-particle excitation levels of the $T_1$, $T_2$ and $T_3$ operators are $1$, $2$, and $3$, respectively, and that of $\\tl{a}_{abcd}^{ijkl}$ is $-4$.\nA convenient rule for evaluating reference expectation values is that the total excitation level of a closed graph must balance out to zero.\n\\end{dfn}\n\n\\begin{ex}\nThe excitation levels in the quasi-particle expansions of one- and two-particle operators are as follows.\n\\begin{align*}\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot=white] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n  \\node at (0,-0.8) {$(0)$};\n}\n=&\\\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(0,+0.5);\n  \\draw[-<-] (h1) to ++(0,-0.5);\n  \\node at (0,-0.8) {$(0)$};\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(-0.25,+0.5);\n  \\draw[-<-] (h1) to ++(+0.25,+0.5);\n  \\node at (0,-0.8) {$(+1)$};\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(-0.25,-0.5);\n  \\draw[-<-] (h1) to ++(+0.25,-0.5);\n  \\node at (0,-0.8) {$(-1)$};\n}\n+\n\\diagram{\n  \\draw (-0.5,0) node[circlep] (h) {} -- (0,0) node[ddot] (h1) {};\n  \\draw[->-] (h1) to ++(0,-0.5);\n  \\draw[-<-] (h1) to ++(0,+0.5);\n  \\node at (0,-0.8) {$(0)$};\n}\n\\\\[10pt]\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot=white}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.5);\n  \\draw[-<-] (g1) to ++(0,-0.5);\n  \\draw[->-] (g2) to ++(0,+0.5);\n  \\draw[-<-] (g2) to ++(0,-0.5);\n  \\node at (0.5,-0.8) {$(0)$};\n}\n=&\\\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.5);\n  \\draw[-<-] (g1) to ++(0,-0.5);\n  \\draw[->-] (g2) to ++(0,+0.5);\n  \\draw[-<-] (g2) to ++(0,-0.5);\n  \\node at (0.5,-0.8) {$(0)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.5);\n  \\draw[-<-] (g1) to ++(0,-0.5);\n  \\draw[->-] (g2) to ++(-0.25,+0.5);\n  \\draw[-<-] (g2) to ++(+0.25,+0.5);\n  \\node at (0.5,-0.8) {$(+1)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,+0.5);\n  \\draw[-<-] (g1) to ++(0,-0.5);\n  \\draw[->-] (g2) to ++(-0.25,-0.5);\n  \\draw[-<-] (g2) to ++(+0.25,-0.5);\n  \\node at (0.5,-0.8) {$(-1)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(-0.25,+0.5);\n  \\draw[-<-] (g1) to ++(+0.25,+0.5);\n  \\draw[->-] (g2) to ++(-0.25,+0.5);\n  \\draw[-<-] (g2) to ++(+0.25,+0.5);\n  \\node at (0.5,-0.8) {$(+2)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(-0.25,-0.5);\n  \\draw[-<-] (g1) to ++(+0.25,-0.5);\n  \\draw[->-] (g2) to ++(-0.25,+0.5);\n  \\draw[-<-] (g2) to ++(+0.25,+0.5);\n  \\node at (0.5,-0.8) {$(0)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(-0.25,-0.5);\n  \\draw[-<-] (g1) to ++(+0.25,-0.5);\n  \\draw[->-] (g2) to ++(-0.25,-0.5);\n  \\draw[-<-] (g2) to ++(+0.25,-0.5);\n  \\node at (0.5,-0.8) {$(-2)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,-0.5);\n  \\draw[-<-] (g1) to ++(0,+0.5);\n  \\draw[->-] (g2) to ++(-0.25,+0.5);\n  \\draw[-<-] (g2) to ++(+0.25,+0.5);\n  \\node at (0.5,-0.8) {$(+1)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,-0.5);\n  \\draw[-<-] (g1) to ++(0,+0.5);\n  \\draw[->-] (g2) to ++(-0.25,-0.5);\n  \\draw[-<-] (g2) to ++(+0.25,-0.5);\n  \\node at (0.5,-0.8) {$(-1)$};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(0,-0.5);\n  \\draw[-<-] (g1) to ++(0,+0.5);\n  \\draw[->-] (g2) to ++(0,-0.5);\n  \\draw[-<-] (g2) to ++(0,+0.5);\n  \\node at (0.5,-0.8) {$(0)$};\n}\\,\\,.\n\\end{align*}\n\\end{ex}\n\n\n\\begin{ex}\n\\thmtitle{The CCSDTQ equations}\nTruncating the cluster operator at quadruples, $T\\approx T_1 + T_2 + T_3 + T_4$, gives the CCSDTQ approximation.\nThe resulting singles, doubles, triples, and quadruples amplitude equations are given by\\begin{align}\n\\nonumber\n  t_a^i\n=&\\\n  (\\mc{E}_a^i)^{-1}\n  \\ip{\\F_i^a|\n    V_{\\text{c}}\n    (\n      1\n    +\n      T_1\n    +\n      T_2\n    +\n      T_3\n    +\n      \\tfr{1}{2}\n      T_1^2\n    +\n      T_1T_2\n    +\n      \\tfr{1}{3!}\n      T_1^3\n    )\n  |\\F}_{\\text{C}}\n\\\\[3pt]\n\\nonumber\n  t_{ab}^{ij}\n=&\\\n  (\\mc{E}_{ab}^{ij})^{-1}\n  \\br{\\F_{ij}^{ab}}\n    V_{\\text{c}}\n    (\n      1\n    +\n      T_1\n    +\n      T_2\n    +\n      T_3\n    +\n      T_4\n    +\n      \\tfr{1}{2}\n      T_1^2\n    +\n      T_1T_2\n    +\n      T_1T_3\n    +\n      \\tfr{1}{2}\n      T_2^2\n    +\n      \\tfr{1}{3!}\n      T_1^3\n    +\n      \\tfr{1}{2}\n      T_1^2T_2\n    +\n      \\tfr{1}{4!}\n      T_1^4\n    )\n  \\kt{\\F}_{\\text{C}}\n\\\\[3pt]\n\\nonumber\n  t_{abc}^{ijk}\n=&\\\n  (\\mc{E}_{abc}^{ijk})^{-1}\n  \\br{\\F_{ijk}^{abc}}\n    V_{\\text{c}}\n    (\n      T_2\n    +\n      T_3\n    +\n      T_4\n    +\n      T_1T_2\n    +\n      T_1T_3\n    +\n      \\tfr{1}{2}\n      T_2^2\n    +\n      T_1T_4\n    +\n      T_2T_3\n    +\n      \\tfr{1}{2}\n      T_1^2T_2\n    +\n      \\tfr{1}{2}\n      T_1^2T_3\n    +\n      \\tfr{1}{2}\n      T_1T_2^2\n    +\n      \\tfr{1}{3!}\n      T_1^3T_2\n    )\n  \\kt{\\F}_{\\text{C}}\n\\\\[3pt]\n\\nonumber\n  t_{abcd}^{ijkl}\n=&\\\n  (\\mc{E}_{abcd}^{ijkl})^{-1}\n  \\br{\\F_{ijkl}^{abcd}}\n    V_{\\text{c}}\n    (\n      T_3\n    +\n      T_4\n    +\n      T_1T_3\n    +\n      \\tfr{1}{2}\n      T_2^2\n    +\n      T_1T_4\n    +\n      T_2T_3\n    +\n      T_2T_4\n    +\n      \\tfr{1}{2}\n      T_3^2\n    +\n      \\tfr{1}{2}\n      T_1^2T_3\n    +\n      \\tfr{1}{2}\n      T_1T_2^2\n    +\n      \\tfr{1}{2}\n      T_1^2T_4\n\\\\\n\\nonumber\n&\n\\hphantom{\n  (\\mc{E}_{abcd}^{ijkl})^{-1}\n  \\br{\\F_{ijkl}^{abcd}}\n    V_{\\text{c}}\n    (\n      T_3\\\n }\n    +\n      T_1T_2T_3\n    +\n      \\tfr{1}{3!}\n      T_2^3\n    +\n      \\tfr{1}{3!}\n      T_1^3T_3\n    +\n      \\tfr{1}{2!2!}\n      T_1^2T_2^2\n    )\n  \\kt{\\F}_{\\text{C}}\n\\end{align}\nwhere several contributions to $\\text{exp}(T_1+T_2+T_3+T_4)$ have been omitted either because the excitation levels do not balance or because they require one of the cluster operators to be disconnected from the Hamiltonian.\n\\end{ex}\n\n\n\\begin{dfn}\n\\thmtitle{Isomorphism}\nFor any invertible map $S:\\ol{V}\\rightarrow V$, we can express operators and vectors on $V$ as\n\\begin{align}\n  A\n=\n  S\n  \\ol{A}\n  S^{-1}\n&&\n  \\kt{v}\n=\n  S\n  \\kt{\\ol{v}}\n&&\n  \\br{v}\n=\n  \\br{\\ol{v}}\n  S^{-1}\n\\end{align}\nin terms of operators and vectors on $\\ol{V}$.\nNote that the transformed bra and ket, $\\br{\\ol{v}}$ and $\\kt{\\ol{v}}$, corresponding to $v$ are not adjoints unless the transformation is unitary, $S^{-1}=S\\dg$.\nThe similarity-transformed operator $\\ol{A}$ retains all of the basis-independent properties of $A$, such as its trace, determinant, and eigenvalue spectrum, and its matrix elements satisfy $\\ip{\\ol{v}|\\ol{A}|\\ol{v}'}=\\ip{v|A|v'}$.\nMore broadly, the invertibility of $S$ implies an \\textit{isomorphism} between $V$ and $\\ol{V}$, such that all statements about $V$ are in one-to-one correspondence with statements about $\\ol{V}$ under this transformation.\n\\end{dfn}\n\n\n\\begin{rmk}\nSince exponential operators are automatically invertible, the TCC wave operator defines a similarity transformation of Fock space into itself.\nThe image of the Schr\\\"odinger equation under this transformation is as follows\n\\begin{align}\n\\label{eq:similarity-transformed-schrodinger-equation}\n  \\ol{H}\n  \\kt{\\ol{\\Y}_k}\n=\n  E_k\n  \\kt{\\ol{\\Y}_k}\n&&\n  \\br{\\ol{\\Y}_k}\n  \\ol{H}\n=\n  \\br{\\ol{\\Y}_k}\n  E_k\n&&\n\\begin{array}{c@{\\ }l}\n  \\ol{H}\n&=\n  \\text{exp}(-T)\n  H\\,\n  \\text{exp}(T)\n\\\\\n  \\kt{\\ol{\\Y}_k}\n&=\n  \\text{exp}(-T)\n  \\kt{\\Y_k}\n\\\\\n  \\br{\\ol{\\Y}_k}\n&=\n  \\br{\\Y_k}\\,\n  \\text{exp}(T)\n\\end{array}\n\\end{align}\nwhere the $k\\eth$ left and right eigenstates are not adjoints because $\\text{exp}(T)$ is inherently non-unitary.\nIn TCC, $T$ is determined by the requirement that the ground-state right eigenvector of $\\ol{H}$ be the reference determinant,\n$\n  \\kt{\\ol{\\Y}_0}\n\\overset{!}{=}\n  \\kt{\\F}\n$.\n\\end{rmk}\n\n\n\\begin{dfn}\n\\thmtitle{Equation-of-motion coupled-cluster theory}\nExpanding the left and right eigenstates of $\\ol{H}$ in the determinant basis leads to the \\textit{equation-of-motion (EOM) coupled-cluster equations}\n\\begin{align}\n\\begin{array}{r@{\\ }lr@{\\ }l}\n  \\ol{H}\n  \\,{}^kR\n  \\kt{\\F}\n&\n=\n  E_k\n  \\,{}^kR\n  \\kt{\\F}\n&\n  R\n&=\n  R_0\n+\n  R_1\n+\n  \\cd\n+\n  R_n\n\\\\[7pt]\n  \\br{\\F}\n  \\,{}^kL\\,\n  \\ol{H}\n&=\n  \\br{\\F}\n  \\,{}^kL\\,\n  E_k\n&\n  L\n&=\n  L_0\n+\n  L_1\n+\n  \\cd\n+\n  L_n\n\\end{array}\n&&\n  \\ip{\\F|\n    {}^kL\\,\n    {}^lR\n  |\\F}\n\\overset{!}{=}\n  \\delta_{kl}\n\\end{align}\nwhich are analogous to the configuration interaction eigenvalue equation, ${}^kR$ and ${}^kL$ being linear excitation and de-excitation operators analogous to $C$ and $C\\dg$.\nThe condition on the right indicates that left and right eigenstates are chosen to form a \\textit{biorthonormal system} by normalizing the overlap of the $k\\eth$ left and right eigenfunctions to equal one.\nObservable expectation values are given by\n$\n  \\ip{\\Y_k|W|\\Y_k}\n=\n  \\ip{\\F|{}^kL\\,\\ol{W}\\,{}^kR|\\F}\n$\nin terms of left and right EOM coefficients.\nTransition matrix elements are given by\n$\n  \\ip{\\Y_k|W|\\Y_l}\n=\n  \\ip{\\F|{}^kL\\,\\ol{W}\\,{}^lR|\\F}\n$.\n\\end{dfn}\n\n\\begin{dfn}\n\\thmtitle{The coupled-cluster Lagrangian}\nThe ground-state TCC equations are equivalent to requiring ${}^0R=1$, which implies ${}^0L_0=1$ from the biorthonormality condition.\nTherefore, the ground-state left eigenvector has the form\n\\begin{align}\n\\label{eq:cc-ground-state-wave-operators}\n  {}^0L\n=\n  1\n+\n  \\La\n&&\n  \\La\n=\n  \\La_1\n+\n  \\cd\n+\n  \\La_n\n&&\n  \\La_k\n\\equiv\n  (\\tfr{1}{k!})^2\n  \\la_{i_1\\cd i_k}^{a_1\\cd a_k}\n  \\tl{a}^{i_1\\cd i_k}_{a_1\\cd a_k}\n\\end{align}\nand the ground-state energy can be written as follows, in an expression known as the \\textit{coupled-cluster Lagrangian}.\n\\begin{align}\n  \\ip{\\Y_0|H|\\Y_0}\n=\n  \\ip{\\F|\n    (\n      1\n    +\n      \\La\n    )\n    \\ol{H}\n  |\\F}\n\\equiv\n  \\mc{L}(\\bo{t},\\bm{\\la})\n\\end{align}\nTo see why this constitutes a Lagrangian, note that setting its gradient with respect to $\\la_{i_1\\cd i_k}^{a_1\\cd a_k}$ equal to zero yields the TCC amplitude equations of eq~\\ref{eq:traditional-cc-equations}.\nIf these are satisfied, the $\\la$-dependent part of the equation vanishes and the Lagrangian returns the coupled-cluster energy:\n$\n  \\ip{\\F|\\ol{H}|\\F}\n=\n  E\n$.\nTherefore, the $\\la$ coefficients can be viewed as Lagrange multipliers enforcing the TCC amplitude equations as a constraint.\n\\end{dfn}\n\n\n\\begin{dfn}\n\\thmtitle{The coupled-cluster lambda equations}\nSetting the gradient of $\\mc{L}$ with respect to $t_{a_1\\cd a_k}^{i_1\\cd i_k}$ equal to zero gives the \\textit{coupled-cluster lambda equations}, which determine the Lagrange multpliers.\n\\begin{align}\n  \\br{\\F}\n  (\n    1\n  +\n    \\La\n  )\n  H_{\\text{c}}\\,\n  \\text{exp}(T)\n  \\kt{\\F_{i_1\\cd i_k}^{a_1\\cd a_k}}_{\\text{C}}\n\\overset{!}{=}\n  0\n\\end{align}\nThe subscript $\\text{C}$ now denotes that $H_{\\text{c}}$ is connected both to the ket and to the $T$ operators.\nThis can be rearranged as\\footnote{Note that $\\ip{\\F|\\La H_0 T^p|\\F_{i_1\\cd i_k}^{a_1\\cd a_k}}_{\\text{C}}=0$ for $p\\geq 1$, since the model Hamiltonian can only connect to one operator on either side.}\n\\begin{align}\n  \\la_{i_1\\cd i_k}^{a_1\\cd a_k}\n=\n  (\\mc{E}_{a_1\\cd a_k}^{i_1\\cd i_k})^{-1}\n  \\br{\\F}\n  (\n    1\n  +\n    \\La\n  )\n  V_{\\text{c}}\\,\n  \\text{exp}(T)\n  \\kt{\\F_{i_1\\cd i_k}^{a_1\\cd a_k}}_{\\text{C}}\n\\end{align}\nwhich sets up the iterative procedure for determining $\\la_{i_1\\cd i_k}^{a_1\\cd a_k}$ from a given set of amplitudes.\n\\end{dfn}\n\n\n\\begin{ex}\n\\thmtitle{The CCSD lambda equations}\nTruncating the wave operator at doubles, $T\\approx T_1 + T_2$, gives the CCSD approximation.\nThe resulting singles and doubles lambda equations are given by the following\n\\begin{align*}\n  \\la_i^a\n=&\\\n  (\\mc{E}_a^i)^{-1}\n  \\br{\\F}\n    V_{\\text{c}}\\,\n    (\n      1\n    +\n      T_1\n    )\n  +\n    \\La_1\n    V_{\\text{c}}\\,\n    (\n      1\n    +\n      T_1\n    +\n      T_2\n    +\n      \\tfr{1}{2}\n      T_1^2\n    )\n  +\n    \\La_2\n    V_{\\text{c}}\\,\n    (\n      1\n    +\n      T_1\n    +\n      T_2\n    +\n      \\tfr{1}{2}\n      T_1^2\n    +\n      T_1\n      T_2\n    )\n  \\kt{\\F_i^a}_{\\text{C}}\n\\\\\n  \\la_{ij}^{ab}\n=&\\\n  (\\mc{E}_{ab}^{ij})^{-1}\n  \\br{\\F}\n    V_{\\text{c}}\\,\n  +\n    \\La_1\n    V_{\\text{c}}\\,\n    (\n      1\n    +\n      T_1\n    )\n  +\n    \\La_2\n    V_{\\text{c}}\\,\n    (\n      1\n    +\n      T_1\n    +\n      T_2\n    +\n      \\tfr{1}{2}\n      T_1^2\n    )\n  \\kt{\\F_{ij}^{ab}}_{\\text{C}}\n\\end{align*}\nwhere we have omitted any contributions to $\\text{exp}(T_1 + T_2)$ that vanish.\n\\end{ex}\n\n\\begin{ex}\nAssuming Brillouin's theorem holds, the CCD lambda equations are as follows.\n\\begin{align*}\n  \\la_{ij}^{ab}\n  \\mc{E}_{ab}^{ij}\n=&\\\n  \\ip{\\F|\n    V_{\\text{c}}\n  +\n    \\La_2\n    V_{\\text{c}}\n  +\n    \\La_2 V_{\\text{c}}T_2\n  |\\F_{ij}^{ab}}_{\\text{C}}\n\\\\=&\\\n\\diagram{\n  \\interaction{2}{g}{(0,0.5)}{ddot}{sawtooth};\n  \\draw[->-] (g1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-] (g1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-] (g2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-] (g2) to ++(+0.25,-1) node[smalldot] {};\n}\n+\n\\diagram{\n  \\interaction{2}{t}{(0,0.5)}{ddot}{overhang};\n  \\draw[->-=0.65] (t1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.25,-<-=0.75]\n      (t1)\n    to\n      node[ddot,midway] (g1) {}\n    ++(+0.25,-1)\n      node[smalldot] {};\n  \\draw[->-=0.65] (t2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.25,-<-=0.75]\n      (t2)\n    to\n      node[ddot,midway] (g2) {}\n    ++(+0.25,-1)\n      node[smalldot] {};\n   \\draw[sawtooth] (g1) to (g2);\n}\n+\n\\diagram{\n  \\interaction{2}{t}{(0,0.5)}{ddot}{overhang};\n  \\draw[-<-=0.65] (t1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.25,->-=0.75]\n      (t1)\n    to\n      node[ddot,midway] (g1) {}\n    ++(+0.25,-1)\n      node[smalldot] {};\n  \\draw[-<-=0.65] (t2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.25,->-=0.75]\n      (t2)\n    to\n      node[ddot,midway] (g2) {}\n    ++(+0.25,-1)\n      node[smalldot] {};\n   \\draw[sawtooth] (g1) to (g2);\n}\n+\n\\diagram{\n  \\interaction{2}{t}{(0,0.5)}{ddot}{overhang};\n  \\interaction{2}{g}{(1,0.)}{ddot}{sawtooth};\n  \\draw[-<-] (t1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-] (t1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-,bend left=40 ] (g1) to (t2);\n  \\draw[-<-,bend right=40] (g1) to (t2);\n  \\draw[-<-] (g2) to ++(-0.25,-0.5) node[smalldot] {};\n  \\draw[->-] (g2) to ++(+0.25,-0.5) node[smalldot] {};\n}\n+\n\\diagram{\n  \\interaction{2}{l}{(0,0.5)}{ddot}{overhang};\n  \\interaction{2}{g}{(2,0.5)}{ddot}{sawtooth};\n  \\draw[overhang] (1.5,0) node[ddot] (t1) {} to ++(1.5,0) node[ddot] (t2) {};\n  \\draw[-<-=0.65] (l1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (l1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.65] (l2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-] (t1) to (l2);\n  \\draw[->-] (t1) to (g1);\n  \\draw[->-=0.65] (g1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[-<-,bend left=40 ] (t2) to (g2);\n  \\draw[->-,bend right=40] (t2) to (g2);\n}\n+\n\\diagram{\n  \\interaction{2}{l}{(0,0.5)}{ddot}{overhang};\n  \\interaction{2}{g}{(2,0.5)}{ddot}{sawtooth};\n  \\draw[overhang] (1.5,0) node[ddot] (t1) {} to ++(1.5,0) node[ddot] (t2) {};\n  \\draw[->-=0.65] (l1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.65] (l1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (l2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-] (t1) to (l2);\n  \\draw[-<-] (t1) to (g1);\n  \\draw[-<-=0.65] (g1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-,bend left=40 ] (t2) to (g2);\n  \\draw[-<-,bend right=40] (t2) to (g2);\n}\n\\\\&\\\n+\n\\diagram{\n  \\interaction{2}{l}{(0,0.5)}{ddot}{overhang};\n  \\interaction{2}{g}{(2.2,0.5)}{ddot}{sawtooth};\n  \\interaction{2}{t}{(1.1,0.0)}{ddot}{overhang};\n  \\draw[->-=0.7] (l1) to ++(-0.4,-1) node[smalldot] {};\n  \\draw[-<-=0.3] (l1) to (t1);\n  \\draw[->-=0.7] (l2) to ++(-0.4,-1) node[smalldot] {};\n  \\draw[-<-=0.3] (l2) to (t2);\n  \\draw[->-=0.3] (g1) to (t1);\n  \\draw[-<-=0.7] (g1) to ++(+0.4,-1) node[smalldot] {};\n  \\draw[->-=0.3] (g2) to (t2);\n  \\draw[-<-=0.7] (g2) to ++(+0.4,-1) node[smalldot] {};\n}\n+\n\\diagram{\n  \\interaction{2}{l}{(0,0.5)}{ddot}{overhang};\n  \\interaction{2}{g}{(2,0.5)}{ddot}{sawtooth};\n  \\interaction{2}{t}{(1,0.0)}{ddot}{overhang};\n  \\draw[-<-=0.65] (l1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (l1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-,bend left=40 ] (t1) to (l2);\n  \\draw[-<-,bend right=40] (t1) to (l2);\n  \\draw[->-,bend left=40 ] (t2) to (g1);\n  \\draw[-<-,bend right=40] (t2) to (g1);\n  \\draw[-<-=0.65] (g2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (g2) to ++(+0.25,-1) node[smalldot] {};\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0.5)}{ddot}{sawtooth};\n  \\interaction{2}{l}{(2.2,0.5)}{ddot}{overhang};\n  \\interaction{2}{t}{(1.1,0.0)}{ddot}{overhang};\n  \\draw[->-=0.7] (g1) to ++(-0.4,-1) node[smalldot] {};\n  \\draw[-<-=0.3] (g1) to (t1);\n  \\draw[->-=0.7] (g2) to ++(-0.4,-1) node[smalldot] {};\n  \\draw[-<-=0.3] (g2) to (t2);\n  \\draw[->-=0.3] (l1) to (t1);\n  \\draw[-<-=0.7] (l1) to ++(+0.4,-1) node[smalldot] {};\n  \\draw[->-=0.3] (l2) to (t2);\n  \\draw[-<-=0.7] (l2) to ++(+0.4,-1) node[smalldot] {};\n}\n\\\\&\\\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0.5)}{ddot}{sawtooth};\n  \\interaction{2}{l}{(2,0.5)}{ddot}{overhang};\n  \\draw[overhang] (1.5,0) node[ddot] (t1) {} to ++(1.5,0) node[ddot] (t2) {};\n  \\draw[-<-=0.65] (g1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (g1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.65] (g2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-] (t1) to (g2);\n  \\draw[->-] (t1) to (l1);\n  \\draw[->-=0.65] (l1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[-<-,bend left=40 ] (t2) to (l2);\n  \\draw[->-,bend right=40] (t2) to (l2);\n}\n+\n\\diagram{\n  \\interaction{2}{g}{(0,0.5)}{ddot}{sawtooth};\n  \\interaction{2}{l}{(2,0.5)}{ddot}{overhang};\n  \\draw[overhang] (1.5,0) node[ddot] (t1) {} to ++(1.5,0) node[ddot] (t2) {};\n  \\draw[->-=0.65] (g1) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[-<-=0.65] (g1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-=0.65] (g2) to ++(-0.25,-1) node[smalldot] {};\n  \\draw[->-] (t1) to (g2);\n  \\draw[-<-] (t1) to (l1);\n  \\draw[-<-=0.65] (l1) to ++(+0.25,-1) node[smalldot] {};\n  \\draw[->-,bend left=40 ] (t2) to (l2);\n  \\draw[-<-,bend right=40] (t2) to (l2);\n}\n\\\\=&\\\n  \\ol{g}_{ij}^{ab}\n+\n  \\tfr{1}{2}\n  \\la_{ij}^{cd}\n  \\ol{g}_{cd}^{ab}\n+\n  \\tfr{1}{2}\n  \\la_{kl}^{ab}\n  \\ol{g}_{ij}^{kl}\n+\n  P_{(i/j)}^{(a/b)}\n  \\la_{ik}^{ac}\n  \\ol{g}_{cj}^{kb}\n-\n  \\tfr{1}{2}\n  P_{(i/j)}\n  \\la_{ik}^{ab}\n  t_{cd}^{kl}\n  \\ol{g}_{jl}^{cd}\n-\n  \\tfr{1}{2}\n  P^{(a/b)}\n  \\la_{ij}^{ac}\n  t_{cd}^{kl}\n  \\ol{g}_{kl}^{bd}\n\\\\&\\\n+\n  \\tfr{1}{2^2}\n  \\la_{ij}^{cd}\n  t_{cd}^{kl}\n  \\ol{g}_{kl}^{ab}\n+\n  P_{(i/j)}^{(a/b)}\n  \\la_{ik}^{ac}\n  t_{cd}^{kl}\n  \\ol{g}_{lj}^{db}\n+\n  \\tfr{1}{2^2}\n  \\ol{g}_{ij}^{cd}\n  t_{cd}^{kl}\n  \\la_{kl}^{ab}\n-\n  \\tfr{1}{2}\n  P_{(i/j)}\n  \\ol{g}_{ik}^{ab}\n  t_{cd}^{kl}\n  \\la_{jl}^{cd}\n-\n  \\tfr{1}{2}\n  P^{(a/b)}\n  \\ol{g}_{ij}^{ac}\n  t_{cd}^{kl}\n  \\la_{kl}^{bd}\n\\end{align*}\n\\end{ex}\n\n\\begin{samepage}\n\\begin{rmk}\n\\thmtitle{The Hellmann-Feynman theorem}\nIf the Hamiltonian depends on a parameter $\\xi$, such as a nuclear coordinate or an electric field strength, we can express the Schr\\\"odinger equation as a function of that parameter\n\\begin{align}\n\\label{eq:xi-dependent-schrodinger-equation}\n  H(\\xi)\n  \\Y(\\xi)\n=\n  E(\\xi)\n  \\Y(\\xi)\n&&\n  \\ip{\\Y(\\xi)|\\Y(\\xi)}\n\\overset{!}{=}\n  1\n\\end{align}\nThen the total derivative of the energy $E(\\xi)=\\ip{\\Y(\\xi)|H(\\xi)|\\Y(\\xi)}$ with respect to $\\xi$ is given by the following.\n\\begin{align}\n  \\fd{E(\\xi)}{\\xi}\n=\n  \\ip{\\Y(\\xi)|\n  \\pd{H(\\xi)}{\\xi}\n  |\\Y(\\xi)}\n+\n\\cancel{\n  \\ip{\\pd{\\Y(\\xi)}{\\xi}|\n  H(\\xi)\n  |\\Y(\\xi)}\n+\n  \\ip{\\Y(\\xi)|\n  H(\\xi)\n  |\\pd{\\Y(\\xi)}{\\xi}}\n}\n\\end{align}\nThe second and third terms cancel by the \\textit{Hellmann-Feynman theorem}, which one can prove by substituting the Schr\\\"odinger equation into both terms and employing the derivative of the normalization condition with respect to $\\xi$.\nIn words, it says that the first derivative of the energy does not depend on the  ``response'' of the wavefunction.\nMore generally, for approximate methods, the wavefunction may be parametrized by a set of coefficients $\\bo{c}$ which are \\textit{stationary} in the sense that their energy gradient equals zero.\nDenoting the remaining non-stationary coordinates by $\\bo{p}$, we have\n\\begin{align}\n  \\fd{E(\\xi)}{\\xi}\n=\n  \\pd{E(\\xi)}{\\xi}\n+\n  \\cancel{\n  \\pd{E}{\\bo{c}}\n  }\n  \\cdot\n  \\fd{\\bo{c}}{\\xi}\n+\n  \\pd{E}{\\bo{p}}\n  \\cdot\n  \\fd{\\bo{p}}{\\xi}\n&&\n  \\pd{E}{\\xi}\n=\n  \\ip{\\Y(\\bo{c},\\bo{p})|\n  \\pd{H(\\xi)}{\\xi}\n  |\\Y(\\bo{c},\\bo{p})}\n\\end{align}\nwhich applies to configuration interaction and other variational methods.\nFor most methods $\\bo{p}$ will include parameters which determine the molecular orbital coefficients, since the shape of the Hartree-Fock orbitals depends on $\\xi$.\nWhen $\\xi$ is a nuclear coordinate, the atomic-orbital basis functions themselves change\\footnote{The parameters defining the basis functions are constant, but their centers of origin move with the nuclei.}\nand we must include parameters to account for this as well.\nThe Hellmann-Feynman theorem does not apply to TCC energy, which is not stationary in any of its parameters.\nHowever, it does apply to the coupled-cluster Lagrangian as follows.\n\\begin{align}\n  \\fd{\\mc{L}(\\xi)}{\\xi}\n=\n  \\pd{\\mc{L}(\\xi)}{\\xi}\n+\n  \\cancel{\n  \\pd{\\mc{L}}{\\bo{t}}\n  }\n  \\cdot\n  \\fd{\\bo{t}}{\\xi}\n+\n  \\cancel{\n  \\pd{\\mc{L}}{\\bm{\\la}}\n  }\n  \\cdot\n  \\fd{\\bm{\\la}}{\\xi}\n+\n  \\pd{\\mc{L}}{\\bo{p}}\n  \\cdot\n  \\fd{\\bo{p}}{\\xi}\n&&\n  \\pd{\\mc{L}(\\xi)}{\\xi}\n=\n  \\ip{\\F(\\bo{p})|\n    (\n      1\n    +\n      \\La\n    )\\,\n    \\pd{H(\\xi)}{\\xi}\\,\n    \\text{exp}(T)\n  |\\F(\\bo{p})}_{\\text{C}}\n\\end{align}\nThis is known as the \\textit{generalized Hellmann-Feynman theorem} for coupled-cluster theory.\nNote that one must solve both the amplitude equations and the lambda equations in order to evaluate the equation on the right.\n\\end{rmk}\n\\end{samepage}\n\n", "meta": {"hexsha": "fe800515a9737eb1e1e7b604733f7910607fda8a", "size": 33631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/sections/coupled-cluster.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/coupled-cluster.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/coupled-cluster.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.0982142857, "max_line_length": 271, "alphanum_fraction": 0.5469358627, "num_tokens": 14846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6020324481293413}}
{"text": "%auto-ignore\n\\providecommand{\\MainFolder}{..}\n\\documentclass[\\MainFolder/Text.tex]{subfiles}\n\n\\begin{document}\n\\section{Homology of twisted IBL-infinity structure for complex projective space}\n%Computation of \\texorpdfstring{$\\OPQ_{210}$ and $\\OPQ_{120}$}{q210 and q120}\n\\label{Section:CPn1}\nLet $\\Kaehler\\in \\DR^2(\\CP^n)$ be the Fubini--Study K\\\"ahler form on $\\CP^n$ (see \\cite[Examples 3.1.9]{Huybrechts2004}). The powers of $\\Kaehler$ are harmonic,\\footnote{This follows by induction on the power of $\\Kaehler$ using the fact that, on a general K\\\"ahler manifold $M$, the Lefschetz operator $\\Lef: \\DR(M)\\rightarrow \\DR(M)$ defined by $\\Lef(\\eta)\\coloneqq \\eta \\wedge \\Kaehler$ for all $\\eta\\in \\DR(M)$ commutes with the Hodge--de Rham Laplacian~$\\Delta$ (see \\cite[Chapter 3]{Huybrechts2004}). } and we get easily\n\\[ \\Harm(\\CP^n) = \\langle 1,\\Kaehler, \\dotsc, \\Kaehler^n \\rangle. \\]\nWe denote the Riemannian volume of $\\CP^n$ by\n\\[ V\\coloneqq \\int_{\\CP^n} \\frac{1}{n!}\\Kaehler^n. \\]\nConsider the basis $e_0$, $\\dotsc$, $e_n$ of $\\Harm(\\CP^n)[1]$ defined for all $i=0$, $\\dotsc$, $n$ by\n\\[ e_i\\coloneqq \\frac{\\NK^i}{(n! V)^{\\frac{i}{n}}}, \\quad \\text{where}\\quad\\NK^i\\coloneqq \\SuspU \\Kaehler^i. \\]\nThe matrix of the pairing $\\Pair$ from~\\eqref{Eq:DeRhamDGA} with respect to the basis $e_0$,~$\\dotsc$,~$e_{n}$ reads:\n\\[ (\\Pair^{ij}) = \\begin{pmatrix}\n0 & \\dotsb & 1 \\\\\n\\vdots & {\\displaystyle\\, .^{{\\displaystyle \\, .^{\\displaystyle\\,.}}}} & \\vdots \\\\\n1 & \\dotsb & 0\n\\end{pmatrix}. \\]\nThe basis $e^0$, $\\dotsc$, $e^n$ dual to $e_0$, $\\dotsc$, $e_n$ with respect to $\\Pair$ thus satisfies\n\\[ e^i = e_{n-i}\\quad\\text{for all }i=0,\\dotsc,n. \\]\nTherefore, the following holds for the matrix $(T^{ij})$ from~\\eqref{Eq:PropagatorT}:\n\\begin{equation*}\n(T^{ij}) = - (\\Pair^{ij}).\n\\end{equation*}\nFor all $1\\le i, j, k \\le n$, we have\n\\[ \\mu_2(e_i, e_j) = e_{i+j}\\quad \\text{and}\\quad\n\\MC_{10}(\\Susp e_{i}e_j e_k) = \\delta_{i+j+k,n}. \\]\nFor $\\psi$, $\\psi_1$, $\\psi_2 \\in \\CDBCyc \\Harm$ and generating words $\\omega$, $\\omega_1$, $\\omega_2 \\in \\BCyc\\Harm$, we chave\n\\begin{equation*}\n\\begin{aligned}\n\\OPQ_{210}(\\Susp^2 \\psi_1 \\otimes \\psi_2)(\\Susp \\omega) &= -\\sum_{i=0}^n \\sum \\varepsilon(\\omega\\mapsto \\omega^1\\omega^2)(-1)^{\\Abs{\\omega^1}} \\psi_1(e_i \\omega^1)\\psi_2(e_{n-i}\\omega^2), \\\\\n\\OPQ_{120}(\\Susp \\psi)(\\Susp^2 \\omega_1 \\otimes \\omega_2) & = - \\sum_{i=0}^n \\sum \\varepsilon(\\omega_1 \\mapsto \\omega_1^1)\\varepsilon(\\omega_2\\mapsto \\omega_2^1) (-1)^{\\Abs{\\omega_1}} \\psi(e_i \\omega_1^1 e_{n-i} \\omega_2^1).\n\\end{aligned}\n\\end{equation*}\n\nThe cyclic homology of $\\Harm(\\CP^n)$ is that of the truncated polynomial algebra\n\\[ A \\coloneqq\\R[x]/(x^{n+1})\\quad\\text{with }\\Deg(x)=2. \\]\nThe following lemma computes its cyclic homology.\n\\begin{Lemma}[Cyclic homology of truncated graded polynomial algebra]\nConsider $A\\coloneqq\\R[x]/(x^{n+1})$ with $\\Deg(x)=d\\in \\Z$. For all $i=1$, $\\dotsc$, $n$ and $k\\in \\N_0$, there are cycles $\\tilde{t}_{2k+1,i}\\in  \\tilde{D}_q(A)$ of weights $w(\\tilde{t}_{2k+1,i}) = 2k+1$ and degrees $\\Abs{\\tilde{t}_{2k+1,i}} = d(i+(n+1)k)$, where $q = w(\\tilde{t}_{2k+1,i})-\\Abs{\\tilde{t}_{2k+1,i}}-1$, which form a basis of $\\ClasCycH(A)$ (the non-degree shifted cyclic homology defined on page~\\pageref{Eq:NDSComplex}).\n\\end{Lemma}\n\\begin{proof}\nA computation of the cyclic homology of $A$ for $\\Abs{x}=0$ is the goal of \\cite[Exercise 4.1.8.]{LodayCyclic} or \\cite[Exercise 9.1.1]{Weibel1994}.\nThe hint is to compute the Hochschild homology $\\H\\H_n(A) = \\Tor_n^{A_e}(A,A)$, where $A_e$ is the enveloping algebra of $A$, using a non-canonical (i.e., not the bar complex) projective resolution of the $A_e$-module $A$ given by\n\\begin{equation}\\label{Eq:ProjRes}\n\\begin{tikzcd}\n\\dotsb \\arrow[r] & A_e \\arrow{r}{\\cdot v} & A_e \\arrow{r}{\\cdot u} & A_e \\arrow{r}{\\mu} & A \\arrow{r} & 0,\n\\end{tikzcd}\n\\end{equation}\nwhere $u = x \\otimes 1 - 1 \\otimes x$ and $v = \\sum_{i=0}^{n} x^i \\otimes x^{n-i}\\in A_e$.\nThe resolution continues to the left with $\\cdot u$ und $\\cdot v$ periodically.\nClearly, $\\mu$ composed with $\\cdot u$ vanishes and $u\\cdot v = v\\cdot u = x^{n+1}\\otimes 1 - 1 \\otimes x^{n+1} = 0$; one can check that \\eqref{Eq:ProjRes} is indeed a resolution.\nIf $\\Deg(x)=d$, then $\\Deg(u) = d$ and $\\Deg(v) = n d$.\n\nWe lift the resolution \\eqref{Eq:ProjRes} to the graded category (i.e., we require that the maps are homogenous) by taking the degree shifts\n\\[\n\\begin{tikzcd}\n\\dotsb \\arrow{r} &\nA_e[-(n+1)di] \\arrow{r}{d_{2i}} \\ar[draw=none]{d}[name=X, anchor=center]{}& \nA_e[-(n+1)di + nd] \\arrow{r}{d_{2i-1}} &\nA_e[-d(n+1)(i-1)]  \\ar[rounded corners,\n            to path={ -- ([xshift=2ex]\\tikztostart.east)\n                      |- (X.center) \\tikztonodes\n                      -| ([xshift=-2ex]\\tikztotarget.west)\n                      -- (\\tikztotarget)}]{dlll}[at end]{}\\\\\n\\dotsb\\arrow{r} &\nA_e[-(n+1)d] \\arrow{r}{d_{2}} &\nA_e[-d] \\arrow{r}{d_1}\\ar[draw=none]{d}[name=Y, anchor=center]{} &\nA_e  \\ar[rounded corners,\n            to path={ -- ([xshift=2ex]\\tikztostart.east)\n                      |- (Y.center) \\tikztonodes\n                      -| ([xshift=-2ex]\\tikztotarget.west)\n                      -- (\\tikztotarget)}]{dl}{\\mu} \\\\ \n&  & A \\arrow{r} & 0,\n\\end{tikzcd}\n\\]\nwhere we denoted by $d_i$ the maps from \\eqref{Eq:ProjRes}.\nTensoring with $A$, we get the graded vector spaces $A \\otimes_{A_e} A_e[\\cdot] \\simeq A[\\cdot]$, and the maps $d_j$ become multiplications with $u$, $v \\in A_e$ in $A$ as a right $A_e$-module.\nFor all polynomials $p\\in A$, we have\n$$ \\begin{aligned}\n    d_{2i-1}(p) = p\\cdot (x\\otimes 1 - 1 \\otimes x) &= px - (-1)^{\\Abs{x} \\Abs{p}}xp = 0, \\\\\n    d_{2i}(p) = p\\cdot (\\sum_{i=0}^n x^i \\otimes x^{n-i}) & = (-1)^{n \\Abs{x}\\Abs{p}}(n+1) x^n p.\n\\end{aligned}$$\nThe homology of this chain complex consists of graded vector spaces $\\H\\H_{(l)}$ for $l\\ge 0$ which correspond to the homology of the bar complex graded by weights, i.e., $\\H\\H_{(l)}$ would be represented by cycles in $A^{\\otimes l+1}$ if the bar resolution was taken. We compute\n\\begin{equation}\\label{Eq:HochCPn}\n\\H\\H_{(l)} = \\begin{cases} \n (x A)[-(n+1)di] & \\text{for }l=2i, \\\\\n \\R[x]/(x^n)[-(n+1)di + nd] & \\text{for }l = 2i - 1, \\\\\n A & \\text{for }l = 0.\n\\end{cases}\n\\end{equation}\nNow, because the differential $\\tilde{\\delta}$ is zero and $\\tilde{\\Hd}$ is degree preserving, it holds (c.f., \\eqref{Eq:TotComplNDS})\n\\[\\ClasHH(A) = \\bigoplus_{l\\in \\N_0} \\H\\H_{(l)}.\\] \nClearly, the same will hold for $\\ClasCycH(A)$, and hence we can ignore the gradation by degree and just use the gradation by weights in the bar complex, i.e., the non-graded theory.\n\nIn order to compute $\\CycH_{(l)}(A)$, we consider the Connes' exact sequence in homology, or $\\mathrm{ISB}$-sequence, see \\cite[Theorem~2.2.1]{LodayCyclic}.\nIt arises from the exact sequence of bicomplexes $0 \\rightarrow \\LodCycBi^{\\{2\\}} \\hookrightarrow \\LodCycBi \\twoheadrightarrow \\LodCycBi[2,0] \\rightarrow 0$, where~$\\LodCycBi$ is the Loday's cyclic bicomplex from~\\cite[Paragraph~2.1.2]{LodayCyclic} (bar complexes in columns), $\\LodCycBi^{\\{2\\}}$ is the sub-bicomplex consisting of the first two columns of $\\LodCycBi$ and $\\LodCycBi[2,0]$ is the part of $\\LodCycBi$ starting with the third column. \nBecause $A$ is augmented and unital, \\cite[Theorem~4.1.13]{LodayCyclic} guarantees a splitting of the ISB-sequence into\n\\begin{equation}\\label{Eq:ConnexIBS}\n0 \\longrightarrow \\widebar{\\H}^\\lambda_{(l-1)} \\longrightarrow \\widebar{\\H\\H}_{(l)} \\longrightarrow \\widebar{\\H}^\\lambda_{(l)} \\longrightarrow 0\\quad\\text{for }l\\ge 1,\n\\end{equation}\nwhere the bar $\\bar{\\cdot}$ denotes the reduced homology. It holds $\\CycH_{(0)}= \\H\\H_{(0)}= A$, and hence $\\widebar{\\H}^\\lambda_{(0)} = \\langle x, \\dotsc, x^n \\rangle$.\nUsing \\eqref{Eq:HochCPn}, the first map for $l=1$ in \\eqref{Eq:ConnexIBS} reads $\\langle x,\\dotsc, x^n \\rangle \\hookrightarrow \\langle 1, x, \\dotsc, x^{n-1}\\rangle[-d]$, and hence it is an isomorphism.\nIt follows that $\\widebar{\\H}^\\lambda_{(1)} = 0$.\nFor $k\\ge 1$, we obtain inductively $\\widebar{\\H}^\\lambda_{(2k)} \\simeq \\widebar{\\H\\H}_{(2k)} = \\langle x,\\dotsc,x^n\\rangle[-(n+1)dk] \\hookrightarrow \\widebar{\\H\\H}_{(2k+1)} = \\langle 1, x, \\dotsc, x^{n-1} \\rangle[-(n+1)dk - d]$. This again has to be an isomorphism, and hence $\\widebar{\\H}^\\lambda_{(2k+1)} = 0$.\n\\end{proof}\n%The case of $\\Abs{x} = d$ can be solved by taking suitable degree shifts in the proposed projective resolution which is used to compute $\\H\\H(A)$. Unfortunately, using a non-canonical projective resolution, we lose the concrete form of the cyclic cycles and obtain just the following result:\n%For all $i=1$, $\\dotsc$, $n$ and $k\\in \\N_0$, there are cycles $\\tilde{t}_{2k+1,i}\\in  \\tilde{D}_q(A)$ of weights $2k+1$ and degrees $d(i+(n+1)k)$ which form a basis of $\\ClasCycH(A)$.\nWe apply the degree shift $U: \\tilde{D}(A) \\rightarrow D(A)$ from Proposition~\\ref{Prop:DGA} to get the generators\n\\[ t_{w,i} \\coloneqq U(\\tilde{t}_{w,i}) \\in D^\\lambda( \\Harm(\\CP^n)) \\]\nof weights $w$ and degrees $2i+ (w-1)n -1$, so that\n\\[ \\H^\\lambda(\\Harm(\\CP^n)) = \\langle t_{w,i}, \\NOne^{w} \\mid w\\in \\N \\text{ odd}, i=1,\\dotsc, n\\rangle. \\]\nBy the universal coefficient theorem, we have $\\H_\\lambda^* = (\\H^\\lambda)^{\\GD}$ with respect to the grading by the degree. Given $d\\in \\Z$, the equation $d= 2i + (w-1)n - 1$ has only finitely many solution $(w,i) \\in \\N \\times \\{1,\\dotsc,n\\}$, and hence we get\n\\begin{equation}\\label{Eq:CPnHom}\n\\HIBL^\\MC(\\CycC(\\Harm(\\CP^n))) = \\langle \\Susp t_{w,i}^*, \\Susp\\NOne^{w*} \\mid w\\in \\N \\text{ odd}, i=1,\\dotsc, n \\rangle,\n\\end{equation}\nwhere $t_{w,i}^*$ and $\\NOne^{w*} \\in \\DBCyc \\Harm$ are the duals to $t_{w,i}$ and $\\NOne^{w}$, respectively (see Remark~\\ref{Rem:UCT}). Notice that both $\\Abs{\\Susp t_{w,i}^*}$ and $\\Abs{\\Susp \\NOne^{w*}}$ are even since $\\Abs{\\Susp} = 2n-3$.\n\nBecause $\\CP^n$ is geometrically formal, Proposition~\\ref{Prop:GeomForm} implies that $\\PMC_{10} = \\MC_{10}$. Because $\\HIBL^\\MC(\\CycC)$ is concentrated in even degrees and because a general $\\IBLInfty$-operation $\\OPQ_{klg}$ is odd, all operations vanish on the homology. Therefore, for the \\emph{twisted $\\IBL$-algebras} we have\n\\begin{equation*}\n\\IBL(\\HIBL^\\PMC(\\CycC)) = \\IBL(\\HIBL^\\MC(\\CycC)) = (\\HIBL^\\MC(\\CycC), \\OPQ_{210} \\equiv 0, \\OPQ_{120}\\equiv 0),\n\\end{equation*}\nwhere $\\HIBL^\\MC(\\CycC)$ is given by \\eqref{Eq:CPnHom}.\n\nAccording to \\cite[Section 3.1.2]{Basu2011}, the minimal model for the Borel construction $\\LoopBorel \\CP^n$ is the cdga $\\Lambda^{\\mathrlap{\\Sph{1}}\\hphantom{S}}(n+1,1)$, which is freely generated (over $\\R$) by the homogenous vectors $x_1$, $x_2$, $y_1$, $y_2$, $u$ of degrees\n\\[ \\Abs{x_1} = 2,\\quad \\Abs{x_2} = 2n+1,\\quad \\Abs{y_1} = 1,\\quad \\Abs{y_2} = 2n, \\quad \\Abs{u} = 2, \\]\nwhose differential $\\Dd$ satisfies\n\\[ \\Dd y_1 = 0,\\quad \\Dd x_1 = y_1 u,\\quad \\Dd y_2 = -(n+1) x_1^n y_1,\\quad \\Dd x_2 = x_1^{n+1} + y_2 u. \\]\nBy \\cite[Theorem 3.6]{Basu2011}, the string cohomology $\\StringCoH^*(\\Loop \\CP^n; \\R)\\simeq \\H(\\Lambda^{\\mathrlap{\\Sph{1}}\\hphantom{S}}(n+1,1),\\Dd)$ satisfies for all $m\\in \\N_0$ the following:\n\\begin{align*}\n\\StringCoH^m(\\Loop \\CP^n; \\R) = \\begin{cases} \n\\langle u^j \\rangle & \\text{if }m=2j, \\\\\n\\langle y_1 y_2^p x_1^q \\mid 0\\le q \\le n-1, p\\ge 0; q + n p = j\\rangle & \\text{if }m=2j+1.\n\\end{cases}\n\\end{align*}\nThe right-hand side can be identified with $\\StringH(\\Loop \\CP^n; \\R)$ by the universal coefficient theorem. According to \\cite[Proposition 3.7]{Basu2011}, we have $\\StringOp_2 = 0$ and $\\StringCoOp_2 = 0$. We conclude that the map\n\\[\\begin{aligned}\n \\HIBL^\\PMC(\\RedCycC(\\Harm(\\CP^n)))[1] & \\longrightarrow \\RedStringH(\\Loop \\CP^n; \\R)[3-n] \\\\\n\\Susp t^*_{2k+1,l} & \\longmapsto \\Susp y_1 y_2^k x_1^{l-1}\\qquad\\text{for }k\\ge 0\\text{ and }l=1,\\dotsc, n\n\\end{aligned} \\]\ninduces an isomorphism of $\\IBL$-algebras\n\\[ \\IBL(\\HIBL^\\PMC(\\RedCycC(\\Harm(\\CP^n)))) \\simeq \\IBL(\\RedStringH(\\Loop \\CP^n; \\R)[3-n]). \\]\n\\end{document}\n", "meta": {"hexsha": "53dce62f1c8533d75667aed323d9398020f68b39", "size": 11879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Subfiles/Comp_CPnIBL.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/Comp_CPnIBL.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/Comp_CPnIBL.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": 81.3630136986, "max_line_length": 526, "alphanum_fraction": 0.647360889, "num_tokens": 4696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541067, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6020324443281981}}
{"text": "\\subsection{Echo State Networks}\n\n\\begin{figure}[htp]\n  \\centering\n  \\subfloat[Training Flow]{\n    \\includegraphics[clip, width=0.85\\columnwidth]{reservoir_training.png}\n  }\n\n\n  \\subfloat[Predicting Flow]{\n    \\includegraphics[clip, width=0.85\\columnwidth]{reservoir_predicting.png}\n  }\n  \\caption{(a) Shows the behavior of an \\gls{esn} during the training phase. (b) Shows \\gls{esn} behavior during the predicting phase. The output $U(t+\\Delta t)$ is used as the next input value. }\n  \\label{fig:reservoir_graph}\n\\end{figure}\n\nAn \\gls{esn}, sometimes called a ``reservoir\ncomputer,''\\cite{pathak_using_2017, pathak_model-free_2018, vlachas_backpropagation_2020} is a type of recurrent\nneural network \\cite{lukosevicius_reservoir_2009}\n that replaces the many hidden layers of a conventional feed-forward\nneural network with a reservoir that is:\n\\begin{enumerate}\n  \\item sparse,\n  \\item connected by uniformly random weights, centered at zero,\n  \\item and large (i.e. has many neurons).\n\\end{enumerate}\n\nThe reservoir is therefore a randomly instantiated adjacency matrix,\n\\textit{\\textbf{W}}, of size $N \\times N$. An input matrix  $W^{in}$, of size\n$N \\times K$, maps the input vector, $U(t)$ with\n$K$ units, onto the reservoir. The activation states of the reservoir are\ncalculated by \\cite{shi_energy_2016, pathak_model-free_2018, lukosevicius_practical_2012}\n \\begin{align}\n   x(t) &= \\tanh \\left(W^{in}\\cdot U(t) + \\mathbf{W}x(t-1)\\right)\n   \\intertext{where}\n   x(t) &= \\text{the collection of reservoir activations}\\nonumber.\n \\end{align}\n The output, $U(t+\\Delta t)$, is read by an output weight matrix,\n $W^{out}$, thus:\n \\begin{align}\n   U(t+\\Delta t) &= \\left(W^{out}\\right)^T\\cdot x(t).\n \\end{align}\n In the training phase, we\n discard the output and the next training input is passed to\n the network. During the prediction phase, we keep the output and use it as the\n next input. Figure \\ref{fig:reservoir_graph} illustrates this behavior. The\n speed of \\glspl{esn} is owed\n to this structure -- only $W^{out}$ has tunable weights. Everything else is\n fixed. In this work, we adapted the open source Python package \\texttt{pyESN} \\cite{korndorfer_pyesn_2015} to construct and train the network.\n\n \\subsection{Hyper-Parameter Optimization}\n\n \\glspl{esn} are fast because a large reservoir, that does not require\n training, replaces the hidden layers in a conventional feed-forward neural\n network.\n The trade-off is that \\glspl{esn} are sensitive to various hyper-parameters\n that must be optimized \\cite{lukosevicius_practical_2012}. Table \\ref{tab:parameters} summarizes these hyper-parameters. The spectral radius ($\\rho$) should satisfy the ``echo state property'' which means that\n previous reservoir activations have a decaying influence on future states. This\n is usually guaranteed for $\\rho < 1$, but is not a requirement\n \\cite{lukosevicius_practical_2012}.\n \\begin{table*}[ht]\n   \\centering\n   \\caption{Description of Model Hyper-Parameters}\n   \\resizebox{\\textwidth}{!}{\n   \\begin{tabular}{l l l}\n     \\hline\n     Hyper-parameter & Purpose & Tested Values\\\\\n     \\hline\n     \\texttt{noise} & Neuron regularization & [0.0001, 0.0003, 0.0007, 0.001, \\\\\n     &&0.003, 0.005, 0.007, 0.01]\\\\\n     $\\rho$ & Spectral radius & [0.5, 0.7, 0.9, 1, 1.1, \\\\\n     &&1.2, 1.3, 1.5]\\\\\n     $N$ & Size of reservoir, \\textbf{W} & [600, 800, 1000, 1500, 2000, \\\\\n     &&2500, 3000, 4000]\\\\\n     \\texttt{sparsity} & The density of connections in \\textbf{W}& [0.005, 0.01, 0.03, 0.05, \\\\\n     &&0.1, 0.12, 0.15, 0.2]\\\\\n     Training Length & Training set size & $L \\in$ [5000, 25000], step size = 300\\\\\n     \\hline\n   \\end{tabular}\n   } % end resizebox\n   \\label{tab:parameters}\n \\end{table*}\n% \\FloatBarrier\n We optimize the hyper-parameters by performing a grid search over the test\n values specified in Table \\ref{tab:parameters}. We took the following\n optimization steps for each prediction task:\n \\begin{enumerate}\n   \\item Select a hyper-parameter or pair of parameters.\n   \\item Generate \\gls{esn} prediction with the specified parameters.\n   \\item Calculate and record the root mean squared error (RMSE).\n   \\item Continue until last entry in the parameter set is reached.\n   \\item Set the network parameters to the hyper-parameter value that minimizes the\n   RMSE.\n \\end{enumerate}\n Figure \\ref{fig:rhoxnoise-demand04} shows an example\n heatmap that optimized the spectral radius and noise hyper-parameters for the 4-hour\n ahead demand forecast and illustrates the sensitivity of \\glspl{esn} to\n hyperparameter values.\n\n \\begin{figure}[h]\n   \\includegraphics[width=\\columnwidth]{./images/04_demand_rho_noise_loss.png}\n   % \\input{./images/04_wind_elevation_rho_noise_loss-img0.png}\n   \\caption{An example heatmap of the RMSE for 4-hour ahead demand prediction with different combinations of spectral radius, $\\rho$, and noise.}\n   \\label{fig:rhoxnoise-demand04}\n \\end{figure}\n\n \\subsection{Prediction Tasks}\nIn order to verify that the performance of our \\gls{esn} implementation was\nconsistent with the literature \\cite{pathak_using_2017} we first\nperformed a benchmarking task by making a prediction for the Lorenz\n1963 model. The Lorenz 1963 model is described by a system of coupled differential equations:\n\\begin{align}\n  \\frac{\\text{d}x}{\\text{d}t} &= \\sigma (y - x),\\\\\n  \\frac{\\text{d}y}{\\text{d}t} &= x(\\rho - z)- y,\\\\\n  \\frac{\\text{d}z}{\\text{d}t} &= xy - \\beta z,\n  \\intertext{where}\n  \\sigma &= 10,\\nonumber\\\\\n  \\beta &= 8/3,\\nonumber\\\\\n  \\rho &=28, \\nonumber\n\\end{align}\nsince the system demonstrates chaotic behavior for these parameter values\n\\cite{lorenz_deterministic_1963}.\n\nNext, we optimized predictions for\nunivariate time-series\nrepresenting total demand, solar energy, and wind energy 4-hours ahead and\n48-hours ahead. Finally, we repeated those same six tasks with an additional\npredictor. One value from each column in Table \\ref{tab:tasks} was selected for\neach task for a total of 42 predictions.\n\n\\begin{table*}[ht]\n  \\centering\n  \\caption{Summary of prediction tasks.}\n  \\label{tab:tasks}\n  \\resizebox{\\columnwidth}{!}{\n  \\begin{tabular}{c c c}\n    \\hline\n    Target & Future & Additional Predictor\\\\\n    \\hline\n    && None \\\\\n    Total Demand && Solar Elevation\\\\\n    &4-hours ahead& Humidity\\\\\n    Solar Energy && Pressure\\\\\n    &48-hours ahead& Wet Bulb Temp.\\\\\n    Wind Energy && Dry Bulb Temp.\\\\\n    && Wind Speed\\\\\n    \\hline\n  \\end{tabular}%\n  } % end resizebox\n\\end{table*}\n% \\FloatBarrier\n", "meta": {"hexsha": "5ee72141c38d2cc0053d6c65ef0c0b9593a9a0fb", "size": 6442, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/forecasting-paper/esn.tex", "max_stars_repo_name": "arfc/cairo", "max_stars_repo_head_hexsha": "f2e38eadd6c786b2853defd97bc49c585bb6e513", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-11T18:27:30.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-11T18:27:30.000Z", "max_issues_repo_path": "publications/forecasting-paper/esn.tex", "max_issues_repo_name": "arfc/cairo", "max_issues_repo_head_hexsha": "f2e38eadd6c786b2853defd97bc49c585bb6e513", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 68, "max_issues_repo_issues_event_min_datetime": "2019-09-19T19:40:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T20:03:06.000Z", "max_forks_repo_path": "publications/forecasting-paper/esn.tex", "max_forks_repo_name": "arfc/cairo", "max_forks_repo_head_hexsha": "f2e38eadd6c786b2853defd97bc49c585bb6e513", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-10-01T18:27:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T07:37:44.000Z", "avg_line_length": 42.3815789474, "max_line_length": 210, "alphanum_fraction": 0.7215150574, "num_tokens": 1908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6020324441819818}}
{"text": "\n\\section{Integral equation derivation} \\label{sec:anapp}\n\n%\\subsection{Adapting the completed double layer representation\n%to solve the Dirichlet problem}\nWe would like to adapt the completed double layer representation\nfor solutions of Stokes flow \\cref{eq:helmstokes,eq:helmstokescty,eq:helmstokesnoslip} to solve \nthe clamped plate problem \\cref{eq:buck1,eq:buck2,eq:buck3}.\nLet $f$ and $g$ be the boundary data as in \\cref{eq:biharmD1,eq:biharmD2,eq:biharmD3}. \nBy computing tangential derivatives of $f$ on each\nboundary component, we get the following related oscillatory Stokes\nproblem:\n\\begin{align}\n \\Delta (\\Delta + \\lambda^2) \\tilde{w}  = 0 &\\quad \\bx \\in D \\, ,\\nonumber\\\\\n \\frac{\\partial \\tilde{w}}{\\partial \\tau} = \n \\frac{\\partial f}{\\partial \\tau} \n&\\quad \\bx \\in \\Gamma \\label{eq:biharm5} \\, ,\\\\ \n \\frac{\\partial \\tilde{w}}{\\partial n} = g &\\quad \\bx \n\\in \\Gamma \n\\, . \n\\nonumber\n\\end{align}\nThere are two main issues to be addressed in using the completed\ndouble layer representation in this context. First,\nthe representation is designed for \noscillatory Stokes flow, in which the quantities of interest are derivatives\nof the potential $\\tilde{w}$ and not $\\tilde{w}$ itself; the\nrepresentation for $\\tilde{w}$ may not be single-valued. \nWe will establish that, in the context of \\cref{eq:biharm5},\nthe stream function is necessarily single-valued. We also discuss\nsome numerical issues related to evaluating the stream function.\nThe second issue to address\nis that the solution $\\tilde{w}$ only satisfies the original boundary \ncondition for the value of $\\tilde{w}$ up to a constant on \neach boundary component.\nIn fact, for multiply connected domains, the completed double layer \nrepresentation is incomplete for the Dirichlet\nproblem \\cref{eq:biharmD1,eq:biharmD2,eq:biharmD3}. We present a remedy for this \nissue and provide some physical intuition.\n%\n%\\subsection{Single-valued stream functions}\n%To solve the Dirichlet problem \\cref{eq:biharmD1,eq:biharmD2,eq:biharmD3},\n%it is necessary to compute\n%a single-valued biharmonic potential.\n%In the case of a multiply connected domain,\n%there is no guarantee that a single-valued stream \n%function exists for a given velocity field.\n%\n%Consider the following example.\n%Let $(r,\\theta)$ denote standard polar coordinates. It is\n%easy to verify that the velocity field \n%$\\bu=\\frac{1}{r}\\hat{r}$ \n%solves the equations of Stokes flow in an annulus centered at the \n%origin. A stream function for this flow is $w=\\theta$, which \n%is not single-valued; indeed, there are no single-valued\n%stream functions which generate this flow. \n%\n%Let $D$ be a multiply connected domain with boundary \n%$\\Gamma = \\cup_{i=0}^N \\Gamma_i$, as in the previous section.\n%We note that the gradient of a stream function is determined \n%by the velocity field, i.e. \n%\n%\\begin{equation}\n%\\nabla w = -\\bu^\\perp := \\begin{pmatrix} \n%  - u_2 \\\\ u_1 \n%\\end{pmatrix} \\; .\n%\\end{equation}\n%Therefore, a velocity field has single-valued stream\n%functions if and only if $\\bu^\\perp$ is conservative.\n%Using standard results from multivariable calculus, \n%we can  characterize such flows.\n%\n%\\begin{proposition} \n%Suppose that $\\bu$ is a divergence-free velocity \n%field which is $C^1$ on $D$ and continuous on \n%$D\\cup \\Gamma$. The field $\\bu^\\perp$ \n%is conservative if and only if \n%\n%\\begin{equation}\n% \\int_{\\Gamma_i} \\bu\\cdot \\bn \\, dS \n%= 0 \\quad i=0,1,\\ldots N \\, .\n%\\label{eq:NecSuffStreamFuncExistence}\n%\\end{equation}\n%\n%\\end{proposition}\n%\n%The equalities \\cref{eq:NecSuffStreamFuncExistence}\n%constitute $N$ linearly independent constraints on the \n%boundary data because the divergence-free condition \n%\\cref{eq:MassConservation} implies that\n%$\\int_{\\Gamma} \\bu \\cdot \\bn \\, dS = 0$. \n%It turns out that \n%these conditions are satisfied when the Dirichlet \n%problem is recast as a Stokes flow \\cref{eq:biharm5}, as \n%it is easily verified that\n%\\begin{equation}\n% \\int_{\\Gamma_i} \\bu\\cdot \\bn \\, dS \n%= \\int_{\\Gamma_i} \\frac{\\partial f}{\\partial \\tau} \\, dS =0 \\, .\n%\\end{equation}\n%Thus, any stream function $\\tilde{w}$ obtained for the Stokes\n%flow \\cref{eq:biharm5} is necessarily single-valued.\n%% NOT GOING THIS WAY ANYMORE\n%%It can be shown using the Helmholtz Hodge decomposition that the \n%%conditions \\cref{eq:NecSuffStreamFuncExistence} are sufficient for \n%%the existence of a single-valued stream function. \n%\n%\\subsection{Evaluating the stream function} \\label{subsec:stream}\n%\n%Given compatible boundary data for the velocity field $\\bu$, \n%the completed double layer representation for Stokes flow \n%\\cref{eq:IntRepStokes} guarantees the existence of\n%a solution density $\\boldsymbol\\mu$ \n%and a corresponding stream function $\\tilde{w}$. The Goursat \n%function formula \n%for $\\tilde{w}$, see \\cref{sec:stokeslayer},\n%is necessarily single-valued, as explained above,\n%but it is not immediately obvious from the formula \n%that this should be true.\n%\n%The difficulty in the representation of $\\tilde{w}$ \n%comes from the part\n%of the stream function corresponding to the double layer potential\n% \\cref{eq:wDL}. The \n%second term in the expression for the double layer potential is\n%\\begin{equation}\n% v_1(z) = \\mbox{Re}\\left[\\frac{1}{4\\pi i}\\int_{\\Gamma}\\left(\n%\\overline{\\rho\\left(\\xi\\right)}d\\xi+\\rho\\left(\\xi\\right)\n%\\overline{d\\xi}\\right)\\log\\left(\\xi-z\\right)\\right] \\, .\n%\\end{equation}\n%To compute this term, in a na\\\"{i}ve numerical implementation,\n%the question of which is the appropriate branch of the \n%logarithm to use would arise at many steps.\n%To avoid this complication, it is possible instead to compute\n%$v_1$, up to a constant, as the harmonic conjugate of the\n%function \n%\\begin{equation}\n% v_2 = \\frac{1}{4\\pi}\\int_{\\Gamma}\\left(\\overline{\\rho\\left(\\xi\\right)}\n%d\\xi+\\rho\\left(\\xi\\right)\\overline{d\\xi}\\right)\\log\n%\\left(\\left|\\xi-z\\right|\\right) \\, . \\label{eq:harmconjg}\n%\\end{equation}\n%\n%We will use this approach to evalute $v_1$ numerically.\n%As a result of the Cauchy-Riemann equations, the \n%harmonic conjugate of $v_2$, satisfies the following\n%Neumann problem for the Laplace equation:\n%\\begin{align}\n% \\Delta v_1 &= 0 &\\quad x\\in D \\, ,\\\\\n% \\frac{\\partial v_1}{\\partial n} &= -\\frac{\\partial v_2}{\\partial \\tau} \n%&\\quad x\\in\\Gamma \\, .\n%\\end{align}\n%It is possible then to use standard integral equation\n%methods to compute $v_1$. \n%\n%Let $v_1 = S^L_\\Gamma \\sigma$, where $S^L_\\Gamma \\sigma$ \n%is the single layer potential for Laplace's equation, given by\n%\\begin{equation}\n%S^L_\\Gamma\\sigma (\\bx) = -\\frac{1}{2\\pi} \\int_{\\Gamma} \\log \n%\\left|\\bx - \\by \\right|\\sigma(\\by)\\, dS \\left(\\by \\right) \\, ,\n%\\end{equation}\n%where $\\sigma\\in \\mathcal{X}= C^{0,\\alpha}\\left(\\Gamma\\right)$, for \n%some $\\alpha \\in (0,1)$, is an unknown density \n%(see \\cite{kress1999linear, guenther1988partial}).\n%Imposing the Neumann boundary conditions results in the \n%following boundary integral equation for $\\sigma$:\n%\\begin{align}\n%-\\frac{\\partial v_2}{\\partial \\tau} (\\bx) &= \\frac{1}{2} \\sigma \\left(\\bx\\right) - \\frac{1}{2\\pi}\\oint_{\\Gamma} \n%\\frac{\\partial}{\\partial n_x}  \n%\\log \\left| \\bx - \\by \\right |\\sigma(\\by)\\, dS \\left(\\by \\right) \n%\\, , \\\\\n%-\\frac{\\partial v_2}{\\partial \\tau} &= \\left( \\frac{1}{2}I_{\\mathcal{X}} + K^L_\\Gamma  \\right) \\sigma \n%\\, ,\n%\\label{eq:BlockSystemRow2P1tmp}\n%\\end{align}\n%where the operator $K^L_\\Gamma$ is compact, so that the integral equation\n%is second kind.\n%For a derivation of this result, see \\cite{kress1999linear}.\n%\n%It is well known that the operator $\\frac{1}{2}I_{\\mathcal{X}} + K^L_\\Gamma$ \n%has a one dimensional null space. Thus,\n%we choose to solve the above integral equation subject to \n%the constraint $\\int_{\\Gamma} \\sigma \\, dS = 0$. \n%Furthermore, it is known that solving the Neumann problem subject \n%to the above constraint is equivalent\n%to solving\n%\\begin{align}\n%\\left( \\frac{1}{2}I_{\\mathcal{X}} + K^L_\\Gamma  + W_\\Gamma \\right) \\sigma \n%= -\\frac{\\partial v_2}{\\partial \\tau}\n%\\label{eq:BlockSystemRow2P1} \n%\\end{align}\n%where $W_\\Gamma\\sigma = \\int_{\\Gamma} \\sigma \\, dS$. \n%To prove this, we need \n%the following property of \n%the Green's function for Laplace's equation.\n%\\begin{align}\n%-\\frac{1}{2\\pi}\\oint_{\\gamma} \\frac{\\partial}{\\partial n_{\\by}}  \n%\\log \\left|\\bx - \\by\\right|\\, dS \\left(\\by \\right) \n%&=-\\frac{1}{2}\\quad\\bx\\in\\gamma \\, , \\label{eq:DLP2}\n%\\end{align}\n%Using the above property, it follows that\n%\\begin{align}\n% \\int_{\\Gamma} K^L_\\Gamma \\sigma \\, dS(\\x) \n%= -\\frac{1}{2}\\int_{\\Gamma} \\sigma \\left(\\bx\\right) \\, dS(\\x) \n%\\label{eq:KLint}\n%\\end{align}\n%Integrating equation \\cref{eq:BlockSystemRow2P1} and using \n%equation \\cref{eq:KLint}, we get\n%\\begin{align}\n%\\int_{\\Gamma} \\left( \\frac{1}{2}I_{\\mathcal{X}} + \n%K^L_\\Gamma  + L \\right) \\sigma \\, dS(\\x) \n%&= -\\int_{\\Gamma} \\frac{\\partial v_2}{\\partial \\tau} \\, dS(\\x) \\\\\n%\\left|\\Gamma\\right| L\\sigma  &= 0 \n%\\end{align}\n%which proves the result.\n\n\\subsection{Making the representation complete}\nAs mentioned above, the solution $\\tilde{w}$ of \nthe auxiliary oscillatory Stokes problem \\cref{eq:biharm5}\nonly satisfies the boundary conditions of the \noriginal Dirichlet problem \\cref{eq:biharmD1,eq:biharmD2,eq:biharmD3}\nup to a constant on each boundary component. For a simply\nconnected domain, this constant can be recovered from the\nfact that adding an arbitrary constant to a stream function\ndoes not change the velocity field. \nThus, in simply connected domains, there is an equivalence in the \nsolutions of \\cref{eq:biharm5} and \\cref{eq:biharmD1,eq:biharmD2,eq:biharmD3}.\n\nTo analyze the case of a multiply connected domain,\nwe first consider\nradially symmetric solutions on an annulus centered at the\norigin. Let $w\\left(r\\right)$ be a \nradially symmetric biharmonic-Stokes\npotential. Then $w(r)$ solves the ordinary differential\nequation (ODE)\n\\begin{equation}\n\\Delta_{r} (\\Delta_{r} + k^2)w = 0 \\, ,\n\\end{equation}\nwhere $\\Delta_{r}$ is the radial component of the Laplacian in polar\ncoordinates given by\n$$\n\\Delta_{r} = \\frac{1}{r}\\frac{d}{dr} r \\frac{d}{dr} \\, .\n$$\nFour linearly independent solutions of this ODE are $1$, $\\log{(r)}$, \n$J_{0}(kr)$, and $H_{0}(kr)$, \nwhere $J_{0}$ is the order zero Bessel function of the first kind, and $H_{0}$ is the order zero Hankel function of the first kind.\nFor each solution, we can compute the associated velocity field \n$\\bu = \\nabla^{\\perp} w$. By construction, $\\bu$ satisfies \nthe continuity condition \\cref{eq:MassConservation}. \nFor the momentum equation \\cref{eq:StokesFlowEq} to be \nsatisfied, we need that $\\Delta\\bu + k^2 \\bu$ is a conservative\nvector field, which \nis equivalent to the condition that \n$\\int_{\\gamma} (\\Delta\\bu + k^2 \\bu) \\cdot d\\bl = 0$ \nfor any closed \nloop $\\gamma$ in the annulus. For $\\tilde{w}=1$, $J_{0}(kr)$, and $H_{0}(kr)$,\nthe corresponding velocity field satisfies\n$\\Delta \\bu + k^2 \\bu=0$ so that $\\Delta \\bu$\nis trivially a conservative vector field. \nOn the other hand, for $\\tilde{w}=\\log{(r)}$, the corresponding velocity field\nsatisfies $\\Delta \\bu + k^2 \\bu=\\frac{k^2}{r} \\hat{\\theta}$.\nBy considering a curve $\\gamma$ encircling the origin,\nwe see that $\\Delta \\bu + k^2 \\bu$ is not a conservative vector\nfield and that any pressure for the velocity field \nassociated with $\\log\\left(r\\right)$ is not single-valued.\n%\n%The above analysis\n%can be extended to show that any solution of the biharmonic equation \n%of the form $\\log{|r-r_{j}|}$ where $r_{j}$ is located in one of the holes of a multiply connected\n%domain.\n%cannot be represented as a Stokes velocity field. \n%In simply connected \n%domains, since there are no holes, corresponding to each solution of the modified biharmonic equation with clamped plate\n%boundary conditions, there exists a solution to . For multiply connected domains with genus $N$, \n%the set of stream functions for Stokes velocity fields\n%misses an $N$ dimensional space of solutions, corresponding \n%to biharmonic charges located in the holes of the domain.\n%Following this reasoning, we obtain a complete representation\n%for biharmonic potentials on multiply connected domains\n%by adding $N$ charges, one per each hole of the domain,\n%to the representation for $w$. The details of this approach, and\n%the proof that it is sufficient, is in the next section.\n", "meta": {"hexsha": "805ffca391807dd4ad028f71c6401638bc9993bc", "size": 12226, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01/03inteq.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/03inteq.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/03inteq.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": 43.5088967972, "max_line_length": 131, "alphanum_fraction": 0.7238671683, "num_tokens": 3773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434873426302, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6020324323399028}}
{"text": "\n\\section*{Problem 1}\n\\begin{problem}{A. Physics of a carbonated drink}\n\nCarbonated bottled drinks contain dissolved carbon dioxide $CO_2$, which tends to be in the gaseous phase under normal condition. When you pour a carbonated drink into a glass, you can observe numerous small bubbles rising from the bottom. Those bubbles grow in size as they ascend and their speed changes as they travel upward.\n\\end{problem}\n\n\\begin{subpr}{A1. \\hfill 0.5pts.}\nConsider a bubble as a perfect sphere with initial radius ${r_0 = 2.0\\cdot 10^{-4}m}$ located at the bottom of a glass filled with fluid of density ${\\rho_f = 1.0\\cdot 10^{3}kg/m^3}$ up to the height ${h = 0.2\\;m}$. When the bubble reaches the surface between fluid and air, its radius increases two times from initial size near bottom of the glass.\n\\vspace{2mm}\n\\begin{center} \n    \\includegraphics[height=4cm]{Images/1_bbl_theory_carbonated.PNG}\n\\end{center}\n\\vspace{2mm}\n\nEstimate amount of energy ${\\Delta E}$ dissipated due to viscous effects during ascending of that bubble. For calculations use acceleration due to gravity as ${g = 9.8\\;m/s^2}$. Assume that surface tension effects are negligibly small\n\\end{subpr}\n\\begin{subpr}{A2. \\hfill 0.2pts.} Estimate velocity ${v_h}$ of the bubble at the distance ${h = 0.2\\;m}$ from bottom of the glass\n\\\\\nFor calculations use dynamic viscosity of carbonated drink as ${\\eta_f = 1.0\\cdot 10^{-3}Pa\\cdot s}$\n\\end{subpr}\n\\begin{subpr}{A3. \\hfill 1.3pts.} \nEstimate acceleration ${a_h}$ of the bubble at the distance ${h = 0.2\\;m}$ from bottom of the glass. Assume that surface tension effects are negligibly small.\n\\end{subpr}\n\n\\begin{problem}{B. Sonoluminescence}\nSonoluminescence is a wonderful phenomena where an external acoustic wave causes disturbances in the fluid, leading to the growth and rapid collapse of bubbles in the liquid. During that bubble collapse, content of the bubble become heated to extremely high temperatures, which causes excitation of the gas with emission of light.\n\\begin{center} \n\\includegraphics[height=4cm]{Images/5_bbl_theory_sonolum1.PNG}\n\\end{center}\n\\begin{center}\nPhoto of single bubble sonoluminescence (light blue spot in the center of glass sphere filled with fluid). Credit to Suslick K.\n\\end{center}\n\\vspace{3mm}\nIn this section of the problem you will have an opportunity to describe some key aspects of the sonoluminescence process\n\\end{problem}\n\\begin{subpr}{B1. \\hfill 1.2pts.}\nConsider a large volume of incompressible fluid of density ${\\rho}$, which is initially at rest. That container with fluid has a small spherical cavity (an empty space without gas or fluid) of initial radius ${R_0}$, which starts to collapse due to an ambient fluid pressure ${P_0}$.\n\\begin{center} \n\\includegraphics[height=3cm]{Images/6_bbl_prob_empty_collapse_velocity1.PNG}\n\\end{center}\nEvaluate velocity ${v_1}$ of the boundary of cavity when radius of the bubble would decrease to some value ${R_1}$. Assume that for such small size of the cavity surface tension and viscous effects can be neglected\n\\end{subpr}\n\\begin{problem}{}\nAs was shown in the previous section velocity of the boundary of an empty cavity would tend to increase to infinity during collapse of the cavity at small radius ${R\\!\\rightarrow\\! 0}.$ Thus, modeling of an empty cavity is unrealistic, which means that bubble in fluid has to be filled with some gas or vapor. This would create a counterbalance pressure inside the bubble, allowing it to bounce back at some small non-zero radius\n\n$$\t***  $$\n\nSonoluminescence effect occurs when changes in ambient pressure of fluid cause a bubble with noble gas to shrink, which increases temperature of the gas significantly. Usually in experiments with sonoluminescence, fluid pressure is varied as a harmonic function of time. However, here for simplicity, will consider only a rough approximation of the process, with one step of such variations in pressure, when fluid pressure is increased very fast from initial value ${P_0}$ to some new high value  ${P_f = 100P_0}$\n\n\\begin{center}\n\\includegraphics[width=9cm]{Images/7_bbl_theory_velocity_too_high1.PNG}\n\\end{center}\n\nFor the next few questions consider a bubble, which initially has a stationary radius ${R_0 = 1.0\\cdot 10^{-4}\\;m},$ being filled with a noble gas xenon at temperature ${T_0 = 300.0\\;K}$ and pressure ${P_0}$. Shrinkage of bubble due to increased ambient fluid pressure can be accurately modeled with adiabatic process, which can be described with adiabatic constant ${\\gamma}$:\n$$\\gamma = \\frac{C_p}{C_v} = \\frac{5}{3}$$\nwhere ${C_p}$ and ${C_v}$ are molar heat capacities of xenon at constant pressure and constant volume respectively.\n\\end{problem}\n\\begin{subpr}{B2. \\hfill 1.2pts.} Determine minimal radius of the bubble ${R_{min}}$ due to increase in ambient fluid pressure from ${P_0}$ to ${P_f = 100P_0}.$ Assume that surface tension and viscous friction effects can be neglected. Also for simplicity assume that presence of water vapor inside the bubble is negligibly small\\\\\n\\textbf{Note:}\nFor your calculations, you are not expected to use manual iterative approach for solving transcendental equations. Instead it could be easier to use calculations in some spreadsheet such as MS Excel, or write a simple script for plotting a complicated function\n\\end{subpr}\n\n\\begin{subpr}{B3. \\hfill 0.3pts.} Evaluate maximum temperature ${T_{max}}$ of the noble gas inside cavity during its shrinkage.\n\\end{subpr}\n\\begin{problem}{Stability}\n\nIt is interesting that a lot of processes for bubbles differ based on the initial equilibrium size of the bubble. If radius of the bubble is larger than certain critical value $R_c$ , then after small disturbances in ambient fluid pressure, the bubble will start growing uncontrollably. Otherwise if initial equilibrium radius of cavity is smaller than certain threshold, it will be stable to small variations of pressure\n\\end{problem}\n\n\\begin{subpr}{B4. \\hfill 1.2pts.} \n\nConsider a small bubble with radius ${R_0 = 5.0\\cdot 10^{-6}m}$, which is held at pressure ${P_0 = 10^5\\;Pa}$ in equilibrium with distilled water. Then fluid pressure was disturbed so that bubble expanded to radius ${R}$.\n\\begin{center}\n\\includegraphics[height=3cm]{Images/4_bbl_prob_Blake_pressure_unstable1.PNG}\n\\end{center}\nCalculate critical radius ${R_c}$ for this system, if entire process can be treated as isothermal, with vapor pressure at that temperature equal to ${P_v = 0.5\\cdot 10^{5}\\;Pa}.$ Coefficient of surface tension of water is ${\\sigma = 7.2\\cdot 10^{-2}N/m}$\n\\end{subpr}\n\n\\begin{problem}{Small oscillations}\n\nIn the next questions, assume that radius of the bubble is less than critical value ${R_c}$ unless otherwise stated. For those smaller bubbles, minor disturbances in ambient fluid pressure would cause small harmonic oscillations with frequency ${\\omega}.$ That frequency can be decomposed at three components as\n\n$$\\omega^2 = \\omega_p^2 + \\omega_{\\sigma}^2 - \\omega_{\\eta}^2$$\nwhere ${\\omega_p}$ is natural frequency of the bubble inside liquid, neglecting effects of surface tension and attenuation due to viscosity. While ${\\omega_{\\sigma}}$ and ${\\omega_{\\eta}}$ are additional correction terms associated with surface tension effects and viscosity respectively.\n\\end{problem}\n\n\\begin{subpr}{B6. \\hfill 1.2pts.} Evaluate frequency ${\\omega_p}$ of small harmonic oscillations of the bubble of radius ${R_0 = 1.0\\cdot 10^{-4}}m$ assuming that surface tension and viscosity effects can be neglected. Consider that oscillating bubble is filled with xenon, which has adiabatic constant ${\\gamma = 5/3}.$ The bubble is floating inside distilled water of density ${\\rho = 1.0\\cdot 10^{3}kg/m^3}.$ Assume that during those oscillations  fluid pressure ${P_f}$ is always close to initial pressure ${P_0}$ inside bubble:\n\n$$P_f\\approx P_0 = 1.0\\cdot 10^{5}Pa$$\n\nFor small ${z\\ll 1}$ can be used following approximation\n$$(1-z)^n\\approx 1-nz + \\frac{n(n-1)z^2}{2}$$\n\\end{subpr}\n\\begin{subpr}{B7. \\hfill 0.2pts.}\nIt is known that for larger bubbles with initial radius ${R_0 = 1.0\\cdot 10^{-4}m}$ ratio between components of frequencies related to surface tension ${\\omega_{\\sigma}}$ to the frequency ${\\omega_p}$ calculated with neglecting surface tension and viscous effects is\n$$z_{\\sigma 0} = \\frac{\\omega_{\\sigma0}}{\\omega_{p0}} = 0.1$$\nDetermine ratio ${z_{\\sigma 1} = \\omega_{\\sigma 1}/\\omega_{p1}}$ for a smaller bubble with radius ${R_1 = R_0/10}$\n\\end{subpr}\n\\begin{subpr}{B8. \\hfill 0.3pts.}\nIt is known that for bubble with radius ${R_0 = 1.0\\cdot 10^{-4}m}$ ratio between components of frequency related to viscous forces ${\\omega_{\\eta}}$ to frequency ${\\omega_{p}}$ calculated by neglecting surface tension and viscous effects is\n$$z_{\\eta 0} = \\frac{\\omega_{\\eta 0}}{\\omega_{p0}} = 4.0\\cdot 10^{-4}$$\nEstimate similar ratio ${z_{\\eta 1} = \\frac{\\omega_{\\eta 1}}{\\omega_{p1}}}$ for bubble with smaller radius ${R_1 = R_0/10}$\n\\end{subpr}\n\\begin{problem}{Forces due to variable pressure}\nIn case when pressure is spatially varied, effective force applied on the object inside such pressure field would be non-zero. For example, hydro static pressure varies with depth, creating buoyancy force in the vertical direction. In this section we will describe horizontal forces exerted on bubbles in fluid in the presence of variable pressure\n\\end{problem}\n\\begin{subpr}{B9. \\hfill 0.2pts.}\n\nConsider a small cylinder with a height ${h}$ and cross-sectional area is ${S}$ placed inside a fluid, which has spatially varied pressure ${P}$ characterized with coordinate ${x}$ as\n\t$$P = P_0(1+c_1x^2)$$\nwhere ${c_1}$ is some known constant\n\\begin{center}\n\\includegraphics[height=3cm]{Images/17_bbl_prob_cylinder_cx21.PNG}\n\\end{center}\nCenter of the cylinder is located at the coordinate ${x_0\\gg h},$ while main axis of the cylinder is parallel to the ${X}$ axis. Evaluate effective horizontal force ${F_x}$ exerted on this cylinder from fluid \n\\end{subpr}\n\n\\begin{subpr}{B10. \\hfill 0.5pts.} \nA rigid sphere of radius ${R}$ is placed inside a fluid, with variable pressure, which changes with horizontal coordinate ${x}$ as\n\n$$P = P_0(1+c_1x^2)$$\nwhere ${c_1}$ is some known constant\\\\\nCenter of the sphere is located at coordinate ${x_0\\ll R}$. Determine effective horizontal force ${F_x}$ applied to the sphere from the surrounding fluid \n\\end{subpr}\n\n\\begin{subpr}{B11. \\hfill 0.2pts.}\nNow consider a similar case with a rigid sphere of radius ${R}$ placed inside fluid, where pressure ${P_f}$ changes with horizontal coordinate ${x}$ and time ${t}$ as\n\n$$P_f = P_0 + c_2\\sin kx\\cos\\omega t$$\nwhere ${P_0}$, ${c_2},$ ${k}$ and ${\\omega}$ are known constants\\\\\nEvaluate average effective horizontal force ${\\left<F_x\\right>}$ exerted at the sphere, if known that radius of the sphere is much smaller than parameter ${1/k}$\n\\end{subpr}\n\n\\begin{subpr}{B12. \\hfill 0.3pts.} Now consider an oscillating bubble in a standing wave, with fluid pressure described as a function of horizontal coordinate ${x}$ and time ${t}$ as\n$$P = P_0 + c_2\\sin kx\\cos\\omega t$$\nwhere ${P_0}$, ${c_2}$, ${k}$, ${\\omega}$ and ${\\phi}$ are some positive constants\\\\\nIt can be shown that in such variable pressure, radius of the bubble ${R}$ would change as a function of time as \n$$R = R_0 - \\delta \\sin kx\\cos(\\omega t +\\phi)$$\nwhere ${R_0}$ and ${\\delta}$ are some positive constants\\\\\nLet's call bubbles with size larger than critical radius  ${R_c}$ as \"Large\" and bubbles with radii smaller than ${R_c}$ as \"Small\". It can be shown that parameter ${\\phi}$ is equal ${0}$ or ${\\pi}$\\\\\nLet ${\\phi_L}$ and ${\\phi_S}$ are coefficients ${\\phi}$ for \"Large\" and \"Small\" bubbles respectively. Briefly justify in 1-2 sentences or in a few short equations, which values ${0}$ or ${\\pi}$ should we use for parameters ${\\phi_L}$ and ${\\phi_S}$\n\\end{subpr}\n\\begin{subpr}{B13. \\hfill 0.7pts.} \nConsider bubble described in the question ${B12}$ with small oscillations such that ${\\delta \\ll R_0}$. Determine average horizontal force ${\\left<F_x\\right>}$ exerted at this oscillating bubble\n\\end{subpr}\n\\begin{subpr}{B14. \\hfill 0.5pts.}\nConsider that fluid pressure changes with time ${t}$ and coordinate ${x}$ as\n$$\tP = P_0 + c_3\\sin kx\\cos\\omega t$$\nThis is an equation of a standing wave, which can be characterized with \"nodes\" and \"antinodes\"\n\\begin{center}\n\\includegraphics[height=3cm]{Images/22_bbl_prob_nodes_antinodes_grouping1.PNG}\n\\end{center}\nDescribe briefly in ${1-2}$ sentences where would gather \"Large\" and \"Small\" bubble in that standing wave (either close to nodes or in the vicinity of antinodes)\t\n\\end{subpr}\n\n\\clearpage", "meta": {"hexsha": "1a3878460fa26f09977fd3047cf4a3acef014c29", "size": 12568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Round-3/Problems/1.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/1.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/1.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": 80.050955414, "max_line_length": 532, "alphanum_fraction": 0.7512730745, "num_tokens": 3488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802476562641, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.601930257043191}}
{"text": "\\chapter{Computers}\n\nWe recommend that you skip this chapter\nuntil you use a computer to do physics calculations.\n\n\\section{Working with limited precision}\n\nComputers can only store finitely many digits.\nComputers can only represent a \\emph{finite} subset of \\(\\Real\\).\nComputers can't represent most real numbers.\n\nThe take-home message is:\n\\emph{Mixing numbers with varying exponents increases errors}.\n\nTo understand these phenomena, we have to understand how computers represent numbers.\n\n\\section{Understanding how computers represent numbers}\n\nThere are many ways:\n\\UnorderedList{\n\\item floating-point integers\n\\item fixed-point integers\n\\item arbitrary-precision integers\n\\item symbolic representations\n\\item one's-complement signed integers\n\\item two's-complement signed integers\n\\item unsigned integers\n\\item sign-magnitude\n}\n\nThe representation depends on the program.\n\nEach representation has its benefits and drawbacks.\n\nIf you are doing physics with computers,\nthen there's a high chance that the numbers you see are \\emph{IEEE 754 double-precision floating-point integers},\nwhich are often shortened to \\emph{doubles}.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Double-precision_floating-point_format}}\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Binary_number}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Signed_number_representations}}\n\n\\subsection{Understanding \\emph{doubles}}\n\nA \\emph{double} represents a number as the base-2 scientific notation\n\\(\n(-1)^s \\times 1 . d_{51} d_{50} d_{49} \\ldots d_2 d_1 d_0 \\times 2^{p - 1023}\n\\)\nNote that the first significant digit is always one and is not stored in memory.\nEach \\(d_k\\) is a binary digit (zero or one).\n\nBit 63 is the sign bit \\(s\\):\n0 means positive;\n1 means negative.\n\nBits 62\\textendash{}52 (11 bits) are the \\emph{biased exponent} \\(p\\).\n\nBits 51\\textendash{}0 (52 bits) are called the \\emph{significand} or \\emph{mantissa}.\nBit 51 is \\(d_{51}\\), and so on; bit 0 is \\(d_0\\).\n\n\\subsection{Understanding the problem with doubles}\n\nIf a fraction has a denominator that is not a power of two,\nthen a double can't represent the fraction exactly.\nFor example, a double can't represent even a simple fraction such as \\(1/3\\) exactly\nbecause the base-2 expansion of \\(1/3\\) doesn't terminate,\nin the same way that the decimal expansion of \\(1/3\\) (\\(0.333\\ldots\\)) doesn't terminate.\n\nA double has only 53 significant binary digits.\nA multiplication of two 53-digit numbers may produce up to a 106-digit number.\nThe result is rounded to 53 digits; thus at most 53 digits are lost.\n\nThere is also a website\\footnote{\\url{http://floating-point-gui.de/}} that explains the issue.\n\n\\subsection{Understanding computer algebra systems}\n\nComputer algebra systems can represent numbers like \\(\\sqrt{2}\\) and \\(1/3\\) exactly because\nit does not represent numbers as strings of digits.\nIt stores \\(\\sqrt{2}\\) as something like \\verb@(sqrt 2)@.\nIt does not evaluate \\(\\sqrt{2}\\) to \\(1.4142\\ldots\\) before storing it.\n\n\\subsection{Understanding ulp: units of least precision}\n\nThe standard is IEEE 754.\n\nFor example, in IEEE 754 double-precision floating-point integers,\n\\( 2^{53} + 1 = 2^{53} \\).\n\nIn some browsers, you can verify this. Press Ctrl+Shift+J to open its Console,\nand then enter \\verb@Math.pow(2,53)@, and then enter \\verb@Math.pow(2,53)+1@,\nand see that they give the same number.\n\n\\section{Solving a system of linear equations}\n\nYou can use GNU Octave.\n\nUse left division:\n\\begin{verbatim}\nA \\ C\n\\end{verbatim}\n\nThis also works for Matlab.\n\n\\section{Related fields of study}\n\nRelated fields of study are\n\\emph{scientific computing} (also known as \\emph{computational science})\nand \\emph{numerical analysis}.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Computational_science}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Numerical_analysis}}\n\n\\section{Using an equation to program a computer}\n", "meta": {"hexsha": "6d598b75e104854604f53e015712185f75809ac1", "size": 3880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/computer.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/computer.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/computer.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.3362831858, "max_line_length": 113, "alphanum_fraction": 0.7613402062, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6019302365745869}}
{"text": "\\section{Manipulate Conductivity in Quantum Hall System}\n\nNow using the relations derived in Eq. \\eqref{5.34} and Eq. \\eqref{7.17} we can derive that\n\\begin{equation} \\label{8.1}\n  \\Gamma_n = \\qty(\\frac{\\hbar }{2\\tau(\\varepsilon_n)}) =\n  \\frac{1}{2}\\Gamma^{00}_{N}(\\tilde{I}),\n\\end{equation}\nand using \\eqref{5.32}, this can be re-write as follows\n\\begin{equation} \\label{8.2}\n   \\Gamma_n = \\frac{1}{2} \\Lambda_N (\\tilde{I}) \\Gamma^{00}_{N=0}\\big|_{E=0}.\n\\end{equation}\nLet $\\Gamma^{00}_{N=0}\\big|_{E=0} = \\Gamma_0$ and this leads to\n\\begin{equation} \\label{8.3}\n   \\gamma_n = \\frac{\\Gamma_n}{\\hbar \\omega_0} =\n   \\frac{\\Gamma_0}{2\\hbar \\omega_0} \\Lambda_N (\\tilde{I})\n\\end{equation}\nLet $\\alpha \\equiv \\flatfrac{\\Gamma_0}{2\\hbar \\omega_0}$ and we can obtain\n\\begin{equation} \\label{8.4}\n   \\gamma_n = \\alpha \\Lambda_N (\\tilde{I})\n\\end{equation}\nThus we can write the transverse conductivity as a function of fermi energy and intensity\n\\begin{equation} \\label{8.5}\n  \\begin{aligned}\n    \\sigma^{xx}(X_F,\\tilde{I}) & =\n    \\frac{e^2}{\\pi\\hbar A}\n    \\sum_{n}\n    \\frac{\\qty(n+1)}{\\alpha^2 \\Lambda_n \\Lambda_{n+1}}\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n -1}{\\alpha\\Lambda_n})^2\n      }\n    ]\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n}{\\alpha\\Lambda_{n+1}})^2\n      }\n    ].\n  \\end{aligned}\n\\end{equation}\nThen we can define a normalized transverse conductivity as follows\n\\begin{equation} \\label{8.6}\n  \\begin{aligned}\n    \\widetilde{\\sigma}^{xx}(X_F,\\tilde{I}) =\n    \\flatfrac{\\sigma^{xx}}{\\sigma_0} =\n    \\sum_{n}\n    \\frac{\\qty(n+1)}{\\alpha^2 \\Lambda_n \\Lambda_{n+1}}\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n -1}{\\alpha\\Lambda_n})^2\n      }\n    ]\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n}{\\alpha\\Lambda_{n+1}})^2\n      }\n    ],\n  \\end{aligned}\n\\end{equation}\nwhere $\\sigma_0 = \\flatfrac{e^2}{(\\pi\\hbar A)}$.\n\nAbove parameters can be evaluated for our experiment variables($\\Gamma_0 = 0.24 \\text{meV}$) as follows\n\\begin{equation} \\label{8.2}\n  \\Gamma_n(\\tilde{I}) = 0.12\\times\n  \\qty[\n  \\frac\n  {\\int_{-\\infty}^{\\infty} d {k}_1 \\;\n  J_0^2\\qty(2.090\\sqrt{\\tilde{I}}\\times{k}_1)\n  \\qty|\n  \\int_{-\\infty}^{\\infty} d{k}_2 \\;\n  \\tilde{\\chi}_{N}\\qty(2.342 \\times k_2)\n  \\tilde{\\chi}_{N}\\qty(2.342 \\times \\qty[{k}_1 - {k}_2])|^2}\n  {\\int_{-\\infty}^{\\infty} d {k}_1 \\;\n  \\qty|\n  \\int_{-\\infty}^{\\infty} d{k}_2 \\;\n  \\tilde{\\chi}_{0}\\qty(2.342 \\times k_2)\n  \\tilde{\\chi}_{0}\\qty(2.342 \\times \\qty[{k}_1 - {k}_2])|^2}\n  ]^{1/2} \\text{meV}\n\\end{equation}\n\n\\noindent\nIn addition we can calculate the cyclotron energy as\n\\begin{equation} \\label{8.3}\n  \\hbar\\omega_0 = 1.95663 \\;\\text{meV}\n\\end{equation}\nand\n\\begin{equation} \\label{8.4}\n  \\gamma_n = \\frac{\\Gamma_n}{\\hbar \\omega_0} = 0.06133 \\times \\Lambda_n(\\tilde{I}) \\approx 0.061 \\Lambda_n(\\tilde{I})\n\\end{equation}\n\n\\noindent\nNow we can use this into our conductivity expression derived in Eq. \\eqref{7.23} and present the normalized transverse conductivity as a function of fermi energy and intensity of the dressing field\n\\begin{equation} \\label{8.5}\n  \\begin{aligned}\n    \\sigma^{xx}(X_F,\\tilde{I}) & =\n    \\sum_{n}\n    \\frac{\\qty(n+1)}{0.0037\\Lambda_n \\Lambda_{n+1}}\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n -1}{0.06\\Lambda_n})^2\n      }\n    ]\n    \\qty[\n      \\frac{1}\n      {\n        1 + \\qty(\\frac{X_F - n}{0.06\\Lambda_{n+1}})^2\n      }\n    ]\n  \\end{aligned}\n\\end{equation}\nwhere\n\\begin{equation} \\label{8.6}\n    \\Lambda_n  =\n    \\qty[\n    \\frac\n    {\\int_{-\\infty}^{\\infty} d {k}_1 \\;\n    J_0^2\\qty(2.090\\sqrt{\\tilde{I}}\\times{k}_1)\n    \\qty|\n    \\int_{-\\infty}^{\\infty} d{k}_2 \\;\n    \\tilde{\\chi}_{n}\\qty(2.342 \\times k_2)\n    \\tilde{\\chi}_{n}\\qty(2.342 \\times \\qty[{k}_1 - {k}_2])|^2}\n    {\\int_{-\\infty}^{\\infty} d {k}_1 \\;\n    \\qty|\n    \\int_{-\\infty}^{\\infty} d{k}_2 \\;\n    \\tilde{\\chi}_{0}\\qty(2.342 \\times k_2)\n    \\tilde{\\chi}_{0}\\qty(2.342 \\times \\qty[{k}_1 - {k}_2])|^2}\n    ]^{1/2}.\n\\end{equation}\n\\hfill$\\blacksquare$\n\n\\noindent\nNow using Eq. \\eqref{8.6} we can calculate the normalized broadening of each Landau levels as given in Table \\ref{tab:8.1}.\n\n\\begin{table}[ht!]\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c|c|c|c|c|c|c|c|c| }\n \\hline\n ${\\tilde{I}}$\n & $n=0$ & $n=1$ & $n=2$ & $n=3$ & $n=4$ & $n=5$ & $n=6$ & $n=7$ & $n=8$ & $n=9$\n & $n=10$\n \\\\ [0.5ex] \\hline\\hline\n 0  & $1.0000$ & $0.8660$ & $0.8004$ & $0.7578$ & $0.7266$\n & $0.7021$ & $0.6821$ & $0.6653$ & $0.6507$ & $0.6380$& $0.6267$ \\\\ \\hline\n 1  & $0.8546$ & $0.7037$ & $0.6502$ & $0.6114$ & $0.5810$\n & $0.5584$ & $0.5416$ & $0.5280$ & $0.5160$ & $0.5050$ & $0.4948$ \\\\ \\hline\n 4  & $0.6875$ & $0.6345$ & $0.5902$ & $0.5528$ & $0.5307$\n & $0.5118$ & $0.4958$ & $0.4840$ & $0.4730$ & $0.4629$  & $0.4547$ \\\\ \\hline\n 9  & $0.5936$ & $0.5539$ & $0.5333$ & $0.5180$ & $0.5006$\n & $0.4812$ & $0.4685$ & $0.4564$ & $0.4469$ & $0.4377$  & $0.4305$ \\\\ \\hline\n\\end{tabular}\n\\caption {\\label{tab:8.1} $\\Lambda_n$ values for each Landau level by changing  applied dressing field intensity ($\\tilde{I}$). }\n\\end{center}\n\\end{table}\n\n\\noindent\nUsing above values we can analyse the changes can be done to the transverse conductivity using apllied dressing field. As given in Figure \\ref{fig:8.1} and \\ref{fig:8.2} we can manipulate the conductivity using external dressing field. When the applied field's intensity increase the broadening of energy bands of Landau levels get reduced the conductivity also get decrease all the regions except the peak point of the energy band. Using this manipulation we can filter the conductivity which is change with the Fermi level. Since Fermi level can be change with the applied gate voltage of the material this can be used as a 2D switch for optoelectonic applications. Using the applied dressing field we can fine tune the switching mechanism.\n\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=1]{figures/fig81.pdf}\n  \\caption{Normalized transverse conductivity against Fermi level ($X_F$) with different intensities ($\\tilde{I}$) of dressing field.}\n  \\label{fig:8.1}\n\\end{figure}\n\\begin{figure}[ht!]\n  \\centering\n  \\includegraphics[scale=1]{figures/fig82.pdf}\n  \\caption{$3$rd Landau level's normalized transverse conductivity against Fermi level ($X_F$) with different intensities ($\\tilde{I}$) of dressing field.}\n  \\label{fig:8.2}\n\\end{figure}\n", "meta": {"hexsha": "bf17eb613e8c1b3988541bda44d8feda4a14f047", "size": 6331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory/sec_08.tex", "max_stars_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_stars_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_stars_repo_licenses": ["MIT"], "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/sec_08.tex", "max_issues_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_issues_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_issues_repo_licenses": ["MIT"], "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/sec_08.tex", "max_forks_repo_name": "KosalaHerath/magnetic-2DEG-conductivity", "max_forks_repo_head_hexsha": "91c5df1b018579b4b9c91d84f2d60ee482a001de", "max_forks_repo_licenses": ["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.3850574713, "max_line_length": 742, "alphanum_fraction": 0.6150687095, "num_tokens": 2535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6019090196302812}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n    \\DeclareGraphicsExtensions{.png, .jpeg}\n\\usepackage{caption}\n\\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}\n\n\\title{STAT 775: Machine Learning \\\\ HW 04}\n\\author{Terence Henriod}\n\\date{\\today}\n\n\\begin{document}\n\n\\clearpage            % All\n\\maketitle            % this,\n\\thispagestyle{empty} % removes the page number from the title page\n\n\\begin{abstract}\nAn exercise that shows a commonality between Ridge Regression and OLS Regression is performed and a common technique of Linear Discriminant Analysis (LDA), the Fisher Discriminant, is implemented and its performance is explored.\n\\end{abstract}\n\n\\newpage\n\\section{Exercise 01}\nElements of Statistical Learning 3.12: Show that the ridge regression estimates can be obtained by ordinary least squares regression on an augmented data set. We augment the centered matrix $\\textbf{X}$ with $p$ additional rows $\\sqrt{\\lambda}\\textbf{I}$, and augment $y$ with $p$ zeros. By introducing artificial data having response value zero, the fitting procedure is forced to shrink the coefficients toward zero. This is related to the idea of \\emph{hints} due to Abu-Mostafa (1995), where model constraints are implemented by adding artificial data examples that satisfy them.\n\n\\textit{Solution}:\\\\\nIf we consider the formulae for finding the regression weight vector $\\vec{\\beta}$ for both methods of regression, we have for OLS Regression:\n$$\\hat{\\vec{\\beta}} = (X^{T}X)^{-1} * X^{T}\\vec{y}$$\nand for Ridge Regression:\n$$\\hat{\\vec{\\beta}} = (X^{T}X + \\lambda\\textbf{I})^{-1} * X^{T}\\vec{y}^\\prime$$\nLet us consider the OLS Regression formula. Suppose we create an $X^\\prime$ matrix and a $y^\\prime$ vector as in the problem statement, where the $X$ matrix has a $p$ x $p$ matrix of $\\sqrt{\\lambda}\\textbf{I}$ appended to the ``bottom\".\n\nConsider the $(X^{T}X)^{-1}$ term. When we compute $X^{\\prime T}X^\\prime$, because of the nature of matrix multiplication, the $\\sqrt{\\lambda}$ terms only get multiplied with one another, and only when matrix multiplication sub-operations that produce the elements of the diagonals of the result at that. This results in a result matrix equivalent to that produced by the `non-$^\\prime$' version, except that $\\sqrt{\\lambda} * \\sqrt{\\lambda} = \\lambda$ is added to each diagonal element. Thus $X^{\\prime T}X^\\prime = X^{T}X + \\lambda\\textbf{I}$.\n\nNow consider the $X^{T}\\vec{y}$. Because $\\vec{y}^\\prime$ has been padded with $0$s, none of the $\\sqrt{\\lambda}$ terms in $X^{\\prime T}$ affect the sums that compose the elements of the resulting vector in the matrix-vector multiplication of $X^{\\prime T}\\vec{y}^\\prime$. Thus $X^{T}\\vec{y} = X^{\\prime T}\\vec{y}^\\prime$, the same result as in both regressions.\n\nSince all elements of the augmented OLS Regression are equivalent to the terms of the Ridge Regression, the two must be equivalent.\n\nAlternately, we can consider the $RSS$ or objective function of the OLS Regression, specifically in the augmented case:\n\\begin{align*}\n  RSS &= \\sum_{i=1}^{N + p}{(y_{i} - \\sum_{j=1}^{p}{x_{ij}\\beta_{j}})^{2}}\\\\\n      &= \\sum_{i=1}^{N}{(y_{i} - \\sum_{j=1}^{p}{x_{ij}\\beta_{j}})^{2}} + \\sum_{i=N+1}^{p}{\\sum_{j=1}^{p}{(x_{ij}\\beta_{j}})^{2}}\\\\\n      &= \\sum_{i=1}^{N}{(y_{i} - \\sum_{j=1}^{p}{x_{ij}\\beta_{j}})^{2}} + \\sum_{j=1}^{p}{\\lambda\\beta_{j}^{2}}\n\\end{align*}\nwhich is the objective function for Ridge Regression. Note that the sum inside the sum in the second term of the intermediate step will add a lot of zeros with the occasional $(\\sqrt{\\lambda}\\beta)^{2}$.\n\n%\n\\newpage\n\\section{Exercise 02}\n\\subsection{Problem Statement}\nUsing the zip code digit data from the ESL website, use the Fisher Discriminant to perform binary classification between 2s and 3s, 4s and 5s, and 7s and 9s.\n\n\\subsection{Results}\nTwo decision boundaries were used, and both produced the same results. Let $\\vec{u}$ be the line the data is projected onto for optimal discrimination. For the first method, let the decision boundary value $c = \\vec{u}^{t} * \\frac{1}{/2} * (\\mu_{1} + \\mu_{2})$, where if $\\vec{u}^{t} * x_{i} > c$, then $x_{i}$ belongs to the first class, or the other class otherwise. For the second, the data was projected onto $\\vec{u}$, and then a gaussian distribution was fitted to the projected points for each class, and then using Bayes' Rule, a decision boundary was computed. IT must be that either the data were small enough, the projections were separate enough, or the covariances were similar enough that no difference between the methods was seen. It should be noted though, that the first method is requires the assumptions that each class is equally likely and have similar covariance to be valid.\n\nThe results are as follows:\n % \\begin{figure}[h!]\n %    \\centering\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_2,_3}\n %      \\caption{A bar chart indicating the classification/misclassification rates for 2s and 3s.}\n %      \\label{fig:2_3_bar}\n %    \\end{minipage}%\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.7\\linewidth]{2_3_confusion}\n %      \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 2s and 3s.}\n %      \\label{fig:2_3_confusion}\n %    \\end{minipage}\n %  \\end{figure}\n\n % \\begin{figure}[h!]\n %    \\centering\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_4,_5}\n %      \\caption{A bar chart indicating the classification/misclassification rates for 4s and 5s.}\n %      \\label{fig:4_5_bar}\n %    \\end{minipage}%\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.7\\linewidth]{4_5_confusion}\n %      \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 4s and 5s.}\n %      \\label{fig:4_5_confusion}\n %    \\end{minipage}\n %  \\end{figure}\n\n %   \\begin{figure}[h!]\n %    \\centering\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_7,_9}\n %      \\caption{A bar chart indicating the classification/misclassification rates for 7s and 9s.}\n %      \\label{fig:7_9_bar}\n %    \\end{minipage}%\n %    \\begin{minipage}{.5\\textwidth}\n %      \\centering\n %      \\includegraphics[width=.7\\linewidth]{7_9_confusion}\n %      \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 7s and 9s.}\n %      \\label{fig:7_9_confusion}\n %    \\end{minipage}\n %  \\end{figure}\n\\newpage\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_2,_3}\n  \\caption{Classification results for Fisher Discriminant Analysis on 2s vs 3s.}\n  \\label{fig:2_3_bar}\n\\end{figure}\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{2_3_confusion}\n  \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 2s and 3s.}\n  \\label{fig:2_3_confusion}\n\\end{figure}\n%\n\\newpage\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_4,_5}\n  \\caption{Classification results for Fisher Discriminant Analysis on 4s vs 5s.}\n  \\label{fig:4_5_bar}\n\\end{figure}\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{4_5_confusion}\n  \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 4s and 5s.}\n  \\label{fig:4_5_confusion}\n\\end{figure}\n%\n\\newpage\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{Fisher_Discriminant_Performance_on_Digits_7,_9}\n  \\caption{Classification results for Fisher Discriminant Analysis on 7s vs 9s.}\n  \\label{fig:7_9_bar}\n\\end{figure}\n\\begin{figure}[h!]\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{7_9_confusion}\n  \\caption{A custom confusion-matrix-output from R indicating the classification performance of the Fisher Discriminant on 7s and 9s.}\n  \\label{fig:7_9_confusion}\n\\end{figure}\n\n%\n\\newpage\n\\subsection{Code}\nThe following R code was used to perform the LDA and classification:\n\\begin{verbatim}\n##############\n# STAT775: Machine Learning\n#\n# Exercise 02\n#\n# Using the zip code digit data from the ESL website, use the Fisher\n# Discriminant to perform binary classification between 2s and 3s, 4s and 5s,\n# and 7s and 9s.\n###############\n\n#\n# Initial Setup\n#\nsetwd('C:/Users/Terence/Documents/GitHub/STAT775/HW04')\nFILE.PRE <- 'zip.data/zip'\n\nrdm <- function(relative.file.name, class, extension) {\n  return(data.matrix(read.table(\n    paste(relative.file.name, class, extension, sep = '.'),\n    sep = ',',\n    header = F\n  )))\n}\n\n\nread.data.summary <- function(relative.file.name, class, extension) {\n  data <- rdm(relative.file.name, class, extension)\n\n  mean = data.matrix(colMeans(data))\n  covariance = cov(data)\n\n  summary <- list(freq = nrow(data), mu = mean, sigma = covariance, label = class)\n  return(summary)\n}\n\n\ncompute.data.summary <- function(data, label) {\n  mean = data.matrix(colMeans(data))\n  covariance = cov(data)\n\n  summary <- list(\n    freq = nrow(data),\n    mu = mean,\n    sigma = covariance,\n    label = label\n  )\n  return(summary)\n}\n\n\ngaussian.pdf <- function(x, mu, sigma) {\n  p <- nrow(sigma)\n  sig.ma <- sigma\n\n  det.sigma <- det(sig.ma)\n  if (det.sigma < 0.0001) {\n    sig.ma <- sig.ma + diag(0.0001, nrow(sig.ma), nrow(sig.ma))\n    det.sigma <- det(sig.ma)\n  }\n\n  scale.factor <- 1.0 / sqrt((2 * pi)^p * det.sigma)\n  exponent <- t(x - mu) * solve(sigma) * (x - mu)\n\n  return(scale.factor * exp(exponent))\n}\n\n\nunscaled.naive.bayes.pdf <- function(x, class.info, n.obs) {\n  return(\n    gaussian.pdf(x = x, mu = class.info$mu, sigma = class.info$sigma) *\n    (class.info$freq / n.obs)\n  )\n}\n\n#\n# Classifier Implementation\n#\nlibrary(ppls)  # for vector normalization\n\ncreate.fisher.discriminant.model <-\nfunction(c0, c1, use.naive.db = T, c0.data = NULL, c1.data = NULL) {\n  sigma.sum <- (c0$sigma + c1$sigma)\n  if (abs(det(sigma.sum)) < 0.001) {\n    sigma.sum <- sigma.sum + diag(0.1, nrow = nrow(sigma.sum))\n  }\n  fisher.discriminant <- normalize.vector(solve(sigma.sum) %*% (c0$mu - c1$mu))\n\n  discriminant.c0 <- NULL\n  discriminant.c1 <- NULL\n  decision.boundary <- NULL\n  if(use.naive.db) {\n    discriminant.c0 <- c0\n    discriminant.c1 <- c1\n    decision.boundary <- t(fisher.discriminant) %*% (0.5 * (c0$mu + c1$mu))\n  } else {\n    projected.data <- t(t(fisher.discriminant) %*% t(c0.data))\n    discriminant.c0 <- list(\n      mu = mean(projected.data),\n      sigma = var(projected.data),\n      freq = c0$freq,\n      label = c0$label\n    )\n    projected.data <- t(t(fisher.discriminant) %*% t(c1.data))\n    discriminant.c1 <- list(\n      mu = mean(projected.data),\n      sigma = var(projected.data),\n      freq = c1$freq,\n      label = c1$label\n    )\n    sigma.ratio <- (discriminant.c1$sigma / discriminant.c0$sigma)\n    k <- sqrt(log(sigma.ratio)) * sigma.ratio\n    decision.boundary <- (k * (discriminant.c0$mu - discriminant.c1$mu)) / (k - 1)\n  }\n\n  model <- list(\n    fd = fisher.discriminant,\n    db = decision.boundary,\n    c0 = discriminant.c0,\n    c1 = discriminant.c1\n  )\n  return(model)\n}\n\nfisher.predict <- function(model, x, use.naive.db = T) {\n  projection <- t(model$fd) %*% data.matrix(x)\n\n  if (use.naive.db) {\n    if (projection > model$db) {\n      return(model$c0$label)\n    } else {\n      return(model$c1$label)\n    }\n  } else {\n    if (unscaled.naive.bayes.pdf(c0) - unscaled.naive.bayes.pdf(c1) > 0) {\n      return(model$c0$label)\n    } else {\n      return(model$c1$label)\n    }\n  }\n}\n\n#\n# Classifier Testing\n#\nfisher.discriminant.test <-\nfunction(c0.summary, c1.summary, test.data, test.labels) {\n  model <- create.fisher.discriminant.model(c0 = class.0, c1 = class.1)\n\n  classification.results <- matrix(\n    data = 0,\n    nrow = 2,\n    ncol = 2,\n    dimnames = list(\n      c(c0.summary$label, c1.summary$label),\n      c(c0.summary$label, c1.summary$label)\n    )\n  )\n\n  for (i in 1:length(test.labels)) {\n    classified.as <- fisher.predict(model, test.data[i, ])\n    previous <- classification.results[test.labels[[i]], classified.as]\n    classification.results[test.labels[[i]], classified.as] <- previous + 1\n  }\n\n  return(classification.results)\n}\n\nprint.confusion.result <- function(confusion.matrix) {\n  print(' Confusion Matrix Results', quote = F)\n  print(' ~~~~~~~~~~~~~~~~~~~~~~~~', quote = F)\n  print(confusion.matrix)\n  print('', quote = F)\n  print('   (Actual Class x Predicted Class)', quote = F)\n  print('---------------------------------------', quote = F)\n\n  class.totals <- rowSums(confusion.matrix)\n  for (i in 1:length(class.totals)) {\n    correct.rate <- confusion.matrix[i, i] / class.totals[[i]]\n    class.result.str <- sprintf(\n      '   Class %s: %.2f%% correctly classified, %.2f%% misclassified',\n      row.names(confusion.matrix)[[i]],\n      correct.rate * 100,\n      (1 - correct.rate) * 100\n    )\n    print(class.result.str, quote = F)\n  }\n}\n\nplot.fisher.test.result <- function(confusion.matrix) {\n  names <- row.names(confusion.matrix)\n  totals <- rowSums(confusion.matrix)\n  rates <- list()\n  rates[[1]] <- confusion.matrix[1, 1] / totals[[1]]\n  rates[[2]] <- confusion.matrix[1, 2] / totals[[1]]\n  rates[[3]] <- confusion.matrix[2, 2] / totals[[2]]\n  rates[[4]] <- confusion.matrix[2, 1] / totals[[2]]\n\n  plot.data <- data.frame(\n    'Actual' = c(names[[1]], names[[1]], names[[2]], names[[2]]),\n    'Predicted' = c(names[[1]], names[[2]], names[[2]], names[[1]]),\n    'Rate' = c(rates[[1]], rates[[2]], rates[[3]], rates[[4]])\n  )\n\n  require(ggplot2)\n  plot.title <- paste(\n    'Fisher Discriminant Performance on Digits ',\n    paste(names[[1]], names[[2]], sep = ', '),\n    sep = ''\n  )\n  result.plot <- ggplot(\n    data = plot.data,\n    aes(x=Actual, y=Rate, fill=Predicted)\n    ) +\n    geom_bar(\n      colour = 'black',\n      stat = 'identity',\n      position = position_dodge(),\n      size = .3\n    ) +\n    scale_fill_hue(name='Classified As') +\n    scale_y_continuous(limits = c(0, 1), breaks = seq(0, 1, 0.025)) +\n    xlab('Actual Class') +\n    ylab('Classification Rate') +\n    ggtitle(plot.title) +\n    theme_bw()\n\n  ggsave(\n    plot = result.plot,\n    filename = paste(gsub(' ', '_', plot.title), 'png', sep = '.')\n  )\n}\n\n#\n# The Whole Shebang\n#\nzip.train <- (read.table(\n  file = 'zip.data/zip.train',\n  header = F\n))\n\nzip.test <- (read.table(\n  file = 'zip.data/zip.test',\n  header = F\n))\n\ntrials <- list(\n  list(2, 3),\n  list(4, 5),\n  list(7, 9)\n)\n\nfor (trial in trials) {\n  class.0.data <- data.matrix(subset(zip.train, V1 == trial[[1]]))[, -1]\n  class.1.data <- data.matrix(subset(zip.train, V1 == trial[[2]]))[, -1]\n\n  class.0 <- compute.data.summary(data = class.0.data, label = as.character(trial[[1]]))\n  class.1 <- compute.data.summary(data = class.1.data, label = as.character(trial[[2]]))\n\n#   model <- create.fisher.discriminant.model(\n#     c0 = class.0,\n#     c1 = class.1\n#   )\n  model <- create.fisher.discriminant.model(\n    c0 = class.0,\n    c1 = class.1,\n    use.naive.db = F,\n    c0.data = class.0.data,\n    c1.data = class.1.data\n  )\n\n  test.set <- data.matrix(subset(zip.test, V1 == trial[[1]] | V1 == trial[[2]]))\n  test.data <- test.set[, -1]\n  test.labels <- lapply(as.list(test.set[, 1]), as.character)\n\n  confusion.matrix <- fisher.discriminant.test(\n    c0.summary = class.0,\n    c1.summary = class.1,\n    test.data = test.data,\n    test.labels = test.labels\n  )\n\n  print.confusion.result(confusion.matrix)\n  plot.fisher.test.result(confusion.matrix)\n}\n\\end{verbatim}\n\n\\end{document}\n", "meta": {"hexsha": "2a47fbd009b7a0904de40a8374405302cdc613ff", "size": 15835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "STAT775/HW04/HW04.tex", "max_stars_repo_name": "T-R0D/Past-Courses", "max_stars_repo_head_hexsha": "0edc83a7bf09515f0d01d23a26df2ff90c0f458a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2017-03-13T17:32:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T16:51:22.000Z", "max_issues_repo_path": "STAT775/HW04/HW04.tex", "max_issues_repo_name": "T-R0D/Past-Courses", "max_issues_repo_head_hexsha": "0edc83a7bf09515f0d01d23a26df2ff90c0f458a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-29T19:54:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-29T19:54:52.000Z", "max_forks_repo_path": "STAT775/HW04/HW04.tex", "max_forks_repo_name": "T-R0D/Past-Courses", "max_forks_repo_head_hexsha": "0edc83a7bf09515f0d01d23a26df2ff90c0f458a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2016-10-18T03:31:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-29T13:23:10.000Z", "avg_line_length": 36.0706150342, "max_line_length": 898, "alphanum_fraction": 0.6678875908, "num_tokens": 4722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.6019090145823469}}
{"text": "\\documentclass[letterpaper, twoside, 12pt]{book}\n\\usepackage{packet}\n\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\n\\chapter{Part 2.3: Sections 14.4-14.6}\n\n\\setcounter{chapter}{14}\n\\setcounter{section}{3}\n\n\\section{Tangent Planes and Linear Approximations} %14.4\n\n\\begin{definition}\n  A \\textbf{normal vector} to a surface is a vector normal to\n  any vector tangent to a curve on the surface.\n\\end{definition}\n\n\\begin{theorem}\n  Let $f(x,y)$ be a function of two variables with continuous partial\n  derivatives, and let $(a,b)$ be a point in the interior of $f$'s\n  domain. Then $\\<f_x(a,b),f_y(a,b),-1\\>$ is normal to the surface\n  at the point $(a,b,f(a,b))$.\n\\end{theorem}\n\n          \\begin{problem}\n            OPTIONAL. Prove the previous theorem by using the curves\n            $\\vect{r}(t)=\\<a,t,f(a,t)\\>$ and\n            $\\vect{q}(t)=\\<t,b,f(t,b)\\>$ to yield the tangent vectors\n            $\\<0,1,f_y(a,b)\\>$ and $\\<1,0,f_x(a,b)\\>$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\n  The \\textbf{tangent plane} to a surface at a point is the plane passing\n  through that point sharing the same normal vectors as the surface.\n\\end{definition}\n\n\\begin{theorem}\n  The tangent plane to the surface $z=f(x,y)$ above the point $(a,b)$\n  is given by the equation\n    \\[\n      z = f(a,b) + f_x(a,b)(x-a)+f_y(a,b)(y-b)\n    \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove the previous theorem.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Find an equation for the plane tangent to the surface\n            $z=4x^2+y^2$ above the point $(1,-1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{definition}\n  The \\textbf{linearization} $L(x,y)$ of a function $f(x,y)$\n  at the point $(a,b)$ is given by the formula:\n  \\[\n    L(x,y) = f(a,b)+f_x(a,b)(x-a)+f_y(a,b)(y-b)\n  \\]\n\\end{definition}\n\n\\begin{definition}\n  A function $f$ is \\textbf{differentiable} at a point if its linearization\n  at that point approximates the value of the function nearby.\n\\end{definition}\n\n\\begin{remark}\n  Basically, a differentiable function is one which looks similar to\n  its tangent planes when zoomed in sufficiently far.\n\\end{remark}\n\n          \\begin{problem}\n            Approximate the value of the differentiable function\n            $f(x,y)=4xy+3y^2$ at $(1.1,-2.05)$ by using its linearization\n            at the point $(1,-2)$.\n            Then use a calculator to approximate $f(1.1,-2.05)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\n\\section{The Chain Rule}%14.5\n\n\\begin{definition}\n  The \\textbf{gradient} of a multi-variable function is the vector containing\n  all its partial derivatives:\n    \\[\n      \\nabla f = \\<f_x,f_y\\>\n    \\]\n    \\[\n      \\nabla g = \\<g_x,g_y,g_z\\>\n    \\]\n\\end{definition}\n\n          \\begin{problem}\n            Compute the gradient of the function $f(x,y,z)=4x\\cos z-y^2$.\n            Then compute its value at the point $(1,-2,0)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{remark}\n  If $f(P)$ is a function of multiple variables, and\n  $\\vect{r}(t)$ is a vector function of $t$, then\n  $f(\\vect{r}(t))$ is a function of $t$.\n\\end{remark}\n\n          \\begin{problem}\n            Let $f(x,y)=x^2y+3y^2$ and\n            $\\vect{r}(t)=\\<x(t),y(t)\\>=\\<t+1,\\sqrt{t}\\>$.\n            Write $f(\\vect{r}(t))$ in terms of $t$ only, then\n            compute $\\frac{df}{dt}$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{remark}\n  The chain rule for single-variable functions may be written as\n  \\[\n    \\frac{d}{dx}\\left[f(u(x))\\right]\n      =\n    \\frac{df}{dx}\n      =\n    \\frac{df}{du}\n    \\frac{du}{dx}\n      =\n    f'(u(x))\n    u'(x)\n  \\]\n\\end{remark}\n\n\\begin{theorem}\n  Let $f(P)$ be a function of multiple variables and $\\vect{r}(t)$\n  be a function of $t$. Then the derivative of $f$ with respect to $t$\n  may be computed using the \\textbf{Chain Rule}:\n  \\[\n    \\frac{d}{dt}\\left[f(\\vect{r}(t))\\right]\n      =\n    \\frac{df}{dt}\n      =\n    \\nabla f\n    \\cdot\n    \\frac{d\\vect{r}}{dt}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Let $f$ and $\\vect{r}$ be defined as in the previous problem.\n            Use the Chain Rule to compute $\\frac{df}{dt}$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Let $f(x,y,z)=xyz^2$, $x(t)=2t+1$, $y(t)=t^2+1$,\n            and $z(t)=1-t^3$.\n            Compute $\\frac{df}{dt}$ at $t=1$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\begin{theorem}\n  Suppose $f(x,y)=c$ defines $y$ as a function of $x$. Then\n  \\[\n    \\frac{dy}{dx} = -\\frac{f_x}{f_y}\n  \\]\n\\end{theorem}\n\n          \\begin{problem}\n            Prove the previous theorem. (Part of the solution has\n            been provided for you.)\n          \\end{problem}\n\n          \\begin{solution}\n            Let $y(x)$ be the function defined by $f(x,y(x))=c$, and\n            then let $t=x$. It follows that\n            $f(t,y(t))=f(\\vect{r}(t))=c$, so by the Chain Rule,\n            \\[\n              \\frac{d}{dt}[f(\\vect{r}(t))]=\\frac{d}{dt}[c]\n            \\]\n            \\[\n              \\dots\n            \\]\n            Since $\\frac{dy}{dt}=-\\frac{f_x}{f_y}$ and $t=x$, we conclude that\n            $\\frac{dy}{dx}=-\\frac{f_x}{f_y}$.\n          \\end{solution}\n\n          \\begin{problem}\n            Find the rate of change $\\frac{dy}{dx}$ for\n            $xy^2=3x-2y$ at $(-1,3)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\n\\section{Directional Derivatives and the Gradient Vector}%14.6\n\n\\begin{definition}\n  Let $\\vect{u}$ be a direction. The\n  \\textbf{derivative of $f$ in the direction $\\vect u$}, denoted\n  $D_{\\vect{u}}f$, is given by $\\frac{df}{ds}$ where $s$ is the\n  arclength parameter for the line oriented in the direction $\\vect{u}$.\n\\end{definition}\n\n\\begin{theorem}\n  The directional derivative is the dot product of the gradient\n  vector and $\\vect{u}$:\n  \\[\n    D_{\\vect{u}}f = \\nabla f \\cdot \\vect{u}\n  \\]\n\\end{theorem}\n\n\\begin{remark}\n  The proof of the previous theorem follows from the fact that if\n  $\\vect{r}$ is the line oriented in the direction $\\vect{u}$, then\n  $\\frac{df}{ds}=\\nabla f \\cdot \\frac{d\\vect{r}}{ds}$ and\n  $\\frac{d\\vect{r}}{ds}=\\vect{u}$.\n\\end{remark}\n\n          \\begin{problem}\n            Find the rate of change of $f(x,y,z)=xz^3+3yz$ in the direction\n            $\\vect{u}=\\<\\frac{1}{3},-\\frac{2}{3},\\frac{2}{3}\\>$\n            at the point $P_0=(-2,0,1)$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Find the rate of change of $f(x,y)=xy^2+3y$\n            in the direction of $\\vect{A}=\\<2,2\\>$\n            at the point $P_0=(2,0)$. (Note that $\\vect{A}$ isn't\n            a unit vector, so you'll need to find its direction first.)\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n          \\begin{problem}\n            Show that the rate of change of $f$ in the direction of\n            $\\vecj$ is same thing as the partial derivative of $f$\n            with respect to $y$.\n          \\end{problem}\n\n          \\begin{solution}\n\n          \\end{solution}\n\n\\end{document}", "meta": {"hexsha": "64a5f56eecc9f5a7de92bcc58e8956c274874416", "size": 7366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packet2_3.tex", "max_stars_repo_name": "StevenClontz/teaching-2015-spring", "max_stars_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packet2_3.tex", "max_issues_repo_name": "StevenClontz/teaching-2015-spring", "max_issues_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packet2_3.tex", "max_forks_repo_name": "StevenClontz/teaching-2015-spring", "max_forks_repo_head_hexsha": "f0f09d6cc9420d643f8ea446e57cb09dd6512843", "max_forks_repo_licenses": ["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.4964028777, "max_line_length": 78, "alphanum_fraction": 0.5548465925, "num_tokens": 2269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.6019090058438882}}
{"text": "%\\section{Mathematical Modeling}\n\\label{sec:mathmodel}\n\n% \\begin{itemize}\n% \\item \\st{unstable stratified boundary layers (raleigh number estimate)}\n% \\item \\st{justify incompressible N-S}\n% \\item \\st{justification of far-field eddy-viscosity model (M-O)}\n% \\item modeling eddy-viscosity in device \n% \\item vane and turbine representation via penalty function // immersed boundary method\n% \\item cone representation\n% \\end{itemize}\n\n%remember that \\st{} is strikethrough\n%\n% should this all be math modeling?\n%\n\nThe aim of this work is to simulate synthetic\ndust devils in the field. This requires a model of the ambient\nconditions for a representative case, such as Arizona, where\nexperimental data is available from tests that have been\nperformed. Furthermore, for this to be generally useful in the\nprediction of flows in a variety of conditions, we need a model\napplicable to any flow near the surface of the earth.  \n\nThis chapter details an analysis of surface fluid mechanics, and\ndevelops a mathematical model for turbulence in a thermally stratified\nmedium. We seek to emulate the operation of the apparatus during the\nday, when dust devils are observed to form readily. \nAt these times, the atmospheric surface layer has the following\ncharacter. Incident radiation from the Sun does not significantly\ninteract with the air, which is nearly\ntransparent\\cite{haltiner1957dynamical}. Instead, this radiation is\nabsorbed by the ground, which causes its temperature to rise. This\nresults in a temperature difference between the hot ground and the cooler\nair. The ground heats the air, causing expansion and lowering the density\nof the air. This reduced density air near the surface is then driven\nupwards by buoyancy.    \n\nFor sufficiently large temperature differences, the hot surface layer is\nunstable, and as the warm air is driven upwards the flow will transition\nto turbulence. For the typical use case we consider, namely Arizona in\nsummer, the temperature difference can be in excess of 30 Kelvin. \nRayleigh numbers associated with temperature differences of this\nmagnitude are between $10^{9} - 10^{11}$ and therefore meets the\ncriterion\\cite{incropera1996fundamentals}  \nfor transition to a turbulent regime. The flow is that of an unstably\nstratified fluid.  \n\nThis chapter begins by describing the governing equations of the system\nof interest. It then proceeds to the development of a viscosity model\nused to resolve the large scale features of the solution. Next, models\nused to represent the vanes and turbine, are introduced.  Finally, the\nmodels for the computational domain extent and the boundary conditions\nare discussed. \n\n%Note that a complete numerical specification of all the model\n%parameters introduced in this chapter are provided in a table in\n%appendix \\ref{app:model_param}.\n\n\\section{The Governing Equations of Fluid Motion}\n\\label{sub_sec:ns_en}\n\nThe equations describing fluid flow with natural convection are,\n\\begin{align}\n  \\frac{\\partial {\\bf u}}{\\partial t} + {\\bf u} \\cdot \\nabla {\\bf u} =& \\,\n  -\\frac{1}{\\rho}\\nabla P + \\nu \\nabla^2 {\\bf u} - {\\bf g} \\frac{T'}{T_0}\n \\label{eq:ns} \\\\\n  \\nabla \\cdot {\\bf u} =& \\, 0 \\label{eq:cont} \\\\\n  \\rho c_p \\frac{\\partial T}{\\partial t} + {\\bf u} \\cdot \\nabla T =& \\, \\nabla\n \\cdot ( k \\nabla T) \\label{eq:ht}\n\\end{align} \nunder the assumption that the temperature variation is small in\ncomparison to the mean temperature of the region. These are the\nincompressible Navier-Stokes equations with the Boussinesq\napproximation\\cite{boussinesq2010théorie}, a representation of buoyancy\ncoupled with the heat equation. Note that in\nEquations~\\ref{eq:ns}-\\ref{eq:ht}, and throughout this document,\nboldface denotes a vector quantity, for example, ${\\bf u} = \\{u,v,w\\}$.  \nFurthermore, these equations ignore the action of the Coriolis force. \nMonin and Obukhov~\\cite{monin1954basic} demonstrated that the Coriolis\nforce is negligible for the surface layer below fifty\nmeters\\footnote{\\normalsize This argument is detailed in\nAppendix~\\ref{appendix:coriolis}.}, a distance well below our region of\ninterest.    \n\nAs discussed above, we anticipate that the flow will be sufficiently\nhigh Reynolds number as to be\nturbulent~\\cite{Reynolds01011883}. Turbulence significantly alters the\ncharacter of the flow,  \nand necessitates either resolving the resulting small scales or\nproviding a model that represents their impact. In this case, \n%a Reynolds Averaged Navier-Stokes (RANS) formulation is used, where \nthe turbulent viscosity and thermal conductivities are permitted to vary in\nspace, and the flow is decomposed into constant laminar\n($\\nu_{l},K_{l}$), varying turbulent ($\\nu_{t},K_{t}$), and vane\n($\\nu_{V},K_{V}$) components, \n\n\\begin{eqnarray}\n \\nu =& \\nu_{l} + \\nu_{t}(z) + \\nu_{V}(r,z), \\label{eqn:visc_tot}\\\\\n K =& K_{l} + K_{t}(z) + K_{V}(r,z). \\label{eqn:therm_tot}\n\\end{eqnarray}\n\nThis is an effective eddy viscosity model\\cite{boussinesq1887}, and the\nsubsequent two sections will elaborate on the spatial dependence and\ncharacter of $\\nu_t$, $K_t$, $\\nu_V$ and $K_V$. The laminar, base\ndiffusivities are $\\nu_l$ and $K_l$, and do not vary in space.  \n\n\\section{Viscosity Model}\n\nWe use the well-known similarity model of Monin and\nObukhov\\cite{monin2007statistical,1990JFM...212..637K} as\na guide to the specification of an eddy viscosity model to describe the\nvertical mixing in the atmosphere.\nThis formulation is an extension of\nthe mixing-length model of Prandtl, where the concepts of gradient\ndiffusion and mixing length were generalized to thermally stratified\nflow. This section details the Monin-Obukhov scaling through the lens \nof dimensional analysis. \n\n%ADD DIMENSIONS TO MAKE SCALING MORE CLEAR\\todo{add dimensions}\n%\n% justify prandtl assumption here\n%\n\nMonin and Obukhov argued that under statistically stationary, horizontally\nhomogeneous conditions, the dynamics of any mean turbulent quantity\n($\\bar f$) in a thermally stratified medium depend only on,  \n\n\\begin{equation}\n%\\bar f = f(z,\\frac{g}{T_0},\\rho_0,\\nu_l,K_l,u^*,q,c_p).\n\\bar f = f(z,\\frac{g}{T_0},\\nu_l,K_l,u^*,\\rho_0,\\frac{q}{\\rho_0 \\, c_p}).\n\\end{equation}\nAside from near the surface, the laminar diffusivities $\\nu_l$ \nand $K_l$ will be  \nsmall compared to their turbulent counterparts, $\\nu_t$ and $K_t$, and \nare therefore negligible. \nThe remaining parameters are: the distance from the ground, z; the\nbuoyancy coefficient, $\\frac{g}{T_0}$; \nthe density of the fluid, $\\rho_0$; \na velocity scale, $u^*$ (in particular, the freestream\nvelocity); and the turbulent heat flux to the ground, $\\frac{q}{\\rho_0 c_p}$. \n%and the specific heat,\n%$c_p$. %\\todo{is this right?} \n% Likewise, if we define $z-z_0$ as an ``effective roughness\n% height'' or displacement distance, we can reasonably neglect $z_0$ from these\n% considerations. While the roughness height can be large (for instance in\n% a cornfield, where the roughness height could reasonably be several\n% meters), for the present study the expectation is that this roughness\n% height will be on the order of centimeters\\cite{oke1987boundary}, and\n% therefore negligible.  \n%\n% add refence to dynamical and physical meteorology \n% \nThese primary quantities have the following dimensions,\n\n\\begin{eqnarray}\n \\textbf{Height:}& z\\enskip \\dot = \\enskip [m]  \\\\\n \\textbf{Buoyancy:}& \\qquad \\frac{g}{T_0}\\enskip \\dot = \\enskip [kg] [m] [s]^{-2}\n  [K]^{-1} \\\\ \n \\textbf{Velocity:}& \\enskip u^* \\enskip \\dot = \\enskip [m] [s]^{-1} \\\\\n  \\textbf{Density:}&  \\enskip \\rho_0 \\enskip \\dot = \\enskip [kg] [m]^{-3}  \\\\\n \\textbf{Heat Flux:}& \\enskip \\frac{q}{\\rho_0 c_p} \\enskip \\dot = \\enskip [K] [m]^{-1} [s]^{-1} \\\\\n % \\textbf{Heat Flux:}& \\enskip q \\enskip \\dot = \\enskip [kg] [s]^{-3} \\\\\n % \\textbf{Specific Heat:}& \\enskip c_p \\enskip \\dot = \\enskip [m]^2 [s]^{-2} [K]^{-1} \n\\end{eqnarray}\n\nThe unknown mean turbulent quantity ($\\bar f$) depends on four\ndimensions: length, time, temperature and mass. Dimensional analysis\nimplies that this should then only be a function of a single dimensionless\ngroup\\cite{munson2012fundamentals}. This is chosen to be,\n\\begin{equation}\n \\xi = -\\frac{\\kappa \\frac{g}{T_0} \\frac{q}{c_p \\rho_0} z}{ {u^*}^3}.\n\\end{equation}\nwhere $\\kappa$ is the (dimensionless) von Karman constant. \nThe physical meaning of this quantity bears some discussion.  \nThe numerator, $\\kappa \\frac{g}{T_0} \\frac{q}{c_p \\rho_0} $, is\nproportional to the buoyant production of kinetic energy.  The\ndenominator, $\\frac{{u^*}^3}{z}$, is a shear production rate. \n%\nThe non-dimensional group $\\xi$ is typically cast into the following \nform, \n\\begin{equation}\n \\xi = \\frac{z}{L_{M-O}},\n\\end{equation}\nwhere $L_{M-O}$ is the famous, ``Monin-Obukhov'' length,\n\\begin{equation}\n L_{M-O} = -\\frac{{u^*}^3}{\\kappa \\frac{g}{T_0} \\frac{q}{c_p \\rho_0}}. \n  \\label{eqn_mo_length}\n\\end{equation}\n%\nThis length can be interpreted as the vertical location\nwhere the production of buoyantly generated kinetic energy is\napproximately equal to the energy generated by wind shear. When the\nmagnitude of $L_{M-O}$ is large, the flow is dominated by shear effects,\nand the impact of buoyancy is small. Conversely, a small magnitude of\n$L_{M-O}$ implies that buoyant effects largely dominate the kinetic\nenergy production. Notice also that the sign convention in Equation\n\\ref{eqn_mo_length} is such that for the systems we consider ($q > 0$, heat\nflux from the surface to the air), $L_{M-O}$ will always be\nnegative. This is as expected, as the convection from the high\ntemperature surface to cooler air is unstable. \nThe scenarios considered in this document are for $\\xi<0$, which\ncorresponds to heat flux from the ground into the air. \n\n%The mean quantity $\\bar f$ has a\n%functional representation to the effect,\nThe results of the scaling analysis imply that appropriately normalized\nmean turbulent quantities should be functions only of a single \nnon-dimensional group, \n\\begin{equation}\n \\frac{\\bar f}{f_{MO}} = \\phi(\\frac{z}{L_{M-O}}), \n\\end{equation}\nwhere $f_{MO}$ is a normalizing constant with units of $\\bar f$, and\n$\\phi$ is a function only of $\\xi$. \nMonin-Obuhkov similarity theory has been shown to apply to a wide variety of\nquantities\\cite{wyngaard2010turbulence}, but we consider the velocity \nand temperature fields here. For instance, the mean velocity field would\nhave scaling, $\\frac{u^*}{\\kappa}$ and the temperature fields would be\nscaled as $T^* = \\frac{1}{\\kappa u^*} \\frac{q}{c_p \\rho_0}$. In this\nway, the mean velocity and temperature fields would have the form,  \n\\begin{eqnarray}\n\\bar u(z) = \\frac{u^*}{\\kappa} \\phi_u(\\frac{z}{L_{M-O}}), \\\\\n\\bar T(z) = T^* \\phi_T(\\frac{z}{L_{M-O}}).\n\\end{eqnarray}\nTaking the derivative of these equations results in the mean \nvertical gradients of the velocity and temperature, which are,\n\\begin{eqnarray}\n\\frac{\\partial \\bar u(z)}{\\partial z} = \\frac{u^*}{\\kappa \\, L_{M-O}}\n \\varphi_u(\\frac{z}{L_{M-O}}) \\label{eq:uz}, \\\\ \n\\frac{\\partial \\bar T(z)}{\\partial z} = \\frac{T^*}{L_{M-O}}\n \\varphi_T(\\frac{z}{L_{M-O}}) \\label{eq:tz}.\n\\end{eqnarray}\nWhere $\\phi$ and $\\varphi$ are different (and unknown) universal functions. Eddy\nviscosity is defined as, $u'v' = \\nu_t \\frac{\\partial\nu}{\\partial z}$\\cite{durbin2001statistical}, in which case, using\nequation \\ref{eq:uz}, it can be expressed as, \n\\begin{equation}\n \\nu_t = \\frac{{u^*}^2}{\\frac{\\partial \\bar u}{\\partial z}} = \\frac{u^* \\,\n  \\kappa \\, L_{M-O}}{\\varphi_u(\\xi)}.\n\\end{equation}\nWhile the eddy thermal diffusivity (defined as, $q = c_p \\rho_0 K_T\n\\frac{\\partial T}{\\partial z}$) is,\n\\begin{equation}\n K_t = \\frac{q/c_p \\rho_0}{\\frac{\\partial \\bar T}{\\partial z}} = \\frac{u^* \\,\n  \\kappa \\, L_{M-O}}{\\varphi_T(\\xi)}.\n\\label{eqn:eddy_kt}\n\\end{equation}\nNote that while we have not assumed that $\\varphi_u$ and\n$\\varphi_T$ are identical, for turbulent Prandtl numbers of unity \n(e.g. $Pr_t = 1$), they will be. We now consider the asymptotic behavior\nof $\\varphi_T$ and $\\varphi_u$ at large and small values of $\\xi$\nto provides guidance as to the more general character of the functions. \n\n%Our interest lies in the case where $L_{M-O} \\leq 0$, which corresponds\n%to heat flux from the ground into the air.  \n%\n\n\\subsection*{Case One: $\\xi \\to 0$}\nThe first case is the limit\n%, is equivalent to the scenario where\n%$\\frac{z}{L_{M-O}} \\to 0$, or \n$L_{M-O}>>z$, $\\xi \\to 0$. This occurs as the heat flux\nat the wall approaches zero (e.g. $q \\to 0$). \nThis is purely wind driven flow with no thermal variation. \nIn this limit, the profile is expected to be the ``log-law''. \nEquation~\\ref{eq:uz} can be rearranged to obtain, \n%\\begin{equation}\n% \\frac{\\partial \\bar u(z)}{\\partial z} = \\frac{u^*}{\\kappa L_{M-O}} \\varphi_u(\\frac{z}{L_{M-O}}).\n%\\end{equation}\n%After substituting $L_{M-O}=\\frac{z}{\\xi}$, \n\\begin{equation}\n \\frac{\\partial \\bar u(z)}{\\partial z} = \\frac{u^*}{\\kappa z} \\xi \\varphi_u(\\xi).\n\\end{equation}\n%This is clearer if the substitution, $\\Phi(\\xi) = \\xi \\, \\varphi(\\xi)$, is made,\n%\\begin{equation}\n% \\frac{\\partial \\bar u(z)}{\\partial z} = \\frac{u^*}{\\kappa z} \\Phi(\\xi).\n%\\end{equation}\nIn the log-layer, \n\\begin{equation}\n \\frac{\\partial \\bar u(z)}{\\partial z} = \\frac{u^*}{\\kappa z},\n\\end{equation}\nif $u^*$ is the friction velocity, $u_{\\tau}$. \n%One can now more easily see that this function results in a logarithmic\n%profile when $\\Phi(\\xi) = 1$, which in turn implies that for \nTherefore, for neutral stratification $(\\xi = 0)$, \n\\begin{equation}\n \\lim_{\\xi \\to 0} \\, \\xi \\, \\varphi(\\xi)= 1. \n\\end{equation}\n%We expect this to be approximately true for all small values of\n%$\\xi$, e.g. \nWhen $ |\\frac{z}{L_{M-O}}| << 1$ it is therefore expected that,\n\\begin{equation}\n \\varphi_u(\\xi) \\approx \\text{ln } \\rvert \\frac{z}{L_{M-O}} \\rvert + C.\n\\end{equation}\nIdentical arguments can be made for the asymptotic \nbehavior of the temperature function.\n\n\\subsection*{Case Two: $\\xi \\to -\\infty$}\n\nThe case where $\\xi \\to -\\infty $ implies $z>>L_{M-O}$.  \nThis is most readily interpreted as the instance\nwhere $u^* \\to 0$, e.g. the buoyancy-dominated case with no wind\n(free-convection). This condition is typically referred to as,\n``Thermal-only'' in this text. \n% hacking\n%\nFor Equation~\\ref{eq:tz} to be non-trivial (and\nnon-singular) in the limit as $\\xi \\to -\\infty$, it must have no\ndependence on $u^*$. A glance at this equation shows that\n$T^* \\thicksim \\frac{1}{u^*}$, and $L \\thicksim\n{u^*}^{3}$. The non-dimensional scale, $\\xi$, includes a\n$(u^*)^{-3}$ factor through the dependence on the M-O length, \n$L_{M-O}$, in the denominator. \nTherefore, the overall function will not depend on $u^*$ only when\nthe function $\\varphi$ is proportional to  $\\xi^{-\\frac{4}{3}}$. \n\nThis means that the gradient in temperature has the following form,\n\\begin{equation}\n\\frac{\\partial \\bar T(z)}{\\partial z} = -C_T \\left(\\frac{q}{c_p \\,\n\t\t\t\t\t      \\rho_0}\\right)^\\frac{2}{3}\n\\left( \\frac{g}{T_0} \\right)^{-\\frac{1}{3}} z^{-\\frac{4}{3}}  \\text{\nfor } z \\gg L.\n\\end{equation}\n\nWhere $C_T$ is some unknown multiplicative scaling constant. \n% hacking ends\nUsing this information in Equation~\\ref{eqn:eddy_kt} provides an\nexpression for the asymptotic behavior of the thermal diffusivity, \n\\begin{equation}\n K_t = -\\frac{q}{c_p \\, \\rho_0 \\, \\frac{\\partial \\bar T(z)}{\\partial z}}\n  = \\frac{1}{C_T} \\left( \\frac{q}{c_p \\rho_0} \\frac{g}{T_0}\n\t\t     \\right)^\\frac{1}{3} z^{\\frac{4}{3}}  \\text{ \nfor } z \\gg L_{M-O}. \n\\end{equation}\n\nSo long as the turbulent Prandtl number remains constant in space, a\nreasonable assumption~\\cite{chuang1969turbulent}, then \nidentical arguments regarding the asymptotic behavior at large $\\xi$\nprovide the analogous result for the eddy viscosity's variation with\nrespect to distance from the ground,   \n\\begin{equation}\n \\nu_t = \\frac{1}{C_{\\nu_t}} \\left( \\frac{q}{c_p \\rho_0} \\frac{g}{T_0}\n\t\t\t     \\right)^\\frac{1}{3} z^{\\frac{4}{3}}  \\text{ \nfor } z \\gg L_{M-O}. \n\\end{equation}\n\n\n\\subsection*{Approximations of the Universal Function}\n\nWe have now derived two criterion that our desired function of $\\xi$ \nmust capture. Namely, that for small values of negative $\\xi$, the\nfunction should be nearly identical to the logarithmic profiles\nassociated with neutral stratification. Secondly, at large negative\nvalues of $\\xi$, the function should go to\n$\\xi^{-\\frac{4}{3}}$. Finally, the function should smoothly vary between\nthese conditions.  \n\nThere are several different functions, which are essentially different\ncalibrations of the same underlying function for different regimes with \nvarying relative merits. \nMost functions are formulated in terms of $\\Phi(\\xi)$, \nnot $\\varphi(\\xi)$. As\n$\\varphi(\\xi) \\thicksim \\xi^{-\\frac{4}{3}}$, and recalling that\n$\\Phi(\\xi) = \\xi \\, \\varphi(\\xi)$, we expect \n$\\Phi(\\xi)$ to scale as $\\xi^{-\\frac{1}{3}}$.\n%\n%\\cite{?}.\\todo{missing cites} \nHowever, the functions are generally in close agreement under neutral\nand unstable conditions, with the disagreement primarily occurring for\n$z/L>0$. As we expect to only simulate conditions of unstable or\nneutrally stratified flow, our choice of interpolation function does not\nhave a significant impact on the predicted value.  \n\n\\begin{figure}[!htb]\n \\centering\n  \\includegraphics[width=.7\\linewidth]{figs/mo-compare}\\\\\n \\caption{Comparison between three common interpolation functions for\n the Monin-Obukhov universal function of momentum. The plots closely\n coincide, as the functions are generally in close agreement under\n neutral and unstable conditions, with the disagreement primarily\n occurring for $\\xi > 0$, which is unimportant for this work.} \n \\label{fig:interp-mo}\n\\end{figure}\n\nFigure~\\ref{fig:interp-mo} shows three common interpolation  \nfunctions, the Businger~\\cite{businger1971flux},\nH{\\\"o}gstr{\\\"o}m~\\cite{hogstrom1988non} and Dyer~\\cite{dyer1974review}\nfunctions. All have similar qualitative form,   \nand yield nearly identical predictions. As a result, we use functions\nthat are simple to compute. The original functions \nproposed by Monin and Obukhov were avoided as they had a discontinuity in\nthe derivative, and are more inaccurate than modern functions due to\nthe fact that they were calibrated on less accurate experimental\ndata. The H{\\\"o}gstr{\\\"o}m functions for momentum and temperature are, \n\\begin{eqnarray}\n  \\Phi_M(\\xi) =& (1-19.3 \\, \\xi)^{-1/4}, \\\\\n  \\Phi_T(\\xi) =& 0.95 \\, (1-11.6 \\,\\xi)^{-1/2}.\n\\end{eqnarray}\nThese functions have been found to be broadly applicable, accurate and \nare easily instantiated in software. For this reason the\nH{\\\"o}gstr{\\\"o}m functions are used in this work. \n\n\\subsection{Shortcomings of Monin-Obukhov Theory}\n\nThere are several well-known conditions for which the Monin\nObukhov similarity theory breaks down. These include:\n \n\\begin{itemize}\n \\item Surfaces with large spatial variations in roughness\n \\item Outside of the surface layer (several hundred meters) where the \n       Coriolis effect is no longer negligible\n%\\item the theory's predictions are well known to be sensitive to choice\n%      of universal function for $L>0$.\n\\end{itemize}\n\nBut neither of these are relevant here. \nIn ``ideal'' situations, the theory has been found to be\naccurate to better than 10\\%\\cite{QJ:QJ49709741204,kaimal}. \nFor our case, with minimal surface roughness and our interest\nconstrained to the near surface layer, these functions are applicable\nand reasonably accurate\\cite{Foken2006}, and are easily implemented in\nsoftware.  \n\n\\section{Eddy Viscosity in the Device}\n\n%However, this is also a more\n%difficult regime to model.\\todo{poor justification} \nThe atmospheric boundary layer model discussed in the previous section\ndoes not account for the presence of the SoV device.\n%The validation process identified a refinement to the virtual vane\n%formulation that results in a better representation of the vane\n%effects in a broader range of flows.\nTo account for this, an augmented turbulent diffusivity \nis used in the vortical plume region to account for the turbulence \nin the device. The diffusivity is enhanced due to vortex shedding from the \ntrailing edge of the vanes, and other effects not \nrepresented in the virtual vane model (discussed in Section~\\ref{subsec:vane}). \n\n% To successfully accomplish this, source terms\n% for production of diffusivity were formulated to properly\n% account for the generation of turbulence in the region of the\n% vanes. This diffusivity would then convect and diffuse through space. \n% To avoid modeling a temporal and three-dimensionally spatially\n% varying field of diffusivities, we have instead calibrated the field\n% based on data provided by our partners at Georgia Tech. \n\n%This calibration\n%is detailed in Section~\\ref{sec:validation}. \nThe eddy-viscosity in the region of the vanes and interior is set\nbased on scaling relations for a turbulent self-similar circular jet, as\ndescribed in Pope\\cite{pope2000turbulent},\n \n\\begin{equation}\n  \\nu_V = U_0 y_{1/2} \\bar \\nu_C.\n  %\\nu_C(r) = U_0(r) y_{1/2}(r) \\bar \\nu_C\n\\end{equation}\n\nIn this equation, $U_0$ is the peak velocity, \nand is set based on the observed\nvelocities that exist in the SoV. \n%\n% In words, we are scaling the\n% calibrated viscosity by the velocity and length scale of the\n% apparatus. $\\bar \\nu_C $ is input, measured from the experimental\n% laboratory.  The diffusivity here is essentially a top hat filter, which\n% radial values interior to the vanes the nominal calibrated value, and\n% those outside the vanes zero, e.g. $\\nu_C(r>r_{\\text{vane}})=0$. \nThe dimensionless constant $\\bar \\nu_C $ was calibrated against\nlaboratory generated experimental data \n(the laboratory experiment is detailed in Section~\\ref{sec:validation}), \nand is set to zero outside the device. \nThe thermal diffusivity inside the device, $K_V$, is then fixed with the \nassumption that the Prandtl number is unity.  \n\nFinally, the length scale $y_{1/2}$ is set either to the \nseparation distance between neighboring vanes, or the radius of the SoV\napparatus. The former is used for the unsteady virtual vanes, when\ngreater spatial and temporal fidelity is required to capture the\ndynamics of the plume and wake. This viscosity is designed to represent\nthe fluctuations inside the device due to separation of flow off the\nturning vanes, for instance. This is in contrast to the case of the\nsteady virtual vanes, where the radius of the SoV apparatus is used as\nthe length scale and no dynamics of the flow are are resolved. Here, the\nresolved scale is that of the vortical plume itself, and not any\nfluctuating quantities. This is principally for design purposes, and is\nintended only to capture the largest scale features of the flow. These\nsimulation regimes are discussed in further detail in\nChapter~\\ref{sec:validation}. \n\n%The thermal and momentum diffusivities are expected to be even larger in the\n%device where the flow across the vanes produces shear and generates\n%turbulence. Our model for the diffusivities inside the vanes should\n%therefore be higher than the ambient regions outside the vanes. \n\n\n\\section{Vane Representation}\n\\label{subsec:vane}\nTo rapidly prototype general system configurations, the\ncomputations must be able to explore a large space of possible\ngeometries and settings. This presents a significant meshing and \ncomputational challenge if the detailed flow around the vanes is to be\ncomputed. In the region near the vanes, where a no-slip boundary\ncondition is imposed, the flow will necessarily form a thin momentum\nboundary layer. Resolving this boundary layer requires high resolutions\nimmediately adjacent to the walls. Changing the vane location requires\nthat a new mesh be generated. This is a significant\nchallenge, as the development of a new mesh often requires significant\nhuman effort and time. Furthermore, the process is error-prone, \nand would require that each simulation using a new mesh undergo \ndetailed solution verification. \n\n\n% Your text on the virtual vanes does not provide enough information to\n% know exactly what we did. It is needlessly vague, and does not\n% adequately connect to the real vane geometry. I propose the following\n% more direct and more precise text. Further, the penalty nomenclature\n% is inappropriate.\n\nInstead, we have developed a modeling formulation that does not require\nexplicitly meshing the turning vanes, or any surface. The primary function\nof the vanes is to turn the flow.\nTherefore, the vanes are represented as a force field, over \nwhich a force is applied to the velocity field to align it \nwith the angle of the turning vanes, defined here as a \nfield of vectors. These so-called `virtual vanes'' are implemented as a\nbody force that is applied in the region that would otherwise contain\nthe vanes.  \n%\n   \\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width =0.47\\textwidth]{figs/gridded_region}\n    \\hfill\n    \\includegraphics[width =0.35\\textwidth]{figs/forcing_region}\n     \\caption{An example of explicitly represented turning vanes (left)\n    versus an annular forcing region (right). $R_{M}$ is the furthest\n    radial extent of the virtual vane forcing, and $R_{m}$ the smallest\n    radial extent. } \n     \\label{fig:penalty_model}\n   \\end{figure}\n%\nVane geometry is specified by the angle $\\phi$ a vane makes with a\nradial line as a function of the radial coordinate, $r$, and the polar\nangle, $\\theta$. A unit normal to the vane surface ${\\bf n_v}$ is defined\nas,\n%\n\\begin{equation}\n {\\bf n_v}({\\bf x}) = \\sin \\left(\\phi(r,\\theta) \\right) \\hat{{\\bf r}}+ \\cos\n  \\left(\\phi(r,\\theta) \\right) \\hat{{\\bf \\theta}},\n\\end{equation}\n%\nwhere $\\hat{{\\bf r}}$ and $\\hat{{\\bf \\theta}}$ are unit\nvectors in the radial and azimuthal directions, respectively.\n\nWith this vane-normal vector field specified, a body force ${\\bf f_v}$\nis defined that will drive the velocity in the ${\\bf n}$ direction\ntoward zero, effectively turning the flow to be parallel to the\nvanes. The body force is defined by,\n\\begin{equation}\n {\\bf f}_v= -\\frac{1}{\\ell_v}|{\\bf u}|\\,({\\bf u}\\cdot{\\bf n_v})\\,{\\bf n_v},\n \\label{eqn:body_force}\n\\end{equation}\nwith ${\\bf u}$ the velocity and $\\ell_v$ is a specified (virtual vane)\nlength scale. The quadratic functional form of this forcing can be\nmotivated by the desire for a dimensionally consistent forcing, which is\nnot possible with only a linear dependence on velocity. The length\nscale, $\\ell_v$, represents the distance over which the \nflow evolves under the influence of the body force before the\nvelocity in the normal direction is reduced by a factor of $1/{\\bf \ne}$. That is, this is the length over which the normal component of the\nvelocity decays exponentially. \n%It is the distance analog to the more\n%familiar time constant of exponential decay. \n\nThe length scale, $\\ell_v$, is a modeling constant and must be\nspecified. This length scale is calibrated to match the annealing\ndistance measured in simulations with explicitly meshed vanes. The\nlength over which the flow comes into alignment with the vane direction\nfor a gridded vane simulation is measured in\nFigure~\\ref{fig:annealing}. This plots the average misfit between the\nturning vane angle and the fluid velocity, measured as the normalized\ndifference between the fluid velocity and the tangent line of the\nturning vanes. A value of one would represent flow that is perpendicular\nto the turning vanes, while a value of zero would represent perfectly\naligned flow.   \n\nThe trend is clear that as the flow moves through the turning vanes\ntowards the center of the apparatus it is brought into alignment with\nthe turning vane direction. Notice that the misfit actually reaches a\nminimum and never comes into complete alignment with the vanes, likely\ndue to unmodeled transient effects such as vortex shedding off the vane\ntrailing edges.  \n\n%Our expectation is that it will be the same order as the separation distance\n%between neighboring vanes in the physical vane configuration, since\n%entry lengths in internal flows scale with the width of the\n%channel. \n\n   \\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width =0.8\\textwidth]{figs/annealing}\n     \\caption{The average misfit between the gridded vanes and the\n    flow. The averaging is accomplished through azimuthal\n    averaging. This was taken at half the height of the turning vanes,\n    although the results do not differ at greater or lower height. \n    The subfigure shows the logarithmic derivative in black and the\n    average of the logarithmic derivative in red. \n    $R_{M}$ is the furthest radial extent of the gridded vanes,\n    and $R_{m}$ the smallest radial extent. The subfigure shows the\n    logarithmic derivative of this quantity in black, and the average\n    value of the logarithmic derivative in red.}\n     \\label{fig:annealing}\n   \\end{figure}\n\nThe value of $\\ell_v$ is calibrated to explicitly match the \nresults of the gridded vanes by assuming that the vane mismatch \nobeys a radial exponential decay of the form $f(r) = A e^{-\\lambda r}$, \nwhere $\\lambda = \\frac{1}{\\ell_v}$.\nTaking the logarithmic derivative of this quantity, \n\\begin{eqnarray}\n \\frac{f'}{f} = \\frac{A e^{-\\lambda r} * -\\lambda}{A e^{-\\lambda r}} =\n  -\\lambda. \n\\end{eqnarray}\n\nThe logarithmic derivative is shown in the \nsubfigure of Figure~\\ref{fig:annealing}. If the misfit between vanes \nwas perfectly described by an exponential decay, the line would be flat. \nWhile the curve does not perfectly coincide with this, the curve does\nnot have severe convexity and the average is sufficient for this\nwork. Based on this, the length scale $\\ell_v$ was set to one third of a\nmeter. For larger or smaller configurations, this value was then scaled \nbased on the total system diameter of the design. \n\n%\\todo{show\n%calibration of this} \n\nThis virtual vane formulation is similar to the ``actuator disk'' model\ncommonly used to represent the rotor of a wind turbine and\ndescribed in the subsequent section. \n\n\\section{Turbine Representation}\n\\label{sec:actuator_disk}\n%\n% https://en.wikipedia.org/wiki/Blade_solidity\n%\n\nThe turbine is modeled similarly to the virtual vanes. As with the\nvanes, it is desirable to avoid explicitly representing the turbine\nblade control surfaces. Instead, the turbine is modeled using the\nactuator disc simplification. \nThis model (also often referred to as a ``Blade Element Momentum''\ntheory) is commonly used in wind\nturbine design\\cite{shevell1983fundamentals,betz,leclerc}. The essence\nof this model is to approximate the individual spinning turbine blades\nas a ``disk'' in which the effects of the turbine are represented by\nbody forces on the fluid, as shown in Figure~\\ref{fig:actuator_disk}.\nThis method assumes an axisymmetric representation of the turbine\ngeometry, and in doing so completely neglects unsteady effects due to\nthe rotation of turbine blades in a plane. \n\nAs the flow moves through the actuator disk, it experiences a force\nnormal to the represented turbine blade surface. This force will\ngenerally be in opposition to the flow direction, and will therefore\nimpart a loss of momentum on the fluid. \nAssociated with the loss of axial and azimuthal momentum is a loss of\nenergy which can be collected by an electrical generator attached\nto the rotor shaft if the rotor experiences a torque\nin the direction of rotation. \n\nAll the turbine cases shown in this study make the further\nsimplification that the rotation speed of the disk is constant. \nIn this way it is assumed that the turbine exerts a torque equal and\nopposite to that of the airflow which keeps the rotational speed\nconstant. The work done by the aerodynamic torque on the\nturbine is assumed to feed into a generator, where it is converted into\nelectrical energy. \n\n\n   \\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width =0.95\\textwidth]{figs/actuator_disk}\n     \\caption{The actuator disk model represents a turbine blade\n    geometry (shown on the left) as a spinning ``disk'' region (shown\n    on the right).}\n     \\label{fig:actuator_disk}\n   \\end{figure}\n\nWe now detail the mathematical machinery necessary to specify the\ndirection and magnitude of force between the turbine and flow. The\nnormal in the blade's velocity direction is, \n\\begin{equation*}\nn_B = \\frac{{\\bf u_B}}{||{\\bf u_B}||}. \n\\end{equation*}\nWhere ${\\bf u_B}$ is the blade velocity vector and is specified. The\nnormal in the fan vertical direction is typically ${\\bf n_f} =\n\\left(0,0,1\\right)$, e.g. pointing ``up''. Then the normal in the radial\ndirection must be,  \n\\begin{equation*}\n{\\bf n_r} = {\\bf n_B} \\times {\\bf n_f}\n\\end{equation*}\n\n% The fan-wing-plane bit means that we're only looking at the projection\n% of velocity into the plane that's defined by the base velocity and\n% vertical direction. \n\n% (01:03:44 PM) Roy Stogner: The \"local relative velocity\" means that\n% we're taking the velocity not in the reference frame of the domain, but\n% in the reference frame of the wing.  So if the base velocity is U_B and\n% the air velocity is U, then the local relative velocity is U - U_B. \n% (01:04:25 PM) Roy Stogner: Note that we simplify that equation a tiny\n% bit by using the fact that U_B and N_R are perpendicular. \n\nand the fan-wing-plane component (e.g. the plane perpendicular to the \nradius) of local relative velocity is\n\\begin{equation}\n%{\\bf u_p} = {\\bf u} - ({\\bf u}\\cdot {\\bf n_r})\\cdot {\\bf n_r} - {\\bf u_B}. \n{\\bf u_p} = {\\bf u} - ({\\bf u}\\cdot {\\bf n_r}) \\, {\\bf n_r} - {\\bf u_B}. \n\\end{equation}\nThis is the projection of velocity into the plane defined by the base\nvelocity and vertical direction. Now the ``forward velocity'' in the\nreference frame of the turbine is,  \n\\begin{equation}\nu_{\\text{fwd}} = -{\\bf u_p} \\cdot {\\bf n_B}\n\\end{equation}\nand the ``upward'' velocity in this frame is, \n\\begin{equation}\nu_{\\text{up}} = {\\bf u_p} \\cdot {\\bf n_f}. \n\\end{equation}\nThe angle with respect to the fan velocity direction is then, \n\\begin{equation}\n% \\theta_f = \\text{atan2}\\left(\\frac{{\\bf u_{\\text{up}}}}{{\\bf\n % u_{\\text{fwd}}}}\\right),\n \\theta_f = \\text{atan2}\\left(\\frac{ u_{\\text{up} }}{\n\t\t\t u_{\\text{fwd}}}\\right), \n %\\theta_f =\n  %\\text{tan}^{-1}\\left(\\frac{u_{\\text{up}}}{u_{\\text{fwd}}}\\right)\n  \\label{eq:fan_direction}\n\\end{equation}\nwhile the angle with respect to the chord is this with the addition of\nthe blade angle relative to the fan vertical direction, \n\\begin{equation}\n \\phi = \\theta_f + \\beta(r).\n\\end{equation}\n\nIn words, the blade angle (or local pitch) is measured from the plane of\nrotation to the chord line (i.e., the straight line connecting leading\nto trailing edge). These parameters, $\\beta$, C, etc. are visually\ndepicted in Figure \\ref{fig:turbine_image}.  \n\nThe actuator disk model assumes that the forces on a blade\nelement can be calculated by means of two-dimensional aerofoil\ncharacteristics using an angle of attack determined from the incident\nresultant velocity in the cross-sectional plane of the element. The\nvelocity component in the span-wise direction is\nignored. Three-dimensional effects are also\nignored\\cite{burton2001wind}.  \n\n  \\begin{figure}[!htb]\n    \\begin{center}\n     \\includegraphics[width = 10 cm]{figs/turbine_image}\n     \\caption{The represented turbine blade\n     geometry. $\\beta$, the blade angle, is measured relative to the\n     horizontal plane. c, the chord length of the turbine, is defined as\n     the straight line distance from leading to trailing edge. } \n     \\label{fig:turbine_image}\n    \\end{center}\n  \\end{figure}\n\n\\subsection{Specification of the Lift and Drag Coefficients}\n\nWe now define the lift and drag normals, where the direction opposing\ndrag is, by definition,  \n\\begin{equation}\n{\\bf n_{\\text{drag}}} = \\frac{{\\bf u_p}}{||{\\bf u_p}||} \n\\end{equation}\nand the direction opposing lift orthogonal to the drag and the radial \ndirection,  \n\\begin{equation}\n{\\bf n_{\\text{lift}}}= {\\bf n_{\\text{drag}}} \\times {\\bf n_r}. \n\\end{equation}\n%\nThen, the force on the turbine is, \n% \\begin{equation}\n%  \\boxed{F = \\frac{1}{2}\\frac{\\rho u_p^2 c}{A}\\left(C_l \\cdot\n% \t\t\t\t\t      n_\\text{lift} + C_d \\cdot\n% \t\t\t\t\t      n_\\text{drag}  \\right)}\n% \\label{eq:force_turb}\n  % \\end{equation}\n\\begin{equation}\n F = \\frac{1}{2} \\rho A_B {\\bf u_p}^2 \\left(C_l \\,\n\t\t\t\t\t      {\\bf n_\\text{lift}} + C_d \\,\n\t\t\t\t\t      {\\bf n_\\text{drag}}  \\right).\n\\label{eq:force_turb}\n\\end{equation}\n$A_B$ is the total area of the turbine blades, so $A_B = B\\, c\\, r$, where B\nis the number of turbine blades and c is the chord length of the\nturbine. \nThe actuator disk is an approximation of the blades as a volumetric\nforcing ``disk'', and so our interest is in this quantity,\n\\begin{equation}\n\\frac{F}{\\text{volume}} = \\frac{F}{\\pi r^2 t} = \\frac{1}{2}\\frac{\\rho\\, B\\, c\\,\n {\\bf u_p}^2}{\\pi r t}\\left(C_l \\, {\\bf n_\\text{lift}} + C_d \\, {\\bf\n\t\t   n_\\text{drag}} \\right).  \n\\label{eq:vol_turb}\n\\end{equation}\nWhere t is the blade thickness of the actuator disk.\nNote that the volume is over a different extent than the area. The\nvolume is for the entire actuator disk, while the force on the blades\nwas only calculated with total surface area of the turbine. \nTo better understand this, note that the product $B c$ appears in\nEquation~\\ref{eq:vol_turb}, above. This quantity impacts the solidity (or\nblockage), and as the chord length or number of blades increases,\nthe total blocked area inside the actuator disk also increases. It is\ninteresting to note that in the actuator disk model, only the product $B c$\nhas impact, and one cannot directly separate the impact of more turbine\nblades versus larger blade chord lengths. \nThe impact of solidity will be discussed in greater detail in\nSection~\\ref{sec:solidity}.\n\nNow, only the drag coefficients ($C_l,C_d$) must be specified to fully\ndetermine the force on the blades. These coefficients are functions of\nthe angle of attack, $\\alpha$. Data for the coefficients was provided\nby Duane McCormick at UTRC and were generated from a 2-D model in\nCOMSOL. As the data was discrete, high order polynomials were used\nto obtain smooth functions fit to the COMSOL data. Typically,\n16\\textsuperscript{th} order polynomials were used to \nensure that the fitted function closely matched the provided\ndata. The drag and lift functions for the three cases considered (flat\nplates, $180^{\\circ}$, $90^{\\circ}$ circles) are shown in \nFigures~\\ref{fig:flat_plate_drag}, \\ref{fig:semi_drag} and\n\\ref{fig:90_drag}. The flat plate drag coefficient is smoothly\nvarying and so the interpolated function is close to the provided\ndata. The semi-circles ($180^{\\circ}$) are largely accurate, but near\nzero degrees the COMSOL data for the lift function shows a sharp feature\nthat is not well resolved by the interpolating polynomial. This is also\nthe case for the quarter-circles, where near a zero angle of attack the\nlift function has a near discontinuity that is not well resolved by the\ninterpolated function. \n\n%The semi-circular plots are more complicated. Here, we use a high order\n%polynomial fit to continuously interpolate between drag polars. \n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/flat}\n    \\caption{The flat plate lift and drag coefficients as a function of the angle of attack, $\\alpha$.} \n    \\label{fig:flat_plate_drag}\n  \\end{center}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/semi}\n    \\caption{The semicircle (180 degree) lift and drag coefficients as a function of the angle of attack, $\\alpha$.} \n    \\label{fig:semi_drag}\n  \\end{center}\n\\end{figure}\n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 12 cm]{figs/90}\n    \\caption{The 90 degree (quarter circle) lift and drag coefficient as a function of the angle of attack, $\\alpha$.} \n    \\label{fig:90_drag}\n  \\end{center}\n\\end{figure}\n\n% what about loads on turbine?\\todo{loads?}\n% Blade torque loads modest, only ~20 ft-lbs\n%% load was predicted at 20 ft*lbs\n\n% lets kill this one\n%\\subsection{Shortcomings of the Actuator Disk Model}\n%\\label{subsec:wake_loss_model}\n\nThe actuator disk model is valuable because of its simplicity, not on\naccount of its accuracy. Despite its pervasive use, there are numerous\nknown inadequacies to the model. \n\n% In particular, the actuator disk does not account for the separation of\n% flow between blades, and implicitly assumes the flow remains attached. \n% This model deficiency results due to the actuator disk\n% method's dependence on the precision of the lift and drag\n% coefficients. During the operation of a wind turbine, should the angle\n% of attack reach high values (post-stall region), then aerodynamic\n% data is not available or inaccurate.  \n% This model inadequacy is commonly fixed with the Glauert Correction. \n% Developed in 1926 by Glauert from helicopters rotor blades, this\n% correction originally was purely based on experimental data. The model\n% was designed to correct the overall thrust coefficient for high angles\n% of attack\\cite{glauert1926general,glauert1935airplane}. \n% While the Glauert correction is a tip loss model, the correction was\n% developed as a correction to an entire rotor disk; the original\n% researcher did not intend it to be applied to a rotor annulus. \n%Given that \n%a duct eliminates tip losses\\todo{write me}\n%However, because of a limited amount of experimental data, an alternative model does not exist.  \n\nFor instance, the model's described above account for the turbulent wake\nstate, which in some cases have been shown to be significant for a wind\nturbine\\cite{churchfield2012numerical} and may have substantial impact\non the SoV. \n\nVarious researchers\\cite{Moriarty_aerodyntheory,wilson1978design} have\nsuggested various other corrections to actuator-disk theory. These\ncorrections include (among others) accounting for blade thickness on\nlocal angle of attack, cascade width for high solidity turbines, and\nspanwise gaps for partial span pitch control. The impact of these\nmissing physics can be significant, for instance, blade thickness\ncan be aerodynamically significant near the rotor hub and may \naffect the in-plane forces on the rotor. Nevertheless,\nthese corrections are not treated in the simulations presented in this\ndocument. \n\nIn summary, the actuator disk is a useful modeling tool for this study\nbut does not represent a high-fidelity representation of the turbine\nblade dynamics, and should not be considered highly accurate. Attempts\nto evaluate and characterize these shortcomings are detailed in\nChapter~\\ref{sec:field}.  Additionally, a new modification to the\nactuator disk that modifies the model to further account for blade\nsolidity is demonstrated in this work in Section~\\ref{sec:solidity}. \n\n\\section{Solid Surface Representation}\n\\label{subsec:solid_surface}\n\nIn addition to vanes, the SoV device includes impermeable surfaces\nsuch as the wind break (``cone'') on the top of the facility. As with\nthe turning vanes, this is represented without explicitly meshing the\nsurface nor imposing  a boundary condition at the surface. This allows\nrapid exploration of configurations  with different solid surfaces to\ncontrol and manipulate the fluid flow. These solid surfaces are\nrepresented by a body force acting in a region surrounding the wall. \nA body force normal to the surface is defined in this region so\nthat it will drive the normal velocity to zero, resulting in the flow\nmoving only parallel to the virtual surface. \nThe body force is defined as in Equation\n\\ref{eqn:body_force}; however, the length scale $\\ell_v$ is specified to\nbe the width of the forcing region used to represent the surface. This is\ntypically the width of two or three grid cells. While the actual surface we are\nemulating is thinner than this, the numerical discretization \ncannot represent anything thinner. \n%difficulty converging for surfaces smaller than the grid size.  \n\nForcing models designed to mimic a surface are not original to this\n project, and the current formulation is  closely related to (among others)\n``immersed boundary methods'' as used by various other\nresearchers~\\cite{doi:10.1146/annurev.fluid.37.061903.175743,verzicco1998complex}. This\napproach is unique in its use of Babuska's penalty treatment of\nconstraints\\cite{1973fempen,ZAMM:ZAMM19880680925} to enforce the\nbehavior at the boundary. This method was selected because it is easily\nimposed in the FEM context, and the penalty method properties have been\nexplored in detail in the literature.\n%\\todo{add more discussion of\n%healing length implications here} \nNote that despite the similarity in name, this is a distinct technique\nfrom the ``penalty immersed boundary method'' of Kim and\nPeskin\\cite{:/content/aip/journal/pof2/19/5/10.1063/1.2734674}.  \n\n%show image of cylinder in 2d flow?\\todo{add cylinder image? what does\n%zthis show?} \n\n%Typically, the enforcement occurs along a domain\n%boundary, but in this work it is used in the interior, \n%and is not imposed as a mathematical constraint but rather as a modeling \n%approach. \n\n% We add a penalty term to the weak\n% form of the Navier-Stokes momentum equation described in the subsequent\n% section %\\ref{eq:ns_weak} \n% that has the form, \n% \\begin{equation}\n% P_\\epsilon = \\int_\\Omega ({\\bf f_v} \\cdot v) \\, dx\n% \\end{equation}\n% where ${\\bf f_v}$ is as described in equation \\ref{eqn:body_force}. \n%% As the system is formulated as a variational problem that seeks to\n%% minimize the test function $v$, any velocity that is not aligned with\n%% the vane normal will incur a penalty versus one that does. Note that unlike\n%% some penalty methods, this does not automatically satisfy\n%% continuity. Rather, the velocity field remains divergence free through a\n%% separately enforced constraint.  \n\n\\section{Separation Model}\n\\label{sec:separation}\n\nIn the presence of wind, it was found that there was a significant flow\nout through the vanes in the back of the device. This was obviously\ninconsistent with the findings of our colleagues in the field, who\nobserved no such outflows. Moreover, this resulted\nin large inconsistencies between our predictions and the field results,\nalmost certainly because of the kinetic and thermal energy that our vane\nrepresentation was permitting to leave out the back of the device.  \n\nThis exposed a weakness of the turning vane representation outlined\npreviously. When the flow entered the virtual vane forcing region it was\nalways turned to align with the vane angle, even when the forcing was in\nthe opposite direction of the present velocity. This is in contrast to\nthe physical situation, in which we expect the flow to continue along an\naveraged streamline separating from the trailing edges of the vanes,\ninstead of turning around it. The averaged streamline will continue past\nthe trailing edge of the vane due to the separation of the boundary\nlayer off the edge surface. An image depicting these two cases in shown\nin Figure \\ref{fig:sep_model}.\n%\\todo{Bogard: could flow in Fig 3.9 turn against the \n%velocity ``inside'' vane (it can). I've amended the figure and caption to reflect this.}\n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width = 6 cm]{figs/sep_model}\n    \\caption{Schematic depicting the separation model that extends past\n   the trailing edge of the vanes. The vane surface is not moving, and \n   the line labelled flow is a path of the flow relative to the vane. \n   In the top case, the flow entering the virtual vane region is forced\n   to align with the vane angle despite this resulting in a reversal of\n   the flow direction. This is a consequence of the forcing function\n   acting on the fluid to ensure the velocity vector aligns with the\n   vane. The second case depicts the separation model, where the flow\n   under certain conditions is not forced and continues to move tangent\n   to the vanes due to the separation of the boundary layer off the\n   trailing edge.}  \n    \\label{fig:sep_model}\n  \\end{center}\n\\end{figure}\n\nLet $\\bf n_v$ be the normal vector to the vanes,\nand $\\bf n_r$ the normal vector pointing out of the vane\nregion\\footnote{\\normalsize The subscripts ``v'' and ``r'' stand for\nvane and radial, respectively.}.  \nThen, $\\bf t_v$ is the tangent vector to the vanes pointing out of\nthe vane region and is defined as,\n\n%\\begin{equation}\n% \\bf t^v = \\left( {\\bf n^v_y},{\\bf -n_x^v} \\right) \\text{sign}\\left[\n%\t    \\left( {\\bf n^v_y},{\\bf -n_x^v} \\right) \\cdot {\\bf n^r} \\right].\n%\\end{equation}\n\\begin{equation}\n \\bf t_v = \\left( {\\bf n_v^{\\perp}} \\right) \\text{sign}\\left(\n\t    {\\bf n_v^{\\perp}} \\cdot {\\bf n_r} \\right).\n\\end{equation}\nHere, sign() is the sign (or signum) function, which extracts the \nsign of a real number, and ${\\bf n_v^{\\perp}}$ is the vector \nperpendicular to the normal vector of the vanes, which is simply, \n\\begin{equation*}\n {\\bf n_v^{\\perp}} = \\left[ \\begin{array}{c}\nn_x\\\\\nn_y\\\\\n\\end{array}\\right]^{\\perp} = \n \\left[ \\begin{array}{c}\n  -n_y\\\\\n  n_x\\\\\n\t\\end{array}\\right].\n\\end{equation*}\n\n%\n% example of an algorithm\n%\n\n% \\begin{center}\n%  \\begin{algorithm}\n%   \\caption{The crude separation model. This model identifies if the flow\n%   is coming into or out of the vane region, and if the velocity vector\n%   is in the same direction as the tangent line of the vanes. In the case\n%   of the ``special forcing'' the flow is forced as if it was\n%   impacting a solid surface. In the\n%   algorithm below, $r_0$ is the max radius of vanes, $r_i$ the minimum\n%   radius of vanes, and $\\delta$ is the width of the separation region.}\n%   \\label{alg:sep}\n%   \\begin{algorithmic}\n%    \\IF{($r_0 > r > r_i$)} \n%    \\IF{$(r_0 - r) < \\delta$ \\textbf{or} $((r - r_i) < \\delta)$}\n%    \\STATE ${\\bf n_r} = {\\bf r}/|r|$\n%    \\IF{$(r - r_i) < \\delta$} \n%    \\STATE ${\\bf n_r} = -{\\bf n_r}$\n%    \\ENDIF\n%    \\STATE  $\\bf t_v = \\left( {\\bf n_v^{\\perp}} \\right) \\text{sign}\\left(\n%   \t    {\\bf n_v^{\\perp}} \\cdot {\\bf n_r} \\right)$\n%    \\IF{$v \\cdot t_v > 0$ \\textbf{and} $v \\cdot n_r < 0 $}\n%    \\STATE ${\\bf n}({\\bf x}) = \\hat r$ \\quad (Special Forcing)\n%    \\ELSE\n%    \\STATE  ${\\bf n}({\\bf x}) = \\sin \\left(\\phi(r) \\right) \\hat{{\\bf r}}+ \\cos\n%   \\left(\\phi(r) \\right) \\hat{{\\bf \\theta}} $\n%   \\quad (Normal Forcing)\n%    \\ENDIF\n%    \\ELSE\n%    \\STATE ${\\bf n}({\\bf x}) = \\sin \\left(\\phi(r) \\right) \\hat{{\\bf r}}+ \\cos\n%   \\left(\\phi(r) \\right) \\hat{{\\bf \\theta}} $\n%   \\quad (Normal Forcing)\n%    \\ENDIF\n%    \\ENDIF\n%   \\end{algorithmic}\n%  \\end{algorithm}\n% \\end{center}\n\n\nThe forcing is modified when the velocity vector of the local flow, ${\\bf u}$ \nis pointing into the forcing region: ${\\bf u} \\cdot {\\bf n_r} < 0$, and\nwhen the velocity vector is in the same direction as the tangent line to\nthe vanes: $ {\\bf u} \\cdot {\\bf t_v} > 0 $, \n\n\\begin{equation}\n {\\bf n}({\\bf x}) = \n \\begin{cases} \n   \\hat {\\bf r}  & \\text{if } {\\bf u} \\cdot {\\bf n_r} < 0 \\text{ and }  {\\bf u} \\cdot {\\bf t_v} > 0  ,\\\\\n   \\sin \\left(\\phi \\right) \\hat{{\\bf r}}+ \\cos \\left(\\phi \\right) \\hat{{\\bf \\theta}}  & \\text{else}.\n \\end{cases}\n\\end{equation}\n%\nIn these instances, the\nforcing acts as if there was a rigid surface past the vane edge, and\ngives the appearance of a special ``no-penetration'' condition for the\nvelocity for these cases. \n\n%The pseudo-code for this procedure is shown in\n%Algorithm~\\ref{alg:sep}.\\todo{cant write mathematically, would be easier}\n\nThe addition of this simple separation model significantly reduced the\nflow that penetrated the back of the vanes, and produces results\nconsistent with the observations provided by our experimental\ncolleagues.  \n\n\\section{Effect of Surface Roughness}\n\n%%\n%% this does not describe the phenomena being modeled or the precise\n%% model -- rewrite\n%%\n%%\n%% this does not say enough about the surface roughness\n%% motivate that and explain how it is used, than show your estimate \n%% to argue it is small\n%%\n\nSurface roughness effects have been shown to play a role in the\nformation of dust devils and related atmospheric\nphenomena\\cite{oke1987boundary}. For the flat and sandy\nregions we are simulating, the impact is expected to be a small vertical \nvelocity perturbation which triggers the convective instability caused\nby stratification near the surface. \n%a small\n%``kick-up'' forcing velocity perturbation in the vertical\n%direction. \nAssuming azimuthal symmetry, this is modeled as a volumetric forcing in\na narrow region above the surface in the region of the vanes,  \n\\begin{equation}\n F^{'''}_{z_0} = \\frac{1}{2}\\rho V_f^2/z_{0}, \n\\end{equation}\nwhere $z_{0}$ is the forcing region height and $V_f$ is the magnitude of\n the  induced velocity fluctuation which is estimated as, \n%\\begin{eqnarray}\n%z_0 = \\frac{1}{2} a t^2, \\\\\n%t = \\sqrt{\\frac{2 a}{z_0}}. \\\\\n%\\end{eqnarray}\n%Combining this with, $V_f = a t$, our estimate is, \n\\begin{equation}\nV_f = \\sqrt{2 a z_0}.\n\\end{equation}\nThe forcing region height $z_0$ is set to the boundary layer thickness\nof 10 centimeters. The acceleration was estimated at 0.05\n$\\text{m}/\\text{s}^2$, based on the observed surface roughness impact on\ntornado-like vortices of Natarajan and Hangan\\cite{Natarajan2012577}.\n\nWe ensure that the energy\nintroduced into the flow is a small fraction of total flow energy by comparing\nthis with the energy flux through the top of the vanes. The total energy\nadded is measured as,  \n\\begin{equation}\n E_{\\text{injected}} = \\int_0^{2\\pi} \\int_0^R \\int_0^{z_0} F^{'''}_{z_0}\n  dz dr d\\theta.  \n\\end{equation}\nR is the outer diameter of the vanes. \nThe value of $E_{\\text{injected}}$ is typically a few percent of the\ntotal kinetic energy flux measured through the top of the\nvanes.\n\nLeslie~\\cite{leslie1977surface} and Dessens~\\cite{dessens1972influence}\nfound that the introduction of surface roughness effects caused a slight\ndecrease in tangential velocity for simulated vortices, but an increase\nin radial and axial velocities. \nOn a related note, hurricane studies have\nconsistently found enhanced heat transport near the surface lead\nto storm intensification, indicating an important role due to roughness\neffects~\\cite{Zeng2010,GRL:GRL50047,hurricane_drag}. The interaction\nwith the surface and therefore, the impact of roughness, is likely\ncomplicated and is not considered in detail in this work. It should be \nnoted that in the simulations performed in the course of this study, the\nsurface roughness model was observed to modestly intensify the thermal\nvortex, typically by several percent. While this formulation was\nundoubtedly {\\it ad hoc}, studies performed on representative test \ncases found that results were not sensitive to small\nchanges in the forcing region height, radial distance, or\nforcing magnitude. \n\n%This general forcing provides additional capabilities including the\n%ability to investigate engineering greater surface roughness or\n%structures that could provide greater ``kick-up'' of the thin thermal\n%layer near the surface into the flowing regime. It can also support more\n%general turning configurations than the virtual vanes outlined above. \n\n\\section{Simulation Geometry and Boundary Conditions}\n\\label{sec:bc}\n\nIn this project, two principle modeling regimes are considered.  \nOne is the ``thermal-only'' scenario, in which there is no wind\n and there is an imposed elevated temperature on the ground.  \nIn the other, there are also ambient winds that contribute to the SoV energy\n(``wind'' cases) and elevated ground temperature. \nThe computational domain and boundary conditions for these \ntwo scenarios are described below.\n\n%\\subsection{Computational Domain} \n\\textbf{Computational Domain} \n\nAll simulations are performed in a cuboid domain, with six\nfaces.  The domain is denoted $\\Omega \\subset \\mathbb{R}^3$. \nThe domain extents are scaled by the system diameter, D, created by the\nouter vane radius. The extents are defined in terms of $\\{L_x,L_y,L_z\\}$ indicating the \nstreamwise, spanwise and vertical directions, respectively. \nFor both simulation regimes, sensitivity analyses \nwere performed to ensure that the results were not sensitive \nto the domain extents. For the thermal-only case, for which $L_x = L_y$,\nthe system \nextents $L_x/D$ and $L_y/D$ are chosen to be 3. The height ($L_z/D$) is\nthree times the system diameter, which is typically nearly equal to the\nheight of the vanes. This defines the thermal-only domain $\\Omega_T$, \nas $\\Omega_T = \\left[-L_x,L_x \\right] \\times \\left[-L_y,L_y \\right]\n\\times \\left[0,L_z \\right]$.   \n\nFor the wind cases, the streamwise extent is no longer equal to\nthe spanwise length, $L_y$. In these cases, the domain length extends\ntwo diameters in front of the vanes and three behind. The\nspanwise direction is symmetric and extends two diameters in each direction \nfrom the center ($L_y/D = 2$). The height is identical to the\nthermal-only case, at three system diameters ($L_z/D = 3$). Thus, the\nwind domain is defined as $\\Omega_W = \\left[-2D,3D \\right] \\times\n\\left[-L_y,L_y \\right] \\times \\left[0,L_z \\right]$.   \n\nThe boundary for the thermal only case is decomposed as,\n$\\partial \\Omega_T = \\Gamma_G \\, \\bigcup \\, \\Gamma_T \\, \\bigcup \\,\n\\Gamma_P $.  \n$\\Gamma_G$ is the boundary along the ``Ground'', $\\Gamma_T$\nthe ``Top'' boundary, and $\\Gamma_P$ the four periodic ``Sides''. A 3D\ndiagram labeling these boundaries appears in\nFigure~\\ref{fig:thermal3d}. For this case (no mean wind),\nperiodic boundary conditions are used on the four sides , with a modified \n``inflow-outflow'' Neumann condition\\cite{gunzburger1989finite} on the\ntop boundary. On the ground, a ``no-slip'' velocity boundary condition is\nimposed, and a Dirichlet condition uniformly fixes\nthe temperature of the surface. \nEach of the $\\Gamma$ boundary terms are defined in the paragraphs below. \nNote that a finite thickness ``Sponge Layer'' is\nindicated on the figure along the top boundary and is defined below. \n\n\\begin{figure}[!htb]\n  \\begin{center}\n    \\includegraphics[width=14cm]{figs/thermal_only_3d}\n    \\caption{Domain for the thermal-only\n   scenario. The diagram scale is representative of typical cases. Note\n   the SoV apparatus in the center, which provides perspective on the\n   extent of the domain with respect to the turning vane diameter. The\n   ground, sides and top boundaries are labeled with the discussion the\n   precise boundary conditions on each provided in\n   Section~\\ref{sec:bc}. Notice also the finite thickness, high\n   viscosity ``sponge layer'' at the top of the domain.} \n    \\label{fig:thermal3d}\n  \\end{center}\n\\end{figure}\n\nThe boundary for the wind cases is decomposed as,\n\\begin{equation*}\n \\partial \\Omega_W = \\Gamma_G \\, \\bigcup \\, \\Gamma_T \\, \\bigcup \\,\n  \\Gamma_O \\, \\bigcup \\, \\Gamma_I \\, \\bigcup \\, \\Gamma_S.  \n  \\end{equation*}\nWhere $\\Gamma_G$ is the boundary along the ``Ground'',\n$\\Gamma_T$ the ``Top'' boundary, $\\Gamma_S$ the two ``Sides'',\n$\\Gamma_I$ the inflow boundary, and $\\Gamma_O$ the ``Outflow''  \nboundary.\nThe ``wind'' simulation domain is diagrammed in\nFigure~\\ref{fig:wind3d}, with the boundaries labeled. \nIn this wind case (a heated ground with \nan ambient wind), there is a proscribed inlet boundary layer\nalong the upstream streamwise face ($\\Gamma_I$) for both the temperature\nand the velocity. The ``Ground'' boundary is identical to\nthe thermal-only case. The ``Sides'', ``Outflow'' and ``Top'' are all\nset to modified Neumann boundary conditions. Note that ``Sponge Layers''\nare used on both the outflow and the top. \n\n\\begin{figure}[!htb]\n  \\begin{center}\n   \\includegraphics[width=14 cm]{figs/wind_3d}\n    \\caption{Domain for the wind and thermal scenario. The diagram scale\n   is representative of typical cases. Note the SoV apparatus which\n   provides perspective on the extent of the domain with respect to the\n   turning vane diameter. The ground, sides, inflow, back and top\n   boundaries are labeled with the discussion the precise boundary\n   conditions on each provided in Section~\\ref{sec:bc}. Notice also the\n   finite thickness, high viscosity ``sponge layer'' at the top and back\n   of the domain.}   \n    \\label{fig:wind3d}\n  \\end{center}\n\\end{figure}\n\n\\textbf{Ground Boundary Conditions, $\\Gamma_G$} \n\nFor both the wind and thermal-only cases the ground has a fixed\ntemperature and no-slip velocity boundary conditions. This boundary \n($\\Gamma_G$) is modeled with a Dirichlet boundary condition, \n\\begin{align}\n {\\bf u} &= 0 \\quad \\text{ on } \\Gamma_G \\\\\n T &= T_g.\n\\end{align}\nWhere $\\Gamma_G = \\{(x,y,0) \\subset \\partial \\Omega \\} $. \n\n%\n% http://fenicsproject.org/documentation/dolfin/dev/python/demo/documented/periodic/python/documentation.html \n%\n%\n\\textbf{Periodic Boundary Condition, $\\Gamma_P$} \n\nA periodic boundary condition is used in the thermal only cases, \nfor boundaries normal to the x and y directions \n(denoted $\\Gamma_{P,x}$ and $\\Gamma_{P,y}$, respectively). In these\ncases the state variables  \nare constrained to have the same value on the opposite faces of the domain, \nfor instance in the streamwise direction the boundary conditions are, \n\\begin{align}\n {\\bf u}(-L_x,y,z) &= {\\bf u}(L_x,y,z) \\quad \\text{ on } \\Gamma_{P,x} \\\\\n T(-L_x,y,z) &= T(L_x,y,z)\n\\end{align}\nand in the spanwise direction,\n\\begin{align}\n {\\bf u}(x,-L_y,z) &= {\\bf u}(x,L_y,z) \\quad \\text{ on } \\Gamma_{P,y} \\\\\n T(x,-L_y,z) &= T(x,L_y,z). \n\\end{align}\nWhere $\\Gamma_{P,x} = \\{(-L_x,y,z) \\, \\bigcup \\, (L_x,y,z) \\subset \\partial\n\\Omega \\}$  \nand $\\Gamma_{P,y} = \\{(x,-L_y,z) \\, \\bigcup \\, (x,L_y,z) \\subset \\partial\n\\Omega \\}$. \n\n\\textbf{Inflow Boundary Condition, $\\Gamma_I$} \n\nOn the inflow boundary $(\\Gamma_I$), Dirichlet conditions are used for\nboth velocity and temperature. The boundary-normal, or streamwise\ncomponent is a function of the surface normal coordinate (z),\nrepresenting a boundary layer below a uniform velocity, U.\nThe common 7\\textsuperscript{th} power model of a turbulent boundary\nlayer is used,    \n\\begin{equation*}\n  u_{\\text{in}}(z) = U \\text{ min }\\left(\\left(\\frac{z}{\\delta}\\right)^7,1\\right),\n  \\label{eq:bl_u}\n\\end{equation*}\nwhere $\\delta$, the boundary layer thickness, is set based on data\nmeasured by our experimental partners in the field. \nThe thermal boundary layer is assumed to have a similar boundary layer,\nbut, as observed in real atmospheric flows, there remains a vertical\ntemperature gradient outside the thin boundary layer. \nThe thermal inflow has the form,\n\\begin{equation*}\n  T_{\\text{in}}(z) = \\Delta T \\left(1- \\text{ min\n\t\t\t}\\left(\\left(\\frac{z}{\\delta}\\right)^7,1\\right)\\right)\n  + T_0 - \\beta z.  \n  \\label{eq:bl_t}\n\\end{equation*}\n% 335+18*tanh(-z/0.1)-z*2/3\nBased on results in the literature, $\\beta = 2/3$ Kelvin per \nmeter\\cite{Blocken2007238}.\nThis inflow boundary is at the surface $x=-L_x$.\n\n\\textbf{Mixed inflow/outflow Boundary Conditions on $\\Gamma_T$,\n$\\Gamma_S$ and $\\Gamma_B$}  \n\nAt outflow boundaries, a homogeneous Neumann condition is\nappropriate\\cite{Rannacher2000}, \n\\begin{align}\n  \\frac{\\partial u}{\\partial n}\\bigg|_{\\Gamma_T} = 0, \\\\\n  \\frac{\\partial T}{\\partial n}\\bigg|_{\\Gamma_T} = 0.\n\\end{align}\nHowever, for the cases in this study, a modified Neumann condition is\nnecessary due to the possibility that there will be an inflow on these\nboundaries. \nFor example, in the region above the vanes, the concentrated hot plume is\nlifted by buoyancy upward and out of the simulation domain. However, the\nradial inflow towards the apparatus is drawn in by large scale\nconvection cells larger than the system diameter. Thus, our boundary\nconditions must permit inflow along the areas above and external to the\nvanes, while simultaneously permitting outflow in the area above the vanes. \n\n% Roy Stogner: Okay, so this DDN is basically no-traction when there's \n% outflow and Tn=v when there's inflow?  We have no-traction for v*n, \n% no-traction for anything else when there's outflow, and Dirichlet\n% v.cross.n = 0 when there's inflow. \n\nTo accomplish this, the boundary condition is,\n\\begin{align}\n  \\frac{\\partial u_n}{\\partial n}\\bigg|_{\\Gamma_T} = 0 \\\\\n  \\text{if } (w<0) \\text{ then}& \\begin{cases}\n    u_t = 0,\\\\\n    T = T_{\\text{in}}\n  \\end{cases} \\\\\n  \\text{ else}& \\begin{cases}\n    \\frac{\\partial u_t}{\\partial n}\\bigg|_{\\Gamma_T} = 0, \\\\  \n    \\frac{\\partial T}{\\partial n}\\bigg|_{\\Gamma_T} = 0\n  \\end{cases}\n\\end{align}\nwhere $u_n$ and $u_t$ are normal and tangential components of the velocity, \nrespectively. This boundary condition is applied on the top boundary\n$\\Gamma_T$ ($z=L_z$) and downstream side boundary  $\\Gamma_B$ in the\nwind case. This mixed boundary condition appears to be a unique\nimplementation of a modified Neumann condition condition, which has been \ndemonstrated previously in other\ninstances~\\cite{braack2014directional,feistauer2006non}. In particular,\nthe well-posedness of this general class of boundary condition is\ntreated in \\cite{bruneau1996new}.  \n\n\\textbf{Sponge Layer} \n\nFinally, a finite thickness ``sponge layer'' is used in the region adjacent \nto the mixed inflow/outflow boundaries $\\Gamma_T$ and $\\Gamma_B$.\nThese regions are referred to by many names in the\nliterature\\cite{doi:10.1146/annurev.fluid.36.050802.121930}, such as\nabsorbing layers, fringe regions, buffer zones, sponges,\netc. \nThis layer artificially increases the momentum diffusivity by\na factor of ten over the nominal value. This was designed to stabilize\nthe modified Neumann boundary conditions which can exhibit an instability\nwhen there is a compact jet of fluid leaving the domain. \nThese small outflows would create small high velocity inflows, and the\nfeedback loop would result in instabilities and numerical\nblow-up. \n% Mindful of the fact that the character of solution not\n% important in this region, and that our physical interest remains focused\n% on the region inside and in immediate proximity to the vanes, we\n% introduced a higher diffusivity ``sponge'' region that would diffuse the\n% high velocity exiting jets sufficiently to prevent numerically\n% un-physical behavior. \nUse of this stabilizing sponge layer is justified because we are not\ninterested in the flow in this region. \nNo results are quoted from this ``sacrificial''\nregion, as it is not considered physically meaningful. The top sponge\nlayer in both the wind and thermal-only cases are half a\nsystem diameter $(L_z/D = 1/2)$ thick. For the wind cases, the\ndownstream sponge layer is also half a system diameter $(L_x/D\n= 1/2)$ thick.  \n\n%\\todo{expand this? how thick did it need to be?}\n", "meta": {"hexsha": "cd3e7592f1377848b929713c147e677bde6afcc8", "size": 66082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/dissertation/chapter-model.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/dissertation/chapter-model.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/dissertation/chapter-model.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 45.7948717949, "max_line_length": 119, "alphanum_fraction": 0.7436972247, "num_tokens": 18208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6019090029310685}}
{"text": "\\documentclass{article}\n\n\n\\begin{document}\n\n\\section{Topic}\nThe sum of the first $n$~integers is given by the formula: $$ \\sum_{i = 0}^{n} i = \\frac{n(n+1)}{2} $$.\n\n\n\\end{document}\n", "meta": {"hexsha": "4f3d515f1bfa2f5830142f6c5b1b724f69be76b4", "size": 181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sample/main.tex", "max_stars_repo_name": "RyanPattison/ghibli256", "max_stars_repo_head_hexsha": "dd4550971d144b9898cc7d85d0dc1fc5c12140d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-10-06T18:59:22.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-06T18:59:22.000Z", "max_issues_repo_path": "sample/main.tex", "max_issues_repo_name": "RyanPattison/ghibli256", "max_issues_repo_head_hexsha": "dd4550971d144b9898cc7d85d0dc1fc5c12140d9", "max_issues_repo_licenses": ["MIT"], "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/main.tex", "max_forks_repo_name": "RyanPattison/ghibli256", "max_forks_repo_head_hexsha": "dd4550971d144b9898cc7d85d0dc1fc5c12140d9", "max_forks_repo_licenses": ["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.4545454545, "max_line_length": 103, "alphanum_fraction": 0.6408839779, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.6859494550081926, "lm_q1q2_score": 0.6019047329468713}}
{"text": "\n\\subsection{Random search}\n\nWe start with a random set of parameters, \\(x\\).\n\nWe then loop through the following:\n\n\\begin{itemize}\n\\item We define a search space local to our current selection.\n\\item We randomly select a point from this space.\n\\item We compare the new point to our current point. If the new point is better we move to that.\n\\end{itemize}\n\n", "meta": {"hexsha": "ed97857d47c88c5ade8073a61dab98f2f3d97663", "size": 357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/optimisation/01-01-randomSearch.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/optimisation/01-01-randomSearch.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/optimisation/01-01-randomSearch.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": 96, "alphanum_fraction": 0.756302521, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6018997143309679}}
{"text": "\\chapter{Summary of Gulwani and Necula}\n\\label{chap:chapter3}\n\nGulwani showed that there is a family of acyclic programs for which \nthe set of all Herbrand equivalences requires an exponential \nsized (with respect to the size of the program) value graph \nrepresentation - the data structure used by Kildall in his algorithm. \nHe also showed that Herbrand Equivalences among program sub \nexpressions can always be represented using linear sized value graph. \nThis explains the reason for exponential complexity of Kildall's \nalgorithm which cannot be improved to polynomial and imprecise nature \nof existing polynomial time algorithms.\n\nSo contrasting to Kildall's algorithm, which finds \\textit{all the \nHerbrand Equivalent classes} corresponding to constants, variables \nand operators occurring in the program, Gulwani's algorithm discovers \n\\textbf{equivalences among program subexpressions} (expressions that \ncan occur syntactically in a program), in linear time with respect to \nparameter $s$, the maximum size of an expression in terms of number \nof operators used. For global value numbering, $s$ can be safely \ntaken to be $N$, the size of the program and hence the algorithm is \nlinear in the program size.\n\nAlso, they proved that the lattice of sets of Herbrand equivalences has \nfinite height $k$, which is the number of program variables. So, an \nabstract interpretation over the lattice of Herbrand equivalences \nwill terminate in at most $k$ iterations even for cyclic programs.\n\n\\section{Brief overview of the algorithm}\n\\label{sec:BriefOverviewOfTheAlgorithm}\nThe program expressions can be represented as\n$$e\\; ::=\\; x\\: |\\: c\\: |\\:F(e_1, e_2)$$\nwhere, $c$ and $x$ are constants and variables occurring in the \nprogram respectively. Any expression of length greater than two\n(in terms of number of operands) can be converted into two length \nexpression by introduction of extra variables.\n\n\nThe data structure used is called \\textbf{Strong Equivalence DAG \n(SED)}. Each node of SED is of the form $<V,t>$ where $V$ is a set of \nprogram variables and $t$ is either $\\perp$ or $c$ for leaf nodes and \n$F(n_1, n_2)$ where $n_1$ and $n_2$ are SED nodes for non leaf nodes\n(also indicating that the node has two ordered successors). $\\perp$ \nmeans that the variables in the node have undefined values.\n\nThere is a SED associated with each program point and the algorithm\nstarts with the following initial SED\n$$G_0\\; =\\; \\{<x,\\perp>\\: |\\: x \\text{ is a program variable}\\}$$ \nTwo functions $Join(G_1, G_2, s')$ and $Assignment(G_1, x := e)$ are \nused to compute SEDs for other points in the flow graph node \ncorresponding to the program, as shown in figure \n\\ref{fig:GulwaniAlgorithm}. $s'$ in the argument of $Join$ is \na positive integer, and it returns equivalences between expressions of\nsize atmost $s'$.\n\n\\begin{figure}[!ht]\n\\label{fig:GulwaniAlgorithm}\n    \\centering {\n        \\setlength{\\fboxsep}{8pt}    \n        \\fbox{\\includegraphics[scale=0.75]{GulwaniAlgorithm.png}}\n    }\n    \\caption{Computation of SED for flowgraph nodes of a program}\n\\end{figure}\n\nFor detailed implementation of \\textbf{Join} and \\textbf{Assignment} \nfunctions, as well as a correctness proof of the algorithm, see \\cite{Gulwani}.\n\n\\section{Complexity of the algorithm}\n\\label{sec:ComplexityOfTheAlgorithm}\nThe complexity of the algorithm is $O(k^{3} * N * j)$, where $k$ is  \nthe total number of program variables, $N$ is the size of the program \nand $j$ is the number of join operations in the program. $k$ and $j$ \nare bounded by $N$, making the whole algorithm polynomial in $N$.", "meta": {"hexsha": "78f9f5164a945bae72c2249d9fbd761ff89a4a79", "size": 3581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/Rep_Mid_8/chapter3.tex", "max_stars_repo_name": "himanshu520/HerbrandEquivalence", "max_stars_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_stars_repo_licenses": ["MIT"], "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/Rep_Mid_8/chapter3.tex", "max_issues_repo_name": "himanshu520/HerbrandEquivalence", "max_issues_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_issues_repo_licenses": ["MIT"], "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/Rep_Mid_8/chapter3.tex", "max_forks_repo_name": "himanshu520/HerbrandEquivalence", "max_forks_repo_head_hexsha": "bfe056d9d370d9e5fe2782381b872bf102a960ba", "max_forks_repo_licenses": ["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.0547945205, "max_line_length": 79, "alphanum_fraction": 0.7598436191, "num_tokens": 921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933315126791, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6018996998693366}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage[\\graphtype]{mfpic}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\opengraphsfile{pl02-03}\n\\begmath 2.3 Gamma and Log-Gamma Functions\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThese subprograms compute values of the gamma function and the natural\nlogarithm of the gamma function, \\cite{ams55} and~\\cite{Hart:1968:CA:gam}.\nThe gamma function is defined by%\n\\begin{equation*}\n\\Gamma (x)=\\int_0^\\infty e^{-s}s^{x-1}ds.\n\\end{equation*}\nFor integer values of $n\\geq 0$, it satisfies the relation\n\\begin{equation*}\nn!=\\Gamma (n+1).\n\\end{equation*}\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf SGAMMA, SLGAMA, X, Y}\n\\end{description}\n\nAssign a value to X and obtain gamma or the natural logarithm of gamma,\nrespectively, through use of the function statements:\n$$\n\\fbox{{\\bf Y =SGAMMA(X)}} \\hspace{.5in} \\fbox{{\\bf Y =SLGAMA(X)}}\n$$\n\n\\subsubsection{Argument Definition}\n\n\\begin{description}\n\\item[X]  \\ [in] Argument at which function evaluation is desired. See\nSection E for restrictions on X.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nFor double precision usage, change the REAL type statement to DOUBLE\nPRECISION and change the function names from SGAMMA to DGAMMA and SLGAMA to\nDLGAMA.\n\n\\subsubsection{Program Prototype, Complex}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf MODE}\n\n\\item[COMPLEX]  \\ {\\bf CARG, CVAL}\n\n\\item[REAL]  \\ {\\bf ERREST}\n\\end{description}\n\nAssign the complex argument in CARG. Set MODE to 0 or 1.\n\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL CGAM(CARG, CVAL,\\\\\nERREST, MODE)\n\\end{tabular}}\n\\end{center}\n\nThe complex result will be in CVAL with an error estimate in ERREST.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[CARG]  \\ [in] Complex argument. The argument must not be zero or a\nnegative real integer value.\n\n\\item[CVAL]  \\ [out] Computed complex value of either log-gamma or gamma.\nThe imaginary part of log-gamma, say $v$, will be standardized to satisfy $%\n-\\pi <v\\leq \\pi .$\n\n\\item[ERREST]  \\ [out] On return ERREST gives an estimate of the absolute\nerror (for log-gamma) or the relative error (for gamma) of the computed\nvalue.\n\n\\item[MODE]  \\ [in] Set value to 0 for log-gamma and 1 for gamma.\n\\end{description}\n\n\\subsubsection{Program Prototype, Double Precision Complex}\n\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf MODE}\n\n\\item[DOUBLE PRECISION]  \\ {\\bf CARG}(2){\\bf , CVAL}(2){\\bf , ERREST}\n\\end{description}\n\nAssign the complex argument in CARG(), with real part in CARG(1) and\nimaginary part in CARG(2). Set MODE to 0 or 1.\n\n\\begin{center}\n\\fbox{%\n\\begin{tabular}{@{\\bf }c}\nCALL ZGAM(CARG, CVAL,\\\\\nERREST, MODE)\n\\end{tabular}}\n\\end{center}\n\nThe result will be in CVAL() with an error estimate in ERREST.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[CARG()]  \\ [in] Array of 2 values representing the complex argument,\nCARG(1) for the real part and CARG(2) for the imaginary part. The argument\nmust not be zero or a negative real integer value.\n\n\\item[CVAL()]  \\ [out] Array of 2 values representing the complex function\nvalue returned: CVAL(1) and CVAL(2) for real and imaginary parts,\nrespectively. The imaginary part of log-gamma, say $v$, will be standardized\nto satisfy $-\\pi <v\\leq \\pi .$\n\n\\item[ERREST]  \\ [out] On return ERREST gives an estimate of the absolute\nerror (for log-gamma) or the relative error (for gamma) of the answer.\n\n\\item[MODE]  \\ [in] Set value to 0 for log-gamma and 1 for gamma.\n\\end{description}\n\nAlthough the Fortran 77 standard does not support a double precision complex\ntype, many vendors do provide for this using a declaration COMPLEX*16 or\nDOUBLE COMPLEX. With such a compiler one can probably use ZGAM with its\nfirst two arguments declared as double precision complex.\n\n\\subsection{Examples and Remarks}\n\n\\subsubsection{Example}\n\nThe gamma function satisfies a ``duplication'' identity which may be written\nas%\n\\begin{equation*}\nz=\\frac{2\\sqrt{\\pi }\\Gamma (x)}{2^x\\Gamma (x/2)\\Gamma (x/2+\\frac 12)}-1=0.\n\\end{equation*}\nThe listing of DRSGAMMA and ODSGAMMA gives an example of using these\nsubprograms to evaluate this identity. The program DRCGAM and output ODCGAM\nillustrate the use of CGAM.\n\n\\subsubsection{Remarks}\n\nNeither the Fortran 77 standard nor the Fortran 90 standard includes\nintrinsic functions for gamma or log-gamma; however, such functions with the\nnames GAMMA, DGAMMA, LGAMMA, ALGAMA, and DLGAMA are provided as intrinsic\nfunctions in some vendors' Fortran systems. In particular these latter\nfunctions are provided with the UNISYS ASCII Fortran and IBM VS-Fortran, but\nnot with the VAX-11 Fortran. In the UNISYS and IBM systems GAMMA and LGAMMA\nare ``generic\" names and thus can be used with either single or double\nprecision arguments.\n\nIn a system having DGAMMA or DLGAMA as intrinsics a reference to one of\nthese function names will cause the vendor-supplied code to be used. If one\nwishes to override this and use the code from this library one must declare\nthe function name to be EXTERNAL in the referencing program unit.\n\n\\subsection{Functional Description}\n\nThe gamma function is defined and takes positive values for all real $x>0$,\nbecoming unbounded both as $x\\rightarrow 0$ and as $x\\rightarrow +\\infty $.\nAs $x\\rightarrow 0$, $\\Gamma (x)$ is asymptotic to $1/x$, and as $%\nx\\rightarrow \\infty $, $\\Gamma (x)$ is asymptotic to%\n\\begin{equation*}\nh(x)=\\left( x/e\\right) ^x\\sqrt{2\\pi /x}.\n\\end{equation*}\nAs an estimate of the size of $\\Gamma (x)$ for large positive real $x$, note\nthat for $x>9$, $\\Gamma (x)$ satisfies $h(x)<\\Gamma (x)<1.01\\ h(x)$. The\ngamma function is also defined for negative $x$ except at the negative\nintegers where it has poles.\n\nAs a function of a complex variable the gamma function is analytic\nthroughout the complex plane except for poles at zero and the negative real\ninteger points. See \\cite{ams55} and \\cite{Hart:1968:CA:gam} for further\ndiscussion of the gamma function.\n\nThe subprograms SGAMMA, DGAMMA, SLGAMA, and DLGAMA are based on subprograms\ndeveloped by W.J. Cody, Argonne National Laboratory, which were designed for\n$10^{-20}$ precision. These subprograms use rational minmax approximations\non selected subintervals as well as asymptotic formulas and argument\nreduction techniques. The degrees of the rational approximations are not\nvaried between the single precision and double precision subprograms or as\na function of the host computer's precision.\n\\vspace{10pt}\n\n\\hspace{5pt}\\mbox{\\input pl02-03a }\n\nSubprograms CGAM and ZGAM are based on \\cite{Kuki:1972:CGF}, making use of\nthe Stirling asymptotic series and recursive formulas.  The accuracy\nadjusts to the host machine up to about 17 significant decimal digits.\nCGAM and ZGAM reference I1MACH(10) to find the radix of the host system's\nfloating point arithmetic.\n\n\\subparagraph{Accuracy tests}\n\nAccuracy tests were run on a Univac 1108 in 1969 and on a Univac 1100 in\n1983. The arithmetic precision of these systems is $\\rho _1 = 2^{-27}\n\\approx 0.$ 745E$-$8 for single precision and $\\rho _2 = 2^{-60}\n\\approx 1.15$E$-$18 for double precision.\n\nSubprograms SGAMMA and SLGAMA were tested in 1983 on a Univac 1100 by\ncomparison with DGAMMA and DLGAMA at 18,000 points. The test results may be\nsummarized as follows:\n\n\\begin{center}\n\\begin{tabular}{l@{}lr}\n& \\multicolumn{1}{c}{\\bf Argument} & \\multicolumn{1}{c}{\\bf Max. Rel.}\\\\\n\\multicolumn{1}{l}{\\bf Function} & \\multicolumn{1}{c}{\\bf Interval} &\n\\multicolumn{1}{c}{\\bf Error}\\\\\nSGAMMA & \\rule{.17in}{0pt}[0., 1.] & $2.5\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[1., 2.] & $1.4\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[2., 10.] & $9.2\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[10., 17.] & $100.0\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[17., 30.] & $180.0\\rho _1$\\rule{.12in}{0pt}\\\\\nSLGAMA & \\rule{.17in}{0pt}[0.0, 0.5] & $2.7\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[0.5, 4.0] & $6.5\\rho _1$\\rule{.12in}{0pt}\\\\\n& \\rule{.17in}{0pt}[4.0, 35.0] & $2.8\\rho _1$\\rule{.12in}{0pt}\n\\end{tabular}\n\\end{center}\n\nTo test the double precision functions, and as an additional test of the\nsingle precision functions, the function $z(x)$ defined in Section C and\na logarithmic form of $z(x)$ defined as\n\n\\hspace{.2in}$w(x) =\\text{LGAM}(x) + 0.5\\ \\ln (2\\pi ) + (0.5 - x) \\ln(2)$\n\\vspace{-2pt}\n\n\\hspace{.8in}$- \\text{LGAM}(0.5x) - \\text{LGAM}(0.5x + 0.5) = 0$\n\nwere evaluated on a Univac 1100 in 1983 at about 100 points. These tests are\nsummarized as follows (``Max. Error\" is the maximum magnitude of\nthe test function):\n\n\\begin{tabular}{@{}l@{}l@{\\ \\ }c@{ }r}\n\\multicolumn{1}{@{}c}{\\bf Subprogram} & \\multicolumn{1}{c}{\\bf Argument} &\n\\multicolumn{1}{c}{\\bf Test} & \\multicolumn{1}{c}{\\bf Max.}\\\\\n\\multicolumn{1}{@{}c}{\\bf Used} & \\multicolumn{1}{c}{\\bf Interval} &\n\\multicolumn{1}{c}{\\bf Function} & \\multicolumn{1}{c}{\\bf Error}\\\\\nSGAMMA & [$-$20.75, $-$11.25] & $z$ & $114\\rho _1$\\\\\n & [$-$11.25, 11.50] & $z$ & $6\\rho _1$\\\\\n & [11.50, 34.00] & $z$ & $100\\rho _1$\\\\\nDGAMMA & [$-$20.75, 43.60] & $z$ & $130\\rho _2$\\\\\n & [43.60, 106.80] & $z$ & $384\\rho _2$\\\\\n & [106.80, 170.00] & $z$ & $1186\\rho _2$\\\\\nSLGAMA & [0.0625, 3.1] & $w$ & $3\\rho _1$\\\\\n & [3.1, 11.5] & $w$ & $8\\rho _1$\\\\\n & [11.5, 0.12E37] & $w/\\text{SLGAMA}$ & $2.7\\rho _1$\\\\\nDLGAMA & [0.0625, 12.0] & $w$ & $110\\rho _2$\\\\\n & [12.0, 0.77D305] & $w/\\text{DLGAMA}$ & $2.9\\rho _2$\n\\end{tabular}\n\nSubprogram ZGAM was tested in 1969 on a Univac 1108. The maximum relative\nerror noted for complex arguments, $x$, satisfying $|x| < 30$, was $345\\rho\n_2$ for gamma and $93\\rho _2$ for log-gamma. The test function, $z$, was\nevaluated at a few complex points, $x$, of magnitude near one on a Univac\n1100 in 1983. The maximum value of $|z|$ was $30\\rho _2.$\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nSubprograms SGAMMA and DGAMMA accept negative as well as positive arguments.\nThese subprograms will issue an error message and return the largest machine\nnumber, $\\Omega $, if $x$ is zero or a negative integer, or if $x \\geq x_g.$\n\nThe subprograms SLGAMA and DLGAMA are designed only for positive arguments.\nThese subprograms will issue an error message and return the value, $\\Omega $%\n, if $x \\leq 0$, or if $x \\geq x_\\lambda .$\n\nThe complex gamma subroutines CGAM and ZGAM issue an error message and\nreturn the complex value $(\\Omega $,\\ $\\Omega )$ if the argument is zero, a\nnegative real integer, or a large argument that would cause overflow.\n\nLet $\\Omega $ denote the machine overflow limit. Let $x_g$ denote the value\nof $x$ for which $\\Gamma (x) = 0.875\\ \\Omega $, and let $x_\\lambda $ denote\nthe value of $x$ for which $\\ln (\\Gamma (x)) = 0.875\\ \\Omega $. Some\nexamples of these values follow.\n\n\\begin{center}\n\\begin{tabular}{lrl}\n{\\bf Computing System}&{\\bf $x_g $}\\rule{3pt}{0pt}&\\ \\ \\ {\\bf $x_\\lambda $}\\\\\nVAX 11/780, SP \\& DP & 34.8 & 1.8e36\\\\\nUNISYS (Sperry) 1100, SP & 34.5 & 1.8e36\\\\\nIEEE Math processor, SP & 35.0 & 3.6e36\\\\\nIBM Mainframe 3xxx, DP & 57.5 & 3.8e73\\\\\nUNISYS (Sperry) 1100, DP & 171.5 & 1.1e305\\\\\nIEEE Math processor, DP & 171.6 & 2.2e305\\\\\nCray, SP \\& DP & 966.9 & 8.5e2461\n\\end{tabular}\n\\end{center}\n\nThe values listed above are computed on a first-time flag at run time making\nuse of the overflow limit obtained from R1MACH(2) or D1MACH(2).\n\n\\subsection{Supporting Information}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nCGAM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, CGAM, ERFIN, ERMSG, SERM1, SERV1\\rule[-5pt]{0pt}{8pt}}\\\\DGAMMA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERM1, DERV1, DGAMMA, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\DLGAMA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERM1, DERV1, DGAMMA, DLGAMA, ERFIN, ERMSG\\rule[-5pt]{0pt}{8pt}}\\\\SGAMMA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERM1, SERV1, SGAMMA\\rule[-5pt]{0pt}{8pt}}\\\\SLGAMA & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, SERM1, SERV1, SGAMMA, SLGAMA\\rule[-5pt]{0pt}{8pt}}\\\\ZGAM & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, DERM1, DERV1, ERFIN, ERMSG, ZGAM\\rule[-5pt]{0pt}{8pt}}\\\\\\end{tabular}\n\nSubprograms SGAMMA, DGAMMA, SLGAMA, and DLGAMA were developed by W.J. Cody,\nArgonne National Lab., 1982, and adapted to the JPL MATH 77 library by C.\nLawson and S. Chiu, JPL, 1983.\n\nSubroutines CGAM and ZGAM were developed by H. Kuki with the name CDLGAM\n(\\cite{Kuki:1972:CGF} above), adapted for JPL Univac 1108 usage by E.W.~%\nNg, 1969, and adapted to the JPL MATH 77 library by C.~Lawson and S.~%\nChiu, JPL, 1983.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSGAMMA}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sgamma}}\n\n\\vspace{20pt}\\centerline{\\bf \\large ODSGAMMA}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sgamma}}\n\n\\newpage\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRCGAM}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{cgam}}\n\n\\vspace{20pt}\\centerline{\\bf \\large ODCGAM}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{cgam}}\n\n\\closegraphsfile\n\\end{document}\n", "meta": {"hexsha": "0a1532796b0c166e5e25169bc3c0509f242ba489", "size": 13408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch02-03.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/ch02-03.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/ch02-03.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.5287356322, "max_line_length": 132, "alphanum_fraction": 0.7168108592, "num_tokens": 4621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754607093178, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6018258960543609}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{color,times,graphicx,epstopdf,fancyhdr,amsfonts,amsthm,amsmath,algorithm,algorithmic,xspace,hyperref}\n\\usepackage[left=1in,top=1in,right=1in,bottom=1in]{geometry}\n\\usepackage{sect sty}\t%For centering section headings\n\\usepackage{enumerate}\t%Allows more labeling options for enumerate environments\n\\usepackage{epsfig}\n\\usepackage[space]{grffile}\n\\usepackage{booktabs}\n\n% This will set LaTeX to look for figures in the same directory as the .tex file\n\\graphicspath{.} % The dot means current directory.\n\n\\pagestyle{fancy}\n\n\\lhead{\\YOURID}\n\\chead{Square Root List}\n\\rhead{\\today}\n\\lfoot{Williams College}\n\\cfoot{\\thepage}\n\\rfoot{Fall 2020}\n\n% Some commands for changing header and footer format\n\\renewcommand{\\headrulewidth}{0.4pt}\n\\renewcommand{\\headwidth}{\\textwidth}\n\\renewcommand{\\footrulewidth}{0.4pt}\n\\newcommand{\\nonterm}[1]{$\\langle$#1$\\rangle$}\n\n% These let you use common environments\n\\newtheorem{claim}{Claim}\n\\newtheorem{definition}{Definition}\n\\newtheorem{theorem}{Theorem}\n\\newtheorem{lemma}{Lemma}\n\\newtheorem{observation}{Observation}\n\\newtheorem{question}{Question}\n\n\\setlength{\\parindent}{0cm}\n\n\\setlength{\\columnseprule}{0.1pt}\n\\def\\columnseprulecolor{\\color{black}}\n\n\n% Edit below as instructed\n\\newcommand{\\YOURID}{Petros Markopoulos}\n\\newcommand{\\ProblemHeader}\n\n\\begin{document}\n\n\\vspace{\\baselineskip}\t% Add some vertical space\n\n\\section{Introduction}\n\\subsection{What is a Linked List}\nA Linked List is a simple data structure consisting of what is usually referred to as \\textit{Nodes}. A Node contains some piece of data as well as a pointer to the next node (it can also contain a pointer to the previous node, to create a Doubly Linked List, which is actually what is used in the implementation of SqrtList). Thus, the whole list can be accessed by starting at the first node (usually referred to as the \\textit{head}) and following the pointers until the end of the list (\\textit{tail}) is reached. A Linked List does not have random access, and thus although given a specific node all operations (inserting a new node next to it, removing the node, getting its value or setting its value) are done in $O(1)$ time, doing the same operations given an \\textit{index} instead of a node are all done in $O(n)$ time (where $n$ is the length of the list), as, in the worst case, the entire list needs to be traveresed to access the node at that index and perform the operation.\n\n\\begin{figure}[hbp]\n\t\\centering\n\t\\textbf{A Singly Linked List}\\par\\medskip\n\t\\includegraphics[width=.5\\textwidth]{./img/singly_linked_list.png}\n\\end{figure}\n\\begin{figure}[hbp]\n\t\\centering\n\t\\textbf{A Doubly Linked List}\\par\\medskip\n\t\\includegraphics[width=.5\\textwidth]{./img/doubly_linked_list.png}\n\\end{figure}\n\\subsection{What is the Square Root List}\nThe \\textit{Square Root List} is an idea I had after examining Linked Lists in my Data Structures class and it is an attempt to improve on the runtime of the aforementioned operations by storing some extra pointers along with the real list. A second list is maintained, which stores pointers for about every $\\sqrt{n}$ elements of the main list, where $n$ is the length of the main list. When an element of the main list needs to be accessed, instead of traversing the main list directly, the appropriate element is selected from the secondary list as the traversal starting point, thus \"skipping\" over many elements; then the traversal of the main list starts and the element is reached. We will show later that this traversal is done in $O(\\sqrt{n})$ time.\n\\begin{figure}[hbp]\n\t\\centering\n\t\\textbf{A Square Root List}\\par\\medskip\n\t\\includegraphics[width=.7\\textwidth]{./img/square_root_list.png}\n\\end{figure}\n\\section{Operation Runtime for the Square Root List}\n\\subsection{Notes}\nBefore showing that the runtime is indeed what was claimed before, a point needs to be clarified. I said that the secondary list is about $\\sqrt{n}$ elements long. That \"about\" means the following: because add and remove operations are contantly changing the length $n$ of the list, instead of constantly keeping up with those changes, the list uses another number $m$ as a stand-in for the length of the list. $m$ is updated in the buildMeta() method of the class, where it is set to be equal to the real size of the list. buildMeta is only called when the size of the list has diverged too much from the value of $m$. When an insertion happens but the threshold for calling buildMeta is not surpassed, then retreat is called. retreat traverses the secondary list from the site of the insertion until the end and updates each stored node to be equal to its next node. This ensures that the chunks between two stored nodes remain equally sized and that the list works correctly. Similarly, when a removal happens, advance is called which works identically to retreat, but updates nodes to be their previous node instead of their next.\n\\subsection{Proofs}\nClaim: $\\sqrt{m}$ is bounded by $O(\\sqrt{n})$.\n\\begin{proof}\n\t$ $\\\\\n\tWe can see from the code that $m - \\sqrt{m} \\leq n \\leq m + \\sqrt{m}$, since when either of those bounds is exceeded, buildMeta is called and then $m = n$.\\\\\n\t$m - \\sqrt{m} \\leq n \\iff m - \\sqrt{m} - n \\leq 0$ (inequality (1))\\\\\n\tBy setting $x = \\sqrt{m}$ inequality (1) becomes $x^2 - x - n \\leq 0$ (inequality (2))\\\\\n\t$x^2 - x - n = 0 \\iff x = \\frac{1 + \\sqrt{1 + 4n}}{2} \\; or \\; x = \\frac{1 - \\sqrt{1 + 4n}}{2}$\\\\\n\tTherefore inequality (2) is satisfied by $\\frac{1 - \\sqrt{1 + 4n}}{2} \\leq x \\leq \\frac{1 + \\sqrt{1 + 4n}}{2}$.\\\\\n\tThis gives us that $0 \\leq \\sqrt{m} \\leq \\frac{1 + \\sqrt{1 + 4n}}{2}$.\\\\\n\t$\\sqrt{m} \\leq \\frac{1}{2} + \\frac{\\sqrt{1 + 4n}}{2} \\leq \\frac{\\sqrt{n}}{2} + \\frac{\\sqrt{5n}}{2}$\\\\\n\tThus $\\sqrt{m} \\leq \\frac{\\sqrt{5} + 1}{2}\\sqrt{n}$ and therefore $\\sqrt{m}$ is bounded by $O(\\sqrt{n})$.\n\n\\end{proof}\n\nClaim: The getNode(idx) method works in $O(\\sqrt{n})$ time.\n\\begin{proof}\n\t$ $\\\\\n\tThe appropriate starting node from the secondary list is selected in constant time. Then, a traversal is needed, from the node stored in the secondary list up to the desired index. That traversal has at most $\\sqrt{m}$ nodes, since, the secondary list stores one node every $\\sqrt{m}$ nodes. Thus, the entire traversal is at most $\\sqrt{m} - 1$ nodes long, which means that it is bounded by $O(\\sqrt{m})$ and thus $O(\\sqrt{n})$.\n\\end{proof}\n\nClaim: The get(idx) method works in $O(\\sqrt{n})$ time.\n\\begin{proof}\n\t$ $\\\\\n\tThe method consists of a single call to getNode(idx)a field access. Since getNode(idx) works in $O(\\sqrt{n})$ time, this method does too.\n\\end{proof}\n\nClaim: The set(idx) method works in $O(\\sqrt{n})$ time.\n\\begin{proof}\n\t$ $\\\\\n\tThe method consists of a single call to getNode(idx) and a value update. Since getNode(idx) works in $O(\\sqrt{n})$ time, this method does too.\n\\end{proof}\n\nClaim: The insert(val, idx) method works in amortized $O(\\sqrt{n})$ time.\n\\begin{proof}\n\t$ $\\\\\n\tThe method calls getNode(idx) which is $O(\\sqrt{n})$ and then creates a new node (which takes constant time with respect to the length of the list).\\\\\n\tIn every call it will make a call to retreat(inseartionIdx), which traverses the entire secondary list and thus takes $O(\\sqrt{m})$ time.\\\\\n\tOnce every $\\sqrt{m}$ calls it will make a call to $buildMeta()$ which traverses the entire main list so it takes $O(n)$ time. Distributing the cost of that call over the $\\sqrt{m}$ calls yields $O(\\frac{n}{\\sqrt{m}})$ time.\\\\\n\tTherefore, overall, insert(val, idx) runs in $O(\\sqrt{n}) + O(\\sqrt{m}) + O(\\frac{n}{\\sqrt{m}})$ time, which is bounded by $O(\\sqrt{n})$.\n\\end{proof}\n\nClaim: The remove(idx) method works in amortized $O(\\sqrt{n})$ time.\n\\begin{proof}\n\t$ $\\\\\n\tThis method works identically with the insert(val, idx) method, and therefore has the same runtime.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "96af491f0fa92b0414ba52de3a2932208e01bae9", "size": 7809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "runtime_proof.tex", "max_stars_repo_name": "petros-marko/sqrtlist", "max_stars_repo_head_hexsha": "4fadff6294eb7e8b002f6f6e1569eeb0e7509704", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-30T21:10:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-30T21:10:49.000Z", "max_issues_repo_path": "runtime_proof.tex", "max_issues_repo_name": "petros-marko/sqrtlist", "max_issues_repo_head_hexsha": "4fadff6294eb7e8b002f6f6e1569eeb0e7509704", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "runtime_proof.tex", "max_forks_repo_name": "petros-marko/sqrtlist", "max_forks_repo_head_hexsha": "4fadff6294eb7e8b002f6f6e1569eeb0e7509704", "max_forks_repo_licenses": ["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.9758064516, "max_line_length": 1134, "alphanum_fraction": 0.7351773595, "num_tokens": 2234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6018258956205927}}
{"text": "\n\\numberwithin{definition}{section}\n\\numberwithin{example}{section}\n\\numberwithin{equation}{section}\n\\numberwithin{figure}{section}\n\n\\addbibresource{../bib/taiga.bib}\n\\addbibresource{../bib/tex.bib}\n%-----------------------------------------------------------------\n\\title{Flat predictive models}\n\\author{\\textsc{John Alan McDonald }}\n\\date{draft of \\today}\n%-----------------------------------------------------------------\n\\begin{document}\n\\maketitle\n%-----------------------------------------------------------------\n\nTaiga's implementation of linear models is expressed in a way\nthat is different from the treatment in most statistics texts.\nI happen to think that Taiga's approach is simpler, and better, \nparticularly because it allows us to discuss these models as\nspecial cases of a general approach to predictive models.\nWhether you agree with that or not, you will need to understand\nTaiga's point of view if you want to use it successfullly.\n\n\\textit{Flat} means linear or affine.\n\n\\section{\\label{sec:Linear} Linear spaces and functions}\n\nA \\textit{real linear space} \n(commonly refered to as a\n\\textit{real vector space}) \n\\(\\mathbb{V}\\) is a set of elements, called vectors,\n\\(\\mathsf{v}_0\\), \\(\\mathsf{v}_1\\), \\ldots that is closed under \n\\textit{linear combinations}:\n\\begin{equation}\n\\mathsf{v} \\; = \\; a_0 \\mathsf{v}_0 \\, + \\, a_1 \\mathsf{v}_1 \n\\in \\mathbb{V}\n\\end{equation}\nfor all \\(a_0, a_1 \\in \\mathbb{R}\\).\nNote that \\(\\mathbb{R}\\) itself is a linear space under this\ndefinition.\n\n(This can be generalized to other scalar fields,\nbut \\(\\mathbb{R}\\) is sufficient for this discussion,\nand will be assumed in what follows.)\n\nA \\textit{linear function} \\(\\mathsf{f}\\) from linear space\n\\(\\mathbb{V}\\) to linear space \\(\\mathbb{W}\\) \npreserves linear combinations:\n\\begin{equation}\n\\mathsf{f}(a_0 \\mathsf{v}_0 + a_1 \\mathsf{v}_1 ) \n\\; = \\;\na_0 \\mathsf{f}(\\mathsf{v}_0) \\, + \\, \na_1 \\mathsf{f}(\\mathsf{v}_1)\n\\end{equation}\nA \\textit{linear functional} is just a real-valued linear\nfunction: \\(\\mathsf{f} : \\mathbb{V} \\rightarrow \\mathbb{R}\\).\n\nThe canonical linear space is \\(\\mathbb{R}^n\\),\nwhich we will take here to be the set of tuples of \\(n\\) real\nnumbers. Implementations in Clojure/Java will most often\napproximate real tuples with instances of \\texttt{double[n]},\noften with instances of classes wrapping \\texttt{double[n]},\nand occasionally with \\texttt{List<Number>.} \n\nNote that the set of linear functions between two linear\nspaces, \\(\\mathcal{L}(\\mathbb{V},\\mathbb{W})\\) is itself a linear\nspace. \n\nIn fact, given any set of functions \\(\\mathcal{F} = {\\mathsf{f} :\n\\mathbb{D} \\rightarrow \\mathbb{V}}\\), \nfrom any domain \\(\\mathbb{D}\\) to a \nlinear space \\(\\mathbb{V}\\),\nwe get a linear space by closing those functions under linear\ncombinations of their values:\n\\(\\mathbb{F} = \\{ \\mathsf{f}() = \\sum_i a_i\\mathsf{f_i}() \\; : \\;\n\\mathsf{f_i} \\in \\mathcal{F}, a_i \\in \\mathbb{R} \\}\\)\n\nSee Halmos \\cite{halmos-1958} for thorough background.\n\n\\section{Inner product space}\n\nAn \\textit{inner product space} is a linear space\ntogether with an \\textit{inner product}, a symmetric,\npositive semidefinite, bilinear function of 2 arguments:\n\\begin{equation}\n\\begin{split}\n\\mathrm{dot}(\\mathsf{v_0},\\mathsf{v_1}) & =\n\\mathrm{dot}(\\mathsf{v_1},\\mathsf{v_0}) \\\\\n\\mathrm{dot}(\\mathsf{v},\\mathsf{v}) & \\geq 0 \\\\\n\\mathrm{dot}(\\mathsf{v},a_0\\mathsf{v_0}+a_1\\mathsf{v_1}) & =\na_0\\mathrm{dot}(\\mathsf{v},\\mathsf{v_0}) + \na_1\\mathrm{dot}(\\mathsf{v},\\mathsf{v_1})\n\\end{split} \n\\end{equation}\n\nSkipping some details, we can identify\nthe linear functionals on an inner product space with the \nvectors in that space:\n\\begin{equation}\n\\mathsf{v}^{\\dagger}(\\mathsf{w}) =\n\\mathrm{dot}(\\mathsf{v},\\mathsf{w}) \\forall \\mathsf{w} \\in\n\\mathbb{V}\n\\end{equation}\n\nL2 norm is\n\\(\\|\\mathsf{v}\\|_2 = \\sqrt(\\mathrm{dot}(\\mathsf{v},\\mathsf{v})\n\\) \n\nL2 distance is \\(\\|\\mathsf{v_0}-\\mathsf{v_0}\\|_2 \\). \n\n\\section{\\label{sec:Affine} Affine spaces and functions}\n\nAn \\textit{affine space} is similar to a linear space, only\nclosed under \\textit{affine combinations} rather than linear.\nThat is,\n\\(\\mathbb{A}\\) is a set of elements, called points,\n\\(\\mathsf{p}_0\\), \\(\\mathsf{p}_1\\), \\ldots such that:\n\\begin{equation}\n\\mathsf{p} \\; = \\; a_0 \\mathsf{p}_0 \\, + \\, a_1 \\mathsf{p}_1 \n\\in \\mathbb{A} \\forall \\mathsf{p}_0, \\mathsf{p}_1 \\in\n\\mathbb{A}; a_0, a_1 \\in \\mathbb{R}; a_0 + a_1 = 1\n\\end{equation}\nfor all \\(a_0, a_1 \\in \\mathbb{R}\\).\nThe key distinction is the constraint that \\(a_0 + a_1 = 1\\).\n\nAbstract differences\\(\\rightarrow\\) linear translation space.\n\nNote that every linear space is automatically an affine space,\nbut not the reverse.\n\nA canonical example of an affine space that is not a linear\nspace is a hyperplane in \\(\\mathbb{R}^n\\) that doesn't go thru\nthe origin, such as the set of all vectors whose first\ncoordinate is 1. (TODO: picture of such a hyperplance in\n\\(\\mathbb{R}^2\\)).\n\nLinearization via equivalence classes of homogeneous\ncoordinates.\n\nImplementations:\n\\begin{enumerate}\n  \\item (Coordinate frame) Pick an origin. Identify elements\n  with elements of \\( \\mathbb{R}^n \\). An affine function on \n  \\( \\mathbb{R}^{m} \\mapsto \\mathbb{R}^n \\) is a linear\n  function plus an 'intercept' term in \\( \\mathbb{R}^n \\).\n  \\item (Linear Lifting) Identity elements with equivalence\n  classes in \\( \\mathbb{R}^{n+1} \\). \n  \\( [p_0, p_1, \\ldots, p_n] \\sim [p_0/p_n, p_1/p_n, \\ldots, 1]\n  \\). Every linear function \\(\\mathbb{R}^{m+1} \\mapsto\n  \\mathbb{R}^{n+1} \\) is an affine function on the equivalence classes.\n\\end{enumerate}\n\n\\section{Euclidean space}\n\n Affine space where translation space is an inner product space.\n \n\\section{Flat predictive models}\n\nIdea is to restrict model space to linear or affine functions.\nAlthough still probably taught as the default model type,\nvery tricky to use well. Rigidity leads to lack of\nexpressiveness and instability, change any training data can\nhave unbounded effects on predictions far from the change.\n\n\\section{Embedding data in flat spaces}\n\nPractical issue is that linear functions only make sense on\nlinear domains; affine on affine domains (which includes\nlinear.)\n\nData comes as lists of records, with attributes some of whose\nvalues are numerical, but many taking value in more complicated\ndomains (eg an address).\n\nClojure implementation: record = object; dataset = list of\nrecords; attribute = function.\n\nAfter numerical attributes, the next simplest are probably\ncategorical, by which I mean an attribute whose values fall in\nsome finite set. Tricky issue is whether the set of possible\nvalue is know ahead of time (usually assumed and usually wrong)\nor whether every new data set may have new values\n(eg USA set of states might change, more common is need to cover\nterritories missing from a training set, etc.)\n\nWhatever set of attributes we start with, we will need to\nconstruct an embedding of the record objects into a flat space.\n\n\\section{Regression}\n\nCodomain is \\( \\mathbb{R} \\), so we want flat functionals.\nComplete model is \\( \\mathsf{g} : \\mathbb{D} \\rightarrow\n\\mathbb{R} \\) constructed from \n\\( \\mathsf{e} : \\mathbb{D} \\rightarrow \\mathbb{F}^n \\)\nand \n\\( \\mathsf{f} : \\mathbb{F}^n \\rightarrow \\mathbb{R} \\) \nvia \\( \\mathsf{g} = \\mathsf{f} \\circ \\mathsf{e} \\). \n\n\\section{Training by minimizing L2 cost}\n\n\\section{Training by minimizing L1 and quantile cost}\n\n\\section{Regularization}\n\n'Ridge regression' = minimize L2 norm of parameter vector;\n'Lasso' = L1 norm.\nNeither makes sense\n\\newpage{}\n\\input{../tex/typesetting}\n\\input{../tex/tail}\n\\end{document}\n", "meta": {"hexsha": "292300286b052a4e8e40b112a2a99064705c14ed", "size": 7539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/flat/flat-models-body.tex", "max_stars_repo_name": "wahpenayo/taiga", "max_stars_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-02T01:14:37.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-30T14:29:40.000Z", "max_issues_repo_path": "doc/flat/flat-models-body.tex", "max_issues_repo_name": "wahpenayo/taiga", "max_issues_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-10-24T18:35:41.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-24T18:35:41.000Z", "max_forks_repo_path": "doc/flat/flat-models-body.tex", "max_forks_repo_name": "wahpenayo/taiga", "max_forks_repo_head_hexsha": "9d142149240f3f5db5dd8fbfbc0ce0552b81d490", "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.2289719626, "max_line_length": 71, "alphanum_fraction": 0.7028783658, "num_tokens": 2333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6018258907416122}}
{"text": "\n\\documentclass[letterpaper,11pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[margin=1in,nohead]{geometry}\n\\usepackage{tikz}\n\n\\newcommand{\\sR}{\\mathbb{R}}\n\n\\newcommand{\\figlab}[1]{\\label{fig:#1}}\n\\newcommand{\\figref}[1]{Figure~\\ref{fig:#1}}\n\n\\tikzstyle{coordaxis}=[draw=red!50!black, thick, ->]\n\\tikzstyle{mapping}=[draw=blue!50!black, thick, ->]\n\\tikzstyle{connect}=[draw=green!50!black, thick, ->]\n\n\\author{Carsten Burstedde}\n\\title{Documentation on octree and quadrant connectivity}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Mappings between octrees and physical space}\n\nSee \\figref{octreemap} for an illustration.\n\n\\begin{figure}[b!]\n\\centering\n\\begin{tikzpicture}\n  % first tree\n  \\begin{scope}[xshift=0cm]\n  \\draw (0,0) rectangle (3,3) node (m1) [midway] {$k_1$};\n  \\draw [style=coordaxis] (0,0) -- (1.5,0) node [below] {$x_1$};\n  \\draw [style=coordaxis] (0,0) -- (0,1.5) node [left] {$y_1$};\n  \\filldraw (3,0.75) node (r1) {} circle (2pt) node [left] {$r_1$};\n  \\end{scope}\n\n  % second tree\n  \\begin{scope}[xshift=4.4cm]\n  \\draw (0,0) rectangle (3,3) node (m2) [midway] {$k_2$};\n  \\draw [style=coordaxis] (3,3) -- (3,1.5) node [right] {$x_2$};\n  \\draw [style=coordaxis] (3,3) -- (1.5,3) node [above] {$y_2$};\n  \\filldraw (0,0.75) node (r2) {} circle (2pt) node [right] {$r_2$};\n  \\end{scope}\n\n  % physical space\n  \\begin{scope}[xshift=1.2cm, yshift=4cm]\n  \\draw (0,0) to [bend left=20] (5,1) node (pm1) [midway] {}\n              to [bend left=10] (6,3)\n              to [bend right=20] (-1,2) node (pm2) [midway] {}\n              to [bend right=10] (0,0);\n  \\draw (pm1.center) to [bend left=5] (pm2.center) node (pmm) [pos=.25] {};\n  \\filldraw (pmm) circle (2pt) node [above right] {$p \\in \\sR^3$};\n  \\end{scope}\n\n  % connections\n  \\draw [connect] (r1) to [bend right=20] (r2)\n        node [midway, below] {$T_{1,2}$};\n  \\draw [connect] (r2) to [bend right=20] (r1)\n        node [midway, above] {$T_{2,1}$};\n  \\draw [mapping] (r1) to [bend left=40] (pmm) node [pos=0.55, left] {$\\phi_1$};\n  \\draw [mapping] (r2) to [bend right=40] (pmm) node [pos=0.6, right] {$\\phi_2$};\n\n\\end{tikzpicture}\n\\caption{%\nTwo octrees $k_1$ and $k_2$ and their individual octree coordinate systems\n(red).  Quadrant coordinates at subdivision level $\\ell \\ge 0$ (not shown) are\ndiscrete numbers that are integer multiples of $2^{-\\ell}$.  In this example\nthe octrees connect through a common face, which defines coordinate\ntransformations $T_{1,2} = T_{2,1}^{-1}$ across this face.  The octree points\n$r_1 = (1, \\frac14)$ and $r_2 = (\\frac34, 1)$ are identified: $T_{i,j}(r_i) =\nr_j$ (green).  This identification is specified solely based on the\nconnectivity relation between the two octrees.  The functions $T_i$ can be\nimplemented in integer arithmetic, entirely without using physical coordinates.\nTo map the octrees to physical space, geometry transformations $\\phi_1$,\n$\\phi_2$ (blue) are introduced that satisfy the compatibility condition $p =\n\\phi_1 (r_1) = \\phi_2 (r_2)$.  This offers the alternate identification\ncriterion $r_j = (\\phi_j ^{-1} \\circ \\phi_i) (r_i)$.  However, this approach is\nnot recommended since it is much more expensive and, more importantly, depends\non the floating-point functions $\\phi_i$ that suffer from roundoff error and\nmake it difficult to determine uniqueness.\n}\n\\figlab{octreemap}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "5de1840644b87d6ef981ec9c3d9c7a5756e6f6ed", "size": 3355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sites/workstation/gcc/p4est/doc/tex/octreemap.tex", "max_stars_repo_name": "jmark/p4wrap", "max_stars_repo_head_hexsha": "6d237ab8fbe03c8ca985778ac1f65678ecbcccb3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-06-02T12:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-27T14:29:52.000Z", "max_issues_repo_path": "sites/workstation/gcc/p4est/doc/tex/octreemap.tex", "max_issues_repo_name": "jmark/p4wrap", "max_issues_repo_head_hexsha": "6d237ab8fbe03c8ca985778ac1f65678ecbcccb3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sites/workstation/gcc/p4est/doc/tex/octreemap.tex", "max_forks_repo_name": "jmark/p4wrap", "max_forks_repo_head_hexsha": "6d237ab8fbe03c8ca985778ac1f65678ecbcccb3", "max_forks_repo_licenses": ["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.6966292135, "max_line_length": 81, "alphanum_fraction": 0.6670640835, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6018258894044645}}
{"text": "\\chapter{Domain adaptation using Monge mappings}\n\n\\section*{Introduction}\nPreviously, we discussed two methods of regularized optimal transport for domain adaptation:\n\\begin{itemize}\n\t\\item Entropic regularization\n\t\\item Regularization with respect to dual potentials\n\\end{itemize}\n\nHowever, the emphasis earlier was not on finding the explicit mapping between datasets. One may instead seek to directly estimate the Monge map between source and target datasets. In this chapter, we show how to establish the optimal linear transport map under arbitrary distributions with finite second moments, demonstrate that this is also the optimal transport map, and propose another regularization scheme that incorporates the explicit transport map. The first result was also discovered concurrently by \\cite{Flamary2019}.\n\n\\section*{Linear Monge Mappings}\nPrevious work \\cite{Flamary2019} estimated the linear Monge mapping between Gaussian distributions and used this to provide a domain adaptation generalization bound.\n\nWe show why estimating the linear Monge map may be of importance if we know the second-order moments. And, as stated previously, the optimal linear transport map is the optimal transport map in this setting.\n\n%We conjecture that their result about the optimal transport map can be extended to say that this particular function of the second moments of the source and target distributions gives the optimal linear transport map, even if the optimal transport map isn't linear.\n\n%This corresponds to finding a solution to\n%$$\\min_A (E_P \\frac{1}{2} x'Ax + E_Q \\frac{1}{2} y'A^{-1}y),$$ which can be rewritten as \n%$$\\min_A Tr(A E_P xx' + A^{-1} E_Q yy')/2.$$\n\n\\section*{Notation}\n\nLet $A$ and $B$ be positive matrices.\n\n\\begin{definition}\n\tAn $n\\times n$ symmetric matrix $M$ is a positive matrix if and only if $x^{'} M x>0$ for all $x\\in \\mathbb{R}^n$.\n\\end{definition}\n\nAnd we also introduce the concept of fidelity measure between matrices. \n\n\\begin{definition}[Fidelity]\n\tIf $A$ and $B$ are positive matrices, then the fidelity $F(A,B) = tr(A^{1/2}BA^{1/2})^{1/2}$.\n\\end{definition}\n\nAlso let $A\\#B=A^{1/2}(A^{-1/2}BA^{-1/2})^{1/2}A^{1/2}$ be the matrix geometric mean. With this established, we can introduce our main lemma.\n\n\\begin{lemma}\n\tLet $\\mu_1$ and $\\mu_2$ be probability measures with zero means and positive-definite covariance matrices $A,B$ respectively. Then the optimal linear transport map coincides with the optimal transport map.\n\\end{lemma}\n\n\\section*{Minimizing over set of linear maps \\cite{Bhatia2019}}\nLet $x$ and $y$ be random vectors with values in $\\mathbb{C}^{n}$, each having zero mean WLOG, and with covariance matrices $A$ and $B$, respectively. This last statement means that\n\\begin{center}\n\t$A=[E(\\overline{x}_{i}x_{j})],\\ B=[E(\\overline{y}_{i}y_{j})]$.\n\\end{center}\n\nWe want to find $x$ and $y$ for which $E\\Vert x-y\\Vert^{2}$ is minimal.\n\nThe covariance matrix of the vector $(x,\\ y)$ is\n\n$$\n\\left[ \\begin{matrix}\n\t[E(\\overline{x}_{i}x_{j})] & [E(\\overline{x}_{i}y_{j})] \\\\\n\t[E(\\overline{y}_{i}x_{j})] & [E(\\overline{y}_{i}y_{j})]\n\\end{matrix}\\right]\n=\n\\left[ \\begin{matrix}\n\tA & M \\\\\n\tM^{*} & B\n\\end{matrix}\\right]\n$$\n\nWe seek to minimize the following:\n\\begin{align*}\nE\\Vert x-y\\Vert^{2} &= E(\\displaystyle \\sum_{i=1}^{n}(|x_{i}|^{2}+|y_{i}|^{2}-2\\mathrm{Re}\\overline{x}_{i}y_{i})) \\\\\n&= \\sum_{i=1}^{n}E(|x_{i}|^{2}+|y_{i}|^{2}-2\\mathrm{Re}\\overline{x}_{i}y_{i}) \\\\\n&= \\mathrm{tr}(A+B)-2\\mathrm{Re} (tr M).\n\\end{align*}\n\nThis is equivalent to the following optimization problem:\n\n$\\displaystyle \\max\\{|\\mathrm{tr}M|$ : $C=\\left[ \\begin{matrix}\n\tA & M \\\\\n\tM^{*} & B\n\\end{matrix}\\right] \\geq 0\\}.$\n\nThe value of the maximum is $F(A,\\ B)$. So\n$$\n\\min E\\Vert x-y\\Vert^{2}\\ =\\ \\mathrm{t}\\mathrm{r}(A+B)-2\\mathrm{t}\\mathrm{r}(A^{1/2}BA^{1/2})^{1/2}\n$$\n$$\n=\\ d^{2}(A,\\ B).\n$$\n\nLet $x$ be a vector with mean $0$ and covariance matrix $A$. Then for any $T\\in \\mathrm{F}\\mathrm{M}(n)$ we have\n\n\\begin{align*}\nE(\\langle x,\\ Tx\\rangle)\\ &= E(\\sum_{i,j}t_{ij}\\overline{x_{i}}x_{j}) =\\sum_{i,j}t_{ij}E(\\overline{x_{i}}x_{j}) \\\\\n&= \\displaystyle \\sum_{i,j}t_{ij}a_{ij}=\\mathrm{tr} TA.\n\\end{align*}\n\nHence,\n\\begin{align*}\nE\\Vert x-Tx\\Vert^{2} &= E(\\Vert x\\Vert^{2}+\\Vert Tx\\Vert^{2} - 2\\textrm{Re}\\langle x,\\ Tx\\rangle) \\\\\t\n&= \\textrm{tr}A+\\textrm{tr}T^{*}TA-2\\textrm{Re} \\textrm{tr} TA \\\\\n&= \\textrm{tr} A+\\textrm{tr}TAT^{*}-2\\textrm{Re} \\textrm{tr} A^{1/2}TA^{1/2}\n\\end{align*}\n\nIf we choose $T=A^{-1}\\# B$, then  we see that tr $A^{1/2}TA^{1/2}=$ tr $(A^{1/2}BA^{1/2})^{1/2}$, and that $\\mathrm{tr}TAT=\\mathrm{tr}B$. Thus, for this choice of $T$, we have\n\\begin{center}\n\t$$E\\Vert x-Tx\\Vert^{2} = tr(A+B)-2 tr (A^{1/2}BA^{1/2})^{1/2}\n\t=\\ d^{2}(A,\\ B)\\ .\n\t$$\n\\end{center}\nThus the problem\n$$\n\\min E\\Vert x-y\\Vert^{2}\n$$\nwhere $x, y$ are vectors with mean zero and covariance matrices $A$ and $B,$ respectively, has as its solution the pairs $(x,\\ y)$ , where $x$ is any vector and $y=Tx$, with $T=A^{-1}\\# B$.\n\nLet $x$ be a vector with covariance matrix $A$, and let $y=Tx$. Then\n$$\nE(\\overline{y}_{i}y_{j})\\ =\\ E\\sum_{k,l}t_{ik}t_{kl}\\overline{x}_{k}x_{l}\n$$\n$$\n=\\ \\sum_{k,l}t_{ik}t_{kl}a_{kl}=(TAT)_{ij}.\n$$\nIf $T$ is the optimal transport map from $A$ to $B$, then $TAT=B$. This shows that the covariance matrix of the vector $y$ is $B.$\n\n%\\section*{Which cross-covariance matrices are feasible with given marginal distributions?}\n%\n%If we have marginal distributions $P$ and $Q$ we want to determine possible cross-covariances between the two distributions. Let $M$ denote the cross-covariance between $\\mu$ and $\\nu$.\n%\n%\\subsection*{What if we knew the marginal covariances?}\n%In the case where we know $\\Sigma_{P}$ and $\\Sigma_{Q}$, we have necessary and sufficient conditions for the block matrix\n%$$\n%\\left( \\begin{matrix}\n%\t\\Sigma_{P} & M \\\\\n%\tM^{*} & \\Sigma_{Q}\n%\\end{matrix}\\right) \n%$$\n%\n%to be PSD. \n%\n%These conditions are the following:\n%\\begin{enumerate}\n%\t\\item $A\\geq M\\Sigma_{Q}^{-1}M^{*}$\n%\t\\item There exists a contraction operator $K$ with $\\norm{K}\\leq 1$ such that $$M=\\Sigma_{P}^{1/2}K\\Sigma_{Q}^{1/2}.$$\n%\\end{enumerate}\n\n%\\subsection*{General Case}\n%Back to our setting, we don't necessarily know the covariance matrices on the marginals.\n%\n%Consider the discrete setting where the distributions $\\mu$ and $\\nu$ can be represented by probability vectors $p$ and $q$. Also let $X$ and $Y$ represent random vectors from $\\mu$ and $\\nu$ and define the respective covariance matrices as $\\Sigma_X$ and $\\Sigma_Y$.\n%\n%Transform $X$ and $Y$ as follows\n%\\begin{align*}\n%\t\\tilde{X} &= diag(\\sqrt{p})X \\\\\n%\t\\tilde{Y} &= diag(\\sqrt{q})Y \\\\\n%\t\\tilde{P} &= diag(1/\\sqrt{p})\\cdot diag(1/\\sqrt{q})\n%\\end{align*}\n%\n%Let $$K=(X^{\\perp}diag(\\sqrt{p})X)^{-1/2}(X^{\\perp}PY)(Y^{\\perp}diag(\\sqrt{q})Y)^{-1/2}.$$\n%\n%Note that\n%$$\\tilde{X}^{\\perp}\\tilde{P}\\tilde{Y}=X^{\\perp}PY=\\Sigma_{XY}=\\Sigma_X^{1/2}K\\Sigma_Y^{1/2}$$\n%\n%We now want to solve the following optimization problem:\n%\n%Maximize $$\\norm{K\\Sigma_{\\nu}^{1/2}}_{\\mathcal{F}}$$ where\n%$P$ satisfies constraints \n%\\begin{align*}\n%\tP\\vec{1} &=p \\\\\n%\tP^{\\perp}\\vec{1} &=q.\n%\\end{align*}\n%\n%\\subsection*{Pythagorean identity for Wasserstein}\n%\n%\\begin{equation}\n%\tW(P,Q)=\\inf_T[d(P,T_{\\#}P)+W(T_{\\#}P,Q)].\n%\\end{equation}\n%\n%Indeed, \n%\\begin{align*}\n%\td(P,T_{\\#}P)+W(T_{\\#}P,Q)&=\\inf_\\gamma\\Big[\\sqrt{\\int_{S\\times S}(x-T(x))^2\\gamma(dx,dy)}+\\sqrt{\\int_{S\\times S}(T(x)-y)^2\\gamma(dx,dy)}\\Big] \\\\\n%\t&\\ge\\inf_\\gamma\\sqrt{\\int_{S\\times S}(x-y)^2\\gamma(dx,dy)}=W(P,Q)\n%\\end{align*}\n%where $\\inf\\limits_\\gamma$ is taken over all couplings $\\gamma$ of $P$ and $Q$. So, the right-hand side of (1) is no less than its left-hand side. On the other hand, taking $T$ to be the identity map of $S$, we see that the right-hand side of (1) is no greater than its left-hand side. Thus, (1) is proved. \n\n%\n%\\section*{A Two-Step Computation for Wasserstein}\n%Define $$d^2(p,q) = E\\norm{X-Y}^2$$ with $X\\sim p$ and $Y\\sim q.$\n%\n%We conjecture that $W^2(p,q) = \\min_{T} d^2(p,T_{\\#}p) + W^2(T_{\\#}p,q)$ where $T$ is the set of linear mappings. This is promising since if $T$ is chosen to be either the identity map or $\\Sigma_X^{-1}\\#\\Sigma_Y$, then $d^2(p,T_{\\#}p) + W^2(T_{\\#}p,q) = W^2(p,q)$.\n%\n%One could extend the set $T$ to a set of mappings closed under addition and composition (i.e. $f,g\\in T$ implies $f+g$ and $f(g)\\in T$) as well.\n%\n%This idea is similar to the concept of $I$-projection for KL-divergences. I'm not sure if this will hold because the I-projection concept extends to Bregman divergences, but the Wasserstein isn't a Bregman type.\n%\n%\\subsection*{Counterexample to our claim}\n%Suppose that the underlying measurable space \n%$(S,\\Si)$ on which $P$ and $Q$ are defined is $(\\R,\\B(\\R))$, where $\\B(\\R)$ is the Borel $\\sigma$-algebra over $\\R$. Let $P$ be the uniform distribution on $(0,1)$. Then any distribution $R$ on $(\\R,\\B(\\R))$ is of the form $T_{\\#}P$ for some $T$; namely, $T$ is the quantile transformation given by the formula \n%$$T(u)=H^{-1}(u):=\\inf\\{x\\in\\R\\colon H(x)\\ge u\\}$$ \n%for $u\\in(0,1)$, where $H$ is the cdf of the distribution $R$. Let $Q$ be any distribution on $(\\R,\\B(\\R))$ other than $P$. There are real-valued random variables (r.v.'s) $X$ and $Y$ with respective distributions $P$ and $Q$ such that $W^2(P,Q)=E(X-Y)^2$; for instance, take any r.v. $X\\sim P$ and let then $Y:=G^{-1}(X)$, where $G$ is the cdf of $Q$. Now let $Z:=(X+Y)/2$ and let $R$ be the distribution of $Z$. Then the right-hand side of our conjectured identity is \n%$$\\le d^2(P,R) + W^2(R,Q)\\le E(X-Z)^2+E(Z-Y)^2=\\frac12\\,E(X-Y)^2=\\frac12\\,W^2(P,Q)<W^2(P,Q);$$\n%the latter inequality holding because $Q\\ne P$.\n%\n%\\section*{What if $Q$ corresponds to a subspace?}\n%Here, one must generalize the claim\n%$$F(\\Sigma_X,\\Sigma_Y) = \\max_{M>0} \\{ \\abs{trX}: \\Sigma_X\\geq M\\Sigma_Y^{-1}M^{*}\\}$$ to the case where $\\Sigma_Y$ is not full rank.\n%\n%First, let's introduce the following lemma.\n%\\begin{lemma}\n%\t$$\n%\t\\left( \\begin{matrix}\n%\t\t\\Sigma_{X} & M \\\\\n%\t\tM^{*} & \\Sigma_{Y}\n%\t\\end{matrix}\\right)\n%\t$$\n%\t is PSD if $\\Sigma_{X}\\geq M\\Sigma_{Y}^{+}M^{*}$, where $\\Sigma_Y^{+}$ denotes the pseudoinverse of $\\Sigma_Y$.\n%\\end{lemma}\n%\n%\\begin{proof}\n%$$\n%\t\\left( \\begin{matrix}\n%\t\t\\Sigma_{X}-M\\Sigma_{Y}^{+}M^{*} & O \\\\\n%\t\tO & \\Sigma_{Y}\n%\t\\end{matrix}\\right)\\sim\n%\t\\left( \\begin{matrix}\n%\t\tI & M\\Sigma_{Y}^{+} \\\\\n%\t\tO & I\n%\t\\end{matrix}\\right)\n%\t\\left( \\begin{matrix}\n%\t\t\\Sigma_{X}-M\\Sigma_{Y}^{+}M^{*} & O \\\\\n%\t\tO & \\Sigma_{Y}\n%\t\\end{matrix}\\right)\n%\t\\left( \\begin{matrix}\n%\t\tI & O \\\\\n%\t\t\\Sigma_{Y}^{+}M^{*} & I\n%\t\\end{matrix}\\right)\n%= \t\\left( \\begin{matrix}\n%\t\\Sigma_{X} & M \\\\\n%\tM^{*} & \\Sigma_{Y}\n%\\end{matrix}\\right).\n%$$\n%\n%It is clear from this that $\\left( \\begin{matrix}\n%\\Sigma_{X} & M \\\\\n%M^{*} & \\Sigma_{Y}\n%\\end{matrix}\\right)$ is positive if and only if $\\Sigma_{X}- M\\Sigma_{Y}^{+}M^{*}\\geq 0.$\n%\\end{proof}\n%\n%One also notes that the positive-definiteness of the cross-covariance matrix implies\n%$$\n%M=\\Sigma_X^{1/2}K\\Sigma_Y^{1/2},\n%$$\n%where $K$ is a contraction. By the Schwarz inequality we have\n%\n%\\begin{align*}\n%\t|\\mathrm{tr}M|=|\\mathrm{tr}(\\Sigma_X^{1/2}K\\Sigma_Y^{1/2})|\\ &\\leq \\norm*{\\Sigma_X^{1/2}K}_2 \\norm*{\\Sigma_Y^{1/2}}_2 \\\\\n%\t&\\leq \\norm*{\\Sigma_X^{1/2}}_2 \\norm*{\\Sigma_Y^{1/2}}_2 = \\sqrt{\\textrm{tr}\\Sigma_X\\textrm{tr}\\Sigma_Y}\n%\\end{align*}\n%\n%If $$\n%\\left( \\begin{matrix}\n%\t\\Sigma_{X} & M \\\\\n%\tM^{*} & \\Sigma_{Y}\n%\\end{matrix}\\right) \\geq 0\n%$$\n%then for every $Z>0$ we have\n%\n%$$\n%\t0\\leq\n%\t\\left( \\begin{matrix}\n%\t\tZ^{1/2} & O \\\\\n%\t\tO & Z^{-1/2}\n%\t\\end{matrix}\\right)\n%\t\\left( \\begin{matrix}\n%\t\t\\Sigma_{X} & M \\\\\n%\t\tM^{*} & \\Sigma_{Y}\n%\t\\end{matrix}\\right)\n%\t\\left( \\begin{matrix}\n%\t\tZ^{1/2} & O \\\\\n%\t\tO & Z^{-1/2}\n%\t\\end{matrix}\\right)\n%\t= \\left( \\begin{matrix}\n%\t\tZ^{1/2}\\Sigma_X Z^{1/2} & Z^{1/2}M Z^{-1/2} \\\\\n%\t\tZ^{-1/2}M^{*} Z^{1/2} & Z^{-1/2}\\Sigma_Y Z^{-1/2}\n%\t\\end{matrix}\\right)\n%$$\n%\n%Hence\n%$$\n%|\\mathrm{tr}Z^{1/2}M Z^{-1/2}|\\leq\\sqrt{\\mathrm{tr}(Z^{1/2}\\Sigma_X Z^{1/2})\\mathrm{tr}(Z^{-1/2}\\Sigma_Y Z^{-1/2})}.\n%$$\n%\n%This simplifies to\n%$$\n%|\\mathrm{tr}M|\\leq\\sqrt{\\mathrm{tr}(\\Sigma_X Z)\\mathrm{tr}(\\Sigma_Y Z^{-1})}.\n%$$\n%\n%This is true for all $M$ satisfying the condition $\\Sigma_{X}\\geq M\\Sigma_{Y}^{+}M^{*}$ and for all $Z>0$. So\n%\n%$$\n% \\max\\{|\\mathrm{tr}M|\\ :\\ \\Sigma_{X}\\geq M\\Sigma_{Y}^{+}M^{*}\\} \\leq \\min_{Z>0} \\sqrt{\\mathrm{tr}(\\Sigma_X Z)\\mathrm{tr}(\\Sigma_Y Z^{-1})}\n%$$\n%\n%Showing equality is a problem I'm having at the moment.\n%\\blacksquare\n\n%\\subsection*{Parts I Need To Clarify}\n%Why do we use $\\norm{K\\Sigma_{Y}^{1/2}}_{\\mathcal{F}}$?\n%And what was the closed set we could extend to from the set of linear mappings (for the two-step Wasserstein computation)?\n%\n\\section*{Regularized Optimization}\nOne may want to look at a regularization of the combination of the squared Bures distance and the expected distance moved under the transport map $T$ by the squared Hilbert-Schmidt norm of $T$.\n$$\n\\min_T Q(T) \\textrm{ where }Q(T) = \\lambda E \\left\\| TX-X \\right\\|^2 + d_B^2(Cov(TX),\\Sigma_v) + \\mu \\left\\|T\\right\\|^2_{HS}\n$$\n\nDifferentiating $Q(T)$, we get \n$$2\\lambda (TX-X)X^{T} + (\\frac{2}{n-1})CTX(I-(BA)^{-1/2}B)X^{T} + 2\\mu T$$ where $A=Cov(TX)=(\\frac{1}{n-1})(TX)^T C(TX)$, $B=\\Sigma_v$, and $C=(1-\\frac{1}{n}J)=C^T$ is a centering matrix.\n\nSolving for $\\hat{T}$ such that $Q'(\\hat{T})=0$, we get\n\n$$\n\\lambda XX^{T} = \\lambda \\hat{T} XX^{T} + \\mu \\hat{T} + \\frac{1}{n-1} C\\hat{T}[X(I-(BA)^{-1/2}B)]X^{T}.\n$$\n\n\\subsection*{Differentiating the Bures distance part I}\nFor PSD matrices a drastic \nsimplification is possible:\n$$\n\\textrm {Tr}((A^{1/2}BA^{1/2})^{1/2}) = \\textrm{Tr}((BA)^{1/2})\n$$\nIn addition, there is a general result for the differential of the trace of any matrix function\n$$\nd\\,\\textrm{Tr}\\big(f(X)\\big) = f'(X^T):dX\n$$\nwhere $f'$ is the ordinary derivative of the scalar function $f;\\,$ both $f$ and $f'$ are evaluated using their respective matrix arguments.\n\nCombining these yields a straightforward solution for the problematic term\n\\begin{align*}\n\t\\phi &= \\textrm {Tr}\\Big((BA)^{1/2}\\Big) \\\\\n\td\\phi\n\t&=  \\tfrac 12\\big((BA)^T\\big)^{-1/2}:d(BA) \\\\\n\t&= \\tfrac 12(AB)^{-1/2}:B\\,dA \\\\\n\t&= \\tfrac 12 B(AB)^{-1/2}:dA \\\\\n\t\\frac{\\partial\\phi}{\\partial A}\n\t&= \\tfrac 12 B(AB)^{-1/2} \n\t\\;=\\; \\tfrac 12 (BA)^{-1/2}B\n\\end{align*}\nWhere the final equality is a theorem due to Higham\n$$B\\cdot f(AB) = f(BA)\\cdot B$$\n\nTherefore the gradient of the Bures Distance is\n\\begin{align*}\n\t\\beta(A,B) &= \\textrm {Tr}\\Big(A+B - 2(BA)^{1/2} \\Big) \\\\\n\td\\beta &= \\Big(I - B(AB)^{-1/2}\\Big):dA \\\\\n\t\\frac{\\partial\\beta}{\\partial A}\n\t&= I - B(AB)^{-1/2} \\;\\;=\\; I - (BA)^{-1/2}B \\\\\n\t&= I - A^{-1}(AB)^{1/2} \\;=\\; I - (BA)^{1/2}A^{-1}\n\\end{align*}\n\n\\subsection*{Differentiating the Bures distance part II}\nLet $J$ be the all-ones matrix and \n\\begin{align*}\n\tC &=(I-\\tfrac 1nJ) = C^T \\qquad\\qquad\\big(\\textrm{ Centering\\,Matrix}\\big) \\\\\n\tB &= \\Sigma_v \\\\\n\tA &= \\textrm{Cov}(TX) \\\\\n\t&= \\left(\\tfrac 1{n-1}\\right)(TX)^TC\\,(TX)\n\\end{align*}\n\nFrom earlier, the Bures distance function and its differential can be simplified to\n\\begin{align*}\n\t\\beta(A,B) &= \\textrm{Tr}\\Big(A+B - 2(BA)^{1/2} \\Big) \\\\\n\td\\beta &=\\Big(I - (BA)^{-1/2}B\\Big):dA\n\\end{align*}\nNow change the differentiation variable from $\\;dA\\to dT$.\n\\begin{align*}\n\td\\beta\n\t&= \\Big(I - (BA)^{-1/2}B\\Big):\\left(\\tfrac 2{n-1}\\right)\\textrm{ Sym}(X^TT^TC\\,dT\\,X) \\\\\n\t&= \\left(\\tfrac 2{n-1}\\right)\\Big(I - (BA)^{-1/2}B\\Big):(X^TT^TC\\,dT\\,X) \\\\\n\t&= \\left(\\tfrac 2{n-1}\\right)CTX\\Big(I - (BA)^{-1/2}B\\Big)X^T:dT \\\\\n\t\\frac{\\partial\\beta}{\\partial T}\n\t&= \\left(\\tfrac 2{n-1}\\right)CTX\\Big(I - (BA)^{-1/2}B\\Big)X^T \\\\\n\\end{align*}\n\nIn the above derivation, the function \n\\begin{align*}\n\t\\textrm{Sym}(M) = \\tfrac 12(M+M^T) \\\\\n\\end{align*}\nwas utilized, as well as the trace/Frobenius product\n\\begin{align*}\n\tP:M = \\textrm{Tr}(P^TM) = \\textrm{Tr}(M^TP) = M:P \\\\\n\\end{align*}\nThese have the following interaction \n\\begin{align*}\n\tP:\\textrm{Sym}(M) = \\textrm{Sym}(P):M \\\\\n\\end{align*}", "meta": {"hexsha": "6fe1926a1a1926bf223e9a22e0e86ef47ad2e0d3", "size": 15892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap3(pjd).tex", "max_stars_repo_name": "pitcany/dissertation", "max_stars_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chap3(pjd).tex", "max_issues_repo_name": "pitcany/dissertation", "max_issues_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chap3(pjd).tex", "max_forks_repo_name": "pitcany/dissertation", "max_forks_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_forks_repo_licenses": ["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.5408163265, "max_line_length": 530, "alphanum_fraction": 0.6371759376, "num_tokens": 6038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6018258878504323}}
{"text": "% Preamble.\n\\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%% Title macros.\n\\newcommand{\\HOMEWORKNUM}{19}\n\\newcommand{\\NAME}{D. Choi}\n\\newcommand{\\DATE}{2020-06-22}\n\n\\title{\\vspace{-2\\baselineskip}MATH 225 - Homework \\#\\HOMEWORKNUM}\n\\author{\\NAME}\n\\date{\\DATE}\n\n%% Formatting options.\n%\\pagenumbering{gobble}  % Include for single-page document.\n\n% Macros.\n%% Contextualized by input/output bases.\n\\newcommand{\\based}[3]{{\\{#1\\}}_{#2}^{#3}}\n\n\n% Document.\n\\begin{document}\n\\maketitle\n\n\\section*{1.}\n\\textit{Let $\\mathcal{S}$ be the standard basis, and let}\n\\begin{gather*}\n\t\\mathcal{A}\n\t=\n\t\\left\\{\n\t\t\\begin{pmatrix} -1 \\\\ 0 \\end{pmatrix},\n\t\t\\begin{pmatrix} 0 \\\\ -1 \\end{pmatrix}\n\t\\right\\}\n\t,\n\t\\\\\n\t\\mathcal{B}\n\t=\n\t\\left\\{\n\t\t\\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix},\n\t\t\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}\n\t\\right\\}\n\t.\n\\end{gather*}\n\\textit{Also, let}\n\\begin{equation*}\n\t\\based{T}{\\mathcal{S}}{\\mathcal{S}}\n\t=\n\t\\begin{pmatrix}\n\t\t-1 & 3 \\\\\n\t\t3 & -1\n\t\\end{pmatrix}\n\t.\n\\end{equation*}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item \\textit{Find $\\based{T}{\\mathcal{B}}{\\mathcal{A}}$.}\n\t\\\\[\\baselineskip]\n\tLet $\\vec{w}_1$ and $\\vec{w}_2$ be the vectors of $\\mathcal{B}$ so that\n\t\\begin{equation*}\n\t\t\\vec{w}_1 = \\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix},\n\t\t\\vec{w}_1 = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}.\n\t\\end{equation*}\n\tUsing $\\based{I}{\\mathcal{B}}{\\mathcal{S}}$ (the change of basis matrix\n\tfrom $\\mathcal{B}$ to standard basis) and\n\t$\\based{I}{\\mathcal{S}}{\\mathcal{A}}$ (the change of basis matrix from\n\tstandard basis to $\\mathcal{A}$), $\\based{T}{\\mathcal{B}}{\\mathcal{A}}$\n\tcan be expressed as\n\t\\begin{align*}\n\t\t\\based{T}{\\mathcal{B}}{\\mathcal{A}}\n\t\t&=\n\t\t\\based{I}{\\mathcal{S}}{\\mathcal{A}}\n\t\t\\based{T}{\\mathcal{S}}{\\mathcal{S}}\n\t\t\\based{I}{\\mathcal{B}}{\\mathcal{S}}\n\t\t\\\\\n\t\t&=\n\t\t\\begin{pmatrix}\n\t\t\t\\vert & \\vert \\\\\n\t\t\t\\based{I}{\\mathcal{S}}{\\mathcal{A}}\n\t\t\t\\based{T}{\\mathcal{S}}{\\mathcal{S}}\n\t\t\t\\vec{w}_1 &\n\t\t\t\\based{I}{\\mathcal{S}}{\\mathcal{A}}\n\t\t\t\\based{T}{\\mathcal{S}}{\\mathcal{S}}\n\t\t\t\\vec{w}_2 \\\\\n\t\t\t\\vert & \\vert\n\t\t\\end{pmatrix}\n\t\\end{align*}\n\tOr, more concisely,\n\t\\begin{equation*}\n\t\t\\based{T}{\\mathcal{B}}{\\mathcal{A}}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t\\vert & \\vert \\\\\n\t\t\t{\\{T \\vec{w}_1\\}}_{\\mathcal{A}} &\n\t\t\t{\\{T \\vec{w}_2\\}}_{\\mathcal{A}} \\\\\n\t\t\t\\vert & \\vert\n\t\t\\end{pmatrix}\n\t\t.\n\t\\end{equation*}\n\t\n\t\\item \\textit{Find $\\based{T}{\\mathcal{B}}{\\mathcal{B}}$.}\n\t\\begin{equation*}\n\t\t\\based{T}{\\mathcal{B}}{\\mathcal{B}}\n\t\t=\n\t\t\\begin{pmatrix}\n\t\t\t\\vert & \\vert \\\\\n\t\t\t{\\{T \\vec{w}_1\\}}_{\\mathcal{B}} &\n\t\t\t{\\{T \\vec{w}_2\\}}_{\\mathcal{B}} \\\\\n\t\t\t\\vert & \\vert\n\t\t\\end{pmatrix}\n\t\t.\n\t\\end{equation*}\n\\end{enumerate}\n\n\\section*{2.}\n\\begin{equation*}\n\t\\vec{a} = \\begin{pmatrix} -4 \\\\ -3 \\\\ 0 \\end{pmatrix},\n\t\\vec{b} = \\begin{pmatrix} 3 \\\\ 4 \\\\ 1 \\end{pmatrix}\n\\end{equation*}\n\\textit{The vectors $\\vec{a}$ and $\\vec{b}$ are orthogonal. Find a vector\n$\\vec{c}$ that is orthogonal to both of these vectors.} \\\\[\\baselineskip]\nThe vector that is the cross product of two other vectors is, by definition,\northogonal to both of the two other vectors. \\\\\nThus, let $\\vec{c}$ be the cross product of $\\vec{a}$ and $\\vec{b}$:\n\\begin{equation*}\n\t\\vec{c}\n\t=\n\t\\vec{a} \\times \\vec{b}\n\t=\n\t\\begin{pmatrix} -4 \\\\ -3 \\\\ 0 \\end{pmatrix}\n\t\\times\n\t\\begin{pmatrix} 3 \\\\ 4 \\\\ 1 \\end{pmatrix}\n\t=\n\t\\boxed{\n\t\t\\begin{pmatrix} -3 \\\\ 4 \\\\ -7 \\end{pmatrix}\n\t}\n\t.\n\\end{equation*}\nThe vector $\\vec{c}$'s orthogonality to both $\\vec{a}$ and $\\vec{b}$ can be\nverified by confirming that\n\\begin{gather*}\n\t\\vec{c} \\cdot \\vec{a} = 0, \\\\\n\t\\vec{c} \\cdot \\vec{b} = 0.\n\\end{gather*}\nAny other vector that fulfills the criteria can be found by computing\n\\begin{equation*}\n\ts \\cdot \\vec{c}\n\\end{equation*}\nwith an arbitrary scalar $s$.\n\n\\end{document}\n", "meta": {"hexsha": "675dfe6168c4c54e3e9f25c5dfcdc36ab70aeeaa", "size": 3915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "usc-20202-math-225-39425/hw19/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/hw19/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/hw19/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": 24.7784810127, "max_line_length": 76, "alphanum_fraction": 0.6201787995, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6018258847423681}}
{"text": "[40 min late]\n\n\\section{Equivalence of microcanonical and canonical ensembles}\n\\begin{align}\n    Z &= \\Tr e^{-\\beta H}\\\\\n    &=\n    \\int_{0}^{\\infty}\\, \\Gamma(E) e^{-\\beta E}\n\\end{align}\nwhere the density of states is $\\Gamma(E)=e^{S(E)/k_B}$.\nThen\n\\begin{align}\n    E &=\n    \\int_{0}^{\\infty} dE\\,\n    e^{\\frac{S(E)}{k_B} - \\frac{E}{k_B T}}\\\\\n    &\\approx \n    \\left. \\Delta e^{\\frac{1}{k_B}\\left( S - \\frac{E}{T} \\right)}\n    \\right|_{E = E^*}\n\\end{align}\nand we don't care about the $\\Delta$ because it's just a constant factor that\ngoes away in the log.\nIt is sharpley bpead as\n\\begin{align}\n    \\frac{\\Delta E}{E} \\to \\frac{1}{\\sqrt{N}}\n\\end{align}\n\n\n\\section{``Derivation'' of the canonical ensemble from the microcanonical}\nAllow heat exchange.\nSubsystem.\nHeat reservoir.\n\\begin{align}\n    \\rho_T (\\underbrace{q, p}_{\\text{subsystem}}, \\underbrace{Q,\n    P}_{\\text{reservoir}}) &\\sim\n    \\delta_\\Delta\\left( \n    H(p,q,P,Q) - E_T\n    \\right)\n\\end{align}\nwhere $\\delta_\\Delta$ is a delta function with finite width $\\Delta$.\nI'm going to sum over all values of the reservoir of that probability\ndistribution and I'm going to get a function of that subsystem only.\n\\begin{align}\n    \\rho(q, p) &=\n    \\int dQ\\, dP\\,\n    \\underbrace{\\rho_T\\left( q, p, Q, P \\right)}_{%\n    \\delta_\\Delta\\left( H(q, p) + H_R(Q,P) - E_T \\right)\n    }\\\\\n    &= \\Gamma_R\\underbrace{\\left( H(q,p) - E_T \\right)}_{E_R}\n\\end{align}\n", "meta": {"hexsha": "02fe6ae4133c036c09b313d2eb6bec383619cfe0", "size": 1412, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture16.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/lecture16.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/lecture16.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.8163265306, "max_line_length": 77, "alphanum_fraction": 0.6239376771, "num_tokens": 502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6017859028394517}}
{"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{Snowfall}\n\\author{Matthias J. Raives}\n\n\\begin{document}\n    \n    \\maketitle{}\n    \n    \\section{Mass of Snowmelt}\n    The OOM method of solving this problem is to equate the kinetic energy of a falling layer of snow to the thermal energy required to melt the snow.\n    \n    Consider an idealized layer of falling snow, of mass $M$, which falls at the terminal velocity of a single snowflake:\n    \\begin{equation}\n        v_{T}^{2} = \\frac{2mg}{\\rho_\\mathrm{air} \\sigma C_{d}}\n    \\end{equation}\n    Where $m$ is the mass of a snowflake, $\\sigma$ is it's projected area, and $\\rho_\\mathrm{air}$ is the density of air. For simplicity, we will assume that $C_{d}=1$.  The snow layer then has kinetic energy:\n    \\begin{equation}\n        K = \\frac{1}{2}Mv_{T}^{2} = \\frac{Mmg}{\\rho_\\mathrm{air}\\sigma}\n    \\end{equation}\n    This can melt a mass of snow:\n    \\begin{equation}\n        \\mathrm{d}M = \\frac{K}{\\Delta\\epsilon_\\mathrm{fus}} = \\frac{Mmg}{\\rho_\\mathrm{air}\\sigma\\Delta\\epsilon_\\mathrm{fus}}\n    \\end{equation}\n    where $\\Delta\\epsilon_\\mathrm{fus}=\\SI{3e9}{\\ergs\\per\\gram}$ is the specific heat of fusion of water (the energy per unit mass required to melt ice at \\SI{0}{\\celsius}).  Thus we can write:\n    \\begin{equation}\n        \\frac{\\mathrm{d}M}{M} = \\frac{mg}{\\rho_\\mathrm{air}\\sigma\\Delta\\epsilon_\\mathrm{fus}}\n    \\end{equation}\n    The mass of a snowflake can be written as:\n    \\begin{equation}\n        m = \\rho_\\mathrm{ice}\\sigma\\ell\n    \\end{equation}\n    where $\\ell$ is the size of the flake normal to the projection (i.e., it's length along the direction of its motion).  Thus we are left with:\n    \\begin{equation}\n        \\frac{\\mathrm{d}M}{M} = \\frac{\\rho_{\\mathrm{ice}}g\\ell}{\\rho_\\mathrm{air}\\Delta\\epsilon_{\\mathrm{fus}}}\\label{eq:dmM}\n    \\end{equation}\n    Assuming that snowflakes fall standing up (i.e., not face down), then $\\ell$ is the diameter of a snowflake, so on order $\\ell\\sim\\SI{0.5}{\\cm}$.  The density of ice is approximately that of water $(\\rho_{\\mathrm{ice}}\\sim\\SI{1}{\\gram\\per\\cubic\\cm})$, and the density of air is $\\rho_{\\mathrm{air}}\\sim\\SI{e-3}{\\gram\\per\\cubic\\cm}$.  Thus:\n    \\begin{equation}\n        \\frac{\\mathrm{d}M}{M} \\sim \\frac{1\\times10^{3}\\times0.5}{10^{-3}\\times\\num{3e9}} \\sim \\num{2e-4}\n    \\end{equation}\n    \n    \\section{Height of Snowmelt}\n    We could equivalently write this as d$h/h$, by writing the mass of a snow layer as\n    \\begin{align}\n        M &= f_\\mathrm{fresh}A\\rho_\\mathrm{ice}h & \\mathrm{d}M &= f_\\mathrm{melt}A\\rho_\\mathrm{ice}\\mathrm{d}h\n    \\end{align}\n    where $A$ is the area of the snow layer and $f$ is the packing efficiency of snow.  We see then that $\\frac{\\mathrm{d}M}{M}=\\frac{\\mathrm{d}h}{h}$, assuming that the falling snow is packed with the same efficiency as the layers on the ground.  That this is a good assumption is not immediately obvious: falling snow is packed much less efficiently than snow is on the ground.  But by considering the snowfall as a single layer, we are effectively projecting a volume of snowfall onto a surface, which increases the effective packing efficiency.  It is also true, however, that the packing efficiency of snow on the ground is increased by compression due to the weight of new layers of snow.  In generality, then:\n    \\begin{align}\n        \\frac{\\mathrm{d}h}{h} = \\frac{f_{\\mathrm{fresh}}}{f_\\mathrm{melt}}\\frac{\\mathrm{d}M}{M}\n    \\end{align}\n    i.e., the more tightly packed the already fallen snow is compared to fresh snow, the shorter the melt layer will be.\n    \n    \\section{Hail}\n    For this problem, we can just consider a single hailstone.  A hailstone of radius $r$ has mass:\n    \\begin{equation}\n        M = \\frac{4\\pi}{3}\\rho_{\\mathrm{ice}}r^{3} = \\frac{4}{3}\\rho_{\\mathrm{ice}}\\sigma r\n    \\end{equation}\n    and thus, we can write, in analogy to Equation~\\eqref{eq:dmM}:\n    \\begin{equation}\n        \\frac{\\mathrm{d}M}{M} = \\frac{4\\rho_{ice}gr}{3\\rho_{\\mathrm{air}}\\Delta\\epsilon_{\\mathrm{fus}}}\n    \\end{equation}\n    For the hail to melt more ice than it deposits, then we must have $\\frac{\\mathrm{d}M}{M}\\geq1$, or:\n    \\begin{equation}\n        r\\geq\\frac{3\\rho_{\\mathrm{air}}\\Delta\\epsilon_{\\mathrm{fus}}}{4\\rho_{\\mathrm{ice}}g}\\sim\\frac{3\\times\\num{e-3}\\times\\num{3e9}}{4\\times 1\\times\\num{e3}}\\sim \\SI{2e3}{\\cm}\n    \\end{equation}\n    \n    \n\\end{document}\n", "meta": {"hexsha": "4fb81b39b9925e3d3167873ca1363a4823543cd6", "size": 4560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Snowfall/Snowfall_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": "Snowfall/Snowfall_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": "Snowfall/Snowfall_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": 60.0, "max_line_length": 716, "alphanum_fraction": 0.6771929825, "num_tokens": 1495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6017769733951452}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{a4wide}\n\\usepackage{indentfirst}\n\\usepackage{hyperref}\n\\usepackage[capitalise]{cleveref}\n\\usepackage{minted}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{witharrows}\n\n\\AtBeginEnvironment{minted}{\\let\\itshape\\relax}\n\n\\begin{document}\n\n\\section*{Exercise 1}\n\nTo show that $(m_1, m_2) = (m'_1, m'_2)$, we have to show that\n$m_1 \\equiv x_T^{-1} c_1 \\ (\\mathrm{mod} \\ p)$ and $m_2 \\equiv y_T^{-1}c_2 \\ (\\mathrm{mod} \\ p)$.\n\n\\vspace{\\baselineskip}\n\n\\[\n\\setlength{\\jot}{10pt}\n\\begin{WithArrows}\nm_1 \\equiv x_T^{-1} c_1 \\ (\\mathrm{mod} \\ p) \\ &\\wedge \\ m_2 \\equiv y_T^{-1} c_2 \\ (\\mathrm{mod} \\ p) \\Arrow{$c_1 \\equiv x_Sm_1 \\ (\\mathrm{mod} \\ p)$ and \\\\$c_2 \\equiv y_Sm_2 \\ (\\mathrm{mod} \\ p)$} \\\\\nm_1 \\equiv x_T^{-1} x_Sm_1 \\ (\\mathrm{mod} \\ p) &\\wedge m_2 \\equiv y_T^{-1} y_Sm_2 \\ (\\mathrm{mod} \\ p)\n\\end{WithArrows}\n\\]\n\n\\vspace{\\baselineskip}\n\nFor $(m_1, m_2) = (m'_1, m'_2)$ to hold, we just have to show that $T^{-1}S \\equiv 1 \\ (\\mathrm{mod} \\ p)$.\n\n\\[ \n\\setlength{\\jot}{10pt}\n\\begin{WithArrows}\n        &\\Arrow{$T = n_AR$ and $S = kQ_A$}\\\\\nT^{-1}S &\\equiv (n_AR)^{-1}kQ_A \\ (\\mathrm{mod} \\ p) \\Arrow{$R = kP$ and $Q_A = n_AP$} \\\\\n        &\\equiv n_A^{-1}(kP)^{-1}kn_AP \\ (\\mathrm{mod} \\ p) \\Arrow{$n_An_A^{-1} = 1$, $kk^{-1} = 1$\\\\ and $PP^{-1} = 1$} \\\\\n        &\\equiv 1 \\ (\\mathrm{mod} \\ p)\n\\end{WithArrows}\n\\]\n\n\\vspace{\\baselineskip}\n\nThus, $(m_1, m_2) = (m'_1, m'_2)$.\n\n\\section*{Exercise 2}\n\n\\vspace{\\baselineskip}\n\n\\begin{minted}{py}\nfrom sage.all import *\n\ndef gen_pub_key(A, B, p, x_p, y_p):\n    Fp = FiniteField(p)\n    E = EllipticCurve(Fp, [A, B])\n    assert(E.is_on_curve(x_p, y_p))\n\n    P = E([x_p, y_p])\n    n_a = ZZ(Fp.random_element())\n    Q_A = n_a * P\n\n    return (Q_A, n_a)\n\n\ndef encrypt(A, B, p, x_p, y_p, Q_A, m_1, m_2):\n    Fp = FiniteField(p)\n    E = EllipticCurve(Fp, [A, B])\n    assert(E.is_on_curve(x_p, y_p))\n\n    P = E([x_p, y_p])\n    k = ZZ(Fp.random_element())\n    R = k * P\n\n    S = k * Q_A\n    c_1 = (S[0] * m_1) % p\n    c_2 = (S[1] * m_2) % p\n\n    return (R, c_1, c_2)\n\\end{minted}\n\n\\begin{minted}{py}\ndef decrypt(A, B, p, x_p, y_p, R, n_a, c_1, c_2):\n    Fp = FiniteField(p)\n    E = EllipticCurve(Fp, [A, B])\n    assert(E.is_on_curve(x_p, y_p))\n\n    T = n_a * R\n    m_1 = (T[0] ** (-1) * c_1) % p\n    m_2 = (T[1] ** (-1) * c_2) % p\n\n    return (m_1, m_2)\n\\end{minted}\n\n\\vspace{2\\baselineskip}\n\nRunning this functions with the Curve P-384, we can see the functions are defined\ncorrectly (\\cref{fig:sage}).\n\n\\vspace{\\baselineskip}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{img/ex2.png}\n    \\caption{Menezes–Vanstone variant for ECC ElGamal}\n    \\label{fig:sage}\n\\end{figure}\n\n\\end{document}\n", "meta": {"hexsha": "ace33fa2b5a7ae246aa5728886f27be54593ee60", "size": 2733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CA/8-ECC/tex/main.tex", "max_stars_repo_name": "ruipedro16/FCUP-MSI", "max_stars_repo_head_hexsha": "6e86087b1b4ff73a789fefcdb1e41bc117cfdf5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CA/8-ECC/tex/main.tex", "max_issues_repo_name": "ruipedro16/FCUP-MSI", "max_issues_repo_head_hexsha": "6e86087b1b4ff73a789fefcdb1e41bc117cfdf5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CA/8-ECC/tex/main.tex", "max_forks_repo_name": "ruipedro16/FCUP-MSI", "max_forks_repo_head_hexsha": "6e86087b1b4ff73a789fefcdb1e41bc117cfdf5e", "max_forks_repo_licenses": ["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.185840708, "max_line_length": 200, "alphanum_fraction": 0.5964141969, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859598, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6017769733951452}}
{"text": "% LaTeX file for a 1 page document\n\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n%\\usepackage{physymb}\n\\usepackage{graphicx}\n%\\usepackage{wrapfig}\n\\usepackage{tikz}\n\\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}\n\n\\title{EP 222 Assigment 2}\n\\date{October 10, 2013}\n\\author{Manish Goregaokar (120260006)}\n\n\\begin{document}\n\\maketitle\n\n\\section{Question 1}\n\n\\includegraphics[scale=1]{1.png}\n\n\nWe shall take $\\theta_1,\\theta_2$ as our coordinates. Let the rigid supports be of length $l$, and let the distance between the supports be equal to the equilibrium length of the spring, $d$. The kinetic energy of this system is $T=\\frac{l^2}2(m_1\\dot\\theta_1^2+m_2\\dot\\theta_2^2)$\\\\\nRewriting $T$ as a matrix, $\\mathbf T=[t_{ij}]=\\left[\\frac{\\partial^2 T}{\\partial \\dot\\theta_i\\partial \\dot\\theta_j}\\right]=l^2\\begin{pmatrix}\nm_1 & 0\\\\\n0 & m_2\n\\end{pmatrix}$\\\\\n\nThe potential energy is \\begin{align}V &=& &m_1gl(1-\\cos\\theta_1)+m_2gl(1-\\cos\\theta_2)+\\frac12k(l(\\theta_2-\\theta_1))^2\\notag\\\\ &\\approx & &m_1gl\\theta_1^2 +m_2gl\\theta_2^2+\\frac12kl^2(\\theta_1^2+\\theta_2^2+2\\theta_1\\theta_2)\\notag\n\\end{align}\n\\\\ Rewriting $V$ as a matrix, \\begin{align}\\mathbf V &=& &[V_{ij}]\\notag\\\\ &=& &\\left[\\frac{\\partial^2 V}{\\partial \\theta_i\\partial \\theta_j}\\right]\\notag\\\\ &=& &\\begin{pmatrix}\n2m_1gl+kl^2 & -kl^2\\\\\n-kl^2 & 2m_2gl+kl^2\n\\end{pmatrix}\\notag\n\\end{align}\\\\\nNow, the normal mode frequencies are given by the eigenvalue equation $$|\\mathbf V-\\omega^2\\mathbf T|=0$$\n\n$$\\therefore\\left|\\begin{pmatrix}\n2m_1gl+kl^2 & -kl^2\\\\\n-kl^2&  2m_2gl+kl^2\n\\end{pmatrix}-\\omega^2l^2\\begin{pmatrix}\nm_1 &0\\\\0&m_2\n\\end{pmatrix}\\right|=0$$\nRewriting $\\lambda=\\omega^2l^2$\n\\begin{align}\n&\\therefore \\begin{vmatrix}k l^2+2 g m_1 l-\\lambda  m_1 & k l^2 \\\\\n k l^2 & k l^2+2 g m_2 l-\\lambda  m_2 \\\\\n\\end{vmatrix} &=& 0\\notag\\\\ &\\implies 4 g^2 l^2 m_1 m_2+2 g k l^3 m_1+2 g k l^3 m_2\\notag\\\\ &-4 g \\lambda  l m_1 m_2-k \\lambda  l^2 m_1-k \\lambda  l^2 m_2+\\lambda ^2 m_1 m_2 &=& 0\\notag \n\\end{align}\t\n\nFrom this we get roots for $\\lambda$ as $2gl$ and $\\frac{kl^2}{\\mu}+2gl$, so the normal modes are $\\boxed{\\omega=\\sqrt{2\\frac{g}{l}}}$ anand $\\boxed{\\omega=\\sqrt{2\\frac{g}{l}+\\frac{k}{\\mu}}}$ where $\\mu$ is the reduced mass.\\\\\n\nThe eigenvectors can be found by solving $\\mathbf{VA}=\\omega^2\\mathbf{TA}$. This expands to $$\\begin{pmatrix}\n 2 g l m_1+k l^2 & -k l^2 \\\\\n -k l^2 & 2 g l m_2+k l^2 \\\\\n\\end{pmatrix}\n\\begin{pmatrix}\n A_1 \\\\\n A_2 \\\\\n\\end{pmatrix}\n=\\lambda \n\\begin{pmatrix}\n m_1 & 0 \\\\\n 0 & m_2 \\\\\n\\end{pmatrix}\n\\begin{pmatrix}\n A_1 \\\\\n A_2 \\\\\n\\end{pmatrix}\n$$\n\nwhich gives rise to eigenvectors $\\boxed{\\mathbf A= \\begin{pmatrix}1 \\\\ 1\\end{pmatrix},\\begin{pmatrix}m_2 \\\\ -m_1\\end{pmatrix}}$, or relative amplitudes ($\\theta_2:\\theta_1$) $1$ and $-\\frac{m_1}{m_2}$.\n\n\\section{Question 2}\n\\includegraphics[scale=1]{2.png}\n\nOur generalized coordinates shall be the elongations in each spring, $x_1,x_2$ ($x_1$ is for the upper spring).\\\\\nThe velocities of the masses are $\\dot x_1$ for $2m$ and $\\dot x_1 +\\dot x_2$ for $m$.\\\\\n$\\therefore T=\\frac12 2m \\dot x_1^2 + \\frac12 m (\\dot x_1+\\dot x_2)^2=\\frac12(3m\\dot x_1^2 + m\\dot x_2^2+2m\\dot x_1\\dot x_2)$\\\\\nRewriting $T$ as a matrix, $\\mathbf T=[t_{ij}]=\\left[\\frac{\\partial^2 T}{\\partial \\dot x_i\\partial \\dot x_j}\\right]=\\frac{m}2\\begin{pmatrix}\n6 & 2\\\\\n2 &2\n\\end{pmatrix}$\\\\\nThe potential energy is simply $\\frac12(kx_1^2+kx_2^2)-2mg(l_1+x_1)-mg(l_1+x_1+l_2+x_2)$ ($l_1,l_2$ are natural lengths of springs), giving $\\mathbf V=[V_{ij}]=\\left[\\frac{\\partial^2 V}{\\partial x_i\\partial x_j}\\right]=\\frac{k}2\\begin{pmatrix}\n2 & 0\\\\\n0 &2\n\\end{pmatrix}$\\\\\nNow, the normal mode frequencies are given by the eigenvalue equation $$|\\mathbf V-\\omega^2\\mathbf T|=0$$\n$$\\therefore\\left| \\frac{k}2\\begin{pmatrix}\n2 & 0\\\\\n0 &2\n\\end{pmatrix}-\\omega^2\\frac{m}2\\begin{pmatrix}\n6 & 2\\\\\n2 &2\n\\end{pmatrix}\\right|=0$$\nRewriting $\\lambda=\\omega^2\\frac{m}{k}$\n\\begin{align}\n&\\therefore \\begin{vmatrix}\n2 -6\\lambda & 0-2\\lambda\\\\\n0-2\\lambda &2-2\\lambda\n\\end{vmatrix} &=& 0\\notag \\\\\n&\\implies (2-6\\lambda)(2-2\\lambda)-(-2\\lambda)^2 &=& 0\\notag\\\\\n&\\implies  8\\lambda^2 -16\\lambda +4 &=& 0\\notag\\\\\n&\\implies  2\\lambda^2 -4\\lambda +1 &=& 0\\notag\\\\\n&\\implies \\lambda &=& \\frac{4\\pm\\sqrt{16-8}}{4}\\notag\\\\\n&~ &=& 1\\pm\\frac1{\\sqrt{2}}\\notag\\\\\n&\\implies \\omega &=&\\sqrt{\\frac{k}{m}\\left(1\\pm\\frac1{\\sqrt{2}}\\right)}\\notag\n\\end{align}\n\nThus, the normal modes are $\\boxed{\\omega_1=\\sqrt{\\frac{k}{m}\\left(1+\\frac1{\\sqrt{2}}\\right)},~~\\omega_2=\\sqrt{\\frac{k}{m}\\left(1-\\frac1{\\sqrt{2}}\\right)}}$\n\\section{Question 3}\n\\begin{tikzpicture}\n\\node[circle,fill=gray,inner sep=2.5mm] (a) at (0,3) {$m$};\n\\node[above=0.1cm, above of= a] {$(x_3,y_3)$}; \n\\node[circle,fill=gray,inner sep=2.5mm] (b) at (0,0) {$m$};\\node[below=0.1cm, below of= b] {$(x_1,y_1)$} ;\n\\node[circle,fill=gray,inner sep=2.5mm] (c) at (3,0) {$m$}; \\node[below=0.1cm, below of= c] {$(x_2,y_2)$};\n\\draw[decoration={aspect=0.3, segment length=3mm, amplitude=2mm,coil},decorate] (b) -- (a) node [midway, left=0.4cm] {$k$}; \n\n\\draw[decoration={aspect=0.3, segment length=3mm, amplitude=2mm,coil},decorate] (b) -- (c)  node [midway, below=0.4cm] {$k$}; \n\\end{tikzpicture}\\\\\n Let $q_1,q_2,q_3$ be the $x$ coordinates, and $q_4,q_5,q_6$ be the y coordinates.\n\nThe kinetic energy is $T=\\frac{m}2(\\sum \\dot q_i^2)$, giving $\\mathbf T=[t_{ij}]=\\left[\\frac{\\partial^2 T}{\\partial \\dot q_i \\dot q_j}\\right]=m\\mathbf I$, where $\\mathbf I$ is the 6$\\times$6 identity matrix.\n\n\\newcommand{\\dxsq}[2]{(x_#1-x_#2)^2}\n\\newcommand{\\dysq}[2]{(y_#1-y_#2)^2}\nThe potential energy is $$V=\\frac{k}2\\left(\\left(\\sqrt{\\left(x_1-x_2\\right){}^2+\\left(y_1-y_2\\right){}^2}-a\\right){}^2+\\left(\\sqrt{\\left(x_3-x_1\\right){}^2+\\left(y_3-y_1\\right){}^2}-a\\right){}^2\\right)$$. This gives us a matrix $\\mathbf V=[V_{ij}]=\\left[\\frac{\\partial^2 V}{\\partial q_i  q_j}\\right]$, which when expanded gives us an unprintably large matrix. However, on substituting the equilibrium values of the coordinates, we get the much more manageable\n$$\\frac{k}2\\begin{pmatrix}\n\n 2 & -2 & 0 & 0 & 0 & 0 \\\\\n -2 & 2 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 2 & 0 & -2 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & -2 & 0 & 2 \\\\\n\n\n\\end{pmatrix}$$\n\nNow, the eigenvalue equation is $|\\mathbf V-\\omega^2 \\mathbf T|=0$, giving us $$\\left|\\frac{k}{2}\\begin{pmatrix}\n 2 & -2 & 0 & 0 & 0 & 0 \\\\\n -2 & 2 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 2 & 0 & -2 \\\\\n 0 & 0 & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & -2 & 0 & 2 \\\\\n\\end{pmatrix}-\\omega^2 m\\mathbf I\\right|=0$$\nWriting $\\lambda=\\frac{2m\\omega^2}{k}$\n$$\\therefore\\begin{vmatrix}\n\n 2-\\lambda  & -2 & 0 & 0 & 0 & 0 \\\\\n -2 & 2-\\lambda  & 0 & 0 & 0 & 0 \\\\\n 0 & 0 & -\\lambda  & 0 & 0 & 0 \\\\\n 0 & 0 & 0 & 2-\\lambda  & 0 & -2 \\\\\n 0 & 0 & 0 & 0 & -\\lambda  & 0 \\\\\n 0 & 0 & 0 & -2 & 0 & 2-\\lambda  \\\\\n\n\n\\end{vmatrix}=0$$\n$$\\therefore \\lambda ^2 \\left(\\lambda ^4-8 \\lambda ^3+16 \\lambda ^2\\right)=0$$\n   $$\\therefore (\\lambda -4)^2 \\lambda ^4=0$$\n   \n   \n   This gives us eigenvalues $\\lambda=0,0,0,0,4,4$. Thus, the normal modes are $\\boxed{\\sqrt{2\\frac{k}{m}} }$ with multiplicity 2.\n\\section{Question 4}\n\\includegraphics[scale=1]{4.png}\n\nWe shall take our coordinates as $\\theta_1,\\theta_2$. The velocity of the upper bob is $\\frac12ml_1^2\\dot\\theta_1^2$. For the second bob, its position is $\\mathbf r_2=l_1(\\cos\\theta_1\\hat i +\\sin\\theta_1\\hat j)+ l_2(\\cos\\theta_2\\hat i +\\sin\\theta_2\\hat j)$.  This gives us velocity $$\\dot{\\mathbf{r_2}}=l_1\\dot\\theta_1(-\\sin\\theta_1\\hat i +\\cos\\theta_1\\hat j)+ l_2\\dot\\theta_2(-\\sin\\theta_2\\hat i +\\cos\\theta_2\\hat j)$$, which can be rewritten as $$\\dot{\\mathbf{r_2}}=\\hat i(-l_1\\dot\\theta_1\\sin\\theta_1-l_2\\dot\\theta_2\\sin\\theta_2)+ \\hat j(l_1\\dot\\theta_1\\cos\\theta_1+l_2\\dot\\theta_2\\cos\\theta_2)$$. The kinetic energy $$T=\\frac12ml_1^2\\dot\\theta_1^2+\\frac12m|\\dot{\\mathbf{r_2}}|^2=\\frac12m\\left(2\\dot{\\theta }_1^2 l_1^2+\\dot{\\theta }_2^2\n   l_2^2+2 \\dot{\\theta }_2 \\dot{\\theta }_1 l_1\n   l_2 \\cos \\left(\\theta _1-\\theta _2\\right)\\right)$$\n   \nRewriting as a matrix,  $$\\mathbf T=[t_{ij}]=\\left[\\frac{\\partial^2 T}{\\partial \\dot \\theta_i \\dot \\theta_j}\\right]=m\\begin{pmatrix}\n2l_1^2 & l_1l_2\\cos(\\theta_1-\\theta_2)\\\\\nl_1l_2\\cos(\\theta_1-\\theta_2) & l_2^2\n\\end{pmatrix}$$\nNear equilibrium ($\\theta_1,\\theta_2=0$), $\\mathbf T=\\begin{pmatrix}\n2l_1^2 & l_1l_2\\\\\nl_1l_2 & l_2^2\n\\end{pmatrix}$\\\\\n\nThe potential energy $V=-mgl_1\\cos\\theta_1-(mgl_1\\cos\\theta_1+mgl_2\\cos\\theta_2)$. This gives us a potential matrix $$\\mathbf V =\\left[\\frac{\\partial^2 V}{\\partial \\theta_i \\theta_j}\\right]=\\begin{pmatrix}\n2mgl_1\\cos\\theta_1&0\\\\\n0& mgl_2\\cos\\theta_2\n\\end{pmatrix}$$\n\nwhich, at equilibrium, is $mg\\begin{pmatrix}\n2l_1&0\\\\0&l_2\n\\end{pmatrix}$\n\nThe eigenvalue equation is $|\\mathbf V-\\omega^2 \\mathbf T|=0$, which comes out to be $$\\left|mg\\begin{pmatrix}\n2l_1&0\\\\0&l_2\n\\end{pmatrix}-\\omega^2\\begin{pmatrix}\n2l_1^2 & l_1l_2\\\\\nl_1l_2 & l_2^2\n\\end{pmatrix}\\right|=0$$\n\nWith $\\lambda=\\frac{\\omega^2}{mg}$, we get\n\n\\begin{align*}\n&\\left|\\begin{pmatrix}\n2l_1&0\\\\0&l_2\n\\end{pmatrix}-\\lambda\\begin{pmatrix}\n2l_1^2 & l_1l_2\\\\\nl_1l_2 & l_2^2\n\\end{pmatrix}\\right| &=0\\notag\\\\\n&\\therefore \\lambda ^2 l_2^2 l_1^2-2 \\lambda  l_2 l_1^2-2 \\lambda  l_2^2 l_1+2 l_2 l_1 &=0 \\notag\\\\\n&\\therefore \\lambda &= \\frac{l_1+l_2\\pm\\sqrt{l_1^2+l_2^2}}{l_1 l_2}\\notag\\\\\n&\\therefore \\omega &= \\sqrt{mg\\frac{l_1+l_2\\pm\\sqrt{l_1^2+l_2^2}}{l_1 l_2}}\\notag\n\\end{align*}\n\nTo find the eigenvectors, we solve $\\mathbf {VA}=\\omega^2\\mathbf{TA}$, which expands to $$\\begin{pmatrix}\n2l_1&0\\\\0&l_2\n\\end{pmatrix}\\begin{pmatrix}\nA_1\\\\A_2\n\\end{pmatrix}=\\lambda\\begin{pmatrix}\n2l_1^2 & l_1l_2\\\\\nl_1l_2 & l_2^2\n\\end{pmatrix}\\begin{pmatrix}\nA_1\\\\A_2\n\\end{pmatrix}$$\n\nThis gives us eigenvectors $$\\mathbf A= \\begin{pmatrix}\nl_2 \\left(\\pm(l_1+l_2)+\\sqrt{l_1^2+l_2^2}\\right)\\\\\n-2 l_1 \\left(\\sqrt{l_1^2+l_2^2}\\pm l_1\\right)\n\\end{pmatrix}$$\n\nThese are already orthogonal ($\\mathbf A_1^T\\mathbf{TA_2}=0$). On normalizing them ($\\mathbf A_i^T\\mathbf{TA_i}=1$), we get $$\\boxed{\\mathbf A=\\frac1{2 l_1 l_2 \\sqrt{l_1^2\\pm  l_1\\sqrt{l_1^2+l_2^2}+l_2^2}}\\begin{pmatrix}\nl_2 \\left(\\pm(l_1+l_2)+\\sqrt{l_1^2+l_2^2}\\right)\\\\\n-2 l_1 \\left(\\sqrt{l_1^2+l_2^2}\\pm l_1\\right)\n\\end{pmatrix}}$$ for corresponding normal modes $\\boxed{ \\omega = \\sqrt{mg\\frac{l_1+l_2\\pm\\sqrt{l_1^2+l_2^2}}{l_1 l_2}}}$\n\\end{document}\n}\n", "meta": {"hexsha": "d84322e380e160e57ddda55b187a4158abf3d397", "size": 10307, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course material/EP 222 - Classical Mechanics/Assignment 2/Assign2.tex", "max_stars_repo_name": "CourseResources/CourseResources", "max_stars_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-28T05:59:31.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-28T05:59:31.000Z", "max_issues_repo_path": "Course material/EP 222 - Classical Mechanics/Assignment 2/Assign2.tex", "max_issues_repo_name": "CourseResources/CourseResources", "max_issues_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Course material/EP 222 - Classical Mechanics/Assignment 2/Assign2.tex", "max_forks_repo_name": "CourseResources/CourseResources", "max_forks_repo_head_hexsha": "4040bfe499609389d1978823e4e2896bf4ce41e3", "max_forks_repo_licenses": ["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.047008547, "max_line_length": 739, "alphanum_fraction": 0.6533423887, "num_tokens": 4634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.785308580887758, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6017769733951451}}
{"text": "% !TEX root = Thesis.tex\n\\section{Document Model}\n\\label{sec:document-model}\n\tIn contrast to the relational model, the document model represents semi-structured as well as unstructured data.  Examples of information suitable to the document model includes emails, memos, and book chapters.\n\t\n\tThese pieces, or units, of information are broken into documents.  Groups of related documents (e.g.~a library catalogue) are referred to as a document collection.\n\n\t\\begin{defn}[Terms and Documents]\n\t\\label{def:document}\n\t\tA term, \\(\\term\\), is an indivisible string, e.g., a proper noun, word, or a phrase.\tA document, \\(\\doc\\), is a bag of words; order is irrelevant.\n\t\t\n\t\tLet \\(\\freq(\\term, \\doc)\\) be the frequency of term \\(\\term\\) in \\(\\doc\\), \\(\\terms\\) denote all possible terms, and \\(\\bag{\\terms}\\) be all possible bag of terms.\n\t\\end{defn}\n\t\n\t\\begin{remark}\n\t\tWe use the bag-of-words model for documents.  This means that position information of terms in a document is irrelevant, but the frequency of terms are kept in the document.  Documents are non-distinct sets.\n\t\\end{remark}\n\t\n\t\\begin{defn}[Document Collection]\n\t\\label{def:document-collection}\n\t\tA document collection \\(\\dc\\) is a set of documents, written \\(\\dc = \\{\\doc_1, \\doc_2, \\dotsc, \\doc_k\\}\\).  The cardinality of \\(\\dc\\) is denoted by \\(\\gls{ndocs}\\).\n\t\\end{defn}\n\t\n\t\\begin{ex}\n\t\\label{ex:documents}\n\t\tConsider the following short phrases\n\t\t\n\t\t\\begin{enumerate}\n\t\t\t\\item MATH 360 is a math class\n\t\t\t\\item CDPS 101 is a boring lecture\n\t\t\t\\item mathematics lecture was great\n\t\t\\end{enumerate}\n\t\t\n\t\tEach sentence phrase produces a document, giving us the following documents\n\t\t\\begin{align}\n\t\t\t\\doc_1 &= \\{\\text{``math''}: 2, \\text{``a''}: 1, \\text{``is''}: 1, \\text{``360''}: 1, \\text{``class''}: 1\\} \\\\\n\t\t\t\\doc_2 &= \\{\\text{``a''}: 1, \\text{``boring''}: 1, \\text{``is''}: 1, \\text{``cdps''}: 1, \\text{``lecture''}: 1, \\text{``101''}: 1\\} \\\\\n\t\t\t\\doc_3 &= \\{\\text{``mathematics''}: 1, \\text{``great''}: 1, \\text{``was''}: 1, \\text{``lecture''}: 1\\}\n\t\t\\end{align}\n\t\t\n\t\twith \\(\\dc = \\{\\doc_1, \\doc_2, \\doc_3\\}\\) and \\(\\gls{ndocs} = 3\\).\n\t\\end{ex}\n\t\n\t\\subsection{Vectorization of Documents}\n\t\\label{sec:vectorization-of-documents}\n\t\tThe most fundamental approach for searching documents is to treat documents as high-dimensional vectors, and the document collection as a subset in a vector space.  Search queries become a nearest neighbour search in a vector space using a distance metric.\n\t\t\n\t\tThe first step is to convert a bag of terms into vectors.  The standard technique \\cite{ir-08} uses a scoring function that measures the relative importance of terms in documents.\n\t\t\n\t\t\\begin{defn}[\\Gls{tfidf} Score]\n\t\t\tThe term frequency is the number of times a term \\(\\term\\) appears in a document \\(\\doc\\), as given by \\(\\freq(\\term, \\doc)\\).\tThe document frequency of a term \\(\\term\\), denoted by \\(\\df(\\term)\\), is the number of documents in \\(\\dc\\) that contains \\(\\term\\).\t It is defined as\n\t\t\t\\[\n\t\t\t\t\\df(\\term) = \\abs{\\{\\doc \\in \\dc: \\term \\in \\doc\\}}\n\t\t\t\\]\n\t\t\t\n\t\t\tThe combined \\gls{tfidf} score of \\(\\term\\) in a document \\(\\doc\\) is given by\n\t\t\t\\[\n\t\t\t\t\\tfidf(\\dc, \\term, \\doc) = \\frac{\\freq(\\term, \\doc)}{\\abs{\\doc}} \\cdot \\log{\\frac{N}{\\df(\\term)}}\n\t\t\t\\]\n\t\t\\end{defn}\n\t\t\n\t\tThe first component, \\(\\frac{\\freq\\left(\\term, \\doc\\right)}{\\abs{\\doc}}\\), measures the importance of a term within a document.  It is normalized to account for document length.\t The second component, \\(\\log{\\frac{N}{\\df\\left(\\term\\right)}}\\), is a measure of the rarity of the term within the document collection \\(\\dc\\).\n\t\t\n\t\t\\begin{ex}\n\t\t\tUsing the documents from \\cref{ex:documents}, the \\gls{tfidf} scores are as follows.\n\t\t\t\\[\n\t\t\t\t\\bordermatrix{\n\t\t\t\t\t~ & d_1 & d_2 & d_3 \\cr\n\t\t\t\t\t\\term_{1} : \\text{``101''} & 0.0000 & 0.2642 & 0.0000 \\cr\n\t\t\t\t\t\\term_{2} : \\text{``360''} & 0.3170 & 0.0000 & 0.0000 \\cr\n\t\t\t\t\t\\term_{3} : \\text{``a''} & 0.1170 & 0.0975 & 0.0000 \\cr\n\t\t\t\t\t\\term_{4} : \\text{``boring''} & 0.0000 & 0.2642 & 0.0000 \\cr\n\t\t\t\t\t\\term_{5} : \\text{``cdps''} & 0.0000 & 0.2642 & 0.0000 \\cr\n\t\t\t\t\t\\term_{6} : \\text{``class''} & 0.3170 & 0.0000 & 0.0000 \\cr\n\t\t\t\t\t\\term_{7} : \\text{``great''} & 0.0000 & 0.0000 & 0.3962 \\cr\n\t\t\t\t\t\\term_{8} : \\text{``is''} & 0.1170 & 0.0975 & 0.0000 \\cr\n\t\t\t\t\t\\term_{9} : \\text{``lecture''} & 0.0000 & 0.0975 & 0.1462 \\cr\n\t\t\t\t\t\\term_{10} : \\text{``math''} & 0.6340 & 0.0000 & 0.0000 \\cr\n\t\t\t\t\t\\term_{11} : \\text{``mathematics''} & 0.0000 & 0.0000 & 0.3962 \\cr\n\t\t\t\t\t\\term_{12} : \\text{``was''} & 0.0000 & 0.0000 & 0.3962 \\cr\n\t\t\t\t}\n\t\t\t\\]\n\t\t\\end{ex}\n\n\t\t\\begin{defn}[Document Vector]\n\t\t\tGiven a document collection \\(\\dc\\) with \\(M\\) unique terms \\(\\terms = [\\term_1, \\term_2, \\dotsc, \\term_M ]\\), each document \\(\\doc\\) can be represented by an \\(M\\)-dimensional vector.\n\t\t\t\\[\n\t\t\t\t\\vec{\\doc} = \n\t\t\t\t\\left[\n\t\t\t\t\\begin{array}{c}\n\t\t\t\t\t\\tfidf(\\term_1, \\doc) \\\\\n\t\t\t\t\t\\tfidf(\\term_2, \\doc) \\\\\n\t\t\t\t\t\\vdots \\\\\n\t\t\t\t\t\\tfidf(\\term_M, \\doc)\n\t\t\t\t\\end{array}\n\t\t\t\t\\right]\n\t\t\t\\]\n\t\t\\end{defn}\n\t\t\n\t\t\\begin{ex}\n\t\t\tThe documents in \\cref{ex:documents} produce the following vectors.\n\t\t\t\\[\n\t\t\t\t\\vec{\\doc_n} = \n\t\t\t\t\t\\left[\n\t\t\t\t\t\t\\begin{array}{l}\n\t\t\t\t\t\t\t\\tfidf(\\term_{1}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{2}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{3}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{4}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{5}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{6}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{7}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{8}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{9}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{10}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{11}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\t\\tfidf(\\term_{12}, \\doc_{n}) \\\\\n\t\t\t\t\t\t\\end{array}\n\t\t\t\t\t\\right],\n\t\t\t\t\\vec{\\doc_1} =\n\t\t\t\t\t\\left[\n\t\t\t\t\t\t\\begin{array}{c}\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.3170 \\\\\n\t\t\t\t\t\t\t0.1170 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.3170 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.1170 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.6340 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\\end{array}\n\t\t\t\t\t\\right],\n\t\t\t\t\\vec{\\doc_2} =\n\t\t\t\t\t\\left[\n\t\t\t\t\t\t\\begin{array}{c}\n\t\t\t\t\t\t\t0.2642 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0975 \\\\\n\t\t\t\t\t\t\t0.2642 \\\\\n\t\t\t\t\t\t\t0.2642 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0975 \\\\\n\t\t\t\t\t\t\t0.0975 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\\end{array}\n\t\t\t\t\t\\right],\n\t\t\t\t\\vec{\\doc_3} =\n\t\t\t\t\t\\left[\n\t\t\t\t\t\t\\begin{array}{c}\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.3962 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.1462 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.3962 \\\\\n\t\t\t\t\t\t\t0.3962 \\\\\n\t\t\t\t\t\t\\end{array}\n\t\t\t\t\t\\right]\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\t\\begin{defn}[Search Query]\n\t\t\\label{def:search-query}\n\t\t\tA search query \\(\\q\\) is simply a document (\\cref{def:document}).  The top-\\(k\\) answers to \\(\\q\\) with respect to a collection \\(\\dc\\) is defined as the \\(k\\) documents, \\(\\{\\doc_1, \\doc_2, \\dotsc, d_k\\}\\) in \\(\\dc\\), such that \\(\\{\\vec{\\doc_1}, \\vec{\\doc_2}, \\dotsc, \\vec{d_k}\\}\\) are the closest vectors to \\(\\vec{\\q}\\) using the Euclidean distance measure in \\(\\mathbb{R}^N\\).\n\t\t\\end{defn}\n\t\t\n\t\t\\begin{ex}\n\t\t\t\\label{ex:query}\n\t\t\tGiven the search query \\(\\q = \\{\\text{math}, \\text{lecture}, \\text{was}, \\text{great}\\}\\), compute the vector \\(\\vec{\\q}\\) within the document collection \\(\\dc\\) (as defined in \\cref{ex:documents}).\n\t\t\t\\[\n\t\t\t\t\\vec{\\q} = \n\t\t\t\t\t\\left[\n\t\t\t\t\t\t\\begin{array}{c}\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.2500 \\\\\n\t\t\t\t\t\t\t0.1038 \\\\\n\t\t\t\t\t\t\t0.1038 \\\\\n\t\t\t\t\t\t\t0.2500 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\t0.0000 \\\\\n\t\t\t\t\t\t\\end{array}\n\t\t\t\t\t\\right]\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\tWe need a way of measuring the similarity between documents to determine the top-\\(k\\) documents for search query \\(\\q\\).\n\t\t\n\t\t\\begin{defn}[Cosine Similarity]\n\t\t\tGiven two document vectors, \\(\\vec{\\doc}_1\\) and \\(\\vec{\\doc}_2\\), the cosine similarity is the dot product \\(\\vec{\\doc}_1 \\cdot \\vec{\\doc}_2\\) normalized by the product of the Euclidean distance of \\(\\vec{\\doc}_1\\) and \\(\\vec{\\doc}_2\\) in \\(\\mathbb{R}^N\\).\tIt is denoted as \\(\\similarity(\\vec{\\doc}_1, \\vec{\\doc}_2)\\).\n\t\t\t\\begin{align}\n\t\t\t\t\\similarity(\\vec{\\doc}_1, \\vec{\\doc}_2) &= \\frac{\\vec{\\doc}_1 \\cdot \\vec{\\doc}_2}{\\norm{\\vec{\\doc}_1} \\cdot \\norm{\\vec{\\doc}_2}} \\\\\n\t\t\t\t &= \\frac{\\sum\\limits_{i=1}^{N} \\vec{\\doc}_{1, i} \\times \\vec{\\doc}_{2, i}}{\\sqrt{\\sum\\limits_{i=1}^{N} (\\vec{\\doc}_{1, i})^2} \\times \\sqrt{\\sum\\limits_{i=1}^{N} (\\vec{\\doc}_{2, i})^2}}\n\t\t\t\\end{align}\n\t\t\\end{defn}\n\t\t\n\t\tRecall we may represent search queries as documents and thus document vectors.  Therefore we may compute the score of a document \\(\\doc\\) for a search query \\(\\q\\) as\n\t\t\\[\n\t\t\t\\similarity(\\vec{\\doc}, \\vec{\\q})\n\t\t\\]\n\t\t\n\t\t\\begin{ex}\n\t\t\tGiven the document collection \\(\\dc\\) (\\cref{ex:documents}) and search query \\(q\\) (\\cref{ex:query}), compute the similarity between \\(\\q\\) and every document \\(\\doc \\in \\dc\\).\n\t\t\t\\begin{align}\n\t\t\t\t\\similarity(\\vec{\\doc_1}, \\vec{\\q}) = 0.390890 \\\\\n\t\t\t\t\\similarity(\\vec{\\doc_2}, \\vec{\\q}) = 0.061592 \\\\\n\t\t\t\t\\similarity(\\vec{\\doc_3}, \\vec{\\q}) = 0.252789\n\t\t\t\\end{align}\n\t\t\\end{ex}\n\t\t\n\t\\subsection{Extending the Document Model}\n\t\\label{sec:extending-the-document-model}\n\t\tIn the extended document model, documents have fields, denoted as \\(\\fields{\\doc}\\).  Each field has a value.\n\t\t\\[\n\t\t\t\\doc : \\fields{\\doc} \\to \\bag{\\terms}\n\t\t\\]\n\t\t\n\t\t\\begin{ex}[Semi-Structured Document]\n\t\t\tWe see that \\(\\doc_1\\) is about MATH 360.  The document contents are semi-structured, containing both a course code and the subject ID.  By adding fields to the document, we are left with \\cref{tbl:course-document}, which is similar in structure to \\cref{tbl:hmr-properties-rel}.\n\t\t\t\n\t\t\t\\begin{table}\n\t\t\t\t\\centering\n\t\t\t\t\n\t\t\t\t\\begin{tabular}{ll}\n\t\t\t\t\t\\toprule\n\t\t\t\t\tField & Value \\\\\n\t\t\t\t\t\\midrule\n\t\t\t\t\tcode & MATH 360 \\\\\n\t\t\t\t\tsubject & MATH \\\\\n\t\t\t\t\tbody & math 360 is a math class \\\\\n\t\t\t\t\t\\bottomrule\n\t\t\t\t\\end{tabular}\n\t\t\t\t\n\t\t\t\t\\caption{Course document for MATH 360.}\n\t\t\t\t\\label{tbl:course-document}\n\t\t\t\\end{table}\n\t\t\\end{ex}\n\t\t\n\t\\subsection{Approximate String matching}\n\t\\label{sec:n-gram}\n\t\t\\begin{defn}[N-Gram]\n\t\t\tAn \\(n\\)-gram is a contiguous sequence of substrings of string \\(S\\) of length \\(n\\).\t An algorithm for computing the \\(n\\)-gram of \\(S\\) is given in \\cref{alg:n-gram}. \n\t\t\\end{defn}\n\t\t\n\t\t% \\char\"24 - DOLLAR\t BILL Y'ALL\n\n\t\t\\begin{algorithm}[H]\n\t\t\t\\caption{\\(\\textsc{N-Gram}(S, n, s)\\)}\n\t\t\t\\label{alg:n-gram}\n\t\t\t\n\t\t\t\\begin{singlespaced}\n\t\t\t\t\\begin{algorithmic}[1]\n\t\t\t\t\t\\REQUIRE \\(S\\) is a string, \\(n \\ge 1\\), and \\(s\\) is a character\n\t\t\t\t\t\\ENSURE the list of \\(n\\)-grams of \\(S\\)\n\t\t\t\t\t\\medskip\n\t\t\t\t\t\\STATE \\(G \\leftarrow []\\)\\label{alg:n-gram:G}\n\t\t\t\t\t\\STATE \\(p \\leftarrow \\textsc{Repeat}(s, n - 1)\\)\n\t\t\t\t\t\\STATE \\(S \\leftarrow \\textsc{Pad}(S, p)\\)\n\t\t\t\t\t\\STATE \\(S \\leftarrow \\textsc{Replace}(S, `\\;', p)\\)\\label{alg:n-gram:S}\n\t\t\t\t\t\n\t\t\t\t\t\\FOR{\\(i=0\\) \\TO \\(l - n + 1\\)}\n\t\t\t\t\t\t\\STATE append \\(S[i, i + n]\\) to \\(G\\)\n\t\t\t\t\t\\ENDFOR\n\t\t\t\t\t\n\t\t\t\t\t\\RETURN \\(G\\)\n\t\t\t\t\t\\medskip\n\t\t\t\t\t\\medskip\n\t\t\t\t\\end{algorithmic}\n\t\t\t\\end{singlespaced}\n\t\t\\end{algorithm}\n\t\t\n\t\t%\\todo{The medskips above should not be required, but are in single spaced mode.}\n\t\t\n\t\tWhere \\(l\\) is the length of \\(S\\), \\(\\textsc{Repeat}(S, m)\\) repeats the character \\(s\\) a total of \\(m\\) times, \\(\\textsc{Pad}(S, p)\\) prefixes and postfixes \\(S\\) with \\(p\\), and \\(\\textsc{Replace}(S, s, p)\\) replaces character \\(s\\) with \\(p\\) in string \\(S\\).\n\t\t\n\t\t\\begin{ex}\n\t\t\\label{ex:ngram}\n\t\t\tGiven a string \\(S = \\text{``human''}\\), compute the trigram of \\(S\\) using \\cref{alg:n-gram}.\n\t\t\t\\[\n\t\t\t\tG = \\{\n\t\t\t\t\t\\text{``\\char\"24\\char\"24h''},\n\t\t\t\t\t\\text{``\\char\"24hu''},\n\t\t\t\t\t\\text{``hum''},\n\t\t\t\t\t\\text{``uma''},\n\t\t\t\t\t\\text{``man''},\n\t\t\t\t\t\\text{``an\\char\"24''},\n\t\t\t\t\t\\text{``n\\char\"24\\char\"24''}\n\t\t\t\t\\}\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\tWe use \\(n\\)-grams to permit approximate string matching.\n\t\t\n\t\t\\begin{ex}\n\t\t\\label{ex:n-gram-comparison}\n\t\t\tGiven a string \\(S\\) (\\cref{ex:ngram}), let \\(S' = \\text{``humans''}\\).  Compute the trigram of \\(S'\\) and compare it to \\(S\\).\n\t\t\t\\[\n\t\t\t\tG' = \\{\n\t\t\t\t\t\\text{``\\char\"24\\char\"24h''},\n\t\t\t\t\t\\text{``\\char\"24hu''},\n\t\t\t\t\t\\text{``hum''},\n\t\t\t\t\t\\text{``uma''},\n\t\t\t\t\t\\text{``man''},\n\t\t\t\t\t\\text{``ans''},\n\t\t\t\t\t\\text{``ns\\char\"24''},\n\t\t\t\t\t\\text{``s\\char\"24\\char\"24''}\n\t\t\t\t\\}\n\t\t\t\\]\n\t\t\t\n\t\t\tComparing \\(G\\) to \\(G'\\) results in the matrix in \\cref{fig:n-gram-misspelling-comparison}.  By using \\(n\\)-grams, we yield a similarity score of \\(\\sfrac{5}{10}\\).\n\t\t\t\n\t\t\t\\begin{figure}\n\t\t\t\t\\[\n\t\t\t\t\t\\bordermatrix{\n\t\t\t\t\t\t~ & G & G' \\cr\n\t\t\t\t\t\t\\term_{1} : \\text{``ns\\char\"24''} & 0 & 1 \\cr\n\t\t\t\t\t\t\\term_{2} : \\text{``n\\char\"24\\char\"24''} & 1 & 0 \\cr\n\t\t\t\t\t\t\\term_{3} : \\text{``s\\char\"24\\char\"24''} & 0 & 1 \\cr\n\t\t\t\t\t\t\\term_{4} : \\text{``ans''} & 0 & 1 \\cr\n\t\t\t\t\t\t\\term_{5} : \\text{``man''} & 1 & 1 \\cr\n\t\t\t\t\t\t\\term_{6} : \\text{``uma''} & 1 & 1 \\cr\n\t\t\t\t\t\t\\term_{7} : \\text{``\\char\"24\\char\"24h''} & 1 & 1 \\cr\n\t\t\t\t\t\t\\term_{8} : \\text{``hum''} & 1 & 1 \\cr\n\t\t\t\t\t\t\\term_{9} : \\text{``\\char\"24hu''} & 1 & 1 \\cr\n\t\t\t\t\t\t\\term_{10} : \\text{``an\\char\"24''} & 1 & 0 \\cr\n\t\t\t\t\t}\n\t\t\t\t\\]\n\t\t\t\t\n\t\t\t\t\\caption{Comparison between \\(n\\)-grams of \\(G\\) and \\(G'\\).}\n\t\t\t\t\\label{fig:n-gram-misspelling-comparison}\n\t\t\t\\end{figure}\n\t\t\\end{ex}\n\t\t\t\n\t\\subsection{Benefits and Drawbacks of the Document Model}\n\t\\label{sec:benefits-drawbacks-document-model}\n\t\tThere are numerous reasons to use the document model.  The most significant reason is that it allows users without domain knowledge and working knowledge of a complex query language such as \\gls{sql} to find information.  Another major advantage is that in the document model we do not need to design a database schema to store information.\n\t\t\n\t\t\\begin{ex}[Simple Queries]\n\t\t\tFind all documents related to ``mathematics'' or ``lecture''.  The result of the query \\(\\q\\) is\n\t\t\t\\[\n\t\t\t\t\\query(\\text{``mathematics''}) \\cup \\query(\\text{``lecture''}) \\rightarrow \\{\\doc_2, \\doc_3\\}\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\tUsers can also modify queries to require certain terms be present or not present.\n\t\t\n\t\t\\begin{ex}[\\texttt{AND} Query]\n\t\t\\label{ex:and-query}\n\t\t\tFind all documents containing both ``mathematics'' and ``lecture''.  This query returns the following set of documents\n\t\t\t\\[\n\t\t\t\t\\query(\\text{``mathematics''}) \\cap \\query(\\text{``lecture''}) \\rightarrow \\{\\doc_3\\}\n\t\t\t\\]\n\t\t\t\n\t\t\tas only \\(\\doc_3\\) contains both terms.\n\t\t\\end{ex}\n\t\t\n\t\t\\begin{ex}[\\texttt{NOT} Query]\n\t\t\tFind all documents containing ``mathematics'' but not ``lecture''.  This query returns different results than \\cref{ex:and-query}.\n\t\t\t\\[\n\t\t\t\t\\query(\\text{``mathematics''})\\neg\\query(\\text{``lecture''}) \\rightarrow \\emptyset\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\tWhile none of the above queries required domain knowledge, it is possible to use the extended document model (\\cref{sec:extending-the-document-model}) to search specific fields.  Doing so permits users to leverage their existing domain knowledge to achieve finer control over what documents are retrieved.\n\t\t\n\t\t\\begin{ex}[Extended Query]\n\t\t\\label{ex:extended-query}\n\t\t\tFind all documents with a subject of ``MATH'' that contain the term ``class''.\n\t\t\t\\[\n\t\t\t\t\\query(\\text{``subject''}, \\text{``MATH''}) \\cap \\query(\\text{``class''}) \\rightarrow \\{\\doc_1\\}\n\t\t\t\\]\n\t\t\\end{ex}\n\t\t\n\t\tNot only does the document model provide a familiar interface to search for information with, it also ranks the results.  In the relational model a search for ``mathematics'' returns all named tuples that contain that term.  In the document model, documents are ranked against the query \\(\\q\\) and the top-\\(k\\) documents are returned in descending order by score.\n\t\t\n\t\tThe advantage is that users have the result of \\(\\q\\) already ranked so only the most relevant documents may be explored.\t As the number of documents matching \\(\\q\\) for a large corpus can be high, showing only the top-\\(k\\) relevant documents may save the user a substantial amount of time.\n\t\t\n\t\tThe relational model does not permit approximate string matching.  By utilizing the document model with \\(n\\)-grams (\\cref{sec:n-gram}), users who substitute, delete, or insert characters from the desired term may still receive results for their intended term (see \\cref{ex:n-gram-comparison} for a demonstration of how \\(n\\)-grams overcome character insertion).\n\t\t\n\t\tUnfortunately the document model does not support the concept of foreign keys (\\cref{def:foreign-keys}).  While information is easily accessible due to flexible search, each document is a discrete unit of information.  Aggregate queries are unsupported, as these units are not linked amongst one another.", "meta": {"hexsha": "3f5e5cff3091b9751bfc76f090fc883a42b0748c", "size": 16361, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/document/document-model.tex", "max_stars_repo_name": "rdrake/Molly", "max_stars_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "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": "thesis/document/document-model.tex", "max_issues_repo_name": "rdrake/Molly", "max_issues_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-13T19:40:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-13T19:40:08.000Z", "max_forks_repo_path": "thesis/document/document-model.tex", "max_forks_repo_name": "rdrake/Molly", "max_forks_repo_head_hexsha": "f074ba926e6459d0074d980297d81dcad7f736d4", "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": 41.3156565657, "max_line_length": 383, "alphanum_fraction": 0.5992909969, "num_tokens": 5777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6017769733951451}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{tikz}\n\\usepackage[utf8]{inputenc}\n\\usepackage{aeguill}\n\\usepackage{setspace}\n\n\\usetikzlibrary{graphs,graphdrawing}\n\\usegdlibrary{trees}\n\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{January 28, 2015}\n\\maketitle\n\\section*{continuing with trees, 2.3}\nrecall that a tree is a graph such that\n\\begin{enumerate}\n\\item\nevery edge is a bridge\n\\item\nthere are no cycles\n\\item\norder $n$ and size $n-1$\n\\end{enumerate}\n\na natural question is to say ``how many non isomorphic trees of over $n$ are there?''\n\nearly application of graph theory is chemistry. molecules are trees\n\nfirst few\n\\begin{enumerate}\n\\item\n$n=1$ then we have $1$ tree\n\\item\n$n=2$ then we have $1$ tree\n\\item\n$n=3$ then we have $1$ non-isomorphic tree\n\\item\n$n=4$ then we have \n\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 1 -- 2; 1-- 3; 1--4 }\n  [shift=(0:2)]\n  graph [tree layout] { 1 -- {2 -- 3} -- 4 };\n\\end{enumerate}\n\nfor any $n$ the number of non-isomorphic trees on $n$-vertices is \\emph{a complete mystery}\n\n\\subsection*{simpler question}\nhow many non-isomorphic {\\bfseries labelled} trees exists on $n$-vertices?\n\na {\\bfseries labelled graph} is a graph where each vertex is distinguished by a label.\n\n\\subsubsection*{example}\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 1 -- 2;1 -- 3};\n$\\ne$\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 2 -- 1; 2-- 3; };\n\ntwo labeled graphs are different if their edge sets are different\n\n\\subsubsection*{example}\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 1--5--4--3;5--6--2;6--4 }\n  [shift=(0:2)]\n  graph [tree layout] { 3--4--6--2;4--5--1;5--6 }\n  [shift=(0:2)]\n    graph [tree layout] { 2--5--4--1;5--6--3;4--6 }\n  [shift=(0:1)];\n\n1 and 2 are the same, 3 is different\n\nthe solution is given neatly by Prüfer codes\n\n\\subsubsection*{example}\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 3--2--1;2--5;2--4--6 }\n  [shift=(0:1)];\n\\begin{enumerate}\n\\item\nrecord the neighbor of the leaf of least valued label\n\\item\nerase leaf and repeat\n\\item\nlast node is not in the code\n2\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 3--2;2--5;2--4--6 }\n  [shift=(0:1)];\n\n22\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 2--5;2--4--6 }\n  [shift=(0:1)];\n\n222\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 2--4--6 }\n  [shift=(0:1)];\n\n2224\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] { 4--6 }\n  [shift=(0:1)];\n\n2224\n\nthis process is reversible, but it's harder\n\\end{enumerate}\n\n\\tikz\\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]\n  graph [tree layout] {6--1--5--2--7;3--1;5--8--4}\n  [shift=(0:1)];\nprüfer code is $(1,8,1,5,2,5)$\n\\section*{spanning tree}\n\\subsection*{properties of prüfer codes}\n\\begin{enumerate}\n\\item\nlength is $n-2$\n\\item\n$i$ appears at most $\\deg(v_i)-1$ times\n\\item\nat most $n-2$ \\emph{different} entries\n\\end{enumerate}\n\n{\\bfseries Prüfer code} is a sequence of $n-2$ integers from $[n]$ where $[n]=\\{1,\\dots,n\\}$\n\nand so we have $n-2$ spaces with $n$ choices and so $n^{n-2}$ codes\n\n\\subsection*{Cayley's Tree theorem}\nLabelled trees are in bijection with Prüfer codes. ie there are $n^{n-2}$ labeled trees on $n$ vertices (non-isomorphic)\n\n\\section*{now finally spanning trees}\n{\\bfseries spanning graph} of $G$ is a subgraph $H$ such that $V(G)=V(H)$.\n\n{\\bfseries weighted graph} a graph with numerical labels on the edges\n\nquestion? how can we find a spanning tree of a weighted graph with least total weight?\n\n\\subsubsection*{greedy algorithm}\ncalled Kruskal's algorithm\n\n\\begin{enumerate}\n\\item\nchoose any edge of least weight\n\\item\nchoose any remaining edge of next least weight  that doesn't make a cycle\n\\item\nrepeat\n\\end{enumerate}\n\\end{document}\n\n", "meta": {"hexsha": "dc4e2506597cfe625671d75f1566b10057b32827", "size": 4444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "graph/graph-notes-2015-01-28.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": "graph/graph-notes-2015-01-28.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": "graph/graph-notes-2015-01-28.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": 27.4320987654, "max_line_length": 120, "alphanum_fraction": 0.6948694869, "num_tokens": 1546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6017769727131037}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath, amsfonts, graphicx}\n\\title{Synthesizing neural-network stabilizing controller for learned dynamics model}\n\\begin{document}\n\\section{Problem statement}\nAssume that we are given dynamics model represented as neural networks\n\\begin{align}\n\t\\text{discrete time } x[n+1] = f(x[n], u[n]) , u[n]\\in\\mathcal{U}\\\\\n\t\\text{continuous time } \\dot{x} = f(x) + G(x)u, u\\in\\mathcal{U}\n\\end{align}\nwhere $f, G$ contain neural networks which we will describe later, our goal is to synthesize a controller $u=\\pi(x)$, also represented by a neural network, and a Lyapunov function $V(x)$, represented by a third neural network, such that we can prove that the closed-loop system is Lyapunov stable. Namely we want to find a controller, such that the closed loop system is Lyapunov exponentially (or asymptotically) stable within a set $\\mathcal{S}$, i.e., for the equilibrium state/control $x^*, u^*$, all the states start within $\\mathcal{S}$ would eventually converge to equilibrium state.\n\nWe assume the set of admissible inputs $\\mathcal{U}$ is a box in the input space, namely we have input bounds $u_{min}(i)\\leq u(i)\\leq u_{max}(i)$ for each dimension of the input.\n\nNotice that we assume the continuous-time system is control affine. We will exploit this property later.\n\n\\section{Approach}\nWe consider the discrete-time and continuous-time system separately. Let's first consider the discrete-time case. In this project, all the neural networks are feed-forward neural network with leaky Relu units, hence the output of the network is a piecewise affine function of the input.\n\\subsection{Discrete time system}\nFirst we assume that our forward dynamical system is represented by a neural network\n\\begin{align}\n\tx[n+1] = \\phi_{dyn}(x[n], u[n]) - \\phi_{dyn}(x^*, u^*) + x^* \\label{eq:discrete_forward_dyn}\n\\end{align}\nwhere $\\phi_{dyn}$ is a feed-forward neural network with (leaky) ReLU activation units. Notice that by construction \\eqref{eq:discrete_forward_dyn} guarantees that with $x[n]=x^*, u[n]=u^*$ the next state is still the equilibrium state $x^*$. This neural network $\\phi_{dyn}$ is given and fixed.\n\nThe Lyapunov function for exponetial stability is\n\\begin{subequations}\n\\begin{align}\n\tV(x) > 0 \\;\\forall x\\neq x^*, V(x^*) = 0\\\\\n\tV(x[n+1]) - V(x[n]) \\le -\\epsilon_2 V(x[n])\\\\\n\tx \\rightarrow \\infty \\Rightarrow V(x)\\rightarrow \\infty\n\\end{align}\n\\end{subequations}\n \nSince we will certify the Lyapunov condition through MILP, which cannot handle strict inequality constraint $V(x) > 0$, we consider the following necessary and sufficient condition\n\\begin{subequations}\n\\begin{align}\n\tV(x) \\ge \\epsilon_1 |R(x-x^*)|_1\\\\\n\tV(x[n+1]) - V(x[n]) \\le -\\epsilon_2V(x[n])\n\\end{align}\n\\label{eq:lyapunov_discrete}\n\\end{subequations}\nwhere $R$ is a matrix with full column rank, $|R(x-x^*)|_1$ is the 1-norm of the vector $R(x-x^*)$.\n\nWe design our Lyapunov function as\n\\begin{align}\n\tV(x) = \\phi_{V, \\theta}(x) -\\phi_{V, \\theta}(x^*) + \\lambda|R(x-x^*)|_1 \\label{eq:lyapunov}\n\\end{align}\nwhere $\\phi_{V, \\theta}$ is a feedforward neural network with (leaky) ReLU activation functions. $\\lambda$ is a given positive constant (with $\\lambda > \\epsilon_1$). The reason to add the term  $\\lambda|R(x-x^*)|_1$ to the Lyapunov function \\eqref{eq:lyapunov}, is that it is very hard for the neural network $\\phi_{V, \\theta}$ to attain its minimum at $x^*$ (Since the neural network $\\phi_{V, \\theta}$ is a piecewise affine function of $x$. If it were to attain minimal at $x^*$, it implies that $x^*$ is the common vertex of all the neighbouring linear pieces, which is almost impossible to satisfy by gradient descent approach. See fig. \\ref{fig:lyapunov_add_l1_3} as a visual explanation.) By adding the function $\\lambda|R(x-x^*)|_1$ which has its global minimal at $x^*$, it is much easier to make the Lyapunov function to attain global minimal at $x^*$. Also by construction of \\eqref{eq:lyapunov} we have $V(x^*) = 0$.\n\\begin{figure}\n\t\\includegraphics[width=0.8\\textwidth]{/home/hongkaidai/Dropbox/talks/pictures/neural_network_controller/lyapunov_add_l1_3.pdf}\n\t\\caption{Adding the term $\\lambda |x-x^*|_1$ helps the neural network to attain (local) minimal at $x^*$.}\n\t\\label{fig:lyapunov_add_l1_3}\n\\end{figure}\n\nOur controller is also represented by a neural network as\n\\begin{align}\n\tu[n] = saturate(\\phi_{u, \\eta}(x[n]) - \\phi_{u, \\eta}(x^*) + u^*)\\label{eq:controller}\n\\end{align}\nwhere $\\phi_{u, \\eta}$ is a feedforward neural network with (leaky) ReLU activation functions. The weights/biases of this network is denoted by $\\eta$. $saturate$ is the saturation function that clamp the control within the input limits. Again by construction of \\eqref{eq:controller}, the control action at the equilibrium state $x^*$ is $u^*$.\n\nWe could solve the following two optimization problem as MILP\n\\begin{align}\n\t\\max_{x} \\epsilon_1|R(x-x^*)|_1 - V(x)\\\\\n\t\\max_{x[n]} V(x[n+1]) - V(x[n]) + \\epsilon_2V(x[n])\n\\end{align}\nWhen the maximal cost of either the function is larger than 0, we find a counter example that violates the Lyapunov condition \\eqref{eq:lyapunov_discrete}. Our goal is to find the neural network for controller and Lyapunov function, such that the violation is 0. Namely we solve the following min-max problem.\n\\begin{align}\n\t\\min_{\\theta, \\eta, R} \\left(\\max_{x}\\epsilon_1|R(x-x^*)|_1 - V(x) + \\max_{x[n]} V(x[n+1]) - V(x[n]) + \\epsilon_2V(x[n])\\right)\n\\end{align}\nAfter solving the inner maximization problem, we then compute the gradient of the maximal cost w.r.t $\\theta, \\eta, R$, and then use gradient descent to minimize the loss.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Continuous-time system}\nWe assume that the continuous time system forward dynamics is\n\\begin{align}\n\t\\dot{x} = \\phi_f(x) + \\phi_G(x)u - \\phi_f(x^*) - \\phi_G(x^*)u^*\n\\end{align}\nwhere $\\phi_f, \\phi_G$ are given feedforward neural networks with leaky ReLU activation units. Without loss of generality we can assume that the bounds on the control input $u$ is \n\\begin{align}\n\t-\\mathbf{1}\\le u \\le \\mathbf{1}\n\\end{align}\n\nDue to the control-affine property of the continuous-time system, we will show that we can search for a control Lyapunov function, instead of a controller and a Lyapunov function as in the discrete-time case. The control Lyapunov function satisfies\n\\begin{subequations}\n\\begin{align}\n\tV(x) \\ge \\epsilon_1|R(x-x^*)|_1\\\\\n\t\\min_{-\\mathbf{1}\\le u\\le \\mathbf{1}} \\dot{V}\\le -\\epsilon_2V(x)\\label{eq:lyapunov_condition_Vdot_continuous}\n\\end{align}\n\\label{eq:lyapunov_condition_continuous}\n\\end{subequations}\n\nNote that the left-hand side of the condition \\eqref{eq:lyapunov_condition_Vdot_continuous} can be rewritten as\n\\begin{subequations}\n\\begin{align}\n\t&\\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\dot{V}\\\\\n\t=&\\min_{-\\mathbf{1}\\le u \\le\\mathbf{1}}\\frac{\\partial V}{\\partial x}(\\phi_f(x) + \\phi_G(x)u - \\phi_f(x^*) - \\phi_G(x^*)u^*)\\\\\n\t=&\\frac{\\partial V}{\\partial x}(\\phi_f(x) - \\phi_f(x^*) - \\phi_G(x^*)u^*) + \\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\frac{\\partial V}{\\partial x}\\phi_G(x)u\\label{eq:control_lyapunov3}\\\\\n\t=&\\frac{\\partial V}{\\partial x}(\\phi_f(x) - \\phi_f(x^*) - \\phi_G(x^*)u^*) - \\left|\\frac{\\partial V}{\\partial x}\\phi_G(x)\\right|_1\\label{eq:control_lyapunov4}\n\\end{align}\n\\end{subequations}\nFrom \\eqref{eq:control_lyapunov3} to \\eqref{eq:control_lyapunov4} we use the fact that $\\min_{|x|_{\\infty}\\le 1} a^Tx = -|a|_1$, namely 1-norm is the \\textit{dual norm} of $\\infty$-norm.\n\nWe represent the control-Lyapunov function through a neural network as\n\\begin{align}\n\tV(x) = \\phi_{V, \\theta}(x) - \\phi_{V, \\theta}(x^*) + \\lambda|R(x-x^*)|_1\n\\end{align}\n\nAnd we solve the following two MILPs to either certify the control-Lyapunov condition, or find the counter-examples.\n\\begin{align}\n\t\\max_{x} \\epsilon_1|R(x-x^*)|_1 - V(x)\\\\\n\t\\max_{x} \\underbrace{\\frac{\\partial V}{\\partial x}(\\phi_f(x) - \\phi_f(x^*) - \\phi_G(x^*)u^*) - \\left|\\frac{\\partial V}{\\partial x}\\phi_G(x)\\right|_1}_{\\min_{-\\mathbf{1}\\le u \\le \\mathbf{1}} \\dot{V}} + \\epsilon_2V(x)\n\\end{align}\n\nWe then compute the gradient of each MILP cost w.r.t $\\theta, R$, and then use gradient descent on $\\theta, R$ to minimize the loss.\n\n\\end{document}\n", "meta": {"hexsha": "d50fc75e98024fe11779857890c214767a4d3d37", "size": 8171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/stabilizing_controller.tex", "max_stars_repo_name": "StanfordASL/neural-network-lyapunov", "max_stars_repo_head_hexsha": "9e5db1c7f91b42df729026c9aa8575bc126f66b6", "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/stabilizing_controller.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/stabilizing_controller.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": 69.2457627119, "max_line_length": 928, "alphanum_fraction": 0.7165585608, "num_tokens": 2604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673359709796, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6016635711425267}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{enumitem}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\\begin{document}\n\\title{MATH1830 --- Assignment 5}\n\\author{Dylan Pinn --- 24160547}\n\\maketitle\n\nLet $A = \\mathcal{P}(\\{1,2,3,4\\})$. Let $f$, $g$ and $h$ be the following functions.\n\n$ f: A \\to A$ defined by $(X) = X \\cap \\{1,4\\}$\n\\begin{equation*}\n  g: A \\to \\mathbb{Z} \\text { defined by } g(X) =\n  \\begin{cases} \n      -1 & \\text{if } X = \\emptyset \\\\\n      \\text{ the smallest element of X} & if X \\not = \\emptyset \n   \\end{cases}\n\\end{equation*}\n\n$h: \\{1,2,3,4\\} \\to A$ defined by $h(x)=\\{1,2,3,4\\} - \\{x\\}$\n\n\\section*{Question 1}\n  \n\\begin{enumerate}[label=(\\roman*)]\n  \\item Write down $f(\\{1,2\\})$\n  $$= \\{1,2\\} \\cap \\{1,4\\} = \\{1\\}$$\n\n  \\item Write down $g(\\{2,4\\})$\n  $$= \\{2\\}$$\n\n  \\item Write down $h(4)$\n  $$= \\{1,2,3\\}$$\n\n  \\item Write down $f(h(1))$\n  $$h(1) = \\{1\\}$$\n  $$f(\\{1\\}) = \\{1\\}$$\n\\end{enumerate}\n\n\\break\n\\section*{Question 2}\n\n\\begin{enumerate}[label=(\\roman*)]\n  \\item Is $f$ one-to-one?\n  \n  To show that it is not one-to-one we must show that $f(x_1) = f(x_2)$ and $x_1 \\not = x_2$\n  \n  By using the values of $x_1 = \\{1,2\\}$ and $x_2 = \\{1,3\\}$ we can show that the functions of both of these do not match.\n  \n  \\begin{equation*}\n    f(x_1) = \\{1,2\\} \\cap \\{1,4\\} = \\{1\\} \\\\\n    f(x_2) = \\{1,3\\} \\cap \\{1,4\\} = \\{1\\}\n  \\end{equation*}\n  \n  \\item Is $g$ one-to-one?\n  \\item Is $h$ one-to-one?\n\\end{enumerate}\n\n\\section*{Question 3}\n\n\\begin{enumerate}[label=(\\roman*)]\n  \\item Write down the image of $f$.\n  $$= \\mathcal{P}(\\{1,4\\})$$\n \n  \\item Write down the image of $g$.\n  $$= \\{-1, 1, 2, 3, 4\\}$$\n  \n  \n  \\item Write down the image of $h$.\n  $$= \\mathcal{P}(1,2,3,4) -  \\{\\}$$\n\\end{enumerate}\n\n\\section*{Question 4}\n\n\\begin{enumerate}[label=(\\roman*)]\n  \\item How many functions are there with domain $A$ and codomain $\\{0,1\\}$?\n  \n  The domain has 16 elements $(2^4)$.\n  \n  For each input, we can decide if it's mapped to a 0 or 1.\n  \n  We can do this $2^{16} = 65536$ ways.\n  \n  \\item How many one-to-one functions are there wth domain $A$ and codomain $\\{0,1\\}$?\n  \n  Each element in A is mapped to $\\{0,1\\}$. To find out the number of permutations of this:\n  $$= \\frac{n!}{(n-k)!}$$\n  \n  We use number of elements of $A$ as $n$ and the number of elements in the codomain as $k$. This gives:\n  $$\\frac{16!}{(16-2)!} = 240$$\n  \n  \\item How many onto functions are there with domain $A$ and codomain $\\{0,1\\}$?\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "56eaeb0a180d9600d57b6f9cde071b4429c813c0", "size": 2469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignments/assignment-05.tex", "max_stars_repo_name": "dylanpinn/MAT1830", "max_stars_repo_head_hexsha": "43c76e9502508c64f7726002613e777e2d71ac88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-03-01T22:58:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T03:41:28.000Z", "max_issues_repo_path": "assignments/assignment-05.tex", "max_issues_repo_name": "dylanpinn/MAT1830", "max_issues_repo_head_hexsha": "43c76e9502508c64f7726002613e777e2d71ac88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-03-05T13:52:05.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-03T06:46:04.000Z", "max_forks_repo_path": "assignments/assignment-05.tex", "max_forks_repo_name": "dylanpinn/MAT1830", "max_forks_repo_head_hexsha": "43c76e9502508c64f7726002613e777e2d71ac88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-27T03:41:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-19T15:55:08.000Z", "avg_line_length": 25.9894736842, "max_line_length": 122, "alphanum_fraction": 0.5702713649, "num_tokens": 1015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6016635467250568}}
{"text": "\\section{Boolean algebra}\n\\label{sec:boole}\n\\index{Boolean algebra}\n%\nBoolean algebra has a long history. George Boole (\\lifetime{1815}{1864}), John Venn (\\lifetime{1834}{1923}) and William Stanley Jevons (\\lifetime{1835}{1882}) pioneered an algebraic structure $\\langle B, \\lor, \\land, \\neg, 0, 1\\rangle$ with the following properties ($x$ and $y$ are boolean expressions and therefore in $B$)~\\cite[10]{Sat20}:\n%\n\\begin{itemize}\n  \\item $\\land$ and $\\lor$ are binary operators. $\\neg$ is an unary operator.\n  \\item $0, 1 \\in B$\n  \\item $x \\land y = y \\land x; x \\lor y = y \\lor x$\n  \\item $x \\lor (y \\land z) = (x \\lor y) \\land (x \\lor z); x \\land (y \\lor z) = (x \\land y) \\lor (x \\land z)$\n  \\item $x \\lor \\neg x = 1; x \\land \\neg x = 0$\n  \\item $1 \\land x = x; 0 \\lor x = x$\n\\end{itemize}\n\nIn the following sections boolean algebra will be used to derive clauses for the \\gls{sat} solver. De Morgan's laws are a set of transformation rules in boolean algebra of equivalent statements. The following one will be used in the document:\n\n\\[\n  \\neg (x \\land y) \\qquad\\Leftrightarrow\\qquad (\\neg x) \\land (\\neg y)\n\\]\n\n\\section{Satisfiability}\n\\label{sec:sat}\n\\index{Satisfiability}\n%\nThe satisfiability problem states the following question:\n\\begin{quote}\n  ``Is a given boolean system in conjunctive normal form \\emph{satisfiable}?''\n\\end{quote}\n%\nSatisfiability or consistency in logic refers to a property of a boolean expression. A boolean equation is satisfiable if and only if there exists some truth assignment for the given expression which evaluates to true.\n\n\\index{Cook-Levin theorem}\nThe Cook-Levin theorem states that the \\gls{sat} problem is NP-complete. This was proven in 1971 by Stephen Cook~\\cite{Sat01} and Leonid Levin~\\cite{Sat02} independently. As such \\gls{sat} problems seem to be computationally infeasible for larger problem sizes and \\gls{sat} solvers are tools to solve those NP-complete problems in the best possible way.\n\n\\index{Conjunctive normal form}\n\\index{Disjunctive normal form}\n\\index{Clauses}\nA $k$-SAT problem (with $k \\in \\mathbb{N}$) is a \\gls{sat} problem in \\gls{cnf} with at maximum $k$ literals per clause. A \\gls{cnf} is the conjunction of disjunctions (so-called \\emph{clauses}). A \\gls{dnf} is the disjunction of conjunctions.\n\n\\section{SAT solving techniques}\n\\label{sec:satsolvers}\n\\index{SAT solvers}\n%\n\\index{DIMACS format}\nIn 1958 Martin Davis and Hilary Putnam proposed the CNF as input for satisfiability problems in an unpublished manuscript for the NSA~\\cite{Sat20}. The DIMACS format has been developed as universal input format for SAT solvers~\\cite{Sat09}.\n\n\\gls{sat} solvers today are variants of the DPLL algorithm. In the original design, four techniques are discussed:\n\\begin{description}\n  \\item[Unit clause.] Clauses with one literal are immediately processed and taken as assignment. A literal is a boolean variable or its negation.\n  \\item[Pure literal rule.] If all occurences of a variable happen with the same polarity, all those clauses can be discarded if the variable gets assigned its polarity.\n  \\item[Elimination of atomic formulas.] Formulas which are atomic for the given equation system get eliminated.\n  \\item[Splitting rule.] Even a single variable might split the whole search space and shall be used as an advantage for speedup.\n\\end{description}\n%\nThe first two techniques are explicitly part of the DPLL algorithm. The often cited paper for the DPLL algorithm is Davis' ``A Computing Procedure for Quantification Theory''~\\cite{Sat05} and a discussion of the history is provided in ``Early History and Perspectives of Automated Deduction''~\\cite{Sat06}. A discussion of possible approaches to this problem is given by Jun Gu, Paul W. Purdom, John Franco and Benjamin Wah~\\cite{Sat08}.\n\nFurther efforts were especially put into efficient representation of the search space with techniques like early pruning, replacement of a tree-like search space with a DAG-like search space and variable choice heuristics~\\cite[24]{Sat20}.\n\nTwo further rules are considered:\n\\begin{description}\n  \\item[Shortest clause rule.]\n    Prefer the assignment of a variable from an existing clause containing the fewest unset literals.\n  \\item[Majority rule.]\n    Prefer the assignment of a variable with the maximum difference between the number of its positive and negative literals.\n\\end{description}\n\n\\subsection{Assumptions}\n\\label{sec:satsolvers-assumptions}\n\\index{Assumptions (SAT solvers)}\n%\nThe interface of a \\gls{sat} solver typically consists of a function to add clauses and a solve function. As such most of the current \\gls{sat} solvers work incrementally; they allow to add clauses to the \\gls{sat} solver and to repeatedly invoke the solve function.\n\nAssumptions are a separate concept which allows the user to specify hints. An assumption is one assignment of a variable that will be lost after one SAT solver evaluation. This way the user has a certain level of control which variables are evaluated.\n\nAssumptions can be simply integrated to the \\gls{cnf} as unit clauses if their value shall be assigned persistently.\n% TODO: better research. Where are assumptions studied?\n\n\\subsection{Runtime analysis}\n\\label{sec:satsolvers-runtime}\n%\nSatisfiability of a CNF formula~$\\phi$ with $n$ boolean variables can be decided in time $\\mathcal{O}(2^n \\abs{\\phi})$ by enumerating all assignments of the variables. Also the number of literals $l$ and number of clauses $m$ have to be considered.\n\nIn 2002 researchers found some deterministic algorithm~\\cite{Sat07} using local search to solve $k$-SAT instances with the best runtime to this day: $(2 - 2/(k+1))^n$. However the general \\gls{sat} problem is not limited to a number of literals per clause.\n\nBecause the desired runtime is not always achieved, focus is put on the encoding and transformation of SAT instances. Grigorii Samuilovich Tseitin got famous for his research in transformations and encoding like the Tseitin encoding. In a recent paper~\\cite{Sat22} Peter Stuckey points out that there are no original SAT problems and we should focus on representing problems in the way they originally appear. SAT research is closely related to the field of \\gls{csp}, which also considers other encodings.\n\nIn terms of performance the following properties of a \\gls{cnf} can be used as measurement~\\cite{Sat20}:\n\\begin{description}\n  \\item[Encoding size.]\n    is defined by the number of clauses, literals or variables.\n    We always add clauses to SAT solvers making the boolean system larger. But symmetry-breaking clauses and blocked clauses can actually improve evaluation speed.\n  \\item[Consistency properties.]\n    This includes arc consistency and forward checking.\n  \\item[Solution density.]\n    The number of solutions divided by $2^n$ ($n$ as the number of variables). The higher the solution density, the faster a satisfying solution can be found.\n\\end{description}\n\n\\section{Obtain CNF and DNF from truth table}\n\\label{sec:cnf-dnf}\n%\n\\index{Truth table}\nTruth tables have 2 dimensions and list all possible boolean variable configurations and their outcome for a given function. Ludwig Wittgenstein established binary truth tables in his philosophical book ``Tractatus Logico-Phulosophicus''.\n\nHaving a boolean function we can always determine an equivalent \\gls{cnf} or \\gls{dnf}.\n\n\\begin{description}\n  \\item[Disjunctive normal form.]\n    The disjunctive normal form can be retrieved by extracting all configurations resulting in value true. Each configuration represents a conjunction of literals. Literals are generated by taking the variable corresponding to the truth value\\footnote{Value true for a variable $v$ yields the literal $v$. Value false yields the literal $\\neg v$.}. The DNF is the disjunction of the configurations.\n  \\item[Conjunctive normal form.]\n    The conjunctive normal form can be retrieved by extracting all false configurations. Each configuration represents a disjunction of literals and literals are created with opposite polarity\\footnote{Value true for a variable $v$ yields the literal $\\neg v$. Value false yields the literal $v$.}. The CNF is the conjunction of the configurations.\n\\end{description}\n\nIt is important to point out that building the truth table takes $\\mathcal{O}(2^n)$ for $n$ variables if constant runtime is assumed for the evaluation of the boolean function. This leads to a problem in our implementation. In general we don't know the functions to be used in advance, but require the equivalent \\gls{cnf} for the \\gls{sat} solver. In our implementation we generate the truth table for every function to be used to retrieve all outcomes.\n\n", "meta": {"hexsha": "0a94b261de3d6892d533ae31602656b4f5e9e983", "size": 8637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sat.tex", "max_stars_repo_name": "prokls/bakk_iaik", "max_stars_repo_head_hexsha": "96646ead8b111287b9ba0024d5ef129303bdf493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sat.tex", "max_issues_repo_name": "prokls/bakk_iaik", "max_issues_repo_head_hexsha": "96646ead8b111287b9ba0024d5ef129303bdf493", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sat.tex", "max_forks_repo_name": "prokls/bakk_iaik", "max_forks_repo_head_hexsha": "96646ead8b111287b9ba0024d5ef129303bdf493", "max_forks_repo_licenses": ["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.4568965517, "max_line_length": 506, "alphanum_fraction": 0.7737640384, "num_tokens": 2132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6016635424404108}}
{"text": "\\section{Examples}\n\\label{sec:examples}\n\nWe now see three applicative examples of the Marciani Normal Form and Marciani's\nRule.\nLet us first consider a very simple application.\n\n\\begin{example}\n\tLet us consider the context-free grammar $G$ with axiom $S$ and\n\tthe following productions\n\n\t\\begin{flalign*}\n\t\tS&\\rightarrow abcS|Sdef|ghi|\\varepsilon\n\t\\end{flalign*}\n\n\tThe grammar is in MNF, thus we know it generates a context-free language.\n\tThe language generated by $G$ is denoted by the regular expression\n\n\t\\begin{equation*}\n\t\t(abc)^{*}(ghi+\\varepsilon)(def)^{*}\n\t\\end{equation*}\n\\end{example}\n\nLet us now consider a slightly more complex application.\n\n\\begin{example}\n\tLet us consider the context-free grammar $G$ with axiom $S$ and\n\tthe following productions\n\n\t\\begin{flalign*}\n\t\tS&\\rightarrow aAS|SBdef|CD|\\varepsilon \\\\\n\t\tA&\\rightarrow uA|Av|m \\\\\n\t\tB&\\rightarrow xB|By|n \\\\\n\t\tC&\\rightarrow gC|Ch|i \\\\\n\t\tD&\\rightarrow pD|Dq|r\n\t\\end{flalign*}\n\n\tThe grammar is in MNF, thus we know it generates a context-free language.\n\tThe language generated by $G$ is denoted by the regular expression\n\n\t\\begin{equation*}\n\t\t(au^{*}mv^{*})^{*}(g^{*}ih^{*}p^{*}rq^{*}+\\varepsilon)(x^{*}ny^{*}def)^{*}\n\t\\end{equation*}\n\\end{example}\n\nWe now consider an application on a grammar in the notable Chomsky Normal Form\n(CNF) \\cite{chomsky1959certain}.\n\n\\begin{example}\n\tLet us consider the context-free grammar $G$ with axiom $S$ and the following\n\tproductions\n\n\t\\begin{flalign*}\n\t\tS&\\rightarrow AS|SB|CD|z|\\varepsilon \\\\\n\t\tA&\\rightarrow UA|AU|m \\\\\n\t\tB&\\rightarrow XB|BX|n \\\\\n\t\tC&\\rightarrow UC|CU|i \\\\\n\t\tD&\\rightarrow XD|DX|r \\\\\n\t\tU&\\rightarrow u \\\\\n\t\tX&\\rightarrow x\n\t\\end{flalign*}\n\n\tThe grammar is in MNF, thus we know it will generate a context-free language.\n\tThe language generated by $G$ is denoted by the regular expression\n\n\t\\begin{equation*}\n\t\t(u^{*}mu^{*})^{*}(u^{*}iu^{*}x^{*}rx^{*}+z+\\varepsilon)(x^{*}nx^{*})^{*}\n\t\\end{equation*}\n\\end{example}\n", "meta": {"hexsha": "dbd9892b8b0667e0eb381c336da53fdb31e731c8", "size": 1939, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "marciani-normal-form/sec/examples.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/examples.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/examples.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": 27.7, "max_line_length": 80, "alphanum_fraction": 0.6941722537, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6016635416918507}}
{"text": "\\chapter{}\n\n\\rmk{1} As a reminder, for a canonical exponential family\n\\[\nf(\\mathbf{x} \\mid \\eta)=h(\\mathbf{x}) \\exp \\{\\langle\\eta, T(\\mathbf{x})\\rangle-A(\\eta)\\}, \\quad \\eta \\in \\operatorname{int}(\\mathcal{E}) \\neq \\emptyset\n\\]\nit is true that\n\\[\n\\frac{\\partial^{k}}{\\partial \\eta^{k}} \\int f(\\mathbf{x} \\mid \\eta) G(d \\mathbf{x})=\\int \\frac{\\partial^{k}}{\\partial \\eta^{k}} f(\\mathbf{x} \\mid \\eta) G(d \\mathbf{x}), \\quad k \\in \\mathbb{N}\n\\]\nwhere \\(\\frac{\\partial^{k}}{\\partial \\eta^{k}}\\) represents the vector derivative with respect to \\(\\eta\\).\n\n\\rmk{2} As another reminder, the application of the theorem on asymptotic efficiency essentially boils down to verifying the conditions\n\\begin{enumerate}[(a)]\n    \\item \\(\\int f\\left(x_{1} \\mid \\theta\\right) G\\left(d x_{1}\\right)\\) can be differentiated twice under the integral sign; \n    \\item the third derivative of \\(\\log f\\left(x_{1} \\mid \\theta\\right)\\) is uniformly bounded by an integrable random variable (i.e., \\(M\\left(X_{1}\\right)\\) such that \\(\\left.\\mathbb{E}_{\\theta}\\left|M\\left(X_{1}\\right)\\right|<\\infty\\right)\\). \n\\end{enumerate}\nIn all problems where \\(\\theta\\) appears, it denotes the parameter or vector of parameters, accordingly. \n\n\\begin{ex}\n    Let \\(\\left\\{X_{n}\\right\\}_{n \\in \\mathbb{N}} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}(\\theta, 1), \\theta \\in \\mathbb{R}\\). Recall that the Hodges estimator is defined by\n\\[\n\\delta(\\mathbf{X})=\\left\\{\\begin{array}{cl}\n\\bar{X}, & \\text { if }|\\bar{X}| \\geq n^{-1 / 4} \\\\\na \\bar{X}, & \\text { if }|\\bar{X}|<n^{-1 / 4}\n\\end{array}\\right.\n\\]\nwhere \\(0<a<1\\). For \\(g(\\theta)=\\theta\\), prove that\n\\[\n\\sqrt{n}(\\delta(\\mathbf{X})-g(\\theta)) \\stackrel{d}{\\rightarrow} \\mathcal{N}(0, v(\\theta)), \\quad n \\rightarrow \\infty\n\\]\nwhere\n\\[\nv(\\theta)=\\left\\{\\begin{array}{cc}\n1, & \\text { if } \\theta \\neq 0 \\\\\na^{2}, & \\text { if } \\theta=0\n\\end{array}\\right.\n\\]\n(suggestion: for the case \\(\\theta \\neq 0\\), break up\n\\[\n\\sqrt{n}(\\delta(\\mathbf{X})-\\theta)=\\sqrt{n}(\\bar{X}-\\theta) 1_{\\left\\{|\\bar{X}| \\geq n^{-1 / 4}\\right\\}}+a \\sqrt{n}(\\bar{X}-\\theta) 1_{\\left\\{|\\bar{X}|<n^{-1 / 4}\\right\\}}+(a-1) \\theta \\sqrt{n} 1_{\\left\\{|\\bar{X}|<n^{-1 / 4}\\right\\}} .\n\\]\nNow show that \\(\\mathbb{P}_{\\theta}\\left(|\\bar{X}|<n^{-1 / 4}\\right) \\rightarrow 0\\) as \\(\\left.n \\rightarrow \\infty\\right)\\).\n\\end{ex}\n\n\\begin{solution}\n    For the case $\\theta=0$, $P(|\\bar{X}|\\geqslant n^{-1/4})\\to 0$, \n    \\begin{align*}\n        \\sqrt{n}(\\delta(\\mathbf{X})-\\theta)&=\\sqrt{n}(\\bar{X}-\\theta) 1_{\\left\\{|\\bar{X}| \\geq n^{-1 / 4}\\right\\}}+\\sqrt{n}(a\\bar{X}-\\theta) 1_{\\{|\\bar{X}|<n^{-1/4}\\}}\\\\\n        &=a\\sqrt{n}\\bar{X}. \n    \\end{align*}\n    $Var(a\\sqrt{n}\\bar{X})=a^2. $\n\n    \\noindent For the case $\\theta\\neq 0$, \n    \\[\n        \\begin{aligned}\n            P(|\\bar{X}|<n^{-1/4})&=P(\\sqrt{n}|\\bar{X}-\\theta+\\theta|<n^{1/4})=P(|Z+\\sqrt{n}\\theta|<n^{1/4})\\\\\n            &=\\Phi(n^{1/4}-\\sqrt{n}\\theta)-\\Phi(-n^{1/4}-\\sqrt{n}\\theta)\\to 0. \n        \\end{aligned}\n    \\]\n    So, $\\sqrt{n}(\\delta(X)-\\theta)\\to \\sqrt{n}(\\bar{X}-\\theta)\\to \\mathcal{N}(0,1)$. \n\\end{solution}\n\n\n\n\\begin{ex}\n    \\label{ex:7.2}\n    Determine whether or not the location families based on the following densities have unique roots. \n    \\begin{enumerate}[(a)]\n        \\item \\label{ex:7.2.a} \\(f(x)=\\frac{1}{\\sqrt{2 \\pi}} \\exp \\left\\{-\\frac{1}{2} x^{2}\\right\\}, x \\in \\mathbb{R}\\); \n        \\item \\(f(x)=\\frac{e^{-x}}{\\left(1+e^{-x}\\right)^{2}}, x \\in \\mathbb{R}\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\[\n            f(\\mathbf{x}, \\theta)=(2\\pi)^{-n/2} \\exp\\left(-\\frac{1}{2}\\sum_{i=1}^n(x_i-\\theta)^2\\right)\n        \\]\n        \\[\n            l(\\theta)=-\\frac{n}{2}\\log 2\\pi-\\frac{1}{2}\\left(\\sum_{i=1}^n(x_i-\\theta)^2\\right). \n        \\]\n        \\[\n            \\frac{\\pder l(\\theta)}{\\pder \\theta}=\\sum_{i=1}^nx_i-n\\theta=0\\Rightarrow \\theta=\\sum x_i/n. \n        \\]\n        So, it has the unique root. \n        \\item \\[\n            f(\\mathbf{x}, \\theta)=\\exp\\left(-\\sum_{i=1}^n x_i-n\\theta\\right)\\prod_{i=1}^n(1+e^{-x_i-\\theta})^{-2}. \n        \\]\n        \\[\n            l(\\theta)=-\\sum_{i=1}^n x_i-n\\theta-2\\sum_{i=1}^n\\log(1+e^{-x_i-\\theta}). \n        \\]\n        \\[\n            \\frac{\\pder l(\\theta)}{\\pder \\theta}=-n+2\\sum_{i=1}^n\\frac{e^{-x_i-\\theta}}{1+e^{-x_i-\\theta}}\n        \\]\n        This log likelihood function is monotone decreasing, and $l(\\theta)\\to n$, when $\\theta\\to-\\infty$; $l(\\theta)\\to -n$, when $\\theta\\to\\infty$. So, it must have a unique root. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Consider a sample \\(X_{1}, \\cdots, X_{n}\\) from a Poisson distribution conditioned to be positive, i.e.,\n    \\[\n        \\mathbb{P}\\left(X_{1}=x\\right)=\\frac{\\theta^{x} e^{-\\theta}}{x !\\left(1-e^{-\\theta}\\right)} . \\quad x \\in \\mathbb{N} .\n    \\]\n    Show that the likelihood equation has a unique root for all values of \\(x\\). \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        f(X)=\\frac{\\theta^{\\sum x_i} e^{-n\\theta}}{\\prod x_i! (1-e^{-\\theta})^n}. \n    \\]\n    \\[\n        l(\\theta)=\\sum x_i \\log \\theta-n\\theta-\\sum_{i=1}^n\\log x_i!-n\\log (1-e^{-\\theta}). \n    \\]\n    \\[\n        \\frac{\\partial}{\\partial\\theta}l(\\theta)=\\frac{\\sum x_i}{\\theta}-\\frac{n}{1-e^{-\\theta}}=0. \n    \\]\n    \\[\n        \\frac{\\theta}{1-e^{-\\theta}}=\\bar{X}. \n    \\]\n    The range of left side is $(1, \\infty)$ and the left side is monotone increasing. So, unless $\\bar{X}=1$, $\\theta$ has a unique root. \n\\end{solution}\n\n\\begin{ex}\n    The so-called digamma function \\(\\Gamma^{\\prime}(\\alpha) / \\Gamma(\\alpha), \\alpha>0\\), is an increasing function of \\(\\alpha\\). Use this fact to prove that, for a sample \\(X_{1}, \\cdots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\Gamma(\\alpha, 1)\\), the likelihood equation has a unique root. Can we arrive at the same conclusion by using a general result for canonical exponential families?\n\\end{ex}\n\n\\begin{solution}\n    Let $\\psi(\\alpha)$ be digamma function. \n    \\[\n        f(X)=\\frac{(\\prod x_i)^{\\alpha-1}e^{-\\sum x_i}}{n\\Gamma(\\alpha)}. \n    \\]\n    \\[\n        l(\\theta)=(\\alpha-1)\\sum_{i=1}^n \\log x_i-n\\log (\\Gamma(\\alpha))-\\sum_{i=1}^n x_i. \n    \\]\n    \\[\n        \\frac{\\partial}{\\partial\\theta}l(\\theta)=\\sum_{i=1}^n\\log x_i-n\\psi(\\alpha)=0. \n    \\]\n    \\[\n        \\psi(\\alpha)=\\frac{\\sum_{i=1}^n \\log x_i}{n}>0. \n    \\]\n    And because $\\log (\\alpha)-1/(2\\alpha)>\\psi(\\alpha)>\\log (\\alpha)-1/\\alpha$, we can find a $\\alpha_0$, which satisfies the above equation. \n\n    \\noindent For canonical exponential families, $l'(\\eta)/l(\\eta)=\\sum T(x_i)-nA'(\\eta)$. Then, because $A(\\eta)$ is convex, $A'(\\eta)$ is increasing. And $E(T(X))=A'(\\eta)$, we can also find a unique $\\eta$ which satisfies $A'(\\eta)=\\sum T(x_i)/n$. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\left\\{Y_{n}\\right\\}_{n \\in \\mathbb{N}}\\) be a random sequence defined on a probability space \\((\\Omega, \\mathcal{F}, \\mathbb{P})\\). This sequence is said to be bounded in probability (or tight) if\n    \\[\n        \\forall \\varepsilon>0, \\exists m(\\varepsilon)>0 \\text { such that } \\mathbb{P}\\left(\\left|Y_{n}\\right|>m(\\varepsilon)\\right)<\\varepsilon, \\quad n \\in \\mathbb{N} .\n    \\]\n    Notation: \\(Y_{n}=O_{\\mathbb{P}}(1)\\). \n    \\begin{enumerate}[(a)]\n        \\item Let \\(\\left\\{M\\left(X_{n}\\right)\\right\\}_{n \\in \\mathbb{N}}\\) be an i.i.d. sequence, \\(\\mathbb{E}\\left|M\\left(X_{1}\\right)\\right|<\\infty\\). Prove that\n        \\[\n        Y_{n}:=\\frac{1}{n} \\sum_{i=1}^{n} M\\left(X_{i}\\right)\n        \\]\n        is bounded in probability. \n        \\item Let \\(\\left\\{Y_{n}\\right\\}_{n \\in \\mathbb{N}}\\) and \\(\\left\\{Z_{n}\\right\\}_{n \\in \\mathbb{N}}\\) be random sequences such that \\(Y_{n}=O_{\\mathbb{P}}(1)\\) and \\(Z_{n}=o_{\\mathbb{P}}(1)\\) (i.e., \\(\\left\\{Z_{n}\\right\\}_{n \\in \\mathbb{N}}\\) converges to zero in probability). Prove that \\(Y_{n} Z_{n}=o_{\\mathbb{P}}(1)\\). \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Because $Y_n\\sim \\mathcal{N}(\\mu, \\sigma^2)$. $\\forall\\ \\varepsilon$, we can find a $A$ that satisfies: \n        \\[\n            \\begin{aligned}\n                P(|Y_n|>A)&=P(Y_n>A)+P(Y_n<-A)\\\\\n                &=P\\left(\\frac{A-\\mu}{\\sigma}<Z_n\\right)+P\\left(Z_n<\\frac{-A-\\mu}{\\sigma}\\right)\\\\\n                &=1-\\Phi\\left(\\frac{A-\\mu}{\\sigma}\\right)+\\Phi\\left(\\frac{-A-\\mu}{\\sigma}\\right)<\\varepsilon. \n            \\end{aligned}\n        \\]\n        So, $Y_n$ is bounded in probability. \n        \\item $\\forall\\ \\varepsilon>0$, let $M$ satisfies $P(|Y_n|>M)<\\varepsilon$, \n        \\begin{align*}\n            P(|Y_nZ_n|>\\varepsilon)&=P(|Y_nZ_n|>\\varepsilon, |Y_n|>M)+P(|Y_nZ_n|>\\varepsilon, |Y_n|<M)\\\\\n            &\\leqslant \\varepsilon +P(|Z_n|>\\varepsilon/M)\\\\\n            &\\leqslant \\varepsilon+\\frac{\\varepsilon}{M}=\\varepsilon'. \n        \\end{align*}\n        $\\forall\\ \\varepsilon>0$, $\\exists\\ m(\\varepsilon)=M\\varepsilon/(M+1)$, such that \n        \\[\n            P(|Y_nZ_n|>m(\\varepsilon))<\\varepsilon. \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    (this problem revisits the key steps of the proof of asymptotic efficiency of a consistent sequence of roots)\n\n    For some \\(\\theta, \\theta_{0} \\in \\Theta=(\\underline{\\theta}, \\bar{\\theta})\\) (without loss of generality, \\(\\left.\\theta>\\theta_{0}\\right)\\), if the likelihood function is smooth enough (more specifically, three times differentiable in \\(\\theta\\) over \\(\\Theta\\) ), then we can use the Taylor expansion (with Lagrange residual)\n    \\begin{equation}\n        \\label{eq:7.6}\n        \\ell^{\\prime}(\\hat{\\theta}_n)=\\ell^{\\prime}\\left(\\theta_{0}\\right)+\\left(\\widehat{\\theta}_{n}-\\theta_{0}\\right) \\ell^{\\prime \\prime}\\left(\\theta_{0}\\right)+\\frac{1}{2}\\left(\\widehat{\\theta}_{n}-\\theta_{0}\\right)^{2} \\ell^{\\prime \\prime \\prime}\\left(\\theta^{*}\\right)\n    \\end{equation}\n    where \\(\\theta^{*} \\in\\left(\\theta_{0}, \\theta\\right)\\) and the derivatives are all with respect to \\(\\theta\\). \n    \\begin{enumerate}[(a)]\n        \\item If \\(\\theta\\) is a root of the likelihood equation, conclude that\n        \\[\n            \\sqrt{n}\\left(\\theta-\\theta_{0}\\right)=\\frac{(1 / \\sqrt{n}) \\ell^{\\prime}(\\theta_0)}{-(1 / n) \\ell^{\\prime \\prime}\\left(\\theta_{0}\\right)-(1 / 2 n)\\left(\\theta-\\theta_{0}\\right) \\ell^{\\prime \\prime \\prime}\\left(\\theta^{*}\\right)}. \n        \\]\n        \\item  Prove that\n        \\[\n            \\frac{1}{\\sqrt{n}} \\ell^{\\prime}\\left(\\theta_{0}\\right) \\stackrel{d}{\\rightarrow} \\mathcal{N}\\left(0, I\\left(\\theta_{0}\\right)\\right), \\quad n \\rightarrow \\infty. \n        \\]\n        \\item Prove that\n        \\[\n            -\\frac{1}{n} \\ell^{\\prime \\prime}\\left(\\theta_{0}\\right) \\stackrel{\\mathbb{P}}{\\rightarrow} I\\left(\\theta_{0}\\right), \\quad n \\rightarrow \\infty. \n        \\]\n        \\item In expression (\\ref{eq:7.6}), assume \\(\\theta\\) is replaced by a consistent sequence of roots \\(\\left\\{\\hat{\\theta}_{n}\\right\\}\\). Show that\n        \\[\n        \\frac{1}{n} \\ell^{\\prime \\prime \\prime}\\left(\\theta_{n}^{*}\\right)\n        \\]\n        is bounded in probability. Use this fact and the previous parts to show that the sequence of roots \\(\\left\\{\\widehat{\\theta}_{n}\\right\\}\\) is asymptotically efficient. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Here, $\\ell(\\theta)$ is log-likelihood function. $\\theta$ is root, \n        \\[\n            \\ell^{\\prime}\\left(\\theta_{0}\\right)+\\left(\\theta-\\theta_{0}\\right) \\ell^{\\prime \\prime}\\left(\\theta_{0}\\right)+\\frac{1}{2}\\left(\\theta-\\theta_{0}\\right)^{2} \\ell^{\\prime \\prime \\prime}\\left(\\theta^{*}\\right)=0, \n        \\]\n        \\[\n            \\left(\\theta-\\theta_{0}\\right)=\\frac{\\ell^{\\prime}\\left(\\theta_{0}\\right)}{-\\ell^{\\prime \\prime}\\left(\\theta_{0}\\right)-\\frac{1}{2}\\left(\\theta-\\theta_{0}\\right) \\ell^{\\prime \\prime \\prime}\\left(\\theta^{*}\\right)}, \n        \\]\n        \\[\n            \\sqrt{n}\\left(\\theta-\\theta_{0}\\right)=\\frac{(1/\\sqrt{n})\\ell^{\\prime}\\left(\\theta_{0}\\right)}{-(1/n)\\ell^{\\prime \\prime}\\left(\\theta_{0}\\right)-\\frac{1}{2n}\\left(\\theta-\\theta_{0}\\right) \\ell^{\\prime \\prime \\prime}\\left(\\theta^{*}\\right)}. \n        \\]\n        \\item \\begin{align*}\n            \\frac{1}{\\sqrt{n}} \\ell^{\\prime}\\left(\\theta_{0}\\right) =\\sqrt{n}/n \\sum\\left(\\log'(f(X_i|\\theta_0))\\right)\n        \\end{align*}\n        Noticing that $E(\\log'(f(X_i|\\theta_0)))=0$, $Var(\\log'(f(X_i|\\theta_0)))=I(\\theta_0)$, $E(\\log'(f(X_i|\\theta_0)))\\stackrel{d}{\\to}\\mathcal{N}(0, I(\\theta_0)/n)$. So, \n        \\[\n            \\frac{1}{\\sqrt{n}} \\ell^{\\prime}\\left(\\theta_{0}\\right) =\\sqrt{n}/n \\sum\\left(\\log'(f(X_i|\\theta_0))\\right)\\stackrel{d}{\\to}\\mathcal{N}(0, I(\\theta_0)). \n        \\]\n        \\item \\[\n            -\\frac{1}{n}l''(\\theta_0)=\\frac{1}{n} \\sum\\frac{f'^2(X_i|\\theta_0)-f(X_i|\\theta_0)f''(X_i|\\theta_0)}{f^2(X_i|\\theta_0)}\\stackrel{P}{\\to}I(\\theta_0)+E(\\log''(f(X_i|\\theta_0)))=I(\\theta_0). \n        \\]\n        \\item Because $\\ell'''(X_i, \\theta)<M(X_i)$,  let $M(X)=\\max (M(X_1), \\cdots, M(X_n))$. \\[\n            \\frac{1}{n} \\ell^{\\prime \\prime \\prime}\\left(\\theta_{n}^{*}\\right)=\\frac{1}{n}\\sum \\ell'''(X_i|\\theta)<M(X)\\to E(M(X)). \n        \\]\n        So, $\\frac{1}{n} \\ell^{\\prime \\prime \\prime}\\left(\\theta_{n}^{*}\\right)$ is a bound in probability. \n\n        Finally, $n\\to\\infty$, $\\widehat{\\theta}_n\\to\\theta_0$, \\[\n            \\sqrt{n}(\\widehat{\\theta}_n-\\theta)\\sim\\frac{\\mathcal{N}(0, I(\\theta))}{I(\\theta)}=\\mathcal{N}\\left((0, {\\frac{1}{I(\\theta)}}\\right). \n        \\]\n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    (this problem is about casting new light on a well-known result) \n\n    Consider an i.i.d. sample \\(X_{1}, \\cdots, X_{n}\\) from the location family \\(f(x-\\mu), \\mu \\in \\mathbb{R}\\), where\n    \\[\n        f(x)=\\frac{1}{\\sqrt{2 \\pi} \\sigma_{0}} \\exp \\left\\{-\\frac{1}{2 \\sigma_{0}^{2}} x^{2}\\right\\}\n    \\]\n    and \\(\\sigma_{0}\\) is known. \n    \\begin{enumerate}[(a)]\n        \\item Show that the likelihood equation has a unique root. Is it related to the ML estimator? \n        \\item Conclude that the sequence of roots thus obtained is consistent. \n        \\item Conclude that such sequence is asymptotically efficient. Calculate the asymptotic variance. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item Same as (\\ref{ex:7.2}.\\ref{ex:7.2.a}). It is MLE. \n        \\item $\\mu=\\sum x_i/n$. From LLN, \n        \\[\n            \\delta(X)=\\frac{\\sum_{i=1}^nX_i}{n}\\to\\bar{X}=\\mu. \n        \\]\n        So, it is consistent. \n        \\item \\[\n            \\bar{X}\\sim\\mathcal{N}(\\mu,\\sigma_0^2/n)\\Rightarrow\\sqrt{n}(\\delta-\\mu)\\to \\mathcal{N}\\left(0, \\sigma_0^2\\right). \n        \\]\n        Because $I(\\mu)=1/\\sigma^2$, $\\delta$ is asymptotically efficient. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\cdots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\operatorname{NegBin}(m, p)\\), i.e.,\n    \\[\n        \\mathbb{P}\\left(X_{1}=x\\right)=\\left(\\begin{array}{c}\n        m+x-1 \\\\\n        m-1\n        \\end{array}\\right) p^{m}(1-p)^{x}, \\quad x=0,1,2, \\cdots\n    \\]\n    Find an EL estimator of \\(p\\). \n\\end{ex}\n\n\\begin{solution}\n    Assume $m$ is known. \n    \\[\n        \\ell'(p)=\\frac{nmp^{nm-1}(1-p)^{\\sum x_i}+p^{nm}\\sum x_i(1-p)^{\\sum x_i-1}}{p^{nm}(1-p)^{\\sum x_i}}=\\frac{nm(1-p)+p\\sum x_i}{p(1-p)}.\n    \\]\n    $p\\neq 0$ or $1$, $\\ell'(p)=0$ has the unique root $\\hat{p}=\\frac{nm}{nm-\\sum x_i}$. So, it is also the efficient likelihood estimator. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(X_{1}, \\cdots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\theta, a \\theta^{2}\\right), \\theta>0\\), and \\(a>0\\) is known. Find an explicit expression for an EL estimator of \\(\\theta\\). \n\\end{ex}\n\n\\begin{solution}\n    \\[\n        \\ell(\\theta)=-\\frac{n}{2}\\log\\left(2\\pi a\\theta^2\\right)-\\frac{1}{2a\\theta^2}\\sum(x_i-\\theta)^2.\n    \\]\n    \\[\n        \\ell'(\\theta)=-\\frac{n}{\\theta}+\\frac{\\sum(x_i-\\theta)^2}{a\\theta^3}+\\frac{\\sum(x_i-\\theta)}{a\\theta^2}= 0. \n    \\]\n    \\[\n        \\hat{\\theta}=\\frac{2\\sum x_i}{1\\pm\\sqrt{1+4an}}. \n    \\]\n    Because $\\theta>0$, the root is unique, i.e., $\\hat{\\theta}=\\frac{2\\sum x_i}{1+\\sqrt{1+4an}}$. \n\\end{solution}\n\n\\begin{ex}\n    We now extend the theorem on efficient likelihood (EL) estimators for canonical exponential families to the multiparameter case. \n\n    Let \\(X_{1}, \\cdots, X_{n}\\) be an i.i.d. sample from a multiparameter canonical exponential family. Under assumptions analogous to those for the univariate case, with probability \\(\\rightarrow 1\\) as \\(n \\rightarrow \\infty\\) there exist solutions\n    \\[\n        \\widehat{\\theta}_{n}=\\hat{\\theta}_{n}(\\mathbf{X})\n    \\]\n    of the likelihood equations such that \n    \\begin{enumerate}[(i)]\n        \\item \\(\\hat{\\theta}_{j n} \\stackrel{\\mathbb{P}}{\\rightarrow} \\theta_{j}, n \\rightarrow \\infty\\); \n        \\item \\(\\sqrt{n}\\left(\\widehat{\\theta}_{n}-\\theta\\right) \\stackrel{d}{\\rightarrow} \\mathcal{N}\\left(0, I(\\theta)^{-1}\\right), n \\rightarrow \\infty\\); \n        \\item \\(\\widehat{\\theta}_{j n}\\) is asymptotically efficient in the sense that\n        \\[\n            \\sqrt{n}\\left(\\hat{\\theta}_{j n}-\\theta_{j}\\right) \\stackrel{d}{\\rightarrow} \\mathcal{N}\\left(0,\\left(I(\\theta)^{-1}\\right)_{j j}\\right), \\quad n \\rightarrow \\infty. \n        \\]\n    \\end{enumerate}\n    Here, we define\n    \\[\n        I(\\theta)=\\mathbb{E}_{\\theta}\\left[\\left(\\frac{\\partial}{\\partial \\theta} \\log f(x \\mid \\theta)\\right)\\left(\\frac{\\partial}{\\partial \\theta} \\log f(x \\mid \\theta)\\right)^T\\right]\n    \\]\n    As before, under smoothness we have\n    \\[\n        I(\\theta)=-\\mathbb{E}\\left(\\frac{\\partial^{2}}{\\partial \\theta \\partial \\theta^T} \\log f(x \\mid \\theta)\\right)\n    \\]\n    So, let \\(X_{1}, \\cdots, X_{n}\\) be an i.i.d. sample from a multiparameter canonical exponential family\n    \\[\n        f(x \\mid \\boldsymbol{\\eta})=h(x) \\exp \\{\\langle\\boldsymbol{\\eta}, T(x)\\rangle-A(\\boldsymbol{\\eta})\\}\n    \\]\n    Assume that \\(\\mathcal{E} \\neq \\emptyset, \\mathcal{E} \\subseteq \\mathbb{R}^{k}\\), is open and that identifiability holds. \n    \\begin{enumerate}[(a)]\n        \\item Conclude that, with probability \\(\\rightarrow 1\\) as \\(n \\rightarrow \\infty, \\widehat{\\boldsymbol{\\eta}}_{\\mathrm{ML}}\\) exists and is unique, and find its expression. \n        \\item Conclude that\n        \\[\n            \\sqrt{n}\\left(\\widehat{\\boldsymbol{\\eta}}_{\\mathrm{ML}}-\\boldsymbol{\\eta}\\right) \\stackrel{d}{\\rightarrow} \\mathcal{N}\\left(0, \\frac{1}{Var_{\\boldsymbol{\\eta}}(T)}\\right), \\quad n \\rightarrow \\infty\n        \\]\n        i.e., \\(\\widehat{\\boldsymbol{\\eta}}_{\\mathrm{ML}}\\) is an EL estimator of \\(\\boldsymbol{\\eta}\\).\n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    多参数的情况不写了, 不可能考. \n\\end{solution}\n\n\\begin{ex}\n    An estimator \\(\\delta_{n}(\\mathbf{X})\\) is called \\(\\sqrt{n}\\)-consistent to \\(\\theta\\) if \\(\\sqrt{n}\\left(\\delta_{n}(\\mathbf{X})-\\theta\\right)\\) is bounded in probability. Let \\(\\left\\{X_{n}\\right\\}_{n \\in \\mathbb{N}}\\) be an i.i.d. sequence such that \\(\\mathbb{E} X_{1}^{2}<\\infty\\). Show that \\(\\bar{X}_{n}\\) is \\(\\sqrt{n}\\)-consistent to \\(\\mu:=\\mathbb{E} X_{1}\\). \n    \n    (hint: Prohorov's theorem ensures that boundedness in probability is equivalent to the existence of a subsequence that converges weakly). \n\\end{ex}\n\n\\begin{solution}\n    这题和上面那个有啥区别吗? \n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\tilde{\\theta}_{n}(\\mathbf{X})\\) be a \\(\\sqrt{n}\\)-consistent estimator of \\(\\theta\\) under the log-likelihood \\(\\ell(\\theta \\mid \\mathbf{X})\\). Under the conditions of the asymptotic normality theorem for EL estimators, it can be shown that the estimator\n    \\begin{equation}\n        \\label{eq:7.12}\n        \\delta_{n}(\\mathbf{X}):=\\tilde{\\theta}_{n}(\\mathbf{X})-\\frac{\\ell^{\\prime}\\left(\\tilde{\\theta}_{n}(\\mathbf{X})\\right)}{\\ell^{\\prime \\prime}\\left(\\tilde{\\theta}_{n}(\\mathbf{X})\\right)}\n    \\end{equation}\n    is also asymptotically efficient (Theorem 6.4.3 in Lehmann and Casella (1998)).\n    Let \\(\\{f(x-\\theta)\\}_{\\theta \\in \\Theta}\\) be a location family based on the symmetric (around zero) and a.c. density \\(f\\) with finite second moments. Assume that the likelihood equation\n    \\[\n    \\frac{\\partial}{\\partial \\theta} \\log f(\\mathbf{x} \\mid \\theta)=0\n    \\]\n    has potentially multiple roots. Use (\\ref{eq:7.12}) to find an asymptotically efficient estimator for \\(\\theta\\) \n\n    (hint: look at the previous problem). \n\n    \\rmk{3} It is clear that the expression (0.3) stems from one step of Newton-Raphson's method.\n\\end{ex}\n\n\\begin{solution}\n    We know that $\\sqrt{n}(\\bar{X}-\\theta)$ is bounded in probability, so we can use Theorem 6.4.3 to find an asymptotically efficient estimator for $\\theta$: \n    \\[\n        \\delta_n(X)=\\bar{X}-\\frac{\\ell'(\\bar{X})}{\\ell''(\\bar{X})}. \n    \\]\n    吐了, 这题到底在干啥. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\left\\{X_{n}\\right\\}_{n \\in \\mathbb{N}} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right), \\mu \\in \\mathbb{R}, \\sigma^{2}>0\\), and let \\(h(x)=x^{2}\\). \n    \\begin{enumerate}[(a)]\n        \\item Construct asymptotic approximations to \\(\\mathbb{E}_{\\theta} h(\\bar{X})\\) and \\(Var_{\\theta} h(\\bar{X})\\). \n        \\item Based on the properties of Gaussian distributions, compute \\(\\mathbb{E}_{\\theta} h(\\bar{X})\\) and \\(Var_{\\theta} h(\\bar{X})\\) explicitly and compare the expressions with the approximations obtained in (a). Do the approximations orders match? \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item $\\hat{x}_{ML}=\\bar{X}$. From Delta method, take $T(X)=\\bar{X}$, $h(x)=x^2$.\n        \\[\n            n(\\bar{X}^2-\\mu^2)\\stackrel{d}{\\to}1/2 \\sigma^2 2 \\chi_1^2=\\sigma^2\\chi_1^2. \n        \\]\n        $E(\\bar{X}^2): \\mu^2+\\sigma^2/n$, $Var(\\bar{X}^2): \\frac{2\\sigma^4}{n^2}$. \n        \\item $\\bar{X}\\sim \\mathcal{N}(\\mu,\\sigma^2/n)$. \n        \\[\n            E(\\bar{X}^2)=\\sigma^2/n+\\mu^2, \\quad Var(\\bar{X}^2)=\\mu^4+6\\mu^2\\sigma^2/n+3\\sigma^4/n^2.\n        \\]\n        The order is match. \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    Consider the following setup. \n    \\begin{itemize}\n        \\item \\(\\left\\{X_{n}\\right\\}_{n \\in \\mathbb{N}}\\) : i.i.d. sequence, \\(X_{1} \\sim \\mathcal{P}=\\left\\{\\mathbb{P}_{\\theta}\\right\\}_{\\theta \\in \\Theta}\\); \n        \\item \\(\\mathbb{E}_{\\theta} X_{1}=\\mu, Var_{\\theta} X_{1}=\\sigma^{2}>0, \\mathbb{E}_{\\theta} X_{1}^{4}<\\infty\\); \n        \\item \\(h: I \\rightarrow \\mathbb{R}\\) is a 4-times differentiable function, where \\(\\mathbb{P}_{\\theta}\\left(X_{1} \\in I\\right)=1, \\theta \\in \\Theta\\); \n        \\item \\(\\left|h^{(i v)}(x)\\right| \\leq M<\\infty, x \\in I\\); \n        \\item \\(c_{n}=1+\\frac{a}{n}+O\\left(\\frac{1}{n^{2}}\\right), n \\in \\mathbb{N}, a \\in \\mathbb{R}\\). \n    \\end{itemize}\n    Consider the estimator \\(\\delta_{n}(\\bar{X})=h\\left(c_{n} \\bar{X}\\right)\\). Show that\n    \\[\n        Var_{\\theta} \\delta_{n}(\\bar{X})=\\frac{\\sigma^{2}}{n}\\left[h^{\\prime}(\\mu)\\right]^{2}+O\\left(\\frac{1}{n^{2}}\\right) .\n    \\]\n\\end{ex}\n\n\\begin{solution}\n    6.2.a. \n\\end{solution}\n\n\\begin{ex}\n    Let \\(\\left\\{X_{n}\\right\\}_{n \\in \\mathbb{N}} \\stackrel{\\text { i.i.d. }}{\\sim} \\mathcal{N}\\left(\\mu, \\sigma^{2}\\right), \\mu \\in \\mathbb{R}, \\sigma^{2}>0\\), and let \\(h(x)=e^{x^{4}}\\). It is clear that all moments of \\(X\\) and all derivatives of \\(h\\) exist. \n    \\begin{enumerate}[(a)]\n        \\item Show that \\(\\mathbb{E}\\left|h\\left(\\bar{X}_{n}\\right)\\right|=\\infty, n \\in \\mathbb{N}\\). Conclude that\n        \\[\n            \\mathbb{E}_{\\theta} \\sqrt{n}\\left[h\\left(\\bar{X}_{n}\\right)-h(\\mu)\\right]^{2}=\\infty, \\quad n \\in \\mathbb{N} .\n        \\]\n        \\item By contrast, assuming \\(\\mu \\neq 0\\), show that \\(\\sqrt{n}\\left[h\\left(\\bar{X}_{n}\\right)-h(\\mu)\\right]\\) has a normal limit distribution with finite variance. \n        \\item Conclude that the theorem seen in class on the approximation of moments does require bounded derivatives. \n    \\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n    \\begin{enumerate}[(a)]\n        \\item \\[\n            E\\left(e^{x^4}\\right)=\\int A\\exp\\left(B(x-\\mu)^2+x^4\\right)\\der x\n        \\]\n        $x\\to\\infty$, $A\\exp\\left(B(x-\\mu)^2+x^4\\right)\\to\\infty$. So, $E\\left(e^{x^4}\\right)\\to\\infty$. Samilarly, \n        \\[\n            E(e^{2x^4})=\\infty. \n        \\]\n        So, $E(\\sqrt{n}(h(\\bar{X}_n)-h(\\mu))^2)=\\infty$. \n        \\item $Var(\\bar{X})=\\sigma^2/n<\\infty$. From Delta method, it has a normal limit distribution with finite variance. \n        \\item \n    \\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n    The Hardy-Weinberg principle from population genetics describes an idealized situation where there are no evolutionary influences. \n    \n    Assume that two alleles \\(A\\) and \\(a\\) appear in a population's gene pool with frequencies \\(\\theta\\) and \\(1-\\theta, 0<\\theta<1\\), respectively. The principle states that, in equilibrium, the frequencies of the genotypes \\(A A, A a\\) and \\(a a\\) will remain constant from generation to generation at\n    \\[\n    p_{1}(\\theta)=\\theta^{2}, \\quad p_{2}(\\theta)=2 \\theta(1-\\theta), \\quad p_{3}(\\theta)=(1-\\theta)^{2},\n    \\]\n    respectively.\n    \n    Assume that a sample \\(\\mathbf{X}=\\left(X_{1}, X_{2}, X_{3}\\right)\\) is drawn. If the population is very large, then we can suppose that the sampling was done with replacement, whence\n    \\[\n    \\mathbb{P}(\\mathbf{X}=\\mathbf{x} \\mid \\theta)=\\frac{n !}{x_{1} ! x_{2} ! x_{3} !} p_{1}(\\theta)^{x_{1}} p_{2}(\\theta)^{x_{2}} p_{3}(\\theta)^{x_{3}}, \\quad \\sum_{i=1}^{3} x_{i}=n .\n    \\]\n    What is the probability that \\(\\widehat{\\theta}_{\\mathrm{ML}}\\) exists, and how does it behave as \\(n \\rightarrow \\infty\\) ?\n\\end{ex}\n\n\n\n", "meta": {"hexsha": "b5433f56b3b92ccbf8fabb19b264cfb951fcb8eb", "size": 25333, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/Set7.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/Set7.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/Set7.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.5580912863, "max_line_length": 393, "alphanum_fraction": 0.5791260411, "num_tokens": 9265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6016635340517341}}
{"text": "\\documentclass[11pt]{amsart}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{tikz}\n\\usepackage{pgfplots}\n\\usepackage{xcolor}\n\n\\DeclareMathOperator\\erf{erf}\n\n\\newcommand{\\airgrid}{\\mathrm{air-grid}}\n\\newcommand{\\app}{a}\n\\newcommand{\\cutin}{\\mathrm{cut-in}}\n\\newcommand{\\cutout}{\\mathrm{cut-out}}\n\\newcommand{\\extra}{\\mathrm{extra}}\n\\newcommand{\\grav}{\\mathrm{grav}}\n\\newcommand{\\groundinverter}{\\mathrm{ground\\;inv.}}\n\\newcommand{\\kiteinverter}{\\mathrm{kite\\;inv.}}\n\\newcommand{\\kite}{k}\n\\newcommand{\\lp}{\\mathrm{loop}}\n%\\newcommand{\\max}{\\mathrm{max}}\n\\newcommand{\\motor}{\\mathrm{motor}}\n\\newcommand{\\path}{\\mathrm{path}}\n\\newcommand{\\prop}{\\mathrm{prop}}\n\\newcommand{\\swept}{\\mathrm{swept}}\n\\newcommand{\\sys}{\\mathrm{sys}}\n\\newcommand{\\tether}{\\mathrm{tether}}\n\\newcommand{\\wind}{w}\n\n\\definecolor{matlab1}{rgb}{0, 0.4470, 0.7410}\n\\definecolor{matlab2}{rgb}{0.8500, 0.3250, 0.0980}\n\\definecolor{matlab3}{rgb}{0.9290, 0.6940, 0.1250}\n\\definecolor{matlab4}{rgb}{0.4940, 0.1840, 0.5560}\n\\definecolor{matlab5}{rgb}{0.4660, 0.6740, 0.1880}\n\\definecolor{matlab6}{rgb}{0.3010, 0.7450, 0.9330}\n\\definecolor{matlab7}{rgb}{0.6350, 0.0780, 0.1840}\n\n\\title{Crosswind kite power curve}\n\\author{Makani Technologies LLC}\n\\date{June 28, 2016}\n\n\\begin{document}\n\\maketitle\n\n\\section{Fundamentals}\n\\label{sec:fundamentals}\n\nTraditional wind turbines use the power coefficient, $C_P$, as a\ncritical performance metric:\n%\n\\begin{equation}\nC_P = \\frac{P}{\\frac{1}{2} \\rho v_{\\wind}^3 A_{\\swept}}\n\\end{equation}\n%\nThis is the value that is optimized in the celebrated Betz limit,\nwhich says that the maximum achievable power coefficient is $C_P \\approx 0.593$.\nNotably the power coefficient is referenced to the {\\it swept area} of\nthe wind turbine blades, which is reasonable given the limited swept\narea available to a traditional wind turbine.\n\nFor kite based systems, where system cost is correlated with kite size\nrather than the vast swept area, it makes sense to reference the power\ncoefficient to {\\it kite area}.  This value is referred to as $\\zeta$:\n%\n\\begin{equation}\n\\label{eqn:zeta}\n\\zeta = \\frac{P}{\\frac{1}{2} \\rho v_{\\wind}^3 A_{\\kite}}\n\\end{equation}\n\nHowever, optimizing a system for the maximum $C_P$ or $\\zeta$ is not\nthe same as optimizing for cost!  In fact, optimizing a system for\nmaximum $\\zeta$ actually increases the maximum tension, a substantial\ncost driver, over a Betz limited system by a factor of two.  To\ndescribe how efficiently a system converts tension into power, it is\nuseful to introduce another dimensionless variable, the tension\nefficiency, $\\eta_T$:\n%\n\\begin{equation}\n\\label{eqn:eta_T}\n\\eta_T = \\frac{P}{T v_{\\wind}}\n\\end{equation}\n%\nAccording to actuator disk theory, for a Betz limited system, the wind\nvelocity at the disk, where it may be assumed the force is applied, is\n$\\frac{2}{3} v_{\\wind}$.  Thus, the tension efficiency for a Betz\nlimited system is $\\eta_T = \\frac{2}{3}$.\n\nTo calculate the corresponding tension efficiency for a kite power\nsystem that attempts to maximize $\\zeta$, i.e. a Loyd limited system,\nit is first necessary to relate $\\zeta$ to physical properties of the\nkite.  Ignoring power efficiency losses and the typically low\ninduction factors of kite propellers, the power generated by the kite\nis approximately, $P = D_{\\prop} v_{\\kite}$, where $D_{\\prop}$ is the\ndrag on all the propellers and $v_{\\kite}$ is the airspeed of the\nkite.  Substituting this into Eq. \\ref{eqn:zeta}, it is found that\n%\n\\begin{equation}\n\\label{eqn:zeta_prop}\n\\zeta = C_{D_{\\prop}} \\left(\\frac{v_{\\kite}}{v_{\\wind}} \\right)^3\n\\end{equation}\n\nThe kite-to-wind speed ratio, which figures prominently in\nEq. \\ref{eqn:zeta_prop}, may be related to the lift and drag\ncoefficients of the kite through simple force balance.  Specifically,\nthe airspeed of a kite traveling perpendicular to the wind is given\nby:\n%\n\\begin{equation}\n\\label{eqn:kite_speed}\nv_{\\kite} = \\sqrt{1 + \\left(\\frac{C_L}{C_D}\\right)^2} v_{\\wind}\n          \\approx \\frac{C_L}{C_D} v_{\\wind}\n\\end{equation}\n%\nHere the drag coefficient, $C_D$, may be divided into two components:\nsystem drag, $C_{D_{\\sys}}$, and propeller drag, $C_{D_{\\prop}}$.  The\nsystem drag coefficient includes parasitic drag, induced drag, and\ntether drag, and to a large degree is fixed during flight.  The\npropeller drag coefficient, however, may be tuned over a wide range.\n\nTo optimize propeller drag for various metrics, e.g. $\\zeta$ or\n$\\eta_T$, it is useful to express the tunable propeller drag\ncoefficient as a fraction, $k$, of the fixed system drag coefficient:\n$C_{D_{\\prop}} = k C_{D_{\\sys}}$.  Now, the kite-to-wind speed ratio,\n$\\lambda$, from Eq. \\ref{eqn:kite_speed} is\n%\n\\begin{equation}\n\\label{eqn:lambda}\n\\lambda = \\frac{v_{\\kite}}{v_{\\wind}} = \\frac{C_L}{C_{D_{\\sys}}} \\frac{1}{1 + k}\n\\end{equation}\n%\nThus, $\\zeta$ from Eq. \\ref{eqn:zeta_prop} is\n%\n\\begin{equation}\n\\zeta = \\frac{C_L^3}{C_{D_{\\sys}}^2} \\frac{k}{(1+k)^3}\n\\end{equation}\n%\nAnd finally, using the approximation for tension,\n$T = \\frac{1}{2} \\rho v_{\\kite}^2 A_{\\kite} C_L$, the tension efficiency, $\\eta_T$,\nfrom Eq. \\ref{eqn:eta_T}, is\n%\n\\begin{equation}\n\\eta_T = \\frac{k}{1 + k}\n\\end{equation}\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}\n\\begin{axis}[axis lines=middle, samples=200,\n    grid=both,\n    grid style={line width=1pt, draw=gray!10},\n    x label style={at={(axis description cs:0.5,-0.1)}, anchor=north},\n    y label style={at={(axis description cs:-0.1,.5)}, rotate=90, anchor=south},\n    xlabel={Propeller drag fraction, $k$ [\\#]},\n    ylabel={Metric [\\#]},\n    legend pos=south east]\n\\addplot[matlab1, domain=0:2] {1 / (1 + x)};\n\\addplot[matlab2, domain=0:2] {x / (1 + x)^3 / (4/27)};\n\\addplot[matlab3, domain=0:2] {x / (1 + x)};\n\\legend{$\\lambda / \\lambda_0$, $\\zeta / \\zeta_{\\max}$, $\\eta_T$};\n\\end{axis}\n\\end{tikzpicture}\n\\caption{Kite performance metrics as a function of the propeller drag\n  fraction.}\n\\end{center}\n\\end{figure}\n\nThere are many interesting things to note from the three dimensionless\nperformance metrics described above ($\\lambda$, $\\zeta$, and $\\eta_T$):\n\\begin{itemize}\n\\item The kite speed is proportional to the system's\n  lift-to-drag ratio, as expected, and this is tunable with the\n  propeller drag.\n\n\\item The $C_L^3$ in the $\\zeta$ metric really encourages high lift\n  coefficients.  This effect is even more dramatic considering the\n  high drag penalty imposed by the tether, which makes the increase in\n  induced drag with $C_L^2$ less important when compared to other\n  systems that optimize for the endurance metric.\n\n\\item Maximizing $\\zeta$ requires setting the propeller drag to half\n  the system drag, $k = \\frac{1}{2}$.  From Eq. \\ref{eqn:lambda}, this\n  is equivalent to saying that the kite should fly at $\\frac{2}{3}$ of\n  its zero-propeller-drag speed.\n\n\\item The tension efficiency is independent of any system parameter\n  save the propeller drag fraction.\n\n\\item Finally, optimizing for $\\zeta$ results in a tension efficiency\n  of $\\eta_T = \\frac{1}{3}$.  Thus, maximizing $\\zeta$ results in half\n  the tension efficiency of a Betz limited system.  Of course, it is\n  not necessary to fly a system at maximum $\\zeta$; and if $k$ is\n  increased to 2, the system will achieve the same tension efficiency\n  as a Betz limited device, but $\\zeta$ will drop by a factor of 2.\n\\end{itemize}\n\n\n\\section{Ideal power curve}\n\n\\begin{figure}[h]\n\\label{fig:power_curve}\n\\begin{center}\n\\begin{tikzpicture}\n  \\def\\CL{2.1};\n  \\def\\CDsys{0.18};\n  \\def\\costheta{1};\n  \\def\\etaairgrid{1};\n  \\def\\Tmax{150};  % [kN]\n  \\def\\Pmax{600};  % [kW]\n  \\def\\zetamax{(4/27 * \\CL^3 / \\CDsys^2)};\n  \\def\\Ak{32.9};\n  \\def\\rho{1.2};\n  \\def\\vkitemin{30};\n  \\def\\P0{(0.5 * \\rho * \\Ak * \\CDsys * \\vkitemin^3 / 1000)};\n  \\def\\vcutin{(\\CDsys / \\CL * \\vkitemin / \\costheta)};\n  \\def\\vT{((\\Tmax * 1000 / 3 / (0.5 * \\rho * \\Ak * \\zetamax))^0.5 / \\costheta)};\n  \\def\\vP{(\\Pmax / (\\etaairgrid * \\Tmax * \\costheta) + 2 * \\vT / 3)};\n  \\def\\loydcoeff{(\\etaairgrid * \\costheta^3 * 0.5 * \\rho * \\Ak * \\zetamax / 1000)};\n\n\\begin{axis}[axis lines=middle, samples=200,\n    grid=both,\n    grid style={line width=1pt, draw=gray!10},\n    x label style={at={(axis description cs:0.5,-0.1)}, anchor=north},\n    y label style={at={(axis description cs:-0.1,.5)}, rotate=90, anchor=south},\n    xlabel={Wind speed [m/s]},\n    ylabel={Power [kW]},\n    legend pos=north west]\n  \\addplot[matlab1, domain=0:(\\vcutin)] {0};\n  \\addplot[matlab2, domain=(\\vcutin):(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1)};\n  \\addplot[matlab3, domain=(1.5 * \\vcutin):(\\vT)] {\\loydcoeff * x^3};\n  \\addplot[matlab4, domain=(\\vT):(\\vP)] {\\etaairgrid * \\costheta * \\Tmax * (x - 2 * \\vT / 3)};\n  \\addplot[matlab5, domain=(\\vP):(\\vP + 2)] {\\Pmax};\n  \\legend{$v_{\\wind,\\cutin}$, $v_{\\kite,\\min}$, $\\zeta_{\\max}$, $T_{\\max}$, $P_{\\max}$};\n\n  \\addplot[matlab3, dashed, domain=2:(1.5 * \\vcutin)] {\\loydcoeff * x^3};\n  \\addplot[matlab3, dashed, domain=(\\vT):(\\vT + 2)] {\\loydcoeff * x^3};\n  \\addplot[matlab2, dashed, domain=2:(\\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1)};\n\n  \\draw[gray, dashed] (axis cs:{\\vcutin}, 50) -- (axis cs:{\\vcutin}, 150)\n  node [above, black] {$v_{\\wind,\\cutin}$};\n  \\draw[gray, dashed] (axis cs:{1.5 * \\vcutin}, 100) -- (axis cs:{1.5 * \\vcutin}, 250)\n  node [above, black] {$v_{\\wind,v_{\\kite}}$};\n  \\draw[gray, dashed] (axis cs:{\\vT}, {\\loydcoeff * \\vT^3 - 50}) -- (axis cs:{\\vT}, {\\loydcoeff * \\vT^3 / 2})\n  node [below, black] {$v_{\\wind,T}$};\n  \\draw[gray, dashed] (axis cs:{\\vP}, 550) -- (axis cs:{\\vP}, 450)\n  node [below, black] {$v_{\\wind,P}$};\n\n\\end{axis}\n\\end{tikzpicture}\n\\caption{Representative ideal power curve showing the\n  airspeed-limited, Loyd-limited, tension-limited, and power-limited\n  segments.  This particular power curve assumes: $A_{\\kite} = 32.9$\n  m$^2$, $v_{\\kite,\\min} = 30$ m/s, $\\zeta_{\\max} = 42.3$, $T_{\\max} = 150$\n  kN, $P_0 = 96$ kW, and $P_{\\max} = 600$ kW.}\n\\end{center}\n\\end{figure}\n\n%% \\begin{figure}\n%% \\label{fig:power_curve}\n%% \\begin{center}\n%% \\begin{tikzpicture}\n%% \\begin{axis}[axis lines=middle, samples=200,\n%%     grid=both,\n%%     grid style={line width=1pt, draw=gray!10},\n%%     x label style={at={(axis description cs:0.5,-0.1)}, anchor=north},\n%%     y label style={at={(axis description cs:-0.1,.5)}, rotate=90, anchor=south},\n%%     xlabel={Wind speed [m/s]},\n%%     ylabel={Power [kW]},\n%%     legend pos=north west]\n%%   \\addplot[matlab1, domain=0:3.43] {0};\n%%   \\addplot[matlab2, domain=3.43:5.14] {127.9 * (x / 3.43 - 1)};\n%%   \\addplot[matlab3, domain=5.14:8.42] {0.4702 * x*x*x};\n%%   \\addplot[matlab4, domain=8.42:11.61] {100 * (x - 5.61)};\n%%   \\addplot[matlab5, domain=11.61:15] {600};\n%%   \\legend{$v_{\\wind,\\cutin}$, $v_{\\kite,\\min}$, $\\zeta_{\\max}$, $T_{\\max}$, $P_{\\max}$};\n\n%%   \\addplot[matlab3, dashed, domain=2:5.14] {0.4702 * x*x*x};\n%%   \\addplot[matlab3, dashed, domain=7.96:11.61] {0.4702 * x*x*x};\n%%   \\addplot[matlab2, dashed, domain=2:3.42] {127.9 * (x / 3.43 - 1)};\n\n%%   \\draw[gray, dashed] (axis cs:3.43, 50) -- (axis cs:3.43, 150)\n%%   node [above, black] {$v_{\\wind,\\cutin}$};\n%%   \\draw[gray, dashed] (axis cs:5.14, 100) -- (axis cs:5.14, 250)\n%%   node [above, black] {$v_{\\wind,v_{\\kite}}$};\n%%   \\draw[gray, dashed] (axis cs:8.42, 250) -- (axis cs:8.42, 150)\n%%   node [below, black] {$v_{\\wind,T}$};\n%%   \\draw[gray, dashed] (axis cs:11.61, 550) -- (axis cs:11.61, 450)\n%%   node [below, black] {$v_{\\wind,P}$};\n%% \\end{axis}\n%% \\end{tikzpicture}\n%% \\caption{Representative ideal power curve showing the\n%%   airspeed-limited, Loyd-limited, tension-limited, and power-limited\n%%   segments.  This particular power curve assumes: $A_{\\kite} = 32.9$\n%%   m$^2$, $v_{\\kite,\\min} = 30$ m/s, $\\zeta_{\\max} = 23.8$, $T_{\\max} = 100$\n%%   kN, $P_0 = 127.9$ kW, and $P_{\\max} = 600$ kW.}\n%% \\end{center}\n%% \\end{figure}\n\nFigure \\ref{fig:power_curve} shows the general form of a crosswind\nkite power curve.  Below the cut-in wind speed, $v_{\\wind,\\cutin}$,\nthe system generates no power, or negative power if it is necessary to\nkeep the kite flying.  Then, there is a small range of low wind speeds\nwhere the system is limited by the requirement to maintain some\nminimum airspeed, $v_{\\kite,\\min}$.  Next, the curve is Loyd-limited,\nor only limited by the maximum achievable $\\zeta$.  Here the kite is\ntrying to extract as much power as possible from the wind regardless\nof tension.  At some wind speed, $v_{\\wind,T}$, however, it becomes\nimportant to limit the tension.  Here, the propeller drag fraction is\nincreased from the Loyd optimal of $k = \\frac{1}{2}$ to the maximum\nvalue available for the system or until the system's power limit is\nreached.  This curve clearly lies below the Loyd-limited curve.  The\nfinal section above $v_{\\wind,P}$ is the power limited section.  Power\nmay be dumped either by further increasing $k$ and slowing the wing\ndown or by shifting the flight path off from downwind.\n\nIt is possible to describe the power curve from\nFig. \\ref{fig:power_curve} in terms of the fundamental limitations of\nthe system: $v_{\\kite,\\min}$, $\\zeta_{\\max}$, $T_{\\max}$, and either\n$k_{\\max}$ or $P_{\\max}$ depending on whether the power limit is set\nby the propellers or the electrical power system.  In the following,\nthe functional form of the power curve in each of the sections is\nderived.\n\nThe cut-in wind speed is the wind speed at which the kite maintains\nsome minimum airspeed, $v_{\\kite,\\min}$, while using zero thrust,\ni.e. $k=0$.\n%\n\\begin{equation}\nv_{\\wind,\\cutin} = \\frac{C_{D_{\\sys}}}{C_L} v_{\\kite,\\min}\n\\end{equation}\n%\nBelow the cut-in wind speed, it generally makes sense to land the\nkite.  However, if it is necessary that the kite keep flying, then $k$\nmust be chosen to satisfy the minimum airspeed requirement.  It turns\nout that the minimum airspeed requirement also constrains the power\ncurve slightly above $v_{\\wind,\\cutin}$ up to the airspeed-limit wind\nspeed threshold, $v_{\\wind,v_{\\kite}} = \\frac{3}{2} v_{\\wind,\\cutin}$.\n%\n\\begin{equation}\nk = \\frac{C_L}{C_{D_{\\sys}}} \\frac{v_{\\wind}}{v_{\\kite,\\min}} - 1,\\;\\;\\;\\;\nv_{\\wind} < v_{\\wind,v_{\\kite}}\n\\end{equation}\n%\nThus, the power curve in the airspeed-limited section is\n%\n\\begin{equation}\nP(v_{\\wind}) = P_0 \\left( \\frac{v_{\\wind}}{v_{\\wind,\\cutin}} - 1 \\right),\\;\\;\\;\\;\nv_{\\wind} < v_{\\wind,v_{\\kite}}\n\\end{equation}\n%\nwhere $P_0 = \\frac{1}{2} \\rho v_{\\kite,\\min}^3 A_{\\kite} C_{D_{\\sys}}$\nis the power necessary to keep the kite flying at its minimum airspeed\nwithout wind.\n\nThe Loyd-limited section is simple and follows the expected\n$v_{\\wind}^3$ function.  The propeller drag is held at the optimal\n$k=\\frac{1}{2}$ value and thus the power curve is:\n%\n\\begin{equation}\nP(v_{\\wind}) = \\frac{1}{2} \\rho v_{\\wind}^3 A_{\\kite} \\zeta_{\\max},\\;\\;\\;\\;\nv_{\\wind,v_{\\kite}} < v_{\\wind} < v_{\\wind,T}\n\\end{equation}\n%\nwhere $v_{\\wind,T}$ is the tension-limit wind speed threshold to be\nderived below.\n\nThe next section is the tension-limited section.  Recall that here the\npower curve is shifted down by slowing the kite down by increasing the\npropeller drag.  To determine the appropriate propeller drag fraction\nthat meets the tension requirement, combine equations \\ref{eqn:zeta}\nand \\ref{eqn:eta_T}, substituting $T_{\\max}$ for tension:\n%\n\\begin{equation}\n\\frac{1}{2} \\rho v_{\\wind}^3 A_{\\kite} \\frac{C_L^3}{C_{D_{\\sys}}^2} \\frac{k}{(1 + k)^3}\n= T_{\\max} v_{\\wind} \\frac{k}{1 + k}\n\\end{equation}\n%\nand solve for $k$:\n%\n\\begin{equation}\nk = \\frac{3}{2} \\sqrt{\\frac{\\frac{1}{2} \\rho A_{\\kite} \\zeta_{\\max}}{T_{\\max} / 3}} \\cdot v_{\\wind} - 1\n\\end{equation}\n%\nThe tension limited section begins when $k > \\frac{1}{2}$.  Thus, the\nthreshold wind speed, $v_{\\wind,T}$, for the tension limited section,\nexpressed in terms of limits of the system, is:\n%\n\\begin{equation}\nv_{\\wind,T} = \\sqrt{\\frac{T_{\\max} / 3}{\\frac{1}{2} \\rho A_{\\kite} \\zeta_{\\max}}}\n\\end{equation}\n%\nFrom this it is also possible to derive an extremely simple form for\nthe maximum power in the tension limited section as a function of wind\nspeed:\n%\n\\begin{equation}\nP(v_{\\wind}) = T_{\\max} \\left( v_{\\wind} - \\frac{2}{3} v_{\\wind,T} \\right),\\;\\;\\;\\;\nv_{\\wind,T} < v_{\\wind} < v_{\\wind,P}\n\\end{equation}\n\nThe start of the power limited section may either be set by the\nfundamental limitations of the electrical power system, $P_{\\max}$, or\nby the maximum drag fraction, $k_{\\max}$, achievable with the\npropellers.  In a balanced system, these limits should be consistent\nwith each other, but it is useful to derive the form of the power\ncurve for each case.  In the power system limited case, the threshold\nwind speed, $v_{\\wind,P}$, for the power limited section is:\n%\n\\begin{equation}\nv_{\\wind,P} = \\frac{P_{\\max}}{T_{\\max}} + \\frac{2}{3} v_{\\wind,T}\n\\end{equation}\n%\nIn the propeller drag limited case, there is essentially a maximum\ntension efficiency, which can be used to convert the tension limit to\na power limit.  Thus,\n%\n\\begin{equation}\nv_{\\wind,P} = \\frac{2}{3} (1 + k_{\\max}) v_{\\wind,T}\n\\end{equation}\n%\nand the maximum power, $P_{\\max}$, is\n%\n\\begin{equation}\nP_{\\max} = \\frac{2 (T_{\\max} / 3)^{3/2} k_{\\max}}{ \\sqrt{\\frac{1}{2} \\rho A \\zeta_{\\max}}}\n\\end{equation}\n\nPutting this all together in one place, the power curve is defined by:\n%\n\\begin{equation}\nP(v_{\\wind}) =\n\\begin{cases}\n  0 &\n  v_{\\wind} \\le v_{\\wind,\\cutin} \\\\\n\n  P_0 \\left(\\frac{v_{\\wind}}{v_{\\wind,\\cutin}} - 1 \\right) &\n  v_{\\wind,\\cutin} < v_{\\wind} \\le \\frac{3}{2} v_{\\wind,\\cutin} \\\\\n\n  \\frac{1}{2} \\rho v_{\\wind}^3 A_{\\kite} \\zeta_{\\max} &\n  \\frac{3}{2} v_{\\wind,\\cutin} < v_{\\wind} \\le v_{\\wind,T} \\\\\n\n  T_{\\max} \\left( v_{\\wind} - \\frac{2}{3} v_{\\wind,T} \\right) &\n  v_{\\wind,T} < v_{\\wind} \\le v_{\\wind,P} \\\\\n\n  P_{\\max} &\n  v_{\\wind,P} < v_{\\wind} \\le v_{\\wind,\\cutout} \\\\\n\n  0 &\n  v_{\\wind} > v_{\\wind,\\cutout}\n\\end{cases}\n\\end{equation}\n\n\n\\section{Efficiency losses}\n\n\\subsection{Air-to-grid losses}\n\nThe simplified analysis in Sec. \\ref{sec:fundamentals} assumes that\nthe power generated is equal to propeller drag times airspeed,\n$P = D_{\\prop} v_{\\kite}$; however this does not take into account the\nefficiency of the propellers in converting aerodynamic power into\nmechanical shaft power.  Moreover, the shaft power from the propellers\ngoes through multiple conversions, from mechanical to electrical and\nbetween AC and DC, and is transmitted down the tether.  Each of the\nconversions and transmissions has an associated power loss and\nefficiency.  The total efficiency between the aerodynamic forces on\nthe kite and the electrical power at the grid, $\\eta_{\\airgrid}$, is\ngiven by:\n%\n\\begin{equation}\n  \\label{eqn:total_efficiency}\n  \\eta_{\\airgrid} = \\eta_{\\prop} \\cdot \\eta_{\\motor} \\cdot \\eta_{\\kiteinverter}\n  \\cdot \\eta_{\\tether} \\cdot \\eta_{\\groundinverter}\n\\end{equation}\n\nThe efficiency loss for the tether is simply the power loss from\nresistive heating in the tether $i^2 R_{\\tether}$:\n%\n\\begin{equation}\n  \\label{eqn:tether_efficiency}\n  \\eta_{\\tether} = 1 - \\frac{P_{\\kite} R_{\\tether}}{V_{\\kite}^2}\n\\end{equation}\n\n\\begin{table}[h]\n\\begin{tabular}{lcl}\n\\hline\n\\hline\nEfficiency               & Typical value & Source \\\\\n\\hline\n$\\eta_{\\prop}$           & 0.81          & \\textsc{xrotor}, Rev. 2 props \\\\\n$\\eta_{\\motor}$          & 0.95          & YASA engineering report \\\\\n$\\eta_{\\kiteinverter}$   & 0.96          & Dyno measurements \\\\\n$\\eta_{\\tether}$         & 0.95          & Eq. \\ref{eqn:tether_efficiency} \\\\\n$\\eta_{\\groundinverter}$ & 0.96          & Satcon datasheet \\\\\n\\hline\n$\\eta_{\\airgrid}$        & 0.67          & Eq. \\ref{eqn:total_efficiency} \\\\\n\\hline\n\\hline\n\\end{tabular}\n\\caption{Total efficiency stack-up.}\n\\end{table}\n\n\\subsection{Off-downwind losses}\n\nThe simplified analysis in Sec. \\ref{sec:fundamentals} also assumes\nthat the flight path of the kite is normal to the direction of the\nwind.  To modify this analysis to account for a flight path that is\ncentered at some elevation and azimuth angle off downwind, simply\nreplace the wind velocity, $v_{\\wind}$, with the wind velocity\nperpendicular to the flight path, $v_{\\wind, \\perp}$.\n%\n\\begin{equation}\nv_{\\wind, \\perp} = v_{\\wind} \\cos \\theta\n\\end{equation}\n%\nHere $\\theta$ is the angle between the normal vector of the flight\npath and the wind vector.\n\n\\subsection{Gravity losses}\n\nSignificant power is lost due to various effects from the velocity\nchanges caused by gravity.  The exact form of this loss depends on the\npropeller strategy used.  There are two naive propeller strategies,\nneither optimal, which can be used to determine the worst case gravity\nloss.\n\nThe first propeller strategy, which is the easiest to analyze, is the\nconstant airspeed strategy, where a term is added to the nominal\npropeller drag to exactly cancel the force of gravity.  The loss here\noccurs because the conversion of power from aerodynamic power to\nelectrical grid power and back is not perfectly efficient.  The exact\nform of the power loss with this strategy is\n%\n\\begin{equation}\n  \\label{eqn:gravity_loss1}\n  P_{\\grav} = \\frac{m g_{\\parallel} v_{\\kite}}{\\pi}\n  \\left( \\eta_{\\airgrid} - 1/\\eta_{\\airgrid} \\right)\n\\end{equation}\n\nThe second propeller strategy is the constant drag fraction strategy.\nHere, the control system ignores the speed variations caused by\ngravity.  One way to view this strategy is that the kite is storing\nthe excess energy during the down stroke as the kinetic energy in the\nkite and then reusing this energy on the upstroke.  Storing and\nreusing the energy in this manner is more efficient than converting\nthe power to and from electrical power.\n\nTo analyze this strategy, assume that the velocity of the kite takes\nthe approximate form\n%\n\\begin{equation}\n  v_{\\kite} \\approx v_{\\kite,0} + \\Delta v \\sin \\psi\n\\end{equation}\n%\nwhere $\\psi$ is the angle around the loop.  The velocity modulation\nfraction, $a = \\Delta v / v_{\\kite,0}$, is approximately:\n%\n\\begin{equation}\n  \\label{eqn:velocity_modulation}\n  a = \\frac{\\Delta v}{v_{\\kite,0}} \\approx\n      \\frac{m g_{\\parallel} R_{\\path}}\n           {m v_{\\kite, 0}^2 +\n            \\frac{1}{2} \\rho v_{\\kite, 0}^2 A_{\\kite} C_{D_{\\sys}} (1 + k) R_{\\path}}\n\\end{equation}\n%\n\nThere are two main power loss mechanisms due to the velocity\nvariation.  The first mechanism is simply that the kite is no longer\nflying at the optimal airspeed.  The effect of this can be found by\nintegrating the extra drag force on the kite,\n$D_{\\extra} = \\frac{1}{2} \\rho C_D A_{\\kite} v_{\\kite} \\Delta v$, around\nthe loop.  The second mechanism is that, while the kite generates the\nsame amount of energy per loop, the loops take longer for larger\nmodulations.  Combining these effects, the power loss due to gravity\nis:\n%\n\\begin{equation}\n  \\label{eqn:gravity_loss2}\n  P_{\\grav} = \\; P(v_{\\wind}) \\left( 1 - \\sqrt{1 - a^2} - \\frac{a^2}{2} \\sqrt{1 - a^2} \\right)\n\\end{equation}\n%\nNote that this quantity is defined to be positive for a power less.\n\n\\section{Realistic power curve}\n\nEquation \\ref{eqn:real_power_curve} describes the modified power curve\nafter applying the efficiency losses from the previous section:\n%\n\\begin{equation}\n  \\label{eqn:real_power_curve}\nP(v_{\\wind}) =\n\\begin{cases}\n  0 &\n  v_{\\wind} \\le v_{\\wind,\\cutin} \\\\\n\n  \\eta_{\\airgrid} \\cdot P_0 \\left(\\frac{v_{\\wind}}{v_{\\wind,\\cutin}} - 1 \\right) - P_{\\grav} &\n  v_{\\wind,\\cutin,0} < v_{\\wind} \\le \\frac{3}{2} v_{\\wind,\\cutin,0} \\\\\n\n  \\eta_{\\airgrid} \\cdot \\frac{1}{2} \\rho v_{\\wind}^3 A_{\\kite} \\zeta_{\\max} \\cos^3 \\theta - P_{\\grav} &\n  \\frac{3}{2} v_{\\wind,\\cutin,0} < v_{\\wind} \\le v_{\\wind,T} \\\\\n\n  \\eta_{\\airgrid} \\cdot T_{\\max} \\cos \\theta \\left( v_{\\wind} - \\frac{2}{3} v_{\\wind,T} \\right) - P_{\\grav} &\n  v_{\\wind,T} < v_{\\wind} \\le v_{\\wind,P} \\\\\n\n  P_{\\max} &\n  v_{\\wind,P} < v_{\\wind} \\le v_{\\wind,\\cutout} \\\\\n\n  0 &\n  v_{\\wind} > v_{\\wind,\\cutout}\n\\end{cases}\n\\end{equation}\n%\nNote that because of the complicated form of the gravity power losses\n(see Eq. \\ref{eqn:gravity_loss1} and Eq. \\ref{eqn:gravity_loss2}), they\nare included as a wind speed independent constant for now.\n\n\\begin{equation}\nP_0 = \\frac{1}{2} \\rho v_{\\kite, \\min}^3 A_{\\kite} C_{D_{\\sys}}\n\\end{equation}\n\n\\begin{equation}\nv_{\\wind, \\cutin, 0} = \\frac{C_{D_{\\sys}}}{C_L} \\frac{v_{\\kite, \\min}}{\\cos \\theta}\n\\end{equation}\n\n\\begin{equation}\n  v_{\\wind, \\cutin} = \\left(1 + \\frac{P_{\\grav}}{\\eta_{\\airgrid} P_0} \\right)\n  \\frac{C_{D_{\\sys}}}{C_L} \\frac{v_{\\kite, \\min}}{\\cos \\theta}\n\\end{equation}\n\n\\begin{equation}\nv_{\\wind, T} = \\frac{1}{\\cos \\theta}\n\\sqrt{\\frac{T_{\\max} / 3}{\\frac{1}{2} \\rho A_{\\kite} \\zeta_{\\max}}}\n\\end{equation}\n\n\\begin{equation}\nv_{\\wind, P} = \\frac{P_{\\max} + P_{\\grav}}{\\eta_{\\airgrid} T_{\\max} \\cos \\theta} + \\frac{2}{3} v_{\\wind, T}\n\\end{equation}\n\n\n\\begin{figure}[h]\n\\label{fig:real_power_curve}\n\\begin{center}\n\\begin{tikzpicture}\n  \\def\\CL{2.1};\n  \\def\\CDsys{0.18};\n  \\def\\costheta{0.866};\n  \\def\\etaairgrid{0.67};\n  \\def\\Tmax{200};  % [kN]\n  \\def\\Pmax{600};  % [kW]\n  \\def\\Pgrav{50};  % [kW]\n  \\def\\zetamax{(4/27 * \\CL^3 / \\CDsys^2)};\n  \\def\\Ak{32.9};\n  \\def\\rho{1.2};\n  \\def\\vkitemin{30};\n  \\def\\P0{(0.5 * \\rho * \\Ak * \\CDsys * \\vkitemin^3 / 1000)};\n  \\def\\vcutin{(\\CDsys / \\CL * \\vkitemin / \\costheta)};\n  \\def\\vT{((\\Tmax * 1000 / 3 / (0.5 * \\rho * \\Ak * \\zetamax))^0.5 / \\costheta)};\n  \\def\\vP{(\\Pmax / (\\etaairgrid * \\Tmax * \\costheta) + 2 * \\vT / 3)};\n  \\def\\vPtrue{(\\vP + \\Pgrav / (\\etaairgrid * \\costheta * \\Tmax))};\n  \\def\\vcutintrue{((1 + \\Pgrav/(\\etaairgrid * \\P0)) * \\vcutin)};\n  \\def\\loydcoeff{(\\etaairgrid * \\costheta^3 * 0.5 * \\rho * \\Ak * \\zetamax / 1000)};\n\n\\begin{axis}[axis lines=middle, samples=200,\n    grid=both,\n    grid style={line width=1pt, draw=gray!10},\n    x label style={at={(axis description cs:0.5,-0.1)}, anchor=north},\n    y label style={at={(axis description cs:-0.1,.5)}, rotate=90, anchor=south},\n    xlabel={Wind speed [m/s]},\n    ylabel={Power [kW]},\n    legend pos=north west]\n  \\addplot[matlab1, domain=0:(\\vcutintrue)] {0};\n  %\\addplot[matlab2, domain=(\\vcutin):(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1) - \\Pgrav};\n  \\addplot[matlab3, domain=(\\vcutintrue):(\\vT)] {\\loydcoeff * x^3 - \\Pgrav};\n  \\addplot[matlab4, domain=(\\vT):(\\vPtrue)] {\\etaairgrid * \\costheta * \\Tmax * (x - 2 * \\vT / 3) - \\Pgrav};\n  \\addplot[matlab5, domain=(\\vPtrue):(\\vPtrue + 2)] {\\Pmax};\n  \\legend{$v_{\\wind,\\cutin}$, $\\zeta_{\\max}$, $T_{\\max}$, $P_{\\max}$};\n\n  \\addplot[matlab3, dashed, domain=(1.5 * \\vcutin):(\\vcutintrue)] {\\loydcoeff * x^3 - \\Pgrav};\n  \\addplot[matlab3, dashed, domain=(\\vT):(\\vT + 2.5)] {\\loydcoeff * x^3 - \\Pgrav};\n  \\addplot[matlab2, dashed, domain=2:(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1) - \\Pgrav};\n\n  \\def\\costheta{1};\n  \\def\\etaairgrid{1};\n  \\addplot[gray!50, domain=(\\vcutin):(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1)};\n  \\addplot[gray!50, domain=(1.5 * \\vcutin):(\\vT)] {\\loydcoeff * x^3};\n  \\addplot[gray!50, domain=(\\vT):(\\vP)] {\\etaairgrid * \\costheta * \\Tmax * (x - 2 * \\vT / 3)};\n  \\addplot[gray!50, domain=(\\vP):(\\vP + 2)] {\\Pmax};\n\n  \\def\\costheta{1};\n  \\def\\etaairgrid{0.67};\n  \\addplot[gray!50, dashed, domain=(\\vcutin):(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1)};\n  \\addplot[gray!50, dashed, domain=(1.5 * \\vcutin):(\\vT)] {\\loydcoeff * x^3};\n  \\addplot[gray!50, dashed, domain=(\\vT):(\\vP)] {\\etaairgrid * \\costheta * \\Tmax * (x - 2 * \\vT / 3)};\n  \\addplot[gray!50, dashed, domain=(\\vP):(\\vP + 2)] {\\Pmax};\n\n  \\def\\costheta{0.866};\n  \\def\\etaairgrid{0.67};\n  \\addplot[gray!50, dotted, domain=(\\vcutin):(1.5 * \\vcutin)] {\\etaairgrid * \\P0 * (x / \\vcutin - 1)};\n  \\addplot[gray!50, dotted, domain=(1.5 * \\vcutin):(\\vT)] {\\loydcoeff * x^3};\n  \\addplot[gray!50, dotted, domain=(\\vT):(\\vP)] {\\etaairgrid * \\costheta * \\Tmax * (x - 2 * \\vT / 3)};\n%  \\addplot[gray!50, dotted, domain=(\\vP):(\\vP + 2)] {\\Pmax};\n\n  \\def\\costheta{0.866};\n  \\def\\etaairgrid{0.67};\n  \\draw[gray, dashed] (axis cs:{\\vcutintrue}, 25) -- (axis cs:{\\vcutintrue}, 150)\n  node [above, black] {$v_{\\wind,\\cutin}$};\n  %% \\draw[gray, dashed] (axis cs:{1.5 * \\vcutin}, 100) -- (axis cs:{1.5 * \\vcutin}, 250)\n  %% node [above, black] {$v_{\\wind,v_{\\kite}}$};\n  \\draw[gray, dashed] (axis cs:{\\vT}, {\\loydcoeff * \\vT^3 - 100}) -- (axis cs:{\\vT}, {\\loydcoeff * \\vT^3 / 2})\n  node [below, black] {$v_{\\wind,T}$};\n  \\draw[gray, dashed] (axis cs:{\\vPtrue}, 550) -- (axis cs:{\\vPtrue}, 450)\n  node [below, black] {$v_{\\wind,P}$};\n\n\\end{axis}\n\\end{tikzpicture}\n\\caption{Realistic power curve (colored) versus the ideal power curve\n  (solid gray), power curve with conversion losses (dashed gray),\n  power curve with conversion and off-downwind losses (dotted gray).\n  This particular power curve assumes: $A_{\\kite} = 32.9$ m$^2$,\n  $v_{\\kite,\\min} = 30$ m/s, $\\zeta_{\\max} = 42.3$, $T_{\\max} = 200$\n  kN, $P_0 = 96$ kW, $P_{\\max} = 600$ kW, $\\theta = 30^{\\circ}$,\n  $\\eta_{\\airgrid} = 0.67$, and $P_{\\grav} = 50$ kW.}\n\\end{center}\n\\end{figure}\n\n\n\\section{Mean power production}\n\nThe utility of a power curve is that it enables the calculation of the\nmean power production, $\\bar{P}$, at a site with a given wind\ndistribution.  The mean power production is found by integrating the\npower curve weighted by the probability distribution function of the\nwind speeds:\n%\n\\begin{equation}\n\\bar{P} = \\int_0^{v_{\\wind,\\cutout}} dv\\, p(v) P(v)\n\\end{equation}\n\nAssuming a Rayleigh distribution, Eq. \\ref{eqn:rayleigh}, for the\ndistribution of wind speeds, it is possible to derive a closed form\nsolution for the mean power production of a kite system in terms of\nthe site's mean wind speed, $\\bar{v}$, and the limits of the kite\nsystem.\n%\n\\begin{equation}\n\\label{eqn:rayleigh}\np(v) = \\frac{\\pi}{2} \\frac{v}{\\bar{v}^2} \\exp \\left(-\\frac{\\pi}{4} \\frac{v^2}{\\bar{v}^2} \\right)\n\\end{equation}\n%\nThe mean power is composed of terms from the Loyd-limited, tension\nlimited, and power limited sections of the power curve.\n\\begin{equation}\n\\bar{P} = \\bar{P}_{\\zeta} + \\bar{P}_T + \\bar{P}_P - \\bar{P}_{\\grav}\n\\end{equation}\n%\nIgnoring the gravity losses for now, the functional form of each of\nthese components is:\n%\n\\begin{align}\n\\bar{P}_{\\zeta} =&\\;\n\\eta_{\\airgrid} \\cdot \\frac{1}{2} \\rho \\zeta_{\\max} \\cos^3 \\theta A \\bar{v}^3 \\\\ \\notag\n&\\times \\left[\\frac{6}{\\pi} \\erf \\left(\\frac{\\sqrt{\\pi}}{2} \\frac{v_{\\wind,T}}{\\bar{v}}\\right) -\n\\frac{v_{\\wind,T}}{\\bar{v}} \\exp \\left(-\\frac{\\pi}{4}\\frac{v_{\\wind,T}^2}{\\bar{v}^2}\\right)\n\\left(\\frac{6}{\\pi} + \\frac{v_{\\wind,T}^2}{\\bar{v}^2}\\right)\n\\right]\n\\end{align}\n\n\\begin{align}\n\\bar{P}_T =&\\; \\eta_{\\airgrid} \\cdot T_{\\max} \\cos \\theta \\bar{v} \\\\ \\notag\n           & \\times \\bigg[\n\\erf \\left(\\frac{\\sqrt{\\pi}}{2} \\frac{v_{\\wind,P}}{\\bar{v}}\\right) -\n\\erf \\left(\\frac{\\sqrt{\\pi}}{2} \\frac{v_{\\wind,T}}{\\bar{v}}\\right) \\\\ \\notag\n%\n& \\phantom{\\times \\bigg[} + \\left(\\frac{2}{3} \\frac{v_{\\wind,T}}{\\bar{v}} -\n\\frac{v_{\\wind,P}}{\\bar{v}}\\right)\n\\exp \\left( -\\frac{\\pi}{4} \\frac{v_{\\wind,P}^2}{\\bar{v}^2} \\right) +\n\\frac{1}{3} \\frac{v_{\\wind,T}}{\\bar{v}}\n\\exp \\left( -\\frac{\\pi}{4} \\frac{v_{\\wind,T}^2}{\\bar{v}^2} \\right) \\bigg]\n\\end{align}\n\n\\begin{equation}\n\\bar{P}_P = P_{\\max} \\exp \\left( -\\frac{\\pi}{4} \\frac{v_{\\wind,P}^2}{\\bar{v}^2}\\right)\n\\end{equation}\n\n\\begin{equation}\n  \\bar{P}_{\\grav} = P_{\\grav} \\left[\n    \\exp \\left(-\\frac{\\pi}{4} \\frac{v_{\\wind,\\cutin}^2}{\\bar{v}^2} \\right) -\n    \\exp \\left(-\\frac{\\pi}{4} \\frac{v_{\\wind,P}^2}{\\bar{v}^2} \\right)\n    \\right]\n\\end{equation}\n\n%% \\subsection{Cost analysis}\n\n%% In this simplified analysis, we assume some cost per unit power,\n%% $c_P$, some cost per unit tension, $c_T$, and some cost per unit kite\n%% area, $c_A$.\n\n%% \\begin{equation}\n%% C = c_P P_{\\max} + c_T T_{\\max} + c_{\\zeta A} \\zeta A\n%% \\end{equation}\n\n\\section{Appendix}\n\n\\subsection{Gravity power loss}\n\nHere is a sketch of the derivation of the velocity modulation for the\nconstant drag fraction strategy (see Eq. \\ref{eqn:velocity_modulation}).\n\n\\begin{equation}\n  m \\dot v_{\\kite} = m g_{\\parallel} \\cos \\psi +\n                     \\frac{1}{2} \\rho v_{\\app} A (C_L v_{\\wind} - C_D v_{\\kite})\n\\end{equation}\n\n\\begin{equation}\n  v_{\\kite}(t) = v_{\\kite, 0} + \\delta v_{\\kite}(t)\n\\end{equation}\n\nAssuming $\\delta v_{\\kite}$ is small:\n%\n\\begin{equation}\n  m \\delta \\dot v_{\\kite} = m g_{\\parallel} \\cos \\psi -\n                            \\frac{1}{2} \\rho v_{\\kite, 0} C_D A \\delta v_{\\kite}\n\\end{equation}\n\n\\begin{align}\n  \\Delta v_{\\kite} &= \\int_{side}^{top} d \\delta v_{\\kite} \\\\\n                   &= \\int_0^{\\pi/2} d\\psi \\frac{R_{\\path}}{v_{\\kite, 0}}\n                      \\left(g_{\\parallel} \\cos \\psi -\n                      \\frac{1}{2} \\rho \\frac{v_{\\kite, 0}}{m} A C_D \\delta v_{\\kite} \\right)\n\\end{align}\n\n\\begin{equation}\n  \\frac{\\Delta v}{v_{\\kite,0}} \\approx\n  \\frac{m g_{\\parallel} R_{\\path}}\n       {m v_{\\kite, 0}^2 +\n        \\frac{1}{2} \\rho v_{\\kite, 0}^2 A_{\\kite} C_D R_{\\path}}\n\\end{equation}\n\n\nThe time it takes to go around the loop is\n\n\\begin{equation}\n  T_{\\lp} = \\int_0^{2 \\pi} d\\psi \\frac{R}{v_{\\kite,0} + \\delta v}\n          = \\frac{R}{v_{\\kite,0}} \\int_0^{2 \\pi} d\\psi \\frac{1}{1 + a \\sin \\psi}\n          = \\frac{T_{\\lp,0}}{\\sqrt{1 - a^2}}\n\\end{equation}\n%\nwhere $a = \\Delta v / v_{\\kite,0}$.\n\nThe energy made in a loop is\n\n\\begin{align}\n  E_{\\lp} &= \\int_0^{2 \\pi} d\\psi R \\frac{1}{2} \\rho v_{\\kite}^2 A_{\\kite} \\eta_{\\airgrid} k C_{D_{\\sys}} \\\\\n          &= \\int_0^{2 \\pi} d\\psi R \\frac{1}{2} \\rho v_{\\kite,0}^2 (1 + a \\sin \\psi)^2 A_{\\kite} \\eta_{\\airgrid}k C_{D_{\\sys}} \\\\\n          &= \\frac{1}{2} \\rho v_{\\kite,0}^2 R A_{\\kite} \\eta_{\\airgrid} k C_{D_{\\sys}} \\left(1 + \\frac{a^2}{2} \\right) 2 \\pi\n\\end{align}\n\nThe power loss due to gravity may be found by comparing the $a=0$\npower to the expected power.\n\n\\begin{align}\n  P_{\\grav} &= \\frac{E_{\\lp,0}}{T_{\\lp,0}} - \\frac{E_{\\lp}}{T_{\\lp}} \\\\\n            &= P_0 \\left( 1 - \\sqrt{1 - a^2} - \\frac{a^2}{2} \\sqrt{1 - a^2} \\right)\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "7d7e349f44be16ba8518dcda383aae9b3f85ec98", "size": 33692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/control/system/power_curve.tex", "max_stars_repo_name": "leozz37/makani", "max_stars_repo_head_hexsha": "c94d5c2b600b98002f932e80a313a06b9285cc1b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1178, "max_stars_repo_stars_event_min_datetime": "2020-09-10T17:15:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:59:35.000Z", "max_issues_repo_path": "documentation/control/system/power_curve.tex", "max_issues_repo_name": "leozz37/makani", "max_issues_repo_head_hexsha": "c94d5c2b600b98002f932e80a313a06b9285cc1b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-22T05:22:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-22T05:22:35.000Z", "max_forks_repo_path": "documentation/control/system/power_curve.tex", "max_forks_repo_name": "leozz37/makani", "max_forks_repo_head_hexsha": "c94d5c2b600b98002f932e80a313a06b9285cc1b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 107, "max_forks_repo_forks_event_min_datetime": "2020-09-10T17:29:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T09:00:14.000Z", "avg_line_length": 38.9502890173, "max_line_length": 129, "alphanum_fraction": 0.656298231, "num_tokens": 12382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569014, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6016472297577425}}
{"text": "\\documentclass{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{graphicx}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\begin{document}\n\\title{\"Fermat's\" Two Squares (aka Christmas) Theorem}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{Fermat's Two Squares Theorem}\n\nThe theorem states that an odd prime $p$ can be written as the sum of two squares of\npositive integers:\n\\[ p = a^2 + b^2 , a, b \\in \\mathbb{N} \\]\nif and only if it is of the form $4k+1, k\\in \\mathbb{N}$.\n\nThis theorem was stated by Fermat without proof, and it was several decades before a proof\nwas provided. Since then, several proofs have been discovered, including one which relies \non the characteristics of the Gaussian integers, and another which we can prove using a\nvery pretty geometry-based involution. I present these two proofs (with dependent tools)\nbelow.\n\n\\section{Dedekind's Proof in Gaussian Integers}\n\n\\subsection{Gaussian Integers}\n\nThe Gaussian integers $\\mathbb{Z}[i]$ are complex numbers of the form \n\\[ \\mathbb{Z}[i] = \\{a+ib:a,b\\in \\mathbb{Z}, i=\\sqrt{-1}\\}\\]\n\nThe Gaussian integers are closed under the standard multiplication operator\n$(a+ib) \\times (c+id) = (ac-bd) + i(bc+ad)$, which is commutative (meaning\n$z_1 \\times z_2 = z_2 \\times z_1$), and they have a multiplicative and additive\nidentity. They are therefore a ring.\n\nBy defining a norm function $N(a+bi) = a^2+b^2$, we can also define Euclidean division of\nGaussian integers. That is, for $a,b \\in \\mathbb{Z}[i]$, there exist $q,r \\in \\mathbb{Z}[i],\n\\text{ s.t. } a=qb+r, \\text{ with } N(r)<N(b)$. So we can use classic division\nalgorithms like  the Euclidean algorithm and Bézout's itentity on Gaussian integers. This\ncharacteristic means that $\\mathbb{Z}[i]$ is a Euclidean domain, and, as a result, a Unique\nFactorization Domain.\n\nWhat this means is that, given any element $x \\in \\mathbb{Z}[i]$, we can find a unique\nfactorization of $x$ in irreducible elements $\\{p_i\\}$ and a unit $u$ such that:\n\\[ x = up_1p_2\\cdots p_n \\text{ with } n\\geq 0 \\]\n\nIn the ring of integers, we call these irreducible elements primes, and in the Gaussian\nintegers, we will call them Gaussian primes. The Gaussian integers has four units,\n$\\pm 1, \\pm i$.\n\n\\subsection{Fermat's Little Theorem}\n\nFor the Two Squares theorem, we will be using a sub-ring of the Gaussian integers, the\nGaussian integers $\\pmod{p}$ defined as $\\{a+ib:a,b\\in \\mathbb{Z}/p\\mathbb{Z}, i=\\sqrt{-1}\\}$.\nAgain, this set is closed under multiplication and addition, and we will denote the set \n$\\mathbb{Z}[i]/(p)$. The notation $(p)$ denotes a prime ideal of the Gaussian integers - the\nsubset of the Gaussian integers that can be generated from the irreducible element $p$.\n\nWe will need some well-known results from modular arithmetic to complete the proof. The first\nof these is Fermat's Little Theorem, which states:\n\n\\begin{theorem}For every prime $p \\in \\mathbb{N}$, and $a \\in \\mathbb{N}$ :\n\\[ a^p \\equiv p \\pmod{p} \\]\n\\end{theorem}\n\n\\begin{proof}\nIf $a\\equiv 0 \\pmod{p}$ then $a^p \\equiv 0 = a \\pmod{p}$\n\nIf $\\gcd(a,p)=1$: \n\\[a \\times n \\equiv a \\times m \\pmod{p} \\implies a(n-m) \\equiv 0 \\pmod{p} \\]\n\nSince $\\gcd(a,p)=1$: $n-m\\equiv 0 \\pmod{p} \\implies n = m \\pmod{p}$. Therefore:\n\n\\[ \\{i: 0 < i < p, i \\in \\mathbb{N}\\} = \\{a\\times i, 0 < i < p, i \\in \\mathbb{N} \\} \\]\n\nThat is, the set of the non-zero integers mod $p$ is a derangement of itself when we \nmultiply each element by any member of the set, so if we multiply all of the elements\ntogether we get the same number. That is:\n\n\\[ \\prod_{i=1}^{p-1} i \\equiv \\prod_{i=1}^{p-1} a\\times i \\]\n\\[ (p-1)! \\equiv a^{p-1}\\times (p-1)! \\]\n\nAnd since all numbers in $(p-1)!$ are relatively prime to $p$, we can divide across on both sides to\nleave: $1 \\equiv a^{p-1}$\n\\end{proof}\n\nWe will use this result to identify a criterion for identifying numbers that can square to a \ncertain value.\n\n\\subsection{Quadratic residues and the Euler criterion}\n\nFermat's Little Theorem proves that all numbers $\\pmod{p}$ have a multiplicative order of at\nmost $p-1$, but clearly there are numbers with a smaller order. For example, $1^i = 1$ for all\n$i$, and $(-1)^i = 1$ for all even $i$.\n\nQuadratic residues in $\\mathbb{Z}/p\\mathbb{Z}$ are numbers which have a square root in\n$\\mathbb{Z}/p\\mathbb{Z}$. For example, in $\\mathbb{Z}/5\\mathbb{Z}$, $1^2 \\equiv 4^2 \\equiv 1\n\\pmod{5}$, and $2^2 \\equiv 3^2 \\equiv 4 \\pmod{5}$, so $\\{1,4\\}$ is the set of quadratic residues\n$\\pmod{5}$. We can show that for a prime $p$, exactly $\\frac{p+1}{2}$ of the members of\n$\\mathbb{Z}/p\\mathbb{Z}$ are quadratic residues (including 0), and $\\frac{p-1}{2}$ are quadratic\nnon-residues.\n\nIn particular, 1 has two square roots $\\pmod{p}: \\pm 1$. If we can show that \n\\[\\sqrt{a^{p-1}} = a^{\\frac{p-1}{2}} = 1\\]\nthen that implies that there is some number $m \\in \\mathbb{Z}/p\\mathbb{Z}$ such that $m^2 = a$,\nsince $m^{p-1} = 1$ for all $m \\neq 0$. This test for quadratic residues is called Euler's\ncriterion, and is formally defined for odd primes as:\n\\[a^{\\frac{p-1}{2}} =\n\\left\\{\n\t\\begin{array}{ll}\n\t\t1  & \\mbox{if there exists } m \\in \\mathbb{Z}/p\\mathbb{Z} \\mbox{ such that } m^2 \\equiv a \\pmod{p} \\\\\n\t\t-1  & \\mbox{if } a \\mbox{ is a quadratic non-residue in } \\mathbb{Z}/p\\mathbb{Z} \\\\\n\t\\end{array}\n\\right. \\]\n\n\\subsection{The Two Squares Theorem}\n\nWe now have all of the tools we need to prove the Two Squares theorem.\n\nFirst, it is trivial to prove that no prime of the form $4k+3$ can be written as the sum of two\nsquares by noticing that $n^2 \\equiv 0 \\mbox{ or } 1 \\pmod{4}$ for all $n\\in \\mathbb{N}$, so \n$a^2+b^2 = 0,1 \\mbox{ or } 2 \\pmod{4}$, but $p \\equiv 3 \\pmod{4}$.\n\nNow, for $p=4k+1$, we must show that there exist $a,b \\in \\mathbb{N}$ such that $p=a^2+b^2$. There\nis a second question, regarding the uniqueness of this solution, which we will not prove here.\n\nNote that $(-1)^{\\frac{p-1}{2}} = 1$ since $\\frac{p-1}{2}=2k$, so -1 is a quadratic\nresidue $\\pmod{p}$. Therefore, there must be an $a \\in \\mathbb{Z}/p\\mathbb{Z}$ such that\n$a^2 + 1 \\equiv 0 \\pmod{p}$. Now, in $\\mathbb{Z}[i]/(p)$, we can factor $a^2+1$ into\n$(a-i)(a+i)$. Since $N(a+i)=N(a-i)<N(p)$ (since $a < p$), $p$ does not divide either $a+i$ or\n$a-i$, and therefore, $p$ is not a prime in $\\mathbb{Z}[i]/(p)$, so there exists some Gaussian \nprime factorization of $p = (x+iy)(x-iy)$ - giving $p = x^2+y^2$.\n\nI like this proof, because once we know that the Gaussian integers are a UFD, we can use all of\nthe other tools we get from modular arithmetic to show that $p$ must have non-trivial factors.\nHowever, understanding the proof does require an understanding of modular arithmetic and rings.\n\n\\section{Zagier's one sentence proof}\n\nThe following proof uses a transformation which appears to come from out of nowhere, but as we\nshall see, has a very intuitive geometric explanation. The full statement of the proof is:\n\nLet $p=4k+1$ be prime, let $\\mathbb{N}$ denote the natural numbers, and consider the finite set\n$S=\\{(x,y,z) \\in \\mathbb{N}^3: x^2+4yz = p\\}$ of triples of numbers. Then $S$ has two \ninvolutions: $(x,y,z) \\to (x,z,y)$ with fixed points when $y=z$ (corresponding to \n$p=x^2+(2y)^2$ a sum of two squares) and the following:\n\\[ (x,y,z) \\to\n\\left\\{\n\t\\begin{array}{ll}\n\t\t(x+2z,z,y-x-z)  & \\mbox{if } x< y-z \\\\\n\t\t(2y-x,y,x-y+z)  & \\mbox{if } y-z < x < 2y \\\\\n\t\t(x-2y,x-y+z,y)  & \\mbox{if } x > 2y \\\\\n\t\\end{array}\n\\right. \\]\nwhich has exactly one fixed point at $(x,y,z) = (1,1,k)$. Two involutions over the same\nset must have sets of fixed points of the same parity, and since the second involution\nhas exactly one fixed point, the first involution must have at least one fixed point, so\n$p$ must be expressible as the sum of two squares.\n\n\\subsection{Involutions}\n\nThe key to this proof is understanding involutions, and their fixed points. An involution\nis simply a function which is its own inverse, that is, $x = f(f(x))$. Every involution is\na bijection - that is, every element of the range has an element of the domain that maps\nonto it, and every element of the domain maps onto a different element of the range.\n\nAs a result, points in a set can have an order of 1 ($f(x)=x$, or $x$ is a fixed point\nof $f$) or 2 ($f(x)=y, y(y)=x, x\\neq y$) under an involution.\n\nIf you have two involutions on the same set, then if there is one fixed point in the first,\nthat means that the total number of solutions is odd (one fixed points and $k$ pairs of\npoints of order 2).\n\nThen if there is a second involution, that must also apply to the same odd number of\nelements of the set, and as a result, there must be an odd number of fixed points in this second involution too (specifically, at least one fixed point)\n\nBut where did that very complicated mapping come from? The time has come to talk about\nwindmills.\n\n\\subsection{Geometric representation of triples $(x,y,z)$}\n\nLet's tease apart the \"one-line\" proof to see what's going on graphically.\n\nFirst, let us verify that the involutions actually make sense.\n\nFor the members of the set $S=\\{(x,y,z):p=x^2+4yz, x, y, z \\in \\mathbb{N}\\}$, since\n$p = 4k+1$, and $4yz$ is even, $x$ can be any odd number less than\n$\\sqrt{p}$. Since we are guaranteed that $x=2a+1$ for $a\\in \\mathbb{N}_0$, we can be\nsure that $p-x^2 = 4k+1 -(4a^2+4a+1) = 4(k-a^2-a)$ is a multiple of 4, with $k>a^2+a$.\n$(x,y,z) \\in S \\implies (x,z,y) \\in S$ - so we are guaranteed that the first\ntransformation is an involution.\n\nFor the second transformation, we can consider a triple $(x,y,z)$ as a geometric\narrangement of a square of side $x$, plus four equal rectangles of size $y\\times z$\narranged symmetrically around the central square. In the diagram below \\ref{fig:windmill1},\nwe have one mapping for $p=89$ with $(x,y,z)=(5,8,2)$ mapping to $(x,y,z)=(9,2,1)$ under the\nmapping $(x,y,z) \\to (x+2z,z,y-x-z)$, and the inverse transformation corresponding\nto $(x,y,z) \\to (x-2y,x-y+z,y)$. The shapes we see for this form are the windmill\nforms the proof is known for.\n\n\\begin{figure}\n\t\\includegraphics[width=\\linewidth, bb=0px 0px 800px 400px]{windmill1.png}\n\t\\caption{Mapping $(5,8,2) \\to (9,2,1)$}\n\t\\label{fig:windmill1}\n\\end{figure}\n\nTo show an alternative arrangement, we can swap $y$ and $z$ in the initial arrangement\nto get $(x,y,z)=(5,2,8)$, which transforms under the rule $(x,y,z) \\to (x-2y, x-y+z, y)$\nto $(x,y,z) = (1, 11, 2)$, and transforms under the inverse rule $(x,y,z) \\to \n(x+2z, z, y-x-z)$ (and note that at each stage, $x^2+4yz = 89$). In this arrangement,\nthe windmill pattern is clearer.\n\n\n\\begin{figure}\n%\t\\includegraphics[width=\\linewidth, bb=0px 0px 1200px 715px]{windmill2.png}\n\t\\includegraphics[width=\\linewidth, viewport=0px 0px 1200px 715px]{windmill2.png}\n\t\\caption{Mapping $(5,2,8) \\to (1,11,2)$}\n\t\\label{fig:windmill2}\n\\end{figure}\n\nThere are exactly two representations in $(x,y,z)$ for each shape\nwhich is a solution to $p=x^2+4yz$, representing different ways of \"wrapping\" the\nrectangles around the inside square, except for one representation, which is represented\nby $(x,y,z) = (1,1,k)$ - this shape is a 1x1 square in the center, and four long and thin\nrectangles pointing out at each side. For this configuration, there is no alternative way\nto get a larger central square - this is guaranteed to be the only fixed point of the\ntransformation (since $y-z < x < 2y$, the rule $(x,y,z) \\to (2y-x, y, x-y+z)$ is applied).\n\nAnd going all the way back to our starting point, since we have exactly one fixed point\nin this involution, and it is applied to the same set as the alternative involution,\nthe alternative must also have a fixed point. QED.\n\n\n\\appendix\n\n\\section{Using the Euclidean algorithm on $\\mathbb{Z}[i]$}\n\nWe can find $\\gcd(a,b), a,b \\in \\mathbb{Z}[i]$ using the Euclidean algorithm\nas follows (example using $11 + 7i$ and $18 - i$):\n\n\\[N(11+7i) = 170, N(18-i)=324 \\]\n\nSo we start with $18-i$ on the LHS.\n\n\\[ \\frac{18 - i}{11 + 7i} = \\frac{(18 - i)(11 - 7i)}{11^2+7^2} = \\frac{205 - 137i}{170} \\]\n\nRounding the real and imaginary parts to the nearest integers, we get \n\n\\[ 18 - i = (1 - i)(11 + 7i) + 3i \\]\n\nNow we repeat with $11 + 7i, 3i$, noting that $N(3i) = 9$:\n\n\\[ \\frac{11+7i}{3i} = \\frac{(11 + 7i)(-3i)}{9} = \\frac{7 -11i}{3} \\]\n\\[ 11 + 7i = (2 - 4i)(3i) +i \\]\n\nAnd the GCD is the unit $i$ (or 1).\n\n\\end{document}\n\n", "meta": {"hexsha": "3721f192ef492e0ec662342722363a7b1357e469", "size": 12277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "two_squares.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": "two_squares.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": "two_squares.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": 46.5037878788, "max_line_length": 152, "alphanum_fraction": 0.6903966767, "num_tokens": 4095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6016472244639587}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 20}\n\\subsection{Lecture Notes - Free Rotation of Spinning Top \\& Euler Angles}\n\\subsubsection{Euler Equations Review}\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img1.png}\n\\end{center}\nA rotating dumbbell consists of two masses $m$ which move in circles at a $z$ displacement $l$ and $-l$, joined by a massless rod. The angular velocity vector is $\\bm{\\omega} = \\omega\\zhat$. Consider the body frame where the positions of the masses are $(0, a, l)$ and $(0, -a, -l)$. What are the principle axes of inertia?\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img2.png}\n\\end{center}\n\\begin{s}\nA). The principle axes of inertia are aligned with the symmetries of the body. If there is a symmetry axes, we can expect this to correspond to a principle axis.\n\\end{s}\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img3.png}\n\\end{center}\nFollowup: What is the components of the angular velocity vector in this frame? (where $\\theta$ is the angle formed by the z-axis/rotation axis and the mass?)\n\\begin{s}\n$\\bm{\\omega} = \\m{\\omega\\cos\\theta \\\\ \\omega\\sin\\theta \\\\ 0}$ by trigonometry. \n\\end{s}\nConsider the body frame aligned with the principle axes of inertia (as sketched). What are Euler's equations in this frame?\n\\begin{s}\nWe first recall the three moments of inertia:\n\\[\\lambda_1 = 0\\]\n\\[\\lambda_2 = 2m(a^2 + l^2)\\]\n\\[\\lambda_3 = 2m(a^2 + l^2)\\]\nWe also recall the Euler equations:\n\\[\\Gamma_1 = \\lambda_1\\dot{\\omega}_1 - (\\lambda_2 - \\lambda_3)\\omega_2\\omega_3\\]\n\\[\\Gamma_2 = \\lambda_2\\dot{\\omega}_2 - (\\lambda_3 - \\lambda_1)\\omega_1\\omega_3\\]\n\\[\\Gamma_3 = \\lambda_3\\dot{\\omega}_3 - (\\lambda_1 - \\lambda_2)\\omega_1\\omega_2\\]\nIn this case, we have that $\\omega_3$ along $\\v{v}_3$ is zero (from the previous problem) and that the time derivatives of all of the $\\omega_i$s are zero (as the dumbell rotates at constant velocity. From this we get:\n\\[\\Gamma_1 = 0\\]\n\\[\\Gamma_2 = 0\\]\n\\[\\Gamma3 = 2m(a^2 + l^2)\\omega^2\\sin\\theta\\cos\\theta\\]\n\\end{s}\nCosnider the body frame aligned with the principle axes of inertia.  In this frame, the torque is constant in the 3 directions (out of the page). How can you describe the torque in the space frame?\n\\begin{s}\nSince $\\v{L}$ is rotating and $\\bm{\\Gamma}$ is perpendicular to this and rotating with it (in the lab frame), we therefore have that $\\abs{\\bm{\\Gamma}}$ is constant and it is rotating about the z axis.\n\\end{s}\nWhat is the angular momentum in the body frame?\n\\begin{s}\n$\\v{L} = \\II\\bm{\\omega}$, and since $\\II$ is diagonal in the body frame, we have:\n\\[\\v{L} = \\II\\bm{\\omega} = \\m{0 & 0 & 0 \\\\ 0 & 2m(a^2+l^2) & 0 \\\\ 0 & 0 & 2m(a^2 + l^2)}\\m{\\omega\\cos\\theta \\\\ \\omega\\sin\\theta \\\\ 0} = \\m{0 \\\\ 2m(a^2+l^2)\\omega\\sin\\theta \\\\ 0}\\]\n\\end{s}\n\n\\subsubsection{Free Rotation of symmetric top}\nHere, we study the motion of a symmetric top. This means that $\\lambda_1 = \\lambda_2$. In addition, no torque, so $\\bm{\\Gamma} = \\v{0}$. Writing down the Euler equations (where the LHS will be zero), we then have:\n\\[0 = \\lambda_1\\dot{\\omega}_1 - (\\lambda_2 - \\lambda_3)\\omega_2\\omega_3\\]\n\\[0 = \\lambda_2\\dot{\\omega}_2 - (\\lambda_3 - \\lambda_1)\\omega_1\\omega_3\\]\n\\[0 = \\lambda_3\\dot{\\omega}_3 - (\\lambda_1 - \\lambda_2)\\omega_1\\omega_2\\]\nSince $\\lambda_1 - \\lambda_2 = 0$, we therefore find that $\\dot{\\omega}_3 = 0$ and hence $\\omega_3$ is constant (as lines up with our experience. Writing the other equations down (making the substitution that $\\lambda_2 = \\lambda_1$, we have:\n\\[\\dot{\\omega}_1 = \\frac{\\lambda_1 - \\lambda_3}{\\lambda_1}\\omega_2\\omega_3\\]\n\\[\\dot{\\omega}_2 = -\\frac{\\lambda_1 - \\lambda_3}{\\lambda_1}\\omega_1\\omega_3\\]\nLet us define $\\Omega_b = \\frac{\\lambda_1 - \\lambda_3}{\\lambda_1}\\omega_3$, then we have:\n\\[\\dot{\\omega}_1 = \\Omega_b\\omega_2\\]\n\\[\\dot{\\omega}_2 = -\\Omega_b\\omega1\\]\nLet us add $i$ times the second equation to the first equation. Then, define $\\eta = \\omega_1 + i\\omega_2$. We then have:\n\\[\\dot{\\omega}_1 + i\\dot{\\omega}_2 = \\dot{\\eta} = \\Omega_b(\\omega_2 - i\\omega_1) = -i\\Omega_b\\eta\\]\nThis has a complex exponential solution:\n\\[\\eta(t) = \\eta_0\\exp(-i\\Omega_b t)\\]\nSuppose $\\eta_0 = \\omega_0$. then:\n\\[\\eta(t) = \\omega_0\\exp(-i\\Omega_b t)\\]\nTakign the real and imaginary parts to recover $\\omega_1$ and $\\omega_2$, we get:\n\\[\\bm{\\omega} = \\m{\\omega_0\\cos(\\Omega_b t) \\\\ -\\omega_0\\sin(\\Omega_b t) \\\\ \\omega_3}\\]\nFrom which we can see tha the free top undergoes precession. We can check that $\\dot{bm{\\omega}} = \\bm{\\Omega}_b \\times \\bm{\\omega}$ which would indeed correspond to rotation. We note that $\\abs{\\bm{\\omega}}$ is a constant here. Visually, we could think of these as follows:\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img4.png}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img5.png}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img6.png}\n\\end{center}\n\n\\subsubsection{Rotation Matrices}\nWe need to establish a more systematic way to go from body to lab frame (i.e. rotating the coordinate system). \n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img7.png}\n\\end{center}\nThese rotations are performed through rotation matrices. The first picture is a rotation around the z axis. The matrix that does this is\n\\[R_z = \\m{\\cos\\theta & \\sin\\theta & 0 \\\\ -\\sin\\theta & \\cos\\theta & 0 \\\\ 0 & 0 & 1}\\]\nThe second picture is a rotation around the y axis. The matrix that does this is:\n\\[R_y = \\m{\\cos\\theta & 0 & -\\sin\\theta \\\\ 0 & 1 & 0 \\\\ \\sin\\theta & 0 & \\cos\\theta}\\]\nWhere the minus sign is switched in order to preserve the handedness of the coordinate system. X is the same, with:\n\\[R_x = \\m{1 & 0 & 0 \\\\ 0 & \\cos\\theta & \\sin\\theta \\\\ 0 & -\\sin\\theta & \\cos\\theta}\\]\nIn general, to go from one coordinate system to another, we can decompose the rotations into rotations about x, y, and z. But note that the \\textbf{order matters}! This brings us to discussion of Euler angles.\n\n\\subsubsection{Euler Angles}\nThe Euler angles gives us a convention for the order of rotations.\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-20/l20-img8.png}\n\\end{center}\n\\begin{enumerate}[1.]\n\\item First, we rotate around the z-axis by $\\phi$.\n\\item Next, we rotate around the \\textbf{new} y axis by $\\theta$\n\\item Finally, we rotate around the \\textbf{new} z-axis by $\\psi$.\n\\end{enumerate}\nNext day: A general Lagrangian for rigid systems, and then applying this to a spinning top with Torque applied to it. Then, we get into Hamiltonian mechanics!\n\\end{document}", "meta": {"hexsha": "0113583ec06a2d6e6d319e4947313ed09566a8fb", "size": 6499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-20/Lecture-Notes-20.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-20/Lecture-Notes-20.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-20/Lecture-Notes-20.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": 65.6464646465, "max_line_length": 323, "alphanum_fraction": 0.7025696261, "num_tokens": 2124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6016472154659832}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Proofs}\n\nWe'll start by learning about the various kinds of proofs that we'll encounter in this class.\\footnote{This section in taken almost verbatim from \\url{http://zimmer.csufresno.edu/~larryc/proofs/proofs.html}.}\n\nProofs are the heart of mathematics. You must come to terms with proofs -- you must be able to read, understand\nand write them. What is the secret? What magic do you need to know? The short answer is: there is no secret, no\nmystery, no magic. All that is needed is some common sense and a basic understanding of a few trusted and easy\nto understand techniques.\n\n\\subsection*{The Structure of a Proof}\nThe basic structure of a proof is easy: it is just a series of statements, each one being either\n\\begin{itemize}\n\t\\item\n\tAn assumption or\n\t\\item\n\tA conclusion, clearly following from an assumption or previously proved result\n\\end{itemize}\nAnd that is all. Occasionally there will be the clarifying remark, but this is just for the reader and has no logical\nbearing on the structure of the proof.\n\nA well written proof will flow. That is, the reader should feel as though they are being taken on a ride that takes\nthem directly and inevitably to the desired conclusion without any distractions about irrelevant details.\n\nEach step\nshould be clear or at least clearly justified. A good proof is easy to follow.\nWhen you are finished with a proof, apply the above simple test to every sentence: is it clearly\n\\begin{enumerate}\n\t\\item an assumption\n\t\\item a justified conclusion?\n\\end{enumerate}\nIf the sentence fails the test, maybe it doesn't belong in the proof.\n\n\n\\subsection*{Example}\nIn order to write proofs, you must be able to read proofs. See if you can follow the proof below. Don't worry\nabout how you would have (or would not have) come up with the idea for the proof. Read the proof with an eye\ntowards the criteria listed above. Is each sentence clearly an assumption or a conclusion? Does the proof flow?\nWas the theorem in fact proved?\n\n\\begin{theorem}\n\t\\label{theorem:irrationality_of_sqrt2}\n\t The square root of 2 is an irrational number.\n\\end{theorem}\n\\begin{proof}\n\tLet's represent the square root of 2 by $s$. Then, by definition, $s$ satisfies the equation\n\t\\begin{align*}\n\t\ts^2 = 2.\n\t\\end{align*}\n\tIf $s$ were a rational number, then we could write $s = p/q$\nwhere $p$ and $q$ are a pair of integers. In fact, by dividing out the common multiple if necessary, we may even assume $p$ and $q$ have no common multiple (other than 1). If we now substitute this into the first equation we obtain, after a little algebra, the equation\n\\begin{align*}\n\t\tp^2 = 2 q^2.\n\\end{align*}\n\nBut now, 2 must appear in the prime factorization of the number $p^2$ (since it appears in the same number $2 q^2$). Since 2 itself is a prime number, 2 must then appear in the prime factorization of the number $p$. But then, $2 \\cdot 2$ would appear in the prime factorization of $p^2$, and hence in $2 q^2$. By dividing out a 2, it then appears that 2 is in the prime factorization of $q^2$. Like before (with $p^2$) we can now conclude 2 is a prime factor of $q$. But now we have $p$ and $q$ sharing a prime factor, namely 2. This violates our assumption above (see if you can find it) that $p$ and $q$ have no common multiple other than 1.\n\\end{proof}\n\n\\subsection{Direct Proofs}\nMost theorems that you want to prove are either explicitly or implicitly in the form \\begin{align*}\n\t\\mbox{ ``If \\textit{P}, then \\textit{Q}\". }\n\\end{align*} This is the standard form of a\ntheorem (though it can be disguised). A direct proof should be thought of as a flow of implications beginning\nwith \\textit{P} and ending with \\textit{Q}.\n\t\\begin{align*}\n\t\t{P} \\implies \\dots \\implies {Q}\n\t\\end{align*}\nMost proofs are (and should be) direct proofs. Always try direct proof first, unless you have a good reason not to. If you find a simple proof, and you are convinced of its correctness, then don't be shy about. Many times proofs\nare simple and short.\n\n\\begin{exercise}\n\t\\label{question:ex1}\n\tProve each of the following.\n\t\\begin{enumerate}\n\t\t\\item If $a$ divides $b$ and $a$ divides $c$ then $a$ divides $b + c$, where $a$, $b$, and $c$ are positive integers.\n\t\t\\item For all real numbers $a$ and $b$, $a^2 + b^2 \\ge 2 a b$.\n\t\t\\item If $a$ is a rational number and $b$ is a rational number, then $a+b$ is a rational number.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\n\\subsection{Proof by Contradiction}\n\\label{section:proofByContradiction}\nIn a proof by contradiction we assume, along with the hypotheses, the logical negation of the result we wish to\nprove, and then reach some kind of contradiction. That is, if we want to prove ``If \\textit{P}, then \\textit{Q}'', we assume \\textit{P} and\nNot \\textit{Q}. The contradiction we arrive at could be some conclusion contradicting one of our assumptions, or\nsomething obviously untrue like 1 = 0. The proof of Theorem \\ref{theorem:irrationality_of_sqrt2} is an example of this.\n\n\\begin{exercise}\n\t\\label{question:ex2}\n\tUse the method of Proof by Contradiction to prove each of the following.\n\t\\begin{enumerate}\n\t\t\\item The cube root of 2 is irrational.\n\t\t\\item If $a$ is a rational number and $b$ is an irrational number, then $a+b$ is an irrational number.\n\t\t\\item There are infinitely many prime numbers.\\footnote{There are dozens of proofs of this theorem, originally due to Euclid. Feel free to look one up online.}\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\n\n\\subsection{Proof by Contrapositive}\n\\label{section:proofByContrapositive}\n\tProof by contrapositive takes advantage of the logical equivalence between ``\\textit{P} implies \\textit{Q}'' and ``Not \\textit{Q} implies Not \\textit{P}''. For example, the assertion ``If it is my car, then it is red'' is equivalent to ``If that car is not red, then it is not mine''. So, to prove ``If \\textit{P}, then \\textit{Q}'' by the method of contrapositive means to prove\n\t\\begin{align*}\n\t\t\\mbox{``If Not \\textit{Q}, then Not \\textit{P}''.}\n\t\\end{align*}\n\n\\noindent \\textbf{How Is This Different From Proof by Contradiction?}\nThe difference between the Contrapositive method and the Contradiction method is subtle. Let's examine how the two methods work when trying to prove ``If \\textit{P}, then \\textit{Q}\".\n\\begin{description}\n\t\\item[Method of Contradiction:] Assume \\textit{P} and Not \\textit{Q} and prove some sort of contradiction.\n\t\\item[Method of Contrapositive:] Assume Not \\textit{Q} and prove Not \\textit{P}.\n\\end{description}\nThe method of Contrapositive has the advantage that your goal is clear: Prove Not P. In the method of Contradiction, your goal is to prove a contradiction, but it is not always clear what the contradiction is going to be at the start.\n\n\\begin{exercise}\n\t\\label{question:ex3}\n\tUse the method of Proof by Contrapositive to prove each of the following.\n\t\\begin{enumerate}\n\t\t\\item If the product of two integers is even, then at least one of the two must be even.\n\t\t\\item If the product of two integers is odd, then both must be odd.\n\t\t\\item If the product of two real numbers is an irrational number, then at least one of the two must be an irrational number.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\subsection{Converse}\nThe converse of an assertion in the form ``If \\textit{P}, then \\textit{Q}\" is the assertion\n\\begin{align*}\n\t\\mbox{``If \\textit{Q}, then \\textit{P}\"}.\n\\end{align*}\nA common logical fallacy is to assume that if an assertion is true then so is its converse.\n\n\n\\subsubsection{If and Only If}\nMany theorems are stated in the form ``\\textit{P}, if, and only if, \\textit{Q}\". Another way to say the same thing is: ``\\textit{Q} is necessary, and sufficient for \\textit{P}\". This means two things:\n\\begin{center}\n\t``If \\textit{P}, Then \\textit{Q}\" \\qquad and \\qquad ``If \\textit{Q}, Then \\textit{P}\".\n\\end{center} So to prove an ``If, and Only If\" theorem, you must prove the theorem and also its \\textit{converse}.\n\n\\begin{exercise}\n\tGo back to the problems in Exercises \\ref{question:ex1}, \\ref{question:ex2}, \\ref{question:ex3} and find the ones which are of the form ``If \\textit{P}, Then \\textit{Q}\". For each of these:\n\t\\begin{itemize}\n\t\t\\item State the converse.\n\t\t\\item Prove or disprove the converse (by providing either a proof or a counterexample).\n\t\t\\item For the problems where the converse is also true rewrite the assertion as an \"If, and Only If\" statement.\n\t\\end{itemize}\n\\end{exercise}\n\n\n\n\n\n\n\n\n\\subsection{Quantifiers}\nIt is extremely important in mathematics to be able to formulate very precise statements. To prevent ambiguous statements and logical fallacies the vocabulary used is very limited and every term has a well-defined meaning. The two concepts we need to get used to are {\\it logical operators} and {\\it quantifiers}.\\\\\n\n{\\bf Logical Operators:} Operators allow us to form complex statements by combining simpler ones. The basic logical operators are {\\it and}, {\\it or}, and {\\it not}. Their usage is the same as in everyday language. The more complicated logical operator that we'll be using a lot is {\\it If - then -}. We've already encountered several examples of its usage in the previous sections.\\\\\n\n\n{\\bf Quantifiers:} Quantifiers allow us to make abstract statements which are ``universally true'' without having to specify a concrete element. There are two commonly used\tquantifiers:\n\\begin{align*}\n\t\\mbox{\\textbf{For all/every}} && \\mbox{\\textbf{There exists}}\n\\end{align*}\nUnderstanding and formulating complex statements using these requires a lot of practice. You'll get used to these as the course progresses. Here are a few examples,\n\\begin{example}$ $\n\t\\begin{enumerate}\n\t\t\\item \\emph{For every} odd integer $a$, the integer $a+1$ is even.\n\t\t\\item An integer $a$ is even if and only if \\emph{there exists} an integer $b$ such that $a = 2b$.\n\t\t\\item There \\emph{do not exist} integers $p,q$ such that $\\frac{p}{q} = \\sqrt{2}$.\n\t\t\\item \\emph{For every} non-zero rational number $x$ \\emph{there exists} a rational number $y$ such that $x \\cdot y = 1$.\n\t\\end{enumerate}\n\\end{example}\n\n\\subsubsection{Nesting Quantifiers}\n\tWhen dealing with statements involving multiple quantifiers the order really matters; changing the order changes the meaning of a statement completely. When you're using multiple quantifiers in a single sentence you should always pause and check if you're using the right quantifiers in the right order.\n\n\\begin{exercise}\n\tFor each of the following pairs, explain how changing the order of the quantifiers changes the meaning of the statement.\\footnote{It's ok to a bit vague in your answers to this question.}\n\t\\begin{enumerate}\n\t\t\\item \\begin{enumerate}\n\t\t\t\\item \\emph{For every} even integer $a$ \\emph{there exists} an integer $b$ such that $a = 2b$.\n\t\t\t\\item \\emph{There exists} an integer $b$ such that \\emph{for every} even integer $a$, $a = 2b$.\n\t\t\\end{enumerate}\n\t\t\\item \\begin{enumerate}\n\t\t\t\\item \\emph{For every} positive integer $n$ \\emph{there exists} a positive real number $\\epsilon$ such that $ \\epsilon < 1/n$.\n\t\t\t\\item \\emph{There exists} a positive real number $\\epsilon$ such that \\emph{for every} positive integer $n$, $ \\epsilon < 1/n$.\\footnote{Such an $\\epsilon$ is called an {\\bf infinitesimal}.\tThere are number systems, for example the \\textbf{hypperreal numbers}, which extend the real numbers by incorporating infinitesimals.}\n\t\t\\end{enumerate}\n\t\t\\item \\begin{enumerate}\n\t\t\t\\item \\emph{For every} even integer $a$, \\emph{for every} odd integer $b$, $a + b$ is odd.\n\t\t\t\\item \\emph{For every} odd integer $b$, \\emph{for every} even integer $a$, $a + b$ is odd.\n\t\t\t\\end{enumerate}\n\t\t\\item Let $f: \\R \\rightarrow \\R$ be a function and let $\\epsilon$ be a positive real number. \\begin{enumerate}\n\t\t\t\\item {\\it For every} $x$, {\\it there exists} a $\\delta > 0$ such that {\\it for every} $y$, if $|x-y| < \\delta$ then $|f(x) - f(y)| < \\epsilon$.\n\t\t\t\\item {\\it There exists} a $\\delta > 0$ such that {\\it for every} $x$, {\\it for every} $y$, if $|x-y| < \\delta$ then $|f(x) - f(y)| < \\epsilon$.\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{exercise}\n\n\t\\subsubsection{Negating Nested Quantifiers}\n\tAs we saw in Sections \\ref{section:proofByContradiction} and \\ref{section:proofByContrapositive} we often need to negate mathematical statements.\n\n\tIn order to systematically negate complicated logical expressions, we observe that we can negate simple statements in the following manner. (These are called {\\it De Morgan's laws}.)\n\t\\begin{center}\n\t\t\\begin{tabular}{|p{0.475\\textwidth}|p{0.475\\textwidth}|}\n\t\t\t\\hline Statement\n\t\t\t\t&\n\t\t\t\t\tNegation \\\\ \\hline & \\\\\n\t\t\tFor every $x$ the statement $P$ is true.\n\t\t\t\t&\n\t\t\t\t\tThere exists an $x$ such that the statement $P$ is false.\n\t\t\t\t\t\\\\& \\\\ \\hline &\\\\\n\t\t\tThere exists an $x$ such that the statement $P$ is true.\n\t\t\t\t&\n\t\t\t\t\tFor every $x$ the statement $P$ is false.\n\t\t\t\t\t\\\\& \\\\ \\hline &\\\\\n\t\t\t$P$ is true and $Q$ is true\n\t\t\t\t&\n\t\t\t\t\t$P$ is false or $Q$ is false.\n\t\t\t\t\t\\\\& \\\\ \\hline &\\\\\n\t\t\t$P$ is true or $Q$ is true\n\t\t\t\t&\n\t\t\t\t\t$P$ is false and $Q$ is false.\n\t\t\t\t\t\\\\& \\\\ \\hline &\\\\\n\t\t\tIf $P$ then $Q$\n\t\t\t\t&\n\t\t\t\t\t$P$ but not $Q$.\n\t\t\t\t\t\\\\& \\\\ \\hline\n\t\\end{tabular}\n\t\\end{center}\n\tIf we have multiple quantifiers in a statement then we start with the outermost quantifier and recursively move inwards.\n\t\\begin{example}\n\t\tThe negation of {\\it ``For every $x$, there exits a $y$ such that, the statement $P$ is true''} equals {\\it ``There exists an $x$ such that, for every $y$, the statement $P$ is false.''}\n\t\\end{example}\n\t\\begin{exercise} Negate each of the following.\n\t\t\\begin{enumerate}\n\t\t\t\\item \\emph{For every} even integer $a$ \\emph{there exists} an integer $b$ such that $a = 2b$.\n\t\t\t\\item \\emph{There exists} an integer $b$ such that \\emph{for every} even integer $a$, $a = 2b$.\n\t\t\t\\item \\emph{For every} positive integer $n$ \\emph{there exists} a positive real number $\\epsilon$ such that $ \\epsilon < 1/n$.\n\t\t\t\\item \\emph{There exists} a positive real number $\\epsilon$ such that \\emph{for every} integer $n$, $ \\epsilon < 1/n$.\n\t\t\t\\item \\emph{For every} even integer $a$, \\emph{for every} odd integer $b$, $a + b$ is odd.\n\t\t\t\\item {\\it For every} $\\epsilon > 0$, {\\it for every} $x$, {\\it there exists} a $\\delta > 0$ such that {\\it for every} $y$, if $|x-y| < \\delta$ then $|f(x) - f(y)| < \\epsilon$.\n\t\t\t\\item {\\it For every} $\\epsilon > 0$, {\\it there exists} a $\\delta > 0$ such that {\\it for every} $x$, {\\it for every} $y$, if $|x-y| < \\delta$ then $|f(x) - f(y)| < \\epsilon$.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\n\t\\noindent {\\bf Word of caution:} When the word ``and'' is used in a list it is not considered a logical operator (this is a deficiency of the English language). For example, negating the following expression\n\t\\begin{center}\n\t\t\\emph{For every} even integer $a$ and \\emph{for every} odd integer $b$, $a + b$ is odd,\n\t\\end{center}\n\tdoes not change the {\\it and} to an {\\it or} (what happens if you do change the {\\it and} to an {\\it or}?).\n", "meta": {"hexsha": "642ce3e095968869f526dd536642326dcf6a23b3", "size": 14846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/01Proofs.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/01Proofs.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/01Proofs.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": 57.766536965, "max_line_length": 643, "alphanum_fraction": 0.7189815439, "num_tokens": 4301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.8947894583870631, "lm_q1q2_score": 0.6015953169650872}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\hyphenation{DCPVAL DMDVAL}\n\\begmath 11.2 Evaluation, Integration, and Differentiation of Polynomials\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis set of subroutines will evaluate, integrate, or differentiate\npolynomials. The polynomials may be represented by coefficients relative to\neither the monomial or Chebyshev basis. The data structure and\nparameterization used to represent a polynomial is the same as that used by\nthe least-squares polynomial curve fit subroutines described in Chapter~11.1.\nSpecial procedures for evaluation of polynomials expressed using the\nLegendre and Laguerre bases are described in Chapters~2.11 and~2.12\nrespectively.\n\n\\subsection{Usage}\n\n\\subsubsection{Usage for Evaluation}\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NDEG}\n\n\\item[REAL]  \\ {\\bf P}$(\\geq $NDEG+3){\\bf , X, Y, SCPVAL, SMPVAL}\n\\end{description}\nAssign values to NDEG, X, and P($i$), $i = 1$, NDEG$+3$. If the Chebyshev\nbasis is being used, use the statement:\n$$\n\\fbox{{\\bf Y = SCPVAL(P, NDEG, X)}}\n$$\nIf the monomial basis is being used, use the statement:\n$$\n\\fbox{{\\bf Y = SMPVAL(P, NDEG, X)}}\n$$\nFollowing the appropriate one of these two statements the value of the\npolynomial at the argument X will be stored in Y.\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[P()]  \\ [in] An array containing NDEG$+3$ parameters that define a\npolynomial as described in Section D.\n\n\\item[NDEG]  \\ [in] Degree of the polynomial.\n\n\\item[X]  \\ [in] Argument value at which the polynomial is to be evaluated.\n\n\\item[SCPVAL]  \\ [out] The value of the polynomial evaluated at X assuming\nthe Chebyshev basis representation.\n\n\\item[SMPVAL]  \\ [out] The value of the polynomial evaluated at X assuming\nthe monomial basis representation.\n\\end{description}\n\\subsubsection{Usage for Integration}\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NDEGA, NDEGB}\n\n\\item[REAL]  \\ {\\bf A}($\\geq $NDEGA+3){\\bf , B}($\\geq $NDEGA+4)\n\\end{description}\nAssign values to NDEGA and A($i$), $i = 1$, ..., NDEGA$+3$. If the Chebyshev\nbasis is being used, use the statement:\n$$\n\\fbox{{\\bf CALL SCPINT (A, NDEGA, B, NDEGB)}}\n$$\nIf the monomial basis is being used, use the statement:\n$$\n\\fbox{{\\bf CALL SMPINT (A, NDEGA, B, NDEGB)}}\n$$\nFollowing the appropriate one of these two call statements the results will\nbe stored in B() and NDEGB.\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[A()]  \\ [in] An array containing NDEGA$+3$ parameters that define the\ninput polynomial, say $p(x)$. See Section D for the specification of the\nparameterization.\n\n\\item[NDEGA]  \\ [in] Degree of the input polynomial, $p(x).$\n\n\\item[B()]  \\ [out] On return B() will contain NDEGB$+3$ parameters defining\nthe output polynomial, say $q(x)$, which is the indefinite integral of the\ninput polynomial $p(x)$. Mathematically the constant term of $q(x)$ is an\narbitrary constant of integration. This subroutine will set the constant\nterm, B($3)$, to zero. The storage locations occupied by A() and B() must be\ndistinct.\n\n\\item[NDEGB]  \\ [out] The subroutine sets NDEGB $= \\text{NDEGA}+1$ to indicate\nthe degree of the output polynomial. The storage locations occupied by NDEGA\nand NDEGB must be distinct.\n\\end{description}\n\\subsubsection{Usage for Differentiation}\n\n\\paragraph{Program Prototype, Single Precision}\n\\begin{description}\n\\item[INTEGER]  \\ {\\bf NDEGC, NDEGD}\n\n\\item[REAL]  \\ {\\bf C} $(\\geq $NDEGC+3){\\bf , D}($\\geq \\max(3,\\text{NDEGC}+2%\n))$\n\\end{description}\nAssign values to NDEGC and C($i$), $i = 1$, ..., NDEGC$+3$. If the Chebyshev\nbasis is being used, use the statement:\n$$\n\\fbox{{\\bf CALL SCPDRV (C, NDEGC, D, NDEGD)}}\n$$\nIf the monomial basis is being used, use the statement:\n$$\n\\fbox{{\\bf CALL SMPDRV (C, NDEGC, D, NDEGD)}}\n$$\nFollowing the appropriate one of these two call statements the results will\nbe stored in D() and NDEGD.\n\n\\paragraph{Argument Definitions}\n\\begin{description}\n\\item[C()]  \\ [in] An array containing NDEGC$+3$ parameters that define the\ninput polynomial, say $p(x)$. See Section D for the specification of the\nparameterization.\n\n\\item[NDEGC]  \\ [in] Degree of the input polynomial, $p(x).$\n\n\\item[D()]  \\ [out] On return D() will contain NDEGD$+3$ parameters defining\nthe output polynomial, say $q(x)$, which is the derivative of the input\npolynomial $p(x)$. The storage locations occupied by C() and D() must be\ndistinct.\n\\newpage\n\n\\item[NDEGD]  \\ [out] The subroutine sets NDEGD $=\\max (0$, NDEGC$-$1) to\nindicate the degree of the output polynomial. The storage locations occupied\nby NDEGC and NDEGD must be distinct.\n\\end{description}\n\\subsubsection{Usage for Double Precision Evaluation, Integration or\nDifferentiation}\n\nFor DOUBLE PRECISION usage change the REAL type statements to DOUBLE\nPRECISION and change the initial ``S'' of the function and subroutine names\nto a ``D.'' Note particularly that if the function names DCPVAL or DMPVAL\nare used they must be typed DOUBLE PRECISION either explicitly or via an\nIMPLICIT statement.\n\n\\subsection{Examples and remarks}\n\nLet a cubic polynomial $p(x)$ be defined relative to the Chebyshev basis as $%\np(x)=10+8T_1(u)+6T_2(u)+4T_3(u)$ where $u=(x-5)/2$. The DRSCPVAL program\ncomputes the indefinite integral of $p(x)$ calling it $q(x)$. This\ncomputation is checked by computing $r(x)$ as the derivative of $q(x)$. Note\nthat $r(x)$ agrees with $p(x)$. Finally the program evaluates the definite\nintegral%\n\\begin{equation*}\nz=\\int_4^6p(x)\\,dx=q(6)-q(4)=10\n\\end{equation*}\nThe output from this program is shown in ODSCPVAL.\n\n\\subsection{Functional Description}\n\nIn typical expected usage the polynomial parameter vector input to any of\nthe subprograms of this set will have been produced by the library curve\nfitting subroutine SPFIT (or DPFIT) or an integration or differentiation\nsubroutine of this set. The subprograms of this set are thus intended to\nlet the user do the operations of evaluation, integration or differentiation\nof polynomials without being concerned with the details of the parametric\nrepresentation of polynomials or algorithmic details.\n\nThe following description is provided for those who wish to know more of the\ninternal details.\n\nFor the purposes of this set of subprograms a polynomial of degree $n$, say $%\np(x)$, is represented by a set of $n+3$ parameters, say $a_1$, ..., $a_{n+3}$%\n. The first two parameters define a linear transformation of the independent\nvariable\n\\begin{equation*}\nu=(x-a_1)/a_2\n\\end{equation*}\nThe remaining $n+1$ parameters are coefficients of an $n^{th}$ degree\npolynomial in the transformed variable $u$. If the Chebyshev basis is used\nthis polynomial is%\n\\begin{equation*}\np(x)=q(u)=\\sum_{i=0}^na_{i+3}T_i(u)\n\\end{equation*}\nwhereas if the monomial basis is used the polynomial is%\n\\begin{equation*}\np(x)=q(u)=\\sum_{i=0}^na_{i+3}u^i\n\\end{equation*}\nThe Chebyshev polynomials $T_i(u)$ are defined by the equations%\n\\begin{gather*}\nT_0(u)=1,\\quad T_1(u)=u\\\\\nT_i(u)=2uT_{i-1}(u)-T_{i-2}(u),\\quad i=2,3,...\n\\end{gather*}\nThe formulas for differentiation and integration of polynomials expressed\nusing the Chebyshev basis may be derived from the following standard\nidentities:\n\\begin{align*}\n0&=dT_0(u)/du\\\\\nT_0(u)&=dT_1(u)/du\\\\\nT_1(u)&=\\frac 14 dT_2(u)/du\\\\\nT_i(u)&=\\frac 12\\frac d{du}\\left[ \\frac{T_{i+1}(u)}{i+1}-\n\\frac{T_{i-1}(u)}{i-1}\\right] ,\\quad i=2,3,...\n\\end{align*}\nThe algorithms used by this set of subprograms are specified as follows:\n\n\\subsubsection{Monomial Basis Evaluation, SMPVAL or DMPVAL}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $p_i$,\n$i=1$,\\ ..., $n+3$ and an argument $x$, compute $y=p(x).$%\n\\begin{align*}\nu&=(x-p_1)/p_2\\\\\nz_n&=p_{n+3}\\\\\nz_i&=u\\,z_{i+1}+p_{i+3},\\quad i=n-1,n-2,...,0\\\\\ny&=z_0.\n\\end{align*}\n\\subsubsection{Monomial Basis Integration, SMPINT or DMPINT}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $a_i$,\n$i=1$,\\ ..., $n+3$, compute the parameters $b_i$ that represent a polynomial\n$q$ that for arbitrary $u$ and $v$ satisfies%\n\\begin{equation*}\n\\int_u^vp(x)\\,dx=q(v)-q(u).\n\\end{equation*}\nThe formulas used are%\n\\begin{gather*}\nb_1=a_1,\\quad b_2=a_2,\\quad b_3=0\\\\\nb_{i+3}=a_2a_{i+2}/i,\\ \\ \\ \\ \\ i=1,...,n+1\n\\end{gather*}\n\\subsubsection{Monomial Basis Differentiation, SMPDRV or DMPDRV}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $c_i$,\n$i=1$,\\ ..., $n+3$, compute the parameters $d_i$ that represent the\npolynomial $q$ satisfying%\n\\begin{equation*}\n\\frac d{dx}p(x)=q(x).\n\\end{equation*}\nThe formulas used are%\n\\begin{gather*}\nd_1=c_1,\\quad d_2=c_2\\\\\nd_{i+3}=(i+1)c_{i+4}/c_2,\\quad i=0,...,n-1\n\\end{gather*}\nwith a special case of $d_3=0$ if $n=0.$\n\n\\subsubsection{Chebyshev Basis Evaluation, SCPVAL or DCPVAL}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $p_i$,\n$i=1$, ..., $n+3$ and an argument $x$ compute $y=p(x).$%\n\\begin{align*}\nu&=(x-p_1)/p_2\\\\\nz_n&=p_{n+3}\\\\\nz_{n-1}&=2uz_n+p_{n+2}\\\\\nz_i&=2uz_{i+1}-z_{i+2}+p_{i+3},\\quad i=n-2,...,1\\\\\ny&=uz_1-z_2+p_3\n\\end{align*}\n\\subsubsection{Chebyshev Basis Integration, SCPINT or DCPINT}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $a_i$,\n$i = 1, $..., $n+3$, compute the parameters $b_i$ that represent a\npolynomial $q$ that for arbitrary $u$ and $v$ satisfies%\n\\begin{equation*}\n\\int_u^vp(x)\\,dx=q(v)-q(u).\n\\end{equation*}\nThe formulas used are\n\\begin{gather*}\nb_1=a_1,\\quad b_2=a_2,\\quad b_3=0\\\\\nb_4=a_2\\left[ a_3-(1/2)a_5\\right]\\\\\nb_{i+3}=a_2(a_{i+2}-a_{i+4})/(2i),\\quad i=2,...,n+1,\n\\end{gather*}\nwhere $a_i$ for $i>n+3$ is taken to be zero.\n\n\\subsubsection{Chebyshev Basis Differentiation, SCPDRV or DCPDRV}\n\nGiven an $n^{th}$ degree polynomial $p$ represented by the parameters $c_i$,\n$i=1$, ..., $n+3$, compute the parameters $d_i$ that represent the\npolynomial $q$ satisfying%\n\\begin{equation*}\n\\frac d{dx}p(x)=q(x)\n\\end{equation*}\nThe formulas used are%\n\\begin{gather*}\nd_1=c_1,\\quad d_2=c_2\\\\\nd_{i+3}=2(i+1)c_{i+4}/c_2,\\quad i=n-1,n-2\\\\\nd_{i+3}=d_{i+5}+2(i+1)c_{i+4}/c_2,\\quad i=n-3,...,1\\\\\nd_3=d_5/2 + c_4 / c_2\n\\end{gather*}\nwith a special case of $d_3=0$ if $n=0.$\n\n\\subsection{Error Procedures and Restrictions}\n\nThe degree of the input polynomial must be zero or positive. If it is\nnegative the subprograms in this set will issue an error message\nusing the error processor in Chapter 19.2 at level 0 and\nreturn.\n\nThe given values of P($2)$, A(2), and C($2)$ must be nonzero.  These\nconditions are not tested.\n\nThe storage locations for the input quantities in the integration and\ndifferentiation subroutines must be distinct from the storage locations for\nthe output quantities.\n\nSince DCPVAL and DMPVAL are FUNCTION type subprograms, their names must be\ntyped DOUBLE PRECISION in any program that uses them.\n\n\\subsection{Supporting Information}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDCPDRV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCPDRV, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDCPINT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCPINT, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDCPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDCPVAL\\rule[-5pt]{0pt}{8pt}}\\\\\nDMPDRV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDMPDRV, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDMPINT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDMPINT, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nDMPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDMPVAL\\rule[-5pt]{0pt}{8pt}}\\\\\nSCPDRV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SCPDRV\\rule[-5pt]{0pt}{8pt}}\\\\\nSCPINT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SCPINT\\rule[-5pt]{0pt}{8pt}}\\\\\nSCPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSCPVAL\\rule[-5pt]{0pt}{8pt}}\\\\\nSMPDRV & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SMPDRV\\rule[-5pt]{0pt}{8pt}}\\\\\nSMPINT & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SMPINT\\rule[-5pt]{0pt}{8pt}}\\\\\nSMPVAL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nSMPVAL}\\\\\n\\end{tabular}\n\nThe source language is Fortran~77.\n\nDesigned by C. L. Lawson, JPL, 1970. Programmed by Lawson and D. Campbell,\nJPL, 1970. Adapted to Fortran~77 by Lawson and S. Y. Chiu, JPL, 1984.\n\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSCPVAL}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{scpval}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSCPVAL}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{scpval}}\n\\end{document}\n", "meta": {"hexsha": "dfac41cd9106081a9c61c98162b6768cbd56ff22", "size": 12894, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch11-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/ch11-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/ch11-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.735042735, "max_line_length": 98, "alphanum_fraction": 0.7224290368, "num_tokens": 4374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6015726789115959}}
{"text": "\\chapter{Principal Component Analysis}\n\\label{ch:pca}\n\nWhich of the following three scatter plots (showing x vs. y, x vs. z and y vs. z) for the same three-dimensional data gives us the best picture about the actual layout of the data in space?\n\n\\begin{figure*}[h]\n    \\centering\n    \\includegraphics[scale=0.25]{pca1.png}\n    \\hspace{0.5cm}\n    \\includegraphics[scale=0.25]{pca2.png}\n    \\hspace{0.5cm}\n    \\includegraphics[scale=0.25]{pca3.png}\n    \\caption{$\\;$}\n\\end{figure*}\n\nYes, the first scatter plot looks very useful: it tells us that x and y are highly correlated and that we have three clusters of somewhat irregular shape. But remember: this data is three dimensional. What is we saw it from another, perhaps better perspective?\n\nLet's make another experiment. Go to \\url{https://in-the-sky.org/ngc3d.php}, disable Auto-rotate and Show labels and select Zoom to show Local Milky Way. Now let's rotate the picture of the galaxy to find the layout of the stars.\n\nThink about what we've done. What are the properties of the best projection?\n\n% not the best example, but couldn't reproduce the original\n\\begin{wrapfigure}{o}{0.8\\textwidth}\n    \\includegraphics[scale=0.4]{pca-3d.png}\n    \\label{fig:pca3d}\n\\end{wrapfigure}\n\nWe want the data to be as spread out as possible. If we look from the direction parallel to the galactic plane, we see just a line. We lose one dimension, essentially keeping just a single coordinate for each star. (This is unfortunately exactly the perspective we see on the night sky: most stars are in the bright band we call the milky way, and we only see the outliers.) Among all possible projections, we attempt to find the one with the highest spread across the scatter plot. This projection may not be (and usually isn't) orthogonal to any axis; it may be a projection to an arbitrary plane.\n\n\\clearpage\n\\newpage\n\nWe again talk about two dimensional projection only for the sake of illustration. Imagine that we have ten thousand dimensional data and we would like, for some reason, keep just ten features. Yes, we can rank the features and keep the most informative, but what if these are correlated and tell us the same thing? Or what if our data does not have any target variable: with what should the \"good features\" be correlated? And what if the optimal projection is not aligned with the axes at all, so \"good\" features are combinations of the original ones?\n\nWe can do the same reasoning as above: we want to find a 10-dimensional (for the sake of examples) projection in which the data  points are as spread as possible.\n\nHow do we do this? Let's go back to our everyday's three dimensional world and think about how to find a two-dimensional projection.\n\nImagine you are observing a swarm of flies; your data are their exact coordinates in the room, so the position of each fly is described by three numbers. Then you discover that your flies actually fly in a formation: they are (almost) on the same line. You could then describe the position of each fly with a single number that represents the fly's position along the line. Plus, you need to know where in the space the line lies. We call this line the first principal component. By using it, we reduce the three-dimensional space into a single dimension.\n\nAfter some careful observation, you notice the flies are a bit spread in one other direction, so they do not fly along a line but along a band. Therefore, we need two numbers, one along the first and one along the — you guessed it — second principal component.\n\nIt turns out the flies are actually also spread in the third direction. Thus you need three numbers after all.\n\nOr do you? It all depends on how spread they are in the second and in the third direction. If the spread along the second is relatively small in comparison with the first, you are fine with a single dimension. If not, you need two, but perhaps still not three.\n\nLet's step back a bit: why would one who carefully measured expressions of ten thousand genes want to throw most data away and reduce it to a dozen dimensions? The data, in general, may not and does not have as many dimensions as there are features. Say you have an experiment in which you spill different amounts of two chemicals over colonies of amoebas and then measure the expressions of 10.000 genes. Instead of flies in a three-dimensional space, you now profile colonies in a 10,000-dimensional space, the coordinates corresponding to gene expressions. Yet if expressions of genes depend only on the concentrations of these two chemicals, you can compute all 10,000 numbers from just two. Your data is then just two-dimensional.\n\n\\newpage\n\nA technique that does this is called Principle Components Analysis, or \\widget{PCA}. The corresponding widget is simple: it receives the data and outputs the transformed data.\n\n\\begin{wrapfigure}{o}{0.6\\textwidth}\n    \\includegraphics[width=\\linewidth]{workflow-scatterplot.png}\n    \\label{fig:wf1}\n\\end{wrapfigure}\n\nThe widget allows you to select the number of components and helps you by showing how much information (technically: explained variance) you retain with respect to the number of components (brownish line) and the amount of information (explained variance) in each component.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{pca-scree.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nThe PCA on the left shows the scree diagram for brown-selected data. Set like this, the widget replaces the 80 features with just seven - and still keeping 82.7\\% of information. (Note: disable \"Normalize data\" checkbox to get the same picture.) Let us see a scatter plot for the first two components.\n\n\\begin{figure}[h!]\n    \\centering\n    \\includegraphics[width=\\linewidth]{scatterplot-gray.png}\n    \\caption{$\\;$}\n\\end{figure}\n\n\\newpage\n\nThe axes, PC1 and PC2, do not correspond to particular features in the original data, but to their linear combination. What we are looking at is a projection onto the plane, defined by the first two components. When you consider only two components, you can imagine that PCA puts a hyperplane into multidimensional space and projects all data into it.\n\nNote that this is an unsupervised method: it does not care about the class. The classes in the projection may be well separated or not. Let's add some colors to the points and see how lucky we are this time.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{scatterplot-color.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nThe data separated so well that these two dimensions alone may suffice for building a good classifier. No, wait, it gets even better. The data classes are separated well even along the first component. So we should be able to build a classifier from a single feature!\n\n\\begin{figure*}[h]\n    \\centering\n    \\newcommand{\\wf}{\\includegraphics[scale=0.6]{workflow-testandscore.png}}\n    \\newcommand{\\distrib}{\\includegraphics[scale=0.6]{distributions.png}}\n    \\infinitewidthbox{\n    \\stackinset{r}{-0.4\\linewidth}{t}{+0.00\\linewidth}{\\distrib}{\\wf}\\hspace{8cm}\n    }\n\\end{figure*}\n\n\\newpage\n\nIn the above schema we uses the ordinary Test and Score widget, but renamed it to \"Test on original data\" for better understanding of the workflow.\n\nOn the original data, logistic regression gets 98\\% AUC and classification accuracy. If we select just a single component in PCA, we already get a 93\\%, and if we take two, we get the same result as on the original data.\n\nPCA is thus useful for multiple purposes. It can simplify our data by combining the existing features to a much smaller number of features without losing much information. The directions of these features may tell us something about the data. Finally, it can find us good two-dimensional projections that we can observe in scatter plots.\n", "meta": {"hexsha": "c203dcda888df6ae7fd22e3a4a8eab1aa43c3c30", "size": 7789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/014-pca/pca.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/014-pca/pca.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/014-pca/pca.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": 74.8942307692, "max_line_length": 735, "alphanum_fraction": 0.7726280652, "num_tokens": 1803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542925, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.601572678473296}}
{"text": "%!TEX root = main.tex\n\\section{Introduction}\nArtificial neural networks have dozends of hyperparameters which influence\ntheir behaviour during training and evaluation time. One parameter is the\nchoice of activation functions. While in principle every neuron could have a\ndifferent activation function, in practice networks only use two activation\nfunctions: The softmax function for the output layer in order to obtain a\nprobability distribution over the possible classes and one activation function\nfor all other neurons.\n\nActivation functions should have the following properties:\n\\begin{itemize}\n    \\item \\textbf{Non-linearity}: A linear activation function in a simple feed\n          forward network leads to a linear function. This means no matter how\n          many layers the network uses, there is an equivalent network with\n          only the input and the output layer. Please note that \\glspl{CNN} are\n          different. Padding and pooling are also non-linear operations.\n    \\item \\textbf{Differentiability}: Activation functions need to be\n          differentiable in order to be able to apply gradient descent. It is\n          not necessary that they are differentiable at any point. In practice,\n          the gradient at non-differentiable points can simply be set to zero\n          in order to prevent weight updates at this point.\n    \\item \\textbf{Non-zero gradient}: The sign function is not suitable for\n          gradient descent based optimizers as its gradient is zero at all\n          differentiable points. An activation function should have infinitely\n          many points with non-zero gradient.\n\\end{itemize}\n\nOne of the simplest and most widely used activation functions for \\glspl{CNN}\nis \\gls{ReLU}~\\cite{AlexNet-2012}, but others such as\n\\gls{ELU}~\\cite{clevert2015fast}, \\gls{PReLU}~\\cite{he2015delving}, softplus~\\cite{7280459}\nand softsign~\\cite{bergstra2009quadratic} have been proposed.\n\nActivation functions differ in the range of values and the derivative. The\ndefinitions and other comparisons of eleven activation functions are given\nin~\\cref{table:activation-functions-overview}.\n\n\n\\section{Important Differences of Proposed Activation Functions}\nTheoretical explanations why one activation function is preferable to another\nin some scenarios are the following:\n\\begin{itemize}\n    \\item \\textbf{Vanishing Gradient}: Activation functions like tanh and the\n          logistic function saturate outside of the interval $[-5, 5]$. This\n          means weight updates are very small for preceding neurons, which is\n          especially a problem for very deep or recurrent networks as described\n          in~\\cite{bengio1994learning}. Even if the neurons learn eventually,\n          learning is slower~\\cite{AlexNet-2012}.\n    \\item \\textbf{Dying ReLU}: The dying \\gls{ReLU} problem is similar to the\n          vanishing gradient problem. The gradient of the \\gls{ReLU} function\n          is~0 for all non-positive values. This means if all elements of the\n          training set lead to a negative input for one neuron at any point in\n          the training process, this neuron does not get any update and hence\n          does not participate in the training process. This problem is\n          addressed in~\\cite{maas2013rectifier}.\n    \\item \\textbf{Mean unit activation}: Some publications\n          like~\\cite{clevert2015fast,BatchNormalization-2015} claim that mean\n          unit activations close to 0 are desirable. They claim that this\n          speeds up learning by reducing the bias shift effect. The speedup\n          of learning is supported by many experiments. Hence the possibility\n          of negative activations is desirable.\n\\end{itemize}\n\nThose considerations are listed\nin~\\cref{table:properties-of-activation-functions} for 11~activation functions.\nBesides the theoretical properties, empiric results are provided\nin~\\cref{table:CIFAR-100-accuracies-activation-functions,table:CIFAR-100-timing-activation-functions}.\nThe baseline network was adjusted so that every activation function except the\none of the output layer was replaced by one of the 11~activation functions.\n\nAs expected, \\gls{PReLU} and \\gls{ELU} performed best. Unexpected was that the\nlogistic function, tanh and softplus performed worse than the identity and it\nis unclear why the pure-softmax network performed so much better than the\nlogistic function.\nOne hypothesis why the logistic function performs so bad is that it cannot\nproduce negative outputs. Hence the logistic$^-$ function was developed:\n\\[\\text{logistic}^{-}(x) = \\frac{1}{1+ e^{-x}} - 0.5\\]\nThe logistic$^-$ function has the same derivative as the logistic function and\nhence still suffers from the vanishing gradient problem.\nThe network with the logistic$^-$ function achieves an accuracy which is\n\\SI{11.30}{\\percent} better than the network with the logistic function, but is\nstill \\SI{5.54}{\\percent} worse than the \\gls{ELU}.\n\nSimilarly, \\gls{ReLU} was adjusted to have a negative output:\n\\[\\text{ReLU}^{-}(x) = \\max(-1, x) = \\text{ReLU}(x+1) - 1\\]\nThe results of \\gls{ReLU}$^-$ are much worse on the training set, but perform\nsimilar on the test set. The result indicates that the possibility of hard zero\nand thus a sparse representation is either not important or similar important as\nthe possibility to produce negative outputs. This\ncontradicts~\\cite{glorot2011deep,srivastava2014understanding}.\n\nA key difference between the logistic$^-$ function and \\gls{ELU} is that\n\\gls{ELU} does neither suffers from the vanishing gradient problem nor is its\nrange of values bound. For this reason, the S2ReLU activation function, defined\nas\n\\begin{align*}\n  \\StwoReLU(x) &= \\ReLU \\left (\\frac{x}{2} + 1 \\right ) - \\ReLU \\left (-\\frac{x}{2} + 1 \\right)\\\\\n  &=\n  \\begin{cases}-\\frac{x}{2} + 1 &\\text{if } x \\le -2\\\\\n               x &\\text{if } -2\\le x \\le 2\\\\\n               \\frac{x}{2} + 1&\\text{if } x > -2\\end{cases}\n\\end{align*}\nThis function is similar to SReLUs as introduced in~\\cite{jin2016deep}. The\ndifference is that S2ReLU does not introduce learnable parameters. The S2ReLU\nwas designed to be symmetric, be the identity close to zero and have a smaller\nabsolute value than the identity farther away. It is easy to compute and easy to\nimplement.\n\nThose results --- not only the absolute values, but also the relative\ncomparison --- might depend on the network architecture, the training\nalgorithm, the initialization and the dataset. Results for MNIST can be found\nin~\\cref{table:MNIST-accuracies-activation-functions} and for HASYv2\nin~\\cref{table:HASYv2-accuracies-activation-functions}. For both datasets, the\nlogistic function has a much shorter training time and a noticeably lower test\naccuracy.\n\n\\glsunset{LReLU}\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{lccc}\n    \\toprule\n    \\multirow{2}{*}{Function} & Vanishing  & Negative Activation & Bound \\\\\n                  & Gradient       & possible & activation \\\\\\midrule\n    Identity      & \\cellcolor{green!25}No    & \\cellcolor{green!25}  Yes    & \\cellcolor{green!25}No  \\\\\n    Logistic      & \\cellcolor{red!25} Yes    & \\cellcolor{red!25}   No      & \\cellcolor{red!25}  Yes \\\\\n    Logistic$^-$  & \\cellcolor{red!25} Yes    & \\cellcolor{green!25}  Yes    & \\cellcolor{red!25}  Yes \\\\\n    Softmax        & \\cellcolor{red!25} Yes    & \\cellcolor{green!25}  Yes    & \\cellcolor{red!25}  Yes \\\\\n    tanh          & \\cellcolor{red!25} Yes    & \\cellcolor{green!25}  Yes    & \\cellcolor{red!25}  Yes \\\\\n    Softsign      & \\cellcolor{red!25} Yes    & \\cellcolor{green!25}Yes      & \\cellcolor{red!25}   Yes \\\\\n    ReLU          & \\cellcolor{yellow!25}Yes\\footnotemark & \\cellcolor{red!25} No & \\cellcolor{yellow!25}Half-sided \\\\\n    Softplus      & \\cellcolor{green!25}No    & \\cellcolor{red!25}   No      & \\cellcolor{yellow!25}Half-sided \\\\\n    S2ReLU        & \\cellcolor{green!25}No    & \\cellcolor{green!25}Yes      & \\cellcolor{green!25} No \\\\\n    \\gls{LReLU}/PReLU   & \\cellcolor{green!25}No    & \\cellcolor{green!25}Yes      & \\cellcolor{green!25} No \\\\\n    ELU           & \\cellcolor{green!25}No    & \\cellcolor{green!25}Yes      & \\cellcolor{green!25} No \\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function properties]{Properties of activation functions.}\n    \\label{table:properties-of-activation-functions}\n\\end{table}\n\\footnotetext{The dying ReLU problem is similar to the vanishing gradient problem.}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{lccclllll}\n    \\toprule\n    \\multirow{2}{*}{Function} & \\multicolumn{2}{c}{Inference per}                                & Training                            & \\multirow{2}{*}{Epochs} & Mean total        \\\\\\cline{2-3}\n                              & 1 Image                        & 128                             & time                                &                         & training time     \\\\\\midrule\n    Identity                  & \\SI{8}{\\milli\\second}          & \\SI{42}{\\milli\\second}          & \\SI{31}{\\second\\per\\epoch}          & 108 -- \\textbf{148}     &\\SI{3629}{\\second} \\\\\n    Logistic                  & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{24}{\\second\\per\\epoch}          & \\textbf{101} -- 167     &\\textbf{\\SI{2234}{\\second}} \\\\\n    Logistic$^-$              & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\textbf{\\SI{22}{\\second\\per\\epoch}} & 133 -- 255              &\\SI{3421}{\\second} \\\\\n    Softmax                   & \\SI{7}{\\milli\\second}          & \\SI{37}{\\milli\\second}          & \\SI{33}{\\second\\per\\epoch}          & 127 -- 248              &\\SI{5250}{\\second} \\\\\n    Tanh                      & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{23}{\\second\\per\\epoch}          & 125 -- 211              &\\SI{3141}{\\second} \\\\\n    Softsign                  & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{23}{\\second\\per\\epoch}          & 122 -- 205              &\\SI{3505}{\\second} \\\\\n    \\gls{ReLU}                & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{23}{\\second\\per\\epoch}          & 118 -- 192              &\\SI{3449}{\\second} \\\\\n    Softplus                  & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{24}{\\second\\per\\epoch}          & \\textbf{101} -- 165     &\\SI{2718}{\\second} \\\\\n    S2ReLU                    & \\textbf{\\SI{5}{\\milli\\second}} & \\SI{32}{\\milli\\second}          & \\SI{26}{\\second\\per\\epoch}          & 108 -- 209              &\\SI{3231}{\\second} \\\\\n    \\gls{LReLU}               & \\SI{7}{\\milli\\second}          & \\SI{34}{\\milli\\second}          & \\SI{25}{\\second\\per\\epoch}          & 109 -- 198              &\\SI{3388}{\\second} \\\\\n    \\gls{PReLU}               & \\SI{7}{\\milli\\second}          & \\SI{34}{\\milli\\second}          & \\SI{28}{\\second\\per\\epoch}          & 131 -- 215              &\\SI{3970}{\\second} \\\\\n    \\gls{ELU}                 & \\SI{6}{\\milli\\second}          & \\textbf{\\SI{31}{\\milli\\second}} & \\SI{23}{\\second\\per\\epoch}          & 146 -- 232              &\\SI{3692}{\\second} \\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function timing results on CIFAR-100]{Training time and\n             inference time of adjusted baseline models trained with different\n             activation functions on GTX~970 \\glspl{GPU} on CIFAR-100. It was\n             expected that the identity is the fastest function. This result is\n             likely an implementation specific problem of Keras~2.0.4 or\n             Tensorflow~1.1.0.}\n    \\label{table:CIFAR-100-timing-activation-functions}\n\\end{table}\n\n\\begin{table}[H]\n    \\centering\n    \\begin{tabular}{lccccc}\n    \\toprule\n    \\multirow{2}{*}{Function} & \\multicolumn{2}{c}{Single model}              & Ensemble & \\multicolumn{2}{c}{Epochs}\\\\\\cline{2-3}\\cline{5-6}\n                              & Accuracy             & std                    & Accuracy & Range & Mean \\\\\\midrule\n    Identity                  & \\SI{99.45}{\\percent} & $\\sigma=0.09$          & \\SI{99.63}{\\percent} & 55 -- \\hphantom{0}77  & 62.2\\\\%TODO: Really?\n    Logistic                  & \\SI{97.27}{\\percent} & $\\sigma=2.10$          & \\SI{99.48}{\\percent} & \\textbf{37} -- \\hphantom{0}76  & \\textbf{54.5}\\\\\n    Softmax                   & \\SI{99.60}{\\percent} & $\\boldsymbol{\\sigma=0.03}$& \\SI{99.63}{\\percent} & 44 -- \\hphantom{0}73  & 55.6\\\\\n    Tanh                      & \\SI{99.40}{\\percent} & $\\sigma=0.09$          & \\SI{99.57}{\\percent} & 56 -- \\hphantom{0}80  & 67.6\\\\\n    Softsign                  & \\SI{99.40}{\\percent} & $\\sigma=0.08$          & \\SI{99.57}{\\percent} & 72 -- 101             & 84.0\\\\\n    \\gls{ReLU}                & \\textbf{\\SI{99.62}{\\percent}} & \\textbf{$\\sigma=0.04$} & \\textbf{\\SI{99.73}{\\percent}} & 51 -- \\hphantom{0}94 & 71.7\\\\\n    Softplus                  & \\SI{99.52}{\\percent} & $\\sigma=0.05$          & \\SI{99.62}{\\percent} & 62 -- \\hphantom{0}\\textbf{70}  & 68.9\\\\\n    \\gls{PReLU}               & \\SI{99.57}{\\percent} & $\\sigma=0.07$          & \\textbf{\\SI{99.73}{\\percent}} & 44 -- \\hphantom{0}89 & 71.2\\\\\n    \\gls{ELU}                 & \\SI{99.53}{\\percent} & $\\sigma=0.06$          & \\SI{99.58}{\\percent} & 45 -- 111 & 72.5\\\\\n    \\bottomrule\n    \\end{tabular}\n    \\caption[Activation function evaluation results on MNIST]{Test accuracy of\n             adjusted baseline models trained with different activation\n             functions on MNIST.}\n    \\label{table:MNIST-accuracies-activation-functions}\n\\end{table}\n\\glsreset{LReLU}\n\n", "meta": {"hexsha": "059ae291c49293481db0c3e3a8266f9d9b19dd73", "size": 13518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "publications/activation-functions/content.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/content.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/content.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": 69.3230769231, "max_line_length": 194, "alphanum_fraction": 0.6284213641, "num_tokens": 3913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6015726765722833}}
{"text": "%!TEX root = ../thesis.tex\n\n\\chapter{Conclusions and recommendation}\n\\section{Summary}\n\\paragraph{}\nIn this thesis, a systematic numerical method where all procedures are conducted without human involvement for an arbitrary geometric input in both 2D and 3D situations has been developed based on the SBFEM.\nThe SBFEM is a semi-analytical method which combines the main advantages of the finite element method and the boundary element method but also has unique features of its own.\nIn contrast to the FEM, only the boundary is discretized using the conventional FEM interpolating function which leads to a decline in the number of unknowns.\nIt also allows solving the problem involving bimaterial interfaces and crack faces without the discretization of them.\nCompared to the BEM, the fundamental solution is no longer required.\nThe infinite boundary can be achieved naturally as the radiation condition at infinity is satisfied in the SBFEM .\nAs only the boundary information is required in SBFEM and hence provides a seamless integration with the CAD modeling compared to conventional Isogeometric Method.\nThe discretization of the boundary can be based on the standard finite element interpolation functions for computational efficiency or NURBS basis function for exact geometry.\n\n\\paragraph{}\nThe preprocessing of the proposed method is conducted automatically without losing exact geometric representation.\nIn 2D problems, the geometric information from the IGES file exported from CAD design is extracted and a quad-tree based mesh will be generated automatically.\nHigh mesh quality and reduced computational cost in the calculation of the element stiffness matrix can be expected. \nFor 3D cases, both of the STL and the IGES files are exported from the CAD design and an octree based mesh will be generated based on STL file.\nSince the STL file represents the triangulation of the geometric surfaces, intersections calculated during cutting stage is supposed to be located on the triangular plane instead of the original surface.\nAs a consequence, a point projection algorithm is adopted to move the points back to the NURBS surfaces after the mesh has been generated.\nThen, an arbitrary geometric shape in 2D and 3D can be meshed automatically with high quality mesh and solved by the SBFEM.\nThe geometric exact can also be achieved by replacing the distance calculation with finding that between the edge of the element and the NURBS surface directly. \n\n\\paragraph{}\nAfter the solution is determined from the SBFEM, a mesh refinement may be necessary to improve the accuracy and check the convergence.\nIn order to find out the scaled boundary finite element which improves the accuracy significant after refinement, an adaptive mesh refinement algorithm is required.\nExpressions related to the eigenvalues of the SBFEM formulation are adopted as the physical error indicator to prevent extra work such as stress recovery.\nSome key geometric error estimator including area of the subdomain, minimal angel and so on are also included.\nThe decision based on numerous error estimators are conducted by the help of a machine learning algorithm.\nThe proposed adaptive mesh refinement exhibits higher rate of convergence compared to an uniform mesh refinement using SBFEM.\n\n\\paragraph{}\nThe thesis commences with an introduction to the research topic in Chapter 1.\nA background and motivation for the research are presented followed by the objective and outline of the research.\nIn Chapter 2, the linear theory of the Isogeometric analysis, together with a brief introduction on the NURBS and its mathematical backgrounds, potentials and limitations are summarized.\nA brief introduction on the IGES file is also presented.\nDue to the dimensional mismatch between the FEM and the CAD, the SBFEM is the technique which can provide a seamless integration with the CAD modeling.\nThe concept of adaptive mesh refinement and its limitation is presented as well.\nThe MLP then is introduced to overcome this limitation by the adoption of multiple error indicators.\nFinally, algorithms used to generate octree mesh in 3D from STL file is presented.\n\n\\paragraph{}\nIn Chapter 3, the NURBS basis functions are employed to approximate the unknown fields in the circumferential direction within the framework of the SBFEM.\nThe accuracy, effectiveness and the convergence properties of the proposed method are demonstrated with benchmark problems in linear elasticity and linear elastic fracture mechanics.\nFrom the numerical studies, it can be observed that the NURBS basis functions yield superior accuracy when compared to Lagrange basis functions of the same order.\nThe proposed method overcomes the disadvantages of both the isogeometric finite element analysis and the isogeometric boundary element method. \nWhen applied to problems with singularities, the proposed method does not require additional functions to span the solution space.\nMoreover, the proposed framework does not require internal discretization to study the dynamic response at high frequencies.\nHowever, for complicated geometries, to meet the star convexity, subdivision into smaller sub-domains is required.\n\n\\paragraph{}\nIn Chapter 4, the IGES file is employed directly from the CAD output to represent the geometry during the preprocessing.\nThe proposed methods provides a systematic and automatic mesh generation algorithm  where high quality mesh is produced efficiently.\nThe CAD design file can be used directly and the exact geometry can also be retained, which largely reduce the human efforts involved in numerical analysis.\nMoreover, it helps to reduce the analytical error as the difference in the geometric representation is minimized.\nComputational efficiency is improved via utilizing the pattern of the quadtree to prevent repeated calculation.\nPoints projection algorithm is accelerated using the strong convex hull property of the NURBS curve.\nThe accuracy, effectiveness and the convergence properties of the proposed method are demonstrated with benchmark problems in linear elasticity mechanics.\nFrom the numerical studies, it can be observed that the quadtree mesh yield better accuracy when compared to uniform mesh with same degree of freedoms.\n\n\\paragraph{}\nChapter 5 adopts a machine learning algorithm to develop an extensible and flexible error indicator.\nAny other error estimators can be added to the existing framework and their effects can be detected based on the performance indicators in machine learning.\nA MLP trained error estimator that concludes expressions related to the eigenvalues of the SBFEM formulation and some key geometric properties of the scaled boundary finite element gives a higher convergence rate compared to the uniform refinement.\nIn order to improve the learning effectiveness of the MLP, regularization methods including bagging and dropout are utilized.\nDue to the lack of the eigenvalue error indicator in the first order triangular element, method that eliminates these situation is developed.\nA matrix representation of the NURBS curves is presented to achieve a higher efficiency and stability in calculating the intersections between edge of the element and the NURBS curve.\n\n\\paragraph{}\nIn Chapter 6, a projection is conducted after the mesh is generated from STL file using octree or calculating the intersection between the edge of the element and the original NURBS surface to retain the exact geometry.\nIn order to utilize the strong hull property of the NURBS surface, a quick hull algorithm in 3D is introduced.\nAs a consequence, the computational efficiency of the points projection and the intersection calculation are improved significantly.\nThe proposed method is able to generate the mesh from an arbitrary geometric input and shows higher accuracy compared to conventional method.\n\n\n\\section{Future work}\n\\paragraph{}\nAs discussed in Chapter 3, there is no exact numerical integration for the NURBS basis function at the moment as its rational property currently.\nFurthermore, the computational cost of calculating a value of NURBS basis function can be $10$ times higher than that of the traditional Legendre polynomials.\nIn chapters after Chapter 3, the conventional shape functions are adopted instead of the NURBS basis functions to avoid too many expensive computational operation when the number of the elements grow drastically.\nFuture work can be performed on derive an exact and efficient numerical integration quadrature to prevent extra error.\nAlgorithm that evaluate the NURBS basis function can also be optimized so that the whole programme can be much more efficient as it is involved in almost all NURBS operation.\n\n\\paragraph{}\nAs discussed in Chapter 4, one of the most outstanding advantages of using machine learning algorithm to train the model responsible for making decision whether an element need to be refined lies in the allowance of unlimited number of error indicators.\nThe effectiveness of the deep neural network is closely related to the quantity of the training data.\nIn Chapter 4, less than a thousand of the training data is used, which limits the depth of the neural network and the number of the error indicators.\nFuture work can concentrate on building a platform so the cloud computing can be utilized and the service can be available to the whole community.\nBy having a platform, number of the training data can be solved naturally as any request of calculation contributes to one extra training data.\nA large training set then motive the scholars adding any error indicator.\n", "meta": {"hexsha": "8f47dae976888287fb85f7b9e114b179d0b3e77d", "size": 9560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "conclusion/index.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": "conclusion/index.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": "conclusion/index.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": 103.9130434783, "max_line_length": 253, "alphanum_fraction": 0.8282426778, "num_tokens": 1756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6015726661906201}}
{"text": "Parametrized, ring valued\nTutte equations and functions (with empty port set), and \nthe universal ported Tutte invariant (called the big Tutte \npolynomial by Las Vergnas) have been studied.  So has\nthe (reduced) Laplacian matrix's determinant for a graph--This \ndeterminant, according to the famous matrix tree theorem, equals\nthe number of bases in the corresponding graphic matroid.  It is\nwell-known that the number of bases in a Tutte invariant defined\nfor all matroids.  More strongly, the following homogeneous generating\nfunction for the bases\n\\[\nF(\\mathcal{N}(\\emptyset,E))=\n\\sum_{B\\in\\mathcal{B}(\\mathcal{N})}\n\\left(\\prod_{e\\in B} g_e\n\\right)\n\\left(\\prod_{e\\in E\\setminus B} r_e\n\\right)\n=\n\\sum_{B\\in\\mathcal{B}(\\mathcal{N})}\ng_B\\;\\;r_{\\scomp{B}}\n\\]\nis a Tutte function (with $P=\\emptyset$).\nThese background topics will be surveyed and extended as needed.\n\n\nThis paper's main topic is a parametrized function from certain\n(ported) extensors to extensors.  An extensor is a \n(fully or completely\\footnote{We will follow authors such as\n\\cite{JacobsonI} in omitting this qualifier for such decomposible elements})\ndecomposible element in an exterior algebra (i.e., algebra of antisymmetric\ntensors).  Our main result (Theorem \\textbf{FILLIN}) is that \nif extensor deletion and contraction are defined in a way that is\nconsistant with our function definition, then our function obeys \nidentities in exterior algebra that are analogs of the Tutte \nequations.  \n\n\nOne corollary applies to the class of ported unimodular oriented\nmatroids:  Our function, restricted to the unimodular extensors\nwhich represent this class, yields an extensor-valued Tutte function \nthat sometimes distinguishes different orientations of the same \nmatroid.\n\nWhen the corollary is applied with the\nparameters all set to $1$, we get new Tutte-like invariants\nthat can sometimes distinguish different orientations of the same matroid.\n\n\\subsection{Ports and Parameters}\n\nThe idea to restrict deletion/contraction decomposition so it does\nnot apply to some distinguished elements \nis a natural one.  It was applied to invariants of\nmatroid morphisms (or strong maps) by Las \nVergnas\\cite{MR0419272,SetPointedLV,EtienneLasVergnasMorphismVectorial}.\nThe equations for \nported Tutte invariants (i.e., $F$ with the $r_e=g_e=1$ and \ninvariant under port-preserving matroid isomorphisms) determine\nthe \n\\textbf{big Tutte polynomial} defined by Las Vergnas in \\cite{SetPointedLV}.\nWhereas the traditional Tutte polynomial has only two variables,\nwhich correspond to the isomorphism classes of the indecomposible \nloop and coloop matroids, the generalization adds additional\nvariables corresponding to the additional indecomposible matroids\non sets of port elements. \n\nOur motivation there and here\ncomes from distinguishing as ports some edges\nin a directed graph model of an electrical network.  The ports\nmodel two-terminal plugs or sockets where the network interacts\nwith an enviroment; the other edges model resistors.\n\nIn this paper we add the observation that if ported Tutte \ndecomposition is done on an \\emph{oriented} matroid, the indecomposible\nminors include connected \\emph{oriented} matroids on sets of port elements.\nTherefore, if $\\mathcal{N}_1$ and $\\mathcal{N}_2$ are different orientations\nof the same orientable matroid, then \n$F(\\mathcal{N}_1)\\neq F(\\mathcal{N}_2)$ is possible for a ported\nTutte function $F$.  \n", "meta": {"hexsha": "231abea707bf9061fa7a913f81a7fa6b14abd1c1", "size": 3407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TutteEx/Current/junk.tex", "max_stars_repo_name": "chaikens/MathOfElec", "max_stars_repo_head_hexsha": "6292a8cffe1441a557212b0fd23f3fd7769975a7", "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": "TutteEx/Current/junk.tex", "max_issues_repo_name": "chaikens/MathOfElec", "max_issues_repo_head_hexsha": "6292a8cffe1441a557212b0fd23f3fd7769975a7", "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": "TutteEx/Current/junk.tex", "max_forks_repo_name": "chaikens/MathOfElec", "max_forks_repo_head_hexsha": "6292a8cffe1441a557212b0fd23f3fd7769975a7", "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.1265822785, "max_line_length": 76, "alphanum_fraction": 0.7951276783, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.6548947290421275, "lm_q1q2_score": 0.6015078705414836}}
{"text": "% !TEX root = ../thesis.tex\n\n\n\\chapter{Beam Propagation using the Hankel Transform}\n% \\label{cha:beam_propagation}\n\nIn this chapter I will briefly show how the trapping geometry presented before could be realised in an experiment.\nThe two ring beams can be produced with axicon lenses. I have programmed a simple beam propagation for cylindrical beams. This tool can be found on my personal GitHub page\\footnote{\\url{github.com/AvonHaaren}} and was programmed in \\Cpp and Python.\n\n\\section{Theory -- Fourier Optics}\nFourier optics in a mathematical approach to the propagation of light through free space and variuos media. In Fourier optics, the light field is decomposed into a sum of plane waves, each of which can be propagated through an arbitrary linear optical system independently. Afterwards, the components are superimposed to give the light field after the system. In two dimensions, this is done by using the Fourier transform\n\\begin{align}\n    \\mathcal{F}\\left\\{f(x,y)\\right\\} = F(\\nu_x,\\nu_y) &= \\iint \\diff{x} \\diff{y}\\; f(x,y) \\exp\\!\\left(2\\pi i (x\\nu_x + y\\nu_y)\\right) \\\\\n    f(x,y) &= \\iint \\diff{\\nu_x} \\diff{\\nu_y}\\; F(\\nu_x,\\nu_y) \\exp\\!\\left(-2\\pi i (x\\nu_x + y\\nu_y)\\right)\n\\end{align}\nIn the case of free space propagation, the transfer function $H(\\nu_x,\\nu_y,\\Delta z)$ is fully expressed by the spatial frequencies $\\nu_x$ and $\\nu_y$. Using this, we can express the electric field after a distance $\\Delta z$ through\n\\begin{align}\n    E(x,y,\\Delta z) = \\iint \\diff{\\nu_x} \\diff{\\nu_y}\\; H(\\nu_x,\\nu_y,\\Delta z) \\mathcal{F}\\left\\{E(x,y,0)\\right\\} \\exp\\!\\left(-2\\pi i (x\\nu_x + y\\nu_y)\\right)\n\\end{align}\n\n\\subsection{Cylindrical Symmetry}\nIf the light field and optical system are cylindrically symmetric, the Fourier transform in the equation above can be replaced by the Hankel transform of zero order:\n\\begin{align}\n    G(\\rho) &= 2\\pi\\int_0^\\infty \\diff{r}\\; g(r) r J_0(2\\pi r \\rho) \\\\\n    g(r) &= 2\\pi \\int_0^\\infty \\diff{\\rho}\\; G(\\rho) \\rho J_0(2\\pi r \\rho)\n\\end{align}\nHere, $g(r)$ is the field in real space, $G(\\rho)$ the transformed field in reciprocal space and $J_0$ is the Bessel function of zero order. $\\rho$ is the spatial frequency in radial direction, where $2\\pi\\rho = \\kappa$ is the radial wavenumber. For numerical calculations, this reduction to a one-dimensional problem is highly beneficial.\n\n\\subsection{Transfer Functions of Optical Elements}\n\\paragraph{Spherical Lens} ~\\\\\nThe transfer function of a spherical lens is given by\n\\begin{equation*}\n    H_\\text{TL}(r) = \\exp\\!\\left(-i\\pi\\frac{r^2}{f\\lambda}\\right)\n\\end{equation*}\nwhere $f$ is the focal length and $\\lambda$ the wavelength of the light.\n\n\\paragraph{Axicon} ~\\\\\nAn axicon has a transfer function\n\\begin{equation*}\n    H_\\text{A}(r) = \\exp\\!\\left(-\\frac{2\\pi r}{\\lambda}(n - 1)\\tan(\\alpha)\\right)\n\\end{equation*}\nwhere $n$ is the refractive index of the axicon and $\\alpha$ is the opening angle, as shown in \\cref{fig:axicon}. A constant phase factor depending on the thickness of the axicon has been omitted.\n\\begin{figure}[htbp]\n    \\centering\n    \\input{TexContents/Figures/Evap/Axicon/axicon.tikz}\n    \\caption{Axicon Lens}\n    \\label{fig:axicon}\n\\end{figure}\n\n\\paragraph{Free Space} ~\\\\\nThe free space transmission function depends only on the coordinates in reciprocal space:\n\\begin{equation}\n    H_\\text{FS}(\\rho, \\Delta z) = \\exp\\!\\left(\\frac{2\\pi i \\Delta z}{\\lambda}\\sqrt{1 - (\\lambda \\rho)^2}\\right)\n\\end{equation}\nNotably, for $\\rho^{-1} > \\lambda$, transmission is exponentially suppressed. This expresses the fact that structures smaller than a wavelength are not resolvable.\n\n\n\\subsection{Numerical Evaluation}\nTo calculate the Hankel transform and its inverse, we discretise real and reciprocal space up to maximum values $r_\\text{max}$ and $\\rho_\\text{max}$ in regular intervals with spacings $\\delta r$ and $\\delta \\rho$ given by\n\\[\n    \\delta r = \\frac{r_\\text{max}}{N}, \\quad \\delta \\rho = \\frac{\\rho_\\text{max}}{N}\n\\]\nwhere $N$ is the grid size.\nThen we have\n\\begin{align}\n    G(\\rho) &= 2\\pi \\delta r \\sum_{i = 0}^N r_i  g(r_i) J_0(2\\pi r_i \\rho) \\\\\n    g(r) &= 2\\pi \\delta \\rho \\sum_{i = 0}^N \\rho_i  G(\\rho_i) J_0(2\\pi r \\rho_i)\n\\end{align}\nTo save computation time, the Bessel function can be pre-evaluated on a $N\\times N$ grid. However, at high resolutions, the memory consumption of this becomes too large, also resulting in higher cache miss rates. We therefore only evaluate the Bessel function on a grid of size $M$ with maximum $2\\pi r_\\text{max} \\rho_\\text{max}$. Interpolation between these values is much faster than calculating the exact value of $J_0(x)$ in the transformation.\n\n\n\\section{Tested Setup and Results}\nTo test an optical system with an arbitrary number of elements, the initial electric field is propagated to the $n$-th optical element using the Hankel transform and the free space propagator. At the location of the optical element, the field is transformed back into real space, the transfer function of the element is applied and then the field can be propagated to the next element etc.\n\nWe adapt the setup from Hueck et al. \\cite{PhysRevLett.120.060402}, using one axicon \\cite{McLeod} to split the initial gaussian into a ring, another axicon in combination with a long focal length spherical lens to invert it and then a third, movable axicon to produce a collimated ring that can have a varying radius. This is shown in \\cref{fig:axicon_setup}. In the setup that we want to use and that is simulated, there is an additional $5\\times$ demagnification stage after the third axicon.\n\\begin{figure}[htbp]\n    \\centering\n    \\input{TexContents/Figures/Evap/AxiconSetup/AxiconSetupNew.tikz}\n    \\caption[Optical setup to create a ring beam with dynamically adjustable radius]{Adapted from \\cite{axiconSM}. Optical setup to create a ring beam with dynamically adjustable radius. Not shown here is an additional microscope that demagnifies the beam from the image plane to the target plane.}\n    \\label{fig:axicon_setup}\n\\end{figure}\nThe position of the first axicon is defined as $z=0$. The \\SI{400}{mm} lens is positioned at $z=\\SI{85}{mm}$ with the second axicon behind it at $z=\\SI{95}{mm}$. The third axicon can be moved between $z=\\SI{585}{mm}$ and $z=\\SI{625}{mm}$ \\todo{check if correct}.\nThe initial gaussian beam has a wavelength of \\SI{770}{nm} the position of its waist relative to $z=0$ as well as the waist size can be varied.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\includegraphics[width=\\textwidth]{Evap/AxiconBeam/plot}\n    \\caption{Example of a beam resulting from the setup above. \\textbf{PRELIMINARY, WILL BE SWAPPED OUT FOR THE FINAL VERSION}}\n    % \\label{fig:axiconBeam}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[t]{0.49\\textwidth}\n        \\centering\n        \\missingfigure[figwidth=.9\\linewidth]{Closeup of the focus region}\n        \\caption{Close-up image of the beam in the focus region}\n    \\end{subfigure}\n    \\begin{subfigure}[t]{0.49\\textwidth}\n        \\centering\n        \\missingfigure[figwidth=.9\\linewidth]{Intensity Plot at the focus, with fitted power law}\n        \\caption{Resulting ring intensity at the focus position. A power-law curve has been fitted to the data. \\textbf{VALUE MISSING}}\n    \\end{subfigure}\n    \\caption{Ring beam at the focus position with a resulting diameter of \\textbf{VALUE MISSING}.}\n    % \\label{fig:axiconBeamResult1}\n\\end{figure}\n", "meta": {"hexsha": "389d86734eb6388ae86ee81547eb43221e819bda", "size": 7396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TexContents/25EVA-Beam_Propagation.tex", "max_stars_repo_name": "AvonHaaren/mphil-thesis", "max_stars_repo_head_hexsha": "f96a6c352420c34632b4d5e502a1b38024753a74", "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": "TexContents/25EVA-Beam_Propagation.tex", "max_issues_repo_name": "AvonHaaren/mphil-thesis", "max_issues_repo_head_hexsha": "f96a6c352420c34632b4d5e502a1b38024753a74", "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": "TexContents/25EVA-Beam_Propagation.tex", "max_forks_repo_name": "AvonHaaren/mphil-thesis", "max_forks_repo_head_hexsha": "f96a6c352420c34632b4d5e502a1b38024753a74", "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": 69.1214953271, "max_line_length": 495, "alphanum_fraction": 0.7320173067, "num_tokens": 2121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6014463653071479}}
{"text": "\\section{Appendix}\n\n\n\n\\subsection{VWM Network model}\n\n\\begin{notation}\n\tTreat 1D tensors as column vectors and 2D tensors as matrices, where appropriate.\n\tWe use lower case to represent both 1D and 2D tensors but occasionally use upper case\n\tfor 2D tensors where matrix operations are involved.\n\t\n\t\\begin{enumerate}\n\t\t\\item Let \n\t\t$\\Delta^d = \\{ (x_0, x_1, \\dots, x_d) : x_0 + x_1 + \\dots + x_d = 1, x_i \\ge 0, i = 0, 1, \\dots, d\\}$ denote the standard $d$-simplex.\t\n\t\t\n\t\t\\item  Let $\\circ$ denote concatenation of two tensors with identical shape except possibly\n\t\tfor their last dimensions $d_1$ and $d_2$, respectively,  \n\t\tresulting in a tensor with last dimension of $d_1+d_2$. \n\t\t\n\t\t\\item Let $\\odot$ denote  element-wise product of two tensors of same shape,\n\t\ti.e., Hadamard product for vectors/matrices.\n\t\t\n\t\t\\item Let $\\otimes$ denote tensor product of two tensors, \n\t\ti.e. Kronecker product for vectors/matrices.\n\t\\end{enumerate}\n\\end{notation}\t\n\n\\subsection{Basic layers/modules}\n\n\\colorbx{Linear (Affine) Layer}\n\n\\begin{description}\n\t\\item[Inputs:] A tensor $x$ with last dimension $n$.\n\t\\item[Parameter:] An affine function $\\cG: \\Reals^n \\to \\Reals^m$ with \n\tweight and bias parameters.\n\t\n\t\\item[Output:] A tensor $y$ with last dimension $m$, and remaining dimensions\n\tsame as that of $x$, obtained by applying $\\cG$ to each 1D slice of $x$\n\talong the last dimension.\n\\end{description}\n\n\n\\colorbx{Attention Module}\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Query: $q \\in \\Reals^d$\n\t\t\\item Keys: $K \\in \\Reals^{N \\times d}$\t\n\t\t\\item Values: $V \\in \\Reals^{N \\times d}$. By default $V=K$, unless mentioned explicitly.\t\n\t\\end{enumerate}\n\t\n\t\\item[Parameter:] Weight $w \\in \\Reals^d$\n\t\n\t\\item[Outputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Content vector: $h =  V^{\\T} u \\in \\Reals^d$\n\t\t\\item Attention vector:  $w = \\softmax(K(w \\odot q)) \\in \\Reals^N$\n\t\\end{enumerate}\n\\end{description}\n\n\n\\colorbx{Interaction Module}\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Base object: $b \\in \\Reals^d$\n\t\t\\item Feature objects: $f \\in \\Reals^{M \\times d}$\t\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Base object projection linear layer: $\\cG: \\Reals^d \\to \\Reals^d$\n\t\t\\item Feature objects projection linear layer : $\\cK: \\Reals^{M \\times d} \\to \\Reals^{M \\times d}$\n\t\t\\item Modifier linear layer:  $\\cH: \\Reals^{M \\times 2d} \\to \\Reals^{M \\times d}$\t\n\t\\end{enumerate}\n\t\n\t\\item[Output:] Modified feature objects \n\t$f' =  \\cH( \\cK(f) \\odot ( \\vone \\otimes \\cG(b))) \\in  \\Reals^{M \\times d}$\n\\end{description}\n\n\\hrulefill\n\n\\subsection{SAM cell}\n\nThe SAM recurrent cell is executed for $T$ reasoning steps for every frame in\nthe temporal order.  Within a single frame, the cell state at the end of each reasoning step \n$t=1,2, \\dots, T$ is denoted by $(c_t, M_t, o_t)$, where: \n\\begin{enumerate}\n\t\\item $c_t \\in \\Reals^d$ is the control state;\n\t\\item $M_t \\in  \\Reals^{N \\times d}$ is the visual working memory with $N$ slots;\n\t\\item $w_t \\in  \\Reals^N$ is the write head; and\n\t\\item $so_t  \\in \\Reals^d$ is the summary visual object.\n\\end{enumerate} \nThe initial state is such that both $c_0$ and $so_0$ are initialized\nto a fixed value at the start of each frame. However $M_0$ is initialized only once at\nthe start of the first frame and otherwise taken to be the value of $M_T$ at the\nend of the previous frame.\n\n%The number of slots $N$ for the SAM $M_t$ is not fixed because the neural network \n%parameters do not depend on it. It can be variable across the different datasets used\n%for training, validation and test as well as within each dataset. This, for example, enables a \n%form of transfer learning where we can train on an easy dataset for one value of $N$\n%and study its generalization to a hard dataset using a larger value of $N$.\n\n\\colorbx{Question-driven Controller}\n\n%The Question-driven Controller plays an important role in the reasoning process.\n%It drives the attention over the question and produces the new control states. Each new control state defines a new reasoning operation. The inputs of this unit are the past control state, the question encoding and the contextual words (see Question Encoding Unit). It uses the dot product attention between the contextual words\n%and the combination of the past control states and the question encoding.  This attention layer produces the new control state.\n%\n%This unit also outputs the temporal class weights that will be used in the Reasoning Unit. It gives access to a temporal information for the current words (last, latest, now, none temporal).\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Reasoning step $t = 1,2, \\dots, T$\n\t\t\\item Previous control state: $c_{t-1} \\in \\Reals^d$\t\n\t\t\\item Contextual words: $cw \\in \\Reals^{L \\times d}$\n\t\t\\item Question encoding: $q \\in \\Reals^d$\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Reasoning step-dependent linear layer: $\\cG_t: \\Reals^d \\to \\Reals^d$, depending on $s$\n\t\t\\item Concatenation linear layer: $\\cH: \\Reals^{2d} \\to \\Reals^d$\n\t\t\\item Attention module $\\cA$\n\t\t\\item Temporal classifier:  $\\cK: \\Reals^d \\to \\Delta^3$. A two-layer feedforward\n\t\tnetwork with ELU activation in the hidden layer of $d$ units.\t\n\t\tThe classes for the temporal context are labeled ``last'', ``latest'', ``now'', as well as \n\t\ta fourth class label ``none`` indicating no temporal context.\n\t\tIf $\\tau \\in \\Delta^3$ is the output of the classifier, we denote the components by\n\t\t$\\tlast$, $\\tlatest$, $\\tnow$ and $\\tnone$.\n\t\\end{enumerate}\n\t\n\t\\item[Outputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Control state $c_t \\in \\Reals^d$\n\t\t\\item Control attention $ca_t \\in \\Reals^L$\n\t\t\\item Temporal class weights $\\tau_t \\in \\Reals^4$\n\t\\end{enumerate}\n\t\n\t\\item[Equations:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Modulation: $y = \\cH\\bigl([c_{t-1}, \\cG_t(q)]\\bigr)$\n\t\t\\item Control state and attention: $c_t,  ca_t= \\cA(y, cw)$\n\t\t\\item Temporal classification: $\\tau_t = \\cK(c_t)$\n\t\\end{enumerate}\n\\end{description}\n\n\n\\colorbx{Visual Retrieval Unit}\n\n%The visual retrievial unit is responsible to extract visual information from the current image given a control state coming from the Question-driven Controller. It is first projecting the past summary object and the feature maps together using the interaction module.\n%It is then using the attention module as follow. The query are the control states and the keys and are the feature maps coming from the image encoder. The results of this attention is applied on the modified features maps coming from the interaction module.  \n%This unit outputs the extracted object and the visual attention.\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Control state: $c_t \\in \\Reals^d$\t\n\t\t\\item Previous summary object: $so_{t-1} \\in \\Reals^d$\n\t\t\\item Feature map of current frame: $F \\in \\Reals^{H \\times W \\times d}$\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Interaction module $\\cI$\n\t\t\\item Attention module $\\cA$\n\t\\end{enumerate}\n\t\n\t\\item[Outputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Visual object: $vo_t \\in  \\Reals^d$\n\t\t\\item Visual attention: $va_t  \\in \\Reals^{H \\times W \\times d}$\n\t\\end{enumerate}\n\t\n\t\\item[Equations:]\n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Modified feature map: $\\hat{F} = \\cI(so_{t-1}, F)$\n\t\t\\item Visual object and attention: $vo_t, va_t = \\cA(y, \\hat{F}, M_{t-1})$\n\t\\end{enumerate}\n\\end{description}\n\n\\begin{note}\n\tAppropriate flatten/unflatten operations are performed to match the signature \n\tof the modules.\n\\end{note}\n\n\n\\colorbx{Memory Retrieval Unit}\n\n%The role of the memory retrieval unit is to read and extract object from memory).\n%As the Visual Retrieval Unit, it uses the combination of the two following submodules. The interaction module blends together the extracted object and the content of the memory. The attention module then extract the corresponding object in memory if present. This unit outputs the extracted object and its corresponding location, we call it the \"read head\".\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Control state: $c_t \\in \\Reals^d$\t\n\t\t\\item Previous summary object: $so_{t-1} \\in  \\Reals^d$\n\t\t\\item Previous SAM $M_{t-1} \\in \\Reals^{N \\times d}$\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Interaction module $\\cI$\n\t\t\\item Attention module $\\cA$\n\t\\end{enumerate}\n\t\n\t\\item[Outputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Memory object: $mo_t \\in \\Reals^d$\n\t\t\\item Read head: $\\rhead_t \\in \\Reals^N$\n\t\\end{enumerate}\n\t\n\t\\item[Equations:]\n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Modified SAM: $\\hat{M}_t = \\cI(so_{t-1}, M_{t-1})$\n\t\t\\item Memory object and attention: $mo_t, \\rhead_t = \\cA(y, \\hat{M}_t, M_{t-1})$\n\t\\end{enumerate}\n\\end{description}\n\n\n\\colorbx{Reasoning Unit}\n\n%control_state, visual_object, memory_object, temporal_class_weights\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Control state: $c_t \\in \\Reals^d$\n\t\t\\item Visual object: $vo_t \\in \\Reals^d$\n\t\t\\item Memory object: $mo_t \\in \\Reals^d$\n\t\t\\item Temporal class weights $\\tau \\in \\Delta^3$\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] Validator modules $\\cG, \\cK: \\Reals^{2d} \\to \\Reals$.\n\tBoth $\\cG, \\cK$ are two-layer networks of $2d$ hidden units,\n\tusing ELU activation in the hidden layer, and sigmoid in the output layer.\n\t\n\t\\item[Output:] Predicate gates for the current reasoning step\n\t\\begin{enumerate}\n\t\t\\item Object match predicate gates (i) image: $\\imatch_t \\in [0,1]$ and \n\t\t(ii) memory: $\\mmatch_t \\in [0,1]$.\n\t\t\n\t\t\\item Memory update predicate gates (i) add: $\\doadd_t \\in [0,1]$ and\n\t\t(ii) replace: $\\doreplace_t \\in [0,1]$\n\t\\end{enumerate}\n\t\n%\t\\item[Equations:]\n%\t\\begin{enumerate}\n%\t\t\\item[]\n%\t\t\\item $\\imatch_t \\in [0,1]$:\n%\t\tIt's true if there is a valid visual object in the current temporal context.\n%\t\t\n%\t\t\\item $\\mmatch_t \\in [0,1]$:\n%\t\tIt's true if there is a valid memory object in the current temporal context.\n%\t\t\n%\t\t\\item $\\doadd_t \\in [0,1]$: \n%\t\tIt's true if the current visual object should be added as a new object to memory.\n%\t\t\n%\t\t\\item $\\doreplace_t \\in [0,1]$: \n%\t\tIt's true if the current visual object should replace an existing object in memory.\n%\t\\end{enumerate}\n\\end{description}\n\n\n\\colorbx{Memory Update Unit}\n\n%This unit is meant to update the content of the memory. \n%\n%Three actions can happen:\n%\n%\\begin{itemize}\n%\t\\item There is no object to be added to memory, the memory remains unchanged\n%\t\\item There is one object that needs to be added to memory, but a similar object is already in memory at a given location. The new object will replace the old object at this location\n%\t\n%\t\\item There is one object that needs to be added to memory, and  it is a new object. It is added at the write head location.\n%\\end{itemize}\n%\n%\n%This module also updates the position of the write head. If a new object as been added to the current write head position, the right head shifts right to a new empty slot. If the object has been replaced, the write head doesn't move.\n% visual_object, visual_working_memory, read_head, write_head, do_replace, do_add_new\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Visual object: $vo_t \\in \\Reals^d$\n\t\t\\item Memory object: $mo_t \\in \\Reals^d$\n\t\t\\item Memory update predicate gates:  $\\doadd_t, \\doreplace_t \\in [0,1]$\n\t\t\\item Read head: $\\rhead_t \\in \\Reals^N$\n\t\t\\item Previous SAM $M_{t-1} \\in \\Reals^{N \\times d}$\n\t\t\\item Previous write head: $\\whead_{t-1} \\in \\Reals^N$\n\t\\end{enumerate}\n\t\n\t\\item[Outputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item SAM $M_t \\in \\Reals^{N \\times d}$\n\t\t\\item Read head: $\\rhead_t \\in \\Reals^N$\n\t\t\\item Write head: $\\whead_t \\in \\Reals^N$\n\t\\end{enumerate}\n\t\n\\end{description}\n\n\n\n\\colorbx{Summary Object Update Unit}\n\n%The  Summary Unit is the last unit of the SAMCell. It is responsible to output the new summary object. It first picks which object is relevant between the object extracted from memory and the visual object extracted from the image. Once the relevant object is picked, it is combined with the former summary object through a linear layer to become the new summary object. It is the final step of the SAMCell reasoning cycle. \n%\n%The image encoder, question encoder and output unit are described in the appendix.\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item[]\n\t\t\\item Previous summary object: $so_{t-1} \\in \\Reals^d$\n\t\t\\item Visual object: $vo_t \\in \\Reals^d$\n\t\t\\item Memory object: $mo_t \\in \\Reals^d$\n\t\t\\item Object predicate gates: $\\imatch_t, \\mmatch_t \\in [0,1]$\n\t\\end{enumerate}\n\t\n\t\\item[Parameters:] Concatenation linear layer $\\cH$ \n\t\n\t\\item[Output:] \n\tNew summary object:\n\t$so_t = \\cH\\bigl([so_{t-1}, (\\imatch_t * vo_t + \\mmatch_t * mo_t)]\\bigr) \\in \\Reals^d$ \n\t\n\\end{description}\n\n\n\\noindent\\makebox[\\linewidth]{\\rule{\\paperwidth}{1pt}}\n\n\n\n\n\n\\colorbx{Image Encoder}\n\n\\begin{description}\n\t\\item[Inputs:] \n\tImages\n\t\n\t\\item[Output:] \n\tFeatures maps:\n\t$F_k$\n\\end{description}\n\nThe Image Encoder unit is responsible to preprocess the sequence of images one at the time. It is a 4 layer convolutional neural network. Every layer is composed of the following sequence of operations:\n\n\\begin{enumerate}\n\t\\item 2D convolution ($stride=1$) \n\t\\item 2D max pooling\n\t\\item 2D batch normalization\n\t\\item Relu (only for the first 3 layers)\n\\end{enumerate}\n\nThe first layer has 3 inputs channels and 32 output channels. Layer 2 has 32 and 64. Layer 3 has 64 and 64. Finally, layer 4 has 64 inputs channels and 128 output channels .\nThe resulting tensor (feature maps) are of dimensions [batch size, $H*W =7*7$, $dim$=128]. \n\n\n\\colorbx{Question Encoder}\n\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item question string $question$\n\t\t\\item question lengths $question_l$\n\t\t\n\t\\end{enumerate}\n\t\n\t\n\t\\item[Output:] \n\t\\begin{enumerate}\n\t\t\\item contextual word embeddingg $cw$\n\t\t\\item question encoding $q$\n\t\t\n\t\\end{enumerate}\n\t\n\\end{description}\n\nThe strings questions are first embedded ($torch.NN.Embeddings$) and then passed through a $d$-dimensional biLSTM ($d$=128).\nThe final hidden state of the biLSTM becomes the question encoding representation $q$. Whereas the biLSTM outputs are projected via a linear layer to become the final words encodings named contextual words $cw$. \n\n\\colorbx{Output Unit}\n\n\\begin{description}\n\t\\item[Inputs:] \n\t\\begin{enumerate}\n\t\t\\item question encoding $q$\n\t\t\\item summary object $so_t$\n\n\t\\end{enumerate}\n\t\n\t\n\t\\item[Output:] \n\tprediction \n\\end{description}\n\nThe output unit predicts the final answer to the question. It is a 2-linear-layer-ELU classifier that produces a distribution over the possible candidates. It is based on two inputs, the final summary object $so_t$ and the question encoding $q$ that are concatenated together. \n \n\n\\subsection{Training and Implementation Details}\n\n\\subsubsection{Implementation Details}\n\n\nSAMNet is implemented using MI-Prometheus~\\cite{kornuta2018accelerating}, a framework based on Pytorch. \nWe trained all our models using NVIDIA’s GeForce GTX TITAN X GPUs. SAMNet was trained using 8 reasoning steps and a hidden state size of 128. The external memory has 128-bit slots for all experiments. We trained our model until convergence but we also have set a training time limit of 80 hours.\n\n\\subsubsection{Training and testing Methodology}\n\nWe compared our model to the original COG model  ~\\cite{yang2018dataset} using their implementation (https://github.com/google/cog) and scores provided by the authors through personal communications. We used the same training parameters detailed in the original paper and reproduced their results.  For the generalization experiments from canonical to hard, we used the verified model and obtained new results that were not reported in the reference paper.   In Table 1 COG section shows 4 columns divided into two parts: \"paper\" and \"ours\" which distinguish between the results reported in the paper vs. our own experiments.\n\nOur experiments focused on the 22 classification tasks provided by the COG dataset. More details about the dataset are given in Table 2. First we evaluated SAMNet's performance on the canonical setting and compared it with the COG Model. As shown in Table 1 we could achieve a small improvement in accuracy, from 97.6\\% for the COG model to 98\\% for SAMNet. Next we focused on the hard setting of the dataset which increases the number of distractors from 1 to 10 and the number of frames from 4 to 8.\n\nThe first approach was to train a model on the hard training set, and test it on the hard test set. This is the same approach used by the COG paper ~\\cite{yang2018dataset} to evaluate performance on the hard dataset. We achieve a test accuracy of 96.1 \\% which represents a 16\\% improvement from the COG model score (see Table 1).\n%It shows that SAMNet's design choices make a difference when it come to harder tasks with longer sequences and more distractors objects.\n\nThe second approach was to see if the models can generalize from the easy to the hard setting. For this experiment, we trained a model on the canonical dataset, and directly tested on the hard dataset.  This experiment highlighted the most significant difference between SAMNet and the baseline COG model.\n\nFinally we trained a model on the canonical data set, fine-tuned it on the hard data set using only 25k iterations, and tested on the hard dataset. Thanks to fine-tuning, we can observe a significant improvement from 91.6\\%  to 96.5\\% test accuracy which represents the state of the art accuracy for the hard setting (classification tasks).\nAfter a short fine-tuning process, the transferred model could generalize well to harder tasks and even surpass the accuracy obtained in the first approach. We note that the third approach is also twice faster than the first one, and it is more effective in terms of accuracy.\n\nA more granular analysis of accuracy per task shows a major improvement for the two hardest tasks, AndCompareShape and AndCompareColor. Those two tasks represent a higher level of difficulty due to the number of objects to be remembered in order to answer the question correctly.\nAs we can see in Table 1 we could achieve a 12\\% improvement for the canonical data set and almost a 30\\% improvement for the hard dataset.\nThe large improvement in these memory-intensive tasks indicate that the SAMNet's external memory plays a crucial role in our results. \nThe training and implementation details are in appendix.\n\n\\begin{table}[htb]\n\\caption{COG test set accuracies for SAMNet \\& COG models. Below `paper' denotes results from~\\cite{yang2018dataset} \n\twhile `code' denotes results of our experiments using their implementation~\\cite{yang2018implement}}\n\\centering\n\\begin{adjustbox}{width=\\textwidth}\n\\begin{tabular}{lcccccccccc}\n\t\\toprule\n\tModel & & SAMNet & && && COG&& \\\\\n\t\\cmidrule{2-5} \\cmidrule{7-11} \n\t&&&&& & paper & ours & ours & paper&\\\\\n\t\\cmidrule{7-9} \\cmidrule{10-11}\n\tTrained on       & canonical & canonical & canonical & hard &           &  canonical  & canonical  & canonical & hard \\\\ \n\tFine tuned on  & - & - & hard  & - &           & -   & - & hard & - \\\\ \n\tTested on        & canonical & hard & hard & hard &            &canonical  & hard & hard & hard  \\\\ \n\t\\midrule\n\t\n\tOverall accuracy & 98.0 & 91.6 & 96.5  & 96.1 &           & 97.6  & 65.9 & 78.1& 80.1 \\\\ \n\t\n\t\\midrule \n\t\t\t\n\tAndCompareColor\t\t\t&\t93.5\t&\t82.7\t&\t89.2\t&\t80.6\t&\t&\t81.9\t&\t57.1\t&\t60.7\t&\t51.4\t \\\\\n\tAndCompareShape\t\t\t&\t93.2\t&\t83.7\t&\t89.7\t&\t80.1\t&\t&\t80.0\t&\t53.1\t&\t50.3\t&\t50.7 \\\\\n\tAndSimpleCompareColor\t\t&\t99.2\t&\t85.3\t&\t97.6\t&\t99.4\t&\t&\t99.7\t&\t53.4\t&\t77.1\t&\t78.2 \\\\\n\tAndSimpleCompareShape\t\t&\t99.2\t&\t85.8\t&\t97.6\t&\t99.2\t&\t&\t100.0\t&\t56.7\t&\t79.3\t&\t77.9 \\\\\n\tCompareColor\t\t\t&\t98.1\t&\t89.3\t&\t95.9\t&\t99.7\t&\t&\t99.2\t&\t56.1\t&\t67.9\t&\t50.1 \\\\\n\tCompareShape\t\t\t&\t98.0\t&\t89.7\t&\t95.9\t&\t99.2\t&\t&\t99.4\t&\t66.8\t&\t65.4\t&\t50.5\t \\\\\n\tExist\t\t\t\t&\t100.0\t&\t99.7\t&\t99.8\t&\t99.8\t&\t&\t100.0\t&\t63.5\t&\t96.1\t&\t99.3 \\\\\n\tExistColor\t\t\t&\t100.0\t&\t99.6\t&\t99.9\t&\t99.9\t&\t&\t99.0\t&\t70.9\t&\t99\t&\t89.8 \\\\\n\tExistColorOf\t\t\t&\t99.9\t&\t95.5\t&\t99.7\t&\t99.8\t&\t&\t99.7\t&\t51.5\t&\t76.1\t&\t73.1 \\\\\n\tExistColorSpace\t\t\t&\t94.1\t&\t88.8\t&\t91.0\t&\t90.8\t&\t&\t98.9\t&\t72.8\t&\t77.3\t&\t89.2 \\\\\n\tExistLastColorSameShape\t\t&\t99.5\t&\t99.4\t&\t99.4\t&\t98.0\t&\t&\t100.0\t&\t65.0\t&\t62.5\t&\t50.4 \\\\\n\tExistLastObjectSameObject\t&\t97.3\t&\t97.5\t&\t97.7\t&\t97.5\t&\t&\t98.0\t&\t77.5\t&\t61.7\t&\t60.2 \\\\\n\tExistLastShapeSameColor\t\t&\t98.2\t&\t98.5\t&\t98.8\t&\t97.5\t&\t&\t100.0\t&\t87.8\t&\t60.4\t&\t50.3 \\\\\n\tExistShape\t\t\t&\t100.0\t&\t99.5\t&\t100.0\t&\t100.0\t&\t&\t100.0\t&\t77.1\t&\t98.2\t&\t92.5 \\\\\n\tExistShapeOf\t\t\t&\t99.4\t&\t95.9\t&\t99.2\t&\t99.2\t&\t&\t100.0\t&\t52.7\t&\t74.7\t&\t72.70 \\\\\n\tExistShapeSpace\t\t\t&\t93.4\t&\t87.5\t&\t91.1\t&\t90.5\t&\t&\t97.7\t&\t70\t&\t89.8\t&\t89.80 \\\\\n\tExistSpace\t\t\t&\t95.3\t&\t89.7\t&\t93.2\t&\t93.3\t&\t&\t98.9\t&\t71.1\t&\t88.1\t&\t92.8 \\\\\n\tGetColor\t\t\t&\t100.0\t&\t95.8\t&\t99.9\t&\t100.0\t&\t&\t100.0\t&\t71.4\t&\t83.1\t&\t97.9 \\\\\n\tGetColorSpace\t\t\t&\t98.0\t&\t90.0\t&\t95.0\t&\t95.4\t&\t&\t98.2\t&\t71.8\t&\t73.\t&\t92.3 \\\\\n\tGetShape\t\t\t&\t100.0\t&\t97.3\t&\t99.9\t&\t99.9\t&\t&\t100.0\t&\t83.5\t&\t89.2\t&\t97.1\t \\\\\n\tGetShapeSpace\t\t\t&\t97.5\t&\t89.4\t&\t93.9\t&\t94.3\t&\t&\t98.1\t&\t78.7\t&\t77.3\t&\t90.3 \\\\\n\tSimpleCompareShape\t\t&\t99.9\t&\t91.4\t&\t99.7\t&\t99.9\t&\t&\t100.0\t&\t67.7\t&\t96.7\t&\t99.3 \\\\\n\tSimpleCompareColor\t\t&\t100.0\t&\t91.6\t&\t99.80\t&\t99.9\t&\t&\t100.0\t&\t64.2\t&\t90.4\t&\t99.3 \\\\\n\t\\bottomrule\n\\end{tabular}\n\\end{adjustbox}\n\\label{results}\n\\end{table}\n\n\n\n\\begin{table}[htb]\n\\caption{COG Dataset parameters for the canonical setting and the hard setting  }\n\\centering\n\\begin{adjustbox}{width=\\textwidth}\n\\begin{tabular}{ccccccc}\n\t\\toprule\n\t\n\tDataset    &  \tnumber of frames  &  \tmaximum memory duration & number of distractors & size of training set & size of validation/test set    \\\\ \n\t\\midrule\n\t\n\tCanonical setting & 4 & 3 & 1 & 10000320 & 500016 &   \\\\\n\t\\midrule\n\t\n\tHard  setting & 8 & 7& 10 & 10000320 & 500016  \\\\\n\t\\bottomrule\t\n\\end{tabular}\n\\end{adjustbox}\n\\label{tab:parameters}\n\\end{table}\n\n", "meta": {"hexsha": "34d9821e33edc9e0e4de34542059d38be3cf1bf1", "size": 21865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "COG_publications/2019_neurips_kr2ml/appendix_model.tex", "max_stars_repo_name": "Bhaskers-Blu-Org1/mi-visual-reasoning-pubs", "max_stars_repo_head_hexsha": "4c5c503cb3976186d6eda4628f7c45914feba9fa", "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": "COG_publications/2019_neurips_kr2ml/appendix_model.tex", "max_issues_repo_name": "Bhaskers-Blu-Org1/mi-visual-reasoning-pubs", "max_issues_repo_head_hexsha": "4c5c503cb3976186d6eda4628f7c45914feba9fa", "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": "COG_publications/2019_neurips_kr2ml/appendix_model.tex", "max_forks_repo_name": "Bhaskers-Blu-Org1/mi-visual-reasoning-pubs", "max_forks_repo_head_hexsha": "4c5c503cb3976186d6eda4628f7c45914feba9fa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-30T10:13:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T10:13:26.000Z", "avg_line_length": 41.8869731801, "max_line_length": 625, "alphanum_fraction": 0.7034987423, "num_tokens": 7118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6014463613070666}}
{"text": "\\problemname{Assistant Ranking}\nThe online retailer Amagoogsoftbook currently offers $N$ different so-called ``home assistants'', which it wants to recommend to its customers.\nFor this recommendation, they wish to rank all the assistants.\nThe quality of this ranking is not very important -- multiple assistants may even be assigned the same rank -- but they wish to maximize the number of distinct ranks assigned, to lessen the decision fatigue of their customers.\n\nTo ensure that the ranking is not \\emph{completely} arbitrary, they have collected for each assistant $i$ two measurements $a_i$ and $b_i$ -- the quality of the jokes the assistant can tell and how nice are the compliments the assistant is able to give (clearly these are the two most important aspects).\nThese measurements are of course somewhat subjective, so we wish to ignore small differences in them.\nHowever, if for two given assistants $i$ and $j$ we have that $a_i + K < a_j$ or $b_i + K < b_j$, the ranking of assistant $j$ must be the same or higher than the ranking of assistant $i$.\nThis rule may force two products to be given the same ranking, for example if an assistant $i$ gives much better puns than assistant $j$, while assistant $j$ gives the superior self-esteem boosts.\n\nWhat is the maximum number of distinct ranks, taken over all possible rankings?\n\n\\section*{Input}\nThe first line contains the integers $1 \\le N \\le 100\\,000$ and $0 \\le K \\le 10^9$ -- the number of assistants and the measurement difference limit as described in the statement.\nThe next line contains the $N$ integers $a_1, a_2, \\dots, a_N$.\nThe next line contains the $N$ integers $b_1, b_2, \\dots, b_N$.\n\nAll measurements are between $0$ and $10^9$.\n\n\\section*{Output}\nOutput a single integer: the maximum number of distinct ranks.\n", "meta": {"hexsha": "18561b0fa3f237433334c326ebff0706518eab16", "size": 1794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assistantranking/problem_statement/problem.en.tex", "max_stars_repo_name": "Kodsport/nova-challenge-2018", "max_stars_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-13T13:38:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-13T13:38:16.000Z", "max_issues_repo_path": "assistantranking/problem_statement/problem.en.tex", "max_issues_repo_name": "Kodsport/nova-challenge-2018", "max_issues_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "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": "assistantranking/problem_statement/problem.en.tex", "max_forks_repo_name": "Kodsport/nova-challenge-2018", "max_forks_repo_head_hexsha": "e9d5e3d63a79c2191ca55f48438344d8b7719d90", "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.5454545455, "max_line_length": 304, "alphanum_fraction": 0.7675585284, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324587033253, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6014463543443882}}
{"text": "\\subsubsection{Beta Model (\\betamodel)}\n\nThe \\betamodel\\ is an analytic shape function widely used in X-ray\nanalysis to fit the radial density profile:\n\n\\begin{equation}\nn_e(x) = {{n_e}_0\\over{\\left[1 + x^2\\right]^{(3\\beta/2)}}}\n\\end{equation}\n\nThe line-integral of this function is therefore commonly used to fit the\nprojected 2D cluster profiles in SZ observations:\n\n\\begin{equation}\np(x) = {1\\over{\\left[1 + x^2\\right]^{(1-3\\beta/2)}}}\n\\end{equation}\n\nThe \\betamodel\\ can bs used in \\climax\\ by invoking \\code{addmodel}\nwith \\code{type = betamodel}.\n\n", "meta": {"hexsha": "125d7ee57936d086afb5cf8b1b6101e2744736db", "size": 554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/betamodel.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/betamodel.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/betamodel.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": 27.7, "max_line_length": 72, "alphanum_fraction": 0.7202166065, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.6477982315512489, "lm_q1q2_score": 0.6014215791564351}}
{"text": "\n\\section{Voting Protocol}\n\n% eventually consider moving to contributions subsection if needed\nThe voting protocol closely follows the cryptographic\nsetup described in Schoenmaker et. al.'s~\\cite{Cramer:1997:SOE:1754542.1754554}\nmulti authority election scheme.  Given the different threat model,\nthe threshold encryption multi authority features are eliminated\nand replaced with a single pollster service.\n\n% Threat model table?\n\nThis is justified on the grounds that neither preventing malicious voters from\nvoting nor defending against malicious authorities is a\ngoal of this solution.\n\nThe malicious voter handling aspect is left to the human level pollsters\nand human authorities which can presumably scale according to the level\nof interest in the specific poll.\nOur protocol ensures that the set of voting parties, the subset of eligible\nvoters selected after ballot casting, and the decisions about\naccepted votes are publicly verifiable.\nAnother aspect of differentiation is \\emph{coercion-freeness}, which\nis an important requirement for a trustable voting infrastucture,\nas described in~\\cite{Karlof:2005:CVP:1251398.1251401}.\nThis property follows from the fact that only the aggregate totals are ever\ndecrypted, thereby providing voters deniability about their vote,\nwhich in turn makes the\nelection coercion-free by allowing the voter to lie about the vote\nthey had cast\\footnote{Ideally one would add a legal clause at the bottom of the\n  ballot stating that it is your right, and under some circumstances,\n  perhaps your duty, to lie about your vote. Such a disclaimer\n  would make the deniability based coercion freeness obvious to\n  unsophisticated voters.  Achieving coercion freeness requires both social and\n  technological actions.  Our protocol provides the latter.}.\n\nMalicious authorities are not considered as a threat because we\npropose to establish authority honesty via open source implementation as well\nas massive public validation of the algorithms and artifacts involved.\nThe authority supports the fully open source voting protocol in an\nopen verifiable manner.  The voting protocol is explained below in terms of\nits phases:\n\n\\subsection{Poll creation}\nOn receiving a request to create a poll, the Pollster service\nchooses a large prime $p$, a generator $g$, and an integer private key $s < p$\nlarge enough such that an $O(\\sqrt s)$ time algorithm is computationally\ninfeasible.\nThe public key $h \\equiv g^s\\bmod p$ is computed from the private key.\nThe values $p$, $g$ and $h$\nare exposed on the public bulletin board.\n\nThis step shall also disclose the non-cryptographic\nattributes of the poll. For example, the expected number of voters,\nthe duration of the poll, as well as the\nlocations where a vote may be cast and the location of the\nbulletin board where the results shall be available.\n\nThis stage can also be used to cryptographically commit the\npolling parameters.  Accordingly the hash of the contents of the\ninitial bulletin board shall be stored on a blockchain\nin a future version of our implementation.\n\n\n\\subsection{Casting encrypted ballots}\n\nThe specific values sent out in the encrypted ballots depends on\nwhether the vote is positive or negative.  The values of the variables\nused in casting the universally verifiable ballot are shown in\nTable~\\ref{table:ballotparams}.  The values are expressed in terms of\na generator $G$ and random numbers $\\alpha$, $r_1$ and $r_2$.\n% TODO explain is G a new generator and if so why\n\n\n\\begin{table}[t]\n\\caption{Values of ballot parameters}\n\\begin{center}\n  \\begin{tabular}{c|c|c} \n    Variable & Vote $+1$ & Vote $-1$ \\\\\\hline\n    $x$   &  $g^\\alpha$ &   $g^\\alpha$ \\\\\n    $y$   &  $h^\\alpha G$ & $\\frac{h^\\alpha}{G}$  \\\\\n    $a_1$ &  $g^{r_1}x^{d_1}$ & $g^\\omega$  \\\\\n    $b_1$ &  $h^{r_1}(yG)^{d_1}$ & $h^\\omega$  \\\\\n    $a_2$ &  $g^\\omega$ &  $g^{r_2}x^{d_2}$ \\\\\n    $b_2$ &  $h^\\omega$ & $h^{r_2} \\big( \\frac{y}{G} \\big)^{d_2}$ \\\\\n\\end{tabular}\n\\label{table:ballotparams}\n\\end{center}\n\\end{table}\n\n\n\n% TODO : get fig from jcn and data from page in yellow book\nThe universally veriable ballot to be cast by the voter $v_i$\ncan be expressed as a 3-tuple $\\{T,C,D\\}$, where:\n\\begin{equation} \\label{eq3}\n\\begin{split}\nT & = \\{ x, y, a_1, b_1, a_2, b_2 \\} \\\\\nC & = H( T || v_i ) \\\\    % subtle conceptual bug - v_i is voter not verifier but see intro\nD & = \\{d_1, d_2, r_1, r_2 \\} \n\\end{split}\n\\end{equation}\n\nAny verifier needs to establish that i)\nthe vote itself is valid, i.e. is a $+1$ or $-1$, and ii) that the ElGamal\npair $(x,y) \\equiv (g^\\alpha, h^\\alpha m)$ is properly constructed using the\npublicly known values $g$ and $h$.  These properties follow from testing\nthe following on the encrypted ballot:\n\n\\begin{equation} \\label{eq4}\n\\begin{split}\nC & = d_1 + d_2  \\\\\na_1 & = g^{r_1} x^{d_1}  \\\\\nb_1 & = h^{r_1} (yG)^{d_1} \\\\\na_2 & = g^{r_2} x^{d_2} \\\\\nb_2 & = h^{r_2}(\\frac{y}{G})^{d_2} \\\\\n\\end{split}\n\\end{equation}\n\n\n\\subsection{Counting ballots}\n\nConsider the encrypted vote part of the ballot $(x,y) \\equiv (g^\\alpha, h^\\alpha G^m)$\nwhere $m \\in {+1, -1}$.\nThe homomorphic property of the encryption allows us to take the product(modulo\nthe large prime) of the ElGamal pairs, and the resultant values can be decrypted to\narrive at the total.   Consider several encrypted ballots\n$(x_i,y_i) \\equiv (g^{r_i} , h^{r_i} G^{m_i})$, and let \n\\[\n(X,Y) \\equiv (\\prod x_i , \\prod y_i) \n\\]\nThen it follows that:\n\\begin{equation} \\label{eq5}\n\\begin{split}\n  \\frac{Y}{X^s} & = \\frac{\\prod h^{r_i} G^{m_i}}{ \\prod (g^{r_i})^s } \\\\\n  & =  \\frac{\\prod g^{sr_i} G^{m_i}}{ \\prod (g^{sr_i}) } \\\\\n  & = \\prod G^{m_i} \\\\\n   & = G^{\\sum m_i}\n\\end{split}\n\\end{equation}\nHence the total vote count is given as $\\log_G \\frac{Y}{X^s}$, which can be\ncalculated by the pollster service as it knows the private key $s$ corresponding\nto this poll.\n\n% zkp of this total is correct\n", "meta": {"hexsha": "e04e4f6836089a6b6b388690a5a6739b45753434", "size": 5859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "protocol.tex", "max_stars_repo_name": "newlibertie/voting-protocol", "max_stars_repo_head_hexsha": "11eeb0ce9c3f86b29fa92c70961c9a660200362e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "protocol.tex", "max_issues_repo_name": "newlibertie/voting-protocol", "max_issues_repo_head_hexsha": "11eeb0ce9c3f86b29fa92c70961c9a660200362e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "protocol.tex", "max_forks_repo_name": "newlibertie/voting-protocol", "max_forks_repo_head_hexsha": "11eeb0ce9c3f86b29fa92c70961c9a660200362e", "max_forks_repo_licenses": ["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.1301369863, "max_line_length": 91, "alphanum_fraction": 0.7275985663, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.6477982043529715, "lm_q1q2_score": 0.6014215539053149}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\\markright{tfrsp}\n\\section*{\\hspace*{-1.6cm} tfrsp}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nSpectrogram time-frequency distribution.\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[tfr,t,f] = tfrsp(x)\n[tfr,t,f] = tfrsp(x,t)\n[tfr,t,f] = tfrsp(x,t,N)\n[tfr,t,f] = tfrsp(x,t,N,h)\n[tfr,t,f] = tfrsp(x,t,N,h,trace)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty tfrsp} computes the spectrogram distribution of a\n        discrete-time signal {\\ty x}. It corresponds to the squared modulus\n        of the short-time Fourier transform. Its expression writes\n\\[S_x(t,\\nu) = \\left|\\int_{-\\infty}^{+\\infty} x(u)\\ h^*(u-t)\\ e^{-j2\\pi \\nu\nu}\\ du\\right|^2.\\]\n\n\\hspace*{-.5cm}\\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}\nName & Description & Default value\\\\\n\\hline\n        {\\ty x}     & analyzed signal ({\\ty Nx=length(x)})\\\\\n        {\\ty t}     & time instant(s)          & {\\ty (1:Nx)}\\\\\n        {\\ty N}     & number of frequency bins & {\\ty Nx}\\\\\n        {\\ty h}     & smoothing window, {\\ty h} being normalized so as to\n                be  of unit energy.      & {\\ty window(odd(N/4))}\\\\ \n        {\\ty trace} & if nonzero, the progression of the algorithm is shown\n                                         & {\\ty 0}\\\\\n     \\hline {\\ty tfr}   & time-frequency representation\\\\\n        {\\ty f}     & vector of normalized frequencies\\\\\n\n\\hline\n\\end{tabular*}\n\\vspace*{.2cm}\n\nWhen called without output arguments, {\\ty tfrsp} runs {\\ty tfrqview}.\n\\end{minipage}\n\\vspace*{1cm}\n\n{\\bf \\large \\sf Example}\n\\begin{verbatim}\n         sig=fmlin(128,0.1,0.4);\n         h=window(17,'Kaiser'); \n         tfrsp(sig,1:128,64,h,1);\n\\end{verbatim}\n\n\\newpage\n\n{\\bf \\large \\sf See Also}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nall the {\\ty tfr*} functions.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf References}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n[1] W. Koenig, H. Dunn, L. Lacy ``The sound spectrograph'',\nJ. Acoust. Soc. Am., Vol. 18, No. 1, pp. 19-49, 1946.\\\\\n\n[2] J. Allen, L. Rabiner ``A Unified Approach to Short-Time Fourier\nAnalysis and Synthesis'' Proc. IEEE, Vol. 65, No. 11, pp. 1558-64, 1977. \n\\end{minipage}\n", "meta": {"hexsha": "16f30ecf813470ad9b91947b83c6edce54dc0ae2", "size": 2534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/tfrsp.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/tfrsp.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/tfrsp.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 28.4719101124, "max_line_length": 75, "alphanum_fraction": 0.6049723757, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6013174071465699}}
{"text": "\\documentclass[draft]{article}\n%\\usepackage[final]{graphics}\n% final means \"include the picture\".  draft means \"put a space with filename\"\n\\usepackage[final]{graphicx}\n\\usepackage{latexsym}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n%\\usepackage{showkeys}  %shows labels in margins see Gratzer p. 249\n\\setlength{\\abovecaptionskip}{0pt}\n\\setlength{\\parindent}{0cm} % no indent for paragraphs\n\\setlength{\\parskip}{1.5ex} % more space between paragraphs.\n\\setlength{\\textwidth}{7in} % width of text \n\\setlength{\\oddsidemargin}{0pt}  % makes margin narrower\n\\title{Double Pendulum as Rigid Bodies}\n\\author{Erik Neumann\\\\\nerikn@myphysicslab.com}\n\\date{April 2, 2011}\n\\begin{document}\n\n\\maketitle\n%===============================================================\n\\section{Introduction}\n\nThis is a derivation of the equations of motion for a double pendulum where we regard the pendulums as rigid bodies.  In an alternate double pendulum model, the so-called ``ideal double pendulum'', the two pendulums are modelled as massless rods with a point mass at the end of each pendulum rod.  The present rigid body model of the double pendulum allows for more realistic configurations, because the pendulums can have any distribution of mass and can be connected together at any point.  The mass distribution is reflected in the rotational inertia of each pendulum.  By contrast in the ideal double pendulum model, the rotational inertia is zero for each pendulum and the connection must be at the end points of the massless rods.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.40 \\textwidth]{Rigid_Double_Pendulum_fig_1.pdf}\n    \\caption{Rigid Body Double Pendulum Model} \\label{fig_1}\n\\end{figure}\n\nPlease refer to figure \\ref{fig_1} below.\n\nLet $\\mathbf{i}$ be the unit vector along the $x$ axis, and let $\\mathbf{j}$ be the unit vector along the $y$ axis.  We regard $y$ as increasing upwards (this is the usual mathematical convention, as opposed to computer graphics systems which often have $y$ increasing downwards).  \n\nThe fixed pivot, which we name pivot 1, is at location $\\mathbf{P_1}$.  Pivot 2 is the moving pivot point connecting the two pendulums at location $\\mathbf{P_2}$.\n\nLet pendulum 1 be the upper pendulum.  It is connected to a fixed location at pivot 1, and connected to the lower pendulum at pivot 2.\\\\\nLet $\\mathbf{X_1} = x_1 \\mathbf{i} + y_1 \\mathbf{j}$ be the location of the center of mass of pendulum 1.\\\\\nLet $\\mathbf{R_1}$ be the vector from pivot 1 to the center of mass of pendulum 1, with length $R_1$.\\\\\nLet $\\theta_1$ be the angle at pivot 1 between $\\mathbf{R_1}$ and the downward vertical position.\\\\\nLet $\\mathbf{L_1}$ be the vector from pivot 1 to pivot 2, with length $L_1$.\\\\\nLet $\\phi$ be the angle from vector $\\mathbf{R_1}$ to $\\mathbf{L_1}$.  Note that $\\phi$ is a constant.\n\nLet pendulum 2 be the lower pendulum.  It is connected to the upper pendulum at pivot 2.\\\\\nLet $\\mathbf{X_2} = x_2 \\mathbf{i} + y_2 \\mathbf{j}$ be the location of the center of mass of pendulum 2.\\\\\nLet $\\mathbf{R_2}$ be the vector from pivot 2 to the center of mass of pendulum 2, with length $R_2$.\\\\\nLet $\\theta_2$ be the angle at pivot 2 between $\\mathbf{R_2}$ and the downward vertical position.\n\nLet $m_1$, $m_2$ be the mass of pendulum 1 and 2 respectively.\\\\\nLet $I_1$, $I_2$ be the rotational inertia about the center of mass of pendulum 1 and 2 respectively.\n\n%===============================================================\n\\section{Kinematics}\nWe have the following relationships just from the geometry of the double pendulum, without using any information about forces. \n\\[\n\\mathbf{R_1} = R_1 \\sin(\\theta_1) \\mathbf{i} - R_1 \\cos(\\theta_1) \\mathbf{j}\n\\]\n\\[\n\\mathbf{R_2} = R_2 \\sin(\\theta_2) \\mathbf{i} - R_2 \\cos(\\theta_2) \\mathbf{j}\n\\]\n\\[\n\\mathbf{L_1} = L_1 \\sin(\\theta_1+\\phi) \\mathbf{i} - L_1 \\cos(\\theta_1+\\phi) \\mathbf{j}\n\\]\n\n\\[\n\\mathbf{X_1} = \\mathbf{R_1}\n\\]\n\\[\nx_1 = R_1 \\sin(\\theta_1)\n\\]\n\\[\ny_1 = -R_1 \\cos(\\theta_1)\n\\]\n\\[\n\\mathbf{X_2} = \\mathbf{L_1} + \\mathbf{R_2}\n\\]\n\\[\nx_2 = L_1 \\sin(\\theta_1+\\phi) + R_2 \\sin(\\theta_2)  \n\\]\n\\[\ny_2 = -L_1 \\cos(\\theta_1+\\phi) - R_2 \\cos(\\theta_2) \n\\]\n\nTake the first derivative with respect to time to get velocity.\n\n\\[\n\\mathbf{X_1'} = \\mathbf{R_1'}\n\\]\n\\[\nx_1' = \\theta_1' R_1 \\cos(\\theta_1)\n\\]\n\\[\ny_1' = \\theta_1' R_1 \\sin(\\theta_1)\n\\]\n\\[\n\\mathbf{X_2'} = \\mathbf{L_1'} + \\mathbf{R_2'}\n\\]\n\\[\nx_2' = \\theta_1' L_1 \\cos(\\theta_1+\\phi) + \\theta_2' R_2 \\cos(\\theta_2)\n\\]\n\\[\ny_2' = \\theta_1' L_1 \\sin(\\theta_1+\\phi) + \\theta_2' R_2 \\sin(\\theta_2)\n\\]\n\nTake the second derivative with respect to time to get acceleration.\n\n\\[\n\\mathbf{X_1''} = \\mathbf{R_1''}\n\\]\n\\begin{equation}\\label{E01}\nx_1'' = -\\theta_1'^2 R_1 \\sin(\\theta_1) + \\theta_1'' R_1 \\cos(\\theta_1)\n\\end{equation}\n\\begin{equation}\\label{E02}\ny_1'' = \\theta_1'^2 R_1 \\cos(\\theta_1) + \\theta_1'' R_1 \\sin(\\theta_1)\n\\end{equation}\n\\[\n\\mathbf{X_2''} = \\mathbf{L_1''} + \\mathbf{R_2''}\n\\]\n\\begin{equation}\\label{E1}\nx_2'' = -\\theta_1'^2 L_1 \\sin(\\theta_1+\\phi) + \\theta_1'' L_1 \\cos(\\theta_1+\\phi)\n- \\theta_2'^2 R_2 \\sin(\\theta_2) + \\theta_2'' R_2 \\cos(\\theta_2)\n\\end{equation}\n\\begin{equation}\\label{E2}\ny_2'' = \\theta_1'^2 L_1 \\cos(\\theta_1+\\phi) + \\theta_1'' L_1 \\sin(\\theta_1+\\phi)\n+ \\theta_2'^2 R_2 \\cos(\\theta_2) + \\theta_2'' R_2 \\sin(\\theta_2)\n\\end{equation}\n\n\n%===============================================================\n\\section{Forces}\n\nLet $\\mathbf{T_1} = T_{1x} \\mathbf{i} + T_{1y} \\mathbf{j}$ be the force vector operating on pendulum 1 at pivot 1.\\\\\nLet $\\mathbf{T_2} = T_{2x} \\mathbf{i} + T_{2y} \\mathbf{j}$ be the force vector operating on pendulum 1 at pivot 2.\nThen by Newton's law of equal and opposite reaction, $-\\mathbf{T_2}$ is the force vector operating on pendulum 2 at pivot 2.\n\nFrom Newton's laws of motion we can write the following force equations:\n\\[\nm_1 \\mathbf{X_1}'' = \\mathbf{T_1} + \\mathbf{T_2} - m_1 g \\mathbf{j}\n\\]\n\\begin{equation}\\label{E3}\nm_1 x_1'' = T_{1x} + T_{2x}\n\\end{equation}\n\\begin{equation}\\label{E4}\nm_1 y_1'' = T_{1y} + T_{2y} - m_1 g\n\\end{equation}\n\\begin{multline}\\label{E5}\n  I_1 \\theta_1'' = (-\\mathbf{R_1}) \\times \\mathbf{T_1} + (\\mathbf{L_1 - R_1}) \\times \\mathbf{T_2} \\\\\n  = -(R_1 \\sin(\\theta_1) T_{1y} + R_1 \\cos(\\theta_1) T_{1x}) \\\\\n  + (L_1 \\sin(\\theta_1+\\phi)- R_1 \\sin(\\theta_1))  T_{2y} \n  + (L_1 \\cos(\\theta_1+\\phi) - R_1 \\cos(\\theta_1)) T_{2x}\n\\end{multline}\n\\[\nm_2 \\mathbf{X_2}'' = -\\mathbf{T_2} - m_2 g \\mathbf{j}\n\\]\n\\begin{equation}\\label{E6}\nm_2 x_2'' = -T_{2x}\n\\end{equation}\n\\begin{equation}\\label{E7}\nm_2 y_2'' = -T_{2y} - m_2 g\n\\end{equation}\n\\begin{equation}\\label{E8}\n  I_2 \\theta_2'' = (-\\mathbf{R_2}) \\times (-\\mathbf{T_2}) \n  = R_2 \\sin(\\theta_2) T_{2y} + R_2 \\cos(\\theta_2) T_{2x}\n\\end{equation}\n\nTo derive these force equations we used Newton's law of motion $\\mathbf{F} = m \\mathbf{a}$ and the rotational version for angular torque $I \\theta'' = \\tau$.  For more about how to calculate the torque see \\texttt{http://www.myphysicslab.com/collision.html}.\n\n%===============================================================\n\\section{Equations of Motion}\n\nSubstitute the four equations (\\ref{E01}) thru (\\ref{E2}) into the six equations (\\ref{E3}) thru (\\ref{E8}) to eliminate the unknowns $x_1''$, $y_1''$, $x_2''$, $y_2''$.  This gives us modified versions of the six equations (\\ref{E3}) thru (\\ref{E8}) with  six unknowns: $T_{1x}$, $T_{2x}$,  $T_{1y}$, $T_{2y}$, $\\theta_1''$,  $\\theta_2''$.  We then solve for $\\theta_1''$, $\\theta_2''$ and eliminate the other four unknowns.  See the accompanying Mathematica notebook \\texttt{Rigid\\_Double\\_Pendulum\\_Algebra.nb} for the calculations.\n\n\\small\n\\begin{multline}\n\\theta_1'' = -\\Big(2 g m_1 R_1 (I_2 + m_2 R_2^2) \\sin(\\theta_1) + L_1 m_2 \\Big(g (2 I_2 + m_2 R_2^2) \\sin(\\theta_1 + \\phi) + \\\\\nR_2 \\Big(g m_2 R_2 \\sin(\\theta_1 - 2 \\theta_2 + \\phi) + 2 (\\theta_2'^2 (I_2 + m_2 R_2^2) +\n\\theta_1'^2 L_1 m_2 R_2 \\cos(\\theta_1 - \\theta_2 + \\phi)) \\sin(\\theta_1 - \\theta_2 + \\phi)\n\\Big)\\Big)\\Big)\\\\\n\\Big/\n\\Big(2 I_2 L_1^2 m_2 + 2 I_2 m_1 R_1^2 + \nL_1^2 m_2^2 R_2^2 + 2 m_1 m_2 R_1^2 R_2^2 + 2 I_1 (I_2 + m_2 R_2^2) - \nL_1^2 m_2^2 R_2^2 \\cos(2 (\\theta_1 - \\theta_2 + \\phi))\\Big) \n\\end{multline}\n\n\\begin{multline}\n\\theta_2'' = \\Big(m_2 R_2 \\Big(-(g (2 I_1 + L_1^2 m_2 + 2 m_1 R_1^2) \\sin(\\theta_2)) + \\\\\nL_1 \\Big(g m_1 R_1 \\sin(\\theta_2 - \\phi) + 2 \\theta_1'^2 (I_1 + L_1^2 m_2 + m_1 R_1^2) \\sin(\\theta_1 - \\theta_2 + \\phi) + \\\\\n\\theta_2'^2 L_1 m_2 R_2 \\sin(2 (\\theta_1 - \\theta_2 + \\phi)) + g m_1 R_1 \\sin(2 \\theta_1 - \\theta_2 + \\phi) + \ng L_1 m_2 \\sin(2 \\theta_1 - \\theta_2 + 2 \\phi)\\Big)\\Big)\\Big)\\\\\n\\Big/\n\\Big(2 I_2 L_1^2 m_2 + 2 I_2 m_1 R_1^2 + L_1^2 m_2^2 R_2^2 + \n2 m_1 m_2 R_1^2 R_2^2 + 2 I_1 (I_2 + m_2 R_2^2) - L_1^2 m_2^2 R_2^2 \\cos(2 (\\theta_1 - \\theta_2 + \\phi))\\Big)\n\\end{multline}\n\nDo these equations match the ideal double pendulum equations? Yes.\n\nIn the ideal double pendulum there are two point masses at the end of each pendulum.  This corresponds to setting $L_1=R_1$, $\\phi=0$, and having rotational inertia be zero for both pendulums.  If we substitute these values into the above equations, we do indeed get the ideal double pendulum equations (see the Mathematica document).\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "513c6453a1853c742626a793bc67a03a1a179229", "size": 9172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/docs/Rigid_Double_Pendulum.tex", "max_stars_repo_name": "PSDev15/myphysicslab", "max_stars_repo_head_hexsha": "a32e54795e4424c29d7b8577433ee735fb80a6da", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 273, "max_stars_repo_stars_event_min_datetime": "2016-11-11T10:28:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T03:06:53.000Z", "max_issues_repo_path": "src/docs/Rigid_Double_Pendulum.tex", "max_issues_repo_name": "PSDev15/myphysicslab", "max_issues_repo_head_hexsha": "a32e54795e4424c29d7b8577433ee735fb80a6da", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-11-19T17:56:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-09T00:19:51.000Z", "max_forks_repo_path": "src/docs/Rigid_Double_Pendulum.tex", "max_forks_repo_name": "PSDev15/myphysicslab", "max_forks_repo_head_hexsha": "a32e54795e4424c29d7b8577433ee735fb80a6da", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2016-12-11T16:18:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T15:15:21.000Z", "avg_line_length": 44.9607843137, "max_line_length": 736, "alphanum_fraction": 0.6662668993, "num_tokens": 3506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6013174028572729}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{natbib,unatbib}\n\\usepackage[nohide,twocolumn]{ulecnot}\n\n\\usepackage{bussproofs}\n\n\n\\pagestyle{fancy}\n\\lhead{COGS 502 -- Programming and Logic}\n\\chead{$\\lambda$-Calculus}\n\\rhead{Updated \\it \\today}\n\\lfoot{Umut \\\"Ozge}\n\\cfoot{}\n\\rfoot{Page \\thepage/\\pageref{LastPage}}\n\\setlength{\\headheight}{13.6pt}\n\n\\usepackage{tikz-qtree}\n\n\\begin{document}\n\n\n%\\section{Lambda operator, bondage, freedom, substitution}\n\\section{Expressions}\n\n\\ezimeti{\n\n\\item Our basic notions here are \\uterm{expression} and \\uterm{evaluation}.\n\n\\begin{udefinition}[Expression]\nLet $A=\\{ a,b,\\ldots,z\\}$ be the set of names.\n\\begin{itemize}\n\\item[i.] all names are expressions; \n\\item[ii.] if $\\omega_1$ and $\\omega_2$ are expressions, so is $(\\omega_1\\omega_2)$;\n\\item[iii.] if $\\omega$ is an expression and $\\alpha$ is a name, then\n$(\\lambda\\alpha.\\omega)$ is an expression.\n\\item[iv.] nothing else is an expression.\n\\end{itemize}\n\\end{udefinition} \n\n\\item Some example expressions:\n\\renewcommand{\\arraycolsep}{6pt}\n\\renewcommand{\\arraystretch}{2}\n\n$$\n\\begin{array}{cccc}\nx & (xy) & (x(yz))  & ((xy)z) \\\\\n(\\lambda x.x) & (\\lambda y.(\\lambda x.x)) & (\\lambda z.(x(\\lambda y.(yz)))) &\n(x(\\lambda z.(\\lambda y.(yz))))\\\\\nx(\\lambda x.x) & (\\lambda y.(\\lambda x.x))(\\lambda x.x) & (\\lambda y.(\\lambda x.x))(\\lambda x.x)(xy)& (x(yz))((xy)z)\n\\end{array}\n$$\n\n\\item Note that in lambda calculus we write $f x$ rather than the usual $f(x)$\nto represent the application of function $f$ to the argument $x$.\n\n\n\\item[] {\\bf Notational conventions:}\n\n\\ezimeti{\n\\item[i.] Omit the outermost parentheses:\n\t\n$$\n\\begin{array}{cccc}\nx & xy & x(yz)  & (xy)z \\\\\n\\lambda x.x & \\lambda y.(\\lambda x.x) & \\lambda z.(x(\\lambda y.(yz))) & x(\\lambda z.(\\lambda y.(yz)))\n\\end{array}\n$$\n\n\\item[ii.] Parentheses associate to left:    \n\n\\begin{align*}\nfxyz & \\equiv (((fx)y)z)\n\\end{align*}\n\n\\item[iii.] Stacked lambdas:\n\\begin{align*}\n(\\lambda f.(\\lambda x.(f(fx))))  &\\equiv \\lambda f \\lambda x.(f(fx)) \\\\\n& \\equiv \\lambda f x.(f(fx))\n\\end{align*}\n}\n\n\\item The notions of bondage, freedom and substitution we covered in predicate\nlogic apply here as well.\n\n\\section{$\\beta$-reduction}\n\n\\item An expression of the form $(\\lambda \\alpha.\\gamma)\\omega$ is called a\n\\uterm{$\\beta$-redex}. \n\n\n\\item It can be \\uterm{$\\beta$-reduced} to $\\subs{\\gamma}{\\omega}{\\alpha}$,\ncalled a \\uterm{reduct}, if $\\omega$ is free for $\\alpha$ in $\\gamma$.\n\n\\item  A lambda expression can be reduced by turning all the redexes to reducts,\nwhich results in a \\uterm{$\\beta$-normal} form.\n\n\\item Some example reductions:\n\\begin{align*}\n(\\lambda f.fx)g  & \\breduce gx \\\\\n(\\lambda f.fx)ga  & \\breduce gxa \\\\\n(\\lambda f.fx)(ga) & \\breduce gax \\\\\n(\\lambda f\\lambda x.fx)g a & \\breduce ga \\\\\n%(\\lambda x\\lambda y \\lambda z.x(yz))f & \\breduce \\\\\n\\end{align*}\n\n\\item There may be more than one redex in a\nexpression:\n\n\\begin{align*}\n(\\lambda x.y)((\\lambda z.zz)(\\lambda w.w)) & \\breduce (\\lambda x.y)((\\lambda w.w)(\\lambda w.w))\\\\\n\t\t\t\t\t\t\t\t\t\t\t& \\breduce (\\lambda x.y)(\\lambda w.w)\n\t\t\t\t\t\t\t\t\t\t\t& \\breduce y \n\\end{align*}\n\n\\item Another reduction of the same expression would be:\n\n\\begin{align*}\n(\\lambda x.y)((\\lambda z.zz)(\\lambda w.w)) & \\breduce y \n\\end{align*}\n\n\\item The first is called the \\uterm{applicative order} reduction; the second is\ncalled the \\uterm{normal order} reduction.\n\n\\item Reduce the following expressions:\n\\begin{align*}\n(\\lambda x. m x)j\\\\\n(\\lambda y. y j)m\\\\\n(\\lambda x.\\lambda y. y(y x))jm\\\\\n(\\lambda y.y j)(\\lambda x. m x)\\\\\n(\\lambda x. xx)(\\lambda y. yyy)\n\\end{align*}\n\n\n\n\n\n\n\n% \\item Reduce the following expression in both applicative and normal order:\n% \n% \\begin{align*}\n% (\\lambda p_1\\lambda p_2. p_1 0 \\land p_2)(\\lambda x. x\\not= 0)((\\lambda y.\\frac{5}{y} = 0)0)\n% \\end{align*}\n\n\n}\n\\section{Lambda calculus in action: some examples}\n\n\\subsection{Logic}\n\\ezimeti{\n\\item Let's define the truth values:\n\n\\begin{align*}\n\\combf{T} \\equiv \\lambda x\\lambda y.x\\\\\n\\combf{F} \\equiv \\lambda x\\lambda y.y\n\\end{align*}\n\n\\item Verify that $\\lambda x\\lambda y.yxy$ behaves like \\emph{and} in prefix\nnotation (i.e. $\\land p q$). \n\n\\item Can you think of lambda expressions for $\\lor$ and $-$?\n\\item What about an if-then-else function that applies to the test, a function\nto execute if the test is true and a function to execute if the test is false.     \n\n}\n\\subsection{Arithmetic}\n\n\\ezimeti{\n\n\\item Number can be represented as lambda expressions in the following way:\n\\begin{align*}\n0 & \\equiv \\lambda f\\lambda x.x\\\\\n1 & \\equiv \\lambda f\\lambda x.fx\\\\\n2 & \\equiv \\lambda f\\lambda x.f(fx)\\\\\n3 & \\equiv \\lambda f\\lambda x.f(f(fx))\\\\\n\\vdots\n\\end{align*}\n\n\n\\item A successor function which returns $n+1$ given $n$ is:\n\\begin{align*}\n\\mathbf{S}\\equiv \\lambda a\\lambda f\\lambda x. f(afx)\n\\end{align*}\n\n\\item Here are addition and multiplication (again in prefix notation); verify\nthat they do what they are meant to do. \n\n\\begin{align*}\n\\mathbf{+} & \\equiv \\lambda a\\lambda b\\lambda f\\lambda x.af(bfx)\\\\\n\\mathbf{\\times} & \\equiv \\lambda a\\lambda b\\lambda f.a(bf)\n\\end{align*}\n\n\n}\n\n\\end{document}\n", "meta": {"hexsha": "fcfe1dace35b8c36bc1928cbd5c015a49b074489", "size": 5060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/03_cogs502-lambda-calculus.tex", "max_stars_repo_name": "umutozge/cogs502", "max_stars_repo_head_hexsha": "9e71b58f61cfa42408a72febeadcf2ff726986fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-15T17:01:09.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-15T17:01:09.000Z", "max_issues_repo_path": "notes/03_cogs502-lambda-calculus.tex", "max_issues_repo_name": "umutozge/cogs502", "max_issues_repo_head_hexsha": "9e71b58f61cfa42408a72febeadcf2ff726986fb", "max_issues_repo_licenses": ["MIT"], "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/03_cogs502-lambda-calculus.tex", "max_forks_repo_name": "umutozge/cogs502", "max_forks_repo_head_hexsha": "9e71b58f61cfa42408a72febeadcf2ff726986fb", "max_forks_repo_licenses": ["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.6852791878, "max_line_length": 116, "alphanum_fraction": 0.6695652174, "num_tokens": 1685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.705785040214066, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.6012955425976901}}
{"text": "% Part: first-order-logic\n% Chapter: model-theory\n% Section: reducts-and-expansions\n\n\\documentclass[../../../include/open-logic-section]{subfiles}\n\n\\begin{document}\n\n\\olfileid{mod}{bas}{red}\n\\section{Reducts and Expansions}\n\nOften it is useful or necessary to compare languages which have\nsymbols in common, as well as !!{structure}s for these languages.  The\nmost comon case is when all the symbols in !!a{language}~$\\Lang{L}$\nare also part of !!a{language}~$\\Lang{L'}$, i.e., $\\Lang{L} \\subseteq\n\\Lang{L'}$. An $\\Lang{L}$-!!{structure}~$\\Struct{M}$ can then always\nbe expanded to an $\\Lang{L'}$-!!{structure} by adding interpretations\nof the additional symbols while leaving the interpretations of the\ncommon symbols the same.  On the other hand, from an\n$\\Lang{L'}$-structure~$\\Struct{M'}$ we can obtain an\n$\\Lang{L}$-structure simpy by ``forgetting'' the interpretations of\nthe symbols that do not occur in~$\\Lang{L}$.\n\n\\begin{defn}\n\\ollabel{defn:reduct}\nSuppose $\\Lang L \\subseteq \\Lang L'$, $\\Struct M$ is an\n$\\Lang L$-!!{structure} and $\\Struct M'$ is an $\\Lang L'$-!!{structure}.\n$\\Struct M$ is the \\emph{reduct} of $\\Struct M'$ to $\\Lang L$, and\n$\\Struct M'$ is an \\emph{expansion} of $\\Struct M$ to $\\Lang L'$ iff\n\\begin{enumerate}\n\\item $\\Domain{M} = \\Domain{M'}$\n\\item For every !!{constant}~$c \\in \\Lang L$, $\\Assign{c}{M} =\n  \\Assign{c}{M'}$.\n\\item For every !!{function}~$f \\in \\Lang L$, $\\Assign{f}{M} =\n  \\Assign{f}{M'}$.\n\\item For every !!{predicate}~$P \\in \\Lang L$, $\\Assign{P}{M} =\n  \\Assign{P}{M'}$.\n\\end{enumerate}\n\\end{defn}\n\n\\begin{prop}\n\\ollabel{prop:reduct}\nIf an $\\Lang{L}$-!!{structure}~$\\Struct{M}$ is a reduct of an\n$\\Lang{L'}$-!!{structure} $\\Struct{M'}$, then for all\n$\\Lang{L}$-!!{sentence}s~$!A$,\n\\[\n\\Sat{M}{!A} \\text{ iff } \\Sat{M'}{!A}.\n\\]\n\\end{prop}\n\n\\begin{proof}\n  Exercise.\n\\end{proof}\n\n\\begin{prob}\nProve \\olref[mod][bas][red]{prop:reduct}.\n\\end{prob}\n\n\\begin{defn}\nWhen we have an $\\Lang{L}$-structure $\\Struct{M}$, and $\\Lang{L'} =\n\\Lang{L} \\cup \\{P\\}$ is the expansion of $\\Lang{L}$ obtained by adding\na single $n$-place !!{predicate}~$P$, and $R \\subseteq \\Domain{M}^n$\nis an $n$-place relation, then we write $\\Expan{M}{R}$ for the\nexpansion~$\\Struct{M'}$ of~$\\Struct{M}$ with $\\Assign{P}{M'} = R$.\n\\end{defn}\n\n\\end{document}\n", "meta": {"hexsha": "84d34ded2fcc4f6f1b62e58eae1b90ca7dd63508", "size": 2273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/model-theory/basics/reducts-and-expansions.tex", "max_stars_repo_name": "grafoid/OpenLogic", "max_stars_repo_head_hexsha": "14039c24df2432fb4b8e360a3aeeb09df7ddab92", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-17T00:08:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T01:35:02.000Z", "max_issues_repo_path": "content/model-theory/basics/reducts-and-expansions.tex", "max_issues_repo_name": "grafoid/OpenLogic", "max_issues_repo_head_hexsha": "14039c24df2432fb4b8e360a3aeeb09df7ddab92", "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": "content/model-theory/basics/reducts-and-expansions.tex", "max_forks_repo_name": "grafoid/OpenLogic", "max_forks_repo_head_hexsha": "14039c24df2432fb4b8e360a3aeeb09df7ddab92", "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": 33.4264705882, "max_line_length": 72, "alphanum_fraction": 0.6511218654, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.6012955280735143}}
{"text": "\\chapter{Fundamental groups}\nTopologists can't tell the difference between a coffee cup and a doughnut.\nSo how do you tell \\emph{anything} apart?\n\nThis is a very hard question to answer, but one way we can\ntry to answer it is to find some \\emph{invariants} of the space.\nTo draw on the group analogy, two groups are clearly not isomorphic if,\nsay, they have different orders, or if one is simple and the other isn't, etc.\nWe'd like to find some similar properties for topological spaces\nso that we can actually tell them apart.\n\nTwo such invariants for a space $X$ are\n\\begin{itemize}\n\t\\ii Defining homology groups $H_1(X)$, $H_2(X)$, \\dots\n\t\\ii Defining homotopy groups $\\pi_1(X)$, $\\pi_2(X)$, \\dots\n\\end{itemize}\nHomology groups are hard to define, but in general easier to compute.\nHomotopy groups are easier to define but harder to compute.\n\nThis chapter is about the fundamental group $\\pi_1$.\n\n\n\\section{Fusing paths together}\nRecall that a \\emph{path} in a space $X$ is a function $[0,1] \\to X$.\nSuppose we have paths $\\gamma_1$ and $\\gamma_2$\nsuch that $\\gamma_1(1) = \\gamma_2(0)$.\nWe'd like to fuse\\footnote{%\n\tAlmost everyone else in the world uses ``gluing'' to describe this\n\tand other types of constructs.\n\tBut I was traumatized by Elmer's glue when I was in high school\n\tbecause I hated the stupid ``make a poster'' projects and hated\n\thaving to use glue on them.\n\tSo I refuse to talk about ``gluing'' paths together, referring\n\tinstead to ``fusing'' them together, which sounds cooler anyways.\n} them together to get a path $\\gamma_1 \\ast \\gamma_2$.  Easy, right?\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(8cm);\n\t\tbigblob(\"$X$\");\n\t\tpair A = Drawing(\"\\gamma_1(0)\", (-3,-1));\n\t\tpair B = Drawing(\"\\gamma_1(1) = \\gamma_2(0)\", (1,1), dir(90));\n\t\tpair C = Drawing(\"\\gamma_2(1)\", (2,-2), dir(-90));\n\t\tpath p = A..(-2,0)..(0,0.5)..B;\n\t\tpath q = B..(1.8,-0.5)..C;\n\t\tdraw(p, red, EndArrow);\n\t\tdraw(q, blue, EndArrow);\n\t\tMP(\"\\gamma_1\", midpoint(p), dir(90));\n\t\tMP(\"\\gamma_2\", midpoint(q), dir(0));\n\t\\end{asy}\n\\end{center}\n\nWe unfortunately do have to hack the definition a tiny bit. In an ideal world, we'd have a path $\\gamma_1 : [0,1] \\to X$ and $\\gamma_2 : [1,2] \\to X$ and we could just merge them together to get $\\gamma_1 \\ast \\gamma_2 : [0,2] \\to X$.\nBut the ``$2$'' is wrong here.\nThe solution is that we allocate $[0, \\half]$ for the first path\nand $[\\half, 1]$ for the second path; we run ``twice as fast''.\n\n\\begin{definition}\n\tGiven two paths $\\gamma_1, \\gamma_2 : [0,1] \\to X$\n\tsuch that $\\gamma_1(1) = \\gamma_2(0)$, we define\n\ta path $\\gamma_1 \\ast \\gamma_2 : [0,1] \\to X$ by\n\t\\[ \n\t\t(\\gamma_1 \\ast \\gamma_2)(t)\n\t\t=\n\t\t\\begin{cases}\n\t\t\t\\gamma_1(2t) & 0 \\le t \\le \\half \\\\\n\t\t\t\\gamma_2(2t-1) & \\half \\le t \\le 1.\n\t\t\\end{cases}\n\t\t\\]\n\\end{definition}\n\nThis hack unfortunately reveals a second shortcoming: this ``product'' is not associative.\nIf we take $(\\gamma_1 \\ast \\gamma_2) \\ast \\gamma_3$ for some suitable paths,\nthen $[0, \\frac14]$, $[\\frac14, \\frac12]$ and $[\\frac12, 1]$\nare the times allocated for $\\gamma_1$, $\\gamma_2$, $\\gamma_3$.\n\\begin{ques}\n\tWhat are the times allocated\n\tfor $\\gamma_1 \\ast (\\gamma_2 \\ast \\gamma_3)$?\n\\end{ques}\nBut I hope you'll agree that even though this operation isn't associative,\nthe reason it fails to be associative is kind of stupid.\nIt's just a matter of how fast we run in certain parts.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tunitsize(6cm);\n\t\tDrawing( unitsquare);\n\t\tMP(\"0\", (0,0), S);\n\t\tMP(\"1\", (1,0), S);\n\t\tMP(\"\\frac{1}{4}\", (1/4, 0), S);\n\t\tMP(\"\\frac{1}{2}\", (1/2, 0), S);\n\t\tMP(\"0\", (0,1), N);\n\t\tMP(\"1\", (1,1), N);\n\t\tMP(\"\\frac{3}{4}\", (3/4, 1), N);\n\t\tMP(\"\\frac{1}{2}\", (1/2, 1), N);\n\t\tMP(\"\\gamma_1\", (1/8, 0), N);\n\t\tMP(\"\\gamma_2\", (3/8, 0), N);\n\t\tMP(\"\\gamma_3\", (3/4, 0), N);\n\t\tMP(\"\\gamma_1\", (1/4, 1), S);\n\t\tMP(\"\\gamma_2\", (5/8, 1), S);\n\t\tMP(\"\\gamma_3\", (7/8, 1), S);\n\n\t\tMP(\"\\boxed{\\gamma_1 \\ast \\left( \\gamma_2 \\ast \\gamma_3 \\right)}\", (0.5,1.2), origin);\n\t\tMP(\"\\boxed{\\left( \\gamma_1 \\ast \\gamma_2 \\right) \\ast \\gamma_3}\", (0.5,-0.2), origin);\n\n\t\tDrawing((1/4,0)--(1/2,1), blue);\n\t\tDrawing((1/2,0)--(3/4,1), blue);\n\t\tDrawing( (1/2,0)--(1/2,1), dotted);\n\t\\end{asy}\n\\end{center}\n\nSo as long as we're fusing paths together,\nwe probably don't want to think of $[0,1]$ itself too seriously.\nAnd so we only consider everything up to (path) homotopy equivalence.\n(Recall that two paths $\\alpha$ and $\\beta$ are homotopic if\nthere's a path homotopy $F : [0,1]^2 \\to X$ between them,\nwhich is a continuous deformation from $\\alpha$ to $\\beta$.)\nIt is definitely true that\n\\[\n\t\\left( \\gamma_1 \\ast \\gamma_2 \\right) \\ast \\gamma_3\n\t\\simeq \n\t\\gamma_1 \\ast \\left( \\gamma_2 \\ast \\gamma_3 \\right) . \\]\nIt is also true that if $\\alpha_1 \\simeq \\alpha_2$ and $\\beta_1 \\simeq \\beta_2$\nthen $\\alpha_1 \\ast \\beta_1 \\simeq \\alpha_2 \\ast \\beta_2$.\n\nNaturally, homotopy is an equivalence relation,\nso paths $\\gamma$ lives in some ``homotopy type'',\nthe equivalence classes under $\\simeq$. We'll denote this $[\\gamma]$.\nThen it makes sense to talk about $[\\alpha] \\ast [\\beta]$.\nThus, \\textbf{we can think of $\\ast$ as an operation on homotopy classes}.\n\n\n\\section{Fundamental groups}\n\\prototype{$\\pi_1(\\RR^2)$ is trivial and $\\pi_1(S^1) \\cong \\ZZ$.}\n\nAt this point I'm a little annoyed at keeping track of endpoints,\nso now I'm going to specialize to a certain type of path.\n\\begin{definition}\n\tA \\vocab{loop} is a path with $\\gamma(0) = \\gamma(1)$.\n\\end{definition}\n\\begin{center}\n\t\\begin{asy}\n\t\tbigblob(\"$X$\");\n\t\tpair A = Drawing(\"x_0\", (-1,0), dir(100));\n\t\tpath p = A..(1,1)..(2,0)..(0.5,-1)..(-1.5,-0.5)..cycle;\n\t\tdraw(p, blue, EndArrow);\n\t\tMP(\"\\gamma\", midpoint(p), dir(-20));\n\t\\end{asy}\n\\end{center}\n\nHence if we restrict our attention to paths starting at a single point $x_0$,\nthen we can stop caring about endpoints and start-points, since\neverything starts and stops at $x_0$.\nWe even have a very canonical loop: the ``do-nothing'' loop\\footnote{Fatty.} given by standing at $x_0$ the whole time.\n\n\\begin{definition}\n\tDenote the trivial ``do-nothing loop'' by $1$.\n\tA loop $\\gamma$ is \\vocab{nulhomotopic} if it is homotopic to $1$; i.e.\\ $\\gamma \\simeq 1$.\n\\end{definition}\n\nFor homotopy of loops, you might visualize ``reeling in'' the loop, contracting it to a single point.\n\n\\begin{example}[Loops in $S^2$ are nulhomotopic]\n\tAs the following picture should convince you, every loop in\n\tthe simply connected space $S^2$ is nulhomotopic.\n\t\\begin{center}\n\t\t\\includegraphics[width=6cm]{media/S2-simply.png}\n\t\\end{center}\n\t(Starting with the purple loop, we contract to the red-brown point.)\n\\end{example}\n\nHence to show that spaces are simply connected it suffices to understand\nthe loops of that space.\nWe are now ready to provide:\n\\begin{definition}\n\tThe \\vocab{fundamental group} of $X$ with basepoint $x_0$,\n\tdenoted $\\pi_1(X, x_0)$, is the set of homotopy classes\n\t\\[ \\left\\{ [\\gamma] \\mid \\gamma \\text{ a loop at $x_0$} \\right\\} \\]\n\tequipped with $\\ast$ as a group operation.\n\\end{definition}\n\nIt might come as a surprise that this has a group structure.\nFor example, what is the inverse?\nLet's define it now.\n\\begin{definition}\n\tGiven a path $\\alpha : [0,1] \\to X$ we can define a path $\\ol\\alpha$\n\t\\[ \\ol\\alpha (t) = \\alpha(1-t). \\]\n\tIn effect, this ``runs $\\alpha$ backwards''.\n\tNote that $\\ol\\alpha$ starts at the endpoint of $\\alpha$\n\tand ends at the starting point of $\\alpha$.\n\\end{definition}\n\\begin{exercise}\n\tShow that for any path $\\alpha$,\n\t$\\alpha \\ast \\ol\\alpha$ is homotopic\n\tto the ``do-nothing'' loop at $\\alpha(0)$.\n\t(Draw a picture.)\n\\end{exercise}\n\nLet's check it.\n\\begin{proof}\n\t[Proof that this is a group structure]\n\tClearly $\\ast$ takes two loops at $x_0$ and spits out a loop at $x_0$.\n\tWe also already took the time to show that $\\ast$ is associative.\n\tSo we only have to check that (i) there's an identity, and (ii)\n\tthere's an inverse.\n\t\\begin{itemize}\n\t\t\\ii We claim that the identity is the ``do-nothing'' loop $1$\n\t\twe described above. The reader can check that for any $\\gamma$,\n\t\t\\[ \\gamma \\simeq \\gamma \\ast 1 = 1 \\ast \\gamma. \\]\n\t\t\\ii For a loop $\\gamma$, recall again we define its ``backwards'' loop $\\ol\\gamma$ by\n\t\t\\[ \\ol\\gamma(t) = \\gamma(1-t). \\]\n\t\tThen we have $\\gamma \\ast \\ol\\gamma = \\ol\\gamma \\ast \\gamma = 1$.\n\t\\end{itemize}\n\tHence $\\pi_1(X,x_0)$ is actually a group.\n\\end{proof}\n\nBefore going any further I had better give some examples.\n\\begin{example}\n\t[Examples of fundamental groups]\n\tNote that proving the following results is not at all trivial.\n\tFor now, just try to see intuitively why the claimed answer ``should'' be correct.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The fundamental group of $\\CC$ is the\n\t\ttrivial group: in the plane, every loop is nulhomotopic.\n\t\t(Proof: imagine it's a piece of rope and reel it in.)\n\t\t\\ii On the other hand, the fundamental group of $\\CC - \\{0\\}$\n\t\t(meteor example from earlier) with any base point is actually $\\ZZ$!\n\t\tWe won't be able to prove this for a while,\n\t\tbut essentially a loop is determined by the number of times\n\t\tthat it winds around the origin -- these are so-called\n\t\t\\emph{winding numbers}.  Think about it!\n\t\t\\ii Similarly, we will soon show that the fundamental group of $S^1$\n\t\t(the boundary of the unit circle) is $\\ZZ$.\n\t\\end{enumerate}\n\tOfficially, I also have to tell you what the base point is, but\n\tby symmetry in these examples, it doesn't matter.\n\\end{example}\nHere is the picture for $\\CC \\setminus \\{0\\}$, with the hole exaggerated\nas the meteor from \\Cref{sec:meteor}.\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(6cm);\n\t\tbigbox(\"$\\mathbb C \\setminus \\{0\\}$\");\n\t\tfilldraw(scale(0.5)*unitcircle, grey, black);\n\t\tdot(\"$x_0$\", (1.4,0), dir(0));\n\t\tdraw( (1.4,0)..(0,1.4)..(-1.4,0)..(1.4*dir(-30))..cycle, blue, EndArrow );\n\t\\end{asy}\n\\end{center}\n\n\\begin{ques}\n\tConvince yourself that the fundamental group of $S^1$ is $\\ZZ$,\n\tand understand why we call these ``winding numbers''.\n\t(This will be the most important example of a fundamental group\n\tin later chapters, so it's crucial you figure it out now.)\n\\end{ques}\n\n\\begin{example}\n\t[The figure eight]\n\t\\label{ex:figure8}\n\tConsider a figure eight $S^1 \\vee S^1$, and let $x_0$\n\tbe the center.\n\tThen  \\[\\pi_1(S^1 \\vee S^1, x_0) \\cong \\left<a,b\\right> \\]\n\tis the \\emph{free group} generated on two letters.\n\tThe idea is that one loop of the eight is $a$,\n\tand the other loop is $b$, so we expect $\\pi_1$\n\tto be generated by this loop $a$ and $b$ (and its inverses\n\t$\\ol a$ and $\\ol b$).\n\tThese loops don't talk to each other.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tdraw( shift( (1,0) ) * unitcircle, grey + 5 );\n\t\t\tdraw( shift( (-1,0) ) * unitcircle, grey + 5 );\n\t\t\tdot(origin);\n\t\t\tpath g = dir(20)..dir(100)..dir(180)..dir(260)..dir(340);\n\t\t\tdraw( shift( (1,0) ) * scale(0.8) * reflect(dir(90),dir(-90)) * g, blue, EndArrow );\n\t\t\tdraw( shift( (-1,0) ) * scale(0.8) * g, red, EndArrow );\n\t\t\tlabel(\"$a$\", (-1.6,0), dir(0));\n\t\t\tlabel(\"$b$\", (1.6,0), dir(180));\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\nRecall that in graph theory, we usually assume our graphs are connected,\nsince otherwise we can just consider every connected component separately.\nLikewise, we generally want to restrict our attention to path-connected spaces, since if a space isn't path-connected then it can be broken into a bunch of ``path-connected components''.\n(Can you guess how to define this?)\nIndeed, you could imagine a space $X$ that consists of the objects on my desk (but not the desk itself): $\\pi_1$ of my phone has nothing to do with $\\pi_1$ of my mug. They are just totally disconnected, both figuratively and literally.\n\nBut on the other hand we claim that in a path-connected space,\nthe groups are very related!\n\\begin{theorem}[Fundamental groups don't depend on basepoint]\n\tLet $X$ be a path-connected space.\n\tThen for any $x_1 \\in X$ and $x_2 \\in X$, we have\n\t\\[ \\pi_1(X, x_1) \\cong \\pi_1(X, x_2). \\]\n\\end{theorem}\nBefore you read the proof, see if you can guess the isomorphism based just on the picture below.\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(7cm);\n\t\tbigblob(\"$X$\");\n\t\tpair A = Drawing(\"x_1\", (-1.5,0), dir(180));\n\t\tpair B = Drawing(\"x_2\", (1.5,0), dir(0));\n\t\tdraw(A..(-2.5,-0.8)..(-2.5,0.9)..cycle, blue);\n\t\tdraw(B..(2.2,-1.1)..(2.4,0.8)..cycle, blue);\n\t\tdraw(A--B, red+dashed, Arrows);\n\t\tlabel(\"$\\alpha$/$\\overline{\\alpha}$\", origin, dir(90));\n\t\\end{asy}\n\\end{center}\n\\begin{proof}\n\tLet $\\alpha$ be any path from $x_1$ to $x_2$ (possible by path-connectedness), and let $\\ol\\alpha$ be its reverse.\n\tThen we can construct a map\n\t\\[ \n\t\t\\pi_1(X,x_1) \\to \\pi_1(X,x_2)\n\t\t\\text{ by }\n\t\t[\\gamma] \\mapsto [\\ol\\alpha \\ast \\gamma \\ast \\alpha]. \\]\n\tIn other words, given a loop $\\gamma$ at $x_1$,\n\twe can start at $x_2$, follow $\\ol\\alpha$ to $x_1$,\n\trun $\\gamma$, then run along $\\alpha$ home to $x_2$.\n\tHence this is a map which builds a loop of $\\pi_1(X, x_2)$\n\tfrom every loop at $\\pi_1(X, x_1)$.\n\tIt is a \\emph{homomorphism} of the groups just because\n\t\\[ \\left( \\ol \\alpha \\ast \\gamma_1 \\ast \\alpha \\right)\n\t\t\\ast \\left( \\ol\\alpha \\ast \\gamma_2 \\ast \\alpha \\right)\n\t\t= \\ol\\alpha \\ast \\gamma_1 \\ast \\gamma_2 \\ast \\alpha \\]\n\tas $\\alpha \\ast \\ol\\alpha$ is nulhomotopic.\n\n\tSimilarly, there is a homomorphism\n\t\\[ \n\t\t\\pi_1(X,x_2) \\to \\pi_1(X,x_1)\n\t\t\\text{ by }\n\t\t[\\gamma] \\mapsto [\\alpha \\ast \\gamma \\ast \\ol\\alpha]. \\]\n\tAs these maps are mutual inverses, it follows\n\tthey must be isomorphisms. End of story.\n\\end{proof}\nThis is a bigger reason why we usually only care about path-connected spaces.\n\n\\begin{abuse}\n\tFor a path-connected space $X$ we will often abbreviate $\\pi_1(X, x_0)$\n\tto just $\\pi_1(X)$, since it doesn't matter which $x_0 \\in X$\n\twe pick.\n\\end{abuse}\n\nFinally, recall that we originally defined ``simply connected'' as saying\nthat any two paths with matching endpoints were homotopic.\nIt's possible to weaken this condition and then rephrase it using\nfundamental groups.\n\\begin{exercise}\n\tLet $X$ be a path-connected space.\n\tProve that $X$ is \\vocab{simply connected} if and only if\n\t$\\pi_1(X)$ is the trivial group.\n\t(One direction is easy; the other is a little trickier.)\n\\end{exercise}\nThis is the ``usual'' definition of simply connected.\n\n\n\\section{Fundamental groups are functorial}\nOne quick shorthand I will introduce to clean up the discussion:\n\\begin{definition}\n\tBy $f : (X, x_0) \\to (Y, y_0)$, we will mean that\n\t$f : X \\to Y$ is a continuous function of spaces\n\twhich also sends the point $x_0$ to $y_0$.\n\\end{definition}\n\nLet $X$ and $Y$ be topological spaces and $f : (X, x_0) \\to (Y, y_0)$.\nWe now want to relate the fundamental groups of $X$ and $Y$.\n\nRecall that a loop $\\gamma$ in $(X, x_0)$ is a map $\\gamma : [0,1] \\to X$\nwith $\\gamma(0) = \\gamma(1) = x_0$.\nThen if we consider the composition\n\\[ [0,1] \\taking\\gamma (X, x_0) \\taking f (Y, y_0) \\]\nthen we get straight-away a loop in $Y$ at $y_0$!\nLet's call this loop $f_\\sharp \\gamma$.\n\\begin{lemma}[$f_\\sharp$ is homotopy invariant]\n\t\\label{lem:fsharp_homotopy_invariant}\n\tIf $\\gamma_1 \\simeq \\gamma_2$ are path-homotopic,\n\tthen in fact\n\t\\[ f_\\sharp \\gamma_1 \\simeq f_\\sharp \\gamma_2. \\]\n\\end{lemma}\n\\begin{proof}\n\tJust take the homotopy $h$ taking $\\gamma_1$ to $\\gamma_2$\t\n\tand consider $f \\circ h$.\n\\end{proof}\n\nIt's worth noting at this point that if $X$ and $Y$ are homeomorphic,\nthen their fundamental groups are all isomorphic.\nIndeed, let $f : X \\to Y$ and $g : Y \\to X$ be mutually inverse continuous maps.\nThen one can check that $f_\\sharp : \\pi_1(X, x_0) \\to \\pi_1(Y, y_0)$\nand $g_\\sharp : \\pi_1(Y, y_0) \\to \\pi_1(X, x_0)$ are inverse maps\nbetween the groups (assuming $f(x_0) = y_0$ and $g(y_0) = x_0$).\n\n%Now we want to show that by taking the map $f_\\sharp$, we get a \\emph{functor}\n%\\begin{diagram}\n%\t& (X, x_0) & & \\pi_1(X, x_0) & \\\\\n%\t\\catname{Top}_\\ast \\ni & \\dTo^f & \\rDotted & \\dTo_{f_\\sharp} & \\in \\catname{Grp} \\\\\n%\t& (Y, y_0) & & \\pi_1(Y, y_0) &\n%\\end{diagram}\n%\\begin{ques}\n%\tCheck this -- we need that $(f \\circ g)_\\sharp = f_\\sharp \\circ g_\\sharp$\n%\tand that $(\\id_X)_\\sharp = \\id_{\\pi_1(X)}$.\n%\tBoth are totally obvious once you can tell what they're asking.\n%\\end{ques}\n%Thus in this way we've constructed a functor\n%\\[ \\catname{Top}_\\ast \\to \\catname{Grp}. \\]\n%In particular, by the fact that functors preserve isomorphism (\\Cref{thm:functor_isom}), we have\n%\\begin{moral}\n%\tHomeomorophic topological spaces have isomorphic fundamental groups.\n%\tCategory theory gives this to us for free.\n%\\end{moral}\n%\n%\\begin{remark}\n%\tNote the similarity between this and the construction\n%\tof the covariant Yoneda functor (\\Cref{ex:covariant_yoneda}).\n%\\end{remark}\n\n\\section{Higher homotopy groups}\nWhy the notation $\\pi_1$ for the fundamental group?\nAnd what are $\\pi_2$, \\dots?\nThe answer lies in the following rephrasing:\n\\begin{ques}\n\tConvince yourself that a loop is the same thing\n\tas a continuous function $S^1 \\to X$.\n\\end{ques}\nIt turns out we can define homotopy for things other than paths.\nTwo functions $f, g : Y \\to X$ are \\vocab{homotopic} if there exists a continuous\nfunction $Y \\times [0,1] \\to X$ which continuously deforms $f$ to $g$.\nSo everything we did above was just the special case $Y = S^1$.\n\nFor general $n$, the group $\\pi_n(X)$ is defined as the homotopy classes\nof the maps $S^n \\to X$.\nThe group operation is a little harder to specify.\nYou have to show that $S^n$ is homeomorphic to $[0,1]^n$ with\nsome endpoints fused together; for example $S^1$ is $[0,1]$ with $0$ fused to $1$.\nOnce you have these cubes, you can merge them together on a face.\n(Again, I'm being terribly imprecise, deliberately.)\n\nFor $n \\neq 1$, $\\pi_n$ behaves somewhat differently than $\\pi_1$.\n(You might not be surprised, as $S^n$ is simply connected for all $n \\ge 2$ but not when $n=1$.)\nIn particular, it turns out that $\\pi_n(X)$ is an abelian group for all $n \\ge 2$.\n\nLet's see some examples.\n\\begin{example}[$\\pi_n(S^n) \\cong \\mathbb Z$]\n\tAs we saw, $\\pi_1(S^1) \\cong \\ZZ$; given the base circle $S^1$,\n\twe can wrap a second circle around it as many times as we want.\n\tIn general, it's true that $\\pi_n(S^n) \\cong \\ZZ$.\n\\end{example}\n\\begin{example}[$\\pi_n(S^m) \\cong \\{1\\}$ when $n < m$]\n\tWe saw that $\\pi_1(S^2) \\cong \\{1\\}$, because \n\ta circle in $S^2$ can just be reeled in to a point.\n\tIt turns out that similarly, any smaller $n$-dimensional sphere\n\tcan be reeled in on the surface of a bigger $m$-dimensional sphere.\n\tSo in general, $\\pi_n(S^m)$ is trivial for $n < m$.\n\\end{example}\nHowever, beyond these observations, the groups behave quite weirdly.\nHere is a table of $\\pi_n(S^m)$ for $1 \\le m \\le 8$ and $2 \\le n \\le 10$,\nso you can see what I'm talking about.\n(Taken from Wikipedia.)\n\n\\bgroup\n\\footnotesize\n\\[\n\t\\begin{array}{r|ccccccccc}\n\t\t\\pi_n(S^m) & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\\\ \\hline\n\t\tm = 1 & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} & \\{1\\} \\\\\n\t\t2 &  \\ZZ & \\ZZ & \\Zc2 & \\Zc2 & \\Zc{12} & \\Zc2 & \\Zc2 & \\Zc3 & \\Zc{15}\\\\\n\t\t3 & & \\ZZ & \\Zc2 & \\Zc2 & \\Zc{12} & \\Zc2 & \\Zc2 & \\Zc3 & \\Zc{15}\\\\\n\t\t4 & &  & \\ZZ & \\Zc2 & \\Zc2 & \\ZZ \\times \\Zc{12} & (\\Zc2)^2 & \\Zc2 \\times \\Zc2 & \\Zc{24} \\times \\Zc3 \\\\\n\t\t5 & &  &  & \\ZZ & \\Zc2 & \\Zc2 & \\Zc{24} & \\Zc2 & \\Zc2 \\\\\n\t\t6 & &  &  &  & \\ZZ & \\Zc2 & \\Zc2 & \\Zc{24} & \\{1\\} \\\\\n\t\t7 & &  &  &  &  & \\ZZ & \\Zc2 & \\Zc2 & \\Zc{24} \\\\\n\t\t8 & &  &  &  &  &  & \\ZZ & \\Zc2 & \\Zc2\n\t\\end{array}\n\\]\n\\egroup\n\nActually, it turns out that if you can compute $\\pi_n(S^m)$\nfor every $m$ and $n$,\nthen you can essentially compute \\emph{any} homotopy classes.\nThus, computing $\\pi_n(S^m)$ is sort of a lost cause in general,\nand the mixture of chaos and pattern in the above table is a testament to this.\n\n\\section{Homotopy equivalent spaces}\n\\prototype{A disk is homotopy equivalent to a point, an annulus is homotopy equivalent to $S^1$.}\nUp to now I've abused notation and referred to ``path homotopy'' as just ``homotopy'' for two paths.\nI will unfortunately continue to do so (and so any time I say two paths are homotopic, you should assume I mean ``path-homotopic'').\nBut let me tell you what the general definition of homotopy is first.\n\\begin{definition}\n\tLet $f,g : X \\to Y$ be continuous functions.\n\tA \\vocab{homotopy} is a continuous function $F : X \\times [0,1] \\to Y$,\n\twhich we'll write $F_s(x)$ for $s \\in [0,1]$, $x \\in X$, such that \n\t\\[ F_0(x) = f(x) \\text{ and } F_1(x) = g(x) \\text{ for all $x \\in X$.} \\]\n\tIf such a function exists, then $f$ and $g$ are \\vocab{homotopic}.\n\\end{definition}\nIntuitively this is once again ``deforming $f$ to $g$''.\nYou might notice this is almost exactly the same definition as path-homotopy,\nexcept that $f$ and $g$ are any functions instead of paths, and hence\nthere's no restriction on keeping some ``endpoints'' fixed through the deformation.\n\nThis homotopy can be quite dramatic:\n\\begin{example}\n\tThe zero function $z \\mapsto 0$ and the identity function $z \\mapsto z$\n\tare homotopic as functions $\\CC \\to \\CC$.\n\tThe necessary deformation is\n\t\\[ [0,1] \\times \\CC \\to \\CC \\text{ by } (t,z) \\mapsto tz. \\]\n\\end{example}\n\nI bring this up because I want to define:\n\\begin{definition}\n\tLet $X$ and $Y$ be continuous spaces.\n\tThey are \\vocab{homotopy equivalent} if there exist\n\tfunctions $f : X \\to Y$ and $g : Y \\to X$ such that\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $f \\circ g : X \\to X$ is homotopic to the identity map on $X$, and\n\t\t\\ii $g \\circ f : Y \\to Y$ is homotopic to the identity map on $Y$.\n\t\\end{enumerate}\n\tIf a topological space is homotopy equivalent to a point,\n\tthen it is said to be \\vocab{contractible}.\n\\end{definition}\n\\begin{ques}\n\tWhy are two homeomorphic spaces also homotopy equivalent?\n\\end{ques}\n\nIntuitively, you can think of this as a more generous form of stretching\nand bending than homeomorphism: we are allowed to compress huge spaces into single points.\n\n\\begin{example}[$\\CC$ is contractible]\n\tConsider the topological spaces $\\CC$\n\tand the space consisting of the single point $\\{0\\}$. \n\tWe claim these spaces are homotopy equivalent (can you guess what $f$ and $g$ are?)\n\tIndeed, the two things to check are\n\t\\begin{enumerate}[(i)]\n\t\t\\ii $\\CC \\to \\{0\\} \\hookrightarrow \\CC$ by $z \\mapsto 0 \\mapsto 0$\n\t\tis homotopy equivalent to the identity on $\\CC$, which we just saw, and\n\t\t\\ii $\\{0\\} \\hookrightarrow \\CC \\to \\{0\\}$ by $0 \\mapsto 0 \\mapsto 0$, which \\emph{is} the identity on $\\{0\\}$.\n\t\\end{enumerate}\n\tHere by $\\hookrightarrow$ I just mean $\\to$ in the special case\n\tthat the function is just an ``inclusion''.\n\\end{example}\n\\begin{remark}\n\t$\\CC$ cannot be \\emph{homeomorphic} to a point\n\tbecause there is no bijection of sets between them.\n\\end{remark}\n\n\\begin{example}[$\\CC \\setminus \\{0\\}$ is homotopy equivalent to $S^1$]\n\tConsider the topological spaces $\\CC \\setminus \\{0\\}$,\n\tthe \\vocab{punctured plane}, and the circle $S^1$ viewed as a subset of $S^1$.\n\tWe claim these spaces are actually homotopy equivalent!\n\tThe necessary functions are the inclusion\n\t\\[ S^1 \\hookrightarrow \\CC \\setminus \\{0\\} \\]\n\tand the function\n\t\\[ \\CC \\setminus \\{0\\} \\to S^1\n\t\t\\quad\\text{by}\\quad\n\t\tz \\mapsto \\frac{z}{\\left\\lvert z \\right\\rvert}. \\]\n\tYou can check that these satisfy the required condition.\n\\end{example}\n\\begin{remark}\n\tOn the other hand, $\\CC \\setminus \\{0\\}$ cannot be \\emph{homeomorphic} to $S^1$.\n\tOne can make $S^1$ disconnected by deleting two points;\n\tthe same is not true for $\\CC \\setminus \\{0\\}$.\n\\end{remark}\n\\begin{example}\n\t[$\\text{Disk} = \\text{Point}$, $\\text{Annulus} = \\text{Circle}$.]\n\tBy the same token, a disk is homotopic to a point;\n\tan annulus is homotopic to a circle.\n\t(This might be a little easier to visualize, since it's finite.)\n\\end{example}\n\nI bring these up because it turns out that \n\\begin{moral}\n\tAlgebraic topology can't distinguish between homotopy equivalent spaces.\n\\end{moral}\nMore precisely,\n\\begin{theorem}[Homotopy equivalent spaces have isomorphic fundamental groups]\n\t\\label{thm:fundgrp_homotopy_invariant}\n\tLet $X$ and $Y$ be path-connected, homotopy-equivalent spaces.\n\tThen $\\pi_n(X) \\cong \\pi_n(Y)$ for every positive integer $n$.\n\\end{theorem}\n\\begin{proof}\n\tLet $\\gamma : [0,1] \\to X$ be a loop.\n\tLet $f : X \\to Y$ and $g : Y \\to X$ be maps witnessing that $X$ and $Y$ are homotopy equivalent\n\t(meaning $f \\circ g$ and $g \\circ f$ are each homotopic to the identity).\n\tThen the composition\n\t\\[ [0,1] \\taking\\gamma X \\taking f Y \\]\n\tis a loop in $Y$ and hence $f$ induces a natural homomorphism $\\pi_1(X) \\to \\pi_1(Y)$.\n\tSimilarly $g$ induces a natural homomorphism $\\pi_1(Y) \\to \\pi_1(X)$.\n\tThe conditions on $f$ and $g$ now say exactly that these two homomorphisms\n\tare inverse to each other, meaning the maps are isomorphisms.\n\\end{proof}\nIn particular,\n\\begin{ques}\n\tWhat are the fundamental groups of contractible spaces?\n\\end{ques}\n\nThat means, for example, that algebraic topology can't tell\nthe following homotopic subspaces of $\\RR^2$ apart.\n\\begin{center}\n\t{\\color{red} \\Huge \\venus}\n\t\\qquad\n\t{\\color{blue} \\Huge \\mars}\n\\end{center}\n\n\\section{The pointed homotopy category}\nThis section is meant to be read by those who know some basic category theory.\nThose of you that don't should come back after reading \\Cref{ch:cats,ch:functors}.\nThose of you that do will enjoy how succinctly we can summarize\nthe content of this chapter using categorical notions.\n\n\\begin{definition}\n\tThe \\vocab{pointed homotopy category} $\\catname{hTop}_\\ast$ is defined as follows.\n\t\\begin{itemize}\n\t\t\\ii Objects: pairs $(X, x_0)$ of spaces with a distinguished basepoint, and\n\t\t\\ii Morphisms: \\emph{homotopy classes} of continuous functions $(X, x_0) \\to (Y, y_0)$.\n\t\\end{itemize}\n\\end{definition}\nIn particular, two path-connected spaces are isomorphic in this category exactly\nwhen they are homotopy equivalent.\nThen we can summarize many of the preceding results as follows:\n\\begin{theorem}[Functorial interpretation of fundamental groups]\n\t\\label{thm:fundgrp_functor}\n\tThere is a functor\n\t\\[ \\pi_1 : \\catname{hTop}_\\ast \\to \\catname{Grp} \\]\n\tsending\n\t\\begin{diagram}\n\t\t(X,x_0) & \\rTo & \\pi_1(X, x_0) \\\\\n\t\t\\dTo^f & & \\dTo^{f_\\sharp} \\\\\n\t\t(Y,y_0) & \\rTo & \\pi_1(Y, y_0)\n\t\\end{diagram}\n\\end{theorem}\nThis implies several things, like\n\\begin{itemize}\n\t\\ii The functor bundles the information of $f_\\sharp$,\n\tincluding the fact that it respects composition.\n\tIn the categorical language, $f_\\sharp$ is $\\pi_1(f)$.\n\t\\ii Homotopic spaces have isomorphic fundamental group\n\t(since the spaces are isomorphic in $\\catname{hTop}$,\n\tand functors preserve isomorphism by \\Cref{thm:functor_isom}).\n\tIn fact, you'll notice that the proofs\n\tof \\Cref{thm:functor_isom} and \\Cref{thm:fundgrp_homotopy_invariant}\n\tare secretly identical to each other.\n\t\\ii If maps $f, g : (X, x_0) \\to (Y, y_0)$ are homotopic,\n\tthen $f_\\sharp = g_\\sharp$. This is basically \\Cref{lem:fsharp_homotopy_invariant}\n\\end{itemize}\n\n\\begin{remark}\n\tIn fact, $\\pi_1(X, x_0)$ is the set of arrows $(S^1, 1) \\to (X, x_0)$ in $\\catname{hTop}_\\ast$,\n\tso this is actually a covariant Yoneda functor (\\Cref{ex:covariant_yoneda}),\n\texcept with target $\\catname{Grp}$ instead of $\\catname{Set}$.\n\\end{remark}\n\n\n\\section\\problemhead\n\n\\begin{problem}[Harmonic fan]\n\tExhibit a subspace $X$ of the metric space $\\RR^2$ which is\n\tpath-connected but for which a point $p$ can be found such that\n\tany $r$-neighborhood of $p$ with $r < 1$ is not path-connected.\n\t% harmonic fan\n\\end{problem}\n\n\\begin{dproblem}\n\t[Special case of Seifert-van Kampen] \\gim\n\tLet $X$ be a topological space.\n\tSuppose $U$ and $V$ are connected open subsets of $X$, with $X = U \\cup V$,\n\tso that $U \\cap V$ is nonempty and path-connected.\n\t\t\n\tProve that if $\\pi_1(U) = \\pi_1(V) = \\{1\\}$ then $\\pi_1(X) = 1$.\n\\end{dproblem}\n\\begin{remark}\n\tThe \\vocab{Seifert--van Kampen theorem} generalizes this \n\tfor $\\pi_1(U)$ and $\\pi_1(V)$ any groups; it gives a formula for calculating $\\pi_1(X)$\n\tin terms of $\\pi_1(U)$, $\\pi_1(V)$, $\\pi_1(U \\cap V)$.\n\tThe proof is much the same.\n\t\n\tUnfortunately, this does not give us a way to calculate $\\pi_1(S^1)$,\n\tbecause it is not possible to write $S^1 = U \\cup V$ for $U \\cap V$ \\emph{connected}.\n\\end{remark}\n\n\\begin{problem}\n\t[RMM 2013] \\yod\n\tLet $n \\ge 2$ be a positive integer.\n\tA stone is placed at each vertex of a regular $2n$-gon.\n\tA move consists of selecting an edge of the $2n$-gon and swapping the two stones at the endpoints of the edge.\n\tProve that if a sequence of moves swaps every pair of stones exactly once, then there is some edge never used in any move.\n\\end{problem}\n(This last problem doesn't technically have anything to do with the chapter,\nbut the ``gut feeling'' which motivates the solution is very similar.)\n", "meta": {"hexsha": "9b24066f099aa983634e2d5d6ddb7d4819d49689", "size": 28382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/topology/fundamental-group.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/fundamental-group.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/fundamental-group.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": 41.3731778426, "max_line_length": 235, "alphanum_fraction": 0.6820167712, "num_tokens": 9619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850154599562, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.6012955162023444}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{MAT257 Notes}\n\\author{Jad Elkhaleq Ghalayini}\n\\date{October 24 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\\DeclareMathOperator{\\Int}{Int}\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*{Proof of the Inverse Function Theorem}\n\nLet \\(f: \\reals^n \\to \\reals^n\\) be \\(\\mc{C}^1\\) on an open set containing \\(a \\in \\reals^n\\) and let \\[\\det f'(a) \\neq 0\\]\nWe can assume, as shown in last lecture, that \\(f'(a) = I\\).\nWe show that there are open \\(V, W\\) containing \\(a\\) and \\(f(a)\\) respectively such that \\(f: V \\to W\\) with a continuous inverse \\(f': W \\to V\\)\n\nWe will begin by showing that we can't have \\(f(x) = f(a)\\) if \\(x \\neq a\\) is sufficiently close to \\(a\\):\n\\[f'(a) = I \\land Ih = h \\implies \\lim_{h \\to 0}\\frac{|f(a + h) - f(a) - h|}{|h|} = 0\\]\nIf \\(f(a + h) = f(a)\\) then the quotient is 1. So the quotient being zero means that there exists a closed ball \\(B\\) centered at \\(a\\) such that\n\\[x \\in B \\setminus \\{a\\} \\implies f(x) \\neq f(a)\\]\nBut that's not enough to mean that \\(f\\) is one to one in \\(B\\): it could be, for example, that \\(f(\\partial B)\\), the image of the boundary of \\(B\\), intersects itself, for example. What we want to do is find an even smaller ball where \\(f\\) really is one-to-one. So, since \\(f\\) is \\(\\mc{C}^1\\) in a neighborhood of \\(a\\) we can also assume:\n\\begin{enumerate}\n\n  \\item \\(x \\in B \\implies \\det f'(x) \\neq 0\\) since \\(f'\\) is continuous\n\n  \\item Given \\(\\epsilon\\), we can make, for all \\(i, j\\), \\[\n    \\left|\\prt{f_i}{x_j}(x) - \\prt{f_i}{x_j}(a)\\right| < \\epsilon\n  \\]\n  Note that, by our previous assumption that \\(f'(a) = I\\),\n  \\[\\prt{f_i}{x_j}(a) = I_{ij}\\]\n\n\\end{enumerate}\nApply the Mean Value Theorem to \\(g(x) = f(x) - x\\). According to the MVT, we can also assume that\n\\[|g(x_1) - g(x_2)| \\leq cb|x_1 - x_2|\\]\nwhere \\(c\\) is a constant and \\(b\\) is a bound on the partial derivatives of \\(g\\). But what is \\(\\prt{g_i}{x_j}\\)? It's the same as what's in the absolute value brackets in assumption (2), since\n\\[\\prt{x_i}{x_j} = \\delta_{ij} = \\prt{f_i}{x_j}\\]\nSo we have that\n\\[|g(x_1) - g(x_2)| \\leq c\\epsilon|x_1 - x_2|\\]\nfor some constant \\(c\\). That was for any given \\(\\epsilon\\). Let's choose \\(\\epsilon\\) such that \\(c\\epsilon = \\frac{1}{2}\\), giving\n\\[|g(x_1) - g(x_2)| \\leq \\frac{1}{2}|x_1 - x_2|\\]\nIf you remember that problem we did on the MVT, we gave a precise bound on \\(\\epsilon\\), specifically it suffices to choose \\(\\epsilon = \\frac{1}{2n}\\). So what does this tell us?\n\\[|f(x_1) - x_1 - f(x_2) + x_2| \\leq \\frac{1}{2}|x_1 - x_2|\\]\nusing the Triangle Inequality, we obtain\n\\[|x_1 - x_2| \\leq 2|f(x_1) - f(x_2)|\\]\nSo what does \\textit{this} tell us? It tells us that \\(f\\) is one-to-one on \\(B\\), since if \\(f(x_1) = f(x_2)\\) and \\(x_1 \\neq x_2\\) then\n\\[|x_1 - x_2| > 2|f(x_1) - f(x_2)| = 0\\]\nWe have that \\(f(\\partial B)\\) is a compact set not including \\(a\\). So we have that\n\\[d = d(f(a), f(\\partial B)) > 0\\]\nLet\n\\[W = \\{y : |y - f(a)| \\leq d/2\\}\\]\nThen if \\(y \\in W\\), \\(x \\in \\partial B\\), then what's the relationship between\n\\(|y - f(a)|\\) and \\(|y - f(x)|\\)? Since \\(W\\) is the ball of radius \\(\\frac{d}{2}\\), we have that\n\\[|y - f(a)| < |y - f(x)|\\]\nThis tells us that \\(W\\) is completely in the image of \\(B\\). It follows that for all \\(y \\in W\\), there is some \\(x \\in \\Int B\\) such that \\(f(x) = y\\). I could have said unique \\(x\\), but I didn't bother because it must be unique anyways since we already checked one to one. But let's check this. We're going to do so by solving an extreme value problem. Let's define \\(h: B \\to \\reals\\) by\n\\[x \\mapsto |y - f(x)|^2 = \\sum_{i = 1}^n|y_i - f_i(x)|^2\\]\n\\(h\\) is continuous, and therefore it has a minimum on the compact set \\(B\\). So this is the usual business of a max-min problem: it could be that the minimum occurs on the bounary. So can it? No, since, as we saw above,\n\\[\\forall y \\in W, |y - f(a)| < |y - f(x)|\\]\nSo that means it occurs at the interior, and since \\(f\\) and hence \\(|y - f(x)|^2\\) is differentiable, at a critical point, a point where all the partial derivatives are zero, \\(x \\in \\Int B\\). But what does the following exactly mean:\n\\[\\prt{h}{x_j}(x) = 0\\]\nExpanding, we get\n\\[\\forall j \\in \\{1,...,n\\}, \\sum_{i = 1}^n2(y_i - f_i(x))\\prt{f_i}{x_j}(x) = 0\\]\nSo what does this tell us? This is a system of \\(n\\) equations linear in \\(y_i - f_i(x)\\) with coefficients \\(\\prt{f_i}{x_j}(x)\\). But since the matrix\n\\[\\left(\\prt{f_i}{x_j}\\right)\\]\nis invertible, since \\(\\det f'(x) \\neq 0\\), we have\n\\[[\\forall i \\in \\{1,...,n\\}, (y_i - f_i(x)) = 0] \\iff y = f(x)\\]\nwhich is what we wanted to show.\n\nSo back to what we wanted to do, we wanted to find those open sets \\(V\\) and \\(W\\). So what should we use as \\(V\\)?\n\\[V = f^{-1}(W) \\cap \\Int B\\]\nThen \\(f: V \\to W\\) has an inverse \\(f^{-1}: W \\to V\\), since \\(f\\) is one to one. We also wanted to show that the inverse is continuous. So how do we see that? Well, we go back to what we showed above:\n\\[\\forall x_1, x_2 \\in V, |x_1 - x_2| \\leq 2|f(x_1) - f(x_2)| \\implies \\forall y_1, y_2 \\in W, |f^{-1}(y_1) - f^{-1}(y_2)| \\leq 2|y_1 - y_2|\\]\nimplying \\(f^{-1}\\) is continuous. So the only thing remaining is to show that \\(f^{-1}\\) is differentiable. So let's take a point \\(x_0 \\in V\\), \\(y_0 = f(x_0)\\). Call \\(\\mu = Df(x_0)\\). We'll show \\(f^{-1}\\) is differentiable at \\(y_0\\) and \\((f^{-1})'(y_0) = \\mu^{-1}\\). So what do we know. We know that\n\\[f(x) = f(x_0) + \\mu(x - x_0) + \\varphi(x)\\]\nwhere\n\\[\\lim_{x \\to x_0}\\frac{|\\varphi(x)|}{|x - x_0|} = 0\\]\nEach \\(y \\in W\\) can be written \\(y = f(x), x \\in V\\). We have\n\\[\\mu^{-1}(y - y_0) = \\mu^{-1}(f(x) - f(x_0)) = x - x_0 + \\mu^{-1}\\varphi(x)\\]\nSo what this says is that\n\\[f^{-1}(y) = f^{-1}(y_0) + \\mu^{-1}(y - y_0) - \\mu^{-1}\\varphi(f^{-1}(y))\\]\nThat's like what we need to show that \\(f^{-1}\\) is differentiable. Specifically, we have to show\n\\[\\lim_{y \\to y_0}\\frac{\\mu^{-1}\\varphi(f^{-1}(y))}{|y - y_0|} = 0\\]\nWe have\n\\[\\frac{\\varphi(f^{-1}(y))}{|y - y_0|} = \\frac{\\varphi(f^{-1}(y))}{|f^{-1}(y) - f^{-1}(y_0)|} \\cdot \\frac{|f^{-1}(y) - f^{-1}(y_0)|}{|y - y_0|} \\leq 2\\frac{\\varphi(f^{-1}(y_0))}{|f^{-1}(y) - f^{-1}(y_0)}\\]\nAnd that's the proof of the inverse function theorem, and hence the implicit function theorem.\n\n\\end{document}\n", "meta": {"hexsha": "9dd5be588460bc7c4cb423661446457c690d425c", "size": 6968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/oct25.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/oct25.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/oct25.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": 59.5555555556, "max_line_length": 392, "alphanum_fraction": 0.6149540758, "num_tokens": 2665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952052, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.6012611528176607}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[T1]{fontenc}\n\\usepackage[utf8]{inputenc}\n\\usepackage{libertine}\n\\usepackage[libertine]{newtxmath}\n\\usepackage{amsmath}\n\\usepackage{commath}\n\\usepackage{mathrsfs}\n% \\usepackage{enumitem}\n\\usepackage{bm}\n\\usepackage{authblk}\n% \\usepackage{esdiff}\n% \\usepackage{microtype}\n\n\\newcommand{\\M}[1]{\\bm{#1}}\n\\newcommand{\\Mc}[1]{\\mathbf{#1}}\n\\newcommand{\\V}[1]{\\mathbf{#1}}\n\\newcommand{\\transpose}{^{\\text{T}}}\n\\newcommand{\\E}{\\text{E}}\n\\newcommand{\\fourier}{\\mathcal{F}}\n\\newcommand{\\lagrange}{\\mathscr{L}}\n\\newcommand{\\sub}[1]{_{\\mathrm{#1}}}\n\\DeclareMathOperator{\\Var}{Var}\n\\DeclareMathOperator{\\nul}{nul}\n\\DeclareMathOperator{\\rank}{rank}\n\n\\title{Summary of TTK4115}\n\\author{Morten Fyhn Amundsen}\n\\affil{NTNU}\n\n\\begin{document}\n\\maketitle\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Matrix stuff}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Nullity} $\\nul(\\M{A}) = \\mbox{No. of columns of } \\M{A} - \\rank(\\M{A})$\n\\paragraph{Positive definite} A symmetric $n \\times n$ real matrix $\\M{M}$ is \\emph{positive definite} if all its eigenvalues are positive. (Or if $\\V{z}\\transpose \\M{M}\\V{z} > 0$ for every non-zero vector $\\V{z}$ of $n$ real numbers.) It is positive \\emph{semidefinite} if all eigenvalues are positive or zero.\n\\paragraph{Singularity} A square matrix is singular if it is not invertible, i.e. if its determinant is $0$.\n\\paragraph{Matrix exponential (diagonal)}\n$$\\M{A} =\n\\begin{bmatrix}\na_1\t\t& \\cdots\t& 0\t\t\t\\\\\n\\vdots \t& \\ddots\t& \\vdots\t\\\\\n0\t\t& \\cdots\t& a_n\t\t\\\\\n\\end{bmatrix}\n\\quad \\implies \\quad\ne^{\\M{A}t} =\n\\begin{bmatrix}\ne^{a_1t}\t& \\cdots\t& 0\t\t\t\\\\\n\\vdots \t\t& \\ddots\t& \\vdots\t\\\\\n0\t\t\t& \\cdots\t& e^{a_nt}\t\\\\\n\\end{bmatrix}$$\n\\paragraph{Matrix exponential (Cayley-Hamilton Method)}\n$$e^{\\M{A}t} = \\sum_{k=0}^{n-1} \\alpha_k \\M{A}^k\n\\quad \\text {with } \\alpha_0 \\cdots \\alpha_{n-1} \\text{ determined by} \\quad\ne^{\\lambda_i t} = \\sum_{k=0}^{n-1} \\alpha_k \\lambda_i^k$$\n\\paragraph{Matrix exponential (Laplace method)}\n$$e^{\\M{A}t} = \\lagrange \\left\\{ (s\\Mc{I}-\\M{A})^{-1} \\right\\}$$\n\\paragraph{Matrix exponential (Jordan form)}\n$$e^{\\M{A}t} = \\M{Q} e^{\\bar{\\M{A}}t} \\M{Q}^{-1} \\quad \\text{where} \\quad \\bar{\\M{A}} = \\M{Q}^{-1}\\M{AQ}$$\n\\paragraph{Controllability matrix} $\\mathcal{C} = \\begin{bmatrix}\\M{B} & \\M{AB} & \\M{A}^{2}\\M{B} & \\hdots & \\M{A}^{n-1}\\M{B}\\end{bmatrix}$\n\\paragraph{Observability matrix} $\\mathcal{O} = \\begin{bmatrix}\\M{C} & \\M{CA} & \\M{CA}^2 & \\hdots & \\M{CA}^{n-1}\\end{bmatrix}^{\\text{T}}$\n\\paragraph{Minimal realisation} Given a transfer function; a state-space model that is controllable and observable, and has the same input-output behaviour as the function, is minimal.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Eigen stuff}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Eigenvalues} Values of $\\lambda$ such that $\\Delta(\\lambda) = |\\lambda \\M{I} - \\M{A}| = 0$.\n\\paragraph{Eigenvectors} Vectors $\\V{v}$ such that $(\\M{A} - \\lambda \\Mc{I})\\V{v} = 0$.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Stability}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Asymptotic stability} Occurs if all poles have strictly negative real parts.\n\\paragraph{Instability} Occurs if one or more poles have positive real parts.\n\\paragraph{Marginal stability} Occurs when the real part of every pole is non-positive, at least one pole has zero real value, and there are no repeated poles on the imaginary axis.\n\\paragraph{BIBO stability} If bounded input $\\rightarrow$ bounded output. Defined for the zero-state response (initially relaxed system). See Section \\ref{sec:bibo}.\n\\paragraph{Lyapunov stability} If every finite initial state gives a finite response. I.e. the zero-input response.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{BIBO Stability}\\label{sec:bibo}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{BIBO Stability for Continuous Systems}\nA continuous system is BIBO stable \\emph{iff}:\n\\begin{itemize}\n\\item\t(SISO) $g(t)$ is absolutely integrable in $[0, \\infty)$ \\quad or \\quad $\\int_{0}^{\\infty} |g(t)| \\dif t \\leq M < \\infty $ for some constant $M$.\n\\item\t(SISO/MIMO) Every pole of every transfer function in $\\M{\\hat{G}}(s)$ or $\\hat{g}(s)$ has a negative real part.\n\\end{itemize}\n\\subsection{BIBO Stability for Discrete Systems}\nA discrete system is BIBO stable iff:\n\\begin{itemize}\n\\item\tEvery pole of every transfer function in $\\M{\\hat{G}}(s)$ or $\\hat{g}(s)$ has magnitude less than $1$.\n\\end{itemize}\n\\subsection{Lyapunov Stability for Linear Systems}\nAn LTI system $\\V{\\dot{x}} = \\M{A}\\V{x}$ is stable if there exists a \\emph{symmetric} positive definite matrix $\\M{P}$ that satisfies the Lyapunov Equation\n$$\\M{A} \\transpose \\M{P} + \\M{MP} = - \\M{N}$$\nWhere $\\M{N}$ is an arbitrary positive definite matrix.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Discretisation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n$$\\M{A}_d = e^{\\M{A}T},\\qquad \\M{B}_d = \\int_0^T e^{\\M{A}\\tau} \\dif \\tau \\M{B}, \\qquad \\M{C}_d = \\M{C}, \\qquad \\M{D}_d = \\M{D}$$\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Similarity transform}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA linear change of coordinates where the original object is expressed with respect to a different basis. The representation of $\\V{x}$ with respect to the basis $\\{ \\V{q}_1, \\dots, \\V{q}_n \\}$ is $\\V{\\bar{x}}$ and with $\\M{Q} = [ \\V{q}_1, \\dots, \\V{q}_n ]$, the similarity transform is\n$$\\V{x} = \\M{Q}\\V{\\bar{x}}.$$\nThe system originally expressed as\n$$\\V{\\dot{x}} = \\M{A}\\V{x} + \\M{B}\\V{u}$$\n$$\\V{y} = \\M{C}\\V{x} + \\M{D}\\V{u}$$\nis transformed to\n$$\\V{\\dot{\\bar{x}}} = \\M{\\bar{A}}\\V{\\bar{x}} + \\M{\\bar{B}}\\V{u}$$\n$$\\V{y} = \\M{\\bar{C}}\\V{\\bar{x}} + \\M{\\bar{D}}\\V{u}$$\nwhere\n$$\\M{\\bar{A}} = \\M{Q}^{-1}\\M{AQ},\\qquad \\M{\\bar{B}} = \\M{Q}^{-1}\\M{B},\\qquad \\M{\\bar{C}} = \\M{CQ},\\quad \\M{\\bar{D}} = \\M{D}$$\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Jordan canonical form}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGeneral strategy:\n\\begin{enumerate}\n\\item Find all eigenvectors corresponding to an eigenvalue of $\\M{A}$.\n\\item The number of L.I. eigenvectors is the number of Jordan blocks.\n\\item For each eigenvector $\\V{q}$, solve $(\\lambda \\Mc{I} - \\M{A}) \\V{v} = \\V{q}$ for the vector $\\V{v}$.\n\\end{enumerate}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Statistics}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\paragraph{Expected value} $\\E[X] = \\int_{-\\infty}^{\\infty} x f(x) \\dif t$\n\\paragraph{Variance} $\\Var(X) = \\E[(X-\\E[X])^{2}] = \\E[X^{2}] - (\\E[X])^{2}$\n\\paragraph{Autocorrelation} $R_X(t_1, t_2) = \\E[X(t_1)X(t_2)]$\n\\paragraph{Wide-sense stationary process} $X(t)$ is WSS if its mean and autocorrelation functions are time invariant: \\quad  $\\E[X(t)] = \\nu$ \\quad and \\quad $R_X(t_1, t_2) = f(t_2-t_1)$.\n\\paragraph{Spectral density function} $S_X(\\jmath\\:\\omega) = \\fourier\\left\\{ R_X(\\tau) \\right\\}$\n\\paragraph{Gauss--Markov process} A stationary Gaussian process $X(t)$ that has an exponential autocorrelation is called a \\emph{Gauss--Markov} process.\n$$R_X(\\tau) = \\sigma^2 e^{-\\beta |\\tau|}$$ $$S_X(\\jmath\\:\\omega) = \\frac{2\\sigma^2\\beta}{\\beta^2 + \\omega^2} \\quad\\text{or}\\quad S_X(s) = \\frac{2\\sigma^2\\beta}{\\beta^2 - s^2}$$\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Linear-quadratic regulator}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA system is given as $$\\V{\\dot{x}} = \\M{A}\\V{x} + \\M{B}\\V{u}$$\nwith a state feedback $\\V{u} = - \\M{K}\\V{x}$ chosen to minimise the cost function\n$$J = \\int_0^\\infty \\V{x}\\transpose \\M{Q} \\V{x} + \\V{u}\\transpose \\M{R} \\V{u} \\dif t$$\nwhere $\\M{Q}$ is symmetric and positive semidefinite, $\\M{R}$ is symmetric and positive definite, and $\\M{K} = \\M{R}^{-1}\\M{B}\\transpose\\M{P}$. The matrix $\\M{P}$ is found by solving $$\\M{A}\\transpose \\M{P} + \\M{PA} - \\M{PBR}^{-1}\\M{B}\\transpose \\M{P} + \\M{Q} = \\M{0}$$\n\nThe relative values of the elements of $Q$ and $R$ enforce tradeoffs between the magnitude of the control action and the speed of the response. The equilibrium can be shifted from $\\V{0}$ to $\\V{x}\\sub{eq}$ by instead using $\\V{u} = \\M{P}\\V{x}\\sub{eq} - \\M{K}\\V{x}$.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Kalman filter}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe system is given as:\n$$\\V{x}_{k+1} = \\M{A}\\V{x}_k + \\M{B}\\V{u}_k + \\V{w}_k$$\n$$\\V{z}_k = \\M{H}_k\\V{x}_k + \\V{v}_k$$\nThe Kalman measurement update equations are:\n$$\\M{K}_k = \\M{P}_k^- \\M{H}_k\\transpose (\\M{H}_k\\M{P}_k^- \\M{H}_k\\transpose + \\M{R}_k)^{-1}$$\n$$\\V{\\hat{x}}_k = \\V{\\hat{x}}_k^- + \\M{K}_k(\\V{z}_k - \\M{H}_k \\V{\\hat{x}}_k^-)$$\n$$\\M{P}_k = (\\Mc{I} - \\M{K}_k \\M{H}_k) \\M{P}_k^- (\\Mc{I}-\\M{K}_k\\M{H}_k)\\transpose + \\M{K}_k\\M{R}_k\\M{K}_k\\transpose$$\nAnd the time update equations are:\n$$\\V{\\hat{x}}_{k+1}^- = \\M{A}\\V{\\hat{x}}_k + \\M{B}\\V{u}_k$$\n$$\\M{P}_{k+1}^- = \\M{AP}_k\\M{A}\\transpose + \\M{Q}_k$$\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Extended Kalman filter}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe system is given as:\n$$\\V{x}_{k+1} = \\V{f}(\\V{x}_k, \\V{u}_k) + \\V{w}_k$$\n$$\\V{y}_k = \\V{h}(\\V{x}_k) + \\V{v}_k$$\nThe Kalman measurement update equations are:\n$$\\M{K}_k = \\M{P}_k^- \\M{C}_k\\transpose (\\M{C}_k \\M{P}_k^- \\M{C}_k\\transpose + \\M{R})^{-1}$$\n$$\\V{\\hat{x}}_k = \\V{\\hat{x}}_k^- + \\M{K}_k \\left(\\V{y}_k - \\V{h}(\\V{\\hat{x}}_k^-)\\right)$$\n$$\\M{P}_k = (\\Mc{I} - \\M{K}_k\\M{C}_k) \\M{P}_k^- (\\Mc{I} - \\M{K}_k\\M{C}_k)\\transpose + \\M{K}_k\\M{R}_k\\M{K}_k\\transpose$$\nAnd the time update equations are:\n$$\\V{\\hat{x}}_{k+1}^- = \\V{f}(\\V{\\hat{x}}_k, \\V{u}_k)$$\n$$\\M{P}_{k+1}^- = \\M{A}_k\\M{P}_k\\M{A}_k\\transpose + \\M{Q}_k$$\nWhere:\n$$\\M{A}_k = \\pd{\\V{f}}{\\V{x}_k}\\bigg|_{\\V{x}_k = \\V{\\hat{x}}_k} \\qquad\\text{and}\\qquad \\M{C}_k = \\od{\\V{h}}{\\V{x}_k}\\bigg|_{\\V{x}_k = \\V{\\hat{x}}_k^-}$$\n\n\\end{document}\n", "meta": {"hexsha": "dbbbc2eaa775913273bfd69fb9560e3a41c030db", "size": 10122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK4115 Linear system theory/TTK4115-Summary.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": "TTK4115 Linear system theory/TTK4115-Summary.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": "TTK4115 Linear system theory/TTK4115-Summary.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": 49.6176470588, "max_line_length": 311, "alphanum_fraction": 0.5513732464, "num_tokens": 3657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.6012253718641217}}
{"text": "\n\\subsubsection{Mission}\n\tIt is necessary to obtain a reasonable estimation of the mission\n\tperformance requirements in order to carry out system level trade studies.\n\tIt is important to note that the exact mission route is dependent on the\n\ttopography of the land between the two notional endpoints. Currently, it is\n\tbeyond the scope of the model to account for the effect that varying\n\ttopology will have on the pod’s trajectory. For simplicity, the model\n\tassumes that the pod travels in a straight, flat line between the departure\n\tand arrival locations, in this case between Los Angeles (LAX) and San\n\tFrancisco (SFO) International airports.\n\tThe mission velocity profile contains three phases: acceleration, coasting\n\twith periodic boosting, and deceleration.\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics{../images/mission_profile.png}\n\t\t\\caption{Notional Velocity Profile in Mission Analysis}\n\t\t\\label{fig:mission_profile}\n\t\\end{figure}\n\t\\Cref{fig:mission_profile} shows a notional velocity profile using the\n\tmission analysis model. The initial acceleration is\n\tmodeled as a constant linear acceleration of 1g from rest to top speed.\n\tPrevious analyses have modeled the start up as an incremental acceleration,\n\tas is shown in \\cref{fig:mission_profile}, to allow for more maneuverability\n\tnear departure and arrival points, and to avoid sustaining potentially\n\tuncomfortable g forces for prolonged periods of time \\cite{Chin}.\n\tThe difference in energy consumption between an incremental acceleration\n\tand the constant acceleration used in this model is negligible.\n\tThe second phase of travel consists of a coasting pod with periodic boosting sections.\n\tIn this phase, the pod begins at top speed and is allowed to coast until it\n\treaches some minimum allowable speed set by the user.\n\tThen, the pod will enter an electromagnetic boosting section which will\n\taccelerate the pod at 1g back to the desired top speed.\n\tFor straight and level travel, the acceleration of the pod is given by the equation\n\t\\begin{equation}\n\t\t\\label{eq:acceleration}\n\t\t\\frac{\\mathrm{d} v}{\\mathrm{d} t} = f ( v  ) = \\frac{1}{m} ( F_{thrust} - \\frac{1}{2}C_{D}\\rho V^{2}A - D_{mag})\n\t\\end{equation}\n\twhere $F_{thrust}$ is the net thrust generated by the flow through the pod\n\tnozzle, $C_D$ is the pod drag coefficient, $\\rho$ is the free stream air\n\tdensity, $A$ is the pod planform area, and $D_{mag}$ is the drag produced\n\tby the magnetic levitation system. The acceleration equation is integrated\n\tto find the time and distance it takes for the pod to decelerate to the\n\tminimum allowable speed using a predictor-corrector integration method.\n\n  The coast distance is used to determine the number of propulsive sections\n\tneeded along the track to complete the mission. The energy consumed in a\n\tsingle propulsive section is then multiplied by the number of propulsive\n\tsections along the track to determine the electromagnetic propulsive energy\n\tconsumed per flight during the coasting phase of the mission. The final\n\tphase of the mission is a constant linear deceleration of 0.5g from top\n\tspeed to rest. Many systems driven by electromagnetic propulsion conserve\n\tenergy through regenerative braking \\cite{inductrack}. For the sake of\n\tconservatism, it is assumed that there is no regenerative braking in this\n\tprocess, although the model allows for regenerative braking to be\n\taccounted for if the user desires. The energy consumed per flight is\n\tcomputed by adding the consumption of all three phases.\n\n\\subsubsection{Cost}\n\tThe cost module estimates the cost of energy, materials, pods, and\n\tconstruction capital. The cost of construction is highly subjective and is\n\tdifficult to get an accurate estimation within less than an order of\n\tmagnitude of uncertainty. However, the cost of materials and energy\n\tconsumption can be estimated with significantly greater certainty.\n\tThus, in this analysis, the cost estimations of materials and energy are of greater interest.\n\tThe average price of electricity used in the model is 0.13 USD/kWh, based on\n\tdata from the Electricity Information Administration\\cite{EIA}.\n\tUsing a different value will not significantly change the trends in the trade studies this model produces.\n\tA rough estimation of the ticket cost is included, which projects ticket cost based on the equation\n\t\\begin{equation}\n\t\t\\label{eq:ticket_cost}\n    \\text{Cost}_\\text{ticket} = \\frac{ (\\frac{\\partial \\text{Cost}}{\\partial D}D+\\frac{\\partial \\text{Cost} }{\\partial \\text{pod}}n_{\\text{pods}}+\\text{Cost}_\\text{capital} ( 1+ib ) + \\frac{\\partial \\text{Cost}}{\\partial \\mathcal{E}} (\\mathcal{E}_\\text{tube} + \\mathcal{E}_\\text{pod}  ))  )}{n_\\text{passengers}*\\frac{\\text{pods}}{s}*3600\\frac{s}{\\text{\\text{year}}}*24\\frac{\\text{\\text{year}}}{\\text{day}}*365\\frac{\\text{day}}{\\text{year}}*bm}\n\t\\end{equation}\n\tWhere $ib$ is the bond interest rate, $bm$ is the number of years for bond\n\tmaturity, and $D$ is the total length of the track. Previous research\n\tindicated that construction costs are likely to be the largest cost factor\n\tin the system \\cite{Musk}. Due to the lack of a reliable method of\n\testimating construction cost or ticket markup at this stage of the design process,\n\tthe exact values of the ticket cost produced by this model will have a high level of uncertainty.\n\tHowever, the trade studies conducted in these analyses can provide useful\n\tinformation to inform the development of more accurate ticket cost models in the future.\n", "meta": {"hexsha": "e391aba75befe6dc4c5cedd0d73097c407c59689", "size": 5463, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/model_overview/top_level_comp_descriptions.tex", "max_stars_repo_name": "NASA-MARTI/MagnePlane", "max_stars_repo_head_hexsha": "ac6261ffc2926cc4041185563044de3dac0101e6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-10-16T02:18:39.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-16T02:18:39.000Z", "max_issues_repo_path": "paper/sections/model_overview/top_level_comp_descriptions.tex", "max_issues_repo_name": "NASA-MARTI/MagnePlane", "max_issues_repo_head_hexsha": "ac6261ffc2926cc4041185563044de3dac0101e6", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2016-11-23T09:10:34.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-06T01:10:09.000Z", "max_forks_repo_path": "paper/sections/model_overview/top_level_comp_descriptions.tex", "max_forks_repo_name": "NASA-MARTI/MagnePlane", "max_forks_repo_head_hexsha": "ac6261ffc2926cc4041185563044de3dac0101e6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-06-29T23:45:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-02T09:46:26.000Z", "avg_line_length": 66.6219512195, "max_line_length": 444, "alphanum_fraction": 0.7812557203, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6012253657571641}}
{"text": "% !TeX root = ./type-system.tex\n\\pdfcompresslevel=0\n\\documentclass[12pt, letterpaper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[english]{babel}\n\\usepackage{fancyhdr}\n\\usepackage{mathtools}\n\n\\newcommand{\\subt}{\\mathrel{<\\vcentcolon}}\n\\newcommand{\\supt}{\\mathrel{>\\vcentcolon}}\n\n\\setlength{\\headheight}{15pt}\n\\pagestyle{fancy}\n\\begin{document}\n\n\\section*{Representation of Types}\n\\begin{itemize}\n    \\item type void = \\( \\bot \\)\n    \\item type any = \\( \\top \\)\n    \\item type union \\( \\alpha_\\epsilon \\) = \\( \\bigcup\\limits_{i < \\epsilon} x_i \\)\n    \\item type func \\( \\alpha~\\tau \\) = \\( \\alpha \\rightarrow \\tau \\)\n    \\item type poly \\( \\sigma \\) = \\( \\forall\\alpha.\\tau[\\alpha \\coloneqq \\sigma ]\\)\n    \\item type list \\( \\alpha \\) = \\( \\{ x : x \\in \\alpha \\} \\)\n\\end{itemize}\n\n\\end{document}", "meta": {"hexsha": "391e9ef3142e6136eb4ecccdeae1334e04c5087a", "size": 799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bs1/docs/type-system.tex", "max_stars_repo_name": "sci4me/eso69", "max_stars_repo_head_hexsha": "1a85869c06724d98feaa9b8c850b9a6aa0e32884", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bs1/docs/type-system.tex", "max_issues_repo_name": "sci4me/eso69", "max_issues_repo_head_hexsha": "1a85869c06724d98feaa9b8c850b9a6aa0e32884", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bs1/docs/type-system.tex", "max_forks_repo_name": "sci4me/eso69", "max_forks_repo_head_hexsha": "1a85869c06724d98feaa9b8c850b9a6aa0e32884", "max_forks_repo_licenses": ["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.7307692308, "max_line_length": 84, "alphanum_fraction": 0.648310388, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6011236778084058}}
{"text": "\\chapter{Results}\n\\begin{comment}\n\n\n\\end{comment}\n\n\\section{Lenard-Jones Potential with direct Summation}\n\\begin{comment}\n\n\\end{comment}\n\n% Plot of the total energy as a function of time\n\nFirst we take a look at a simulation with just the lenard-jones-potential. \nFirst a good timestep for the simulation has to be chosen. \nSo we search for a good $ \\mathrm{prefactor} $ for the following equation \\cite{molDymCourse}.\n\\begin{equation}\n\t\\label{timestepDeterminant}\n \\mathrm{timestep} = \\mathrm{prefactor} * \\sqrt{(m\\sigma^2)/\\epsilon} \n\\end{equation}\nTo decide on a good timestep a sequence of plots, as can be seen in Fig. \\ref{SimWithTimestep},was created. \n\\par \nAs the prefactor gets bigger, the energy in the simulation goes from stable (prefactor 0.01) over a drifting behavior (prefactor 0.03) to being unstable (prefactor 0.05). A good prefactor would be 0.01.\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale= 1.0]{/home/cm/CLionProjects/MDCode/AData//totalEnergyDrift.png}\n\t\\end{center}\n\t\\caption[Comparison of the energy in the simulation with different timesteps]{Comparison of the energy in the simulation for different timesteps. We run the simulation with $\\mathrm{m}, \\sigma, \\epsilon = 1$ for a constant number of steps $\\mathrm{n_{steps}} = 10000 $}\n\t\\label{SimWithTimestep}\n\\end{figure}\n\\par\nTo visualize the simulation OVITO \\cite{ovito} was used and a series of snapshots, visible in Fig. \\ref{SimulationSnapshot1} - \\ref{SimulationSnapshot3}, was created. The following images show one of the first simulations, where the forces were calculated with the Lenard-Jones-Potential. The simulated cluster had a size of 52 atoms, and was given in the course lecture material \\cite{molDymCourse}.\n% Simulation Snapshots\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale= 0.65]{Figure/1ImageS.png}\n\t\\end{center}\n\t\\caption[Simulation Snapshot 1]{Initial state of the cluster}\n\t\\label{SimulationSnapshot1}\n\\end{figure}\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale= 0.75]{Figure/2ImageS.png}\n\t\\end{center}\n\t\\caption[Simulation Snapshot 2]{State after 2000 timesteps}\n\t\\label{SimulationSnapshot2}\n\\end{figure}\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale= 0.65]{Figure/3ImageS.png}\n\t\\end{center}\n\t\\caption[Simulation Snapshot 3]{State after 4000 timesteps}\n\t\\label{SimulationSnapshot3}\n\\end{figure}\nAs it can be seen in the images \\ref{SimulationSnapshot1}, \\ref{SimulationSnapshot2} and \\ref{SimulationSnapshot3} the Atoms are initially ordered into a cluster.\nLater in the simulation some of the atoms escaped the initial cluster and flew outward separately. \n\\section{Simulation with the Berendsen Thermostat}\n\\begin{comment}\ncomputational complexity \nwhy on2\noptimization not every force is looked at individually as the force resluting form this atom is the same for the other atom but negative\n\\end{comment}\nAfter incorporating the Berendsen thermostat into the code it is interesting to look at the computational complexity of the simulation. \nWith growing numbers of atoms the computation-time should grow quadratically. \nThe main source for this is the force-computation, as each interaction with all the other atoms in the simulation has to be computed. This is also shown in the next figure as the computation time seems to follow a quadratic function. \n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale=1]{Figure/plotAtomTimesM5.png}\n\t\\end{center}\n\t\\caption[Comparison of the time needed to simulate 8 to 192 Atoms]{Comparison of the time needed to simulate 8 to 192 Atoms. The simulation was run with the parameters $\\sigma, \\epsilon = 1$ , $m = 12~\\mathrm{u}$ for a total of 10000 steps with a duration of each $\\mathrm{timestep}$ being $0.01\\sqrt{(m\\sigma^2)/\\epsilon} $. The relaxationtime of the thermostat was set to 50 $\\mathrm{timestep} $, which is very low, but was done to get the simulation stable in all cases. The thermostat had a target-temperature of 275 (as a value).} \n\t\\label{PlotSimulationTimeBerendsenThermostat}\n\\end{figure}\n\nAlthough all the interaction between the atoms are computed, the individual forces do not carry the same weight to the force that affects the atom. It should be rather clear that, the further atoms are apart, the smaller the forces get. After a certain distance it gets so small that it can be ignored. This leads to the idea to use neighborhood-lists that ignore the atoms outside of a certain radius. It has been done in the next section.\n\n\\section{Simulation with the Neighborhood-List}\n\\begin{comment}\n\n\\end{comment}\nAfter running the simulation in the previous section, it was clear that they follow a computational complexity of the order O(N²). This can be reduced to a linear order O(N) with the usage of neighborhood-lists. Only the atoms in a certain radius around the atom will be considered and a force will be added to the total force affecting the atom. This can be seen in Fig. \\ref{PlotSimulationTimesCutoffNew}.\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[scale=1.25]{Figure/plotAtomTimesM6.png}\n\t\\end{center}\n\t\\caption[Comparison of the simulationtime with neighborhood-lists ]{Comparison of the simulationtime with Neighborhood-lists. Basic parameters are the same as in Fig. \\ref{PlotSimulationTimeBerendsenThermostat}, but with an additional cutoff of 2.5$\\sigma$.}\n\t\\label{PlotSimulationTimesCutoffNew}\n\\end{figure}\n\n\\section{Simulation with the Embedded-Atom Method Potential}\n\\begin{comment}\n1 graph\n- potential energy gets less with an increase to the clustersize\n- the \n\n2 \nHeat capacity and latent heat should converge\n\\end{comment}\nIn the next step the embedded-atom method was used to compute the potential energy and the forces between the atoms. \nA neighborhood-list was also used. \nWith this it was possible to look at the actual physical properties(meltingpoint, latent heat, heat capacity) of the different materials - in this case gold. \n\n\\par \n%hard to get sim right quite the hassle\n%We now look at the steps to get good data from the simulation. \n%get the units right fix to time unit\nFirst we have to get the units right. In the simulations beforehand, we simulated in Lenard-Jones units. \nHere we will use real units. \nThis means for the timestep fs, for the distance \\r{A}, for the mass u and for the energy eV. \nWe have to fix either the mass unit (mass of gold is 196.97u \\cite{Kurzweil2015}) or the time unit. \nThe later was chosen. To get to a timestep of 1 fs we have to consider the expression $ [m] = [E][t]^2/[l]^2 = 1.6\\mathrm{E}-19 * 1\\mathrm{E}-30/1\\mathrm{E}-20~\\mathrm{kg} = 1.6\\mathrm{E}-29~\\mathrm{kg} $. For the final result we have to divide the mass of gold by the factor $ f = 1.6\\mathrm{E}-29/\\mathrm{u} = 0.009635 $\n\\cite{molDymCourse}.\n\n%stettled on 3 steps: preheating, waiting vor a time after switching sim off -> diagram looks nicer\nIn the next step it is necessary to come up with a scheme to acquire good data.\nFor this it is very helpful to look at the kinetic energy in relation to time. \nThis is shown in Fig. \\ref{GoldClusterSimulationKinVsTime}. \nWhen the temperature is being increased via rescaling of the kinetic energy, we pump energy into the system. \nIf we do this at temperatures, that are too low, the cluster is unstable and will start pulsing. \nSo in the first step of the simulation we preheat the cluster via a thermostat to 300~K. \nAfter this is done, we stop using the thermostat, as it would interfere with the measurement. \nNow we could start to heat up the system and obtain the data for the next figures. But it has been rather helpful to wait for a bit after the thermostat is switched off. In doing so, we can obtain smoother graphs and data. \n\\par\n%TODO not sure if nesessary lol \n%heat up with 5e-3 eV per step\nWe heat the system up for a total of 50000 steps. Then we wait for 1000 steps after switching of the thermostat. \nAfter that we start to heat up the system for a total of 120 times and deposit 5e-3~eV per Atom. \nIn one of these steps, we run the simulation for a total of 6000 times and record the temperature in the later half. \nThen the average temperature is recorded. \nThe exact number of steps were practically determined via small experiments that were scaled up. \n%Dude i dont know my own code \n\\begin{figure}\n\t%Higher than 9 just nicer to look at!!!\n\t\\begin{center} \n\t\t\\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/kineticEnergyCurve14.png} \n\t\\end{center} \n\t\\caption[Gold cluster simulation: Kinetic Energy vs Time]{Gold cluster simulation: Kinetic energy vs time for 10179 Atoms} \n\t\\label{GoldClusterSimulationKinVsTime} \n\\end{figure} \n\n\n\\par \nIn Fig.  \\ref{GoldClusterSimulationTemperaturEnergy4In1} energy and temperature for different cluster sizes are plotted. \nIt is possible to extract the melting point, the heat-capacity and the latent-heat from this diagram. \nThis can be seen in the next Fig.\\ref{GoldClusterSimulationVsClustersize} in relation to the size of the atom-cluster.\n\\par \nThe first interesting property is the melting point of the cluster. It can be seen in the different curvatures in the graphs in figure \\ref{GoldClusterSimulationTemperaturEnergy4In1} (for the red graph at 900~K for example). \nThe melting point increases as the clusters get bigger. \nBut it is still not near it's macroscopic equivalent of 1337~K \\cite{Kurzweil2015}. %TODO this was converted but i think its ok\n\\par\nIt can also be seen that the potential energy of the average atom decreases with bigger clustersizes. \nTo explain this, the ratio of surface to volume of the cluster and the fact that atoms at the border of the cluster need to have a higher energy, have to be considered. \nWith increased clustersizes a smaller percentage of atoms is at the edge, which leads to an increases in the total energy of the cluster. \nThe slope of the jump at the melting point also grows with bigger clustersizes. \nFor many atoms these curves would be piecewise linear with a high-slope section around the melting point. \nThe simulated system seems to converge to that. \n\n\\begin{figure}\n\t\\begin{center} \n\t\t\\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/temperaturPotentialEnergyCurveMoreInOne.png} \n\t\\end{center} \n\t\\caption[Gold cluster simulation]{Gold cluster simulation with different quantities of atoms with a cutoff-distance of 10~\\r{A}} \n\t\\label{GoldClusterSimulationTemperaturEnergy4In1} \n\\end{figure} \n\nIn the diagram of Fig. \\ref{GoldClusterSimulationVsClustersize} which plots the heat capacity and the latent heat, it can be seen that both seem to converge. On the other hand, the melting point still seems to increase as it is still away from it's true melting point.\n\n\\begin{figure}\n\t\\begin{center} \n\t\t\\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/VsClusterSizeAll.png} \n\t\\end{center} \n\t\\caption[Melting point, heat capacity and latent heat vs clustersize]{Melting point, heat capacity and latent heat vs clustersize} \n\t\\label{GoldClusterSimulationVsClustersize} \n\\end{figure} \n", "meta": {"hexsha": "e42b34364710e634755c07ab45520671c220d399", "size": 10999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AALatex/Tex/results.tex", "max_stars_repo_name": "cmoser8892/MoleDymCode", "max_stars_repo_head_hexsha": "9077289a670c6cb0ed9e1daac5a03b51c83bc6fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AALatex/Tex/results.tex", "max_issues_repo_name": "cmoser8892/MoleDymCode", "max_issues_repo_head_hexsha": "9077289a670c6cb0ed9e1daac5a03b51c83bc6fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AALatex/Tex/results.tex", "max_forks_repo_name": "cmoser8892/MoleDymCode", "max_forks_repo_head_hexsha": "9077289a670c6cb0ed9e1daac5a03b51c83bc6fb", "max_forks_repo_licenses": ["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.7921348315, "max_line_length": 537, "alphanum_fraction": 0.7805255023, "num_tokens": 2863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321936479701, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6011136028172785}}
{"text": "% Chapter Template\n\n\\chapter{Classification Algorithms} % Main chapter title\n\n\\label{Chapter4} % Change X to a consecutive number; for referencing this chapter elsewhere, use \\ref{ChapterX}\n\n\\lhead{\\emph{Classification Algorithms}} % Change X to a consecutive number; this is for the header on each page - perhaps a shortened title\n\n%----------------------------------------------------------------------------------------\n%\tSECTION 1\n%----------------------------------------------------------------------------------------\n\nMachine learning algorithms are the fundamental of all classification program. \nThese algorithms are divided in two big families: the supervised learning and the unsupervised learning.\nIn this project only supervised learning models are used.\nThis section presents briefly the classification algorithms used in this work. \n\\section{Naïve Bayes classifier}\nA Naïve Bayes classifier\\cite{website:Naive_Bayes_classifier} is a simple probabilistic classifier based on applying Bayes' theorem (from Bayesian\nstatistics) with strong (naive) independence assumptions. \nIn simple terms, a naive Bayes classifier assumes that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature.\nDepending on the precise nature of the probability model, naive Bayes classifiers can be trained very efficiently in a supervised learning setting.\n\n\\subsection{The Naïve Bayes probabilistic model}\nAbstractly, the probability model for a classifier is a conditional model.\n$$ P(C|F_1, \\cdots, F_n) $$\n\nOver a dependent class variable $C$ with a small number of outcomes or $classes$, conditional on several feature\nvariables $F_1$ through $F_n$ . The problem is that if the number of features $n$ is large or when a feature can take on a\nlarge number of values, then basing such a model on probability tables is infeasible. Therefore the\nmodel is formulated to make it more tractable using Bayes' theorem:\n$$ P(C|F_1, \\cdots, F_n) = \\frac{p(C)p(F_1, \\cdots, F_n|C)}{p(F_1, \\cdots, F_n)}$$  The equation could be formulated as follow in a literal way $$posterior = \\frac{prior * likelihood}{evidence}$$\n\n\n%----------------------------------------------------------------------------------------\n%\tSECTION 2\n%----------------------------------------------------------------------------------------\n\n\\section{Support Vector Machine}\nA Support Vector Machine (SVM) is a discriminative classifier formally defined by a separating hyperplane. In other words, given labeled training data (supervised learning), the algorithm outputs an optimal hyperplane which categorizes new examples.\nThe figure \\ref{fig:hyperplane} shows an example for a linearly separable set of 2D-points which belong to one of two classes.\n\\begin{figure}[H]\n  \\centering\n  \\includegraphics[width=60mm]{figures/optimal-hyperplane.png}\n  \\caption{Optimal hyperplane \\label{fig:hyperplane}}\n\\end{figure}\nThe optimal hyperplane computedusing equation \\ref{eq:hyperplane}:\n\n\\begin{equation}\n\\label{eq:hyperplane}\nf(x) = \\beta_{0} + \\beta^{T} x\n\\end{equation}\nWhere $\\beta$ is known as the weight vector and $\\beta_{0}$ as the bias.\n\n%----------------------------------------------------------------------------------------\n%\tSECTION 3\n%----------------------------------------------------------------------------------------\n\n\\section{Maximum Entropy}\nThe maximum entropy classifier estimates probabilities\nbased on the principle of making as few\nassumptions as possible, other than the constraints\nimposed. Such constraints are derived from training\ndata, expressing some relationship between features\nand outcome. The probability distribution\nthat satisfies the above property is the one with\nthe highest entropy. It is unique, agrees with the\nmaximum-likelihood distribution, and has the exponential\nform :\n\n\\begin{equation}\n\\label{eq:maxent}\np(o|h) = \\frac{1}{Z(h)}\\prod_{j=1}^k\\alpha_j^{f_j(h,o)}\n\\end{equation}\n\nWhere: \n\\begin{itemize}\n\\item $o$ refers to the outcome\n\\item $h$ refers to the history or context.\n\\item $Z(h)$ is a normalization function.\n\\item $f_j(h,o)$ is a binary function.\n\\item $\\alpha_j$ is estimated by a procedure called Generalized Iterative Scaling (GIS). This is an iterative method that improves the estimation of the parameters at each iteration.\n\\end{itemize}", "meta": {"hexsha": "481c0cb981f348841c235ea6c4a0d8a2720ba803", "size": 4325, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/Chapters/Chapter4.tex", "max_stars_repo_name": "HaythemSahbani/Text-Mining-", "max_stars_repo_head_hexsha": "7447b6dfbcbe8f30062d9956c80ab0ae7dc790fa", "max_stars_repo_licenses": ["MIT"], "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/Chapters/Chapter4.tex", "max_issues_repo_name": "HaythemSahbani/Text-Mining-", "max_issues_repo_head_hexsha": "7447b6dfbcbe8f30062d9956c80ab0ae7dc790fa", "max_issues_repo_licenses": ["MIT"], "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/Chapters/Chapter4.tex", "max_forks_repo_name": "HaythemSahbani/Text-Mining-", "max_forks_repo_head_hexsha": "7447b6dfbcbe8f30062d9956c80ab0ae7dc790fa", "max_forks_repo_licenses": ["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.743902439, "max_line_length": 249, "alphanum_fraction": 0.6853179191, "num_tokens": 952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6011135947874472}}
{"text": "\\problemname{Driving Lanes}\n\nWhile driving around a curve on the highway, Sam realizes that if they\nuse the inside lane, they travel a shorter distance. Sam wonders what\nis the minimum distance needed to travel to the destination.\n%across the entire highway.\n\n\n\nThe multilane highway consists of a sequence of straightaways that are\nconnected by curves. When going around a curve, the distance travelled\ndepends on which lane you are in. Each curve has a curvature $c$ and\nstretch $s$. Specifically, if Sam is in lane $i$, then they travel\n$s + c \\cdot i$ meters while going around this curve.\n\n\n\nWhenever Sam is on a straightaway, they may change from one lane into\nan adjacent lane.  When changing to an adjacent lane, Sam moves\nforward $k$ meters, but travels a total of $k+r$ meters.  Each lane\nchange must be completed before the car reaches the end of the current\nstraightaway.  Sam may change lanes multiple times in the same\nstraightaway. For safety reasons, changing lanes is not possible on\ncurves.\n\n\\begin{center}\n \\includegraphics[width=0.8\\textwidth]{chla.pdf}\n\\end{center}\n\nSam starts in lane $1$ and wishes to end in lane $1$. What is the minimum\ndistance they must travel?\n\n\n\n\\section*{Input}\n\nThe first line of input contains two integers\n$n$~($1 \\leq n \\leq 250$), which is the number of straightaways, and\n$m$~($1 \\leq m \\leq 250$), which is the number of lanes on the\nhighway. The lanes are numbered $1, 2, \\dots, m$.\n\n\n\nThe second line of input contains two integers\n$k$~($1 \\leq k \\leq 10^6$) and $r$~($1 \\leq r \\leq 10^6$), which are\nthe lane changing parameters.\n\n\n\nThe next $n$ lines describe the straightaways in order. Each of these lines\ncontains a single integer $\\ell$~($1 \\leq \\ell \\leq 10^6$), which is\nthe length of this straightaway.\n\n\n\nThe next $n-1$ lines describe the curves in order. Each of these lines contains\ntwo integers $s$~($1 \\leq s \\leq 10^6$), which is the stretch of\nthis curve, and $c$~($-10^6 \\leq c \\leq 10^6$), which is the curvature of\nthis curve. It is guaranteed that $s + c \\cdot m > 0$.\n\nThe $i$th curve connects the $i$th and $(i+1)$th straightaway.\n\n\n\n\\section*{Output}\n\nDisplay the minimum distance Sam must travel.\n", "meta": {"hexsha": "680998d782253328c451be9895b8e698f4ec0d3b", "size": 2177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/drivinglanes/problem_statement/problem.tex", "max_stars_repo_name": "icpc/na-rocky-mountain-2018-public", "max_stars_repo_head_hexsha": "416a94258f99ab68ff7d9777faca55c94cdaf5f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-22T16:34:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T16:34:26.000Z", "max_issues_repo_path": "problems/drivinglanes/problem_statement/problem.tex", "max_issues_repo_name": "icpc/na-rocky-mountain-2018-public", "max_issues_repo_head_hexsha": "416a94258f99ab68ff7d9777faca55c94cdaf5f5", "max_issues_repo_licenses": ["MIT"], "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/drivinglanes/problem_statement/problem.tex", "max_forks_repo_name": "icpc/na-rocky-mountain-2018-public", "max_forks_repo_head_hexsha": "416a94258f99ab68ff7d9777faca55c94cdaf5f5", "max_forks_repo_licenses": ["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.0147058824, "max_line_length": 79, "alphanum_fraction": 0.7363344051, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6011135884986247}}
{"text": "%%%%this file inputes all section-02-*.tex files. \n\\chapter{Overview of various smoothers}\nA scatter plot smoother is a tool for finding structure in a scatter\nplot: $(x_1,y_1),\\dots,(x_n,y_n)$\n\n\n\\begin{figure}[htp]\n\\caption{\\label{f2.1} CD4 cell count since seroconversion for HIV\n  infected men.} \n\\centerline{\\epsfig{figure=Plots/plot-02-01.ps,angle=270,width=.8\\textwidth}}\n\\end{figure}\n\n\\begin{itemize}\n\\item Suppose that we consider $\\by = (y_1,\\dots,y_n)'$ as the {\\it response\nmeasurements} and $\\bx = (x_1,\\dots,x_n)'$ as the {\\it design points}.\n\n\\item We can think of $\\bx$ and $\\by$ as outcomes of random variable $X$\nand $Y$. However, for scatter plot smoothers we don't\nreally need stochastic assumptions, it can be considered as a\ndescriptive tool.\n\n\\item A scatter plot smoother can be defined as a function (remember\n  the general definition of {\\it function}) of $\\bx$ and\n$\\by$ with domain at least containing the values in $\\bx$: $s =\n\\bS[\\by | \\bx]$. \n \n\\item There is usually a ``recipe'' that gives $s(x_0)$, which is the function\n$\\bS[\\by | \\bx]$ evaluated at $x_0$,  for all $x_0$. We will be\ncalling $x_0$ the {\\it target value} when we giving the recipe. Note:\nSome recipes don't give an $s(x_0)$ for all $x_0$, but only for the\n$x$'s included in $\\bx$. \n\n\\end{itemize}\n\nNote we will call the vector $\\{s(x_1),\\dots,s(x_n)\\}'$ as {\\it the smooth}.\n\nHere is a stupid example: If we assume a random desing model and take\nexpectations over the empirical distribution $\\hat{F}$, defined by the\nobservations, we have for any $x_0 \\in \\{x_1,\\dots,x_n\\}$, \n\\[\nE_{\\hat{F}}[Y|X=x_0] = \\ave \\{ y_i; x_i = x_0\\}. \n\\]\nDefine $s(x_0)=\\E_{\\hat{F}}[Y|X=x_0]$. What happens if the $x_i$ are\nunique? \n\nSince $Y$ and $X$ are, in general,  non-categorical we don't expect to\nfind many replicates at any given value of $X$. This means that we\ncould end up with the data again, $s(x_0)=y_0$ for all $x_0$. Not very\nsmooth!\n\nNote: For convenience, through out this chapter,  we assume that the\ndata are sorted by $X$. \n\nMany smoothers force  $s(x)$ to be a smooth function of $x$. This is\na fancy way of saying we think data points that are close (in $x$)\nshould have roughly the same expectation. \n\n\\newpage\n\n\\input{section-02-01}\n\n\\newpage\n\n\\input{section-02-02}\n\n\\newpage\n\n\\input{section-02-03}\n\n\\input{section-02-04}\n\n\\input{section-02-05}\n\n\n\n\n", "meta": {"hexsha": "dbcaaf3123ef39c70a431b89fbf79848fcf25d29", "size": 2353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-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.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.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": 30.5584415584, "max_line_length": 78, "alphanum_fraction": 0.6982575436, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6011135850166067}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{amsmath}\n\n\\usepackage{Sweave}\n\\begin{document}\n\\input{sweave_example-concordance}\n\n%------------------------------------------------------------\n\\title{An example Sweave document}\n\\author{Eli Holmes}\n\\maketitle\n%------------------------------------------------------------\n\nThis is a super simple template to show you how to use Sweave to combine LaTeX with R code and create a PDF. Google 'Sweave tutorial' or 'LaTeX tutorial' to learn more about Sweave and LaTeX.  You will need LaTeX installed.  Mac users should have this already installed.  PC users will need to install MikTeX (and then talk to Eli to get it set up properly).\n\n\\section*{Problem 1}\n%The * tells LaTeX not to number the sections\n\nThis is my solution to problem 1: add together 2 numbers. I decided to do $1+1$. It was not very hard. \n\\begin{Schunk}\n\\begin{Sinput}\n> 1+1\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2\n\\end{Soutput}\n\\end{Schunk}\n\n\\section*{Problem 2}\n\nThis question asked me to add together the numbers 1 to 9, so $\\sum_{i=1}^9 i$. This question was also easy.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> sum(1:9)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 45\n\\end{Soutput}\n\\end{Schunk}\n\n\\section*{Problem 3}\n\nUse the \\verb@lm@ function to do a linear regression using the example in \\verb@?lm@.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> ## Annette Dobson (1990) \"An Introduction to Generalized Linear Models\".\n> ## Page 9: Plant Weight Data.\n> ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)\n> trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)\n> group = gl(2, 10, 20, labels = c(\"Ctl\",\"Trt\"))\n> weight = c(ctl, trt)\n> lm.D9 = lm(weight ~ group)\n\\end{Sinput}\n\\end{Schunk}\n\nWe can use \\verb@summary@ to get a summary. Figure \\ref{fig:summarylm} shows the 4 figures that plotting a lm object produces.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> summary(lm.D9)\n\\end{Sinput}\n\\begin{Soutput}\nCall:\nlm(formula = weight ~ group)\n\nResiduals:\n    Min      1Q  Median      3Q     Max \n-1.0710 -0.4938  0.0685  0.2462  1.3690 \n\nCoefficients:\n            Estimate Std. Error t value Pr(>|t|)    \n(Intercept)   5.0320     0.2202  22.850 9.55e-15 ***\ngroupTrt     -0.3710     0.3114  -1.191    0.249    \n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 0.6964 on 18 degrees of freedom\nMultiple R-squared:  0.07308,\tAdjusted R-squared:  0.02158 \nF-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249\n\\end{Soutput}\n\\end{Schunk}\n\n\\section*{Problem 4}\n\nUse \\verb@plot()@to get diagnostic plots.  This is the code I used:\n%just show code but don't evaluate here.\n\\begin{Schunk}\n\\begin{Sinput}\n> #set the par to 4x4 figure and then set back at the end\n> opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))\n> plot(lm.D9, las = 1)      # Residuals, Fitted, ...\n> par(opar)\n\\end{Sinput}\n\\end{Schunk}\nThe figure generated by this is in Figure \\ref{fig:summarylm}.\n\n% The first bit is the set up of a figure in LaTeX and the middle bit is the code that makes the figure. The [h] says to place the figure \"here\" approximately. [t] is top. [b] is bottom. Notice I pass in echo=FALSE so that the code doesn't show up.\n\\setkeys{Gin}{width=5in}\n\\begin{figure}[h]\n\\begin{center}\n\\includegraphics{sweave_example-summary_plot}\n\\end{center}\n\\caption{This is a summary of the linear regression.}\n\\label{fig:summarylm}\n\\end{figure}\n\\setkeys{Gin}{width=\\textwidth}\n\n\\section*{Problem 5}\nThe last problem asked me to write a function to do $$\\sqrt{b^2 - 4ac}$$.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> myfun = function(a,b,c){return(sqrt(b^2-4*a*c))}\n> myfun(1,3,1)\n\\end{Sinput}\n\\begin{Soutput}\n[1] 2.236068\n\\end{Soutput}\n\\end{Schunk}\n\n\\section*{Problem 6}\n\nThis problem asked me to write out a matrix equation $\\mathbf{A}\\mathbf{B}$ with $\\mathbf{A}$ as a $3 \\times 2$ matrix and $\\mathbf{B}$ as a $2 \\times 2$ matrix.  I chose this equation:\n$$\n\\mathbf{A}\\mathbf{B}=\n\\begin{bmatrix} 1 & 4\\\\ 2 & 5 \\\\ 3 & 6\\end{bmatrix}\n\\begin{bmatrix} 3 & 0 \\\\ 0 & 3 \\end{bmatrix}\n$$\nHere's my R code:\n\n\\begin{Schunk}\n\\begin{Sinput}\n> A=matrix(1:6,3,2)\n> B=diag(3,2)\n> A%*%B\n\\end{Sinput}\n\\begin{Soutput}\n     [,1] [,2]\n[1,]    3   12\n[2,]    6   15\n[3,]    9   18\n\\end{Soutput}\n\\end{Schunk}\n\n\n\\end{document}\n", "meta": {"hexsha": "be37dbacbeef1cef03529e361523af4305922eee", "size": 4223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Homework Templates/sweave_example.tex", "max_stars_repo_name": "atsa-es/atsa2021", "max_stars_repo_head_hexsha": "50d16e728a6c9ea8b5705161350f69e7ddedcf1f", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-21T18:58:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T11:50:46.000Z", "max_issues_repo_path": "Labs/Homework Templates/sweave_example.tex", "max_issues_repo_name": "atsa-es/atsa2021", "max_issues_repo_head_hexsha": "50d16e728a6c9ea8b5705161350f69e7ddedcf1f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-08T10:46:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T10:46:18.000Z", "max_forks_repo_path": "docs/Labs/Homework Templates/sweave_example.tex", "max_forks_repo_name": "atsa-es/atsa2021", "max_forks_repo_head_hexsha": "50d16e728a6c9ea8b5705161350f69e7ddedcf1f", "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.9668874172, "max_line_length": 358, "alphanum_fraction": 0.6573525929, "num_tokens": 1543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.6010684123466649}}
{"text": "\\clearpage %or \\cleardoublepage\n\\phantomsection\n\\chapter*{Notation}\n\\markright{}\n\\addcontentsline{toc}{chapter}{Notation}\n\n\\begin{longtable}[l]{ l p{0.85\\textwidth} }\n  $a=\\cfrac{dC_L}{d \\alpha}$                   & [1/rad] lift curve slope \\\\\n  $A=\\cfrac{b^2}{S}$                           & [-] wing aspect ratio \\\\\n  $b$                                          & [m] wing span \\\\\n  $c_r$                                        & [m] chord at wing root \\\\\n  $c_t$                                        & [m] chord at wing tip \\\\\n  $\\hat c$, $MAC$                              & [m] mean aerodynamic chord \\\\\n  $C_D$                                        & [-] drag coefficient \\\\\n  $C_l$                                        & [-] rolling moment coefficient \\\\\n  $C_L$                                        & [-] lift coefficient \\\\\n  $C_m$                                        & [-] pitching moment coefficient \\\\\n  $C_n$                                        & [-] yawing moment coefficient \\\\\n  $C_Y$                                        & [-] side force coefficient \\\\\n  $C_{\\mu}$                                    & [-] k-$\\varepsilon$ turbulence model constant \\\\\n  $d$                                          & [m] fuselage diameter \\\\\n  $D$                                          & [N] drag \\\\\\\n  $e$                                          & [-] Oswald efficiency factor \\\\\n  $i$                                          & [rad] incidence angle \\\\\n  $I$                                          & [-] turbulence intensity \\\\\n  $k$                                          & [m\\textsuperscript{2}/s\\textsuperscript{2}] turbulence kinetic energy \\\\\n  $L$                                          & [N] lift \\\\\n  $L$                                          & [m] reference length scale \\\\\n  $p$                                          & [Pa] pressure \\\\\n  $Re$                                         & [-] Reynolds number \\\\\n  $S$                                          & [m\\textsuperscript{2}] wing area \\\\\n  $V$                                          & [m/s] velocity \\\\\n  $\\alpha$                                     & [rad] angle of attack \\\\\n  $\\beta$                                      & [rad] angle of sideslip \\\\\n  $\\lambda=\\cfrac{c_t}{c_r}$                   & [-] wing taper ratio \\\\\n  $\\Lambda_{LE}$                               & [rad] leading edge sweep angle \\\\\n  $\\Lambda_{t/c}$                              & [rad] sweep angle at maximum thickness \\\\\n  $\\omega$                                     & [1/s] specific turbulence dissipation rate \\\\\n  $\\cfrac{\\partial \\epsilon}{\\partial \\alpha}$ & [-] horizontal stabilizer downwash angle derivative with respect to the aircraft angle of attack \\\\\n\\end{longtable}\n", "meta": {"hexsha": "bbcf26a2ecc88ab729407a56c7e028a9187e5faf", "size": 2761, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/data_0.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_0.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_0.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": 67.3414634146, "max_line_length": 148, "alphanum_fraction": 0.3556682361, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6010684011188592}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{bm}\n\\usepackage[margin=1in]{geometry}\n\\usepackage{parskip}\n\\usepackage{algorithm}\n\\usepackage{algpseudocode}\n\n\\usepackage[backend=biber,style=numeric,sorting=ynt,bibencoding=utf8]{biblatex}\n\\addbibresource{sources.bib}\n\n\\renewcommand\\aa{\\bm{\\theta}}\n\\renewcommand\\t{\\vartheta}\n\\newcommand\\R{\\bm{R}}\n\\newcommand\\q{\\bm{q}}\n\\newcommand\\I{\\bm{I}}\n\\renewcommand\\u{\\bm{u}}\n\\renewcommand\\v{\\bm{v}}\n\\renewcommand\\skew[1]{[#1]_{\\times}}\n\\newcommand\\Real{\\mathbb{R}}\n\\newcommand\\norm[1]{\\Vert#1\\Vert}\n\\newcommand\\vecop[1]{\\text{vec} \\left( #1\\right)}\n\n\\DeclareMathOperator{\\arctantwo}{arctan2}\n\n\\begin{document}\n\n\\title{Overview of 3D orientation transformations with Jacobians}\n\\author{Christian V. Berg}\n\\maketitle\n\\date\n\nMany of the following transformations are functions of matricies. Since we are\nalso interested in their first order derivative, we need an efficient way\nof ordering their partial derivates. In the following derivations, we use the\n\\textit{Magnus-Neudecker} layout convention as presented in\n\\cite{magnus_matrix_1985}. A practical introduction can be found in\n\\cite{fackler_notes_2005}. We will be using the product rule in particular: Given \nfunctions $f(X):\\Real^{n \\times m} \\to \\Real^{p \\times q}$ and\n$g(X):\\Real^{n \\times m} \\to \\Real^{q \\times k}$ then\n\\begin{align}\n  \\frac{\\partial \\vecop{f(X) g(X)}}{\\partial \\vecop{X}} =\n    \\left(g(X)^T \\otimes \\bm{I}_k \\right) \\frac{\\partial \\vecop{f(X)}}{\\partial \\vecop{X}}\n    + \\left(\\bm{I}_p \\otimes f(X) \\right) \\frac{\\partial \\vecop{g(X)}}{\\partial \\vecop{X}}\n\\end{align}\n\nwhere $\\otimes$ is the Kronecker product. You will also find some references to the Lie group $SO(3)$ and its exponential map.\nThough Lie theory is not needed to understand what follows, an excellent introduction\nto the topic and its applications in robotics can be found in \\cite{sola_micro_2019}.\n\n\n\\tableofcontents\n\n\\section{Notations}\n\\subsection{Symbols}\n\\begin{tabular}{l p{15cm}}\n  $\\t \\in \\Real$ & Angle \\\\\n  $\\aa \\in \\Real^3$ & Axis-angle such that $\\aa = \\t \\, \\u$, $\\t \\in \\Real$ and a unit vector $\\u \\in S^2$ \\\\\n  $\\q \\in S^3$ & Unit quaternion such that $\\q = \\begin{bmatrix} w \\\\ \\v \\end{bmatrix}$ \\\\\n  $\\R \\in SO(3)$ & Rotation matrix \\\\\n  $\\I \\in \\Real^{3\\times3}$ & Identity matrix \\\\\n  $\\bm{0} \\in \\Real^{3}$ & Zero vector \\\\\n  $\\bm{1} \\in \\Real^{3}$ & Vector of ones \\\\\n   $e_i \\in \\Real^3$ & $i^{th}$ standard orthonormal base vector of $\\Real^3$, i.e.\n     $e_1=\\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\end{bmatrix},\n     e_2 =\\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\end{bmatrix},\n       e_3 =\\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}$ \\\\ [10pt] \\\\\n   $E_i = \\skew{e_i}\\in \\Real^{3 \\times 3}$ & $i^{th}$ generator of $SO(3)$ \\\\ [10pt] \\\\\n\\end{tabular}\n\n\\subsection{Operators}\n\\begin{tabular}{l p{15cm}}\n  $ (.)^T : \\Real^{m \\times n} \\to \\Real^{n \\times m}$ & Matrix transpose \\\\\n  $tr(.) : \\Real^{n \\times n} \\to \\Real$ & Matrix trace \\\\\n  $\\skew{.} : \\Real^3 \\to  \\Real^{3\\times 3}$ & Skew symmetric matrix operator such that\n  $\\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}_\\times =\n  \\begin{bmatrix}\n    0& - z & y \\\\ \n    z & 0 & -x \\\\\n    -y & x & 0\n  \\end{bmatrix}$ \\\\ [10pt] \\\\\n  $(.)^\\vee : \\Real^{3 \\times 3} \\to \\Real^{3}$ & Vee operator such that\n  $\\begin{bmatrix}\n    a_1& - z & y \\\\ \n    z & a_2 & -x \\\\\n    -y & x & a_3\n  \\end{bmatrix}^\\vee = \\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}$ \\newline Notice that $\\left(\\skew{\\bm{d}}\\right)^\\vee = \\bm{d}$ \\\\\n    $\\vecop{.} : \\Real^{m \\times n} \\to \\Real^{m\\,n}$ & Vectorization operator of a matrix such that\n   $\\vecop{\\begin{bmatrix}\n    a_1 & a_3 \\\\ \n    a_2 & a_4\n    \\end{bmatrix}} = \\begin{bmatrix} a_1 \\\\ a_2 \\\\ a_3 \\\\ a_4 \\end{bmatrix}$ \\\\ [10pt] \\\\\n\\end{tabular}\n\n\\section{Rotation matrix and axis-angle}\n\\subsection{Rotation matrix from axis-angle}\nThis transformation is provided by Rodrigues' rotation formula, and gives a closed form expression of the exponential map of $SO(3)$:\n\\begin{align}\n  \\R = \\exp(\\skew{\\aa}) = \\I + \\frac{\\sin \\t}{\\t} \\skew{\\aa} + \\frac{1 - \\cos \\t}{\\t^2} \\skew{\\aa}^2 \n\\end{align}\n\nFirst order Taylor approximation at $\\aa = \\bm{0}$\n\\begin{align}\n  \\R = \\exp(\\skew{\\aa}) = \\I + \\skew{\\aa} + O(\\skew{\\aa}^2) \\approx \\I + \\skew{\\aa}\n\\end{align}\n\n\\subsection{Rotation matrix from axis-angle Jacobian}\nSince the expression is fairly long, we will define 2 intermediate functions:\n\\begin{align}\n  k_1(\\t) = \\frac{\\sin{\\t}}{\\t} \\;\\;&,\\;\\;\n  \\frac{\\partial k_1(\\t)}{\\partial \\t} = \\frac{\\t\\cos{\\t} - \\sin{\\t}}{\\t^2} \\\\\n  k_2(\\t) = \\frac{1-\\cos{\\t}}{\\t^2} \\;\\;&,\\;\\;\n  \\frac{\\partial k_2(\\t)}{\\partial \\t} = \\frac{\\t\\sin{\\t} - 2\\left(1-\\cos{\\t} \\right)}{\\t^3}\n\\end{align}\n\nFor both functions, we have\n\\begin{align}\n  \\frac{\\partial k_i(\\t)}{\\partial \\aa} &= \n    \\frac{\\partial k_i(\\t)}{\\partial \\t} \\frac{\\t}{\\partial \\aa} =\n    \\frac{\\partial k_i(\\t)}{\\partial \\t} \\frac{\\sqrt{\\aa^T\\aa}}{\\partial \\aa} =\n    \\frac{\\partial k_i(\\t)}{\\partial \\t} \\frac{\\aa^T}{\\t}\n\\end{align}\n\nUsing the Kronecker product $\\otimes$, it then follows\n\\begin{align}\n  \\frac{\\partial \\vecop{k_1(\\t) \\skew{\\aa}}}{\\partial \\aa}  \n  &= \\left( \\I \\otimes k_1(\\t)\\I \\right) \\frac{\\partial \\vecop{\\skew{\\aa}}}{\\partial \\aa}\n    + \\left(\\skew{\\aa}^T \\otimes \\I \\right) \\frac{\\partial \\vecop{k_1(\\t)\\;\\I}}{\\partial \\aa} \\\\\n  &= k_1(\\t) \\frac{\\partial \\vecop{\\skew{\\aa}}}{\\partial \\aa}\n    - \\left(\\skew{\\aa} \\otimes \\I \\right) \\vecop{\\I} \\frac{\\partial k_1(\\t)}{\\partial \\t} \\frac{\\aa^T}{\\t}\n\\end{align}\n\nwhere we used $\\skew{.}^T = - \\skew{.}$. Next, we also have\n\\begin{align}\n  \\frac{\\partial \\vecop{k_2(\\t) \\skew{\\aa}^2}}{\\partial \\aa}  \n  &= \\left( \\I \\otimes k_2(\\t)\\I \\right) \\frac{\\partial \\vecop{\\skew{\\aa}^2}}{\\partial \\aa}\n    + \\left({\\skew{\\aa}^2}^T \\otimes \\I \\right) \\frac{\\partial \\vecop{k_2(\\t)\\;\\I}}{\\partial \\aa} \\\\\n  &= k_2(\\t) \\frac{\\partial \\vecop{\\skew{\\aa}^2}}{\\partial \\aa}\n    + \\left({\\skew{\\aa}^2} \\otimes \\I \\right) \\vecop{\\I} \\frac{\\partial k_2(\\t)}{\\partial \\t} \\frac{\\aa^T}{\\t}\n\\end{align}\n\nwhere we used ${\\skew{.}^2}^T = \\skew{.}^2$. Putting it all together, we get:\n\n\\begin{align}\n  \\frac{\\partial \\vecop{\\R}}{\\partial \\aa} = \n    \\frac{\\partial \\vecop{k_1(\\t) \\skew{\\aa}}}{\\partial \\aa}  \n    + \\frac{\\partial \\vecop{k_2(\\t) \\skew{\\aa}^2}}{\\partial \\aa}  \n\\end{align}\n\nWhen $\\t = 0$, we reuse the exponential map of $SO(3)$ to deduce that \n\\begin{align}\n  \\left. \\frac{\\partial \\vecop{\\R}}{\\partial \\aa} \\right \\vert_{\\aa = \\bm{0}} =\n  \\left. \\frac{\\partial \\vecop{\\exp(\\skew{\\aa})}}{\\partial \\aa_i} \\right \\vert_{\\aa = \\bm{0}} \\approx\n  \\left. \\frac{\\partial \\vecop{\\I + \\skew{\\aa}}}{\\partial \\aa_i} \\right \\vert_{\\aa = \\bm{0}} =\n  \\frac{\\partial \\vecop{\\skew{\\aa}}}{\\partial \\aa}\n\\end{align}\n\n\\subsection{Axis-angle from rotation matrix}\nWe begin by retrieving the angle $\\t$:\n\\begin{align}\n  tr(\\R) \n    &= tr(\\I) + \\frac{\\sin \\t }{\\t} tr(\\skew{\\aa}) + \\frac{1 - \\cos \\t}{\\t^2} tr(\\skew{\\aa}^2) \\\\\n    &= 3 - 2 (1 - \\cos \\t) \\\\\n  \\t &=  \\arccos \\frac{tr(\\R) - 1}{2}\n\\end{align}\n\nwhere we used $tr(\\skew{\\aa}^2) =  - 2 \\aa^T \\aa = -2\\t^2$ and $tr(\\skew{.}) = 0$.\n\nNext, and assuming $\\t \\neq 0 \\iff tr(\\R) \\neq 3$ and $\\t \\neq \\pi \\iff tr(\\R) \\neq -1$ then\n\\begin{align}\n  \\R - \\R^T \n    &= \\frac{\\sin{\\t}}{\\t} \\left(\\skew{\\aa} - \\skew{\\aa}^T\\right)\n    + \\frac{1 - \\cos \\t}{\\t^2} \\left( \\skew{\\aa}^2 - \\skew{\\aa}^{2^T} \\right) \\\\\n    &= \\frac{2\\, \\sin \\t}{\\t} \\skew{\\aa} \\\\\n  \\aa &= \\frac{\\t \\, \\left(\\R - \\R^T \\right)^\\vee }{2\\, \\sin \\t}\n\\end{align}\n\nWhen $\\t$ is close to $0 \\iff tr(\\R)$ close to $3$, we can reuse the first\norder Taylor approximation from before:\n\n\\begin{align}\n  \\aa \\approx \\left( \\R - \\I \\right)^\\vee\n\\end{align}\n\nWhen $\\t = \\pi \\iff tr(\\R) = -1$\n\\begin{align}\n  \\R = \\I + \\frac{2}{\\t^2} \\skew{\\aa}^2 \n  &= \\I + 2\\skew{\\u}^2 \\\\\n  &= \\I + 2\\, (\\u \\u^T - \\I) \\\\\n  \\u \\u^T = \\frac{\\R + \\I }{2}\n\\end{align}\n\nwhere we used $\\skew{\\u}^2 =  \\u \\u^T - \\u^T \\u \\I$ and $\\u^T \\u = 1$ by definition.\nSince $\\u \\u^T$ has the form:\n\\begin{align}\n  \\u \\u^T = \n  \\begin{bmatrix}\n    \\u_x^2 & \\u_x \\u_y & \\u_x \\u_z \\\\\n    \\u_y \\u_x & \\u_y^2 & \\u_y \\u_z \\\\\n    \\u_z \\u_x & \\u_z \\u_y & \\u_z^2\n  \\end{bmatrix}\n\\end{align}\n\nwe know that the largest element of the diagonal corresponds to the most\nsignificant axis of rotation. Since $\\t=\\pi$ then the largest diagonal element\nis always different from zero. Therefore, we take the square root of the largest\ndiagonal element, then use it to divide its corresponding column vector in\norder to retrieve $\\u$. Note that we cannot deduce the sign of $\\u$, only the\nrelative \"sign-ness\" of each element.\n\n\\begin{align}\n  \\u = \\pm \n    \\frac{col_i \\left[ \\frac{\\R + \\I}{2} \\right] }\n         {\\sqrt{diag_i \\left[ \\frac{\\R + \\I }{2} \\right] }}\n  \\;,\\; i = argmax \\;\\; diag \\left( \\frac{\\R + \\I }{2} \\right)\n\\end{align}\n\nFinally\n\\begin{align}\n  \\aa = \\pm \\pi \\u\n\\end{align}\n\n\\subsection{Axis-angle from rotation matrix Jacobian}\nOnce again we will define an intermediate function and variable:\n\\begin{align}\n  k_3(\\t) = \\frac{\\t}{2\\sin{\\t}} \\;\\;&,\\;\\;\n  \\frac{\\partial k_3(\\t)}{\\partial \\t} = \n    \\left(1 - \\frac{\\t}{\\tan{\\t}} \\right) \\frac{1}{2\\sin{\\t}} \\\\\n  x = \\frac{tr(\\R) - 1}{2} \\;\\;&,\\;\\; \\t = \\arccos(x)\n\\end{align}\n\nConsequently, we have\n\\begin{align}\n  \\frac{\\partial k_3(\\t)}{\\partial tr(\\R)} \n  &=\\frac{\\partial k_3(\\t)}{\\partial \\t} \n    \\frac{\\partial \\t}{\\partial x} \n    \\frac{\\partial x}{\\partial tr(\\R)} \\\\\n  &=-\\frac{\\partial k_3(\\t)}{\\partial \\t} \n    \\frac{1}{2\\sqrt{1-\\t^2}}\n\\end{align}\n\nAssuming $\\t \\neq 0 \\iff tr(\\R) \\neq 3$ and $\\t \\neq \\pi \\iff tr(\\R) \\neq -1$, then\n\\begin{align}\n  \\frac{\\partial \\vecop{\\aa}}{\\partial \\vecop{\\R}} = \n    \\big({(\\R - \\R^T)^\\vee}^T \\otimes \\I \\big)\n    \\vecop{\\I}\n    \\frac{\\partial k_3(\\t)}{\\partial tr(\\R)} \n    \\frac{\\partial tr(\\R)}{\\partial \\vecop{\\R}} + \n    k_3(\\t) \\frac{\\partial \\left( \\R - \\R^T \\right)^\\vee}{\\partial \\vecop{\\R}}\n\\end{align}\n\nWhen $\\t = 0 \\iff tr(\\R) = 3$, then \n\\begin{align}\n  \\left. \\frac{\\partial \\aa}{\\partial \\vecop{\\R}} \\right \\vert_{\\aa = \\bm{0}} \\approx\n    \\frac{\\partial \\left(\\R - \\I \\right)^\\vee}{\\partial \\vecop{\\R}}\n\\end{align}\n\n\\section{Rotation matrix and quaternion}\n\\subsection{Rotation matrix from quaternion}\nAssuming unit quaternions, we have\n\\begin{align}\n  \\R = \\I + 2 \\; w \\; \\skew{\\v} + 2\\; \\skew{\\v}^2\n\\end{align}\n\n\\subsection{Rotation matrix from quaternion Jacobian}\n\\begin{align}\n  \\frac{\\partial \\vecop{\\R}}{\\partial w} &= 2\\, \\vecop{\\skew{\\v}} \\\\\n  \\frac{\\partial \\vecop{\\R}}{\\partial \\v} &= \n  2w \\frac{\\partial\\vecop{\\skew{\\v}}}{\\partial \\v} +\n  2 \\frac{\\partial\\vecop{\\skew{\\v}^2}}{\\partial \\v} \\\\\n  \\frac{\\partial \\vecop{\\R}}{\\partial \\q} &= \n    \\begin{bmatrix}\n      \\frac{\\partial \\vecop{\\R}}{\\partial w} & \n      \\frac{\\partial \\vecop{\\R}}{\\partial \\v}\n    \\end{bmatrix}\n\\end{align}\n\n\\subsection{Quaternion from rotation matrix}\nWe begin by retrieving the scale component of the quaternion:\n\\begin{align}\n  tr(\\R) \n    &= tr(\\I) + 2\\; w \\; tr(\\skew{\\v}) + 2 \\; tr(\\skew{\\v}^2) \\\\\n    &= 3 - 4 \\v^t \\v = 4\\;w^2 - 1 \\\\\n  w &= \\pm \\frac{ \\sqrt{ tr(\\R) + 1} }{2}\n\\end{align}\n\nAssuming $w \\neq 0 \\iff tr(\\R) \\neq -1$\n\\begin{align}\n  \\R - \\R^T\n    &= 2\\; w \\; \\left( \\skew{\\v} - \\skew{\\v}^T \\right) + 2 \\; \\left(\\skew{\\v}^2 - {\\skew{\\v}^2}^T \\right) \\\\\n    &= 4\\; w \\; \\skew{\\v} \\\\\n  \\v &= \\frac{\\left( \\R -\\R^T \\right)^\\vee}{4\\;w}\n\\end{align}\n\nWhen $w = 0$, then\n\\begin{align}\n  \\R &= \\I + 2 \\skew{\\v}^2  = \\I + 2 \\left ( \\v \\v^T - \\I \\right) \\\\\n  \\v \\v^T &= \\frac{\\R + \\I}{2}\n\\end{align}\n\nand we can reuse the same method as for axis-angle when $\\t = \\pi$.\n\n\\subsection{Quaternion from rotation matrix Jacobian}\nAs before, we define\n\\begin{align}\n  k_4(w) = \\frac{1}{4w} \\;\\;,\\;\\; \\frac{\\partial k_4(w)}{\\partial w} = -\\frac{1}{4w^2}\n\\end{align}\n\nAssuming $w \\neq 0 \\iff tr(\\R) \\neq -1$\n\\begin{align}\n  \\frac{\\partial w}{\\partial \\vecop{\\R}}\n    &=\\frac{\\partial w}{\\partial tr(\\R)} \\frac{\\partial tr(\\R)}{\\partial \\vecop{\\R}}\n    = \\frac{1}{4\\sqrt{tr(\\R) + 1}} \\frac{\\partial tr(\\R)}{\\partial \\R} \\\\\n  \\frac{\\partial \\v}{\\partial \\vecop{\\R}}\n    &= \\big({\\left(\\R - \\R^T\\right)^\\vee}^T \\otimes \\I \\big)\\frac{\\partial k_4(w)}{\\partial w}\\frac{\\partial w}{\\partial \\vecop{\\R}}\n    + k_4(w) \\frac{\\partial \\left(\\R - \\R^T\\right)^\\vee }{\\partial \\vecop{\\R}}\n\\end{align}\n\n\\section{Axis-angle and quaternion}\n\\subsection{Quaternion from axis-angle}\n\\begin{align}\n  \\q = \n    \\begin{bmatrix} \n       \\cos{ \\frac{\\t}{2} } \\\\[5pt]\n       \\frac{\\sin{ \\frac{\\t}{2} }}{\\t} \\aa\n    \\end{bmatrix}\n\\end{align}\n\nWhen $\\t$ is close to $0$, then the second order Taylor approximation is\n\\begin{align}\n  \\q \\approx\n    \\begin{bmatrix} \n      1 - \\frac{\\t^2}{8} \\\\[5pt]\n      \\left( \\frac{1}{2} - \\frac{\\t^2}{48} \\right) \\aa\n    \\end{bmatrix}\n\\end{align}\n\n\\subsection{Quaternion from axis-angle Jacobian}\n\\begin{align}\n  \\frac{\\partial w}{\\partial \\aa} \n  &=  \\frac{\\partial w}{\\partial \\t} \\frac{\\partial \\t}{\\partial \\aa}  \\\\\n  &=-\\frac{\\sin{\\frac{\\t}{2}}}{2} \\frac{\\aa^T}{\\t}  \\\\\n     \\frac{\\partial \\v}{\\partial \\aa} &= \n  \\aa \\frac{\\partial \\frac{\\sin{ \\frac{\\t}{2} }}{\\t}}{\\partial \\aa} + \n  \\frac{\\sin{ \\frac{\\t}{2} }}{\\t} \\frac{\\partial \\aa}{\\partial \\aa}\\\\\n  &= \\aa \\frac{\\partial \\frac{\\sin{ \\frac{\\t}{2} }}{\\t}}{\\partial \\t} \\frac{\\partial \\t}{\\partial \\aa}  + \n  \\frac{\\sin{ \\frac{\\t}{2} }}{\\t} \\I \\\\\n  &= \n     \\aa \\frac{\\t \\, \\cos{\\frac{\\t}{2}} - 2\\,\\sin{\\frac{\\t}{2}}}{2\\,\\t^2} \\frac{\\aa^T}{\\t}\n    + \\frac{\\sin{\\frac{\\t}{2}}}{\\t} \\I\n\\end{align}\n\nWhen $\\t$ is close to $0$, then\n\\begin{align}\n  \\left. \\frac{\\partial w}{\\partial \\aa} \\right \\vert_{\\aa = 0} &\\approx - \\frac{1}{4} \\aa^T \\\\\n  \\left. \\frac{\\partial w}{\\partial \\aa} \\right \\vert_{\\aa = 0} &\\approx - \\frac{1}{24} \\aa \\aa^T + \\left(\\frac{1}{2} - \\frac{\\t^2}{48} \\right) \\I\n\\end{align}\n\nand finally\n\n\\begin{align}\n  \\frac{\\partial \\q}{\\partial \\aa} = \n    \\begin{bmatrix}\n      \\frac{\\partial w}{\\partial \\aa} \\\\[5pt]\n      \\frac{\\partial \\v}{\\partial \\aa}\n    \\end{bmatrix}\n\\end{align}\n\n\\subsection{Axis-angle from quaternion}\nUsing $y=\\sqrt{\\v^T\\v}$\n\\begin{align}\n  \\aa = 2 \\frac{\\arctantwo \\left(y, w \\right)}{y} \\v \n\\end{align}\n\nWhen $w$ approaches $1$ from the left $\\iff \\t$ close to $0$, we can reuse the second order Taylor approximation from before to deduce\n\\begin{align}\n  \\aa \\approx \\frac{6\\v}{w+2}\n\\end{align}\n\n\\subsection{Axis-angle from quaternion Jacobian}\nWe define an intermediate function\n\\begin{align}\n  k_5(y,x) &= 2 \\frac{\\arctantwo \\left(y, w \\right)}{y} \\\\\n  \\frac{\\partial k_5(y,x)}{\\partial x} &= \\frac{-2}{y^2 + w^2} = -2 \\\\\n  \\frac{\\partial k_5(y,x)}{\\partial y} &= 2 \\frac{ \\frac{w\\,y}{y^2 + w^2} - \\arctantwo \\left(y, w \\right)}{y^2} = 2 \\frac{ w\\,y - \\arctantwo \\left(y, w \\right)}{y^2}\n\\end{align}\nwhere we used $y^2 + w^2 = \\q^T \\q = 1$ since we are assuming unit quaternions. It then follows:\n\\begin{align}\n  \\frac{\\partial \\aa}{\\partial w} &= \\frac{\\partial k_5(y,w)}{\\partial w} \\v \\\\\n  \\frac{\\partial \\aa}{\\partial \\v} \n  &= \\v \\frac{\\partial k_5(y,w)}{\\partial y} \\frac{\\partial y}{\\partial \\v} + k_5(y,w) \\I\n  =  \\v \\frac{\\partial k_5(y,w)}{\\partial y} \\frac{\\v^T}{y} + k_5(y,w) \\I\n\\end{align}\n\nWhen $w$ approach $1$ from the left $\\iff \\t$ close to $0$, then\n\\begin{align}\n  \\left. \\frac{\\partial \\aa}{\\partial w} \\right \\vert_{w = 1^-} &\\approx - \\frac{6}{\\left( w + 2 \\right)^2} \\v \\\\\n  \\left. \\frac{\\partial \\aa}{\\partial \\v} \\right \\vert_{w = 1^-} &\\approx \\frac{6}{w + 2} \\I\n\\end{align}\n\nand finally\n\n\\begin{align}\n  \\frac{\\partial \\aa}{\\partial \\q} = \n    \\begin{bmatrix}\n      \\frac{\\partial \\aa}{\\partial w} &\n      \\frac{\\partial \\aa}{\\partial \\v}\n    \\end{bmatrix}\n\\end{align}\n\n\\section{Euler angles and rotation matrix}\n\nThis section is largely based on \\cite{eberly_euler_nodate}, which details how\none can retrieve the Euler angles of a given sequence of rotation from a rotation matrix.\n\nThe following subsection presents the pseudocode to retrieve the wanted Euler angles, but \nunlike \\cite{eberly_euler_nodate}, the pseudocode is generalized for the intrinsic order of rotation.\n\nWe define\n\n\\begin{tabular}{l p{15cm}}\n  $\\R_i(\\t_k)$ & The rotation matrix about the axis $e_i$ by an angle $\\t_k$ \\\\\n  $s_k$ & Sine of the angle $\\t_k$, i.e. $s_k = \\sin \\t_k$\\\\\n  $c_k$ & Cosine of the angle $\\t_k$, i.e. $c_k = \\cos \\t_k$\\\\\n  $M$ & The \"sign\" matrix used to correct the sign of the sine and cosine element of the rotation matrix \\\\\n\\end{tabular}\n\nUsing this, a rotation matrix can be written as $\\R = \\R_a(\\t_1) \\; \\R_b(\\t_2) \\; \\R_c(\\t_3)$.\nFor example, the intrinsic sequences of rotation \\textit{x-y-z} by angles $(\\t_x, \\t_y, \\t_z)$ is written\n$\\R = \\R_1(\\t_x) \\; \\R_2(\\t_y) \\; \\R_3(\\t_z)$.\n\nA particular matrix element is denoted by a lower case letter and the indicies in subscript, i.e.\n\\begin{align}\n  \\R = \\begin{bmatrix} \n    r_{1,1} & r_{1,2} & r_{1,3} \\\\\n    r_{2,1} & r_{2,2} & r_{2,3} \\\\\n    r_{3,1} & r_{3,2} & r_{3,3}\n  \\end{bmatrix} \\text{       }\n\\end{align}\n\nThe both algorithms rely on a sign matrix given by\n\\begin{align}\n  M = \\begin{bmatrix} \n    m_{1,1} & m_{1,2} & m_{1,3} \\\\\n    m_{2,1} & m_{2,2} & m_{2,3} \\\\\n    m_{3,1} & m_{3,2} & m_{3,3}\n  \\end{bmatrix} \n  = \\begin{bmatrix} \n    1 & -1 & 1 \\\\\n    1 & 1 & -1 \\\\\n    -1 & 1 & 1\n  \\end{bmatrix} = \n  \\I + \\skew{\\bm{1}}\n\\end{align}\n\n\\subsection{Tait-Bryan angles from rotation matrix}\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Function{ToTaitBryan}{$\\R,a,b,c$}\\Comment{Corresponds to the intrinsic rotation sequence $e_a-e_b-e_c$}\n  \\State $M = \\I + \\skew{\\bm{1}}$\\Comment{Sign matrix}\n  \\State $s_2 = r_{a,c}$\n  \\If{$s_2 < +1$}\n    \\If{$s_2 > -1$}\n      \\State $\\t_2 = \\arcsin(m_{a,c} \\; s2)$\n      \\State $\\t_1 = \\arctantwo(m_{b,c} \\; r_{b,c}, m_{c,c} \\; r_{c,c})$\n      \\State $\\t_3 = \\arctantwo(m_{a,b} \\; r_{a,b}, m_{a,a} \\; r_{a,a})$\n    \\Else\\Comment{Gimbal lock: $s_2 = -1$}\n      \\State $\\t_2 = - m_{a,c} \\; \\frac{\\pi}{2}$\n      \\State $\\t_1 = \\arctantwo(m_{b,a} \\; r_{b,a}, m_{b,b} \\; r_{b,b})$\n      \\State $\\t_3 = 0$\n    \\EndIf\n  \\Else\\Comment{Gimbal lock: $s_2 = 1$}\n    \\State $\\t_2 = m_{a,c} \\; \\frac{\\pi}{2}$\n    \\State $\\t_1 = \\arctantwo(m_{b,a} \\; r_{b,a}, m_{b,b} \\; r_{b,b})$\n    \\State $\\t_3 = 0$\n  \\EndIf\n  \\State \\textbf{return} $\\t_1, \\t_2, \\t_3$\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{Proper Euler angles from rotation matrix}\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n  \\Function{ToProperEuler}{$\\R,a,b$}\\Comment{Corresponds to the intrinsic rotation sequence $e_a-e_b-e_a'$}\n  \\State $M = \\I + \\skew{\\bm{1}}$\\Comment{Sign matrix}\n  \\State $c = 6 - a -b$\\Comment{$c$ is the \"unused\" axis}\n  \\State $c_2 = r_{a,a}$\n  \\If{$c_2 < +1$}\n    \\If{$c_2 > -1$}\n      \\State $\\t_2 = \\arccos(m_{a,a} \\; c2)$\n      \\State $\\t_1 = \\arctantwo(m_{b,a} \\; r_{b,a}, m_{c,a} \\; r_{c,a})$\n      \\State $\\t_3 = \\arctantwo(m_{a,b} \\; r_{a,b}, m_{a,c} \\; r_{a,c})$\n    \\Else\\Comment{Gimbal lock: $c_2 = -1$}\n      \\State $\\t_2 = \\pi$\n      \\State $\\t_1 = - \\arctantwo(m_{b,c} \\; r_{b,c}, m_{b,b} \\; r_{b,b})$\n      \\State $\\t_3 = 0$\n    \\EndIf\n  \\Else\\Comment{Gimbal lock: $c_2 = 1$}\n    \\State $\\t_2 = 0$\n    \\State $\\t_1 = \\arctantwo(m_{b,c} \\; r_{b,c}, m_{b,b} \\; r_{b,b})$\n    \\State $\\t_3 = 0$\n  \\EndIf\n  \\State \\textbf{return} $\\t_1, \\t_2, \\t_3$\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\n\\newpage\n\n\\section{Common matrix derivatives}\n\nUsing $e'_i$ as $i^{th}$ standard orthonormal base vector of $\\Real^9$, then\n\n\\begin{align}\n  \\forall X \\in \\Real^{3 \\times 3} \\;\\; \\text{ then } \\;\\; \\frac{\\partial \\vecop{X^T}}{\\partial \\vecop{X}}\n  = \\begin{bmatrix} e'_1 &   e'_4 &   e'_7 &   e'_2 &   e'_5 &   e'_8 &   e'_3 &   e'_6 &   e'_9  \\end{bmatrix} = J_T\n\\end{align}\n\n\\begin{align}\n  \\forall X \\in \\Real^{n \\times n} \\;\\; \\text{ then } \\;\\; \\frac{\\partial \\vecop{tr(X)}}{\\partial \\vecop{X}}\n  = \\vecop{\\I_n}\n\\end{align}\n\n\\begin{align}\n  \\forall \\bm{v} \\in \\Real^{3} \\;\\; \\text{ then } \\;\\; \\frac{\\partial \\skew{\\bm{v}}}{\\partial \\bm{v}}\n  = \\begin{bmatrix} \\vecop{E_1} &  \\vecop{E_2} & \\vecop{E_3} \\end{bmatrix} = J_\\times\n\\end{align}\n\n\\begin{align}\n  \\forall X \\in \\Real^{3 \\times 3} \\;\\; \\text{ then } \\;\\; \\frac{\\partial X^\\vee}{\\partial \\vecop{X}} =\n  \\begin{bmatrix}\n    0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 & 0 \\\\\n    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n    0 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 0\n  \\end{bmatrix} = J_\\vee\n\\end{align}\n\n\\begin{align}\n  \\forall X \\in \\Real^{3 \\times 3} \\;\\; \\text{ then } \\;\\; \\frac{\\partial (X - X^T)^\\vee}{\\partial \\vecop{X}}\n  = \\frac{\\partial (X - X^T)^\\vee}{\\partial \\vecop{X - X^T}}\n  \\frac{\\partial \\vecop{X - X^T}}{\\partial \\vecop{X}} = J_\\vee \\; (\\I_9 - J_T)\n\\end{align}\n\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "162898f22580802c45a6fb869829ad0a1e1f5ce3", "size": 20583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/conversion_formulas.tex", "max_stars_repo_name": "Eskilade/orient", "max_stars_repo_head_hexsha": "d73e9459155e991539c20bfd92c04cb487b65538", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-05-11T07:27:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-10T09:23:29.000Z", "max_issues_repo_path": "documentation/conversion_formulas.tex", "max_issues_repo_name": "Eskilade/orient", "max_issues_repo_head_hexsha": "d73e9459155e991539c20bfd92c04cb487b65538", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-20T02:22:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-21T01:42:47.000Z", "max_forks_repo_path": "documentation/conversion_formulas.tex", "max_forks_repo_name": "Eskilade/orient", "max_forks_repo_head_hexsha": "d73e9459155e991539c20bfd92c04cb487b65538", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-14T11:11:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:26:22.000Z", "avg_line_length": 37.2206148282, "max_line_length": 165, "alphanum_fraction": 0.5860175873, "num_tokens": 8354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6010492568778387}}
{"text": "%!TEX root = index.tex\n\\section{Symmetries \\& Polynomials}\n\n\\epigraph{Out of nothing I have created a strange new universe.}{Janos Bolyai}\n\n\n\nWe need one last definition, that of a normal subgroup, to understand the Galois' ideas using the language of group theory. \n\n\\subsection{Cycle decomposition and Normality}\nEvery permutation naturally breaks up as cycles. For example $ (3 \\: 4 \\: 1 \\: 5 \\: 2) \\in S_5$ breaks up as,\n\\begin{align*}\n  (3 \\: 4 \\: 1 \\: 5 \\: 2) \\rightsquigarrow 1 \\mapsto 3 \\mapsto 1 \\mbox{ and } 2 \\mapsto 4 \\mapsto 5 \\mapsto 2 \n\\end{align*}\nWe say that $ (3 \\: 4 \\: 1 \\: 5 \\: 2)$ has a \\textbf{cycle decomposition} $[1 \\: 3] [2 \\: 4 \\: 5]$ and \\textbf{cycle type} $2 + 3$. The order of the cycles and of the elements within the cycles is not relevant. We can rewrite the above permutation as having a cycle decomposition $[4 \\: 5 \\: 2][1 \\: 3] $ and cycle type $3 + 2$. \n\n{The cycle decomposition is the more common way of writing permutations, but it is harder to multiply two permutations when they're written in the cycle notation and needs some getting used to.}\n\n\\begin{questions}\n  \\item Determine cycle decompositions and cycle types of all the elements of $ S_3$.\n  \\item \n  \\label{ques:s4}\n  What are the possible cycle types for elements in $ S_4$? How many elements are there in each cycle type (this is a long problem, patience is the key here).\n\\end{questions}\n\n\\noindent A subgroup $ G \\subseteq S_n$ is called \\textbf{normal} if it satisfies the following property:\n \nif it contains one element of a certain cycle type then it contains \\emph{all} the elements of that cycle type.\n\n\n\\begin{questions}[resume]\n  \\item Determine which of the subgroups of $ S_3$ are normal.\\footnote{Just so that we're all on the same page $ S_3$ has 6 subgroups: $ \\{ e \\}$, $ \\{ e, (1 \\: 3 \\: 2) \\}$, $ \\{ e,  (3 \\: 2 \\: 1) \\}$, $ \\{ e, (2 \\: 1 \\: 3) \\}$, $ \\{ e,  (2 \\: 3 \\: 1),  (3 \\: 1 \\: 2) \\}$, and $ S_3$ itself.}\n  \n  \\item \n  \\begin{enumerate}\n    \\item Find the cycle type of $ e \\in S_n$.\n    \\item What other elements of $ S_n$ have the same cycle type as $ e$?\n    \\item Argue that the trivial group is a normal subgroup of $ S_n$. (Also note that $ S_n$ itself is a normal subgroup.)\n  \\end{enumerate}\n\\end{questions}\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Normal subgroups of $ S_n$}\nSuppose a permutation $ \\sigma \\in S_n$ has a cycle type $ a_1 + a_2 + \\cdots + a_k$ then we say that $ \\sigma$ is an \\textbf{even permutation} if $ (a_1 - 1) + (a_2 - 1) + \\cdots + (a_k - 1)$ is even, \\textbf{odd} otherwise. This is also called the \\textbf{parity} of the permutation. \n\nFor example, $ \\sigma = (3 \\: 4 \\: 1 \\: 5 \\: 2)$ has cycle type $ 2 + 3$ and $ (2 - 1) + (3 - 1) = 1 + 2 = 3$ is odd, hence the parity of $(3 \\: 4 \\: 1 \\: 5 \\: 2)$ is an odd permutation.\n\n\\begin{questions}[resume]\n  \\item \n  \\begin{enumerate}\n    \\item Determine which permutations of $ S_3$ are even and which ones are odd.\n    \\item Determine which cycle types of $ S_4$ correspond to even permutations and which ones to odd permutations, hence count the number of even and odd permutations in $ S_4$.\n    \\item What is the parity of the identity $ e = (1 \\: 2 \\: \\cdots \\: n) \\in S_n$?\n  \\end{enumerate}\n\\end{questions}\nAs it turns out the subset containing all the even permutations forms a normal subgroup of $ S_n$, denoted $A_n$, called the \\textbf{alternating group} and has size $ n!/2$. (We'll assume this fact.)\n\n\\begin{questions}[resume]\n  \\item \n  \\begin{enumerate}[resume]\n      \\item What is the subgroup $ A_3$?\n      \\item What is the subgroup $ A_4$? Have you encountered this subgroup before?\n  \\end{enumerate}\n\\end{questions}\n\n$ A_n$ is the only true friend $ S_n$ has.\n\\begin{thm}\n  Every $ S_n$, for $ n>4$, has exactly 3 normal subgroups $ \\{e \\}$, $ A_n$ and $ S_n$\n\\end{thm}\nThere is no deep reason why this theorem is true, it is simply a matter a computing the normal subgroups carefully. This is a recurring phenomenon in group theory, seemingly elementary mathematical objects have very structured symmetric groups, and these then give rise to very beautiful and deep mathematics.\n\n\n\n\n\\newpage\n\\subsection{Normal subgroups of $ S_4$}\nBy direct computations we can find all the normal subgroups of $ S_4$. We'll need the following theorem about subgroups.\n\\begin{thm}\n  The size of a subgroup divides the size of the total group.\n\\end{thm}\n\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n    \\item Verify the above theorem for $ S_3$.\n    \\item Verify the above theorem for $ \\{ e \\}, A_4, S_4$, as subgroups of $ S_4$. \n    \\item Verify the above theorem of the dihedral groups $ D_{2n}$ which are subgroups of $ S_n$.\n  \\end{enumerate}\n\\end{questions}\n\nWe already know 3 subgroups of $ S_4$: $ \\{ e \\}, A_4, S_4$. Turns out there is exactly one more called the \\textbf{Klein 4-group}, denoted $ K_4$.\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n    \\item What are the possible sizes of subgroups of $ S_4$?\n    \\item Show that $ S_4$ has exactly 4 normal subgroups: $ \\{ e \\}, K_4, A_4, S_4$.\n    \n     (You'll need to use the number of elements in each cycle type of $ S_4$ that you've already computed in \\ref{ques:s4} Remember that if a normal subgroup contains one element of a certain cycle type then it must contain all the elements with that cycle type.)\n  \\end{enumerate}\n\\end{questions}\n\nThis is the fortunate accident that allows us to solve the quartic. This does not occur for any other $ S_n$.\n\n\n\n\n\n\n\\newpage\n\\subsection{The Cubic and the Quartic}\nWe'll now return to polynomials and understand our methods using the language of symmetric groups.\n\nThe symmetry groups $ S_n$ naturally acts on a set of $ n$ variables, but more importantly it also acts on the set of all polynomials in $ n$ variables. For example, the permutation $ (1 \\: 3 \\: 2)$ sends $ \\beta_1 \\beta_2^2 +  \\beta_3 $ to $ \\beta_1 \\beta_3^2 +  \\beta_2 $. Let us go back to the cubic and quartic and analyze them using this new language.\\\\\n\n\nRecall that we had the following intermediate variables for the cubic\n  \\begin{align*}\n    \\sqrt{\\Delta} = (\\beta_1 -\\beta_2)(\\beta_2 - \\beta_3)(\\beta_3 - \\beta_1) \\mbox{ and } -\\sqrt{\\Delta} = (\\beta_2 -\\beta_1)(\\beta_3 - \\beta_2)(\\beta_1 - \\beta_3)\n  \\end{align*}\n\n\\begin{questions}[resume]\n  \\item \\begin{enumerate}\n  \\label{ques:cubic}\n    \\item Identify the \\emph{subgroup} of $ S_3$ that fixes \\emph{both} $\\sqrt{\\Delta} $ and $-\\sqrt{\\Delta}$.\n    \\item What is the subgroup of $ S_3$ that fixes all the symmetric variables corresponding to the coefficients: $ \\beta_1 \\beta_2 \\beta_3$, $\\beta_1 \\beta_2 + \\beta_2 \\beta_3 + \\beta_3 \\beta_1$, and $\\beta_1 + \\beta_2 + \\beta_3$.\n    \\item What is the subgroup of $ S_3$ that fixes the individual variables $\\beta_1 , \\beta_2,  \\beta_3 $.\n  \\end{enumerate}\n  This problem generalizes to all $ n$.\n\\end{questions}\n\nSimilarly we had the following intermediate variables for the quartic\n  \\begin{align*}\n    \\lambda_1 = \\gamma_1 \\gamma_2 + \\gamma_3 \\gamma_4 \n    \\mbox{ and } \\lambda_2 = \\gamma_1 \\gamma_3 + \\gamma_2 \\gamma_4\n    \\mbox{ and } \\lambda_3 = \\gamma_1 \\gamma_4 + \\gamma_2 \\gamma_3 \n  \\end{align*}\n\n\\begin{questions}[resume]\n  \\item \n  \\label{ques:quartic}\nIdentify the \\emph{subgroup} of $ S_4$ that fixes \\emph{all} the elements $ \\lambda_1, \\lambda_2, \\lambda_3$. \n\\end{questions}\n\nNotice that all the groups you've computed above are normal subgroups. \n\n\\newpage \n\\noindent \\textbf{Galois correspondence: } Galois' theorem states that there is a one-to-one correspondence between (sequence of) \\emph{intermediate variables}\\footnote{We need the concept of a \\emph{field} to make this more precise.} in the roots of polynomials of degree $ n$ and (sequence of) normal subgroups of $ S_n$. As mentioned earlier a {general} polynomial can be solved by radicals only if there exists (sequence of) intermediate variables of lower degrees.\n\nFor any $ S_n$ the correspondence is\n\\begin{align*}\n  \\{ e \\} & \\leftrightarrow  \\mbox{ roots }   \\\\\n  A_n & \\leftrightarrow \\{ +\\sqrt{\\Delta}, -\\sqrt{\\Delta} \\} \\\\\n  S_n & \\leftrightarrow \\mbox{ coefficients }\n\\end{align*}\n\n\nFor $ S_3$ this correspondence is enough as we've already seen that $ \\mu_1^3, \\mu_2^3$ could be expressed in terms of $ \\pm \\sqrt{\\Delta} $, and it is possible to recover the roots from these.\\\\\n\nFor $ S_n, n \\ge 4$ knowing $ \\{ +\\sqrt{\\Delta}, -\\sqrt{\\Delta} \\} $ is not enough to recover the roots.\\\\\n\nHowever we get lucky for $ S_4$, as $ S_4$ has a special normal subgroup $ K_4$ and the variables $ \\{ \\lambda_1, \\lambda_2, \\lambda_3 \\}$ corresponding to this normal subgroup do indeed satisfy a lower degree (cubic) polynomial and the roots can be recovered from these.\n\\begin{align*}\n  K_4 & \\leftrightarrow \\{ \\lambda_1, \\lambda_2, \\lambda_3 \\}\n\\end{align*}\n\nBut because $ S_5$ does not have this accidental normal subgroup, there are not enough intermediate variables which could allow us to find a general formula using radicals. This then is the underlying reason why a quintic polynomial cannot be solved using radicals: as $ S_5$ has very few normal subgroups!!!\\footnote{A more precise statement is that $ A_5$ has no normal subgroups.}\\\\\n\n\\noindent \\textbf{For further reading:} If you're interested in learning more about this you should start by some group theory in more details. One of my favorite algebra book for beginners is \\emph{Algebra}, by Michael Artin.\n\n", "meta": {"hexsha": "768a9ec3b14fc9d7013aaabe494e33835274a9ff", "size": 9371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Symmetries_and_Polynomials.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_and_Polynomials.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_and_Polynomials.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": 53.5485714286, "max_line_length": 469, "alphanum_fraction": 0.6991783161, "num_tokens": 2878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.6010492493647174}}
{"text": "\\subsection{Fields}\\label{subsec:fields}\n\n\\begin{definition}\\label{def:field}\n  As mentioned in \\fullref{def:semiring/field}, fields are commutative division rings.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:ideals_of_field}\n  The only \\hyperref[def:semiring_ideal]{ideals} of a field are \\( \\{ 0 \\} \\) and \\( \\BbbK \\).\n\\end{proposition}\n\n\\begin{theorem}\\label{thm:ring_of_integers_module_prime_is_field}\n  The ring \\( \\BbbZ_n \\) (see \\fullref{def:ring_of_integers_modulo}) of integers modulo \\( n \\) is a field if \\( n \\) is a prime \\hyperref[def:prime_number]{number}.\n\\end{theorem}\n\\begin{proof}\n  We only need to show that \\( \\BbbZ_n \\) has a multiplicative inverse for any nonzero element.\n\n  Fix \\( x \\in \\BbbZ_n \\). If \\( y \\) is a multiplicative inverse of \\( x \\), we should have\n  \\begin{equation*}\n    xy \\cong 1 \\pmod n,\n  \\end{equation*}\n  which is the same as\n  \\begin{equation*}\n    n \\mid (xy - 1).\n  \\end{equation*}\n\n  \\Fullref{thm:bezout_identity} gives us integers \\( a, b \\in \\BbbZ \\) such that\n  \\begin{equation*}\n    ax + bn = \\gcd(x, n) = 1,\n  \\end{equation*}\n  which is the same as\n  \\begin{equation*}\n    -bn = xa - 1.\n  \\end{equation*}\n\n  Define \\( y \\coloneqq \\rem(a, n) \\). This is the multiplicative inverse of \\( x \\).\n\\end{proof}\n\n\\begin{definition}\\label{def:field_extension}\n  If \\( \\Bbbk \\) and \\( \\BbbK \\) are fields and \\( \\Bbbk \\) is a unital \\hyperref[def:first_order_substructure]{subring} of \\( \\BbbK \\), we say that \\( \\Bbbk \\) is a \\term{subfield} of \\( \\BbbK \\) and that \\( \\BbbK \\) is a \\term{field extension} of \\( \\Bbbk \\). If \\( \\BbbK = \\Bbbk \\), we say that \\( \\BbbK \\) is a \\term{trivial field extension} of \\( \\Bbbk \\).\n\n  Field extension are also denoted as \\( \\BbbK / \\Bbbk \\) to highlight the roles of \\( \\BbbK \\) and \\( \\Bbbk \\). This is not a quotient ring, but simply a notation. See \\fullref{def:galois_group}.\n\n  We define the following\n  \\begin{thmenum}\n    \\thmitem{def:field_extension/dimension} The extension \\( \\BbbK \\) is a vector space over \\( \\Bbbk \\). We denote the dimension of this vector space by\n    \\begin{equation*}\n      [\\BbbK : \\Bbbk].\n    \\end{equation*}\n\n    We call \\( [\\BbbK : \\Bbbk] \\) the dimension of \\( \\BbbK \\) over \\( \\Bbbk \\) and if \\( [\\BbbK : \\Bbbk] \\) is finite, we say that \\( \\BbbK \\) is a \\term{finite extension} of \\( \\Bbbk \\).\n\n    \\thmitem{def:field_extension/generated_extension} If \\( x_1, \\ldots, x_n \\) are members of \\( \\BbbK \\), we will use the following\n    \\begin{itemize}\n      \\item The ring \\( \\Bbbk[x_1, \\ldots, x_n] \\) obtained by evaluating \\hyperref[thm:polynomial_ring_universal_property]{polynomials}.\n      \\item The field \\( \\Bbbk(x_1, \\ldots, x_n) \\) obtained by evaluating rational algebraic \\hyperref[def:rational_algebraic_function]{functions}.\n    \\end{itemize}\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:adjoint_extension_field}\n  Any field of rational algebraic \\hyperref[def:rational_algebraic_function]{functions} over \\( \\BbbK \\) is always a field extension of \\( \\BbbK \\). We say that the field \\( \\BbbK(X) \\) is obtained from \\( \\BbbK \\) by \\term{adjoining} a new element \\( X \\). Although formally \\( X \\) is a polynomial, we regard it as a symbol in the sense of \\fullref{def:formal_language}.\n\\end{remark}\n\n\\begin{definition}\\label{def:galois_group}\\mcite[124]{Knapp2016BasicAlgebra}\n  Let \\( \\BbbK \\) be a field \\hyperref[def:field_extension]{extension} of \\( \\Bbbk \\). The group \\( \\op{Gal}(\\BbbK / \\Bbbk) \\) of automorphisms of \\( \\BbbK \\) that leave \\( \\Bbbk \\) fixed is called the \\term{Galois group} of the field extension \\( \\BbbK / \\Bbbk \\).\n\\end{definition}\n\n\\begin{example}\\label{thm:galois_group_complex_over_real}\n  The Galois \\hyperref[def:galois_group]{group} \\( \\op{Gal}(\\BbbC / \\BbbR) \\) is the group of all \\( \\BbbR \\)-linear functions \\( \\varphi: \\BbbC \\to \\BbbC \\) such that\n  \\begin{equation*}\n    \\varphi(\\BbbR) = \\BbbR.\n  \\end{equation*}\n\n  The only such functions are rotations and axial symmetries. No nontrivial rotations of the complex plane leave \\( \\BbbR \\) intact and the only nontrivial axial symmetry that fixes \\( \\BbbR \\) is \\( a + bi \\mapsto a - bi \\). Hence,\n  \\begin{equation*}\n    \\op{Gal}(\\BbbC / \\BbbR) \\cong \\BbbZ_2.\n  \\end{equation*}\n\\end{example}\n\n\\begin{definition}\\label{def:transcendetal_element}\\mcite[454]{Knapp2016BasicAlgebra}\n  We say that the element \\( a \\in \\BbbK \\) of the field extension \\( \\BbbK \\) of \\( \\Bbbk \\) is \\term{transcendental} over \\( \\BbbK \\) if any of the equivalent conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:transcendetal_element/evaluation} The evaluation \\hyperref[thm:polynomial_ring_universal_property]{map} \\( \\Phi_a: \\Bbbk[X] \\to \\Bbbk[a] \\) is injective.\n\n    \\thmitem{def:transcendetal_element/polynomial} There exists no polynomial \\( p(X) \\in \\Bbbk[X] \\) such that \\( p(a) = 0 \\).\n  \\end{thmenum}\n\n  If \\( a \\) is not transcendental, we say that is is \\term{algebraic}.\n\\end{definition}\n\n\\begin{definition}\\label{def:algebraic_extension}\\mcite[456]{Knapp2016BasicAlgebra}\n  We say that the field extension \\( \\BbbK \\) of \\( \\Bbbk \\) is an \\term{algebraic extension} if every element of \\( \\BbbK \\) is algebraic over \\( \\Bbbk \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:field_elements_are_algebraic}\n  Every field is an \\hyperref[def:algebraic_extension]{algebraic} of itself.\n\\end{proposition}\n\\begin{proof}\n  If \\( a \\in \\BbbK \\), then \\( \\BbbK[a] = \\Bbbk \\) because every polynomial evaluates to some real element, depending on \\( a \\), and the constant polynomials already take all possible values. Thus, \\( \\Phi_a \\) is not injective.\n\n  Since \\( a \\in \\BbbK \\) was arbitrary, we conclude that all elements from a field are algebraic over \\( \\BbbK \\).\n\\end{proof}\n\n\\begin{theorem}\\label{thm:algebraic_extension_always_exists}\\mcite[485]{Knapp2016BasicAlgebra}\n  If \\( p(X) \\) is a prime polynomial over the field \\( \\BbbK \\), there exists an algebraic extension of \\( \\BbbK = \\Bbbk[u] \\), where \\( u \\in \\BbbK \\) is a root of \\( p(X) \\).\n\\end{theorem}\n\\begin{proof}\n  Since \\( p(X) \\) is prime, \\( \\braket{p(X)} \\) is a nontrivial prime ideal. By \\fullref{thm:prime_ideals_are_maximal_in_pid}, \\( \\braket{p(X)} \\) is maximal and by \\fullref{def:maximal_ring_ideal}, the quotient \\( \\BbbK \\coloneqq \\Bbbk / \\braket{p(X)} \\) is a field. It is an extension field of \\( \\Bbbk \\).\n\n  Define\n  \\begin{equation*}\n    u \\coloneqq X + \\braket{p(X)}.\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    p(u) = p(X + \\braket{p(X)}) = p(X) + \\braket{p(X)} = \\braket{p(X)},\n  \\end{equation*}\n  hence \\( u \\) is a root of \\( p(X) \\) in \\( \\BbbK \\).\n\n  Thus, \\( u \\) is algebraic over \\( \\Bbbk \\) and \\( \\BbbK \\) is an algebraic extension of \\( \\Bbbk \\).\n\n  It remains to show that \\( \\BbbK = \\Bbbk[u] \\). First, take a coset \\( q(X) + \\braket{p(X)} \\) in \\( \\BbbK \\). We have\n  \\begin{equation*}\n    q(X) + \\braket{p(X)} = (q(X) - X) + (X + \\braket{p(X)}) = (q(X) - X) + u,\n  \\end{equation*}\n  hence this belongs in \\( \\Bbbk[u] \\). Conversely, evaluating a polynomial \\( q(X) \\in \\Bbbk[X] \\) at \\( u \\) gives us\n  \\begin{equation*}\n    q(u) = q(X + \\braket{p(X)}) = q(X) + \\braket{p(X)},\n  \\end{equation*}\n  which is a coset of \\( \\BbbK \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:finite_field_extensions_are_algebraic}\n  Finite field extensions are algebraic.\n\\end{proposition}\n\\begin{proof}\n  Fix a finite field extension \\( \\BbbK / \\Bbbk \\) and denote by \\( n \\) the dimension \\( [\\BbbK : \\Bbbk] \\). Assume that \\( a \\in \\BbbK \\) is transcendental. Then the evaluation map\n  \\begin{equation*}\n    \\Phi_a: \\Bbbk[X] \\to \\Bbbk[a]\n  \\end{equation*}\n  is injective. But \\( \\Bbbk[X] \\) has a countably infinite monomial basis, so \\( \\Bbbk[a] \\) must also have a countable basis consisting of \\( 1, a, a^2, \\ldots \\). But \\( \\Bbbk[a] \\) is a subspace of \\( \\Bbbk \\), which is finite dimensional over \\( \\Bbbk \\).\n\n  The obtained contradiction proves the theorem.\n\\end{proof}\n\n\\begin{theorem}\\label{thm:e_is_transcendental}\\label{thm:eulers_constant_is_transcendental}\n  \\hyperref[def:exponential_function]{Euler's constant} \\( e \\) is transcendental over \\( \\BbbQ \\).\n\\end{theorem}\n\n\\begin{theorem}\\label{thm:pi_is_transcendental}\\mcite[454]{Knapp2016BasicAlgebra}\n  The number \\( \\pi \\) (see \\fullref{def:pi}) is transcendental over \\( \\BbbQ \\).\n\\end{theorem}\n\n\\begin{example}\\label{ex:polynomials_over_pi}\n  \\Fullref{thm:pi_is_transcendental} implies that the polynomials \\( \\BbbQ[X] \\) can be embedded into \\( \\BbbR \\) via \\( \\Phi_\\pi: \\BbbQ[X] \\to \\BbbR \\). We can identify a polynomial\n  \\begin{equation*}\n    p(X) = \\sum_{i=0}^n a_i X^i\n  \\end{equation*}\n  with rational coefficients with the number\n  \\begin{equation*}\n    p(\\pi) = \\sum_{i=0}^n a_i \\pi^i.\n  \\end{equation*}\n\\end{example}\n\n\\begin{definition}\\label{def:algebraically_closed_field}\\mcite[prop. 9.20]{Knapp2016BasicAlgebra}\n  We say that the field \\( \\BbbK \\) is algebraically closed if any of the equivalent conditions are satisfied:\n  \\begin{thmenum}\n    \\thmitem{def:algebraically_closed_field/trivial_algebraic_extensions} \\( \\BbbK \\) has no nontrivial algebraic \\hyperref[def:algebraic_extension]{extensions}.\n    \\thmitem{def:algebraically_closed_field/linear_irreducible_polynomials} Every irreducible polynomial in \\( \\Bbbk[X] \\) is linear.\n    \\thmitem{def:algebraically_closed_field/at_least_one_root} Every nonconstant polynomial in \\( \\Bbbk[X] \\) has at least one root in \\( \\Bbbk \\).\n    \\thmitem{def:algebraically_closed_field/factorization} Every polynomial in \\( \\Bbbk[X] \\) \\hyperref[def:factorization_in_ring]{factors} into a product of linear polynomials.\n    \\thmitem{def:algebraically_closed_field/exactly_n_roots} Every polynomial in \\( \\Bbbk[X] \\) of degree \\( n \\) has exactly \\( n \\) roots in \\( \\Bbbk \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:algebraically_closed_field/trivial_algebraic_extensions}{def:algebraically_closed_field/linear_irreducible_polynomials} Let \\( p(X) \\) be an irreducible polynomial in \\( \\Bbbk[X] \\). By \\fullref{thm:ufd_prime_iff_irreducible}, \\( p(X) \\) is prime. By \\fullref{thm:algebraic_extension_always_exists}, there exists an algebraic extension \\( \\BbbK \\) of \\( \\Bbbk \\) such that the prime polynomial \\( p(X) \\) has a root in \\( \\BbbK \\). But \\( \\Bbbk \\) has no nontrivial algebraic extensions, hence \\( F = G \\) and \\( p(X) \\) has a root \\( u \\in F \\).\n\n  If \\( p(X) \\) is not linear, we can divide \\( p(X) \\) by \\( (X - u) \\) to obtain a lower-degree non-constant polynomial. Hence, \\( p(X) \\) is linear.\n\n  \\ImplicationSubProof{def:algebraically_closed_field/linear_irreducible_polynomials}{def:algebraically_closed_field/factorization} With induction on the polynomial degree, we split a polynomial \\( p(X) \\) into a product of linear polynomials.\n\n  This is obvious for \\( \\deg p = 1 \\). Assume that the statement holds for polynomial of degree strictly less than \\( n \\) and let \\( p(X) \\) be a polynomial of degree \\( n \\). By \\fullref{def:factorization_in_ring}, it is \\hyperref[def:irreducible_ring_element]{reducible}, that is, there exist non-invertible (that is, non-constant) polynomials \\( r_1(X) \\) and \\( r_2(X) \\), such that\n  \\begin{equation*}\n    p(X) = r_1(X) r_2(X).\n  \\end{equation*}\n\n  Since both \\( r_1(X) \\) and \\( r_2(X) \\) are non-constant, they have a positive degree less than \\( n \\). Hence, the induction conjecture holds for them and both can be factored into linear polynomials. Therefore, their product \\( p(X) \\) can also be factored into linear polynomials.\n\n  This completes the proof.\n\n  \\ImplicationSubProof{def:algebraically_closed_field/at_least_one_root}{def:algebraically_closed_field/factorization} Suppose that \\( u_1 \\) is a root of \\( p(X) \\). \\Fullref{thm:polynomial_root_iff_divisible} tells us that \\( p(X) \\) is divisible by \\( (X - u_1) \\). Using induction on the degree of \\( p(X) \\), we can factor \\( p(X) \\) into\n  \\begin{equation*}\n    p(X) = a (X - u_1) (X - u_2) \\cdots (X - u_n),\n  \\end{equation*}\n  where \\( a \\in F \\).\n\n  \\ImplicationSubProof{def:algebraically_closed_field/factorization}{def:algebraically_closed_field/exactly_n_roots} Follows from \\fullref{thm:polynomial_root_iff_divisible} Follows from \\fullref{thm:polynomial_root_iff_divisible} by induction on the polynomial degree. Note that the number of roots is bounded by \\( n \\) (see \\fullref{thm:integral_domain_polynomial_root_limit}).\n\n  \\ImplicationSubProof{def:algebraically_closed_field/exactly_n_roots}{def:algebraically_closed_field/trivial_algebraic_extensions} By \\fullref{thm:integral_domain_polynomial_root_limit}, if \\( p(X) \\) has degree \\( n \\) and exactly \\( n \\) roots, then it has no more roots. Hence, all roots of \\( p(X) \\) are already in the field \\( \\Bbbk \\) and \\( \\Bbbk \\) is the only algebraic extension of itself.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:no_finite_extensions_of_closed_fields}\n  There exist no nontrivial finite extensions of an algebraically closed field.\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\BbbK \\) is a finite extension of the algebraically closed field \\( \\Bbbk \\). By \\fullref{thm:finite_field_extensions_are_algebraic}, \\( \\BbbK \\) is an algebraic extension. But every element of \\( \\Bbbk \\) is already algebraic over \\( \\Bbbk \\), therefore \\( \\BbbK \\subseteq \\Bbbk \\).\n\n  We conclude that \\( \\Bbbk = \\BbbK \\), hence the only finite extension of an algebraically closed field is trivial.\n\\end{proof}\n\n\\begin{definition}\\label{def:splitting_field}\\mcite[458]{Knapp2016BasicAlgebra}\n  We say that a polynomial \\( p(X) \\in \\BbbK[X] \\) over the field \\( \\BbbK \\) \\term{splits} if \\( p(X) \\) can be \\hyperref[def:factorization_in_ring]{factored} into a product of linear polynomials in \\( \\BbbK[X] \\).\n\n  A \\term{splitting field} of \\( p(X) \\) over \\( \\Bbbk \\) is a field extension \\( \\BbbK / \\Bbbk \\) such that\n  \\begin{itemize}\n    \\item \\( p(X) \\) splits over \\( \\BbbK \\).\n    \\item \\( \\BbbK \\) is \\hyperref[def:generated_ring_ideal]{generated} by \\( \\Bbbk \\) and the roots of \\( p(X) \\) over \\( \\BbbK \\).\n  \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:splitting_field_existence}\\mcite[thm. 9.12]{Knapp2016BasicAlgebra}\n  A splitting field exists for every polynomial \\( p(X) \\in \\BbbK[X] \\).\n\\end{proposition}\n\n\\medskip\n\n\\begin{theorem}\\label{thm:galois_field_existence}\\mcite[thm. 9.14]{Knapp2016BasicAlgebra}\n  Fix a prime \\hyperref[def:prime_number]{number} \\( p \\) and a positive integer \\( n \\). Then there exists up to an isomorphism a unique field with \\( p^n \\) elements. Furthermore, this is a splitting field for \\( X^{p^n} - X \\) for the field \\( \\BbbZ_p \\).\n\n  We call this field the \\term{Galois field} of \\( p^n \\) elements over the prime field \\( \\BbbZ_p \\) and denote it by\n  \\( \\BbbF_{p^n} \\). We identify \\( \\BbbZ_p \\) with \\( \\BbbF_p \\).\n\\end{theorem}\n\n\\begin{theorem}\\label{thm:f2_is_boolean_algebra}\n  The Galois field \\( \\BbbF_2 \\) is a \\hyperref[def:boolean_algebra]{Boolean algebra} with joins and meets induced by the ordering (see \\fullref{thm:binary_lattice_operations}) and complements given by \\( \\neg x \\coloneqq x \\mapsto x \\oplus 1 \\).\n\n  More concretely:\n  \\begin{itemize}\n    \\item The top element is \\( \\sup \\{ 0, 1 \\} = 1 \\)\n    \\item The bottom element is \\( \\inf \\{ 0, 1 \\} = 0 \\)\n    \\item Joins are given by \\( \\inf \\{ x, y \\} = xy \\)\n    \\item Meets are given by multiplication \\( \\sup \\{ x, y \\} = x \\oplus y \\oplus (x \\odot y) = x \\oplus y \\oplus \\inf \\{ x, y \\} \\)\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  Addition and multiplication in \\( \\BbbF_2 \\) works as usual integer \\hyperref[def:set_of_integers]{arithmetic}, except that \\( 1 \\oplus 1 = 0 \\):\n  \\begin{equation*}\n    \\begin{tabular}{c c | c c}\n      \\( x \\) & \\( y \\) & \\( x \\oplus y \\) & \\( x \\odot y \\) \\\\\n      \\hline\n      \\( 0 \\) & \\( 0 \\) & \\( 0 \\)          & \\( 0 \\)         \\\\\n      \\( 0 \\) & \\( 1 \\) & \\( 1 \\)          & \\( 0 \\)         \\\\\n      \\( 1 \\) & \\( 0 \\) & \\( 1 \\)          & \\( 0 \\)         \\\\\n      \\( 1 \\) & \\( 1 \\) & \\( 0 \\)          & \\( 1 \\)\n    \\end{tabular}\n  \\end{equation*}\n\n  Evidently \\( 1 \\) is a top element and \\( 0 \\) is a bottom element, thus \\( \\BbbF_2 \\) is a \\hyperref[def:semilattice/lattice]{lattice}.\n\n  Distributivity of multiplication over addition is inherited from \\( \\BbbZ \\), however unlike in \\( \\BbbZ \\), addition distributes over multiplication:\n  \\begin{equation*}\n    \\begin{tabular}{c c c | c c}\n      \\( x \\) & \\( y \\) & \\( z \\) & \\(x \\odot (y \\oplus z) \\) & \\( (x \\odot y) \\oplus (x \\odot z) \\) \\\\\n      \\hline\n      \\( 0 \\) & \\( 0 \\) & \\( 0 \\) & \\( 0 \\)                   & \\( 0 \\)                              \\\\\n      \\( 0 \\) & \\( 0 \\) & \\( 1 \\) & \\( 0 \\)                   & \\( 0 \\)                              \\\\\n      \\( 0 \\) & \\( 1 \\) & \\( 0 \\) & \\( 0 \\)                   & \\( 0 \\)                              \\\\\n      \\( 0 \\) & \\( 1 \\) & \\( 1 \\) & \\( 0 \\)                   & \\( 0 \\)                              \\\\\n      \\( 1 \\) & \\( 0 \\) & \\( 0 \\) & \\( 0 \\)                   & \\( 0 \\)                              \\\\\n      \\( 1 \\) & \\( 0 \\) & \\( 1 \\) & \\( 1 \\)                   & \\( 1 \\)                              \\\\\n      \\( 1 \\) & \\( 1 \\) & \\( 0 \\) & \\( 1 \\)                   & \\( 1 \\)                              \\\\\n      \\( 1 \\) & \\( 1 \\) & \\( 1 \\) & \\( 1 \\)                   & \\( 1 \\)\n    \\end{tabular}\n  \\end{equation*}\n\n  Thus, \\( \\BbbF_2 \\) is a distributive \\hyperref[def:semilattice/distributive_lattice]{lattice}.\n\n  It is also evident that the complementation \\( \\neg x = x \\mapsto x \\oplus 1 \\) gives the desired result:\n  \\begin{itemize}\n    \\item \\( \\inf \\{ x, \\neg x \\} = x \\odot \\neg x = x \\odot (x \\oplus 1) = (x \\odot x) \\oplus (x \\odot 1) = 0 \\) since \\( x \\odot x = x \\odot 1 \\).\n    \\item \\( \\sup \\{ x, \\neg x \\} = x \\oplus \\neg x \\oplus (x \\odot \\neg x) = x \\oplus \\neg x \\oplus 0 = x \\oplus (x \\oplus 1) = 1 \\).\n  \\end{itemize}\n\n  Therefore, \\( (\\BbbF_2, 1, 0, \\inf, \\sup, \\neg x ) \\) is a Boolean algebra.\n\\end{proof}\n\n\\begin{proposition}\n  For any function \\( f: \\BbbF_n \\to \\BbbF_n \\) over any Galois field \\( \\BbbF_n \\), there exists a unique polynomial \\( p(X) \\in \\BbbF_n[X] \\) of degree \\( n - 1 \\) such that the corresponding function \\( p(x) \\) agrees with \\( f(x) \\) on all of \\( \\BbbF_n \\).\n\\end{proposition}\n\\begin{proof}\n  We simply use \\fullref{thm:lagrange_interpolation} on all points of the field.\n\\end{proof}\n\n\\begin{algorithm}\\label{alg:finite_field_polynomial_reduction}\n  Let \\( \\BbbF_p \\) be the \\hyperref[thm:galois_field_existence]{Galois field} for some prime number \\( p \\). Consider the nonzero polynomial\n  \\begin{equation*}\n    f(X_1, \\ldots, X_n) \\coloneqq \\sum_{k_1=0}^{m_1} \\cdots \\sum_{k_n=0}^{m_n} a_{k_1,\\ldots,k_n} X_1^{k_1} \\cdots X_n^{k_n}.\n  \\end{equation*}\n\n  We will build a polynomial \\( \\hat f(X_1, \\ldots, X_n) \\) of degree at most \\( n - 1 \\) that corresponds to the same function. In terms of the \\hyperref[thm:polynomial_ring_universal_property]{evaluation homomorphism}\n  \\begin{equation*}\n    \\Phi: \\BbbF_p[X_1, \\ldots, X_n] \\to \\fun(\\BbbF_p^n, \\BbbF_p),\n  \\end{equation*}\n  this means that\n  \\begin{equation*}\n    \\Phi(f) = \\Phi(\\hat f).\n  \\end{equation*}\n\n  This can be achieved by grouping some of the coefficients. The univariate case is more understandable, so we will instead initially consider the polynomial\n  \\begin{equation*}\n    g(X) \\coloneqq \\sum_{k=0}^m a_k X^k.\n  \\end{equation*}\n\n  We will now use (and later prove) that the following two univariate polynomials evaluate to the same function:\n  \\begin{equation}\\label{eq:alg:finite_field_polynomial_reduction/reduction}\n    \\Phi(X^s) = \\Phi(X^{\\rho(s)}),\n  \\end{equation}\n  where\n  \\begin{align*}\n    &\\rho: \\{ 1, 2, 3, \\ldots \\} \\to \\{ 1, 2, \\ldots, p - 1 \\} \\\\\n    &\\rho(s) \\coloneqq \\begin{cases}\n      p - 1,          &(p - 1) \\mid s \\\\\n      \\rem(s, p - 1), &\\T{times}.\n    \\end{cases}\n  \\end{align*}\n\n  Obviously \\( \\rho(s) = s \\) for \\( s < p \\). It follows from the linearity of \\( \\Phi \\) that\n  \\begin{equation*}\n    \\hat g(X)\n    \\coloneqq\n    \\sum_{k=0}^m a_k X^{r(k)}\n    =\n    \\sum_{j=0}^{p-1} \\left( \\sum_{k \\in r^{-1}(j)} a_k \\right) X^j\n  \\end{equation*}\n  is the desired polynomial.\n\n  In the multivariate case, the reduced polynomial is\n  \\begin{equation*}\n    \\hat f(X_1, \\ldots, X_n) \\coloneqq \\sum_{j_1=0}^{p-1} \\cdots \\sum_{j_n=0}^{p-1} \\left( \\sum_{k_1 \\in r^{-1}(j_1)} \\cdots \\sum_{k_n \\in r^{-1}(j_n)} a_{k_1,\\ldots,k_n} \\right) X_1^{k_1} \\cdots X_n^{k_n}.\n  \\end{equation*}\n\n  Correctness follows, again, from the linearity of \\( \\Phi \\).\n\\end{algorithm}\n\\begin{proof}[Proof of \\eqref{eq:alg:finite_field_polynomial_reduction/reduction}]\n  By \\fullref{thm:fermats_little_theorem},\n  \\begin{equation}\\label{eq:alg:finite_field_polynomial_reduction/fermat}\n    \\Phi(X^p) = \\Phi(X).\n  \\end{equation}\n\n  We now use induction on \\( q \\coloneqq \\quot(s, p) \\).\n  \\begin{itemize}\n    \\item If \\( q = 0 \\), then \\( s < p \\) and no reduction is necessary.\n    \\item If \\( q > 0 \\), let \\( s = (p - 1) q + r \\). We have two cases\n    \\begin{itemize}\n      \\item If \\( (p - 1) \\mid s \\), i.e. if \\( r = 0 \\), then\n      \\begin{balign*}\n        \\Phi(X^s)\n        &=\n        \\Phi(X^{(p-1)q})\n        = \\\\ &=\n        \\Phi(X^{(p-1)(q-1) + (p-1)})\n        = \\\\ &=\n        \\Phi(X^{(p-1)(q-1)}) \\Phi(X^{p-1})\n        \\reloset {\\T{ind.}} = \\\\ &=\n        \\Phi(X^{p-1}) \\Phi(X^{p-1})\n        = \\\\ &=\n        \\Phi(X^{2(p-1)})\n        = \\\\ &=\n        \\Phi(X^{p+(p-2)})\n        = \\\\ &=\n        \\Phi(X^p) \\Phi(X^{p-2})\n        \\reloset {\\eqref{eq:alg:finite_field_polynomial_reduction/fermat}} = \\\\ &=\n        \\Phi(X^{p-1}).\n      \\end{balign*}\n\n      \\item If \\( r > 0 \\), we have\n      \\begin{balign*}\n        \\Phi(X^s)\n        &=\n        \\Phi(X^{(p-1)q+r})\n        = \\\\ &=\n        \\Phi(X^{[(p-1)(q-1) + r] + (p-1)})\n        = \\\\ &=\n        \\Phi(X^{(p-1)(q-1)+r}) \\Phi(X^{p-1})\n        \\reloset {\\T{ind.}} = \\\\ &=\n        \\Phi(X^r) \\Phi(X^{p-1})\n        = \\\\ &=\n        \\Phi(X^{r-1}) \\Phi(X^p)\n        \\reloset {\\eqref{eq:alg:finite_field_polynomial_reduction/fermat}} = \\\\ &=\n        \\Phi(X^{r-1}) \\Phi(X)\n        = \\\\ &=\n        \\Phi(X^r).\n      \\end{balign*}\n    \\end{itemize}\n  \\end{itemize}\n\\end{proof}\n", "meta": {"hexsha": "101fdd412549613ad4ad781500aa1e82cd049240", "size": 22138, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/fields.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/fields.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/fields.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": 55.6231155779, "max_line_length": 573, "alphanum_fraction": 0.6263890144, "num_tokens": 7722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.6010492474441045}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section{November exercises}\n\n\\subsection{Exercise 4}\n\n% \\marginpar{Tuesday\\\\ 2020-10-6, \\\\ compiled \\\\ \\today}\n\nAfter being given a probability distribution \\(\\mathbb{P}(x)\\), we define the \\emph{characteristic function} \\(\\phi \\) as its Fourier transform, which can also be expressed as the expectation value of \\(\\exp(- i \\vec{k} \\cdot \\vec{x})\\): \n%\n\\begin{align}\n\\phi (\\vec{k}) = \\int \\dd[n]{x} \\exp(- i \\vec{k} \\cdot \\vec{x}) \\mathbb{P}(x) \n= \\mathbb{E} \\qty[ \\exp(- i \\vec{k} \\cdot \\vec{x})]\n\\,.\n\\end{align}\n\n\\begin{claim}\nA multivariate normal distribution \n%\n\\begin{align}\n\\mathcal{N}(\\vec{x} | \\vec{\\mu}, C)\n&= \\frac{1}{(2\\pi )^{n/2} \\sqrt{\\det C}} \\eval{\\exp(- \\frac{1}{2} \\vec{y}^{\\top} C^{-1} \\vec{y})}_{\\vec{y} = \\vec{x} - \\vec{\\mu}}\n\\,,\n\\end{align}\n%\nhas a characteristic function equal to \n%\n\\begin{align}\n\\phi (\\vec{k}) = \\exp(- i \\vec{\\mu}\\cdot \\vec{k} - \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k}) \n\\,.\n\\end{align}\n\\end{claim}\n\n\\begin{proof}[Proof: completing the square]\nThe integral we need to compute is given, absorbing the normalization into a factor \\(N\\), by \n%\n\\begin{align}\n\\phi (\\vec{k}) = N \\int \\dd[n]{x} \\eval{\\exp(- i \\vec{k} \\cdot \\vec{x} - \\frac{1}{2} \\vec{y}^{\\top} C^{-1} \\vec{y})}_{\\vec{y} = \\vec{x} - \\vec{\\mu}}\n\\,.\n\\end{align}\n\nThe only integrals we really know how to do are Gaussian ones, so we want to rewrite the argument of the exponential so that it is a quadratic form. The manipulation goes as follows, considering the opposite of the argument the exponential in order to have less minus signs and defining the symmetric matrix \\(V = C^{-1}\\):\n%\n\\begin{align}\ni \\vec{k} \\cdot \\vec{x} + \\frac{1}{2} \\vec{y}^{\\top} V \\vec{y}\n&= i \\vec{k} \\cdot \\vec{x} + \n\\frac{1}{2} \\vec{x}^{\\top} V \\vec{x}\n- \\vec{x}^{\\top} V \\vec{\\mu } \n+ \\frac{1}{2} \\vec{\\mu}^{\\top} V \\vec{\\mu}  \\\\\n&= \\frac{1}{2} \\vec{x}^{\\top} V \\vec{x}\n+ \\vec{x}^{\\top}\\qty(\n    i \\vec{k} - V \\vec{\\mu}\n)\n+ \\frac{1}{2} \\vec{\\mu}^{\\top} V \\vec{\\mu}  \\\\\n\\begin{split}\n&= \\underbrace{\\frac{1}{2} \\qty(\\vec{x} + V^{-1} (i \\vec{k} - V \\vec{\\mu}))^{\\top} V \\qty(\\vec{x} + V^{-1} (i \\vec{k} - V \\vec{\\mu}))}_{\\Circled{1}} +\\\\\n&\\phantom{=}\\ \\underbrace{- \\frac{1}{2} \\qty(i \\vec{k} - V \\vec{\\mu})^{\\top} V^{-1} \\qty(i \\vec{k} - V \\vec{\\mu}) + \\frac{1}{2} \\vec{\\mu}^{\\top} V \\vec{\\mu}}_{\\Circled{2}}\n\\,,\n\\end{split} \n\\end{align}\n%\nwhich we can now integrate, since it is now a quadratic form in terms of a shifted variable, \\(\\vec{x} + \\vec{p}\\), where the constant (with respect to \\(\\vec{x}\\)) vector \\(\\vec{p}\\) is given by \\(V^{-1}(i \\vec{k} - V \\vec{\\mu} )\\).\\footnote{\nIn the last step we applied the matrix square completion formula: for a  symmetric matrix \\(A\\) and vectors \\(\\vec{x}\\), \\(\\vec{b}\\) we have \n%\n\\begin{align} \\label{eq:square-completion}\n&\\frac{1}{2} \\qty(\\vec{x} + A^{-1} \\vec{b})^{\\top} A \\qty(\\vec{x} + A^{-1} \\vec{b}) - \\frac{1}{2} \\vec{b}^{\\top} A^{-1} \\vec{b}  =\\\\\n&= \\frac{1}{2} \\qty[ \\vec{x}^{\\top} A \\vec{x}\n+  \\vec{x}^{\\top} A A^{-1} \\vec{b}\n+  \\qty(A^{-1} \\vec{b})^{\\top} A \\vec{x}\n+  \\qty( A^{-1} \\vec{b})^{\\top} A A^{-1} \\vec{b}\n-  \\vec{b}^{\\top} A^{-1} \\vec{b}]  \\\\\n&=\\frac{1}{2} \\qty[ \\vec{x}^{\\top} A \\vec{x}\n+  \\vec{x}^{\\top} \\vec{b}\n+  \\vec{b}^{\\top} (A^{-1})^{\\top} A \\vec{x}\n+  \\vec{b}^{\\top} (A^{-1})^{\\top}  \\vec{b}\n-  \\vec{b}^{\\top} A^{-1} \\vec{b}]  \\\\\n&= \\frac{1}{2} \\vec{x}^{\\top} A \\vec{x}\n+ \\vec{b}^{\\top} \\vec{x}\n\\,,\n\\end{align}\n%\nwhich we used with \\(\\vec{b} = i \\vec{k} - V \\vec{\\mu}\\).} \n\nNow, shifting the integral from one in  \\(\\dd[n]{x}\\) to one in \\(\\dd[n]{(x + p)}\\) does not change the measure, since the Jacobian of a shift  is the identity.\nThen, we have \n%\n\\begin{align}\n\\phi (\\vec{k}) &= N \\int \\dd[n]{(x+p)} \\exp(- \\Circled{1} - \\Circled{2})  \\\\\n&= N \\sqrt{\\frac{(2\\pi )^{n}}{\\det V}} \\exp(- \\Circled{2})  \\\\\n&= \\underbrace{\\frac{1}{\\sqrt{\\det V \\det C}}}_{= 1} \\exp(- \\Circled{2})\n\\,,\n\\end{align}\n%\nsince the determinant of the inverse is the inverse of the determinant.\n\nNow, we only need to simplify \\(\\Circled{2}\\): \n%\n\\begin{align}\n\\Circled{2} &= - \\frac{1}{2} \\qty[\n    - \\vec{k}^{\\top} V^{-1} \\vec{k}\n    - 2i \\vec{\\mu}^{\\top} V V^{-1} \\vec{k}\n    + \\vec{\\mu}^{\\top} V V^{-1} V \\vec{\\mu}\n]\n+ \\frac{1}{2} \\vec{\\mu}^{\\top} V \\vec{\\mu}  \\\\\n&= \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} + i \\vec{\\mu}^{\\top} \\vec{k}\n\\,,\n\\end{align}\n%\ninserting which into the exponent yields the desired result. \n\\end{proof}\n\n\\begin{proof}[Proof: by diagonalization]\nWe now follow a different approach: the covariance matrix \\(C\\) is symmetric, so we will always be able to find an orthogonal matrix \\(O\\) (satisfying \\(O^{\\top} = O^{-1}\\)) such that \\(C = O^{\\top} D O\\), where \\(D\\) is diagonal. \nWe will then also have \\(V = C^{-1} = O^{\\top} D^{-1} O\\).\nLet us denote the eigenvalues of \\(D\\) as \\(\\lambda _i\\), and the eigenvalues of \\(D^{-1}\\) as \\(d_i = \\lambda _i^{-1}\\).\n\nDefining \\(\\vec{z} = O \\vec{x}\\), \\(\\vec{m} = O \\vec{\\mu}\\), \\(\\vec{u} = O \\vec{k}\\) the negative of the argument of the integral becomes:\n%\n\\begin{align}\n i \\vec{k} \\cdot \\vec{x} \n + \\frac{1}{2}\n\\qty(\\vec{x} - \\vec{\\mu})^{\\top} C^{-1} \n\\qty(\\vec{x} - \\vec{\\mu}) &=\n i \\vec{u} \\cdot \\vec{z} \n+ \\frac{1}{2} (\\vec{z} - \\vec{m})^{\\top} D^{-1} (\\vec{z} - \\vec{m})  \\\\\n&= \ni \\vec{u} \\cdot \\vec{z} \n+ \\frac{1}{2} \\sum _{i} d_i (z_i - m_i)^2   \\\\\n&= \\sum _{i} \\qty[i u_i z_i + \\frac{d_i}{2} \\qty(z_i^2 + m_i^2 - 2 m_i z_i)]  \\\\\n&= \\sum _{i} \\qty[z_i^2 \\frac{d_i}{2} + z_i \\qty(i u_i - m_i d_i) + \\frac{d_i}{2} m_i^2]\n\\,.\n\\end{align}\n\nWith this, and since by \\(\\det O = 1\\) we have \\(\\dd[n]{z} = \\dd[n]{x}\\), we can decompose our Gaussian integral into a product of Gaussian integrals:\n%\n\\begin{align}\n\\phi (\\vec{k}) &= \nN \\int \\dd[n]{x} \\exp(-  i \\vec{k} \\cdot \\vec{x} \n - \\frac{1}{2}\n\\qty(\\vec{x} - \\vec{\\mu})^{\\top} C^{-1} \n\\qty(\\vec{x} - \\vec{\\mu}))  \\\\\n&= N \\int \\dd[n]{z} \\exp(- \\sum _{i} \\qty[z_i^2 \\frac{d_i}{2} + z_i \\qty(i u_i - m_i d_i) + \\frac{d_i}{2} m_i^2])  \\\\\n&= N \\prod_i \\int \\dd{z_i}\n\\exp(- z_i^2 \\frac{d_i}{2} - z_i \\qty(i u_i - m_i d_i) - \\frac{d_i}{2} m_i^2)  \\\\\n&= N \\prod_i \\sqrt{\\frac{2\\pi }{d_i}} \\exp(\\frac{(i u_i - m_i d_i)^2}{2 d_i} - \\frac{d_im_i^2}{2}) \\\\\n&= \\frac{1}{\\sqrt{\\det C \\det V}} \\prod_i \\exp(\\frac{- u_i^2 + m_i^2 d_i^2 - 2 i u_i m_i d_i }{2 d_i} - \\frac{d_i m_i^2}{2}) \\\\\n&= \\exp(\\sum _{i} \\qty[- \\frac{u_i^2}{2d_i} - i u_i m_i])  \\\\\n&= \\exp(- \\frac{1}{2} \\vec{u}^{\\top} C \\vec{u} - i \\vec{u} \\cdot \\vec{m})  \\\\\n&= \\exp(- \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} - i \\vec{k} \\cdot \\vec{\\mu })\n\\,,\n\\end{align}\n%\nwhere we have used the expression for the single-variable Gaussian integral: \n%\n\\begin{align} \\label{eq:single-variable-gaussian-integral}\n\\int \\dd{z} \\exp(- a z^2 + bz + c) = \\sqrt{ \\frac{\\pi}{a}} \\exp( \\frac{b^2}{4 a} + c)\n\\,,\n\\end{align}\n%\nwhich comes from the one-variable completion of the square: \n%\n\\begin{align}\n-az^2 + bz + c = -a \\qty(z - \\frac{b}{2a})^2 + \\frac{b^2}{4a} + c\n\\,.\n\\end{align}\n\nAlso, we used the fact that orthogonal transformation do not change fully-contracted objects, such as scalar products or bilinear forms.\n\\end{proof}\n\n\\subsection{Exercise 5}\n\nWe can calculate the moments of a distribution through its characteristic function: \n%\n\\begin{align}\n\\mathbb{E} \\qty[x_\\alpha^{n_\\alpha } \\dots x_\\beta^{n_\\beta }]\n= \\eval{\\frac{\\partial^{n_\\alpha \\dots n_\\beta } \\phi (\\vec{k})}{\\partial(- i k_\\alpha )^{n_\\alpha } \\dots \\partial(-i k_\\beta )^{n_\\beta }}}_{\\vec{k} = 0}\n\\,.\n\\end{align}\n\nIn the multivariate Gaussian case we can then calculate the mean (component by component) as \n%\n\\begin{align}\n\\mathbb{E}(x_\\alpha ) &= \\eval{\\pdv{\\phi (\\vec{k})}{(-i k_\\alpha )}}_{\\vec{k} = 0}  \\\\\n&= \\eval{\\pdv{}{(-i k_\\alpha )}}_{\\vec{k} = 0}\n\\exp(- \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} - i \\vec{k} \\cdot \\vec{\\mu })  \\\\\n&= \\eval{\\qty[- i \\sum_\\beta  k_\\beta  C_{\\beta  \\alpha } + \\mu _\\alpha ] \\exp(- \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} - i \\vec{k} \\cdot \\vec{\\mu })}_{\\vec{k} = 0}  \\\\\n&= \\mu _\\alpha \n\\,,\n\\end{align}\n%\nwhere we used the fact that the differentiation of a symmetric bilinear form is as follows: \n%\n\\begin{align}\n\\pdv{}{k_\\alpha } \\qty(\\sum _{\\beta \\gamma } k_\\beta k_\\gamma C_{\\beta \\gamma }) = 2 \\sum _{\\beta \\gamma } \\delta_{\\beta \\alpha } k_\\gamma C_{\\beta \\gamma } = 2 \\sum_{\\gamma } k_\\gamma C_{\\alpha \\gamma }\n\\,.\n\\end{align}\n\nThe covariance matrix can be computed by linearity as\n%\n\\begin{align}\n\\widetilde{C}_{\\alpha \\beta } = \\mathbb{E}\\qty[\\qty(x_ \\alpha - \\mathbb{E}(x_\\alpha )) \\qty(x_\\beta - \\mathbb{E}(x_\\beta ))] \n= \\mathbb{E}\\qty[x_\\alpha  x_\\beta ] - \\mu _\\alpha \\mu _\\beta \n\\,,\n\\end{align}\n%\nthe first term of which reads as follows: \n%\n\\begin{align}\n\\mathbb{E}[x_\\alpha x_\\beta ] &= \\eval{\\pdv[2]{\\phi (\\vec{k})}{(-i k_\\beta  )}{(-i k_\\alpha  )}}_{\\vec{k} = 0}  \\\\\n&= \\eval{\\pdv{}{(-i k_\\beta )}}_{\\vec{k} = 0} \\qty[-i \\sum _{\\beta } k_\\beta C_{\\beta \\alpha } + \\mu _\\alpha ] \\exp(- \\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} - i \\vec{k} \\cdot \\vec{\\mu })  \\\\\n&= C_{\\alpha \\beta } + \\mu _\\alpha \\mu _\\beta \n\\,,\n\\end{align}\n%\ntherefore, as expected, \\(\\widetilde{C}_{\\alpha \\beta }\\) is indeed \\(C_{\\alpha \\beta }\\). \n\n\\subsection{Exercise 6}\n\n\\begin{claim}\nThe characteristic function of a multivariate Gaussian is, up to normalization, a multivariate Gaussian. \n\\end{claim}\n\n\\begin{proof}\nThe characteristic function is the exponential of (minus) \n%\n\\begin{align}\n\\frac{1}{2} \\vec{k}^{\\top} C \\vec{k} + i \\vec{k} \\cdot \\vec{\\mu} \n&=  \\frac{1}{2} \\qty(\\vec{k} + i C^{-1} \\vec{\\mu })^{\\top} C \n\\qty(\\vec{k} + iC^{-1}\\vec{\\mu }) + \\frac{1}{2} \\vec{\\mu }^{\\top} C^{-1} \\vec{\\mu }  \n\\,,\n\\end{align}\n%\nwhich means that the characteristic function is in the form \n%\n\\begin{align}\n\\phi (\\vec{k}) = \\const \\times \\exp(- \\frac{1}{2} (\\vec{k} -\\vec{m})^{\\top} C (\\vec{k} - \\vec{m}) )\n\\,,\n\\end{align}\n%\na multivariate normal with mean \\(\\vec{m} = -i C^{-1} \\vec{\\mu}\\) and covariance matrix \\(C^{-1}\\), the inverse of the covariance matrix of the corresponding MVN.  \n\\end{proof}\n\n\\end{document}", "meta": {"hexsha": "1e8b0cfabfd4c96609ee949d5a673672b4898f14", "size": 9943, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_third_semester/astrostat_homework/exercises_456.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_third_semester/astrostat_homework/exercises_456.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_third_semester/astrostat_homework/exercises_456.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": 40.75, "max_line_length": 323, "alphanum_fraction": 0.5750779443, "num_tokens": 4052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6009552966900114}}
{"text": "% This is part of the TFTB Reference Manual.\n% Copyright (C) 1996 CNRS (France) and Rice University (US).\n% See the file refguide.tex for copying conditions.\n\n\n\n\\markright{divider}\n\\section*{\\hspace*{-1.6cm} divider}\n\n\\vspace*{-.4cm}\n\\hspace*{-1.6cm}\\rule[0in]{16.5cm}{.02cm}\n\\vspace*{.2cm}\n\n\n\n{\\bf \\large \\sf Purpose}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\nFind dividers of an integer, closest from the square root of the integer.\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Synopsis}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n\\begin{verbatim}\n[N,M] = divider(N1)\n\\end{verbatim}\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Description}\\\\\n\\hspace*{1.5cm}\n\\begin{minipage}[t]{13.5cm}\n        {\\ty divider} find two integers {\\ty N} and {\\ty M} such that {\\ty\n        M*N=N1}, with {\\ty M} and {\\ty N} as close as possible from {\\ty\n        sqrt(N1)}.\\\\\n\\end{minipage}\n\\vspace*{.5cm}\n\n\n{\\bf \\large \\sf Examples}\n\\begin{verbatim}\n         N1=256; [N,M]=divider(N1); [N,M]\n         ans = \n               16    16 \n         N1=258; [N,M]=divider(N1); [N,M]\n         ans = \n               6     43 \n\\end{verbatim}\n\n\n\n", "meta": {"hexsha": "027d7a627e5b9118c6c8dfa0fa5b32f86001657d", "size": 1130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tftb/refguide/divider.tex", "max_stars_repo_name": "sangyoonHan/extern", "max_stars_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2018-03-28T01:50:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T07:24:14.000Z", "max_issues_repo_path": "tftb/refguide/divider.tex", "max_issues_repo_name": "sangyoonHan/extern", "max_issues_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "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": "tftb/refguide/divider.tex", "max_forks_repo_name": "sangyoonHan/extern", "max_forks_repo_head_hexsha": "a3c874538a7262b895b60d3c4d493e5b34cf81f8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2018-03-28T01:50:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T09:09:40.000Z", "avg_line_length": 20.1785714286, "max_line_length": 74, "alphanum_fraction": 0.5973451327, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6009552950354309}}
{"text": "\\documentclass{memoir}\n\\usepackage{notestemplate}\n\n%\\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}\n%\\institute{Rice University}\n%\\faculty{Faculty of Whatever Sciences}\n%\\department{Department of Mathematics}\n%\\title{Class Notes}\n%\\subtitle{Based on MATH xxx}\n%\\author{\\textit{Author}\\\\Gabriel \\textsc{Gress}}\n%\\supervisor{Linus \\textsc{Torvalds}}\n%\\context{Well, I was bored...}\n%\\date{\\today}\n\n%\\makeindex\n\n\\begin{document}\n\n% \\maketitle\n\n% Notes taken on \n\n\\begin{defn}[Gaussian Integers]\n\tThe Gaussian integers are elements of the quadratic integer ring \\(\\Z[i]\\). Elements of the ring are the complex numbers \\(a+bi \\in \\C\\) with \\(a,b \\in \\Z\\). The field norm \\(N\\) maps\n\t\\begin{align*}\n\t\ta+bi \\mapsto a^2+b^2\n\t\\end{align*}\n\tand hence the units\\(u\\) are given by\n\t\\begin{align*}\n\t\tN(a+bi) = a^2+b^2 = \\pm 1 \\implies u \\in \\left\\{ \\pm 1, \\pm i \\right\\}\n\t\\end{align*}\n\\end{defn}\n\nIn general, let \\(\\mathcal{O}\\) be a quadratic integer ring and \\(N\\) the associated field norm. The multiplicity of the norm gives us a natural irreducibility condition.\n\n\\begin{hw}\n\tLet \\(\\alpha  \\in \\mathcal{O}\\) be an element such that \\(N(\\alpha ) = \\pm p\\) for a prime \\(p \\in \\Z\\). Then \\(\\alpha \\) is irreducible in \\(\\mathcal{O}\\).\n\\end{hw}\n\nLet \\(\\pi \\in \\mathcal{O}\\) be a prime element. Observe that \\((\\pi ) \\cap \\Z\\) is a prime ideal in \\(\\Z\\). Because \\(N(\\pi )\\) is a nonzero integer, we have that \\((\\pi )\\cap \\Z = p\\Z\\) for some integer prime \\(p\\). Hence \\(\\pi \\mid p\\) in \\(\\mathcal{O}\\)-- this hints that we can find the prime elements of \\(\\mathcal{O}\\) by determing how primes in \\(\\Z\\) factor as elements of \\(\\mathcal{O}\\).\\\\\n\nSuppose \\(\\pi \\mid p\\) in \\(\\mathcal{O}\\). Then\n\\begin{align*}\n\tN(\\pi )N(\\pi ') = N(p) = p^2 \\implies N(\\pi ) = \\pm p^2 \\text{ or } N(\\pi ) = \\pm p\n\\end{align*}\nIf the first holds, then \\(\\pi '\\) is a unit and \\(p = \\pi \\) is irreducible in \\(\\Z[i]\\). If the second holds, then \\(\\pi '\\) is also irreducible and \\(p = \\pi \\pi '\\) is the product of precisely two irreducibles.\\\\\n\nNow returning to the case of the Gaussian integers, it follows that \\(p\\) factors in \\(\\Z[i]\\) into precisely two irreducibles if and only if \\(p = a^2+b^2\\) for \\(a,b \\in \\Z\\). Otherwise, it remains irreducible in \\(\\Z[i]\\). If \\(p=a^2+b^2\\) then the irreducible elements in \\(\\Z[i]\\) are \\(a\\pm bi\\).\n\n\\begin{exmp}[Factoring an even prime]\n\tClearly \\(2 = 1^2+1^2\\) and so we get a factorization\n\t\\begin{align*}\n\t\t2 = (1+i)(1-i) = -i(1+i)^2\n\t\\end{align*}\n\tIn fact, \\((1+i)\\) and \\((1-i)\\) are associates-- this is the only situation in which conjugate irreducibles can be associates.\n\\end{exmp}\nSince \\(a^2 \\equiv 0 \\pmod{4}\\) or \\(a^2 \\equiv 1\\pmod{4}\\) for any integer \\(a \\in \\Z\\), an odd prime in \\(\\Z\\) that satisfies \\(p = a^2+b^2\\) must be congruent to \\(1 \\pmod{ 4}\\). Hence, if \\(p\\) is a prime of \\(\\Z\\) and \\(p \\equiv 3 \\pmod{4}\\) then \\(p\\) is irreducible in \\(\\Z[i]\\). In fact, in the first case with \\(p \\equiv 1 \\pmod{4}\\), \\(p\\) must factor into two distinct irreducibles \\((a+bi)(a-bi)\\).\n\n\\begin{lemma}\n\tThe prime number \\(p \\in \\Z\\) divides an integer of the form \\(n^2+1\\) if and only if \\(p = 2\\) or \\(p \\equiv 1 \\pmod{ 4}\\).\n\\end{lemma}\n\nThe Gaussian integers admit a nice Euclidean algorithm that is key to factoring primes further.\n\\begin{thm}\n\tThe Gaussian integers \\(\\Z[i]\\) form a Euclidean Domain.\n\\end{thm}\n\\begin{proof}% Find an alternate proof?\n\tWe will show that \\(f(\\alpha) = N(\\alpha)\\) suffices. Observe that\n\t\\begin{align*}\n\t\t\\alpha = \\beta \\rho + \\theta \\iff\\\\\n\t\t\\frac{\\alpha}{\\beta = \\rho + \\frac{\\theta}{\\beta}}\\iff\\\\\n\t\t\\frac{\\alpha}{\\beta}-\\rho = \\frac{\\theta}{\\beta} \\iff\\\\\n\t\t\\left| \\frac{\\alpha}{\\beta} - \\rho \\right| < 1\n\t\\end{align*}\n\tOf course, this is the distance between \\(\\frac{\\alpha}{\\beta}\\) and \\(\\rho\\). But there always exists a lattice point within distance \\(1\\) of any \\(\\C\\), and so therefore the statement holds.\n\\end{proof}\n\n\\begin{thm}[Fermat's Theorem on sum of squares]\n\tThe prime \\(p\\) can be written as \\(p = a^2+b^2\\) for \\(a,b \\in \\Z\\) if and only if \\(p = 2\\) or \\(p \\cong 1 \\pmod{4}\\). The representation of \\(p\\) as the sum of two squares is unique.\n\\end{thm}\nThis is the last key piece we need to classify all prime elements of Gaussian integers.\n\\begin{thm}[Prime elements of Gaussian integers]\n\tAll Gaussian primes take on the form:\n\t\\begin{itemize}\n\t\t\\item \\(\\varepsilon(1+i)\\) \n\t\t\\item \\(\\varepsilon q\\), where \\(q\\) is prime and \\(q \\equiv 3 \\pmod{4}\\) \n\t\t\\item \\(\\pi\\) where \\(N(\\pi)\\) is a prime with \\(N(\\pi ) \\equiv 1 \\pmod{4}\\)\n\t\\end{itemize}\n\twhere \\(\\varepsilon\\) is a unit.\n\\end{thm}\nWhy is it important to classify all prime elements of \\(\\Z[i]\\)? We will see shortly that this allows us to approach number theory questions by factoring primes in \\(\\Z[i]\\).\n\n\\begin{prop}[Disjoint Partitions of Fields]\n\tLet \\(F\\) be a field. Then we can partition \\(F\\) into disjoint sets by taking all sets of the form\n\t\\begin{align*}\n\t\t\\left\\{ a, -a, a^{-1}, (-a)^{-1} \\right\\} \n\t\\end{align*}\n\twhere \\(a\\in F\\) is non-zero. The union of all sets of this form with \\(\\left\\{ 0 \\right\\} \\) forms a partition of \\(F\\).\n\\end{prop}\n\n\\begin{thm}[Two Squares Theorem]\nConsider the equation \\(x^2+y^2 = n\\), and let \\(n = 2^{\\alpha}p_1^{\\beta_1}\\ldots p_r^{\\beta_r}q_1^{\\gamma_1}\\ldots q_s^{\\gamma_s}\\) be the Gaussian factorization of \\(n\\). Then, \\(x^2+y^2 = n\\) is solvable in \\(\\Z\\) if and only if all \\(\\gamma_j\\) are even. Furthermore, the number of solutions is\n\\begin{align*}\n\t4 \\prod_{j=1}^{r} (\\beta_j + 1) \n\\end{align*}\n\\end{thm}\n\\begin{proof}\n\tFirst, we write \\(n = x^2+y^2 = (x+yi)(x-yi)\\). Using the Gaussian factorization, we rewrite\n\t\\begin{align*}\n\t\tn = 2^{\\alpha}p_1^{\\beta_1}\\cdot \\ldots\\cdot q_1^{\\gamma_1}\\cdot \\ldots = (-i)^{\\alpha}(1+i)^{2\\alpha}\\pi_1^{\\beta_1}\\overline{\\pi_1}^{\\beta_1}\\cdot \\ldots\\cdot q_1^{\\gamma_1}\n\t\\end{align*}\n\tNow observe that\n\t\\begin{align*}\n\t\t(x+yi)\\mid n \\implies x+yi = \\varepsilon (1+i)^{\\alpha'}\\pi_1^{\\beta_1'}\\overline{\\pi_1}^{\\beta_1''}\\cdot \\ldots\\cdot q_1^{\\gamma_1'}\\cdot \\ldots \\\\\n\t\t\\implies x-yi = \\overline{\\varepsilon}(1-i)^{\\alpha'}\\overline{\\pi_1}^{\\beta_1'}\\pi_1^{\\beta_1'}\\cdot \\ldots\\cdot q_1^{\\gamma_1}\n\t\\end{align*}\n\tThen because\n\t\\begin{align*}\n\t\tn = (x+yi)(x-yi)\n\t\\end{align*}\n\tWe have\n\t\\begin{align*}\n\t\t  2\\alpha = \\alpha' + \\alpha' \\iff\\alpha' = \\alpha\\\\\n\t\t\\beta_1 = \\beta_1' + \\beta_1'' \\iff \\beta_1' = 0,1,\\ldots,\\beta_1; \\beta_1'' = \\beta_1-\\beta_1' \\\\\n\t\t\\gamma_1 = \\gamma_1' + \\gamma_1' \\iff \\gamma_1 \\text{ even}, \\gamma_1' = \\frac{\\gamma_1}{2}\\\\\n\t\t(-i)^{\\alpha} = \\varepsilon \\overline{\\varepsilon}(-i)^{\\alpha} \\iff 1 = \\varepsilon \\overline{\\varepsilon} \\text{ which always holds}\n\t\\end{align*}\n\tThus, the equation is always solvable if all the \\(\\gamma\\) are even. Looking at the above, the number of solutions will be\n\t\\begin{align*}\n\t\t1 \\cdot (\\beta_j+1) \\cdot 1 \\cdot 4 = 4 \\prod_{j=1}^{r} (\\beta_j + 1) \n\t\\end{align*}\n\\end{proof}\n\n%\\subsection{Fermat's Last Theorem}\n%\\label{subsec:fermat_s_last_theorem}\n%\\begin{thm}[Fermat's Last Theorem]\n%\tLet \\(n\\geq 3\\). Does \\(x^{n}+y^{n}=z^{n}\\) have positive integer solutions?\n%\\end{thm}\n%It is clear that if it is true for \\(n  = 4\\), \\(n= p\\) prime, then it holds, as of course it will hold for any multiples. We can rewrite this as\n%\\begin{align*}\n%\tx^{p} = z^{p}-y^{p}\n%\\end{align*}\n%\\(y\\) is a parameter, so the roots are\n%\\begin{align*}\n%\tz^{p} = y^{p} \\implies z = (y^{p})^{\\frac{1}{p}} = z, z\\rho, z\\rho^2,\\ldots,z\\rho^{p-1} \\text{ where } \\rho = \\cos \\frac{\\pi}{p} + i \\sin^2 \\frac{2\\pi}{p}\n%\\end{align*}\n%So we can rewrite this as\n%\\begin{align*}\n%\tx^{p} = z^{p}-y^{p} = (z-y)(z-\\rho y)\\ldots(z-\\rho y^{p-1})\n%\\end{align*}\n%Observe that each prime must be a \\(p\\)-th power as they cannot share factors. Let\n%\\begin{align*}\n%\tH_p = \\left\\{ a_0 + a_1\\rho + \\ldots + a_{p-2}\\rho^{p-2} \\right\\}, a_j \\in \\Z \\\\\n%\t\\rho^{p-1}+\\rho^{p-2} + \\ldots + \\rho + 1 = 0\n%\\end{align*}\n%If the factors on the RHS are pairwise coprime, then \\(z-y = \\varepsilon_0 \\theta_0^{p}\\), \\(z-y\\rho = e_1 \\theta_1^{p}\\)\n%BUT the units are non-trivial for these types of coefficients, AND we don't have UFT.\\\\\n%\n%Then Kummer did a different direction. Note that ~\"if there is a gcd then it is UFT\" (not exactly, but dw about it). Then consider for \\(a,b \\in \\Z\\)\n%\\begin{align*}\n%\t\\textrm{gcd}(a,b) = d \\implies d = au + bv\n%\\end{align*}\n%Consider the set\n%\\begin{align*}\n%\t\\left\\{ak + bl \\mid k,l \\in \\Z \\right\\} = \\left\\{dn \\mid n \\in \\Z \\right\\} \n%\\end{align*}\n%Now consider\n%\\begin{align*}\n%\t\\left\\{ak + bl \\mid k,l \\in H_p \\right\\} \n%\\end{align*}\n%If \\( \\exists \\textrm{gcd}(a,b) \\implies\\) this set is the set of multiples of gcd. So for \"ideal numbers\" UFT holds and the proof holds. So for \"ideal numbers\" UFT holds and the proof holds.\n\n% \\printindex\n\\end{document}\n", "meta": {"hexsha": "7dbf1d2cd03bac7bf28119a5cdbc7b339f482738", "size": 8778, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ring Theory/Notes/source/GaussianIntegers.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": "Ring Theory/Notes/source/GaussianIntegers.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": "Ring Theory/Notes/source/GaussianIntegers.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": 50.16, "max_line_length": 410, "alphanum_fraction": 0.6386420597, "num_tokens": 3266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286833, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6009552839659279}}
{"text": "\\chapter{Parametric Assumptions}\n\nThis chapter covers the implementation of our approach for\nanalyzing parametric assumptions.\nWe support all assumptions satisfying the following restrictions:\n\\begin{enumerate}\n\\item The group setting models a symmetric leveled $k$-linear map.\n  Note that if $k=2$, there are no intermediate levels and\n  the source (resp. target) groups is the sole group on level $1$ (resp. $2$).\n  For the non-leveled $k$-linear case, the intermediate groups\n  are irrelevant if the input and challenge are all located on\n  level $1$ and level $k$ (the target group).\n\\item The problem is a computational problem or a decisional\n problem. Decisional problems must be real-or-random and\n the challenge must be in the target group.\n\\item The input given to the adversary must be a monomial.\n\\item The challenge must be a monomial.\\footnote{\n    Note that everything generalizes to polynomials $C$ since\n    the method can be applied to each monomial in $C$.}\n\\end{enumerate}%\n%\n\\newcommand{\\range}[1]{r_{#1} \\in [\\alpha_{#1},\\beta_{#1}]}%\n\\renewcommand{\\brack}[1]{[#1]}%\n%\n\\label{assumption_def}%\nFor a a symmetric leveled $k$-linear map,\n  random variables $\\vec{X}$ and range limits $\\vec{l}$,\n  the adversary input is of the following form\n\\begin{align*}\n  I_1 :={}& \\forall \\range{1,1},\\ldots,\\range{1,w_1}:\\, \\vec{X}^{\\vec{f_{1}}}\n    & \\text{ in group }\\lambda_1\\\\\n  \\ldots & \\\\\n  I_n :={}& \\forall \\range{n,1},\\ldots,\\range{n,w_n}:\\, \\vec{X}^{\\vec{f_{n}}}\n    & \\text{ in group }\\lambda_n\n\\end{align*}\n  and the challenge is of the form\n  $C := \\vec{X}^{\\vec{g}} \\text{ in group }\\lambda$.\nWe assume the following:\n\\begin{description}\n\\item[WF1] $f_{j,i} \\in \\mathbb{Z}[k,\\vec{l},r_{j,1},\\ldots,r_{j,w_j}]$,\n          no overshadowing of range indices, and\n          $\\alpha_{j,i},\\beta_{j,i} \\in \\mathbb{Z}[\\vec{l}]$\n\\item[WF2] $g_i \\in \\mathbb{Z}[k,\\vec{l}]$\n\\item[WF3] $\\lambda_i$ is either a positive integer or\n  of the form $k - i$ for a positive integer $i$\n\\item[WF4] $\\lambda=k$ for decisional problems\n\\end{description}\n%\nNote that we always assume that $\\alpha_i \\leq \\beta_i$ since\n  we assume that all ranges are non-empty and increasing.\nWe also assume that $k > i$ for all such levels occuring in the\n  assumption.", "meta": {"hexsha": "8d51b8a2650121a5f6a8edf9e04e0c21c5b20498", "size": 2254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chap-param.tex", "max_stars_repo_name": "generic-group-analyzer/gga", "max_stars_repo_head_hexsha": "75d362fb3db4cc34b8e3fc7e6d76d8d31068457f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-08-17T11:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-14T14:00:14.000Z", "max_issues_repo_path": "doc/chap-param.tex", "max_issues_repo_name": "generic-group-analyzer/gga", "max_issues_repo_head_hexsha": "75d362fb3db4cc34b8e3fc7e6d76d8d31068457f", "max_issues_repo_licenses": ["MIT"], "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/chap-param.tex", "max_forks_repo_name": "generic-group-analyzer/gga", "max_forks_repo_head_hexsha": "75d362fb3db4cc34b8e3fc7e6d76d8d31068457f", "max_forks_repo_licenses": ["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.3461538462, "max_line_length": 78, "alphanum_fraction": 0.6947648625, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324848629214, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6009552759493056}}
{"text": "\\chapter{Demosaicing}\n\\label{chap:appendix_demosaicing}\nIn this chapter we describe a method allows to address the problem of demosaicing a mosaiced image. It is based on a convex energy that is optimized by using a primal-dual solver. \\\\ \\\\\nHowever, please notice that this method has not been implemented while writing this thesis. This method, as well as all the derivations below were derived during a semester project in the class of $\\textit{Convex Optimization}$ held by Prof. Dr. P. Favaro in 2015. \\\\ \\\\\nThe complete report as well as the corresponding source code to run this solver can be found at: $\\text{\\url{https://github.com/simplay/convex_opt}}$.\n\n\\section{Problem Statement}\n\\label{sec:demosaicing_problem_statement}\nIn this work we address the problem of demosaicing by formulating it as a convex optimization problem. Given a mosaiced image $g$ depicting a raw camera production, we want to find an optimal demosaiced image $u$. For describing the optimality property we take into account a cost function that describes the color smoothness and also that the resulting image $u$ should be close to the given raw input image $g$. \\\\ \\\\\nMore precisely, let $g$ denote the bayer filter camera raw input image. Then we want to solve for $u=(u_r, u_g, u_g)$ (RGB image) minimzating the following energy term (cost function):\n\\begin{align}\n\tE(u_c) = \\norm{\\nabla u_c}_2 + \\frac{\\lambda}{2} \\norm{u_c - g}^2_{\\Omega_{c}}\n\\label{eq:basis_cost_demosaicing}\t\n\\end{align}\nwith the measure\n\\begin{equation}\n\t\\norm{u_C - g}^2_{\\Omega_{C}} = \\sum_x \\sum_y \\Omega_{C}(x,y)\\norm{u_{c}(x,y) - g(x,y)}^2\n\\label{eq:measure}\n\\end{equation}\nwhere C denotes the three different color channels. $\\Omega_{C}$ is defined such that $\\Omega_{C}(x,y) = 1$ if the pixel value at $(x,y)$ is \\emph{valid}$\\footnote{this means that the pixel at location (x,y) is valid for the bayer color mask C}$ and $\\Omega_{C}(x,y) = 0$ when the data is missing. \\\\ \\\\\nThe cost function from Equation $\\ref{eq:basis_cost_demosaicing}$ consists of a smoothness term, $\\norm{\\nabla u_c}_2$ and $\\norm{u_c - g}^{2}_{\\Omega_{c}}$. The first term ensures a smooth color transition between colors in a l2 norm sense. The second term ensures that the reconstructed images does not deviate too much from the given input, i.e. de demosaiced image should resemble to the provided mosaiced raw camera image. This similarity term is further parameterized by a regularization term $\\lambda$, indicating how strong the output should match the given input according to the formulated measure in Equation $\\ref{eq:measure}$. In summary, larger values for $\\lambda$ weight the similarity of the input and output image more, and contrarely, lower values weight the color smoothness term more. \\\\ \\\\\nHereby, minimizating the cost function from Equation $\\ref{eq:basis_cost_demosaicing}$ leads to an optimal demosaiced image $u$.\nMathematically we want to solve for \n\\begin{equation}\n\t\\widetilde{u} = \\argmin_{u_c} E(u_c)\n\\label{eq:our_general_cost_function}\n\\end{equation}\nWe can further simplify the cost function stated in Equation $\\ref{eq:basis_cost_demosaicing}$ relying on the following observation: Since the function $\\Omega_{C}$ is only true for pixels that correspond to the color channel C in the bayer mask, we see that $\\Omega_{C}(x,y)\\norm{u_{c}(x,y) - g(x,y)}$ is only not equal zero if the pixel at location $(x,y)$ belongs to the color channel $C$. Therefore we are allowed to solve the stated optimization problem from Equation $\\ref{eq:basis_cost_demosaicing}$ for each color channel separately. \\\\ \\\\\nAccording to this insight we are supposed to minimize the following three independent$\\footnote{Independent in the sense that we are allowed to solve for each color channel separately}$ convex problems:\n\\begin{align}\n\t\\widetilde{u}_R = \\argmin_{u_R} \\norm{\\nabla u_R}_2 + \\frac{\\lambda}{2} \\norm{u_R - g}^2_{\\Omega_{R}} \\nonumber \\\\\n\t\\widetilde{u}_G = \\argmin_{u_G} \\norm{\\nabla u_G}_2 + \\frac{\\lambda}{2} \\norm{u_G - g}^2_{\\Omega_{G}}\\nonumber \\\\\n\t\\widetilde{u}_B = \\argmin_{u_B} \\norm{\\nabla u_R}_2 + \\frac{\\lambda}{2} \\norm{u_B - g}^2_{\\Omega_{B}}\n\\label{eq:our_convex_probelm}\t\t\n\\end{align}\nWhere we still rely on the measure defined in Equation $\\ref{eq:measure}$ but C was replayed by the appropriate color channel$\\footnote{C stands for either the color channel R, G or B.}$. We notice that the equations in Equation $\\ref{eq:our_convex_probelm}$ tell us that we have to solve three different energies similar to the one formulated in Equation $\\ref{eq:our_general_cost_function}$. \\\\ \\\\\nIn the next section we will describe how to solve the stated minimization problems from Equation $\\ref{eq:our_convex_probelm}$ numerically. \\\\ \\\\\n\n\\section{Primal-Dual Form}\n\\label{sec:primal_dual_form}\nIn this section we derive the primal-dual form of the stated convex demosaicing problem. But first off, let us consider an initial problem of the form \n\\begin{align}\n\t\\min_{x \\in X} F(K x) + G(x)\n\\label{eq:initial_primal}\t\n\\end{align}\nwhere $F$, $G$ are convex functions and $K$ denotes a linear operator. The primal-dual formulation for Equation $\\ref{eq:initial_primal}$ is given by \n\\begin{align}\n\t\\min_{x \\in X} \\max_{y \\in Y} < Kx, y > - F^*(y) + G(x)\n\\label{eq:initial_primal_dual}\t\n\\end{align}\nFor a given mosaiced RGB image $u_{RGB}$ encoded as a 3 dimensional $M \\times N$ matrix, i.e. a tensor of dimension $M \\times N \\times 3$. As mentioned in the problem statement we can solve three independent convex problems in order to solve the problem of demosaicing a RGB image. Therefore let in the following $u$ define stand for one particular color channel of the given color image $u_{RGB}$.\n\\begin{equation}\n\\min_{u \\in U} \\norm{\\nabla u} + \\frac{\\lambda}{2} \\norm{u - g}^2_{\\Omega}\n\\label{eq:initial_energy}\n\\end{equation}\nwhere $\\norm{u - g}^2_{\\Omega}$ is defined as in Equation $\\ref{eq:measure}$ and $g$ is the corresponding color channel of the mosaiced image described in the problem statement. \\\\ \\\\\nWe observe that Equation $\\ref{eq:initial_energy}$ has the same structure as the initial problem stated in Equation $\\ref{eq:initial_primal}$. This allows us to formulate the primal-dual form of Equation $\\ref{eq:initial_energy}$ which will look like the following:\n\\begin{align}\n\t\\min_{u \\in U} \\max_{y \\in Y} < Kx, y > - F^*(y) + G(x)\n\\label{eq:initial_primal_dual}\t\n\\end{align}\nWhere $K$, $F$ and $G$ are defined as:\n\\begin{align}\n\tK &= \\nabla \\nonumber \\\\\n\tF &= \\norm{\\cdot}_2 \\nonumber \\\\\n\tG &= \\norm{u - g}^2_{\\Omega}\n\\label{eq:def_kfg}\t\n\\end{align}\nNote that $F*$ denotes the convex conjugate form of $F$. The convex conjugate of $F$ has an explicit identity that can be computed using the Legendre-Fenchel-Transform.\n\\begin{align}\n\tF^*(y) &= (\\norm{\\cdot}_2)^*(y) \\nonumber \\\\\n\t\t  &= \\sup_x x^T y - \\twonorm{x} \\nonumber \\\\\n\t\t  &= \\sup_x x^T y - \\max_{\\twonorm{z} \\leq 1} x^T z \\nonumber \\\\\n\t\t  &= \\sup_x \\min_{\\twonorm{z} \\leq 1} x^T(y-z) \\nonumber \\\\\n\t\t  &= \\begin{cases}\n   \t\t\t\t0  \t\t\t& \\text{if} \\twonorm{y} \\leq 1 \\\\\n   \t\t\t\t\\infty      & \\text{otherwise}\n  \t\t\t \\end{cases} \\nonumber \\\\\n  \t\t  &= \\delta(y)\n\\label{eq:legendre_fenchel_transform_f}  \t\t  \n\\end{align}\nThe first equality is simply the definition of $F$. The second equality is using the so called Legendre-Fenchel transformation,\n\\begin{equation}\n\t(\\norm{\\cdot}_2)^*(y) = \\sup_x x^T y - \\twonorm{x} \\nonumber\n\\end{equation}. \nIn the third equality I make use of the Cauchy-Schwarz inequality, \n\\begin{equation}\n\t\\twonorm{x} = \\max_{\\twonorm{z} \\leq 1} x^T z\n\\end{equation}\nPlugging Equation $\\ref{eq:legendre_fenchel_transform_f}$ and the definitions in from Equation $\\ref{eq:def_kfg}$ into the primal-dual Equation $\\ref{eq:initial_primal_dual}$ we conclude the following final primal-dual formulation:\n\\begin{equation}\n\\min_{u \\in U} \\max_{y \\in Y} <\\nabla u, y> - \\delta(y) + \\frac{\\lambda}{2}\\norm{u - g}^2_{\\Omega}\n\\label{eq:final_primal_dual}\n\\end{equation}\n\n\\section{Primal-Dual steps}\nIn this section I will present an iterative solver for our stated primal-dual formulation. \\\\ \\\\\nIn the following I am going to rely on an algorithm formulated by A.Chambolle and T.Pocke which allows to solve primal-formulations as ours stated in Equation $\\ref{eq:final_primal_dual}$. \\\\ \\\\\nThey stated an iterative algorithm that has the following update steps:\n\\begin{align}\n\ty^{n+1} &= \\prox_{\\sigma F^*}(y^n + \\sigma K \\bar{x}^n) \\nonumber \\\\\n\tx^{n+1} &= \\prox_{\\tau G}(x^n - \\tau K^* y^{n+1}) \\\\\n\t\\bar{x}^{n+1} &= x^{n+1} + \\theta(x^{n+1} - x^n)\n\\label{eq:update_rules_plain}\t\n\\end{align}\nwith $\\theta \\in (0, 1]$ and the constraint $\\tau \\sigma \\norm{K}^2 < 1$. Note that stated constraint is important in order to guarantee convergence of their algorithm. \\\\ \\\\\nHereby $prox(\\cdot)$ denotes the proximity operator and is defined as \n\\begin{equation}\n\t\\prox_{\\lambda F}(z) = \\arg \\min_x \\frac{1}{2} \\twonorm{x - z}^2 + \\lambda F(x)\n\\end{equation}\nIn the following we will derive explicit identities for the update rules in Equation $\\ref{eq:update_rules_plain}$that can be numerically solved. Our goal is to find an expression for the proximity operator.\n\n\\subsection{Update for $y^{n+1}$}\n\\label{sec:pd_yn}\nIn this subsection we derive an identity for the $y^{n+1}$ update rule from Equation $\\ref{eq:update_rules_plain}$. The key idea is to use the so called Moreau's Identity:  \n\\begin{equation}\n\t\\prox_{\\lambda F^*}(z) = z - \\lambda \\cdot \\prox_{F/ \\lambda}(z / \\lambda) \n\\label{eq:moreau}\t\n\\end{equation}\nNext, we apply the Moreau's identity to the proximity operator of the Legendre-Fenchel transformation.\n\\begin{align}\n\t\\prox_{\\lambda F^*}(y^n + \\sigma K \\bar{x}^{n}) \n\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\sigma \\prox_{\\frac{F}{\\sigma} } \\left(\\frac{y^n + \\sigma K \\bar{x}^{n} }{\\sigma} \\right) \\nonumber \\\\\n\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\sigma \\left( \\frac{y^n + \\sigma K \\bar{x}^{n} }{\\sigma} \\max{0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n} }}} \\right) \\nonumber \\\\\n\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\left( y^n + \\sigma K \\bar{x}^{n} \\right) \\max{\\left(0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n} }}\\right)}  \n\\label{eq:y_n_1_expression}\n\\end{align}\nFor the first equality we use the definition of Equation $\\ref{eq:moreau}$ and for the second equality we used the fact (proven during class) that\n\\begin{align}\n\t\\prox_{\\frac{\\twonorm{\\cdot}}{\\sigma}}(\\frac{x}{\\sigma}) = \\frac{x}{\\sigma} \\max{\\left(0, 1-\\frac{1}{\\twonorm{x}}\\right)}\n\\end{align}\nTo simplify our derivation even and also get rid of the proximity operator we next make a case distinction for $\\twonorm{y^n + \\sigma K \\bar{x}^{n}}$. \n\\begin{itemize}\n\t\\item If $\\twonorm{y^n + \\sigma K \\bar{x}^{n}} \\geq 1$\n\t\tthen  \n\t\t\\begin{align}\n\t\t\t0 \\leq 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}} \\leq 1\n\t\t\\end{align}\n\t\t\n\t\tTherefore $\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}}$ is smaller than one and thus\n\t\t\n\t\t\\begin{align}\n\t\t\t\\max{\\left(0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}}\\right)} \n\t\t\t&= 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}}\n\t\t\\end{align}\n\t\t\n\t\tThis insight can directly be used for the maximum expression in Equation $\\ref{eq:y_n_1_expression}$ and we hence obtain:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\prox_{\\lambda F^*}(y^n + \\sigma K \\bar{x}^{n})\n\t\t\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\left( y^n + \\sigma K \\bar{x}^{n} \\right) \\max{\\left(0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n} }}\\right)} \\nonumber \\\\\n\t\t\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\left( y^n + \\sigma K \\bar{x}^{n} \\right) \\left( 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}} \\right)\\nonumber \\\\\n\t\t\t&= (y^n + \\sigma K \\bar{x}^{n}) -(y^n + \\sigma K \\bar{x}^{n}) +\\frac{y^n + \\sigma K \\bar{x}^{n}}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}} \\nonumber \\\\\n\t\t\t&= \\frac{y^n + \\sigma K \\bar{x}^{n}}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}}\n\t\t\\end{align}\n\t\t\n\t\\item If $\\twonorm{y^n + \\sigma K \\bar{x}^{n}} < 1$\n\t\tthen \n\t\t\\begin{align}\n\t\t\t1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}} < 0\n\t\t\\end{align}\n\t\tthus we conclude \n\t\t\\begin{align}\n\t\t\t\\max{\\left(0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n}}}\\right)} \n\t\t\t&= 0\n\t\t\\end{align}\n\t\twhich offers us the following new identity for Equation $\\ref{eq:y_n_1_expression}$:\n\t\t\n\t\t\\begin{align}\n\t\t\t\\prox_{\\lambda F^*}(y^n + \\sigma K \\bar{x}^{n})\n\t\t\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\left( y^n + \\sigma K \\bar{x}^{n} \\right) \\max{\\left(0, 1-\\frac{1}{\\twonorm{y^n + \\sigma K \\bar{x}^{n} }}\\right)} \\nonumber \\\\\n\t\t\t&= (y^n + \\sigma K \\bar{x}^{n}) - \\left( y^n + \\sigma K \\bar{x}^{n} \\right) 0 \\nonumber \\\\\n\t\t\t&= y^n + \\sigma K \\bar{x}^{n}\n\t\t\\end{align}\n\\end{itemize}\nBy using the results from the case distinction from above we can simplify Equation $\\ref{eq:y_n_1_expression}$ even further to:\n\\begin{equation}\n\t\\prox_{\\lambda F^*}(y^n + \\sigma K \\bar{x}^{n}) = \\frac{y^n + \\sigma K \\bar{x}^{n}}{\\max{\\left(1,\\twonorm{y^n + \\sigma K \\bar{x}^{n}} \\right)}}\n\\label{eq:y_p_1_we_proxy}\t\n\\end{equation}\nFinally, the only left step to do is to plug in the definition of $K$ into Equation $\\ref{eq:y_p_1_we_proxy}$ which gives us then the final update rule for $y_{n+1}$ when relying on the update rule from Equation $\\ref{eq:y_n_1_expression}$:\n\\begin{align}\n\ty_{n+1} = \\frac{y^n + \\sigma \\nabla \\bar{x}^{n}}{\\max{\\left(1,\\twonorm{y^n + \\sigma \\nabla \\bar{x}^{n}} \\right)}}\n\\label{eq:update_rule_y_n_p_1}\t\n\\end{align} \t\n\n\\subsection{Update for $x^{n+1}$}\n\\label{sec:pd_xn}\n\\begin{align}\nx^{n+1} &= \\prox_{\\tau G}(x^n - \\tau K^* y^{n+1}) \\\\\n\t\t&= \\prox_{\\tau \\frac{\\lambda}{2} \\norm{u - g}_{\\Omega}^2 }(x^n - \\tau \\nabla^* y^{n+1}) \\\\\n\t    &= \\arg \\min_{z} \\frac{1}{2} \\twonorm{\\left(x^n - \\tau \\nabla^* y^{n+1} \\right) - z}^2 + \\tau \\frac{\\lambda}{2}\\norm{z - g}_{\\Omega}^2 \\\\\n\t    &= \\arg \\min_{z} E(z)\n\\label{eq:energy_x_p_1}\t    \n\\end{align}\nTo simplify the following derivations, let us define the following substitution: \n\\begin{align}\n\tm := \\left(x^n - \\tau \\nabla^* y^{n+1} \\right)\n\\end{align}\nWe can solve for $x^{n+1}$ by finding the zeros of the partial derivative of $E(z)$ from Equation $\\ref{eq:energy_x_p_1}$. Let us start with the partial derivative along $z$ of $E(z)$ from Equation $\\ref{eq:energy_x_p_1}$: \n\\begin{align}\n\t\\partial_{z} E(z)\n\t&= \\partial_{z} \\left( \\frac{1}{2} \\twonorm{m - z}^2 + \\tau \\frac{\\lambda}{2}\\norm{z - g}_{\\Omega}^2 \\right) \\nonumber \\\\\n\t&= \\frac{1}{2} \\partial_{z} \\left[ \\left( m - z \\right)^{T}\\left( m - z \\right) + \\tau \\lambda \\Omega \\left( z -g \\right)^{T}\\left( z -g \\right) \\right] \\nonumber \\\\\n\t&= \\frac{1}{2} \\partial_{z} \\left[ m^{T}m -2m^{T} z + z^{T} z + \\tau \\lambda \\Omega \\left( z^{T}z -2z^{T} g + g^{T} g\\right) \\right] \\nonumber \\\\\n\t&= \\frac{1}{2} \\left[ -2m + 2z + \\tau \\lambda \\Omega \\left( 2 z -2g \\right) \\right] \\nonumber \\\\\n\t&= \\left[ -m + z + \\tau \\lambda \\Omega z - \\tau \\lambda \\Omega g \\right]\t \\nonumber \\\\\t\n\t&= \\left[ \\left(1+\\tau \\lambda \\Omega \\right)z-m - \\tau \\lambda \\Omega g \\right]\t \\nonumber \\\\\n\\label{eq:derivative_x_n_p_1}\t\t\n\\end{align}\nNext, let us set the finding from Equation $\\ref{eq:derivative_x_n_p_1}$ to zero and solve for $z$:\n\\begin{align}\n\t\\partial_{z} E(z) \n\t&= 0 \\nonumber \\\\\n\t&\\Leftrightarrow \\left(1+\\tau \\lambda \\Omega \\right)z-m - \\tau \\lambda \\Omega g = 0 \\nonumber \\\\\n\t&\\Rightarrow z = \\left(m +  \\tau \\lambda \\Omega g \\right) \\left( 1+\\tau \\lambda \\Omega\\right)^{-1} \\nonumber \\\\\n\t&\\Rightarrow z = \\frac{m +  \\tau \\lambda \\Omega g}{1+\\tau \\lambda \\Omega} \\nonumber \\\\\n\\label{eq:zeros_ez}\t\n\\end{align}\nNote that the division $(1+\\tau \\lambda \\Omega)$ denotes a component-wise division, since $\\Omega$ is applied component-wise to the elements of $g$. In addition, 1 and $\\Omega$ are representing matrices here (of same dimension as $g$ and $z$ ($u$ respectively).\nBy plugging the definition $m$ into Equation $\\ref{eq:zeros_ez}$ and using the fact, that $z$ corresponds to $x^{n+1}$ we can conclude:\n\\begin{align}\n\tx^{n+1} \n\t&= \\frac{x^n - \\tau \\nabla^* y^{n+1} +  \\tau \\lambda \\Omega g}{1+\\tau \\lambda \\Omega} \\nonumber \\\\\n\t&= \\frac{x^n + \\tau div(y^{n+1}) +  \\tau \\lambda \\Omega g}{1+\\tau \\lambda \\Omega}\n\\label{eq:update_x_n_p_1}\t\n\\end{align}\nIn the last step we used the well known fact, that \n\\begin{align}\n\t\\nabla^* (v) = -div(v)\n\\end{align}\nfor any vector-field $v$ of the form \n\\begin{align}\n\tv = \\nabla u\n\\end{align}\nIn the next section I explain how I used the derived update rules in my actual implementation and what parameter values I have used. \n\n\\section{Implementation}\nIn this section I how I have actually Implemented the so far described dual-primal solver for demosaicing a raw image. One important note in advance. In the discrete case, the following holds true \n\\begin{align}\n\t\\nabla^* (y^{n+1}) \n\t&= \\nabla^{T} (y^{n+1}) \\nonumber \\\\\n\t&= div(y^{n+1})\n\\end{align}\nSo we have to omit a minus one factor. This affects the update rule for $x^{n+1}$ derived previously. \\\\ \\\\\nIn the previous section we have defined explicit update rules. Aggregating all finding, mainly those from Equation $\\ref{eq:update_x_n_p_1}$ and Equation $\\ref{eq:update_rule_y_n_p_1}$, and plugging them into Equation $\\ref{eq:update_rules_plain}$ we get our update rules\n\\begin{align}\n\ty^{n+1} &= \\frac{y^n + \\sigma \\nabla \\bar{x}^{n}}{\\max{\\left(1,\\twonorm{y^n + \\sigma \\nabla \\bar{x}^{n}} \\right)}} \\nonumber \\\\\n\tx^{n+1} &= \\frac{x^n - \\tau div(y^{n+1}) +  \\tau \\lambda \\Omega g}{1+\\tau \\lambda \\Omega} \\\\\n\t\\bar{x}^{n+1} &= x^{n+1} + \\theta(x^{n+1} - x^n)\n\\label{eq:final_update_rules_plain}\t\n\\end{align}\nI initialized $x_n$ with the mosaiced image $g$, $y^{n}$ with a zeros \\footnote{a tensor of dimension $M \\times N \\times 2$ filled with zeros, where $(M \\times N)$ denotes the dimension of one color channel of $g$.} and $\\bar{x}^{n}$ also with the mosaiced image $g$. \\\\ \\\\\nFor computing $\\nabla$ I used a forward difference approximation scheme. For computing the divergence operator of the vector-field $y^{n+1}$ I used backward difference approximation scheme. The reason for using a backward difference using a backward difference is to shift back gradients (remember, the divergence is applied to $y^{n+1}$ which is the result of a forward difference. Otherwise, when not altering between a forward-and backward difference we would end up with shifted gradients. \\\\ \\\\\nFor computing the divergence, I relied on its mathematical definition. For a given vector-field $v = (v_x, v_y)$ the divergence is defined as the following:\n\\begin{align}\n\tdiv(v) = \\partial_x v_x + \\partial_y v_y\n\\end{align}\nSince in our case we have $v = y^{n+1}$ and $y^{n+1}$ a vector valued function of the form $y^{n+1} = (y_{x}^{n+1}, (y_{y}^{n+1})$ it follows:\n\\begin{align}\n\tdiv(y^{n+1}) \n\t&= div((y_{x}^{n+1}) + div((y_{y}^{n+1}) \\\\\n\t&= \\left( \\partial_x y_{x}^{n+1} + \\partial_y y_{x}^{n+1} \\right) + \\left( \\partial_x y_{y}^{n+1} + \\partial_y y_{y}^{n+1} \\right)\n\\end{align}\nInitially, I used the following parameter setting:\n\\begin{align}\n\t\\lambda &= 1000 \\\\\n\t\\theta &= 0.5 \\\\\n\t\\tau &= 2*10^{-3} \\\\\n\t\\sigma &= \\frac{1}{\\tau * \\sqrt{\\norm{K}}}\n\\label{eq:parameter_set_up}\t\n\\end{align}\nWith $\\sqrt{\\norm{K}} = \\sqrt{4}$, a strong upper bound for the function $K$\\footnote{For further information about this upper bound please have a look at Chambolle, Antonin: An algorithm for total variation minimisation and application. In Journal of Mathematical imaging and vision 20, 2004.}. \\\\ \\\\\nFor consistency, a named all functions in my Matlab code the same as in this report. Furthermore I used a fixed number of iterations for computing my iterative demosaiced images. The final algorithms I have to perform is the following: For each color-channel $C \\in \\{R,G,B\\}$ Do Loop until $\\norm{\\bar{x}^{n+1} - \\bar{x}^{n}}$ is small enough do: use parameter setup as defined in Equation $\\ref{eq:parameter_set_up}$ and then solve the update rules from Equation $\\ref{eq:final_update_rules_plain}$. Finally, merge all color iterative color channel solutions to a color image. \\\\ \\\\\nWhen computing the gradient and divergence finite approximation schemes, I used a zero padding boundary condition. Since I also tried out this kind of boundary condition in the first report, comparing the results produced in this project which those from the first project is valid. \\\\ \\\\\nOne last comment: From the definition of the update rules, we see that the value of $\\lambda$ directly affects the parameters $\\tau$ and $\\sigma$. Thus, when changing the value of $\\lambda$ we also would have to find new best $\\tau$ and $\\sigma$ parameters. Hence, changing $\\lambda$ also affects the convergence behaviour of the primal dual method. \n", "meta": {"hexsha": "0aef75ceed587036d9d642658a50157b8d792c09", "size": 20474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Document/Source/Chapters/demosaicing.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/demosaicing.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/demosaicing.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.9133574007, "max_line_length": 811, "alphanum_fraction": 0.6854058806, "num_tokens": 6734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6008845781732834}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 24, 2022}\n\\subsection{Algebraic Integers \\emph{continued}}\n\\recall our definition for algebraic integers\\dots\n\\begin{definition*}[Algebraic Integer]\n    A complex number that satisfies $f(x) = 0$ for a non-constant \\emph{monic} polynomial $f(x)\\in\\ZZ[x]$ is an \\ul{algebraic integer}.\n\n    An algebraic number is an algebraic number whose minimal polynomial over $\\QQ$ has integer coefficients.\n\n    We denote this set by $\\ZZbar$.\n\\end{definition*}\n\nClearly, we have that $\\ZZbar \\subseteq \\QQbar$.\n\\begin{claim*}\n    We want to show that $\\ZZbar$ is, in fact, a subring of $\\QQbar$.\n\\end{claim*}\n\n\\begin{lemma}[Setup Lemma, p.44 \\cite{stewart2015algebraic}]\n    $\\theta\\in\\CC$ is an algebraic integer iff the additive group generated by all powers $1, \\theta, \\theta^2, \\dots$, $\\ZZ[\\theta, \\theta^2, \\dots]$, is finitely generated.\n\\end{lemma}\n\\begin{proof}\n    \\begin{description}\n        \\item[Forward Direction.] Suppose $\\theta\\in\\ZZbar$. Then for some $n$,\n            \\[\\theta^n  + a_{n-1}\\theta^{n-1} + \\cdots + a_0 = 0,\\]\n            where $a_i\\in\\ZZ, \\forall\\ 0\\leq i\\leq n-1$.\n            \\begin{claim*}\n                Every power of $\\theta$ lies in the additive group $\\Gamma$ generated by $1, \\theta, \\theta^2, \\dots, \\theta^{n-1}$.\n            \\end{claim*}\n            Suppose inductively that $m\\geq n$, and that $1, \\theta, \\theta^2, \\dots, \\theta^m\\in\\Gamma$. We express\n            \\begin{align*}\n                \\theta^{n+1} = \\theta^{m+1-n}\\theta^n & = \\theta^{m+1-n}(-a_{n-1}\\theta^{n-1} - \\cdots - a_0)     \\\\\n                                                      & = -a_{n-1}\\theta^m - \\text{lower degree stuff} \\in \\Gamma\n            \\end{align*}\n        \\item[Backward Direction.] Suppose every power of $\\theta$ lies in a finitely generated additive group $G$. Then the subgroup $\\Gamma$ of $G$ generated by $\\left\\{ 1, \\theta, \\theta^2, \\dots \\right\\}$ must also be finitely generated.\n\n            Let $v_1, \\dots, v_n$ be generators of $\\Gamma$. (\\textsc{wlog} can assume not all zero). Each $v_i \\in\\ZZ[\\theta]$ (polynomial in $\\theta$ with integer coefficients), so $\\theta v_i\\in\\ZZ[\\theta]\\ \\forall i$. Hence there exists integers $b_{ij}$ such that\n            \\[\\theta v_i = \\sum_{j=1}^n b_{ij}v_j\\quad \\forall i.\\]\n            This gives us a system of linear equations\n            \\begin{align*}\n                (b_{11}-\\theta)v_1 + b_{12}v_2 + \\cdots + b_{1n}v_n & = 0    \\\\\n                b_{21}v_1 + (b_{22}-\\theta)v_2 + \\cdots + b_{2n}v_n & = 0    \\\\\n                                                                    & \\vdots \\\\\n                b_{n1}v_1 + b_{n2}v_2 + \\cdots + (b_{nn}-\\theta)v_n & = 0\n            \\end{align*}\n            So now we have $A\\vec{v} = \\vec{0}$ so $\\det{A} = 0$.\n\n            The $v_1, \\dots, v_n\\in \\CC$ give a nontrivial solution to the obvious associated system of linear equations, so the determinant\n            \\[\\left|\\begin{array}{cccc}\n                    b_{11} - \\theta & b_{12}          & \\cdots & b_{1n}          \\\\\n                    b_{21}          & b_{22} - \\theta & \\cdots & b_{2n}          \\\\\n                    \\vdots          & \\vdots          & \\ddots & \\vdots          \\\\\n                    b_{n1}          & b_{n2}          & \\cdots & b_{nn} - \\theta\n                \\end{array}\\right|\\]\n            is zero. So the determinant, expanding as minors as a polynomial, is a monic\\footnote{The highest degree of $\\theta$ comes from the diagonal which monic up to sign. We also have that this is the characteristic of the $b_{ij}$ matrix which is monic.} polynomial (in $\\theta$) with integral entries $b_{ij}$ of which $\\theta$ satisfies. So $\\theta$ is an algebraic integer.\n    \\end{description}\n    Both directions of which are as desired.\n\\end{proof}\n\nNote we prove something stronger and more intuitive:\n\\begin{lemma*}\n    $\\theta\\in\\CC$ is an algebraic integer iff the additive subgroup generated by $1, \\theta, \\theta^2, \\dots$ is in fact generated by $1, \\theta, \\theta^2, \\dots, \\theta^{n-1}$ for some $n$.\n\\end{lemma*}\n\\begin{theorem}\n    $\\ZZbar$ is a subring of $\\QQbar$.\n\\end{theorem}\n\\begin{proof}\n    Suppose that $\\theta, \\phi\\in\\ZZbar$. We want to show that $\\theta + \\phi, \\theta\\phi\\in\\ZZbar$.\n\n    By the lemma, all powers of $\\theta$ lie in a finitely generated subgroup $\\Gamma_\\theta$ of $\\CC$ and similarly, all powers of $\\phi$ lie in a finitely generated subgroup $\\Gamma_\\phi$ of $\\CC$.\n\n    \\otoh, all powers of $\\theta + \\phi$ and $\\theta\\phi$ are integer linear combinations of the elements\n    \\[\\theta^k \\phi^l\\in \\Gamma_\\theta\\Gamma_\\phi\\]\n    where $\\Gamma_\\theta\\Gamma_\\phi := $ the additive group generated by $v_iw_j$ where $1\\leq i\\leq n$ and $1\\leq j\\leq m$ with\n    \\begin{align*}\n        \\Gamma_\\theta & = \\langle v_1, \\dots, v_n\\rangle \\\\\n        \\Gamma_\\phi   & = \\langle w_1, \\dots, w_m\\rangle\n    \\end{align*}\n    We note that $\\Gamma_\\theta\\Gamma_\\phi$ is finitely generated, and since each power of $\\theta+\\phi$ and $\\theta\\phi$ lie in this finitely generated subgroup\\footnote{The subgroup that they generate had better be finitely generated.}, by our lemma $\\theta + \\phi$ and $\\theta\\phi$ are both algebraic integers.\n\\end{proof}\n\n\\begin{theorem}[p.44 or p.45 \\cite{stewart2015algebraic}]\n    Let $\\theta\\in\\CC$ satisfy a monic polynomial equation with coefficients in $\\ZZbar$ (not just in $\\ZZ$). Then $\\theta$ is an algebraic integer.\n\\end{theorem}\n\\begin{proof}\n    \\emph{One imitates the proof of the forward direction in our previous setup lemma, applying a bit of module theory.}\n\\end{proof}\n\n\\subsection{Ring of Integers of a Number Field}\n\\begin{definition}[Ring of Integers of Number Field $K$]\n    If $K$ is a number field, then\n    \\[\\riO_K := K\\cap \\ZZbar\\]\n    is called the \\ul{ring of integers of $K$}.\\footnote{In textbooks, it's \\emph{fraktor} $\\mathfrak{O}$. In papers, usually mathcal $\\mathcal{O}$. In handwriting, usually fancy loopy $O$.}\n\\end{definition}\n$\\riO_K$ is a ring because $K$ and $\\ZZbar$ are subrings of $\\CC$. The relationship between $K$ and $\\riO_K$ is the same as that of $\\QQ$ and $\\ZZ$.\n\n\\begin{lemma}\n    If $\\alpha\\in K$, then $c\\alpha\\in \\riO_K$ for some $c\\in\\ZZ$.\n\\end{lemma}\n\\begin{proof}\n    Let $\\alpha\\in K$ and $f(x) = \\minpoly_\\QQ(\\alpha)$, with $\\deg f = n$. Let $0\\neq c\\in \\ZZ$ and let $g_c := c^n\\cdot f\\left( \\frac{x}{c} \\right)$.\n\n    Observe:\n    \\begin{enumerate}[1)]\n        \\item The roots of $g_c$ are the $c\\alpha_i$ where $\\alpha_i$ are the roots of $f$.\n        \\item $g_c$ is monic.\n        \\item If we choose $c$ to be the lcm of the denominators of the coefficients of $f$ implies that $g_c$ has integer coefficients.\n    \\end{enumerate}\n    So $c\\alpha$ is an element of $\\riO_K$ since it is also an algebraic integer.\n\\end{proof}\n\n\\begin{corollary}\n    If $K$ is a number field, then $K = \\QQ(\\theta)$, for some algebraic integer $\\theta\\in\\ZZbar$.\n\\end{corollary}\n\n\\textbf{Warning!} (pp.46-47 \\cite{stewart2015algebraic}) Though it is often the case that if $K = \\QQ(\\theta)$ with $\\theta\\in\\ZZbar$, then $\\riO_K = \\ZZ[\\theta]$, this need not be true.\n\\begin{example}\n    Let $K = \\QQ(\\sqrt{5})$. However,\n    \\[\\ZZ[\\sqrt{5}]\\subsetneq \\riO_K\\]\n    In fact, \\[\\ZZ\\left[ \\frac{1+\\sqrt{5}}{2} \\right] = \\riO_K.\\]\n\\end{example}\nFurthermore, is it always the case that $\\riO_K$ is generated by a single element? \\emph{No!} $\\riO_K$ need \\ul{not} be of the form $\\ZZ[\\theta]$ for some $\\theta\\in\\ZZbar$.\n\\begin{example}\n    The counterexample of this is\n    \\[K = \\QQ(\\theta)\\]\n    when $\\theta$ is a root of $x^3 - x^2 - 2x - 8$.\n\\end{example}\nNumber fields where such a $\\theta$ does exist are called \\ul{monogenic}.", "meta": {"hexsha": "1b5c5ef77a647733aab67fe4e0ec45decab14d52", "size": 7679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-24.tex", "max_stars_repo_name": "jchen/math1560-notes", "max_stars_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-02T15:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T20:28:48.000Z", "max_issues_repo_path": "lectures/2022-03-24.tex", "max_issues_repo_name": "jchen/math1560-notes", "max_issues_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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-24.tex", "max_forks_repo_name": "jchen/math1560-notes", "max_forks_repo_head_hexsha": "a3605894c69d4e3dd7f90829523ff3ec3c73a6f4", "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": 60.4645669291, "max_line_length": 383, "alphanum_fraction": 0.617528324, "num_tokens": 2459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583124210896, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.60088456783588}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{geometry}                \n\\geometry{a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}\n\\usepackage{natbib}\n\\usepackage{color}\n\\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue\n\\definecolor{mylilas}{RGB}{170,55,241}\n\\usepackage{epsfig}\n\\usepackage{amssymb,amsmath}\n\\usepackage{enumerate}\n\\usepackage{enumitem}\n\\usepackage[utf8]{inputenc}\n\\usepackage{hyperref}\n\\usepackage{mathtools}\n\n\n\\newcommand{\\ssd}{\\text{ssd}}\n\\newcommand{\\sS}{\\mathsf{S}}\n\\newcommand{\\tot}{\\text{tot}}\n\n\\begin{document}\n\n\n\\input{symbols}\n\n\\section*{Linear stability analysis}\n\nWith $h_b = 0$, the linear eigenproblem is\n\n\\begin{equation}\n \\sA \\, \\mathsf{\\Phi} = \\omega \\, \\sB\\, \\mathsf{\\Phi}\\,,\n\\end{equation}\nwhere\n\n\\begin{equation}\n\\sA \\equiv \\mathsf{B}(\\mathsf{U}\\, k + \\mathsf{V}\\,l) + \\mathsf{I}\\left(k\\,\\mathsf{Q}_y - l\\,\\mathsf{Q}_x\\right) + \\mathsf{I}\\,\\delta_{\\mathsf{N}\\mathsf{N}}\\, \\mathrm{i} \\,r_{ek}\\,\\kappa^2\\,,\n\\end{equation}\nwhere $\\delta_{\\mathsf{N}\\mathsf{N}} = [0,0,\\dots,0,1]\\,,$\nand \n\\begin{equation}\n\\mathsf{B} \\equiv  \\mathsf{S} - \\mathsf{I} \\kappa^2\\,. \n\\end{equation}\nThe growth rate is Im$\\{\\omega\\}$.\n\n\\end{document}\n", "meta": {"hexsha": "c247271107292f389ac8673e2098dc54ede6db21", "size": 1180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/equations/notation_linearstability.tex", "max_stars_repo_name": "pittwolfe/pyqg", "max_stars_repo_head_hexsha": "3a4b8b0a53dc0204a437376ffdcb981568edb111", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 100, "max_stars_repo_stars_event_min_datetime": "2015-08-31T19:05:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T23:36:33.000Z", "max_issues_repo_path": "docs/equations/notation_linearstability.tex", "max_issues_repo_name": "pittwolfe/pyqg", "max_issues_repo_head_hexsha": "3a4b8b0a53dc0204a437376ffdcb981568edb111", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 212, "max_issues_repo_issues_event_min_datetime": "2015-08-30T04:07:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T22:42:16.000Z", "max_forks_repo_path": "docs/equations/notation_linearstability.tex", "max_forks_repo_name": "pittwolfe/pyqg", "max_forks_repo_head_hexsha": "3a4b8b0a53dc0204a437376ffdcb981568edb111", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 75, "max_forks_repo_forks_event_min_datetime": "2015-08-31T16:16:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T17:33:30.000Z", "avg_line_length": 25.652173913, "max_line_length": 191, "alphanum_fraction": 0.6754237288, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6008731139750215}}
{"text": "\\documentclass[letterpaper]{article}\n\n\\usepackage{fullpage}\n\\usepackage{nopageno}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\allowdisplaybreaks\n\n\\newcommand{\\abs}[1]{\\left\\lvert #1 \\right\\rvert}\n\n\\begin{document}\n\\title{Notes}\n\\date{September 5, 2014}\n\\maketitle\n\\section*{proposition 2.5.1}\nlast time we got to $|a_nb_n-AB|\\le ...\\le |a_n||b_n-B|+|a_n-A||B|$, where $|b_n-B|=|a_n-A|=\\epsilon$. $L-1\\le a_n\\le L+1$.\n\nlet $\\{a_n\\}_{n=1}^\\infty$ be a convergent sequence of real numbers, them $\\{a_n:n\\in\\mathbb{N}\\}$ is bounded above and below.\n\n\\subsection*{proof}\nlet $L=\\lim_{n\\to\\infty}a_n$. set $\\epsilon=1$ then there is a $N_1\\in\\mathbb{N}$ such that $|a_n-L|<1$ if $n\\ge N_1$. Hence for $n=N_1,N_{1}+1,N_1+2,...$ etc $L-1\\le a_n\\le L+1$. $N_1$ is a fixed natural set. $B=\\{a_z,a_2,...,a_{N_1-1}\\}$. let $M=\\max B, m=\\min B$. $\\forall n\\ge1, \\min\\{L-1,m\\}\\le a_n\\le\\max\\{L+1,M\\}$.\n\n\\subsection*{example 2.4Ac}\n\\begin{align*}\n  0\\le\\lim_{n\\to\\infty}\\frac{3^n}{n!}&=\\lim_{n\\to\\infty}\\frac{3\\cdot3\\cdot3\\cdot...\\cdot3\\cdot3\\cdot3}{n(n-1)(n-2)...4\\cdot3\\cdot2\\cdot1}\\\\\n  &=\\lim_{n\\to\\infty}\\frac{3\\cdot3\\cdot3\\cdot...\\cdot3\\cdot3\\cdot3\\cdot27}{n(n-1)(n-2)...4\\cdot(3\\cdot2\\cdot1)}\\\\\n  &\\le \\lim_{n\\to\\infty}\\frac{3}{n}\\cdot1\\cdot...\\cdot1\\cdot\\frac{9}{2}\n\\end{align*}\nso by squeeze it's zero\n\\section*{excercise}\nif $a_n\\le b_n\\forall n$ then $\\lim_{n\\to\\infty}a_n\\le\\lim_{n\\to\\infty}b_n$\n\\end{document}\n", "meta": {"hexsha": "20c764bc4e9623beb6cd399c7ca586ffd1f4981e", "size": 1406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "real analysis/analysis-notes-2014-09-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": "real analysis/analysis-notes-2014-09-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": "real analysis/analysis-notes-2014-09-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": 42.6060606061, "max_line_length": 321, "alphanum_fraction": 0.6571834993, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.6008731090481597}}
{"text": "\\section{Preliminaries}\r\n\\label{sec:HomographyPreliminaries}\r\n\r\nWe define a marker as an object with a known, easy-to-detect shape. Such an object can be either naturally occurring or artificially placed on the planar surface of the scene we want to remove perspective distortion from. The marker contains keypoints, which is a set of distinct, independent, visual feature points (for instance, corners). The chosen keypoints visible in the perspectively deformed image are called the \\mbox{warped keypoints}. The set of the \\mbox{rectified keypoints} is represented in the desired image (not subjected to perspective distortion) and is produced from the warped keypoints using the homography projection. Last but not least, the \\mbox{point correspondence} is a relationship between the warped and the \\mbox{target keypoints} and it is necessary for homography estimation. In an ideal case, the rectified keypoints match the target keypoints in terms of their pixel positions (\\figtext{}~\\ref{fig:HomographyTerminology}).\r\n\r\n% ------------------------------------------------------------------------------\r\n\\begin{figure}[t]\r\n    \\centering\r\n    \\includegraphics[width=0.6\\linewidth]{figures/homography/terminology.pdf}\r\n    \\caption[Homography ranking terminology]{Visualization of relationships within our established terminology. This diagram also depicts the hierarchical dependence between individual terms. In addition, the dotted elements represent processes with arrows denoting their input and output.}\r\n    \\label{fig:HomographyTerminology}\r\n\\end{figure}\r\n% ------------------------------------------------------------------------------\r\n\r\nUnless stated otherwise, a \\mbox{\\textbf{similarity transformation}} denotes a limited affine transformation with $4$ \\gls{dof} which encompasses translation, rotation and uniform scaling (\\eqtext{}~\\ref{eq:SimilarityMatrices}). Specifically, let $\\mset{K}_1$ and $\\mset{K}_2$ be sets of feature keypoints belonging to objects $O_1$ and $O_2$. We refer to the objects $O_1$ and $O_2$ as \\mbox{\\textbf{similar}} if there exists a similarity transformation $\\psi$, such that $\\mset{K}_1 = \\func{\\psi}{\\mset{K}_2}$ and $\\mset{K}_2 = \\func{\\psi^{-1}}{\\mset{K}_1}$. For instance, $O_1$ and $O_2$ may represent rectangles of different sizes whilst having a equal aspect ratio.\r\n\r\nLet $m$ denote the number of markers and $k$ represent the number of keypoints belonging to each marker in consideration. We describe each $i$-th marker using a $3 \\times k$ matrix $\\suprbrackets{\\mtx{W}}{i}$ that stores the warped keypoints as\r\n\\begin{equation}\r\n    \\suprbrackets{\\mtx{W}}{i} =\r\n    \\begin{bmatrix}\r\n        \\subsuprbrackets{x}{1}{i} & \\subsuprbrackets{x}{2}{i} & \\dots & \\subsuprbrackets{x}{k}{i} \\\\\r\n        \\subsuprbrackets{y}{1}{i} & \\subsuprbrackets{y}{2}{i} & \\dots & \\subsuprbrackets{y}{k}{i} \\\\\r\n        1                         & 1                         & \\dots & 1\r\n    \\end{bmatrix},\r\n    i = 1, \\dots, m.\r\n\\end{equation}\r\nAnalogivally, we describe the target keypoints using a $3 \\times k$ matrix $\\mtx{T}$. Owing to the many-to-one point correspondence, only one specification is sufficient. Just beware that the ordering of keypoints had to match the warped keypoints defined above, so\r\n\\begin{equation}\r\n    \\mtx{T} =\r\n    \\begin{bmatrix}\r\n        \\tilde{x}_1 & \\tilde{x}_2 & \\dots & \\tilde{x}_k \\\\\r\n        \\tilde{y}_1 & \\tilde{y}_2 & \\dots & \\tilde{y}_k \\\\\r\n        1           & 1           & \\dots & 1\r\n    \\end{bmatrix},\r\n\\end{equation}\r\nwith the point correspondence relationship formulated as\r\n\\begin{equation}\r\n    \\subsuprbrackets{x}{j}{i} \\simeq \\tilde{x}_j, \\subsuprbrackets{y}{j}{i} \\simeq \\tilde{y}_j, i = 1, \\dots, m, j = 1, \\dots, k.\r\n\\end{equation}\r\n", "meta": {"hexsha": "4af01cf556b9183cb4667acd49b0568566690fd2", "size": 3726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/chapters/homography/sections/preliminaries.tex", "max_stars_repo_name": "mondrasovic/phd_thesis", "max_stars_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_stars_repo_licenses": ["MIT"], "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/chapters/homography/sections/preliminaries.tex", "max_issues_repo_name": "mondrasovic/phd_thesis", "max_issues_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_issues_repo_licenses": ["MIT"], "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/chapters/homography/sections/preliminaries.tex", "max_forks_repo_name": "mondrasovic/phd_thesis", "max_forks_repo_head_hexsha": "68a3a6d1687ea43dc6cdfafcd5e6d9ce35f424e8", "max_forks_repo_licenses": ["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.15, "max_line_length": 958, "alphanum_fraction": 0.6825013419, "num_tokens": 999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6008731078484943}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}  %for the align environment\r\n\\usepackage{xfrac}    %for pretty swing fractions\r\n\\usepackage{algorithm}\r\n\\usepackage{algpseudocode}\r\n\\usepackage{mathtools}\r\n\\usepackage{esint}\r\n\r\n\\newcommand*\\VF[1]{\\mathbf{#1}}\r\n\\newcommand*\\dif{\\mathop{}\\!\\mathrm{d}}\r\n\r\n\\DeclarePairedDelimiter{\\abs}{\\lvert}{\\rvert}\r\n\\DeclarePairedDelimiter{\\paren}{\\lparen}{\\rparen}\r\n\r\n\\makeatletter\r\n\\def\\BState{\\State\\hskip-\\ALG@thistlm}\r\n\\makeatother\r\n\r\n\\begin{document}\r\n\r\n\\title{Spectrum and Position Decomposition}\r\n\\author{James T. Matta}\r\n\\date{21 July 2017}\r\n\\maketitle\r\n\\tableofcontents\r\n\r\n\\section{The Algorithm}\r\nFrequently one is presented with a matrix equation that looks something like\r\n\\begin{align}\r\n\tY_{i} = \\sum\\limits_{\\alpha}X_{\\alpha}\\times{}M_{\\alpha,i}\r\n\\end{align}\r\nWhere\r\n\\begin{itemize}\r\n\\item $Y=$ Some know vector of data\r\n\\item $X=$ An unknown vector of multipliers\r\n\\item $M=$ Some matrix\r\n\\end{itemize}\r\n\r\nIn many cases simple linear algebra can be used to solve this problem. However, there are a number of cases where the linear algebra solution is incorrect because it will yield negative values which are unphysical.\r\n\r\nIn these cases the problem can be solved in a numerically stable and positive definite way [Taín and Ott, NIMA 571 (2007) 728–738] as shown in the equation below.\r\n\r\n\\begin{align}\r\n\tf_{\\mu}^{(s+1)} = \\frac{1}{\\sum\\limits_{j}R_{\\mu{}j}} \\sum\\limits_{i}\\frac{f_{\\mu{}}^{(s)} R_{\\mu{}i}d_i}{\\sum\\limits_{\\alpha}R_{\\alpha{}i}f_{\\alpha}^{(s)}} \\\\\r\n\\end{align}\r\nWhere:\r\n\\begin{itemize}\r\n\\item $m=$ Number of response functions\r\n\\item $n=$ Number of data bins\r\n\\item $R=$ Matrix of Response functions $(m \\times n)$\r\n\\item $d=$ Input spectrum vector $(n \\times 1)$\r\n\\item $f^{(s)}=$ Decomposed spectrum in the $i^{th}$ iteration $(1 \\times m)$\r\n\\end{itemize}\r\n\r\nTo simplify this, somewhat, let:\r\n\\begin{align}\r\nr_{\\mu} & = \\sum\\limits_{j}R_{\\mu{},j} \\\\\r\nc & = f^{(s)T}\\times{}R\\\\\r\nm_i &= \\frac{d_i}{c_i}\\\\\r\n\\rho{}_{\\mu{}} & = \\frac{f_{\\mu}^{(s)}}{r_{\\mu}}\r\n\\end{align}\r\n\r\nThen we can rewrite the equation to:\r\n\\begin{align}\r\nf_{\\mu}^{(s+1)} = \\rho{}_{\\mu} R_{\\mu}\\times{}m\r\n\\end{align}\r\n\r\nThe use of this formula can then be expressed as the following two algorithms\r\n\r\n\\begin{algorithm}[H]\r\n\\caption{Decomposition algorithm for converting observed spectra into incident spectra for a given response matrix. $\\odot$ is the element-wise multiplication operator and $\\oslash$ is the element-wise division operator. $m$ is the number of response functions, $n$ is the number of data bins.}\\label{alg_decomp}\r\n\\begin{algorithmic}\r\n\\Procedure{DecomposeSpectrum}{$d, R, f^{(0)}, L, \\tau{}$}\r\n\\BState \\textbf{Input}:\r\n\\State $s \\gets \\text{Input spectrum}$\r\n\\State $R \\gets \\text{Repsonse matrix}$\r\n\\State $f^{(0)} \\gets \\text{Initial decomposition guess}$\r\n\\State $L \\gets \\text{Convergence Limit}$\r\n\\State $\\tau \\gets \\text{Value Threshold For Convergence Test}$\r\n\\BState \\textbf{Start}:\r\n\\State $T \\gets R^T$\r\n\\State $r \\gets \\sum\\limits_{j}R_{\\mu{}j}$\r\n\\State $d \\gets \\textit{False}$\r\n\\For{$i \\gets 0$; $!d$; $i \\gets i+1$}\r\n\\State $c \\gets T \\cdot f^{(i)}$\r\n\\State $m \\gets s \\oslash c$\r\n\\State $\\Gamma \\gets R \\cdot m$\r\n\\State $f^{(i+1)} \\gets f^{(i)} \\oslash r \\odot \\Gamma$\r\n\\State $d \\gets$ \\Call{TestConvergence}{$f^{(i)}, f^{(i+1)}, L, \\tau{}$}\r\n\\EndFor\r\n\\State \\Return{$f^{(i+1)}$}\r\n\\EndProcedure\r\n\\end{algorithmic}\r\n\\end{algorithm}\r\n\r\nWhere Algorithm \\ref{alg_decomp} has the following requirements for its inputs:\r\n\\begin{itemize}\r\n\\item $s_j \\geq 0$; $\\forall{}j \\text{ s.t. } 0\\leq{}j<n$\r\n\\item $\\sum\\limits_{j=0}^{n}s_j \\geq 0$\r\n\\item $f^{(0)}_j > 0$; $\\forall{}j \\text{ s.t. } 0\\leq{}j<m$\r\n\\item $\\sum\\limits_{j=0}^{m}R_{\\mu{}j}$; $\\forall{}\\mu \\text{ s.t. } 0\\leq{}\\mu<n$\r\n\\item $\\sum\\limits_{j=0}^{n}R_{j\\mu{}}$; $\\forall{}\\mu \\text{ s.t. } 0\\leq{}\\mu<m$\r\n\\item $L > 0$\r\n\\item $\\tau > 0$\r\n\\end{itemize}\r\n\r\nTypical values chosen for the convergence limit $L$ are in the range $[0.001, 0.005]$. Typical values chose for the convergence limit testing threshold are in the range $Min(s_j) \\cdot{} [10^{-3}, 10^{-4}]$.\r\n\r\n\\begin{algorithm}[H]\r\n\\caption{Convergence testing algorithm for decomposition.}\\label{alg_conv}\r\n\\begin{algorithmic}\r\n\\Function{TestConvergence}{$f^{(i)}, f^{(i+1)}, L, \\tau{}$}\r\n\\BState \\textbf{Input}:\r\n\\State $f^{(i)} \\gets \\text{Decomposition vector before iteration i}$\r\n\\State $f^{(i+1)} \\gets \\text{Decomposition vector after iteration i}$\r\n\\State $L \\gets \\text{Convergence Limit }$\r\n\\State $\\tau \\gets \\text{Value Threshold For Convergence Test}$\r\n\\BState \\textbf{Start}:\r\n\\For{$j \\gets 0$; $j<Length(f^{(i)})$; $j \\gets j+1$}\r\n\\If{$f^{(i+1)}_j > \\tau$ and $f^{(i)}_j > \\tau$}\r\n\\If{ $\\abs{\\frac{2 \\paren{f^{(i+1)}_j - f^{(i)}_j}}{f^{(i+1)}_j + f^{(i)}_j}} > L$}\r\n\\State \\Return{$\\textit{False}$}\r\n\\EndIf\r\n\\EndIf\r\n\\EndFor\r\n\\State \\Return{$\\textit{True}$}\r\n\\EndFunction\r\n\\end{algorithmic}\r\n\\end{algorithm}\r\n\r\nWhere Algorithm \\ref{alg_conv} has the following requirements for its inputs:\r\n\\begin{itemize}\r\n\\item $f^{(i)}_j > 0$; $\\forall{}j \\text{ s.t. } 0\\leq{}j<m$\r\n\\item $f^{(i+1)}_j > 0$; $\\forall{}j \\text{ s.t. } 0\\leq{}j<m$\r\n\\item $L > 0$\r\n\\item $\\tau > 0$\r\n\\end{itemize}\r\n\r\n\\section{Use Cases}\r\n\\subsection{Energy Decomposition}\r\nDecomposition of a detected gamma-ray energy spectrum is a straightforward use of the algorithm presented above. The spectrum observed in a detector can be expressed as a weighted sum of the detector response to bombardment by mono-energetic gamma rays. This process converts the observed spectrum in a detector into the spectrum incident upon the detector. The necessary reponses can either be measured using a tagged bremsstrahlung facility or simulated (a much easier approach). In the case of simulation one can even simulate only the energy deposition probabilities and then convolve that histogram with a function representing the detectors peak width as a function of energy (as opposed to also simulating the light or charge production of the detector and then simulating its collection.)\r\n\\begin{align}\r\n\td_{i} = \\sum\\limits_{\\alpha}f_{\\alpha}\\times{}R_{\\alpha,i}\r\n\\end{align}\r\nWhere:\r\n\\begin{itemize}\r\n\\item $d_{i}=$ The $i^{th}$ energy bin of the input spectrum\r\n\\item $f_{\\alpha}=$ Decomposition weight for the $\\alpha^{th}$ mono-energetic response function\r\n\\item $R_{\\alpha,i}=$ Observed counts at energy bin $i$ for the $\\alpha^{th}$ response function, a.k.a the Response Matrix\r\n\\end{itemize}\r\n\r\nApplying the algorithm in Section 1 yields the spectrum incident upon the detector.\r\n\r\n\r\n\\subsection{Position Decomposition}\r\nThe spectrum observed at a position $i$ ($d_j$) can be expressed as weighed sum of spectra from a set of sources $S_{j}$ for sources at a set of positions $\\alpha$.\r\n\\begin{align}\r\n\td_{j,i} = \\sum\\limits_{\\alpha}S_{j,\\alpha}\\times{}W_{\\alpha,i}\r\n\\end{align}\r\nWhere:\r\n\\begin{itemize}\r\n\\item $d_{j,i}=$ Energy bin $j$ of the decomposed spectrum at position $i$\r\n\\item $S_{j,\\alpha}=$ Energy bin $j$ of the source spectrum for source $\\alpha$\r\n\\item $W_{\\alpha,i}=$ Contribution weight of source $\\alpha$ at position $i$\r\n\\end{itemize}\r\n\r\nThe $W_{\\alpha,i}$, essentially solid angle contributions, can be defined as follows:\r\n\\begin{equation}\r\n\tW_{\\alpha,i} = \\oiint\\limits_{D} \\oiint\\limits_{S} \\frac{SN(x_s, x_d)\\cdot{}Atten(x_s, x_d)}{4\\pi{} \\mid{} \\vec{x_d}-\\vec{x_s} \\mid{}^2} \\dif \\vec{x_s} \\dif \\vec{x_d}\r\n\\end{equation}\r\n\\begin{equation}\r\n\tF(x_s, x_d) =\r\n\t\\begin{cases}\r\n\t\t0 & \\vec{N_D}(x_d)\\cdot{}(\\vec{x_s}-\\vec{x_d}) \\leq{} 0\\\\\r\n\t\t1 & \\text{otherwise}\r\n\t\\end{cases}\r\n\\end{equation}\r\nWhere:\r\n\\begin{itemize}\r\n\\item $x_s=$ Position detector to the source.\r\n\\item $x_d=$ Position detector to the volume.\r\n\\item $D=$ Surface of the detector segment being considered\r\n\\item $S=$ Surface/Volume/Whatever of the source being considered.\r\n\\item $\\vec{N_D}(x_d)=$ Vector normal to the surface of the detector at $\\vec{x_d}$, pointing outward.\r\n\\item $Atten(x_s, x_d)=$ Function accounting for shielding attenuation between $\\vec{x_s}$ and $\\vec{x_d}$. This function is one if only air is between the source and detector.\r\n\\end{itemize}\r\n\r\nConsidering a single energy bin $j$ gives an equation that is equivalent to the energy decomposition equation:\r\n\\begin{align}\r\n\td_{i} = \\sum\\limits_{\\alpha}S_{\\alpha}\\times{}W_{\\alpha,i}\r\n\\end{align}\r\nWhere:\r\n\\begin{itemize}\r\n\\item $d_{i}=$ Single energy bin of the decomposed spectrum at position $i$\r\n\\item $S_{\\alpha}=$ Single energy bin of the source spectrum for source $\\alpha$\r\n\\item $W_{\\alpha,i}=$ Contribution weight of source $\\alpha$ at position $i$\r\n\\end{itemize}\r\n\r\nTherefore a set of spectra taken at multiple positions can be decomposed into contributions from a finite number of stationary sources, a single energy bin at a time, using the same solution we used for energy decomposition. By analogy, the list of weights at each position for a given source would constitute a response function, the set of bin contents for a given energy for the decomposed spectra are the input spectrum, and the set of bin contents for each source would be the ``decomposed spectrum''. Repeating this at every energy bin would build up the spectrum from each source.\r\n\r\n\\end{document}", "meta": {"hexsha": "95988be8bcb378720543b98cae2158e100638441", "size": 9200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/algorithm_usecases/algorithm_usecases.tex", "max_stars_repo_name": "jmatta1/DecompLib", "max_stars_repo_head_hexsha": "59c3592388a6a6d167214882e6a0f38c7b1d7cc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-04-17T14:27:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-16T11:32:22.000Z", "max_issues_repo_path": "doc/algorithm_usecases/algorithm_usecases.tex", "max_issues_repo_name": "jmatta1/DecompLib", "max_issues_repo_head_hexsha": "59c3592388a6a6d167214882e6a0f38c7b1d7cc2", "max_issues_repo_licenses": ["MIT"], "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/algorithm_usecases/algorithm_usecases.tex", "max_forks_repo_name": "jmatta1/DecompLib", "max_forks_repo_head_hexsha": "59c3592388a6a6d167214882e6a0f38c7b1d7cc2", "max_forks_repo_licenses": ["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.7711442786, "max_line_length": 797, "alphanum_fraction": 0.6920652174, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214155, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6008731078484943}}
{"text": "\\subsection{Inequalities, Intervals and Solving Basic Inequalities}\\label{subsec:IneqInterval}\r\n\r\n\\subsection*{Inequality Notation}\r\nRecall that we use the symbols $<,>,\\leq,\\geq$ when writing an inequality.\r\nIn particular,\r\n\\begin{itemize}\r\n\t\\item $a<b$ means $a$ is to the \\ifont{left} of $b$ (that is, \r\n\t\t\t\t$a$ is \\ifont{strictly less} than $b$),\r\n\t\\item $a\\leq b$ means $a$ is to the \\ifont{left of or the same} \r\n\t\t\t\tas $b$ (that is, $a$ is \\ifont{less than or equal} to $b$),\r\n\t\\item $a>b$ means $a$ is to the \\ifont{right} of $b$ (that is, $a$ \r\n\t\t\t\tis \\ifont{strictly greater} than $b$),\r\n\t\\item $a\\geq b$ means $a$ is to the \\ifont{right of or the same} \r\n\t\t\t\tas $b$ (that is, $a$ is \\ifont{greater than or equal} to $b$).\r\n\\end{itemize}\r\n\r\n\\noindent To keep track of the difference between the symbols, some students use the following mnemonic.\\\\\r\n\r\n\\begin{formulabox}[Mnemonic]\r\nThe $<$ symbol looks like a slanted \\ifont{L} which stands for ``\\ifont{L}ess than''.\r\n\\end{formulabox}\r\n\r\n\\bigskip\r\n\r\n\\begin{example}{Inequalities}{Inequalities}\r\nThe following expressions are true: \r\n\\[ 1<2,\\quad \r\n   -5<-2,\\quad \r\n   1\\leq 2,\\quad\r\n   1\\leq 1,\\quad\r\n   4\\geq\\pi>3,\\quad\r\n   7.23\\geq -7.23.\r\n\\]\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\nThe real numbers are ordered and are often illustrated using the \\dfont{real number line}:\r\n\\[\r\n\\includegraphics[width=5in]{images/real-number-line} \r\n\\]\r\n\r\n \r\n\\subsection*{Intervals}\r\nAssume $a,b$ are real numbers with $a<b$ (i.e., $a$ is strictly \r\nless than $b$). An \\dfont{interval} is a set of every real number \r\nbetween two indicated numbers and may or may not contain the two numbers themselves.\r\nWhen describing intervals we use both round brackets and square brackets.\r\n\r\n(1) Use of round brackets in intervals: $(~,~)$.\r\nThe notation \\dfont{(a,b)} is what we call the \\dfont{open interval from a to b} \r\nand consists of all the numbers between $a$ and $b$, but does \\ifont{not} include $a$ or $b$.\r\nUsing set-builder notation we write this as:\r\n\\[ (a,b)=\\{x\\in\\mathbb{R}\\, \\ssep \\,a<x<b\\} \\]\r\nWe read $\\{x\\in\\mathbb{R}\\,\\ssep \\,a<x<b\\}$ as ``the set of real numbers $x$ such that $x$ is greater than $a$ and less than $b$''. On the real number line we represent this with the following diagram:\r\n\\[\r\n\\includegraphics[width=2in]{images/interval-open} \r\n\\]\r\nNote that the circles on $a$ and $b$ are not shaded in, we call these \\dfont{open circles} and use them to denote that $a$,$b$ are \\ifont{omitted} from the set.\r\n\r\n(2) Use of square brackets in intervals: $[~,~]$.\r\nThe notation \\dfont{[a,b]} is what we call the \\dfont{closed interval from a to b} \r\nand consists of all the numbers between $a$ and $b$ and \\ifont{including} $a$ and $b$.\r\nUsing set-builder notation we write this as\r\n\\[ [a,b]=\\{x\\in\\mathbb{R}\\,|\\,a\\leq x\\leq b\\} \\]\r\nOn the real number line we represent this with the following diagram:\r\n\\[\r\n\\includegraphics[width=2in]{images/interval-closed} \r\n\\]\r\nNote that the circles on $a$ and $b$ are shaded in, we call these \\dfont{closed circles} and use them to denote that $a$ and $b$ are \\ifont{included} in the set.\r\n\r\nTo keep track of when to shade a circle in, you may find the following mnemonic useful:\\\\\r\n\r\n\\begin{formulabox}[Mnemonic]\r\nThe round brackets $(,)$ and non-shaded circle both form an ``O'' shape which stands for ``Open and Omit''.\r\n\\end{formulabox}\r\n\r\nTaking combinations of round and square brackets, we can write different \r\npossible types of intervals. \r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{formulabox}[Interval Notation]\r\n\r\nLet $a$ and $b$ be real numbers with $a<b$.\\\\\r\n\r\n\\vspace{2mm}\r\n\t\\begin{tabular}{|c|c|c|} \\hline\r\n\t\t&& \\\\ [-1em]\r\n\t\tSet of Real Numbers & Interval Notation &  Region on the Real Number Line  \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\,\\ssep \\,a<x<b\\}$ \\\\ \\hfill}& \\shortstack{$(a,b)$ \\\\ \\hfill} & \r\n\t\t\r\n\t\t  \\includegraphics[width=1.8in]{images/interval-open}  \\\\ \\hline\r\n\t\t\r\n\t\t& &  \\\\\r\n\t\t\\shortstack{$\\{x\\,\\ssep \\,a\\leq x<b\\}$ \\\\ \\hfill}& \\shortstack{$[a,b)$ \\\\ \\hfill} & \r\n\t\t\r\n\t\t \\includegraphics[width=1.8in]{images/interval-1} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\,\\ssep \\,a<x\\leq b\\}$ \\\\ \\hfill}&\\shortstack{$(a,b]$ \\\\ \\hfill} & \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-2} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\,\\ssep \\,a\\leq x \\leq b\\}$ \\\\ \\hfill}& \\shortstack{$[a,b]$ \\\\ \\hfill}& \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-closed} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t& & \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\, x<b\\}$ \\\\ \\hfill}& \\shortstack{$(-\\infty,b)$ \\\\ \\hfill}& \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-5} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\, x \\leq b\\}$ \\\\ \\hfill} & \\shortstack{$(-\\infty,b]$ \\\\ \\hfill}& \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-6}\r\n\t\t\r\n\t\t  \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\, x>a\\}$ \\\\ \\hfill}& \\shortstack{$(a,\\infty)$ \\\\ \\hfill}& \r\n\t\t\r\n\t\t \\includegraphics[width=1.8in]{images/interval-3} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\, x \\geq a \\}$ \\\\ \\hfill}& \\shortstack{$[a,\\infty)$ \\\\ \\hfill} & \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-4}\r\n\t\t\r\n\t\t \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\mathbb R$ \\\\ \\hfill}& \\shortstack{$(-\\infty,\\infty)$ \\\\ \\hfill} & \r\n\t\t\r\n\t\t\\includegraphics[width=1.8in]{images/interval-7}\r\n\t\t\r\n\t\t   \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\\end{tabular}\r\n\t\r\n\\end{formulabox}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n%\\[\r\n%\\begin{array}{|c|c|c|}\r\n%\\hline\r\n%&& \\\\\r\n%(a,b)=\\{x\\in\\mathbb{R}\\,\\ssep \\,a<x<b\\} \r\n%\t& [a,b]=\\{x\\in\\mathbb{R}\\, \\ssep \\,a\\leq x\\leq b\\} \r\n%\t& [a,b)=\\{x\\in\\mathbb{R}\\, \\ssep \\,a\\,\\leq x<b\\}\\\\\r\n%\t~&~&~\\\\\r\n%\\includegraphics[width=1.8in]{images/interval-open} \r\n%\t& \\includegraphics[width=1.8in]{images/interval-closed}\r\n%\t& \\includegraphics[width=1.8in]{images/interval-1}\\\\\r\n%\r\n%\\hline\r\n%&& \\\\\r\n%(a,b]=\\{x\\in\\mathbb{R}\\, \\ssep \\,a<x\\leq b\\}\r\n%\t& (a,\\infty)=\\{x\\in\\mathbb{R}\\, \\ssep \\,x>a\\} \r\n%\t& [a,\\infty)=\\{x\\in\\mathbb{R}\\, \\ssep \\,x\\geq a\\}\\\\\r\n%\t~&~&~\\\\\r\n%\\includegraphics[width=1.8in]{images/interval-2} \r\n%\t& \\includegraphics[width=1.8in]{images/interval-3}\r\n%\t& \\includegraphics[width=1.8in]{images/interval-4}\\\\\r\n%\r\n%\\hline\r\n%&& \\\\\r\n%(-\\infty,b)=\\{x\\in\\mathbb{R}\\, \\ssep \\,x<b\\} \r\n%\t& (-\\infty,b]=\\{x\\in\\mathbb{R}\\, \\ssep \\,x\\leq b\\}\r\n%\t& (-\\infty,\\infty)=\\mathbb{R}=\\mbox{all real numbers}\\\\\r\n%\t~&~&~\\\\\r\n%\\includegraphics[width=1.8in]{images/interval-5} \r\n%\t& \\includegraphics[width=1.8in]{images/interval-6}\r\n%\t& \\includegraphics[width=1.8in]{images/interval-7}\\\\\r\n%\\hline\r\n%\\end{array}\r\n%\\]\r\n\r\n\\textit{Note}: Any set which is bound at positive and/or negative infinity is an open interval.\\\\\r\n\r\nFor an example, consider the sets of real numbers described below.\r\n\r\n\\begin{example}{Interval Notation}{IntervalNotation}\r\n\t\\begin{tabular}{|c|c|c|} \\hline\r\n\t\t\r\n\t\tSet of Real Numbers & Interval Notation &  Region on the Real Number Line  \\\\\r\n\t\t\\hline\r\n\t\t& &  \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\,1\\leq x< 3\\}$ \\\\ \\hfill} & \\shortstack{$[1,3)$ \\\\ \\hfill} & \r\n\t\t  \\includegraphics[width=2.3in]{images/interval-1ex} \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep \\,-1\\leq x \\leq 4\\}$ \\\\ \\hfill}& \\shortstack{$[-1,4]$ \\\\ \\hfill} & \r\n\t\t\\includegraphics[width=2.3in]{images/interval-closedex}  \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\r\n\t\t\\shortstack{$\\{x\\, \\ssep  \\, x \\leq 5 \\}$ \\\\ \\hfill} & \\shortstack{$(-\\infty, 5]$ \\\\ \\hfill} &\r\n\t\t\\includegraphics[width=2.3in]{images/interval-6ex}  \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\t&  & \\\\\r\n\t\t\\shortstack{$\\{x\\, \\ssep  \\, x > -2 \\}$ \\\\ \\hfill} & \\shortstack{$(-2, \\infty)$ \\\\ \\hfill} &  \t\r\n\t\\includegraphics[width=2.3in]{images/interval-3ex}  \\\\\r\n\t\t\\hline\r\n\t\t\r\n\t\\end{tabular}\r\n\\end{example}\t\r\n\r\n\r\nWe will often have occasion to combine sets.  There are two basic ways to combine sets:  \\textbf{intersection}\r\nand \\textbf{union}.  We define both of these concepts below.\r\n\r\n\\begin{definition}   \r\n\t\r\n\tSSuppose $A$ and $B$ are two sets.\r\n\t\t\r\n\t\t\\begin{itemize}\r\n\t\t\t\r\n\t\t\t\\item The \\textbf{intersection}\\index{set ! intersection}\\index{intersection of two sets} of $A$ and $B$:  $A \\cap B = \\{ x \\, \\ssep  \\, x \\in A \\, \\text{and} \\,\\, x \\in B \\}$\r\n\t\t\t\r\n\t\t\t\\item The \\textbf{union}\\index{set ! union}\\index{union of two sets} of $A$ and $B$: $A \\cup B = \\{ x \\, \\ssep  \\, x \\in A \\, \\text{or} \\,\\, x \\in B \\, \\, \\text{(or both)} \\}$\r\n\t\t\t\r\n\t\t\\end{itemize}\r\n\t\t\r\n\\end{definition}\r\n\t\r\nSaid differently, the intersection of two sets is the overlap of the two sets -- the elements which the sets have in common.  The union of two sets consists of the totality of the elements in each of the sets, collected together.\t\r\n\t\r\n\\begin{example}{Union and Intersection}{UI1}\t\r\nIf $A = \\{ 1,2,3 \\}$ and $B = \\{2,4,6 \\}$, then $A \\cap B = \\{2\\}$ and $A \\cup B = \\{1,2,3,4,6\\}$. \r\n\\end{example}\r\n\r\n\\begin{example}{Union and Intersection}{UI2}\r\n  If $A = [-5,3)$ and $B = (1, \\infty)$, find $A \\cap B$ and $A\\cup B$.  \r\n\\end{example}\r\n\\begin{solution}\r\n\tTo find $A\\cap B$, we shade  the overlap of the two and obtain $A \\cap B = (1,3)$. \\\\\r\n\t$$\\includegraphics[scale=0.2]{images/interval-unionex}$$\r\n\t\r\n\t To find $A \\cup B$, we shade each of $A$ and $B$ and describe the resulting shaded region to find  $A \\cup B = [-5,\\infty)$.\\\\\r\n\t $$\\includegraphics[scale=0.2]{images/interval-unionex2}$$\r\n\t \r\n\\end{solution}\t\r\n\r\n\r\n\r\nWhile both intersection and union are important, we have more occasion to use union in this text than intersection, simply because most of the sets of real numbers we will be working with are either intervals or are unions of intervals, as the following example illustrates.\r\n\r\n%%%%%%%%%%%%%%%\r\n%%%%%%%%%%%%\r\n\\begin{example}{Union}{union}\r\n\t\r\nExpress the following sets of numbers using interval notation.\\\\\r\n\t\r\n\t\\begin{tabular}{lcl}\r\n\t\t\t(a) \\hspace{2mm}  $\\{ x \\, \\ssep  \\, x \\leq -2 \\, \\, \\text{or} \\, \\,  x \\geq 2 \\}$\r\n\t\t\t& \\hspace{2cm}\r\n\t\t\t& (b) \\hspace{2mm} $\\{ x \\, \\ssep  \\, x \\neq 3 \\}$ \\\\\r\n\t\t\t&& \\\\ [-1em]\r\n\t\t\t(c) \\hspace{2mm} $\\{ x \\, \\ssep  \\, x \\neq \\pm 3 \\}$\r\n\t\t\t&\r\n\t\t\t&(d) \\hspace{2mm} $\\{ x \\, \\ssep  \\, -1 < x \\leq 3 \\,\\, \\text{or} \\,\\, x = 5\\}$ \\\\\r\n\t\\end{tabular} \t\t\r\n\t\t\r\n\\end{example}\t\r\n\\begin{solution} \r\n\t\r\n\t\\begin{enumerate}\r\n\t\t\r\n\t\t\\item  The best way to proceed here is to graph the set of numbers on the number line and glean the answer from it.  The inequality $x \\leq -2$ corresponds to the interval $(-\\infty, -2]$ and the inequality $x \\geq 2$ corresponds to the interval $[2, \\infty)$.  Since we are looking to describe the real numbers $x$ in one of these \\textit{or} the other, we have $\\{ x \\, | \\, x \\leq -2 \\, \\, \\text{or} \\, \\,  x \\geq 2 \\} = (-\\infty, -2] \\cup [2, \\infty)$.\\\\\r\n\t\t $$\\includegraphics[scale=0.3]{images/intervals-ex1}$$\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\\item For the set $\\{ x \\, | \\, x \\neq 3 \\}$, we shade the entire real number line except $x=3$, where we leave an open circle.  This divides the real number line into two intervals, $(-\\infty, 3)$ and $(3,\\infty)$.  Since the values of $x$ could be in either one of these intervals \\textit{or} the other, we have that $\\{ x \\, | \\, x \\neq 3 \\} = (-\\infty, 3) \\cup (3,\\infty)$\\\\\r\n\t\t$$\\includegraphics[scale=0.3]{images/intervals-ex2}$$\r\n\t\t\r\n\t\r\n\t\t\t\r\n\t\t\r\n\t\t\\item  For the set $\\{ x \\, | \\, x \\neq \\pm 3 \\}$, we proceed as before and exclude both $x=3$ and $x=-3$ from our set.  This breaks the number line into \\textit{three} intervals, $(-\\infty, -3)$, $(-3,3)$ and $(3, \\infty)$.   Since the set describes real numbers which come from the first, second \\textit{or} third interval, we have $\\{ x \\, | \\, x \\neq \\pm 3 \\} = (-\\infty, -3) \\cup (-3,3) \\cup (3, \\infty)$.\\\\\r\n\t\t$$\\includegraphics[scale=0.3]{images/intervals-ex3}$$\r\n\t\t\r\n\t\t\r\n\t\r\n\t\t\r\n\t\t\\item  Graphing the set $\\{ x \\, | \\, -1 < x \\leq 3 \\,\\, \\text{or} \\,\\, x = 5\\}$, we get one interval, $(-1,3]$ along with a single number, or point, $\\{ 5\\}$.  While we \\textit{could} express the latter as $[5,5]$ (Can you see why?), we choose to write our answer as $\\{ x \\, | \\, -1 < x \\leq 3 \\,\\, \\text{or} \\,\\, x = 5\\} = (-1,3] \\cup \\{ 5\\}$.\\\\\r\n\t\t$$\\includegraphics[scale=0.3]{images/intervals-ex4}$$\r\n\t\t\r\n\r\n\t\\end{enumerate}\r\n\t\r\n\t\t\r\n\\end{solution}\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\\subsection*{Inequality Rules}\\label{sec:Inequalities}\r\nBefore solving inequalities, we start with the properties and rules of inequalities.\\\\\r\n\r\n%\\begin{definition}{Inequality Rules}{Inequalityrules}\r\n\\begin{formulabox}[Inequality Rules]\r\n{\\bf Add/subtract a number to both sides:}\\vspace{-0.2cm}\r\n\\begin{itemize}\r\n\t\\item If $a<b$, then $a+c<b+c$ and $a-c<b-c$.\r\n\\end{itemize}\r\n{\\bf Adding two inequalities of the \\red{same} type:}\\vspace{-0.2cm}\r\n\\begin{itemize}\r\n\t\\item If $a<b$ and $c<d$, then $a+c<b+d$.\\\\\r\n\t\t\t\t\\ifont{Add the left sides together, add the right sides together.}\r\n\\end{itemize}\r\n{\\bf Multiplying by a \\red{positive} number:}\\vspace{-0.2cm}\r\n\\begin{itemize}\r\n\t\\item Let $c>0$. If $a<b$, then $c\\cdot a<c\\cdot b$.\r\n\\end{itemize}\r\n{\\bf Multiplying by a \\red{negative}  number:}\\vspace{-0.2cm}\r\n\\begin{itemize}\r\n\t\\item Let $c<0$. If $a<b$, then $c\\cdot a>c\\cdot b$.\\\\\r\n\t\t\\ifont{Note that we reversed the inequality symbol!}\r\n\\end{itemize}\r\n\\end{formulabox}\r\n%\\end{definition}\r\n\r\nSimilar rules hold for each of $\\leq$, $>$ and $\\geq$.\r\n\r\n\r\n\\subsection*{Solving Basic Inequalities}\r\nWe can use the inequality rules to solve some simple inequalities. \\\\\r\n\r\n\\begin{example}{Basic Inequality}{BasicInequality}\r\nFind all values of $x$ satisfying\r\n\\[ 3x+1>2x-3. \\]\r\nWrite your answer in both interval and set-builder notation.\r\nFinally, draw a number line indicating your solution set.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nSubtracting $2x$ from both sides gives $x+1>-3$.\r\nSubtracting $1$ from both sides gives $x>-4$.\r\nTherefore, the solution is the interval $(-4,\\infty)$.\r\nIn set-builder notation the solution may be written as $\\{x\\in\\mathbb{R}\\, \\ssep \\,x>-4\\}$.\r\nWe illustrate the solution on the number line as follows:\r\n\\[\r\n\\includegraphics[width=2in]{images/ineq-ex-1}\r\n\\]\r\n\\end{solution}\r\n\r\nSometimes we need to split our inequality into two cases as the next example demonstrates. \\\\\r\n\r\n\\begin{example}{Double Inequalities}{DoubleInequalities}\r\nSolve the inequality \r\n\\[ 4>3x-2\\geq 2x-1. \\]\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nWe need both $\\,\\,4>3x-2\\,\\, $ and $\\,\\,3x-2\\geq 2x-1\\,\\,$ to be true:\r\n\\[\\begin{array}{rclcrcl}\r\n\t4 & > & 3x-2 & \\hspace{5mm} \\text{and} \\hspace{5mm} & \\hspace{3mm} 3x-2 & \\geq & 2x-1\\\\\r\n\t6 & > & 3x & & x-2 & \\geq & -1\\\\\r\n\t2 & > & x &  & x & \\geq & 1\\\\\r\n\tx & < & 2 & & x & \\geq & 1\\\\\r\n\\end{array}\\]\r\nThus, we require $\\,\\,x\\geq 1\\,\\,$ but also $\\,\\,x<2\\,\\,$ to be true. \r\nThis gives all the numbers between $1$ and $2$, including $1$ but not including $2$.\r\nThat is, the solution to the inequality $\\,\\,4>3x-2\\geq 2x-1\\,\\,$ is the interval $[1,2)$.\r\nIn set-builder notation this is the set $\\,\\,\\{x\\in\\mathbb{R}\\, \\ssep \\,1\\leq x<2\\}$.\r\n\\end{solution}\r\n\r\n\\bigskip\r\n\r\n\\begin{example}{Positive Inequality}{4x-inequality}\r\nSolve $4x-x^2>0$.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nWe provide two methods to solve this inequality.\r\n\r\n\\bigskip\r\n\\noindent\r\n\\ifont{First method.} Factor $4x-x^2$ as $x(4-x)$.  The product of two numbers\r\nis positive when either both are positive or both are negative, i.e., if\r\neither $x>0$ and $4-x>0$, or else $x<0$ and $4-x<0$.  The latter alternative\r\nis impossible, since if $x$ is negative, then $4-x$ is greater than 4, and\r\nso cannot be negative.  As for the first alternative, the condition $4-x>0$\r\ncan be rewritten (adding $x$ to both sides) as $4>x$, so we need:\r\n$x>0$ and $4>x$ (this is sometimes combined in the form $4>x>0$, or,\r\nequivalently, $0<x<4$).  In interval notation, this says that the solution\r\nis the interval $(0,4)$.\r\n\r\n\\bigskip\r\n\\noindent\r\n\\ifont{Second method.}  Write $4x-x^2$ as $-(x^2-4x)$, and then complete\r\nthe square, obtaining \r\n$$-\\Bigl((x-2)^2-4\\Bigr)=4-(x-2)^2.$$  \r\nFor this to be positive we need $(x-2)^2<4$, which means that $x-2$ must be less\r\nthan 2 and greater than $-2$:  $-2<x-2<2$.  Adding 2 to everything gives\r\n$0<x<4$.  \r\n\r\n\\bigskip\r\n\\noindent\r\nBoth of these methods are equally correct; you may use either\r\nin a problem of this type.\r\n\\end{solution}\r\n\r\nWe next present another method to solve more complicated looking inequalities.\r\nIn the next example we will solve a rational inequality by using \r\na number line and test points. We follow the guidelines below.\\\\\r\n\r\n\\begin{formulabox}[Guidelines for Solving Rational Inequalities]\r\n\\begin{enumerate}\\itemsep0em \r\n\t\\item Move everything to \\ifont{one side} to get a $0$ on the other side.\r\n\t\\item If needed, combine terms using a \\ifont{common denominator}.\r\n\t\\item \\ifont{Factor} the numerator and denominator.\r\n\t\\item Identify points where either the numerator or denominator is $0$. Such points\r\n\t\t\t\tare called \\dfont{split points}.\r\n\t\\item Draw a \\ifont{number line} and indicate your split points on the number line. \r\n\t\t\t\tDraw \\ifont{closed/open circles} for each split point depending on \r\n\t\t\t\tif that split point satisfies the inequality (division by zero is not allowed).\r\n\t\\item The split points will split the number line into subintervals. For each \r\n\t\t\t\tsubinterval pick a \\ifont{test point} and see if the expression in Step 3 \r\n\t\t\t\tis positive or negative. Indicate this with a $+$ or $-$ symbol on the \r\n\t\t\t\tnumber line for that subinterval.\r\n\t\\item Now write your answer in set-builder notation. Use the union symbol \r\n\t\t\t\t$\\cup$ if you have multiple intervals in your solution.\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Rational Inequality}{RationalInequality1}\r\nWrite the solution to the following inequality using interval notation:\r\n\\[\\frac{2-x}{2+x}\\geq 1.\\]\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nOne method to solve this inequality is to multiply both sides by $2+x$, but because we do not know if $2+x$ is positive or negative we must split it into two cases (\\ifont{Case 1:} $2+x>0$ and \\ifont{Case 2:} $2+x<0$).\r\n\r\nInstead we follow the guidelines for solving rational inequalities:\r\n\\[\r\n\\begin{array}{rcl}\r\n\\mbox{Start with original problem:}& ~ & \\displaystyle{\\frac{2-x}{2+x}\\geq 1}\\\\\r\n\\\\\r\n\\mbox{Move everything to one side:}& ~ & \\displaystyle{\\frac{2-x}{2+x}-1 \\geq 0}\\\\\r\n\\\\\r\n\\mbox{Find a common denominator:}& ~ & \\displaystyle{\\frac{2-x}{2+x}-\\frac{2+x}{2+x} \\geq 0}\\\\\r\n\\\\\r\n\\mbox{Combine fractions:}& ~ & \\displaystyle{\\frac{(2-x)-(2+x)}{2+x} \\geq 0}\\\\\r\n\\\\\r\n\\mbox{Expand numerator:}& ~ & \\displaystyle{\\frac{2-x-2-x}{2+x} \\geq 0}\\\\\r\n\\\\\r\n\\mbox{Simplify numerator:}& ~ & \\displaystyle{\\frac{-2x}{2+x} \\geq 0\\quad(*)}\\\\\r\n\\end{array}\r\n\\]\r\nNow we have the numerator and denominator in fully factored form.\r\nThe split points are $x=0$ (makes the numerator $0$) and $x=-2$ (makes the denominator $0$).\r\nLet us draw a number line with the split points indicated on it:\r\n\\[\r\n\\includegraphics[width=2in]{images/ineq-rational-1}\r\n\\]\r\nThe point $x=0$ is included since if we sub $x=0$ into (*) we get $0\\geq 0$ which is true.\r\nThe point $x=-2$ is not included since we cannot divide by zero.\r\nWe indicate this with open/closed circles on the number line (remember that open means omit):\r\n\\[\r\n\\includegraphics[width=2in]{images/ineq-rational-2}\r\n\\]\r\nNow choosing a test point from each of the three subintervals we can determine if the expression $-2x /(2+x) $ is positive or negative.\r\nWhen $x=-3$, it is negative.\r\nWhen $x=-1$, it is positive.\r\nWhen $x=1$, it is negative.\r\nIndicating this on the number line gives:\r\n\\[\r\n\\includegraphics[width=2in]{images/ineq-rational-3}\r\n\\]\r\nSince we wish to solve $\\displaystyle{\\frac{-2x}{2+x}\\geq 0}$, we look at where the $+$ signs are and shade that area on the number line:\r\n\\[\r\n\\includegraphics[width=2in]{images/ineq-rational-4}\r\n\\]\r\nSince there is a closed circle at $0$, we include it.\r\nTherefore, the solution is $(-2,0]$.\r\n\\end{solution}\r\n\r\n\\begin{example}{Rational Inequality}{RationalInequality2}\r\nWrite the solution to the following inequality using interval notation:\r\n\\[ \\frac{2}{x+2}>{3}{x+3}. \\]\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nWe provide a brief outline of the solution.\r\nBy subtracting $(3x+3)$ from both sides and using a common denominator of $x+2$,\r\nwe can collect like terms and simplify to get:\r\n\\[ \\frac{-(3x^2+9x+4)}{x+2}>0. \\]\r\nThe denominator is zero when $x=-2$.\r\nUsing the quadratic formula, the numerator is zero when \r\n$x=(-9\\pm\\sqrt{33})/6$ (these two numbers are approximately $-2.46$ and $-0.54$).\r\nSince the inequality uses ``$>$'' and $0>0$ is false, \r\nwe do not include any of the split points in our solution.\r\nAfter choosing suitable test points and determining the sign of \r\n$-(3x^2+9x+4)/(x+2)$ we have\r\n\\[\r\n\\includegraphics[width=2.5in]{images/ineq-ex-2}\r\n\\]\r\nLooking where the $+$ symbols are located gives the solution:\r\n$$\\left(-\\infty,\\frac{-9-\\sqrt{33}}{6}\\right) \\cup\\left(-2,\\frac{-9+\\sqrt{33}}{6}\\right).$$\r\nWhen writing the final answer we use \\ifont{exact} expressions for numbers in mathematics, not \r\napproximations (unless stated otherwise).\r\n\\end{solution}\r\n", "meta": {"hexsha": "4945fafc0d8ebc4bfeb679412906b63bd358e318", "size": 20965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-4-inequalities-and-intervals.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-1-4-inequalities-and-intervals.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-1-4-inequalities-and-intervals.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.1138059701, "max_line_length": 461, "alphanum_fraction": 0.6306701646, "num_tokens": 7261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6008730998583689}}
{"text": "\\section{Interpreter}\n\n\\subsection{Testclass}\n\n\\begin{lstlisting}[language=Scala]\nimport Interpreter.evalBExpr\nimport scala.collection.mutable.Map\n\nobject Test {\n  def main(args: Array[String]) {\n    val bExpr = DyaBExpr(CondAnd, LitBExpr(true), LitBExpr(false)); //Comparision of true AND false\n    println(evalBExpr(bExpr, Map[String, Int]())); //Returns false\n\n    //Command to test interpreter\n    val intDiv = CpsCmd(List(\n      AssiCmd(\"q\", LitAExpr(0)),\n      AssiCmd(\"r\", IdAExpr(\"m\")),\n      WhileCmd(\n        RelBExpr(GreaterEq, IdAExpr(\"r\"), IdAExpr(\"n\")),\n        CpsCmd(List(\n          AssiCmd(\"q\", DyaAExpr(Plus, IdAExpr(\"q\"), LitAExpr(1))),\n          AssiCmd(\"r\", DyaAExpr(Minus, IdAExpr(\"r\"), IdAExpr(\"n\")))))),\n      SkipCmd));\n    val map = Map[String, Int](\"m\" -> 5, \"n\" -> 2) // initial values for m and n\n    println(\"map = \" + map);\n    println(\"res = \" + Interpreter.interpret(intDiv, map))\n  }\n}\n\\end{lstlisting}\n\n\\subsection{Syntax definition}\n\n\\begin{lstlisting}[language=Scala]\n//Abstract class with only case objects. Case objects can be used if there are cases which take no parameter.\nabstract class RelOperator\ncase object LessEq extends RelOperator\ncase object GreaterEq extends RelOperator\n\nabstract class BoolOperator \ncase object CondAnd extends BoolOperator \ncase object CondOr extends BoolOperator \n\nabstract class BoolExpr\ncase class LitBExpr(value: Boolean) extends BoolExpr\ncase class NegBExpr(expr: BoolExpr) extends BoolExpr\ncase class DyaBExpr(operator: BoolOperator, op1: BoolExpr, op2: BoolExpr) extends BoolExpr // dyadic, means two\ncase class RelBExpr(relOp: RelOperator, aExp1: ArithExpr, aExp2: ArithExpr) extends BoolExpr\n\n//Also working with different objects, no classes\nabstract class ArithOperator\ncase object Times extends ArithOperator\ncase object Div extends ArithOperator\ncase object Mod extends ArithOperator\ncase object Plus extends ArithOperator\ncase object Minus extends ArithOperator\n\nabstract class ArithExpr\ncase class LitAExpr(value: Int) extends ArithExpr\ncase class IdAExpr(ident: String) extends ArithExpr\ncase class DyaAExpr(op: ArithOperator, exp1: ArithExpr, exp2: ArithExpr) extends ArithExpr\n\nabstract class Command\ncase class AssiCmd(ident: String, aExpr: ArithExpr) extends Command\ncase class CpsCmd(commands: List[Command]) extends Command\ncase class WhileCmd(bExpr: BoolExpr, command: Command) extends Command\ncase object SkipCmd extends Command\n\\end{lstlisting}\n\n\\subsection{Interpreter}\n\n\\begin{lstlisting}[language=Scala]\n//import scala.collection.Map  //This would be the immutable map (default)\nimport scala.collection.mutable.Map //We need the mutable map\n\nobject Interpreter {\n\n  type Value = Int\n  type State = Map[String, Value]\n\n  //Boolean Expressions\n  def evalBExpr(expr: BoolExpr, state: State): Boolean =\n    expr match {\n      case LitBExpr(value) => value\n      case NegBExpr(op) => !evalBExpr(op, state)\n      case DyaBExpr(CondAnd, op1, op2) => evalBExpr(op1, state) && evalBExpr(op2, state)\n      case DyaBExpr(CondOr, op1, op2) => evalBExpr(op1, state) || evalBExpr(op2, state)\n      case RelBExpr(LessEq, aExp1, aExp2) => evalAExpr(aExp1, state) <= evalAExpr(aExp2, state)\n      case RelBExpr(GreaterEq, aExp1, aExp2) => evalAExpr(aExp1, state) >= evalAExpr(aExp2, state)\n    }\n\n  //Arithmetic Expressions\n  def evalAExpr(aExpr: ArithExpr, state: State): Int =\n    aExpr match {\n      case LitAExpr(value) => value\n      case IdAExpr(ident) => state(ident)\n      case DyaAExpr(Times, exp1, exp2) => evalAExpr(exp1, state) * evalAExpr(exp2, state)\n      case DyaAExpr(Div, exp1, exp2) => evalAExpr(exp1, state) / evalAExpr(exp2, state)\n      case DyaAExpr(Mod, exp1, exp2) => evalAExpr(exp1, state) % evalAExpr(exp2, state)\n      case DyaAExpr(Plus, exp1, exp2) => evalAExpr(exp1, state) + evalAExpr(exp2, state)\n      case DyaAExpr(Minus, exp1, exp2) => evalAExpr(exp1, state) - evalAExpr(exp2, state)\n    }\n\n  //Interpreter to interpret different commands\n  def interpret(commands: Command, state: State): State =\n    commands match {\n      case SkipCmd => state\n      case AssiCmd(ident, aExpr) => state(ident) = evalAExpr(aExpr, state); state\n      case CpsCmd(Nil) => state\n      case CpsCmd(x :: xs) => interpret(CpsCmd(xs), interpret(x, state))\n      case WhileCmd(bExpr, command) => if (evalBExpr(bExpr, state)) interpret(command, state) else state\n    }\n}\n\\end{lstlisting}\n\n\\clearpage", "meta": {"hexsha": "3b8d9ef63deee1be31810fcfabc8bf7ed8319eb3", "size": 4392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TSM_AdvPrPa/Excercises/Scala/01_Interpreter.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/Scala/01_Interpreter.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/Scala/01_Interpreter.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": 38.1913043478, "max_line_length": 111, "alphanum_fraction": 0.7188069217, "num_tokens": 1256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6007658254520728}}
{"text": "\\section{Approximation Rates for ReLU$^k$ Networks}\\label{relu-result-section}\nIn this section, we consider approximation by neural networks with activation function $$\\sigma_k(x) = [\\max(0,x)]^k$$ for $k=\\mathbb{Z}_{\\geq 0}$ (here we set $0^0 = 0$, i.e. $\\sigma_0(x)$ is the Heaviside function). Specifically, we consider approximating a function $f$ by elements of the set\n\\begin{equation}\n \\Sigma^k_{n} = \\left\\{\\sum_{i=1}^n a_i\\sigma_k(\\omega_i\\cdot x + b_i):~\\omega_i\\in S^{d-1},~b_i\\in \\mathbb{R},~a_i\\in\\mathbb{C}\\right\\},\n\\end{equation}\nwhere we allow the coefficients $a_i$ to have arbitrarily large $\\ell^1$-norm.\n\nWe will use Lemma \\ref{fourier-representation-lemma} to obtain an improved approximation rate for such networks on the spectral Barron space $\\mathcal{B}^m(\\Omega)$. To do this, we introduce a multiscale approximation of the complex exponentials $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}$ using splines. We begin by recalling some facts about spline interpolation which will be important in the following analysis. We will refer to \\cite{devore1993constructive} for most of this material.\n\nInstead of working directly with $\\sigma_k$ it is much more convenient to introduce the cardinal B-splines\n\\begin{equation}\\label{card-b-splines-def}\n N_k(x) = \\frac{1}{k!}\\sum_{i=0}^{k+1}(-1)^i\\binom{k+1}{i}\\sigma_k(x-i) \\in \\Sigma_{k+1}^k,\n\\end{equation}\nwhich are compactly supported on $[0,k+1]$. \n\nLet $\\mathcal{S}^k_\\lambda$ denote the Schoenberg space of piecewise degree $k$ splines on $\\mathbb{R}$ with knots at $\\lambda \\mathbb{Z}$. It is well known that every spline $S\\in\\mathcal{S}^k_1$ can be written as\n\\begin{equation}\\label{eq_963}\n S(x) = \\sum_{j=-\\infty}^\\infty c_j(S)N_k(x-j),\n\\end{equation}\nwhere $c_j$ are the de Boor-Fix functionals (see \\cite{devore1993constructive}, section 5.3). Since the knots of the spline are all evenly spaced, the functionals $c_j(S)$ are all translations of the functional $c_0$, i.e.\n\\begin{equation}\\label{eq_967}\n c_j(S) = c_0(S(\\cdot-j)).\n\\end{equation}\nMoreover, consider change the spacing between the knots, i.e. consider $\\mathcal{S}^k_\\lambda$. Then, if $S\\in \\mathcal{S}^k_\\lambda$, $S(\\lambda x)\\in \\mathcal{S}^k_1$ and equations \\eqref{eq_963} and \\eqref{eq_967} imply that\n\\begin{equation}\n S(\\lambda x) = \\sum_{j=-\\infty}^\\infty c_j(S(\\lambda\\cdot))N_k(x-j),\n\\end{equation}\nso that\n\\begin{equation}\n S(x) = \\sum_{j=-\\infty}^\\infty c_{j,\\lambda}(S)N_k(\\lambda^{-1}x-j),\n\\end{equation}\nwhere the functionals $c_{j,\\lambda}$ are given by $c_{j,\\lambda}(S) = c_0(S(\\lambda(\\cdot - j)))$.\n\nNow, we see from \\cite{devore1993constructive}, Lemma 4.1 of Chapter 5, that\n\\begin{equation}\\label{eq_983}\n |c_{j,\\lambda}(S)| \\leq C\\|S\\|_{L^\\infty([\\lambda j, \\lambda (j+k+1)])},\n\\end{equation}\nfor a fixed constant $C$. Thus, by the Hahn-Banach theorem, we can extend the de Boor-Fix functionals $c_{j,\\lambda}$ to functionals $\\gamma_{j,\\lambda}$ on $L^\\infty([\\lambda j, \\lambda (j+k+1)])$ which satisfy the same bound. This allows us to define the quasi-interpolation operators\n\\begin{equation}\\label{quasi-interpolation}\n Q_\\lambda(f) = \\sum_{j=-\\infty}^\\infty \\gamma_{j,\\lambda}(f)N_k(\\lambda^{-1}x-j),\n\\end{equation}\nwhich are bounded in $L^\\infty$ (uniformly in $\\lambda$) and satisfy $Q(S) = S$ for all splines $S\\in \\mathcal{S}^k_\\lambda$ (see \\cite{devore1993constructive}, section 5.4). Note that here and in what follows, we suppress the dependence on $k$ of the operators $Q_\\lambda$ and the de Boor-Fix functions $\\gamma_{j,\\lambda}$ to simplify notation.\n\nWe are now in the position to introduce the following multiscale piecewise degree $k$ approximation to $e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}$. We write\n\\begin{equation}\\label{multiscale-approx}\n e^{2\\pi {\\mathrm{i}\\mkern1mu}  x} = Q_{2^{-1}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}) + \\sum_{l=2}^\\infty [Q_{2^{-l}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}) - Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})] = \\sum_{l=1}^\\infty h_l(x),\n\\end{equation}\nwhere\n\\begin{equation}\n h_l(x) = Q_{2^{-l}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}) - Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}),\n\\end{equation}\nfor $l > 1$ and $h_1(x) = Q_{2^{-1}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})$. Since we clearly have $\\mathcal{S}^k_{2^{-(l-1)}} \\subset \\mathcal{S}^k_{2^{-l}}$, we see that\n$$Q_{2^{-l}}(Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})) = Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}),$$ \nso that we can rewrite $h_l$ as\n\n\\begin{equation}\\label{eq_995}\nh_l(x) = Q_{2^{-l}}\\left(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x} - Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})\\right) = Q_{2^{-l}}(e_{l-1}(x)) = \\sum_{j=-\\infty}^\\infty \\alpha_{j,l}N_k(2^{l}x-j),\n\\end{equation}\nwhere the error $e_{l-1}$ is given by $e_{l-1}(x) = e^{2\\pi {\\mathrm{i}\\mkern1mu}   x} - Q_{2^{-(l-1)}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})$ and the coefficients $\\alpha_{j,l}$ are given by $\\alpha_{j,l} = \\gamma_{j,2^{-l}}(e_{l-1})$.\n\nWe have the following lemma concerning this this piecewise degree $k$ approximation of $e^{2\\pi {\\mathrm{i}\\mkern1mu}   x}$.\n\\begin{lemma}\\label{multilevel-spline}\n The above expansion of $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}$ has the following properties.\n \\begin{itemize}\n  \\item $\\|e_l\\|_{\\infty} \\lesssim 2^{-(k+1)l}$.\n  \\item The coefficients $\\alpha_{j,l}$ in equation \\eqref{eq_995} satisfy $|\\alpha_{j,l}| \\lesssim 2^{-(k+1)l}$.\n  \\item The series in \\eqref{multiscale-approx} converges in $W^{m,\\infty}(\\mathbb{R})$ for $0 \\leq m \\leq k$.\n \\end{itemize}\n\\end{lemma}\nNote that the implied constants in the above lemma and the following proof only depend upon $k$ and not upon $l$ or $j$.\n\\begin{proof}\n The first statement follows immediately from Theorem 4.5 in \\cite{devore1993constructive}, since $e_l(x) = e^{2\\pi {\\mathrm{i}\\mkern1mu}   x} - Q_{2^{-l}}(e^{2\\pi {\\mathrm{i}\\mkern1mu}   x})$ and $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}\\in W^{k+1,\\infty}(\\mathbb{R})$.\n \n%  Let $z\\in \\mathbb{R}$. We will show that $|e_{l-1}(z)| \\lesssim 2^{-(k+1)l}$. Choose an index $j$ so that $z\\in I^k_{l,j}:=[2^{-l}j, 2^{-l}(j+k+1)]$. \n%  \n%  We first note that\n%  \\begin{equation}\\label{eq_1018}\n%   e_l(x) = e^{2\\pi {\\mathrm{i}\\mkern1mu}   x} - \\sum_{s=1}^{l}h_s(x) = e_{l-1}(x) - Q_{2^{-l}}(e_{l-1}(x)).\n%  \\end{equation}\n%  Since $\\|e^{2\\pi {\\mathrm{i}\\mkern1mu} x}\\|_{W^{k+1,\\infty}(\\mathbb{R})}\\lesssim 1$ (here the constant only depends upon $k$), we get\n%  \\begin{equation}\n%   \\|e^{2\\pi {\\mathrm{i}\\mkern1mu}   x} - T_{l,j}^k(x)\\|_{L^\\infty(I^k_{l,j})} \\lesssim |I^k_{l,j}|^{k+1}\\lesssim 2^{-(k+1)l},\n%  \\end{equation}\n%  where $T_{l,j}^k(x)$ is the degree $k$ Taylor polynomial of $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}$ centered at the left endpoint $2^{-l}j$. We thus obtain\n%  \\begin{equation}\n%   \\left\\|e_{l-1}(x) - S_{l,j}^k(x)\\right\\|_{L^\\infty(I^k_{l,j})} \\lesssim 2^{-(k+1)l},\n%  \\end{equation}\n%  where\n%  \\begin{equation}\n%   S_{l,j}^k(x) = T_{l,j}^k(x) - \\sum_{s=1}^{l-1}h_s(x) \\in \\mathcal{S}^k_{2^{-l}},\n%  \\end{equation}\n%  since $T_{l,j}^k(x)$ is a polynomial and $h_s(x) \\in \\mathcal{S}^k_{2^{-s}}\\subset \\mathcal{S}^k_{2^{-l}}$ (since $s < l$).\n%  \n%  As $Q_{2^{-l}}$ leaves the space $\\mathcal{S}^k_{2^{-l}}$ invariant, i.e. $S_{l,j}^k(x) = Q_{2^{-l}}(S_{l,j}^k(x))$, we obtain\n%  \\begin{equation}\n%  \\begin{split}\n%   \\|e_{l-1}(x) - Q_{2^{-l}}(e_{l-1}(x))\\|_{L^\\infty(I^k_{l,j})} &\\leq \\|e_{l-1}(x) - S_{l,j}^k(x)\\|_{L^\\infty(I^k_{l,j})} + \\|Q_{2^{-l}}(S_{l,j}^k(x) - e_{l-1}(x))\\|_{L^\\infty(I^k_{l,j})} \\\\\n%   & \\leq (1 + \\|Q_{2^{-l}}\\|_{L^\\infty\\rightarrow L^\\infty})\\|e_{l-1}(x) - S_{l,j}^k(x)\\|_{L^\\infty(I^k_{l,j})} \\lesssim 2^{-(k+1)l}.\n%   \\end{split}\n%  \\end{equation}\n%  Here it is important to note that the operator norm $\\|Q_{2^{-l}}\\|_{L^\\infty\\rightarrow L^\\infty}$ is bounded independently of $l$ since the quasi-interpolation operators $Q_\\lambda$ are bounded uniformly in $\\lambda$.\n%  \n%  By equation \\eqref{eq_1018} we then obtain\n%  \\begin{equation}\n%   \\|e_l(x)\\|_{L^\\infty(I^k_{l,j})} = \\|e_{l-1}(x) - Q_{2^{-l}}(e_{l-1}(x))\\|_{L^\\infty(I^k_{l,j})} \\lesssim 2^{-(k+1)l}.\n%  \\end{equation}\n%  Since $z\\in I^k_{l,j}$, we thus have $|e_{l}(z)| \\lesssim 2^{-(k+1)l}$ and the first statement follows.\n \n For the second statement, we note that\n \\begin{equation}\n  |\\alpha_{j,l}| = |\\gamma_{j,2^{-l}}(e_{l-1})| \\leq C\\|e_{l-1}\\|_{L^\\infty(\\mathbb{R})} \\lesssim 2^{-(k+1)(l-1)} \\lesssim 2^{-(k+1)l},\n \\end{equation}\n where the first inequality is due to the fact that $\\gamma_{j,2^{-j}}$ is a Hahn-Banach extension of the de Boor-Fix functional $c_{j,2^{-j}}$ which satisfies \\eqref{eq_983}.\n \n Finally, note that since $\\|e_l\\|_{L^\\infty(\\mathbb{R})} \\lesssim 2^{-(k+1)l}\\rightarrow 0$, we have that the series in \\eqref{multiscale-approx} converges in $L^\\infty(\\mathbb{R})$ to $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}$. We now claim that\n \\begin{equation}\n  \\|h_l\\|_{W^{m,\\infty}(\\mathbb{R})} \\lesssim 2^{-(k+1-m)l}.\n \\end{equation}\n First, we note that simply by taking derivatives, we get\n \\begin{equation}\n  \\|N_p(2^lx-j)\\|_{W^{m,\\infty}(\\mathbb{R}, dx)} \\lesssim 2^{ml}.\n \\end{equation}\n Second, the B-splines $N_k(2^lx-j)$ are compactly supported and each point $x$ is covered by at most $p+1$ of them. Hence\n \\begin{equation}\n  \\|h_l\\|_{W^{m,\\infty}} = \\left\\|\\sum_{j=-\\infty}^\\infty \\alpha_{j,l}N_k(2^{l}x-j)\\right\\|_{W^{m,\\infty}} \\leq (k+1)\\sup_{j}|\\alpha_{j,l}|\\|N_k(2^lx-j)\\|_{W^{m,\\infty}(\\mathbb{R}, dx)} \\lesssim 2^{-(k+1-m)l},\n \\end{equation}\n since $\\alpha_{j,l}\\lesssim 2^{-(k+1)l}$.\n \n This means that if $m\\leq k$, then $\\sum_{l=1}^\\infty \\|h_l\\|_{W^{m,\\infty}}$ is summable and hence the sum in \\eqref{multiscale-approx} converges in $W^{m,\\infty}(\\mathbb{R})$. Clearly, its limit must be the same as the limit in $L^\\infty$ and thus it converges to $e^{2\\pi {\\mathrm{i}\\mkern1mu} x}$.\n\\end{proof}\n\nCombining the multiscale expansion \\eqref{multiscale-approx} with Lemma \\ref{fourier-representation-lemma} and some ideas from \\cite{makovoz1996random}, we obtain the following theorem.\n\n\\begin{theorem}\\label{piecewise-poly-approx-theorem}\n Let $\\Omega = [0,1]^d$ and $f\\in \\mathcal{B}^s(\\Omega)$ for $s \\geq \\frac{1}{2}$. Let $k \\in \\mathbb{Z}_{\\geq 0}$ and $m\\geq 0$, with $m\\leq s-\\frac{1}{2}$ and $m < k + \\frac{1}{2}$. Then for $n\\geq 2$,\n \\begin{equation}\\label{bound-equation}\n  \\inf_{f_n\\in \\Sigma^k_{n}}\\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}^s}n^{-t}\\log(n)^q,\n \\end{equation}\n where the exponent $t$ is given by\n $$t = \\min\\left(\\frac{1}{2}+\\frac{2(s-m)-1}{2(d+1)}, k-m+1\\right) = \\begin{cases}\n            \\frac{1}{2}+\\frac{2(s-m)-1}{2(d+1)} & \\text{if}~s < (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2} \\\\\n            k-m+1 & \\text{if}~s \\geq (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2}\n                                        \\end{cases}\n$$\n and $q$ is given by $$q = \\begin{cases}\n            0 & \\text{if}~s < (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2} \\\\\n            1 & \\text{if}~s > (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2}\\\\\n            1 + (k-m+\\frac{1}{2}) & \\text{if}~s = (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2}\n           \\end{cases}.$$\n\\end{theorem}\nBefore beginning the proof, we remark that all of the implied constants in the $\\eqsim$, $\\gtrsim$, and $\\lesssim$ can be seen to depend only on $s,k,m,d,L$ and $\\delta$ ($L$ and $\\delta$ chosen during the course of the proof), but not on $f$ or $n$. Further, we remark that the suppressed constant may depend exponentially on the dimension, i.e. as $A^d$ for some $A$. Finally, note that the maximal possible rate of $s-m+1$, which is achieved for sufficiently large $s$, is exactly the best achievable rate in one dimension. In Theorem \\ref{relu-lower-bound} we use this fact the show that the rate of $s-m+1$ cannot be improved upon no matter how large $s$ is. It is an open problem whether such a rate can be obtained with less smoothness.\n\nComparing with other results in the literature, we see for instance that the results in \\cite{klusowski2018approximation} apply to the cases $k=1,m=0$ (ReLU) and $k=2,m=0$ (ReLU$^2$). Furthermore, in \\cite{CiCP-28-1707}, the general case $0\\leq m\\leq k$ is considered. In all of these cases the rate previously obtained was $O(n^{-\\frac{1}{2}-\\frac{1}{d}})$, while the rates in Theorem \\ref{piecewise-poly-approx-theorem} are $O(n^{-\\frac{1}{2}-\\frac{2k+1}{2(d+1)}})$, which are significantly better for large $k$ and large $d$. However, the rates in Theorem \\ref{piecewise-poly-approx-theorem} were obtained without the $\\ell^1$-norm bound on the coefficients as in \\cite{klusowski2018approximation} and \\cite{CiCP-28-1707}. It is open whether the same rates can also be obtained with $\\ell^1$-bounded  coefficients.\n\n\\begin{proof}\n   Choose $L > 1$. Using Corollary \\ref{fourier-representation-lemma}, we see that there exists an $a\\in L^{-1}[0,1]^d$ and coefficients $a_\\xi$ such that\n \\begin{equation}\\label{eq_675}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d} a_\\xi (1+|a+\\xi|)^{-s}e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a + \\xi)\\cdot x}\n \\end{equation}\n and $\\sum |a_\\xi|\\lesssim \\|f\\|_{\\mathcal{B}^s}$. Here the suppressed constant depends potentially exponentially on the dimension, by the remarks in the previous section.\n \n We expand $e^{2\\pi {\\mathrm{i}\\mkern1mu}   (a+\\xi)\\cdot x}$ using \\eqref{multiscale-approx} to get\n \\begin{equation}\n  e^{2\\pi {\\mathrm{i}\\mkern1mu}  (a + \\xi)\\cdot x} = \\sum_{l=1}^\\infty h_l((a + \\xi)\\cdot x),\n \\end{equation}\n which holds in $W^{m,\\infty}(\\mathbb{R}^d)$ and thus in $H^m(\\Omega)$ since $\\Omega$ is bounded. \n \n Expanding $h_l$ using equation \\eqref{eq_995} and plugging this into equation \\eqref{eq_675}, we obtain (in $H^m(\\Omega)$)\n \\begin{equation}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}\\sum_{l=1}^\\infty \\sum_{j=-\\infty}^\\infty a_\\xi \\alpha_{j,l} (1+|a+\\xi|)^{-s}N_k(2^l(a+\\xi)\\cdot x - j).\n \\end{equation}\n \n Now, since $x\\in \\Omega$, $\\Omega$ is a bounded set, and $N_k$ is compactly supported, the number of non-zero terms in the inner-most sum above is finite. Indexing the values of $j$ for which $N_k(2^l(a+\\xi)\\cdot x - j)$ is non-zero for $x\\in \\Omega$ as $j_1,...,j_{n_{\\xi, l}}$, we get\n \\begin{equation}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}\\sum_{l=1}^\\infty \\sum_{p=1}^{n_{\\xi,l}} a_\\xi \\alpha_{j_p,l} (1+|a+\\xi|)^{-s} \\psi_{\\xi,l,p}(x),\n \\end{equation}\n where\n \\begin{equation}\\label{psi-definition}\n  \\psi_{\\xi,l,p}(x) = N_k(2^l(a+\\xi)\\cdot x - j_p).\n \\end{equation}\n A straightforward calculation utilizing the compact support of $N_k$ implies that\n \\begin{equation}\\label{eq_454}\n  \\|\\psi_{\\xi,l,p}\\|_{H^m(\\Omega)} \\lesssim 2^{l\\left(m-\\frac{1}{2}\\right)}(1 + |\\xi|)^{\\left(m-\\frac{1}{2}\\right)}.\n \\end{equation}\n Further, note that the number of terms $n_{\\xi,l}$ satisfies\n \\begin{equation}\\label{eq_452}\n  n_{\\xi,l} \\lesssim 2^l(1 + |\\xi|).\n \\end{equation}\nThis follows since for $x\\in \\Omega$, $y = 2^l(a + \\xi)\\cdot x$ takes on values in an interval of length at most $2^l|a + \\xi|\\text{diam}(\\Omega)$ and $N_k$ has compact support of size $k+1$.\n\nLet $\\delta > 0$ to be specified later. We proceed to write\n\\begin{equation}\\label{eq_458}\n  f(x) = \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}\\sum_{l=1}^\\infty \\sum_{p=1}^{n_{\\xi,l}} a_\\xi 2^{-l(1+\\delta)}(1+|\\xi|)^{-1} \\phi_{\\xi,l,p}(x),\n \\end{equation}\n where \n \\begin{equation}\\label{eq_463}\n  \\phi_{\\xi,l,p}(x) = 2^{l(1+\\delta)}(1+|\\xi|)\\alpha_{j_p,l} (1+|a+\\xi|)^{-s} \\psi_{\\xi,l,p}(x).\n \\end{equation}\n Using \\eqref{eq_463} and \\eqref{eq_454} combined with the bound on $|\\alpha_{j,l}|$ from Lemma \\ref{multilevel-spline}, we calculate\n \\begin{equation}\\label{eq_470}\n  \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} \\lesssim 2^{-l(k-m+\\frac{1}{2}-\\delta)}(1+|\\xi|)^{m-s+\\frac{1}{2}}.\n \\end{equation}\n \n We now observe that  by \\eqref{eq_452} the $\\ell^1$ norm of the coefficients of the $\\phi_{\\xi,l,p}$ in \\eqref{eq_458} is bounded, namely\n \\begin{equation}\n \\begin{split}\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}\\sum_{l=1}^\\infty \\sum_{p=1}^{n_{\\xi,l}} |a_\\xi 2^{-l(1+\\delta)}(1+|\\xi|)^{-1}| =\n  \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}|a_\\xi|\\sum_{l=1}^\\infty n_{\\xi,l}2^{-l(1+\\delta)}(1+|\\xi|)^{-1} &\\lesssim \\sum_{\\xi\\in L^{-1}\\mathbb{Z}^d}|a_\\xi|\\sum_{l=1}^\\infty 2^{-l\\delta} \\\\\n  & \\lesssim \\delta^{-1}\\|f\\|_{\\mathcal{B}^m(\\Omega)}.\n  \\end{split}\n \\end{equation}\n We can now apply Theorem 1 in \\cite{makovoz1996random} (note that this theorem still applies even though the coefficients in \\eqref{eq_458} are potentially complex) to $f$ to conclude that there exists an\n \\begin{equation}\n  f_n = \\sum_{i=1}^n a_i\\phi_{\\xi_i,l_i,p_i}(x)\n \\end{equation}\n with $\\sum_{i=1}^n|a_i| \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}$ such that\n \\begin{equation}\\label{bound_equation}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\delta^{-1}\\|f\\|_{\\mathcal{B}^s(\\Omega)}\\epsilon_n(\\Phi)n^{-\\frac{1}{2}},\n \\end{equation}\n where $\\Phi = \\{\\phi_{\\xi,l,p}\\}$ and $\\epsilon_n(\\Phi) = \\inf\\{\\epsilon > 0:\\Phi~\\text{is covered by $n$ balls of diameter $\\epsilon$}\\}$ is the $n$-covering width of $\\Phi$. \n \n By choosing $\\delta = k-m+\\frac{1}{2} > 0$ we obtain the result at the endpoint $s = m+\\frac{1}{2}$ (where the desired rate is $O(n^{-\\frac{1}{2}})$) since by \\eqref{eq_470} $$\\epsilon_n(\\Phi)\\leq \\epsilon_1(\\Phi)\\leq \\sup \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)}\\lesssim 1.$$\n \n For larger $s$ we need to obtain a sharper bound on $\\epsilon_n(\\Phi)$. We do this by considering the covering number \n \\begin{equation}\n  N_\\Phi(\\epsilon) = \\min\\{n:~\\text{there is a covering of $\\Phi$ by $n$ balls of diameter $\\epsilon$}\\},\n \\end{equation}\n and noting that by definition $\\epsilon_n(\\Phi) = \\inf\\{\\epsilon > 0: N_\\Phi(\\epsilon) \\leq n\\}$. \n \n Given $\\epsilon > 0$, we cover the set $\\Phi$ by a single ball of radius $\\frac{\\epsilon}{2}$ centered at the origin, and cover each of the remaining elements with additional balls. This implies that\n \\begin{equation}\n  N_\\Phi(\\epsilon) \\leq 1 + \\left|\\left\\{\\phi_{\\xi,l,p}: \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} > \\frac{\\epsilon}{2}\\right\\}\\right|.\n \\end{equation}\n We proceed to count the number of $\\phi_{\\xi,l,p}$ with large norm. This process is messy but relatively straightforward.\n \n By \\eqref{eq_470} we must count the indices $\\xi\\in L^{-1}\\mathbb{Z}^d,l\\in \\mathbb{Z}_{>0}$ and $s=1,...,n_{\\xi,l}$ for which\n \\begin{equation}\n  \\epsilon \\lesssim 2^{-l(k-m+\\frac{1}{2}-\\delta)}(1+|\\xi|)^{m-s+\\frac{1}{2}}.\n \\end{equation}\n We observe that this condition implies that we must choose $\\xi$ so that $(1+|\\xi|)^{m-s+\\frac{1}{2}} \\gtrsim \\epsilon$ and $l$ so that\n \\begin{equation}\\label{eq_506}\n  2^{l(k-m+\\frac{1}{2}-\\delta)} \\lesssim \\epsilon^{-1}(1+|\\xi|)^{m-s+\\frac{1}{2}}.\n \\end{equation}\n In addition, for each of these values of $\\xi$ and $l$, we get $n_{\\xi,l}\\lesssim 2^l(1+|\\xi|)$ differt values of $p$. Combining these observations, we see that\n \\begin{equation}\n  \\left|\\left\\{\\phi_{\\xi,l,p}: \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} > \\frac{\\epsilon}{2}\\right\\}\\right| \\lesssim \\sum_{\\substack{\\xi\\in L^{-1}\\mathbb{Z}^d\\\\|\\xi|\\leq R}} (1+|\\xi|) \\sum_{l\\in L(\\epsilon,\\xi)} 2^l,\n \\end{equation}\n where $R \\lesssim \\epsilon^{\\frac{1}{m-s+\\frac{1}{2}}}$ (note that here we require $m-s+\\frac{1}{2} < 0$) and $L(\\epsilon,\\xi)$ consists of indices $l$ which satisfy \\eqref{eq_506}. Taking a logarithm, the set $L(\\epsilon,\\xi)$ can be characterized by\n \\begin{equation}\n  l\\leq \\left(k-m+\\frac{1}{2}-\\delta\\right)^{-1}\\left(-\\log(\\epsilon) + \\left(m-s+\\frac{1}{2}\\right)\\log(1+|\\xi|)\\right) + C\n \\end{equation}\n for some constant $C$. Using this bound on $l$, combined with the fact that $\\sum_{l=1}^k 2^l \\lesssim 2^k$, we get\n \\begin{equation}\n  \\sum_{l\\in L(\\epsilon,\\xi)} 2^l \\lesssim \\epsilon^{\\frac{-1}{k-m+\\frac{1}{2}-\\delta}}(1+|\\xi|)^{\\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}}.\n \\end{equation}\n So we get\n \\begin{equation}\\label{eq_524}\n  \\left|\\left\\{\\phi_{\\xi,l,p}: \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} > \\frac{\\epsilon}{2}\\right\\}\\right| \\lesssim \\epsilon^{\\frac{-1}{k-m+\\frac{1}{2}-\\delta}} \\sum_{\\substack{\\xi\\in L^{-1}\\mathbb{Z}^d\\\\|\\xi|\\leq R}} (1+|\\xi|)^{1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}}.\n \\end{equation}\n For the final sum, we distinguish between two cases. \n \n First, if $m-s+\\frac{1}{2} > -(d+1)\\left(k-m+\\frac{1}{2}\\right)$, then we can choose a fixed $\\delta = \\delta(s,m,k,d) > 0$ small enough so that \n \\begin{equation}\n  1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta} > -d.\n \\end{equation}\n In this case, by comparing the sum over the lattice $L^{-1}\\mathbb{Z}^d$ to an integral, the sum in \\eqref{eq_524} satisfies\n \\begin{equation}\n  \\sum_{\\substack{\\xi\\in L^{-1}\\mathbb{Z}^d\\\\|\\xi|\\leq R}} (1+|\\xi|)^{1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}} \\lesssim R^{d+1+\\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}} \\lesssim \\epsilon^{\\frac{d+1}{m-s+\\frac{1}{2}} + \\frac{1}{k-m+\\frac{1}{2}-\\delta}},\n \\end{equation}\n since $R\\lesssim \\epsilon^{\\frac{1}{m-s+\\frac{1}{2}}}$. Combining this with \\eqref{eq_524} we get\n \\begin{equation}\n  \\left|\\left\\{\\phi_{\\xi,l,p}: \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} > \\frac{\\epsilon}{2}\\right\\}\\right| \\lesssim\\epsilon^{\\frac{d+1}{m-s+\\frac{1}{2}}}.\n \\end{equation}\n This implies that for small $\\epsilon$, $N_\\Phi(\\epsilon)\\lesssim \\epsilon^{\\frac{d+1}{m-s+\\frac{1}{2}}}$ and so\n \\begin{equation}\n  \\epsilon_n(\\Phi) \\lesssim n^{\\frac{m-s+\\frac{1}{2}}{d+1}}.\n \\end{equation}\n Plugging this into \\eqref{bound_equation}, we get\n \\begin{equation}\\label{eq_549}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\delta(s,m,k,d)^{-1}\\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{\\frac{m-s+\\frac{1}{2}}{d+1}}n^{-\\frac{1}{2}}\\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-\\frac{1}{2}-\\frac{s-m-\\frac{1}{2}}{d+1}}.\n \\end{equation}\n\n \n Next, if $m-s+\\frac{1}{2} \\leq -(d+1)\\left(k-m+\\frac{1}{2}\\right)$, then for any $\\delta > 0$ we get\n \\begin{equation}\n  1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta} < -d.\n \\end{equation}\n In this case, the sum in \\eqref{eq_524} is summable and we get\n \\begin{equation}\n  \\sum_{\\substack{\\xi\\in L^{-1}\\mathbb{Z}^d\\\\|\\xi|\\leq R}} (1+|\\xi|)^{1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}} \\lesssim 1\n \\end{equation}\n if $m-s+\\frac{1}{2} < -(d+1)\\left(k-m+\\frac{1}{2}\\right)$, and in the special case where $m-s+\\frac{1}{2} = -(d+1)\\left(k-m+\\frac{1}{2}\\right)$, we get\n\\begin{equation}\n  \\sum_{\\substack{\\xi\\in L^{-1}\\mathbb{Z}^d\\\\|\\xi|\\leq R}} (1+|\\xi|)^{1 + \\frac{m-s+\\frac{1}{2}}{k-m+\\frac{1}{2}-\\delta}} \\lesssim \\delta^{-1}.\n \\end{equation}\n Combining this with \\eqref{eq_524} we get\n \\begin{equation}\n  \\left|\\left\\{\\phi_{\\xi,l,p}: \\|\\phi_{\\xi,l,p}\\|_{H^m(\\Omega)} > \\frac{\\epsilon}{2}\\right\\}\\right| \\lesssim \\epsilon^{\\frac{-1}{k-m+\\frac{1}{2}-\\delta}},\n \\end{equation}\n where we need an extra factor of $\\delta^{-1}$ in the special case where $m-s+\\frac{1}{2} = -(d+1)\\left(k-m+\\frac{1}{2}\\right)$.\n This implies that up to a factor of $\\delta^{-(k-m+\\frac{1}{2}-\\delta)}$ in this special case, we have\n \\begin{equation}\n  \\epsilon_n(\\Phi) \\lesssim n^{-(k-m+\\frac{1}{2}-\\delta)}.\n \\end{equation}\n Using \\eqref{bound_equation}, we get\n \\begin{equation}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\delta^{-1}\\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-(k-m+\\frac{1}{2}-\\delta)}n^{-\\frac{1}{2}},\n \\end{equation}\n where the power of $\\delta$ is replaced by $-1-(k-m+\\frac{1}{2}-\\delta)$ in the endpoint case. Finally, optimizing over $\\delta$, we get\n \\begin{equation}\\label{eq_580}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-(k-m+1)}\\log(n),\n \\end{equation}\n where in the endpoint case the logarithm is taken to the power $1 + (k-m+\\frac{1}{2})$.\n \n Combining the results of \\eqref{eq_580} and \\eqref{eq_549} with the previously discussed result at $s = m + \\frac{1}{2}$, we get\n \\begin{equation}\n  \\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}^s(\\Omega)}n^{-t}\\log(n)^q,\n \\end{equation}\n where $t = \\min\\left(\\frac{1}{2}+\\frac{s-m-\\frac{1}{2}}{d+1}, k-m+1\\right)$ and $q$ is given by\n \\begin{equation}\n q = \\begin{cases}\n            0 & \\text{if}~t < k-m+1 \\\\\n            1 & \\text{if}~t < \\frac{1}{2}+\\frac{2(s-m)-1}{2(d+1)}\\\\\n            1 + (k-m+\\frac{1}{2}) & \\text{otherwise}\n           \\end{cases}.\n \\end{equation}\n This completes the proof since \\eqref{psi-definition}, \\eqref{eq_463}, and \\eqref{card-b-splines-def} imply that $\\phi_{\\xi,l,p}\\in \\Sigma_{k+1}^k$.\n\n\\end{proof}\n\nIn the case where $f$ is highly smooth, i.e. $f\\in \\mathcal{B}^s(\\Omega)$ with $s > (d+1)(k-m-\\frac{1}{2})+m+\\frac{1}{2}$, we obtain, up to a logarithmic factor, an approximation rate of $O(n^{-k-1+m})$ in $H^m(\\Omega)$. We state this as a separate theorem.\n\\begin{theorem}\\label{high-smoothness-approximation}\n Let $\\Omega = [0,1]^d$, $k \\in \\mathbb{Z}_{\\geq 0}$ and $m\\geq 0$, with $m < k + \\frac{1}{2}$. Suppose that $f\\in \\mathcal{B}^s(\\Omega)$ for $s$ sufficiently large, specifically $$s > (d+1)\\left(k-m+\\frac{1}{2}\\right) + m + \\frac{1}{2}.$$ Then for $n\\geq 2$,\n \\begin{equation}\\label{bound-equation}\n  \\inf_{f_n\\in \\Sigma^k_{n}}\\|f - f_n\\|_{H^m(\\Omega)} \\lesssim \\|f\\|_{\\mathcal{B}^s}n^{m-(k+1)}\\log(n).\n \\end{equation}\n\\end{theorem}\n", "meta": {"hexsha": "b669039c84daae0babae8d44956d74188c7ab563", "size": 24900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ReLUkApprox.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/ReLUkApprox.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/ReLUkApprox.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": 73.6686390533, "max_line_length": 817, "alphanum_fraction": 0.6303212851, "num_tokens": 9999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6007658088792107}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Bi-Nilplex Numbers}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn exo-2 real number has the form\n\\begin{equation}\n    a_{0} + a_{1} W + a_{2} X + a_{3} WX\n\\end{equation}\nThese follow from a parabolic Cayley-Dickson construct on the exo-1 reals.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Arithmetic Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Conjugate Operations}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Differential Operators}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...", "meta": {"hexsha": "80ab6bc246fb91de12905b7112aea4671012bd3c", "size": 2097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/F.tex", "max_stars_repo_name": "meirizarrygelpi/plexifications", "max_stars_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_stars_repo_licenses": ["MIT"], "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/F.tex", "max_issues_repo_name": "meirizarrygelpi/plexifications", "max_issues_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_issues_repo_licenses": ["MIT"], "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/F.tex", "max_forks_repo_name": "meirizarrygelpi/plexifications", "max_forks_repo_head_hexsha": "0976772cc56b7f4b6cb9856c6d2bb052fed0b525", "max_forks_repo_licenses": ["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.6590909091, "max_line_length": 80, "alphanum_fraction": 0.1959942775, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.6584174938590246, "lm_q1q2_score": 0.6007639316553355}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 23}\n\\subsection{Lecture Notes - Hamiltonian Mechanics}\n\\subsubsection{Hamilton's Equations \\& Properties} \\}\nA particle slides on a helical wire defined by $z = k\\theta$, $r = R$. If we use $\\theta$ as the generalized coordinate, the generalized momentum is $p = m(r^2 + k^2)\\dot{\\theta}$. What is the Hamiltonian of the system?\n\\begin{s}\n    Using the fact that here the Hamiltonian is equal to the energy:\n    \\[\\mathcal{H} = T + U = \\frac{p^2}{2m} + mgk\\theta\\]\n\\end{s}\nLast lecture, we derived Hamilton's equations of motion:\n\\[\\boxed{\\dpd{\\mathcal{H}}{p_i} = \\dot{q}_i, \\quad \\dpd{\\mathcal{H}}{q_i} = - \\dot{p}_i}\\]\nThis was done by starting with the Hamiltonian (Legendre transform of $\\mathcal{L}$), expanding out in the total differential of $\\mathcal{H}$, then using the EL equation to solve for Hamilton's equation (see last day's notes for more detail). We notice that Hamilton's equations are two first order equations, rather than a single second order equation. In general, if we have $n$ degrees of freedom, the Lagrangian gives us $n$ 2nd order differential equations, while Hamilton gives us $2n$ 1st order differential equations. \n\n\\noindent Now suppose that the Hamiltonian is independent of $p_i$. What can we say about the system?\n\\begin{s}\n$q_i$ is constant by Hamilton's equations.\n\\end{s}\n\nNow, what do Hamilton's equations tell us about the derivatives $\\dpd{\\dot{q}_i}{q_i} + \\dpd{\\dot{p}_i}{p_i}$?\n\\begin{s}\nAgain using Hamilton's equation, these are equal to:\n\\[\\dpd{\\HH}{q_ip_i} - \\dpd{\\HH}{p_iq_i} = 0\\]\nBy the equality of mixed partials.\n\\end{s}\n\n\\subsubsection{The Variational Principle, Revisited}\nFrom Lagrangian mechanics, we have that the variation in the action is zero:\n\\[\\delta S = \\delta \\int_{t_1}^{t_2}\\mathcal{L}dt = \\delta \\int_{t_1}^{t_2}[\\sum p_i\\dot{q}_i - \\mathcal{H}]dt = 0\\]\nExpanding this, we have:\n\\[\\int_{t_1}^{t_2}\\sum_i \\left[-\\left(\\dot{p}_i + \\dpd{\\HH}{q_i}\\right)\\delta q_i + \\left(\\dot{q}_i - \\dpd{\\HH}{p_i}\\right)\\delta p_i\\right] dt = 0\\]\nWhat does this imply about the terms in parentheses?\n\\begin{s}\nSince $q$ and $p$ can be varied independently, both $\\dot{p}_i + \\dpd{\\HH}{q_i}$ and $\\dot{q}_i - \\dpd{\\HH}{p_i}$ must vanish independently; these are exactly Hamilton's equations of motion!\n\\end{s}\n\n\\subsubsection{Hamiltonian Time Dependence}\nLet us now look at the time derivative of the Hamiltonian:\n\\[\\dod{\\mathcal{H}}{t} = \\sum_i\\left(\\dpd{\\mathcal{H}}{q_i}\\dot{q}_i + \\dpd{\\HH}{p_i}\\dot{p}_i\\right)  + \\dpd{\\HH}{t}\\]\nAssuming the trajectory obeys Hamilton's equations, we have:\n\\[\\dod{\\mathcal{H}}{t} = \\sum_i\\left(-\\dot{p}_i\\dot{q}_i + \\dot{q}_i\\dot{p}_i\\right) + \\dpd{\\HH}{t} = = \\dpd{\\HH}{t} = - \\dpd{\\LL}{t} \\]\nEven though $\\HH$ is a function of $q, p, t$, the only explicit time dependence comes from the Hamiltonian itself! $\\HH$ is constant if $\\LL$ is independent of time.\n\n\\subsubsection{The Atwood Machine, Again}\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-23/l23-img1.png}\n\\end{center}\nThe Atwood machine has Hamiltonian:\n\\[\\HH = \\frac{p^2}{2(m_1 + m_2)} - (m_1 - m_2)gx - m_2gl\\]\nWhat are the equations of motion?\n\\begin{s}\nBy Hamilton's equations:\n\\[\\dot{x} = \\frac{p}{m_1 + m_2}\\]\n\\[\\dot{p} = (m_1 - m_2)g\\]\n\\end{s}\nHow does the system move?\n\\begin{s}\nFrom above, we can see that $x$ moves with constant gravitational acceleration with effective mass \\[\\frac{m_1 - m_2}{m_1 + m_2}\\]\nWhich we can see from:\n\\[\\ddot{x} = \\frac{m_1 - m_2}{m_1 + m_2}g\\]\nWe can also reason this from limits of $m_1 \\ll m_2$, $m_1 \\gg m_2$.\n\\end{s}\n\n\\subsubsection{Phase Space of the Harmonic Oscillator}\nPhase space is the set of points $\\set{q_i, p_i}$ i.e. possible combinations of (generalized) position/momenta. We can write the phase space vector as $\\v{z} = (\\v{q}, \\v{p})$. For the Harmonic oscillator in one dimension (spring constant $k$, mass $m$ distance from equlibrium $x$), we have the Hamiltonian:\n\\[\\HH = \\frac{p_x^2}{2m} + \\frac{k}{2}x^2\\]\nHamilton's equations give:\n\\[\\dot{p}_x = -\\dpd{\\HH}{x} = -kx\\]\n\\[\\dot{x} = \\dpd{\\HH}{p_x} = \\frac{p_x}{m}\\]\nOf course, we may combine these to get:\n\\[\\ddot{x} = \\frac{p_x}{m} = -\\frac{k}{m}x\\]\nWe may write Hamilton's equations as a vector:\n\\[\\m{\\dot{x} \\\\ \\dot{p}_x} = \\m{p_x/m \\\\ -kx}\\]\nWe know that this will have solutions:\n\\[x = x_0\\cos(\\sqrt{\\frac{k}{m}}t - \\delta)\\]\n\\[p_x = m\\dot{x} = -mx_0\\sqrt{\\frac{k}{m}}\\sin(\\sqrt{\\frac{k}{m}}t - \\delta)\\]\nNow, we observe:\n\\[\\frac{x^2}{x_0^2} + \\frac{p_x^2}{mx_0^2k} = \\sin^2(x) + \\cos^2(x) = 1\\]\nBut this of course is just the equation for an ellipse, that tells us that the trajectory in phase space of the harmonic oscillator will be an ellipse! In particular, which of the two directions (if both) are possible?\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-23/l23-img2.png}\n\\end{center}\n\\begin{s}\nOnly B; consider that when we sit at the rightmost point in the ellipse, we get pulled back towards the origin, hence the magnitude of the momentum increases, in the negative direction. Hence only the second trajectory makes sense. \n\\end{s}\nNow, consider a collection of harmonic oscillators which have the same energy but different relative phases. Which collection of phase points represents this system at a given instant in time?\n\\begin{center}\n    \\includegraphics[scale=0.7]{Lecture-23/l23-img3.png}\n\\end{center}\n\\begin{s}\nFor a given fixed energy, we stay on the ellipse, and the phase angle just tells you where you are on the ellipse. So, A.\n\\end{s}\nConsider an area element in phase space. What physically must happen for a particle to move into the area across the left boundary?\n\\begin{center}\n    \\includegraphics[scale=1]{Lecture-23/l23-img4.png}\n\\end{center}\n\\begin{s}\nThe position $q_k$ increases but the momentum $p_k$ is constant.\n\\end{s}\n\n\\subsubsection{Particle in a Central Force Field}\nThe kinetic energy for a particle of mass $m$ in a central force field is given by:\n\\[T = \\frac{m}{2}\\left(\\dot{r}^2 + r^2\\dot{\\phi}^2\\right)\\]\nThen we have the generalized momenta:\n\\[p_r = \\dpd{T}{\\dot{r}} = m\\dot{r} \\implies \\dot{r} = \\frac{p_r}{m}\\]\n\\[p_\\phi = \\dpd{T}{\\dot{\\phi}} = mr^2\\dot{\\phi} \\implies \\dot{\\phi} = \\frac{p_\\phi}{mr^2}\\]\nHence the Hamiltonian has the form:\n\\[\\HH = T + U = \\frac{1}{2m}\\left(p_r^2 + \\frac{p_\\phi^2}{r^2}\\right) + U(r)\\]\nHence Hamilton's equations yield:\n\\[\\dot{r} = \\dpd{\\HH}{p_r} = \\frac{p_r}{m}, \\quad \\dot{p}_r = -\\dpd{\\HH}{r} = \\frac{p_\\phi^2}{mr^3} - \\dod{U}{r}\\]\\\n\\[\\dot{\\phi} = \\dpd{\\HH}{p_\\phi} = \\frac{p_\\phi}{mr^2}, \\quad p_\\phi = -\\dpd{\\HH}{\\phi} = 0\\]\n\\subsubsection{General Procedure for setting up Hamilton's equations}\n\\begin{enumerate}[1.]\n\\item Choose suitable generalized coordinates, $q_{1}, \\cdots, q_{n}$.\n\\item Write down the kinetic and potential energies, $T$ and $U$, in terms of the $q$ 's and $\\dot{q}$ 's. \n\\item Find the generalized momenta $p_{1}, \\cdots, p_{n} .$ (We are now assuming our system is conservative, so $U$ is independent of $\\dot{q}_{i}$ and we can use $p_{i}=\\partial T / \\partial \\dot{q}_{i} .$ In general, one must use $p_{i}=\\partial \\mathcal{L} / \\partial \\dot{q}_{i}$. \n\\item Solve for the $\\dot{q}$ 's in terms of the $p$ 's and $q$ 's.\n\\item Write down the Hamiltonian $\\mathcal{H}$ as a function of the $p$ 's and $q$ 's. [Provided our coordinates are \"natural\" (relation between generalized coordinates and underlying Cartesians is independent of time), $\\mathcal{H}$ is just the total energy $\\mathcal{H}=T+U,$ but when in doubt, use $\\mathcal{H}=\\sum p_{i} \\dot{q}_{i}-\\mathcal{L} .$ See Problems 13.11\nand $13.12 .]$.\n\\item Write down Hamilton's equations (13.25).\n\\end{enumerate}\nWe will illustrate the advantages of using Hamilton's equations rather than Lagrange next week. One advantage is that we get first order versus second order equations, which can be easier sometimes (we have more techniques). A deeper advantage is theoretical, which we will see. We will also see how to construct a quantum theory with this framework.\n\\end{document}", "meta": {"hexsha": "6178894740036a2815e2644f4669c88e7e844ad4", "size": 8021, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-23/Lecture-Notes-23.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-23/Lecture-Notes-23.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-23/Lecture-Notes-23.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.685483871, "max_line_length": 527, "alphanum_fraction": 0.6941777833, "num_tokens": 2661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.7956580976404296, "lm_q1q2_score": 0.600654231105827}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% UMB-CS110-2015S: Introduction to Computing\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/UMB-CS110-2015S\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\def \\topDirectory {.}\n\\def \\texDirectory {\\topDirectory/src/main/tex}\n\n\\documentclass[12pt,letterpaper,twoside]{article}\n\\usepackage{\\texDirectory/template/style/directives}\n\\usepackage{\\texDirectory/template/style/assignment}\n\\input{\\texDirectory/template/config}\n\n\\begin{document}\n\n\\doc{title}{Solution to Quiz 1(b)}\n\\doc{date-pub}{Feb 19, 2015 at 01:00 PM}\n\\doc{date-due}{Feb 19, 2015 at 11:00 PM}\n\\doc{points}{4}\n\n\\prepare{header}\n\n\\section*{Question 1}\n\nAccording to National Weather Serivce, the \\textit{Wind Chill} can be computed as given in Equation \\ref{eq1}, where $t$ is the temperature in Fahrenheit and $v$ is the wind speed in miles per hour.\n\n\\begin{equation}\nw = 35.74 + 0.6215 t + (0.4275t-35.75)v^{0.16}\n\\label{eq1}\n\\end{equation}\n\nWrite a program \\texttt{WindChill.java} that takes temperature in Celsius and using Equation \\ref{eq1} gives the wind chill in Celsius.\nFahrenheit to Celsius conversion formula is given in Equation \\ref{eq2}.\n\n\\begin{equation}\nt_F = 1.8 \\times t_C + 32\n\\label{eq2}\n\\end{equation}\n\n\\begin{figure}[H]\\centering\n\t\\includegraphics[width=8cm]{\\texDirectory/template/images/windchill.png}\n\\end{figure}\n\n\\section*{Question 2}\n\nWrite a program \\textit{Maximum.java} that takes three integer numbers as command-line arguments and prints their maximum, minimum and mean values.\n\n\\prepare{footer}\n\n\\end{document}\n", "meta": {"hexsha": "aee016629d999db2798dd42225227c240fe845fc", "size": 1731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/main/tex/quizzes/q01b.tex", "max_stars_repo_name": "UMB-CS110-2015S/Assignments", "max_stars_repo_head_hexsha": "b12ded95ddec71cd45dd05dff773018f6879d37f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-03T18:41:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-03T18:41:40.000Z", "max_issues_repo_path": "src/main/tex/quizzes/q01b.tex", "max_issues_repo_name": "UMB-CS110-2015S/Assignments", "max_issues_repo_head_hexsha": "b12ded95ddec71cd45dd05dff773018f6879d37f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-08-22T15:44:45.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-17T16:39:11.000Z", "max_forks_repo_path": "src/main/tex/quizzes/q01b.tex", "max_forks_repo_name": "UMB-CS110-2015S/Assignments", "max_forks_repo_head_hexsha": "b12ded95ddec71cd45dd05dff773018f6879d37f", "max_forks_repo_licenses": ["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.6603773585, "max_line_length": 198, "alphanum_fraction": 0.7001733102, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.888758803068433, "lm_q1q2_score": 0.6005917379577059}}
{"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{Norms}{Norms}\n\n\\input{../../fncextra}\n\n\\begin{document}\n\n\\begin{center}\n  \\bf Norm-an conquest\n\\end{center}\n\nThe absolute value $|x|$ represents the distance on the number line\nbetween the point $x$ and the origin. We can do the same for a vector\nof $n$ numbers, plotting an arrows whose tail is at the origin and\napplying the Pythagorean theorem to conclude that $\\bfx$ represents a\npoint that is a distance $(x_1^2 + \\cdots + x_n^2)^{1/2}$ from the\norigin. This is what we call the 2-norm, $\\|\\bfx\\|_2$. It turns out\nthat if we abstract the notion of ``distance'' a little to its\nessential properties, we can get other vector norms as well. Each norm has its own set of unit vectors (those having norm equal to 1).\n\nFor matrices, a definition based on the action of the\nmatrix as a linear transformation is quite handy for analyzing linear\nalgebra algorithms.  The definition starts with all the unit vectors\nin whatever norm we like. Each of these\nvectors $\\bfv$ is mapped to the vector $\\bfu=\\mA\\bfv$. The maximum of\n$\\|\\bfu\\|$ for all such $\\bfv$ is the value of $\\|\\mA\\|$. This\ndefinition can be visualized easily only when both $\\bfv$ and\n$\\bfu$ are low-dimensional.\n\n\\subsection*{Goals}\n\nYou will use experiments based on the definitions of norms to approximate the calculation of norms of a small matrix.\n\n\\subsection*{Preparation}\n\nRead section 2.7. Recall that the equations $x=\\cos(\\theta)$, $y=\\sin(\\theta)$, $0\\le \\theta \\le 2\\pi$ parameterize the unit circle (set of all unit vectors) defined by the 2-norm in $\\mathbf{R}^2$.\n\n\\subsection*{Procedure}\n\nDownload the script template and complete it to perform the following steps.\n\n\\begin{enumerate}\n\\item Define a vector \\texttt{theta} of 200 equally spaced values from 0 to $2\\pi$. Use it to define vectors \\texttt{x} and \\texttt{y} via $x_j = \\cos(\\theta_j)$, $y_j = \\sin(\\theta_j)$ (do this without any loops). Plot these points, which lie on the unit circle.\n\n\\item Let \\texttt{A=magic(2)}. For each $j$, define the vector $\\bfv=[x_j\\:y_j]^T$ and let $\\bfu=\\mA\\bfv$. On a new graph, plot all the $\\bfu$ points, and make a vector storing $\\|\\bfu\\|_2$ for all $j$.\n\n\\item Plot $\\|\\bfu\\|_2$ as a function of $\\theta$. \n\n\\item Using \\texttt{format long} and \\texttt{max}, calculate and show the maximum value of $\\|\\bfu\\|_2$ over all $j$. This estimates $\\|\\mA\\|_2$. Also compute the actual value \\texttt{norm(A,2)}.\n  \n\\item The script creates new vectors \\texttt{x} and \\texttt{y} that are unit vectors in the $\\infty$-norm. Plot these points, giving a title and axis labels.\n\n\\item Repeat step 2, this time collecting $\\|\\bfu\\|_\\infty$ as a function of the point index $j$.\n  \n\\item Make a plot as in step 3. This time, the $x$-axis will the index number $j$.\n\n\\item Estimate the norm $\\|\\mA\\|_\\infty$ and compute its exact value, as in step 4. \n\\end{enumerate}\n\n\\end{document}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: t\n%%% End:\n", "meta": {"hexsha": "2d7fdbbc645ac24f83d8e3a55aceb578236d8329", "size": 3086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "labs/chapter02/Norms/Norms.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/Norms/Norms.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/Norms/Norms.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": 42.2739726027, "max_line_length": 263, "alphanum_fraction": 0.7200259235, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.6005453767403315}}
{"text": "%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\input{../../doc/related_pages/header.tex}\r\n\\input{../../doc/related_pages/newcommands.tex}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\begin{document}\r\n\r\n\\title{The toefl project}\r\n\\author{ M.~Wiesenberger and M.~Held}\r\n\\maketitle\r\n\r\n\\begin{abstract}\r\n  This is a program for 2d isothermal blob simulations used in References~\\cite{Wiesenberger2014,Kube2016,Wiesenberger2017a}.\r\n\\end{abstract}\r\n\r\n\\section{Equations}\r\nCurrently we implemented $5$ slightly different sets of equations. $n$ is the electron density, $N$ is the ion gyrocentre density and $\\rho$\r\nthe vorticity density. $\\phi$ is the electric potential. We\r\nuse Cartesian coordinates $x$, $y$.\r\n\\subsection{Models}\r\n\r\n\"local\"\r\n\\begin{subequations}\r\n\\begin{align}\r\n -\\nabla^2 \\phi =  \\Gamma_1 N -n, \\quad\r\n\\psi = \\Gamma_1 \\phi \\quad \\Gamma_1 = ( 1- 0.5\\tau\\nabla^2)^{-1} \\\\\r\n \\frac{\\partial n}{\\partial t}     = \r\n    \\{ n, \\phi\\} \r\n  + \\kappa \\frac{\\partial \\phi}{\\partial y} \r\n  -\\kappa \\frac{\\partial n}{\\partial y}\r\n  + \\nu \\nabla^2 n  \\\\\r\n  \\frac{\\partial N}{\\partial t} =\r\n  \\{ N, \\psi\\} \r\n  + \\kappa \\frac{\\partial \\psi}{\\partial y} \r\n  + \\tau \\kappa\\frac{\\partial N}{\\partial y} +\\nu\\nabla^2N\r\n\\end{align}\r\n\\end{subequations}\r\n\r\n\"global\"\r\n\\begin{subequations}\r\n\\begin{align}\r\nB(x)^{-1} = \\kappa x +1-\\kappa X\\quad \\Gamma_1 = ( 1- 0.5\\tau\\nabla^2)^{-1}\\\\\r\n -\\nabla\\cdot \\left(\\frac{N}{B^2} \\nabla_\\perp \\phi\\right) = \\Gamma_1 N-n, \\quad\r\n \\text{Boussinesq:}\\quad -\\nabla_\\perp^2 \\phi = \\frac{B^2}{N} (\\Gamma_1 N -n) \\\\\r\n\\psi = \\Gamma_1 \\phi - \\frac{1}{2} \\frac{(\\nabla\\phi)^2}{B^2}\\\\\r\n \\frac{\\partial n}{\\partial t}     = \r\n    \\frac{1}{B}\\{ n, \\phi\\} \r\n  + \\kappa n\\frac{\\partial \\phi}{\\partial y} \r\n  -\\kappa \\frac{\\partial n}{\\partial y}\r\n  + \\nu \\nabla_\\perp^2 n  \\\\\r\n  \\frac{\\partial N}{\\partial t} =\r\n  \\frac{1}{B}\\{ N, \\psi\\} \r\n  + \\kappa N\\frac{\\partial \\psi}{\\partial y} \r\n  + \\tau \\kappa\\frac{\\partial N}{\\partial y} +\\nu\\nabla_\\perp^2N\r\n\\end{align}\r\n\\end{subequations}\r\n\r\n\"gravity local\"\r\n\\begin{subequations}\r\n\\begin{align}\r\n \\nabla^2 \\phi = \\rho \\\\\r\n \\frac{\\partial n}{\\partial t} = \\{ n, \\phi\\} + \\nu \\nabla^2 n  \\\\\r\n  \\frac{\\partial \\rho}{\\partial t} = \\{ \\rho, \\phi\\} - \\eta \\rho - \\frac{\\partial n}{\\partial y} + \\nu \\nabla^2 \\rho \r\n\\end{align}\r\n\\end{subequations}\r\n\r\n\r\n\"gravity global\"\r\n\\begin{subequations}\r\n\\begin{align}\r\n \\nabla \\cdot(n \\nabla \\phi) = \\rho \\quad\\text{ Boussinesq: }\\quad \\nabla^2 \\phi = \\rho/n \\\\\r\n \\frac{\\partial n}{\\partial t} = \\{ n, \\phi\\} +  \\nu \\nabla^2 n  \\\\\r\n  \\frac{\\partial \\rho}{\\partial t} = \\{ \\rho, \\phi\\} + \\{n, \\frac{1}{2} \\nabla\\phi^2\\} - \\eta \\rho - \\frac{\\partial n}{\\partial y} +\\nu\\nabla^2\\rho \r\n\\end{align}\r\n\\end{subequations}\r\n\r\n\"drift global\"\r\n\\begin{subequations}\r\n\\begin{align}\r\nB(x)^{-1} = \\kappa x +1-\\kappa X\\\\\r\n \\nabla \\cdot \\left(\\frac{n}{B^2} \\nabla \\phi\\right) = \\rho \\quad\r\n \\text{Boussinesq:}\\quad \\nabla^2\\phi = \\rho \\frac{B^2}{n} \\quad\r\n\\psi = \\frac{1}{2} \\frac{(\\nabla\\phi)^2}{B^2}\\\\\r\n \\frac{\\partial n}{\\partial t}     = \r\n    \\frac{1}{B}\\{ n, \\phi\\} \r\n  + \\kappa n\\frac{\\partial \\phi}{\\partial y} \r\n  + \\nu \\nabla^2 n  \\\\\r\n  \\frac{\\partial \\rho}{\\partial t} =\r\n  \\frac{1}{B}\\{ \\rho, \\phi\\} \r\n  + \\frac{1}{B}\\{n, \\psi\\}\r\n  + \\kappa \\rho\\frac{\\partial \\phi}{\\partial y} \r\n  + \\kappa n\\frac{\\partial \\psi}{\\partial y}\r\n  - \\kappa\\frac{\\partial n}{\\partial y} +\\nu\\nabla^2\\rho \r\n\\end{align}\r\n\\end{subequations}\r\n\r\n\r\n\\subsection{Initialization}\r\nInitialization of $n$ is a Gaussian \r\n\\begin{align}\r\n    n(x,y) = 1 + A\\exp\\left( -\\frac{(x-X)^2 + (y-Y)^2}{2\\sigma^2}\\right)\r\n    \\label{}\r\n\\end{align}\r\nwhere $X = p_x l_x$ and $Y=p_yl_y$ are the initial centre of mass position coordinates, $A$ is the amplitude and $\\sigma$ the\r\nradius of the blob.\r\nWe initialize \r\n\\begin{align}\r\n    N = \\Gamma_1^{-1} n \\quad \\phi = 0 \\\\\r\n    \\rho = \\phi = 0\r\n    \\label{}\r\n\\end{align}\r\n\\subsection{Diagnostics}\r\n\\begin{align}\r\n    M(t) = \\int n-1 \\\\\r\n    \\Lambda_n = \\nu \\int \\Delta n  \\\\\r\n    ...\r\n    \\label{}\r\n\\end{align}\r\n\\section{Numerical methods}\r\ndiscontinuous Galerkin on structured grid\r\n\\rowcolors{2}{gray!25}{white} %%% Use this line in front of longtable\r\n\\begin{longtable}{ll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Term} &  \\textbf{Method} & \\textbf{Description}  \\\\ \\midrule\r\ncoordinate system & Cartesian 2D & equidistant discretization of $[0,l_x] \\times [0,l_y]$, equal number of Gaussian nodes in x and y \\\\\r\nmatrix inversions & conjugate gradient & Use previous two solutions to extrapolate initial guess and $1/\\chi$ as preconditioner \\\\\r\n\\ExB advection & Arakawa & s.a. \\cite{Einkemmer2014} \\\\\r\ncurvature terms & direct & flux conserving \\\\\r\ntime &  Karniadakis multistep & $3rd$ order explicit, diffusion $2nd$ order implicit \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\n\\section{Compilation and useage}\r\nThere are two programs toeflR.cu and toefl\\_hpc.cu . Compilation with\r\n\\begin{verbatim}\r\nmake <toeflR toefl_hpc toefl_mpi> device = <omp gpu>\r\n\\end{verbatim}\r\nRun with\r\n\\begin{verbatim}\r\npath/to/feltor/src/toefl/toeflR input.json\r\npath/to/feltor/src/toefl/toefl_hpc input.json output.nc\r\necho np_x np_y | mpirun -n np_x*np_y path/to/feltor/src/toefl/toefl_mpi\\\r\n    input.json output.nc\r\n\\end{verbatim}\r\nAll programs write performance informations to std::cout.\r\nThe first is for shared memory systems (OpenMP/GPU) and opens a terminal window with life simulation results.\r\n The\r\nsecond can be compiled for both shared and distributed memory systems and uses serial netcdf in both cases\r\nto write results to a file.\r\nFor distributed\r\nmemory systems (MPI+OpenMP/GPU) the program expects the distribution of processes in the\r\nx and y directions as command line input parameters.\r\n\r\n\\subsection{Input file structure}\r\nInput file format: json\r\n\r\n%%This is a booktabs table\r\n\\begin{longtable}{llll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Example} & \\textbf{Default} & \\textbf{Description}  \\\\ \\midrule\r\nn      & integer & 3 & - &\\# Gaussian nodes in x and y \\\\\r\nNx     & integer &100& - &\\# grid points in x \\\\\r\nNy     & integer &100& - &\\# grid points in y \\\\\r\ndt     & integer &3.0& - &time step in units of $c_s/\\rho_s$ \\\\\r\nn\\_out  & integer &3  & - &\\# Gaussian nodes in x and y in output \\\\\r\nNx\\_out & integer &100& - &\\# grid points in x in output fields \\\\\r\nNy\\_out & integer &100& - &\\# grid points in y in output fields \\\\\r\nitstp  & integer &2  & - &   steps between outputs \\\\\r\nmaxout & integer &100& - &      \\# outputs excluding first \\\\\r\neps\\_pol   & float &1e-6    & - &  accuracy of polarisation solver \\\\\r\neps\\_gamma & float &1e-7    & - & accuracy of $\\Gamma_1$ (only in gyrofluid model) \\\\\r\neps\\_time  & float &1e-10   & - & accuracy of implicit time-stepper \\\\\r\ncurvature  & float &0.00015& - & magnetic curvature $\\kappa$ \\\\\r\ntau        & float &1      & - & $\\tau = T_i/T_e$ (only in gyrofluid models) \\\\\r\nnu\\_perp    & float &5e-3   & - & pependicular viscosity $\\nu$ \\\\\r\namplitude  & float &1.0    & - & amplitude $A$ of the blob \\\\\r\nsigma      & float &10     & - & blob radius $\\sigma$ \\\\\r\nposX       & float &0.3    & - & blob x-position in units of $l_x$, i.e. $X = p_x l_x$\\\\\r\nposY       & float &0.5    & - & blob y-position in units of $l_y$, i.e. $Y = p_y l_y$ \\\\\r\nlx         & float &200    & - & $l_x$  \\\\\r\nly         & float &200    & - & $l_y$  \\\\\r\nfriction   & float & 0     & 0 & friction coefficient $\\eta$ in gravity model \\\\\r\nbc\\_x   & char & \"DIR\"      & - & boundary condition in x (one of PER, DIR, NEU, DIR\\_NEU or NEU\\_DIR) \\\\\r\nbc\\_y   & char & \"PER\"      & - & boundary condition in y (one of PER, DIR, NEU, DIR\\_NEU or NEU\\_DIR) \\\\\r\nequations  & char & \"global\" & \"global\" &local, global, gravity\\_local, gravity\\_global, drift\\_global \\\\\r\nboussinesq & bool & false    & false &boussinesq approximation in global models true or false\\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\nThe default value is taken if the value name is not found in the input file. If there is no default and\r\nthe value is not found,\r\nthe program exits with an error message.\r\n\r\n\\subsection{Structure of output file}\r\nOutput file format: netcdf-4/hdf5\r\n%\r\n%Name | Type | Dimensionality | Description\r\n%---|---|---|---|\r\n\\begin{longtable}{lll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Dimension} & \\textbf{Description}  \\\\ \\midrule\r\ninputfile  &             text attribute & 1 & verbose input file as a string \\\\\r\nenergy\\_time             & Dataset & 1 & timesteps at which 1d variables are written \\\\\r\ntime                     & Dataset & 1 & time at which fields are written \\\\\r\nx                        & Dataset & 1 & x-coordinate  \\\\\r\ny                        & Dataset & 1 & y-coordinate \\\\\r\nelectrons                & Dataset & 3 (time, y, x) & electon density $n$ \\\\\r\nions                     & Dataset & 3 (time, y, x) & ion density $N$ or vorticity density $\\rho$  \\\\\r\npotential                & Dataset & 3 (time, y, x) & electric potential $\\phi$  \\\\\r\nvorticity                & Dataset & 3 (time, y, x) & Laplacian of potential $\\nabla^2\\phi$  \\\\\r\ndEdt                     & Dataset & 1 (energy\\_time) & change of energy per time  \\\\\r\ndissipation              & Dataset & 1 (energy\\_time) & diffusion integrals  \\\\\r\nenergy                   & Dataset & 1 (energy\\_time) & total energy integral  \\\\\r\nmass                     & Dataset & 1 (energy\\_time) & mass integral   \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\\section{Diagnostics toeflRdiag.cu}\r\nThere only is a shared memory version available\r\n\\begin{verbatim}\r\ncd path/to/feltor/diag\r\nmake toeflRdiag\r\npath/to/feltor/diag/toeflRdiag input.nc output.nc\r\n\\end{verbatim}\r\n\r\nInput file format: netcdf-4/hdf5\r\n%\r\n%Name | Type | Dimensionality | Description\r\n%---|---|---|---|\r\n\\begin{longtable}{lll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Dimension} & \\textbf{Description}  \\\\ \\midrule\r\ninputfile  &             text attribute & 1 & verbose input file as a string \\\\\r\nelectrons                & Dataset & 3 & electon density (time, y, x) \\\\\r\nions                     & Dataset & 3 & ion density (time, y, x) \\\\\r\npotential                & Dataset & 3 & electric potential (time, y, x) \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\nOutput file format: netcdf-4/hdf5\r\n%\r\n%Name | Type | Dimensionality | Description\r\n%---|---|---|---|\r\n\\begin{longtable}{lll>{\\RaggedRight}p{7cm}}\r\n\\toprule\r\n\\rowcolor{gray!50}\\textbf{Name} &  \\textbf{Type} & \\textbf{Dimension} & \\textbf{Description}  \\\\ \\midrule\r\n inputfile & text attribute & 1 & copy of inputfile attribute of the input file (the json string of the simulation input file) \\\\\r\n time & Dataset & 1 & the time steps at which variables are written \\\\\r\n posX & Dataset & 1 (time) & centre of mass (COM) position x-coordinate \\\\\r\n posY & Dataset & 1 (time) &COM y-position \\\\\r\n velX & Dataset & 1 (time)& COM x-velocity \\\\\r\n velY & Dataset & 1 (time)& COM y-velocity \\\\\r\n accX & Dataset & 1 (time)& COM x-acceleration \\\\\r\n accY & Dataset & 1 (time)& COM y-acceleration \\\\\r\n velCOM & Dataset & 1 (time)&absolute value of the COM velocity \\\\\r\n posXmax& Dataset & 1 (time)&maximum amplitude x-position \\\\\r\n posYmax& Dataset & 1 (time)&maximum amplitude y-position \\\\\r\n velXmax& Dataset & 1 (time)&maximum amplitude x-velocity \\\\\r\n velYmax& Dataset & 1 (time)&maximum amplitude y-velocity \\\\\r\n maxamp & Dataset & 1 (time)&value of the maximum amplitude  \\\\\r\n  compactness\\_ne& Dataset & 1 (time) &compactness of the density field \\\\\r\n Ue& Dataset&  1 (time) &entropy electrons \\\\\r\n Ui &Dataset& 1 (time) & entropy ions \\\\\r\n Uphi& Dataset& 1 (time) &  exb energy \\\\\r\n mass& Dataset & 1 (time) & mass of the blob without background \\\\\r\n\\bottomrule\r\n\\end{longtable}\r\n\r\n\r\n%..................................................................\r\n\\bibliography{../../doc/related_pages/references}\r\n%..................................................................\r\n\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "90ac7dbdcd198b99bf6f10b8b1cc5f9cbd153254", "size": 12001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/toefl/toefl.tex", "max_stars_repo_name": "RaulGerru/FELTOR_Raul", "max_stars_repo_head_hexsha": "a566f8a9003ade437e093334877f839f3dfd0260", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2016-06-28T14:34:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T08:50:48.000Z", "max_issues_repo_path": "src/toefl/toefl.tex", "max_issues_repo_name": "RaulGerru/FELTOR_Raul", "max_issues_repo_head_hexsha": "a566f8a9003ade437e093334877f839f3dfd0260", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2017-01-18T16:06:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T19:11:42.000Z", "max_forks_repo_path": "src/toefl/toefl.tex", "max_forks_repo_name": "RaulGerru/FELTOR_Raul", "max_forks_repo_head_hexsha": "a566f8a9003ade437e093334877f839f3dfd0260", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-06-27T13:18:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T08:12:25.000Z", "avg_line_length": 43.481884058, "max_line_length": 149, "alphanum_fraction": 0.6127822681, "num_tokens": 3933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.600545357857629}}
{"text": "\\chapter{Introduction}\nA common problem in applied statistics is that one has an independent\nvariable or outcome $Y$ and various dependent variable or covariates \n$X_1,\\dots,X_p$. One usually observes these variables for various\n``subjects''. \n\nOne may be interested in various things: What effects do the\ncovariates have on the outcome? How well can we describe these\neffects? Can we predict the outcome using the\ncovariates?, etc..  \n\nStatisticians usually assume that $Y$ and the $X$'s are random\nvariables. Then one can summarize the above question by asking: what\nis $\\E[ Y | X_1,\\dots,X_p]$? We usually call $f(X_1,\\dots,X_p) = \\E[Y\n| X_1,\\dots, X_p]$ the {\\it regression function}. \n\nIt should be noted that for some designed experiments it does not make\nsense to assume the $X$ are random variables. In this case we usually\nassume we have ``design points'' $x_{1i}, \\dots, x_{pi}, i=1,\\dots,n$\nand non-IID observations $Y_1,\\dots,Y_n$ for each design\npoint. In most cases, the\ntheory for both these cases is very similar if not the same. These are\ncalled the {\\it random design model} and {\\it fixed design model} respectively.\n\nHow do we learn about $E[Y|X_1,\\dots,X_p]$?\n\nA common procedure is linear regression. One typically assumes\n\\[\n\\E[Y | X_1, \\dots, X_p] = \\sum_{j=1}^p X_j \\beta_j.\n\\]\nAssuming that the conditional probability of $Y$ is normal is quite\ncommon. However, if the range of this expectation is not continuous one can \ngeneralize to: \n\\[\ng ( \\E[Y | X_1, \\dots, X_p] ) = \\sum_{j=1}^p X_j \\beta_j\n\\]\nwith $g$ a link function with real-valued range. It is typical to\nassume the conditional distribution of $Y$  is part of an exponential\nfamily, e.g. binomial, Poisson, gamma, etc.... Many times the link\nfunction is chosen for mathematical convenience.\n\nThese model have the convenience that the parameters $\\beta$ usually\nhave direct interpretation with scientific meaning. For example\n$\\beta=5$ may mean that a man that is one inch higher than another is\nexpected to weigh 5 more pounds.\n\nAnother advantage is that, once an appropriate model is in place, the\nestimates have many desirable properties.\n\nA drawback of these models is that they are quite\nrestrictive. Linearity and additivity are two very strong\nassumptions. This may have practical consequences. For example, by\nassuming  linearity one may never notice that a covariate\nhas an effect that increases and then decreases. We will see various\nexample of this in class. \n\nIn this class we will\n\\begin{itemize}\n\n\\item Start by introducing various smoothers useful for smoothing\n  scatter plots $\\{ (X_i, Y_i), i=1,\\dots,n \\}$ where both $X$ and $Y$\n  are continuous variables.\n\\item Set down precise models and outline the proofs of asymptotic\n  results.\n\\item Introduce local regression (loess).\n\\item Examine spline models and some of the theory behind splines.\n\\item Some smoothers are more flexible than others. However with\n  flexibility comes variance. We will talk about the bias-variance\n  trade-off and how one can use resampling methods to estimate bias\n  and variance.\n\\item After explaining all these smoothers we will make a connection\n  between them. We will also make connections to other statistical\n  procedures.\n\\item We will examine the case were one has many covariates. One can\n  relax the linearity assumption, \n  assume additivity and use additive models. One can also forget the\n  additivity assumption and \n  use regression trees.\n\\item After all this we will be ready to consider the case where $Y$\n  is not necessarily continuous. We will generalize to this case and\n  look at Generalized Additive Models and Local Likelihood.\n\\item While examining all these subjects we will be considering\n  various models for one data set. We will briefly discuss techniques\n  that can be used to aid in the choice of such models.\n\\item Finally we will look at a brief introduction of times series\n  analysis.\n\\end{itemize}\n\nBy relaxing assumptions we loose some of the nice properties of\nestimates. There is an on going debate about specification\nvs. estimation.\n\n\nWe will begin the class talking about the case were the regression\nfunction $f$ will depend on a \nsingle, real-valued predictor $X$ ranging over some possibly infinite\ninterval of the real line, $I \\subset \\mathbb{R}$. Therefore, the\n(mean) dependence of $Y$ on $X$ is given by\n\\begin{equation}\n\\label{regfunc}\nf(x) = \\E[Y|X=x], x \\in I \\subset \\mathbb{R}.\n\\end{equation}\n\nSometimes, the need to estimate $f$ arises when investigators have to\ndecide among various explanations for a physical phenomenon,\nand existing subject-knowledge or scientific theory says nothing about\n$f$. In this case we collect data to see what it says. Exhibiting some\naspect of $f$ may then imply the confirmation or \nrevision of a given theory.  \n\nThe data to\nsupport  such investigations are typically a set of $n$ paired\nobservations $(\\bX_1,Y_1),\\dots,(\\bX_n,Y_n)$. These can be either a\nrandom sample of  the joint distribution of $(\\bX,Y)$ as is the case\nfor observational studies, or fixed input values $\\{ \\bx_i \\}$, arising perhaps from a designed experiment. \n\nSo once we have the data what do we do?\n\nIf we are going to ``model'' (\\ref{regfunc}), we gain insight into the\nimportant features of the relationship \nbetween $Y$ and $\\bX$ by entertaining various descriptions of or\nmodels for $f$. Through this exercise we might:\n\\begin{itemize}\n\\item  identify the width and height of peaks\n\\item  explore the overall shape of $f$ in some neighborhood\n\\item find  areas of sharp increase or regions exhibiting little\n  curvature.\n\\end{itemize}\n\nThe first three chapters of the class deal with this problem. We will\nthen move on to the case where we have many covariates, then cases\nwhere the \nexpectation needs to be transformed, and various other generalization.\n\n\nThrough out all these subjects we will be talking about finite sample\ntheory, asymptotics, practical aspects, and computational\nconsideration. \n\n\n", "meta": {"hexsha": "9f33b393743333f245e871d52fff7648d3a44402", "size": 5963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-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-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-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": 42.2907801418, "max_line_length": 108, "alphanum_fraction": 0.7672312594, "num_tokens": 1477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.743168019989179, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6005297076791245}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\section{Lecture 30}\n\\subsection{Lecture Notes - Continuum Mechanics}\n\\subsubsection{Setting Up The Continuum Limit}\nRecall HW5, where we considered an infinitely long chain of particles. Then, defining $u_s$ to be the displacement of the $s$th photon from the equilibrium position, we solved (by Newton's law):\n\\[m\\ddot{u}_s = m\\omega_0^2(u_{s+1} + u_{s-1} - 2u_s)\\]\nWhere $\\omega_0^2 = \\frac{k}{m}$. The forces depend on the neighbouring interactions and displacements from equilibrium. Now, it becomes a bit of a subtle issue to how we take limits to infinity without getting things to blow up.\n\\newline We start with $N$ masses which are separated by a distance $l$ (chain of SHOs).\n\\begin{itemize}\n    \\item  We want to take $N \\rightarrow \\infty$ and $l \\rightarrow 0$ at the same time. We do this in such a way that the total length $L = Nl$ of the string remains constant.\n    \\item  As we increase the number of particles, they also get lighter, so we take $m \\rightarrow 0$ and $l \\rightarrow 0$ such that the line mass density $\\lambda = \\frac{m}{l}$ of the string also is a constant.\n\\end{itemize}\nQuestion: When we double the number of masses and reduce the equilibrium length by a factor of 2, what must happen with the spring constant $k$?\n\\begin{center}\n    \\includegraphics[scale=1]{Lecture-30/l30-img1.png}\n\\end{center}\n\\begin{s}\nSince $F = kx$, if $x \\mapsto \\frac{x}{2}$, then $k \\mapsto 2k$ in order to give the same force between the particles as the original configuration. \n\\end{s}\n\\begin{itemize}\n    \\item So another condition on our limit; we will take $k \\rightarrow \\infty$ and $l \\rightarrow 0$ with $kl$ held constant.\n\\end{itemize}\nThe idea is we will go from the position of a single particle $u_s(t)$ and take it to the continuum limit of $u(x, t)$, now considering a field.\n\\begin{center}\n    \\includegraphics[scale=1]{Lecture-30/l30-img2.png}\n\\end{center}\n\n\\subsubsection{Deriving the Wave Equation}\nReplacing the discrete positions with a continuous variable in the Newton's law equation we had in the section above, we have:\n\\[\\dpd[2]{u(x, t)}{t} = \\omega_0^2\\left(u(x + l, t) + u(x - l, t) - 2u(x, t)\\right)\\]\nBut there is an issue; $\\omega_0^2 = \\frac{k}{m}$ diverges as $k \\rightarrow \\infty$ and $m \\rightarrow 0$! How do we rescue this? We multiply the above equation by $1$ in a clever way, multiplying and dividing by $l^2$:\n\\[\\dpd[2]{u(x, t)}{t} = \\omega_0^2l^2\\left(\\frac{u(x + l, t) + u(x - l, t) - 2u(x, t)}{l}\\right)\\]\nBut this is quite convenient, as $\\omega_0^2l^2 = kl\\frac{l}{m} = \\frac{kl}{\\lambda}$ which is constant! Let us therefore denote $\\omega_0^2l^2 = c^2$ where $c$ si the speed of sound. We can therefore write the above equation in the following way:\n\\[\\dpd[2]{u(x, t)}{t} = \\frac{c^2}{l}\\left[\\frac{u(x +l) - u(x, t)}{l} - \\frac{u(x, t) - u(x - l, t)}{l}\\right]\\]\nWe recognize that the two terms in the bracket are two first order spatial derivatives. Further taking another derivative by considering the difference of the two first order derivatives by taking $l \\rightarrow 0$, the RHS becomes a single second order spatial derivative:\n\\[\\boxed{\\dpd[2]{u(x, t)}{t} = c^2\\dpd[2]{u(x, t)}{x}}\\]\nWhich we recognize is a wave equation!\n\n\\subsubsection{Wave equation Solutions and Dispersion Relation}\nOne prime example of a solution to the wave equation is:\n\\[u(x, t) = A\\sin(kx - \\omega t)\\]\nWhere $k$ is the wavevector and $\\omega$ the frequency. Plugging this into the wave equation, we immediately obtain the (familiar) dispersion relation:\n\\[\\omega = ck\\]\nRecall that in HW5 we found a relation that was slightly more complicated, and was given as:\n\\[\\omega = 2\\omega_0\\abs{\\sin(\\frac{kl}{2})}\\]\nWhich graphically looks like:\n\\begin{center}\n    \\includegraphics[scale=0.8]{Lecture-30/l30-img3.pdf}\n\\end{center}\nSo if we consider the limit of this dispersion for $kl \\ll 1$, we can Taylor expand the sine and get:\n\\[\\omega = 2\\omega_0 \\frac{kl}{2} = \\omega_0 kl = ck\\]\nSo we therefore have that the slope of the above graph for small $k$ is equal to $c$. We then see that we can recover the linear dispersion relationship that we obtained in the continuum limit!\n\n\\subsubsection{Generalization to 3D}\nSuppose we work in three dimensions, and instead have $P = p(x, y, z)$ (pressure, or some other variable). We then have that:\n\\[\\dpd[2]{p}{t} = c^2\\left(\\dpd[2]{p}{x} + \\dpd[2]{p}{y} + \\dpd[2]{p}{z}\\right) = c^2\\nabla^2 p\\]\nWhere $\\nabla^2$ is the laplacian.\n\n\\subsubsection{Volume and Surface Forces}\nSince we now work with materials with a finite extension, we have more types of forces to consider. We first have \\textbf{volume forces}, which are proportional to $dV$. Typical examples are gravity and electrostatic forces:\n\\[\\v{F}_g = \\rho_0 \\v{g}dV\\]\n\\[\\v{F}_e = \\rho_e \\v{E}dV\\]\n$\\rho_0, \\rho_e$ represent mass and charge densities repectively. These are in a sense \"boring\" and just come from external fields.\n\\begin{center}\n    \\includegraphics[scale=0.9]{Lecture-30/l30-img4.png}\n\\end{center}\nSlightly more interesting are surface forces, which are proportional to dA. We then have Pressure, Tension, and Shear forces, as pictured below. Already things become more complicated as they depend not just on the magnitude of the force as well as the orientation of the body. \n\\begin{center}\n    \\includegraphics[scale=0.9]{Lecture-30/l30-img5.png}\n\\end{center}\nWe could of course build up to something like torsion from combinations of the above \"elementary\" surface forces.\n\\newline A question might be is where does this resistance to these surface forces come from? The answer is the intermolecular forces between the atoms in the material. \n\n\\subsubsection{Stress \\& Strain - Basic Definitions}\n\\begin{itemize}\n    \\item Stress = Force / Area = Pressure (Fluid)\n    \\item Stress = Tension / Area (Wire)\n    \\item Stress = Shear Force / Area (Shear)\n    \\item Strain = dV/V (Fluid)\n    \\item Strain = dl/l (Wire)\n    \\item Strain = dy/dx (Shear)\n\\end{itemize}\nOne can think of the stress as a pressure, and the Strain as a \"fractional deformation\"/relative change.\n\n\\subsubsection{Hooke's Law for Solids (Linear Elasticity)}\nFor small deformations, materials will also follow Hooke's law. We start with the wire case. If we change the wire by length $dl$, we have that the force $dF$ is given by:\n\\[dF = k\\cdot dl\\]\nHowever, it is more useful to divide both sides by the area $A$ and add a factor of $l$ on the RHS, which gives:\n\\[\\frac{dF}{A} = \\frac{kl}{A}\\frac{dl}{l}\\]\nTherein, the term on the LHS is the tensile stress, the rightmost term is the tensile strain (could be compressive if $dl < 0$, but let us assume for now that $dl > 0$) and define:\n\\[\\frac{lk}{A} = Y\\]\nWhich is Young's modulus, which is a characteristic of the material/material property. \n\\newline Next, we look at a change of pressure in a fluid. We then have:\n\\[dp = -B\\frac{dV}{V}\\]\nWhere if we pull/expand a fluid, the pressure decreases. The $B$ is known as the bulk modulus, which tells us the response to a volumetric change (the proportionality constant to the strain). Note that in general liquids are non-compressible and hence $B$ for something like water is extremely high (but not infinite!)\n\\newline Finally, considering a shear, we have\n\\[\\frac{F}{A} = G\\frac{dy}{dx}\\]\nWhere $G$ is the shear modulus. As a visual, consider shearing a material by displacing it. The amount by which we shear is $dy$. The amount of tilt is the shear strain, and the coefficient of the force that fights back is the shear modulus.\n\\begin{center}\n    \\includegraphics[]{Lecture-30/l30-img6.png}\n\\end{center}\n\n\\subsubsection{The Stress Tensor}\nWhen we think of solids, we worry about two things; we both worry about the force (which has three components) as well as the orientation of the surface in which we apply the force, as the material acts differently depending along which surface we apply the force. The stress is specified by the direction of action and the orientation of the surface. This yields $3 \\cdot 3 = 9$ possible components, yielding the stress tensor!\n\\begin{center}\n    \\includegraphics[scale=0.5]{Lecture-30/l30-img7.png}\n\\end{center}\nQuestion: A fluid is an isotropic molecule that cannot sustain any shearing forces in equilibrium. What must be true for the stress tensor of the fluid?\n\\begin{s}\n    The tensor must be digonal (no shear forces) with one unique component (isotropic). The idea is if we push, we feel the same pressure on all sides. There is only one scalar value which quantifies the response. For the fluid, the stress tensor will have a simple form:\n    \\[\\sigma = \\m{-P & 0 & 0 \\\\ 0 & -P & 0 \\\\ 0 & 0 & -P}, \\quad  \\sigma_{ij} = -P\\delta_{ij}\\]\n    Note that this is not true of all liquids, e.g. with viscous liquids like honey we can expect shear forces when we stir.\n\\end{s}\nNext day we will look at the counterpart of the stress tensor, the strain tensor, and hopefully get to equations of motion that describe the motion of objects with finite extension. \n\n\\end{document}", "meta": {"hexsha": "09bbcdace2ae61f4286c707af6fb7f5d6f24ee51", "size": 9030, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-30/Lecture-Notes-30.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-30/Lecture-Notes-30.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-30/Lecture-Notes-30.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": 76.5254237288, "max_line_length": 428, "alphanum_fraction": 0.7282392027, "num_tokens": 2591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6005297019210436}}
{"text": "\\chapter{Nonparametric regression}\nThis chapter is under \\work.\n\\section{Kernel regression}\nLet $(x_1,y_1),\\ldots,(x_n,y_n)$ be a bivariate sample of size $n$. Assuming that the relationship between $x$ and $y$ can be expressed as:\n\\begin{equation}\ny_i=m(x_i)+\\epsilon_i,\n\\end{equation}\n\nwhere $\\epsilon_1,\\epsilon_2,\\ldots$ are IID with mean 0 and constant variance $\\sigma^2$. Our goal is to estimate the {\\it regression function (or regression curve)} $m(x)$.\n\n{\\it Nonparametric regression} is a collection of techniques for estimating the regression function without making strong assumptions about the shape of the function. Beside kernel regression, other nonparametric regression techniques include spline regression, wavelet regression and tree regression.\n\nKernel regression methods can be broadly classified as:\n\\begin{asparaenum}[(a)]\n\\item {\\it Local polynomial kernel regression methods.}\n\n\\item {\\it Others}, e.g. the {\\it Gasser-Muller method} and the {\\it Priestley-Chao method}.\n\\end{asparaenum}\nWe will focus mainly on the local polynomial kernel regression methods because they perform better. Moreover, with respect to mean squared error, the Gasser-Muller and Priestley-Chao methods are asymptotically inadmissible.\n\n\\subsection{Local polynomial kernel regression}\nThe estimated value of the regression function at a particular point, say $x^*$, is obtained by locally fitting a $p^{\\textrm{th}}$ degree polynomial to the data via weighted least squares:\n\\begin{asparaenum}[(a)]\n\\item Let:\n\\begin{equation}\nm_p(x,x^*)=\\beta_0+\\beta_1(x-x^*)+\\beta_2(x-x^*)^2+\\ldots+\\beta_p(x-x^*)^p.\n\\end{equation}\n\\item Estimate the coefficients, $\\beta_0,\\beta_1,\\ldots,\\beta_p$ by weighted least squares:\n\\begin{equation}\n(\\hat{\\beta}_0,\\hat{\\beta}_1,\\ldots,\\hat{\\beta}_p)=\\arg\\min\\sum^{n}_{i=1}K_h(x_i-x^*)[y_i-m_p(x_i,x^*)]^2.\n\\end{equation}\n\\item Let:\n\\begin{equation}\n\\hat{m}_{p,h}(x,x^*)=\\hat{\\beta}_0+\\hat{\\beta}_1(x-x^*)+\\hat{\\beta}_2(x-x^*)^2+\\ldots+\\hat{\\beta}_p(x-x^*)^p.\n\\end{equation}\n\\item The estimated value of the regression function at $x^*$ is given by:\n\\begin{equation}\n\\hat{m}(x^*)=\\hat{m}_{p,h}(x^*,x^*)=\\hat{\\beta}_0\n\\end{equation}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{asparaenum}\nNote that the points are first shifted in the $x$-axis, so that the origin is at $x^*$, and then the polynomial is fitted to the shifted points by weighted least squares. The weights are provided by a kernel centred on $x^*$, i.e. $K_h(x-x^*)$. The consequence of the shift is that the estimate of the regression function at $x^*$ is now simply the estimate of the $y$-intercept, i.e. $\\hat{\\beta}_0$.\n\nTo obtain the regression coefficients by weighted least squares, let:\n$$B=\\left(\\begin{array}{c}\\beta_0\\\\\\beta_1\\\\\\textrm{M}\\\\\\beta_p\\end{array}\\right),\\space \nY=\\left(\\begin{array}{c}y_1\\\\\\textrm{M}\\\\y_n\\end{array}\\right),\\space \nX_{x^*}=\\left(\\begin{array}{cccc}1&(x_1-x^*)&\\Lambda &(x_1-x^*)^p\\\\\\textrm{M}&\\textrm{M}&\\textrm{M}&\\textrm{M}\\\\1&(x_n-x^*)&\\Lambda &(x_n-x^*)^p\n\\end{array}\\right)$$\n$$W_{x^*}=\\left(\\begin{array}{cccc}\nK_k(x_1-x^*)&0&\\Lambda&0\\\\\n0&K_k(x_2-x^*)&&\\textrm{M}\\\\\n\\textrm{M}&&\\textrm{O}&0\\\\\n0&\\Lambda&0&K_k(x_n-x^*)\\\\\n\\end{array}\\right).$$\nThen:\n\\begin{equation}\n\\hat{B}=(X^T_{x^*}W_{x^*}X_{x^*})^{-1}X^T_{x^*}W_{x^*}Y.\n\\end{equation}\n\nIf $e_1$ is the $(p + 1)$-column vector with 1 in the first row and 0 elsewhere, then:\n\\begin{equation}\n\\hat{m}(x^*)=e_1^T(X^T_{x^*}W_{x^*}X_{x^*})^{-1}X^T_{x^*}W_{x^*}Y.\n\\end{equation}\n\nSpecial cases of local polynomial kernel regression include:\n\n\\begin{asparaenum}[(a)]\n\\item {\\it Nadaraya-Watson method.} This corresponds to $p = 0$, i.e. fit a constant locally to the data. The estimate of the regression function at $x^*$ can be expressed as:\n\\begin{equation}\n\\hat{m}(x^*)=\\frac{\\sum^n_{i=1}K_h(x_i-x^*)y_i}{\\sum^n_{j=1}K_h(x_j-x^*)}.\n\\end{equation}\n\\item {\\it Local linear kernel regression.} This corresponds to $p = 1$, i.e. fit a straight line locally to the data. The estimate of the regression function at $x^*$ can be expressed as:\n\\begin{equation}\n\\hat{m}(x^*)=\\frac{\\sum^n_{i=1}[\\hat{s}_2(x^*)-\\hat{s}_1(x^*)(x_i-x^*)]K_h(x_i-x^*)y_i}{\\hat{s}_2(x^*)\\hat{s}_0(x^*)-\\hat{s}_1(x^*)^2},\n\\end{equation}\nwhere:\n\\begin{equation}\n\\hat{s}_r(x^*)=\\sum^n_{i=1}(x_i-x^*)^rK_h(x_i-x^*),\n\\end{equation}\nwhich may be thought of as a weighted $r^{\\textrm{th}}$ moment about $x^*$.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{asparaenum}\n\nSee WJ\\footnote{Wand, M.P. and Jones, M.C. (1995), {\\it Kernel Smoothing}, Chapman \\& Hall.}: Figure 5.1 for a visualisation of this regression.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\nNotice that for $p = 0$ and $p = 1$, the estimates of the regression function have the form:\n\\begin{equation}\n\\hat{m}(x^*)=\\sum^n_{i=1}\\omega_i(x^*)y_i,\n\\end{equation}\nwhere:\n\\begin{equation}\n\\sum^n_{i=1}\\omega_i(x^*)=1,\n\\end{equation}\n\ni.e. the estimates are weighted (linear) combinations of the $y$ values. In general, this is true of local polynomial kernel regression for any $p$. The weights, $\\omega_1(x^*),\\ldots,\\omega_n(x^*)$, are called {\\it equivalent kernel weights} and they depend on the point $x^*$ at which the regression function is being estimated.\n\nSee WJ: Figures 5.6 and 5.7 for a visualisation of this method.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\nFor routine use, local linear kernel regression is recommended because it has good asymptotic properties and behaves well at boundaries.\n\n\\subsection{Choice of kernel bandwidth}\n\nThe bandwidth selection methods for kernel density estimation can be adapted for kernel regression.\n\nOne approach is to consider the optimal bandwidth that minimises the asymptotic conditional mean of the integrated weighted squared error:\n\\begin{equation}\n\\lim_{n\\rightarrow\\infty}E[\\int\\{\\hat{m}(x)-m(x)\\}^2f(x)dx|x_1,\\ldots,x_n],\n\\end{equation}\n\nwhere $f$ is the density of the predictors.\n\nAssuming that the perturbation variance $\\sigma^2$ is constant and that the predictors are supported on the bounded interval $[a, b]$, the optimal bandwidth for local linear kernel regression is given by\\footnote{Ruppert, D., Sheather, S. J. and Wand, M. P. (1995), \\textquotedblleft An effective bandwidth selector for local least squares regression\", {\\it Journal of the American Statistical Association 90, 1257-1270}.}:\n\\begin{equation}\nh=[\\frac{c_K\\sigma^2(b-a)}{c_mn}]^{1/5},\n\\end{equation}\nwhere: \n\\begin{equation}\nc_K=\\frac{\\int K(x)^2dx}{[\\int x^2K(x)dx]^2},\n\\end{equation}\n\ndepends on the kernel $K$, and:\n\\begin{equation}\nc_m=\\int m^{\\prime\\prime}(x)^2f(x)dx,\n\\end{equation}\n\ndepends on the regression function $m$.\n\nFor the Gaussian kernel, $c_K=(2\\sqrt{\\pi})^{-1}$, and for the Epanechnikov kernel, $c_K=15$.\n\nTo compute the optimal bandwidth, plug-in estimates of $\\sigma^2$ and $c_m$ are required. One way to do this is implemented in the \\Matlab function {\\tt loclinbw}:\n\\begin{VrbM}\n% loclinbw.m\n% Bandwidth selection for local linear kernel regression.\n% Estimates the optimal asymptotic mean integrated weighted squared error\n% by the rule-of-thumb method.\n%\n% Assumptions: Homoscesdastic, bounded predictor support.\n%\n% Usage: bw = loclinbw(x,y,kertype);\n%\n% Inputs: x = column vector of predictors.\n%             y = column vector of responses.\n%             kertype = kernel type:\n%                             1 = Gaussian,\n%                             2 = Epanechnikov.\n%\n% Output: bw = bandwidth.\n%\n% Reference: Ruppert, D., Sheather, S. J. and Wand, M. P. (1995),\n% \"An effective bandwidth selector for local least squares regression\",\n% Journal of the American Statistical Association 90, 1257-1270.\n\\end{VrbM}\nThis bandwidth should be used as an initial guide to what the appropriate bandwidth should be, by exploring other values close to it.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nSee WJ: Figure 5.2 for a depiction of this.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\n\\begin{labwork}\nThe data in {\\tt automobile.txt} are the horsepower (HP, in column 1) and miles per gallon (MPG, in column 2) of 82 automobiles. Estimate the regression function for MPG against HP using local linear Gaussian kernel regression.\n\n\\begin{VrbM}\ndata = load('automobile.txt');\nx = data(:,1);\ny = data(:,2);\nbw = loclinbw(x,y,1)\ns = [40:330]';\nn = length(x);\nns = length(s);\nyfit = zeros(ns,1);\nfor i = 1:ns\n    K = normpdf(x,s(i),bw);\n    xdev = x - s(i);\n    xdevK = xdev .* K;\n    s0 = sum(K);\n    s1 = sum(xdevK);\n    s2 = sum(xdev .* xdevK);\n    w = ((s2 - s1 * xdev) .* K) / (s0 * s2 - s1 * s1);\n    yfit(i) = w' * y;\nend\nplot(x,y,'.b',s,yfit,'-r')\nxlabel('HP'), ylabel('MPG')\ntitle(['Local linear Gaussian kernel regression with bw = ' num2str(bw)])\n\\end{VrbM}\nResults:\n\\begin{VrbM}\nbw = 13.3923\n\\end{VrbM}\n%\\includegraphics\nNotice the gap in the HP values that causes the estimated regression curve to look suspicious - we should expect MPG to decrease monotonically with HP. We can therefore increase the kernel bandwidth slowly until the estimated regression curve is approximately monotone. A bandwidth of about 34 appears to be adequate.\n%\\includegraphics\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{labwork}\n\n\\section{Extension to multivariate predictors}\nSuppose that the predictors $x_1,\\ldots,x_n$ are multivariate, say $d$-dimensional, but the responses $y_1,\\ldots,y_n$ are still univariate. Once again, assume that the relationship between $x$ and $y$ can be expressed as:\n\\begin{equation}\ny_i=m(x_i)+\\epsilon_i=m(x_i(1),\\ldots,x_i(d))+\\epsilon_i,\n\\end{equation}\n\nwhere $x_i(j)$ denotes the $j^{\\textrm{th}}$ component of $x_i$, and $\\epsilon_1,\\epsilon_2,\\ldots$ are IID with mean 0 and constant variance $\\sigma^2$.\n\n\\subsection{Multivariate kernel regression}\nWe will describe the extension of local linear kernel regression to multivariate predictors. The estimated value of the regression function at a point $x^*$ is obtained by locally fitting a hyperplane to the data via weighted least squares, with weights provided by a multivariate kernel:\n\\begin{asparaenum}[(a)]\n\\item Let $m_1(x,x^*)=\\beta_0+\\beta_1(1)[x(1)-x^*(1)]+\\Lambda+\\beta_1(d)[x(d)-x^*(d)]$.\n\n\\item Estimate the regression coefficients by weighted least squares:\n$$(\\hat{\\beta}_0,\\hat{\\beta}_1(1),\\ldots,\\hat{\\beta}_1(d))=\\arg\\min\\sum^n_{i=1}K_H(x_i-x^*)[y_i-m_1(x_i,x^*)]^2.$$\n\n\\item Let $\\hat{m}_{1,H}(x,x^*)=\\hat{\\beta}_0+\\hat{\\beta}_1(1)[x(1)-x^*(1)]+\\Lambda+\\hat{\\beta}_1(d)[x(d)-x^*(d)]$.\n\n\\item The estimated value of the regression function at $x^*$ is given by:\n\n$$\\hat{m}(x^*)=\\hat{m}_{1,H}(x^*,x^*)=\\hat{\\beta}_0,$$\n\nwhich can be computed directly from:\n$$\\hat{m}(x^*)=e_1^T(X^T_{x^*}W_{x^*}X_{x^*})^{-1}X^T_{x^*}W_{x^*}Y,$$\n\nwhere $e_1$ is the $(d + 1)$-column vector with 1 in the first row and 0 elsewhere:\n$$X_{x^*}=\\left(\\begin{array}{cccc}1&(x_1(1)-x^*(1))&\\Lambda &(x_1(d)-x^*(d))\\\\\\textrm{M}&\\textrm{M}&\\textrm{M}&\\textrm{M}\\\\1&(x_n(1)-x^*(1))&\\Lambda &(x_n(d)-x^*(d))\n\\end{array}\\right)$$\nand:\n$$W_{x^*}=\\left(\\begin{array}{cccc}\nK_H(x_1-x^*)&0&\\Lambda&0\\\\\n0&K_H(x_2-x^*)&&\\textrm{M}\\\\\n\\textrm{M}&&\\textrm{O}&0\\\\\n0&\\Lambda&0&K_H(x_n-x^*)\\\\\n\\end{array}\\right).$$\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{asparaenum}\nClearly, the extension from univariate predictors to multivariate ones is straightforward. Unfortunately, to get a good estimate of the regression function as $d$ increases requires the sample size to grow much faster than $d$ - this is known as the {\\it curse of dimensionality}.\n\n\\subsection{Additive regression}\nThis is an alternative approach that models the multivariate regression function as a sum of univariate regression functions, one for each dimension, plus a constant term $m_0$:\n\\begin{equation}\ny_i=m(x_i)+\\epsilon_i=m_0+\\sum^d_{j=1}m_j(x_i(j))+\\epsilon_i.\n\\end{equation}\n\nThus, $m_j$ is a univariate regression function for the $j^{\\textrm{th}}$ component of the predictor. Finding the regression functions is not the same as performing d separate univariate regressions because the other dimensions must be taken into account when fitting for one dimension. This involves an iterative procedure known as {\\it backfitting}, where the residuals from the current iteration are used to improve the fit in the next iteration.\n\nAdditive regression performs well if the multivariate regression function is represented well by the assumed additive model, and if the components of the predictor are not strongly correlated.\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\nSee Scott\\footnote{Scott, D.W. (1992), {\\it Multivariate Density Estimation: Theory, Practice and Visualization,} Wiley.}: Figures 8.7 and 8.9 for a graphic illustration.\n\n\\section{Exercises}\n\\begin{exercise}\nWork through Example 6.1.7 for the automobile data.\n\\end{exercise}\n\\begin{exercise}\nThe data in {\\tt car.txt} are the miles per gallon (MPG) (column 1) and top speed (column 2) of 82 cars.\n\\begin{asparaenum}[(a)]\n\\item Perform a regression of top speed (response) on MPG (predictor) using local linear Gaussian kernel regression with the bandwidth that minimises the asymptotic conditional mean integrated weighted squared error. Produce a scatter plot of the data points with the estimated regression curve superimposed.\n\\item Suppose that the relationship between top speed and MPG is actually monotone. Adjust the bandwidth to get a regression curve that reflects this but does not oversmooth. Produce a scatter plot of the data points with the new regression curve superimposed.\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. The fifth column contains the aluminium contents of the glass specimens.\n\\begin{asparaenum}[(a)]\n\\item Perform a local linear Gaussian kernel regression of refractive index $(y)$ against aluminium content $(x)$, with four times the bandwidth that minimises the asymptotic conditional mean integrated weighted squared error. Produce a scatter plot of the data points with the estimated regression curve superimposed.\n\\item Obtain a point-wise 0.95 BCA confidence band for the regression function by bootstrapping residuals with 1000 bootstrap replicates.\n\\end{asparaenum}\n\\end{exercise}\n\n\\begin{exercise}\nThe data in {\\tt motorcycle.txt} are from 94 simulated motorcycle accidents. The first column contains the times in milliseconds since impact; the second column contains the head accelerations in gs.\n\\begin{asparaenum}[(a)]\n\\item Perform a local linear Gaussian kernel regression of head acceleration $(y)$ versus time $(x)$, with the bandwidth that minimises the asymptotic conditional mean integrated weighted squared error. Produce a scatter plot of the data points with the estimated regression curve superimposed.\n\\item Obtain a point-wise 0.95 BCA confidence band for the regression function by bootstrapping residuals with 1000 bootstrap replicates.\n\\end{asparaenum}\n\\end{exercise}\n", "meta": {"hexsha": "4c6899cc11f076a5c8f5c4bdd5424f7701aa7e98", "size": 14916, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/NonParametricRegression.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/NonParametricRegression.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/NonParametricRegression.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": 54.4379562044, "max_line_length": 449, "alphanum_fraction": 0.7223786538, "num_tokens": 4537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6005296984859879}}
{"text": "\\section{Model fitting}\n\n\\subsection{Hough transform}\n\nx-y space to a-b parameter space\n\n\\includegraphics[width=0.8\\columnwidth]{pictures/hough}\n\n$$b = (-x)*a+y$$\n\nAlternative: x-y space to $\\theta$-$\\rho$ (or d) space\n$$x cos(\\theta) + y sin(\\theta) = \\rho$$\n\nFor each point, render the curve ($\\theta$, d) and count the parameter in bins with similar values.\n\nDifficulties: How big should the bins be (too big, and we cannot distinguish between quite different lines; too small, and noise causes lines to be missed)\n\n\nHardly ever satisfactory in practice, because problems with noise and bin size defeat it\n\n\\subsection{Line fitting}\n\\subsubsection{Incremental line fitting}\n\\begin{lstlisting}[frame=single]\nPut all points on a curve list, in order along the curve\nEmpty the line point list\nEmpty the line list\nUntil there are too few points on the curve\n\tTransfer first few points on the curve tot the line point list\n\tFit line to line point list\n\tWhile fitted line is good enough\n\t\tTransfer the next point on the curve to tthe line point list and refit the line\n\tend\n\tTransfer last point(s) back to curve\n\tRefit line\n\tAttach line to line list\nend\n\\end{lstlisting}  \n\n\\subsubsection{K-means}\n\\begin{lstlisting}[frame=single]\nHypothesize k lines (perhabps uniformly at random)\nor\nHypothesize an assignment of lines to points and then fit lines using this assingment\n\nUntil convergence\n\tAllocate each point to the closest line\n\tRefit lines\nend\n\\end{lstlisting} \n\nProblem can be stuck in local optima\n \n\\subsubsection{Probabilistic}\n- EM-algorithm (expectation maximum)\n- M-estimators\n- RANSAC\n\n\\subsubsection{RANSAC}\n\n- Choose a small subset uniformly at random\n- Fit to that\n- Anything that is close to result is signal; all others are noise\n- Refit\n- Do this many times and choose the best\\\\\n\n\\textbf{Issues} \n\\begin{itemize}\n\t\\item How many times? Often enough that we are likely to have a good line\n\t\\item How big a subset? Smallest possible\n\t\\item What does close mean? Depends on the problem\n\t\\item What is a good line? One where the number of nearby points is so big it is unlikely to be all outliers\n\\end{itemize}\n\n\n\\begin{lstlisting}[frame=single]\nDetermine:\n\tn-the smallest number of points required\n\tk-the number of iterations required\n\tt-the threshold used to identify a point that fits well\n\td-the number of nearby points required to assert a model fits well\nUntil k iterations have occured\n\tDraw a sample of n points from the data uniformly and at random\n\tFit to that set of n points\n\tFor each data point outside the sample\n\t\tTest the distance from the point to the line against t; if the distance from the point to the line is less than t, the point is close\n\tend\n\tIf there are d or more points close to the line then there is a good fit. Refit the line using all these points.\nend\nUse the best fit from this collection, using the fitting error as criterium\t\n\\end{lstlisting} \n\n$$ k = \\frac{log(1-p)}{log(1-w^s)} $$\nk - number of iterations\\\\\np - probability at least one sample free from outliers\\\\\nw - fraction of inliers = d/n\\\\\ns - model dimension (2 for a line, 3 for plane)\n\n\\subsection{Missing variable problems}\n\nIn many vision problems, if some variables were known the maximum likelihood inference problem would be easy \n\\begin{itemize}\n\t\\item fitting; if we knew which line each token came from, it would be easy to determine line parameters\n\t\\item segmentation; if we knew the segment each pixel came from, it would be easy to determine the segment parameters\n\t\\item fundamental matrix estimation; if we knew which feature corresponded to which, it would be easy to determine the fundamental matrix\n\\end{itemize}\nThis sort of thing happens in statistics, too - strategy:\n\\begin{enumerate}\n\t\\item estimate missing variables\n\t\\item plug these in, now estimate parameters\n\t\\item re-estimate appropriate values for missing variables - converges to local extremum (like k-means)\n\\end{enumerate}\n\n\\subsection{Cross validation}\n-Split data set into two pieces, fit to one, and compute negative loglikelihood on the other\n-Average over multiple different splits\n-Choose the model with the smallest value of this average\n-The difference in averages for two different models is an estimate of the difference in KL divergence of the models from the source of the data", "meta": {"hexsha": "6da181ed6c10a3724eb471d3156dab3164a7d240", "size": 4284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/6_Model_Fitting.tex", "max_stars_repo_name": "gruke/ethz-cv-lectureNotes", "max_stars_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-05T20:43:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-05T20:43:06.000Z", "max_issues_repo_path": "chapters/6_Model_Fitting.tex", "max_issues_repo_name": "gruke/ethz-cv-lectureNotes", "max_issues_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "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_Model_Fitting.tex", "max_forks_repo_name": "gruke/ethz-cv-lectureNotes", "max_forks_repo_head_hexsha": "688827b1eebdf7d7aa4446986aa838312175fa1f", "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.6153846154, "max_line_length": 155, "alphanum_fraction": 0.7731092437, "num_tokens": 1054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431679972357831, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6005296875753234}}
{"text": "\\documentclass[a4paper, 12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{dsfont}\n\\usepackage[left=1.5cm, right=1.5cm, bottom=2cm, top=2cm]{geometry}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage[utf8]{inputenc}\n\\usepackage{microtype}\n\\usepackage{natbib}\n\\newcommand{\\given}{\\,|\\,}\n\n\\title{Notes}\n\\author{Brendon J. Brewer}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\abstract{}\n\n% Need this after the abstract\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{8pt}\n\n\\section*{Unknown True Metallicities}\nLet $\\{Z_i\\}$ be the unknown true metallicities and let $\\{z_i\\}$ be the\nmeasured metallicities, with the reported errorbars $\\{b_i\\}$, such that\n\\begin{align}\nz_i \\given Z_i &\\sim \\textnormal{Normal}\\left(z_i, b_i^2\\right).\n\\end{align}\nLet the other parameters be $\\theta$ and the data be $D$. We seek the\nposterior\n\\begin{align}\np(\\theta, \\boldsymbol{Z} \\given D) &\\propto p(\\theta, \\boldsymbol{Z})\n                                            p(D \\given \\theta, \\boldsymbol{Z}) \\\\\n    &= p(\\theta)p(\\boldsymbol{Z}) p(D \\given \\theta, \\boldsymbol{Z}),\n\\end{align}\nassuming that the true metallicities do not tell us anything about the other\nparameters. Then, we can marginalise out the true metallicities:\n\\begin{align}\np(\\theta \\given D)\n    &= \\int p(\\theta, \\boldsymbol{Z} \\given D) \\, d\\boldsymbol{Z} \\\\\n    &\\propto \\int p(\\theta)p(\\boldsymbol{Z}) p(D \\given \\theta, \\boldsymbol{Z})\n               \\, d\\boldsymbol{Z} \n\\end{align}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "39a4407d4f7175baddcc068f0cbd5cc0761ccfad", "size": 1482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/ms.tex", "max_stars_repo_name": "eggplantbren/M31Globulars", "max_stars_repo_head_hexsha": "0493ae9a4fda520915e6c2a5f9477f89d6236957", "max_stars_repo_licenses": ["MIT"], "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/ms.tex", "max_issues_repo_name": "eggplantbren/M31Globulars", "max_issues_repo_head_hexsha": "0493ae9a4fda520915e6c2a5f9477f89d6236957", "max_issues_repo_licenses": ["MIT"], "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/ms.tex", "max_forks_repo_name": "eggplantbren/M31Globulars", "max_forks_repo_head_hexsha": "0493ae9a4fda520915e6c2a5f9477f89d6236957", "max_forks_repo_licenses": ["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.0588235294, "max_line_length": 81, "alphanum_fraction": 0.6828609987, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6003737957700861}}
{"text": "\\documentclass{homework}\n\\course{Math 5522H}\n\\author{Jim Fowler}\n\\input{preamble}\n\n\\begin{document}\n\\maketitle\n\n\\begin{inspiration}\n  On April 9, 1975, Congressman Robert Michel brandished a list of new\n  NSF grants on the floor of the House of Representatives and selected\n  a few that he thought might represent a waste of the taxpayers'\n  money. One of them \\ldots was called ``Studies in Complex\n  Analysis. Michel's comment was, `` `Simple Analysis' would,\n  hopefully, be cheaper.''\n  \\byline{Gerald B. Folland} % the American Mathematical Monthly (vol 780, Oct 1998, pg. 780)\n\\end{inspiration}\n\n\\section{Terminology}\n\n\\begin{problem}\n  What is a \\textbf{simply-connected} domain?\n\\end{problem}\n\n\\begin{problem}\n  What does it mean to say that two curves $\\alpha$ and $\\beta$ are\n  \\textbf{homologous}?\n\\end{problem}\n\n\\begin{problem}\n  What is a \\textbf{null homotopic} path?\n\\end{problem}\n\n\\begin{problem}\n  Given a function $f : U \\to \\C$, what is meant by a \\textbf{branch} of the log of $f$?\n\\end{problem}\n\n\\section{Numericals}\n\n\\begin{problem}\n  Let $f(z) = (z^2-z-1)/z^3$, and consider the curve\n  $\\gamma : [0,2\\pi] \\to \\C$ by $\\gamma(\\theta) = f(e^{i\\theta})$.\n  Compute the winding number $n(\\gamma,0)$.\n\\end{problem}\n\n\\begin{problem}\n  Evaluate the \\textbf{Dirichlet integral}\n  \\[\n    \\int_0^\\infty \\frac{\\sin x}{x} \\, dx.\n  \\]\n\\end{problem}\n\n\\begin{problem}\n  Define $\\gamma : [0,2\\pi] \\to \\C$ by $\\gamma(\\theta) = e^{i\\theta}$.\n  Suppose $p \\in \\C[z]$ is a degree $n$ polynomial with distinct roots\n  $z_1,\\ldots,z_n$ in the unit disk, and evaluate\n  \\[\n    \\int_\\gamma \\frac{z^m \\, p'(z)}{p(z)} \\, dz.\n  \\]\n\\end{problem}\n\n\\begin{problem}\n  Again define $\\gamma : [0,2\\pi] \\to \\C$ by\n  $\\gamma(\\theta) = e^{i\\theta}$, and then evaluate\n  \\[\n    \\int_\\gamma \\frac{\\conj{w}}{w - z} \\, dw\n  \\] for $z \\in \\C$ with $\\abs{z} < 1$.\n\\end{problem}\n\n\\begin{problem}\n  Consider subsets of the real line $A = (-\\infty,-1] \\cup [1,\\infty)$\n  and $B = [-1,1]$.  Is it possible to define a branch of the\n  logarithm of $z^2 - 1$ on $\\C \\setminus A$?  What about on\n  $\\C \\setminus B$?\n\\end{problem}\n\n\\section{Exploration}\n\n\\begin{problem}\n  If we can find a branch of log $f$, then we can define a\n  single-valued $\\sqrt{f(z)}$ via $e^{(1/2) \\, \\log f}$.  Does the\n  converse hold?  Find an open set $U \\subset \\C$ and a holomorphic\n  function $f : U \\to \\C$ so that there is \\textit{no} branch of log\n  of $f$, but it is nevertheless possible to define a single-valued\n  $\\sqrt{f(z)}$.\n\\end{problem}\n\n\\begin{problem}\n  Liouville's theorem (\\ref{liouville-theorem}) states that a\n  nonconstant holomorphic function $f : \\C \\to \\C$ is not bounded.\n  Seeing \\ref{entire-is-dense}, we might ask how ``small'' can the\n  image of holomorphic function be.  Find a holomorphic function\n  $f : \\C \\to \\C$ with image equal to $\\C \\setminus \\{w\\}$.\n  (Incidentally, by \\textbf{Picard's little theorem}, you will have\n  trouble finding an entire function with image missing two points.)\n\\end{problem}\n\n\\begin{problem}\\label{cauchy-inequalities-2}Suppose\n  $f(z) = \\sum_{n=0}^\\infty a_n z^n$ is holomorphic in the disk\n  $B_R(0)$.  If $0 < r < R$, show that\n  \\[\n    \\abs{a_n} \\leq \\frac{1}{r^n} \\displaystyle\\sup_{z \\in \\partial B_r(0)} \\abs{f(z)}.\n  \\]\n  This extends \\ref{cauchy-inequalities}.\n\\end{problem}\n\n\\begin{problem}\n  Consider a nonconstant polynomial $p \\in \\mathbb{C}[z]$ of degree $n$.  Compute\n  \\[\n    \\lim_{r \\to \\infty} \\int_{\\partial B_r(0)} \\left( \\frac{p'(z)}{p(z)} - \\frac{n}{z} \\right) dz.\n  \\]\n  Can you perform this computation \\textit{without} appealing to the\n  fundamental theorem of algebra?\n\\end{problem}\n\n\\begin{problem}\\label{uniformly-approximate-conj}For $\\epsilon > 0$, is there a polynomial $p \\in \\mathbb{C}[z]$ so\n  that $\\abs{p(z) - \\conj{z}} < \\epsilon$ for $z \\in B_1(0)$?  In\n  other words, can we uniformly approximate $\\conj{z}$ by a polynomial\n  in $z$?\n\\end{problem}\n\n\\section{Prove or Disprove and Salvage if Possible}\n\n\\begin{problem}\\label{entire-is-dense}If $f : \\C \\to \\C$ is\n  holomorphic, then the image of $f$ is dense in $\\C$.\n\\end{problem}\n\n\\begin{problem}\\label{identity-dominate-entire}Suppose $f : \\C \\to \\C$\n  is holomorphic and for all $z \\in \\C$ we have\n  $\\abs{f(z)} \\leq \\abs{z}$.  Then $f(z) = \\lambda z$ for some\n  $\\lambda \\in \\C$.\n\\end{problem}\n\n\\begin{problem}\n  There is a nonconstant holomorphic function $f : \\C \\to \\C$ so that\n  for all $n \\in \\Z$ we have $f(z + n) = f(z)$.  (Such a function is\n  \\textbf{periodic}.)\n\\end{problem}\n\n\\begin{problem}\\label{doubly-periodic}There is a nonconstant holomorphic function $f : \\C \\to \\C$ so that\n  for all $\\omega \\in \\Z[i]$ we have $f(z + \\omega) = f(z)$.  (Such a\n  function is \\textbf{doubly periodic}.)\n\\end{problem}\n\n\\begin{problem}\\label{maximum-modulus-principle}Consider a connected open subset $U \\subset \\C$ and a holomorphic\n  function $f : U \\to \\C$.  If there is a point $z_0 \\in U$ so that\n  for all $z \\in U$ we have $\\abs{f(z_0)} \\geq \\abs{f(z)}$, then $f$\n  is constant.  \\textit{Hint:} show that $g(z) = \\abs{f(z)}$ is\n  constant and invoke \\ref{open-mapping-theorem-preview}.  This is the\n  \\textbf{maximum modulus principle}.\n\\end{problem}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "f4055d80ad269cf5cdb73c03953c29578cd07fa8", "size": 5188, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problem-sets/set05.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/set05.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/set05.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": 33.2564102564, "max_line_length": 115, "alphanum_fraction": 0.6613338473, "num_tokens": 1821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185944046238981, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.6003737905024881}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Taylor Series}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to Taylor series and their computation.\n\\end{abstract}\n\\maketitle\n\n\n\\begin{exercise}\nUse the Maclaurin series for $\\sin x$ to give a complete formula for the Maclaurin series for $x \\sin x^2$:\n\\[ x \\sin (x^2) = \\sum_{m=0}^\\infty  \\answer{\\frac{(-1)^m}{(2m+1)!}} x^{\\answer{4m+3}} \\]\n\\end{exercise}\n\n\\begin{exercise}\nUse the Maclaurin series for $e^x$ and $e^{-x}$ to give a complete formula for the Maclaurin series for $\\cosh x$:\n\\[ \\cosh x = \\sum_{n=0}^\\infty \\answer{\\frac{1}{(2n)!}} x^{\\answer{2n}}. \\]\n\\begin{hint}\nYour formula should account for the fact that there are only even powers of $x$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the Taylor series of the function $f(x) = \\ln x$ centered at the point $x_0 = 2$.\n\\[ \\answer{ \\ln 2} + \\answer{\\frac{1}{2}} (x-2) + \\answer{- \\frac{1}{8}}(x-2)^2 + \\answer{\\frac{1}{24}}(x-2)^3 + \\cdots = \\ln 2 + \\sum_{n=1}^\\infty \\answer{\\frac{(-1)^{n-1}2^{-n}}{n}} (x-2)^n \\]\n\\end{exercise}\n\n\n\\begin{exercise}\nCompute the Maclaurin series of the function identified below.\n\\[ \\int_0^x \\frac{\\sin t}{t} dt = \\sum_{n=0}^\\infty \\answer{\\frac{(-1)^n}{(2n+1)! (2n+1)}} x^{\\answer{2n+1}} \\]\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[TaylorExpand001]\n\nCompute the first \\(4\\) nonzero terms in the Taylor series \nat \\(x=0\\) of the function \\[\\frac{d}{dx} \\left[ x e^{x^2} \\right].\\]\n\\begin{multiplechoice}\n\\choice[correct]{\\( \\displaystyle 1 + 3x^{2} + \\frac{5}{2}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\choice{\\( \\displaystyle  - 1 - 3x^{2} + \\frac{5}{2}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\choice{\\( \\displaystyle 1 - 6x^{2} - \\frac{5}{4}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\choice{\\( \\displaystyle  - 1 - 6x^{2} + \\frac{5}{4}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\choice{\\( \\displaystyle 2 + 3x^{2} + \\frac{5}{4}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\choice{\\( \\displaystyle 2 - 3x^{2} - \\frac{5}{4}x^{4} + \\frac{7}{6}x^{6}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nCompute the series in stages beginning with substitution into known series:\n\\[e^{x^2} = 1 + x^{2} + \\frac{1}{2}x^{4} + \\frac{1}{6}x^{6} + \\cdots \\]\n\\[x e^{x^2} = x + x^{3} + \\frac{1}{2}x^{5} + \\frac{1}{6}x^{7} + \\cdots \\]\n\\[\\frac{d}{dx} \\left[ x e^{x^2} \\right] = 1 + 3x^{2} + \\frac{5}{2}x^{4} + \\frac{7}{6}x^{6} + \\cdots \\]\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[TaylorExpand011]\n\nCompute the first \\(4\\) nonzero terms in the Taylor series \nat \\(x=0\\) of the function \\[\\int_0^x \\left( x \\ln (1-x) \\right) ~ dx.\\]\n\\begin{multiplechoice}\n\\choice{\\( \\displaystyle  - \\frac{1}{6}x^{3} - \\frac{1}{8}x^{4} - \\frac{2}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\choice{\\( \\displaystyle \\frac{1}{6}x^{3} + \\frac{1}{8}x^{4} - \\frac{2}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\choice{\\( \\displaystyle  - \\frac{1}{6}x^{3} + \\frac{1}{4}x^{4} + \\frac{1}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\choice{\\( \\displaystyle \\frac{1}{6}x^{3} + \\frac{1}{4}x^{4} - \\frac{1}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\choice[correct]{\\( \\displaystyle  - \\frac{1}{3}x^{3} - \\frac{1}{8}x^{4} - \\frac{1}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\choice{\\( \\displaystyle  - \\frac{1}{3}x^{3} + \\frac{1}{8}x^{4} + \\frac{1}{15}x^{5} - \\frac{1}{24}x^{6}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nCompute the series in stages beginning with substitution into known series:\n\\[\\ln (1-x) =  - x - \\frac{1}{2}x^{2} - \\frac{1}{3}x^{3} - \\frac{1}{4}x^{4} + \\cdots \\]\n\\[x \\ln (1-x) =  - x^{2} - \\frac{1}{2}x^{3} - \\frac{1}{3}x^{4} - \\frac{1}{4}x^{5} + \\cdots \\]\n\\[\\int_0^x \\left( x \\ln (1-x) \\right) ~ dx =  - \\frac{1}{3}x^{3} - \\frac{1}{8}x^{4} - \\frac{1}{15}x^{5} - \\frac{1}{24}x^{6} + \\cdots \\]\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.01]\n\nThe first few nonzero terms of the Maclaurin series for \\(f(x) = \\ln ( 1 + \\sin x)\\) are:\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle 1 + \\frac{1}{2} x - \\frac{1}{8} x^2 + \\frac{1}{24} x^3 + \\cdots\\)}\n\\choice{\\(\\displaystyle 1 + \\frac{1}{2} x - \\frac{1}{8} x^2 - \\frac{1}{48} x^3 + \\cdots\\)} \n\\choice{\\(\\displaystyle x - \\frac{1}{2} x^2 + \\frac{1}{8} x^3 - \\frac{1}{24} x^4 + \\cdots\\)}\n\\choice{\\(\\displaystyle 1 + x + \\frac{1}{2} x^2 + \\frac{1}{3} x^3 + \\frac{1}{6} x^4 \\cdots\\)} \n\\choice[correct]{\\(\\displaystyle x - \\frac{1}{2} x^2 + \\frac{1}{6} x^3 - \\frac{1}{12} x^4 + \\cdots\\)}\n\\choice{\\(\\displaystyle 1 + x + \\frac{1}{2} x^2 + \\frac{1}{3} x^3 - \\frac{1}{12} x^4 + \\cdots\\)}\n\\end{multiplechoice}\n(Hints will not be revealed until you choose your response.)\n\\begin{feedback}\nThe first few derivatives of \\(f(x)\\) are:\n\\[\\begin{aligned}\nf(x) & = \\ln (1 + \\sin(x)) \\\\\nf'(x) & = \\frac{ \\cos x}{1 + \\sin x} \\\\\nf''(x) & = - \\frac{\\sin x}{1 + \\sin x} - \\frac{\\cos^2 x}{(1 + \\sin x)^2} \\\\\nf'''(x) & = - \\frac{\\cos x}{1 + \\sin x} + \\frac{\\sin x \\cos x}{(1 + \\sin x)^2} - \\frac{2 \\sin x \\cos x}{(1 + \\sin x)^2} + 2 \\frac{\\cos^3 x}{(1 + \\sin x)^3}\n\\end{aligned}\\]\n\\begin{hint}\nEvaluating at \\(x = 0\\) gives \\(f(0) = \\ln 1 = 0\\), \\(f'(0) = 1\\), \\(f''(0) = -1\\), and \\(f'''(0) = 1\\). Therefore the series starts with the terms \\(x - \\frac{1}{2} x^2 + \\frac{1}{6} x^3 + \\cdots\\).\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.12]\n\nFind the Taylor polynomial of degree 2 for \\(f(x) = \\sqrt{x+16}\\) centered at \\(x=9\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle 5 + \\frac{4}{5} x + \\frac{9}{250} x^2\\)}\n\\choice{\\(\\displaystyle 5 - \\frac{3}{5} (x-5) + \\frac{1}{125} (x-5)^2\\)}\n\\choice[correct]{\\(\\displaystyle 5 + \\frac{1}{10} (x-9) - \\frac{1}{1000} (x-9)^2\\)} \n\\choice{\\(\\displaystyle 5 + \\frac{3}{5} (x-5) + \\frac{8}{125} (x-5)^2\\)}\n\\choice{\\(\\displaystyle 5 + \\frac{1}{5} (x-9) + \\frac{16}{125} (x-9)^2\\)}\n\\choice{none of these}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.14]\n\nUse the Taylor polynomial of degree \\(3\\) for \\(f(x) = \\ln (1+x)\\) centered at \\(x_0 = 0\\) to approximate the value of \\(\\displaystyle \\ln \\left( \\frac{3}{2} \\right)\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\frac{2}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{3}{2}\\)}\n\\choice{\\(\\displaystyle \\frac{15}{4}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{5}{12}\\)}\n\\choice{\\(\\displaystyle \\frac{9}{24}\\)}\n\\choice{\\(\\displaystyle \\frac{11}{24}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.15]\n\nLet \\(F(x)\\) be the unique function that satisfies \\(F(0) = 0\\), \\(F'(0) = 0\\), and \\(F'(x) = \\frac{1}{x} \\sin x^3\\) for all \\(x \\neq 0\\). Find the Taylor Series of \\(F(x)\\) centered at \\(x_0 = 0\\).\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n x^{6n+3}}{(2n+1)!}\\)}\n\\choice{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n (6n+3) x^{6n+2}}{(2n+1)!}\\)}\n\\choice[correct]{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n x^{6n+3}}{(6n+3)(2n+1)!}\\)} \n\\choice{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n x^{6n+2}}{(2n+1)!}\\)}\n\\choice{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n (6n+2) x^{6n+2}}{(2n+1)!}\\)}\n\\choice{\\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n x^{2n+3}}{(6n+3)(2n+1)!}\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "1fd3b7cffaf9aacedbce4244abdc22fe72a7de50", "size": 7098, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "powerseries/26taylorseriespractice.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/26taylorseriespractice.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/26taylorseriespractice.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.0909090909, "max_line_length": 199, "alphanum_fraction": 0.5759368836, "num_tokens": 3092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.6003737831434471}}
{"text": "% Copyright 2018 Markus J. Pflaum and Daniel Spiegel, licensed under GNU FDL v1.3\n% lectures notes taken by Daniel Spiegel based on a lecture by Markus J.Pflaum\n% \n\\section{Spectral theory of bounded operators}\n\\para\nWe now apply the foundations of Hilbert space theory built in the previous sections to \nspectral theory. For the moment we will sacrifice generality and work only with bounded\nlinear operators. The spectral theory of unbounded linear operators will be treated later. \n\nLet us a recall that a linear map $A: \\hilbertH_1 \\rightarrow \\hilbertH_2$ between Hilbert spaces \nis continuous if and only if it is bounded, i.e.\\ has finite operator norm, and that \n$\\blinOps (\\hilbertH_1,\\hilbertH_2)$ is a Banach space with the operator norm. \nFor the rest of this section, $\\hilbertH$, $\\hilbertH_1$, $\\hilbertH_2, \\ldots$ will always \ndenote complex Hilbert spaces and $A$, $B$ bounded linear operators. \nWe will also now fix the base field to be complex, i.e.\\ $\\fldK = \\C$.\nLast we agree on writing $I_\\hilbertH$ or just $I$ for the identity operator on a Hilbert space \n$\\hilbertH$. \n\n\\subsec{Spectrum and Resolvent}\n\n\\begin{definition}\n  Let $A:\\hilbertH \\to \\hilbertH$ be a bounded linear operator.  A complex number $\\lambda$\n  is then called an \\emph{eigenvalue} of $A$ if there exists a nonzero $v \\in H$ such that\n  $Av = \\lambda v$. For every $\\lambda \\in \\C$ one defines the $\\lambda$-\\emph{eigenspace} of\n  $A$ as\n  \\[\n   \\operatorname{Eig}_\\lambda  (A) = \\big\\{ v \\in H \\bigmid Av = \\lambda v \\big\\} \\subset \\hilbertH,\n  \\]\n which is clearly a linear subspace of $\\hilbertH$. \n\\end{definition}\n\n\\para\n  By definition it is immediately clear that \n \\[\n   \\operatorname{Eig}_\\lambda (A) = \\ker(A - \\lambda),\n \\]\n where the $\\lambda$ on the right stands for the operator $\\lambda I$. \n In other words this means that\n $\\lambda\\in \\C$ is an eigenvalue of $A$ if and only if $A - \\lambda$ is not injective.\n\n\\begin{definition}\nLet $A \\in \\blinOps(\\hilbertH)$. We make the following definitions.\n\\begin{romanlist}\n  \\item A \\emph{regular value} of $A$ is a complex number $\\lambda$ such that $A-\\lambda$ is invertible.\n  \\item The set of all regular values is the \\emph{resolvent} of $A$, denoted $\\rset(A)$.\n  \\item A \\emph{spectral value} of $A$ is a complex number $\\lambda$ such that $A - \\lambda$ is not \n        invertible.\n  \\item The set of all spectral values is the \\emph{spectrum} of $A$, denoted $\\sigma(A)$.\n  \\item The \\emph{point} or \\emph{eigenspectrum} of $A$ is the set\n\t\\[\n\t\\sigma_\\textup{p}(A) = \\big\\{\\lambda \\in \\C \\bigmid \\ker(A - \\lambda) \\neq \\{0 \\} \\big\\}.\n\t\\]\n  \\item An \\emph{approximate eigenvalue} of $A$ is a complex number $\\lambda$ for which there exists \n        a sequence of unit vectors $(v_n)_{n\\in \\N}\\subset \\hilbertH$ such that\n\t\\[\n   \t   \\lim_{n \\rightarrow \\infty} (A - \\lambda)v_n = 0.\n\t\\]\n\tThe set $\\sigma_\\textup{ap}(A)$ is the set of all approximate eigenvalues.\n\\end{romanlist}\n\\para \nEvidently, $\\sigma(A) = \\C \\setminus \\rset(A)$ and $\\sigma_\\textup{p}(A) \\subset \\sigma_\\textup{ap}(A) \\subset \\sigma(A)$,\nand these may all be strict inclusions. Note that $A - \\lambda$ is bounded for any $\\lambda \\in \\C$, \nso the open mapping theorem \\ref{} implies that $(A - \\lambda)^{-1} \\in \\blinOps(\\hilbertH)$ when $\\lambda \\in \\rset(A)$.\nWe call the map \n\\[\n  R_\\bullet (A ):\\rset(A) \\rightarrow \\blinOps(\\hilbertH), \\quad R_\\lambda (A) = (A-\\lambda)^{-1}\n\\]\nthe \\emph{resolvent} of $A$, not to be confused with the resolvent set $\\rset(A)$. \nTo keep the notation clean, we often briefly write $R_\\lambda$ for $R_\\lambda(A)$ and leave implicit that $R_\\lambda$ depends on $A$.\n\\end{definition}\nFirst, we prove some topological properties of the spectrum and resolvent. Recall the following lemma, which generalizes the geometric series.\n\n\\begin{lemma}[Carl Neumann]\\label{thm:neumann-series} Let $A \\in \\blinOps(\\hilbertH)$. If $\\norm{A} < 1$, then $I - A$ is invertible,\n\\[\n(I - A)^{-1} = \\sum_{n=0}^\\infty A^n,\n\\]\nand\n\\[\n\\norm{(I-A)^{-1}} \\leq \\frac{1}{1 - \\norm{A}}.\n\\]\n\\end{lemma}\n\n\\begin{proof}\n  Since $\\norm{A} < 1$ and $\\norm{A^n} \\leq \\norm{A}^n$ by submultiplicativity of the operator norm, we know\n  $\\sum_{n=0}^\\infty \\norm{A^n} < \\infty$. This implies that the  family $(A^n)_{n\\in\\N}$ is absolutely summable,\n  so $\\sum_{n=0}^\\infty A^n$ exists. Furthermore, for every $N \\in \\N$ we have\n  \\begin{align*}\n    (I-A)\\sum_{n=0}^N A^n = \\left(\\sum_{n=0}^N A^n \\right)(I-A)= \\sum_{n=0}^N A^n - \\sum_{n=1}^{N+1}A^n = I - A^{N+1},\n  \\end{align*}\nwhich implies that \n\\[\n\\lim_{N \\rightarrow \\infty}(I-A)\\sum_{n=0}^N A^n = \\lim_{N \\rightarrow \\infty} \\left(\\sum_{n=0}^N A^n\\right) (I-A) = I.\n\\]\nBy continuity of multiplication in $\\blinOps(\\hilbertH)$ one gets\n\\[\n(I-A) \\sum_{n=0}^\\infty A^n = \\left(\\sum_{n=0}^\\infty A^n\\right) (I-A) = I,\n\\]\nwhich proves that $I-A$ is invertible and $(I-A)^{-1} = \\sum_{n=0}^\\infty A^n$.\n\nFinally,  one concludes by the triangle inequality and submultiplicativity of the operator norm \n\\[\n  \\norm{(I - A)^{-1}} \\leq \\sum_{n=0}^\\infty \\norm{A^n} \\leq \\sum_{n=0}^\\infty \\norm{A}^n = \\frac{1}{1 - \\norm{A}}. \n\\]\n\\end{proof}\n\n\\begin{proposition}\\label{thm:resolvent-topological-properties}\nLet $A \\in \\blinOps(\\hilbertH)$. \n\\begin{romanlist}\n\\item For any $\\lambda \\in \\rset(A)$, one has\n\t\\[\n\tB_{\\norm{R_{\\lambda}}^{-1}}(\\lambda) \\subset \\rset(A) \\ .\n\t\\]\n\tHence, $\\rset(A) \\subset \\C$ is open.\n\\item The spectrum $\\sigma(A)$ is compact and\n\t\\[\n\t\\sigma(A) \\subset \\closure{B}_{\\norm{A}}(0) \\ .\n\t\\]\n\\item\\label{ite:resolvent-expansion-large-argument} If the complex number $\\lambda$ satisfies $\\abs{\\lambda} > \\norm{A}$, then $\\lambda \\in \\rset(A)$ and\n      \\[\n\tR_\\lambda = - \\frac{1}{\\lambda} - \\sum_{n=1}^\\infty \\lambda^{-n-1}A^n \\ ,\n      \\]\n      where convergence is with respect to the operator norm.  \n\\end{romanlist}\n\\end{proposition}\n\n\\begin{proof}\n \\begin{adromanlist}\n \\item \n Fix $\\lambda \\in \\rset(A)$ and set $r = \\norm{R_{\\lambda}}^{-1}$. Let $\\mu \\in B_r(\\lambda)$. Then\n\\begin{align*}\n \\norm{(\\mu - \\lambda)R_{\\lambda}} = \\abs{\\mu - \\lambda} \\norm{R_{\\lambda}} < 1.\n\\end{align*}\nThus, by Lemma \\ref{thm:neumann-series}, one knows that $I - (\\mu - \\lambda)R_{\\lambda}$ is invertible. Since $A - \\lambda$ is invertible,\nthe composition\n\\[\n(A - \\lambda) \\, \\big( I - (\\mu - \\lambda)R_{\\lambda} \\big) = A - \\mu\n\\]\nis invertible, which proves that $\\mu \\in \\rset(A)$. Hence $\\rset(A)$ is open.\n\n\n\\item Since $\\rset(A)$ is open, the complement $\\sigma(A) = \\C \\setminus \\rset(A)$ is closed. Furthermore, if $\\abs{\\lambda} > \\norm{A}$, then $\\norm{\\lambda^{-1}A} < 1$, so $I - \\lambda^{-1}A$ and hence $A - \\lambda$ are invertible by Lemma \\ref{thm:neumann-series}. This implies that $\\lambda \\in \\rset(A)$, so $\\sigma(A) \\subset \\closure{B}_{\\norm{A}}(0)$. Since $\\sigma(A)$ is closed and bounded, it is compact.\n\\item If $\\abs{\\lambda} > \\norm{A}$, then $I - \\lambda^{-1}A$ is invertible by Lemma \\ref{thm:neumann-series} and\n\\[\n(I - \\lambda^{-1}A)^{-1} = \\sum_{n=0}^\\infty \\lambda^{-n}A^n.\n\\]\nSince $-\\lambda(A - \\lambda)^{-1} = (I - \\lambda^{-1}A)^{-1}$, one obtains\n\\[\nR_\\lambda = -\\frac{1}{\\lambda}\\sum_{n=0}^\\infty \\lambda^{-n}A^n = -\\frac{1}{\\lambda} - \\sum_{n=1}^\\infty \\lambda^{-n-1}A^n,\n\\]\nas desired.   \n\\end{adromanlist}\n\\end{proof}\n\nNext, we prove some algebraic properties of the resolvent. Hereby, $[A,B] = AB - BA$ denotes the commutator of two operators,\nas usual.\n\n\\begin{proposition}\\label{thm:resolvent-algebraic-properties}\nLet $A,B \\in \\blinOps(\\hilbertH)$. Then the following holds true.\n\\begin{romanlist}\n\\item\\label{ite:commutativity-resolvent-operator} The resolvent commutes with the operator which means that\n  \\[ [A, R_\\lambda(A) ] = 0 \\quad\\text{for all } \\lambda \\in \\rset(A) \\ . \\]\n\\item\\label{ite:commutativity-resolvent-itself}\n   The values of the resolvent commute with each other that is\n \\[ [R_\\lambda (A), R_\\mu (A)] = 0 \\quad\\text{for all } \\lambda,\\mu \\in \\rset(A) \\ . \\]\n\\item\\label{ite:first-resolvent-identity}\\textup{({\\sffamily First resolvent identity})} For all $\\lambda, \\mu \\in \\rset(A)$\n  \\[ R_\\lambda(A) - R_\\mu (A)= (\\lambda - \\mu)R_\\lambda(A) R_\\mu(A) \\ . \\]\n\\item\\textup{({\\sffamily Second resolvent identity})} For all $\\lambda \\in \\rset(A)\\cap \\rset(B)$\n  \\[ R_\\lambda (A)- R_\\lambda (B) = R_\\lambda(A)\\, (B-A) \\, R_\\lambda (B) \\ . \\] \n\\end{romanlist}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{adromanlist}\n\\item Obviously  $[A, A - \\lambda] = 0$, so\n  \\[\n    0 = R_\\lambda [A, A - \\lambda]R_\\lambda = R_\\lambda A - AR_\\lambda,\n  \\]\nas desired.\n\\setcounter{enumi}{2}\n\\item We compute\n\\begin{align*}\n(R_\\lambda - R_\\mu)(A - \\mu)(A - \\lambda) &= (R_\\lambda A - \\mu R_\\lambda)(A - \\lambda) - (A - \\lambda)\\\\\n&= (A - \\mu)R_\\lambda (A - \\lambda) - (A - \\lambda)\\\\\n&= \\lambda - \\mu ,\n\\end{align*}\nwhere we used part \\ref{ite:commutativity-resolvent-operator} to commute $R_\\lambda$ past $A$ in the second step.\nNow multiplying both sides with $R_\\lambda R_\\mu $ from the right yields the desired equality. \n\\setcounter{enumi}{1}\n\\item \n  For $\\lambda = \\mu$, one obviously has $[A_\\lambda, A_\\mu] = 0$. For $\\lambda \\neq \\mu$, one concludes from\n  \\ref{ite:commutativity-resolvent-itself}\n  \\[\n     R_\\mu R_\\lambda = \\frac{R_\\mu - R_\\lambda}{\\mu - \\lambda} = \\frac{R_\\lambda - R_\\mu}{\\lambda - \\mu} = R_\\lambda R_\\mu,\n  \\]\n  so $[R_\\lambda, R_\\mu] = 0$ for $\\lambda \\neq \\mu $ as well.\n\\setcounter{enumi}{3}\n\\item  The  last equality follows by\n  \\[ R_\\lambda(A)\\, (B-A) \\, R_\\lambda (B) =  R_\\lambda(A)\\, \\big((B-\\lambda)-(A-\\lambda) \\big) \\, R_\\lambda (B) =\n     R_\\lambda(A) - R_\\lambda (B) \\ . \\]\n\\end{adromanlist}\n\\end{proof}\n\nThe resolvent $R_\\bullet (A)$ also has some nice analytic properties which we are going to prove next. \n\\begin{proposition}\\label{thm:resolvent-analytic-properties}\n  The resolvent $R_\\bullet (A) :\\rset(A) \\rightarrow \\blinOps(\\hilbertH)$, $\\lambda \\mapsto R_\\lambda$ is continuous and complex\n  differentiable with derivative given by \n  \\[\n    R_\\bullet(A)' :\\: \\rset(A) \\rightarrow \\blinOps(\\hilbertH),  \\: \\lambda \\mapsto \\lim_{\\mu \\rightarrow \\lambda} \\frac{R_\\mu - R_\\lambda}{\\mu - \\lambda} =  R_\\lambda^2\n  \\]\n\\end{proposition}\n\n\\begin{proof}\nFix $\\lambda \\in \\rset(A)$ and $\\varepsilon > 0$. Let $0 < \\abs{\\mu - \\lambda} < \\delta$, where \n\\[\n  \\delta = \\min\\left( \\frac{\\varepsilon}{2\\norm{R_\\lambda}^2},\\, \\frac{1}{2\\norm{R_\\lambda}} \\right) \\ .\n\\]\nNote that $\\mu \\in \\rset(A)$ by Proposition \\ref{thm:resolvent-topological-properties}. Moreover, $\\norm{(\\mu - \\lambda)R_\\lambda} <1$, so $I - (\\mu - \\lambda)R_\\lambda$ is invertible with norm less than $(1 - \\norm{(\\mu - \\lambda) R_\\lambda})^{-1}$ by Lemma \\ref{thm:neumann-series}.\nNow observe that the first resolvent identity can be rearranged to\n\\[\nR_\\mu =  R_\\lambda[I - (\\mu - \\lambda)R_\\lambda]^{-1} \\ .\n\\]\nHence\n\\begin{align*}\n\\norm{R_\\mu - R_\\lambda} &\\leq \\abs{\\mu - \\lambda}\\norm{R_\\mu}\\norm{R_\\lambda} \\\\\n&\\leq \\abs{\\mu - \\lambda} \\norm{R_\\lambda}^2 \\norm{(I - (\\mu - \\lambda)R_\\lambda)^{-1}}\\\\\n&\\leq \\frac{\\abs{\\mu - \\lambda} \\norm{R_\\lambda}^2}{1 - \\norm{(\\mu - \\lambda)R_\\lambda}}\\\\\n&< \\frac{\\varepsilon/2}{1-1/2} = \\varepsilon \\ .\n\\end{align*}\nThis proves that $\\lambda \\mapsto R_\\lambda$ is continuous. \n\nAs for complex differentiability, we simply use the first resolvent identity and continuity to conclude\n\\[\n\\lim_{\\mu \\rightarrow \\lambda} \\frac{R_\\mu - R_\\lambda}{\\mu - \\lambda} = \\lim_{\\mu \\rightarrow \\lambda} R_\\mu R_\\lambda = R_\\lambda^2. \n\\]\n\\end{proof}\n\n\\begin{proposition}\\label{thm:resolvent-limes-infinity}\nLet $A \\in \\blinOps(\\hilbertH)$. Then $\\lambda R_\\lambda \\rightarrow -I$ as $\\abs{\\lambda} \\rightarrow \\infty$. In particular, $R_\\lambda \\rightarrow 0$ as $\\abs{\\lambda} \\rightarrow \\infty$.\n\\end{proposition}\n\n\\begin{proof}\nFix $\\varepsilon > 0$.  For $\\abs{\\lambda} > \\norm{A}$, we have by \\Cref{thm:resolvent-topological-properties} \\ref{ite:resolvent-expansion-large-argument}\n\\[\n\\lambda R_\\lambda = -I - \\sum_{n=1}^\\infty \\lambda^{-n}A^n.\n\\]\nSince \n\\[\n\\norm{\\sum_{n=1}^\\infty \\lambda^{-n}A^n} \\leq  \\frac{\\norm{A}}{\\abs{\\lambda}-\\norm{A}},\n\\]\none sees that $\\lambda R_\\lambda \\rightarrow - I$ as $\\abs{\\lambda} \\rightarrow \\infty$. Similarly, for $\\abs{\\lambda} > \\norm{A}$ one has\n\\[\n\\norm{R_\\lambda} \\leq \\frac{1}{\\abs{\\lambda}} + \\frac{1}{\\abs{\\lambda}}\\sum_{n=1}^\\infty \\norm{\\lambda^{-n}A^n} \\leq \\frac{1}{\\abs{\\lambda}} + \\frac{1}{\\abs{\\lambda}} \\frac{\\norm{A}}{\\abs{\\lambda} - \\norm{A}},\n\\]\nwhich shows that $R_\\lambda \\rightarrow 0$ as $\\abs{\\lambda} \\rightarrow \\infty$.\n\\end{proof}\n\n\\begin{proposition}\nFor all $v, w \\in \\hilbertH$, the map \n\\[\n \\inprod{ R_\\bullet (A) v,  w} : \\: \\rset(A) \\rightarrow \\C , \\: \\lambda \\mapsto \\inprod{ R_\\lambda v, w}\n\\]\nis holomorphic with derivative\n\\[\n \\inprod{ R_\\bullet (A) v, w}' : \\: \\rset(A) \\rightarrow \\C , \\: \\lambda \\mapsto \\inprod{R_\\lambda^2 v,  w}.\n\\]\n\\end{proposition}\n\n\\begin{proof}\nGiven $\\lambda \\in \\rset(A)$, we compute\n\\begin{align*}\n  \\lim_{\\mu \\rightarrow \\lambda} \\frac{\\inprod{R_\\mu v, w} - \\inprod{R_\\lambda v,  w}}{\\mu - \\lambda} =\n  \\lim_{\\mu \\rightarrow \\lambda} \\frac{\\inprod{(\\mu - \\lambda)R_\\mu R_\\lambda v,  w}}{\\mu - \\lambda} =\n  \\lim_{\\mu \\rightarrow \\lambda} \\inprod{ R_\\mu R_\\lambda v, w} = \\inprod{R_\\lambda^2v , w},\n\\end{align*}\nwhere we have used the first resolvent identity in the first step and continuity of the inner product in the last.\n\\end{proof}\n\n\\begin{proposition}\nThe spectrum of an operator $A \\in \\blinOps(\\hilbertH)$ is nonempty.\n\\end{proposition}\n\n\\begin{proof}\nSuppose $\\sigma(A) = \\emptyset$, hence $\\rset(A) = \\C$. The map\n\\[\n\\C \\to \\C , \\: \\lambda \\mapsto \\inprod{R_\\lambda v, w}\n\\]\nthen is entire for every $v, w \\in \\hilbertH$. Furthermore, one has  for $\\norm{v}, \\norm{w} \\leq 1$\n\\[\n  \\abs{\\inprod{R_\\lambda v,  w}} \\leq  \\norm{R_\\lambda} \\norm{v} \\norm{w} \\leq \\norm{R_\\lambda} \\ .\n\\]\nSince $\\lambda \\mapsto \\norm{R_\\lambda}$ is continuous and $\\norm{R_\\lambda} \\rightarrow 0$ as $\\abs{\\lambda} \\rightarrow \\infty$, one sees\nthat $\\norm{R_\\lambda}$ is bounded. Hence $\\inprod{R_\\bullet v,  w}$ is a bounded entire function, which  by Liouville's theorem implies\nthat it is zero for every pair $v, w \\in \\hilbertH$ with $\\norm{v} = \\norm{w} = 1$.\nThis entails that $R_\\lambda = 0$ for every $\\lambda \\in \\C$, which \nis a contradiction to $R_\\lambda$ being invertible. Hence $\\sigma(A) \\neq \\emptyset$.\n\\end{proof}\n\n\n", "meta": {"hexsha": "23272252973f6881078f3ac6de8dfeab0945125f", "size": 14310, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/spectral-theory-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/spectral-theory-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/spectral-theory-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": 47.8595317726, "max_line_length": 415, "alphanum_fraction": 0.6547868623, "num_tokens": 5160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.6003737747776762}}
{"text": "\\section{Stabilization and Weak Formulation}\n\\label{app:stab}\n\nThis appendix details the weak formulation of the Navier Stokes\nequations instantiated in the software GRINS, as well as providing a\nderivation of the $\\tau$ stabilization terms. \n\nIn brief, our process is the following: \n\n\\begin{itemize}\n \\item Cast Navier Stokes + Boussinesq equations into weak form\n \\item Prepare as an operator $Lc=f$\n \\item Calculate Fr\\'echet derivative\n \\item Separate into differential (P) and constant (Z) components,\n       $L'[c] = P + Z$\n \\item Choose stabilization operator such that $S = -P^*$\n \\item Then stabilization has form, $a_h(c,\\phi) = a(c,\\phi) + \\langle\n       Lc,S\\phi \\rangle_\\tau$\n\\end{itemize}\n\nThis is essentially the least-squares stabilization proposed by Hughes\nand extended to natural convection by Becker and Braack. \n\n%\n% start the real work\n%\n\n\\subsection{Weak Formulation of Equations of Interest}\n\nWe begin with the incompressible Navier-Stokes equations with Bousinesq\nbuoyancy,\n\\begin{align}\n \\nabla \\cdot u &= \\, 0 \\label{eq_cont}\\\\\n \\frac{\\partial u}{\\partial t} + u \\cdot \\nabla u &= -\\frac{1}{\\rho}\n \\nabla p + \\nu \\nabla^2 u + g \\frac{T'}{T_0} \\label{eq_mom}\\\\\n \\rho c_p \\frac{\\partial T}{\\partial t} + u \\cdot \\nabla T &= \\nabla\n \\cdot (k \\nabla T) \\label{eq_energy}\n\\end{align}\ne.g. the continuity, momentum and energy equations, respectively. Our \nstate vector is $c =  \\left[p,u,T \\right]$. To cast these into\nweak form we multiply by appropriate test \nfunctions $\\phi = \\left[q,v,w \\right] \\in H^1_0(\\Omega)$ and integrate over\nthe domain, $\\Omega \\in \\mathbb{R}^n$. Our system of equations now\nappears as, \n\\begin{align}\n  \\bigintsss_\\Omega q \\nabla \\cdot u \\, dx &= 0 \\\\\n \\bigintsss_\\Omega \\dot u \\cdot v \\, dx +\n \\bigintsss_\\Omega  (u \\cdot \\nabla) \\, u \\cdot v \\, dx &=\n \\bigintsss_\\Omega \\frac{p}{\\rho} \\nabla \\cdot v \\, dx - \\nu \\bigintsss_\\Omega \\nabla u \\cdot \\nabla v\n \\,dx + \\bigintsss_\\Omega g \\frac{T'}{T_0} \\cdot v \\, dx \\\\ \n \\rho c_p \\bigintsss_\\Omega \\dot T \\cdot w \\, dx + \\bigintsss_\\Omega (u\n \\cdot \\nabla) T \\cdot w \\, dx  &= -\\bigintsss_\\Omega (k \\nabla T) \\cdot\n \\nabla w \\, dx\n\\end{align}\n\nwhere an ``over-dot'' denotes time diffentiation, e.g. $\\dot u =\n\\frac{\\partial u}{\\partial t}$. Note that both the pressure term as well\nas the viscous term were integrated by parts to reduce the required\norder of the solution on those state variables.  \n\nWe define the inner product by the shorthand notation $(u,v) =\n\\bigintsss_\\Omega u\\cdot v dx $, giving our equations the form,  \n\\begin{align}\n (\\nabla \\cdot u, q) &= 0 \\\\\n (\\dot u,v) + (u \\cdot \\nabla u, v) - (p,\\nabla \\cdot v) + \\nu (\\nabla\n u, \\nabla v) &= (g \\frac{T'}{T_0},v) \\\\\n \\rho c_p (\\dot T,w) + (u \\cdot \\nabla T,w) + (k \\nabla T,\\nabla w) &= 0.\n\\end{align}\n\nThis defines our weak form operator $a(c,\\phi)$. Our full equations will\nalso include a stabilization term such that,  \n\\begin{equation}\n a_h(c,\\phi) = a(c,\\phi) +  \\langle Lc,S\\phi \\rangle_\\tau. \n\\end{equation}\n\nThe subsequent section will define the operators L and S, so that we\nmight then fully define the stabilization term $\\langle Lc,S\\phi\n\\rangle_\\tau$. \n\n%\n% subsection\n%\n\\subsection{The operators L and S}\n\n\nTo form the stabilization terms, \n\n\\begin{equation}\n \\langle Lc,S\\phi \\rangle_\\tau\n\\end{equation}\n\nwe must define the operators L and S. The operator L is simply the PDEs\nin Equations \\ref{eq_cont} - \\ref{eq_energy} written in operator form. S is\ndefined as the negative adjoint of the differential terms in L, e.g.\n\\begin{align}\n L'[c] = P + Z \\\\\n S = -P^*. \n\\end{align}\nWhere P are the differential terms, and Z the constant terms. \n\nOur objective is now to construct the adjoint operator of L. This is\naccomplished using the Fr\\'echet derivative, which defines the\nfunctional derivative on L. In general this is accomplished by taking\nthe first variation of a function $\\Pi(u)$ around a base state, $u$,\n\\begin{equation}\n \\delta\\, \\Pi(u) = \\lim_{\\epsilon \\to 0} \\frac{\\Pi(u+\\epsilon \\hat u) -\n  \\Pi(u)}{\\epsilon} =\n  \\frac{\\partial \\Pi(u +\\epsilon \\hat u)}{\\partial \\epsilon}\n  \\bigg|_{\\epsilon = 0}\n\\end{equation}\nfor all $\\hat u$ and $\\epsilon > 0$ with $u + \\epsilon \\hat u \\in\nH^1_0(\\Omega)$. This is recognizable as the G\\^{a}teaux\nderivative of the functional. \n\n\nWe now consider the first variation of state for the momentum equation\nterm by term. The convective term is, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} (u + \\epsilon \\hat u) &\\cdot \\nabla\n  (u + \\epsilon \\hat u) \\\\\n = \\lim_{\\epsilon \\to 0} \\hat u &\\cdot \\nabla (u + \\epsilon \\hat u) \\\\\n = \\hat u & \\cdot \\nabla u \\\\\n = - u &\\cdot \\nabla \\hat u\n\\end{align}\nand the viscous term is, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\nabla^2 (u + \\epsilon \\hat u) \\\\\n = \\nabla^2 \\hat u\n\\end{align}\nwhile the buoyancy term is, \n\\begin{align}\n \\delta \\left(-g \\frac{T'}{T_0}\\right) &= \\delta \\left( -g\n \\frac{T-T_0}{T_0} \\right) \\\\\n &= -g \\frac{\\partial}{\\partial \\epsilon} \\left( \\frac{T-T_0+\\epsilon\n \\hat T}{T_0} \\right) \\\\\n &= -g \\left( \\frac{\\hat T}{T_0} \\right) \n\\end{align}\n\n\n%Lagrangian is therefore, $\\mathcal{L}$\nand thus the full adjoint equation for momentum appears as\n\\begin{align}\n - u &\\cdot \\nabla \\hat u - \\nabla^2 \\hat u = -\\frac{1}{\\rho} \\nabla p. \n\\label{eq_adjmom}\n\\end{align}\n\nThe continuity equation is straightforward, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\nabla \\cdot (u + \\epsilon \\hat\n u) = 0 \\\\\n\\nabla \\cdot \\hat u = 0.\n\\label{eq_adjcont}\n\\end{align}\n\nFinally, consider the convective term of the energy equation, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} u \\cdot \\nabla (T + \\epsilon \\hat T)\n = u \\cdot \\nabla \\hat T\n\\end{align}\nand the thermal diffusion term, \n\\begin{align}\n \\frac{\\partial}{\\partial \\epsilon} \\cdot (-k \\nabla (T + \\epsilon \\hat\n T)) = \\nabla \\cdot (-k \\nabla \\hat T).\n\\end{align}\nThe full adjoint energy equation is therefore, \n\\begin{align}\n u \\cdot \\nabla \\hat T + \\nabla \\cdot (k \\nabla \\hat T) =0.\n\\label{eq_adjen}\n\\end{align}\n\nWe are now in a position to define the matricies L and S. L comes\ndirectly from the PDEs in Equations \\ref{eq_cont} - \\ref{eq_energy} and is\ndefined as thus, \n\n\\begin{equation}\n\\renewcommand\\arraystretch{2}\n L = \n  \\begin{pmatrix}\n    0 & \\nabla \\cdot () & 0   \\\\\n    \\nabla \\,() & u \\cdot \\nabla() - \\nu \\nabla^2() & -g \\frac{()}{T_0}  \\\\\n    0 & 0 & u \\cdot \\nabla() - \\nabla \\cdot (k \\nabla() \\,)\n  \\end{pmatrix}.\n\\end{equation}\n\nWhile the S matrix is constructed from Equations\n\\ref{eq_adjmom}, \\ref{eq_adjcont}, and \\ref{eq_adjen} must be, \n\\begin{equation}\n\\renewcommand\\arraystretch{2}\n S = -P^* = \n  \\begin{pmatrix}\n    0 & \\nabla \\cdot () & 0   \\\\\n    \\nabla \\,() & u \\cdot \\nabla() + \\nu \\nabla^2() &  -g \\frac{()}{T_0}  \\\\\n    0 & 0 & u \\cdot \\nabla() + \\nabla \\cdot k \\nabla()\n  \\end{pmatrix}.\n\\end{equation}\n\n%\n% tau!\n%\n\\subsection{Tau stabilization terms}\n\nFinally, we may now form the $\\tau$ stabilization terms, \n\\begin{equation}\n \\langle Lc,S\\phi \\rangle_\\tau. \n\\end{equation}\nWhere the operator $ \\langle \\cdot,\\cdot \\rangle_\\tau. $ is shorthand \nand denotes\n\\begin{equation}\n \\langle u,v \\rangle_\\tau = \\sum_K \\tau_K (u,v)_K.\n\\end{equation}\nWhere $K$ denotes the FEM cells. Now, through what Becker and Braack\ncontemptibly referred to as ``elementary calculus'', we now discover our\nstabilization terms,  \n\\begin{align*}\n \\langle Lc,S\\phi \\rangle_\\tau = \\sum_K \\{ \\quad &\\tau_p (\\nabla \\cdot u,\n \\nabla \\cdot v) \\\\\n +\\quad &\\tau_u \\,(\\nabla p + u \\cdot \\nabla u - \\nu \\nabla^2 - g \\frac{T'}{T_0},\n \\nabla q) \\\\\n +\\quad &\\tau_u \\, (\\nabla p + u \\cdot \\nabla u - \\nu \\nabla^2 - g \\frac{T'}{T_0},\n \\nabla u \\cdot \\nabla v + \\nu \\nabla^2 v) \\\\\n +\\quad &\\tau_T \\, (u \\cdot T - \\nabla \\cdot (k \\nabla T), \\nabla u \\cdot \\nabla\n w + \\nabla \\cdot (k \\nabla w)) \\}.\n\\end{align*}\n\n", "meta": {"hexsha": "95f9e6b8357cac772e8d145666a6f0bcd8b620b8", "size": 7763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "disputatio/propositum/stab.tex", "max_stars_repo_name": "nicholasmalaya/paleologos", "max_stars_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-04T17:49:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-04T17:49:42.000Z", "max_issues_repo_path": "disputatio/propositum/stab.tex", "max_issues_repo_name": "nicholasmalaya/paleologos", "max_issues_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "disputatio/propositum/stab.tex", "max_forks_repo_name": "nicholasmalaya/paleologos", "max_forks_repo_head_hexsha": "11959056caa80d3c910759b714a0f8e42f986f0f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-01-04T16:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-16T19:34:24.000Z", "avg_line_length": 34.5022222222, "max_line_length": 102, "alphanum_fraction": 0.6661084632, "num_tokens": 2717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.600246494721008}}
{"text": "\\documentclass[]{article}\n\n\\author{Braden Fineberg}\n\\usepackage[pdftex]{graphicx}\n\\usepackage{achicago}\n\\usepackage{fullpage}\n\\usepackage{ amssymb }\n\\usepackage{amsmath} \n%\\usepackage[top=1in, bottom=1in, left= 1 in, right=1in]{geometry}\n\\usepackage{setspace}\n\\usepackage[nopar]{lipsum} % for dummy text\n\\newcommand{\\HRule}{\\rule{\\linewidth}{0.25mm}}\n\n\\usepackage{listings}\n\\usepackage{subfig}\n\\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white\n\\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue\n\\definecolor{mylilas}{RGB}{170,55,241}\n\\renewcommand\\thesection{\\Alph{section}}\n\n\n\\begin{document}\n\t\n\t\\lstset{language=Matlab,%\n\t\t%basicstyle=\\color{red},\n\t\tbreaklines=true,%\n\t\tmorekeywords={matlab2tikz},\n\t\tkeywordstyle=\\color{blue},%\n\t\tmorekeywords=[2]{1}, keywordstyle=[2]{\\color{black}},\n\t\tidentifierstyle=\\color{black},%\n\t\tstringstyle=\\color{mylilas},\n\t\tcommentstyle=\\color{mygreen},%\n\t\tshowstringspaces=false,%without this there will be a symbol in the places where there is a space\n\t\tnumbers=left,%\n\t\tnumberstyle={\\tiny \\color{black}},% size of the numbers\n\t\tnumbersep=9pt, % this defines how far the numbers are from the text\n\t\temph=[1]{for,end,break},emphstyle=[1]\\color{red}, %some words to emphasise\n\t\t%emph=[2]{word1,word2}, emphstyle=[2]{style},  \n\t\tbasicstyle=\\tiny,  \n\t}\n\n\\input{../title.tex} \n\n\\section{CTMC states}\nGiven the integer nature of the problem, $X(t)$ will be integer values between 0 and max.\n\n\\section{Transition times out of given state}\nThe transition time will be the first occurrence of anything that changes the value of X. Given that the chance of a claim, premium or dividend is paid are all exponentially distributed, the transition time will also be exponential. Lack of transition is the case in which no event happens. Exponential distributions are additive, therefore, $$T_{leave} = min\\{T_p, T_c, T_d\\} \\qquad T_{stay} = e^{-(\\lambda + \\alpha + \\beta)t}$$\n\\begin{center}\n\t\\begin{tabular}{|| c | c | c||} \n\t\t\\hline\n\t\tRange & Event & $v_x$ \\\\ [0.5ex] \n\t\t\\hline\\hline\n\t\tA & premium & $\\lambda$ \\\\ \n\t\t\\hline\n\t\tB & premium \\& claim paid @ $X(t)$& $\\lambda + \\alpha$ \\\\\n\t\t\\hline\n\t\tC & premium \\& claim paid & $\\lambda + \\alpha$ \\\\\n\t\t\\hline\n\t\tE & claim, dividend & $\\lambda + \\beta$ \\\\ [.5ex] \n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\section{Possible states going out of X(t) = x}\nGiven that there are only four options for each transition out of x, \n\\begin{center}\n\t\\begin{tabular}{|| c | c | c||} \n\t\t\\hline\n\t\tRange & Event & Possible States \\\\ [0.5ex] \n\t\t\\hline\\hline\n\t\tA & premium & x+1 \\\\ \n\t\t\\hline\n\t\tB & premium \\& claim paid @ $X(t)$& x+1, net 0 \\\\\n\t\t\\hline\n\t\tC & premium \\& claim paid & x+1-c \\\\\n\t\t\\hline\n\t\tE & claim, dividend & x-c-d\\\\ [.5ex] \n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\n\\section{Transition probabilities}\nGiven Baye's theory, \n\\begin{center}\n\tP\\{premium payment$|$ a transition happens\\} =$\\frac{\\text{\tP\\{premium payment\\}}\\ \\cap \\text{ P\\{transition happens\\}}}{\\text{P\\{transition happens\\}}}$\n\\end{center}\n$$= \\frac{\\lambda}{\\lambda+\\alpha+\\beta }$$\n\\begin{center}\n\t\\begin{tabular}{|| c | c | c||} \n\t\t\\hline\n\t\tRange & State j & Transition P \\\\ [0.5ex] \n\t\t\\hline\\hline\n\t\tA & 1 & $\\frac{\\lambda}{\\lambda}$ \\\\ \n\t\t\\hline\n\t\tB & x+1 & $\\frac{\\lambda}{\\lambda + \\alpha}$ \\\\\n\t\t\\hline\n\t\tB & 0 & $\\frac{\\alpha}{\\lambda + \\alpha}$ \\\\\n\t\t\\hline\n\t\tC & x+1 & $\\frac{\\lambda}{\\lambda + \\alpha}$ \\\\\n\t\t\\hline\n\t\tC & x-c & $\\frac{\\alpha}{\\lambda + \\alpha}$ \\\\\n\t\t\\hline\n\t\tE & x-c & $\\frac{\\alpha}{\\beta + \\alpha}$\\\\ \n\t\t\\hline\n\t\tE & x-d & $\\frac{\\beta}{\\beta + \\alpha}$\\\\[.5ex] \n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\n\\section{Simulation}\n\\begin{lstlisting}\nfunction [X,T] = cfSim(lambda,beta, alpha, X0, c, d, Xr, Xmax, Tmax)\n\ni = 1;\nT(i) = 0;\nX(i) = X0;\nadd = [1, -c, -d];\n\nwhile T(i) < Tmax\n\tx=X(i);\n\ttp = exprnd(1/lambda);\n\ttc = exprnd(1/alpha);\n\ttd = exprnd(1/beta);\n\t\n\tif x==0\n\t\tT(i+1) = T(i) + tp;\n\t\tX(i+1)=x+1;\n\telseif  0<x && x<Xr\n\t\t[m, ind]=min([tp,tc]);\n\t\tT(i+1) = T(i) + m;\n\t\tX(i+1) = x + add(ind);\n\telseif Xr <= x && x < Xmax\n\t\t[m, ind]=min([tp,tc,td]);\n\t\tT(i+1) = T(i) + m;\n\t\tX(i+1) = x + add(ind);\n\telseif x==Xmax\n\t\t[m, ind] = min([realmax,tc,td]);\n\t\tT(i+1) = T(i) + m;\n\t\tX(i+1) = x + add(ind);\n\telse\n\t\tbreak;\n\tend\n\ti=i+1;\nend\n\\end{lstlisting}\n\nThe code above was used to generate:\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figures/Cashflow}\n\t\\caption{Cash On Hand @ time t}\n\t\\label{fig:cashflow}\n\\end{figure}\n\n\\section{Kolmogorov's Forward Equation}\nGiven the lecture notes, \n\\begin{center}\n\t\\begin{tabular}{|| c | c | c | c ||} \n\t\t\\hline\n\t\tRange & State j @ t+1 & $v_x\\cdot p_{xy}$ & $q_{xy}$\\\\ [0.5ex] \n\t\t\\hline\\hline\n\t\tA & 1 & $\\frac{\\lambda}{\\lambda} \\cdot \\lambda$ & $\\lambda$ \\\\ \n\t\t\\hline\n\t\tB & x+1 & $\\frac{\\lambda}{\\lambda + \\alpha} \\cdot (\\lambda + \\alpha)$ & $\\lambda$\\\\\n\t\t\\hline\n\t\tB & 0 & $\\frac{\\alpha}{\\lambda + \\alpha}\\cdot (\\lambda + \\alpha)$ & $\\alpha$ \\\\\n\t\t\\hline\n\t\tC & x+1 & $\\frac{\\lambda}{\\lambda + \\alpha} \\cdot (\\lambda + \\alpha)$ & $\\lambda$\\\\\n\t\t\\hline\n\t\tC & x-c & $\\frac{\\alpha}{\\lambda + \\alpha}\\cdot (\\lambda + \\alpha)$ & $\\alpha$\\\\\n\t\t\\hline\n\t\tD & x-c & $\\frac{\\alpha}{\\lambda + \\beta + \\alpha}\\cdot (\\lambda + \\alpha + \\beta)$& $\\alpha$\\\\ \n\t\t\\hline\n\t\tD & x+1 & $\\frac{\\lambda}{\\lambda + \\beta + \\alpha}\\cdot (\\lambda + \\alpha + \\beta)$& $\\lambda$\\\\ \n\t\t\\hline\n\t\tD & x-d & $\\frac{\\beta}{\\lambda + \\beta + \\alpha}\\cdot (\\lambda + \\alpha + \\beta)$& $\\beta$\\\\ \n\t\t\\hline\n\t\tE & x-d & $\\frac{\\beta}{\\beta + \\alpha}\\cdot (\\beta + \\alpha)$& $\\beta$\\\\\n\t\t\\hline\n\t\tE & x-c & $\\frac{\\alpha}{\\beta + \\alpha}\\cdot (\\beta + \\alpha)$& $\\alpha$\\\\[.5ex] \n\t\t\\hline\n\t\\end{tabular}\n\\end{center}\nTherefore, by plugging the various probabilities into the Kolmogorov's equations, I can generate the following:\n\\subsection{Range A, Y = 0}\n$$\\alpha\\sum_{k=1}^{c} P_{xk}-\\lambda P_{xy}$$\n\\subsection{Range B, 0 $<$ Y $<$ c}\n$$\\lambda P_{x,Y-1} + \\alpha P_{x, Y+c} - (\\lambda + \\alpha)P_{xY}$$\n\\subsection{Range C, c $\\leq$ Y $<$ X$_r$}\nGiven the dividend cannot surpass X$_r$,\n$$\\lambda P_{x,Y-1} + \\alpha P_{x, Y+c} - (\\lambda + \\alpha)P_{xY}$$\nGiven the dividend can surpass X$_r$,\n$$\\lambda P_{x,Y-1} + \\alpha P_{x, Y+c} + \\beta P_{x, Y+d} - (\\lambda + \\alpha)P_{xY}$$\n\\subsection{Range D, X$_r$ $<$ Y $\\leq$ Xmax}\nThe transition is close enough to Y that a claim or dividend can cause the transition:\n$$\\lambda P_{x,Y-1} + \\alpha P_{x, Y+c} + \\beta P_{x, Y+d} - (\\lambda + \\alpha + \\beta)P_{xY}$$\nWhen the transition cannot be caused by a claim or dividend:\n$$\\lambda P_{x,Y-1} - (\\lambda + \\alpha + \\beta)P_{xY}$$\nWhen a transition can only be caused a claim or premium:\n$$\\lambda P_{x,Y-1} + \\alpha P_{x, Y+c} - (\\lambda + \\alpha + \\beta)P_{xY}$$\nWhen the transition can only be caused by a dividend or premium:\n$$\\lambda P_{x,Y-1} + \\beta P_{x, Y+d} - (\\lambda + \\alpha + \\beta)P_{xY}$$\n\\subsection{Range E, Y = Xmax}\n$$\\lambda P_{x,Y-1} - (\\alpha + \\beta)P_{xY}$$\n\n\\section{Kolmogorov's Backwards Equations}\n\\subsection{Range A, X = 0}\n$$\\lambda P_{X+1, y} - P_{X,y}$$\n\\subsection{Range B, 0 < X < c}\n$$\\lambda P_{X+1, y} + \\alpha P_{0, y} - (\\lambda + \\alpha) P_{X,y}$$\n\\subsection{Range C, c $\\leq$ X < X$_r$}\n$$\\lambda P_{X+1, y} + \\alpha P_{x-c, y} - (\\lambda + \\alpha) P_{X,y}$$\n\\subsection{Range D, X$_r$ $\\leq$ X $<$ Xmax}\n$$\\lambda P_{X+1, y} + \\alpha P_{x-c, y} + \\beta P_{x-d, y} - (\\lambda + \\alpha + \\beta) P_{X,y}$$\n\\subsection{Range E, X = Xmax}\n$$\\alpha P_{x-c, y} + \\beta P_{x-d, y} - (\\alpha + \\beta) P_{X,y}$$\n\n\\section{Solution of Kolmogorov’s equations}\n\\begin{lstlisting}\nfunction [R]=Kolm(lambda,alpha,beta,c,d,Xr,Xmax)\n\t%UNTITLED2 Summary of this function goes here\n\t%   Detailed explanation goes here\n\tR=zeros(Xmax+1);\n\tR(1, 1) = -lambda;\n\tR(Xmax+1, Xmax)=lambda;\n\tR(Xmax+1, Xmax+1)=-(alpha+beta);\n\t\n\tfor i=1:Xmax+1\n\t\tif i>=2 && i <=Xr-d\n\t\t\tR(i,i)=-(lambda+alpha);\n\t\t\tR(i, i-1) = lambda;\n\t\t\tR(i, i+c) = alpha;\n\t\telseif i>=Xr-d+1 && i<=Xmax-d+1\n\t\t\tR(i, i-1) = lambda;\n\t\t\tR(i,i+c)=alpha;\n\t\t\tR(i,i+d)=beta;\n\t\t\tif i>= Xr+1\n\t\t\t\tR(i,i)=-(lambda+alpha+beta);\n\t\t\telse\n\t\t\t\tR(i,i)=-(lambda+alpha);\n\t\tend\n\t\t\telseif i >= Xmax-d+2 && i<= Xmax-c+1\n\t\t\tR(i,i-1)=lambda;\n\t\t\tR(i,i+c)=alpha;\n\t\t\tR(i,i)=-(lambda+alpha+beta);\n\t\telseif i>= Xmax-c+2 && i<=Xmax\n\t\t\tR(i,i-1)=lambda;\n\t\t\tR(i,i)=-(lambda+alpha+beta);\n\t\tend  \n\tend\nend\n\\end{lstlisting}\nThe code above was used to generate the following: \n\\begin{figure}[!ht]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figures/pmf}\n\t\\caption{Probability Mass Function of Realizations}\n\t\\label{fig:pmf}\n\\end{figure}\n\\pagebreak\n\\section{PMF of Dividends}\n\\begin{lstlisting}\ns = 0;\nfor i=1:1000\n[x,~] = cfSim(lambda,beta, alpha, X0, c, d, Xr, Xmax, Tmax);\na = x(2:end);\ndiff = a-x(1:end-1);\nif ~isempty(find(diff == -d, 1))\ns = s+1;\nend\nend\ndisp(s/100);\n\n%%\npmf = zeros(100, 21);\nfor i=1:100\n\t[x,t] = cfSim(lambda,beta, alpha, X0, c, d, Xr, Xmax, Tmax);\n\ta = x(2:end);\n\tdiff = a-x(1:end-1);\n\t\n\tT = .25:.25:5;\n\tedges = zeros(1, length(T));\n\tfor tm = 1:length(T)\n\t\t[~,ind] = find(t<=T(tm), 1, 'last');\n\t\tedges(tm) = ind;\n\t\tend\n\t\t\n\t\tedges(edges > length(diff)) = length(diff);\n\t\t\n\t\tedges = [1,edges];\n\t\tp = zeros(1, 21);\n\t\tfor e=2:21\n\t\tp(e-1) = length(find(diff(edges(e-1):edges(e)) == -d));\n\tend\n\tpmf(i, :) = p/sum(p);\nend\npmf(any(isnan(pmf), 2),:)=[];\navg = mean(pmf);\nstairs(0:20, avg);\ngrid on;\ntitle('average pmf of paying a dividend at in quarter q (100 trials)');\nxlabel('q');\nylabel('pmf');\nsaveas(gcf, 'pmfDividend.png');\n\\end{lstlisting}\nThe code above was used to generate the following: \n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figures/pmfDividend}\n\t\\caption{Average pmf, 100 trials}\n\t\\label{fig:pmfdividend}\n\\end{figure}\n\\pagebreak\n\\\\\nThis indicates that over 20 quarters, the insurance company will almost always pay a dividend. However, the probability that the company will pay a dividend in quarter q varies from approx. 7.5\\% to 3.75\\% \n\n\n\\end{document}\n", "meta": {"hexsha": "63fb67474bc95b6c02f6f9a631d9885408ba367c", "size": 9870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework8.tex", "max_stars_repo_name": "bfine9618/InsuranceClaimSimulation", "max_stars_repo_head_hexsha": "7d212a9cf1ca3c57393483ae8038bfef36923bb6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-02T07:56:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T07:56:28.000Z", "max_issues_repo_path": "Homework8.tex", "max_issues_repo_name": "bfine9618/InsuranceClaimSimulation", "max_issues_repo_head_hexsha": "7d212a9cf1ca3c57393483ae8038bfef36923bb6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework8.tex", "max_forks_repo_name": "bfine9618/InsuranceClaimSimulation", "max_forks_repo_head_hexsha": "7d212a9cf1ca3c57393483ae8038bfef36923bb6", "max_forks_repo_licenses": ["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.84375, "max_line_length": 429, "alphanum_fraction": 0.6189463019, "num_tokens": 3758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6002464894588275}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[a4paper, total={6in, 10in}]{geometry}\n\\usepackage{amsmath}\n\\usepackage{pgfplots}\n\\usepackage{hyperref}\n\\usepackage{graphicx}\n\\usepackage{float}\n\\usepackage{import}\n\\setlength{\\parindent}{0pt}\n\\newcommand\\inputpgf[2]{{\n\\let\\pgfimageWithoutPath\\pgfimage\n\\renewcommand{\\pgfimage}[2][]{\\pgfimageWithoutPath[##1]{#1/##2}}\n\\input{#1/#2}\n}}\n\n\n\\begin{document}\n\\date{}\n\\title{KL-$\\lambda$-optimal post model threshold search}\n\\author{Hilding Wollbo}\n\\maketitle\n\\vspace{-0.5cm}\n\n\\section{KL-Divergence in Machine Learning}\n\nThe Kullback-Leibler (KL) Divergence is an information theoretic concept used across many different probabilistic domains, including the field of Machine Learning. The KL-divergence is defined as\n\n\\begin{equation}\n\\textbf{KL}[p \\vert\\vert q] = -\\int p(x) \\log \\frac{q(x)}{p(x)} dx\n\\end{equation}\n\nand can be thought of as a metric describing the distance between two probability distributions $p$ and $q$. The KL-divergence is however not a true distance metric since it is neither symmetric in that $\\textbf{KL}[p \\vert\\vert q] \\neq \\textbf{KL}[q \\vert\\vert p]$ nor does it satisfy the triangle inequality. \\\\\n\nIn the case of logistic regression, one tries to fit model parameters $\\varphi$ such that the computed probability $\\hat{P}_\\varphi(y=1\\vert x) $ is as close to the true probability $P(y=1\\vert x)$ as possible, for every point $x$ in the dataset. The difference between these two distributions can be quantified by their KL-divergence, and the problem can be reduced to finding the set of parameters $\\varphi$ that minimize the average KL-distance of the dataset such that\n\n\\begin{align}\n    \\varphi: \\underset{\\varphi}{\\arg\\min} \\Big \\{ -\\frac{1}{N} \\sum_{n=1}^N P(y_n=1\\vert X_n) \\log \\frac{\\hat{P}_\\varphi(y_n=1\\vert X_n)}{P(y_n=1\\vert X_n)} + P(y_n=0\\vert X_n) \\log \\frac{\\hat{P}_\\varphi(y_n=0\\vert X_n)}{P(y_n=0\\vert X_n)} \\Big \\}\n\\end{align}\n% relate to cross entropy and likelihood\nNoting that the minimization is performed with regard to $\\varphi$ one can disregard the independent terms in the optimization, which leads to the equivalent problem of minimizing the average cross entropy loss\n\n\\begin{align}\n    \\varphi: \\underset{\\varphi}{\\arg\\min} \\Big \\{ -\\frac{1}{N} \\sum_{n=1}^N P(y_n=1\\vert X_n) \\log \\hat{P}_\\varphi(y_n=1\\vert X_n) + P(y_n=0\\vert X_n) \\log \\hat{P}_\\varphi(y_n=0\\vert X_n) \\Big \\}\n\\end{align}\n\nThis is also equivalent to the Maximum Likelihood formulation of finding the model parameters $\\varphi$ which maximizes the probability that our model predictions $\\hat{\\mathbf{y}}$ gave rise to the set of observed true labels $\\mathbf{y}$. \n% EX from https://www.textbook.ds100.org/ch/17/classification_cost_justification.html\n\n\\section{Post model threshold selection}\n\nIn the case of binary classification, the trained model outputs a probability $f_\\varphi (x) \\in [0, 1]$ for each input $x$ which is then thresholded to either 0 or 1 by a threshold $\\theta$. The default threshold is generally set to $\\theta = 0.5$, which for well behaved and balanced datasets can be sufficient. However, the performance of the model predictions on the validation dataset can often be improved by shifting the threshold by maximizing a set of relevant metrics such as precision, recall, $F_1$-measure etc. depending on application. This view of threshold selection is generally to maximize the average performance of the model output for a specified metric $M$ by varying the threshold $\\theta$:\n\\begin{align}\n    \\theta : \\underset{\\theta}{\\arg\\max}\\{\\frac{1}{N} \\sum_{n=1}^N M(\\theta(f_\\varphi(x_n)), y_n\\}\n\\end{align}\nor equivalently, to minimize an expected total cost associated with the respective errors as\n\\begin{align}\n\t\\label{eq:cost}\n    \\theta : \\underset{\\theta}{\\arg\\min}\\{\\frac{1}{N} \\sum_{n=1}^N \\alpha y_n (1-\\theta(f_\\varphi(x_n)) )+ \\beta (1-y_n) \\theta(f_\\varphi(x_n))\\}\n\\end{align}\nwhere $\\alpha$ is the cost of a false negative and $\\beta$ that of a false positive. However, as given by the prediction problem we have no way of knowing the true labels $y_n$. We could use the training data to create predictions and calculate an expected cost and select an optimal threshold on this data. Still, we would like to incorporate the information about the test predictions in our threshold selection. % this section needs some polishing\nInstead, given that we can collect a sufficient set of unthresholded test predictions, we can use a probabilistic view and just consider the relation between the ideal predictor $\\hat{y}^*$ and the true data labels $y$. One property that an ideal predictor must fulfill is that $\\hat{y}^* \\sim p(y)$, since all predictions are correct. That is, the proportions of each class in the predictions should equal those in the dataset labels. This essentially means that, instead of minimizing the expected total error of our predictions, we could try to find an optimal threshold $\\theta^*$ after training by minimizing the distance between the distribution of true class labels $p(y)$ and the global distribution of thresholded predictions $q_\\theta(\\hat{y})$.\n\n\\section{Binary classification}\n\nBinary classification is the most simple application of prediction in machine learning, but also the most fundamental, since every classification problem can be formulated as sets of binary prediction tasks or decision trees. For a given post model classification problem we have a set of true labels following a distribution $p(y)$ which can be estimated empirically directly from the training data (assuming that both training and test data follow the same distribution). Likewise for the predictions $\\hat{y}$ we can define an empirical distribution given a threshold $\\theta$ as\n\\begin{align*}\n    q_\\theta(\\hat{y}) = \\begin{cases} 1, & \\text{w. p.} \\ \\frac{1}{N}\\sum_{n=1}^N \\theta(\\hat{y}_n) \\\\[0.2cm]\n    0, &  \\text{w. p.} \\ 1 - \\frac{1}{N}\\sum_{n=1}^N \\theta(\\hat{y}_n) \\end{cases}\n\\end{align*}\\text{,}\nwhere $\\theta(\\hat{y}_n) = 1$ if $\\hat{y}_n \\geq \\theta$, else 0.\nIn the case of discrete class classification, the integral in the KL-divergence is replaced with a sum, such that\n\\begin{equation}\n\\textbf{KL}[p(y) \\vert\\vert q_\\theta(\\hat{y})] = -\\sum p(y) \\log \\frac{q_\\theta(\\hat{y})}{p(y)}\\text{,}\n\\end{equation}\nand for the binary classification problem we simply insert our binary probabilities\n\\begin{align}\n\\textbf{KL}[p(y) \\vert\\vert q_\\theta(\\hat{y})] = & \\ - p(y=1) \\log \\frac{q_\\theta(\\hat{y}=1)}{p(y=1)} - p(y=0) \\log \\frac{q_\\theta(\\hat{y}=0)}{p(y=0)} \\\\ = & \\label{eq:tprfpr} -p \\log \\underbrace{\\frac{P(\\hat{y}\\geq \\theta)}{p}}_\\text{\"fnr cost\"} - (1-p) \\log \\underbrace{\\frac{P(\\hat{y} < \\theta)}{1-p}}_\\text{\"fpr cost\"} \\text{.}\n\\end{align}\nIn the binary case, each term is associated with an error cost depending on the amount of respective errors resulting from a given threshold, similar to the expected cost in Equation (\\ref{eq:cost}). With a too conservative threshold the probability of a negative in the global distribution of predictions $q_\\theta (\\hat{y}=0)$ is larger than that of the true negative labels $p(y=0)$, resulting in an increased amount of false negatives. This in turn implies that the proportion of predicted positives must be smaller than the true amount of positives, $q_\\theta(\\hat{y} = 1) < p(y=1)$. That is, the classifications follow\n\\begin{align*}\n    q_\\theta(\\hat{y}=0) > p(y=0) \\iff  TN + FN > \\underbrace{TN+FP}_{N} \\rightarrow FN>FP \\text{.}\n\\end{align*}\nVice versa holds for the case when $q_\\theta(\\hat{y}=1) > p(y=1)$, where the proportion of predicted positives is larger than that of the true distribution.\nHowever, the cost associated with a false positive error is generally different than that of a false negative, this relation can be captured by a constant $\\lambda$. One may then define the threshold optimization problem as:  \n\\begin{align}\n    \\theta: \\underset{\\theta}{\\arg \\min} \\Big\\{ - p \\log \\frac{P(\\hat{y}\\geq \\theta)}{p} - \\lambda (1-p) \\log \\frac{P(\\hat{y} < \\theta)}{1-p} \\Big \\}\n\\end{align}\nFor $\\lambda>1$, false positives are associated with a higher cost during minimization (in relation to their prevalence in the true labels). This causes the resulting proportion of predicted positives given the threshold to be smaller. % since the total product lambda * fpr cost is increased!\nAgain, the optimization is performed with regard to $\\theta$ and the independent terms can be disregarded, leading to the equivalent optimization problem of minimizing the weighted cross entropy loss between the two distributions as\n\\begin{align}\n\\label{eq:threshold} \n\\theta: \\underset{\\theta}{\\arg \\min} \\Big\\{ - p \\log P(\\hat{y}\\geq \\theta) - \\lambda (1-p) \\log P(\\hat{y} < \\theta) \\Big \\} \\text{.}\n\\end{align}\nFor brevity, we set $q = P(\\hat{y}\\geq \\theta)$ and the minimization can be expressed as\n\\begin{align*}\n\\theta:& \\ \\underset{\\theta}{\\arg \\min} \\Big\\{ - p \\log q - \\lambda (1-p) \\log (1-q) \\Big \\} = \\\\\n=& \\ \\underset{\\theta}{\\arg \\min} \\Big\\{ - \\log q^p - \\log (1-q)^{\\lambda(1-p)} \\Big \\} \\\\\n=& \\ \\underset{\\theta}{\\arg \\min} \\Big\\{ - \\log q^p (1-q)^{\\lambda(1-p)} \\Big \\} \\\\\n=& \\ \\underset{\\theta}{\\arg \\min} \\Big\\{ - q^p (1-q)^{\\lambda(1-p)} \\Big \\} \\text{.}\n\\end{align*}\nDeriving and solving for zero, we have the expression\n\\begin{align*}\n\\partial_q q^p (1-q)^{\\lambda(1-p)} =& \\ -\\lambda(1-p)(1-q)^{\\lambda(1-p)-1}q^p + pq^{p-1}(1-q)^{\\lambda(1-p)} \\\\\n=& \\ (1-q)^{\\lambda(1-p)-1}(-\\lambda(1-p)q^p + p(1-q)q^{p-1}) \\\\\n=& \\ 0\n\\end{align*}\nleading to the closed form solution\n\\begin{align}\n\\label{eq:pos}\np(1-q)q^{p-1} =& \\ \\lambda(1-p)q^p \\\\\n\\rightarrow q =& \\ \\frac{p}{p + \\lambda(1-p)}\\text{.}\n\\end{align}\nHere, $q$ corresponds to a resulting proportion of positive predictions associated with a certain threshold $\\theta$ when applied to the raw predictions. This threshold can be found by finding the index $m$ in the sorted predictions which corresponds to the proportion $q$ of resulting positively classified predictions, according to\n\\begin{align}\n\\label{eq:m}\nm : \\underset{m}{\\arg \\min}&\\Big\\{ \\Big \\lvert q - \\frac{1}{N}\\sum_{n=m}^N\\delta(f_\\varphi(x_n)) \\Big \\rvert \\Big\\}, \\ m \\in [0, N] \\\\\n&\\theta = f_\\varphi(x_m)\n\\end{align}\nIn this way, we arrive at a structured method of quantifying the tradeoff between probability of errors and the associated costs of each error to find the optimal threshold in the binary prediction setting.\n\n% Could be interesting to plot logarithmic x-axis of q as a function of lambda for a few different p\n\n\\subsection{Example}\n\nWe may also find specific solutions to this threshold optimization problem in cases where the distribution of test predictions is known but the actual test predictions are not.\nGiven that the set of predictions is modelled by the following, exponential mixture distribution\n\n\\begin{align*}\n    f_0(x\\vert y=0;\\beta_0) =& \\ \\frac{\\beta_0}{Z_0}e^{-\\beta_0 x} = \\frac{\\beta_0}{1-e^{-\\beta_0}}e^{-\\beta_0 x} \\\\\n    f_1(x\\vert y=1;\\beta_1) =& \\ \\frac{\\beta_1}{Z_1}e^{\\beta_1 x} = \\frac{-\\beta_1}{1-e^{\\beta_1}}e^{\\beta_1 x}\\\\\n    f (x;\\beta_0,\\beta_1,\\alpha) =& \\ (1-\\alpha)\\frac{\\beta_0}{1-e^{-\\beta_0}}e^{-\\beta_0 x} - \\alpha\\frac{\\beta_1}{1-e^{\\beta_1}}e^{\\beta_1 x} % consider changing order of alpha=1-alpha\n\\end{align*}\nwe can find the optimal threshold $\\theta$ by finding the point where the proportion of expected predicted positives is equal to the one found in Equation (\\ref{eq:pos}). We recognize that $\\alpha = p$ and set\n\n\\begin{align}\n    \\frac{p}{p+\\lambda(1-p)} = & \\int_{\\theta}^1 f(x;\\beta_0, \\beta_1, p) dx = \\\\\n    = & \\int_{\\theta}^1 \\frac{1-p}{1-e^{-\\beta_0}}\\beta_0e^{-\\beta_0x} - \\frac{p}{1-e^{\\beta_1}}\\beta_1e^{\\beta_1x} dx = \\\\\n    = & \\ \\frac{1-p}{1-e^{-\\beta_0}}(e^{-\\beta_0}-e^{-\\beta_0 \\theta}) - \\frac{p}{1-e^{\\beta_1}}(e^{\\beta_1}-e^{\\beta_1 \\theta})\\text{.}\n\\end{align}\n\nRearranging and setting $\\beta_1 = \\beta_0 = \\beta$ for simplicity, we can define the function\n\n\\begin{align}\n    f(\\theta) =& \\ \\frac{e^{-\\beta \\theta} (e^\\beta-e^{\\beta \\theta}) (p(e^{\\beta \\theta}-1) + 1)}{e^{\\beta}-1} - \\frac{p}{p+\\lambda(1-p)} = 0 \\\\\n    f'(\\theta) =& \\ \\frac{\\beta e^{-\\beta \\theta} ((p-1) e^\\beta - p e^{2\\beta \\theta})}{e^{\\beta}-1}\\text{.}\n\\end{align}\nUsing Newton's Method we can find an approximate solution to $\\theta$ by iterating\n\\begin{align}\n    \\theta_{n+1} =& \\ \\theta_n - \\frac{f(\\theta_n)}{f'(\\theta_n)}\n\\end{align}\nuntil convergence. An example of this method is shown in Figure \\ref{fig:exp5}.\n\\begin{figure}\n    \\centering\n    \\scalebox{.8}{\\input{figures/thresholds_breastcancer_exponential_5.pgf}}\n    \\caption{Thresholds for an exponential test prediction distribution with parameter $\\beta = 5$ in a dataset of 61 \\% positive examples.}\n    \\label{fig:exp5}\n\\end{figure}\n\n\\subsection{Statistical significance}\nThe whole framework henceforth presented assumes that we have a batch of test predictions from which we are able to infer a threshold representative of the true distribution of test predictions. However, if by chance, we end up with a set of test predictions with class balance widely different from the training data, we can be sure to arrive at suboptimal thresholds. Therefore, in relation to the class balance, we need to define criteria for which we either proceed with calculating the threshold or simply wait for more data to become available before proceeding. \\\\\n\nAssuming that the number of test predictions in the set is sufficiently large (i.e. $pN\\geq 10, (1-p)N\\geq 10$) to allow us to view $q$ as normally distributed around the true proportion $\\bar{q}$, we can use a z-test to determine how many samples we need to achieve at most error $E=q-\\bar{q}$ given a certain confidence level $\\alpha$. The test statistic for the z-test is calculated by %We assume that the $q$ we calculate from the test predictions is normally distributed around the true mean $\\bar{q}$.\n\\begin{align}\nz_{\\alpha/2} = \\frac{q-\\bar{q}}{\\frac{\\sigma_q}{\\sqrt{N}}}\\text{.}\n\\end{align}\nFrom here, we may set the confidence interval and error tolerance and solve for $N$.\nWe already assumed that the proportion of positives in the training data is roughly the same as in the test data, so it is justified that we calculate the population variance from the training data as \n\\begin{align*}\n    \\sigma_q =& \\ \\sqrt{q(1-q)} \\\\\n            =& \\ \\frac{1}{p+\\lambda(1-p)}\\sqrt{\\lambda p(1-p)} \\\\\n            =& \\ \\frac{\\sqrt{\\lambda}}{p+\\lambda(1-p)}\\sigma_p\n\\end{align*}\nFurthermore, we need to decide a margin of error and a confidence interval for our estimation. Since our threshold $\\theta$ and proportions $p$ and $q$ all lie in the interval $[0, 1]$, it can be suitable to assume that we want an error no larger than $0.05$ from the true weighted proportion $\\bar{q}$. Following standard practice, we also select a 95\\% confidence interval. Using the two-sided Z-test, we have\n\\begin{align}\n    E = z_{\\alpha/2}\\frac{\\sigma_q}{\\sqrt{N}}\n\\end{align}\nThus, to find how large $N$ needs to be for our requirements to hold, we calculate\n\\begin{align*}\n    N =& \\ (\\frac{z_{\\alpha/2}}{E})^2\\sigma_q^2 \\\\\n      =& \\ (\\frac{z_{\\alpha/2}}{E})^2 \\frac{\\lambda}{(p+\\lambda(1-p))^2}\\sigma_p^2\n\\end{align*}\nFor the chosen values, Figure \\ref{fig:hmap} shows a heatmap of the number of samples $N$ needed to confidently use the developed threshold selection scheme.\n%https://brownmath.com/stat/sampsiz.htm#Case2\n% make a friendly and nice table with p: 0.05:0.95 and different lambda\n\\begin{figure}\n    \\centering\n    \\scalebox{.8}{\\inputpgf{figures/}{hmap.pgf}}\n    \\caption{Heatmap of the required number of samples $N$ to achieve at most an error of $0.05$ with a $95\\%$ CI when estimating $q$.}\n    \\label{fig:hmap}\n\\end{figure}\n\n\n%Pr(X = m) = (N, m) p^(N-m)(1-p)^m (switched around because 1 is label of p)\n\n\\section{Practical examples}\nIn order to illustrate how this threshold search can be used in practice, a few simple cases are studied for known binary datasets.\n\\subsection{Setup}\nIn order to generate predictions, a small decision tree model using LightGBM was implemented with default parameters. The project was implemented in Python using the \\texttt{LGBMClassifier} package, as well as \\texttt{sklearn}, \\texttt{numpy} and \\texttt{pandas} for data manipulation. The code used to produce the results is available at \\url{https://github.com/wollbo/threshold}. The labels of the dataset are marked accordingly: positive test samples in blue, and negative test samples are marked in orange. The probability output from the classifier is presented as histograms, with several thresholds $\\theta$ calculated from the classifier predictions using Equation (\\ref{eq:pos}) for different misclassification cost ratios $\\lambda$. Points to the right of a threshold is classified as positive, data to the left of the threshold is classified as negatives.\n\\subsection{Breast Cancer Wisconsin}\nThe Breast Cancer Wisconsin dataset is a traditional dataset used for evaluating baseline performance for binary classifiers, containing a majority positive samples. It is comprised of features computed from digitized images of mammograms. In this case, the simple decision tree model is able to almost perfectly separate the positive and negative samples with only a few outliers. Notably, the raw output probabilities are also very distinctly 1 or 0.\n\\begin{figure}[H]\n    \\centering\n    \\scalebox{.8}{\\input{figures/thresholds_breastcancer.pgf}}\n    \\caption{Thresholds and predictions generated for the Wisconsin Breast Cancer dataset, 64 \\% positive samples. This is a very easy dataset to classify.}\n\\end{figure}\n\n\\subsection{German Credit Data}\nThe German Credit dataset is comprised of several categorical and numerical attributes associated with the financial status of individuals as to determine their credit worthiness, with the majority of samples being positive (corresponding to a 'good' credit status). This is also a rather traditional dataset, but is considerably harder to classify than the Breast Cancer dataset. Still, the algorithm is generally able to separate the positives and negatives, and the threshold selection shows how increasing the parameter $\\lambda$ increases the propensity to classify samples as negatives, and how lowering $\\lambda$ results in classifying most samples as positives.\n\\begin{figure}[H]\n    \\centering\n    \\scalebox{.8}{\\input{figures/thresholds_credit.pgf}}\n    \\caption{Thresholds and predictions generated for the German Credit Data dataset, 71 \\% positive samples.}\n\\end{figure}\n\n\\subsection{KDD CUP 2009 - Churn}\n    The KDD CUP 2009 dataset was initially used for the competition bearing the same name, and consists of customer relationship data of the French Telecom company Orange. In this dataset, each customer has 190 numerical and 40 categorical features which are very sparse. Corresponding to the feature data is the labels of 'Churn' which is used to train and evaluate the model. This is a much harder dataset to classify than the other two, and the decision tree model struggles to separate the two distributions. In this case, only 7\\% of the samples are positive, which means that the selected thresholds become shifted to 0.\n\\begin{figure}[H]\n    \\centering\n    \\scalebox{.8}{\\input{figures/thresholds_orange-small.pgf}}\n    \\caption{Thresholds and predictions generated for the KDD Cup 2009 Churn dataset, 7 \\% positive samples. This is a hard dataset to classify.}\n\\end{figure}\n\n% \\newpage\n% \\subsection{Extension to the Multi-label setup}\n% The Multi-label classification task can essentially, from the post model perspective, be viewed as a joint set of binary classification tasks, assuming that each label is independent and mutually nonexclusive. Similarly to the binary case, one can calculate empirical dataset probabilities for each of the $M$ separate labels such that\n% \\begin{align*}\n%     p(y_1 = 1) &= p_1 \\\\\n%     p(y_2 = 1) &= p_2 \\\\\n%     \\vdots & \\\\\n%     p(y_M = 1) &= p_M\n% \\end{align*}\n\n% This leads to the set of KL-divergence equations\n\n% \\begin{align*}\n% \\textbf{KL}[p(\\mathbf{y})\\vert\\vert q_\\Theta(\\mathbf{\\hat{y}})] = - \\sum p(\\mathbf{y})\\log \\frac{q_\\Theta(\\hat{\\mathbf{y}})}{p(\\mathbf{y})} =\n% \\left [ \\begin{aligned}\n%    \\left. - p_1 \\log P(\\hat{y}_1\\geq \\theta_1) -& \\beta_1 (1-p_1) \\log P(\\hat{y}_1 < \\theta_1) \\\\ \\right.\n%     \\left.- p_2 \\log P(\\hat{y}_2\\geq \\theta_2) -& \\lambda_2 (1-p_2) \\log P(\\hat{y}_2 < \\theta_2) \\\\ \\right.\n%     \\left.\\vdots& \\\\ \\right.\n%     \\left.- p_M \\log P(\\hat{y}_M\\geq \\theta_M) -& \\lambda_M (1-p_M) \\log P(\\hat{y}_M < \\theta_M)  \\\\ \\right.  \\end{aligned} \\right ]\n% \\end{align*}\n\n% Defining the set of $M$ thresholds as\n% \\begin{align}\n% \\label{eq:thresholdset}\n%     \\Theta_1^M = \\bigcup\\limits_{i=1}^M \\theta_i\n% \\end{align}\n\n% one would then try to find $\\Theta_1^M$ by individually calculating the threshold $\\theta_i$ for each class distribution $p(y_i)$, prediction distribution $q_\\theta(\\hat{y}_i)$ and error cost factor $\\lambda_i$ according to equation (\\ref{eq:threshold}).\n% \\subsubsection{Ranking Predictions}\n% In some applications it can be desirable to rank the different positive label predictions according to their confidence when there are several positive predicted class labels. In a medical setting, for example, this could correspond to deciding which indicated disease in a multi-class medical test to treat first. The predictions can be weighed in many different ways. It would be reasonable to assign confidence in the predicted class label with regard to the overall distribution of possible samples in that specific class, as well as incorporation of how confident the specific class prediction is in relation to the average class prediction for the label, since it can be assumed that the distances between threshold and prediction are generally different between labels. In this way, one weighs both information about the distribution together with the quality of the individual prediction.\n% \\\\\n% Assuming that the probability of a correct thresholded prediction is directly related to the distance between the raw positive prediction $\\hat{y}$ and the threshold $\\theta$, one can define a distance factor simply as $\\vert\\vert \\theta-\\hat{y} \\vert\\vert $, where $\\hat{y} \\geq \\theta$. \n% We can also create a scale factor of the confidence of the $i$:th label predictions in relation to the other labels by calculating the average distance factor for each label as\n% \\begin{align}\n%     \\Delta_i =  \\frac{1}{L_i}\\sum_{l=1}^{L_i} \\vert\\vert \\theta_i-\\hat{y}_i^l \\vert\\vert\n% \\end{align}\n% where $[\\hat{y}_i^1, \\hat{y}_i^2, \\dots , \\hat{y}_i^{L_i}] $ is the set of $i$:th label predictions greater than the threshold $\\theta_i$. Finally, we can add a factor related to the probability of a positive sample in the distribution simply as the empirical mean of each label in the dataset as\n% \\begin{align*}\n%     p_i = p(y_i = 1) = \\frac{1}{N}\\sum_{n=1}^N y_i^n .\n% \\end{align*}\n% Thus, for each label $i$ and predicted positive sample $\\hat{y}_i$ we can define the confidence score as\n\n% \\begin{align*}\n%     c_i = p_i \\frac{\\vert\\vert \\theta_i-\\hat{y}_i \\vert\\vert}{\\Delta_i}\n% \\end{align*}\n% and rank the confidence of each label $i$ for every positive prediction $\\hat{y}_i$ in descending order.\n\n% \\subsection{Special Case: Multiclass setup}\n\n% The Multiclass classification problem is less straightforward than the binary and multi-label tasks.\n% Normally for a multiclass problem, one determines class prediction by calculating the soft-max of the output and selects the class index with the largest probability. If we instead retain our output as a set of seemingly independent sigmoids, we can apply similar logic as in the previous sections. Here, one can calculate the empirical dataset probabilities $[p_1, p_2 \\dots p_M]$ as before with the added constraint that\n% \\begin{align*}\n%     \\sum_{i=1}^M p_i = 1\n% \\end{align*}\n\n% One simple way to handle the case where two or more probability outputs are above their thresholds is to define a new class $M+1$ representing an ambiguous output. With the definition of the joint set of thresholds according to equation (\\ref{eq:thresholdset}), we arrive at the post model threshold classification problem\n\n% \\begin{align}\n%     P(\\Theta (\\mathbf{\\hat{y}})) & = \\begin{cases}\n%     j,& \\text{if} \\ \\hat{y}_j \\geq \\theta_j \\ \\cup \\ \\hat{y}_i < \\theta_i \\ \\forall \\ {i\\neq j} \\\\ % originally bigcup\n%     M+1,& \\text{otherwise}\n%     \\end{cases}\n% \\end{align}\n\n% This naturally lends itself as a more conservative classifier, in that the ambiguous class naturally handles many of the samples that would be erroneously classified by a soft-max classifier. However, this setup is also guaranteed to produce false negatives that would be correctly classified by the softmax-classifier. \n\n\\end{document}\n\n", "meta": {"hexsha": "a3b6c7a95644a4d2e6ae8154ab9d5ba393757916", "size": 24765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/main.tex", "max_stars_repo_name": "wollbo/threshold", "max_stars_repo_head_hexsha": "378a32260fe4f4c5fa481138f778398427fb82e3", "max_stars_repo_licenses": ["MIT"], "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.tex", "max_issues_repo_name": "wollbo/threshold", "max_issues_repo_head_hexsha": "378a32260fe4f4c5fa481138f778398427fb82e3", "max_issues_repo_licenses": ["MIT"], "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": "wollbo/threshold", "max_forks_repo_head_hexsha": "378a32260fe4f4c5fa481138f778398427fb82e3", "max_forks_repo_licenses": ["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.8116438356, "max_line_length": 898, "alphanum_fraction": 0.7292146174, "num_tokens": 7019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6001973955491495}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\n\\bibliographystyle{plain}\n\\usepackage{latexsym}\n\\usepackage{algorithm,algorithmic}\n\\usepackage{amssymb,amsthm}\n\\usepackage{amsmath,amsfonts}\n\\usepackage{mathrsfs}\n\\usepackage{enumerate}\n\\usepackage{graphicx,psfrag}\n\\usepackage{comment}\n%\\usepackage[notcite,notref]{showkeys}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{remark}{Remark}[section]\n\\newtheorem{lemma}{Lemma}[section]\n\\newtheorem{corollary}{Corollary}[section]\n\\newtheorem{assumption}{Assumption}[section]\n\\newtheorem{definition}{{Definition}}[section]\n\\newtheorem{proposition}{Proposition}[section]\n\\newtheorem{question}{Question}\n\n\n\\author{G\\\"unay Do\\u gan}\n\\title{Computing Surface Tension}\n\n\\begin{document}\n\n\\maketitle\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Introduction}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nOur goal is to compute a displacement field $\\vec{u}$ that minimizes\nthe energy\n%\n\\begin{equation}\\label{E:energy}\nE(\\vec{u}) = \\int_\\mathcal{D} \\left( \\frac{1}{2}\\sigma_{ij}\\varepsilon_{ij} \n-\\vec{f}\\cdot\\vec{u} \\right) dx + \\gamma \\int_{\\Gamma(\\vec{u})} d\\Gamma.\n\\end{equation}\n%\nThe energy \\eqref{E:energy} has two components: the elastic energy and \nthe surface tension, which is given by the surface area of \nthe displaced surface\n%\n\\begin{equation}\\label{E:displaced-surface}\n\\Gamma(\\vec{u}) = \\{\\vec{x} + \\vec{u}(\\vec{x}), \\vec{x} \\in \\Gamma_0 \\}.\n\\end{equation}\n%\nTo find a minimizer of the energy \\eqref{E:energy}, we take \nits first variation $\\delta E(\\vec{u};\\vec{\\phi})$ \nwith respect to a test function $\\vec{\\phi}$ and seek \n$\\vec{u}$ that satisfies\n\\[\n\\delta E(\\vec{u};\\vec{\\phi}) = 0, \\quad \\forall \\vec{\\phi}\n\\]\nor more explicitly\n%\n\\begin{equation}\\label{E:1st-variation}\n\\int_\\mathcal{D} \\left( \\frac{1}{2} D\\vec{u}:C D\\vec{\\phi} \n- \\vec{f}\\cdot\\vec{\\phi} \\right) dx \n+ \\gamma \\int_{\\Gamma(\\vec{u})} \\kappa \\vec{\\phi}\\cdot\\hat{n} \\, d\\Gamma = 0,\n\\quad \\forall \\vec{\\phi}.\n\\end{equation}\n%\nGiven the first variation \\eqref{E:1st-variation}, we could\nattempt to write an iterative scheme to compute $\\vec{u}$\nthat satisfies, for example,\n%\n\\begin{equation}\\label{E:1st-iterative-scheme}\n\\int_\\mathcal{D} \\left( \\frac{1}{2} D\\vec{u}^{n+1}:C D\\vec{\\phi} \n- \\vec{f}\\cdot\\vec{\\phi} \\right) dx \n= -\\gamma \\int_{\\Gamma(\\vec{u}^n)} \\kappa \\vec{\\phi}\\cdot\\hat{n} \\, d\\Gamma,\n\\quad \\forall \\vec{\\phi}.\n\\end{equation}\n%\nIn this way, we separate the linear and nonlinear parts\nand treat the nonlinear part explicitly without the need\nfor a nonlinear solve at each step of iterations.\nTo use this scheme, we would still need to verify \nthat the scheme converges to a solution. \nThere are other issues that need to be addressed \nas well. The right hand side in \\eqref{E:1st-iterative-scheme}\nis an integral computed on the displaced surface\n$\\Gamma(\\vec{u})$. Therefore, at each iteration, \nwe need to move the surface $\\Gamma$ to its displaced\nposition and then evaluate the surface integral. \nMoreover, evaluating the integral requires computing\nthe curvature of the displaced curve $\\Gamma(\\vec{u})$.\nIdeally we would like to avoid both tracking the displaced\ncurve and computing its curvature. For this reason,\nin the following, we rederive the first variation\nof the surface tension term in \\eqref{E:energy}. \nOur goal is to obtain an expression that is\nevaluated on the initial surface $\\Gamma_0$\nand does not require the curvature of the surface.\nFor the moment, we restrict our attention \nto parametric planar curves in 2d. \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{First variation of curve length}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nWe start by taking the first variation of\n%\n\\begin{equation}\\label{E:curve-length}\nE(\\Gamma_0) = \\int_{\\Gamma_0} d\\Gamma = \\int_{s_1}^{s_2} |\\Gamma_0'(s)|ds\n\\end{equation}\n%\nwith respect to a given parametric curve\n\\[\n\\Gamma_0(s) = \\left( x(s), y(s) \\right), \\quad s_1 \\leqslant s \\leqslant s_2.\n\\]\nLet us write \\eqref{E:curve-length} more explicitly\n%\n\\begin{align*}\n\\Gamma_0'(s)&=\\left( x'(s), y'(s) \\right), \\\\\n|\\Gamma_0'(s)|&=\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^\\frac{1}{2}\n\\end{align*}\n%\n\\[\n\\Rightarrow  E(\\Gamma_0) = \\int_{s_1}^{s_2} \\left( |x'(s)|^2 + |y'(s)|^2 \\right)^\\frac{1}{2} ds.\n\\]\nWe define the perturbed curve\n\\[\n\\Gamma_\\varepsilon(s) = \\left( x(s)+\\varepsilon \\phi(s), y(s) + \\varepsilon \\psi(s) \\right)\n\\]\nand compute\n\\[\n\\delta E(\\Gamma_0) = \\lim_{\\varepsilon \\rightarrow 0} \\frac{E(\\Gamma_\\varepsilon) - E(\\Gamma)}{\\varepsilon}\n= \\frac{d}{d\\varepsilon} E(\\Gamma_\\varepsilon) |_{\\varepsilon=0}.\n\\]\nWe need to take the derivative of\n\\[\nE(\\Gamma_\\varepsilon) = \\int_{s_1}^{s_2} \\left( |x'(s)+\\varepsilon \\phi'(s)|^2 + |y'(s) + \\varepsilon \\psi'(s)|^2 \\right)^\\frac{1}{2} ds\n\\]\nwith respect to $\\varepsilon$. We start with\n%\n\\begin{equation*}\n\\frac{d}{d\\varepsilon} |\\Gamma_\\varepsilon'| \n= \\frac{(x'(s)+\\varepsilon \\phi'(s)) \\phi'(s) + (y'(s) + \\varepsilon \\psi'(s))\\psi'(s) }{\\left( |x'(s)+\\varepsilon \\phi'(s)|^2 + |y'(s) + \\varepsilon \\psi'(s)|^2 \\right)^{\\frac{1}{2}}},\n\\end{equation*}\n%\nand\n%\n\\begin{equation*}\n\\frac{d}{d\\varepsilon} |\\Gamma_\\varepsilon'|_{\\varepsilon=0} = \\frac{x'(s)\\phi'(s) + y'(s)\\psi'(s)}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{1}{2}}}.\n\\end{equation*}\n%\nWe have\n\\[\n\\delta E(\\Gamma_0) = \\int_{s_1}^{s_2} \\frac{x'(s)\\phi'(s) + y'(s)\\psi'(s)}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{1}{2}}} ds.\n\\]\nLet us integrate $\\phi', \\psi'$ by parts (with the simplifying assumption that\n$ \\int_{s_1}^{s_2} = \\oint$, that is, we integrate over a closed curve).\nStart with\n%\n\\begin{align*}\n\\left(  \\frac{x'(s)}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{1}{2}}} \\right)'\n&=x''(s)\\frac{1}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{1}{2}}} \n- x'(s)\\frac{1}{2}\\frac{(2x'(s)x''(s) + 2y'(s)y''(s))}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{3}{2}}} \\\\\n&= \\frac{x''\\left( |x'|^2 + |y'|^2 \\right) - x'x'x''-x'y'y''}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{3}{2}}} \\\\\n&= -y'(s)\\kappa(s) \\\\\n&= -y' \\frac{x'y'' - x''y'}{\\left( |x'|^2 + |y'|^2 \\right)^{\\frac{3}{2}}} \\\\\n\\left(  \\frac{y'(s)}{\\left( |x'(s)|^2 + |y'(s)|^2 \\right)^{\\frac{1}{2}}} \\right)' \n&= x' \\frac{x'y'' - x''y'}{\\left( |x'|^2 + |y'|^2 \\right)^{\\frac{3}{2}}} \\\\\n&= x'(s)\\kappa(s).\n\\end{align*}\n%\n\\begin{align*}\n\\Rightarrow \\delta E(\\Gamma_0) &= \\int \\kappa(s) \\left( -y'(s)\\phi(s) + x'(s)\\psi(s) \\right) \\frac{1}{|\\Gamma_0'(s)|} |\\Gamma_0'(s)| ds, \\\\\n\\Rightarrow \\delta E(\\Gamma_0) &= \\int \\kappa(s) \\vec{\\varphi}\\cdot \\hat{n}(s)|\\Gamma_0'(s)| ds,\n\\end{align*}\nwhere $\\vec{\\varphi} = (\\phi(s),\\psi(s))$ and $\\hat{n} = \\frac{1}{|\\Gamma_0'(s)|}(-y'(s),x(s))$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Variation with respect to displacement}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nNow we take the first variation of $E(\\Gamma_u)$ with \nrespect to the displacement field $\\vec{u}$ (\\emph{not $\\Gamma_u$})\nwhere $\\Gamma_u$ is $\\Gamma_0$ displaced by $\\vec{u}$, that is,\n\\[\n\\Gamma_u(s) = \\Gamma_0(s) + \\vec{u}\\cdot (x(s),y(s)) = \\left( x(s)+u(x(s),y(s)), y(s)+v(x(s),y(s)) \\right).\n\\]\nWe will need the derivative of $\\Gamma_u(s)$\n%\n\\begin{align*}\n\\Gamma_u'(s) &= \\left( x' + \\nabla u \\cdot (x',y'), y' + \\nabla v \\cdot (x',y') \\right) \\\\\n\\Gamma_u'(s) &= \\Gamma_0'(s) + D\\vec{u} \\Gamma_0'(s) = (I + D\\vec{u}) \\Gamma_0'(s) \\\\\n\\Gamma_u'(s) &= \\left( x' + \\nabla u \\cdot \\Gamma_0', y' + \\nabla v \\cdot \\Gamma_0' \\right) .\n\\end{align*}\n%\nNote $D\\vec{u} = \\left( \\begin{array}{c} \\nabla u^T \\\\ \\nabla v^T \\end{array} \\right)$. \\\\\nNow we write\n\\[\n|\\Gamma_u'(s)| = \\left( |x' + \\nabla u \\cdot \\Gamma_0'|^2 + |y' + \\nabla v \\cdot \\Gamma_0'|^2  \\right)^\\frac{1}{2}\n\\]\nalso the perturbed version (by $u \\rightarrow u+\\varepsilon\\phi$, $v \\rightarrow v+\\varepsilon\\psi$)\n\\[\n|\\Gamma_\\varepsilon'(s)| = \\left( |x' + \\nabla u \\cdot \\Gamma_0'+ \\varepsilon\\nabla\\phi \\cdot \\Gamma_0'|^2 + |y' + \\nabla v \\cdot \\Gamma_0'+ \\varepsilon\\nabla\\psi \\cdot \\Gamma_0'|^2  \\right)^\\frac{1}{2}.\n\\]\nDifferentiate $|\\Gamma_\\varepsilon'|$ with respect to $\\varepsilon$ and evaluate at $\\varepsilon=0$\n%\n\\begin{equation*}\n\\frac{d}{d\\varepsilon}|\\Gamma_\\varepsilon'| \n= \\frac{1}{2}\\left( \\ldots \\right)^\\frac{1}{2}\n2 \\left( (x' + \\nabla u \\cdot \\Gamma_0'+ \\varepsilon\\nabla\\phi \\cdot \\Gamma_0')\\nabla\\phi\\cdot\\Gamma_0' +\n(y' + \\nabla v \\cdot \\Gamma_0'+ \\varepsilon\\nabla\\psi \\cdot \\Gamma_0')\\nabla\\psi\\cdot\\Gamma_0' \\right),\n\\end{equation*}\n%\n\\begin{equation*}\n\\frac{d}{d\\varepsilon}|\\Gamma_\\varepsilon'| |_{\\varepsilon=0} =\n\\frac{ \\left( (x' + \\nabla u \\cdot \\Gamma_0')\\nabla\\phi\\cdot\\Gamma_0' +\n(y' + \\nabla v \\cdot \\Gamma_0')\\nabla\\psi\\cdot\\Gamma_0' \\right) }\n{\\left( |x' + \\nabla u \\cdot \\Gamma_0'|^2 + |y' + \\nabla v \\cdot \\Gamma_0'|^2  \\right)^\\frac{1}{2}},\n\\end{equation*}\n%\nwhence we obtain the first variation of $E(\\Gamma_u)$\n%\n\\begin{equation}\\label{E:displaced_curve_1st_variation}\n\\delta E(\\Gamma_u) = \\int_{s_1}^{s_2}\n\\frac{ \\left( (x' + \\nabla u \\cdot \\Gamma_0')\\nabla\\phi\\cdot\\Gamma_0' +\n(y' + \\nabla v \\cdot \\Gamma_0')\\nabla\\psi\\cdot\\Gamma_0' \\right) }\n{\\left( |x' + \\nabla u \\cdot \\Gamma_0'|^2 + |y' + \\nabla v \\cdot \\Gamma_0'|^2  \\right)^\\frac{1}{2}} ds.\n\\end{equation}\n%\nNote $(\\phi)' = (\\phi(x(s),y(s)))'=\\nabla\\phi\\cdot\\Gamma_0'$, $(\\psi)'=\\nabla\\psi\\cdot\\Gamma_0'$. \n\nWe integrate $(\\phi)',(\\psi)'$ by parts as we did for $E(\\Gamma_0)$ and obtain\n%\n\\begin{equation*}\n\\delta E(\\Gamma_u) = \\int \\kappa_u(s) \\vec{\\varphi}(x,y) \\cdot \\hat{n}_u |\\Gamma_u'(s)| ds,\n\\end{equation*}\n%\nwhere $\\vec{\\varphi}(x,y)=(\\phi(x,y),\\psi(x,y))$ and\n\\[\n\\hat{n}_u(s)=\\frac{1}{|\\Gamma_u'(s)|} (-y_u'(s),x_u'(s)), \\qquad\n\\kappa_u(s) = \\frac{x_u' y_u'' - x_u'' y_u'}{\\left( |x_u'|^2 + |y_u'|^2 \\right)^{\\frac{1}{2}}}. \n\\]\n\nLet us rearrange the terms in \\eqref{E:displaced_curve_1st_variation}.\nFirst recall that the tangent vector $\\hat{\\tau}$ is given by\n\\[\n\\hat{tau} = \\frac{\\Gamma_0'}{|\\Gamma_0'|} = \\frac{1}{|\\Gamma_0'|} (x',y'), \\qquad \n\\hat{tau} = (\\tau_x,\\tau_y).\n\\]\nRewrite $\\delta E(\\Gamma_u)$  in \\eqref{E:displaced_curve_1st_variation}:\n%\n\\begin{align*}\n\\delta E(\\Gamma_u) &= \\int\n\\frac{|\\Gamma_0'|^2}{|\\Gamma_0'|}\n\\frac{ \\frac{x'}{|\\Gamma_0'|} \\nabla\\phi \\cdot \\frac{\\Gamma_0' }{|\\Gamma_0'|}\n+ \\frac{y'}{|\\Gamma_0'|} \\nabla\\psi \\cdot \\frac{\\Gamma_0' }{|\\Gamma_0'|}\n+ \\nabla u \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} \\nabla\\phi \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} \n+ \\nabla v \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} \\nabla\\psi \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} }\n{\\left[ \\left( \\frac{x'}{|\\Gamma_0'|} + \\nabla u \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} \\right)^2 +          \n\\left( \\frac{y'}{|\\Gamma_0'|} + \\nabla v \\cdot \\frac{\\Gamma_0'}{|\\Gamma_0'|} \\right)^2  \\right]^\\frac{1}{2}} ds \\\\\n\\delta E(\\Gamma_u) &= \\int\n\\frac{\\tau_x \\nabla\\phi \\cdot \\hat{\\tau} + \\tau_y \\nabla\\psi \\cdot \\hat{\\tau}\n+ \\nabla u \\cdot \\hat{\\tau} \\nabla\\phi \\cdot \\hat{\\tau}\n+ \\nabla v \\cdot \\hat{\\tau} \\nabla\\psi \\cdot \\hat{\\tau}}\n{\\left[ (\\tau_x + \\nabla u \\cdot \\hat{\\tau})^2 + (\\tau_y + \\nabla v \\cdot \\hat{\\tau})^2 \\right]} ds.\n\\end{align*}\n%\nThis can be written compactly as\n\\[\n\\delta E(\\Gamma_u) = \\int\n\\frac{\\hat{\\tau}^T (I + D\\vec{u})^T D\\vec{\\varphi} \\hat{\\tau}}{|(I+D\\vec{u})\\hat{\\tau}|} ds.\n\\]\n\n\\end{document}\n", "meta": {"hexsha": "2a7332f4fc74fa08c160c4e6f417807d8bf46e3e", "size": 11195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NOTES/surface_tension.tex", "max_stars_repo_name": "usnistgov/OOF3D", "max_stars_repo_head_hexsha": "4fd423a48aea9c5dc207520f02de53ae184be74c", "max_stars_repo_licenses": ["X11"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2015-04-01T15:59:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T20:21:47.000Z", "max_issues_repo_path": "NOTES/surface_tension.tex", "max_issues_repo_name": "usnistgov/OOF3D", "max_issues_repo_head_hexsha": "4fd423a48aea9c5dc207520f02de53ae184be74c", "max_issues_repo_licenses": ["X11"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-02-06T19:30:24.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-25T14:14:31.000Z", "max_forks_repo_path": "NOTES/surface_tension.tex", "max_forks_repo_name": "usnistgov/OOF3D", "max_forks_repo_head_hexsha": "4fd423a48aea9c5dc207520f02de53ae184be74c", "max_forks_repo_licenses": ["X11"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-01-23T15:19:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T09:03:59.000Z", "avg_line_length": 40.7090909091, "max_line_length": 203, "alphanum_fraction": 0.6120589549, "num_tokens": 4387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6001973829130652}}
{"text": "\\documentclass[a4paper,titlepage]{article}\n\n\\title{Lucre: Anonymous Electronic Tokens v1.8}\n\\author{Ben Laurie \\\\\nben@algroup.co.uk}\n\n\\begin{document}\n\\maketitle\n\n\\def\\mod#1{\\,(\\textrm{mod}\\,#1)}\n\\def\\implies{\\Rightarrow}\n\\def\\qe#1{\\begin{equation}#1\\end{equation}}\n\\def\\qearray#1{\\begin{eqnarray}#1\\end{eqnarray}}\n\\def\\oneway#1{\\textrm{oneway}(#1)}\n\\def\\preoneway#1{\\textrm{preoneway}(#1)}\n\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{1ex plus 0.5ex minus 0.2ex}\n\n\\section{Introduction}\n\nThis is a revised version of the theory of blinded coins that may not\nviolate Chaum's patent\\footnote{At least, that's what people\nthink. Take legal advice before using this stuff!}, based on the\noriginal work by David Wagner, and conversations with Ian Goldberg,\nDavid Molnar, Paul Barreto and various Anonymouses.\n\nNote that this now includes variants that probably do violate the\npatent, but are of sufficient academic interest to be worthy of\ninclusion.\n\n\\section{Coins}\n\n\\subsection{Creating the Mint}\n\\label{sec:mint}\n\nThe mint chooses a prime, $p$, with $(p-1)/2$ also prime, a generator,\n$g$, s.t.\n\n\\qe{\\label{eq:3}g^2 \\neq 1 \\mod p}\n\nand\n\n\\qe{\\label{eq:1}g^{(p-1)/2} = 1 \\mod p}\n\n(see \\ref{sec:theory1}) and a random number, $k$,\n\n\\qe{k \\in [0,(p-1)/2)}\n\nLet $G$ be the group generated by $g$.\n\nThe mint publishes\n\n\\qe{(g,p,g^k \\mod p)}\n\n\\subsection{Withdrawing a Coin}\n\nTo withdraw a coin Alice picks a random $x$, the coin ID, from a\nsufficiently large set that two equal values are unlikely to ever be\ngenerated\\footnote{Remember that if the size of the set of all\npossible coins is $C$, the probability of two being the same is .5\nafter around $\\sqrt{C}$ coins have been generated.}, and calculates,\n\n\\qe{y=\\oneway{x}}\n\n(see \\ref{sec:oneway}). $y$ should be in $G$; check that\n\n\\qe{1 < y < p-1}\n\nWe should avoid the trivial values 1 and -1, because their signatures\nare independent of $k$. Note that many one-way coin functions\n(including the one presented here) provably never produce 1 or -1, but\nwe include this condition for completeness.\n\n\\qe{y^{(p-1)/2}=1 \\mod p}\n\nIf it is not, a new coin should be chosen. Note that great care must\nbe take if you want to choose a one-way function that guarantees\nmembership of $G$ - certainly one attempt (see \\ref{sec:badoneway})\nled to disaster.\n\nAlice chooses a random blinding factor $b \\in [0,(p-1)/2)$ and sends\n$y g^b$ (the coin request) to the mint. The mint debits Alice's\naccount and returns the blinded signature,\n\n\\qe{m=(y g^b)^k \\mod p}\n\nAlice unblinds $m$, calculating the signature,\n\n\\qe{z=m (g^k)^{-b}=(y g^b)^k g^{-kb}=y^k g^{bk} g^{-kb}=y^k \\mod p}\n\nThe coin is then\n\n\\qe{c=(x,z)}\n\n\\subsection{Spending a Coin}\n\nTo spend a coin, Alice simply gives the coin, $c$, to Bob. Bob then\nsends it to the mint to be checked. The mint first ensures that $x$\nhas not already been spent, and that $\\oneway x$ is in $G$ and is not\n1 or -1, then checks that $z$ is a signature for $x$\n(i.e. $z=\\oneway{x}^k \\mod p$). The mint then records $x$ as spent and\ncredits Bob's account.\n\n\\section{Attack\\cite{Anon1}}\n\nUnfortunately an attack on the anonymity of this protocol is\npossible. The mint can mark a coin in a way that only it can detect,\nby signing it with $k'$ instead of $k$. Then the unblinded\n``signature'' is\n\n\\qe{z=(y g^b)^{k'} g^{-bk}=y^{k'} g^{b(k'-k)} \\mod p}\n\nWhen Bob submits $c$ to the mint, then the mint calculates\n\n\\qe{y (z y^{-k'})^{1/(k'-k)}=y (g^{b(k'-k)})^{1/(k'-k)}=y g^b \\mod p}\n\nThe mint can then simply look up who sent $y g^b$ to it and thus learn\nAlice's identity.\n\n\\section{Type I Defence}\n\nOne defence against this attack is to make the mint prove that it has\nsigned with $k$ and not some other number. Since the mint must not\nreveal $k$, this proof must be a zero-knowledge proof. Two possible\nzero-knowledge proofs are known to me.\n\n\\subsection{Variation 1\\cite{Goldberg2}}\n\nGiven a coin request, $y g^b$, the mint chooses a random number $r$\n s.t.\n\n\\qe{r \\in [1,p-1)}\n\ns.t. r is invertible modulo $p-1$ (i.e. $gcd(r,p-1)=1$) and calculates\n\n\\qe{t=k/r \\mod{p-1}}\n\n($p-1$ rather than $p$ because $r$ and $t$ will be used as exponents\nmodulo $p$). The mint then sends Alice\n\n\\qe{Q=(y g^b)^r \\mod p}\n\nand\n\n\\qe{A=g^r \\mod p}\n\nAlice then randomly demands one of $r$ or $t$.\n\nIf Alice chose $r$, she verifies that\n\n\\qe{Q=(y g^b)^r \\mod p}\n\nand\n\n\\qe{A=g^r \\mod p}\n\nIf Alice chose $t$, she verifies that\n\n\\qe{A^t=g^{rt}=g^k \\mod p}\n\nand\n\n\\qe{Q^t=(y g^b)^{rt}=(y g^b)^k=z \\mod p}\n\nNote that a mint that wants to cheat has a .5 chance of getting away\nwith it each time (by guessing whether the challenger will choose $r$\nor $t$ and lying about $Q$ and $A$ appropriately). Naturally, it is\nincreasingly unlikely to get away with this with each repetition. A\nsuspicious challenger could always repeat the protocol until the\nprobability of cheating is low enough to make them happy.\n\n\\subsection{Variation 2\\cite{Chaum}}\n\nThe mint chooses a random value $r$ and sends Alice\n\n\\qe{u=g^r \\mod p}\n\nand\n\n\\qe{v=(y g^b)^r \\mod p}\n\nAlice responds with a challenge $d$. The mint answers with\n\n\\qe{w=dk+r \\mod{(p-1)/2}}\n\nAlice verifies that\n\n\\qe{g^w=g^{dk+r}=(g^k)^d u \\mod p}\n\nand\n\n\\qe{(y g^b)^w=(y g^b)^{dk+r}=((y g^b)^k)^d v=(y g^b)^d v \\mod p}\n\n\\subsection{Non-interactive variant}\n\nIt is suggested that choosing\n\n\\qe{d=hash(u,v)}\n\nwould allow the second variation to be used non-interactively. The\nmint sends $(d,w)$ along with the coin, Alice calculates\n\n\\qe{g^w (g^k)^{-d}=u \\mod p}\n\nand\n\n\\qe{(y g^b)^w m^{-d}=v \\mod p}\n\nand verifies that $d=hash(u,v)$.\n\nI'm not entirely convinced that it isn't possible to search for (or\neven calculate) a set of values that makes this appear to work whilst\nstill signing with $k'$.\n\n\\section{Type II Defence\\cite{Anon1}}\n\nAnother defence is to combine two blinding methods, using two\nindepenent random blinding factors. With this method, the\ncoin-withdrawal protocol changes as follows.\n\nTo withdraw a coin Alice picks a random $x$, the coin ID, from a\nsufficiently large set that two equal values are unlikely to ever be\ngenerated, and calculates,\n\n\\qe{y=\\oneway{x}}\n\n(see \\ref{sec:oneway}). $y$ should be in $G$; check that\n\n\\qe{y^{(p-1)/2}=1 \\mod p}\n\nAlice chooses random blinding factors $b_y,b_g \\in [1,p-1)$, ensuring\nthat $b_y$ is invertible modulo $p-1$ (i.e. $gcd(y,p-1)=1$) and sends\n$y^{b_y} g^{b_g}$ (the coin request) to the mint. The mint debits\nAlice's account and returns the blinded signature,\n\n\\qe{m=(y^{b_y} g^{b_g})^k \\mod p}\n\nAlice unblinds $m$, calculating the signature,\n\n\\qearray{z&=&(m.(g^k)^{-b_g})^{1/b_y} \\\\\n\t  &=&((y^{b_y} g^{b_g})^k g^{-kb_g})^{1/b_y} \\\\\n\t  &=&(y^{kb_y} g^{kb_g} g^{-kb_g})^{1/b_y} \\\\\n\t  &=&(y^{kb_y})^{1/b_y} \\\\\n\t  &=&y^k \\mod p}\n\nnot forgetting that $1/b_y$ must be calculated modulo $p-1$, since it is\nused as an exponent.\n\nNow $z$ is in the same form as in the original scheme and we can\nproceed as normal.\n\n\\subsection{Failed Attack}\n\nIf the mint attempts to mark the coin, as before, then let's see what\nhappens. The blinded signature is\n\n\\qe{m=(y^{b_y} g^{b_g})^{k'} \\mod p}\n\nunblinding, Alice gets\n\n\\qearray{z&=&(m.(g^k)^{-b_g})^{1/b_y} \\\\\n\t  &=&((y^{b_y} g^{b_g})^{k'} g^{-kb_g})^{1/b_y} \\\\\n\t  &=&(y^{k'b_y} g^{k'b_g} g^{-kb_g})^{1/b_y} \\\\\n\t  &=&(y^{k'b_y} g^{(k'-k)b_g})^{1/b_y} \\\\\n\t  &=&y^{k'} g^{(k'-k)b_g/b_y} \\mod p}\n\nBecause this result entangles both the unknown (to the mint) value $y$\nand the, also unknown, value $g^{b_g/b_y}$, the mint cannot even\nverify that this is a correct signature, let alone figure out who gave\nit the blinded coin in the first place.\n\n\\section{Type III Defence}\n\nIt has recently been pointed out that the Decisional Diffie-Hellman\n(DDH) problem has to be separated from the Diffie-Hellman problem\n(also known as the Computational Diffie-Hellman problem) (DH). In\nparticular there are groups where DDH is easy even though DH is\nhard. What this actually means in practice is that although given $g$,\n$g^a$ and $g^b$ we can't find an $h$ s.t. $h=g^{ab}$, we can, given\n$g$, $g^a$, $g^b$ and $g^c$, determine whether $ab=c$ (all modulo $p$,\nof course).\\cite{Joux}\n\nGiven such a group, it is possible to verify that the signature is\ncorrect in single blinding without a zero knowledge proof. This works\nlike this: once the coin $x$ has been signed, we have $y=oneway(x)$, a\nnumber $z$ that we hope is $y^k$ (but let us signify our doubt for now\nby calling it $y^{k'}$), $g$ and $g^k$.\\cite{Goldberg}\n\nWe can check the correctness of $z$ using the easiness of DDH\nas follows: since $g$ is a generator for the group, there must exist a\n$t$ s.t. $y=g^t$. Then we have $g$, $g^t$ (which is $y$), $g^k$ and\n$g^{tk'}$ (which is $y^{k'}=z$). We can use easy DDH to check whether\n$tk=tk'$. If it is, then, of course, $k'=k$ and the signature is\ngenuine.\n\nOf course, the groups we are talking about here are not $Z_p^*$. In\nfact, the groups discovered so far with this property are carefully\nconstructed elliptic curves.\n\nNote that there may well be an argument that the weakness of DDH in\nthis group means that the blind signature constitutes a verifiable\nsignature as covered by Chaum's patent and hence would no longer\nsidestep the patent.\n\n\\section{Cost and Value}\n\nAlthough there are those that hold that a coin should have a value\nsimilar to its cost of production, this is clearly insane, at least\nwhen the coin is to be used as money\\footnote{A clear example where it\nis not insane is Adam Back's hashcash used as an anti-spam measure -\nin that case, the whole point is that the coin is expensive to\nproduce.}.\n\nIn general, the cost of production should be considerably\nless than the value of the coin. So, it is worth calculating the cost\nof producing Lucre coins.\n\nAssuming that the coins are relatively low value, then a 512 bit\nsigning key should be sufficient. The cost of producing a coin is\nreally the cost of signing it twice (once blinded when withdrawn, and\nonce ublinded when deposited). Implemented in Java on a 300 MHz\nPentium\\footnote{Surely nothing can be slower that this?} we can\nachieve 25 signs per second. A server in the Bunker\n(http://www.thebunker.net/) costs \\pounds250 per month.\n\nThat's \\pounds8 per day. 30p per hour, .5p per minute, .001p per second,\n.0004p per sign.\n\nSo, values of .01p per coin are easily achievable.\n\nIncidentally, signing with a 1024-bit key takes around 6 times as\nlong, so values of .1p with 1024-bit security are also achievable.\n\n\\section{Choosing Parameters}\n\nWhen creating a mint, there are a number of parameters to choose, some\nof which must satisfy certain properties. Also, some may be well-known\nand some have to be secret. This section discusses these requirements.\n\n\\subsection{The Prime, $p$}\n\nThe prime, as noted in \\ref{sec:mint}, needs to be a Sophie Germain\nprime\\footnote{Strictly, a Sophie Germain prime is the {\\it smaller} of\nthe two, and we want the larger.}. There's no particular requirement\nfor secrecy, so an existing prime that has been proven prime should be\npreferred to a probabilistically generated one.\n\nThe other factor in choosing the prime is a cost/security tradeoff. If\nthe prime is too small, there is a danger that an attacker can\nretrieve it from coin signatures by brute force. If it is too large,\nthen the cost of signing coins can become prohibitive. A detailed\nanalysis of this tradeoff may be the subject of another paper, but for\nnow (i.e. in February 2003), I would say that a 512 bit prime should\nonly be used for very low value coins. 1024 or 2048 bits should be\nsafe for most applications.\n\nWhere can such primes be found? RFC 2412, Appendix E, contains\n(allegedly) proven 768, 1024 and 1536 bit primes, though certificates\nare not included. Nor is it entirely clear that $(p-1)/2$ have also\nbeen proven prime.\n\nThe Internet Draft draft-ietf-ipsec-ike-modp-groups-05.txt adds 2048,\n3072, 4096, 6144 and 8192 bit primes - but with no statement of proof\n(and obviously no certificates). Sinced I-Ds are ephemeral, I include\nthe primes here.\n\n\\qe{2^{1536} - 2^{1472} - 1 + 2^{64} ( 2^{1406} \\pi + 741804 ) }\n\n\\begin{tt}\n\tFFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1\n\t29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD\n\tEF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245\n\tE485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED\n\tEE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D\n\tC2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F\n\t83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D\n\t670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF\n\\end{tt}\n\n\\qe{2^{2048} - 2^{1984} - 1 + 2^{64} ( 2^{1918} \\pi + 124476 ) }\n\n\\begin{tt}\n        FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1\n        29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD\n        EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245\n        E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED\n        EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D\n        C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F\n        83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D\n        670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B\n        E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9\n        DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510\n        15728E5A 8AACAA68 FFFFFFFF FFFFFFFF\n\\end{tt}\n\n\\qe{2^{3072} - 2^{3008} - 1 + 2^{64} ( 2^{2942} \\pi + 1690314 ) }\n\n\\begin{tt}\n        FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1\n        29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD\n        EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245\n        E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED\n        EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D\n        C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F\n        83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D\n        670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B\n        E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9\n        DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510\n        15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64\n        ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7\n\\end{tt}\n\n\\qe{2^{4096} - 2^{4032} - 1 + 2^{64} ( 2^{3966} \\pi + 240904 ) }\n\n\\begin{tt}\n        FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1\n        29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD\n        EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245\n        E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED\n        EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D\n        C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F\n        83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D\n        670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B\n        E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9\n        DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510\n        15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64\n        ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7\n        ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B\n        F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C\n        BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31\n        43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7\n        88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA\n        2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6\n        287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED\n        1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9\n        93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34063199\n        FFFFFFFF FFFFFFFF\n\\end{tt}\n\n\\qe{2^{6144} - 2^{6080} - 1 + 2^{64} ( 2^{6014} \\pi + 929484 ) }\n\n\\begin{tt}\n        FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1\n        29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD\n        EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245\n        E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED\n        EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D\n        C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F\n        83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D\n        670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B\n        E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9\n        DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510\n        15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64\n        ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7\n        ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B\n        F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C\n        BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31\n        43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7\n        88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA\n        2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6\n        287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED\n        1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9\n        93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34028492\n        36C3FAB4 D27C7026 C1D4DCB2 602646DE C9751E76 3DBA37BD\n        F8FF9406 AD9E530E E5DB382F 413001AE B06A53ED 9027D831\n        179727B0 865A8918 DA3EDBEB CF9B14ED 44CE6CBA CED4BB1B\n        DB7F1447 E6CC254B 33205151 2BD7AF42 6FB8F401 378CD2BF\n        5983CA01 C64B92EC F032EA15 D1721D03 F482D7CE 6E74FEF6\n        D55E702F 46980C82 B5A84031 900B1C9E 59E7C97F BEC7E8F3\n        23A97A7E 36CC88BE 0F1D45B7 FF585AC5 4BD407B2 2B4154AA\n        CC8F6D7E BF48E1D8 14CC5ED2 0F8037E0 A79715EE F29BE328\n        06A1D58B B7C5DA76 F550AA3D 8A1FBFF0 EB19CCB1 A313D55C\n        DA56C9EC 2EF29632 387FE8D7 6E3C0468 043E8F66 3F4860EE\n        12BF2D5B 0B7474D6 E694F91E 6DCC4024 FFFFFFFF FFFFFFFF\n\\end{tt}\n\nCertificates for all of these can be found at\nftp://ftp.ssh.com/pub/ietf/ecpp-certificates, however, I am not aware\nof source for code that allows the certificates to be checked.\n\n\\subsection{The Generator, $g$}\n\nEquations \\ref{eq:3} and \\ref{eq:1} constrain the generator. Luckily,\nthere's a trivial choice that satisfies them always: 4.\n\n\\subsubsection{Proof}\n\n\\qe{4^2=16=1 \\mod {15}}\n\nand 15 isn't prime.\n\n\\qe{n^{p-1}=1 \\mod p}\n\nby Euler's theorem, so\n\n\\qe{2^{p-1}=4^{(p-1)/2}=1 \\mod p}\n\nwhich satisfies \\ref{eq:1} for all primes.\n\n\\subsection{Coin Size}\n\nThe coin needs to be large enough that collisions are extremely\nunlikely. The only other constraint is that the total size needs to be\nthe same as the key size, so it should not be so large as to reduce\nthe size of the stuff added by the one-way coin function (see\n\\ref{sec:oneway}) to a level were coin signatures might be\nforged. Generally 128 bits is considered sufficient to avoid\ncollisions in most real-world situations. Since we've stipulated a\nminimum key size of 512 bits, there's no reason to fiddle with this,\nso 128 bits for the random part is sufficient.\n\nNote that even though the client generates the coin, there's no reason\nto defend against a client generating the same coin twice (or the same\ncoin as someone else), since that would cause their coin to appear to\nbe a doublespend and would cost them money.\n\n\\section{Theory}\n\n\\subsection{Subgroup Order}\n\\label{sec:theory1}\n\n(\\ref{eq:1}) ensures that the order of the subgroup generated by $g$ is\n$(p-1)/2$.\n\n\\subsubsection{Leakage}\n\nThis avoids leakage of information about $k$ which can\noccur if $g$ generates the whole of $Z_p^*$, because\n\n\\qe{(g^k)^{(p-1)/2}\\left\\{\\begin{array}{ll}\n\t=1 & \\textrm{if $k$ is even} \\\\\n\t\\neq 1 & \\textrm{if $k$ is odd} \\\\\n\\end{array} \\right.}\n\n{\\bf Proof}\n\nIf $k$ is even, then there exists an $n$\ns.t. $k=2n$.\n\n\\qe{(g^{2n})^{(p-1)/2}=(g^n)^{p-1}}\n\nSince\n\n\\qe{gcd(g^n,p)=1}\n\nthen, by Euler's theorem, \n\n\\qe{\\label{eq:2}(g^n)^{p-1}=1 \\mod p}\n\nIf $k$ is odd, then there exists an $n$ s.t. $k=2n+1$.\n\n\\qe{(g^{2n+1})^{(p-1)/2}=(g^n)^{p-1} g^{(p-1)/2}}\n\n\\qe{(g^n)^{p-1}=1 \\mod p}\n\n(see (\\ref{eq:2})) and\n\n\\qe{g^{(p-1)/2} \\neq 1 \\mod p}\n\nbecause the order of $g$ is $p-1$, so no $y < p-1$ can give $g^y=1\n \\mod p$. So\n\n\\qe{(g^n)^{p-1} g^{(p-1)/2}=1 \\cdot x \\mod p, x \\neq 1}\n\n\\subsubsection{Subgroup Order Revisited}\n\nIt has been pointed out that using a $g$ that generates the whole\ngroup $Z_p^*$ and choosing $k$ odd also fixes both the above problems,\nand makes some parts of the protocol cheaper (because you can avoid\nthe exponentiation in the one-way function). This seems to me to be\nsomehow less satisfying, but I can't see anything actively wrong with\nit.\n\n\\subsection{One-way Coin Function}\n\\label{sec:oneway}\n\nThe purpose of the one way function is to prevent Alice from cheating\nthe mint by producing variants on a signed coin by simpy reblinding\nthe coin and the signature - the fact that the coin has a special\nstructure prevents this from working.\n\nThe one-way coin function can, in principle, be any one way function\nproducing a sufficient number of bits (i.e. around the same number as\nin $p$), but the one chosen for Lucre is defined as follows: Let the\nrandom seed for the coin be in $[0,2^n)$ where\n\n\\qe{n=m+((\\log_2(p)-m) \\bmod 160)}\n\n$m$ is the minimim number of bits in $x$, chosen to be large\nenough to avoid collisions (128 in Lucre's case). We then define\n\n\\qe{\\oneway{x}=x\\|SHA1(x\\|1)\\|SHA1(x\\|2)\\| \\cdots \\|SHA1(x\\|(\\log_2(p)-n)/160)}\n\nwhere $\\|$ denotes concatenation. In case it isn't obvious, this\nensures that\n\n\\qe{\\log_2(\\oneway x) \\approx \\log_2(p)}\n\nNote that the resulting coin must actually be in $G$, so it may take\nseveral attempts to find a correct one.\n\nAlso note that Lucre encodes the appended numbers as two bytes, LSB\nfirst. This is massive overkill and allows for gigantic primes.\n\n\\subsection{A Possibly Weak One-Way Coin Function}\n\nIn an earlier version of Lucre, we defined the one-way function like\nthis\n\n\\qe{h_0(x)=x}\n\\qe{h_k(x)=h_{k-1}(x)\\|SHA1(h_{k-1}(x))}\n\n\\qe{\\oneway{x}=h_{(n-m)/160}(x)}\n\nThe problem with this is that\n\n\\qe{\\oneway{x|SHA1(x)}=\\oneway{x}/2^{160} + O(2^{160})}\n\nWhilst we can't see an attack that uses this property, we find it\nslightly worrying, and so prefer the more conventional construction above.\n\n\\subsection{A Bad One-way Coin Function}\n\\label{sec:badoneway}\n\nAn earlier version of this paper contained an ``improvement'' to the\none-way coin generation - namely the need to test the resulting coin\nfor membership in $G$ was removed by adding an extra step:\n\n\\qe{\\oneway x=g^{\\preoneway x} \\mod p}\n\nwhere $\\preoneway$ is the one-way function defined above. This guarantees\nthe coin is in $G$. However, the consequences are disastrous\\cite{Wagner}.\n\nThe mint publishes $g^k \\bmod p$. A coin's signature is $\\oneway\nx^k \\bmod p$. But\n\n\\qe{\\oneway x^k=(g^{\\preoneway x})^k=(g^k)^{\\preoneway x} \\mod p}\n\nThat is, the signature can be forged, trivially!\n\n\\begin{thebibliography}{99}\n\n\t\\bibitem{Goldberg2} Ian Goldberg -- mail to {\\sl coderpunks}.\n\n\t\\bibitem{Chaum} David Chaum and Torben Pedersen -- {\\sl\n\t\"Wallet databases with observers\"} -- Advances in Cryptology\n\t-- Proceedings of Crypto '92, pp. 89-105.\n\n\t\\bibitem{Joux} Antoine Joux and Kim Nguyen -- {\\sl\n\t``Separating Decision Diffie-Hellman from Diffie-Hellman in\n\tcryptographic groups''} -- http://eprint.iacr.org/2001/003.\n\n\t\\bibitem{Goldberg} Ian Goldberg -- mail to {\\sl coderpunks}.\n\n\t\\bibitem{Wagner} David Wagner -- personal communication.\n\n\t\\bibitem{Anon1} Anonymous --\n\thttp://www.mail-archive.com/coderpunks@toad.com/msg02186.html\n\tand\n\thttp://www.mail-archive.com/coderpunks@toad.com/msg02323.html.\n\n\\end{thebibliography}\n\n\\section{Change History}\n\nA change history was not kept until v1.8. The original version of this\npaper was written 30 November 1999.\n\n\\subsection{Changes in 1.8}\n\nReleased 1 June 2003.\n\nSeveral errors in the handling of exponents in modulo arithmetic and\nchecks for invertability were corrected.\n\n\\end{document}\n", "meta": {"hexsha": "be7cdfada36db4253ecdf5383b03ad443ae0bd26", "size": 23560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory2.tex", "max_stars_repo_name": "da2ce7/lucre", "max_stars_repo_head_hexsha": "ef4a664c33310b923a7741a2644d0bc86c1f1b51", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-01-06T20:07:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T22:53:13.000Z", "max_issues_repo_path": "doc/theory2.tex", "max_issues_repo_name": "da2ce7/lucre", "max_issues_repo_head_hexsha": "ef4a664c33310b923a7741a2644d0bc86c1f1b51", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-12-02T22:53:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-03T15:36:00.000Z", "max_forks_repo_path": "doc/theory2.tex", "max_forks_repo_name": "da2ce7/lucre", "max_forks_repo_head_hexsha": "ef4a664c33310b923a7741a2644d0bc86c1f1b51", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-05-23T23:38:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T04:14:36.000Z", "avg_line_length": 34.7492625369, "max_line_length": 79, "alphanum_fraction": 0.7239813243, "num_tokens": 8679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6001880521052715}}
{"text": "\\chapter{Python Lists}\n\nWatch CS Dojo's \\textbf{Introduction to Lists in Python} video at \\url{https://www.youtube.com/watch?v=tw7ror9x32s}\n\nTo review, Python list is an indexed collection. The indices start at\nzero. You can create a list using square brackets.\n\nNow you are going to write a program that makes an array of\nstrings. Type this code into a file called \\filename{faves.py}:\n\n\\begin{Verbatim}\nfavorites = [\"Raindrops\", \"Whiskers\", \"Kettles\", \"Mittens\"]\nfavorites.append(\"Packages\")\nprint(\"Here are all my favorites:\", favorites)\nprint(\"My most favorite thing is\", favorites[0])\nprint(\"My second most favorite is\", favorites[1])\nnumber_of_faves = len(favorites)\nprint(\"Number of things I like:\", number_of_faves)\n\nfor i in range(number_of_faves):\n    print(i, \": I like\", favorites[i])\n\\end{Verbatim}\n\nRun it:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n$ \\textbf{python3 faves.py}\nHere are all my favorites: ['Raindrops', 'Whiskers', 'Kettles', 'Mittens', 'Packages']\nMy most favorite thing is Raindrops\nMy second most favorite is Whiskers\nNumber of things I like: 5\n0 : I like Raindrops\n1 : I like Whiskers\n2 : I like Kettles\n3 : I like Mittens\n4 : I like Packages\n\\end{Verbatim}\nAfter you have run the code, study it until the output makes sense.\n\n\\begin{Exercise}[title={Assign into list}, label=assignintolist]\n  Before you list the items, replace \"Mittens\" with \"Gloves\".\n\\end{Exercise}\n\\begin{Answer}[ref=assignintolist]\n\\begin{Verbatim}\nfavorites[3] = \"Gloves\"\n\\end{Verbatim}\n\\end{Answer}\n\n\\section{Evaluating Polynomials in Python}\n\nFirst, before you go any further, you need to know that raising a\nnumber to a power is done with ** in Python.  So for example, to get\n$5^2$, you would write \\texttt{5**2}.\n\nBack to polynomials: if you had a polynomial like $2x^3 -9x + 12$, you\ncould write it like this: $12x^0 + (-9)x^1 + 0x^2 + 2x^3$.  We could\nuse this representation to keep a polynomial in a Python list. We\nwould simply store all the coefficients in order:\n\\begin{Verbatim}\npn1 = [12,-9,0,2]\n\\end{Verbatim}\n\nIn the list, the index of each coefficient would correspond to the\ndegree of that monomial. For example, in the list 2 is at index 3, so\nthat entry represents $2x^3$.\n\nIn the last chapter, you evaluated the polynomial $x^3 - 3x^2 + 10x -\n12$ at $x=4$. Now you will write code that does that evalution.\nCreate a file called \\filename{polynomials.py} and type in the following:\n\n\\begin{Verbatim}\ndef evaluate_polynomial(pn, x):\n    sum = 0.0  \n    for degree in range(len(pn)):\n        coefficient = pn[degree]\n        term_value = coefficient * x ** degree\n        sum = sum + term_value\n    return sum\n   \npn1 = [-12.0, 10.0, -3.0, 1.0]\ny = evaluate_polynomial(pn1, 4.0)\nprint(\"Polynomial 1: When x is 4.0, y is\", y)\n\\end{Verbatim}\n\nRun it. It should evaluate to 44.0.\n\n\\section{Walking the list backwards}\n\nNow you are going to make a function that makes a pretty string to\nrepresent your polynomial. Here is how it will be used:\n\\begin{Verbatim}\ndef polynomial_to_string(pn):\n    ...Your Code Here...\n\npn_test = [-12.0, 10.0, 0.0, 1.0]\nprint(polynomial_to_string(pn1))\n\\end{Verbatim}\n\nThis would output:\n\\begin{Verbatim}\n1.0x**3 + 10.0x + -12.0\n\\end{Verbatim}\nThis is not as simple as you might hope. In particular:\n\\begin{itemize}\n\\item You should skip the terms with a coefficient of zero\n\\item The term of degree 1 has an $x$, but no exponent\n\\item The term of degree 0 has neither an $x$ nor an exponent\n\\item Standard form demands that you list the terms in the reverse\n  order from that of your coefficients list. You will need to walk the\n  list from last to first.\n\\end{itemize}\n\nAdd this function to your \\filename{polynomials.py} file after your \\pyfunction{evaluate\\_polynomial} function:\n\\begin{Verbatim}\n  def polynomial_to_string(pn):\n    \n    # Make a list of the monomial strings\n    monomial_strings = []\n\n    # Start at the term with the largest degree\n    degree = len(pn) - 1\n\n    # Go through the list backwards stop after constant term\n    while degree >= 0:\n        coefficient = pn[degree]\n\n        # Skip any term with a zero coefficient\n        if coefficient != 0.0:\n\n            # Describe the monomial\n            if degree == 0:\n                monomial_string = \"{}\".format(coefficient)\n            elif degree == 1:\n                monomial_string = \"{}x\".format(coefficient)\n            else:\n                monomial_string = \"{}x^{}\".format(coefficient, degree)\n                \n            # Add it to the list\n            monomial_strings.append(monomial_string)\n\n        # Move to the previous term\n        degree = degree - 1\n\n    # Deal with the zero polynomial\n    if len(monomial_strings) == 0:\n        monomial_strings.append(\"0.0\")\n    \n    # Make a string that joins the terms with a plus sign\n    return \" + \".join(monomial_strings)\n\\end{Verbatim}\n\nNote that in a list $n$ items, the indices go from 0 to $n-1$. So when\nwe are walking the list backwards, we start at \\pyfunction{len(pn) -\n  1} and stop at zero.\n\nLook over the code and google the functions you aren't familar\nwith. For example, if you want to know about the \\pyfunction(join)\nfunction, google for ``python join''.\n\nNow change your code to use the new function:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\npn1 = [-12.0, 10.0, -3.0, 1.0]\ny = evaluate_polynomial(pn1, 4.0)\n\\textbf{print(\"y =\", polynomial\\_to\\_string(pn1))}\nprint(\"    When x is 4.0, y is\", y)\n\\end{Verbatim}\n\nRun the program. Does the function work?\n\n\\begin{Exercise}[title={Evaluate Polynomials}, label=pyevalpolynomials]\nUsing the function that you just wrote, add a few lines of code to\n\\filename{polynomials.py} to evaluate the following polynomials:\n\\begin{itemize}\n\\item Find $4x^4 - 7x^3 - 2x^2 + 5x + 2.5$ at $x = 8.5$.  It should be 16481.875\n\\item Find $5x^5 - 9$ at $x = 2.0$.  It should be 151.0\n\\end{itemize}\n\\end{Exercise}\n\\begin{Answer}[ref=pyevalpolynomials]\n\\begin{Verbatim}\npn2 = [2.5, 5.0, -2.0, -7.0, 4.0]\ny = evaluate_polynomial(pn2, 8.5)\nprint(\"Polynomia 2: When x is 8.5, y is\", y)\n\npn3 = [-9.0, 0.0, 0.0, 0.0, 0.0, 5.0]\ny = evaluate_polynomial(pn3, 2.0)\nprint(\"Polynomial 3: When x is 2.0, y is\", y)    \n\\end{Verbatim} \n\\end{Answer}\n\n\\section{Plot the polynomial}\n\nWe can evaluate a polynomial at many points and plot them on a\ngraph. You are going to write the code to do this.  Create a new file\ncalled \\filename{plot\\_polynomial.py}. Copy your \\pyfunction{evaluate\\_polynomial}\nfunction into the new file.\n\nAdd a line at the beginning of the program that imports the plotting library matplotlib:\n\\begin{Verbatim}\nimport matplotlib.pyplot as plt\n\\end{Verbatim}\n\nAfter the \\pyfunction{evaluate\\_polynomial} function:\n\\begin{itemize}\n\\item Create a list with polynomial coefficients.\n\\item Create two empty arrays, one for x values and one for y values.\n\\item Fill the x array with values from -3.5 to 3.5. Evaluate the polynomial at each of these points; put those values\n  in the y array.\n\\item Plot them\n\\end{itemize}\n\nLike this:\n\\begin{Verbatim}\n# x**3 - 7x + 6\npn = [6.0, -7.0, 0.0, 1.0]\n\n# These lists will hold our x and y values\nx_list = []\ny_list = []\n\n# Start at x=-3.5\ncurrent_x =-3.5\n\n# End at x=3.5\nwhile current_x <= 3.5:\n    current_y = evaluate_polynomial(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.1\n\n# Plot the curve\nplt.plot(x_list, y_list)\nplt.grid(True)\nplt.show()\n\\end{Verbatim}\n\nYou should get a beautiful plot like this:\n\n\\includegraphics[width=\\textwidth]{polyplot1.png}\n\nIf you received an error that the matplotlib was not found, use pip to install it:\n\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n$ \\textbf{pip3 install matplotlib}\n\\end{Verbatim}\n\n\\begin{Exercise}[title={Observations}, label=plotobservations]\n  Where does your polynomial cross the y-axis? Looking at the\n  polynomial $x^3 - 7x + 6$, could you have guessed that value?\n\n  \\vspace{20mm}\n  \n  Where does your polynomial cross the x-axis? The places where a\n  polynomial crosses the x-axis is called \\emph{its roots}. Later in\n  the course, you will learn techniques for finding the roots of a\n  polynomial.\n\\end{Exercise}\n\\begin{Answer}[ref=plotobservations]\n  The polynomial crosses the y-axis at 6. When x is zero, all the terms are zero except the\n  last one. Thus you can easily tell that $x^3 - 7x + 6$ will cross the y-axis at $y=6$.\n\n  Looking at the graph, you tell that the curve crosses the y-axes\n  near -3, 1 and 2. If you plug those numbers into the polynomial, you\n  would find that it evalutes to zero at each one. Thus, $x=-3$, $x=1$, and $x=2$ are roots.\n\\end{Answer}\n", "meta": {"hexsha": "97ef8685fe7bc25e254295a1455188c9f0283f5d", "size": 8607, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/pylists-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/pylists-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/pylists-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.2359550562, "max_line_length": 118, "alphanum_fraction": 0.7018705705, "num_tokens": 2565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.6001075870719498}}
{"text": "\\label{ch:two}\n\\section{What is a shared key?}\n\tThe first step towards understanding \\emph{bound information} is looking at the end product of a key exchange. \n\tThe secret key is what we want to obtain from a protocol, so we must understand what we are after.\n\tWhat is then a shared key? \n\tHow do we define a common secret shared between Alice and Bob than can be used formally later on? \n%    \t\\subsection{Common Secret} \\label{commonsecret}\n    \t\nIntuitively a common secret is a piece of information (i.e. \\textit{bits} of information) known to trusted parties --- for example Alice and Bob --- and to none else. \nIn an environment where we allow the presence of an eavesdropper Eve that makes observation on the communication reaching such state is not always trivial. \nThere exist methods and protocols to generate such secrets, even from nothing, although they reach different levels of secrecy. A notable one is the famous Diffie-Hellman method to generate a common cryptographic key \\cite{DH76} . \nWe discuss in section \\ref{comparison}, while still secure, it is not \\textit{information theoretical secure}.\nHere we provide a mathematical definition of a common secret that makes use of concepts that will be explained later in chapter \\ref{ch:four}.\n    \t\\begin{definition}\n\tLet $X,Y,Z,S$ be random variables on the same range $\\mathcal{X}$. Let $X$ be owned by Alice, $Y$ by Bob and $Z$ by Eve. Then if\n  \\begin{equation} \\label{eq:common}\n\t  P[X=Y=S] > 1 - \\epsilon \\tag{common}\n\t\\end{equation}\n\t\\begin{equation} \\label{eq:secret}\n\t  \\I(X;Z) = 0 \\: \\wedge \\: \\I(Y;Z) = 0 \\tag{secret}\n  \\end{equation}\nfor all $\\epsilon > 0 $ we say Alice and Bob share a common secret.\n    \t\\end{definition}\nThe first part defines the \\textit{common} property: $X$ and $Y$ --- Alice and Bob's variables in the system --- must be asymptotically the same, i.e. the probability that they are the same comes arbitrarily close to $1$ for an arbitrarily large number of realization.\nThe second part states that the amount of information Eve can gather about $X$ and $Y$, through it's realization of $Z$, is zero.\n\\section{The analogy with entanglement}\n\tA fascinating feature that arises from quantum mechanics is quantum entanglement. As Einstein, Podolsky and Rosen pointed out almost a century ago \\cite{einstein1935}, \n\tthe measurement of entangled states defies the classical understanding of a state. \n\tThey concluded that the theory is incomplete and has to be replaced.\n\tBell responded to that with \\emph{non-locality}\\cite{Bell64}: there are probability distributions for which there is no local hidden variable model, i.e. exactly what EPR are chasing for.\n\tAs quantum mechanics gives rise to such non-local probability distributions we cannot hope to find a \"local hidden variable model\" replacing quantum mechanics.\n\t\n\tFor a quantum system to exhibit non-locality, entanglement is necessary.\n%\tEntangled particles remain connected so that actions on one affect the other, even when separated by great distances.\n\tConsider two pure quantum states $\\ket{\\psi}_A$ and $\\ket{\\phi}_B$.\n\tThe composite system of the two states is\n\t\\begin{equation}\\label{eq:separable}\n\t\t\\ket{\\psi}_A \\otimes \\ket{\\phi}_B = \\ket{\\psi\\phi}_{AB}\n\t\\end{equation}\n\tStates that can be represented as in Eq. \\ref{eq:separable} are called \\emph{separable}.\n\tNot all states are separable. Non-separable states are called \\emph{entangled}.\n\tConsider now the state\n\t\\begin{equation}\n\t\t\\frac{1}{\\sqrt{2}}\\left(\\ket{0}_A\\otimes\\ket{1}_B - \\ket{1}_A\\otimes\\ket{0}_B\\right) = \\ket{\\Psi^{-}}_{AB}\n\t\\end{equation}\n\tfor it there is no decomposition into (indices are omitted)\n\t\\begin{multline}\n\t\t\\frac{1}{\\sqrt{2}}\\left( (\\alpha_0\\ket0+\\alpha_1\\ket1)\\otimes (\\beta_0\\ket0 + \\beta_1\\ket1) \\right) \\\\\n\t\t= \\frac{1}{\\sqrt{2}} \\left( \\alpha_0\\beta_0\\ket{00} + \\alpha_0\\beta_1\\ket{01} + \\alpha_1\\beta_0\\ket{10} + \\alpha_1\\beta_1\\ket{11} \\right)\n\t\\end{multline}\n\tthat satisfies \n\t\\begin{align}\n\t\\alpha_0\\beta_0 = \\alpha_1\\beta_1 & = 0 \\\\\n\t\\alpha_0\\beta_1 & = 1\\\\\n\t\\alpha_1\\beta_0 & = -1\n\t\\end{align}\n\tThis is an entangled state\\footnote{This particular state is called \"singlet\" and is one of the four Bell's basis presented in \\cite{Bell64}}.\n\t\n\tFurthermore, if Alice measures to have $\\ket{0}$ on her part of the system, then Bob, using the same measurement basis, by non-locality, will measure $\\ket{1}$.\n\tThe other option of measuring $\\ket1$ for Alice and $\\ket0$ for Bob is also equally probable.\n\tAlice and Bob's values are always (anti-)correlated, regardless of which of the measurements is obtained (which is random).\n\n%\tLet a joint quantum system between Alice and Bob be entangled.\n%\tTracing out the part of the system only for Alice (respectively for Bob) will give a completely mixed state. \n%\tSince entanglement is a phenomenon that appears non-locally, it can be measured only on the whole system, i.e. one has to have access to both the states.\n%\tThis makes the two states \\emph{inseparable}. \n%\tA complete (anti-)correlation exists then between maximally entangled states when measured in the same basis.\n%\t This allows Alice and Bob to encode a message onto the quantum state and use it as a variable to share a secret\\footnotemark . \n%\tIf Alice measures to have $\\ket{0}$ on her part of the system, then Bob, using the same measurement basis, by non-locality, will measure $\\ket{1}$\\\\\n\t\n\tQuantum entanglement possesses one more feature that classical correlation does not have: the monogamy of entanglement \\cite{KW04}. \n\tAs Koashi and Winter state in their paper a fundamental difference is that classical correlation can be shared, while quantum entanglement can not. \n\tThis translates to the case where an eavesdropper Eve listens to the message exchange between Alice and Bob: in the classical communication there is no direct way for Alice nor Bob to know that Eve is listening (i.e. \\textit{shares the correlation}), while in the second case Eve breaks the existing correlation between Alice and Bob.\nThese two aspects of quantum entanglement --- correlation and monogamy --- give a valid framework for the establishment of a private channel between parties.\n\t\n\t\n\t\\footnotetext{A quantum state in quantum mechanics describes a single and isolated quantum system. This can be for example an electron or a photon. For our purposes, a quantum state is always abstracted as a \\emph{qubit} or multiple qubits, as described in appendix \\ref{App:appendixB}}\n\t\\footnotetext{There are known protocols that achieve that, for example in \\cite{Ekert91} or \\cite{BB84}}\n%   \t \\begin{figure}[h]\n%\t\t\t\\centering\n%\t\t\t\\input{images/entanglement-origin}\n%\t\t\t\\caption{origin of entanglement via linearity}\n%\t\t\\end{figure}\n\t\t\n\\section{Examples of key exchange}\n\tExchanging keys for encryption was once done \\textit{physically}, requiring the parties to meet and assure that no eavesdropper was present.\n\tModern cryptographic systems make use of protocols over telecommunication channels. \n\tIn both cases the result at the end is that the trusted parties leave (or terminate the protocol) with a bit of information that they know it will be known only to them.\n\tHere we present examples for both classical and quantum mechanical channels and compare them.\n\tThe intention is to compare them and discuss on the different level of security -- computational, physical and information theoretical --- one might achieve with the correct implementation of one of those.\n\t\t\\subsection{The Diffie-Hellman key exchange}\n\t\t\\label{Diffie}\n\t\t% Explain only how the protocol works, what is based on, what are its bounds, how it can be attacked (ideally).\n\t\t% Don't dive into Maurer violations, that will be covered in chapter [3] (XX)\n\t\n\t\tA famous and widely used method for the exchange of cryptographic keys is the Diffie-Hellman (DH) key-exchange method.\n\tThe whole process can be summarized in five basic steps \\cite{DH76}:\n\t\\begin{enumerate}\n\t\t\\item Alice and Bob \\emph{publicly} communicate and agree on two numbers, that will serve as basis for the computations.\n\t\t\\item Each party generates \\emph{locally} a personal and distinct secret ($s_A$ and $s_B$) without ever communicating it .\n\t\t\\item They mix their own secret with the common agreed basis, producing a result $R_A$ and $R_B$. The mathematical properties of this operation make it so it is computational infeasible to go back and retrieve the secrets $s$ from $R$.\n\t\t\\item Both parties exchange \\emph{publicly} their result. Each party now know both the result of the other and their own.\n\t\t\\item Each party applies their secret to the received $R$. The outputs are equal for Alice and Bob so they can use this result as a common secret to create a key.\n\t\\end{enumerate}\t \n\t\n\tThe parts exchanged over the public channel --- the ones that Eve knows --- are only the mutually agreed base and the two partial mixtures. \n\tIt can be proven that those two elements alone give no information about the complete shared secret and that it is virtually impossible (within reasonable amount of time and use of resources) to obtain the correct final product with only those two.\\\\  \n\t\n\t\\subsection{The BB84 protocol}\n\tProtocols for the exchange of keys over a quantum channel have been invented \\cite{BB84, Ekert91}.\n\tThese protocols work on the underlying physics of quantum mechanics.\n\tAlice and Bob need then to have access to a quantum channel to exchange quantum states\n\t\\footnote{A quantum channel is anything that can carry quantum states between two points. For example an optical fiber that carries photons.}.\n\tHere follows the BB84 protocol as described in \\cite{NC10} :\n\t\t\\begin{enumerate}\n\t\t\t\\item Alice chooses $(4+\\delta )n$ data bits.\n\t\t\t\\item Alice chooses a random $(4+\\delta )n$-bit string $b$. She encodes each data bit as $\\{\\ket{0},\\ket{1}\\}$ if the corresponding bit of $b$ is $0$ or with the diagonal basis $\\{\\frac{\\ket{0} + \\ket{1}}{\\sqrt{2}},\\frac{\\ket{0} - \\ket{1}}{\\sqrt{2}}\\}$ if $b$ is $1$.\n\t\t\t\\item Alice sends the resulting state to Bob.\n\t\t\t\\item Bob receives the $(4+\\delta )n$, announces \\emph{publicly} this fact, and measures each qubit in the $X$ or $Z$ basis at random.\n\t\t\t\\item Alice announces \\emph{publicly} $b$.\n\t\t\t\\item Alice and Bob discard any bits where Bob measured a different basis than Alice prepared. With high probability, there are at least $2n$ bits left (if not, abort the protocol and restart). They keep $2n$ bits.\n\t\t\t\\item Alice selects a subset of $n$ bits that will to serve as a check on Eve's interference, and tells Bob which basis she selected.\n\t\t\t\\item Alice and Bob announce \\emph{publicly} and compare the values of the $n$ check bits. If more than an acceptable number disagree, they abort the protocol.\n\t\t\t\\item Alice and Bob perform information reconciliation and privacy amplification on the remaining $n$ bits to obtain $m$ shared key bits.\n\t\t\\end{enumerate}\n\n\t\\subsection{The one-time Pad}\n\t\t%this is not really a method to share a common secret, since you have \n\t\t% to already start with a secret.. <- point that out!\n\t\t\n\t\t% example of utilization of the key after generation\n\t\t% info theoretical key exchanged with OTP over already existing channel\n\t\tThe one-time pad is not a key exchange method, but a technique to encrypt a message once the key is obtained.\n\t\tHere is presented as an example of utilization of a key previously exchanged with some other secure algorithm. \n\t\tThe message obtained from the OTP is as secure as the method that produced the key.\n\t\tThis means that if the key is provided to be information theoretical secure, then Eve is \\emph{completely factored out} from the information contained in the message.\n\t\tShannon proved in \\cite{Shannon49} the perfect security of OTP.\n\t\tFigure \\ref{Fig:OTP} illustrates an example over a 5-bits string.\n\t\tIt is important to notice that in order for to OTP to function correctly the key has to be perfectly random and at least of the same size of the message.\n\t\t\n\t\t\\begin{figure}[h!]\n\t\t\t\\centering\n\t\t\t\\input{images/Otp}\n\t\t\t\\caption{The one-time pad. In order to get true security the key should change each time for each message.}\n\t\t\t\\label{Fig:OTP}\n\t\t\\end{figure}\n\\section{A comparison between securities}\\label{comparison}\n    A point can be made comparing these different way of establishing privacy.\n    The majority of cryptographic systems used are built on computational complexity security. \n\tWhen Shannon laid out the basis of information theory in \\cite{Shannon49} in 1949, he affirmed that the highest level of security (information theoretical security) can only be achieved by sharing a secret key from the beginning.\n\tMaurer later expanded this concept saying that it is not possible to obtain an information theoretical secure key from just a protocol through local operations and public communications\\cite{Maur93}. A starting initial correlation must be provided.\\\\\n\t \n\t Even though the Diffie-Hellman method does start from nothing, it does not violates Maurer's statement.\n\t The key produced by DH is not information theoretical secure. \n\t Step $3$ enumerated above relies on computational complexity.\n\t The difficulty of breaking this step --- thus accessing the correlation between Alice and Bob --- is bounded only by the length of the number chosen one one side and the computational power available to the adversary on the other.\n\t This means, for example, that one cannot use a key obtained through Diffie-Hellman (DH) to generate an information theoretical secure key: \n\t as DH starts from nothing, a protocol $R$ constructed to start as DH and producing information theoretical secure key with LOPC will violate the statement that no key can be crated by LOPC alone.\n\t The BB84 protocol works differently, but also does not violate Maurer.\n\t Albeit Alice and Bob share, at the end of the protocol, a key starting from nothing, and the secret is in theory information theoretical secure --- it can be arbitrarily close ---, it does not so with public (classical) communication.\n\t Alice utilizes a quantum channel to pass the states to Bob, which is not public because of the monogamy of entanglement.\n\t The communication part in BB84 over a classical channel serves only to check for the presence of an enemy Eve, not to modify the secret --- which is already transferred at this point.  \n\t Thus the key is created only through a quantum channel, which is not covered by Maurer's claim.\n\n%    The so-called cryptographic functions are functions that are easy to compute in one way, but have a much higher complexity the other way round.\\\\\n%    This is the case for example for the Diffie-Hellman method. \n%\tThe security in this method relies mainly on step 3 (listed above).    \n%    Here an action as $ R_A = g^{s_A} \\bmod p $ is performed, where $g$ and $p$ are the public common basis agreed beforehand. \n%\tTo get back to $s_A$  one will need to find the prime factors of $R_A$, which is a known hard problem. \n%\tIt is not impossible nevertheless. \n%\tThe difficulty of breaking this step --- thus accessing the correlation between Alice and Bob --- is bounded only by the length of the number chosen one one side and the computational power available to the adversary on the other.\\\\\n%\t\n%\tThe BB84 protocol works differently. \n%\tIt takes advantage of the monogamy of entanglement. \n%\tIf Eve was able to wire-tap the quantum channel, she would disrupt the correlation between Alice and Bob.\n%\tIn this sense the correlation between Alice and Bob is much more protected, since the eavesdropper Eve is factored out from the entangled state $\\rho = \\rho_{AB}\\otimes\\rho_E$.\n%\tHowever, the entanglement in the protocol is only used to spot the presence of Eve over a large number of repetitions of the experiment.\n%\tWhile the amount of information that Eve gets can be bounded by some $\\epsilon$, she is not yet \\emph{completely} factored out.\\\\\n\t \n\t\n    \n\\section{The equivalent of CKA in QM}\n\tWhat we were trying to do was to factor out Eve from Alice and Bob's point of view.\n\tThe goal of classical key agreement (CKA) is also to create a private correlation between Alice and Bob, from one that also includes Eve.\n\tWe already stated that entangled states can provide this level of privacy \\cite{Ekert91}.\n\tHowever pure entangled states are very fragile and do not occur in nature.\n\tThe more general quantum state is a mixed state.\n\tA mixed state is a convex mixture of pure states with their probability.\n\tA mixed state is represented by a density matrix, defined as a positive, trace-$1$ operator.\n\tBy the spectral theorem they can then be wrote in the form of\n\t\\begin{equation}\n\t\t\\rho = \\sum_i p_i \\ketbra{\\psi_i}{\\psi_i} ,\\quad \\ket{\\psi_i}: \\text{ state with probability } p_i\n\t\\end{equation}\n\tand interpreted as a statistical \n\tAssume that Alice and Bob start with a state $\\ket{\\psi_{ABE}}$, which is also mixed with a part owned by Eve. \n\tIs there a way to factor her out the state, so that they obtain\n\t\\begin{equation}\n\t\t\\rho_{AB} = \\Tr_E \\kb{\\psi_{ABE}}{\\psi_{ABE}}\n\t\\end{equation}\n\twith\n\t\\begin{equation}\n\t\t\\rho_{AB}\\otimes\\rho_E\n\t\\end{equation}\n\tafter a series of local operations and classical communication (LOCC)?\n\tQuantum distillation is a process that allows that. \\label{distillation}\n\tIf Alice and Bob have maximally entangled states after distillation then they know --- by the monogamy of entanglement --- that Eve is factored out.\n\tIn other words, the state Alice and Bob have is product with the environment and entangled among them.\n\tThe joint probability distribution $P_{ABE}$ falls similarly into a product $P_{AB}\\cdot P_E$ after a CKA protocol.\n\tHowever from within $P_{AB}$ we cannot decide whether Eve is factored out or not in classical key agreement.\n    \n    \\begin{figure}[h]\n    \t\\centering\n    \t\\input{images/intuition_poster}\n    \t\\caption{Entanglement distillation and CKA utilize a resource (mixed state or probability distribution) to produce a distillate that factors out Eve.}\n    \t\\label{Fig:intuition}\n    \\end{figure}\n    \n    To measure entanglement one might consider the least number of maximally entangled bipartite quantum states required to prepare a density matrix $\\rho_{AB}$ by local operations and classical communication. \n    Similarly one might measure entanglement by the maximal number of singlets that can be obtained form $\\rho$ by local operations and classical communication. \n    These measures are not the same. \n    The first is called \\emph{entanglement cost} or \\emph{entanglement of formation}; the second describes the \\emph{distillate entanglement}. \n    We will discuss the classical counterparts, namely the \\emph{information of formation} and the \\emph{secret-key rate}.\n    Figure \\ref{Fig:intuition} illustrates the analogy between the resource, distillate and cost.\n    This is part of the intuition that leads to bound information.\n    \n    ", "meta": {"hexsha": "2fb7084310a0ea36b08b52dbe4790902b30b20bf", "size": 18782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writings/chapters/chapter2.tex", "max_stars_repo_name": "CrashingBrain/BSc_Project", "max_stars_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_stars_repo_licenses": ["FSFAP"], "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/chapters/chapter2.tex", "max_issues_repo_name": "CrashingBrain/BSc_Project", "max_issues_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_issues_repo_licenses": ["FSFAP"], "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/chapters/chapter2.tex", "max_forks_repo_name": "CrashingBrain/BSc_Project", "max_forks_repo_head_hexsha": "44b91601341ff3a59acbad7abbf28389aa99f89d", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.1061946903, "max_line_length": 335, "alphanum_fraction": 0.7613672665, "num_tokens": 4675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972650509007, "lm_q2_score": 0.689305616785446, "lm_q1q2_score": 0.6001075847576336}}
{"text": "\\subsection{Combining type graphs}\n\\label{subsec:transformation_framework:type_models_and_type_graphs:combining_type_graphs}\n\nThe structure of \\cref{fig:transformation_framework:type_models_and_type_graphs:structure_type_models_graphs} shows that the type graphs $TG_A$ and $TG_B$ are combined into one type graph $TG_{AB}$. This section provides the definition of this combination and its corresponding theorems. Please note that the definitions presented here, just like the previous section, are as generic as possible, and do not actively take into account that $TG_{A}$ and $TG_{B}$ are mostly distinct. This bit of information is added later as part of a theorem and proof.\n\n\\begin{defin}[Combination function on type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine}\n$\\mathrm{combine}$ is a binary function on two type graphs which combines two type graphs into one type graph. It is defined as follows:\n\\begin{align*}\n\\mathrm{combine}(TG_A, TG_B) = \\langle&\nNT = NT_{TG_A} \\cup NT_{TG_B} \\\\&\nET = ET_{TG_A} \\cup ET_{TG_B} \\\\&\n\\!\\!\\sqsubseteq\\ = (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\\\&\nabs = (abs_{TG_A} \\setminus NT_{TG_B}) \\cup (abs_{TG_B} \\setminus NT_{TG_A}) \\cup (abs_{TG_A} \\cap abs_{TG_B}) \\\\&\n\\mathrm{mult} = \\mathrm{mult\\_\\!combine}(TG_A, TG_B) \\\\&\ncontains = contains_{TG_A} \\cup contains_{TG_B} \\rangle\n\\end{align*}\n\nIn which $\\mathrm{mult\\_\\!combine}$ is given as part of \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:mult_combine}.\n\\isabellelref{tg_combine}{GROOVE.Type_Graph_Combination}\n\\end{defin}\n\nIntuitively, the presented definition makes sense. In order to combine two (type) graphs, the nodes and edges of the graph need to be merged. The definition accurately describes this behaviour.\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.3\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/type_graph_combination_inh1.tikz}\n        \\caption{First type graph $TG_A$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh_tg1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.3\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/type_graph_combination_inh2.tikz}\n        \\caption{Second type graph $TG_A$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh_tg2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.3\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/type_graph_combination_inh12.tikz}\n        \\caption{Combined type graph $TG_{AB}$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh_tg12}\n    \\end{subfigure}\n    \\caption{Combination of the inheritance relation}\n    \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh}\n\\end{figure}\n\nTo preserve the correctness of the inheritance relation, the inheritance relation is merged and the transitive closure it taken. This is to ensure that the inheritance relation is correct and contains all subtypes. An example of this is given in \\cref{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh}. The inheritance relation of the first type graph, $TG_A$ is $(( \\type{B}, \\type{B} ), ( \\type{C}, \\type{C} ), ( \\type{C}, \\type{B} ))$. The inheritance relation of the second type graph, $TG_B$ is $(( \\type{A}, \\type{A} ), ( \\type{B}, \\type{B} ), ( \\type{B}, \\type{A} ))$. Taking the union of these relations is not enough to get the correct inheritance relation for the combination of $TG_A$ and $TG_B$, as the inheritance relation is transitive. If the union is taken, the new relation would become $(( \\type{B}, \\type{B} ), ( \\type{C}, \\type{C} ), ( \\type{C}, \\type{B} ), ( \\type{A}, \\type{A} ), ( \\type{B}, \\type{A} ))$. This is not enough, as $\\type{C}$ is also a subtype of $\\type{A}$ in the combination (see \\cref{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_inh_tg12}). Taking the transitive closure of the union solves this, which results in $(( \\type{B}, \\type{B} ), ( \\type{C}, \\type{C} ), ( \\type{C}, \\type{B} ), ( \\type{A}, \\type{A} ), ( \\type{B}, \\type{A} ), ( \\type{C}, \\type{A} ))$.\n\nAbstract node types are merged in a similar way to the abstract property in type models (\\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:prop_combine}). For node types that are only present in one of the type graphs, their abstract property is preserved. For node types that are present in both type graphs, the abstract property is only preserved if the node type is abstract in both graphs. Intuitively, this makes sense, as instances of a class can only appear if the node type is not abstract. When the node type was not abstract in one of the type graphs, making it abstract within the combination would make all instances of the class invalid.\n\nContainment edges are just merged, meaning that if an edge is a containment edge in one of the graphs, it is a containment edge in the combination. This behaviour makes sense from a practical standpoint. When applying models, it is undesired that ownership over a node might get lost after combining two graphs.\n\nThe multiplicity function is merged using a new function, which is discussed in the next definition.\n\n\\begin{defin}[Combination function for multiplicity pairs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:mult_combine}\n$\\mathrm{mult\\_\\!combine}(TG_A, TG_B)$ is a partial function on two type graphs which returns a new function \\\\$ET_{TG_{AB}} \\Rightarrow (\\mathbb{M} \\times \\mathbb{M})$. It is defined as follows:\n\\begin{multline*}\n    \\mathrm{mult\\_\\!combine}(TG_{A}, TG_{B}, e) = \\\\\n    \\begin{cases}\n        ( \\max(l_{in}^A, l_{in}^B)..\\min(u_{in}^A, u_{in}^B), \\max(l_{out}^A, l_{out}^B)..\\min(u_{out}^A, u_{out}^B) ) & \\mathrm{if }\\ e \\in ET_{TG_A} \\cap ET_{TG_B} \\\\\n        \\mathrm{mult}_{TG_A}(e) & \\mathrm{if }\\ e \\in ET_{TG_A} \\setminus ET_{TG_B} \\\\\n        \\mathrm{mult}_{TG_B}(e) & \\mathrm{if }\\ e \\in ET_{TG_B} \\setminus ET_{TG_A}\n    \\end{cases}\n\\end{multline*}\nwhere\n\\begin{align*}\n    l_{in}^A .. u_{in}^A &= \\mathrm{in}(\\mathrm{mult}_{TG_A}(e)) &\n    l_{out}^A .. u_{out}^A &= \\mathrm{out}(\\mathrm{mult}_{TG_A}(e)) \\\\\n    l_{in}^B .. u_{in}^B &= \\mathrm{in}(\\mathrm{mult}_{TG_B}(e)) &\n    l_{out}^B .. u_{out}^B &= \\mathrm{out}(\\mathrm{mult}_{TG_B}(e))\n\\end{align*}\n\\isabellelref{tg_combine_mult}{GROOVE.Type_Graph_Combination}\n\\end{defin}\n\nAlthough the presented function looks quite complicated, it is similar to the way multiplicities are handled in type models (see \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:fieldsig_combine}), the only difference being that there are now two multiplicities, an incoming and outgoing multiplicity. In the case that an edge $e$ is shared across $TG_A$ and $TG_B$, the incoming and outgoing multiplicities are merged. For each of these multiplicities, the maximum of the corresponding lower bounds is taken, and the minimum of the corresponding upper bounds. For an edge $e$ that only occurs in once of the type graphs, the multiplicity pair is copied.\n\nWith all definitions in place, it is possible to provide a more significant example. Suppose the model of a straightforward contacts list. It consists of $\\type{Contact}$s of which the name, age and email address can be stored. The formal definition of the model of such a contacts list could be as follows:\n\n\\begin{align*}\nTG_{Contact} =\\ &\\langle&\nNT =\\ &\\{ \\type{Contact}, \\type{int}, \\type{string} \\} \\\\&&\nET =\\ &\\{ \n( \\type{Contact}, \\type{age}, \\type{int} ),\n( \\type{Contact}, \\type{email}, \\type{string} ),\\\\&&&\n( \\type{Contact}, \\type{firstName}, \\type{string} ),\n( \\type{Contact}, \\type{lastName}, \\type{string} )\n\\} \\\\&&\n\\sqsubseteq\\ =\\ &\\{\n( \\type{Contact}, \\type{Contact} ),\n( \\type{int}, \\type{int} ),\n( \\type{string}, \\type{string} )\n\\} \\\\&&\nabs =\\ &\\{\\} \\\\&&\n\\mathrm{mult} =\\ &\\big\\{\n\\big( ( \\type{Contact}, \\type{age}, \\type{int} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( ( \\type{Contact}, \\type{email}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Contact}, \\type{firstName}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Contact}, \\type{lastName}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big)\n\\big\\} \\\\&&\ncontains =\\ &\\{\\} \n\\\\&\\rangle\n\\end{align*}\n\nAn visual representation of $TG_{Contact}$ is included as  \\cref{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_ig1}. Now, assume a model that represents an extension to this application, adding support for adding $\\type{Address}$es. Furthermore, it adds the possibility to select favourite $\\type{Contact}$s. This extension could formally be defined as:\n\n\\begin{align*}\nTG_{Ext} =\\ &\\langle&\nNT =\\ &\\{ \\type{Address}, \\type{Contact}, \\type{int}, \\type{string} \\} \\\\&&\nET =\\ &\\{ \n( \\type{Contact}, \\type{fav}, \\type{Contact} ),\n( \\type{Contact}, \\type{addresses}, \\type{Address} ), \\\\&&&\n( \\type{Address}, \\type{addressLine}, \\type{string} ),\n( \\type{Address}, \\type{country}, \\type{string} ),\\\\&&&\n( \\type{Address}, \\type{postalCode}, \\type{string} )\n\\} \\\\&&\n\\sqsubseteq\\ =\\ &\\{\n( \\type{Address}, \\type{Address} ),\n( \\type{Contact}, \\type{Contact} ),\n( \\type{int}, \\type{int} ),\n( \\type{string}, \\type{string} )\n\\} \\\\&&\nabs =\\ &\\{\\} \\\\&&\n\\mathrm{mult} =\\ &\\big\\{\n\\big( ( \\type{Contact}, \\type{fav}, \\type{Contact} ), ( 0..1, 0..1 ) \\big),\\\\&&&\n\\big( ( \\type{Contact}, \\type{addresses}, \\type{Address} ), ( 1..1, 1..4 ) \\big),\\\\&&&\n\\big( ( \\type{Address}, \\type{addressLine}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Address}, \\type{country}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Address}, \\type{postalCode}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big)\n\\big\\} \\\\&&\ncontains =\\ &\\{\n( \\type{Contact}, \\type{addresses}, \\type{Address} )\n\\}\n\\\\&\\rangle\n\\end{align*}\n\nThe visual representation of the extension is included as \\cref{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_tg2}. Please note that $\\type{fav}$ is modelled as a flag in this model. In the visual notation, syntactic sugar is added to flags by writing them inside the node, in an italic font. Now, using \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine}, it is possible to combine these graphs into one model. This will yield the following graph:\n\n\\begin{align*}\nTG_{ContactExt} =\\ &\\langle&\nNT =\\ &\\{ \\type{Address}, \\type{Contact}, \\type{int}, \\type{string} \\} \\\\&&\nET =\\ &\\{ \n( \\type{Contact}, \\type{age}, \\type{int} ),\n( \\type{Contact}, \\type{email}, \\type{string} ),\\\\&&&\n( \\type{Contact}, \\type{firstName}, \\type{string} ),\n( \\type{Contact}, \\type{lastName}, \\type{string} ), \\\\&&&\n( \\type{Contact}, \\type{fav}, \\type{Contact} ),\n( \\type{Contact}, \\type{addresses}, \\type{Address} ), \\\\&&&\n( \\type{Address}, \\type{addressLine}, \\type{string} ),\n( \\type{Address}, \\type{country}, \\type{string} ),\\\\&&&\n( \\type{Address}, \\type{postalCode}, \\type{string} )\n\\} \\\\&&\n\\sqsubseteq\\ =\\ &\\{\n( \\type{Address}, \\type{Address} ),\n( \\type{Contact}, \\type{Contact} ),\n( \\type{int}, \\type{int} ),\n( \\type{string}, \\type{string} )\n\\} \\\\&&\nabs =\\ &\\{\\} \\\\&&\n\\mathrm{mult} =\\ &\\big\\{\n\\big( ( \\type{Contact}, \\type{age}, \\type{int} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( ( \\type{Contact}, \\type{email}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Contact}, \\type{firstName}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Contact}, \\type{lastName}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( ( \\type{Contact}, \\type{fav}, \\type{Contact} ), ( 0..1, 0..1 ) \\big),\\\\&&&\n\\big( ( \\type{Contact}, \\type{addresses}, \\type{Address} ), ( 1..1, 1..4 ) \\big),\\\\&&&\n\\big( ( \\type{Address}, \\type{addressLine}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Address}, \\type{country}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big),\\\\&&&\n\\big( \\type{Address}, \\type{postalCode}, \\type{string} ), ( 0..\\mstar, 0..1 ) \\big)\n\\big\\} \\\\&&\ncontains =\\ &\\{\n( \\type{Contact}, \\type{addresses}, \\type{Address} )\n\\}\n\\\\&\\rangle\n\\end{align*}\n\nA visual representation of this combined graph is included as \\cref{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_tg12}. The example perfectly shows why the combination of type graphs is useful: It allows for building larger graphs out of smaller building blocks. This behaviour is the exact goal of this definition within the transformation framework.\n\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}{0.3\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/contact_partial1.tikz}\n        \\caption{Contacts model $TG_{Contact}$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_ig1}\n    \\end{subfigure}\n    \\begin{subfigure}{0.3\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/contact_partial2.tikz}\n        \\caption{Address extension $TG_{Ext}$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_tg2}\n    \\end{subfigure}\n    \\begin{subfigure}{0.35\\textwidth}\n        \\centering\n        \\input{images/04_transformation_framework/type_graphs_combination/contact_combined.tikz}\n        \\caption{Combined model $TG_{ContactExt}$}\n        \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example_tg12}\n    \\end{subfigure}\n    \\caption{Example of the combination of type graphs}\n    \\label{fig:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine_example}\n\\end{figure}\n\nAlthough the definitions of the combination of type graphs are given, no mathematical properties or theorems are defined yet. Some mathematical properties hold for the combination of type graphs, that will be presented in the following theorems.\n\n\\begin{thm}[Commutativity of the combination of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_commute}\nAssume that $TG_A$ and $TG_B$ are type graphs, then the $\\mathrm{combine}$ function is commutative:\n\\begin{equation*}\n    \\mathrm{combine}(TG_A, TG_B) = \\mathrm{combine}(TG_B, TG_A)\n\\end{equation*}\n\\isabellelref{tg_combine_commute}{GROOVE.Type_Graph_Combination}\n\\end{thm}\n\n\\begin{thm}[Associativity of the combination of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_assoc}\nAssume that $TG_A$, $TG_B$ and $TG_C$ are type graphs, then the $\\mathrm{combine}$ function is associative:\n\\begin{equation*}\n    \\mathrm{combine}(\\mathrm{combine}(TG_A, TG_B), TG_C) = \\mathrm{combine}(TG_A, \\mathrm{combine}(TG_B, TG_C))\n\\end{equation*}\n\\isabellelref{tg_combine_assoc}{GROOVE.Type_Graph_Combination}\n\\end{thm}\n\n\\begin{thm}[Idempotence of the combination of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_idemp}\nAssume that $TG_A$ is a type graph and that it is valid in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}. Then the following property holds:\n\\begin{equation*}\n    \\mathrm{combine}(TG_A, TG_A) = TG_A\n\\end{equation*}\n\\isabellelref{tg_combine_idemp_alt}{GROOVE.Type_Graph_Combination}\n\\end{thm}\n\nThese properties follow directly from \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine}, but the corresponding proofs will not be included here. It should be noted that these properties are indeed proven correct as part of this thesis, and the corresponding proofs are validated within Isabelle.\n\nBesides these properties, the combination of type graphs also has an identity element. The empty type graph represents this identity element, but it needs to be defined first:\n\n\\begin{defin}[Empty type graph]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:empty_type_graph}\nLet $TG_{\\epsilon}$ be the empty type graph. $TG_{\\epsilon}$ is defined as:\n\\begin{align*}\nTG_{\\epsilon} = \\langle&\nNT = \\{\\} \\\\&\nET = \\{\\} \\\\&\n\\!\\!\\sqsubseteq\\ = \\{\\} \\\\&\nabs = \\{\\} \\\\&\n\\mathrm{mult} = undefined \\\\&\ncontains = \\{\\} \\rangle\n\\end{align*}\n\\end{defin}\n\n\\begin{thm}[Correctness of the empty type graph]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_empty_correct}\nThe empty type graph, $TG_{\\epsilon}$, is valid with respect to\n\\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}.\n\\isabellelref{tg_empty_correct}{GROOVE.Type_Graph}\n\\end{thm}\n\nThe proof for the correctness of the empty type graph is trivial. Still, a validated version of this proof can be found within the Isabelle theories of this thesis.\n\nAs mentioned earlier, the empty type graph acts as an identity element when combining two type graphs. The following theorem specifies this behaviour.\n\n\\begin{thm}[Identity of the combination of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_identity}\nAssume that $TG_A$ is a type graph and that it is valid in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}. Then $TG_{\\epsilon}$ acts as an identity element in the combination function:\n\\begin{equation*}\n    \\mathrm{combine}(TG_{\\epsilon}, TG_A) = TG_A\n\\end{equation*}\n\\isabellelref{tg_combine_identity_alt}{GROOVE.Type_Graph_Combination}\n\\end{thm}\n\nOnce more, the proof of this theorem follows directly from the definition. Therefore, the corresponding proof will not be included here, but a validated version can be found within the Isabelle theories of this thesis.\n\nJust like type models, the final desired property for the combination of type graphs is a correctness property. \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_correct} defines the theorem under which the combination of type graphs is a valid type graph. Please note that this theorem is a generic theorem, which does not take into account that the type graphs are mostly distinct.\n\n\\begin{thm}[Validity of the combination of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_correct}\nAssume that $TG_A$ and $TG_B$ are valid type graphs in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}. Furthermore, assume the following properties:\n\\begin{itemize}\n    \\item For all edges in $TG_A$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the source of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_A}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\! \\lor\\ (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B}\\!)^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big) \\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_A$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the target of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_A}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\! \\lor\\ (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\!\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_B$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the source of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_B} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\! \\lor\\ (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big) \\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_B$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the target of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_B} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\! \\lor\\ (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\!\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item Ensure that there is no possible confusion of edge types between an edge from $Tm_A$ and an edge from $Tm_B$: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!:$\\\\$\\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all shared edges, ensure the combination of multiplicity pairs is a valid multiplicity pair: $\\forall e \\in ET_{TG_A} \\cap ET_{TG_B}\\!: \\mathrm{mult\\_\\!combine}(TG_{A}, TG_{B}, e) \\in (\\mathbb{M} \\times \\mathbb{M})$.\n    \\item The transitive closure of the combine inheritance relation is antisymmetric: $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is antisymmetric.\n\\end{itemize}\n\nThen $\\mathrm{combine}(TG_A, TG_B)$ is a valid type graph in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}\n\\isabellelref{tg_combine_correct}{GROOVE.Type_Graph_Combination}\n\\end{thm}\n\n\\begin{proof}\nTo proof that $\\mathrm{combine}(TG_A, TG_B)$ is a valid type model, it needs to be shown that\\\\ $\\mathrm{combine}(TG_A, TG_B)$ gives rise to a valid structure for a type graph and that \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity} holds. For readability, define $TG_{AB}$ to be $\\mathrm{combine}(TG_A, TG_B)$.\n\n\\emph{Structural properties}\n\\begin{itemize}\n\\item All elements of $NT_{TG_{AB}}$ are elements of $Lab_t \\cup Lab_{prim}$.\n\nFollows from $NT_{TG_{A}} \\subseteq Lab_t \\cup Lab_{prim}$ and $NT_{TG_{B}} \\subseteq Lab_t \\cup Lab_{prim}$.\n\n\n\\item All elements of $ET_{TG_{AB}}$ are elements of $NT_{TG_{AB}} \\times (Lab_e \\cup Lab_f) \\times NT_{TG_{AB}}$.\n\nFollows from $ET_{TG_{A}} \\subseteq (NT_{TG_{A}} \\times (Lab_e \\cup Lab_f) \\times NT_{TG_{A}})$ and $ET_{TG_{B}} \\subseteq (NT_{TG_{B}} \\times (Lab_e \\cup Lab_f) \\times NT_{TG_{B}})$. To complete the proof, use $NT_{TG_{AB}} = NT_{TG_{A}} \\cup NT_{TG_{B}}$.\n\n\n\\item All elements of $\\sqsubseteq$ are elements of $NT_{TG_{AB}} \\times NT_{TG_{AB}}$.\n\nFollows from $\\sqsubseteq_{TG_{A}}\\ \\subseteq (NT_{TG_{A}} \\times NT_{TG_{A}})$ and $\\sqsubseteq_{TG_{B}}\\ \\subseteq (NT_{TG_{B}} \\times NT_{TG_{B}})$. To complete the proof, use $NT_{TG_{AB}} = NT_{TG_{A}} \\cup NT_{TG_{B}}$.\n\n\n\\item All elements of $abs_{TG_{AB}}$ are elements of $NT_{TG_{AB}}$.\n\nFollows from $abs_{TG_{A}} \\subseteq NT_{TG_{A}}$ and $abs_{TG_{B}} \\subseteq NT_{TG_{B}}$. To complete the proof, use $NT_{TG_{AB}} = NT_{TG_{A}} \\cup NT_{TG_{B}}$.\n\n\n\\item For each edge $e$, $\\mathrm{mult}_{TG_{AB}}(e)$ must be an element of $\\mathbb{M} \\times \\mathbb{M}$.\n\nIt holds that $e \\in ET_{TG_{A}} \\setminus ET_{TG_{B}}$, $e \\in ET_{TG_{B}} \\setminus ET_{TG_{A}}$ or $e \\in ET_{TG_{A}} \\cap ET_{TG_{B}}$.\n\nPerform the proof by a case distinction based on this fact. In case of $e \\in ET_{TG_{A}} \\cap ET_{TG_{B}}$, use the assumption to complete the proof.\n\n\n\\item All elements of $contains_{TG_{AB}}$ are elements of $ET_{TG_{AB}}$.\n\nFollows from $contains_{TG_{A}} \\subseteq ET_{TG_{A}}$ and $contains_{TG_{B}} \\subseteq ET_{TG_{B}}$. To complete the proof, use $ET_{TG_{AB}} = ET_{TG_{A}} \\cup ET_{TG_{B}}$.\n\\end{itemize}\n\n\\emph{Properties for validity}\n\\begin{itemize}\n\\item $\\forall (s_1, l, t_1) \\in ET_{TG_{AB}}\\,\\land\\, (s_2, l, t_2) \\in ET_{TG_{AB}}\\!: \\big((s_1, s_2) \\in\\ \\sqsubseteq_{TG_{AB}} \\lor\\ (s_2, s_1) \\in\\ \\sqsubseteq_{TG_{AB}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in\\ \\sqsubseteq_{TG_{AB}} \\lor\\ (t_2, t_1) \\in\\ \\sqsubseteq_{TG_{AB}}\\!\\!\\big) \\Longrightarrow s_1 = s_2 \\land t_1 = t_2$.\n\nEstablish that $(s_1, l, t_1) \\in ET_{TG_{A}}$ or $(s_1, l, t_1) \\in ET_{TG_{B}}$. Also establish that $(s_2, l, t_2) \\in ET_{TG_{A}}$ or $(s_2, l, t_2) \\in ET_{TG_{B}}$.\n\nPerform a case distinction on these facts. If $(s_1, l, t_1) \\in ET_{TG_{A}}$ and $(s_2, l, t_2) \\in ET_{TG_{B}}$, then proof by the corresponding assumption. The case $(s_1, l, t_1) \\in ET_{TG_{B}}$ and $(s_2, l, t_2) \\in ET_{TG_{A}}$ is proven by the same assumption.\n\nIf $(s_1, l, t_1) \\in ET_{TG_{A}}$ and $(s_2, l, t_2) \\in ET_{TG_{A}}$, then check if $\\big((s_1, s_2) \\in\\ \\sqsubseteq_{TG_{A}} \\lor\\ (s_2, s_1) \\in\\ \\sqsubseteq_{TG_{A}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in\\ \\sqsubseteq_{TG_{A}} \\lor\\ (t_2, t_1) \\in\\ \\sqsubseteq_{TG_{A}}\\!\\!\\big)$. If this is the case, solve using the properties of $TG_A$, when this is not the case, prove the statement using the corresponding assumptions.\n\nIf $(s_1, l, t_1) \\in ET_{TG_{B}}$ and $(s_2, l, t_2) \\in ET_{TG_{B}}$, then check if $\\big((s_1, s_2) \\in\\ \\sqsubseteq_{TG_{B}} \\lor\\ (s_2, s_1) \\in\\ \\sqsubseteq_{TG_{B}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in\\ \\sqsubseteq_{TG_{B}} \\lor\\ (t_2, t_1) \\in\\ \\sqsubseteq_{TG_{B}}\\!\\!\\big)$. If this is the case, solve using the properties of $TG_B$, when this is not the case, prove the statement using the corresponding assumptions.\n\n\n\\item $\\forall (s, l, t) \\in ET_{TG_{AB}}: l \\in Lab_f \\Longrightarrow s = t$.\n\nEstablish that $(s, l, t) \\in ET_{TG_{A}}$ or $(s, l, t) \\in ET_{TG_{B}}$. Then if $l \\in Lab_f$, show that $s = t$.\n\n\n\\item $\\sqsubseteq_{TG_{AB}}$ is a partial order.\n\nFirst show that $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is reflexive. Since $\\sqsubseteq_{TG_{A}}$ is reflexive and $\\sqsubseteq_{TG_{B}}$ is reflexive, $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is reflexive as well.\n\nThen show that $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is transitive. This is easily proven using the definition of the transitive closure.\n\nFinally, have that $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is antisymmetric by assumption.\n\n\n\\item $\\forall e \\in contains_{TG_{AB}}: \\mathrm{in}(\\mathrm{mult}_{TG_{AB}}(e)) = (0, 1) \\lor \\mathrm{in}(\\mathrm{mult}_{TG_{AB}}(e)) = (1, 1)$.\n\nUse the fact that $e \\in contains_{TG_{A}}$ or $e \\in contains_{TG_{B}}$. Then have that incoming multiplicity is valid in $Tm_A$ or $Tm_B$. Use the assumption that the combined multiplicities are valid and the definition of $\\mathrm{mult\\_\\!combine}(TG_{A}, TG_{B}, e)$ to show that the statement holds.\n\\end{itemize}\n\nThe proofs of all these individual properties completes the proof.\n\\end{proof}\n\nAs explained before, \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_correct} does not take into account that the type graphs are supposed to be distinct except for a set of node types. The following lemma is an alternation of the previous theorem, which takes this into account.\n\n\\begin{lem}[Validity of the combination (mostly) distinct of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_merge_correct}\nAssume that $TG_A$ and $TG_B$ are valid type graphs in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}. Also, assume that $TG_A$ and $TG_B$ are fully distinct except for a shared set of node types $N$. Furthermore, assume the following properties:\n\\begin{itemize}\n    \\item For all edges in $TG_A$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the source of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_A}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\! \\lor\\ (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B}\\!)^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big) \\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_A$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the target of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_A}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\! \\lor\\ (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{A}}\\!\\!\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_B$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the source of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_B} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\! \\lor\\ (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\!\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big) \\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item For all edges in $TG_B$ that share the same label, ensure that there is no possible confusion of edge types because of a new subtype introduced at the target of the edge: $\\forall (s_1, l, t_1) \\in ET_{TG_B} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!: \\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\! \\lor\\ (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\ \\setminus \\sqsubseteq_{TG_{B}}\\!\\!\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item Ensure that there is no possible confusion of edge types between an edge from $Tm_A$ and an edge from $Tm_B$: $\\forall (s_1, l, t_1) \\in ET_{TG_A} \\land (s_2, l, t_2) \\in ET_{TG_B}\\!:$\\\\$\\big((s_1, s_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (s_2, s_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)\\ \\land$\\\\$\\big((t_1, t_2) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+ \\lor (t_2, t_1) \\in (\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+\\big)$\\\\$\\implies s_1 = s_2\\ \\land\\ t_1 = t_2$.\n    \\item The transitive closure of the combine inheritance relation is antisymmetric: $(\\sqsubseteq_{TG_A} \\cup \\sqsubseteq_{TG_B})^+$ is antisymmetric.\n\\end{itemize}\n\nThen $\\mathrm{combine}(TG_A, TG_B)$ is a valid type graph in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}.\n\\isabellelref{tg_combine_merge_correct}{GROOVE.Type_Graph_Combination}\n\\end{lem}\n\n\\begin{proof}\nUse \\cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_correct} to show that $\\mathrm{combine}(TG_A, TG_B)$ is a valid type graph. Use the assumptions given. The assumption for the correctness of the multiplicity pair for shared edges has become irrelevant because there are no shared edges.\n\\end{proof}\n\nFinally, the concept of compatibility between two type graphs is defined.\n\n\\begin{defin}[Compatibility of type graphs]\n\\label{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:compatibility}\nAssume type graphs $TG_A$ and $TG_B$. We say that $TG_A$ is compatible with $TG_B$ if $\\mathrm{combine}(TG_A, TG_B)$ is a valid type graph in the sense of \\cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}.\n\\end{defin}\n\nThe notion of compatibility will be used later as a way to denote type graphs that can be combined with other type graphs without loss of validity.", "meta": {"hexsha": "be795b47b54dc70709c4c0b60ae36fc0d7d70f99", "size": 33274, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/tex/04_transformation_framework/03_type_models_and_type_graphs/02_combining_type_graphs.tex", "max_stars_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_stars_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_stars_repo_licenses": ["AFL-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": "thesis/tex/04_transformation_framework/03_type_models_and_type_graphs/02_combining_type_graphs.tex", "max_issues_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_issues_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_issues_repo_licenses": ["AFL-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": "thesis/tex/04_transformation_framework/03_type_models_and_type_graphs/02_combining_type_graphs.tex", "max_forks_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_forks_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_forks_repo_licenses": ["AFL-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": 84.4517766497, "max_line_length": 1385, "alphanum_fraction": 0.7131393881, "num_tokens": 10836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.689305616785446, "lm_q1q2_score": 0.600107577814685}}
{"text": "\\section{Appendix}\n\\label{section:appendix}\n\n\\subsection*{Priors}\n\\label{section:priors}\n\nWe used the default priors in the {\\tt isochrones.py} {\\it python} package.\nThe prior over age was,\n\\begin{equation}\np(A) = \\frac{\\log(10) 10^{A}}{10^{10.5} - 10^8}, ~~~ 8 < A < 10.5.\n\\end{equation}\n% where $A$, is $\\log_{10}(\\frac{\\mathrm{Age}}{\\mathrm{yrs}})$.\nwhere $A$, is $\\log_{10}(\\mathrm{Age~[yrs]})$.\n% The prior over mass is uniform in natural-log between -20 and 20,\n% \\begin{equation}\n%     p(M) = U(-20, 20)\n% \\end{equation}\n% % where $M$ is $\\ln(\\frac{\\mathrm{mass}}{M_\\odot})$.\n% where $M$ is $\\ln(\\mathrm{Mass}~[M_\\odot])$.\nThe prior over EEP was uniform with an upper limit of 800.\nWe found that adding this upper limit reduced some multi-modality caused by\nthe giant branch and resulted in better performance.\nThe prior over true bulk metallicity was based on the galactic metallicity\ndistribution, as inferred using data from the Sloan Digital Sky Survey\n\\citep{casagrande2011}.\n% It is based on two double-Gaussian distribution, where the halo is described as\n% a broad Gaussian and the galactic disc as a narrow Gaussian.\nIt is the product of a Gaussian that describes the metallicity distribution\nover halo stars and two Gaussians that describe the metallicity distribution\nin the thin and thick disks:\n\\begin{eqnarray}\n    p(F) =\n    & H_F \\frac{1}{\\sqrt{2\\pi\\sigma_{\\mathrm{halo}}^2}}\n    \\exp\\left(-\\frac{(F-\\mu_{\\mathrm{halo}})^2}{2\\sigma_{\\mathrm{halo}}}\\right)\n    \\\\ \\nonumber\n    & \\times (1-H_F)\n    \\frac{1}{\\xi}\n    \\left[\\frac{0.8}{0.15}\\exp\\left(-\\frac{(F-0.016)^2}{2\\times 0.15^2}\\right)\n    + \\frac{0.2}{0.22}\\exp\\left(-\\frac{(F-0.15)^2}{2\\times\n    0.22^2}\\right)\\right],\n\\end{eqnarray}\nwhere $H_F = 0.001$ is the halo fraction, $\\mu_\\mathrm{halo}$ and\n$\\sigma_{\\mathrm{halo}}$ are the mean and standard deviation of a Gaussian\nthat describes a probability distribution over metallicity in the halo, and\ntake values -1.5 and 0.4 respectively.\n% $\\mu_\\mathrm{disk, 1}$, $\\mu_\\mathrm{disk, 2}$, $\\sigma_\\mathrm{disk, 1}$\n% and $\\sigma_\\mathrm{disk, 2}$ are the means and standard deviations of two\nThe two Gaussians inside the square brackets describe probability\ndistributions over metallicity in the thin and thick disks.\nThe values of the means and standard deviations in these Gaussians are from\n\\citet{casagrande2011}.\n$\\xi$ is the integral of everything in the square brackets from $-\\infty$ to\n$\\infty$ and takes the value $\\sim 2.507$.\n% D_F = 0.8 \\sigma_{\\mathrm{disk, 1}} = 0.15 \\mu_{\\mathrm{disk, 1}} = 0.016\n% \\sigma_{\\mathrm{disk, 2}} = 0.22 \\mu_{\\mathrm{disk, 2}} = 0.15\nThe prior over distance was,\n\\begin{equation}\n    p(D) = \\frac{3}{3000^3} D^2, ~~~ 0 < D < 3000,\n\\end{equation}\nwith D in kiloparsecs, and, finally, the prior over extinction was uniform\nbetween zero and one,\n\\begin{equation}\n    p(A_V) = U(0, 1).\n\\end{equation}\n", "meta": {"hexsha": "9cef4fad30ec625ce48b443425064e209f948567", "size": 2874, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/appendix.tex", "max_stars_repo_name": "john-livingston/stardate", "max_stars_repo_head_hexsha": "5c0d45c1e2eb9ec5b6c57aeacbcb301304065bbc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-02-19T13:46:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-31T23:46:36.000Z", "max_issues_repo_path": "paper/appendix.tex", "max_issues_repo_name": "john-livingston/stardate", "max_issues_repo_head_hexsha": "5c0d45c1e2eb9ec5b6c57aeacbcb301304065bbc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-02-21T21:37:05.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-09T10:38:15.000Z", "max_forks_repo_path": "paper/appendix.tex", "max_forks_repo_name": "john-livingston/stardate", "max_forks_repo_head_hexsha": "5c0d45c1e2eb9ec5b6c57aeacbcb301304065bbc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-02-11T02:46:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T22:16:53.000Z", "avg_line_length": 44.2153846154, "max_line_length": 81, "alphanum_fraction": 0.6958942241, "num_tokens": 966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.6825737344123242, "lm_q1q2_score": 0.6000824857115385}}
